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 = global || self, global.BpmnJS = factory());
|
17 | }(this, function () { 'use strict';
|
18 |
|
19 | var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : 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 | var inherits_browser = createCommonjsModule(function (module) {
|
26 | if (typeof Object.create === 'function') {
|
27 |
|
28 | module.exports = function inherits(ctor, superCtor) {
|
29 | ctor.super_ = superCtor;
|
30 | ctor.prototype = Object.create(superCtor.prototype, {
|
31 | constructor: {
|
32 | value: ctor,
|
33 | enumerable: false,
|
34 | writable: true,
|
35 | configurable: true
|
36 | }
|
37 | });
|
38 | };
|
39 | } else {
|
40 |
|
41 | module.exports = function inherits(ctor, superCtor) {
|
42 | ctor.super_ = superCtor;
|
43 | var TempCtor = function () {};
|
44 | TempCtor.prototype = superCtor.prototype;
|
45 | ctor.prototype = new TempCtor();
|
46 | ctor.prototype.constructor = ctor;
|
47 | };
|
48 | }
|
49 | });
|
50 |
|
51 | function createCommonjsModule$1(fn, module) {
|
52 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
53 | }
|
54 |
|
55 | var hat_1 = createCommonjsModule$1(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 |
|
128 | function Ids(seed) {
|
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 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 | Ids.prototype.next = function (element) {
|
145 | return this._seed(element || true);
|
146 | };
|
147 | |
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 | Ids.prototype.nextPrefixed = function (prefix, element) {
|
157 | var id;
|
158 |
|
159 | do {
|
160 | id = prefix + this.next(true);
|
161 | } while (this.assigned(id));
|
162 |
|
163 |
|
164 | this.claim(id, element);
|
165 |
|
166 | return id;
|
167 | };
|
168 | |
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 | Ids.prototype.claim = function (id, element) {
|
177 | this._seed.set(id, element || true);
|
178 | };
|
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 |
|
197 | Ids.prototype.unclaim = function (id) {
|
198 | delete this._seed.hats[id];
|
199 | };
|
200 | |
201 |
|
202 |
|
203 |
|
204 |
|
205 | Ids.prototype.clear = function () {
|
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 | function isUndefined(obj) {
|
228 | return obj === undefined;
|
229 | }
|
230 | function isDefined(obj) {
|
231 | return obj !== undefined;
|
232 | }
|
233 | function isNil(obj) {
|
234 | return obj == null;
|
235 | }
|
236 | function isArray(obj) {
|
237 | return nativeToString.call(obj) === '[object Array]';
|
238 | }
|
239 | function isObject(obj) {
|
240 | return nativeToString.call(obj) === '[object Object]';
|
241 | }
|
242 | function isNumber(obj) {
|
243 | return nativeToString.call(obj) === '[object Number]';
|
244 | }
|
245 | function isFunction(obj) {
|
246 | var tag = nativeToString.call(obj);
|
247 | return tag === '[object Function]' || tag === '[object AsyncFunction]' || tag === '[object GeneratorFunction]' || tag === '[object AsyncGeneratorFunction]' || tag === '[object Proxy]';
|
248 | }
|
249 | function isString(obj) {
|
250 | return nativeToString.call(obj) === '[object String]';
|
251 | }
|
252 | |
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 | function ensureArray(obj) {
|
259 | if (isArray(obj)) {
|
260 | return;
|
261 | }
|
262 |
|
263 | throw new Error('must supply array');
|
264 | }
|
265 | |
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 | function has(target, key) {
|
275 | return nativeHasOwnProperty.call(target, key);
|
276 | }
|
277 |
|
278 | |
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 | function find(collection, matcher) {
|
288 | matcher = toMatcher(matcher);
|
289 | var match;
|
290 | forEach(collection, function (val, key) {
|
291 | if (matcher(val, key)) {
|
292 | match = val;
|
293 | return false;
|
294 | }
|
295 | });
|
296 | return match;
|
297 | }
|
298 | |
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 | function findIndex(collection, matcher) {
|
308 | matcher = toMatcher(matcher);
|
309 | var idx = isArray(collection) ? -1 : undefined;
|
310 | forEach(collection, function (val, key) {
|
311 | if (matcher(val, key)) {
|
312 | idx = key;
|
313 | return false;
|
314 | }
|
315 | });
|
316 | return idx;
|
317 | }
|
318 | |
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 | function filter(collection, matcher) {
|
328 | var result = [];
|
329 | forEach(collection, function (val, key) {
|
330 | if (matcher(val, key)) {
|
331 | result.push(val);
|
332 | }
|
333 | });
|
334 | return result;
|
335 | }
|
336 | |
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 | function forEach(collection, iterator) {
|
347 | var val, result;
|
348 |
|
349 | if (isUndefined(collection)) {
|
350 | return;
|
351 | }
|
352 |
|
353 | var convertKey = isArray(collection) ? toNum : identity;
|
354 |
|
355 | for (var key in collection) {
|
356 | if (has(collection, key)) {
|
357 | val = collection[key];
|
358 | result = iterator(val, convertKey(key));
|
359 |
|
360 | if (result === false) {
|
361 | return val;
|
362 | }
|
363 | }
|
364 | }
|
365 | }
|
366 | |
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 | function without(arr, matcher) {
|
376 | if (isUndefined(arr)) {
|
377 | return [];
|
378 | }
|
379 |
|
380 | ensureArray(arr);
|
381 | matcher = toMatcher(matcher);
|
382 | return arr.filter(function (el, idx) {
|
383 | return !matcher(el, idx);
|
384 | });
|
385 | }
|
386 | |
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 | function reduce(collection, iterator, result) {
|
397 | forEach(collection, function (value, idx) {
|
398 | result = iterator(result, value, idx);
|
399 | });
|
400 | return result;
|
401 | }
|
402 | |
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 | function every(collection, matcher) {
|
413 | return !!reduce(collection, function (matches, val, key) {
|
414 | return matches && matcher(val, key);
|
415 | }, true);
|
416 | }
|
417 | |
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 | function some(collection, matcher) {
|
428 | return !!find(collection, matcher);
|
429 | }
|
430 | |
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 | function map(collection, fn) {
|
441 | var result = [];
|
442 | forEach(collection, function (val, key) {
|
443 | result.push(fn(val, key));
|
444 | });
|
445 | return result;
|
446 | }
|
447 | |
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 | function keys(collection) {
|
456 | return collection && Object.keys(collection) || [];
|
457 | }
|
458 | |
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 | function size(collection) {
|
467 | return keys(collection).length;
|
468 | }
|
469 | |
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 | function values(collection) {
|
478 | return map(collection, function (val) {
|
479 | return val;
|
480 | });
|
481 | }
|
482 | |
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 | function groupBy(collection, extractor) {
|
492 | var grouped = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
493 | extractor = toExtractor(extractor);
|
494 | forEach(collection, function (val) {
|
495 | var discriminator = extractor(val) || '_';
|
496 | var group = grouped[discriminator];
|
497 |
|
498 | if (!group) {
|
499 | group = grouped[discriminator] = [];
|
500 | }
|
501 |
|
502 | group.push(val);
|
503 | });
|
504 | return grouped;
|
505 | }
|
506 | function uniqueBy(extractor) {
|
507 | extractor = toExtractor(extractor);
|
508 | var grouped = {};
|
509 |
|
510 | for (var _len = arguments.length, collections = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
511 | collections[_key - 1] = arguments[_key];
|
512 | }
|
513 |
|
514 | forEach(collections, function (c) {
|
515 | return groupBy(c, extractor, grouped);
|
516 | });
|
517 | var result = map(grouped, function (val, key) {
|
518 | return val[0];
|
519 | });
|
520 | return result;
|
521 | }
|
522 | var unionBy = uniqueBy;
|
523 | |
524 |
|
525 |
|
526 |
|
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 | function sortBy(collection, extractor) {
|
533 | extractor = toExtractor(extractor);
|
534 | var sorted = [];
|
535 | forEach(collection, function (value, key) {
|
536 | var disc = extractor(value, key);
|
537 | var entry = {
|
538 | d: disc,
|
539 | v: value
|
540 | };
|
541 |
|
542 | for (var idx = 0; idx < sorted.length; idx++) {
|
543 | var d = sorted[idx].d;
|
544 |
|
545 | if (disc < d) {
|
546 | sorted.splice(idx, 0, entry);
|
547 | return;
|
548 | }
|
549 | }
|
550 |
|
551 |
|
552 | sorted.push(entry);
|
553 | });
|
554 | return map(sorted, function (e) {
|
555 | return e.v;
|
556 | });
|
557 | }
|
558 | |
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 | function matchPattern(pattern) {
|
573 | return function (el) {
|
574 | return every(pattern, function (val, key) {
|
575 | return el[key] === val;
|
576 | });
|
577 | };
|
578 | }
|
579 |
|
580 | function toExtractor(extractor) {
|
581 | return isFunction(extractor) ? extractor : function (e) {
|
582 | return e[extractor];
|
583 | };
|
584 | }
|
585 |
|
586 | function toMatcher(matcher) {
|
587 | return isFunction(matcher) ? matcher : function (e) {
|
588 | return e === matcher;
|
589 | };
|
590 | }
|
591 |
|
592 | function identity(arg) {
|
593 | return arg;
|
594 | }
|
595 |
|
596 | function toNum(arg) {
|
597 | return Number(arg);
|
598 | }
|
599 |
|
600 | |
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 | function debounce(fn, timeout) {
|
610 | var timer;
|
611 | var lastArgs;
|
612 | var lastThis;
|
613 | var lastNow;
|
614 |
|
615 | function fire() {
|
616 | var now = Date.now();
|
617 | var scheduledDiff = lastNow + timeout - now;
|
618 |
|
619 | if (scheduledDiff > 0) {
|
620 | return schedule(scheduledDiff);
|
621 | }
|
622 |
|
623 | fn.apply(lastThis, lastArgs);
|
624 | timer = lastNow = lastArgs = lastThis = undefined;
|
625 | }
|
626 |
|
627 | function schedule(timeout) {
|
628 | timer = setTimeout(fire, timeout);
|
629 | }
|
630 |
|
631 | return function () {
|
632 | lastNow = Date.now();
|
633 |
|
634 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
635 | args[_key] = arguments[_key];
|
636 | }
|
637 |
|
638 | lastArgs = args;
|
639 | lastThis = this;
|
640 |
|
641 | if (!timer) {
|
642 | schedule(timeout);
|
643 | }
|
644 | };
|
645 | }
|
646 | |
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 | function bind(fn, target) {
|
656 | return fn.bind(target);
|
657 | }
|
658 |
|
659 | function _extends() {
|
660 | _extends = Object.assign || function (target) {
|
661 | for (var i = 1; i < arguments.length; i++) {
|
662 | var source = arguments[i];
|
663 |
|
664 | for (var key in source) {
|
665 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
666 | target[key] = source[key];
|
667 | }
|
668 | }
|
669 | }
|
670 |
|
671 | return target;
|
672 | };
|
673 |
|
674 | return _extends.apply(this, arguments);
|
675 | }
|
676 |
|
677 | |
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 | function assign(target) {
|
687 | for (var _len = arguments.length, others = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
688 | others[_key - 1] = arguments[_key];
|
689 | }
|
690 |
|
691 | return _extends.apply(void 0, [target].concat(others));
|
692 | }
|
693 | |
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 | function pick(target, properties) {
|
703 | var result = {};
|
704 | var obj = Object(target);
|
705 | forEach(properties, function (prop) {
|
706 | if (prop in obj) {
|
707 | result[prop] = target[prop];
|
708 | }
|
709 | });
|
710 | return result;
|
711 | }
|
712 | |
713 |
|
714 |
|
715 |
|
716 |
|
717 |
|
718 |
|
719 |
|
720 |
|
721 | function omit(target, properties) {
|
722 | var result = {};
|
723 | var obj = Object(target);
|
724 | forEach(obj, function (prop, key) {
|
725 | if (properties.indexOf(key) === -1) {
|
726 | result[key] = prop;
|
727 | }
|
728 | });
|
729 | return result;
|
730 | }
|
731 |
|
732 | |
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 | function attr(el, name, val) {
|
741 |
|
742 | if (arguments.length == 2) {
|
743 | return el.getAttribute(name);
|
744 | }
|
745 |
|
746 |
|
747 | if (val === null) {
|
748 | return el.removeAttribute(name);
|
749 | }
|
750 |
|
751 |
|
752 | el.setAttribute(name, val);
|
753 |
|
754 | return el;
|
755 | }
|
756 |
|
757 | var indexOf = [].indexOf;
|
758 |
|
759 | var indexof = function(arr, obj){
|
760 | if (indexOf) return arr.indexOf(obj);
|
761 | for (var i = 0; i < arr.length; ++i) {
|
762 | if (arr[i] === obj) return i;
|
763 | }
|
764 | return -1;
|
765 | };
|
766 |
|
767 | |
768 |
|
769 |
|
770 |
|
771 |
|
772 |
|
773 | |
774 |
|
775 |
|
776 |
|
777 | var re = /\s+/;
|
778 |
|
779 | |
780 |
|
781 |
|
782 |
|
783 | var toString = Object.prototype.toString;
|
784 |
|
785 | |
786 |
|
787 |
|
788 |
|
789 |
|
790 |
|
791 |
|
792 |
|
793 | function classes(el) {
|
794 | return new ClassList(el);
|
795 | }
|
796 |
|
797 | |
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 | function ClassList(el) {
|
805 | if (!el || !el.nodeType) {
|
806 | throw new Error('A DOM element reference is required');
|
807 | }
|
808 | this.el = el;
|
809 | this.list = el.classList;
|
810 | }
|
811 |
|
812 | |
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 | ClassList.prototype.add = function (name) {
|
821 |
|
822 | if (this.list) {
|
823 | this.list.add(name);
|
824 | return this;
|
825 | }
|
826 |
|
827 |
|
828 | var arr = this.array();
|
829 | var i = indexof(arr, name);
|
830 | if (!~i) arr.push(name);
|
831 | this.el.className = arr.join(' ');
|
832 | return this;
|
833 | };
|
834 |
|
835 | |
836 |
|
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 |
|
844 |
|
845 | ClassList.prototype.remove = function (name) {
|
846 | if ('[object RegExp]' == toString.call(name)) {
|
847 | return this.removeMatching(name);
|
848 | }
|
849 |
|
850 |
|
851 | if (this.list) {
|
852 | this.list.remove(name);
|
853 | return this;
|
854 | }
|
855 |
|
856 |
|
857 | var arr = this.array();
|
858 | var i = indexof(arr, name);
|
859 | if (~i) arr.splice(i, 1);
|
860 | this.el.className = arr.join(' ');
|
861 | return this;
|
862 | };
|
863 |
|
864 | |
865 |
|
866 |
|
867 |
|
868 |
|
869 |
|
870 |
|
871 |
|
872 | ClassList.prototype.removeMatching = function (re) {
|
873 | var arr = this.array();
|
874 | for (var i = 0; i < arr.length; i++) {
|
875 | if (re.test(arr[i])) {
|
876 | this.remove(arr[i]);
|
877 | }
|
878 | }
|
879 | return this;
|
880 | };
|
881 |
|
882 | |
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 | ClassList.prototype.toggle = function (name, force) {
|
895 |
|
896 | if (this.list) {
|
897 | if ('undefined' !== typeof force) {
|
898 | if (force !== this.list.toggle(name, force)) {
|
899 | this.list.toggle(name);
|
900 | }
|
901 | } else {
|
902 | this.list.toggle(name);
|
903 | }
|
904 | return this;
|
905 | }
|
906 |
|
907 |
|
908 | if ('undefined' !== typeof force) {
|
909 | if (!force) {
|
910 | this.remove(name);
|
911 | } else {
|
912 | this.add(name);
|
913 | }
|
914 | } else {
|
915 | if (this.has(name)) {
|
916 | this.remove(name);
|
917 | } else {
|
918 | this.add(name);
|
919 | }
|
920 | }
|
921 |
|
922 | return this;
|
923 | };
|
924 |
|
925 | |
926 |
|
927 |
|
928 |
|
929 |
|
930 |
|
931 |
|
932 | ClassList.prototype.array = function () {
|
933 | var className = this.el.getAttribute('class') || '';
|
934 | var str = className.replace(/^\s+|\s+$/g, '');
|
935 | var arr = str.split(re);
|
936 | if ('' === arr[0]) arr.shift();
|
937 | return arr;
|
938 | };
|
939 |
|
940 | |
941 |
|
942 |
|
943 |
|
944 |
|
945 |
|
946 |
|
947 |
|
948 | ClassList.prototype.has = ClassList.prototype.contains = function (name) {
|
949 | return this.list ? this.list.contains(name) : !!~indexof(this.array(), name);
|
950 | };
|
951 |
|
952 | |
953 |
|
954 |
|
955 | function clear(el) {
|
956 |
|
957 | var c;
|
958 |
|
959 | while (el.childNodes.length) {
|
960 | c = el.childNodes[0];
|
961 | el.removeChild(c);
|
962 | }
|
963 |
|
964 | return el;
|
965 | }
|
966 |
|
967 | |
968 |
|
969 |
|
970 |
|
971 | var proto = Element.prototype;
|
972 |
|
973 | |
974 |
|
975 |
|
976 |
|
977 | var vendor = proto.matchesSelector
|
978 | || proto.webkitMatchesSelector
|
979 | || proto.mozMatchesSelector
|
980 | || proto.msMatchesSelector
|
981 | || proto.oMatchesSelector;
|
982 |
|
983 | |
984 |
|
985 |
|
986 |
|
987 | var matchesSelector = match;
|
988 |
|
989 | |
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 | function match(el, selector) {
|
999 | if (vendor) return vendor.call(el, selector);
|
1000 | var nodes = el.parentNode.querySelectorAll(selector);
|
1001 | for (var i = 0; i < nodes.length; ++i) {
|
1002 | if (nodes[i] == el) return true;
|
1003 | }
|
1004 | return false;
|
1005 | }
|
1006 |
|
1007 | var closest = function (element, selector, checkYoSelf) {
|
1008 | var parent = checkYoSelf ? element : element.parentNode;
|
1009 |
|
1010 | while (parent && parent !== document) {
|
1011 | if (matchesSelector(parent, selector)) return parent;
|
1012 | parent = parent.parentNode;
|
1013 | }
|
1014 | };
|
1015 |
|
1016 | var bind$1 = window.addEventListener ? 'addEventListener' : 'attachEvent',
|
1017 | unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
|
1018 | prefix = bind$1 !== 'addEventListener' ? 'on' : '';
|
1019 |
|
1020 | |
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 |
|
1030 |
|
1031 | var bind_1 = function(el, type, fn, capture){
|
1032 | el[bind$1](prefix + type, fn, capture || false);
|
1033 | return fn;
|
1034 | };
|
1035 |
|
1036 | |
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 | var unbind_1 = function(el, type, fn, capture){
|
1048 | el[unbind](prefix + type, fn, capture || false);
|
1049 | return fn;
|
1050 | };
|
1051 |
|
1052 | var componentEvent = {
|
1053 | bind: bind_1,
|
1054 | unbind: unbind_1
|
1055 | };
|
1056 |
|
1057 | |
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 | |
1064 |
|
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 | var forceCaptureEvents = ['focus', 'blur'];
|
1080 |
|
1081 | var bind$1$1 = function(el, selector, type, fn, capture){
|
1082 | if (forceCaptureEvents.indexOf(type) !== -1) capture = true;
|
1083 |
|
1084 | return componentEvent.bind(el, type, function(e){
|
1085 | var target = e.target || e.srcElement;
|
1086 | e.delegateTarget = closest(target, selector, true);
|
1087 | if (e.delegateTarget) fn.call(el, e);
|
1088 | }, capture);
|
1089 | };
|
1090 |
|
1091 | |
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 | var unbind$1 = function(el, type, fn, capture){
|
1102 | if (forceCaptureEvents.indexOf(type) !== -1) capture = true;
|
1103 |
|
1104 | componentEvent.unbind(el, type, fn, capture);
|
1105 | };
|
1106 |
|
1107 | var delegateEvents = {
|
1108 | bind: bind$1$1,
|
1109 | unbind: unbind$1
|
1110 | };
|
1111 |
|
1112 | |
1113 |
|
1114 |
|
1115 |
|
1116 | var domify = parse;
|
1117 |
|
1118 | |
1119 |
|
1120 |
|
1121 |
|
1122 | var innerHTMLBug = false;
|
1123 | var bugTestDiv;
|
1124 | if (typeof document !== 'undefined') {
|
1125 | bugTestDiv = document.createElement('div');
|
1126 |
|
1127 | bugTestDiv.innerHTML = ' <link/><table></table><a href="/a">a</a><input type="checkbox"/>';
|
1128 |
|
1129 |
|
1130 | innerHTMLBug = !bugTestDiv.getElementsByTagName('link').length;
|
1131 | bugTestDiv = undefined;
|
1132 | }
|
1133 |
|
1134 | |
1135 |
|
1136 |
|
1137 |
|
1138 | var map$1 = {
|
1139 | legend: [1, '<fieldset>', '</fieldset>'],
|
1140 | tr: [2, '<table><tbody>', '</tbody></table>'],
|
1141 | col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
|
1142 |
|
1143 |
|
1144 | _default: innerHTMLBug ? [1, 'X<div>', '</div>'] : [0, '', '']
|
1145 | };
|
1146 |
|
1147 | map$1.td =
|
1148 | map$1.th = [3, '<table><tbody><tr>', '</tr></tbody></table>'];
|
1149 |
|
1150 | map$1.option =
|
1151 | map$1.optgroup = [1, '<select multiple="multiple">', '</select>'];
|
1152 |
|
1153 | map$1.thead =
|
1154 | map$1.tbody =
|
1155 | map$1.colgroup =
|
1156 | map$1.caption =
|
1157 | map$1.tfoot = [1, '<table>', '</table>'];
|
1158 |
|
1159 | map$1.polyline =
|
1160 | map$1.ellipse =
|
1161 | map$1.polygon =
|
1162 | map$1.circle =
|
1163 | map$1.text =
|
1164 | map$1.line =
|
1165 | map$1.path =
|
1166 | map$1.rect =
|
1167 | map$1.g = [1, '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">','</svg>'];
|
1168 |
|
1169 | |
1170 |
|
1171 |
|
1172 |
|
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 |
|
1178 |
|
1179 |
|
1180 | function parse(html, doc) {
|
1181 | if ('string' != typeof html) throw new TypeError('String expected');
|
1182 |
|
1183 |
|
1184 | if (!doc) doc = document;
|
1185 |
|
1186 |
|
1187 | var m = /<([\w:]+)/.exec(html);
|
1188 | if (!m) return doc.createTextNode(html);
|
1189 |
|
1190 | html = html.replace(/^\s+|\s+$/g, '');
|
1191 |
|
1192 | var tag = m[1];
|
1193 |
|
1194 |
|
1195 | if (tag == 'body') {
|
1196 | var el = doc.createElement('html');
|
1197 | el.innerHTML = html;
|
1198 | return el.removeChild(el.lastChild);
|
1199 | }
|
1200 |
|
1201 |
|
1202 | var wrap = map$1[tag] || map$1._default;
|
1203 | var depth = wrap[0];
|
1204 | var prefix = wrap[1];
|
1205 | var suffix = wrap[2];
|
1206 | var el = doc.createElement('div');
|
1207 | el.innerHTML = prefix + html + suffix;
|
1208 | while (depth--) el = el.lastChild;
|
1209 |
|
1210 |
|
1211 | if (el.firstChild == el.lastChild) {
|
1212 | return el.removeChild(el.firstChild);
|
1213 | }
|
1214 |
|
1215 |
|
1216 | var fragment = doc.createDocumentFragment();
|
1217 | while (el.firstChild) {
|
1218 | fragment.appendChild(el.removeChild(el.firstChild));
|
1219 | }
|
1220 |
|
1221 | return fragment;
|
1222 | }
|
1223 |
|
1224 | var proto$1 = typeof Element !== 'undefined' ? Element.prototype : {};
|
1225 | var vendor$1 = proto$1.matches
|
1226 | || proto$1.matchesSelector
|
1227 | || proto$1.webkitMatchesSelector
|
1228 | || proto$1.mozMatchesSelector
|
1229 | || proto$1.msMatchesSelector
|
1230 | || proto$1.oMatchesSelector;
|
1231 |
|
1232 | var matchesSelector$1 = match$1;
|
1233 |
|
1234 | |
1235 |
|
1236 |
|
1237 |
|
1238 |
|
1239 |
|
1240 |
|
1241 |
|
1242 |
|
1243 | function match$1(el, selector) {
|
1244 | if (!el || el.nodeType !== 1) return false;
|
1245 | if (vendor$1) return vendor$1.call(el, selector);
|
1246 | var nodes = el.parentNode.querySelectorAll(selector);
|
1247 | for (var i = 0; i < nodes.length; i++) {
|
1248 | if (nodes[i] == el) return true;
|
1249 | }
|
1250 | return false;
|
1251 | }
|
1252 |
|
1253 | function query(selector, el) {
|
1254 | el = el || document;
|
1255 |
|
1256 | return el.querySelector(selector);
|
1257 | }
|
1258 |
|
1259 | function all(selector, el) {
|
1260 | el = el || document;
|
1261 |
|
1262 | return el.querySelectorAll(selector);
|
1263 | }
|
1264 |
|
1265 | function remove(el) {
|
1266 | el.parentNode && el.parentNode.removeChild(el);
|
1267 | }
|
1268 |
|
1269 | function ensureImported(element, target) {
|
1270 |
|
1271 | if (element.ownerDocument !== target.ownerDocument) {
|
1272 | try {
|
1273 |
|
1274 | return target.ownerDocument.importNode(element, true);
|
1275 | } catch (e) {
|
1276 |
|
1277 | }
|
1278 | }
|
1279 |
|
1280 | return element;
|
1281 | }
|
1282 |
|
1283 | |
1284 |
|
1285 |
|
1286 |
|
1287 | |
1288 |
|
1289 |
|
1290 |
|
1291 |
|
1292 |
|
1293 |
|
1294 |
|
1295 | function appendTo(element, target) {
|
1296 | return target.appendChild(ensureImported(element, target));
|
1297 | }
|
1298 |
|
1299 | |
1300 |
|
1301 |
|
1302 |
|
1303 | |
1304 |
|
1305 |
|
1306 |
|
1307 |
|
1308 |
|
1309 |
|
1310 |
|
1311 | function append(target, node) {
|
1312 | appendTo(node, target);
|
1313 | return target;
|
1314 | }
|
1315 |
|
1316 | |
1317 |
|
1318 |
|
1319 |
|
1320 | var LENGTH_ATTR = 2;
|
1321 |
|
1322 | var CSS_PROPERTIES = {
|
1323 | 'alignment-baseline': 1,
|
1324 | 'baseline-shift': 1,
|
1325 | 'clip': 1,
|
1326 | 'clip-path': 1,
|
1327 | 'clip-rule': 1,
|
1328 | 'color': 1,
|
1329 | 'color-interpolation': 1,
|
1330 | 'color-interpolation-filters': 1,
|
1331 | 'color-profile': 1,
|
1332 | 'color-rendering': 1,
|
1333 | 'cursor': 1,
|
1334 | 'direction': 1,
|
1335 | 'display': 1,
|
1336 | 'dominant-baseline': 1,
|
1337 | 'enable-background': 1,
|
1338 | 'fill': 1,
|
1339 | 'fill-opacity': 1,
|
1340 | 'fill-rule': 1,
|
1341 | 'filter': 1,
|
1342 | 'flood-color': 1,
|
1343 | 'flood-opacity': 1,
|
1344 | 'font': 1,
|
1345 | 'font-family': 1,
|
1346 | 'font-size': LENGTH_ATTR,
|
1347 | 'font-size-adjust': 1,
|
1348 | 'font-stretch': 1,
|
1349 | 'font-style': 1,
|
1350 | 'font-variant': 1,
|
1351 | 'font-weight': 1,
|
1352 | 'glyph-orientation-horizontal': 1,
|
1353 | 'glyph-orientation-vertical': 1,
|
1354 | 'image-rendering': 1,
|
1355 | 'kerning': 1,
|
1356 | 'letter-spacing': 1,
|
1357 | 'lighting-color': 1,
|
1358 | 'marker': 1,
|
1359 | 'marker-end': 1,
|
1360 | 'marker-mid': 1,
|
1361 | 'marker-start': 1,
|
1362 | 'mask': 1,
|
1363 | 'opacity': 1,
|
1364 | 'overflow': 1,
|
1365 | 'pointer-events': 1,
|
1366 | 'shape-rendering': 1,
|
1367 | 'stop-color': 1,
|
1368 | 'stop-opacity': 1,
|
1369 | 'stroke': 1,
|
1370 | 'stroke-dasharray': 1,
|
1371 | 'stroke-dashoffset': 1,
|
1372 | 'stroke-linecap': 1,
|
1373 | 'stroke-linejoin': 1,
|
1374 | 'stroke-miterlimit': 1,
|
1375 | 'stroke-opacity': 1,
|
1376 | 'stroke-width': LENGTH_ATTR,
|
1377 | 'text-anchor': 1,
|
1378 | 'text-decoration': 1,
|
1379 | 'text-rendering': 1,
|
1380 | 'unicode-bidi': 1,
|
1381 | 'visibility': 1,
|
1382 | 'word-spacing': 1,
|
1383 | 'writing-mode': 1
|
1384 | };
|
1385 |
|
1386 |
|
1387 | function getAttribute(node, name) {
|
1388 | if (CSS_PROPERTIES[name]) {
|
1389 | return node.style[name];
|
1390 | } else {
|
1391 | return node.getAttributeNS(null, name);
|
1392 | }
|
1393 | }
|
1394 |
|
1395 | function setAttribute(node, name, value) {
|
1396 | var hyphenated = name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
1397 |
|
1398 | var type = CSS_PROPERTIES[hyphenated];
|
1399 |
|
1400 | if (type) {
|
1401 |
|
1402 | if (type === LENGTH_ATTR && typeof value === 'number') {
|
1403 | value = String(value) + 'px';
|
1404 | }
|
1405 |
|
1406 | node.style[hyphenated] = value;
|
1407 | } else {
|
1408 | node.setAttributeNS(null, name, value);
|
1409 | }
|
1410 | }
|
1411 |
|
1412 | function setAttributes(node, attrs) {
|
1413 |
|
1414 | var names = Object.keys(attrs), i, name;
|
1415 |
|
1416 | for (i = 0, name; (name = names[i]); i++) {
|
1417 | setAttribute(node, name, attrs[name]);
|
1418 | }
|
1419 | }
|
1420 |
|
1421 | |
1422 |
|
1423 |
|
1424 |
|
1425 |
|
1426 |
|
1427 |
|
1428 |
|
1429 |
|
1430 |
|
1431 | function attr$1(node, name, value) {
|
1432 | if (typeof name === 'string') {
|
1433 | if (value !== undefined) {
|
1434 | setAttribute(node, name, value);
|
1435 | } else {
|
1436 | return getAttribute(node, name);
|
1437 | }
|
1438 | } else {
|
1439 | setAttributes(node, name);
|
1440 | }
|
1441 |
|
1442 | return node;
|
1443 | }
|
1444 |
|
1445 | |
1446 |
|
1447 |
|
1448 | function index(arr, obj) {
|
1449 | if (arr.indexOf) {
|
1450 | return arr.indexOf(obj);
|
1451 | }
|
1452 |
|
1453 |
|
1454 | for (var i = 0; i < arr.length; ++i) {
|
1455 | if (arr[i] === obj) {
|
1456 | return i;
|
1457 | }
|
1458 | }
|
1459 |
|
1460 | return -1;
|
1461 | }
|
1462 |
|
1463 | var re$1 = /\s+/;
|
1464 |
|
1465 | var toString$1 = Object.prototype.toString;
|
1466 |
|
1467 | function defined(o) {
|
1468 | return typeof o !== 'undefined';
|
1469 | }
|
1470 |
|
1471 | |
1472 |
|
1473 |
|
1474 |
|
1475 |
|
1476 |
|
1477 |
|
1478 |
|
1479 | function classes$1(el) {
|
1480 | return new ClassList$1(el);
|
1481 | }
|
1482 |
|
1483 | function ClassList$1(el) {
|
1484 | if (!el || !el.nodeType) {
|
1485 | throw new Error('A DOM element reference is required');
|
1486 | }
|
1487 | this.el = el;
|
1488 | this.list = el.classList;
|
1489 | }
|
1490 |
|
1491 | |
1492 |
|
1493 |
|
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 |
|
1499 | ClassList$1.prototype.add = function(name) {
|
1500 |
|
1501 |
|
1502 | if (this.list) {
|
1503 | this.list.add(name);
|
1504 | return this;
|
1505 | }
|
1506 |
|
1507 |
|
1508 | var arr = this.array();
|
1509 | var i = index(arr, name);
|
1510 | if (!~i) {
|
1511 | arr.push(name);
|
1512 | }
|
1513 |
|
1514 | if (defined(this.el.className.baseVal)) {
|
1515 | this.el.className.baseVal = arr.join(' ');
|
1516 | } else {
|
1517 | this.el.className = arr.join(' ');
|
1518 | }
|
1519 |
|
1520 | return this;
|
1521 | };
|
1522 |
|
1523 | |
1524 |
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 | ClassList$1.prototype.remove = function(name) {
|
1534 | if ('[object RegExp]' === toString$1.call(name)) {
|
1535 | return this.removeMatching(name);
|
1536 | }
|
1537 |
|
1538 |
|
1539 | if (this.list) {
|
1540 | this.list.remove(name);
|
1541 | return this;
|
1542 | }
|
1543 |
|
1544 |
|
1545 | var arr = this.array();
|
1546 | var i = index(arr, name);
|
1547 | if (~i) {
|
1548 | arr.splice(i, 1);
|
1549 | }
|
1550 | this.el.className.baseVal = arr.join(' ');
|
1551 | return this;
|
1552 | };
|
1553 |
|
1554 | |
1555 |
|
1556 |
|
1557 |
|
1558 |
|
1559 |
|
1560 |
|
1561 |
|
1562 | ClassList$1.prototype.removeMatching = function(re) {
|
1563 | var arr = this.array();
|
1564 | for (var i = 0; i < arr.length; i++) {
|
1565 | if (re.test(arr[i])) {
|
1566 | this.remove(arr[i]);
|
1567 | }
|
1568 | }
|
1569 | return this;
|
1570 | };
|
1571 |
|
1572 | |
1573 |
|
1574 |
|
1575 |
|
1576 |
|
1577 |
|
1578 |
|
1579 |
|
1580 |
|
1581 |
|
1582 |
|
1583 |
|
1584 | ClassList$1.prototype.toggle = function(name, force) {
|
1585 |
|
1586 | if (this.list) {
|
1587 | if (defined(force)) {
|
1588 | if (force !== this.list.toggle(name, force)) {
|
1589 | this.list.toggle(name);
|
1590 | }
|
1591 | } else {
|
1592 | this.list.toggle(name);
|
1593 | }
|
1594 | return this;
|
1595 | }
|
1596 |
|
1597 |
|
1598 | if (defined(force)) {
|
1599 | if (!force) {
|
1600 | this.remove(name);
|
1601 | } else {
|
1602 | this.add(name);
|
1603 | }
|
1604 | } else {
|
1605 | if (this.has(name)) {
|
1606 | this.remove(name);
|
1607 | } else {
|
1608 | this.add(name);
|
1609 | }
|
1610 | }
|
1611 |
|
1612 | return this;
|
1613 | };
|
1614 |
|
1615 | |
1616 |
|
1617 |
|
1618 |
|
1619 |
|
1620 |
|
1621 |
|
1622 | ClassList$1.prototype.array = function() {
|
1623 | var className = this.el.getAttribute('class') || '';
|
1624 | var str = className.replace(/^\s+|\s+$/g, '');
|
1625 | var arr = str.split(re$1);
|
1626 | if ('' === arr[0]) {
|
1627 | arr.shift();
|
1628 | }
|
1629 | return arr;
|
1630 | };
|
1631 |
|
1632 | |
1633 |
|
1634 |
|
1635 |
|
1636 |
|
1637 |
|
1638 |
|
1639 |
|
1640 | ClassList$1.prototype.has =
|
1641 | ClassList$1.prototype.contains = function(name) {
|
1642 | return (
|
1643 | this.list ?
|
1644 | this.list.contains(name) :
|
1645 | !! ~index(this.array(), name)
|
1646 | );
|
1647 | };
|
1648 |
|
1649 | function remove$1(element) {
|
1650 | var parent = element.parentNode;
|
1651 |
|
1652 | if (parent) {
|
1653 | parent.removeChild(element);
|
1654 | }
|
1655 |
|
1656 | return element;
|
1657 | }
|
1658 |
|
1659 | |
1660 |
|
1661 |
|
1662 |
|
1663 | |
1664 |
|
1665 |
|
1666 |
|
1667 |
|
1668 |
|
1669 | function clear$1(element) {
|
1670 | var child;
|
1671 |
|
1672 | while ((child = element.firstChild)) {
|
1673 | remove$1(child);
|
1674 | }
|
1675 |
|
1676 | return element;
|
1677 | }
|
1678 |
|
1679 | function clone(element) {
|
1680 | return element.cloneNode(true);
|
1681 | }
|
1682 |
|
1683 | var ns = {
|
1684 | svg: 'http://www.w3.org/2000/svg'
|
1685 | };
|
1686 |
|
1687 | |
1688 |
|
1689 |
|
1690 |
|
1691 | var SVG_START = '<svg xmlns="' + ns.svg + '"';
|
1692 |
|
1693 | function parse$1(svg) {
|
1694 |
|
1695 | var unwrap = false;
|
1696 |
|
1697 |
|
1698 | if (svg.substring(0, 4) === '<svg') {
|
1699 | if (svg.indexOf(ns.svg) === -1) {
|
1700 | svg = SVG_START + svg.substring(4);
|
1701 | }
|
1702 | } else {
|
1703 |
|
1704 | svg = SVG_START + '>' + svg + '</svg>';
|
1705 | unwrap = true;
|
1706 | }
|
1707 |
|
1708 | var parsed = parseDocument(svg);
|
1709 |
|
1710 | if (!unwrap) {
|
1711 | return parsed;
|
1712 | }
|
1713 |
|
1714 | var fragment = document.createDocumentFragment();
|
1715 |
|
1716 | var parent = parsed.firstChild;
|
1717 |
|
1718 | while (parent.firstChild) {
|
1719 | fragment.appendChild(parent.firstChild);
|
1720 | }
|
1721 |
|
1722 | return fragment;
|
1723 | }
|
1724 |
|
1725 | function parseDocument(svg) {
|
1726 |
|
1727 | var parser;
|
1728 |
|
1729 |
|
1730 | parser = new DOMParser();
|
1731 | parser.async = false;
|
1732 |
|
1733 | return parser.parseFromString(svg, 'text/xml');
|
1734 | }
|
1735 |
|
1736 | |
1737 |
|
1738 |
|
1739 |
|
1740 |
|
1741 | |
1742 |
|
1743 |
|
1744 |
|
1745 |
|
1746 |
|
1747 |
|
1748 |
|
1749 | function create(name, attrs) {
|
1750 | var element;
|
1751 |
|
1752 | if (name.charAt(0) === '<') {
|
1753 | element = parse$1(name).firstChild;
|
1754 | element = document.importNode(element, true);
|
1755 | } else {
|
1756 | element = document.createElementNS(ns.svg, name);
|
1757 | }
|
1758 |
|
1759 | if (attrs) {
|
1760 | attr$1(element, attrs);
|
1761 | }
|
1762 |
|
1763 | return element;
|
1764 | }
|
1765 |
|
1766 | |
1767 |
|
1768 |
|
1769 |
|
1770 |
|
1771 | var node = create('svg');
|
1772 |
|
1773 | function extend(object, props) {
|
1774 | var i, k, keys = Object.keys(props);
|
1775 |
|
1776 | for (i = 0; (k = keys[i]); i++) {
|
1777 | object[k] = props[k];
|
1778 | }
|
1779 |
|
1780 | return object;
|
1781 | }
|
1782 |
|
1783 | |
1784 |
|
1785 |
|
1786 |
|
1787 |
|
1788 |
|
1789 |
|
1790 |
|
1791 |
|
1792 |
|
1793 |
|
1794 | function createMatrix(a, b, c, d, e, f) {
|
1795 | var matrix = node.createSVGMatrix();
|
1796 |
|
1797 | switch (arguments.length) {
|
1798 | case 0:
|
1799 | return matrix;
|
1800 | case 1:
|
1801 | return extend(matrix, a);
|
1802 | case 6:
|
1803 | return extend(matrix, {
|
1804 | a: a,
|
1805 | b: b,
|
1806 | c: c,
|
1807 | d: d,
|
1808 | e: e,
|
1809 | f: f
|
1810 | });
|
1811 | }
|
1812 | }
|
1813 |
|
1814 | function createTransform(matrix) {
|
1815 | if (matrix) {
|
1816 | return node.createSVGTransformFromMatrix(matrix);
|
1817 | } else {
|
1818 | return node.createSVGTransform();
|
1819 | }
|
1820 | }
|
1821 |
|
1822 | |
1823 |
|
1824 |
|
1825 |
|
1826 | var TEXT_ENTITIES = /([&<>]{1})/g;
|
1827 | var ATTR_ENTITIES = /([\n\r"]{1})/g;
|
1828 |
|
1829 | var ENTITY_REPLACEMENT = {
|
1830 | '&': '&',
|
1831 | '<': '<',
|
1832 | '>': '>',
|
1833 | '"': '\''
|
1834 | };
|
1835 |
|
1836 | function escape(str, pattern) {
|
1837 |
|
1838 | function replaceFn(match, entity) {
|
1839 | return ENTITY_REPLACEMENT[entity] || entity;
|
1840 | }
|
1841 |
|
1842 | return str.replace(pattern, replaceFn);
|
1843 | }
|
1844 |
|
1845 | function serialize(node, output) {
|
1846 |
|
1847 | var i, len, attrMap, attrNode, childNodes;
|
1848 |
|
1849 | switch (node.nodeType) {
|
1850 |
|
1851 | case 3:
|
1852 |
|
1853 | output.push(escape(node.textContent, TEXT_ENTITIES));
|
1854 | break;
|
1855 |
|
1856 |
|
1857 | case 1:
|
1858 | output.push('<', node.tagName);
|
1859 |
|
1860 | if (node.hasAttributes()) {
|
1861 | attrMap = node.attributes;
|
1862 | for (i = 0, len = attrMap.length; i < len; ++i) {
|
1863 | attrNode = attrMap.item(i);
|
1864 | output.push(' ', attrNode.name, '="', escape(attrNode.value, ATTR_ENTITIES), '"');
|
1865 | }
|
1866 | }
|
1867 |
|
1868 | if (node.hasChildNodes()) {
|
1869 | output.push('>');
|
1870 | childNodes = node.childNodes;
|
1871 | for (i = 0, len = childNodes.length; i < len; ++i) {
|
1872 | serialize(childNodes.item(i), output);
|
1873 | }
|
1874 | output.push('</', node.tagName, '>');
|
1875 | } else {
|
1876 | output.push('/>');
|
1877 | }
|
1878 | break;
|
1879 |
|
1880 |
|
1881 | case 8:
|
1882 | output.push('<!--', escape(node.nodeValue, TEXT_ENTITIES), '-->');
|
1883 | break;
|
1884 |
|
1885 |
|
1886 | case 4:
|
1887 | output.push('<![CDATA[', node.nodeValue, ']]>');
|
1888 | break;
|
1889 |
|
1890 | default:
|
1891 | throw new Error('unable to handle node ' + node.nodeType);
|
1892 | }
|
1893 |
|
1894 | return output;
|
1895 | }
|
1896 |
|
1897 | |
1898 |
|
1899 |
|
1900 |
|
1901 |
|
1902 |
|
1903 | function set(element, svg) {
|
1904 |
|
1905 | var parsed = parse$1(svg);
|
1906 |
|
1907 |
|
1908 | clear$1(element);
|
1909 |
|
1910 | if (!svg) {
|
1911 | return;
|
1912 | }
|
1913 |
|
1914 | if (!isFragment(parsed)) {
|
1915 |
|
1916 | parsed = parsed.documentElement;
|
1917 | }
|
1918 |
|
1919 | var nodes = slice(parsed.childNodes);
|
1920 |
|
1921 |
|
1922 | for (var i = 0; i < nodes.length; i++) {
|
1923 | appendTo(nodes[i], element);
|
1924 | }
|
1925 |
|
1926 | }
|
1927 |
|
1928 | function get(element) {
|
1929 | var child = element.firstChild,
|
1930 | output = [];
|
1931 |
|
1932 | while (child) {
|
1933 | serialize(child, output);
|
1934 | child = child.nextSibling;
|
1935 | }
|
1936 |
|
1937 | return output.join('');
|
1938 | }
|
1939 |
|
1940 | function isFragment(node) {
|
1941 | return node.nodeName === '#document-fragment';
|
1942 | }
|
1943 |
|
1944 | function innerSVG(element, svg) {
|
1945 |
|
1946 | if (svg !== undefined) {
|
1947 |
|
1948 | try {
|
1949 | set(element, svg);
|
1950 | } catch (e) {
|
1951 | throw new Error('error parsing SVG: ' + e.message);
|
1952 | }
|
1953 |
|
1954 | return element;
|
1955 | } else {
|
1956 | return get(element);
|
1957 | }
|
1958 | }
|
1959 |
|
1960 |
|
1961 | function slice(arr) {
|
1962 | return Array.prototype.slice.call(arr);
|
1963 | }
|
1964 |
|
1965 | |
1966 |
|
1967 |
|
1968 |
|
1969 | function wrapMatrix(transformList, transform) {
|
1970 | if (transform instanceof SVGMatrix) {
|
1971 | return transformList.createSVGTransformFromMatrix(transform);
|
1972 | }
|
1973 |
|
1974 | return transform;
|
1975 | }
|
1976 |
|
1977 |
|
1978 | function setTransforms(transformList, transforms) {
|
1979 | var i, t;
|
1980 |
|
1981 | transformList.clear();
|
1982 |
|
1983 | for (i = 0; (t = transforms[i]); i++) {
|
1984 | transformList.appendItem(wrapMatrix(transformList, t));
|
1985 | }
|
1986 | }
|
1987 |
|
1988 | |
1989 |
|
1990 |
|
1991 |
|
1992 |
|
1993 |
|
1994 |
|
1995 |
|
1996 | function transform(node, transforms) {
|
1997 | var transformList = node.transform.baseVal;
|
1998 |
|
1999 | if (transforms) {
|
2000 |
|
2001 | if (!Array.isArray(transforms)) {
|
2002 | transforms = [ transforms ];
|
2003 | }
|
2004 |
|
2005 | setTransforms(transformList, transforms);
|
2006 | }
|
2007 |
|
2008 | return transformList.consolidate();
|
2009 | }
|
2010 |
|
2011 | var CLASS_PATTERN = /^class /;
|
2012 |
|
2013 | function isClass(fn) {
|
2014 | return CLASS_PATTERN.test(fn.toString());
|
2015 | }
|
2016 |
|
2017 | function isArray$1(obj) {
|
2018 | return Object.prototype.toString.call(obj) === '[object Array]';
|
2019 | }
|
2020 |
|
2021 | function annotate() {
|
2022 | var args = Array.prototype.slice.call(arguments);
|
2023 |
|
2024 | if (args.length === 1 && isArray$1(args[0])) {
|
2025 | args = args[0];
|
2026 | }
|
2027 |
|
2028 | var fn = args.pop();
|
2029 |
|
2030 | fn.$inject = args;
|
2031 |
|
2032 | return fn;
|
2033 | }
|
2034 |
|
2035 |
|
2036 |
|
2037 |
|
2038 |
|
2039 |
|
2040 |
|
2041 |
|
2042 |
|
2043 |
|
2044 |
|
2045 |
|
2046 |
|
2047 |
|
2048 | var CONSTRUCTOR_ARGS = /constructor\s*[^(]*\(\s*([^)]*)\)/m;
|
2049 | var FN_ARGS = /^function\s*[^(]*\(\s*([^)]*)\)/m;
|
2050 | var FN_ARG = /\/\*([^*]*)\*\//m;
|
2051 |
|
2052 | function parse$2(fn) {
|
2053 |
|
2054 | if (typeof fn !== 'function') {
|
2055 | throw new Error('Cannot annotate "' + fn + '". Expected a function!');
|
2056 | }
|
2057 |
|
2058 | var match = fn.toString().match(isClass(fn) ? CONSTRUCTOR_ARGS : FN_ARGS);
|
2059 |
|
2060 |
|
2061 | if (!match) {
|
2062 | return [];
|
2063 | }
|
2064 |
|
2065 | return match[1] && match[1].split(',').map(function (arg) {
|
2066 | match = arg.match(FN_ARG);
|
2067 | return match ? match[1].trim() : arg.trim();
|
2068 | }) || [];
|
2069 | }
|
2070 |
|
2071 | function Module() {
|
2072 | var providers = [];
|
2073 |
|
2074 | this.factory = function (name, factory) {
|
2075 | providers.push([name, 'factory', factory]);
|
2076 | return this;
|
2077 | };
|
2078 |
|
2079 | this.value = function (name, value) {
|
2080 | providers.push([name, 'value', value]);
|
2081 | return this;
|
2082 | };
|
2083 |
|
2084 | this.type = function (name, type) {
|
2085 | providers.push([name, 'type', type]);
|
2086 | return this;
|
2087 | };
|
2088 |
|
2089 | this.forEach = function (iterator) {
|
2090 | providers.forEach(iterator);
|
2091 | };
|
2092 | }
|
2093 |
|
2094 | 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; };
|
2095 |
|
2096 | 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); } }
|
2097 |
|
2098 | function Injector(modules, parent) {
|
2099 | parent = parent || {
|
2100 | get: function get(name, strict) {
|
2101 | currentlyResolving.push(name);
|
2102 |
|
2103 | if (strict === false) {
|
2104 | return null;
|
2105 | } else {
|
2106 | throw error('No provider for "' + name + '"!');
|
2107 | }
|
2108 | }
|
2109 | };
|
2110 |
|
2111 | var currentlyResolving = [];
|
2112 | var providers = this._providers = Object.create(parent._providers || null);
|
2113 | var instances = this._instances = Object.create(null);
|
2114 |
|
2115 | var self = instances.injector = this;
|
2116 |
|
2117 | var error = function error(msg) {
|
2118 | var stack = currentlyResolving.join(' -> ');
|
2119 | currentlyResolving.length = 0;
|
2120 | return new Error(stack ? msg + ' (Resolving: ' + stack + ')' : msg);
|
2121 | };
|
2122 |
|
2123 | |
2124 |
|
2125 |
|
2126 |
|
2127 |
|
2128 |
|
2129 |
|
2130 |
|
2131 | var get = function get(name, strict) {
|
2132 | if (!providers[name] && name.indexOf('.') !== -1) {
|
2133 | var parts = name.split('.');
|
2134 | var pivot = get(parts.shift());
|
2135 |
|
2136 | while (parts.length) {
|
2137 | pivot = pivot[parts.shift()];
|
2138 | }
|
2139 |
|
2140 | return pivot;
|
2141 | }
|
2142 |
|
2143 | if (hasProp(instances, name)) {
|
2144 | return instances[name];
|
2145 | }
|
2146 |
|
2147 | if (hasProp(providers, name)) {
|
2148 | if (currentlyResolving.indexOf(name) !== -1) {
|
2149 | currentlyResolving.push(name);
|
2150 | throw error('Cannot resolve circular dependency!');
|
2151 | }
|
2152 |
|
2153 | currentlyResolving.push(name);
|
2154 | instances[name] = providers[name][0](providers[name][1]);
|
2155 | currentlyResolving.pop();
|
2156 |
|
2157 | return instances[name];
|
2158 | }
|
2159 |
|
2160 | return parent.get(name, strict);
|
2161 | };
|
2162 |
|
2163 | var fnDef = function fnDef(fn) {
|
2164 | var locals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
2165 |
|
2166 | if (typeof fn !== 'function') {
|
2167 | if (isArray$1(fn)) {
|
2168 | fn = annotate(fn.slice());
|
2169 | } else {
|
2170 | throw new Error('Cannot invoke "' + fn + '". Expected a function!');
|
2171 | }
|
2172 | }
|
2173 |
|
2174 | var inject = fn.$inject || parse$2(fn);
|
2175 | var dependencies = inject.map(function (dep) {
|
2176 | if (hasProp(locals, dep)) {
|
2177 | return locals[dep];
|
2178 | } else {
|
2179 | return get(dep);
|
2180 | }
|
2181 | });
|
2182 |
|
2183 | return {
|
2184 | fn: fn,
|
2185 | dependencies: dependencies
|
2186 | };
|
2187 | };
|
2188 |
|
2189 | var instantiate = function instantiate(Type) {
|
2190 | var _fnDef = fnDef(Type),
|
2191 | dependencies = _fnDef.dependencies,
|
2192 | fn = _fnDef.fn;
|
2193 |
|
2194 | return new (Function.prototype.bind.apply(fn, [null].concat(_toConsumableArray(dependencies))))();
|
2195 | };
|
2196 |
|
2197 | var invoke = function invoke(func, context, locals) {
|
2198 | var _fnDef2 = fnDef(func, locals),
|
2199 | dependencies = _fnDef2.dependencies,
|
2200 | fn = _fnDef2.fn;
|
2201 |
|
2202 | return fn.call.apply(fn, [context].concat(_toConsumableArray(dependencies)));
|
2203 | };
|
2204 |
|
2205 | var createPrivateInjectorFactory = function createPrivateInjectorFactory(privateChildInjector) {
|
2206 | return annotate(function (key) {
|
2207 | return privateChildInjector.get(key);
|
2208 | });
|
2209 | };
|
2210 |
|
2211 | var createChild = function createChild(modules, forceNewInstances) {
|
2212 | if (forceNewInstances && forceNewInstances.length) {
|
2213 | var fromParentModule = Object.create(null);
|
2214 | var matchedScopes = Object.create(null);
|
2215 |
|
2216 | var privateInjectorsCache = [];
|
2217 | var privateChildInjectors = [];
|
2218 | var privateChildFactories = [];
|
2219 |
|
2220 | var provider;
|
2221 | var cacheIdx;
|
2222 | var privateChildInjector;
|
2223 | var privateChildInjectorFactory;
|
2224 | for (var name in providers) {
|
2225 | provider = providers[name];
|
2226 |
|
2227 | if (forceNewInstances.indexOf(name) !== -1) {
|
2228 | if (provider[2] === 'private') {
|
2229 | cacheIdx = privateInjectorsCache.indexOf(provider[3]);
|
2230 | if (cacheIdx === -1) {
|
2231 | privateChildInjector = provider[3].createChild([], forceNewInstances);
|
2232 | privateChildInjectorFactory = createPrivateInjectorFactory(privateChildInjector);
|
2233 | privateInjectorsCache.push(provider[3]);
|
2234 | privateChildInjectors.push(privateChildInjector);
|
2235 | privateChildFactories.push(privateChildInjectorFactory);
|
2236 | fromParentModule[name] = [privateChildInjectorFactory, name, 'private', privateChildInjector];
|
2237 | } else {
|
2238 | fromParentModule[name] = [privateChildFactories[cacheIdx], name, 'private', privateChildInjectors[cacheIdx]];
|
2239 | }
|
2240 | } else {
|
2241 | fromParentModule[name] = [provider[2], provider[1]];
|
2242 | }
|
2243 | matchedScopes[name] = true;
|
2244 | }
|
2245 |
|
2246 | if ((provider[2] === 'factory' || provider[2] === 'type') && provider[1].$scope) {
|
2247 |
|
2248 | forceNewInstances.forEach(function (scope) {
|
2249 | if (provider[1].$scope.indexOf(scope) !== -1) {
|
2250 | fromParentModule[name] = [provider[2], provider[1]];
|
2251 | matchedScopes[scope] = true;
|
2252 | }
|
2253 | });
|
2254 | }
|
2255 | }
|
2256 |
|
2257 | forceNewInstances.forEach(function (scope) {
|
2258 | if (!matchedScopes[scope]) {
|
2259 | throw new Error('No provider for "' + scope + '". Cannot use provider from the parent!');
|
2260 | }
|
2261 | });
|
2262 |
|
2263 | modules.unshift(fromParentModule);
|
2264 | }
|
2265 |
|
2266 | return new Injector(modules, self);
|
2267 | };
|
2268 |
|
2269 | var factoryMap = {
|
2270 | factory: invoke,
|
2271 | type: instantiate,
|
2272 | value: function value(_value) {
|
2273 | return _value;
|
2274 | }
|
2275 | };
|
2276 |
|
2277 | modules.forEach(function (module) {
|
2278 |
|
2279 | function arrayUnwrap(type, value) {
|
2280 | if (type !== 'value' && isArray$1(value)) {
|
2281 | value = annotate(value.slice());
|
2282 | }
|
2283 |
|
2284 | return value;
|
2285 | }
|
2286 |
|
2287 |
|
2288 | if (module instanceof Module) {
|
2289 | module.forEach(function (provider) {
|
2290 | var name = provider[0];
|
2291 | var type = provider[1];
|
2292 | var value = provider[2];
|
2293 |
|
2294 | providers[name] = [factoryMap[type], arrayUnwrap(type, value), type];
|
2295 | });
|
2296 | } else if ((typeof module === 'undefined' ? 'undefined' : _typeof(module)) === 'object') {
|
2297 | if (module.__exports__) {
|
2298 | var clonedModule = Object.keys(module).reduce(function (m, key) {
|
2299 | if (key.substring(0, 2) !== '__') {
|
2300 | m[key] = module[key];
|
2301 | }
|
2302 | return m;
|
2303 | }, Object.create(null));
|
2304 |
|
2305 | var privateInjector = new Injector((module.__modules__ || []).concat([clonedModule]), self);
|
2306 | var getFromPrivateInjector = annotate(function (key) {
|
2307 | return privateInjector.get(key);
|
2308 | });
|
2309 | module.__exports__.forEach(function (key) {
|
2310 | providers[key] = [getFromPrivateInjector, key, 'private', privateInjector];
|
2311 | });
|
2312 | } else {
|
2313 | Object.keys(module).forEach(function (name) {
|
2314 | if (module[name][2] === 'private') {
|
2315 | providers[name] = module[name];
|
2316 | return;
|
2317 | }
|
2318 |
|
2319 | var type = module[name][0];
|
2320 | var value = module[name][1];
|
2321 |
|
2322 | providers[name] = [factoryMap[type], arrayUnwrap(type, value), type];
|
2323 | });
|
2324 | }
|
2325 | }
|
2326 | });
|
2327 |
|
2328 |
|
2329 | this.get = get;
|
2330 | this.invoke = invoke;
|
2331 | this.instantiate = instantiate;
|
2332 | this.createChild = createChild;
|
2333 | }
|
2334 |
|
2335 | // helpers /////////////////
|
2336 |
|
2337 | function hasProp(obj, prop) {
|
2338 | return Object.hasOwnProperty.call(obj, prop);
|
2339 | }
|
2340 |
|
2341 | var DEFAULT_RENDER_PRIORITY = 1000;
|
2342 |
|
2343 | |
2344 |
|
2345 |
|
2346 |
|
2347 |
|
2348 |
|
2349 | function BaseRenderer(eventBus, renderPriority) {
|
2350 | var self = this;
|
2351 |
|
2352 | renderPriority = renderPriority || DEFAULT_RENDER_PRIORITY;
|
2353 |
|
2354 | eventBus.on([ 'render.shape', 'render.connection' ], renderPriority, function(evt, context) {
|
2355 | var type = evt.type,
|
2356 | element = context.element,
|
2357 | visuals = context.gfx;
|
2358 |
|
2359 | if (self.canRender(element)) {
|
2360 | if (type === 'render.shape') {
|
2361 | return self.drawShape(visuals, element);
|
2362 | } else {
|
2363 | return self.drawConnection(visuals, element);
|
2364 | }
|
2365 | }
|
2366 | });
|
2367 |
|
2368 | eventBus.on([ 'render.getShapePath', 'render.getConnectionPath'], renderPriority, function(evt, element) {
|
2369 | if (self.canRender(element)) {
|
2370 | if (evt.type === 'render.getShapePath') {
|
2371 | return self.getShapePath(element);
|
2372 | } else {
|
2373 | return self.getConnectionPath(element);
|
2374 | }
|
2375 | }
|
2376 | });
|
2377 | }
|
2378 |
|
2379 | |
2380 |
|
2381 |
|
2382 |
|
2383 |
|
2384 |
|
2385 |
|
2386 |
|
2387 | BaseRenderer.prototype.canRender = function() {};
|
2388 |
|
2389 | |
2390 |
|
2391 |
|
2392 |
|
2393 |
|
2394 |
|
2395 |
|
2396 |
|
2397 | BaseRenderer.prototype.drawShape = function() {};
|
2398 |
|
2399 | |
2400 |
|
2401 |
|
2402 |
|
2403 |
|
2404 |
|
2405 |
|
2406 |
|
2407 | BaseRenderer.prototype.drawConnection = function() {};
|
2408 |
|
2409 | |
2410 |
|
2411 |
|
2412 |
|
2413 |
|
2414 |
|
2415 |
|
2416 | BaseRenderer.prototype.getShapePath = function() {};
|
2417 |
|
2418 | |
2419 |
|
2420 |
|
2421 |
|
2422 |
|
2423 |
|
2424 |
|
2425 | BaseRenderer.prototype.getConnectionPath = function() {};
|
2426 |
|
2427 | function componentsToPath(elements) {
|
2428 | return elements.join(',').replace(/,?([A-z]),?/g, '$1');
|
2429 | }
|
2430 |
|
2431 | function toSVGPoints(points) {
|
2432 | var result = '';
|
2433 |
|
2434 | for (var i = 0, p; (p = points[i]); i++) {
|
2435 | result += p.x + ',' + p.y + ' ';
|
2436 | }
|
2437 |
|
2438 | return result;
|
2439 | }
|
2440 |
|
2441 | function createLine(points, attrs) {
|
2442 |
|
2443 | var line = create('polyline');
|
2444 | attr$1(line, { points: toSVGPoints(points) });
|
2445 |
|
2446 | if (attrs) {
|
2447 | attr$1(line, attrs);
|
2448 | }
|
2449 |
|
2450 | return line;
|
2451 | }
|
2452 |
|
2453 | function updateLine(gfx, points) {
|
2454 | attr$1(gfx, { points: toSVGPoints(points) });
|
2455 |
|
2456 | return gfx;
|
2457 | }
|
2458 |
|
2459 | |
2460 |
|
2461 |
|
2462 |
|
2463 |
|
2464 |
|
2465 |
|
2466 | function getParents(elements) {
|
2467 |
|
2468 |
|
2469 | return filter(elements, function(element) {
|
2470 | return !find(elements, function(e) {
|
2471 | return e !== element && getParent(element, e);
|
2472 | });
|
2473 | });
|
2474 | }
|
2475 |
|
2476 |
|
2477 | function getParent(element, parent) {
|
2478 | if (!parent) {
|
2479 | return;
|
2480 | }
|
2481 |
|
2482 | if (element === parent) {
|
2483 | return parent;
|
2484 | }
|
2485 |
|
2486 | if (!element.parent) {
|
2487 | return;
|
2488 | }
|
2489 |
|
2490 | return getParent(element.parent, parent);
|
2491 | }
|
2492 |
|
2493 |
|
2494 | |
2495 |
|
2496 |
|
2497 |
|
2498 |
|
2499 |
|
2500 |
|
2501 |
|
2502 | function add(elements, e, unique) {
|
2503 | var canAdd = !unique || elements.indexOf(e) === -1;
|
2504 |
|
2505 | if (canAdd) {
|
2506 | elements.push(e);
|
2507 | }
|
2508 |
|
2509 | return canAdd;
|
2510 | }
|
2511 |
|
2512 |
|
2513 | |
2514 |
|
2515 |
|
2516 |
|
2517 |
|
2518 |
|
2519 |
|
2520 |
|
2521 |
|
2522 |
|
2523 | function eachElement(elements, fn, depth) {
|
2524 |
|
2525 | depth = depth || 0;
|
2526 |
|
2527 | if (!isArray(elements)) {
|
2528 | elements = [ elements ];
|
2529 | }
|
2530 |
|
2531 | forEach(elements, function(s, i) {
|
2532 | var filter = fn(s, i, depth);
|
2533 |
|
2534 | if (isArray(filter) && filter.length) {
|
2535 | eachElement(filter, fn, depth + 1);
|
2536 | }
|
2537 | });
|
2538 | }
|
2539 |
|
2540 |
|
2541 | |
2542 |
|
2543 |
|
2544 |
|
2545 |
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 | function selfAndChildren(elements, unique, maxDepth) {
|
2551 | var result = [],
|
2552 | processedChildren = [];
|
2553 |
|
2554 | eachElement(elements, function(element, i, depth) {
|
2555 | add(result, element, unique);
|
2556 |
|
2557 | var children = element.children;
|
2558 |
|
2559 |
|
2560 | if (maxDepth === -1 || depth < maxDepth) {
|
2561 |
|
2562 |
|
2563 | if (children && add(processedChildren, children, unique)) {
|
2564 | return children;
|
2565 | }
|
2566 | }
|
2567 | });
|
2568 |
|
2569 | return result;
|
2570 | }
|
2571 |
|
2572 |
|
2573 | |
2574 |
|
2575 |
|
2576 |
|
2577 |
|
2578 |
|
2579 |
|
2580 |
|
2581 | function selfAndAllChildren(elements, allowDuplicates) {
|
2582 | return selfAndChildren(elements, !allowDuplicates, -1);
|
2583 | }
|
2584 |
|
2585 |
|
2586 | |
2587 |
|
2588 |
|
2589 |
|
2590 |
|
2591 |
|
2592 |
|
2593 |
|
2594 |
|
2595 |
|
2596 | function getClosure(elements, isTopLevel, closure) {
|
2597 |
|
2598 | if (isUndefined(isTopLevel)) {
|
2599 | isTopLevel = true;
|
2600 | }
|
2601 |
|
2602 | if (isObject(isTopLevel)) {
|
2603 | closure = isTopLevel;
|
2604 | isTopLevel = true;
|
2605 | }
|
2606 |
|
2607 |
|
2608 | closure = closure || {};
|
2609 |
|
2610 | var allShapes = copyObject(closure.allShapes),
|
2611 | allConnections = copyObject(closure.allConnections),
|
2612 | enclosedElements = copyObject(closure.enclosedElements),
|
2613 | enclosedConnections = copyObject(closure.enclosedConnections);
|
2614 |
|
2615 | var topLevel = copyObject(
|
2616 | closure.topLevel,
|
2617 | isTopLevel && groupBy(elements, function(e) { return e.id; })
|
2618 | );
|
2619 |
|
2620 |
|
2621 | function handleConnection(c) {
|
2622 | if (topLevel[c.source.id] && topLevel[c.target.id]) {
|
2623 | topLevel[c.id] = [ c ];
|
2624 | }
|
2625 |
|
2626 |
|
2627 |
|
2628 | if (allShapes[c.source.id] && allShapes[c.target.id]) {
|
2629 | enclosedConnections[c.id] = enclosedElements[c.id] = c;
|
2630 | }
|
2631 |
|
2632 | allConnections[c.id] = c;
|
2633 | }
|
2634 |
|
2635 | function handleElement(element) {
|
2636 |
|
2637 | enclosedElements[element.id] = element;
|
2638 |
|
2639 | if (element.waypoints) {
|
2640 |
|
2641 |
|
2642 | enclosedConnections[element.id] = allConnections[element.id] = element;
|
2643 | } else {
|
2644 |
|
2645 |
|
2646 | allShapes[element.id] = element;
|
2647 |
|
2648 |
|
2649 | forEach(element.incoming, handleConnection);
|
2650 |
|
2651 | forEach(element.outgoing, handleConnection);
|
2652 |
|
2653 |
|
2654 | return element.children;
|
2655 | }
|
2656 | }
|
2657 |
|
2658 | eachElement(elements, handleElement);
|
2659 |
|
2660 | return {
|
2661 | allShapes: allShapes,
|
2662 | allConnections: allConnections,
|
2663 | topLevel: topLevel,
|
2664 | enclosedConnections: enclosedConnections,
|
2665 | enclosedElements: enclosedElements
|
2666 | };
|
2667 | }
|
2668 |
|
2669 | |
2670 |
|
2671 |
|
2672 |
|
2673 |
|
2674 |
|
2675 |
|
2676 | function getBBox(elements, stopRecursion) {
|
2677 |
|
2678 | stopRecursion = !!stopRecursion;
|
2679 | if (!isArray(elements)) {
|
2680 | elements = [elements];
|
2681 | }
|
2682 |
|
2683 | var minX,
|
2684 | minY,
|
2685 | maxX,
|
2686 | maxY;
|
2687 |
|
2688 | forEach(elements, function(element) {
|
2689 |
|
2690 |
|
2691 | var bbox = element;
|
2692 | if (element.waypoints && !stopRecursion) {
|
2693 | bbox = getBBox(element.waypoints, true);
|
2694 | }
|
2695 |
|
2696 | var x = bbox.x,
|
2697 | y = bbox.y,
|
2698 | height = bbox.height || 0,
|
2699 | width = bbox.width || 0;
|
2700 |
|
2701 | if (x < minX || minX === undefined) {
|
2702 | minX = x;
|
2703 | }
|
2704 | if (y < minY || minY === undefined) {
|
2705 | minY = y;
|
2706 | }
|
2707 |
|
2708 | if ((x + width) > maxX || maxX === undefined) {
|
2709 | maxX = x + width;
|
2710 | }
|
2711 | if ((y + height) > maxY || maxY === undefined) {
|
2712 | maxY = y + height;
|
2713 | }
|
2714 | });
|
2715 |
|
2716 | return {
|
2717 | x: minX,
|
2718 | y: minY,
|
2719 | height: maxY - minY,
|
2720 | width: maxX - minX
|
2721 | };
|
2722 | }
|
2723 |
|
2724 |
|
2725 | |
2726 |
|
2727 |
|
2728 |
|
2729 |
|
2730 |
|
2731 |
|
2732 |
|
2733 |
|
2734 |
|
2735 |
|
2736 |
|
2737 |
|
2738 | function getEnclosedElements(elements, bbox) {
|
2739 |
|
2740 | var filteredElements = {};
|
2741 |
|
2742 | forEach(elements, function(element) {
|
2743 |
|
2744 | var e = element;
|
2745 |
|
2746 | if (e.waypoints) {
|
2747 | e = getBBox(e);
|
2748 | }
|
2749 |
|
2750 | if (!isNumber(bbox.y) && (e.x > bbox.x)) {
|
2751 | filteredElements[element.id] = element;
|
2752 | }
|
2753 | if (!isNumber(bbox.x) && (e.y > bbox.y)) {
|
2754 | filteredElements[element.id] = element;
|
2755 | }
|
2756 | if (e.x > bbox.x && e.y > bbox.y) {
|
2757 | if (isNumber(bbox.width) && isNumber(bbox.height) &&
|
2758 | e.width + e.x < bbox.width + bbox.x &&
|
2759 | e.height + e.y < bbox.height + bbox.y) {
|
2760 |
|
2761 | filteredElements[element.id] = element;
|
2762 | } else if (!isNumber(bbox.width) || !isNumber(bbox.height)) {
|
2763 | filteredElements[element.id] = element;
|
2764 | }
|
2765 | }
|
2766 | });
|
2767 |
|
2768 | return filteredElements;
|
2769 | }
|
2770 |
|
2771 |
|
2772 | function getType(element) {
|
2773 |
|
2774 | if ('waypoints' in element) {
|
2775 | return 'connection';
|
2776 | }
|
2777 |
|
2778 | if ('x' in element) {
|
2779 | return 'shape';
|
2780 | }
|
2781 |
|
2782 | return 'root';
|
2783 | }
|
2784 |
|
2785 | function isFrameElement(element) {
|
2786 |
|
2787 | return !!(element && element.isFrame);
|
2788 | }
|
2789 |
|
2790 |
|
2791 |
|
2792 | function copyObject(src1, src2) {
|
2793 | return assign({}, src1 || {}, src2 || {});
|
2794 | }
|
2795 |
|
2796 |
|
2797 |
|
2798 | var DEFAULT_RENDER_PRIORITY$1 = 1;
|
2799 |
|
2800 | |
2801 |
|
2802 |
|
2803 |
|
2804 |
|
2805 |
|
2806 | function DefaultRenderer(eventBus, styles) {
|
2807 |
|
2808 |
|
2809 | BaseRenderer.call(this, eventBus, DEFAULT_RENDER_PRIORITY$1);
|
2810 |
|
2811 | this.CONNECTION_STYLE = styles.style([ 'no-fill' ], { strokeWidth: 5, stroke: 'fuchsia' });
|
2812 | this.SHAPE_STYLE = styles.style({ fill: 'white', stroke: 'fuchsia', strokeWidth: 2 });
|
2813 | this.FRAME_STYLE = styles.style([ 'no-fill' ], { stroke: 'fuchsia', strokeDasharray: 4, strokeWidth: 2 });
|
2814 | }
|
2815 |
|
2816 | inherits_browser(DefaultRenderer, BaseRenderer);
|
2817 |
|
2818 |
|
2819 | DefaultRenderer.prototype.canRender = function() {
|
2820 | return true;
|
2821 | };
|
2822 |
|
2823 | DefaultRenderer.prototype.drawShape = function drawShape(visuals, element) {
|
2824 | var rect = create('rect');
|
2825 |
|
2826 | attr$1(rect, {
|
2827 | x: 0,
|
2828 | y: 0,
|
2829 | width: element.width || 0,
|
2830 | height: element.height || 0
|
2831 | });
|
2832 |
|
2833 | if (isFrameElement(element)) {
|
2834 | attr$1(rect, this.FRAME_STYLE);
|
2835 | } else {
|
2836 | attr$1(rect, this.SHAPE_STYLE);
|
2837 | }
|
2838 |
|
2839 | append(visuals, rect);
|
2840 |
|
2841 | return rect;
|
2842 | };
|
2843 |
|
2844 | DefaultRenderer.prototype.drawConnection = function drawConnection(visuals, connection) {
|
2845 |
|
2846 | var line = createLine(connection.waypoints, this.CONNECTION_STYLE);
|
2847 | append(visuals, line);
|
2848 |
|
2849 | return line;
|
2850 | };
|
2851 |
|
2852 | DefaultRenderer.prototype.getShapePath = function getShapePath(shape) {
|
2853 |
|
2854 | var x = shape.x,
|
2855 | y = shape.y,
|
2856 | width = shape.width,
|
2857 | height = shape.height;
|
2858 |
|
2859 | var shapePath = [
|
2860 | ['M', x, y],
|
2861 | ['l', width, 0],
|
2862 | ['l', 0, height],
|
2863 | ['l', -width, 0],
|
2864 | ['z']
|
2865 | ];
|
2866 |
|
2867 | return componentsToPath(shapePath);
|
2868 | };
|
2869 |
|
2870 | DefaultRenderer.prototype.getConnectionPath = function getConnectionPath(connection) {
|
2871 | var waypoints = connection.waypoints;
|
2872 |
|
2873 | var idx, point, connectionPath = [];
|
2874 |
|
2875 | for (idx = 0; (point = waypoints[idx]); idx++) {
|
2876 |
|
2877 |
|
2878 |
|
2879 | point = point.original || point;
|
2880 |
|
2881 | connectionPath.push([ idx === 0 ? 'M' : 'L', point.x, point.y ]);
|
2882 | }
|
2883 |
|
2884 | return componentsToPath(connectionPath);
|
2885 | };
|
2886 |
|
2887 |
|
2888 | DefaultRenderer.$inject = [ 'eventBus', 'styles' ];
|
2889 |
|
2890 | |
2891 |
|
2892 |
|
2893 | function Styles() {
|
2894 |
|
2895 | var defaultTraits = {
|
2896 |
|
2897 | 'no-fill': {
|
2898 | fill: 'none'
|
2899 | },
|
2900 | 'no-border': {
|
2901 | strokeOpacity: 0.0
|
2902 | },
|
2903 | 'no-events': {
|
2904 | pointerEvents: 'none'
|
2905 | }
|
2906 | };
|
2907 |
|
2908 | var self = this;
|
2909 |
|
2910 | |
2911 |
|
2912 |
|
2913 |
|
2914 |
|
2915 |
|
2916 |
|
2917 |
|
2918 |
|
2919 | this.cls = function(className, traits, additionalAttrs) {
|
2920 | var attrs = this.style(traits, additionalAttrs);
|
2921 |
|
2922 | return assign(attrs, { 'class': className });
|
2923 | };
|
2924 |
|
2925 | |
2926 |
|
2927 |
|
2928 |
|
2929 |
|
2930 |
|
2931 |
|
2932 |
|
2933 | this.style = function(traits, additionalAttrs) {
|
2934 |
|
2935 | if (!isArray(traits) && !additionalAttrs) {
|
2936 | additionalAttrs = traits;
|
2937 | traits = [];
|
2938 | }
|
2939 |
|
2940 | var attrs = reduce(traits, function(attrs, t) {
|
2941 | return assign(attrs, defaultTraits[t] || {});
|
2942 | }, {});
|
2943 |
|
2944 | return additionalAttrs ? assign(attrs, additionalAttrs) : attrs;
|
2945 | };
|
2946 |
|
2947 | this.computeStyle = function(custom, traits, defaultStyles) {
|
2948 | if (!isArray(traits)) {
|
2949 | defaultStyles = traits;
|
2950 | traits = [];
|
2951 | }
|
2952 |
|
2953 | return self.style(traits || [], assign({}, defaultStyles, custom || {}));
|
2954 | };
|
2955 | }
|
2956 |
|
2957 | var DrawModule = {
|
2958 | __init__: [ 'defaultRenderer' ],
|
2959 | defaultRenderer: [ 'type', DefaultRenderer ],
|
2960 | styles: [ 'type', Styles ]
|
2961 | };
|
2962 |
|
2963 | |
2964 |
|
2965 |
|
2966 |
|
2967 |
|
2968 |
|
2969 |
|
2970 |
|
2971 | function remove$2(collection, element) {
|
2972 |
|
2973 | if (!collection || !element) {
|
2974 | return -1;
|
2975 | }
|
2976 |
|
2977 | var idx = collection.indexOf(element);
|
2978 |
|
2979 | if (idx !== -1) {
|
2980 | collection.splice(idx, 1);
|
2981 | }
|
2982 |
|
2983 | return idx;
|
2984 | }
|
2985 |
|
2986 | |
2987 |
|
2988 |
|
2989 |
|
2990 |
|
2991 |
|
2992 |
|
2993 |
|
2994 | function add$1(collection, element, idx) {
|
2995 |
|
2996 | if (!collection || !element) {
|
2997 | return;
|
2998 | }
|
2999 |
|
3000 | if (typeof idx !== 'number') {
|
3001 | idx = -1;
|
3002 | }
|
3003 |
|
3004 | var currentIdx = collection.indexOf(element);
|
3005 |
|
3006 | if (currentIdx !== -1) {
|
3007 |
|
3008 | if (currentIdx === idx) {
|
3009 |
|
3010 |
|
3011 | return;
|
3012 | } else {
|
3013 |
|
3014 | if (idx !== -1) {
|
3015 |
|
3016 |
|
3017 | collection.splice(currentIdx, 1);
|
3018 | } else {
|
3019 |
|
3020 |
|
3021 | return;
|
3022 | }
|
3023 | }
|
3024 | }
|
3025 |
|
3026 | if (idx !== -1) {
|
3027 |
|
3028 |
|
3029 | collection.splice(idx, 0, element);
|
3030 | } else {
|
3031 |
|
3032 |
|
3033 | collection.push(element);
|
3034 | }
|
3035 | }
|
3036 |
|
3037 |
|
3038 | |
3039 |
|
3040 |
|
3041 |
|
3042 |
|
3043 |
|
3044 |
|
3045 |
|
3046 |
|
3047 | function indexOf$1(collection, element) {
|
3048 |
|
3049 | if (!collection || !element) {
|
3050 | return -1;
|
3051 | }
|
3052 |
|
3053 | return collection.indexOf(element);
|
3054 | }
|
3055 |
|
3056 | function round(number, resolution) {
|
3057 | return Math.round(number * resolution) / resolution;
|
3058 | }
|
3059 |
|
3060 | function ensurePx(number) {
|
3061 | return isNumber(number) ? number + 'px' : number;
|
3062 | }
|
3063 |
|
3064 | |
3065 |
|
3066 |
|
3067 |
|
3068 |
|
3069 |
|
3070 |
|
3071 | function createContainer(options) {
|
3072 |
|
3073 | options = assign({}, { width: '100%', height: '100%' }, options);
|
3074 |
|
3075 | var container = options.container || document.body;
|
3076 |
|
3077 |
|
3078 |
|
3079 |
|
3080 | var parent = document.createElement('div');
|
3081 | parent.setAttribute('class', 'djs-container');
|
3082 |
|
3083 | assign(parent.style, {
|
3084 | position: 'relative',
|
3085 | overflow: 'hidden',
|
3086 | width: ensurePx(options.width),
|
3087 | height: ensurePx(options.height)
|
3088 | });
|
3089 |
|
3090 | container.appendChild(parent);
|
3091 |
|
3092 | return parent;
|
3093 | }
|
3094 |
|
3095 | function createGroup(parent, cls, childIndex) {
|
3096 | var group = create('g');
|
3097 | classes$1(group).add(cls);
|
3098 |
|
3099 | var index = childIndex !== undefined ? childIndex : parent.childNodes.length - 1;
|
3100 |
|
3101 |
|
3102 |
|
3103 | parent.insertBefore(group, parent.childNodes[index] || null);
|
3104 |
|
3105 | return group;
|
3106 | }
|
3107 |
|
3108 | var BASE_LAYER = 'base';
|
3109 |
|
3110 |
|
3111 | var REQUIRED_MODEL_ATTRS = {
|
3112 | shape: [ 'x', 'y', 'width', 'height' ],
|
3113 | connection: [ 'waypoints' ]
|
3114 | };
|
3115 |
|
3116 | |
3117 |
|
3118 |
|
3119 |
|
3120 |
|
3121 |
|
3122 |
|
3123 |
|
3124 |
|
3125 |
|
3126 |
|
3127 |
|
3128 |
|
3129 | function Canvas(config, eventBus, graphicsFactory, elementRegistry) {
|
3130 |
|
3131 | this._eventBus = eventBus;
|
3132 | this._elementRegistry = elementRegistry;
|
3133 | this._graphicsFactory = graphicsFactory;
|
3134 |
|
3135 | this._init(config || {});
|
3136 | }
|
3137 |
|
3138 | Canvas.$inject = [
|
3139 | 'config.canvas',
|
3140 | 'eventBus',
|
3141 | 'graphicsFactory',
|
3142 | 'elementRegistry'
|
3143 | ];
|
3144 |
|
3145 |
|
3146 | Canvas.prototype._init = function(config) {
|
3147 |
|
3148 | var eventBus = this._eventBus;
|
3149 |
|
3150 |
|
3151 |
|
3152 |
|
3153 |
|
3154 |
|
3155 |
|
3156 |
|
3157 |
|
3158 |
|
3159 |
|
3160 |
|
3161 |
|
3162 |
|
3163 | var container = this._container = createContainer(config);
|
3164 |
|
3165 | var svg = this._svg = create('svg');
|
3166 | attr$1(svg, { width: '100%', height: '100%' });
|
3167 |
|
3168 | append(container, svg);
|
3169 |
|
3170 | var viewport = this._viewport = createGroup(svg, 'viewport');
|
3171 |
|
3172 | this._layers = {};
|
3173 |
|
3174 |
|
3175 |
|
3176 | if (config.deferUpdate !== false) {
|
3177 | this._viewboxChanged = debounce(bind(this._viewboxChanged, this), 300);
|
3178 | }
|
3179 |
|
3180 | eventBus.on('diagram.init', function() {
|
3181 |
|
3182 | |
3183 |
|
3184 |
|
3185 |
|
3186 |
|
3187 |
|
3188 |
|
3189 |
|
3190 |
|
3191 |
|
3192 |
|
3193 | eventBus.fire('canvas.init', {
|
3194 | svg: svg,
|
3195 | viewport: viewport
|
3196 | });
|
3197 |
|
3198 | }, this);
|
3199 |
|
3200 |
|
3201 |
|
3202 | eventBus.on([
|
3203 | 'shape.added',
|
3204 | 'connection.added',
|
3205 | 'shape.removed',
|
3206 | 'connection.removed',
|
3207 | 'elements.changed'
|
3208 | ], function() {
|
3209 | delete this._cachedViewbox;
|
3210 | }, this);
|
3211 |
|
3212 | eventBus.on('diagram.destroy', 500, this._destroy, this);
|
3213 | eventBus.on('diagram.clear', 500, this._clear, this);
|
3214 | };
|
3215 |
|
3216 | Canvas.prototype._destroy = function(emit) {
|
3217 | this._eventBus.fire('canvas.destroy', {
|
3218 | svg: this._svg,
|
3219 | viewport: this._viewport
|
3220 | });
|
3221 |
|
3222 | var parent = this._container.parentNode;
|
3223 |
|
3224 | if (parent) {
|
3225 | parent.removeChild(this._container);
|
3226 | }
|
3227 |
|
3228 | delete this._svg;
|
3229 | delete this._container;
|
3230 | delete this._layers;
|
3231 | delete this._rootElement;
|
3232 | delete this._viewport;
|
3233 | };
|
3234 |
|
3235 | Canvas.prototype._clear = function() {
|
3236 |
|
3237 | var self = this;
|
3238 |
|
3239 | var allElements = this._elementRegistry.getAll();
|
3240 |
|
3241 |
|
3242 | allElements.forEach(function(element) {
|
3243 | var type = getType(element);
|
3244 |
|
3245 | if (type === 'root') {
|
3246 | self.setRootElement(null, true);
|
3247 | } else {
|
3248 | self._removeElement(element, type);
|
3249 | }
|
3250 | });
|
3251 |
|
3252 |
|
3253 | delete this._cachedViewbox;
|
3254 | };
|
3255 |
|
3256 | |
3257 |
|
3258 |
|
3259 |
|
3260 |
|
3261 |
|
3262 | Canvas.prototype.getDefaultLayer = function() {
|
3263 | return this.getLayer(BASE_LAYER, 0);
|
3264 | };
|
3265 |
|
3266 | |
3267 |
|
3268 |
|
3269 |
|
3270 |
|
3271 |
|
3272 |
|
3273 |
|
3274 |
|
3275 |
|
3276 |
|
3277 |
|
3278 |
|
3279 |
|
3280 |
|
3281 | Canvas.prototype.getLayer = function(name, index) {
|
3282 |
|
3283 | if (!name) {
|
3284 | throw new Error('must specify a name');
|
3285 | }
|
3286 |
|
3287 | var layer = this._layers[name];
|
3288 |
|
3289 | if (!layer) {
|
3290 | layer = this._layers[name] = this._createLayer(name, index);
|
3291 | }
|
3292 |
|
3293 |
|
3294 |
|
3295 | if (typeof index !== 'undefined' && layer.index !== index) {
|
3296 | throw new Error('layer <' + name + '> already created at index <' + index + '>');
|
3297 | }
|
3298 |
|
3299 | return layer.group;
|
3300 | };
|
3301 |
|
3302 | |
3303 |
|
3304 |
|
3305 |
|
3306 |
|
3307 |
|
3308 |
|
3309 |
|
3310 | Canvas.prototype._createLayer = function(name, index) {
|
3311 |
|
3312 | if (!index) {
|
3313 | index = 0;
|
3314 | }
|
3315 |
|
3316 | var childIndex = reduce(this._layers, function(childIndex, layer) {
|
3317 | if (index >= layer.index) {
|
3318 | childIndex++;
|
3319 | }
|
3320 |
|
3321 | return childIndex;
|
3322 | }, 0);
|
3323 |
|
3324 | return {
|
3325 | group: createGroup(this._viewport, 'layer-' + name, childIndex),
|
3326 | index: index
|
3327 | };
|
3328 |
|
3329 | };
|
3330 |
|
3331 | |
3332 |
|
3333 |
|
3334 |
|
3335 |
|
3336 |
|
3337 | Canvas.prototype.getContainer = function() {
|
3338 | return this._container;
|
3339 | };
|
3340 |
|
3341 |
|
3342 |
|
3343 |
|
3344 | Canvas.prototype._updateMarker = function(element, marker, add) {
|
3345 | var container;
|
3346 |
|
3347 | if (!element.id) {
|
3348 | element = this._elementRegistry.get(element);
|
3349 | }
|
3350 |
|
3351 |
|
3352 | container = this._elementRegistry._elements[element.id];
|
3353 |
|
3354 | if (!container) {
|
3355 | return;
|
3356 | }
|
3357 |
|
3358 | forEach([ container.gfx, container.secondaryGfx ], function(gfx) {
|
3359 | if (gfx) {
|
3360 |
|
3361 |
|
3362 | if (add) {
|
3363 | classes$1(gfx).add(marker);
|
3364 | } else {
|
3365 | classes$1(gfx).remove(marker);
|
3366 | }
|
3367 | }
|
3368 | });
|
3369 |
|
3370 | |
3371 |
|
3372 |
|
3373 |
|
3374 |
|
3375 |
|
3376 |
|
3377 |
|
3378 |
|
3379 |
|
3380 | this._eventBus.fire('element.marker.update', { element: element, gfx: container.gfx, marker: marker, add: !!add });
|
3381 | };
|
3382 |
|
3383 |
|
3384 | |
3385 |
|
3386 |
|
3387 |
|
3388 |
|
3389 |
|
3390 |
|
3391 |
|
3392 |
|
3393 |
|
3394 |
|
3395 |
|
3396 |
|
3397 |
|
3398 |
|
3399 |
|
3400 | Canvas.prototype.addMarker = function(element, marker) {
|
3401 | this._updateMarker(element, marker, true);
|
3402 | };
|
3403 |
|
3404 |
|
3405 | |
3406 |
|
3407 |
|
3408 |
|
3409 |
|
3410 |
|
3411 |
|
3412 |
|
3413 |
|
3414 | Canvas.prototype.removeMarker = function(element, marker) {
|
3415 | this._updateMarker(element, marker, false);
|
3416 | };
|
3417 |
|
3418 | |
3419 |
|
3420 |
|
3421 |
|
3422 |
|
3423 |
|
3424 | Canvas.prototype.hasMarker = function(element, marker) {
|
3425 | if (!element.id) {
|
3426 | element = this._elementRegistry.get(element);
|
3427 | }
|
3428 |
|
3429 | var gfx = this.getGraphics(element);
|
3430 |
|
3431 | return classes$1(gfx).has(marker);
|
3432 | };
|
3433 |
|
3434 | |
3435 |
|
3436 |
|
3437 |
|
3438 |
|
3439 |
|
3440 |
|
3441 |
|
3442 |
|
3443 | Canvas.prototype.toggleMarker = function(element, marker) {
|
3444 | if (this.hasMarker(element, marker)) {
|
3445 | this.removeMarker(element, marker);
|
3446 | } else {
|
3447 | this.addMarker(element, marker);
|
3448 | }
|
3449 | };
|
3450 |
|
3451 | Canvas.prototype.getRootElement = function() {
|
3452 | if (!this._rootElement) {
|
3453 | this.setRootElement({ id: '__implicitroot', children: [] });
|
3454 | }
|
3455 |
|
3456 | return this._rootElement;
|
3457 | };
|
3458 |
|
3459 |
|
3460 |
|
3461 |
|
3462 |
|
3463 | |
3464 |
|
3465 |
|
3466 |
|
3467 |
|
3468 |
|
3469 |
|
3470 |
|
3471 |
|
3472 | Canvas.prototype.setRootElement = function(element, override) {
|
3473 |
|
3474 | if (element) {
|
3475 | this._ensureValid('root', element);
|
3476 | }
|
3477 |
|
3478 | var currentRoot = this._rootElement,
|
3479 | elementRegistry = this._elementRegistry,
|
3480 | eventBus = this._eventBus;
|
3481 |
|
3482 | if (currentRoot) {
|
3483 | if (!override) {
|
3484 | throw new Error('rootElement already set, need to specify override');
|
3485 | }
|
3486 |
|
3487 |
|
3488 | eventBus.fire('root.remove', { element: currentRoot });
|
3489 | eventBus.fire('root.removed', { element: currentRoot });
|
3490 |
|
3491 | elementRegistry.remove(currentRoot);
|
3492 | }
|
3493 |
|
3494 | if (element) {
|
3495 | var gfx = this.getDefaultLayer();
|
3496 |
|
3497 |
|
3498 | eventBus.fire('root.add', { element: element });
|
3499 |
|
3500 | elementRegistry.add(element, gfx, this._svg);
|
3501 |
|
3502 | eventBus.fire('root.added', { element: element, gfx: gfx });
|
3503 | }
|
3504 |
|
3505 | this._rootElement = element;
|
3506 |
|
3507 | return element;
|
3508 | };
|
3509 |
|
3510 |
|
3511 |
|
3512 |
|
3513 |
|
3514 | Canvas.prototype._ensureValid = function(type, element) {
|
3515 | if (!element.id) {
|
3516 | throw new Error('element must have an id');
|
3517 | }
|
3518 |
|
3519 | if (this._elementRegistry.get(element.id)) {
|
3520 | throw new Error('element with id ' + element.id + ' already exists');
|
3521 | }
|
3522 |
|
3523 | var requiredAttrs = REQUIRED_MODEL_ATTRS[type];
|
3524 |
|
3525 | var valid = every(requiredAttrs, function(attr) {
|
3526 | return typeof element[attr] !== 'undefined';
|
3527 | });
|
3528 |
|
3529 | if (!valid) {
|
3530 | throw new Error(
|
3531 | 'must supply { ' + requiredAttrs.join(', ') + ' } with ' + type);
|
3532 | }
|
3533 | };
|
3534 |
|
3535 | Canvas.prototype._setParent = function(element, parent, parentIndex) {
|
3536 | add$1(parent.children, element, parentIndex);
|
3537 | element.parent = parent;
|
3538 | };
|
3539 |
|
3540 | |
3541 |
|
3542 |
|
3543 |
|
3544 |
|
3545 |
|
3546 |
|
3547 |
|
3548 |
|
3549 |
|
3550 |
|
3551 |
|
3552 |
|
3553 |
|
3554 |
|
3555 |
|
3556 |
|
3557 |
|
3558 |
|
3559 |
|
3560 | Canvas.prototype._addElement = function(type, element, parent, parentIndex) {
|
3561 |
|
3562 | parent = parent || this.getRootElement();
|
3563 |
|
3564 | var eventBus = this._eventBus,
|
3565 | graphicsFactory = this._graphicsFactory;
|
3566 |
|
3567 | this._ensureValid(type, element);
|
3568 |
|
3569 | eventBus.fire(type + '.add', { element: element, parent: parent });
|
3570 |
|
3571 | this._setParent(element, parent, parentIndex);
|
3572 |
|
3573 |
|
3574 | var gfx = graphicsFactory.create(type, element, parentIndex);
|
3575 |
|
3576 | this._elementRegistry.add(element, gfx);
|
3577 |
|
3578 |
|
3579 | graphicsFactory.update(type, element, gfx);
|
3580 |
|
3581 | eventBus.fire(type + '.added', { element: element, gfx: gfx });
|
3582 |
|
3583 | return element;
|
3584 | };
|
3585 |
|
3586 | |
3587 |
|
3588 |
|
3589 |
|
3590 |
|
3591 |
|
3592 |
|
3593 |
|
3594 |
|
3595 | Canvas.prototype.addShape = function(shape, parent, parentIndex) {
|
3596 | return this._addElement('shape', shape, parent, parentIndex);
|
3597 | };
|
3598 |
|
3599 | |
3600 |
|
3601 |
|
3602 |
|
3603 |
|
3604 |
|
3605 |
|
3606 |
|
3607 |
|
3608 | Canvas.prototype.addConnection = function(connection, parent, parentIndex) {
|
3609 | return this._addElement('connection', connection, parent, parentIndex);
|
3610 | };
|
3611 |
|
3612 |
|
3613 | |
3614 |
|
3615 |
|
3616 | Canvas.prototype._removeElement = function(element, type) {
|
3617 |
|
3618 | var elementRegistry = this._elementRegistry,
|
3619 | graphicsFactory = this._graphicsFactory,
|
3620 | eventBus = this._eventBus;
|
3621 |
|
3622 | element = elementRegistry.get(element.id || element);
|
3623 |
|
3624 | if (!element) {
|
3625 |
|
3626 |
|
3627 | return;
|
3628 | }
|
3629 |
|
3630 | eventBus.fire(type + '.remove', { element: element });
|
3631 |
|
3632 | graphicsFactory.remove(element);
|
3633 |
|
3634 |
|
3635 | remove$2(element.parent && element.parent.children, element);
|
3636 | element.parent = null;
|
3637 |
|
3638 | eventBus.fire(type + '.removed', { element: element });
|
3639 |
|
3640 | elementRegistry.remove(element);
|
3641 |
|
3642 | return element;
|
3643 | };
|
3644 |
|
3645 |
|
3646 | |
3647 |
|
3648 |
|
3649 |
|
3650 |
|
3651 |
|
3652 |
|
3653 | Canvas.prototype.removeShape = function(shape) {
|
3654 |
|
3655 | |
3656 |
|
3657 |
|
3658 |
|
3659 |
|
3660 |
|
3661 |
|
3662 |
|
3663 |
|
3664 |
|
3665 |
|
3666 | |
3667 |
|
3668 |
|
3669 |
|
3670 |
|
3671 |
|
3672 |
|
3673 |
|
3674 |
|
3675 |
|
3676 | return this._removeElement(shape, 'shape');
|
3677 | };
|
3678 |
|
3679 |
|
3680 | |
3681 |
|
3682 |
|
3683 |
|
3684 |
|
3685 |
|
3686 |
|
3687 | Canvas.prototype.removeConnection = function(connection) {
|
3688 |
|
3689 | |
3690 |
|
3691 |
|
3692 |
|
3693 |
|
3694 |
|
3695 |
|
3696 |
|
3697 |
|
3698 |
|
3699 |
|
3700 | |
3701 |
|
3702 |
|
3703 |
|
3704 |
|
3705 |
|
3706 |
|
3707 |
|
3708 |
|
3709 |
|
3710 | return this._removeElement(connection, 'connection');
|
3711 | };
|
3712 |
|
3713 |
|
3714 | |
3715 |
|
3716 |
|
3717 |
|
3718 |
|
3719 |
|
3720 |
|
3721 |
|
3722 | Canvas.prototype.getGraphics = function(element, secondary) {
|
3723 | return this._elementRegistry.getGraphics(element, secondary);
|
3724 | };
|
3725 |
|
3726 |
|
3727 | |
3728 |
|
3729 |
|
3730 |
|
3731 |
|
3732 | Canvas.prototype._changeViewbox = function(changeFn) {
|
3733 |
|
3734 |
|
3735 | this._eventBus.fire('canvas.viewbox.changing');
|
3736 |
|
3737 |
|
3738 | changeFn.apply(this);
|
3739 |
|
3740 |
|
3741 |
|
3742 |
|
3743 | this._cachedViewbox = null;
|
3744 |
|
3745 |
|
3746 |
|
3747 | this._viewboxChanged();
|
3748 | };
|
3749 |
|
3750 | Canvas.prototype._viewboxChanged = function() {
|
3751 | this._eventBus.fire('canvas.viewbox.changed', { viewbox: this.viewbox() });
|
3752 | };
|
3753 |
|
3754 |
|
3755 | |
3756 |
|
3757 |
|
3758 |
|
3759 |
|
3760 |
|
3761 |
|
3762 |
|
3763 |
|
3764 |
|
3765 |
|
3766 |
|
3767 |
|
3768 |
|
3769 |
|
3770 |
|
3771 |
|
3772 |
|
3773 |
|
3774 |
|
3775 |
|
3776 |
|
3777 |
|
3778 |
|
3779 |
|
3780 |
|
3781 |
|
3782 |
|
3783 |
|
3784 |
|
3785 |
|
3786 |
|
3787 |
|
3788 |
|
3789 |
|
3790 |
|
3791 |
|
3792 |
|
3793 |
|
3794 |
|
3795 |
|
3796 |
|
3797 |
|
3798 |
|
3799 |
|
3800 | Canvas.prototype.viewbox = function(box) {
|
3801 |
|
3802 | if (box === undefined && this._cachedViewbox) {
|
3803 | return this._cachedViewbox;
|
3804 | }
|
3805 |
|
3806 | var viewport = this._viewport,
|
3807 | innerBox,
|
3808 | outerBox = this.getSize(),
|
3809 | matrix,
|
3810 | transform$1,
|
3811 | scale,
|
3812 | x, y;
|
3813 |
|
3814 | if (!box) {
|
3815 |
|
3816 |
|
3817 |
|
3818 |
|
3819 | innerBox = this.getDefaultLayer().getBBox();
|
3820 |
|
3821 | transform$1 = transform(viewport);
|
3822 | matrix = transform$1 ? transform$1.matrix : createMatrix();
|
3823 | scale = round(matrix.a, 1000);
|
3824 |
|
3825 | x = round(-matrix.e || 0, 1000);
|
3826 | y = round(-matrix.f || 0, 1000);
|
3827 |
|
3828 | box = this._cachedViewbox = {
|
3829 | x: x ? x / scale : 0,
|
3830 | y: y ? y / scale : 0,
|
3831 | width: outerBox.width / scale,
|
3832 | height: outerBox.height / scale,
|
3833 | scale: scale,
|
3834 | inner: {
|
3835 | width: innerBox.width,
|
3836 | height: innerBox.height,
|
3837 | x: innerBox.x,
|
3838 | y: innerBox.y
|
3839 | },
|
3840 | outer: outerBox
|
3841 | };
|
3842 |
|
3843 | return box;
|
3844 | } else {
|
3845 |
|
3846 | this._changeViewbox(function() {
|
3847 | scale = Math.min(outerBox.width / box.width, outerBox.height / box.height);
|
3848 |
|
3849 | var matrix = this._svg.createSVGMatrix()
|
3850 | .scale(scale)
|
3851 | .translate(-box.x, -box.y);
|
3852 |
|
3853 | transform(viewport, matrix);
|
3854 | });
|
3855 | }
|
3856 |
|
3857 | return box;
|
3858 | };
|
3859 |
|
3860 |
|
3861 | |
3862 |
|
3863 |
|
3864 |
|
3865 |
|
3866 |
|
3867 |
|
3868 |
|
3869 | Canvas.prototype.scroll = function(delta) {
|
3870 |
|
3871 | var node = this._viewport;
|
3872 | var matrix = node.getCTM();
|
3873 |
|
3874 | if (delta) {
|
3875 | this._changeViewbox(function() {
|
3876 | delta = assign({ dx: 0, dy: 0 }, delta || {});
|
3877 |
|
3878 | matrix = this._svg.createSVGMatrix().translate(delta.dx, delta.dy).multiply(matrix);
|
3879 |
|
3880 | setCTM(node, matrix);
|
3881 | });
|
3882 | }
|
3883 |
|
3884 | return { x: matrix.e, y: matrix.f };
|
3885 | };
|
3886 |
|
3887 |
|
3888 | |
3889 |
|
3890 |
|
3891 |
|
3892 |
|
3893 |
|
3894 |
|
3895 |
|
3896 |
|
3897 |
|
3898 |
|
3899 |
|
3900 |
|
3901 | Canvas.prototype.zoom = function(newScale, center) {
|
3902 |
|
3903 | if (!newScale) {
|
3904 | return this.viewbox(newScale).scale;
|
3905 | }
|
3906 |
|
3907 | if (newScale === 'fit-viewport') {
|
3908 | return this._fitViewport(center);
|
3909 | }
|
3910 |
|
3911 | var outer,
|
3912 | matrix;
|
3913 |
|
3914 | this._changeViewbox(function() {
|
3915 |
|
3916 | if (typeof center !== 'object') {
|
3917 | outer = this.viewbox().outer;
|
3918 |
|
3919 | center = {
|
3920 | x: outer.width / 2,
|
3921 | y: outer.height / 2
|
3922 | };
|
3923 | }
|
3924 |
|
3925 | matrix = this._setZoom(newScale, center);
|
3926 | });
|
3927 |
|
3928 | return round(matrix.a, 1000);
|
3929 | };
|
3930 |
|
3931 | function setCTM(node, m) {
|
3932 | var mstr = 'matrix(' + m.a + ',' + m.b + ',' + m.c + ',' + m.d + ',' + m.e + ',' + m.f + ')';
|
3933 | node.setAttribute('transform', mstr);
|
3934 | }
|
3935 |
|
3936 | Canvas.prototype._fitViewport = function(center) {
|
3937 |
|
3938 | var vbox = this.viewbox(),
|
3939 | outer = vbox.outer,
|
3940 | inner = vbox.inner,
|
3941 | newScale,
|
3942 | newViewbox;
|
3943 |
|
3944 |
|
3945 |
|
3946 |
|
3947 |
|
3948 |
|
3949 |
|
3950 |
|
3951 | if (inner.x >= 0 &&
|
3952 | inner.y >= 0 &&
|
3953 | inner.x + inner.width <= outer.width &&
|
3954 | inner.y + inner.height <= outer.height &&
|
3955 | !center) {
|
3956 |
|
3957 | newViewbox = {
|
3958 | x: 0,
|
3959 | y: 0,
|
3960 | width: Math.max(inner.width + inner.x, outer.width),
|
3961 | height: Math.max(inner.height + inner.y, outer.height)
|
3962 | };
|
3963 | } else {
|
3964 |
|
3965 | newScale = Math.min(1, outer.width / inner.width, outer.height / inner.height);
|
3966 | newViewbox = {
|
3967 | x: inner.x + (center ? inner.width / 2 - outer.width / newScale / 2 : 0),
|
3968 | y: inner.y + (center ? inner.height / 2 - outer.height / newScale / 2 : 0),
|
3969 | width: outer.width / newScale,
|
3970 | height: outer.height / newScale
|
3971 | };
|
3972 | }
|
3973 |
|
3974 | this.viewbox(newViewbox);
|
3975 |
|
3976 | return this.viewbox(false).scale;
|
3977 | };
|
3978 |
|
3979 |
|
3980 | Canvas.prototype._setZoom = function(scale, center) {
|
3981 |
|
3982 | var svg = this._svg,
|
3983 | viewport = this._viewport;
|
3984 |
|
3985 | var matrix = svg.createSVGMatrix();
|
3986 | var point = svg.createSVGPoint();
|
3987 |
|
3988 | var centerPoint,
|
3989 | originalPoint,
|
3990 | currentMatrix,
|
3991 | scaleMatrix,
|
3992 | newMatrix;
|
3993 |
|
3994 | currentMatrix = viewport.getCTM();
|
3995 |
|
3996 | var currentScale = currentMatrix.a;
|
3997 |
|
3998 | if (center) {
|
3999 | centerPoint = assign(point, center);
|
4000 |
|
4001 |
|
4002 | originalPoint = centerPoint.matrixTransform(currentMatrix.inverse());
|
4003 |
|
4004 |
|
4005 | scaleMatrix = matrix
|
4006 | .translate(originalPoint.x, originalPoint.y)
|
4007 | .scale(1 / currentScale * scale)
|
4008 | .translate(-originalPoint.x, -originalPoint.y);
|
4009 |
|
4010 | newMatrix = currentMatrix.multiply(scaleMatrix);
|
4011 | } else {
|
4012 | newMatrix = matrix.scale(scale);
|
4013 | }
|
4014 |
|
4015 | setCTM(this._viewport, newMatrix);
|
4016 |
|
4017 | return newMatrix;
|
4018 | };
|
4019 |
|
4020 |
|
4021 | |
4022 |
|
4023 |
|
4024 |
|
4025 |
|
4026 | Canvas.prototype.getSize = function() {
|
4027 | return {
|
4028 | width: this._container.clientWidth,
|
4029 | height: this._container.clientHeight
|
4030 | };
|
4031 | };
|
4032 |
|
4033 |
|
4034 | |
4035 |
|
4036 |
|
4037 |
|
4038 |
|
4039 |
|
4040 |
|
4041 |
|
4042 |
|
4043 |
|
4044 | Canvas.prototype.getAbsoluteBBox = function(element) {
|
4045 | var vbox = this.viewbox();
|
4046 | var bbox;
|
4047 |
|
4048 |
|
4049 |
|
4050 | if (element.waypoints) {
|
4051 | var gfx = this.getGraphics(element);
|
4052 |
|
4053 | bbox = gfx.getBBox();
|
4054 | }
|
4055 |
|
4056 |
|
4057 |
|
4058 | else {
|
4059 | bbox = element;
|
4060 | }
|
4061 |
|
4062 | var x = bbox.x * vbox.scale - vbox.x * vbox.scale;
|
4063 | var y = bbox.y * vbox.scale - vbox.y * vbox.scale;
|
4064 |
|
4065 | var width = bbox.width * vbox.scale;
|
4066 | var height = bbox.height * vbox.scale;
|
4067 |
|
4068 | return {
|
4069 | x: x,
|
4070 | y: y,
|
4071 | width: width,
|
4072 | height: height
|
4073 | };
|
4074 | };
|
4075 |
|
4076 | |
4077 |
|
4078 |
|
4079 |
|
4080 | Canvas.prototype.resized = function() {
|
4081 |
|
4082 |
|
4083 | delete this._cachedViewbox;
|
4084 |
|
4085 | this._eventBus.fire('canvas.resized');
|
4086 | };
|
4087 |
|
4088 | var ELEMENT_ID = 'data-element-id';
|
4089 |
|
4090 |
|
4091 | |
4092 |
|
4093 |
|
4094 |
|
4095 |
|
4096 | function ElementRegistry(eventBus) {
|
4097 | this._elements = {};
|
4098 |
|
4099 | this._eventBus = eventBus;
|
4100 | }
|
4101 |
|
4102 | ElementRegistry.$inject = [ 'eventBus' ];
|
4103 |
|
4104 | |
4105 |
|
4106 |
|
4107 |
|
4108 |
|
4109 |
|
4110 |
|
4111 | ElementRegistry.prototype.add = function(element, gfx, secondaryGfx) {
|
4112 |
|
4113 | var id = element.id;
|
4114 |
|
4115 | this._validateId(id);
|
4116 |
|
4117 |
|
4118 | attr$1(gfx, ELEMENT_ID, id);
|
4119 |
|
4120 | if (secondaryGfx) {
|
4121 | attr$1(secondaryGfx, ELEMENT_ID, id);
|
4122 | }
|
4123 |
|
4124 | this._elements[id] = { element: element, gfx: gfx, secondaryGfx: secondaryGfx };
|
4125 | };
|
4126 |
|
4127 | |
4128 |
|
4129 |
|
4130 |
|
4131 |
|
4132 | ElementRegistry.prototype.remove = function(element) {
|
4133 | var elements = this._elements,
|
4134 | id = element.id || element,
|
4135 | container = id && elements[id];
|
4136 |
|
4137 | if (container) {
|
4138 |
|
4139 |
|
4140 | attr$1(container.gfx, ELEMENT_ID, '');
|
4141 |
|
4142 | if (container.secondaryGfx) {
|
4143 | attr$1(container.secondaryGfx, ELEMENT_ID, '');
|
4144 | }
|
4145 |
|
4146 | delete elements[id];
|
4147 | }
|
4148 | };
|
4149 |
|
4150 | |
4151 |
|
4152 |
|
4153 |
|
4154 |
|
4155 |
|
4156 | ElementRegistry.prototype.updateId = function(element, newId) {
|
4157 |
|
4158 | this._validateId(newId);
|
4159 |
|
4160 | if (typeof element === 'string') {
|
4161 | element = this.get(element);
|
4162 | }
|
4163 |
|
4164 | this._eventBus.fire('element.updateId', {
|
4165 | element: element,
|
4166 | newId: newId
|
4167 | });
|
4168 |
|
4169 | var gfx = this.getGraphics(element),
|
4170 | secondaryGfx = this.getGraphics(element, true);
|
4171 |
|
4172 | this.remove(element);
|
4173 |
|
4174 | element.id = newId;
|
4175 |
|
4176 | this.add(element, gfx, secondaryGfx);
|
4177 | };
|
4178 |
|
4179 | |
4180 |
|
4181 |
|
4182 |
|
4183 |
|
4184 |
|
4185 |
|
4186 |
|
4187 |
|
4188 |
|
4189 |
|
4190 |
|
4191 |
|
4192 | ElementRegistry.prototype.get = function(filter) {
|
4193 | var id;
|
4194 |
|
4195 | if (typeof filter === 'string') {
|
4196 | id = filter;
|
4197 | } else {
|
4198 | id = filter && attr$1(filter, ELEMENT_ID);
|
4199 | }
|
4200 |
|
4201 | var container = this._elements[id];
|
4202 | return container && container.element;
|
4203 | };
|
4204 |
|
4205 | |
4206 |
|
4207 |
|
4208 |
|
4209 |
|
4210 |
|
4211 |
|
4212 | ElementRegistry.prototype.filter = function(fn) {
|
4213 |
|
4214 | var filtered = [];
|
4215 |
|
4216 | this.forEach(function(element, gfx) {
|
4217 | if (fn(element, gfx)) {
|
4218 | filtered.push(element);
|
4219 | }
|
4220 | });
|
4221 |
|
4222 | return filtered;
|
4223 | };
|
4224 |
|
4225 | |
4226 |
|
4227 |
|
4228 |
|
4229 |
|
4230 | ElementRegistry.prototype.getAll = function() {
|
4231 | return this.filter(function(e) { return e; });
|
4232 | };
|
4233 |
|
4234 | |
4235 |
|
4236 |
|
4237 |
|
4238 |
|
4239 | ElementRegistry.prototype.forEach = function(fn) {
|
4240 |
|
4241 | var map = this._elements;
|
4242 |
|
4243 | Object.keys(map).forEach(function(id) {
|
4244 | var container = map[id],
|
4245 | element = container.element,
|
4246 | gfx = container.gfx;
|
4247 |
|
4248 | return fn(element, gfx);
|
4249 | });
|
4250 | };
|
4251 |
|
4252 | |
4253 |
|
4254 |
|
4255 |
|
4256 |
|
4257 |
|
4258 |
|
4259 |
|
4260 |
|
4261 |
|
4262 |
|
4263 |
|
4264 |
|
4265 |
|
4266 |
|
4267 | ElementRegistry.prototype.getGraphics = function(filter, secondary) {
|
4268 | var id = filter.id || filter;
|
4269 |
|
4270 | var container = this._elements[id];
|
4271 | return container && (secondary ? container.secondaryGfx : container.gfx);
|
4272 | };
|
4273 |
|
4274 | |
4275 |
|
4276 |
|
4277 |
|
4278 |
|
4279 |
|
4280 |
|
4281 |
|
4282 | ElementRegistry.prototype._validateId = function(id) {
|
4283 | if (!id) {
|
4284 | throw new Error('element must have an id');
|
4285 | }
|
4286 |
|
4287 | if (this._elements[id]) {
|
4288 | throw new Error('element with id ' + id + ' already added');
|
4289 | }
|
4290 | };
|
4291 |
|
4292 | |
4293 |
|
4294 |
|
4295 |
|
4296 |
|
4297 |
|
4298 |
|
4299 | |
4300 |
|
4301 |
|
4302 |
|
4303 |
|
4304 |
|
4305 |
|
4306 |
|
4307 |
|
4308 |
|
4309 |
|
4310 |
|
4311 |
|
4312 | function extend$1(collection, refs, property, target) {
|
4313 |
|
4314 | var inverseProperty = property.inverse;
|
4315 |
|
4316 | |
4317 |
|
4318 |
|
4319 |
|
4320 |
|
4321 |
|
4322 |
|
4323 | Object.defineProperty(collection, 'remove', {
|
4324 | value: function(element) {
|
4325 | var idx = this.indexOf(element);
|
4326 | if (idx !== -1) {
|
4327 | this.splice(idx, 1);
|
4328 |
|
4329 |
|
4330 | refs.unset(element, inverseProperty, target);
|
4331 | }
|
4332 |
|
4333 | return element;
|
4334 | }
|
4335 | });
|
4336 |
|
4337 | |
4338 |
|
4339 |
|
4340 |
|
4341 |
|
4342 |
|
4343 |
|
4344 | Object.defineProperty(collection, 'contains', {
|
4345 | value: function(element) {
|
4346 | return this.indexOf(element) !== -1;
|
4347 | }
|
4348 | });
|
4349 |
|
4350 | |
4351 |
|
4352 |
|
4353 |
|
4354 |
|
4355 |
|
4356 |
|
4357 |
|
4358 |
|
4359 | Object.defineProperty(collection, 'add', {
|
4360 | value: function(element, idx) {
|
4361 |
|
4362 | var currentIdx = this.indexOf(element);
|
4363 |
|
4364 | if (typeof idx === 'undefined') {
|
4365 |
|
4366 | if (currentIdx !== -1) {
|
4367 |
|
4368 | return;
|
4369 | }
|
4370 |
|
4371 |
|
4372 | idx = this.length;
|
4373 | }
|
4374 |
|
4375 |
|
4376 | if (currentIdx !== -1) {
|
4377 |
|
4378 |
|
4379 | this.splice(currentIdx, 1);
|
4380 | }
|
4381 |
|
4382 |
|
4383 | this.splice(idx, 0, element);
|
4384 |
|
4385 | if (currentIdx === -1) {
|
4386 |
|
4387 |
|
4388 | refs.set(element, inverseProperty, target);
|
4389 | }
|
4390 | }
|
4391 | });
|
4392 |
|
4393 |
|
4394 |
|
4395 | Object.defineProperty(collection, '__refs_collection', {
|
4396 | value: true
|
4397 | });
|
4398 |
|
4399 | return collection;
|
4400 | }
|
4401 |
|
4402 |
|
4403 | function isExtended(collection) {
|
4404 | return collection.__refs_collection === true;
|
4405 | }
|
4406 |
|
4407 | var extend_1 = extend$1;
|
4408 |
|
4409 | var isExtended_1 = isExtended;
|
4410 |
|
4411 | var collection = {
|
4412 | extend: extend_1,
|
4413 | isExtended: isExtended_1
|
4414 | };
|
4415 |
|
4416 | function hasOwnProperty(e, property) {
|
4417 | return Object.prototype.hasOwnProperty.call(e, property.name || property);
|
4418 | }
|
4419 |
|
4420 | function defineCollectionProperty(ref, property, target) {
|
4421 |
|
4422 | var collection$1 = collection.extend(target[property.name] || [], ref, property, target);
|
4423 |
|
4424 | Object.defineProperty(target, property.name, {
|
4425 | enumerable: property.enumerable,
|
4426 | value: collection$1
|
4427 | });
|
4428 |
|
4429 | if (collection$1.length) {
|
4430 |
|
4431 | collection$1.forEach(function(o) {
|
4432 | ref.set(o, property.inverse, target);
|
4433 | });
|
4434 | }
|
4435 | }
|
4436 |
|
4437 |
|
4438 | function defineProperty(ref, property, target) {
|
4439 |
|
4440 | var inverseProperty = property.inverse;
|
4441 |
|
4442 | var _value = target[property.name];
|
4443 |
|
4444 | Object.defineProperty(target, property.name, {
|
4445 | configurable: property.configurable,
|
4446 | enumerable: property.enumerable,
|
4447 |
|
4448 | get: function() {
|
4449 | return _value;
|
4450 | },
|
4451 |
|
4452 | set: function(value) {
|
4453 |
|
4454 |
|
4455 | if (value === _value) {
|
4456 | return;
|
4457 | }
|
4458 |
|
4459 | var old = _value;
|
4460 |
|
4461 |
|
4462 | _value = null;
|
4463 |
|
4464 | if (old) {
|
4465 | ref.unset(old, inverseProperty, target);
|
4466 | }
|
4467 |
|
4468 |
|
4469 | _value = value;
|
4470 |
|
4471 |
|
4472 | ref.set(_value, inverseProperty, target);
|
4473 | }
|
4474 | });
|
4475 |
|
4476 | }
|
4477 |
|
4478 | |
4479 |
|
4480 |
|
4481 |
|
4482 |
|
4483 |
|
4484 |
|
4485 |
|
4486 |
|
4487 |
|
4488 |
|
4489 |
|
4490 |
|
4491 |
|
4492 |
|
4493 |
|
4494 |
|
4495 |
|
4496 |
|
4497 |
|
4498 |
|
4499 |
|
4500 |
|
4501 |
|
4502 |
|
4503 |
|
4504 |
|
4505 |
|
4506 |
|
4507 |
|
4508 |
|
4509 |
|
4510 |
|
4511 |
|
4512 |
|
4513 |
|
4514 |
|
4515 |
|
4516 |
|
4517 |
|
4518 |
|
4519 |
|
4520 |
|
4521 | function Refs(a, b) {
|
4522 |
|
4523 | if (!(this instanceof Refs)) {
|
4524 | return new Refs(a, b);
|
4525 | }
|
4526 |
|
4527 |
|
4528 | a.inverse = b;
|
4529 | b.inverse = a;
|
4530 |
|
4531 | this.props = {};
|
4532 | this.props[a.name] = a;
|
4533 | this.props[b.name] = b;
|
4534 | }
|
4535 |
|
4536 | |
4537 |
|
4538 |
|
4539 |
|
4540 |
|
4541 |
|
4542 |
|
4543 |
|
4544 |
|
4545 | Refs.prototype.bind = function(target, property) {
|
4546 | if (typeof property === 'string') {
|
4547 | if (!this.props[property]) {
|
4548 | throw new Error('no property <' + property + '> in ref');
|
4549 | }
|
4550 | property = this.props[property];
|
4551 | }
|
4552 |
|
4553 | if (property.collection) {
|
4554 | defineCollectionProperty(this, property, target);
|
4555 | } else {
|
4556 | defineProperty(this, property, target);
|
4557 | }
|
4558 | };
|
4559 |
|
4560 | Refs.prototype.ensureRefsCollection = function(target, property) {
|
4561 |
|
4562 | var collection$1 = target[property.name];
|
4563 |
|
4564 | if (!collection.isExtended(collection$1)) {
|
4565 | defineCollectionProperty(this, property, target);
|
4566 | }
|
4567 |
|
4568 | return collection$1;
|
4569 | };
|
4570 |
|
4571 | Refs.prototype.ensureBound = function(target, property) {
|
4572 | if (!hasOwnProperty(target, property)) {
|
4573 | this.bind(target, property);
|
4574 | }
|
4575 | };
|
4576 |
|
4577 | Refs.prototype.unset = function(target, property, value) {
|
4578 |
|
4579 | if (target) {
|
4580 | this.ensureBound(target, property);
|
4581 |
|
4582 | if (property.collection) {
|
4583 | this.ensureRefsCollection(target, property).remove(value);
|
4584 | } else {
|
4585 | target[property.name] = undefined;
|
4586 | }
|
4587 | }
|
4588 | };
|
4589 |
|
4590 | Refs.prototype.set = function(target, property, value) {
|
4591 |
|
4592 | if (target) {
|
4593 | this.ensureBound(target, property);
|
4594 |
|
4595 | if (property.collection) {
|
4596 | this.ensureRefsCollection(target, property).add(value);
|
4597 | } else {
|
4598 | target[property.name] = value;
|
4599 | }
|
4600 | }
|
4601 | };
|
4602 |
|
4603 | var refs = Refs;
|
4604 |
|
4605 | var objectRefs = refs;
|
4606 |
|
4607 | var Collection = collection;
|
4608 | objectRefs.Collection = Collection;
|
4609 |
|
4610 | var parentRefs = new objectRefs({ name: 'children', enumerable: true, collection: true }, { name: 'parent' }),
|
4611 | labelRefs = new objectRefs({ name: 'labels', enumerable: true, collection: true }, { name: 'labelTarget' }),
|
4612 | attacherRefs = new objectRefs({ name: 'attachers', collection: true }, { name: 'host' }),
|
4613 | outgoingRefs = new objectRefs({ name: 'outgoing', collection: true }, { name: 'source' }),
|
4614 | incomingRefs = new objectRefs({ name: 'incoming', collection: true }, { name: 'target' });
|
4615 |
|
4616 | |
4617 |
|
4618 |
|
4619 |
|
4620 | |
4621 |
|
4622 |
|
4623 |
|
4624 | |
4625 |
|
4626 |
|
4627 |
|
4628 |
|
4629 |
|
4630 |
|
4631 | function Base() {
|
4632 |
|
4633 | |
4634 |
|
4635 |
|
4636 |
|
4637 |
|
4638 |
|
4639 | Object.defineProperty(this, 'businessObject', {
|
4640 | writable: true
|
4641 | });
|
4642 |
|
4643 |
|
4644 | |
4645 |
|
4646 |
|
4647 |
|
4648 |
|
4649 |
|
4650 | Object.defineProperty(this, 'label', {
|
4651 | get: function() {
|
4652 | return this.labels[0];
|
4653 | },
|
4654 | set: function(newLabel) {
|
4655 |
|
4656 | var label = this.label,
|
4657 | labels = this.labels;
|
4658 |
|
4659 | if (!newLabel && label) {
|
4660 | labels.remove(label);
|
4661 | } else {
|
4662 | labels.add(newLabel, 0);
|
4663 | }
|
4664 | }
|
4665 | });
|
4666 |
|
4667 | |
4668 |
|
4669 |
|
4670 |
|
4671 |
|
4672 |
|
4673 | parentRefs.bind(this, 'parent');
|
4674 |
|
4675 | |
4676 |
|
4677 |
|
4678 |
|
4679 |
|
4680 |
|
4681 | labelRefs.bind(this, 'labels');
|
4682 |
|
4683 | |
4684 |
|
4685 |
|
4686 |
|
4687 |
|
4688 |
|
4689 | outgoingRefs.bind(this, 'outgoing');
|
4690 |
|
4691 | |
4692 |
|
4693 |
|
4694 |
|
4695 |
|
4696 |
|
4697 | incomingRefs.bind(this, 'incoming');
|
4698 | }
|
4699 |
|
4700 |
|
4701 | |
4702 |
|
4703 |
|
4704 |
|
4705 |
|
4706 |
|
4707 |
|
4708 |
|
4709 | function Shape() {
|
4710 | Base.call(this);
|
4711 |
|
4712 | |
4713 |
|
4714 |
|
4715 |
|
4716 |
|
4717 |
|
4718 |
|
4719 | |
4720 |
|
4721 |
|
4722 |
|
4723 |
|
4724 |
|
4725 | parentRefs.bind(this, 'children');
|
4726 |
|
4727 | |
4728 |
|
4729 |
|
4730 |
|
4731 | attacherRefs.bind(this, 'host');
|
4732 |
|
4733 | |
4734 |
|
4735 |
|
4736 |
|
4737 | attacherRefs.bind(this, 'attachers');
|
4738 | }
|
4739 |
|
4740 | inherits_browser(Shape, Base);
|
4741 |
|
4742 |
|
4743 | |
4744 |
|
4745 |
|
4746 |
|
4747 |
|
4748 |
|
4749 |
|
4750 |
|
4751 | function Root() {
|
4752 | Shape.call(this);
|
4753 | }
|
4754 |
|
4755 | inherits_browser(Root, Shape);
|
4756 |
|
4757 |
|
4758 | |
4759 |
|
4760 |
|
4761 |
|
4762 |
|
4763 |
|
4764 |
|
4765 |
|
4766 | function Label() {
|
4767 | Shape.call(this);
|
4768 |
|
4769 | |
4770 |
|
4771 |
|
4772 |
|
4773 |
|
4774 |
|
4775 | labelRefs.bind(this, 'labelTarget');
|
4776 | }
|
4777 |
|
4778 | inherits_browser(Label, Shape);
|
4779 |
|
4780 |
|
4781 | |
4782 |
|
4783 |
|
4784 |
|
4785 |
|
4786 |
|
4787 |
|
4788 |
|
4789 | function Connection() {
|
4790 | Base.call(this);
|
4791 |
|
4792 | |
4793 |
|
4794 |
|
4795 |
|
4796 |
|
4797 |
|
4798 | outgoingRefs.bind(this, 'source');
|
4799 |
|
4800 | |
4801 |
|
4802 |
|
4803 |
|
4804 |
|
4805 |
|
4806 | incomingRefs.bind(this, 'target');
|
4807 | }
|
4808 |
|
4809 | inherits_browser(Connection, Base);
|
4810 |
|
4811 |
|
4812 | var types = {
|
4813 | connection: Connection,
|
4814 | shape: Shape,
|
4815 | label: Label,
|
4816 | root: Root
|
4817 | };
|
4818 |
|
4819 | |
4820 |
|
4821 |
|
4822 |
|
4823 |
|
4824 |
|
4825 |
|
4826 |
|
4827 |
|
4828 |
|
4829 |
|
4830 |
|
4831 |
|
4832 |
|
4833 |
|
4834 |
|
4835 |
|
4836 | function create$1(type, attrs) {
|
4837 | var Type = types[type];
|
4838 | if (!Type) {
|
4839 | throw new Error('unknown type: <' + type + '>');
|
4840 | }
|
4841 | return assign(new Type(), attrs);
|
4842 | }
|
4843 |
|
4844 | |
4845 |
|
4846 |
|
4847 | function ElementFactory() {
|
4848 | this._uid = 12;
|
4849 | }
|
4850 |
|
4851 |
|
4852 | ElementFactory.prototype.createRoot = function(attrs) {
|
4853 | return this.create('root', attrs);
|
4854 | };
|
4855 |
|
4856 | ElementFactory.prototype.createLabel = function(attrs) {
|
4857 | return this.create('label', attrs);
|
4858 | };
|
4859 |
|
4860 | ElementFactory.prototype.createShape = function(attrs) {
|
4861 | return this.create('shape', attrs);
|
4862 | };
|
4863 |
|
4864 | ElementFactory.prototype.createConnection = function(attrs) {
|
4865 | return this.create('connection', attrs);
|
4866 | };
|
4867 |
|
4868 | |
4869 |
|
4870 |
|
4871 |
|
4872 |
|
4873 |
|
4874 |
|
4875 |
|
4876 | ElementFactory.prototype.create = function(type, attrs) {
|
4877 |
|
4878 | attrs = assign({}, attrs || {});
|
4879 |
|
4880 | if (!attrs.id) {
|
4881 | attrs.id = type + '_' + (this._uid++);
|
4882 | }
|
4883 |
|
4884 | return create$1(type, attrs);
|
4885 | };
|
4886 |
|
4887 | var FN_REF = '__fn';
|
4888 |
|
4889 | var DEFAULT_PRIORITY = 1000;
|
4890 |
|
4891 | var slice$1 = Array.prototype.slice;
|
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 |
|
4918 |
|
4919 |
|
4920 |
|
4921 |
|
4922 |
|
4923 |
|
4924 |
|
4925 |
|
4926 |
|
4927 |
|
4928 |
|
4929 |
|
4930 |
|
4931 |
|
4932 |
|
4933 |
|
4934 |
|
4935 |
|
4936 |
|
4937 |
|
4938 |
|
4939 |
|
4940 |
|
4941 |
|
4942 |
|
4943 |
|
4944 |
|
4945 |
|
4946 |
|
4947 |
|
4948 |
|
4949 |
|
4950 |
|
4951 |
|
4952 |
|
4953 |
|
4954 |
|
4955 |
|
4956 |
|
4957 |
|
4958 |
|
4959 |
|
4960 |
|
4961 |
|
4962 |
|
4963 |
|
4964 |
|
4965 |
|
4966 |
|
4967 |
|
4968 |
|
4969 |
|
4970 |
|
4971 |
|
4972 |
|
4973 |
|
4974 |
|
4975 |
|
4976 | function EventBus() {
|
4977 | this._listeners = {};
|
4978 |
|
4979 |
|
4980 |
|
4981 | this.on('diagram.destroy', 1, this._destroy, this);
|
4982 | }
|
4983 |
|
4984 |
|
4985 | |
4986 |
|
4987 |
|
4988 |
|
4989 |
|
4990 |
|
4991 |
|
4992 |
|
4993 |
|
4994 |
|
4995 |
|
4996 |
|
4997 |
|
4998 |
|
4999 |
|
5000 |
|
5001 |
|
5002 | EventBus.prototype.on = function(events, priority, callback, that) {
|
5003 |
|
5004 | events = isArray(events) ? events : [ events ];
|
5005 |
|
5006 | if (isFunction(priority)) {
|
5007 | that = callback;
|
5008 | callback = priority;
|
5009 | priority = DEFAULT_PRIORITY;
|
5010 | }
|
5011 |
|
5012 | if (!isNumber(priority)) {
|
5013 | throw new Error('priority must be a number');
|
5014 | }
|
5015 |
|
5016 | var actualCallback = callback;
|
5017 |
|
5018 | if (that) {
|
5019 | actualCallback = bind(callback, that);
|
5020 |
|
5021 |
|
5022 |
|
5023 |
|
5024 | actualCallback[FN_REF] = callback[FN_REF] || callback;
|
5025 | }
|
5026 |
|
5027 | var self = this;
|
5028 |
|
5029 | events.forEach(function(e) {
|
5030 | self._addListener(e, {
|
5031 | priority: priority,
|
5032 | callback: actualCallback,
|
5033 | next: null
|
5034 | });
|
5035 | });
|
5036 | };
|
5037 |
|
5038 |
|
5039 | |
5040 |
|
5041 |
|
5042 |
|
5043 |
|
5044 |
|
5045 |
|
5046 |
|
5047 | EventBus.prototype.once = function(event, priority, callback, that) {
|
5048 | var self = this;
|
5049 |
|
5050 | if (isFunction(priority)) {
|
5051 | that = callback;
|
5052 | callback = priority;
|
5053 | priority = DEFAULT_PRIORITY;
|
5054 | }
|
5055 |
|
5056 | if (!isNumber(priority)) {
|
5057 | throw new Error('priority must be a number');
|
5058 | }
|
5059 |
|
5060 | function wrappedCallback() {
|
5061 | var result = callback.apply(that, arguments);
|
5062 |
|
5063 | self.off(event, wrappedCallback);
|
5064 |
|
5065 | return result;
|
5066 | }
|
5067 |
|
5068 |
|
5069 |
|
5070 |
|
5071 | wrappedCallback[FN_REF] = callback;
|
5072 |
|
5073 | this.on(event, priority, wrappedCallback);
|
5074 | };
|
5075 |
|
5076 |
|
5077 | |
5078 |
|
5079 |
|
5080 |
|
5081 |
|
5082 |
|
5083 |
|
5084 |
|
5085 | EventBus.prototype.off = function(events, callback) {
|
5086 |
|
5087 | events = isArray(events) ? events : [ events ];
|
5088 |
|
5089 | var self = this;
|
5090 |
|
5091 | events.forEach(function(event) {
|
5092 | self._removeListener(event, callback);
|
5093 | });
|
5094 |
|
5095 | };
|
5096 |
|
5097 |
|
5098 | |
5099 |
|
5100 |
|
5101 |
|
5102 |
|
5103 |
|
5104 |
|
5105 | EventBus.prototype.createEvent = function(data) {
|
5106 | var event = new InternalEvent();
|
5107 |
|
5108 | event.init(data);
|
5109 |
|
5110 | return event;
|
5111 | };
|
5112 |
|
5113 |
|
5114 | |
5115 |
|
5116 |
|
5117 |
|
5118 |
|
5119 |
|
5120 |
|
5121 |
|
5122 |
|
5123 |
|
5124 |
|
5125 |
|
5126 |
|
5127 |
|
5128 |
|
5129 |
|
5130 |
|
5131 |
|
5132 |
|
5133 |
|
5134 |
|
5135 |
|
5136 |
|
5137 |
|
5138 |
|
5139 |
|
5140 |
|
5141 |
|
5142 |
|
5143 |
|
5144 | EventBus.prototype.fire = function(type, data) {
|
5145 |
|
5146 | var event,
|
5147 | firstListener,
|
5148 | returnValue,
|
5149 | args;
|
5150 |
|
5151 | args = slice$1.call(arguments);
|
5152 |
|
5153 | if (typeof type === 'object') {
|
5154 | data = type;
|
5155 | type = data.type;
|
5156 | }
|
5157 |
|
5158 | if (!type) {
|
5159 | throw new Error('no event type specified');
|
5160 | }
|
5161 |
|
5162 | firstListener = this._listeners[type];
|
5163 |
|
5164 | if (!firstListener) {
|
5165 | return;
|
5166 | }
|
5167 |
|
5168 |
|
5169 |
|
5170 | if (data instanceof InternalEvent) {
|
5171 |
|
5172 |
|
5173 | event = data;
|
5174 | } else {
|
5175 | event = this.createEvent(data);
|
5176 | }
|
5177 |
|
5178 |
|
5179 | args[0] = event;
|
5180 |
|
5181 |
|
5182 | var originalType = event.type;
|
5183 |
|
5184 |
|
5185 | if (type !== originalType) {
|
5186 | event.type = type;
|
5187 | }
|
5188 |
|
5189 | try {
|
5190 | returnValue = this._invokeListeners(event, args, firstListener);
|
5191 | } finally {
|
5192 |
|
5193 |
|
5194 | if (type !== originalType) {
|
5195 | event.type = originalType;
|
5196 | }
|
5197 | }
|
5198 |
|
5199 |
|
5200 |
|
5201 | if (returnValue === undefined && event.defaultPrevented) {
|
5202 | returnValue = false;
|
5203 | }
|
5204 |
|
5205 | return returnValue;
|
5206 | };
|
5207 |
|
5208 |
|
5209 | EventBus.prototype.handleError = function(error) {
|
5210 | return this.fire('error', { error: error }) === false;
|
5211 | };
|
5212 |
|
5213 |
|
5214 | EventBus.prototype._destroy = function() {
|
5215 | this._listeners = {};
|
5216 | };
|
5217 |
|
5218 | EventBus.prototype._invokeListeners = function(event, args, listener) {
|
5219 |
|
5220 | var returnValue;
|
5221 |
|
5222 | while (listener) {
|
5223 |
|
5224 |
|
5225 | if (event.cancelBubble) {
|
5226 | break;
|
5227 | }
|
5228 |
|
5229 | returnValue = this._invokeListener(event, args, listener);
|
5230 |
|
5231 | listener = listener.next;
|
5232 | }
|
5233 |
|
5234 | return returnValue;
|
5235 | };
|
5236 |
|
5237 | EventBus.prototype._invokeListener = function(event, args, listener) {
|
5238 |
|
5239 | var returnValue;
|
5240 |
|
5241 | try {
|
5242 |
|
5243 |
|
5244 | returnValue = invokeFunction(listener.callback, args);
|
5245 |
|
5246 |
|
5247 | if (returnValue !== undefined) {
|
5248 | event.returnValue = returnValue;
|
5249 | event.stopPropagation();
|
5250 | }
|
5251 |
|
5252 |
|
5253 | if (returnValue === false) {
|
5254 | event.preventDefault();
|
5255 | }
|
5256 | } catch (e) {
|
5257 | if (!this.handleError(e)) {
|
5258 | console.error('unhandled error in event listener');
|
5259 | console.error(e.stack);
|
5260 |
|
5261 | throw e;
|
5262 | }
|
5263 | }
|
5264 |
|
5265 | return returnValue;
|
5266 | };
|
5267 |
|
5268 | |
5269 |
|
5270 |
|
5271 |
|
5272 |
|
5273 |
|
5274 |
|
5275 |
|
5276 |
|
5277 |
|
5278 |
|
5279 |
|
5280 |
|
5281 |
|
5282 |
|
5283 |
|
5284 | EventBus.prototype._addListener = function(event, newListener) {
|
5285 |
|
5286 | var listener = this._getListeners(event),
|
5287 | previousListener;
|
5288 |
|
5289 |
|
5290 | if (!listener) {
|
5291 | this._setListeners(event, newListener);
|
5292 |
|
5293 | return;
|
5294 | }
|
5295 |
|
5296 |
|
5297 |
|
5298 | while (listener) {
|
5299 |
|
5300 | if (listener.priority < newListener.priority) {
|
5301 |
|
5302 | newListener.next = listener;
|
5303 |
|
5304 | if (previousListener) {
|
5305 | previousListener.next = newListener;
|
5306 | } else {
|
5307 | this._setListeners(event, newListener);
|
5308 | }
|
5309 |
|
5310 | return;
|
5311 | }
|
5312 |
|
5313 | previousListener = listener;
|
5314 | listener = listener.next;
|
5315 | }
|
5316 |
|
5317 |
|
5318 | previousListener.next = newListener;
|
5319 | };
|
5320 |
|
5321 |
|
5322 | EventBus.prototype._getListeners = function(name) {
|
5323 | return this._listeners[name];
|
5324 | };
|
5325 |
|
5326 | EventBus.prototype._setListeners = function(name, listener) {
|
5327 | this._listeners[name] = listener;
|
5328 | };
|
5329 |
|
5330 | EventBus.prototype._removeListener = function(event, callback) {
|
5331 |
|
5332 | var listener = this._getListeners(event),
|
5333 | nextListener,
|
5334 | previousListener,
|
5335 | listenerCallback;
|
5336 |
|
5337 | if (!callback) {
|
5338 |
|
5339 |
|
5340 | this._setListeners(event, null);
|
5341 |
|
5342 | return;
|
5343 | }
|
5344 |
|
5345 | while (listener) {
|
5346 |
|
5347 | nextListener = listener.next;
|
5348 |
|
5349 | listenerCallback = listener.callback;
|
5350 |
|
5351 | if (listenerCallback === callback || listenerCallback[FN_REF] === callback) {
|
5352 | if (previousListener) {
|
5353 | previousListener.next = nextListener;
|
5354 | } else {
|
5355 |
|
5356 |
|
5357 | this._setListeners(event, nextListener);
|
5358 | }
|
5359 | }
|
5360 |
|
5361 | previousListener = listener;
|
5362 | listener = nextListener;
|
5363 | }
|
5364 | };
|
5365 |
|
5366 | |
5367 |
|
5368 |
|
5369 | function InternalEvent() { }
|
5370 |
|
5371 | InternalEvent.prototype.stopPropagation = function() {
|
5372 | this.cancelBubble = true;
|
5373 | };
|
5374 |
|
5375 | InternalEvent.prototype.preventDefault = function() {
|
5376 | this.defaultPrevented = true;
|
5377 | };
|
5378 |
|
5379 | InternalEvent.prototype.init = function(data) {
|
5380 | assign(this, data || {});
|
5381 | };
|
5382 |
|
5383 |
|
5384 | |
5385 |
|
5386 |
|
5387 |
|
5388 |
|
5389 |
|
5390 |
|
5391 |
|
5392 | function invokeFunction(fn, args) {
|
5393 | return fn.apply(null, args);
|
5394 | }
|
5395 |
|
5396 | |
5397 |
|
5398 |
|
5399 |
|
5400 |
|
5401 |
|
5402 |
|
5403 | |
5404 |
|
5405 |
|
5406 |
|
5407 |
|
5408 |
|
5409 |
|
5410 | function getVisual(gfx) {
|
5411 | return gfx.childNodes[0];
|
5412 | }
|
5413 |
|
5414 | |
5415 |
|
5416 |
|
5417 |
|
5418 |
|
5419 |
|
5420 | function getChildren(gfx) {
|
5421 | return gfx.parentNode.childNodes[1];
|
5422 | }
|
5423 |
|
5424 | |
5425 |
|
5426 |
|
5427 |
|
5428 |
|
5429 |
|
5430 |
|
5431 | function transform$1(gfx, x, y, angle, amount) {
|
5432 | var translate = createTransform();
|
5433 | translate.setTranslate(x, y);
|
5434 |
|
5435 | var rotate = createTransform();
|
5436 | rotate.setRotate(angle || 0, 0, 0);
|
5437 |
|
5438 | var scale = createTransform();
|
5439 | scale.setScale(amount || 1, amount || 1);
|
5440 |
|
5441 | transform(gfx, [ translate, rotate, scale ]);
|
5442 | }
|
5443 |
|
5444 |
|
5445 | |
5446 |
|
5447 |
|
5448 |
|
5449 |
|
5450 | function translate(gfx, x, y) {
|
5451 | var translate = createTransform();
|
5452 | translate.setTranslate(x, y);
|
5453 |
|
5454 | transform(gfx, translate);
|
5455 | }
|
5456 |
|
5457 |
|
5458 | |
5459 |
|
5460 |
|
5461 |
|
5462 | function rotate(gfx, angle) {
|
5463 | var rotate = createTransform();
|
5464 | rotate.setRotate(angle, 0, 0);
|
5465 |
|
5466 | transform(gfx, rotate);
|
5467 | }
|
5468 |
|
5469 | |
5470 |
|
5471 |
|
5472 |
|
5473 |
|
5474 |
|
5475 | function GraphicsFactory(eventBus, elementRegistry) {
|
5476 | this._eventBus = eventBus;
|
5477 | this._elementRegistry = elementRegistry;
|
5478 | }
|
5479 |
|
5480 | GraphicsFactory.$inject = [ 'eventBus' , 'elementRegistry' ];
|
5481 |
|
5482 |
|
5483 | GraphicsFactory.prototype._getChildrenContainer = function(element) {
|
5484 |
|
5485 | var gfx = this._elementRegistry.getGraphics(element);
|
5486 |
|
5487 | var childrenGfx;
|
5488 |
|
5489 |
|
5490 | if (!element.parent) {
|
5491 | childrenGfx = gfx;
|
5492 | } else {
|
5493 | childrenGfx = getChildren(gfx);
|
5494 | if (!childrenGfx) {
|
5495 | childrenGfx = create('g');
|
5496 | classes$1(childrenGfx).add('djs-children');
|
5497 |
|
5498 | append(gfx.parentNode, childrenGfx);
|
5499 | }
|
5500 | }
|
5501 |
|
5502 | return childrenGfx;
|
5503 | };
|
5504 |
|
5505 | |
5506 |
|
5507 |
|
5508 |
|
5509 | GraphicsFactory.prototype._clear = function(gfx) {
|
5510 | var visual = getVisual(gfx);
|
5511 |
|
5512 | clear(visual);
|
5513 |
|
5514 | return visual;
|
5515 | };
|
5516 |
|
5517 | |
5518 |
|
5519 |
|
5520 |
|
5521 |
|
5522 |
|
5523 |
|
5524 |
|
5525 |
|
5526 |
|
5527 |
|
5528 |
|
5529 |
|
5530 |
|
5531 |
|
5532 |
|
5533 |
|
5534 |
|
5535 |
|
5536 |
|
5537 |
|
5538 |
|
5539 |
|
5540 |
|
5541 |
|
5542 |
|
5543 |
|
5544 | GraphicsFactory.prototype._createContainer = function(
|
5545 | type, childrenGfx, parentIndex, isFrame
|
5546 | ) {
|
5547 | var outerGfx = create('g');
|
5548 | classes$1(outerGfx).add('djs-group');
|
5549 |
|
5550 |
|
5551 | if (typeof parentIndex !== 'undefined') {
|
5552 | prependTo(outerGfx, childrenGfx, childrenGfx.childNodes[parentIndex]);
|
5553 | } else {
|
5554 | append(childrenGfx, outerGfx);
|
5555 | }
|
5556 |
|
5557 | var gfx = create('g');
|
5558 | classes$1(gfx).add('djs-element');
|
5559 | classes$1(gfx).add('djs-' + type);
|
5560 |
|
5561 | if (isFrame) {
|
5562 | classes$1(gfx).add('djs-frame');
|
5563 | }
|
5564 |
|
5565 | append(outerGfx, gfx);
|
5566 |
|
5567 |
|
5568 | var visual = create('g');
|
5569 | classes$1(visual).add('djs-visual');
|
5570 |
|
5571 | append(gfx, visual);
|
5572 |
|
5573 | return gfx;
|
5574 | };
|
5575 |
|
5576 | GraphicsFactory.prototype.create = function(type, element, parentIndex) {
|
5577 | var childrenGfx = this._getChildrenContainer(element.parent);
|
5578 | return this._createContainer(type, childrenGfx, parentIndex, isFrameElement(element));
|
5579 | };
|
5580 |
|
5581 | GraphicsFactory.prototype.updateContainments = function(elements) {
|
5582 |
|
5583 | var self = this,
|
5584 | elementRegistry = this._elementRegistry,
|
5585 | parents;
|
5586 |
|
5587 | parents = reduce(elements, function(map, e) {
|
5588 |
|
5589 | if (e.parent) {
|
5590 | map[e.parent.id] = e.parent;
|
5591 | }
|
5592 |
|
5593 | return map;
|
5594 | }, {});
|
5595 |
|
5596 |
|
5597 |
|
5598 | forEach(parents, function(parent) {
|
5599 |
|
5600 | var children = parent.children;
|
5601 |
|
5602 | if (!children) {
|
5603 | return;
|
5604 | }
|
5605 |
|
5606 | var childrenGfx = self._getChildrenContainer(parent);
|
5607 |
|
5608 | forEach(children.slice().reverse(), function(child) {
|
5609 | var childGfx = elementRegistry.getGraphics(child);
|
5610 |
|
5611 | prependTo(childGfx.parentNode, childrenGfx);
|
5612 | });
|
5613 | });
|
5614 | };
|
5615 |
|
5616 | GraphicsFactory.prototype.drawShape = function(visual, element) {
|
5617 | var eventBus = this._eventBus;
|
5618 |
|
5619 | return eventBus.fire('render.shape', { gfx: visual, element: element });
|
5620 | };
|
5621 |
|
5622 | GraphicsFactory.prototype.getShapePath = function(element) {
|
5623 | var eventBus = this._eventBus;
|
5624 |
|
5625 | return eventBus.fire('render.getShapePath', element);
|
5626 | };
|
5627 |
|
5628 | GraphicsFactory.prototype.drawConnection = function(visual, element) {
|
5629 | var eventBus = this._eventBus;
|
5630 |
|
5631 | return eventBus.fire('render.connection', { gfx: visual, element: element });
|
5632 | };
|
5633 |
|
5634 | GraphicsFactory.prototype.getConnectionPath = function(waypoints) {
|
5635 | var eventBus = this._eventBus;
|
5636 |
|
5637 | return eventBus.fire('render.getConnectionPath', waypoints);
|
5638 | };
|
5639 |
|
5640 | GraphicsFactory.prototype.update = function(type, element, gfx) {
|
5641 |
|
5642 |
|
5643 | if (!element.parent) {
|
5644 | return;
|
5645 | }
|
5646 |
|
5647 | var visual = this._clear(gfx);
|
5648 |
|
5649 |
|
5650 | if (type === 'shape') {
|
5651 | this.drawShape(visual, element);
|
5652 |
|
5653 |
|
5654 | translate(gfx, element.x, element.y);
|
5655 | } else
|
5656 | if (type === 'connection') {
|
5657 | this.drawConnection(visual, element);
|
5658 | } else {
|
5659 | throw new Error('unknown type: ' + type);
|
5660 | }
|
5661 |
|
5662 | if (element.hidden) {
|
5663 | attr$1(gfx, 'display', 'none');
|
5664 | } else {
|
5665 | attr$1(gfx, 'display', 'block');
|
5666 | }
|
5667 | };
|
5668 |
|
5669 | GraphicsFactory.prototype.remove = function(element) {
|
5670 | var gfx = this._elementRegistry.getGraphics(element);
|
5671 |
|
5672 |
|
5673 | remove$1(gfx.parentNode);
|
5674 | };
|
5675 |
|
5676 |
|
5677 |
|
5678 |
|
5679 | function prependTo(newNode, parentNode, siblingNode) {
|
5680 | var node = siblingNode || parentNode.firstChild;
|
5681 |
|
5682 |
|
5683 |
|
5684 | if (newNode === node) {
|
5685 | return;
|
5686 | }
|
5687 |
|
5688 | parentNode.insertBefore(newNode, node);
|
5689 | }
|
5690 |
|
5691 | var CoreModule = {
|
5692 | __depends__: [ DrawModule ],
|
5693 | __init__: [ 'canvas' ],
|
5694 | canvas: [ 'type', Canvas ],
|
5695 | elementRegistry: [ 'type', ElementRegistry ],
|
5696 | elementFactory: [ 'type', ElementFactory ],
|
5697 | eventBus: [ 'type', EventBus ],
|
5698 | graphicsFactory: [ 'type', GraphicsFactory ]
|
5699 | };
|
5700 |
|
5701 | |
5702 |
|
5703 |
|
5704 |
|
5705 |
|
5706 |
|
5707 |
|
5708 |
|
5709 | function bootstrap(bootstrapModules) {
|
5710 |
|
5711 | var modules = [],
|
5712 | components = [];
|
5713 |
|
5714 | function hasModule(m) {
|
5715 | return modules.indexOf(m) >= 0;
|
5716 | }
|
5717 |
|
5718 | function addModule(m) {
|
5719 | modules.push(m);
|
5720 | }
|
5721 |
|
5722 | function visit(m) {
|
5723 | if (hasModule(m)) {
|
5724 | return;
|
5725 | }
|
5726 |
|
5727 | (m.__depends__ || []).forEach(visit);
|
5728 |
|
5729 | if (hasModule(m)) {
|
5730 | return;
|
5731 | }
|
5732 |
|
5733 | addModule(m);
|
5734 |
|
5735 | (m.__init__ || []).forEach(function(c) {
|
5736 | components.push(c);
|
5737 | });
|
5738 | }
|
5739 |
|
5740 | bootstrapModules.forEach(visit);
|
5741 |
|
5742 | var injector = new Injector(modules);
|
5743 |
|
5744 | components.forEach(function(c) {
|
5745 |
|
5746 | try {
|
5747 |
|
5748 |
|
5749 | injector[typeof c === 'string' ? 'get' : 'invoke'](c);
|
5750 | } catch (e) {
|
5751 | console.error('Failed to instantiate component');
|
5752 | console.error(e.stack);
|
5753 |
|
5754 | throw e;
|
5755 | }
|
5756 | });
|
5757 |
|
5758 | return injector;
|
5759 | }
|
5760 |
|
5761 | |
5762 |
|
5763 |
|
5764 |
|
5765 |
|
5766 |
|
5767 |
|
5768 | function createInjector(options) {
|
5769 |
|
5770 | options = options || {};
|
5771 |
|
5772 | var configModule = {
|
5773 | 'config': ['value', options]
|
5774 | };
|
5775 |
|
5776 | var modules = [ configModule, CoreModule ].concat(options.modules || []);
|
5777 |
|
5778 | return bootstrap(modules);
|
5779 | }
|
5780 |
|
5781 |
|
5782 | |
5783 |
|
5784 |
|
5785 |
|
5786 |
|
5787 |
|
5788 |
|
5789 |
|
5790 |
|
5791 |
|
5792 |
|
5793 |
|
5794 |
|
5795 |
|
5796 |
|
5797 |
|
5798 |
|
5799 |
|
5800 |
|
5801 |
|
5802 |
|
5803 |
|
5804 |
|
5805 |
|
5806 |
|
5807 |
|
5808 |
|
5809 |
|
5810 |
|
5811 |
|
5812 |
|
5813 |
|
5814 |
|
5815 |
|
5816 |
|
5817 |
|
5818 |
|
5819 |
|
5820 |
|
5821 |
|
5822 |
|
5823 |
|
5824 |
|
5825 |
|
5826 |
|
5827 |
|
5828 |
|
5829 |
|
5830 |
|
5831 | function Diagram(options, injector) {
|
5832 |
|
5833 |
|
5834 | this.injector = injector = injector || createInjector(options);
|
5835 |
|
5836 |
|
5837 |
|
5838 | |
5839 |
|
5840 |
|
5841 |
|
5842 |
|
5843 |
|
5844 |
|
5845 |
|
5846 | this.get = injector.get;
|
5847 |
|
5848 | |
5849 |
|
5850 |
|
5851 |
|
5852 |
|
5853 |
|
5854 |
|
5855 |
|
5856 | this.invoke = injector.invoke;
|
5857 |
|
5858 |
|
5859 |
|
5860 |
|
5861 |
|
5862 |
|
5863 | |
5864 |
|
5865 |
|
5866 |
|
5867 |
|
5868 |
|
5869 |
|
5870 |
|
5871 |
|
5872 |
|
5873 |
|
5874 |
|
5875 |
|
5876 |
|
5877 |
|
5878 |
|
5879 |
|
5880 | this.get('eventBus').fire('diagram.init');
|
5881 | }
|
5882 |
|
5883 |
|
5884 | |
5885 |
|
5886 |
|
5887 |
|
5888 |
|
5889 | Diagram.prototype.destroy = function() {
|
5890 | this.get('eventBus').fire('diagram.destroy');
|
5891 | };
|
5892 |
|
5893 | |
5894 |
|
5895 |
|
5896 | Diagram.prototype.clear = function() {
|
5897 | this.get('eventBus').fire('diagram.clear');
|
5898 | };
|
5899 |
|
5900 | |
5901 |
|
5902 |
|
5903 | function Base$1() { }
|
5904 |
|
5905 | Base$1.prototype.get = function(name) {
|
5906 | return this.$model.properties.get(this, name);
|
5907 | };
|
5908 |
|
5909 | Base$1.prototype.set = function(name, value) {
|
5910 | this.$model.properties.set(this, name, value);
|
5911 | };
|
5912 |
|
5913 | |
5914 |
|
5915 |
|
5916 |
|
5917 |
|
5918 |
|
5919 | function Factory(model, properties) {
|
5920 | this.model = model;
|
5921 | this.properties = properties;
|
5922 | }
|
5923 |
|
5924 |
|
5925 | Factory.prototype.createType = function(descriptor) {
|
5926 |
|
5927 | var model = this.model;
|
5928 |
|
5929 | var props = this.properties,
|
5930 | prototype = Object.create(Base$1.prototype);
|
5931 |
|
5932 |
|
5933 | forEach(descriptor.properties, function(p) {
|
5934 | if (!p.isMany && p.default !== undefined) {
|
5935 | prototype[p.name] = p.default;
|
5936 | }
|
5937 | });
|
5938 |
|
5939 | props.defineModel(prototype, model);
|
5940 | props.defineDescriptor(prototype, descriptor);
|
5941 |
|
5942 | var name = descriptor.ns.name;
|
5943 |
|
5944 | |
5945 |
|
5946 |
|
5947 | function ModdleElement(attrs) {
|
5948 | props.define(this, '$type', { value: name, enumerable: true });
|
5949 | props.define(this, '$attrs', { value: {} });
|
5950 | props.define(this, '$parent', { writable: true });
|
5951 |
|
5952 | forEach(attrs, bind(function(val, key) {
|
5953 | this.set(key, val);
|
5954 | }, this));
|
5955 | }
|
5956 |
|
5957 | ModdleElement.prototype = prototype;
|
5958 |
|
5959 | ModdleElement.hasType = prototype.$instanceOf = this.model.hasType;
|
5960 |
|
5961 |
|
5962 | props.defineModel(ModdleElement, model);
|
5963 | props.defineDescriptor(ModdleElement, descriptor);
|
5964 |
|
5965 | return ModdleElement;
|
5966 | };
|
5967 |
|
5968 | |
5969 |
|
5970 |
|
5971 | var BUILTINS = {
|
5972 | String: true,
|
5973 | Boolean: true,
|
5974 | Integer: true,
|
5975 | Real: true,
|
5976 | Element: true
|
5977 | };
|
5978 |
|
5979 | |
5980 |
|
5981 |
|
5982 | var TYPE_CONVERTERS = {
|
5983 | String: function(s) { return s; },
|
5984 | Boolean: function(s) { return s === 'true'; },
|
5985 | Integer: function(s) { return parseInt(s, 10); },
|
5986 | Real: function(s) { return parseFloat(s, 10); }
|
5987 | };
|
5988 |
|
5989 | |
5990 |
|
5991 |
|
5992 | function coerceType(type, value) {
|
5993 |
|
5994 | var converter = TYPE_CONVERTERS[type];
|
5995 |
|
5996 | if (converter) {
|
5997 | return converter(value);
|
5998 | } else {
|
5999 | return value;
|
6000 | }
|
6001 | }
|
6002 |
|
6003 | |
6004 |
|
6005 |
|
6006 | function isBuiltIn(type) {
|
6007 | return !!BUILTINS[type];
|
6008 | }
|
6009 |
|
6010 | |
6011 |
|
6012 |
|
6013 | function isSimple(type) {
|
6014 | return !!TYPE_CONVERTERS[type];
|
6015 | }
|
6016 |
|
6017 | |
6018 |
|
6019 |
|
6020 |
|
6021 |
|
6022 |
|
6023 |
|
6024 |
|
6025 |
|
6026 | function parseName(name, defaultPrefix) {
|
6027 | var parts = name.split(/:/),
|
6028 | localName, prefix;
|
6029 |
|
6030 |
|
6031 | if (parts.length === 1) {
|
6032 | localName = name;
|
6033 | prefix = defaultPrefix;
|
6034 | } else
|
6035 |
|
6036 | if (parts.length === 2) {
|
6037 | localName = parts[1];
|
6038 | prefix = parts[0];
|
6039 | } else {
|
6040 | throw new Error('expected <prefix:localName> or <localName>, got ' + name);
|
6041 | }
|
6042 |
|
6043 | name = (prefix ? prefix + ':' : '') + localName;
|
6044 |
|
6045 | return {
|
6046 | name: name,
|
6047 | prefix: prefix,
|
6048 | localName: localName
|
6049 | };
|
6050 | }
|
6051 |
|
6052 | |
6053 |
|
6054 |
|
6055 | function DescriptorBuilder(nameNs) {
|
6056 | this.ns = nameNs;
|
6057 | this.name = nameNs.name;
|
6058 | this.allTypes = [];
|
6059 | this.allTypesByName = {};
|
6060 | this.properties = [];
|
6061 | this.propertiesByName = {};
|
6062 | }
|
6063 |
|
6064 |
|
6065 | DescriptorBuilder.prototype.build = function() {
|
6066 | return pick(this, [
|
6067 | 'ns',
|
6068 | 'name',
|
6069 | 'allTypes',
|
6070 | 'allTypesByName',
|
6071 | 'properties',
|
6072 | 'propertiesByName',
|
6073 | 'bodyProperty',
|
6074 | 'idProperty'
|
6075 | ]);
|
6076 | };
|
6077 |
|
6078 | |
6079 |
|
6080 |
|
6081 |
|
6082 |
|
6083 |
|
6084 |
|
6085 | DescriptorBuilder.prototype.addProperty = function(p, idx, validate) {
|
6086 |
|
6087 | if (typeof idx === 'boolean') {
|
6088 | validate = idx;
|
6089 | idx = undefined;
|
6090 | }
|
6091 |
|
6092 | this.addNamedProperty(p, validate !== false);
|
6093 |
|
6094 | var properties = this.properties;
|
6095 |
|
6096 | if (idx !== undefined) {
|
6097 | properties.splice(idx, 0, p);
|
6098 | } else {
|
6099 | properties.push(p);
|
6100 | }
|
6101 | };
|
6102 |
|
6103 |
|
6104 | DescriptorBuilder.prototype.replaceProperty = function(oldProperty, newProperty, replace) {
|
6105 | var oldNameNs = oldProperty.ns;
|
6106 |
|
6107 | var props = this.properties,
|
6108 | propertiesByName = this.propertiesByName,
|
6109 | rename = oldProperty.name !== newProperty.name;
|
6110 |
|
6111 | if (oldProperty.isId) {
|
6112 | if (!newProperty.isId) {
|
6113 | throw new Error(
|
6114 | 'property <' + newProperty.ns.name + '> must be id property ' +
|
6115 | 'to refine <' + oldProperty.ns.name + '>');
|
6116 | }
|
6117 |
|
6118 | this.setIdProperty(newProperty, false);
|
6119 | }
|
6120 |
|
6121 | if (oldProperty.isBody) {
|
6122 |
|
6123 | if (!newProperty.isBody) {
|
6124 | throw new Error(
|
6125 | 'property <' + newProperty.ns.name + '> must be body property ' +
|
6126 | 'to refine <' + oldProperty.ns.name + '>');
|
6127 | }
|
6128 |
|
6129 |
|
6130 | this.setBodyProperty(newProperty, false);
|
6131 | }
|
6132 |
|
6133 |
|
6134 | var idx = props.indexOf(oldProperty);
|
6135 | if (idx === -1) {
|
6136 | throw new Error('property <' + oldNameNs.name + '> not found in property list');
|
6137 | }
|
6138 |
|
6139 |
|
6140 | props.splice(idx, 1);
|
6141 |
|
6142 |
|
6143 |
|
6144 |
|
6145 |
|
6146 |
|
6147 | this.addProperty(newProperty, replace ? undefined : idx, rename);
|
6148 |
|
6149 |
|
6150 | propertiesByName[oldNameNs.name] = propertiesByName[oldNameNs.localName] = newProperty;
|
6151 | };
|
6152 |
|
6153 |
|
6154 | DescriptorBuilder.prototype.redefineProperty = function(p, targetPropertyName, replace) {
|
6155 |
|
6156 | var nsPrefix = p.ns.prefix;
|
6157 | var parts = targetPropertyName.split('#');
|
6158 |
|
6159 | var name = parseName(parts[0], nsPrefix);
|
6160 | var attrName = parseName(parts[1], name.prefix).name;
|
6161 |
|
6162 | var redefinedProperty = this.propertiesByName[attrName];
|
6163 | if (!redefinedProperty) {
|
6164 | throw new Error('refined property <' + attrName + '> not found');
|
6165 | } else {
|
6166 | this.replaceProperty(redefinedProperty, p, replace);
|
6167 | }
|
6168 |
|
6169 | delete p.redefines;
|
6170 | };
|
6171 |
|
6172 | DescriptorBuilder.prototype.addNamedProperty = function(p, validate) {
|
6173 | var ns = p.ns,
|
6174 | propsByName = this.propertiesByName;
|
6175 |
|
6176 | if (validate) {
|
6177 | this.assertNotDefined(p, ns.name);
|
6178 | this.assertNotDefined(p, ns.localName);
|
6179 | }
|
6180 |
|
6181 | propsByName[ns.name] = propsByName[ns.localName] = p;
|
6182 | };
|
6183 |
|
6184 | DescriptorBuilder.prototype.removeNamedProperty = function(p) {
|
6185 | var ns = p.ns,
|
6186 | propsByName = this.propertiesByName;
|
6187 |
|
6188 | delete propsByName[ns.name];
|
6189 | delete propsByName[ns.localName];
|
6190 | };
|
6191 |
|
6192 | DescriptorBuilder.prototype.setBodyProperty = function(p, validate) {
|
6193 |
|
6194 | if (validate && this.bodyProperty) {
|
6195 | throw new Error(
|
6196 | 'body property defined multiple times ' +
|
6197 | '(<' + this.bodyProperty.ns.name + '>, <' + p.ns.name + '>)');
|
6198 | }
|
6199 |
|
6200 | this.bodyProperty = p;
|
6201 | };
|
6202 |
|
6203 | DescriptorBuilder.prototype.setIdProperty = function(p, validate) {
|
6204 |
|
6205 | if (validate && this.idProperty) {
|
6206 | throw new Error(
|
6207 | 'id property defined multiple times ' +
|
6208 | '(<' + this.idProperty.ns.name + '>, <' + p.ns.name + '>)');
|
6209 | }
|
6210 |
|
6211 | this.idProperty = p;
|
6212 | };
|
6213 |
|
6214 | DescriptorBuilder.prototype.assertNotDefined = function(p, name) {
|
6215 | var propertyName = p.name,
|
6216 | definedProperty = this.propertiesByName[propertyName];
|
6217 |
|
6218 | if (definedProperty) {
|
6219 | throw new Error(
|
6220 | 'property <' + propertyName + '> already defined; ' +
|
6221 | 'override of <' + definedProperty.definedBy.ns.name + '#' + definedProperty.ns.name + '> by ' +
|
6222 | '<' + p.definedBy.ns.name + '#' + p.ns.name + '> not allowed without redefines');
|
6223 | }
|
6224 | };
|
6225 |
|
6226 | DescriptorBuilder.prototype.hasProperty = function(name) {
|
6227 | return this.propertiesByName[name];
|
6228 | };
|
6229 |
|
6230 | DescriptorBuilder.prototype.addTrait = function(t, inherited) {
|
6231 |
|
6232 | var typesByName = this.allTypesByName,
|
6233 | types = this.allTypes;
|
6234 |
|
6235 | var typeName = t.name;
|
6236 |
|
6237 | if (typeName in typesByName) {
|
6238 | return;
|
6239 | }
|
6240 |
|
6241 | forEach(t.properties, bind(function(p) {
|
6242 |
|
6243 |
|
6244 | p = assign({}, p, {
|
6245 | name: p.ns.localName,
|
6246 | inherited: inherited
|
6247 | });
|
6248 |
|
6249 | Object.defineProperty(p, 'definedBy', {
|
6250 | value: t
|
6251 | });
|
6252 |
|
6253 | var replaces = p.replaces,
|
6254 | redefines = p.redefines;
|
6255 |
|
6256 |
|
6257 | if (replaces || redefines) {
|
6258 | this.redefineProperty(p, replaces || redefines, replaces);
|
6259 | } else {
|
6260 | if (p.isBody) {
|
6261 | this.setBodyProperty(p);
|
6262 | }
|
6263 | if (p.isId) {
|
6264 | this.setIdProperty(p);
|
6265 | }
|
6266 | this.addProperty(p);
|
6267 | }
|
6268 | }, this));
|
6269 |
|
6270 | types.push(t);
|
6271 | typesByName[typeName] = t;
|
6272 | };
|
6273 |
|
6274 | |
6275 |
|
6276 |
|
6277 |
|
6278 |
|
6279 |
|
6280 | function Registry(packages, properties) {
|
6281 | this.packageMap = {};
|
6282 | this.typeMap = {};
|
6283 |
|
6284 | this.packages = [];
|
6285 |
|
6286 | this.properties = properties;
|
6287 |
|
6288 | forEach(packages, bind(this.registerPackage, this));
|
6289 | }
|
6290 |
|
6291 |
|
6292 | Registry.prototype.getPackage = function(uriOrPrefix) {
|
6293 | return this.packageMap[uriOrPrefix];
|
6294 | };
|
6295 |
|
6296 | Registry.prototype.getPackages = function() {
|
6297 | return this.packages;
|
6298 | };
|
6299 |
|
6300 |
|
6301 | Registry.prototype.registerPackage = function(pkg) {
|
6302 |
|
6303 |
|
6304 | pkg = assign({}, pkg);
|
6305 |
|
6306 | var pkgMap = this.packageMap;
|
6307 |
|
6308 | ensureAvailable(pkgMap, pkg, 'prefix');
|
6309 | ensureAvailable(pkgMap, pkg, 'uri');
|
6310 |
|
6311 |
|
6312 | forEach(pkg.types, bind(function(descriptor) {
|
6313 | this.registerType(descriptor, pkg);
|
6314 | }, this));
|
6315 |
|
6316 | pkgMap[pkg.uri] = pkgMap[pkg.prefix] = pkg;
|
6317 | this.packages.push(pkg);
|
6318 | };
|
6319 |
|
6320 |
|
6321 | |
6322 |
|
6323 |
|
6324 | Registry.prototype.registerType = function(type, pkg) {
|
6325 |
|
6326 | type = assign({}, type, {
|
6327 | superClass: (type.superClass || []).slice(),
|
6328 | extends: (type.extends || []).slice(),
|
6329 | properties: (type.properties || []).slice(),
|
6330 | meta: assign((type.meta || {}))
|
6331 | });
|
6332 |
|
6333 | var ns = parseName(type.name, pkg.prefix),
|
6334 | name = ns.name,
|
6335 | propertiesByName = {};
|
6336 |
|
6337 |
|
6338 | forEach(type.properties, bind(function(p) {
|
6339 |
|
6340 |
|
6341 | var propertyNs = parseName(p.name, ns.prefix),
|
6342 | propertyName = propertyNs.name;
|
6343 |
|
6344 |
|
6345 | if (!isBuiltIn(p.type)) {
|
6346 | p.type = parseName(p.type, propertyNs.prefix).name;
|
6347 | }
|
6348 |
|
6349 | assign(p, {
|
6350 | ns: propertyNs,
|
6351 | name: propertyName
|
6352 | });
|
6353 |
|
6354 | propertiesByName[propertyName] = p;
|
6355 | }, this));
|
6356 |
|
6357 |
|
6358 | assign(type, {
|
6359 | ns: ns,
|
6360 | name: name,
|
6361 | propertiesByName: propertiesByName
|
6362 | });
|
6363 |
|
6364 | forEach(type.extends, bind(function(extendsName) {
|
6365 | var extended = this.typeMap[extendsName];
|
6366 |
|
6367 | extended.traits = extended.traits || [];
|
6368 | extended.traits.push(name);
|
6369 | }, this));
|
6370 |
|
6371 |
|
6372 | this.definePackage(type, pkg);
|
6373 |
|
6374 |
|
6375 | this.typeMap[name] = type;
|
6376 | };
|
6377 |
|
6378 |
|
6379 | |
6380 |
|
6381 |
|
6382 |
|
6383 |
|
6384 |
|
6385 |
|
6386 |
|
6387 |
|
6388 | Registry.prototype.mapTypes = function(nsName, iterator, trait) {
|
6389 |
|
6390 | var type = isBuiltIn(nsName.name) ? { name: nsName.name } : this.typeMap[nsName.name];
|
6391 |
|
6392 | var self = this;
|
6393 |
|
6394 | |
6395 |
|
6396 |
|
6397 |
|
6398 |
|
6399 | function traverseTrait(cls) {
|
6400 | return traverseSuper(cls, true);
|
6401 | }
|
6402 |
|
6403 | |
6404 |
|
6405 |
|
6406 |
|
6407 |
|
6408 |
|
6409 | function traverseSuper(cls, trait) {
|
6410 | var parentNs = parseName(cls, isBuiltIn(cls) ? '' : nsName.prefix);
|
6411 | self.mapTypes(parentNs, iterator, trait);
|
6412 | }
|
6413 |
|
6414 | if (!type) {
|
6415 | throw new Error('unknown type <' + nsName.name + '>');
|
6416 | }
|
6417 |
|
6418 | forEach(type.superClass, trait ? traverseTrait : traverseSuper);
|
6419 |
|
6420 |
|
6421 | iterator(type, !trait);
|
6422 |
|
6423 | forEach(type.traits, traverseTrait);
|
6424 | };
|
6425 |
|
6426 |
|
6427 | |
6428 |
|
6429 |
|
6430 |
|
6431 |
|
6432 |
|
6433 |
|
6434 | Registry.prototype.getEffectiveDescriptor = function(name) {
|
6435 |
|
6436 | var nsName = parseName(name);
|
6437 |
|
6438 | var builder = new DescriptorBuilder(nsName);
|
6439 |
|
6440 | this.mapTypes(nsName, function(type, inherited) {
|
6441 | builder.addTrait(type, inherited);
|
6442 | });
|
6443 |
|
6444 | var descriptor = builder.build();
|
6445 |
|
6446 |
|
6447 | this.definePackage(descriptor, descriptor.allTypes[descriptor.allTypes.length - 1].$pkg);
|
6448 |
|
6449 | return descriptor;
|
6450 | };
|
6451 |
|
6452 |
|
6453 | Registry.prototype.definePackage = function(target, pkg) {
|
6454 | this.properties.define(target, '$pkg', { value: pkg });
|
6455 | };
|
6456 |
|
6457 |
|
6458 |
|
6459 |
|
6460 |
|
6461 | function ensureAvailable(packageMap, pkg, identifierKey) {
|
6462 |
|
6463 | var value = pkg[identifierKey];
|
6464 |
|
6465 | if (value in packageMap) {
|
6466 | throw new Error('package with ' + identifierKey + ' <' + value + '> already defined');
|
6467 | }
|
6468 | }
|
6469 |
|
6470 | |
6471 |
|
6472 |
|
6473 |
|
6474 |
|
6475 | function Properties(model) {
|
6476 | this.model = model;
|
6477 | }
|
6478 |
|
6479 |
|
6480 | |
6481 |
|
6482 |
|
6483 |
|
6484 |
|
6485 |
|
6486 |
|
6487 |
|
6488 | Properties.prototype.set = function(target, name, value) {
|
6489 |
|
6490 | var property = this.model.getPropertyDescriptor(target, name);
|
6491 |
|
6492 | var propertyName = property && property.name;
|
6493 |
|
6494 | if (isUndefined$1(value)) {
|
6495 |
|
6496 |
|
6497 | if (property) {
|
6498 | delete target[propertyName];
|
6499 | } else {
|
6500 | delete target.$attrs[name];
|
6501 | }
|
6502 | } else {
|
6503 |
|
6504 |
|
6505 | if (property) {
|
6506 | if (propertyName in target) {
|
6507 | target[propertyName] = value;
|
6508 | } else {
|
6509 | defineProperty$1(target, property, value);
|
6510 | }
|
6511 | } else {
|
6512 | target.$attrs[name] = value;
|
6513 | }
|
6514 | }
|
6515 | };
|
6516 |
|
6517 | |
6518 |
|
6519 |
|
6520 |
|
6521 |
|
6522 |
|
6523 |
|
6524 |
|
6525 | Properties.prototype.get = function(target, name) {
|
6526 |
|
6527 | var property = this.model.getPropertyDescriptor(target, name);
|
6528 |
|
6529 | if (!property) {
|
6530 | return target.$attrs[name];
|
6531 | }
|
6532 |
|
6533 | var propertyName = property.name;
|
6534 |
|
6535 |
|
6536 | if (!target[propertyName] && property.isMany) {
|
6537 | defineProperty$1(target, property, []);
|
6538 | }
|
6539 |
|
6540 | return target[propertyName];
|
6541 | };
|
6542 |
|
6543 |
|
6544 | |
6545 |
|
6546 |
|
6547 |
|
6548 |
|
6549 |
|
6550 |
|
6551 | Properties.prototype.define = function(target, name, options) {
|
6552 | Object.defineProperty(target, name, options);
|
6553 | };
|
6554 |
|
6555 |
|
6556 | |
6557 |
|
6558 |
|
6559 | Properties.prototype.defineDescriptor = function(target, descriptor) {
|
6560 | this.define(target, '$descriptor', { value: descriptor });
|
6561 | };
|
6562 |
|
6563 | |
6564 |
|
6565 |
|
6566 | Properties.prototype.defineModel = function(target, model) {
|
6567 | this.define(target, '$model', { value: model });
|
6568 | };
|
6569 |
|
6570 |
|
6571 | function isUndefined$1(val) {
|
6572 | return typeof val === 'undefined';
|
6573 | }
|
6574 |
|
6575 | function defineProperty$1(target, property, value) {
|
6576 | Object.defineProperty(target, property.name, {
|
6577 | enumerable: !property.isReference,
|
6578 | writable: true,
|
6579 | value: value,
|
6580 | configurable: true
|
6581 | });
|
6582 | }
|
6583 |
|
6584 |
|
6585 |
|
6586 | |
6587 |
|
6588 |
|
6589 |
|
6590 |
|
6591 |
|
6592 |
|
6593 |
|
6594 |
|
6595 |
|
6596 |
|
6597 |
|
6598 |
|
6599 |
|
6600 |
|
6601 |
|
6602 |
|
6603 |
|
6604 |
|
6605 |
|
6606 |
|
6607 | function Moddle(packages) {
|
6608 |
|
6609 | this.properties = new Properties(this);
|
6610 |
|
6611 | this.factory = new Factory(this, this.properties);
|
6612 | this.registry = new Registry(packages, this.properties);
|
6613 |
|
6614 | this.typeCache = {};
|
6615 | }
|
6616 |
|
6617 |
|
6618 | |
6619 |
|
6620 |
|
6621 |
|
6622 |
|
6623 |
|
6624 |
|
6625 |
|
6626 |
|
6627 |
|
6628 |
|
6629 |
|
6630 |
|
6631 |
|
6632 | Moddle.prototype.create = function(descriptor, attrs) {
|
6633 | var Type = this.getType(descriptor);
|
6634 |
|
6635 | if (!Type) {
|
6636 | throw new Error('unknown type <' + descriptor + '>');
|
6637 | }
|
6638 |
|
6639 | return new Type(attrs);
|
6640 | };
|
6641 |
|
6642 |
|
6643 | |
6644 |
|
6645 |
|
6646 |
|
6647 |
|
6648 |
|
6649 |
|
6650 |
|
6651 |
|
6652 |
|
6653 |
|
6654 |
|
6655 |
|
6656 | Moddle.prototype.getType = function(descriptor) {
|
6657 |
|
6658 | var cache = this.typeCache;
|
6659 |
|
6660 | var name = isString(descriptor) ? descriptor : descriptor.ns.name;
|
6661 |
|
6662 | var type = cache[name];
|
6663 |
|
6664 | if (!type) {
|
6665 | descriptor = this.registry.getEffectiveDescriptor(name);
|
6666 | type = cache[name] = this.factory.createType(descriptor);
|
6667 | }
|
6668 |
|
6669 | return type;
|
6670 | };
|
6671 |
|
6672 |
|
6673 | |
6674 |
|
6675 |
|
6676 |
|
6677 |
|
6678 |
|
6679 |
|
6680 |
|
6681 |
|
6682 |
|
6683 |
|
6684 |
|
6685 |
|
6686 |
|
6687 |
|
6688 |
|
6689 |
|
6690 |
|
6691 |
|
6692 |
|
6693 |
|
6694 |
|
6695 |
|
6696 |
|
6697 |
|
6698 |
|
6699 |
|
6700 | Moddle.prototype.createAny = function(name, nsUri, properties) {
|
6701 |
|
6702 | var nameNs = parseName(name);
|
6703 |
|
6704 | var element = {
|
6705 | $type: name,
|
6706 | $instanceOf: function(type) {
|
6707 | return type === this.$type;
|
6708 | }
|
6709 | };
|
6710 |
|
6711 | var descriptor = {
|
6712 | name: name,
|
6713 | isGeneric: true,
|
6714 | ns: {
|
6715 | prefix: nameNs.prefix,
|
6716 | localName: nameNs.localName,
|
6717 | uri: nsUri
|
6718 | }
|
6719 | };
|
6720 |
|
6721 | this.properties.defineDescriptor(element, descriptor);
|
6722 | this.properties.defineModel(element, this);
|
6723 | this.properties.define(element, '$parent', { enumerable: false, writable: true });
|
6724 |
|
6725 | forEach(properties, function(a, key) {
|
6726 | if (isObject(a) && a.value !== undefined) {
|
6727 | element[a.name] = a.value;
|
6728 | } else {
|
6729 | element[key] = a;
|
6730 | }
|
6731 | });
|
6732 |
|
6733 | return element;
|
6734 | };
|
6735 |
|
6736 | |
6737 |
|
6738 |
|
6739 |
|
6740 |
|
6741 | Moddle.prototype.getPackage = function(uriOrPrefix) {
|
6742 | return this.registry.getPackage(uriOrPrefix);
|
6743 | };
|
6744 |
|
6745 | |
6746 |
|
6747 |
|
6748 |
|
6749 |
|
6750 | Moddle.prototype.getPackages = function() {
|
6751 | return this.registry.getPackages();
|
6752 | };
|
6753 |
|
6754 | |
6755 |
|
6756 |
|
6757 | Moddle.prototype.getElementDescriptor = function(element) {
|
6758 | return element.$descriptor;
|
6759 | };
|
6760 |
|
6761 | |
6762 |
|
6763 |
|
6764 |
|
6765 |
|
6766 |
|
6767 | Moddle.prototype.hasType = function(element, type) {
|
6768 | if (type === undefined) {
|
6769 | type = element;
|
6770 | element = this;
|
6771 | }
|
6772 |
|
6773 | var descriptor = element.$model.getElementDescriptor(element);
|
6774 |
|
6775 | return (type in descriptor.allTypesByName);
|
6776 | };
|
6777 |
|
6778 | |
6779 |
|
6780 |
|
6781 | Moddle.prototype.getPropertyDescriptor = function(element, property) {
|
6782 | return this.getElementDescriptor(element).propertiesByName[property];
|
6783 | };
|
6784 |
|
6785 | |
6786 |
|
6787 |
|
6788 | Moddle.prototype.getTypeDescriptor = function(type) {
|
6789 | return this.registry.typeMap[type];
|
6790 | };
|
6791 |
|
6792 | var fromCharCode = String.fromCharCode;
|
6793 |
|
6794 | var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
6795 |
|
6796 | var ENTITY_PATTERN = /&#(\d+);|&#x([0-9a-f]+);|&(\w+);/ig;
|
6797 |
|
6798 | var ENTITY_MAPPING = {
|
6799 | 'amp': '&',
|
6800 | 'apos': '\'',
|
6801 | 'gt': '>',
|
6802 | 'lt': '<',
|
6803 | 'quot': '"'
|
6804 | };
|
6805 |
|
6806 |
|
6807 | Object.keys(ENTITY_MAPPING).forEach(function(k) {
|
6808 | ENTITY_MAPPING[k.toUpperCase()] = ENTITY_MAPPING[k];
|
6809 | });
|
6810 |
|
6811 |
|
6812 | function replaceEntities(_, d, x, z) {
|
6813 |
|
6814 |
|
6815 | if (z) {
|
6816 | if (hasOwnProperty$1.call(ENTITY_MAPPING, z)) {
|
6817 | return ENTITY_MAPPING[z];
|
6818 | } else {
|
6819 |
|
6820 | return '&' + z + ';';
|
6821 | }
|
6822 | }
|
6823 |
|
6824 |
|
6825 | if (d) {
|
6826 | return fromCharCode(d);
|
6827 | }
|
6828 |
|
6829 |
|
6830 | return fromCharCode(parseInt(x, 16));
|
6831 | }
|
6832 |
|
6833 |
|
6834 | |
6835 |
|
6836 |
|
6837 |
|
6838 |
|
6839 |
|
6840 |
|
6841 |
|
6842 |
|
6843 | function decodeEntities(s) {
|
6844 | if (s.length > 3 && s.indexOf('&') !== -1) {
|
6845 | return s.replace(ENTITY_PATTERN, replaceEntities);
|
6846 | }
|
6847 |
|
6848 | return s;
|
6849 | }
|
6850 |
|
6851 | var XSI_URI = 'http://www.w3.org/2001/XMLSchema-instance';
|
6852 | var XSI_PREFIX = 'xsi';
|
6853 | var XSI_TYPE = 'xsi:type';
|
6854 |
|
6855 | var NON_WHITESPACE_OUTSIDE_ROOT_NODE = 'non-whitespace outside of root node';
|
6856 |
|
6857 | function error(msg) {
|
6858 | return new Error(msg);
|
6859 | }
|
6860 |
|
6861 | function missingNamespaceForPrefix(prefix) {
|
6862 | return 'missing namespace for prefix <' + prefix + '>';
|
6863 | }
|
6864 |
|
6865 | function getter(getFn) {
|
6866 | return {
|
6867 | 'get': getFn,
|
6868 | 'enumerable': true
|
6869 | };
|
6870 | }
|
6871 |
|
6872 | function cloneNsMatrix(nsMatrix) {
|
6873 | var clone = {}, key;
|
6874 | for (key in nsMatrix) {
|
6875 | clone[key] = nsMatrix[key];
|
6876 | }
|
6877 | return clone;
|
6878 | }
|
6879 |
|
6880 | function uriPrefix(prefix) {
|
6881 | return prefix + '$uri';
|
6882 | }
|
6883 |
|
6884 | function buildNsMatrix(nsUriToPrefix) {
|
6885 | var nsMatrix = {},
|
6886 | uri,
|
6887 | prefix;
|
6888 |
|
6889 | for (uri in nsUriToPrefix) {
|
6890 | prefix = nsUriToPrefix[uri];
|
6891 | nsMatrix[prefix] = prefix;
|
6892 | nsMatrix[uriPrefix(prefix)] = uri;
|
6893 | }
|
6894 |
|
6895 | return nsMatrix;
|
6896 | }
|
6897 |
|
6898 | function noopGetContext() {
|
6899 | return { 'line': 0, 'column': 0 };
|
6900 | }
|
6901 |
|
6902 | function throwFunc(err) {
|
6903 | throw err;
|
6904 | }
|
6905 |
|
6906 | |
6907 |
|
6908 |
|
6909 |
|
6910 |
|
6911 |
|
6912 |
|
6913 | function Parser(options) {
|
6914 |
|
6915 | if (!this) {
|
6916 | return new Parser(options);
|
6917 | }
|
6918 |
|
6919 | var proxy = options && options['proxy'];
|
6920 |
|
6921 | var onText,
|
6922 | onOpenTag,
|
6923 | onCloseTag,
|
6924 | onCDATA,
|
6925 | onError = throwFunc,
|
6926 | onWarning,
|
6927 | onComment,
|
6928 | onQuestion,
|
6929 | onAttention;
|
6930 |
|
6931 | var getContext = noopGetContext;
|
6932 |
|
6933 | |
6934 |
|
6935 |
|
6936 |
|
6937 |
|
6938 | var maybeNS = false;
|
6939 |
|
6940 | |
6941 |
|
6942 |
|
6943 |
|
6944 |
|
6945 | var isNamespace = false;
|
6946 |
|
6947 | |
6948 |
|
6949 |
|
6950 |
|
6951 |
|
6952 | var returnError = null;
|
6953 |
|
6954 | |
6955 |
|
6956 |
|
6957 |
|
6958 |
|
6959 | var parseStop = false;
|
6960 |
|
6961 | |
6962 |
|
6963 |
|
6964 |
|
6965 |
|
6966 |
|
6967 |
|
6968 |
|
6969 | var nsUriToPrefix;
|
6970 |
|
6971 | |
6972 |
|
6973 |
|
6974 |
|
6975 |
|
6976 | function handleError(err) {
|
6977 | if (!(err instanceof Error)) {
|
6978 | err = error(err);
|
6979 | }
|
6980 |
|
6981 | returnError = err;
|
6982 |
|
6983 | onError(err, getContext);
|
6984 | }
|
6985 |
|
6986 | |
6987 |
|
6988 |
|
6989 |
|
6990 |
|
6991 | function handleWarning(err) {
|
6992 |
|
6993 | if (!onWarning) {
|
6994 | return;
|
6995 | }
|
6996 |
|
6997 | if (!(err instanceof Error)) {
|
6998 | err = error(err);
|
6999 | }
|
7000 |
|
7001 | onWarning(err, getContext);
|
7002 | }
|
7003 |
|
7004 | |
7005 |
|
7006 |
|
7007 |
|
7008 |
|
7009 |
|
7010 |
|
7011 |
|
7012 | this['on'] = function(name, cb) {
|
7013 |
|
7014 | if (typeof cb !== 'function') {
|
7015 | throw error('required args <name, cb>');
|
7016 | }
|
7017 |
|
7018 | switch (name) {
|
7019 | case 'openTag': onOpenTag = cb; break;
|
7020 | case 'text': onText = cb; break;
|
7021 | case 'closeTag': onCloseTag = cb; break;
|
7022 | case 'error': onError = cb; break;
|
7023 | case 'warn': onWarning = cb; break;
|
7024 | case 'cdata': onCDATA = cb; break;
|
7025 | case 'attention': onAttention = cb; break;
|
7026 | case 'question': onQuestion = cb; break;
|
7027 | case 'comment': onComment = cb; break;
|
7028 | default:
|
7029 | throw error('unsupported event: ' + name);
|
7030 | }
|
7031 |
|
7032 | return this;
|
7033 | };
|
7034 |
|
7035 | |
7036 |
|
7037 |
|
7038 |
|
7039 |
|
7040 |
|
7041 |
|
7042 |
|
7043 |
|
7044 |
|
7045 |
|
7046 |
|
7047 |
|
7048 |
|
7049 | this['ns'] = function(nsMap) {
|
7050 |
|
7051 | if (typeof nsMap === 'undefined') {
|
7052 | nsMap = {};
|
7053 | }
|
7054 |
|
7055 | if (typeof nsMap !== 'object') {
|
7056 | throw error('required args <nsMap={}>');
|
7057 | }
|
7058 |
|
7059 | var _nsUriToPrefix = {}, k;
|
7060 |
|
7061 | for (k in nsMap) {
|
7062 | _nsUriToPrefix[k] = nsMap[k];
|
7063 | }
|
7064 |
|
7065 |
|
7066 | _nsUriToPrefix[XSI_URI] = XSI_PREFIX;
|
7067 |
|
7068 | isNamespace = true;
|
7069 | nsUriToPrefix = _nsUriToPrefix;
|
7070 |
|
7071 | return this;
|
7072 | };
|
7073 |
|
7074 | |
7075 |
|
7076 |
|
7077 |
|
7078 |
|
7079 |
|
7080 |
|
7081 | this['parse'] = function(xml) {
|
7082 | if (typeof xml !== 'string') {
|
7083 | throw error('required args <xml=string>');
|
7084 | }
|
7085 |
|
7086 | returnError = null;
|
7087 |
|
7088 | parse(xml);
|
7089 |
|
7090 | getContext = noopGetContext;
|
7091 | parseStop = false;
|
7092 |
|
7093 | return returnError;
|
7094 | };
|
7095 |
|
7096 | |
7097 |
|
7098 |
|
7099 | this['stop'] = function() {
|
7100 | parseStop = true;
|
7101 | };
|
7102 |
|
7103 | |
7104 |
|
7105 |
|
7106 |
|
7107 |
|
7108 | function parse(xml) {
|
7109 | var nsMatrixStack = isNamespace ? [] : null,
|
7110 | nsMatrix = isNamespace ? buildNsMatrix(nsUriToPrefix) : null,
|
7111 | _nsMatrix,
|
7112 | nodeStack = [],
|
7113 | anonymousNsCount = 0,
|
7114 | tagStart = false,
|
7115 | tagEnd = false,
|
7116 | i = 0, j = 0,
|
7117 | x, y, q, w,
|
7118 | xmlns,
|
7119 | elementName,
|
7120 | _elementName,
|
7121 | elementProxy
|
7122 | ;
|
7123 |
|
7124 | var attrsString = '',
|
7125 | attrsStart = 0,
|
7126 | cachedAttrs
|
7127 | ;
|
7128 |
|
7129 | |
7130 |
|
7131 |
|
7132 |
|
7133 |
|
7134 |
|
7135 |
|
7136 |
|
7137 | function getAttrs() {
|
7138 | if (cachedAttrs !== null) {
|
7139 | return cachedAttrs;
|
7140 | }
|
7141 |
|
7142 | var nsUri,
|
7143 | nsUriPrefix,
|
7144 | nsName,
|
7145 | defaultAlias = isNamespace && nsMatrix['xmlns'],
|
7146 | attrList = isNamespace && maybeNS ? [] : null,
|
7147 | i = attrsStart,
|
7148 | s = attrsString,
|
7149 | l = s.length,
|
7150 | hasNewMatrix,
|
7151 | newalias,
|
7152 | value,
|
7153 | alias,
|
7154 | name,
|
7155 | attrs = {},
|
7156 | seenAttrs = {},
|
7157 | skipAttr,
|
7158 | w,
|
7159 | j;
|
7160 |
|
7161 | parseAttr:
|
7162 | for (; i < l; i++) {
|
7163 | skipAttr = false;
|
7164 | w = s.charCodeAt(i);
|
7165 |
|
7166 | if (w === 32 || (w < 14 && w > 8)) {
|
7167 | continue;
|
7168 | }
|
7169 |
|
7170 |
|
7171 | if (w < 65 || w > 122 || (w > 90 && w < 97)) {
|
7172 | if (w !== 95 && w !== 58) {
|
7173 | handleWarning('illegal first char attribute name');
|
7174 | skipAttr = true;
|
7175 | }
|
7176 | }
|
7177 |
|
7178 |
|
7179 | for (j = i + 1; j < l; j++) {
|
7180 | w = s.charCodeAt(j);
|
7181 |
|
7182 | if (
|
7183 | w > 96 && w < 123 ||
|
7184 | w > 64 && w < 91 ||
|
7185 | w > 47 && w < 59 ||
|
7186 | w === 46 ||
|
7187 | w === 45 ||
|
7188 | w === 95
|
7189 | ) {
|
7190 | continue;
|
7191 | }
|
7192 |
|
7193 |
|
7194 | if (w === 32 || (w < 14 && w > 8)) {
|
7195 | handleWarning('missing attribute value');
|
7196 | i = j;
|
7197 |
|
7198 | continue parseAttr;
|
7199 | }
|
7200 |
|
7201 |
|
7202 | if (w === 61) {
|
7203 | break;
|
7204 | }
|
7205 |
|
7206 | handleWarning('illegal attribute name char');
|
7207 | skipAttr = true;
|
7208 | }
|
7209 |
|
7210 | name = s.substring(i, j);
|
7211 |
|
7212 | if (name === 'xmlns:xmlns') {
|
7213 | handleWarning('illegal declaration of xmlns');
|
7214 | skipAttr = true;
|
7215 | }
|
7216 |
|
7217 | w = s.charCodeAt(j + 1);
|
7218 |
|
7219 | if (w === 34) {
|
7220 | j = s.indexOf('"', i = j + 2);
|
7221 |
|
7222 | if (j === -1) {
|
7223 | j = s.indexOf('\'', i);
|
7224 |
|
7225 | if (j !== -1) {
|
7226 | handleWarning('attribute value quote missmatch');
|
7227 | skipAttr = true;
|
7228 | }
|
7229 | }
|
7230 |
|
7231 | } else if (w === 39) {
|
7232 | j = s.indexOf('\'', i = j + 2);
|
7233 |
|
7234 | if (j === -1) {
|
7235 | j = s.indexOf('"', i);
|
7236 |
|
7237 | if (j !== -1) {
|
7238 | handleWarning('attribute value quote missmatch');
|
7239 | skipAttr = true;
|
7240 | }
|
7241 | }
|
7242 |
|
7243 | } else {
|
7244 | handleWarning('missing attribute value quotes');
|
7245 | skipAttr = true;
|
7246 |
|
7247 |
|
7248 | for (j = j + 1; j < l; j++) {
|
7249 | w = s.charCodeAt(j + 1);
|
7250 |
|
7251 | if (w === 32 || (w < 14 && w > 8)) {
|
7252 | break;
|
7253 | }
|
7254 | }
|
7255 |
|
7256 | }
|
7257 |
|
7258 | if (j === -1) {
|
7259 | handleWarning('missing closing quotes');
|
7260 |
|
7261 | j = l;
|
7262 | skipAttr = true;
|
7263 | }
|
7264 |
|
7265 | if (!skipAttr) {
|
7266 | value = s.substring(i, j);
|
7267 | }
|
7268 |
|
7269 | i = j;
|
7270 |
|
7271 |
|
7272 |
|
7273 |
|
7274 | for (; j + 1 < l; j++) {
|
7275 | w = s.charCodeAt(j + 1);
|
7276 |
|
7277 | if (w === 32 || (w < 14 && w > 8)) {
|
7278 | break;
|
7279 | }
|
7280 |
|
7281 |
|
7282 | if (i === j) {
|
7283 | handleWarning('illegal character after attribute end');
|
7284 | skipAttr = true;
|
7285 | }
|
7286 | }
|
7287 |
|
7288 |
|
7289 | i = j + 1;
|
7290 |
|
7291 | if (skipAttr) {
|
7292 | continue parseAttr;
|
7293 | }
|
7294 |
|
7295 |
|
7296 | if (name in seenAttrs) {
|
7297 | handleWarning('attribute <' + name + '> already defined');
|
7298 | continue;
|
7299 | }
|
7300 |
|
7301 | seenAttrs[name] = true;
|
7302 |
|
7303 | if (!isNamespace) {
|
7304 | attrs[name] = value;
|
7305 | continue;
|
7306 | }
|
7307 |
|
7308 |
|
7309 | if (maybeNS) {
|
7310 | newalias = (
|
7311 | name === 'xmlns'
|
7312 | ? 'xmlns'
|
7313 | : (name.charCodeAt(0) === 120 && name.substr(0, 6) === 'xmlns:')
|
7314 | ? name.substr(6)
|
7315 | : null
|
7316 | );
|
7317 |
|
7318 |
|
7319 | if (newalias !== null) {
|
7320 | nsUri = decodeEntities(value);
|
7321 | nsUriPrefix = uriPrefix(newalias);
|
7322 |
|
7323 | alias = nsUriToPrefix[nsUri];
|
7324 |
|
7325 | if (!alias) {
|
7326 |
|
7327 | if (
|
7328 | (newalias === 'xmlns') ||
|
7329 | (nsUriPrefix in nsMatrix && nsMatrix[nsUriPrefix] !== nsUri)
|
7330 | ) {
|
7331 |
|
7332 | do {
|
7333 | alias = 'ns' + (anonymousNsCount++);
|
7334 | } while (typeof nsMatrix[alias] !== 'undefined');
|
7335 | } else {
|
7336 | alias = newalias;
|
7337 | }
|
7338 |
|
7339 | nsUriToPrefix[nsUri] = alias;
|
7340 | }
|
7341 |
|
7342 | if (nsMatrix[newalias] !== alias) {
|
7343 | if (!hasNewMatrix) {
|
7344 | nsMatrix = cloneNsMatrix(nsMatrix);
|
7345 | hasNewMatrix = true;
|
7346 | }
|
7347 |
|
7348 | nsMatrix[newalias] = alias;
|
7349 | if (newalias === 'xmlns') {
|
7350 | nsMatrix[uriPrefix(alias)] = nsUri;
|
7351 | defaultAlias = alias;
|
7352 | }
|
7353 |
|
7354 | nsMatrix[nsUriPrefix] = nsUri;
|
7355 | }
|
7356 |
|
7357 |
|
7358 | attrs[name] = value;
|
7359 | continue;
|
7360 | }
|
7361 |
|
7362 |
|
7363 |
|
7364 | attrList.push(name, value);
|
7365 | continue;
|
7366 |
|
7367 | }
|
7368 |
|
7369 |
|
7370 |
|
7371 | w = name.indexOf(':');
|
7372 | if (w === -1) {
|
7373 | attrs[name] = value;
|
7374 | continue;
|
7375 | }
|
7376 |
|
7377 |
|
7378 | if (!(nsName = nsMatrix[name.substring(0, w)])) {
|
7379 | handleWarning(missingNamespaceForPrefix(name.substring(0, w)));
|
7380 | continue;
|
7381 | }
|
7382 |
|
7383 | name = defaultAlias === nsName
|
7384 | ? name.substr(w + 1)
|
7385 | : nsName + name.substr(w);
|
7386 |
|
7387 |
|
7388 |
|
7389 | if (name === XSI_TYPE) {
|
7390 | w = value.indexOf(':');
|
7391 |
|
7392 | if (w !== -1) {
|
7393 | nsName = value.substring(0, w);
|
7394 |
|
7395 | nsName = nsMatrix[nsName] || nsName;
|
7396 | value = nsName + value.substring(w);
|
7397 | } else {
|
7398 | value = defaultAlias + ':' + value;
|
7399 | }
|
7400 | }
|
7401 |
|
7402 |
|
7403 | attrs[name] = value;
|
7404 | }
|
7405 |
|
7406 |
|
7407 |
|
7408 | if (maybeNS) {
|
7409 |
|
7410 |
|
7411 | for (i = 0, l = attrList.length; i < l; i++) {
|
7412 |
|
7413 | name = attrList[i++];
|
7414 | value = attrList[i];
|
7415 |
|
7416 | w = name.indexOf(':');
|
7417 |
|
7418 | if (w !== -1) {
|
7419 |
|
7420 | if (!(nsName = nsMatrix[name.substring(0, w)])) {
|
7421 | handleWarning(missingNamespaceForPrefix(name.substring(0, w)));
|
7422 | continue;
|
7423 | }
|
7424 |
|
7425 | name = defaultAlias === nsName
|
7426 | ? name.substr(w + 1)
|
7427 | : nsName + name.substr(w);
|
7428 |
|
7429 |
|
7430 |
|
7431 | if (name === XSI_TYPE) {
|
7432 | w = value.indexOf(':');
|
7433 |
|
7434 | if (w !== -1) {
|
7435 | nsName = value.substring(0, w);
|
7436 |
|
7437 | nsName = nsMatrix[nsName] || nsName;
|
7438 | value = nsName + value.substring(w);
|
7439 | } else {
|
7440 | value = defaultAlias + ':' + value;
|
7441 | }
|
7442 | }
|
7443 |
|
7444 | }
|
7445 |
|
7446 | attrs[name] = value;
|
7447 | }
|
7448 |
|
7449 | }
|
7450 |
|
7451 | return cachedAttrs = attrs;
|
7452 | }
|
7453 |
|
7454 | |
7455 |
|
7456 |
|
7457 |
|
7458 |
|
7459 |
|
7460 | function getParseContext() {
|
7461 | var splitsRe = /(\r\n|\r|\n)/g;
|
7462 |
|
7463 | var line = 0;
|
7464 | var column = 0;
|
7465 | var startOfLine = 0;
|
7466 | var endOfLine = j;
|
7467 | var match;
|
7468 | var data;
|
7469 |
|
7470 | while (i >= startOfLine) {
|
7471 |
|
7472 | match = splitsRe.exec(xml);
|
7473 |
|
7474 | if (!match) {
|
7475 | break;
|
7476 | }
|
7477 |
|
7478 |
|
7479 | endOfLine = match[0].length + match.index;
|
7480 |
|
7481 | if (endOfLine > i) {
|
7482 | break;
|
7483 | }
|
7484 |
|
7485 |
|
7486 | line += 1;
|
7487 |
|
7488 | startOfLine = endOfLine;
|
7489 | }
|
7490 |
|
7491 |
|
7492 | if (i == -1) {
|
7493 | column = endOfLine;
|
7494 | data = xml.substring(j);
|
7495 | } else
|
7496 |
|
7497 | if (j === 0) {
|
7498 | console.log(i - startOfLine);
|
7499 | data = xml.substring(j, i);
|
7500 | }
|
7501 |
|
7502 | else {
|
7503 | column = i - startOfLine;
|
7504 | data = (j == -1 ? xml.substring(i) : xml.substring(i, j + 1));
|
7505 | }
|
7506 |
|
7507 | return {
|
7508 | 'data': data,
|
7509 | 'line': line,
|
7510 | 'column': column
|
7511 | };
|
7512 | }
|
7513 |
|
7514 | getContext = getParseContext;
|
7515 |
|
7516 |
|
7517 | if (proxy) {
|
7518 | elementProxy = Object.create({}, {
|
7519 | 'name': getter(function() {
|
7520 | return elementName;
|
7521 | }),
|
7522 | 'originalName': getter(function() {
|
7523 | return _elementName;
|
7524 | }),
|
7525 | 'attrs': getter(getAttrs),
|
7526 | 'ns': getter(function() {
|
7527 | return nsMatrix;
|
7528 | })
|
7529 | });
|
7530 | }
|
7531 |
|
7532 |
|
7533 | while (j !== -1) {
|
7534 |
|
7535 | if (xml.charCodeAt(j) === 60) {
|
7536 | i = j;
|
7537 | } else {
|
7538 | i = xml.indexOf('<', j);
|
7539 | }
|
7540 |
|
7541 |
|
7542 | if (i === -1) {
|
7543 | if (nodeStack.length) {
|
7544 | return handleError('unexpected end of file');
|
7545 | }
|
7546 |
|
7547 | if (j === 0) {
|
7548 | return handleError('missing start tag');
|
7549 | }
|
7550 |
|
7551 | if (j < xml.length) {
|
7552 | if (xml.substring(j).trim()) {
|
7553 | handleWarning(NON_WHITESPACE_OUTSIDE_ROOT_NODE);
|
7554 | }
|
7555 | }
|
7556 |
|
7557 | return;
|
7558 | }
|
7559 |
|
7560 |
|
7561 | if (j !== i) {
|
7562 |
|
7563 | if (nodeStack.length) {
|
7564 | if (onText) {
|
7565 | onText(xml.substring(j, i), decodeEntities, getContext);
|
7566 |
|
7567 | if (parseStop) {
|
7568 | return;
|
7569 | }
|
7570 | }
|
7571 | } else {
|
7572 | if (xml.substring(j, i).trim()) {
|
7573 | handleWarning(NON_WHITESPACE_OUTSIDE_ROOT_NODE);
|
7574 |
|
7575 | if (parseStop) {
|
7576 | return;
|
7577 | }
|
7578 | }
|
7579 | }
|
7580 | }
|
7581 |
|
7582 | w = xml.charCodeAt(i+1);
|
7583 |
|
7584 |
|
7585 | if (w === 33) {
|
7586 | w = xml.charCodeAt(i+2);
|
7587 | if (w === 91 && xml.substr(i + 3, 6) === 'CDATA[') {
|
7588 | j = xml.indexOf(']]>', i);
|
7589 | if (j === -1) {
|
7590 | return handleError('unclosed cdata');
|
7591 | }
|
7592 |
|
7593 | if (onCDATA) {
|
7594 | onCDATA(xml.substring(i + 9, j), getContext);
|
7595 | if (parseStop) {
|
7596 | return;
|
7597 | }
|
7598 | }
|
7599 |
|
7600 | j += 3;
|
7601 | continue;
|
7602 | }
|
7603 |
|
7604 |
|
7605 | if (w === 45 && xml.charCodeAt(i + 3) === 45) {
|
7606 | j = xml.indexOf('-->', i);
|
7607 | if (j === -1) {
|
7608 | return handleError('unclosed comment');
|
7609 | }
|
7610 |
|
7611 |
|
7612 | if (onComment) {
|
7613 | onComment(xml.substring(i + 4, j), decodeEntities, getContext);
|
7614 | if (parseStop) {
|
7615 | return;
|
7616 | }
|
7617 | }
|
7618 |
|
7619 | j += 3;
|
7620 | continue;
|
7621 | }
|
7622 |
|
7623 | j = xml.indexOf('>', i + 1);
|
7624 | if (j === -1) {
|
7625 | return handleError('unclosed tag');
|
7626 | }
|
7627 |
|
7628 | if (onAttention) {
|
7629 | onAttention(xml.substring(i, j + 1), decodeEntities, getContext);
|
7630 | if (parseStop) {
|
7631 | return;
|
7632 | }
|
7633 | }
|
7634 |
|
7635 | j += 1;
|
7636 | continue;
|
7637 | }
|
7638 |
|
7639 | if (w === 63) {
|
7640 | j = xml.indexOf('?>', i);
|
7641 | if (j === -1) {
|
7642 | return handleError('unclosed question');
|
7643 | }
|
7644 |
|
7645 | if (onQuestion) {
|
7646 | onQuestion(xml.substring(i, j + 2), getContext);
|
7647 | if (parseStop) {
|
7648 | return;
|
7649 | }
|
7650 | }
|
7651 |
|
7652 | j += 2;
|
7653 | continue;
|
7654 | }
|
7655 |
|
7656 | j = xml.indexOf('>', i + 1);
|
7657 |
|
7658 | if (j == -1) {
|
7659 | return handleError('unclosed tag');
|
7660 | }
|
7661 |
|
7662 |
|
7663 |
|
7664 | cachedAttrs = {};
|
7665 |
|
7666 |
|
7667 | if (w === 47) {
|
7668 | tagStart = false;
|
7669 | tagEnd = true;
|
7670 |
|
7671 | if (!nodeStack.length) {
|
7672 | return handleError('missing open tag');
|
7673 | }
|
7674 |
|
7675 |
|
7676 | x = elementName = nodeStack.pop();
|
7677 | q = i + 2 + x.length;
|
7678 |
|
7679 | if (xml.substring(i + 2, q) !== x) {
|
7680 | return handleError('closing tag mismatch');
|
7681 | }
|
7682 |
|
7683 |
|
7684 | for (; q < j; q++) {
|
7685 | w = xml.charCodeAt(q);
|
7686 |
|
7687 | if (w === 32 || (w > 8 && w < 14)) {
|
7688 | continue;
|
7689 | }
|
7690 |
|
7691 | return handleError('close tag');
|
7692 | }
|
7693 |
|
7694 | } else {
|
7695 | if (xml.charCodeAt(j - 1) === 47) {
|
7696 | x = elementName = xml.substring(i + 1, j - 1);
|
7697 |
|
7698 | tagStart = true;
|
7699 | tagEnd = true;
|
7700 |
|
7701 | } else {
|
7702 | x = elementName = xml.substring(i + 1, j);
|
7703 |
|
7704 | tagStart = true;
|
7705 | tagEnd = false;
|
7706 | }
|
7707 |
|
7708 | if (!(w > 96 && w < 123 || w > 64 && w < 91 || w === 95 || w === 58)) {
|
7709 | return handleError('illegal first char nodeName');
|
7710 | }
|
7711 |
|
7712 | for (q = 1, y = x.length; q < y; q++) {
|
7713 | w = x.charCodeAt(q);
|
7714 |
|
7715 | if (w > 96 && w < 123 || w > 64 && w < 91 || w > 47 && w < 59 || w === 45 || w === 95 || w == 46) {
|
7716 | continue;
|
7717 | }
|
7718 |
|
7719 | if (w === 32 || (w < 14 && w > 8)) {
|
7720 | elementName = x.substring(0, q);
|
7721 |
|
7722 | cachedAttrs = null;
|
7723 | break;
|
7724 | }
|
7725 |
|
7726 | return handleError('invalid nodeName');
|
7727 | }
|
7728 |
|
7729 | if (!tagEnd) {
|
7730 | nodeStack.push(elementName);
|
7731 | }
|
7732 | }
|
7733 |
|
7734 | if (isNamespace) {
|
7735 |
|
7736 | _nsMatrix = nsMatrix;
|
7737 |
|
7738 | if (tagStart) {
|
7739 |
|
7740 |
|
7741 | if (!tagEnd) {
|
7742 | nsMatrixStack.push(_nsMatrix);
|
7743 | }
|
7744 |
|
7745 | if (cachedAttrs === null) {
|
7746 |
|
7747 |
|
7748 |
|
7749 | if ((maybeNS = x.indexOf('xmlns', q) !== -1)) {
|
7750 | attrsStart = q;
|
7751 | attrsString = x;
|
7752 |
|
7753 | getAttrs();
|
7754 |
|
7755 | maybeNS = false;
|
7756 | }
|
7757 | }
|
7758 | }
|
7759 |
|
7760 | _elementName = elementName;
|
7761 |
|
7762 | w = elementName.indexOf(':');
|
7763 | if (w !== -1) {
|
7764 | xmlns = nsMatrix[elementName.substring(0, w)];
|
7765 |
|
7766 |
|
7767 | if (!xmlns) {
|
7768 | return handleError('missing namespace on <' + _elementName + '>');
|
7769 | }
|
7770 |
|
7771 | elementName = elementName.substr(w + 1);
|
7772 | } else {
|
7773 | xmlns = nsMatrix['xmlns'];
|
7774 |
|
7775 |
|
7776 |
|
7777 |
|
7778 |
|
7779 |
|
7780 |
|
7781 | }
|
7782 |
|
7783 |
|
7784 | if (xmlns) {
|
7785 | elementName = xmlns + ':' + elementName;
|
7786 | }
|
7787 |
|
7788 | }
|
7789 |
|
7790 | if (tagStart) {
|
7791 | attrsStart = q;
|
7792 | attrsString = x;
|
7793 |
|
7794 | if (onOpenTag) {
|
7795 | if (proxy) {
|
7796 | onOpenTag(elementProxy, decodeEntities, tagEnd, getContext);
|
7797 | } else {
|
7798 | onOpenTag(elementName, getAttrs, decodeEntities, tagEnd, getContext);
|
7799 | }
|
7800 |
|
7801 | if (parseStop) {
|
7802 | return;
|
7803 | }
|
7804 | }
|
7805 |
|
7806 | }
|
7807 |
|
7808 | if (tagEnd) {
|
7809 |
|
7810 | if (onCloseTag) {
|
7811 | onCloseTag(proxy ? elementProxy : elementName, decodeEntities, tagStart, getContext);
|
7812 |
|
7813 | if (parseStop) {
|
7814 | return;
|
7815 | }
|
7816 | }
|
7817 |
|
7818 |
|
7819 | if (isNamespace) {
|
7820 | if (!tagStart) {
|
7821 | nsMatrix = nsMatrixStack.pop();
|
7822 | } else {
|
7823 | nsMatrix = _nsMatrix;
|
7824 | }
|
7825 | }
|
7826 | }
|
7827 |
|
7828 | j += 1;
|
7829 | }
|
7830 | }
|
7831 |
|
7832 | }
|
7833 |
|
7834 | function hasLowerCaseAlias(pkg) {
|
7835 | return pkg.xml && pkg.xml.tagAlias === 'lowerCase';
|
7836 | }
|
7837 |
|
7838 | var DEFAULT_NS_MAP = {
|
7839 | 'xsi': 'http://www.w3.org/2001/XMLSchema-instance'
|
7840 | };
|
7841 |
|
7842 | var XSI_TYPE$1 = 'xsi:type';
|
7843 |
|
7844 | function serializeFormat(element) {
|
7845 | return element.xml && element.xml.serialize;
|
7846 | }
|
7847 |
|
7848 | function serializeAsType(element) {
|
7849 | return serializeFormat(element) === XSI_TYPE$1;
|
7850 | }
|
7851 |
|
7852 | function serializeAsProperty(element) {
|
7853 | return serializeFormat(element) === 'property';
|
7854 | }
|
7855 |
|
7856 | function capitalize(str) {
|
7857 | return str.charAt(0).toUpperCase() + str.slice(1);
|
7858 | }
|
7859 |
|
7860 | function aliasToName(aliasNs, pkg) {
|
7861 |
|
7862 | if (!hasLowerCaseAlias(pkg)) {
|
7863 | return aliasNs.name;
|
7864 | }
|
7865 |
|
7866 | return aliasNs.prefix + ':' + capitalize(aliasNs.localName);
|
7867 | }
|
7868 |
|
7869 | function prefixedToName(nameNs, pkg) {
|
7870 |
|
7871 | var name = nameNs.name,
|
7872 | localName = nameNs.localName;
|
7873 |
|
7874 | var typePrefix = pkg.xml && pkg.xml.typePrefix;
|
7875 |
|
7876 | if (typePrefix && localName.indexOf(typePrefix) === 0) {
|
7877 | return nameNs.prefix + ':' + localName.slice(typePrefix.length);
|
7878 | } else {
|
7879 | return name;
|
7880 | }
|
7881 | }
|
7882 |
|
7883 | function normalizeXsiTypeName(name, model) {
|
7884 |
|
7885 | var nameNs = parseName(name);
|
7886 | var pkg = model.getPackage(nameNs.prefix);
|
7887 |
|
7888 | return prefixedToName(nameNs, pkg);
|
7889 | }
|
7890 |
|
7891 | function error$1(message) {
|
7892 | return new Error(message);
|
7893 | }
|
7894 |
|
7895 | |
7896 |
|
7897 |
|
7898 |
|
7899 |
|
7900 |
|
7901 |
|
7902 | function getModdleDescriptor(element) {
|
7903 | return element.$descriptor;
|
7904 | }
|
7905 |
|
7906 | function defer(fn) {
|
7907 | setTimeout(fn, 0);
|
7908 | }
|
7909 |
|
7910 | |
7911 |
|
7912 |
|
7913 |
|
7914 |
|
7915 |
|
7916 |
|
7917 |
|
7918 |
|
7919 | function Context(options) {
|
7920 |
|
7921 | |
7922 |
|
7923 |
|
7924 |
|
7925 | |
7926 |
|
7927 |
|
7928 |
|
7929 | assign(this, options);
|
7930 |
|
7931 | this.elementsById = {};
|
7932 | this.references = [];
|
7933 | this.warnings = [];
|
7934 |
|
7935 | |
7936 |
|
7937 |
|
7938 |
|
7939 |
|
7940 | this.addReference = function(reference) {
|
7941 | this.references.push(reference);
|
7942 | };
|
7943 |
|
7944 | |
7945 |
|
7946 |
|
7947 |
|
7948 |
|
7949 | this.addElement = function(element) {
|
7950 |
|
7951 | if (!element) {
|
7952 | throw error$1('expected element');
|
7953 | }
|
7954 |
|
7955 | var elementsById = this.elementsById;
|
7956 |
|
7957 | var descriptor = getModdleDescriptor(element);
|
7958 |
|
7959 | var idProperty = descriptor.idProperty,
|
7960 | id;
|
7961 |
|
7962 | if (idProperty) {
|
7963 | id = element.get(idProperty.name);
|
7964 |
|
7965 | if (id) {
|
7966 |
|
7967 | if (!/^([a-z][\w-.]*:)?[a-z_][\w-.]*$/i.test(id)) {
|
7968 | throw new Error('illegal ID <' + id + '>');
|
7969 | }
|
7970 |
|
7971 | if (elementsById[id]) {
|
7972 | throw error$1('duplicate ID <' + id + '>');
|
7973 | }
|
7974 |
|
7975 | elementsById[id] = element;
|
7976 | }
|
7977 | }
|
7978 | };
|
7979 |
|
7980 | |
7981 |
|
7982 |
|
7983 |
|
7984 |
|
7985 |
|
7986 |
|
7987 | this.addWarning = function(warning) {
|
7988 | this.warnings.push(warning);
|
7989 | };
|
7990 | }
|
7991 |
|
7992 | function BaseHandler() {}
|
7993 |
|
7994 | BaseHandler.prototype.handleEnd = function() {};
|
7995 | BaseHandler.prototype.handleText = function() {};
|
7996 | BaseHandler.prototype.handleNode = function() {};
|
7997 |
|
7998 |
|
7999 | |
8000 |
|
8001 |
|
8002 |
|
8003 |
|
8004 |
|
8005 |
|
8006 | function NoopHandler() { }
|
8007 |
|
8008 | NoopHandler.prototype = Object.create(BaseHandler.prototype);
|
8009 |
|
8010 | NoopHandler.prototype.handleNode = function() {
|
8011 | return this;
|
8012 | };
|
8013 |
|
8014 | function BodyHandler() {}
|
8015 |
|
8016 | BodyHandler.prototype = Object.create(BaseHandler.prototype);
|
8017 |
|
8018 | BodyHandler.prototype.handleText = function(text) {
|
8019 | this.body = (this.body || '') + text;
|
8020 | };
|
8021 |
|
8022 | function ReferenceHandler(property, context) {
|
8023 | this.property = property;
|
8024 | this.context = context;
|
8025 | }
|
8026 |
|
8027 | ReferenceHandler.prototype = Object.create(BodyHandler.prototype);
|
8028 |
|
8029 | ReferenceHandler.prototype.handleNode = function(node) {
|
8030 |
|
8031 | if (this.element) {
|
8032 | throw error$1('expected no sub nodes');
|
8033 | } else {
|
8034 | this.element = this.createReference(node);
|
8035 | }
|
8036 |
|
8037 | return this;
|
8038 | };
|
8039 |
|
8040 | ReferenceHandler.prototype.handleEnd = function() {
|
8041 | this.element.id = this.body;
|
8042 | };
|
8043 |
|
8044 | ReferenceHandler.prototype.createReference = function(node) {
|
8045 | return {
|
8046 | property: this.property.ns.name,
|
8047 | id: ''
|
8048 | };
|
8049 | };
|
8050 |
|
8051 | function ValueHandler(propertyDesc, element) {
|
8052 | this.element = element;
|
8053 | this.propertyDesc = propertyDesc;
|
8054 | }
|
8055 |
|
8056 | ValueHandler.prototype = Object.create(BodyHandler.prototype);
|
8057 |
|
8058 | ValueHandler.prototype.handleEnd = function() {
|
8059 |
|
8060 | var value = this.body || '',
|
8061 | element = this.element,
|
8062 | propertyDesc = this.propertyDesc;
|
8063 |
|
8064 | value = coerceType(propertyDesc.type, value);
|
8065 |
|
8066 | if (propertyDesc.isMany) {
|
8067 | element.get(propertyDesc.name).push(value);
|
8068 | } else {
|
8069 | element.set(propertyDesc.name, value);
|
8070 | }
|
8071 | };
|
8072 |
|
8073 |
|
8074 | function BaseElementHandler() {}
|
8075 |
|
8076 | BaseElementHandler.prototype = Object.create(BodyHandler.prototype);
|
8077 |
|
8078 | BaseElementHandler.prototype.handleNode = function(node) {
|
8079 | var parser = this,
|
8080 | element = this.element;
|
8081 |
|
8082 | if (!element) {
|
8083 | element = this.element = this.createElement(node);
|
8084 |
|
8085 | this.context.addElement(element);
|
8086 | } else {
|
8087 | parser = this.handleChild(node);
|
8088 | }
|
8089 |
|
8090 | return parser;
|
8091 | };
|
8092 |
|
8093 | |
8094 |
|
8095 |
|
8096 |
|
8097 | function ElementHandler(model, typeName, context) {
|
8098 | this.model = model;
|
8099 | this.type = model.getType(typeName);
|
8100 | this.context = context;
|
8101 | }
|
8102 |
|
8103 | ElementHandler.prototype = Object.create(BaseElementHandler.prototype);
|
8104 |
|
8105 | ElementHandler.prototype.addReference = function(reference) {
|
8106 | this.context.addReference(reference);
|
8107 | };
|
8108 |
|
8109 | ElementHandler.prototype.handleText = function(text) {
|
8110 |
|
8111 | var element = this.element,
|
8112 | descriptor = getModdleDescriptor(element),
|
8113 | bodyProperty = descriptor.bodyProperty;
|
8114 |
|
8115 | if (!bodyProperty) {
|
8116 | throw error$1('unexpected body text <' + text + '>');
|
8117 | }
|
8118 |
|
8119 | BodyHandler.prototype.handleText.call(this, text);
|
8120 | };
|
8121 |
|
8122 | ElementHandler.prototype.handleEnd = function() {
|
8123 |
|
8124 | var value = this.body,
|
8125 | element = this.element,
|
8126 | descriptor = getModdleDescriptor(element),
|
8127 | bodyProperty = descriptor.bodyProperty;
|
8128 |
|
8129 | if (bodyProperty && value !== undefined) {
|
8130 | value = coerceType(bodyProperty.type, value);
|
8131 | element.set(bodyProperty.name, value);
|
8132 | }
|
8133 | };
|
8134 |
|
8135 | |
8136 |
|
8137 |
|
8138 |
|
8139 |
|
8140 | ElementHandler.prototype.createElement = function(node) {
|
8141 | var attributes = node.attributes,
|
8142 | Type = this.type,
|
8143 | descriptor = getModdleDescriptor(Type),
|
8144 | context = this.context,
|
8145 | instance = new Type({}),
|
8146 | model = this.model,
|
8147 | propNameNs;
|
8148 |
|
8149 | forEach(attributes, function(value, name) {
|
8150 |
|
8151 | var prop = descriptor.propertiesByName[name],
|
8152 | values;
|
8153 |
|
8154 | if (prop && prop.isReference) {
|
8155 |
|
8156 | if (!prop.isMany) {
|
8157 | context.addReference({
|
8158 | element: instance,
|
8159 | property: prop.ns.name,
|
8160 | id: value
|
8161 | });
|
8162 | } else {
|
8163 |
|
8164 | values = value.split(' ');
|
8165 |
|
8166 | forEach(values, function(v) {
|
8167 | context.addReference({
|
8168 | element: instance,
|
8169 | property: prop.ns.name,
|
8170 | id: v
|
8171 | });
|
8172 | });
|
8173 | }
|
8174 |
|
8175 | } else {
|
8176 | if (prop) {
|
8177 | value = coerceType(prop.type, value);
|
8178 | } else
|
8179 | if (name !== 'xmlns') {
|
8180 | propNameNs = parseName(name, descriptor.ns.prefix);
|
8181 |
|
8182 |
|
8183 |
|
8184 | if (model.getPackage(propNameNs.prefix)) {
|
8185 |
|
8186 | context.addWarning({
|
8187 | message: 'unknown attribute <' + name + '>',
|
8188 | element: instance,
|
8189 | property: name,
|
8190 | value: value
|
8191 | });
|
8192 | }
|
8193 | }
|
8194 |
|
8195 | instance.set(name, value);
|
8196 | }
|
8197 | });
|
8198 |
|
8199 | return instance;
|
8200 | };
|
8201 |
|
8202 | ElementHandler.prototype.getPropertyForNode = function(node) {
|
8203 |
|
8204 | var name = node.name;
|
8205 | var nameNs = parseName(name);
|
8206 |
|
8207 | var type = this.type,
|
8208 | model = this.model,
|
8209 | descriptor = getModdleDescriptor(type);
|
8210 |
|
8211 | var propertyName = nameNs.name,
|
8212 | property = descriptor.propertiesByName[propertyName],
|
8213 | elementTypeName,
|
8214 | elementType;
|
8215 |
|
8216 |
|
8217 |
|
8218 | if (property) {
|
8219 |
|
8220 | if (serializeAsType(property)) {
|
8221 | elementTypeName = node.attributes[XSI_TYPE$1];
|
8222 |
|
8223 |
|
8224 |
|
8225 | if (elementTypeName) {
|
8226 |
|
8227 |
|
8228 |
|
8229 | elementTypeName = normalizeXsiTypeName(elementTypeName, model);
|
8230 |
|
8231 | elementType = model.getType(elementTypeName);
|
8232 |
|
8233 | return assign({}, property, {
|
8234 | effectiveType: getModdleDescriptor(elementType).name
|
8235 | });
|
8236 | }
|
8237 | }
|
8238 |
|
8239 |
|
8240 | return property;
|
8241 | }
|
8242 |
|
8243 | var pkg = model.getPackage(nameNs.prefix);
|
8244 |
|
8245 | if (pkg) {
|
8246 | elementTypeName = aliasToName(nameNs, pkg);
|
8247 | elementType = model.getType(elementTypeName);
|
8248 |
|
8249 |
|
8250 | property = find(descriptor.properties, function(p) {
|
8251 | return !p.isVirtual && !p.isReference && !p.isAttribute && elementType.hasType(p.type);
|
8252 | });
|
8253 |
|
8254 | if (property) {
|
8255 | return assign({}, property, {
|
8256 | effectiveType: getModdleDescriptor(elementType).name
|
8257 | });
|
8258 | }
|
8259 | } else {
|
8260 |
|
8261 | property = find(descriptor.properties, function(p) {
|
8262 | return !p.isReference && !p.isAttribute && p.type === 'Element';
|
8263 | });
|
8264 |
|
8265 | if (property) {
|
8266 | return property;
|
8267 | }
|
8268 | }
|
8269 |
|
8270 | throw error$1('unrecognized element <' + nameNs.name + '>');
|
8271 | };
|
8272 |
|
8273 | ElementHandler.prototype.toString = function() {
|
8274 | return 'ElementDescriptor[' + getModdleDescriptor(this.type).name + ']';
|
8275 | };
|
8276 |
|
8277 | ElementHandler.prototype.valueHandler = function(propertyDesc, element) {
|
8278 | return new ValueHandler(propertyDesc, element);
|
8279 | };
|
8280 |
|
8281 | ElementHandler.prototype.referenceHandler = function(propertyDesc) {
|
8282 | return new ReferenceHandler(propertyDesc, this.context);
|
8283 | };
|
8284 |
|
8285 | ElementHandler.prototype.handler = function(type) {
|
8286 | if (type === 'Element') {
|
8287 | return new GenericElementHandler(this.model, type, this.context);
|
8288 | } else {
|
8289 | return new ElementHandler(this.model, type, this.context);
|
8290 | }
|
8291 | };
|
8292 |
|
8293 | |
8294 |
|
8295 |
|
8296 |
|
8297 |
|
8298 | ElementHandler.prototype.handleChild = function(node) {
|
8299 | var propertyDesc, type, element, childHandler;
|
8300 |
|
8301 | propertyDesc = this.getPropertyForNode(node);
|
8302 | element = this.element;
|
8303 |
|
8304 | type = propertyDesc.effectiveType || propertyDesc.type;
|
8305 |
|
8306 | if (isSimple(type)) {
|
8307 | return this.valueHandler(propertyDesc, element);
|
8308 | }
|
8309 |
|
8310 | if (propertyDesc.isReference) {
|
8311 | childHandler = this.referenceHandler(propertyDesc).handleNode(node);
|
8312 | } else {
|
8313 | childHandler = this.handler(type).handleNode(node);
|
8314 | }
|
8315 |
|
8316 | var newElement = childHandler.element;
|
8317 |
|
8318 |
|
8319 |
|
8320 | if (newElement !== undefined) {
|
8321 |
|
8322 | if (propertyDesc.isMany) {
|
8323 | element.get(propertyDesc.name).push(newElement);
|
8324 | } else {
|
8325 | element.set(propertyDesc.name, newElement);
|
8326 | }
|
8327 |
|
8328 | if (propertyDesc.isReference) {
|
8329 | assign(newElement, {
|
8330 | element: element
|
8331 | });
|
8332 |
|
8333 | this.context.addReference(newElement);
|
8334 | } else {
|
8335 |
|
8336 | newElement.$parent = element;
|
8337 | }
|
8338 | }
|
8339 |
|
8340 | return childHandler;
|
8341 | };
|
8342 |
|
8343 | |
8344 |
|
8345 |
|
8346 |
|
8347 |
|
8348 |
|
8349 |
|
8350 |
|
8351 |
|
8352 | function RootElementHandler(model, typeName, context) {
|
8353 | ElementHandler.call(this, model, typeName, context);
|
8354 | }
|
8355 |
|
8356 | RootElementHandler.prototype = Object.create(ElementHandler.prototype);
|
8357 |
|
8358 | RootElementHandler.prototype.createElement = function(node) {
|
8359 |
|
8360 | var name = node.name,
|
8361 | nameNs = parseName(name),
|
8362 | model = this.model,
|
8363 | type = this.type,
|
8364 | pkg = model.getPackage(nameNs.prefix),
|
8365 | typeName = pkg && aliasToName(nameNs, pkg) || name;
|
8366 |
|
8367 |
|
8368 |
|
8369 |
|
8370 |
|
8371 | if (!type.hasType(typeName)) {
|
8372 | throw error$1('unexpected element <' + node.originalName + '>');
|
8373 | }
|
8374 |
|
8375 | return ElementHandler.prototype.createElement.call(this, node);
|
8376 | };
|
8377 |
|
8378 |
|
8379 | function GenericElementHandler(model, typeName, context) {
|
8380 | this.model = model;
|
8381 | this.context = context;
|
8382 | }
|
8383 |
|
8384 | GenericElementHandler.prototype = Object.create(BaseElementHandler.prototype);
|
8385 |
|
8386 | GenericElementHandler.prototype.createElement = function(node) {
|
8387 |
|
8388 | var name = node.name,
|
8389 | ns = parseName(name),
|
8390 | prefix = ns.prefix,
|
8391 | uri = node.ns[prefix + '$uri'],
|
8392 | attributes = node.attributes;
|
8393 |
|
8394 | return this.model.createAny(name, uri, attributes);
|
8395 | };
|
8396 |
|
8397 | GenericElementHandler.prototype.handleChild = function(node) {
|
8398 |
|
8399 | var handler = new GenericElementHandler(this.model, 'Element', this.context).handleNode(node),
|
8400 | element = this.element;
|
8401 |
|
8402 | var newElement = handler.element,
|
8403 | children;
|
8404 |
|
8405 | if (newElement !== undefined) {
|
8406 | children = element.$children = element.$children || [];
|
8407 | children.push(newElement);
|
8408 |
|
8409 |
|
8410 | newElement.$parent = element;
|
8411 | }
|
8412 |
|
8413 | return handler;
|
8414 | };
|
8415 |
|
8416 | GenericElementHandler.prototype.handleEnd = function() {
|
8417 | if (this.body) {
|
8418 | this.element.$body = this.body;
|
8419 | }
|
8420 | };
|
8421 |
|
8422 | |
8423 |
|
8424 |
|
8425 |
|
8426 |
|
8427 |
|
8428 |
|
8429 | function Reader(options) {
|
8430 |
|
8431 | if (options instanceof Moddle) {
|
8432 | options = {
|
8433 | model: options
|
8434 | };
|
8435 | }
|
8436 |
|
8437 | assign(this, { lax: false }, options);
|
8438 | }
|
8439 |
|
8440 |
|
8441 | |
8442 |
|
8443 |
|
8444 |
|
8445 |
|
8446 |
|
8447 |
|
8448 | Reader.prototype.fromXML = function(xml, options, done) {
|
8449 |
|
8450 | var rootHandler = options.rootHandler;
|
8451 |
|
8452 | if (options instanceof ElementHandler) {
|
8453 |
|
8454 | rootHandler = options;
|
8455 | options = {};
|
8456 | } else {
|
8457 | if (typeof options === 'string') {
|
8458 |
|
8459 | rootHandler = this.handler(options);
|
8460 | options = {};
|
8461 | } else if (typeof rootHandler === 'string') {
|
8462 |
|
8463 | rootHandler = this.handler(rootHandler);
|
8464 | }
|
8465 | }
|
8466 |
|
8467 | var model = this.model,
|
8468 | lax = this.lax;
|
8469 |
|
8470 | var context = new Context(assign({}, options, { rootHandler: rootHandler })),
|
8471 | parser = new Parser({ proxy: true }),
|
8472 | stack = createStack();
|
8473 |
|
8474 | rootHandler.context = context;
|
8475 |
|
8476 |
|
8477 | stack.push(rootHandler);
|
8478 |
|
8479 |
|
8480 | |
8481 |
|
8482 |
|
8483 |
|
8484 |
|
8485 |
|
8486 |
|
8487 |
|
8488 |
|
8489 | function handleError(err, getContext, lax) {
|
8490 |
|
8491 | var ctx = getContext();
|
8492 |
|
8493 | var line = ctx.line,
|
8494 | column = ctx.column,
|
8495 | data = ctx.data;
|
8496 |
|
8497 |
|
8498 |
|
8499 |
|
8500 | if (data.charAt(0) === '<' && data.indexOf(' ') !== -1) {
|
8501 | data = data.slice(0, data.indexOf(' ')) + '>';
|
8502 | }
|
8503 |
|
8504 | var message =
|
8505 | 'unparsable content ' + (data ? data + ' ' : '') + 'detected\n\t' +
|
8506 | 'line: ' + line + '\n\t' +
|
8507 | 'column: ' + column + '\n\t' +
|
8508 | 'nested error: ' + err.message;
|
8509 |
|
8510 | if (lax) {
|
8511 | context.addWarning({
|
8512 | message: message,
|
8513 | error: err
|
8514 | });
|
8515 |
|
8516 | return true;
|
8517 | } else {
|
8518 | throw error$1(message);
|
8519 | }
|
8520 | }
|
8521 |
|
8522 | function handleWarning(err, getContext) {
|
8523 |
|
8524 | return handleError(err, getContext, true);
|
8525 | }
|
8526 |
|
8527 | |
8528 |
|
8529 |
|
8530 | function resolveReferences() {
|
8531 |
|
8532 | var elementsById = context.elementsById;
|
8533 | var references = context.references;
|
8534 |
|
8535 | var i, r;
|
8536 |
|
8537 | for (i = 0; (r = references[i]); i++) {
|
8538 | var element = r.element;
|
8539 | var reference = elementsById[r.id];
|
8540 | var property = getModdleDescriptor(element).propertiesByName[r.property];
|
8541 |
|
8542 | if (!reference) {
|
8543 | context.addWarning({
|
8544 | message: 'unresolved reference <' + r.id + '>',
|
8545 | element: r.element,
|
8546 | property: r.property,
|
8547 | value: r.id
|
8548 | });
|
8549 | }
|
8550 |
|
8551 | if (property.isMany) {
|
8552 | var collection = element.get(property.name),
|
8553 | idx = collection.indexOf(r);
|
8554 |
|
8555 |
|
8556 |
|
8557 | if (idx === -1) {
|
8558 | idx = collection.length;
|
8559 | }
|
8560 |
|
8561 | if (!reference) {
|
8562 |
|
8563 | collection.splice(idx, 1);
|
8564 | } else {
|
8565 |
|
8566 | collection[idx] = reference;
|
8567 | }
|
8568 | } else {
|
8569 | element.set(property.name, reference);
|
8570 | }
|
8571 | }
|
8572 | }
|
8573 |
|
8574 | function handleClose() {
|
8575 | stack.pop().handleEnd();
|
8576 | }
|
8577 |
|
8578 | var PREAMBLE_START_PATTERN = /^<\?xml /i;
|
8579 |
|
8580 | var ENCODING_PATTERN = / encoding="([^"]+)"/i;
|
8581 |
|
8582 | var UTF_8_PATTERN = /^utf-8$/i;
|
8583 |
|
8584 | function handleQuestion(question) {
|
8585 |
|
8586 | if (!PREAMBLE_START_PATTERN.test(question)) {
|
8587 | return;
|
8588 | }
|
8589 |
|
8590 | var match = ENCODING_PATTERN.exec(question);
|
8591 | var encoding = match && match[1];
|
8592 |
|
8593 | if (!encoding || UTF_8_PATTERN.test(encoding)) {
|
8594 | return;
|
8595 | }
|
8596 |
|
8597 | context.addWarning({
|
8598 | message:
|
8599 | 'unsupported document encoding <' + encoding + '>, ' +
|
8600 | 'falling back to UTF-8'
|
8601 | });
|
8602 | }
|
8603 |
|
8604 | function handleOpen(node, getContext) {
|
8605 | var handler = stack.peek();
|
8606 |
|
8607 | try {
|
8608 | stack.push(handler.handleNode(node));
|
8609 | } catch (err) {
|
8610 |
|
8611 | if (handleError(err, getContext, lax)) {
|
8612 | stack.push(new NoopHandler());
|
8613 | }
|
8614 | }
|
8615 | }
|
8616 |
|
8617 | function handleCData(text, getContext) {
|
8618 |
|
8619 | try {
|
8620 | stack.peek().handleText(text);
|
8621 | } catch (err) {
|
8622 | handleWarning(err, getContext);
|
8623 | }
|
8624 | }
|
8625 |
|
8626 | function handleText(text, getContext) {
|
8627 |
|
8628 |
|
8629 | text = text.trim();
|
8630 |
|
8631 | if (!text) {
|
8632 | return;
|
8633 | }
|
8634 |
|
8635 | handleCData(text, getContext);
|
8636 | }
|
8637 |
|
8638 | var uriMap = model.getPackages().reduce(function(uriMap, p) {
|
8639 | uriMap[p.uri] = p.prefix;
|
8640 |
|
8641 | return uriMap;
|
8642 | }, {});
|
8643 |
|
8644 | parser
|
8645 | .ns(uriMap)
|
8646 | .on('openTag', function(obj, decodeStr, selfClosing, getContext) {
|
8647 |
|
8648 |
|
8649 | var attrs = obj.attrs || {};
|
8650 |
|
8651 | var decodedAttrs = Object.keys(attrs).reduce(function(d, key) {
|
8652 | var value = decodeStr(attrs[key]);
|
8653 |
|
8654 | d[key] = value;
|
8655 |
|
8656 | return d;
|
8657 | }, {});
|
8658 |
|
8659 | var node = {
|
8660 | name: obj.name,
|
8661 | originalName: obj.originalName,
|
8662 | attributes: decodedAttrs,
|
8663 | ns: obj.ns
|
8664 | };
|
8665 |
|
8666 | handleOpen(node, getContext);
|
8667 | })
|
8668 | .on('question', handleQuestion)
|
8669 | .on('closeTag', handleClose)
|
8670 | .on('cdata', handleCData)
|
8671 | .on('text', function(text, decodeEntities, getContext) {
|
8672 | handleText(decodeEntities(text), getContext);
|
8673 | })
|
8674 | .on('error', handleError)
|
8675 | .on('warn', handleWarning);
|
8676 |
|
8677 |
|
8678 |
|
8679 |
|
8680 |
|
8681 | defer(function() {
|
8682 | var err;
|
8683 |
|
8684 | try {
|
8685 | parser.parse(xml);
|
8686 |
|
8687 | resolveReferences();
|
8688 | } catch (e) {
|
8689 | err = e;
|
8690 | }
|
8691 |
|
8692 | var element = rootHandler.element;
|
8693 |
|
8694 |
|
8695 |
|
8696 | if (!err && !element) {
|
8697 | err = error$1('failed to parse document as <' + rootHandler.type.$descriptor.name + '>');
|
8698 | }
|
8699 |
|
8700 | done(err, err ? undefined : element, context);
|
8701 | });
|
8702 | };
|
8703 |
|
8704 | Reader.prototype.handler = function(name) {
|
8705 | return new RootElementHandler(this.model, name);
|
8706 | };
|
8707 |
|
8708 |
|
8709 |
|
8710 |
|
8711 | function createStack() {
|
8712 | var stack = [];
|
8713 |
|
8714 | Object.defineProperty(stack, 'peek', {
|
8715 | value: function() {
|
8716 | return this[this.length - 1];
|
8717 | }
|
8718 | });
|
8719 |
|
8720 | return stack;
|
8721 | }
|
8722 |
|
8723 | var XML_PREAMBLE = '<?xml version="1.0" encoding="UTF-8"?>\n';
|
8724 |
|
8725 | var ESCAPE_ATTR_CHARS = /<|>|'|"|&|\n\r|\n/g;
|
8726 | var ESCAPE_CHARS = /<|>|&/g;
|
8727 |
|
8728 |
|
8729 | function Namespaces(parent) {
|
8730 |
|
8731 | var prefixMap = {};
|
8732 | var uriMap = {};
|
8733 | var used = {};
|
8734 |
|
8735 | var wellknown = [];
|
8736 | var custom = [];
|
8737 |
|
8738 |
|
8739 |
|
8740 | this.byUri = function(uri) {
|
8741 | return uriMap[uri] || (
|
8742 | parent && parent.byUri(uri)
|
8743 | );
|
8744 | };
|
8745 |
|
8746 | this.add = function(ns, isWellknown) {
|
8747 |
|
8748 | uriMap[ns.uri] = ns;
|
8749 |
|
8750 | if (isWellknown) {
|
8751 | wellknown.push(ns);
|
8752 | } else {
|
8753 | custom.push(ns);
|
8754 | }
|
8755 |
|
8756 | this.mapPrefix(ns.prefix, ns.uri);
|
8757 | };
|
8758 |
|
8759 | this.uriByPrefix = function(prefix) {
|
8760 | return prefixMap[prefix || 'xmlns'];
|
8761 | };
|
8762 |
|
8763 | this.mapPrefix = function(prefix, uri) {
|
8764 | prefixMap[prefix || 'xmlns'] = uri;
|
8765 | };
|
8766 |
|
8767 | this.logUsed = function(ns) {
|
8768 | var uri = ns.uri;
|
8769 |
|
8770 | used[uri] = this.byUri(uri);
|
8771 | };
|
8772 |
|
8773 | this.getUsed = function(ns) {
|
8774 |
|
8775 | function isUsed(ns) {
|
8776 | return used[ns.uri];
|
8777 | }
|
8778 |
|
8779 | var allNs = [].concat(wellknown, custom);
|
8780 |
|
8781 | return allNs.filter(isUsed);
|
8782 | };
|
8783 |
|
8784 | }
|
8785 |
|
8786 | function lower(string) {
|
8787 | return string.charAt(0).toLowerCase() + string.slice(1);
|
8788 | }
|
8789 |
|
8790 | function nameToAlias(name, pkg) {
|
8791 | if (hasLowerCaseAlias(pkg)) {
|
8792 | return lower(name);
|
8793 | } else {
|
8794 | return name;
|
8795 | }
|
8796 | }
|
8797 |
|
8798 | function inherits(ctor, superCtor) {
|
8799 | ctor.super_ = superCtor;
|
8800 | ctor.prototype = Object.create(superCtor.prototype, {
|
8801 | constructor: {
|
8802 | value: ctor,
|
8803 | enumerable: false,
|
8804 | writable: true,
|
8805 | configurable: true
|
8806 | }
|
8807 | });
|
8808 | }
|
8809 |
|
8810 | function nsName(ns) {
|
8811 | if (isString(ns)) {
|
8812 | return ns;
|
8813 | } else {
|
8814 | return (ns.prefix ? ns.prefix + ':' : '') + ns.localName;
|
8815 | }
|
8816 | }
|
8817 |
|
8818 | function getNsAttrs(namespaces) {
|
8819 |
|
8820 | return map(namespaces.getUsed(), function(ns) {
|
8821 | var name = 'xmlns' + (ns.prefix ? ':' + ns.prefix : '');
|
8822 | return { name: name, value: ns.uri };
|
8823 | });
|
8824 |
|
8825 | }
|
8826 |
|
8827 | function getElementNs(ns, descriptor) {
|
8828 | if (descriptor.isGeneric) {
|
8829 | return assign({ localName: descriptor.ns.localName }, ns);
|
8830 | } else {
|
8831 | return assign({ localName: nameToAlias(descriptor.ns.localName, descriptor.$pkg) }, ns);
|
8832 | }
|
8833 | }
|
8834 |
|
8835 | function getPropertyNs(ns, descriptor) {
|
8836 | return assign({ localName: descriptor.ns.localName }, ns);
|
8837 | }
|
8838 |
|
8839 | function getSerializableProperties(element) {
|
8840 | var descriptor = element.$descriptor;
|
8841 |
|
8842 | return filter(descriptor.properties, function(p) {
|
8843 | var name = p.name;
|
8844 |
|
8845 | if (p.isVirtual) {
|
8846 | return false;
|
8847 | }
|
8848 |
|
8849 |
|
8850 | if (!element.hasOwnProperty(name)) {
|
8851 | return false;
|
8852 | }
|
8853 |
|
8854 | var value = element[name];
|
8855 |
|
8856 |
|
8857 | if (value === p.default) {
|
8858 | return false;
|
8859 | }
|
8860 |
|
8861 |
|
8862 | if (value === null) {
|
8863 | return false;
|
8864 | }
|
8865 |
|
8866 | return p.isMany ? value.length : true;
|
8867 | });
|
8868 | }
|
8869 |
|
8870 | var ESCAPE_ATTR_MAP = {
|
8871 | '\n': '#10',
|
8872 | '\n\r': '#10',
|
8873 | '"': '#34',
|
8874 | '\'': '#39',
|
8875 | '<': '#60',
|
8876 | '>': '#62',
|
8877 | '&': '#38'
|
8878 | };
|
8879 |
|
8880 | var ESCAPE_MAP = {
|
8881 | '<': 'lt',
|
8882 | '>': 'gt',
|
8883 | '&': 'amp'
|
8884 | };
|
8885 |
|
8886 | function escape$1(str, charPattern, replaceMap) {
|
8887 |
|
8888 |
|
8889 | str = isString(str) ? str : '' + str;
|
8890 |
|
8891 | return str.replace(charPattern, function(s) {
|
8892 | return '&' + replaceMap[s] + ';';
|
8893 | });
|
8894 | }
|
8895 |
|
8896 | |
8897 |
|
8898 |
|
8899 |
|
8900 |
|
8901 |
|
8902 | function escapeAttr(str) {
|
8903 | return escape$1(str, ESCAPE_ATTR_CHARS, ESCAPE_ATTR_MAP);
|
8904 | }
|
8905 |
|
8906 | function escapeBody(str) {
|
8907 | return escape$1(str, ESCAPE_CHARS, ESCAPE_MAP);
|
8908 | }
|
8909 |
|
8910 | function filterAttributes(props) {
|
8911 | return filter(props, function(p) { return p.isAttr; });
|
8912 | }
|
8913 |
|
8914 | function filterContained(props) {
|
8915 | return filter(props, function(p) { return !p.isAttr; });
|
8916 | }
|
8917 |
|
8918 |
|
8919 | function ReferenceSerializer(tagName) {
|
8920 | this.tagName = tagName;
|
8921 | }
|
8922 |
|
8923 | ReferenceSerializer.prototype.build = function(element) {
|
8924 | this.element = element;
|
8925 | return this;
|
8926 | };
|
8927 |
|
8928 | ReferenceSerializer.prototype.serializeTo = function(writer) {
|
8929 | writer
|
8930 | .appendIndent()
|
8931 | .append('<' + this.tagName + '>' + this.element.id + '</' + this.tagName + '>')
|
8932 | .appendNewLine();
|
8933 | };
|
8934 |
|
8935 | function BodySerializer() {}
|
8936 |
|
8937 | BodySerializer.prototype.serializeValue =
|
8938 | BodySerializer.prototype.serializeTo = function(writer) {
|
8939 | writer.append(
|
8940 | this.escape
|
8941 | ? escapeBody(this.value)
|
8942 | : this.value
|
8943 | );
|
8944 | };
|
8945 |
|
8946 | BodySerializer.prototype.build = function(prop, value) {
|
8947 | this.value = value;
|
8948 |
|
8949 | if (prop.type === 'String' && value.search(ESCAPE_CHARS) !== -1) {
|
8950 | this.escape = true;
|
8951 | }
|
8952 |
|
8953 | return this;
|
8954 | };
|
8955 |
|
8956 | function ValueSerializer(tagName) {
|
8957 | this.tagName = tagName;
|
8958 | }
|
8959 |
|
8960 | inherits(ValueSerializer, BodySerializer);
|
8961 |
|
8962 | ValueSerializer.prototype.serializeTo = function(writer) {
|
8963 |
|
8964 | writer
|
8965 | .appendIndent()
|
8966 | .append('<' + this.tagName + '>');
|
8967 |
|
8968 | this.serializeValue(writer);
|
8969 |
|
8970 | writer
|
8971 | .append('</' + this.tagName + '>')
|
8972 | .appendNewLine();
|
8973 | };
|
8974 |
|
8975 | function ElementSerializer(parent, propertyDescriptor) {
|
8976 | this.body = [];
|
8977 | this.attrs = [];
|
8978 |
|
8979 | this.parent = parent;
|
8980 | this.propertyDescriptor = propertyDescriptor;
|
8981 | }
|
8982 |
|
8983 | ElementSerializer.prototype.build = function(element) {
|
8984 | this.element = element;
|
8985 |
|
8986 | var elementDescriptor = element.$descriptor,
|
8987 | propertyDescriptor = this.propertyDescriptor;
|
8988 |
|
8989 | var otherAttrs,
|
8990 | properties;
|
8991 |
|
8992 | var isGeneric = elementDescriptor.isGeneric;
|
8993 |
|
8994 | if (isGeneric) {
|
8995 | otherAttrs = this.parseGeneric(element);
|
8996 | } else {
|
8997 | otherAttrs = this.parseNsAttributes(element);
|
8998 | }
|
8999 |
|
9000 | if (propertyDescriptor) {
|
9001 | this.ns = this.nsPropertyTagName(propertyDescriptor);
|
9002 | } else {
|
9003 | this.ns = this.nsTagName(elementDescriptor);
|
9004 | }
|
9005 |
|
9006 |
|
9007 | this.tagName = this.addTagName(this.ns);
|
9008 |
|
9009 | if (!isGeneric) {
|
9010 | properties = getSerializableProperties(element);
|
9011 |
|
9012 | this.parseAttributes(filterAttributes(properties));
|
9013 | this.parseContainments(filterContained(properties));
|
9014 | }
|
9015 |
|
9016 | this.parseGenericAttributes(element, otherAttrs);
|
9017 |
|
9018 | return this;
|
9019 | };
|
9020 |
|
9021 | ElementSerializer.prototype.nsTagName = function(descriptor) {
|
9022 | var effectiveNs = this.logNamespaceUsed(descriptor.ns);
|
9023 | return getElementNs(effectiveNs, descriptor);
|
9024 | };
|
9025 |
|
9026 | ElementSerializer.prototype.nsPropertyTagName = function(descriptor) {
|
9027 | var effectiveNs = this.logNamespaceUsed(descriptor.ns);
|
9028 | return getPropertyNs(effectiveNs, descriptor);
|
9029 | };
|
9030 |
|
9031 | ElementSerializer.prototype.isLocalNs = function(ns) {
|
9032 | return ns.uri === this.ns.uri;
|
9033 | };
|
9034 |
|
9035 | |
9036 |
|
9037 |
|
9038 |
|
9039 |
|
9040 |
|
9041 |
|
9042 |
|
9043 | ElementSerializer.prototype.nsAttributeName = function(element) {
|
9044 |
|
9045 | var ns;
|
9046 |
|
9047 | if (isString(element)) {
|
9048 | ns = parseName(element);
|
9049 | } else {
|
9050 | ns = element.ns;
|
9051 | }
|
9052 |
|
9053 |
|
9054 | if (element.inherited) {
|
9055 | return { localName: ns.localName };
|
9056 | }
|
9057 |
|
9058 |
|
9059 | var effectiveNs = this.logNamespaceUsed(ns);
|
9060 |
|
9061 |
|
9062 | this.getNamespaces().logUsed(effectiveNs);
|
9063 |
|
9064 |
|
9065 | if (this.isLocalNs(effectiveNs)) {
|
9066 | return { localName: ns.localName };
|
9067 | } else {
|
9068 | return assign({ localName: ns.localName }, effectiveNs);
|
9069 | }
|
9070 | };
|
9071 |
|
9072 | ElementSerializer.prototype.parseGeneric = function(element) {
|
9073 |
|
9074 | var self = this,
|
9075 | body = this.body;
|
9076 |
|
9077 | var attributes = [];
|
9078 |
|
9079 | forEach(element, function(val, key) {
|
9080 |
|
9081 | var nonNsAttr;
|
9082 |
|
9083 | if (key === '$body') {
|
9084 | body.push(new BodySerializer().build({ type: 'String' }, val));
|
9085 | } else
|
9086 | if (key === '$children') {
|
9087 | forEach(val, function(child) {
|
9088 | body.push(new ElementSerializer(self).build(child));
|
9089 | });
|
9090 | } else
|
9091 | if (key.indexOf('$') !== 0) {
|
9092 | nonNsAttr = self.parseNsAttribute(element, key, val);
|
9093 |
|
9094 | if (nonNsAttr) {
|
9095 | attributes.push({ name: key, value: val });
|
9096 | }
|
9097 | }
|
9098 | });
|
9099 |
|
9100 | return attributes;
|
9101 | };
|
9102 |
|
9103 | ElementSerializer.prototype.parseNsAttribute = function(element, name, value) {
|
9104 | var model = element.$model;
|
9105 |
|
9106 | var nameNs = parseName(name);
|
9107 |
|
9108 | var ns;
|
9109 |
|
9110 |
|
9111 | if (nameNs.prefix === 'xmlns') {
|
9112 | ns = { prefix: nameNs.localName, uri: value };
|
9113 | }
|
9114 |
|
9115 |
|
9116 | if (!nameNs.prefix && nameNs.localName === 'xmlns') {
|
9117 | ns = { uri: value };
|
9118 | }
|
9119 |
|
9120 | if (!ns) {
|
9121 | return {
|
9122 | name: name,
|
9123 | value: value
|
9124 | };
|
9125 | }
|
9126 |
|
9127 | if (model && model.getPackage(value)) {
|
9128 |
|
9129 | this.logNamespace(ns, true, true);
|
9130 | } else {
|
9131 |
|
9132 | var actualNs = this.logNamespaceUsed(ns, true);
|
9133 |
|
9134 | this.getNamespaces().logUsed(actualNs);
|
9135 | }
|
9136 | };
|
9137 |
|
9138 |
|
9139 | |
9140 |
|
9141 |
|
9142 |
|
9143 |
|
9144 |
|
9145 | ElementSerializer.prototype.parseNsAttributes = function(element, attrs) {
|
9146 | var self = this;
|
9147 |
|
9148 | var genericAttrs = element.$attrs;
|
9149 |
|
9150 | var attributes = [];
|
9151 |
|
9152 |
|
9153 |
|
9154 |
|
9155 | forEach(genericAttrs, function(value, name) {
|
9156 |
|
9157 | var nonNsAttr = self.parseNsAttribute(element, name, value);
|
9158 |
|
9159 | if (nonNsAttr) {
|
9160 | attributes.push(nonNsAttr);
|
9161 | }
|
9162 | });
|
9163 |
|
9164 | return attributes;
|
9165 | };
|
9166 |
|
9167 | ElementSerializer.prototype.parseGenericAttributes = function(element, attributes) {
|
9168 |
|
9169 | var self = this;
|
9170 |
|
9171 | forEach(attributes, function(attr) {
|
9172 |
|
9173 |
|
9174 |
|
9175 | if (attr.name === XSI_TYPE$1) {
|
9176 | return;
|
9177 | }
|
9178 |
|
9179 | try {
|
9180 | self.addAttribute(self.nsAttributeName(attr.name), attr.value);
|
9181 | } catch (e) {
|
9182 | console.warn(
|
9183 | 'missing namespace information for ',
|
9184 | attr.name, '=', attr.value, 'on', element,
|
9185 | e);
|
9186 | }
|
9187 | });
|
9188 | };
|
9189 |
|
9190 | ElementSerializer.prototype.parseContainments = function(properties) {
|
9191 |
|
9192 | var self = this,
|
9193 | body = this.body,
|
9194 | element = this.element;
|
9195 |
|
9196 | forEach(properties, function(p) {
|
9197 | var value = element.get(p.name),
|
9198 | isReference = p.isReference,
|
9199 | isMany = p.isMany;
|
9200 |
|
9201 | if (!isMany) {
|
9202 | value = [ value ];
|
9203 | }
|
9204 |
|
9205 | if (p.isBody) {
|
9206 | body.push(new BodySerializer().build(p, value[0]));
|
9207 | } else
|
9208 | if (isSimple(p.type)) {
|
9209 | forEach(value, function(v) {
|
9210 | body.push(new ValueSerializer(self.addTagName(self.nsPropertyTagName(p))).build(p, v));
|
9211 | });
|
9212 | } else
|
9213 | if (isReference) {
|
9214 | forEach(value, function(v) {
|
9215 | body.push(new ReferenceSerializer(self.addTagName(self.nsPropertyTagName(p))).build(v));
|
9216 | });
|
9217 | } else {
|
9218 |
|
9219 |
|
9220 | var asType = serializeAsType(p),
|
9221 | asProperty = serializeAsProperty(p);
|
9222 |
|
9223 | forEach(value, function(v) {
|
9224 | var serializer;
|
9225 |
|
9226 | if (asType) {
|
9227 | serializer = new TypeSerializer(self, p);
|
9228 | } else
|
9229 | if (asProperty) {
|
9230 | serializer = new ElementSerializer(self, p);
|
9231 | } else {
|
9232 | serializer = new ElementSerializer(self);
|
9233 | }
|
9234 |
|
9235 | body.push(serializer.build(v));
|
9236 | });
|
9237 | }
|
9238 | });
|
9239 | };
|
9240 |
|
9241 | ElementSerializer.prototype.getNamespaces = function(local) {
|
9242 |
|
9243 | var namespaces = this.namespaces,
|
9244 | parent = this.parent,
|
9245 | parentNamespaces;
|
9246 |
|
9247 | if (!namespaces) {
|
9248 | parentNamespaces = parent && parent.getNamespaces();
|
9249 |
|
9250 | if (local || !parentNamespaces) {
|
9251 | this.namespaces = namespaces = new Namespaces(parentNamespaces);
|
9252 | } else {
|
9253 | namespaces = parentNamespaces;
|
9254 | }
|
9255 | }
|
9256 |
|
9257 | return namespaces;
|
9258 | };
|
9259 |
|
9260 | ElementSerializer.prototype.logNamespace = function(ns, wellknown, local) {
|
9261 | var namespaces = this.getNamespaces(local);
|
9262 |
|
9263 | var nsUri = ns.uri,
|
9264 | nsPrefix = ns.prefix;
|
9265 |
|
9266 | var existing = namespaces.byUri(nsUri);
|
9267 |
|
9268 | if (!existing) {
|
9269 | namespaces.add(ns, wellknown);
|
9270 | }
|
9271 |
|
9272 | namespaces.mapPrefix(nsPrefix, nsUri);
|
9273 |
|
9274 | return ns;
|
9275 | };
|
9276 |
|
9277 | ElementSerializer.prototype.logNamespaceUsed = function(ns, local) {
|
9278 | var element = this.element,
|
9279 | model = element.$model,
|
9280 | namespaces = this.getNamespaces(local);
|
9281 |
|
9282 |
|
9283 |
|
9284 |
|
9285 |
|
9286 |
|
9287 |
|
9288 | var prefix = ns.prefix,
|
9289 | uri = ns.uri,
|
9290 | newPrefix, idx,
|
9291 | wellknownUri;
|
9292 |
|
9293 |
|
9294 | if (!prefix && !uri) {
|
9295 | return { localName: ns.localName };
|
9296 | }
|
9297 |
|
9298 | wellknownUri = DEFAULT_NS_MAP[prefix] || model && (model.getPackage(prefix) || {}).uri;
|
9299 |
|
9300 | uri = uri || wellknownUri || namespaces.uriByPrefix(prefix);
|
9301 |
|
9302 | if (!uri) {
|
9303 | throw new Error('no namespace uri given for prefix <' + prefix + '>');
|
9304 | }
|
9305 |
|
9306 | ns = namespaces.byUri(uri);
|
9307 |
|
9308 | if (!ns) {
|
9309 | newPrefix = prefix;
|
9310 | idx = 1;
|
9311 |
|
9312 |
|
9313 | while (namespaces.uriByPrefix(newPrefix)) {
|
9314 | newPrefix = prefix + '_' + idx++;
|
9315 | }
|
9316 |
|
9317 | ns = this.logNamespace({ prefix: newPrefix, uri: uri }, wellknownUri === uri);
|
9318 | }
|
9319 |
|
9320 | if (prefix) {
|
9321 | namespaces.mapPrefix(prefix, uri);
|
9322 | }
|
9323 |
|
9324 | return ns;
|
9325 | };
|
9326 |
|
9327 | ElementSerializer.prototype.parseAttributes = function(properties) {
|
9328 | var self = this,
|
9329 | element = this.element;
|
9330 |
|
9331 | forEach(properties, function(p) {
|
9332 |
|
9333 | var value = element.get(p.name);
|
9334 |
|
9335 | if (p.isReference) {
|
9336 |
|
9337 | if (!p.isMany) {
|
9338 | value = value.id;
|
9339 | }
|
9340 | else {
|
9341 | var values = [];
|
9342 | forEach(value, function(v) {
|
9343 | values.push(v.id);
|
9344 | });
|
9345 |
|
9346 | value = values.join(' ');
|
9347 | }
|
9348 |
|
9349 | }
|
9350 |
|
9351 | self.addAttribute(self.nsAttributeName(p), value);
|
9352 | });
|
9353 | };
|
9354 |
|
9355 | ElementSerializer.prototype.addTagName = function(nsTagName) {
|
9356 | var actualNs = this.logNamespaceUsed(nsTagName);
|
9357 |
|
9358 | this.getNamespaces().logUsed(actualNs);
|
9359 |
|
9360 | return nsName(nsTagName);
|
9361 | };
|
9362 |
|
9363 | ElementSerializer.prototype.addAttribute = function(name, value) {
|
9364 | var attrs = this.attrs;
|
9365 |
|
9366 | if (isString(value)) {
|
9367 | value = escapeAttr(value);
|
9368 | }
|
9369 |
|
9370 | attrs.push({ name: name, value: value });
|
9371 | };
|
9372 |
|
9373 | ElementSerializer.prototype.serializeAttributes = function(writer) {
|
9374 | var attrs = this.attrs,
|
9375 | namespaces = this.namespaces;
|
9376 |
|
9377 | if (namespaces) {
|
9378 | attrs = getNsAttrs(namespaces).concat(attrs);
|
9379 | }
|
9380 |
|
9381 | forEach(attrs, function(a) {
|
9382 | writer
|
9383 | .append(' ')
|
9384 | .append(nsName(a.name)).append('="').append(a.value).append('"');
|
9385 | });
|
9386 | };
|
9387 |
|
9388 | ElementSerializer.prototype.serializeTo = function(writer) {
|
9389 | var firstBody = this.body[0],
|
9390 | indent = firstBody && firstBody.constructor !== BodySerializer;
|
9391 |
|
9392 | writer
|
9393 | .appendIndent()
|
9394 | .append('<' + this.tagName);
|
9395 |
|
9396 | this.serializeAttributes(writer);
|
9397 |
|
9398 | writer.append(firstBody ? '>' : ' />');
|
9399 |
|
9400 | if (firstBody) {
|
9401 |
|
9402 | if (indent) {
|
9403 | writer
|
9404 | .appendNewLine()
|
9405 | .indent();
|
9406 | }
|
9407 |
|
9408 | forEach(this.body, function(b) {
|
9409 | b.serializeTo(writer);
|
9410 | });
|
9411 |
|
9412 | if (indent) {
|
9413 | writer
|
9414 | .unindent()
|
9415 | .appendIndent();
|
9416 | }
|
9417 |
|
9418 | writer.append('</' + this.tagName + '>');
|
9419 | }
|
9420 |
|
9421 | writer.appendNewLine();
|
9422 | };
|
9423 |
|
9424 | |
9425 |
|
9426 |
|
9427 | function TypeSerializer(parent, propertyDescriptor) {
|
9428 | ElementSerializer.call(this, parent, propertyDescriptor);
|
9429 | }
|
9430 |
|
9431 | inherits(TypeSerializer, ElementSerializer);
|
9432 |
|
9433 | TypeSerializer.prototype.parseNsAttributes = function(element) {
|
9434 |
|
9435 |
|
9436 | var attributes = ElementSerializer.prototype.parseNsAttributes.call(this, element);
|
9437 |
|
9438 | var descriptor = element.$descriptor;
|
9439 |
|
9440 |
|
9441 | if (descriptor.name === this.propertyDescriptor.type) {
|
9442 | return attributes;
|
9443 | }
|
9444 |
|
9445 | var typeNs = this.typeNs = this.nsTagName(descriptor);
|
9446 | this.getNamespaces().logUsed(this.typeNs);
|
9447 |
|
9448 |
|
9449 |
|
9450 |
|
9451 | var pkg = element.$model.getPackage(typeNs.uri),
|
9452 | typePrefix = (pkg.xml && pkg.xml.typePrefix) || '';
|
9453 |
|
9454 | this.addAttribute(
|
9455 | this.nsAttributeName(XSI_TYPE$1),
|
9456 | (typeNs.prefix ? typeNs.prefix + ':' : '') + typePrefix + descriptor.ns.localName
|
9457 | );
|
9458 |
|
9459 | return attributes;
|
9460 | };
|
9461 |
|
9462 | TypeSerializer.prototype.isLocalNs = function(ns) {
|
9463 | return ns.uri === (this.typeNs || this.ns).uri;
|
9464 | };
|
9465 |
|
9466 | function SavingWriter() {
|
9467 | this.value = '';
|
9468 |
|
9469 | this.write = function(str) {
|
9470 | this.value += str;
|
9471 | };
|
9472 | }
|
9473 |
|
9474 | function FormatingWriter(out, format) {
|
9475 |
|
9476 | var indent = [''];
|
9477 |
|
9478 | this.append = function(str) {
|
9479 | out.write(str);
|
9480 |
|
9481 | return this;
|
9482 | };
|
9483 |
|
9484 | this.appendNewLine = function() {
|
9485 | if (format) {
|
9486 | out.write('\n');
|
9487 | }
|
9488 |
|
9489 | return this;
|
9490 | };
|
9491 |
|
9492 | this.appendIndent = function() {
|
9493 | if (format) {
|
9494 | out.write(indent.join(' '));
|
9495 | }
|
9496 |
|
9497 | return this;
|
9498 | };
|
9499 |
|
9500 | this.indent = function() {
|
9501 | indent.push('');
|
9502 | return this;
|
9503 | };
|
9504 |
|
9505 | this.unindent = function() {
|
9506 | indent.pop();
|
9507 | return this;
|
9508 | };
|
9509 | }
|
9510 |
|
9511 | |
9512 |
|
9513 |
|
9514 |
|
9515 |
|
9516 | function Writer(options) {
|
9517 |
|
9518 | options = assign({ format: false, preamble: true }, options || {});
|
9519 |
|
9520 | function toXML(tree, writer) {
|
9521 | var internalWriter = writer || new SavingWriter();
|
9522 | var formatingWriter = new FormatingWriter(internalWriter, options.format);
|
9523 |
|
9524 | if (options.preamble) {
|
9525 | formatingWriter.append(XML_PREAMBLE);
|
9526 | }
|
9527 |
|
9528 | new ElementSerializer().build(tree).serializeTo(formatingWriter);
|
9529 |
|
9530 | if (!writer) {
|
9531 | return internalWriter.value;
|
9532 | }
|
9533 | }
|
9534 |
|
9535 | return {
|
9536 | toXML: toXML
|
9537 | };
|
9538 | }
|
9539 |
|
9540 | |
9541 |
|
9542 |
|
9543 |
|
9544 |
|
9545 |
|
9546 |
|
9547 |
|
9548 |
|
9549 | function BpmnModdle(packages, options) {
|
9550 | Moddle.call(this, packages, options);
|
9551 | }
|
9552 |
|
9553 | BpmnModdle.prototype = Object.create(Moddle.prototype);
|
9554 |
|
9555 |
|
9556 | |
9557 |
|
9558 |
|
9559 |
|
9560 |
|
9561 |
|
9562 |
|
9563 |
|
9564 |
|
9565 | BpmnModdle.prototype.fromXML = function(xmlStr, typeName, options, done) {
|
9566 |
|
9567 | if (!isString(typeName)) {
|
9568 | done = options;
|
9569 | options = typeName;
|
9570 | typeName = 'bpmn:Definitions';
|
9571 | }
|
9572 |
|
9573 | if (isFunction(options)) {
|
9574 | done = options;
|
9575 | options = {};
|
9576 | }
|
9577 |
|
9578 | var reader = new Reader(assign({ model: this, lax: true }, options));
|
9579 | var rootHandler = reader.handler(typeName);
|
9580 |
|
9581 | reader.fromXML(xmlStr, rootHandler, done);
|
9582 | };
|
9583 |
|
9584 |
|
9585 | |
9586 |
|
9587 |
|
9588 |
|
9589 |
|
9590 |
|
9591 |
|
9592 | BpmnModdle.prototype.toXML = function(element, options, done) {
|
9593 |
|
9594 | if (isFunction(options)) {
|
9595 | done = options;
|
9596 | options = {};
|
9597 | }
|
9598 |
|
9599 | var writer = new Writer(options);
|
9600 |
|
9601 | var result;
|
9602 | var err;
|
9603 |
|
9604 | try {
|
9605 | result = writer.toXML(element);
|
9606 | } catch (e) {
|
9607 | err = e;
|
9608 | }
|
9609 |
|
9610 | return done(err, result);
|
9611 | };
|
9612 |
|
9613 | var name = "BPMN20";
|
9614 | var uri = "http://www.omg.org/spec/BPMN/20100524/MODEL";
|
9615 | var associations = [
|
9616 | ];
|
9617 | var types$1 = [
|
9618 | {
|
9619 | name: "Interface",
|
9620 | superClass: [
|
9621 | "RootElement"
|
9622 | ],
|
9623 | properties: [
|
9624 | {
|
9625 | name: "name",
|
9626 | isAttr: true,
|
9627 | type: "String"
|
9628 | },
|
9629 | {
|
9630 | name: "operations",
|
9631 | type: "Operation",
|
9632 | isMany: true
|
9633 | },
|
9634 | {
|
9635 | name: "implementationRef",
|
9636 | type: "String",
|
9637 | isAttr: true
|
9638 | }
|
9639 | ]
|
9640 | },
|
9641 | {
|
9642 | name: "Operation",
|
9643 | superClass: [
|
9644 | "BaseElement"
|
9645 | ],
|
9646 | properties: [
|
9647 | {
|
9648 | name: "name",
|
9649 | isAttr: true,
|
9650 | type: "String"
|
9651 | },
|
9652 | {
|
9653 | name: "inMessageRef",
|
9654 | type: "Message",
|
9655 | isReference: true
|
9656 | },
|
9657 | {
|
9658 | name: "outMessageRef",
|
9659 | type: "Message",
|
9660 | isReference: true
|
9661 | },
|
9662 | {
|
9663 | name: "errorRef",
|
9664 | type: "Error",
|
9665 | isMany: true,
|
9666 | isReference: true
|
9667 | },
|
9668 | {
|
9669 | name: "implementationRef",
|
9670 | type: "String",
|
9671 | isAttr: true
|
9672 | }
|
9673 | ]
|
9674 | },
|
9675 | {
|
9676 | name: "EndPoint",
|
9677 | superClass: [
|
9678 | "RootElement"
|
9679 | ]
|
9680 | },
|
9681 | {
|
9682 | name: "Auditing",
|
9683 | superClass: [
|
9684 | "BaseElement"
|
9685 | ]
|
9686 | },
|
9687 | {
|
9688 | name: "GlobalTask",
|
9689 | superClass: [
|
9690 | "CallableElement"
|
9691 | ],
|
9692 | properties: [
|
9693 | {
|
9694 | name: "resources",
|
9695 | type: "ResourceRole",
|
9696 | isMany: true
|
9697 | }
|
9698 | ]
|
9699 | },
|
9700 | {
|
9701 | name: "Monitoring",
|
9702 | superClass: [
|
9703 | "BaseElement"
|
9704 | ]
|
9705 | },
|
9706 | {
|
9707 | name: "Performer",
|
9708 | superClass: [
|
9709 | "ResourceRole"
|
9710 | ]
|
9711 | },
|
9712 | {
|
9713 | name: "Process",
|
9714 | superClass: [
|
9715 | "FlowElementsContainer",
|
9716 | "CallableElement"
|
9717 | ],
|
9718 | properties: [
|
9719 | {
|
9720 | name: "processType",
|
9721 | type: "ProcessType",
|
9722 | isAttr: true
|
9723 | },
|
9724 | {
|
9725 | name: "isClosed",
|
9726 | isAttr: true,
|
9727 | type: "Boolean"
|
9728 | },
|
9729 | {
|
9730 | name: "auditing",
|
9731 | type: "Auditing"
|
9732 | },
|
9733 | {
|
9734 | name: "monitoring",
|
9735 | type: "Monitoring"
|
9736 | },
|
9737 | {
|
9738 | name: "properties",
|
9739 | type: "Property",
|
9740 | isMany: true
|
9741 | },
|
9742 | {
|
9743 | name: "laneSets",
|
9744 | type: "LaneSet",
|
9745 | isMany: true,
|
9746 | replaces: "FlowElementsContainer#laneSets"
|
9747 | },
|
9748 | {
|
9749 | name: "flowElements",
|
9750 | type: "FlowElement",
|
9751 | isMany: true,
|
9752 | replaces: "FlowElementsContainer#flowElements"
|
9753 | },
|
9754 | {
|
9755 | name: "artifacts",
|
9756 | type: "Artifact",
|
9757 | isMany: true
|
9758 | },
|
9759 | {
|
9760 | name: "resources",
|
9761 | type: "ResourceRole",
|
9762 | isMany: true
|
9763 | },
|
9764 | {
|
9765 | name: "correlationSubscriptions",
|
9766 | type: "CorrelationSubscription",
|
9767 | isMany: true
|
9768 | },
|
9769 | {
|
9770 | name: "supports",
|
9771 | type: "Process",
|
9772 | isMany: true,
|
9773 | isReference: true
|
9774 | },
|
9775 | {
|
9776 | name: "definitionalCollaborationRef",
|
9777 | type: "Collaboration",
|
9778 | isAttr: true,
|
9779 | isReference: true
|
9780 | },
|
9781 | {
|
9782 | name: "isExecutable",
|
9783 | isAttr: true,
|
9784 | type: "Boolean"
|
9785 | }
|
9786 | ]
|
9787 | },
|
9788 | {
|
9789 | name: "LaneSet",
|
9790 | superClass: [
|
9791 | "BaseElement"
|
9792 | ],
|
9793 | properties: [
|
9794 | {
|
9795 | name: "lanes",
|
9796 | type: "Lane",
|
9797 | isMany: true
|
9798 | },
|
9799 | {
|
9800 | name: "name",
|
9801 | isAttr: true,
|
9802 | type: "String"
|
9803 | }
|
9804 | ]
|
9805 | },
|
9806 | {
|
9807 | name: "Lane",
|
9808 | superClass: [
|
9809 | "BaseElement"
|
9810 | ],
|
9811 | properties: [
|
9812 | {
|
9813 | name: "name",
|
9814 | isAttr: true,
|
9815 | type: "String"
|
9816 | },
|
9817 | {
|
9818 | name: "partitionElementRef",
|
9819 | type: "BaseElement",
|
9820 | isAttr: true,
|
9821 | isReference: true
|
9822 | },
|
9823 | {
|
9824 | name: "partitionElement",
|
9825 | type: "BaseElement"
|
9826 | },
|
9827 | {
|
9828 | name: "flowNodeRef",
|
9829 | type: "FlowNode",
|
9830 | isMany: true,
|
9831 | isReference: true
|
9832 | },
|
9833 | {
|
9834 | name: "childLaneSet",
|
9835 | type: "LaneSet",
|
9836 | xml: {
|
9837 | serialize: "xsi:type"
|
9838 | }
|
9839 | }
|
9840 | ]
|
9841 | },
|
9842 | {
|
9843 | name: "GlobalManualTask",
|
9844 | superClass: [
|
9845 | "GlobalTask"
|
9846 | ]
|
9847 | },
|
9848 | {
|
9849 | name: "ManualTask",
|
9850 | superClass: [
|
9851 | "Task"
|
9852 | ]
|
9853 | },
|
9854 | {
|
9855 | name: "UserTask",
|
9856 | superClass: [
|
9857 | "Task"
|
9858 | ],
|
9859 | properties: [
|
9860 | {
|
9861 | name: "renderings",
|
9862 | type: "Rendering",
|
9863 | isMany: true
|
9864 | },
|
9865 | {
|
9866 | name: "implementation",
|
9867 | isAttr: true,
|
9868 | type: "String"
|
9869 | }
|
9870 | ]
|
9871 | },
|
9872 | {
|
9873 | name: "Rendering",
|
9874 | superClass: [
|
9875 | "BaseElement"
|
9876 | ]
|
9877 | },
|
9878 | {
|
9879 | name: "HumanPerformer",
|
9880 | superClass: [
|
9881 | "Performer"
|
9882 | ]
|
9883 | },
|
9884 | {
|
9885 | name: "PotentialOwner",
|
9886 | superClass: [
|
9887 | "HumanPerformer"
|
9888 | ]
|
9889 | },
|
9890 | {
|
9891 | name: "GlobalUserTask",
|
9892 | superClass: [
|
9893 | "GlobalTask"
|
9894 | ],
|
9895 | properties: [
|
9896 | {
|
9897 | name: "implementation",
|
9898 | isAttr: true,
|
9899 | type: "String"
|
9900 | },
|
9901 | {
|
9902 | name: "renderings",
|
9903 | type: "Rendering",
|
9904 | isMany: true
|
9905 | }
|
9906 | ]
|
9907 | },
|
9908 | {
|
9909 | name: "Gateway",
|
9910 | isAbstract: true,
|
9911 | superClass: [
|
9912 | "FlowNode"
|
9913 | ],
|
9914 | properties: [
|
9915 | {
|
9916 | name: "gatewayDirection",
|
9917 | type: "GatewayDirection",
|
9918 | "default": "Unspecified",
|
9919 | isAttr: true
|
9920 | }
|
9921 | ]
|
9922 | },
|
9923 | {
|
9924 | name: "EventBasedGateway",
|
9925 | superClass: [
|
9926 | "Gateway"
|
9927 | ],
|
9928 | properties: [
|
9929 | {
|
9930 | name: "instantiate",
|
9931 | "default": false,
|
9932 | isAttr: true,
|
9933 | type: "Boolean"
|
9934 | },
|
9935 | {
|
9936 | name: "eventGatewayType",
|
9937 | type: "EventBasedGatewayType",
|
9938 | isAttr: true,
|
9939 | "default": "Exclusive"
|
9940 | }
|
9941 | ]
|
9942 | },
|
9943 | {
|
9944 | name: "ComplexGateway",
|
9945 | superClass: [
|
9946 | "Gateway"
|
9947 | ],
|
9948 | properties: [
|
9949 | {
|
9950 | name: "activationCondition",
|
9951 | type: "Expression",
|
9952 | xml: {
|
9953 | serialize: "xsi:type"
|
9954 | }
|
9955 | },
|
9956 | {
|
9957 | name: "default",
|
9958 | type: "SequenceFlow",
|
9959 | isAttr: true,
|
9960 | isReference: true
|
9961 | }
|
9962 | ]
|
9963 | },
|
9964 | {
|
9965 | name: "ExclusiveGateway",
|
9966 | superClass: [
|
9967 | "Gateway"
|
9968 | ],
|
9969 | properties: [
|
9970 | {
|
9971 | name: "default",
|
9972 | type: "SequenceFlow",
|
9973 | isAttr: true,
|
9974 | isReference: true
|
9975 | }
|
9976 | ]
|
9977 | },
|
9978 | {
|
9979 | name: "InclusiveGateway",
|
9980 | superClass: [
|
9981 | "Gateway"
|
9982 | ],
|
9983 | properties: [
|
9984 | {
|
9985 | name: "default",
|
9986 | type: "SequenceFlow",
|
9987 | isAttr: true,
|
9988 | isReference: true
|
9989 | }
|
9990 | ]
|
9991 | },
|
9992 | {
|
9993 | name: "ParallelGateway",
|
9994 | superClass: [
|
9995 | "Gateway"
|
9996 | ]
|
9997 | },
|
9998 | {
|
9999 | name: "RootElement",
|
10000 | isAbstract: true,
|
10001 | superClass: [
|
10002 | "BaseElement"
|
10003 | ]
|
10004 | },
|
10005 | {
|
10006 | name: "Relationship",
|
10007 | superClass: [
|
10008 | "BaseElement"
|
10009 | ],
|
10010 | properties: [
|
10011 | {
|
10012 | name: "type",
|
10013 | isAttr: true,
|
10014 | type: "String"
|
10015 | },
|
10016 | {
|
10017 | name: "direction",
|
10018 | type: "RelationshipDirection",
|
10019 | isAttr: true
|
10020 | },
|
10021 | {
|
10022 | name: "source",
|
10023 | isMany: true,
|
10024 | isReference: true,
|
10025 | type: "Element"
|
10026 | },
|
10027 | {
|
10028 | name: "target",
|
10029 | isMany: true,
|
10030 | isReference: true,
|
10031 | type: "Element"
|
10032 | }
|
10033 | ]
|
10034 | },
|
10035 | {
|
10036 | name: "BaseElement",
|
10037 | isAbstract: true,
|
10038 | properties: [
|
10039 | {
|
10040 | name: "id",
|
10041 | isAttr: true,
|
10042 | type: "String",
|
10043 | isId: true
|
10044 | },
|
10045 | {
|
10046 | name: "documentation",
|
10047 | type: "Documentation",
|
10048 | isMany: true
|
10049 | },
|
10050 | {
|
10051 | name: "extensionDefinitions",
|
10052 | type: "ExtensionDefinition",
|
10053 | isMany: true,
|
10054 | isReference: true
|
10055 | },
|
10056 | {
|
10057 | name: "extensionElements",
|
10058 | type: "ExtensionElements"
|
10059 | }
|
10060 | ]
|
10061 | },
|
10062 | {
|
10063 | name: "Extension",
|
10064 | properties: [
|
10065 | {
|
10066 | name: "mustUnderstand",
|
10067 | "default": false,
|
10068 | isAttr: true,
|
10069 | type: "Boolean"
|
10070 | },
|
10071 | {
|
10072 | name: "definition",
|
10073 | type: "ExtensionDefinition",
|
10074 | isAttr: true,
|
10075 | isReference: true
|
10076 | }
|
10077 | ]
|
10078 | },
|
10079 | {
|
10080 | name: "ExtensionDefinition",
|
10081 | properties: [
|
10082 | {
|
10083 | name: "name",
|
10084 | isAttr: true,
|
10085 | type: "String"
|
10086 | },
|
10087 | {
|
10088 | name: "extensionAttributeDefinitions",
|
10089 | type: "ExtensionAttributeDefinition",
|
10090 | isMany: true
|
10091 | }
|
10092 | ]
|
10093 | },
|
10094 | {
|
10095 | name: "ExtensionAttributeDefinition",
|
10096 | properties: [
|
10097 | {
|
10098 | name: "name",
|
10099 | isAttr: true,
|
10100 | type: "String"
|
10101 | },
|
10102 | {
|
10103 | name: "type",
|
10104 | isAttr: true,
|
10105 | type: "String"
|
10106 | },
|
10107 | {
|
10108 | name: "isReference",
|
10109 | "default": false,
|
10110 | isAttr: true,
|
10111 | type: "Boolean"
|
10112 | },
|
10113 | {
|
10114 | name: "extensionDefinition",
|
10115 | type: "ExtensionDefinition",
|
10116 | isAttr: true,
|
10117 | isReference: true
|
10118 | }
|
10119 | ]
|
10120 | },
|
10121 | {
|
10122 | name: "ExtensionElements",
|
10123 | properties: [
|
10124 | {
|
10125 | name: "valueRef",
|
10126 | isAttr: true,
|
10127 | isReference: true,
|
10128 | type: "Element"
|
10129 | },
|
10130 | {
|
10131 | name: "values",
|
10132 | type: "Element",
|
10133 | isMany: true
|
10134 | },
|
10135 | {
|
10136 | name: "extensionAttributeDefinition",
|
10137 | type: "ExtensionAttributeDefinition",
|
10138 | isAttr: true,
|
10139 | isReference: true
|
10140 | }
|
10141 | ]
|
10142 | },
|
10143 | {
|
10144 | name: "Documentation",
|
10145 | superClass: [
|
10146 | "BaseElement"
|
10147 | ],
|
10148 | properties: [
|
10149 | {
|
10150 | name: "text",
|
10151 | type: "String",
|
10152 | isBody: true
|
10153 | },
|
10154 | {
|
10155 | name: "textFormat",
|
10156 | "default": "text/plain",
|
10157 | isAttr: true,
|
10158 | type: "String"
|
10159 | }
|
10160 | ]
|
10161 | },
|
10162 | {
|
10163 | name: "Event",
|
10164 | isAbstract: true,
|
10165 | superClass: [
|
10166 | "FlowNode",
|
10167 | "InteractionNode"
|
10168 | ],
|
10169 | properties: [
|
10170 | {
|
10171 | name: "properties",
|
10172 | type: "Property",
|
10173 | isMany: true
|
10174 | }
|
10175 | ]
|
10176 | },
|
10177 | {
|
10178 | name: "IntermediateCatchEvent",
|
10179 | superClass: [
|
10180 | "CatchEvent"
|
10181 | ]
|
10182 | },
|
10183 | {
|
10184 | name: "IntermediateThrowEvent",
|
10185 | superClass: [
|
10186 | "ThrowEvent"
|
10187 | ]
|
10188 | },
|
10189 | {
|
10190 | name: "EndEvent",
|
10191 | superClass: [
|
10192 | "ThrowEvent"
|
10193 | ]
|
10194 | },
|
10195 | {
|
10196 | name: "StartEvent",
|
10197 | superClass: [
|
10198 | "CatchEvent"
|
10199 | ],
|
10200 | properties: [
|
10201 | {
|
10202 | name: "isInterrupting",
|
10203 | "default": true,
|
10204 | isAttr: true,
|
10205 | type: "Boolean"
|
10206 | }
|
10207 | ]
|
10208 | },
|
10209 | {
|
10210 | name: "ThrowEvent",
|
10211 | isAbstract: true,
|
10212 | superClass: [
|
10213 | "Event"
|
10214 | ],
|
10215 | properties: [
|
10216 | {
|
10217 | name: "dataInputs",
|
10218 | type: "DataInput",
|
10219 | isMany: true
|
10220 | },
|
10221 | {
|
10222 | name: "dataInputAssociations",
|
10223 | type: "DataInputAssociation",
|
10224 | isMany: true
|
10225 | },
|
10226 | {
|
10227 | name: "inputSet",
|
10228 | type: "InputSet"
|
10229 | },
|
10230 | {
|
10231 | name: "eventDefinitions",
|
10232 | type: "EventDefinition",
|
10233 | isMany: true
|
10234 | },
|
10235 | {
|
10236 | name: "eventDefinitionRef",
|
10237 | type: "EventDefinition",
|
10238 | isMany: true,
|
10239 | isReference: true
|
10240 | }
|
10241 | ]
|
10242 | },
|
10243 | {
|
10244 | name: "CatchEvent",
|
10245 | isAbstract: true,
|
10246 | superClass: [
|
10247 | "Event"
|
10248 | ],
|
10249 | properties: [
|
10250 | {
|
10251 | name: "parallelMultiple",
|
10252 | isAttr: true,
|
10253 | type: "Boolean",
|
10254 | "default": false
|
10255 | },
|
10256 | {
|
10257 | name: "dataOutputs",
|
10258 | type: "DataOutput",
|
10259 | isMany: true
|
10260 | },
|
10261 | {
|
10262 | name: "dataOutputAssociations",
|
10263 | type: "DataOutputAssociation",
|
10264 | isMany: true
|
10265 | },
|
10266 | {
|
10267 | name: "outputSet",
|
10268 | type: "OutputSet"
|
10269 | },
|
10270 | {
|
10271 | name: "eventDefinitions",
|
10272 | type: "EventDefinition",
|
10273 | isMany: true
|
10274 | },
|
10275 | {
|
10276 | name: "eventDefinitionRef",
|
10277 | type: "EventDefinition",
|
10278 | isMany: true,
|
10279 | isReference: true
|
10280 | }
|
10281 | ]
|
10282 | },
|
10283 | {
|
10284 | name: "BoundaryEvent",
|
10285 | superClass: [
|
10286 | "CatchEvent"
|
10287 | ],
|
10288 | properties: [
|
10289 | {
|
10290 | name: "cancelActivity",
|
10291 | "default": true,
|
10292 | isAttr: true,
|
10293 | type: "Boolean"
|
10294 | },
|
10295 | {
|
10296 | name: "attachedToRef",
|
10297 | type: "Activity",
|
10298 | isAttr: true,
|
10299 | isReference: true
|
10300 | }
|
10301 | ]
|
10302 | },
|
10303 | {
|
10304 | name: "EventDefinition",
|
10305 | isAbstract: true,
|
10306 | superClass: [
|
10307 | "RootElement"
|
10308 | ]
|
10309 | },
|
10310 | {
|
10311 | name: "CancelEventDefinition",
|
10312 | superClass: [
|
10313 | "EventDefinition"
|
10314 | ]
|
10315 | },
|
10316 | {
|
10317 | name: "ErrorEventDefinition",
|
10318 | superClass: [
|
10319 | "EventDefinition"
|
10320 | ],
|
10321 | properties: [
|
10322 | {
|
10323 | name: "errorRef",
|
10324 | type: "Error",
|
10325 | isAttr: true,
|
10326 | isReference: true
|
10327 | }
|
10328 | ]
|
10329 | },
|
10330 | {
|
10331 | name: "TerminateEventDefinition",
|
10332 | superClass: [
|
10333 | "EventDefinition"
|
10334 | ]
|
10335 | },
|
10336 | {
|
10337 | name: "EscalationEventDefinition",
|
10338 | superClass: [
|
10339 | "EventDefinition"
|
10340 | ],
|
10341 | properties: [
|
10342 | {
|
10343 | name: "escalationRef",
|
10344 | type: "Escalation",
|
10345 | isAttr: true,
|
10346 | isReference: true
|
10347 | }
|
10348 | ]
|
10349 | },
|
10350 | {
|
10351 | name: "Escalation",
|
10352 | properties: [
|
10353 | {
|
10354 | name: "structureRef",
|
10355 | type: "ItemDefinition",
|
10356 | isAttr: true,
|
10357 | isReference: true
|
10358 | },
|
10359 | {
|
10360 | name: "name",
|
10361 | isAttr: true,
|
10362 | type: "String"
|
10363 | },
|
10364 | {
|
10365 | name: "escalationCode",
|
10366 | isAttr: true,
|
10367 | type: "String"
|
10368 | }
|
10369 | ],
|
10370 | superClass: [
|
10371 | "RootElement"
|
10372 | ]
|
10373 | },
|
10374 | {
|
10375 | name: "CompensateEventDefinition",
|
10376 | superClass: [
|
10377 | "EventDefinition"
|
10378 | ],
|
10379 | properties: [
|
10380 | {
|
10381 | name: "waitForCompletion",
|
10382 | isAttr: true,
|
10383 | type: "Boolean",
|
10384 | "default": true
|
10385 | },
|
10386 | {
|
10387 | name: "activityRef",
|
10388 | type: "Activity",
|
10389 | isAttr: true,
|
10390 | isReference: true
|
10391 | }
|
10392 | ]
|
10393 | },
|
10394 | {
|
10395 | name: "TimerEventDefinition",
|
10396 | superClass: [
|
10397 | "EventDefinition"
|
10398 | ],
|
10399 | properties: [
|
10400 | {
|
10401 | name: "timeDate",
|
10402 | type: "Expression",
|
10403 | xml: {
|
10404 | serialize: "xsi:type"
|
10405 | }
|
10406 | },
|
10407 | {
|
10408 | name: "timeCycle",
|
10409 | type: "Expression",
|
10410 | xml: {
|
10411 | serialize: "xsi:type"
|
10412 | }
|
10413 | },
|
10414 | {
|
10415 | name: "timeDuration",
|
10416 | type: "Expression",
|
10417 | xml: {
|
10418 | serialize: "xsi:type"
|
10419 | }
|
10420 | }
|
10421 | ]
|
10422 | },
|
10423 | {
|
10424 | name: "LinkEventDefinition",
|
10425 | superClass: [
|
10426 | "EventDefinition"
|
10427 | ],
|
10428 | properties: [
|
10429 | {
|
10430 | name: "name",
|
10431 | isAttr: true,
|
10432 | type: "String"
|
10433 | },
|
10434 | {
|
10435 | name: "target",
|
10436 | type: "LinkEventDefinition",
|
10437 | isAttr: true,
|
10438 | isReference: true
|
10439 | },
|
10440 | {
|
10441 | name: "source",
|
10442 | type: "LinkEventDefinition",
|
10443 | isMany: true,
|
10444 | isReference: true
|
10445 | }
|
10446 | ]
|
10447 | },
|
10448 | {
|
10449 | name: "MessageEventDefinition",
|
10450 | superClass: [
|
10451 | "EventDefinition"
|
10452 | ],
|
10453 | properties: [
|
10454 | {
|
10455 | name: "messageRef",
|
10456 | type: "Message",
|
10457 | isAttr: true,
|
10458 | isReference: true
|
10459 | },
|
10460 | {
|
10461 | name: "operationRef",
|
10462 | type: "Operation",
|
10463 | isAttr: true,
|
10464 | isReference: true
|
10465 | }
|
10466 | ]
|
10467 | },
|
10468 | {
|
10469 | name: "ConditionalEventDefinition",
|
10470 | superClass: [
|
10471 | "EventDefinition"
|
10472 | ],
|
10473 | properties: [
|
10474 | {
|
10475 | name: "condition",
|
10476 | type: "Expression",
|
10477 | xml: {
|
10478 | serialize: "xsi:type"
|
10479 | }
|
10480 | }
|
10481 | ]
|
10482 | },
|
10483 | {
|
10484 | name: "SignalEventDefinition",
|
10485 | superClass: [
|
10486 | "EventDefinition"
|
10487 | ],
|
10488 | properties: [
|
10489 | {
|
10490 | name: "signalRef",
|
10491 | type: "Signal",
|
10492 | isAttr: true,
|
10493 | isReference: true
|
10494 | }
|
10495 | ]
|
10496 | },
|
10497 | {
|
10498 | name: "Signal",
|
10499 | superClass: [
|
10500 | "RootElement"
|
10501 | ],
|
10502 | properties: [
|
10503 | {
|
10504 | name: "structureRef",
|
10505 | type: "ItemDefinition",
|
10506 | isAttr: true,
|
10507 | isReference: true
|
10508 | },
|
10509 | {
|
10510 | name: "name",
|
10511 | isAttr: true,
|
10512 | type: "String"
|
10513 | }
|
10514 | ]
|
10515 | },
|
10516 | {
|
10517 | name: "ImplicitThrowEvent",
|
10518 | superClass: [
|
10519 | "ThrowEvent"
|
10520 | ]
|
10521 | },
|
10522 | {
|
10523 | name: "DataState",
|
10524 | superClass: [
|
10525 | "BaseElement"
|
10526 | ],
|
10527 | properties: [
|
10528 | {
|
10529 | name: "name",
|
10530 | isAttr: true,
|
10531 | type: "String"
|
10532 | }
|
10533 | ]
|
10534 | },
|
10535 | {
|
10536 | name: "ItemAwareElement",
|
10537 | superClass: [
|
10538 | "BaseElement"
|
10539 | ],
|
10540 | properties: [
|
10541 | {
|
10542 | name: "itemSubjectRef",
|
10543 | type: "ItemDefinition",
|
10544 | isAttr: true,
|
10545 | isReference: true
|
10546 | },
|
10547 | {
|
10548 | name: "dataState",
|
10549 | type: "DataState"
|
10550 | }
|
10551 | ]
|
10552 | },
|
10553 | {
|
10554 | name: "DataAssociation",
|
10555 | superClass: [
|
10556 | "BaseElement"
|
10557 | ],
|
10558 | properties: [
|
10559 | {
|
10560 | name: "assignment",
|
10561 | type: "Assignment",
|
10562 | isMany: true
|
10563 | },
|
10564 | {
|
10565 | name: "sourceRef",
|
10566 | type: "ItemAwareElement",
|
10567 | isMany: true,
|
10568 | isReference: true
|
10569 | },
|
10570 | {
|
10571 | name: "targetRef",
|
10572 | type: "ItemAwareElement",
|
10573 | isReference: true
|
10574 | },
|
10575 | {
|
10576 | name: "transformation",
|
10577 | type: "FormalExpression",
|
10578 | xml: {
|
10579 | serialize: "property"
|
10580 | }
|
10581 | }
|
10582 | ]
|
10583 | },
|
10584 | {
|
10585 | name: "DataInput",
|
10586 | superClass: [
|
10587 | "ItemAwareElement"
|
10588 | ],
|
10589 | properties: [
|
10590 | {
|
10591 | name: "name",
|
10592 | isAttr: true,
|
10593 | type: "String"
|
10594 | },
|
10595 | {
|
10596 | name: "isCollection",
|
10597 | "default": false,
|
10598 | isAttr: true,
|
10599 | type: "Boolean"
|
10600 | },
|
10601 | {
|
10602 | name: "inputSetRef",
|
10603 | type: "InputSet",
|
10604 | isVirtual: true,
|
10605 | isMany: true,
|
10606 | isReference: true
|
10607 | },
|
10608 | {
|
10609 | name: "inputSetWithOptional",
|
10610 | type: "InputSet",
|
10611 | isVirtual: true,
|
10612 | isMany: true,
|
10613 | isReference: true
|
10614 | },
|
10615 | {
|
10616 | name: "inputSetWithWhileExecuting",
|
10617 | type: "InputSet",
|
10618 | isVirtual: true,
|
10619 | isMany: true,
|
10620 | isReference: true
|
10621 | }
|
10622 | ]
|
10623 | },
|
10624 | {
|
10625 | name: "DataOutput",
|
10626 | superClass: [
|
10627 | "ItemAwareElement"
|
10628 | ],
|
10629 | properties: [
|
10630 | {
|
10631 | name: "name",
|
10632 | isAttr: true,
|
10633 | type: "String"
|
10634 | },
|
10635 | {
|
10636 | name: "isCollection",
|
10637 | "default": false,
|
10638 | isAttr: true,
|
10639 | type: "Boolean"
|
10640 | },
|
10641 | {
|
10642 | name: "outputSetRef",
|
10643 | type: "OutputSet",
|
10644 | isVirtual: true,
|
10645 | isMany: true,
|
10646 | isReference: true
|
10647 | },
|
10648 | {
|
10649 | name: "outputSetWithOptional",
|
10650 | type: "OutputSet",
|
10651 | isVirtual: true,
|
10652 | isMany: true,
|
10653 | isReference: true
|
10654 | },
|
10655 | {
|
10656 | name: "outputSetWithWhileExecuting",
|
10657 | type: "OutputSet",
|
10658 | isVirtual: true,
|
10659 | isMany: true,
|
10660 | isReference: true
|
10661 | }
|
10662 | ]
|
10663 | },
|
10664 | {
|
10665 | name: "InputSet",
|
10666 | superClass: [
|
10667 | "BaseElement"
|
10668 | ],
|
10669 | properties: [
|
10670 | {
|
10671 | name: "name",
|
10672 | isAttr: true,
|
10673 | type: "String"
|
10674 | },
|
10675 | {
|
10676 | name: "dataInputRefs",
|
10677 | type: "DataInput",
|
10678 | isMany: true,
|
10679 | isReference: true
|
10680 | },
|
10681 | {
|
10682 | name: "optionalInputRefs",
|
10683 | type: "DataInput",
|
10684 | isMany: true,
|
10685 | isReference: true
|
10686 | },
|
10687 | {
|
10688 | name: "whileExecutingInputRefs",
|
10689 | type: "DataInput",
|
10690 | isMany: true,
|
10691 | isReference: true
|
10692 | },
|
10693 | {
|
10694 | name: "outputSetRefs",
|
10695 | type: "OutputSet",
|
10696 | isMany: true,
|
10697 | isReference: true
|
10698 | }
|
10699 | ]
|
10700 | },
|
10701 | {
|
10702 | name: "OutputSet",
|
10703 | superClass: [
|
10704 | "BaseElement"
|
10705 | ],
|
10706 | properties: [
|
10707 | {
|
10708 | name: "dataOutputRefs",
|
10709 | type: "DataOutput",
|
10710 | isMany: true,
|
10711 | isReference: true
|
10712 | },
|
10713 | {
|
10714 | name: "name",
|
10715 | isAttr: true,
|
10716 | type: "String"
|
10717 | },
|
10718 | {
|
10719 | name: "inputSetRefs",
|
10720 | type: "InputSet",
|
10721 | isMany: true,
|
10722 | isReference: true
|
10723 | },
|
10724 | {
|
10725 | name: "optionalOutputRefs",
|
10726 | type: "DataOutput",
|
10727 | isMany: true,
|
10728 | isReference: true
|
10729 | },
|
10730 | {
|
10731 | name: "whileExecutingOutputRefs",
|
10732 | type: "DataOutput",
|
10733 | isMany: true,
|
10734 | isReference: true
|
10735 | }
|
10736 | ]
|
10737 | },
|
10738 | {
|
10739 | name: "Property",
|
10740 | superClass: [
|
10741 | "ItemAwareElement"
|
10742 | ],
|
10743 | properties: [
|
10744 | {
|
10745 | name: "name",
|
10746 | isAttr: true,
|
10747 | type: "String"
|
10748 | }
|
10749 | ]
|
10750 | },
|
10751 | {
|
10752 | name: "DataInputAssociation",
|
10753 | superClass: [
|
10754 | "DataAssociation"
|
10755 | ]
|
10756 | },
|
10757 | {
|
10758 | name: "DataOutputAssociation",
|
10759 | superClass: [
|
10760 | "DataAssociation"
|
10761 | ]
|
10762 | },
|
10763 | {
|
10764 | name: "InputOutputSpecification",
|
10765 | superClass: [
|
10766 | "BaseElement"
|
10767 | ],
|
10768 | properties: [
|
10769 | {
|
10770 | name: "dataInputs",
|
10771 | type: "DataInput",
|
10772 | isMany: true
|
10773 | },
|
10774 | {
|
10775 | name: "dataOutputs",
|
10776 | type: "DataOutput",
|
10777 | isMany: true
|
10778 | },
|
10779 | {
|
10780 | name: "inputSets",
|
10781 | type: "InputSet",
|
10782 | isMany: true
|
10783 | },
|
10784 | {
|
10785 | name: "outputSets",
|
10786 | type: "OutputSet",
|
10787 | isMany: true
|
10788 | }
|
10789 | ]
|
10790 | },
|
10791 | {
|
10792 | name: "DataObject",
|
10793 | superClass: [
|
10794 | "FlowElement",
|
10795 | "ItemAwareElement"
|
10796 | ],
|
10797 | properties: [
|
10798 | {
|
10799 | name: "isCollection",
|
10800 | "default": false,
|
10801 | isAttr: true,
|
10802 | type: "Boolean"
|
10803 | }
|
10804 | ]
|
10805 | },
|
10806 | {
|
10807 | name: "InputOutputBinding",
|
10808 | properties: [
|
10809 | {
|
10810 | name: "inputDataRef",
|
10811 | type: "InputSet",
|
10812 | isAttr: true,
|
10813 | isReference: true
|
10814 | },
|
10815 | {
|
10816 | name: "outputDataRef",
|
10817 | type: "OutputSet",
|
10818 | isAttr: true,
|
10819 | isReference: true
|
10820 | },
|
10821 | {
|
10822 | name: "operationRef",
|
10823 | type: "Operation",
|
10824 | isAttr: true,
|
10825 | isReference: true
|
10826 | }
|
10827 | ]
|
10828 | },
|
10829 | {
|
10830 | name: "Assignment",
|
10831 | superClass: [
|
10832 | "BaseElement"
|
10833 | ],
|
10834 | properties: [
|
10835 | {
|
10836 | name: "from",
|
10837 | type: "Expression",
|
10838 | xml: {
|
10839 | serialize: "xsi:type"
|
10840 | }
|
10841 | },
|
10842 | {
|
10843 | name: "to",
|
10844 | type: "Expression",
|
10845 | xml: {
|
10846 | serialize: "xsi:type"
|
10847 | }
|
10848 | }
|
10849 | ]
|
10850 | },
|
10851 | {
|
10852 | name: "DataStore",
|
10853 | superClass: [
|
10854 | "RootElement",
|
10855 | "ItemAwareElement"
|
10856 | ],
|
10857 | properties: [
|
10858 | {
|
10859 | name: "name",
|
10860 | isAttr: true,
|
10861 | type: "String"
|
10862 | },
|
10863 | {
|
10864 | name: "capacity",
|
10865 | isAttr: true,
|
10866 | type: "Integer"
|
10867 | },
|
10868 | {
|
10869 | name: "isUnlimited",
|
10870 | "default": true,
|
10871 | isAttr: true,
|
10872 | type: "Boolean"
|
10873 | }
|
10874 | ]
|
10875 | },
|
10876 | {
|
10877 | name: "DataStoreReference",
|
10878 | superClass: [
|
10879 | "ItemAwareElement",
|
10880 | "FlowElement"
|
10881 | ],
|
10882 | properties: [
|
10883 | {
|
10884 | name: "dataStoreRef",
|
10885 | type: "DataStore",
|
10886 | isAttr: true,
|
10887 | isReference: true
|
10888 | }
|
10889 | ]
|
10890 | },
|
10891 | {
|
10892 | name: "DataObjectReference",
|
10893 | superClass: [
|
10894 | "ItemAwareElement",
|
10895 | "FlowElement"
|
10896 | ],
|
10897 | properties: [
|
10898 | {
|
10899 | name: "dataObjectRef",
|
10900 | type: "DataObject",
|
10901 | isAttr: true,
|
10902 | isReference: true
|
10903 | }
|
10904 | ]
|
10905 | },
|
10906 | {
|
10907 | name: "ConversationLink",
|
10908 | superClass: [
|
10909 | "BaseElement"
|
10910 | ],
|
10911 | properties: [
|
10912 | {
|
10913 | name: "sourceRef",
|
10914 | type: "InteractionNode",
|
10915 | isAttr: true,
|
10916 | isReference: true
|
10917 | },
|
10918 | {
|
10919 | name: "targetRef",
|
10920 | type: "InteractionNode",
|
10921 | isAttr: true,
|
10922 | isReference: true
|
10923 | },
|
10924 | {
|
10925 | name: "name",
|
10926 | isAttr: true,
|
10927 | type: "String"
|
10928 | }
|
10929 | ]
|
10930 | },
|
10931 | {
|
10932 | name: "ConversationAssociation",
|
10933 | superClass: [
|
10934 | "BaseElement"
|
10935 | ],
|
10936 | properties: [
|
10937 | {
|
10938 | name: "innerConversationNodeRef",
|
10939 | type: "ConversationNode",
|
10940 | isAttr: true,
|
10941 | isReference: true
|
10942 | },
|
10943 | {
|
10944 | name: "outerConversationNodeRef",
|
10945 | type: "ConversationNode",
|
10946 | isAttr: true,
|
10947 | isReference: true
|
10948 | }
|
10949 | ]
|
10950 | },
|
10951 | {
|
10952 | name: "CallConversation",
|
10953 | superClass: [
|
10954 | "ConversationNode"
|
10955 | ],
|
10956 | properties: [
|
10957 | {
|
10958 | name: "calledCollaborationRef",
|
10959 | type: "Collaboration",
|
10960 | isAttr: true,
|
10961 | isReference: true
|
10962 | },
|
10963 | {
|
10964 | name: "participantAssociations",
|
10965 | type: "ParticipantAssociation",
|
10966 | isMany: true
|
10967 | }
|
10968 | ]
|
10969 | },
|
10970 | {
|
10971 | name: "Conversation",
|
10972 | superClass: [
|
10973 | "ConversationNode"
|
10974 | ]
|
10975 | },
|
10976 | {
|
10977 | name: "SubConversation",
|
10978 | superClass: [
|
10979 | "ConversationNode"
|
10980 | ],
|
10981 | properties: [
|
10982 | {
|
10983 | name: "conversationNodes",
|
10984 | type: "ConversationNode",
|
10985 | isMany: true
|
10986 | }
|
10987 | ]
|
10988 | },
|
10989 | {
|
10990 | name: "ConversationNode",
|
10991 | isAbstract: true,
|
10992 | superClass: [
|
10993 | "InteractionNode",
|
10994 | "BaseElement"
|
10995 | ],
|
10996 | properties: [
|
10997 | {
|
10998 | name: "name",
|
10999 | isAttr: true,
|
11000 | type: "String"
|
11001 | },
|
11002 | {
|
11003 | name: "participantRef",
|
11004 | type: "Participant",
|
11005 | isMany: true,
|
11006 | isReference: true
|
11007 | },
|
11008 | {
|
11009 | name: "messageFlowRefs",
|
11010 | type: "MessageFlow",
|
11011 | isMany: true,
|
11012 | isReference: true
|
11013 | },
|
11014 | {
|
11015 | name: "correlationKeys",
|
11016 | type: "CorrelationKey",
|
11017 | isMany: true
|
11018 | }
|
11019 | ]
|
11020 | },
|
11021 | {
|
11022 | name: "GlobalConversation",
|
11023 | superClass: [
|
11024 | "Collaboration"
|
11025 | ]
|
11026 | },
|
11027 | {
|
11028 | name: "PartnerEntity",
|
11029 | superClass: [
|
11030 | "RootElement"
|
11031 | ],
|
11032 | properties: [
|
11033 | {
|
11034 | name: "name",
|
11035 | isAttr: true,
|
11036 | type: "String"
|
11037 | },
|
11038 | {
|
11039 | name: "participantRef",
|
11040 | type: "Participant",
|
11041 | isMany: true,
|
11042 | isReference: true
|
11043 | }
|
11044 | ]
|
11045 | },
|
11046 | {
|
11047 | name: "PartnerRole",
|
11048 | superClass: [
|
11049 | "RootElement"
|
11050 | ],
|
11051 | properties: [
|
11052 | {
|
11053 | name: "name",
|
11054 | isAttr: true,
|
11055 | type: "String"
|
11056 | },
|
11057 | {
|
11058 | name: "participantRef",
|
11059 | type: "Participant",
|
11060 | isMany: true,
|
11061 | isReference: true
|
11062 | }
|
11063 | ]
|
11064 | },
|
11065 | {
|
11066 | name: "CorrelationProperty",
|
11067 | superClass: [
|
11068 | "RootElement"
|
11069 | ],
|
11070 | properties: [
|
11071 | {
|
11072 | name: "correlationPropertyRetrievalExpression",
|
11073 | type: "CorrelationPropertyRetrievalExpression",
|
11074 | isMany: true
|
11075 | },
|
11076 | {
|
11077 | name: "name",
|
11078 | isAttr: true,
|
11079 | type: "String"
|
11080 | },
|
11081 | {
|
11082 | name: "type",
|
11083 | type: "ItemDefinition",
|
11084 | isAttr: true,
|
11085 | isReference: true
|
11086 | }
|
11087 | ]
|
11088 | },
|
11089 | {
|
11090 | name: "Error",
|
11091 | superClass: [
|
11092 | "RootElement"
|
11093 | ],
|
11094 | properties: [
|
11095 | {
|
11096 | name: "structureRef",
|
11097 | type: "ItemDefinition",
|
11098 | isAttr: true,
|
11099 | isReference: true
|
11100 | },
|
11101 | {
|
11102 | name: "name",
|
11103 | isAttr: true,
|
11104 | type: "String"
|
11105 | },
|
11106 | {
|
11107 | name: "errorCode",
|
11108 | isAttr: true,
|
11109 | type: "String"
|
11110 | }
|
11111 | ]
|
11112 | },
|
11113 | {
|
11114 | name: "CorrelationKey",
|
11115 | superClass: [
|
11116 | "BaseElement"
|
11117 | ],
|
11118 | properties: [
|
11119 | {
|
11120 | name: "correlationPropertyRef",
|
11121 | type: "CorrelationProperty",
|
11122 | isMany: true,
|
11123 | isReference: true
|
11124 | },
|
11125 | {
|
11126 | name: "name",
|
11127 | isAttr: true,
|
11128 | type: "String"
|
11129 | }
|
11130 | ]
|
11131 | },
|
11132 | {
|
11133 | name: "Expression",
|
11134 | superClass: [
|
11135 | "BaseElement"
|
11136 | ],
|
11137 | isAbstract: false,
|
11138 | properties: [
|
11139 | {
|
11140 | name: "body",
|
11141 | type: "String",
|
11142 | isBody: true
|
11143 | }
|
11144 | ]
|
11145 | },
|
11146 | {
|
11147 | name: "FormalExpression",
|
11148 | superClass: [
|
11149 | "Expression"
|
11150 | ],
|
11151 | properties: [
|
11152 | {
|
11153 | name: "language",
|
11154 | isAttr: true,
|
11155 | type: "String"
|
11156 | },
|
11157 | {
|
11158 | name: "evaluatesToTypeRef",
|
11159 | type: "ItemDefinition",
|
11160 | isAttr: true,
|
11161 | isReference: true
|
11162 | }
|
11163 | ]
|
11164 | },
|
11165 | {
|
11166 | name: "Message",
|
11167 | superClass: [
|
11168 | "RootElement"
|
11169 | ],
|
11170 | properties: [
|
11171 | {
|
11172 | name: "name",
|
11173 | isAttr: true,
|
11174 | type: "String"
|
11175 | },
|
11176 | {
|
11177 | name: "itemRef",
|
11178 | type: "ItemDefinition",
|
11179 | isAttr: true,
|
11180 | isReference: true
|
11181 | }
|
11182 | ]
|
11183 | },
|
11184 | {
|
11185 | name: "ItemDefinition",
|
11186 | superClass: [
|
11187 | "RootElement"
|
11188 | ],
|
11189 | properties: [
|
11190 | {
|
11191 | name: "itemKind",
|
11192 | type: "ItemKind",
|
11193 | isAttr: true
|
11194 | },
|
11195 | {
|
11196 | name: "structureRef",
|
11197 | type: "String",
|
11198 | isAttr: true
|
11199 | },
|
11200 | {
|
11201 | name: "isCollection",
|
11202 | "default": false,
|
11203 | isAttr: true,
|
11204 | type: "Boolean"
|
11205 | },
|
11206 | {
|
11207 | name: "import",
|
11208 | type: "Import",
|
11209 | isAttr: true,
|
11210 | isReference: true
|
11211 | }
|
11212 | ]
|
11213 | },
|
11214 | {
|
11215 | name: "FlowElement",
|
11216 | isAbstract: true,
|
11217 | superClass: [
|
11218 | "BaseElement"
|
11219 | ],
|
11220 | properties: [
|
11221 | {
|
11222 | name: "name",
|
11223 | isAttr: true,
|
11224 | type: "String"
|
11225 | },
|
11226 | {
|
11227 | name: "auditing",
|
11228 | type: "Auditing"
|
11229 | },
|
11230 | {
|
11231 | name: "monitoring",
|
11232 | type: "Monitoring"
|
11233 | },
|
11234 | {
|
11235 | name: "categoryValueRef",
|
11236 | type: "CategoryValue",
|
11237 | isMany: true,
|
11238 | isReference: true
|
11239 | }
|
11240 | ]
|
11241 | },
|
11242 | {
|
11243 | name: "SequenceFlow",
|
11244 | superClass: [
|
11245 | "FlowElement"
|
11246 | ],
|
11247 | properties: [
|
11248 | {
|
11249 | name: "isImmediate",
|
11250 | isAttr: true,
|
11251 | type: "Boolean"
|
11252 | },
|
11253 | {
|
11254 | name: "conditionExpression",
|
11255 | type: "Expression",
|
11256 | xml: {
|
11257 | serialize: "xsi:type"
|
11258 | }
|
11259 | },
|
11260 | {
|
11261 | name: "sourceRef",
|
11262 | type: "FlowNode",
|
11263 | isAttr: true,
|
11264 | isReference: true
|
11265 | },
|
11266 | {
|
11267 | name: "targetRef",
|
11268 | type: "FlowNode",
|
11269 | isAttr: true,
|
11270 | isReference: true
|
11271 | }
|
11272 | ]
|
11273 | },
|
11274 | {
|
11275 | name: "FlowElementsContainer",
|
11276 | isAbstract: true,
|
11277 | superClass: [
|
11278 | "BaseElement"
|
11279 | ],
|
11280 | properties: [
|
11281 | {
|
11282 | name: "laneSets",
|
11283 | type: "LaneSet",
|
11284 | isMany: true
|
11285 | },
|
11286 | {
|
11287 | name: "flowElements",
|
11288 | type: "FlowElement",
|
11289 | isMany: true
|
11290 | }
|
11291 | ]
|
11292 | },
|
11293 | {
|
11294 | name: "CallableElement",
|
11295 | isAbstract: true,
|
11296 | superClass: [
|
11297 | "RootElement"
|
11298 | ],
|
11299 | properties: [
|
11300 | {
|
11301 | name: "name",
|
11302 | isAttr: true,
|
11303 | type: "String"
|
11304 | },
|
11305 | {
|
11306 | name: "ioSpecification",
|
11307 | type: "InputOutputSpecification",
|
11308 | xml: {
|
11309 | serialize: "property"
|
11310 | }
|
11311 | },
|
11312 | {
|
11313 | name: "supportedInterfaceRef",
|
11314 | type: "Interface",
|
11315 | isMany: true,
|
11316 | isReference: true
|
11317 | },
|
11318 | {
|
11319 | name: "ioBinding",
|
11320 | type: "InputOutputBinding",
|
11321 | isMany: true,
|
11322 | xml: {
|
11323 | serialize: "property"
|
11324 | }
|
11325 | }
|
11326 | ]
|
11327 | },
|
11328 | {
|
11329 | name: "FlowNode",
|
11330 | isAbstract: true,
|
11331 | superClass: [
|
11332 | "FlowElement"
|
11333 | ],
|
11334 | properties: [
|
11335 | {
|
11336 | name: "incoming",
|
11337 | type: "SequenceFlow",
|
11338 | isMany: true,
|
11339 | isReference: true
|
11340 | },
|
11341 | {
|
11342 | name: "outgoing",
|
11343 | type: "SequenceFlow",
|
11344 | isMany: true,
|
11345 | isReference: true
|
11346 | },
|
11347 | {
|
11348 | name: "lanes",
|
11349 | type: "Lane",
|
11350 | isVirtual: true,
|
11351 | isMany: true,
|
11352 | isReference: true
|
11353 | }
|
11354 | ]
|
11355 | },
|
11356 | {
|
11357 | name: "CorrelationPropertyRetrievalExpression",
|
11358 | superClass: [
|
11359 | "BaseElement"
|
11360 | ],
|
11361 | properties: [
|
11362 | {
|
11363 | name: "messagePath",
|
11364 | type: "FormalExpression"
|
11365 | },
|
11366 | {
|
11367 | name: "messageRef",
|
11368 | type: "Message",
|
11369 | isAttr: true,
|
11370 | isReference: true
|
11371 | }
|
11372 | ]
|
11373 | },
|
11374 | {
|
11375 | name: "CorrelationPropertyBinding",
|
11376 | superClass: [
|
11377 | "BaseElement"
|
11378 | ],
|
11379 | properties: [
|
11380 | {
|
11381 | name: "dataPath",
|
11382 | type: "FormalExpression"
|
11383 | },
|
11384 | {
|
11385 | name: "correlationPropertyRef",
|
11386 | type: "CorrelationProperty",
|
11387 | isAttr: true,
|
11388 | isReference: true
|
11389 | }
|
11390 | ]
|
11391 | },
|
11392 | {
|
11393 | name: "Resource",
|
11394 | superClass: [
|
11395 | "RootElement"
|
11396 | ],
|
11397 | properties: [
|
11398 | {
|
11399 | name: "name",
|
11400 | isAttr: true,
|
11401 | type: "String"
|
11402 | },
|
11403 | {
|
11404 | name: "resourceParameters",
|
11405 | type: "ResourceParameter",
|
11406 | isMany: true
|
11407 | }
|
11408 | ]
|
11409 | },
|
11410 | {
|
11411 | name: "ResourceParameter",
|
11412 | superClass: [
|
11413 | "BaseElement"
|
11414 | ],
|
11415 | properties: [
|
11416 | {
|
11417 | name: "name",
|
11418 | isAttr: true,
|
11419 | type: "String"
|
11420 | },
|
11421 | {
|
11422 | name: "isRequired",
|
11423 | isAttr: true,
|
11424 | type: "Boolean"
|
11425 | },
|
11426 | {
|
11427 | name: "type",
|
11428 | type: "ItemDefinition",
|
11429 | isAttr: true,
|
11430 | isReference: true
|
11431 | }
|
11432 | ]
|
11433 | },
|
11434 | {
|
11435 | name: "CorrelationSubscription",
|
11436 | superClass: [
|
11437 | "BaseElement"
|
11438 | ],
|
11439 | properties: [
|
11440 | {
|
11441 | name: "correlationKeyRef",
|
11442 | type: "CorrelationKey",
|
11443 | isAttr: true,
|
11444 | isReference: true
|
11445 | },
|
11446 | {
|
11447 | name: "correlationPropertyBinding",
|
11448 | type: "CorrelationPropertyBinding",
|
11449 | isMany: true
|
11450 | }
|
11451 | ]
|
11452 | },
|
11453 | {
|
11454 | name: "MessageFlow",
|
11455 | superClass: [
|
11456 | "BaseElement"
|
11457 | ],
|
11458 | properties: [
|
11459 | {
|
11460 | name: "name",
|
11461 | isAttr: true,
|
11462 | type: "String"
|
11463 | },
|
11464 | {
|
11465 | name: "sourceRef",
|
11466 | type: "InteractionNode",
|
11467 | isAttr: true,
|
11468 | isReference: true
|
11469 | },
|
11470 | {
|
11471 | name: "targetRef",
|
11472 | type: "InteractionNode",
|
11473 | isAttr: true,
|
11474 | isReference: true
|
11475 | },
|
11476 | {
|
11477 | name: "messageRef",
|
11478 | type: "Message",
|
11479 | isAttr: true,
|
11480 | isReference: true
|
11481 | }
|
11482 | ]
|
11483 | },
|
11484 | {
|
11485 | name: "MessageFlowAssociation",
|
11486 | superClass: [
|
11487 | "BaseElement"
|
11488 | ],
|
11489 | properties: [
|
11490 | {
|
11491 | name: "innerMessageFlowRef",
|
11492 | type: "MessageFlow",
|
11493 | isAttr: true,
|
11494 | isReference: true
|
11495 | },
|
11496 | {
|
11497 | name: "outerMessageFlowRef",
|
11498 | type: "MessageFlow",
|
11499 | isAttr: true,
|
11500 | isReference: true
|
11501 | }
|
11502 | ]
|
11503 | },
|
11504 | {
|
11505 | name: "InteractionNode",
|
11506 | isAbstract: true,
|
11507 | properties: [
|
11508 | {
|
11509 | name: "incomingConversationLinks",
|
11510 | type: "ConversationLink",
|
11511 | isVirtual: true,
|
11512 | isMany: true,
|
11513 | isReference: true
|
11514 | },
|
11515 | {
|
11516 | name: "outgoingConversationLinks",
|
11517 | type: "ConversationLink",
|
11518 | isVirtual: true,
|
11519 | isMany: true,
|
11520 | isReference: true
|
11521 | }
|
11522 | ]
|
11523 | },
|
11524 | {
|
11525 | name: "Participant",
|
11526 | superClass: [
|
11527 | "InteractionNode",
|
11528 | "BaseElement"
|
11529 | ],
|
11530 | properties: [
|
11531 | {
|
11532 | name: "name",
|
11533 | isAttr: true,
|
11534 | type: "String"
|
11535 | },
|
11536 | {
|
11537 | name: "interfaceRef",
|
11538 | type: "Interface",
|
11539 | isMany: true,
|
11540 | isReference: true
|
11541 | },
|
11542 | {
|
11543 | name: "participantMultiplicity",
|
11544 | type: "ParticipantMultiplicity"
|
11545 | },
|
11546 | {
|
11547 | name: "endPointRefs",
|
11548 | type: "EndPoint",
|
11549 | isMany: true,
|
11550 | isReference: true
|
11551 | },
|
11552 | {
|
11553 | name: "processRef",
|
11554 | type: "Process",
|
11555 | isAttr: true,
|
11556 | isReference: true
|
11557 | }
|
11558 | ]
|
11559 | },
|
11560 | {
|
11561 | name: "ParticipantAssociation",
|
11562 | superClass: [
|
11563 | "BaseElement"
|
11564 | ],
|
11565 | properties: [
|
11566 | {
|
11567 | name: "innerParticipantRef",
|
11568 | type: "Participant",
|
11569 | isAttr: true,
|
11570 | isReference: true
|
11571 | },
|
11572 | {
|
11573 | name: "outerParticipantRef",
|
11574 | type: "Participant",
|
11575 | isAttr: true,
|
11576 | isReference: true
|
11577 | }
|
11578 | ]
|
11579 | },
|
11580 | {
|
11581 | name: "ParticipantMultiplicity",
|
11582 | properties: [
|
11583 | {
|
11584 | name: "minimum",
|
11585 | "default": 0,
|
11586 | isAttr: true,
|
11587 | type: "Integer"
|
11588 | },
|
11589 | {
|
11590 | name: "maximum",
|
11591 | "default": 1,
|
11592 | isAttr: true,
|
11593 | type: "Integer"
|
11594 | }
|
11595 | ],
|
11596 | superClass: [
|
11597 | "BaseElement"
|
11598 | ]
|
11599 | },
|
11600 | {
|
11601 | name: "Collaboration",
|
11602 | superClass: [
|
11603 | "RootElement"
|
11604 | ],
|
11605 | properties: [
|
11606 | {
|
11607 | name: "name",
|
11608 | isAttr: true,
|
11609 | type: "String"
|
11610 | },
|
11611 | {
|
11612 | name: "isClosed",
|
11613 | isAttr: true,
|
11614 | type: "Boolean"
|
11615 | },
|
11616 | {
|
11617 | name: "participants",
|
11618 | type: "Participant",
|
11619 | isMany: true
|
11620 | },
|
11621 | {
|
11622 | name: "messageFlows",
|
11623 | type: "MessageFlow",
|
11624 | isMany: true
|
11625 | },
|
11626 | {
|
11627 | name: "artifacts",
|
11628 | type: "Artifact",
|
11629 | isMany: true
|
11630 | },
|
11631 | {
|
11632 | name: "conversations",
|
11633 | type: "ConversationNode",
|
11634 | isMany: true
|
11635 | },
|
11636 | {
|
11637 | name: "conversationAssociations",
|
11638 | type: "ConversationAssociation"
|
11639 | },
|
11640 | {
|
11641 | name: "participantAssociations",
|
11642 | type: "ParticipantAssociation",
|
11643 | isMany: true
|
11644 | },
|
11645 | {
|
11646 | name: "messageFlowAssociations",
|
11647 | type: "MessageFlowAssociation",
|
11648 | isMany: true
|
11649 | },
|
11650 | {
|
11651 | name: "correlationKeys",
|
11652 | type: "CorrelationKey",
|
11653 | isMany: true
|
11654 | },
|
11655 | {
|
11656 | name: "choreographyRef",
|
11657 | type: "Choreography",
|
11658 | isMany: true,
|
11659 | isReference: true
|
11660 | },
|
11661 | {
|
11662 | name: "conversationLinks",
|
11663 | type: "ConversationLink",
|
11664 | isMany: true
|
11665 | }
|
11666 | ]
|
11667 | },
|
11668 | {
|
11669 | name: "ChoreographyActivity",
|
11670 | isAbstract: true,
|
11671 | superClass: [
|
11672 | "FlowNode"
|
11673 | ],
|
11674 | properties: [
|
11675 | {
|
11676 | name: "participantRef",
|
11677 | type: "Participant",
|
11678 | isMany: true,
|
11679 | isReference: true
|
11680 | },
|
11681 | {
|
11682 | name: "initiatingParticipantRef",
|
11683 | type: "Participant",
|
11684 | isAttr: true,
|
11685 | isReference: true
|
11686 | },
|
11687 | {
|
11688 | name: "correlationKeys",
|
11689 | type: "CorrelationKey",
|
11690 | isMany: true
|
11691 | },
|
11692 | {
|
11693 | name: "loopType",
|
11694 | type: "ChoreographyLoopType",
|
11695 | "default": "None",
|
11696 | isAttr: true
|
11697 | }
|
11698 | ]
|
11699 | },
|
11700 | {
|
11701 | name: "CallChoreography",
|
11702 | superClass: [
|
11703 | "ChoreographyActivity"
|
11704 | ],
|
11705 | properties: [
|
11706 | {
|
11707 | name: "calledChoreographyRef",
|
11708 | type: "Choreography",
|
11709 | isAttr: true,
|
11710 | isReference: true
|
11711 | },
|
11712 | {
|
11713 | name: "participantAssociations",
|
11714 | type: "ParticipantAssociation",
|
11715 | isMany: true
|
11716 | }
|
11717 | ]
|
11718 | },
|
11719 | {
|
11720 | name: "SubChoreography",
|
11721 | superClass: [
|
11722 | "ChoreographyActivity",
|
11723 | "FlowElementsContainer"
|
11724 | ],
|
11725 | properties: [
|
11726 | {
|
11727 | name: "artifacts",
|
11728 | type: "Artifact",
|
11729 | isMany: true
|
11730 | }
|
11731 | ]
|
11732 | },
|
11733 | {
|
11734 | name: "ChoreographyTask",
|
11735 | superClass: [
|
11736 | "ChoreographyActivity"
|
11737 | ],
|
11738 | properties: [
|
11739 | {
|
11740 | name: "messageFlowRef",
|
11741 | type: "MessageFlow",
|
11742 | isMany: true,
|
11743 | isReference: true
|
11744 | }
|
11745 | ]
|
11746 | },
|
11747 | {
|
11748 | name: "Choreography",
|
11749 | superClass: [
|
11750 | "Collaboration",
|
11751 | "FlowElementsContainer"
|
11752 | ]
|
11753 | },
|
11754 | {
|
11755 | name: "GlobalChoreographyTask",
|
11756 | superClass: [
|
11757 | "Choreography"
|
11758 | ],
|
11759 | properties: [
|
11760 | {
|
11761 | name: "initiatingParticipantRef",
|
11762 | type: "Participant",
|
11763 | isAttr: true,
|
11764 | isReference: true
|
11765 | }
|
11766 | ]
|
11767 | },
|
11768 | {
|
11769 | name: "TextAnnotation",
|
11770 | superClass: [
|
11771 | "Artifact"
|
11772 | ],
|
11773 | properties: [
|
11774 | {
|
11775 | name: "text",
|
11776 | type: "String"
|
11777 | },
|
11778 | {
|
11779 | name: "textFormat",
|
11780 | "default": "text/plain",
|
11781 | isAttr: true,
|
11782 | type: "String"
|
11783 | }
|
11784 | ]
|
11785 | },
|
11786 | {
|
11787 | name: "Group",
|
11788 | superClass: [
|
11789 | "Artifact"
|
11790 | ],
|
11791 | properties: [
|
11792 | {
|
11793 | name: "categoryValueRef",
|
11794 | type: "CategoryValue",
|
11795 | isAttr: true,
|
11796 | isReference: true
|
11797 | }
|
11798 | ]
|
11799 | },
|
11800 | {
|
11801 | name: "Association",
|
11802 | superClass: [
|
11803 | "Artifact"
|
11804 | ],
|
11805 | properties: [
|
11806 | {
|
11807 | name: "associationDirection",
|
11808 | type: "AssociationDirection",
|
11809 | isAttr: true
|
11810 | },
|
11811 | {
|
11812 | name: "sourceRef",
|
11813 | type: "BaseElement",
|
11814 | isAttr: true,
|
11815 | isReference: true
|
11816 | },
|
11817 | {
|
11818 | name: "targetRef",
|
11819 | type: "BaseElement",
|
11820 | isAttr: true,
|
11821 | isReference: true
|
11822 | }
|
11823 | ]
|
11824 | },
|
11825 | {
|
11826 | name: "Category",
|
11827 | superClass: [
|
11828 | "RootElement"
|
11829 | ],
|
11830 | properties: [
|
11831 | {
|
11832 | name: "categoryValue",
|
11833 | type: "CategoryValue",
|
11834 | isMany: true
|
11835 | },
|
11836 | {
|
11837 | name: "name",
|
11838 | isAttr: true,
|
11839 | type: "String"
|
11840 | }
|
11841 | ]
|
11842 | },
|
11843 | {
|
11844 | name: "Artifact",
|
11845 | isAbstract: true,
|
11846 | superClass: [
|
11847 | "BaseElement"
|
11848 | ]
|
11849 | },
|
11850 | {
|
11851 | name: "CategoryValue",
|
11852 | superClass: [
|
11853 | "BaseElement"
|
11854 | ],
|
11855 | properties: [
|
11856 | {
|
11857 | name: "categorizedFlowElements",
|
11858 | type: "FlowElement",
|
11859 | isVirtual: true,
|
11860 | isMany: true,
|
11861 | isReference: true
|
11862 | },
|
11863 | {
|
11864 | name: "value",
|
11865 | isAttr: true,
|
11866 | type: "String"
|
11867 | }
|
11868 | ]
|
11869 | },
|
11870 | {
|
11871 | name: "Activity",
|
11872 | isAbstract: true,
|
11873 | superClass: [
|
11874 | "FlowNode"
|
11875 | ],
|
11876 | properties: [
|
11877 | {
|
11878 | name: "isForCompensation",
|
11879 | "default": false,
|
11880 | isAttr: true,
|
11881 | type: "Boolean"
|
11882 | },
|
11883 | {
|
11884 | name: "default",
|
11885 | type: "SequenceFlow",
|
11886 | isAttr: true,
|
11887 | isReference: true
|
11888 | },
|
11889 | {
|
11890 | name: "ioSpecification",
|
11891 | type: "InputOutputSpecification",
|
11892 | xml: {
|
11893 | serialize: "property"
|
11894 | }
|
11895 | },
|
11896 | {
|
11897 | name: "boundaryEventRefs",
|
11898 | type: "BoundaryEvent",
|
11899 | isMany: true,
|
11900 | isReference: true
|
11901 | },
|
11902 | {
|
11903 | name: "properties",
|
11904 | type: "Property",
|
11905 | isMany: true
|
11906 | },
|
11907 | {
|
11908 | name: "dataInputAssociations",
|
11909 | type: "DataInputAssociation",
|
11910 | isMany: true
|
11911 | },
|
11912 | {
|
11913 | name: "dataOutputAssociations",
|
11914 | type: "DataOutputAssociation",
|
11915 | isMany: true
|
11916 | },
|
11917 | {
|
11918 | name: "startQuantity",
|
11919 | "default": 1,
|
11920 | isAttr: true,
|
11921 | type: "Integer"
|
11922 | },
|
11923 | {
|
11924 | name: "resources",
|
11925 | type: "ResourceRole",
|
11926 | isMany: true
|
11927 | },
|
11928 | {
|
11929 | name: "completionQuantity",
|
11930 | "default": 1,
|
11931 | isAttr: true,
|
11932 | type: "Integer"
|
11933 | },
|
11934 | {
|
11935 | name: "loopCharacteristics",
|
11936 | type: "LoopCharacteristics"
|
11937 | }
|
11938 | ]
|
11939 | },
|
11940 | {
|
11941 | name: "ServiceTask",
|
11942 | superClass: [
|
11943 | "Task"
|
11944 | ],
|
11945 | properties: [
|
11946 | {
|
11947 | name: "implementation",
|
11948 | isAttr: true,
|
11949 | type: "String"
|
11950 | },
|
11951 | {
|
11952 | name: "operationRef",
|
11953 | type: "Operation",
|
11954 | isAttr: true,
|
11955 | isReference: true
|
11956 | }
|
11957 | ]
|
11958 | },
|
11959 | {
|
11960 | name: "SubProcess",
|
11961 | superClass: [
|
11962 | "Activity",
|
11963 | "FlowElementsContainer",
|
11964 | "InteractionNode"
|
11965 | ],
|
11966 | properties: [
|
11967 | {
|
11968 | name: "triggeredByEvent",
|
11969 | "default": false,
|
11970 | isAttr: true,
|
11971 | type: "Boolean"
|
11972 | },
|
11973 | {
|
11974 | name: "artifacts",
|
11975 | type: "Artifact",
|
11976 | isMany: true
|
11977 | }
|
11978 | ]
|
11979 | },
|
11980 | {
|
11981 | name: "LoopCharacteristics",
|
11982 | isAbstract: true,
|
11983 | superClass: [
|
11984 | "BaseElement"
|
11985 | ]
|
11986 | },
|
11987 | {
|
11988 | name: "MultiInstanceLoopCharacteristics",
|
11989 | superClass: [
|
11990 | "LoopCharacteristics"
|
11991 | ],
|
11992 | properties: [
|
11993 | {
|
11994 | name: "isSequential",
|
11995 | "default": false,
|
11996 | isAttr: true,
|
11997 | type: "Boolean"
|
11998 | },
|
11999 | {
|
12000 | name: "behavior",
|
12001 | type: "MultiInstanceBehavior",
|
12002 | "default": "All",
|
12003 | isAttr: true
|
12004 | },
|
12005 | {
|
12006 | name: "loopCardinality",
|
12007 | type: "Expression",
|
12008 | xml: {
|
12009 | serialize: "xsi:type"
|
12010 | }
|
12011 | },
|
12012 | {
|
12013 | name: "loopDataInputRef",
|
12014 | type: "ItemAwareElement",
|
12015 | isReference: true
|
12016 | },
|
12017 | {
|
12018 | name: "loopDataOutputRef",
|
12019 | type: "ItemAwareElement",
|
12020 | isReference: true
|
12021 | },
|
12022 | {
|
12023 | name: "inputDataItem",
|
12024 | type: "DataInput",
|
12025 | xml: {
|
12026 | serialize: "property"
|
12027 | }
|
12028 | },
|
12029 | {
|
12030 | name: "outputDataItem",
|
12031 | type: "DataOutput",
|
12032 | xml: {
|
12033 | serialize: "property"
|
12034 | }
|
12035 | },
|
12036 | {
|
12037 | name: "complexBehaviorDefinition",
|
12038 | type: "ComplexBehaviorDefinition",
|
12039 | isMany: true
|
12040 | },
|
12041 | {
|
12042 | name: "completionCondition",
|
12043 | type: "Expression",
|
12044 | xml: {
|
12045 | serialize: "xsi:type"
|
12046 | }
|
12047 | },
|
12048 | {
|
12049 | name: "oneBehaviorEventRef",
|
12050 | type: "EventDefinition",
|
12051 | isAttr: true,
|
12052 | isReference: true
|
12053 | },
|
12054 | {
|
12055 | name: "noneBehaviorEventRef",
|
12056 | type: "EventDefinition",
|
12057 | isAttr: true,
|
12058 | isReference: true
|
12059 | }
|
12060 | ]
|
12061 | },
|
12062 | {
|
12063 | name: "StandardLoopCharacteristics",
|
12064 | superClass: [
|
12065 | "LoopCharacteristics"
|
12066 | ],
|
12067 | properties: [
|
12068 | {
|
12069 | name: "testBefore",
|
12070 | "default": false,
|
12071 | isAttr: true,
|
12072 | type: "Boolean"
|
12073 | },
|
12074 | {
|
12075 | name: "loopCondition",
|
12076 | type: "Expression",
|
12077 | xml: {
|
12078 | serialize: "xsi:type"
|
12079 | }
|
12080 | },
|
12081 | {
|
12082 | name: "loopMaximum",
|
12083 | type: "Integer",
|
12084 | isAttr: true
|
12085 | }
|
12086 | ]
|
12087 | },
|
12088 | {
|
12089 | name: "CallActivity",
|
12090 | superClass: [
|
12091 | "Activity"
|
12092 | ],
|
12093 | properties: [
|
12094 | {
|
12095 | name: "calledElement",
|
12096 | type: "String",
|
12097 | isAttr: true
|
12098 | }
|
12099 | ]
|
12100 | },
|
12101 | {
|
12102 | name: "Task",
|
12103 | superClass: [
|
12104 | "Activity",
|
12105 | "InteractionNode"
|
12106 | ]
|
12107 | },
|
12108 | {
|
12109 | name: "SendTask",
|
12110 | superClass: [
|
12111 | "Task"
|
12112 | ],
|
12113 | properties: [
|
12114 | {
|
12115 | name: "implementation",
|
12116 | isAttr: true,
|
12117 | type: "String"
|
12118 | },
|
12119 | {
|
12120 | name: "operationRef",
|
12121 | type: "Operation",
|
12122 | isAttr: true,
|
12123 | isReference: true
|
12124 | },
|
12125 | {
|
12126 | name: "messageRef",
|
12127 | type: "Message",
|
12128 | isAttr: true,
|
12129 | isReference: true
|
12130 | }
|
12131 | ]
|
12132 | },
|
12133 | {
|
12134 | name: "ReceiveTask",
|
12135 | superClass: [
|
12136 | "Task"
|
12137 | ],
|
12138 | properties: [
|
12139 | {
|
12140 | name: "implementation",
|
12141 | isAttr: true,
|
12142 | type: "String"
|
12143 | },
|
12144 | {
|
12145 | name: "instantiate",
|
12146 | "default": false,
|
12147 | isAttr: true,
|
12148 | type: "Boolean"
|
12149 | },
|
12150 | {
|
12151 | name: "operationRef",
|
12152 | type: "Operation",
|
12153 | isAttr: true,
|
12154 | isReference: true
|
12155 | },
|
12156 | {
|
12157 | name: "messageRef",
|
12158 | type: "Message",
|
12159 | isAttr: true,
|
12160 | isReference: true
|
12161 | }
|
12162 | ]
|
12163 | },
|
12164 | {
|
12165 | name: "ScriptTask",
|
12166 | superClass: [
|
12167 | "Task"
|
12168 | ],
|
12169 | properties: [
|
12170 | {
|
12171 | name: "scriptFormat",
|
12172 | isAttr: true,
|
12173 | type: "String"
|
12174 | },
|
12175 | {
|
12176 | name: "script",
|
12177 | type: "String"
|
12178 | }
|
12179 | ]
|
12180 | },
|
12181 | {
|
12182 | name: "BusinessRuleTask",
|
12183 | superClass: [
|
12184 | "Task"
|
12185 | ],
|
12186 | properties: [
|
12187 | {
|
12188 | name: "implementation",
|
12189 | isAttr: true,
|
12190 | type: "String"
|
12191 | }
|
12192 | ]
|
12193 | },
|
12194 | {
|
12195 | name: "AdHocSubProcess",
|
12196 | superClass: [
|
12197 | "SubProcess"
|
12198 | ],
|
12199 | properties: [
|
12200 | {
|
12201 | name: "completionCondition",
|
12202 | type: "Expression",
|
12203 | xml: {
|
12204 | serialize: "xsi:type"
|
12205 | }
|
12206 | },
|
12207 | {
|
12208 | name: "ordering",
|
12209 | type: "AdHocOrdering",
|
12210 | isAttr: true
|
12211 | },
|
12212 | {
|
12213 | name: "cancelRemainingInstances",
|
12214 | "default": true,
|
12215 | isAttr: true,
|
12216 | type: "Boolean"
|
12217 | }
|
12218 | ]
|
12219 | },
|
12220 | {
|
12221 | name: "Transaction",
|
12222 | superClass: [
|
12223 | "SubProcess"
|
12224 | ],
|
12225 | properties: [
|
12226 | {
|
12227 | name: "protocol",
|
12228 | isAttr: true,
|
12229 | type: "String"
|
12230 | },
|
12231 | {
|
12232 | name: "method",
|
12233 | isAttr: true,
|
12234 | type: "String"
|
12235 | }
|
12236 | ]
|
12237 | },
|
12238 | {
|
12239 | name: "GlobalScriptTask",
|
12240 | superClass: [
|
12241 | "GlobalTask"
|
12242 | ],
|
12243 | properties: [
|
12244 | {
|
12245 | name: "scriptLanguage",
|
12246 | isAttr: true,
|
12247 | type: "String"
|
12248 | },
|
12249 | {
|
12250 | name: "script",
|
12251 | isAttr: true,
|
12252 | type: "String"
|
12253 | }
|
12254 | ]
|
12255 | },
|
12256 | {
|
12257 | name: "GlobalBusinessRuleTask",
|
12258 | superClass: [
|
12259 | "GlobalTask"
|
12260 | ],
|
12261 | properties: [
|
12262 | {
|
12263 | name: "implementation",
|
12264 | isAttr: true,
|
12265 | type: "String"
|
12266 | }
|
12267 | ]
|
12268 | },
|
12269 | {
|
12270 | name: "ComplexBehaviorDefinition",
|
12271 | superClass: [
|
12272 | "BaseElement"
|
12273 | ],
|
12274 | properties: [
|
12275 | {
|
12276 | name: "condition",
|
12277 | type: "FormalExpression"
|
12278 | },
|
12279 | {
|
12280 | name: "event",
|
12281 | type: "ImplicitThrowEvent"
|
12282 | }
|
12283 | ]
|
12284 | },
|
12285 | {
|
12286 | name: "ResourceRole",
|
12287 | superClass: [
|
12288 | "BaseElement"
|
12289 | ],
|
12290 | properties: [
|
12291 | {
|
12292 | name: "resourceRef",
|
12293 | type: "Resource",
|
12294 | isReference: true
|
12295 | },
|
12296 | {
|
12297 | name: "resourceParameterBindings",
|
12298 | type: "ResourceParameterBinding",
|
12299 | isMany: true
|
12300 | },
|
12301 | {
|
12302 | name: "resourceAssignmentExpression",
|
12303 | type: "ResourceAssignmentExpression"
|
12304 | },
|
12305 | {
|
12306 | name: "name",
|
12307 | isAttr: true,
|
12308 | type: "String"
|
12309 | }
|
12310 | ]
|
12311 | },
|
12312 | {
|
12313 | name: "ResourceParameterBinding",
|
12314 | properties: [
|
12315 | {
|
12316 | name: "expression",
|
12317 | type: "Expression",
|
12318 | xml: {
|
12319 | serialize: "xsi:type"
|
12320 | }
|
12321 | },
|
12322 | {
|
12323 | name: "parameterRef",
|
12324 | type: "ResourceParameter",
|
12325 | isAttr: true,
|
12326 | isReference: true
|
12327 | }
|
12328 | ],
|
12329 | superClass: [
|
12330 | "BaseElement"
|
12331 | ]
|
12332 | },
|
12333 | {
|
12334 | name: "ResourceAssignmentExpression",
|
12335 | properties: [
|
12336 | {
|
12337 | name: "expression",
|
12338 | type: "Expression",
|
12339 | xml: {
|
12340 | serialize: "xsi:type"
|
12341 | }
|
12342 | }
|
12343 | ],
|
12344 | superClass: [
|
12345 | "BaseElement"
|
12346 | ]
|
12347 | },
|
12348 | {
|
12349 | name: "Import",
|
12350 | properties: [
|
12351 | {
|
12352 | name: "importType",
|
12353 | isAttr: true,
|
12354 | type: "String"
|
12355 | },
|
12356 | {
|
12357 | name: "location",
|
12358 | isAttr: true,
|
12359 | type: "String"
|
12360 | },
|
12361 | {
|
12362 | name: "namespace",
|
12363 | isAttr: true,
|
12364 | type: "String"
|
12365 | }
|
12366 | ]
|
12367 | },
|
12368 | {
|
12369 | name: "Definitions",
|
12370 | superClass: [
|
12371 | "BaseElement"
|
12372 | ],
|
12373 | properties: [
|
12374 | {
|
12375 | name: "name",
|
12376 | isAttr: true,
|
12377 | type: "String"
|
12378 | },
|
12379 | {
|
12380 | name: "targetNamespace",
|
12381 | isAttr: true,
|
12382 | type: "String"
|
12383 | },
|
12384 | {
|
12385 | name: "expressionLanguage",
|
12386 | "default": "http://www.w3.org/1999/XPath",
|
12387 | isAttr: true,
|
12388 | type: "String"
|
12389 | },
|
12390 | {
|
12391 | name: "typeLanguage",
|
12392 | "default": "http://www.w3.org/2001/XMLSchema",
|
12393 | isAttr: true,
|
12394 | type: "String"
|
12395 | },
|
12396 | {
|
12397 | name: "imports",
|
12398 | type: "Import",
|
12399 | isMany: true
|
12400 | },
|
12401 | {
|
12402 | name: "extensions",
|
12403 | type: "Extension",
|
12404 | isMany: true
|
12405 | },
|
12406 | {
|
12407 | name: "rootElements",
|
12408 | type: "RootElement",
|
12409 | isMany: true
|
12410 | },
|
12411 | {
|
12412 | name: "diagrams",
|
12413 | isMany: true,
|
12414 | type: "bpmndi:BPMNDiagram"
|
12415 | },
|
12416 | {
|
12417 | name: "exporter",
|
12418 | isAttr: true,
|
12419 | type: "String"
|
12420 | },
|
12421 | {
|
12422 | name: "relationships",
|
12423 | type: "Relationship",
|
12424 | isMany: true
|
12425 | },
|
12426 | {
|
12427 | name: "exporterVersion",
|
12428 | isAttr: true,
|
12429 | type: "String"
|
12430 | }
|
12431 | ]
|
12432 | }
|
12433 | ];
|
12434 | var enumerations = [
|
12435 | {
|
12436 | name: "ProcessType",
|
12437 | literalValues: [
|
12438 | {
|
12439 | name: "None"
|
12440 | },
|
12441 | {
|
12442 | name: "Public"
|
12443 | },
|
12444 | {
|
12445 | name: "Private"
|
12446 | }
|
12447 | ]
|
12448 | },
|
12449 | {
|
12450 | name: "GatewayDirection",
|
12451 | literalValues: [
|
12452 | {
|
12453 | name: "Unspecified"
|
12454 | },
|
12455 | {
|
12456 | name: "Converging"
|
12457 | },
|
12458 | {
|
12459 | name: "Diverging"
|
12460 | },
|
12461 | {
|
12462 | name: "Mixed"
|
12463 | }
|
12464 | ]
|
12465 | },
|
12466 | {
|
12467 | name: "EventBasedGatewayType",
|
12468 | literalValues: [
|
12469 | {
|
12470 | name: "Parallel"
|
12471 | },
|
12472 | {
|
12473 | name: "Exclusive"
|
12474 | }
|
12475 | ]
|
12476 | },
|
12477 | {
|
12478 | name: "RelationshipDirection",
|
12479 | literalValues: [
|
12480 | {
|
12481 | name: "None"
|
12482 | },
|
12483 | {
|
12484 | name: "Forward"
|
12485 | },
|
12486 | {
|
12487 | name: "Backward"
|
12488 | },
|
12489 | {
|
12490 | name: "Both"
|
12491 | }
|
12492 | ]
|
12493 | },
|
12494 | {
|
12495 | name: "ItemKind",
|
12496 | literalValues: [
|
12497 | {
|
12498 | name: "Physical"
|
12499 | },
|
12500 | {
|
12501 | name: "Information"
|
12502 | }
|
12503 | ]
|
12504 | },
|
12505 | {
|
12506 | name: "ChoreographyLoopType",
|
12507 | literalValues: [
|
12508 | {
|
12509 | name: "None"
|
12510 | },
|
12511 | {
|
12512 | name: "Standard"
|
12513 | },
|
12514 | {
|
12515 | name: "MultiInstanceSequential"
|
12516 | },
|
12517 | {
|
12518 | name: "MultiInstanceParallel"
|
12519 | }
|
12520 | ]
|
12521 | },
|
12522 | {
|
12523 | name: "AssociationDirection",
|
12524 | literalValues: [
|
12525 | {
|
12526 | name: "None"
|
12527 | },
|
12528 | {
|
12529 | name: "One"
|
12530 | },
|
12531 | {
|
12532 | name: "Both"
|
12533 | }
|
12534 | ]
|
12535 | },
|
12536 | {
|
12537 | name: "MultiInstanceBehavior",
|
12538 | literalValues: [
|
12539 | {
|
12540 | name: "None"
|
12541 | },
|
12542 | {
|
12543 | name: "One"
|
12544 | },
|
12545 | {
|
12546 | name: "All"
|
12547 | },
|
12548 | {
|
12549 | name: "Complex"
|
12550 | }
|
12551 | ]
|
12552 | },
|
12553 | {
|
12554 | name: "AdHocOrdering",
|
12555 | literalValues: [
|
12556 | {
|
12557 | name: "Parallel"
|
12558 | },
|
12559 | {
|
12560 | name: "Sequential"
|
12561 | }
|
12562 | ]
|
12563 | }
|
12564 | ];
|
12565 | var prefix$1 = "bpmn";
|
12566 | var xml = {
|
12567 | tagAlias: "lowerCase",
|
12568 | typePrefix: "t"
|
12569 | };
|
12570 | var BpmnPackage = {
|
12571 | name: name,
|
12572 | uri: uri,
|
12573 | associations: associations,
|
12574 | types: types$1,
|
12575 | enumerations: enumerations,
|
12576 | prefix: prefix$1,
|
12577 | xml: xml
|
12578 | };
|
12579 |
|
12580 | var name$1 = "BPMNDI";
|
12581 | var uri$1 = "http://www.omg.org/spec/BPMN/20100524/DI";
|
12582 | var types$1$1 = [
|
12583 | {
|
12584 | name: "BPMNDiagram",
|
12585 | properties: [
|
12586 | {
|
12587 | name: "plane",
|
12588 | type: "BPMNPlane",
|
12589 | redefines: "di:Diagram#rootElement"
|
12590 | },
|
12591 | {
|
12592 | name: "labelStyle",
|
12593 | type: "BPMNLabelStyle",
|
12594 | isMany: true
|
12595 | }
|
12596 | ],
|
12597 | superClass: [
|
12598 | "di:Diagram"
|
12599 | ]
|
12600 | },
|
12601 | {
|
12602 | name: "BPMNPlane",
|
12603 | properties: [
|
12604 | {
|
12605 | name: "bpmnElement",
|
12606 | isAttr: true,
|
12607 | isReference: true,
|
12608 | type: "bpmn:BaseElement",
|
12609 | redefines: "di:DiagramElement#modelElement"
|
12610 | }
|
12611 | ],
|
12612 | superClass: [
|
12613 | "di:Plane"
|
12614 | ]
|
12615 | },
|
12616 | {
|
12617 | name: "BPMNShape",
|
12618 | properties: [
|
12619 | {
|
12620 | name: "bpmnElement",
|
12621 | isAttr: true,
|
12622 | isReference: true,
|
12623 | type: "bpmn:BaseElement",
|
12624 | redefines: "di:DiagramElement#modelElement"
|
12625 | },
|
12626 | {
|
12627 | name: "isHorizontal",
|
12628 | isAttr: true,
|
12629 | type: "Boolean"
|
12630 | },
|
12631 | {
|
12632 | name: "isExpanded",
|
12633 | isAttr: true,
|
12634 | type: "Boolean"
|
12635 | },
|
12636 | {
|
12637 | name: "isMarkerVisible",
|
12638 | isAttr: true,
|
12639 | type: "Boolean"
|
12640 | },
|
12641 | {
|
12642 | name: "label",
|
12643 | type: "BPMNLabel"
|
12644 | },
|
12645 | {
|
12646 | name: "isMessageVisible",
|
12647 | isAttr: true,
|
12648 | type: "Boolean"
|
12649 | },
|
12650 | {
|
12651 | name: "participantBandKind",
|
12652 | type: "ParticipantBandKind",
|
12653 | isAttr: true
|
12654 | },
|
12655 | {
|
12656 | name: "choreographyActivityShape",
|
12657 | type: "BPMNShape",
|
12658 | isAttr: true,
|
12659 | isReference: true
|
12660 | }
|
12661 | ],
|
12662 | superClass: [
|
12663 | "di:LabeledShape"
|
12664 | ]
|
12665 | },
|
12666 | {
|
12667 | name: "BPMNEdge",
|
12668 | properties: [
|
12669 | {
|
12670 | name: "label",
|
12671 | type: "BPMNLabel"
|
12672 | },
|
12673 | {
|
12674 | name: "bpmnElement",
|
12675 | isAttr: true,
|
12676 | isReference: true,
|
12677 | type: "bpmn:BaseElement",
|
12678 | redefines: "di:DiagramElement#modelElement"
|
12679 | },
|
12680 | {
|
12681 | name: "sourceElement",
|
12682 | isAttr: true,
|
12683 | isReference: true,
|
12684 | type: "di:DiagramElement",
|
12685 | redefines: "di:Edge#source"
|
12686 | },
|
12687 | {
|
12688 | name: "targetElement",
|
12689 | isAttr: true,
|
12690 | isReference: true,
|
12691 | type: "di:DiagramElement",
|
12692 | redefines: "di:Edge#target"
|
12693 | },
|
12694 | {
|
12695 | name: "messageVisibleKind",
|
12696 | type: "MessageVisibleKind",
|
12697 | isAttr: true,
|
12698 | "default": "initiating"
|
12699 | }
|
12700 | ],
|
12701 | superClass: [
|
12702 | "di:LabeledEdge"
|
12703 | ]
|
12704 | },
|
12705 | {
|
12706 | name: "BPMNLabel",
|
12707 | properties: [
|
12708 | {
|
12709 | name: "labelStyle",
|
12710 | type: "BPMNLabelStyle",
|
12711 | isAttr: true,
|
12712 | isReference: true,
|
12713 | redefines: "di:DiagramElement#style"
|
12714 | }
|
12715 | ],
|
12716 | superClass: [
|
12717 | "di:Label"
|
12718 | ]
|
12719 | },
|
12720 | {
|
12721 | name: "BPMNLabelStyle",
|
12722 | properties: [
|
12723 | {
|
12724 | name: "font",
|
12725 | type: "dc:Font"
|
12726 | }
|
12727 | ],
|
12728 | superClass: [
|
12729 | "di:Style"
|
12730 | ]
|
12731 | }
|
12732 | ];
|
12733 | var enumerations$1 = [
|
12734 | {
|
12735 | name: "ParticipantBandKind",
|
12736 | literalValues: [
|
12737 | {
|
12738 | name: "top_initiating"
|
12739 | },
|
12740 | {
|
12741 | name: "middle_initiating"
|
12742 | },
|
12743 | {
|
12744 | name: "bottom_initiating"
|
12745 | },
|
12746 | {
|
12747 | name: "top_non_initiating"
|
12748 | },
|
12749 | {
|
12750 | name: "middle_non_initiating"
|
12751 | },
|
12752 | {
|
12753 | name: "bottom_non_initiating"
|
12754 | }
|
12755 | ]
|
12756 | },
|
12757 | {
|
12758 | name: "MessageVisibleKind",
|
12759 | literalValues: [
|
12760 | {
|
12761 | name: "initiating"
|
12762 | },
|
12763 | {
|
12764 | name: "non_initiating"
|
12765 | }
|
12766 | ]
|
12767 | }
|
12768 | ];
|
12769 | var associations$1 = [
|
12770 | ];
|
12771 | var prefix$1$1 = "bpmndi";
|
12772 | var BpmnDiPackage = {
|
12773 | name: name$1,
|
12774 | uri: uri$1,
|
12775 | types: types$1$1,
|
12776 | enumerations: enumerations$1,
|
12777 | associations: associations$1,
|
12778 | prefix: prefix$1$1
|
12779 | };
|
12780 |
|
12781 | var name$2 = "DC";
|
12782 | var uri$2 = "http://www.omg.org/spec/DD/20100524/DC";
|
12783 | var types$2 = [
|
12784 | {
|
12785 | name: "Boolean"
|
12786 | },
|
12787 | {
|
12788 | name: "Integer"
|
12789 | },
|
12790 | {
|
12791 | name: "Real"
|
12792 | },
|
12793 | {
|
12794 | name: "String"
|
12795 | },
|
12796 | {
|
12797 | name: "Font",
|
12798 | properties: [
|
12799 | {
|
12800 | name: "name",
|
12801 | type: "String",
|
12802 | isAttr: true
|
12803 | },
|
12804 | {
|
12805 | name: "size",
|
12806 | type: "Real",
|
12807 | isAttr: true
|
12808 | },
|
12809 | {
|
12810 | name: "isBold",
|
12811 | type: "Boolean",
|
12812 | isAttr: true
|
12813 | },
|
12814 | {
|
12815 | name: "isItalic",
|
12816 | type: "Boolean",
|
12817 | isAttr: true
|
12818 | },
|
12819 | {
|
12820 | name: "isUnderline",
|
12821 | type: "Boolean",
|
12822 | isAttr: true
|
12823 | },
|
12824 | {
|
12825 | name: "isStrikeThrough",
|
12826 | type: "Boolean",
|
12827 | isAttr: true
|
12828 | }
|
12829 | ]
|
12830 | },
|
12831 | {
|
12832 | name: "Point",
|
12833 | properties: [
|
12834 | {
|
12835 | name: "x",
|
12836 | type: "Real",
|
12837 | "default": "0",
|
12838 | isAttr: true
|
12839 | },
|
12840 | {
|
12841 | name: "y",
|
12842 | type: "Real",
|
12843 | "default": "0",
|
12844 | isAttr: true
|
12845 | }
|
12846 | ]
|
12847 | },
|
12848 | {
|
12849 | name: "Bounds",
|
12850 | properties: [
|
12851 | {
|
12852 | name: "x",
|
12853 | type: "Real",
|
12854 | "default": "0",
|
12855 | isAttr: true
|
12856 | },
|
12857 | {
|
12858 | name: "y",
|
12859 | type: "Real",
|
12860 | "default": "0",
|
12861 | isAttr: true
|
12862 | },
|
12863 | {
|
12864 | name: "width",
|
12865 | type: "Real",
|
12866 | isAttr: true
|
12867 | },
|
12868 | {
|
12869 | name: "height",
|
12870 | type: "Real",
|
12871 | isAttr: true
|
12872 | }
|
12873 | ]
|
12874 | }
|
12875 | ];
|
12876 | var prefix$2 = "dc";
|
12877 | var associations$2 = [
|
12878 | ];
|
12879 | var DcPackage = {
|
12880 | name: name$2,
|
12881 | uri: uri$2,
|
12882 | types: types$2,
|
12883 | prefix: prefix$2,
|
12884 | associations: associations$2
|
12885 | };
|
12886 |
|
12887 | var name$3 = "DI";
|
12888 | var uri$3 = "http://www.omg.org/spec/DD/20100524/DI";
|
12889 | var types$3 = [
|
12890 | {
|
12891 | name: "DiagramElement",
|
12892 | isAbstract: true,
|
12893 | properties: [
|
12894 | {
|
12895 | name: "id",
|
12896 | type: "String",
|
12897 | isAttr: true,
|
12898 | isId: true
|
12899 | },
|
12900 | {
|
12901 | name: "extension",
|
12902 | type: "Extension"
|
12903 | },
|
12904 | {
|
12905 | name: "owningDiagram",
|
12906 | type: "Diagram",
|
12907 | isReadOnly: true,
|
12908 | isVirtual: true,
|
12909 | isReference: true
|
12910 | },
|
12911 | {
|
12912 | name: "owningElement",
|
12913 | type: "DiagramElement",
|
12914 | isReadOnly: true,
|
12915 | isVirtual: true,
|
12916 | isReference: true
|
12917 | },
|
12918 | {
|
12919 | name: "modelElement",
|
12920 | isReadOnly: true,
|
12921 | isVirtual: true,
|
12922 | isReference: true,
|
12923 | type: "Element"
|
12924 | },
|
12925 | {
|
12926 | name: "style",
|
12927 | type: "Style",
|
12928 | isReadOnly: true,
|
12929 | isVirtual: true,
|
12930 | isReference: true
|
12931 | },
|
12932 | {
|
12933 | name: "ownedElement",
|
12934 | type: "DiagramElement",
|
12935 | isReadOnly: true,
|
12936 | isVirtual: true,
|
12937 | isMany: true
|
12938 | }
|
12939 | ]
|
12940 | },
|
12941 | {
|
12942 | name: "Node",
|
12943 | isAbstract: true,
|
12944 | superClass: [
|
12945 | "DiagramElement"
|
12946 | ]
|
12947 | },
|
12948 | {
|
12949 | name: "Edge",
|
12950 | isAbstract: true,
|
12951 | superClass: [
|
12952 | "DiagramElement"
|
12953 | ],
|
12954 | properties: [
|
12955 | {
|
12956 | name: "source",
|
12957 | type: "DiagramElement",
|
12958 | isReadOnly: true,
|
12959 | isVirtual: true,
|
12960 | isReference: true
|
12961 | },
|
12962 | {
|
12963 | name: "target",
|
12964 | type: "DiagramElement",
|
12965 | isReadOnly: true,
|
12966 | isVirtual: true,
|
12967 | isReference: true
|
12968 | },
|
12969 | {
|
12970 | name: "waypoint",
|
12971 | isUnique: false,
|
12972 | isMany: true,
|
12973 | type: "dc:Point",
|
12974 | xml: {
|
12975 | serialize: "xsi:type"
|
12976 | }
|
12977 | }
|
12978 | ]
|
12979 | },
|
12980 | {
|
12981 | name: "Diagram",
|
12982 | isAbstract: true,
|
12983 | properties: [
|
12984 | {
|
12985 | name: "id",
|
12986 | type: "String",
|
12987 | isAttr: true,
|
12988 | isId: true
|
12989 | },
|
12990 | {
|
12991 | name: "rootElement",
|
12992 | type: "DiagramElement",
|
12993 | isReadOnly: true,
|
12994 | isVirtual: true
|
12995 | },
|
12996 | {
|
12997 | name: "name",
|
12998 | isAttr: true,
|
12999 | type: "String"
|
13000 | },
|
13001 | {
|
13002 | name: "documentation",
|
13003 | isAttr: true,
|
13004 | type: "String"
|
13005 | },
|
13006 | {
|
13007 | name: "resolution",
|
13008 | isAttr: true,
|
13009 | type: "Real"
|
13010 | },
|
13011 | {
|
13012 | name: "ownedStyle",
|
13013 | type: "Style",
|
13014 | isReadOnly: true,
|
13015 | isVirtual: true,
|
13016 | isMany: true
|
13017 | }
|
13018 | ]
|
13019 | },
|
13020 | {
|
13021 | name: "Shape",
|
13022 | isAbstract: true,
|
13023 | superClass: [
|
13024 | "Node"
|
13025 | ],
|
13026 | properties: [
|
13027 | {
|
13028 | name: "bounds",
|
13029 | type: "dc:Bounds"
|
13030 | }
|
13031 | ]
|
13032 | },
|
13033 | {
|
13034 | name: "Plane",
|
13035 | isAbstract: true,
|
13036 | superClass: [
|
13037 | "Node"
|
13038 | ],
|
13039 | properties: [
|
13040 | {
|
13041 | name: "planeElement",
|
13042 | type: "DiagramElement",
|
13043 | subsettedProperty: "DiagramElement-ownedElement",
|
13044 | isMany: true
|
13045 | }
|
13046 | ]
|
13047 | },
|
13048 | {
|
13049 | name: "LabeledEdge",
|
13050 | isAbstract: true,
|
13051 | superClass: [
|
13052 | "Edge"
|
13053 | ],
|
13054 | properties: [
|
13055 | {
|
13056 | name: "ownedLabel",
|
13057 | type: "Label",
|
13058 | isReadOnly: true,
|
13059 | subsettedProperty: "DiagramElement-ownedElement",
|
13060 | isVirtual: true,
|
13061 | isMany: true
|
13062 | }
|
13063 | ]
|
13064 | },
|
13065 | {
|
13066 | name: "LabeledShape",
|
13067 | isAbstract: true,
|
13068 | superClass: [
|
13069 | "Shape"
|
13070 | ],
|
13071 | properties: [
|
13072 | {
|
13073 | name: "ownedLabel",
|
13074 | type: "Label",
|
13075 | isReadOnly: true,
|
13076 | subsettedProperty: "DiagramElement-ownedElement",
|
13077 | isVirtual: true,
|
13078 | isMany: true
|
13079 | }
|
13080 | ]
|
13081 | },
|
13082 | {
|
13083 | name: "Label",
|
13084 | isAbstract: true,
|
13085 | superClass: [
|
13086 | "Node"
|
13087 | ],
|
13088 | properties: [
|
13089 | {
|
13090 | name: "bounds",
|
13091 | type: "dc:Bounds"
|
13092 | }
|
13093 | ]
|
13094 | },
|
13095 | {
|
13096 | name: "Style",
|
13097 | isAbstract: true,
|
13098 | properties: [
|
13099 | {
|
13100 | name: "id",
|
13101 | type: "String",
|
13102 | isAttr: true,
|
13103 | isId: true
|
13104 | }
|
13105 | ]
|
13106 | },
|
13107 | {
|
13108 | name: "Extension",
|
13109 | properties: [
|
13110 | {
|
13111 | name: "values",
|
13112 | type: "Element",
|
13113 | isMany: true
|
13114 | }
|
13115 | ]
|
13116 | }
|
13117 | ];
|
13118 | var associations$3 = [
|
13119 | ];
|
13120 | var prefix$3 = "di";
|
13121 | var xml$1 = {
|
13122 | tagAlias: "lowerCase"
|
13123 | };
|
13124 | var DiPackage = {
|
13125 | name: name$3,
|
13126 | uri: uri$3,
|
13127 | types: types$3,
|
13128 | associations: associations$3,
|
13129 | prefix: prefix$3,
|
13130 | xml: xml$1
|
13131 | };
|
13132 |
|
13133 | var name$4 = "bpmn.io colors for BPMN";
|
13134 | var uri$4 = "http://bpmn.io/schema/bpmn/biocolor/1.0";
|
13135 | var prefix$4 = "bioc";
|
13136 | var types$4 = [
|
13137 | {
|
13138 | name: "ColoredShape",
|
13139 | "extends": [
|
13140 | "bpmndi:BPMNShape"
|
13141 | ],
|
13142 | properties: [
|
13143 | {
|
13144 | name: "stroke",
|
13145 | isAttr: true,
|
13146 | type: "String"
|
13147 | },
|
13148 | {
|
13149 | name: "fill",
|
13150 | isAttr: true,
|
13151 | type: "String"
|
13152 | }
|
13153 | ]
|
13154 | },
|
13155 | {
|
13156 | name: "ColoredEdge",
|
13157 | "extends": [
|
13158 | "bpmndi:BPMNEdge"
|
13159 | ],
|
13160 | properties: [
|
13161 | {
|
13162 | name: "stroke",
|
13163 | isAttr: true,
|
13164 | type: "String"
|
13165 | },
|
13166 | {
|
13167 | name: "fill",
|
13168 | isAttr: true,
|
13169 | type: "String"
|
13170 | }
|
13171 | ]
|
13172 | }
|
13173 | ];
|
13174 | var enumerations$2 = [
|
13175 | ];
|
13176 | var associations$4 = [
|
13177 | ];
|
13178 | var BiocPackage = {
|
13179 | name: name$4,
|
13180 | uri: uri$4,
|
13181 | prefix: prefix$4,
|
13182 | types: types$4,
|
13183 | enumerations: enumerations$2,
|
13184 | associations: associations$4
|
13185 | };
|
13186 |
|
13187 | var packages = {
|
13188 | bpmn: BpmnPackage,
|
13189 | bpmndi: BpmnDiPackage,
|
13190 | dc: DcPackage,
|
13191 | di: DiPackage,
|
13192 | bioc: BiocPackage
|
13193 | };
|
13194 |
|
13195 | function simple(additionalPackages, options) {
|
13196 | var pks = assign({}, packages, additionalPackages);
|
13197 |
|
13198 | return new BpmnModdle(pks, options);
|
13199 | }
|
13200 |
|
13201 | function elementToString(e) {
|
13202 | if (!e) {
|
13203 | return '<null>';
|
13204 | }
|
13205 |
|
13206 | return '<' + e.$type + (e.id ? ' id="' + e.id : '') + '" />';
|
13207 | }
|
13208 |
|
13209 | var diRefs = new objectRefs(
|
13210 | { name: 'bpmnElement', enumerable: true },
|
13211 | { name: 'di', configurable: true }
|
13212 | );
|
13213 |
|
13214 | |
13215 |
|
13216 |
|
13217 |
|
13218 |
|
13219 |
|
13220 |
|
13221 |
|
13222 | function is(element, type) {
|
13223 | return element.$instanceOf(type);
|
13224 | }
|
13225 |
|
13226 |
|
13227 | |
13228 |
|
13229 |
|
13230 |
|
13231 | function findDisplayCandidate(definitions) {
|
13232 | return find(definitions.rootElements, function(e) {
|
13233 | return is(e, 'bpmn:Process') || is(e, 'bpmn:Collaboration');
|
13234 | });
|
13235 | }
|
13236 |
|
13237 |
|
13238 | function BpmnTreeWalker(handler, translate) {
|
13239 |
|
13240 |
|
13241 | var handledElements = {};
|
13242 |
|
13243 |
|
13244 |
|
13245 | var deferred = [];
|
13246 |
|
13247 |
|
13248 |
|
13249 | function contextual(fn, ctx) {
|
13250 | return function(e) {
|
13251 | fn(e, ctx);
|
13252 | };
|
13253 | }
|
13254 |
|
13255 | function handled(element) {
|
13256 | handledElements[element.id] = element;
|
13257 | }
|
13258 |
|
13259 | function isHandled(element) {
|
13260 | return handledElements[element.id];
|
13261 | }
|
13262 |
|
13263 | function visit(element, ctx) {
|
13264 |
|
13265 | var gfx = element.gfx;
|
13266 |
|
13267 |
|
13268 | if (gfx) {
|
13269 | throw new Error(
|
13270 | translate('already rendered {element}', { element: elementToString(element) })
|
13271 | );
|
13272 | }
|
13273 |
|
13274 |
|
13275 | return handler.element(element, ctx);
|
13276 | }
|
13277 |
|
13278 | function visitRoot(element, diagram) {
|
13279 | return handler.root(element, diagram);
|
13280 | }
|
13281 |
|
13282 | function visitIfDi(element, ctx) {
|
13283 |
|
13284 | try {
|
13285 | var gfx = element.di && visit(element, ctx);
|
13286 |
|
13287 | handled(element);
|
13288 |
|
13289 | return gfx;
|
13290 | } catch (e) {
|
13291 | logError(e.message, { element: element, error: e });
|
13292 |
|
13293 | console.error(translate('failed to import {element}', { element: elementToString(element) }));
|
13294 | console.error(e);
|
13295 | }
|
13296 | }
|
13297 |
|
13298 | function logError(message, context) {
|
13299 | handler.error(message, context);
|
13300 | }
|
13301 |
|
13302 |
|
13303 |
|
13304 | function registerDi(di) {
|
13305 | var bpmnElement = di.bpmnElement;
|
13306 |
|
13307 | if (bpmnElement) {
|
13308 | if (bpmnElement.di) {
|
13309 | logError(
|
13310 | translate('multiple DI elements defined for {element}', {
|
13311 | element: elementToString(bpmnElement)
|
13312 | }),
|
13313 | { element: bpmnElement }
|
13314 | );
|
13315 | } else {
|
13316 | diRefs.bind(bpmnElement, 'di');
|
13317 | bpmnElement.di = di;
|
13318 | }
|
13319 | } else {
|
13320 | logError(
|
13321 | translate('no bpmnElement referenced in {element}', {
|
13322 | element: elementToString(di)
|
13323 | }),
|
13324 | { element: di }
|
13325 | );
|
13326 | }
|
13327 | }
|
13328 |
|
13329 | function handleDiagram(diagram) {
|
13330 | handlePlane(diagram.plane);
|
13331 | }
|
13332 |
|
13333 | function handlePlane(plane) {
|
13334 | registerDi(plane);
|
13335 |
|
13336 | forEach(plane.planeElement, handlePlaneElement);
|
13337 | }
|
13338 |
|
13339 | function handlePlaneElement(planeElement) {
|
13340 | registerDi(planeElement);
|
13341 | }
|
13342 |
|
13343 |
|
13344 |
|
13345 |
|
13346 | |
13347 |
|
13348 |
|
13349 |
|
13350 |
|
13351 |
|
13352 |
|
13353 |
|
13354 | function handleDefinitions(definitions, diagram) {
|
13355 |
|
13356 |
|
13357 |
|
13358 | var diagrams = definitions.diagrams;
|
13359 |
|
13360 | if (diagram && diagrams.indexOf(diagram) === -1) {
|
13361 | throw new Error(translate('diagram not part of bpmn:Definitions'));
|
13362 | }
|
13363 |
|
13364 | if (!diagram && diagrams && diagrams.length) {
|
13365 | diagram = diagrams[0];
|
13366 | }
|
13367 |
|
13368 |
|
13369 | if (!diagram) {
|
13370 | throw new Error(translate('no diagram to display'));
|
13371 | }
|
13372 |
|
13373 |
|
13374 | handleDiagram(diagram);
|
13375 |
|
13376 |
|
13377 | var plane = diagram.plane;
|
13378 |
|
13379 | if (!plane) {
|
13380 | throw new Error(translate(
|
13381 | 'no plane for {element}',
|
13382 | { element: elementToString(diagram) }
|
13383 | ));
|
13384 | }
|
13385 |
|
13386 | var rootElement = plane.bpmnElement;
|
13387 |
|
13388 |
|
13389 |
|
13390 | if (!rootElement) {
|
13391 | rootElement = findDisplayCandidate(definitions);
|
13392 |
|
13393 | if (!rootElement) {
|
13394 | throw new Error(translate('no process or collaboration to display'));
|
13395 | } else {
|
13396 |
|
13397 | logError(
|
13398 | translate('correcting missing bpmnElement on {plane} to {rootElement}', {
|
13399 | plane: elementToString(plane),
|
13400 | rootElement: elementToString(rootElement)
|
13401 | })
|
13402 | );
|
13403 |
|
13404 |
|
13405 | plane.bpmnElement = rootElement;
|
13406 | registerDi(plane);
|
13407 | }
|
13408 | }
|
13409 |
|
13410 |
|
13411 | var ctx = visitRoot(rootElement, plane);
|
13412 |
|
13413 | if (is(rootElement, 'bpmn:Process')) {
|
13414 | handleProcess(rootElement, ctx);
|
13415 | } else if (is(rootElement, 'bpmn:Collaboration')) {
|
13416 | handleCollaboration(rootElement);
|
13417 |
|
13418 |
|
13419 | handleUnhandledProcesses(definitions.rootElements, ctx);
|
13420 | } else {
|
13421 | throw new Error(
|
13422 | translate('unsupported bpmnElement for {plane}: {rootElement}', {
|
13423 | plane: elementToString(plane),
|
13424 | rootElement: elementToString(rootElement)
|
13425 | })
|
13426 | );
|
13427 | }
|
13428 |
|
13429 |
|
13430 | handleDeferred();
|
13431 | }
|
13432 |
|
13433 | function handleDeferred() {
|
13434 |
|
13435 | var fn;
|
13436 |
|
13437 |
|
13438 | while (deferred.length) {
|
13439 | fn = deferred.shift();
|
13440 |
|
13441 | fn();
|
13442 | }
|
13443 | }
|
13444 |
|
13445 | function handleProcess(process, context) {
|
13446 | handleFlowElementsContainer(process, context);
|
13447 | handleIoSpecification(process.ioSpecification, context);
|
13448 |
|
13449 | handleArtifacts(process.artifacts, context);
|
13450 |
|
13451 |
|
13452 | handled(process);
|
13453 | }
|
13454 |
|
13455 | function handleUnhandledProcesses(rootElements, ctx) {
|
13456 |
|
13457 |
|
13458 |
|
13459 |
|
13460 | var processes = filter(rootElements, function(e) {
|
13461 | return !isHandled(e) && is(e, 'bpmn:Process') && e.laneSets;
|
13462 | });
|
13463 |
|
13464 | processes.forEach(contextual(handleProcess, ctx));
|
13465 | }
|
13466 |
|
13467 | function handleMessageFlow(messageFlow, context) {
|
13468 | visitIfDi(messageFlow, context);
|
13469 | }
|
13470 |
|
13471 | function handleMessageFlows(messageFlows, context) {
|
13472 | forEach(messageFlows, contextual(handleMessageFlow, context));
|
13473 | }
|
13474 |
|
13475 | function handleDataAssociation(association, context) {
|
13476 | visitIfDi(association, context);
|
13477 | }
|
13478 |
|
13479 | function handleDataInput(dataInput, context) {
|
13480 | visitIfDi(dataInput, context);
|
13481 | }
|
13482 |
|
13483 | function handleDataOutput(dataOutput, context) {
|
13484 | visitIfDi(dataOutput, context);
|
13485 | }
|
13486 |
|
13487 | function handleArtifact(artifact, context) {
|
13488 |
|
13489 |
|
13490 |
|
13491 |
|
13492 |
|
13493 | visitIfDi(artifact, context);
|
13494 | }
|
13495 |
|
13496 | function handleArtifacts(artifacts, context) {
|
13497 |
|
13498 | forEach(artifacts, function(e) {
|
13499 | if (is(e, 'bpmn:Association')) {
|
13500 | deferred.push(function() {
|
13501 | handleArtifact(e, context);
|
13502 | });
|
13503 | } else {
|
13504 | handleArtifact(e, context);
|
13505 | }
|
13506 | });
|
13507 | }
|
13508 |
|
13509 | function handleIoSpecification(ioSpecification, context) {
|
13510 |
|
13511 | if (!ioSpecification) {
|
13512 | return;
|
13513 | }
|
13514 |
|
13515 | forEach(ioSpecification.dataInputs, contextual(handleDataInput, context));
|
13516 | forEach(ioSpecification.dataOutputs, contextual(handleDataOutput, context));
|
13517 | }
|
13518 |
|
13519 | function handleSubProcess(subProcess, context) {
|
13520 | handleFlowElementsContainer(subProcess, context);
|
13521 | handleArtifacts(subProcess.artifacts, context);
|
13522 | }
|
13523 |
|
13524 | function handleFlowNode(flowNode, context) {
|
13525 | var childCtx = visitIfDi(flowNode, context);
|
13526 |
|
13527 | if (is(flowNode, 'bpmn:SubProcess')) {
|
13528 | handleSubProcess(flowNode, childCtx || context);
|
13529 | }
|
13530 |
|
13531 | if (is(flowNode, 'bpmn:Activity')) {
|
13532 | handleIoSpecification(flowNode.ioSpecification, context);
|
13533 | }
|
13534 |
|
13535 |
|
13536 |
|
13537 |
|
13538 |
|
13539 |
|
13540 |
|
13541 |
|
13542 | deferred.push(function() {
|
13543 | forEach(flowNode.dataInputAssociations, contextual(handleDataAssociation, context));
|
13544 | forEach(flowNode.dataOutputAssociations, contextual(handleDataAssociation, context));
|
13545 | });
|
13546 | }
|
13547 |
|
13548 | function handleSequenceFlow(sequenceFlow, context) {
|
13549 | visitIfDi(sequenceFlow, context);
|
13550 | }
|
13551 |
|
13552 | function handleDataElement(dataObject, context) {
|
13553 | visitIfDi(dataObject, context);
|
13554 | }
|
13555 |
|
13556 | function handleLane(lane, context) {
|
13557 |
|
13558 | deferred.push(function() {
|
13559 |
|
13560 | var newContext = visitIfDi(lane, context);
|
13561 |
|
13562 | if (lane.childLaneSet) {
|
13563 | handleLaneSet(lane.childLaneSet, newContext || context);
|
13564 | }
|
13565 |
|
13566 | wireFlowNodeRefs(lane);
|
13567 | });
|
13568 | }
|
13569 |
|
13570 | function handleLaneSet(laneSet, context) {
|
13571 | forEach(laneSet.lanes, contextual(handleLane, context));
|
13572 | }
|
13573 |
|
13574 | function handleLaneSets(laneSets, context) {
|
13575 | forEach(laneSets, contextual(handleLaneSet, context));
|
13576 | }
|
13577 |
|
13578 | function handleFlowElementsContainer(container, context) {
|
13579 | handleFlowElements(container.flowElements, context);
|
13580 |
|
13581 | if (container.laneSets) {
|
13582 | handleLaneSets(container.laneSets, context);
|
13583 | }
|
13584 | }
|
13585 |
|
13586 | function handleFlowElements(flowElements, context) {
|
13587 | forEach(flowElements, function(e) {
|
13588 | if (is(e, 'bpmn:SequenceFlow')) {
|
13589 | deferred.push(function() {
|
13590 | handleSequenceFlow(e, context);
|
13591 | });
|
13592 | } else if (is(e, 'bpmn:BoundaryEvent')) {
|
13593 | deferred.unshift(function() {
|
13594 | handleFlowNode(e, context);
|
13595 | });
|
13596 | } else if (is(e, 'bpmn:FlowNode')) {
|
13597 | handleFlowNode(e, context);
|
13598 | } else if (is(e, 'bpmn:DataObject')) ; else if (is(e, 'bpmn:DataStoreReference')) {
|
13599 | handleDataElement(e, context);
|
13600 | } else if (is(e, 'bpmn:DataObjectReference')) {
|
13601 | handleDataElement(e, context);
|
13602 | } else {
|
13603 | logError(
|
13604 | translate('unrecognized flowElement {element} in context {context}', {
|
13605 | element: elementToString(e),
|
13606 | context: (context ? elementToString(context.businessObject) : 'null')
|
13607 | }),
|
13608 | { element: e, context: context }
|
13609 | );
|
13610 | }
|
13611 | });
|
13612 | }
|
13613 |
|
13614 | function handleParticipant(participant, context) {
|
13615 | var newCtx = visitIfDi(participant, context);
|
13616 |
|
13617 | var process = participant.processRef;
|
13618 | if (process) {
|
13619 | handleProcess(process, newCtx || context);
|
13620 | }
|
13621 | }
|
13622 |
|
13623 | function handleCollaboration(collaboration) {
|
13624 |
|
13625 | forEach(collaboration.participants, contextual(handleParticipant));
|
13626 |
|
13627 | handleArtifacts(collaboration.artifacts);
|
13628 |
|
13629 |
|
13630 | deferred.push(function() {
|
13631 | handleMessageFlows(collaboration.messageFlows);
|
13632 | });
|
13633 | }
|
13634 |
|
13635 |
|
13636 | function wireFlowNodeRefs(lane) {
|
13637 |
|
13638 |
|
13639 | forEach(lane.flowNodeRef, function(flowNode) {
|
13640 | var lanes = flowNode.get('lanes');
|
13641 |
|
13642 | if (lanes) {
|
13643 | lanes.push(lane);
|
13644 | }
|
13645 | });
|
13646 | }
|
13647 |
|
13648 |
|
13649 |
|
13650 | return {
|
13651 | handleDeferred: handleDeferred,
|
13652 | handleDefinitions: handleDefinitions,
|
13653 | handleSubProcess: handleSubProcess,
|
13654 | registerDi: registerDi
|
13655 | };
|
13656 | }
|
13657 |
|
13658 | |
13659 |
|
13660 |
|
13661 |
|
13662 |
|
13663 |
|
13664 |
|
13665 |
|
13666 |
|
13667 |
|
13668 |
|
13669 | function importBpmnDiagram(diagram, definitions, bpmnDiagram, done) {
|
13670 |
|
13671 | if (isFunction(bpmnDiagram)) {
|
13672 | done = bpmnDiagram;
|
13673 | bpmnDiagram = null;
|
13674 | }
|
13675 |
|
13676 | var importer,
|
13677 | eventBus,
|
13678 | translate;
|
13679 |
|
13680 | var error,
|
13681 | warnings = [];
|
13682 |
|
13683 | |
13684 |
|
13685 |
|
13686 |
|
13687 |
|
13688 |
|
13689 |
|
13690 | function render(definitions, bpmnDiagram) {
|
13691 |
|
13692 | var visitor = {
|
13693 |
|
13694 | root: function(element) {
|
13695 | return importer.add(element);
|
13696 | },
|
13697 |
|
13698 | element: function(element, parentShape) {
|
13699 | return importer.add(element, parentShape);
|
13700 | },
|
13701 |
|
13702 | error: function(message, context) {
|
13703 | warnings.push({ message: message, context: context });
|
13704 | }
|
13705 | };
|
13706 |
|
13707 | var walker = new BpmnTreeWalker(visitor, translate);
|
13708 |
|
13709 |
|
13710 |
|
13711 | walker.handleDefinitions(definitions, bpmnDiagram);
|
13712 | }
|
13713 |
|
13714 | try {
|
13715 | importer = diagram.get('bpmnImporter');
|
13716 | eventBus = diagram.get('eventBus');
|
13717 | translate = diagram.get('translate');
|
13718 |
|
13719 | eventBus.fire('import.render.start', { definitions: definitions });
|
13720 |
|
13721 | render(definitions, bpmnDiagram);
|
13722 |
|
13723 | eventBus.fire('import.render.complete', {
|
13724 | error: error,
|
13725 | warnings: warnings
|
13726 | });
|
13727 | } catch (e) {
|
13728 | error = e;
|
13729 | }
|
13730 |
|
13731 | done(error, warnings);
|
13732 | }
|
13733 |
|
13734 | |
13735 |
|
13736 |
|
13737 |
|
13738 |
|
13739 |
|
13740 |
|
13741 |
|
13742 | 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>';
|
13743 |
|
13744 | var BPMNIO_LOGO_URL = 'data:image/svg+xml,' + encodeURIComponent(BPMNIO_LOGO_SVG);
|
13745 |
|
13746 | var BPMNIO_IMG = '<img width="52" height="52" src="' + BPMNIO_LOGO_URL + '" />';
|
13747 |
|
13748 | function css(attrs) {
|
13749 | return attrs.join(';');
|
13750 | }
|
13751 |
|
13752 | var LIGHTBOX_STYLES = css([
|
13753 | 'z-index: 1001',
|
13754 | 'position: fixed',
|
13755 | 'top: 0',
|
13756 | 'left: 0',
|
13757 | 'right: 0',
|
13758 | 'bottom: 0'
|
13759 | ]);
|
13760 |
|
13761 | var BACKDROP_STYLES = css([
|
13762 | 'width: 100%',
|
13763 | 'height: 100%',
|
13764 | 'background: rgba(0,0,0,0.2)'
|
13765 | ]);
|
13766 |
|
13767 | var NOTICE_STYLES = css([
|
13768 | 'position: absolute',
|
13769 | 'left: 50%',
|
13770 | 'top: 40%',
|
13771 | 'margin: 0 -130px',
|
13772 | 'width: 260px',
|
13773 | 'padding: 10px',
|
13774 | 'background: white',
|
13775 | 'border: solid 1px #AAA',
|
13776 | 'border-radius: 3px',
|
13777 | 'font-family: Helvetica, Arial, sans-serif',
|
13778 | 'font-size: 14px',
|
13779 | 'line-height: 1.2em'
|
13780 | ]);
|
13781 |
|
13782 | var LIGHTBOX_MARKUP =
|
13783 | '<div class="bjs-powered-by-lightbox" style="' + LIGHTBOX_STYLES + '">' +
|
13784 | '<div class="backdrop" style="' + BACKDROP_STYLES + '"></div>' +
|
13785 | '<div class="notice" style="' + NOTICE_STYLES + '">' +
|
13786 | '<a href="http://bpmn.io" target="_blank" style="float: left; margin-right: 10px">' +
|
13787 | BPMNIO_IMG +
|
13788 | '</a>' +
|
13789 | 'Web-based tooling for BPMN, DMN and CMMN diagrams ' +
|
13790 | 'powered by <a href="http://bpmn.io" target="_blank">bpmn.io</a>.' +
|
13791 | '</div>' +
|
13792 | '</div>';
|
13793 |
|
13794 |
|
13795 | var lightbox;
|
13796 |
|
13797 | function open() {
|
13798 |
|
13799 | if (!lightbox) {
|
13800 | lightbox = domify(LIGHTBOX_MARKUP);
|
13801 |
|
13802 | delegateEvents.bind(lightbox, '.backdrop', 'click', function(event) {
|
13803 | document.body.removeChild(lightbox);
|
13804 | });
|
13805 | }
|
13806 |
|
13807 | document.body.appendChild(lightbox);
|
13808 | }
|
13809 |
|
13810 | |
13811 |
|
13812 |
|
13813 |
|
13814 |
|
13815 |
|
13816 |
|
13817 |
|
13818 | |
13819 |
|
13820 |
|
13821 |
|
13822 |
|
13823 |
|
13824 |
|
13825 |
|
13826 |
|
13827 |
|
13828 |
|
13829 |
|
13830 |
|
13831 |
|
13832 | function BaseViewer(options) {
|
13833 |
|
13834 | options = assign({}, DEFAULT_OPTIONS, options);
|
13835 |
|
13836 | this._moddle = this._createModdle(options);
|
13837 |
|
13838 | this._container = this._createContainer(options);
|
13839 |
|
13840 |
|
13841 |
|
13842 | addProjectLogo(this._container);
|
13843 |
|
13844 |
|
13845 |
|
13846 | this._init(this._container, this._moddle, options);
|
13847 | }
|
13848 |
|
13849 | inherits_browser(BaseViewer, Diagram);
|
13850 |
|
13851 |
|
13852 | |
13853 |
|
13854 |
|
13855 |
|
13856 |
|
13857 |
|
13858 |
|
13859 |
|
13860 |
|
13861 |
|
13862 |
|
13863 |
|
13864 |
|
13865 |
|
13866 |
|
13867 |
|
13868 |
|
13869 |
|
13870 |
|
13871 |
|
13872 |
|
13873 |
|
13874 | BaseViewer.prototype.importXML = function(xml, bpmnDiagram, done) {
|
13875 |
|
13876 | if (isFunction(bpmnDiagram)) {
|
13877 | done = bpmnDiagram;
|
13878 | bpmnDiagram = null;
|
13879 | }
|
13880 |
|
13881 |
|
13882 | done = done || function() {};
|
13883 |
|
13884 | var self = this;
|
13885 |
|
13886 |
|
13887 |
|
13888 | xml = this._emit('import.parse.start', { xml: xml }) || xml;
|
13889 |
|
13890 | this._moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions, context) {
|
13891 |
|
13892 |
|
13893 |
|
13894 | definitions = self._emit('import.parse.complete', {
|
13895 | error: err,
|
13896 | definitions: definitions,
|
13897 | context: context
|
13898 | }) || definitions;
|
13899 |
|
13900 | var parseWarnings = context.warnings;
|
13901 |
|
13902 | if (err) {
|
13903 | err = checkValidationError(err);
|
13904 |
|
13905 | self._emit('import.done', { error: err, warnings: parseWarnings });
|
13906 |
|
13907 | return done(err, parseWarnings);
|
13908 | }
|
13909 |
|
13910 | self.importDefinitions(definitions, bpmnDiagram, function(err, importWarnings) {
|
13911 | var allWarnings = [].concat(parseWarnings, importWarnings || []);
|
13912 |
|
13913 | self._emit('import.done', { error: err, warnings: allWarnings });
|
13914 |
|
13915 | done(err, allWarnings);
|
13916 | });
|
13917 | });
|
13918 | };
|
13919 |
|
13920 | |
13921 |
|
13922 |
|
13923 |
|
13924 |
|
13925 |
|
13926 |
|
13927 |
|
13928 |
|
13929 |
|
13930 |
|
13931 |
|
13932 |
|
13933 |
|
13934 |
|
13935 |
|
13936 |
|
13937 |
|
13938 |
|
13939 | BaseViewer.prototype.importDefinitions = function(definitions, bpmnDiagram, done) {
|
13940 |
|
13941 | if (isFunction(bpmnDiagram)) {
|
13942 | done = bpmnDiagram;
|
13943 | bpmnDiagram = null;
|
13944 | }
|
13945 |
|
13946 |
|
13947 | done = done || function() {};
|
13948 |
|
13949 | this._setDefinitions(definitions);
|
13950 |
|
13951 | return this.open(bpmnDiagram, done);
|
13952 | };
|
13953 |
|
13954 | |
13955 |
|
13956 |
|
13957 |
|
13958 |
|
13959 |
|
13960 |
|
13961 |
|
13962 |
|
13963 |
|
13964 |
|
13965 |
|
13966 |
|
13967 |
|
13968 |
|
13969 |
|
13970 |
|
13971 |
|
13972 | BaseViewer.prototype.open = function(bpmnDiagramOrId, done) {
|
13973 |
|
13974 | if (isFunction(bpmnDiagramOrId)) {
|
13975 | done = bpmnDiagramOrId;
|
13976 | bpmnDiagramOrId = null;
|
13977 | }
|
13978 |
|
13979 | var definitions = this._definitions;
|
13980 | var bpmnDiagram = bpmnDiagramOrId;
|
13981 |
|
13982 |
|
13983 | done = done || function() {};
|
13984 |
|
13985 | if (!definitions) {
|
13986 | return done(new Error('no XML imported'));
|
13987 | }
|
13988 |
|
13989 | if (typeof bpmnDiagramOrId === 'string') {
|
13990 | bpmnDiagram = findBPMNDiagram(definitions, bpmnDiagramOrId);
|
13991 |
|
13992 | if (!bpmnDiagram) {
|
13993 | return done(new Error('BPMNDiagram <' + bpmnDiagramOrId + '> not found'));
|
13994 | }
|
13995 | }
|
13996 |
|
13997 |
|
13998 |
|
13999 | try {
|
14000 | this.clear();
|
14001 | } catch (error) {
|
14002 | return done(error);
|
14003 | }
|
14004 |
|
14005 |
|
14006 | return importBpmnDiagram(this, definitions, bpmnDiagram, done);
|
14007 | };
|
14008 |
|
14009 | |
14010 |
|
14011 |
|
14012 |
|
14013 |
|
14014 |
|
14015 |
|
14016 |
|
14017 |
|
14018 |
|
14019 |
|
14020 |
|
14021 |
|
14022 |
|
14023 |
|
14024 |
|
14025 |
|
14026 |
|
14027 |
|
14028 |
|
14029 | BaseViewer.prototype.saveXML = function(options, done) {
|
14030 |
|
14031 | if (!done) {
|
14032 | done = options;
|
14033 | options = {};
|
14034 | }
|
14035 |
|
14036 | var self = this;
|
14037 |
|
14038 | var definitions = this._definitions;
|
14039 |
|
14040 | if (!definitions) {
|
14041 | return done(new Error('no definitions loaded'));
|
14042 | }
|
14043 |
|
14044 |
|
14045 | definitions = this._emit('saveXML.start', {
|
14046 | definitions: definitions
|
14047 | }) || definitions;
|
14048 |
|
14049 | this._moddle.toXML(definitions, options, function(err, xml) {
|
14050 |
|
14051 | try {
|
14052 | xml = self._emit('saveXML.serialized', {
|
14053 | error: err,
|
14054 | xml: xml
|
14055 | }) || xml;
|
14056 |
|
14057 | self._emit('saveXML.done', {
|
14058 | error: err,
|
14059 | xml: xml
|
14060 | });
|
14061 | } catch (e) {
|
14062 | console.error('error in saveXML life-cycle listener', e);
|
14063 | }
|
14064 |
|
14065 | done(err, xml);
|
14066 | });
|
14067 | };
|
14068 |
|
14069 | |
14070 |
|
14071 |
|
14072 |
|
14073 |
|
14074 |
|
14075 |
|
14076 |
|
14077 |
|
14078 |
|
14079 |
|
14080 |
|
14081 |
|
14082 |
|
14083 |
|
14084 |
|
14085 | BaseViewer.prototype.saveSVG = function(options, done) {
|
14086 |
|
14087 | if (!done) {
|
14088 | done = options;
|
14089 | options = {};
|
14090 | }
|
14091 |
|
14092 | this._emit('saveSVG.start');
|
14093 |
|
14094 | var svg, err;
|
14095 |
|
14096 | try {
|
14097 | var canvas = this.get('canvas');
|
14098 |
|
14099 | var contentNode = canvas.getDefaultLayer(),
|
14100 | defsNode = query('defs', canvas._svg);
|
14101 |
|
14102 | var contents = innerSVG(contentNode),
|
14103 | defs = defsNode ? '<defs>' + innerSVG(defsNode) + '</defs>' : '';
|
14104 |
|
14105 | var bbox = contentNode.getBBox();
|
14106 |
|
14107 | svg =
|
14108 | '<?xml version="1.0" encoding="utf-8"?>\n' +
|
14109 | '<!-- created with bpmn-js / http://bpmn.io -->\n' +
|
14110 | '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
|
14111 | '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +
|
14112 | 'width="' + bbox.width + '" height="' + bbox.height + '" ' +
|
14113 | 'viewBox="' + bbox.x + ' ' + bbox.y + ' ' + bbox.width + ' ' + bbox.height + '" version="1.1">' +
|
14114 | defs + contents +
|
14115 | '</svg>';
|
14116 | } catch (e) {
|
14117 | err = e;
|
14118 | }
|
14119 |
|
14120 | this._emit('saveSVG.done', {
|
14121 | error: err,
|
14122 | svg: svg
|
14123 | });
|
14124 |
|
14125 | done(err, svg);
|
14126 | };
|
14127 |
|
14128 | |
14129 |
|
14130 |
|
14131 |
|
14132 |
|
14133 |
|
14134 |
|
14135 |
|
14136 |
|
14137 |
|
14138 |
|
14139 |
|
14140 |
|
14141 |
|
14142 |
|
14143 | |
14144 |
|
14145 |
|
14146 |
|
14147 |
|
14148 |
|
14149 |
|
14150 |
|
14151 |
|
14152 |
|
14153 |
|
14154 |
|
14155 |
|
14156 |
|
14157 |
|
14158 |
|
14159 |
|
14160 | BaseViewer.prototype._setDefinitions = function(definitions) {
|
14161 | this._definitions = definitions;
|
14162 | };
|
14163 |
|
14164 | BaseViewer.prototype.getModules = function() {
|
14165 | return this._modules;
|
14166 | };
|
14167 |
|
14168 | |
14169 |
|
14170 |
|
14171 |
|
14172 |
|
14173 |
|
14174 |
|
14175 |
|
14176 | BaseViewer.prototype.clear = function() {
|
14177 | if (!this.getDefinitions()) {
|
14178 |
|
14179 |
|
14180 | return;
|
14181 | }
|
14182 |
|
14183 |
|
14184 |
|
14185 |
|
14186 |
|
14187 |
|
14188 | this.get('elementRegistry').forEach(function(element) {
|
14189 | var bo = element.businessObject;
|
14190 |
|
14191 | if (bo && bo.di) {
|
14192 | delete bo.di;
|
14193 | }
|
14194 | });
|
14195 |
|
14196 |
|
14197 | Diagram.prototype.clear.call(this);
|
14198 | };
|
14199 |
|
14200 | |
14201 |
|
14202 |
|
14203 |
|
14204 | BaseViewer.prototype.destroy = function() {
|
14205 |
|
14206 |
|
14207 | Diagram.prototype.destroy.call(this);
|
14208 |
|
14209 |
|
14210 | remove(this._container);
|
14211 | };
|
14212 |
|
14213 | |
14214 |
|
14215 |
|
14216 |
|
14217 |
|
14218 |
|
14219 |
|
14220 |
|
14221 |
|
14222 |
|
14223 | BaseViewer.prototype.on = function(event, priority, callback, target) {
|
14224 | return this.get('eventBus').on(event, priority, callback, target);
|
14225 | };
|
14226 |
|
14227 | |
14228 |
|
14229 |
|
14230 |
|
14231 |
|
14232 |
|
14233 | BaseViewer.prototype.off = function(event, callback) {
|
14234 | this.get('eventBus').off(event, callback);
|
14235 | };
|
14236 |
|
14237 | BaseViewer.prototype.attachTo = function(parentNode) {
|
14238 |
|
14239 | if (!parentNode) {
|
14240 | throw new Error('parentNode required');
|
14241 | }
|
14242 |
|
14243 |
|
14244 |
|
14245 | this.detach();
|
14246 |
|
14247 |
|
14248 | if (parentNode.get && parentNode.constructor.prototype.jquery) {
|
14249 | parentNode = parentNode.get(0);
|
14250 | }
|
14251 |
|
14252 | if (typeof parentNode === 'string') {
|
14253 | parentNode = query(parentNode);
|
14254 | }
|
14255 |
|
14256 | parentNode.appendChild(this._container);
|
14257 |
|
14258 | this._emit('attach', {});
|
14259 |
|
14260 | this.get('canvas').resized();
|
14261 | };
|
14262 |
|
14263 | BaseViewer.prototype.getDefinitions = function() {
|
14264 | return this._definitions;
|
14265 | };
|
14266 |
|
14267 | BaseViewer.prototype.detach = function() {
|
14268 |
|
14269 | var container = this._container,
|
14270 | parentNode = container.parentNode;
|
14271 |
|
14272 | if (!parentNode) {
|
14273 | return;
|
14274 | }
|
14275 |
|
14276 | this._emit('detach', {});
|
14277 |
|
14278 | parentNode.removeChild(container);
|
14279 | };
|
14280 |
|
14281 | BaseViewer.prototype._init = function(container, moddle, options) {
|
14282 |
|
14283 | var baseModules = options.modules || this.getModules(),
|
14284 | additionalModules = options.additionalModules || [],
|
14285 | staticModules = [
|
14286 | {
|
14287 | bpmnjs: [ 'value', this ],
|
14288 | moddle: [ 'value', moddle ]
|
14289 | }
|
14290 | ];
|
14291 |
|
14292 | var diagramModules = [].concat(staticModules, baseModules, additionalModules);
|
14293 |
|
14294 | var diagramOptions = assign(omit(options, [ 'additionalModules' ]), {
|
14295 | canvas: assign({}, options.canvas, { container: container }),
|
14296 | modules: diagramModules
|
14297 | });
|
14298 |
|
14299 |
|
14300 | Diagram.call(this, diagramOptions);
|
14301 |
|
14302 | if (options && options.container) {
|
14303 | this.attachTo(options.container);
|
14304 | }
|
14305 | };
|
14306 |
|
14307 | |
14308 |
|
14309 |
|
14310 |
|
14311 |
|
14312 |
|
14313 |
|
14314 |
|
14315 | BaseViewer.prototype._emit = function(type, event) {
|
14316 | return this.get('eventBus').fire(type, event);
|
14317 | };
|
14318 |
|
14319 | BaseViewer.prototype._createContainer = function(options) {
|
14320 |
|
14321 | var container = domify('<div class="bjs-container"></div>');
|
14322 |
|
14323 | assign(container.style, {
|
14324 | width: ensureUnit(options.width),
|
14325 | height: ensureUnit(options.height),
|
14326 | position: options.position
|
14327 | });
|
14328 |
|
14329 | return container;
|
14330 | };
|
14331 |
|
14332 | BaseViewer.prototype._createModdle = function(options) {
|
14333 | var moddleOptions = assign({}, this._moddleExtensions, options.moddleExtensions);
|
14334 |
|
14335 | return new simple(moddleOptions);
|
14336 | };
|
14337 |
|
14338 | BaseViewer.prototype._modules = [];
|
14339 |
|
14340 |
|
14341 |
|
14342 |
|
14343 | function checkValidationError(err) {
|
14344 |
|
14345 |
|
14346 |
|
14347 |
|
14348 | var pattern = /unparsable content <([^>]+)> detected([\s\S]*)$/;
|
14349 | var match = pattern.exec(err.message);
|
14350 |
|
14351 | if (match) {
|
14352 | err.message =
|
14353 | 'unparsable content <' + match[1] + '> detected; ' +
|
14354 | 'this may indicate an invalid BPMN 2.0 diagram file' + match[2];
|
14355 | }
|
14356 |
|
14357 | return err;
|
14358 | }
|
14359 |
|
14360 | var DEFAULT_OPTIONS = {
|
14361 | width: '100%',
|
14362 | height: '100%',
|
14363 | position: 'relative'
|
14364 | };
|
14365 |
|
14366 |
|
14367 | |
14368 |
|
14369 |
|
14370 | function ensureUnit(val) {
|
14371 | return val + (isNumber(val) ? 'px' : '');
|
14372 | }
|
14373 |
|
14374 |
|
14375 | |
14376 |
|
14377 |
|
14378 |
|
14379 |
|
14380 |
|
14381 |
|
14382 |
|
14383 | function findBPMNDiagram(definitions, diagramId) {
|
14384 | if (!diagramId) {
|
14385 | return null;
|
14386 | }
|
14387 |
|
14388 | return find(definitions.diagrams, function(element) {
|
14389 | return element.id === diagramId;
|
14390 | }) || null;
|
14391 | }
|
14392 |
|
14393 | |
14394 |
|
14395 |
|
14396 |
|
14397 |
|
14398 |
|
14399 |
|
14400 |
|
14401 | function addProjectLogo(container) {
|
14402 | var img = BPMNIO_IMG;
|
14403 |
|
14404 | var linkMarkup =
|
14405 | '<a href="http://bpmn.io" ' +
|
14406 | 'target="_blank" ' +
|
14407 | 'class="bjs-powered-by" ' +
|
14408 | 'title="Powered by bpmn.io" ' +
|
14409 | 'style="position: absolute; bottom: 15px; right: 15px; z-index: 100">' +
|
14410 | img +
|
14411 | '</a>';
|
14412 |
|
14413 | var linkElement = domify(linkMarkup);
|
14414 |
|
14415 | container.appendChild(linkElement);
|
14416 |
|
14417 | componentEvent.bind(linkElement, 'click', function(event) {
|
14418 | open();
|
14419 |
|
14420 | event.preventDefault();
|
14421 | });
|
14422 | }
|
14423 |
|
14424 |
|
14425 |
|
14426 | |
14427 |
|
14428 |
|
14429 |
|
14430 |
|
14431 |
|
14432 |
|
14433 |
|
14434 |
|
14435 |
|
14436 |
|
14437 |
|
14438 |
|
14439 | function BaseModeler(options) {
|
14440 | BaseViewer.call(this, options);
|
14441 |
|
14442 |
|
14443 | this.on('import.parse.complete', function(event) {
|
14444 | if (!event.error) {
|
14445 | this._collectIds(event.definitions, event.context);
|
14446 | }
|
14447 | }, this);
|
14448 |
|
14449 | this.on('diagram.destroy', function() {
|
14450 | this.get('moddle').ids.clear();
|
14451 | }, this);
|
14452 | }
|
14453 |
|
14454 | inherits_browser(BaseModeler, BaseViewer);
|
14455 |
|
14456 |
|
14457 | |
14458 |
|
14459 |
|
14460 |
|
14461 |
|
14462 | BaseModeler.prototype._createModdle = function(options) {
|
14463 | var moddle = BaseViewer.prototype._createModdle.call(this, options);
|
14464 |
|
14465 |
|
14466 |
|
14467 |
|
14468 | moddle.ids = new Ids([ 32, 36, 1 ]);
|
14469 |
|
14470 | return moddle;
|
14471 | };
|
14472 |
|
14473 | |
14474 |
|
14475 |
|
14476 |
|
14477 |
|
14478 |
|
14479 |
|
14480 | BaseModeler.prototype._collectIds = function(definitions, context) {
|
14481 |
|
14482 | var moddle = definitions.$model,
|
14483 | ids = moddle.ids,
|
14484 | id;
|
14485 |
|
14486 |
|
14487 | ids.clear();
|
14488 |
|
14489 | for (id in context.elementsById) {
|
14490 | ids.claim(id, context.elementsById[id]);
|
14491 | }
|
14492 | };
|
14493 |
|
14494 | |
14495 |
|
14496 |
|
14497 |
|
14498 |
|
14499 |
|
14500 |
|
14501 |
|
14502 | function is$1(element, type) {
|
14503 | var bo = getBusinessObject(element);
|
14504 |
|
14505 | return bo && (typeof bo.$instanceOf === 'function') && bo.$instanceOf(type);
|
14506 | }
|
14507 |
|
14508 |
|
14509 | |
14510 |
|
14511 |
|
14512 |
|
14513 |
|
14514 |
|
14515 |
|
14516 | function getBusinessObject(element) {
|
14517 | return (element && element.businessObject) || element;
|
14518 | }
|
14519 |
|
14520 | function isExpanded(element) {
|
14521 |
|
14522 | if (is$1(element, 'bpmn:CallActivity')) {
|
14523 | return false;
|
14524 | }
|
14525 |
|
14526 | if (is$1(element, 'bpmn:SubProcess')) {
|
14527 | return !!getBusinessObject(element).di.isExpanded;
|
14528 | }
|
14529 |
|
14530 | if (is$1(element, 'bpmn:Participant')) {
|
14531 | return !!getBusinessObject(element).processRef;
|
14532 | }
|
14533 |
|
14534 | return true;
|
14535 | }
|
14536 |
|
14537 | function isInterrupting(element) {
|
14538 | return element && getBusinessObject(element).isInterrupting !== false;
|
14539 | }
|
14540 |
|
14541 | function isEventSubProcess(element) {
|
14542 | return element && !!getBusinessObject(element).triggeredByEvent;
|
14543 | }
|
14544 |
|
14545 | function hasEventDefinition(element, eventType) {
|
14546 | var bo = getBusinessObject(element),
|
14547 | hasEventDefinition = false;
|
14548 |
|
14549 | if (bo.eventDefinitions) {
|
14550 | forEach(bo.eventDefinitions, function(event) {
|
14551 | if (is$1(event, eventType)) {
|
14552 | hasEventDefinition = true;
|
14553 | }
|
14554 | });
|
14555 | }
|
14556 |
|
14557 | return hasEventDefinition;
|
14558 | }
|
14559 |
|
14560 | function hasErrorEventDefinition(element) {
|
14561 | return hasEventDefinition(element, 'bpmn:ErrorEventDefinition');
|
14562 | }
|
14563 |
|
14564 | function hasEscalationEventDefinition(element) {
|
14565 | return hasEventDefinition(element, 'bpmn:EscalationEventDefinition');
|
14566 | }
|
14567 |
|
14568 | function hasCompensateEventDefinition(element) {
|
14569 | return hasEventDefinition(element, 'bpmn:CompensateEventDefinition');
|
14570 | }
|
14571 |
|
14572 | function getLabelAttr(semantic) {
|
14573 | if (
|
14574 | is$1(semantic, 'bpmn:FlowElement') ||
|
14575 | is$1(semantic, 'bpmn:Participant') ||
|
14576 | is$1(semantic, 'bpmn:Lane') ||
|
14577 | is$1(semantic, 'bpmn:SequenceFlow') ||
|
14578 | is$1(semantic, 'bpmn:MessageFlow') ||
|
14579 | is$1(semantic, 'bpmn:DataInput') ||
|
14580 | is$1(semantic, 'bpmn:DataOutput')
|
14581 | ) {
|
14582 | return 'name';
|
14583 | }
|
14584 |
|
14585 | if (is$1(semantic, 'bpmn:TextAnnotation')) {
|
14586 | return 'text';
|
14587 | }
|
14588 |
|
14589 | if (is$1(semantic, 'bpmn:Group')) {
|
14590 | return 'categoryValueRef';
|
14591 | }
|
14592 | }
|
14593 |
|
14594 | function getCategoryValue(semantic) {
|
14595 | var categoryValueRef = semantic['categoryValueRef'];
|
14596 |
|
14597 | if (!categoryValueRef) {
|
14598 | return '';
|
14599 | }
|
14600 |
|
14601 |
|
14602 | return categoryValueRef.value || '';
|
14603 | }
|
14604 |
|
14605 | function getLabel(element) {
|
14606 | var semantic = element.businessObject,
|
14607 | attr = getLabelAttr(semantic);
|
14608 |
|
14609 | if (attr) {
|
14610 |
|
14611 | if (attr === 'categoryValueRef') {
|
14612 |
|
14613 | return getCategoryValue(semantic);
|
14614 | }
|
14615 |
|
14616 | return semantic[attr] || '';
|
14617 | }
|
14618 | }
|
14619 |
|
14620 |
|
14621 | function setLabel(element, text, isExternal) {
|
14622 | var semantic = element.businessObject,
|
14623 | attr = getLabelAttr(semantic);
|
14624 |
|
14625 | if (attr) {
|
14626 |
|
14627 | if (attr === 'categoryValueRef') {
|
14628 | semantic['categoryValueRef'].value = text;
|
14629 | } else {
|
14630 | semantic[attr] = text;
|
14631 | }
|
14632 |
|
14633 | }
|
14634 |
|
14635 | return element;
|
14636 | }
|
14637 |
|
14638 |
|
14639 |
|
14640 | |
14641 |
|
14642 |
|
14643 |
|
14644 |
|
14645 | function isTypedEvent(event, eventDefinitionType, filter) {
|
14646 |
|
14647 | function matches(definition, filter) {
|
14648 | return every(filter, function(val, key) {
|
14649 |
|
14650 |
|
14651 |
|
14652 |
|
14653 | return definition[key] == val;
|
14654 | });
|
14655 | }
|
14656 |
|
14657 | return some(event.eventDefinitions, function(definition) {
|
14658 | return definition.$type === eventDefinitionType && matches(event, filter);
|
14659 | });
|
14660 | }
|
14661 |
|
14662 | function isThrowEvent(event) {
|
14663 | return (event.$type === 'bpmn:IntermediateThrowEvent') || (event.$type === 'bpmn:EndEvent');
|
14664 | }
|
14665 |
|
14666 | function isCollection(element) {
|
14667 | var dataObject = element.dataObjectRef;
|
14668 |
|
14669 | return element.isCollection || (dataObject && dataObject.isCollection);
|
14670 | }
|
14671 |
|
14672 | function getDi(element) {
|
14673 | return element.businessObject.di;
|
14674 | }
|
14675 |
|
14676 | function getSemantic(element) {
|
14677 | return element.businessObject;
|
14678 | }
|
14679 |
|
14680 |
|
14681 |
|
14682 |
|
14683 | function getFillColor(element, defaultColor) {
|
14684 | return getDi(element).get('bioc:fill') || defaultColor || 'white';
|
14685 | }
|
14686 |
|
14687 | function getStrokeColor(element, defaultColor) {
|
14688 | return getDi(element).get('bioc:stroke') || defaultColor || 'black';
|
14689 | }
|
14690 |
|
14691 |
|
14692 |
|
14693 |
|
14694 | function getCirclePath(shape) {
|
14695 |
|
14696 | var cx = shape.x + shape.width / 2,
|
14697 | cy = shape.y + shape.height / 2,
|
14698 | radius = shape.width / 2;
|
14699 |
|
14700 | var circlePath = [
|
14701 | ['M', cx, cy],
|
14702 | ['m', 0, -radius],
|
14703 | ['a', radius, radius, 0, 1, 1, 0, 2 * radius],
|
14704 | ['a', radius, radius, 0, 1, 1, 0, -2 * radius],
|
14705 | ['z']
|
14706 | ];
|
14707 |
|
14708 | return componentsToPath(circlePath);
|
14709 | }
|
14710 |
|
14711 | function getRoundRectPath(shape, borderRadius) {
|
14712 |
|
14713 | var x = shape.x,
|
14714 | y = shape.y,
|
14715 | width = shape.width,
|
14716 | height = shape.height;
|
14717 |
|
14718 | var roundRectPath = [
|
14719 | ['M', x + borderRadius, y],
|
14720 | ['l', width - borderRadius * 2, 0],
|
14721 | ['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, borderRadius],
|
14722 | ['l', 0, height - borderRadius * 2],
|
14723 | ['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, borderRadius],
|
14724 | ['l', borderRadius * 2 - width, 0],
|
14725 | ['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, -borderRadius],
|
14726 | ['l', 0, borderRadius * 2 - height],
|
14727 | ['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, -borderRadius],
|
14728 | ['z']
|
14729 | ];
|
14730 |
|
14731 | return componentsToPath(roundRectPath);
|
14732 | }
|
14733 |
|
14734 | function getDiamondPath(shape) {
|
14735 |
|
14736 | var width = shape.width,
|
14737 | height = shape.height,
|
14738 | x = shape.x,
|
14739 | y = shape.y,
|
14740 | halfWidth = width / 2,
|
14741 | halfHeight = height / 2;
|
14742 |
|
14743 | var diamondPath = [
|
14744 | ['M', x + halfWidth, y],
|
14745 | ['l', halfWidth, halfHeight],
|
14746 | ['l', -halfWidth, halfHeight],
|
14747 | ['l', -halfWidth, -halfHeight],
|
14748 | ['z']
|
14749 | ];
|
14750 |
|
14751 | return componentsToPath(diamondPath);
|
14752 | }
|
14753 |
|
14754 | function getRectPath(shape) {
|
14755 | var x = shape.x,
|
14756 | y = shape.y,
|
14757 | width = shape.width,
|
14758 | height = shape.height;
|
14759 |
|
14760 | var rectPath = [
|
14761 | ['M', x, y],
|
14762 | ['l', width, 0],
|
14763 | ['l', 0, height],
|
14764 | ['l', -width, 0],
|
14765 | ['z']
|
14766 | ];
|
14767 |
|
14768 | return componentsToPath(rectPath);
|
14769 | }
|
14770 |
|
14771 | var RENDERER_IDS = new Ids();
|
14772 |
|
14773 | var TASK_BORDER_RADIUS = 10;
|
14774 | var INNER_OUTER_DIST = 3;
|
14775 |
|
14776 | var DEFAULT_FILL_OPACITY = .95,
|
14777 | HIGH_FILL_OPACITY = .35;
|
14778 |
|
14779 |
|
14780 | function BpmnRenderer(
|
14781 | config, eventBus, styles, pathMap,
|
14782 | canvas, textRenderer, priority) {
|
14783 |
|
14784 | BaseRenderer.call(this, eventBus, priority);
|
14785 |
|
14786 | var defaultFillColor = config && config.defaultFillColor,
|
14787 | defaultStrokeColor = config && config.defaultStrokeColor;
|
14788 |
|
14789 | var rendererId = RENDERER_IDS.next();
|
14790 |
|
14791 | var markers = {};
|
14792 |
|
14793 | var computeStyle = styles.computeStyle;
|
14794 |
|
14795 | function addMarker(id, options) {
|
14796 | var attrs = assign({
|
14797 | fill: 'black',
|
14798 | strokeWidth: 1,
|
14799 | strokeLinecap: 'round',
|
14800 | strokeDasharray: 'none'
|
14801 | }, options.attrs);
|
14802 |
|
14803 | var ref = options.ref || { x: 0, y: 0 };
|
14804 |
|
14805 | var scale = options.scale || 1;
|
14806 |
|
14807 |
|
14808 |
|
14809 | if (attrs.strokeDasharray === 'none') {
|
14810 | attrs.strokeDasharray = [10000, 1];
|
14811 | }
|
14812 |
|
14813 | var marker = create('marker');
|
14814 |
|
14815 | attr$1(options.element, attrs);
|
14816 |
|
14817 | append(marker, options.element);
|
14818 |
|
14819 | attr$1(marker, {
|
14820 | id: id,
|
14821 | viewBox: '0 0 20 20',
|
14822 | refX: ref.x,
|
14823 | refY: ref.y,
|
14824 | markerWidth: 20 * scale,
|
14825 | markerHeight: 20 * scale,
|
14826 | orient: 'auto'
|
14827 | });
|
14828 |
|
14829 | var defs = query('defs', canvas._svg);
|
14830 |
|
14831 | if (!defs) {
|
14832 | defs = create('defs');
|
14833 |
|
14834 | append(canvas._svg, defs);
|
14835 | }
|
14836 |
|
14837 | append(defs, marker);
|
14838 |
|
14839 | markers[id] = marker;
|
14840 | }
|
14841 |
|
14842 | function colorEscape(str) {
|
14843 |
|
14844 |
|
14845 | return str.replace(/[^0-9a-zA-z]+/g, '_');
|
14846 | }
|
14847 |
|
14848 | function marker(type, fill, stroke) {
|
14849 | var id = type + '-' + colorEscape(fill) + '-' + colorEscape(stroke) + '-' + rendererId;
|
14850 |
|
14851 | if (!markers[id]) {
|
14852 | createMarker(id, type, fill, stroke);
|
14853 | }
|
14854 |
|
14855 | return 'url(#' + id + ')';
|
14856 | }
|
14857 |
|
14858 | function createMarker(id, type, fill, stroke) {
|
14859 |
|
14860 | if (type === 'sequenceflow-end') {
|
14861 | var sequenceflowEnd = create('path');
|
14862 | attr$1(sequenceflowEnd, { d: 'M 1 5 L 11 10 L 1 15 Z' });
|
14863 |
|
14864 | addMarker(id, {
|
14865 | element: sequenceflowEnd,
|
14866 | ref: { x: 11, y: 10 },
|
14867 | scale: 0.5,
|
14868 | attrs: {
|
14869 | fill: stroke,
|
14870 | stroke: stroke
|
14871 | }
|
14872 | });
|
14873 | }
|
14874 |
|
14875 | if (type === 'messageflow-start') {
|
14876 | var messageflowStart = create('circle');
|
14877 | attr$1(messageflowStart, { cx: 6, cy: 6, r: 3.5 });
|
14878 |
|
14879 | addMarker(id, {
|
14880 | element: messageflowStart,
|
14881 | attrs: {
|
14882 | fill: fill,
|
14883 | stroke: stroke
|
14884 | },
|
14885 | ref: { x: 6, y: 6 }
|
14886 | });
|
14887 | }
|
14888 |
|
14889 | if (type === 'messageflow-end') {
|
14890 | var messageflowEnd = create('path');
|
14891 | attr$1(messageflowEnd, { d: 'm 1 5 l 0 -3 l 7 3 l -7 3 z' });
|
14892 |
|
14893 | addMarker(id, {
|
14894 | element: messageflowEnd,
|
14895 | attrs: {
|
14896 | fill: fill,
|
14897 | stroke: stroke,
|
14898 | strokeLinecap: 'butt'
|
14899 | },
|
14900 | ref: { x: 8.5, y: 5 }
|
14901 | });
|
14902 | }
|
14903 |
|
14904 | if (type === 'association-start') {
|
14905 | var associationStart = create('path');
|
14906 | attr$1(associationStart, { d: 'M 11 5 L 1 10 L 11 15' });
|
14907 |
|
14908 | addMarker(id, {
|
14909 | element: associationStart,
|
14910 | attrs: {
|
14911 | fill: 'none',
|
14912 | stroke: stroke,
|
14913 | strokeWidth: 1.5
|
14914 | },
|
14915 | ref: { x: 1, y: 10 },
|
14916 | scale: 0.5
|
14917 | });
|
14918 | }
|
14919 |
|
14920 | if (type === 'association-end') {
|
14921 | var associationEnd = create('path');
|
14922 | attr$1(associationEnd, { d: 'M 1 5 L 11 10 L 1 15' });
|
14923 |
|
14924 | addMarker(id, {
|
14925 | element: associationEnd,
|
14926 | attrs: {
|
14927 | fill: 'none',
|
14928 | stroke: stroke,
|
14929 | strokeWidth: 1.5
|
14930 | },
|
14931 | ref: { x: 12, y: 10 },
|
14932 | scale: 0.5
|
14933 | });
|
14934 | }
|
14935 |
|
14936 | if (type === 'conditional-flow-marker') {
|
14937 | var conditionalflowMarker = create('path');
|
14938 | attr$1(conditionalflowMarker, { d: 'M 0 10 L 8 6 L 16 10 L 8 14 Z' });
|
14939 |
|
14940 | addMarker(id, {
|
14941 | element: conditionalflowMarker,
|
14942 | attrs: {
|
14943 | fill: fill,
|
14944 | stroke: stroke
|
14945 | },
|
14946 | ref: { x: -1, y: 10 },
|
14947 | scale: 0.5
|
14948 | });
|
14949 | }
|
14950 |
|
14951 | if (type === 'conditional-default-flow-marker') {
|
14952 | var conditionaldefaultflowMarker = create('path');
|
14953 | attr$1(conditionaldefaultflowMarker, { d: 'M 6 4 L 10 16' });
|
14954 |
|
14955 | addMarker(id, {
|
14956 | element: conditionaldefaultflowMarker,
|
14957 | attrs: {
|
14958 | stroke: stroke
|
14959 | },
|
14960 | ref: { x: 0, y: 10 },
|
14961 | scale: 0.5
|
14962 | });
|
14963 | }
|
14964 | }
|
14965 |
|
14966 | function drawCircle(parentGfx, width, height, offset, attrs) {
|
14967 |
|
14968 | if (isObject(offset)) {
|
14969 | attrs = offset;
|
14970 | offset = 0;
|
14971 | }
|
14972 |
|
14973 | offset = offset || 0;
|
14974 |
|
14975 | attrs = computeStyle(attrs, {
|
14976 | stroke: 'black',
|
14977 | strokeWidth: 2,
|
14978 | fill: 'white'
|
14979 | });
|
14980 |
|
14981 | if (attrs.fill === 'none') {
|
14982 | delete attrs.fillOpacity;
|
14983 | }
|
14984 |
|
14985 | var cx = width / 2,
|
14986 | cy = height / 2;
|
14987 |
|
14988 | var circle = create('circle');
|
14989 | attr$1(circle, {
|
14990 | cx: cx,
|
14991 | cy: cy,
|
14992 | r: Math.round((width + height) / 4 - offset)
|
14993 | });
|
14994 | attr$1(circle, attrs);
|
14995 |
|
14996 | append(parentGfx, circle);
|
14997 |
|
14998 | return circle;
|
14999 | }
|
15000 |
|
15001 | function drawRect(parentGfx, width, height, r, offset, attrs) {
|
15002 |
|
15003 | if (isObject(offset)) {
|
15004 | attrs = offset;
|
15005 | offset = 0;
|
15006 | }
|
15007 |
|
15008 | offset = offset || 0;
|
15009 |
|
15010 | attrs = computeStyle(attrs, {
|
15011 | stroke: 'black',
|
15012 | strokeWidth: 2,
|
15013 | fill: 'white'
|
15014 | });
|
15015 |
|
15016 | var rect = create('rect');
|
15017 | attr$1(rect, {
|
15018 | x: offset,
|
15019 | y: offset,
|
15020 | width: width - offset * 2,
|
15021 | height: height - offset * 2,
|
15022 | rx: r,
|
15023 | ry: r
|
15024 | });
|
15025 | attr$1(rect, attrs);
|
15026 |
|
15027 | append(parentGfx, rect);
|
15028 |
|
15029 | return rect;
|
15030 | }
|
15031 |
|
15032 | function drawDiamond(parentGfx, width, height, attrs) {
|
15033 |
|
15034 | var x_2 = width / 2;
|
15035 | var y_2 = height / 2;
|
15036 |
|
15037 | var points = [{ x: x_2, y: 0 }, { x: width, y: y_2 }, { x: x_2, y: height }, { x: 0, y: y_2 }];
|
15038 |
|
15039 | var pointsString = points.map(function(point) {
|
15040 | return point.x + ',' + point.y;
|
15041 | }).join(' ');
|
15042 |
|
15043 | attrs = computeStyle(attrs, {
|
15044 | stroke: 'black',
|
15045 | strokeWidth: 2,
|
15046 | fill: 'white'
|
15047 | });
|
15048 |
|
15049 | var polygon = create('polygon');
|
15050 | attr$1(polygon, {
|
15051 | points: pointsString
|
15052 | });
|
15053 | attr$1(polygon, attrs);
|
15054 |
|
15055 | append(parentGfx, polygon);
|
15056 |
|
15057 | return polygon;
|
15058 | }
|
15059 |
|
15060 | function drawLine(parentGfx, waypoints, attrs) {
|
15061 | attrs = computeStyle(attrs, [ 'no-fill' ], {
|
15062 | stroke: 'black',
|
15063 | strokeWidth: 2,
|
15064 | fill: 'none'
|
15065 | });
|
15066 |
|
15067 | var line = createLine(waypoints, attrs);
|
15068 |
|
15069 | append(parentGfx, line);
|
15070 |
|
15071 | return line;
|
15072 | }
|
15073 |
|
15074 | function drawPath(parentGfx, d, attrs) {
|
15075 |
|
15076 | attrs = computeStyle(attrs, [ 'no-fill' ], {
|
15077 | strokeWidth: 2,
|
15078 | stroke: 'black'
|
15079 | });
|
15080 |
|
15081 | var path = create('path');
|
15082 | attr$1(path, { d: d });
|
15083 | attr$1(path, attrs);
|
15084 |
|
15085 | append(parentGfx, path);
|
15086 |
|
15087 | return path;
|
15088 | }
|
15089 |
|
15090 | function drawMarker(type, parentGfx, path, attrs) {
|
15091 | return drawPath(parentGfx, path, assign({ 'data-marker': type }, attrs));
|
15092 | }
|
15093 |
|
15094 | function as(type) {
|
15095 | return function(parentGfx, element) {
|
15096 | return handlers[type](parentGfx, element);
|
15097 | };
|
15098 | }
|
15099 |
|
15100 | function renderer(type) {
|
15101 | return handlers[type];
|
15102 | }
|
15103 |
|
15104 | function renderEventContent(element, parentGfx) {
|
15105 |
|
15106 | var event = getSemantic(element);
|
15107 | var isThrowing = isThrowEvent(event);
|
15108 |
|
15109 | if (event.eventDefinitions && event.eventDefinitions.length>1) {
|
15110 | if (event.parallelMultiple) {
|
15111 | return renderer('bpmn:ParallelMultipleEventDefinition')(parentGfx, element, isThrowing);
|
15112 | }
|
15113 | else {
|
15114 | return renderer('bpmn:MultipleEventDefinition')(parentGfx, element, isThrowing);
|
15115 | }
|
15116 | }
|
15117 |
|
15118 | if (isTypedEvent(event, 'bpmn:MessageEventDefinition')) {
|
15119 | return renderer('bpmn:MessageEventDefinition')(parentGfx, element, isThrowing);
|
15120 | }
|
15121 |
|
15122 | if (isTypedEvent(event, 'bpmn:TimerEventDefinition')) {
|
15123 | return renderer('bpmn:TimerEventDefinition')(parentGfx, element, isThrowing);
|
15124 | }
|
15125 |
|
15126 | if (isTypedEvent(event, 'bpmn:ConditionalEventDefinition')) {
|
15127 | return renderer('bpmn:ConditionalEventDefinition')(parentGfx, element);
|
15128 | }
|
15129 |
|
15130 | if (isTypedEvent(event, 'bpmn:SignalEventDefinition')) {
|
15131 | return renderer('bpmn:SignalEventDefinition')(parentGfx, element, isThrowing);
|
15132 | }
|
15133 |
|
15134 | if (isTypedEvent(event, 'bpmn:EscalationEventDefinition')) {
|
15135 | return renderer('bpmn:EscalationEventDefinition')(parentGfx, element, isThrowing);
|
15136 | }
|
15137 |
|
15138 | if (isTypedEvent(event, 'bpmn:LinkEventDefinition')) {
|
15139 | return renderer('bpmn:LinkEventDefinition')(parentGfx, element, isThrowing);
|
15140 | }
|
15141 |
|
15142 | if (isTypedEvent(event, 'bpmn:ErrorEventDefinition')) {
|
15143 | return renderer('bpmn:ErrorEventDefinition')(parentGfx, element, isThrowing);
|
15144 | }
|
15145 |
|
15146 | if (isTypedEvent(event, 'bpmn:CancelEventDefinition')) {
|
15147 | return renderer('bpmn:CancelEventDefinition')(parentGfx, element, isThrowing);
|
15148 | }
|
15149 |
|
15150 | if (isTypedEvent(event, 'bpmn:CompensateEventDefinition')) {
|
15151 | return renderer('bpmn:CompensateEventDefinition')(parentGfx, element, isThrowing);
|
15152 | }
|
15153 |
|
15154 | if (isTypedEvent(event, 'bpmn:TerminateEventDefinition')) {
|
15155 | return renderer('bpmn:TerminateEventDefinition')(parentGfx, element, isThrowing);
|
15156 | }
|
15157 |
|
15158 | return null;
|
15159 | }
|
15160 |
|
15161 | function renderLabel(parentGfx, label, options) {
|
15162 |
|
15163 | options = assign({
|
15164 | size: {
|
15165 | width: 100
|
15166 | }
|
15167 | }, options);
|
15168 |
|
15169 | var text = textRenderer.createText(label || '', options);
|
15170 |
|
15171 | classes$1(text).add('djs-label');
|
15172 |
|
15173 | append(parentGfx, text);
|
15174 |
|
15175 | return text;
|
15176 | }
|
15177 |
|
15178 | function renderEmbeddedLabel(parentGfx, element, align) {
|
15179 | var semantic = getSemantic(element);
|
15180 |
|
15181 | return renderLabel(parentGfx, semantic.name, {
|
15182 | box: element,
|
15183 | align: align,
|
15184 | padding: 5,
|
15185 | style: {
|
15186 | fill: getStrokeColor(element, defaultStrokeColor)
|
15187 | }
|
15188 | });
|
15189 | }
|
15190 |
|
15191 | function renderExternalLabel(parentGfx, element) {
|
15192 |
|
15193 | var box = {
|
15194 | width: 90,
|
15195 | height: 30,
|
15196 | x: element.width / 2 + element.x,
|
15197 | y: element.height / 2 + element.y
|
15198 | };
|
15199 |
|
15200 | return renderLabel(parentGfx, getLabel(element), {
|
15201 | box: box,
|
15202 | fitBox: true,
|
15203 | style: assign(
|
15204 | {},
|
15205 | textRenderer.getExternalStyle(),
|
15206 | {
|
15207 | fill: getStrokeColor(element, defaultStrokeColor)
|
15208 | }
|
15209 | )
|
15210 | });
|
15211 | }
|
15212 |
|
15213 | function renderLaneLabel(parentGfx, text, element) {
|
15214 | var textBox = renderLabel(parentGfx, text, {
|
15215 | box: {
|
15216 | height: 30,
|
15217 | width: element.height
|
15218 | },
|
15219 | align: 'center-middle',
|
15220 | style: {
|
15221 | fill: getStrokeColor(element, defaultStrokeColor)
|
15222 | }
|
15223 | });
|
15224 |
|
15225 | var top = -1 * element.height;
|
15226 |
|
15227 | transform$1(textBox, 0, -top, 270);
|
15228 | }
|
15229 |
|
15230 | function createPathFromConnection(connection) {
|
15231 | var waypoints = connection.waypoints;
|
15232 |
|
15233 | var pathData = 'm ' + waypoints[0].x + ',' + waypoints[0].y;
|
15234 | for (var i = 1; i < waypoints.length; i++) {
|
15235 | pathData += 'L' + waypoints[i].x + ',' + waypoints[i].y + ' ';
|
15236 | }
|
15237 | return pathData;
|
15238 | }
|
15239 |
|
15240 | var handlers = this.handlers = {
|
15241 | 'bpmn:Event': function(parentGfx, element, attrs) {
|
15242 |
|
15243 | if (!('fillOpacity' in attrs)) {
|
15244 | attrs.fillOpacity = DEFAULT_FILL_OPACITY;
|
15245 | }
|
15246 |
|
15247 | return drawCircle(parentGfx, element.width, element.height, attrs);
|
15248 | },
|
15249 | 'bpmn:StartEvent': function(parentGfx, element) {
|
15250 | var attrs = {
|
15251 | fill: getFillColor(element, defaultFillColor),
|
15252 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15253 | };
|
15254 |
|
15255 | var semantic = getSemantic(element);
|
15256 |
|
15257 | if (!semantic.isInterrupting) {
|
15258 | attrs = {
|
15259 | strokeDasharray: '6',
|
15260 | strokeLinecap: 'round',
|
15261 | fill: getFillColor(element, defaultFillColor),
|
15262 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15263 | };
|
15264 | }
|
15265 |
|
15266 | var circle = renderer('bpmn:Event')(parentGfx, element, attrs);
|
15267 |
|
15268 | renderEventContent(element, parentGfx);
|
15269 |
|
15270 | return circle;
|
15271 | },
|
15272 | 'bpmn:MessageEventDefinition': function(parentGfx, element, isThrowing) {
|
15273 | var pathData = pathMap.getScaledPath('EVENT_MESSAGE', {
|
15274 | xScaleFactor: 0.9,
|
15275 | yScaleFactor: 0.9,
|
15276 | containerWidth: element.width,
|
15277 | containerHeight: element.height,
|
15278 | position: {
|
15279 | mx: 0.235,
|
15280 | my: 0.315
|
15281 | }
|
15282 | });
|
15283 |
|
15284 | var fill = isThrowing ? getStrokeColor(element, defaultStrokeColor) : getFillColor(element, defaultFillColor);
|
15285 | var stroke = isThrowing ? getFillColor(element, defaultFillColor) : getStrokeColor(element, defaultStrokeColor);
|
15286 |
|
15287 | var messagePath = drawPath(parentGfx, pathData, {
|
15288 | strokeWidth: 1,
|
15289 | fill: fill,
|
15290 | stroke: stroke
|
15291 | });
|
15292 |
|
15293 | return messagePath;
|
15294 | },
|
15295 | 'bpmn:TimerEventDefinition': function(parentGfx, element) {
|
15296 | var circle = drawCircle(parentGfx, element.width, element.height, 0.2 * element.height, {
|
15297 | strokeWidth: 2,
|
15298 | fill: getFillColor(element, defaultFillColor),
|
15299 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15300 | });
|
15301 |
|
15302 | var pathData = pathMap.getScaledPath('EVENT_TIMER_WH', {
|
15303 | xScaleFactor: 0.75,
|
15304 | yScaleFactor: 0.75,
|
15305 | containerWidth: element.width,
|
15306 | containerHeight: element.height,
|
15307 | position: {
|
15308 | mx: 0.5,
|
15309 | my: 0.5
|
15310 | }
|
15311 | });
|
15312 |
|
15313 | drawPath(parentGfx, pathData, {
|
15314 | strokeWidth: 2,
|
15315 | strokeLinecap: 'square',
|
15316 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15317 | });
|
15318 |
|
15319 | for (var i = 0;i < 12; i++) {
|
15320 |
|
15321 | var linePathData = pathMap.getScaledPath('EVENT_TIMER_LINE', {
|
15322 | xScaleFactor: 0.75,
|
15323 | yScaleFactor: 0.75,
|
15324 | containerWidth: element.width,
|
15325 | containerHeight: element.height,
|
15326 | position: {
|
15327 | mx: 0.5,
|
15328 | my: 0.5
|
15329 | }
|
15330 | });
|
15331 |
|
15332 | var width = element.width / 2;
|
15333 | var height = element.height / 2;
|
15334 |
|
15335 | drawPath(parentGfx, linePathData, {
|
15336 | strokeWidth: 1,
|
15337 | strokeLinecap: 'square',
|
15338 | transform: 'rotate(' + (i * 30) + ',' + height + ',' + width + ')',
|
15339 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15340 | });
|
15341 | }
|
15342 |
|
15343 | return circle;
|
15344 | },
|
15345 | 'bpmn:EscalationEventDefinition': function(parentGfx, event, isThrowing) {
|
15346 | var pathData = pathMap.getScaledPath('EVENT_ESCALATION', {
|
15347 | xScaleFactor: 1,
|
15348 | yScaleFactor: 1,
|
15349 | containerWidth: event.width,
|
15350 | containerHeight: event.height,
|
15351 | position: {
|
15352 | mx: 0.5,
|
15353 | my: 0.2
|
15354 | }
|
15355 | });
|
15356 |
|
15357 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
15358 |
|
15359 | return drawPath(parentGfx, pathData, {
|
15360 | strokeWidth: 1,
|
15361 | fill: fill,
|
15362 | stroke: getStrokeColor(event, defaultStrokeColor)
|
15363 | });
|
15364 | },
|
15365 | 'bpmn:ConditionalEventDefinition': function(parentGfx, event) {
|
15366 | var pathData = pathMap.getScaledPath('EVENT_CONDITIONAL', {
|
15367 | xScaleFactor: 1,
|
15368 | yScaleFactor: 1,
|
15369 | containerWidth: event.width,
|
15370 | containerHeight: event.height,
|
15371 | position: {
|
15372 | mx: 0.5,
|
15373 | my: 0.222
|
15374 | }
|
15375 | });
|
15376 |
|
15377 | return drawPath(parentGfx, pathData, {
|
15378 | strokeWidth: 1,
|
15379 | stroke: getStrokeColor(event, defaultStrokeColor)
|
15380 | });
|
15381 | },
|
15382 | 'bpmn:LinkEventDefinition': function(parentGfx, event, isThrowing) {
|
15383 | var pathData = pathMap.getScaledPath('EVENT_LINK', {
|
15384 | xScaleFactor: 1,
|
15385 | yScaleFactor: 1,
|
15386 | containerWidth: event.width,
|
15387 | containerHeight: event.height,
|
15388 | position: {
|
15389 | mx: 0.57,
|
15390 | my: 0.263
|
15391 | }
|
15392 | });
|
15393 |
|
15394 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
15395 |
|
15396 | return drawPath(parentGfx, pathData, {
|
15397 | strokeWidth: 1,
|
15398 | fill: fill,
|
15399 | stroke: getStrokeColor(event, defaultStrokeColor)
|
15400 | });
|
15401 | },
|
15402 | 'bpmn:ErrorEventDefinition': function(parentGfx, event, isThrowing) {
|
15403 | var pathData = pathMap.getScaledPath('EVENT_ERROR', {
|
15404 | xScaleFactor: 1.1,
|
15405 | yScaleFactor: 1.1,
|
15406 | containerWidth: event.width,
|
15407 | containerHeight: event.height,
|
15408 | position: {
|
15409 | mx: 0.2,
|
15410 | my: 0.722
|
15411 | }
|
15412 | });
|
15413 |
|
15414 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
15415 |
|
15416 | return drawPath(parentGfx, pathData, {
|
15417 | strokeWidth: 1,
|
15418 | fill: fill,
|
15419 | stroke: getStrokeColor(event, defaultStrokeColor)
|
15420 | });
|
15421 | },
|
15422 | 'bpmn:CancelEventDefinition': function(parentGfx, event, isThrowing) {
|
15423 | var pathData = pathMap.getScaledPath('EVENT_CANCEL_45', {
|
15424 | xScaleFactor: 1.0,
|
15425 | yScaleFactor: 1.0,
|
15426 | containerWidth: event.width,
|
15427 | containerHeight: event.height,
|
15428 | position: {
|
15429 | mx: 0.638,
|
15430 | my: -0.055
|
15431 | }
|
15432 | });
|
15433 |
|
15434 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
15435 |
|
15436 | var path = drawPath(parentGfx, pathData, {
|
15437 | strokeWidth: 1,
|
15438 | fill: fill,
|
15439 | stroke: getStrokeColor(event, defaultStrokeColor)
|
15440 | });
|
15441 |
|
15442 | rotate(path, 45);
|
15443 |
|
15444 | return path;
|
15445 | },
|
15446 | 'bpmn:CompensateEventDefinition': function(parentGfx, event, isThrowing) {
|
15447 | var pathData = pathMap.getScaledPath('EVENT_COMPENSATION', {
|
15448 | xScaleFactor: 1,
|
15449 | yScaleFactor: 1,
|
15450 | containerWidth: event.width,
|
15451 | containerHeight: event.height,
|
15452 | position: {
|
15453 | mx: 0.22,
|
15454 | my: 0.5
|
15455 | }
|
15456 | });
|
15457 |
|
15458 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
15459 |
|
15460 | return drawPath(parentGfx, pathData, {
|
15461 | strokeWidth: 1,
|
15462 | fill: fill,
|
15463 | stroke: getStrokeColor(event, defaultStrokeColor)
|
15464 | });
|
15465 | },
|
15466 | 'bpmn:SignalEventDefinition': function(parentGfx, event, isThrowing) {
|
15467 | var pathData = pathMap.getScaledPath('EVENT_SIGNAL', {
|
15468 | xScaleFactor: 0.9,
|
15469 | yScaleFactor: 0.9,
|
15470 | containerWidth: event.width,
|
15471 | containerHeight: event.height,
|
15472 | position: {
|
15473 | mx: 0.5,
|
15474 | my: 0.2
|
15475 | }
|
15476 | });
|
15477 |
|
15478 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
15479 |
|
15480 | return drawPath(parentGfx, pathData, {
|
15481 | strokeWidth: 1,
|
15482 | fill: fill,
|
15483 | stroke: getStrokeColor(event, defaultStrokeColor)
|
15484 | });
|
15485 | },
|
15486 | 'bpmn:MultipleEventDefinition': function(parentGfx, event, isThrowing) {
|
15487 | var pathData = pathMap.getScaledPath('EVENT_MULTIPLE', {
|
15488 | xScaleFactor: 1.1,
|
15489 | yScaleFactor: 1.1,
|
15490 | containerWidth: event.width,
|
15491 | containerHeight: event.height,
|
15492 | position: {
|
15493 | mx: 0.222,
|
15494 | my: 0.36
|
15495 | }
|
15496 | });
|
15497 |
|
15498 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
15499 |
|
15500 | return drawPath(parentGfx, pathData, {
|
15501 | strokeWidth: 1,
|
15502 | fill: fill
|
15503 | });
|
15504 | },
|
15505 | 'bpmn:ParallelMultipleEventDefinition': function(parentGfx, event) {
|
15506 | var pathData = pathMap.getScaledPath('EVENT_PARALLEL_MULTIPLE', {
|
15507 | xScaleFactor: 1.2,
|
15508 | yScaleFactor: 1.2,
|
15509 | containerWidth: event.width,
|
15510 | containerHeight: event.height,
|
15511 | position: {
|
15512 | mx: 0.458,
|
15513 | my: 0.194
|
15514 | }
|
15515 | });
|
15516 |
|
15517 | return drawPath(parentGfx, pathData, {
|
15518 | strokeWidth: 1,
|
15519 | fill: getStrokeColor(event, defaultStrokeColor),
|
15520 | stroke: getStrokeColor(event, defaultStrokeColor)
|
15521 | });
|
15522 | },
|
15523 | 'bpmn:EndEvent': function(parentGfx, element) {
|
15524 | var circle = renderer('bpmn:Event')(parentGfx, element, {
|
15525 | strokeWidth: 4,
|
15526 | fill: getFillColor(element, defaultFillColor),
|
15527 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15528 | });
|
15529 |
|
15530 | renderEventContent(element, parentGfx);
|
15531 |
|
15532 | return circle;
|
15533 | },
|
15534 | 'bpmn:TerminateEventDefinition': function(parentGfx, element) {
|
15535 | var circle = drawCircle(parentGfx, element.width, element.height, 8, {
|
15536 | strokeWidth: 4,
|
15537 | fill: getStrokeColor(element, defaultStrokeColor),
|
15538 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15539 | });
|
15540 |
|
15541 | return circle;
|
15542 | },
|
15543 | 'bpmn:IntermediateEvent': function(parentGfx, element) {
|
15544 | var outer = renderer('bpmn:Event')(parentGfx, element, {
|
15545 | strokeWidth: 1,
|
15546 | fill: getFillColor(element, defaultFillColor),
|
15547 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15548 | });
|
15549 |
|
15550 |
|
15551 | drawCircle(parentGfx, element.width, element.height, INNER_OUTER_DIST, {
|
15552 | strokeWidth: 1,
|
15553 | fill: getFillColor(element, 'none'),
|
15554 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15555 | });
|
15556 |
|
15557 | renderEventContent(element, parentGfx);
|
15558 |
|
15559 | return outer;
|
15560 | },
|
15561 | 'bpmn:IntermediateCatchEvent': as('bpmn:IntermediateEvent'),
|
15562 | 'bpmn:IntermediateThrowEvent': as('bpmn:IntermediateEvent'),
|
15563 |
|
15564 | 'bpmn:Activity': function(parentGfx, element, attrs) {
|
15565 |
|
15566 | attrs = attrs || {};
|
15567 |
|
15568 | if (!('fillOpacity' in attrs)) {
|
15569 | attrs.fillOpacity = DEFAULT_FILL_OPACITY;
|
15570 | }
|
15571 |
|
15572 | return drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS, attrs);
|
15573 | },
|
15574 |
|
15575 | 'bpmn:Task': function(parentGfx, element) {
|
15576 | var attrs = {
|
15577 | fill: getFillColor(element, defaultFillColor),
|
15578 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15579 | };
|
15580 |
|
15581 | var rect = renderer('bpmn:Activity')(parentGfx, element, attrs);
|
15582 |
|
15583 | renderEmbeddedLabel(parentGfx, element, 'center-middle');
|
15584 | attachTaskMarkers(parentGfx, element);
|
15585 |
|
15586 | return rect;
|
15587 | },
|
15588 | 'bpmn:ServiceTask': function(parentGfx, element) {
|
15589 | var task = renderer('bpmn:Task')(parentGfx, element);
|
15590 |
|
15591 | var pathDataBG = pathMap.getScaledPath('TASK_TYPE_SERVICE', {
|
15592 | abspos: {
|
15593 | x: 12,
|
15594 | y: 18
|
15595 | }
|
15596 | });
|
15597 |
|
15598 | drawPath(parentGfx, pathDataBG, {
|
15599 | strokeWidth: 1,
|
15600 | fill: getFillColor(element, defaultFillColor),
|
15601 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15602 | });
|
15603 |
|
15604 | var fillPathData = pathMap.getScaledPath('TASK_TYPE_SERVICE_FILL', {
|
15605 | abspos: {
|
15606 | x: 17.2,
|
15607 | y: 18
|
15608 | }
|
15609 | });
|
15610 |
|
15611 | drawPath(parentGfx, fillPathData, {
|
15612 | strokeWidth: 0,
|
15613 | fill: getFillColor(element, defaultFillColor)
|
15614 | });
|
15615 |
|
15616 | var pathData = pathMap.getScaledPath('TASK_TYPE_SERVICE', {
|
15617 | abspos: {
|
15618 | x: 17,
|
15619 | y: 22
|
15620 | }
|
15621 | });
|
15622 |
|
15623 | drawPath(parentGfx, pathData, {
|
15624 | strokeWidth: 1,
|
15625 | fill: getFillColor(element, defaultFillColor),
|
15626 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15627 | });
|
15628 |
|
15629 | return task;
|
15630 | },
|
15631 | 'bpmn:UserTask': function(parentGfx, element) {
|
15632 | var task = renderer('bpmn:Task')(parentGfx, element);
|
15633 |
|
15634 | var x = 15;
|
15635 | var y = 12;
|
15636 |
|
15637 | var pathData = pathMap.getScaledPath('TASK_TYPE_USER_1', {
|
15638 | abspos: {
|
15639 | x: x,
|
15640 | y: y
|
15641 | }
|
15642 | });
|
15643 |
|
15644 | drawPath(parentGfx, pathData, {
|
15645 | strokeWidth: 0.5,
|
15646 | fill: getFillColor(element, defaultFillColor),
|
15647 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15648 | });
|
15649 |
|
15650 | var pathData2 = pathMap.getScaledPath('TASK_TYPE_USER_2', {
|
15651 | abspos: {
|
15652 | x: x,
|
15653 | y: y
|
15654 | }
|
15655 | });
|
15656 |
|
15657 | drawPath(parentGfx, pathData2, {
|
15658 | strokeWidth: 0.5,
|
15659 | fill: getFillColor(element, defaultFillColor),
|
15660 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15661 | });
|
15662 |
|
15663 | var pathData3 = pathMap.getScaledPath('TASK_TYPE_USER_3', {
|
15664 | abspos: {
|
15665 | x: x,
|
15666 | y: y
|
15667 | }
|
15668 | });
|
15669 |
|
15670 | drawPath(parentGfx, pathData3, {
|
15671 | strokeWidth: 0.5,
|
15672 | fill: getStrokeColor(element, defaultStrokeColor),
|
15673 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15674 | });
|
15675 |
|
15676 | return task;
|
15677 | },
|
15678 | 'bpmn:ManualTask': function(parentGfx, element) {
|
15679 | var task = renderer('bpmn:Task')(parentGfx, element);
|
15680 |
|
15681 | var pathData = pathMap.getScaledPath('TASK_TYPE_MANUAL', {
|
15682 | abspos: {
|
15683 | x: 17,
|
15684 | y: 15
|
15685 | }
|
15686 | });
|
15687 |
|
15688 | drawPath(parentGfx, pathData, {
|
15689 | strokeWidth: 0.5,
|
15690 | fill: getFillColor(element, defaultFillColor),
|
15691 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15692 | });
|
15693 |
|
15694 | return task;
|
15695 | },
|
15696 | 'bpmn:SendTask': function(parentGfx, element) {
|
15697 | var task = renderer('bpmn:Task')(parentGfx, element);
|
15698 |
|
15699 | var pathData = pathMap.getScaledPath('TASK_TYPE_SEND', {
|
15700 | xScaleFactor: 1,
|
15701 | yScaleFactor: 1,
|
15702 | containerWidth: 21,
|
15703 | containerHeight: 14,
|
15704 | position: {
|
15705 | mx: 0.285,
|
15706 | my: 0.357
|
15707 | }
|
15708 | });
|
15709 |
|
15710 | drawPath(parentGfx, pathData, {
|
15711 | strokeWidth: 1,
|
15712 | fill: getStrokeColor(element, defaultStrokeColor),
|
15713 | stroke: getFillColor(element, defaultFillColor)
|
15714 | });
|
15715 |
|
15716 | return task;
|
15717 | },
|
15718 | 'bpmn:ReceiveTask' : function(parentGfx, element) {
|
15719 | var semantic = getSemantic(element);
|
15720 |
|
15721 | var task = renderer('bpmn:Task')(parentGfx, element);
|
15722 | var pathData;
|
15723 |
|
15724 | if (semantic.instantiate) {
|
15725 | drawCircle(parentGfx, 28, 28, 20 * 0.22, { strokeWidth: 1 });
|
15726 |
|
15727 | pathData = pathMap.getScaledPath('TASK_TYPE_INSTANTIATING_SEND', {
|
15728 | abspos: {
|
15729 | x: 7.77,
|
15730 | y: 9.52
|
15731 | }
|
15732 | });
|
15733 | } else {
|
15734 |
|
15735 | pathData = pathMap.getScaledPath('TASK_TYPE_SEND', {
|
15736 | xScaleFactor: 0.9,
|
15737 | yScaleFactor: 0.9,
|
15738 | containerWidth: 21,
|
15739 | containerHeight: 14,
|
15740 | position: {
|
15741 | mx: 0.3,
|
15742 | my: 0.4
|
15743 | }
|
15744 | });
|
15745 | }
|
15746 |
|
15747 | drawPath(parentGfx, pathData, {
|
15748 | strokeWidth: 1,
|
15749 | fill: getFillColor(element, defaultFillColor),
|
15750 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15751 | });
|
15752 |
|
15753 | return task;
|
15754 | },
|
15755 | 'bpmn:ScriptTask': function(parentGfx, element) {
|
15756 | var task = renderer('bpmn:Task')(parentGfx, element);
|
15757 |
|
15758 | var pathData = pathMap.getScaledPath('TASK_TYPE_SCRIPT', {
|
15759 | abspos: {
|
15760 | x: 15,
|
15761 | y: 20
|
15762 | }
|
15763 | });
|
15764 |
|
15765 | drawPath(parentGfx, pathData, {
|
15766 | strokeWidth: 1,
|
15767 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15768 | });
|
15769 |
|
15770 | return task;
|
15771 | },
|
15772 | 'bpmn:BusinessRuleTask': function(parentGfx, element) {
|
15773 | var task = renderer('bpmn:Task')(parentGfx, element);
|
15774 |
|
15775 | var headerPathData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_HEADER', {
|
15776 | abspos: {
|
15777 | x: 8,
|
15778 | y: 8
|
15779 | }
|
15780 | });
|
15781 |
|
15782 | var businessHeaderPath = drawPath(parentGfx, headerPathData);
|
15783 | attr$1(businessHeaderPath, {
|
15784 | strokeWidth: 1,
|
15785 | fill: getFillColor(element, '#aaaaaa'),
|
15786 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15787 | });
|
15788 |
|
15789 | var headerData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_MAIN', {
|
15790 | abspos: {
|
15791 | x: 8,
|
15792 | y: 8
|
15793 | }
|
15794 | });
|
15795 |
|
15796 | var businessPath = drawPath(parentGfx, headerData);
|
15797 | attr$1(businessPath, {
|
15798 | strokeWidth: 1,
|
15799 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15800 | });
|
15801 |
|
15802 | return task;
|
15803 | },
|
15804 | 'bpmn:SubProcess': function(parentGfx, element, attrs) {
|
15805 | attrs = assign({
|
15806 | fill: getFillColor(element, defaultFillColor),
|
15807 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15808 | }, attrs);
|
15809 |
|
15810 | var rect = renderer('bpmn:Activity')(parentGfx, element, attrs);
|
15811 |
|
15812 | var expanded = isExpanded(element);
|
15813 |
|
15814 | if (isEventSubProcess(element)) {
|
15815 | attr$1(rect, {
|
15816 | strokeDasharray: '1,2'
|
15817 | });
|
15818 | }
|
15819 |
|
15820 | renderEmbeddedLabel(parentGfx, element, expanded ? 'center-top' : 'center-middle');
|
15821 |
|
15822 | if (expanded) {
|
15823 | attachTaskMarkers(parentGfx, element);
|
15824 | } else {
|
15825 | attachTaskMarkers(parentGfx, element, ['SubProcessMarker']);
|
15826 | }
|
15827 |
|
15828 | return rect;
|
15829 | },
|
15830 | 'bpmn:AdHocSubProcess': function(parentGfx, element) {
|
15831 | return renderer('bpmn:SubProcess')(parentGfx, element);
|
15832 | },
|
15833 | 'bpmn:Transaction': function(parentGfx, element) {
|
15834 | var outer = renderer('bpmn:SubProcess')(parentGfx, element);
|
15835 |
|
15836 | var innerAttrs = styles.style([ 'no-fill', 'no-events' ], {
|
15837 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15838 | });
|
15839 |
|
15840 | drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS - 2, INNER_OUTER_DIST, innerAttrs);
|
15841 |
|
15842 | return outer;
|
15843 | },
|
15844 | 'bpmn:CallActivity': function(parentGfx, element) {
|
15845 | return renderer('bpmn:SubProcess')(parentGfx, element, {
|
15846 | strokeWidth: 5
|
15847 | });
|
15848 | },
|
15849 | 'bpmn:Participant': function(parentGfx, element) {
|
15850 |
|
15851 | var attrs = {
|
15852 | fillOpacity: DEFAULT_FILL_OPACITY,
|
15853 | fill: getFillColor(element, defaultFillColor),
|
15854 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15855 | };
|
15856 |
|
15857 | var lane = renderer('bpmn:Lane')(parentGfx, element, attrs);
|
15858 |
|
15859 | var expandedPool = isExpanded(element);
|
15860 |
|
15861 | if (expandedPool) {
|
15862 | drawLine(parentGfx, [
|
15863 | { x: 30, y: 0 },
|
15864 | { x: 30, y: element.height }
|
15865 | ], {
|
15866 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15867 | });
|
15868 | var text = getSemantic(element).name;
|
15869 | renderLaneLabel(parentGfx, text, element);
|
15870 | } else {
|
15871 |
|
15872 |
|
15873 | var text2 = getSemantic(element).name;
|
15874 | renderLabel(parentGfx, text2, {
|
15875 | box: element, align: 'center-middle',
|
15876 | style: {
|
15877 | fill: getStrokeColor(element, defaultStrokeColor)
|
15878 | }
|
15879 | });
|
15880 | }
|
15881 |
|
15882 | var participantMultiplicity = !!(getSemantic(element).participantMultiplicity);
|
15883 |
|
15884 | if (participantMultiplicity) {
|
15885 | renderer('ParticipantMultiplicityMarker')(parentGfx, element);
|
15886 | }
|
15887 |
|
15888 | return lane;
|
15889 | },
|
15890 | 'bpmn:Lane': function(parentGfx, element, attrs) {
|
15891 | var rect = drawRect(parentGfx, element.width, element.height, 0, assign({
|
15892 | fill: getFillColor(element, defaultFillColor),
|
15893 | fillOpacity: HIGH_FILL_OPACITY,
|
15894 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15895 | }, attrs));
|
15896 |
|
15897 | var semantic = getSemantic(element);
|
15898 |
|
15899 | if (semantic.$type === 'bpmn:Lane') {
|
15900 | var text = semantic.name;
|
15901 | renderLaneLabel(parentGfx, text, element);
|
15902 | }
|
15903 |
|
15904 | return rect;
|
15905 | },
|
15906 | 'bpmn:InclusiveGateway': function(parentGfx, element) {
|
15907 | var diamond = renderer('bpmn:Gateway')(parentGfx, element);
|
15908 |
|
15909 |
|
15910 | drawCircle(parentGfx, element.width, element.height, element.height * 0.24, {
|
15911 | strokeWidth: 2.5,
|
15912 | fill: getFillColor(element, defaultFillColor),
|
15913 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15914 | });
|
15915 |
|
15916 | return diamond;
|
15917 | },
|
15918 | 'bpmn:ExclusiveGateway': function(parentGfx, element) {
|
15919 | var diamond = renderer('bpmn:Gateway')(parentGfx, element);
|
15920 |
|
15921 | var pathData = pathMap.getScaledPath('GATEWAY_EXCLUSIVE', {
|
15922 | xScaleFactor: 0.4,
|
15923 | yScaleFactor: 0.4,
|
15924 | containerWidth: element.width,
|
15925 | containerHeight: element.height,
|
15926 | position: {
|
15927 | mx: 0.32,
|
15928 | my: 0.3
|
15929 | }
|
15930 | });
|
15931 |
|
15932 | if ((getDi(element).isMarkerVisible)) {
|
15933 | drawPath(parentGfx, pathData, {
|
15934 | strokeWidth: 1,
|
15935 | fill: getStrokeColor(element, defaultStrokeColor),
|
15936 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15937 | });
|
15938 | }
|
15939 |
|
15940 | return diamond;
|
15941 | },
|
15942 | 'bpmn:ComplexGateway': function(parentGfx, element) {
|
15943 | var diamond = renderer('bpmn:Gateway')(parentGfx, element);
|
15944 |
|
15945 | var pathData = pathMap.getScaledPath('GATEWAY_COMPLEX', {
|
15946 | xScaleFactor: 0.5,
|
15947 | yScaleFactor:0.5,
|
15948 | containerWidth: element.width,
|
15949 | containerHeight: element.height,
|
15950 | position: {
|
15951 | mx: 0.46,
|
15952 | my: 0.26
|
15953 | }
|
15954 | });
|
15955 |
|
15956 | drawPath(parentGfx, pathData, {
|
15957 | strokeWidth: 1,
|
15958 | fill: getStrokeColor(element, defaultStrokeColor),
|
15959 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15960 | });
|
15961 |
|
15962 | return diamond;
|
15963 | },
|
15964 | 'bpmn:ParallelGateway': function(parentGfx, element) {
|
15965 | var diamond = renderer('bpmn:Gateway')(parentGfx, element);
|
15966 |
|
15967 | var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', {
|
15968 | xScaleFactor: 0.6,
|
15969 | yScaleFactor:0.6,
|
15970 | containerWidth: element.width,
|
15971 | containerHeight: element.height,
|
15972 | position: {
|
15973 | mx: 0.46,
|
15974 | my: 0.2
|
15975 | }
|
15976 | });
|
15977 |
|
15978 | drawPath(parentGfx, pathData, {
|
15979 | strokeWidth: 1,
|
15980 | fill: getStrokeColor(element, defaultStrokeColor),
|
15981 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15982 | });
|
15983 |
|
15984 | return diamond;
|
15985 | },
|
15986 | 'bpmn:EventBasedGateway': function(parentGfx, element) {
|
15987 |
|
15988 | var semantic = getSemantic(element);
|
15989 |
|
15990 | var diamond = renderer('bpmn:Gateway')(parentGfx, element);
|
15991 |
|
15992 | drawCircle(parentGfx, element.width, element.height, element.height * 0.20, {
|
15993 | strokeWidth: 1,
|
15994 | fill: 'none',
|
15995 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15996 | });
|
15997 |
|
15998 | var type = semantic.eventGatewayType;
|
15999 | var instantiate = !!semantic.instantiate;
|
16000 |
|
16001 | function drawEvent() {
|
16002 |
|
16003 | var pathData = pathMap.getScaledPath('GATEWAY_EVENT_BASED', {
|
16004 | xScaleFactor: 0.18,
|
16005 | yScaleFactor: 0.18,
|
16006 | containerWidth: element.width,
|
16007 | containerHeight: element.height,
|
16008 | position: {
|
16009 | mx: 0.36,
|
16010 | my: 0.44
|
16011 | }
|
16012 | });
|
16013 |
|
16014 | var attrs = {
|
16015 | strokeWidth: 2,
|
16016 | fill: getFillColor(element, 'none'),
|
16017 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16018 | };
|
16019 |
|
16020 | drawPath(parentGfx, pathData, attrs);
|
16021 | }
|
16022 |
|
16023 | if (type === 'Parallel') {
|
16024 |
|
16025 | var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', {
|
16026 | xScaleFactor: 0.4,
|
16027 | yScaleFactor:0.4,
|
16028 | containerWidth: element.width,
|
16029 | containerHeight: element.height,
|
16030 | position: {
|
16031 | mx: 0.474,
|
16032 | my: 0.296
|
16033 | }
|
16034 | });
|
16035 |
|
16036 | var parallelPath = drawPath(parentGfx, pathData);
|
16037 | attr$1(parallelPath, {
|
16038 | strokeWidth: 1,
|
16039 | fill: 'none'
|
16040 | });
|
16041 | } else if (type === 'Exclusive') {
|
16042 |
|
16043 | if (!instantiate) {
|
16044 | var innerCircle = drawCircle(parentGfx, element.width, element.height, element.height * 0.26);
|
16045 | attr$1(innerCircle, {
|
16046 | strokeWidth: 1,
|
16047 | fill: 'none',
|
16048 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16049 | });
|
16050 | }
|
16051 |
|
16052 | drawEvent();
|
16053 | }
|
16054 |
|
16055 |
|
16056 | return diamond;
|
16057 | },
|
16058 | 'bpmn:Gateway': function(parentGfx, element) {
|
16059 | var attrs = {
|
16060 | fill: getFillColor(element, defaultFillColor),
|
16061 | fillOpacity: DEFAULT_FILL_OPACITY,
|
16062 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16063 | };
|
16064 |
|
16065 | return drawDiamond(parentGfx, element.width, element.height, attrs);
|
16066 | },
|
16067 | 'bpmn:SequenceFlow': function(parentGfx, element) {
|
16068 | var pathData = createPathFromConnection(element);
|
16069 |
|
16070 | var fill = getFillColor(element, defaultFillColor),
|
16071 | stroke = getStrokeColor(element, defaultStrokeColor);
|
16072 |
|
16073 | var attrs = {
|
16074 | strokeLinejoin: 'round',
|
16075 | markerEnd: marker('sequenceflow-end', fill, stroke),
|
16076 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16077 | };
|
16078 |
|
16079 | var path = drawPath(parentGfx, pathData, attrs);
|
16080 |
|
16081 | var sequenceFlow = getSemantic(element);
|
16082 |
|
16083 | var source;
|
16084 |
|
16085 | if (element.source) {
|
16086 | source = element.source.businessObject;
|
16087 |
|
16088 |
|
16089 | if (sequenceFlow.conditionExpression && source.$instanceOf('bpmn:Activity')) {
|
16090 | attr$1(path, {
|
16091 | markerStart: marker('conditional-flow-marker', fill, stroke)
|
16092 | });
|
16093 | }
|
16094 |
|
16095 |
|
16096 | if (source.default && (source.$instanceOf('bpmn:Gateway') || source.$instanceOf('bpmn:Activity')) &&
|
16097 | source.default === sequenceFlow) {
|
16098 | attr$1(path, {
|
16099 | markerStart: marker('conditional-default-flow-marker', fill, stroke)
|
16100 | });
|
16101 | }
|
16102 | }
|
16103 |
|
16104 | return path;
|
16105 | },
|
16106 | 'bpmn:Association': function(parentGfx, element, attrs) {
|
16107 |
|
16108 | var semantic = getSemantic(element);
|
16109 |
|
16110 | var fill = getFillColor(element, defaultFillColor),
|
16111 | stroke = getStrokeColor(element, defaultStrokeColor);
|
16112 |
|
16113 | attrs = assign({
|
16114 | strokeDasharray: '0.5, 5',
|
16115 | strokeLinecap: 'round',
|
16116 | strokeLinejoin: 'round',
|
16117 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16118 | }, attrs || {});
|
16119 |
|
16120 | if (semantic.associationDirection === 'One' ||
|
16121 | semantic.associationDirection === 'Both') {
|
16122 | attrs.markerEnd = marker('association-end', fill, stroke);
|
16123 | }
|
16124 |
|
16125 | if (semantic.associationDirection === 'Both') {
|
16126 | attrs.markerStart = marker('association-start', fill, stroke);
|
16127 | }
|
16128 |
|
16129 | return drawLine(parentGfx, element.waypoints, attrs);
|
16130 | },
|
16131 | 'bpmn:DataInputAssociation': function(parentGfx, element) {
|
16132 | var fill = getFillColor(element, defaultFillColor),
|
16133 | stroke = getStrokeColor(element, defaultStrokeColor);
|
16134 |
|
16135 | return renderer('bpmn:Association')(parentGfx, element, {
|
16136 | markerEnd: marker('association-end', fill, stroke)
|
16137 | });
|
16138 | },
|
16139 | 'bpmn:DataOutputAssociation': function(parentGfx, element) {
|
16140 | var fill = getFillColor(element, defaultFillColor),
|
16141 | stroke = getStrokeColor(element, defaultStrokeColor);
|
16142 |
|
16143 | return renderer('bpmn:Association')(parentGfx, element, {
|
16144 | markerEnd: marker('association-end', fill, stroke)
|
16145 | });
|
16146 | },
|
16147 | 'bpmn:MessageFlow': function(parentGfx, element) {
|
16148 |
|
16149 | var semantic = getSemantic(element),
|
16150 | di = getDi(element);
|
16151 |
|
16152 | var fill = getFillColor(element, defaultFillColor),
|
16153 | stroke = getStrokeColor(element, defaultStrokeColor);
|
16154 |
|
16155 | var pathData = createPathFromConnection(element);
|
16156 |
|
16157 | var attrs = {
|
16158 | markerEnd: marker('messageflow-end', fill, stroke),
|
16159 | markerStart: marker('messageflow-start', fill, stroke),
|
16160 | strokeDasharray: '10, 12',
|
16161 | strokeLinecap: 'round',
|
16162 | strokeLinejoin: 'round',
|
16163 | strokeWidth: '1.5px',
|
16164 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16165 | };
|
16166 |
|
16167 | var path = drawPath(parentGfx, pathData, attrs);
|
16168 |
|
16169 | if (semantic.messageRef) {
|
16170 | var midPoint = path.getPointAtLength(path.getTotalLength() / 2);
|
16171 |
|
16172 | var markerPathData = pathMap.getScaledPath('MESSAGE_FLOW_MARKER', {
|
16173 | abspos: {
|
16174 | x: midPoint.x,
|
16175 | y: midPoint.y
|
16176 | }
|
16177 | });
|
16178 |
|
16179 | var messageAttrs = { strokeWidth: 1 };
|
16180 |
|
16181 | if (di.messageVisibleKind === 'initiating') {
|
16182 | messageAttrs.fill = 'white';
|
16183 | messageAttrs.stroke = 'black';
|
16184 | } else {
|
16185 | messageAttrs.fill = '#888';
|
16186 | messageAttrs.stroke = 'white';
|
16187 | }
|
16188 |
|
16189 | drawPath(parentGfx, markerPathData, messageAttrs);
|
16190 | }
|
16191 |
|
16192 | return path;
|
16193 | },
|
16194 | 'bpmn:DataObject': function(parentGfx, element) {
|
16195 | var pathData = pathMap.getScaledPath('DATA_OBJECT_PATH', {
|
16196 | xScaleFactor: 1,
|
16197 | yScaleFactor: 1,
|
16198 | containerWidth: element.width,
|
16199 | containerHeight: element.height,
|
16200 | position: {
|
16201 | mx: 0.474,
|
16202 | my: 0.296
|
16203 | }
|
16204 | });
|
16205 |
|
16206 | var elementObject = drawPath(parentGfx, pathData, {
|
16207 | fill: getFillColor(element, defaultFillColor),
|
16208 | fillOpacity: DEFAULT_FILL_OPACITY,
|
16209 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16210 | });
|
16211 |
|
16212 | var semantic = getSemantic(element);
|
16213 |
|
16214 | if (isCollection(semantic)) {
|
16215 | renderDataItemCollection(parentGfx, element);
|
16216 | }
|
16217 |
|
16218 | return elementObject;
|
16219 | },
|
16220 | 'bpmn:DataObjectReference': as('bpmn:DataObject'),
|
16221 | 'bpmn:DataInput': function(parentGfx, element) {
|
16222 |
|
16223 | var arrowPathData = pathMap.getRawPath('DATA_ARROW');
|
16224 |
|
16225 |
|
16226 | var elementObject = renderer('bpmn:DataObject')(parentGfx, element);
|
16227 |
|
16228 | drawPath(parentGfx, arrowPathData, { strokeWidth: 1 });
|
16229 |
|
16230 | return elementObject;
|
16231 | },
|
16232 | 'bpmn:DataOutput': function(parentGfx, element) {
|
16233 | var arrowPathData = pathMap.getRawPath('DATA_ARROW');
|
16234 |
|
16235 |
|
16236 | var elementObject = renderer('bpmn:DataObject')(parentGfx, element);
|
16237 |
|
16238 | drawPath(parentGfx, arrowPathData, {
|
16239 | strokeWidth: 1,
|
16240 | fill: 'black'
|
16241 | });
|
16242 |
|
16243 | return elementObject;
|
16244 | },
|
16245 | 'bpmn:DataStoreReference': function(parentGfx, element) {
|
16246 | var DATA_STORE_PATH = pathMap.getScaledPath('DATA_STORE', {
|
16247 | xScaleFactor: 1,
|
16248 | yScaleFactor: 1,
|
16249 | containerWidth: element.width,
|
16250 | containerHeight: element.height,
|
16251 | position: {
|
16252 | mx: 0,
|
16253 | my: 0.133
|
16254 | }
|
16255 | });
|
16256 |
|
16257 | var elementStore = drawPath(parentGfx, DATA_STORE_PATH, {
|
16258 | strokeWidth: 2,
|
16259 | fill: getFillColor(element, defaultFillColor),
|
16260 | fillOpacity: DEFAULT_FILL_OPACITY,
|
16261 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16262 | });
|
16263 |
|
16264 | return elementStore;
|
16265 | },
|
16266 | 'bpmn:BoundaryEvent': function(parentGfx, element) {
|
16267 |
|
16268 | var semantic = getSemantic(element),
|
16269 | cancel = semantic.cancelActivity;
|
16270 |
|
16271 | var attrs = {
|
16272 | strokeWidth: 1,
|
16273 | fill: getFillColor(element, defaultFillColor),
|
16274 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16275 | };
|
16276 |
|
16277 | if (!cancel) {
|
16278 | attrs.strokeDasharray = '6';
|
16279 | attrs.strokeLinecap = 'round';
|
16280 | }
|
16281 |
|
16282 |
|
16283 | var outerAttrs = assign({}, attrs, {
|
16284 | fillOpacity: 1
|
16285 | });
|
16286 |
|
16287 |
|
16288 | var innerAttrs = assign({}, attrs, {
|
16289 | fill: 'none'
|
16290 | });
|
16291 |
|
16292 | var outer = renderer('bpmn:Event')(parentGfx, element, outerAttrs);
|
16293 |
|
16294 | drawCircle(parentGfx, element.width, element.height, INNER_OUTER_DIST, innerAttrs);
|
16295 |
|
16296 | renderEventContent(element, parentGfx);
|
16297 |
|
16298 | return outer;
|
16299 | },
|
16300 | 'bpmn:Group': function(parentGfx, element) {
|
16301 |
|
16302 | var group = drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS, {
|
16303 | stroke: getStrokeColor(element, defaultStrokeColor),
|
16304 | strokeWidth: 1,
|
16305 | strokeDasharray: '8,3,1,3',
|
16306 | fill: 'none',
|
16307 | pointerEvents: 'none'
|
16308 | });
|
16309 |
|
16310 | return group;
|
16311 | },
|
16312 | 'label': function(parentGfx, element) {
|
16313 | return renderExternalLabel(parentGfx, element);
|
16314 | },
|
16315 | 'bpmn:TextAnnotation': function(parentGfx, element) {
|
16316 | var style = {
|
16317 | 'fill': 'none',
|
16318 | 'stroke': 'none'
|
16319 | };
|
16320 |
|
16321 | var textElement = drawRect(parentGfx, element.width, element.height, 0, 0, style);
|
16322 |
|
16323 | var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', {
|
16324 | xScaleFactor: 1,
|
16325 | yScaleFactor: 1,
|
16326 | containerWidth: element.width,
|
16327 | containerHeight: element.height,
|
16328 | position: {
|
16329 | mx: 0.0,
|
16330 | my: 0.0
|
16331 | }
|
16332 | });
|
16333 |
|
16334 | drawPath(parentGfx, textPathData, {
|
16335 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16336 | });
|
16337 |
|
16338 | var text = getSemantic(element).text || '';
|
16339 | renderLabel(parentGfx, text, {
|
16340 | box: element,
|
16341 | align: 'left-top',
|
16342 | padding: 5,
|
16343 | style: {
|
16344 | fill: getStrokeColor(element, defaultStrokeColor)
|
16345 | }
|
16346 | });
|
16347 |
|
16348 | return textElement;
|
16349 | },
|
16350 | 'ParticipantMultiplicityMarker': function(parentGfx, element) {
|
16351 | var markerPath = pathMap.getScaledPath('MARKER_PARALLEL', {
|
16352 | xScaleFactor: 1,
|
16353 | yScaleFactor: 1,
|
16354 | containerWidth: element.width,
|
16355 | containerHeight: element.height,
|
16356 | position: {
|
16357 | mx: ((element.width / 2) / element.width),
|
16358 | my: (element.height - 15) / element.height
|
16359 | }
|
16360 | });
|
16361 |
|
16362 | drawMarker('participant-multiplicity', parentGfx, markerPath, {
|
16363 | strokeWidth: 1,
|
16364 | fill: getFillColor(element, defaultFillColor),
|
16365 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16366 | });
|
16367 | },
|
16368 | 'SubProcessMarker': function(parentGfx, element) {
|
16369 | var markerRect = drawRect(parentGfx, 14, 14, 0, {
|
16370 | strokeWidth: 1,
|
16371 | fill: getFillColor(element, defaultFillColor),
|
16372 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16373 | });
|
16374 |
|
16375 |
|
16376 |
|
16377 | translate(markerRect, element.width / 2 - 7.5, element.height - 20);
|
16378 |
|
16379 | var markerPath = pathMap.getScaledPath('MARKER_SUB_PROCESS', {
|
16380 | xScaleFactor: 1.5,
|
16381 | yScaleFactor: 1.5,
|
16382 | containerWidth: element.width,
|
16383 | containerHeight: element.height,
|
16384 | position: {
|
16385 | mx: (element.width / 2 - 7.5) / element.width,
|
16386 | my: (element.height - 20) / element.height
|
16387 | }
|
16388 | });
|
16389 |
|
16390 | drawMarker('sub-process', parentGfx, markerPath, {
|
16391 | fill: getFillColor(element, defaultFillColor),
|
16392 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16393 | });
|
16394 | },
|
16395 | 'ParallelMarker': function(parentGfx, element, position) {
|
16396 | var markerPath = pathMap.getScaledPath('MARKER_PARALLEL', {
|
16397 | xScaleFactor: 1,
|
16398 | yScaleFactor: 1,
|
16399 | containerWidth: element.width,
|
16400 | containerHeight: element.height,
|
16401 | position: {
|
16402 | mx: ((element.width / 2 + position.parallel) / element.width),
|
16403 | my: (element.height - 20) / element.height
|
16404 | }
|
16405 | });
|
16406 |
|
16407 | drawMarker('parallel', parentGfx, markerPath, {
|
16408 | fill: getFillColor(element, defaultFillColor),
|
16409 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16410 | });
|
16411 | },
|
16412 | 'SequentialMarker': function(parentGfx, element, position) {
|
16413 | var markerPath = pathMap.getScaledPath('MARKER_SEQUENTIAL', {
|
16414 | xScaleFactor: 1,
|
16415 | yScaleFactor: 1,
|
16416 | containerWidth: element.width,
|
16417 | containerHeight: element.height,
|
16418 | position: {
|
16419 | mx: ((element.width / 2 + position.seq) / element.width),
|
16420 | my: (element.height - 19) / element.height
|
16421 | }
|
16422 | });
|
16423 |
|
16424 | drawMarker('sequential', parentGfx, markerPath, {
|
16425 | fill: getFillColor(element, defaultFillColor),
|
16426 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16427 | });
|
16428 | },
|
16429 | 'CompensationMarker': function(parentGfx, element, position) {
|
16430 | var markerMath = pathMap.getScaledPath('MARKER_COMPENSATION', {
|
16431 | xScaleFactor: 1,
|
16432 | yScaleFactor: 1,
|
16433 | containerWidth: element.width,
|
16434 | containerHeight: element.height,
|
16435 | position: {
|
16436 | mx: ((element.width / 2 + position.compensation) / element.width),
|
16437 | my: (element.height - 13) / element.height
|
16438 | }
|
16439 | });
|
16440 |
|
16441 | drawMarker('compensation', parentGfx, markerMath, {
|
16442 | strokeWidth: 1,
|
16443 | fill: getFillColor(element, defaultFillColor),
|
16444 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16445 | });
|
16446 | },
|
16447 | 'LoopMarker': function(parentGfx, element, position) {
|
16448 | var markerPath = pathMap.getScaledPath('MARKER_LOOP', {
|
16449 | xScaleFactor: 1,
|
16450 | yScaleFactor: 1,
|
16451 | containerWidth: element.width,
|
16452 | containerHeight: element.height,
|
16453 | position: {
|
16454 | mx: ((element.width / 2 + position.loop) / element.width),
|
16455 | my: (element.height - 7) / element.height
|
16456 | }
|
16457 | });
|
16458 |
|
16459 | drawMarker('loop', parentGfx, markerPath, {
|
16460 | strokeWidth: 1,
|
16461 | fill: getFillColor(element, defaultFillColor),
|
16462 | stroke: getStrokeColor(element, defaultStrokeColor),
|
16463 | strokeLinecap: 'round',
|
16464 | strokeMiterlimit: 0.5
|
16465 | });
|
16466 | },
|
16467 | 'AdhocMarker': function(parentGfx, element, position) {
|
16468 | var markerPath = pathMap.getScaledPath('MARKER_ADHOC', {
|
16469 | xScaleFactor: 1,
|
16470 | yScaleFactor: 1,
|
16471 | containerWidth: element.width,
|
16472 | containerHeight: element.height,
|
16473 | position: {
|
16474 | mx: ((element.width / 2 + position.adhoc) / element.width),
|
16475 | my: (element.height - 15) / element.height
|
16476 | }
|
16477 | });
|
16478 |
|
16479 | drawMarker('adhoc', parentGfx, markerPath, {
|
16480 | strokeWidth: 1,
|
16481 | fill: getStrokeColor(element, defaultStrokeColor),
|
16482 | stroke: getStrokeColor(element, defaultStrokeColor)
|
16483 | });
|
16484 | }
|
16485 | };
|
16486 |
|
16487 | function attachTaskMarkers(parentGfx, element, taskMarkers) {
|
16488 | var obj = getSemantic(element);
|
16489 |
|
16490 | var subprocess = taskMarkers && taskMarkers.indexOf('SubProcessMarker') !== -1;
|
16491 | var position;
|
16492 |
|
16493 | if (subprocess) {
|
16494 | position = {
|
16495 | seq: -21,
|
16496 | parallel: -22,
|
16497 | compensation: -42,
|
16498 | loop: -18,
|
16499 | adhoc: 10
|
16500 | };
|
16501 | } else {
|
16502 | position = {
|
16503 | seq: -3,
|
16504 | parallel: -6,
|
16505 | compensation: -27,
|
16506 | loop: 0,
|
16507 | adhoc: 10
|
16508 | };
|
16509 | }
|
16510 |
|
16511 | forEach(taskMarkers, function(marker) {
|
16512 | renderer(marker)(parentGfx, element, position);
|
16513 | });
|
16514 |
|
16515 | if (obj.isForCompensation) {
|
16516 | renderer('CompensationMarker')(parentGfx, element, position);
|
16517 | }
|
16518 |
|
16519 | if (obj.$type === 'bpmn:AdHocSubProcess') {
|
16520 | renderer('AdhocMarker')(parentGfx, element, position);
|
16521 | }
|
16522 |
|
16523 | var loopCharacteristics = obj.loopCharacteristics,
|
16524 | isSequential = loopCharacteristics && loopCharacteristics.isSequential;
|
16525 |
|
16526 | if (loopCharacteristics) {
|
16527 |
|
16528 | if (isSequential === undefined) {
|
16529 | renderer('LoopMarker')(parentGfx, element, position);
|
16530 | }
|
16531 |
|
16532 | if (isSequential === false) {
|
16533 | renderer('ParallelMarker')(parentGfx, element, position);
|
16534 | }
|
16535 |
|
16536 | if (isSequential === true) {
|
16537 | renderer('SequentialMarker')(parentGfx, element, position);
|
16538 | }
|
16539 | }
|
16540 | }
|
16541 |
|
16542 | function renderDataItemCollection(parentGfx, element) {
|
16543 |
|
16544 | var yPosition = (element.height - 16) / element.height;
|
16545 |
|
16546 | var pathData = pathMap.getScaledPath('DATA_OBJECT_COLLECTION_PATH', {
|
16547 | xScaleFactor: 1,
|
16548 | yScaleFactor: 1,
|
16549 | containerWidth: element.width,
|
16550 | containerHeight: element.height,
|
16551 | position: {
|
16552 | mx: 0.451,
|
16553 | my: yPosition
|
16554 | }
|
16555 | });
|
16556 |
|
16557 | drawPath(parentGfx, pathData, {
|
16558 | strokeWidth: 2
|
16559 | });
|
16560 | }
|
16561 |
|
16562 |
|
16563 |
|
16564 | this._drawPath = drawPath;
|
16565 |
|
16566 | }
|
16567 |
|
16568 |
|
16569 | inherits_browser(BpmnRenderer, BaseRenderer);
|
16570 |
|
16571 | BpmnRenderer.$inject = [
|
16572 | 'config.bpmnRenderer',
|
16573 | 'eventBus',
|
16574 | 'styles',
|
16575 | 'pathMap',
|
16576 | 'canvas',
|
16577 | 'textRenderer'
|
16578 | ];
|
16579 |
|
16580 |
|
16581 | BpmnRenderer.prototype.canRender = function(element) {
|
16582 | return is$1(element, 'bpmn:BaseElement');
|
16583 | };
|
16584 |
|
16585 | BpmnRenderer.prototype.drawShape = function(parentGfx, element) {
|
16586 | var type = element.type;
|
16587 | var h = this.handlers[type];
|
16588 |
|
16589 |
|
16590 | return h(parentGfx, element);
|
16591 | };
|
16592 |
|
16593 | BpmnRenderer.prototype.drawConnection = function(parentGfx, element) {
|
16594 | var type = element.type;
|
16595 | var h = this.handlers[type];
|
16596 |
|
16597 |
|
16598 | return h(parentGfx, element);
|
16599 | };
|
16600 |
|
16601 | BpmnRenderer.prototype.getShapePath = function(element) {
|
16602 |
|
16603 | if (is$1(element, 'bpmn:Event')) {
|
16604 | return getCirclePath(element);
|
16605 | }
|
16606 |
|
16607 | if (is$1(element, 'bpmn:Activity')) {
|
16608 | return getRoundRectPath(element, TASK_BORDER_RADIUS);
|
16609 | }
|
16610 |
|
16611 | if (is$1(element, 'bpmn:Gateway')) {
|
16612 | return getDiamondPath(element);
|
16613 | }
|
16614 |
|
16615 | return getRectPath(element);
|
16616 | };
|
16617 |
|
16618 | var DEFAULT_BOX_PADDING = 0;
|
16619 |
|
16620 | var DEFAULT_LABEL_SIZE = {
|
16621 | width: 150,
|
16622 | height: 50
|
16623 | };
|
16624 |
|
16625 |
|
16626 | function parseAlign(align) {
|
16627 |
|
16628 | var parts = align.split('-');
|
16629 |
|
16630 | return {
|
16631 | horizontal: parts[0] || 'center',
|
16632 | vertical: parts[1] || 'top'
|
16633 | };
|
16634 | }
|
16635 |
|
16636 | function parsePadding(padding) {
|
16637 |
|
16638 | if (isObject(padding)) {
|
16639 | return assign({ top: 0, left: 0, right: 0, bottom: 0 }, padding);
|
16640 | } else {
|
16641 | return {
|
16642 | top: padding,
|
16643 | left: padding,
|
16644 | right: padding,
|
16645 | bottom: padding
|
16646 | };
|
16647 | }
|
16648 | }
|
16649 |
|
16650 | function getTextBBox(text, fakeText) {
|
16651 |
|
16652 | fakeText.textContent = text;
|
16653 |
|
16654 | var textBBox;
|
16655 |
|
16656 | try {
|
16657 | var bbox,
|
16658 | emptyLine = text === '';
|
16659 |
|
16660 |
|
16661 |
|
16662 | fakeText.textContent = emptyLine ? 'dummy' : text;
|
16663 |
|
16664 | textBBox = fakeText.getBBox();
|
16665 |
|
16666 |
|
16667 |
|
16668 | bbox = {
|
16669 | width: textBBox.width + textBBox.x * 2,
|
16670 | height: textBBox.height
|
16671 | };
|
16672 |
|
16673 | if (emptyLine) {
|
16674 |
|
16675 |
|
16676 | bbox.width = 0;
|
16677 | }
|
16678 |
|
16679 | return bbox;
|
16680 | } catch (e) {
|
16681 | return { width: 0, height: 0 };
|
16682 | }
|
16683 | }
|
16684 |
|
16685 |
|
16686 | |
16687 |
|
16688 |
|
16689 |
|
16690 |
|
16691 |
|
16692 |
|
16693 |
|
16694 | function layoutNext(lines, maxWidth, fakeText) {
|
16695 |
|
16696 | var originalLine = lines.shift(),
|
16697 | fitLine = originalLine;
|
16698 |
|
16699 | var textBBox;
|
16700 |
|
16701 | for (;;) {
|
16702 | textBBox = getTextBBox(fitLine, fakeText);
|
16703 |
|
16704 | textBBox.width = fitLine ? textBBox.width : 0;
|
16705 |
|
16706 |
|
16707 | if (fitLine === ' ' || fitLine === '' || textBBox.width < Math.round(maxWidth) || fitLine.length < 2) {
|
16708 | return fit(lines, fitLine, originalLine, textBBox);
|
16709 | }
|
16710 |
|
16711 | fitLine = shortenLine(fitLine, textBBox.width, maxWidth);
|
16712 | }
|
16713 | }
|
16714 |
|
16715 | function fit(lines, fitLine, originalLine, textBBox) {
|
16716 | if (fitLine.length < originalLine.length) {
|
16717 | var remainder = originalLine.slice(fitLine.length).trim();
|
16718 |
|
16719 | lines.unshift(remainder);
|
16720 | }
|
16721 |
|
16722 | return {
|
16723 | width: textBBox.width,
|
16724 | height: textBBox.height,
|
16725 | text: fitLine
|
16726 | };
|
16727 | }
|
16728 |
|
16729 |
|
16730 | |
16731 |
|
16732 |
|
16733 |
|
16734 |
|
16735 |
|
16736 |
|
16737 |
|
16738 | function semanticShorten(line, maxLength) {
|
16739 | var parts = line.split(/(\s|-)/g),
|
16740 | part,
|
16741 | shortenedParts = [],
|
16742 | length = 0;
|
16743 |
|
16744 |
|
16745 | if (parts.length > 1) {
|
16746 | while ((part = parts.shift())) {
|
16747 | if (part.length + length < maxLength) {
|
16748 | shortenedParts.push(part);
|
16749 | length += part.length;
|
16750 | } else {
|
16751 |
|
16752 |
|
16753 | if (part === '-') {
|
16754 | shortenedParts.pop();
|
16755 | }
|
16756 |
|
16757 | break;
|
16758 | }
|
16759 | }
|
16760 | }
|
16761 |
|
16762 | return shortenedParts.join('');
|
16763 | }
|
16764 |
|
16765 |
|
16766 | function shortenLine(line, width, maxWidth) {
|
16767 | var length = Math.max(line.length * (maxWidth / width), 1);
|
16768 |
|
16769 |
|
16770 | var shortenedLine = semanticShorten(line, length);
|
16771 |
|
16772 | if (!shortenedLine) {
|
16773 |
|
16774 |
|
16775 | shortenedLine = line.slice(0, Math.max(Math.round(length - 1), 1));
|
16776 | }
|
16777 |
|
16778 | return shortenedLine;
|
16779 | }
|
16780 |
|
16781 |
|
16782 | function getHelperSvg() {
|
16783 | var helperSvg = document.getElementById('helper-svg');
|
16784 |
|
16785 | if (!helperSvg) {
|
16786 | helperSvg = create('svg');
|
16787 |
|
16788 | attr$1(helperSvg, {
|
16789 | id: 'helper-svg',
|
16790 | width: 0,
|
16791 | height: 0,
|
16792 | style: 'visibility: hidden; position: fixed'
|
16793 | });
|
16794 |
|
16795 | document.body.appendChild(helperSvg);
|
16796 | }
|
16797 |
|
16798 | return helperSvg;
|
16799 | }
|
16800 |
|
16801 |
|
16802 | |
16803 |
|
16804 |
|
16805 |
|
16806 |
|
16807 |
|
16808 |
|
16809 |
|
16810 |
|
16811 | function Text(config) {
|
16812 |
|
16813 | this._config = assign({}, {
|
16814 | size: DEFAULT_LABEL_SIZE,
|
16815 | padding: DEFAULT_BOX_PADDING,
|
16816 | style: {},
|
16817 | align: 'center-top'
|
16818 | }, config || {});
|
16819 | }
|
16820 |
|
16821 | |
16822 |
|
16823 |
|
16824 |
|
16825 |
|
16826 |
|
16827 |
|
16828 |
|
16829 | Text.prototype.createText = function(text, options) {
|
16830 | return this.layoutText(text, options).element;
|
16831 | };
|
16832 |
|
16833 | |
16834 |
|
16835 |
|
16836 |
|
16837 |
|
16838 |
|
16839 |
|
16840 |
|
16841 | Text.prototype.getDimensions = function(text, options) {
|
16842 | return this.layoutText(text, options).dimensions;
|
16843 | };
|
16844 |
|
16845 | |
16846 |
|
16847 |
|
16848 |
|
16849 |
|
16850 |
|
16851 |
|
16852 |
|
16853 |
|
16854 |
|
16855 |
|
16856 |
|
16857 |
|
16858 |
|
16859 |
|
16860 |
|
16861 | Text.prototype.layoutText = function(text, options) {
|
16862 | var box = assign({}, this._config.size, options.box),
|
16863 | style = assign({}, this._config.style, options.style),
|
16864 | align = parseAlign(options.align || this._config.align),
|
16865 | padding = parsePadding(options.padding !== undefined ? options.padding : this._config.padding),
|
16866 | fitBox = options.fitBox || false;
|
16867 |
|
16868 | var lineHeight = getLineHeight(style);
|
16869 |
|
16870 | var lines = text.split(/\r?\n/g),
|
16871 | layouted = [];
|
16872 |
|
16873 | var maxWidth = box.width - padding.left - padding.right;
|
16874 |
|
16875 |
|
16876 | var helperText = create('text');
|
16877 | attr$1(helperText, { x: 0, y: 0 });
|
16878 | attr$1(helperText, style);
|
16879 |
|
16880 | var helperSvg = getHelperSvg();
|
16881 |
|
16882 | append(helperSvg, helperText);
|
16883 |
|
16884 | while (lines.length) {
|
16885 | layouted.push(layoutNext(lines, maxWidth, helperText));
|
16886 | }
|
16887 |
|
16888 | if (align.vertical === 'middle') {
|
16889 | padding.top = padding.bottom = 0;
|
16890 | }
|
16891 |
|
16892 | var totalHeight = reduce(layouted, function(sum, line, idx) {
|
16893 | return sum + (lineHeight || line.height);
|
16894 | }, 0) + padding.top + padding.bottom;
|
16895 |
|
16896 | var maxLineWidth = reduce(layouted, function(sum, line, idx) {
|
16897 | return line.width > sum ? line.width : sum;
|
16898 | }, 0);
|
16899 |
|
16900 |
|
16901 | var y = padding.top;
|
16902 |
|
16903 | if (align.vertical === 'middle') {
|
16904 | y += (box.height - totalHeight) / 2;
|
16905 | }
|
16906 |
|
16907 |
|
16908 | y -= (lineHeight || layouted[0].height) / 4;
|
16909 |
|
16910 |
|
16911 | var textElement = create('text');
|
16912 |
|
16913 | attr$1(textElement, style);
|
16914 |
|
16915 |
|
16916 |
|
16917 | forEach(layouted, function(line) {
|
16918 |
|
16919 | var x;
|
16920 |
|
16921 | y += (lineHeight || line.height);
|
16922 |
|
16923 | switch (align.horizontal) {
|
16924 | case 'left':
|
16925 | x = padding.left;
|
16926 | break;
|
16927 |
|
16928 | case 'right':
|
16929 | x = ((fitBox ? maxLineWidth : maxWidth)
|
16930 | - padding.right - line.width);
|
16931 | break;
|
16932 |
|
16933 | default:
|
16934 |
|
16935 |
|
16936 | x = Math.max((((fitBox ? maxLineWidth : maxWidth)
|
16937 | - line.width) / 2 + padding.left), 0);
|
16938 | }
|
16939 |
|
16940 | var tspan = create('tspan');
|
16941 | attr$1(tspan, { x: x, y: y });
|
16942 |
|
16943 | tspan.textContent = line.text;
|
16944 |
|
16945 | append(textElement, tspan);
|
16946 | });
|
16947 |
|
16948 | remove$1(helperText);
|
16949 |
|
16950 | var dimensions = {
|
16951 | width: maxLineWidth,
|
16952 | height: totalHeight
|
16953 | };
|
16954 |
|
16955 | return {
|
16956 | dimensions: dimensions,
|
16957 | element: textElement
|
16958 | };
|
16959 | };
|
16960 |
|
16961 |
|
16962 | function getLineHeight(style) {
|
16963 | if ('fontSize' in style && 'lineHeight' in style) {
|
16964 | return style.lineHeight * parseInt(style.fontSize, 10);
|
16965 | }
|
16966 | }
|
16967 |
|
16968 | var DEFAULT_FONT_SIZE = 12;
|
16969 | var LINE_HEIGHT_RATIO = 1.2;
|
16970 |
|
16971 | var MIN_TEXT_ANNOTATION_HEIGHT = 30;
|
16972 |
|
16973 |
|
16974 | function TextRenderer(config) {
|
16975 |
|
16976 | var defaultStyle = assign({
|
16977 | fontFamily: 'Arial, sans-serif',
|
16978 | fontSize: DEFAULT_FONT_SIZE,
|
16979 | fontWeight: 'normal',
|
16980 | lineHeight: LINE_HEIGHT_RATIO
|
16981 | }, config && config.defaultStyle || {});
|
16982 |
|
16983 | var fontSize = parseInt(defaultStyle.fontSize, 10) - 1;
|
16984 |
|
16985 | var externalStyle = assign({}, defaultStyle, {
|
16986 | fontSize: fontSize
|
16987 | }, config && config.externalStyle || {});
|
16988 |
|
16989 | var textUtil = new Text({
|
16990 | style: defaultStyle
|
16991 | });
|
16992 |
|
16993 | |
16994 |
|
16995 |
|
16996 |
|
16997 |
|
16998 |
|
16999 |
|
17000 |
|
17001 |
|
17002 | this.getExternalLabelBounds = function(bounds, text) {
|
17003 |
|
17004 | var layoutedDimensions = textUtil.getDimensions(text, {
|
17005 | box: {
|
17006 | width: 90,
|
17007 | height: 30,
|
17008 | x: bounds.width / 2 + bounds.x,
|
17009 | y: bounds.height / 2 + bounds.y
|
17010 | },
|
17011 | style: externalStyle
|
17012 | });
|
17013 |
|
17014 |
|
17015 | return {
|
17016 | x: Math.round(bounds.x + bounds.width / 2 - layoutedDimensions.width / 2),
|
17017 | y: Math.round(bounds.y),
|
17018 | width: Math.ceil(layoutedDimensions.width),
|
17019 | height: Math.ceil(layoutedDimensions.height)
|
17020 | };
|
17021 |
|
17022 | };
|
17023 |
|
17024 | |
17025 |
|
17026 |
|
17027 |
|
17028 |
|
17029 |
|
17030 |
|
17031 |
|
17032 | this.getTextAnnotationBounds = function(bounds, text) {
|
17033 |
|
17034 | var layoutedDimensions = textUtil.getDimensions(text, {
|
17035 | box: bounds,
|
17036 | style: defaultStyle,
|
17037 | align: 'left-top',
|
17038 | padding: 5
|
17039 | });
|
17040 |
|
17041 | return {
|
17042 | x: bounds.x,
|
17043 | y: bounds.y,
|
17044 | width: bounds.width,
|
17045 | height: Math.max(MIN_TEXT_ANNOTATION_HEIGHT, Math.round(layoutedDimensions.height))
|
17046 | };
|
17047 | };
|
17048 |
|
17049 | |
17050 |
|
17051 |
|
17052 |
|
17053 |
|
17054 |
|
17055 |
|
17056 |
|
17057 | this.createText = function(text, options) {
|
17058 | return textUtil.createText(text, options || {});
|
17059 | };
|
17060 |
|
17061 | |
17062 |
|
17063 |
|
17064 | this.getDefaultStyle = function() {
|
17065 | return defaultStyle;
|
17066 | };
|
17067 |
|
17068 | |
17069 |
|
17070 |
|
17071 | this.getExternalStyle = function() {
|
17072 | return externalStyle;
|
17073 | };
|
17074 |
|
17075 | }
|
17076 |
|
17077 | TextRenderer.$inject = [
|
17078 | 'config.textRenderer'
|
17079 | ];
|
17080 |
|
17081 | |
17082 |
|
17083 |
|
17084 |
|
17085 | function PathMap() {
|
17086 |
|
17087 | |
17088 |
|
17089 |
|
17090 |
|
17091 |
|
17092 |
|
17093 |
|
17094 |
|
17095 |
|
17096 |
|
17097 |
|
17098 |
|
17099 |
|
17100 |
|
17101 |
|
17102 |
|
17103 |
|
17104 |
|
17105 |
|
17106 |
|
17107 |
|
17108 |
|
17109 |
|
17110 |
|
17111 |
|
17112 |
|
17113 |
|
17114 |
|
17115 |
|
17116 |
|
17117 |
|
17118 | this.pathMap = {
|
17119 | 'EVENT_MESSAGE': {
|
17120 | 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}',
|
17121 | height: 36,
|
17122 | width: 36,
|
17123 | heightElements: [6, 14],
|
17124 | widthElements: [10.5, 21]
|
17125 | },
|
17126 | 'EVENT_SIGNAL': {
|
17127 | d: 'M {mx},{my} l {e.x0},{e.y0} l -{e.x1},0 Z',
|
17128 | height: 36,
|
17129 | width: 36,
|
17130 | heightElements: [18],
|
17131 | widthElements: [10, 20]
|
17132 | },
|
17133 | 'EVENT_ESCALATION': {
|
17134 | d: 'M {mx},{my} l {e.x0},{e.y0} l -{e.x0},-{e.y1} l -{e.x0},{e.y1} Z',
|
17135 | height: 36,
|
17136 | width: 36,
|
17137 | heightElements: [20, 7],
|
17138 | widthElements: [8]
|
17139 | },
|
17140 | 'EVENT_CONDITIONAL': {
|
17141 | d: 'M {e.x0},{e.y0} l {e.x1},0 l 0,{e.y2} l -{e.x1},0 Z ' +
|
17142 | 'M {e.x2},{e.y3} l {e.x0},0 ' +
|
17143 | 'M {e.x2},{e.y4} l {e.x0},0 ' +
|
17144 | 'M {e.x2},{e.y5} l {e.x0},0 ' +
|
17145 | 'M {e.x2},{e.y6} l {e.x0},0 ' +
|
17146 | 'M {e.x2},{e.y7} l {e.x0},0 ' +
|
17147 | 'M {e.x2},{e.y8} l {e.x0},0 ',
|
17148 | height: 36,
|
17149 | width: 36,
|
17150 | heightElements: [8.5, 14.5, 18, 11.5, 14.5, 17.5, 20.5, 23.5, 26.5],
|
17151 | widthElements: [10.5, 14.5, 12.5]
|
17152 | },
|
17153 | 'EVENT_LINK': {
|
17154 | 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',
|
17155 | height: 36,
|
17156 | width: 36,
|
17157 | heightElements: [4.4375, 6.75, 7.8125],
|
17158 | widthElements: [9.84375, 13.5]
|
17159 | },
|
17160 | 'EVENT_ERROR': {
|
17161 | 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',
|
17162 | height: 36,
|
17163 | width: 36,
|
17164 | heightElements: [0.023, 8.737, 8.151, 16.564, 10.591, 8.714],
|
17165 | widthElements: [0.085, 6.672, 6.97, 4.273, 5.337, 6.636]
|
17166 | },
|
17167 | 'EVENT_CANCEL_45': {
|
17168 | d: 'm {mx},{my} -{e.x1},0 0,{e.x0} {e.x1},0 0,{e.y1} {e.x0},0 ' +
|
17169 | '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z',
|
17170 | height: 36,
|
17171 | width: 36,
|
17172 | heightElements: [4.75, 8.5],
|
17173 | widthElements: [4.75, 8.5]
|
17174 | },
|
17175 | 'EVENT_COMPENSATION': {
|
17176 | 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',
|
17177 | height: 36,
|
17178 | width: 36,
|
17179 | heightElements: [6.5, 13, 0.4, 6.1],
|
17180 | widthElements: [9, 9.3, 8.7]
|
17181 | },
|
17182 | 'EVENT_TIMER_WH': {
|
17183 | d: 'M {mx},{my} l {e.x0},-{e.y0} m -{e.x0},{e.y0} l {e.x1},{e.y1} ',
|
17184 | height: 36,
|
17185 | width: 36,
|
17186 | heightElements: [10, 2],
|
17187 | widthElements: [3, 7]
|
17188 | },
|
17189 | 'EVENT_TIMER_LINE': {
|
17190 | d: 'M {mx},{my} ' +
|
17191 | 'm {e.x0},{e.y0} l -{e.x1},{e.y1} ',
|
17192 | height: 36,
|
17193 | width: 36,
|
17194 | heightElements: [10, 3],
|
17195 | widthElements: [0, 0]
|
17196 | },
|
17197 | 'EVENT_MULTIPLE': {
|
17198 | d:'m {mx},{my} {e.x1},-{e.y0} {e.x1},{e.y0} -{e.x0},{e.y1} -{e.x2},0 z',
|
17199 | height: 36,
|
17200 | width: 36,
|
17201 | heightElements: [6.28099, 12.56199],
|
17202 | widthElements: [3.1405, 9.42149, 12.56198]
|
17203 | },
|
17204 | 'EVENT_PARALLEL_MULTIPLE': {
|
17205 | d:'m {mx},{my} {e.x0},0 0,{e.y1} {e.x1},0 0,{e.y0} -{e.x1},0 0,{e.y1} ' +
|
17206 | '-{e.x0},0 0,-{e.y1} -{e.x1},0 0,-{e.y0} {e.x1},0 z',
|
17207 | height: 36,
|
17208 | width: 36,
|
17209 | heightElements: [2.56228, 7.68683],
|
17210 | widthElements: [2.56228, 7.68683]
|
17211 | },
|
17212 | 'GATEWAY_EXCLUSIVE': {
|
17213 | d:'m {mx},{my} {e.x0},{e.y0} {e.x1},{e.y0} {e.x2},0 {e.x4},{e.y2} ' +
|
17214 | '{e.x4},{e.y1} {e.x2},0 {e.x1},{e.y3} {e.x0},{e.y3} ' +
|
17215 | '{e.x3},0 {e.x5},{e.y1} {e.x5},{e.y2} {e.x3},0 z',
|
17216 | height: 17.5,
|
17217 | width: 17.5,
|
17218 | heightElements: [8.5, 6.5312, -6.5312, -8.5],
|
17219 | widthElements: [6.5, -6.5, 3, -3, 5, -5]
|
17220 | },
|
17221 | 'GATEWAY_PARALLEL': {
|
17222 | d:'m {mx},{my} 0,{e.y1} -{e.x1},0 0,{e.y0} {e.x1},0 0,{e.y1} {e.x0},0 ' +
|
17223 | '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z',
|
17224 | height: 30,
|
17225 | width: 30,
|
17226 | heightElements: [5, 12.5],
|
17227 | widthElements: [5, 12.5]
|
17228 | },
|
17229 | 'GATEWAY_EVENT_BASED': {
|
17230 | d:'m {mx},{my} {e.x0},{e.y0} {e.x0},{e.y1} {e.x1},{e.y2} {e.x2},0 z',
|
17231 | height: 11,
|
17232 | width: 11,
|
17233 | heightElements: [-6, 6, 12, -12],
|
17234 | widthElements: [9, -3, -12]
|
17235 | },
|
17236 | 'GATEWAY_COMPLEX': {
|
17237 | 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} ' +
|
17238 | '{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} ' +
|
17239 | '{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} ' +
|
17240 | '-{e.x0},{e.y1} 0,-{e.y0} -{e.x3},0 z',
|
17241 | height: 17.125,
|
17242 | width: 17.125,
|
17243 | heightElements: [4.875, 3.4375, 2.125, 3],
|
17244 | widthElements: [3.4375, 2.125, 4.875, 3]
|
17245 | },
|
17246 | 'DATA_OBJECT_PATH': {
|
17247 | 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',
|
17248 | height: 61,
|
17249 | width: 51,
|
17250 | heightElements: [10, 50, 60],
|
17251 | widthElements: [10, 40, 50, 60]
|
17252 | },
|
17253 | 'DATA_OBJECT_COLLECTION_PATH': {
|
17254 | d:'m {mx}, {my} ' +
|
17255 | 'm 0 15 l 0 -15 ' +
|
17256 | 'm 4 15 l 0 -15 ' +
|
17257 | 'm 4 15 l 0 -15 ',
|
17258 | height: 61,
|
17259 | width: 51,
|
17260 | heightElements: [12],
|
17261 | widthElements: [1, 6, 12, 15]
|
17262 | },
|
17263 | 'DATA_ARROW': {
|
17264 | d:'m 5,9 9,0 0,-3 5,5 -5,5 0,-3 -9,0 z',
|
17265 | height: 61,
|
17266 | width: 51,
|
17267 | heightElements: [],
|
17268 | widthElements: []
|
17269 | },
|
17270 | 'DATA_STORE': {
|
17271 | d:'m {mx},{my} ' +
|
17272 | 'l 0,{e.y2} ' +
|
17273 | 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' +
|
17274 | 'l 0,-{e.y2} ' +
|
17275 | 'c -{e.x0},-{e.y1} -{e.x1},-{e.y1} -{e.x2},0' +
|
17276 | 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' +
|
17277 | 'm -{e.x2},{e.y0}' +
|
17278 | 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0' +
|
17279 | 'm -{e.x2},{e.y0}' +
|
17280 | 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0',
|
17281 | height: 61,
|
17282 | width: 61,
|
17283 | heightElements: [7, 10, 45],
|
17284 | widthElements: [2, 58, 60]
|
17285 | },
|
17286 | 'TEXT_ANNOTATION': {
|
17287 | d: 'm {mx}, {my} m 10,0 l -10,0 l 0,{e.y0} l 10,0',
|
17288 | height: 30,
|
17289 | width: 10,
|
17290 | heightElements: [30],
|
17291 | widthElements: [10]
|
17292 | },
|
17293 | 'MARKER_SUB_PROCESS': {
|
17294 | d: 'm{mx},{my} m 7,2 l 0,10 m -5,-5 l 10,0',
|
17295 | height: 10,
|
17296 | width: 10,
|
17297 | heightElements: [],
|
17298 | widthElements: []
|
17299 | },
|
17300 | 'MARKER_PARALLEL': {
|
17301 | d: 'm{mx},{my} m 3,2 l 0,10 m 3,-10 l 0,10 m 3,-10 l 0,10',
|
17302 | height: 10,
|
17303 | width: 10,
|
17304 | heightElements: [],
|
17305 | widthElements: []
|
17306 | },
|
17307 | 'MARKER_SEQUENTIAL': {
|
17308 | d: 'm{mx},{my} m 0,3 l 10,0 m -10,3 l 10,0 m -10,3 l 10,0',
|
17309 | height: 10,
|
17310 | width: 10,
|
17311 | heightElements: [],
|
17312 | widthElements: []
|
17313 | },
|
17314 | 'MARKER_COMPENSATION': {
|
17315 | 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',
|
17316 | height: 10,
|
17317 | width: 21,
|
17318 | heightElements: [],
|
17319 | widthElements: []
|
17320 | },
|
17321 | 'MARKER_LOOP': {
|
17322 | d: 'm {mx},{my} c 3.526979,0 6.386161,-2.829858 6.386161,-6.320661 0,-3.490806 -2.859182,-6.320661 ' +
|
17323 | '-6.386161,-6.320661 -3.526978,0 -6.38616,2.829855 -6.38616,6.320661 0,1.745402 ' +
|
17324 | '0.714797,3.325567 1.870463,4.469381 0.577834,0.571908 1.265885,1.034728 2.029916,1.35457 ' +
|
17325 | 'l -0.718163,-3.909793 m 0.718163,3.909793 -3.885211,0.802902',
|
17326 | height: 13.9,
|
17327 | width: 13.7,
|
17328 | heightElements: [],
|
17329 | widthElements: []
|
17330 | },
|
17331 | 'MARKER_ADHOC': {
|
17332 | 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 ' +
|
17333 | '3.85579,1.15803 5.76082,1.79107 1.06385,0.34139996 2.24454,0.1438 3.18759,-0.43767 0.61743,-0.33642 ' +
|
17334 | '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 ' +
|
17335 | '-3.6918,1.66181996 -1.24459,0.0927 -2.46671,-0.2491 -3.59505,-0.74812 -1.35789,-0.55965 ' +
|
17336 | '-2.75133,-1.33436996 -4.27027,-1.18121996 -1.37741,0.14601 -2.41842,1.13685996 -3.44288,1.96782996 z',
|
17337 | height: 4,
|
17338 | width: 15,
|
17339 | heightElements: [],
|
17340 | widthElements: []
|
17341 | },
|
17342 | 'TASK_TYPE_SEND': {
|
17343 | 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}',
|
17344 | height: 14,
|
17345 | width: 21,
|
17346 | heightElements: [6, 14],
|
17347 | widthElements: [10.5, 21]
|
17348 | },
|
17349 | 'TASK_TYPE_SCRIPT': {
|
17350 | d: 'm {mx},{my} c 9.966553,-6.27276 -8.000926,-7.91932 2.968968,-14.938 l -8.802728,0 ' +
|
17351 | 'c -10.969894,7.01868 6.997585,8.66524 -2.968967,14.938 z ' +
|
17352 | 'm -7,-12 l 5,0 ' +
|
17353 | 'm -4.5,3 l 4.5,0 ' +
|
17354 | 'm -3,3 l 5,0' +
|
17355 | 'm -4,3 l 5,0',
|
17356 | height: 15,
|
17357 | width: 12.6,
|
17358 | heightElements: [6, 14],
|
17359 | widthElements: [10.5, 21]
|
17360 | },
|
17361 | 'TASK_TYPE_USER_1': {
|
17362 | d: 'm {mx},{my} c 0.909,-0.845 1.594,-2.049 1.594,-3.385 0,-2.554 -1.805,-4.62199999 ' +
|
17363 | '-4.357,-4.62199999 -2.55199998,0 -4.28799998,2.06799999 -4.28799998,4.62199999 0,1.348 ' +
|
17364 | '0.974,2.562 1.89599998,3.405 -0.52899998,0.187 -5.669,2.097 -5.794,4.7560005 v 6.718 ' +
|
17365 | 'h 17 v -6.718 c 0,-2.2980005 -5.5279996,-4.5950005 -6.0509996,-4.7760005 z' +
|
17366 | 'm -8,6 l 0,5.5 m 11,0 l 0,-5'
|
17367 | },
|
17368 | 'TASK_TYPE_USER_2': {
|
17369 | d: 'm {mx},{my} m 2.162,1.009 c 0,2.4470005 -2.158,4.4310005 -4.821,4.4310005 ' +
|
17370 | '-2.66499998,0 -4.822,-1.981 -4.822,-4.4310005 '
|
17371 | },
|
17372 | 'TASK_TYPE_USER_3': {
|
17373 | 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 ' +
|
17374 | '4.124,0.965 -0.098,-0.57 -0.117,-3.79099999 -4.191,-4.13599999 -3.57499998,0.001 ' +
|
17375 | '-4.20799998,3.36699999 -4.20699998,4.34799999 z'
|
17376 | },
|
17377 | 'TASK_TYPE_MANUAL': {
|
17378 | 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 ' +
|
17379 | '-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 ' +
|
17380 | '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 ' +
|
17381 | '-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 ' +
|
17382 | '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 ' +
|
17383 | '-10.86,-0.003 -11.0829995,-0.003 -0.022,-0.047 -0.045,-0.094 -0.069,-0.139 0.3939995,-0.319 ' +
|
17384 | '2.0409995,-1.626 2.4149995,-2.017 0.469,-0.4870005 0.519,-1.1650005 0.162,-1.6040005 -0.414,-0.511 ' +
|
17385 | '-0.973,-0.5 -1.48,-0.236 -1.4609995,0.764 -6.5999995,3.6430005 -7.7329995,4.2710005 -0.9,0.499 ' +
|
17386 | '-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 ' +
|
17387 | '-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 ' +
|
17388 | '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 ' +
|
17389 | '-5.824,-0.004 -6.04,-0.004 10e-4,-0.084 0.003,-0.586 10e-4,-0.67 z'
|
17390 | },
|
17391 | 'TASK_TYPE_INSTANTIATING_SEND': {
|
17392 | 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'
|
17393 | },
|
17394 | 'TASK_TYPE_SERVICE': {
|
17395 | d: 'm {mx},{my} v -1.71335 c 0.352326,-0.0705 0.703932,-0.17838 1.047628,-0.32133 ' +
|
17396 | '0.344416,-0.14465 0.665822,-0.32133 0.966377,-0.52145 l 1.19431,1.18005 1.567487,-1.57688 ' +
|
17397 | '-1.195028,-1.18014 c 0.403376,-0.61394 0.683079,-1.29908 0.825447,-2.01824 l 1.622133,-0.01 ' +
|
17398 | 'v -2.2196 l -1.636514,0.01 c -0.07333,-0.35153 -0.178319,-0.70024 -0.323564,-1.04372 ' +
|
17399 | '-0.145244,-0.34406 -0.321407,-0.6644 -0.522735,-0.96217 l 1.131035,-1.13631 -1.583305,-1.56293 ' +
|
17400 | '-1.129598,1.13589 c -0.614052,-0.40108 -1.302883,-0.68093 -2.022633,-0.82247 l 0.0093,-1.61852 ' +
|
17401 | '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 ' +
|
17402 | '-0.665102,0.32092 -0.9635006,0.52046 l -1.1698628,-1.15823 -1.5667691,1.5792 1.1684265,1.15669 ' +
|
17403 | 'c -0.4026573,0.61283 -0.68308,1.29797 -0.8247287,2.01713 l -1.6588041,0.003 v 2.22174 ' +
|
17404 | 'l 1.6724648,-0.006 c 0.073327,0.35077 0.1797598,0.70243 0.3242851,1.04472 0.1452428,0.34448 ' +
|
17405 | '0.3214064,0.6644 0.5227339,0.96066 l -1.1993431,1.19723 1.5840256,1.56011 1.1964668,-1.19348 ' +
|
17406 | 'c 0.6140517,0.40346 1.3028827,0.68232 2.0233517,0.82331 l 7.19e-4,1.69892 h 2.226848 z ' +
|
17407 | 'm 0.221462,-3.9957 c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' +
|
17408 | '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' +
|
17409 | '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z'
|
17410 | },
|
17411 | 'TASK_TYPE_SERVICE_FILL': {
|
17412 | d: 'm {mx},{my} c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' +
|
17413 | '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' +
|
17414 | '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z'
|
17415 | },
|
17416 | 'TASK_TYPE_BUSINESS_RULE_HEADER': {
|
17417 | d: 'm {mx},{my} 0,4 20,0 0,-4 z'
|
17418 | },
|
17419 | 'TASK_TYPE_BUSINESS_RULE_MAIN': {
|
17420 | d: 'm {mx},{my} 0,12 20,0 0,-12 z' +
|
17421 | 'm 0,8 l 20,0 ' +
|
17422 | 'm -13,-4 l 0,8'
|
17423 | },
|
17424 | 'MESSAGE_FLOW_MARKER': {
|
17425 | 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'
|
17426 | }
|
17427 | };
|
17428 |
|
17429 | this.getRawPath = function getRawPath(pathId) {
|
17430 | return this.pathMap[pathId].d;
|
17431 | };
|
17432 |
|
17433 | |
17434 |
|
17435 |
|
17436 |
|
17437 |
|
17438 |
|
17439 |
|
17440 |
|
17441 |
|
17442 |
|
17443 |
|
17444 |
|
17445 |
|
17446 |
|
17447 |
|
17448 |
|
17449 |
|
17450 |
|
17451 |
|
17452 |
|
17453 |
|
17454 |
|
17455 |
|
17456 |
|
17457 |
|
17458 |
|
17459 |
|
17460 |
|
17461 |
|
17462 |
|
17463 |
|
17464 |
|
17465 |
|
17466 |
|
17467 |
|
17468 |
|
17469 |
|
17470 |
|
17471 |
|
17472 |
|
17473 |
|
17474 |
|
17475 |
|
17476 |
|
17477 |
|
17478 |
|
17479 |
|
17480 |
|
17481 |
|
17482 | this.getScaledPath = function getScaledPath(pathId, param) {
|
17483 | var rawPath = this.pathMap[pathId];
|
17484 |
|
17485 |
|
17486 |
|
17487 | var mx, my;
|
17488 |
|
17489 | if (param.abspos) {
|
17490 | mx = param.abspos.x;
|
17491 | my = param.abspos.y;
|
17492 | } else {
|
17493 | mx = param.containerWidth * param.position.mx;
|
17494 | my = param.containerHeight * param.position.my;
|
17495 | }
|
17496 |
|
17497 | var coordinates = {};
|
17498 | if (param.position) {
|
17499 |
|
17500 |
|
17501 | var heightRatio = (param.containerHeight / rawPath.height) * param.yScaleFactor;
|
17502 | var widthRatio = (param.containerWidth / rawPath.width) * param.xScaleFactor;
|
17503 |
|
17504 |
|
17505 |
|
17506 | for (var heightIndex = 0; heightIndex < rawPath.heightElements.length; heightIndex++) {
|
17507 | coordinates['y' + heightIndex] = rawPath.heightElements[heightIndex] * heightRatio;
|
17508 | }
|
17509 |
|
17510 |
|
17511 | for (var widthIndex = 0; widthIndex < rawPath.widthElements.length; widthIndex++) {
|
17512 | coordinates['x' + widthIndex] = rawPath.widthElements[widthIndex] * widthRatio;
|
17513 | }
|
17514 | }
|
17515 |
|
17516 |
|
17517 | var path = format(
|
17518 | rawPath.d, {
|
17519 | mx: mx,
|
17520 | my: my,
|
17521 | e: coordinates
|
17522 | }
|
17523 | );
|
17524 | return path;
|
17525 | };
|
17526 | }
|
17527 |
|
17528 |
|
17529 |
|
17530 |
|
17531 | var tokenRegex = /\{([^}]+)\}/g,
|
17532 | objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g;
|
17533 |
|
17534 | function replacer(all, key, obj) {
|
17535 | var res = obj;
|
17536 | key.replace(objNotationRegex, function(all, name, quote, quotedName, isFunc) {
|
17537 | name = name || quotedName;
|
17538 | if (res) {
|
17539 | if (name in res) {
|
17540 | res = res[name];
|
17541 | }
|
17542 | typeof res == 'function' && isFunc && (res = res());
|
17543 | }
|
17544 | });
|
17545 | res = (res == null || res == obj ? all : res) + '';
|
17546 |
|
17547 | return res;
|
17548 | }
|
17549 |
|
17550 | function format(str, obj) {
|
17551 | return String(str).replace(tokenRegex, function(all, key) {
|
17552 | return replacer(all, key, obj);
|
17553 | });
|
17554 | }
|
17555 |
|
17556 | var DrawModule$1 = {
|
17557 | __init__: [ 'bpmnRenderer' ],
|
17558 | bpmnRenderer: [ 'type', BpmnRenderer ],
|
17559 | textRenderer: [ 'type', TextRenderer ],
|
17560 | pathMap: [ 'type', PathMap ]
|
17561 | };
|
17562 |
|
17563 | |
17564 |
|
17565 |
|
17566 |
|
17567 |
|
17568 |
|
17569 |
|
17570 |
|
17571 |
|
17572 |
|
17573 |
|
17574 |
|
17575 |
|
17576 |
|
17577 |
|
17578 |
|
17579 |
|
17580 |
|
17581 | function translate$1(template, replacements) {
|
17582 |
|
17583 | replacements = replacements || {};
|
17584 |
|
17585 | return template.replace(/{([^}]+)}/g, function(_, key) {
|
17586 | return replacements[key] || '{' + key + '}';
|
17587 | });
|
17588 | }
|
17589 |
|
17590 | var translate$2 = {
|
17591 | translate: [ 'value', translate$1 ]
|
17592 | };
|
17593 |
|
17594 | var DEFAULT_LABEL_SIZE$1 = {
|
17595 | width: 90,
|
17596 | height: 20
|
17597 | };
|
17598 |
|
17599 | var FLOW_LABEL_INDENT = 15;
|
17600 |
|
17601 |
|
17602 | |
17603 |
|
17604 |
|
17605 |
|
17606 |
|
17607 |
|
17608 | function isLabelExternal(semantic) {
|
17609 | return is$1(semantic, 'bpmn:Event') ||
|
17610 | is$1(semantic, 'bpmn:Gateway') ||
|
17611 | is$1(semantic, 'bpmn:DataStoreReference') ||
|
17612 | is$1(semantic, 'bpmn:DataObjectReference') ||
|
17613 | is$1(semantic, 'bpmn:DataInput') ||
|
17614 | is$1(semantic, 'bpmn:DataOutput') ||
|
17615 | is$1(semantic, 'bpmn:SequenceFlow') ||
|
17616 | is$1(semantic, 'bpmn:MessageFlow') ||
|
17617 | is$1(semantic, 'bpmn:Group');
|
17618 | }
|
17619 |
|
17620 | |
17621 |
|
17622 |
|
17623 |
|
17624 |
|
17625 |
|
17626 | function hasExternalLabel(element) {
|
17627 | return isLabel(element.label);
|
17628 | }
|
17629 |
|
17630 | |
17631 |
|
17632 |
|
17633 |
|
17634 |
|
17635 |
|
17636 | function getFlowLabelPosition(waypoints) {
|
17637 |
|
17638 |
|
17639 | var mid = waypoints.length / 2 - 1;
|
17640 |
|
17641 | var first = waypoints[Math.floor(mid)];
|
17642 | var second = waypoints[Math.ceil(mid + 0.01)];
|
17643 |
|
17644 |
|
17645 | var position = getWaypointsMid(waypoints);
|
17646 |
|
17647 |
|
17648 | var angle = Math.atan((second.y - first.y) / (second.x - first.x));
|
17649 |
|
17650 | var x = position.x,
|
17651 | y = position.y;
|
17652 |
|
17653 | if (Math.abs(angle) < Math.PI / 2) {
|
17654 | y -= FLOW_LABEL_INDENT;
|
17655 | } else {
|
17656 | x += FLOW_LABEL_INDENT;
|
17657 | }
|
17658 |
|
17659 | return { x: x, y: y };
|
17660 | }
|
17661 |
|
17662 |
|
17663 | |
17664 |
|
17665 |
|
17666 |
|
17667 |
|
17668 |
|
17669 | function getWaypointsMid(waypoints) {
|
17670 |
|
17671 | var mid = waypoints.length / 2 - 1;
|
17672 |
|
17673 | var first = waypoints[Math.floor(mid)];
|
17674 | var second = waypoints[Math.ceil(mid + 0.01)];
|
17675 |
|
17676 | return {
|
17677 | x: first.x + (second.x - first.x) / 2,
|
17678 | y: first.y + (second.y - first.y) / 2
|
17679 | };
|
17680 | }
|
17681 |
|
17682 |
|
17683 | function getExternalLabelMid(element) {
|
17684 |
|
17685 | if (element.waypoints) {
|
17686 | return getFlowLabelPosition(element.waypoints);
|
17687 | } else if (is$1(element, 'bpmn:Group')) {
|
17688 | return {
|
17689 | x: element.x + element.width / 2,
|
17690 | y: element.y + DEFAULT_LABEL_SIZE$1.height / 2
|
17691 | };
|
17692 | } else {
|
17693 | return {
|
17694 | x: element.x + element.width / 2,
|
17695 | y: element.y + element.height + DEFAULT_LABEL_SIZE$1.height / 2
|
17696 | };
|
17697 | }
|
17698 | }
|
17699 |
|
17700 |
|
17701 | |
17702 |
|
17703 |
|
17704 |
|
17705 |
|
17706 |
|
17707 |
|
17708 | function getExternalLabelBounds(semantic, element) {
|
17709 |
|
17710 | var mid,
|
17711 | size,
|
17712 | bounds,
|
17713 | di = semantic.di,
|
17714 | label = di.label;
|
17715 |
|
17716 | if (label && label.bounds) {
|
17717 | bounds = label.bounds;
|
17718 |
|
17719 | size = {
|
17720 | width: Math.max(DEFAULT_LABEL_SIZE$1.width, bounds.width),
|
17721 | height: bounds.height
|
17722 | };
|
17723 |
|
17724 | mid = {
|
17725 | x: bounds.x + bounds.width / 2,
|
17726 | y: bounds.y + bounds.height / 2
|
17727 | };
|
17728 | } else {
|
17729 |
|
17730 | mid = getExternalLabelMid(element);
|
17731 |
|
17732 | size = DEFAULT_LABEL_SIZE$1;
|
17733 | }
|
17734 |
|
17735 | return assign({
|
17736 | x: mid.x - size.width / 2,
|
17737 | y: mid.y - size.height / 2
|
17738 | }, size);
|
17739 | }
|
17740 |
|
17741 | function isLabel(element) {
|
17742 | return element && !!element.labelTarget;
|
17743 | }
|
17744 |
|
17745 | |
17746 |
|
17747 |
|
17748 |
|
17749 |
|
17750 |
|
17751 |
|
17752 |
|
17753 | function pointDistance(a, b) {
|
17754 | if (!a || !b) {
|
17755 | return -1;
|
17756 | }
|
17757 |
|
17758 | return Math.sqrt(
|
17759 | Math.pow(a.x - b.x, 2) +
|
17760 | Math.pow(a.y - b.y, 2)
|
17761 | );
|
17762 | }
|
17763 |
|
17764 |
|
17765 | |
17766 |
|
17767 |
|
17768 |
|
17769 |
|
17770 |
|
17771 |
|
17772 |
|
17773 |
|
17774 |
|
17775 | function pointsOnLine(p, q, r, accuracy) {
|
17776 |
|
17777 | if (typeof accuracy === 'undefined') {
|
17778 | accuracy = 5;
|
17779 | }
|
17780 |
|
17781 | if (!p || !q || !r) {
|
17782 | return false;
|
17783 | }
|
17784 |
|
17785 | var val = (q.x - p.x) * (r.y - p.y) - (q.y - p.y) * (r.x - p.x),
|
17786 | dist = pointDistance(p, q);
|
17787 |
|
17788 |
|
17789 | return Math.abs(val / dist) <= accuracy;
|
17790 | }
|
17791 |
|
17792 |
|
17793 | var ALIGNED_THRESHOLD = 2;
|
17794 |
|
17795 | |
17796 |
|
17797 |
|
17798 |
|
17799 |
|
17800 |
|
17801 |
|
17802 |
|
17803 | function pointsAligned(a, b) {
|
17804 | var points;
|
17805 |
|
17806 | if (isArray(a)) {
|
17807 | points = a;
|
17808 | } else {
|
17809 | points = [ a, b ];
|
17810 | }
|
17811 |
|
17812 | if (pointsAlignedHorizontally(points)) {
|
17813 | return 'h';
|
17814 | }
|
17815 |
|
17816 | if (pointsAlignedVertically(points)) {
|
17817 | return 'v';
|
17818 | }
|
17819 |
|
17820 | return false;
|
17821 | }
|
17822 |
|
17823 | function pointsAlignedHorizontally(a, b) {
|
17824 | var points;
|
17825 |
|
17826 | if (isArray(a)) {
|
17827 | points = a;
|
17828 | } else {
|
17829 | points = [ a, b ];
|
17830 | }
|
17831 |
|
17832 | var firstPoint = points.slice().shift();
|
17833 |
|
17834 | return every(points, function(point) {
|
17835 | return Math.abs(firstPoint.y - point.y) <= ALIGNED_THRESHOLD;
|
17836 | });
|
17837 | }
|
17838 |
|
17839 | function pointsAlignedVertically(a, b) {
|
17840 | var points;
|
17841 |
|
17842 | if (isArray(a)) {
|
17843 | points = a;
|
17844 | } else {
|
17845 | points = [ a, b ];
|
17846 | }
|
17847 |
|
17848 | var firstPoint = points.slice().shift();
|
17849 |
|
17850 | return every(points, function(point) {
|
17851 | return Math.abs(firstPoint.x - point.x) <= ALIGNED_THRESHOLD;
|
17852 | });
|
17853 | }
|
17854 |
|
17855 |
|
17856 |
|
17857 | |
17858 |
|
17859 |
|
17860 |
|
17861 |
|
17862 |
|
17863 |
|
17864 |
|
17865 |
|
17866 | function pointInRect(p, rect, tolerance) {
|
17867 | tolerance = tolerance || 0;
|
17868 |
|
17869 | return p.x > rect.x - tolerance &&
|
17870 | p.y > rect.y - tolerance &&
|
17871 | p.x < rect.x + rect.width + tolerance &&
|
17872 | p.y < rect.y + rect.height + tolerance;
|
17873 | }
|
17874 |
|
17875 | |
17876 |
|
17877 |
|
17878 |
|
17879 |
|
17880 |
|
17881 |
|
17882 |
|
17883 | function getMidPoint(p, q) {
|
17884 | return {
|
17885 | x: Math.round(p.x + ((q.x - p.x) / 2.0)),
|
17886 | y: Math.round(p.y + ((q.y - p.y) / 2.0))
|
17887 | };
|
17888 | }
|
17889 |
|
17890 | |
17891 |
|
17892 |
|
17893 |
|
17894 |
|
17895 |
|
17896 |
|
17897 |
|
17898 | var p2s = /,?([a-z]),?/gi,
|
17899 | toFloat = parseFloat,
|
17900 | math = Math,
|
17901 | PI = math.PI,
|
17902 | mmin = math.min,
|
17903 | mmax = math.max,
|
17904 | pow = math.pow,
|
17905 | abs = math.abs,
|
17906 | pathCommand = /([a-z])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?[\s]*,?[\s]*)+)/ig,
|
17907 | pathValues = /(-?\d*\.?\d*(?:e[-+]?\\d+)?)[\s]*,?[\s]*/ig;
|
17908 |
|
17909 | var isArray$2 = Array.isArray || function(o) { return o instanceof Array; };
|
17910 |
|
17911 | function hasProperty(obj, property) {
|
17912 | return Object.prototype.hasOwnProperty.call(obj, property);
|
17913 | }
|
17914 |
|
17915 | function clone$1(obj) {
|
17916 |
|
17917 | if (typeof obj == 'function' || Object(obj) !== obj) {
|
17918 | return obj;
|
17919 | }
|
17920 |
|
17921 | var res = new obj.constructor;
|
17922 |
|
17923 | for (var key in obj) {
|
17924 | if (hasProperty(obj, key)) {
|
17925 | res[key] = clone$1(obj[key]);
|
17926 | }
|
17927 | }
|
17928 |
|
17929 | return res;
|
17930 | }
|
17931 |
|
17932 | function repush(array, item) {
|
17933 | for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
|
17934 | return array.push(array.splice(i, 1)[0]);
|
17935 | }
|
17936 | }
|
17937 |
|
17938 | function cacher(f) {
|
17939 |
|
17940 | function newf() {
|
17941 |
|
17942 | var arg = Array.prototype.slice.call(arguments, 0),
|
17943 | args = arg.join('\u2400'),
|
17944 | cache = newf.cache = newf.cache || {},
|
17945 | count = newf.count = newf.count || [];
|
17946 |
|
17947 | if (hasProperty(cache, args)) {
|
17948 | repush(count, args);
|
17949 | return cache[args];
|
17950 | }
|
17951 |
|
17952 | count.length >= 1e3 && delete cache[count.shift()];
|
17953 | count.push(args);
|
17954 | cache[args] = f.apply(0, arg);
|
17955 |
|
17956 | return cache[args];
|
17957 | }
|
17958 | return newf;
|
17959 | }
|
17960 |
|
17961 | function parsePathString(pathString) {
|
17962 |
|
17963 | if (!pathString) {
|
17964 | return null;
|
17965 | }
|
17966 |
|
17967 | var pth = paths(pathString);
|
17968 |
|
17969 | if (pth.arr) {
|
17970 | return clone$1(pth.arr);
|
17971 | }
|
17972 |
|
17973 | var paramCounts = { a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0 },
|
17974 | data = [];
|
17975 |
|
17976 | if (isArray$2(pathString) && isArray$2(pathString[0])) {
|
17977 | data = clone$1(pathString);
|
17978 | }
|
17979 |
|
17980 | if (!data.length) {
|
17981 |
|
17982 | String(pathString).replace(pathCommand, function(a, b, c) {
|
17983 | var params = [],
|
17984 | name = b.toLowerCase();
|
17985 |
|
17986 | c.replace(pathValues, function(a, b) {
|
17987 | b && params.push(+b);
|
17988 | });
|
17989 |
|
17990 | if (name == 'm' && params.length > 2) {
|
17991 | data.push([b].concat(params.splice(0, 2)));
|
17992 | name = 'l';
|
17993 | b = b == 'm' ? 'l' : 'L';
|
17994 | }
|
17995 |
|
17996 | while (params.length >= paramCounts[name]) {
|
17997 | data.push([b].concat(params.splice(0, paramCounts[name])));
|
17998 | if (!paramCounts[name]) {
|
17999 | break;
|
18000 | }
|
18001 | }
|
18002 | });
|
18003 | }
|
18004 |
|
18005 | data.toString = paths.toString;
|
18006 | pth.arr = clone$1(data);
|
18007 |
|
18008 | return data;
|
18009 | }
|
18010 |
|
18011 | function paths(ps) {
|
18012 | var p = paths.ps = paths.ps || {};
|
18013 |
|
18014 | if (p[ps]) {
|
18015 | p[ps].sleep = 100;
|
18016 | } else {
|
18017 | p[ps] = {
|
18018 | sleep: 100
|
18019 | };
|
18020 | }
|
18021 |
|
18022 | setTimeout(function() {
|
18023 | for (var key in p) {
|
18024 | if (hasProperty(p, key) && key != ps) {
|
18025 | p[key].sleep--;
|
18026 | !p[key].sleep && delete p[key];
|
18027 | }
|
18028 | }
|
18029 | });
|
18030 |
|
18031 | return p[ps];
|
18032 | }
|
18033 |
|
18034 | function rectBBox(x, y, width, height) {
|
18035 |
|
18036 | if (arguments.length === 1) {
|
18037 | y = x.y;
|
18038 | width = x.width;
|
18039 | height = x.height;
|
18040 | x = x.x;
|
18041 | }
|
18042 |
|
18043 | return {
|
18044 | x: x,
|
18045 | y: y,
|
18046 | width: width,
|
18047 | height: height,
|
18048 | x2: x + width,
|
18049 | y2: y + height
|
18050 | };
|
18051 | }
|
18052 |
|
18053 | function pathToString() {
|
18054 | return this.join(',').replace(p2s, '$1');
|
18055 | }
|
18056 |
|
18057 | function pathClone(pathArray) {
|
18058 | var res = clone$1(pathArray);
|
18059 | res.toString = pathToString;
|
18060 | return res;
|
18061 | }
|
18062 |
|
18063 | function findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
|
18064 | var t1 = 1 - t,
|
18065 | t13 = pow(t1, 3),
|
18066 | t12 = pow(t1, 2),
|
18067 | t2 = t * t,
|
18068 | t3 = t2 * t,
|
18069 | x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x,
|
18070 | y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y;
|
18071 |
|
18072 | return {
|
18073 | x: fixError(x),
|
18074 | y: fixError(y)
|
18075 | };
|
18076 | }
|
18077 |
|
18078 | function bezierBBox(points) {
|
18079 |
|
18080 | var bbox = curveBBox.apply(null, points);
|
18081 |
|
18082 | return rectBBox(
|
18083 | bbox.x0,
|
18084 | bbox.y0,
|
18085 | bbox.x1 - bbox.x0,
|
18086 | bbox.y1 - bbox.y0
|
18087 | );
|
18088 | }
|
18089 |
|
18090 | function isPointInsideBBox(bbox, x, y) {
|
18091 | return x >= bbox.x &&
|
18092 | x <= bbox.x + bbox.width &&
|
18093 | y >= bbox.y &&
|
18094 | y <= bbox.y + bbox.height;
|
18095 | }
|
18096 |
|
18097 | function isBBoxIntersect(bbox1, bbox2) {
|
18098 | bbox1 = rectBBox(bbox1);
|
18099 | bbox2 = rectBBox(bbox2);
|
18100 | return isPointInsideBBox(bbox2, bbox1.x, bbox1.y)
|
18101 | || isPointInsideBBox(bbox2, bbox1.x2, bbox1.y)
|
18102 | || isPointInsideBBox(bbox2, bbox1.x, bbox1.y2)
|
18103 | || isPointInsideBBox(bbox2, bbox1.x2, bbox1.y2)
|
18104 | || isPointInsideBBox(bbox1, bbox2.x, bbox2.y)
|
18105 | || isPointInsideBBox(bbox1, bbox2.x2, bbox2.y)
|
18106 | || isPointInsideBBox(bbox1, bbox2.x, bbox2.y2)
|
18107 | || isPointInsideBBox(bbox1, bbox2.x2, bbox2.y2)
|
18108 | || (bbox1.x < bbox2.x2 && bbox1.x > bbox2.x
|
18109 | || bbox2.x < bbox1.x2 && bbox2.x > bbox1.x)
|
18110 | && (bbox1.y < bbox2.y2 && bbox1.y > bbox2.y
|
18111 | || bbox2.y < bbox1.y2 && bbox2.y > bbox1.y);
|
18112 | }
|
18113 |
|
18114 | function base3(t, p1, p2, p3, p4) {
|
18115 | var t1 = -3 * p1 + 9 * p2 - 9 * p3 + 3 * p4,
|
18116 | t2 = t * t1 + 6 * p1 - 12 * p2 + 6 * p3;
|
18117 | return t * t2 - 3 * p1 + 3 * p2;
|
18118 | }
|
18119 |
|
18120 | function bezlen(x1, y1, x2, y2, x3, y3, x4, y4, z) {
|
18121 |
|
18122 | if (z == null) {
|
18123 | z = 1;
|
18124 | }
|
18125 |
|
18126 | z = z > 1 ? 1 : z < 0 ? 0 : z;
|
18127 |
|
18128 | var z2 = z / 2,
|
18129 | n = 12,
|
18130 | Tvalues = [-.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816],
|
18131 | 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],
|
18132 | sum = 0;
|
18133 |
|
18134 | for (var i = 0; i < n; i++) {
|
18135 | var ct = z2 * Tvalues[i] + z2,
|
18136 | xbase = base3(ct, x1, x2, x3, x4),
|
18137 | ybase = base3(ct, y1, y2, y3, y4),
|
18138 | comb = xbase * xbase + ybase * ybase;
|
18139 |
|
18140 | sum += Cvalues[i] * math.sqrt(comb);
|
18141 | }
|
18142 |
|
18143 | return z2 * sum;
|
18144 | }
|
18145 |
|
18146 |
|
18147 | function intersectLines(x1, y1, x2, y2, x3, y3, x4, y4) {
|
18148 |
|
18149 | if (
|
18150 | mmax(x1, x2) < mmin(x3, x4) ||
|
18151 | mmin(x1, x2) > mmax(x3, x4) ||
|
18152 | mmax(y1, y2) < mmin(y3, y4) ||
|
18153 | mmin(y1, y2) > mmax(y3, y4)
|
18154 | ) {
|
18155 | return;
|
18156 | }
|
18157 |
|
18158 | var nx = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4),
|
18159 | ny = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4),
|
18160 | denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
|
18161 |
|
18162 | if (!denominator) {
|
18163 | return;
|
18164 | }
|
18165 |
|
18166 | var px = fixError(nx / denominator),
|
18167 | py = fixError(ny / denominator),
|
18168 | px2 = +px.toFixed(2),
|
18169 | py2 = +py.toFixed(2);
|
18170 |
|
18171 | if (
|
18172 | px2 < +mmin(x1, x2).toFixed(2) ||
|
18173 | px2 > +mmax(x1, x2).toFixed(2) ||
|
18174 | px2 < +mmin(x3, x4).toFixed(2) ||
|
18175 | px2 > +mmax(x3, x4).toFixed(2) ||
|
18176 | py2 < +mmin(y1, y2).toFixed(2) ||
|
18177 | py2 > +mmax(y1, y2).toFixed(2) ||
|
18178 | py2 < +mmin(y3, y4).toFixed(2) ||
|
18179 | py2 > +mmax(y3, y4).toFixed(2)
|
18180 | ) {
|
18181 | return;
|
18182 | }
|
18183 |
|
18184 | return { x: px, y: py };
|
18185 | }
|
18186 |
|
18187 | function fixError(number) {
|
18188 | return Math.round(number * 100000000000) / 100000000000;
|
18189 | }
|
18190 |
|
18191 | function findBezierIntersections(bez1, bez2, justCount) {
|
18192 | var bbox1 = bezierBBox(bez1),
|
18193 | bbox2 = bezierBBox(bez2);
|
18194 |
|
18195 | if (!isBBoxIntersect(bbox1, bbox2)) {
|
18196 | return justCount ? 0 : [];
|
18197 | }
|
18198 |
|
18199 | var l1 = bezlen.apply(0, bez1),
|
18200 | l2 = bezlen.apply(0, bez2),
|
18201 | n1 = ~~(l1 / 5) || 1,
|
18202 | n2 = ~~(l2 / 5) || 1,
|
18203 | dots1 = [],
|
18204 | dots2 = [],
|
18205 | xy = {},
|
18206 | res = justCount ? 0 : [];
|
18207 |
|
18208 | for (var i = 0; i < n1 + 1; i++) {
|
18209 | var p = findDotsAtSegment.apply(0, bez1.concat(i / n1));
|
18210 | dots1.push({ x: p.x, y: p.y, t: i / n1 });
|
18211 | }
|
18212 |
|
18213 | for (i = 0; i < n2 + 1; i++) {
|
18214 | p = findDotsAtSegment.apply(0, bez2.concat(i / n2));
|
18215 | dots2.push({ x: p.x, y: p.y, t: i / n2 });
|
18216 | }
|
18217 |
|
18218 | for (i = 0; i < n1; i++) {
|
18219 |
|
18220 | for (var j = 0; j < n2; j++) {
|
18221 | var di = dots1[i],
|
18222 | di1 = dots1[i + 1],
|
18223 | dj = dots2[j],
|
18224 | dj1 = dots2[j + 1],
|
18225 | ci = abs(di1.x - di.x) < .01 ? 'y' : 'x',
|
18226 | cj = abs(dj1.x - dj.x) < .01 ? 'y' : 'x',
|
18227 | is = intersectLines(di.x, di.y, di1.x, di1.y, dj.x, dj.y, dj1.x, dj1.y),
|
18228 | key;
|
18229 |
|
18230 | if (is) {
|
18231 | key = is.x.toFixed(9) + '#' + is.y.toFixed(9);
|
18232 |
|
18233 | if (xy[key]) {
|
18234 | continue;
|
18235 | }
|
18236 |
|
18237 | xy[key] = true;
|
18238 |
|
18239 | var t1 = di.t + abs((is[ci] - di[ci]) / (di1[ci] - di[ci])) * (di1.t - di.t),
|
18240 | t2 = dj.t + abs((is[cj] - dj[cj]) / (dj1[cj] - dj[cj])) * (dj1.t - dj.t);
|
18241 |
|
18242 | if (t1 >= 0 && t1 <= 1 && t2 >= 0 && t2 <= 1) {
|
18243 |
|
18244 | if (justCount) {
|
18245 | res++;
|
18246 | } else {
|
18247 | res.push({
|
18248 | x: is.x,
|
18249 | y: is.y,
|
18250 | t1: t1,
|
18251 | t2: t2
|
18252 | });
|
18253 | }
|
18254 | }
|
18255 | }
|
18256 | }
|
18257 | }
|
18258 |
|
18259 | return res;
|
18260 | }
|
18261 |
|
18262 |
|
18263 | |
18264 |
|
18265 |
|
18266 |
|
18267 |
|
18268 |
|
18269 |
|
18270 |
|
18271 |
|
18272 |
|
18273 |
|
18274 |
|
18275 |
|
18276 |
|
18277 |
|
18278 |
|
18279 |
|
18280 |
|
18281 |
|
18282 |
|
18283 |
|
18284 |
|
18285 |
|
18286 |
|
18287 |
|
18288 |
|
18289 |
|
18290 |
|
18291 |
|
18292 |
|
18293 | function findPathIntersections(path1, path2, justCount) {
|
18294 | path1 = pathToCurve(path1);
|
18295 | path2 = pathToCurve(path2);
|
18296 |
|
18297 | var x1, y1, x2, y2, x1m, y1m, x2m, y2m, bez1, bez2,
|
18298 | res = justCount ? 0 : [];
|
18299 |
|
18300 | for (var i = 0, ii = path1.length; i < ii; i++) {
|
18301 | var pi = path1[i];
|
18302 |
|
18303 | if (pi[0] == 'M') {
|
18304 | x1 = x1m = pi[1];
|
18305 | y1 = y1m = pi[2];
|
18306 | } else {
|
18307 |
|
18308 | if (pi[0] == 'C') {
|
18309 | bez1 = [x1, y1].concat(pi.slice(1));
|
18310 | x1 = bez1[6];
|
18311 | y1 = bez1[7];
|
18312 | } else {
|
18313 | bez1 = [x1, y1, x1, y1, x1m, y1m, x1m, y1m];
|
18314 | x1 = x1m;
|
18315 | y1 = y1m;
|
18316 | }
|
18317 |
|
18318 | for (var j = 0, jj = path2.length; j < jj; j++) {
|
18319 | var pj = path2[j];
|
18320 |
|
18321 | if (pj[0] == 'M') {
|
18322 | x2 = x2m = pj[1];
|
18323 | y2 = y2m = pj[2];
|
18324 | } else {
|
18325 |
|
18326 | if (pj[0] == 'C') {
|
18327 | bez2 = [x2, y2].concat(pj.slice(1));
|
18328 | x2 = bez2[6];
|
18329 | y2 = bez2[7];
|
18330 | } else {
|
18331 | bez2 = [x2, y2, x2, y2, x2m, y2m, x2m, y2m];
|
18332 | x2 = x2m;
|
18333 | y2 = y2m;
|
18334 | }
|
18335 |
|
18336 | var intr = findBezierIntersections(bez1, bez2, justCount);
|
18337 |
|
18338 | if (justCount) {
|
18339 | res += intr;
|
18340 | } else {
|
18341 |
|
18342 | for (var k = 0, kk = intr.length; k < kk; k++) {
|
18343 | intr[k].segment1 = i;
|
18344 | intr[k].segment2 = j;
|
18345 | intr[k].bez1 = bez1;
|
18346 | intr[k].bez2 = bez2;
|
18347 | }
|
18348 |
|
18349 | res = res.concat(intr);
|
18350 | }
|
18351 | }
|
18352 | }
|
18353 | }
|
18354 | }
|
18355 |
|
18356 | return res;
|
18357 | }
|
18358 |
|
18359 |
|
18360 | function pathToAbsolute(pathArray) {
|
18361 | var pth = paths(pathArray);
|
18362 |
|
18363 | if (pth.abs) {
|
18364 | return pathClone(pth.abs);
|
18365 | }
|
18366 |
|
18367 | if (!isArray$2(pathArray) || !isArray$2(pathArray && pathArray[0])) {
|
18368 | pathArray = parsePathString(pathArray);
|
18369 | }
|
18370 |
|
18371 | if (!pathArray || !pathArray.length) {
|
18372 | return [['M', 0, 0]];
|
18373 | }
|
18374 |
|
18375 | var res = [],
|
18376 | x = 0,
|
18377 | y = 0,
|
18378 | mx = 0,
|
18379 | my = 0,
|
18380 | start = 0,
|
18381 | pa0;
|
18382 |
|
18383 | if (pathArray[0][0] == 'M') {
|
18384 | x = +pathArray[0][1];
|
18385 | y = +pathArray[0][2];
|
18386 | mx = x;
|
18387 | my = y;
|
18388 | start++;
|
18389 | res[0] = ['M', x, y];
|
18390 | }
|
18391 |
|
18392 | for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) {
|
18393 | res.push(r = []);
|
18394 | pa = pathArray[i];
|
18395 | pa0 = pa[0];
|
18396 |
|
18397 | if (pa0 != pa0.toUpperCase()) {
|
18398 | r[0] = pa0.toUpperCase();
|
18399 |
|
18400 | switch (r[0]) {
|
18401 | case 'A':
|
18402 | r[1] = pa[1];
|
18403 | r[2] = pa[2];
|
18404 | r[3] = pa[3];
|
18405 | r[4] = pa[4];
|
18406 | r[5] = pa[5];
|
18407 | r[6] = +pa[6] + x;
|
18408 | r[7] = +pa[7] + y;
|
18409 | break;
|
18410 | case 'V':
|
18411 | r[1] = +pa[1] + y;
|
18412 | break;
|
18413 | case 'H':
|
18414 | r[1] = +pa[1] + x;
|
18415 | break;
|
18416 | case 'M':
|
18417 | mx = +pa[1] + x;
|
18418 | my = +pa[2] + y;
|
18419 | default:
|
18420 | for (var j = 1, jj = pa.length; j < jj; j++) {
|
18421 | r[j] = +pa[j] + ((j % 2) ? x : y);
|
18422 | }
|
18423 | }
|
18424 | } else {
|
18425 | for (var k = 0, kk = pa.length; k < kk; k++) {
|
18426 | r[k] = pa[k];
|
18427 | }
|
18428 | }
|
18429 | pa0 = pa0.toUpperCase();
|
18430 |
|
18431 | switch (r[0]) {
|
18432 | case 'Z':
|
18433 | x = +mx;
|
18434 | y = +my;
|
18435 | break;
|
18436 | case 'H':
|
18437 | x = r[1];
|
18438 | break;
|
18439 | case 'V':
|
18440 | y = r[1];
|
18441 | break;
|
18442 | case 'M':
|
18443 | mx = r[r.length - 2];
|
18444 | my = r[r.length - 1];
|
18445 | default:
|
18446 | x = r[r.length - 2];
|
18447 | y = r[r.length - 1];
|
18448 | }
|
18449 | }
|
18450 |
|
18451 | res.toString = pathToString;
|
18452 | pth.abs = pathClone(res);
|
18453 |
|
18454 | return res;
|
18455 | }
|
18456 |
|
18457 | function lineToCurve(x1, y1, x2, y2) {
|
18458 | return [
|
18459 | x1, y1, x2,
|
18460 | y2, x2, y2
|
18461 | ];
|
18462 | }
|
18463 |
|
18464 | function qubicToCurve(x1, y1, ax, ay, x2, y2) {
|
18465 | var _13 = 1 / 3,
|
18466 | _23 = 2 / 3;
|
18467 |
|
18468 | return [
|
18469 | _13 * x1 + _23 * ax,
|
18470 | _13 * y1 + _23 * ay,
|
18471 | _13 * x2 + _23 * ax,
|
18472 | _13 * y2 + _23 * ay,
|
18473 | x2,
|
18474 | y2
|
18475 | ];
|
18476 | }
|
18477 |
|
18478 | function arcToCurve(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
|
18479 |
|
18480 |
|
18481 |
|
18482 | var _120 = PI * 120 / 180,
|
18483 | rad = PI / 180 * (+angle || 0),
|
18484 | res = [],
|
18485 | xy,
|
18486 | rotate = cacher(function(x, y, rad) {
|
18487 | var X = x * math.cos(rad) - y * math.sin(rad),
|
18488 | Y = x * math.sin(rad) + y * math.cos(rad);
|
18489 |
|
18490 | return { x: X, y: Y };
|
18491 | });
|
18492 |
|
18493 | if (!recursive) {
|
18494 | xy = rotate(x1, y1, -rad);
|
18495 | x1 = xy.x;
|
18496 | y1 = xy.y;
|
18497 | xy = rotate(x2, y2, -rad);
|
18498 | x2 = xy.x;
|
18499 | y2 = xy.y;
|
18500 |
|
18501 | var x = (x1 - x2) / 2,
|
18502 | y = (y1 - y2) / 2;
|
18503 |
|
18504 | var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
|
18505 |
|
18506 | if (h > 1) {
|
18507 | h = math.sqrt(h);
|
18508 | rx = h * rx;
|
18509 | ry = h * ry;
|
18510 | }
|
18511 |
|
18512 | var rx2 = rx * rx,
|
18513 | ry2 = ry * ry,
|
18514 | k = (large_arc_flag == sweep_flag ? -1 : 1) *
|
18515 | math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
|
18516 | cx = k * rx * y / ry + (x1 + x2) / 2,
|
18517 | cy = k * -ry * x / rx + (y1 + y2) / 2,
|
18518 | f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
|
18519 | f2 = math.asin(((y2 - cy) / ry).toFixed(9));
|
18520 |
|
18521 | f1 = x1 < cx ? PI - f1 : f1;
|
18522 | f2 = x2 < cx ? PI - f2 : f2;
|
18523 | f1 < 0 && (f1 = PI * 2 + f1);
|
18524 | f2 < 0 && (f2 = PI * 2 + f2);
|
18525 |
|
18526 | if (sweep_flag && f1 > f2) {
|
18527 | f1 = f1 - PI * 2;
|
18528 | }
|
18529 | if (!sweep_flag && f2 > f1) {
|
18530 | f2 = f2 - PI * 2;
|
18531 | }
|
18532 | } else {
|
18533 | f1 = recursive[0];
|
18534 | f2 = recursive[1];
|
18535 | cx = recursive[2];
|
18536 | cy = recursive[3];
|
18537 | }
|
18538 |
|
18539 | var df = f2 - f1;
|
18540 |
|
18541 | if (abs(df) > _120) {
|
18542 | var f2old = f2,
|
18543 | x2old = x2,
|
18544 | y2old = y2;
|
18545 |
|
18546 | f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
|
18547 | x2 = cx + rx * math.cos(f2);
|
18548 | y2 = cy + ry * math.sin(f2);
|
18549 | res = arcToCurve(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
|
18550 | }
|
18551 |
|
18552 | df = f2 - f1;
|
18553 |
|
18554 | var c1 = math.cos(f1),
|
18555 | s1 = math.sin(f1),
|
18556 | c2 = math.cos(f2),
|
18557 | s2 = math.sin(f2),
|
18558 | t = math.tan(df / 4),
|
18559 | hx = 4 / 3 * rx * t,
|
18560 | hy = 4 / 3 * ry * t,
|
18561 | m1 = [x1, y1],
|
18562 | m2 = [x1 + hx * s1, y1 - hy * c1],
|
18563 | m3 = [x2 + hx * s2, y2 - hy * c2],
|
18564 | m4 = [x2, y2];
|
18565 |
|
18566 | m2[0] = 2 * m1[0] - m2[0];
|
18567 | m2[1] = 2 * m1[1] - m2[1];
|
18568 |
|
18569 | if (recursive) {
|
18570 | return [m2, m3, m4].concat(res);
|
18571 | } else {
|
18572 | res = [m2, m3, m4].concat(res).join().split(',');
|
18573 | var newres = [];
|
18574 |
|
18575 | for (var i = 0, ii = res.length; i < ii; i++) {
|
18576 | newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
|
18577 | }
|
18578 |
|
18579 | return newres;
|
18580 | }
|
18581 | }
|
18582 |
|
18583 |
|
18584 |
|
18585 |
|
18586 |
|
18587 | function curveBBox(x0, y0, x1, y1, x2, y2, x3, y3) {
|
18588 | var tvalues = [],
|
18589 | bounds = [[], []],
|
18590 | a, b, c, t, t1, t2, b2ac, sqrtb2ac;
|
18591 |
|
18592 | for (var i = 0; i < 2; ++i) {
|
18593 |
|
18594 | if (i == 0) {
|
18595 | b = 6 * x0 - 12 * x1 + 6 * x2;
|
18596 | a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
|
18597 | c = 3 * x1 - 3 * x0;
|
18598 | } else {
|
18599 | b = 6 * y0 - 12 * y1 + 6 * y2;
|
18600 | a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
|
18601 | c = 3 * y1 - 3 * y0;
|
18602 | }
|
18603 |
|
18604 | if (abs(a) < 1e-12) {
|
18605 |
|
18606 | if (abs(b) < 1e-12) {
|
18607 | continue;
|
18608 | }
|
18609 |
|
18610 | t = -c / b;
|
18611 |
|
18612 | if (0 < t && t < 1) {
|
18613 | tvalues.push(t);
|
18614 | }
|
18615 |
|
18616 | continue;
|
18617 | }
|
18618 |
|
18619 | b2ac = b * b - 4 * c * a;
|
18620 | sqrtb2ac = math.sqrt(b2ac);
|
18621 |
|
18622 | if (b2ac < 0) {
|
18623 | continue;
|
18624 | }
|
18625 |
|
18626 | t1 = (-b + sqrtb2ac) / (2 * a);
|
18627 |
|
18628 | if (0 < t1 && t1 < 1) {
|
18629 | tvalues.push(t1);
|
18630 | }
|
18631 |
|
18632 | t2 = (-b - sqrtb2ac) / (2 * a);
|
18633 |
|
18634 | if (0 < t2 && t2 < 1) {
|
18635 | tvalues.push(t2);
|
18636 | }
|
18637 | }
|
18638 |
|
18639 | var j = tvalues.length,
|
18640 | jlen = j,
|
18641 | mt;
|
18642 |
|
18643 | while (j--) {
|
18644 | t = tvalues[j];
|
18645 | mt = 1 - t;
|
18646 | bounds[0][j] = (mt * mt * mt * x0) + (3 * mt * mt * t * x1) + (3 * mt * t * t * x2) + (t * t * t * x3);
|
18647 | bounds[1][j] = (mt * mt * mt * y0) + (3 * mt * mt * t * y1) + (3 * mt * t * t * y2) + (t * t * t * y3);
|
18648 | }
|
18649 |
|
18650 | bounds[0][jlen] = x0;
|
18651 | bounds[1][jlen] = y0;
|
18652 | bounds[0][jlen + 1] = x3;
|
18653 | bounds[1][jlen + 1] = y3;
|
18654 | bounds[0].length = bounds[1].length = jlen + 2;
|
18655 |
|
18656 | return {
|
18657 | x0: mmin.apply(0, bounds[0]),
|
18658 | y0: mmin.apply(0, bounds[1]),
|
18659 | x1: mmax.apply(0, bounds[0]),
|
18660 | y1: mmax.apply(0, bounds[1])
|
18661 | };
|
18662 | }
|
18663 |
|
18664 | function pathToCurve(path) {
|
18665 |
|
18666 | var pth = paths(path);
|
18667 |
|
18668 |
|
18669 | if (pth.curve) {
|
18670 | return pathClone(pth.curve);
|
18671 | }
|
18672 |
|
18673 | var curvedPath = pathToAbsolute(path),
|
18674 | attrs = { x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null },
|
18675 | processPath = function(path, d, pathCommand) {
|
18676 | var nx, ny;
|
18677 |
|
18678 | if (!path) {
|
18679 | return ['C', d.x, d.y, d.x, d.y, d.x, d.y];
|
18680 | }
|
18681 |
|
18682 | !(path[0] in { T: 1, Q: 1 }) && (d.qx = d.qy = null);
|
18683 |
|
18684 | switch (path[0]) {
|
18685 | case 'M':
|
18686 | d.X = path[1];
|
18687 | d.Y = path[2];
|
18688 | break;
|
18689 | case 'A':
|
18690 | path = ['C'].concat(arcToCurve.apply(0, [d.x, d.y].concat(path.slice(1))));
|
18691 | break;
|
18692 | case 'S':
|
18693 | if (pathCommand == 'C' || pathCommand == 'S') {
|
18694 |
|
18695 | nx = d.x * 2 - d.bx;
|
18696 |
|
18697 | ny = d.y * 2 - d.by;
|
18698 |
|
18699 | }
|
18700 | else {
|
18701 |
|
18702 | nx = d.x;
|
18703 | ny = d.y;
|
18704 | }
|
18705 | path = ['C', nx, ny].concat(path.slice(1));
|
18706 | break;
|
18707 | case 'T':
|
18708 | if (pathCommand == 'Q' || pathCommand == 'T') {
|
18709 |
|
18710 | d.qx = d.x * 2 - d.qx;
|
18711 |
|
18712 | d.qy = d.y * 2 - d.qy;
|
18713 |
|
18714 | }
|
18715 | else {
|
18716 |
|
18717 | d.qx = d.x;
|
18718 | d.qy = d.y;
|
18719 | }
|
18720 | path = ['C'].concat(qubicToCurve(d.x, d.y, d.qx, d.qy, path[1], path[2]));
|
18721 | break;
|
18722 | case 'Q':
|
18723 | d.qx = path[1];
|
18724 | d.qy = path[2];
|
18725 | path = ['C'].concat(qubicToCurve(d.x, d.y, path[1], path[2], path[3], path[4]));
|
18726 | break;
|
18727 | case 'L':
|
18728 | path = ['C'].concat(lineToCurve(d.x, d.y, path[1], path[2]));
|
18729 | break;
|
18730 | case 'H':
|
18731 | path = ['C'].concat(lineToCurve(d.x, d.y, path[1], d.y));
|
18732 | break;
|
18733 | case 'V':
|
18734 | path = ['C'].concat(lineToCurve(d.x, d.y, d.x, path[1]));
|
18735 | break;
|
18736 | case 'Z':
|
18737 | path = ['C'].concat(lineToCurve(d.x, d.y, d.X, d.Y));
|
18738 | break;
|
18739 | }
|
18740 |
|
18741 | return path;
|
18742 | },
|
18743 |
|
18744 | fixArc = function(pp, i) {
|
18745 |
|
18746 | if (pp[i].length > 7) {
|
18747 | pp[i].shift();
|
18748 | var pi = pp[i];
|
18749 |
|
18750 | while (pi.length) {
|
18751 | pathCommands[i] = 'A';
|
18752 | pp.splice(i++, 0, ['C'].concat(pi.splice(0, 6)));
|
18753 | }
|
18754 |
|
18755 | pp.splice(i, 1);
|
18756 | ii = curvedPath.length;
|
18757 | }
|
18758 | },
|
18759 |
|
18760 | pathCommands = [],
|
18761 | pfirst = '',
|
18762 | pathCommand = '';
|
18763 |
|
18764 | for (var i = 0, ii = curvedPath.length; i < ii; i++) {
|
18765 | curvedPath[i] && (pfirst = curvedPath[i][0]);
|
18766 |
|
18767 | if (pfirst != 'C')
|
18768 | {
|
18769 | pathCommands[i] = pfirst;
|
18770 | i && (pathCommand = pathCommands[i - 1]);
|
18771 | }
|
18772 | curvedPath[i] = processPath(curvedPath[i], attrs, pathCommand);
|
18773 |
|
18774 | if (pathCommands[i] != 'A' && pfirst == 'C') pathCommands[i] = 'C';
|
18775 |
|
18776 |
|
18777 |
|
18778 | fixArc(curvedPath, i);
|
18779 |
|
18780 | var seg = curvedPath[i],
|
18781 | seglen = seg.length;
|
18782 |
|
18783 | attrs.x = seg[seglen - 2];
|
18784 | attrs.y = seg[seglen - 1];
|
18785 | attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
|
18786 | attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
|
18787 | }
|
18788 |
|
18789 |
|
18790 | pth.curve = pathClone(curvedPath);
|
18791 |
|
18792 | return curvedPath;
|
18793 | }
|
18794 |
|
18795 | var intersect = findPathIntersections;
|
18796 |
|
18797 | function roundBounds(bounds) {
|
18798 | return {
|
18799 | x: Math.round(bounds.x),
|
18800 | y: Math.round(bounds.y),
|
18801 | width: Math.round(bounds.width),
|
18802 | height: Math.round(bounds.height)
|
18803 | };
|
18804 | }
|
18805 |
|
18806 |
|
18807 | function roundPoint(point) {
|
18808 |
|
18809 | return {
|
18810 | x: Math.round(point.x),
|
18811 | y: Math.round(point.y)
|
18812 | };
|
18813 | }
|
18814 |
|
18815 |
|
18816 | |
18817 |
|
18818 |
|
18819 |
|
18820 |
|
18821 |
|
18822 |
|
18823 | function asTRBL(bounds) {
|
18824 | return {
|
18825 | top: bounds.y,
|
18826 | right: bounds.x + (bounds.width || 0),
|
18827 | bottom: bounds.y + (bounds.height || 0),
|
18828 | left: bounds.x
|
18829 | };
|
18830 | }
|
18831 |
|
18832 |
|
18833 | |
18834 |
|
18835 |
|
18836 |
|
18837 |
|
18838 |
|
18839 |
|
18840 | function asBounds(trbl) {
|
18841 | return {
|
18842 | x: trbl.left,
|
18843 | y: trbl.top,
|
18844 | width: trbl.right - trbl.left,
|
18845 | height: trbl.bottom - trbl.top
|
18846 | };
|
18847 | }
|
18848 |
|
18849 |
|
18850 | |
18851 |
|
18852 |
|
18853 |
|
18854 |
|
18855 |
|
18856 |
|
18857 | function getMid(bounds) {
|
18858 | return roundPoint({
|
18859 | x: bounds.x + (bounds.width || 0) / 2,
|
18860 | y: bounds.y + (bounds.height || 0) / 2
|
18861 | });
|
18862 | }
|
18863 |
|
18864 |
|
18865 |
|
18866 |
|
18867 | |
18868 |
|
18869 |
|
18870 |
|
18871 |
|
18872 |
|
18873 |
|
18874 |
|
18875 |
|
18876 |
|
18877 |
|
18878 |
|
18879 |
|
18880 | function getOrientation(rect, reference, padding) {
|
18881 |
|
18882 | padding = padding || 0;
|
18883 |
|
18884 |
|
18885 |
|
18886 | if (!isObject(padding)) {
|
18887 | padding = { x: padding, y: padding };
|
18888 | }
|
18889 |
|
18890 |
|
18891 | var rectOrientation = asTRBL(rect),
|
18892 | referenceOrientation = asTRBL(reference);
|
18893 |
|
18894 | var top = rectOrientation.bottom + padding.y <= referenceOrientation.top,
|
18895 | right = rectOrientation.left - padding.x >= referenceOrientation.right,
|
18896 | bottom = rectOrientation.top - padding.y >= referenceOrientation.bottom,
|
18897 | left = rectOrientation.right + padding.x <= referenceOrientation.left;
|
18898 |
|
18899 | var vertical = top ? 'top' : (bottom ? 'bottom' : null),
|
18900 | horizontal = left ? 'left' : (right ? 'right' : null);
|
18901 |
|
18902 | if (horizontal && vertical) {
|
18903 | return vertical + '-' + horizontal;
|
18904 | } else {
|
18905 | return horizontal || vertical || 'intersect';
|
18906 | }
|
18907 | }
|
18908 |
|
18909 |
|
18910 |
|
18911 |
|
18912 | |
18913 |
|
18914 |
|
18915 |
|
18916 |
|
18917 |
|
18918 |
|
18919 |
|
18920 |
|
18921 | function getElementLineIntersection(elementPath, linePath, cropStart) {
|
18922 |
|
18923 | var intersections = getIntersections(elementPath, linePath);
|
18924 |
|
18925 |
|
18926 |
|
18927 |
|
18928 |
|
18929 |
|
18930 | if (intersections.length === 1) {
|
18931 | return roundPoint(intersections[0]);
|
18932 | } else if (intersections.length === 2 && pointDistance(intersections[0], intersections[1]) < 1) {
|
18933 | return roundPoint(intersections[0]);
|
18934 | } else if (intersections.length > 1) {
|
18935 |
|
18936 |
|
18937 |
|
18938 | intersections = sortBy(intersections, function(i) {
|
18939 | var distance = Math.floor(i.t2 * 100) || 1;
|
18940 |
|
18941 | distance = 100 - distance;
|
18942 |
|
18943 | distance = (distance < 10 ? '0' : '') + distance;
|
18944 |
|
18945 |
|
18946 |
|
18947 |
|
18948 | return i.segment2 + '#' + distance;
|
18949 | });
|
18950 |
|
18951 | return roundPoint(intersections[cropStart ? 0 : intersections.length - 1]);
|
18952 | }
|
18953 |
|
18954 | return null;
|
18955 | }
|
18956 |
|
18957 |
|
18958 | function getIntersections(a, b) {
|
18959 | return intersect(a, b);
|
18960 | }
|
18961 |
|
18962 |
|
18963 | function filterRedundantWaypoints(waypoints) {
|
18964 |
|
18965 |
|
18966 | waypoints = waypoints.slice();
|
18967 |
|
18968 | var idx = 0,
|
18969 | point,
|
18970 | previousPoint,
|
18971 | nextPoint;
|
18972 |
|
18973 | while (waypoints[idx]) {
|
18974 | point = waypoints[idx];
|
18975 | previousPoint = waypoints[idx - 1];
|
18976 | nextPoint = waypoints[idx + 1];
|
18977 |
|
18978 | if (pointDistance(point, nextPoint) === 0 ||
|
18979 | pointsOnLine(previousPoint, nextPoint, point)) {
|
18980 |
|
18981 |
|
18982 |
|
18983 | waypoints.splice(idx, 1);
|
18984 | } else {
|
18985 | idx++;
|
18986 | }
|
18987 | }
|
18988 |
|
18989 | return waypoints;
|
18990 | }
|
18991 |
|
18992 | function elementData(semantic, attrs) {
|
18993 | return assign({
|
18994 | id: semantic.id,
|
18995 | type: semantic.$type,
|
18996 | businessObject: semantic
|
18997 | }, attrs);
|
18998 | }
|
18999 |
|
19000 | function getWaypoints(bo, source, target) {
|
19001 |
|
19002 | var waypoints = bo.di.waypoint;
|
19003 |
|
19004 | if (!waypoints || waypoints.length < 2) {
|
19005 | return [ getMid(source), getMid(target) ];
|
19006 | }
|
19007 |
|
19008 | return waypoints.map(function(p) {
|
19009 | return { x: p.x, y: p.y };
|
19010 | });
|
19011 | }
|
19012 |
|
19013 | function notYetDrawn(translate, semantic, refSemantic, property) {
|
19014 | return new Error(translate('element {element} referenced by {referenced}#{property} not yet drawn', {
|
19015 | element: elementToString(refSemantic),
|
19016 | referenced: elementToString(semantic),
|
19017 | property: property
|
19018 | }));
|
19019 | }
|
19020 |
|
19021 |
|
19022 | |
19023 |
|
19024 |
|
19025 |
|
19026 |
|
19027 |
|
19028 |
|
19029 |
|
19030 |
|
19031 |
|
19032 | function BpmnImporter(
|
19033 | eventBus, canvas, elementFactory,
|
19034 | elementRegistry, translate, textRenderer) {
|
19035 |
|
19036 | this._eventBus = eventBus;
|
19037 | this._canvas = canvas;
|
19038 | this._elementFactory = elementFactory;
|
19039 | this._elementRegistry = elementRegistry;
|
19040 | this._translate = translate;
|
19041 | this._textRenderer = textRenderer;
|
19042 | }
|
19043 |
|
19044 | BpmnImporter.$inject = [
|
19045 | 'eventBus',
|
19046 | 'canvas',
|
19047 | 'elementFactory',
|
19048 | 'elementRegistry',
|
19049 | 'translate',
|
19050 | 'textRenderer'
|
19051 | ];
|
19052 |
|
19053 |
|
19054 | |
19055 |
|
19056 |
|
19057 |
|
19058 | BpmnImporter.prototype.add = function(semantic, parentElement) {
|
19059 |
|
19060 | var di = semantic.di,
|
19061 | element,
|
19062 | translate = this._translate,
|
19063 | hidden;
|
19064 |
|
19065 | var parentIndex;
|
19066 |
|
19067 |
|
19068 |
|
19069 |
|
19070 | if (is$1(di, 'bpmndi:BPMNPlane')) {
|
19071 |
|
19072 |
|
19073 | element = this._elementFactory.createRoot(elementData(semantic));
|
19074 |
|
19075 | this._canvas.setRootElement(element);
|
19076 | }
|
19077 |
|
19078 |
|
19079 | else if (is$1(di, 'bpmndi:BPMNShape')) {
|
19080 |
|
19081 | var collapsed = !isExpanded(semantic);
|
19082 | hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
|
19083 |
|
19084 | var bounds = semantic.di.bounds;
|
19085 |
|
19086 | element = this._elementFactory.createShape(elementData(semantic, {
|
19087 | collapsed: collapsed,
|
19088 | hidden: hidden,
|
19089 | x: Math.round(bounds.x),
|
19090 | y: Math.round(bounds.y),
|
19091 | width: Math.round(bounds.width),
|
19092 | height: Math.round(bounds.height)
|
19093 | }));
|
19094 |
|
19095 | if (is$1(semantic, 'bpmn:BoundaryEvent')) {
|
19096 | this._attachBoundary(semantic, element);
|
19097 | }
|
19098 |
|
19099 |
|
19100 | if (is$1(semantic, 'bpmn:Lane')) {
|
19101 | parentIndex = 0;
|
19102 | }
|
19103 |
|
19104 | if (is$1(semantic, 'bpmn:DataStoreReference')) {
|
19105 |
|
19106 |
|
19107 | if (!isPointInsideBBox$1(parentElement, getMid(bounds))) {
|
19108 | parentElement = this._canvas.getRootElement();
|
19109 | }
|
19110 | }
|
19111 |
|
19112 | this._canvas.addShape(element, parentElement, parentIndex);
|
19113 | }
|
19114 |
|
19115 |
|
19116 | else if (is$1(di, 'bpmndi:BPMNEdge')) {
|
19117 |
|
19118 | var source = this._getSource(semantic),
|
19119 | target = this._getTarget(semantic);
|
19120 |
|
19121 | hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
|
19122 |
|
19123 | element = this._elementFactory.createConnection(elementData(semantic, {
|
19124 | hidden: hidden,
|
19125 | source: source,
|
19126 | target: target,
|
19127 | waypoints: getWaypoints(semantic, source, target)
|
19128 | }));
|
19129 |
|
19130 | if (is$1(semantic, 'bpmn:DataAssociation')) {
|
19131 |
|
19132 |
|
19133 |
|
19134 |
|
19135 |
|
19136 | parentElement = null;
|
19137 | }
|
19138 |
|
19139 |
|
19140 | if (is$1(semantic, 'bpmn:SequenceFlow')) {
|
19141 | parentIndex = 0;
|
19142 | }
|
19143 |
|
19144 | this._canvas.addConnection(element, parentElement, parentIndex);
|
19145 | } else {
|
19146 | throw new Error(translate('unknown di {di} for element {semantic}', {
|
19147 | di: elementToString(di),
|
19148 | semantic: elementToString(semantic)
|
19149 | }));
|
19150 | }
|
19151 |
|
19152 |
|
19153 | if (isLabelExternal(semantic) && getLabel(element)) {
|
19154 | this.addLabel(semantic, element);
|
19155 | }
|
19156 |
|
19157 |
|
19158 | this._eventBus.fire('bpmnElement.added', { element: element });
|
19159 |
|
19160 | return element;
|
19161 | };
|
19162 |
|
19163 |
|
19164 | |
19165 |
|
19166 |
|
19167 |
|
19168 |
|
19169 |
|
19170 | BpmnImporter.prototype._attachBoundary = function(boundarySemantic, boundaryElement) {
|
19171 | var translate = this._translate;
|
19172 | var hostSemantic = boundarySemantic.attachedToRef;
|
19173 |
|
19174 | if (!hostSemantic) {
|
19175 | throw new Error(translate('missing {semantic}#attachedToRef', {
|
19176 | semantic: elementToString(boundarySemantic)
|
19177 | }));
|
19178 | }
|
19179 |
|
19180 | var host = this._elementRegistry.get(hostSemantic.id),
|
19181 | attachers = host && host.attachers;
|
19182 |
|
19183 | if (!host) {
|
19184 | throw notYetDrawn(translate, boundarySemantic, hostSemantic, 'attachedToRef');
|
19185 | }
|
19186 |
|
19187 |
|
19188 | boundaryElement.host = host;
|
19189 |
|
19190 | if (!attachers) {
|
19191 | host.attachers = attachers = [];
|
19192 | }
|
19193 |
|
19194 | if (attachers.indexOf(boundaryElement) === -1) {
|
19195 | attachers.push(boundaryElement);
|
19196 | }
|
19197 | };
|
19198 |
|
19199 |
|
19200 | |
19201 |
|
19202 |
|
19203 | BpmnImporter.prototype.addLabel = function(semantic, element) {
|
19204 | var bounds,
|
19205 | text,
|
19206 | label;
|
19207 |
|
19208 | bounds = getExternalLabelBounds(semantic, element);
|
19209 |
|
19210 | text = getLabel(element);
|
19211 |
|
19212 | if (text) {
|
19213 |
|
19214 |
|
19215 | bounds = this._textRenderer.getExternalLabelBounds(bounds, text);
|
19216 | }
|
19217 |
|
19218 | label = this._elementFactory.createLabel(elementData(semantic, {
|
19219 | id: semantic.id + '_label',
|
19220 | labelTarget: element,
|
19221 | type: 'label',
|
19222 | hidden: element.hidden || !getLabel(element),
|
19223 | x: Math.round(bounds.x),
|
19224 | y: Math.round(bounds.y),
|
19225 | width: Math.round(bounds.width),
|
19226 | height: Math.round(bounds.height)
|
19227 | }));
|
19228 |
|
19229 | return this._canvas.addShape(label, element.parent);
|
19230 | };
|
19231 |
|
19232 | |
19233 |
|
19234 |
|
19235 |
|
19236 |
|
19237 | BpmnImporter.prototype._getEnd = function(semantic, side) {
|
19238 |
|
19239 | var element,
|
19240 | refSemantic,
|
19241 | type = semantic.$type,
|
19242 | translate = this._translate;
|
19243 |
|
19244 | refSemantic = semantic[side + 'Ref'];
|
19245 |
|
19246 |
|
19247 | if (side === 'source' && type === 'bpmn:DataInputAssociation') {
|
19248 | refSemantic = refSemantic && refSemantic[0];
|
19249 | }
|
19250 |
|
19251 |
|
19252 | if (side === 'source' && type === 'bpmn:DataOutputAssociation' ||
|
19253 | side === 'target' && type === 'bpmn:DataInputAssociation') {
|
19254 |
|
19255 | refSemantic = semantic.$parent;
|
19256 | }
|
19257 |
|
19258 | element = refSemantic && this._getElement(refSemantic);
|
19259 |
|
19260 | if (element) {
|
19261 | return element;
|
19262 | }
|
19263 |
|
19264 | if (refSemantic) {
|
19265 | throw notYetDrawn(translate, semantic, refSemantic, side + 'Ref');
|
19266 | } else {
|
19267 | throw new Error(translate('{semantic}#{side} Ref not specified', {
|
19268 | semantic: elementToString(semantic),
|
19269 | side: side
|
19270 | }));
|
19271 | }
|
19272 | };
|
19273 |
|
19274 | BpmnImporter.prototype._getSource = function(semantic) {
|
19275 | return this._getEnd(semantic, 'source');
|
19276 | };
|
19277 |
|
19278 | BpmnImporter.prototype._getTarget = function(semantic) {
|
19279 | return this._getEnd(semantic, 'target');
|
19280 | };
|
19281 |
|
19282 |
|
19283 | BpmnImporter.prototype._getElement = function(semantic) {
|
19284 | return this._elementRegistry.get(semantic.id);
|
19285 | };
|
19286 |
|
19287 |
|
19288 |
|
19289 |
|
19290 | function isPointInsideBBox$1(bbox, point) {
|
19291 | var x = point.x,
|
19292 | y = point.y;
|
19293 |
|
19294 | return x >= bbox.x &&
|
19295 | x <= bbox.x + bbox.width &&
|
19296 | y >= bbox.y &&
|
19297 | y <= bbox.y + bbox.height;
|
19298 | }
|
19299 |
|
19300 | var ImportModule = {
|
19301 | __depends__: [
|
19302 | translate$2
|
19303 | ],
|
19304 | bpmnImporter: [ 'type', BpmnImporter ]
|
19305 | };
|
19306 |
|
19307 | var CoreModule$1 = {
|
19308 | __depends__: [
|
19309 | DrawModule$1,
|
19310 | ImportModule
|
19311 | ]
|
19312 | };
|
19313 |
|
19314 | function __stopPropagation(event) {
|
19315 | if (!event || typeof event.stopPropagation !== 'function') {
|
19316 | return;
|
19317 | }
|
19318 |
|
19319 | event.stopPropagation();
|
19320 | }
|
19321 |
|
19322 |
|
19323 | function getOriginal(event) {
|
19324 | return event.originalEvent || event.srcEvent;
|
19325 | }
|
19326 |
|
19327 |
|
19328 | function stopPropagation(event, immediate) {
|
19329 | __stopPropagation(event);
|
19330 | __stopPropagation(getOriginal(event));
|
19331 | }
|
19332 |
|
19333 |
|
19334 | function toPoint(event) {
|
19335 |
|
19336 | if (event.pointers && event.pointers.length) {
|
19337 | event = event.pointers[0];
|
19338 | }
|
19339 |
|
19340 | if (event.touches && event.touches.length) {
|
19341 | event = event.touches[0];
|
19342 | }
|
19343 |
|
19344 | return event ? {
|
19345 | x: event.clientX,
|
19346 | y: event.clientY
|
19347 | } : null;
|
19348 | }
|
19349 |
|
19350 | function isMac() {
|
19351 | return (/mac/i).test(navigator.platform);
|
19352 | }
|
19353 |
|
19354 | function isPrimaryButton(event) {
|
19355 |
|
19356 |
|
19357 | return !(getOriginal(event) || event).button;
|
19358 | }
|
19359 |
|
19360 | function hasPrimaryModifier(event) {
|
19361 | var originalEvent = getOriginal(event) || event;
|
19362 |
|
19363 | if (!isPrimaryButton(event)) {
|
19364 | return false;
|
19365 | }
|
19366 |
|
19367 |
|
19368 | if (isMac()) {
|
19369 | return originalEvent.metaKey;
|
19370 | } else {
|
19371 | return originalEvent.ctrlKey;
|
19372 | }
|
19373 | }
|
19374 |
|
19375 |
|
19376 | function hasSecondaryModifier(event) {
|
19377 | var originalEvent = getOriginal(event) || event;
|
19378 |
|
19379 | return isPrimaryButton(event) && originalEvent.shiftKey;
|
19380 | }
|
19381 |
|
19382 | function allowAll(e) { return true; }
|
19383 |
|
19384 | var LOW_PRIORITY = 500;
|
19385 |
|
19386 |
|
19387 | |
19388 |
|
19389 |
|
19390 |
|
19391 |
|
19392 |
|
19393 |
|
19394 |
|
19395 |
|
19396 |
|
19397 |
|
19398 |
|
19399 |
|
19400 |
|
19401 |
|
19402 |
|
19403 |
|
19404 |
|
19405 |
|
19406 |
|
19407 |
|
19408 | function InteractionEvents(eventBus, elementRegistry, styles) {
|
19409 |
|
19410 | var self = this;
|
19411 |
|
19412 | |
19413 |
|
19414 |
|
19415 |
|
19416 |
|
19417 |
|
19418 |
|
19419 |
|
19420 | function fire(type, event, element) {
|
19421 |
|
19422 | if (isIgnored(type, event)) {
|
19423 | return;
|
19424 | }
|
19425 |
|
19426 | var target, gfx, returnValue;
|
19427 |
|
19428 | if (!element) {
|
19429 | target = event.delegateTarget || event.target;
|
19430 |
|
19431 | if (target) {
|
19432 | gfx = target;
|
19433 | element = elementRegistry.get(gfx);
|
19434 | }
|
19435 | } else {
|
19436 | gfx = elementRegistry.getGraphics(element);
|
19437 | }
|
19438 |
|
19439 | if (!gfx || !element) {
|
19440 | return;
|
19441 | }
|
19442 |
|
19443 | returnValue = eventBus.fire(type, {
|
19444 | element: element,
|
19445 | gfx: gfx,
|
19446 | originalEvent: event
|
19447 | });
|
19448 |
|
19449 | if (returnValue === false) {
|
19450 | event.stopPropagation();
|
19451 | event.preventDefault();
|
19452 | }
|
19453 | }
|
19454 |
|
19455 |
|
19456 | var handlers = {};
|
19457 |
|
19458 | function mouseHandler(localEventName) {
|
19459 | return handlers[localEventName];
|
19460 | }
|
19461 |
|
19462 | function isIgnored(localEventName, event) {
|
19463 |
|
19464 | var filter = ignoredFilters[localEventName] || isPrimaryButton;
|
19465 |
|
19466 |
|
19467 |
|
19468 |
|
19469 | return !filter(event);
|
19470 | }
|
19471 |
|
19472 | var bindings = {
|
19473 | click: 'element.click',
|
19474 | contextmenu: 'element.contextmenu',
|
19475 | dblclick: 'element.dblclick',
|
19476 | mousedown: 'element.mousedown',
|
19477 | mousemove: 'element.mousemove',
|
19478 | mouseover: 'element.hover',
|
19479 | mouseout: 'element.out',
|
19480 | mouseup: 'element.mouseup',
|
19481 | };
|
19482 |
|
19483 | var ignoredFilters = {
|
19484 | 'element.contextmenu': allowAll
|
19485 | };
|
19486 |
|
19487 |
|
19488 |
|
19489 |
|
19490 | |
19491 |
|
19492 |
|
19493 |
|
19494 |
|
19495 |
|
19496 |
|
19497 |
|
19498 | function triggerMouseEvent(eventName, event, targetElement) {
|
19499 |
|
19500 |
|
19501 | var localEventName = bindings[eventName];
|
19502 |
|
19503 | if (!localEventName) {
|
19504 | throw new Error('unmapped DOM event name <' + eventName + '>');
|
19505 | }
|
19506 |
|
19507 | return fire(localEventName, event, targetElement);
|
19508 | }
|
19509 |
|
19510 |
|
19511 | var ELEMENT_SELECTOR = 'svg, .djs-element';
|
19512 |
|
19513 |
|
19514 |
|
19515 | function registerEvent(node, event, localEvent, ignoredFilter) {
|
19516 |
|
19517 | var handler = handlers[localEvent] = function(event) {
|
19518 | fire(localEvent, event);
|
19519 | };
|
19520 |
|
19521 | if (ignoredFilter) {
|
19522 | ignoredFilters[localEvent] = ignoredFilter;
|
19523 | }
|
19524 |
|
19525 | handler.$delegate = delegateEvents.bind(node, ELEMENT_SELECTOR, event, handler);
|
19526 | }
|
19527 |
|
19528 | function unregisterEvent(node, event, localEvent) {
|
19529 |
|
19530 | var handler = mouseHandler(localEvent);
|
19531 |
|
19532 | if (!handler) {
|
19533 | return;
|
19534 | }
|
19535 |
|
19536 | delegateEvents.unbind(node, event, handler.$delegate);
|
19537 | }
|
19538 |
|
19539 | function registerEvents(svg) {
|
19540 | forEach(bindings, function(val, key) {
|
19541 | registerEvent(svg, key, val);
|
19542 | });
|
19543 | }
|
19544 |
|
19545 | function unregisterEvents(svg) {
|
19546 | forEach(bindings, function(val, key) {
|
19547 | unregisterEvent(svg, key, val);
|
19548 | });
|
19549 | }
|
19550 |
|
19551 | eventBus.on('canvas.destroy', function(event) {
|
19552 | unregisterEvents(event.svg);
|
19553 | });
|
19554 |
|
19555 | eventBus.on('canvas.init', function(event) {
|
19556 | registerEvents(event.svg);
|
19557 | });
|
19558 |
|
19559 |
|
19560 |
|
19561 |
|
19562 | eventBus.on([ 'shape.added', 'connection.added' ], function(event) {
|
19563 | var element = event.element,
|
19564 | gfx = event.gfx;
|
19565 |
|
19566 | eventBus.fire('interactionEvents.createHit', { element: element, gfx: gfx });
|
19567 | });
|
19568 |
|
19569 |
|
19570 |
|
19571 |
|
19572 | eventBus.on([
|
19573 | 'shape.changed',
|
19574 | 'connection.changed'
|
19575 | ], LOW_PRIORITY, function(event) {
|
19576 |
|
19577 | var element = event.element,
|
19578 | gfx = event.gfx;
|
19579 |
|
19580 | eventBus.fire('interactionEvents.updateHit', { element: element, gfx: gfx });
|
19581 | });
|
19582 |
|
19583 | eventBus.on('interactionEvents.createHit', LOW_PRIORITY, function(event) {
|
19584 | var element = event.element,
|
19585 | gfx = event.gfx;
|
19586 |
|
19587 | self.createDefaultHit(element, gfx);
|
19588 | });
|
19589 |
|
19590 | eventBus.on('interactionEvents.updateHit', function(event) {
|
19591 | var element = event.element,
|
19592 | gfx = event.gfx;
|
19593 |
|
19594 | self.updateDefaultHit(element, gfx);
|
19595 | });
|
19596 |
|
19597 |
|
19598 |
|
19599 |
|
19600 | var STROKE_HIT_STYLE = createHitStyle('djs-hit djs-hit-stroke');
|
19601 |
|
19602 | var CLICK_STROKE_HIT_STYLE = createHitStyle('djs-hit djs-hit-click-stroke');
|
19603 |
|
19604 | var ALL_HIT_STYLE = createHitStyle('djs-hit djs-hit-all');
|
19605 |
|
19606 | var HIT_TYPES = {
|
19607 | 'all': ALL_HIT_STYLE,
|
19608 | 'click-stroke': CLICK_STROKE_HIT_STYLE,
|
19609 | 'stroke': STROKE_HIT_STYLE
|
19610 | };
|
19611 |
|
19612 | function createHitStyle(classNames, attrs) {
|
19613 |
|
19614 | attrs = assign({
|
19615 | stroke: 'white',
|
19616 | strokeWidth: 15
|
19617 | }, attrs || {});
|
19618 |
|
19619 | return styles.cls(classNames, [ 'no-fill', 'no-border' ], attrs);
|
19620 | }
|
19621 |
|
19622 |
|
19623 |
|
19624 |
|
19625 | function applyStyle(hit, type) {
|
19626 |
|
19627 | var attrs = HIT_TYPES[type];
|
19628 |
|
19629 | if (!attrs) {
|
19630 | throw new Error('invalid hit type <' + type + '>');
|
19631 | }
|
19632 |
|
19633 | attr$1(hit, attrs);
|
19634 |
|
19635 | return hit;
|
19636 | }
|
19637 |
|
19638 | function appendHit(gfx, hit) {
|
19639 | append(gfx, hit);
|
19640 | }
|
19641 |
|
19642 |
|
19643 |
|
19644 |
|
19645 | |
19646 |
|
19647 |
|
19648 |
|
19649 |
|
19650 | this.removeHits = function(gfx) {
|
19651 | var hits = all('.djs-hit', gfx);
|
19652 |
|
19653 | forEach(hits, remove$1);
|
19654 | };
|
19655 |
|
19656 | |
19657 |
|
19658 |
|
19659 |
|
19660 |
|
19661 |
|
19662 |
|
19663 |
|
19664 | this.createDefaultHit = function(element, gfx) {
|
19665 | var waypoints = element.waypoints,
|
19666 | isFrame = element.isFrame,
|
19667 | boxType;
|
19668 |
|
19669 | if (waypoints) {
|
19670 | return this.createWaypointsHit(gfx, waypoints);
|
19671 | } else {
|
19672 |
|
19673 | boxType = isFrame ? 'stroke' : 'all';
|
19674 |
|
19675 | return this.createBoxHit(gfx, boxType, {
|
19676 | width: element.width,
|
19677 | height: element.height
|
19678 | });
|
19679 | }
|
19680 | };
|
19681 |
|
19682 | |
19683 |
|
19684 |
|
19685 |
|
19686 |
|
19687 |
|
19688 |
|
19689 |
|
19690 | this.createWaypointsHit = function(gfx, waypoints) {
|
19691 |
|
19692 | var hit = createLine(waypoints);
|
19693 |
|
19694 | applyStyle(hit, 'stroke');
|
19695 |
|
19696 | appendHit(gfx, hit);
|
19697 |
|
19698 | return hit;
|
19699 | };
|
19700 |
|
19701 | |
19702 |
|
19703 |
|
19704 |
|
19705 |
|
19706 |
|
19707 |
|
19708 |
|
19709 |
|
19710 | this.createBoxHit = function(gfx, type, attrs) {
|
19711 |
|
19712 | attrs = assign({
|
19713 | x: 0,
|
19714 | y: 0
|
19715 | }, attrs);
|
19716 |
|
19717 | var hit = create('rect');
|
19718 |
|
19719 | applyStyle(hit, type);
|
19720 |
|
19721 | attr$1(hit, attrs);
|
19722 |
|
19723 | appendHit(gfx, hit);
|
19724 |
|
19725 | return hit;
|
19726 | };
|
19727 |
|
19728 | |
19729 |
|
19730 |
|
19731 |
|
19732 |
|
19733 |
|
19734 |
|
19735 |
|
19736 | this.updateDefaultHit = function(element, gfx) {
|
19737 |
|
19738 | var hit = query('.djs-hit', gfx);
|
19739 |
|
19740 | if (!hit) {
|
19741 | return;
|
19742 | }
|
19743 |
|
19744 | if (element.waypoints) {
|
19745 | updateLine(hit, element.waypoints);
|
19746 | } else {
|
19747 | attr$1(hit, {
|
19748 | width: element.width,
|
19749 | height: element.height
|
19750 | });
|
19751 | }
|
19752 |
|
19753 | return hit;
|
19754 | };
|
19755 |
|
19756 | this.fire = fire;
|
19757 |
|
19758 | this.triggerMouseEvent = triggerMouseEvent;
|
19759 |
|
19760 | this.mouseHandler = mouseHandler;
|
19761 |
|
19762 | this.registerEvent = registerEvent;
|
19763 | this.unregisterEvent = unregisterEvent;
|
19764 | }
|
19765 |
|
19766 |
|
19767 | InteractionEvents.$inject = [
|
19768 | 'eventBus',
|
19769 | 'elementRegistry',
|
19770 | 'styles'
|
19771 | ];
|
19772 |
|
19773 |
|
19774 | |
19775 |
|
19776 |
|
19777 |
|
19778 |
|
19779 |
|
19780 |
|
19781 |
|
19782 |
|
19783 |
|
19784 |
|
19785 | |
19786 |
|
19787 |
|
19788 |
|
19789 |
|
19790 |
|
19791 |
|
19792 |
|
19793 |
|
19794 |
|
19795 |
|
19796 | |
19797 |
|
19798 |
|
19799 |
|
19800 |
|
19801 |
|
19802 |
|
19803 |
|
19804 |
|
19805 |
|
19806 |
|
19807 | |
19808 |
|
19809 |
|
19810 |
|
19811 |
|
19812 |
|
19813 |
|
19814 |
|
19815 |
|
19816 |
|
19817 |
|
19818 | |
19819 |
|
19820 |
|
19821 |
|
19822 |
|
19823 |
|
19824 |
|
19825 |
|
19826 |
|
19827 |
|
19828 |
|
19829 | |
19830 |
|
19831 |
|
19832 |
|
19833 |
|
19834 |
|
19835 |
|
19836 |
|
19837 |
|
19838 |
|
19839 |
|
19840 | |
19841 |
|
19842 |
|
19843 |
|
19844 |
|
19845 |
|
19846 |
|
19847 |
|
19848 |
|
19849 |
|
19850 |
|
19851 |
|
19852 | var InteractionEventsModule = {
|
19853 | __init__: [ 'interactionEvents' ],
|
19854 | interactionEvents: [ 'type', InteractionEvents ]
|
19855 | };
|
19856 |
|
19857 | var LOW_PRIORITY$1 = 500;
|
19858 |
|
19859 |
|
19860 | |
19861 |
|
19862 |
|
19863 |
|
19864 |
|
19865 |
|
19866 |
|
19867 |
|
19868 |
|
19869 |
|
19870 | function Outline(eventBus, styles, elementRegistry) {
|
19871 |
|
19872 | this.offset = 6;
|
19873 |
|
19874 | var OUTLINE_STYLE = styles.cls('djs-outline', [ 'no-fill' ]);
|
19875 |
|
19876 | var self = this;
|
19877 |
|
19878 | function createOutline(gfx, bounds) {
|
19879 | var outline = create('rect');
|
19880 |
|
19881 | attr$1(outline, assign({
|
19882 | x: 10,
|
19883 | y: 10,
|
19884 | width: 100,
|
19885 | height: 100
|
19886 | }, OUTLINE_STYLE));
|
19887 |
|
19888 | append(gfx, outline);
|
19889 |
|
19890 | return outline;
|
19891 | }
|
19892 |
|
19893 |
|
19894 |
|
19895 | eventBus.on([ 'shape.added', 'shape.changed' ], LOW_PRIORITY$1, function(event) {
|
19896 | var element = event.element,
|
19897 | gfx = event.gfx;
|
19898 |
|
19899 | var outline = query('.djs-outline', gfx);
|
19900 |
|
19901 | if (!outline) {
|
19902 | outline = createOutline(gfx);
|
19903 | }
|
19904 |
|
19905 | self.updateShapeOutline(outline, element);
|
19906 | });
|
19907 |
|
19908 | eventBus.on([ 'connection.added', 'connection.changed' ], function(event) {
|
19909 | var element = event.element,
|
19910 | gfx = event.gfx;
|
19911 |
|
19912 | var outline = query('.djs-outline', gfx);
|
19913 |
|
19914 | if (!outline) {
|
19915 | outline = createOutline(gfx);
|
19916 | }
|
19917 |
|
19918 | self.updateConnectionOutline(outline, element);
|
19919 | });
|
19920 | }
|
19921 |
|
19922 |
|
19923 | |
19924 |
|
19925 |
|
19926 |
|
19927 |
|
19928 |
|
19929 |
|
19930 | Outline.prototype.updateShapeOutline = function(outline, element) {
|
19931 |
|
19932 | attr$1(outline, {
|
19933 | x: -this.offset,
|
19934 | y: -this.offset,
|
19935 | width: element.width + this.offset * 2,
|
19936 | height: element.height + this.offset * 2
|
19937 | });
|
19938 |
|
19939 | };
|
19940 |
|
19941 |
|
19942 | |
19943 |
|
19944 |
|
19945 |
|
19946 |
|
19947 |
|
19948 |
|
19949 | Outline.prototype.updateConnectionOutline = function(outline, connection) {
|
19950 |
|
19951 | var bbox = getBBox(connection);
|
19952 |
|
19953 | attr$1(outline, {
|
19954 | x: bbox.x - this.offset,
|
19955 | y: bbox.y - this.offset,
|
19956 | width: bbox.width + this.offset * 2,
|
19957 | height: bbox.height + this.offset * 2
|
19958 | });
|
19959 |
|
19960 | };
|
19961 |
|
19962 |
|
19963 | Outline.$inject = ['eventBus', 'styles', 'elementRegistry'];
|
19964 |
|
19965 | var OutlineModule = {
|
19966 | __init__: [ 'outline' ],
|
19967 | outline: [ 'type', Outline ]
|
19968 | };
|
19969 |
|
19970 | |
19971 |
|
19972 |
|
19973 |
|
19974 |
|
19975 |
|
19976 |
|
19977 |
|
19978 | function Selection(eventBus) {
|
19979 |
|
19980 | this._eventBus = eventBus;
|
19981 |
|
19982 | this._selectedElements = [];
|
19983 |
|
19984 | var self = this;
|
19985 |
|
19986 | eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
|
19987 | var element = e.element;
|
19988 | self.deselect(element);
|
19989 | });
|
19990 |
|
19991 | eventBus.on([ 'diagram.clear' ], function(e) {
|
19992 | self.select(null);
|
19993 | });
|
19994 | }
|
19995 |
|
19996 | Selection.$inject = [ 'eventBus' ];
|
19997 |
|
19998 |
|
19999 | Selection.prototype.deselect = function(element) {
|
20000 | var selectedElements = this._selectedElements;
|
20001 |
|
20002 | var idx = selectedElements.indexOf(element);
|
20003 |
|
20004 | if (idx !== -1) {
|
20005 | var oldSelection = selectedElements.slice();
|
20006 |
|
20007 | selectedElements.splice(idx, 1);
|
20008 |
|
20009 | this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
|
20010 | }
|
20011 | };
|
20012 |
|
20013 |
|
20014 | Selection.prototype.get = function() {
|
20015 | return this._selectedElements;
|
20016 | };
|
20017 |
|
20018 | Selection.prototype.isSelected = function(element) {
|
20019 | return this._selectedElements.indexOf(element) !== -1;
|
20020 | };
|
20021 |
|
20022 |
|
20023 | |
20024 |
|
20025 |
|
20026 |
|
20027 |
|
20028 |
|
20029 |
|
20030 |
|
20031 |
|
20032 |
|
20033 |
|
20034 | Selection.prototype.select = function(elements, add) {
|
20035 | var selectedElements = this._selectedElements,
|
20036 | oldSelection = selectedElements.slice();
|
20037 |
|
20038 | if (!isArray(elements)) {
|
20039 | elements = elements ? [ elements ] : [];
|
20040 | }
|
20041 |
|
20042 |
|
20043 |
|
20044 | if (add) {
|
20045 | forEach(elements, function(element) {
|
20046 | if (selectedElements.indexOf(element) !== -1) {
|
20047 |
|
20048 |
|
20049 | return;
|
20050 | } else {
|
20051 | selectedElements.push(element);
|
20052 | }
|
20053 | });
|
20054 | } else {
|
20055 | this._selectedElements = selectedElements = elements.slice();
|
20056 | }
|
20057 |
|
20058 | this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
|
20059 | };
|
20060 |
|
20061 | var MARKER_HOVER = 'hover',
|
20062 | MARKER_SELECTED = 'selected';
|
20063 |
|
20064 |
|
20065 | |
20066 |
|
20067 |
|
20068 |
|
20069 |
|
20070 |
|
20071 |
|
20072 |
|
20073 |
|
20074 |
|
20075 |
|
20076 |
|
20077 | function SelectionVisuals(events, canvas, selection, styles) {
|
20078 |
|
20079 | this._multiSelectionBox = null;
|
20080 |
|
20081 | function addMarker(e, cls) {
|
20082 | canvas.addMarker(e, cls);
|
20083 | }
|
20084 |
|
20085 | function removeMarker(e, cls) {
|
20086 | canvas.removeMarker(e, cls);
|
20087 | }
|
20088 |
|
20089 | events.on('element.hover', function(event) {
|
20090 | addMarker(event.element, MARKER_HOVER);
|
20091 | });
|
20092 |
|
20093 | events.on('element.out', function(event) {
|
20094 | removeMarker(event.element, MARKER_HOVER);
|
20095 | });
|
20096 |
|
20097 | events.on('selection.changed', function(event) {
|
20098 |
|
20099 | function deselect(s) {
|
20100 | removeMarker(s, MARKER_SELECTED);
|
20101 | }
|
20102 |
|
20103 | function select(s) {
|
20104 | addMarker(s, MARKER_SELECTED);
|
20105 | }
|
20106 |
|
20107 | var oldSelection = event.oldSelection,
|
20108 | newSelection = event.newSelection;
|
20109 |
|
20110 | forEach(oldSelection, function(e) {
|
20111 | if (newSelection.indexOf(e) === -1) {
|
20112 | deselect(e);
|
20113 | }
|
20114 | });
|
20115 |
|
20116 | forEach(newSelection, function(e) {
|
20117 | if (oldSelection.indexOf(e) === -1) {
|
20118 | select(e);
|
20119 | }
|
20120 | });
|
20121 | });
|
20122 | }
|
20123 |
|
20124 | SelectionVisuals.$inject = [
|
20125 | 'eventBus',
|
20126 | 'canvas',
|
20127 | 'selection',
|
20128 | 'styles'
|
20129 | ];
|
20130 |
|
20131 | function SelectionBehavior(
|
20132 | eventBus, selection, canvas,
|
20133 | elementRegistry) {
|
20134 |
|
20135 | eventBus.on('create.end', 500, function(e) {
|
20136 |
|
20137 | var context = e.context,
|
20138 | canExecute = context.canExecute,
|
20139 | elements = context.elements,
|
20140 | hints = context.hints || {},
|
20141 | autoSelect = hints.autoSelect;
|
20142 |
|
20143 |
|
20144 | if (canExecute) {
|
20145 | if (autoSelect === false) {
|
20146 |
|
20147 |
|
20148 | return;
|
20149 | }
|
20150 |
|
20151 | if (isArray(autoSelect)) {
|
20152 | selection.select(autoSelect);
|
20153 | } else {
|
20154 |
|
20155 |
|
20156 | selection.select(elements);
|
20157 | }
|
20158 | }
|
20159 | });
|
20160 |
|
20161 | eventBus.on('connect.end', 500, function(e) {
|
20162 |
|
20163 |
|
20164 |
|
20165 | if (e.context.canExecute && e.context.target) {
|
20166 | selection.select(e.context.target);
|
20167 | }
|
20168 | });
|
20169 |
|
20170 | eventBus.on('shape.move.end', 500, function(e) {
|
20171 | var previousSelection = e.previousSelection || [];
|
20172 |
|
20173 | var shape = elementRegistry.get(e.context.shape.id);
|
20174 |
|
20175 |
|
20176 |
|
20177 | var inSelection = find(previousSelection, function(selectedShape) {
|
20178 | return shape.id === selectedShape.id;
|
20179 | });
|
20180 |
|
20181 | if (!inSelection) {
|
20182 | selection.select(shape);
|
20183 | }
|
20184 | });
|
20185 |
|
20186 |
|
20187 | eventBus.on('element.click', function(event) {
|
20188 |
|
20189 | var element = event.element;
|
20190 |
|
20191 |
|
20192 |
|
20193 | if (element === canvas.getRootElement()) {
|
20194 | element = null;
|
20195 | }
|
20196 |
|
20197 | var isSelected = selection.isSelected(element),
|
20198 | isMultiSelect = selection.get().length > 1;
|
20199 |
|
20200 |
|
20201 | var add = hasPrimaryModifier(event);
|
20202 |
|
20203 |
|
20204 | if (isSelected && isMultiSelect) {
|
20205 | if (add) {
|
20206 | return selection.deselect(element);
|
20207 | } else {
|
20208 | return selection.select(element);
|
20209 | }
|
20210 | } else
|
20211 | if (!isSelected) {
|
20212 | selection.select(element, add);
|
20213 | } else {
|
20214 | selection.deselect(element);
|
20215 | }
|
20216 | });
|
20217 | }
|
20218 |
|
20219 | SelectionBehavior.$inject = [
|
20220 | 'eventBus',
|
20221 | 'selection',
|
20222 | 'canvas',
|
20223 | 'elementRegistry'
|
20224 | ];
|
20225 |
|
20226 | var SelectionModule = {
|
20227 | __init__: [ 'selectionVisuals', 'selectionBehavior' ],
|
20228 | __depends__: [
|
20229 | InteractionEventsModule,
|
20230 | OutlineModule
|
20231 | ],
|
20232 | selection: [ 'type', Selection ],
|
20233 | selectionVisuals: [ 'type', SelectionVisuals ],
|
20234 | selectionBehavior: [ 'type', SelectionBehavior ]
|
20235 | };
|
20236 |
|
20237 | |
20238 |
|
20239 |
|
20240 |
|
20241 |
|
20242 |
|
20243 |
|
20244 |
|
20245 |
|
20246 |
|
20247 |
|
20248 | function IdGenerator(prefix) {
|
20249 |
|
20250 | this._counter = 0;
|
20251 | this._prefix = (prefix ? prefix + '-' : '') + Math.floor(Math.random() * 1000000000) + '-';
|
20252 | }
|
20253 |
|
20254 | |
20255 |
|
20256 |
|
20257 |
|
20258 |
|
20259 |
|
20260 |
|
20261 | IdGenerator.prototype.next = function() {
|
20262 | return this._prefix + (++this._counter);
|
20263 | };
|
20264 |
|
20265 |
|
20266 | var ids = new IdGenerator('ov');
|
20267 |
|
20268 | var LOW_PRIORITY$2 = 500;
|
20269 |
|
20270 |
|
20271 | |
20272 |
|
20273 |
|
20274 |
|
20275 |
|
20276 |
|
20277 |
|
20278 |
|
20279 |
|
20280 |
|
20281 |
|
20282 |
|
20283 |
|
20284 |
|
20285 |
|
20286 |
|
20287 |
|
20288 |
|
20289 |
|
20290 |
|
20291 |
|
20292 |
|
20293 |
|
20294 |
|
20295 |
|
20296 |
|
20297 |
|
20298 |
|
20299 |
|
20300 |
|
20301 |
|
20302 |
|
20303 |
|
20304 |
|
20305 |
|
20306 |
|
20307 |
|
20308 |
|
20309 |
|
20310 |
|
20311 |
|
20312 |
|
20313 |
|
20314 |
|
20315 |
|
20316 |
|
20317 |
|
20318 |
|
20319 |
|
20320 |
|
20321 |
|
20322 |
|
20323 |
|
20324 |
|
20325 |
|
20326 |
|
20327 |
|
20328 |
|
20329 |
|
20330 |
|
20331 |
|
20332 |
|
20333 |
|
20334 |
|
20335 | function Overlays(config, eventBus, canvas, elementRegistry) {
|
20336 |
|
20337 | this._eventBus = eventBus;
|
20338 | this._canvas = canvas;
|
20339 | this._elementRegistry = elementRegistry;
|
20340 |
|
20341 | this._ids = ids;
|
20342 |
|
20343 | this._overlayDefaults = assign({
|
20344 |
|
20345 |
|
20346 | show: null,
|
20347 |
|
20348 |
|
20349 | scale: true
|
20350 | }, config && config.defaults);
|
20351 |
|
20352 | |
20353 |
|
20354 |
|
20355 | this._overlays = {};
|
20356 |
|
20357 | |
20358 |
|
20359 |
|
20360 | this._overlayContainers = [];
|
20361 |
|
20362 |
|
20363 | this._overlayRoot = createRoot(canvas.getContainer());
|
20364 |
|
20365 | this._init();
|
20366 | }
|
20367 |
|
20368 |
|
20369 | Overlays.$inject = [
|
20370 | 'config.overlays',
|
20371 | 'eventBus',
|
20372 | 'canvas',
|
20373 | 'elementRegistry'
|
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 |
|
20401 |
|
20402 |
|
20403 | Overlays.prototype.get = function(search) {
|
20404 |
|
20405 | if (isString(search)) {
|
20406 | search = { id: search };
|
20407 | }
|
20408 |
|
20409 | if (isString(search.element)) {
|
20410 | search.element = this._elementRegistry.get(search.element);
|
20411 | }
|
20412 |
|
20413 | if (search.element) {
|
20414 | var container = this._getOverlayContainer(search.element, true);
|
20415 |
|
20416 |
|
20417 | if (container) {
|
20418 | return search.type ? filter(container.overlays, matchPattern({ type: search.type })) : container.overlays.slice();
|
20419 | } else {
|
20420 | return [];
|
20421 | }
|
20422 | } else
|
20423 | if (search.type) {
|
20424 | return filter(this._overlays, matchPattern({ type: search.type }));
|
20425 | } else {
|
20426 |
|
20427 |
|
20428 | return search.id ? this._overlays[search.id] : null;
|
20429 | }
|
20430 | };
|
20431 |
|
20432 | |
20433 |
|
20434 |
|
20435 |
|
20436 |
|
20437 |
|
20438 |
|
20439 |
|
20440 |
|
20441 |
|
20442 |
|
20443 |
|
20444 |
|
20445 |
|
20446 |
|
20447 |
|
20448 |
|
20449 |
|
20450 |
|
20451 |
|
20452 |
|
20453 |
|
20454 |
|
20455 | Overlays.prototype.add = function(element, type, overlay) {
|
20456 |
|
20457 | if (isObject(type)) {
|
20458 | overlay = type;
|
20459 | type = null;
|
20460 | }
|
20461 |
|
20462 | if (!element.id) {
|
20463 | element = this._elementRegistry.get(element);
|
20464 | }
|
20465 |
|
20466 | if (!overlay.position) {
|
20467 | throw new Error('must specifiy overlay position');
|
20468 | }
|
20469 |
|
20470 | if (!overlay.html) {
|
20471 | throw new Error('must specifiy overlay html');
|
20472 | }
|
20473 |
|
20474 | if (!element) {
|
20475 | throw new Error('invalid element specified');
|
20476 | }
|
20477 |
|
20478 | var id = this._ids.next();
|
20479 |
|
20480 | overlay = assign({}, this._overlayDefaults, overlay, {
|
20481 | id: id,
|
20482 | type: type,
|
20483 | element: element,
|
20484 | html: overlay.html
|
20485 | });
|
20486 |
|
20487 | this._addOverlay(overlay);
|
20488 |
|
20489 | return id;
|
20490 | };
|
20491 |
|
20492 |
|
20493 | |
20494 |
|
20495 |
|
20496 |
|
20497 |
|
20498 |
|
20499 |
|
20500 |
|
20501 | Overlays.prototype.remove = function(filter) {
|
20502 |
|
20503 | var overlays = this.get(filter) || [];
|
20504 |
|
20505 | if (!isArray(overlays)) {
|
20506 | overlays = [ overlays ];
|
20507 | }
|
20508 |
|
20509 | var self = this;
|
20510 |
|
20511 | forEach(overlays, function(overlay) {
|
20512 |
|
20513 | var container = self._getOverlayContainer(overlay.element, true);
|
20514 |
|
20515 | if (overlay) {
|
20516 | remove(overlay.html);
|
20517 | remove(overlay.htmlContainer);
|
20518 |
|
20519 | delete overlay.htmlContainer;
|
20520 | delete overlay.element;
|
20521 |
|
20522 | delete self._overlays[overlay.id];
|
20523 | }
|
20524 |
|
20525 | if (container) {
|
20526 | var idx = container.overlays.indexOf(overlay);
|
20527 | if (idx !== -1) {
|
20528 | container.overlays.splice(idx, 1);
|
20529 | }
|
20530 | }
|
20531 | });
|
20532 |
|
20533 | };
|
20534 |
|
20535 |
|
20536 | Overlays.prototype.show = function() {
|
20537 | setVisible(this._overlayRoot);
|
20538 | };
|
20539 |
|
20540 |
|
20541 | Overlays.prototype.hide = function() {
|
20542 | setVisible(this._overlayRoot, false);
|
20543 | };
|
20544 |
|
20545 | Overlays.prototype.clear = function() {
|
20546 | this._overlays = {};
|
20547 |
|
20548 | this._overlayContainers = [];
|
20549 |
|
20550 | clear(this._overlayRoot);
|
20551 | };
|
20552 |
|
20553 | Overlays.prototype._updateOverlayContainer = function(container) {
|
20554 | var element = container.element,
|
20555 | html = container.html;
|
20556 |
|
20557 |
|
20558 |
|
20559 |
|
20560 | var x = element.x,
|
20561 | y = element.y;
|
20562 |
|
20563 | if (element.waypoints) {
|
20564 | var bbox = getBBox(element);
|
20565 | x = bbox.x;
|
20566 | y = bbox.y;
|
20567 | }
|
20568 |
|
20569 | setPosition(html, x, y);
|
20570 |
|
20571 | attr(container.html, 'data-container-id', element.id);
|
20572 | };
|
20573 |
|
20574 |
|
20575 | Overlays.prototype._updateOverlay = function(overlay) {
|
20576 |
|
20577 | var position = overlay.position,
|
20578 | htmlContainer = overlay.htmlContainer,
|
20579 | element = overlay.element;
|
20580 |
|
20581 |
|
20582 |
|
20583 |
|
20584 |
|
20585 | var left = position.left,
|
20586 | top = position.top;
|
20587 |
|
20588 | if (position.right !== undefined) {
|
20589 |
|
20590 | var width;
|
20591 |
|
20592 | if (element.waypoints) {
|
20593 | width = getBBox(element).width;
|
20594 | } else {
|
20595 | width = element.width;
|
20596 | }
|
20597 |
|
20598 | left = position.right * -1 + width;
|
20599 | }
|
20600 |
|
20601 | if (position.bottom !== undefined) {
|
20602 |
|
20603 | var height;
|
20604 |
|
20605 | if (element.waypoints) {
|
20606 | height = getBBox(element).height;
|
20607 | } else {
|
20608 | height = element.height;
|
20609 | }
|
20610 |
|
20611 | top = position.bottom * -1 + height;
|
20612 | }
|
20613 |
|
20614 | setPosition(htmlContainer, left || 0, top || 0);
|
20615 | };
|
20616 |
|
20617 |
|
20618 | Overlays.prototype._createOverlayContainer = function(element) {
|
20619 | var html = domify('<div class="djs-overlays" style="position: absolute" />');
|
20620 |
|
20621 | this._overlayRoot.appendChild(html);
|
20622 |
|
20623 | var container = {
|
20624 | html: html,
|
20625 | element: element,
|
20626 | overlays: []
|
20627 | };
|
20628 |
|
20629 | this._updateOverlayContainer(container);
|
20630 |
|
20631 | this._overlayContainers.push(container);
|
20632 |
|
20633 | return container;
|
20634 | };
|
20635 |
|
20636 |
|
20637 | Overlays.prototype._updateRoot = function(viewbox) {
|
20638 | var scale = viewbox.scale || 1;
|
20639 |
|
20640 | var matrix = 'matrix(' +
|
20641 | [
|
20642 | scale,
|
20643 | 0,
|
20644 | 0,
|
20645 | scale,
|
20646 | -1 * viewbox.x * scale,
|
20647 | -1 * viewbox.y * scale
|
20648 | ].join(',') +
|
20649 | ')';
|
20650 |
|
20651 | setTransform(this._overlayRoot, matrix);
|
20652 | };
|
20653 |
|
20654 |
|
20655 | Overlays.prototype._getOverlayContainer = function(element, raw) {
|
20656 | var container = find(this._overlayContainers, function(c) {
|
20657 | return c.element === element;
|
20658 | });
|
20659 |
|
20660 |
|
20661 | if (!container && !raw) {
|
20662 | return this._createOverlayContainer(element);
|
20663 | }
|
20664 |
|
20665 | return container;
|
20666 | };
|
20667 |
|
20668 |
|
20669 | Overlays.prototype._addOverlay = function(overlay) {
|
20670 |
|
20671 | var id = overlay.id,
|
20672 | element = overlay.element,
|
20673 | html = overlay.html,
|
20674 | htmlContainer,
|
20675 | overlayContainer;
|
20676 |
|
20677 |
|
20678 | if (html.get && html.constructor.prototype.jquery) {
|
20679 | html = html.get(0);
|
20680 | }
|
20681 |
|
20682 |
|
20683 |
|
20684 | if (isString(html)) {
|
20685 | html = domify(html);
|
20686 | }
|
20687 |
|
20688 | overlayContainer = this._getOverlayContainer(element);
|
20689 |
|
20690 | htmlContainer = domify('<div class="djs-overlay" data-overlay-id="' + id + '" style="position: absolute">');
|
20691 |
|
20692 | htmlContainer.appendChild(html);
|
20693 |
|
20694 | if (overlay.type) {
|
20695 | classes(htmlContainer).add('djs-overlay-' + overlay.type);
|
20696 | }
|
20697 |
|
20698 | overlay.htmlContainer = htmlContainer;
|
20699 |
|
20700 | overlayContainer.overlays.push(overlay);
|
20701 | overlayContainer.html.appendChild(htmlContainer);
|
20702 |
|
20703 | this._overlays[id] = overlay;
|
20704 |
|
20705 | this._updateOverlay(overlay);
|
20706 | this._updateOverlayVisibilty(overlay, this._canvas.viewbox());
|
20707 | };
|
20708 |
|
20709 |
|
20710 | Overlays.prototype._updateOverlayVisibilty = function(overlay, viewbox) {
|
20711 | var show = overlay.show,
|
20712 | minZoom = show && show.minZoom,
|
20713 | maxZoom = show && show.maxZoom,
|
20714 | htmlContainer = overlay.htmlContainer,
|
20715 | visible = true;
|
20716 |
|
20717 | if (show) {
|
20718 | if (
|
20719 | (isDefined(minZoom) && minZoom > viewbox.scale) ||
|
20720 | (isDefined(maxZoom) && maxZoom < viewbox.scale)
|
20721 | ) {
|
20722 | visible = false;
|
20723 | }
|
20724 |
|
20725 | setVisible(htmlContainer, visible);
|
20726 | }
|
20727 |
|
20728 | this._updateOverlayScale(overlay, viewbox);
|
20729 | };
|
20730 |
|
20731 |
|
20732 | Overlays.prototype._updateOverlayScale = function(overlay, viewbox) {
|
20733 | var shouldScale = overlay.scale,
|
20734 | minScale,
|
20735 | maxScale,
|
20736 | htmlContainer = overlay.htmlContainer;
|
20737 |
|
20738 | var scale, transform = '';
|
20739 |
|
20740 | if (shouldScale !== true) {
|
20741 |
|
20742 | if (shouldScale === false) {
|
20743 | minScale = 1;
|
20744 | maxScale = 1;
|
20745 | } else {
|
20746 | minScale = shouldScale.min;
|
20747 | maxScale = shouldScale.max;
|
20748 | }
|
20749 |
|
20750 | if (isDefined(minScale) && viewbox.scale < minScale) {
|
20751 | scale = (1 / viewbox.scale || 1) * minScale;
|
20752 | }
|
20753 |
|
20754 | if (isDefined(maxScale) && viewbox.scale > maxScale) {
|
20755 | scale = (1 / viewbox.scale || 1) * maxScale;
|
20756 | }
|
20757 | }
|
20758 |
|
20759 | if (isDefined(scale)) {
|
20760 | transform = 'scale(' + scale + ',' + scale + ')';
|
20761 | }
|
20762 |
|
20763 | setTransform(htmlContainer, transform);
|
20764 | };
|
20765 |
|
20766 |
|
20767 | Overlays.prototype._updateOverlaysVisibilty = function(viewbox) {
|
20768 |
|
20769 | var self = this;
|
20770 |
|
20771 | forEach(this._overlays, function(overlay) {
|
20772 | self._updateOverlayVisibilty(overlay, viewbox);
|
20773 | });
|
20774 | };
|
20775 |
|
20776 |
|
20777 | Overlays.prototype._init = function() {
|
20778 |
|
20779 | var eventBus = this._eventBus;
|
20780 |
|
20781 | var self = this;
|
20782 |
|
20783 |
|
20784 |
|
20785 |
|
20786 | function updateViewbox(viewbox) {
|
20787 | self._updateRoot(viewbox);
|
20788 | self._updateOverlaysVisibilty(viewbox);
|
20789 |
|
20790 | self.show();
|
20791 | }
|
20792 |
|
20793 | eventBus.on('canvas.viewbox.changing', function(event) {
|
20794 | self.hide();
|
20795 | });
|
20796 |
|
20797 | eventBus.on('canvas.viewbox.changed', function(event) {
|
20798 | updateViewbox(event.viewbox);
|
20799 | });
|
20800 |
|
20801 |
|
20802 |
|
20803 |
|
20804 | eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
|
20805 | var element = e.element;
|
20806 | var overlays = self.get({ element: element });
|
20807 |
|
20808 | forEach(overlays, function(o) {
|
20809 | self.remove(o.id);
|
20810 | });
|
20811 |
|
20812 | var container = self._getOverlayContainer(element);
|
20813 |
|
20814 | if (container) {
|
20815 | remove(container.html);
|
20816 | var i = self._overlayContainers.indexOf(container);
|
20817 | if (i !== -1) {
|
20818 | self._overlayContainers.splice(i, 1);
|
20819 | }
|
20820 | }
|
20821 | });
|
20822 |
|
20823 |
|
20824 |
|
20825 |
|
20826 | eventBus.on('element.changed', LOW_PRIORITY$2, function(e) {
|
20827 | var element = e.element;
|
20828 |
|
20829 | var container = self._getOverlayContainer(element, true);
|
20830 |
|
20831 | if (container) {
|
20832 | forEach(container.overlays, function(overlay) {
|
20833 | self._updateOverlay(overlay);
|
20834 | });
|
20835 |
|
20836 | self._updateOverlayContainer(container);
|
20837 | }
|
20838 | });
|
20839 |
|
20840 |
|
20841 |
|
20842 |
|
20843 | eventBus.on('element.marker.update', function(e) {
|
20844 | var container = self._getOverlayContainer(e.element, true);
|
20845 | if (container) {
|
20846 | classes(container.html)[e.add ? 'add' : 'remove'](e.marker);
|
20847 | }
|
20848 | });
|
20849 |
|
20850 |
|
20851 |
|
20852 |
|
20853 | eventBus.on('diagram.clear', this.clear, this);
|
20854 | };
|
20855 |
|
20856 |
|
20857 |
|
20858 |
|
20859 |
|
20860 | function createRoot(parentNode) {
|
20861 | var root = domify(
|
20862 | '<div class="djs-overlay-container" style="position: absolute; width: 0; height: 0;" />'
|
20863 | );
|
20864 |
|
20865 | parentNode.insertBefore(root, parentNode.firstChild);
|
20866 |
|
20867 | return root;
|
20868 | }
|
20869 |
|
20870 | function setPosition(el, x, y) {
|
20871 | assign(el.style, { left: x + 'px', top: y + 'px' });
|
20872 | }
|
20873 |
|
20874 | function setVisible(el, visible) {
|
20875 | el.style.display = visible === false ? 'none' : '';
|
20876 | }
|
20877 |
|
20878 | function setTransform(el, transform) {
|
20879 |
|
20880 | el.style['transform-origin'] = 'top left';
|
20881 |
|
20882 | [ '', '-ms-', '-webkit-' ].forEach(function(prefix) {
|
20883 | el.style[prefix + 'transform'] = transform;
|
20884 | });
|
20885 | }
|
20886 |
|
20887 | var OverlaysModule = {
|
20888 | __init__: [ 'overlays' ],
|
20889 | overlays: [ 'type', Overlays ]
|
20890 | };
|
20891 |
|
20892 | |
20893 |
|
20894 |
|
20895 |
|
20896 |
|
20897 |
|
20898 |
|
20899 |
|
20900 |
|
20901 |
|
20902 |
|
20903 |
|
20904 |
|
20905 |
|
20906 |
|
20907 |
|
20908 |
|
20909 |
|
20910 |
|
20911 |
|
20912 |
|
20913 |
|
20914 |
|
20915 |
|
20916 |
|
20917 |
|
20918 |
|
20919 |
|
20920 |
|
20921 |
|
20922 |
|
20923 |
|
20924 |
|
20925 |
|
20926 |
|
20927 |
|
20928 |
|
20929 |
|
20930 |
|
20931 |
|
20932 |
|
20933 |
|
20934 |
|
20935 |
|
20936 |
|
20937 |
|
20938 |
|
20939 | function Viewer(options) {
|
20940 | BaseViewer.call(this, options);
|
20941 | }
|
20942 |
|
20943 | inherits_browser(Viewer, BaseViewer);
|
20944 |
|
20945 |
|
20946 | Viewer.prototype._modules = [
|
20947 | CoreModule$1,
|
20948 | translate$2,
|
20949 | SelectionModule,
|
20950 | OverlaysModule
|
20951 | ];
|
20952 |
|
20953 |
|
20954 | Viewer.prototype._moddleExtensions = {};
|
20955 |
|
20956 | |
20957 |
|
20958 |
|
20959 |
|
20960 | function hasModifier(event) {
|
20961 | return (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey);
|
20962 | }
|
20963 |
|
20964 | |
20965 |
|
20966 |
|
20967 | function isCmd(event) {
|
20968 |
|
20969 |
|
20970 |
|
20971 | if (event.altKey) {
|
20972 | return false;
|
20973 | }
|
20974 |
|
20975 | return event.ctrlKey || event.metaKey;
|
20976 | }
|
20977 |
|
20978 | |
20979 |
|
20980 |
|
20981 |
|
20982 |
|
20983 |
|
20984 | function isKey(keys, event) {
|
20985 | keys = isArray(keys) ? keys : [ keys ];
|
20986 |
|
20987 | return keys.indexOf(event.key) > -1;
|
20988 | }
|
20989 |
|
20990 | |
20991 |
|
20992 |
|
20993 | function isShift(event) {
|
20994 | return event.shiftKey;
|
20995 | }
|
20996 |
|
20997 | var KEYDOWN_EVENT = 'keyboard.keydown',
|
20998 | KEYUP_EVENT = 'keyboard.keyup';
|
20999 |
|
21000 | var DEFAULT_PRIORITY$1 = 1000;
|
21001 |
|
21002 |
|
21003 | |
21004 |
|
21005 |
|
21006 |
|
21007 |
|
21008 |
|
21009 |
|
21010 |
|
21011 |
|
21012 |
|
21013 |
|
21014 |
|
21015 |
|
21016 |
|
21017 |
|
21018 |
|
21019 |
|
21020 |
|
21021 |
|
21022 |
|
21023 |
|
21024 |
|
21025 |
|
21026 |
|
21027 | function Keyboard(config, eventBus) {
|
21028 | var self = this;
|
21029 |
|
21030 | this._config = config || {};
|
21031 | this._eventBus = eventBus;
|
21032 |
|
21033 | this._keydownHandler = this._keydownHandler.bind(this);
|
21034 | this._keyupHandler = this._keyupHandler.bind(this);
|
21035 |
|
21036 |
|
21037 | eventBus.on('diagram.destroy', function() {
|
21038 | self._fire('destroy');
|
21039 |
|
21040 | self.unbind();
|
21041 | });
|
21042 |
|
21043 | eventBus.on('diagram.init', function() {
|
21044 | self._fire('init');
|
21045 | });
|
21046 |
|
21047 | eventBus.on('attach', function() {
|
21048 | if (config && config.bindTo) {
|
21049 | self.bind(config.bindTo);
|
21050 | }
|
21051 | });
|
21052 |
|
21053 | eventBus.on('detach', function() {
|
21054 | self.unbind();
|
21055 | });
|
21056 | }
|
21057 |
|
21058 | Keyboard.$inject = [
|
21059 | 'config.keyboard',
|
21060 | 'eventBus'
|
21061 | ];
|
21062 |
|
21063 | Keyboard.prototype._keydownHandler = function(event) {
|
21064 | this._keyHandler(event, KEYDOWN_EVENT);
|
21065 | };
|
21066 |
|
21067 | Keyboard.prototype._keyupHandler = function(event) {
|
21068 | this._keyHandler(event, KEYUP_EVENT);
|
21069 | };
|
21070 |
|
21071 | Keyboard.prototype._keyHandler = function(event, type) {
|
21072 | var target = event.target,
|
21073 | eventBusResult;
|
21074 |
|
21075 | if (isInput(target)) {
|
21076 | return;
|
21077 | }
|
21078 |
|
21079 | var context = {
|
21080 | keyEvent: event
|
21081 | };
|
21082 |
|
21083 | eventBusResult = this._eventBus.fire(type || KEYDOWN_EVENT, context);
|
21084 |
|
21085 | if (eventBusResult) {
|
21086 | event.preventDefault();
|
21087 | }
|
21088 | };
|
21089 |
|
21090 | Keyboard.prototype.bind = function(node) {
|
21091 |
|
21092 |
|
21093 | this.unbind();
|
21094 |
|
21095 | this._node = node;
|
21096 |
|
21097 |
|
21098 | componentEvent.bind(node, 'keydown', this._keydownHandler, true);
|
21099 | componentEvent.bind(node, 'keyup', this._keyupHandler, true);
|
21100 |
|
21101 | this._fire('bind');
|
21102 | };
|
21103 |
|
21104 | Keyboard.prototype.getBinding = function() {
|
21105 | return this._node;
|
21106 | };
|
21107 |
|
21108 | Keyboard.prototype.unbind = function() {
|
21109 | var node = this._node;
|
21110 |
|
21111 | if (node) {
|
21112 | this._fire('unbind');
|
21113 |
|
21114 |
|
21115 | componentEvent.unbind(node, 'keydown', this._keydownHandler, true);
|
21116 | componentEvent.unbind(node, 'keyup', this._keyupHandler, true);
|
21117 | }
|
21118 |
|
21119 | this._node = null;
|
21120 | };
|
21121 |
|
21122 | Keyboard.prototype._fire = function(event) {
|
21123 | this._eventBus.fire('keyboard.' + event, { node: this._node });
|
21124 | };
|
21125 |
|
21126 | |
21127 |
|
21128 |
|
21129 |
|
21130 |
|
21131 |
|
21132 |
|
21133 |
|
21134 |
|
21135 | Keyboard.prototype.addListener = function(priority, listener, type) {
|
21136 | if (isFunction(priority)) {
|
21137 | type = listener;
|
21138 | listener = priority;
|
21139 | priority = DEFAULT_PRIORITY$1;
|
21140 | }
|
21141 |
|
21142 | this._eventBus.on(type || KEYDOWN_EVENT, priority, listener);
|
21143 | };
|
21144 |
|
21145 | Keyboard.prototype.removeListener = function(listener, type) {
|
21146 | this._eventBus.off(type || KEYDOWN_EVENT, listener);
|
21147 | };
|
21148 |
|
21149 | Keyboard.prototype.hasModifier = hasModifier;
|
21150 | Keyboard.prototype.isCmd = isCmd;
|
21151 | Keyboard.prototype.isShift = isShift;
|
21152 | Keyboard.prototype.isKey = isKey;
|
21153 |
|
21154 |
|
21155 |
|
21156 |
|
21157 |
|
21158 | function isInput(target) {
|
21159 | return target && (matchesSelector$1(target, 'input, textarea') || target.contentEditable === 'true');
|
21160 | }
|
21161 |
|
21162 | var LOW_PRIORITY$3 = 500;
|
21163 |
|
21164 |
|
21165 | |
21166 |
|
21167 |
|
21168 |
|
21169 |
|
21170 |
|
21171 |
|
21172 |
|
21173 |
|
21174 | function KeyboardBindings(eventBus, keyboard) {
|
21175 |
|
21176 | var self = this;
|
21177 |
|
21178 | eventBus.on('editorActions.init', LOW_PRIORITY$3, function(event) {
|
21179 |
|
21180 | var editorActions = event.editorActions;
|
21181 |
|
21182 | self.registerBindings(keyboard, editorActions);
|
21183 | });
|
21184 | }
|
21185 |
|
21186 | KeyboardBindings.$inject = [
|
21187 | 'eventBus',
|
21188 | 'keyboard'
|
21189 | ];
|
21190 |
|
21191 |
|
21192 | |
21193 |
|
21194 |
|
21195 |
|
21196 |
|
21197 |
|
21198 | KeyboardBindings.prototype.registerBindings = function(keyboard, editorActions) {
|
21199 |
|
21200 | |
21201 |
|
21202 |
|
21203 |
|
21204 |
|
21205 |
|
21206 |
|
21207 | function addListener(action, fn) {
|
21208 |
|
21209 | if (editorActions.isRegistered(action)) {
|
21210 | keyboard.addListener(fn);
|
21211 | }
|
21212 | }
|
21213 |
|
21214 |
|
21215 |
|
21216 |
|
21217 | addListener('undo', function(context) {
|
21218 |
|
21219 | var event = context.keyEvent;
|
21220 |
|
21221 | if (isCmd(event) && !isShift(event) && isKey(['z', 'Z'], event)) {
|
21222 | editorActions.trigger('undo');
|
21223 |
|
21224 | return true;
|
21225 | }
|
21226 | });
|
21227 |
|
21228 |
|
21229 |
|
21230 |
|
21231 | addListener('redo', function(context) {
|
21232 |
|
21233 | var event = context.keyEvent;
|
21234 |
|
21235 | if (isCmd(event) && (isKey(['y', 'Y'], event) || (isKey(['z', 'Z'], event) && isShift(event)))) {
|
21236 | editorActions.trigger('redo');
|
21237 |
|
21238 | return true;
|
21239 | }
|
21240 | });
|
21241 |
|
21242 |
|
21243 |
|
21244 | addListener('copy', function(context) {
|
21245 |
|
21246 | var event = context.keyEvent;
|
21247 |
|
21248 | if (isCmd(event) && isKey(['c', 'C'], event)) {
|
21249 | editorActions.trigger('copy');
|
21250 |
|
21251 | return true;
|
21252 | }
|
21253 | });
|
21254 |
|
21255 |
|
21256 |
|
21257 | addListener('paste', function(context) {
|
21258 |
|
21259 | var event = context.keyEvent;
|
21260 |
|
21261 | if (isCmd(event) && isKey(['v', 'V'], event)) {
|
21262 | editorActions.trigger('paste');
|
21263 |
|
21264 | return true;
|
21265 | }
|
21266 | });
|
21267 |
|
21268 |
|
21269 |
|
21270 | addListener('stepZoom', function(context) {
|
21271 |
|
21272 | var event = context.keyEvent;
|
21273 |
|
21274 | if (isKey([ '+', 'Add' ], event) && isCmd(event)) {
|
21275 | editorActions.trigger('stepZoom', { value: 1 });
|
21276 |
|
21277 | return true;
|
21278 | }
|
21279 | });
|
21280 |
|
21281 |
|
21282 |
|
21283 | addListener('stepZoom', function(context) {
|
21284 |
|
21285 | var event = context.keyEvent;
|
21286 |
|
21287 | if (isKey([ '-', 'Subtract' ], event) && isCmd(event)) {
|
21288 | editorActions.trigger('stepZoom', { value: -1 });
|
21289 |
|
21290 | return true;
|
21291 | }
|
21292 | });
|
21293 |
|
21294 |
|
21295 |
|
21296 | addListener('zoom', function(context) {
|
21297 |
|
21298 | var event = context.keyEvent;
|
21299 |
|
21300 | if (isKey('0', event) && isCmd(event)) {
|
21301 | editorActions.trigger('zoom', { value: 1 });
|
21302 |
|
21303 | return true;
|
21304 | }
|
21305 | });
|
21306 |
|
21307 |
|
21308 |
|
21309 | addListener('removeSelection', function(context) {
|
21310 |
|
21311 | var event = context.keyEvent;
|
21312 |
|
21313 | if (isKey([ 'Delete', 'Del' ], event)) {
|
21314 | editorActions.trigger('removeSelection');
|
21315 |
|
21316 | return true;
|
21317 | }
|
21318 | });
|
21319 | };
|
21320 |
|
21321 | var KeyboardModule = {
|
21322 | __init__: [ 'keyboard', 'keyboardBindings' ],
|
21323 | keyboard: [ 'type', Keyboard ],
|
21324 | keyboardBindings: [ 'type', KeyboardBindings ]
|
21325 | };
|
21326 |
|
21327 | var DEFAULT_CONFIG = {
|
21328 | moveSpeed: 50,
|
21329 | moveSpeedAccelerated: 200
|
21330 | };
|
21331 |
|
21332 |
|
21333 | |
21334 |
|
21335 |
|
21336 |
|
21337 |
|
21338 |
|
21339 |
|
21340 |
|
21341 |
|
21342 | function KeyboardMove(
|
21343 | config,
|
21344 | keyboard,
|
21345 | canvas
|
21346 | ) {
|
21347 |
|
21348 | var self = this;
|
21349 |
|
21350 | this._config = assign({}, DEFAULT_CONFIG, config || {});
|
21351 |
|
21352 | keyboard.addListener(arrowsListener);
|
21353 |
|
21354 |
|
21355 | function arrowsListener(context) {
|
21356 |
|
21357 | var event = context.keyEvent,
|
21358 | config = self._config;
|
21359 |
|
21360 | if (!keyboard.isCmd(event)) {
|
21361 | return;
|
21362 | }
|
21363 |
|
21364 | if (keyboard.isKey([
|
21365 | 'ArrowLeft', 'Left',
|
21366 | 'ArrowUp', 'Up',
|
21367 | 'ArrowDown', 'Down',
|
21368 | 'ArrowRight', 'Right'
|
21369 | ], event)) {
|
21370 |
|
21371 | var speed = (
|
21372 | keyboard.isShift(event) ?
|
21373 | config.moveSpeedAccelerated :
|
21374 | config.moveSpeed
|
21375 | );
|
21376 |
|
21377 | var direction;
|
21378 |
|
21379 | switch (event.key) {
|
21380 | case 'ArrowLeft':
|
21381 | case 'Left':
|
21382 | direction = 'left';
|
21383 | break;
|
21384 | case 'ArrowUp':
|
21385 | case 'Up':
|
21386 | direction = 'up';
|
21387 | break;
|
21388 | case 'ArrowRight':
|
21389 | case 'Right':
|
21390 | direction = 'right';
|
21391 | break;
|
21392 | case 'ArrowDown':
|
21393 | case 'Down':
|
21394 | direction = 'down';
|
21395 | break;
|
21396 | }
|
21397 |
|
21398 | self.moveCanvas({
|
21399 | speed: speed,
|
21400 | direction: direction
|
21401 | });
|
21402 |
|
21403 | return true;
|
21404 | }
|
21405 | }
|
21406 |
|
21407 | this.moveCanvas = function(opts) {
|
21408 |
|
21409 | var dx = 0,
|
21410 | dy = 0,
|
21411 | speed = opts.speed;
|
21412 |
|
21413 | var actualSpeed = speed / Math.min(Math.sqrt(canvas.viewbox().scale), 1);
|
21414 |
|
21415 | switch (opts.direction) {
|
21416 | case 'left':
|
21417 | dx = actualSpeed;
|
21418 | break;
|
21419 | case 'up':
|
21420 | dy = actualSpeed;
|
21421 | break;
|
21422 | case 'right':
|
21423 | dx = -actualSpeed;
|
21424 | break;
|
21425 | case 'down':
|
21426 | dy = -actualSpeed;
|
21427 | break;
|
21428 | }
|
21429 |
|
21430 | canvas.scroll({
|
21431 | dx: dx,
|
21432 | dy: dy
|
21433 | });
|
21434 | };
|
21435 |
|
21436 | }
|
21437 |
|
21438 |
|
21439 | KeyboardMove.$inject = [
|
21440 | 'config.keyboardMove',
|
21441 | 'keyboard',
|
21442 | 'canvas'
|
21443 | ];
|
21444 |
|
21445 | var KeyboardMoveModule = {
|
21446 | __depends__: [
|
21447 | KeyboardModule
|
21448 | ],
|
21449 | __init__: [ 'keyboardMove' ],
|
21450 | keyboardMove: [ 'type', KeyboardMove ]
|
21451 | };
|
21452 |
|
21453 | var CURSOR_CLS_PATTERN = /^djs-cursor-.*$/;
|
21454 |
|
21455 |
|
21456 | function set$1(mode) {
|
21457 | var classes$1 = classes(document.body);
|
21458 |
|
21459 | classes$1.removeMatching(CURSOR_CLS_PATTERN);
|
21460 |
|
21461 | if (mode) {
|
21462 | classes$1.add('djs-cursor-' + mode);
|
21463 | }
|
21464 | }
|
21465 |
|
21466 | function unset() {
|
21467 | set$1(null);
|
21468 | }
|
21469 |
|
21470 | var TRAP_PRIORITY = 5000;
|
21471 |
|
21472 | /**
|
21473 | * Installs a click trap that prevents a ghost click following a dragging operation.
|
21474 | *
|
21475 | * @return {Function} a function to immediately remove the installed trap.
|
21476 | */
|
21477 | function install(eventBus, eventName) {
|
21478 |
|
21479 | eventName = eventName || 'element.click';
|
21480 |
|
21481 | function trap() {
|
21482 | return false;
|
21483 | }
|
21484 |
|
21485 | eventBus.once(eventName, TRAP_PRIORITY, trap);
|
21486 |
|
21487 | return function() {
|
21488 | eventBus.off(eventName, trap);
|
21489 | };
|
21490 | }
|
21491 |
|
21492 | function center(bounds) {
|
21493 | return {
|
21494 | x: bounds.x + (bounds.width / 2),
|
21495 | y: bounds.y + (bounds.height / 2)
|
21496 | };
|
21497 | }
|
21498 |
|
21499 |
|
21500 | function delta(a, b) {
|
21501 | return {
|
21502 | x: a.x - b.x,
|
21503 | y: a.y - b.y
|
21504 | };
|
21505 | }
|
21506 |
|
21507 | var THRESHOLD = 15;
|
21508 |
|
21509 |
|
21510 | |
21511 |
|
21512 |
|
21513 |
|
21514 |
|
21515 |
|
21516 | function MoveCanvas(eventBus, canvas) {
|
21517 |
|
21518 | var context;
|
21519 |
|
21520 |
|
21521 |
|
21522 |
|
21523 |
|
21524 | eventBus.on('element.mousedown', 500, function(e) {
|
21525 | return handleStart(e.originalEvent);
|
21526 | });
|
21527 |
|
21528 |
|
21529 | function handleMove(event) {
|
21530 |
|
21531 | var start = context.start,
|
21532 | position = toPoint(event),
|
21533 | delta$1 = delta(position, start);
|
21534 |
|
21535 | if (!context.dragging && length(delta$1) > THRESHOLD) {
|
21536 | context.dragging = true;
|
21537 |
|
21538 | install(eventBus);
|
21539 |
|
21540 | set$1('grab');
|
21541 | }
|
21542 |
|
21543 | if (context.dragging) {
|
21544 |
|
21545 | var lastPosition = context.last || context.start;
|
21546 |
|
21547 | delta$1 = delta(position, lastPosition);
|
21548 |
|
21549 | canvas.scroll({
|
21550 | dx: delta$1.x,
|
21551 | dy: delta$1.y
|
21552 | });
|
21553 |
|
21554 | context.last = position;
|
21555 | }
|
21556 |
|
21557 |
|
21558 | event.preventDefault();
|
21559 | }
|
21560 |
|
21561 |
|
21562 | function handleEnd(event) {
|
21563 | componentEvent.unbind(document, 'mousemove', handleMove);
|
21564 | componentEvent.unbind(document, 'mouseup', handleEnd);
|
21565 |
|
21566 | context = null;
|
21567 |
|
21568 | unset();
|
21569 | }
|
21570 |
|
21571 | function handleStart(event) {
|
21572 |
|
21573 |
|
21574 | if (closest(event.target, '.djs-draggable')) {
|
21575 | return;
|
21576 | }
|
21577 |
|
21578 |
|
21579 |
|
21580 | if (event.button || event.ctrlKey || event.shiftKey || event.altKey) {
|
21581 | return;
|
21582 | }
|
21583 |
|
21584 | context = {
|
21585 | start: toPoint(event)
|
21586 | };
|
21587 |
|
21588 | componentEvent.bind(document, 'mousemove', handleMove);
|
21589 | componentEvent.bind(document, 'mouseup', handleEnd);
|
21590 |
|
21591 |
|
21592 | return true;
|
21593 | }
|
21594 | }
|
21595 |
|
21596 |
|
21597 | MoveCanvas.$inject = [
|
21598 | 'eventBus',
|
21599 | 'canvas'
|
21600 | ];
|
21601 |
|
21602 |
|
21603 |
|
21604 |
|
21605 |
|
21606 | function length(point) {
|
21607 | return Math.sqrt(Math.pow(point.x, 2) + Math.pow(point.y, 2));
|
21608 | }
|
21609 |
|
21610 | var MoveCanvasModule = {
|
21611 | __init__: [ 'moveCanvas' ],
|
21612 | moveCanvas: [ 'type', MoveCanvas ]
|
21613 | };
|
21614 |
|
21615 | |
21616 |
|
21617 |
|
21618 |
|
21619 | function log10(x) {
|
21620 | return Math.log(x) / Math.log(10);
|
21621 | }
|
21622 |
|
21623 | |
21624 |
|
21625 |
|
21626 |
|
21627 |
|
21628 |
|
21629 |
|
21630 | function getStepSize(range, steps) {
|
21631 |
|
21632 | var minLinearRange = log10(range.min),
|
21633 | maxLinearRange = log10(range.max);
|
21634 |
|
21635 | var absoluteLinearRange = Math.abs(minLinearRange) + Math.abs(maxLinearRange);
|
21636 |
|
21637 | return absoluteLinearRange / steps;
|
21638 | }
|
21639 |
|
21640 | function cap(range, scale) {
|
21641 | return Math.max(range.min, Math.min(range.max, scale));
|
21642 | }
|
21643 |
|
21644 | var sign = Math.sign || function(n) {
|
21645 | return n >= 0 ? 1 : -1;
|
21646 | };
|
21647 |
|
21648 | var RANGE = { min: 0.2, max: 4 },
|
21649 | NUM_STEPS = 10;
|
21650 |
|
21651 | var DELTA_THRESHOLD = 0.1;
|
21652 |
|
21653 | var DEFAULT_SCALE = 0.75;
|
21654 |
|
21655 | |
21656 |
|
21657 |
|
21658 |
|
21659 |
|
21660 |
|
21661 |
|
21662 |
|
21663 |
|
21664 |
|
21665 |
|
21666 |
|
21667 |
|
21668 | function ZoomScroll(config, eventBus, canvas) {
|
21669 |
|
21670 | config = config || {};
|
21671 |
|
21672 | this._enabled = false;
|
21673 |
|
21674 | this._canvas = canvas;
|
21675 | this._container = canvas._container;
|
21676 |
|
21677 | this._handleWheel = bind(this._handleWheel, this);
|
21678 |
|
21679 | this._totalDelta = 0;
|
21680 | this._scale = config.scale || DEFAULT_SCALE;
|
21681 |
|
21682 | var self = this;
|
21683 |
|
21684 | eventBus.on('canvas.init', function(e) {
|
21685 | self._init(config.enabled !== false);
|
21686 | });
|
21687 | }
|
21688 |
|
21689 | ZoomScroll.$inject = [
|
21690 | 'config.zoomScroll',
|
21691 | 'eventBus',
|
21692 | 'canvas'
|
21693 | ];
|
21694 |
|
21695 | ZoomScroll.prototype.scroll = function scroll(delta) {
|
21696 | this._canvas.scroll(delta);
|
21697 | };
|
21698 |
|
21699 |
|
21700 | ZoomScroll.prototype.reset = function reset() {
|
21701 | this._canvas.zoom('fit-viewport');
|
21702 | };
|
21703 |
|
21704 | |
21705 |
|
21706 |
|
21707 |
|
21708 |
|
21709 |
|
21710 | ZoomScroll.prototype.zoom = function zoom(delta, position) {
|
21711 |
|
21712 |
|
21713 | var stepSize = getStepSize(RANGE, NUM_STEPS * 2);
|
21714 |
|
21715 |
|
21716 | this._totalDelta += delta;
|
21717 |
|
21718 | if (Math.abs(this._totalDelta) > DELTA_THRESHOLD) {
|
21719 | this._zoom(delta, position, stepSize);
|
21720 |
|
21721 |
|
21722 | this._totalDelta = 0;
|
21723 | }
|
21724 | };
|
21725 |
|
21726 |
|
21727 | ZoomScroll.prototype._handleWheel = function handleWheel(event) {
|
21728 |
|
21729 |
|
21730 | if (closest(event.target, '.djs-scrollable', true)) {
|
21731 | return;
|
21732 | }
|
21733 |
|
21734 | var element = this._container;
|
21735 |
|
21736 | event.preventDefault();
|
21737 |
|
21738 |
|
21739 |
|
21740 |
|
21741 | var isZoom = event.ctrlKey;
|
21742 |
|
21743 | var isHorizontalScroll = event.shiftKey;
|
21744 |
|
21745 | var factor = -1 * this._scale,
|
21746 | delta;
|
21747 |
|
21748 | if (isZoom) {
|
21749 | factor *= event.deltaMode === 0 ? 0.020 : 0.32;
|
21750 | } else {
|
21751 | factor *= event.deltaMode === 0 ? 1.0 : 16.0;
|
21752 | }
|
21753 |
|
21754 | if (isZoom) {
|
21755 | var elementRect = element.getBoundingClientRect();
|
21756 |
|
21757 | var offset = {
|
21758 | x: event.clientX - elementRect.left,
|
21759 | y: event.clientY - elementRect.top
|
21760 | };
|
21761 |
|
21762 | delta = (
|
21763 | Math.sqrt(
|
21764 | Math.pow(event.deltaY, 2) +
|
21765 | Math.pow(event.deltaX, 2)
|
21766 | ) * sign(event.deltaY) * factor
|
21767 | );
|
21768 |
|
21769 |
|
21770 | this.zoom(delta, offset);
|
21771 | } else {
|
21772 |
|
21773 | if (isHorizontalScroll) {
|
21774 | delta = {
|
21775 | dx: factor * event.deltaY,
|
21776 | dy: 0
|
21777 | };
|
21778 | } else {
|
21779 | delta = {
|
21780 | dx: factor * event.deltaX,
|
21781 | dy: factor * event.deltaY
|
21782 | };
|
21783 | }
|
21784 |
|
21785 | this.scroll(delta);
|
21786 | }
|
21787 | };
|
21788 |
|
21789 | |
21790 |
|
21791 |
|
21792 |
|
21793 |
|
21794 |
|
21795 | ZoomScroll.prototype.stepZoom = function stepZoom(delta, position) {
|
21796 |
|
21797 | var stepSize = getStepSize(RANGE, NUM_STEPS);
|
21798 |
|
21799 | this._zoom(delta, position, stepSize);
|
21800 | };
|
21801 |
|
21802 |
|
21803 | |
21804 |
|
21805 |
|
21806 |
|
21807 |
|
21808 |
|
21809 |
|
21810 | ZoomScroll.prototype._zoom = function(delta, position, stepSize) {
|
21811 | var canvas = this._canvas;
|
21812 |
|
21813 | var direction = delta > 0 ? 1 : -1;
|
21814 |
|
21815 | var currentLinearZoomLevel = log10(canvas.zoom());
|
21816 |
|
21817 |
|
21818 | var newLinearZoomLevel = Math.round(currentLinearZoomLevel / stepSize) * stepSize;
|
21819 |
|
21820 |
|
21821 | newLinearZoomLevel += stepSize * direction;
|
21822 |
|
21823 |
|
21824 |
|
21825 | var newLogZoomLevel = Math.pow(10, newLinearZoomLevel);
|
21826 |
|
21827 | canvas.zoom(cap(RANGE, newLogZoomLevel), position);
|
21828 | };
|
21829 |
|
21830 |
|
21831 | |
21832 |
|
21833 |
|
21834 |
|
21835 |
|
21836 | ZoomScroll.prototype.toggle = function toggle(newEnabled) {
|
21837 |
|
21838 | var element = this._container;
|
21839 | var handleWheel = this._handleWheel;
|
21840 |
|
21841 | var oldEnabled = this._enabled;
|
21842 |
|
21843 | if (typeof newEnabled === 'undefined') {
|
21844 | newEnabled = !oldEnabled;
|
21845 | }
|
21846 |
|
21847 |
|
21848 | if (oldEnabled !== newEnabled) {
|
21849 |
|
21850 |
|
21851 |
|
21852 | componentEvent[newEnabled ? 'bind' : 'unbind'](element, 'wheel', handleWheel, false);
|
21853 | }
|
21854 |
|
21855 | this._enabled = newEnabled;
|
21856 |
|
21857 | return newEnabled;
|
21858 | };
|
21859 |
|
21860 |
|
21861 | ZoomScroll.prototype._init = function(newEnabled) {
|
21862 | this.toggle(newEnabled);
|
21863 | };
|
21864 |
|
21865 | var ZoomScrollModule = {
|
21866 | __init__: [ 'zoomScroll' ],
|
21867 | zoomScroll: [ 'type', ZoomScroll ]
|
21868 | };
|
21869 |
|
21870 | |
21871 |
|
21872 |
|
21873 |
|
21874 |
|
21875 | function NavigatedViewer(options) {
|
21876 | Viewer.call(this, options);
|
21877 | }
|
21878 |
|
21879 | inherits_browser(NavigatedViewer, Viewer);
|
21880 |
|
21881 |
|
21882 | NavigatedViewer.prototype._navigationModules = [
|
21883 | KeyboardMoveModule,
|
21884 | MoveCanvasModule,
|
21885 | ZoomScrollModule
|
21886 | ];
|
21887 |
|
21888 | NavigatedViewer.prototype._modules = [].concat(
|
21889 | Viewer.prototype._modules,
|
21890 | NavigatedViewer.prototype._navigationModules
|
21891 | );
|
21892 |
|
21893 | var hammer = createCommonjsModule(function (module) {
|
21894 | |
21895 |
|
21896 |
|
21897 |
|
21898 |
|
21899 | (function(window, document, exportName, undefined$1) {
|
21900 |
|
21901 | var VENDOR_PREFIXES = ['', 'webkit', 'Moz', 'MS', 'ms', 'o'];
|
21902 | var TEST_ELEMENT = document.createElement('div');
|
21903 |
|
21904 | var TYPE_FUNCTION = 'function';
|
21905 |
|
21906 | var round = Math.round;
|
21907 | var abs = Math.abs;
|
21908 | var now = Date.now;
|
21909 |
|
21910 | |
21911 |
|
21912 |
|
21913 |
|
21914 |
|
21915 |
|
21916 |
|
21917 | function setTimeoutContext(fn, timeout, context) {
|
21918 | return setTimeout(bindFn(fn, context), timeout);
|
21919 | }
|
21920 |
|
21921 | |
21922 |
|
21923 |
|
21924 |
|
21925 |
|
21926 |
|
21927 |
|
21928 |
|
21929 |
|
21930 | function invokeArrayArg(arg, fn, context) {
|
21931 | if (Array.isArray(arg)) {
|
21932 | each(arg, context[fn], context);
|
21933 | return true;
|
21934 | }
|
21935 | return false;
|
21936 | }
|
21937 |
|
21938 | |
21939 |
|
21940 |
|
21941 |
|
21942 |
|
21943 |
|
21944 | function each(obj, iterator, context) {
|
21945 | var i;
|
21946 |
|
21947 | if (!obj) {
|
21948 | return;
|
21949 | }
|
21950 |
|
21951 | if (obj.forEach) {
|
21952 | obj.forEach(iterator, context);
|
21953 | } else if (obj.length !== undefined$1) {
|
21954 | i = 0;
|
21955 | while (i < obj.length) {
|
21956 | iterator.call(context, obj[i], i, obj);
|
21957 | i++;
|
21958 | }
|
21959 | } else {
|
21960 | for (i in obj) {
|
21961 | obj.hasOwnProperty(i) && iterator.call(context, obj[i], i, obj);
|
21962 | }
|
21963 | }
|
21964 | }
|
21965 |
|
21966 | |
21967 |
|
21968 |
|
21969 |
|
21970 |
|
21971 |
|
21972 |
|
21973 | function deprecate(method, name, message) {
|
21974 | var deprecationMessage = 'DEPRECATED METHOD: ' + name + '\n' + message + ' AT \n';
|
21975 | return function() {
|
21976 | var e = new Error('get-stack-trace');
|
21977 | var stack = e && e.stack ? e.stack.replace(/^[^\(]+?[\n$]/gm, '')
|
21978 | .replace(/^\s+at\s+/gm, '')
|
21979 | .replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@') : 'Unknown Stack Trace';
|
21980 |
|
21981 | var log = window.console && (window.console.warn || window.console.log);
|
21982 | if (log) {
|
21983 | log.call(window.console, deprecationMessage, stack);
|
21984 | }
|
21985 | return method.apply(this, arguments);
|
21986 | };
|
21987 | }
|
21988 |
|
21989 | |
21990 |
|
21991 |
|
21992 |
|
21993 |
|
21994 |
|
21995 |
|
21996 | var assign;
|
21997 | if (typeof Object.assign !== 'function') {
|
21998 | assign = function assign(target) {
|
21999 | if (target === undefined$1 || target === null) {
|
22000 | throw new TypeError('Cannot convert undefined or null to object');
|
22001 | }
|
22002 |
|
22003 | var output = Object(target);
|
22004 | for (var index = 1; index < arguments.length; index++) {
|
22005 | var source = arguments[index];
|
22006 | if (source !== undefined$1 && source !== null) {
|
22007 | for (var nextKey in source) {
|
22008 | if (source.hasOwnProperty(nextKey)) {
|
22009 | output[nextKey] = source[nextKey];
|
22010 | }
|
22011 | }
|
22012 | }
|
22013 | }
|
22014 | return output;
|
22015 | };
|
22016 | } else {
|
22017 | assign = Object.assign;
|
22018 | }
|
22019 |
|
22020 | |
22021 |
|
22022 |
|
22023 |
|
22024 |
|
22025 |
|
22026 |
|
22027 |
|
22028 | var extend = deprecate(function extend(dest, src, merge) {
|
22029 | var keys = Object.keys(src);
|
22030 | var i = 0;
|
22031 | while (i < keys.length) {
|
22032 | if (!merge || (merge && dest[keys[i]] === undefined$1)) {
|
22033 | dest[keys[i]] = src[keys[i]];
|
22034 | }
|
22035 | i++;
|
22036 | }
|
22037 | return dest;
|
22038 | }, 'extend', 'Use `assign`.');
|
22039 |
|
22040 | |
22041 |
|
22042 |
|
22043 |
|
22044 |
|
22045 |
|
22046 |
|
22047 | var merge = deprecate(function merge(dest, src) {
|
22048 | return extend(dest, src, true);
|
22049 | }, 'merge', 'Use `assign`.');
|
22050 |
|
22051 | |
22052 |
|
22053 |
|
22054 |
|
22055 |
|
22056 |
|
22057 | function inherit(child, base, properties) {
|
22058 | var baseP = base.prototype,
|
22059 | childP;
|
22060 |
|
22061 | childP = child.prototype = Object.create(baseP);
|
22062 | childP.constructor = child;
|
22063 | childP._super = baseP;
|
22064 |
|
22065 | if (properties) {
|
22066 | assign(childP, properties);
|
22067 | }
|
22068 | }
|
22069 |
|
22070 | |
22071 |
|
22072 |
|
22073 |
|
22074 |
|
22075 |
|
22076 | function bindFn(fn, context) {
|
22077 | return function boundFn() {
|
22078 | return fn.apply(context, arguments);
|
22079 | };
|
22080 | }
|
22081 |
|
22082 | |
22083 |
|
22084 |
|
22085 |
|
22086 |
|
22087 |
|
22088 |
|
22089 | function boolOrFn(val, args) {
|
22090 | if (typeof val == TYPE_FUNCTION) {
|
22091 | return val.apply(args ? args[0] || undefined$1 : undefined$1, args);
|
22092 | }
|
22093 | return val;
|
22094 | }
|
22095 |
|
22096 | |
22097 |
|
22098 |
|
22099 |
|
22100 |
|
22101 |
|
22102 | function ifUndefined(val1, val2) {
|
22103 | return (val1 === undefined$1) ? val2 : val1;
|
22104 | }
|
22105 |
|
22106 | |
22107 |
|
22108 |
|
22109 |
|
22110 |
|
22111 |
|
22112 | function addEventListeners(target, types, handler) {
|
22113 | each(splitStr(types), function(type) {
|
22114 | target.addEventListener(type, handler, false);
|
22115 | });
|
22116 | }
|
22117 |
|
22118 | |
22119 |
|
22120 |
|
22121 |
|
22122 |
|
22123 |
|
22124 | function removeEventListeners(target, types, handler) {
|
22125 | each(splitStr(types), function(type) {
|
22126 | target.removeEventListener(type, handler, false);
|
22127 | });
|
22128 | }
|
22129 |
|
22130 | |
22131 |
|
22132 |
|
22133 |
|
22134 |
|
22135 |
|
22136 |
|
22137 | function hasParent(node, parent) {
|
22138 | while (node) {
|
22139 | if (node == parent) {
|
22140 | return true;
|
22141 | }
|
22142 | node = node.parentNode;
|
22143 | }
|
22144 | return false;
|
22145 | }
|
22146 |
|
22147 | |
22148 |
|
22149 |
|
22150 |
|
22151 |
|
22152 |
|
22153 | function inStr(str, find) {
|
22154 | return str.indexOf(find) > -1;
|
22155 | }
|
22156 |
|
22157 | |
22158 |
|
22159 |
|
22160 |
|
22161 |
|
22162 | function splitStr(str) {
|
22163 | return str.trim().split(/\s+/g);
|
22164 | }
|
22165 |
|
22166 | |
22167 |
|
22168 |
|
22169 |
|
22170 |
|
22171 |
|
22172 |
|
22173 | function inArray(src, find, findByKey) {
|
22174 | if (src.indexOf && !findByKey) {
|
22175 | return src.indexOf(find);
|
22176 | } else {
|
22177 | var i = 0;
|
22178 | while (i < src.length) {
|
22179 | if ((findByKey && src[i][findByKey] == find) || (!findByKey && src[i] === find)) {
|
22180 | return i;
|
22181 | }
|
22182 | i++;
|
22183 | }
|
22184 | return -1;
|
22185 | }
|
22186 | }
|
22187 |
|
22188 | |
22189 |
|
22190 |
|
22191 |
|
22192 |
|
22193 | function toArray(obj) {
|
22194 | return Array.prototype.slice.call(obj, 0);
|
22195 | }
|
22196 |
|
22197 | |
22198 |
|
22199 |
|
22200 |
|
22201 |
|
22202 |
|
22203 |
|
22204 | function uniqueArray(src, key, sort) {
|
22205 | var results = [];
|
22206 | var values = [];
|
22207 | var i = 0;
|
22208 |
|
22209 | while (i < src.length) {
|
22210 | var val = key ? src[i][key] : src[i];
|
22211 | if (inArray(values, val) < 0) {
|
22212 | results.push(src[i]);
|
22213 | }
|
22214 | values[i] = val;
|
22215 | i++;
|
22216 | }
|
22217 |
|
22218 | if (sort) {
|
22219 | if (!key) {
|
22220 | results = results.sort();
|
22221 | } else {
|
22222 | results = results.sort(function sortUniqueArray(a, b) {
|
22223 | return a[key] > b[key];
|
22224 | });
|
22225 | }
|
22226 | }
|
22227 |
|
22228 | return results;
|
22229 | }
|
22230 |
|
22231 | |
22232 |
|
22233 |
|
22234 |
|
22235 |
|
22236 |
|
22237 | function prefixed(obj, property) {
|
22238 | var prefix, prop;
|
22239 | var camelProp = property[0].toUpperCase() + property.slice(1);
|
22240 |
|
22241 | var i = 0;
|
22242 | while (i < VENDOR_PREFIXES.length) {
|
22243 | prefix = VENDOR_PREFIXES[i];
|
22244 | prop = (prefix) ? prefix + camelProp : property;
|
22245 |
|
22246 | if (prop in obj) {
|
22247 | return prop;
|
22248 | }
|
22249 | i++;
|
22250 | }
|
22251 | return undefined$1;
|
22252 | }
|
22253 |
|
22254 | |
22255 |
|
22256 |
|
22257 |
|
22258 | var _uniqueId = 1;
|
22259 | function uniqueId() {
|
22260 | return _uniqueId++;
|
22261 | }
|
22262 |
|
22263 | |
22264 |
|
22265 |
|
22266 |
|
22267 |
|
22268 | function getWindowForElement(element) {
|
22269 | var doc = element.ownerDocument || element;
|
22270 | return (doc.defaultView || doc.parentWindow || window);
|
22271 | }
|
22272 |
|
22273 | var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
|
22274 |
|
22275 | var SUPPORT_TOUCH = ('ontouchstart' in window);
|
22276 | var SUPPORT_POINTER_EVENTS = prefixed(window, 'PointerEvent') !== undefined$1;
|
22277 | var SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent);
|
22278 |
|
22279 | var INPUT_TYPE_TOUCH = 'touch';
|
22280 | var INPUT_TYPE_PEN = 'pen';
|
22281 | var INPUT_TYPE_MOUSE = 'mouse';
|
22282 | var INPUT_TYPE_KINECT = 'kinect';
|
22283 |
|
22284 | var COMPUTE_INTERVAL = 25;
|
22285 |
|
22286 | var INPUT_START = 1;
|
22287 | var INPUT_MOVE = 2;
|
22288 | var INPUT_END = 4;
|
22289 | var INPUT_CANCEL = 8;
|
22290 |
|
22291 | var DIRECTION_NONE = 1;
|
22292 | var DIRECTION_LEFT = 2;
|
22293 | var DIRECTION_RIGHT = 4;
|
22294 | var DIRECTION_UP = 8;
|
22295 | var DIRECTION_DOWN = 16;
|
22296 |
|
22297 | var DIRECTION_HORIZONTAL = DIRECTION_LEFT | DIRECTION_RIGHT;
|
22298 | var DIRECTION_VERTICAL = DIRECTION_UP | DIRECTION_DOWN;
|
22299 | var DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL;
|
22300 |
|
22301 | var PROPS_XY = ['x', 'y'];
|
22302 | var PROPS_CLIENT_XY = ['clientX', 'clientY'];
|
22303 |
|
22304 | |
22305 |
|
22306 |
|
22307 |
|
22308 |
|
22309 |
|
22310 |
|
22311 | function Input(manager, callback) {
|
22312 | var self = this;
|
22313 | this.manager = manager;
|
22314 | this.callback = callback;
|
22315 | this.element = manager.element;
|
22316 | this.target = manager.options.inputTarget;
|
22317 |
|
22318 |
|
22319 |
|
22320 | this.domHandler = function(ev) {
|
22321 | if (boolOrFn(manager.options.enable, [manager])) {
|
22322 | self.handler(ev);
|
22323 | }
|
22324 | };
|
22325 |
|
22326 | this.init();
|
22327 |
|
22328 | }
|
22329 |
|
22330 | Input.prototype = {
|
22331 | |
22332 |
|
22333 |
|
22334 |
|
22335 | handler: function() { },
|
22336 |
|
22337 | |
22338 |
|
22339 |
|
22340 | init: function() {
|
22341 | this.evEl && addEventListeners(this.element, this.evEl, this.domHandler);
|
22342 | this.evTarget && addEventListeners(this.target, this.evTarget, this.domHandler);
|
22343 | this.evWin && addEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
|
22344 | },
|
22345 |
|
22346 | |
22347 |
|
22348 |
|
22349 | destroy: function() {
|
22350 | this.evEl && removeEventListeners(this.element, this.evEl, this.domHandler);
|
22351 | this.evTarget && removeEventListeners(this.target, this.evTarget, this.domHandler);
|
22352 | this.evWin && removeEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
|
22353 | }
|
22354 | };
|
22355 |
|
22356 | |
22357 |
|
22358 |
|
22359 |
|
22360 |
|
22361 |
|
22362 | function createInputInstance(manager) {
|
22363 | var Type;
|
22364 | var inputClass = manager.options.inputClass;
|
22365 |
|
22366 | if (inputClass) {
|
22367 | Type = inputClass;
|
22368 | } else if (SUPPORT_POINTER_EVENTS) {
|
22369 | Type = PointerEventInput;
|
22370 | } else if (SUPPORT_ONLY_TOUCH) {
|
22371 | Type = TouchInput;
|
22372 | } else if (!SUPPORT_TOUCH) {
|
22373 | Type = MouseInput;
|
22374 | } else {
|
22375 | Type = TouchMouseInput;
|
22376 | }
|
22377 | return new (Type)(manager, inputHandler);
|
22378 | }
|
22379 |
|
22380 | |
22381 |
|
22382 |
|
22383 |
|
22384 |
|
22385 |
|
22386 | function inputHandler(manager, eventType, input) {
|
22387 | var pointersLen = input.pointers.length;
|
22388 | var changedPointersLen = input.changedPointers.length;
|
22389 | var isFirst = (eventType & INPUT_START && (pointersLen - changedPointersLen === 0));
|
22390 | var isFinal = (eventType & (INPUT_END | INPUT_CANCEL) && (pointersLen - changedPointersLen === 0));
|
22391 |
|
22392 | input.isFirst = !!isFirst;
|
22393 | input.isFinal = !!isFinal;
|
22394 |
|
22395 | if (isFirst) {
|
22396 | manager.session = {};
|
22397 | }
|
22398 |
|
22399 |
|
22400 |
|
22401 | input.eventType = eventType;
|
22402 |
|
22403 |
|
22404 | computeInputData(manager, input);
|
22405 |
|
22406 |
|
22407 | manager.emit('hammer.input', input);
|
22408 |
|
22409 | manager.recognize(input);
|
22410 | manager.session.prevInput = input;
|
22411 | }
|
22412 |
|
22413 | |
22414 |
|
22415 |
|
22416 |
|
22417 |
|
22418 | function computeInputData(manager, input) {
|
22419 | var session = manager.session;
|
22420 | var pointers = input.pointers;
|
22421 | var pointersLength = pointers.length;
|
22422 |
|
22423 |
|
22424 | if (!session.firstInput) {
|
22425 | session.firstInput = simpleCloneInputData(input);
|
22426 | }
|
22427 |
|
22428 |
|
22429 | if (pointersLength > 1 && !session.firstMultiple) {
|
22430 | session.firstMultiple = simpleCloneInputData(input);
|
22431 | } else if (pointersLength === 1) {
|
22432 | session.firstMultiple = false;
|
22433 | }
|
22434 |
|
22435 | var firstInput = session.firstInput;
|
22436 | var firstMultiple = session.firstMultiple;
|
22437 | var offsetCenter = firstMultiple ? firstMultiple.center : firstInput.center;
|
22438 |
|
22439 | var center = input.center = getCenter(pointers);
|
22440 | input.timeStamp = now();
|
22441 | input.deltaTime = input.timeStamp - firstInput.timeStamp;
|
22442 |
|
22443 | input.angle = getAngle(offsetCenter, center);
|
22444 | input.distance = getDistance(offsetCenter, center);
|
22445 |
|
22446 | computeDeltaXY(session, input);
|
22447 | input.offsetDirection = getDirection(input.deltaX, input.deltaY);
|
22448 |
|
22449 | var overallVelocity = getVelocity(input.deltaTime, input.deltaX, input.deltaY);
|
22450 | input.overallVelocityX = overallVelocity.x;
|
22451 | input.overallVelocityY = overallVelocity.y;
|
22452 | input.overallVelocity = (abs(overallVelocity.x) > abs(overallVelocity.y)) ? overallVelocity.x : overallVelocity.y;
|
22453 |
|
22454 | input.scale = firstMultiple ? getScale(firstMultiple.pointers, pointers) : 1;
|
22455 | input.rotation = firstMultiple ? getRotation(firstMultiple.pointers, pointers) : 0;
|
22456 |
|
22457 | input.maxPointers = !session.prevInput ? input.pointers.length : ((input.pointers.length >
|
22458 | session.prevInput.maxPointers) ? input.pointers.length : session.prevInput.maxPointers);
|
22459 |
|
22460 | computeIntervalInputData(session, input);
|
22461 |
|
22462 |
|
22463 | var target = manager.element;
|
22464 | if (hasParent(input.srcEvent.target, target)) {
|
22465 | target = input.srcEvent.target;
|
22466 | }
|
22467 | input.target = target;
|
22468 | }
|
22469 |
|
22470 | function computeDeltaXY(session, input) {
|
22471 | var center = input.center;
|
22472 | var offset = session.offsetDelta || {};
|
22473 | var prevDelta = session.prevDelta || {};
|
22474 | var prevInput = session.prevInput || {};
|
22475 |
|
22476 | if (input.eventType === INPUT_START || prevInput.eventType === INPUT_END) {
|
22477 | prevDelta = session.prevDelta = {
|
22478 | x: prevInput.deltaX || 0,
|
22479 | y: prevInput.deltaY || 0
|
22480 | };
|
22481 |
|
22482 | offset = session.offsetDelta = {
|
22483 | x: center.x,
|
22484 | y: center.y
|
22485 | };
|
22486 | }
|
22487 |
|
22488 | input.deltaX = prevDelta.x + (center.x - offset.x);
|
22489 | input.deltaY = prevDelta.y + (center.y - offset.y);
|
22490 | }
|
22491 |
|
22492 | |
22493 |
|
22494 |
|
22495 |
|
22496 |
|
22497 | function computeIntervalInputData(session, input) {
|
22498 | var last = session.lastInterval || input,
|
22499 | deltaTime = input.timeStamp - last.timeStamp,
|
22500 | velocity, velocityX, velocityY, direction;
|
22501 |
|
22502 | if (input.eventType != INPUT_CANCEL && (deltaTime > COMPUTE_INTERVAL || last.velocity === undefined$1)) {
|
22503 | var deltaX = input.deltaX - last.deltaX;
|
22504 | var deltaY = input.deltaY - last.deltaY;
|
22505 |
|
22506 | var v = getVelocity(deltaTime, deltaX, deltaY);
|
22507 | velocityX = v.x;
|
22508 | velocityY = v.y;
|
22509 | velocity = (abs(v.x) > abs(v.y)) ? v.x : v.y;
|
22510 | direction = getDirection(deltaX, deltaY);
|
22511 |
|
22512 | session.lastInterval = input;
|
22513 | } else {
|
22514 |
|
22515 | velocity = last.velocity;
|
22516 | velocityX = last.velocityX;
|
22517 | velocityY = last.velocityY;
|
22518 | direction = last.direction;
|
22519 | }
|
22520 |
|
22521 | input.velocity = velocity;
|
22522 | input.velocityX = velocityX;
|
22523 | input.velocityY = velocityY;
|
22524 | input.direction = direction;
|
22525 | }
|
22526 |
|
22527 | |
22528 |
|
22529 |
|
22530 |
|
22531 |
|
22532 | function simpleCloneInputData(input) {
|
22533 |
|
22534 |
|
22535 | var pointers = [];
|
22536 | var i = 0;
|
22537 | while (i < input.pointers.length) {
|
22538 | pointers[i] = {
|
22539 | clientX: round(input.pointers[i].clientX),
|
22540 | clientY: round(input.pointers[i].clientY)
|
22541 | };
|
22542 | i++;
|
22543 | }
|
22544 |
|
22545 | return {
|
22546 | timeStamp: now(),
|
22547 | pointers: pointers,
|
22548 | center: getCenter(pointers),
|
22549 | deltaX: input.deltaX,
|
22550 | deltaY: input.deltaY
|
22551 | };
|
22552 | }
|
22553 |
|
22554 | |
22555 |
|
22556 |
|
22557 |
|
22558 |
|
22559 | function getCenter(pointers) {
|
22560 | var pointersLength = pointers.length;
|
22561 |
|
22562 |
|
22563 | if (pointersLength === 1) {
|
22564 | return {
|
22565 | x: round(pointers[0].clientX),
|
22566 | y: round(pointers[0].clientY)
|
22567 | };
|
22568 | }
|
22569 |
|
22570 | var x = 0, y = 0, i = 0;
|
22571 | while (i < pointersLength) {
|
22572 | x += pointers[i].clientX;
|
22573 | y += pointers[i].clientY;
|
22574 | i++;
|
22575 | }
|
22576 |
|
22577 | return {
|
22578 | x: round(x / pointersLength),
|
22579 | y: round(y / pointersLength)
|
22580 | };
|
22581 | }
|
22582 |
|
22583 | |
22584 |
|
22585 |
|
22586 |
|
22587 |
|
22588 |
|
22589 |
|
22590 | function getVelocity(deltaTime, x, y) {
|
22591 | return {
|
22592 | x: x / deltaTime || 0,
|
22593 | y: y / deltaTime || 0
|
22594 | };
|
22595 | }
|
22596 |
|
22597 | |
22598 |
|
22599 |
|
22600 |
|
22601 |
|
22602 |
|
22603 | function getDirection(x, y) {
|
22604 | if (x === y) {
|
22605 | return DIRECTION_NONE;
|
22606 | }
|
22607 |
|
22608 | if (abs(x) >= abs(y)) {
|
22609 | return x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
22610 | }
|
22611 | return y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
|
22612 | }
|
22613 |
|
22614 | |
22615 |
|
22616 |
|
22617 |
|
22618 |
|
22619 |
|
22620 |
|
22621 | function getDistance(p1, p2, props) {
|
22622 | if (!props) {
|
22623 | props = PROPS_XY;
|
22624 | }
|
22625 | var x = p2[props[0]] - p1[props[0]],
|
22626 | y = p2[props[1]] - p1[props[1]];
|
22627 |
|
22628 | return Math.sqrt((x * x) + (y * y));
|
22629 | }
|
22630 |
|
22631 | |
22632 |
|
22633 |
|
22634 |
|
22635 |
|
22636 |
|
22637 |
|
22638 | function getAngle(p1, p2, props) {
|
22639 | if (!props) {
|
22640 | props = PROPS_XY;
|
22641 | }
|
22642 | var x = p2[props[0]] - p1[props[0]],
|
22643 | y = p2[props[1]] - p1[props[1]];
|
22644 | return Math.atan2(y, x) * 180 / Math.PI;
|
22645 | }
|
22646 |
|
22647 | |
22648 |
|
22649 |
|
22650 |
|
22651 |
|
22652 |
|
22653 | function getRotation(start, end) {
|
22654 | return getAngle(end[1], end[0], PROPS_CLIENT_XY) + getAngle(start[1], start[0], PROPS_CLIENT_XY);
|
22655 | }
|
22656 |
|
22657 | |
22658 |
|
22659 |
|
22660 |
|
22661 |
|
22662 |
|
22663 |
|
22664 | function getScale(start, end) {
|
22665 | return getDistance(end[0], end[1], PROPS_CLIENT_XY) / getDistance(start[0], start[1], PROPS_CLIENT_XY);
|
22666 | }
|
22667 |
|
22668 | var MOUSE_INPUT_MAP = {
|
22669 | mousedown: INPUT_START,
|
22670 | mousemove: INPUT_MOVE,
|
22671 | mouseup: INPUT_END
|
22672 | };
|
22673 |
|
22674 | var MOUSE_ELEMENT_EVENTS = 'mousedown';
|
22675 | var MOUSE_WINDOW_EVENTS = 'mousemove mouseup';
|
22676 |
|
22677 | |
22678 |
|
22679 |
|
22680 |
|
22681 |
|
22682 | function MouseInput() {
|
22683 | this.evEl = MOUSE_ELEMENT_EVENTS;
|
22684 | this.evWin = MOUSE_WINDOW_EVENTS;
|
22685 |
|
22686 | this.pressed = false;
|
22687 |
|
22688 | Input.apply(this, arguments);
|
22689 | }
|
22690 |
|
22691 | inherit(MouseInput, Input, {
|
22692 | |
22693 |
|
22694 |
|
22695 |
|
22696 | handler: function MEhandler(ev) {
|
22697 | var eventType = MOUSE_INPUT_MAP[ev.type];
|
22698 |
|
22699 |
|
22700 | if (eventType & INPUT_START && ev.button === 0) {
|
22701 | this.pressed = true;
|
22702 | }
|
22703 |
|
22704 | if (eventType & INPUT_MOVE && ev.which !== 1) {
|
22705 | eventType = INPUT_END;
|
22706 | }
|
22707 |
|
22708 |
|
22709 | if (!this.pressed) {
|
22710 | return;
|
22711 | }
|
22712 |
|
22713 | if (eventType & INPUT_END) {
|
22714 | this.pressed = false;
|
22715 | }
|
22716 |
|
22717 | this.callback(this.manager, eventType, {
|
22718 | pointers: [ev],
|
22719 | changedPointers: [ev],
|
22720 | pointerType: INPUT_TYPE_MOUSE,
|
22721 | srcEvent: ev
|
22722 | });
|
22723 | }
|
22724 | });
|
22725 |
|
22726 | var POINTER_INPUT_MAP = {
|
22727 | pointerdown: INPUT_START,
|
22728 | pointermove: INPUT_MOVE,
|
22729 | pointerup: INPUT_END,
|
22730 | pointercancel: INPUT_CANCEL,
|
22731 | pointerout: INPUT_CANCEL
|
22732 | };
|
22733 |
|
22734 |
|
22735 | var IE10_POINTER_TYPE_ENUM = {
|
22736 | 2: INPUT_TYPE_TOUCH,
|
22737 | 3: INPUT_TYPE_PEN,
|
22738 | 4: INPUT_TYPE_MOUSE,
|
22739 | 5: INPUT_TYPE_KINECT
|
22740 | };
|
22741 |
|
22742 | var POINTER_ELEMENT_EVENTS = 'pointerdown';
|
22743 | var POINTER_WINDOW_EVENTS = 'pointermove pointerup pointercancel';
|
22744 |
|
22745 |
|
22746 | if (window.MSPointerEvent && !window.PointerEvent) {
|
22747 | POINTER_ELEMENT_EVENTS = 'MSPointerDown';
|
22748 | POINTER_WINDOW_EVENTS = 'MSPointerMove MSPointerUp MSPointerCancel';
|
22749 | }
|
22750 |
|
22751 | |
22752 |
|
22753 |
|
22754 |
|
22755 |
|
22756 | function PointerEventInput() {
|
22757 | this.evEl = POINTER_ELEMENT_EVENTS;
|
22758 | this.evWin = POINTER_WINDOW_EVENTS;
|
22759 |
|
22760 | Input.apply(this, arguments);
|
22761 |
|
22762 | this.store = (this.manager.session.pointerEvents = []);
|
22763 | }
|
22764 |
|
22765 | inherit(PointerEventInput, Input, {
|
22766 | |
22767 |
|
22768 |
|
22769 |
|
22770 | handler: function PEhandler(ev) {
|
22771 | var store = this.store;
|
22772 | var removePointer = false;
|
22773 |
|
22774 | var eventTypeNormalized = ev.type.toLowerCase().replace('ms', '');
|
22775 | var eventType = POINTER_INPUT_MAP[eventTypeNormalized];
|
22776 | var pointerType = IE10_POINTER_TYPE_ENUM[ev.pointerType] || ev.pointerType;
|
22777 |
|
22778 | var isTouch = (pointerType == INPUT_TYPE_TOUCH);
|
22779 |
|
22780 |
|
22781 | var storeIndex = inArray(store, ev.pointerId, 'pointerId');
|
22782 |
|
22783 |
|
22784 | if (eventType & INPUT_START && (ev.button === 0 || isTouch)) {
|
22785 | if (storeIndex < 0) {
|
22786 | store.push(ev);
|
22787 | storeIndex = store.length - 1;
|
22788 | }
|
22789 | } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
|
22790 | removePointer = true;
|
22791 | }
|
22792 |
|
22793 |
|
22794 | if (storeIndex < 0) {
|
22795 | return;
|
22796 | }
|
22797 |
|
22798 |
|
22799 | store[storeIndex] = ev;
|
22800 |
|
22801 | this.callback(this.manager, eventType, {
|
22802 | pointers: store,
|
22803 | changedPointers: [ev],
|
22804 | pointerType: pointerType,
|
22805 | srcEvent: ev
|
22806 | });
|
22807 |
|
22808 | if (removePointer) {
|
22809 |
|
22810 | store.splice(storeIndex, 1);
|
22811 | }
|
22812 | }
|
22813 | });
|
22814 |
|
22815 | var SINGLE_TOUCH_INPUT_MAP = {
|
22816 | touchstart: INPUT_START,
|
22817 | touchmove: INPUT_MOVE,
|
22818 | touchend: INPUT_END,
|
22819 | touchcancel: INPUT_CANCEL
|
22820 | };
|
22821 |
|
22822 | var SINGLE_TOUCH_TARGET_EVENTS = 'touchstart';
|
22823 | var SINGLE_TOUCH_WINDOW_EVENTS = 'touchstart touchmove touchend touchcancel';
|
22824 |
|
22825 | |
22826 |
|
22827 |
|
22828 |
|
22829 |
|
22830 | function SingleTouchInput() {
|
22831 | this.evTarget = SINGLE_TOUCH_TARGET_EVENTS;
|
22832 | this.evWin = SINGLE_TOUCH_WINDOW_EVENTS;
|
22833 | this.started = false;
|
22834 |
|
22835 | Input.apply(this, arguments);
|
22836 | }
|
22837 |
|
22838 | inherit(SingleTouchInput, Input, {
|
22839 | handler: function TEhandler(ev) {
|
22840 | var type = SINGLE_TOUCH_INPUT_MAP[ev.type];
|
22841 |
|
22842 |
|
22843 | if (type === INPUT_START) {
|
22844 | this.started = true;
|
22845 | }
|
22846 |
|
22847 | if (!this.started) {
|
22848 | return;
|
22849 | }
|
22850 |
|
22851 | var touches = normalizeSingleTouches.call(this, ev, type);
|
22852 |
|
22853 |
|
22854 | if (type & (INPUT_END | INPUT_CANCEL) && touches[0].length - touches[1].length === 0) {
|
22855 | this.started = false;
|
22856 | }
|
22857 |
|
22858 | this.callback(this.manager, type, {
|
22859 | pointers: touches[0],
|
22860 | changedPointers: touches[1],
|
22861 | pointerType: INPUT_TYPE_TOUCH,
|
22862 | srcEvent: ev
|
22863 | });
|
22864 | }
|
22865 | });
|
22866 |
|
22867 | |
22868 |
|
22869 |
|
22870 |
|
22871 |
|
22872 |
|
22873 | function normalizeSingleTouches(ev, type) {
|
22874 | var all = toArray(ev.touches);
|
22875 | var changed = toArray(ev.changedTouches);
|
22876 |
|
22877 | if (type & (INPUT_END | INPUT_CANCEL)) {
|
22878 | all = uniqueArray(all.concat(changed), 'identifier', true);
|
22879 | }
|
22880 |
|
22881 | return [all, changed];
|
22882 | }
|
22883 |
|
22884 | var TOUCH_INPUT_MAP = {
|
22885 | touchstart: INPUT_START,
|
22886 | touchmove: INPUT_MOVE,
|
22887 | touchend: INPUT_END,
|
22888 | touchcancel: INPUT_CANCEL
|
22889 | };
|
22890 |
|
22891 | var TOUCH_TARGET_EVENTS = 'touchstart touchmove touchend touchcancel';
|
22892 |
|
22893 | |
22894 |
|
22895 |
|
22896 |
|
22897 |
|
22898 | function TouchInput() {
|
22899 | this.evTarget = TOUCH_TARGET_EVENTS;
|
22900 | this.targetIds = {};
|
22901 |
|
22902 | Input.apply(this, arguments);
|
22903 | }
|
22904 |
|
22905 | inherit(TouchInput, Input, {
|
22906 | handler: function MTEhandler(ev) {
|
22907 | var type = TOUCH_INPUT_MAP[ev.type];
|
22908 | var touches = getTouches.call(this, ev, type);
|
22909 | if (!touches) {
|
22910 | return;
|
22911 | }
|
22912 |
|
22913 | this.callback(this.manager, type, {
|
22914 | pointers: touches[0],
|
22915 | changedPointers: touches[1],
|
22916 | pointerType: INPUT_TYPE_TOUCH,
|
22917 | srcEvent: ev
|
22918 | });
|
22919 | }
|
22920 | });
|
22921 |
|
22922 | |
22923 |
|
22924 |
|
22925 |
|
22926 |
|
22927 |
|
22928 | function getTouches(ev, type) {
|
22929 | var allTouches = toArray(ev.touches);
|
22930 | var targetIds = this.targetIds;
|
22931 |
|
22932 |
|
22933 | if (type & (INPUT_START | INPUT_MOVE) && allTouches.length === 1) {
|
22934 | targetIds[allTouches[0].identifier] = true;
|
22935 | return [allTouches, allTouches];
|
22936 | }
|
22937 |
|
22938 | var i,
|
22939 | targetTouches,
|
22940 | changedTouches = toArray(ev.changedTouches),
|
22941 | changedTargetTouches = [],
|
22942 | target = this.target;
|
22943 |
|
22944 |
|
22945 | targetTouches = allTouches.filter(function(touch) {
|
22946 | return hasParent(touch.target, target);
|
22947 | });
|
22948 |
|
22949 |
|
22950 | if (type === INPUT_START) {
|
22951 | i = 0;
|
22952 | while (i < targetTouches.length) {
|
22953 | targetIds[targetTouches[i].identifier] = true;
|
22954 | i++;
|
22955 | }
|
22956 | }
|
22957 |
|
22958 |
|
22959 | i = 0;
|
22960 | while (i < changedTouches.length) {
|
22961 | if (targetIds[changedTouches[i].identifier]) {
|
22962 | changedTargetTouches.push(changedTouches[i]);
|
22963 | }
|
22964 |
|
22965 |
|
22966 | if (type & (INPUT_END | INPUT_CANCEL)) {
|
22967 | delete targetIds[changedTouches[i].identifier];
|
22968 | }
|
22969 | i++;
|
22970 | }
|
22971 |
|
22972 | if (!changedTargetTouches.length) {
|
22973 | return;
|
22974 | }
|
22975 |
|
22976 | return [
|
22977 |
|
22978 | uniqueArray(targetTouches.concat(changedTargetTouches), 'identifier', true),
|
22979 | changedTargetTouches
|
22980 | ];
|
22981 | }
|
22982 |
|
22983 | |
22984 |
|
22985 |
|
22986 |
|
22987 |
|
22988 |
|
22989 |
|
22990 |
|
22991 |
|
22992 |
|
22993 | var DEDUP_TIMEOUT = 2500;
|
22994 | var DEDUP_DISTANCE = 25;
|
22995 |
|
22996 | function TouchMouseInput() {
|
22997 | Input.apply(this, arguments);
|
22998 |
|
22999 | var handler = bindFn(this.handler, this);
|
23000 | this.touch = new TouchInput(this.manager, handler);
|
23001 | this.mouse = new MouseInput(this.manager, handler);
|
23002 |
|
23003 | this.primaryTouch = null;
|
23004 | this.lastTouches = [];
|
23005 | }
|
23006 |
|
23007 | inherit(TouchMouseInput, Input, {
|
23008 | |
23009 |
|
23010 |
|
23011 |
|
23012 |
|
23013 |
|
23014 | handler: function TMEhandler(manager, inputEvent, inputData) {
|
23015 | var isTouch = (inputData.pointerType == INPUT_TYPE_TOUCH),
|
23016 | isMouse = (inputData.pointerType == INPUT_TYPE_MOUSE);
|
23017 |
|
23018 | if (isMouse && inputData.sourceCapabilities && inputData.sourceCapabilities.firesTouchEvents) {
|
23019 | return;
|
23020 | }
|
23021 |
|
23022 |
|
23023 | if (isTouch) {
|
23024 | recordTouches.call(this, inputEvent, inputData);
|
23025 | } else if (isMouse && isSyntheticEvent.call(this, inputData)) {
|
23026 | return;
|
23027 | }
|
23028 |
|
23029 | this.callback(manager, inputEvent, inputData);
|
23030 | },
|
23031 |
|
23032 | |
23033 |
|
23034 |
|
23035 | destroy: function destroy() {
|
23036 | this.touch.destroy();
|
23037 | this.mouse.destroy();
|
23038 | }
|
23039 | });
|
23040 |
|
23041 | function recordTouches(eventType, eventData) {
|
23042 | if (eventType & INPUT_START) {
|
23043 | this.primaryTouch = eventData.changedPointers[0].identifier;
|
23044 | setLastTouch.call(this, eventData);
|
23045 | } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
|
23046 | setLastTouch.call(this, eventData);
|
23047 | }
|
23048 | }
|
23049 |
|
23050 | function setLastTouch(eventData) {
|
23051 | var touch = eventData.changedPointers[0];
|
23052 |
|
23053 | if (touch.identifier === this.primaryTouch) {
|
23054 | var lastTouch = {x: touch.clientX, y: touch.clientY};
|
23055 | this.lastTouches.push(lastTouch);
|
23056 | var lts = this.lastTouches;
|
23057 | var removeLastTouch = function() {
|
23058 | var i = lts.indexOf(lastTouch);
|
23059 | if (i > -1) {
|
23060 | lts.splice(i, 1);
|
23061 | }
|
23062 | };
|
23063 | setTimeout(removeLastTouch, DEDUP_TIMEOUT);
|
23064 | }
|
23065 | }
|
23066 |
|
23067 | function isSyntheticEvent(eventData) {
|
23068 | var x = eventData.srcEvent.clientX, y = eventData.srcEvent.clientY;
|
23069 | for (var i = 0; i < this.lastTouches.length; i++) {
|
23070 | var t = this.lastTouches[i];
|
23071 | var dx = Math.abs(x - t.x), dy = Math.abs(y - t.y);
|
23072 | if (dx <= DEDUP_DISTANCE && dy <= DEDUP_DISTANCE) {
|
23073 | return true;
|
23074 | }
|
23075 | }
|
23076 | return false;
|
23077 | }
|
23078 |
|
23079 | var PREFIXED_TOUCH_ACTION = prefixed(TEST_ELEMENT.style, 'touchAction');
|
23080 | var NATIVE_TOUCH_ACTION = PREFIXED_TOUCH_ACTION !== undefined$1;
|
23081 |
|
23082 |
|
23083 | var TOUCH_ACTION_COMPUTE = 'compute';
|
23084 | var TOUCH_ACTION_AUTO = 'auto';
|
23085 | var TOUCH_ACTION_MANIPULATION = 'manipulation';
|
23086 | var TOUCH_ACTION_NONE = 'none';
|
23087 | var TOUCH_ACTION_PAN_X = 'pan-x';
|
23088 | var TOUCH_ACTION_PAN_Y = 'pan-y';
|
23089 | var TOUCH_ACTION_MAP = getTouchActionProps();
|
23090 |
|
23091 | |
23092 |
|
23093 |
|
23094 |
|
23095 |
|
23096 |
|
23097 |
|
23098 | function TouchAction(manager, value) {
|
23099 | this.manager = manager;
|
23100 | this.set(value);
|
23101 | }
|
23102 |
|
23103 | TouchAction.prototype = {
|
23104 | |
23105 |
|
23106 |
|
23107 |
|
23108 | set: function(value) {
|
23109 |
|
23110 | if (value == TOUCH_ACTION_COMPUTE) {
|
23111 | value = this.compute();
|
23112 | }
|
23113 |
|
23114 | if (NATIVE_TOUCH_ACTION && this.manager.element.style && TOUCH_ACTION_MAP[value]) {
|
23115 | this.manager.element.style[PREFIXED_TOUCH_ACTION] = value;
|
23116 | }
|
23117 | this.actions = value.toLowerCase().trim();
|
23118 | },
|
23119 |
|
23120 | |
23121 |
|
23122 |
|
23123 | update: function() {
|
23124 | this.set(this.manager.options.touchAction);
|
23125 | },
|
23126 |
|
23127 | |
23128 |
|
23129 |
|
23130 |
|
23131 | compute: function() {
|
23132 | var actions = [];
|
23133 | each(this.manager.recognizers, function(recognizer) {
|
23134 | if (boolOrFn(recognizer.options.enable, [recognizer])) {
|
23135 | actions = actions.concat(recognizer.getTouchAction());
|
23136 | }
|
23137 | });
|
23138 | return cleanTouchActions(actions.join(' '));
|
23139 | },
|
23140 |
|
23141 | |
23142 |
|
23143 |
|
23144 |
|
23145 | preventDefaults: function(input) {
|
23146 | var srcEvent = input.srcEvent;
|
23147 | var direction = input.offsetDirection;
|
23148 |
|
23149 |
|
23150 | if (this.manager.session.prevented) {
|
23151 | srcEvent.preventDefault();
|
23152 | return;
|
23153 | }
|
23154 |
|
23155 | var actions = this.actions;
|
23156 | var hasNone = inStr(actions, TOUCH_ACTION_NONE) && !TOUCH_ACTION_MAP[TOUCH_ACTION_NONE];
|
23157 | var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_Y];
|
23158 | var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_X];
|
23159 |
|
23160 | if (hasNone) {
|
23161 |
|
23162 |
|
23163 | var isTapPointer = input.pointers.length === 1;
|
23164 | var isTapMovement = input.distance < 2;
|
23165 | var isTapTouchTime = input.deltaTime < 250;
|
23166 |
|
23167 | if (isTapPointer && isTapMovement && isTapTouchTime) {
|
23168 | return;
|
23169 | }
|
23170 | }
|
23171 |
|
23172 | if (hasPanX && hasPanY) {
|
23173 |
|
23174 | return;
|
23175 | }
|
23176 |
|
23177 | if (hasNone ||
|
23178 | (hasPanY && direction & DIRECTION_HORIZONTAL) ||
|
23179 | (hasPanX && direction & DIRECTION_VERTICAL)) {
|
23180 | return this.preventSrc(srcEvent);
|
23181 | }
|
23182 | },
|
23183 |
|
23184 | |
23185 |
|
23186 |
|
23187 |
|
23188 | preventSrc: function(srcEvent) {
|
23189 | this.manager.session.prevented = true;
|
23190 | srcEvent.preventDefault();
|
23191 | }
|
23192 | };
|
23193 |
|
23194 | |
23195 |
|
23196 |
|
23197 |
|
23198 |
|
23199 | function cleanTouchActions(actions) {
|
23200 |
|
23201 | if (inStr(actions, TOUCH_ACTION_NONE)) {
|
23202 | return TOUCH_ACTION_NONE;
|
23203 | }
|
23204 |
|
23205 | var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
|
23206 | var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y);
|
23207 |
|
23208 |
|
23209 |
|
23210 |
|
23211 |
|
23212 | if (hasPanX && hasPanY) {
|
23213 | return TOUCH_ACTION_NONE;
|
23214 | }
|
23215 |
|
23216 |
|
23217 | if (hasPanX || hasPanY) {
|
23218 | return hasPanX ? TOUCH_ACTION_PAN_X : TOUCH_ACTION_PAN_Y;
|
23219 | }
|
23220 |
|
23221 |
|
23222 | if (inStr(actions, TOUCH_ACTION_MANIPULATION)) {
|
23223 | return TOUCH_ACTION_MANIPULATION;
|
23224 | }
|
23225 |
|
23226 | return TOUCH_ACTION_AUTO;
|
23227 | }
|
23228 |
|
23229 | function getTouchActionProps() {
|
23230 | if (!NATIVE_TOUCH_ACTION) {
|
23231 | return false;
|
23232 | }
|
23233 | var touchMap = {};
|
23234 | var cssSupports = window.CSS && window.CSS.supports;
|
23235 | ['auto', 'manipulation', 'pan-y', 'pan-x', 'pan-x pan-y', 'none'].forEach(function(val) {
|
23236 |
|
23237 |
|
23238 |
|
23239 | touchMap[val] = cssSupports ? window.CSS.supports('touch-action', val) : true;
|
23240 | });
|
23241 | return touchMap;
|
23242 | }
|
23243 |
|
23244 | |
23245 |
|
23246 |
|
23247 |
|
23248 |
|
23249 |
|
23250 |
|
23251 |
|
23252 |
|
23253 |
|
23254 |
|
23255 |
|
23256 |
|
23257 |
|
23258 |
|
23259 |
|
23260 |
|
23261 |
|
23262 |
|
23263 |
|
23264 |
|
23265 |
|
23266 |
|
23267 |
|
23268 |
|
23269 |
|
23270 |
|
23271 | var STATE_POSSIBLE = 1;
|
23272 | var STATE_BEGAN = 2;
|
23273 | var STATE_CHANGED = 4;
|
23274 | var STATE_ENDED = 8;
|
23275 | var STATE_RECOGNIZED = STATE_ENDED;
|
23276 | var STATE_CANCELLED = 16;
|
23277 | var STATE_FAILED = 32;
|
23278 |
|
23279 | |
23280 |
|
23281 |
|
23282 |
|
23283 |
|
23284 |
|
23285 | function Recognizer(options) {
|
23286 | this.options = assign({}, this.defaults, options || {});
|
23287 |
|
23288 | this.id = uniqueId();
|
23289 |
|
23290 | this.manager = null;
|
23291 |
|
23292 |
|
23293 | this.options.enable = ifUndefined(this.options.enable, true);
|
23294 |
|
23295 | this.state = STATE_POSSIBLE;
|
23296 |
|
23297 | this.simultaneous = {};
|
23298 | this.requireFail = [];
|
23299 | }
|
23300 |
|
23301 | Recognizer.prototype = {
|
23302 | |
23303 |
|
23304 |
|
23305 |
|
23306 | defaults: {},
|
23307 |
|
23308 | |
23309 |
|
23310 |
|
23311 |
|
23312 |
|
23313 | set: function(options) {
|
23314 | assign(this.options, options);
|
23315 |
|
23316 |
|
23317 | this.manager && this.manager.touchAction.update();
|
23318 | return this;
|
23319 | },
|
23320 |
|
23321 | |
23322 |
|
23323 |
|
23324 |
|
23325 |
|
23326 | recognizeWith: function(otherRecognizer) {
|
23327 | if (invokeArrayArg(otherRecognizer, 'recognizeWith', this)) {
|
23328 | return this;
|
23329 | }
|
23330 |
|
23331 | var simultaneous = this.simultaneous;
|
23332 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
23333 | if (!simultaneous[otherRecognizer.id]) {
|
23334 | simultaneous[otherRecognizer.id] = otherRecognizer;
|
23335 | otherRecognizer.recognizeWith(this);
|
23336 | }
|
23337 | return this;
|
23338 | },
|
23339 |
|
23340 | |
23341 |
|
23342 |
|
23343 |
|
23344 |
|
23345 | dropRecognizeWith: function(otherRecognizer) {
|
23346 | if (invokeArrayArg(otherRecognizer, 'dropRecognizeWith', this)) {
|
23347 | return this;
|
23348 | }
|
23349 |
|
23350 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
23351 | delete this.simultaneous[otherRecognizer.id];
|
23352 | return this;
|
23353 | },
|
23354 |
|
23355 | |
23356 |
|
23357 |
|
23358 |
|
23359 |
|
23360 | requireFailure: function(otherRecognizer) {
|
23361 | if (invokeArrayArg(otherRecognizer, 'requireFailure', this)) {
|
23362 | return this;
|
23363 | }
|
23364 |
|
23365 | var requireFail = this.requireFail;
|
23366 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
23367 | if (inArray(requireFail, otherRecognizer) === -1) {
|
23368 | requireFail.push(otherRecognizer);
|
23369 | otherRecognizer.requireFailure(this);
|
23370 | }
|
23371 | return this;
|
23372 | },
|
23373 |
|
23374 | |
23375 |
|
23376 |
|
23377 |
|
23378 |
|
23379 | dropRequireFailure: function(otherRecognizer) {
|
23380 | if (invokeArrayArg(otherRecognizer, 'dropRequireFailure', this)) {
|
23381 | return this;
|
23382 | }
|
23383 |
|
23384 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
23385 | var index = inArray(this.requireFail, otherRecognizer);
|
23386 | if (index > -1) {
|
23387 | this.requireFail.splice(index, 1);
|
23388 | }
|
23389 | return this;
|
23390 | },
|
23391 |
|
23392 | |
23393 |
|
23394 |
|
23395 |
|
23396 | hasRequireFailures: function() {
|
23397 | return this.requireFail.length > 0;
|
23398 | },
|
23399 |
|
23400 | |
23401 |
|
23402 |
|
23403 |
|
23404 |
|
23405 | canRecognizeWith: function(otherRecognizer) {
|
23406 | return !!this.simultaneous[otherRecognizer.id];
|
23407 | },
|
23408 |
|
23409 | |
23410 |
|
23411 |
|
23412 |
|
23413 |
|
23414 | emit: function(input) {
|
23415 | var self = this;
|
23416 | var state = this.state;
|
23417 |
|
23418 | function emit(event) {
|
23419 | self.manager.emit(event, input);
|
23420 | }
|
23421 |
|
23422 |
|
23423 | if (state < STATE_ENDED) {
|
23424 | emit(self.options.event + stateStr(state));
|
23425 | }
|
23426 |
|
23427 | emit(self.options.event);
|
23428 |
|
23429 | if (input.additionalEvent) {
|
23430 | emit(input.additionalEvent);
|
23431 | }
|
23432 |
|
23433 |
|
23434 | if (state >= STATE_ENDED) {
|
23435 | emit(self.options.event + stateStr(state));
|
23436 | }
|
23437 | },
|
23438 |
|
23439 | |
23440 |
|
23441 |
|
23442 |
|
23443 |
|
23444 |
|
23445 | tryEmit: function(input) {
|
23446 | if (this.canEmit()) {
|
23447 | return this.emit(input);
|
23448 | }
|
23449 |
|
23450 | this.state = STATE_FAILED;
|
23451 | },
|
23452 |
|
23453 | |
23454 |
|
23455 |
|
23456 |
|
23457 | canEmit: function() {
|
23458 | var i = 0;
|
23459 | while (i < this.requireFail.length) {
|
23460 | if (!(this.requireFail[i].state & (STATE_FAILED | STATE_POSSIBLE))) {
|
23461 | return false;
|
23462 | }
|
23463 | i++;
|
23464 | }
|
23465 | return true;
|
23466 | },
|
23467 |
|
23468 | |
23469 |
|
23470 |
|
23471 |
|
23472 | recognize: function(inputData) {
|
23473 |
|
23474 |
|
23475 | var inputDataClone = assign({}, inputData);
|
23476 |
|
23477 |
|
23478 | if (!boolOrFn(this.options.enable, [this, inputDataClone])) {
|
23479 | this.reset();
|
23480 | this.state = STATE_FAILED;
|
23481 | return;
|
23482 | }
|
23483 |
|
23484 |
|
23485 | if (this.state & (STATE_RECOGNIZED | STATE_CANCELLED | STATE_FAILED)) {
|
23486 | this.state = STATE_POSSIBLE;
|
23487 | }
|
23488 |
|
23489 | this.state = this.process(inputDataClone);
|
23490 |
|
23491 |
|
23492 |
|
23493 | if (this.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED | STATE_CANCELLED)) {
|
23494 | this.tryEmit(inputDataClone);
|
23495 | }
|
23496 | },
|
23497 |
|
23498 | |
23499 |
|
23500 |
|
23501 |
|
23502 |
|
23503 |
|
23504 |
|
23505 | process: function(inputData) { },
|
23506 |
|
23507 | |
23508 |
|
23509 |
|
23510 |
|
23511 |
|
23512 | getTouchAction: function() { },
|
23513 |
|
23514 | |
23515 |
|
23516 |
|
23517 |
|
23518 |
|
23519 | reset: function() { }
|
23520 | };
|
23521 |
|
23522 | |
23523 |
|
23524 |
|
23525 |
|
23526 |
|
23527 | function stateStr(state) {
|
23528 | if (state & STATE_CANCELLED) {
|
23529 | return 'cancel';
|
23530 | } else if (state & STATE_ENDED) {
|
23531 | return 'end';
|
23532 | } else if (state & STATE_CHANGED) {
|
23533 | return 'move';
|
23534 | } else if (state & STATE_BEGAN) {
|
23535 | return 'start';
|
23536 | }
|
23537 | return '';
|
23538 | }
|
23539 |
|
23540 | |
23541 |
|
23542 |
|
23543 |
|
23544 |
|
23545 | function directionStr(direction) {
|
23546 | if (direction == DIRECTION_DOWN) {
|
23547 | return 'down';
|
23548 | } else if (direction == DIRECTION_UP) {
|
23549 | return 'up';
|
23550 | } else if (direction == DIRECTION_LEFT) {
|
23551 | return 'left';
|
23552 | } else if (direction == DIRECTION_RIGHT) {
|
23553 | return 'right';
|
23554 | }
|
23555 | return '';
|
23556 | }
|
23557 |
|
23558 | |
23559 |
|
23560 |
|
23561 |
|
23562 |
|
23563 |
|
23564 | function getRecognizerByNameIfManager(otherRecognizer, recognizer) {
|
23565 | var manager = recognizer.manager;
|
23566 | if (manager) {
|
23567 | return manager.get(otherRecognizer);
|
23568 | }
|
23569 | return otherRecognizer;
|
23570 | }
|
23571 |
|
23572 | |
23573 |
|
23574 |
|
23575 |
|
23576 |
|
23577 | function AttrRecognizer() {
|
23578 | Recognizer.apply(this, arguments);
|
23579 | }
|
23580 |
|
23581 | inherit(AttrRecognizer, Recognizer, {
|
23582 | |
23583 |
|
23584 |
|
23585 |
|
23586 | defaults: {
|
23587 | |
23588 |
|
23589 |
|
23590 |
|
23591 | pointers: 1
|
23592 | },
|
23593 |
|
23594 | |
23595 |
|
23596 |
|
23597 |
|
23598 |
|
23599 |
|
23600 | attrTest: function(input) {
|
23601 | var optionPointers = this.options.pointers;
|
23602 | return optionPointers === 0 || input.pointers.length === optionPointers;
|
23603 | },
|
23604 |
|
23605 | |
23606 |
|
23607 |
|
23608 |
|
23609 |
|
23610 |
|
23611 | process: function(input) {
|
23612 | var state = this.state;
|
23613 | var eventType = input.eventType;
|
23614 |
|
23615 | var isRecognized = state & (STATE_BEGAN | STATE_CHANGED);
|
23616 | var isValid = this.attrTest(input);
|
23617 |
|
23618 |
|
23619 | if (isRecognized && (eventType & INPUT_CANCEL || !isValid)) {
|
23620 | return state | STATE_CANCELLED;
|
23621 | } else if (isRecognized || isValid) {
|
23622 | if (eventType & INPUT_END) {
|
23623 | return state | STATE_ENDED;
|
23624 | } else if (!(state & STATE_BEGAN)) {
|
23625 | return STATE_BEGAN;
|
23626 | }
|
23627 | return state | STATE_CHANGED;
|
23628 | }
|
23629 | return STATE_FAILED;
|
23630 | }
|
23631 | });
|
23632 |
|
23633 | |
23634 |
|
23635 |
|
23636 |
|
23637 |
|
23638 |
|
23639 | function PanRecognizer() {
|
23640 | AttrRecognizer.apply(this, arguments);
|
23641 |
|
23642 | this.pX = null;
|
23643 | this.pY = null;
|
23644 | }
|
23645 |
|
23646 | inherit(PanRecognizer, AttrRecognizer, {
|
23647 | |
23648 |
|
23649 |
|
23650 |
|
23651 | defaults: {
|
23652 | event: 'pan',
|
23653 | threshold: 10,
|
23654 | pointers: 1,
|
23655 | direction: DIRECTION_ALL
|
23656 | },
|
23657 |
|
23658 | getTouchAction: function() {
|
23659 | var direction = this.options.direction;
|
23660 | var actions = [];
|
23661 | if (direction & DIRECTION_HORIZONTAL) {
|
23662 | actions.push(TOUCH_ACTION_PAN_Y);
|
23663 | }
|
23664 | if (direction & DIRECTION_VERTICAL) {
|
23665 | actions.push(TOUCH_ACTION_PAN_X);
|
23666 | }
|
23667 | return actions;
|
23668 | },
|
23669 |
|
23670 | directionTest: function(input) {
|
23671 | var options = this.options;
|
23672 | var hasMoved = true;
|
23673 | var distance = input.distance;
|
23674 | var direction = input.direction;
|
23675 | var x = input.deltaX;
|
23676 | var y = input.deltaY;
|
23677 |
|
23678 |
|
23679 | if (!(direction & options.direction)) {
|
23680 | if (options.direction & DIRECTION_HORIZONTAL) {
|
23681 | direction = (x === 0) ? DIRECTION_NONE : (x < 0) ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
23682 | hasMoved = x != this.pX;
|
23683 | distance = Math.abs(input.deltaX);
|
23684 | } else {
|
23685 | direction = (y === 0) ? DIRECTION_NONE : (y < 0) ? DIRECTION_UP : DIRECTION_DOWN;
|
23686 | hasMoved = y != this.pY;
|
23687 | distance = Math.abs(input.deltaY);
|
23688 | }
|
23689 | }
|
23690 | input.direction = direction;
|
23691 | return hasMoved && distance > options.threshold && direction & options.direction;
|
23692 | },
|
23693 |
|
23694 | attrTest: function(input) {
|
23695 | return AttrRecognizer.prototype.attrTest.call(this, input) &&
|
23696 | (this.state & STATE_BEGAN || (!(this.state & STATE_BEGAN) && this.directionTest(input)));
|
23697 | },
|
23698 |
|
23699 | emit: function(input) {
|
23700 |
|
23701 | this.pX = input.deltaX;
|
23702 | this.pY = input.deltaY;
|
23703 |
|
23704 | var direction = directionStr(input.direction);
|
23705 |
|
23706 | if (direction) {
|
23707 | input.additionalEvent = this.options.event + direction;
|
23708 | }
|
23709 | this._super.emit.call(this, input);
|
23710 | }
|
23711 | });
|
23712 |
|
23713 | |
23714 |
|
23715 |
|
23716 |
|
23717 |
|
23718 |
|
23719 | function PinchRecognizer() {
|
23720 | AttrRecognizer.apply(this, arguments);
|
23721 | }
|
23722 |
|
23723 | inherit(PinchRecognizer, AttrRecognizer, {
|
23724 | |
23725 |
|
23726 |
|
23727 |
|
23728 | defaults: {
|
23729 | event: 'pinch',
|
23730 | threshold: 0,
|
23731 | pointers: 2
|
23732 | },
|
23733 |
|
23734 | getTouchAction: function() {
|
23735 | return [TOUCH_ACTION_NONE];
|
23736 | },
|
23737 |
|
23738 | attrTest: function(input) {
|
23739 | return this._super.attrTest.call(this, input) &&
|
23740 | (Math.abs(input.scale - 1) > this.options.threshold || this.state & STATE_BEGAN);
|
23741 | },
|
23742 |
|
23743 | emit: function(input) {
|
23744 | if (input.scale !== 1) {
|
23745 | var inOut = input.scale < 1 ? 'in' : 'out';
|
23746 | input.additionalEvent = this.options.event + inOut;
|
23747 | }
|
23748 | this._super.emit.call(this, input);
|
23749 | }
|
23750 | });
|
23751 |
|
23752 | |
23753 |
|
23754 |
|
23755 |
|
23756 |
|
23757 |
|
23758 | function PressRecognizer() {
|
23759 | Recognizer.apply(this, arguments);
|
23760 |
|
23761 | this._timer = null;
|
23762 | this._input = null;
|
23763 | }
|
23764 |
|
23765 | inherit(PressRecognizer, Recognizer, {
|
23766 | |
23767 |
|
23768 |
|
23769 |
|
23770 | defaults: {
|
23771 | event: 'press',
|
23772 | pointers: 1,
|
23773 | time: 251,
|
23774 | threshold: 9
|
23775 | },
|
23776 |
|
23777 | getTouchAction: function() {
|
23778 | return [TOUCH_ACTION_AUTO];
|
23779 | },
|
23780 |
|
23781 | process: function(input) {
|
23782 | var options = this.options;
|
23783 | var validPointers = input.pointers.length === options.pointers;
|
23784 | var validMovement = input.distance < options.threshold;
|
23785 | var validTime = input.deltaTime > options.time;
|
23786 |
|
23787 | this._input = input;
|
23788 |
|
23789 |
|
23790 |
|
23791 | if (!validMovement || !validPointers || (input.eventType & (INPUT_END | INPUT_CANCEL) && !validTime)) {
|
23792 | this.reset();
|
23793 | } else if (input.eventType & INPUT_START) {
|
23794 | this.reset();
|
23795 | this._timer = setTimeoutContext(function() {
|
23796 | this.state = STATE_RECOGNIZED;
|
23797 | this.tryEmit();
|
23798 | }, options.time, this);
|
23799 | } else if (input.eventType & INPUT_END) {
|
23800 | return STATE_RECOGNIZED;
|
23801 | }
|
23802 | return STATE_FAILED;
|
23803 | },
|
23804 |
|
23805 | reset: function() {
|
23806 | clearTimeout(this._timer);
|
23807 | },
|
23808 |
|
23809 | emit: function(input) {
|
23810 | if (this.state !== STATE_RECOGNIZED) {
|
23811 | return;
|
23812 | }
|
23813 |
|
23814 | if (input && (input.eventType & INPUT_END)) {
|
23815 | this.manager.emit(this.options.event + 'up', input);
|
23816 | } else {
|
23817 | this._input.timeStamp = now();
|
23818 | this.manager.emit(this.options.event, this._input);
|
23819 | }
|
23820 | }
|
23821 | });
|
23822 |
|
23823 | |
23824 |
|
23825 |
|
23826 |
|
23827 |
|
23828 |
|
23829 | function RotateRecognizer() {
|
23830 | AttrRecognizer.apply(this, arguments);
|
23831 | }
|
23832 |
|
23833 | inherit(RotateRecognizer, AttrRecognizer, {
|
23834 | |
23835 |
|
23836 |
|
23837 |
|
23838 | defaults: {
|
23839 | event: 'rotate',
|
23840 | threshold: 0,
|
23841 | pointers: 2
|
23842 | },
|
23843 |
|
23844 | getTouchAction: function() {
|
23845 | return [TOUCH_ACTION_NONE];
|
23846 | },
|
23847 |
|
23848 | attrTest: function(input) {
|
23849 | return this._super.attrTest.call(this, input) &&
|
23850 | (Math.abs(input.rotation) > this.options.threshold || this.state & STATE_BEGAN);
|
23851 | }
|
23852 | });
|
23853 |
|
23854 | |
23855 |
|
23856 |
|
23857 |
|
23858 |
|
23859 |
|
23860 | function SwipeRecognizer() {
|
23861 | AttrRecognizer.apply(this, arguments);
|
23862 | }
|
23863 |
|
23864 | inherit(SwipeRecognizer, AttrRecognizer, {
|
23865 | |
23866 |
|
23867 |
|
23868 |
|
23869 | defaults: {
|
23870 | event: 'swipe',
|
23871 | threshold: 10,
|
23872 | velocity: 0.3,
|
23873 | direction: DIRECTION_HORIZONTAL | DIRECTION_VERTICAL,
|
23874 | pointers: 1
|
23875 | },
|
23876 |
|
23877 | getTouchAction: function() {
|
23878 | return PanRecognizer.prototype.getTouchAction.call(this);
|
23879 | },
|
23880 |
|
23881 | attrTest: function(input) {
|
23882 | var direction = this.options.direction;
|
23883 | var velocity;
|
23884 |
|
23885 | if (direction & (DIRECTION_HORIZONTAL | DIRECTION_VERTICAL)) {
|
23886 | velocity = input.overallVelocity;
|
23887 | } else if (direction & DIRECTION_HORIZONTAL) {
|
23888 | velocity = input.overallVelocityX;
|
23889 | } else if (direction & DIRECTION_VERTICAL) {
|
23890 | velocity = input.overallVelocityY;
|
23891 | }
|
23892 |
|
23893 | return this._super.attrTest.call(this, input) &&
|
23894 | direction & input.offsetDirection &&
|
23895 | input.distance > this.options.threshold &&
|
23896 | input.maxPointers == this.options.pointers &&
|
23897 | abs(velocity) > this.options.velocity && input.eventType & INPUT_END;
|
23898 | },
|
23899 |
|
23900 | emit: function(input) {
|
23901 | var direction = directionStr(input.offsetDirection);
|
23902 | if (direction) {
|
23903 | this.manager.emit(this.options.event + direction, input);
|
23904 | }
|
23905 |
|
23906 | this.manager.emit(this.options.event, input);
|
23907 | }
|
23908 | });
|
23909 |
|
23910 | |
23911 |
|
23912 |
|
23913 |
|
23914 |
|
23915 |
|
23916 |
|
23917 |
|
23918 |
|
23919 |
|
23920 | function TapRecognizer() {
|
23921 | Recognizer.apply(this, arguments);
|
23922 |
|
23923 |
|
23924 |
|
23925 | this.pTime = false;
|
23926 | this.pCenter = false;
|
23927 |
|
23928 | this._timer = null;
|
23929 | this._input = null;
|
23930 | this.count = 0;
|
23931 | }
|
23932 |
|
23933 | inherit(TapRecognizer, Recognizer, {
|
23934 | |
23935 |
|
23936 |
|
23937 |
|
23938 | defaults: {
|
23939 | event: 'tap',
|
23940 | pointers: 1,
|
23941 | taps: 1,
|
23942 | interval: 300,
|
23943 | time: 250,
|
23944 | threshold: 9,
|
23945 | posThreshold: 10
|
23946 | },
|
23947 |
|
23948 | getTouchAction: function() {
|
23949 | return [TOUCH_ACTION_MANIPULATION];
|
23950 | },
|
23951 |
|
23952 | process: function(input) {
|
23953 | var options = this.options;
|
23954 |
|
23955 | var validPointers = input.pointers.length === options.pointers;
|
23956 | var validMovement = input.distance < options.threshold;
|
23957 | var validTouchTime = input.deltaTime < options.time;
|
23958 |
|
23959 | this.reset();
|
23960 |
|
23961 | if ((input.eventType & INPUT_START) && (this.count === 0)) {
|
23962 | return this.failTimeout();
|
23963 | }
|
23964 |
|
23965 |
|
23966 |
|
23967 | if (validMovement && validTouchTime && validPointers) {
|
23968 | if (input.eventType != INPUT_END) {
|
23969 | return this.failTimeout();
|
23970 | }
|
23971 |
|
23972 | var validInterval = this.pTime ? (input.timeStamp - this.pTime < options.interval) : true;
|
23973 | var validMultiTap = !this.pCenter || getDistance(this.pCenter, input.center) < options.posThreshold;
|
23974 |
|
23975 | this.pTime = input.timeStamp;
|
23976 | this.pCenter = input.center;
|
23977 |
|
23978 | if (!validMultiTap || !validInterval) {
|
23979 | this.count = 1;
|
23980 | } else {
|
23981 | this.count += 1;
|
23982 | }
|
23983 |
|
23984 | this._input = input;
|
23985 |
|
23986 |
|
23987 |
|
23988 | var tapCount = this.count % options.taps;
|
23989 | if (tapCount === 0) {
|
23990 |
|
23991 |
|
23992 | if (!this.hasRequireFailures()) {
|
23993 | return STATE_RECOGNIZED;
|
23994 | } else {
|
23995 | this._timer = setTimeoutContext(function() {
|
23996 | this.state = STATE_RECOGNIZED;
|
23997 | this.tryEmit();
|
23998 | }, options.interval, this);
|
23999 | return STATE_BEGAN;
|
24000 | }
|
24001 | }
|
24002 | }
|
24003 | return STATE_FAILED;
|
24004 | },
|
24005 |
|
24006 | failTimeout: function() {
|
24007 | this._timer = setTimeoutContext(function() {
|
24008 | this.state = STATE_FAILED;
|
24009 | }, this.options.interval, this);
|
24010 | return STATE_FAILED;
|
24011 | },
|
24012 |
|
24013 | reset: function() {
|
24014 | clearTimeout(this._timer);
|
24015 | },
|
24016 |
|
24017 | emit: function() {
|
24018 | if (this.state == STATE_RECOGNIZED) {
|
24019 | this._input.tapCount = this.count;
|
24020 | this.manager.emit(this.options.event, this._input);
|
24021 | }
|
24022 | }
|
24023 | });
|
24024 |
|
24025 | |
24026 |
|
24027 |
|
24028 |
|
24029 |
|
24030 |
|
24031 | function Hammer(element, options) {
|
24032 | options = options || {};
|
24033 | options.recognizers = ifUndefined(options.recognizers, Hammer.defaults.preset);
|
24034 | return new Manager(element, options);
|
24035 | }
|
24036 |
|
24037 | |
24038 |
|
24039 |
|
24040 | Hammer.VERSION = '2.0.7';
|
24041 |
|
24042 | |
24043 |
|
24044 |
|
24045 |
|
24046 | Hammer.defaults = {
|
24047 | |
24048 |
|
24049 |
|
24050 |
|
24051 |
|
24052 |
|
24053 | domEvents: false,
|
24054 |
|
24055 | |
24056 |
|
24057 |
|
24058 |
|
24059 |
|
24060 |
|
24061 | touchAction: TOUCH_ACTION_COMPUTE,
|
24062 |
|
24063 | |
24064 |
|
24065 |
|
24066 |
|
24067 | enable: true,
|
24068 |
|
24069 | |
24070 |
|
24071 |
|
24072 |
|
24073 |
|
24074 |
|
24075 |
|
24076 | inputTarget: null,
|
24077 |
|
24078 | |
24079 |
|
24080 |
|
24081 |
|
24082 |
|
24083 | inputClass: null,
|
24084 |
|
24085 | |
24086 |
|
24087 |
|
24088 |
|
24089 |
|
24090 | preset: [
|
24091 |
|
24092 | [RotateRecognizer, {enable: false}],
|
24093 | [PinchRecognizer, {enable: false}, ['rotate']],
|
24094 | [SwipeRecognizer, {direction: DIRECTION_HORIZONTAL}],
|
24095 | [PanRecognizer, {direction: DIRECTION_HORIZONTAL}, ['swipe']],
|
24096 | [TapRecognizer],
|
24097 | [TapRecognizer, {event: 'doubletap', taps: 2}, ['tap']],
|
24098 | [PressRecognizer]
|
24099 | ],
|
24100 |
|
24101 | |
24102 |
|
24103 |
|
24104 |
|
24105 |
|
24106 | cssProps: {
|
24107 | |
24108 |
|
24109 |
|
24110 |
|
24111 |
|
24112 | userSelect: 'none',
|
24113 |
|
24114 | |
24115 |
|
24116 |
|
24117 |
|
24118 |
|
24119 | touchSelect: 'none',
|
24120 |
|
24121 | |
24122 |
|
24123 |
|
24124 |
|
24125 |
|
24126 |
|
24127 |
|
24128 | touchCallout: 'none',
|
24129 |
|
24130 | |
24131 |
|
24132 |
|
24133 |
|
24134 |
|
24135 | contentZooming: 'none',
|
24136 |
|
24137 | |
24138 |
|
24139 |
|
24140 |
|
24141 |
|
24142 | userDrag: 'none',
|
24143 |
|
24144 | |
24145 |
|
24146 |
|
24147 |
|
24148 |
|
24149 |
|
24150 | tapHighlightColor: 'rgba(0,0,0,0)'
|
24151 | }
|
24152 | };
|
24153 |
|
24154 | var STOP = 1;
|
24155 | var FORCED_STOP = 2;
|
24156 |
|
24157 | |
24158 |
|
24159 |
|
24160 |
|
24161 |
|
24162 |
|
24163 | function Manager(element, options) {
|
24164 | this.options = assign({}, Hammer.defaults, options || {});
|
24165 |
|
24166 | this.options.inputTarget = this.options.inputTarget || element;
|
24167 |
|
24168 | this.handlers = {};
|
24169 | this.session = {};
|
24170 | this.recognizers = [];
|
24171 | this.oldCssProps = {};
|
24172 |
|
24173 | this.element = element;
|
24174 | this.input = createInputInstance(this);
|
24175 | this.touchAction = new TouchAction(this, this.options.touchAction);
|
24176 |
|
24177 | toggleCssProps(this, true);
|
24178 |
|
24179 | each(this.options.recognizers, function(item) {
|
24180 | var recognizer = this.add(new (item[0])(item[1]));
|
24181 | item[2] && recognizer.recognizeWith(item[2]);
|
24182 | item[3] && recognizer.requireFailure(item[3]);
|
24183 | }, this);
|
24184 | }
|
24185 |
|
24186 | Manager.prototype = {
|
24187 | |
24188 |
|
24189 |
|
24190 |
|
24191 |
|
24192 | set: function(options) {
|
24193 | assign(this.options, options);
|
24194 |
|
24195 |
|
24196 | if (options.touchAction) {
|
24197 | this.touchAction.update();
|
24198 | }
|
24199 | if (options.inputTarget) {
|
24200 |
|
24201 | this.input.destroy();
|
24202 | this.input.target = options.inputTarget;
|
24203 | this.input.init();
|
24204 | }
|
24205 | return this;
|
24206 | },
|
24207 |
|
24208 | |
24209 |
|
24210 |
|
24211 |
|
24212 |
|
24213 |
|
24214 | stop: function(force) {
|
24215 | this.session.stopped = force ? FORCED_STOP : STOP;
|
24216 | },
|
24217 |
|
24218 | |
24219 |
|
24220 |
|
24221 |
|
24222 |
|
24223 |
|
24224 | recognize: function(inputData) {
|
24225 | var session = this.session;
|
24226 | if (session.stopped) {
|
24227 | return;
|
24228 | }
|
24229 |
|
24230 |
|
24231 | this.touchAction.preventDefaults(inputData);
|
24232 |
|
24233 | var recognizer;
|
24234 | var recognizers = this.recognizers;
|
24235 |
|
24236 |
|
24237 |
|
24238 |
|
24239 | var curRecognizer = session.curRecognizer;
|
24240 |
|
24241 |
|
24242 |
|
24243 | if (!curRecognizer || (curRecognizer && curRecognizer.state & STATE_RECOGNIZED)) {
|
24244 | curRecognizer = session.curRecognizer = null;
|
24245 | }
|
24246 |
|
24247 | var i = 0;
|
24248 | while (i < recognizers.length) {
|
24249 | recognizer = recognizers[i];
|
24250 |
|
24251 |
|
24252 |
|
24253 |
|
24254 |
|
24255 |
|
24256 |
|
24257 | if (session.stopped !== FORCED_STOP && (
|
24258 | !curRecognizer || recognizer == curRecognizer ||
|
24259 | recognizer.canRecognizeWith(curRecognizer))) {
|
24260 | recognizer.recognize(inputData);
|
24261 | } else {
|
24262 | recognizer.reset();
|
24263 | }
|
24264 |
|
24265 |
|
24266 |
|
24267 | if (!curRecognizer && recognizer.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED)) {
|
24268 | curRecognizer = session.curRecognizer = recognizer;
|
24269 | }
|
24270 | i++;
|
24271 | }
|
24272 | },
|
24273 |
|
24274 | |
24275 |
|
24276 |
|
24277 |
|
24278 |
|
24279 | get: function(recognizer) {
|
24280 | if (recognizer instanceof Recognizer) {
|
24281 | return recognizer;
|
24282 | }
|
24283 |
|
24284 | var recognizers = this.recognizers;
|
24285 | for (var i = 0; i < recognizers.length; i++) {
|
24286 | if (recognizers[i].options.event == recognizer) {
|
24287 | return recognizers[i];
|
24288 | }
|
24289 | }
|
24290 | return null;
|
24291 | },
|
24292 |
|
24293 | |
24294 |
|
24295 |
|
24296 |
|
24297 |
|
24298 |
|
24299 | add: function(recognizer) {
|
24300 | if (invokeArrayArg(recognizer, 'add', this)) {
|
24301 | return this;
|
24302 | }
|
24303 |
|
24304 |
|
24305 | var existing = this.get(recognizer.options.event);
|
24306 | if (existing) {
|
24307 | this.remove(existing);
|
24308 | }
|
24309 |
|
24310 | this.recognizers.push(recognizer);
|
24311 | recognizer.manager = this;
|
24312 |
|
24313 | this.touchAction.update();
|
24314 | return recognizer;
|
24315 | },
|
24316 |
|
24317 | |
24318 |
|
24319 |
|
24320 |
|
24321 |
|
24322 | remove: function(recognizer) {
|
24323 | if (invokeArrayArg(recognizer, 'remove', this)) {
|
24324 | return this;
|
24325 | }
|
24326 |
|
24327 | recognizer = this.get(recognizer);
|
24328 |
|
24329 |
|
24330 | if (recognizer) {
|
24331 | var recognizers = this.recognizers;
|
24332 | var index = inArray(recognizers, recognizer);
|
24333 |
|
24334 | if (index !== -1) {
|
24335 | recognizers.splice(index, 1);
|
24336 | this.touchAction.update();
|
24337 | }
|
24338 | }
|
24339 |
|
24340 | return this;
|
24341 | },
|
24342 |
|
24343 | |
24344 |
|
24345 |
|
24346 |
|
24347 |
|
24348 |
|
24349 | on: function(events, handler) {
|
24350 | if (events === undefined$1) {
|
24351 | return;
|
24352 | }
|
24353 | if (handler === undefined$1) {
|
24354 | return;
|
24355 | }
|
24356 |
|
24357 | var handlers = this.handlers;
|
24358 | each(splitStr(events), function(event) {
|
24359 | handlers[event] = handlers[event] || [];
|
24360 | handlers[event].push(handler);
|
24361 | });
|
24362 | return this;
|
24363 | },
|
24364 |
|
24365 | |
24366 |
|
24367 |
|
24368 |
|
24369 |
|
24370 |
|
24371 | off: function(events, handler) {
|
24372 | if (events === undefined$1) {
|
24373 | return;
|
24374 | }
|
24375 |
|
24376 | var handlers = this.handlers;
|
24377 | each(splitStr(events), function(event) {
|
24378 | if (!handler) {
|
24379 | delete handlers[event];
|
24380 | } else {
|
24381 | handlers[event] && handlers[event].splice(inArray(handlers[event], handler), 1);
|
24382 | }
|
24383 | });
|
24384 | return this;
|
24385 | },
|
24386 |
|
24387 | |
24388 |
|
24389 |
|
24390 |
|
24391 |
|
24392 | emit: function(event, data) {
|
24393 |
|
24394 | if (this.options.domEvents) {
|
24395 | triggerDomEvent(event, data);
|
24396 | }
|
24397 |
|
24398 |
|
24399 | var handlers = this.handlers[event] && this.handlers[event].slice();
|
24400 | if (!handlers || !handlers.length) {
|
24401 | return;
|
24402 | }
|
24403 |
|
24404 | data.type = event;
|
24405 | data.preventDefault = function() {
|
24406 | data.srcEvent.preventDefault();
|
24407 | };
|
24408 |
|
24409 | var i = 0;
|
24410 | while (i < handlers.length) {
|
24411 | handlers[i](data);
|
24412 | i++;
|
24413 | }
|
24414 | },
|
24415 |
|
24416 | |
24417 |
|
24418 |
|
24419 |
|
24420 | destroy: function() {
|
24421 | this.element && toggleCssProps(this, false);
|
24422 |
|
24423 | this.handlers = {};
|
24424 | this.session = {};
|
24425 | this.input.destroy();
|
24426 | this.element = null;
|
24427 | }
|
24428 | };
|
24429 |
|
24430 | |
24431 |
|
24432 |
|
24433 |
|
24434 |
|
24435 | function toggleCssProps(manager, add) {
|
24436 | var element = manager.element;
|
24437 | if (!element.style) {
|
24438 | return;
|
24439 | }
|
24440 | var prop;
|
24441 | each(manager.options.cssProps, function(value, name) {
|
24442 | prop = prefixed(element.style, name);
|
24443 | if (add) {
|
24444 | manager.oldCssProps[prop] = element.style[prop];
|
24445 | element.style[prop] = value;
|
24446 | } else {
|
24447 | element.style[prop] = manager.oldCssProps[prop] || '';
|
24448 | }
|
24449 | });
|
24450 | if (!add) {
|
24451 | manager.oldCssProps = {};
|
24452 | }
|
24453 | }
|
24454 |
|
24455 | |
24456 |
|
24457 |
|
24458 |
|
24459 |
|
24460 | function triggerDomEvent(event, data) {
|
24461 | var gestureEvent = document.createEvent('Event');
|
24462 | gestureEvent.initEvent(event, true, true);
|
24463 | gestureEvent.gesture = data;
|
24464 | data.target.dispatchEvent(gestureEvent);
|
24465 | }
|
24466 |
|
24467 | assign(Hammer, {
|
24468 | INPUT_START: INPUT_START,
|
24469 | INPUT_MOVE: INPUT_MOVE,
|
24470 | INPUT_END: INPUT_END,
|
24471 | INPUT_CANCEL: INPUT_CANCEL,
|
24472 |
|
24473 | STATE_POSSIBLE: STATE_POSSIBLE,
|
24474 | STATE_BEGAN: STATE_BEGAN,
|
24475 | STATE_CHANGED: STATE_CHANGED,
|
24476 | STATE_ENDED: STATE_ENDED,
|
24477 | STATE_RECOGNIZED: STATE_RECOGNIZED,
|
24478 | STATE_CANCELLED: STATE_CANCELLED,
|
24479 | STATE_FAILED: STATE_FAILED,
|
24480 |
|
24481 | DIRECTION_NONE: DIRECTION_NONE,
|
24482 | DIRECTION_LEFT: DIRECTION_LEFT,
|
24483 | DIRECTION_RIGHT: DIRECTION_RIGHT,
|
24484 | DIRECTION_UP: DIRECTION_UP,
|
24485 | DIRECTION_DOWN: DIRECTION_DOWN,
|
24486 | DIRECTION_HORIZONTAL: DIRECTION_HORIZONTAL,
|
24487 | DIRECTION_VERTICAL: DIRECTION_VERTICAL,
|
24488 | DIRECTION_ALL: DIRECTION_ALL,
|
24489 |
|
24490 | Manager: Manager,
|
24491 | Input: Input,
|
24492 | TouchAction: TouchAction,
|
24493 |
|
24494 | TouchInput: TouchInput,
|
24495 | MouseInput: MouseInput,
|
24496 | PointerEventInput: PointerEventInput,
|
24497 | TouchMouseInput: TouchMouseInput,
|
24498 | SingleTouchInput: SingleTouchInput,
|
24499 |
|
24500 | Recognizer: Recognizer,
|
24501 | AttrRecognizer: AttrRecognizer,
|
24502 | Tap: TapRecognizer,
|
24503 | Pan: PanRecognizer,
|
24504 | Swipe: SwipeRecognizer,
|
24505 | Pinch: PinchRecognizer,
|
24506 | Rotate: RotateRecognizer,
|
24507 | Press: PressRecognizer,
|
24508 |
|
24509 | on: addEventListeners,
|
24510 | off: removeEventListeners,
|
24511 | each: each,
|
24512 | merge: merge,
|
24513 | extend: extend,
|
24514 | assign: assign,
|
24515 | inherit: inherit,
|
24516 | bindFn: bindFn,
|
24517 | prefixed: prefixed
|
24518 | });
|
24519 |
|
24520 |
|
24521 |
|
24522 | var freeGlobal = (typeof window !== 'undefined' ? window : (typeof self !== 'undefined' ? self : {}));
|
24523 | freeGlobal.Hammer = Hammer;
|
24524 |
|
24525 | if (typeof undefined$1 === 'function' && undefined$1.amd) {
|
24526 | undefined$1(function() {
|
24527 | return Hammer;
|
24528 | });
|
24529 | } else if ( module.exports) {
|
24530 | module.exports = Hammer;
|
24531 | } else {
|
24532 | window[exportName] = Hammer;
|
24533 | }
|
24534 |
|
24535 | })(window, document, 'Hammer');
|
24536 | });
|
24537 |
|
24538 | var MIN_ZOOM = 0.2,
|
24539 | MAX_ZOOM = 4;
|
24540 |
|
24541 | var mouseEvents = [
|
24542 | 'mousedown',
|
24543 | 'mouseup',
|
24544 | 'mouseover',
|
24545 | 'mouseout',
|
24546 | 'click',
|
24547 | 'dblclick'
|
24548 | ];
|
24549 |
|
24550 | function get$1(service, injector) {
|
24551 | return injector.get(service, false);
|
24552 | }
|
24553 |
|
24554 | function stopEvent(event) {
|
24555 |
|
24556 | event.preventDefault();
|
24557 | event.stopPropagation();
|
24558 |
|
24559 | if (typeof event.stopImmediatePropagation === 'function') {
|
24560 | event.stopImmediatePropagation();
|
24561 | }
|
24562 | }
|
24563 |
|
24564 |
|
24565 | function createTouchRecognizer(node) {
|
24566 |
|
24567 | function stopMouse(event) {
|
24568 |
|
24569 | forEach(mouseEvents, function(e) {
|
24570 | componentEvent.bind(node, e, stopEvent, true);
|
24571 | });
|
24572 | }
|
24573 |
|
24574 | function allowMouse(event) {
|
24575 | setTimeout(function() {
|
24576 | forEach(mouseEvents, function(e) {
|
24577 | componentEvent.unbind(node, e, stopEvent, true);
|
24578 | });
|
24579 | }, 500);
|
24580 | }
|
24581 |
|
24582 | componentEvent.bind(node, 'touchstart', stopMouse, true);
|
24583 | componentEvent.bind(node, 'touchend', allowMouse, true);
|
24584 | componentEvent.bind(node, 'touchcancel', allowMouse, true);
|
24585 |
|
24586 |
|
24587 |
|
24588 |
|
24589 |
|
24590 | var recognizer = new hammer.Manager(node, {
|
24591 | inputClass: hammer.TouchInput,
|
24592 | recognizers: []
|
24593 | });
|
24594 |
|
24595 |
|
24596 | var tap = new hammer.Tap();
|
24597 | var pan = new hammer.Pan({ threshold: 10 });
|
24598 | var press = new hammer.Press();
|
24599 | var pinch = new hammer.Pinch();
|
24600 |
|
24601 | var doubleTap = new hammer.Tap({ event: 'doubletap', taps: 2 });
|
24602 |
|
24603 | pinch.requireFailure(pan);
|
24604 | pinch.requireFailure(press);
|
24605 |
|
24606 | recognizer.add([ pan, press, pinch, doubleTap, tap ]);
|
24607 |
|
24608 | recognizer.reset = function(force) {
|
24609 | var recognizers = this.recognizers,
|
24610 | session = this.session;
|
24611 |
|
24612 | if (session.stopped) {
|
24613 | return;
|
24614 | }
|
24615 |
|
24616 | recognizer.stop(force);
|
24617 |
|
24618 | setTimeout(function() {
|
24619 | var i, r;
|
24620 | for (i = 0; (r = recognizers[i]); i++) {
|
24621 | r.reset();
|
24622 | r.state = 8;
|
24623 | }
|
24624 |
|
24625 | session.curRecognizer = null;
|
24626 | }, 0);
|
24627 | };
|
24628 |
|
24629 | recognizer.on('hammer.input', function(event) {
|
24630 | if (event.srcEvent.defaultPrevented) {
|
24631 | recognizer.reset(true);
|
24632 | }
|
24633 | });
|
24634 |
|
24635 | return recognizer;
|
24636 | }
|
24637 |
|
24638 | |
24639 |
|
24640 |
|
24641 |
|
24642 |
|
24643 |
|
24644 | function TouchInteractionEvents(
|
24645 | injector, canvas, eventBus,
|
24646 | elementRegistry, interactionEvents) {
|
24647 |
|
24648 |
|
24649 | var dragging = get$1('dragging', injector),
|
24650 | move = get$1('move', injector),
|
24651 | contextPad = get$1('contextPad', injector),
|
24652 | palette = get$1('palette', injector);
|
24653 |
|
24654 | // the touch recognizer
|
24655 | var recognizer;
|
24656 |
|
24657 | function handler(type) {
|
24658 |
|
24659 | return function(event) {
|
24660 |
|
24661 | interactionEvents.fire(type, event);
|
24662 | };
|
24663 | }
|
24664 |
|
24665 | function getGfx(target) {
|
24666 | var node = closest(target, 'svg, .djs-element', true);
|
24667 | return node;
|
24668 | }
|
24669 |
|
24670 | function initEvents(svg) {
|
24671 |
|
24672 |
|
24673 | recognizer = createTouchRecognizer(svg);
|
24674 |
|
24675 | recognizer.on('doubletap', handler('element.dblclick'));
|
24676 |
|
24677 | recognizer.on('tap', handler('element.click'));
|
24678 |
|
24679 | function startGrabCanvas(event) {
|
24680 |
|
24681 | var lx = 0, ly = 0;
|
24682 |
|
24683 | function update(e) {
|
24684 |
|
24685 | var dx = e.deltaX - lx,
|
24686 | dy = e.deltaY - ly;
|
24687 |
|
24688 | canvas.scroll({ dx: dx, dy: dy });
|
24689 |
|
24690 | lx = e.deltaX;
|
24691 | ly = e.deltaY;
|
24692 | }
|
24693 |
|
24694 | function end(e) {
|
24695 | recognizer.off('panmove', update);
|
24696 | recognizer.off('panend', end);
|
24697 | recognizer.off('pancancel', end);
|
24698 | }
|
24699 |
|
24700 | recognizer.on('panmove', update);
|
24701 | recognizer.on('panend', end);
|
24702 | recognizer.on('pancancel', end);
|
24703 | }
|
24704 |
|
24705 | function startGrab(event) {
|
24706 |
|
24707 | var gfx = getGfx(event.target),
|
24708 | element = gfx && elementRegistry.get(gfx);
|
24709 |
|
24710 |
|
24711 | if (move && canvas.getRootElement() !== element) {
|
24712 | return move.start(event, element, true);
|
24713 | } else {
|
24714 | startGrabCanvas();
|
24715 | }
|
24716 | }
|
24717 |
|
24718 | function startZoom(e) {
|
24719 |
|
24720 | var zoom = canvas.zoom(),
|
24721 | mid = e.center;
|
24722 |
|
24723 | function update(e) {
|
24724 |
|
24725 | var ratio = 1 - (1 - e.scale) / 1.50,
|
24726 | newZoom = Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, ratio * zoom));
|
24727 |
|
24728 | canvas.zoom(newZoom, mid);
|
24729 |
|
24730 | stopEvent(e);
|
24731 | }
|
24732 |
|
24733 | function end(e) {
|
24734 | recognizer.off('pinchmove', update);
|
24735 | recognizer.off('pinchend', end);
|
24736 | recognizer.off('pinchcancel', end);
|
24737 |
|
24738 | recognizer.reset(true);
|
24739 | }
|
24740 |
|
24741 | recognizer.on('pinchmove', update);
|
24742 | recognizer.on('pinchend', end);
|
24743 | recognizer.on('pinchcancel', end);
|
24744 | }
|
24745 |
|
24746 | recognizer.on('panstart', startGrab);
|
24747 | recognizer.on('press', startGrab);
|
24748 |
|
24749 | recognizer.on('pinchstart', startZoom);
|
24750 | }
|
24751 |
|
24752 | if (dragging) {
|
24753 |
|
24754 |
|
24755 | eventBus.on('drag.move', function(event) {
|
24756 |
|
24757 | var originalEvent = event.originalEvent;
|
24758 |
|
24759 | if (!originalEvent || originalEvent instanceof MouseEvent) {
|
24760 | return;
|
24761 | }
|
24762 |
|
24763 | var position = toPoint(originalEvent);
|
24764 |
|
24765 |
|
24766 | var node = document.elementFromPoint(position.x, position.y),
|
24767 | gfx = getGfx(node),
|
24768 | element = gfx && elementRegistry.get(gfx);
|
24769 |
|
24770 | if (element !== event.hover) {
|
24771 | if (event.hover) {
|
24772 | dragging.out(event);
|
24773 | }
|
24774 |
|
24775 | if (element) {
|
24776 | dragging.hover({ element: element, gfx: gfx });
|
24777 |
|
24778 | event.hover = element;
|
24779 | event.hoverGfx = gfx;
|
24780 | }
|
24781 | }
|
24782 | });
|
24783 | }
|
24784 |
|
24785 | if (contextPad) {
|
24786 |
|
24787 | eventBus.on('contextPad.create', function(event) {
|
24788 | var node = event.pad.html;
|
24789 |
|
24790 |
|
24791 | var padRecognizer = createTouchRecognizer(node);
|
24792 |
|
24793 | padRecognizer.on('panstart', function(event) {
|
24794 | contextPad.trigger('dragstart', event, true);
|
24795 | });
|
24796 |
|
24797 | padRecognizer.on('press', function(event) {
|
24798 | contextPad.trigger('dragstart', event, true);
|
24799 | });
|
24800 |
|
24801 | padRecognizer.on('tap', function(event) {
|
24802 | contextPad.trigger('click', event);
|
24803 | });
|
24804 | });
|
24805 | }
|
24806 |
|
24807 | if (palette) {
|
24808 | eventBus.on('palette.create', function(event) {
|
24809 | var node = event.container;
|
24810 |
|
24811 |
|
24812 | var padRecognizer = createTouchRecognizer(node);
|
24813 |
|
24814 | padRecognizer.on('panstart', function(event) {
|
24815 | palette.trigger('dragstart', event, true);
|
24816 | });
|
24817 |
|
24818 | padRecognizer.on('press', function(event) {
|
24819 | palette.trigger('dragstart', event, true);
|
24820 | });
|
24821 |
|
24822 | padRecognizer.on('tap', function(event) {
|
24823 | palette.trigger('click', event);
|
24824 | });
|
24825 | });
|
24826 | }
|
24827 |
|
24828 | eventBus.on('canvas.init', function(event) {
|
24829 | initEvents(event.svg);
|
24830 | });
|
24831 | }
|
24832 |
|
24833 |
|
24834 | TouchInteractionEvents.$inject = [
|
24835 | 'injector',
|
24836 | 'canvas',
|
24837 | 'eventBus',
|
24838 | 'elementRegistry',
|
24839 | 'interactionEvents',
|
24840 | 'touchFix'
|
24841 | ];
|
24842 |
|
24843 | function TouchFix(canvas, eventBus) {
|
24844 |
|
24845 | var self = this;
|
24846 |
|
24847 | eventBus.on('canvas.init', function(e) {
|
24848 | self.addBBoxMarker(e.svg);
|
24849 | });
|
24850 | }
|
24851 |
|
24852 | TouchFix.$inject = [ 'canvas', 'eventBus' ];
|
24853 |
|
24854 |
|
24855 | |
24856 |
|
24857 |
|
24858 |
|
24859 |
|
24860 |
|
24861 |
|
24862 | TouchFix.prototype.addBBoxMarker = function(svg) {
|
24863 |
|
24864 | var markerStyle = {
|
24865 | fill: 'none',
|
24866 | class: 'outer-bound-marker'
|
24867 | };
|
24868 |
|
24869 | var rect1 = create('rect');
|
24870 | attr$1(rect1, {
|
24871 | x: -10000,
|
24872 | y: 10000,
|
24873 | width: 10,
|
24874 | height: 10
|
24875 | });
|
24876 | attr$1(rect1, markerStyle);
|
24877 |
|
24878 | append(svg, rect1);
|
24879 |
|
24880 | var rect2 = create('rect');
|
24881 | attr$1(rect2, {
|
24882 | x: 10000,
|
24883 | y: 10000,
|
24884 | width: 10,
|
24885 | height: 10
|
24886 | });
|
24887 | attr$1(rect2, markerStyle);
|
24888 |
|
24889 | append(svg, rect2);
|
24890 | };
|
24891 |
|
24892 | var TouchModule = {
|
24893 | __depends__: [ InteractionEventsModule ],
|
24894 | __init__: [ 'touchInteractionEvents' ],
|
24895 | touchInteractionEvents: [ 'type', TouchInteractionEvents ],
|
24896 | touchFix: [ 'type', TouchFix ]
|
24897 | };
|
24898 |
|
24899 | var TouchModule$1 = {
|
24900 | __depends__: [
|
24901 | TouchModule
|
24902 | ]
|
24903 | };
|
24904 |
|
24905 | function last(arr) {
|
24906 | return arr && arr[arr.length - 1];
|
24907 | }
|
24908 |
|
24909 | function sortTopOrMiddle(element) {
|
24910 | return element.y;
|
24911 | }
|
24912 |
|
24913 | function sortLeftOrCenter(element) {
|
24914 | return element.x;
|
24915 | }
|
24916 |
|
24917 | |
24918 |
|
24919 |
|
24920 |
|
24921 |
|
24922 |
|
24923 |
|
24924 | var ALIGNMENT_SORTING = {
|
24925 | left: sortLeftOrCenter,
|
24926 | center: sortLeftOrCenter,
|
24927 | right: function(element) {
|
24928 | return element.x + element.width;
|
24929 | },
|
24930 | top: sortTopOrMiddle,
|
24931 | middle: sortTopOrMiddle,
|
24932 | bottom: function(element) {
|
24933 | return element.y + element.height;
|
24934 | }
|
24935 | };
|
24936 |
|
24937 |
|
24938 | function AlignElements(modeling) {
|
24939 | this._modeling = modeling;
|
24940 | }
|
24941 |
|
24942 | AlignElements.$inject = [ 'modeling' ];
|
24943 |
|
24944 |
|
24945 | |
24946 |
|
24947 |
|
24948 |
|
24949 |
|
24950 |
|
24951 |
|
24952 | AlignElements.prototype._getOrientationDetails = function(type) {
|
24953 | var vertical = [ 'top', 'bottom', 'middle' ],
|
24954 | axis = 'x',
|
24955 | dimension = 'width';
|
24956 |
|
24957 | if (vertical.indexOf(type) !== -1) {
|
24958 | axis = 'y';
|
24959 | dimension = 'height';
|
24960 | }
|
24961 |
|
24962 | return {
|
24963 | axis: axis,
|
24964 | dimension: dimension
|
24965 | };
|
24966 | };
|
24967 |
|
24968 | AlignElements.prototype._isType = function(type, types) {
|
24969 | return types.indexOf(type) !== -1;
|
24970 | };
|
24971 |
|
24972 | |
24973 |
|
24974 |
|
24975 |
|
24976 |
|
24977 |
|
24978 |
|
24979 |
|
24980 | AlignElements.prototype._alignmentPosition = function(type, sortedElements) {
|
24981 | var orientation = this._getOrientationDetails(type),
|
24982 | axis = orientation.axis,
|
24983 | dimension = orientation.dimension,
|
24984 | alignment = {},
|
24985 | centers = {},
|
24986 | hasSharedCenters = false,
|
24987 | centeredElements,
|
24988 | firstElement,
|
24989 | lastElement;
|
24990 |
|
24991 | function getMiddleOrTop(first, last) {
|
24992 | return Math.round((first[axis] + last[axis] + last[dimension]) / 2);
|
24993 | }
|
24994 |
|
24995 | if (this._isType(type, [ 'left', 'top' ])) {
|
24996 | alignment[type] = sortedElements[0][axis];
|
24997 |
|
24998 | } else if (this._isType(type, [ 'right', 'bottom' ])) {
|
24999 | lastElement = last(sortedElements);
|
25000 |
|
25001 | alignment[type] = lastElement[axis] + lastElement[dimension];
|
25002 |
|
25003 | } else if (this._isType(type, [ 'center', 'middle' ])) {
|
25004 |
|
25005 |
|
25006 |
|
25007 | forEach(sortedElements, function(element) {
|
25008 | var center = element[axis] + Math.round(element[dimension] / 2);
|
25009 |
|
25010 | if (centers[center]) {
|
25011 | centers[center].elements.push(element);
|
25012 | } else {
|
25013 | centers[center] = {
|
25014 | elements: [ element ],
|
25015 | center: center
|
25016 | };
|
25017 | }
|
25018 | });
|
25019 |
|
25020 | centeredElements = sortBy(centers, function(center) {
|
25021 | if (center.elements.length > 1) {
|
25022 | hasSharedCenters = true;
|
25023 | }
|
25024 |
|
25025 | return center.elements.length;
|
25026 | });
|
25027 |
|
25028 | if (hasSharedCenters) {
|
25029 | alignment[type] = last(centeredElements).center;
|
25030 |
|
25031 | return alignment;
|
25032 | }
|
25033 |
|
25034 | firstElement = sortedElements[0];
|
25035 |
|
25036 | sortedElements = sortBy(sortedElements, function(element) {
|
25037 | return element[axis] + element[dimension];
|
25038 | });
|
25039 |
|
25040 | lastElement = last(sortedElements);
|
25041 |
|
25042 | alignment[type] = getMiddleOrTop(firstElement, lastElement);
|
25043 | }
|
25044 |
|
25045 | return alignment;
|
25046 | };
|
25047 |
|
25048 | |
25049 |
|
25050 |
|
25051 |
|
25052 |
|
25053 |
|
25054 | AlignElements.prototype.trigger = function(elements, type) {
|
25055 | var modeling = this._modeling;
|
25056 |
|
25057 | var filteredElements = filter(elements, function(element) {
|
25058 | return !(element.waypoints || element.host || element.labelTarget);
|
25059 | });
|
25060 |
|
25061 | var sortFn = ALIGNMENT_SORTING[type];
|
25062 |
|
25063 | var sortedElements = sortBy(filteredElements, sortFn);
|
25064 |
|
25065 | var alignment = this._alignmentPosition(type, sortedElements);
|
25066 |
|
25067 | modeling.alignElements(sortedElements, alignment);
|
25068 | };
|
25069 |
|
25070 | var AlignElementsModule = {
|
25071 | __init__: [ 'alignElements' ],
|
25072 | alignElements: [ 'type', AlignElements ]
|
25073 | };
|
25074 |
|
25075 | |
25076 |
|
25077 |
|
25078 |
|
25079 |
|
25080 |
|
25081 |
|
25082 |
|
25083 | function isAny(element, types) {
|
25084 | return some(types, function(t) {
|
25085 | return is$1(element, t);
|
25086 | });
|
25087 | }
|
25088 |
|
25089 |
|
25090 | |
25091 |
|
25092 |
|
25093 |
|
25094 |
|
25095 |
|
25096 |
|
25097 |
|
25098 | function getParent$1(element, anyType) {
|
25099 |
|
25100 | if (typeof anyType === 'string') {
|
25101 | anyType = [ anyType ];
|
25102 | }
|
25103 |
|
25104 | while ((element = element.parent)) {
|
25105 | if (isAny(element, anyType)) {
|
25106 | return element;
|
25107 | }
|
25108 | }
|
25109 |
|
25110 | return null;
|
25111 | }
|
25112 |
|
25113 | var DEFAULT_HORIZONTAL_DISTANCE = 50;
|
25114 |
|
25115 | var MAX_HORIZONTAL_DISTANCE = 250;
|
25116 |
|
25117 |
|
25118 | var PLACEMENT_DETECTION_PAD = 10;
|
25119 |
|
25120 | |
25121 |
|
25122 |
|
25123 |
|
25124 |
|
25125 |
|
25126 |
|
25127 |
|
25128 |
|
25129 | function getNewShapePosition(source, element) {
|
25130 |
|
25131 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
25132 | return getTextAnnotationPosition(source, element);
|
25133 | }
|
25134 |
|
25135 | if (isAny(element, [ 'bpmn:DataObjectReference', 'bpmn:DataStoreReference' ])) {
|
25136 | return getDataElementPosition(source, element);
|
25137 | }
|
25138 |
|
25139 | if (is$1(element, 'bpmn:FlowNode')) {
|
25140 | return getFlowNodePosition(source, element);
|
25141 | }
|
25142 |
|
25143 | return getDefaultPosition(source, element);
|
25144 | }
|
25145 |
|
25146 | |
25147 |
|
25148 |
|
25149 |
|
25150 | function getFlowNodePosition(source, element) {
|
25151 |
|
25152 | var sourceTrbl = asTRBL(source);
|
25153 | var sourceMid = getMid(source);
|
25154 |
|
25155 | var horizontalDistance = getFlowNodeDistance(source);
|
25156 |
|
25157 | var orientation = 'left',
|
25158 | rowSize = 80,
|
25159 | margin = 30;
|
25160 |
|
25161 | if (is$1(source, 'bpmn:BoundaryEvent')) {
|
25162 | orientation = getOrientation(source, source.host, -25);
|
25163 |
|
25164 | if (orientation.indexOf('top') !== -1) {
|
25165 | margin *= -1;
|
25166 | }
|
25167 | }
|
25168 |
|
25169 | function getVerticalDistance(orient) {
|
25170 | if (orient.indexOf('top') != -1) {
|
25171 | return -1 * rowSize;
|
25172 | } else if (orient.indexOf('bottom') != -1) {
|
25173 | return rowSize;
|
25174 | } else {
|
25175 | return 0;
|
25176 | }
|
25177 | }
|
25178 |
|
25179 | var position = {
|
25180 | x: sourceTrbl.right + horizontalDistance + element.width / 2,
|
25181 | y: sourceMid.y + getVerticalDistance(orientation)
|
25182 | };
|
25183 |
|
25184 | var escapeDirection = {
|
25185 | y: {
|
25186 | margin: margin,
|
25187 | rowSize: rowSize
|
25188 | }
|
25189 | };
|
25190 |
|
25191 | return deconflictPosition(source, element, position, escapeDirection);
|
25192 | }
|
25193 |
|
25194 |
|
25195 | |
25196 |
|
25197 |
|
25198 |
|
25199 |
|
25200 |
|
25201 |
|
25202 |
|
25203 |
|
25204 | function getFlowNodeDistance(source, element) {
|
25205 |
|
25206 | var sourceTrbl = asTRBL(source);
|
25207 |
|
25208 |
|
25209 | function isReference(c) {
|
25210 | return is$1(c, 'bpmn:SequenceFlow');
|
25211 | }
|
25212 |
|
25213 | function toTargetNode(weight) {
|
25214 |
|
25215 | return function(shape) {
|
25216 | return {
|
25217 | shape: shape,
|
25218 | weight: weight,
|
25219 | distanceTo: function(shape) {
|
25220 | var shapeTrbl = asTRBL(shape);
|
25221 |
|
25222 | return shapeTrbl.left - sourceTrbl.right;
|
25223 | }
|
25224 | };
|
25225 | };
|
25226 | }
|
25227 |
|
25228 | function toSourceNode(weight) {
|
25229 | return function(shape) {
|
25230 | return {
|
25231 | shape: shape,
|
25232 | weight: weight,
|
25233 | distanceTo: function(shape) {
|
25234 | var shapeTrbl = asTRBL(shape);
|
25235 |
|
25236 | return sourceTrbl.left - shapeTrbl.right;
|
25237 | }
|
25238 | };
|
25239 | };
|
25240 | }
|
25241 |
|
25242 |
|
25243 |
|
25244 |
|
25245 |
|
25246 |
|
25247 |
|
25248 | var nodes = reduce([].concat(
|
25249 | getTargets(source, isReference).map(toTargetNode(5)),
|
25250 | getSources(source, isReference).map(toSourceNode(1))
|
25251 | ), function(nodes, node) {
|
25252 |
|
25253 |
|
25254 | nodes[node.shape.id + '__weight_' + node.weight] = node;
|
25255 |
|
25256 | return nodes;
|
25257 | }, {});
|
25258 |
|
25259 |
|
25260 |
|
25261 |
|
25262 | var distancesGrouped = reduce(nodes, function(result, node) {
|
25263 |
|
25264 | var shape = node.shape,
|
25265 | weight = node.weight,
|
25266 | distanceTo = node.distanceTo;
|
25267 |
|
25268 | var fav = result.fav,
|
25269 | currentDistance,
|
25270 | currentDistanceCount,
|
25271 | currentDistanceEntry;
|
25272 |
|
25273 | currentDistance = distanceTo(shape);
|
25274 |
|
25275 |
|
25276 |
|
25277 | if (currentDistance < 0 || currentDistance > MAX_HORIZONTAL_DISTANCE) {
|
25278 | return result;
|
25279 | }
|
25280 |
|
25281 | currentDistanceEntry = result[String(currentDistance)] =
|
25282 | result[String(currentDistance)] || {
|
25283 | value: currentDistance,
|
25284 | count: 0
|
25285 | };
|
25286 |
|
25287 |
|
25288 | currentDistanceCount = currentDistanceEntry.count += 1 * weight;
|
25289 |
|
25290 | if (!fav || fav.count < currentDistanceCount) {
|
25291 | result.fav = currentDistanceEntry;
|
25292 | }
|
25293 |
|
25294 | return result;
|
25295 | }, { });
|
25296 |
|
25297 |
|
25298 | if (distancesGrouped.fav) {
|
25299 | return distancesGrouped.fav.value;
|
25300 | } else {
|
25301 | return DEFAULT_HORIZONTAL_DISTANCE;
|
25302 | }
|
25303 | }
|
25304 |
|
25305 |
|
25306 | |
25307 |
|
25308 |
|
25309 | function getTextAnnotationPosition(source, element) {
|
25310 |
|
25311 | var sourceTrbl = asTRBL(source);
|
25312 |
|
25313 | var position = {
|
25314 | x: sourceTrbl.right + element.width / 2,
|
25315 | y: sourceTrbl.top - 50 - element.height / 2
|
25316 | };
|
25317 |
|
25318 | var escapeDirection = {
|
25319 | y: {
|
25320 | margin: -30,
|
25321 | rowSize: 20
|
25322 | }
|
25323 | };
|
25324 |
|
25325 | return deconflictPosition(source, element, position, escapeDirection);
|
25326 | }
|
25327 |
|
25328 |
|
25329 | |
25330 |
|
25331 |
|
25332 | function getDataElementPosition(source, element) {
|
25333 |
|
25334 | var sourceTrbl = asTRBL(source);
|
25335 |
|
25336 | var position = {
|
25337 | x: sourceTrbl.right - 10 + element.width / 2,
|
25338 | y: sourceTrbl.bottom + 40 + element.width / 2
|
25339 | };
|
25340 |
|
25341 | var escapeDirection = {
|
25342 | x: {
|
25343 | margin: 30,
|
25344 | rowSize: 30
|
25345 | }
|
25346 | };
|
25347 |
|
25348 | return deconflictPosition(source, element, position, escapeDirection);
|
25349 | }
|
25350 |
|
25351 |
|
25352 | |
25353 |
|
25354 |
|
25355 | function getDefaultPosition(source, element) {
|
25356 |
|
25357 | var sourceTrbl = asTRBL(source);
|
25358 |
|
25359 | var sourceMid = getMid(source);
|
25360 |
|
25361 |
|
25362 | return {
|
25363 | x: sourceTrbl.right + DEFAULT_HORIZONTAL_DISTANCE + element.width / 2,
|
25364 | y: sourceMid.y
|
25365 | };
|
25366 | }
|
25367 |
|
25368 |
|
25369 | |
25370 |
|
25371 |
|
25372 |
|
25373 |
|
25374 |
|
25375 |
|
25376 |
|
25377 |
|
25378 |
|
25379 |
|
25380 |
|
25381 |
|
25382 |
|
25383 | function getAutoPlaceClosure(source, element) {
|
25384 |
|
25385 | var allConnected = getConnected(source);
|
25386 |
|
25387 | if (source.host) {
|
25388 | allConnected = allConnected.concat(getConnected(source.host));
|
25389 | }
|
25390 |
|
25391 | if (source.attachers) {
|
25392 | allConnected = allConnected.concat(source.attachers.reduce(function(shapes, attacher) {
|
25393 | return shapes.concat(getConnected(attacher));
|
25394 | }, []));
|
25395 | }
|
25396 |
|
25397 | return allConnected;
|
25398 | }
|
25399 |
|
25400 | |
25401 |
|
25402 |
|
25403 |
|
25404 |
|
25405 |
|
25406 | function getConnectedAtPosition(source, position, element) {
|
25407 |
|
25408 | var bounds = {
|
25409 | x: position.x - (element.width / 2),
|
25410 | y: position.y - (element.height / 2),
|
25411 | width: element.width,
|
25412 | height: element.height
|
25413 | };
|
25414 |
|
25415 | var closure = getAutoPlaceClosure(source);
|
25416 |
|
25417 | return find(closure, function(target) {
|
25418 |
|
25419 | if (target === element) {
|
25420 | return false;
|
25421 | }
|
25422 |
|
25423 | var orientation = getOrientation(target, bounds, PLACEMENT_DETECTION_PAD);
|
25424 |
|
25425 | return orientation === 'intersect';
|
25426 | });
|
25427 | }
|
25428 |
|
25429 |
|
25430 | |
25431 |
|
25432 |
|
25433 |
|
25434 |
|
25435 |
|
25436 |
|
25437 |
|
25438 |
|
25439 |
|
25440 |
|
25441 |
|
25442 |
|
25443 |
|
25444 |
|
25445 | function deconflictPosition(source, element, position, escapeDelta) {
|
25446 |
|
25447 | function nextPosition(existingElement) {
|
25448 |
|
25449 | var newPosition = {
|
25450 | x: position.x,
|
25451 | y: position.y
|
25452 | };
|
25453 |
|
25454 | [ 'x', 'y' ].forEach(function(axis) {
|
25455 |
|
25456 | var axisDelta = escapeDelta[axis];
|
25457 |
|
25458 | if (!axisDelta) {
|
25459 | return;
|
25460 | }
|
25461 |
|
25462 | var dimension = axis === 'x' ? 'width' : 'height';
|
25463 |
|
25464 | var margin = axisDelta.margin,
|
25465 | rowSize = axisDelta.rowSize;
|
25466 |
|
25467 | if (margin < 0) {
|
25468 | newPosition[axis] = Math.min(
|
25469 | existingElement[axis] + margin - element[dimension] / 2,
|
25470 | position[axis] - rowSize + margin
|
25471 | );
|
25472 | } else {
|
25473 | newPosition[axis] = Math.max(
|
25474 | existingTarget[axis] + existingTarget[dimension] + margin + element[dimension] / 2,
|
25475 | position[axis] + rowSize + margin
|
25476 | );
|
25477 | }
|
25478 | });
|
25479 |
|
25480 | return newPosition;
|
25481 | }
|
25482 |
|
25483 | var existingTarget;
|
25484 |
|
25485 |
|
25486 | while ((existingTarget = getConnectedAtPosition(source, position, element))) {
|
25487 | position = nextPosition(existingTarget);
|
25488 | }
|
25489 |
|
25490 | return position;
|
25491 | }
|
25492 |
|
25493 |
|
25494 |
|
25495 |
|
25496 |
|
25497 | function noneFilter() {
|
25498 | return true;
|
25499 | }
|
25500 |
|
25501 | function getConnected(element, connectionFilter) {
|
25502 | return [].concat(
|
25503 | getTargets(element, connectionFilter),
|
25504 | getSources(element, connectionFilter)
|
25505 | );
|
25506 | }
|
25507 |
|
25508 | function getSources(shape, connectionFilter) {
|
25509 |
|
25510 | if (!connectionFilter) {
|
25511 | connectionFilter = noneFilter;
|
25512 | }
|
25513 |
|
25514 | return shape.incoming.filter(connectionFilter).map(function(c) {
|
25515 | return c.source;
|
25516 | });
|
25517 | }
|
25518 |
|
25519 | function getTargets(shape, connectionFilter) {
|
25520 |
|
25521 | if (!connectionFilter) {
|
25522 | connectionFilter = noneFilter;
|
25523 | }
|
25524 |
|
25525 | return shape.outgoing.filter(connectionFilter).map(function(c) {
|
25526 | return c.target;
|
25527 | });
|
25528 | }
|
25529 |
|
25530 | |
25531 |
|
25532 |
|
25533 |
|
25534 |
|
25535 |
|
25536 |
|
25537 | function AutoPlace(eventBus, modeling) {
|
25538 |
|
25539 | function emit(event, payload) {
|
25540 | return eventBus.fire(event, payload);
|
25541 | }
|
25542 |
|
25543 |
|
25544 | |
25545 |
|
25546 |
|
25547 |
|
25548 |
|
25549 |
|
25550 |
|
25551 |
|
25552 | this.append = function(source, shape) {
|
25553 |
|
25554 | emit('autoPlace.start', {
|
25555 | source: source,
|
25556 | shape: shape
|
25557 | });
|
25558 |
|
25559 |
|
25560 | var position = emit('autoPlace', {
|
25561 | source: source,
|
25562 | shape: shape
|
25563 | });
|
25564 |
|
25565 | if (!position) {
|
25566 | position = getNewShapePosition(source, shape);
|
25567 | }
|
25568 |
|
25569 | var newShape = modeling.appendShape(source, shape, position, source.parent);
|
25570 |
|
25571 | emit('autoPlace.end', {
|
25572 | source: source,
|
25573 | shape: newShape
|
25574 | });
|
25575 |
|
25576 | return newShape;
|
25577 | };
|
25578 |
|
25579 | }
|
25580 |
|
25581 | AutoPlace.$inject = [
|
25582 | 'eventBus',
|
25583 | 'modeling'
|
25584 | ];
|
25585 |
|
25586 | |
25587 |
|
25588 |
|
25589 |
|
25590 |
|
25591 |
|
25592 | function AutoPlaceSelectionBehavior(eventBus, selection) {
|
25593 |
|
25594 | eventBus.on('autoPlace.end', 500, function(e) {
|
25595 | selection.select(e.shape);
|
25596 | });
|
25597 |
|
25598 | }
|
25599 |
|
25600 | AutoPlaceSelectionBehavior.$inject = [
|
25601 | 'eventBus',
|
25602 | 'selection'
|
25603 | ];
|
25604 |
|
25605 | var AutoPlaceModule = {
|
25606 | __init__: [ 'autoPlaceSelectionBehavior' ],
|
25607 | autoPlace: [ 'type', AutoPlace ],
|
25608 | autoPlaceSelectionBehavior: [ 'type', AutoPlaceSelectionBehavior ]
|
25609 | };
|
25610 |
|
25611 | var DEFAULT_PRIORITY$2 = 1000;
|
25612 |
|
25613 | |
25614 |
|
25615 |
|
25616 |
|
25617 |
|
25618 |
|
25619 |
|
25620 |
|
25621 |
|
25622 |
|
25623 |
|
25624 |
|
25625 |
|
25626 |
|
25627 |
|
25628 |
|
25629 |
|
25630 |
|
25631 |
|
25632 |
|
25633 |
|
25634 |
|
25635 |
|
25636 | function CommandInterceptor(eventBus) {
|
25637 | this._eventBus = eventBus;
|
25638 | }
|
25639 |
|
25640 | CommandInterceptor.$inject = [ 'eventBus' ];
|
25641 |
|
25642 | function unwrapEvent(fn, that) {
|
25643 | return function(event) {
|
25644 | return fn.call(that || null, event.context, event.command, event);
|
25645 | };
|
25646 | }
|
25647 |
|
25648 | |
25649 |
|
25650 |
|
25651 |
|
25652 |
|
25653 |
|
25654 |
|
25655 |
|
25656 |
|
25657 |
|
25658 |
|
25659 | CommandInterceptor.prototype.on = function(events, hook, priority, handlerFn, unwrap, that) {
|
25660 |
|
25661 | if (isFunction(hook) || isNumber(hook)) {
|
25662 | that = unwrap;
|
25663 | unwrap = handlerFn;
|
25664 | handlerFn = priority;
|
25665 | priority = hook;
|
25666 | hook = null;
|
25667 | }
|
25668 |
|
25669 | if (isFunction(priority)) {
|
25670 | that = unwrap;
|
25671 | unwrap = handlerFn;
|
25672 | handlerFn = priority;
|
25673 | priority = DEFAULT_PRIORITY$2;
|
25674 | }
|
25675 |
|
25676 | if (isObject(unwrap)) {
|
25677 | that = unwrap;
|
25678 | unwrap = false;
|
25679 | }
|
25680 |
|
25681 | if (!isFunction(handlerFn)) {
|
25682 | throw new Error('handlerFn must be a function');
|
25683 | }
|
25684 |
|
25685 | if (!isArray(events)) {
|
25686 | events = [ events ];
|
25687 | }
|
25688 |
|
25689 | var eventBus = this._eventBus;
|
25690 |
|
25691 | forEach(events, function(event) {
|
25692 |
|
25693 |
|
25694 | var fullEvent = [ 'commandStack', event, hook ].filter(function(e) { return e; }).join('.');
|
25695 |
|
25696 | eventBus.on(fullEvent, priority, unwrap ? unwrapEvent(handlerFn, that) : handlerFn, that);
|
25697 | });
|
25698 | };
|
25699 |
|
25700 |
|
25701 | var hooks = [
|
25702 | 'canExecute',
|
25703 | 'preExecute',
|
25704 | 'preExecuted',
|
25705 | 'execute',
|
25706 | 'executed',
|
25707 | 'postExecute',
|
25708 | 'postExecuted',
|
25709 | 'revert',
|
25710 | 'reverted'
|
25711 | ];
|
25712 |
|
25713 | |
25714 |
|
25715 |
|
25716 |
|
25717 |
|
25718 |
|
25719 | forEach(hooks, function(hook) {
|
25720 |
|
25721 | |
25722 |
|
25723 |
|
25724 |
|
25725 |
|
25726 |
|
25727 |
|
25728 |
|
25729 |
|
25730 |
|
25731 |
|
25732 |
|
25733 | CommandInterceptor.prototype[hook] = function(events, priority, handlerFn, unwrap, that) {
|
25734 |
|
25735 | if (isFunction(events) || isNumber(events)) {
|
25736 | that = unwrap;
|
25737 | unwrap = handlerFn;
|
25738 | handlerFn = priority;
|
25739 | priority = events;
|
25740 | events = null;
|
25741 | }
|
25742 |
|
25743 | this.on(events, hook, priority, handlerFn, unwrap, that);
|
25744 | };
|
25745 | });
|
25746 |
|
25747 | |
25748 |
|
25749 |
|
25750 |
|
25751 |
|
25752 |
|
25753 |
|
25754 |
|
25755 |
|
25756 | function AutoResize(eventBus, elementRegistry, modeling, rules) {
|
25757 |
|
25758 | CommandInterceptor.call(this, eventBus);
|
25759 |
|
25760 | this._elementRegistry = elementRegistry;
|
25761 | this._modeling = modeling;
|
25762 | this._rules = rules;
|
25763 |
|
25764 | var self = this;
|
25765 |
|
25766 | this.postExecuted([ 'shape.create' ], function(event) {
|
25767 | var context = event.context,
|
25768 | hints = context.hints || {},
|
25769 | shape = context.shape,
|
25770 | parent = context.parent || context.newParent;
|
25771 |
|
25772 | if (hints.autoResize === false) {
|
25773 | return;
|
25774 | }
|
25775 |
|
25776 | self._expand([ shape ], parent);
|
25777 | });
|
25778 |
|
25779 | this.postExecuted([ 'elements.move' ], function(event) {
|
25780 | var context = event.context,
|
25781 | elements = flatten(values(context.closure.topLevel)),
|
25782 | hints = context.hints;
|
25783 |
|
25784 | var autoResize = hints ? hints.autoResize : true;
|
25785 |
|
25786 | if (autoResize === false) {
|
25787 | return;
|
25788 | }
|
25789 |
|
25790 | var expandings = groupBy(elements, function(element) {
|
25791 | return element.parent.id;
|
25792 | });
|
25793 |
|
25794 | forEach(expandings, function(elements, parentId) {
|
25795 |
|
25796 |
|
25797 | if (isArray(autoResize)) {
|
25798 | elements = elements.filter(function(element) {
|
25799 | return find(autoResize, matchPattern({ id: element.id }));
|
25800 | });
|
25801 | }
|
25802 |
|
25803 | self._expand(elements, parentId);
|
25804 | });
|
25805 | });
|
25806 |
|
25807 | this.postExecuted([ 'shape.toggleCollapse' ], function(event) {
|
25808 | var context = event.context,
|
25809 | hints = context.hints,
|
25810 | shape = context.shape;
|
25811 |
|
25812 | if (hints && hints.autoResize === false) {
|
25813 | return;
|
25814 | }
|
25815 |
|
25816 | if (shape.collapsed) {
|
25817 | return;
|
25818 | }
|
25819 |
|
25820 | self._expand(shape.children || [], shape);
|
25821 | });
|
25822 |
|
25823 | this.postExecuted([ 'shape.resize' ], function(event) {
|
25824 | var context = event.context,
|
25825 | hints = context.hints,
|
25826 | shape = context.shape,
|
25827 | parent = shape.parent;
|
25828 |
|
25829 | if (hints && hints.autoResize === false) {
|
25830 | return;
|
25831 | }
|
25832 |
|
25833 | if (parent) {
|
25834 | self._expand([ shape ], parent);
|
25835 | }
|
25836 | });
|
25837 |
|
25838 | }
|
25839 |
|
25840 | AutoResize.$inject = [
|
25841 | 'eventBus',
|
25842 | 'elementRegistry',
|
25843 | 'modeling',
|
25844 | 'rules'
|
25845 | ];
|
25846 |
|
25847 | inherits_browser(AutoResize, CommandInterceptor);
|
25848 |
|
25849 |
|
25850 | |
25851 |
|
25852 |
|
25853 |
|
25854 |
|
25855 |
|
25856 |
|
25857 |
|
25858 |
|
25859 |
|
25860 | AutoResize.prototype._getOptimalBounds = function(elements, target) {
|
25861 |
|
25862 | var offset = this.getOffset(target),
|
25863 | padding = this.getPadding(target);
|
25864 |
|
25865 | var elementsTrbl = asTRBL(getBBox(elements)),
|
25866 | targetTrbl = asTRBL(target);
|
25867 |
|
25868 | var newTrbl = {};
|
25869 |
|
25870 | if (elementsTrbl.top - targetTrbl.top < padding.top) {
|
25871 | newTrbl.top = elementsTrbl.top - offset.top;
|
25872 | }
|
25873 |
|
25874 | if (elementsTrbl.left - targetTrbl.left < padding.left) {
|
25875 | newTrbl.left = elementsTrbl.left - offset.left;
|
25876 | }
|
25877 |
|
25878 | if (targetTrbl.right - elementsTrbl.right < padding.right) {
|
25879 | newTrbl.right = elementsTrbl.right + offset.right;
|
25880 | }
|
25881 |
|
25882 | if (targetTrbl.bottom - elementsTrbl.bottom < padding.bottom) {
|
25883 | newTrbl.bottom = elementsTrbl.bottom + offset.bottom;
|
25884 | }
|
25885 |
|
25886 | return asBounds(assign({}, targetTrbl, newTrbl));
|
25887 | };
|
25888 |
|
25889 |
|
25890 | |
25891 |
|
25892 |
|
25893 |
|
25894 |
|
25895 |
|
25896 | AutoResize.prototype._expand = function(elements, target) {
|
25897 |
|
25898 | if (typeof target === 'string') {
|
25899 | target = this._elementRegistry.get(target);
|
25900 | }
|
25901 |
|
25902 | var allowed = this._rules.allowed('element.autoResize', {
|
25903 | elements: elements,
|
25904 | target: target
|
25905 | });
|
25906 |
|
25907 | if (!allowed) {
|
25908 | return;
|
25909 | }
|
25910 |
|
25911 |
|
25912 | var newBounds = this._getOptimalBounds(elements, target);
|
25913 |
|
25914 | if (!boundsChanged(newBounds, target)) {
|
25915 | return;
|
25916 | }
|
25917 |
|
25918 | var resizeDirections = getResizeDirections(pick(target, [ 'x', 'y', 'width', 'height' ]), newBounds);
|
25919 |
|
25920 |
|
25921 | this.resize(target, newBounds, {
|
25922 | autoResize: resizeDirections
|
25923 | });
|
25924 |
|
25925 | var parent = target.parent;
|
25926 |
|
25927 |
|
25928 | if (parent) {
|
25929 | this._expand([ target ], parent);
|
25930 | }
|
25931 | };
|
25932 |
|
25933 |
|
25934 | |
25935 |
|
25936 |
|
25937 |
|
25938 |
|
25939 |
|
25940 |
|
25941 | AutoResize.prototype.getOffset = function(shape) {
|
25942 | return { top: 60, bottom: 60, left: 100, right: 100 };
|
25943 | };
|
25944 |
|
25945 |
|
25946 | |
25947 |
|
25948 |
|
25949 |
|
25950 |
|
25951 |
|
25952 |
|
25953 |
|
25954 | AutoResize.prototype.getPadding = function(shape) {
|
25955 | return { top: 2, bottom: 2, left: 15, right: 15 };
|
25956 | };
|
25957 |
|
25958 |
|
25959 | |
25960 |
|
25961 |
|
25962 |
|
25963 |
|
25964 |
|
25965 |
|
25966 |
|
25967 | AutoResize.prototype.resize = function(shape, newBounds, hints) {
|
25968 | this._modeling.resizeShape(shape, newBounds, null, hints);
|
25969 | };
|
25970 |
|
25971 |
|
25972 | function boundsChanged(newBounds, oldBounds) {
|
25973 | return (
|
25974 | newBounds.x !== oldBounds.x ||
|
25975 | newBounds.y !== oldBounds.y ||
|
25976 | newBounds.width !== oldBounds.width ||
|
25977 | newBounds.height !== oldBounds.height
|
25978 | );
|
25979 | }
|
25980 |
|
25981 | |
25982 |
|
25983 |
|
25984 |
|
25985 |
|
25986 |
|
25987 |
|
25988 |
|
25989 | function getResizeDirections(oldBounds, newBounds) {
|
25990 | var directions = '';
|
25991 |
|
25992 | oldBounds = asTRBL(oldBounds);
|
25993 | newBounds = asTRBL(newBounds);
|
25994 |
|
25995 | if (oldBounds.top > newBounds.top) {
|
25996 | directions = directions.concat('n');
|
25997 | }
|
25998 |
|
25999 | if (oldBounds.right < newBounds.right) {
|
26000 | directions = directions.concat('w');
|
26001 | }
|
26002 |
|
26003 | if (oldBounds.bottom < newBounds.bottom) {
|
26004 | directions = directions.concat('s');
|
26005 | }
|
26006 |
|
26007 | if (oldBounds.left > newBounds.left) {
|
26008 | directions = directions.concat('e');
|
26009 | }
|
26010 |
|
26011 | return directions;
|
26012 | }
|
26013 |
|
26014 | |
26015 |
|
26016 |
|
26017 |
|
26018 | function BpmnAutoResize(injector) {
|
26019 |
|
26020 | injector.invoke(AutoResize, this);
|
26021 | }
|
26022 |
|
26023 | BpmnAutoResize.$inject = [
|
26024 | 'injector'
|
26025 | ];
|
26026 |
|
26027 | inherits_browser(BpmnAutoResize, AutoResize);
|
26028 |
|
26029 |
|
26030 | |
26031 |
|
26032 |
|
26033 |
|
26034 |
|
26035 |
|
26036 |
|
26037 | BpmnAutoResize.prototype.resize = function(target, newBounds, hints) {
|
26038 |
|
26039 | if (is$1(target, 'bpmn:Participant')) {
|
26040 | this._modeling.resizeLane(target, newBounds, null, hints);
|
26041 | } else {
|
26042 | this._modeling.resizeShape(target, newBounds, null, hints);
|
26043 | }
|
26044 | };
|
26045 |
|
26046 | |
26047 |
|
26048 |
|
26049 |
|
26050 |
|
26051 |
|
26052 |
|
26053 |
|
26054 | function RuleProvider(eventBus) {
|
26055 | CommandInterceptor.call(this, eventBus);
|
26056 |
|
26057 | this.init();
|
26058 | }
|
26059 |
|
26060 | RuleProvider.$inject = [ 'eventBus' ];
|
26061 |
|
26062 | inherits_browser(RuleProvider, CommandInterceptor);
|
26063 |
|
26064 |
|
26065 | |
26066 |
|
26067 |
|
26068 |
|
26069 |
|
26070 |
|
26071 |
|
26072 |
|
26073 |
|
26074 |
|
26075 |
|
26076 |
|
26077 |
|
26078 |
|
26079 |
|
26080 |
|
26081 |
|
26082 |
|
26083 |
|
26084 |
|
26085 |
|
26086 |
|
26087 |
|
26088 |
|
26089 |
|
26090 |
|
26091 |
|
26092 |
|
26093 |
|
26094 |
|
26095 |
|
26096 |
|
26097 |
|
26098 |
|
26099 |
|
26100 |
|
26101 |
|
26102 |
|
26103 |
|
26104 |
|
26105 |
|
26106 |
|
26107 |
|
26108 |
|
26109 | RuleProvider.prototype.addRule = function(actions, priority, fn) {
|
26110 |
|
26111 | var self = this;
|
26112 |
|
26113 | if (typeof actions === 'string') {
|
26114 | actions = [ actions ];
|
26115 | }
|
26116 |
|
26117 | actions.forEach(function(action) {
|
26118 |
|
26119 | self.canExecute(action, priority, function(context, action, event) {
|
26120 | return fn(context);
|
26121 | }, true);
|
26122 | });
|
26123 | };
|
26124 |
|
26125 | |
26126 |
|
26127 |
|
26128 | RuleProvider.prototype.init = function() {};
|
26129 |
|
26130 | |
26131 |
|
26132 |
|
26133 | function AutoResizeProvider(eventBus) {
|
26134 |
|
26135 | RuleProvider.call(this, eventBus);
|
26136 |
|
26137 | var self = this;
|
26138 |
|
26139 | this.addRule('element.autoResize', function(context) {
|
26140 | return self.canResize(context.elements, context.target);
|
26141 | });
|
26142 | }
|
26143 |
|
26144 | AutoResizeProvider.$inject = [ 'eventBus' ];
|
26145 |
|
26146 | inherits_browser(AutoResizeProvider, RuleProvider);
|
26147 |
|
26148 | |
26149 |
|
26150 |
|
26151 |
|
26152 |
|
26153 |
|
26154 |
|
26155 |
|
26156 | AutoResizeProvider.prototype.canResize = function(elements, target) {
|
26157 | return false;
|
26158 | };
|
26159 |
|
26160 | |
26161 |
|
26162 |
|
26163 | function BpmnAutoResizeProvider(eventBus, modeling) {
|
26164 | AutoResizeProvider.call(this, eventBus);
|
26165 |
|
26166 | this._modeling = modeling;
|
26167 | }
|
26168 |
|
26169 | inherits_browser(BpmnAutoResizeProvider, AutoResizeProvider);
|
26170 |
|
26171 | BpmnAutoResizeProvider.$inject = [
|
26172 | 'eventBus',
|
26173 | 'modeling'
|
26174 | ];
|
26175 |
|
26176 |
|
26177 | |
26178 |
|
26179 |
|
26180 |
|
26181 |
|
26182 |
|
26183 |
|
26184 | BpmnAutoResizeProvider.prototype.canResize = function(elements, target) {
|
26185 |
|
26186 | if (!is$1(target, 'bpmn:Participant') && !is$1(target, 'bpmn:Lane') && !(is$1(target, 'bpmn:SubProcess'))) {
|
26187 | return false;
|
26188 | }
|
26189 |
|
26190 | var canResize = true;
|
26191 |
|
26192 | forEach(elements, function(element) {
|
26193 |
|
26194 | if (is$1(element, 'bpmn:Lane') || element.labelTarget) {
|
26195 | canResize = false;
|
26196 | return;
|
26197 | }
|
26198 | });
|
26199 |
|
26200 | return canResize;
|
26201 | };
|
26202 |
|
26203 | var AutoResizeModule = {
|
26204 | __init__: [
|
26205 | 'bpmnAutoResize',
|
26206 | 'bpmnAutoResizeProvider'
|
26207 | ],
|
26208 | bpmnAutoResize: [ 'type', BpmnAutoResize ],
|
26209 | bpmnAutoResizeProvider: [ 'type', BpmnAutoResizeProvider ]
|
26210 | };
|
26211 |
|
26212 |
|
26213 |
|
26214 | var round$1 = Math.round;
|
26215 |
|
26216 | var DRAG_ACTIVE_CLS = 'djs-drag-active';
|
26217 |
|
26218 |
|
26219 | function preventDefault(event) {
|
26220 | event.preventDefault();
|
26221 | }
|
26222 |
|
26223 | function isTouchEvent(event) {
|
26224 |
|
26225 |
|
26226 |
|
26227 | return typeof TouchEvent !== 'undefined' && event instanceof TouchEvent;
|
26228 | }
|
26229 |
|
26230 | function getLength(point) {
|
26231 | return Math.sqrt(Math.pow(point.x, 2) + Math.pow(point.y, 2));
|
26232 | }
|
26233 |
|
26234 | |
26235 |
|
26236 |
|
26237 |
|
26238 |
|
26239 |
|
26240 |
|
26241 |
|
26242 |
|
26243 |
|
26244 |
|
26245 |
|
26246 |
|
26247 |
|
26248 |
|
26249 |
|
26250 |
|
26251 |
|
26252 |
|
26253 |
|
26254 |
|
26255 |
|
26256 |
|
26257 |
|
26258 |
|
26259 |
|
26260 |
|
26261 |
|
26262 |
|
26263 |
|
26264 |
|
26265 |
|
26266 |
|
26267 |
|
26268 |
|
26269 |
|
26270 |
|
26271 |
|
26272 |
|
26273 |
|
26274 |
|
26275 |
|
26276 |
|
26277 |
|
26278 |
|
26279 |
|
26280 |
|
26281 |
|
26282 |
|
26283 |
|
26284 |
|
26285 |
|
26286 |
|
26287 |
|
26288 |
|
26289 |
|
26290 |
|
26291 |
|
26292 |
|
26293 |
|
26294 |
|
26295 |
|
26296 |
|
26297 |
|
26298 |
|
26299 |
|
26300 |
|
26301 |
|
26302 |
|
26303 |
|
26304 |
|
26305 |
|
26306 |
|
26307 |
|
26308 |
|
26309 |
|
26310 |
|
26311 |
|
26312 | function Dragging(eventBus, canvas, selection, elementRegistry) {
|
26313 |
|
26314 | var defaultOptions = {
|
26315 | threshold: 5,
|
26316 | trapClick: true
|
26317 | };
|
26318 |
|
26319 |
|
26320 |
|
26321 |
|
26322 |
|
26323 | var context;
|
26324 |
|
26325 |
|
26326 | function toLocalPoint(globalPosition) {
|
26327 |
|
26328 | var viewbox = canvas.viewbox();
|
26329 |
|
26330 | var clientRect = canvas._container.getBoundingClientRect();
|
26331 |
|
26332 | return {
|
26333 | x: viewbox.x + (globalPosition.x - clientRect.left) / viewbox.scale,
|
26334 | y: viewbox.y + (globalPosition.y - clientRect.top) / viewbox.scale
|
26335 | };
|
26336 | }
|
26337 |
|
26338 |
|
26339 |
|
26340 | function fire(type, dragContext) {
|
26341 | dragContext = dragContext || context;
|
26342 |
|
26343 | var event = eventBus.createEvent(
|
26344 | assign(
|
26345 | {},
|
26346 | dragContext.payload,
|
26347 | dragContext.data,
|
26348 | { isTouch: dragContext.isTouch }
|
26349 | )
|
26350 | );
|
26351 |
|
26352 |
|
26353 | if (eventBus.fire('drag.' + type, event) === false) {
|
26354 | return false;
|
26355 | }
|
26356 |
|
26357 | return eventBus.fire(dragContext.prefix + '.' + type, event);
|
26358 | }
|
26359 |
|
26360 | function restoreSelection(previousSelection) {
|
26361 | var existingSelection = previousSelection.filter(function(element) {
|
26362 | return elementRegistry.get(element.id);
|
26363 | });
|
26364 |
|
26365 | existingSelection.length && selection.select(existingSelection);
|
26366 | }
|
26367 |
|
26368 |
|
26369 |
|
26370 | function move(event, activate) {
|
26371 | var payload = context.payload,
|
26372 | displacement = context.displacement;
|
26373 |
|
26374 | var globalStart = context.globalStart,
|
26375 | globalCurrent = toPoint(event),
|
26376 | globalDelta = delta(globalCurrent, globalStart);
|
26377 |
|
26378 | var localStart = context.localStart,
|
26379 | localCurrent = toLocalPoint(globalCurrent),
|
26380 | localDelta = delta(localCurrent, localStart);
|
26381 |
|
26382 |
|
26383 |
|
26384 | if (!context.active && (activate || getLength(globalDelta) > context.threshold)) {
|
26385 |
|
26386 |
|
26387 |
|
26388 |
|
26389 | assign(payload, {
|
26390 | x: round$1(localStart.x + displacement.x),
|
26391 | y: round$1(localStart.y + displacement.y),
|
26392 | dx: 0,
|
26393 | dy: 0
|
26394 | }, { originalEvent: event });
|
26395 |
|
26396 | if (false === fire('start')) {
|
26397 | return cancel();
|
26398 | }
|
26399 |
|
26400 | context.active = true;
|
26401 |
|
26402 |
|
26403 |
|
26404 |
|
26405 | if (!context.keepSelection) {
|
26406 | payload.previousSelection = selection.get();
|
26407 | selection.select(null);
|
26408 | }
|
26409 |
|
26410 |
|
26411 | if (context.cursor) {
|
26412 | set$1(context.cursor);
|
26413 | }
|
26414 |
|
26415 | // indicate dragging via marker on root element
|
26416 | canvas.addMarker(canvas.getRootElement(), DRAG_ACTIVE_CLS);
|
26417 | }
|
26418 |
|
26419 | stopPropagation(event);
|
26420 |
|
26421 | if (context.active) {
|
26422 |
|
26423 |
|
26424 | assign(payload, {
|
26425 | x: round$1(localCurrent.x + displacement.x),
|
26426 | y: round$1(localCurrent.y + displacement.y),
|
26427 | dx: round$1(localDelta.x),
|
26428 | dy: round$1(localDelta.y)
|
26429 | }, { originalEvent: event });
|
26430 |
|
26431 |
|
26432 | fire('move');
|
26433 | }
|
26434 | }
|
26435 |
|
26436 | function end(event) {
|
26437 | var previousContext,
|
26438 | returnValue = true;
|
26439 |
|
26440 | if (context.active) {
|
26441 |
|
26442 | if (event) {
|
26443 | context.payload.originalEvent = event;
|
26444 |
|
26445 |
|
26446 |
|
26447 | stopPropagation(event);
|
26448 | }
|
26449 |
|
26450 |
|
26451 |
|
26452 |
|
26453 | returnValue = fire('end');
|
26454 | }
|
26455 |
|
26456 | if (returnValue === false) {
|
26457 | fire('rejected');
|
26458 | }
|
26459 |
|
26460 | previousContext = cleanup(returnValue !== true);
|
26461 |
|
26462 |
|
26463 |
|
26464 | fire('ended', previousContext);
|
26465 | }
|
26466 |
|
26467 |
|
26468 |
|
26469 |
|
26470 |
|
26471 | function checkCancel(event) {
|
26472 |
|
26473 | if (event.which === 27) {
|
26474 | preventDefault(event);
|
26475 |
|
26476 | cancel();
|
26477 | }
|
26478 | }
|
26479 |
|
26480 |
|
26481 |
|
26482 |
|
26483 |
|
26484 | function trapClickAndEnd(event) {
|
26485 |
|
26486 | var untrap;
|
26487 |
|
26488 |
|
26489 |
|
26490 |
|
26491 | if (context.active) {
|
26492 |
|
26493 | untrap = install(eventBus);
|
26494 |
|
26495 |
|
26496 | setTimeout(untrap, 400);
|
26497 |
|
26498 |
|
26499 | preventDefault(event);
|
26500 | }
|
26501 |
|
26502 | end(event);
|
26503 | }
|
26504 |
|
26505 | function trapTouch(event) {
|
26506 | move(event);
|
26507 | }
|
26508 |
|
26509 |
|
26510 |
|
26511 |
|
26512 |
|
26513 | function hover(event) {
|
26514 | var payload = context.payload;
|
26515 |
|
26516 | payload.hoverGfx = event.gfx;
|
26517 | payload.hover = event.element;
|
26518 |
|
26519 | fire('hover');
|
26520 | }
|
26521 |
|
26522 | function out(event) {
|
26523 | fire('out');
|
26524 |
|
26525 | var payload = context.payload;
|
26526 |
|
26527 | payload.hoverGfx = null;
|
26528 | payload.hover = null;
|
26529 | }
|
26530 |
|
26531 |
|
26532 |
|
26533 |
|
26534 | function cancel(restore) {
|
26535 | var previousContext;
|
26536 |
|
26537 | if (!context) {
|
26538 | return;
|
26539 | }
|
26540 |
|
26541 | var wasActive = context.active;
|
26542 |
|
26543 | if (wasActive) {
|
26544 | fire('cancel');
|
26545 | }
|
26546 |
|
26547 | previousContext = cleanup(restore);
|
26548 |
|
26549 | if (wasActive) {
|
26550 |
|
26551 |
|
26552 |
|
26553 | fire('canceled', previousContext);
|
26554 | }
|
26555 | }
|
26556 |
|
26557 | function cleanup(restore) {
|
26558 | var previousContext,
|
26559 | endDrag;
|
26560 |
|
26561 | fire('cleanup');
|
26562 |
|
26563 |
|
26564 | unset();
|
26565 |
|
26566 | if (context.trapClick) {
|
26567 | endDrag = trapClickAndEnd;
|
26568 | } else {
|
26569 | endDrag = end;
|
26570 | }
|
26571 |
|
26572 |
|
26573 | componentEvent.unbind(document, 'mousemove', move);
|
26574 |
|
26575 | componentEvent.unbind(document, 'dragstart', preventDefault);
|
26576 | componentEvent.unbind(document, 'selectstart', preventDefault);
|
26577 |
|
26578 | componentEvent.unbind(document, 'mousedown', endDrag, true);
|
26579 | componentEvent.unbind(document, 'mouseup', endDrag, true);
|
26580 |
|
26581 | componentEvent.unbind(document, 'keyup', checkCancel);
|
26582 |
|
26583 | componentEvent.unbind(document, 'touchstart', trapTouch, true);
|
26584 | componentEvent.unbind(document, 'touchcancel', cancel, true);
|
26585 | componentEvent.unbind(document, 'touchmove', move, true);
|
26586 | componentEvent.unbind(document, 'touchend', end, true);
|
26587 |
|
26588 | eventBus.off('element.hover', hover);
|
26589 | eventBus.off('element.out', out);
|
26590 |
|
26591 |
|
26592 | canvas.removeMarker(canvas.getRootElement(), DRAG_ACTIVE_CLS);
|
26593 |
|
26594 |
|
26595 | var previousSelection = context.payload.previousSelection;
|
26596 |
|
26597 | if (restore !== false && previousSelection && !selection.get().length) {
|
26598 | restoreSelection(previousSelection);
|
26599 | }
|
26600 |
|
26601 | previousContext = context;
|
26602 |
|
26603 | context = null;
|
26604 |
|
26605 | return previousContext;
|
26606 | }
|
26607 |
|
26608 | |
26609 |
|
26610 |
|
26611 |
|
26612 |
|
26613 |
|
26614 |
|
26615 |
|
26616 |
|
26617 |
|
26618 |
|
26619 | function init(event, relativeTo, prefix, options) {
|
26620 |
|
26621 |
|
26622 | if (context) {
|
26623 | cancel(false);
|
26624 | }
|
26625 |
|
26626 | if (typeof relativeTo === 'string') {
|
26627 | options = prefix;
|
26628 | prefix = relativeTo;
|
26629 | relativeTo = null;
|
26630 | }
|
26631 |
|
26632 | options = assign({}, defaultOptions, options || {});
|
26633 |
|
26634 | var data = options.data || {},
|
26635 | originalEvent,
|
26636 | globalStart,
|
26637 | localStart,
|
26638 | endDrag,
|
26639 | isTouch;
|
26640 |
|
26641 | if (options.trapClick) {
|
26642 | endDrag = trapClickAndEnd;
|
26643 | } else {
|
26644 | endDrag = end;
|
26645 | }
|
26646 |
|
26647 | if (event) {
|
26648 | originalEvent = getOriginal(event) || event;
|
26649 | globalStart = toPoint(event);
|
26650 |
|
26651 | stopPropagation(event);
|
26652 |
|
26653 |
|
26654 | if (originalEvent.type === 'dragstart') {
|
26655 | preventDefault(originalEvent);
|
26656 | }
|
26657 | } else {
|
26658 | originalEvent = null;
|
26659 | globalStart = { x: 0, y: 0 };
|
26660 | }
|
26661 |
|
26662 | localStart = toLocalPoint(globalStart);
|
26663 |
|
26664 | if (!relativeTo) {
|
26665 | relativeTo = localStart;
|
26666 | }
|
26667 |
|
26668 | isTouch = isTouchEvent(originalEvent);
|
26669 |
|
26670 | context = assign({
|
26671 | prefix: prefix,
|
26672 | data: data,
|
26673 | payload: {},
|
26674 | globalStart: globalStart,
|
26675 | displacement: delta(relativeTo, localStart),
|
26676 | localStart: localStart,
|
26677 | isTouch: isTouch
|
26678 | }, options);
|
26679 |
|
26680 |
|
26681 |
|
26682 | if (!options.manual) {
|
26683 |
|
26684 |
|
26685 |
|
26686 | if (isTouch) {
|
26687 | componentEvent.bind(document, 'touchstart', trapTouch, true);
|
26688 | componentEvent.bind(document, 'touchcancel', cancel, true);
|
26689 | componentEvent.bind(document, 'touchmove', move, true);
|
26690 | componentEvent.bind(document, 'touchend', end, true);
|
26691 | } else {
|
26692 |
|
26693 |
|
26694 | componentEvent.bind(document, 'mousemove', move);
|
26695 |
|
26696 |
|
26697 | componentEvent.bind(document, 'dragstart', preventDefault);
|
26698 | componentEvent.bind(document, 'selectstart', preventDefault);
|
26699 |
|
26700 | componentEvent.bind(document, 'mousedown', endDrag, true);
|
26701 | componentEvent.bind(document, 'mouseup', endDrag, true);
|
26702 | }
|
26703 |
|
26704 | componentEvent.bind(document, 'keyup', checkCancel);
|
26705 |
|
26706 | eventBus.on('element.hover', hover);
|
26707 | eventBus.on('element.out', out);
|
26708 | }
|
26709 |
|
26710 | fire('init');
|
26711 |
|
26712 | if (options.autoActivate) {
|
26713 | move(event, true);
|
26714 | }
|
26715 | }
|
26716 |
|
26717 |
|
26718 | eventBus.on('diagram.destroy', cancel);
|
26719 |
|
26720 |
|
26721 |
|
26722 |
|
26723 | this.init = init;
|
26724 | this.move = move;
|
26725 | this.hover = hover;
|
26726 | this.out = out;
|
26727 | this.end = end;
|
26728 |
|
26729 | this.cancel = cancel;
|
26730 |
|
26731 |
|
26732 |
|
26733 | this.context = function() {
|
26734 | return context;
|
26735 | };
|
26736 |
|
26737 | this.setOptions = function(options) {
|
26738 | assign(defaultOptions, options);
|
26739 | };
|
26740 | }
|
26741 |
|
26742 | Dragging.$inject = [
|
26743 | 'eventBus',
|
26744 | 'canvas',
|
26745 | 'selection',
|
26746 | 'elementRegistry'
|
26747 | ];
|
26748 |
|
26749 | var HIGH_PRIORITY = 1500;
|
26750 |
|
26751 |
|
26752 | |
26753 |
|
26754 |
|
26755 |
|
26756 |
|
26757 |
|
26758 |
|
26759 |
|
26760 |
|
26761 |
|
26762 |
|
26763 |
|
26764 |
|
26765 |
|
26766 |
|
26767 | function HoverFix(eventBus, dragging, elementRegistry) {
|
26768 |
|
26769 | var self = this;
|
26770 |
|
26771 | |
26772 |
|
26773 |
|
26774 |
|
26775 |
|
26776 | function ensureHover(event) {
|
26777 |
|
26778 | if (event.hover) {
|
26779 | return;
|
26780 | }
|
26781 |
|
26782 | var originalEvent = event.originalEvent;
|
26783 |
|
26784 | var gfx = self._findTargetGfx(originalEvent);
|
26785 |
|
26786 | var element = gfx && elementRegistry.get(gfx);
|
26787 |
|
26788 | if (gfx && element) {
|
26789 |
|
26790 |
|
26791 | event.stopPropagation();
|
26792 |
|
26793 |
|
26794 | dragging.hover({ element: element, gfx: gfx });
|
26795 |
|
26796 |
|
26797 | dragging.move(originalEvent);
|
26798 | }
|
26799 | }
|
26800 |
|
26801 | |
26802 |
|
26803 |
|
26804 |
|
26805 |
|
26806 |
|
26807 |
|
26808 |
|
26809 |
|
26810 | eventBus.on('drag.start', function(event) {
|
26811 |
|
26812 | eventBus.once('drag.move', HIGH_PRIORITY, function(event) {
|
26813 |
|
26814 | ensureHover(event);
|
26815 |
|
26816 | });
|
26817 |
|
26818 | });
|
26819 |
|
26820 |
|
26821 | |
26822 |
|
26823 |
|
26824 |
|
26825 |
|
26826 |
|
26827 |
|
26828 |
|
26829 |
|
26830 |
|
26831 | eventBus.on('drag.init', function() {
|
26832 |
|
26833 | var hover, hoverGfx;
|
26834 |
|
26835 | function setDragHover(event) {
|
26836 | hover = event.hover;
|
26837 | hoverGfx = event.hoverGfx;
|
26838 | }
|
26839 |
|
26840 | function unsetHover() {
|
26841 | hover = null;
|
26842 | hoverGfx = null;
|
26843 | }
|
26844 |
|
26845 | function ensureOut() {
|
26846 |
|
26847 | if (!hover) {
|
26848 | return;
|
26849 | }
|
26850 |
|
26851 | var element = hover,
|
26852 | gfx = hoverGfx;
|
26853 |
|
26854 | hover = null;
|
26855 | hoverGfx = null;
|
26856 |
|
26857 |
|
26858 | dragging.out({
|
26859 | element: element,
|
26860 | gfx: gfx
|
26861 | });
|
26862 | }
|
26863 |
|
26864 | eventBus.on('drag.hover', setDragHover);
|
26865 | eventBus.on('element.out', unsetHover);
|
26866 | eventBus.on('element.hover', HIGH_PRIORITY, ensureOut);
|
26867 |
|
26868 | eventBus.once('drag.cleanup', function() {
|
26869 | eventBus.off('drag.hover', setDragHover);
|
26870 | eventBus.off('element.out', unsetHover);
|
26871 | eventBus.off('element.hover', ensureOut);
|
26872 | });
|
26873 |
|
26874 | });
|
26875 |
|
26876 | this._findTargetGfx = function(event) {
|
26877 | var position,
|
26878 | target;
|
26879 |
|
26880 | if (!(event instanceof MouseEvent)) {
|
26881 | return;
|
26882 | }
|
26883 |
|
26884 | position = toPoint(event);
|
26885 |
|
26886 |
|
26887 | target = document.elementFromPoint(position.x, position.y);
|
26888 |
|
26889 | return getGfx(target);
|
26890 | };
|
26891 |
|
26892 | }
|
26893 |
|
26894 | HoverFix.$inject = [
|
26895 | 'eventBus',
|
26896 | 'dragging',
|
26897 | 'elementRegistry'
|
26898 | ];
|
26899 |
|
26900 |
|
26901 |
|
26902 |
|
26903 | function getGfx(target) {
|
26904 | return closest(target, 'svg, .djs-element', true);
|
26905 | }
|
26906 |
|
26907 | var DraggingModule = {
|
26908 | __init__: [
|
26909 | 'hoverFix'
|
26910 | ],
|
26911 | __depends__: [
|
26912 | SelectionModule
|
26913 | ],
|
26914 | dragging: [ 'type', Dragging ],
|
26915 | hoverFix: [ 'type', HoverFix ]
|
26916 | };
|
26917 |
|
26918 | |
26919 |
|
26920 |
|
26921 |
|
26922 |
|
26923 |
|
26924 |
|
26925 |
|
26926 |
|
26927 |
|
26928 |
|
26929 |
|
26930 |
|
26931 |
|
26932 | function AutoScroll(config, eventBus, canvas) {
|
26933 |
|
26934 | this._canvas = canvas;
|
26935 |
|
26936 | this._opts = assign({
|
26937 | scrollThresholdIn: [ 20, 20, 20, 20 ],
|
26938 | scrollThresholdOut: [ 0, 0, 0, 0 ],
|
26939 | scrollRepeatTimeout: 15,
|
26940 | scrollStep: 10
|
26941 | }, config);
|
26942 |
|
26943 | var self = this;
|
26944 |
|
26945 | eventBus.on('drag.move', function(e) {
|
26946 | var point = self._toBorderPoint(e);
|
26947 |
|
26948 | self.startScroll(point);
|
26949 | });
|
26950 |
|
26951 | eventBus.on([ 'drag.cleanup' ], function() {
|
26952 | self.stopScroll();
|
26953 | });
|
26954 | }
|
26955 |
|
26956 | AutoScroll.$inject = [
|
26957 | 'config.autoScroll',
|
26958 | 'eventBus',
|
26959 | 'canvas'
|
26960 | ];
|
26961 |
|
26962 |
|
26963 | |
26964 |
|
26965 |
|
26966 |
|
26967 |
|
26968 |
|
26969 | AutoScroll.prototype.startScroll = function(point) {
|
26970 |
|
26971 | var canvas = this._canvas;
|
26972 | var opts = this._opts;
|
26973 | var self = this;
|
26974 |
|
26975 | var clientRect = canvas.getContainer().getBoundingClientRect();
|
26976 |
|
26977 | var diff = [
|
26978 | point.x,
|
26979 | point.y,
|
26980 | clientRect.width - point.x,
|
26981 | clientRect.height - point.y
|
26982 | ];
|
26983 |
|
26984 | this.stopScroll();
|
26985 |
|
26986 | var dx = 0,
|
26987 | dy = 0;
|
26988 |
|
26989 | for (var i = 0; i < 4; i++) {
|
26990 | if (between(diff[i], opts.scrollThresholdOut[i], opts.scrollThresholdIn[i])) {
|
26991 | if (i === 0) {
|
26992 | dx = opts.scrollStep;
|
26993 | } else if (i == 1) {
|
26994 | dy = opts.scrollStep;
|
26995 | } else if (i == 2) {
|
26996 | dx = -opts.scrollStep;
|
26997 | } else if (i == 3) {
|
26998 | dy = -opts.scrollStep;
|
26999 | }
|
27000 | }
|
27001 | }
|
27002 |
|
27003 | if (dx !== 0 || dy !== 0) {
|
27004 | canvas.scroll({ dx: dx, dy: dy });
|
27005 |
|
27006 | this._scrolling = setTimeout(function() {
|
27007 | self.startScroll(point);
|
27008 | }, opts.scrollRepeatTimeout);
|
27009 | }
|
27010 | };
|
27011 |
|
27012 | function between(val, start, end) {
|
27013 | if (start < val && val < end) {
|
27014 | return true;
|
27015 | }
|
27016 |
|
27017 | return false;
|
27018 | }
|
27019 |
|
27020 |
|
27021 | |
27022 |
|
27023 |
|
27024 | AutoScroll.prototype.stopScroll = function() {
|
27025 | clearTimeout(this._scrolling);
|
27026 | };
|
27027 |
|
27028 |
|
27029 | |
27030 |
|
27031 |
|
27032 |
|
27033 |
|
27034 | AutoScroll.prototype.setOptions = function(options) {
|
27035 | this._opts = assign({}, this._opts, options);
|
27036 | };
|
27037 |
|
27038 |
|
27039 | |
27040 |
|
27041 |
|
27042 |
|
27043 |
|
27044 |
|
27045 | AutoScroll.prototype._toBorderPoint = function(event) {
|
27046 | var clientRect = this._canvas._container.getBoundingClientRect();
|
27047 |
|
27048 | var globalPosition = toPoint(event.originalEvent);
|
27049 |
|
27050 | return {
|
27051 | x: globalPosition.x - clientRect.left,
|
27052 | y: globalPosition.y - clientRect.top
|
27053 | };
|
27054 | };
|
27055 |
|
27056 | var AutoScrollModule = {
|
27057 | __depends__: [
|
27058 | DraggingModule,
|
27059 | ],
|
27060 | __init__: [ 'autoScroll' ],
|
27061 | autoScroll: [ 'type', AutoScroll ]
|
27062 | };
|
27063 |
|
27064 | |
27065 |
|
27066 |
|
27067 |
|
27068 |
|
27069 |
|
27070 |
|
27071 |
|
27072 |
|
27073 |
|
27074 |
|
27075 |
|
27076 |
|
27077 |
|
27078 | function Rules(injector) {
|
27079 | this._commandStack = injector.get('commandStack', false);
|
27080 | }
|
27081 |
|
27082 | Rules.$inject = [ 'injector' ];
|
27083 |
|
27084 |
|
27085 | |
27086 |
|
27087 |
|
27088 |
|
27089 |
|
27090 |
|
27091 |
|
27092 |
|
27093 |
|
27094 |
|
27095 |
|
27096 |
|
27097 |
|
27098 | Rules.prototype.allowed = function(action, context) {
|
27099 | var allowed = true;
|
27100 |
|
27101 | var commandStack = this._commandStack;
|
27102 |
|
27103 | if (commandStack) {
|
27104 | allowed = commandStack.canExecute(action, context);
|
27105 | }
|
27106 |
|
27107 |
|
27108 | return allowed === undefined ? true : allowed;
|
27109 | };
|
27110 |
|
27111 | var RulesModule = {
|
27112 | __init__: [ 'rules' ],
|
27113 | rules: [ 'type', Rules ]
|
27114 | };
|
27115 |
|
27116 | var round$2 = Math.round,
|
27117 | max = Math.max;
|
27118 |
|
27119 |
|
27120 | function circlePath(center, r) {
|
27121 | var x = center.x,
|
27122 | y = center.y;
|
27123 |
|
27124 | return [
|
27125 | ['M', x, y],
|
27126 | ['m', 0, -r],
|
27127 | ['a', r, r, 0, 1, 1, 0, 2 * r],
|
27128 | ['a', r, r, 0, 1, 1, 0, -2 * r],
|
27129 | ['z']
|
27130 | ];
|
27131 | }
|
27132 |
|
27133 | function linePath(points) {
|
27134 | var segments = [];
|
27135 |
|
27136 | points.forEach(function(p, idx) {
|
27137 | segments.push([ idx === 0 ? 'M' : 'L', p.x, p.y ]);
|
27138 | });
|
27139 |
|
27140 | return segments;
|
27141 | }
|
27142 |
|
27143 |
|
27144 | var INTERSECTION_THRESHOLD = 10;
|
27145 |
|
27146 | function getBendpointIntersection(waypoints, reference) {
|
27147 |
|
27148 | var i, w;
|
27149 |
|
27150 | for (i = 0; (w = waypoints[i]); i++) {
|
27151 |
|
27152 | if (pointDistance(w, reference) <= INTERSECTION_THRESHOLD) {
|
27153 | return {
|
27154 | point: waypoints[i],
|
27155 | bendpoint: true,
|
27156 | index: i
|
27157 | };
|
27158 | }
|
27159 | }
|
27160 |
|
27161 | return null;
|
27162 | }
|
27163 |
|
27164 | function getPathIntersection(waypoints, reference) {
|
27165 |
|
27166 | var intersections = intersect(circlePath(reference, INTERSECTION_THRESHOLD), linePath(waypoints));
|
27167 |
|
27168 | var a = intersections[0],
|
27169 | b = intersections[intersections.length - 1],
|
27170 | idx;
|
27171 |
|
27172 | if (!a) {
|
27173 |
|
27174 |
|
27175 | return null;
|
27176 | }
|
27177 |
|
27178 | if (a !== b) {
|
27179 |
|
27180 | if (a.segment2 !== b.segment2) {
|
27181 |
|
27182 |
|
27183 |
|
27184 |
|
27185 | idx = max(a.segment2, b.segment2) - 1;
|
27186 |
|
27187 | return {
|
27188 | point: waypoints[idx],
|
27189 | bendpoint: true,
|
27190 | index: idx
|
27191 | };
|
27192 | }
|
27193 |
|
27194 | return {
|
27195 | point: {
|
27196 | x: (round$2(a.x + b.x) / 2),
|
27197 | y: (round$2(a.y + b.y) / 2)
|
27198 | },
|
27199 | index: a.segment2
|
27200 | };
|
27201 | }
|
27202 |
|
27203 | return {
|
27204 | point: {
|
27205 | x: round$2(a.x),
|
27206 | y: round$2(a.y)
|
27207 | },
|
27208 | index: a.segment2
|
27209 | };
|
27210 | }
|
27211 |
|
27212 | |
27213 |
|
27214 |
|
27215 |
|
27216 |
|
27217 |
|
27218 |
|
27219 |
|
27220 | function getApproxIntersection(waypoints, reference) {
|
27221 | return getBendpointIntersection(waypoints, reference) || getPathIntersection(waypoints, reference);
|
27222 | }
|
27223 |
|
27224 | var BENDPOINT_CLS = 'djs-bendpoint';
|
27225 | var SEGMENT_DRAGGER_CLS = 'djs-segment-dragger';
|
27226 |
|
27227 | function toCanvasCoordinates(canvas, event) {
|
27228 |
|
27229 | var position = toPoint(event),
|
27230 | clientRect = canvas._container.getBoundingClientRect(),
|
27231 | offset;
|
27232 |
|
27233 |
|
27234 |
|
27235 | offset = {
|
27236 | x: clientRect.left,
|
27237 | y: clientRect.top
|
27238 | };
|
27239 |
|
27240 |
|
27241 |
|
27242 | var viewbox = canvas.viewbox();
|
27243 |
|
27244 | return {
|
27245 | x: viewbox.x + (position.x - offset.x) / viewbox.scale,
|
27246 | y: viewbox.y + (position.y - offset.y) / viewbox.scale
|
27247 | };
|
27248 | }
|
27249 |
|
27250 | function getConnectionIntersection(canvas, waypoints, event) {
|
27251 | var localPosition = toCanvasCoordinates(canvas, event),
|
27252 | intersection = getApproxIntersection(waypoints, localPosition);
|
27253 |
|
27254 | return intersection;
|
27255 | }
|
27256 |
|
27257 | function addBendpoint(parentGfx, cls) {
|
27258 | var groupGfx = create('g');
|
27259 | classes$1(groupGfx).add(BENDPOINT_CLS);
|
27260 |
|
27261 | append(parentGfx, groupGfx);
|
27262 |
|
27263 | var visual = create('circle');
|
27264 | attr$1(visual, {
|
27265 | cx: 0,
|
27266 | cy: 0,
|
27267 | r: 4
|
27268 | });
|
27269 | classes$1(visual).add('djs-visual');
|
27270 |
|
27271 | append(groupGfx, visual);
|
27272 |
|
27273 | var hit = create('circle');
|
27274 | attr$1(hit, {
|
27275 | cx: 0,
|
27276 | cy: 0,
|
27277 | r: 10
|
27278 | });
|
27279 | classes$1(hit).add('djs-hit');
|
27280 |
|
27281 | append(groupGfx, hit);
|
27282 |
|
27283 | if (cls) {
|
27284 | classes$1(groupGfx).add(cls);
|
27285 | }
|
27286 |
|
27287 | return groupGfx;
|
27288 | }
|
27289 |
|
27290 | function createParallelDragger(parentGfx, segmentStart, segmentEnd, alignment) {
|
27291 | var draggerGfx = create('g');
|
27292 |
|
27293 | append(parentGfx, draggerGfx);
|
27294 |
|
27295 | var width = 14,
|
27296 | height = 3,
|
27297 | padding = 6,
|
27298 | hitWidth = calculateHitWidth(segmentStart, segmentEnd, alignment),
|
27299 | hitHeight = height + padding;
|
27300 |
|
27301 | var visual = create('rect');
|
27302 | attr$1(visual, {
|
27303 | x: -width / 2,
|
27304 | y: -height / 2,
|
27305 | width: width,
|
27306 | height: height
|
27307 | });
|
27308 | classes$1(visual).add('djs-visual');
|
27309 |
|
27310 | append(draggerGfx, visual);
|
27311 |
|
27312 | var hit = create('rect');
|
27313 | attr$1(hit, {
|
27314 | x: -hitWidth / 2,
|
27315 | y: -hitHeight / 2,
|
27316 | width: hitWidth,
|
27317 | height: hitHeight
|
27318 | });
|
27319 | classes$1(hit).add('djs-hit');
|
27320 |
|
27321 | append(draggerGfx, hit);
|
27322 |
|
27323 | rotate(draggerGfx, alignment === 'v' ? 90 : 0);
|
27324 |
|
27325 | return draggerGfx;
|
27326 | }
|
27327 |
|
27328 |
|
27329 | function addSegmentDragger(parentGfx, segmentStart, segmentEnd) {
|
27330 |
|
27331 | var groupGfx = create('g'),
|
27332 | mid = getMidPoint(segmentStart, segmentEnd),
|
27333 | alignment = pointsAligned(segmentStart, segmentEnd);
|
27334 |
|
27335 | append(parentGfx, groupGfx);
|
27336 |
|
27337 | createParallelDragger(groupGfx, segmentStart, segmentEnd, alignment);
|
27338 |
|
27339 | classes$1(groupGfx).add(SEGMENT_DRAGGER_CLS);
|
27340 | classes$1(groupGfx).add(alignment === 'h' ? 'horizontal' : 'vertical');
|
27341 |
|
27342 | translate(groupGfx, mid.x, mid.y);
|
27343 |
|
27344 | return groupGfx;
|
27345 | }
|
27346 |
|
27347 | |
27348 |
|
27349 |
|
27350 |
|
27351 |
|
27352 |
|
27353 | function calculateSegmentMoveRegion(segmentLength) {
|
27354 | return Math.abs(Math.round(segmentLength * 2 / 3));
|
27355 | }
|
27356 |
|
27357 |
|
27358 |
|
27359 | function calculateHitWidth(segmentStart, segmentEnd, alignment) {
|
27360 | var segmentLengthXAxis = segmentEnd.x - segmentStart.x,
|
27361 | segmentLengthYAxis = segmentEnd.y - segmentStart.y;
|
27362 |
|
27363 | return alignment === 'h' ?
|
27364 | calculateSegmentMoveRegion(segmentLengthXAxis) :
|
27365 | calculateSegmentMoveRegion(segmentLengthYAxis);
|
27366 | }
|
27367 |
|
27368 | var css_escape = createCommonjsModule(function (module, exports) {
|
27369 | (function(root, factory) {
|
27370 |
|
27371 | {
|
27372 |
|
27373 | module.exports = factory(root);
|
27374 | }
|
27375 | }(typeof commonjsGlobal != 'undefined' ? commonjsGlobal : commonjsGlobal, function(root) {
|
27376 |
|
27377 | if (root.CSS && root.CSS.escape) {
|
27378 | return root.CSS.escape;
|
27379 | }
|
27380 |
|
27381 |
|
27382 | var cssEscape = function(value) {
|
27383 | if (arguments.length == 0) {
|
27384 | throw new TypeError('`CSS.escape` requires an argument.');
|
27385 | }
|
27386 | var string = String(value);
|
27387 | var length = string.length;
|
27388 | var index = -1;
|
27389 | var codeUnit;
|
27390 | var result = '';
|
27391 | var firstCodeUnit = string.charCodeAt(0);
|
27392 | while (++index < length) {
|
27393 | codeUnit = string.charCodeAt(index);
|
27394 |
|
27395 |
|
27396 |
|
27397 |
|
27398 |
|
27399 | if (codeUnit == 0x0000) {
|
27400 | result += '\uFFFD';
|
27401 | continue;
|
27402 | }
|
27403 |
|
27404 | if (
|
27405 |
|
27406 |
|
27407 | (codeUnit >= 0x0001 && codeUnit <= 0x001F) || codeUnit == 0x007F ||
|
27408 |
|
27409 |
|
27410 | (index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039) ||
|
27411 |
|
27412 |
|
27413 | (
|
27414 | index == 1 &&
|
27415 | codeUnit >= 0x0030 && codeUnit <= 0x0039 &&
|
27416 | firstCodeUnit == 0x002D
|
27417 | )
|
27418 | ) {
|
27419 |
|
27420 | result += '\\' + codeUnit.toString(16) + ' ';
|
27421 | continue;
|
27422 | }
|
27423 |
|
27424 | if (
|
27425 |
|
27426 |
|
27427 | index == 0 &&
|
27428 | length == 1 &&
|
27429 | codeUnit == 0x002D
|
27430 | ) {
|
27431 | result += '\\' + string.charAt(index);
|
27432 | continue;
|
27433 | }
|
27434 |
|
27435 |
|
27436 |
|
27437 |
|
27438 |
|
27439 | if (
|
27440 | codeUnit >= 0x0080 ||
|
27441 | codeUnit == 0x002D ||
|
27442 | codeUnit == 0x005F ||
|
27443 | codeUnit >= 0x0030 && codeUnit <= 0x0039 ||
|
27444 | codeUnit >= 0x0041 && codeUnit <= 0x005A ||
|
27445 | codeUnit >= 0x0061 && codeUnit <= 0x007A
|
27446 | ) {
|
27447 |
|
27448 | result += string.charAt(index);
|
27449 | continue;
|
27450 | }
|
27451 |
|
27452 |
|
27453 |
|
27454 | result += '\\' + string.charAt(index);
|
27455 |
|
27456 | }
|
27457 | return result;
|
27458 | };
|
27459 |
|
27460 | if (!root.CSS) {
|
27461 | root.CSS = {};
|
27462 | }
|
27463 |
|
27464 | root.CSS.escape = cssEscape;
|
27465 | return cssEscape;
|
27466 |
|
27467 | }));
|
27468 | });
|
27469 |
|
27470 | var HTML_ESCAPE_MAP = {
|
27471 | '&': '&',
|
27472 | '<': '<',
|
27473 | '>': '>',
|
27474 | '"': '"',
|
27475 | '\'': '''
|
27476 | };
|
27477 |
|
27478 | function escapeHTML(str) {
|
27479 | str = '' + str;
|
27480 |
|
27481 | return str && str.replace(/[&<>"']/g, function(match) {
|
27482 | return HTML_ESCAPE_MAP[match];
|
27483 | });
|
27484 | }
|
27485 |
|
27486 | |
27487 |
|
27488 |
|
27489 | function Bendpoints(
|
27490 | eventBus, canvas, interactionEvents,
|
27491 | bendpointMove, connectionSegmentMove) {
|
27492 |
|
27493 | |
27494 |
|
27495 |
|
27496 |
|
27497 | function isIntersectionMiddle(intersection, waypoints, treshold) {
|
27498 | var idx = intersection.index,
|
27499 | p = intersection.point,
|
27500 | p0, p1, mid, aligned, xDelta, yDelta;
|
27501 |
|
27502 | if (idx <= 0 || intersection.bendpoint) {
|
27503 | return false;
|
27504 | }
|
27505 |
|
27506 | p0 = waypoints[idx - 1];
|
27507 | p1 = waypoints[idx];
|
27508 | mid = getMidPoint(p0, p1),
|
27509 | aligned = pointsAligned(p0, p1);
|
27510 | xDelta = Math.abs(p.x - mid.x);
|
27511 | yDelta = Math.abs(p.y - mid.y);
|
27512 |
|
27513 | return aligned && xDelta <= treshold && yDelta <= treshold;
|
27514 | }
|
27515 |
|
27516 | |
27517 |
|
27518 |
|
27519 | function calculateIntersectionThreshold(connection, intersection) {
|
27520 | var waypoints = connection.waypoints,
|
27521 | relevantSegment, alignment, segmentLength, threshold;
|
27522 |
|
27523 | if (intersection.index <= 0 || intersection.bendpoint) {
|
27524 | return null;
|
27525 | }
|
27526 |
|
27527 |
|
27528 | relevantSegment = {
|
27529 | start: waypoints[intersection.index - 1],
|
27530 | end: waypoints[intersection.index]
|
27531 | };
|
27532 |
|
27533 | alignment = pointsAligned(relevantSegment.start, relevantSegment.end);
|
27534 |
|
27535 | if (!alignment) {
|
27536 | return null;
|
27537 | }
|
27538 |
|
27539 | if (alignment === 'h') {
|
27540 | segmentLength = relevantSegment.end.x - relevantSegment.start.x;
|
27541 | } else {
|
27542 | segmentLength = relevantSegment.end.y - relevantSegment.start.y;
|
27543 | }
|
27544 |
|
27545 |
|
27546 | threshold = calculateSegmentMoveRegion(segmentLength) / 2;
|
27547 |
|
27548 | return threshold;
|
27549 | }
|
27550 |
|
27551 | function activateBendpointMove(event, connection) {
|
27552 | var waypoints = connection.waypoints,
|
27553 | intersection = getConnectionIntersection(canvas, waypoints, event),
|
27554 | threshold;
|
27555 |
|
27556 | if (!intersection) {
|
27557 | return;
|
27558 | }
|
27559 |
|
27560 | threshold = calculateIntersectionThreshold(connection, intersection);
|
27561 |
|
27562 | if (isIntersectionMiddle(intersection, waypoints, threshold)) {
|
27563 | connectionSegmentMove.start(event, connection, intersection.index);
|
27564 | } else {
|
27565 | bendpointMove.start(event, connection, intersection.index, !intersection.bendpoint);
|
27566 | }
|
27567 |
|
27568 |
|
27569 | return true;
|
27570 | }
|
27571 |
|
27572 | function bindInteractionEvents(node, eventName, element) {
|
27573 |
|
27574 | componentEvent.bind(node, eventName, function(event) {
|
27575 | interactionEvents.triggerMouseEvent(eventName, event, element);
|
27576 | event.stopPropagation();
|
27577 | });
|
27578 | }
|
27579 |
|
27580 | function getBendpointsContainer(element, create$1) {
|
27581 |
|
27582 | var layer = canvas.getLayer('overlays'),
|
27583 | gfx = query('.djs-bendpoints[data-element-id="' + css_escape(element.id) + '"]', layer);
|
27584 |
|
27585 | if (!gfx && create$1) {
|
27586 | gfx = create('g');
|
27587 | attr$1(gfx, { 'data-element-id': element.id });
|
27588 | classes$1(gfx).add('djs-bendpoints');
|
27589 |
|
27590 | append(layer, gfx);
|
27591 |
|
27592 | bindInteractionEvents(gfx, 'mousedown', element);
|
27593 | bindInteractionEvents(gfx, 'click', element);
|
27594 | bindInteractionEvents(gfx, 'dblclick', element);
|
27595 | }
|
27596 |
|
27597 | return gfx;
|
27598 | }
|
27599 |
|
27600 | function getSegmentDragger(idx, parentGfx) {
|
27601 | return query(
|
27602 | '.djs-segment-dragger[data-segment-idx="' + idx + '"]',
|
27603 | parentGfx
|
27604 | );
|
27605 | }
|
27606 |
|
27607 | function createBendpoints(gfx, connection) {
|
27608 | connection.waypoints.forEach(function(p, idx) {
|
27609 | var bendpoint = addBendpoint(gfx);
|
27610 |
|
27611 | append(gfx, bendpoint);
|
27612 |
|
27613 | translate(bendpoint, p.x, p.y);
|
27614 | });
|
27615 |
|
27616 |
|
27617 | addBendpoint(gfx, 'floating');
|
27618 | }
|
27619 |
|
27620 | function createSegmentDraggers(gfx, connection) {
|
27621 |
|
27622 | var waypoints = connection.waypoints;
|
27623 |
|
27624 | var segmentStart,
|
27625 | segmentEnd,
|
27626 | segmentDraggerGfx;
|
27627 |
|
27628 | for (var i = 1; i < waypoints.length; i++) {
|
27629 |
|
27630 | segmentStart = waypoints[i - 1];
|
27631 | segmentEnd = waypoints[i];
|
27632 |
|
27633 | if (pointsAligned(segmentStart, segmentEnd)) {
|
27634 | segmentDraggerGfx = addSegmentDragger(gfx, segmentStart, segmentEnd);
|
27635 |
|
27636 | attr$1(segmentDraggerGfx, { 'data-segment-idx': i });
|
27637 |
|
27638 | bindInteractionEvents(segmentDraggerGfx, 'mousemove', connection);
|
27639 | }
|
27640 | }
|
27641 | }
|
27642 |
|
27643 | function clearBendpoints(gfx) {
|
27644 | forEach(all('.' + BENDPOINT_CLS, gfx), function(node) {
|
27645 | remove$1(node);
|
27646 | });
|
27647 | }
|
27648 |
|
27649 | function clearSegmentDraggers(gfx) {
|
27650 | forEach(all('.' + SEGMENT_DRAGGER_CLS, gfx), function(node) {
|
27651 | remove$1(node);
|
27652 | });
|
27653 | }
|
27654 |
|
27655 | function addHandles(connection) {
|
27656 |
|
27657 | var gfx = getBendpointsContainer(connection);
|
27658 |
|
27659 | if (!gfx) {
|
27660 | gfx = getBendpointsContainer(connection, true);
|
27661 |
|
27662 | createBendpoints(gfx, connection);
|
27663 | createSegmentDraggers(gfx, connection);
|
27664 | }
|
27665 |
|
27666 | return gfx;
|
27667 | }
|
27668 |
|
27669 | function updateHandles(connection) {
|
27670 |
|
27671 | var gfx = getBendpointsContainer(connection);
|
27672 |
|
27673 | if (gfx) {
|
27674 | clearSegmentDraggers(gfx);
|
27675 | clearBendpoints(gfx);
|
27676 | createSegmentDraggers(gfx, connection);
|
27677 | createBendpoints(gfx, connection);
|
27678 | }
|
27679 | }
|
27680 |
|
27681 | function updateFloatingBendpointPosition(parentGfx, intersection) {
|
27682 | var floating = query('.floating', parentGfx),
|
27683 | point = intersection.point;
|
27684 |
|
27685 | if (!floating) {
|
27686 | return;
|
27687 | }
|
27688 |
|
27689 | translate(floating, point.x, point.y);
|
27690 |
|
27691 | }
|
27692 |
|
27693 | function updateSegmentDraggerPosition(parentGfx, intersection, waypoints) {
|
27694 |
|
27695 | var draggerGfx = getSegmentDragger(intersection.index, parentGfx),
|
27696 | segmentStart = waypoints[intersection.index - 1],
|
27697 | segmentEnd = waypoints[intersection.index],
|
27698 | point = intersection.point,
|
27699 | mid = getMidPoint(segmentStart, segmentEnd),
|
27700 | alignment = pointsAligned(segmentStart, segmentEnd),
|
27701 | draggerVisual, relativePosition;
|
27702 |
|
27703 | if (!draggerGfx) {
|
27704 | return;
|
27705 | }
|
27706 |
|
27707 | draggerVisual = getDraggerVisual(draggerGfx);
|
27708 |
|
27709 | relativePosition = {
|
27710 | x: point.x - mid.x,
|
27711 | y: point.y - mid.y
|
27712 | };
|
27713 |
|
27714 | if (alignment === 'v') {
|
27715 |
|
27716 |
|
27717 | relativePosition = {
|
27718 | x: relativePosition.y,
|
27719 | y: relativePosition.x
|
27720 | };
|
27721 | }
|
27722 |
|
27723 | translate(draggerVisual, relativePosition.x, relativePosition.y);
|
27724 | }
|
27725 |
|
27726 | eventBus.on('connection.changed', function(event) {
|
27727 | updateHandles(event.element);
|
27728 | });
|
27729 |
|
27730 | eventBus.on('connection.remove', function(event) {
|
27731 | var gfx = getBendpointsContainer(event.element);
|
27732 |
|
27733 | if (gfx) {
|
27734 | remove$1(gfx);
|
27735 | }
|
27736 | });
|
27737 |
|
27738 | eventBus.on('element.marker.update', function(event) {
|
27739 |
|
27740 | var element = event.element,
|
27741 | bendpointsGfx;
|
27742 |
|
27743 | if (!element.waypoints) {
|
27744 | return;
|
27745 | }
|
27746 |
|
27747 | bendpointsGfx = addHandles(element);
|
27748 |
|
27749 | if (event.add) {
|
27750 | classes$1(bendpointsGfx).add(event.marker);
|
27751 | } else {
|
27752 | classes$1(bendpointsGfx).remove(event.marker);
|
27753 | }
|
27754 | });
|
27755 |
|
27756 | eventBus.on('element.mousemove', function(event) {
|
27757 |
|
27758 | var element = event.element,
|
27759 | waypoints = element.waypoints,
|
27760 | bendpointsGfx,
|
27761 | intersection;
|
27762 |
|
27763 | if (waypoints) {
|
27764 | bendpointsGfx = getBendpointsContainer(element, true);
|
27765 |
|
27766 | intersection = getConnectionIntersection(canvas, waypoints, event.originalEvent);
|
27767 |
|
27768 | if (!intersection) {
|
27769 | return;
|
27770 | }
|
27771 |
|
27772 | updateFloatingBendpointPosition(bendpointsGfx, intersection);
|
27773 |
|
27774 | if (!intersection.bendpoint) {
|
27775 | updateSegmentDraggerPosition(bendpointsGfx, intersection, waypoints);
|
27776 | }
|
27777 |
|
27778 | }
|
27779 | });
|
27780 |
|
27781 | eventBus.on('element.mousedown', function(event) {
|
27782 |
|
27783 | var originalEvent = event.originalEvent,
|
27784 | element = event.element;
|
27785 |
|
27786 | if (!element.waypoints) {
|
27787 | return;
|
27788 | }
|
27789 |
|
27790 | return activateBendpointMove(originalEvent, element);
|
27791 | });
|
27792 |
|
27793 | eventBus.on('selection.changed', function(event) {
|
27794 | var newSelection = event.newSelection,
|
27795 | primary = newSelection[0];
|
27796 |
|
27797 | if (primary && primary.waypoints) {
|
27798 | addHandles(primary);
|
27799 | }
|
27800 | });
|
27801 |
|
27802 | eventBus.on('element.hover', function(event) {
|
27803 | var element = event.element;
|
27804 |
|
27805 | if (element.waypoints) {
|
27806 | addHandles(element);
|
27807 | interactionEvents.registerEvent(event.gfx, 'mousemove', 'element.mousemove');
|
27808 | }
|
27809 | });
|
27810 |
|
27811 | eventBus.on('element.out', function(event) {
|
27812 | interactionEvents.unregisterEvent(event.gfx, 'mousemove', 'element.mousemove');
|
27813 | });
|
27814 |
|
27815 |
|
27816 | eventBus.on('element.updateId', function(context) {
|
27817 | var element = context.element,
|
27818 | newId = context.newId;
|
27819 |
|
27820 | if (element.waypoints) {
|
27821 | var bendpointContainer = getBendpointsContainer(element);
|
27822 |
|
27823 | if (bendpointContainer) {
|
27824 | attr$1(bendpointContainer, { 'data-element-id': newId });
|
27825 | }
|
27826 | }
|
27827 | });
|
27828 |
|
27829 |
|
27830 |
|
27831 | this.addHandles = addHandles;
|
27832 | this.updateHandles = updateHandles;
|
27833 | this.getBendpointsContainer = getBendpointsContainer;
|
27834 | this.getSegmentDragger = getSegmentDragger;
|
27835 | }
|
27836 |
|
27837 | Bendpoints.$inject = [
|
27838 | 'eventBus',
|
27839 | 'canvas',
|
27840 | 'interactionEvents',
|
27841 | 'bendpointMove',
|
27842 | 'connectionSegmentMove'
|
27843 | ];
|
27844 |
|
27845 |
|
27846 |
|
27847 |
|
27848 |
|
27849 | function getDraggerVisual(draggerGfx) {
|
27850 | return query('.djs-visual', draggerGfx);
|
27851 | }
|
27852 |
|
27853 | var round$3 = Math.round;
|
27854 |
|
27855 | var RECONNECT_START = 'reconnectStart',
|
27856 | RECONNECT_END = 'reconnectEnd',
|
27857 | UPDATE_WAYPOINTS = 'updateWaypoints';
|
27858 |
|
27859 |
|
27860 | |
27861 |
|
27862 |
|
27863 | function BendpointMove(injector, eventBus, canvas, dragging, rules, modeling) {
|
27864 | this._injector = injector;
|
27865 |
|
27866 | this.start = function(event, connection, bendpointIndex, insert) {
|
27867 | var gfx = canvas.getGraphics(connection),
|
27868 | source = connection.source,
|
27869 | target = connection.target,
|
27870 | waypoints = connection.waypoints,
|
27871 | type;
|
27872 |
|
27873 | if (!insert && bendpointIndex === 0) {
|
27874 | type = RECONNECT_START;
|
27875 | } else
|
27876 | if (!insert && bendpointIndex === waypoints.length - 1) {
|
27877 | type = RECONNECT_END;
|
27878 | } else {
|
27879 | type = UPDATE_WAYPOINTS;
|
27880 | }
|
27881 |
|
27882 | var command = type === UPDATE_WAYPOINTS ? 'connection.updateWaypoints' : 'connection.reconnect';
|
27883 |
|
27884 | var allowed = rules.allowed(command, {
|
27885 | connection: connection,
|
27886 | source: source,
|
27887 | target: target
|
27888 | });
|
27889 |
|
27890 | if (allowed === false) {
|
27891 | allowed = rules.allowed(command, {
|
27892 | connection: connection,
|
27893 | source: target,
|
27894 | target: source
|
27895 | });
|
27896 | }
|
27897 |
|
27898 | if (allowed === false) {
|
27899 | return;
|
27900 | }
|
27901 |
|
27902 | dragging.init(event, 'bendpoint.move', {
|
27903 | data: {
|
27904 | connection: connection,
|
27905 | connectionGfx: gfx,
|
27906 | context: {
|
27907 | allowed: allowed,
|
27908 | bendpointIndex: bendpointIndex,
|
27909 | connection: connection,
|
27910 | source: source,
|
27911 | target: target,
|
27912 | insert: insert,
|
27913 | type: type
|
27914 | }
|
27915 | }
|
27916 | });
|
27917 | };
|
27918 |
|
27919 | eventBus.on('bendpoint.move.hover', function(event) {
|
27920 | var context = event.context,
|
27921 | connection = context.connection,
|
27922 | source = connection.source,
|
27923 | target = connection.target,
|
27924 | hover = event.hover,
|
27925 | type = context.type;
|
27926 |
|
27927 |
|
27928 | context.hover = hover;
|
27929 |
|
27930 | var allowed;
|
27931 |
|
27932 | if (!hover) {
|
27933 | return;
|
27934 | }
|
27935 |
|
27936 | var command = type === UPDATE_WAYPOINTS ? 'connection.updateWaypoints' : 'connection.reconnect';
|
27937 |
|
27938 | allowed = context.allowed = rules.allowed(command, {
|
27939 | connection: connection,
|
27940 | source: type === RECONNECT_START ? hover : source,
|
27941 | target: type === RECONNECT_END ? hover : target
|
27942 | });
|
27943 |
|
27944 | if (allowed) {
|
27945 | context.source = type === RECONNECT_START ? hover : source;
|
27946 | context.target = type === RECONNECT_END ? hover : target;
|
27947 |
|
27948 | return;
|
27949 | }
|
27950 |
|
27951 | if (allowed === false) {
|
27952 | allowed = context.allowed = rules.allowed(command, {
|
27953 | connection: connection,
|
27954 | source: type === RECONNECT_END ? hover : target,
|
27955 | target: type === RECONNECT_START ? hover : source
|
27956 | });
|
27957 | }
|
27958 |
|
27959 | if (allowed) {
|
27960 | context.source = type === RECONNECT_END ? hover : target;
|
27961 | context.target = type === RECONNECT_START ? hover : source;
|
27962 | }
|
27963 | });
|
27964 |
|
27965 | eventBus.on([ 'bendpoint.move.out', 'bendpoint.move.cleanup' ], function(event) {
|
27966 | var context = event.context;
|
27967 |
|
27968 | context.hover = null;
|
27969 | context.source = null;
|
27970 | context.target = null;
|
27971 |
|
27972 | context.allowed = false;
|
27973 | });
|
27974 |
|
27975 | eventBus.on('bendpoint.move.end', function(event) {
|
27976 | var context = event.context,
|
27977 | allowed = context.allowed,
|
27978 | bendpointIndex = context.bendpointIndex,
|
27979 | connection = context.connection,
|
27980 | insert = context.insert,
|
27981 | newWaypoints = connection.waypoints.slice(),
|
27982 | source = context.source,
|
27983 | target = context.target,
|
27984 | type = context.type,
|
27985 | hints = {};
|
27986 |
|
27987 |
|
27988 | var docking = {
|
27989 | x: round$3(event.x),
|
27990 | y: round$3(event.y)
|
27991 | };
|
27992 |
|
27993 | if (!allowed) {
|
27994 | return false;
|
27995 | }
|
27996 |
|
27997 | if (type === UPDATE_WAYPOINTS) {
|
27998 | if (insert) {
|
27999 |
|
28000 |
|
28001 | newWaypoints.splice(bendpointIndex, 0, docking);
|
28002 | } else {
|
28003 |
|
28004 |
|
28005 | newWaypoints[bendpointIndex] = docking;
|
28006 | }
|
28007 |
|
28008 |
|
28009 |
|
28010 | hints = {
|
28011 | bendpointMove: {
|
28012 | insert: insert,
|
28013 | bendpointIndex: bendpointIndex
|
28014 | }
|
28015 | };
|
28016 |
|
28017 | newWaypoints = this.cropWaypoints(connection, newWaypoints);
|
28018 |
|
28019 | modeling.updateWaypoints(connection, filterRedundantWaypoints(newWaypoints), hints);
|
28020 | } else {
|
28021 | if (type === RECONNECT_START) {
|
28022 | hints.docking = 'source';
|
28023 |
|
28024 | if (isReverse(context)) {
|
28025 | hints.docking = 'target';
|
28026 |
|
28027 | hints.newWaypoints = newWaypoints.reverse();
|
28028 | }
|
28029 | } else if (type === RECONNECT_END) {
|
28030 | hints.docking = 'target';
|
28031 |
|
28032 | if (isReverse(context)) {
|
28033 | hints.docking = 'source';
|
28034 |
|
28035 | hints.newWaypoints = newWaypoints.reverse();
|
28036 | }
|
28037 | }
|
28038 |
|
28039 | modeling.reconnect(connection, source, target, docking, hints);
|
28040 | }
|
28041 | }, this);
|
28042 | }
|
28043 |
|
28044 | BendpointMove.$inject = [
|
28045 | 'injector',
|
28046 | 'eventBus',
|
28047 | 'canvas',
|
28048 | 'dragging',
|
28049 | 'rules',
|
28050 | 'modeling'
|
28051 | ];
|
28052 |
|
28053 | BendpointMove.prototype.cropWaypoints = function(connection, newWaypoints) {
|
28054 | var connectionDocking = this._injector.get('connectionDocking', false);
|
28055 |
|
28056 | if (!connectionDocking) {
|
28057 | return newWaypoints;
|
28058 | }
|
28059 |
|
28060 | var waypoints = connection.waypoints;
|
28061 |
|
28062 | connection.waypoints = newWaypoints;
|
28063 |
|
28064 | connection.waypoints = connectionDocking.getCroppedWaypoints(connection);
|
28065 |
|
28066 | newWaypoints = connection.waypoints;
|
28067 |
|
28068 | connection.waypoints = waypoints;
|
28069 |
|
28070 | return newWaypoints;
|
28071 | };
|
28072 |
|
28073 |
|
28074 |
|
28075 |
|
28076 | function isReverse(context) {
|
28077 | var hover = context.hover,
|
28078 | source = context.source,
|
28079 | target = context.target,
|
28080 | type = context.type;
|
28081 |
|
28082 | if (type === RECONNECT_START) {
|
28083 | return hover && target && hover === target && source !== target;
|
28084 | }
|
28085 |
|
28086 | if (type === RECONNECT_END) {
|
28087 | return hover && source && hover === source && source !== target;
|
28088 | }
|
28089 | }
|
28090 |
|
28091 | var RECONNECT_START$1 = 'reconnectStart',
|
28092 | RECONNECT_END$1 = 'reconnectEnd',
|
28093 | UPDATE_WAYPOINTS$1 = 'updateWaypoints';
|
28094 |
|
28095 | var MARKER_OK = 'connect-ok',
|
28096 | MARKER_NOT_OK = 'connect-not-ok',
|
28097 | MARKER_CONNECT_HOVER = 'connect-hover',
|
28098 | MARKER_CONNECT_UPDATING = 'djs-updating',
|
28099 | MARKER_ELEMENT_HIDDEN = 'djs-element-hidden';
|
28100 |
|
28101 | var HIGH_PRIORITY$1 = 1100;
|
28102 |
|
28103 | |
28104 |
|
28105 |
|
28106 | function BendpointMovePreview(bendpointMove, injector, eventBus, canvas) {
|
28107 | this._injector = injector;
|
28108 |
|
28109 | var connectionPreview = injector.get('connectionPreview', false);
|
28110 |
|
28111 | eventBus.on('bendpoint.move.start', function(event) {
|
28112 | var context = event.context,
|
28113 | bendpointIndex = context.bendpointIndex,
|
28114 | connection = context.connection,
|
28115 | insert = context.insert,
|
28116 | waypoints = connection.waypoints,
|
28117 | newWaypoints = waypoints.slice();
|
28118 |
|
28119 | context.waypoints = waypoints;
|
28120 |
|
28121 | if (insert) {
|
28122 |
|
28123 |
|
28124 | newWaypoints.splice(bendpointIndex, 0, { x: event.x, y: event.y });
|
28125 | }
|
28126 |
|
28127 | connection.waypoints = newWaypoints;
|
28128 |
|
28129 |
|
28130 | var draggerGfx = context.draggerGfx = addBendpoint(canvas.getLayer('overlays'));
|
28131 |
|
28132 | classes$1(draggerGfx).add('djs-dragging');
|
28133 |
|
28134 | canvas.addMarker(connection, MARKER_ELEMENT_HIDDEN);
|
28135 | canvas.addMarker(connection, MARKER_CONNECT_UPDATING);
|
28136 | });
|
28137 |
|
28138 | eventBus.on('bendpoint.move.hover', function(event) {
|
28139 | var context = event.context,
|
28140 | allowed = context.allowed,
|
28141 | hover = context.hover,
|
28142 | type = context.type;
|
28143 |
|
28144 | if (hover) {
|
28145 | canvas.addMarker(hover, MARKER_CONNECT_HOVER);
|
28146 |
|
28147 | if (type === UPDATE_WAYPOINTS$1) {
|
28148 | return;
|
28149 | }
|
28150 |
|
28151 | if (allowed) {
|
28152 | canvas.removeMarker(hover, MARKER_NOT_OK);
|
28153 | canvas.addMarker(hover, MARKER_OK);
|
28154 | } else if (allowed === false) {
|
28155 | canvas.removeMarker(hover, MARKER_OK);
|
28156 | canvas.addMarker(hover, MARKER_NOT_OK);
|
28157 | }
|
28158 | }
|
28159 | });
|
28160 |
|
28161 | eventBus.on([
|
28162 | 'bendpoint.move.out',
|
28163 | 'bendpoint.move.cleanup'
|
28164 | ], HIGH_PRIORITY$1, function(event) {
|
28165 | var context = event.context,
|
28166 | hover = context.hover,
|
28167 | target = context.target;
|
28168 |
|
28169 | if (hover) {
|
28170 | canvas.removeMarker(hover, MARKER_CONNECT_HOVER);
|
28171 | canvas.removeMarker(hover, target ? MARKER_OK : MARKER_NOT_OK);
|
28172 | }
|
28173 | });
|
28174 |
|
28175 | eventBus.on('bendpoint.move.move', function(event) {
|
28176 | var context = event.context,
|
28177 | allowed = context.allowed,
|
28178 | bendpointIndex = context.bendpointIndex,
|
28179 | draggerGfx = context.draggerGfx,
|
28180 | hover = context.hover,
|
28181 | type = context.type,
|
28182 | connection = context.connection,
|
28183 | source = connection.source,
|
28184 | target = connection.target,
|
28185 | newWaypoints = connection.waypoints.slice(),
|
28186 | bendpoint = { x: event.x, y: event.y },
|
28187 | hints;
|
28188 |
|
28189 | if (connectionPreview) {
|
28190 | hints = {
|
28191 | source: source,
|
28192 | target: target
|
28193 | };
|
28194 |
|
28195 | if (type === RECONNECT_START$1) {
|
28196 | if (isReverse(context)) {
|
28197 | hints.connectionEnd = bendpoint;
|
28198 | hints.source = target;
|
28199 | hints.target = hover || source;
|
28200 |
|
28201 | newWaypoints = newWaypoints.reverse();
|
28202 | } else {
|
28203 | hints.connectionStart = bendpoint;
|
28204 | hints.source = hover || source;
|
28205 | }
|
28206 | } else if (type === RECONNECT_END$1) {
|
28207 | if (isReverse(context)) {
|
28208 | hints.connectionStart = bendpoint;
|
28209 | hints.target = source;
|
28210 | hints.source = hover || target;
|
28211 |
|
28212 | newWaypoints = newWaypoints.reverse();
|
28213 | } else {
|
28214 | hints.connectionEnd = bendpoint;
|
28215 | hints.target = hover || target;
|
28216 | }
|
28217 |
|
28218 | } else {
|
28219 | hints.noCropping = true;
|
28220 | hints.noLayout = true;
|
28221 | newWaypoints[ bendpointIndex ] = bendpoint;
|
28222 | }
|
28223 |
|
28224 | if (type === UPDATE_WAYPOINTS$1) {
|
28225 | newWaypoints = bendpointMove.cropWaypoints(connection, newWaypoints);
|
28226 | }
|
28227 |
|
28228 | hints.waypoints = newWaypoints;
|
28229 |
|
28230 | connectionPreview.drawPreview(context, allowed, hints);
|
28231 | }
|
28232 |
|
28233 | translate(draggerGfx, event.x, event.y);
|
28234 | }, this);
|
28235 |
|
28236 | eventBus.on([
|
28237 | 'bendpoint.move.end',
|
28238 | 'bendpoint.move.cancel'
|
28239 | ], HIGH_PRIORITY$1, function(event) {
|
28240 | var context = event.context,
|
28241 | connection = context.connection,
|
28242 | draggerGfx = context.draggerGfx,
|
28243 | hover = context.hover,
|
28244 | target = context.target,
|
28245 | waypoints = context.waypoints;
|
28246 |
|
28247 | connection.waypoints = waypoints;
|
28248 |
|
28249 |
|
28250 | remove$1(draggerGfx);
|
28251 |
|
28252 | canvas.removeMarker(connection, MARKER_CONNECT_UPDATING);
|
28253 | canvas.removeMarker(connection, MARKER_ELEMENT_HIDDEN);
|
28254 |
|
28255 | if (hover) {
|
28256 | canvas.removeMarker(hover, MARKER_OK);
|
28257 | canvas.removeMarker(hover, target ? MARKER_OK : MARKER_NOT_OK);
|
28258 | }
|
28259 |
|
28260 | if (connectionPreview) {
|
28261 | connectionPreview.cleanUp(context);
|
28262 | }
|
28263 | });
|
28264 | }
|
28265 |
|
28266 | BendpointMovePreview.$inject = [
|
28267 | 'bendpointMove',
|
28268 | 'injector',
|
28269 | 'eventBus',
|
28270 | 'canvas'
|
28271 | ];
|
28272 |
|
28273 | var MARKER_CONNECT_HOVER$1 = 'connect-hover',
|
28274 | MARKER_CONNECT_UPDATING$1 = 'djs-updating';
|
28275 |
|
28276 |
|
28277 | function axisAdd(point, axis, delta) {
|
28278 | return axisSet(point, axis, point[axis] + delta);
|
28279 | }
|
28280 |
|
28281 | function axisSet(point, axis, value) {
|
28282 | return {
|
28283 | x: (axis === 'x' ? value : point.x),
|
28284 | y: (axis === 'y' ? value : point.y)
|
28285 | };
|
28286 | }
|
28287 |
|
28288 | function axisFenced(position, segmentStart, segmentEnd, axis) {
|
28289 |
|
28290 | var maxValue = Math.max(segmentStart[axis], segmentEnd[axis]),
|
28291 | minValue = Math.min(segmentStart[axis], segmentEnd[axis]);
|
28292 |
|
28293 | var padding = 20;
|
28294 |
|
28295 | var fencedValue = Math.min(Math.max(minValue + padding, position[axis]), maxValue - padding);
|
28296 |
|
28297 | return axisSet(segmentStart, axis, fencedValue);
|
28298 | }
|
28299 |
|
28300 | function flipAxis(axis) {
|
28301 | return axis === 'x' ? 'y' : 'x';
|
28302 | }
|
28303 |
|
28304 | |
28305 |
|
28306 |
|
28307 |
|
28308 |
|
28309 |
|
28310 |
|
28311 |
|
28312 |
|
28313 |
|
28314 |
|
28315 | function getDocking(point, referenceElement, moveAxis) {
|
28316 |
|
28317 | var referenceMid,
|
28318 | inverseAxis;
|
28319 |
|
28320 | if (point.original) {
|
28321 | return point.original;
|
28322 | } else {
|
28323 | referenceMid = getMid(referenceElement);
|
28324 | inverseAxis = flipAxis(moveAxis);
|
28325 |
|
28326 | return axisSet(point, inverseAxis, referenceMid[inverseAxis]);
|
28327 | }
|
28328 | }
|
28329 |
|
28330 | |
28331 |
|
28332 |
|
28333 | function ConnectionSegmentMove(
|
28334 | injector, eventBus, canvas,
|
28335 | dragging, graphicsFactory, modeling) {
|
28336 |
|
28337 |
|
28338 | var connectionDocking = injector.get('connectionDocking', false);
|
28339 |
|
28340 |
|
28341 |
|
28342 |
|
28343 | this.start = function(event, connection, idx) {
|
28344 |
|
28345 | var context,
|
28346 | gfx = canvas.getGraphics(connection),
|
28347 | segmentStartIndex = idx - 1,
|
28348 | segmentEndIndex = idx,
|
28349 | waypoints = connection.waypoints,
|
28350 | segmentStart = waypoints[segmentStartIndex],
|
28351 | segmentEnd = waypoints[segmentEndIndex],
|
28352 | intersection = getConnectionIntersection(canvas, waypoints, event),
|
28353 | direction, axis, dragPosition;
|
28354 |
|
28355 | direction = pointsAligned(segmentStart, segmentEnd);
|
28356 |
|
28357 |
|
28358 | if (!direction) {
|
28359 | return;
|
28360 | }
|
28361 |
|
28362 |
|
28363 | axis = direction === 'v' ? 'x' : 'y';
|
28364 |
|
28365 | if (segmentStartIndex === 0) {
|
28366 | segmentStart = getDocking(segmentStart, connection.source, axis);
|
28367 | }
|
28368 |
|
28369 | if (segmentEndIndex === waypoints.length - 1) {
|
28370 | segmentEnd = getDocking(segmentEnd, connection.target, axis);
|
28371 | }
|
28372 |
|
28373 | if (intersection) {
|
28374 | dragPosition = intersection.point;
|
28375 | } else {
|
28376 |
|
28377 |
|
28378 | dragPosition = {
|
28379 | x: (segmentStart.x + segmentEnd.x) / 2,
|
28380 | y: (segmentStart.y + segmentEnd.y) / 2
|
28381 | };
|
28382 | }
|
28383 |
|
28384 | context = {
|
28385 | connection: connection,
|
28386 | segmentStartIndex: segmentStartIndex,
|
28387 | segmentEndIndex: segmentEndIndex,
|
28388 | segmentStart: segmentStart,
|
28389 | segmentEnd: segmentEnd,
|
28390 | axis: axis,
|
28391 | dragPosition: dragPosition
|
28392 | };
|
28393 |
|
28394 | dragging.init(event, dragPosition, 'connectionSegment.move', {
|
28395 | cursor: axis === 'x' ? 'resize-ew' : 'resize-ns',
|
28396 | data: {
|
28397 | connection: connection,
|
28398 | connectionGfx: gfx,
|
28399 | context: context
|
28400 | }
|
28401 | });
|
28402 | };
|
28403 |
|
28404 | |
28405 |
|
28406 |
|
28407 |
|
28408 |
|
28409 |
|
28410 |
|
28411 |
|
28412 | function cropConnection(connection, newWaypoints) {
|
28413 |
|
28414 |
|
28415 | if (!connectionDocking) {
|
28416 | return newWaypoints;
|
28417 | }
|
28418 |
|
28419 | var oldWaypoints = connection.waypoints,
|
28420 | croppedWaypoints;
|
28421 |
|
28422 |
|
28423 | connection.waypoints = newWaypoints;
|
28424 |
|
28425 | croppedWaypoints = connectionDocking.getCroppedWaypoints(connection);
|
28426 |
|
28427 |
|
28428 | connection.waypoints = oldWaypoints;
|
28429 |
|
28430 | return croppedWaypoints;
|
28431 | }
|
28432 |
|
28433 |
|
28434 |
|
28435 | function redrawConnection(data) {
|
28436 | graphicsFactory.update('connection', data.connection, data.connectionGfx);
|
28437 | }
|
28438 |
|
28439 | function updateDragger(context, segmentOffset, event) {
|
28440 |
|
28441 | var newWaypoints = context.newWaypoints,
|
28442 | segmentStartIndex = context.segmentStartIndex + segmentOffset,
|
28443 | segmentStart = newWaypoints[segmentStartIndex],
|
28444 | segmentEndIndex = context.segmentEndIndex + segmentOffset,
|
28445 | segmentEnd = newWaypoints[segmentEndIndex],
|
28446 | axis = flipAxis(context.axis);
|
28447 |
|
28448 |
|
28449 |
|
28450 | var draggerPosition = axisFenced(event, segmentStart, segmentEnd, axis);
|
28451 |
|
28452 |
|
28453 | translate(context.draggerGfx, draggerPosition.x, draggerPosition.y);
|
28454 | }
|
28455 |
|
28456 | |
28457 |
|
28458 |
|
28459 |
|
28460 |
|
28461 |
|
28462 |
|
28463 |
|
28464 |
|
28465 | function filterRedundantWaypoints(waypoints, segmentStartIndex) {
|
28466 |
|
28467 | var segmentOffset = 0;
|
28468 |
|
28469 | var filteredWaypoints = waypoints.filter(function(r, idx) {
|
28470 | if (pointsOnLine(waypoints[idx - 1], waypoints[idx + 1], r)) {
|
28471 |
|
28472 |
|
28473 | segmentOffset = idx <= segmentStartIndex ? segmentOffset - 1 : segmentOffset;
|
28474 | return false;
|
28475 | }
|
28476 |
|
28477 |
|
28478 | return true;
|
28479 | });
|
28480 |
|
28481 | return {
|
28482 | waypoints: filteredWaypoints,
|
28483 | segmentOffset: segmentOffset
|
28484 | };
|
28485 | }
|
28486 |
|
28487 | eventBus.on('connectionSegment.move.start', function(event) {
|
28488 |
|
28489 | var context = event.context,
|
28490 | connection = event.connection,
|
28491 | layer = canvas.getLayer('overlays');
|
28492 |
|
28493 | context.originalWaypoints = connection.waypoints.slice();
|
28494 |
|
28495 |
|
28496 | context.draggerGfx = addSegmentDragger(layer, context.segmentStart, context.segmentEnd);
|
28497 | classes$1(context.draggerGfx).add('djs-dragging');
|
28498 |
|
28499 | canvas.addMarker(connection, MARKER_CONNECT_UPDATING$1);
|
28500 | });
|
28501 |
|
28502 | eventBus.on('connectionSegment.move.move', function(event) {
|
28503 |
|
28504 | var context = event.context,
|
28505 | connection = context.connection,
|
28506 | segmentStartIndex = context.segmentStartIndex,
|
28507 | segmentEndIndex = context.segmentEndIndex,
|
28508 | segmentStart = context.segmentStart,
|
28509 | segmentEnd = context.segmentEnd,
|
28510 | axis = context.axis;
|
28511 |
|
28512 | var newWaypoints = context.originalWaypoints.slice(),
|
28513 | newSegmentStart = axisAdd(segmentStart, axis, event['d' + axis]),
|
28514 | newSegmentEnd = axisAdd(segmentEnd, axis, event['d' + axis]);
|
28515 |
|
28516 |
|
28517 |
|
28518 |
|
28519 | var waypointCount = newWaypoints.length,
|
28520 | segmentOffset = 0;
|
28521 |
|
28522 |
|
28523 | newWaypoints[segmentStartIndex] = newSegmentStart;
|
28524 | newWaypoints[segmentEndIndex] = newSegmentEnd;
|
28525 |
|
28526 | var sourceToSegmentOrientation,
|
28527 | targetToSegmentOrientation;
|
28528 |
|
28529 |
|
28530 | if (segmentStartIndex < 2) {
|
28531 | sourceToSegmentOrientation = getOrientation(connection.source, newSegmentStart);
|
28532 |
|
28533 |
|
28534 | if (segmentStartIndex === 1) {
|
28535 |
|
28536 | if (sourceToSegmentOrientation === 'intersect') {
|
28537 | newWaypoints.shift();
|
28538 | newWaypoints[0] = newSegmentStart;
|
28539 | segmentOffset--;
|
28540 | }
|
28541 | }
|
28542 |
|
28543 |
|
28544 | else {
|
28545 | if (sourceToSegmentOrientation !== 'intersect') {
|
28546 | newWaypoints.unshift(segmentStart);
|
28547 | segmentOffset++;
|
28548 | }
|
28549 | }
|
28550 | }
|
28551 |
|
28552 |
|
28553 | if (segmentEndIndex > waypointCount - 3) {
|
28554 | targetToSegmentOrientation = getOrientation(connection.target, newSegmentEnd);
|
28555 |
|
28556 |
|
28557 | if (segmentEndIndex === waypointCount - 2) {
|
28558 |
|
28559 | if (targetToSegmentOrientation === 'intersect') {
|
28560 | newWaypoints.pop();
|
28561 | newWaypoints[newWaypoints.length - 1] = newSegmentEnd;
|
28562 | }
|
28563 | }
|
28564 |
|
28565 |
|
28566 | else {
|
28567 | if (targetToSegmentOrientation !== 'intersect') {
|
28568 | newWaypoints.push(segmentEnd);
|
28569 | }
|
28570 | }
|
28571 | }
|
28572 |
|
28573 |
|
28574 | context.newWaypoints = connection.waypoints = cropConnection(connection, newWaypoints);
|
28575 |
|
28576 |
|
28577 | updateDragger(context, segmentOffset, event);
|
28578 |
|
28579 |
|
28580 | context.newSegmentStartIndex = segmentStartIndex + segmentOffset;
|
28581 |
|
28582 |
|
28583 | redrawConnection(event);
|
28584 | });
|
28585 |
|
28586 | eventBus.on('connectionSegment.move.hover', function(event) {
|
28587 |
|
28588 | event.context.hover = event.hover;
|
28589 | canvas.addMarker(event.hover, MARKER_CONNECT_HOVER$1);
|
28590 | });
|
28591 |
|
28592 | eventBus.on([
|
28593 | 'connectionSegment.move.out',
|
28594 | 'connectionSegment.move.cleanup'
|
28595 | ], function(event) {
|
28596 |
|
28597 |
|
28598 |
|
28599 | var hover = event.context.hover;
|
28600 |
|
28601 | if (hover) {
|
28602 | canvas.removeMarker(hover, MARKER_CONNECT_HOVER$1);
|
28603 | }
|
28604 | });
|
28605 |
|
28606 | eventBus.on('connectionSegment.move.cleanup', function(event) {
|
28607 |
|
28608 | var context = event.context,
|
28609 | connection = context.connection;
|
28610 |
|
28611 |
|
28612 | if (context.draggerGfx) {
|
28613 | remove$1(context.draggerGfx);
|
28614 | }
|
28615 |
|
28616 | canvas.removeMarker(connection, MARKER_CONNECT_UPDATING$1);
|
28617 | });
|
28618 |
|
28619 | eventBus.on([
|
28620 | 'connectionSegment.move.cancel',
|
28621 | 'connectionSegment.move.end'
|
28622 | ], function(event) {
|
28623 | var context = event.context,
|
28624 | connection = context.connection;
|
28625 |
|
28626 | connection.waypoints = context.originalWaypoints;
|
28627 |
|
28628 | redrawConnection(event);
|
28629 | });
|
28630 |
|
28631 | eventBus.on('connectionSegment.move.end', function(event) {
|
28632 |
|
28633 | var context = event.context,
|
28634 | connection = context.connection,
|
28635 | newWaypoints = context.newWaypoints,
|
28636 | newSegmentStartIndex = context.newSegmentStartIndex;
|
28637 |
|
28638 |
|
28639 |
|
28640 | newWaypoints = newWaypoints.map(function(p) {
|
28641 | return {
|
28642 | original: p.original,
|
28643 | x: Math.round(p.x),
|
28644 | y: Math.round(p.y)
|
28645 | };
|
28646 | });
|
28647 |
|
28648 |
|
28649 | var filtered = filterRedundantWaypoints(newWaypoints, newSegmentStartIndex);
|
28650 |
|
28651 |
|
28652 | var filteredWaypoints = filtered.waypoints,
|
28653 | croppedWaypoints = cropConnection(connection, filteredWaypoints),
|
28654 | segmentOffset = filtered.segmentOffset;
|
28655 |
|
28656 | var hints = {
|
28657 | segmentMove: {
|
28658 | segmentStartIndex: context.segmentStartIndex,
|
28659 | newSegmentStartIndex: newSegmentStartIndex + segmentOffset
|
28660 | }
|
28661 | };
|
28662 |
|
28663 | modeling.updateWaypoints(connection, croppedWaypoints, hints);
|
28664 | });
|
28665 | }
|
28666 |
|
28667 | ConnectionSegmentMove.$inject = [
|
28668 | 'injector',
|
28669 | 'eventBus',
|
28670 | 'canvas',
|
28671 | 'dragging',
|
28672 | 'graphicsFactory',
|
28673 | 'modeling'
|
28674 | ];
|
28675 |
|
28676 | var abs$1 = Math.abs,
|
28677 | round$4 = Math.round;
|
28678 |
|
28679 |
|
28680 | |
28681 |
|
28682 |
|
28683 |
|
28684 |
|
28685 |
|
28686 |
|
28687 |
|
28688 |
|
28689 | function snapTo(value, values, tolerance) {
|
28690 | tolerance = tolerance === undefined ? 10 : tolerance;
|
28691 |
|
28692 | var idx, snapValue;
|
28693 |
|
28694 | for (idx = 0; idx < values.length; idx++) {
|
28695 | snapValue = values[idx];
|
28696 |
|
28697 | if (abs$1(snapValue - value) <= tolerance) {
|
28698 | return snapValue;
|
28699 | }
|
28700 | }
|
28701 | }
|
28702 |
|
28703 |
|
28704 | function topLeft(bounds) {
|
28705 | return {
|
28706 | x: bounds.x,
|
28707 | y: bounds.y
|
28708 | };
|
28709 | }
|
28710 |
|
28711 | function bottomRight(bounds) {
|
28712 | return {
|
28713 | x: bounds.x + bounds.width,
|
28714 | y: bounds.y + bounds.height
|
28715 | };
|
28716 | }
|
28717 |
|
28718 | function mid(bounds, defaultValue) {
|
28719 |
|
28720 | if (!bounds || isNaN(bounds.x) || isNaN(bounds.y)) {
|
28721 | return defaultValue;
|
28722 | }
|
28723 |
|
28724 | return {
|
28725 | x: round$4(bounds.x + bounds.width / 2),
|
28726 | y: round$4(bounds.y + bounds.height / 2)
|
28727 | };
|
28728 | }
|
28729 |
|
28730 |
|
28731 | |
28732 |
|
28733 |
|
28734 |
|
28735 |
|
28736 |
|
28737 |
|
28738 |
|
28739 |
|
28740 | function isSnapped(event, axis) {
|
28741 | var snapped = event.snapped;
|
28742 |
|
28743 | if (!snapped) {
|
28744 | return false;
|
28745 | }
|
28746 |
|
28747 | if (typeof axis === 'string') {
|
28748 | return snapped[axis];
|
28749 | }
|
28750 |
|
28751 | return snapped.x && snapped.y;
|
28752 | }
|
28753 |
|
28754 |
|
28755 | |
28756 |
|
28757 |
|
28758 |
|
28759 |
|
28760 |
|
28761 |
|
28762 |
|
28763 |
|
28764 |
|
28765 |
|
28766 |
|
28767 | function setSnapped(event, axis, value) {
|
28768 | if (typeof axis !== 'string') {
|
28769 | throw new Error('axis must be in [x, y]');
|
28770 | }
|
28771 |
|
28772 | if (typeof value !== 'number' && value !== false) {
|
28773 | throw new Error('value must be Number or false');
|
28774 | }
|
28775 |
|
28776 | var delta,
|
28777 | previousValue = event[axis];
|
28778 |
|
28779 | var snapped = event.snapped = (event.snapped || {});
|
28780 |
|
28781 |
|
28782 | if (value === false) {
|
28783 | snapped[axis] = false;
|
28784 | } else {
|
28785 | snapped[axis] = true;
|
28786 |
|
28787 | delta = value - previousValue;
|
28788 |
|
28789 | event[axis] += delta;
|
28790 | event['d' + axis] += delta;
|
28791 | }
|
28792 |
|
28793 | return previousValue;
|
28794 | }
|
28795 |
|
28796 | |
28797 |
|
28798 |
|
28799 |
|
28800 |
|
28801 |
|
28802 |
|
28803 | function getChildren$1(parent) {
|
28804 | return parent.children || [];
|
28805 | }
|
28806 |
|
28807 | var abs$2= Math.abs,
|
28808 | round$5 = Math.round;
|
28809 |
|
28810 | var TOLERANCE = 10;
|
28811 |
|
28812 |
|
28813 | function BendpointSnapping(eventBus) {
|
28814 |
|
28815 | function snapTo(values, value) {
|
28816 |
|
28817 | if (isArray(values)) {
|
28818 | var i = values.length;
|
28819 |
|
28820 | while (i--) if (abs$2(values[i] - value) <= TOLERANCE) {
|
28821 | return values[i];
|
28822 | }
|
28823 | } else {
|
28824 | values = +values;
|
28825 | var rem = value % values;
|
28826 |
|
28827 | if (rem < TOLERANCE) {
|
28828 | return value - rem;
|
28829 | }
|
28830 |
|
28831 | if (rem > values - TOLERANCE) {
|
28832 | return value - rem + values;
|
28833 | }
|
28834 | }
|
28835 |
|
28836 | return value;
|
28837 | }
|
28838 |
|
28839 | function mid(element) {
|
28840 | if (element.width) {
|
28841 | return {
|
28842 | x: round$5(element.width / 2 + element.x),
|
28843 | y: round$5(element.height / 2 + element.y)
|
28844 | };
|
28845 | }
|
28846 | }
|
28847 |
|
28848 |
|
28849 |
|
28850 | function getConnectionSegmentSnaps(context) {
|
28851 |
|
28852 | var snapPoints = context.snapPoints,
|
28853 | connection = context.connection,
|
28854 | waypoints = connection.waypoints,
|
28855 | segmentStart = context.segmentStart,
|
28856 | segmentStartIndex = context.segmentStartIndex,
|
28857 | segmentEnd = context.segmentEnd,
|
28858 | segmentEndIndex = context.segmentEndIndex,
|
28859 | axis = context.axis;
|
28860 |
|
28861 | if (snapPoints) {
|
28862 | return snapPoints;
|
28863 | }
|
28864 |
|
28865 | var referenceWaypoints = [
|
28866 | waypoints[segmentStartIndex - 1],
|
28867 | segmentStart,
|
28868 | segmentEnd,
|
28869 | waypoints[segmentEndIndex + 1]
|
28870 | ];
|
28871 |
|
28872 | if (segmentStartIndex < 2) {
|
28873 | referenceWaypoints.unshift(mid(connection.source));
|
28874 | }
|
28875 |
|
28876 | if (segmentEndIndex > waypoints.length - 3) {
|
28877 | referenceWaypoints.unshift(mid(connection.target));
|
28878 | }
|
28879 |
|
28880 | context.snapPoints = snapPoints = { horizontal: [] , vertical: [] };
|
28881 |
|
28882 | forEach(referenceWaypoints, function(p) {
|
28883 |
|
28884 |
|
28885 |
|
28886 | if (p) {
|
28887 | p = p.original || p;
|
28888 |
|
28889 | if (axis === 'y') {
|
28890 | snapPoints.horizontal.push(p.y);
|
28891 | }
|
28892 |
|
28893 | if (axis === 'x') {
|
28894 | snapPoints.vertical.push(p.x);
|
28895 | }
|
28896 | }
|
28897 | });
|
28898 |
|
28899 | return snapPoints;
|
28900 | }
|
28901 |
|
28902 | eventBus.on('connectionSegment.move.move', 1500, function(event) {
|
28903 | var context = event.context,
|
28904 | snapPoints = getConnectionSegmentSnaps(context),
|
28905 | x = event.x,
|
28906 | y = event.y,
|
28907 | sx, sy;
|
28908 |
|
28909 | if (!snapPoints) {
|
28910 | return;
|
28911 | }
|
28912 |
|
28913 |
|
28914 | sx = snapTo(snapPoints.vertical, x);
|
28915 | sy = snapTo(snapPoints.horizontal, y);
|
28916 |
|
28917 |
|
28918 |
|
28919 | var cx = (x - sx),
|
28920 | cy = (y - sy);
|
28921 |
|
28922 |
|
28923 | assign(event, {
|
28924 | dx: event.dx - cx,
|
28925 | dy: event.dy - cy,
|
28926 | x: sx,
|
28927 | y: sy
|
28928 | });
|
28929 |
|
28930 |
|
28931 | if (cx || snapPoints.vertical.indexOf(x) !== -1) {
|
28932 | setSnapped(event, 'x', sx);
|
28933 | }
|
28934 |
|
28935 | if (cy || snapPoints.horizontal.indexOf(y) !== -1) {
|
28936 | setSnapped(event, 'y', sy);
|
28937 | }
|
28938 | });
|
28939 |
|
28940 |
|
28941 |
|
28942 |
|
28943 | function getBendpointSnaps(context) {
|
28944 |
|
28945 | var snapPoints = context.snapPoints,
|
28946 | waypoints = context.connection.waypoints,
|
28947 | bendpointIndex = context.bendpointIndex;
|
28948 |
|
28949 | if (snapPoints) {
|
28950 | return snapPoints;
|
28951 | }
|
28952 |
|
28953 | var referenceWaypoints = [ waypoints[bendpointIndex - 1], waypoints[bendpointIndex + 1] ];
|
28954 |
|
28955 | context.snapPoints = snapPoints = { horizontal: [] , vertical: [] };
|
28956 |
|
28957 | forEach(referenceWaypoints, function(p) {
|
28958 |
|
28959 |
|
28960 |
|
28961 | if (p) {
|
28962 | p = p.original || p;
|
28963 |
|
28964 | snapPoints.horizontal.push(p.y);
|
28965 | snapPoints.vertical.push(p.x);
|
28966 | }
|
28967 | });
|
28968 |
|
28969 | return snapPoints;
|
28970 | }
|
28971 |
|
28972 |
|
28973 | eventBus.on([ 'bendpoint.move.move', 'bendpoint.move.end' ], 1500, function(event) {
|
28974 |
|
28975 | var context = event.context,
|
28976 | snapPoints = getBendpointSnaps(context),
|
28977 | hover = context.hover,
|
28978 | hoverMid = hover && mid(hover),
|
28979 | x = event.x,
|
28980 | y = event.y,
|
28981 | sx, sy;
|
28982 |
|
28983 | if (!snapPoints) {
|
28984 | return;
|
28985 | }
|
28986 |
|
28987 |
|
28988 | sx = snapTo(hoverMid ? snapPoints.vertical.concat([ hoverMid.x ]) : snapPoints.vertical, x);
|
28989 | sy = snapTo(hoverMid ? snapPoints.horizontal.concat([ hoverMid.y ]) : snapPoints.horizontal, y);
|
28990 |
|
28991 |
|
28992 | var cx = (x - sx),
|
28993 | cy = (y - sy);
|
28994 |
|
28995 |
|
28996 | assign(event, {
|
28997 | dx: event.dx - cx,
|
28998 | dy: event.dy - cy,
|
28999 | x: event.x - cx,
|
29000 | y: event.y - cy
|
29001 | });
|
29002 |
|
29003 |
|
29004 | if (cx || snapPoints.vertical.indexOf(x) !== -1) {
|
29005 | setSnapped(event, 'x', sx);
|
29006 | }
|
29007 |
|
29008 | if (cy || snapPoints.horizontal.indexOf(y) !== -1) {
|
29009 | setSnapped(event, 'y', sy);
|
29010 | }
|
29011 | });
|
29012 | }
|
29013 |
|
29014 |
|
29015 | BendpointSnapping.$inject = [ 'eventBus' ];
|
29016 |
|
29017 | var BendpointsModule = {
|
29018 | __depends__: [
|
29019 | DraggingModule,
|
29020 | RulesModule
|
29021 | ],
|
29022 | __init__: [ 'bendpoints', 'bendpointSnapping', 'bendpointMovePreview' ],
|
29023 | bendpoints: [ 'type', Bendpoints ],
|
29024 | bendpointMove: [ 'type', BendpointMove ],
|
29025 | bendpointMovePreview: [ 'type', BendpointMovePreview ],
|
29026 | connectionSegmentMove: [ 'type', ConnectionSegmentMove ],
|
29027 | bendpointSnapping: [ 'type', BendpointSnapping ]
|
29028 | };
|
29029 |
|
29030 | function Connect(eventBus, dragging, modeling, rules) {
|
29031 |
|
29032 |
|
29033 |
|
29034 | function canConnect(source, target) {
|
29035 | return rules.allowed('connection.create', {
|
29036 | source: source,
|
29037 | target: target
|
29038 | });
|
29039 | }
|
29040 |
|
29041 | function canConnectReverse(source, target) {
|
29042 | return canConnect(target, source);
|
29043 | }
|
29044 |
|
29045 |
|
29046 |
|
29047 |
|
29048 | eventBus.on('connect.hover', function(event) {
|
29049 | var context = event.context,
|
29050 | start = context.start,
|
29051 | hover = event.hover,
|
29052 | canExecute;
|
29053 |
|
29054 |
|
29055 | context.hover = hover;
|
29056 |
|
29057 | canExecute = context.canExecute = canConnect(start, hover);
|
29058 |
|
29059 |
|
29060 | if (isNil(canExecute)) {
|
29061 | return;
|
29062 | }
|
29063 |
|
29064 | if (canExecute !== false) {
|
29065 | context.source = start;
|
29066 | context.target = hover;
|
29067 |
|
29068 | return;
|
29069 | }
|
29070 |
|
29071 | canExecute = context.canExecute = canConnectReverse(start, hover);
|
29072 |
|
29073 |
|
29074 | if (isNil(canExecute)) {
|
29075 | return;
|
29076 | }
|
29077 |
|
29078 | if (canExecute !== false) {
|
29079 | context.source = hover;
|
29080 | context.target = start;
|
29081 | }
|
29082 | });
|
29083 |
|
29084 | eventBus.on([ 'connect.out', 'connect.cleanup' ], function(event) {
|
29085 | var context = event.context;
|
29086 |
|
29087 | context.hover = null;
|
29088 | context.source = null;
|
29089 | context.target = null;
|
29090 |
|
29091 | context.canExecute = false;
|
29092 | });
|
29093 |
|
29094 | eventBus.on('connect.end', function(event) {
|
29095 | var context = event.context,
|
29096 | canExecute = context.canExecute,
|
29097 | connectionStart = context.connectionStart,
|
29098 | connectionEnd = {
|
29099 | x: event.x,
|
29100 | y: event.y
|
29101 | },
|
29102 | source = context.source,
|
29103 | target = context.target;
|
29104 |
|
29105 | if (!canExecute) {
|
29106 | return false;
|
29107 | }
|
29108 |
|
29109 | var attrs = null,
|
29110 | hints = {
|
29111 | connectionStart: isReverse$1(context) ? connectionEnd : connectionStart,
|
29112 | connectionEnd: isReverse$1(context) ? connectionStart : connectionEnd
|
29113 | };
|
29114 |
|
29115 | if (isObject(canExecute)) {
|
29116 | attrs = canExecute;
|
29117 | }
|
29118 |
|
29119 | modeling.connect(source, target, attrs, hints);
|
29120 | });
|
29121 |
|
29122 |
|
29123 |
|
29124 |
|
29125 | |
29126 |
|
29127 |
|
29128 |
|
29129 |
|
29130 |
|
29131 |
|
29132 |
|
29133 | this.start = function(event, start, connectionStart, autoActivate) {
|
29134 | if (!isObject(connectionStart)) {
|
29135 | autoActivate = connectionStart;
|
29136 | connectionStart = getMid(start);
|
29137 | }
|
29138 |
|
29139 | dragging.init(event, 'connect', {
|
29140 | autoActivate: autoActivate,
|
29141 | data: {
|
29142 | shape: start,
|
29143 | context: {
|
29144 | start: start,
|
29145 | connectionStart: connectionStart
|
29146 | }
|
29147 | }
|
29148 | });
|
29149 | };
|
29150 | }
|
29151 |
|
29152 | Connect.$inject = [
|
29153 | 'eventBus',
|
29154 | 'dragging',
|
29155 | 'modeling',
|
29156 | 'rules'
|
29157 | ];
|
29158 |
|
29159 |
|
29160 |
|
29161 |
|
29162 | function isReverse$1(context) {
|
29163 | var hover = context.hover,
|
29164 | source = context.source,
|
29165 | target = context.target;
|
29166 |
|
29167 | return hover && source && hover === source && source !== target;
|
29168 | }
|
29169 |
|
29170 | var HIGH_PRIORITY$2 = 1100,
|
29171 | LOW_PRIORITY$4 = 900;
|
29172 |
|
29173 | var MARKER_OK$1 = 'connect-ok',
|
29174 | MARKER_NOT_OK$1 = 'connect-not-ok';
|
29175 |
|
29176 | |
29177 |
|
29178 |
|
29179 |
|
29180 |
|
29181 |
|
29182 |
|
29183 | function ConnectPreview(injector, eventBus, canvas) {
|
29184 | var connectionPreview = injector.get('connectionPreview', false);
|
29185 |
|
29186 | connectionPreview && eventBus.on('connect.move', function(event) {
|
29187 | var context = event.context,
|
29188 | canConnect = context.canExecute,
|
29189 | hover = context.hover,
|
29190 | source = context.source,
|
29191 | start = context.start,
|
29192 | startPosition = context.startPosition,
|
29193 | target = context.target;
|
29194 |
|
29195 | var connectionStart = isReverse$1(context) ? {
|
29196 | x: event.x,
|
29197 | y: event.y
|
29198 | } : startPosition;
|
29199 |
|
29200 | var connectionEnd = isReverse$1(context) ? startPosition : {
|
29201 | x: event.x,
|
29202 | y: event.y
|
29203 | };
|
29204 |
|
29205 | connectionPreview.drawPreview(context, canConnect, {
|
29206 | source: source || start,
|
29207 | target: target || hover,
|
29208 | connectionStart: connectionStart,
|
29209 | connectionEnd: connectionEnd
|
29210 | });
|
29211 | });
|
29212 |
|
29213 | eventBus.on('connect.hover', LOW_PRIORITY$4, function(event) {
|
29214 | var context = event.context,
|
29215 | hover = event.hover,
|
29216 | canExecute = context.canExecute;
|
29217 |
|
29218 |
|
29219 | if (canExecute === null) {
|
29220 | return;
|
29221 | }
|
29222 |
|
29223 | canvas.addMarker(hover, canExecute ? MARKER_OK$1 : MARKER_NOT_OK$1);
|
29224 | });
|
29225 |
|
29226 | eventBus.on([
|
29227 | 'connect.out',
|
29228 | 'connect.cleanup'
|
29229 | ], HIGH_PRIORITY$2, function(event) {
|
29230 | var hover = event.hover;
|
29231 |
|
29232 | if (hover) {
|
29233 | canvas.removeMarker(hover, MARKER_OK$1);
|
29234 | canvas.removeMarker(hover, MARKER_NOT_OK$1);
|
29235 | }
|
29236 | });
|
29237 |
|
29238 | connectionPreview && eventBus.on('connect.cleanup', function(event) {
|
29239 | connectionPreview.cleanUp(event.context);
|
29240 | });
|
29241 | }
|
29242 |
|
29243 | ConnectPreview.$inject = [
|
29244 | 'injector',
|
29245 | 'eventBus',
|
29246 | 'canvas'
|
29247 | ];
|
29248 |
|
29249 | var ConnectModule = {
|
29250 | __depends__: [
|
29251 | SelectionModule,
|
29252 | RulesModule,
|
29253 | DraggingModule
|
29254 | ],
|
29255 | __init__: [
|
29256 | 'connectPreview'
|
29257 | ],
|
29258 | connect: [ 'type', Connect ],
|
29259 | connectPreview: [ 'type', ConnectPreview ]
|
29260 | };
|
29261 |
|
29262 | var MARKER_CONNECTION_PREVIEW = 'djs-connection-preview';
|
29263 |
|
29264 | |
29265 |
|
29266 |
|
29267 |
|
29268 |
|
29269 |
|
29270 |
|
29271 |
|
29272 |
|
29273 | function ConnectionPreview(
|
29274 | injector,
|
29275 | canvas,
|
29276 | graphicsFactory,
|
29277 | elementFactory
|
29278 | ) {
|
29279 | this._canvas = canvas;
|
29280 | this._graphicsFactory = graphicsFactory;
|
29281 | this._elementFactory = elementFactory;
|
29282 |
|
29283 |
|
29284 | this._connectionDocking = injector.get('connectionDocking', false);
|
29285 | this._layouter = injector.get('layouter', false);
|
29286 | }
|
29287 |
|
29288 | ConnectionPreview.$inject = [
|
29289 | 'injector',
|
29290 | 'canvas',
|
29291 | 'graphicsFactory',
|
29292 | 'elementFactory'
|
29293 | ];
|
29294 |
|
29295 | |
29296 |
|
29297 |
|
29298 |
|
29299 |
|
29300 |
|
29301 |
|
29302 |
|
29303 |
|
29304 |
|
29305 |
|
29306 |
|
29307 |
|
29308 |
|
29309 |
|
29310 |
|
29311 |
|
29312 |
|
29313 | ConnectionPreview.prototype.drawPreview = function(context, canConnect, hints) {
|
29314 |
|
29315 | hints = hints || {};
|
29316 |
|
29317 | var connectionPreviewGfx = context.connectionPreviewGfx,
|
29318 | getConnection = context.getConnection,
|
29319 | source = hints.source,
|
29320 | target = hints.target,
|
29321 | waypoints = hints.waypoints,
|
29322 | connectionStart = hints.connectionStart,
|
29323 | connectionEnd = hints.connectionEnd,
|
29324 | noLayout = hints.noLayout,
|
29325 | noCropping = hints.noCropping,
|
29326 | noNoop = hints.noNoop,
|
29327 | connection;
|
29328 |
|
29329 | var self = this;
|
29330 |
|
29331 | if (!connectionPreviewGfx) {
|
29332 | connectionPreviewGfx = context.connectionPreviewGfx = this.createConnectionPreviewGfx();
|
29333 | }
|
29334 |
|
29335 | clear$1(connectionPreviewGfx);
|
29336 |
|
29337 | if (!getConnection) {
|
29338 | getConnection = context.getConnection = cacheReturnValues(function(canConnect, source, target) {
|
29339 | return self.getConnection(canConnect, source, target);
|
29340 | });
|
29341 | }
|
29342 |
|
29343 | if (canConnect) {
|
29344 | connection = getConnection(canConnect, source, target);
|
29345 | }
|
29346 |
|
29347 | if (!connection) {
|
29348 | !noNoop && this.drawNoopPreview(connectionPreviewGfx, hints);
|
29349 | return;
|
29350 | }
|
29351 |
|
29352 | connection.waypoints = waypoints || [];
|
29353 |
|
29354 |
|
29355 | if (this._layouter && !noLayout) {
|
29356 | connection.waypoints = this._layouter.layoutConnection(connection, {
|
29357 | source: source,
|
29358 | target: target,
|
29359 | connectionStart: connectionStart,
|
29360 | connectionEnd: connectionEnd,
|
29361 | waypoints: hints.waypoints || connection.waypoints
|
29362 | });
|
29363 | }
|
29364 |
|
29365 |
|
29366 | if (!connection.waypoints || !connection.waypoints.length) {
|
29367 | connection.waypoints = [
|
29368 | source ? getMid(source) : connectionStart,
|
29369 | target ? getMid(target) : connectionEnd
|
29370 | ];
|
29371 | }
|
29372 |
|
29373 |
|
29374 | if (this._connectionDocking && (source || target) && !noCropping) {
|
29375 | connection.waypoints = this._connectionDocking.getCroppedWaypoints(connection, source, target);
|
29376 | }
|
29377 |
|
29378 | this._graphicsFactory.drawConnection(connectionPreviewGfx, connection);
|
29379 | };
|
29380 |
|
29381 | |
29382 |
|
29383 |
|
29384 |
|
29385 |
|
29386 |
|
29387 |
|
29388 |
|
29389 |
|
29390 |
|
29391 | ConnectionPreview.prototype.drawNoopPreview = function(connectionPreviewGfx, hints) {
|
29392 | var source = hints.source,
|
29393 | target = hints.target,
|
29394 | start = hints.connectionStart || getMid(source),
|
29395 | end = hints.connectionEnd || getMid(target);
|
29396 |
|
29397 | var waypoints = this.cropWaypoints(start, end, source, target);
|
29398 |
|
29399 | var connection = this.createNoopConnection(waypoints[0], waypoints[1]);
|
29400 |
|
29401 | append(connectionPreviewGfx, connection);
|
29402 | };
|
29403 |
|
29404 | |
29405 |
|
29406 |
|
29407 |
|
29408 |
|
29409 |
|
29410 |
|
29411 |
|
29412 |
|
29413 |
|
29414 | ConnectionPreview.prototype.cropWaypoints = function(start, end, source, target) {
|
29415 | var graphicsFactory = this._graphicsFactory,
|
29416 | sourcePath = source && graphicsFactory.getShapePath(source),
|
29417 | targetPath = target && graphicsFactory.getShapePath(target),
|
29418 | connectionPath = graphicsFactory.getConnectionPath({ waypoints: [ start, end ] });
|
29419 |
|
29420 | start = (source && getElementLineIntersection(sourcePath, connectionPath, true)) || start;
|
29421 | end = (target && getElementLineIntersection(targetPath, connectionPath, false)) || end;
|
29422 |
|
29423 | return [ start, end ];
|
29424 | };
|
29425 |
|
29426 | |
29427 |
|
29428 |
|
29429 |
|
29430 |
|
29431 |
|
29432 | ConnectionPreview.prototype.cleanUp = function(context) {
|
29433 | if (context && context.connectionPreviewGfx) {
|
29434 | remove$1(context.connectionPreviewGfx);
|
29435 | }
|
29436 | };
|
29437 |
|
29438 | |
29439 |
|
29440 |
|
29441 |
|
29442 |
|
29443 |
|
29444 |
|
29445 | ConnectionPreview.prototype.getConnection = function(canConnect) {
|
29446 | var attrs = ensureConnectionAttrs(canConnect);
|
29447 |
|
29448 | return this._elementFactory.createConnection(attrs);
|
29449 | };
|
29450 |
|
29451 |
|
29452 | |
29453 |
|
29454 |
|
29455 |
|
29456 |
|
29457 | ConnectionPreview.prototype.createConnectionPreviewGfx = function() {
|
29458 | var gfx = create('g');
|
29459 |
|
29460 | attr$1(gfx, {
|
29461 | pointerEvents: 'none'
|
29462 | });
|
29463 |
|
29464 | classes$1(gfx).add(MARKER_CONNECTION_PREVIEW);
|
29465 |
|
29466 | append(this._canvas.getDefaultLayer(), gfx);
|
29467 |
|
29468 | return gfx;
|
29469 | };
|
29470 |
|
29471 | |
29472 |
|
29473 |
|
29474 |
|
29475 |
|
29476 |
|
29477 |
|
29478 |
|
29479 | ConnectionPreview.prototype.createNoopConnection = function(start, end) {
|
29480 | var connection = create('polyline');
|
29481 |
|
29482 | attr$1(connection, {
|
29483 | 'stroke': '#333',
|
29484 | 'strokeDasharray': [ 1 ],
|
29485 | 'strokeWidth': 2,
|
29486 | 'pointer-events': 'none'
|
29487 | });
|
29488 |
|
29489 | attr$1(connection, { 'points': [ start.x, start.y, end.x, end.y ] });
|
29490 |
|
29491 | return connection;
|
29492 | };
|
29493 |
|
29494 |
|
29495 |
|
29496 | |
29497 |
|
29498 |
|
29499 |
|
29500 |
|
29501 |
|
29502 |
|
29503 | function cacheReturnValues(fn) {
|
29504 | var returnValues = {};
|
29505 |
|
29506 | |
29507 |
|
29508 |
|
29509 |
|
29510 |
|
29511 | return function(firstArgument) {
|
29512 | var key = JSON.stringify(firstArgument);
|
29513 |
|
29514 | var returnValue = returnValues[key];
|
29515 |
|
29516 | if (!returnValue) {
|
29517 | returnValue = returnValues[key] = fn.apply(null, arguments);
|
29518 | }
|
29519 |
|
29520 | return returnValue;
|
29521 | };
|
29522 | }
|
29523 |
|
29524 | |
29525 |
|
29526 |
|
29527 |
|
29528 |
|
29529 |
|
29530 |
|
29531 | function ensureConnectionAttrs(canConnect) {
|
29532 | if (isObject(canConnect)) {
|
29533 | return canConnect;
|
29534 | } else {
|
29535 | return {};
|
29536 | }
|
29537 | }
|
29538 |
|
29539 | var ConnectionPreviewModule = {
|
29540 | __init__: [ 'connectionPreview' ],
|
29541 | connectionPreview: [ 'type', ConnectionPreview ]
|
29542 | };
|
29543 |
|
29544 | var min = Math.min,
|
29545 | max$1 = Math.max;
|
29546 |
|
29547 | function preventDefault$1(e) {
|
29548 | e.preventDefault();
|
29549 | }
|
29550 |
|
29551 | function stopPropagation$1(e) {
|
29552 | e.stopPropagation();
|
29553 | }
|
29554 |
|
29555 | function isTextNode(node) {
|
29556 | return node.nodeType === Node.TEXT_NODE;
|
29557 | }
|
29558 |
|
29559 | function toArray(nodeList) {
|
29560 | return [].slice.call(nodeList);
|
29561 | }
|
29562 |
|
29563 | |
29564 |
|
29565 |
|
29566 |
|
29567 |
|
29568 |
|
29569 |
|
29570 |
|
29571 |
|
29572 |
|
29573 |
|
29574 |
|
29575 |
|
29576 |
|
29577 |
|
29578 | function TextBox(options) {
|
29579 | this.container = options.container;
|
29580 |
|
29581 | this.parent = domify(
|
29582 | '<div class="djs-direct-editing-parent">' +
|
29583 | '<div class="djs-direct-editing-content" contenteditable="true"></div>' +
|
29584 | '</div>'
|
29585 | );
|
29586 |
|
29587 | this.content = query('[contenteditable]', this.parent);
|
29588 |
|
29589 | this.keyHandler = options.keyHandler || function() {};
|
29590 | this.resizeHandler = options.resizeHandler || function() {};
|
29591 |
|
29592 | this.autoResize = bind(this.autoResize, this);
|
29593 | this.handlePaste = bind(this.handlePaste, this);
|
29594 | }
|
29595 |
|
29596 |
|
29597 | |
29598 |
|
29599 |
|
29600 |
|
29601 |
|
29602 |
|
29603 |
|
29604 |
|
29605 |
|
29606 |
|
29607 |
|
29608 |
|
29609 |
|
29610 |
|
29611 |
|
29612 |
|
29613 |
|
29614 | TextBox.prototype.create = function(bounds, style, value, options) {
|
29615 | var self = this;
|
29616 |
|
29617 | var parent = this.parent,
|
29618 | content = this.content,
|
29619 | container = this.container;
|
29620 |
|
29621 | options = this.options = options || {};
|
29622 |
|
29623 | style = this.style = style || {};
|
29624 |
|
29625 | var parentStyle = pick(style, [
|
29626 | 'width',
|
29627 | 'height',
|
29628 | 'maxWidth',
|
29629 | 'maxHeight',
|
29630 | 'minWidth',
|
29631 | 'minHeight',
|
29632 | 'left',
|
29633 | 'top',
|
29634 | 'backgroundColor',
|
29635 | 'position',
|
29636 | 'overflow',
|
29637 | 'border',
|
29638 | 'wordWrap',
|
29639 | 'textAlign',
|
29640 | 'outline',
|
29641 | 'transform'
|
29642 | ]);
|
29643 |
|
29644 | assign(parent.style, {
|
29645 | width: bounds.width + 'px',
|
29646 | height: bounds.height + 'px',
|
29647 | maxWidth: bounds.maxWidth + 'px',
|
29648 | maxHeight: bounds.maxHeight + 'px',
|
29649 | minWidth: bounds.minWidth + 'px',
|
29650 | minHeight: bounds.minHeight + 'px',
|
29651 | left: bounds.x + 'px',
|
29652 | top: bounds.y + 'px',
|
29653 | backgroundColor: '#ffffff',
|
29654 | position: 'absolute',
|
29655 | overflow: 'visible',
|
29656 | border: '1px solid #ccc',
|
29657 | boxSizing: 'border-box',
|
29658 | wordWrap: 'normal',
|
29659 | textAlign: 'center',
|
29660 | outline: 'none'
|
29661 | }, parentStyle);
|
29662 |
|
29663 | var contentStyle = pick(style, [
|
29664 | 'fontFamily',
|
29665 | 'fontSize',
|
29666 | 'fontWeight',
|
29667 | 'lineHeight',
|
29668 | 'padding',
|
29669 | 'paddingTop',
|
29670 | 'paddingRight',
|
29671 | 'paddingBottom',
|
29672 | 'paddingLeft'
|
29673 | ]);
|
29674 |
|
29675 | assign(content.style, {
|
29676 | boxSizing: 'border-box',
|
29677 | width: '100%',
|
29678 | outline: 'none',
|
29679 | wordWrap: 'break-word'
|
29680 | }, contentStyle);
|
29681 |
|
29682 | if (options.centerVertically) {
|
29683 | assign(content.style, {
|
29684 | position: 'absolute',
|
29685 | top: '50%',
|
29686 | transform: 'translate(0, -50%)'
|
29687 | }, contentStyle);
|
29688 | }
|
29689 |
|
29690 | content.innerText = value;
|
29691 |
|
29692 | componentEvent.bind(content, 'keydown', this.keyHandler);
|
29693 | componentEvent.bind(content, 'mousedown', stopPropagation$1);
|
29694 | componentEvent.bind(content, 'paste', self.handlePaste);
|
29695 |
|
29696 | if (options.autoResize) {
|
29697 | componentEvent.bind(content, 'input', this.autoResize);
|
29698 | }
|
29699 |
|
29700 | if (options.resizable) {
|
29701 | this.resizable(style);
|
29702 | }
|
29703 |
|
29704 | container.appendChild(parent);
|
29705 |
|
29706 |
|
29707 | this.setSelection(content.lastChild, content.lastChild && content.lastChild.length);
|
29708 |
|
29709 | return parent;
|
29710 | };
|
29711 |
|
29712 | |
29713 |
|
29714 |
|
29715 | TextBox.prototype.handlePaste = function(e) {
|
29716 | var options = this.options,
|
29717 | style = this.style;
|
29718 |
|
29719 | e.preventDefault();
|
29720 |
|
29721 | var text;
|
29722 |
|
29723 | if (e.clipboardData) {
|
29724 |
|
29725 |
|
29726 | text = e.clipboardData.getData('text/plain');
|
29727 | } else {
|
29728 |
|
29729 |
|
29730 | text = window.clipboardData.getData('Text');
|
29731 | }
|
29732 |
|
29733 | this.insertText(text);
|
29734 |
|
29735 | if (options.autoResize) {
|
29736 | var hasResized = this.autoResize(style);
|
29737 |
|
29738 | if (hasResized) {
|
29739 | this.resizeHandler(hasResized);
|
29740 | }
|
29741 | }
|
29742 | };
|
29743 |
|
29744 | TextBox.prototype.insertText = function(text) {
|
29745 |
|
29746 |
|
29747 | var success = document.execCommand('insertText', false, text);
|
29748 |
|
29749 | if (success) {
|
29750 | return;
|
29751 | }
|
29752 |
|
29753 | this._insertTextIE(text);
|
29754 | };
|
29755 |
|
29756 | TextBox.prototype._insertTextIE = function(text) {
|
29757 |
|
29758 |
|
29759 | var range = this.getSelection(),
|
29760 | startContainer = range.startContainer,
|
29761 | endContainer = range.endContainer,
|
29762 | startOffset = range.startOffset,
|
29763 | endOffset = range.endOffset,
|
29764 | commonAncestorContainer = range.commonAncestorContainer;
|
29765 |
|
29766 | var childNodesArray = toArray(commonAncestorContainer.childNodes);
|
29767 |
|
29768 | var container,
|
29769 | offset;
|
29770 |
|
29771 | if (isTextNode(commonAncestorContainer)) {
|
29772 | var containerTextContent = startContainer.textContent;
|
29773 |
|
29774 | startContainer.textContent =
|
29775 | containerTextContent.substring(0, startOffset)
|
29776 | + text
|
29777 | + containerTextContent.substring(endOffset);
|
29778 |
|
29779 | container = startContainer;
|
29780 | offset = startOffset + text.length;
|
29781 |
|
29782 | } else if (startContainer === this.content && endContainer === this.content) {
|
29783 | var textNode = document.createTextNode(text);
|
29784 |
|
29785 | this.content.insertBefore(textNode, childNodesArray[startOffset]);
|
29786 |
|
29787 | container = textNode;
|
29788 | offset = textNode.textContent.length;
|
29789 | } else {
|
29790 | var startContainerChildIndex = childNodesArray.indexOf(startContainer),
|
29791 | endContainerChildIndex = childNodesArray.indexOf(endContainer);
|
29792 |
|
29793 | childNodesArray.forEach(function(childNode, index) {
|
29794 |
|
29795 | if (index === startContainerChildIndex) {
|
29796 | childNode.textContent =
|
29797 | startContainer.textContent.substring(0, startOffset) +
|
29798 | text +
|
29799 | endContainer.textContent.substring(endOffset);
|
29800 | } else if (index > startContainerChildIndex && index <= endContainerChildIndex) {
|
29801 | remove(childNode);
|
29802 | }
|
29803 | });
|
29804 |
|
29805 | container = startContainer;
|
29806 | offset = startOffset + text.length;
|
29807 | }
|
29808 |
|
29809 | if (container && offset !== undefined) {
|
29810 |
|
29811 |
|
29812 | setTimeout(function() {
|
29813 | self.setSelection(container, offset);
|
29814 | });
|
29815 | }
|
29816 | };
|
29817 |
|
29818 | |
29819 |
|
29820 |
|
29821 | TextBox.prototype.autoResize = function() {
|
29822 | var parent = this.parent,
|
29823 | content = this.content;
|
29824 |
|
29825 | var fontSize = parseInt(this.style.fontSize) || 12;
|
29826 |
|
29827 | if (content.scrollHeight > parent.offsetHeight ||
|
29828 | content.scrollHeight < parent.offsetHeight - fontSize) {
|
29829 | var bounds = parent.getBoundingClientRect();
|
29830 |
|
29831 | var height = content.scrollHeight;
|
29832 | parent.style.height = height + 'px';
|
29833 |
|
29834 | this.resizeHandler({
|
29835 | width: bounds.width,
|
29836 | height: bounds.height,
|
29837 | dx: 0,
|
29838 | dy: height - bounds.height
|
29839 | });
|
29840 | }
|
29841 | };
|
29842 |
|
29843 | |
29844 |
|
29845 |
|
29846 | TextBox.prototype.resizable = function() {
|
29847 | var self = this;
|
29848 |
|
29849 | var parent = this.parent,
|
29850 | resizeHandle = this.resizeHandle;
|
29851 |
|
29852 | var minWidth = parseInt(this.style.minWidth) || 0,
|
29853 | minHeight = parseInt(this.style.minHeight) || 0,
|
29854 | maxWidth = parseInt(this.style.maxWidth) || Infinity,
|
29855 | maxHeight = parseInt(this.style.maxHeight) || Infinity;
|
29856 |
|
29857 | if (!resizeHandle) {
|
29858 | resizeHandle = this.resizeHandle = domify(
|
29859 | '<div class="djs-direct-editing-resize-handle"></div>'
|
29860 | );
|
29861 |
|
29862 | var startX, startY, startWidth, startHeight;
|
29863 |
|
29864 | var onMouseDown = function(e) {
|
29865 | preventDefault$1(e);
|
29866 | stopPropagation$1(e);
|
29867 |
|
29868 | startX = e.clientX;
|
29869 | startY = e.clientY;
|
29870 |
|
29871 | var bounds = parent.getBoundingClientRect();
|
29872 |
|
29873 | startWidth = bounds.width;
|
29874 | startHeight = bounds.height;
|
29875 |
|
29876 | componentEvent.bind(document, 'mousemove', onMouseMove);
|
29877 | componentEvent.bind(document, 'mouseup', onMouseUp);
|
29878 | };
|
29879 |
|
29880 | var onMouseMove = function(e) {
|
29881 | preventDefault$1(e);
|
29882 | stopPropagation$1(e);
|
29883 |
|
29884 | var newWidth = min(max$1(startWidth + e.clientX - startX, minWidth), maxWidth);
|
29885 | var newHeight = min(max$1(startHeight + e.clientY - startY, minHeight), maxHeight);
|
29886 |
|
29887 | parent.style.width = newWidth + 'px';
|
29888 | parent.style.height = newHeight + 'px';
|
29889 |
|
29890 | self.resizeHandler({
|
29891 | width: startWidth,
|
29892 | height: startHeight,
|
29893 | dx: e.clientX - startX,
|
29894 | dy: e.clientY - startY
|
29895 | });
|
29896 | };
|
29897 |
|
29898 | var onMouseUp = function(e) {
|
29899 | preventDefault$1(e);
|
29900 | stopPropagation$1(e);
|
29901 |
|
29902 | componentEvent.unbind(document,'mousemove', onMouseMove, false);
|
29903 | componentEvent.unbind(document, 'mouseup', onMouseUp, false);
|
29904 | };
|
29905 |
|
29906 | componentEvent.bind(resizeHandle, 'mousedown', onMouseDown);
|
29907 | }
|
29908 |
|
29909 | assign(resizeHandle.style, {
|
29910 | position: 'absolute',
|
29911 | bottom: '0px',
|
29912 | right: '0px',
|
29913 | cursor: 'nwse-resize',
|
29914 | width: '0',
|
29915 | height: '0',
|
29916 | borderTop: (parseInt(this.style.fontSize) / 4 || 3) + 'px solid transparent',
|
29917 | borderRight: (parseInt(this.style.fontSize) / 4 || 3) + 'px solid #ccc',
|
29918 | borderBottom: (parseInt(this.style.fontSize) / 4 || 3) + 'px solid #ccc',
|
29919 | borderLeft: (parseInt(this.style.fontSize) / 4 || 3) + 'px solid transparent'
|
29920 | });
|
29921 |
|
29922 | parent.appendChild(resizeHandle);
|
29923 | };
|
29924 |
|
29925 |
|
29926 | |
29927 |
|
29928 |
|
29929 |
|
29930 | TextBox.prototype.destroy = function() {
|
29931 | var parent = this.parent,
|
29932 | content = this.content,
|
29933 | resizeHandle = this.resizeHandle;
|
29934 |
|
29935 |
|
29936 | content.innerText = '';
|
29937 |
|
29938 |
|
29939 | parent.removeAttribute('style');
|
29940 | content.removeAttribute('style');
|
29941 |
|
29942 | componentEvent.unbind(content, 'keydown', this.keyHandler);
|
29943 | componentEvent.unbind(content, 'mousedown', stopPropagation$1);
|
29944 | componentEvent.unbind(content, 'input', this.autoResize);
|
29945 | componentEvent.unbind(content, 'paste', this.handlePaste);
|
29946 |
|
29947 | if (resizeHandle) {
|
29948 | resizeHandle.removeAttribute('style');
|
29949 |
|
29950 | remove(resizeHandle);
|
29951 | }
|
29952 |
|
29953 | remove(parent);
|
29954 | };
|
29955 |
|
29956 |
|
29957 | TextBox.prototype.getValue = function() {
|
29958 | return this.content.innerText.trim();
|
29959 | };
|
29960 |
|
29961 |
|
29962 | TextBox.prototype.getSelection = function() {
|
29963 | var selection = window.getSelection(),
|
29964 | range = selection.getRangeAt(0);
|
29965 |
|
29966 | return range;
|
29967 | };
|
29968 |
|
29969 |
|
29970 | TextBox.prototype.setSelection = function(container, offset) {
|
29971 | var range = document.createRange();
|
29972 |
|
29973 | if (container === null) {
|
29974 | range.selectNodeContents(this.content);
|
29975 | } else {
|
29976 | range.setStart(container, offset);
|
29977 | range.setEnd(container, offset);
|
29978 | }
|
29979 |
|
29980 | var selection = window.getSelection();
|
29981 |
|
29982 | selection.removeAllRanges();
|
29983 | selection.addRange(range);
|
29984 | };
|
29985 |
|
29986 | |
29987 |
|
29988 |
|
29989 |
|
29990 |
|
29991 |
|
29992 | function DirectEditing(eventBus, canvas) {
|
29993 |
|
29994 | this._eventBus = eventBus;
|
29995 |
|
29996 | this._providers = [];
|
29997 | this._textbox = new TextBox({
|
29998 | container: canvas.getContainer(),
|
29999 | keyHandler: bind(this._handleKey, this),
|
30000 | resizeHandler: bind(this._handleResize, this)
|
30001 | });
|
30002 | }
|
30003 |
|
30004 | DirectEditing.$inject = [ 'eventBus', 'canvas' ];
|
30005 |
|
30006 |
|
30007 | |
30008 |
|
30009 |
|
30010 |
|
30011 |
|
30012 |
|
30013 |
|
30014 |
|
30015 |
|
30016 | DirectEditing.prototype.registerProvider = function(provider) {
|
30017 | this._providers.push(provider);
|
30018 | };
|
30019 |
|
30020 |
|
30021 | |
30022 |
|
30023 |
|
30024 |
|
30025 |
|
30026 | DirectEditing.prototype.isActive = function() {
|
30027 | return !!this._active;
|
30028 | };
|
30029 |
|
30030 |
|
30031 | |
30032 |
|
30033 |
|
30034 | DirectEditing.prototype.cancel = function() {
|
30035 | if (!this._active) {
|
30036 | return;
|
30037 | }
|
30038 |
|
30039 | this._fire('cancel');
|
30040 | this.close();
|
30041 | };
|
30042 |
|
30043 |
|
30044 | DirectEditing.prototype._fire = function(event, context) {
|
30045 | this._eventBus.fire('directEditing.' + event, context || { active: this._active });
|
30046 | };
|
30047 |
|
30048 | DirectEditing.prototype.close = function() {
|
30049 | this._textbox.destroy();
|
30050 |
|
30051 | this._fire('deactivate');
|
30052 |
|
30053 | this._active = null;
|
30054 |
|
30055 | this.resizable = undefined;
|
30056 | };
|
30057 |
|
30058 |
|
30059 | DirectEditing.prototype.complete = function() {
|
30060 |
|
30061 | var active = this._active;
|
30062 |
|
30063 | if (!active) {
|
30064 | return;
|
30065 | }
|
30066 |
|
30067 | var containerBounds,
|
30068 | previousBounds = active.context.bounds,
|
30069 | newBounds = this.$textbox.getBoundingClientRect(),
|
30070 | newText = this.getValue(),
|
30071 | previousText = active.context.text;
|
30072 |
|
30073 | if (
|
30074 | newText !== previousText ||
|
30075 | newBounds.height !== previousBounds.height ||
|
30076 | newBounds.width !== previousBounds.width
|
30077 | ) {
|
30078 | containerBounds = this._textbox.container.getBoundingClientRect();
|
30079 |
|
30080 | active.provider.update(active.element, newText, active.context.text, {
|
30081 | x: newBounds.left - containerBounds.left,
|
30082 | y: newBounds.top - containerBounds.top,
|
30083 | width: newBounds.width,
|
30084 | height: newBounds.height
|
30085 | });
|
30086 | }
|
30087 |
|
30088 | this._fire('complete');
|
30089 |
|
30090 | this.close();
|
30091 | };
|
30092 |
|
30093 |
|
30094 | DirectEditing.prototype.getValue = function() {
|
30095 | return this._textbox.getValue();
|
30096 | };
|
30097 |
|
30098 |
|
30099 | DirectEditing.prototype._handleKey = function(e) {
|
30100 |
|
30101 |
|
30102 | e.stopPropagation();
|
30103 |
|
30104 | var key = e.keyCode || e.charCode;
|
30105 |
|
30106 |
|
30107 | if (key === 27) {
|
30108 | e.preventDefault();
|
30109 | return this.cancel();
|
30110 | }
|
30111 |
|
30112 |
|
30113 | if (key === 13 && !e.shiftKey) {
|
30114 | e.preventDefault();
|
30115 | return this.complete();
|
30116 | }
|
30117 | };
|
30118 |
|
30119 |
|
30120 | DirectEditing.prototype._handleResize = function(event) {
|
30121 | this._fire('resize', event);
|
30122 | };
|
30123 |
|
30124 |
|
30125 | |
30126 |
|
30127 |
|
30128 |
|
30129 |
|
30130 |
|
30131 | DirectEditing.prototype.activate = function(element) {
|
30132 | if (this.isActive()) {
|
30133 | this.cancel();
|
30134 | }
|
30135 |
|
30136 |
|
30137 | var context;
|
30138 |
|
30139 | var provider = find(this._providers, function(p) {
|
30140 | return (context = p.activate(element)) ? p : null;
|
30141 | });
|
30142 |
|
30143 |
|
30144 | if (context) {
|
30145 | this.$textbox = this._textbox.create(
|
30146 | context.bounds,
|
30147 | context.style,
|
30148 | context.text,
|
30149 | context.options
|
30150 | );
|
30151 |
|
30152 | this._active = {
|
30153 | element: element,
|
30154 | context: context,
|
30155 | provider: provider
|
30156 | };
|
30157 |
|
30158 | if (context.options && context.options.resizable) {
|
30159 | this.resizable = true;
|
30160 | }
|
30161 |
|
30162 | this._fire('activate');
|
30163 | }
|
30164 |
|
30165 | return !!context;
|
30166 | };
|
30167 |
|
30168 | var DirectEditingModule = {
|
30169 | __depends__: [
|
30170 | InteractionEventsModule
|
30171 | ],
|
30172 | __init__: [ 'directEditing' ],
|
30173 | directEditing: [ 'type', DirectEditing ]
|
30174 | };
|
30175 |
|
30176 | var entrySelector = '.entry';
|
30177 |
|
30178 | var DEFAULT_PRIORITY$3 = 1000;
|
30179 |
|
30180 |
|
30181 | |
30182 |
|
30183 |
|
30184 |
|
30185 |
|
30186 |
|
30187 |
|
30188 |
|
30189 |
|
30190 |
|
30191 |
|
30192 | function ContextPad(config, eventBus, overlays) {
|
30193 |
|
30194 | this._eventBus = eventBus;
|
30195 | this._overlays = overlays;
|
30196 |
|
30197 | var scale = isDefined(config && config.scale) ? config.scale : {
|
30198 | min: 1,
|
30199 | max: 1.5
|
30200 | };
|
30201 |
|
30202 | this._overlaysConfig = {
|
30203 | position: {
|
30204 | right: -9,
|
30205 | top: -6
|
30206 | },
|
30207 | scale: scale
|
30208 | };
|
30209 |
|
30210 | this._current = null;
|
30211 |
|
30212 | this._init();
|
30213 | }
|
30214 |
|
30215 | ContextPad.$inject = [
|
30216 | 'config.contextPad',
|
30217 | 'eventBus',
|
30218 | 'overlays'
|
30219 | ];
|
30220 |
|
30221 |
|
30222 | |
30223 |
|
30224 |
|
30225 | ContextPad.prototype._init = function() {
|
30226 |
|
30227 | var eventBus = this._eventBus;
|
30228 |
|
30229 | var self = this;
|
30230 |
|
30231 | eventBus.on('selection.changed', function(e) {
|
30232 |
|
30233 | var selection = e.newSelection;
|
30234 |
|
30235 | if (selection.length === 1) {
|
30236 | self.open(selection[0]);
|
30237 | } else {
|
30238 | self.close();
|
30239 | }
|
30240 | });
|
30241 |
|
30242 | eventBus.on('elements.delete', function(event) {
|
30243 | var elements = event.elements;
|
30244 |
|
30245 | forEach(elements, function(e) {
|
30246 | if (self.isOpen(e)) {
|
30247 | self.close();
|
30248 | }
|
30249 | });
|
30250 | });
|
30251 |
|
30252 | eventBus.on('element.changed', function(event) {
|
30253 | var element = event.element,
|
30254 | current = self._current;
|
30255 |
|
30256 |
|
30257 | if (current && current.element === element) {
|
30258 | self.open(element, true);
|
30259 | }
|
30260 | });
|
30261 | };
|
30262 |
|
30263 |
|
30264 | |
30265 |
|
30266 |
|
30267 |
|
30268 |
|
30269 |
|
30270 |
|
30271 |
|
30272 |
|
30273 |
|
30274 |
|
30275 |
|
30276 |
|
30277 |
|
30278 |
|
30279 |
|
30280 |
|
30281 |
|
30282 |
|
30283 |
|
30284 |
|
30285 |
|
30286 |
|
30287 | ContextPad.prototype.registerProvider = function(priority, provider) {
|
30288 | if (!provider) {
|
30289 | provider = priority;
|
30290 | priority = DEFAULT_PRIORITY$3;
|
30291 | }
|
30292 |
|
30293 | this._eventBus.on('contextPad.getProviders', priority, function(event) {
|
30294 | event.providers.push(provider);
|
30295 | });
|
30296 | };
|
30297 |
|
30298 |
|
30299 | |
30300 |
|
30301 |
|
30302 |
|
30303 |
|
30304 |
|
30305 |
|
30306 | ContextPad.prototype.getEntries = function(element) {
|
30307 | var providers = this._getProviders();
|
30308 |
|
30309 | var entries = {};
|
30310 |
|
30311 |
|
30312 |
|
30313 | forEach(providers, function(provider) {
|
30314 | var entriesOrUpdater = provider.getContextPadEntries(element);
|
30315 |
|
30316 | if (isFunction(entriesOrUpdater)) {
|
30317 | entries = entriesOrUpdater(entries);
|
30318 | } else {
|
30319 | forEach(entriesOrUpdater, function(entry, id) {
|
30320 | entries[id] = entry;
|
30321 | });
|
30322 | }
|
30323 | });
|
30324 |
|
30325 | return entries;
|
30326 | };
|
30327 |
|
30328 |
|
30329 | |
30330 |
|
30331 |
|
30332 |
|
30333 |
|
30334 |
|
30335 |
|
30336 | ContextPad.prototype.trigger = function(action, event, autoActivate) {
|
30337 |
|
30338 | var element = this._current.element,
|
30339 | entries = this._current.entries,
|
30340 | entry,
|
30341 | handler,
|
30342 | originalEvent,
|
30343 | button = event.delegateTarget || event.target;
|
30344 |
|
30345 | if (!button) {
|
30346 | return event.preventDefault();
|
30347 | }
|
30348 |
|
30349 | entry = entries[attr(button, 'data-action')];
|
30350 | handler = entry.action;
|
30351 |
|
30352 | originalEvent = event.originalEvent || event;
|
30353 |
|
30354 |
|
30355 | if (isFunction(handler)) {
|
30356 | if (action === 'click') {
|
30357 | return handler(originalEvent, element, autoActivate);
|
30358 | }
|
30359 | } else {
|
30360 | if (handler[action]) {
|
30361 | return handler[action](originalEvent, element, autoActivate);
|
30362 | }
|
30363 | }
|
30364 |
|
30365 |
|
30366 | event.preventDefault();
|
30367 | };
|
30368 |
|
30369 |
|
30370 | |
30371 |
|
30372 |
|
30373 |
|
30374 |
|
30375 |
|
30376 | ContextPad.prototype.open = function(element, force) {
|
30377 | if (!force && this.isOpen(element)) {
|
30378 | return;
|
30379 | }
|
30380 |
|
30381 | this.close();
|
30382 | this._updateAndOpen(element);
|
30383 | };
|
30384 |
|
30385 | ContextPad.prototype._getProviders = function(id) {
|
30386 |
|
30387 | var event = this._eventBus.createEvent({
|
30388 | type: 'contextPad.getProviders',
|
30389 | providers: []
|
30390 | });
|
30391 |
|
30392 | this._eventBus.fire(event);
|
30393 |
|
30394 | return event.providers;
|
30395 | };
|
30396 |
|
30397 | ContextPad.prototype._updateAndOpen = function(element) {
|
30398 |
|
30399 | var entries = this.getEntries(element),
|
30400 | pad = this.getPad(element),
|
30401 | html = pad.html;
|
30402 |
|
30403 | forEach(entries, function(entry, id) {
|
30404 | var grouping = entry.group || 'default',
|
30405 | control = domify(entry.html || '<div class="entry" draggable="true"></div>'),
|
30406 | container;
|
30407 |
|
30408 | attr(control, 'data-action', id);
|
30409 |
|
30410 | container = query('[data-group=' + grouping + ']', html);
|
30411 | if (!container) {
|
30412 | container = domify('<div class="group" data-group="' + grouping + '"></div>');
|
30413 | html.appendChild(container);
|
30414 | }
|
30415 |
|
30416 | container.appendChild(control);
|
30417 |
|
30418 | if (entry.className) {
|
30419 | addClasses(control, entry.className);
|
30420 | }
|
30421 |
|
30422 | if (entry.title) {
|
30423 | attr(control, 'title', entry.title);
|
30424 | }
|
30425 |
|
30426 | if (entry.imageUrl) {
|
30427 | control.appendChild(domify('<img src="' + entry.imageUrl + '">'));
|
30428 | }
|
30429 | });
|
30430 |
|
30431 | classes(html).add('open');
|
30432 |
|
30433 | this._current = {
|
30434 | element: element,
|
30435 | pad: pad,
|
30436 | entries: entries
|
30437 | };
|
30438 |
|
30439 | this._eventBus.fire('contextPad.open', { current: this._current });
|
30440 | };
|
30441 |
|
30442 |
|
30443 | ContextPad.prototype.getPad = function(element) {
|
30444 | if (this.isOpen()) {
|
30445 | return this._current.pad;
|
30446 | }
|
30447 |
|
30448 | var self = this;
|
30449 |
|
30450 | var overlays = this._overlays;
|
30451 |
|
30452 | var html = domify('<div class="djs-context-pad"></div>');
|
30453 |
|
30454 | var overlaysConfig = assign({
|
30455 | html: html
|
30456 | }, this._overlaysConfig);
|
30457 |
|
30458 | delegateEvents.bind(html, entrySelector, 'click', function(event) {
|
30459 | self.trigger('click', event);
|
30460 | });
|
30461 |
|
30462 | delegateEvents.bind(html, entrySelector, 'dragstart', function(event) {
|
30463 | self.trigger('dragstart', event);
|
30464 | });
|
30465 |
|
30466 |
|
30467 | componentEvent.bind(html, 'mousedown', function(event) {
|
30468 | event.stopPropagation();
|
30469 | });
|
30470 |
|
30471 | this._overlayId = overlays.add(element, 'context-pad', overlaysConfig);
|
30472 |
|
30473 | var pad = overlays.get(this._overlayId);
|
30474 |
|
30475 | this._eventBus.fire('contextPad.create', { element: element, pad: pad });
|
30476 |
|
30477 | return pad;
|
30478 | };
|
30479 |
|
30480 |
|
30481 | |
30482 |
|
30483 |
|
30484 | ContextPad.prototype.close = function() {
|
30485 | if (!this.isOpen()) {
|
30486 | return;
|
30487 | }
|
30488 |
|
30489 | this._overlays.remove(this._overlayId);
|
30490 |
|
30491 | this._overlayId = null;
|
30492 |
|
30493 | this._eventBus.fire('contextPad.close', { current: this._current });
|
30494 |
|
30495 | this._current = null;
|
30496 | };
|
30497 |
|
30498 | |
30499 |
|
30500 |
|
30501 |
|
30502 |
|
30503 |
|
30504 |
|
30505 | ContextPad.prototype.isOpen = function(element) {
|
30506 | return !!this._current && (!element ? true : this._current.element === element);
|
30507 | };
|
30508 |
|
30509 |
|
30510 |
|
30511 |
|
30512 |
|
30513 |
|
30514 | function addClasses(element, classNames) {
|
30515 |
|
30516 | var classes$1 = classes(element);
|
30517 |
|
30518 | var actualClassNames = isArray(classNames) ? classNames : classNames.split(/\s+/g);
|
30519 | actualClassNames.forEach(function(cls) {
|
30520 | classes$1.add(cls);
|
30521 | });
|
30522 | }
|
30523 |
|
30524 | var ContextPadModule = {
|
30525 | __depends__: [
|
30526 | InteractionEventsModule,
|
30527 | OverlaysModule
|
30528 | ],
|
30529 | contextPad: [ 'type', ContextPad ]
|
30530 | };
|
30531 |
|
30532 | var MARKER_TYPES = [
|
30533 | 'marker-start',
|
30534 | 'marker-mid',
|
30535 | 'marker-end'
|
30536 | ];
|
30537 |
|
30538 | var NODES_CAN_HAVE_MARKER = [
|
30539 | 'circle',
|
30540 | 'ellipse',
|
30541 | 'line',
|
30542 | 'path',
|
30543 | 'polygon',
|
30544 | 'polyline',
|
30545 | 'rect'
|
30546 | ];
|
30547 |
|
30548 |
|
30549 | |
30550 |
|
30551 |
|
30552 | function PreviewSupport(elementRegistry, eventBus, canvas, styles) {
|
30553 | this._elementRegistry = elementRegistry;
|
30554 | this._canvas = canvas;
|
30555 | this._styles = styles;
|
30556 |
|
30557 | this._clonedMarkers = {};
|
30558 |
|
30559 | var self = this;
|
30560 |
|
30561 | eventBus.on('drag.cleanup', function() {
|
30562 | forEach(self._clonedMarkers, function(clonedMarker) {
|
30563 | remove$1(clonedMarker);
|
30564 | });
|
30565 |
|
30566 | self._clonedMarkers = {};
|
30567 | });
|
30568 | }
|
30569 |
|
30570 | PreviewSupport.$inject = [
|
30571 | 'elementRegistry',
|
30572 | 'eventBus',
|
30573 | 'canvas',
|
30574 | 'styles'
|
30575 | ];
|
30576 |
|
30577 |
|
30578 | |
30579 |
|
30580 |
|
30581 |
|
30582 |
|
30583 |
|
30584 |
|
30585 | PreviewSupport.prototype.getGfx = function(element) {
|
30586 | return this._elementRegistry.getGraphics(element);
|
30587 | };
|
30588 |
|
30589 | |
30590 |
|
30591 |
|
30592 |
|
30593 |
|
30594 |
|
30595 |
|
30596 |
|
30597 |
|
30598 | PreviewSupport.prototype.addDragger = function(element, group, gfx) {
|
30599 | gfx = gfx || this.getGfx(element);
|
30600 |
|
30601 | var dragger = clone(gfx);
|
30602 | var bbox = gfx.getBoundingClientRect();
|
30603 |
|
30604 | this._cloneMarkers(getVisual(dragger));
|
30605 |
|
30606 | attr$1(dragger, this._styles.cls('djs-dragger', [], {
|
30607 | x: bbox.top,
|
30608 | y: bbox.left
|
30609 | }));
|
30610 |
|
30611 | append(group, dragger);
|
30612 |
|
30613 | return dragger;
|
30614 | };
|
30615 |
|
30616 | |
30617 |
|
30618 |
|
30619 |
|
30620 |
|
30621 |
|
30622 |
|
30623 |
|
30624 | PreviewSupport.prototype.addFrame = function(shape, group) {
|
30625 |
|
30626 | var frame = create('rect', {
|
30627 | class: 'djs-resize-overlay',
|
30628 | width: shape.width,
|
30629 | height: shape.height,
|
30630 | x: shape.x,
|
30631 | y: shape.y
|
30632 | });
|
30633 |
|
30634 | append(group, frame);
|
30635 |
|
30636 | return frame;
|
30637 | };
|
30638 |
|
30639 | |
30640 |
|
30641 |
|
30642 |
|
30643 |
|
30644 | PreviewSupport.prototype._cloneMarkers = function(gfx) {
|
30645 | var self = this;
|
30646 |
|
30647 | if (gfx.childNodes) {
|
30648 |
|
30649 |
|
30650 | for (var i = 0; i < gfx.childNodes.length; i++) {
|
30651 |
|
30652 |
|
30653 | self._cloneMarkers(gfx.childNodes[ i ]);
|
30654 | }
|
30655 | }
|
30656 |
|
30657 | if (!canHaveMarker(gfx)) {
|
30658 | return;
|
30659 | }
|
30660 |
|
30661 | MARKER_TYPES.forEach(function(markerType) {
|
30662 | if (attr$1(gfx, markerType)) {
|
30663 | var marker = getMarker(gfx, markerType, self._canvas.getContainer());
|
30664 |
|
30665 | self._cloneMarker(gfx, marker, markerType);
|
30666 | }
|
30667 | });
|
30668 | };
|
30669 |
|
30670 | |
30671 |
|
30672 |
|
30673 |
|
30674 |
|
30675 |
|
30676 |
|
30677 | PreviewSupport.prototype._cloneMarker = function(gfx, marker, markerType) {
|
30678 | var markerId = marker.id;
|
30679 |
|
30680 | var clonedMarker = this._clonedMarkers[ markerId ];
|
30681 |
|
30682 | if (!clonedMarker) {
|
30683 | clonedMarker = clone(marker);
|
30684 |
|
30685 | var clonedMarkerId = markerId + '-clone';
|
30686 |
|
30687 | clonedMarker.id = clonedMarkerId;
|
30688 |
|
30689 | classes$1(clonedMarker)
|
30690 | .add('djs-dragger')
|
30691 | .add('djs-dragger-marker');
|
30692 |
|
30693 | this._clonedMarkers[ markerId ] = clonedMarker;
|
30694 |
|
30695 | var defs = query('defs', this._canvas._svg);
|
30696 |
|
30697 | if (!defs) {
|
30698 | defs = create('defs');
|
30699 |
|
30700 | append(this._canvas._svg, defs);
|
30701 | }
|
30702 |
|
30703 | append(defs, clonedMarker);
|
30704 | }
|
30705 |
|
30706 | var reference = idToReference(this._clonedMarkers[ markerId ].id);
|
30707 |
|
30708 | attr$1(gfx, markerType, reference);
|
30709 | };
|
30710 |
|
30711 |
|
30712 |
|
30713 | |
30714 |
|
30715 |
|
30716 |
|
30717 |
|
30718 |
|
30719 |
|
30720 |
|
30721 |
|
30722 | function getMarker(node, markerType, parentNode) {
|
30723 | var id = referenceToId(attr$1(node, markerType));
|
30724 |
|
30725 | return query('marker#' + id, parentNode || document);
|
30726 | }
|
30727 |
|
30728 | |
30729 |
|
30730 |
|
30731 |
|
30732 |
|
30733 |
|
30734 |
|
30735 |
|
30736 | function referenceToId(reference) {
|
30737 | return reference.match(/url\(['"]?#([^'"]*)['"]?\)/)[1];
|
30738 | }
|
30739 |
|
30740 | |
30741 |
|
30742 |
|
30743 |
|
30744 |
|
30745 |
|
30746 |
|
30747 | function idToReference(id) {
|
30748 | return 'url(#' + id + ')';
|
30749 | }
|
30750 |
|
30751 | |
30752 |
|
30753 |
|
30754 |
|
30755 |
|
30756 |
|
30757 |
|
30758 | function canHaveMarker(node) {
|
30759 | return NODES_CAN_HAVE_MARKER.indexOf(node.nodeName) !== -1;
|
30760 | }
|
30761 |
|
30762 | var PreviewSupportModule = {
|
30763 | __init__: [ 'previewSupport' ],
|
30764 | previewSupport: [ 'type', PreviewSupport ]
|
30765 | };
|
30766 |
|
30767 | var MARKER_OK$2 = 'drop-ok',
|
30768 | MARKER_NOT_OK$2 = 'drop-not-ok',
|
30769 | MARKER_ATTACH = 'attach-ok',
|
30770 | MARKER_NEW_PARENT = 'new-parent';
|
30771 |
|
30772 | var PREFIX = 'create';
|
30773 |
|
30774 | var HIGH_PRIORITY$3 = 2000;
|
30775 |
|
30776 |
|
30777 | |
30778 |
|
30779 |
|
30780 |
|
30781 |
|
30782 |
|
30783 |
|
30784 |
|
30785 |
|
30786 | function Create(
|
30787 | canvas,
|
30788 | dragging,
|
30789 | eventBus,
|
30790 | modeling,
|
30791 | rules
|
30792 | ) {
|
30793 |
|
30794 |
|
30795 |
|
30796 | |
30797 |
|
30798 |
|
30799 |
|
30800 |
|
30801 |
|
30802 |
|
30803 |
|
30804 |
|
30805 |
|
30806 | function canCreate(elements, target, position, source) {
|
30807 | if (!target) {
|
30808 | return false;
|
30809 | }
|
30810 |
|
30811 |
|
30812 | elements = filter(elements, function(element) {
|
30813 | var labelTarget = element.labelTarget;
|
30814 |
|
30815 | return !element.parent && !(isLabel$1(element) && elements.indexOf(labelTarget) !== -1);
|
30816 | });
|
30817 |
|
30818 | var shape = find(elements, function(element) {
|
30819 | return !isConnection(element);
|
30820 | });
|
30821 |
|
30822 | var attach = false,
|
30823 | connect = false,
|
30824 | create = false;
|
30825 |
|
30826 |
|
30827 | if (isSingleShape(elements)) {
|
30828 | attach = rules.allowed('shape.attach', {
|
30829 | position: position,
|
30830 | shape: shape,
|
30831 | target: target
|
30832 | });
|
30833 | }
|
30834 |
|
30835 | if (!attach) {
|
30836 |
|
30837 |
|
30838 | if (isSingleShape(elements)) {
|
30839 | create = rules.allowed('shape.create', {
|
30840 | position: position,
|
30841 | shape: shape,
|
30842 | source: source,
|
30843 | target: target
|
30844 | });
|
30845 | } else {
|
30846 | create = rules.allowed('elements.create', {
|
30847 | elements: elements,
|
30848 | position: position,
|
30849 | target: target
|
30850 | });
|
30851 | }
|
30852 |
|
30853 | }
|
30854 |
|
30855 |
|
30856 | if (create || attach) {
|
30857 |
|
30858 | if (shape && source) {
|
30859 | connect = rules.allowed('connection.create', {
|
30860 | source: source,
|
30861 | target: shape,
|
30862 | hints: {
|
30863 | targetParent: target,
|
30864 | targetAttach: attach
|
30865 | }
|
30866 | });
|
30867 | }
|
30868 |
|
30869 | return {
|
30870 | attach: attach,
|
30871 | connect: connect
|
30872 | };
|
30873 | }
|
30874 |
|
30875 |
|
30876 | if (create === null || attach === null) {
|
30877 | return null;
|
30878 | }
|
30879 |
|
30880 | return false;
|
30881 | }
|
30882 |
|
30883 | function setMarker(element, marker) {
|
30884 | [ MARKER_ATTACH, MARKER_OK$2, MARKER_NOT_OK$2, MARKER_NEW_PARENT ].forEach(function(m) {
|
30885 |
|
30886 | if (m === marker) {
|
30887 | canvas.addMarker(element, m);
|
30888 | } else {
|
30889 | canvas.removeMarker(element, m);
|
30890 | }
|
30891 | });
|
30892 | }
|
30893 |
|
30894 |
|
30895 |
|
30896 | eventBus.on([ 'create.move', 'create.hover' ], function(event) {
|
30897 | var context = event.context,
|
30898 | elements = context.elements,
|
30899 | hover = event.hover,
|
30900 | source = context.source;
|
30901 |
|
30902 | if (!hover) {
|
30903 | context.canExecute = false;
|
30904 | context.target = null;
|
30905 |
|
30906 | return;
|
30907 | }
|
30908 |
|
30909 | ensureConstraints(event);
|
30910 |
|
30911 | var position = {
|
30912 | x: event.x,
|
30913 | y: event.y
|
30914 | };
|
30915 |
|
30916 | var canExecute = context.canExecute = hover && canCreate(elements, hover, position, source);
|
30917 |
|
30918 | if (hover && canExecute !== null) {
|
30919 | context.target = hover;
|
30920 |
|
30921 | if (canExecute && canExecute.attach) {
|
30922 | setMarker(hover, MARKER_ATTACH);
|
30923 | } else {
|
30924 | setMarker(hover, canExecute ? MARKER_NEW_PARENT : MARKER_NOT_OK$2);
|
30925 | }
|
30926 | }
|
30927 | });
|
30928 |
|
30929 | eventBus.on([ 'create.end', 'create.out', 'create.cleanup' ], function(event) {
|
30930 | var hover = event.hover;
|
30931 |
|
30932 | if (hover) {
|
30933 | setMarker(hover, null);
|
30934 | }
|
30935 | });
|
30936 |
|
30937 | eventBus.on('create.end', function(event) {
|
30938 | var context = event.context,
|
30939 | source = context.source,
|
30940 | shape = context.shape,
|
30941 | elements = context.elements,
|
30942 | target = context.target,
|
30943 | hints = context.hints,
|
30944 | canExecute = context.canExecute,
|
30945 | attach = canExecute && canExecute.attach,
|
30946 | connect = canExecute && canExecute.connect;
|
30947 |
|
30948 | if (canExecute === false || !target) {
|
30949 | return false;
|
30950 | }
|
30951 |
|
30952 | ensureConstraints(event);
|
30953 |
|
30954 | var position = {
|
30955 | x: event.x,
|
30956 | y: event.y
|
30957 | };
|
30958 |
|
30959 | if (connect) {
|
30960 | shape = modeling.appendShape(source, shape, position, target, {
|
30961 | attach: attach,
|
30962 | connection: connect === true ? {} : connect
|
30963 | });
|
30964 | } else {
|
30965 | elements = modeling.createElements(elements, position, target, assign({}, hints, {
|
30966 | attach: attach
|
30967 | }));
|
30968 |
|
30969 |
|
30970 | shape = find(elements, function(element) {
|
30971 | return !isConnection(element);
|
30972 | });
|
30973 | }
|
30974 |
|
30975 |
|
30976 | assign(context, {
|
30977 | elements: elements,
|
30978 | shape: shape
|
30979 | });
|
30980 |
|
30981 | assign(event, {
|
30982 | elements: elements,
|
30983 | shape: shape
|
30984 | });
|
30985 | });
|
30986 |
|
30987 | function cancel() {
|
30988 | var context = dragging.context();
|
30989 |
|
30990 | if (context && context.prefix === PREFIX) {
|
30991 | dragging.cancel();
|
30992 | }
|
30993 | }
|
30994 |
|
30995 |
|
30996 | eventBus.on('create.init', function() {
|
30997 | eventBus.on('elements.changed', cancel);
|
30998 |
|
30999 | eventBus.once([ 'create.cancel', 'create.end' ], HIGH_PRIORITY$3, function() {
|
31000 | eventBus.off('elements.changed', cancel);
|
31001 | });
|
31002 | });
|
31003 |
|
31004 |
|
31005 |
|
31006 | this.start = function(event, elements, context) {
|
31007 | if (!isArray(elements)) {
|
31008 | elements = [ elements ];
|
31009 | }
|
31010 |
|
31011 | var shape = find(elements, function(element) {
|
31012 | return !isConnection(element);
|
31013 | });
|
31014 |
|
31015 | if (!shape) {
|
31016 |
|
31017 |
|
31018 | return;
|
31019 | }
|
31020 |
|
31021 | context = assign({
|
31022 | elements: elements,
|
31023 | hints: {},
|
31024 | shape: shape
|
31025 | }, context || {});
|
31026 |
|
31027 |
|
31028 | forEach(elements, function(element) {
|
31029 | if (!isNumber(element.x)) {
|
31030 | element.x = 0;
|
31031 | }
|
31032 |
|
31033 | if (!isNumber(element.y)) {
|
31034 | element.y = 0;
|
31035 | }
|
31036 | });
|
31037 |
|
31038 | var bbox = getBBox(elements);
|
31039 |
|
31040 |
|
31041 | forEach(elements, function(element) {
|
31042 | if (isConnection(element)) {
|
31043 | element.waypoints = map(element.waypoints, function(waypoint) {
|
31044 | return {
|
31045 | x: waypoint.x - bbox.x - bbox.width / 2,
|
31046 | y: waypoint.y - bbox.y - bbox.height / 2
|
31047 | };
|
31048 | });
|
31049 | }
|
31050 |
|
31051 | assign(element, {
|
31052 | x: element.x - bbox.x - bbox.width / 2,
|
31053 | y: element.y - bbox.y - bbox.height / 2
|
31054 | });
|
31055 | });
|
31056 |
|
31057 | dragging.init(event, PREFIX, {
|
31058 | cursor: 'grabbing',
|
31059 | autoActivate: true,
|
31060 | data: {
|
31061 | shape: shape,
|
31062 | elements: elements,
|
31063 | context: context
|
31064 | }
|
31065 | });
|
31066 | };
|
31067 | }
|
31068 |
|
31069 | Create.$inject = [
|
31070 | 'canvas',
|
31071 | 'dragging',
|
31072 | 'eventBus',
|
31073 | 'modeling',
|
31074 | 'rules'
|
31075 | ];
|
31076 |
|
31077 |
|
31078 |
|
31079 | function ensureConstraints(event) {
|
31080 | var context = event.context,
|
31081 | createConstraints = context.createConstraints;
|
31082 |
|
31083 | if (!createConstraints) {
|
31084 | return;
|
31085 | }
|
31086 |
|
31087 | if (createConstraints.left) {
|
31088 | event.x = Math.max(event.x, createConstraints.left);
|
31089 | }
|
31090 |
|
31091 | if (createConstraints.right) {
|
31092 | event.x = Math.min(event.x, createConstraints.right);
|
31093 | }
|
31094 |
|
31095 | if (createConstraints.top) {
|
31096 | event.y = Math.max(event.y, createConstraints.top);
|
31097 | }
|
31098 |
|
31099 | if (createConstraints.bottom) {
|
31100 | event.y = Math.min(event.y, createConstraints.bottom);
|
31101 | }
|
31102 | }
|
31103 |
|
31104 | function isConnection(element) {
|
31105 | return !!element.waypoints;
|
31106 | }
|
31107 |
|
31108 | function isSingleShape(elements) {
|
31109 | return elements && elements.length === 1 && !isConnection(elements[0]);
|
31110 | }
|
31111 |
|
31112 | function isLabel$1(element) {
|
31113 | return !!element.labelTarget;
|
31114 | }
|
31115 |
|
31116 | var LOW_PRIORITY$5 = 750;
|
31117 |
|
31118 |
|
31119 | function CreatePreview(
|
31120 | canvas,
|
31121 | eventBus,
|
31122 | graphicsFactory,
|
31123 | previewSupport,
|
31124 | styles
|
31125 | ) {
|
31126 | function createDragGroup(elements) {
|
31127 | var dragGroup = create('g');
|
31128 |
|
31129 | attr$1(dragGroup, styles.cls('djs-drag-group', [ 'no-events' ]));
|
31130 |
|
31131 | var childrenGfx = create('g');
|
31132 |
|
31133 | elements.forEach(function(element) {
|
31134 |
|
31135 |
|
31136 | var gfx;
|
31137 |
|
31138 | if (element.waypoints) {
|
31139 | gfx = graphicsFactory._createContainer('connection', childrenGfx);
|
31140 |
|
31141 | graphicsFactory.drawConnection(getVisual(gfx), element);
|
31142 | } else {
|
31143 | gfx = graphicsFactory._createContainer('shape', childrenGfx);
|
31144 |
|
31145 | graphicsFactory.drawShape(getVisual(gfx), element);
|
31146 |
|
31147 | translate(gfx, element.x, element.y);
|
31148 | }
|
31149 |
|
31150 |
|
31151 | previewSupport.addDragger(element, dragGroup, gfx);
|
31152 | });
|
31153 |
|
31154 | return dragGroup;
|
31155 | }
|
31156 |
|
31157 | eventBus.on('create.move', LOW_PRIORITY$5, function(event) {
|
31158 |
|
31159 | var hover = event.hover,
|
31160 | context = event.context,
|
31161 | elements = context.elements,
|
31162 | dragGroup = context.dragGroup;
|
31163 |
|
31164 |
|
31165 | if (!dragGroup) {
|
31166 | dragGroup = context.dragGroup = createDragGroup(elements);
|
31167 | }
|
31168 |
|
31169 | var defaultLayer;
|
31170 |
|
31171 | if (hover) {
|
31172 | if (!dragGroup.parentNode) {
|
31173 | defaultLayer = canvas.getDefaultLayer();
|
31174 |
|
31175 | append(defaultLayer, dragGroup);
|
31176 | }
|
31177 |
|
31178 | translate(dragGroup, event.x, event.y);
|
31179 | } else {
|
31180 | remove$1(dragGroup);
|
31181 | }
|
31182 | });
|
31183 |
|
31184 | eventBus.on('create.cleanup', function(event) {
|
31185 | var context = event.context,
|
31186 | dragGroup = context.dragGroup;
|
31187 |
|
31188 | if (dragGroup) {
|
31189 | remove$1(dragGroup);
|
31190 | }
|
31191 | });
|
31192 | }
|
31193 |
|
31194 | CreatePreview.$inject = [
|
31195 | 'canvas',
|
31196 | 'eventBus',
|
31197 | 'graphicsFactory',
|
31198 | 'previewSupport',
|
31199 | 'styles'
|
31200 | ];
|
31201 |
|
31202 | var CreateModule = {
|
31203 | __depends__: [
|
31204 | DraggingModule,
|
31205 | PreviewSupportModule,
|
31206 | RulesModule,
|
31207 | SelectionModule
|
31208 | ],
|
31209 | __init__: [
|
31210 | 'create',
|
31211 | 'createPreview'
|
31212 | ],
|
31213 | create: [ 'type', Create ],
|
31214 | createPreview: [ 'type', CreatePreview ]
|
31215 | };
|
31216 |
|
31217 | var DATA_REF = 'data-id';
|
31218 |
|
31219 | var CLOSE_EVENTS = [
|
31220 | 'contextPad.close',
|
31221 | 'canvas.viewbox.changing',
|
31222 | 'commandStack.changed'
|
31223 | ];
|
31224 |
|
31225 | var DEFAULT_PRIORITY$4 = 1000;
|
31226 |
|
31227 |
|
31228 | |
31229 |
|
31230 |
|
31231 |
|
31232 |
|
31233 |
|
31234 |
|
31235 |
|
31236 |
|
31237 |
|
31238 |
|
31239 |
|
31240 |
|
31241 | function PopupMenu(config, eventBus, canvas) {
|
31242 |
|
31243 | var scale = isDefined(config && config.scale) ? config.scale : {
|
31244 | min: 1,
|
31245 | max: 1.5
|
31246 | };
|
31247 |
|
31248 | this._config = {
|
31249 | scale: scale
|
31250 | };
|
31251 |
|
31252 | this._eventBus = eventBus;
|
31253 | this._canvas = canvas;
|
31254 | this._providers = {};
|
31255 | this._current = {};
|
31256 | }
|
31257 |
|
31258 | PopupMenu.$inject = [
|
31259 | 'config.popupMenu',
|
31260 | 'eventBus',
|
31261 | 'canvas'
|
31262 | ];
|
31263 |
|
31264 | |
31265 |
|
31266 |
|
31267 |
|
31268 |
|
31269 |
|
31270 |
|
31271 |
|
31272 |
|
31273 |
|
31274 |
|
31275 |
|
31276 |
|
31277 |
|
31278 |
|
31279 |
|
31280 |
|
31281 |
|
31282 |
|
31283 |
|
31284 |
|
31285 | PopupMenu.prototype.registerProvider = function(id, priority, provider) {
|
31286 | if (!provider) {
|
31287 | provider = priority;
|
31288 | priority = DEFAULT_PRIORITY$4;
|
31289 | }
|
31290 |
|
31291 | this._eventBus.on('popupMenu.getProviders.' + id, priority, function(event) {
|
31292 | event.providers.push(provider);
|
31293 | });
|
31294 | };
|
31295 |
|
31296 | |
31297 |
|
31298 |
|
31299 |
|
31300 |
|
31301 | PopupMenu.prototype.isEmpty = function(element, providerId) {
|
31302 | if (!element) {
|
31303 | throw new Error('element parameter is missing');
|
31304 | }
|
31305 |
|
31306 | if (!providerId) {
|
31307 | throw new Error('providerId parameter is missing');
|
31308 | }
|
31309 |
|
31310 | var providers = this._getProviders(providerId);
|
31311 |
|
31312 | if (!providers) {
|
31313 | return true;
|
31314 | }
|
31315 |
|
31316 | var entries = this._getEntries(element, providers),
|
31317 | headerEntries = this._getHeaderEntries(element, providers);
|
31318 |
|
31319 | var hasEntries = size(entries) > 0,
|
31320 | hasHeaderEntries = headerEntries && size(headerEntries) > 0;
|
31321 |
|
31322 | return !hasEntries && !hasHeaderEntries;
|
31323 | };
|
31324 |
|
31325 |
|
31326 | |
31327 |
|
31328 |
|
31329 |
|
31330 |
|
31331 |
|
31332 |
|
31333 |
|
31334 |
|
31335 | PopupMenu.prototype.open = function(element, id, position) {
|
31336 |
|
31337 | var providers = this._getProviders(id);
|
31338 |
|
31339 | if (!element) {
|
31340 | throw new Error('Element is missing');
|
31341 | }
|
31342 |
|
31343 | if (!providers || !providers.length) {
|
31344 | throw new Error('No registered providers for: ' + id);
|
31345 | }
|
31346 |
|
31347 | if (!position) {
|
31348 | throw new Error('the position argument is missing');
|
31349 | }
|
31350 |
|
31351 | if (this.isOpen()) {
|
31352 | this.close();
|
31353 | }
|
31354 |
|
31355 | this._emit('open');
|
31356 |
|
31357 | var current = this._current = {
|
31358 | className: id,
|
31359 | element: element,
|
31360 | position: position
|
31361 | };
|
31362 |
|
31363 | var entries = this._getEntries(element, providers),
|
31364 | headerEntries = this._getHeaderEntries(element, providers);
|
31365 |
|
31366 | current.entries = assign({}, entries, headerEntries);
|
31367 |
|
31368 | current.container = this._createContainer();
|
31369 |
|
31370 | if (size(headerEntries)) {
|
31371 | current.container.appendChild(
|
31372 | this._createEntries(headerEntries, 'djs-popup-header')
|
31373 | );
|
31374 | }
|
31375 |
|
31376 | if (size(entries)) {
|
31377 | current.container.appendChild(
|
31378 | this._createEntries(entries, 'djs-popup-body')
|
31379 | );
|
31380 | }
|
31381 |
|
31382 | var canvas = this._canvas,
|
31383 | parent = canvas.getContainer();
|
31384 |
|
31385 | this._attachContainer(current.container, parent, position.cursor);
|
31386 | this._bindAutoClose();
|
31387 | };
|
31388 |
|
31389 |
|
31390 | |
31391 |
|
31392 |
|
31393 | PopupMenu.prototype.close = function() {
|
31394 |
|
31395 | if (!this.isOpen()) {
|
31396 | return;
|
31397 | }
|
31398 |
|
31399 | this._emit('close');
|
31400 |
|
31401 | this._unbindAutoClose();
|
31402 | remove(this._current.container);
|
31403 | this._current.container = null;
|
31404 | };
|
31405 |
|
31406 |
|
31407 | |
31408 |
|
31409 |
|
31410 |
|
31411 |
|
31412 | PopupMenu.prototype.isOpen = function() {
|
31413 | return !!this._current.container;
|
31414 | };
|
31415 |
|
31416 |
|
31417 | |
31418 |
|
31419 |
|
31420 |
|
31421 |
|
31422 |
|
31423 |
|
31424 | PopupMenu.prototype.trigger = function(event) {
|
31425 |
|
31426 |
|
31427 | event.preventDefault();
|
31428 |
|
31429 | var element = event.delegateTarget || event.target,
|
31430 | entryId = attr(element, DATA_REF);
|
31431 |
|
31432 | var entry = this._getEntry(entryId);
|
31433 |
|
31434 | if (entry.action) {
|
31435 | return entry.action.call(null, event, entry);
|
31436 | }
|
31437 | };
|
31438 |
|
31439 | PopupMenu.prototype._getProviders = function(id) {
|
31440 |
|
31441 | var event = this._eventBus.createEvent({
|
31442 | type: 'popupMenu.getProviders.' + id,
|
31443 | providers: []
|
31444 | });
|
31445 |
|
31446 | this._eventBus.fire(event);
|
31447 |
|
31448 | return event.providers;
|
31449 | };
|
31450 |
|
31451 | PopupMenu.prototype._getEntries = function(element, providers) {
|
31452 |
|
31453 | var entries = {};
|
31454 |
|
31455 | forEach(providers, function(provider) {
|
31456 |
|
31457 |
|
31458 | if (!provider.getPopupMenuEntries) {
|
31459 | forEach(provider.getEntries(element), function(entry) {
|
31460 | var id = entry.id;
|
31461 |
|
31462 | if (!id) {
|
31463 | throw new Error('every entry must have the id property set');
|
31464 | }
|
31465 |
|
31466 | entries[id] = omit(entry, [ 'id' ]);
|
31467 | });
|
31468 |
|
31469 | return;
|
31470 | }
|
31471 |
|
31472 | var entriesOrUpdater = provider.getPopupMenuEntries(element);
|
31473 |
|
31474 | if (isFunction(entriesOrUpdater)) {
|
31475 | entries = entriesOrUpdater(entries);
|
31476 | } else {
|
31477 | forEach(entriesOrUpdater, function(entry, id) {
|
31478 | entries[id] = entry;
|
31479 | });
|
31480 | }
|
31481 | });
|
31482 |
|
31483 | return entries;
|
31484 | };
|
31485 |
|
31486 | PopupMenu.prototype._getHeaderEntries = function(element, providers) {
|
31487 |
|
31488 | var entries = {};
|
31489 |
|
31490 | forEach(providers, function(provider) {
|
31491 |
|
31492 |
|
31493 | if (!provider.getPopupMenuHeaderEntries) {
|
31494 | if (!provider.getHeaderEntries) {
|
31495 | return;
|
31496 | }
|
31497 |
|
31498 | forEach(provider.getHeaderEntries(element), function(entry) {
|
31499 | var id = entry.id;
|
31500 |
|
31501 | if (!id) {
|
31502 | throw new Error('every entry must have the id property set');
|
31503 | }
|
31504 |
|
31505 | entries[id] = omit(entry, [ 'id' ]);
|
31506 | });
|
31507 |
|
31508 | return;
|
31509 | }
|
31510 |
|
31511 | var entriesOrUpdater = provider.getPopupMenuHeaderEntries(element);
|
31512 |
|
31513 | if (isFunction(entriesOrUpdater)) {
|
31514 | entries = entriesOrUpdater(entries);
|
31515 | } else {
|
31516 | forEach(entriesOrUpdater, function(entry, id) {
|
31517 | entries[id] = entry;
|
31518 | });
|
31519 | }
|
31520 | });
|
31521 |
|
31522 | return entries;
|
31523 |
|
31524 |
|
31525 | };
|
31526 |
|
31527 | |
31528 |
|
31529 |
|
31530 |
|
31531 |
|
31532 |
|
31533 |
|
31534 | PopupMenu.prototype._getEntry = function(entryId) {
|
31535 |
|
31536 | var entry = this._current.entries[entryId];
|
31537 |
|
31538 | if (!entry) {
|
31539 | throw new Error('entry not found');
|
31540 | }
|
31541 |
|
31542 | return entry;
|
31543 | };
|
31544 |
|
31545 | PopupMenu.prototype._emit = function(eventName) {
|
31546 | this._eventBus.fire('popupMenu.' + eventName);
|
31547 | };
|
31548 |
|
31549 | |
31550 |
|
31551 |
|
31552 |
|
31553 |
|
31554 | PopupMenu.prototype._createContainer = function() {
|
31555 | var container = domify('<div class="djs-popup">'),
|
31556 | position = this._current.position,
|
31557 | className = this._current.className;
|
31558 |
|
31559 | assign(container.style, {
|
31560 | position: 'absolute',
|
31561 | left: position.x + 'px',
|
31562 | top: position.y + 'px',
|
31563 | visibility: 'hidden'
|
31564 | });
|
31565 |
|
31566 | classes(container).add(className);
|
31567 |
|
31568 | return container;
|
31569 | };
|
31570 |
|
31571 |
|
31572 | |
31573 |
|
31574 |
|
31575 |
|
31576 |
|
31577 |
|
31578 | PopupMenu.prototype._attachContainer = function(container, parent, cursor) {
|
31579 | var self = this;
|
31580 |
|
31581 |
|
31582 | delegateEvents.bind(container, '.entry' ,'click', function(event) {
|
31583 | self.trigger(event);
|
31584 | });
|
31585 |
|
31586 | this._updateScale(container);
|
31587 |
|
31588 |
|
31589 | parent.appendChild(container);
|
31590 |
|
31591 | if (cursor) {
|
31592 | this._assureIsInbounds(container, cursor);
|
31593 | }
|
31594 | };
|
31595 |
|
31596 |
|
31597 | |
31598 |
|
31599 |
|
31600 |
|
31601 |
|
31602 |
|
31603 |
|
31604 | PopupMenu.prototype._updateScale = function(container) {
|
31605 | var zoom = this._canvas.zoom();
|
31606 |
|
31607 | var scaleConfig = this._config.scale,
|
31608 | minScale,
|
31609 | maxScale,
|
31610 | scale = zoom;
|
31611 |
|
31612 | if (scaleConfig !== true) {
|
31613 |
|
31614 | if (scaleConfig === false) {
|
31615 | minScale = 1;
|
31616 | maxScale = 1;
|
31617 | } else {
|
31618 | minScale = scaleConfig.min;
|
31619 | maxScale = scaleConfig.max;
|
31620 | }
|
31621 |
|
31622 | if (isDefined(minScale) && zoom < minScale) {
|
31623 | scale = minScale;
|
31624 | }
|
31625 |
|
31626 | if (isDefined(maxScale) && zoom > maxScale) {
|
31627 | scale = maxScale;
|
31628 | }
|
31629 |
|
31630 | }
|
31631 |
|
31632 | setTransform$1(container, 'scale(' + scale + ')');
|
31633 | };
|
31634 |
|
31635 |
|
31636 | |
31637 |
|
31638 |
|
31639 |
|
31640 |
|
31641 |
|
31642 |
|
31643 |
|
31644 | PopupMenu.prototype._assureIsInbounds = function(container, cursor) {
|
31645 | var canvas = this._canvas,
|
31646 | clientRect = canvas._container.getBoundingClientRect();
|
31647 |
|
31648 | var containerX = container.offsetLeft,
|
31649 | containerY = container.offsetTop,
|
31650 | containerWidth = container.scrollWidth,
|
31651 | containerHeight = container.scrollHeight,
|
31652 | overAxis = {},
|
31653 | left, top;
|
31654 |
|
31655 | var cursorPosition = {
|
31656 | x: cursor.x - clientRect.left,
|
31657 | y: cursor.y - clientRect.top
|
31658 | };
|
31659 |
|
31660 | if (containerX + containerWidth > clientRect.width) {
|
31661 | overAxis.x = true;
|
31662 | }
|
31663 |
|
31664 | if (containerY + containerHeight > clientRect.height) {
|
31665 | overAxis.y = true;
|
31666 | }
|
31667 |
|
31668 | if (overAxis.x && overAxis.y) {
|
31669 | left = cursorPosition.x - containerWidth + 'px';
|
31670 | top = cursorPosition.y - containerHeight + 'px';
|
31671 | } else if (overAxis.x) {
|
31672 | left = cursorPosition.x - containerWidth + 'px';
|
31673 | top = cursorPosition.y + 'px';
|
31674 | } else if (overAxis.y && cursorPosition.y < containerHeight) {
|
31675 | left = cursorPosition.x + 'px';
|
31676 | top = 10 + 'px';
|
31677 | } else if (overAxis.y) {
|
31678 | left = cursorPosition.x + 'px';
|
31679 | top = cursorPosition.y - containerHeight + 'px';
|
31680 | }
|
31681 |
|
31682 | assign(container.style, { left: left, top: top }, { visibility: 'visible', 'z-index': 1000 });
|
31683 | };
|
31684 |
|
31685 |
|
31686 | |
31687 |
|
31688 |
|
31689 |
|
31690 |
|
31691 |
|
31692 |
|
31693 |
|
31694 | PopupMenu.prototype._createEntries = function(entries, className) {
|
31695 |
|
31696 | var entriesContainer = domify('<div>'),
|
31697 | self = this;
|
31698 |
|
31699 | classes(entriesContainer).add(className);
|
31700 |
|
31701 | forEach(entries, function(entry, id) {
|
31702 | var entryContainer = self._createEntry(entry, id);
|
31703 | entriesContainer.appendChild(entryContainer);
|
31704 | });
|
31705 |
|
31706 | return entriesContainer;
|
31707 | };
|
31708 |
|
31709 |
|
31710 | |
31711 |
|
31712 |
|
31713 |
|
31714 |
|
31715 |
|
31716 |
|
31717 | PopupMenu.prototype._createEntry = function(entry, id) {
|
31718 |
|
31719 | var entryContainer = domify('<div>'),
|
31720 | entryClasses = classes(entryContainer);
|
31721 |
|
31722 | entryClasses.add('entry');
|
31723 |
|
31724 | if (entry.className) {
|
31725 | entry.className.split(' ').forEach(function(className) {
|
31726 | entryClasses.add(className);
|
31727 | });
|
31728 | }
|
31729 |
|
31730 | attr(entryContainer, DATA_REF, id);
|
31731 |
|
31732 | if (entry.label) {
|
31733 | var label = domify('<span>');
|
31734 | label.textContent = entry.label;
|
31735 | entryContainer.appendChild(label);
|
31736 | }
|
31737 |
|
31738 | if (entry.imageUrl) {
|
31739 | entryContainer.appendChild(domify('<img src="' + entry.imageUrl + '" />'));
|
31740 | }
|
31741 |
|
31742 | if (entry.active === true) {
|
31743 | entryClasses.add('active');
|
31744 | }
|
31745 |
|
31746 | if (entry.disabled === true) {
|
31747 | entryClasses.add('disabled');
|
31748 | }
|
31749 |
|
31750 | if (entry.title) {
|
31751 | entryContainer.title = entry.title;
|
31752 | }
|
31753 |
|
31754 | return entryContainer;
|
31755 | };
|
31756 |
|
31757 |
|
31758 | |
31759 |
|
31760 |
|
31761 | PopupMenu.prototype._bindAutoClose = function() {
|
31762 | this._eventBus.once(CLOSE_EVENTS, this.close, this);
|
31763 | };
|
31764 |
|
31765 |
|
31766 | |
31767 |
|
31768 |
|
31769 | PopupMenu.prototype._unbindAutoClose = function() {
|
31770 | this._eventBus.off(CLOSE_EVENTS, this.close, this);
|
31771 | };
|
31772 |
|
31773 |
|
31774 |
|
31775 |
|
31776 |
|
31777 | function setTransform$1(element, transform) {
|
31778 | element.style['transform-origin'] = 'top left';
|
31779 |
|
31780 | [ '', '-ms-', '-webkit-' ].forEach(function(prefix) {
|
31781 | element.style[prefix + 'transform'] = transform;
|
31782 | });
|
31783 | }
|
31784 |
|
31785 | var PopupMenuModule = {
|
31786 | __init__: [ 'popupMenu' ],
|
31787 | popupMenu: [ 'type', PopupMenu ]
|
31788 | };
|
31789 |
|
31790 | |
31791 |
|
31792 |
|
31793 | function Clipboard() {}
|
31794 |
|
31795 |
|
31796 | Clipboard.prototype.get = function() {
|
31797 | return this._data;
|
31798 | };
|
31799 |
|
31800 | Clipboard.prototype.set = function(data) {
|
31801 | this._data = data;
|
31802 | };
|
31803 |
|
31804 | Clipboard.prototype.clear = function() {
|
31805 | var data = this._data;
|
31806 |
|
31807 | delete this._data;
|
31808 |
|
31809 | return data;
|
31810 | };
|
31811 |
|
31812 | Clipboard.prototype.isEmpty = function() {
|
31813 | return !this._data;
|
31814 | };
|
31815 |
|
31816 | var ClipboardModule = {
|
31817 | clipboard: [ 'type', Clipboard ]
|
31818 | };
|
31819 |
|
31820 | function Mouse(eventBus) {
|
31821 | var self = this;
|
31822 |
|
31823 | this._lastMoveEvent = null;
|
31824 |
|
31825 | function setLastMoveEvent(mousemoveEvent) {
|
31826 | self._lastMoveEvent = mousemoveEvent;
|
31827 | }
|
31828 |
|
31829 | eventBus.on('canvas.init', function(context) {
|
31830 | var svg = self._svg = context.svg;
|
31831 |
|
31832 | svg.addEventListener('mousemove', setLastMoveEvent);
|
31833 | });
|
31834 |
|
31835 | eventBus.on('canvas.destroy', function() {
|
31836 | self._lastMouseEvent = null;
|
31837 |
|
31838 | self._svg.removeEventListener('mousemove', setLastMoveEvent);
|
31839 | });
|
31840 | }
|
31841 |
|
31842 | Mouse.$inject = [ 'eventBus' ];
|
31843 |
|
31844 | Mouse.prototype.getLastMoveEvent = function() {
|
31845 | return this._lastMoveEvent || createMoveEvent(0, 0);
|
31846 | };
|
31847 |
|
31848 |
|
31849 |
|
31850 | function createMoveEvent(x, y) {
|
31851 | var event = document.createEvent('MouseEvent');
|
31852 |
|
31853 | var screenX = x,
|
31854 | screenY = y,
|
31855 | clientX = x,
|
31856 | clientY = y;
|
31857 |
|
31858 | if (event.initMouseEvent) {
|
31859 | event.initMouseEvent(
|
31860 | 'mousemove',
|
31861 | true,
|
31862 | true,
|
31863 | window,
|
31864 | 0,
|
31865 | screenX,
|
31866 | screenY,
|
31867 | clientX,
|
31868 | clientY,
|
31869 | false,
|
31870 | false,
|
31871 | false,
|
31872 | false,
|
31873 | 0,
|
31874 | null
|
31875 | );
|
31876 | }
|
31877 |
|
31878 | return event;
|
31879 | }
|
31880 |
|
31881 | var MouseModule = {
|
31882 | __init__: [ 'mouse' ],
|
31883 | mouse: [ 'type', Mouse ]
|
31884 | };
|
31885 |
|
31886 | |
31887 |
|
31888 |
|
31889 |
|
31890 |
|
31891 |
|
31892 |
|
31893 |
|
31894 |
|
31895 |
|
31896 | |
31897 |
|
31898 |
|
31899 |
|
31900 |
|
31901 |
|
31902 |
|
31903 |
|
31904 |
|
31905 | |
31906 |
|
31907 |
|
31908 |
|
31909 |
|
31910 |
|
31911 |
|
31912 |
|
31913 | |
31914 |
|
31915 |
|
31916 |
|
31917 |
|
31918 |
|
31919 |
|
31920 |
|
31921 | |
31922 |
|
31923 |
|
31924 |
|
31925 |
|
31926 |
|
31927 |
|
31928 | |
31929 |
|
31930 |
|
31931 |
|
31932 |
|
31933 |
|
31934 |
|
31935 |
|
31936 |
|
31937 |
|
31938 |
|
31939 |
|
31940 | function CopyPaste(
|
31941 | canvas,
|
31942 | create,
|
31943 | clipboard,
|
31944 | elementFactory,
|
31945 | eventBus,
|
31946 | modeling,
|
31947 | mouse,
|
31948 | rules
|
31949 | ) {
|
31950 |
|
31951 | this._canvas = canvas;
|
31952 | this._create = create;
|
31953 | this._clipboard = clipboard;
|
31954 | this._elementFactory = elementFactory;
|
31955 | this._eventBus = eventBus;
|
31956 | this._modeling = modeling;
|
31957 | this._mouse = mouse;
|
31958 | this._rules = rules;
|
31959 |
|
31960 | eventBus.on('copyPaste.copyElement', function(context) {
|
31961 | var descriptor = context.descriptor,
|
31962 | element = context.element,
|
31963 | elements = context.elements;
|
31964 |
|
31965 |
|
31966 | descriptor.priority = 1;
|
31967 |
|
31968 | descriptor.id = element.id;
|
31969 |
|
31970 | var parentCopied = find(elements, function(e) {
|
31971 | return e === element.parent;
|
31972 | });
|
31973 |
|
31974 |
|
31975 | if (parentCopied) {
|
31976 | descriptor.parent = element.parent.id;
|
31977 | }
|
31978 |
|
31979 |
|
31980 | if (isAttacher(element)) {
|
31981 | descriptor.priority = 2;
|
31982 |
|
31983 | descriptor.host = element.host.id;
|
31984 | }
|
31985 |
|
31986 |
|
31987 | if (isConnection$1(element)) {
|
31988 | descriptor.priority = 3;
|
31989 |
|
31990 | descriptor.source = element.source.id;
|
31991 | descriptor.target = element.target.id;
|
31992 |
|
31993 | descriptor.waypoints = copyWaypoints(element);
|
31994 | }
|
31995 |
|
31996 |
|
31997 | if (isLabel$2(element)) {
|
31998 | descriptor.priority = 4;
|
31999 |
|
32000 | descriptor.labelTarget = element.labelTarget.id;
|
32001 | }
|
32002 |
|
32003 | forEach([ 'x', 'y', 'width', 'height' ], function(property) {
|
32004 | if (isNumber(element[ property ])) {
|
32005 | descriptor[ property ] = element[ property ];
|
32006 | }
|
32007 | });
|
32008 | });
|
32009 |
|
32010 | eventBus.on('copyPaste.pasteElements', function(context) {
|
32011 | var hints = context.hints;
|
32012 |
|
32013 | assign(hints, {
|
32014 | createElementsBehavior: false
|
32015 | });
|
32016 | });
|
32017 | }
|
32018 |
|
32019 | CopyPaste.$inject = [
|
32020 | 'canvas',
|
32021 | 'create',
|
32022 | 'clipboard',
|
32023 | 'elementFactory',
|
32024 | 'eventBus',
|
32025 | 'modeling',
|
32026 | 'mouse',
|
32027 | 'rules'
|
32028 | ];
|
32029 |
|
32030 |
|
32031 | |
32032 |
|
32033 |
|
32034 |
|
32035 |
|
32036 |
|
32037 |
|
32038 | CopyPaste.prototype.copy = function(elements) {
|
32039 | var allowed,
|
32040 | tree;
|
32041 |
|
32042 | if (!isArray(elements)) {
|
32043 | elements = elements ? [ elements ] : [];
|
32044 | }
|
32045 |
|
32046 | allowed = this._eventBus.fire('copyPaste.canCopyElements', {
|
32047 | elements: elements
|
32048 | });
|
32049 |
|
32050 | if (allowed === false) {
|
32051 | tree = {};
|
32052 | } else {
|
32053 | tree = this.createTree(isArray(allowed) ? allowed : elements);
|
32054 | }
|
32055 |
|
32056 |
|
32057 |
|
32058 | this._clipboard.set(tree);
|
32059 |
|
32060 | this._eventBus.fire('copyPaste.elementsCopied', {
|
32061 | elements: elements,
|
32062 | tree: tree
|
32063 | });
|
32064 |
|
32065 | return tree;
|
32066 | };
|
32067 |
|
32068 | |
32069 |
|
32070 |
|
32071 |
|
32072 |
|
32073 |
|
32074 |
|
32075 |
|
32076 | CopyPaste.prototype.paste = function(context) {
|
32077 | var tree = this._clipboard.get();
|
32078 |
|
32079 | if (this._clipboard.isEmpty()) {
|
32080 | return;
|
32081 | }
|
32082 |
|
32083 | var hints = context && context.hints || {};
|
32084 |
|
32085 | this._eventBus.fire('copyPaste.pasteElements', {
|
32086 | hints: hints
|
32087 | });
|
32088 |
|
32089 | var elements = this._createElements(tree);
|
32090 |
|
32091 |
|
32092 | if (context && context.element && context.point) {
|
32093 | return this._paste(elements, context.element, context.point, hints);
|
32094 | }
|
32095 |
|
32096 | this._create.start(this._mouse.getLastMoveEvent(), elements, {
|
32097 | hints: hints || {}
|
32098 | });
|
32099 | };
|
32100 |
|
32101 | |
32102 |
|
32103 |
|
32104 |
|
32105 |
|
32106 |
|
32107 |
|
32108 |
|
32109 | CopyPaste.prototype._paste = function(elements, target, position, hints) {
|
32110 |
|
32111 |
|
32112 | forEach(elements, function(element) {
|
32113 | if (!isNumber(element.x)) {
|
32114 | element.x = 0;
|
32115 | }
|
32116 |
|
32117 | if (!isNumber(element.y)) {
|
32118 | element.y = 0;
|
32119 | }
|
32120 | });
|
32121 |
|
32122 | var bbox = getBBox(elements);
|
32123 |
|
32124 |
|
32125 | forEach(elements, function(element) {
|
32126 | if (isConnection$1(element)) {
|
32127 | element.waypoints = map(element.waypoints, function(waypoint) {
|
32128 | return {
|
32129 | x: waypoint.x - bbox.x - bbox.width / 2,
|
32130 | y: waypoint.y - bbox.y - bbox.height / 2
|
32131 | };
|
32132 | });
|
32133 | }
|
32134 |
|
32135 | assign(element, {
|
32136 | x: element.x - bbox.x - bbox.width / 2,
|
32137 | y: element.y - bbox.y - bbox.height / 2
|
32138 | });
|
32139 | });
|
32140 |
|
32141 | return this._modeling.createElements(elements, position, target, assign({}, hints));
|
32142 | };
|
32143 |
|
32144 | |
32145 |
|
32146 |
|
32147 | CopyPaste.prototype._createElements = function(tree) {
|
32148 | var self = this;
|
32149 |
|
32150 | var eventBus = this._eventBus;
|
32151 |
|
32152 | var cache = {};
|
32153 |
|
32154 | var elements = [];
|
32155 |
|
32156 | forEach(tree, function(branch, depth) {
|
32157 |
|
32158 |
|
32159 | branch = sortBy(branch, 'priority');
|
32160 |
|
32161 | forEach(branch, function(descriptor) {
|
32162 |
|
32163 |
|
32164 | var attrs = assign({}, omit(descriptor, [ 'priority' ]));
|
32165 |
|
32166 | if (cache[ descriptor.parent ]) {
|
32167 | attrs.parent = cache[ descriptor.parent ];
|
32168 | } else {
|
32169 | delete attrs.parent;
|
32170 | }
|
32171 |
|
32172 | eventBus.fire('copyPaste.pasteElement', {
|
32173 | cache: cache,
|
32174 | descriptor: attrs
|
32175 | });
|
32176 |
|
32177 | var element;
|
32178 |
|
32179 | if (isConnection$1(attrs)) {
|
32180 | attrs.source = cache[ descriptor.source ];
|
32181 | attrs.target = cache[ descriptor.target ];
|
32182 |
|
32183 | element = cache[ descriptor.id ] = self.createConnection(attrs);
|
32184 |
|
32185 | elements.push(element);
|
32186 |
|
32187 | return;
|
32188 | }
|
32189 |
|
32190 | if (isLabel$2(attrs)) {
|
32191 | attrs.labelTarget = cache[ attrs.labelTarget ];
|
32192 |
|
32193 | element = cache[ descriptor.id ] = self.createLabel(attrs);
|
32194 |
|
32195 | elements.push(element);
|
32196 |
|
32197 | return;
|
32198 | }
|
32199 |
|
32200 | if (attrs.host) {
|
32201 | attrs.host = cache[ attrs.host ];
|
32202 | }
|
32203 |
|
32204 | element = cache[ descriptor.id ] = self.createShape(attrs);
|
32205 |
|
32206 | elements.push(element);
|
32207 | });
|
32208 |
|
32209 | });
|
32210 |
|
32211 | return elements;
|
32212 | };
|
32213 |
|
32214 | CopyPaste.prototype.createConnection = function(attrs) {
|
32215 | var connection = this._elementFactory.createConnection(omit(attrs, [ 'id' ]));
|
32216 |
|
32217 | return connection;
|
32218 | };
|
32219 |
|
32220 | CopyPaste.prototype.createLabel = function(attrs) {
|
32221 | var label = this._elementFactory.createLabel(omit(attrs, [ 'id' ]));
|
32222 |
|
32223 | return label;
|
32224 | };
|
32225 |
|
32226 | CopyPaste.prototype.createShape = function(attrs) {
|
32227 | var shape = this._elementFactory.createShape(omit(attrs, [ 'id' ]));
|
32228 |
|
32229 | return shape;
|
32230 | };
|
32231 |
|
32232 | |
32233 |
|
32234 |
|
32235 |
|
32236 |
|
32237 |
|
32238 |
|
32239 |
|
32240 | CopyPaste.prototype.hasRelations = function(element, elements) {
|
32241 | var labelTarget,
|
32242 | source,
|
32243 | target;
|
32244 |
|
32245 | if (isConnection$1(element)) {
|
32246 | source = find(elements, matchPattern({ id: element.source.id }));
|
32247 | target = find(elements, matchPattern({ id: element.target.id }));
|
32248 |
|
32249 | if (!source || !target) {
|
32250 | return false;
|
32251 | }
|
32252 | }
|
32253 |
|
32254 | if (isLabel$2(element)) {
|
32255 | labelTarget = find(elements, matchPattern({ id: element.labelTarget.id }));
|
32256 |
|
32257 | if (!labelTarget) {
|
32258 | return false;
|
32259 | }
|
32260 | }
|
32261 |
|
32262 | return true;
|
32263 | };
|
32264 |
|
32265 | |
32266 |
|
32267 |
|
32268 |
|
32269 |
|
32270 |
|
32271 |
|
32272 |
|
32273 |
|
32274 |
|
32275 |
|
32276 |
|
32277 |
|
32278 |
|
32279 |
|
32280 |
|
32281 |
|
32282 |
|
32283 |
|
32284 |
|
32285 |
|
32286 | CopyPaste.prototype.createTree = function(elements) {
|
32287 | var rules = this._rules,
|
32288 | self = this;
|
32289 |
|
32290 | var tree = {},
|
32291 | elementsData = [];
|
32292 |
|
32293 | var parents = getParents(elements);
|
32294 |
|
32295 | function canCopy(element, elements) {
|
32296 | return rules.allowed('element.copy', {
|
32297 | element: element,
|
32298 | elements: elements
|
32299 | });
|
32300 | }
|
32301 |
|
32302 | function addElementData(element, depth) {
|
32303 |
|
32304 |
|
32305 | var foundElementData = find(elementsData, function(elementsData) {
|
32306 | return element === elementsData.element;
|
32307 | });
|
32308 |
|
32309 |
|
32310 | if (!foundElementData) {
|
32311 | elementsData.push({
|
32312 | element: element,
|
32313 | depth: depth
|
32314 | });
|
32315 |
|
32316 | return;
|
32317 | }
|
32318 |
|
32319 |
|
32320 | if (foundElementData.depth < depth) {
|
32321 | elementsData = removeElementData(foundElementData, elementsData);
|
32322 |
|
32323 | elementsData.push({
|
32324 | element: foundElementData.element,
|
32325 | depth: depth
|
32326 | });
|
32327 | }
|
32328 | }
|
32329 |
|
32330 | function removeElementData(elementData, elementsData) {
|
32331 | var index = elementsData.indexOf(elementData);
|
32332 |
|
32333 | if (index !== -1) {
|
32334 | elementsData.splice(index, 1);
|
32335 | }
|
32336 |
|
32337 | return elementsData;
|
32338 | }
|
32339 |
|
32340 |
|
32341 | eachElement(parents, function(element, _index, depth) {
|
32342 |
|
32343 |
|
32344 | if (isLabel$2(element)) {
|
32345 | return;
|
32346 | }
|
32347 |
|
32348 |
|
32349 | forEach(element.labels, function(label) {
|
32350 | addElementData(label, depth);
|
32351 | });
|
32352 |
|
32353 | function addRelatedElements(elements) {
|
32354 | elements && elements.length && forEach(elements, function(element) {
|
32355 |
|
32356 |
|
32357 | forEach(element.labels, function(label) {
|
32358 | addElementData(label, depth);
|
32359 | });
|
32360 |
|
32361 | addElementData(element, depth);
|
32362 | });
|
32363 | }
|
32364 |
|
32365 | forEach([ element.attachers, element.incoming, element.outgoing ], addRelatedElements);
|
32366 |
|
32367 | addElementData(element, depth);
|
32368 |
|
32369 | return element.children;
|
32370 | });
|
32371 |
|
32372 | elements = map(elementsData, function(elementData) {
|
32373 | return elementData.element;
|
32374 | });
|
32375 |
|
32376 |
|
32377 | elementsData = map(elementsData, function(elementData) {
|
32378 | elementData.descriptor = {};
|
32379 |
|
32380 | self._eventBus.fire('copyPaste.copyElement', {
|
32381 | descriptor: elementData.descriptor,
|
32382 | element: elementData.element,
|
32383 | elements: elements
|
32384 | });
|
32385 |
|
32386 | return elementData;
|
32387 | });
|
32388 |
|
32389 |
|
32390 | elementsData = sortBy(elementsData, function(elementData) {
|
32391 | return elementData.descriptor.priority;
|
32392 | });
|
32393 |
|
32394 | elements = map(elementsData, function(elementData) {
|
32395 | return elementData.element;
|
32396 | });
|
32397 |
|
32398 |
|
32399 | forEach(elementsData, function(elementData) {
|
32400 | var depth = elementData.depth;
|
32401 |
|
32402 | if (!self.hasRelations(elementData.element, elements)) {
|
32403 | removeElement(elementData.element, elements);
|
32404 |
|
32405 | return;
|
32406 | }
|
32407 |
|
32408 | if (!canCopy(elementData.element, elements)) {
|
32409 | removeElement(elementData.element, elements);
|
32410 |
|
32411 | return;
|
32412 | }
|
32413 |
|
32414 | if (!tree[depth]) {
|
32415 | tree[depth] = [];
|
32416 | }
|
32417 |
|
32418 | tree[depth].push(elementData.descriptor);
|
32419 | });
|
32420 |
|
32421 | return tree;
|
32422 | };
|
32423 |
|
32424 |
|
32425 |
|
32426 | function isAttacher(element) {
|
32427 | return !!element.host;
|
32428 | }
|
32429 |
|
32430 | function isConnection$1(element) {
|
32431 | return !!element.waypoints;
|
32432 | }
|
32433 |
|
32434 | function isLabel$2(element) {
|
32435 | return !!element.labelTarget;
|
32436 | }
|
32437 |
|
32438 | function copyWaypoints(element) {
|
32439 | return map(element.waypoints, function(waypoint) {
|
32440 |
|
32441 | waypoint = copyWaypoint(waypoint);
|
32442 |
|
32443 | if (waypoint.original) {
|
32444 | waypoint.original = copyWaypoint(waypoint.original);
|
32445 | }
|
32446 |
|
32447 | return waypoint;
|
32448 | });
|
32449 | }
|
32450 |
|
32451 | function copyWaypoint(waypoint) {
|
32452 | return assign({}, waypoint);
|
32453 | }
|
32454 |
|
32455 | function removeElement(element, elements) {
|
32456 | var index = elements.indexOf(element);
|
32457 |
|
32458 | if (index === -1) {
|
32459 | return elements;
|
32460 | }
|
32461 |
|
32462 | return elements.splice(index, 1);
|
32463 | }
|
32464 |
|
32465 | var CopyPasteModule = {
|
32466 | __depends__: [
|
32467 | ClipboardModule,
|
32468 | CreateModule,
|
32469 | MouseModule,
|
32470 | RulesModule
|
32471 | ],
|
32472 | __init__: [ 'copyPaste' ],
|
32473 | copyPaste: [ 'type', CopyPaste ]
|
32474 | };
|
32475 |
|
32476 | function copyProperties(source, target, properties) {
|
32477 | if (!isArray(properties)) {
|
32478 | properties = [ properties ];
|
32479 | }
|
32480 |
|
32481 | forEach(properties, function(property) {
|
32482 | if (!isUndefined(source[property])) {
|
32483 | target[property] = source[property];
|
32484 | }
|
32485 | });
|
32486 | }
|
32487 |
|
32488 | function removeProperties(element, properties) {
|
32489 | if (!isArray(properties)) {
|
32490 | properties = [ properties ];
|
32491 | }
|
32492 |
|
32493 | forEach(properties, function(property) {
|
32494 | if (element[property]) {
|
32495 | delete element[property];
|
32496 | }
|
32497 | });
|
32498 | }
|
32499 |
|
32500 | var LOW_PRIORITY$6 = 750;
|
32501 |
|
32502 |
|
32503 | function BpmnCopyPaste(bpmnFactory, eventBus, moddleCopy) {
|
32504 |
|
32505 | eventBus.on('copyPaste.copyElement', LOW_PRIORITY$6, function(context) {
|
32506 | var descriptor = context.descriptor,
|
32507 | element = context.element;
|
32508 |
|
32509 | var businessObject = descriptor.oldBusinessObject = getBusinessObject(element);
|
32510 |
|
32511 | descriptor.type = element.type;
|
32512 |
|
32513 | copyProperties(businessObject, descriptor, 'name');
|
32514 |
|
32515 | descriptor.di = {};
|
32516 |
|
32517 |
|
32518 | copyProperties(businessObject.di, descriptor.di, [
|
32519 | 'fill',
|
32520 | 'stroke'
|
32521 | ]);
|
32522 |
|
32523 | copyProperties(businessObject.di, descriptor, 'isExpanded');
|
32524 |
|
32525 | if (isLabel$3(descriptor)) {
|
32526 | return descriptor;
|
32527 | }
|
32528 |
|
32529 |
|
32530 | if (businessObject.default) {
|
32531 | descriptor.default = businessObject.default.id;
|
32532 | }
|
32533 | });
|
32534 |
|
32535 | eventBus.on('moddleCopy.canCopyProperty', function(context) {
|
32536 | var parent = context.parent,
|
32537 | property = context.property,
|
32538 | propertyName = context.propertyName,
|
32539 | bpmnProcess;
|
32540 |
|
32541 | if (
|
32542 | propertyName === 'processRef' &&
|
32543 | is$1(parent, 'bpmn:Participant') &&
|
32544 | is$1(property, 'bpmn:Process')
|
32545 | ) {
|
32546 | bpmnProcess = bpmnFactory.create('bpmn:Process');
|
32547 |
|
32548 |
|
32549 | return moddleCopy.copyElement(property, bpmnProcess);
|
32550 | }
|
32551 | });
|
32552 |
|
32553 | var references;
|
32554 |
|
32555 | function resolveReferences(descriptor, cache) {
|
32556 | var businessObject = getBusinessObject(descriptor);
|
32557 |
|
32558 |
|
32559 | if (descriptor.default) {
|
32560 |
|
32561 |
|
32562 | references[ descriptor.default ] = {
|
32563 | element: businessObject,
|
32564 | property: 'default'
|
32565 | };
|
32566 | }
|
32567 |
|
32568 |
|
32569 | if (descriptor.host) {
|
32570 |
|
32571 |
|
32572 | getBusinessObject(descriptor).attachedToRef = getBusinessObject(cache[ descriptor.host ]);
|
32573 | }
|
32574 |
|
32575 | references = omit(references, reduce(references, function(array, reference, key) {
|
32576 | var element = reference.element,
|
32577 | property = reference.property;
|
32578 |
|
32579 | if (key === descriptor.id) {
|
32580 | element[ property ] = businessObject;
|
32581 |
|
32582 | array.push(descriptor.id);
|
32583 | }
|
32584 |
|
32585 | return array;
|
32586 | }, []));
|
32587 | }
|
32588 |
|
32589 | eventBus.on('copyPaste.pasteElements', function() {
|
32590 | references = {};
|
32591 | });
|
32592 |
|
32593 | eventBus.on('copyPaste.pasteElement', function(context) {
|
32594 | var cache = context.cache,
|
32595 | descriptor = context.descriptor,
|
32596 | oldBusinessObject = descriptor.oldBusinessObject,
|
32597 | newBusinessObject;
|
32598 |
|
32599 |
|
32600 | if (isLabel$3(descriptor)) {
|
32601 | descriptor.businessObject = getBusinessObject(cache[ descriptor.labelTarget ]);
|
32602 |
|
32603 | return;
|
32604 | }
|
32605 |
|
32606 | newBusinessObject = bpmnFactory.create(oldBusinessObject.$type);
|
32607 |
|
32608 | descriptor.businessObject = moddleCopy.copyElement(
|
32609 | oldBusinessObject,
|
32610 | newBusinessObject
|
32611 | );
|
32612 |
|
32613 |
|
32614 | resolveReferences(descriptor, cache);
|
32615 |
|
32616 | copyProperties(descriptor, newBusinessObject, [
|
32617 | 'isExpanded',
|
32618 | 'name'
|
32619 | ]);
|
32620 |
|
32621 | removeProperties(descriptor, 'oldBusinessObject');
|
32622 | });
|
32623 |
|
32624 | }
|
32625 |
|
32626 |
|
32627 | BpmnCopyPaste.$inject = [
|
32628 | 'bpmnFactory',
|
32629 | 'eventBus',
|
32630 | 'moddleCopy'
|
32631 | ];
|
32632 |
|
32633 |
|
32634 |
|
32635 | function isLabel$3(element) {
|
32636 | return !!element.labelTarget;
|
32637 | }
|
32638 |
|
32639 | var DISALLOWED_PROPERTIES = [
|
32640 | 'artifacts',
|
32641 | 'dataInputAssociations',
|
32642 | 'dataOutputAssociations',
|
32643 | 'default',
|
32644 | 'flowElements',
|
32645 | 'lanes',
|
32646 | 'incoming',
|
32647 | 'outgoing'
|
32648 | ];
|
32649 |
|
32650 | |
32651 |
|
32652 |
|
32653 |
|
32654 |
|
32655 |
|
32656 |
|
32657 |
|
32658 |
|
32659 |
|
32660 |
|
32661 |
|
32662 | |
32663 |
|
32664 |
|
32665 |
|
32666 |
|
32667 |
|
32668 |
|
32669 |
|
32670 |
|
32671 |
|
32672 |
|
32673 |
|
32674 | |
32675 |
|
32676 |
|
32677 |
|
32678 |
|
32679 |
|
32680 |
|
32681 |
|
32682 |
|
32683 |
|
32684 |
|
32685 |
|
32686 | |
32687 |
|
32688 |
|
32689 |
|
32690 |
|
32691 |
|
32692 |
|
32693 | function ModdleCopy(eventBus, bpmnFactory, moddle) {
|
32694 | this._bpmnFactory = bpmnFactory;
|
32695 | this._eventBus = eventBus;
|
32696 | this._moddle = moddle;
|
32697 |
|
32698 |
|
32699 | eventBus.on('moddleCopy.canCopyProperties', function(context) {
|
32700 | var propertyNames = context.propertyNames;
|
32701 |
|
32702 | if (!propertyNames || !propertyNames.length) {
|
32703 | return;
|
32704 | }
|
32705 |
|
32706 | return sortBy(propertyNames, function(propertyName) {
|
32707 | return propertyName === 'extensionElements';
|
32708 | });
|
32709 | });
|
32710 |
|
32711 |
|
32712 | eventBus.on('moddleCopy.canCopyProperty', function(context) {
|
32713 | var parent = context.parent,
|
32714 | parentDescriptor = isObject(parent) && parent.$descriptor,
|
32715 | propertyName = context.propertyName;
|
32716 |
|
32717 | if (propertyName && DISALLOWED_PROPERTIES.indexOf(propertyName) !== -1) {
|
32718 |
|
32719 |
|
32720 | return false;
|
32721 | }
|
32722 |
|
32723 | if (propertyName &&
|
32724 | parentDescriptor &&
|
32725 | !find(parentDescriptor.properties, matchPattern({ name: propertyName }))) {
|
32726 |
|
32727 |
|
32728 | return false;
|
32729 | }
|
32730 | });
|
32731 |
|
32732 |
|
32733 | eventBus.on('moddleCopy.canSetCopiedProperty', function(context) {
|
32734 | var property = context.property;
|
32735 |
|
32736 | if (is$2(property, 'bpmn:ExtensionElements') && (!property.values || !property.values.length)) {
|
32737 |
|
32738 |
|
32739 | return false;
|
32740 | }
|
32741 | });
|
32742 | }
|
32743 |
|
32744 | ModdleCopy.$inject = [
|
32745 | 'eventBus',
|
32746 | 'bpmnFactory',
|
32747 | 'moddle'
|
32748 | ];
|
32749 |
|
32750 | |
32751 |
|
32752 |
|
32753 |
|
32754 |
|
32755 |
|
32756 |
|
32757 |
|
32758 |
|
32759 | ModdleCopy.prototype.copyElement = function(sourceElement, targetElement, propertyNames) {
|
32760 | var self = this;
|
32761 |
|
32762 | if (propertyNames && !isArray(propertyNames)) {
|
32763 | propertyNames = [ propertyNames ];
|
32764 | }
|
32765 |
|
32766 | propertyNames = propertyNames || getPropertyNames(sourceElement.$descriptor);
|
32767 |
|
32768 | var canCopyProperties = this._eventBus.fire('moddleCopy.canCopyProperties', {
|
32769 | propertyNames: propertyNames,
|
32770 | sourceElement: sourceElement,
|
32771 | targetElement: targetElement
|
32772 | });
|
32773 |
|
32774 | if (canCopyProperties === false) {
|
32775 | return targetElement;
|
32776 | }
|
32777 |
|
32778 | if (isArray(canCopyProperties)) {
|
32779 | propertyNames = canCopyProperties;
|
32780 | }
|
32781 |
|
32782 |
|
32783 | forEach(propertyNames, function(propertyName) {
|
32784 | var sourceProperty;
|
32785 |
|
32786 | if (has(sourceElement, propertyName)) {
|
32787 | sourceProperty = sourceElement.get(propertyName);
|
32788 | }
|
32789 |
|
32790 | var copiedProperty = self.copyProperty(sourceProperty, targetElement, propertyName);
|
32791 |
|
32792 | var canSetProperty = self._eventBus.fire('moddleCopy.canSetCopiedProperty', {
|
32793 | parent: parent,
|
32794 | property: copiedProperty,
|
32795 | propertyName: propertyName
|
32796 | });
|
32797 |
|
32798 | if (canSetProperty === false) {
|
32799 | return;
|
32800 | }
|
32801 |
|
32802 | if (isDefined(copiedProperty)) {
|
32803 | targetElement.set(propertyName, copiedProperty);
|
32804 | }
|
32805 | });
|
32806 |
|
32807 | return targetElement;
|
32808 | };
|
32809 |
|
32810 | |
32811 |
|
32812 |
|
32813 |
|
32814 |
|
32815 |
|
32816 |
|
32817 |
|
32818 |
|
32819 | ModdleCopy.prototype.copyProperty = function(property, parent, propertyName) {
|
32820 | var self = this;
|
32821 |
|
32822 |
|
32823 | var copiedProperty = this._eventBus.fire('moddleCopy.canCopyProperty', {
|
32824 | parent: parent,
|
32825 | property: property,
|
32826 | propertyName: propertyName
|
32827 | });
|
32828 |
|
32829 |
|
32830 | if (copiedProperty === false) {
|
32831 | return;
|
32832 | }
|
32833 |
|
32834 | if (copiedProperty) {
|
32835 | if (isObject(copiedProperty) && copiedProperty.$type && !copiedProperty.$parent) {
|
32836 | copiedProperty.$parent = parent;
|
32837 | }
|
32838 |
|
32839 | return copiedProperty;
|
32840 | }
|
32841 |
|
32842 | var propertyDescriptor = this._moddle.getPropertyDescriptor(parent, propertyName);
|
32843 |
|
32844 |
|
32845 | if (propertyDescriptor.isId || propertyDescriptor.isReference) {
|
32846 | return;
|
32847 | }
|
32848 |
|
32849 |
|
32850 | if (isArray(property)) {
|
32851 | return reduce(property, function(childProperties, childProperty) {
|
32852 |
|
32853 |
|
32854 | copiedProperty = self.copyProperty(childProperty, parent, propertyName);
|
32855 |
|
32856 |
|
32857 | if (copiedProperty) {
|
32858 | copiedProperty.$parent = parent;
|
32859 |
|
32860 | return childProperties.concat(copiedProperty);
|
32861 | }
|
32862 |
|
32863 | return childProperties;
|
32864 | }, []);
|
32865 | }
|
32866 |
|
32867 |
|
32868 | if (isObject(property) && property.$type) {
|
32869 | if (this._moddle.getElementDescriptor(property).isGeneric) {
|
32870 | return;
|
32871 | }
|
32872 |
|
32873 | copiedProperty = self._bpmnFactory.create(property.$type);
|
32874 |
|
32875 | copiedProperty.$parent = parent;
|
32876 |
|
32877 |
|
32878 | copiedProperty = self.copyElement(property, copiedProperty);
|
32879 |
|
32880 | return copiedProperty;
|
32881 | }
|
32882 |
|
32883 |
|
32884 | return property;
|
32885 | };
|
32886 |
|
32887 |
|
32888 |
|
32889 | function getPropertyNames(descriptor, keepDefaultProperties) {
|
32890 | return reduce(descriptor.properties, function(properties, property) {
|
32891 |
|
32892 | if (keepDefaultProperties && property.default) {
|
32893 | return properties;
|
32894 | }
|
32895 |
|
32896 | return properties.concat(property.name);
|
32897 | }, []);
|
32898 | }
|
32899 |
|
32900 | function is$2(element, type) {
|
32901 | return element && (typeof element.$instanceOf === 'function') && element.$instanceOf(type);
|
32902 | }
|
32903 |
|
32904 | var CopyPasteModule$1 = {
|
32905 | __depends__: [
|
32906 | CopyPasteModule
|
32907 | ],
|
32908 | __init__: [ 'bpmnCopyPaste', 'moddleCopy' ],
|
32909 | bpmnCopyPaste: [ 'type', BpmnCopyPaste ],
|
32910 | moddleCopy: [ 'type', ModdleCopy ]
|
32911 | };
|
32912 |
|
32913 | var round$6 = Math.round;
|
32914 |
|
32915 | |
32916 |
|
32917 |
|
32918 | function Replace(modeling) {
|
32919 |
|
32920 | this._modeling = modeling;
|
32921 | }
|
32922 |
|
32923 | Replace.$inject = [ 'modeling' ];
|
32924 |
|
32925 | |
32926 |
|
32927 |
|
32928 |
|
32929 |
|
32930 |
|
32931 |
|
32932 |
|
32933 | Replace.prototype.replaceElement = function(oldElement, newElementData, options) {
|
32934 |
|
32935 | var modeling = this._modeling;
|
32936 |
|
32937 | var newElement = null;
|
32938 |
|
32939 | if (oldElement.waypoints) ; else {
|
32940 |
|
32941 |
|
32942 |
|
32943 | newElementData.x = round$6(oldElement.x + (newElementData.width || oldElement.width) / 2);
|
32944 | newElementData.y = round$6(oldElement.y + (newElementData.height || oldElement.height) / 2);
|
32945 |
|
32946 | newElement = modeling.replaceShape(oldElement, newElementData, options);
|
32947 | }
|
32948 |
|
32949 | return newElement;
|
32950 | };
|
32951 |
|
32952 | var ReplaceModule = {
|
32953 | __init__: [ 'replace' ],
|
32954 | replace: [ 'type', Replace ]
|
32955 | };
|
32956 |
|
32957 | function copyProperties$1(source, target, properties) {
|
32958 | if (!isArray(properties)) {
|
32959 | properties = [ properties ];
|
32960 | }
|
32961 |
|
32962 | forEach(properties, function(property) {
|
32963 | if (!isUndefined(source[property])) {
|
32964 | target[property] = source[property];
|
32965 | }
|
32966 | });
|
32967 | }
|
32968 |
|
32969 | var CUSTOM_PROPERTIES = [
|
32970 | 'cancelActivity',
|
32971 | 'instantiate',
|
32972 | 'eventGatewayType',
|
32973 | 'triggeredByEvent',
|
32974 | 'isInterrupting'
|
32975 | ];
|
32976 |
|
32977 |
|
32978 | function toggeling(element, target) {
|
32979 |
|
32980 | var oldCollapsed = (
|
32981 | element && has(element, 'collapsed') ? element.collapsed : !isExpanded(element)
|
32982 | );
|
32983 |
|
32984 | var targetCollapsed;
|
32985 |
|
32986 | if (target && (has(target, 'collapsed') || has(target, 'isExpanded'))) {
|
32987 |
|
32988 |
|
32989 | targetCollapsed = (
|
32990 | has(target, 'collapsed') ? target.collapsed : !target.isExpanded
|
32991 | );
|
32992 | } else {
|
32993 |
|
32994 |
|
32995 | targetCollapsed = oldCollapsed;
|
32996 | }
|
32997 |
|
32998 | if (oldCollapsed !== targetCollapsed) {
|
32999 | element.collapsed = oldCollapsed;
|
33000 | return true;
|
33001 | }
|
33002 |
|
33003 | return false;
|
33004 | }
|
33005 |
|
33006 |
|
33007 |
|
33008 | |
33009 |
|
33010 |
|
33011 | function BpmnReplace(
|
33012 | bpmnFactory,
|
33013 | elementFactory,
|
33014 | moddleCopy,
|
33015 | modeling,
|
33016 | replace,
|
33017 | selection
|
33018 | ) {
|
33019 |
|
33020 | |
33021 |
|
33022 |
|
33023 |
|
33024 |
|
33025 |
|
33026 |
|
33027 |
|
33028 |
|
33029 |
|
33030 | function replaceElement(element, target, hints) {
|
33031 |
|
33032 | hints = hints || {};
|
33033 |
|
33034 | var type = target.type,
|
33035 | oldBusinessObject = element.businessObject;
|
33036 |
|
33037 | if (isSubProcess(oldBusinessObject)) {
|
33038 | if (type === 'bpmn:SubProcess') {
|
33039 | if (toggeling(element, target)) {
|
33040 |
|
33041 |
|
33042 | modeling.toggleCollapse(element);
|
33043 |
|
33044 | return element;
|
33045 | }
|
33046 | }
|
33047 | }
|
33048 |
|
33049 | var newBusinessObject = bpmnFactory.create(type);
|
33050 |
|
33051 | var newElement = {
|
33052 | type: type,
|
33053 | businessObject: newBusinessObject
|
33054 | };
|
33055 |
|
33056 | var elementProps = getPropertyNames(oldBusinessObject.$descriptor),
|
33057 | newElementProps = getPropertyNames(newBusinessObject.$descriptor, true),
|
33058 | copyProps = intersection(elementProps, newElementProps);
|
33059 |
|
33060 |
|
33061 | assign(newBusinessObject, pick(target, CUSTOM_PROPERTIES));
|
33062 |
|
33063 | var properties = filter(copyProps, function(propertyName) {
|
33064 |
|
33065 |
|
33066 | if (propertyName === 'eventDefinitions') {
|
33067 | return hasEventDefinition$1(element, target.eventDefinitionType);
|
33068 | }
|
33069 |
|
33070 |
|
33071 |
|
33072 | if (propertyName === 'loopCharacteristics') {
|
33073 | return !isEventSubProcess(newBusinessObject);
|
33074 | }
|
33075 |
|
33076 |
|
33077 | if (newBusinessObject.hasOwnProperty(propertyName)) {
|
33078 | return false;
|
33079 | }
|
33080 |
|
33081 | if (propertyName === 'processRef' && target.isExpanded === false) {
|
33082 | return false;
|
33083 | }
|
33084 |
|
33085 | if (propertyName === 'triggeredByEvent') {
|
33086 | return false;
|
33087 | }
|
33088 |
|
33089 | return true;
|
33090 | });
|
33091 |
|
33092 | newBusinessObject = moddleCopy.copyElement(
|
33093 | oldBusinessObject,
|
33094 | newBusinessObject,
|
33095 | properties
|
33096 | );
|
33097 |
|
33098 |
|
33099 | if (target.eventDefinitionType) {
|
33100 |
|
33101 |
|
33102 |
|
33103 |
|
33104 | if (!hasEventDefinition$1(newBusinessObject, target.eventDefinitionType)) {
|
33105 | newElement.eventDefinitionType = target.eventDefinitionType;
|
33106 | }
|
33107 | }
|
33108 |
|
33109 | if (is$1(oldBusinessObject, 'bpmn:Activity')) {
|
33110 |
|
33111 | if (isSubProcess(oldBusinessObject)) {
|
33112 |
|
33113 |
|
33114 | newElement.isExpanded = isExpanded(oldBusinessObject);
|
33115 | }
|
33116 |
|
33117 |
|
33118 | else if (target && has(target, 'isExpanded')) {
|
33119 | newElement.isExpanded = target.isExpanded;
|
33120 | }
|
33121 |
|
33122 |
|
33123 |
|
33124 |
|
33125 | if ((isExpanded(oldBusinessObject) && !is$1(oldBusinessObject, 'bpmn:Task')) && newElement.isExpanded) {
|
33126 | newElement.width = element.width;
|
33127 | newElement.height = element.height;
|
33128 | }
|
33129 | }
|
33130 |
|
33131 |
|
33132 | if (isSubProcess(oldBusinessObject) && !isSubProcess(newBusinessObject)) {
|
33133 | hints.moveChildren = false;
|
33134 | }
|
33135 |
|
33136 |
|
33137 | if (is$1(oldBusinessObject, 'bpmn:Participant')) {
|
33138 |
|
33139 |
|
33140 | if (target.isExpanded === true) {
|
33141 | newBusinessObject.processRef = bpmnFactory.create('bpmn:Process');
|
33142 | } else {
|
33143 |
|
33144 |
|
33145 | hints.moveChildren = false;
|
33146 | }
|
33147 |
|
33148 |
|
33149 | newElement.width = element.width;
|
33150 | newElement.height = elementFactory._getDefaultSize(newBusinessObject).height;
|
33151 | }
|
33152 |
|
33153 | newBusinessObject.name = oldBusinessObject.name;
|
33154 |
|
33155 |
|
33156 | if (
|
33157 | isAny(oldBusinessObject, [
|
33158 | 'bpmn:ExclusiveGateway',
|
33159 | 'bpmn:InclusiveGateway',
|
33160 | 'bpmn:Activity'
|
33161 | ]) &&
|
33162 | isAny(newBusinessObject, [
|
33163 | 'bpmn:ExclusiveGateway',
|
33164 | 'bpmn:InclusiveGateway',
|
33165 | 'bpmn:Activity'
|
33166 | ])
|
33167 | ) {
|
33168 | newBusinessObject.default = oldBusinessObject.default;
|
33169 | }
|
33170 |
|
33171 | if (
|
33172 | target.host &&
|
33173 | !is$1(oldBusinessObject, 'bpmn:BoundaryEvent') &&
|
33174 | is$1(newBusinessObject, 'bpmn:BoundaryEvent')
|
33175 | ) {
|
33176 | newElement.host = target.host;
|
33177 | }
|
33178 |
|
33179 | newElement.di = {};
|
33180 |
|
33181 |
|
33182 | copyProperties$1(oldBusinessObject.di, newElement.di, [
|
33183 | 'fill',
|
33184 | 'stroke'
|
33185 | ]);
|
33186 |
|
33187 | newElement = replace.replaceElement(element, newElement, hints);
|
33188 |
|
33189 | if (hints.select !== false) {
|
33190 | selection.select(newElement);
|
33191 | }
|
33192 |
|
33193 | return newElement;
|
33194 | }
|
33195 |
|
33196 | this.replaceElement = replaceElement;
|
33197 | }
|
33198 |
|
33199 | BpmnReplace.$inject = [
|
33200 | 'bpmnFactory',
|
33201 | 'elementFactory',
|
33202 | 'moddleCopy',
|
33203 | 'modeling',
|
33204 | 'replace',
|
33205 | 'selection'
|
33206 | ];
|
33207 |
|
33208 |
|
33209 | function isSubProcess(bo) {
|
33210 | return is$1(bo, 'bpmn:SubProcess');
|
33211 | }
|
33212 |
|
33213 | function hasEventDefinition$1(element, type) {
|
33214 |
|
33215 | var bo = getBusinessObject(element);
|
33216 |
|
33217 | return type && bo.get('eventDefinitions').some(function(definition) {
|
33218 | return is$1(definition, type);
|
33219 | });
|
33220 | }
|
33221 |
|
33222 | |
33223 |
|
33224 |
|
33225 | function intersection(a1, a2) {
|
33226 | return a1.filter(function(el) {
|
33227 | return a2.indexOf(el) !== -1;
|
33228 | });
|
33229 | }
|
33230 |
|
33231 | var ReplaceModule$1 = {
|
33232 | __depends__: [
|
33233 | CopyPasteModule$1,
|
33234 | ReplaceModule,
|
33235 | SelectionModule
|
33236 | ],
|
33237 | bpmnReplace: [ 'type', BpmnReplace ]
|
33238 | };
|
33239 |
|
33240 | |
33241 |
|
33242 |
|
33243 |
|
33244 |
|
33245 |
|
33246 |
|
33247 |
|
33248 |
|
33249 | function isDifferentType(element) {
|
33250 |
|
33251 | return function(entry) {
|
33252 | var target = entry.target;
|
33253 |
|
33254 | var businessObject = getBusinessObject(element),
|
33255 | eventDefinition = businessObject.eventDefinitions && businessObject.eventDefinitions[0];
|
33256 |
|
33257 | var isTypeEqual = businessObject.$type === target.type;
|
33258 |
|
33259 | var isEventDefinitionEqual = (
|
33260 | (eventDefinition && eventDefinition.$type) === target.eventDefinitionType
|
33261 | );
|
33262 |
|
33263 | var isTriggeredByEventEqual = (
|
33264 | businessObject.triggeredByEvent === target.triggeredByEvent
|
33265 | );
|
33266 |
|
33267 | var isExpandedEqual = (
|
33268 | target.isExpanded === undefined ||
|
33269 | target.isExpanded === isExpanded(businessObject)
|
33270 | );
|
33271 |
|
33272 | return !isTypeEqual || !isEventDefinitionEqual || !isTriggeredByEventEqual || !isExpandedEqual;
|
33273 | };
|
33274 | }
|
33275 |
|
33276 | var START_EVENT = [
|
33277 | {
|
33278 | label: 'Start Event',
|
33279 | actionName: 'replace-with-none-start',
|
33280 | className: 'bpmn-icon-start-event-none',
|
33281 | target: {
|
33282 | type: 'bpmn:StartEvent'
|
33283 | }
|
33284 | },
|
33285 | {
|
33286 | label: 'Intermediate Throw Event',
|
33287 | actionName: 'replace-with-none-intermediate-throwing',
|
33288 | className: 'bpmn-icon-intermediate-event-none',
|
33289 | target: {
|
33290 | type: 'bpmn:IntermediateThrowEvent'
|
33291 | }
|
33292 | },
|
33293 | {
|
33294 | label: 'End Event',
|
33295 | actionName: 'replace-with-none-end',
|
33296 | className: 'bpmn-icon-end-event-none',
|
33297 | target: {
|
33298 | type: 'bpmn:EndEvent'
|
33299 | }
|
33300 | },
|
33301 | {
|
33302 | label: 'Message Start Event',
|
33303 | actionName: 'replace-with-message-start',
|
33304 | className: 'bpmn-icon-start-event-message',
|
33305 | target: {
|
33306 | type: 'bpmn:StartEvent',
|
33307 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
33308 | }
|
33309 | },
|
33310 | {
|
33311 | label: 'Timer Start Event',
|
33312 | actionName: 'replace-with-timer-start',
|
33313 | className: 'bpmn-icon-start-event-timer',
|
33314 | target: {
|
33315 | type: 'bpmn:StartEvent',
|
33316 | eventDefinitionType: 'bpmn:TimerEventDefinition'
|
33317 | }
|
33318 | },
|
33319 | {
|
33320 | label: 'Conditional Start Event',
|
33321 | actionName: 'replace-with-conditional-start',
|
33322 | className: 'bpmn-icon-start-event-condition',
|
33323 | target: {
|
33324 | type: 'bpmn:StartEvent',
|
33325 | eventDefinitionType: 'bpmn:ConditionalEventDefinition'
|
33326 | }
|
33327 | },
|
33328 | {
|
33329 | label: 'Signal Start Event',
|
33330 | actionName: 'replace-with-signal-start',
|
33331 | className: 'bpmn-icon-start-event-signal',
|
33332 | target: {
|
33333 | type: 'bpmn:StartEvent',
|
33334 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
33335 | }
|
33336 | }
|
33337 | ];
|
33338 |
|
33339 | var INTERMEDIATE_EVENT = [
|
33340 | {
|
33341 | label: 'Start Event',
|
33342 | actionName: 'replace-with-none-start',
|
33343 | className: 'bpmn-icon-start-event-none',
|
33344 | target: {
|
33345 | type: 'bpmn:StartEvent'
|
33346 | }
|
33347 | },
|
33348 | {
|
33349 | label: 'Intermediate Throw Event',
|
33350 | actionName: 'replace-with-none-intermediate-throw',
|
33351 | className: 'bpmn-icon-intermediate-event-none',
|
33352 | target: {
|
33353 | type: 'bpmn:IntermediateThrowEvent'
|
33354 | }
|
33355 | },
|
33356 | {
|
33357 | label: 'End Event',
|
33358 | actionName: 'replace-with-none-end',
|
33359 | className: 'bpmn-icon-end-event-none',
|
33360 | target: {
|
33361 | type: 'bpmn:EndEvent'
|
33362 | }
|
33363 | },
|
33364 | {
|
33365 | label: 'Message Intermediate Catch Event',
|
33366 | actionName: 'replace-with-message-intermediate-catch',
|
33367 | className: 'bpmn-icon-intermediate-event-catch-message',
|
33368 | target: {
|
33369 | type: 'bpmn:IntermediateCatchEvent',
|
33370 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
33371 | }
|
33372 | },
|
33373 | {
|
33374 | label: 'Message Intermediate Throw Event',
|
33375 | actionName: 'replace-with-message-intermediate-throw',
|
33376 | className: 'bpmn-icon-intermediate-event-throw-message',
|
33377 | target: {
|
33378 | type: 'bpmn:IntermediateThrowEvent',
|
33379 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
33380 | }
|
33381 | },
|
33382 | {
|
33383 | label: 'Timer Intermediate Catch Event',
|
33384 | actionName: 'replace-with-timer-intermediate-catch',
|
33385 | className: 'bpmn-icon-intermediate-event-catch-timer',
|
33386 | target: {
|
33387 | type: 'bpmn:IntermediateCatchEvent',
|
33388 | eventDefinitionType: 'bpmn:TimerEventDefinition'
|
33389 | }
|
33390 | },
|
33391 | {
|
33392 | label: 'Escalation Intermediate Throw Event',
|
33393 | actionName: 'replace-with-escalation-intermediate-throw',
|
33394 | className: 'bpmn-icon-intermediate-event-throw-escalation',
|
33395 | target: {
|
33396 | type: 'bpmn:IntermediateThrowEvent',
|
33397 | eventDefinitionType: 'bpmn:EscalationEventDefinition'
|
33398 | }
|
33399 | },
|
33400 | {
|
33401 | label: 'Conditional Intermediate Catch Event',
|
33402 | actionName: 'replace-with-conditional-intermediate-catch',
|
33403 | className: 'bpmn-icon-intermediate-event-catch-condition',
|
33404 | target: {
|
33405 | type: 'bpmn:IntermediateCatchEvent',
|
33406 | eventDefinitionType: 'bpmn:ConditionalEventDefinition'
|
33407 | }
|
33408 | },
|
33409 | {
|
33410 | label: 'Link Intermediate Catch Event',
|
33411 | actionName: 'replace-with-link-intermediate-catch',
|
33412 | className: 'bpmn-icon-intermediate-event-catch-link',
|
33413 | target: {
|
33414 | type: 'bpmn:IntermediateCatchEvent',
|
33415 | eventDefinitionType: 'bpmn:LinkEventDefinition'
|
33416 | }
|
33417 | },
|
33418 | {
|
33419 | label: 'Link Intermediate Throw Event',
|
33420 | actionName: 'replace-with-link-intermediate-throw',
|
33421 | className: 'bpmn-icon-intermediate-event-throw-link',
|
33422 | target: {
|
33423 | type: 'bpmn:IntermediateThrowEvent',
|
33424 | eventDefinitionType: 'bpmn:LinkEventDefinition'
|
33425 | }
|
33426 | },
|
33427 | {
|
33428 | label: 'Compensation Intermediate Throw Event',
|
33429 | actionName: 'replace-with-compensation-intermediate-throw',
|
33430 | className: 'bpmn-icon-intermediate-event-throw-compensation',
|
33431 | target: {
|
33432 | type: 'bpmn:IntermediateThrowEvent',
|
33433 | eventDefinitionType: 'bpmn:CompensateEventDefinition'
|
33434 | }
|
33435 | },
|
33436 | {
|
33437 | label: 'Signal Intermediate Catch Event',
|
33438 | actionName: 'replace-with-signal-intermediate-catch',
|
33439 | className: 'bpmn-icon-intermediate-event-catch-signal',
|
33440 | target: {
|
33441 | type: 'bpmn:IntermediateCatchEvent',
|
33442 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
33443 | }
|
33444 | },
|
33445 | {
|
33446 | label: 'Signal Intermediate Throw Event',
|
33447 | actionName: 'replace-with-signal-intermediate-throw',
|
33448 | className: 'bpmn-icon-intermediate-event-throw-signal',
|
33449 | target: {
|
33450 | type: 'bpmn:IntermediateThrowEvent',
|
33451 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
33452 | }
|
33453 | }
|
33454 | ];
|
33455 |
|
33456 | var END_EVENT = [
|
33457 | {
|
33458 | label: 'Start Event',
|
33459 | actionName: 'replace-with-none-start',
|
33460 | className: 'bpmn-icon-start-event-none',
|
33461 | target: {
|
33462 | type: 'bpmn:StartEvent'
|
33463 | }
|
33464 | },
|
33465 | {
|
33466 | label: 'Intermediate Throw Event',
|
33467 | actionName: 'replace-with-none-intermediate-throw',
|
33468 | className: 'bpmn-icon-intermediate-event-none',
|
33469 | target: {
|
33470 | type: 'bpmn:IntermediateThrowEvent'
|
33471 | }
|
33472 | },
|
33473 | {
|
33474 | label: 'End Event',
|
33475 | actionName: 'replace-with-none-end',
|
33476 | className: 'bpmn-icon-end-event-none',
|
33477 | target: {
|
33478 | type: 'bpmn:EndEvent'
|
33479 | }
|
33480 | },
|
33481 | {
|
33482 | label: 'Message End Event',
|
33483 | actionName: 'replace-with-message-end',
|
33484 | className: 'bpmn-icon-end-event-message',
|
33485 | target: {
|
33486 | type: 'bpmn:EndEvent',
|
33487 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
33488 | }
|
33489 | },
|
33490 | {
|
33491 | label: 'Escalation End Event',
|
33492 | actionName: 'replace-with-escalation-end',
|
33493 | className: 'bpmn-icon-end-event-escalation',
|
33494 | target: {
|
33495 | type: 'bpmn:EndEvent',
|
33496 | eventDefinitionType: 'bpmn:EscalationEventDefinition'
|
33497 | }
|
33498 | },
|
33499 | {
|
33500 | label: 'Error End Event',
|
33501 | actionName: 'replace-with-error-end',
|
33502 | className: 'bpmn-icon-end-event-error',
|
33503 | target: {
|
33504 | type: 'bpmn:EndEvent',
|
33505 | eventDefinitionType: 'bpmn:ErrorEventDefinition'
|
33506 | }
|
33507 | },
|
33508 | {
|
33509 | label: 'Cancel End Event',
|
33510 | actionName: 'replace-with-cancel-end',
|
33511 | className: 'bpmn-icon-end-event-cancel',
|
33512 | target: {
|
33513 | type: 'bpmn:EndEvent',
|
33514 | eventDefinitionType: 'bpmn:CancelEventDefinition'
|
33515 | }
|
33516 | },
|
33517 | {
|
33518 | label: 'Compensation End Event',
|
33519 | actionName: 'replace-with-compensation-end',
|
33520 | className: 'bpmn-icon-end-event-compensation',
|
33521 | target: {
|
33522 | type: 'bpmn:EndEvent',
|
33523 | eventDefinitionType: 'bpmn:CompensateEventDefinition'
|
33524 | }
|
33525 | },
|
33526 | {
|
33527 | label: 'Signal End Event',
|
33528 | actionName: 'replace-with-signal-end',
|
33529 | className: 'bpmn-icon-end-event-signal',
|
33530 | target: {
|
33531 | type: 'bpmn:EndEvent',
|
33532 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
33533 | }
|
33534 | },
|
33535 | {
|
33536 | label: 'Terminate End Event',
|
33537 | actionName: 'replace-with-terminate-end',
|
33538 | className: 'bpmn-icon-end-event-terminate',
|
33539 | target: {
|
33540 | type: 'bpmn:EndEvent',
|
33541 | eventDefinitionType: 'bpmn:TerminateEventDefinition'
|
33542 | }
|
33543 | }
|
33544 | ];
|
33545 |
|
33546 | var GATEWAY = [
|
33547 | {
|
33548 | label: 'Exclusive Gateway',
|
33549 | actionName: 'replace-with-exclusive-gateway',
|
33550 | className: 'bpmn-icon-gateway-xor',
|
33551 | target: {
|
33552 | type: 'bpmn:ExclusiveGateway'
|
33553 | }
|
33554 | },
|
33555 | {
|
33556 | label: 'Parallel Gateway',
|
33557 | actionName: 'replace-with-parallel-gateway',
|
33558 | className: 'bpmn-icon-gateway-parallel',
|
33559 | target: {
|
33560 | type: 'bpmn:ParallelGateway'
|
33561 | }
|
33562 | },
|
33563 | {
|
33564 | label: 'Inclusive Gateway',
|
33565 | actionName: 'replace-with-inclusive-gateway',
|
33566 | className: 'bpmn-icon-gateway-or',
|
33567 | target: {
|
33568 | type: 'bpmn:InclusiveGateway'
|
33569 | }
|
33570 | },
|
33571 | {
|
33572 | label: 'Complex Gateway',
|
33573 | actionName: 'replace-with-complex-gateway',
|
33574 | className: 'bpmn-icon-gateway-complex',
|
33575 | target: {
|
33576 | type: 'bpmn:ComplexGateway'
|
33577 | }
|
33578 | },
|
33579 | {
|
33580 | label: 'Event based Gateway',
|
33581 | actionName: 'replace-with-event-based-gateway',
|
33582 | className: 'bpmn-icon-gateway-eventbased',
|
33583 | target: {
|
33584 | type: 'bpmn:EventBasedGateway',
|
33585 | instantiate: false,
|
33586 | eventGatewayType: 'Exclusive'
|
33587 | }
|
33588 | }
|
33589 |
|
33590 |
|
33591 |
|
33592 |
|
33593 |
|
33594 |
|
33595 |
|
33596 |
|
33597 |
|
33598 |
|
33599 |
|
33600 |
|
33601 |
|
33602 |
|
33603 |
|
33604 |
|
33605 |
|
33606 |
|
33607 |
|
33608 |
|
33609 |
|
33610 |
|
33611 |
|
33612 |
|
33613 | ];
|
33614 |
|
33615 | var SUBPROCESS_EXPANDED = [
|
33616 | {
|
33617 | label: 'Transaction',
|
33618 | actionName: 'replace-with-transaction',
|
33619 | className: 'bpmn-icon-transaction',
|
33620 | target: {
|
33621 | type: 'bpmn:Transaction',
|
33622 | isExpanded: true
|
33623 | }
|
33624 | },
|
33625 | {
|
33626 | label: 'Event Sub Process',
|
33627 | actionName: 'replace-with-event-subprocess',
|
33628 | className: 'bpmn-icon-event-subprocess-expanded',
|
33629 | target: {
|
33630 | type: 'bpmn:SubProcess',
|
33631 | triggeredByEvent: true,
|
33632 | isExpanded: true
|
33633 | }
|
33634 | },
|
33635 | {
|
33636 | label: 'Sub Process (collapsed)',
|
33637 | actionName: 'replace-with-collapsed-subprocess',
|
33638 | className: 'bpmn-icon-subprocess-collapsed',
|
33639 | target: {
|
33640 | type: 'bpmn:SubProcess',
|
33641 | isExpanded: false
|
33642 | }
|
33643 | }
|
33644 | ];
|
33645 |
|
33646 | var TRANSACTION = [
|
33647 | {
|
33648 | label: 'Sub Process',
|
33649 | actionName: 'replace-with-subprocess',
|
33650 | className: 'bpmn-icon-subprocess-expanded',
|
33651 | target: {
|
33652 | type: 'bpmn:SubProcess',
|
33653 | isExpanded: true
|
33654 | }
|
33655 | },
|
33656 | {
|
33657 | label: 'Event Sub Process',
|
33658 | actionName: 'replace-with-event-subprocess',
|
33659 | className: 'bpmn-icon-event-subprocess-expanded',
|
33660 | target: {
|
33661 | type: 'bpmn:SubProcess',
|
33662 | triggeredByEvent: true,
|
33663 | isExpanded: true
|
33664 | }
|
33665 | }
|
33666 | ];
|
33667 |
|
33668 | var EVENT_SUB_PROCESS = [
|
33669 | {
|
33670 | label: 'Sub Process',
|
33671 | actionName: 'replace-with-subprocess',
|
33672 | className: 'bpmn-icon-subprocess-expanded',
|
33673 | target: {
|
33674 | type: 'bpmn:SubProcess',
|
33675 | isExpanded: true
|
33676 | }
|
33677 | },
|
33678 | {
|
33679 | label: 'Transaction',
|
33680 | actionName: 'replace-with-transaction',
|
33681 | className: 'bpmn-icon-transaction',
|
33682 | target: {
|
33683 | type: 'bpmn:Transaction',
|
33684 | isExpanded: true
|
33685 | }
|
33686 | }
|
33687 | ];
|
33688 |
|
33689 | var TASK = [
|
33690 | {
|
33691 | label: 'Task',
|
33692 | actionName: 'replace-with-task',
|
33693 | className: 'bpmn-icon-task',
|
33694 | target: {
|
33695 | type: 'bpmn:Task'
|
33696 | }
|
33697 | },
|
33698 | {
|
33699 | label: 'Send Task',
|
33700 | actionName: 'replace-with-send-task',
|
33701 | className: 'bpmn-icon-send',
|
33702 | target: {
|
33703 | type: 'bpmn:SendTask'
|
33704 | }
|
33705 | },
|
33706 | {
|
33707 | label: 'Receive Task',
|
33708 | actionName: 'replace-with-receive-task',
|
33709 | className: 'bpmn-icon-receive',
|
33710 | target: {
|
33711 | type: 'bpmn:ReceiveTask'
|
33712 | }
|
33713 | },
|
33714 | {
|
33715 | label: 'User Task',
|
33716 | actionName: 'replace-with-user-task',
|
33717 | className: 'bpmn-icon-user',
|
33718 | target: {
|
33719 | type: 'bpmn:UserTask'
|
33720 | }
|
33721 | },
|
33722 | {
|
33723 | label: 'Manual Task',
|
33724 | actionName: 'replace-with-manual-task',
|
33725 | className: 'bpmn-icon-manual',
|
33726 | target: {
|
33727 | type: 'bpmn:ManualTask'
|
33728 | }
|
33729 | },
|
33730 | {
|
33731 | label: 'Business Rule Task',
|
33732 | actionName: 'replace-with-rule-task',
|
33733 | className: 'bpmn-icon-business-rule',
|
33734 | target: {
|
33735 | type: 'bpmn:BusinessRuleTask'
|
33736 | }
|
33737 | },
|
33738 | {
|
33739 | label: 'Service Task',
|
33740 | actionName: 'replace-with-service-task',
|
33741 | className: 'bpmn-icon-service',
|
33742 | target: {
|
33743 | type: 'bpmn:ServiceTask'
|
33744 | }
|
33745 | },
|
33746 | {
|
33747 | label: 'Script Task',
|
33748 | actionName: 'replace-with-script-task',
|
33749 | className: 'bpmn-icon-script',
|
33750 | target: {
|
33751 | type: 'bpmn:ScriptTask'
|
33752 | }
|
33753 | },
|
33754 | {
|
33755 | label: 'Call Activity',
|
33756 | actionName: 'replace-with-call-activity',
|
33757 | className: 'bpmn-icon-call-activity',
|
33758 | target: {
|
33759 | type: 'bpmn:CallActivity'
|
33760 | }
|
33761 | },
|
33762 | {
|
33763 | label: 'Sub Process (collapsed)',
|
33764 | actionName: 'replace-with-collapsed-subprocess',
|
33765 | className: 'bpmn-icon-subprocess-collapsed',
|
33766 | target: {
|
33767 | type: 'bpmn:SubProcess',
|
33768 | isExpanded: false
|
33769 | }
|
33770 | },
|
33771 | {
|
33772 | label: 'Sub Process (expanded)',
|
33773 | actionName: 'replace-with-expanded-subprocess',
|
33774 | className: 'bpmn-icon-subprocess-expanded',
|
33775 | target: {
|
33776 | type: 'bpmn:SubProcess',
|
33777 | isExpanded: true
|
33778 | }
|
33779 | }
|
33780 | ];
|
33781 |
|
33782 | var BOUNDARY_EVENT = [
|
33783 | {
|
33784 | label: 'Message Boundary Event',
|
33785 | actionName: 'replace-with-message-boundary',
|
33786 | className: 'bpmn-icon-intermediate-event-catch-message',
|
33787 | target: {
|
33788 | type: 'bpmn:BoundaryEvent',
|
33789 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
33790 | }
|
33791 | },
|
33792 | {
|
33793 | label: 'Timer Boundary Event',
|
33794 | actionName: 'replace-with-timer-boundary',
|
33795 | className: 'bpmn-icon-intermediate-event-catch-timer',
|
33796 | target: {
|
33797 | type: 'bpmn:BoundaryEvent',
|
33798 | eventDefinitionType: 'bpmn:TimerEventDefinition'
|
33799 | }
|
33800 | },
|
33801 | {
|
33802 | label: 'Escalation Boundary Event',
|
33803 | actionName: 'replace-with-escalation-boundary',
|
33804 | className: 'bpmn-icon-intermediate-event-catch-escalation',
|
33805 | target: {
|
33806 | type: 'bpmn:BoundaryEvent',
|
33807 | eventDefinitionType: 'bpmn:EscalationEventDefinition'
|
33808 | }
|
33809 | },
|
33810 | {
|
33811 | label: 'Conditional Boundary Event',
|
33812 | actionName: 'replace-with-conditional-boundary',
|
33813 | className: 'bpmn-icon-intermediate-event-catch-condition',
|
33814 | target: {
|
33815 | type: 'bpmn:BoundaryEvent',
|
33816 | eventDefinitionType: 'bpmn:ConditionalEventDefinition'
|
33817 | }
|
33818 | },
|
33819 | {
|
33820 | label: 'Error Boundary Event',
|
33821 | actionName: 'replace-with-error-boundary',
|
33822 | className: 'bpmn-icon-intermediate-event-catch-error',
|
33823 | target: {
|
33824 | type: 'bpmn:BoundaryEvent',
|
33825 | eventDefinitionType: 'bpmn:ErrorEventDefinition'
|
33826 | }
|
33827 | },
|
33828 | {
|
33829 | label: 'Cancel Boundary Event',
|
33830 | actionName: 'replace-with-cancel-boundary',
|
33831 | className: 'bpmn-icon-intermediate-event-catch-cancel',
|
33832 | target: {
|
33833 | type: 'bpmn:BoundaryEvent',
|
33834 | eventDefinitionType: 'bpmn:CancelEventDefinition'
|
33835 | }
|
33836 | },
|
33837 | {
|
33838 | label: 'Signal Boundary Event',
|
33839 | actionName: 'replace-with-signal-boundary',
|
33840 | className: 'bpmn-icon-intermediate-event-catch-signal',
|
33841 | target: {
|
33842 | type: 'bpmn:BoundaryEvent',
|
33843 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
33844 | }
|
33845 | },
|
33846 | {
|
33847 | label: 'Compensation Boundary Event',
|
33848 | actionName: 'replace-with-compensation-boundary',
|
33849 | className: 'bpmn-icon-intermediate-event-catch-compensation',
|
33850 | target: {
|
33851 | type: 'bpmn:BoundaryEvent',
|
33852 | eventDefinitionType: 'bpmn:CompensateEventDefinition'
|
33853 | }
|
33854 | },
|
33855 | {
|
33856 | label: 'Message Boundary Event (non-interrupting)',
|
33857 | actionName: 'replace-with-non-interrupting-message-boundary',
|
33858 | className: 'bpmn-icon-intermediate-event-catch-non-interrupting-message',
|
33859 | target: {
|
33860 | type: 'bpmn:BoundaryEvent',
|
33861 | eventDefinitionType: 'bpmn:MessageEventDefinition',
|
33862 | cancelActivity: false
|
33863 | }
|
33864 | },
|
33865 | {
|
33866 | label: 'Timer Boundary Event (non-interrupting)',
|
33867 | actionName: 'replace-with-non-interrupting-timer-boundary',
|
33868 | className: 'bpmn-icon-intermediate-event-catch-non-interrupting-timer',
|
33869 | target: {
|
33870 | type: 'bpmn:BoundaryEvent',
|
33871 | eventDefinitionType: 'bpmn:TimerEventDefinition',
|
33872 | cancelActivity: false
|
33873 | }
|
33874 | },
|
33875 | {
|
33876 | label: 'Escalation Boundary Event (non-interrupting)',
|
33877 | actionName: 'replace-with-non-interrupting-escalation-boundary',
|
33878 | className: 'bpmn-icon-intermediate-event-catch-non-interrupting-escalation',
|
33879 | target: {
|
33880 | type: 'bpmn:BoundaryEvent',
|
33881 | eventDefinitionType: 'bpmn:EscalationEventDefinition',
|
33882 | cancelActivity: false
|
33883 | }
|
33884 | },
|
33885 | {
|
33886 | label: 'Conditional Boundary Event (non-interrupting)',
|
33887 | actionName: 'replace-with-non-interrupting-conditional-boundary',
|
33888 | className: 'bpmn-icon-intermediate-event-catch-non-interrupting-condition',
|
33889 | target: {
|
33890 | type: 'bpmn:BoundaryEvent',
|
33891 | eventDefinitionType: 'bpmn:ConditionalEventDefinition',
|
33892 | cancelActivity: false
|
33893 | }
|
33894 | },
|
33895 | {
|
33896 | label: 'Signal Boundary Event (non-interrupting)',
|
33897 | actionName: 'replace-with-non-interrupting-signal-boundary',
|
33898 | className: 'bpmn-icon-intermediate-event-catch-non-interrupting-signal',
|
33899 | target: {
|
33900 | type: 'bpmn:BoundaryEvent',
|
33901 | eventDefinitionType: 'bpmn:SignalEventDefinition',
|
33902 | cancelActivity: false
|
33903 | }
|
33904 | }
|
33905 | ];
|
33906 |
|
33907 | var EVENT_SUB_PROCESS_START_EVENT = [
|
33908 | {
|
33909 | label: 'Message Start Event',
|
33910 | actionName: 'replace-with-message-start',
|
33911 | className: 'bpmn-icon-start-event-message',
|
33912 | target: {
|
33913 | type: 'bpmn:StartEvent',
|
33914 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
33915 | }
|
33916 | },
|
33917 | {
|
33918 | label: 'Timer Start Event',
|
33919 | actionName: 'replace-with-timer-start',
|
33920 | className: 'bpmn-icon-start-event-timer',
|
33921 | target: {
|
33922 | type: 'bpmn:StartEvent',
|
33923 | eventDefinitionType: 'bpmn:TimerEventDefinition'
|
33924 | }
|
33925 | },
|
33926 | {
|
33927 | label: 'Conditional Start Event',
|
33928 | actionName: 'replace-with-conditional-start',
|
33929 | className: 'bpmn-icon-start-event-condition',
|
33930 | target: {
|
33931 | type: 'bpmn:StartEvent',
|
33932 | eventDefinitionType: 'bpmn:ConditionalEventDefinition'
|
33933 | }
|
33934 | },
|
33935 | {
|
33936 | label: 'Signal Start Event',
|
33937 | actionName: 'replace-with-signal-start',
|
33938 | className: 'bpmn-icon-start-event-signal',
|
33939 | target: {
|
33940 | type: 'bpmn:StartEvent',
|
33941 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
33942 | }
|
33943 | },
|
33944 | {
|
33945 | label: 'Error Start Event',
|
33946 | actionName: 'replace-with-error-start',
|
33947 | className: 'bpmn-icon-start-event-error',
|
33948 | target: {
|
33949 | type: 'bpmn:StartEvent',
|
33950 | eventDefinitionType: 'bpmn:ErrorEventDefinition'
|
33951 | }
|
33952 | },
|
33953 | {
|
33954 | label: 'Escalation Start Event',
|
33955 | actionName: 'replace-with-escalation-start',
|
33956 | className: 'bpmn-icon-start-event-escalation',
|
33957 | target: {
|
33958 | type: 'bpmn:StartEvent',
|
33959 | eventDefinitionType: 'bpmn:EscalationEventDefinition'
|
33960 | }
|
33961 | },
|
33962 | {
|
33963 | label: 'Compensation Start Event',
|
33964 | actionName: 'replace-with-compensation-start',
|
33965 | className: 'bpmn-icon-start-event-compensation',
|
33966 | target: {
|
33967 | type: 'bpmn:StartEvent',
|
33968 | eventDefinitionType: 'bpmn:CompensateEventDefinition'
|
33969 | }
|
33970 | },
|
33971 | {
|
33972 | label: 'Message Start Event (non-interrupting)',
|
33973 | actionName: 'replace-with-non-interrupting-message-start',
|
33974 | className: 'bpmn-icon-start-event-non-interrupting-message',
|
33975 | target: {
|
33976 | type: 'bpmn:StartEvent',
|
33977 | eventDefinitionType: 'bpmn:MessageEventDefinition',
|
33978 | isInterrupting: false
|
33979 | }
|
33980 | },
|
33981 | {
|
33982 | label: 'Timer Start Event (non-interrupting)',
|
33983 | actionName: 'replace-with-non-interrupting-timer-start',
|
33984 | className: 'bpmn-icon-start-event-non-interrupting-timer',
|
33985 | target: {
|
33986 | type: 'bpmn:StartEvent',
|
33987 | eventDefinitionType: 'bpmn:TimerEventDefinition',
|
33988 | isInterrupting: false
|
33989 | }
|
33990 | },
|
33991 | {
|
33992 | label: 'Conditional Start Event (non-interrupting)',
|
33993 | actionName: 'replace-with-non-interrupting-conditional-start',
|
33994 | className: 'bpmn-icon-start-event-non-interrupting-condition',
|
33995 | target: {
|
33996 | type: 'bpmn:StartEvent',
|
33997 | eventDefinitionType: 'bpmn:ConditionalEventDefinition',
|
33998 | isInterrupting: false
|
33999 | }
|
34000 | },
|
34001 | {
|
34002 | label: 'Signal Start Event (non-interrupting)',
|
34003 | actionName: 'replace-with-non-interrupting-signal-start',
|
34004 | className: 'bpmn-icon-start-event-non-interrupting-signal',
|
34005 | target: {
|
34006 | type: 'bpmn:StartEvent',
|
34007 | eventDefinitionType: 'bpmn:SignalEventDefinition',
|
34008 | isInterrupting: false
|
34009 | }
|
34010 | },
|
34011 | {
|
34012 | label: 'Escalation Start Event (non-interrupting)',
|
34013 | actionName: 'replace-with-non-interrupting-escalation-start',
|
34014 | className: 'bpmn-icon-start-event-non-interrupting-escalation',
|
34015 | target: {
|
34016 | type: 'bpmn:StartEvent',
|
34017 | eventDefinitionType: 'bpmn:EscalationEventDefinition',
|
34018 | isInterrupting: false
|
34019 | }
|
34020 | }
|
34021 | ];
|
34022 |
|
34023 | var SEQUENCE_FLOW = [
|
34024 | {
|
34025 | label: 'Sequence Flow',
|
34026 | actionName: 'replace-with-sequence-flow',
|
34027 | className: 'bpmn-icon-connection'
|
34028 | },
|
34029 | {
|
34030 | label: 'Default Flow',
|
34031 | actionName: 'replace-with-default-flow',
|
34032 | className: 'bpmn-icon-default-flow'
|
34033 | },
|
34034 | {
|
34035 | label: 'Conditional Flow',
|
34036 | actionName: 'replace-with-conditional-flow',
|
34037 | className: 'bpmn-icon-conditional-flow'
|
34038 | }
|
34039 | ];
|
34040 |
|
34041 | var PARTICIPANT = [
|
34042 | {
|
34043 | label: 'Expanded Pool',
|
34044 | actionName: 'replace-with-expanded-pool',
|
34045 | className: 'bpmn-icon-participant',
|
34046 | target: {
|
34047 | type: 'bpmn:Participant',
|
34048 | isExpanded: true
|
34049 | }
|
34050 | },
|
34051 | {
|
34052 | label: 'Collapsed Pool',
|
34053 | actionName: 'replace-with-collapsed-pool',
|
34054 |
|
34055 |
|
34056 | className: 'bpmn-icon-lane',
|
34057 | target: {
|
34058 | type: 'bpmn:Participant',
|
34059 | isExpanded: false
|
34060 | }
|
34061 | }
|
34062 | ];
|
34063 |
|
34064 | |
34065 |
|
34066 |
|
34067 | function ReplaceMenuProvider(
|
34068 | popupMenu, modeling, moddle,
|
34069 | bpmnReplace, rules, translate) {
|
34070 |
|
34071 | this._popupMenu = popupMenu;
|
34072 | this._modeling = modeling;
|
34073 | this._moddle = moddle;
|
34074 | this._bpmnReplace = bpmnReplace;
|
34075 | this._rules = rules;
|
34076 | this._translate = translate;
|
34077 |
|
34078 | this.register();
|
34079 | }
|
34080 |
|
34081 | ReplaceMenuProvider.$inject = [
|
34082 | 'popupMenu',
|
34083 | 'modeling',
|
34084 | 'moddle',
|
34085 | 'bpmnReplace',
|
34086 | 'rules',
|
34087 | 'translate'
|
34088 | ];
|
34089 |
|
34090 |
|
34091 | |
34092 |
|
34093 |
|
34094 | ReplaceMenuProvider.prototype.register = function() {
|
34095 | this._popupMenu.registerProvider('bpmn-replace', this);
|
34096 | };
|
34097 |
|
34098 |
|
34099 | |
34100 |
|
34101 |
|
34102 |
|
34103 |
|
34104 |
|
34105 |
|
34106 |
|
34107 | ReplaceMenuProvider.prototype.getEntries = function(element) {
|
34108 |
|
34109 | var businessObject = element.businessObject;
|
34110 |
|
34111 | var rules = this._rules;
|
34112 |
|
34113 | var entries;
|
34114 |
|
34115 | if (!rules.allowed('shape.replace', { element: element })) {
|
34116 | return [];
|
34117 | }
|
34118 |
|
34119 | var differentType = isDifferentType(element);
|
34120 |
|
34121 |
|
34122 | if (is$1(businessObject, 'bpmn:StartEvent') && !isEventSubProcess(businessObject.$parent)) {
|
34123 |
|
34124 | entries = filter(START_EVENT, differentType);
|
34125 |
|
34126 | return this._createEntries(element, entries);
|
34127 | }
|
34128 |
|
34129 |
|
34130 | if (is$1(businessObject, 'bpmn:Participant')) {
|
34131 |
|
34132 | entries = filter(PARTICIPANT, function(entry) {
|
34133 | return isExpanded(businessObject) !== entry.target.isExpanded;
|
34134 | });
|
34135 |
|
34136 | return this._createEntries(element, entries);
|
34137 | }
|
34138 |
|
34139 |
|
34140 | if (is$1(businessObject, 'bpmn:StartEvent') && isEventSubProcess(businessObject.$parent)) {
|
34141 |
|
34142 | entries = filter(EVENT_SUB_PROCESS_START_EVENT, function(entry) {
|
34143 |
|
34144 | var target = entry.target;
|
34145 |
|
34146 | var isInterrupting = target.isInterrupting !== false;
|
34147 |
|
34148 | var isInterruptingEqual = getBusinessObject(element).isInterrupting === isInterrupting;
|
34149 |
|
34150 |
|
34151 | return differentType(entry) || !differentType(entry) && !isInterruptingEqual;
|
34152 |
|
34153 | });
|
34154 |
|
34155 | return this._createEntries(element, entries);
|
34156 | }
|
34157 |
|
34158 |
|
34159 | if (is$1(businessObject, 'bpmn:EndEvent')) {
|
34160 |
|
34161 | entries = filter(END_EVENT, function(entry) {
|
34162 | var target = entry.target;
|
34163 |
|
34164 |
|
34165 | if (target.eventDefinitionType == 'bpmn:CancelEventDefinition' && !is$1(businessObject.$parent, 'bpmn:Transaction')) {
|
34166 | return false;
|
34167 | }
|
34168 |
|
34169 | return differentType(entry);
|
34170 | });
|
34171 |
|
34172 | return this._createEntries(element, entries);
|
34173 | }
|
34174 |
|
34175 |
|
34176 | if (is$1(businessObject, 'bpmn:BoundaryEvent')) {
|
34177 |
|
34178 | entries = filter(BOUNDARY_EVENT, function(entry) {
|
34179 |
|
34180 | var target = entry.target;
|
34181 |
|
34182 | if (target.eventDefinition == 'bpmn:CancelEventDefinition' &&
|
34183 | !is$1(businessObject.attachedToRef, 'bpmn:Transaction')) {
|
34184 | return false;
|
34185 | }
|
34186 | var cancelActivity = target.cancelActivity !== false;
|
34187 |
|
34188 | var isCancelActivityEqual = businessObject.cancelActivity == cancelActivity;
|
34189 |
|
34190 | return differentType(entry) || !differentType(entry) && !isCancelActivityEqual;
|
34191 | });
|
34192 |
|
34193 | return this._createEntries(element, entries);
|
34194 | }
|
34195 |
|
34196 |
|
34197 | if (is$1(businessObject, 'bpmn:IntermediateCatchEvent') ||
|
34198 | is$1(businessObject, 'bpmn:IntermediateThrowEvent')) {
|
34199 |
|
34200 | entries = filter(INTERMEDIATE_EVENT, differentType);
|
34201 |
|
34202 | return this._createEntries(element, entries);
|
34203 | }
|
34204 |
|
34205 |
|
34206 | if (is$1(businessObject, 'bpmn:Gateway')) {
|
34207 |
|
34208 | entries = filter(GATEWAY, differentType);
|
34209 |
|
34210 | return this._createEntries(element, entries);
|
34211 | }
|
34212 |
|
34213 |
|
34214 | if (is$1(businessObject, 'bpmn:Transaction')) {
|
34215 |
|
34216 | entries = filter(TRANSACTION, differentType);
|
34217 |
|
34218 | return this._createEntries(element, entries);
|
34219 | }
|
34220 |
|
34221 |
|
34222 | if (isEventSubProcess(businessObject) && isExpanded(businessObject)) {
|
34223 |
|
34224 | entries = filter(EVENT_SUB_PROCESS, differentType);
|
34225 |
|
34226 | return this._createEntries(element, entries);
|
34227 | }
|
34228 |
|
34229 |
|
34230 | if (is$1(businessObject, 'bpmn:SubProcess') && isExpanded(businessObject)) {
|
34231 |
|
34232 | entries = filter(SUBPROCESS_EXPANDED, differentType);
|
34233 |
|
34234 | return this._createEntries(element, entries);
|
34235 | }
|
34236 |
|
34237 |
|
34238 | if (is$1(businessObject, 'bpmn:AdHocSubProcess') && !isExpanded(businessObject)) {
|
34239 |
|
34240 | entries = filter(TASK, function(entry) {
|
34241 |
|
34242 | var target = entry.target;
|
34243 |
|
34244 | var isTargetSubProcess = target.type === 'bpmn:SubProcess';
|
34245 |
|
34246 | var isTargetExpanded = target.isExpanded === true;
|
34247 |
|
34248 | return isDifferentType(element) && (!isTargetSubProcess || isTargetExpanded);
|
34249 | });
|
34250 |
|
34251 | return this._createEntries(element, entries);
|
34252 | }
|
34253 |
|
34254 |
|
34255 | if (is$1(businessObject, 'bpmn:SequenceFlow')) {
|
34256 | return this._createSequenceFlowEntries(element, SEQUENCE_FLOW);
|
34257 | }
|
34258 |
|
34259 |
|
34260 | if (is$1(businessObject, 'bpmn:FlowNode')) {
|
34261 | entries = filter(TASK, differentType);
|
34262 |
|
34263 |
|
34264 | if (is$1(businessObject, 'bpmn:SubProcess') && !isExpanded(businessObject)) {
|
34265 | entries = filter(entries, function(entry) {
|
34266 | return entry.label !== 'Sub Process (collapsed)';
|
34267 | });
|
34268 | }
|
34269 |
|
34270 | return this._createEntries(element, entries);
|
34271 | }
|
34272 |
|
34273 | return [];
|
34274 | };
|
34275 |
|
34276 |
|
34277 | |
34278 |
|
34279 |
|
34280 |
|
34281 |
|
34282 |
|
34283 |
|
34284 |
|
34285 | ReplaceMenuProvider.prototype.getHeaderEntries = function(element) {
|
34286 |
|
34287 | var headerEntries = [];
|
34288 |
|
34289 | if (is$1(element, 'bpmn:Activity') && !isEventSubProcess(element)) {
|
34290 | headerEntries = headerEntries.concat(this._getLoopEntries(element));
|
34291 | }
|
34292 |
|
34293 | if (is$1(element, 'bpmn:SubProcess') &&
|
34294 | !is$1(element, 'bpmn:Transaction') &&
|
34295 | !isEventSubProcess(element)) {
|
34296 | headerEntries.push(this._getAdHocEntry(element));
|
34297 | }
|
34298 |
|
34299 | return headerEntries;
|
34300 | };
|
34301 |
|
34302 |
|
34303 | |
34304 |
|
34305 |
|
34306 |
|
34307 |
|
34308 |
|
34309 |
|
34310 |
|
34311 |
|
34312 | ReplaceMenuProvider.prototype._createEntries = function(element, replaceOptions) {
|
34313 | var menuEntries = [];
|
34314 |
|
34315 | var self = this;
|
34316 |
|
34317 | forEach(replaceOptions, function(definition) {
|
34318 | var entry = self._createMenuEntry(definition, element);
|
34319 |
|
34320 | menuEntries.push(entry);
|
34321 | });
|
34322 |
|
34323 | return menuEntries;
|
34324 | };
|
34325 |
|
34326 | |
34327 |
|
34328 |
|
34329 |
|
34330 |
|
34331 |
|
34332 |
|
34333 |
|
34334 | ReplaceMenuProvider.prototype._createSequenceFlowEntries = function(element, replaceOptions) {
|
34335 |
|
34336 | var businessObject = getBusinessObject(element);
|
34337 |
|
34338 | var menuEntries = [];
|
34339 |
|
34340 | var modeling = this._modeling,
|
34341 | moddle = this._moddle;
|
34342 |
|
34343 | var self = this;
|
34344 |
|
34345 | forEach(replaceOptions, function(entry) {
|
34346 |
|
34347 | switch (entry.actionName) {
|
34348 | case 'replace-with-default-flow':
|
34349 | if (businessObject.sourceRef.default !== businessObject &&
|
34350 | (is$1(businessObject.sourceRef, 'bpmn:ExclusiveGateway') ||
|
34351 | is$1(businessObject.sourceRef, 'bpmn:InclusiveGateway') ||
|
34352 | is$1(businessObject.sourceRef, 'bpmn:ComplexGateway') ||
|
34353 | is$1(businessObject.sourceRef, 'bpmn:Activity'))) {
|
34354 |
|
34355 | menuEntries.push(self._createMenuEntry(entry, element, function() {
|
34356 | modeling.updateProperties(element.source, { default: businessObject });
|
34357 | }));
|
34358 | }
|
34359 | break;
|
34360 | case 'replace-with-conditional-flow':
|
34361 | if (!businessObject.conditionExpression && is$1(businessObject.sourceRef, 'bpmn:Activity')) {
|
34362 |
|
34363 | menuEntries.push(self._createMenuEntry(entry, element, function() {
|
34364 | var conditionExpression = moddle.create('bpmn:FormalExpression', { body: '' });
|
34365 |
|
34366 | modeling.updateProperties(element, { conditionExpression: conditionExpression });
|
34367 | }));
|
34368 | }
|
34369 | break;
|
34370 | default:
|
34371 |
|
34372 |
|
34373 | if (is$1(businessObject.sourceRef, 'bpmn:Activity') && businessObject.conditionExpression) {
|
34374 | return menuEntries.push(self._createMenuEntry(entry, element, function() {
|
34375 | modeling.updateProperties(element, { conditionExpression: undefined });
|
34376 | }));
|
34377 | }
|
34378 |
|
34379 |
|
34380 | if ((is$1(businessObject.sourceRef, 'bpmn:ExclusiveGateway') ||
|
34381 | is$1(businessObject.sourceRef, 'bpmn:InclusiveGateway') ||
|
34382 | is$1(businessObject.sourceRef, 'bpmn:ComplexGateway') ||
|
34383 | is$1(businessObject.sourceRef, 'bpmn:Activity')) &&
|
34384 | businessObject.sourceRef.default === businessObject) {
|
34385 |
|
34386 | return menuEntries.push(self._createMenuEntry(entry, element, function() {
|
34387 | modeling.updateProperties(element.source, { default: undefined });
|
34388 | }));
|
34389 | }
|
34390 | }
|
34391 | });
|
34392 |
|
34393 | return menuEntries;
|
34394 | };
|
34395 |
|
34396 |
|
34397 | |
34398 |
|
34399 |
|
34400 |
|
34401 |
|
34402 |
|
34403 |
|
34404 |
|
34405 |
|
34406 |
|
34407 | ReplaceMenuProvider.prototype._createMenuEntry = function(definition, element, action) {
|
34408 | var translate = this._translate;
|
34409 | var replaceElement = this._bpmnReplace.replaceElement;
|
34410 |
|
34411 | var replaceAction = function() {
|
34412 | return replaceElement(element, definition.target);
|
34413 | };
|
34414 |
|
34415 | action = action || replaceAction;
|
34416 |
|
34417 | var menuEntry = {
|
34418 | label: translate(definition.label),
|
34419 | className: definition.className,
|
34420 | id: definition.actionName,
|
34421 | action: action
|
34422 | };
|
34423 |
|
34424 | return menuEntry;
|
34425 | };
|
34426 |
|
34427 | |
34428 |
|
34429 |
|
34430 |
|
34431 |
|
34432 |
|
34433 |
|
34434 | ReplaceMenuProvider.prototype._getLoopEntries = function(element) {
|
34435 |
|
34436 | var self = this;
|
34437 | var translate = this._translate;
|
34438 |
|
34439 | function toggleLoopEntry(event, entry) {
|
34440 | var loopCharacteristics;
|
34441 |
|
34442 | if (entry.active) {
|
34443 | loopCharacteristics = undefined;
|
34444 | } else {
|
34445 | loopCharacteristics = self._moddle.create(entry.options.loopCharacteristics);
|
34446 |
|
34447 | if (entry.options.isSequential) {
|
34448 | loopCharacteristics.isSequential = entry.options.isSequential;
|
34449 | }
|
34450 | }
|
34451 | self._modeling.updateProperties(element, { loopCharacteristics: loopCharacteristics });
|
34452 | }
|
34453 |
|
34454 | var businessObject = getBusinessObject(element),
|
34455 | loopCharacteristics = businessObject.loopCharacteristics;
|
34456 |
|
34457 | var isSequential,
|
34458 | isLoop,
|
34459 | isParallel;
|
34460 |
|
34461 | if (loopCharacteristics) {
|
34462 | isSequential = loopCharacteristics.isSequential;
|
34463 | isLoop = loopCharacteristics.isSequential === undefined;
|
34464 | isParallel = loopCharacteristics.isSequential !== undefined && !loopCharacteristics.isSequential;
|
34465 | }
|
34466 |
|
34467 |
|
34468 | var loopEntries = [
|
34469 | {
|
34470 | id: 'toggle-parallel-mi',
|
34471 | className: 'bpmn-icon-parallel-mi-marker',
|
34472 | title: translate('Parallel Multi Instance'),
|
34473 | active: isParallel,
|
34474 | action: toggleLoopEntry,
|
34475 | options: {
|
34476 | loopCharacteristics: 'bpmn:MultiInstanceLoopCharacteristics',
|
34477 | isSequential: false
|
34478 | }
|
34479 | },
|
34480 | {
|
34481 | id: 'toggle-sequential-mi',
|
34482 | className: 'bpmn-icon-sequential-mi-marker',
|
34483 | title: translate('Sequential Multi Instance'),
|
34484 | active: isSequential,
|
34485 | action: toggleLoopEntry,
|
34486 | options: {
|
34487 | loopCharacteristics: 'bpmn:MultiInstanceLoopCharacteristics',
|
34488 | isSequential: true
|
34489 | }
|
34490 | },
|
34491 | {
|
34492 | id: 'toggle-loop',
|
34493 | className: 'bpmn-icon-loop-marker',
|
34494 | title: translate('Loop'),
|
34495 | active: isLoop,
|
34496 | action: toggleLoopEntry,
|
34497 | options: {
|
34498 | loopCharacteristics: 'bpmn:StandardLoopCharacteristics'
|
34499 | }
|
34500 | }
|
34501 | ];
|
34502 | return loopEntries;
|
34503 | };
|
34504 |
|
34505 |
|
34506 | |
34507 |
|
34508 |
|
34509 |
|
34510 |
|
34511 |
|
34512 |
|
34513 | ReplaceMenuProvider.prototype._getAdHocEntry = function(element) {
|
34514 | var translate = this._translate;
|
34515 | var businessObject = getBusinessObject(element);
|
34516 |
|
34517 | var isAdHoc = is$1(businessObject, 'bpmn:AdHocSubProcess');
|
34518 |
|
34519 | var replaceElement = this._bpmnReplace.replaceElement;
|
34520 |
|
34521 | var adHocEntry = {
|
34522 | id: 'toggle-adhoc',
|
34523 | className: 'bpmn-icon-ad-hoc-marker',
|
34524 | title: translate('Ad-hoc'),
|
34525 | active: isAdHoc,
|
34526 | action: function(event, entry) {
|
34527 | if (isAdHoc) {
|
34528 | return replaceElement(element, { type: 'bpmn:SubProcess' }, {
|
34529 | autoResize: false,
|
34530 | layoutConnection: false
|
34531 | });
|
34532 | } else {
|
34533 | return replaceElement(element, { type: 'bpmn:AdHocSubProcess' }, {
|
34534 | autoResize: false,
|
34535 | layoutConnection: false
|
34536 | });
|
34537 | }
|
34538 | }
|
34539 | };
|
34540 |
|
34541 | return adHocEntry;
|
34542 | };
|
34543 |
|
34544 | var PopupMenuModule$1 = {
|
34545 | __depends__: [
|
34546 | PopupMenuModule,
|
34547 | ReplaceModule$1
|
34548 | ],
|
34549 | __init__: [ 'replaceMenuProvider' ],
|
34550 | replaceMenuProvider: [ 'type', ReplaceMenuProvider ]
|
34551 | };
|
34552 |
|
34553 | var max$2 = Math.max,
|
34554 | min$1 = Math.min;
|
34555 |
|
34556 | var DEFAULT_CHILD_BOX_PADDING = 20;
|
34557 |
|
34558 |
|
34559 | |
34560 |
|
34561 |
|
34562 |
|
34563 |
|
34564 |
|
34565 |
|
34566 |
|
34567 | function substractTRBL(trblA, trblB) {
|
34568 | return {
|
34569 | top: trblA.top - trblB.top,
|
34570 | right: trblA.right - trblB.right,
|
34571 | bottom: trblA.bottom - trblB.bottom,
|
34572 | left: trblA.left - trblB.left
|
34573 | };
|
34574 | }
|
34575 |
|
34576 | |
34577 |
|
34578 |
|
34579 |
|
34580 |
|
34581 |
|
34582 |
|
34583 |
|
34584 |
|
34585 | function resizeBounds(bounds, direction, delta) {
|
34586 | var dx = delta.x,
|
34587 | dy = delta.y;
|
34588 |
|
34589 | var newBounds = {
|
34590 | x: bounds.x,
|
34591 | y: bounds.y,
|
34592 | width: bounds.width,
|
34593 | height: bounds.height
|
34594 | };
|
34595 |
|
34596 | if (direction.indexOf('n') !== -1) {
|
34597 | newBounds.y = bounds.y + dy;
|
34598 | newBounds.height = bounds.height - dy;
|
34599 | } else if (direction.indexOf('s') !== -1) {
|
34600 | newBounds.height = bounds.height + dy;
|
34601 | }
|
34602 |
|
34603 | if (direction.indexOf('e') !== -1) {
|
34604 | newBounds.width = bounds.width + dx;
|
34605 | } else if (direction.indexOf('w') !== -1) {
|
34606 | newBounds.x = bounds.x + dx;
|
34607 | newBounds.width = bounds.width - dx;
|
34608 | }
|
34609 |
|
34610 | return newBounds;
|
34611 | }
|
34612 |
|
34613 |
|
34614 | |
34615 |
|
34616 |
|
34617 |
|
34618 |
|
34619 |
|
34620 |
|
34621 |
|
34622 |
|
34623 | function resizeTRBL(bounds, resize) {
|
34624 | return {
|
34625 | x: bounds.x + (resize.left || 0),
|
34626 | y: bounds.y + (resize.top || 0),
|
34627 | width: bounds.width - (resize.left || 0) + (resize.right || 0),
|
34628 | height: bounds.height - (resize.top || 0) + (resize.bottom || 0)
|
34629 | };
|
34630 | }
|
34631 |
|
34632 |
|
34633 | function applyConstraints(attr, trbl, resizeConstraints) {
|
34634 |
|
34635 | var value = trbl[attr],
|
34636 | minValue = resizeConstraints.min && resizeConstraints.min[attr],
|
34637 | maxValue = resizeConstraints.max && resizeConstraints.max[attr];
|
34638 |
|
34639 | if (isNumber(minValue)) {
|
34640 | value = (/top|left/.test(attr) ? min$1 : max$2)(value, minValue);
|
34641 | }
|
34642 |
|
34643 | if (isNumber(maxValue)) {
|
34644 | value = (/top|left/.test(attr) ? max$2 : min$1)(value, maxValue);
|
34645 | }
|
34646 |
|
34647 | return value;
|
34648 | }
|
34649 |
|
34650 | function ensureConstraints$1(currentBounds, resizeConstraints) {
|
34651 |
|
34652 | if (!resizeConstraints) {
|
34653 | return currentBounds;
|
34654 | }
|
34655 |
|
34656 | var currentTrbl = asTRBL(currentBounds);
|
34657 |
|
34658 | return asBounds({
|
34659 | top: applyConstraints('top', currentTrbl, resizeConstraints),
|
34660 | right: applyConstraints('right', currentTrbl, resizeConstraints),
|
34661 | bottom: applyConstraints('bottom', currentTrbl, resizeConstraints),
|
34662 | left: applyConstraints('left', currentTrbl, resizeConstraints)
|
34663 | });
|
34664 | }
|
34665 |
|
34666 |
|
34667 | function getMinResizeBounds(direction, currentBounds, minDimensions, childrenBounds) {
|
34668 |
|
34669 | var currentBox = asTRBL(currentBounds);
|
34670 |
|
34671 | var minBox = {
|
34672 | top: /n/.test(direction) ? currentBox.bottom - minDimensions.height : currentBox.top,
|
34673 | left: /w/.test(direction) ? currentBox.right - minDimensions.width : currentBox.left,
|
34674 | bottom: /s/.test(direction) ? currentBox.top + minDimensions.height : currentBox.bottom,
|
34675 | right: /e/.test(direction) ? currentBox.left + minDimensions.width : currentBox.right
|
34676 | };
|
34677 |
|
34678 | var childrenBox = childrenBounds ? asTRBL(childrenBounds) : minBox;
|
34679 |
|
34680 | var combinedBox = {
|
34681 | top: min$1(minBox.top, childrenBox.top),
|
34682 | left: min$1(minBox.left, childrenBox.left),
|
34683 | bottom: max$2(minBox.bottom, childrenBox.bottom),
|
34684 | right: max$2(minBox.right, childrenBox.right)
|
34685 | };
|
34686 |
|
34687 | return asBounds(combinedBox);
|
34688 | }
|
34689 |
|
34690 | function asPadding(mayBePadding, defaultValue) {
|
34691 | if (typeof mayBePadding !== 'undefined') {
|
34692 | return mayBePadding;
|
34693 | } else {
|
34694 | return DEFAULT_CHILD_BOX_PADDING;
|
34695 | }
|
34696 | }
|
34697 |
|
34698 | function addPadding(bbox, padding) {
|
34699 | var left, right, top, bottom;
|
34700 |
|
34701 | if (typeof padding === 'object') {
|
34702 | left = asPadding(padding.left);
|
34703 | right = asPadding(padding.right);
|
34704 | top = asPadding(padding.top);
|
34705 | bottom = asPadding(padding.bottom);
|
34706 | } else {
|
34707 | left = right = top = bottom = asPadding(padding);
|
34708 | }
|
34709 |
|
34710 | return {
|
34711 | x: bbox.x - left,
|
34712 | y: bbox.y - top,
|
34713 | width: bbox.width + left + right,
|
34714 | height: bbox.height + top + bottom
|
34715 | };
|
34716 | }
|
34717 |
|
34718 |
|
34719 | |
34720 |
|
34721 |
|
34722 |
|
34723 |
|
34724 |
|
34725 |
|
34726 |
|
34727 |
|
34728 | function isBBoxChild(element) {
|
34729 |
|
34730 |
|
34731 | if (element.waypoints) {
|
34732 | return false;
|
34733 | }
|
34734 |
|
34735 |
|
34736 | if (element.type === 'label') {
|
34737 | return false;
|
34738 | }
|
34739 |
|
34740 | return true;
|
34741 | }
|
34742 |
|
34743 | |
34744 |
|
34745 |
|
34746 |
|
34747 |
|
34748 |
|
34749 |
|
34750 |
|
34751 |
|
34752 | function computeChildrenBBox(shapeOrChildren, padding) {
|
34753 |
|
34754 | var elements;
|
34755 |
|
34756 |
|
34757 | if (shapeOrChildren.length === undefined) {
|
34758 |
|
34759 |
|
34760 |
|
34761 | elements = filter(shapeOrChildren.children, isBBoxChild);
|
34762 |
|
34763 | } else {
|
34764 | elements = shapeOrChildren;
|
34765 | }
|
34766 |
|
34767 | if (elements.length) {
|
34768 | return addPadding(getBBox(elements), padding);
|
34769 | }
|
34770 | }
|
34771 |
|
34772 | var abs$3 = Math.abs;
|
34773 |
|
34774 |
|
34775 | function getTRBLResize(oldBounds, newBounds) {
|
34776 | return substractTRBL(asTRBL(newBounds), asTRBL(oldBounds));
|
34777 | }
|
34778 |
|
34779 |
|
34780 | var LANE_PARENTS = [
|
34781 | 'bpmn:Participant',
|
34782 | 'bpmn:Process',
|
34783 | 'bpmn:SubProcess'
|
34784 | ];
|
34785 |
|
34786 | var LANE_INDENTATION = 30;
|
34787 |
|
34788 |
|
34789 | |
34790 |
|
34791 |
|
34792 |
|
34793 |
|
34794 |
|
34795 |
|
34796 |
|
34797 | function collectLanes(shape, collectedShapes) {
|
34798 |
|
34799 | collectedShapes = collectedShapes || [];
|
34800 |
|
34801 | shape.children.filter(function(s) {
|
34802 | if (is$1(s, 'bpmn:Lane')) {
|
34803 | collectLanes(s, collectedShapes);
|
34804 |
|
34805 | collectedShapes.push(s);
|
34806 | }
|
34807 | });
|
34808 |
|
34809 | return collectedShapes;
|
34810 | }
|
34811 |
|
34812 |
|
34813 | |
34814 |
|
34815 |
|
34816 |
|
34817 |
|
34818 |
|
34819 |
|
34820 | function getChildLanes(shape) {
|
34821 | return shape.children.filter(function(c) {
|
34822 | return is$1(c, 'bpmn:Lane');
|
34823 | });
|
34824 | }
|
34825 |
|
34826 |
|
34827 | |
34828 |
|
34829 |
|
34830 |
|
34831 |
|
34832 |
|
34833 |
|
34834 | function getLanesRoot(shape) {
|
34835 | return getParent$1(shape, LANE_PARENTS) || shape;
|
34836 | }
|
34837 |
|
34838 |
|
34839 | |
34840 |
|
34841 |
|
34842 |
|
34843 |
|
34844 |
|
34845 |
|
34846 |
|
34847 |
|
34848 |
|
34849 | function computeLanesResize(shape, newBounds) {
|
34850 |
|
34851 | var rootElement = getLanesRoot(shape);
|
34852 |
|
34853 | var initialShapes = is$1(rootElement, 'bpmn:Process') ? [] : [ rootElement ];
|
34854 |
|
34855 | var allLanes = collectLanes(rootElement, initialShapes),
|
34856 | shapeTrbl = asTRBL(shape),
|
34857 | shapeNewTrbl = asTRBL(newBounds),
|
34858 | trblResize = getTRBLResize(shape, newBounds),
|
34859 | resizeNeeded = [];
|
34860 |
|
34861 | allLanes.forEach(function(other) {
|
34862 |
|
34863 | if (other === shape) {
|
34864 | return;
|
34865 | }
|
34866 |
|
34867 | var topResize = 0,
|
34868 | rightResize = trblResize.right,
|
34869 | bottomResize = 0,
|
34870 | leftResize = trblResize.left;
|
34871 |
|
34872 | var otherTrbl = asTRBL(other);
|
34873 |
|
34874 | if (trblResize.top) {
|
34875 | if (abs$3(otherTrbl.bottom - shapeTrbl.top) < 10) {
|
34876 | bottomResize = shapeNewTrbl.top - otherTrbl.bottom;
|
34877 | }
|
34878 |
|
34879 | if (abs$3(otherTrbl.top - shapeTrbl.top) < 5) {
|
34880 | topResize = shapeNewTrbl.top - otherTrbl.top;
|
34881 | }
|
34882 | }
|
34883 |
|
34884 | if (trblResize.bottom) {
|
34885 | if (abs$3(otherTrbl.top - shapeTrbl.bottom) < 10) {
|
34886 | topResize = shapeNewTrbl.bottom - otherTrbl.top;
|
34887 | }
|
34888 |
|
34889 | if (abs$3(otherTrbl.bottom - shapeTrbl.bottom) < 5) {
|
34890 | bottomResize = shapeNewTrbl.bottom - otherTrbl.bottom;
|
34891 | }
|
34892 | }
|
34893 |
|
34894 | if (topResize || rightResize || bottomResize || leftResize) {
|
34895 |
|
34896 | resizeNeeded.push({
|
34897 | shape: other,
|
34898 | newBounds: resizeTRBL(other, {
|
34899 | top: topResize,
|
34900 | right: rightResize,
|
34901 | bottom: bottomResize,
|
34902 | left: leftResize
|
34903 | })
|
34904 | });
|
34905 | }
|
34906 |
|
34907 | });
|
34908 |
|
34909 | return resizeNeeded;
|
34910 | }
|
34911 |
|
34912 | |
34913 |
|
34914 |
|
34915 | function ContextPadProvider(
|
34916 | config, injector, eventBus,
|
34917 | contextPad, modeling, elementFactory,
|
34918 | connect, create, popupMenu,
|
34919 | canvas, rules, translate) {
|
34920 |
|
34921 | config = config || {};
|
34922 |
|
34923 | contextPad.registerProvider(this);
|
34924 |
|
34925 | this._contextPad = contextPad;
|
34926 |
|
34927 | this._modeling = modeling;
|
34928 |
|
34929 | this._elementFactory = elementFactory;
|
34930 | this._connect = connect;
|
34931 | this._create = create;
|
34932 | this._popupMenu = popupMenu;
|
34933 | this._canvas = canvas;
|
34934 | this._rules = rules;
|
34935 | this._translate = translate;
|
34936 |
|
34937 | if (config.autoPlace !== false) {
|
34938 | this._autoPlace = injector.get('autoPlace', false);
|
34939 | }
|
34940 |
|
34941 | eventBus.on('create.end', 250, function(event) {
|
34942 | var context = event.context,
|
34943 | shape = context.shape;
|
34944 |
|
34945 | if (!hasPrimaryModifier(event) || !contextPad.isOpen(shape)) {
|
34946 | return;
|
34947 | }
|
34948 |
|
34949 | var entries = contextPad.getEntries(shape);
|
34950 |
|
34951 | if (entries.replace) {
|
34952 | entries.replace.action.click(event, shape);
|
34953 | }
|
34954 | });
|
34955 | }
|
34956 |
|
34957 | ContextPadProvider.$inject = [
|
34958 | 'config.contextPad',
|
34959 | 'injector',
|
34960 | 'eventBus',
|
34961 | 'contextPad',
|
34962 | 'modeling',
|
34963 | 'elementFactory',
|
34964 | 'connect',
|
34965 | 'create',
|
34966 | 'popupMenu',
|
34967 | 'canvas',
|
34968 | 'rules',
|
34969 | 'translate'
|
34970 | ];
|
34971 |
|
34972 |
|
34973 | ContextPadProvider.prototype.getContextPadEntries = function(element) {
|
34974 |
|
34975 | var contextPad = this._contextPad,
|
34976 | modeling = this._modeling,
|
34977 |
|
34978 | elementFactory = this._elementFactory,
|
34979 | connect = this._connect,
|
34980 | create = this._create,
|
34981 | popupMenu = this._popupMenu,
|
34982 | canvas = this._canvas,
|
34983 | rules = this._rules,
|
34984 | autoPlace = this._autoPlace,
|
34985 | translate = this._translate;
|
34986 |
|
34987 | var actions = {};
|
34988 |
|
34989 | if (element.type === 'label') {
|
34990 | return actions;
|
34991 | }
|
34992 |
|
34993 | var businessObject = element.businessObject;
|
34994 |
|
34995 | function startConnect(event, element) {
|
34996 | connect.start(event, element);
|
34997 | }
|
34998 |
|
34999 | function removeElement(e) {
|
35000 | modeling.removeElements([ element ]);
|
35001 | }
|
35002 |
|
35003 | function getReplaceMenuPosition(element) {
|
35004 |
|
35005 | var Y_OFFSET = 5;
|
35006 |
|
35007 | var diagramContainer = canvas.getContainer(),
|
35008 | pad = contextPad.getPad(element).html;
|
35009 |
|
35010 | var diagramRect = diagramContainer.getBoundingClientRect(),
|
35011 | padRect = pad.getBoundingClientRect();
|
35012 |
|
35013 | var top = padRect.top - diagramRect.top;
|
35014 | var left = padRect.left - diagramRect.left;
|
35015 |
|
35016 | var pos = {
|
35017 | x: left,
|
35018 | y: top + padRect.height + Y_OFFSET
|
35019 | };
|
35020 |
|
35021 | return pos;
|
35022 | }
|
35023 |
|
35024 |
|
35025 | |
35026 |
|
35027 |
|
35028 |
|
35029 |
|
35030 |
|
35031 |
|
35032 |
|
35033 |
|
35034 |
|
35035 | function appendAction(type, className, title, options) {
|
35036 |
|
35037 | if (typeof title !== 'string') {
|
35038 | options = title;
|
35039 | title = translate('Append {type}', { type: type.replace(/^bpmn:/, '') });
|
35040 | }
|
35041 |
|
35042 | function appendStart(event, element) {
|
35043 |
|
35044 | var shape = elementFactory.createShape(assign({ type: type }, options));
|
35045 | create.start(event, shape, {
|
35046 | source: element
|
35047 | });
|
35048 | }
|
35049 |
|
35050 |
|
35051 | var append = autoPlace ? function(event, element) {
|
35052 | var shape = elementFactory.createShape(assign({ type: type }, options));
|
35053 |
|
35054 | autoPlace.append(element, shape);
|
35055 | } : appendStart;
|
35056 |
|
35057 |
|
35058 | return {
|
35059 | group: 'model',
|
35060 | className: className,
|
35061 | title: title,
|
35062 | action: {
|
35063 | dragstart: appendStart,
|
35064 | click: append
|
35065 | }
|
35066 | };
|
35067 | }
|
35068 |
|
35069 | function splitLaneHandler(count) {
|
35070 |
|
35071 | return function(event, element) {
|
35072 |
|
35073 |
|
35074 | modeling.splitLane(element, count);
|
35075 |
|
35076 |
|
35077 |
|
35078 | contextPad.open(element, true);
|
35079 | };
|
35080 | }
|
35081 |
|
35082 |
|
35083 | if (isAny(businessObject, [ 'bpmn:Lane', 'bpmn:Participant' ]) && isExpanded(businessObject)) {
|
35084 |
|
35085 | var childLanes = getChildLanes(element);
|
35086 |
|
35087 | assign(actions, {
|
35088 | 'lane-insert-above': {
|
35089 | group: 'lane-insert-above',
|
35090 | className: 'bpmn-icon-lane-insert-above',
|
35091 | title: translate('Add Lane above'),
|
35092 | action: {
|
35093 | click: function(event, element) {
|
35094 | modeling.addLane(element, 'top');
|
35095 | }
|
35096 | }
|
35097 | }
|
35098 | });
|
35099 |
|
35100 | if (childLanes.length < 2) {
|
35101 |
|
35102 | if (element.height >= 120) {
|
35103 | assign(actions, {
|
35104 | 'lane-divide-two': {
|
35105 | group: 'lane-divide',
|
35106 | className: 'bpmn-icon-lane-divide-two',
|
35107 | title: translate('Divide into two Lanes'),
|
35108 | action: {
|
35109 | click: splitLaneHandler(2)
|
35110 | }
|
35111 | }
|
35112 | });
|
35113 | }
|
35114 |
|
35115 | if (element.height >= 180) {
|
35116 | assign(actions, {
|
35117 | 'lane-divide-three': {
|
35118 | group: 'lane-divide',
|
35119 | className: 'bpmn-icon-lane-divide-three',
|
35120 | title: translate('Divide into three Lanes'),
|
35121 | action: {
|
35122 | click: splitLaneHandler(3)
|
35123 | }
|
35124 | }
|
35125 | });
|
35126 | }
|
35127 | }
|
35128 |
|
35129 | assign(actions, {
|
35130 | 'lane-insert-below': {
|
35131 | group: 'lane-insert-below',
|
35132 | className: 'bpmn-icon-lane-insert-below',
|
35133 | title: translate('Add Lane below'),
|
35134 | action: {
|
35135 | click: function(event, element) {
|
35136 | modeling.addLane(element, 'bottom');
|
35137 | }
|
35138 | }
|
35139 | }
|
35140 | });
|
35141 |
|
35142 | }
|
35143 |
|
35144 | if (is$1(businessObject, 'bpmn:FlowNode')) {
|
35145 |
|
35146 | if (is$1(businessObject, 'bpmn:EventBasedGateway')) {
|
35147 |
|
35148 | assign(actions, {
|
35149 | 'append.receive-task': appendAction(
|
35150 | 'bpmn:ReceiveTask',
|
35151 | 'bpmn-icon-receive-task'
|
35152 | ),
|
35153 | 'append.message-intermediate-event': appendAction(
|
35154 | 'bpmn:IntermediateCatchEvent',
|
35155 | 'bpmn-icon-intermediate-event-catch-message',
|
35156 | translate('Append MessageIntermediateCatchEvent'),
|
35157 | { eventDefinitionType: 'bpmn:MessageEventDefinition' }
|
35158 | ),
|
35159 | 'append.timer-intermediate-event': appendAction(
|
35160 | 'bpmn:IntermediateCatchEvent',
|
35161 | 'bpmn-icon-intermediate-event-catch-timer',
|
35162 | translate('Append TimerIntermediateCatchEvent'),
|
35163 | { eventDefinitionType: 'bpmn:TimerEventDefinition' }
|
35164 | ),
|
35165 | 'append.condition-intermediate-event': appendAction(
|
35166 | 'bpmn:IntermediateCatchEvent',
|
35167 | 'bpmn-icon-intermediate-event-catch-condition',
|
35168 | translate('Append ConditionIntermediateCatchEvent'),
|
35169 | { eventDefinitionType: 'bpmn:ConditionalEventDefinition' }
|
35170 | ),
|
35171 | 'append.signal-intermediate-event': appendAction(
|
35172 | 'bpmn:IntermediateCatchEvent',
|
35173 | 'bpmn-icon-intermediate-event-catch-signal',
|
35174 | translate('Append SignalIntermediateCatchEvent'),
|
35175 | { eventDefinitionType: 'bpmn:SignalEventDefinition' }
|
35176 | )
|
35177 | });
|
35178 | } else
|
35179 |
|
35180 | if (isEventType(businessObject, 'bpmn:BoundaryEvent', 'bpmn:CompensateEventDefinition')) {
|
35181 |
|
35182 | assign(actions, {
|
35183 | 'append.compensation-activity':
|
35184 | appendAction(
|
35185 | 'bpmn:Task',
|
35186 | 'bpmn-icon-task',
|
35187 | translate('Append compensation activity'),
|
35188 | {
|
35189 | isForCompensation: true
|
35190 | }
|
35191 | )
|
35192 | });
|
35193 | } else
|
35194 |
|
35195 | if (!is$1(businessObject, 'bpmn:EndEvent') &&
|
35196 | !businessObject.isForCompensation &&
|
35197 | !isEventType(businessObject, 'bpmn:IntermediateThrowEvent', 'bpmn:LinkEventDefinition') &&
|
35198 | !isEventSubProcess(businessObject)) {
|
35199 |
|
35200 | assign(actions, {
|
35201 | 'append.end-event': appendAction(
|
35202 | 'bpmn:EndEvent',
|
35203 | 'bpmn-icon-end-event-none',
|
35204 | translate('Append EndEvent')
|
35205 | ),
|
35206 | 'append.gateway': appendAction(
|
35207 | 'bpmn:ExclusiveGateway',
|
35208 | 'bpmn-icon-gateway-none',
|
35209 | translate('Append Gateway')
|
35210 | ),
|
35211 | 'append.append-task': appendAction(
|
35212 | 'bpmn:Task',
|
35213 | 'bpmn-icon-task',
|
35214 | translate('Append Task')
|
35215 | ),
|
35216 | 'append.intermediate-event': appendAction(
|
35217 | 'bpmn:IntermediateThrowEvent',
|
35218 | 'bpmn-icon-intermediate-event-none',
|
35219 | translate('Append Intermediate/Boundary Event')
|
35220 | )
|
35221 | });
|
35222 | }
|
35223 | }
|
35224 |
|
35225 | if (!popupMenu.isEmpty(element, 'bpmn-replace')) {
|
35226 |
|
35227 |
|
35228 | assign(actions, {
|
35229 | 'replace': {
|
35230 | group: 'edit',
|
35231 | className: 'bpmn-icon-screw-wrench',
|
35232 | title: translate('Change type'),
|
35233 | action: {
|
35234 | click: function(event, element) {
|
35235 |
|
35236 | var position = assign(getReplaceMenuPosition(element), {
|
35237 | cursor: { x: event.x, y: event.y }
|
35238 | });
|
35239 |
|
35240 | popupMenu.open(element, 'bpmn-replace', position);
|
35241 | }
|
35242 | }
|
35243 | }
|
35244 | });
|
35245 | }
|
35246 |
|
35247 | if (isAny(businessObject, [
|
35248 | 'bpmn:FlowNode',
|
35249 | 'bpmn:InteractionNode',
|
35250 | 'bpmn:DataObjectReference',
|
35251 | 'bpmn:DataStoreReference'
|
35252 | ])) {
|
35253 |
|
35254 | assign(actions, {
|
35255 | 'append.text-annotation': appendAction('bpmn:TextAnnotation', 'bpmn-icon-text-annotation'),
|
35256 |
|
35257 | 'connect': {
|
35258 | group: 'connect',
|
35259 | className: 'bpmn-icon-connection-multi',
|
35260 | title: translate('Connect using ' +
|
35261 | (businessObject.isForCompensation ? '' : 'Sequence/MessageFlow or ') +
|
35262 | 'Association'),
|
35263 | action: {
|
35264 | click: startConnect,
|
35265 | dragstart: startConnect
|
35266 | }
|
35267 | }
|
35268 | });
|
35269 | }
|
35270 |
|
35271 | if (isAny(businessObject, [ 'bpmn:DataObjectReference', 'bpmn:DataStoreReference' ])) {
|
35272 | assign(actions, {
|
35273 | 'connect': {
|
35274 | group: 'connect',
|
35275 | className: 'bpmn-icon-connection-multi',
|
35276 | title: translate('Connect using DataInputAssociation'),
|
35277 | action: {
|
35278 | click: startConnect,
|
35279 | dragstart: startConnect
|
35280 | }
|
35281 | }
|
35282 | });
|
35283 | }
|
35284 |
|
35285 |
|
35286 | var deleteAllowed = rules.allowed('elements.delete', { elements: [ element ] });
|
35287 |
|
35288 | if (isArray(deleteAllowed)) {
|
35289 |
|
35290 |
|
35291 | deleteAllowed = deleteAllowed[0] === element;
|
35292 | }
|
35293 |
|
35294 | if (deleteAllowed) {
|
35295 | assign(actions, {
|
35296 | 'delete': {
|
35297 | group: 'edit',
|
35298 | className: 'bpmn-icon-trash',
|
35299 | title: translate('Remove'),
|
35300 | action: {
|
35301 | click: removeElement
|
35302 | }
|
35303 | }
|
35304 | });
|
35305 | }
|
35306 |
|
35307 | return actions;
|
35308 | };
|
35309 |
|
35310 |
|
35311 |
|
35312 |
|
35313 | function isEventType(eventBo, type, definition) {
|
35314 |
|
35315 | var isType = eventBo.$instanceOf(type);
|
35316 | var isDefinition = false;
|
35317 |
|
35318 | var definitions = eventBo.eventDefinitions || [];
|
35319 | forEach(definitions, function(def) {
|
35320 | if (def.$type === definition) {
|
35321 | isDefinition = true;
|
35322 | }
|
35323 | });
|
35324 |
|
35325 | return isType && isDefinition;
|
35326 | }
|
35327 |
|
35328 | var ContextPadModule$1 = {
|
35329 | __depends__: [
|
35330 | DirectEditingModule,
|
35331 | ContextPadModule,
|
35332 | SelectionModule,
|
35333 | ConnectModule,
|
35334 | CreateModule,
|
35335 | PopupMenuModule$1
|
35336 | ],
|
35337 | __init__: [ 'contextPadProvider' ],
|
35338 | contextPadProvider: [ 'type', ContextPadProvider ]
|
35339 | };
|
35340 |
|
35341 | var AXIS_DIMENSIONS = {
|
35342 | horizontal: [ 'x', 'width' ],
|
35343 | vertical: [ 'y', 'height' ]
|
35344 | };
|
35345 |
|
35346 | var THRESHOLD$1 = 5;
|
35347 |
|
35348 |
|
35349 | |
35350 |
|
35351 |
|
35352 | function DistributeElements(modeling) {
|
35353 | this._modeling = modeling;
|
35354 |
|
35355 | this._filters = [];
|
35356 |
|
35357 |
|
35358 | this.registerFilter(function(elements, axis, dimension) {
|
35359 | var elementsSize = 0,
|
35360 | numOfShapes = 0,
|
35361 | avgDimension;
|
35362 |
|
35363 | forEach(elements, function(element) {
|
35364 | if (element.waypoints || element.labelTarget) {
|
35365 | return;
|
35366 | }
|
35367 |
|
35368 | elementsSize += element[dimension];
|
35369 |
|
35370 | numOfShapes += 1;
|
35371 | });
|
35372 |
|
35373 | avgDimension = Math.round(elementsSize / numOfShapes);
|
35374 |
|
35375 | return filter(elements, function(element) {
|
35376 | return element[dimension] < (avgDimension + 50);
|
35377 | });
|
35378 | });
|
35379 |
|
35380 | }
|
35381 |
|
35382 | DistributeElements.$inject = [ 'modeling' ];
|
35383 |
|
35384 |
|
35385 | |
35386 |
|
35387 |
|
35388 |
|
35389 |
|
35390 |
|
35391 | DistributeElements.prototype.registerFilter = function(filterFn) {
|
35392 | if (typeof filterFn !== 'function') {
|
35393 | throw new Error('the filter has to be a function');
|
35394 | }
|
35395 |
|
35396 | this._filters.push(filterFn);
|
35397 | };
|
35398 |
|
35399 | |
35400 |
|
35401 |
|
35402 |
|
35403 |
|
35404 |
|
35405 | DistributeElements.prototype.trigger = function(elements, orientation) {
|
35406 | var modeling = this._modeling;
|
35407 |
|
35408 | var groups,
|
35409 | distributableElements;
|
35410 |
|
35411 | if (elements.length < 3) {
|
35412 | return;
|
35413 | }
|
35414 |
|
35415 | this._setOrientation(orientation);
|
35416 |
|
35417 | distributableElements = this._filterElements(elements);
|
35418 |
|
35419 | groups = this._createGroups(distributableElements);
|
35420 |
|
35421 |
|
35422 | if (groups.length <= 2) {
|
35423 | return;
|
35424 | }
|
35425 |
|
35426 | modeling.distributeElements(groups, this._axis, this._dimension);
|
35427 |
|
35428 | return groups;
|
35429 | };
|
35430 |
|
35431 | |
35432 |
|
35433 |
|
35434 |
|
35435 |
|
35436 |
|
35437 |
|
35438 | DistributeElements.prototype._filterElements = function(elements) {
|
35439 | var filters = this._filters,
|
35440 | axis = this._axis,
|
35441 | dimension = this._dimension,
|
35442 | distributableElements = [].concat(elements);
|
35443 |
|
35444 | if (!filters.length) {
|
35445 | return elements;
|
35446 | }
|
35447 |
|
35448 | forEach(filters, function(filterFn) {
|
35449 | distributableElements = filterFn(distributableElements, axis, dimension);
|
35450 | });
|
35451 |
|
35452 | return distributableElements;
|
35453 | };
|
35454 |
|
35455 |
|
35456 | |
35457 |
|
35458 |
|
35459 |
|
35460 |
|
35461 |
|
35462 |
|
35463 |
|
35464 |
|
35465 |
|
35466 |
|
35467 |
|
35468 |
|
35469 |
|
35470 |
|
35471 |
|
35472 |
|
35473 |
|
35474 |
|
35475 | DistributeElements.prototype._createGroups = function(elements) {
|
35476 | var rangeGroups = [],
|
35477 | self = this,
|
35478 | axis = this._axis,
|
35479 | dimension = this._dimension;
|
35480 |
|
35481 | if (!axis) {
|
35482 | throw new Error('must have a defined "axis" and "dimension"');
|
35483 | }
|
35484 |
|
35485 |
|
35486 | var sortedElements = sortBy(elements, axis);
|
35487 |
|
35488 | forEach(sortedElements, function(element, idx) {
|
35489 | var elementRange = self._findRange(element, axis, dimension),
|
35490 | range;
|
35491 |
|
35492 | var previous = rangeGroups[rangeGroups.length - 1];
|
35493 |
|
35494 | if (previous && self._hasIntersection(previous.range, elementRange)) {
|
35495 | rangeGroups[rangeGroups.length - 1].elements.push(element);
|
35496 | } else {
|
35497 | range = { range: elementRange, elements: [ element ] };
|
35498 |
|
35499 | rangeGroups.push(range);
|
35500 | }
|
35501 | });
|
35502 |
|
35503 | return rangeGroups;
|
35504 | };
|
35505 |
|
35506 |
|
35507 | |
35508 |
|
35509 |
|
35510 |
|
35511 |
|
35512 | DistributeElements.prototype._setOrientation = function(direction) {
|
35513 | var orientation = AXIS_DIMENSIONS[direction];
|
35514 |
|
35515 | this._axis = orientation[0];
|
35516 | this._dimension = orientation[1];
|
35517 | };
|
35518 |
|
35519 |
|
35520 | |
35521 |
|
35522 |
|
35523 |
|
35524 |
|
35525 |
|
35526 |
|
35527 |
|
35528 | DistributeElements.prototype._hasIntersection = function(rangeA, rangeB) {
|
35529 | return Math.max(rangeA.min, rangeA.max) >= Math.min(rangeB.min, rangeB.max) &&
|
35530 | Math.min(rangeA.min, rangeA.max) <= Math.max(rangeB.min, rangeB.max);
|
35531 | };
|
35532 |
|
35533 |
|
35534 | |
35535 |
|
35536 |
|
35537 |
|
35538 |
|
35539 |
|
35540 |
|
35541 |
|
35542 |
|
35543 | DistributeElements.prototype._findRange = function(element) {
|
35544 | var axis = element[this._axis],
|
35545 | dimension = element[this._dimension];
|
35546 |
|
35547 | return {
|
35548 | min: axis + THRESHOLD$1,
|
35549 | max: axis + dimension - THRESHOLD$1
|
35550 | };
|
35551 | };
|
35552 |
|
35553 | var DistributeElementsModule = {
|
35554 | __init__: [ 'distributeElements' ],
|
35555 | distributeElements: [ 'type', DistributeElements ]
|
35556 | };
|
35557 |
|
35558 | |
35559 |
|
35560 |
|
35561 |
|
35562 | function BpmnDistributeElements(distributeElements) {
|
35563 |
|
35564 | distributeElements.registerFilter(function(elements) {
|
35565 | return filter(elements, function(element) {
|
35566 | var cannotDistribute = isAny(element, [
|
35567 | 'bpmn:Association',
|
35568 | 'bpmn:BoundaryEvent',
|
35569 | 'bpmn:DataInputAssociation',
|
35570 | 'bpmn:DataOutputAssociation',
|
35571 | 'bpmn:Lane',
|
35572 | 'bpmn:MessageFlow',
|
35573 | 'bpmn:Participant',
|
35574 | 'bpmn:SequenceFlow',
|
35575 | 'bpmn:TextAnnotation'
|
35576 | ]);
|
35577 |
|
35578 | return !(element.labelTarget || cannotDistribute);
|
35579 | });
|
35580 | });
|
35581 | }
|
35582 |
|
35583 | BpmnDistributeElements.$inject = [ 'distributeElements' ];
|
35584 |
|
35585 | var DistributeElementsModule$1 = {
|
35586 | __depends__: [
|
35587 | DistributeElementsModule
|
35588 | ],
|
35589 | __init__: [ 'bpmnDistributeElements' ],
|
35590 | bpmnDistributeElements: [ 'type', BpmnDistributeElements ]
|
35591 | };
|
35592 |
|
35593 | var NOT_REGISTERED_ERROR = 'is not a registered action',
|
35594 | IS_REGISTERED_ERROR = 'is already registered';
|
35595 |
|
35596 |
|
35597 | |
35598 |
|
35599 |
|
35600 |
|
35601 |
|
35602 |
|
35603 |
|
35604 |
|
35605 |
|
35606 |
|
35607 |
|
35608 |
|
35609 |
|
35610 |
|
35611 |
|
35612 |
|
35613 |
|
35614 |
|
35615 |
|
35616 |
|
35617 | function EditorActions(eventBus, injector) {
|
35618 |
|
35619 |
|
35620 | this._actions = {};
|
35621 |
|
35622 | var self = this;
|
35623 |
|
35624 | eventBus.on('diagram.init', function() {
|
35625 |
|
35626 |
|
35627 |
|
35628 | self._registerDefaultActions(injector);
|
35629 |
|
35630 |
|
35631 |
|
35632 | eventBus.fire('editorActions.init', {
|
35633 | editorActions: self
|
35634 | });
|
35635 | });
|
35636 |
|
35637 | }
|
35638 |
|
35639 | EditorActions.$inject = [
|
35640 | 'eventBus',
|
35641 | 'injector'
|
35642 | ];
|
35643 |
|
35644 | |
35645 |
|
35646 |
|
35647 |
|
35648 |
|
35649 | EditorActions.prototype._registerDefaultActions = function(injector) {
|
35650 |
|
35651 |
|
35652 |
|
35653 | var commandStack = injector.get('commandStack', false);
|
35654 | var modeling = injector.get('modeling', false);
|
35655 | var selection = injector.get('selection', false);
|
35656 | var zoomScroll = injector.get('zoomScroll', false);
|
35657 | var copyPaste = injector.get('copyPaste', false);
|
35658 | var canvas = injector.get('canvas', false);
|
35659 | var rules = injector.get('rules', false);
|
35660 | var keyboardMove = injector.get('keyboardMove', false);
|
35661 | var keyboardMoveSelection = injector.get('keyboardMoveSelection', false);
|
35662 |
|
35663 |
|
35664 |
|
35665 | if (commandStack) {
|
35666 | this.register('undo', function() {
|
35667 | commandStack.undo();
|
35668 | });
|
35669 |
|
35670 | this.register('redo', function() {
|
35671 | commandStack.redo();
|
35672 | });
|
35673 | }
|
35674 |
|
35675 | if (copyPaste && selection) {
|
35676 | this.register('copy', function() {
|
35677 | var selectedElements = selection.get();
|
35678 |
|
35679 | copyPaste.copy(selectedElements);
|
35680 | });
|
35681 | }
|
35682 |
|
35683 | if (copyPaste) {
|
35684 | this.register('paste', function() {
|
35685 | copyPaste.paste();
|
35686 | });
|
35687 | }
|
35688 |
|
35689 | if (zoomScroll) {
|
35690 | this.register('stepZoom', function(opts) {
|
35691 | zoomScroll.stepZoom(opts.value);
|
35692 | });
|
35693 | }
|
35694 |
|
35695 | if (canvas) {
|
35696 | this.register('zoom', function(opts) {
|
35697 | canvas.zoom(opts.value);
|
35698 | });
|
35699 | }
|
35700 |
|
35701 | if (modeling && selection && rules) {
|
35702 | this.register('removeSelection', function() {
|
35703 |
|
35704 | var selectedElements = selection.get();
|
35705 |
|
35706 | if (!selectedElements.length) {
|
35707 | return;
|
35708 | }
|
35709 |
|
35710 | var allowed = rules.allowed('elements.delete', { elements: selectedElements }),
|
35711 | removableElements;
|
35712 |
|
35713 | if (allowed === false) {
|
35714 | return;
|
35715 | }
|
35716 | else if (isArray(allowed)) {
|
35717 | removableElements = allowed;
|
35718 | }
|
35719 | else {
|
35720 | removableElements = selectedElements;
|
35721 | }
|
35722 |
|
35723 | if (removableElements.length) {
|
35724 | modeling.removeElements(removableElements.slice());
|
35725 | }
|
35726 | });
|
35727 | }
|
35728 |
|
35729 | if (keyboardMove) {
|
35730 | this.register('moveCanvas', function(opts) {
|
35731 | keyboardMove.moveCanvas(opts);
|
35732 | });
|
35733 | }
|
35734 |
|
35735 | if (keyboardMoveSelection) {
|
35736 | this.register('moveSelection', function(opts) {
|
35737 | keyboardMoveSelection.moveSelection(opts.direction, opts.accelerated);
|
35738 | });
|
35739 | }
|
35740 |
|
35741 | };
|
35742 |
|
35743 |
|
35744 | |
35745 |
|
35746 |
|
35747 |
|
35748 |
|
35749 |
|
35750 |
|
35751 |
|
35752 | EditorActions.prototype.trigger = function(action, opts) {
|
35753 | if (!this._actions[action]) {
|
35754 | throw error$2(action, NOT_REGISTERED_ERROR);
|
35755 | }
|
35756 |
|
35757 | return this._actions[action](opts);
|
35758 | };
|
35759 |
|
35760 |
|
35761 | |
35762 |
|
35763 |
|
35764 |
|
35765 |
|
35766 |
|
35767 |
|
35768 |
|
35769 |
|
35770 |
|
35771 |
|
35772 |
|
35773 |
|
35774 |
|
35775 |
|
35776 |
|
35777 |
|
35778 |
|
35779 |
|
35780 |
|
35781 |
|
35782 |
|
35783 | EditorActions.prototype.register = function(actions, listener) {
|
35784 | var self = this;
|
35785 |
|
35786 | if (typeof actions === 'string') {
|
35787 | return this._registerAction(actions, listener);
|
35788 | }
|
35789 |
|
35790 | forEach(actions, function(listener, action) {
|
35791 | self._registerAction(action, listener);
|
35792 | });
|
35793 | };
|
35794 |
|
35795 | |
35796 |
|
35797 |
|
35798 |
|
35799 |
|
35800 |
|
35801 | EditorActions.prototype._registerAction = function(action, listener) {
|
35802 | if (this.isRegistered(action)) {
|
35803 | throw error$2(action, IS_REGISTERED_ERROR);
|
35804 | }
|
35805 |
|
35806 | this._actions[action] = listener;
|
35807 | };
|
35808 |
|
35809 | |
35810 |
|
35811 |
|
35812 |
|
35813 |
|
35814 | EditorActions.prototype.unregister = function(action) {
|
35815 | if (!this.isRegistered(action)) {
|
35816 | throw error$2(action, NOT_REGISTERED_ERROR);
|
35817 | }
|
35818 |
|
35819 | this._actions[action] = undefined;
|
35820 | };
|
35821 |
|
35822 | |
35823 |
|
35824 |
|
35825 |
|
35826 |
|
35827 | EditorActions.prototype.getActions = function() {
|
35828 | return Object.keys(this._actions);
|
35829 | };
|
35830 |
|
35831 | |
35832 |
|
35833 |
|
35834 |
|
35835 |
|
35836 |
|
35837 |
|
35838 | EditorActions.prototype.isRegistered = function(action) {
|
35839 | return !!this._actions[action];
|
35840 | };
|
35841 |
|
35842 |
|
35843 | function error$2(action, message) {
|
35844 | return new Error(action + ' ' + message);
|
35845 | }
|
35846 |
|
35847 | var EditorActionsModule = {
|
35848 | __init__: [ 'editorActions' ],
|
35849 | editorActions: [ 'type', EditorActions ]
|
35850 | };
|
35851 |
|
35852 | |
35853 |
|
35854 |
|
35855 |
|
35856 |
|
35857 | function BpmnEditorActions(injector) {
|
35858 | injector.invoke(EditorActions, this);
|
35859 | }
|
35860 |
|
35861 | inherits_browser(BpmnEditorActions, EditorActions);
|
35862 |
|
35863 | BpmnEditorActions.$inject = [
|
35864 | 'injector'
|
35865 | ];
|
35866 |
|
35867 | |
35868 |
|
35869 |
|
35870 |
|
35871 |
|
35872 | BpmnEditorActions.prototype._registerDefaultActions = function(injector) {
|
35873 |
|
35874 |
|
35875 |
|
35876 | EditorActions.prototype._registerDefaultActions.call(this, injector);
|
35877 |
|
35878 |
|
35879 |
|
35880 | var canvas = injector.get('canvas', false);
|
35881 | var elementRegistry = injector.get('elementRegistry', false);
|
35882 | var selection = injector.get('selection', false);
|
35883 | var spaceTool = injector.get('spaceTool', false);
|
35884 | var lassoTool = injector.get('lassoTool', false);
|
35885 | var handTool = injector.get('handTool', false);
|
35886 | var globalConnect = injector.get('globalConnect', false);
|
35887 | var distributeElements = injector.get('distributeElements', false);
|
35888 | var alignElements = injector.get('alignElements', false);
|
35889 | var directEditing = injector.get('directEditing', false);
|
35890 | var searchPad = injector.get('searchPad', false);
|
35891 | var modeling = injector.get('modeling', false);
|
35892 |
|
35893 |
|
35894 |
|
35895 | if (canvas && elementRegistry && selection) {
|
35896 | this._registerAction('selectElements', function() {
|
35897 |
|
35898 |
|
35899 |
|
35900 | var rootElement = canvas.getRootElement();
|
35901 |
|
35902 | var elements = elementRegistry.filter(function(element) {
|
35903 | return element !== rootElement;
|
35904 | });
|
35905 |
|
35906 | selection.select(elements);
|
35907 |
|
35908 | return elements;
|
35909 | });
|
35910 | }
|
35911 |
|
35912 | if (spaceTool) {
|
35913 | this._registerAction('spaceTool', function() {
|
35914 | spaceTool.toggle();
|
35915 | });
|
35916 | }
|
35917 |
|
35918 | if (lassoTool) {
|
35919 | this._registerAction('lassoTool', function() {
|
35920 | lassoTool.toggle();
|
35921 | });
|
35922 | }
|
35923 |
|
35924 | if (handTool) {
|
35925 | this._registerAction('handTool', function() {
|
35926 | handTool.toggle();
|
35927 | });
|
35928 | }
|
35929 |
|
35930 | if (globalConnect) {
|
35931 | this._registerAction('globalConnectTool', function() {
|
35932 | globalConnect.toggle();
|
35933 | });
|
35934 | }
|
35935 |
|
35936 | if (selection && distributeElements) {
|
35937 | this._registerAction('distributeElements', function(opts) {
|
35938 | var currentSelection = selection.get(),
|
35939 | type = opts.type;
|
35940 |
|
35941 | if (currentSelection.length) {
|
35942 | distributeElements.trigger(currentSelection, type);
|
35943 | }
|
35944 | });
|
35945 | }
|
35946 |
|
35947 | if (selection && alignElements) {
|
35948 | this._registerAction('alignElements', function(opts) {
|
35949 | var currentSelection = selection.get(),
|
35950 | aligneableElements = [],
|
35951 | type = opts.type;
|
35952 |
|
35953 | if (currentSelection.length) {
|
35954 | aligneableElements = filter(currentSelection, function(element) {
|
35955 | return !is$1(element, 'bpmn:Lane');
|
35956 | });
|
35957 |
|
35958 | alignElements.trigger(aligneableElements, type);
|
35959 | }
|
35960 | });
|
35961 | }
|
35962 |
|
35963 | if (selection && modeling) {
|
35964 | this._registerAction('setColor', function(opts) {
|
35965 | var currentSelection = selection.get();
|
35966 |
|
35967 | if (currentSelection.length) {
|
35968 | modeling.setColor(currentSelection, opts);
|
35969 | }
|
35970 | });
|
35971 | }
|
35972 |
|
35973 | if (selection && directEditing) {
|
35974 | this._registerAction('directEditing', function() {
|
35975 | var currentSelection = selection.get();
|
35976 |
|
35977 | if (currentSelection.length) {
|
35978 | directEditing.activate(currentSelection[0]);
|
35979 | }
|
35980 | });
|
35981 | }
|
35982 |
|
35983 | if (searchPad) {
|
35984 | this._registerAction('find', function() {
|
35985 | searchPad.toggle();
|
35986 | });
|
35987 | }
|
35988 |
|
35989 | if (canvas && modeling) {
|
35990 | this._registerAction('moveToOrigin', function() {
|
35991 | var rootElement = canvas.getRootElement(),
|
35992 | boundingBox,
|
35993 | elements;
|
35994 |
|
35995 | if (is$1(rootElement, 'bpmn:Collaboration')) {
|
35996 | elements = elementRegistry.filter(function(element) {
|
35997 | return is$1(element.parent, 'bpmn:Collaboration');
|
35998 | });
|
35999 | } else {
|
36000 | elements = elementRegistry.filter(function(element) {
|
36001 | return element !== rootElement && !is$1(element.parent, 'bpmn:SubProcess');
|
36002 | });
|
36003 | }
|
36004 |
|
36005 | boundingBox = getBBox(elements);
|
36006 |
|
36007 | modeling.moveElements(
|
36008 | elements,
|
36009 | { x: -boundingBox.x, y: -boundingBox.y },
|
36010 | rootElement
|
36011 | );
|
36012 | });
|
36013 | }
|
36014 |
|
36015 | };
|
36016 |
|
36017 | var EditorActionsModule$1 = {
|
36018 | __depends__: [
|
36019 | EditorActionsModule
|
36020 | ],
|
36021 | editorActions: [ 'type', BpmnEditorActions ]
|
36022 | };
|
36023 |
|
36024 | function BpmnGridSnapping(eventBus) {
|
36025 | eventBus.on([
|
36026 | 'create.init',
|
36027 | 'shape.move.init'
|
36028 | ], function(event) {
|
36029 | var context = event.context,
|
36030 | shape = event.shape;
|
36031 |
|
36032 | if (isAny(shape, [
|
36033 | 'bpmn:Participant',
|
36034 | 'bpmn:SubProcess',
|
36035 | 'bpmn:TextAnnotation'
|
36036 | ])) {
|
36037 | if (!context.gridSnappingContext) {
|
36038 | context.gridSnappingContext = {};
|
36039 | }
|
36040 |
|
36041 | context.gridSnappingContext.snapLocation = 'top-left';
|
36042 | }
|
36043 | });
|
36044 | }
|
36045 |
|
36046 | BpmnGridSnapping.$inject = [ 'eventBus' ];
|
36047 |
|
36048 | var SPACING = 10;
|
36049 |
|
36050 | function quantize(value, quantum, fn) {
|
36051 | if (!fn) {
|
36052 | fn = 'round';
|
36053 | }
|
36054 |
|
36055 | return Math[ fn ](value / quantum) * quantum;
|
36056 | }
|
36057 |
|
36058 | var LOWER_PRIORITY = 1200;
|
36059 | var LOW_PRIORITY$7 = 800;
|
36060 |
|
36061 | |
36062 |
|
36063 |
|
36064 |
|
36065 | function GridSnapping(elementRegistry, eventBus, config) {
|
36066 |
|
36067 | var active = !config || config.active !== false;
|
36068 |
|
36069 | this._eventBus = eventBus;
|
36070 |
|
36071 | var self = this;
|
36072 |
|
36073 | eventBus.on('diagram.init', LOW_PRIORITY$7, function() {
|
36074 | self.setActive(active);
|
36075 | });
|
36076 |
|
36077 | eventBus.on([
|
36078 | 'create.move',
|
36079 | 'create.end',
|
36080 | 'bendpoint.move.move',
|
36081 | 'bendpoint.move.end',
|
36082 | 'connect.move',
|
36083 | 'connect.end',
|
36084 | 'connectionSegment.move.move',
|
36085 | 'connectionSegment.move.end',
|
36086 | 'resize.move',
|
36087 | 'resize.end',
|
36088 | 'shape.move.move',
|
36089 | 'shape.move.end'
|
36090 | ], LOWER_PRIORITY, function(event) {
|
36091 | var originalEvent = event.originalEvent;
|
36092 |
|
36093 | if (!self.active || (originalEvent && isCmd(originalEvent))) {
|
36094 | return;
|
36095 | }
|
36096 |
|
36097 | var context = event.context,
|
36098 | gridSnappingContext = context.gridSnappingContext;
|
36099 |
|
36100 | if (!gridSnappingContext) {
|
36101 | gridSnappingContext = context.gridSnappingContext = {};
|
36102 | }
|
36103 |
|
36104 | [ 'x', 'y' ].forEach(function(axis) {
|
36105 | var options = {};
|
36106 |
|
36107 |
|
36108 | var snapOffset = getSnapOffset(event, axis, elementRegistry);
|
36109 |
|
36110 | if (snapOffset) {
|
36111 | options.offset = snapOffset;
|
36112 | }
|
36113 |
|
36114 |
|
36115 | var snapConstraints = getSnapConstraints(event, axis);
|
36116 |
|
36117 | if (snapConstraints) {
|
36118 | assign(options, snapConstraints);
|
36119 | }
|
36120 |
|
36121 | if (!isSnapped(event, axis)) {
|
36122 | self.snapEvent(event, axis, options);
|
36123 | }
|
36124 | });
|
36125 | });
|
36126 | }
|
36127 |
|
36128 | |
36129 |
|
36130 |
|
36131 |
|
36132 |
|
36133 |
|
36134 |
|
36135 |
|
36136 |
|
36137 | GridSnapping.prototype.snapEvent = function(event, axis, options) {
|
36138 | var snappedValue = this.snapValue(event[ axis ], options);
|
36139 |
|
36140 | setSnapped(event, axis, snappedValue);
|
36141 | };
|
36142 |
|
36143 | |
36144 |
|
36145 |
|
36146 |
|
36147 |
|
36148 | GridSnapping.prototype.getGridSpacing = function() {
|
36149 | return SPACING;
|
36150 | };
|
36151 |
|
36152 | |
36153 |
|
36154 |
|
36155 |
|
36156 |
|
36157 |
|
36158 |
|
36159 |
|
36160 |
|
36161 | GridSnapping.prototype.snapValue = function(value, options) {
|
36162 | var offset = 0;
|
36163 |
|
36164 | if (options && options.offset) {
|
36165 | offset = options.offset;
|
36166 | }
|
36167 |
|
36168 | value += offset;
|
36169 |
|
36170 | value = quantize(value, SPACING);
|
36171 |
|
36172 | var min, max;
|
36173 |
|
36174 | if (options && options.min) {
|
36175 | min = options.min;
|
36176 |
|
36177 | if (isNumber(min)) {
|
36178 | min = quantize(min + offset, SPACING, 'ceil');
|
36179 |
|
36180 | value = Math.max(value, min);
|
36181 | }
|
36182 | }
|
36183 |
|
36184 | if (options && options.max) {
|
36185 | max = options.max;
|
36186 |
|
36187 | if (isNumber(max)) {
|
36188 | max = quantize(max + offset, SPACING, 'floor');
|
36189 |
|
36190 | value = Math.min(value, max);
|
36191 | }
|
36192 | }
|
36193 |
|
36194 | value -= offset;
|
36195 |
|
36196 | return value;
|
36197 | };
|
36198 |
|
36199 | GridSnapping.prototype.isActive = function() {
|
36200 | return this.active;
|
36201 | };
|
36202 |
|
36203 | GridSnapping.prototype.setActive = function(active) {
|
36204 | this.active = active;
|
36205 |
|
36206 | this._eventBus.fire('gridSnapping.toggle', { active: active });
|
36207 | };
|
36208 |
|
36209 | GridSnapping.prototype.toggleActive = function() {
|
36210 | this.setActive(!this.active);
|
36211 | };
|
36212 |
|
36213 | GridSnapping.$inject = [
|
36214 | 'elementRegistry',
|
36215 | 'eventBus',
|
36216 | 'config.gridSnapping'
|
36217 | ];
|
36218 |
|
36219 |
|
36220 |
|
36221 | |
36222 |
|
36223 |
|
36224 |
|
36225 |
|
36226 |
|
36227 |
|
36228 |
|
36229 |
|
36230 |
|
36231 | function getSnapConstraints(event, axis) {
|
36232 | var context = event.context,
|
36233 | createConstraints = context.createConstraints,
|
36234 | resizeConstraints = context.resizeConstraints || {},
|
36235 | gridSnappingContext = context.gridSnappingContext,
|
36236 | snapConstraints = gridSnappingContext.snapConstraints;
|
36237 |
|
36238 |
|
36239 | if (snapConstraints && snapConstraints[ axis ]) {
|
36240 | return snapConstraints[ axis ];
|
36241 | }
|
36242 |
|
36243 | if (!snapConstraints) {
|
36244 | snapConstraints = gridSnappingContext.snapConstraints = {};
|
36245 | }
|
36246 |
|
36247 | if (!snapConstraints[ axis ]) {
|
36248 | snapConstraints[ axis ] = {};
|
36249 | }
|
36250 |
|
36251 | var direction = context.direction;
|
36252 |
|
36253 |
|
36254 | if (createConstraints) {
|
36255 | if (isHorizontal(axis)) {
|
36256 | snapConstraints.x.min = createConstraints.left;
|
36257 | snapConstraints.x.max = createConstraints.right;
|
36258 | } else {
|
36259 | snapConstraints.y.min = createConstraints.top;
|
36260 | snapConstraints.y.max = createConstraints.bottom;
|
36261 | }
|
36262 | }
|
36263 |
|
36264 |
|
36265 | var minResizeConstraints = resizeConstraints.min,
|
36266 | maxResizeConstraints = resizeConstraints.max;
|
36267 |
|
36268 | if (minResizeConstraints) {
|
36269 | if (isHorizontal(axis)) {
|
36270 |
|
36271 | if (isWest(direction)) {
|
36272 | snapConstraints.x.max = minResizeConstraints.left;
|
36273 | } else {
|
36274 | snapConstraints.x.min = minResizeConstraints.right;
|
36275 | }
|
36276 |
|
36277 | } else {
|
36278 |
|
36279 | if (isNorth(direction)) {
|
36280 | snapConstraints.y.max = minResizeConstraints.top;
|
36281 | } else {
|
36282 | snapConstraints.y.min = minResizeConstraints.bottom;
|
36283 | }
|
36284 |
|
36285 | }
|
36286 | }
|
36287 |
|
36288 | if (maxResizeConstraints) {
|
36289 | if (isHorizontal(axis)) {
|
36290 |
|
36291 | if (isWest(direction)) {
|
36292 | snapConstraints.x.min = maxResizeConstraints.left;
|
36293 | } else {
|
36294 | snapConstraints.x.max = maxResizeConstraints.right;
|
36295 | }
|
36296 |
|
36297 | } else {
|
36298 |
|
36299 | if (isNorth(direction)) {
|
36300 | snapConstraints.y.min = maxResizeConstraints.top;
|
36301 | } else {
|
36302 | snapConstraints.y.max = maxResizeConstraints.bottom;
|
36303 | }
|
36304 |
|
36305 | }
|
36306 | }
|
36307 |
|
36308 | return snapConstraints[ axis ];
|
36309 | }
|
36310 |
|
36311 | |
36312 |
|
36313 |
|
36314 |
|
36315 |
|
36316 |
|
36317 |
|
36318 |
|
36319 |
|
36320 |
|
36321 | function getSnapOffset(event, axis, elementRegistry) {
|
36322 | var context = event.context,
|
36323 | shape = event.shape,
|
36324 | gridSnappingContext = context.gridSnappingContext,
|
36325 | snapLocation = gridSnappingContext.snapLocation,
|
36326 | snapOffset = gridSnappingContext.snapOffset;
|
36327 |
|
36328 |
|
36329 | if (snapOffset && isNumber(snapOffset[ axis ])) {
|
36330 | return snapOffset[ axis ];
|
36331 | }
|
36332 |
|
36333 | if (!snapOffset) {
|
36334 | snapOffset = gridSnappingContext.snapOffset = {};
|
36335 | }
|
36336 |
|
36337 | if (!isNumber(snapOffset[ axis ])) {
|
36338 | snapOffset[ axis ] = 0;
|
36339 | }
|
36340 |
|
36341 | if (!shape) {
|
36342 | return snapOffset[ axis ];
|
36343 | }
|
36344 |
|
36345 | if (!elementRegistry.get(shape.id)) {
|
36346 |
|
36347 | if (isHorizontal(axis)) {
|
36348 | snapOffset[ axis ] += shape[ axis ] + shape.width / 2;
|
36349 | } else {
|
36350 | snapOffset[ axis ] += shape[ axis ] + shape.height / 2;
|
36351 | }
|
36352 | }
|
36353 |
|
36354 | if (!snapLocation) {
|
36355 | return snapOffset[ axis ];
|
36356 | }
|
36357 |
|
36358 | if (axis === 'x') {
|
36359 | if (/left/.test(snapLocation)) {
|
36360 | snapOffset[ axis ] -= shape.width / 2;
|
36361 | } else if (/right/.test(snapLocation)) {
|
36362 | snapOffset[ axis ] += shape.width / 2;
|
36363 | }
|
36364 | } else {
|
36365 | if (/top/.test(snapLocation)) {
|
36366 | snapOffset[ axis ] -= shape.height / 2;
|
36367 | } else if (/bottom/.test(snapLocation)) {
|
36368 | snapOffset[ axis ] += shape.height / 2;
|
36369 | }
|
36370 | }
|
36371 |
|
36372 | return snapOffset[ axis ];
|
36373 | }
|
36374 |
|
36375 | function isHorizontal(axis) {
|
36376 | return axis === 'x';
|
36377 | }
|
36378 |
|
36379 | function isNorth(direction) {
|
36380 | return direction.indexOf('n') !== -1;
|
36381 | }
|
36382 |
|
36383 | function isWest(direction) {
|
36384 | return direction.indexOf('w') !== -1;
|
36385 | }
|
36386 |
|
36387 | |
36388 |
|
36389 |
|
36390 | function ResizeBehavior(eventBus, gridSnapping) {
|
36391 | CommandInterceptor.call(this, eventBus);
|
36392 |
|
36393 | this._gridSnapping = gridSnapping;
|
36394 |
|
36395 | var self = this;
|
36396 |
|
36397 | this.preExecute('shape.resize', function(event) {
|
36398 | var context = event.context,
|
36399 | hints = context.hints || {},
|
36400 | autoResize = hints.autoResize;
|
36401 |
|
36402 | if (!autoResize) {
|
36403 | return;
|
36404 | }
|
36405 |
|
36406 | var shape = context.shape,
|
36407 | newBounds = context.newBounds;
|
36408 |
|
36409 | if (isString(autoResize)) {
|
36410 | context.newBounds = self.snapComplex(newBounds, autoResize);
|
36411 | } else {
|
36412 | context.newBounds = self.snapSimple(shape, newBounds);
|
36413 | }
|
36414 | });
|
36415 | }
|
36416 |
|
36417 | ResizeBehavior.$inject = [
|
36418 | 'eventBus',
|
36419 | 'gridSnapping',
|
36420 | 'modeling'
|
36421 | ];
|
36422 |
|
36423 | inherits_browser(ResizeBehavior, CommandInterceptor);
|
36424 |
|
36425 | |
36426 |
|
36427 |
|
36428 |
|
36429 |
|
36430 |
|
36431 |
|
36432 |
|
36433 | ResizeBehavior.prototype.snapSimple = function(shape, newBounds) {
|
36434 | var gridSnapping = this._gridSnapping;
|
36435 |
|
36436 | newBounds.width = gridSnapping.snapValue(newBounds.width, {
|
36437 | min: newBounds.width
|
36438 | });
|
36439 |
|
36440 | newBounds.height = gridSnapping.snapValue(newBounds.height, {
|
36441 | min: newBounds.height
|
36442 | });
|
36443 |
|
36444 | newBounds.x = shape.x + (shape.width / 2) - (newBounds.width / 2);
|
36445 | newBounds.y = shape.y + (shape.height / 2) - (newBounds.height / 2);
|
36446 |
|
36447 | return newBounds;
|
36448 | };
|
36449 |
|
36450 | |
36451 |
|
36452 |
|
36453 |
|
36454 |
|
36455 |
|
36456 |
|
36457 |
|
36458 | ResizeBehavior.prototype.snapComplex = function(newBounds, directions) {
|
36459 | if (/w|e/.test(directions)) {
|
36460 | newBounds = this.snapHorizontally(newBounds, directions);
|
36461 | }
|
36462 |
|
36463 | if (/n|s/.test(directions)) {
|
36464 | newBounds = this.snapVertically(newBounds, directions);
|
36465 | }
|
36466 |
|
36467 | return newBounds;
|
36468 | };
|
36469 |
|
36470 | |
36471 |
|
36472 |
|
36473 |
|
36474 |
|
36475 |
|
36476 |
|
36477 |
|
36478 | ResizeBehavior.prototype.snapHorizontally = function(newBounds, directions) {
|
36479 | var gridSnapping = this._gridSnapping,
|
36480 | west = /w/.test(directions),
|
36481 | east = /e/.test(directions);
|
36482 |
|
36483 | var snappedNewBounds = {};
|
36484 |
|
36485 | snappedNewBounds.width = gridSnapping.snapValue(newBounds.width, {
|
36486 | min: newBounds.width
|
36487 | });
|
36488 |
|
36489 | if (east) {
|
36490 |
|
36491 |
|
36492 | if (west) {
|
36493 | snappedNewBounds.x = gridSnapping.snapValue(newBounds.x, {
|
36494 | max: newBounds.x
|
36495 | });
|
36496 |
|
36497 | snappedNewBounds.width += gridSnapping.snapValue(newBounds.x - snappedNewBounds.x, {
|
36498 | min: newBounds.x - snappedNewBounds.x
|
36499 | });
|
36500 | }
|
36501 |
|
36502 |
|
36503 | else {
|
36504 | newBounds.x = newBounds.x + newBounds.width - snappedNewBounds.width;
|
36505 | }
|
36506 | }
|
36507 |
|
36508 |
|
36509 | assign(newBounds, snappedNewBounds);
|
36510 |
|
36511 | return newBounds;
|
36512 | };
|
36513 |
|
36514 | |
36515 |
|
36516 |
|
36517 |
|
36518 |
|
36519 |
|
36520 |
|
36521 |
|
36522 | ResizeBehavior.prototype.snapVertically = function(newBounds, directions) {
|
36523 | var gridSnapping = this._gridSnapping,
|
36524 | north = /n/.test(directions),
|
36525 | south = /s/.test(directions);
|
36526 |
|
36527 | var snappedNewBounds = {};
|
36528 |
|
36529 | snappedNewBounds.height = gridSnapping.snapValue(newBounds.height, {
|
36530 | min: newBounds.height
|
36531 | });
|
36532 |
|
36533 | if (north) {
|
36534 |
|
36535 |
|
36536 | if (south) {
|
36537 | snappedNewBounds.y = gridSnapping.snapValue(newBounds.y, {
|
36538 | max: newBounds.y
|
36539 | });
|
36540 |
|
36541 | snappedNewBounds.height += gridSnapping.snapValue(newBounds.y - snappedNewBounds.y, {
|
36542 | min: newBounds.y - snappedNewBounds.y
|
36543 | });
|
36544 | }
|
36545 |
|
36546 |
|
36547 | else {
|
36548 | newBounds.y = newBounds.y + newBounds.height - snappedNewBounds.height;
|
36549 | }
|
36550 | }
|
36551 |
|
36552 |
|
36553 | assign(newBounds, snappedNewBounds);
|
36554 |
|
36555 | return newBounds;
|
36556 | };
|
36557 |
|
36558 | var HIGH_PRIORITY$4 = 2000;
|
36559 |
|
36560 | |
36561 |
|
36562 |
|
36563 | function SpaceToolBehavior(eventBus, gridSnapping) {
|
36564 | eventBus.on([
|
36565 | 'spaceTool.move',
|
36566 | 'spaceTool.end'
|
36567 | ], HIGH_PRIORITY$4, function(event) {
|
36568 | var context = event.context;
|
36569 |
|
36570 | if (!context.initialized) {
|
36571 | return;
|
36572 | }
|
36573 |
|
36574 | var axis = context.axis;
|
36575 |
|
36576 | if (axis === 'x') {
|
36577 |
|
36578 |
|
36579 | event.dx = gridSnapping.snapValue(event.dx);
|
36580 | } else {
|
36581 |
|
36582 |
|
36583 | event.dy = gridSnapping.snapValue(event.dy);
|
36584 | }
|
36585 | });
|
36586 | }
|
36587 |
|
36588 | SpaceToolBehavior.$inject = [
|
36589 | 'eventBus',
|
36590 | 'gridSnapping'
|
36591 | ];
|
36592 |
|
36593 | var GridSnappingBehaviorModule = {
|
36594 | __init__: [
|
36595 | 'gridSnappingResizeBehavior',
|
36596 | 'gridSnappingSpaceToolBehavior'
|
36597 | ],
|
36598 | gridSnappingResizeBehavior: [ 'type', ResizeBehavior ],
|
36599 | gridSnappingSpaceToolBehavior: [ 'type', SpaceToolBehavior ]
|
36600 | };
|
36601 |
|
36602 | var GridSnappingModule = {
|
36603 | __depends__: [ GridSnappingBehaviorModule ],
|
36604 | __init__: [ 'gridSnapping' ],
|
36605 | gridSnapping: [ 'type', GridSnapping ]
|
36606 | };
|
36607 |
|
36608 | function AutoPlaceBehavior(eventBus, gridSnapping) {
|
36609 | eventBus.on('autoPlace', function(context) {
|
36610 | var source = context.source,
|
36611 | sourceMid = getMid(source),
|
36612 | shape = context.shape;
|
36613 |
|
36614 | var position = getNewShapePosition(source, shape);
|
36615 |
|
36616 | [ 'x', 'y' ].forEach(function(axis) {
|
36617 | var options = {};
|
36618 |
|
36619 |
|
36620 | if (position[ axis ] === sourceMid[ axis ]) {
|
36621 | return;
|
36622 | }
|
36623 |
|
36624 | if (position[ axis ] > sourceMid[ axis ]) {
|
36625 | options.min = position[ axis ];
|
36626 | } else {
|
36627 | options.max = position[ axis ];
|
36628 | }
|
36629 |
|
36630 | if (is$1(shape, 'bpmn:TextAnnotation')) {
|
36631 |
|
36632 | if (isHorizontal$1(axis)) {
|
36633 | options.offset = -shape.width / 2;
|
36634 | } else {
|
36635 | options.offset = -shape.height / 2;
|
36636 | }
|
36637 |
|
36638 | }
|
36639 |
|
36640 | position[ axis ] = gridSnapping.snapValue(position[ axis ], options);
|
36641 |
|
36642 | });
|
36643 |
|
36644 |
|
36645 | return position;
|
36646 | });
|
36647 | }
|
36648 |
|
36649 | AutoPlaceBehavior.$inject = [
|
36650 | 'eventBus',
|
36651 | 'gridSnapping'
|
36652 | ];
|
36653 |
|
36654 |
|
36655 |
|
36656 | function isHorizontal$1(axis) {
|
36657 | return axis === 'x';
|
36658 | }
|
36659 |
|
36660 | var HIGHER_PRIORITY = 1750;
|
36661 |
|
36662 |
|
36663 | function CreateParticipantBehavior(canvas, eventBus, gridSnapping) {
|
36664 | eventBus.on([
|
36665 | 'create.start',
|
36666 | 'shape.move.start'
|
36667 | ], HIGHER_PRIORITY, function(event) {
|
36668 | var context = event.context,
|
36669 | shape = context.shape,
|
36670 | rootElement = canvas.getRootElement();
|
36671 |
|
36672 | if (!is$1(shape, 'bpmn:Participant') ||
|
36673 | !is$1(rootElement, 'bpmn:Process') ||
|
36674 | !rootElement.children.length) {
|
36675 | return;
|
36676 | }
|
36677 |
|
36678 | var createConstraints = context.createConstraints;
|
36679 |
|
36680 | if (!createConstraints) {
|
36681 | return;
|
36682 | }
|
36683 |
|
36684 | shape.width = gridSnapping.snapValue(shape.width, { min: shape.width });
|
36685 | shape.height = gridSnapping.snapValue(shape.height, { min: shape.height });
|
36686 | });
|
36687 | }
|
36688 |
|
36689 | CreateParticipantBehavior.$inject = [
|
36690 | 'canvas',
|
36691 | 'eventBus',
|
36692 | 'gridSnapping'
|
36693 | ];
|
36694 |
|
36695 | var HIGH_PRIORITY$5 = 3000;
|
36696 |
|
36697 |
|
36698 | |
36699 |
|
36700 |
|
36701 | function LayoutConnectionBehavior(eventBus, gridSnapping, modeling) {
|
36702 | CommandInterceptor.call(this, eventBus);
|
36703 |
|
36704 | this._gridSnapping = gridSnapping;
|
36705 |
|
36706 | var self = this;
|
36707 |
|
36708 | this.postExecuted([
|
36709 | 'connection.create',
|
36710 | 'connection.layout'
|
36711 | ], HIGH_PRIORITY$5, function(event) {
|
36712 | var context = event.context,
|
36713 | connection = context.connection,
|
36714 | hints = context.hints || {},
|
36715 | waypoints = connection.waypoints;
|
36716 |
|
36717 | if (hints.connectionStart || hints.connectionEnd || hints.createElementsBehavior === false) {
|
36718 | return;
|
36719 | }
|
36720 |
|
36721 | if (!hasMiddleSegments(waypoints)) {
|
36722 | return;
|
36723 | }
|
36724 |
|
36725 | modeling.updateWaypoints(connection, self.snapMiddleSegments(waypoints));
|
36726 | });
|
36727 | }
|
36728 |
|
36729 | LayoutConnectionBehavior.$inject = [
|
36730 | 'eventBus',
|
36731 | 'gridSnapping',
|
36732 | 'modeling'
|
36733 | ];
|
36734 |
|
36735 | inherits_browser(LayoutConnectionBehavior, CommandInterceptor);
|
36736 |
|
36737 | |
36738 |
|
36739 |
|
36740 |
|
36741 |
|
36742 |
|
36743 |
|
36744 | LayoutConnectionBehavior.prototype.snapMiddleSegments = function(waypoints) {
|
36745 | var gridSnapping = this._gridSnapping,
|
36746 | snapped;
|
36747 |
|
36748 | waypoints = waypoints.slice();
|
36749 |
|
36750 | for (var i = 1; i < waypoints.length - 2; i++) {
|
36751 |
|
36752 | snapped = snapSegment(gridSnapping, waypoints[i], waypoints[i + 1]);
|
36753 |
|
36754 | waypoints[i] = snapped[0];
|
36755 | waypoints[i + 1] = snapped[1];
|
36756 | }
|
36757 |
|
36758 | return waypoints;
|
36759 | };
|
36760 |
|
36761 |
|
36762 |
|
36763 |
|
36764 | |
36765 |
|
36766 |
|
36767 |
|
36768 |
|
36769 |
|
36770 |
|
36771 | function hasMiddleSegments(waypoints) {
|
36772 | return waypoints.length > 3;
|
36773 | }
|
36774 |
|
36775 | |
36776 |
|
36777 |
|
36778 |
|
36779 |
|
36780 |
|
36781 |
|
36782 | function horizontallyAligned(aligned) {
|
36783 | return aligned === 'h';
|
36784 | }
|
36785 |
|
36786 | |
36787 |
|
36788 |
|
36789 |
|
36790 |
|
36791 |
|
36792 |
|
36793 | function verticallyAligned(aligned) {
|
36794 | return aligned === 'v';
|
36795 | }
|
36796 |
|
36797 | |
36798 |
|
36799 |
|
36800 |
|
36801 |
|
36802 |
|
36803 |
|
36804 | function snapSegment(gridSnapping, segmentStart, segmentEnd) {
|
36805 |
|
36806 | var aligned = pointsAligned(segmentStart, segmentEnd);
|
36807 |
|
36808 | var snapped = {};
|
36809 |
|
36810 | if (horizontallyAligned(aligned)) {
|
36811 |
|
36812 |
|
36813 | snapped.y = gridSnapping.snapValue(segmentStart.y);
|
36814 | }
|
36815 |
|
36816 | if (verticallyAligned(aligned)) {
|
36817 |
|
36818 |
|
36819 | snapped.x = gridSnapping.snapValue(segmentStart.x);
|
36820 | }
|
36821 |
|
36822 | if ('x' in snapped || 'y' in snapped) {
|
36823 | segmentStart = assign({}, segmentStart, snapped);
|
36824 | segmentEnd = assign({}, segmentEnd, snapped);
|
36825 | }
|
36826 |
|
36827 | return [ segmentStart, segmentEnd ];
|
36828 | }
|
36829 |
|
36830 | var GridSnappingBehaviorModule$1 = {
|
36831 | __init__: [
|
36832 | 'gridSnappingAutoPlaceBehavior',
|
36833 | 'gridSnappingCreateParticipantBehavior',
|
36834 | 'gridSnappingLayoutConnectionBehavior',
|
36835 | ],
|
36836 | gridSnappingAutoPlaceBehavior: [ 'type', AutoPlaceBehavior ],
|
36837 | gridSnappingCreateParticipantBehavior: [ 'type', CreateParticipantBehavior ],
|
36838 | gridSnappingLayoutConnectionBehavior: [ 'type', LayoutConnectionBehavior ]
|
36839 | };
|
36840 |
|
36841 | var GridSnappingModule$1 = {
|
36842 | __depends__: [
|
36843 | GridSnappingModule,
|
36844 | GridSnappingBehaviorModule$1
|
36845 | ],
|
36846 | __init__: [ 'bpmnGridSnapping' ],
|
36847 | bpmnGridSnapping: [ 'type', BpmnGridSnapping ]
|
36848 | };
|
36849 |
|
36850 | var LABEL_WIDTH = 30,
|
36851 | LABEL_HEIGHT = 30;
|
36852 |
|
36853 |
|
36854 | |
36855 |
|
36856 |
|
36857 |
|
36858 |
|
36859 |
|
36860 | function BpmnInteractionEvents(eventBus, interactionEvents) {
|
36861 |
|
36862 | this._interactionEvents = interactionEvents;
|
36863 |
|
36864 | var self = this;
|
36865 |
|
36866 | eventBus.on([
|
36867 | 'interactionEvents.createHit',
|
36868 | 'interactionEvents.updateHit'
|
36869 | ], function(context) {
|
36870 | var element = context.element,
|
36871 | gfx = context.gfx;
|
36872 |
|
36873 | if (is$1(element, 'bpmn:Lane')) {
|
36874 | return self.createParticipantHit(element, gfx);
|
36875 | } else
|
36876 |
|
36877 | if (is$1(element, 'bpmn:Participant')) {
|
36878 | if (isExpanded(element)) {
|
36879 | return self.createParticipantHit(element, gfx);
|
36880 | } else {
|
36881 | return self.createDefaultHit(element, gfx);
|
36882 | }
|
36883 | } else
|
36884 |
|
36885 | if (is$1(element, 'bpmn:SubProcess')) {
|
36886 | if (isExpanded(element)) {
|
36887 | return self.createSubProcessHit(element, gfx);
|
36888 | } else {
|
36889 | return self.createDefaultHit(element, gfx);
|
36890 | }
|
36891 | }
|
36892 | });
|
36893 |
|
36894 | }
|
36895 |
|
36896 | BpmnInteractionEvents.$inject = [
|
36897 | 'eventBus',
|
36898 | 'interactionEvents'
|
36899 | ];
|
36900 |
|
36901 |
|
36902 | BpmnInteractionEvents.prototype.createDefaultHit = function(element, gfx) {
|
36903 | this._interactionEvents.removeHits(gfx);
|
36904 |
|
36905 | this._interactionEvents.createDefaultHit(element, gfx);
|
36906 |
|
36907 |
|
36908 | return true;
|
36909 | };
|
36910 |
|
36911 | BpmnInteractionEvents.prototype.createParticipantHit = function(element, gfx) {
|
36912 |
|
36913 |
|
36914 | this._interactionEvents.removeHits(gfx);
|
36915 |
|
36916 |
|
36917 | this._interactionEvents.createBoxHit(gfx, 'click-stroke', {
|
36918 | width: element.width,
|
36919 | height: element.height
|
36920 | });
|
36921 |
|
36922 |
|
36923 | this._interactionEvents.createBoxHit(gfx, 'all', {
|
36924 | width: LABEL_WIDTH,
|
36925 | height: element.height
|
36926 | });
|
36927 |
|
36928 |
|
36929 | return true;
|
36930 | };
|
36931 |
|
36932 | BpmnInteractionEvents.prototype.createSubProcessHit = function(element, gfx) {
|
36933 |
|
36934 |
|
36935 | this._interactionEvents.removeHits(gfx);
|
36936 |
|
36937 |
|
36938 | this._interactionEvents.createBoxHit(gfx, 'click-stroke', {
|
36939 | width: element.width,
|
36940 | height: element.height
|
36941 | });
|
36942 |
|
36943 |
|
36944 | this._interactionEvents.createBoxHit(gfx, 'all', {
|
36945 | width: element.width,
|
36946 | height: LABEL_HEIGHT
|
36947 | });
|
36948 |
|
36949 |
|
36950 | return true;
|
36951 | };
|
36952 |
|
36953 | var InteractionEventsModule$1 = {
|
36954 | __init__: [ 'bpmnInteractionEvents' ],
|
36955 | bpmnInteractionEvents: [ 'type', BpmnInteractionEvents ]
|
36956 | };
|
36957 |
|
36958 | |
36959 |
|
36960 |
|
36961 |
|
36962 |
|
36963 | function BpmnKeyboardBindings(injector) {
|
36964 | injector.invoke(KeyboardBindings, this);
|
36965 | }
|
36966 |
|
36967 | inherits_browser(BpmnKeyboardBindings, KeyboardBindings);
|
36968 |
|
36969 | BpmnKeyboardBindings.$inject = [
|
36970 | 'injector'
|
36971 | ];
|
36972 |
|
36973 |
|
36974 | |
36975 |
|
36976 |
|
36977 |
|
36978 |
|
36979 |
|
36980 | BpmnKeyboardBindings.prototype.registerBindings = function(keyboard, editorActions) {
|
36981 |
|
36982 |
|
36983 | KeyboardBindings.prototype.registerBindings.call(this, keyboard, editorActions);
|
36984 |
|
36985 | |
36986 |
|
36987 |
|
36988 |
|
36989 |
|
36990 |
|
36991 |
|
36992 | function addListener(action, fn) {
|
36993 |
|
36994 | if (editorActions.isRegistered(action)) {
|
36995 | keyboard.addListener(fn);
|
36996 | }
|
36997 | }
|
36998 |
|
36999 |
|
37000 |
|
37001 | addListener('selectElements', function(context) {
|
37002 |
|
37003 | var event = context.keyEvent;
|
37004 |
|
37005 | if (keyboard.isKey(['a', 'A'], event) && keyboard.isCmd(event)) {
|
37006 | editorActions.trigger('selectElements');
|
37007 |
|
37008 | return true;
|
37009 | }
|
37010 | });
|
37011 |
|
37012 |
|
37013 |
|
37014 | addListener('find', function(context) {
|
37015 |
|
37016 | var event = context.keyEvent;
|
37017 |
|
37018 | if (keyboard.isKey(['f', 'F'], event) && keyboard.isCmd(event)) {
|
37019 | editorActions.trigger('find');
|
37020 |
|
37021 | return true;
|
37022 | }
|
37023 | });
|
37024 |
|
37025 |
|
37026 |
|
37027 | addListener('spaceTool', function(context) {
|
37028 |
|
37029 | var event = context.keyEvent;
|
37030 |
|
37031 | if (keyboard.hasModifier(event)) {
|
37032 | return;
|
37033 | }
|
37034 |
|
37035 | if (keyboard.isKey(['s', 'S'], event)) {
|
37036 | editorActions.trigger('spaceTool');
|
37037 |
|
37038 | return true;
|
37039 | }
|
37040 | });
|
37041 |
|
37042 |
|
37043 |
|
37044 | addListener('lassoTool', function(context) {
|
37045 |
|
37046 | var event = context.keyEvent;
|
37047 |
|
37048 | if (keyboard.hasModifier(event)) {
|
37049 | return;
|
37050 | }
|
37051 |
|
37052 | if (keyboard.isKey(['l', 'L'], event)) {
|
37053 | editorActions.trigger('lassoTool');
|
37054 |
|
37055 | return true;
|
37056 | }
|
37057 | });
|
37058 |
|
37059 |
|
37060 |
|
37061 | addListener('handTool', function(context) {
|
37062 |
|
37063 | var event = context.keyEvent;
|
37064 |
|
37065 | if (keyboard.hasModifier(event)) {
|
37066 | return;
|
37067 | }
|
37068 |
|
37069 | if (keyboard.isKey(['h', 'H'], event)) {
|
37070 | editorActions.trigger('handTool');
|
37071 |
|
37072 | return true;
|
37073 | }
|
37074 | });
|
37075 |
|
37076 |
|
37077 |
|
37078 | addListener('globalConnectTool', function(context) {
|
37079 |
|
37080 | var event = context.keyEvent;
|
37081 |
|
37082 | if (keyboard.hasModifier(event)) {
|
37083 | return;
|
37084 | }
|
37085 |
|
37086 | if (keyboard.isKey(['c', 'C'], event)) {
|
37087 | editorActions.trigger('globalConnectTool');
|
37088 |
|
37089 | return true;
|
37090 | }
|
37091 | });
|
37092 |
|
37093 |
|
37094 |
|
37095 | addListener('directEditing', function(context) {
|
37096 |
|
37097 | var event = context.keyEvent;
|
37098 |
|
37099 | if (keyboard.hasModifier(event)) {
|
37100 | return;
|
37101 | }
|
37102 |
|
37103 | if (keyboard.isKey(['e', 'E'], event)) {
|
37104 | editorActions.trigger('directEditing');
|
37105 |
|
37106 | return true;
|
37107 | }
|
37108 | });
|
37109 |
|
37110 | };
|
37111 |
|
37112 | var KeyboardModule$1 = {
|
37113 | __depends__: [
|
37114 | KeyboardModule
|
37115 | ],
|
37116 | __init__: [ 'keyboardBindings' ],
|
37117 | keyboardBindings: [ 'type', BpmnKeyboardBindings ]
|
37118 | };
|
37119 |
|
37120 | var DEFAULT_CONFIG$1 = {
|
37121 | moveSpeed: 1,
|
37122 | moveSpeedAccelerated: 10
|
37123 | };
|
37124 |
|
37125 | var HIGHER_PRIORITY$1 = 1500;
|
37126 |
|
37127 | var LEFT = 'left';
|
37128 | var UP = 'up';
|
37129 | var RIGHT = 'right';
|
37130 | var DOWN = 'down';
|
37131 |
|
37132 | var KEY_TO_DIRECTION = {
|
37133 | ArrowLeft: LEFT,
|
37134 | Left: LEFT,
|
37135 | ArrowUp: UP,
|
37136 | Up: UP,
|
37137 | ArrowRight: RIGHT,
|
37138 | Right: RIGHT,
|
37139 | ArrowDown: DOWN,
|
37140 | Down: DOWN
|
37141 | };
|
37142 |
|
37143 | var DIRECTIONS_DELTA = {
|
37144 | left: function(speed) {
|
37145 | return {
|
37146 | x: -speed,
|
37147 | y: 0
|
37148 | };
|
37149 | },
|
37150 | up: function(speed) {
|
37151 | return {
|
37152 | x: 0,
|
37153 | y: -speed
|
37154 | };
|
37155 | },
|
37156 | right: function(speed) {
|
37157 | return {
|
37158 | x: speed,
|
37159 | y: 0
|
37160 | };
|
37161 | },
|
37162 | down: function(speed) {
|
37163 | return {
|
37164 | x: 0,
|
37165 | y: speed
|
37166 | };
|
37167 | }
|
37168 | };
|
37169 |
|
37170 |
|
37171 | |
37172 |
|
37173 |
|
37174 |
|
37175 |
|
37176 |
|
37177 |
|
37178 |
|
37179 |
|
37180 |
|
37181 |
|
37182 |
|
37183 | function KeyboardMoveSelection(
|
37184 | config,
|
37185 | keyboard,
|
37186 | modeling,
|
37187 | rules,
|
37188 | selection
|
37189 | ) {
|
37190 |
|
37191 | var self = this;
|
37192 |
|
37193 | this._config = assign({}, DEFAULT_CONFIG$1, config || {});
|
37194 |
|
37195 | keyboard.addListener(HIGHER_PRIORITY$1, function(event) {
|
37196 |
|
37197 | var keyEvent = event.keyEvent;
|
37198 |
|
37199 | var direction = KEY_TO_DIRECTION[keyEvent.key];
|
37200 |
|
37201 | if (!direction) {
|
37202 | return;
|
37203 | }
|
37204 |
|
37205 | if (keyboard.isCmd(keyEvent)) {
|
37206 | return;
|
37207 | }
|
37208 |
|
37209 | var accelerated = keyboard.isShift(keyEvent);
|
37210 |
|
37211 | self.moveSelection(direction, accelerated);
|
37212 |
|
37213 | return true;
|
37214 | });
|
37215 |
|
37216 |
|
37217 | |
37218 |
|
37219 |
|
37220 |
|
37221 |
|
37222 |
|
37223 |
|
37224 | this.moveSelection = function(direction, accelerated) {
|
37225 |
|
37226 | var selectedElements = selection.get();
|
37227 |
|
37228 | if (!selectedElements.length) {
|
37229 | return;
|
37230 | }
|
37231 |
|
37232 | var speed = this._config[
|
37233 | accelerated ?
|
37234 | 'moveSpeedAccelerated' :
|
37235 | 'moveSpeed'
|
37236 | ];
|
37237 |
|
37238 | var delta = DIRECTIONS_DELTA[direction](speed);
|
37239 |
|
37240 | var canMove = rules.allowed('elements.move', {
|
37241 | shapes: selectedElements
|
37242 | });
|
37243 |
|
37244 | if (canMove) {
|
37245 | modeling.moveElements(selectedElements, delta);
|
37246 | }
|
37247 | };
|
37248 |
|
37249 | }
|
37250 |
|
37251 | KeyboardMoveSelection.$inject = [
|
37252 | 'config.keyboardMoveSelection',
|
37253 | 'keyboard',
|
37254 | 'modeling',
|
37255 | 'rules',
|
37256 | 'selection'
|
37257 | ];
|
37258 |
|
37259 | var KeyboardMoveSelectionModule = {
|
37260 | __depends__: [
|
37261 | KeyboardModule,
|
37262 | SelectionModule
|
37263 | ],
|
37264 | __init__: [
|
37265 | 'keyboardMoveSelection'
|
37266 | ],
|
37267 | keyboardMoveSelection: [ 'type', KeyboardMoveSelection ]
|
37268 | };
|
37269 |
|
37270 | |
37271 |
|
37272 |
|
37273 |
|
37274 |
|
37275 |
|
37276 |
|
37277 |
|
37278 |
|
37279 |
|
37280 |
|
37281 |
|
37282 | function ChangeSupport(
|
37283 | eventBus, canvas, elementRegistry,
|
37284 | graphicsFactory) {
|
37285 |
|
37286 |
|
37287 |
|
37288 |
|
37289 | eventBus.on('element.changed', function(event) {
|
37290 |
|
37291 | var element = event.element;
|
37292 |
|
37293 |
|
37294 |
|
37295 | if (element.parent || element === canvas.getRootElement()) {
|
37296 | event.gfx = elementRegistry.getGraphics(element);
|
37297 | }
|
37298 |
|
37299 |
|
37300 | if (!event.gfx) {
|
37301 | return;
|
37302 | }
|
37303 |
|
37304 | eventBus.fire(getType(element) + '.changed', event);
|
37305 | });
|
37306 |
|
37307 | eventBus.on('elements.changed', function(event) {
|
37308 |
|
37309 | var elements = event.elements;
|
37310 |
|
37311 | elements.forEach(function(e) {
|
37312 | eventBus.fire('element.changed', { element: e });
|
37313 | });
|
37314 |
|
37315 | graphicsFactory.updateContainments(elements);
|
37316 | });
|
37317 |
|
37318 | eventBus.on('shape.changed', function(event) {
|
37319 | graphicsFactory.update('shape', event.element, event.gfx);
|
37320 | });
|
37321 |
|
37322 | eventBus.on('connection.changed', function(event) {
|
37323 | graphicsFactory.update('connection', event.element, event.gfx);
|
37324 | });
|
37325 | }
|
37326 |
|
37327 | ChangeSupport.$inject = [
|
37328 | 'eventBus',
|
37329 | 'canvas',
|
37330 | 'elementRegistry',
|
37331 | 'graphicsFactory'
|
37332 | ];
|
37333 |
|
37334 | var ChangeSupportModule = {
|
37335 | __init__: [ 'changeSupport'],
|
37336 | changeSupport: [ 'type', ChangeSupport ]
|
37337 | };
|
37338 |
|
37339 | var DEFAULT_MIN_WIDTH = 10;
|
37340 |
|
37341 |
|
37342 | |
37343 |
|
37344 |
|
37345 |
|
37346 |
|
37347 |
|
37348 |
|
37349 |
|
37350 |
|
37351 |
|
37352 |
|
37353 |
|
37354 |
|
37355 |
|
37356 |
|
37357 |
|
37358 |
|
37359 |
|
37360 |
|
37361 |
|
37362 |
|
37363 |
|
37364 |
|
37365 |
|
37366 |
|
37367 |
|
37368 |
|
37369 |
|
37370 |
|
37371 |
|
37372 |
|
37373 |
|
37374 |
|
37375 |
|
37376 |
|
37377 |
|
37378 |
|
37379 | function Resize(eventBus, rules, modeling, dragging) {
|
37380 |
|
37381 | this._dragging = dragging;
|
37382 | this._rules = rules;
|
37383 |
|
37384 | var self = this;
|
37385 |
|
37386 |
|
37387 | |
37388 |
|
37389 |
|
37390 |
|
37391 |
|
37392 |
|
37393 | function handleMove(context, delta) {
|
37394 |
|
37395 | var shape = context.shape,
|
37396 | direction = context.direction,
|
37397 | resizeConstraints = context.resizeConstraints,
|
37398 | newBounds;
|
37399 |
|
37400 | context.delta = delta;
|
37401 |
|
37402 | newBounds = resizeBounds(shape, direction, delta);
|
37403 |
|
37404 |
|
37405 | context.newBounds = ensureConstraints$1(newBounds, resizeConstraints);
|
37406 |
|
37407 |
|
37408 | context.canExecute = self.canResize(context);
|
37409 | }
|
37410 |
|
37411 | |
37412 |
|
37413 |
|
37414 |
|
37415 |
|
37416 | function handleStart(context) {
|
37417 |
|
37418 | var resizeConstraints = context.resizeConstraints,
|
37419 |
|
37420 |
|
37421 | minBounds = context.minBounds;
|
37422 |
|
37423 | if (resizeConstraints !== undefined) {
|
37424 | return;
|
37425 | }
|
37426 |
|
37427 | if (minBounds === undefined) {
|
37428 | minBounds = self.computeMinResizeBox(context);
|
37429 | }
|
37430 |
|
37431 | context.resizeConstraints = {
|
37432 | min: asTRBL(minBounds)
|
37433 | };
|
37434 | }
|
37435 |
|
37436 | |
37437 |
|
37438 |
|
37439 |
|
37440 |
|
37441 | function handleEnd(context) {
|
37442 | var shape = context.shape,
|
37443 | canExecute = context.canExecute,
|
37444 | newBounds = context.newBounds;
|
37445 |
|
37446 | if (canExecute) {
|
37447 |
|
37448 |
|
37449 |
|
37450 | newBounds = roundBounds(newBounds);
|
37451 |
|
37452 | if (!boundsChanged$1(shape, newBounds)) {
|
37453 |
|
37454 |
|
37455 | return;
|
37456 | }
|
37457 |
|
37458 |
|
37459 | modeling.resizeShape(shape, newBounds);
|
37460 | }
|
37461 | }
|
37462 |
|
37463 |
|
37464 | eventBus.on('resize.start', function(event) {
|
37465 | handleStart(event.context);
|
37466 | });
|
37467 |
|
37468 | eventBus.on('resize.move', function(event) {
|
37469 | var delta = {
|
37470 | x: event.dx,
|
37471 | y: event.dy
|
37472 | };
|
37473 |
|
37474 | handleMove(event.context, delta);
|
37475 | });
|
37476 |
|
37477 | eventBus.on('resize.end', function(event) {
|
37478 | handleEnd(event.context);
|
37479 | });
|
37480 |
|
37481 | }
|
37482 |
|
37483 |
|
37484 | Resize.prototype.canResize = function(context) {
|
37485 | var rules = this._rules;
|
37486 |
|
37487 | var ctx = pick(context, [ 'newBounds', 'shape', 'delta', 'direction' ]);
|
37488 |
|
37489 | return rules.allowed('shape.resize', ctx);
|
37490 | };
|
37491 |
|
37492 | |
37493 |
|
37494 |
|
37495 |
|
37496 |
|
37497 |
|
37498 |
|
37499 |
|
37500 |
|
37501 |
|
37502 | Resize.prototype.activate = function(event, shape, contextOrDirection) {
|
37503 | var dragging = this._dragging,
|
37504 | context,
|
37505 | direction;
|
37506 |
|
37507 | if (typeof contextOrDirection === 'string') {
|
37508 | contextOrDirection = {
|
37509 | direction: contextOrDirection
|
37510 | };
|
37511 | }
|
37512 |
|
37513 | context = assign({ shape: shape }, contextOrDirection);
|
37514 |
|
37515 | direction = context.direction;
|
37516 |
|
37517 | if (!direction) {
|
37518 | throw new Error('must provide a direction (n|w|s|e|nw|se|ne|sw)');
|
37519 | }
|
37520 |
|
37521 | dragging.init(event, getReferencePoint(shape, direction), 'resize', {
|
37522 | autoActivate: true,
|
37523 | cursor: getCursor(direction),
|
37524 | data: {
|
37525 | shape: shape,
|
37526 | context: context
|
37527 | }
|
37528 | });
|
37529 | };
|
37530 |
|
37531 | Resize.prototype.computeMinResizeBox = function(context) {
|
37532 | var shape = context.shape,
|
37533 | direction = context.direction,
|
37534 | minDimensions,
|
37535 | childrenBounds;
|
37536 |
|
37537 | minDimensions = context.minDimensions || {
|
37538 | width: DEFAULT_MIN_WIDTH,
|
37539 | height: DEFAULT_MIN_WIDTH
|
37540 | };
|
37541 |
|
37542 |
|
37543 | childrenBounds = computeChildrenBBox(shape, context.childrenBoxPadding);
|
37544 |
|
37545 |
|
37546 |
|
37547 | return getMinResizeBounds(direction, shape, minDimensions, childrenBounds);
|
37548 | };
|
37549 |
|
37550 |
|
37551 | Resize.$inject = [
|
37552 | 'eventBus',
|
37553 | 'rules',
|
37554 | 'modeling',
|
37555 | 'dragging'
|
37556 | ];
|
37557 |
|
37558 |
|
37559 |
|
37560 | function boundsChanged$1(shape, newBounds) {
|
37561 | return shape.x !== newBounds.x ||
|
37562 | shape.y !== newBounds.y ||
|
37563 | shape.width !== newBounds.width ||
|
37564 | shape.height !== newBounds.height;
|
37565 | }
|
37566 |
|
37567 | function getReferencePoint(shape, direction) {
|
37568 | var mid = getMid(shape),
|
37569 | trbl = asTRBL(shape);
|
37570 |
|
37571 | var referencePoint = {
|
37572 | x: mid.x,
|
37573 | y: mid.y
|
37574 | };
|
37575 |
|
37576 | if (direction.indexOf('n') !== -1) {
|
37577 | referencePoint.y = trbl.top;
|
37578 | } else if (direction.indexOf('s') !== -1) {
|
37579 | referencePoint.y = trbl.bottom;
|
37580 | }
|
37581 |
|
37582 | if (direction.indexOf('e') !== -1) {
|
37583 | referencePoint.x = trbl.right;
|
37584 | } else if (direction.indexOf('w') !== -1) {
|
37585 | referencePoint.x = trbl.left;
|
37586 | }
|
37587 |
|
37588 | return referencePoint;
|
37589 | }
|
37590 |
|
37591 | function getCursor(direction) {
|
37592 | var prefix = 'resize-';
|
37593 |
|
37594 | if (direction === 'n' || direction === 's') {
|
37595 | return prefix + 'ns';
|
37596 | } else if (direction === 'e' || direction === 'w') {
|
37597 | return prefix + 'ew';
|
37598 | } else if (direction === 'nw' || direction === 'se') {
|
37599 | return prefix + 'nwse';
|
37600 | } else {
|
37601 | return prefix + 'nesw';
|
37602 | }
|
37603 | }
|
37604 |
|
37605 | var MARKER_RESIZING = 'djs-resizing',
|
37606 | MARKER_RESIZE_NOT_OK = 'resize-not-ok';
|
37607 |
|
37608 | var LOW_PRIORITY$8 = 500;
|
37609 |
|
37610 |
|
37611 | |
37612 |
|
37613 |
|
37614 |
|
37615 |
|
37616 |
|
37617 |
|
37618 | function ResizePreview(eventBus, canvas, previewSupport) {
|
37619 |
|
37620 | |
37621 |
|
37622 |
|
37623 |
|
37624 |
|
37625 | function updateFrame(context) {
|
37626 |
|
37627 | var shape = context.shape,
|
37628 | bounds = context.newBounds,
|
37629 | frame = context.frame;
|
37630 |
|
37631 | if (!frame) {
|
37632 | frame = context.frame = previewSupport.addFrame(shape, canvas.getDefaultLayer());
|
37633 |
|
37634 | canvas.addMarker(shape, MARKER_RESIZING);
|
37635 | }
|
37636 |
|
37637 | if (bounds.width > 5) {
|
37638 | attr$1(frame, { x: bounds.x, width: bounds.width });
|
37639 | }
|
37640 |
|
37641 | if (bounds.height > 5) {
|
37642 | attr$1(frame, { y: bounds.y, height: bounds.height });
|
37643 | }
|
37644 |
|
37645 | if (context.canExecute) {
|
37646 | classes$1(frame).remove(MARKER_RESIZE_NOT_OK);
|
37647 | } else {
|
37648 | classes$1(frame).add(MARKER_RESIZE_NOT_OK);
|
37649 | }
|
37650 | }
|
37651 |
|
37652 | |
37653 |
|
37654 |
|
37655 |
|
37656 |
|
37657 | function removeFrame(context) {
|
37658 | var shape = context.shape,
|
37659 | frame = context.frame;
|
37660 |
|
37661 | if (frame) {
|
37662 | remove$1(context.frame);
|
37663 | }
|
37664 |
|
37665 | canvas.removeMarker(shape, MARKER_RESIZING);
|
37666 | }
|
37667 |
|
37668 |
|
37669 | eventBus.on('resize.move', LOW_PRIORITY$8, function(event) {
|
37670 | updateFrame(event.context);
|
37671 | });
|
37672 |
|
37673 |
|
37674 | eventBus.on('resize.cleanup', function(event) {
|
37675 | removeFrame(event.context);
|
37676 | });
|
37677 |
|
37678 | }
|
37679 |
|
37680 | ResizePreview.$inject = [
|
37681 | 'eventBus',
|
37682 | 'canvas',
|
37683 | 'previewSupport'
|
37684 | ];
|
37685 |
|
37686 | var HANDLE_OFFSET = -6,
|
37687 | HANDLE_SIZE = 4,
|
37688 | HANDLE_HIT_SIZE = 20;
|
37689 |
|
37690 | var CLS_RESIZER = 'djs-resizer';
|
37691 |
|
37692 | var directions = [ 'n', 'w', 's', 'e', 'nw', 'ne', 'se', 'sw' ];
|
37693 |
|
37694 |
|
37695 | |
37696 |
|
37697 |
|
37698 |
|
37699 |
|
37700 |
|
37701 |
|
37702 |
|
37703 | function ResizeHandles(eventBus, canvas, selection, resize) {
|
37704 |
|
37705 | this._resize = resize;
|
37706 | this._canvas = canvas;
|
37707 |
|
37708 | var self = this;
|
37709 |
|
37710 | eventBus.on('selection.changed', function(e) {
|
37711 | var newSelection = e.newSelection;
|
37712 |
|
37713 |
|
37714 | self.removeResizers();
|
37715 |
|
37716 |
|
37717 | if (newSelection.length === 1) {
|
37718 | forEach(newSelection, bind(self.addResizer, self));
|
37719 | }
|
37720 | });
|
37721 |
|
37722 | eventBus.on('shape.changed', function(e) {
|
37723 | var shape = e.element;
|
37724 |
|
37725 | if (selection.isSelected(shape)) {
|
37726 | self.removeResizers();
|
37727 |
|
37728 | self.addResizer(shape);
|
37729 | }
|
37730 | });
|
37731 | }
|
37732 |
|
37733 |
|
37734 | ResizeHandles.prototype.makeDraggable = function(element, gfx, direction) {
|
37735 | var resize = this._resize;
|
37736 |
|
37737 | function startResize(event) {
|
37738 |
|
37739 |
|
37740 | if (isPrimaryButton(event)) {
|
37741 | resize.activate(event, element, direction);
|
37742 | }
|
37743 | }
|
37744 |
|
37745 | componentEvent.bind(gfx, 'mousedown', startResize);
|
37746 | componentEvent.bind(gfx, 'touchstart', startResize);
|
37747 | };
|
37748 |
|
37749 |
|
37750 | ResizeHandles.prototype._createResizer = function(element, x, y, direction) {
|
37751 | var resizersParent = this._getResizersParent();
|
37752 |
|
37753 | var offset = getHandleOffset(direction);
|
37754 |
|
37755 | var group = create('g');
|
37756 |
|
37757 | classes$1(group).add(CLS_RESIZER);
|
37758 | classes$1(group).add(CLS_RESIZER + '-' + element.id);
|
37759 | classes$1(group).add(CLS_RESIZER + '-' + direction);
|
37760 |
|
37761 | append(resizersParent, group);
|
37762 |
|
37763 | var visual = create('rect');
|
37764 |
|
37765 | attr$1(visual, {
|
37766 | x: -HANDLE_SIZE / 2 + offset.x,
|
37767 | y: -HANDLE_SIZE / 2 + offset.y,
|
37768 | width: HANDLE_SIZE,
|
37769 | height: HANDLE_SIZE
|
37770 | });
|
37771 |
|
37772 | classes$1(visual).add(CLS_RESIZER + '-visual');
|
37773 |
|
37774 | append(group, visual);
|
37775 |
|
37776 | var hit = create('rect');
|
37777 |
|
37778 | attr$1(hit, {
|
37779 | x: -HANDLE_HIT_SIZE / 2 + offset.x,
|
37780 | y: -HANDLE_HIT_SIZE / 2 + offset.y,
|
37781 | width: HANDLE_HIT_SIZE,
|
37782 | height: HANDLE_HIT_SIZE
|
37783 | });
|
37784 |
|
37785 | classes$1(hit).add(CLS_RESIZER + '-hit');
|
37786 |
|
37787 | append(group, hit);
|
37788 |
|
37789 | transform$1(group, x, y);
|
37790 |
|
37791 | return group;
|
37792 | };
|
37793 |
|
37794 | ResizeHandles.prototype.createResizer = function(element, direction) {
|
37795 | var point = getReferencePoint(element, direction);
|
37796 |
|
37797 | var resizer = this._createResizer(element, point.x, point.y, direction);
|
37798 |
|
37799 | this.makeDraggable(element, resizer, direction);
|
37800 | };
|
37801 |
|
37802 |
|
37803 |
|
37804 | |
37805 |
|
37806 |
|
37807 |
|
37808 |
|
37809 | ResizeHandles.prototype.addResizer = function(shape) {
|
37810 | var self = this;
|
37811 |
|
37812 | var resize = this._resize;
|
37813 |
|
37814 | if (!resize.canResize({ shape: shape })) {
|
37815 | return;
|
37816 | }
|
37817 |
|
37818 | forEach(directions, function(direction) {
|
37819 | self.createResizer(shape, direction);
|
37820 | });
|
37821 | };
|
37822 |
|
37823 | |
37824 |
|
37825 |
|
37826 | ResizeHandles.prototype.removeResizers = function() {
|
37827 | var resizersParent = this._getResizersParent();
|
37828 |
|
37829 | clear$1(resizersParent);
|
37830 | };
|
37831 |
|
37832 | ResizeHandles.prototype._getResizersParent = function() {
|
37833 | return this._canvas.getLayer('resizers');
|
37834 | };
|
37835 |
|
37836 | ResizeHandles.$inject = [
|
37837 | 'eventBus',
|
37838 | 'canvas',
|
37839 | 'selection',
|
37840 | 'resize'
|
37841 | ];
|
37842 |
|
37843 |
|
37844 |
|
37845 | function getHandleOffset(direction) {
|
37846 | var offset = {
|
37847 | x: 0,
|
37848 | y: 0
|
37849 | };
|
37850 |
|
37851 | if (direction.indexOf('e') !== -1) {
|
37852 | offset.x = -HANDLE_OFFSET;
|
37853 | } else if (direction.indexOf('w') !== -1) {
|
37854 | offset.x = HANDLE_OFFSET;
|
37855 | }
|
37856 |
|
37857 | if (direction.indexOf('s') !== -1) {
|
37858 | offset.y = -HANDLE_OFFSET;
|
37859 | } else if (direction.indexOf('n') !== -1) {
|
37860 | offset.y = HANDLE_OFFSET;
|
37861 | }
|
37862 |
|
37863 | return offset;
|
37864 | }
|
37865 |
|
37866 | var ResizeModule = {
|
37867 | __depends__: [
|
37868 | RulesModule,
|
37869 | DraggingModule,
|
37870 | PreviewSupportModule
|
37871 | ],
|
37872 | __init__: [
|
37873 | 'resize',
|
37874 | 'resizePreview',
|
37875 | 'resizeHandles'
|
37876 | ],
|
37877 | resize: [ 'type', Resize ],
|
37878 | resizePreview: [ 'type', ResizePreview ],
|
37879 | resizeHandles: [ 'type', ResizeHandles ]
|
37880 | };
|
37881 |
|
37882 | |
37883 |
|
37884 |
|
37885 |
|
37886 |
|
37887 |
|
37888 |
|
37889 |
|
37890 | function createCategoryValue(definitions, bpmnFactory) {
|
37891 | var categoryValue = bpmnFactory.create('bpmn:CategoryValue'),
|
37892 | category = bpmnFactory.create('bpmn:Category', {
|
37893 | categoryValue: [ categoryValue ]
|
37894 | });
|
37895 |
|
37896 |
|
37897 | add$1(definitions.get('rootElements'), category);
|
37898 | getBusinessObject(category).$parent = definitions;
|
37899 | getBusinessObject(categoryValue).$parent = category;
|
37900 |
|
37901 | return categoryValue;
|
37902 |
|
37903 | }
|
37904 |
|
37905 | function LabelEditingProvider(
|
37906 | eventBus, bpmnFactory, canvas, directEditing,
|
37907 | modeling, resizeHandles, textRenderer) {
|
37908 |
|
37909 | this._bpmnFactory = bpmnFactory;
|
37910 | this._canvas = canvas;
|
37911 | this._modeling = modeling;
|
37912 | this._textRenderer = textRenderer;
|
37913 |
|
37914 | directEditing.registerProvider(this);
|
37915 |
|
37916 |
|
37917 | eventBus.on('element.dblclick', function(event) {
|
37918 | activateDirectEdit(event.element, true);
|
37919 | });
|
37920 |
|
37921 |
|
37922 | eventBus.on([
|
37923 | 'autoPlace.start',
|
37924 | 'canvas.viewbox.changing',
|
37925 | 'drag.init',
|
37926 | 'element.mousedown',
|
37927 | 'popupMenu.open'
|
37928 | ], function(event) {
|
37929 |
|
37930 | if (directEditing.isActive()) {
|
37931 | directEditing.complete();
|
37932 | }
|
37933 | });
|
37934 |
|
37935 |
|
37936 | eventBus.on([ 'commandStack.changed' ], function(e) {
|
37937 | if (directEditing.isActive()) {
|
37938 | directEditing.cancel();
|
37939 | }
|
37940 | });
|
37941 |
|
37942 |
|
37943 | eventBus.on('directEditing.activate', function(event) {
|
37944 | resizeHandles.removeResizers();
|
37945 | });
|
37946 |
|
37947 | eventBus.on('create.end', 500, function(event) {
|
37948 |
|
37949 | var context = event.context,
|
37950 | element = context.shape,
|
37951 | canExecute = event.context.canExecute,
|
37952 | isTouch = event.isTouch;
|
37953 |
|
37954 |
|
37955 |
|
37956 |
|
37957 |
|
37958 |
|
37959 |
|
37960 |
|
37961 |
|
37962 | if (isTouch) {
|
37963 | return;
|
37964 | }
|
37965 |
|
37966 | if (!canExecute) {
|
37967 | return;
|
37968 | }
|
37969 |
|
37970 | if (context.hints && context.hints.createElementsBehavior === false) {
|
37971 | return;
|
37972 | }
|
37973 |
|
37974 | activateDirectEdit(element);
|
37975 | });
|
37976 |
|
37977 | eventBus.on('autoPlace.end', 500, function(event) {
|
37978 | activateDirectEdit(event.shape);
|
37979 | });
|
37980 |
|
37981 |
|
37982 | function activateDirectEdit(element, force) {
|
37983 | if (force ||
|
37984 | isAny(element, [ 'bpmn:Task', 'bpmn:TextAnnotation', 'bpmn:Group' ]) ||
|
37985 | isCollapsedSubProcess(element)) {
|
37986 |
|
37987 | directEditing.activate(element);
|
37988 | }
|
37989 | }
|
37990 |
|
37991 | }
|
37992 |
|
37993 | LabelEditingProvider.$inject = [
|
37994 | 'eventBus',
|
37995 | 'bpmnFactory',
|
37996 | 'canvas',
|
37997 | 'directEditing',
|
37998 | 'modeling',
|
37999 | 'resizeHandles',
|
38000 | 'textRenderer'
|
38001 | ];
|
38002 |
|
38003 |
|
38004 | |
38005 |
|
38006 |
|
38007 |
|
38008 |
|
38009 |
|
38010 |
|
38011 | LabelEditingProvider.prototype.activate = function(element) {
|
38012 |
|
38013 |
|
38014 | var text = getLabel(element);
|
38015 |
|
38016 | if (text === undefined) {
|
38017 | return;
|
38018 | }
|
38019 |
|
38020 | var context = {
|
38021 | text: text
|
38022 | };
|
38023 |
|
38024 |
|
38025 | var bounds = this.getEditingBBox(element);
|
38026 |
|
38027 | assign(context, bounds);
|
38028 |
|
38029 | var options = {};
|
38030 |
|
38031 |
|
38032 | if (
|
38033 | isAny(element, [
|
38034 | 'bpmn:Task',
|
38035 | 'bpmn:Participant',
|
38036 | 'bpmn:Lane',
|
38037 | 'bpmn:CallActivity'
|
38038 | ]) ||
|
38039 | isCollapsedSubProcess(element)
|
38040 | ) {
|
38041 | assign(options, {
|
38042 | centerVertically: true
|
38043 | });
|
38044 | }
|
38045 |
|
38046 |
|
38047 | if (isLabelExternal(element)) {
|
38048 | assign(options, {
|
38049 | autoResize: true
|
38050 | });
|
38051 | }
|
38052 |
|
38053 |
|
38054 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
38055 | assign(options, {
|
38056 | resizable: true,
|
38057 | autoResize: true
|
38058 | });
|
38059 | }
|
38060 |
|
38061 | assign(context, {
|
38062 | options: options
|
38063 | });
|
38064 |
|
38065 | return context;
|
38066 | };
|
38067 |
|
38068 |
|
38069 | |
38070 |
|
38071 |
|
38072 |
|
38073 |
|
38074 |
|
38075 |
|
38076 |
|
38077 | LabelEditingProvider.prototype.getEditingBBox = function(element) {
|
38078 | var canvas = this._canvas;
|
38079 |
|
38080 | var target = element.label || element;
|
38081 |
|
38082 | var bbox = canvas.getAbsoluteBBox(target);
|
38083 |
|
38084 | var mid = {
|
38085 | x: bbox.x + bbox.width / 2,
|
38086 | y: bbox.y + bbox.height / 2
|
38087 | };
|
38088 |
|
38089 |
|
38090 | var bounds = { x: bbox.x, y: bbox.y };
|
38091 |
|
38092 | var zoom = canvas.zoom();
|
38093 |
|
38094 | var defaultStyle = this._textRenderer.getDefaultStyle(),
|
38095 | externalStyle = this._textRenderer.getExternalStyle();
|
38096 |
|
38097 |
|
38098 | var externalFontSize = externalStyle.fontSize * zoom,
|
38099 | externalLineHeight = externalStyle.lineHeight,
|
38100 | defaultFontSize = defaultStyle.fontSize * zoom,
|
38101 | defaultLineHeight = defaultStyle.lineHeight;
|
38102 |
|
38103 | var style = {
|
38104 | fontFamily: this._textRenderer.getDefaultStyle().fontFamily,
|
38105 | fontWeight: this._textRenderer.getDefaultStyle().fontWeight
|
38106 | };
|
38107 |
|
38108 |
|
38109 | if (is$1(element, 'bpmn:Lane') || isExpandedPool(element)) {
|
38110 |
|
38111 | assign(bounds, {
|
38112 | width: bbox.height,
|
38113 | height: 30 * zoom,
|
38114 | x: bbox.x - bbox.height / 2 + (15 * zoom),
|
38115 | y: mid.y - (30 * zoom) / 2
|
38116 | });
|
38117 |
|
38118 | assign(style, {
|
38119 | fontSize: defaultFontSize + 'px',
|
38120 | lineHeight: defaultLineHeight,
|
38121 | paddingTop: (7 * zoom) + 'px',
|
38122 | paddingBottom: (7 * zoom) + 'px',
|
38123 | paddingLeft: (5 * zoom) + 'px',
|
38124 | paddingRight: (5 * zoom) + 'px',
|
38125 | transform: 'rotate(-90deg)'
|
38126 | });
|
38127 | }
|
38128 |
|
38129 |
|
38130 |
|
38131 |
|
38132 | if (isAny(element, [ 'bpmn:Task', 'bpmn:CallActivity']) ||
|
38133 | isCollapsedPool(element) ||
|
38134 | isCollapsedSubProcess(element)) {
|
38135 |
|
38136 | assign(bounds, {
|
38137 | width: bbox.width,
|
38138 | height: bbox.height
|
38139 | });
|
38140 |
|
38141 | assign(style, {
|
38142 | fontSize: defaultFontSize + 'px',
|
38143 | lineHeight: defaultLineHeight,
|
38144 | paddingTop: (7 * zoom) + 'px',
|
38145 | paddingBottom: (7 * zoom) + 'px',
|
38146 | paddingLeft: (5 * zoom) + 'px',
|
38147 | paddingRight: (5 * zoom) + 'px'
|
38148 | });
|
38149 | }
|
38150 |
|
38151 |
|
38152 |
|
38153 | if (isExpandedSubProcess(element)) {
|
38154 | assign(bounds, {
|
38155 | width: bbox.width,
|
38156 | x: bbox.x
|
38157 | });
|
38158 |
|
38159 | assign(style, {
|
38160 | fontSize: defaultFontSize + 'px',
|
38161 | lineHeight: defaultLineHeight,
|
38162 | paddingTop: (7 * zoom) + 'px',
|
38163 | paddingBottom: (7 * zoom) + 'px',
|
38164 | paddingLeft: (5 * zoom) + 'px',
|
38165 | paddingRight: (5 * zoom) + 'px'
|
38166 | });
|
38167 | }
|
38168 |
|
38169 | var width = 90 * zoom,
|
38170 | paddingTop = 7 * zoom,
|
38171 | paddingBottom = 4 * zoom;
|
38172 |
|
38173 |
|
38174 | if (target.labelTarget) {
|
38175 | assign(bounds, {
|
38176 | width: width,
|
38177 | height: bbox.height + paddingTop + paddingBottom,
|
38178 | x: mid.x - width / 2,
|
38179 | y: bbox.y - paddingTop
|
38180 | });
|
38181 |
|
38182 | assign(style, {
|
38183 | fontSize: externalFontSize + 'px',
|
38184 | lineHeight: externalLineHeight,
|
38185 | paddingTop: paddingTop + 'px',
|
38186 | paddingBottom: paddingBottom + 'px'
|
38187 | });
|
38188 | }
|
38189 |
|
38190 |
|
38191 | if (isLabelExternal(target)
|
38192 | && !hasExternalLabel(target)
|
38193 | && !isLabel(target)) {
|
38194 |
|
38195 | var externalLabelMid = getExternalLabelMid(element);
|
38196 |
|
38197 | var absoluteBBox = canvas.getAbsoluteBBox({
|
38198 | x: externalLabelMid.x,
|
38199 | y: externalLabelMid.y,
|
38200 | width: 0,
|
38201 | height: 0
|
38202 | });
|
38203 |
|
38204 | var height = externalFontSize + paddingTop + paddingBottom;
|
38205 |
|
38206 | assign(bounds, {
|
38207 | width: width,
|
38208 | height: height,
|
38209 | x: absoluteBBox.x - width / 2,
|
38210 | y: absoluteBBox.y - height / 2
|
38211 | });
|
38212 |
|
38213 | assign(style, {
|
38214 | fontSize: externalFontSize + 'px',
|
38215 | lineHeight: externalLineHeight,
|
38216 | paddingTop: paddingTop + 'px',
|
38217 | paddingBottom: paddingBottom + 'px'
|
38218 | });
|
38219 | }
|
38220 |
|
38221 |
|
38222 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
38223 | assign(bounds, {
|
38224 | width: bbox.width,
|
38225 | height: bbox.height,
|
38226 | minWidth: 30 * zoom,
|
38227 | minHeight: 10 * zoom
|
38228 | });
|
38229 |
|
38230 | assign(style, {
|
38231 | textAlign: 'left',
|
38232 | paddingTop: (5 * zoom) + 'px',
|
38233 | paddingBottom: (7 * zoom) + 'px',
|
38234 | paddingLeft: (7 * zoom) + 'px',
|
38235 | paddingRight: (5 * zoom) + 'px',
|
38236 | fontSize: defaultFontSize + 'px',
|
38237 | lineHeight: defaultLineHeight
|
38238 | });
|
38239 | }
|
38240 |
|
38241 | return { bounds: bounds, style: style };
|
38242 | };
|
38243 |
|
38244 |
|
38245 | LabelEditingProvider.prototype.update = function(
|
38246 | element, newLabel,
|
38247 | activeContextText, bounds) {
|
38248 |
|
38249 | var newBounds,
|
38250 | bbox;
|
38251 |
|
38252 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
38253 |
|
38254 | bbox = this._canvas.getAbsoluteBBox(element);
|
38255 |
|
38256 | newBounds = {
|
38257 | x: element.x,
|
38258 | y: element.y,
|
38259 | width: element.width / bbox.width * bounds.width,
|
38260 | height: element.height / bbox.height * bounds.height
|
38261 | };
|
38262 | }
|
38263 |
|
38264 | if (is$1(element, 'bpmn:Group')) {
|
38265 |
|
38266 | var businessObject = getBusinessObject(element);
|
38267 |
|
38268 |
|
38269 | if (!businessObject.categoryValueRef) {
|
38270 |
|
38271 | var rootElement = this._canvas.getRootElement(),
|
38272 | definitions = getBusinessObject(rootElement).$parent;
|
38273 |
|
38274 | var categoryValue = createCategoryValue(definitions, this._bpmnFactory);
|
38275 |
|
38276 | getBusinessObject(element).categoryValueRef = categoryValue;
|
38277 | }
|
38278 |
|
38279 | }
|
38280 |
|
38281 | if (isEmptyText(newLabel)) {
|
38282 | newLabel = null;
|
38283 | }
|
38284 |
|
38285 | this._modeling.updateLabel(element, newLabel, newBounds);
|
38286 | };
|
38287 |
|
38288 |
|
38289 |
|
38290 |
|
38291 |
|
38292 | function isCollapsedSubProcess(element) {
|
38293 | return is$1(element, 'bpmn:SubProcess') && !isExpanded(element);
|
38294 | }
|
38295 |
|
38296 | function isExpandedSubProcess(element) {
|
38297 | return is$1(element, 'bpmn:SubProcess') && isExpanded(element);
|
38298 | }
|
38299 |
|
38300 | function isCollapsedPool(element) {
|
38301 | return is$1(element, 'bpmn:Participant') && !isExpanded(element);
|
38302 | }
|
38303 |
|
38304 | function isExpandedPool(element) {
|
38305 | return is$1(element, 'bpmn:Participant') && isExpanded(element);
|
38306 | }
|
38307 |
|
38308 | function isEmptyText(label) {
|
38309 | return !label || !label.trim();
|
38310 | }
|
38311 |
|
38312 | var MARKER_HIDDEN = 'djs-element-hidden',
|
38313 | MARKER_LABEL_HIDDEN = 'djs-label-hidden';
|
38314 |
|
38315 |
|
38316 | function LabelEditingPreview(
|
38317 | eventBus, canvas, elementRegistry,
|
38318 | pathMap) {
|
38319 |
|
38320 | var self = this;
|
38321 |
|
38322 | var defaultLayer = canvas.getDefaultLayer();
|
38323 |
|
38324 | var element, absoluteElementBBox, gfx;
|
38325 |
|
38326 | eventBus.on('directEditing.activate', function(context) {
|
38327 | var activeProvider = context.active;
|
38328 |
|
38329 | element = activeProvider.element.label || activeProvider.element;
|
38330 |
|
38331 |
|
38332 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
38333 | absoluteElementBBox = canvas.getAbsoluteBBox(element);
|
38334 |
|
38335 | gfx = create('g');
|
38336 |
|
38337 | var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', {
|
38338 | xScaleFactor: 1,
|
38339 | yScaleFactor: 1,
|
38340 | containerWidth: element.width,
|
38341 | containerHeight: element.height,
|
38342 | position: {
|
38343 | mx: 0.0,
|
38344 | my: 0.0
|
38345 | }
|
38346 | });
|
38347 |
|
38348 | var path = self.path = create('path');
|
38349 |
|
38350 | attr$1(path, {
|
38351 | d: textPathData,
|
38352 | strokeWidth: 2,
|
38353 | stroke: getStrokeColor$1(element)
|
38354 | });
|
38355 |
|
38356 | append(gfx, path);
|
38357 |
|
38358 | append(defaultLayer, gfx);
|
38359 |
|
38360 | translate(gfx, element.x, element.y);
|
38361 | }
|
38362 |
|
38363 | if (is$1(element, 'bpmn:TextAnnotation') ||
|
38364 | element.labelTarget) {
|
38365 | canvas.addMarker(element, MARKER_HIDDEN);
|
38366 | } else if (is$1(element, 'bpmn:Task') ||
|
38367 | is$1(element, 'bpmn:CallActivity') ||
|
38368 | is$1(element, 'bpmn:SubProcess') ||
|
38369 | is$1(element, 'bpmn:Participant')) {
|
38370 | canvas.addMarker(element, MARKER_LABEL_HIDDEN);
|
38371 | }
|
38372 | });
|
38373 |
|
38374 | eventBus.on('directEditing.resize', function(context) {
|
38375 |
|
38376 |
|
38377 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
38378 | var height = context.height,
|
38379 | dy = context.dy;
|
38380 |
|
38381 | var newElementHeight = Math.max(element.height / absoluteElementBBox.height * (height + dy), 0);
|
38382 |
|
38383 | var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', {
|
38384 | xScaleFactor: 1,
|
38385 | yScaleFactor: 1,
|
38386 | containerWidth: element.width,
|
38387 | containerHeight: newElementHeight,
|
38388 | position: {
|
38389 | mx: 0.0,
|
38390 | my: 0.0
|
38391 | }
|
38392 | });
|
38393 |
|
38394 | attr$1(self.path, {
|
38395 | d: textPathData
|
38396 | });
|
38397 | }
|
38398 | });
|
38399 |
|
38400 | eventBus.on([ 'directEditing.complete', 'directEditing.cancel' ], function(context) {
|
38401 | var activeProvider = context.active;
|
38402 |
|
38403 | if (activeProvider) {
|
38404 | canvas.removeMarker(activeProvider.element.label || activeProvider.element, MARKER_HIDDEN);
|
38405 | canvas.removeMarker(element, MARKER_LABEL_HIDDEN);
|
38406 | }
|
38407 |
|
38408 | element = undefined;
|
38409 | absoluteElementBBox = undefined;
|
38410 |
|
38411 | if (gfx) {
|
38412 | remove$1(gfx);
|
38413 |
|
38414 | gfx = undefined;
|
38415 | }
|
38416 | });
|
38417 | }
|
38418 |
|
38419 | LabelEditingPreview.$inject = [
|
38420 | 'eventBus',
|
38421 | 'canvas',
|
38422 | 'elementRegistry',
|
38423 | 'pathMap'
|
38424 | ];
|
38425 |
|
38426 |
|
38427 |
|
38428 |
|
38429 | function getStrokeColor$1(element, defaultColor) {
|
38430 | var bo = getBusinessObject(element);
|
38431 |
|
38432 | return bo.di.get('stroke') || defaultColor || 'black';
|
38433 | }
|
38434 |
|
38435 | var LabelEditingModule = {
|
38436 | __depends__: [
|
38437 | ChangeSupportModule,
|
38438 | ResizeModule,
|
38439 | DirectEditingModule
|
38440 | ],
|
38441 | __init__: [
|
38442 | 'labelEditingProvider',
|
38443 | 'labelEditingPreview'
|
38444 | ],
|
38445 | labelEditingProvider: [ 'type', LabelEditingProvider ],
|
38446 | labelEditingPreview: [ 'type', LabelEditingPreview ]
|
38447 | };
|
38448 |
|
38449 | var ALIGNMENTS = [
|
38450 | 'top',
|
38451 | 'bottom',
|
38452 | 'left',
|
38453 | 'right'
|
38454 | ];
|
38455 |
|
38456 | var ELEMENT_LABEL_DISTANCE = 10;
|
38457 |
|
38458 | |
38459 |
|
38460 |
|
38461 |
|
38462 |
|
38463 |
|
38464 |
|
38465 |
|
38466 | function AdaptiveLabelPositioningBehavior(eventBus, modeling) {
|
38467 |
|
38468 | CommandInterceptor.call(this, eventBus);
|
38469 |
|
38470 | this.postExecuted([
|
38471 | 'connection.create',
|
38472 | 'connection.layout',
|
38473 | 'connection.updateWaypoints'
|
38474 | ], function(event) {
|
38475 | var context = event.context,
|
38476 | connection = context.connection,
|
38477 | source = connection.source,
|
38478 | target = connection.target,
|
38479 | hints = context.hints || {};
|
38480 |
|
38481 | if (hints.createElementsBehavior !== false) {
|
38482 | checkLabelAdjustment(source);
|
38483 | checkLabelAdjustment(target);
|
38484 | }
|
38485 | });
|
38486 |
|
38487 |
|
38488 | this.postExecuted([
|
38489 | 'label.create'
|
38490 | ], function(event) {
|
38491 | var context = event.context,
|
38492 | shape = context.shape,
|
38493 | hints = context.hints || {};
|
38494 |
|
38495 | if (hints.createElementsBehavior !== false) {
|
38496 | checkLabelAdjustment(shape.labelTarget);
|
38497 | }
|
38498 | });
|
38499 |
|
38500 |
|
38501 | this.postExecuted([
|
38502 | 'elements.create'
|
38503 | ], function(event) {
|
38504 | var context = event.context,
|
38505 | elements = context.elements,
|
38506 | hints = context.hints || {};
|
38507 |
|
38508 | if (hints.createElementsBehavior !== false) {
|
38509 | elements.forEach(function(element) {
|
38510 | checkLabelAdjustment(element);
|
38511 | });
|
38512 | }
|
38513 | });
|
38514 |
|
38515 | function checkLabelAdjustment(element) {
|
38516 |
|
38517 |
|
38518 | if (!hasExternalLabel(element)) {
|
38519 | return;
|
38520 | }
|
38521 |
|
38522 | var optimalPosition = getOptimalPosition(element);
|
38523 |
|
38524 |
|
38525 | if (!optimalPosition) {
|
38526 | return;
|
38527 | }
|
38528 |
|
38529 | adjustLabelPosition(element, optimalPosition);
|
38530 | }
|
38531 |
|
38532 | function adjustLabelPosition(element, orientation) {
|
38533 |
|
38534 | var elementMid = getMid(element),
|
38535 | label = element.label,
|
38536 | labelMid = getMid(label);
|
38537 |
|
38538 |
|
38539 | if (!label.parent) {
|
38540 | return;
|
38541 | }
|
38542 |
|
38543 | var elementTrbl = asTRBL(element);
|
38544 |
|
38545 | var newLabelMid;
|
38546 |
|
38547 | switch (orientation) {
|
38548 | case 'top':
|
38549 | newLabelMid = {
|
38550 | x: elementMid.x,
|
38551 | y: elementTrbl.top - ELEMENT_LABEL_DISTANCE - label.height / 2
|
38552 | };
|
38553 |
|
38554 | break;
|
38555 |
|
38556 | case 'left':
|
38557 |
|
38558 | newLabelMid = {
|
38559 | x: elementTrbl.left - ELEMENT_LABEL_DISTANCE - label.width / 2,
|
38560 | y: elementMid.y
|
38561 | };
|
38562 |
|
38563 | break;
|
38564 |
|
38565 | case 'bottom':
|
38566 |
|
38567 | newLabelMid = {
|
38568 | x: elementMid.x,
|
38569 | y: elementTrbl.bottom + ELEMENT_LABEL_DISTANCE + label.height / 2
|
38570 | };
|
38571 |
|
38572 | break;
|
38573 |
|
38574 | case 'right':
|
38575 |
|
38576 | newLabelMid = {
|
38577 | x: elementTrbl.right + ELEMENT_LABEL_DISTANCE + label.width / 2,
|
38578 | y: elementMid.y
|
38579 | };
|
38580 |
|
38581 | break;
|
38582 | }
|
38583 |
|
38584 | var delta$1 = delta(newLabelMid, labelMid);
|
38585 |
|
38586 | modeling.moveShape(label, delta$1);
|
38587 | }
|
38588 |
|
38589 | }
|
38590 |
|
38591 | inherits_browser(AdaptiveLabelPositioningBehavior, CommandInterceptor);
|
38592 |
|
38593 | AdaptiveLabelPositioningBehavior.$inject = [
|
38594 | 'eventBus',
|
38595 | 'modeling'
|
38596 | ];
|
38597 |
|
38598 |
|
38599 |
|
38600 |
|
38601 | |
38602 |
|
38603 |
|
38604 |
|
38605 |
|
38606 |
|
38607 |
|
38608 | function getTakenHostAlignments(element) {
|
38609 |
|
38610 | var hostElement = element.host,
|
38611 | elementMid = getMid(element),
|
38612 | hostOrientation = getOrientation(elementMid, hostElement);
|
38613 |
|
38614 | var freeAlignments;
|
38615 |
|
38616 |
|
38617 | if (hostOrientation.indexOf('-') >= 0) {
|
38618 | freeAlignments = hostOrientation.split('-');
|
38619 | } else {
|
38620 | freeAlignments = [ hostOrientation ];
|
38621 | }
|
38622 |
|
38623 | var takenAlignments = ALIGNMENTS.filter(function(alignment) {
|
38624 |
|
38625 | return freeAlignments.indexOf(alignment) === -1;
|
38626 | });
|
38627 |
|
38628 | return takenAlignments;
|
38629 |
|
38630 | }
|
38631 |
|
38632 | |
38633 |
|
38634 |
|
38635 |
|
38636 |
|
38637 |
|
38638 |
|
38639 | function getTakenConnectionAlignments(element) {
|
38640 |
|
38641 | var elementMid = getMid(element);
|
38642 |
|
38643 | var takenAlignments = [].concat(
|
38644 | element.incoming.map(function(c) {
|
38645 | return c.waypoints[c.waypoints.length - 2 ];
|
38646 | }),
|
38647 | element.outgoing.map(function(c) {
|
38648 | return c.waypoints[1];
|
38649 | })
|
38650 | ).map(function(point) {
|
38651 | return getApproximateOrientation(elementMid, point);
|
38652 | });
|
38653 |
|
38654 | return takenAlignments;
|
38655 | }
|
38656 |
|
38657 | |
38658 |
|
38659 |
|
38660 |
|
38661 |
|
38662 |
|
38663 |
|
38664 |
|
38665 | function getOptimalPosition(element) {
|
38666 |
|
38667 | var labelMid = getMid(element.label);
|
38668 |
|
38669 | var elementMid = getMid(element);
|
38670 |
|
38671 | var labelOrientation = getApproximateOrientation(elementMid, labelMid);
|
38672 |
|
38673 | if (!isAligned(labelOrientation)) {
|
38674 | return;
|
38675 | }
|
38676 |
|
38677 | var takenAlignments = getTakenConnectionAlignments(element);
|
38678 |
|
38679 | if (element.host) {
|
38680 | var takenHostAlignments = getTakenHostAlignments(element);
|
38681 |
|
38682 | takenAlignments = takenAlignments.concat(takenHostAlignments);
|
38683 | }
|
38684 |
|
38685 | var freeAlignments = ALIGNMENTS.filter(function(alignment) {
|
38686 |
|
38687 | return takenAlignments.indexOf(alignment) === -1;
|
38688 | });
|
38689 |
|
38690 |
|
38691 | if (freeAlignments.indexOf(labelOrientation) !== -1) {
|
38692 | return;
|
38693 | }
|
38694 |
|
38695 | return freeAlignments[0];
|
38696 | }
|
38697 |
|
38698 | function getApproximateOrientation(p0, p1) {
|
38699 | return getOrientation(p1, p0, 5);
|
38700 | }
|
38701 |
|
38702 | function isAligned(orientation) {
|
38703 | return ALIGNMENTS.indexOf(orientation) !== -1;
|
38704 | }
|
38705 |
|
38706 | function AppendBehavior(eventBus, elementFactory, bpmnRules) {
|
38707 |
|
38708 | CommandInterceptor.call(this, eventBus);
|
38709 |
|
38710 |
|
38711 |
|
38712 | this.preExecute('shape.append', function(context) {
|
38713 |
|
38714 | var source = context.source,
|
38715 | shape = context.shape;
|
38716 |
|
38717 | if (!context.position) {
|
38718 |
|
38719 | if (is$1(shape, 'bpmn:TextAnnotation')) {
|
38720 | context.position = {
|
38721 | x: source.x + source.width / 2 + 75,
|
38722 | y: source.y - (50) - shape.height / 2
|
38723 | };
|
38724 | } else {
|
38725 | context.position = {
|
38726 | x: source.x + source.width + 80 + shape.width / 2,
|
38727 | y: source.y + source.height / 2
|
38728 | };
|
38729 | }
|
38730 | }
|
38731 | }, true);
|
38732 | }
|
38733 |
|
38734 | inherits_browser(AppendBehavior, CommandInterceptor);
|
38735 |
|
38736 | AppendBehavior.$inject = [
|
38737 | 'eventBus',
|
38738 | 'elementFactory',
|
38739 | 'bpmnRules'
|
38740 | ];
|
38741 |
|
38742 | function AssociationBehavior(injector, modeling) {
|
38743 | injector.invoke(CommandInterceptor, this);
|
38744 |
|
38745 | this.postExecute('shape.move', function(context) {
|
38746 | var newParent = context.newParent,
|
38747 | shape = context.shape;
|
38748 |
|
38749 | var associations = filter(shape.incoming.concat(shape.outgoing), function(connection) {
|
38750 | return is$1(connection, 'bpmn:Association');
|
38751 | });
|
38752 |
|
38753 | forEach(associations, function(association) {
|
38754 | modeling.moveConnection(association, { x: 0, y: 0 }, newParent);
|
38755 | });
|
38756 | }, true);
|
38757 | }
|
38758 |
|
38759 | inherits_browser(AssociationBehavior, CommandInterceptor);
|
38760 |
|
38761 | AssociationBehavior.$inject = [
|
38762 | 'injector',
|
38763 | 'modeling'
|
38764 | ];
|
38765 |
|
38766 | var LOW_PRIORITY$9 = 500;
|
38767 |
|
38768 |
|
38769 | |
38770 |
|
38771 |
|
38772 | function AttachEventBehavior(bpmnReplace, injector) {
|
38773 | injector.invoke(CommandInterceptor, this);
|
38774 |
|
38775 | this._bpmnReplace = bpmnReplace;
|
38776 |
|
38777 | var self = this;
|
38778 |
|
38779 | this.postExecuted('elements.create', LOW_PRIORITY$9, function(context) {
|
38780 | var elements = context.elements;
|
38781 |
|
38782 | elements = elements.filter(function(shape) {
|
38783 | var host = shape.host;
|
38784 |
|
38785 | return shouldReplace(shape, host);
|
38786 | });
|
38787 |
|
38788 | if (elements.length !== 1) {
|
38789 | return;
|
38790 | }
|
38791 |
|
38792 | elements.map(function(element) {
|
38793 | return elements.indexOf(element);
|
38794 | }).forEach(function(index) {
|
38795 | var host = elements[ index ];
|
38796 |
|
38797 | context.elements[ index ] = self.replaceShape(elements[ index ], host);
|
38798 | });
|
38799 | }, true);
|
38800 |
|
38801 |
|
38802 | this.preExecute('elements.move', LOW_PRIORITY$9, function(context) {
|
38803 | var shapes = context.shapes,
|
38804 | host = context.newHost;
|
38805 |
|
38806 | if (shapes.length !== 1) {
|
38807 | return;
|
38808 | }
|
38809 |
|
38810 | var shape = shapes[0];
|
38811 |
|
38812 | if (shouldReplace(shape, host)) {
|
38813 | context.shapes = [ self.replaceShape(shape, host) ];
|
38814 | }
|
38815 | }, true);
|
38816 | }
|
38817 |
|
38818 | AttachEventBehavior.$inject = [
|
38819 | 'bpmnReplace',
|
38820 | 'injector'
|
38821 | ];
|
38822 |
|
38823 | inherits_browser(AttachEventBehavior, CommandInterceptor);
|
38824 |
|
38825 | AttachEventBehavior.prototype.replaceShape = function(shape, host) {
|
38826 | var eventDefinition = getEventDefinition(shape);
|
38827 |
|
38828 | var boundaryEvent = {
|
38829 | type: 'bpmn:BoundaryEvent',
|
38830 | host: host
|
38831 | };
|
38832 |
|
38833 | if (eventDefinition) {
|
38834 | boundaryEvent.eventDefinitionType = eventDefinition.$type;
|
38835 | }
|
38836 |
|
38837 | return this._bpmnReplace.replaceElement(shape, boundaryEvent, { layoutConnection: false });
|
38838 | };
|
38839 |
|
38840 |
|
38841 |
|
38842 |
|
38843 | function getEventDefinition(element) {
|
38844 | var businessObject = getBusinessObject(element),
|
38845 | eventDefinitions = businessObject.eventDefinitions;
|
38846 |
|
38847 | return eventDefinitions && eventDefinitions[0];
|
38848 | }
|
38849 |
|
38850 | function shouldReplace(shape, host) {
|
38851 | return !isLabel(shape) &&
|
38852 | isAny(shape, [ 'bpmn:IntermediateThrowEvent', 'bpmn:IntermediateCatchEvent' ]) && !!host;
|
38853 | }
|
38854 |
|
38855 | |
38856 |
|
38857 |
|
38858 | function BoundaryEventBehavior(eventBus, modeling) {
|
38859 |
|
38860 | CommandInterceptor.call(this, eventBus);
|
38861 |
|
38862 | function getBoundaryEvents(element) {
|
38863 | return filter(element.attachers, function(attacher) {
|
38864 | return is$1(attacher, 'bpmn:BoundaryEvent');
|
38865 | });
|
38866 | }
|
38867 |
|
38868 |
|
38869 | this.postExecute('connection.create', function(event) {
|
38870 | var source = event.context.source,
|
38871 | target = event.context.target,
|
38872 | boundaryEvents = getBoundaryEvents(target);
|
38873 |
|
38874 | if (
|
38875 | is$1(source, 'bpmn:EventBasedGateway') &&
|
38876 | is$1(target, 'bpmn:ReceiveTask') &&
|
38877 | boundaryEvents.length > 0
|
38878 | ) {
|
38879 | modeling.removeElements(boundaryEvents);
|
38880 | }
|
38881 |
|
38882 | });
|
38883 |
|
38884 |
|
38885 | this.postExecute('connection.reconnect', function(event) {
|
38886 | var oldSource = event.context.oldSource,
|
38887 | newSource = event.context.newSource;
|
38888 |
|
38889 | if (is$1(oldSource, 'bpmn:Gateway') &&
|
38890 | is$1(newSource, 'bpmn:EventBasedGateway')) {
|
38891 | forEach(newSource.outgoing, function(connection) {
|
38892 | var target = connection.target,
|
38893 | attachedboundaryEvents = getBoundaryEvents(target);
|
38894 |
|
38895 | if (is$1(target, 'bpmn:ReceiveTask') &&
|
38896 | attachedboundaryEvents.length > 0) {
|
38897 | modeling.removeElements(attachedboundaryEvents);
|
38898 | }
|
38899 | });
|
38900 | }
|
38901 | });
|
38902 | }
|
38903 |
|
38904 | BoundaryEventBehavior.$inject = [
|
38905 | 'eventBus',
|
38906 | 'modeling'
|
38907 | ];
|
38908 |
|
38909 | inherits_browser(BoundaryEventBehavior, CommandInterceptor);
|
38910 |
|
38911 | var LOW_PRIORITY$a = 500;
|
38912 |
|
38913 |
|
38914 | |
38915 |
|
38916 |
|
38917 |
|
38918 | function RootElementReferenceBehavior(bpmnjs, eventBus, injector) {
|
38919 | injector.invoke(CommandInterceptor, this);
|
38920 |
|
38921 | function hasRootElement(rootElement) {
|
38922 | var definitions = bpmnjs.getDefinitions(),
|
38923 | rootElements = definitions.get('rootElements');
|
38924 |
|
38925 | return !!find(rootElements, matchPattern({ id: rootElement.id }));
|
38926 | }
|
38927 |
|
38928 | function getRootElementReferencePropertyName(eventDefinition) {
|
38929 | if (is$1(eventDefinition, 'bpmn:ErrorEventDefinition')) {
|
38930 | return 'errorRef';
|
38931 | } else if (is$1(eventDefinition, 'bpmn:EscalationEventDefinition')) {
|
38932 | return 'escalationRef';
|
38933 | } else if (is$1(eventDefinition, 'bpmn:MessageEventDefinition')) {
|
38934 | return 'messageRef';
|
38935 | } else if (is$1(eventDefinition, 'bpmn:SignalEventDefinition')) {
|
38936 | return 'signalRef';
|
38937 | }
|
38938 | }
|
38939 |
|
38940 | function getRootElementReferenced(eventDefinition) {
|
38941 | return eventDefinition.get(getRootElementReferencePropertyName(eventDefinition));
|
38942 | }
|
38943 |
|
38944 |
|
38945 | this.executed('shape.create', function(context) {
|
38946 | var shape = context.shape;
|
38947 |
|
38948 | if (!hasAnyEventDefinition(shape, [
|
38949 | 'bpmn:ErrorEventDefinition',
|
38950 | 'bpmn:EscalationEventDefinition',
|
38951 | 'bpmn:MessageEventDefinition',
|
38952 | 'bpmn:SignalEventDefinition'
|
38953 | ])) {
|
38954 | return;
|
38955 | }
|
38956 |
|
38957 | var businessObject = getBusinessObject(shape),
|
38958 | eventDefinitions = businessObject.get('eventDefinitions'),
|
38959 | eventDefinition = eventDefinitions[ 0 ],
|
38960 | rootElement = getRootElementReferenced(eventDefinition),
|
38961 | rootElements;
|
38962 |
|
38963 | if (rootElement && !hasRootElement(rootElement)) {
|
38964 | rootElements = bpmnjs.getDefinitions().get('rootElements');
|
38965 |
|
38966 |
|
38967 | add$1(rootElements, rootElement);
|
38968 |
|
38969 | context.addedRootElement = rootElement;
|
38970 | }
|
38971 | }, true);
|
38972 |
|
38973 | this.reverted('shape.create', function(context) {
|
38974 | var addedRootElement = context.addedRootElement;
|
38975 |
|
38976 | if (!addedRootElement) {
|
38977 | return;
|
38978 | }
|
38979 |
|
38980 | var rootElements = bpmnjs.getDefinitions().get('rootElements');
|
38981 |
|
38982 |
|
38983 | remove$2(rootElements, addedRootElement);
|
38984 | }, true);
|
38985 |
|
38986 | eventBus.on('copyPaste.copyElement', function(context) {
|
38987 | var descriptor = context.descriptor,
|
38988 | element = context.element;
|
38989 |
|
38990 | if (!hasAnyEventDefinition(element, [
|
38991 | 'bpmn:ErrorEventDefinition',
|
38992 | 'bpmn:EscalationEventDefinition',
|
38993 | 'bpmn:MessageEventDefinition',
|
38994 | 'bpmn:SignalEventDefinition'
|
38995 | ])) {
|
38996 | return;
|
38997 | }
|
38998 |
|
38999 | var businessObject = getBusinessObject(element),
|
39000 | eventDefinitions = businessObject.get('eventDefinitions'),
|
39001 | eventDefinition = eventDefinitions[ 0 ],
|
39002 | rootElement = getRootElementReferenced(eventDefinition);
|
39003 |
|
39004 | if (rootElement) {
|
39005 | descriptor.referencedRootElement = rootElement;
|
39006 | }
|
39007 | });
|
39008 |
|
39009 | eventBus.on('copyPaste.pasteElement', LOW_PRIORITY$a, function(context) {
|
39010 | var descriptor = context.descriptor,
|
39011 | businessObject = descriptor.businessObject;
|
39012 |
|
39013 | if (!hasAnyEventDefinition(businessObject, [
|
39014 | 'bpmn:ErrorEventDefinition',
|
39015 | 'bpmn:EscalationEventDefinition',
|
39016 | 'bpmn:MessageEventDefinition',
|
39017 | 'bpmn:SignalEventDefinition'
|
39018 | ])) {
|
39019 | return;
|
39020 | }
|
39021 |
|
39022 | var eventDefinitions = businessObject.get('eventDefinitions'),
|
39023 | eventDefinition = eventDefinitions[ 0 ],
|
39024 | referencedRootElement = descriptor.referencedRootElement;
|
39025 |
|
39026 | if (!referencedRootElement) {
|
39027 | return;
|
39028 | }
|
39029 |
|
39030 | eventDefinition.set(getRootElementReferencePropertyName(eventDefinition), referencedRootElement);
|
39031 | });
|
39032 | }
|
39033 |
|
39034 | RootElementReferenceBehavior.$inject = [
|
39035 | 'bpmnjs',
|
39036 | 'eventBus',
|
39037 | 'injector'
|
39038 | ];
|
39039 |
|
39040 | inherits_browser(RootElementReferenceBehavior, CommandInterceptor);
|
39041 |
|
39042 |
|
39043 |
|
39044 | function hasAnyEventDefinition(element, types) {
|
39045 | if (!isArray(types)) {
|
39046 | types = [ types ];
|
39047 | }
|
39048 |
|
39049 | return some(types, function(type) {
|
39050 | return hasEventDefinition(element, type);
|
39051 | });
|
39052 | }
|
39053 |
|
39054 | function CreateBehavior(injector) {
|
39055 | injector.invoke(CommandInterceptor, this);
|
39056 |
|
39057 | this.preExecute('shape.create', 1500, function(event) {
|
39058 | var context = event.context,
|
39059 | parent = context.parent,
|
39060 | shape = context.shape;
|
39061 |
|
39062 | if (is$1(parent, 'bpmn:Lane') && !is$1(shape, 'bpmn:Lane')) {
|
39063 | context.parent = getParent$1(parent, 'bpmn:Participant');
|
39064 | }
|
39065 | });
|
39066 |
|
39067 | }
|
39068 |
|
39069 |
|
39070 | CreateBehavior.$inject = [ 'injector' ];
|
39071 |
|
39072 | inherits_browser(CreateBehavior, CommandInterceptor);
|
39073 |
|
39074 | var HIGH_PRIORITY$6 = 1500;
|
39075 | var HIGHEST_PRIORITY = 2000;
|
39076 |
|
39077 |
|
39078 | |
39079 |
|
39080 |
|
39081 |
|
39082 |
|
39083 |
|
39084 |
|
39085 | function FixHoverBehavior(elementRegistry, eventBus, canvas) {
|
39086 |
|
39087 | eventBus.on([
|
39088 | 'create.hover',
|
39089 | 'create.move',
|
39090 | 'create.end',
|
39091 | 'shape.move.hover',
|
39092 | 'shape.move.move',
|
39093 | 'shape.move.end'
|
39094 | ], HIGH_PRIORITY$6, function(event) {
|
39095 | var context = event.context,
|
39096 | shape = context.shape || event.shape,
|
39097 | hover = event.hover;
|
39098 |
|
39099 |
|
39100 |
|
39101 | if (is$1(hover, 'bpmn:Lane') && !isAny(shape, [ 'bpmn:Lane', 'bpmn:Participant' ])) {
|
39102 | event.hover = getLanesRoot(hover);
|
39103 | event.hoverGfx = elementRegistry.getGraphics(event.hover);
|
39104 | }
|
39105 |
|
39106 | var rootElement = canvas.getRootElement();
|
39107 |
|
39108 |
|
39109 |
|
39110 | if (hover !== rootElement && (shape.labelTarget || is$1(shape, 'bpmn:Group'))) {
|
39111 | event.hover = rootElement;
|
39112 | event.hoverGfx = elementRegistry.getGraphics(event.hover);
|
39113 | }
|
39114 | });
|
39115 |
|
39116 |
|
39117 | eventBus.on([
|
39118 | 'connect.hover',
|
39119 | 'connect.out',
|
39120 | 'connect.end',
|
39121 | 'connect.cleanup',
|
39122 | 'global-connect.hover',
|
39123 | 'global-connect.out',
|
39124 | 'global-connect.end',
|
39125 | 'global-connect.cleanup'
|
39126 | ], HIGH_PRIORITY$6, function(event) {
|
39127 | var hover = event.hover;
|
39128 |
|
39129 |
|
39130 |
|
39131 | if (is$1(hover, 'bpmn:Lane')) {
|
39132 | event.hover = getLanesRoot(hover) || hover;
|
39133 | event.hoverGfx = elementRegistry.getGraphics(event.hover);
|
39134 | }
|
39135 | });
|
39136 |
|
39137 |
|
39138 | eventBus.on([
|
39139 | 'bendpoint.move.hover'
|
39140 | ], HIGH_PRIORITY$6, function(event) {
|
39141 | var context = event.context,
|
39142 | hover = event.hover,
|
39143 | type = context.type;
|
39144 |
|
39145 |
|
39146 |
|
39147 | if (is$1(hover, 'bpmn:Lane') && /reconnect/.test(type)) {
|
39148 | event.hover = getLanesRoot(hover) || hover;
|
39149 | event.hoverGfx = elementRegistry.getGraphics(event.hover);
|
39150 | }
|
39151 | });
|
39152 |
|
39153 |
|
39154 | eventBus.on([
|
39155 | 'connect.start'
|
39156 | ], HIGH_PRIORITY$6, function(event) {
|
39157 | var context = event.context,
|
39158 | start = context.start;
|
39159 |
|
39160 |
|
39161 |
|
39162 | if (is$1(start, 'bpmn:Lane')) {
|
39163 | context.start = getLanesRoot(start) || start;
|
39164 | }
|
39165 | });
|
39166 |
|
39167 |
|
39168 |
|
39169 | eventBus.on('shape.move.start', HIGHEST_PRIORITY, function(event) {
|
39170 | var shape = event.shape;
|
39171 |
|
39172 | if (is$1(shape, 'bpmn:Lane')) {
|
39173 | event.shape = getLanesRoot(shape) || shape;
|
39174 | }
|
39175 | });
|
39176 |
|
39177 | }
|
39178 |
|
39179 | FixHoverBehavior.$inject = [
|
39180 | 'elementRegistry',
|
39181 | 'eventBus',
|
39182 | 'canvas'
|
39183 | ];
|
39184 |
|
39185 | |
39186 |
|
39187 |
|
39188 | function CreateDataObjectBehavior(eventBus, bpmnFactory, moddle) {
|
39189 |
|
39190 | CommandInterceptor.call(this, eventBus);
|
39191 |
|
39192 | this.preExecute('shape.create', function(event) {
|
39193 |
|
39194 | var context = event.context,
|
39195 | shape = context.shape;
|
39196 |
|
39197 | if (is$1(shape, 'bpmn:DataObjectReference') && shape.type !== 'label') {
|
39198 |
|
39199 |
|
39200 | var dataObject = bpmnFactory.create('bpmn:DataObject');
|
39201 |
|
39202 |
|
39203 | shape.businessObject.dataObjectRef = dataObject;
|
39204 | }
|
39205 | });
|
39206 |
|
39207 | }
|
39208 |
|
39209 | CreateDataObjectBehavior.$inject = [
|
39210 | 'eventBus',
|
39211 | 'bpmnFactory',
|
39212 | 'moddle'
|
39213 | ];
|
39214 |
|
39215 | inherits_browser(CreateDataObjectBehavior, CommandInterceptor);
|
39216 |
|
39217 | var HORIZONTAL_PARTICIPANT_PADDING = 20,
|
39218 | VERTICAL_PARTICIPANT_PADDING = 20;
|
39219 |
|
39220 | var PARTICIPANT_BORDER_WIDTH = 30;
|
39221 |
|
39222 | var HIGH_PRIORITY$7 = 2000;
|
39223 |
|
39224 |
|
39225 | |
39226 |
|
39227 |
|
39228 | function CreateParticipantBehavior$1(canvas, eventBus, modeling) {
|
39229 | CommandInterceptor.call(this, eventBus);
|
39230 |
|
39231 |
|
39232 | eventBus.on([
|
39233 | 'create.start',
|
39234 | 'shape.move.start'
|
39235 | ], HIGH_PRIORITY$7, function(event) {
|
39236 | var context = event.context,
|
39237 | shape = context.shape,
|
39238 | rootElement = canvas.getRootElement();
|
39239 |
|
39240 | if (!is$1(shape, 'bpmn:Participant') ||
|
39241 | !is$1(rootElement, 'bpmn:Process') ||
|
39242 | !rootElement.children.length) {
|
39243 | return;
|
39244 | }
|
39245 |
|
39246 |
|
39247 | var children = rootElement.children.filter(function(element) {
|
39248 | return !is$1(element, 'bpmn:Group') &&
|
39249 | !isLabel(element) &&
|
39250 | !isConnection$2(element);
|
39251 | });
|
39252 |
|
39253 |
|
39254 | if (!children.length) {
|
39255 | return;
|
39256 | }
|
39257 |
|
39258 | var childrenBBox = getBBox(children);
|
39259 |
|
39260 | var participantBounds = getParticipantBounds(shape, childrenBBox);
|
39261 |
|
39262 |
|
39263 | assign(shape, participantBounds);
|
39264 |
|
39265 |
|
39266 | context.createConstraints = getParticipantCreateConstraints(shape, childrenBBox);
|
39267 | });
|
39268 |
|
39269 |
|
39270 | eventBus.on('create.start', HIGH_PRIORITY$7, function(event) {
|
39271 | var context = event.context,
|
39272 | shape = context.shape,
|
39273 | rootElement = canvas.getRootElement(),
|
39274 | rootElementGfx = canvas.getGraphics(rootElement);
|
39275 |
|
39276 | function ensureHoveringProcess(event) {
|
39277 | event.element = rootElement;
|
39278 | event.gfx = rootElementGfx;
|
39279 | }
|
39280 |
|
39281 | if (is$1(shape, 'bpmn:Participant') && is$1(rootElement, 'bpmn:Process')) {
|
39282 | eventBus.on('element.hover', HIGH_PRIORITY$7, ensureHoveringProcess);
|
39283 |
|
39284 | eventBus.once('create.cleanup', function() {
|
39285 | eventBus.off('element.hover', ensureHoveringProcess);
|
39286 | });
|
39287 | }
|
39288 | });
|
39289 |
|
39290 | function ensureCollaboration(context) {
|
39291 | var parent = context.parent,
|
39292 | collaboration;
|
39293 |
|
39294 | var rootElement = canvas.getRootElement();
|
39295 |
|
39296 | if (is$1(rootElement, 'bpmn:Collaboration')) {
|
39297 | collaboration = rootElement;
|
39298 | } else {
|
39299 |
|
39300 |
|
39301 | collaboration = modeling.makeCollaboration();
|
39302 |
|
39303 |
|
39304 | context.process = parent;
|
39305 | }
|
39306 |
|
39307 | context.parent = collaboration;
|
39308 | }
|
39309 |
|
39310 |
|
39311 | this.preExecute('shape.create', function(context) {
|
39312 | var parent = context.parent,
|
39313 | shape = context.shape;
|
39314 |
|
39315 | if (is$1(shape, 'bpmn:Participant') && is$1(parent, 'bpmn:Process')) {
|
39316 | ensureCollaboration(context);
|
39317 | }
|
39318 | }, true);
|
39319 |
|
39320 | this.execute('shape.create', function(context) {
|
39321 | var process = context.process,
|
39322 | shape = context.shape;
|
39323 |
|
39324 | if (process) {
|
39325 | context.oldProcessRef = shape.businessObject.processRef;
|
39326 |
|
39327 |
|
39328 | shape.businessObject.processRef = process.businessObject;
|
39329 | }
|
39330 | }, true);
|
39331 |
|
39332 | this.revert('shape.create', function(context) {
|
39333 | var process = context.process,
|
39334 | shape = context.shape;
|
39335 |
|
39336 | if (process) {
|
39337 |
|
39338 |
|
39339 | shape.businessObject.processRef = context.oldProcessRef;
|
39340 | }
|
39341 | }, true);
|
39342 |
|
39343 | this.postExecute('shape.create', function(context) {
|
39344 | var process = context.process,
|
39345 | shape = context.shape;
|
39346 |
|
39347 | if (process) {
|
39348 |
|
39349 |
|
39350 | var processChildren = process.children.slice();
|
39351 |
|
39352 | modeling.moveElements(processChildren, { x: 0, y: 0 }, shape);
|
39353 | }
|
39354 |
|
39355 | }, true);
|
39356 |
|
39357 |
|
39358 | this.preExecute('elements.create', HIGH_PRIORITY$7, function(context) {
|
39359 | var elements = context.elements,
|
39360 | parent = context.parent,
|
39361 | participant;
|
39362 |
|
39363 | var hasParticipants = findParticipant(elements);
|
39364 |
|
39365 | if (hasParticipants && is$1(parent, 'bpmn:Process')) {
|
39366 | ensureCollaboration(context);
|
39367 |
|
39368 | participant = findParticipant(elements);
|
39369 |
|
39370 | context.oldProcessRef = participant.businessObject.processRef;
|
39371 |
|
39372 |
|
39373 | participant.businessObject.processRef = parent.businessObject;
|
39374 | }
|
39375 | }, true);
|
39376 |
|
39377 | this.revert('elements.create', function(context) {
|
39378 | var elements = context.elements,
|
39379 | process = context.process,
|
39380 | participant;
|
39381 |
|
39382 | if (process) {
|
39383 | participant = findParticipant(elements);
|
39384 |
|
39385 |
|
39386 | participant.businessObject.processRef = context.oldProcessRef;
|
39387 | }
|
39388 | }, true);
|
39389 |
|
39390 | this.postExecute('elements.create', function(context) {
|
39391 | var elements = context.elements,
|
39392 | process = context.process,
|
39393 | participant;
|
39394 |
|
39395 | if (process) {
|
39396 | participant = findParticipant(elements);
|
39397 |
|
39398 |
|
39399 | var processChildren = process.children.slice();
|
39400 |
|
39401 | modeling.moveElements(processChildren, { x: 0, y: 0 }, participant);
|
39402 | }
|
39403 |
|
39404 | }, true);
|
39405 |
|
39406 | }
|
39407 |
|
39408 | CreateParticipantBehavior$1.$inject = [
|
39409 | 'canvas',
|
39410 | 'eventBus',
|
39411 | 'modeling'
|
39412 | ];
|
39413 |
|
39414 | inherits_browser(CreateParticipantBehavior$1, CommandInterceptor);
|
39415 |
|
39416 |
|
39417 |
|
39418 | function getParticipantBounds(shape, childrenBBox) {
|
39419 | childrenBBox = {
|
39420 | width: childrenBBox.width + HORIZONTAL_PARTICIPANT_PADDING * 2 + PARTICIPANT_BORDER_WIDTH,
|
39421 | height: childrenBBox.height + VERTICAL_PARTICIPANT_PADDING * 2
|
39422 | };
|
39423 |
|
39424 | var width = Math.max(shape.width, childrenBBox.width),
|
39425 | height = Math.max(shape.height, childrenBBox.height);
|
39426 |
|
39427 | return {
|
39428 | x: -width / 2,
|
39429 | y: -height / 2,
|
39430 | width: width,
|
39431 | height: height
|
39432 | };
|
39433 | }
|
39434 |
|
39435 | function getParticipantCreateConstraints(shape, childrenBBox) {
|
39436 | childrenBBox = asTRBL(childrenBBox);
|
39437 |
|
39438 | return {
|
39439 | bottom: childrenBBox.top + shape.height / 2 - VERTICAL_PARTICIPANT_PADDING,
|
39440 | left: childrenBBox.right - shape.width / 2 + HORIZONTAL_PARTICIPANT_PADDING,
|
39441 | top: childrenBBox.bottom - shape.height / 2 + VERTICAL_PARTICIPANT_PADDING,
|
39442 | right: childrenBBox.left + shape.width / 2 - HORIZONTAL_PARTICIPANT_PADDING - PARTICIPANT_BORDER_WIDTH
|
39443 | };
|
39444 | }
|
39445 |
|
39446 | function isConnection$2(element) {
|
39447 | return !!element.waypoints;
|
39448 | }
|
39449 |
|
39450 | function findParticipant(elements) {
|
39451 | return find(elements, function(element) {
|
39452 | return is$1(element, 'bpmn:Participant');
|
39453 | });
|
39454 | }
|
39455 |
|
39456 | var TARGET_REF_PLACEHOLDER_NAME = '__targetRef_placeholder';
|
39457 |
|
39458 |
|
39459 | |
39460 |
|
39461 |
|
39462 |
|
39463 |
|
39464 |
|
39465 |
|
39466 |
|
39467 |
|
39468 |
|
39469 |
|
39470 |
|
39471 | function DataInputAssociationBehavior(eventBus, bpmnFactory) {
|
39472 |
|
39473 | CommandInterceptor.call(this, eventBus);
|
39474 |
|
39475 |
|
39476 | this.executed([
|
39477 | 'connection.create',
|
39478 | 'connection.delete',
|
39479 | 'connection.move',
|
39480 | 'connection.reconnect'
|
39481 | ], ifDataInputAssociation(fixTargetRef));
|
39482 |
|
39483 | this.reverted([
|
39484 | 'connection.create',
|
39485 | 'connection.delete',
|
39486 | 'connection.move',
|
39487 | 'connection.reconnect'
|
39488 | ], ifDataInputAssociation(fixTargetRef));
|
39489 |
|
39490 |
|
39491 | function usesTargetRef(element, targetRef, removedConnection) {
|
39492 |
|
39493 | var inputAssociations = element.get('dataInputAssociations');
|
39494 |
|
39495 | return find(inputAssociations, function(association) {
|
39496 | return association !== removedConnection &&
|
39497 | association.targetRef === targetRef;
|
39498 | });
|
39499 | }
|
39500 |
|
39501 | function getTargetRef(element, create) {
|
39502 |
|
39503 | var properties = element.get('properties');
|
39504 |
|
39505 | var targetRefProp = find(properties, function(p) {
|
39506 | return p.name === TARGET_REF_PLACEHOLDER_NAME;
|
39507 | });
|
39508 |
|
39509 | if (!targetRefProp && create) {
|
39510 | targetRefProp = bpmnFactory.create('bpmn:Property', {
|
39511 | name: TARGET_REF_PLACEHOLDER_NAME
|
39512 | });
|
39513 |
|
39514 | add$1(properties, targetRefProp);
|
39515 | }
|
39516 |
|
39517 | return targetRefProp;
|
39518 | }
|
39519 |
|
39520 | function cleanupTargetRef(element, connection) {
|
39521 |
|
39522 | var targetRefProp = getTargetRef(element);
|
39523 |
|
39524 | if (!targetRefProp) {
|
39525 | return;
|
39526 | }
|
39527 |
|
39528 | if (!usesTargetRef(element, targetRefProp, connection)) {
|
39529 | remove$2(element.get('properties'), targetRefProp);
|
39530 | }
|
39531 | }
|
39532 |
|
39533 | |
39534 |
|
39535 |
|
39536 |
|
39537 |
|
39538 |
|
39539 | function fixTargetRef(event) {
|
39540 |
|
39541 | var context = event.context,
|
39542 | connection = context.connection,
|
39543 | connectionBo = connection.businessObject,
|
39544 | target = connection.target,
|
39545 | targetBo = target && target.businessObject,
|
39546 | newTarget = context.newTarget,
|
39547 | newTargetBo = newTarget && newTarget.businessObject,
|
39548 | oldTarget = context.oldTarget || context.target,
|
39549 | oldTargetBo = oldTarget && oldTarget.businessObject;
|
39550 |
|
39551 | var dataAssociation = connection.businessObject,
|
39552 | targetRefProp;
|
39553 |
|
39554 | if (oldTargetBo && oldTargetBo !== targetBo) {
|
39555 | cleanupTargetRef(oldTargetBo, connectionBo);
|
39556 | }
|
39557 |
|
39558 | if (newTargetBo && newTargetBo !== targetBo) {
|
39559 | cleanupTargetRef(newTargetBo, connectionBo);
|
39560 | }
|
39561 |
|
39562 | if (targetBo) {
|
39563 | targetRefProp = getTargetRef(targetBo, true);
|
39564 | dataAssociation.targetRef = targetRefProp;
|
39565 | } else {
|
39566 | dataAssociation.targetRef = null;
|
39567 | }
|
39568 | }
|
39569 | }
|
39570 |
|
39571 | DataInputAssociationBehavior.$inject = [
|
39572 | 'eventBus',
|
39573 | 'bpmnFactory'
|
39574 | ];
|
39575 |
|
39576 | inherits_browser(DataInputAssociationBehavior, CommandInterceptor);
|
39577 |
|
39578 |
|
39579 | |
39580 |
|
39581 |
|
39582 |
|
39583 |
|
39584 |
|
39585 |
|
39586 | function ifDataInputAssociation(fn) {
|
39587 |
|
39588 | return function(event) {
|
39589 | var context = event.context,
|
39590 | connection = context.connection;
|
39591 |
|
39592 | if (is$1(connection, 'bpmn:DataInputAssociation')) {
|
39593 | return fn(event);
|
39594 | }
|
39595 | };
|
39596 | }
|
39597 |
|
39598 | function UpdateSemanticParentHandler(bpmnUpdater) {
|
39599 | this._bpmnUpdater = bpmnUpdater;
|
39600 | }
|
39601 |
|
39602 | UpdateSemanticParentHandler.$inject = [ 'bpmnUpdater' ];
|
39603 |
|
39604 |
|
39605 | UpdateSemanticParentHandler.prototype.execute = function(context) {
|
39606 | var dataStoreBo = context.dataStoreBo,
|
39607 | newSemanticParent = context.newSemanticParent,
|
39608 | newDiParent = context.newDiParent;
|
39609 |
|
39610 | context.oldSemanticParent = dataStoreBo.$parent;
|
39611 | context.oldDiParent = dataStoreBo.di.$parent;
|
39612 |
|
39613 |
|
39614 | this._bpmnUpdater.updateSemanticParent(dataStoreBo, newSemanticParent);
|
39615 |
|
39616 |
|
39617 | this._bpmnUpdater.updateDiParent(dataStoreBo.di, newDiParent);
|
39618 | };
|
39619 |
|
39620 | UpdateSemanticParentHandler.prototype.revert = function(context) {
|
39621 | var dataStoreBo = context.dataStoreBo,
|
39622 | oldSemanticParent = context.oldSemanticParent,
|
39623 | oldDiParent = context.oldDiParent;
|
39624 |
|
39625 |
|
39626 | this._bpmnUpdater.updateSemanticParent(dataStoreBo, oldSemanticParent);
|
39627 |
|
39628 |
|
39629 | this._bpmnUpdater.updateDiParent(dataStoreBo.di, oldDiParent);
|
39630 | };
|
39631 |
|
39632 | |
39633 |
|
39634 |
|
39635 | function DataStoreBehavior(
|
39636 | canvas, commandStack, elementRegistry,
|
39637 | eventBus) {
|
39638 |
|
39639 | CommandInterceptor.call(this, eventBus);
|
39640 |
|
39641 | commandStack.registerHandler('dataStore.updateContainment', UpdateSemanticParentHandler);
|
39642 |
|
39643 | function getFirstParticipant() {
|
39644 | return elementRegistry.filter(function(element) {
|
39645 | return is$1(element, 'bpmn:Participant');
|
39646 | })[0];
|
39647 | }
|
39648 |
|
39649 | function getDataStores(element) {
|
39650 | return element.children.filter(function(child) {
|
39651 | return is$1(child, 'bpmn:DataStoreReference') && !child.labelTarget;
|
39652 | });
|
39653 | }
|
39654 |
|
39655 | function updateDataStoreParent(dataStore, newDataStoreParent) {
|
39656 | var dataStoreBo = dataStore.businessObject || dataStore;
|
39657 |
|
39658 | newDataStoreParent = newDataStoreParent || getFirstParticipant();
|
39659 |
|
39660 | if (newDataStoreParent) {
|
39661 | var newDataStoreParentBo = newDataStoreParent.businessObject || newDataStoreParent;
|
39662 |
|
39663 | commandStack.execute('dataStore.updateContainment', {
|
39664 | dataStoreBo: dataStoreBo,
|
39665 | newSemanticParent: newDataStoreParentBo.processRef || newDataStoreParentBo,
|
39666 | newDiParent: newDataStoreParentBo.di
|
39667 | });
|
39668 | }
|
39669 | }
|
39670 |
|
39671 |
|
39672 |
|
39673 | this.preExecute('shape.create', function(event) {
|
39674 |
|
39675 | var context = event.context,
|
39676 | shape = context.shape;
|
39677 |
|
39678 | if (is$1(shape, 'bpmn:DataStoreReference') &&
|
39679 | shape.type !== 'label') {
|
39680 |
|
39681 | if (!context.hints) {
|
39682 | context.hints = {};
|
39683 | }
|
39684 |
|
39685 |
|
39686 | context.hints.autoResize = false;
|
39687 | }
|
39688 | });
|
39689 |
|
39690 |
|
39691 |
|
39692 | this.preExecute('elements.move', function(event) {
|
39693 | var context = event.context,
|
39694 | shapes = context.shapes;
|
39695 |
|
39696 | var dataStoreReferences = shapes.filter(function(shape) {
|
39697 | return is$1(shape, 'bpmn:DataStoreReference');
|
39698 | });
|
39699 |
|
39700 | if (dataStoreReferences.length) {
|
39701 | if (!context.hints) {
|
39702 | context.hints = {};
|
39703 | }
|
39704 |
|
39705 |
|
39706 | context.hints.autoResize = shapes.filter(function(shape) {
|
39707 | return !is$1(shape, 'bpmn:DataStoreReference');
|
39708 | });
|
39709 | }
|
39710 | });
|
39711 |
|
39712 |
|
39713 |
|
39714 | this.postExecute('shape.create', function(event) {
|
39715 | var context = event.context,
|
39716 | shape = context.shape,
|
39717 | parent = shape.parent;
|
39718 |
|
39719 |
|
39720 | if (is$1(shape, 'bpmn:DataStoreReference') &&
|
39721 | shape.type !== 'label' &&
|
39722 | is$1(parent, 'bpmn:Collaboration')) {
|
39723 |
|
39724 | updateDataStoreParent(shape);
|
39725 | }
|
39726 | });
|
39727 |
|
39728 |
|
39729 |
|
39730 | this.postExecute('shape.move', function(event) {
|
39731 | var context = event.context,
|
39732 | shape = context.shape,
|
39733 | oldParent = context.oldParent,
|
39734 | parent = shape.parent;
|
39735 |
|
39736 | if (is$1(oldParent, 'bpmn:Collaboration')) {
|
39737 |
|
39738 |
|
39739 | return;
|
39740 | }
|
39741 |
|
39742 | if (is$1(shape, 'bpmn:DataStoreReference') &&
|
39743 | shape.type !== 'label' &&
|
39744 | is$1(parent, 'bpmn:Collaboration')) {
|
39745 |
|
39746 | var participant = is$1(oldParent, 'bpmn:Participant') ?
|
39747 | oldParent :
|
39748 | getAncestor(oldParent, 'bpmn:Participant');
|
39749 |
|
39750 | updateDataStoreParent(shape, participant);
|
39751 | }
|
39752 | });
|
39753 |
|
39754 |
|
39755 |
|
39756 | this.postExecute('shape.delete', function(event) {
|
39757 | var context = event.context,
|
39758 | shape = context.shape,
|
39759 | rootElement = canvas.getRootElement();
|
39760 |
|
39761 | if (isAny(shape, [ 'bpmn:Participant', 'bpmn:SubProcess' ])
|
39762 | && is$1(rootElement, 'bpmn:Collaboration')) {
|
39763 | getDataStores(rootElement)
|
39764 | .filter(function(dataStore) {
|
39765 | return isDescendant(dataStore, shape);
|
39766 | })
|
39767 | .forEach(function(dataStore) {
|
39768 | updateDataStoreParent(dataStore);
|
39769 | });
|
39770 | }
|
39771 | });
|
39772 |
|
39773 |
|
39774 | this.postExecute('canvas.updateRoot', function(event) {
|
39775 | var context = event.context,
|
39776 | oldRoot = context.oldRoot,
|
39777 | newRoot = context.newRoot;
|
39778 |
|
39779 | var dataStores = getDataStores(oldRoot);
|
39780 |
|
39781 | dataStores.forEach(function(dataStore) {
|
39782 |
|
39783 | if (is$1(newRoot, 'bpmn:Process')) {
|
39784 | updateDataStoreParent(dataStore, newRoot);
|
39785 | }
|
39786 |
|
39787 | });
|
39788 | });
|
39789 | }
|
39790 |
|
39791 | DataStoreBehavior.$inject = [
|
39792 | 'canvas',
|
39793 | 'commandStack',
|
39794 | 'elementRegistry',
|
39795 | 'eventBus',
|
39796 | ];
|
39797 |
|
39798 | inherits_browser(DataStoreBehavior, CommandInterceptor);
|
39799 |
|
39800 |
|
39801 |
|
39802 |
|
39803 | function isDescendant(descendant, ancestor) {
|
39804 | var descendantBo = descendant.businessObject || descendant,
|
39805 | ancestorBo = ancestor.businessObject || ancestor;
|
39806 |
|
39807 | while (descendantBo.$parent) {
|
39808 | if (descendantBo.$parent === ancestorBo.processRef || ancestorBo) {
|
39809 | return true;
|
39810 | }
|
39811 |
|
39812 | descendantBo = descendantBo.$parent;
|
39813 | }
|
39814 |
|
39815 | return false;
|
39816 | }
|
39817 |
|
39818 | function getAncestor(element, type) {
|
39819 |
|
39820 | while (element.parent) {
|
39821 | if (is$1(element.parent, type)) {
|
39822 | return element.parent;
|
39823 | }
|
39824 |
|
39825 | element = element.parent;
|
39826 | }
|
39827 | }
|
39828 |
|
39829 | var LOW_PRIORITY$b = 500;
|
39830 |
|
39831 |
|
39832 | |
39833 |
|
39834 |
|
39835 | function DeleteLaneBehavior(eventBus, modeling, spaceTool) {
|
39836 |
|
39837 | CommandInterceptor.call(this, eventBus);
|
39838 |
|
39839 |
|
39840 | function compensateLaneDelete(shape, oldParent) {
|
39841 |
|
39842 | var siblings = getChildLanes(oldParent);
|
39843 |
|
39844 | var topAffected = [];
|
39845 | var bottomAffected = [];
|
39846 |
|
39847 | eachElement(siblings, function(element) {
|
39848 |
|
39849 | if (element.y > shape.y) {
|
39850 | bottomAffected.push(element);
|
39851 | } else {
|
39852 | topAffected.push(element);
|
39853 | }
|
39854 |
|
39855 | return element.children;
|
39856 | });
|
39857 |
|
39858 | if (!siblings.length) {
|
39859 | return;
|
39860 | }
|
39861 |
|
39862 | var offset;
|
39863 |
|
39864 | if (bottomAffected.length && topAffected.length) {
|
39865 | offset = shape.height / 2;
|
39866 | } else {
|
39867 | offset = shape.height;
|
39868 | }
|
39869 |
|
39870 | var topAdjustments,
|
39871 | bottomAdjustments;
|
39872 |
|
39873 | if (topAffected.length) {
|
39874 | topAdjustments = spaceTool.calculateAdjustments(
|
39875 | topAffected, 'y', offset, shape.y - 10);
|
39876 |
|
39877 | spaceTool.makeSpace(
|
39878 | topAdjustments.movingShapes,
|
39879 | topAdjustments.resizingShapes,
|
39880 | { x: 0, y: offset }, 's');
|
39881 | }
|
39882 |
|
39883 | if (bottomAffected.length) {
|
39884 | bottomAdjustments = spaceTool.calculateAdjustments(
|
39885 | bottomAffected, 'y', -offset, shape.y + shape.height + 10);
|
39886 |
|
39887 | spaceTool.makeSpace(
|
39888 | bottomAdjustments.movingShapes,
|
39889 | bottomAdjustments.resizingShapes,
|
39890 | { x: 0, y: -offset }, 'n');
|
39891 | }
|
39892 | }
|
39893 |
|
39894 |
|
39895 | |
39896 |
|
39897 |
|
39898 | this.postExecuted('shape.delete', LOW_PRIORITY$b, function(event) {
|
39899 |
|
39900 | var context = event.context,
|
39901 | hints = context.hints,
|
39902 | shape = context.shape,
|
39903 | oldParent = context.oldParent;
|
39904 |
|
39905 |
|
39906 | if (!is$1(shape, 'bpmn:Lane')) {
|
39907 | return;
|
39908 | }
|
39909 |
|
39910 |
|
39911 | if (hints && hints.nested) {
|
39912 | return;
|
39913 | }
|
39914 |
|
39915 | compensateLaneDelete(shape, oldParent);
|
39916 | });
|
39917 | }
|
39918 |
|
39919 | DeleteLaneBehavior.$inject = [
|
39920 | 'eventBus',
|
39921 | 'modeling',
|
39922 | 'spaceTool'
|
39923 | ];
|
39924 |
|
39925 | inherits_browser(DeleteLaneBehavior, CommandInterceptor);
|
39926 |
|
39927 | var LOW_PRIORITY$c = 500;
|
39928 |
|
39929 |
|
39930 | |
39931 |
|
39932 |
|
39933 | function DetachEventBehavior(bpmnReplace, injector) {
|
39934 | injector.invoke(CommandInterceptor, this);
|
39935 |
|
39936 | this._bpmnReplace = bpmnReplace;
|
39937 |
|
39938 | var self = this;
|
39939 |
|
39940 | this.postExecuted('elements.create', LOW_PRIORITY$c, function(context) {
|
39941 | var elements = context.elements;
|
39942 |
|
39943 | elements.filter(function(shape) {
|
39944 | var host = shape.host;
|
39945 |
|
39946 | return shouldReplace$1(shape, host);
|
39947 | }).map(function(shape) {
|
39948 | return elements.indexOf(shape);
|
39949 | }).forEach(function(index) {
|
39950 | context.elements[ index ] = self.replaceShape(elements[ index ]);
|
39951 | });
|
39952 | }, true);
|
39953 |
|
39954 | this.preExecute('elements.move', LOW_PRIORITY$c, function(context) {
|
39955 | var shapes = context.shapes,
|
39956 | newHost = context.newHost;
|
39957 |
|
39958 | shapes.forEach(function(shape, index) {
|
39959 | var host = shape.host;
|
39960 |
|
39961 | if (shouldReplace$1(shape, includes(shapes, host) ? host : newHost)) {
|
39962 | shapes[ index ] = self.replaceShape(shape);
|
39963 | }
|
39964 | });
|
39965 | }, true);
|
39966 | }
|
39967 |
|
39968 | DetachEventBehavior.$inject = [
|
39969 | 'bpmnReplace',
|
39970 | 'injector'
|
39971 | ];
|
39972 |
|
39973 | inherits_browser(DetachEventBehavior, CommandInterceptor);
|
39974 |
|
39975 | DetachEventBehavior.prototype.replaceShape = function(shape) {
|
39976 | var eventDefinition = getEventDefinition$1(shape),
|
39977 | intermediateEvent;
|
39978 |
|
39979 | if (eventDefinition) {
|
39980 | intermediateEvent = {
|
39981 | type: 'bpmn:IntermediateCatchEvent',
|
39982 | eventDefinitionType: eventDefinition.$type
|
39983 | };
|
39984 | } else {
|
39985 | intermediateEvent = {
|
39986 | type: 'bpmn:IntermediateThrowEvent'
|
39987 | };
|
39988 | }
|
39989 |
|
39990 | return this._bpmnReplace.replaceElement(shape, intermediateEvent, { layoutConnection: false });
|
39991 | };
|
39992 |
|
39993 |
|
39994 |
|
39995 |
|
39996 | function getEventDefinition$1(element) {
|
39997 | var businessObject = getBusinessObject(element),
|
39998 | eventDefinitions = businessObject.eventDefinitions;
|
39999 |
|
40000 | return eventDefinitions && eventDefinitions[0];
|
40001 | }
|
40002 |
|
40003 | function shouldReplace$1(shape, host) {
|
40004 | return !isLabel(shape) && is$1(shape, 'bpmn:BoundaryEvent') && !host;
|
40005 | }
|
40006 |
|
40007 | function includes(array, item) {
|
40008 | return array.indexOf(item) !== -1;
|
40009 | }
|
40010 |
|
40011 | function DropOnFlowBehavior(eventBus, bpmnRules, modeling) {
|
40012 |
|
40013 | CommandInterceptor.call(this, eventBus);
|
40014 |
|
40015 | |
40016 |
|
40017 |
|
40018 |
|
40019 |
|
40020 | function insertShape(shape, targetFlow, positionOrBounds) {
|
40021 | var waypoints = targetFlow.waypoints,
|
40022 | waypointsBefore,
|
40023 | waypointsAfter,
|
40024 | dockingPoint,
|
40025 | source,
|
40026 | target,
|
40027 | incomingConnection,
|
40028 | outgoingConnection,
|
40029 | oldOutgoing = shape.outgoing.slice(),
|
40030 | oldIncoming = shape.incoming.slice();
|
40031 |
|
40032 | var mid;
|
40033 |
|
40034 | if (isNumber(positionOrBounds.width)) {
|
40035 | mid = getMid(positionOrBounds);
|
40036 | } else {
|
40037 | mid = positionOrBounds;
|
40038 | }
|
40039 |
|
40040 | var intersection = getApproxIntersection(waypoints, mid);
|
40041 |
|
40042 | if (intersection) {
|
40043 | waypointsBefore = waypoints.slice(0, intersection.index);
|
40044 | waypointsAfter = waypoints.slice(intersection.index + (intersection.bendpoint ? 1 : 0));
|
40045 |
|
40046 |
|
40047 | if (!waypointsBefore.length || !waypointsAfter.length) {
|
40048 | return;
|
40049 | }
|
40050 |
|
40051 | dockingPoint = intersection.bendpoint ? waypoints[intersection.index] : mid;
|
40052 |
|
40053 |
|
40054 | if (!isPointInsideBBox$2(shape, waypointsBefore[waypointsBefore.length-1])) {
|
40055 | waypointsBefore.push(copy(dockingPoint));
|
40056 | }
|
40057 |
|
40058 |
|
40059 | if (!isPointInsideBBox$2(shape, waypointsAfter[0])) {
|
40060 | waypointsAfter.unshift(copy(dockingPoint));
|
40061 | }
|
40062 | }
|
40063 |
|
40064 | source = targetFlow.source;
|
40065 | target = targetFlow.target;
|
40066 |
|
40067 | if (bpmnRules.canConnect(source, shape, targetFlow)) {
|
40068 |
|
40069 |
|
40070 | modeling.reconnectEnd(targetFlow, shape, waypointsBefore || mid);
|
40071 |
|
40072 | incomingConnection = targetFlow;
|
40073 | }
|
40074 |
|
40075 | if (bpmnRules.canConnect(shape, target, targetFlow)) {
|
40076 |
|
40077 | if (!incomingConnection) {
|
40078 |
|
40079 |
|
40080 | modeling.reconnectStart(targetFlow, shape, waypointsAfter || mid);
|
40081 |
|
40082 | outgoingConnection = targetFlow;
|
40083 | } else {
|
40084 | outgoingConnection = modeling.connect(
|
40085 | shape, target, { type: targetFlow.type, waypoints: waypointsAfter }
|
40086 | );
|
40087 | }
|
40088 | }
|
40089 |
|
40090 | var duplicateConnections = [].concat(
|
40091 |
|
40092 | incomingConnection && filter(oldIncoming, function(connection) {
|
40093 | return connection.source === incomingConnection.source;
|
40094 | }) || [],
|
40095 |
|
40096 | outgoingConnection && filter(oldOutgoing, function(connection) {
|
40097 | return connection.source === outgoingConnection.source;
|
40098 | }) || []
|
40099 | );
|
40100 |
|
40101 | if (duplicateConnections.length) {
|
40102 | modeling.removeElements(duplicateConnections);
|
40103 | }
|
40104 | }
|
40105 |
|
40106 | this.preExecute('elements.move', function(context) {
|
40107 |
|
40108 | var newParent = context.newParent,
|
40109 | shapes = context.shapes,
|
40110 | delta = context.delta,
|
40111 | shape = shapes[0];
|
40112 |
|
40113 | if (!shape || !newParent) {
|
40114 | return;
|
40115 | }
|
40116 |
|
40117 |
|
40118 |
|
40119 | if (newParent && newParent.waypoints) {
|
40120 | context.newParent = newParent = newParent.parent;
|
40121 | }
|
40122 |
|
40123 | var shapeMid = getMid(shape);
|
40124 | var newShapeMid = {
|
40125 | x: shapeMid.x + delta.x,
|
40126 | y: shapeMid.y + delta.y
|
40127 | };
|
40128 |
|
40129 |
|
40130 |
|
40131 | var connection = find(newParent.children, function(element) {
|
40132 | var canInsert = bpmnRules.canInsert(shapes, element);
|
40133 |
|
40134 | return canInsert && getApproxIntersection(element.waypoints, newShapeMid);
|
40135 | });
|
40136 |
|
40137 | if (connection) {
|
40138 | context.targetFlow = connection;
|
40139 | context.position = newShapeMid;
|
40140 | }
|
40141 |
|
40142 | }, true);
|
40143 |
|
40144 | this.postExecuted('elements.move', function(context) {
|
40145 |
|
40146 | var shapes = context.shapes,
|
40147 | targetFlow = context.targetFlow,
|
40148 | position = context.position;
|
40149 |
|
40150 | if (targetFlow) {
|
40151 | insertShape(shapes[0], targetFlow, position);
|
40152 | }
|
40153 |
|
40154 | }, true);
|
40155 |
|
40156 | this.preExecute('shape.create', function(context) {
|
40157 |
|
40158 | var parent = context.parent,
|
40159 | shape = context.shape;
|
40160 |
|
40161 | if (bpmnRules.canInsert(shape, parent)) {
|
40162 | context.targetFlow = parent;
|
40163 | context.parent = parent.parent;
|
40164 | }
|
40165 | }, true);
|
40166 |
|
40167 | this.postExecuted('shape.create', function(context) {
|
40168 |
|
40169 | var shape = context.shape,
|
40170 | targetFlow = context.targetFlow,
|
40171 | positionOrBounds = context.position;
|
40172 |
|
40173 | if (targetFlow) {
|
40174 | insertShape(shape, targetFlow, positionOrBounds);
|
40175 | }
|
40176 | }, true);
|
40177 | }
|
40178 |
|
40179 | inherits_browser(DropOnFlowBehavior, CommandInterceptor);
|
40180 |
|
40181 | DropOnFlowBehavior.$inject = [
|
40182 | 'eventBus',
|
40183 | 'bpmnRules',
|
40184 | 'modeling'
|
40185 | ];
|
40186 |
|
40187 |
|
40188 |
|
40189 |
|
40190 | function isPointInsideBBox$2(bbox, point) {
|
40191 | var x = point.x,
|
40192 | y = point.y;
|
40193 |
|
40194 | return x >= bbox.x &&
|
40195 | x <= bbox.x + bbox.width &&
|
40196 | y >= bbox.y &&
|
40197 | y <= bbox.y + bbox.height;
|
40198 | }
|
40199 |
|
40200 | function copy(obj) {
|
40201 | return assign({}, obj);
|
40202 | }
|
40203 |
|
40204 | function EventBasedGatewayBehavior(eventBus, modeling) {
|
40205 |
|
40206 | CommandInterceptor.call(this, eventBus);
|
40207 |
|
40208 | |
40209 |
|
40210 |
|
40211 |
|
40212 | this.preExecuted('connection.create', function(event) {
|
40213 |
|
40214 | var context = event.context,
|
40215 | source = context.source,
|
40216 | target = context.target,
|
40217 | existingIncomingConnections = target.incoming.slice();
|
40218 |
|
40219 | if (context.hints && context.hints.createElementsBehavior === false) {
|
40220 | return;
|
40221 | }
|
40222 |
|
40223 | if (
|
40224 | is$1(source, 'bpmn:EventBasedGateway') &&
|
40225 | target.incoming.length
|
40226 | ) {
|
40227 |
|
40228 | existingIncomingConnections.filter(isSequenceFlow)
|
40229 | .forEach(function(sequenceFlow) {
|
40230 | modeling.removeConnection(sequenceFlow);
|
40231 | });
|
40232 | }
|
40233 | });
|
40234 |
|
40235 | |
40236 |
|
40237 |
|
40238 |
|
40239 |
|
40240 | this.preExecuted('shape.replace', function(event) {
|
40241 |
|
40242 | var newShape = event.context.newShape,
|
40243 | newShapeTargets,
|
40244 | newShapeTargetsIncomingSequenceFlows;
|
40245 |
|
40246 | if (!is$1(newShape, 'bpmn:EventBasedGateway')) {
|
40247 | return;
|
40248 | }
|
40249 |
|
40250 | newShapeTargets = newShape.outgoing.filter(isSequenceFlow)
|
40251 | .map(function(sequenceFlow) {
|
40252 | return sequenceFlow.target;
|
40253 | });
|
40254 |
|
40255 | newShapeTargetsIncomingSequenceFlows = newShapeTargets.reduce(function(sequenceFlows, target) {
|
40256 | var incomingSequenceFlows = target.incoming.filter(isSequenceFlow);
|
40257 |
|
40258 | return sequenceFlows.concat(incomingSequenceFlows);
|
40259 | }, []);
|
40260 |
|
40261 | newShapeTargetsIncomingSequenceFlows.forEach(function(sequenceFlow) {
|
40262 | if (sequenceFlow.source !== newShape) {
|
40263 | modeling.removeConnection(sequenceFlow);
|
40264 | }
|
40265 | });
|
40266 | });
|
40267 | }
|
40268 |
|
40269 | EventBasedGatewayBehavior.$inject = [
|
40270 | 'eventBus',
|
40271 | 'modeling'
|
40272 | ];
|
40273 |
|
40274 | inherits_browser(EventBasedGatewayBehavior, CommandInterceptor);
|
40275 |
|
40276 |
|
40277 |
|
40278 |
|
40279 |
|
40280 | function isSequenceFlow(connection) {
|
40281 | return is$1(connection, 'bpmn:SequenceFlow');
|
40282 | }
|
40283 |
|
40284 | var HIGH_PRIORITY$8 = 2000;
|
40285 |
|
40286 |
|
40287 | |
40288 |
|
40289 |
|
40290 | function GroupBehavior(
|
40291 | bpmnFactory,
|
40292 | canvas,
|
40293 | elementRegistry,
|
40294 | eventBus,
|
40295 | injector,
|
40296 | moddleCopy
|
40297 | ) {
|
40298 | injector.invoke(CommandInterceptor, this);
|
40299 |
|
40300 | |
40301 |
|
40302 |
|
40303 |
|
40304 |
|
40305 | function getDefinitions() {
|
40306 | var rootElement = canvas.getRootElement(),
|
40307 | businessObject = getBusinessObject(rootElement);
|
40308 |
|
40309 | return businessObject.$parent;
|
40310 | }
|
40311 |
|
40312 | |
40313 |
|
40314 |
|
40315 |
|
40316 |
|
40317 | function removeReferencedCategoryValue(shape) {
|
40318 |
|
40319 | var businessObject = getBusinessObject(shape),
|
40320 | categoryValue = businessObject.categoryValueRef;
|
40321 |
|
40322 | if (!categoryValue) {
|
40323 | return;
|
40324 | }
|
40325 |
|
40326 | var category = categoryValue.$parent;
|
40327 |
|
40328 | if (!categoryValue) {
|
40329 | return;
|
40330 | }
|
40331 |
|
40332 | remove$2(category.categoryValue, categoryValue);
|
40333 |
|
40334 |
|
40335 | if (category && !category.categoryValue.length) {
|
40336 | removeCategory(category);
|
40337 | }
|
40338 | }
|
40339 |
|
40340 | |
40341 |
|
40342 |
|
40343 |
|
40344 |
|
40345 | function removeCategory(category) {
|
40346 |
|
40347 | var definitions = getDefinitions();
|
40348 |
|
40349 | remove$2(definitions.get('rootElements'), category);
|
40350 | }
|
40351 |
|
40352 | |
40353 |
|
40354 |
|
40355 |
|
40356 |
|
40357 | function getGroupElements() {
|
40358 | return elementRegistry.filter(function(e) {
|
40359 | return is$1(e, 'bpmn:Group');
|
40360 | });
|
40361 | }
|
40362 |
|
40363 | |
40364 |
|
40365 |
|
40366 |
|
40367 |
|
40368 |
|
40369 |
|
40370 | function isReferenced(elements, categoryValue) {
|
40371 | return elements.some(function(e) {
|
40372 |
|
40373 | var businessObject = getBusinessObject(e);
|
40374 |
|
40375 | return businessObject.categoryValueRef
|
40376 | && businessObject.categoryValueRef === categoryValue;
|
40377 | });
|
40378 | }
|
40379 |
|
40380 | |
40381 |
|
40382 |
|
40383 | this.executed('shape.delete', function(event) {
|
40384 |
|
40385 | var context = event.context,
|
40386 | shape = context.shape;
|
40387 |
|
40388 | if (is$1(shape, 'bpmn:Group')) {
|
40389 |
|
40390 | var businessObject = getBusinessObject(shape),
|
40391 | categoryValueRef = businessObject.categoryValueRef,
|
40392 | groupElements = getGroupElements();
|
40393 |
|
40394 | if (!isReferenced(groupElements, categoryValueRef)) {
|
40395 | removeReferencedCategoryValue(shape);
|
40396 | }
|
40397 | }
|
40398 | });
|
40399 |
|
40400 | |
40401 |
|
40402 |
|
40403 | this.reverted('shape.delete', function(event) {
|
40404 |
|
40405 | var context = event.context,
|
40406 | shape = context.shape;
|
40407 |
|
40408 | if (is$1(shape, 'bpmn:Group')) {
|
40409 |
|
40410 | var businessObject = getBusinessObject(shape),
|
40411 | categoryValueRef = businessObject.categoryValueRef,
|
40412 | definitions = getDefinitions(),
|
40413 | category = categoryValueRef ? categoryValueRef.$parent : null;
|
40414 |
|
40415 | add$1(category.get('categoryValue'), categoryValueRef);
|
40416 | add$1(definitions.get('rootElements'), category);
|
40417 | }
|
40418 | });
|
40419 |
|
40420 | |
40421 |
|
40422 |
|
40423 | this.execute('shape.create', function(event) {
|
40424 | var context = event.context,
|
40425 | shape = context.shape,
|
40426 | businessObject = getBusinessObject(shape);
|
40427 |
|
40428 | if (is$1(businessObject, 'bpmn:Group') && !businessObject.categoryValueRef) {
|
40429 |
|
40430 | var definitions = getDefinitions(),
|
40431 | categoryValue = createCategoryValue(definitions, bpmnFactory);
|
40432 |
|
40433 |
|
40434 | businessObject.categoryValueRef = categoryValue;
|
40435 | }
|
40436 | });
|
40437 |
|
40438 |
|
40439 | this.revert('shape.create', function(event) {
|
40440 |
|
40441 | var context = event.context,
|
40442 | shape = context.shape;
|
40443 |
|
40444 | if (is$1(shape, 'bpmn:Group')) {
|
40445 | removeReferencedCategoryValue(shape);
|
40446 |
|
40447 | delete getBusinessObject(shape).categoryValueRef;
|
40448 |
|
40449 | }
|
40450 | });
|
40451 |
|
40452 |
|
40453 | eventBus.on('moddleCopy.canCopyProperty', HIGH_PRIORITY$8, function(context) {
|
40454 | var property = context.property,
|
40455 | categoryValue;
|
40456 |
|
40457 | if (is$1(property, 'bpmn:CategoryValue')) {
|
40458 | categoryValue = createCategoryValue(getDefinitions(), bpmnFactory);
|
40459 |
|
40460 |
|
40461 | return moddleCopy.copyElement(property, categoryValue);
|
40462 | }
|
40463 | });
|
40464 |
|
40465 | }
|
40466 |
|
40467 | GroupBehavior.$inject = [
|
40468 | 'bpmnFactory',
|
40469 | 'canvas',
|
40470 | 'elementRegistry',
|
40471 | 'eventBus',
|
40472 | 'injector',
|
40473 | 'moddleCopy'
|
40474 | ];
|
40475 |
|
40476 | inherits_browser(GroupBehavior, CommandInterceptor);
|
40477 |
|
40478 | |
40479 |
|
40480 |
|
40481 |
|
40482 |
|
40483 |
|
40484 |
|
40485 |
|
40486 |
|
40487 |
|
40488 | function lineIntersect(l1s, l1e, l2s, l2e) {
|
40489 |
|
40490 |
|
40491 |
|
40492 |
|
40493 | var denominator, a, b, c, numerator;
|
40494 |
|
40495 | denominator = ((l2e.y - l2s.y) * (l1e.x - l1s.x)) - ((l2e.x - l2s.x) * (l1e.y - l1s.y));
|
40496 |
|
40497 | if (denominator == 0) {
|
40498 | return null;
|
40499 | }
|
40500 |
|
40501 | a = l1s.y - l2s.y;
|
40502 | b = l1s.x - l2s.x;
|
40503 | numerator = ((l2e.x - l2s.x) * a) - ((l2e.y - l2s.y) * b);
|
40504 |
|
40505 | c = numerator / denominator;
|
40506 |
|
40507 |
|
40508 |
|
40509 | return {
|
40510 | x: Math.round(l1s.x + (c * (l1e.x - l1s.x))),
|
40511 | y: Math.round(l1s.y + (c * (l1e.y - l1s.y)))
|
40512 | };
|
40513 | }
|
40514 |
|
40515 | |
40516 |
|
40517 |
|
40518 |
|
40519 |
|
40520 | function ImportDockingFix(eventBus) {
|
40521 |
|
40522 | function adjustDocking(startPoint, nextPoint, elementMid) {
|
40523 |
|
40524 | var elementTop = {
|
40525 | x: elementMid.x,
|
40526 | y: elementMid.y - 50
|
40527 | };
|
40528 |
|
40529 | var elementLeft = {
|
40530 | x: elementMid.x - 50,
|
40531 | y: elementMid.y
|
40532 | };
|
40533 |
|
40534 | var verticalIntersect = lineIntersect(startPoint, nextPoint, elementMid, elementTop),
|
40535 | horizontalIntersect = lineIntersect(startPoint, nextPoint, elementMid, elementLeft);
|
40536 |
|
40537 |
|
40538 | var centerIntersect;
|
40539 |
|
40540 | if (verticalIntersect && horizontalIntersect) {
|
40541 | if (getDistance(verticalIntersect, elementMid) > getDistance(horizontalIntersect, elementMid)) {
|
40542 | centerIntersect = horizontalIntersect;
|
40543 | } else {
|
40544 | centerIntersect = verticalIntersect;
|
40545 | }
|
40546 | } else {
|
40547 | centerIntersect = verticalIntersect || horizontalIntersect;
|
40548 | }
|
40549 |
|
40550 | startPoint.original = centerIntersect;
|
40551 | }
|
40552 |
|
40553 | function fixDockings(connection) {
|
40554 | var waypoints = connection.waypoints;
|
40555 |
|
40556 | adjustDocking(
|
40557 | waypoints[0],
|
40558 | waypoints[1],
|
40559 | getMid(connection.source)
|
40560 | );
|
40561 |
|
40562 | adjustDocking(
|
40563 | waypoints[waypoints.length - 1],
|
40564 | waypoints[waypoints.length - 2],
|
40565 | getMid(connection.target)
|
40566 | );
|
40567 | }
|
40568 |
|
40569 | eventBus.on('bpmnElement.added', function(e) {
|
40570 |
|
40571 | var element = e.element;
|
40572 |
|
40573 | if (element.waypoints) {
|
40574 | fixDockings(element);
|
40575 | }
|
40576 | });
|
40577 | }
|
40578 |
|
40579 | ImportDockingFix.$inject = [
|
40580 | 'eventBus'
|
40581 | ];
|
40582 |
|
40583 |
|
40584 |
|
40585 |
|
40586 | function getDistance(p1, p2) {
|
40587 | return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
|
40588 | }
|
40589 |
|
40590 | |
40591 |
|
40592 |
|
40593 |
|
40594 |
|
40595 |
|
40596 | function IsHorizontalFix(eventBus) {
|
40597 |
|
40598 | CommandInterceptor.call(this, eventBus);
|
40599 |
|
40600 | var elementTypesToUpdate = [
|
40601 | 'bpmn:Participant',
|
40602 | 'bpmn:Lane'
|
40603 | ];
|
40604 |
|
40605 | this.executed([ 'shape.move', 'shape.create', 'shape.resize' ], function(event) {
|
40606 | var bo = getBusinessObject(event.context.shape);
|
40607 |
|
40608 | if (isAny(bo, elementTypesToUpdate) && !bo.di.get('isHorizontal')) {
|
40609 |
|
40610 |
|
40611 | bo.di.set('isHorizontal', true);
|
40612 | }
|
40613 | });
|
40614 |
|
40615 | }
|
40616 |
|
40617 | IsHorizontalFix.$inject = [ 'eventBus' ];
|
40618 |
|
40619 | inherits_browser(IsHorizontalFix, CommandInterceptor);
|
40620 |
|
40621 | |
40622 |
|
40623 |
|
40624 |
|
40625 |
|
40626 |
|
40627 | function vectorLength(v) {
|
40628 | return Math.sqrt(Math.pow(v.x, 2) + Math.pow(v.y, 2));
|
40629 | }
|
40630 |
|
40631 |
|
40632 | |
40633 |
|
40634 |
|
40635 |
|
40636 |
|
40637 |
|
40638 | function getAngle(line) {
|
40639 |
|
40640 |
|
40641 |
|
40642 | return Math.atan((line[1].y - line[0].y) / (line[1].x - line[0].x));
|
40643 | }
|
40644 |
|
40645 |
|
40646 | |
40647 |
|
40648 |
|
40649 |
|
40650 |
|
40651 |
|
40652 |
|
40653 | function rotateVector(vector, angle) {
|
40654 | return (!angle) ? vector : {
|
40655 | x: Math.cos(angle) * vector.x - Math.sin(angle) * vector.y,
|
40656 | y: Math.sin(angle) * vector.x + Math.cos(angle) * vector.y
|
40657 | };
|
40658 | }
|
40659 |
|
40660 |
|
40661 | |
40662 |
|
40663 |
|
40664 |
|
40665 |
|
40666 |
|
40667 |
|
40668 |
|
40669 |
|
40670 | function solveLambaSystem(a, b, c) {
|
40671 |
|
40672 |
|
40673 | var system = [
|
40674 | { n: a[0] - c[0], lambda: b[0] },
|
40675 | { n: a[1] - c[1], lambda: b[1] }
|
40676 | ];
|
40677 |
|
40678 |
|
40679 | var n = system[0].n * b[0] + system[1].n * b[1],
|
40680 | l = system[0].lambda * b[0] + system[1].lambda * b[1];
|
40681 |
|
40682 | return -n/l;
|
40683 | }
|
40684 |
|
40685 |
|
40686 | |
40687 |
|
40688 |
|
40689 |
|
40690 |
|
40691 |
|
40692 |
|
40693 | function perpendicularFoot(point, line) {
|
40694 |
|
40695 | var a = line[0], b = line[1];
|
40696 |
|
40697 |
|
40698 | var bd = { x: b.x - a.x, y: b.y - a.y };
|
40699 |
|
40700 |
|
40701 | var r = solveLambaSystem([ a.x, a.y ], [ bd.x, bd.y ], [ point.x, point.y ]);
|
40702 |
|
40703 | return { x: a.x + r*bd.x, y: a.y + r*bd.y };
|
40704 | }
|
40705 |
|
40706 |
|
40707 | |
40708 |
|
40709 |
|
40710 |
|
40711 |
|
40712 |
|
40713 |
|
40714 | function getDistancePointLine(point, line) {
|
40715 |
|
40716 | var pfPoint = perpendicularFoot(point, line);
|
40717 |
|
40718 |
|
40719 | var connectionVector = {
|
40720 | x: pfPoint.x - point.x,
|
40721 | y: pfPoint.y - point.y
|
40722 | };
|
40723 |
|
40724 | return vectorLength(connectionVector);
|
40725 | }
|
40726 |
|
40727 |
|
40728 | |
40729 |
|
40730 |
|
40731 |
|
40732 |
|
40733 |
|
40734 |
|
40735 | function getDistancePointPoint(point1, point2) {
|
40736 |
|
40737 | return vectorLength({
|
40738 | x: point1.x - point2.x,
|
40739 | y: point1.y - point2.y
|
40740 | });
|
40741 | }
|
40742 |
|
40743 | var sqrt = Math.sqrt,
|
40744 | min$2 = Math.min,
|
40745 | max$3 = Math.max,
|
40746 | abs$4 = Math.abs;
|
40747 |
|
40748 | |
40749 |
|
40750 |
|
40751 |
|
40752 |
|
40753 |
|
40754 |
|
40755 | function sq(n) {
|
40756 | return Math.pow(n, 2);
|
40757 | }
|
40758 |
|
40759 | |
40760 |
|
40761 |
|
40762 |
|
40763 |
|
40764 |
|
40765 |
|
40766 |
|
40767 | function getDistance$1(p1, p2) {
|
40768 | return sqrt(sq(p1.x - p2.x) + sq(p1.y - p2.y));
|
40769 | }
|
40770 |
|
40771 | |
40772 |
|
40773 |
|
40774 |
|
40775 |
|
40776 |
|
40777 |
|
40778 |
|
40779 |
|
40780 |
|
40781 |
|
40782 |
|
40783 |
|
40784 |
|
40785 |
|
40786 |
|
40787 |
|
40788 |
|
40789 |
|
40790 |
|
40791 |
|
40792 |
|
40793 |
|
40794 |
|
40795 |
|
40796 |
|
40797 | function getAttachment(point, line) {
|
40798 |
|
40799 | var idx = 0,
|
40800 | segmentStart,
|
40801 | segmentEnd,
|
40802 | segmentStartDistance,
|
40803 | segmentEndDistance,
|
40804 | attachmentPosition,
|
40805 | minDistance,
|
40806 | intersections,
|
40807 | attachment,
|
40808 | attachmentDistance,
|
40809 | closestAttachmentDistance,
|
40810 | closestAttachment;
|
40811 |
|
40812 | for (idx = 0; idx < line.length - 1; idx++) {
|
40813 |
|
40814 | segmentStart = line[idx];
|
40815 | segmentEnd = line[idx + 1];
|
40816 |
|
40817 | if (pointsEqual(segmentStart, segmentEnd)) {
|
40818 | intersections = [ segmentStart ];
|
40819 | } else {
|
40820 | segmentStartDistance = getDistance$1(point, segmentStart);
|
40821 | segmentEndDistance = getDistance$1(point, segmentEnd);
|
40822 |
|
40823 | minDistance = min$2(segmentStartDistance, segmentEndDistance);
|
40824 |
|
40825 | intersections = getCircleSegmentIntersections(segmentStart, segmentEnd, point, minDistance);
|
40826 | }
|
40827 |
|
40828 | if (intersections.length < 1) {
|
40829 | throw new Error('expected between [1, 2] circle -> line intersections');
|
40830 | }
|
40831 |
|
40832 |
|
40833 | if (intersections.length === 1) {
|
40834 | attachment = {
|
40835 | type: 'bendpoint',
|
40836 | position: intersections[0],
|
40837 | segmentIndex: idx,
|
40838 | bendpointIndex: pointsEqual(segmentStart, intersections[0]) ? idx : idx + 1
|
40839 | };
|
40840 | }
|
40841 |
|
40842 |
|
40843 | if (intersections.length === 2) {
|
40844 |
|
40845 | attachmentPosition = mid$1(intersections[0], intersections[1]);
|
40846 |
|
40847 | attachment = {
|
40848 | type: 'segment',
|
40849 | position: attachmentPosition,
|
40850 | segmentIndex: idx,
|
40851 | relativeLocation: getDistance$1(segmentStart, attachmentPosition) / getDistance$1(segmentStart, segmentEnd)
|
40852 | };
|
40853 | }
|
40854 |
|
40855 | attachmentDistance = getDistance$1(attachment.position, point);
|
40856 |
|
40857 | if (!closestAttachment || closestAttachmentDistance > attachmentDistance) {
|
40858 | closestAttachment = attachment;
|
40859 | closestAttachmentDistance = attachmentDistance;
|
40860 | }
|
40861 | }
|
40862 |
|
40863 | return closestAttachment;
|
40864 | }
|
40865 |
|
40866 | |
40867 |
|
40868 |
|
40869 |
|
40870 |
|
40871 |
|
40872 |
|
40873 |
|
40874 |
|
40875 |
|
40876 | function getCircleSegmentIntersections(s1, s2, cc, cr) {
|
40877 |
|
40878 | var baX = s2.x - s1.x;
|
40879 | var baY = s2.y - s1.y;
|
40880 | var caX = cc.x - s1.x;
|
40881 | var caY = cc.y - s1.y;
|
40882 |
|
40883 | var a = baX * baX + baY * baY;
|
40884 | var bBy2 = baX * caX + baY * caY;
|
40885 | var c = caX * caX + caY * caY - cr * cr;
|
40886 |
|
40887 | var pBy2 = bBy2 / a;
|
40888 | var q = c / a;
|
40889 |
|
40890 | var disc = pBy2 * pBy2 - q;
|
40891 |
|
40892 |
|
40893 |
|
40894 |
|
40895 | if (disc < 0 && disc > -0.000001) {
|
40896 | disc = 0;
|
40897 | }
|
40898 |
|
40899 | if (disc < 0) {
|
40900 | return [];
|
40901 | }
|
40902 |
|
40903 |
|
40904 | var tmpSqrt = sqrt(disc);
|
40905 | var abScalingFactor1 = -pBy2 + tmpSqrt;
|
40906 | var abScalingFactor2 = -pBy2 - tmpSqrt;
|
40907 |
|
40908 | var i1 = {
|
40909 | x: s1.x - baX * abScalingFactor1,
|
40910 | y: s1.y - baY * abScalingFactor1
|
40911 | };
|
40912 |
|
40913 | if (disc === 0) {
|
40914 | return [ i1 ];
|
40915 | }
|
40916 |
|
40917 | var i2 = {
|
40918 | x: s1.x - baX * abScalingFactor2,
|
40919 | y: s1.y - baY * abScalingFactor2
|
40920 | };
|
40921 |
|
40922 |
|
40923 | return [ i1, i2 ].filter(function(p) {
|
40924 | return isPointInSegment(p, s1, s2);
|
40925 | });
|
40926 | }
|
40927 |
|
40928 |
|
40929 | function isPointInSegment(p, segmentStart, segmentEnd) {
|
40930 | return (
|
40931 | fenced(p.x, segmentStart.x, segmentEnd.x) &&
|
40932 | fenced(p.y, segmentStart.y, segmentEnd.y)
|
40933 | );
|
40934 | }
|
40935 |
|
40936 | function fenced(n, rangeStart, rangeEnd) {
|
40937 |
|
40938 |
|
40939 |
|
40940 |
|
40941 | return (
|
40942 | n >= min$2(rangeStart, rangeEnd) - EQUAL_THRESHOLD &&
|
40943 | n <= max$3(rangeStart, rangeEnd) + EQUAL_THRESHOLD
|
40944 | );
|
40945 | }
|
40946 |
|
40947 | |
40948 |
|
40949 |
|
40950 |
|
40951 |
|
40952 |
|
40953 |
|
40954 |
|
40955 | function mid$1(p1, p2) {
|
40956 |
|
40957 | return {
|
40958 | x: (p1.x + p2.x) / 2,
|
40959 | y: (p1.y + p2.y) / 2
|
40960 | };
|
40961 | }
|
40962 |
|
40963 | var EQUAL_THRESHOLD = 0.1;
|
40964 |
|
40965 | function pointsEqual(p1, p2) {
|
40966 |
|
40967 | return (
|
40968 | abs$4(p1.x - p2.x) <= EQUAL_THRESHOLD &&
|
40969 | abs$4(p1.y - p2.y) <= EQUAL_THRESHOLD
|
40970 | );
|
40971 | }
|
40972 |
|
40973 | function findNewLabelLineStartIndex(oldWaypoints, newWaypoints, attachment, hints) {
|
40974 |
|
40975 | var index = attachment.segmentIndex;
|
40976 |
|
40977 | var offset = newWaypoints.length - oldWaypoints.length;
|
40978 |
|
40979 |
|
40980 | if (hints.segmentMove) {
|
40981 |
|
40982 | var oldSegmentStartIndex = hints.segmentMove.segmentStartIndex,
|
40983 | newSegmentStartIndex = hints.segmentMove.newSegmentStartIndex;
|
40984 |
|
40985 |
|
40986 | if (index === oldSegmentStartIndex) {
|
40987 | return newSegmentStartIndex;
|
40988 | }
|
40989 |
|
40990 |
|
40991 | if (index >= newSegmentStartIndex) {
|
40992 | return (index+offset < newSegmentStartIndex) ? newSegmentStartIndex : index+offset;
|
40993 | }
|
40994 |
|
40995 |
|
40996 | return index;
|
40997 | }
|
40998 |
|
40999 |
|
41000 | if (hints.bendpointMove) {
|
41001 |
|
41002 | var insert = hints.bendpointMove.insert,
|
41003 | bendpointIndex = hints.bendpointMove.bendpointIndex,
|
41004 | newIndex;
|
41005 |
|
41006 |
|
41007 | if (offset === 0) {
|
41008 | return index;
|
41009 | }
|
41010 |
|
41011 |
|
41012 | if (index >= bendpointIndex) {
|
41013 | newIndex = insert ? index + 1 : index - 1;
|
41014 | }
|
41015 |
|
41016 |
|
41017 | if (index < bendpointIndex) {
|
41018 |
|
41019 | newIndex = index;
|
41020 |
|
41021 |
|
41022 | if (insert && attachment.type !== 'bendpoint' && bendpointIndex-1 === index) {
|
41023 |
|
41024 | var rel = relativePositionMidWaypoint(newWaypoints, bendpointIndex);
|
41025 |
|
41026 | if (rel < attachment.relativeLocation) {
|
41027 | newIndex++;
|
41028 | }
|
41029 | }
|
41030 | }
|
41031 |
|
41032 | return newIndex;
|
41033 | }
|
41034 |
|
41035 |
|
41036 | if (offset === 0) {
|
41037 | return index;
|
41038 | }
|
41039 |
|
41040 | if (hints.connectionStart) {
|
41041 | return (index === 0) ? 0 : null;
|
41042 | }
|
41043 |
|
41044 | if (hints.connectionEnd) {
|
41045 | return (index === oldWaypoints.length - 2) ? newWaypoints.length - 2 : null;
|
41046 | }
|
41047 |
|
41048 |
|
41049 | return null;
|
41050 | }
|
41051 |
|
41052 |
|
41053 | |
41054 |
|
41055 |
|
41056 |
|
41057 |
|
41058 |
|
41059 |
|
41060 |
|
41061 |
|
41062 |
|
41063 |
|
41064 | function getLabelAdjustment(label, newWaypoints, oldWaypoints, hints) {
|
41065 |
|
41066 | var x = 0,
|
41067 | y = 0;
|
41068 |
|
41069 | var labelPosition = getLabelMid(label);
|
41070 |
|
41071 |
|
41072 | var attachment = getAttachment(labelPosition, oldWaypoints),
|
41073 | oldLabelLineIndex = attachment.segmentIndex,
|
41074 | newLabelLineIndex = findNewLabelLineStartIndex(oldWaypoints, newWaypoints, attachment, hints);
|
41075 |
|
41076 | if (newLabelLineIndex === null) {
|
41077 | return { x: x, y: y };
|
41078 | }
|
41079 |
|
41080 |
|
41081 |
|
41082 | if (newLabelLineIndex < 0 ||
|
41083 | newLabelLineIndex > newWaypoints.length - 2) {
|
41084 | return { x: x, y: y };
|
41085 | }
|
41086 |
|
41087 | var oldLabelLine = getLine(oldWaypoints, oldLabelLineIndex),
|
41088 | newLabelLine = getLine(newWaypoints, newLabelLineIndex),
|
41089 | oldFoot = attachment.position;
|
41090 |
|
41091 | var relativeFootPosition = getRelativeFootPosition(oldLabelLine, oldFoot),
|
41092 | angleDelta = getAngleDelta(oldLabelLine, newLabelLine);
|
41093 |
|
41094 |
|
41095 | if (attachment.type === 'bendpoint') {
|
41096 |
|
41097 | var offset = newWaypoints.length - oldWaypoints.length,
|
41098 | oldBendpointIndex = attachment.bendpointIndex,
|
41099 | oldBendpoint = oldWaypoints[oldBendpointIndex];
|
41100 |
|
41101 |
|
41102 | if (newWaypoints.indexOf(oldBendpoint) !== -1) {
|
41103 | return { x: x, y: y };
|
41104 | }
|
41105 |
|
41106 |
|
41107 | if (offset === 0) {
|
41108 | var newBendpoint = newWaypoints[oldBendpointIndex];
|
41109 |
|
41110 | return {
|
41111 | x: newBendpoint.x - attachment.position.x,
|
41112 | y: newBendpoint.y - attachment.position.y
|
41113 | };
|
41114 | }
|
41115 |
|
41116 |
|
41117 | if (offset < 0 && oldBendpointIndex !== 0 && oldBendpointIndex < oldWaypoints.length - 1) {
|
41118 | relativeFootPosition = relativePositionMidWaypoint(oldWaypoints, oldBendpointIndex);
|
41119 | }
|
41120 | }
|
41121 |
|
41122 | var newFoot = {
|
41123 | x: (newLabelLine[1].x - newLabelLine[0].x) * relativeFootPosition + newLabelLine[0].x,
|
41124 | y: (newLabelLine[1].y - newLabelLine[0].y) * relativeFootPosition + newLabelLine[0].y
|
41125 | };
|
41126 |
|
41127 |
|
41128 | var newLabelVector = rotateVector({
|
41129 | x: labelPosition.x - oldFoot.x,
|
41130 | y: labelPosition.y - oldFoot.y
|
41131 | }, angleDelta);
|
41132 |
|
41133 |
|
41134 | x = newFoot.x + newLabelVector.x - labelPosition.x;
|
41135 | y = newFoot.y + newLabelVector.y - labelPosition.y;
|
41136 |
|
41137 | return roundPoint({
|
41138 | x: x,
|
41139 | y: y
|
41140 | });
|
41141 | }
|
41142 |
|
41143 |
|
41144 |
|
41145 |
|
41146 | function relativePositionMidWaypoint(waypoints, idx) {
|
41147 |
|
41148 | var distanceSegment1 = getDistancePointPoint(waypoints[idx-1], waypoints[idx]),
|
41149 | distanceSegment2 = getDistancePointPoint(waypoints[idx], waypoints[idx+1]);
|
41150 |
|
41151 | var relativePosition = distanceSegment1 / (distanceSegment1 + distanceSegment2);
|
41152 |
|
41153 | return relativePosition;
|
41154 | }
|
41155 |
|
41156 | function getLabelMid(label) {
|
41157 | return {
|
41158 | x: label.x + label.width / 2,
|
41159 | y: label.y + label.height / 2
|
41160 | };
|
41161 | }
|
41162 |
|
41163 | function getAngleDelta(l1, l2) {
|
41164 | var a1 = getAngle(l1),
|
41165 | a2 = getAngle(l2);
|
41166 | return a2 - a1;
|
41167 | }
|
41168 |
|
41169 | function getLine(waypoints, idx) {
|
41170 | return [ waypoints[idx], waypoints[idx+1] ];
|
41171 | }
|
41172 |
|
41173 | function getRelativeFootPosition(line, foot) {
|
41174 |
|
41175 | var length = getDistancePointPoint(line[0], line[1]),
|
41176 | lengthToFoot = getDistancePointPoint(line[0], foot);
|
41177 |
|
41178 | return length === 0 ? 0 : lengthToFoot / length;
|
41179 | }
|
41180 |
|
41181 | |
41182 |
|
41183 |
|
41184 |
|
41185 |
|
41186 |
|
41187 |
|
41188 |
|
41189 |
|
41190 | function getNewAttachPoint(point, oldBounds, newBounds) {
|
41191 | var oldCenter = center(oldBounds),
|
41192 | newCenter = center(newBounds),
|
41193 | oldDelta = delta(point, oldCenter);
|
41194 |
|
41195 | var newDelta = {
|
41196 | x: oldDelta.x * (newBounds.width / oldBounds.width),
|
41197 | y: oldDelta.y * (newBounds.height / oldBounds.height)
|
41198 | };
|
41199 |
|
41200 | return roundPoint({
|
41201 | x: newCenter.x + newDelta.x,
|
41202 | y: newCenter.y + newDelta.y
|
41203 | });
|
41204 | }
|
41205 |
|
41206 |
|
41207 | |
41208 |
|
41209 |
|
41210 |
|
41211 |
|
41212 |
|
41213 |
|
41214 |
|
41215 |
|
41216 |
|
41217 | function getNewAttachShapeDelta(shape, oldBounds, newBounds) {
|
41218 | var shapeCenter = center(shape),
|
41219 | oldCenter = center(oldBounds),
|
41220 | newCenter = center(newBounds),
|
41221 | shapeDelta = delta(shape, shapeCenter),
|
41222 | oldCenterDelta = delta(shapeCenter, oldCenter);
|
41223 |
|
41224 | var newCenterDelta = {
|
41225 | x: oldCenterDelta.x * (newBounds.width / oldBounds.width),
|
41226 | y: oldCenterDelta.y * (newBounds.height / oldBounds.height)
|
41227 | };
|
41228 |
|
41229 | var newShapeCenter = {
|
41230 | x: newCenter.x + newCenterDelta.x,
|
41231 | y: newCenter.y + newCenterDelta.y
|
41232 | };
|
41233 |
|
41234 | return roundPoint({
|
41235 | x: newShapeCenter.x + shapeDelta.x - shape.x,
|
41236 | y: newShapeCenter.y + shapeDelta.y - shape.y
|
41237 | });
|
41238 | }
|
41239 |
|
41240 | var DEFAULT_LABEL_DIMENSIONS = {
|
41241 | width: 90,
|
41242 | height: 20
|
41243 | };
|
41244 |
|
41245 | var NAME_PROPERTY = 'name';
|
41246 | var TEXT_PROPERTY = 'text';
|
41247 |
|
41248 | |
41249 |
|
41250 |
|
41251 |
|
41252 |
|
41253 |
|
41254 |
|
41255 |
|
41256 |
|
41257 |
|
41258 | function LabelBehavior(
|
41259 | eventBus, modeling, bpmnFactory,
|
41260 | textRenderer) {
|
41261 |
|
41262 | CommandInterceptor.call(this, eventBus);
|
41263 |
|
41264 |
|
41265 | this.postExecute('element.updateProperties', function(e) {
|
41266 | var context = e.context,
|
41267 | element = context.element,
|
41268 | properties = context.properties;
|
41269 |
|
41270 | if (NAME_PROPERTY in properties) {
|
41271 | modeling.updateLabel(element, properties[NAME_PROPERTY]);
|
41272 | }
|
41273 |
|
41274 | if (TEXT_PROPERTY in properties
|
41275 | && is$1(element, 'bpmn:TextAnnotation')) {
|
41276 |
|
41277 | var newBounds = textRenderer.getTextAnnotationBounds(
|
41278 | {
|
41279 | x: element.x,
|
41280 | y: element.y,
|
41281 | width: element.width,
|
41282 | height: element.height
|
41283 | },
|
41284 | properties[TEXT_PROPERTY] || ''
|
41285 | );
|
41286 |
|
41287 | modeling.updateLabel(element, properties.text, newBounds);
|
41288 | }
|
41289 | });
|
41290 |
|
41291 |
|
41292 | this.postExecute([ 'shape.create', 'connection.create' ], function(e) {
|
41293 | var context = e.context,
|
41294 | hints = context.hints || {};
|
41295 |
|
41296 | if (hints.createElementsBehavior === false) {
|
41297 | return;
|
41298 | }
|
41299 |
|
41300 | var element = context.shape || context.connection,
|
41301 | businessObject = element.businessObject;
|
41302 |
|
41303 | if (isLabel(element) || !isLabelExternal(element)) {
|
41304 | return;
|
41305 | }
|
41306 |
|
41307 |
|
41308 | if (!getLabel(element)) {
|
41309 | return;
|
41310 | }
|
41311 |
|
41312 | var labelCenter = getExternalLabelMid(element);
|
41313 |
|
41314 |
|
41315 | var labelDimensions = textRenderer.getExternalLabelBounds(
|
41316 | DEFAULT_LABEL_DIMENSIONS,
|
41317 | getLabel(element)
|
41318 | );
|
41319 |
|
41320 | modeling.createLabel(element, labelCenter, {
|
41321 | id: businessObject.id + '_label',
|
41322 | businessObject: businessObject,
|
41323 | width: labelDimensions.width,
|
41324 | height: labelDimensions.height
|
41325 | });
|
41326 | });
|
41327 |
|
41328 |
|
41329 | this.postExecute('shape.delete', function(event) {
|
41330 | var context = event.context,
|
41331 | labelTarget = context.labelTarget,
|
41332 | hints = context.hints || {};
|
41333 |
|
41334 |
|
41335 | if (labelTarget && hints.unsetLabel !== false) {
|
41336 | modeling.updateLabel(labelTarget, null, null, { removeShape: false });
|
41337 | }
|
41338 | });
|
41339 |
|
41340 |
|
41341 | this.postExecute([ 'label.create' ], function(event) {
|
41342 |
|
41343 | var context = event.context,
|
41344 | element = context.shape,
|
41345 | businessObject,
|
41346 | di;
|
41347 |
|
41348 |
|
41349 | if (!element.labelTarget) {
|
41350 | return;
|
41351 | }
|
41352 |
|
41353 |
|
41354 | if (!is$1(element.labelTarget || element, 'bpmn:BaseElement')) {
|
41355 | return;
|
41356 | }
|
41357 |
|
41358 | businessObject = element.businessObject,
|
41359 | di = businessObject.di;
|
41360 |
|
41361 |
|
41362 | if (!di.label) {
|
41363 | di.label = bpmnFactory.create('bpmndi:BPMNLabel', {
|
41364 | bounds: bpmnFactory.create('dc:Bounds')
|
41365 | });
|
41366 | }
|
41367 |
|
41368 | assign(di.label.bounds, {
|
41369 | x: element.x,
|
41370 | y: element.y,
|
41371 | width: element.width,
|
41372 | height: element.height
|
41373 | });
|
41374 | });
|
41375 |
|
41376 | function getVisibleLabelAdjustment(event) {
|
41377 |
|
41378 | var context = event.context,
|
41379 | connection = context.connection,
|
41380 | label = connection.label,
|
41381 | hints = assign({}, context.hints),
|
41382 | newWaypoints = context.newWaypoints || connection.waypoints,
|
41383 | oldWaypoints = context.oldWaypoints;
|
41384 |
|
41385 |
|
41386 | if (typeof hints.startChanged === 'undefined') {
|
41387 | hints.startChanged = !!hints.connectionStart;
|
41388 | }
|
41389 |
|
41390 | if (typeof hints.endChanged === 'undefined') {
|
41391 | hints.endChanged = !!hints.connectionEnd;
|
41392 | }
|
41393 |
|
41394 | return getLabelAdjustment(label, newWaypoints, oldWaypoints, hints);
|
41395 | }
|
41396 |
|
41397 | this.postExecute([
|
41398 | 'connection.layout',
|
41399 | 'connection.updateWaypoints'
|
41400 | ], function(event) {
|
41401 |
|
41402 | var label = event.context.connection.label,
|
41403 | labelAdjustment;
|
41404 |
|
41405 |
|
41406 |
|
41407 |
|
41408 |
|
41409 |
|
41410 | if (!label || !label.parent) {
|
41411 | return;
|
41412 | }
|
41413 |
|
41414 | labelAdjustment = getVisibleLabelAdjustment(event);
|
41415 |
|
41416 | modeling.moveShape(label, labelAdjustment);
|
41417 | });
|
41418 |
|
41419 |
|
41420 |
|
41421 | this.postExecute([ 'shape.replace' ], function(event) {
|
41422 | var context = event.context,
|
41423 | newShape = context.newShape,
|
41424 | oldShape = context.oldShape;
|
41425 |
|
41426 | var businessObject = getBusinessObject(newShape);
|
41427 |
|
41428 | if (businessObject
|
41429 | && isLabelExternal(businessObject)
|
41430 | && oldShape.label
|
41431 | && newShape.label) {
|
41432 | newShape.label.x = oldShape.label.x;
|
41433 | newShape.label.y = oldShape.label.y;
|
41434 | }
|
41435 | });
|
41436 |
|
41437 |
|
41438 |
|
41439 | this.postExecute('shape.resize', function(event) {
|
41440 |
|
41441 | var context = event.context,
|
41442 | shape = context.shape,
|
41443 | newBounds = context.newBounds,
|
41444 | oldBounds = context.oldBounds;
|
41445 |
|
41446 | if (hasExternalLabel(shape)) {
|
41447 |
|
41448 | var label = shape.label,
|
41449 | labelMid = getMid(label),
|
41450 | edges = asEdges(oldBounds);
|
41451 |
|
41452 |
|
41453 | var referencePoint = getReferencePoint$1(labelMid, edges);
|
41454 |
|
41455 | var delta = getReferencePointDelta(referencePoint, oldBounds, newBounds);
|
41456 |
|
41457 | modeling.moveShape(label, delta);
|
41458 |
|
41459 | }
|
41460 |
|
41461 | });
|
41462 |
|
41463 | }
|
41464 |
|
41465 | inherits_browser(LabelBehavior, CommandInterceptor);
|
41466 |
|
41467 | LabelBehavior.$inject = [
|
41468 | 'eventBus',
|
41469 | 'modeling',
|
41470 | 'bpmnFactory',
|
41471 | 'textRenderer'
|
41472 | ];
|
41473 |
|
41474 |
|
41475 |
|
41476 | |
41477 |
|
41478 |
|
41479 |
|
41480 |
|
41481 |
|
41482 |
|
41483 |
|
41484 |
|
41485 |
|
41486 | function getReferencePointDelta(referencePoint, oldBounds, newBounds) {
|
41487 |
|
41488 | var newReferencePoint = getNewAttachPoint(referencePoint, oldBounds, newBounds);
|
41489 |
|
41490 | return roundPoint(delta(newReferencePoint, referencePoint));
|
41491 | }
|
41492 |
|
41493 | |
41494 |
|
41495 |
|
41496 |
|
41497 |
|
41498 |
|
41499 |
|
41500 |
|
41501 |
|
41502 | function getReferencePoint$1(point, lines) {
|
41503 |
|
41504 | if (!lines.length) {
|
41505 | return;
|
41506 | }
|
41507 |
|
41508 | var nearestLine = getNearestLine(point, lines);
|
41509 |
|
41510 | return perpendicularFoot(point, nearestLine);
|
41511 | }
|
41512 |
|
41513 | |
41514 |
|
41515 |
|
41516 |
|
41517 |
|
41518 |
|
41519 |
|
41520 | function asEdges(bounds) {
|
41521 | return [
|
41522 | [
|
41523 | {
|
41524 | x: bounds.x,
|
41525 | y: bounds.y
|
41526 | },
|
41527 | {
|
41528 | x: bounds.x + (bounds.width || 0),
|
41529 | y: bounds.y
|
41530 | }
|
41531 | ],
|
41532 | [
|
41533 | {
|
41534 | x: bounds.x + (bounds.width || 0),
|
41535 | y: bounds.y
|
41536 | },
|
41537 | {
|
41538 | x: bounds.x + (bounds.width || 0),
|
41539 | y: bounds.y + (bounds.height || 0)
|
41540 | }
|
41541 | ],
|
41542 | [
|
41543 | {
|
41544 | x: bounds.x,
|
41545 | y: bounds.y + (bounds.height || 0)
|
41546 | },
|
41547 | {
|
41548 | x: bounds.x + (bounds.width || 0),
|
41549 | y: bounds.y + (bounds.height || 0)
|
41550 | }
|
41551 | ],
|
41552 | [
|
41553 | {
|
41554 | x: bounds.x,
|
41555 | y: bounds.y
|
41556 | },
|
41557 | {
|
41558 | x: bounds.x,
|
41559 | y: bounds.y + (bounds.height || 0)
|
41560 | }
|
41561 | ]
|
41562 | ];
|
41563 | }
|
41564 |
|
41565 | |
41566 |
|
41567 |
|
41568 |
|
41569 |
|
41570 |
|
41571 |
|
41572 | function getNearestLine(point, lines) {
|
41573 |
|
41574 | var distances = lines.map(function(l) {
|
41575 | return {
|
41576 | line: l,
|
41577 | distance: getDistancePointLine(point, l)
|
41578 | };
|
41579 | });
|
41580 |
|
41581 | var sorted = sortBy(distances, 'distance');
|
41582 |
|
41583 | return sorted[0].line;
|
41584 | }
|
41585 |
|
41586 | var COLLAB_ERR_MSG = 'flow elements must be children of pools/participants',
|
41587 | PROCESS_ERR_MSG = 'participants cannot be pasted onto a non-empty process diagram';
|
41588 |
|
41589 |
|
41590 | function ModelingFeedback(eventBus, tooltips, translate) {
|
41591 |
|
41592 | function showError(position, message, timeout) {
|
41593 | tooltips.add({
|
41594 | position: {
|
41595 | x: position.x + 5,
|
41596 | y: position.y + 5
|
41597 | },
|
41598 | type: 'error',
|
41599 | timeout: timeout || 2000,
|
41600 | html: '<div>' + message + '</div>'
|
41601 | });
|
41602 | }
|
41603 |
|
41604 | eventBus.on([ 'shape.move.rejected', 'create.rejected' ], function(event) {
|
41605 | var context = event.context,
|
41606 | shape = context.shape,
|
41607 | target = context.target;
|
41608 |
|
41609 | if (is$1(target, 'bpmn:Collaboration') && is$1(shape, 'bpmn:FlowNode')) {
|
41610 | showError(event, translate(COLLAB_ERR_MSG));
|
41611 | }
|
41612 | });
|
41613 |
|
41614 | eventBus.on([ 'elements.paste.rejected' ], function(event) {
|
41615 | var context = event.context,
|
41616 | position = context.position,
|
41617 | target = context.target;
|
41618 |
|
41619 | if (is$1(target, 'bpmn:Collaboration')) {
|
41620 | showError(position, translate(COLLAB_ERR_MSG));
|
41621 | }
|
41622 |
|
41623 | if (is$1(target, 'bpmn:Process')) {
|
41624 | showError(position, translate(PROCESS_ERR_MSG), 3000);
|
41625 | }
|
41626 | });
|
41627 | }
|
41628 |
|
41629 | ModelingFeedback.$inject = [
|
41630 | 'eventBus',
|
41631 | 'tooltips',
|
41632 | 'translate'
|
41633 | ];
|
41634 |
|
41635 | function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules, injector) {
|
41636 |
|
41637 | CommandInterceptor.call(this, eventBus);
|
41638 |
|
41639 | var dragging = injector.get('dragging', false);
|
41640 |
|
41641 | function fixConnection(connection) {
|
41642 |
|
41643 | var source = connection.source,
|
41644 | target = connection.target,
|
41645 | parent = connection.parent;
|
41646 |
|
41647 |
|
41648 |
|
41649 |
|
41650 | if (!parent) {
|
41651 | return;
|
41652 | }
|
41653 |
|
41654 | var replacementType,
|
41655 | remove;
|
41656 |
|
41657 | |
41658 |
|
41659 |
|
41660 |
|
41661 |
|
41662 |
|
41663 |
|
41664 |
|
41665 | if (is$1(connection, 'bpmn:SequenceFlow')) {
|
41666 | if (!bpmnRules.canConnectSequenceFlow(source, target)) {
|
41667 | remove = true;
|
41668 | }
|
41669 |
|
41670 | if (bpmnRules.canConnectMessageFlow(source, target)) {
|
41671 | replacementType = 'bpmn:MessageFlow';
|
41672 | }
|
41673 | }
|
41674 |
|
41675 |
|
41676 |
|
41677 | if (is$1(connection, 'bpmn:MessageFlow')) {
|
41678 |
|
41679 | if (!bpmnRules.canConnectMessageFlow(source, target)) {
|
41680 | remove = true;
|
41681 | }
|
41682 |
|
41683 | if (bpmnRules.canConnectSequenceFlow(source, target)) {
|
41684 | replacementType = 'bpmn:SequenceFlow';
|
41685 | }
|
41686 | }
|
41687 |
|
41688 | if (is$1(connection, 'bpmn:Association') && !bpmnRules.canConnectAssociation(source, target)) {
|
41689 | remove = true;
|
41690 | }
|
41691 |
|
41692 |
|
41693 |
|
41694 |
|
41695 | if (remove) {
|
41696 | modeling.removeConnection(connection);
|
41697 | }
|
41698 |
|
41699 |
|
41700 |
|
41701 | if (replacementType) {
|
41702 | modeling.connect(source, target, {
|
41703 | type: replacementType,
|
41704 | waypoints: connection.waypoints.slice()
|
41705 | });
|
41706 | }
|
41707 | }
|
41708 |
|
41709 | function replaceReconnectedConnection(event) {
|
41710 |
|
41711 | var context = event.context,
|
41712 | connection = context.connection,
|
41713 | source = context.newSource || connection.source,
|
41714 | target = context.newTarget || connection.target,
|
41715 | allowed,
|
41716 | replacement;
|
41717 |
|
41718 | allowed = bpmnRules.canConnect(source, target);
|
41719 |
|
41720 | if (!allowed || allowed.type === connection.type) {
|
41721 | return;
|
41722 | }
|
41723 |
|
41724 | replacement = modeling.connect(source, target, {
|
41725 | type: allowed.type,
|
41726 | waypoints: connection.waypoints.slice()
|
41727 | });
|
41728 |
|
41729 |
|
41730 | modeling.removeConnection(connection);
|
41731 |
|
41732 |
|
41733 | context.connection = replacement;
|
41734 |
|
41735 | if (dragging) {
|
41736 | cleanDraggingSelection(connection, replacement);
|
41737 | }
|
41738 | }
|
41739 |
|
41740 |
|
41741 | function cleanDraggingSelection(oldConnection, newConnection) {
|
41742 | var context = dragging.context(),
|
41743 | previousSelection = context && context.payload.previousSelection,
|
41744 | index;
|
41745 |
|
41746 |
|
41747 | if (!previousSelection || !previousSelection.length) {
|
41748 | return;
|
41749 | }
|
41750 |
|
41751 | index = previousSelection.indexOf(oldConnection);
|
41752 |
|
41753 | if (index === -1) {
|
41754 | return;
|
41755 | }
|
41756 |
|
41757 | previousSelection.splice(index, 1, newConnection);
|
41758 | }
|
41759 |
|
41760 |
|
41761 |
|
41762 | this.postExecuted('elements.move', function(context) {
|
41763 |
|
41764 | var closure = context.closure,
|
41765 | allConnections = closure.allConnections;
|
41766 |
|
41767 | forEach(allConnections, fixConnection);
|
41768 | }, true);
|
41769 |
|
41770 | this.preExecute('connection.reconnect', replaceReconnectedConnection);
|
41771 |
|
41772 | this.postExecuted('element.updateProperties', function(event) {
|
41773 | var context = event.context,
|
41774 | properties = context.properties,
|
41775 | element = context.element,
|
41776 | businessObject = element.businessObject,
|
41777 | connection;
|
41778 |
|
41779 |
|
41780 | if (properties.default) {
|
41781 | connection = find(
|
41782 | element.outgoing,
|
41783 | matchPattern({ id: element.businessObject.default.id })
|
41784 | );
|
41785 |
|
41786 | if (connection) {
|
41787 | modeling.updateProperties(connection, { conditionExpression: undefined });
|
41788 | }
|
41789 | }
|
41790 |
|
41791 |
|
41792 | if (properties.conditionExpression && businessObject.sourceRef.default === businessObject) {
|
41793 | modeling.updateProperties(element.source, { default: undefined });
|
41794 | }
|
41795 | });
|
41796 | }
|
41797 |
|
41798 | inherits_browser(ReplaceConnectionBehavior, CommandInterceptor);
|
41799 |
|
41800 | ReplaceConnectionBehavior.$inject = [
|
41801 | 'eventBus',
|
41802 | 'modeling',
|
41803 | 'bpmnRules',
|
41804 | 'injector'
|
41805 | ];
|
41806 |
|
41807 | |
41808 |
|
41809 |
|
41810 | function RemoveParticipantBehavior(eventBus, modeling) {
|
41811 |
|
41812 | CommandInterceptor.call(this, eventBus);
|
41813 |
|
41814 |
|
41815 | |
41816 |
|
41817 |
|
41818 |
|
41819 |
|
41820 | this.preExecute('shape.delete', function(context) {
|
41821 |
|
41822 | var shape = context.shape,
|
41823 | parent = shape.parent;
|
41824 |
|
41825 |
|
41826 |
|
41827 | if (is$1(shape, 'bpmn:Participant')) {
|
41828 | context.collaborationRoot = parent;
|
41829 | }
|
41830 | }, true);
|
41831 |
|
41832 | this.postExecute('shape.delete', function(context) {
|
41833 |
|
41834 | var collaborationRoot = context.collaborationRoot;
|
41835 |
|
41836 | if (collaborationRoot && !collaborationRoot.businessObject.participants.length) {
|
41837 |
|
41838 |
|
41839 | modeling.makeProcess();
|
41840 | }
|
41841 | }, true);
|
41842 |
|
41843 | }
|
41844 |
|
41845 | RemoveParticipantBehavior.$inject = [ 'eventBus', 'modeling' ];
|
41846 |
|
41847 | inherits_browser(RemoveParticipantBehavior, CommandInterceptor);
|
41848 |
|
41849 | |
41850 |
|
41851 |
|
41852 | function ReplaceElementBehaviour(
|
41853 | bpmnReplace,
|
41854 | bpmnRules,
|
41855 | elementRegistry,
|
41856 | injector,
|
41857 | modeling,
|
41858 | selection
|
41859 | ) {
|
41860 | injector.invoke(CommandInterceptor, this);
|
41861 |
|
41862 | this._bpmnReplace = bpmnReplace;
|
41863 | this._elementRegistry = elementRegistry;
|
41864 | this._selection = selection;
|
41865 |
|
41866 |
|
41867 | this.postExecuted([ 'elements.move' ], 500, function(event) {
|
41868 | var context = event.context,
|
41869 | target = context.newParent,
|
41870 | newHost = context.newHost,
|
41871 | elements = [];
|
41872 |
|
41873 | forEach(context.closure.topLevel, function(topLevelElements) {
|
41874 | if (isEventSubProcess(topLevelElements)) {
|
41875 | elements = elements.concat(topLevelElements.children);
|
41876 | } else {
|
41877 | elements = elements.concat(topLevelElements);
|
41878 | }
|
41879 | });
|
41880 |
|
41881 |
|
41882 | if (elements.length === 1 && newHost) {
|
41883 | target = newHost;
|
41884 | }
|
41885 |
|
41886 | var canReplace = bpmnRules.canReplace(elements, target);
|
41887 |
|
41888 | if (canReplace) {
|
41889 | this.replaceElements(elements, canReplace.replacements, newHost);
|
41890 | }
|
41891 | }, this);
|
41892 |
|
41893 |
|
41894 | this.postExecute([ 'shape.replace' ], 1500, function(e) {
|
41895 | var context = e.context,
|
41896 | oldShape = context.oldShape,
|
41897 | newShape = context.newShape,
|
41898 | attachers = oldShape.attachers,
|
41899 | canReplace;
|
41900 |
|
41901 | if (attachers && attachers.length) {
|
41902 | canReplace = bpmnRules.canReplace(attachers, newShape);
|
41903 |
|
41904 | this.replaceElements(attachers, canReplace.replacements);
|
41905 | }
|
41906 |
|
41907 | }, this);
|
41908 |
|
41909 |
|
41910 | this.postExecuted([ 'shape.replace' ], 1500, function(e) {
|
41911 | var context = e.context,
|
41912 | oldShape = context.oldShape,
|
41913 | newShape = context.newShape;
|
41914 |
|
41915 | modeling.unclaimId(oldShape.businessObject.id, oldShape.businessObject);
|
41916 | modeling.updateProperties(newShape, { id: oldShape.id });
|
41917 | });
|
41918 | }
|
41919 |
|
41920 | inherits_browser(ReplaceElementBehaviour, CommandInterceptor);
|
41921 |
|
41922 | ReplaceElementBehaviour.prototype.replaceElements = function(elements, newElements) {
|
41923 | var elementRegistry = this._elementRegistry,
|
41924 | bpmnReplace = this._bpmnReplace,
|
41925 | selection = this._selection;
|
41926 |
|
41927 | forEach(newElements, function(replacement) {
|
41928 | var newElement = {
|
41929 | type: replacement.newElementType
|
41930 | };
|
41931 |
|
41932 | var oldElement = elementRegistry.get(replacement.oldElementId);
|
41933 |
|
41934 | var idx = elements.indexOf(oldElement);
|
41935 |
|
41936 | elements[idx] = bpmnReplace.replaceElement(oldElement, newElement, { select: false });
|
41937 | });
|
41938 |
|
41939 | if (newElements) {
|
41940 | selection.select(elements);
|
41941 | }
|
41942 | };
|
41943 |
|
41944 | ReplaceElementBehaviour.$inject = [
|
41945 | 'bpmnReplace',
|
41946 | 'bpmnRules',
|
41947 | 'elementRegistry',
|
41948 | 'injector',
|
41949 | 'modeling',
|
41950 | 'selection'
|
41951 | ];
|
41952 |
|
41953 | var abs$5 = Math.abs,
|
41954 | min$3 = Math.min,
|
41955 | max$4 = Math.max;
|
41956 |
|
41957 |
|
41958 | function addToTrbl(trbl, attr, value, choice) {
|
41959 | var current = trbl[attr];
|
41960 |
|
41961 |
|
41962 |
|
41963 |
|
41964 | trbl[attr] = current === undefined ? value : choice(value, current);
|
41965 | }
|
41966 |
|
41967 | function addMin(trbl, attr, value) {
|
41968 | return addToTrbl(trbl, attr, value, min$3);
|
41969 | }
|
41970 |
|
41971 | function addMax(trbl, attr, value) {
|
41972 | return addToTrbl(trbl, attr, value, max$4);
|
41973 | }
|
41974 |
|
41975 | var LANE_MIN_HEIGHT = 60,
|
41976 | LANE_MIN_WIDTH = 300,
|
41977 | LANE_RIGHT_PADDING = 20,
|
41978 | LANE_LEFT_PADDING = 50,
|
41979 | LANE_TOP_PADDING = 20,
|
41980 | LANE_BOTTOM_PADDING = 20;
|
41981 |
|
41982 |
|
41983 | function getParticipantResizeConstraints(laneShape, resizeDirection, balanced) {
|
41984 | var lanesRoot = getLanesRoot(laneShape);
|
41985 |
|
41986 | var isFirst = true,
|
41987 | isLast = true;
|
41988 |
|
41989 |
|
41990 | var allLanes = collectLanes(lanesRoot, [ lanesRoot ]);
|
41991 |
|
41992 | var laneTrbl = asTRBL(laneShape);
|
41993 |
|
41994 | var maxTrbl = {},
|
41995 | minTrbl = {};
|
41996 |
|
41997 | if (/e/.test(resizeDirection)) {
|
41998 | minTrbl.right = laneTrbl.left + LANE_MIN_WIDTH;
|
41999 | } else
|
42000 | if (/w/.test(resizeDirection)) {
|
42001 | minTrbl.left = laneTrbl.right - LANE_MIN_WIDTH;
|
42002 | }
|
42003 |
|
42004 | allLanes.forEach(function(other) {
|
42005 |
|
42006 | var otherTrbl = asTRBL(other);
|
42007 |
|
42008 | if (/n/.test(resizeDirection)) {
|
42009 |
|
42010 | if (otherTrbl.top < (laneTrbl.top - 10)) {
|
42011 | isFirst = false;
|
42012 | }
|
42013 |
|
42014 |
|
42015 | if (balanced && abs$5(laneTrbl.top - otherTrbl.bottom) < 10) {
|
42016 | addMax(maxTrbl, 'top', otherTrbl.top + LANE_MIN_HEIGHT);
|
42017 | }
|
42018 |
|
42019 |
|
42020 | if (abs$5(laneTrbl.top - otherTrbl.top) < 5) {
|
42021 | addMin(minTrbl, 'top', otherTrbl.bottom - LANE_MIN_HEIGHT);
|
42022 | }
|
42023 | }
|
42024 |
|
42025 | if (/s/.test(resizeDirection)) {
|
42026 |
|
42027 | if (otherTrbl.bottom > (laneTrbl.bottom + 10)) {
|
42028 | isLast = false;
|
42029 | }
|
42030 |
|
42031 |
|
42032 | if (balanced && abs$5(laneTrbl.bottom - otherTrbl.top) < 10) {
|
42033 | addMin(maxTrbl, 'bottom', otherTrbl.bottom - LANE_MIN_HEIGHT);
|
42034 | }
|
42035 |
|
42036 |
|
42037 | if (abs$5(laneTrbl.bottom - otherTrbl.bottom) < 5) {
|
42038 | addMax(minTrbl, 'bottom', otherTrbl.top + LANE_MIN_HEIGHT);
|
42039 | }
|
42040 | }
|
42041 | });
|
42042 |
|
42043 |
|
42044 | var flowElements = lanesRoot.children.filter(function(s) {
|
42045 | return !s.hidden && !s.waypoints && (is$1(s, 'bpmn:FlowElement') || is$1(s, 'bpmn:Artifact'));
|
42046 | });
|
42047 |
|
42048 | flowElements.forEach(function(flowElement) {
|
42049 |
|
42050 | var flowElementTrbl = asTRBL(flowElement);
|
42051 |
|
42052 | if (isFirst && /n/.test(resizeDirection)) {
|
42053 | addMin(minTrbl, 'top', flowElementTrbl.top - LANE_TOP_PADDING);
|
42054 | }
|
42055 |
|
42056 | if (/e/.test(resizeDirection)) {
|
42057 | addMax(minTrbl, 'right', flowElementTrbl.right + LANE_RIGHT_PADDING);
|
42058 | }
|
42059 |
|
42060 | if (isLast && /s/.test(resizeDirection)) {
|
42061 | addMax(minTrbl, 'bottom', flowElementTrbl.bottom + LANE_BOTTOM_PADDING);
|
42062 | }
|
42063 |
|
42064 | if (/w/.test(resizeDirection)) {
|
42065 | addMin(minTrbl, 'left', flowElementTrbl.left - LANE_LEFT_PADDING);
|
42066 | }
|
42067 | });
|
42068 |
|
42069 | return {
|
42070 | min: minTrbl,
|
42071 | max: maxTrbl
|
42072 | };
|
42073 | }
|
42074 |
|
42075 | var HIGH_PRIORITY$9 = 1500;
|
42076 |
|
42077 | var PARTICIPANT_MIN_DIMENSIONS = { width: 300, height: 150 },
|
42078 | SUB_PROCESS_MIN_DIMENSIONS = { width: 140, height: 120 },
|
42079 | TEXT_ANNOTATION_MIN_DIMENSIONS = { width: 50, height: 30 };
|
42080 |
|
42081 |
|
42082 | |
42083 |
|
42084 |
|
42085 |
|
42086 |
|
42087 | function ResizeBehavior$1(eventBus) {
|
42088 | eventBus.on('resize.start', HIGH_PRIORITY$9, function(event) {
|
42089 | var context = event.context,
|
42090 | shape = context.shape,
|
42091 | direction = context.direction,
|
42092 | balanced = context.balanced;
|
42093 |
|
42094 | if (is$1(shape, 'bpmn:Lane') || is$1(shape, 'bpmn:Participant')) {
|
42095 | context.resizeConstraints = getParticipantResizeConstraints(shape, direction, balanced);
|
42096 | }
|
42097 |
|
42098 | if (is$1(shape, 'bpmn:Participant')) {
|
42099 | context.minDimensions = PARTICIPANT_MIN_DIMENSIONS;
|
42100 | }
|
42101 |
|
42102 | if (is$1(shape, 'bpmn:SubProcess') && isExpanded(shape)) {
|
42103 | context.minDimensions = SUB_PROCESS_MIN_DIMENSIONS;
|
42104 | }
|
42105 |
|
42106 | if (is$1(shape, 'bpmn:TextAnnotation')) {
|
42107 | context.minDimensions = TEXT_ANNOTATION_MIN_DIMENSIONS;
|
42108 | }
|
42109 | });
|
42110 | }
|
42111 |
|
42112 | ResizeBehavior$1.$inject = [ 'eventBus' ];
|
42113 |
|
42114 | var SLIGHTLY_HIGHER_PRIORITY = 1001;
|
42115 |
|
42116 |
|
42117 | |
42118 |
|
42119 |
|
42120 |
|
42121 |
|
42122 | function ResizeLaneBehavior(eventBus, modeling) {
|
42123 |
|
42124 | eventBus.on('resize.start', SLIGHTLY_HIGHER_PRIORITY + 500, function(event) {
|
42125 | var context = event.context,
|
42126 | shape = context.shape;
|
42127 |
|
42128 | if (is$1(shape, 'bpmn:Lane') || is$1(shape, 'bpmn:Participant')) {
|
42129 |
|
42130 |
|
42131 |
|
42132 | context.balanced = !hasPrimaryModifier(event);
|
42133 | }
|
42134 | });
|
42135 |
|
42136 | |
42137 |
|
42138 |
|
42139 | eventBus.on('resize.end', SLIGHTLY_HIGHER_PRIORITY, function(event) {
|
42140 | var context = event.context,
|
42141 | shape = context.shape,
|
42142 | canExecute = context.canExecute,
|
42143 | newBounds = context.newBounds;
|
42144 |
|
42145 | if (is$1(shape, 'bpmn:Lane') || is$1(shape, 'bpmn:Participant')) {
|
42146 |
|
42147 | if (canExecute) {
|
42148 |
|
42149 |
|
42150 |
|
42151 | newBounds = roundBounds(newBounds);
|
42152 |
|
42153 |
|
42154 | modeling.resizeLane(shape, newBounds, context.balanced);
|
42155 | }
|
42156 |
|
42157 |
|
42158 | return false;
|
42159 | }
|
42160 | });
|
42161 | }
|
42162 |
|
42163 | ResizeLaneBehavior.$inject = [
|
42164 | 'eventBus',
|
42165 | 'modeling'
|
42166 | ];
|
42167 |
|
42168 | function RemoveElementBehavior(eventBus, bpmnRules, modeling) {
|
42169 |
|
42170 | CommandInterceptor.call(this, eventBus);
|
42171 |
|
42172 | |
42173 |
|
42174 |
|
42175 |
|
42176 |
|
42177 | this.preExecute('shape.delete', function(e) {
|
42178 |
|
42179 | var shape = e.context.shape;
|
42180 |
|
42181 |
|
42182 | if (shape.incoming.length !== 1 || shape.outgoing.length !== 1) {
|
42183 | return;
|
42184 | }
|
42185 |
|
42186 | var inConnection = shape.incoming[0],
|
42187 | outConnection = shape.outgoing[0];
|
42188 |
|
42189 |
|
42190 | if (!is$1(inConnection, 'bpmn:SequenceFlow') || !is$1(outConnection, 'bpmn:SequenceFlow')) {
|
42191 | return;
|
42192 | }
|
42193 |
|
42194 | if (bpmnRules.canConnect(inConnection.source, outConnection.target, inConnection)) {
|
42195 |
|
42196 |
|
42197 | var newWaypoints = getNewWaypoints(inConnection.waypoints, outConnection.waypoints);
|
42198 |
|
42199 | modeling.reconnectEnd(inConnection, outConnection.target, newWaypoints);
|
42200 | }
|
42201 | });
|
42202 |
|
42203 | }
|
42204 |
|
42205 | inherits_browser(RemoveElementBehavior, CommandInterceptor);
|
42206 |
|
42207 | RemoveElementBehavior.$inject = [
|
42208 | 'eventBus',
|
42209 | 'bpmnRules',
|
42210 | 'modeling'
|
42211 | ];
|
42212 |
|
42213 |
|
42214 |
|
42215 |
|
42216 | function getDocking$1(point) {
|
42217 | return point.original || point;
|
42218 | }
|
42219 |
|
42220 |
|
42221 | function getNewWaypoints(inWaypoints, outWaypoints) {
|
42222 |
|
42223 | var intersection = lineIntersect(
|
42224 | getDocking$1(inWaypoints[inWaypoints.length - 2]),
|
42225 | getDocking$1(inWaypoints[inWaypoints.length - 1]),
|
42226 | getDocking$1(outWaypoints[1]),
|
42227 | getDocking$1(outWaypoints[0]));
|
42228 |
|
42229 | if (intersection) {
|
42230 | return [].concat(
|
42231 | inWaypoints.slice(0, inWaypoints.length - 1),
|
42232 | [ intersection ],
|
42233 | outWaypoints.slice(1));
|
42234 | } else {
|
42235 | return [
|
42236 | getDocking$1(inWaypoints[0]),
|
42237 | getDocking$1(outWaypoints[outWaypoints.length - 1])
|
42238 | ];
|
42239 | }
|
42240 | }
|
42241 |
|
42242 | |
42243 |
|
42244 |
|
42245 |
|
42246 |
|
42247 |
|
42248 | function SubProcessStartEventBehavior(injector, modeling) {
|
42249 | injector.invoke(CommandInterceptor, this);
|
42250 |
|
42251 | this.postExecuted('shape.replace', function(event) {
|
42252 | var oldShape = event.context.oldShape,
|
42253 | newShape = event.context.newShape;
|
42254 |
|
42255 | if (
|
42256 | !is$1(newShape, 'bpmn:SubProcess') ||
|
42257 | !is$1(oldShape, 'bpmn:Task') ||
|
42258 | !isExpanded(newShape)
|
42259 | ) {
|
42260 | return;
|
42261 | }
|
42262 |
|
42263 | var position = getStartEventPosition(newShape);
|
42264 |
|
42265 | modeling.createShape({ type: 'bpmn:StartEvent' }, position, newShape);
|
42266 | });
|
42267 | }
|
42268 |
|
42269 | SubProcessStartEventBehavior.$inject = [
|
42270 | 'injector',
|
42271 | 'modeling'
|
42272 | ];
|
42273 |
|
42274 | inherits_browser(SubProcessStartEventBehavior, CommandInterceptor);
|
42275 |
|
42276 |
|
42277 |
|
42278 | function getStartEventPosition(shape) {
|
42279 | return {
|
42280 | x: shape.x + shape.width / 6,
|
42281 | y: shape.y + shape.height / 2
|
42282 | };
|
42283 | }
|
42284 |
|
42285 | var LOW_PRIORITY$d = 500;
|
42286 |
|
42287 |
|
42288 | function ToggleElementCollapseBehaviour(
|
42289 | eventBus, elementFactory, modeling,
|
42290 | resize) {
|
42291 |
|
42292 | CommandInterceptor.call(this, eventBus);
|
42293 |
|
42294 |
|
42295 | function hideEmptyLabels(children) {
|
42296 | if (children.length) {
|
42297 | children.forEach(function(child) {
|
42298 | if (child.type === 'label' && !child.businessObject.name) {
|
42299 | child.hidden = true;
|
42300 | }
|
42301 | });
|
42302 | }
|
42303 | }
|
42304 |
|
42305 | function expandedBounds(shape, defaultSize) {
|
42306 | var children = shape.children,
|
42307 | newBounds = defaultSize,
|
42308 | visibleElements,
|
42309 | visibleBBox;
|
42310 |
|
42311 | visibleElements = filterVisible(children).concat([ shape ]);
|
42312 |
|
42313 | visibleBBox = computeChildrenBBox(visibleElements);
|
42314 |
|
42315 | if (visibleBBox) {
|
42316 |
|
42317 |
|
42318 | newBounds.width = Math.max(visibleBBox.width, newBounds.width);
|
42319 | newBounds.height = Math.max(visibleBBox.height, newBounds.height);
|
42320 |
|
42321 | newBounds.x = visibleBBox.x + (visibleBBox.width - newBounds.width) / 2;
|
42322 | newBounds.y = visibleBBox.y + (visibleBBox.height - newBounds.height) / 2;
|
42323 | } else {
|
42324 |
|
42325 |
|
42326 | newBounds.x = shape.x + (shape.width - newBounds.width) / 2;
|
42327 | newBounds.y = shape.y + (shape.height - newBounds.height) / 2;
|
42328 | }
|
42329 |
|
42330 | return newBounds;
|
42331 | }
|
42332 |
|
42333 | function collapsedBounds(shape, defaultSize) {
|
42334 |
|
42335 | return {
|
42336 | x: shape.x + (shape.width - defaultSize.width) / 2,
|
42337 | y: shape.y + (shape.height - defaultSize.height) / 2,
|
42338 | width: defaultSize.width,
|
42339 | height: defaultSize.height
|
42340 | };
|
42341 | }
|
42342 |
|
42343 | this.executed([ 'shape.toggleCollapse' ], LOW_PRIORITY$d, function(e) {
|
42344 |
|
42345 | var context = e.context,
|
42346 | shape = context.shape;
|
42347 |
|
42348 | if (!is$1(shape, 'bpmn:SubProcess')) {
|
42349 | return;
|
42350 | }
|
42351 |
|
42352 | if (!shape.collapsed) {
|
42353 |
|
42354 |
|
42355 | hideEmptyLabels(shape.children);
|
42356 |
|
42357 |
|
42358 | getBusinessObject(shape).di.isExpanded = true;
|
42359 | } else {
|
42360 |
|
42361 |
|
42362 | getBusinessObject(shape).di.isExpanded = false;
|
42363 | }
|
42364 | });
|
42365 |
|
42366 | this.reverted([ 'shape.toggleCollapse' ], LOW_PRIORITY$d, function(e) {
|
42367 |
|
42368 | var context = e.context;
|
42369 | var shape = context.shape;
|
42370 |
|
42371 |
|
42372 |
|
42373 | if (!shape.collapsed) {
|
42374 | getBusinessObject(shape).di.isExpanded = true;
|
42375 |
|
42376 | } else {
|
42377 | getBusinessObject(shape).di.isExpanded = false;
|
42378 | }
|
42379 | });
|
42380 |
|
42381 | this.postExecuted([ 'shape.toggleCollapse' ], LOW_PRIORITY$d, function(e) {
|
42382 | var shape = e.context.shape,
|
42383 | defaultSize = elementFactory._getDefaultSize(shape),
|
42384 | newBounds;
|
42385 |
|
42386 | if (shape.collapsed) {
|
42387 |
|
42388 |
|
42389 | newBounds = collapsedBounds(shape, defaultSize);
|
42390 | } else {
|
42391 |
|
42392 |
|
42393 | newBounds = expandedBounds(shape, defaultSize);
|
42394 | }
|
42395 |
|
42396 | modeling.resizeShape(shape, newBounds, null, {
|
42397 | autoResize: shape.collapsed ? false : 'nwse'
|
42398 | });
|
42399 | });
|
42400 |
|
42401 | }
|
42402 |
|
42403 |
|
42404 | inherits_browser(ToggleElementCollapseBehaviour, CommandInterceptor);
|
42405 |
|
42406 | ToggleElementCollapseBehaviour.$inject = [
|
42407 | 'eventBus',
|
42408 | 'elementFactory',
|
42409 | 'modeling'
|
42410 | ];
|
42411 |
|
42412 |
|
42413 |
|
42414 |
|
42415 | function filterVisible(elements) {
|
42416 | return elements.filter(function(e) {
|
42417 | return !e.hidden;
|
42418 | });
|
42419 | }
|
42420 |
|
42421 | |
42422 |
|
42423 |
|
42424 |
|
42425 |
|
42426 |
|
42427 |
|
42428 |
|
42429 | function UnclaimIdBehavior(canvas, injector, moddle, modeling) {
|
42430 | injector.invoke(CommandInterceptor, this);
|
42431 |
|
42432 | this.preExecute('shape.delete', function(event) {
|
42433 | var context = event.context,
|
42434 | shape = context.shape,
|
42435 | shapeBo = shape.businessObject;
|
42436 |
|
42437 | if (isLabel(shape)) {
|
42438 | return;
|
42439 | }
|
42440 |
|
42441 | if (is$1(shape, 'bpmn:Participant') && isExpanded(shape)) {
|
42442 | moddle.ids.unclaim(shapeBo.processRef.id);
|
42443 | }
|
42444 |
|
42445 | modeling.unclaimId(shapeBo.id, shapeBo);
|
42446 | });
|
42447 |
|
42448 |
|
42449 | this.preExecute('connection.delete', function(event) {
|
42450 | var context = event.context,
|
42451 | connection = context.connection,
|
42452 | connectionBo = connection.businessObject;
|
42453 |
|
42454 | modeling.unclaimId(connectionBo.id, connectionBo);
|
42455 | });
|
42456 |
|
42457 | this.preExecute('canvas.updateRoot', function() {
|
42458 | var rootElement = canvas.getRootElement(),
|
42459 | rootElementBo = rootElement.businessObject;
|
42460 |
|
42461 | moddle.ids.unclaim(rootElementBo.id);
|
42462 | });
|
42463 | }
|
42464 |
|
42465 | inherits_browser(UnclaimIdBehavior, CommandInterceptor);
|
42466 |
|
42467 | UnclaimIdBehavior.$inject = [ 'canvas', 'injector', 'moddle', 'modeling' ];
|
42468 |
|
42469 | var LOW_PRIORITY$e = 500,
|
42470 | HIGH_PRIORITY$a = 5000;
|
42471 |
|
42472 |
|
42473 | |
42474 |
|
42475 |
|
42476 | function UpdateFlowNodeRefsBehavior(eventBus, modeling, translate) {
|
42477 |
|
42478 | CommandInterceptor.call(this, eventBus);
|
42479 |
|
42480 | |
42481 |
|
42482 |
|
42483 |
|
42484 |
|
42485 |
|
42486 |
|
42487 |
|
42488 |
|
42489 |
|
42490 |
|
42491 |
|
42492 |
|
42493 |
|
42494 | var context;
|
42495 |
|
42496 |
|
42497 | function initContext() {
|
42498 | context = context || new UpdateContext();
|
42499 | context.enter();
|
42500 |
|
42501 | return context;
|
42502 | }
|
42503 |
|
42504 | function getContext() {
|
42505 | if (!context) {
|
42506 | throw new Error(translate('out of bounds release'));
|
42507 | }
|
42508 |
|
42509 | return context;
|
42510 | }
|
42511 |
|
42512 | function releaseContext() {
|
42513 |
|
42514 | if (!context) {
|
42515 | throw new Error(translate('out of bounds release'));
|
42516 | }
|
42517 |
|
42518 | var triggerUpdate = context.leave();
|
42519 |
|
42520 | if (triggerUpdate) {
|
42521 | modeling.updateLaneRefs(context.flowNodes, context.lanes);
|
42522 |
|
42523 | context = null;
|
42524 | }
|
42525 |
|
42526 | return triggerUpdate;
|
42527 | }
|
42528 |
|
42529 |
|
42530 | var laneRefUpdateEvents = [
|
42531 | 'spaceTool',
|
42532 | 'lane.add',
|
42533 | 'lane.resize',
|
42534 | 'lane.split',
|
42535 | 'elements.create',
|
42536 | 'elements.delete',
|
42537 | 'elements.move',
|
42538 | 'shape.create',
|
42539 | 'shape.delete',
|
42540 | 'shape.move',
|
42541 | 'shape.resize'
|
42542 | ];
|
42543 |
|
42544 |
|
42545 |
|
42546 |
|
42547 | this.preExecute(laneRefUpdateEvents, HIGH_PRIORITY$a, function(event) {
|
42548 | initContext();
|
42549 | });
|
42550 |
|
42551 | this.postExecuted(laneRefUpdateEvents, LOW_PRIORITY$e, function(event) {
|
42552 | releaseContext();
|
42553 | });
|
42554 |
|
42555 |
|
42556 |
|
42557 |
|
42558 | this.preExecute([
|
42559 | 'shape.create',
|
42560 | 'shape.move',
|
42561 | 'shape.delete',
|
42562 | 'shape.resize'
|
42563 | ], function(event) {
|
42564 |
|
42565 | var context = event.context,
|
42566 | shape = context.shape;
|
42567 |
|
42568 | var updateContext = getContext();
|
42569 |
|
42570 |
|
42571 | if (shape.labelTarget) {
|
42572 | return;
|
42573 | }
|
42574 |
|
42575 | if (is$1(shape, 'bpmn:Lane')) {
|
42576 | updateContext.addLane(shape);
|
42577 | }
|
42578 |
|
42579 | if (is$1(shape, 'bpmn:FlowNode')) {
|
42580 | updateContext.addFlowNode(shape);
|
42581 | }
|
42582 | });
|
42583 | }
|
42584 |
|
42585 | UpdateFlowNodeRefsBehavior.$inject = [
|
42586 | 'eventBus',
|
42587 | 'modeling' ,
|
42588 | 'translate'
|
42589 | ];
|
42590 |
|
42591 | inherits_browser(UpdateFlowNodeRefsBehavior, CommandInterceptor);
|
42592 |
|
42593 |
|
42594 | function UpdateContext() {
|
42595 |
|
42596 | this.flowNodes = [];
|
42597 | this.lanes = [];
|
42598 |
|
42599 | this.counter = 0;
|
42600 |
|
42601 | this.addLane = function(lane) {
|
42602 | this.lanes.push(lane);
|
42603 | };
|
42604 |
|
42605 | this.addFlowNode = function(flowNode) {
|
42606 | this.flowNodes.push(flowNode);
|
42607 | };
|
42608 |
|
42609 | this.enter = function() {
|
42610 | this.counter++;
|
42611 | };
|
42612 |
|
42613 | this.leave = function() {
|
42614 | this.counter--;
|
42615 |
|
42616 | return !this.counter;
|
42617 | };
|
42618 | }
|
42619 |
|
42620 | |
42621 |
|
42622 |
|
42623 |
|
42624 |
|
42625 |
|
42626 |
|
42627 |
|
42628 | function DeleteSequenceFlowBehavior(eventBus, modeling) {
|
42629 |
|
42630 | CommandInterceptor.call(this, eventBus);
|
42631 |
|
42632 |
|
42633 | this.preExecute('connection.delete', function(event) {
|
42634 | var context = event.context,
|
42635 | connection = context.connection,
|
42636 | source = connection.source;
|
42637 |
|
42638 | if (isDefaultFlow(connection, source)) {
|
42639 | modeling.updateProperties(source, {
|
42640 | 'default': null
|
42641 | });
|
42642 | }
|
42643 | });
|
42644 | }
|
42645 |
|
42646 | inherits_browser(DeleteSequenceFlowBehavior, CommandInterceptor);
|
42647 |
|
42648 | DeleteSequenceFlowBehavior.$inject = [
|
42649 | 'eventBus',
|
42650 | 'modeling'
|
42651 | ];
|
42652 |
|
42653 |
|
42654 |
|
42655 |
|
42656 | function isDefaultFlow(connection, source) {
|
42657 |
|
42658 | if (!is$1(connection, 'bpmn:SequenceFlow')) {
|
42659 | return false;
|
42660 | }
|
42661 |
|
42662 | var sourceBo = getBusinessObject(source),
|
42663 | sequenceFlow = getBusinessObject(connection);
|
42664 |
|
42665 | return sourceBo.get('default') === sequenceFlow;
|
42666 | }
|
42667 |
|
42668 | var BehaviorModule = {
|
42669 | __init__: [
|
42670 | 'adaptiveLabelPositioningBehavior',
|
42671 | 'appendBehavior',
|
42672 | 'associationBehavior',
|
42673 | 'attachEventBehavior',
|
42674 | 'boundaryEventBehavior',
|
42675 | 'rootElementReferenceBehavior',
|
42676 | 'createBehavior',
|
42677 | 'fixHoverBehavior',
|
42678 | 'createDataObjectBehavior',
|
42679 | 'createParticipantBehavior',
|
42680 | 'dataStoreBehavior',
|
42681 | 'dataInputAssociationBehavior',
|
42682 | 'deleteLaneBehavior',
|
42683 | 'detachEventBehavior',
|
42684 | 'dropOnFlowBehavior',
|
42685 | 'eventBasedGatewayBehavior',
|
42686 | 'groupBehavior',
|
42687 | 'importDockingFix',
|
42688 | 'isHorizontalFix',
|
42689 | 'labelBehavior',
|
42690 | 'modelingFeedback',
|
42691 | 'removeElementBehavior',
|
42692 | 'removeParticipantBehavior',
|
42693 | 'replaceConnectionBehavior',
|
42694 | 'replaceElementBehaviour',
|
42695 | 'resizeBehavior',
|
42696 | 'resizeLaneBehavior',
|
42697 | 'toggleElementCollapseBehaviour',
|
42698 | 'subProcessStartEventBehavior',
|
42699 | 'unclaimIdBehavior',
|
42700 | 'unsetDefaultFlowBehavior',
|
42701 | 'updateFlowNodeRefsBehavior'
|
42702 | ],
|
42703 | adaptiveLabelPositioningBehavior: [ 'type', AdaptiveLabelPositioningBehavior ],
|
42704 | appendBehavior: [ 'type', AppendBehavior ],
|
42705 | associationBehavior: [ 'type', AssociationBehavior ],
|
42706 | attachEventBehavior: [ 'type', AttachEventBehavior ],
|
42707 | boundaryEventBehavior: [ 'type', BoundaryEventBehavior ],
|
42708 | rootElementReferenceBehavior: [ 'type', RootElementReferenceBehavior ],
|
42709 | createBehavior: [ 'type', CreateBehavior ],
|
42710 | fixHoverBehavior: [ 'type', FixHoverBehavior ],
|
42711 | createDataObjectBehavior: [ 'type', CreateDataObjectBehavior ],
|
42712 | createParticipantBehavior: [ 'type', CreateParticipantBehavior$1 ],
|
42713 | dataInputAssociationBehavior: [ 'type', DataInputAssociationBehavior ],
|
42714 | dataStoreBehavior: [ 'type', DataStoreBehavior ],
|
42715 | deleteLaneBehavior: [ 'type', DeleteLaneBehavior ],
|
42716 | detachEventBehavior: [ 'type', DetachEventBehavior ],
|
42717 | dropOnFlowBehavior: [ 'type', DropOnFlowBehavior ],
|
42718 | eventBasedGatewayBehavior: [ 'type', EventBasedGatewayBehavior ],
|
42719 | groupBehavior: [ 'type', GroupBehavior ],
|
42720 | importDockingFix: [ 'type', ImportDockingFix ],
|
42721 | isHorizontalFix: [ 'type', IsHorizontalFix ],
|
42722 | labelBehavior: [ 'type', LabelBehavior ],
|
42723 | modelingFeedback: [ 'type', ModelingFeedback ],
|
42724 | replaceConnectionBehavior: [ 'type', ReplaceConnectionBehavior ],
|
42725 | removeParticipantBehavior: [ 'type', RemoveParticipantBehavior ],
|
42726 | replaceElementBehaviour: [ 'type', ReplaceElementBehaviour ],
|
42727 | resizeBehavior: [ 'type', ResizeBehavior$1 ],
|
42728 | resizeLaneBehavior: [ 'type', ResizeLaneBehavior ],
|
42729 | removeElementBehavior: [ 'type', RemoveElementBehavior ],
|
42730 | toggleElementCollapseBehaviour : [ 'type', ToggleElementCollapseBehaviour ],
|
42731 | subProcessStartEventBehavior: [ 'type', SubProcessStartEventBehavior ],
|
42732 | unclaimIdBehavior: [ 'type', UnclaimIdBehavior ],
|
42733 | updateFlowNodeRefsBehavior: [ 'type', UpdateFlowNodeRefsBehavior ],
|
42734 | unsetDefaultFlowBehavior: [ 'type', DeleteSequenceFlowBehavior ]
|
42735 | };
|
42736 |
|
42737 | function getBoundaryAttachment(position, targetBounds) {
|
42738 |
|
42739 | var orientation = getOrientation(position, targetBounds, -15);
|
42740 |
|
42741 | if (orientation !== 'intersect') {
|
42742 | return orientation;
|
42743 | } else {
|
42744 | return null;
|
42745 | }
|
42746 | }
|
42747 |
|
42748 | |
42749 |
|
42750 |
|
42751 | function BpmnRules(eventBus) {
|
42752 | RuleProvider.call(this, eventBus);
|
42753 | }
|
42754 |
|
42755 | inherits_browser(BpmnRules, RuleProvider);
|
42756 |
|
42757 | BpmnRules.$inject = [ 'eventBus' ];
|
42758 |
|
42759 | BpmnRules.prototype.init = function() {
|
42760 |
|
42761 | this.addRule('connection.start', function(context) {
|
42762 | var source = context.source;
|
42763 |
|
42764 | return canStartConnection(source);
|
42765 | });
|
42766 |
|
42767 | this.addRule('connection.create', function(context) {
|
42768 | var source = context.source,
|
42769 | target = context.target,
|
42770 | hints = context.hints || {},
|
42771 | targetParent = hints.targetParent,
|
42772 | targetAttach = hints.targetAttach;
|
42773 |
|
42774 |
|
42775 |
|
42776 |
|
42777 | if (targetAttach) {
|
42778 | return false;
|
42779 | }
|
42780 |
|
42781 |
|
42782 |
|
42783 | if (targetParent) {
|
42784 | target.parent = targetParent;
|
42785 | }
|
42786 |
|
42787 | try {
|
42788 | return canConnect(source, target);
|
42789 | } finally {
|
42790 |
|
42791 |
|
42792 | if (targetParent) {
|
42793 | target.parent = null;
|
42794 | }
|
42795 | }
|
42796 | });
|
42797 |
|
42798 | this.addRule('connection.reconnect', function(context) {
|
42799 |
|
42800 | var connection = context.connection,
|
42801 | source = context.source,
|
42802 | target = context.target;
|
42803 |
|
42804 | return canConnect(source, target, connection);
|
42805 | });
|
42806 |
|
42807 | this.addRule('connection.updateWaypoints', function(context) {
|
42808 | return {
|
42809 | type: context.connection.type
|
42810 | };
|
42811 | });
|
42812 |
|
42813 | this.addRule('shape.resize', function(context) {
|
42814 |
|
42815 | var shape = context.shape,
|
42816 | newBounds = context.newBounds;
|
42817 |
|
42818 | return canResize(shape, newBounds);
|
42819 | });
|
42820 |
|
42821 | this.addRule('elements.create', function(context) {
|
42822 | var elements = context.elements,
|
42823 | position = context.position,
|
42824 | target = context.target;
|
42825 |
|
42826 | return every(elements, function(element) {
|
42827 | if (isConnection$3(element)) {
|
42828 | return canConnect(element.source, element.target, element);
|
42829 | }
|
42830 |
|
42831 | if (element.host) {
|
42832 | return canAttach(element, element.host, null, position);
|
42833 | }
|
42834 |
|
42835 | return canCreate(element, target, null);
|
42836 | });
|
42837 | });
|
42838 |
|
42839 | this.addRule('elements.move', function(context) {
|
42840 |
|
42841 | var target = context.target,
|
42842 | shapes = context.shapes,
|
42843 | position = context.position;
|
42844 |
|
42845 | return canAttach(shapes, target, null, position) ||
|
42846 | canReplace(shapes, target, position) ||
|
42847 | canMove(shapes, target) ||
|
42848 | canInsert(shapes, target);
|
42849 | });
|
42850 |
|
42851 | this.addRule('shape.create', function(context) {
|
42852 | return canCreate(
|
42853 | context.shape,
|
42854 | context.target,
|
42855 | context.source,
|
42856 | context.position
|
42857 | );
|
42858 | });
|
42859 |
|
42860 | this.addRule('shape.attach', function(context) {
|
42861 |
|
42862 | return canAttach(
|
42863 | context.shape,
|
42864 | context.target,
|
42865 | null,
|
42866 | context.position
|
42867 | );
|
42868 | });
|
42869 |
|
42870 | this.addRule('element.copy', function(context) {
|
42871 | var element = context.element,
|
42872 | elements = context.elements;
|
42873 |
|
42874 | return canCopy(elements, element);
|
42875 | });
|
42876 | };
|
42877 |
|
42878 | BpmnRules.prototype.canConnectMessageFlow = canConnectMessageFlow;
|
42879 |
|
42880 | BpmnRules.prototype.canConnectSequenceFlow = canConnectSequenceFlow;
|
42881 |
|
42882 | BpmnRules.prototype.canConnectDataAssociation = canConnectDataAssociation;
|
42883 |
|
42884 | BpmnRules.prototype.canConnectAssociation = canConnectAssociation;
|
42885 |
|
42886 | BpmnRules.prototype.canMove = canMove;
|
42887 |
|
42888 | BpmnRules.prototype.canAttach = canAttach;
|
42889 |
|
42890 | BpmnRules.prototype.canReplace = canReplace;
|
42891 |
|
42892 | BpmnRules.prototype.canDrop = canDrop;
|
42893 |
|
42894 | BpmnRules.prototype.canInsert = canInsert;
|
42895 |
|
42896 | BpmnRules.prototype.canCreate = canCreate;
|
42897 |
|
42898 | BpmnRules.prototype.canConnect = canConnect;
|
42899 |
|
42900 | BpmnRules.prototype.canResize = canResize;
|
42901 |
|
42902 | BpmnRules.prototype.canCopy = canCopy;
|
42903 |
|
42904 | |
42905 |
|
42906 |
|
42907 |
|
42908 | |
42909 |
|
42910 |
|
42911 |
|
42912 |
|
42913 |
|
42914 | function canStartConnection(element) {
|
42915 | if (nonExistingOrLabel(element)) {
|
42916 | return null;
|
42917 | }
|
42918 |
|
42919 | return isAny(element, [
|
42920 | 'bpmn:FlowNode',
|
42921 | 'bpmn:InteractionNode',
|
42922 | 'bpmn:DataObjectReference',
|
42923 | 'bpmn:DataStoreReference'
|
42924 | ]);
|
42925 | }
|
42926 |
|
42927 | function nonExistingOrLabel(element) {
|
42928 | return !element || isLabel(element);
|
42929 | }
|
42930 |
|
42931 | function isSame(a, b) {
|
42932 | return a === b;
|
42933 | }
|
42934 |
|
42935 | function getOrganizationalParent(element) {
|
42936 |
|
42937 | do {
|
42938 | if (is$1(element, 'bpmn:Process')) {
|
42939 | return getBusinessObject(element);
|
42940 | }
|
42941 |
|
42942 | if (is$1(element, 'bpmn:Participant')) {
|
42943 | return (
|
42944 | getBusinessObject(element).processRef ||
|
42945 | getBusinessObject(element)
|
42946 | );
|
42947 | }
|
42948 | } while ((element = element.parent));
|
42949 |
|
42950 | }
|
42951 |
|
42952 | function isTextAnnotation(element) {
|
42953 | return is$1(element, 'bpmn:TextAnnotation');
|
42954 | }
|
42955 |
|
42956 | function isGroup(element) {
|
42957 | return is$1(element, 'bpmn:Group') && !element.labelTarget;
|
42958 | }
|
42959 |
|
42960 | function isCompensationBoundary(element) {
|
42961 | return is$1(element, 'bpmn:BoundaryEvent') &&
|
42962 | hasEventDefinition$2(element, 'bpmn:CompensateEventDefinition');
|
42963 | }
|
42964 |
|
42965 | function isForCompensation(e) {
|
42966 | return getBusinessObject(e).isForCompensation;
|
42967 | }
|
42968 |
|
42969 | function isSameOrganization(a, b) {
|
42970 | var parentA = getOrganizationalParent(a),
|
42971 | parentB = getOrganizationalParent(b);
|
42972 |
|
42973 | return parentA === parentB;
|
42974 | }
|
42975 |
|
42976 | function isMessageFlowSource(element) {
|
42977 | return (
|
42978 | is$1(element, 'bpmn:InteractionNode') && (
|
42979 | !is$1(element, 'bpmn:Event') || (
|
42980 | is$1(element, 'bpmn:ThrowEvent') &&
|
42981 | hasEventDefinitionOrNone(element, 'bpmn:MessageEventDefinition')
|
42982 | )
|
42983 | )
|
42984 | );
|
42985 | }
|
42986 |
|
42987 | function isMessageFlowTarget(element) {
|
42988 | return (
|
42989 | is$1(element, 'bpmn:InteractionNode') &&
|
42990 | !isForCompensation(element) && (
|
42991 | !is$1(element, 'bpmn:Event') || (
|
42992 | is$1(element, 'bpmn:CatchEvent') &&
|
42993 | hasEventDefinitionOrNone(element, 'bpmn:MessageEventDefinition')
|
42994 | )
|
42995 | )
|
42996 | );
|
42997 | }
|
42998 |
|
42999 | function getScopeParent(element) {
|
43000 |
|
43001 | var parent = element;
|
43002 |
|
43003 | while ((parent = parent.parent)) {
|
43004 |
|
43005 | if (is$1(parent, 'bpmn:FlowElementsContainer')) {
|
43006 | return getBusinessObject(parent);
|
43007 | }
|
43008 |
|
43009 | if (is$1(parent, 'bpmn:Participant')) {
|
43010 | return getBusinessObject(parent).processRef;
|
43011 | }
|
43012 | }
|
43013 |
|
43014 | return null;
|
43015 | }
|
43016 |
|
43017 | function isSameScope(a, b) {
|
43018 | var scopeParentA = getScopeParent(a),
|
43019 | scopeParentB = getScopeParent(b);
|
43020 |
|
43021 | return scopeParentA === scopeParentB;
|
43022 | }
|
43023 |
|
43024 | function hasEventDefinition$2(element, eventDefinition) {
|
43025 | var bo = getBusinessObject(element);
|
43026 |
|
43027 | return !!find(bo.eventDefinitions || [], function(definition) {
|
43028 | return is$1(definition, eventDefinition);
|
43029 | });
|
43030 | }
|
43031 |
|
43032 | function hasEventDefinitionOrNone(element, eventDefinition) {
|
43033 | var bo = getBusinessObject(element);
|
43034 |
|
43035 | return (bo.eventDefinitions || []).every(function(definition) {
|
43036 | return is$1(definition, eventDefinition);
|
43037 | });
|
43038 | }
|
43039 |
|
43040 | function isSequenceFlowSource(element) {
|
43041 | return (
|
43042 | is$1(element, 'bpmn:FlowNode') &&
|
43043 | !is$1(element, 'bpmn:EndEvent') &&
|
43044 | !isEventSubProcess(element) &&
|
43045 | !(is$1(element, 'bpmn:IntermediateThrowEvent') &&
|
43046 | hasEventDefinition$2(element, 'bpmn:LinkEventDefinition')
|
43047 | ) &&
|
43048 | !isCompensationBoundary(element) &&
|
43049 | !isForCompensation(element)
|
43050 | );
|
43051 | }
|
43052 |
|
43053 | function isSequenceFlowTarget(element) {
|
43054 | return (
|
43055 | is$1(element, 'bpmn:FlowNode') &&
|
43056 | !is$1(element, 'bpmn:StartEvent') &&
|
43057 | !is$1(element, 'bpmn:BoundaryEvent') &&
|
43058 | !isEventSubProcess(element) &&
|
43059 | !(is$1(element, 'bpmn:IntermediateCatchEvent') &&
|
43060 | hasEventDefinition$2(element, 'bpmn:LinkEventDefinition')
|
43061 | ) &&
|
43062 | !isForCompensation(element)
|
43063 | );
|
43064 | }
|
43065 |
|
43066 | function isEventBasedTarget(element) {
|
43067 | return (
|
43068 | is$1(element, 'bpmn:ReceiveTask') || (
|
43069 | is$1(element, 'bpmn:IntermediateCatchEvent') && (
|
43070 | hasEventDefinition$2(element, 'bpmn:MessageEventDefinition') ||
|
43071 | hasEventDefinition$2(element, 'bpmn:TimerEventDefinition') ||
|
43072 | hasEventDefinition$2(element, 'bpmn:ConditionalEventDefinition') ||
|
43073 | hasEventDefinition$2(element, 'bpmn:SignalEventDefinition')
|
43074 | )
|
43075 | )
|
43076 | );
|
43077 | }
|
43078 |
|
43079 | function isConnection$3(element) {
|
43080 | return element.waypoints;
|
43081 | }
|
43082 |
|
43083 | function getParents$1(element) {
|
43084 |
|
43085 | var parents = [];
|
43086 |
|
43087 | while (element) {
|
43088 | element = element.parent;
|
43089 |
|
43090 | if (element) {
|
43091 | parents.push(element);
|
43092 | }
|
43093 | }
|
43094 |
|
43095 | return parents;
|
43096 | }
|
43097 |
|
43098 | function isParent(possibleParent, element) {
|
43099 | var allParents = getParents$1(element);
|
43100 | return allParents.indexOf(possibleParent) !== -1;
|
43101 | }
|
43102 |
|
43103 | function canConnect(source, target, connection) {
|
43104 |
|
43105 | if (nonExistingOrLabel(source) || nonExistingOrLabel(target)) {
|
43106 | return null;
|
43107 | }
|
43108 |
|
43109 | if (!is$1(connection, 'bpmn:DataAssociation')) {
|
43110 |
|
43111 | if (canConnectMessageFlow(source, target)) {
|
43112 | return { type: 'bpmn:MessageFlow' };
|
43113 | }
|
43114 |
|
43115 | if (canConnectSequenceFlow(source, target)) {
|
43116 | return { type: 'bpmn:SequenceFlow' };
|
43117 | }
|
43118 | }
|
43119 |
|
43120 | var connectDataAssociation = canConnectDataAssociation(source, target);
|
43121 |
|
43122 | if (connectDataAssociation) {
|
43123 | return connectDataAssociation;
|
43124 | }
|
43125 |
|
43126 | if (isCompensationBoundary(source) && isForCompensation(target)) {
|
43127 | return {
|
43128 | type: 'bpmn:Association',
|
43129 | associationDirection: 'One'
|
43130 | };
|
43131 | }
|
43132 |
|
43133 | if (canConnectAssociation(source, target)) {
|
43134 |
|
43135 | return {
|
43136 | type: 'bpmn:Association'
|
43137 | };
|
43138 | }
|
43139 |
|
43140 | return false;
|
43141 | }
|
43142 |
|
43143 | |
43144 |
|
43145 |
|
43146 |
|
43147 |
|
43148 | function canDrop(element, target, position) {
|
43149 |
|
43150 |
|
43151 | if (isLabel(element) || isGroup(element)) {
|
43152 | return true;
|
43153 | }
|
43154 |
|
43155 |
|
43156 |
|
43157 | if (is$1(target, 'bpmn:Participant') && !isExpanded(target)) {
|
43158 | return false;
|
43159 | }
|
43160 |
|
43161 |
|
43162 |
|
43163 | if (is$1(element, 'bpmn:Participant')) {
|
43164 | return is$1(target, 'bpmn:Process') || is$1(target, 'bpmn:Collaboration');
|
43165 | }
|
43166 |
|
43167 |
|
43168 | if (isAny(element, [ 'bpmn:DataInput', 'bpmn:DataOutput' ])) {
|
43169 |
|
43170 | if (element.parent) {
|
43171 | return target === element.parent;
|
43172 | }
|
43173 | }
|
43174 |
|
43175 |
|
43176 | if (is$1(element, 'bpmn:Lane')) {
|
43177 | return is$1(target, 'bpmn:Participant') || is$1(target, 'bpmn:Lane');
|
43178 | }
|
43179 |
|
43180 |
|
43181 | if (is$1(element, 'bpmn:BoundaryEvent') && !isDroppableBoundaryEvent(element)) {
|
43182 | return false;
|
43183 | }
|
43184 |
|
43185 |
|
43186 |
|
43187 | if (is$1(element, 'bpmn:FlowElement') && !is$1(element, 'bpmn:DataStoreReference')) {
|
43188 | if (is$1(target, 'bpmn:FlowElementsContainer')) {
|
43189 | return isExpanded(target);
|
43190 | }
|
43191 |
|
43192 | return isAny(target, [ 'bpmn:Participant', 'bpmn:Lane' ]);
|
43193 | }
|
43194 |
|
43195 |
|
43196 |
|
43197 |
|
43198 |
|
43199 | if (isAny(element, [ 'bpmn:Artifact', 'bpmn:DataAssociation', 'bpmn:DataStoreReference' ])) {
|
43200 | return isAny(target, [
|
43201 | 'bpmn:Collaboration',
|
43202 | 'bpmn:Lane',
|
43203 | 'bpmn:Participant',
|
43204 | 'bpmn:Process',
|
43205 | 'bpmn:SubProcess' ]);
|
43206 | }
|
43207 |
|
43208 | if (is$1(element, 'bpmn:MessageFlow')) {
|
43209 | return is$1(target, 'bpmn:Collaboration')
|
43210 | || element.source.parent == target
|
43211 | || element.target.parent == target;
|
43212 | }
|
43213 |
|
43214 | return false;
|
43215 | }
|
43216 |
|
43217 | function isDroppableBoundaryEvent(event) {
|
43218 | return getBusinessObject(event).cancelActivity && (
|
43219 | hasNoEventDefinition(event) || hasCommonBoundaryIntermediateEventDefinition(event)
|
43220 | );
|
43221 | }
|
43222 |
|
43223 | function isBoundaryEvent(element) {
|
43224 | return !isLabel(element) && is$1(element, 'bpmn:BoundaryEvent');
|
43225 | }
|
43226 |
|
43227 | function isLane(element) {
|
43228 | return is$1(element, 'bpmn:Lane');
|
43229 | }
|
43230 |
|
43231 | |
43232 |
|
43233 |
|
43234 |
|
43235 | function isBoundaryCandidate(element) {
|
43236 | if (isBoundaryEvent(element)) {
|
43237 | return true;
|
43238 | }
|
43239 |
|
43240 | if (is$1(element, 'bpmn:IntermediateThrowEvent') && hasNoEventDefinition(element)) {
|
43241 | return true;
|
43242 | }
|
43243 |
|
43244 | return (
|
43245 | is$1(element, 'bpmn:IntermediateCatchEvent') &&
|
43246 | hasCommonBoundaryIntermediateEventDefinition(element)
|
43247 | );
|
43248 | }
|
43249 |
|
43250 | function hasNoEventDefinition(element) {
|
43251 | var bo = getBusinessObject(element);
|
43252 |
|
43253 | return bo && !(bo.eventDefinitions && bo.eventDefinitions.length);
|
43254 | }
|
43255 |
|
43256 | function hasCommonBoundaryIntermediateEventDefinition(element) {
|
43257 | return hasOneOfEventDefinitions(element, [
|
43258 | 'bpmn:MessageEventDefinition',
|
43259 | 'bpmn:TimerEventDefinition',
|
43260 | 'bpmn:SignalEventDefinition',
|
43261 | 'bpmn:ConditionalEventDefinition'
|
43262 | ]);
|
43263 | }
|
43264 |
|
43265 | function hasOneOfEventDefinitions(element, eventDefinitions) {
|
43266 | return eventDefinitions.some(function(definition) {
|
43267 | return hasEventDefinition$2(element, definition);
|
43268 | });
|
43269 | }
|
43270 |
|
43271 | function isReceiveTaskAfterEventBasedGateway(element) {
|
43272 | return (
|
43273 | is$1(element, 'bpmn:ReceiveTask') &&
|
43274 | find(element.incoming, function(incoming) {
|
43275 | return is$1(incoming.source, 'bpmn:EventBasedGateway');
|
43276 | })
|
43277 | );
|
43278 | }
|
43279 |
|
43280 |
|
43281 | function canAttach(elements, target, source, position) {
|
43282 |
|
43283 | if (!Array.isArray(elements)) {
|
43284 | elements = [ elements ];
|
43285 | }
|
43286 |
|
43287 |
|
43288 | if (elements.length !== 1) {
|
43289 | return false;
|
43290 | }
|
43291 |
|
43292 | var element = elements[0];
|
43293 |
|
43294 |
|
43295 | if (isLabel(element)) {
|
43296 | return false;
|
43297 | }
|
43298 |
|
43299 |
|
43300 | if (!isBoundaryCandidate(element)) {
|
43301 | return false;
|
43302 | }
|
43303 |
|
43304 |
|
43305 | if (isEventSubProcess(target)) {
|
43306 | return false;
|
43307 | }
|
43308 |
|
43309 |
|
43310 | if (!is$1(target, 'bpmn:Activity') || isForCompensation(target)) {
|
43311 | return false;
|
43312 | }
|
43313 |
|
43314 |
|
43315 | if (position && !getBoundaryAttachment(position, target)) {
|
43316 | return false;
|
43317 | }
|
43318 |
|
43319 |
|
43320 | if (isReceiveTaskAfterEventBasedGateway(target)) {
|
43321 | return false;
|
43322 | }
|
43323 |
|
43324 | return 'attach';
|
43325 | }
|
43326 |
|
43327 |
|
43328 | |
43329 |
|
43330 |
|
43331 |
|
43332 |
|
43333 |
|
43334 |
|
43335 |
|
43336 |
|
43337 |
|
43338 |
|
43339 |
|
43340 |
|
43341 |
|
43342 |
|
43343 |
|
43344 |
|
43345 |
|
43346 |
|
43347 | function canReplace(elements, target, position) {
|
43348 |
|
43349 | if (!target) {
|
43350 | return false;
|
43351 | }
|
43352 |
|
43353 | var canExecute = {
|
43354 | replacements: []
|
43355 | };
|
43356 |
|
43357 | forEach(elements, function(element) {
|
43358 |
|
43359 | if (!isEventSubProcess(target)) {
|
43360 |
|
43361 | if (is$1(element, 'bpmn:StartEvent') &&
|
43362 | element.type !== 'label' &&
|
43363 | canDrop(element, target)) {
|
43364 |
|
43365 |
|
43366 |
|
43367 | if (!isInterrupting(element)) {
|
43368 | canExecute.replacements.push({
|
43369 | oldElementId: element.id,
|
43370 | newElementType: 'bpmn:StartEvent'
|
43371 | });
|
43372 | }
|
43373 |
|
43374 |
|
43375 |
|
43376 | if (hasErrorEventDefinition(element) ||
|
43377 | hasEscalationEventDefinition(element) ||
|
43378 | hasCompensateEventDefinition(element)) {
|
43379 | canExecute.replacements.push({
|
43380 | oldElementId: element.id,
|
43381 | newElementType: 'bpmn:StartEvent'
|
43382 | });
|
43383 | }
|
43384 | }
|
43385 | }
|
43386 |
|
43387 | if (!is$1(target, 'bpmn:Transaction')) {
|
43388 | if (hasEventDefinition$2(element, 'bpmn:CancelEventDefinition') &&
|
43389 | element.type !== 'label') {
|
43390 |
|
43391 | if (is$1(element, 'bpmn:EndEvent') && canDrop(element, target)) {
|
43392 | canExecute.replacements.push({
|
43393 | oldElementId: element.id,
|
43394 | newElementType: 'bpmn:EndEvent'
|
43395 | });
|
43396 | }
|
43397 |
|
43398 | if (is$1(element, 'bpmn:BoundaryEvent') && canAttach(element, target, null, position)) {
|
43399 | canExecute.replacements.push({
|
43400 | oldElementId: element.id,
|
43401 | newElementType: 'bpmn:BoundaryEvent'
|
43402 | });
|
43403 | }
|
43404 | }
|
43405 | }
|
43406 | });
|
43407 |
|
43408 | return canExecute.replacements.length ? canExecute : false;
|
43409 | }
|
43410 |
|
43411 | function canMove(elements, target) {
|
43412 |
|
43413 |
|
43414 | if (some(elements, isLane)) {
|
43415 | return false;
|
43416 | }
|
43417 |
|
43418 |
|
43419 | if (!target) {
|
43420 | return true;
|
43421 | }
|
43422 |
|
43423 | return elements.every(function(element) {
|
43424 | return canDrop(element, target);
|
43425 | });
|
43426 | }
|
43427 |
|
43428 | function canCreate(shape, target, source, position) {
|
43429 |
|
43430 | if (!target) {
|
43431 | return false;
|
43432 | }
|
43433 |
|
43434 | if (isLabel(shape) || isGroup(shape)) {
|
43435 | return true;
|
43436 | }
|
43437 |
|
43438 | if (isSame(source, target)) {
|
43439 | return false;
|
43440 | }
|
43441 |
|
43442 |
|
43443 |
|
43444 | if (source && isParent(source, target)) {
|
43445 | return false;
|
43446 | }
|
43447 |
|
43448 | return canDrop(shape, target) || canInsert(shape, target);
|
43449 | }
|
43450 |
|
43451 | function canResize(shape, newBounds) {
|
43452 | if (is$1(shape, 'bpmn:SubProcess')) {
|
43453 | return (
|
43454 | isExpanded(shape) && (
|
43455 | !newBounds || (newBounds.width >= 100 && newBounds.height >= 80)
|
43456 | )
|
43457 | );
|
43458 | }
|
43459 |
|
43460 | if (is$1(shape, 'bpmn:Lane')) {
|
43461 | return !newBounds || (newBounds.width >= 130 && newBounds.height >= 60);
|
43462 | }
|
43463 |
|
43464 | if (is$1(shape, 'bpmn:Participant')) {
|
43465 | return !newBounds || (newBounds.width >= 250 && newBounds.height >= 50);
|
43466 | }
|
43467 |
|
43468 | if (isTextAnnotation(shape)) {
|
43469 | return true;
|
43470 | }
|
43471 |
|
43472 | if (isGroup(shape)) {
|
43473 | return true;
|
43474 | }
|
43475 |
|
43476 | return false;
|
43477 | }
|
43478 |
|
43479 | |
43480 |
|
43481 |
|
43482 |
|
43483 | function isOneTextAnnotation(source, target) {
|
43484 |
|
43485 | var sourceTextAnnotation = isTextAnnotation(source),
|
43486 | targetTextAnnotation = isTextAnnotation(target);
|
43487 |
|
43488 | return (
|
43489 | (sourceTextAnnotation || targetTextAnnotation) &&
|
43490 | (sourceTextAnnotation !== targetTextAnnotation)
|
43491 | );
|
43492 | }
|
43493 |
|
43494 |
|
43495 | function canConnectAssociation(source, target) {
|
43496 |
|
43497 |
|
43498 | if (isConnection$3(source) || isConnection$3(target)) {
|
43499 | return false;
|
43500 | }
|
43501 |
|
43502 |
|
43503 | if (isCompensationBoundary(source) && isForCompensation(target)) {
|
43504 | return true;
|
43505 | }
|
43506 |
|
43507 |
|
43508 | if (isParent(target, source) || isParent(source, target)) {
|
43509 | return false;
|
43510 | }
|
43511 |
|
43512 |
|
43513 | return isOneTextAnnotation(source, target);
|
43514 | }
|
43515 |
|
43516 | function canConnectMessageFlow(source, target) {
|
43517 |
|
43518 |
|
43519 |
|
43520 | if (getRootElement(source) && !getRootElement(target)) {
|
43521 | return false;
|
43522 | }
|
43523 |
|
43524 | return (
|
43525 | isMessageFlowSource(source) &&
|
43526 | isMessageFlowTarget(target) &&
|
43527 | !isSameOrganization(source, target)
|
43528 | );
|
43529 | }
|
43530 |
|
43531 | function canConnectSequenceFlow(source, target) {
|
43532 |
|
43533 | if (
|
43534 | isEventBasedTarget(target) &&
|
43535 | target.incoming.length > 0 &&
|
43536 | areOutgoingEventBasedGatewayConnections(target.incoming) &&
|
43537 | !is$1(source, 'bpmn:EventBasedGateway')
|
43538 | ) {
|
43539 | return false;
|
43540 | }
|
43541 |
|
43542 | return isSequenceFlowSource(source) &&
|
43543 | isSequenceFlowTarget(target) &&
|
43544 | isSameScope(source, target) &&
|
43545 | !(is$1(source, 'bpmn:EventBasedGateway') && !isEventBasedTarget(target));
|
43546 | }
|
43547 |
|
43548 |
|
43549 | function canConnectDataAssociation(source, target) {
|
43550 |
|
43551 | if (isAny(source, [ 'bpmn:DataObjectReference', 'bpmn:DataStoreReference' ]) &&
|
43552 | isAny(target, [ 'bpmn:Activity', 'bpmn:ThrowEvent' ])) {
|
43553 | return { type: 'bpmn:DataInputAssociation' };
|
43554 | }
|
43555 |
|
43556 | if (isAny(target, [ 'bpmn:DataObjectReference', 'bpmn:DataStoreReference' ]) &&
|
43557 | isAny(source, [ 'bpmn:Activity', 'bpmn:CatchEvent' ])) {
|
43558 | return { type: 'bpmn:DataOutputAssociation' };
|
43559 | }
|
43560 |
|
43561 | return false;
|
43562 | }
|
43563 |
|
43564 | function canInsert(shape, flow, position) {
|
43565 |
|
43566 | if (!flow) {
|
43567 | return false;
|
43568 | }
|
43569 |
|
43570 | if (Array.isArray(shape)) {
|
43571 | if (shape.length !== 1) {
|
43572 | return false;
|
43573 | }
|
43574 |
|
43575 | shape = shape[0];
|
43576 | }
|
43577 |
|
43578 | if (flow.source === shape ||
|
43579 | flow.target === shape) {
|
43580 | return false;
|
43581 | }
|
43582 |
|
43583 |
|
43584 |
|
43585 |
|
43586 |
|
43587 |
|
43588 |
|
43589 | return (
|
43590 | isAny(flow, [ 'bpmn:SequenceFlow', 'bpmn:MessageFlow' ]) &&
|
43591 | !isLabel(flow) &&
|
43592 | is$1(shape, 'bpmn:FlowNode') &&
|
43593 | !is$1(shape, 'bpmn:BoundaryEvent') &&
|
43594 | canDrop(shape, flow.parent));
|
43595 | }
|
43596 |
|
43597 | function includes$1(elements, element) {
|
43598 | return (elements && element) && elements.indexOf(element) !== -1;
|
43599 | }
|
43600 |
|
43601 | function canCopy(elements, element) {
|
43602 | if (isLabel(element)) {
|
43603 | return true;
|
43604 | }
|
43605 |
|
43606 | if (is$1(element, 'bpmn:Lane') && !includes$1(elements, element.parent)) {
|
43607 | return false;
|
43608 | }
|
43609 |
|
43610 | return true;
|
43611 | }
|
43612 |
|
43613 | function isOutgoingEventBasedGatewayConnection(connection) {
|
43614 |
|
43615 | if (connection && connection.source) {
|
43616 | return is$1(connection.source, 'bpmn:EventBasedGateway');
|
43617 | }
|
43618 | }
|
43619 |
|
43620 | function areOutgoingEventBasedGatewayConnections(connections) {
|
43621 | connections = connections || [];
|
43622 |
|
43623 | return connections.some(isOutgoingEventBasedGatewayConnection);
|
43624 | }
|
43625 |
|
43626 | function getRootElement(element) {
|
43627 | return getParent$1(element, 'bpmn:Process') || getParent$1(element, 'bpmn:Collaboration');
|
43628 | }
|
43629 |
|
43630 | var RulesModule$1 = {
|
43631 | __depends__: [
|
43632 | RulesModule
|
43633 | ],
|
43634 | __init__: [ 'bpmnRules' ],
|
43635 | bpmnRules: [ 'type', BpmnRules ]
|
43636 | };
|
43637 |
|
43638 | |
43639 |
|
43640 |
|
43641 |
|
43642 |
|
43643 |
|
43644 |
|
43645 |
|
43646 |
|
43647 |
|
43648 |
|
43649 |
|
43650 |
|
43651 |
|
43652 |
|
43653 |
|
43654 |
|
43655 |
|
43656 |
|
43657 |
|
43658 |
|
43659 |
|
43660 |
|
43661 |
|
43662 |
|
43663 |
|
43664 |
|
43665 |
|
43666 |
|
43667 | function OrderingProvider(eventBus) {
|
43668 |
|
43669 | CommandInterceptor.call(this, eventBus);
|
43670 |
|
43671 |
|
43672 | var self = this;
|
43673 |
|
43674 | this.preExecute([ 'shape.create', 'connection.create' ], function(event) {
|
43675 |
|
43676 | var context = event.context,
|
43677 | element = context.shape || context.connection,
|
43678 | parent = context.parent;
|
43679 |
|
43680 | var ordering = self.getOrdering(element, parent);
|
43681 |
|
43682 | if (ordering) {
|
43683 |
|
43684 | if (ordering.parent !== undefined) {
|
43685 | context.parent = ordering.parent;
|
43686 | }
|
43687 |
|
43688 | context.parentIndex = ordering.index;
|
43689 | }
|
43690 | });
|
43691 |
|
43692 | this.preExecute([ 'shape.move', 'connection.move' ], function(event) {
|
43693 |
|
43694 | var context = event.context,
|
43695 | element = context.shape || context.connection,
|
43696 | parent = context.newParent || element.parent;
|
43697 |
|
43698 | var ordering = self.getOrdering(element, parent);
|
43699 |
|
43700 | if (ordering) {
|
43701 |
|
43702 | if (ordering.parent !== undefined) {
|
43703 | context.newParent = ordering.parent;
|
43704 | }
|
43705 |
|
43706 | context.newParentIndex = ordering.index;
|
43707 | }
|
43708 | });
|
43709 | }
|
43710 |
|
43711 | |
43712 |
|
43713 |
|
43714 |
|
43715 |
|
43716 |
|
43717 |
|
43718 |
|
43719 |
|
43720 |
|
43721 |
|
43722 |
|
43723 | OrderingProvider.prototype.getOrdering = function(element, newParent) {
|
43724 | return null;
|
43725 | };
|
43726 |
|
43727 | inherits_browser(OrderingProvider, CommandInterceptor);
|
43728 |
|
43729 | |
43730 |
|
43731 |
|
43732 |
|
43733 |
|
43734 |
|
43735 | function BpmnOrderingProvider(eventBus, canvas, translate) {
|
43736 |
|
43737 | OrderingProvider.call(this, eventBus);
|
43738 |
|
43739 | var orders = [
|
43740 | { type: 'bpmn:SubProcess', order: { level: 6 } },
|
43741 | {
|
43742 | type: 'bpmn:SequenceFlow',
|
43743 | order: {
|
43744 | level: 3,
|
43745 | containers: [
|
43746 | 'bpmn:Participant',
|
43747 | 'bpmn:FlowElementsContainer'
|
43748 | ]
|
43749 | }
|
43750 | },
|
43751 |
|
43752 |
|
43753 | {
|
43754 | type: 'bpmn:DataAssociation',
|
43755 | order: {
|
43756 | level: 9,
|
43757 | containers: [
|
43758 | 'bpmn:Collaboration',
|
43759 | 'bpmn:Process'
|
43760 | ]
|
43761 | }
|
43762 | },
|
43763 | {
|
43764 | type: 'bpmn:MessageFlow', order: {
|
43765 | level: 9,
|
43766 | containers: [ 'bpmn:Collaboration' ]
|
43767 | }
|
43768 | },
|
43769 | {
|
43770 | type: 'bpmn:Association',
|
43771 | order: {
|
43772 | level: 6,
|
43773 | containers: [
|
43774 | 'bpmn:Participant',
|
43775 | 'bpmn:FlowElementsContainer',
|
43776 | 'bpmn:Collaboration'
|
43777 | ]
|
43778 | }
|
43779 | },
|
43780 | { type: 'bpmn:BoundaryEvent', order: { level: 8 } },
|
43781 | {
|
43782 | type: 'bpmn:Group',
|
43783 | order: {
|
43784 | level: 10,
|
43785 | containers: [
|
43786 | 'bpmn:Collaboration',
|
43787 | 'bpmn:Process'
|
43788 | ]
|
43789 | }
|
43790 | },
|
43791 | { type: 'bpmn:FlowElement', order: { level: 5 } },
|
43792 | { type: 'bpmn:Participant', order: { level: -2 } },
|
43793 | { type: 'bpmn:Lane', order: { level: -1 } }
|
43794 | ];
|
43795 |
|
43796 | function computeOrder(element) {
|
43797 | if (element.labelTarget) {
|
43798 | return { level: 10 };
|
43799 | }
|
43800 |
|
43801 | var entry = find(orders, function(o) {
|
43802 | return isAny(element, [ o.type ]);
|
43803 | });
|
43804 |
|
43805 | return entry && entry.order || { level: 1 };
|
43806 | }
|
43807 |
|
43808 | function getOrder(element) {
|
43809 |
|
43810 | var order = element.order;
|
43811 |
|
43812 | if (!order) {
|
43813 | element.order = order = computeOrder(element);
|
43814 | }
|
43815 |
|
43816 | return order;
|
43817 | }
|
43818 |
|
43819 | function findActualParent(element, newParent, containers) {
|
43820 |
|
43821 | var actualParent = newParent;
|
43822 |
|
43823 | while (actualParent) {
|
43824 |
|
43825 | if (isAny(actualParent, containers)) {
|
43826 | break;
|
43827 | }
|
43828 |
|
43829 | actualParent = actualParent.parent;
|
43830 | }
|
43831 |
|
43832 | if (!actualParent) {
|
43833 | throw new Error(translate('no parent for {element} in {parent}', {
|
43834 | element: element.id,
|
43835 | parent: newParent.id
|
43836 | }));
|
43837 | }
|
43838 |
|
43839 | return actualParent;
|
43840 | }
|
43841 |
|
43842 | this.getOrdering = function(element, newParent) {
|
43843 |
|
43844 |
|
43845 | if (element.labelTarget) {
|
43846 | return {
|
43847 | parent: canvas.getRootElement(),
|
43848 | index: -1
|
43849 | };
|
43850 | }
|
43851 |
|
43852 | var elementOrder = getOrder(element);
|
43853 |
|
43854 |
|
43855 | if (elementOrder.containers) {
|
43856 | newParent = findActualParent(element, newParent, elementOrder.containers);
|
43857 | }
|
43858 |
|
43859 |
|
43860 | var currentIndex = newParent.children.indexOf(element);
|
43861 |
|
43862 | var insertIndex = findIndex(newParent.children, function(child) {
|
43863 |
|
43864 |
|
43865 |
|
43866 |
|
43867 | if (!element.labelTarget && child.labelTarget) {
|
43868 | return false;
|
43869 | }
|
43870 |
|
43871 | return elementOrder.level < getOrder(child).level;
|
43872 | });
|
43873 |
|
43874 |
|
43875 |
|
43876 |
|
43877 |
|
43878 |
|
43879 | if (insertIndex !== -1) {
|
43880 | if (currentIndex !== -1 && currentIndex < insertIndex) {
|
43881 | insertIndex -= 1;
|
43882 | }
|
43883 | }
|
43884 |
|
43885 | return {
|
43886 | index: insertIndex,
|
43887 | parent: newParent
|
43888 | };
|
43889 | };
|
43890 | }
|
43891 |
|
43892 | BpmnOrderingProvider.$inject = [ 'eventBus', 'canvas', 'translate' ];
|
43893 |
|
43894 | inherits_browser(BpmnOrderingProvider, OrderingProvider);
|
43895 |
|
43896 | var OrderingModule = {
|
43897 | __depends__: [
|
43898 | translate$2
|
43899 | ],
|
43900 | __init__: [ 'bpmnOrderingProvider' ],
|
43901 | bpmnOrderingProvider: [ 'type', BpmnOrderingProvider ]
|
43902 | };
|
43903 |
|
43904 | |
43905 |
|
43906 |
|
43907 |
|
43908 |
|
43909 |
|
43910 |
|
43911 |
|
43912 |
|
43913 |
|
43914 |
|
43915 |
|
43916 |
|
43917 |
|
43918 |
|
43919 |
|
43920 |
|
43921 |
|
43922 |
|
43923 |
|
43924 |
|
43925 |
|
43926 |
|
43927 |
|
43928 |
|
43929 |
|
43930 |
|
43931 |
|
43932 |
|
43933 |
|
43934 |
|
43935 |
|
43936 |
|
43937 |
|
43938 |
|
43939 |
|
43940 |
|
43941 |
|
43942 |
|
43943 |
|
43944 |
|
43945 |
|
43946 |
|
43947 |
|
43948 |
|
43949 |
|
43950 |
|
43951 |
|
43952 |
|
43953 |
|
43954 |
|
43955 |
|
43956 |
|
43957 |
|
43958 |
|
43959 |
|
43960 |
|
43961 |
|
43962 |
|
43963 |
|
43964 |
|
43965 |
|
43966 |
|
43967 |
|
43968 |
|
43969 |
|
43970 |
|
43971 |
|
43972 |
|
43973 |
|
43974 |
|
43975 |
|
43976 |
|
43977 |
|
43978 |
|
43979 |
|
43980 | function CommandStack(eventBus, injector) {
|
43981 |
|
43982 | |
43983 |
|
43984 |
|
43985 |
|
43986 |
|
43987 | this._handlerMap = {};
|
43988 |
|
43989 | |
43990 |
|
43991 |
|
43992 |
|
43993 |
|
43994 | this._stack = [];
|
43995 |
|
43996 | |
43997 |
|
43998 |
|
43999 |
|
44000 |
|
44001 | this._stackIdx = -1;
|
44002 |
|
44003 | |
44004 |
|
44005 |
|
44006 |
|
44007 |
|
44008 | this._currentExecution = {
|
44009 | actions: [],
|
44010 | dirty: []
|
44011 | };
|
44012 |
|
44013 |
|
44014 | this._injector = injector;
|
44015 | this._eventBus = eventBus;
|
44016 |
|
44017 | this._uid = 1;
|
44018 |
|
44019 | eventBus.on([
|
44020 | 'diagram.destroy',
|
44021 | 'diagram.clear'
|
44022 | ], function() {
|
44023 | this.clear(false);
|
44024 | }, this);
|
44025 | }
|
44026 |
|
44027 | CommandStack.$inject = [ 'eventBus', 'injector' ];
|
44028 |
|
44029 |
|
44030 | |
44031 |
|
44032 |
|
44033 |
|
44034 |
|
44035 |
|
44036 | CommandStack.prototype.execute = function(command, context) {
|
44037 | if (!command) {
|
44038 | throw new Error('command required');
|
44039 | }
|
44040 |
|
44041 | var action = { command: command, context: context };
|
44042 |
|
44043 | this._pushAction(action);
|
44044 | this._internalExecute(action);
|
44045 | this._popAction(action);
|
44046 | };
|
44047 |
|
44048 |
|
44049 | |
44050 |
|
44051 |
|
44052 |
|
44053 |
|
44054 |
|
44055 |
|
44056 |
|
44057 |
|
44058 |
|
44059 |
|
44060 |
|
44061 |
|
44062 |
|
44063 |
|
44064 |
|
44065 |
|
44066 |
|
44067 |
|
44068 |
|
44069 | CommandStack.prototype.canExecute = function(command, context) {
|
44070 |
|
44071 | var action = { command: command, context: context };
|
44072 |
|
44073 | var handler = this._getHandler(command);
|
44074 |
|
44075 | var result = this._fire(command, 'canExecute', action);
|
44076 |
|
44077 |
|
44078 |
|
44079 | if (result === undefined) {
|
44080 | if (!handler) {
|
44081 | return false;
|
44082 | }
|
44083 |
|
44084 | if (handler.canExecute) {
|
44085 | result = handler.canExecute(context);
|
44086 | }
|
44087 | }
|
44088 |
|
44089 | return result;
|
44090 | };
|
44091 |
|
44092 |
|
44093 | |
44094 |
|
44095 |
|
44096 | CommandStack.prototype.clear = function(emit) {
|
44097 | this._stack.length = 0;
|
44098 | this._stackIdx = -1;
|
44099 |
|
44100 | if (emit !== false) {
|
44101 | this._fire('changed');
|
44102 | }
|
44103 | };
|
44104 |
|
44105 |
|
44106 | |
44107 |
|
44108 |
|
44109 | CommandStack.prototype.undo = function() {
|
44110 | var action = this._getUndoAction(),
|
44111 | next;
|
44112 |
|
44113 | if (action) {
|
44114 | this._pushAction(action);
|
44115 |
|
44116 | while (action) {
|
44117 | this._internalUndo(action);
|
44118 | next = this._getUndoAction();
|
44119 |
|
44120 | if (!next || next.id !== action.id) {
|
44121 | break;
|
44122 | }
|
44123 |
|
44124 | action = next;
|
44125 | }
|
44126 |
|
44127 | this._popAction();
|
44128 | }
|
44129 | };
|
44130 |
|
44131 |
|
44132 | |
44133 |
|
44134 |
|
44135 | CommandStack.prototype.redo = function() {
|
44136 | var action = this._getRedoAction(),
|
44137 | next;
|
44138 |
|
44139 | if (action) {
|
44140 | this._pushAction(action);
|
44141 |
|
44142 | while (action) {
|
44143 | this._internalExecute(action, true);
|
44144 | next = this._getRedoAction();
|
44145 |
|
44146 | if (!next || next.id !== action.id) {
|
44147 | break;
|
44148 | }
|
44149 |
|
44150 | action = next;
|
44151 | }
|
44152 |
|
44153 | this._popAction();
|
44154 | }
|
44155 | };
|
44156 |
|
44157 |
|
44158 | |
44159 |
|
44160 |
|
44161 |
|
44162 |
|
44163 |
|
44164 | CommandStack.prototype.register = function(command, handler) {
|
44165 | this._setHandler(command, handler);
|
44166 | };
|
44167 |
|
44168 |
|
44169 | |
44170 |
|
44171 |
|
44172 |
|
44173 |
|
44174 |
|
44175 |
|
44176 | CommandStack.prototype.registerHandler = function(command, handlerCls) {
|
44177 |
|
44178 | if (!command || !handlerCls) {
|
44179 | throw new Error('command and handlerCls must be defined');
|
44180 | }
|
44181 |
|
44182 | var handler = this._injector.instantiate(handlerCls);
|
44183 | this.register(command, handler);
|
44184 | };
|
44185 |
|
44186 | CommandStack.prototype.canUndo = function() {
|
44187 | return !!this._getUndoAction();
|
44188 | };
|
44189 |
|
44190 | CommandStack.prototype.canRedo = function() {
|
44191 | return !!this._getRedoAction();
|
44192 | };
|
44193 |
|
44194 |
|
44195 |
|
44196 | CommandStack.prototype._getRedoAction = function() {
|
44197 | return this._stack[this._stackIdx + 1];
|
44198 | };
|
44199 |
|
44200 |
|
44201 | CommandStack.prototype._getUndoAction = function() {
|
44202 | return this._stack[this._stackIdx];
|
44203 | };
|
44204 |
|
44205 |
|
44206 |
|
44207 |
|
44208 | CommandStack.prototype._internalUndo = function(action) {
|
44209 | var self = this;
|
44210 |
|
44211 | var command = action.command,
|
44212 | context = action.context;
|
44213 |
|
44214 | var handler = this._getHandler(command);
|
44215 |
|
44216 |
|
44217 | this._atomicDo(function() {
|
44218 | self._fire(command, 'revert', action);
|
44219 |
|
44220 | if (handler.revert) {
|
44221 | self._markDirty(handler.revert(context));
|
44222 | }
|
44223 |
|
44224 | self._revertedAction(action);
|
44225 |
|
44226 | self._fire(command, 'reverted', action);
|
44227 | });
|
44228 | };
|
44229 |
|
44230 |
|
44231 | CommandStack.prototype._fire = function(command, qualifier, event) {
|
44232 | if (arguments.length < 3) {
|
44233 | event = qualifier;
|
44234 | qualifier = null;
|
44235 | }
|
44236 |
|
44237 | var names = qualifier ? [ command + '.' + qualifier, qualifier ] : [ command ],
|
44238 | i, name, result;
|
44239 |
|
44240 | event = this._eventBus.createEvent(event);
|
44241 |
|
44242 | for (i = 0; (name = names[i]); i++) {
|
44243 | result = this._eventBus.fire('commandStack.' + name, event);
|
44244 |
|
44245 | if (event.cancelBubble) {
|
44246 | break;
|
44247 | }
|
44248 | }
|
44249 |
|
44250 | return result;
|
44251 | };
|
44252 |
|
44253 | CommandStack.prototype._createId = function() {
|
44254 | return this._uid++;
|
44255 | };
|
44256 |
|
44257 | CommandStack.prototype._atomicDo = function(fn) {
|
44258 |
|
44259 | var execution = this._currentExecution;
|
44260 |
|
44261 | execution.atomic = true;
|
44262 |
|
44263 | try {
|
44264 | fn();
|
44265 | } finally {
|
44266 | execution.atomic = false;
|
44267 | }
|
44268 | };
|
44269 |
|
44270 | CommandStack.prototype._internalExecute = function(action, redo) {
|
44271 | var self = this;
|
44272 |
|
44273 | var command = action.command,
|
44274 | context = action.context;
|
44275 |
|
44276 | var handler = this._getHandler(command);
|
44277 |
|
44278 | if (!handler) {
|
44279 | throw new Error('no command handler registered for <' + command + '>');
|
44280 | }
|
44281 |
|
44282 | this._pushAction(action);
|
44283 |
|
44284 | if (!redo) {
|
44285 | this._fire(command, 'preExecute', action);
|
44286 |
|
44287 | if (handler.preExecute) {
|
44288 | handler.preExecute(context);
|
44289 | }
|
44290 |
|
44291 | this._fire(command, 'preExecuted', action);
|
44292 | }
|
44293 |
|
44294 |
|
44295 | this._atomicDo(function() {
|
44296 |
|
44297 | self._fire(command, 'execute', action);
|
44298 |
|
44299 | if (handler.execute) {
|
44300 |
|
44301 |
|
44302 | self._markDirty(handler.execute(context));
|
44303 | }
|
44304 |
|
44305 |
|
44306 | self._executedAction(action, redo);
|
44307 |
|
44308 | self._fire(command, 'executed', action);
|
44309 | });
|
44310 |
|
44311 | if (!redo) {
|
44312 | this._fire(command, 'postExecute', action);
|
44313 |
|
44314 | if (handler.postExecute) {
|
44315 | handler.postExecute(context);
|
44316 | }
|
44317 |
|
44318 | this._fire(command, 'postExecuted', action);
|
44319 | }
|
44320 |
|
44321 | this._popAction(action);
|
44322 | };
|
44323 |
|
44324 |
|
44325 | CommandStack.prototype._pushAction = function(action) {
|
44326 |
|
44327 | var execution = this._currentExecution,
|
44328 | actions = execution.actions;
|
44329 |
|
44330 | var baseAction = actions[0];
|
44331 |
|
44332 | if (execution.atomic) {
|
44333 | throw new Error('illegal invocation in <execute> or <revert> phase (action: ' + action.command + ')');
|
44334 | }
|
44335 |
|
44336 | if (!action.id) {
|
44337 | action.id = (baseAction && baseAction.id) || this._createId();
|
44338 | }
|
44339 |
|
44340 | actions.push(action);
|
44341 | };
|
44342 |
|
44343 |
|
44344 | CommandStack.prototype._popAction = function() {
|
44345 | var execution = this._currentExecution,
|
44346 | actions = execution.actions,
|
44347 | dirty = execution.dirty;
|
44348 |
|
44349 | actions.pop();
|
44350 |
|
44351 | if (!actions.length) {
|
44352 | this._eventBus.fire('elements.changed', { elements: uniqueBy('id', dirty.reverse()) });
|
44353 |
|
44354 | dirty.length = 0;
|
44355 |
|
44356 | this._fire('changed');
|
44357 | }
|
44358 | };
|
44359 |
|
44360 |
|
44361 | CommandStack.prototype._markDirty = function(elements) {
|
44362 | var execution = this._currentExecution;
|
44363 |
|
44364 | if (!elements) {
|
44365 | return;
|
44366 | }
|
44367 |
|
44368 | elements = isArray(elements) ? elements : [ elements ];
|
44369 |
|
44370 | execution.dirty = execution.dirty.concat(elements);
|
44371 | };
|
44372 |
|
44373 |
|
44374 | CommandStack.prototype._executedAction = function(action, redo) {
|
44375 | var stackIdx = ++this._stackIdx;
|
44376 |
|
44377 | if (!redo) {
|
44378 | this._stack.splice(stackIdx, this._stack.length, action);
|
44379 | }
|
44380 | };
|
44381 |
|
44382 |
|
44383 | CommandStack.prototype._revertedAction = function(action) {
|
44384 | this._stackIdx--;
|
44385 | };
|
44386 |
|
44387 |
|
44388 | CommandStack.prototype._getHandler = function(command) {
|
44389 | return this._handlerMap[command];
|
44390 | };
|
44391 |
|
44392 | CommandStack.prototype._setHandler = function(command, handler) {
|
44393 | if (!command || !handler) {
|
44394 | throw new Error('command and handler required');
|
44395 | }
|
44396 |
|
44397 | if (this._handlerMap[command]) {
|
44398 | throw new Error('overriding handler for command <' + command + '>');
|
44399 | }
|
44400 |
|
44401 | this._handlerMap[command] = handler;
|
44402 | };
|
44403 |
|
44404 | var CommandModule = {
|
44405 | commandStack: [ 'type', CommandStack ]
|
44406 | };
|
44407 |
|
44408 |
|
44409 | var ids$1 = new IdGenerator('tt');
|
44410 |
|
44411 |
|
44412 | function createRoot$1(parentNode) {
|
44413 | var root = domify(
|
44414 | '<div class="djs-tooltip-container" style="position: absolute; width: 0; height: 0;" />'
|
44415 | );
|
44416 |
|
44417 | parentNode.insertBefore(root, parentNode.firstChild);
|
44418 |
|
44419 | return root;
|
44420 | }
|
44421 |
|
44422 |
|
44423 | function setPosition$1(el, x, y) {
|
44424 | assign(el.style, { left: x + 'px', top: y + 'px' });
|
44425 | }
|
44426 |
|
44427 | function setVisible$1(el, visible) {
|
44428 | el.style.display = visible === false ? 'none' : '';
|
44429 | }
|
44430 |
|
44431 |
|
44432 | var tooltipClass = 'djs-tooltip',
|
44433 | tooltipSelector = '.' + tooltipClass;
|
44434 |
|
44435 | |
44436 |
|
44437 |
|
44438 |
|
44439 |
|
44440 |
|
44441 |
|
44442 |
|
44443 |
|
44444 |
|
44445 |
|
44446 |
|
44447 |
|
44448 |
|
44449 |
|
44450 |
|
44451 |
|
44452 |
|
44453 |
|
44454 |
|
44455 |
|
44456 |
|
44457 |
|
44458 |
|
44459 |
|
44460 |
|
44461 |
|
44462 |
|
44463 |
|
44464 |
|
44465 |
|
44466 |
|
44467 |
|
44468 |
|
44469 |
|
44470 |
|
44471 |
|
44472 | function Tooltips(eventBus, canvas) {
|
44473 |
|
44474 | this._eventBus = eventBus;
|
44475 | this._canvas = canvas;
|
44476 |
|
44477 | this._ids = ids$1;
|
44478 |
|
44479 | this._tooltipDefaults = {
|
44480 | show: {
|
44481 | minZoom: 0.7,
|
44482 | maxZoom: 5.0
|
44483 | }
|
44484 | };
|
44485 |
|
44486 | |
44487 |
|
44488 |
|
44489 | this._tooltips = {};
|
44490 |
|
44491 |
|
44492 | this._tooltipRoot = createRoot$1(canvas.getContainer());
|
44493 |
|
44494 |
|
44495 | var self = this;
|
44496 |
|
44497 | delegateEvents.bind(this._tooltipRoot, tooltipSelector, 'mousedown', function(event) {
|
44498 | event.stopPropagation();
|
44499 | });
|
44500 |
|
44501 | delegateEvents.bind(this._tooltipRoot, tooltipSelector, 'mouseover', function(event) {
|
44502 | self.trigger('mouseover', event);
|
44503 | });
|
44504 |
|
44505 | delegateEvents.bind(this._tooltipRoot, tooltipSelector, 'mouseout', function(event) {
|
44506 | self.trigger('mouseout', event);
|
44507 | });
|
44508 |
|
44509 | this._init();
|
44510 | }
|
44511 |
|
44512 |
|
44513 | Tooltips.$inject = [ 'eventBus', 'canvas' ];
|
44514 |
|
44515 |
|
44516 | |
44517 |
|
44518 |
|
44519 |
|
44520 |
|
44521 |
|
44522 |
|
44523 |
|
44524 |
|
44525 |
|
44526 |
|
44527 |
|
44528 |
|
44529 |
|
44530 |
|
44531 |
|
44532 |
|
44533 |
|
44534 | Tooltips.prototype.add = function(tooltip) {
|
44535 |
|
44536 | if (!tooltip.position) {
|
44537 | throw new Error('must specifiy tooltip position');
|
44538 | }
|
44539 |
|
44540 | if (!tooltip.html) {
|
44541 | throw new Error('must specifiy tooltip html');
|
44542 | }
|
44543 |
|
44544 | var id = this._ids.next();
|
44545 |
|
44546 | tooltip = assign({}, this._tooltipDefaults, tooltip, {
|
44547 | id: id
|
44548 | });
|
44549 |
|
44550 | this._addTooltip(tooltip);
|
44551 |
|
44552 | if (tooltip.timeout) {
|
44553 | this.setTimeout(tooltip);
|
44554 | }
|
44555 |
|
44556 | return id;
|
44557 | };
|
44558 |
|
44559 | Tooltips.prototype.trigger = function(action, event) {
|
44560 |
|
44561 | var node = event.delegateTarget || event.target;
|
44562 |
|
44563 | var tooltip = this.get(attr(node, 'data-tooltip-id'));
|
44564 |
|
44565 | if (!tooltip) {
|
44566 | return;
|
44567 | }
|
44568 |
|
44569 | if (action === 'mouseover' && tooltip.timeout) {
|
44570 | this.clearTimeout(tooltip);
|
44571 | }
|
44572 |
|
44573 | if (action === 'mouseout' && tooltip.timeout) {
|
44574 |
|
44575 |
|
44576 | tooltip.timeout = 1000;
|
44577 |
|
44578 | this.setTimeout(tooltip);
|
44579 | }
|
44580 | };
|
44581 |
|
44582 | |
44583 |
|
44584 |
|
44585 |
|
44586 |
|
44587 | Tooltips.prototype.get = function(id) {
|
44588 |
|
44589 | if (typeof id !== 'string') {
|
44590 | id = id.id;
|
44591 | }
|
44592 |
|
44593 | return this._tooltips[id];
|
44594 | };
|
44595 |
|
44596 | Tooltips.prototype.clearTimeout = function(tooltip) {
|
44597 |
|
44598 | tooltip = this.get(tooltip);
|
44599 |
|
44600 | if (!tooltip) {
|
44601 | return;
|
44602 | }
|
44603 |
|
44604 | var removeTimer = tooltip.removeTimer;
|
44605 |
|
44606 | if (removeTimer) {
|
44607 | clearTimeout(removeTimer);
|
44608 | tooltip.removeTimer = null;
|
44609 | }
|
44610 | };
|
44611 |
|
44612 | Tooltips.prototype.setTimeout = function(tooltip) {
|
44613 |
|
44614 | tooltip = this.get(tooltip);
|
44615 |
|
44616 | if (!tooltip) {
|
44617 | return;
|
44618 | }
|
44619 |
|
44620 | this.clearTimeout(tooltip);
|
44621 |
|
44622 | var self = this;
|
44623 |
|
44624 | tooltip.removeTimer = setTimeout(function() {
|
44625 | self.remove(tooltip);
|
44626 | }, tooltip.timeout);
|
44627 | };
|
44628 |
|
44629 | |
44630 |
|
44631 |
|
44632 |
|
44633 |
|
44634 | Tooltips.prototype.remove = function(id) {
|
44635 |
|
44636 | var tooltip = this.get(id);
|
44637 |
|
44638 | if (tooltip) {
|
44639 | remove(tooltip.html);
|
44640 | remove(tooltip.htmlContainer);
|
44641 |
|
44642 | delete tooltip.htmlContainer;
|
44643 |
|
44644 | delete this._tooltips[tooltip.id];
|
44645 | }
|
44646 | };
|
44647 |
|
44648 |
|
44649 | Tooltips.prototype.show = function() {
|
44650 | setVisible$1(this._tooltipRoot);
|
44651 | };
|
44652 |
|
44653 |
|
44654 | Tooltips.prototype.hide = function() {
|
44655 | setVisible$1(this._tooltipRoot, false);
|
44656 | };
|
44657 |
|
44658 |
|
44659 | Tooltips.prototype._updateRoot = function(viewbox) {
|
44660 | var a = viewbox.scale || 1;
|
44661 | var d = viewbox.scale || 1;
|
44662 |
|
44663 | var matrix = 'matrix(' + a + ',0,0,' + d + ',' + (-1 * viewbox.x * a) + ',' + (-1 * viewbox.y * d) + ')';
|
44664 |
|
44665 | this._tooltipRoot.style.transform = matrix;
|
44666 | this._tooltipRoot.style['-ms-transform'] = matrix;
|
44667 | };
|
44668 |
|
44669 |
|
44670 | Tooltips.prototype._addTooltip = function(tooltip) {
|
44671 |
|
44672 | var id = tooltip.id,
|
44673 | html = tooltip.html,
|
44674 | htmlContainer,
|
44675 | tooltipRoot = this._tooltipRoot;
|
44676 |
|
44677 |
|
44678 | if (html.get && html.constructor.prototype.jquery) {
|
44679 | html = html.get(0);
|
44680 | }
|
44681 |
|
44682 |
|
44683 |
|
44684 | if (isString(html)) {
|
44685 | html = domify(html);
|
44686 | }
|
44687 |
|
44688 | htmlContainer = domify('<div data-tooltip-id="' + id + '" class="' + tooltipClass + '" style="position: absolute">');
|
44689 |
|
44690 | htmlContainer.appendChild(html);
|
44691 |
|
44692 | if (tooltip.type) {
|
44693 | classes(htmlContainer).add('djs-tooltip-' + tooltip.type);
|
44694 | }
|
44695 |
|
44696 | if (tooltip.className) {
|
44697 | classes(htmlContainer).add(tooltip.className);
|
44698 | }
|
44699 |
|
44700 | tooltip.htmlContainer = htmlContainer;
|
44701 |
|
44702 | tooltipRoot.appendChild(htmlContainer);
|
44703 |
|
44704 | this._tooltips[id] = tooltip;
|
44705 |
|
44706 | this._updateTooltip(tooltip);
|
44707 | };
|
44708 |
|
44709 |
|
44710 | Tooltips.prototype._updateTooltip = function(tooltip) {
|
44711 |
|
44712 | var position = tooltip.position,
|
44713 | htmlContainer = tooltip.htmlContainer;
|
44714 |
|
44715 |
|
44716 |
|
44717 | setPosition$1(htmlContainer, position.x, position.y);
|
44718 | };
|
44719 |
|
44720 |
|
44721 | Tooltips.prototype._updateTooltipVisibilty = function(viewbox) {
|
44722 |
|
44723 | forEach(this._tooltips, function(tooltip) {
|
44724 | var show = tooltip.show,
|
44725 | htmlContainer = tooltip.htmlContainer,
|
44726 | visible = true;
|
44727 |
|
44728 | if (show) {
|
44729 | if (show.minZoom > viewbox.scale ||
|
44730 | show.maxZoom < viewbox.scale) {
|
44731 | visible = false;
|
44732 | }
|
44733 |
|
44734 | setVisible$1(htmlContainer, visible);
|
44735 | }
|
44736 | });
|
44737 | };
|
44738 |
|
44739 | Tooltips.prototype._init = function() {
|
44740 |
|
44741 | var self = this;
|
44742 |
|
44743 |
|
44744 |
|
44745 | function updateViewbox(viewbox) {
|
44746 | self._updateRoot(viewbox);
|
44747 | self._updateTooltipVisibilty(viewbox);
|
44748 |
|
44749 | self.show();
|
44750 | }
|
44751 |
|
44752 | this._eventBus.on('canvas.viewbox.changing', function(event) {
|
44753 | self.hide();
|
44754 | });
|
44755 |
|
44756 | this._eventBus.on('canvas.viewbox.changed', function(event) {
|
44757 | updateViewbox(event.viewbox);
|
44758 | });
|
44759 | };
|
44760 |
|
44761 | var TooltipsModule = {
|
44762 | __init__: [ 'tooltips' ],
|
44763 | tooltips: [ 'type', Tooltips ]
|
44764 | };
|
44765 |
|
44766 | |
44767 |
|
44768 |
|
44769 |
|
44770 |
|
44771 |
|
44772 |
|
44773 |
|
44774 |
|
44775 |
|
44776 |
|
44777 |
|
44778 |
|
44779 |
|
44780 |
|
44781 |
|
44782 | function saveClear(collection, removeFn) {
|
44783 |
|
44784 | if (typeof removeFn !== 'function') {
|
44785 | throw new Error('removeFn iterator must be a function');
|
44786 | }
|
44787 |
|
44788 | if (!collection) {
|
44789 | return;
|
44790 | }
|
44791 |
|
44792 | var e;
|
44793 |
|
44794 | while ((e = collection[0])) {
|
44795 | removeFn(e);
|
44796 | }
|
44797 |
|
44798 | return collection;
|
44799 | }
|
44800 |
|
44801 | var LOW_PRIORITY$f = 250,
|
44802 | HIGH_PRIORITY$b = 1400;
|
44803 |
|
44804 |
|
44805 | |
44806 |
|
44807 |
|
44808 |
|
44809 |
|
44810 |
|
44811 |
|
44812 |
|
44813 | function LabelSupport(injector, eventBus, modeling) {
|
44814 |
|
44815 | CommandInterceptor.call(this, eventBus);
|
44816 |
|
44817 | var movePreview = injector.get('movePreview', false);
|
44818 |
|
44819 |
|
44820 |
|
44821 | eventBus.on('shape.move.start', HIGH_PRIORITY$b, function(e) {
|
44822 |
|
44823 | var context = e.context,
|
44824 | shapes = context.shapes,
|
44825 | validatedShapes = context.validatedShapes;
|
44826 |
|
44827 | context.shapes = removeLabels(shapes);
|
44828 | context.validatedShapes = removeLabels(validatedShapes);
|
44829 | });
|
44830 |
|
44831 |
|
44832 | movePreview && eventBus.on('shape.move.start', LOW_PRIORITY$f, function(e) {
|
44833 |
|
44834 | var context = e.context,
|
44835 | shapes = context.shapes;
|
44836 |
|
44837 | var labels = [];
|
44838 |
|
44839 | forEach(shapes, function(element) {
|
44840 |
|
44841 | forEach(element.labels, function(label) {
|
44842 |
|
44843 | if (!label.hidden && context.shapes.indexOf(label) === -1) {
|
44844 | labels.push(label);
|
44845 | }
|
44846 |
|
44847 | if (element.labelTarget) {
|
44848 | labels.push(element);
|
44849 | }
|
44850 | });
|
44851 | });
|
44852 |
|
44853 | forEach(labels, function(label) {
|
44854 | movePreview.makeDraggable(context, label, true);
|
44855 | });
|
44856 |
|
44857 | });
|
44858 |
|
44859 |
|
44860 | this.preExecuted('elements.move', HIGH_PRIORITY$b, function(e) {
|
44861 | var context = e.context,
|
44862 | closure = context.closure,
|
44863 | enclosedElements = closure.enclosedElements;
|
44864 |
|
44865 | var enclosedLabels = [];
|
44866 |
|
44867 |
|
44868 |
|
44869 | forEach(enclosedElements, function(element) {
|
44870 | forEach(element.labels, function(label) {
|
44871 |
|
44872 | if (!enclosedElements[label.id]) {
|
44873 | enclosedLabels.push(label);
|
44874 | }
|
44875 | });
|
44876 | });
|
44877 |
|
44878 | closure.addAll(enclosedLabels);
|
44879 | });
|
44880 |
|
44881 |
|
44882 | this.preExecute([
|
44883 | 'connection.delete',
|
44884 | 'shape.delete'
|
44885 | ], function(e) {
|
44886 |
|
44887 | var context = e.context,
|
44888 | element = context.connection || context.shape;
|
44889 |
|
44890 | saveClear(element.labels, function(label) {
|
44891 | modeling.removeShape(label, { nested: true });
|
44892 | });
|
44893 | });
|
44894 |
|
44895 |
|
44896 | this.execute('shape.delete', function(e) {
|
44897 |
|
44898 | var context = e.context,
|
44899 | shape = context.shape,
|
44900 | labelTarget = shape.labelTarget;
|
44901 |
|
44902 |
|
44903 | if (labelTarget) {
|
44904 | context.labelTargetIndex = indexOf$1(labelTarget.labels, shape);
|
44905 | context.labelTarget = labelTarget;
|
44906 |
|
44907 | shape.labelTarget = null;
|
44908 | }
|
44909 | });
|
44910 |
|
44911 | this.revert('shape.delete', function(e) {
|
44912 |
|
44913 | var context = e.context,
|
44914 | shape = context.shape,
|
44915 | labelTarget = context.labelTarget,
|
44916 | labelTargetIndex = context.labelTargetIndex;
|
44917 |
|
44918 |
|
44919 | if (labelTarget) {
|
44920 | add$1(labelTarget.labels, shape, labelTargetIndex);
|
44921 |
|
44922 | shape.labelTarget = labelTarget;
|
44923 | }
|
44924 | });
|
44925 |
|
44926 | }
|
44927 |
|
44928 | inherits_browser(LabelSupport, CommandInterceptor);
|
44929 |
|
44930 | LabelSupport.$inject = [
|
44931 | 'injector',
|
44932 | 'eventBus',
|
44933 | 'modeling'
|
44934 | ];
|
44935 |
|
44936 |
|
44937 | |
44938 |
|
44939 |
|
44940 |
|
44941 |
|
44942 |
|
44943 |
|
44944 |
|
44945 |
|
44946 | function removeLabels(elements) {
|
44947 |
|
44948 | return filter(elements, function(element) {
|
44949 |
|
44950 |
|
44951 |
|
44952 | return elements.indexOf(element.labelTarget) === -1;
|
44953 | });
|
44954 | }
|
44955 |
|
44956 | var LabelSupportModule = {
|
44957 | __init__: [ 'labelSupport'],
|
44958 | labelSupport: [ 'type', LabelSupport ]
|
44959 | };
|
44960 |
|
44961 | var LOW_PRIORITY$g = 251,
|
44962 | HIGH_PRIORITY$c = 1401;
|
44963 |
|
44964 | var MARKER_ATTACH$1 = 'attach-ok';
|
44965 |
|
44966 |
|
44967 | |
44968 |
|
44969 |
|
44970 |
|
44971 |
|
44972 |
|
44973 |
|
44974 |
|
44975 |
|
44976 |
|
44977 |
|
44978 |
|
44979 |
|
44980 |
|
44981 |
|
44982 | function AttachSupport(injector, eventBus, canvas, rules, modeling) {
|
44983 |
|
44984 | CommandInterceptor.call(this, eventBus);
|
44985 |
|
44986 | var movePreview = injector.get('movePreview', false);
|
44987 |
|
44988 |
|
44989 |
|
44990 |
|
44991 | eventBus.on('shape.move.start', HIGH_PRIORITY$c, function(e) {
|
44992 |
|
44993 | var context = e.context,
|
44994 | shapes = context.shapes,
|
44995 | validatedShapes = context.validatedShapes;
|
44996 |
|
44997 | context.shapes = addAttached(shapes);
|
44998 |
|
44999 | context.validatedShapes = removeAttached(validatedShapes);
|
45000 | });
|
45001 |
|
45002 |
|
45003 | movePreview && eventBus.on('shape.move.start', LOW_PRIORITY$g, function(e) {
|
45004 |
|
45005 | var context = e.context,
|
45006 | shapes = context.shapes,
|
45007 | attachers = getAttachers(shapes);
|
45008 |
|
45009 | forEach(attachers, function(attacher) {
|
45010 | movePreview.makeDraggable(context, attacher, true);
|
45011 |
|
45012 | forEach(attacher.labels, function(label) {
|
45013 | movePreview.makeDraggable(context, label, true);
|
45014 | });
|
45015 | });
|
45016 | });
|
45017 |
|
45018 |
|
45019 | movePreview && eventBus.on('shape.move.start', function(event) {
|
45020 | var context = event.context,
|
45021 | shapes = context.shapes;
|
45022 |
|
45023 | if (shapes.length !== 1) {
|
45024 | return;
|
45025 | }
|
45026 |
|
45027 | var shape = shapes[0];
|
45028 |
|
45029 | var host = shape.host;
|
45030 |
|
45031 | if (host) {
|
45032 | canvas.addMarker(host, MARKER_ATTACH$1);
|
45033 |
|
45034 | eventBus.once([
|
45035 | 'shape.move.out',
|
45036 | 'shape.move.cleanup'
|
45037 | ], function() {
|
45038 | canvas.removeMarker(host, MARKER_ATTACH$1);
|
45039 | });
|
45040 | }
|
45041 | });
|
45042 |
|
45043 |
|
45044 | this.preExecuted('elements.move', HIGH_PRIORITY$c, function(e) {
|
45045 | var context = e.context,
|
45046 | closure = context.closure,
|
45047 | shapes = context.shapes,
|
45048 | attachers = getAttachers(shapes);
|
45049 |
|
45050 | forEach(attachers, function(attacher) {
|
45051 | closure.add(attacher, closure.topLevel[attacher.host.id]);
|
45052 | });
|
45053 | });
|
45054 |
|
45055 |
|
45056 | this.postExecuted('elements.move', function(e) {
|
45057 |
|
45058 | var context = e.context,
|
45059 | shapes = context.shapes,
|
45060 | newHost = context.newHost,
|
45061 | attachers;
|
45062 |
|
45063 |
|
45064 |
|
45065 | if (newHost && shapes.length !== 1) {
|
45066 | return;
|
45067 | }
|
45068 |
|
45069 | if (newHost) {
|
45070 | attachers = shapes;
|
45071 | } else {
|
45072 |
|
45073 |
|
45074 | attachers = filter(shapes, function(shape) {
|
45075 | var host = shape.host;
|
45076 |
|
45077 | return isAttacher$1(shape) && !includes$2(shapes, host);
|
45078 | });
|
45079 | }
|
45080 |
|
45081 | forEach(attachers, function(attacher) {
|
45082 | modeling.updateAttachment(attacher, newHost);
|
45083 | });
|
45084 | });
|
45085 |
|
45086 |
|
45087 | this.postExecuted('elements.move', function(e) {
|
45088 |
|
45089 | var shapes = e.context.shapes;
|
45090 |
|
45091 | forEach(shapes, function(shape) {
|
45092 |
|
45093 | forEach(shape.attachers, function(attacher) {
|
45094 |
|
45095 |
|
45096 | forEach(attacher.outgoing.slice(), function(connection) {
|
45097 | var allowed = rules.allowed('connection.reconnect', {
|
45098 | connection: connection,
|
45099 | source: connection.source,
|
45100 | target: connection.target
|
45101 | });
|
45102 |
|
45103 | if (!allowed) {
|
45104 | modeling.removeConnection(connection);
|
45105 | }
|
45106 | });
|
45107 |
|
45108 |
|
45109 | forEach(attacher.incoming.slice(), function(connection) {
|
45110 | var allowed = rules.allowed('connection.reconnect', {
|
45111 | connection: connection,
|
45112 | source: connection.source,
|
45113 | target: connection.target
|
45114 | });
|
45115 |
|
45116 | if (!allowed) {
|
45117 | modeling.removeConnection(connection);
|
45118 | }
|
45119 | });
|
45120 | });
|
45121 | });
|
45122 | });
|
45123 |
|
45124 | this.postExecute('shape.create', function(e) {
|
45125 | var context = e.context,
|
45126 | shape = context.shape,
|
45127 | host = context.host;
|
45128 |
|
45129 | if (host) {
|
45130 | modeling.updateAttachment(shape, host);
|
45131 | }
|
45132 | });
|
45133 |
|
45134 |
|
45135 | this.postExecute('shape.replace', function(e) {
|
45136 |
|
45137 | var context = e.context,
|
45138 | oldShape = context.oldShape,
|
45139 | newShape = context.newShape;
|
45140 |
|
45141 |
|
45142 | saveClear(oldShape.attachers, function(attacher) {
|
45143 | var allowed = rules.allowed('elements.move', {
|
45144 | target: newShape,
|
45145 | shapes: [attacher]
|
45146 | });
|
45147 |
|
45148 | if (allowed === 'attach') {
|
45149 | modeling.updateAttachment(attacher, newShape);
|
45150 | } else {
|
45151 | modeling.removeShape(attacher);
|
45152 | }
|
45153 | });
|
45154 |
|
45155 |
|
45156 | if (newShape.attachers.length) {
|
45157 |
|
45158 | forEach(newShape.attachers, function(attacher) {
|
45159 | var delta = getNewAttachShapeDelta(attacher, oldShape, newShape);
|
45160 | modeling.moveShape(attacher, delta, attacher.parent);
|
45161 | });
|
45162 | }
|
45163 |
|
45164 | });
|
45165 |
|
45166 |
|
45167 | this.postExecute('shape.resize', function(event) {
|
45168 | var context = event.context,
|
45169 | shape = context.shape,
|
45170 | oldBounds = context.oldBounds,
|
45171 | newBounds = context.newBounds,
|
45172 | attachers = shape.attachers;
|
45173 |
|
45174 | forEach(attachers, function(attacher) {
|
45175 | var delta = getNewAttachShapeDelta(attacher, oldBounds, newBounds);
|
45176 |
|
45177 | modeling.moveShape(attacher, delta, attacher.parent);
|
45178 |
|
45179 | forEach(attacher.labels, function(label) {
|
45180 | modeling.moveShape(label, delta, label.parent);
|
45181 | });
|
45182 | });
|
45183 | });
|
45184 |
|
45185 |
|
45186 | this.preExecute('shape.delete', function(event) {
|
45187 |
|
45188 | var shape = event.context.shape;
|
45189 |
|
45190 | saveClear(shape.attachers, function(attacher) {
|
45191 | modeling.removeShape(attacher);
|
45192 | });
|
45193 |
|
45194 | if (shape.host) {
|
45195 | modeling.updateAttachment(shape, null);
|
45196 | }
|
45197 | });
|
45198 |
|
45199 |
|
45200 |
|
45201 |
|
45202 | eventBus.on('spaceTool.move', function(event) {
|
45203 |
|
45204 | var context = event.context,
|
45205 | initialized = context.initialized,
|
45206 | attachSupportInitialized = context.attachSupportInitialized;
|
45207 |
|
45208 | if (!initialized || attachSupportInitialized) {
|
45209 | return;
|
45210 | }
|
45211 |
|
45212 | var movingShapes = context.movingShapes;
|
45213 |
|
45214 |
|
45215 | var staticAttachers = filter(movingShapes, function(shape) {
|
45216 | var host = shape.host;
|
45217 |
|
45218 | return host && movingShapes.indexOf(host) === -1;
|
45219 | });
|
45220 |
|
45221 |
|
45222 | forEach(staticAttachers, function(shape) {
|
45223 | remove$2(movingShapes, shape);
|
45224 |
|
45225 | forEach(shape.labels, function(label) {
|
45226 | remove$2(movingShapes, shape.label);
|
45227 | });
|
45228 | });
|
45229 |
|
45230 | context.attachSupportInitialized = true;
|
45231 | });
|
45232 | }
|
45233 |
|
45234 | inherits_browser(AttachSupport, CommandInterceptor);
|
45235 |
|
45236 | AttachSupport.$inject = [
|
45237 | 'injector',
|
45238 | 'eventBus',
|
45239 | 'canvas',
|
45240 | 'rules',
|
45241 | 'modeling'
|
45242 | ];
|
45243 |
|
45244 |
|
45245 | |
45246 |
|
45247 |
|
45248 |
|
45249 |
|
45250 |
|
45251 | function getAttachers(shapes) {
|
45252 | return flatten(map(shapes, function(s) {
|
45253 | return s.attachers || [];
|
45254 | }));
|
45255 | }
|
45256 |
|
45257 | |
45258 |
|
45259 |
|
45260 |
|
45261 |
|
45262 |
|
45263 |
|
45264 | function addAttached(elements) {
|
45265 | var attachers = getAttachers(elements);
|
45266 |
|
45267 | return unionBy('id', elements, attachers);
|
45268 | }
|
45269 |
|
45270 | |
45271 |
|
45272 |
|
45273 |
|
45274 |
|
45275 |
|
45276 |
|
45277 |
|
45278 |
|
45279 | function removeAttached(elements) {
|
45280 |
|
45281 | var ids = groupBy(elements, 'id');
|
45282 |
|
45283 | return filter(elements, function(element) {
|
45284 | while (element) {
|
45285 |
|
45286 |
|
45287 | if (element.host && ids[element.host.id]) {
|
45288 | return false;
|
45289 | }
|
45290 |
|
45291 | element = element.parent;
|
45292 | }
|
45293 |
|
45294 | return true;
|
45295 | });
|
45296 | }
|
45297 |
|
45298 | function isAttacher$1(shape) {
|
45299 | return !!shape.host;
|
45300 | }
|
45301 |
|
45302 | function includes$2(array, item) {
|
45303 | return array.indexOf(item) !== -1;
|
45304 | }
|
45305 |
|
45306 | var AttachSupportModule = {
|
45307 | __depends__: [
|
45308 | RulesModule
|
45309 | ],
|
45310 | __init__: [ 'attachSupport' ],
|
45311 | attachSupport: [ 'type', AttachSupport ]
|
45312 | };
|
45313 |
|
45314 | var LOW_PRIORITY$h = 250;
|
45315 |
|
45316 | |
45317 |
|
45318 |
|
45319 |
|
45320 |
|
45321 |
|
45322 |
|
45323 | function ToolManager(eventBus, dragging) {
|
45324 | this._eventBus = eventBus;
|
45325 | this._dragging = dragging;
|
45326 |
|
45327 | this._tools = [];
|
45328 | this._active = null;
|
45329 | }
|
45330 |
|
45331 | ToolManager.$inject = [ 'eventBus', 'dragging' ];
|
45332 |
|
45333 | ToolManager.prototype.registerTool = function(name, events) {
|
45334 | var tools = this._tools;
|
45335 |
|
45336 | if (!events) {
|
45337 | throw new Error('A tool has to be registered with it\'s "events"');
|
45338 | }
|
45339 |
|
45340 | tools.push(name);
|
45341 |
|
45342 | this.bindEvents(name, events);
|
45343 | };
|
45344 |
|
45345 | ToolManager.prototype.isActive = function(tool) {
|
45346 | return tool && this._active === tool;
|
45347 | };
|
45348 |
|
45349 | ToolManager.prototype.length = function(tool) {
|
45350 | return this._tools.length;
|
45351 | };
|
45352 |
|
45353 | ToolManager.prototype.setActive = function(tool) {
|
45354 | var eventBus = this._eventBus;
|
45355 |
|
45356 | if (this._active !== tool) {
|
45357 | this._active = tool;
|
45358 |
|
45359 | eventBus.fire('tool-manager.update', { tool: tool });
|
45360 | }
|
45361 | };
|
45362 |
|
45363 | ToolManager.prototype.bindEvents = function(name, events) {
|
45364 | var eventBus = this._eventBus,
|
45365 | dragging = this._dragging;
|
45366 |
|
45367 | var eventsToRegister = [];
|
45368 |
|
45369 | eventBus.on(events.tool + '.init', function(event) {
|
45370 | var context = event.context;
|
45371 |
|
45372 |
|
45373 | if (!context.reactivate && this.isActive(name)) {
|
45374 | this.setActive(null);
|
45375 |
|
45376 | dragging.cancel();
|
45377 | return;
|
45378 | }
|
45379 |
|
45380 | this.setActive(name);
|
45381 |
|
45382 | }, this);
|
45383 |
|
45384 |
|
45385 | forEach(events, function(event) {
|
45386 | eventsToRegister.push(event + '.ended');
|
45387 | eventsToRegister.push(event + '.canceled');
|
45388 | });
|
45389 |
|
45390 | eventBus.on(eventsToRegister, LOW_PRIORITY$h, function(event) {
|
45391 | var originalEvent = event.originalEvent;
|
45392 |
|
45393 |
|
45394 |
|
45395 |
|
45396 | if (!this._active) {
|
45397 | return;
|
45398 | }
|
45399 |
|
45400 | if (originalEvent && closest(originalEvent.target, '.group[data-group="tools"]')) {
|
45401 | return;
|
45402 | }
|
45403 |
|
45404 | this.setActive(null);
|
45405 | }, this);
|
45406 | };
|
45407 |
|
45408 | var ToolManagerModule = {
|
45409 | __depends__: [
|
45410 | DraggingModule
|
45411 | ],
|
45412 | __init__: [ 'toolManager' ],
|
45413 | toolManager: [ 'type', ToolManager ]
|
45414 | };
|
45415 |
|
45416 | |
45417 |
|
45418 |
|
45419 |
|
45420 |
|
45421 |
|
45422 |
|
45423 |
|
45424 | function getDirection(axis, offset) {
|
45425 |
|
45426 | if (axis === 'x') {
|
45427 | if (offset > 0) {
|
45428 | return 'e';
|
45429 | }
|
45430 |
|
45431 | if (offset < 0) {
|
45432 | return 'w';
|
45433 | }
|
45434 | }
|
45435 |
|
45436 | if (axis === 'y') {
|
45437 | if (offset > 0) {
|
45438 | return 's';
|
45439 | }
|
45440 |
|
45441 | if (offset < 0) {
|
45442 | return 'n';
|
45443 | }
|
45444 | }
|
45445 |
|
45446 | return null;
|
45447 | }
|
45448 |
|
45449 |
|
45450 | |
45451 |
|
45452 |
|
45453 |
|
45454 |
|
45455 |
|
45456 |
|
45457 |
|
45458 |
|
45459 | function resizeBounds$1(bounds, direction, delta) {
|
45460 |
|
45461 | var dx = delta.x,
|
45462 | dy = delta.y;
|
45463 |
|
45464 | switch (direction) {
|
45465 |
|
45466 | case 'n':
|
45467 | return {
|
45468 | x: bounds.x,
|
45469 | y: bounds.y + dy,
|
45470 | width: bounds.width,
|
45471 | height: bounds.height - dy
|
45472 | };
|
45473 |
|
45474 | case 's':
|
45475 | return {
|
45476 | x: bounds.x,
|
45477 | y: bounds.y,
|
45478 | width: bounds.width,
|
45479 | height: bounds.height + dy
|
45480 | };
|
45481 |
|
45482 | case 'w':
|
45483 | return {
|
45484 | x: bounds.x + dx,
|
45485 | y: bounds.y,
|
45486 | width: bounds.width - dx,
|
45487 | height: bounds.height
|
45488 | };
|
45489 |
|
45490 | case 'e':
|
45491 | return {
|
45492 | x: bounds.x,
|
45493 | y: bounds.y,
|
45494 | width: bounds.width + dx,
|
45495 | height: bounds.height
|
45496 | };
|
45497 |
|
45498 | default:
|
45499 | throw new Error('unrecognized direction: ' + direction);
|
45500 | }
|
45501 | }
|
45502 |
|
45503 | var abs$6 = Math.abs,
|
45504 | round$7 = Math.round;
|
45505 |
|
45506 | var HIGH_PRIORITY$d = 1500,
|
45507 | SPACE_TOOL_CURSOR = 'crosshair';
|
45508 |
|
45509 | var AXIS_TO_DIMENSION = { x: 'width', y: 'height' },
|
45510 | AXIS_INVERTED = { x: 'y', y: 'x' };
|
45511 |
|
45512 |
|
45513 | |
45514 |
|
45515 |
|
45516 |
|
45517 |
|
45518 | function SpaceTool(
|
45519 | eventBus, dragging, canvas,
|
45520 | modeling, rules, toolManager) {
|
45521 |
|
45522 | this._canvas = canvas;
|
45523 | this._dragging = dragging;
|
45524 | this._modeling = modeling;
|
45525 | this._rules = rules;
|
45526 | this._toolManager = toolManager;
|
45527 |
|
45528 | var self = this;
|
45529 |
|
45530 | toolManager.registerTool('space', {
|
45531 | tool: 'spaceTool.selection',
|
45532 | dragging: 'spaceTool'
|
45533 | });
|
45534 |
|
45535 | eventBus.on('spaceTool.selection.end', function(event) {
|
45536 | var target = event.originalEvent.target;
|
45537 |
|
45538 |
|
45539 |
|
45540 | if (!event.hover && !(target instanceof SVGElement)) {
|
45541 | return;
|
45542 | }
|
45543 |
|
45544 | eventBus.once('spaceTool.selection.ended', function() {
|
45545 | self.activateMakeSpace(event.originalEvent);
|
45546 | });
|
45547 | });
|
45548 |
|
45549 |
|
45550 | eventBus.on('spaceTool.move', HIGH_PRIORITY$d , function(event) {
|
45551 |
|
45552 | var context = event.context;
|
45553 |
|
45554 | if (!context.initialized) {
|
45555 | context.initialized = self.initializeMakeSpace(event, context);
|
45556 | }
|
45557 | });
|
45558 |
|
45559 |
|
45560 | eventBus.on('spaceTool.end', function(event) {
|
45561 |
|
45562 | var context = event.context,
|
45563 | axis = context.axis,
|
45564 | direction = context.direction,
|
45565 | movingShapes = context.movingShapes,
|
45566 | resizingShapes = context.resizingShapes;
|
45567 |
|
45568 |
|
45569 | if (!context.initialized) {
|
45570 | return;
|
45571 | }
|
45572 |
|
45573 | var delta = { x: round$7(event.dx), y: round$7(event.dy) };
|
45574 | delta[ AXIS_INVERTED[ axis ] ] = 0;
|
45575 |
|
45576 | var insideBounds = true;
|
45577 |
|
45578 |
|
45579 |
|
45580 | forEach(resizingShapes, function(shape) {
|
45581 |
|
45582 | if ((direction === 'w' && event.x > shape.x + shape.width) ||
|
45583 | (direction === 'e' && event.x < shape.x) ||
|
45584 | (direction === 'n' && event.y > shape.y + shape.height) ||
|
45585 | (direction === 's' && event.y < shape.y)) {
|
45586 |
|
45587 | insideBounds = false;
|
45588 | return;
|
45589 | }
|
45590 | });
|
45591 |
|
45592 | if (insideBounds) {
|
45593 |
|
45594 |
|
45595 | self.makeSpace(movingShapes, resizingShapes, delta, direction);
|
45596 | }
|
45597 |
|
45598 | eventBus.once('spaceTool.ended', function(event) {
|
45599 |
|
45600 |
|
45601 | self.activateSelection(event.originalEvent, true, true);
|
45602 | });
|
45603 |
|
45604 | });
|
45605 | }
|
45606 |
|
45607 | SpaceTool.$inject = [
|
45608 | 'eventBus',
|
45609 | 'dragging',
|
45610 | 'canvas',
|
45611 | 'modeling',
|
45612 | 'rules',
|
45613 | 'toolManager'
|
45614 | ];
|
45615 |
|
45616 |
|
45617 | |
45618 |
|
45619 |
|
45620 |
|
45621 |
|
45622 |
|
45623 | SpaceTool.prototype.activateSelection = function(event, autoActivate, reactivate) {
|
45624 | this._dragging.init(event, 'spaceTool.selection', {
|
45625 | trapClick: false,
|
45626 | cursor: SPACE_TOOL_CURSOR,
|
45627 | autoActivate: autoActivate,
|
45628 | data: {
|
45629 | context: {
|
45630 | reactivate: reactivate
|
45631 | }
|
45632 | }
|
45633 | });
|
45634 | };
|
45635 |
|
45636 | |
45637 |
|
45638 |
|
45639 |
|
45640 |
|
45641 | SpaceTool.prototype.activateMakeSpace = function(event) {
|
45642 | this._dragging.init(event, 'spaceTool', {
|
45643 | autoActivate: true,
|
45644 | cursor: SPACE_TOOL_CURSOR,
|
45645 | data: {
|
45646 | context: {}
|
45647 | }
|
45648 | });
|
45649 | };
|
45650 |
|
45651 | |
45652 |
|
45653 |
|
45654 |
|
45655 |
|
45656 |
|
45657 |
|
45658 |
|
45659 | SpaceTool.prototype.makeSpace = function(movingShapes, resizingShapes, delta, direction) {
|
45660 | return this._modeling.createSpace(movingShapes, resizingShapes, delta, direction);
|
45661 | };
|
45662 |
|
45663 | |
45664 |
|
45665 |
|
45666 |
|
45667 |
|
45668 |
|
45669 |
|
45670 |
|
45671 | SpaceTool.prototype.initializeMakeSpace = function(event, context) {
|
45672 |
|
45673 | var axis = abs$6(event.dx) > abs$6(event.dy) ? 'x' : 'y',
|
45674 | offset = event['d' + axis],
|
45675 |
|
45676 |
|
45677 | spacePos = event[axis] - offset;
|
45678 |
|
45679 | if (abs$6(offset) < 5) {
|
45680 | return false;
|
45681 | }
|
45682 |
|
45683 |
|
45684 | if (offset < 0) {
|
45685 | offset *= -1;
|
45686 | }
|
45687 |
|
45688 |
|
45689 |
|
45690 |
|
45691 | if (hasPrimaryModifier(event)) {
|
45692 | offset *= -1;
|
45693 | }
|
45694 |
|
45695 | var rootShape = this._canvas.getRootElement();
|
45696 |
|
45697 | var allShapes = selfAndAllChildren(rootShape, true);
|
45698 |
|
45699 | var adjustments = this.calculateAdjustments(allShapes, axis, offset, spacePos);
|
45700 |
|
45701 |
|
45702 | assign(context, adjustments, {
|
45703 | axis: axis,
|
45704 | direction: getDirection(axis, offset)
|
45705 | });
|
45706 |
|
45707 | set$1('resize-' + (axis === 'x' ? 'ew' : 'ns'));
|
45708 |
|
45709 | return true;
|
45710 | };
|
45711 |
|
45712 | /**
|
45713 | * Calculate adjustments needed when making space
|
45714 | *
|
45715 | * @param {Array<djs.model.Shape>} elements
|
45716 | * @param {String} axis
|
45717 | * @param {Number} offset
|
45718 | * @param {Number} spacePos
|
45719 | *
|
45720 | * @return {Object}
|
45721 | */
|
45722 | SpaceTool.prototype.calculateAdjustments = function(elements, axis, offset, spacePos) {
|
45723 |
|
45724 | var movingShapes = [],
|
45725 | resizingShapes = [];
|
45726 |
|
45727 | var rules = this._rules;
|
45728 |
|
45729 |
|
45730 |
|
45731 | elements.forEach(function(shape) {
|
45732 |
|
45733 | var shapeStart = shape[axis],
|
45734 | shapeEnd = shapeStart + shape[AXIS_TO_DIMENSION[axis]];
|
45735 |
|
45736 |
|
45737 | if (!shape.parent) {
|
45738 | return;
|
45739 | }
|
45740 |
|
45741 |
|
45742 | if (shape.waypoints) {
|
45743 | return;
|
45744 | }
|
45745 |
|
45746 |
|
45747 | if (offset > 0 && shapeStart > spacePos) {
|
45748 | return movingShapes.push(shape);
|
45749 | }
|
45750 |
|
45751 |
|
45752 | if (offset < 0 && shapeEnd < spacePos) {
|
45753 | return movingShapes.push(shape);
|
45754 | }
|
45755 |
|
45756 |
|
45757 | if (shapeStart < spacePos &&
|
45758 | shapeEnd > spacePos &&
|
45759 | rules.allowed('shape.resize', { shape: shape })) {
|
45760 |
|
45761 | return resizingShapes.push(shape);
|
45762 | }
|
45763 | });
|
45764 |
|
45765 | return {
|
45766 | movingShapes: movingShapes,
|
45767 | resizingShapes: resizingShapes
|
45768 | };
|
45769 | };
|
45770 |
|
45771 | SpaceTool.prototype.toggle = function() {
|
45772 | if (this.isActive()) {
|
45773 | this._dragging.cancel();
|
45774 | } else {
|
45775 | this.activateSelection();
|
45776 | }
|
45777 | };
|
45778 |
|
45779 | SpaceTool.prototype.isActive = function() {
|
45780 | var context = this._dragging.context();
|
45781 |
|
45782 | return context && /^spaceTool/.test(context.prefix);
|
45783 | };
|
45784 |
|
45785 | var MARKER_DRAGGING = 'djs-dragging',
|
45786 | MARKER_RESIZING$1 = 'djs-resizing';
|
45787 |
|
45788 | var LOW_PRIORITY$i = 250;
|
45789 |
|
45790 | var max$5 = Math.max;
|
45791 |
|
45792 |
|
45793 | |
45794 |
|
45795 |
|
45796 |
|
45797 |
|
45798 |
|
45799 |
|
45800 |
|
45801 | function SpaceToolPreview(
|
45802 | eventBus, elementRegistry, canvas,
|
45803 | styles, previewSupport) {
|
45804 |
|
45805 | function addPreviewGfx(collection, dragGroup) {
|
45806 | forEach(collection, function(element) {
|
45807 | previewSupport.addDragger(element, dragGroup);
|
45808 |
|
45809 | canvas.addMarker(element, MARKER_DRAGGING);
|
45810 | });
|
45811 | }
|
45812 |
|
45813 |
|
45814 | eventBus.on('spaceTool.selection.start', function(event) {
|
45815 | var space = canvas.getLayer('space'),
|
45816 | context = event.context;
|
45817 |
|
45818 | var orientation = {
|
45819 | x: 'M 0,-10000 L 0,10000',
|
45820 | y: 'M -10000,0 L 10000,0'
|
45821 | };
|
45822 |
|
45823 | var crosshairGroup = create('g');
|
45824 | attr$1(crosshairGroup, styles.cls('djs-crosshair-group', [ 'no-events' ]));
|
45825 |
|
45826 | append(space, crosshairGroup);
|
45827 |
|
45828 |
|
45829 | var pathX = create('path');
|
45830 | attr$1(pathX, 'd', orientation.x);
|
45831 | classes$1(pathX).add('djs-crosshair');
|
45832 |
|
45833 | append(crosshairGroup, pathX);
|
45834 |
|
45835 |
|
45836 | var pathY = create('path');
|
45837 | attr$1(pathY, 'd', orientation.y);
|
45838 | classes$1(pathY).add('djs-crosshair');
|
45839 |
|
45840 | append(crosshairGroup, pathY);
|
45841 |
|
45842 | context.crosshairGroup = crosshairGroup;
|
45843 | });
|
45844 |
|
45845 |
|
45846 | eventBus.on('spaceTool.selection.move', function(event) {
|
45847 | var crosshairGroup = event.context.crosshairGroup;
|
45848 |
|
45849 | translate(crosshairGroup, event.x, event.y);
|
45850 | });
|
45851 |
|
45852 |
|
45853 | eventBus.on('spaceTool.selection.cleanup', function(event) {
|
45854 | var context = event.context,
|
45855 | crosshairGroup = context.crosshairGroup;
|
45856 |
|
45857 | if (crosshairGroup) {
|
45858 | remove$1(crosshairGroup);
|
45859 | }
|
45860 | });
|
45861 |
|
45862 |
|
45863 | eventBus.on('spaceTool.move', LOW_PRIORITY$i, function(event) {
|
45864 |
|
45865 | var context = event.context,
|
45866 | line = context.line,
|
45867 | axis = context.axis,
|
45868 | movingShapes = context.movingShapes,
|
45869 | resizingShapes = context.resizingShapes;
|
45870 |
|
45871 | if (!context.initialized) {
|
45872 | return;
|
45873 | }
|
45874 |
|
45875 | if (!context.dragGroup) {
|
45876 | var spaceLayer = canvas.getLayer('space');
|
45877 |
|
45878 | line = create('path');
|
45879 | attr$1(line, 'd', 'M0,0 L0,0');
|
45880 | classes$1(line).add('djs-crosshair');
|
45881 |
|
45882 | append(spaceLayer, line);
|
45883 |
|
45884 | context.line = line;
|
45885 |
|
45886 | var dragGroup = create('g');
|
45887 | attr$1(dragGroup, styles.cls('djs-drag-group', [ 'no-events' ]));
|
45888 |
|
45889 | append(canvas.getDefaultLayer(), dragGroup);
|
45890 |
|
45891 |
|
45892 | addPreviewGfx(movingShapes, dragGroup);
|
45893 |
|
45894 |
|
45895 | var movingConnections = context.movingConnections = elementRegistry.filter(function(element) {
|
45896 | var sourceIsMoving = false;
|
45897 |
|
45898 | forEach(movingShapes, function(shape) {
|
45899 | forEach(shape.outgoing, function(connection) {
|
45900 | if (element === connection) {
|
45901 | sourceIsMoving = true;
|
45902 | }
|
45903 | });
|
45904 | });
|
45905 |
|
45906 | var targetIsMoving = false;
|
45907 |
|
45908 | forEach(movingShapes, function(shape) {
|
45909 | forEach(shape.incoming, function(connection) {
|
45910 | if (element === connection) {
|
45911 | targetIsMoving = true;
|
45912 | }
|
45913 | });
|
45914 | });
|
45915 |
|
45916 | var sourceIsResizing = false;
|
45917 |
|
45918 | forEach(resizingShapes, function(shape) {
|
45919 | forEach(shape.outgoing, function(connection) {
|
45920 | if (element === connection) {
|
45921 | sourceIsResizing = true;
|
45922 | }
|
45923 | });
|
45924 | });
|
45925 |
|
45926 | var targetIsResizing = false;
|
45927 |
|
45928 | forEach(resizingShapes, function(shape) {
|
45929 | forEach(shape.incoming, function(connection) {
|
45930 | if (element === connection) {
|
45931 | targetIsResizing = true;
|
45932 | }
|
45933 | });
|
45934 | });
|
45935 |
|
45936 | return isConnection$4(element)
|
45937 | && (sourceIsMoving || sourceIsResizing)
|
45938 | && (targetIsMoving || targetIsResizing);
|
45939 | });
|
45940 |
|
45941 |
|
45942 | addPreviewGfx(movingConnections, dragGroup);
|
45943 |
|
45944 | context.dragGroup = dragGroup;
|
45945 | }
|
45946 |
|
45947 | if (!context.frameGroup) {
|
45948 | var frameGroup = create('g');
|
45949 | attr$1(frameGroup, styles.cls('djs-frame-group', [ 'no-events' ]));
|
45950 |
|
45951 | append(canvas.getDefaultLayer(), frameGroup);
|
45952 |
|
45953 | var frames = [];
|
45954 |
|
45955 | forEach(resizingShapes, function(shape) {
|
45956 | var frame = previewSupport.addFrame(shape, frameGroup);
|
45957 |
|
45958 | var initialBounds = frame.getBBox();
|
45959 |
|
45960 | frames.push({
|
45961 | element: frame,
|
45962 | initialBounds: initialBounds
|
45963 | });
|
45964 |
|
45965 | canvas.addMarker(shape, MARKER_RESIZING$1);
|
45966 | });
|
45967 |
|
45968 | context.frameGroup = frameGroup;
|
45969 | context.frames = frames;
|
45970 | }
|
45971 |
|
45972 | var orientation = {
|
45973 | x: 'M' + event.x + ', -10000 L' + event.x + ', 10000',
|
45974 | y: 'M -10000, ' + event.y + ' L 10000, ' + event.y
|
45975 | };
|
45976 |
|
45977 | attr$1(line, { path: orientation[ axis ], display: '' });
|
45978 |
|
45979 | var opposite = { x: 'y', y: 'x' };
|
45980 | var delta = { x: event.dx, y: event.dy };
|
45981 | delta[ opposite[ context.axis ] ] = 0;
|
45982 |
|
45983 |
|
45984 | translate(context.dragGroup, delta.x, delta.y);
|
45985 |
|
45986 |
|
45987 | forEach(context.frames, function(frame) {
|
45988 | var element = frame.element,
|
45989 | initialBounds = frame.initialBounds,
|
45990 | width,
|
45991 | height;
|
45992 |
|
45993 | if (context.direction === 'e') {
|
45994 | attr$1(element, {
|
45995 | width: max$5(initialBounds.width + delta.x, 5)
|
45996 | });
|
45997 | } else {
|
45998 | width = max$5(initialBounds.width - delta.x, 5);
|
45999 |
|
46000 | attr$1(element, {
|
46001 | width: width,
|
46002 | x: initialBounds.x + initialBounds.width - width
|
46003 | });
|
46004 | }
|
46005 |
|
46006 | if (context.direction === 's') {
|
46007 | attr$1(element, {
|
46008 | height: max$5(initialBounds.height + delta.y, 5)
|
46009 | });
|
46010 | } else {
|
46011 | height = max$5(initialBounds.height - delta.y, 5);
|
46012 |
|
46013 | attr$1(element, {
|
46014 | height: height,
|
46015 | y: initialBounds.y + initialBounds.height - height
|
46016 | });
|
46017 | }
|
46018 | });
|
46019 |
|
46020 | });
|
46021 |
|
46022 |
|
46023 | eventBus.on('spaceTool.cleanup', function(event) {
|
46024 |
|
46025 | var context = event.context,
|
46026 | movingShapes = context.movingShapes,
|
46027 | movingConnections = context.movingConnections,
|
46028 | resizingShapes = context.resizingShapes,
|
46029 | line = context.line,
|
46030 | dragGroup = context.dragGroup,
|
46031 | frameGroup = context.frameGroup;
|
46032 |
|
46033 |
|
46034 | forEach(movingShapes, function(shape) {
|
46035 | canvas.removeMarker(shape, MARKER_DRAGGING);
|
46036 | });
|
46037 |
|
46038 |
|
46039 | forEach(movingConnections, function(connection) {
|
46040 | canvas.removeMarker(connection, MARKER_DRAGGING);
|
46041 | });
|
46042 |
|
46043 | if (dragGroup) {
|
46044 | remove$1(line);
|
46045 | remove$1(dragGroup);
|
46046 | }
|
46047 |
|
46048 | forEach(resizingShapes, function(shape) {
|
46049 | canvas.removeMarker(shape, MARKER_RESIZING$1);
|
46050 | });
|
46051 |
|
46052 | if (frameGroup) {
|
46053 | remove$1(frameGroup);
|
46054 | }
|
46055 | });
|
46056 | }
|
46057 |
|
46058 | SpaceToolPreview.$inject = [
|
46059 | 'eventBus',
|
46060 | 'elementRegistry',
|
46061 | 'canvas',
|
46062 | 'styles',
|
46063 | 'previewSupport'
|
46064 | ];
|
46065 |
|
46066 |
|
46067 |
|
46068 |
|
46069 | |
46070 |
|
46071 |
|
46072 | function isConnection$4(element) {
|
46073 | return element.waypoints;
|
46074 | }
|
46075 |
|
46076 | var SpaceToolModule = {
|
46077 | __init__: ['spaceToolPreview'],
|
46078 | __depends__: [
|
46079 | DraggingModule,
|
46080 | RulesModule,
|
46081 | ToolManagerModule,
|
46082 | PreviewSupportModule
|
46083 | ],
|
46084 | spaceTool: ['type', SpaceTool ],
|
46085 | spaceToolPreview: ['type', SpaceToolPreview ]
|
46086 | };
|
46087 |
|
46088 | function BpmnFactory(moddle) {
|
46089 | this._model = moddle;
|
46090 | }
|
46091 |
|
46092 | BpmnFactory.$inject = [ 'moddle' ];
|
46093 |
|
46094 |
|
46095 | BpmnFactory.prototype._needsId = function(element) {
|
46096 | return isAny(element, [
|
46097 | 'bpmn:RootElement',
|
46098 | 'bpmn:FlowElement',
|
46099 | 'bpmn:MessageFlow',
|
46100 | 'bpmn:DataAssociation',
|
46101 | 'bpmn:Artifact',
|
46102 | 'bpmn:Participant',
|
46103 | 'bpmn:Lane',
|
46104 | 'bpmn:LaneSet',
|
46105 | 'bpmn:Process',
|
46106 | 'bpmn:Collaboration',
|
46107 | 'bpmndi:BPMNShape',
|
46108 | 'bpmndi:BPMNEdge',
|
46109 | 'bpmndi:BPMNDiagram',
|
46110 | 'bpmndi:BPMNPlane',
|
46111 | 'bpmn:Property',
|
46112 | 'bpmn:CategoryValue'
|
46113 | ]);
|
46114 | };
|
46115 |
|
46116 | BpmnFactory.prototype._ensureId = function(element) {
|
46117 |
|
46118 |
|
46119 |
|
46120 | var prefix = (element.$type || '').replace(/^[^:]*:/g, '') + '_';
|
46121 |
|
46122 | if (!element.id && this._needsId(element)) {
|
46123 | element.id = this._model.ids.nextPrefixed(prefix, element);
|
46124 | }
|
46125 | };
|
46126 |
|
46127 |
|
46128 | BpmnFactory.prototype.create = function(type, attrs) {
|
46129 | var element = this._model.create(type, attrs || {});
|
46130 |
|
46131 | this._ensureId(element);
|
46132 |
|
46133 | return element;
|
46134 | };
|
46135 |
|
46136 |
|
46137 | BpmnFactory.prototype.createDiLabel = function() {
|
46138 | return this.create('bpmndi:BPMNLabel', {
|
46139 | bounds: this.createDiBounds()
|
46140 | });
|
46141 | };
|
46142 |
|
46143 |
|
46144 | BpmnFactory.prototype.createDiShape = function(semantic, bounds, attrs) {
|
46145 |
|
46146 | return this.create('bpmndi:BPMNShape', assign({
|
46147 | bpmnElement: semantic,
|
46148 | bounds: this.createDiBounds(bounds)
|
46149 | }, attrs));
|
46150 | };
|
46151 |
|
46152 |
|
46153 | BpmnFactory.prototype.createDiBounds = function(bounds) {
|
46154 | return this.create('dc:Bounds', bounds);
|
46155 | };
|
46156 |
|
46157 |
|
46158 | BpmnFactory.prototype.createDiWaypoints = function(waypoints) {
|
46159 | var self = this;
|
46160 |
|
46161 | return map(waypoints, function(pos) {
|
46162 | return self.createDiWaypoint(pos);
|
46163 | });
|
46164 | };
|
46165 |
|
46166 | BpmnFactory.prototype.createDiWaypoint = function(point) {
|
46167 | return this.create('dc:Point', pick(point, [ 'x', 'y' ]));
|
46168 | };
|
46169 |
|
46170 |
|
46171 | BpmnFactory.prototype.createDiEdge = function(semantic, waypoints, attrs) {
|
46172 | return this.create('bpmndi:BPMNEdge', assign({
|
46173 | bpmnElement: semantic
|
46174 | }, attrs));
|
46175 | };
|
46176 |
|
46177 | BpmnFactory.prototype.createDiPlane = function(semantic) {
|
46178 | return this.create('bpmndi:BPMNPlane', {
|
46179 | bpmnElement: semantic
|
46180 | });
|
46181 | };
|
46182 |
|
46183 | |
46184 |
|
46185 |
|
46186 |
|
46187 | function BpmnUpdater(
|
46188 | eventBus, bpmnFactory, connectionDocking,
|
46189 | translate) {
|
46190 |
|
46191 | CommandInterceptor.call(this, eventBus);
|
46192 |
|
46193 | this._bpmnFactory = bpmnFactory;
|
46194 | this._translate = translate;
|
46195 |
|
46196 | var self = this;
|
46197 |
|
46198 |
|
46199 |
|
46200 |
|
46201 |
|
46202 |
|
46203 | function cropConnection(e) {
|
46204 | var context = e.context,
|
46205 | hints = context.hints || {},
|
46206 | connection;
|
46207 |
|
46208 | if (!context.cropped && hints.createElementsBehavior !== false) {
|
46209 | connection = context.connection;
|
46210 | connection.waypoints = connectionDocking.getCroppedWaypoints(connection);
|
46211 | context.cropped = true;
|
46212 | }
|
46213 | }
|
46214 |
|
46215 | this.executed([
|
46216 | 'connection.layout',
|
46217 | 'connection.create'
|
46218 | ], cropConnection);
|
46219 |
|
46220 | this.reverted([ 'connection.layout' ], function(e) {
|
46221 | delete e.context.cropped;
|
46222 | });
|
46223 |
|
46224 |
|
46225 |
|
46226 |
|
46227 |
|
46228 |
|
46229 |
|
46230 | function updateParent(e) {
|
46231 | var context = e.context;
|
46232 |
|
46233 | self.updateParent(context.shape || context.connection, context.oldParent);
|
46234 | }
|
46235 |
|
46236 | function reverseUpdateParent(e) {
|
46237 | var context = e.context;
|
46238 |
|
46239 | var element = context.shape || context.connection,
|
46240 |
|
46241 |
|
46242 | oldParent = context.parent || context.newParent;
|
46243 |
|
46244 | self.updateParent(element, oldParent);
|
46245 | }
|
46246 |
|
46247 | this.executed([
|
46248 | 'shape.move',
|
46249 | 'shape.create',
|
46250 | 'shape.delete',
|
46251 | 'connection.create',
|
46252 | 'connection.move',
|
46253 | 'connection.delete'
|
46254 | ], ifBpmn(updateParent));
|
46255 |
|
46256 | this.reverted([
|
46257 | 'shape.move',
|
46258 | 'shape.create',
|
46259 | 'shape.delete',
|
46260 | 'connection.create',
|
46261 | 'connection.move',
|
46262 | 'connection.delete'
|
46263 | ], ifBpmn(reverseUpdateParent));
|
46264 |
|
46265 | |
46266 |
|
46267 |
|
46268 |
|
46269 |
|
46270 |
|
46271 |
|
46272 |
|
46273 | function updateRoot(event) {
|
46274 | var context = event.context,
|
46275 | oldRoot = context.oldRoot,
|
46276 | children = oldRoot.children;
|
46277 |
|
46278 | forEach(children, function(child) {
|
46279 | if (is$1(child, 'bpmn:BaseElement')) {
|
46280 | self.updateParent(child);
|
46281 | }
|
46282 | });
|
46283 | }
|
46284 |
|
46285 | this.executed([ 'canvas.updateRoot' ], updateRoot);
|
46286 | this.reverted([ 'canvas.updateRoot' ], updateRoot);
|
46287 |
|
46288 |
|
46289 |
|
46290 | function updateBounds(e) {
|
46291 | var shape = e.context.shape;
|
46292 |
|
46293 | if (!is$1(shape, 'bpmn:BaseElement')) {
|
46294 | return;
|
46295 | }
|
46296 |
|
46297 | self.updateBounds(shape);
|
46298 | }
|
46299 |
|
46300 | this.executed([ 'shape.move', 'shape.create', 'shape.resize' ], ifBpmn(function(event) {
|
46301 |
|
46302 |
|
46303 | if (event.context.shape.type === 'label') {
|
46304 | return;
|
46305 | }
|
46306 |
|
46307 | updateBounds(event);
|
46308 | }));
|
46309 |
|
46310 | this.reverted([ 'shape.move', 'shape.create', 'shape.resize' ], ifBpmn(function(event) {
|
46311 |
|
46312 |
|
46313 | if (event.context.shape.type === 'label') {
|
46314 | return;
|
46315 | }
|
46316 |
|
46317 | updateBounds(event);
|
46318 | }));
|
46319 |
|
46320 |
|
46321 |
|
46322 | eventBus.on('shape.changed', function(event) {
|
46323 | if (event.element.type === 'label') {
|
46324 | updateBounds({ context: { shape: event.element } });
|
46325 | }
|
46326 | });
|
46327 |
|
46328 |
|
46329 | function updateConnection(e) {
|
46330 | self.updateConnection(e.context);
|
46331 | }
|
46332 |
|
46333 | this.executed([
|
46334 | 'connection.create',
|
46335 | 'connection.move',
|
46336 | 'connection.delete',
|
46337 | 'connection.reconnect'
|
46338 | ], ifBpmn(updateConnection));
|
46339 |
|
46340 | this.reverted([
|
46341 | 'connection.create',
|
46342 | 'connection.move',
|
46343 | 'connection.delete',
|
46344 | 'connection.reconnect'
|
46345 | ], ifBpmn(updateConnection));
|
46346 |
|
46347 |
|
46348 |
|
46349 | function updateConnectionWaypoints(e) {
|
46350 | self.updateConnectionWaypoints(e.context.connection);
|
46351 | }
|
46352 |
|
46353 | this.executed([
|
46354 | 'connection.layout',
|
46355 | 'connection.move',
|
46356 | 'connection.updateWaypoints',
|
46357 | ], ifBpmn(updateConnectionWaypoints));
|
46358 |
|
46359 | this.reverted([
|
46360 | 'connection.layout',
|
46361 | 'connection.move',
|
46362 | 'connection.updateWaypoints',
|
46363 | ], ifBpmn(updateConnectionWaypoints));
|
46364 |
|
46365 |
|
46366 | this.executed('connection.reconnect', ifBpmn(function(event) {
|
46367 | var context = event.context,
|
46368 | connection = context.connection,
|
46369 | oldSource = context.oldSource,
|
46370 | newSource = context.newSource,
|
46371 | connectionBo = getBusinessObject(connection),
|
46372 | oldSourceBo = getBusinessObject(oldSource),
|
46373 | newSourceBo = getBusinessObject(newSource);
|
46374 |
|
46375 |
|
46376 |
|
46377 | if (connectionBo.conditionExpression && !isAny(newSourceBo, [
|
46378 | 'bpmn:Activity',
|
46379 | 'bpmn:ExclusiveGateway',
|
46380 | 'bpmn:InclusiveGateway'
|
46381 | ])) {
|
46382 | context.oldConditionExpression = connectionBo.conditionExpression;
|
46383 |
|
46384 | delete connectionBo.conditionExpression;
|
46385 | }
|
46386 |
|
46387 |
|
46388 |
|
46389 | if (oldSource !== newSource && oldSourceBo.default === connectionBo) {
|
46390 | context.oldDefault = oldSourceBo.default;
|
46391 |
|
46392 | delete oldSourceBo.default;
|
46393 | }
|
46394 | }));
|
46395 |
|
46396 | this.reverted('connection.reconnect', ifBpmn(function(event) {
|
46397 | var context = event.context,
|
46398 | connection = context.connection,
|
46399 | oldSource = context.oldSource,
|
46400 | newSource = context.newSource,
|
46401 | connectionBo = getBusinessObject(connection),
|
46402 | oldSourceBo = getBusinessObject(oldSource),
|
46403 | newSourceBo = getBusinessObject(newSource);
|
46404 |
|
46405 |
|
46406 | if (context.oldConditionExpression) {
|
46407 | connectionBo.conditionExpression = context.oldConditionExpression;
|
46408 | }
|
46409 |
|
46410 |
|
46411 | if (context.oldDefault) {
|
46412 | oldSourceBo.default = context.oldDefault;
|
46413 |
|
46414 | delete newSourceBo.default;
|
46415 | }
|
46416 | }));
|
46417 |
|
46418 |
|
46419 | function updateAttachment(e) {
|
46420 | self.updateAttachment(e.context);
|
46421 | }
|
46422 |
|
46423 | this.executed([ 'element.updateAttachment' ], ifBpmn(updateAttachment));
|
46424 | this.reverted([ 'element.updateAttachment' ], ifBpmn(updateAttachment));
|
46425 | }
|
46426 |
|
46427 | inherits_browser(BpmnUpdater, CommandInterceptor);
|
46428 |
|
46429 | BpmnUpdater.$inject = [
|
46430 | 'eventBus',
|
46431 | 'bpmnFactory',
|
46432 | 'connectionDocking',
|
46433 | 'translate'
|
46434 | ];
|
46435 |
|
46436 |
|
46437 |
|
46438 |
|
46439 | BpmnUpdater.prototype.updateAttachment = function(context) {
|
46440 |
|
46441 | var shape = context.shape,
|
46442 | businessObject = shape.businessObject,
|
46443 | host = shape.host;
|
46444 |
|
46445 | businessObject.attachedToRef = host && host.businessObject;
|
46446 | };
|
46447 |
|
46448 | BpmnUpdater.prototype.updateParent = function(element, oldParent) {
|
46449 |
|
46450 |
|
46451 | if (element instanceof Label) {
|
46452 | return;
|
46453 | }
|
46454 |
|
46455 |
|
46456 | if (is$1(element, 'bpmn:DataStoreReference') &&
|
46457 | element.parent &&
|
46458 | is$1(element.parent, 'bpmn:Collaboration')) {
|
46459 | return;
|
46460 | }
|
46461 |
|
46462 | var parentShape = element.parent;
|
46463 |
|
46464 | var businessObject = element.businessObject,
|
46465 | parentBusinessObject = parentShape && parentShape.businessObject,
|
46466 | parentDi = parentBusinessObject && parentBusinessObject.di;
|
46467 |
|
46468 | if (is$1(element, 'bpmn:FlowNode')) {
|
46469 | this.updateFlowNodeRefs(businessObject, parentBusinessObject, oldParent && oldParent.businessObject);
|
46470 | }
|
46471 |
|
46472 | if (is$1(element, 'bpmn:DataOutputAssociation')) {
|
46473 | if (element.source) {
|
46474 | parentBusinessObject = element.source.businessObject;
|
46475 | } else {
|
46476 | parentBusinessObject = null;
|
46477 | }
|
46478 | }
|
46479 |
|
46480 | if (is$1(element, 'bpmn:DataInputAssociation')) {
|
46481 | if (element.target) {
|
46482 | parentBusinessObject = element.target.businessObject;
|
46483 | } else {
|
46484 | parentBusinessObject = null;
|
46485 | }
|
46486 | }
|
46487 |
|
46488 | this.updateSemanticParent(businessObject, parentBusinessObject);
|
46489 |
|
46490 | if (is$1(element, 'bpmn:DataObjectReference') && businessObject.dataObjectRef) {
|
46491 | this.updateSemanticParent(businessObject.dataObjectRef, parentBusinessObject);
|
46492 | }
|
46493 |
|
46494 | this.updateDiParent(businessObject.di, parentDi);
|
46495 | };
|
46496 |
|
46497 |
|
46498 | BpmnUpdater.prototype.updateBounds = function(shape) {
|
46499 |
|
46500 | var di = shape.businessObject.di;
|
46501 |
|
46502 | var target = (shape instanceof Label) ? this._getLabel(di) : di;
|
46503 |
|
46504 | var bounds = target.bounds;
|
46505 |
|
46506 | if (!bounds) {
|
46507 | bounds = this._bpmnFactory.createDiBounds();
|
46508 | target.set('bounds', bounds);
|
46509 | }
|
46510 |
|
46511 | assign(bounds, {
|
46512 | x: shape.x,
|
46513 | y: shape.y,
|
46514 | width: shape.width,
|
46515 | height: shape.height
|
46516 | });
|
46517 | };
|
46518 |
|
46519 | BpmnUpdater.prototype.updateFlowNodeRefs = function(businessObject, newContainment, oldContainment) {
|
46520 |
|
46521 | if (oldContainment === newContainment) {
|
46522 | return;
|
46523 | }
|
46524 |
|
46525 | var oldRefs, newRefs;
|
46526 |
|
46527 | if (is$1 (oldContainment, 'bpmn:Lane')) {
|
46528 | oldRefs = oldContainment.get('flowNodeRef');
|
46529 | remove$2(oldRefs, businessObject);
|
46530 | }
|
46531 |
|
46532 | if (is$1(newContainment, 'bpmn:Lane')) {
|
46533 | newRefs = newContainment.get('flowNodeRef');
|
46534 | add$1(newRefs, businessObject);
|
46535 | }
|
46536 | };
|
46537 |
|
46538 |
|
46539 |
|
46540 | BpmnUpdater.prototype.updateDiConnection = function(di, newSource, newTarget) {
|
46541 |
|
46542 | if (di.sourceElement && di.sourceElement.bpmnElement !== newSource) {
|
46543 | di.sourceElement = newSource && newSource.di;
|
46544 | }
|
46545 |
|
46546 | if (di.targetElement && di.targetElement.bpmnElement !== newTarget) {
|
46547 | di.targetElement = newTarget && newTarget.di;
|
46548 | }
|
46549 |
|
46550 | };
|
46551 |
|
46552 |
|
46553 | BpmnUpdater.prototype.updateDiParent = function(di, parentDi) {
|
46554 |
|
46555 | if (parentDi && !is$1(parentDi, 'bpmndi:BPMNPlane')) {
|
46556 | parentDi = parentDi.$parent;
|
46557 | }
|
46558 |
|
46559 | if (di.$parent === parentDi) {
|
46560 | return;
|
46561 | }
|
46562 |
|
46563 | var planeElements = (parentDi || di.$parent).get('planeElement');
|
46564 |
|
46565 | if (parentDi) {
|
46566 | planeElements.push(di);
|
46567 | di.$parent = parentDi;
|
46568 | } else {
|
46569 | remove$2(planeElements, di);
|
46570 | di.$parent = null;
|
46571 | }
|
46572 | };
|
46573 |
|
46574 | function getDefinitions(element) {
|
46575 | while (element && !is$1(element, 'bpmn:Definitions')) {
|
46576 | element = element.$parent;
|
46577 | }
|
46578 |
|
46579 | return element;
|
46580 | }
|
46581 |
|
46582 | BpmnUpdater.prototype.getLaneSet = function(container) {
|
46583 |
|
46584 | var laneSet, laneSets;
|
46585 |
|
46586 |
|
46587 | if (is$1(container, 'bpmn:Lane')) {
|
46588 | laneSet = container.childLaneSet;
|
46589 |
|
46590 | if (!laneSet) {
|
46591 | laneSet = this._bpmnFactory.create('bpmn:LaneSet');
|
46592 | container.childLaneSet = laneSet;
|
46593 | laneSet.$parent = container;
|
46594 | }
|
46595 |
|
46596 | return laneSet;
|
46597 | }
|
46598 |
|
46599 |
|
46600 | if (is$1(container, 'bpmn:Participant')) {
|
46601 | container = container.processRef;
|
46602 | }
|
46603 |
|
46604 |
|
46605 | laneSets = container.get('laneSets');
|
46606 | laneSet = laneSets[0];
|
46607 |
|
46608 | if (!laneSet) {
|
46609 | laneSet = this._bpmnFactory.create('bpmn:LaneSet');
|
46610 | laneSet.$parent = container;
|
46611 | laneSets.push(laneSet);
|
46612 | }
|
46613 |
|
46614 | return laneSet;
|
46615 | };
|
46616 |
|
46617 | BpmnUpdater.prototype.updateSemanticParent = function(businessObject, newParent, visualParent) {
|
46618 |
|
46619 | var containment,
|
46620 | translate = this._translate;
|
46621 |
|
46622 | if (businessObject.$parent === newParent) {
|
46623 | return;
|
46624 | }
|
46625 |
|
46626 | if (is$1(businessObject, 'bpmn:DataInput') || is$1(businessObject, 'bpmn:DataOutput')) {
|
46627 |
|
46628 | if (is$1(newParent, 'bpmn:Participant') && 'processRef' in newParent) {
|
46629 | newParent = newParent.processRef;
|
46630 | }
|
46631 |
|
46632 |
|
46633 | if ('ioSpecification' in newParent && newParent.ioSpecification === businessObject.$parent) {
|
46634 | return;
|
46635 | }
|
46636 | }
|
46637 |
|
46638 | if (is$1(businessObject, 'bpmn:Lane')) {
|
46639 |
|
46640 | if (newParent) {
|
46641 | newParent = this.getLaneSet(newParent);
|
46642 | }
|
46643 |
|
46644 | containment = 'lanes';
|
46645 | } else
|
46646 |
|
46647 | if (is$1(businessObject, 'bpmn:FlowElement')) {
|
46648 |
|
46649 | if (newParent) {
|
46650 |
|
46651 | if (is$1(newParent, 'bpmn:Participant')) {
|
46652 | newParent = newParent.processRef;
|
46653 | } else
|
46654 |
|
46655 | if (is$1(newParent, 'bpmn:Lane')) {
|
46656 | do {
|
46657 |
|
46658 |
|
46659 | newParent = newParent.$parent.$parent;
|
46660 | } while (is$1(newParent, 'bpmn:Lane'));
|
46661 |
|
46662 | }
|
46663 | }
|
46664 |
|
46665 | containment = 'flowElements';
|
46666 |
|
46667 | } else
|
46668 |
|
46669 | if (is$1(businessObject, 'bpmn:Artifact')) {
|
46670 |
|
46671 | while (newParent &&
|
46672 | !is$1(newParent, 'bpmn:Process') &&
|
46673 | !is$1(newParent, 'bpmn:SubProcess') &&
|
46674 | !is$1(newParent, 'bpmn:Collaboration')) {
|
46675 |
|
46676 | if (is$1(newParent, 'bpmn:Participant')) {
|
46677 | newParent = newParent.processRef;
|
46678 | break;
|
46679 | } else {
|
46680 | newParent = newParent.$parent;
|
46681 | }
|
46682 | }
|
46683 |
|
46684 | containment = 'artifacts';
|
46685 | } else
|
46686 |
|
46687 | if (is$1(businessObject, 'bpmn:MessageFlow')) {
|
46688 | containment = 'messageFlows';
|
46689 |
|
46690 | } else
|
46691 |
|
46692 | if (is$1(businessObject, 'bpmn:Participant')) {
|
46693 | containment = 'participants';
|
46694 |
|
46695 |
|
46696 |
|
46697 |
|
46698 | var process = businessObject.processRef,
|
46699 | definitions;
|
46700 |
|
46701 | if (process) {
|
46702 | definitions = getDefinitions(businessObject.$parent || newParent);
|
46703 |
|
46704 | if (businessObject.$parent) {
|
46705 | remove$2(definitions.get('rootElements'), process);
|
46706 | process.$parent = null;
|
46707 | }
|
46708 |
|
46709 | if (newParent) {
|
46710 | add$1(definitions.get('rootElements'), process);
|
46711 | process.$parent = definitions;
|
46712 | }
|
46713 | }
|
46714 | } else
|
46715 |
|
46716 | if (is$1(businessObject, 'bpmn:DataOutputAssociation')) {
|
46717 | containment = 'dataOutputAssociations';
|
46718 | } else
|
46719 |
|
46720 | if (is$1(businessObject, 'bpmn:DataInputAssociation')) {
|
46721 | containment = 'dataInputAssociations';
|
46722 | }
|
46723 |
|
46724 | if (!containment) {
|
46725 | throw new Error(translate(
|
46726 | 'no parent for {element} in {parent}',
|
46727 | {
|
46728 | element: businessObject.id,
|
46729 | parent: newParent.id
|
46730 | }
|
46731 | ));
|
46732 | }
|
46733 |
|
46734 | var children;
|
46735 |
|
46736 | if (businessObject.$parent) {
|
46737 |
|
46738 |
|
46739 | children = businessObject.$parent.get(containment);
|
46740 | remove$2(children, businessObject);
|
46741 | }
|
46742 |
|
46743 | if (!newParent) {
|
46744 | businessObject.$parent = null;
|
46745 | } else {
|
46746 |
|
46747 |
|
46748 | children = newParent.get(containment);
|
46749 | children.push(businessObject);
|
46750 | businessObject.$parent = newParent;
|
46751 | }
|
46752 |
|
46753 | if (visualParent) {
|
46754 | var diChildren = visualParent.get(containment);
|
46755 |
|
46756 | remove$2(children, businessObject);
|
46757 |
|
46758 | if (newParent) {
|
46759 |
|
46760 | if (!diChildren) {
|
46761 | diChildren = [];
|
46762 | newParent.set(containment, diChildren);
|
46763 | }
|
46764 |
|
46765 | diChildren.push(businessObject);
|
46766 | }
|
46767 | }
|
46768 | };
|
46769 |
|
46770 |
|
46771 | BpmnUpdater.prototype.updateConnectionWaypoints = function(connection) {
|
46772 | connection.businessObject.di.set('waypoint', this._bpmnFactory.createDiWaypoints(connection.waypoints));
|
46773 | };
|
46774 |
|
46775 |
|
46776 | BpmnUpdater.prototype.updateConnection = function(context) {
|
46777 |
|
46778 | var connection = context.connection,
|
46779 | businessObject = getBusinessObject(connection),
|
46780 | newSource = getBusinessObject(connection.source),
|
46781 | newTarget = getBusinessObject(connection.target),
|
46782 | visualParent;
|
46783 |
|
46784 | if (!is$1(businessObject, 'bpmn:DataAssociation')) {
|
46785 |
|
46786 | var inverseSet = is$1(businessObject, 'bpmn:SequenceFlow');
|
46787 |
|
46788 | if (businessObject.sourceRef !== newSource) {
|
46789 | if (inverseSet) {
|
46790 | remove$2(businessObject.sourceRef && businessObject.sourceRef.get('outgoing'), businessObject);
|
46791 |
|
46792 | if (newSource && newSource.get('outgoing')) {
|
46793 | newSource.get('outgoing').push(businessObject);
|
46794 | }
|
46795 | }
|
46796 |
|
46797 | businessObject.sourceRef = newSource;
|
46798 | }
|
46799 |
|
46800 | if (businessObject.targetRef !== newTarget) {
|
46801 | if (inverseSet) {
|
46802 | remove$2(businessObject.targetRef && businessObject.targetRef.get('incoming'), businessObject);
|
46803 |
|
46804 | if (newTarget && newTarget.get('incoming')) {
|
46805 | newTarget.get('incoming').push(businessObject);
|
46806 | }
|
46807 | }
|
46808 |
|
46809 | businessObject.targetRef = newTarget;
|
46810 | }
|
46811 | } else
|
46812 |
|
46813 | if (is$1(businessObject, 'bpmn:DataInputAssociation')) {
|
46814 |
|
46815 |
|
46816 | businessObject.get('sourceRef')[0] = newSource;
|
46817 |
|
46818 | visualParent = context.parent || context.newParent || newTarget;
|
46819 |
|
46820 | this.updateSemanticParent(businessObject, newTarget, visualParent);
|
46821 | } else
|
46822 |
|
46823 | if (is$1(businessObject, 'bpmn:DataOutputAssociation')) {
|
46824 | visualParent = context.parent || context.newParent || newSource;
|
46825 |
|
46826 | this.updateSemanticParent(businessObject, newSource, visualParent);
|
46827 |
|
46828 |
|
46829 | businessObject.targetRef = newTarget;
|
46830 | }
|
46831 |
|
46832 | this.updateConnectionWaypoints(connection);
|
46833 |
|
46834 | this.updateDiConnection(businessObject.di, newSource, newTarget);
|
46835 | };
|
46836 |
|
46837 |
|
46838 |
|
46839 |
|
46840 | BpmnUpdater.prototype._getLabel = function(di) {
|
46841 | if (!di.label) {
|
46842 | di.label = this._bpmnFactory.createDiLabel();
|
46843 | }
|
46844 |
|
46845 | return di.label;
|
46846 | };
|
46847 |
|
46848 |
|
46849 | |
46850 |
|
46851 |
|
46852 |
|
46853 |
|
46854 |
|
46855 |
|
46856 | function ifBpmn(fn) {
|
46857 |
|
46858 | return function(event) {
|
46859 |
|
46860 | var context = event.context,
|
46861 | element = context.shape || context.connection;
|
46862 |
|
46863 | if (is$1(element, 'bpmn:BaseElement')) {
|
46864 | fn(event);
|
46865 | }
|
46866 | };
|
46867 | }
|
46868 |
|
46869 | |
46870 |
|
46871 |
|
46872 | function ElementFactory$1(bpmnFactory, moddle, translate) {
|
46873 | ElementFactory.call(this);
|
46874 |
|
46875 | this._bpmnFactory = bpmnFactory;
|
46876 | this._moddle = moddle;
|
46877 | this._translate = translate;
|
46878 | }
|
46879 |
|
46880 | inherits_browser(ElementFactory$1, ElementFactory);
|
46881 |
|
46882 | ElementFactory$1.$inject = [
|
46883 | 'bpmnFactory',
|
46884 | 'moddle',
|
46885 | 'translate'
|
46886 | ];
|
46887 |
|
46888 | ElementFactory$1.prototype.baseCreate = ElementFactory.prototype.create;
|
46889 |
|
46890 | ElementFactory$1.prototype.create = function(elementType, attrs) {
|
46891 |
|
46892 |
|
46893 |
|
46894 |
|
46895 | if (elementType === 'label') {
|
46896 | return this.baseCreate(elementType, assign({ type: 'label' }, DEFAULT_LABEL_SIZE$1, attrs));
|
46897 | }
|
46898 |
|
46899 | return this.createBpmnElement(elementType, attrs);
|
46900 | };
|
46901 |
|
46902 | ElementFactory$1.prototype.createBpmnElement = function(elementType, attrs) {
|
46903 | var size,
|
46904 | translate = this._translate;
|
46905 |
|
46906 | attrs = attrs || {};
|
46907 |
|
46908 | var businessObject = attrs.businessObject;
|
46909 |
|
46910 | if (!businessObject) {
|
46911 | if (!attrs.type) {
|
46912 | throw new Error(translate('no shape type specified'));
|
46913 | }
|
46914 |
|
46915 | businessObject = this._bpmnFactory.create(attrs.type);
|
46916 | }
|
46917 |
|
46918 | if (!businessObject.di) {
|
46919 | if (elementType === 'root') {
|
46920 | businessObject.di = this._bpmnFactory.createDiPlane(businessObject, [], {
|
46921 | id: businessObject.id + '_di'
|
46922 | });
|
46923 | } else
|
46924 | if (elementType === 'connection') {
|
46925 | businessObject.di = this._bpmnFactory.createDiEdge(businessObject, [], {
|
46926 | id: businessObject.id + '_di'
|
46927 | });
|
46928 | } else {
|
46929 | businessObject.di = this._bpmnFactory.createDiShape(businessObject, {}, {
|
46930 | id: businessObject.id + '_di'
|
46931 | });
|
46932 | }
|
46933 | }
|
46934 |
|
46935 | if (is$1(businessObject, 'bpmn:Group')) {
|
46936 | attrs = assign({
|
46937 | isFrame: true
|
46938 | }, attrs);
|
46939 | }
|
46940 |
|
46941 | if (attrs.di) {
|
46942 | assign(businessObject.di, attrs.di);
|
46943 |
|
46944 | delete attrs.di;
|
46945 | }
|
46946 |
|
46947 | applyAttributes(businessObject, attrs, [
|
46948 | 'processRef',
|
46949 | 'isInterrupting',
|
46950 | 'associationDirection',
|
46951 | 'isForCompensation'
|
46952 | ]);
|
46953 |
|
46954 | if (attrs.isExpanded) {
|
46955 | applyAttribute(businessObject.di, attrs, 'isExpanded');
|
46956 | }
|
46957 |
|
46958 | if (is$1(businessObject, 'bpmn:ExclusiveGateway')) {
|
46959 | businessObject.di.isMarkerVisible = true;
|
46960 | }
|
46961 |
|
46962 | var eventDefinitions,
|
46963 | newEventDefinition;
|
46964 |
|
46965 | if (attrs.eventDefinitionType) {
|
46966 | eventDefinitions = businessObject.get('eventDefinitions') || [];
|
46967 | newEventDefinition = this._bpmnFactory.create(attrs.eventDefinitionType);
|
46968 |
|
46969 | if (attrs.eventDefinitionType === 'bpmn:ConditionalEventDefinition') {
|
46970 | newEventDefinition.condition = this._bpmnFactory.create('bpmn:FormalExpression');
|
46971 | }
|
46972 |
|
46973 | eventDefinitions.push(newEventDefinition);
|
46974 |
|
46975 | newEventDefinition.$parent = businessObject;
|
46976 | businessObject.eventDefinitions = eventDefinitions;
|
46977 |
|
46978 | delete attrs.eventDefinitionType;
|
46979 | }
|
46980 |
|
46981 | size = this._getDefaultSize(businessObject);
|
46982 |
|
46983 | attrs = assign({
|
46984 | businessObject: businessObject,
|
46985 | id: businessObject.id
|
46986 | }, size, attrs);
|
46987 |
|
46988 | return this.baseCreate(elementType, attrs);
|
46989 | };
|
46990 |
|
46991 |
|
46992 | ElementFactory$1.prototype._getDefaultSize = function(semantic) {
|
46993 |
|
46994 | if (is$1(semantic, 'bpmn:SubProcess')) {
|
46995 |
|
46996 | if (isExpanded(semantic)) {
|
46997 | return { width: 350, height: 200 };
|
46998 | } else {
|
46999 | return { width: 100, height: 80 };
|
47000 | }
|
47001 | }
|
47002 |
|
47003 | if (is$1(semantic, 'bpmn:Task')) {
|
47004 | return { width: 100, height: 80 };
|
47005 | }
|
47006 |
|
47007 | if (is$1(semantic, 'bpmn:Gateway')) {
|
47008 | return { width: 50, height: 50 };
|
47009 | }
|
47010 |
|
47011 | if (is$1(semantic, 'bpmn:Event')) {
|
47012 | return { width: 36, height: 36 };
|
47013 | }
|
47014 |
|
47015 | if (is$1(semantic, 'bpmn:Participant')) {
|
47016 | if (isExpanded(semantic)) {
|
47017 | return { width: 600, height: 250 };
|
47018 | } else {
|
47019 | return { width: 400, height: 60 };
|
47020 | }
|
47021 | }
|
47022 |
|
47023 | if (is$1(semantic, 'bpmn:Lane')) {
|
47024 | return { width: 400, height: 100 };
|
47025 | }
|
47026 |
|
47027 | if (is$1(semantic, 'bpmn:DataObjectReference')) {
|
47028 | return { width: 36, height: 50 };
|
47029 | }
|
47030 |
|
47031 | if (is$1(semantic, 'bpmn:DataStoreReference')) {
|
47032 | return { width: 50, height: 50 };
|
47033 | }
|
47034 |
|
47035 | if (is$1(semantic, 'bpmn:TextAnnotation')) {
|
47036 | return { width: 100, height: 30 };
|
47037 | }
|
47038 |
|
47039 | if (is$1(semantic, 'bpmn:Group')) {
|
47040 | return { width: 300, height: 300 };
|
47041 | }
|
47042 |
|
47043 | return { width: 100, height: 80 };
|
47044 | };
|
47045 |
|
47046 |
|
47047 | |
47048 |
|
47049 |
|
47050 |
|
47051 |
|
47052 |
|
47053 |
|
47054 | ElementFactory$1.prototype.createParticipantShape = function(attrs) {
|
47055 |
|
47056 | if (!isObject(attrs)) {
|
47057 | attrs = { isExpanded: attrs };
|
47058 | }
|
47059 |
|
47060 | attrs = assign({ type: 'bpmn:Participant' }, attrs || {});
|
47061 |
|
47062 |
|
47063 | if (attrs.isExpanded !== false) {
|
47064 | attrs.processRef = this._bpmnFactory.create('bpmn:Process');
|
47065 | }
|
47066 |
|
47067 | return this.createShape(attrs);
|
47068 | };
|
47069 |
|
47070 |
|
47071 |
|
47072 |
|
47073 | |
47074 |
|
47075 |
|
47076 |
|
47077 |
|
47078 |
|
47079 |
|
47080 |
|
47081 | function applyAttributes(element, attrs, attributeNames) {
|
47082 |
|
47083 | forEach(attributeNames, function(property) {
|
47084 | if (attrs[property] !== undefined) {
|
47085 | applyAttribute(element, attrs, property);
|
47086 | }
|
47087 | });
|
47088 | }
|
47089 |
|
47090 | |
47091 |
|
47092 |
|
47093 |
|
47094 |
|
47095 |
|
47096 |
|
47097 |
|
47098 | function applyAttribute(element, attrs, attributeName) {
|
47099 | element[attributeName] = attrs[attributeName];
|
47100 |
|
47101 | delete attrs[attributeName];
|
47102 | }
|
47103 |
|
47104 | |
47105 |
|
47106 |
|
47107 |
|
47108 | function AlignElements$1(modeling, canvas) {
|
47109 | this._modeling = modeling;
|
47110 | this._canvas = canvas;
|
47111 | }
|
47112 |
|
47113 | AlignElements$1.$inject = [ 'modeling', 'canvas' ];
|
47114 |
|
47115 |
|
47116 | AlignElements$1.prototype.preExecute = function(context) {
|
47117 | var modeling = this._modeling;
|
47118 |
|
47119 | var elements = context.elements,
|
47120 | alignment = context.alignment;
|
47121 |
|
47122 |
|
47123 | forEach(elements, function(element) {
|
47124 | var delta = {
|
47125 | x: 0,
|
47126 | y: 0
|
47127 | };
|
47128 |
|
47129 | if (alignment.left) {
|
47130 | delta.x = alignment.left - element.x;
|
47131 |
|
47132 | } else if (alignment.right) {
|
47133 | delta.x = (alignment.right - element.width) - element.x;
|
47134 |
|
47135 | } else if (alignment.center) {
|
47136 | delta.x = (alignment.center - Math.round(element.width / 2)) - element.x;
|
47137 |
|
47138 | } else if (alignment.top) {
|
47139 | delta.y = alignment.top - element.y;
|
47140 |
|
47141 | } else if (alignment.bottom) {
|
47142 | delta.y = (alignment.bottom - element.height) - element.y;
|
47143 |
|
47144 | } else if (alignment.middle) {
|
47145 | delta.y = (alignment.middle - Math.round(element.height / 2)) - element.y;
|
47146 | }
|
47147 |
|
47148 | modeling.moveElements([ element ], delta, element.parent);
|
47149 | });
|
47150 | };
|
47151 |
|
47152 | AlignElements$1.prototype.postExecute = function(context) {
|
47153 |
|
47154 | };
|
47155 |
|
47156 | |
47157 |
|
47158 |
|
47159 |
|
47160 |
|
47161 |
|
47162 |
|
47163 |
|
47164 | function AppendShapeHandler(modeling) {
|
47165 | this._modeling = modeling;
|
47166 | }
|
47167 |
|
47168 | AppendShapeHandler.$inject = [ 'modeling' ];
|
47169 |
|
47170 |
|
47171 |
|
47172 |
|
47173 |
|
47174 | |
47175 |
|
47176 |
|
47177 |
|
47178 |
|
47179 |
|
47180 |
|
47181 |
|
47182 |
|
47183 | AppendShapeHandler.prototype.preExecute = function(context) {
|
47184 |
|
47185 | var source = context.source;
|
47186 |
|
47187 | if (!source) {
|
47188 | throw new Error('source required');
|
47189 | }
|
47190 |
|
47191 | var target = context.target || source.parent,
|
47192 | shape = context.shape;
|
47193 |
|
47194 | shape = context.shape =
|
47195 | this._modeling.createShape(
|
47196 | shape,
|
47197 | context.position,
|
47198 | target, { attach: context.attach });
|
47199 |
|
47200 | context.shape = shape;
|
47201 | };
|
47202 |
|
47203 | AppendShapeHandler.prototype.postExecute = function(context) {
|
47204 | var parent = context.connectionParent || context.shape.parent;
|
47205 |
|
47206 | if (!existsConnection(context.source, context.shape)) {
|
47207 |
|
47208 |
|
47209 | this._modeling.connect(context.source, context.shape, context.connection, parent);
|
47210 | }
|
47211 | };
|
47212 |
|
47213 |
|
47214 | function existsConnection(source, target) {
|
47215 | return some(source.outgoing, function(c) {
|
47216 | return c.target === target;
|
47217 | });
|
47218 | }
|
47219 |
|
47220 | function CreateConnectionHandler(canvas, layouter) {
|
47221 | this._canvas = canvas;
|
47222 | this._layouter = layouter;
|
47223 | }
|
47224 |
|
47225 | CreateConnectionHandler.$inject = [ 'canvas', 'layouter' ];
|
47226 |
|
47227 |
|
47228 |
|
47229 |
|
47230 |
|
47231 | |
47232 |
|
47233 |
|
47234 |
|
47235 |
|
47236 |
|
47237 |
|
47238 |
|
47239 | CreateConnectionHandler.prototype.execute = function(context) {
|
47240 |
|
47241 | var connection = context.connection,
|
47242 | source = context.source,
|
47243 | target = context.target,
|
47244 | parent = context.parent,
|
47245 | parentIndex = context.parentIndex,
|
47246 | hints = context.hints;
|
47247 |
|
47248 | if (!source || !target) {
|
47249 | throw new Error('source and target required');
|
47250 | }
|
47251 |
|
47252 | if (!parent) {
|
47253 | throw new Error('parent required');
|
47254 | }
|
47255 |
|
47256 | connection.source = source;
|
47257 | connection.target = target;
|
47258 |
|
47259 | if (!connection.waypoints) {
|
47260 | connection.waypoints = this._layouter.layoutConnection(connection, hints);
|
47261 | }
|
47262 |
|
47263 |
|
47264 | this._canvas.addConnection(connection, parent, parentIndex);
|
47265 |
|
47266 | return connection;
|
47267 | };
|
47268 |
|
47269 | CreateConnectionHandler.prototype.revert = function(context) {
|
47270 | var connection = context.connection;
|
47271 |
|
47272 | this._canvas.removeConnection(connection);
|
47273 |
|
47274 | connection.source = null;
|
47275 | connection.target = null;
|
47276 |
|
47277 | return connection;
|
47278 | };
|
47279 |
|
47280 | var round$8 = Math.round;
|
47281 |
|
47282 | function CreateElementsHandler(modeling) {
|
47283 | this._modeling = modeling;
|
47284 | }
|
47285 |
|
47286 | CreateElementsHandler.$inject = [
|
47287 | 'modeling'
|
47288 | ];
|
47289 |
|
47290 | CreateElementsHandler.prototype.preExecute = function(context) {
|
47291 | var elements = context.elements,
|
47292 | parent = context.parent,
|
47293 | parentIndex = context.parentIndex,
|
47294 | position = context.position,
|
47295 | hints = context.hints;
|
47296 |
|
47297 | var modeling = this._modeling;
|
47298 |
|
47299 |
|
47300 | forEach(elements, function(element) {
|
47301 | if (!isNumber(element.x)) {
|
47302 | element.x = 0;
|
47303 | }
|
47304 |
|
47305 | if (!isNumber(element.y)) {
|
47306 | element.y = 0;
|
47307 | }
|
47308 | });
|
47309 |
|
47310 | var bbox = getBBox(elements);
|
47311 |
|
47312 |
|
47313 | forEach(elements, function(element) {
|
47314 | if (isConnection$5(element)) {
|
47315 | element.waypoints = map(element.waypoints, function(waypoint) {
|
47316 | return {
|
47317 | x: round$8(waypoint.x - bbox.x - bbox.width / 2 + position.x),
|
47318 | y: round$8(waypoint.y - bbox.y - bbox.height / 2 + position.y)
|
47319 | };
|
47320 | });
|
47321 | }
|
47322 |
|
47323 | assign(element, {
|
47324 | x: round$8(element.x - bbox.x - bbox.width / 2 + position.x),
|
47325 | y: round$8(element.y - bbox.y - bbox.height / 2 + position.y)
|
47326 | });
|
47327 | });
|
47328 |
|
47329 | var parents = getParents(elements);
|
47330 |
|
47331 | var cache = {};
|
47332 |
|
47333 | forEach(elements, function(element) {
|
47334 | if (isConnection$5(element)) {
|
47335 | cache[ element.id ] = isNumber(parentIndex) ?
|
47336 | modeling.createConnection(
|
47337 | cache[ element.source.id ],
|
47338 | cache[ element.target.id ],
|
47339 | parentIndex,
|
47340 | element,
|
47341 | element.parent || parent,
|
47342 | hints
|
47343 | ) :
|
47344 | modeling.createConnection(
|
47345 | cache[ element.source.id ],
|
47346 | cache[ element.target.id ],
|
47347 | element,
|
47348 | element.parent || parent,
|
47349 | hints
|
47350 | );
|
47351 |
|
47352 | return;
|
47353 | }
|
47354 |
|
47355 | var createShapeHints = assign({}, hints);
|
47356 |
|
47357 | if (parents.indexOf(element) === -1) {
|
47358 | createShapeHints.autoResize = false;
|
47359 | }
|
47360 |
|
47361 | cache[ element.id ] = isNumber(parentIndex) ?
|
47362 | modeling.createShape(
|
47363 | element,
|
47364 | pick(element, [ 'x', 'y', 'width', 'height' ]),
|
47365 | element.parent || parent,
|
47366 | parentIndex,
|
47367 | createShapeHints
|
47368 | ) :
|
47369 | modeling.createShape(
|
47370 | element,
|
47371 | pick(element, [ 'x', 'y', 'width', 'height' ]),
|
47372 | element.parent || parent,
|
47373 | createShapeHints
|
47374 | );
|
47375 | });
|
47376 |
|
47377 | context.elements = values(cache);
|
47378 | };
|
47379 |
|
47380 |
|
47381 |
|
47382 | function isConnection$5(element) {
|
47383 | return !!element.waypoints;
|
47384 | }
|
47385 |
|
47386 | var round$9 = Math.round;
|
47387 |
|
47388 |
|
47389 | |
47390 |
|
47391 |
|
47392 |
|
47393 |
|
47394 | function CreateShapeHandler(canvas) {
|
47395 | this._canvas = canvas;
|
47396 | }
|
47397 |
|
47398 | CreateShapeHandler.$inject = [ 'canvas' ];
|
47399 |
|
47400 |
|
47401 |
|
47402 |
|
47403 |
|
47404 | |
47405 |
|
47406 |
|
47407 |
|
47408 |
|
47409 |
|
47410 |
|
47411 | CreateShapeHandler.prototype.execute = function(context) {
|
47412 |
|
47413 | var shape = context.shape,
|
47414 | positionOrBounds = context.position,
|
47415 | parent = context.parent,
|
47416 | parentIndex = context.parentIndex;
|
47417 |
|
47418 | if (!parent) {
|
47419 | throw new Error('parent required');
|
47420 | }
|
47421 |
|
47422 | if (!positionOrBounds) {
|
47423 | throw new Error('position required');
|
47424 | }
|
47425 |
|
47426 |
|
47427 | if (positionOrBounds.width !== undefined) {
|
47428 | assign(shape, positionOrBounds);
|
47429 | } else {
|
47430 | assign(shape, {
|
47431 | x: positionOrBounds.x - round$9(shape.width / 2),
|
47432 | y: positionOrBounds.y - round$9(shape.height / 2)
|
47433 | });
|
47434 | }
|
47435 |
|
47436 |
|
47437 | this._canvas.addShape(shape, parent, parentIndex);
|
47438 |
|
47439 | return shape;
|
47440 | };
|
47441 |
|
47442 |
|
47443 | |
47444 |
|
47445 |
|
47446 | CreateShapeHandler.prototype.revert = function(context) {
|
47447 |
|
47448 | var shape = context.shape;
|
47449 |
|
47450 |
|
47451 | this._canvas.removeShape(shape);
|
47452 |
|
47453 | return shape;
|
47454 | };
|
47455 |
|
47456 | |
47457 |
|
47458 |
|
47459 |
|
47460 |
|
47461 | function CreateLabelHandler(canvas) {
|
47462 | CreateShapeHandler.call(this, canvas);
|
47463 | }
|
47464 |
|
47465 | inherits_browser(CreateLabelHandler, CreateShapeHandler);
|
47466 |
|
47467 | CreateLabelHandler.$inject = [ 'canvas' ];
|
47468 |
|
47469 |
|
47470 |
|
47471 |
|
47472 |
|
47473 | var originalExecute = CreateShapeHandler.prototype.execute;
|
47474 |
|
47475 | |
47476 |
|
47477 |
|
47478 |
|
47479 |
|
47480 |
|
47481 |
|
47482 |
|
47483 |
|
47484 |
|
47485 | CreateLabelHandler.prototype.execute = function(context) {
|
47486 |
|
47487 | var label = context.shape;
|
47488 |
|
47489 | ensureValidDimensions(label);
|
47490 |
|
47491 | label.labelTarget = context.labelTarget;
|
47492 |
|
47493 | return originalExecute.call(this, context);
|
47494 | };
|
47495 |
|
47496 | var originalRevert = CreateShapeHandler.prototype.revert;
|
47497 |
|
47498 | |
47499 |
|
47500 |
|
47501 | CreateLabelHandler.prototype.revert = function(context) {
|
47502 | context.shape.labelTarget = null;
|
47503 |
|
47504 | return originalRevert.call(this, context);
|
47505 | };
|
47506 |
|
47507 |
|
47508 |
|
47509 |
|
47510 | function ensureValidDimensions(label) {
|
47511 |
|
47512 |
|
47513 | [ 'width', 'height' ].forEach(function(prop) {
|
47514 | if (typeof label[prop] === 'undefined') {
|
47515 | label[prop] = 0;
|
47516 | }
|
47517 | });
|
47518 | }
|
47519 |
|
47520 | |
47521 |
|
47522 |
|
47523 | function DeleteConnectionHandler(canvas, modeling) {
|
47524 | this._canvas = canvas;
|
47525 | this._modeling = modeling;
|
47526 | }
|
47527 |
|
47528 | DeleteConnectionHandler.$inject = [
|
47529 | 'canvas',
|
47530 | 'modeling'
|
47531 | ];
|
47532 |
|
47533 |
|
47534 | DeleteConnectionHandler.prototype.execute = function(context) {
|
47535 |
|
47536 | var connection = context.connection,
|
47537 | parent = connection.parent;
|
47538 |
|
47539 | context.parent = parent;
|
47540 |
|
47541 |
|
47542 | context.parentIndex = indexOf$1(parent.children, connection);
|
47543 |
|
47544 | context.source = connection.source;
|
47545 | context.target = connection.target;
|
47546 |
|
47547 | this._canvas.removeConnection(connection);
|
47548 |
|
47549 | connection.source = null;
|
47550 | connection.target = null;
|
47551 |
|
47552 | return connection;
|
47553 | };
|
47554 |
|
47555 | |
47556 |
|
47557 |
|
47558 | DeleteConnectionHandler.prototype.revert = function(context) {
|
47559 |
|
47560 | var connection = context.connection,
|
47561 | parent = context.parent,
|
47562 | parentIndex = context.parentIndex;
|
47563 |
|
47564 | connection.source = context.source;
|
47565 | connection.target = context.target;
|
47566 |
|
47567 |
|
47568 | add$1(parent.children, connection, parentIndex);
|
47569 |
|
47570 | this._canvas.addConnection(connection, parent);
|
47571 |
|
47572 | return connection;
|
47573 | };
|
47574 |
|
47575 | function DeleteElementsHandler(modeling, elementRegistry) {
|
47576 | this._modeling = modeling;
|
47577 | this._elementRegistry = elementRegistry;
|
47578 | }
|
47579 |
|
47580 | DeleteElementsHandler.$inject = [
|
47581 | 'modeling',
|
47582 | 'elementRegistry'
|
47583 | ];
|
47584 |
|
47585 |
|
47586 | DeleteElementsHandler.prototype.postExecute = function(context) {
|
47587 |
|
47588 | var modeling = this._modeling,
|
47589 | elementRegistry = this._elementRegistry,
|
47590 | elements = context.elements;
|
47591 |
|
47592 | forEach(elements, function(element) {
|
47593 |
|
47594 |
|
47595 |
|
47596 | if (!elementRegistry.get(element.id)) {
|
47597 | return;
|
47598 | }
|
47599 |
|
47600 | if (element.waypoints) {
|
47601 | modeling.removeConnection(element);
|
47602 | } else {
|
47603 | modeling.removeShape(element);
|
47604 | }
|
47605 | });
|
47606 | };
|
47607 |
|
47608 | |
47609 |
|
47610 |
|
47611 |
|
47612 | function DeleteShapeHandler(canvas, modeling) {
|
47613 | this._canvas = canvas;
|
47614 | this._modeling = modeling;
|
47615 | }
|
47616 |
|
47617 | DeleteShapeHandler.$inject = [ 'canvas', 'modeling' ];
|
47618 |
|
47619 |
|
47620 | |
47621 |
|
47622 |
|
47623 |
|
47624 | DeleteShapeHandler.prototype.preExecute = function(context) {
|
47625 |
|
47626 | var modeling = this._modeling;
|
47627 |
|
47628 | var shape = context.shape;
|
47629 |
|
47630 |
|
47631 | saveClear(shape.incoming, function(connection) {
|
47632 |
|
47633 |
|
47634 |
|
47635 | modeling.removeConnection(connection, { nested: true });
|
47636 | });
|
47637 |
|
47638 | saveClear(shape.outgoing, function(connection) {
|
47639 | modeling.removeConnection(connection, { nested: true });
|
47640 | });
|
47641 |
|
47642 |
|
47643 | saveClear(shape.children, function(child) {
|
47644 | if (isConnection$6(child)) {
|
47645 | modeling.removeConnection(child, { nested: true });
|
47646 | } else {
|
47647 | modeling.removeShape(child, { nested: true });
|
47648 | }
|
47649 | });
|
47650 | };
|
47651 |
|
47652 | |
47653 |
|
47654 |
|
47655 | DeleteShapeHandler.prototype.execute = function(context) {
|
47656 | var canvas = this._canvas;
|
47657 |
|
47658 | var shape = context.shape,
|
47659 | oldParent = shape.parent;
|
47660 |
|
47661 | context.oldParent = oldParent;
|
47662 |
|
47663 |
|
47664 | context.oldParentIndex = indexOf$1(oldParent.children, shape);
|
47665 |
|
47666 |
|
47667 | canvas.removeShape(shape);
|
47668 |
|
47669 | return shape;
|
47670 | };
|
47671 |
|
47672 |
|
47673 | |
47674 |
|
47675 |
|
47676 | DeleteShapeHandler.prototype.revert = function(context) {
|
47677 |
|
47678 | var canvas = this._canvas;
|
47679 |
|
47680 | var shape = context.shape,
|
47681 | oldParent = context.oldParent,
|
47682 | oldParentIndex = context.oldParentIndex;
|
47683 |
|
47684 |
|
47685 | add$1(oldParent.children, shape, oldParentIndex);
|
47686 |
|
47687 | canvas.addShape(shape, oldParent);
|
47688 |
|
47689 | return shape;
|
47690 | };
|
47691 |
|
47692 | function isConnection$6(element) {
|
47693 | return element.waypoints;
|
47694 | }
|
47695 |
|
47696 | |
47697 |
|
47698 |
|
47699 | function DistributeElements$1(modeling) {
|
47700 | this._modeling = modeling;
|
47701 | }
|
47702 |
|
47703 | DistributeElements$1.$inject = [ 'modeling' ];
|
47704 |
|
47705 | var OFF_AXIS = {
|
47706 | x: 'y',
|
47707 | y: 'x'
|
47708 | };
|
47709 |
|
47710 | DistributeElements$1.prototype.preExecute = function(context) {
|
47711 | var modeling = this._modeling;
|
47712 |
|
47713 | var groups = context.groups,
|
47714 | axis = context.axis,
|
47715 | dimension = context.dimension;
|
47716 |
|
47717 | function updateRange(group, element) {
|
47718 | group.range.min = Math.min(element[axis], group.range.min);
|
47719 | group.range.max = Math.max(element[axis] + element[dimension], group.range.max);
|
47720 | }
|
47721 |
|
47722 | function center(element) {
|
47723 | return element[axis] + element[dimension] / 2;
|
47724 | }
|
47725 |
|
47726 | function lastIdx(arr) {
|
47727 | return arr.length - 1;
|
47728 | }
|
47729 |
|
47730 | function rangeDiff(range) {
|
47731 | return range.max - range.min;
|
47732 | }
|
47733 |
|
47734 | function centerElement(refCenter, element) {
|
47735 | var delta = { y: 0 };
|
47736 |
|
47737 | delta[axis] = refCenter - center(element);
|
47738 |
|
47739 | if (delta[axis]) {
|
47740 |
|
47741 | delta[OFF_AXIS[axis]] = 0;
|
47742 |
|
47743 | modeling.moveElements([ element ], delta, element.parent);
|
47744 | }
|
47745 | }
|
47746 |
|
47747 | var firstGroup = groups[0],
|
47748 | lastGroupIdx = lastIdx(groups),
|
47749 | lastGroup = groups[ lastGroupIdx ];
|
47750 |
|
47751 | var margin,
|
47752 | spaceInBetween,
|
47753 | groupsSize = 0;
|
47754 |
|
47755 | forEach(groups, function(group, idx) {
|
47756 | var sortedElements,
|
47757 | refElem,
|
47758 | refCenter;
|
47759 |
|
47760 | if (group.elements.length < 2) {
|
47761 | if (idx && idx !== groups.length - 1) {
|
47762 | updateRange(group, group.elements[0]);
|
47763 |
|
47764 | groupsSize += rangeDiff(group.range);
|
47765 | }
|
47766 | return;
|
47767 | }
|
47768 |
|
47769 | sortedElements = sortBy(group.elements, axis);
|
47770 |
|
47771 | refElem = sortedElements[0];
|
47772 |
|
47773 | if (idx === lastGroupIdx) {
|
47774 | refElem = sortedElements[lastIdx(sortedElements)];
|
47775 | }
|
47776 |
|
47777 | refCenter = center(refElem);
|
47778 |
|
47779 |
|
47780 | group.range = null;
|
47781 |
|
47782 | forEach(sortedElements, function(element) {
|
47783 |
|
47784 | centerElement(refCenter, element);
|
47785 |
|
47786 | if (group.range === null) {
|
47787 | group.range = {
|
47788 | min: element[axis],
|
47789 | max: element[axis] + element[dimension]
|
47790 | };
|
47791 |
|
47792 | return;
|
47793 | }
|
47794 |
|
47795 |
|
47796 | updateRange(group, element);
|
47797 | });
|
47798 |
|
47799 | if (idx && idx !== groups.length - 1) {
|
47800 | groupsSize += rangeDiff(group.range);
|
47801 | }
|
47802 | });
|
47803 |
|
47804 | spaceInBetween = Math.abs(lastGroup.range.min - firstGroup.range.max);
|
47805 |
|
47806 | margin = Math.round((spaceInBetween - groupsSize) / (groups.length - 1));
|
47807 |
|
47808 | if (margin < groups.length - 1) {
|
47809 | return;
|
47810 | }
|
47811 |
|
47812 | forEach(groups, function(group, groupIdx) {
|
47813 | var delta = {},
|
47814 | prevGroup;
|
47815 |
|
47816 | if (group === firstGroup || group === lastGroup) {
|
47817 | return;
|
47818 | }
|
47819 |
|
47820 | prevGroup = groups[groupIdx - 1];
|
47821 |
|
47822 | group.range.max = 0;
|
47823 |
|
47824 | forEach(group.elements, function(element, idx) {
|
47825 | delta[OFF_AXIS[axis]] = 0;
|
47826 | delta[axis] = (prevGroup.range.max - element[axis]) + margin;
|
47827 |
|
47828 | if (group.range.min !== element[axis]) {
|
47829 | delta[axis] += element[axis] - group.range.min;
|
47830 | }
|
47831 |
|
47832 | if (delta[axis]) {
|
47833 | modeling.moveElements([ element ], delta, element.parent);
|
47834 | }
|
47835 |
|
47836 | group.range.max = Math.max(element[axis] + element[dimension], idx ? group.range.max : 0);
|
47837 | });
|
47838 | });
|
47839 | };
|
47840 |
|
47841 | DistributeElements$1.prototype.postExecute = function(context) {
|
47842 |
|
47843 | };
|
47844 |
|
47845 | |
47846 |
|
47847 |
|
47848 | function LayoutConnectionHandler(layouter, canvas) {
|
47849 | this._layouter = layouter;
|
47850 | this._canvas = canvas;
|
47851 | }
|
47852 |
|
47853 | LayoutConnectionHandler.$inject = [ 'layouter', 'canvas' ];
|
47854 |
|
47855 | LayoutConnectionHandler.prototype.execute = function(context) {
|
47856 |
|
47857 | var connection = context.connection;
|
47858 |
|
47859 | var oldWaypoints = connection.waypoints;
|
47860 |
|
47861 | assign(context, {
|
47862 | oldWaypoints: oldWaypoints
|
47863 | });
|
47864 |
|
47865 | connection.waypoints = this._layouter.layoutConnection(connection, context.hints);
|
47866 |
|
47867 | return connection;
|
47868 | };
|
47869 |
|
47870 | LayoutConnectionHandler.prototype.revert = function(context) {
|
47871 |
|
47872 | var connection = context.connection;
|
47873 |
|
47874 | connection.waypoints = context.oldWaypoints;
|
47875 |
|
47876 | return connection;
|
47877 | };
|
47878 |
|
47879 | |
47880 |
|
47881 |
|
47882 |
|
47883 |
|
47884 |
|
47885 | function MoveConnectionHandler() { }
|
47886 |
|
47887 |
|
47888 | MoveConnectionHandler.prototype.execute = function(context) {
|
47889 |
|
47890 | var connection = context.connection,
|
47891 | delta = context.delta;
|
47892 |
|
47893 | var newParent = context.newParent || connection.parent,
|
47894 | newParentIndex = context.newParentIndex,
|
47895 | oldParent = connection.parent;
|
47896 |
|
47897 |
|
47898 | context.oldParent = oldParent;
|
47899 | context.oldParentIndex = remove$2(oldParent.children, connection);
|
47900 |
|
47901 |
|
47902 | add$1(newParent.children, connection, newParentIndex);
|
47903 |
|
47904 |
|
47905 | connection.parent = newParent;
|
47906 |
|
47907 |
|
47908 | forEach(connection.waypoints, function(p) {
|
47909 | p.x += delta.x;
|
47910 | p.y += delta.y;
|
47911 |
|
47912 | if (p.original) {
|
47913 | p.original.x += delta.x;
|
47914 | p.original.y += delta.y;
|
47915 | }
|
47916 | });
|
47917 |
|
47918 | return connection;
|
47919 | };
|
47920 |
|
47921 | MoveConnectionHandler.prototype.revert = function(context) {
|
47922 |
|
47923 | var connection = context.connection,
|
47924 | newParent = connection.parent,
|
47925 | oldParent = context.oldParent,
|
47926 | oldParentIndex = context.oldParentIndex,
|
47927 | delta = context.delta;
|
47928 |
|
47929 |
|
47930 | remove$2(newParent.children, connection);
|
47931 |
|
47932 |
|
47933 | add$1(oldParent.children, connection, oldParentIndex);
|
47934 |
|
47935 |
|
47936 | connection.parent = oldParent;
|
47937 |
|
47938 |
|
47939 | forEach(connection.waypoints, function(p) {
|
47940 | p.x -= delta.x;
|
47941 | p.y -= delta.y;
|
47942 |
|
47943 | if (p.original) {
|
47944 | p.original.x -= delta.x;
|
47945 | p.original.y -= delta.y;
|
47946 | }
|
47947 | });
|
47948 |
|
47949 | return connection;
|
47950 | };
|
47951 |
|
47952 | function getResizedSourceAnchor(connection, shape, oldBounds) {
|
47953 |
|
47954 | var waypoints = safeGetWaypoints(connection),
|
47955 | oldAnchor = waypoints[0];
|
47956 |
|
47957 | return getNewAttachPoint(oldAnchor.original || oldAnchor, oldBounds, shape);
|
47958 | }
|
47959 |
|
47960 |
|
47961 | function getResizedTargetAnchor(connection, shape, oldBounds) {
|
47962 |
|
47963 | var waypoints = safeGetWaypoints(connection),
|
47964 | oldAnchor = waypoints[waypoints.length - 1];
|
47965 |
|
47966 | return getNewAttachPoint(oldAnchor.original || oldAnchor, oldBounds, shape);
|
47967 | }
|
47968 |
|
47969 |
|
47970 | function getMovedSourceAnchor(connection, source, moveDelta) {
|
47971 | return getResizedSourceAnchor(connection, source, substractPosition(source, moveDelta));
|
47972 | }
|
47973 |
|
47974 |
|
47975 | function getMovedTargetAnchor(connection, target, moveDelta) {
|
47976 | return getResizedTargetAnchor(connection, target, substractPosition(target, moveDelta));
|
47977 | }
|
47978 |
|
47979 |
|
47980 |
|
47981 |
|
47982 | function substractPosition(bounds, delta) {
|
47983 | return {
|
47984 | x: bounds.x - delta.x,
|
47985 | y: bounds.y - delta.y,
|
47986 | width: bounds.width,
|
47987 | height: bounds.height
|
47988 | };
|
47989 | }
|
47990 |
|
47991 |
|
47992 | |
47993 |
|
47994 |
|
47995 |
|
47996 |
|
47997 |
|
47998 |
|
47999 | function safeGetWaypoints(connection) {
|
48000 |
|
48001 | var waypoints = connection.waypoints;
|
48002 |
|
48003 | if (!waypoints.length) {
|
48004 | throw new Error('connection#' + connection.id + ': no waypoints');
|
48005 | }
|
48006 |
|
48007 | return waypoints;
|
48008 | }
|
48009 |
|
48010 | function MoveClosure() {
|
48011 |
|
48012 | this.allShapes = {};
|
48013 | this.allConnections = {};
|
48014 |
|
48015 | this.enclosedElements = {};
|
48016 | this.enclosedConnections = {};
|
48017 |
|
48018 | this.topLevel = {};
|
48019 | }
|
48020 |
|
48021 |
|
48022 | MoveClosure.prototype.add = function(element, isTopLevel) {
|
48023 | return this.addAll([ element ], isTopLevel);
|
48024 | };
|
48025 |
|
48026 |
|
48027 | MoveClosure.prototype.addAll = function(elements, isTopLevel) {
|
48028 |
|
48029 | var newClosure = getClosure(elements, !!isTopLevel, this);
|
48030 |
|
48031 | assign(this, newClosure);
|
48032 |
|
48033 | return this;
|
48034 | };
|
48035 |
|
48036 | |
48037 |
|
48038 |
|
48039 |
|
48040 |
|
48041 |
|
48042 | function MoveHelper(modeling) {
|
48043 | this._modeling = modeling;
|
48044 | }
|
48045 |
|
48046 | |
48047 |
|
48048 |
|
48049 |
|
48050 |
|
48051 |
|
48052 |
|
48053 |
|
48054 |
|
48055 |
|
48056 |
|
48057 |
|
48058 | MoveHelper.prototype.moveRecursive = function(elements, delta, newParent) {
|
48059 | if (!elements) {
|
48060 | return [];
|
48061 | } else {
|
48062 | return this.moveClosure(this.getClosure(elements), delta, newParent);
|
48063 | }
|
48064 | };
|
48065 |
|
48066 | |
48067 |
|
48068 |
|
48069 |
|
48070 |
|
48071 |
|
48072 |
|
48073 |
|
48074 | MoveHelper.prototype.moveClosure = function(closure, delta, newParent, newHost, primaryShape) {
|
48075 | var modeling = this._modeling;
|
48076 |
|
48077 | var allShapes = closure.allShapes,
|
48078 | allConnections = closure.allConnections,
|
48079 | enclosedConnections = closure.enclosedConnections,
|
48080 | topLevel = closure.topLevel,
|
48081 | keepParent = false;
|
48082 |
|
48083 | if (primaryShape && primaryShape.parent === newParent) {
|
48084 | keepParent = true;
|
48085 | }
|
48086 |
|
48087 |
|
48088 | forEach(allShapes, function(shape) {
|
48089 |
|
48090 |
|
48091 | modeling.moveShape(shape, delta, topLevel[shape.id] && !keepParent && newParent, {
|
48092 | recurse: false,
|
48093 | layout: false
|
48094 | });
|
48095 | });
|
48096 |
|
48097 |
|
48098 | forEach(allConnections, function(c) {
|
48099 |
|
48100 | var sourceMoved = !!allShapes[c.source.id],
|
48101 | targetMoved = !!allShapes[c.target.id];
|
48102 |
|
48103 | if (enclosedConnections[c.id] && sourceMoved && targetMoved) {
|
48104 | modeling.moveConnection(c, delta, topLevel[c.id] && !keepParent && newParent);
|
48105 | } else {
|
48106 | modeling.layoutConnection(c, {
|
48107 | connectionStart: sourceMoved && getMovedSourceAnchor(c, c.source, delta),
|
48108 | connectionEnd: targetMoved && getMovedTargetAnchor(c, c.target, delta)
|
48109 | });
|
48110 | }
|
48111 | });
|
48112 | };
|
48113 |
|
48114 | |
48115 |
|
48116 |
|
48117 |
|
48118 |
|
48119 |
|
48120 | MoveHelper.prototype.getClosure = function(elements) {
|
48121 | return new MoveClosure().addAll(elements, true);
|
48122 | };
|
48123 |
|
48124 | |
48125 |
|
48126 |
|
48127 | function MoveElementsHandler(modeling) {
|
48128 | this._helper = new MoveHelper(modeling);
|
48129 | }
|
48130 |
|
48131 | MoveElementsHandler.$inject = [ 'modeling' ];
|
48132 |
|
48133 | MoveElementsHandler.prototype.preExecute = function(context) {
|
48134 | context.closure = this._helper.getClosure(context.shapes);
|
48135 | };
|
48136 |
|
48137 | MoveElementsHandler.prototype.postExecute = function(context) {
|
48138 |
|
48139 | var hints = context.hints,
|
48140 | primaryShape;
|
48141 |
|
48142 | if (hints && hints.primaryShape) {
|
48143 | primaryShape = hints.primaryShape;
|
48144 | hints.oldParent = primaryShape.parent;
|
48145 | }
|
48146 |
|
48147 | this._helper.moveClosure(
|
48148 | context.closure,
|
48149 | context.delta,
|
48150 | context.newParent,
|
48151 | context.newHost,
|
48152 | primaryShape
|
48153 | );
|
48154 | };
|
48155 |
|
48156 | |
48157 |
|
48158 |
|
48159 | function MoveShapeHandler(modeling) {
|
48160 | this._modeling = modeling;
|
48161 |
|
48162 | this._helper = new MoveHelper(modeling);
|
48163 | }
|
48164 |
|
48165 | MoveShapeHandler.$inject = [ 'modeling' ];
|
48166 |
|
48167 |
|
48168 | MoveShapeHandler.prototype.execute = function(context) {
|
48169 |
|
48170 | var shape = context.shape,
|
48171 | delta = context.delta,
|
48172 | newParent = context.newParent || shape.parent,
|
48173 | newParentIndex = context.newParentIndex,
|
48174 | oldParent = shape.parent;
|
48175 |
|
48176 | context.oldBounds = pick(shape, [ 'x', 'y', 'width', 'height']);
|
48177 |
|
48178 |
|
48179 | context.oldParent = oldParent;
|
48180 | context.oldParentIndex = remove$2(oldParent.children, shape);
|
48181 |
|
48182 |
|
48183 | add$1(newParent.children, shape, newParentIndex);
|
48184 |
|
48185 |
|
48186 | assign(shape, {
|
48187 | parent: newParent,
|
48188 | x: shape.x + delta.x,
|
48189 | y: shape.y + delta.y
|
48190 | });
|
48191 |
|
48192 | return shape;
|
48193 | };
|
48194 |
|
48195 | MoveShapeHandler.prototype.postExecute = function(context) {
|
48196 |
|
48197 | var shape = context.shape,
|
48198 | delta = context.delta,
|
48199 | hints = context.hints;
|
48200 |
|
48201 | var modeling = this._modeling;
|
48202 |
|
48203 | if (hints.layout !== false) {
|
48204 |
|
48205 | forEach(shape.incoming, function(c) {
|
48206 | modeling.layoutConnection(c, {
|
48207 | connectionEnd: getMovedTargetAnchor(c, shape, delta)
|
48208 | });
|
48209 | });
|
48210 |
|
48211 | forEach(shape.outgoing, function(c) {
|
48212 | modeling.layoutConnection(c, {
|
48213 | connectionStart: getMovedSourceAnchor(c, shape, delta)
|
48214 | });
|
48215 | });
|
48216 | }
|
48217 |
|
48218 | if (hints.recurse !== false) {
|
48219 | this.moveChildren(context);
|
48220 | }
|
48221 | };
|
48222 |
|
48223 | MoveShapeHandler.prototype.revert = function(context) {
|
48224 |
|
48225 | var shape = context.shape,
|
48226 | oldParent = context.oldParent,
|
48227 | oldParentIndex = context.oldParentIndex,
|
48228 | delta = context.delta;
|
48229 |
|
48230 |
|
48231 | add$1(oldParent.children, shape, oldParentIndex);
|
48232 |
|
48233 |
|
48234 | assign(shape, {
|
48235 | parent: oldParent,
|
48236 | x: shape.x - delta.x,
|
48237 | y: shape.y - delta.y
|
48238 | });
|
48239 |
|
48240 | return shape;
|
48241 | };
|
48242 |
|
48243 | MoveShapeHandler.prototype.moveChildren = function(context) {
|
48244 |
|
48245 | var delta = context.delta,
|
48246 | shape = context.shape;
|
48247 |
|
48248 | this._helper.moveRecursive(shape.children, delta, null);
|
48249 | };
|
48250 |
|
48251 | MoveShapeHandler.prototype.getNewParent = function(context) {
|
48252 | return context.newParent || context.shape.parent;
|
48253 | };
|
48254 |
|
48255 | |
48256 |
|
48257 |
|
48258 | function ReconnectConnectionHandler(modeling) {
|
48259 | this._modeling = modeling;
|
48260 | }
|
48261 |
|
48262 | ReconnectConnectionHandler.$inject = [ 'modeling' ];
|
48263 |
|
48264 | ReconnectConnectionHandler.prototype.execute = function(context) {
|
48265 | var newSource = context.newSource,
|
48266 | newTarget = context.newTarget,
|
48267 | connection = context.connection,
|
48268 | dockingOrPoints = context.dockingOrPoints;
|
48269 |
|
48270 | if (!newSource && !newTarget) {
|
48271 | throw new Error('newSource or newTarget required');
|
48272 | }
|
48273 |
|
48274 | if (isArray(dockingOrPoints)) {
|
48275 | context.oldWaypoints = connection.waypoints;
|
48276 | connection.waypoints = dockingOrPoints;
|
48277 | }
|
48278 |
|
48279 | if (newSource) {
|
48280 | context.oldSource = connection.source;
|
48281 | connection.source = newSource;
|
48282 | }
|
48283 |
|
48284 | if (newTarget) {
|
48285 | context.oldTarget = connection.target;
|
48286 | connection.target = newTarget;
|
48287 | }
|
48288 |
|
48289 | return connection;
|
48290 | };
|
48291 |
|
48292 | ReconnectConnectionHandler.prototype.postExecute = function(context) {
|
48293 | var connection = context.connection,
|
48294 | newSource = context.newSource,
|
48295 | newTarget = context.newTarget,
|
48296 | dockingOrPoints = context.dockingOrPoints,
|
48297 | hints = context.hints || {};
|
48298 |
|
48299 | if (hints.layoutConnection === false) {
|
48300 | return;
|
48301 | }
|
48302 |
|
48303 | var layoutConnectionHints = {};
|
48304 |
|
48305 | if (newSource && (!newTarget || hints.docking === 'source')) {
|
48306 | layoutConnectionHints.connectionStart = getDocking$2(isArray(dockingOrPoints) ? dockingOrPoints[ 0 ] : dockingOrPoints);
|
48307 | }
|
48308 |
|
48309 | if (newTarget && (!newSource || hints.docking === 'target')) {
|
48310 | layoutConnectionHints.connectionEnd = getDocking$2(isArray(dockingOrPoints) ? dockingOrPoints[ dockingOrPoints.length - 1 ] : dockingOrPoints);
|
48311 | }
|
48312 |
|
48313 | if (hints.newWaypoints) {
|
48314 | layoutConnectionHints.waypoints = hints.newWaypoints;
|
48315 | }
|
48316 |
|
48317 | this._modeling.layoutConnection(connection, layoutConnectionHints);
|
48318 | };
|
48319 |
|
48320 | ReconnectConnectionHandler.prototype.revert = function(context) {
|
48321 | var oldSource = context.oldSource,
|
48322 | oldTarget = context.oldTarget,
|
48323 | oldWaypoints = context.oldWaypoints,
|
48324 | connection = context.connection;
|
48325 |
|
48326 | if (oldSource) {
|
48327 | connection.source = oldSource;
|
48328 | }
|
48329 |
|
48330 | if (oldTarget) {
|
48331 | connection.target = oldTarget;
|
48332 | }
|
48333 |
|
48334 | if (oldWaypoints) {
|
48335 | connection.waypoints = oldWaypoints;
|
48336 | }
|
48337 |
|
48338 | return connection;
|
48339 | };
|
48340 |
|
48341 |
|
48342 |
|
48343 |
|
48344 |
|
48345 | function getDocking$2(point) {
|
48346 | return point.original || point;
|
48347 | }
|
48348 |
|
48349 | |
48350 |
|
48351 |
|
48352 |
|
48353 |
|
48354 |
|
48355 |
|
48356 |
|
48357 |
|
48358 |
|
48359 | function ReplaceShapeHandler(modeling, rules) {
|
48360 | this._modeling = modeling;
|
48361 | this._rules = rules;
|
48362 | }
|
48363 |
|
48364 | ReplaceShapeHandler.$inject = [ 'modeling', 'rules' ];
|
48365 |
|
48366 |
|
48367 | |
48368 |
|
48369 |
|
48370 |
|
48371 |
|
48372 |
|
48373 |
|
48374 |
|
48375 |
|
48376 |
|
48377 |
|
48378 | ReplaceShapeHandler.prototype.preExecute = function(context) {
|
48379 | var self = this,
|
48380 | modeling = this._modeling,
|
48381 | rules = this._rules;
|
48382 |
|
48383 | var oldShape = context.oldShape,
|
48384 | newData = context.newData,
|
48385 | hints = context.hints || {},
|
48386 | newShape;
|
48387 |
|
48388 | function canReconnect(source, target, connection) {
|
48389 | return rules.allowed('connection.reconnect', {
|
48390 | connection: connection,
|
48391 | source: source,
|
48392 | target: target
|
48393 | });
|
48394 | }
|
48395 |
|
48396 |
|
48397 | var position = {
|
48398 | x: newData.x,
|
48399 | y: newData.y
|
48400 | };
|
48401 |
|
48402 | newShape = context.newShape =
|
48403 | context.newShape ||
|
48404 | self.createShape(newData, position, oldShape.parent, hints);
|
48405 |
|
48406 |
|
48407 | if (oldShape.host) {
|
48408 | modeling.updateAttachment(newShape, oldShape.host);
|
48409 | }
|
48410 |
|
48411 |
|
48412 | var children;
|
48413 |
|
48414 | if (hints.moveChildren !== false) {
|
48415 | children = oldShape.children.slice();
|
48416 |
|
48417 | modeling.moveElements(children, { x: 0, y: 0 }, newShape, hints);
|
48418 | }
|
48419 |
|
48420 |
|
48421 | var incoming = oldShape.incoming.slice(),
|
48422 | outgoing = oldShape.outgoing.slice();
|
48423 |
|
48424 | forEach(incoming, function(connection) {
|
48425 | var waypoints = connection.waypoints,
|
48426 | docking = waypoints[ waypoints.length - 1 ],
|
48427 | source = connection.source,
|
48428 | allowed = canReconnect(source, newShape, connection);
|
48429 |
|
48430 | if (allowed) {
|
48431 | self.reconnectEnd(connection, newShape, docking, hints);
|
48432 | }
|
48433 | });
|
48434 |
|
48435 | forEach(outgoing, function(connection) {
|
48436 | var waypoints = connection.waypoints,
|
48437 | docking = waypoints[ 0 ],
|
48438 | target = connection.target,
|
48439 | allowed = canReconnect(newShape, target, connection);
|
48440 |
|
48441 | if (allowed) {
|
48442 | self.reconnectStart(connection, newShape, docking, hints);
|
48443 | }
|
48444 | });
|
48445 | };
|
48446 |
|
48447 |
|
48448 | |
48449 |
|
48450 |
|
48451 | ReplaceShapeHandler.prototype.postExecute = function(context) {
|
48452 | var modeling = this._modeling;
|
48453 |
|
48454 | var oldShape = context.oldShape,
|
48455 | newShape = context.newShape,
|
48456 | layoutConnection = context.hints.layoutConnection;
|
48457 |
|
48458 | if (layoutConnection !== false) {
|
48459 | forEach(newShape.incoming, function(connection) {
|
48460 | modeling.layoutConnection(connection, { endChanged: true });
|
48461 | });
|
48462 |
|
48463 | forEach(newShape.outgoing, function(connection) {
|
48464 | modeling.layoutConnection(connection, { startChanged: true });
|
48465 | });
|
48466 | }
|
48467 |
|
48468 |
|
48469 | modeling.removeShape(oldShape);
|
48470 | };
|
48471 |
|
48472 |
|
48473 | ReplaceShapeHandler.prototype.execute = function(context) {};
|
48474 |
|
48475 |
|
48476 | ReplaceShapeHandler.prototype.revert = function(context) {};
|
48477 |
|
48478 |
|
48479 | ReplaceShapeHandler.prototype.createShape = function(shape, position, target, hints) {
|
48480 | return this._modeling.createShape(shape, position, target, hints);
|
48481 | };
|
48482 |
|
48483 |
|
48484 | ReplaceShapeHandler.prototype.reconnectStart = function(connection, newSource, dockingPoint, hints) {
|
48485 | this._modeling.reconnectStart(connection, newSource, dockingPoint, hints);
|
48486 | };
|
48487 |
|
48488 |
|
48489 | ReplaceShapeHandler.prototype.reconnectEnd = function(connection, newTarget, dockingPoint, hints) {
|
48490 | this._modeling.reconnectEnd(connection, newTarget, dockingPoint, hints);
|
48491 | };
|
48492 |
|
48493 | |
48494 |
|
48495 |
|
48496 |
|
48497 |
|
48498 | function ResizeShapeHandler(modeling) {
|
48499 | this._modeling = modeling;
|
48500 | }
|
48501 |
|
48502 | ResizeShapeHandler.$inject = [ 'modeling' ];
|
48503 |
|
48504 | |
48505 |
|
48506 |
|
48507 |
|
48508 |
|
48509 |
|
48510 |
|
48511 |
|
48512 |
|
48513 |
|
48514 |
|
48515 |
|
48516 | ResizeShapeHandler.prototype.execute = function(context) {
|
48517 | var shape = context.shape,
|
48518 | newBounds = context.newBounds,
|
48519 | minBounds = context.minBounds;
|
48520 |
|
48521 | if (newBounds.x === undefined || newBounds.y === undefined ||
|
48522 | newBounds.width === undefined || newBounds.height === undefined) {
|
48523 | throw new Error('newBounds must have {x, y, width, height} properties');
|
48524 | }
|
48525 |
|
48526 | if (minBounds && (newBounds.width < minBounds.width
|
48527 | || newBounds.height < minBounds.height)) {
|
48528 | throw new Error('width and height cannot be less than minimum height and width');
|
48529 | } else if (!minBounds
|
48530 | && newBounds.width < 10 || newBounds.height < 10) {
|
48531 | throw new Error('width and height cannot be less than 10px');
|
48532 | }
|
48533 |
|
48534 |
|
48535 | context.oldBounds = {
|
48536 | width: shape.width,
|
48537 | height: shape.height,
|
48538 | x: shape.x,
|
48539 | y: shape.y
|
48540 | };
|
48541 |
|
48542 |
|
48543 | assign(shape, {
|
48544 | width: newBounds.width,
|
48545 | height: newBounds.height,
|
48546 | x: newBounds.x,
|
48547 | y: newBounds.y
|
48548 | });
|
48549 |
|
48550 | return shape;
|
48551 | };
|
48552 |
|
48553 | ResizeShapeHandler.prototype.postExecute = function(context) {
|
48554 |
|
48555 | var shape = context.shape,
|
48556 | oldBounds = context.oldBounds;
|
48557 |
|
48558 | var modeling = this._modeling;
|
48559 |
|
48560 | forEach(shape.incoming, function(c) {
|
48561 | modeling.layoutConnection(c, {
|
48562 | connectionEnd: getResizedTargetAnchor(c, shape, oldBounds)
|
48563 | });
|
48564 | });
|
48565 |
|
48566 | forEach(shape.outgoing, function(c) {
|
48567 | modeling.layoutConnection(c, {
|
48568 | connectionStart: getResizedSourceAnchor(c, shape, oldBounds)
|
48569 | });
|
48570 | });
|
48571 |
|
48572 | };
|
48573 |
|
48574 | ResizeShapeHandler.prototype.revert = function(context) {
|
48575 |
|
48576 | var shape = context.shape,
|
48577 | oldBounds = context.oldBounds;
|
48578 |
|
48579 |
|
48580 | assign(shape, {
|
48581 | width: oldBounds.width,
|
48582 | height: oldBounds.height,
|
48583 | x: oldBounds.x,
|
48584 | y: oldBounds.y
|
48585 | });
|
48586 |
|
48587 | return shape;
|
48588 | };
|
48589 |
|
48590 | |
48591 |
|
48592 |
|
48593 |
|
48594 |
|
48595 |
|
48596 |
|
48597 |
|
48598 | function SpaceToolHandler(modeling) {
|
48599 | this._modeling = modeling;
|
48600 | }
|
48601 |
|
48602 | SpaceToolHandler.$inject = [ 'modeling' ];
|
48603 |
|
48604 |
|
48605 | SpaceToolHandler.prototype.preExecute = function(context) {
|
48606 |
|
48607 |
|
48608 | var modeling = this._modeling,
|
48609 | resizingShapes = context.resizingShapes,
|
48610 | delta = context.delta,
|
48611 | direction = context.direction;
|
48612 |
|
48613 | forEach(resizingShapes, function(shape) {
|
48614 | var newBounds = resizeBounds$1(shape, direction, delta);
|
48615 |
|
48616 | modeling.resizeShape(shape, newBounds);
|
48617 | });
|
48618 | };
|
48619 |
|
48620 | SpaceToolHandler.prototype.postExecute = function(context) {
|
48621 |
|
48622 |
|
48623 | var modeling = this._modeling,
|
48624 | movingShapes = context.movingShapes,
|
48625 | delta = context.delta;
|
48626 |
|
48627 | modeling.moveElements(movingShapes, delta, undefined, { autoResize: false, attach: false });
|
48628 | };
|
48629 |
|
48630 | SpaceToolHandler.prototype.execute = function(context) {};
|
48631 | SpaceToolHandler.prototype.revert = function(context) {};
|
48632 |
|
48633 | |
48634 |
|
48635 |
|
48636 |
|
48637 |
|
48638 |
|
48639 | function ToggleShapeCollapseHandler(modeling) {
|
48640 | this._modeling = modeling;
|
48641 | }
|
48642 |
|
48643 | ToggleShapeCollapseHandler.$inject = [ 'modeling' ];
|
48644 |
|
48645 |
|
48646 | ToggleShapeCollapseHandler.prototype.execute = function(context) {
|
48647 |
|
48648 | var shape = context.shape,
|
48649 | children = shape.children;
|
48650 |
|
48651 |
|
48652 | context.oldChildrenVisibility = getElementsVisibilityRecursive(children);
|
48653 |
|
48654 |
|
48655 | shape.collapsed = !shape.collapsed;
|
48656 |
|
48657 |
|
48658 | var result = setHiddenRecursive(children, shape.collapsed);
|
48659 |
|
48660 | return [shape].concat(result);
|
48661 | };
|
48662 |
|
48663 |
|
48664 | ToggleShapeCollapseHandler.prototype.revert = function(context) {
|
48665 |
|
48666 | var shape = context.shape,
|
48667 | oldChildrenVisibility = context.oldChildrenVisibility;
|
48668 |
|
48669 | var children = shape.children;
|
48670 |
|
48671 |
|
48672 | var result = restoreVisibilityRecursive(children, oldChildrenVisibility);
|
48673 |
|
48674 |
|
48675 | shape.collapsed = !shape.collapsed;
|
48676 |
|
48677 | return [shape].concat(result);
|
48678 | };
|
48679 |
|
48680 |
|
48681 |
|
48682 |
|
48683 | |
48684 |
|
48685 |
|
48686 |
|
48687 |
|
48688 |
|
48689 |
|
48690 | function getElementsVisibilityRecursive(elements) {
|
48691 |
|
48692 | var result = {};
|
48693 |
|
48694 | forEach(elements, function(element) {
|
48695 | result[element.id] = element.hidden;
|
48696 |
|
48697 | if (element.children) {
|
48698 | result = assign({}, result, getElementsVisibilityRecursive(element.children));
|
48699 | }
|
48700 | });
|
48701 |
|
48702 | return result;
|
48703 | }
|
48704 |
|
48705 |
|
48706 | function setHiddenRecursive(elements, newHidden) {
|
48707 | var result = [];
|
48708 | forEach(elements, function(element) {
|
48709 | element.hidden = newHidden;
|
48710 |
|
48711 | result = result.concat(element);
|
48712 |
|
48713 | if (element.children) {
|
48714 | result = result.concat(setHiddenRecursive(element.children, element.collapsed || newHidden));
|
48715 | }
|
48716 | });
|
48717 |
|
48718 | return result;
|
48719 | }
|
48720 |
|
48721 | function restoreVisibilityRecursive(elements, lastState) {
|
48722 | var result = [];
|
48723 | forEach(elements, function(element) {
|
48724 | element.hidden = lastState[element.id];
|
48725 |
|
48726 | result = result.concat(element);
|
48727 |
|
48728 | if (element.children) {
|
48729 | result = result.concat(restoreVisibilityRecursive(element.children, lastState));
|
48730 | }
|
48731 | });
|
48732 |
|
48733 | return result;
|
48734 | }
|
48735 |
|
48736 | |
48737 |
|
48738 |
|
48739 | function UpdateAttachmentHandler(modeling) {
|
48740 | this._modeling = modeling;
|
48741 | }
|
48742 |
|
48743 | UpdateAttachmentHandler.$inject = [ 'modeling' ];
|
48744 |
|
48745 |
|
48746 | UpdateAttachmentHandler.prototype.execute = function(context) {
|
48747 | var shape = context.shape,
|
48748 | newHost = context.newHost,
|
48749 | oldHost = shape.host;
|
48750 |
|
48751 |
|
48752 | context.oldHost = oldHost;
|
48753 | context.attacherIdx = removeAttacher(oldHost, shape);
|
48754 |
|
48755 |
|
48756 | addAttacher(newHost, shape);
|
48757 |
|
48758 |
|
48759 | shape.host = newHost;
|
48760 |
|
48761 | return shape;
|
48762 | };
|
48763 |
|
48764 | UpdateAttachmentHandler.prototype.revert = function(context) {
|
48765 | var shape = context.shape,
|
48766 | newHost = context.newHost,
|
48767 | oldHost = context.oldHost,
|
48768 | attacherIdx = context.attacherIdx;
|
48769 |
|
48770 |
|
48771 | shape.host = oldHost;
|
48772 |
|
48773 |
|
48774 | removeAttacher(newHost, shape);
|
48775 |
|
48776 |
|
48777 | addAttacher(oldHost, shape, attacherIdx);
|
48778 |
|
48779 | return shape;
|
48780 | };
|
48781 |
|
48782 |
|
48783 | function removeAttacher(host, attacher) {
|
48784 |
|
48785 |
|
48786 | return remove$2(host && host.attachers, attacher);
|
48787 | }
|
48788 |
|
48789 | function addAttacher(host, attacher, idx) {
|
48790 |
|
48791 | if (!host) {
|
48792 | return;
|
48793 | }
|
48794 |
|
48795 | var attachers = host.attachers;
|
48796 |
|
48797 | if (!attachers) {
|
48798 | host.attachers = attachers = [];
|
48799 | }
|
48800 |
|
48801 | add$1(attachers, attacher, idx);
|
48802 | }
|
48803 |
|
48804 | function UpdateWaypointsHandler() { }
|
48805 |
|
48806 | UpdateWaypointsHandler.prototype.execute = function(context) {
|
48807 |
|
48808 | var connection = context.connection,
|
48809 | newWaypoints = context.newWaypoints;
|
48810 |
|
48811 | context.oldWaypoints = connection.waypoints;
|
48812 |
|
48813 | connection.waypoints = newWaypoints;
|
48814 |
|
48815 | return connection;
|
48816 | };
|
48817 |
|
48818 | UpdateWaypointsHandler.prototype.revert = function(context) {
|
48819 |
|
48820 | var connection = context.connection,
|
48821 | oldWaypoints = context.oldWaypoints;
|
48822 |
|
48823 | connection.waypoints = oldWaypoints;
|
48824 |
|
48825 | return connection;
|
48826 | };
|
48827 |
|
48828 | |
48829 |
|
48830 |
|
48831 |
|
48832 |
|
48833 |
|
48834 |
|
48835 | function Modeling(eventBus, elementFactory, commandStack) {
|
48836 | this._eventBus = eventBus;
|
48837 | this._elementFactory = elementFactory;
|
48838 | this._commandStack = commandStack;
|
48839 |
|
48840 | var self = this;
|
48841 |
|
48842 | eventBus.on('diagram.init', function() {
|
48843 |
|
48844 |
|
48845 | self.registerHandlers(commandStack);
|
48846 | });
|
48847 | }
|
48848 |
|
48849 | Modeling.$inject = [ 'eventBus', 'elementFactory', 'commandStack' ];
|
48850 |
|
48851 |
|
48852 | Modeling.prototype.getHandlers = function() {
|
48853 | return {
|
48854 | 'shape.append': AppendShapeHandler,
|
48855 | 'shape.create': CreateShapeHandler,
|
48856 | 'shape.delete': DeleteShapeHandler,
|
48857 | 'shape.move': MoveShapeHandler,
|
48858 | 'shape.resize': ResizeShapeHandler,
|
48859 | 'shape.replace': ReplaceShapeHandler,
|
48860 | 'shape.toggleCollapse': ToggleShapeCollapseHandler,
|
48861 |
|
48862 | 'spaceTool': SpaceToolHandler,
|
48863 |
|
48864 | 'label.create': CreateLabelHandler,
|
48865 |
|
48866 | 'connection.create': CreateConnectionHandler,
|
48867 | 'connection.delete': DeleteConnectionHandler,
|
48868 | 'connection.move': MoveConnectionHandler,
|
48869 | 'connection.layout': LayoutConnectionHandler,
|
48870 |
|
48871 | 'connection.updateWaypoints': UpdateWaypointsHandler,
|
48872 |
|
48873 | 'connection.reconnect': ReconnectConnectionHandler,
|
48874 |
|
48875 | 'elements.create': CreateElementsHandler,
|
48876 | 'elements.move': MoveElementsHandler,
|
48877 | 'elements.delete': DeleteElementsHandler,
|
48878 |
|
48879 | 'elements.distribute': DistributeElements$1,
|
48880 | 'elements.align': AlignElements$1,
|
48881 |
|
48882 | 'element.updateAttachment': UpdateAttachmentHandler
|
48883 | };
|
48884 | };
|
48885 |
|
48886 | |
48887 |
|
48888 |
|
48889 |
|
48890 |
|
48891 | Modeling.prototype.registerHandlers = function(commandStack) {
|
48892 | forEach(this.getHandlers(), function(handler, id) {
|
48893 | commandStack.registerHandler(id, handler);
|
48894 | });
|
48895 | };
|
48896 |
|
48897 |
|
48898 |
|
48899 |
|
48900 | Modeling.prototype.moveShape = function(shape, delta, newParent, newParentIndex, hints) {
|
48901 |
|
48902 | if (typeof newParentIndex === 'object') {
|
48903 | hints = newParentIndex;
|
48904 | newParentIndex = null;
|
48905 | }
|
48906 |
|
48907 | var context = {
|
48908 | shape: shape,
|
48909 | delta: delta,
|
48910 | newParent: newParent,
|
48911 | newParentIndex: newParentIndex,
|
48912 | hints: hints || {}
|
48913 | };
|
48914 |
|
48915 | this._commandStack.execute('shape.move', context);
|
48916 | };
|
48917 |
|
48918 |
|
48919 | |
48920 |
|
48921 |
|
48922 |
|
48923 |
|
48924 |
|
48925 | Modeling.prototype.updateAttachment = function(shape, newHost) {
|
48926 | var context = {
|
48927 | shape: shape,
|
48928 | newHost: newHost
|
48929 | };
|
48930 |
|
48931 | this._commandStack.execute('element.updateAttachment', context);
|
48932 | };
|
48933 |
|
48934 |
|
48935 | |
48936 |
|
48937 |
|
48938 |
|
48939 |
|
48940 |
|
48941 |
|
48942 |
|
48943 |
|
48944 |
|
48945 | Modeling.prototype.moveElements = function(shapes, delta, target, hints) {
|
48946 |
|
48947 | hints = hints || {};
|
48948 |
|
48949 | var attach = hints.attach;
|
48950 |
|
48951 | var newParent = target,
|
48952 | newHost;
|
48953 |
|
48954 | if (attach === true) {
|
48955 | newHost = target;
|
48956 | newParent = target.parent;
|
48957 | } else
|
48958 |
|
48959 | if (attach === false) {
|
48960 | newHost = null;
|
48961 | }
|
48962 |
|
48963 | var context = {
|
48964 | shapes: shapes,
|
48965 | delta: delta,
|
48966 | newParent: newParent,
|
48967 | newHost: newHost,
|
48968 | hints: hints
|
48969 | };
|
48970 |
|
48971 | this._commandStack.execute('elements.move', context);
|
48972 | };
|
48973 |
|
48974 |
|
48975 | Modeling.prototype.moveConnection = function(connection, delta, newParent, newParentIndex, hints) {
|
48976 |
|
48977 | if (typeof newParentIndex === 'object') {
|
48978 | hints = newParentIndex;
|
48979 | newParentIndex = undefined;
|
48980 | }
|
48981 |
|
48982 | var context = {
|
48983 | connection: connection,
|
48984 | delta: delta,
|
48985 | newParent: newParent,
|
48986 | newParentIndex: newParentIndex,
|
48987 | hints: hints || {}
|
48988 | };
|
48989 |
|
48990 | this._commandStack.execute('connection.move', context);
|
48991 | };
|
48992 |
|
48993 |
|
48994 | Modeling.prototype.layoutConnection = function(connection, hints) {
|
48995 | var context = {
|
48996 | connection: connection,
|
48997 | hints: hints || {}
|
48998 | };
|
48999 |
|
49000 | this._commandStack.execute('connection.layout', context);
|
49001 | };
|
49002 |
|
49003 |
|
49004 | |
49005 |
|
49006 |
|
49007 |
|
49008 |
|
49009 |
|
49010 |
|
49011 |
|
49012 |
|
49013 |
|
49014 |
|
49015 |
|
49016 | Modeling.prototype.createConnection = function(source, target, parentIndex, connection, parent, hints) {
|
49017 |
|
49018 | if (typeof parentIndex === 'object') {
|
49019 | hints = parent;
|
49020 | parent = connection;
|
49021 | connection = parentIndex;
|
49022 | parentIndex = undefined;
|
49023 | }
|
49024 |
|
49025 | connection = this._create('connection', connection);
|
49026 |
|
49027 | var context = {
|
49028 | source: source,
|
49029 | target: target,
|
49030 | parent: parent,
|
49031 | parentIndex: parentIndex,
|
49032 | connection: connection,
|
49033 | hints: hints
|
49034 | };
|
49035 |
|
49036 | this._commandStack.execute('connection.create', context);
|
49037 |
|
49038 | return context.connection;
|
49039 | };
|
49040 |
|
49041 |
|
49042 | |
49043 |
|
49044 |
|
49045 |
|
49046 |
|
49047 |
|
49048 |
|
49049 |
|
49050 |
|
49051 |
|
49052 |
|
49053 |
|
49054 | Modeling.prototype.createShape = function(shape, position, target, parentIndex, hints) {
|
49055 |
|
49056 | if (typeof parentIndex !== 'number') {
|
49057 | hints = parentIndex;
|
49058 | parentIndex = undefined;
|
49059 | }
|
49060 |
|
49061 | hints = hints || {};
|
49062 |
|
49063 | var attach = hints.attach,
|
49064 | parent,
|
49065 | host;
|
49066 |
|
49067 | shape = this._create('shape', shape);
|
49068 |
|
49069 | if (attach) {
|
49070 | parent = target.parent;
|
49071 | host = target;
|
49072 | } else {
|
49073 | parent = target;
|
49074 | }
|
49075 |
|
49076 | var context = {
|
49077 | position: position,
|
49078 | shape: shape,
|
49079 | parent: parent,
|
49080 | parentIndex: parentIndex,
|
49081 | host: host,
|
49082 | hints: hints
|
49083 | };
|
49084 |
|
49085 | this._commandStack.execute('shape.create', context);
|
49086 |
|
49087 | return context.shape;
|
49088 | };
|
49089 |
|
49090 |
|
49091 | Modeling.prototype.createElements = function(elements, position, parent, parentIndex, hints) {
|
49092 | if (!isArray(elements)) {
|
49093 | elements = [ elements ];
|
49094 | }
|
49095 |
|
49096 | if (typeof parentIndex !== 'number') {
|
49097 | hints = parentIndex;
|
49098 | parentIndex = undefined;
|
49099 | }
|
49100 |
|
49101 | hints = hints || {};
|
49102 |
|
49103 | var context = {
|
49104 | position: position,
|
49105 | elements: elements,
|
49106 | parent: parent,
|
49107 | parentIndex: parentIndex,
|
49108 | hints: hints
|
49109 | };
|
49110 |
|
49111 | this._commandStack.execute('elements.create', context);
|
49112 |
|
49113 | return context.elements;
|
49114 | };
|
49115 |
|
49116 |
|
49117 | Modeling.prototype.createLabel = function(labelTarget, position, label, parent) {
|
49118 |
|
49119 | label = this._create('label', label);
|
49120 |
|
49121 | var context = {
|
49122 | labelTarget: labelTarget,
|
49123 | position: position,
|
49124 | parent: parent || labelTarget.parent,
|
49125 | shape: label
|
49126 | };
|
49127 |
|
49128 | this._commandStack.execute('label.create', context);
|
49129 |
|
49130 | return context.shape;
|
49131 | };
|
49132 |
|
49133 |
|
49134 | |
49135 |
|
49136 |
|
49137 |
|
49138 |
|
49139 |
|
49140 |
|
49141 |
|
49142 |
|
49143 |
|
49144 |
|
49145 |
|
49146 |
|
49147 |
|
49148 |
|
49149 | Modeling.prototype.appendShape = function(source, shape, position, target, hints) {
|
49150 |
|
49151 | hints = hints || {};
|
49152 |
|
49153 | shape = this._create('shape', shape);
|
49154 |
|
49155 | var context = {
|
49156 | source: source,
|
49157 | position: position,
|
49158 | target: target,
|
49159 | shape: shape,
|
49160 | connection: hints.connection,
|
49161 | connectionParent: hints.connectionParent,
|
49162 | attach: hints.attach
|
49163 | };
|
49164 |
|
49165 | this._commandStack.execute('shape.append', context);
|
49166 |
|
49167 | return context.shape;
|
49168 | };
|
49169 |
|
49170 |
|
49171 | Modeling.prototype.removeElements = function(elements) {
|
49172 | var context = {
|
49173 | elements: elements
|
49174 | };
|
49175 |
|
49176 | this._commandStack.execute('elements.delete', context);
|
49177 | };
|
49178 |
|
49179 |
|
49180 | Modeling.prototype.distributeElements = function(groups, axis, dimension) {
|
49181 | var context = {
|
49182 | groups: groups,
|
49183 | axis: axis,
|
49184 | dimension: dimension
|
49185 | };
|
49186 |
|
49187 | this._commandStack.execute('elements.distribute', context);
|
49188 | };
|
49189 |
|
49190 |
|
49191 | Modeling.prototype.removeShape = function(shape, hints) {
|
49192 | var context = {
|
49193 | shape: shape,
|
49194 | hints: hints || {}
|
49195 | };
|
49196 |
|
49197 | this._commandStack.execute('shape.delete', context);
|
49198 | };
|
49199 |
|
49200 |
|
49201 | Modeling.prototype.removeConnection = function(connection, hints) {
|
49202 | var context = {
|
49203 | connection: connection,
|
49204 | hints: hints || {}
|
49205 | };
|
49206 |
|
49207 | this._commandStack.execute('connection.delete', context);
|
49208 | };
|
49209 |
|
49210 | Modeling.prototype.replaceShape = function(oldShape, newShape, hints) {
|
49211 | var context = {
|
49212 | oldShape: oldShape,
|
49213 | newData: newShape,
|
49214 | hints: hints || {}
|
49215 | };
|
49216 |
|
49217 | this._commandStack.execute('shape.replace', context);
|
49218 |
|
49219 | return context.newShape;
|
49220 | };
|
49221 |
|
49222 | Modeling.prototype.alignElements = function(elements, alignment) {
|
49223 | var context = {
|
49224 | elements: elements,
|
49225 | alignment: alignment
|
49226 | };
|
49227 |
|
49228 | this._commandStack.execute('elements.align', context);
|
49229 | };
|
49230 |
|
49231 | Modeling.prototype.resizeShape = function(shape, newBounds, minBounds, hints) {
|
49232 | var context = {
|
49233 | shape: shape,
|
49234 | newBounds: newBounds,
|
49235 | minBounds: minBounds,
|
49236 | hints: hints
|
49237 | };
|
49238 |
|
49239 | this._commandStack.execute('shape.resize', context);
|
49240 | };
|
49241 |
|
49242 | Modeling.prototype.createSpace = function(movingShapes, resizingShapes, delta, direction) {
|
49243 | var context = {
|
49244 | movingShapes: movingShapes,
|
49245 | resizingShapes: resizingShapes,
|
49246 | delta: delta,
|
49247 | direction: direction
|
49248 | };
|
49249 |
|
49250 | this._commandStack.execute('spaceTool', context);
|
49251 | };
|
49252 |
|
49253 | Modeling.prototype.updateWaypoints = function(connection, newWaypoints, hints) {
|
49254 | var context = {
|
49255 | connection: connection,
|
49256 | newWaypoints: newWaypoints,
|
49257 | hints: hints || {}
|
49258 | };
|
49259 |
|
49260 | this._commandStack.execute('connection.updateWaypoints', context);
|
49261 | };
|
49262 |
|
49263 | Modeling.prototype.reconnect = function(connection, source, target, dockingOrPoints, hints) {
|
49264 | var context = {
|
49265 | connection: connection,
|
49266 | newSource: source,
|
49267 | newTarget: target,
|
49268 | dockingOrPoints: dockingOrPoints,
|
49269 | hints: hints || {}
|
49270 | };
|
49271 |
|
49272 | this._commandStack.execute('connection.reconnect', context);
|
49273 | };
|
49274 |
|
49275 | Modeling.prototype.reconnectStart = function(connection, newSource, dockingOrPoints, hints) {
|
49276 | if (!hints) {
|
49277 | hints = {};
|
49278 | }
|
49279 |
|
49280 | this.reconnect(connection, newSource, connection.target, dockingOrPoints, assign(hints, {
|
49281 | docking: 'source'
|
49282 | }));
|
49283 | };
|
49284 |
|
49285 | Modeling.prototype.reconnectEnd = function(connection, newTarget, dockingOrPoints, hints) {
|
49286 | if (!hints) {
|
49287 | hints = {};
|
49288 | }
|
49289 |
|
49290 | this.reconnect(connection, connection.source, newTarget, dockingOrPoints, assign(hints, {
|
49291 | docking: 'target'
|
49292 | }));
|
49293 | };
|
49294 |
|
49295 | Modeling.prototype.connect = function(source, target, attrs, hints) {
|
49296 | return this.createConnection(source, target, attrs || {}, source.parent, hints);
|
49297 | };
|
49298 |
|
49299 | Modeling.prototype._create = function(type, attrs) {
|
49300 | if (attrs instanceof Base) {
|
49301 | return attrs;
|
49302 | } else {
|
49303 | return this._elementFactory.create(type, attrs);
|
49304 | }
|
49305 | };
|
49306 |
|
49307 | Modeling.prototype.toggleCollapse = function(shape, hints) {
|
49308 | var context = {
|
49309 | shape: shape,
|
49310 | hints: hints || {}
|
49311 | };
|
49312 |
|
49313 | this._commandStack.execute('shape.toggleCollapse', context);
|
49314 | };
|
49315 |
|
49316 | var DEFAULT_FLOW = 'default',
|
49317 | ID = 'id',
|
49318 | DI = 'di';
|
49319 |
|
49320 | var NULL_DIMENSIONS = {
|
49321 | width: 0,
|
49322 | height: 0
|
49323 | };
|
49324 |
|
49325 | |
49326 |
|
49327 |
|
49328 |
|
49329 |
|
49330 |
|
49331 |
|
49332 |
|
49333 |
|
49334 | function UpdatePropertiesHandler(
|
49335 | elementRegistry, moddle, translate,
|
49336 | modeling, textRenderer) {
|
49337 |
|
49338 | this._elementRegistry = elementRegistry;
|
49339 | this._moddle = moddle;
|
49340 | this._translate = translate;
|
49341 | this._modeling = modeling;
|
49342 | this._textRenderer = textRenderer;
|
49343 | }
|
49344 |
|
49345 | UpdatePropertiesHandler.$inject = [
|
49346 | 'elementRegistry',
|
49347 | 'moddle',
|
49348 | 'translate',
|
49349 | 'modeling',
|
49350 | 'textRenderer'
|
49351 | ];
|
49352 |
|
49353 |
|
49354 |
|
49355 |
|
49356 | |
49357 |
|
49358 |
|
49359 |
|
49360 |
|
49361 |
|
49362 |
|
49363 |
|
49364 |
|
49365 |
|
49366 | UpdatePropertiesHandler.prototype.execute = function(context) {
|
49367 |
|
49368 | var element = context.element,
|
49369 | changed = [ element ],
|
49370 | translate = this._translate;
|
49371 |
|
49372 | if (!element) {
|
49373 | throw new Error(translate('element required'));
|
49374 | }
|
49375 |
|
49376 | var elementRegistry = this._elementRegistry,
|
49377 | ids = this._moddle.ids;
|
49378 |
|
49379 | var businessObject = element.businessObject,
|
49380 | properties = unwrapBusinessObjects(context.properties),
|
49381 | oldProperties = context.oldProperties || getProperties(businessObject, properties);
|
49382 |
|
49383 | if (isIdChange(properties, businessObject)) {
|
49384 | ids.unclaim(businessObject[ID]);
|
49385 |
|
49386 | elementRegistry.updateId(element, properties[ID]);
|
49387 |
|
49388 | ids.claim(properties[ID], businessObject);
|
49389 | }
|
49390 |
|
49391 |
|
49392 | if (DEFAULT_FLOW in properties) {
|
49393 |
|
49394 | if (properties[DEFAULT_FLOW]) {
|
49395 | changed.push(elementRegistry.get(properties[DEFAULT_FLOW].id));
|
49396 | }
|
49397 |
|
49398 | if (businessObject[DEFAULT_FLOW]) {
|
49399 | changed.push(elementRegistry.get(businessObject[DEFAULT_FLOW].id));
|
49400 | }
|
49401 | }
|
49402 |
|
49403 |
|
49404 | setProperties(businessObject, properties);
|
49405 |
|
49406 |
|
49407 | context.oldProperties = oldProperties;
|
49408 | context.changed = changed;
|
49409 |
|
49410 |
|
49411 | return changed;
|
49412 | };
|
49413 |
|
49414 |
|
49415 | UpdatePropertiesHandler.prototype.postExecute = function(context) {
|
49416 | var element = context.element,
|
49417 | label = element.label;
|
49418 |
|
49419 | var text = label && getBusinessObject(label).name;
|
49420 |
|
49421 | if (!text) {
|
49422 | return;
|
49423 | }
|
49424 |
|
49425 |
|
49426 |
|
49427 | var newLabelBounds = this._textRenderer.getExternalLabelBounds(label, text);
|
49428 |
|
49429 | this._modeling.resizeShape(label, newLabelBounds, NULL_DIMENSIONS);
|
49430 | };
|
49431 |
|
49432 | |
49433 |
|
49434 |
|
49435 |
|
49436 |
|
49437 |
|
49438 |
|
49439 | UpdatePropertiesHandler.prototype.revert = function(context) {
|
49440 |
|
49441 | var element = context.element,
|
49442 | properties = context.properties,
|
49443 | oldProperties = context.oldProperties,
|
49444 | businessObject = element.businessObject,
|
49445 | elementRegistry = this._elementRegistry,
|
49446 | ids = this._moddle.ids;
|
49447 |
|
49448 |
|
49449 | setProperties(businessObject, oldProperties);
|
49450 |
|
49451 | if (isIdChange(properties, businessObject)) {
|
49452 | ids.unclaim(properties[ID]);
|
49453 |
|
49454 | elementRegistry.updateId(element, oldProperties[ID]);
|
49455 |
|
49456 | ids.claim(oldProperties[ID], businessObject);
|
49457 | }
|
49458 |
|
49459 | return context.changed;
|
49460 | };
|
49461 |
|
49462 |
|
49463 | function isIdChange(properties, businessObject) {
|
49464 | return ID in properties && properties[ID] !== businessObject[ID];
|
49465 | }
|
49466 |
|
49467 |
|
49468 | function getProperties(businessObject, properties) {
|
49469 | var propertyNames = keys(properties);
|
49470 |
|
49471 | return reduce(propertyNames, function(result, key) {
|
49472 |
|
49473 |
|
49474 | if (key !== DI) {
|
49475 | result[key] = businessObject.get(key);
|
49476 | } else {
|
49477 | result[key] = getDiProperties(businessObject.di, keys(properties.di));
|
49478 | }
|
49479 |
|
49480 | return result;
|
49481 | }, {});
|
49482 | }
|
49483 |
|
49484 |
|
49485 | function getDiProperties(di, propertyNames) {
|
49486 | return reduce(propertyNames, function(result, key) {
|
49487 | result[key] = di.get(key);
|
49488 |
|
49489 | return result;
|
49490 | }, {});
|
49491 | }
|
49492 |
|
49493 |
|
49494 | function setProperties(businessObject, properties) {
|
49495 | forEach(properties, function(value, key) {
|
49496 |
|
49497 | if (key !== DI) {
|
49498 | businessObject.set(key, value);
|
49499 | } else {
|
49500 |
|
49501 |
|
49502 | if (businessObject.di) {
|
49503 | setDiProperties(businessObject.di, value);
|
49504 | }
|
49505 | }
|
49506 | });
|
49507 | }
|
49508 |
|
49509 |
|
49510 | function setDiProperties(di, properties) {
|
49511 | forEach(properties, function(value, key) {
|
49512 | di.set(key, value);
|
49513 | });
|
49514 | }
|
49515 |
|
49516 |
|
49517 | var referencePropertyNames = [ 'default' ];
|
49518 |
|
49519 | |
49520 |
|
49521 |
|
49522 |
|
49523 |
|
49524 |
|
49525 |
|
49526 |
|
49527 |
|
49528 | function unwrapBusinessObjects(properties) {
|
49529 |
|
49530 | var unwrappedProps = assign({}, properties);
|
49531 |
|
49532 | referencePropertyNames.forEach(function(name) {
|
49533 | if (name in properties) {
|
49534 | unwrappedProps[name] = getBusinessObject(unwrappedProps[name]);
|
49535 | }
|
49536 | });
|
49537 |
|
49538 | return unwrappedProps;
|
49539 | }
|
49540 |
|
49541 | function UpdateCanvasRootHandler(canvas, modeling) {
|
49542 | this._canvas = canvas;
|
49543 | this._modeling = modeling;
|
49544 | }
|
49545 |
|
49546 | UpdateCanvasRootHandler.$inject = [
|
49547 | 'canvas',
|
49548 | 'modeling'
|
49549 | ];
|
49550 |
|
49551 |
|
49552 | UpdateCanvasRootHandler.prototype.execute = function(context) {
|
49553 |
|
49554 | var canvas = this._canvas;
|
49555 |
|
49556 | var newRoot = context.newRoot,
|
49557 | newRootBusinessObject = newRoot.businessObject,
|
49558 | oldRoot = canvas.getRootElement(),
|
49559 | oldRootBusinessObject = oldRoot.businessObject,
|
49560 | bpmnDefinitions = oldRootBusinessObject.$parent,
|
49561 | diPlane = oldRootBusinessObject.di;
|
49562 |
|
49563 |
|
49564 | canvas.setRootElement(newRoot, true);
|
49565 |
|
49566 |
|
49567 | add$1(bpmnDefinitions.rootElements, newRootBusinessObject);
|
49568 | newRootBusinessObject.$parent = bpmnDefinitions;
|
49569 |
|
49570 | remove$2(bpmnDefinitions.rootElements, oldRootBusinessObject);
|
49571 | oldRootBusinessObject.$parent = null;
|
49572 |
|
49573 |
|
49574 | oldRootBusinessObject.di = null;
|
49575 |
|
49576 | diPlane.bpmnElement = newRootBusinessObject;
|
49577 | newRootBusinessObject.di = diPlane;
|
49578 |
|
49579 | context.oldRoot = oldRoot;
|
49580 |
|
49581 |
|
49582 |
|
49583 | };
|
49584 |
|
49585 |
|
49586 | UpdateCanvasRootHandler.prototype.revert = function(context) {
|
49587 |
|
49588 | var canvas = this._canvas;
|
49589 |
|
49590 | var newRoot = context.newRoot,
|
49591 | newRootBusinessObject = newRoot.businessObject,
|
49592 | oldRoot = context.oldRoot,
|
49593 | oldRootBusinessObject = oldRoot.businessObject,
|
49594 | bpmnDefinitions = newRootBusinessObject.$parent,
|
49595 | diPlane = newRootBusinessObject.di;
|
49596 |
|
49597 |
|
49598 | canvas.setRootElement(oldRoot, true);
|
49599 |
|
49600 |
|
49601 | remove$2(bpmnDefinitions.rootElements, newRootBusinessObject);
|
49602 | newRootBusinessObject.$parent = null;
|
49603 |
|
49604 | add$1(bpmnDefinitions.rootElements, oldRootBusinessObject);
|
49605 | oldRootBusinessObject.$parent = bpmnDefinitions;
|
49606 |
|
49607 |
|
49608 | newRootBusinessObject.di = null;
|
49609 |
|
49610 | diPlane.bpmnElement = oldRootBusinessObject;
|
49611 | oldRootBusinessObject.di = diPlane;
|
49612 |
|
49613 |
|
49614 |
|
49615 | };
|
49616 |
|
49617 | |
49618 |
|
49619 |
|
49620 |
|
49621 |
|
49622 |
|
49623 | function AddLaneHandler(modeling, spaceTool) {
|
49624 | this._modeling = modeling;
|
49625 | this._spaceTool = spaceTool;
|
49626 | }
|
49627 |
|
49628 | AddLaneHandler.$inject = [
|
49629 | 'modeling',
|
49630 | 'spaceTool'
|
49631 | ];
|
49632 |
|
49633 |
|
49634 | AddLaneHandler.prototype.preExecute = function(context) {
|
49635 |
|
49636 | var spaceTool = this._spaceTool,
|
49637 | modeling = this._modeling;
|
49638 |
|
49639 | var shape = context.shape,
|
49640 | location = context.location;
|
49641 |
|
49642 | var lanesRoot = getLanesRoot(shape);
|
49643 |
|
49644 | var isRoot = lanesRoot === shape,
|
49645 | laneParent = isRoot ? shape : shape.parent;
|
49646 |
|
49647 | var existingChildLanes = getChildLanes(laneParent);
|
49648 |
|
49649 |
|
49650 | if (!existingChildLanes.length) {
|
49651 | modeling.createShape({ type: 'bpmn:Lane' }, {
|
49652 | x: shape.x + LANE_INDENTATION,
|
49653 | y: shape.y,
|
49654 | width: shape.width - LANE_INDENTATION,
|
49655 | height: shape.height
|
49656 | }, laneParent);
|
49657 | }
|
49658 |
|
49659 |
|
49660 | var allAffected = [];
|
49661 |
|
49662 | eachElement(lanesRoot, function(element) {
|
49663 | allAffected.push(element);
|
49664 |
|
49665 | if (element === shape) {
|
49666 | return [];
|
49667 | }
|
49668 |
|
49669 | return filter(element.children, function(c) {
|
49670 | return c !== shape;
|
49671 | });
|
49672 | });
|
49673 |
|
49674 | var offset = location === 'top' ? -120 : 120,
|
49675 | lanePosition = location === 'top' ? shape.y : shape.y + shape.height,
|
49676 | spacePos = lanePosition + (location === 'top' ? 10 : -10),
|
49677 | direction = location === 'top' ? 'n' : 's';
|
49678 |
|
49679 | var adjustments = spaceTool.calculateAdjustments(allAffected, 'y', offset, spacePos);
|
49680 |
|
49681 | spaceTool.makeSpace(adjustments.movingShapes, adjustments.resizingShapes, { x: 0, y: offset }, direction);
|
49682 |
|
49683 |
|
49684 | context.newLane = modeling.createShape({ type: 'bpmn:Lane' }, {
|
49685 | x: shape.x + (isRoot ? LANE_INDENTATION : 0),
|
49686 | y: lanePosition - (location === 'top' ? 120 : 0),
|
49687 | width: shape.width - (isRoot ? LANE_INDENTATION : 0),
|
49688 | height: 120
|
49689 | }, laneParent);
|
49690 | };
|
49691 |
|
49692 | |
49693 |
|
49694 |
|
49695 |
|
49696 |
|
49697 |
|
49698 | function SplitLaneHandler(modeling, translate) {
|
49699 | this._modeling = modeling;
|
49700 | this._translate = translate;
|
49701 | }
|
49702 |
|
49703 | SplitLaneHandler.$inject = [
|
49704 | 'modeling',
|
49705 | 'translate'
|
49706 | ];
|
49707 |
|
49708 |
|
49709 | SplitLaneHandler.prototype.preExecute = function(context) {
|
49710 |
|
49711 | var modeling = this._modeling,
|
49712 | translate = this._translate;
|
49713 |
|
49714 | var shape = context.shape,
|
49715 | newLanesCount = context.count;
|
49716 |
|
49717 | var childLanes = getChildLanes(shape),
|
49718 | existingLanesCount = childLanes.length;
|
49719 |
|
49720 | if (existingLanesCount > newLanesCount) {
|
49721 | throw new Error(translate('more than {count} child lanes', { count: newLanesCount }));
|
49722 | }
|
49723 |
|
49724 | var newLanesHeight = Math.round(shape.height / newLanesCount);
|
49725 |
|
49726 |
|
49727 |
|
49728 |
|
49729 |
|
49730 |
|
49731 |
|
49732 | var laneY,
|
49733 | laneHeight,
|
49734 | laneBounds,
|
49735 | newLaneAttrs,
|
49736 | idx;
|
49737 |
|
49738 | for (idx = 0; idx < newLanesCount; idx++) {
|
49739 |
|
49740 | laneY = shape.y + idx * newLanesHeight;
|
49741 |
|
49742 |
|
49743 | if (idx === newLanesCount - 1) {
|
49744 | laneHeight = shape.height - (newLanesHeight * idx);
|
49745 | } else {
|
49746 | laneHeight = newLanesHeight;
|
49747 | }
|
49748 |
|
49749 | laneBounds = {
|
49750 | x: shape.x + LANE_INDENTATION,
|
49751 | y: laneY,
|
49752 | width: shape.width - LANE_INDENTATION,
|
49753 | height: laneHeight
|
49754 | };
|
49755 |
|
49756 | if (idx < existingLanesCount) {
|
49757 |
|
49758 |
|
49759 | modeling.resizeShape(childLanes[idx], laneBounds);
|
49760 | } else {
|
49761 |
|
49762 |
|
49763 | newLaneAttrs = {
|
49764 | type: 'bpmn:Lane'
|
49765 | };
|
49766 |
|
49767 | modeling.createShape(newLaneAttrs, laneBounds, shape);
|
49768 | }
|
49769 | }
|
49770 | };
|
49771 |
|
49772 | |
49773 |
|
49774 |
|
49775 |
|
49776 |
|
49777 | function ResizeLaneHandler(modeling, spaceTool) {
|
49778 | this._modeling = modeling;
|
49779 | this._spaceTool = spaceTool;
|
49780 | }
|
49781 |
|
49782 | ResizeLaneHandler.$inject = [
|
49783 | 'modeling',
|
49784 | 'spaceTool'
|
49785 | ];
|
49786 |
|
49787 |
|
49788 | ResizeLaneHandler.prototype.preExecute = function(context) {
|
49789 |
|
49790 | var shape = context.shape,
|
49791 | newBounds = context.newBounds,
|
49792 | balanced = context.balanced;
|
49793 |
|
49794 | if (balanced !== false) {
|
49795 | this.resizeBalanced(shape, newBounds);
|
49796 | } else {
|
49797 | this.resizeSpace(shape, newBounds);
|
49798 | }
|
49799 | };
|
49800 |
|
49801 |
|
49802 | |
49803 |
|
49804 |
|
49805 |
|
49806 |
|
49807 |
|
49808 | ResizeLaneHandler.prototype.resizeBalanced = function(shape, newBounds) {
|
49809 |
|
49810 | var modeling = this._modeling;
|
49811 |
|
49812 | var resizeNeeded = computeLanesResize(shape, newBounds);
|
49813 |
|
49814 |
|
49815 | modeling.resizeShape(shape, newBounds);
|
49816 |
|
49817 |
|
49818 | resizeNeeded.forEach(function(r) {
|
49819 | modeling.resizeShape(r.shape, r.newBounds);
|
49820 | });
|
49821 | };
|
49822 |
|
49823 |
|
49824 | |
49825 |
|
49826 |
|
49827 |
|
49828 |
|
49829 |
|
49830 | ResizeLaneHandler.prototype.resizeSpace = function(shape, newBounds) {
|
49831 | var spaceTool = this._spaceTool;
|
49832 |
|
49833 | var shapeTrbl = asTRBL(shape),
|
49834 | newTrbl = asTRBL(newBounds);
|
49835 |
|
49836 | var trblDiff = substractTRBL(newTrbl, shapeTrbl);
|
49837 |
|
49838 | var lanesRoot = getLanesRoot(shape);
|
49839 |
|
49840 | var allAffected = [],
|
49841 | allLanes = [];
|
49842 |
|
49843 | eachElement(lanesRoot, function(element) {
|
49844 | allAffected.push(element);
|
49845 |
|
49846 | if (is$1(element, 'bpmn:Lane') || is$1(element, 'bpmn:Participant')) {
|
49847 | allLanes.push(element);
|
49848 | }
|
49849 |
|
49850 | return element.children;
|
49851 | });
|
49852 |
|
49853 | var change,
|
49854 | spacePos,
|
49855 | direction,
|
49856 | offset,
|
49857 | adjustments;
|
49858 |
|
49859 | if (trblDiff.bottom || trblDiff.top) {
|
49860 |
|
49861 | change = trblDiff.bottom || trblDiff.top;
|
49862 | spacePos = shape.y + (trblDiff.bottom ? shape.height : 0) + (trblDiff.bottom ? -10 : 10);
|
49863 | direction = trblDiff.bottom ? 's' : 'n';
|
49864 |
|
49865 | offset = trblDiff.top > 0 || trblDiff.bottom < 0 ? -change : change;
|
49866 |
|
49867 | adjustments = spaceTool.calculateAdjustments(allAffected, 'y', offset, spacePos);
|
49868 |
|
49869 | spaceTool.makeSpace(adjustments.movingShapes, adjustments.resizingShapes, { x: 0, y: change }, direction);
|
49870 | }
|
49871 |
|
49872 |
|
49873 | if (trblDiff.left || trblDiff.right) {
|
49874 |
|
49875 | change = trblDiff.right || trblDiff.left;
|
49876 | spacePos = shape.x + (trblDiff.right ? shape.width : 0) + (trblDiff.right ? -10 : 100);
|
49877 | direction = trblDiff.right ? 'e' : 'w';
|
49878 |
|
49879 | offset = trblDiff.left > 0 || trblDiff.right < 0 ? -change : change;
|
49880 |
|
49881 | adjustments = spaceTool.calculateAdjustments(allLanes, 'x', offset, spacePos);
|
49882 |
|
49883 | spaceTool.makeSpace(adjustments.movingShapes, adjustments.resizingShapes, { x: change, y: 0 }, direction);
|
49884 | }
|
49885 | };
|
49886 |
|
49887 | var FLOW_NODE_REFS_ATTR = 'flowNodeRef',
|
49888 | LANES_ATTR = 'lanes';
|
49889 |
|
49890 |
|
49891 | |
49892 |
|
49893 |
|
49894 | function UpdateFlowNodeRefsHandler(elementRegistry) {
|
49895 | this._elementRegistry = elementRegistry;
|
49896 | }
|
49897 |
|
49898 | UpdateFlowNodeRefsHandler.$inject = [
|
49899 | 'elementRegistry'
|
49900 | ];
|
49901 |
|
49902 |
|
49903 | UpdateFlowNodeRefsHandler.prototype.computeUpdates = function(flowNodeShapes, laneShapes) {
|
49904 |
|
49905 | var handledNodes = [];
|
49906 |
|
49907 | var updates = [];
|
49908 |
|
49909 | var participantCache = {};
|
49910 |
|
49911 | var allFlowNodeShapes = [];
|
49912 |
|
49913 | function isInLaneShape(element, laneShape) {
|
49914 |
|
49915 | var laneTrbl = asTRBL(laneShape);
|
49916 |
|
49917 | var elementMid = {
|
49918 | x: element.x + element.width / 2,
|
49919 | y: element.y + element.height / 2
|
49920 | };
|
49921 |
|
49922 | return elementMid.x > laneTrbl.left &&
|
49923 | elementMid.x < laneTrbl.right &&
|
49924 | elementMid.y > laneTrbl.top &&
|
49925 | elementMid.y < laneTrbl.bottom;
|
49926 | }
|
49927 |
|
49928 | function addFlowNodeShape(flowNodeShape) {
|
49929 | if (handledNodes.indexOf(flowNodeShape) === -1) {
|
49930 | allFlowNodeShapes.push(flowNodeShape);
|
49931 | handledNodes.push(flowNodeShape);
|
49932 | }
|
49933 | }
|
49934 |
|
49935 | function getAllLaneShapes(flowNodeShape) {
|
49936 |
|
49937 | var root = getLanesRoot(flowNodeShape);
|
49938 |
|
49939 | if (!participantCache[root.id]) {
|
49940 | participantCache[root.id] = collectLanes(root);
|
49941 | }
|
49942 |
|
49943 | return participantCache[root.id];
|
49944 | }
|
49945 |
|
49946 | function getNewLanes(flowNodeShape) {
|
49947 | if (!flowNodeShape.parent) {
|
49948 | return [];
|
49949 | }
|
49950 |
|
49951 | var allLaneShapes = getAllLaneShapes(flowNodeShape);
|
49952 |
|
49953 | return allLaneShapes.filter(function(l) {
|
49954 | return isInLaneShape(flowNodeShape, l);
|
49955 | }).map(function(shape) {
|
49956 | return shape.businessObject;
|
49957 | });
|
49958 | }
|
49959 |
|
49960 | laneShapes.forEach(function(laneShape) {
|
49961 | var root = getLanesRoot(laneShape);
|
49962 |
|
49963 | if (!root || handledNodes.indexOf(root) !== -1) {
|
49964 | return;
|
49965 | }
|
49966 |
|
49967 | var children = root.children.filter(function(c) {
|
49968 | return is$1(c, 'bpmn:FlowNode');
|
49969 | });
|
49970 |
|
49971 | children.forEach(addFlowNodeShape);
|
49972 |
|
49973 | handledNodes.push(root);
|
49974 | });
|
49975 |
|
49976 | flowNodeShapes.forEach(addFlowNodeShape);
|
49977 |
|
49978 |
|
49979 | allFlowNodeShapes.forEach(function(flowNodeShape) {
|
49980 |
|
49981 | var flowNode = flowNodeShape.businessObject;
|
49982 |
|
49983 | var lanes = flowNode.get(LANES_ATTR),
|
49984 | remove = lanes.slice(),
|
49985 | add = getNewLanes(flowNodeShape);
|
49986 |
|
49987 | updates.push({ flowNode: flowNode, remove: remove, add: add });
|
49988 | });
|
49989 |
|
49990 | laneShapes.forEach(function(laneShape) {
|
49991 |
|
49992 | var lane = laneShape.businessObject;
|
49993 |
|
49994 |
|
49995 | if (!laneShape.parent) {
|
49996 | lane.get(FLOW_NODE_REFS_ATTR).forEach(function(flowNode) {
|
49997 | updates.push({ flowNode: flowNode, remove: [ lane ], add: [] });
|
49998 | });
|
49999 | }
|
50000 | });
|
50001 |
|
50002 | return updates;
|
50003 | };
|
50004 |
|
50005 | UpdateFlowNodeRefsHandler.prototype.execute = function(context) {
|
50006 |
|
50007 | var updates = context.updates;
|
50008 |
|
50009 | if (!updates) {
|
50010 | updates = context.updates = this.computeUpdates(context.flowNodeShapes, context.laneShapes);
|
50011 | }
|
50012 |
|
50013 |
|
50014 | updates.forEach(function(update) {
|
50015 |
|
50016 | var flowNode = update.flowNode,
|
50017 | lanes = flowNode.get(LANES_ATTR);
|
50018 |
|
50019 |
|
50020 | update.remove.forEach(function(oldLane) {
|
50021 | remove$2(lanes, oldLane);
|
50022 | remove$2(oldLane.get(FLOW_NODE_REFS_ATTR), flowNode);
|
50023 | });
|
50024 |
|
50025 |
|
50026 | update.add.forEach(function(newLane) {
|
50027 | add$1(lanes, newLane);
|
50028 | add$1(newLane.get(FLOW_NODE_REFS_ATTR), flowNode);
|
50029 | });
|
50030 | });
|
50031 |
|
50032 |
|
50033 |
|
50034 | };
|
50035 |
|
50036 |
|
50037 | UpdateFlowNodeRefsHandler.prototype.revert = function(context) {
|
50038 |
|
50039 | var updates = context.updates;
|
50040 |
|
50041 | updates.forEach(function(update) {
|
50042 |
|
50043 | var flowNode = update.flowNode,
|
50044 | lanes = flowNode.get(LANES_ATTR);
|
50045 |
|
50046 |
|
50047 | update.add.forEach(function(newLane) {
|
50048 | remove$2(lanes, newLane);
|
50049 | remove$2(newLane.get(FLOW_NODE_REFS_ATTR), flowNode);
|
50050 | });
|
50051 |
|
50052 |
|
50053 | update.remove.forEach(function(oldLane) {
|
50054 | add$1(lanes, oldLane);
|
50055 | add$1(oldLane.get(FLOW_NODE_REFS_ATTR), flowNode);
|
50056 | });
|
50057 | });
|
50058 |
|
50059 |
|
50060 |
|
50061 | };
|
50062 |
|
50063 | function IdClaimHandler(moddle) {
|
50064 | this._moddle = moddle;
|
50065 | }
|
50066 |
|
50067 | IdClaimHandler.$inject = [ 'moddle' ];
|
50068 |
|
50069 |
|
50070 | IdClaimHandler.prototype.execute = function(context) {
|
50071 | var ids = this._moddle.ids,
|
50072 | id = context.id,
|
50073 | element = context.element,
|
50074 | claiming = context.claiming;
|
50075 |
|
50076 | if (claiming) {
|
50077 | ids.claim(id, element);
|
50078 | } else {
|
50079 | ids.unclaim(id);
|
50080 | }
|
50081 | };
|
50082 |
|
50083 | |
50084 |
|
50085 |
|
50086 | IdClaimHandler.prototype.revert = function(context) {
|
50087 | var ids = this._moddle.ids,
|
50088 | id = context.id,
|
50089 | element = context.element,
|
50090 | claiming = context.claiming;
|
50091 |
|
50092 | if (claiming) {
|
50093 | ids.unclaim(id);
|
50094 | } else {
|
50095 | ids.claim(id, element);
|
50096 | }
|
50097 | };
|
50098 |
|
50099 | var DEFAULT_COLORS = {
|
50100 | fill: undefined,
|
50101 | stroke: undefined
|
50102 | };
|
50103 |
|
50104 |
|
50105 | function SetColorHandler(commandStack) {
|
50106 | this._commandStack = commandStack;
|
50107 | }
|
50108 |
|
50109 | SetColorHandler.$inject = [
|
50110 | 'commandStack'
|
50111 | ];
|
50112 |
|
50113 |
|
50114 | SetColorHandler.prototype.postExecute = function(context) {
|
50115 | var elements = context.elements,
|
50116 | colors = context.colors || DEFAULT_COLORS;
|
50117 |
|
50118 | var self = this;
|
50119 |
|
50120 | var di = {};
|
50121 |
|
50122 | if ('fill' in colors) {
|
50123 | assign(di, { fill: colors.fill });
|
50124 | }
|
50125 |
|
50126 | if ('stroke' in colors) {
|
50127 | assign(di, { stroke: colors.stroke });
|
50128 | }
|
50129 |
|
50130 | forEach(elements, function(element) {
|
50131 |
|
50132 | self._commandStack.execute('element.updateProperties', {
|
50133 | element: element,
|
50134 | properties: {
|
50135 | di: di
|
50136 | }
|
50137 | });
|
50138 | });
|
50139 |
|
50140 | };
|
50141 |
|
50142 | var NULL_DIMENSIONS$1 = {
|
50143 | width: 0,
|
50144 | height: 0
|
50145 | };
|
50146 |
|
50147 |
|
50148 | |
50149 |
|
50150 |
|
50151 | function UpdateLabelHandler(modeling, textRenderer) {
|
50152 |
|
50153 | |
50154 |
|
50155 |
|
50156 |
|
50157 |
|
50158 |
|
50159 |
|
50160 |
|
50161 | function setText(element, text) {
|
50162 |
|
50163 |
|
50164 | var label = element.label || element;
|
50165 |
|
50166 | var labelTarget = element.labelTarget || element;
|
50167 |
|
50168 | setLabel(label, text);
|
50169 |
|
50170 | return [ label, labelTarget ];
|
50171 | }
|
50172 |
|
50173 | function preExecute(ctx) {
|
50174 | var element = ctx.element,
|
50175 | businessObject = element.businessObject,
|
50176 | newLabel = ctx.newLabel;
|
50177 |
|
50178 | if (!isLabel(element)
|
50179 | && isLabelExternal(element)
|
50180 | && !hasExternalLabel(element)
|
50181 | && !isEmptyText$1(newLabel)) {
|
50182 |
|
50183 |
|
50184 | var paddingTop = 7;
|
50185 |
|
50186 | var labelCenter = getExternalLabelMid(element);
|
50187 |
|
50188 | labelCenter = {
|
50189 | x: labelCenter.x,
|
50190 | y: labelCenter.y + paddingTop
|
50191 | };
|
50192 |
|
50193 | modeling.createLabel(element, labelCenter, {
|
50194 | id: businessObject.id + '_label',
|
50195 | businessObject: businessObject
|
50196 | });
|
50197 | }
|
50198 | }
|
50199 |
|
50200 | function execute(ctx) {
|
50201 | ctx.oldLabel = getLabel(ctx.element);
|
50202 | return setText(ctx.element, ctx.newLabel);
|
50203 | }
|
50204 |
|
50205 | function revert(ctx) {
|
50206 | return setText(ctx.element, ctx.oldLabel);
|
50207 | }
|
50208 |
|
50209 | function postExecute(ctx) {
|
50210 | var element = ctx.element,
|
50211 | label = element.label || element,
|
50212 | newLabel = ctx.newLabel,
|
50213 | newBounds = ctx.newBounds,
|
50214 | hints = ctx.hints || {};
|
50215 |
|
50216 | if (isLabel(label) && isEmptyText$1(newLabel)) {
|
50217 |
|
50218 | if (hints.removeShape !== false) {
|
50219 | modeling.removeShape(label, { unsetLabel: false });
|
50220 | }
|
50221 |
|
50222 | return;
|
50223 | }
|
50224 |
|
50225 |
|
50226 | if (!isLabelExternal(element) && !is$1(element, 'bpmn:TextAnnotation')) {
|
50227 | return;
|
50228 | }
|
50229 |
|
50230 | var text = getLabel(label);
|
50231 |
|
50232 |
|
50233 | if (!text) {
|
50234 | return;
|
50235 | }
|
50236 |
|
50237 |
|
50238 | if (typeof newBounds === 'undefined') {
|
50239 | newBounds = textRenderer.getExternalLabelBounds(label, text);
|
50240 | }
|
50241 |
|
50242 |
|
50243 |
|
50244 | if (newBounds) {
|
50245 | modeling.resizeShape(label, newBounds, NULL_DIMENSIONS$1);
|
50246 | }
|
50247 | }
|
50248 |
|
50249 |
|
50250 |
|
50251 | this.preExecute = preExecute;
|
50252 | this.execute = execute;
|
50253 | this.revert = revert;
|
50254 | this.postExecute = postExecute;
|
50255 | }
|
50256 |
|
50257 | UpdateLabelHandler.$inject = [
|
50258 | 'modeling',
|
50259 | 'textRenderer'
|
50260 | ];
|
50261 |
|
50262 |
|
50263 |
|
50264 |
|
50265 | function isEmptyText$1(label) {
|
50266 | return !label || !label.trim();
|
50267 | }
|
50268 |
|
50269 | |
50270 |
|
50271 |
|
50272 |
|
50273 |
|
50274 |
|
50275 |
|
50276 |
|
50277 | function Modeling$1(
|
50278 | eventBus, elementFactory, commandStack,
|
50279 | bpmnRules) {
|
50280 |
|
50281 | Modeling.call(this, eventBus, elementFactory, commandStack);
|
50282 |
|
50283 | this._bpmnRules = bpmnRules;
|
50284 | }
|
50285 |
|
50286 | inherits_browser(Modeling$1, Modeling);
|
50287 |
|
50288 | Modeling$1.$inject = [
|
50289 | 'eventBus',
|
50290 | 'elementFactory',
|
50291 | 'commandStack',
|
50292 | 'bpmnRules'
|
50293 | ];
|
50294 |
|
50295 |
|
50296 | Modeling$1.prototype.getHandlers = function() {
|
50297 | var handlers = Modeling.prototype.getHandlers.call(this);
|
50298 |
|
50299 | handlers['element.updateProperties'] = UpdatePropertiesHandler;
|
50300 | handlers['canvas.updateRoot'] = UpdateCanvasRootHandler;
|
50301 | handlers['lane.add'] = AddLaneHandler;
|
50302 | handlers['lane.resize'] = ResizeLaneHandler;
|
50303 | handlers['lane.split'] = SplitLaneHandler;
|
50304 | handlers['lane.updateRefs'] = UpdateFlowNodeRefsHandler;
|
50305 | handlers['id.updateClaim'] = IdClaimHandler;
|
50306 | handlers['element.setColor'] = SetColorHandler;
|
50307 | handlers['element.updateLabel'] = UpdateLabelHandler;
|
50308 |
|
50309 | return handlers;
|
50310 | };
|
50311 |
|
50312 |
|
50313 | Modeling$1.prototype.updateLabel = function(element, newLabel, newBounds, hints) {
|
50314 | this._commandStack.execute('element.updateLabel', {
|
50315 | element: element,
|
50316 | newLabel: newLabel,
|
50317 | newBounds: newBounds,
|
50318 | hints: hints || {}
|
50319 | });
|
50320 | };
|
50321 |
|
50322 |
|
50323 | Modeling$1.prototype.connect = function(source, target, attrs, hints) {
|
50324 |
|
50325 | var bpmnRules = this._bpmnRules;
|
50326 |
|
50327 | if (!attrs) {
|
50328 | attrs = bpmnRules.canConnect(source, target);
|
50329 | }
|
50330 |
|
50331 | if (!attrs) {
|
50332 | return;
|
50333 | }
|
50334 |
|
50335 | return this.createConnection(source, target, attrs, source.parent, hints);
|
50336 | };
|
50337 |
|
50338 |
|
50339 | Modeling$1.prototype.updateProperties = function(element, properties) {
|
50340 | this._commandStack.execute('element.updateProperties', {
|
50341 | element: element,
|
50342 | properties: properties
|
50343 | });
|
50344 | };
|
50345 |
|
50346 | Modeling$1.prototype.resizeLane = function(laneShape, newBounds, balanced) {
|
50347 | this._commandStack.execute('lane.resize', {
|
50348 | shape: laneShape,
|
50349 | newBounds: newBounds,
|
50350 | balanced: balanced
|
50351 | });
|
50352 | };
|
50353 |
|
50354 | Modeling$1.prototype.addLane = function(targetLaneShape, location) {
|
50355 | var context = {
|
50356 | shape: targetLaneShape,
|
50357 | location: location
|
50358 | };
|
50359 |
|
50360 | this._commandStack.execute('lane.add', context);
|
50361 |
|
50362 | return context.newLane;
|
50363 | };
|
50364 |
|
50365 | Modeling$1.prototype.splitLane = function(targetLane, count) {
|
50366 | this._commandStack.execute('lane.split', {
|
50367 | shape: targetLane,
|
50368 | count: count
|
50369 | });
|
50370 | };
|
50371 |
|
50372 | |
50373 |
|
50374 |
|
50375 |
|
50376 |
|
50377 | Modeling$1.prototype.makeCollaboration = function() {
|
50378 |
|
50379 | var collaborationElement = this._create('root', {
|
50380 | type: 'bpmn:Collaboration'
|
50381 | });
|
50382 |
|
50383 | var context = {
|
50384 | newRoot: collaborationElement
|
50385 | };
|
50386 |
|
50387 | this._commandStack.execute('canvas.updateRoot', context);
|
50388 |
|
50389 | return collaborationElement;
|
50390 | };
|
50391 |
|
50392 | Modeling$1.prototype.updateLaneRefs = function(flowNodeShapes, laneShapes) {
|
50393 |
|
50394 | this._commandStack.execute('lane.updateRefs', {
|
50395 | flowNodeShapes: flowNodeShapes,
|
50396 | laneShapes: laneShapes
|
50397 | });
|
50398 | };
|
50399 |
|
50400 | |
50401 |
|
50402 |
|
50403 |
|
50404 |
|
50405 | Modeling$1.prototype.makeProcess = function() {
|
50406 |
|
50407 | var processElement = this._create('root', {
|
50408 | type: 'bpmn:Process'
|
50409 | });
|
50410 |
|
50411 | var context = {
|
50412 | newRoot: processElement
|
50413 | };
|
50414 |
|
50415 | this._commandStack.execute('canvas.updateRoot', context);
|
50416 | };
|
50417 |
|
50418 |
|
50419 | Modeling$1.prototype.claimId = function(id, moddleElement) {
|
50420 | this._commandStack.execute('id.updateClaim', {
|
50421 | id: id,
|
50422 | element: moddleElement,
|
50423 | claiming: true
|
50424 | });
|
50425 | };
|
50426 |
|
50427 |
|
50428 | Modeling$1.prototype.unclaimId = function(id, moddleElement) {
|
50429 | this._commandStack.execute('id.updateClaim', {
|
50430 | id: id,
|
50431 | element: moddleElement
|
50432 | });
|
50433 | };
|
50434 |
|
50435 | Modeling$1.prototype.setColor = function(elements, colors) {
|
50436 | if (!elements.length) {
|
50437 | elements = [ elements ];
|
50438 | }
|
50439 |
|
50440 | this._commandStack.execute('element.setColor', {
|
50441 | elements: elements,
|
50442 | colors: colors
|
50443 | });
|
50444 | };
|
50445 |
|
50446 | |
50447 |
|
50448 |
|
50449 |
|
50450 |
|
50451 | function BaseLayouter() {}
|
50452 |
|
50453 |
|
50454 | |
50455 |
|
50456 |
|
50457 |
|
50458 |
|
50459 |
|
50460 |
|
50461 |
|
50462 |
|
50463 |
|
50464 |
|
50465 |
|
50466 |
|
50467 |
|
50468 |
|
50469 | BaseLayouter.prototype.layoutConnection = function(connection, hints) {
|
50470 |
|
50471 | hints = hints || {};
|
50472 |
|
50473 | return [
|
50474 | hints.connectionStart || getMid(hints.source || connection.source),
|
50475 | hints.connectionEnd || getMid(hints.target || connection.target)
|
50476 | ];
|
50477 | };
|
50478 |
|
50479 | var MIN_SEGMENT_LENGTH = 20,
|
50480 | POINT_ORIENTATION_PADDING = 5;
|
50481 |
|
50482 | var round$a = Math.round;
|
50483 |
|
50484 | var INTERSECTION_THRESHOLD$1 = 20,
|
50485 | ORIENTATION_THRESHOLD = {
|
50486 | 'h:h': 20,
|
50487 | 'v:v': 20,
|
50488 | 'h:v': -10,
|
50489 | 'v:h': -10
|
50490 | };
|
50491 |
|
50492 | function needsTurn(orientation, startDirection) {
|
50493 | return !{
|
50494 | t: /top/,
|
50495 | r: /right/,
|
50496 | b: /bottom/,
|
50497 | l: /left/,
|
50498 | h: /./,
|
50499 | v: /./
|
50500 | }[startDirection].test(orientation);
|
50501 | }
|
50502 |
|
50503 | function canLayoutStraight(direction, targetOrientation) {
|
50504 | return {
|
50505 | t: /top/,
|
50506 | r: /right/,
|
50507 | b: /bottom/,
|
50508 | l: /left/,
|
50509 | h: /left|right/,
|
50510 | v: /top|bottom/
|
50511 | }[direction].test(targetOrientation);
|
50512 | }
|
50513 |
|
50514 | function getSegmentBendpoints(a, b, directions) {
|
50515 | var orientation = getOrientation(b, a, POINT_ORIENTATION_PADDING);
|
50516 |
|
50517 | var startDirection = directions.split(':')[0];
|
50518 |
|
50519 | var xmid = round$a((b.x - a.x) / 2 + a.x),
|
50520 | ymid = round$a((b.y - a.y) / 2 + a.y);
|
50521 |
|
50522 | var segmentEnd, segmentDirections;
|
50523 |
|
50524 | var layoutStraight = canLayoutStraight(startDirection, orientation),
|
50525 | layoutHorizontal = /h|r|l/.test(startDirection),
|
50526 | layoutTurn = false;
|
50527 |
|
50528 | var turnNextDirections = false;
|
50529 |
|
50530 | if (layoutStraight) {
|
50531 | segmentEnd = layoutHorizontal ? { x: xmid, y: a.y } : { x: a.x, y: ymid };
|
50532 |
|
50533 | segmentDirections = layoutHorizontal ? 'h:h' : 'v:v';
|
50534 | } else {
|
50535 | layoutTurn = needsTurn(orientation, startDirection);
|
50536 |
|
50537 | segmentDirections = layoutHorizontal ? 'h:v' : 'v:h';
|
50538 |
|
50539 | if (layoutTurn) {
|
50540 |
|
50541 | if (layoutHorizontal) {
|
50542 | turnNextDirections = ymid === a.y;
|
50543 |
|
50544 | segmentEnd = {
|
50545 | x: a.x + MIN_SEGMENT_LENGTH * (/l/.test(startDirection) ? -1 : 1),
|
50546 | y: turnNextDirections ? ymid + MIN_SEGMENT_LENGTH : ymid
|
50547 | };
|
50548 | } else {
|
50549 | turnNextDirections = xmid === a.x;
|
50550 |
|
50551 | segmentEnd = {
|
50552 | x: turnNextDirections ? xmid + MIN_SEGMENT_LENGTH : xmid,
|
50553 | y: a.y + MIN_SEGMENT_LENGTH * (/t/.test(startDirection) ? -1 : 1)
|
50554 | };
|
50555 | }
|
50556 |
|
50557 | } else {
|
50558 | segmentEnd = {
|
50559 | x: xmid,
|
50560 | y: ymid
|
50561 | };
|
50562 | }
|
50563 | }
|
50564 |
|
50565 | return {
|
50566 | waypoints: getBendpoints(a, segmentEnd, segmentDirections).concat(segmentEnd),
|
50567 | directions: segmentDirections,
|
50568 | turnNextDirections: turnNextDirections
|
50569 | };
|
50570 | }
|
50571 |
|
50572 | function getStartSegment(a, b, directions) {
|
50573 | return getSegmentBendpoints(a, b, directions);
|
50574 | }
|
50575 |
|
50576 | function getEndSegment(a, b, directions) {
|
50577 | var invertedSegment = getSegmentBendpoints(b, a, invertDirections(directions));
|
50578 |
|
50579 | return {
|
50580 | waypoints: invertedSegment.waypoints.slice().reverse(),
|
50581 | directions: invertDirections(invertedSegment.directions),
|
50582 | turnNextDirections: invertedSegment.turnNextDirections
|
50583 | };
|
50584 | }
|
50585 |
|
50586 | function getMidSegment(startSegment, endSegment) {
|
50587 |
|
50588 | var startDirection = startSegment.directions.split(':')[1],
|
50589 | endDirection = endSegment.directions.split(':')[0];
|
50590 |
|
50591 | if (startSegment.turnNextDirections) {
|
50592 | startDirection = startDirection == 'h' ? 'v' : 'h';
|
50593 | }
|
50594 |
|
50595 | if (endSegment.turnNextDirections) {
|
50596 | endDirection = endDirection == 'h' ? 'v' : 'h';
|
50597 | }
|
50598 |
|
50599 | var directions = startDirection + ':' + endDirection;
|
50600 |
|
50601 | var bendpoints = getBendpoints(
|
50602 | startSegment.waypoints[startSegment.waypoints.length - 1],
|
50603 | endSegment.waypoints[0],
|
50604 | directions
|
50605 | );
|
50606 |
|
50607 | return {
|
50608 | waypoints: bendpoints,
|
50609 | directions: directions
|
50610 | };
|
50611 | }
|
50612 |
|
50613 | function invertDirections(directions) {
|
50614 | return directions.split(':').reverse().join(':');
|
50615 | }
|
50616 |
|
50617 | |
50618 |
|
50619 |
|
50620 | function getSimpleBendpoints(a, b, directions) {
|
50621 |
|
50622 | var xmid = round$a((b.x - a.x) / 2 + a.x),
|
50623 | ymid = round$a((b.y - a.y) / 2 + a.y);
|
50624 |
|
50625 |
|
50626 | if (directions === 'h:v') {
|
50627 | return [ { x: b.x, y: a.y } ];
|
50628 | }
|
50629 |
|
50630 |
|
50631 | if (directions === 'v:h') {
|
50632 | return [ { x: a.x, y: b.y } ];
|
50633 | }
|
50634 |
|
50635 |
|
50636 | if (directions === 'h:h') {
|
50637 | return [
|
50638 | { x: xmid, y: a.y },
|
50639 | { x: xmid, y: b.y }
|
50640 | ];
|
50641 | }
|
50642 |
|
50643 |
|
50644 | if (directions === 'v:v') {
|
50645 | return [
|
50646 | { x: a.x, y: ymid },
|
50647 | { x: b.x, y: ymid }
|
50648 | ];
|
50649 | }
|
50650 |
|
50651 | throw new Error('invalid directions: can only handle varians of [hv]:[hv]');
|
50652 | }
|
50653 |
|
50654 |
|
50655 | |
50656 |
|
50657 |
|
50658 |
|
50659 |
|
50660 |
|
50661 |
|
50662 |
|
50663 |
|
50664 |
|
50665 |
|
50666 |
|
50667 |
|
50668 |
|
50669 |
|
50670 |
|
50671 |
|
50672 |
|
50673 |
|
50674 |
|
50675 |
|
50676 |
|
50677 |
|
50678 |
|
50679 |
|
50680 |
|
50681 |
|
50682 | function getBendpoints(a, b, directions) {
|
50683 | directions = directions || 'h:h';
|
50684 |
|
50685 | if (!isValidDirections(directions)) {
|
50686 | throw new Error(
|
50687 | 'unknown directions: <' + directions + '>: ' +
|
50688 | 'must be specified as <start>:<end> ' +
|
50689 | 'with start/end in { h,v,t,r,b,l }'
|
50690 | );
|
50691 | }
|
50692 |
|
50693 |
|
50694 |
|
50695 | if (isExplicitDirections(directions)) {
|
50696 | var startSegment = getStartSegment(a, b, directions),
|
50697 | endSegment = getEndSegment(a, b, directions),
|
50698 | midSegment = getMidSegment(startSegment, endSegment);
|
50699 |
|
50700 | return [].concat(
|
50701 | startSegment.waypoints,
|
50702 | midSegment.waypoints,
|
50703 | endSegment.waypoints
|
50704 | );
|
50705 | }
|
50706 |
|
50707 |
|
50708 | return getSimpleBendpoints(a, b, directions);
|
50709 | }
|
50710 |
|
50711 | |
50712 |
|
50713 |
|
50714 |
|
50715 |
|
50716 |
|
50717 |
|
50718 |
|
50719 |
|
50720 |
|
50721 |
|
50722 |
|
50723 | function connectPoints(a, b, directions) {
|
50724 |
|
50725 | var points = getBendpoints(a, b, directions);
|
50726 |
|
50727 | points.unshift(a);
|
50728 | points.push(b);
|
50729 |
|
50730 | return withoutRedundantPoints(points);
|
50731 | }
|
50732 |
|
50733 |
|
50734 | |
50735 |
|
50736 |
|
50737 |
|
50738 |
|
50739 |
|
50740 |
|
50741 |
|
50742 |
|
50743 |
|
50744 |
|
50745 |
|
50746 |
|
50747 |
|
50748 |
|
50749 |
|
50750 | function connectRectangles(source, target, start, end, hints) {
|
50751 |
|
50752 | var preferredLayouts = hints && hints.preferredLayouts || [];
|
50753 |
|
50754 | var preferredLayout = without(preferredLayouts, 'straight')[0] || 'h:h';
|
50755 |
|
50756 | var threshold = ORIENTATION_THRESHOLD[preferredLayout] || 0;
|
50757 |
|
50758 | var orientation = getOrientation(source, target, threshold);
|
50759 |
|
50760 | var directions = getDirections(orientation, preferredLayout);
|
50761 |
|
50762 | start = start || getMid(source);
|
50763 | end = end || getMid(target);
|
50764 |
|
50765 | var directionSplit = directions.split(':');
|
50766 |
|
50767 |
|
50768 |
|
50769 |
|
50770 | var startDocking = getDockingPoint(start, source, directionSplit[0], invertOrientation(orientation)),
|
50771 | endDocking = getDockingPoint(end, target, directionSplit[1], orientation);
|
50772 |
|
50773 | return connectPoints(startDocking, endDocking, directions);
|
50774 | }
|
50775 |
|
50776 |
|
50777 | |
50778 |
|
50779 |
|
50780 |
|
50781 |
|
50782 |
|
50783 |
|
50784 |
|
50785 |
|
50786 |
|
50787 |
|
50788 |
|
50789 |
|
50790 |
|
50791 |
|
50792 | function repairConnection(source, target, start, end, waypoints, hints) {
|
50793 |
|
50794 | if (isArray(start)) {
|
50795 | waypoints = start;
|
50796 | hints = end;
|
50797 |
|
50798 | start = getMid(source);
|
50799 | end = getMid(target);
|
50800 | }
|
50801 |
|
50802 | hints = assign({ preferredLayouts: [] }, hints);
|
50803 | waypoints = waypoints || [];
|
50804 |
|
50805 | var preferredLayouts = hints.preferredLayouts,
|
50806 | preferStraight = preferredLayouts.indexOf('straight') !== -1,
|
50807 | repairedWaypoints;
|
50808 |
|
50809 |
|
50810 |
|
50811 |
|
50812 |
|
50813 | repairedWaypoints = preferStraight && tryLayoutStraight(source, target, start, end, hints);
|
50814 |
|
50815 | if (repairedWaypoints) {
|
50816 | return repairedWaypoints;
|
50817 | }
|
50818 |
|
50819 |
|
50820 | repairedWaypoints = hints.connectionEnd && tryRepairConnectionEnd(target, source, end, waypoints);
|
50821 |
|
50822 | if (repairedWaypoints) {
|
50823 | return repairedWaypoints;
|
50824 | }
|
50825 |
|
50826 |
|
50827 | repairedWaypoints = hints.connectionStart && tryRepairConnectionStart(source, target, start, waypoints);
|
50828 |
|
50829 | if (repairedWaypoints) {
|
50830 | return repairedWaypoints;
|
50831 | }
|
50832 |
|
50833 |
|
50834 | if (!hints.connectionStart && !hints.connectionEnd && waypoints && waypoints.length) {
|
50835 | return waypoints;
|
50836 | }
|
50837 |
|
50838 |
|
50839 | return connectRectangles(source, target, start, end, hints);
|
50840 | }
|
50841 |
|
50842 |
|
50843 | function inRange(a, start, end) {
|
50844 | return a >= start && a <= end;
|
50845 | }
|
50846 |
|
50847 | function isInRange(axis, a, b) {
|
50848 | var size = {
|
50849 | x: 'width',
|
50850 | y: 'height'
|
50851 | };
|
50852 |
|
50853 | return inRange(a[axis], b[axis], b[axis] + b[size[axis]]);
|
50854 | }
|
50855 |
|
50856 | |
50857 |
|
50858 |
|
50859 |
|
50860 |
|
50861 |
|
50862 |
|
50863 |
|
50864 |
|
50865 |
|
50866 |
|
50867 | function tryLayoutStraight(source, target, start, end, hints) {
|
50868 | var axis = {},
|
50869 | primaryAxis,
|
50870 | orientation;
|
50871 |
|
50872 | orientation = getOrientation(source, target);
|
50873 |
|
50874 |
|
50875 |
|
50876 | if (!/^(top|bottom|left|right)$/.test(orientation)) {
|
50877 | return null;
|
50878 | }
|
50879 |
|
50880 | if (/top|bottom/.test(orientation)) {
|
50881 | primaryAxis = 'x';
|
50882 | }
|
50883 |
|
50884 | if (/left|right/.test(orientation)) {
|
50885 | primaryAxis = 'y';
|
50886 | }
|
50887 |
|
50888 | if (hints.preserveDocking === 'target') {
|
50889 |
|
50890 | if (!isInRange(primaryAxis, end, source)) {
|
50891 | return null;
|
50892 | }
|
50893 |
|
50894 | axis[primaryAxis] = end[primaryAxis];
|
50895 |
|
50896 | return [
|
50897 | {
|
50898 | x: axis.x !== undefined ? axis.x : start.x,
|
50899 | y: axis.y !== undefined ? axis.y : start.y,
|
50900 | original: {
|
50901 | x: axis.x !== undefined ? axis.x : start.x,
|
50902 | y: axis.y !== undefined ? axis.y : start.y
|
50903 | }
|
50904 | },
|
50905 | {
|
50906 | x: end.x,
|
50907 | y: end.y
|
50908 | }
|
50909 | ];
|
50910 |
|
50911 | } else {
|
50912 |
|
50913 | if (!isInRange(primaryAxis, start, target)) {
|
50914 | return null;
|
50915 | }
|
50916 |
|
50917 | axis[primaryAxis] = start[primaryAxis];
|
50918 |
|
50919 | return [
|
50920 | {
|
50921 | x: start.x,
|
50922 | y: start.y
|
50923 | },
|
50924 | {
|
50925 | x: axis.x !== undefined ? axis.x : end.x,
|
50926 | y: axis.y !== undefined ? axis.y : end.y,
|
50927 | original: {
|
50928 | x: axis.x !== undefined ? axis.x : end.x,
|
50929 | y: axis.y !== undefined ? axis.y : end.y
|
50930 | }
|
50931 | }
|
50932 | ];
|
50933 | }
|
50934 |
|
50935 | }
|
50936 |
|
50937 | |
50938 |
|
50939 |
|
50940 |
|
50941 |
|
50942 |
|
50943 |
|
50944 |
|
50945 |
|
50946 |
|
50947 | function tryRepairConnectionStart(moved, other, newDocking, points) {
|
50948 | return _tryRepairConnectionSide(moved, other, newDocking, points);
|
50949 | }
|
50950 |
|
50951 | |
50952 |
|
50953 |
|
50954 |
|
50955 |
|
50956 |
|
50957 |
|
50958 |
|
50959 |
|
50960 |
|
50961 | function tryRepairConnectionEnd(moved, other, newDocking, points) {
|
50962 | var waypoints = points.slice().reverse();
|
50963 |
|
50964 | waypoints = _tryRepairConnectionSide(moved, other, newDocking, waypoints);
|
50965 |
|
50966 | return waypoints ? waypoints.reverse() : null;
|
50967 | }
|
50968 |
|
50969 | |
50970 |
|
50971 |
|
50972 |
|
50973 |
|
50974 |
|
50975 |
|
50976 |
|
50977 |
|
50978 |
|
50979 | function _tryRepairConnectionSide(moved, other, newDocking, points) {
|
50980 |
|
50981 | function needsRelayout(points) {
|
50982 | if (points.length < 3) {
|
50983 | return true;
|
50984 | }
|
50985 |
|
50986 | if (points.length > 4) {
|
50987 | return false;
|
50988 | }
|
50989 |
|
50990 |
|
50991 |
|
50992 | return !!find(points, function(p, idx) {
|
50993 | var q = points[idx - 1];
|
50994 |
|
50995 | return q && pointDistance(p, q) < 3;
|
50996 | });
|
50997 | }
|
50998 |
|
50999 | function repairBendpoint(candidate, oldPeer, newPeer) {
|
51000 |
|
51001 | var alignment = pointsAligned(oldPeer, candidate);
|
51002 |
|
51003 | switch (alignment) {
|
51004 | case 'v':
|
51005 |
|
51006 |
|
51007 | return { x: newPeer.x, y: candidate.y };
|
51008 | case 'h':
|
51009 |
|
51010 |
|
51011 | return { x: candidate.x, y: newPeer.y };
|
51012 | }
|
51013 |
|
51014 | return { x: candidate.x, y: candidate. y };
|
51015 | }
|
51016 |
|
51017 | function removeOverlapping(points, a, b) {
|
51018 | var i;
|
51019 |
|
51020 | for (i = points.length - 2; i !== 0; i--) {
|
51021 |
|
51022 |
|
51023 | if (pointInRect(points[i], a, INTERSECTION_THRESHOLD$1) ||
|
51024 | pointInRect(points[i], b, INTERSECTION_THRESHOLD$1)) {
|
51025 |
|
51026 |
|
51027 | return points.slice(i);
|
51028 | }
|
51029 | }
|
51030 |
|
51031 | return points;
|
51032 | }
|
51033 |
|
51034 |
|
51035 |
|
51036 |
|
51037 |
|
51038 |
|
51039 | if (needsRelayout(points)) {
|
51040 | return null;
|
51041 | }
|
51042 |
|
51043 | var oldDocking = points[0],
|
51044 | newPoints = points.slice(),
|
51045 | slicedPoints;
|
51046 |
|
51047 |
|
51048 |
|
51049 | newPoints[0] = newDocking;
|
51050 | newPoints[1] = repairBendpoint(newPoints[1], oldDocking, newDocking);
|
51051 |
|
51052 |
|
51053 |
|
51054 |
|
51055 | slicedPoints = removeOverlapping(newPoints, moved, other);
|
51056 |
|
51057 | if (slicedPoints !== newPoints) {
|
51058 | newPoints = _tryRepairConnectionSide(moved, other, newDocking, slicedPoints);
|
51059 | }
|
51060 |
|
51061 |
|
51062 | if (newPoints && pointsAligned(newPoints)) {
|
51063 | return null;
|
51064 | }
|
51065 |
|
51066 | return newPoints;
|
51067 | }
|
51068 |
|
51069 |
|
51070 | |
51071 |
|
51072 |
|
51073 |
|
51074 |
|
51075 |
|
51076 |
|
51077 |
|
51078 |
|
51079 |
|
51080 |
|
51081 |
|
51082 |
|
51083 |
|
51084 |
|
51085 |
|
51086 |
|
51087 |
|
51088 |
|
51089 |
|
51090 |
|
51091 | function getDirections(orientation, defaultLayout) {
|
51092 |
|
51093 |
|
51094 | if (isExplicitDirections(defaultLayout)) {
|
51095 | return defaultLayout;
|
51096 | }
|
51097 |
|
51098 | switch (orientation) {
|
51099 | case 'intersect':
|
51100 | return 't:t';
|
51101 |
|
51102 | case 'top':
|
51103 | case 'bottom':
|
51104 | return 'v:v';
|
51105 |
|
51106 | case 'left':
|
51107 | case 'right':
|
51108 | return 'h:h';
|
51109 |
|
51110 |
|
51111 |
|
51112 |
|
51113 |
|
51114 | default:
|
51115 | return defaultLayout;
|
51116 | }
|
51117 | }
|
51118 |
|
51119 | function isValidDirections(directions) {
|
51120 | return directions && /^h|v|t|r|b|l:h|v|t|r|b|l$/.test(directions);
|
51121 | }
|
51122 |
|
51123 | function isExplicitDirections(directions) {
|
51124 | return directions && /t|r|b|l/.test(directions);
|
51125 | }
|
51126 |
|
51127 | function invertOrientation(orientation) {
|
51128 | return {
|
51129 | 'top': 'bottom',
|
51130 | 'bottom': 'top',
|
51131 | 'left': 'right',
|
51132 | 'right': 'left',
|
51133 | 'top-left': 'bottom-right',
|
51134 | 'bottom-right': 'top-left',
|
51135 | 'top-right': 'bottom-left',
|
51136 | 'bottom-left': 'top-right',
|
51137 | }[orientation];
|
51138 | }
|
51139 |
|
51140 | function getDockingPoint(point, rectangle, dockingDirection, targetOrientation) {
|
51141 |
|
51142 |
|
51143 |
|
51144 |
|
51145 | if (dockingDirection === 'h') {
|
51146 | dockingDirection = /left/.test(targetOrientation) ? 'l' : 'r';
|
51147 | }
|
51148 |
|
51149 | if (dockingDirection === 'v') {
|
51150 | dockingDirection = /top/.test(targetOrientation) ? 't' : 'b';
|
51151 | }
|
51152 |
|
51153 | if (dockingDirection === 't') {
|
51154 | return { original: point, x: point.x, y: rectangle.y };
|
51155 | }
|
51156 |
|
51157 | if (dockingDirection === 'r') {
|
51158 | return { original: point, x: rectangle.x + rectangle.width, y: point.y };
|
51159 | }
|
51160 |
|
51161 | if (dockingDirection === 'b') {
|
51162 | return { original: point, x: point.x, y: rectangle.y + rectangle.height };
|
51163 | }
|
51164 |
|
51165 | if (dockingDirection === 'l') {
|
51166 | return { original: point, x: rectangle.x, y: point.y };
|
51167 | }
|
51168 |
|
51169 | throw new Error('unexpected dockingDirection: <' + dockingDirection + '>');
|
51170 | }
|
51171 |
|
51172 |
|
51173 | |
51174 |
|
51175 |
|
51176 |
|
51177 |
|
51178 |
|
51179 |
|
51180 |
|
51181 |
|
51182 |
|
51183 |
|
51184 |
|
51185 |
|
51186 |
|
51187 |
|
51188 |
|
51189 |
|
51190 |
|
51191 |
|
51192 |
|
51193 |
|
51194 | function withoutRedundantPoints(waypoints) {
|
51195 | return waypoints.reduce(function(points, p, idx) {
|
51196 |
|
51197 | var previous = points[points.length - 1],
|
51198 | next = waypoints[idx + 1];
|
51199 |
|
51200 | if (!pointsOnLine(previous, next, p, 0)) {
|
51201 | points.push(p);
|
51202 | }
|
51203 |
|
51204 | return points;
|
51205 | }, []);
|
51206 | }
|
51207 |
|
51208 | var ATTACH_ORIENTATION_PADDING = -10,
|
51209 | BOUNDARY_TO_HOST_THRESHOLD = 40;
|
51210 |
|
51211 | var oppositeOrientationMapping = {
|
51212 | 'top': 'bottom',
|
51213 | 'top-right': 'bottom-left',
|
51214 | 'top-left': 'bottom-right',
|
51215 | 'right': 'left',
|
51216 | 'bottom': 'top',
|
51217 | 'bottom-right': 'top-left',
|
51218 | 'bottom-left': 'top-right',
|
51219 | 'left': 'right'
|
51220 | };
|
51221 |
|
51222 | var orientationDirectionMapping = {
|
51223 | top: 't',
|
51224 | right: 'r',
|
51225 | bottom: 'b',
|
51226 | left: 'l'
|
51227 | };
|
51228 |
|
51229 |
|
51230 | function BpmnLayouter() {}
|
51231 |
|
51232 | inherits_browser(BpmnLayouter, BaseLayouter);
|
51233 |
|
51234 |
|
51235 | BpmnLayouter.prototype.layoutConnection = function(connection, hints) {
|
51236 | if (!hints) {
|
51237 | hints = {};
|
51238 | }
|
51239 |
|
51240 | var source = hints.source || connection.source,
|
51241 | target = hints.target || connection.target,
|
51242 | waypoints = hints.waypoints || connection.waypoints,
|
51243 | connectionStart = hints.connectionStart,
|
51244 | connectionEnd = hints.connectionEnd;
|
51245 |
|
51246 | var manhattanOptions,
|
51247 | updatedWaypoints;
|
51248 |
|
51249 | if (!connectionStart) {
|
51250 | connectionStart = getConnectionDocking(waypoints && waypoints[ 0 ], source);
|
51251 | }
|
51252 |
|
51253 | if (!connectionEnd) {
|
51254 | connectionEnd = getConnectionDocking(waypoints && waypoints[ waypoints.length - 1 ], target);
|
51255 | }
|
51256 |
|
51257 |
|
51258 |
|
51259 |
|
51260 | if (is$1(connection, 'bpmn:Association') ||
|
51261 | is$1(connection, 'bpmn:DataAssociation')) {
|
51262 |
|
51263 | if (waypoints && !isCompensationAssociation(source, target)) {
|
51264 | return [].concat([ connectionStart ], waypoints.slice(1, -1), [ connectionEnd ]);
|
51265 | }
|
51266 | }
|
51267 |
|
51268 | if (is$1(connection, 'bpmn:MessageFlow')) {
|
51269 | manhattanOptions = getMessageFlowManhattanOptions(source, target);
|
51270 | } else if (is$1(connection, 'bpmn:SequenceFlow') || isCompensationAssociation(source, target)) {
|
51271 |
|
51272 |
|
51273 |
|
51274 |
|
51275 |
|
51276 | if (source === target) {
|
51277 | manhattanOptions = {
|
51278 | preferredLayouts: getLoopPreferredLayout(source, connection)
|
51279 | };
|
51280 | } else if (is$1(source, 'bpmn:BoundaryEvent')) {
|
51281 | manhattanOptions = {
|
51282 | preferredLayouts: getBoundaryEventPreferredLayouts(source, target, connectionEnd)
|
51283 | };
|
51284 | } else if (is$1(source, 'bpmn:Gateway')) {
|
51285 | manhattanOptions = {
|
51286 | preferredLayouts: [ 'v:h' ]
|
51287 | };
|
51288 | } else if (is$1(target, 'bpmn:Gateway')) {
|
51289 | manhattanOptions = {
|
51290 | preferredLayouts: [ 'h:v' ]
|
51291 | };
|
51292 | } else {
|
51293 | manhattanOptions = {
|
51294 | preferredLayouts: [ 'h:h' ]
|
51295 | };
|
51296 | }
|
51297 | }
|
51298 |
|
51299 | if (manhattanOptions) {
|
51300 | manhattanOptions = assign(manhattanOptions, hints);
|
51301 |
|
51302 | updatedWaypoints = withoutRedundantPoints(repairConnection(
|
51303 | source,
|
51304 | target,
|
51305 | connectionStart,
|
51306 | connectionEnd,
|
51307 | waypoints,
|
51308 | manhattanOptions
|
51309 | ));
|
51310 | }
|
51311 |
|
51312 | return updatedWaypoints || [ connectionStart, connectionEnd ];
|
51313 | };
|
51314 |
|
51315 |
|
51316 |
|
51317 |
|
51318 | function getAttachOrientation(attachedElement) {
|
51319 | var hostElement = attachedElement.host;
|
51320 |
|
51321 | return getOrientation(getMid(attachedElement), hostElement, ATTACH_ORIENTATION_PADDING);
|
51322 | }
|
51323 |
|
51324 | function getMessageFlowManhattanOptions(source, target) {
|
51325 | return {
|
51326 | preferredLayouts: [ 'straight', 'v:v' ],
|
51327 | preserveDocking: getMessageFlowPreserveDocking(source, target)
|
51328 | };
|
51329 | }
|
51330 |
|
51331 | function getMessageFlowPreserveDocking(source, target) {
|
51332 |
|
51333 |
|
51334 | if (is$1(target, 'bpmn:Participant')) {
|
51335 | return 'source';
|
51336 | }
|
51337 |
|
51338 | if (is$1(source, 'bpmn:Participant')) {
|
51339 | return 'target';
|
51340 | }
|
51341 |
|
51342 |
|
51343 | if (isExpandedSubProcess$1(target)) {
|
51344 | return 'source';
|
51345 | }
|
51346 |
|
51347 | if (isExpandedSubProcess$1(source)) {
|
51348 | return 'target';
|
51349 | }
|
51350 |
|
51351 |
|
51352 | if (is$1(target, 'bpmn:Event')) {
|
51353 | return 'target';
|
51354 | }
|
51355 |
|
51356 | if (is$1(source, 'bpmn:Event')) {
|
51357 | return 'source';
|
51358 | }
|
51359 |
|
51360 | return null;
|
51361 | }
|
51362 |
|
51363 | function getConnectionDocking(point, shape) {
|
51364 | return point ? (point.original || point) : getMid(shape);
|
51365 | }
|
51366 |
|
51367 | function isCompensationAssociation(source, target) {
|
51368 | return is$1(target, 'bpmn:Activity') &&
|
51369 | is$1(source, 'bpmn:BoundaryEvent') &&
|
51370 | target.businessObject.isForCompensation;
|
51371 | }
|
51372 |
|
51373 | function isExpandedSubProcess$1(element) {
|
51374 | return is$1(element, 'bpmn:SubProcess') && isExpanded(element);
|
51375 | }
|
51376 |
|
51377 | function isSame$1(a, b) {
|
51378 | return a === b;
|
51379 | }
|
51380 |
|
51381 | function isAnyOrientation(orientation, orientations) {
|
51382 | return orientations.indexOf(orientation) !== -1;
|
51383 | }
|
51384 |
|
51385 | function getHorizontalOrientation(orientation) {
|
51386 | var matches = /right|left/.exec(orientation);
|
51387 |
|
51388 | return matches && matches[0];
|
51389 | }
|
51390 |
|
51391 | function getVerticalOrientation(orientation) {
|
51392 | var matches = /top|bottom/.exec(orientation);
|
51393 |
|
51394 | return matches && matches[0];
|
51395 | }
|
51396 |
|
51397 | function isOppositeOrientation(a, b) {
|
51398 | return oppositeOrientationMapping[a] === b;
|
51399 | }
|
51400 |
|
51401 | function isOppositeHorizontalOrientation(a, b) {
|
51402 | var horizontalOrientation = getHorizontalOrientation(a);
|
51403 |
|
51404 | var oppositeHorizontalOrientation = oppositeOrientationMapping[horizontalOrientation];
|
51405 |
|
51406 | return b.indexOf(oppositeHorizontalOrientation) !== -1;
|
51407 | }
|
51408 |
|
51409 | function isOppositeVerticalOrientation(a, b) {
|
51410 | var verticalOrientation = getVerticalOrientation(a);
|
51411 |
|
51412 | var oppositeVerticalOrientation = oppositeOrientationMapping[verticalOrientation];
|
51413 |
|
51414 | return b.indexOf(oppositeVerticalOrientation) !== -1;
|
51415 | }
|
51416 |
|
51417 | function isHorizontalOrientation(orientation) {
|
51418 | return orientation === 'right' || orientation === 'left';
|
51419 | }
|
51420 |
|
51421 | function getLoopPreferredLayout(source, connection) {
|
51422 | var waypoints = connection.waypoints;
|
51423 |
|
51424 | var orientation = waypoints && waypoints.length && getOrientation(waypoints[0], source);
|
51425 |
|
51426 | if (orientation === 'top') {
|
51427 | return [ 't:r' ];
|
51428 | } else if (orientation === 'right') {
|
51429 | return [ 'r:b' ];
|
51430 | } else if (orientation === 'left') {
|
51431 | return [ 'l:t' ];
|
51432 | }
|
51433 |
|
51434 | return [ 'b:l' ];
|
51435 | }
|
51436 |
|
51437 | function getBoundaryEventPreferredLayouts(source, target, end) {
|
51438 | var sourceMid = getMid(source),
|
51439 | targetMid = getMid(target),
|
51440 | attachOrientation = getAttachOrientation(source),
|
51441 | sourceLayout,
|
51442 | targetLayout;
|
51443 |
|
51444 | var isLoop = isSame$1(source.host, target);
|
51445 |
|
51446 | var attachedToSide = isAnyOrientation(attachOrientation, [ 'top', 'right', 'bottom', 'left' ]);
|
51447 |
|
51448 | var targetOrientation = getOrientation(targetMid, sourceMid, {
|
51449 | x: source.width / 2 + target.width / 2,
|
51450 | y: source.height / 2 + target.height / 2
|
51451 | });
|
51452 |
|
51453 | if (isLoop) {
|
51454 | return getBoundaryEventLoopLayout(attachOrientation, attachedToSide, source, target, end);
|
51455 | }
|
51456 |
|
51457 |
|
51458 | sourceLayout = getBoundaryEventSourceLayout(attachOrientation, targetOrientation, attachedToSide);
|
51459 |
|
51460 |
|
51461 | targetLayout = getBoundaryEventTargetLayout(attachOrientation, targetOrientation, attachedToSide);
|
51462 |
|
51463 | return [ sourceLayout + ':' + targetLayout ];
|
51464 | }
|
51465 |
|
51466 | function getBoundaryEventLoopLayout(attachOrientation, attachedToSide, source, target, end) {
|
51467 | var orientation = attachedToSide ? attachOrientation : getVerticalOrientation(attachOrientation),
|
51468 | sourceLayout = orientationDirectionMapping[ orientation ],
|
51469 | targetLayout;
|
51470 |
|
51471 | if (attachedToSide) {
|
51472 | if (isHorizontalOrientation(attachOrientation)) {
|
51473 | targetLayout = shouldConnectToSameSide('y', source, target, end) ? 'h' : 'b';
|
51474 | } else {
|
51475 | targetLayout = shouldConnectToSameSide('x', source, target, end) ? 'v' : 'l';
|
51476 | }
|
51477 | } else {
|
51478 | targetLayout = 'v';
|
51479 | }
|
51480 |
|
51481 | return [ sourceLayout + ':' + targetLayout ];
|
51482 | }
|
51483 |
|
51484 | function shouldConnectToSameSide(axis, source, target, end) {
|
51485 | var threshold = BOUNDARY_TO_HOST_THRESHOLD;
|
51486 |
|
51487 | return !(
|
51488 | areCloseOnAxis(axis, end, target, threshold) ||
|
51489 | areCloseOnAxis(axis, end, {
|
51490 | x: target.x + target.width,
|
51491 | y: target.y + target.height
|
51492 | }, threshold) ||
|
51493 | areCloseOnAxis(axis, end, getMid(source), threshold)
|
51494 | );
|
51495 | }
|
51496 |
|
51497 | function areCloseOnAxis(axis, a, b, threshold) {
|
51498 | return Math.abs(a[ axis ] - b[ axis ]) < threshold;
|
51499 | }
|
51500 |
|
51501 | function getBoundaryEventSourceLayout(attachOrientation, targetOrientation, attachedToSide) {
|
51502 |
|
51503 |
|
51504 | if (attachedToSide) {
|
51505 | return orientationDirectionMapping[ attachOrientation ];
|
51506 | }
|
51507 |
|
51508 |
|
51509 |
|
51510 |
|
51511 | if (isSame$1(
|
51512 | getVerticalOrientation(attachOrientation), getVerticalOrientation(targetOrientation)
|
51513 | ) || isOppositeOrientation(
|
51514 | getHorizontalOrientation(attachOrientation), getHorizontalOrientation(targetOrientation)
|
51515 | )) {
|
51516 | return orientationDirectionMapping[ getVerticalOrientation(attachOrientation) ];
|
51517 | }
|
51518 |
|
51519 |
|
51520 | return orientationDirectionMapping[ getHorizontalOrientation(attachOrientation) ];
|
51521 | }
|
51522 |
|
51523 | function getBoundaryEventTargetLayout(attachOrientation, targetOrientation, attachedToSide) {
|
51524 |
|
51525 |
|
51526 | if (attachedToSide) {
|
51527 | if (isHorizontalOrientation(attachOrientation)) {
|
51528 |
|
51529 |
|
51530 |
|
51531 |
|
51532 | if (
|
51533 | isOppositeHorizontalOrientation(attachOrientation, targetOrientation) ||
|
51534 | isSame$1(attachOrientation, targetOrientation)
|
51535 | ) {
|
51536 | return 'h';
|
51537 | }
|
51538 |
|
51539 |
|
51540 | return 'v';
|
51541 | } else {
|
51542 |
|
51543 |
|
51544 |
|
51545 |
|
51546 | if (
|
51547 | isOppositeVerticalOrientation(attachOrientation, targetOrientation) ||
|
51548 | isSame$1(attachOrientation, targetOrientation)
|
51549 | ) {
|
51550 | return 'v';
|
51551 | }
|
51552 |
|
51553 |
|
51554 | return 'h';
|
51555 | }
|
51556 | }
|
51557 |
|
51558 |
|
51559 |
|
51560 |
|
51561 |
|
51562 | if (isHorizontalOrientation(targetOrientation) ||
|
51563 | (isSame$1(getVerticalOrientation(attachOrientation), getVerticalOrientation(targetOrientation)) &&
|
51564 | getHorizontalOrientation(targetOrientation))) {
|
51565 | return 'h';
|
51566 | } else {
|
51567 | return 'v';
|
51568 | }
|
51569 | }
|
51570 |
|
51571 | function dockingToPoint(docking) {
|
51572 |
|
51573 |
|
51574 |
|
51575 | return assign({ original: docking.point.original || docking.point }, docking.actual);
|
51576 | }
|
51577 |
|
51578 |
|
51579 | |
51580 |
|
51581 |
|
51582 |
|
51583 |
|
51584 |
|
51585 | function CroppingConnectionDocking(elementRegistry, graphicsFactory) {
|
51586 | this._elementRegistry = elementRegistry;
|
51587 | this._graphicsFactory = graphicsFactory;
|
51588 | }
|
51589 |
|
51590 | CroppingConnectionDocking.$inject = [ 'elementRegistry', 'graphicsFactory' ];
|
51591 |
|
51592 |
|
51593 | |
51594 |
|
51595 |
|
51596 | CroppingConnectionDocking.prototype.getCroppedWaypoints = function(connection, source, target) {
|
51597 |
|
51598 | source = source || connection.source;
|
51599 | target = target || connection.target;
|
51600 |
|
51601 | var sourceDocking = this.getDockingPoint(connection, source, true),
|
51602 | targetDocking = this.getDockingPoint(connection, target);
|
51603 |
|
51604 | var croppedWaypoints = connection.waypoints.slice(sourceDocking.idx + 1, targetDocking.idx);
|
51605 |
|
51606 | croppedWaypoints.unshift(dockingToPoint(sourceDocking));
|
51607 | croppedWaypoints.push(dockingToPoint(targetDocking));
|
51608 |
|
51609 | return croppedWaypoints;
|
51610 | };
|
51611 |
|
51612 | |
51613 |
|
51614 |
|
51615 |
|
51616 |
|
51617 | CroppingConnectionDocking.prototype.getDockingPoint = function(connection, shape, dockStart) {
|
51618 |
|
51619 | var waypoints = connection.waypoints,
|
51620 | dockingIdx,
|
51621 | dockingPoint,
|
51622 | croppedPoint;
|
51623 |
|
51624 | dockingIdx = dockStart ? 0 : waypoints.length - 1;
|
51625 | dockingPoint = waypoints[dockingIdx];
|
51626 |
|
51627 | croppedPoint = this._getIntersection(shape, connection, dockStart);
|
51628 |
|
51629 | return {
|
51630 | point: dockingPoint,
|
51631 | actual: croppedPoint || dockingPoint,
|
51632 | idx: dockingIdx
|
51633 | };
|
51634 | };
|
51635 |
|
51636 |
|
51637 |
|
51638 |
|
51639 | CroppingConnectionDocking.prototype._getIntersection = function(shape, connection, takeFirst) {
|
51640 |
|
51641 | var shapePath = this._getShapePath(shape),
|
51642 | connectionPath = this._getConnectionPath(connection);
|
51643 |
|
51644 | return getElementLineIntersection(shapePath, connectionPath, takeFirst);
|
51645 | };
|
51646 |
|
51647 | CroppingConnectionDocking.prototype._getConnectionPath = function(connection) {
|
51648 | return this._graphicsFactory.getConnectionPath(connection);
|
51649 | };
|
51650 |
|
51651 | CroppingConnectionDocking.prototype._getShapePath = function(shape) {
|
51652 | return this._graphicsFactory.getShapePath(shape);
|
51653 | };
|
51654 |
|
51655 | CroppingConnectionDocking.prototype._getGfx = function(element) {
|
51656 | return this._elementRegistry.getGraphics(element);
|
51657 | };
|
51658 |
|
51659 | var ModelingModule = {
|
51660 | __init__: [
|
51661 | 'modeling',
|
51662 | 'bpmnUpdater'
|
51663 | ],
|
51664 | __depends__: [
|
51665 | BehaviorModule,
|
51666 | RulesModule$1,
|
51667 | OrderingModule,
|
51668 | ReplaceModule$1,
|
51669 | CommandModule,
|
51670 | TooltipsModule,
|
51671 | LabelSupportModule,
|
51672 | AttachSupportModule,
|
51673 | SelectionModule,
|
51674 | ChangeSupportModule,
|
51675 | SpaceToolModule
|
51676 | ],
|
51677 | bpmnFactory: [ 'type', BpmnFactory ],
|
51678 | bpmnUpdater: [ 'type', BpmnUpdater ],
|
51679 | elementFactory: [ 'type', ElementFactory$1 ],
|
51680 | modeling: [ 'type', Modeling$1 ],
|
51681 | layouter: [ 'type', BpmnLayouter ],
|
51682 | connectionDocking: [ 'type', CroppingConnectionDocking ]
|
51683 | };
|
51684 |
|
51685 | var LOW_PRIORITY$j = 500,
|
51686 | MEDIUM_PRIORITY = 1250,
|
51687 | HIGH_PRIORITY$e = 1500;
|
51688 |
|
51689 | var round$b = Math.round;
|
51690 |
|
51691 | function mid$2(element) {
|
51692 | return {
|
51693 | x: element.x + round$b(element.width / 2),
|
51694 | y: element.y + round$b(element.height / 2)
|
51695 | };
|
51696 | }
|
51697 |
|
51698 | |
51699 |
|
51700 |
|
51701 |
|
51702 |
|
51703 |
|
51704 |
|
51705 |
|
51706 |
|
51707 | function MoveEvents(
|
51708 | eventBus, dragging, modeling,
|
51709 | selection, rules) {
|
51710 |
|
51711 |
|
51712 |
|
51713 | function canMove(shapes, delta, position, target) {
|
51714 |
|
51715 | return rules.allowed('elements.move', {
|
51716 | shapes: shapes,
|
51717 | delta: delta,
|
51718 | position: position,
|
51719 | target: target
|
51720 | });
|
51721 | }
|
51722 |
|
51723 |
|
51724 |
|
51725 |
|
51726 |
|
51727 |
|
51728 |
|
51729 |
|
51730 |
|
51731 |
|
51732 |
|
51733 |
|
51734 |
|
51735 |
|
51736 |
|
51737 | eventBus.on('shape.move.start', HIGH_PRIORITY$e, function(event) {
|
51738 |
|
51739 | var context = event.context,
|
51740 | shape = event.shape,
|
51741 | shapes = selection.get().slice();
|
51742 |
|
51743 |
|
51744 |
|
51745 | if (shapes.indexOf(shape) === -1) {
|
51746 | shapes = [ shape ];
|
51747 | }
|
51748 |
|
51749 |
|
51750 |
|
51751 | shapes = removeNested(shapes);
|
51752 |
|
51753 |
|
51754 | assign(context, {
|
51755 | shapes: shapes,
|
51756 | validatedShapes: shapes,
|
51757 | shape: shape
|
51758 | });
|
51759 | });
|
51760 |
|
51761 |
|
51762 |
|
51763 |
|
51764 |
|
51765 |
|
51766 | eventBus.on('shape.move.start', MEDIUM_PRIORITY, function(event) {
|
51767 |
|
51768 | var context = event.context,
|
51769 | validatedShapes = context.validatedShapes,
|
51770 | canExecute;
|
51771 |
|
51772 | canExecute = context.canExecute = canMove(validatedShapes);
|
51773 |
|
51774 |
|
51775 | if (!canExecute) {
|
51776 | return false;
|
51777 | }
|
51778 | });
|
51779 |
|
51780 |
|
51781 |
|
51782 |
|
51783 |
|
51784 | eventBus.on('shape.move.move', LOW_PRIORITY$j, function(event) {
|
51785 |
|
51786 | var context = event.context,
|
51787 | validatedShapes = context.validatedShapes,
|
51788 | hover = event.hover,
|
51789 | delta = { x: event.dx, y: event.dy },
|
51790 | position = { x: event.x, y: event.y },
|
51791 | canExecute;
|
51792 |
|
51793 |
|
51794 | canExecute = canMove(validatedShapes, delta, position, hover);
|
51795 |
|
51796 | context.delta = delta;
|
51797 | context.canExecute = canExecute;
|
51798 |
|
51799 |
|
51800 | if (canExecute === null) {
|
51801 | context.target = null;
|
51802 |
|
51803 | return;
|
51804 | }
|
51805 |
|
51806 | context.target = hover;
|
51807 | });
|
51808 |
|
51809 | eventBus.on('shape.move.end', function(event) {
|
51810 |
|
51811 | var context = event.context;
|
51812 |
|
51813 | var delta = context.delta,
|
51814 | canExecute = context.canExecute,
|
51815 | isAttach = canExecute === 'attach',
|
51816 | shapes = context.shapes;
|
51817 |
|
51818 | if (canExecute === false) {
|
51819 | return false;
|
51820 | }
|
51821 |
|
51822 |
|
51823 |
|
51824 | delta.x = round$b(delta.x);
|
51825 | delta.y = round$b(delta.y);
|
51826 |
|
51827 | if (delta.x === 0 && delta.y === 0) {
|
51828 |
|
51829 |
|
51830 | return;
|
51831 | }
|
51832 |
|
51833 | modeling.moveElements(shapes, delta, context.target, {
|
51834 | primaryShape: context.shape,
|
51835 | attach: isAttach
|
51836 | });
|
51837 | });
|
51838 |
|
51839 |
|
51840 |
|
51841 |
|
51842 | eventBus.on('element.mousedown', function(event) {
|
51843 |
|
51844 | var originalEvent = getOriginal(event);
|
51845 |
|
51846 | if (!originalEvent) {
|
51847 | throw new Error('must supply DOM mousedown event');
|
51848 | }
|
51849 |
|
51850 | return start(originalEvent, event.element);
|
51851 | });
|
51852 |
|
51853 | |
51854 |
|
51855 |
|
51856 |
|
51857 |
|
51858 |
|
51859 |
|
51860 |
|
51861 | function start(event, element, activate, context) {
|
51862 | if (isObject(activate)) {
|
51863 | context = activate;
|
51864 | activate = false;
|
51865 | }
|
51866 |
|
51867 |
|
51868 | if (element.waypoints || !element.parent) {
|
51869 | return;
|
51870 | }
|
51871 |
|
51872 | var referencePoint = mid$2(element);
|
51873 |
|
51874 | dragging.init(event, referencePoint, 'shape.move', {
|
51875 | cursor: 'grabbing',
|
51876 | autoActivate: activate,
|
51877 | data: {
|
51878 | shape: element,
|
51879 | context: context || {}
|
51880 | }
|
51881 | });
|
51882 |
|
51883 |
|
51884 | return true;
|
51885 | }
|
51886 |
|
51887 |
|
51888 |
|
51889 | this.start = start;
|
51890 | }
|
51891 |
|
51892 | MoveEvents.$inject = [
|
51893 | 'eventBus',
|
51894 | 'dragging',
|
51895 | 'modeling',
|
51896 | 'selection',
|
51897 | 'rules'
|
51898 | ];
|
51899 |
|
51900 |
|
51901 | |
51902 |
|
51903 |
|
51904 |
|
51905 |
|
51906 |
|
51907 |
|
51908 |
|
51909 | function removeNested(elements) {
|
51910 |
|
51911 | var ids = groupBy(elements, 'id');
|
51912 |
|
51913 | return filter(elements, function(element) {
|
51914 | while ((element = element.parent)) {
|
51915 |
|
51916 |
|
51917 | if (ids[element.id]) {
|
51918 | return false;
|
51919 | }
|
51920 | }
|
51921 |
|
51922 | return true;
|
51923 | });
|
51924 | }
|
51925 |
|
51926 | var LOW_PRIORITY$k = 499;
|
51927 |
|
51928 | var MARKER_DRAGGING$1 = 'djs-dragging',
|
51929 | MARKER_OK$3 = 'drop-ok',
|
51930 | MARKER_NOT_OK$3 = 'drop-not-ok',
|
51931 | MARKER_NEW_PARENT$1 = 'new-parent',
|
51932 | MARKER_ATTACH$2 = 'attach-ok';
|
51933 |
|
51934 |
|
51935 | |
51936 |
|
51937 |
|
51938 |
|
51939 |
|
51940 |
|
51941 |
|
51942 |
|
51943 | function MovePreview(
|
51944 | eventBus, canvas, styles, previewSupport) {
|
51945 |
|
51946 | function getVisualDragShapes(shapes) {
|
51947 | var elements = getAllDraggedElements(shapes);
|
51948 |
|
51949 | var filteredElements = removeEdges(elements);
|
51950 |
|
51951 | return filteredElements;
|
51952 | }
|
51953 |
|
51954 | function getAllDraggedElements(shapes) {
|
51955 | var allShapes = selfAndAllChildren(shapes, true);
|
51956 |
|
51957 | var allConnections = map(allShapes, function(shape) {
|
51958 | return (shape.incoming || []).concat(shape.outgoing || []);
|
51959 | });
|
51960 |
|
51961 | return flatten(allShapes.concat(allConnections));
|
51962 | }
|
51963 |
|
51964 | |
51965 |
|
51966 |
|
51967 | function setMarker(element, marker) {
|
51968 |
|
51969 | [ MARKER_ATTACH$2, MARKER_OK$3, MARKER_NOT_OK$3, MARKER_NEW_PARENT$1 ].forEach(function(m) {
|
51970 |
|
51971 | if (m === marker) {
|
51972 | canvas.addMarker(element, m);
|
51973 | } else {
|
51974 | canvas.removeMarker(element, m);
|
51975 | }
|
51976 | });
|
51977 | }
|
51978 |
|
51979 | |
51980 |
|
51981 |
|
51982 |
|
51983 |
|
51984 |
|
51985 |
|
51986 | function makeDraggable(context, element, addMarker) {
|
51987 |
|
51988 | previewSupport.addDragger(element, context.dragGroup);
|
51989 |
|
51990 | if (addMarker) {
|
51991 | canvas.addMarker(element, MARKER_DRAGGING$1);
|
51992 | }
|
51993 |
|
51994 | if (context.allDraggedElements) {
|
51995 | context.allDraggedElements.push(element);
|
51996 | } else {
|
51997 | context.allDraggedElements = [ element ];
|
51998 | }
|
51999 | }
|
52000 |
|
52001 |
|
52002 |
|
52003 |
|
52004 | eventBus.on('shape.move.start', LOW_PRIORITY$k, function(event) {
|
52005 | var context = event.context,
|
52006 | dragShapes = context.shapes,
|
52007 | allDraggedElements = context.allDraggedElements;
|
52008 |
|
52009 | var visuallyDraggedShapes = getVisualDragShapes(dragShapes);
|
52010 |
|
52011 | if (!context.dragGroup) {
|
52012 | var dragGroup = create('g');
|
52013 |
|
52014 | attr$1(dragGroup, styles.cls('djs-drag-group', [ 'no-events' ]));
|
52015 |
|
52016 | var defaultLayer = canvas.getDefaultLayer();
|
52017 |
|
52018 | append(defaultLayer, dragGroup);
|
52019 |
|
52020 | context.dragGroup = dragGroup;
|
52021 | }
|
52022 |
|
52023 |
|
52024 | visuallyDraggedShapes.forEach(function(shape) {
|
52025 | previewSupport.addDragger(shape, context.dragGroup);
|
52026 | });
|
52027 |
|
52028 |
|
52029 |
|
52030 | if (!allDraggedElements) {
|
52031 | allDraggedElements = getAllDraggedElements(dragShapes);
|
52032 | } else {
|
52033 | allDraggedElements = flatten([
|
52034 | allDraggedElements,
|
52035 | getAllDraggedElements(dragShapes)
|
52036 | ]);
|
52037 | }
|
52038 |
|
52039 |
|
52040 | forEach(allDraggedElements, function(e) {
|
52041 | canvas.addMarker(e, MARKER_DRAGGING$1);
|
52042 | });
|
52043 |
|
52044 | context.allDraggedElements = allDraggedElements;
|
52045 |
|
52046 |
|
52047 | context.differentParents = haveDifferentParents(dragShapes);
|
52048 | });
|
52049 |
|
52050 |
|
52051 | eventBus.on('shape.move.move', LOW_PRIORITY$k, function(event) {
|
52052 |
|
52053 | var context = event.context,
|
52054 | dragGroup = context.dragGroup,
|
52055 | target = context.target,
|
52056 | parent = context.shape.parent,
|
52057 | canExecute = context.canExecute;
|
52058 |
|
52059 | if (target) {
|
52060 | if (canExecute === 'attach') {
|
52061 | setMarker(target, MARKER_ATTACH$2);
|
52062 | } else if (context.canExecute && target && target.id !== parent.id) {
|
52063 | setMarker(target, MARKER_NEW_PARENT$1);
|
52064 | } else {
|
52065 | setMarker(target, context.canExecute ? MARKER_OK$3 : MARKER_NOT_OK$3);
|
52066 | }
|
52067 | }
|
52068 |
|
52069 | translate(dragGroup, event.dx, event.dy);
|
52070 | });
|
52071 |
|
52072 | eventBus.on([ 'shape.move.out', 'shape.move.cleanup' ], function(event) {
|
52073 | var context = event.context,
|
52074 | target = context.target;
|
52075 |
|
52076 | if (target) {
|
52077 | setMarker(target, null);
|
52078 | }
|
52079 | });
|
52080 |
|
52081 |
|
52082 | eventBus.on('shape.move.cleanup', function(event) {
|
52083 |
|
52084 | var context = event.context,
|
52085 | allDraggedElements = context.allDraggedElements,
|
52086 | dragGroup = context.dragGroup;
|
52087 |
|
52088 |
|
52089 |
|
52090 | forEach(allDraggedElements, function(e) {
|
52091 | canvas.removeMarker(e, MARKER_DRAGGING$1);
|
52092 | });
|
52093 |
|
52094 | if (dragGroup) {
|
52095 | remove$1(dragGroup);
|
52096 | }
|
52097 | });
|
52098 |
|
52099 |
|
52100 |
|
52101 |
|
52102 | |
52103 |
|
52104 |
|
52105 |
|
52106 |
|
52107 |
|
52108 |
|
52109 | this.makeDraggable = makeDraggable;
|
52110 | }
|
52111 |
|
52112 | MovePreview.$inject = [
|
52113 | 'eventBus',
|
52114 | 'canvas',
|
52115 | 'styles',
|
52116 | 'previewSupport'
|
52117 | ];
|
52118 |
|
52119 |
|
52120 |
|
52121 |
|
52122 | |
52123 |
|
52124 |
|
52125 |
|
52126 | function removeEdges(elements) {
|
52127 |
|
52128 | var filteredElements = filter(elements, function(element) {
|
52129 |
|
52130 | if (!isConnection$7(element)) {
|
52131 | return true;
|
52132 | } else {
|
52133 |
|
52134 | return (
|
52135 | find(elements, matchPattern({ id: element.source.id })) &&
|
52136 | find(elements, matchPattern({ id: element.target.id }))
|
52137 | );
|
52138 | }
|
52139 | });
|
52140 |
|
52141 | return filteredElements;
|
52142 | }
|
52143 |
|
52144 | function haveDifferentParents(elements) {
|
52145 | return size(groupBy(elements, function(e) { return e.parent && e.parent.id; })) !== 1;
|
52146 | }
|
52147 |
|
52148 | |
52149 |
|
52150 |
|
52151 | function isConnection$7(element) {
|
52152 | return element.waypoints;
|
52153 | }
|
52154 |
|
52155 | var MoveModule = {
|
52156 | __depends__: [
|
52157 | InteractionEventsModule,
|
52158 | SelectionModule,
|
52159 | OutlineModule,
|
52160 | RulesModule,
|
52161 | DraggingModule,
|
52162 | PreviewSupportModule
|
52163 | ],
|
52164 | __init__: [
|
52165 | 'move',
|
52166 | 'movePreview'
|
52167 | ],
|
52168 | move: [ 'type', MoveEvents ],
|
52169 | movePreview: [ 'type', MovePreview ]
|
52170 | };
|
52171 |
|
52172 | var TOGGLE_SELECTOR = '.djs-palette-toggle',
|
52173 | ENTRY_SELECTOR = '.entry',
|
52174 | ELEMENT_SELECTOR = TOGGLE_SELECTOR + ', ' + ENTRY_SELECTOR;
|
52175 |
|
52176 | var PALETTE_OPEN_CLS = 'open',
|
52177 | PALETTE_TWO_COLUMN_CLS = 'two-column';
|
52178 |
|
52179 | var DEFAULT_PRIORITY$5 = 1000;
|
52180 |
|
52181 |
|
52182 | |
52183 |
|
52184 |
|
52185 | function Palette(eventBus, canvas) {
|
52186 |
|
52187 | this._eventBus = eventBus;
|
52188 | this._canvas = canvas;
|
52189 |
|
52190 | var self = this;
|
52191 |
|
52192 | eventBus.on('tool-manager.update', function(event) {
|
52193 | var tool = event.tool;
|
52194 |
|
52195 | self.updateToolHighlight(tool);
|
52196 | });
|
52197 |
|
52198 | eventBus.on('i18n.changed', function() {
|
52199 | self._update();
|
52200 | });
|
52201 |
|
52202 | eventBus.on('diagram.init', function() {
|
52203 |
|
52204 | self._diagramInitialized = true;
|
52205 |
|
52206 | self._rebuild();
|
52207 | });
|
52208 | }
|
52209 |
|
52210 | Palette.$inject = [ 'eventBus', 'canvas' ];
|
52211 |
|
52212 |
|
52213 | |
52214 |
|
52215 |
|
52216 |
|
52217 |
|
52218 |
|
52219 |
|
52220 |
|
52221 |
|
52222 |
|
52223 |
|
52224 |
|
52225 |
|
52226 |
|
52227 |
|
52228 |
|
52229 |
|
52230 |
|
52231 |
|
52232 |
|
52233 |
|
52234 |
|
52235 |
|
52236 | Palette.prototype.registerProvider = function(priority, provider) {
|
52237 | if (!provider) {
|
52238 | provider = priority;
|
52239 | priority = DEFAULT_PRIORITY$5;
|
52240 | }
|
52241 |
|
52242 | this._eventBus.on('palette.getProviders', priority, function(event) {
|
52243 | event.providers.push(provider);
|
52244 | });
|
52245 |
|
52246 | this._rebuild();
|
52247 | };
|
52248 |
|
52249 |
|
52250 | |
52251 |
|
52252 |
|
52253 |
|
52254 |
|
52255 | Palette.prototype.getEntries = function() {
|
52256 | var providers = this._getProviders();
|
52257 |
|
52258 | return providers.reduce(addPaletteEntries, {});
|
52259 | };
|
52260 |
|
52261 | Palette.prototype._rebuild = function() {
|
52262 |
|
52263 | if (!this._diagramInitialized) {
|
52264 | return;
|
52265 | }
|
52266 |
|
52267 | var providers = this._getProviders();
|
52268 |
|
52269 | if (!providers.length) {
|
52270 | return;
|
52271 | }
|
52272 |
|
52273 | if (!this._container) {
|
52274 | this._init();
|
52275 | }
|
52276 |
|
52277 | this._update();
|
52278 | };
|
52279 |
|
52280 | |
52281 |
|
52282 |
|
52283 | Palette.prototype._init = function() {
|
52284 |
|
52285 | var self = this;
|
52286 |
|
52287 | var eventBus = this._eventBus;
|
52288 |
|
52289 | var parentContainer = this._getParentContainer();
|
52290 |
|
52291 | var container = this._container = domify(Palette.HTML_MARKUP);
|
52292 |
|
52293 | parentContainer.appendChild(container);
|
52294 |
|
52295 | delegateEvents.bind(container, ELEMENT_SELECTOR, 'click', function(event) {
|
52296 |
|
52297 | var target = event.delegateTarget;
|
52298 |
|
52299 | if (matchesSelector$1(target, TOGGLE_SELECTOR)) {
|
52300 | return self.toggle();
|
52301 | }
|
52302 |
|
52303 | self.trigger('click', event);
|
52304 | });
|
52305 |
|
52306 |
|
52307 | componentEvent.bind(container, 'mousedown', function(event) {
|
52308 | event.stopPropagation();
|
52309 | });
|
52310 |
|
52311 |
|
52312 | delegateEvents.bind(container, ENTRY_SELECTOR, 'dragstart', function(event) {
|
52313 | self.trigger('dragstart', event);
|
52314 | });
|
52315 |
|
52316 | eventBus.on('canvas.resized', this._layoutChanged, this);
|
52317 |
|
52318 | eventBus.fire('palette.create', {
|
52319 | container: container
|
52320 | });
|
52321 | };
|
52322 |
|
52323 | Palette.prototype._getProviders = function(id) {
|
52324 |
|
52325 | var event = this._eventBus.createEvent({
|
52326 | type: 'palette.getProviders',
|
52327 | providers: []
|
52328 | });
|
52329 |
|
52330 | this._eventBus.fire(event);
|
52331 |
|
52332 | return event.providers;
|
52333 | };
|
52334 |
|
52335 | |
52336 |
|
52337 |
|
52338 |
|
52339 |
|
52340 | Palette.prototype._toggleState = function(state) {
|
52341 |
|
52342 | state = state || {};
|
52343 |
|
52344 | var parent = this._getParentContainer(),
|
52345 | container = this._container;
|
52346 |
|
52347 | var eventBus = this._eventBus;
|
52348 |
|
52349 | var twoColumn;
|
52350 |
|
52351 | var cls = classes(container);
|
52352 |
|
52353 | if ('twoColumn' in state) {
|
52354 | twoColumn = state.twoColumn;
|
52355 | } else {
|
52356 | twoColumn = this._needsCollapse(parent.clientHeight, this._entries || {});
|
52357 | }
|
52358 |
|
52359 |
|
52360 | cls.toggle(PALETTE_TWO_COLUMN_CLS, twoColumn);
|
52361 |
|
52362 | if ('open' in state) {
|
52363 | cls.toggle(PALETTE_OPEN_CLS, state.open);
|
52364 | }
|
52365 |
|
52366 | eventBus.fire('palette.changed', {
|
52367 | twoColumn: twoColumn,
|
52368 | open: this.isOpen()
|
52369 | });
|
52370 | };
|
52371 |
|
52372 | Palette.prototype._update = function() {
|
52373 |
|
52374 | var entriesContainer = query('.djs-palette-entries', this._container),
|
52375 | entries = this._entries = this.getEntries();
|
52376 |
|
52377 | clear(entriesContainer);
|
52378 |
|
52379 | forEach(entries, function(entry, id) {
|
52380 |
|
52381 | var grouping = entry.group || 'default';
|
52382 |
|
52383 | var container = query('[data-group=' + grouping + ']', entriesContainer);
|
52384 | if (!container) {
|
52385 | container = domify('<div class="group" data-group="' + grouping + '"></div>');
|
52386 | entriesContainer.appendChild(container);
|
52387 | }
|
52388 |
|
52389 | var html = entry.html || (
|
52390 | entry.separator ?
|
52391 | '<hr class="separator" />' :
|
52392 | '<div class="entry" draggable="true"></div>');
|
52393 |
|
52394 |
|
52395 | var control = domify(html);
|
52396 | container.appendChild(control);
|
52397 |
|
52398 | if (!entry.separator) {
|
52399 | attr(control, 'data-action', id);
|
52400 |
|
52401 | if (entry.title) {
|
52402 | attr(control, 'title', entry.title);
|
52403 | }
|
52404 |
|
52405 | if (entry.className) {
|
52406 | addClasses$1(control, entry.className);
|
52407 | }
|
52408 |
|
52409 | if (entry.imageUrl) {
|
52410 | control.appendChild(domify('<img src="' + entry.imageUrl + '">'));
|
52411 | }
|
52412 | }
|
52413 | });
|
52414 |
|
52415 |
|
52416 | this.open();
|
52417 | };
|
52418 |
|
52419 |
|
52420 | |
52421 |
|
52422 |
|
52423 |
|
52424 |
|
52425 |
|
52426 | Palette.prototype.trigger = function(action, event, autoActivate) {
|
52427 | var entries = this._entries,
|
52428 | entry,
|
52429 | handler,
|
52430 | originalEvent,
|
52431 | button = event.delegateTarget || event.target;
|
52432 |
|
52433 | if (!button) {
|
52434 | return event.preventDefault();
|
52435 | }
|
52436 |
|
52437 | entry = entries[attr(button, 'data-action')];
|
52438 |
|
52439 |
|
52440 | if (!entry) {
|
52441 | return;
|
52442 | }
|
52443 |
|
52444 | handler = entry.action;
|
52445 |
|
52446 | originalEvent = event.originalEvent || event;
|
52447 |
|
52448 |
|
52449 | if (isFunction(handler)) {
|
52450 | if (action === 'click') {
|
52451 | handler(originalEvent, autoActivate);
|
52452 | }
|
52453 | } else {
|
52454 | if (handler[action]) {
|
52455 | handler[action](originalEvent, autoActivate);
|
52456 | }
|
52457 | }
|
52458 |
|
52459 |
|
52460 | event.preventDefault();
|
52461 | };
|
52462 |
|
52463 | Palette.prototype._layoutChanged = function() {
|
52464 | this._toggleState({});
|
52465 | };
|
52466 |
|
52467 | |
52468 |
|
52469 |
|
52470 |
|
52471 |
|
52472 |
|
52473 |
|
52474 |
|
52475 | Palette.prototype._needsCollapse = function(availableHeight, entries) {
|
52476 |
|
52477 |
|
52478 |
|
52479 |
|
52480 | var margin = 20 + 10 + 20;
|
52481 |
|
52482 | var entriesHeight = Object.keys(entries).length * 46;
|
52483 |
|
52484 | return availableHeight < entriesHeight + margin;
|
52485 | };
|
52486 |
|
52487 | |
52488 |
|
52489 |
|
52490 | Palette.prototype.close = function() {
|
52491 |
|
52492 | this._toggleState({
|
52493 | open: false,
|
52494 | twoColumn: false
|
52495 | });
|
52496 | };
|
52497 |
|
52498 |
|
52499 | |
52500 |
|
52501 |
|
52502 | Palette.prototype.open = function() {
|
52503 | this._toggleState({ open: true });
|
52504 | };
|
52505 |
|
52506 |
|
52507 | Palette.prototype.toggle = function(open) {
|
52508 | if (this.isOpen()) {
|
52509 | this.close();
|
52510 | } else {
|
52511 | this.open();
|
52512 | }
|
52513 | };
|
52514 |
|
52515 | Palette.prototype.isActiveTool = function(tool) {
|
52516 | return tool && this._activeTool === tool;
|
52517 | };
|
52518 |
|
52519 | Palette.prototype.updateToolHighlight = function(name) {
|
52520 | var entriesContainer,
|
52521 | toolsContainer;
|
52522 |
|
52523 | if (!this._toolsContainer) {
|
52524 | entriesContainer = query('.djs-palette-entries', this._container);
|
52525 |
|
52526 | this._toolsContainer = query('[data-group=tools]', entriesContainer);
|
52527 | }
|
52528 |
|
52529 | toolsContainer = this._toolsContainer;
|
52530 |
|
52531 | forEach(toolsContainer.children, function(tool) {
|
52532 | var actionName = tool.getAttribute('data-action');
|
52533 |
|
52534 | if (!actionName) {
|
52535 | return;
|
52536 | }
|
52537 |
|
52538 | var toolClasses = classes(tool);
|
52539 |
|
52540 | actionName = actionName.replace('-tool', '');
|
52541 |
|
52542 | if (toolClasses.contains('entry') && actionName === name) {
|
52543 | toolClasses.add('highlighted-entry');
|
52544 | } else {
|
52545 | toolClasses.remove('highlighted-entry');
|
52546 | }
|
52547 | });
|
52548 | };
|
52549 |
|
52550 |
|
52551 | |
52552 |
|
52553 |
|
52554 |
|
52555 |
|
52556 |
|
52557 |
|
52558 |
|
52559 |
|
52560 |
|
52561 |
|
52562 |
|
52563 |
|
52564 | Palette.prototype.isOpen = function() {
|
52565 | return classes(this._container).has(PALETTE_OPEN_CLS);
|
52566 | };
|
52567 |
|
52568 | |
52569 |
|
52570 |
|
52571 |
|
52572 |
|
52573 | Palette.prototype._getParentContainer = function() {
|
52574 | return this._canvas.getContainer();
|
52575 | };
|
52576 |
|
52577 |
|
52578 |
|
52579 |
|
52580 | Palette.HTML_MARKUP =
|
52581 | '<div class="djs-palette">' +
|
52582 | '<div class="djs-palette-entries"></div>' +
|
52583 | '<div class="djs-palette-toggle"></div>' +
|
52584 | '</div>';
|
52585 |
|
52586 |
|
52587 |
|
52588 |
|
52589 | function addClasses$1(element, classNames) {
|
52590 |
|
52591 | var classes$1 = classes(element);
|
52592 |
|
52593 | var actualClassNames = isArray(classNames) ? classNames : classNames.split(/\s+/g);
|
52594 | actualClassNames.forEach(function(cls) {
|
52595 | classes$1.add(cls);
|
52596 | });
|
52597 | }
|
52598 |
|
52599 | function addPaletteEntries(entries, provider) {
|
52600 |
|
52601 | var entriesOrUpdater = provider.getPaletteEntries();
|
52602 |
|
52603 | if (isFunction(entriesOrUpdater)) {
|
52604 | return entriesOrUpdater(entries);
|
52605 | }
|
52606 |
|
52607 | forEach(entriesOrUpdater, function(entry, id) {
|
52608 | entries[id] = entry;
|
52609 | });
|
52610 |
|
52611 | return entries;
|
52612 | }
|
52613 |
|
52614 | var PaletteModule = {
|
52615 | __init__: [ 'palette' ],
|
52616 | palette: [ 'type', Palette ]
|
52617 | };
|
52618 |
|
52619 | var LASSO_TOOL_CURSOR = 'crosshair';
|
52620 |
|
52621 |
|
52622 | function LassoTool(
|
52623 | eventBus, canvas, dragging,
|
52624 | elementRegistry, selection, toolManager) {
|
52625 |
|
52626 | this._selection = selection;
|
52627 | this._dragging = dragging;
|
52628 |
|
52629 | var self = this;
|
52630 |
|
52631 |
|
52632 |
|
52633 | |
52634 |
|
52635 |
|
52636 | var visuals = {
|
52637 |
|
52638 | create: function(context) {
|
52639 | var container = canvas.getDefaultLayer(),
|
52640 | frame;
|
52641 |
|
52642 | frame = context.frame = create('rect');
|
52643 | attr$1(frame, {
|
52644 | class: 'djs-lasso-overlay',
|
52645 | width: 1,
|
52646 | height: 1,
|
52647 | x: 0,
|
52648 | y: 0
|
52649 | });
|
52650 |
|
52651 | append(container, frame);
|
52652 | },
|
52653 |
|
52654 | update: function(context) {
|
52655 | var frame = context.frame,
|
52656 | bbox = context.bbox;
|
52657 |
|
52658 | attr$1(frame, {
|
52659 | x: bbox.x,
|
52660 | y: bbox.y,
|
52661 | width: bbox.width,
|
52662 | height: bbox.height
|
52663 | });
|
52664 | },
|
52665 |
|
52666 | remove: function(context) {
|
52667 |
|
52668 | if (context.frame) {
|
52669 | remove$1(context.frame);
|
52670 | }
|
52671 | }
|
52672 | };
|
52673 |
|
52674 | toolManager.registerTool('lasso', {
|
52675 | tool: 'lasso.selection',
|
52676 | dragging: 'lasso'
|
52677 | });
|
52678 |
|
52679 | eventBus.on('lasso.selection.end', function(event) {
|
52680 | var target = event.originalEvent.target;
|
52681 |
|
52682 |
|
52683 |
|
52684 | if (!event.hover && !(target instanceof SVGElement)) {
|
52685 | return;
|
52686 | }
|
52687 |
|
52688 | eventBus.once('lasso.selection.ended', function() {
|
52689 | self.activateLasso(event.originalEvent, true);
|
52690 | });
|
52691 | });
|
52692 |
|
52693 |
|
52694 |
|
52695 | eventBus.on('lasso.end', function(event) {
|
52696 |
|
52697 | var bbox = toBBox(event);
|
52698 |
|
52699 | var elements = elementRegistry.filter(function(element) {
|
52700 | return element;
|
52701 | });
|
52702 |
|
52703 | self.select(elements, bbox);
|
52704 | });
|
52705 |
|
52706 | eventBus.on('lasso.start', function(event) {
|
52707 |
|
52708 | var context = event.context;
|
52709 |
|
52710 | context.bbox = toBBox(event);
|
52711 | visuals.create(context);
|
52712 | });
|
52713 |
|
52714 | eventBus.on('lasso.move', function(event) {
|
52715 |
|
52716 | var context = event.context;
|
52717 |
|
52718 | context.bbox = toBBox(event);
|
52719 | visuals.update(context);
|
52720 | });
|
52721 |
|
52722 | eventBus.on('lasso.cleanup', function(event) {
|
52723 |
|
52724 | var context = event.context;
|
52725 |
|
52726 | visuals.remove(context);
|
52727 | });
|
52728 |
|
52729 |
|
52730 |
|
52731 |
|
52732 | eventBus.on('element.mousedown', 1500, function(event) {
|
52733 |
|
52734 | if (hasSecondaryModifier(event)) {
|
52735 | self.activateLasso(event.originalEvent);
|
52736 |
|
52737 |
|
52738 | return true;
|
52739 | }
|
52740 | });
|
52741 | }
|
52742 |
|
52743 | LassoTool.$inject = [
|
52744 | 'eventBus',
|
52745 | 'canvas',
|
52746 | 'dragging',
|
52747 | 'elementRegistry',
|
52748 | 'selection',
|
52749 | 'toolManager'
|
52750 | ];
|
52751 |
|
52752 |
|
52753 | LassoTool.prototype.activateLasso = function(event, autoActivate) {
|
52754 |
|
52755 | this._dragging.init(event, 'lasso', {
|
52756 | autoActivate: autoActivate,
|
52757 | cursor: LASSO_TOOL_CURSOR,
|
52758 | data: {
|
52759 | context: {}
|
52760 | }
|
52761 | });
|
52762 | };
|
52763 |
|
52764 | LassoTool.prototype.activateSelection = function(event) {
|
52765 |
|
52766 | this._dragging.init(event, 'lasso.selection', {
|
52767 | trapClick: false,
|
52768 | cursor: LASSO_TOOL_CURSOR,
|
52769 | data: {
|
52770 | context: {}
|
52771 | }
|
52772 | });
|
52773 | };
|
52774 |
|
52775 | LassoTool.prototype.select = function(elements, bbox) {
|
52776 | var selectedElements = getEnclosedElements(elements, bbox);
|
52777 |
|
52778 | this._selection.select(values(selectedElements));
|
52779 | };
|
52780 |
|
52781 | LassoTool.prototype.toggle = function() {
|
52782 | if (this.isActive()) {
|
52783 | this._dragging.cancel();
|
52784 | } else {
|
52785 | this.activateSelection();
|
52786 | }
|
52787 | };
|
52788 |
|
52789 | LassoTool.prototype.isActive = function() {
|
52790 | var context = this._dragging.context();
|
52791 |
|
52792 | return context && /^lasso/.test(context.prefix);
|
52793 | };
|
52794 |
|
52795 |
|
52796 |
|
52797 | function toBBox(event) {
|
52798 |
|
52799 | var start = {
|
52800 |
|
52801 | x: event.x - event.dx,
|
52802 | y: event.y - event.dy
|
52803 | };
|
52804 |
|
52805 | var end = {
|
52806 | x: event.x,
|
52807 | y: event.y
|
52808 | };
|
52809 |
|
52810 | var bbox;
|
52811 |
|
52812 | if ((start.x <= end.x && start.y < end.y) ||
|
52813 | (start.x < end.x && start.y <= end.y)) {
|
52814 |
|
52815 | bbox = {
|
52816 | x: start.x,
|
52817 | y: start.y,
|
52818 | width: end.x - start.x,
|
52819 | height: end.y - start.y
|
52820 | };
|
52821 | } else if ((start.x >= end.x && start.y < end.y) ||
|
52822 | (start.x > end.x && start.y <= end.y)) {
|
52823 |
|
52824 | bbox = {
|
52825 | x: end.x,
|
52826 | y: start.y,
|
52827 | width: start.x - end.x,
|
52828 | height: end.y - start.y
|
52829 | };
|
52830 | } else if ((start.x <= end.x && start.y > end.y) ||
|
52831 | (start.x < end.x && start.y >= end.y)) {
|
52832 |
|
52833 | bbox = {
|
52834 | x: start.x,
|
52835 | y: end.y,
|
52836 | width: end.x - start.x,
|
52837 | height: start.y - end.y
|
52838 | };
|
52839 | } else if ((start.x >= end.x && start.y > end.y) ||
|
52840 | (start.x > end.x && start.y >= end.y)) {
|
52841 |
|
52842 | bbox = {
|
52843 | x: end.x,
|
52844 | y: end.y,
|
52845 | width: start.x - end.x,
|
52846 | height: start.y - end.y
|
52847 | };
|
52848 | } else {
|
52849 |
|
52850 | bbox = {
|
52851 | x: end.x,
|
52852 | y: end.y,
|
52853 | width: 0,
|
52854 | height: 0
|
52855 | };
|
52856 | }
|
52857 | return bbox;
|
52858 | }
|
52859 |
|
52860 | var LassoToolModule = {
|
52861 | __depends__: [
|
52862 | ToolManagerModule
|
52863 | ],
|
52864 | __init__: [ 'lassoTool' ],
|
52865 | lassoTool: [ 'type', LassoTool ]
|
52866 | };
|
52867 |
|
52868 | var HIGH_PRIORITY$f = 1500;
|
52869 | var HAND_CURSOR = 'grab';
|
52870 |
|
52871 |
|
52872 | function HandTool(eventBus, canvas, dragging, injector, toolManager) {
|
52873 | this._dragging = dragging;
|
52874 |
|
52875 | var self = this,
|
52876 | keyboard = injector.get('keyboard', false);
|
52877 |
|
52878 | toolManager.registerTool('hand', {
|
52879 | tool: 'hand',
|
52880 | dragging: 'hand.move'
|
52881 | });
|
52882 |
|
52883 | eventBus.on('element.mousedown', HIGH_PRIORITY$f, function(event) {
|
52884 | if (hasPrimaryModifier(event)) {
|
52885 | this.activateMove(event.originalEvent);
|
52886 |
|
52887 | return false;
|
52888 | }
|
52889 | }, this);
|
52890 |
|
52891 | keyboard && keyboard.addListener(HIGH_PRIORITY$f, function(e) {
|
52892 | if (!isSpace(e.keyEvent)) {
|
52893 | return;
|
52894 | }
|
52895 |
|
52896 | if (self.isActive()) {
|
52897 | return;
|
52898 | }
|
52899 |
|
52900 | function activateMove(event) {
|
52901 | self.activateMove(event);
|
52902 |
|
52903 | window.removeEventListener('mousemove', activateMove);
|
52904 | }
|
52905 |
|
52906 | window.addEventListener('mousemove', activateMove);
|
52907 |
|
52908 | function deactivateMove(e) {
|
52909 | if (!isSpace(e.keyEvent)) {
|
52910 | return;
|
52911 | }
|
52912 |
|
52913 | window.removeEventListener('mousemove', activateMove);
|
52914 |
|
52915 | keyboard.removeListener(deactivateMove, 'keyboard.keyup');
|
52916 |
|
52917 | dragging.cancel();
|
52918 | }
|
52919 |
|
52920 | keyboard.addListener(HIGH_PRIORITY$f, deactivateMove, 'keyboard.keyup');
|
52921 | }, 'keyboard.keydown');
|
52922 |
|
52923 | eventBus.on('hand.end', function(event) {
|
52924 | var target = event.originalEvent.target;
|
52925 |
|
52926 |
|
52927 |
|
52928 | if (!event.hover && !(target instanceof SVGElement)) {
|
52929 | return false;
|
52930 | }
|
52931 |
|
52932 | eventBus.once('hand.ended', function() {
|
52933 | this.activateMove(event.originalEvent, { reactivate: true });
|
52934 | }, this);
|
52935 |
|
52936 | }, this);
|
52937 |
|
52938 |
|
52939 | eventBus.on('hand.move.move', function(event) {
|
52940 | var scale = canvas.viewbox().scale;
|
52941 |
|
52942 | canvas.scroll({
|
52943 | dx: event.dx * scale,
|
52944 | dy: event.dy * scale
|
52945 | });
|
52946 | });
|
52947 |
|
52948 | eventBus.on('hand.move.end', function(event) {
|
52949 | var context = event.context,
|
52950 | reactivate = context.reactivate;
|
52951 |
|
52952 |
|
52953 | if (!hasPrimaryModifier(event) && reactivate) {
|
52954 |
|
52955 | eventBus.once('hand.move.ended', function(event) {
|
52956 | this.activateHand(event.originalEvent, true, true);
|
52957 | }, this);
|
52958 |
|
52959 | }
|
52960 |
|
52961 | return false;
|
52962 | }, this);
|
52963 |
|
52964 | }
|
52965 |
|
52966 | HandTool.$inject = [
|
52967 | 'eventBus',
|
52968 | 'canvas',
|
52969 | 'dragging',
|
52970 | 'injector',
|
52971 | 'toolManager'
|
52972 | ];
|
52973 |
|
52974 |
|
52975 | HandTool.prototype.activateMove = function(event, autoActivate, context) {
|
52976 | if (typeof autoActivate === 'object') {
|
52977 | context = autoActivate;
|
52978 | autoActivate = false;
|
52979 | }
|
52980 |
|
52981 | this._dragging.init(event, 'hand.move', {
|
52982 | autoActivate: autoActivate,
|
52983 | cursor: HAND_CURSOR,
|
52984 | data: {
|
52985 | context: context || {}
|
52986 | }
|
52987 | });
|
52988 | };
|
52989 |
|
52990 | HandTool.prototype.activateHand = function(event, autoActivate, reactivate) {
|
52991 | this._dragging.init(event, 'hand', {
|
52992 | trapClick: false,
|
52993 | autoActivate: autoActivate,
|
52994 | cursor: HAND_CURSOR,
|
52995 | data: {
|
52996 | context: {
|
52997 | reactivate: reactivate
|
52998 | }
|
52999 | }
|
53000 | });
|
53001 | };
|
53002 |
|
53003 | HandTool.prototype.toggle = function() {
|
53004 | if (this.isActive()) {
|
53005 | this._dragging.cancel();
|
53006 | } else {
|
53007 | this.activateHand();
|
53008 | }
|
53009 | };
|
53010 |
|
53011 | HandTool.prototype.isActive = function() {
|
53012 | var context = this._dragging.context();
|
53013 |
|
53014 | if (context) {
|
53015 | return /^(hand|hand\.move)$/.test(context.prefix);
|
53016 | }
|
53017 |
|
53018 | return false;
|
53019 | };
|
53020 |
|
53021 |
|
53022 |
|
53023 | function isSpace(keyEvent) {
|
53024 | return isKey(' ', keyEvent);
|
53025 | }
|
53026 |
|
53027 | var HandToolModule = {
|
53028 | __depends__: [
|
53029 | ToolManagerModule
|
53030 | ],
|
53031 | __init__: [ 'handTool' ],
|
53032 | handTool: [ 'type', HandTool ]
|
53033 | };
|
53034 |
|
53035 | var MARKER_OK$4 = 'connect-ok',
|
53036 | MARKER_NOT_OK$4 = 'connect-not-ok';
|
53037 |
|
53038 | |
53039 |
|
53040 |
|
53041 |
|
53042 |
|
53043 |
|
53044 |
|
53045 |
|
53046 |
|
53047 |
|
53048 |
|
53049 | function GlobalConnect(
|
53050 | eventBus, dragging, connect,
|
53051 | canvas, toolManager, rules) {
|
53052 |
|
53053 | var self = this;
|
53054 |
|
53055 | this._dragging = dragging;
|
53056 | this._rules = rules;
|
53057 |
|
53058 | toolManager.registerTool('global-connect', {
|
53059 | tool: 'global-connect',
|
53060 | dragging: 'global-connect.drag'
|
53061 | });
|
53062 |
|
53063 | eventBus.on('global-connect.hover', function(event) {
|
53064 | var context = event.context,
|
53065 | startTarget = event.hover;
|
53066 |
|
53067 | var canStartConnect = context.canStartConnect = self.canStartConnect(startTarget);
|
53068 |
|
53069 |
|
53070 | if (canStartConnect === null) {
|
53071 | return;
|
53072 | }
|
53073 |
|
53074 | context.startTarget = startTarget;
|
53075 |
|
53076 | canvas.addMarker(startTarget, canStartConnect ? MARKER_OK$4 : MARKER_NOT_OK$4);
|
53077 | });
|
53078 |
|
53079 |
|
53080 | eventBus.on([ 'global-connect.out', 'global-connect.cleanup' ], function(event) {
|
53081 | var startTarget = event.context.startTarget,
|
53082 | canStartConnect = event.context.canStartConnect;
|
53083 |
|
53084 | if (startTarget) {
|
53085 | canvas.removeMarker(startTarget, canStartConnect ? MARKER_OK$4 : MARKER_NOT_OK$4);
|
53086 | }
|
53087 | });
|
53088 |
|
53089 |
|
53090 | eventBus.on([ 'global-connect.ended' ], function(event) {
|
53091 | var context = event.context,
|
53092 | startTarget = context.startTarget,
|
53093 | startPosition = {
|
53094 | x: event.x,
|
53095 | y: event.y
|
53096 | };
|
53097 |
|
53098 | var canStartConnect = self.canStartConnect(startTarget);
|
53099 |
|
53100 | if (!canStartConnect) {
|
53101 | return;
|
53102 | }
|
53103 |
|
53104 | eventBus.once('element.out', function() {
|
53105 | eventBus.once([ 'connect.ended', 'connect.canceled' ], function() {
|
53106 | eventBus.fire('global-connect.drag.ended');
|
53107 | });
|
53108 |
|
53109 | connect.start(null, startTarget, startPosition);
|
53110 | });
|
53111 |
|
53112 | return false;
|
53113 | });
|
53114 | }
|
53115 |
|
53116 | GlobalConnect.$inject = [
|
53117 | 'eventBus',
|
53118 | 'dragging',
|
53119 | 'connect',
|
53120 | 'canvas',
|
53121 | 'toolManager',
|
53122 | 'rules'
|
53123 | ];
|
53124 |
|
53125 | |
53126 |
|
53127 |
|
53128 | GlobalConnect.prototype.start = function(event) {
|
53129 | this._dragging.init(event, 'global-connect', {
|
53130 | trapClick: false,
|
53131 | data: {
|
53132 | context: {}
|
53133 | }
|
53134 | });
|
53135 | };
|
53136 |
|
53137 | GlobalConnect.prototype.toggle = function() {
|
53138 | if (this.isActive()) {
|
53139 | this._dragging.cancel();
|
53140 | } else {
|
53141 | this.start();
|
53142 | }
|
53143 | };
|
53144 |
|
53145 | GlobalConnect.prototype.isActive = function() {
|
53146 | var context = this._dragging.context();
|
53147 |
|
53148 | return context && /^global-connect/.test(context.prefix);
|
53149 | };
|
53150 |
|
53151 | |
53152 |
|
53153 |
|
53154 |
|
53155 |
|
53156 |
|
53157 | GlobalConnect.prototype.canStartConnect = function(startTarget) {
|
53158 | return this._rules.allowed('connection.start', { source: startTarget });
|
53159 | };
|
53160 |
|
53161 | var GlobalConnectModule = {
|
53162 | __depends__: [
|
53163 | ConnectModule,
|
53164 | RulesModule,
|
53165 | DraggingModule,
|
53166 | ToolManagerModule
|
53167 | ],
|
53168 | globalConnect: [ 'type', GlobalConnect ]
|
53169 | };
|
53170 |
|
53171 | |
53172 |
|
53173 |
|
53174 | function PaletteProvider(
|
53175 | palette, create, elementFactory,
|
53176 | spaceTool, lassoTool, handTool,
|
53177 | globalConnect, translate) {
|
53178 |
|
53179 | this._palette = palette;
|
53180 | this._create = create;
|
53181 | this._elementFactory = elementFactory;
|
53182 | this._spaceTool = spaceTool;
|
53183 | this._lassoTool = lassoTool;
|
53184 | this._handTool = handTool;
|
53185 | this._globalConnect = globalConnect;
|
53186 | this._translate = translate;
|
53187 |
|
53188 | palette.registerProvider(this);
|
53189 | }
|
53190 |
|
53191 | PaletteProvider.$inject = [
|
53192 | 'palette',
|
53193 | 'create',
|
53194 | 'elementFactory',
|
53195 | 'spaceTool',
|
53196 | 'lassoTool',
|
53197 | 'handTool',
|
53198 | 'globalConnect',
|
53199 | 'translate'
|
53200 | ];
|
53201 |
|
53202 |
|
53203 | PaletteProvider.prototype.getPaletteEntries = function(element) {
|
53204 |
|
53205 | var actions = {},
|
53206 | create = this._create,
|
53207 | elementFactory = this._elementFactory,
|
53208 | spaceTool = this._spaceTool,
|
53209 | lassoTool = this._lassoTool,
|
53210 | handTool = this._handTool,
|
53211 | globalConnect = this._globalConnect,
|
53212 | translate = this._translate;
|
53213 |
|
53214 | function createAction(type, group, className, title, options) {
|
53215 |
|
53216 | function createListener(event) {
|
53217 | var shape = elementFactory.createShape(assign({ type: type }, options));
|
53218 |
|
53219 | if (options) {
|
53220 | shape.businessObject.di.isExpanded = options.isExpanded;
|
53221 | }
|
53222 |
|
53223 | create.start(event, shape);
|
53224 | }
|
53225 |
|
53226 | var shortType = type.replace(/^bpmn:/, '');
|
53227 |
|
53228 | return {
|
53229 | group: group,
|
53230 | className: className,
|
53231 | title: title || translate('Create {type}', { type: shortType }),
|
53232 | action: {
|
53233 | dragstart: createListener,
|
53234 | click: createListener
|
53235 | }
|
53236 | };
|
53237 | }
|
53238 |
|
53239 | function createSubprocess(event) {
|
53240 | var subProcess = elementFactory.createShape({
|
53241 | type: 'bpmn:SubProcess',
|
53242 | x: 0,
|
53243 | y: 0,
|
53244 | isExpanded: true
|
53245 | });
|
53246 |
|
53247 | var startEvent = elementFactory.createShape({
|
53248 | type: 'bpmn:StartEvent',
|
53249 | x: 40,
|
53250 | y: 82,
|
53251 | parent: subProcess
|
53252 | });
|
53253 |
|
53254 | create.start(event, [ subProcess, startEvent ], {
|
53255 | hints: {
|
53256 | autoSelect: [ startEvent ]
|
53257 | }
|
53258 | });
|
53259 | }
|
53260 |
|
53261 | function createParticipant(event) {
|
53262 | create.start(event, elementFactory.createParticipantShape());
|
53263 | }
|
53264 |
|
53265 | assign(actions, {
|
53266 | 'hand-tool': {
|
53267 | group: 'tools',
|
53268 | className: 'bpmn-icon-hand-tool',
|
53269 | title: translate('Activate the hand tool'),
|
53270 | action: {
|
53271 | click: function(event) {
|
53272 | handTool.activateHand(event);
|
53273 | }
|
53274 | }
|
53275 | },
|
53276 | 'lasso-tool': {
|
53277 | group: 'tools',
|
53278 | className: 'bpmn-icon-lasso-tool',
|
53279 | title: translate('Activate the lasso tool'),
|
53280 | action: {
|
53281 | click: function(event) {
|
53282 | lassoTool.activateSelection(event);
|
53283 | }
|
53284 | }
|
53285 | },
|
53286 | 'space-tool': {
|
53287 | group: 'tools',
|
53288 | className: 'bpmn-icon-space-tool',
|
53289 | title: translate('Activate the create/remove space tool'),
|
53290 | action: {
|
53291 | click: function(event) {
|
53292 | spaceTool.activateSelection(event);
|
53293 | }
|
53294 | }
|
53295 | },
|
53296 | 'global-connect-tool': {
|
53297 | group: 'tools',
|
53298 | className: 'bpmn-icon-connection-multi',
|
53299 | title: translate('Activate the global connect tool'),
|
53300 | action: {
|
53301 | click: function(event) {
|
53302 | globalConnect.toggle(event);
|
53303 | }
|
53304 | }
|
53305 | },
|
53306 | 'tool-separator': {
|
53307 | group: 'tools',
|
53308 | separator: true
|
53309 | },
|
53310 | 'create.start-event': createAction(
|
53311 | 'bpmn:StartEvent', 'event', 'bpmn-icon-start-event-none',
|
53312 | translate('Create StartEvent')
|
53313 | ),
|
53314 | 'create.intermediate-event': createAction(
|
53315 | 'bpmn:IntermediateThrowEvent', 'event', 'bpmn-icon-intermediate-event-none',
|
53316 | translate('Create Intermediate/Boundary Event')
|
53317 | ),
|
53318 | 'create.end-event': createAction(
|
53319 | 'bpmn:EndEvent', 'event', 'bpmn-icon-end-event-none',
|
53320 | translate('Create EndEvent')
|
53321 | ),
|
53322 | 'create.exclusive-gateway': createAction(
|
53323 | 'bpmn:ExclusiveGateway', 'gateway', 'bpmn-icon-gateway-none',
|
53324 | translate('Create Gateway')
|
53325 | ),
|
53326 | 'create.task': createAction(
|
53327 | 'bpmn:Task', 'activity', 'bpmn-icon-task',
|
53328 | translate('Create Task')
|
53329 | ),
|
53330 | 'create.data-object': createAction(
|
53331 | 'bpmn:DataObjectReference', 'data-object', 'bpmn-icon-data-object',
|
53332 | translate('Create DataObjectReference')
|
53333 | ),
|
53334 | 'create.data-store': createAction(
|
53335 | 'bpmn:DataStoreReference', 'data-store', 'bpmn-icon-data-store',
|
53336 | translate('Create DataStoreReference')
|
53337 | ),
|
53338 | 'create.subprocess-expanded': {
|
53339 | group: 'activity',
|
53340 | className: 'bpmn-icon-subprocess-expanded',
|
53341 | title: translate('Create expanded SubProcess'),
|
53342 | action: {
|
53343 | dragstart: createSubprocess,
|
53344 | click: createSubprocess
|
53345 | }
|
53346 | },
|
53347 | 'create.participant-expanded': {
|
53348 | group: 'collaboration',
|
53349 | className: 'bpmn-icon-participant',
|
53350 | title: translate('Create Pool/Participant'),
|
53351 | action: {
|
53352 | dragstart: createParticipant,
|
53353 | click: createParticipant
|
53354 | }
|
53355 | },
|
53356 | 'create.group': createAction(
|
53357 | 'bpmn:Group', 'artifact', 'bpmn-icon-group',
|
53358 | translate('Create Group')
|
53359 | ),
|
53360 | });
|
53361 |
|
53362 | return actions;
|
53363 | };
|
53364 |
|
53365 | var PaletteModule$1 = {
|
53366 | __depends__: [
|
53367 | PaletteModule,
|
53368 | CreateModule,
|
53369 | SpaceToolModule,
|
53370 | LassoToolModule,
|
53371 | HandToolModule,
|
53372 | GlobalConnectModule,
|
53373 | translate$2
|
53374 | ],
|
53375 | __init__: [ 'paletteProvider' ],
|
53376 | paletteProvider: [ 'type', PaletteProvider ]
|
53377 | };
|
53378 |
|
53379 | var LOW_PRIORITY$l = 250;
|
53380 |
|
53381 |
|
53382 | function BpmnReplacePreview(
|
53383 | eventBus, elementRegistry, elementFactory,
|
53384 | canvas, previewSupport) {
|
53385 |
|
53386 | CommandInterceptor.call(this, eventBus);
|
53387 |
|
53388 | |
53389 |
|
53390 |
|
53391 |
|
53392 |
|
53393 | function replaceVisual(context) {
|
53394 |
|
53395 | var replacements = context.canExecute.replacements;
|
53396 |
|
53397 | forEach(replacements, function(replacement) {
|
53398 |
|
53399 | var id = replacement.oldElementId;
|
53400 |
|
53401 | var newElement = {
|
53402 | type: replacement.newElementType
|
53403 | };
|
53404 |
|
53405 |
|
53406 | if (context.visualReplacements[id]) {
|
53407 | return;
|
53408 | }
|
53409 |
|
53410 | var element = elementRegistry.get(id);
|
53411 |
|
53412 | assign(newElement, { x: element.x, y: element.y });
|
53413 |
|
53414 |
|
53415 | var tempShape = elementFactory.createShape(newElement);
|
53416 |
|
53417 | canvas.addShape(tempShape, element.parent);
|
53418 |
|
53419 |
|
53420 | var gfx = query('[data-element-id="' + css_escape(element.id) + '"]', context.dragGroup);
|
53421 |
|
53422 | if (gfx) {
|
53423 | attr$1(gfx, { display: 'none' });
|
53424 | }
|
53425 |
|
53426 |
|
53427 | var dragger = previewSupport.addDragger(tempShape, context.dragGroup);
|
53428 |
|
53429 | context.visualReplacements[id] = dragger;
|
53430 |
|
53431 | canvas.removeShape(tempShape);
|
53432 | });
|
53433 | }
|
53434 |
|
53435 | |
53436 |
|
53437 |
|
53438 |
|
53439 |
|
53440 | function restoreVisual(context) {
|
53441 |
|
53442 | var visualReplacements = context.visualReplacements;
|
53443 |
|
53444 | forEach(visualReplacements, function(dragger, id) {
|
53445 |
|
53446 | var originalGfx = query('[data-element-id="' + css_escape(id) + '"]', context.dragGroup);
|
53447 |
|
53448 | if (originalGfx) {
|
53449 | attr$1(originalGfx, { display: 'inline' });
|
53450 | }
|
53451 |
|
53452 | dragger.remove();
|
53453 |
|
53454 | if (visualReplacements[id]) {
|
53455 | delete visualReplacements[id];
|
53456 | }
|
53457 | });
|
53458 | }
|
53459 |
|
53460 | eventBus.on('shape.move.move', LOW_PRIORITY$l, function(event) {
|
53461 |
|
53462 | var context = event.context,
|
53463 | canExecute = context.canExecute;
|
53464 |
|
53465 | if (!context.visualReplacements) {
|
53466 | context.visualReplacements = {};
|
53467 | }
|
53468 |
|
53469 | if (canExecute && canExecute.replacements) {
|
53470 | replaceVisual(context);
|
53471 | } else {
|
53472 | restoreVisual(context);
|
53473 | }
|
53474 | });
|
53475 | }
|
53476 |
|
53477 | BpmnReplacePreview.$inject = [
|
53478 | 'eventBus',
|
53479 | 'elementRegistry',
|
53480 | 'elementFactory',
|
53481 | 'canvas',
|
53482 | 'previewSupport'
|
53483 | ];
|
53484 |
|
53485 | inherits_browser(BpmnReplacePreview, CommandInterceptor);
|
53486 |
|
53487 | var ReplacePreviewModule = {
|
53488 | __depends__: [
|
53489 | PreviewSupportModule
|
53490 | ],
|
53491 | __init__: [ 'bpmnReplacePreview' ],
|
53492 | bpmnReplacePreview: [ 'type', BpmnReplacePreview ]
|
53493 | };
|
53494 |
|
53495 | var HIGHER_PRIORITY$2 = 1250;
|
53496 |
|
53497 | var BOUNDARY_TO_HOST_THRESHOLD$1 = 40;
|
53498 |
|
53499 | var TARGET_BOUNDS_PADDING = 20,
|
53500 | TASK_BOUNDS_PADDING = 10;
|
53501 |
|
53502 | var TARGET_CENTER_PADDING = 20;
|
53503 |
|
53504 | var AXES = [ 'x', 'y' ];
|
53505 |
|
53506 | var abs$7 = Math.abs;
|
53507 |
|
53508 | |
53509 |
|
53510 |
|
53511 |
|
53512 |
|
53513 | function BpmnConnectSnapping(eventBus) {
|
53514 | eventBus.on([
|
53515 | 'connect.hover',
|
53516 | 'connect.move',
|
53517 | 'connect.end',
|
53518 | ], HIGHER_PRIORITY$2, function(event) {
|
53519 | var context = event.context,
|
53520 | canExecute = context.canExecute,
|
53521 | start = context.start,
|
53522 | hover = context.hover,
|
53523 | source = context.source,
|
53524 | target = context.target;
|
53525 |
|
53526 |
|
53527 | if (event.originalEvent && isCmd(event.originalEvent)) {
|
53528 | return;
|
53529 | }
|
53530 |
|
53531 | if (!context.initialConnectionStart) {
|
53532 | context.initialConnectionStart = context.connectionStart;
|
53533 | }
|
53534 |
|
53535 |
|
53536 | if (canExecute && hover) {
|
53537 | snapToShape(event, hover, getTargetBoundsPadding(hover));
|
53538 | }
|
53539 |
|
53540 | if (hover && isAnyType(canExecute, [
|
53541 | 'bpmn:Association',
|
53542 | 'bpmn:DataInputAssociation',
|
53543 | 'bpmn:DataOutputAssociation',
|
53544 | 'bpmn:SequenceFlow'
|
53545 | ])) {
|
53546 | context.connectionStart = mid(start);
|
53547 |
|
53548 |
|
53549 | if (isAny(hover, [ 'bpmn:Event', 'bpmn:Gateway' ])) {
|
53550 | snapToPosition(event, mid(hover));
|
53551 | }
|
53552 |
|
53553 |
|
53554 | if (isAny(hover, [ 'bpmn:Task', 'bpmn:SubProcess' ])) {
|
53555 | snapToTargetMid(event, hover);
|
53556 | }
|
53557 |
|
53558 |
|
53559 | if (is$1(source, 'bpmn:BoundaryEvent') && target === source.host) {
|
53560 | snapBoundaryEventLoop(event);
|
53561 | }
|
53562 |
|
53563 | } else if (isType(canExecute, 'bpmn:MessageFlow')) {
|
53564 |
|
53565 | if (is$1(start, 'bpmn:Event')) {
|
53566 |
|
53567 |
|
53568 | context.connectionStart = mid(start);
|
53569 | }
|
53570 |
|
53571 | if (is$1(hover, 'bpmn:Event')) {
|
53572 |
|
53573 |
|
53574 | snapToPosition(event, mid(hover));
|
53575 | }
|
53576 |
|
53577 | } else {
|
53578 |
|
53579 |
|
53580 | context.connectionStart = context.initialConnectionStart;
|
53581 | }
|
53582 | });
|
53583 | }
|
53584 |
|
53585 | BpmnConnectSnapping.$inject = [ 'eventBus' ];
|
53586 |
|
53587 |
|
53588 |
|
53589 |
|
53590 |
|
53591 | function snapToShape(event, target, padding) {
|
53592 | AXES.forEach(function(axis) {
|
53593 | var dimensionForAxis = getDimensionForAxis(axis, target);
|
53594 |
|
53595 | if (event[ axis ] < target[ axis ] + padding) {
|
53596 | setSnapped(event, axis, target[ axis ] + padding);
|
53597 | } else if (event[ axis ] > target[ axis ] + dimensionForAxis - padding) {
|
53598 | setSnapped(event, axis, target[ axis ] + dimensionForAxis - padding);
|
53599 | }
|
53600 | });
|
53601 | }
|
53602 |
|
53603 |
|
53604 | function snapToTargetMid(event, target) {
|
53605 | var targetMid = mid(target);
|
53606 |
|
53607 | AXES.forEach(function(axis) {
|
53608 | if (isMid(event, target, axis)) {
|
53609 | setSnapped(event, axis, targetMid[ axis ]);
|
53610 | }
|
53611 | });
|
53612 | }
|
53613 |
|
53614 |
|
53615 | function snapBoundaryEventLoop(event) {
|
53616 | var context = event.context,
|
53617 | source = context.source,
|
53618 | target = context.target;
|
53619 |
|
53620 | if (isReverse$2(context)) {
|
53621 | return;
|
53622 | }
|
53623 |
|
53624 | var sourceMid = mid(source),
|
53625 | orientation = getOrientation(sourceMid, target, -10),
|
53626 | axes = [];
|
53627 |
|
53628 | if (/top|bottom/.test(orientation)) {
|
53629 | axes.push('x');
|
53630 | }
|
53631 |
|
53632 | if (/left|right/.test(orientation)) {
|
53633 | axes.push('y');
|
53634 | }
|
53635 |
|
53636 | axes.forEach(function(axis) {
|
53637 | var coordinate = event[ axis ], newCoordinate;
|
53638 |
|
53639 | if (abs$7(coordinate - sourceMid[ axis ]) < BOUNDARY_TO_HOST_THRESHOLD$1) {
|
53640 | if (coordinate > sourceMid[ axis ]) {
|
53641 | newCoordinate = sourceMid[ axis ] + BOUNDARY_TO_HOST_THRESHOLD$1;
|
53642 | }
|
53643 | else {
|
53644 | newCoordinate = sourceMid[ axis ] - BOUNDARY_TO_HOST_THRESHOLD$1;
|
53645 | }
|
53646 |
|
53647 | setSnapped(event, axis, newCoordinate);
|
53648 | }
|
53649 | });
|
53650 | }
|
53651 |
|
53652 | function snapToPosition(event, position) {
|
53653 | setSnapped(event, 'x', position.x);
|
53654 | setSnapped(event, 'y', position.y);
|
53655 | }
|
53656 |
|
53657 | function isType(attrs, type) {
|
53658 | return attrs && attrs.type === type;
|
53659 | }
|
53660 |
|
53661 | function isAnyType(attrs, types) {
|
53662 | return some(types, function(type) {
|
53663 | return isType(attrs, type);
|
53664 | });
|
53665 | }
|
53666 |
|
53667 | function getDimensionForAxis(axis, element) {
|
53668 | return axis === 'x' ? element.width : element.height;
|
53669 | }
|
53670 |
|
53671 | function getTargetBoundsPadding(target) {
|
53672 | if (is$1(target, 'bpmn:Task')) {
|
53673 | return TASK_BOUNDS_PADDING;
|
53674 | } else {
|
53675 | return TARGET_BOUNDS_PADDING;
|
53676 | }
|
53677 | }
|
53678 |
|
53679 | function isMid(event, target, axis) {
|
53680 | return event[ axis ] > target[ axis ] + TARGET_CENTER_PADDING
|
53681 | && event[ axis ] < target[ axis ] + getDimensionForAxis(axis, target) - TARGET_CENTER_PADDING;
|
53682 | }
|
53683 |
|
53684 | function isReverse$2(context) {
|
53685 | var hover = context.hover,
|
53686 | source = context.source;
|
53687 |
|
53688 | return hover && source && hover === source;
|
53689 | }
|
53690 |
|
53691 | |
53692 |
|
53693 |
|
53694 |
|
53695 |
|
53696 | function SnapContext() {
|
53697 |
|
53698 | |
53699 |
|
53700 |
|
53701 |
|
53702 |
|
53703 |
|
53704 | this._targets = {};
|
53705 |
|
53706 | |
53707 |
|
53708 |
|
53709 |
|
53710 |
|
53711 |
|
53712 | this._snapOrigins = {};
|
53713 |
|
53714 | |
53715 |
|
53716 |
|
53717 |
|
53718 |
|
53719 | this._snapLocations = [];
|
53720 |
|
53721 | |
53722 |
|
53723 |
|
53724 |
|
53725 |
|
53726 | this._defaultSnaps = {};
|
53727 | }
|
53728 |
|
53729 |
|
53730 | SnapContext.prototype.getSnapOrigin = function(snapLocation) {
|
53731 | return this._snapOrigins[snapLocation];
|
53732 | };
|
53733 |
|
53734 |
|
53735 | SnapContext.prototype.setSnapOrigin = function(snapLocation, initialValue) {
|
53736 | this._snapOrigins[snapLocation] = initialValue;
|
53737 |
|
53738 | if (this._snapLocations.indexOf(snapLocation) === -1) {
|
53739 | this._snapLocations.push(snapLocation);
|
53740 | }
|
53741 | };
|
53742 |
|
53743 |
|
53744 | SnapContext.prototype.addDefaultSnap = function(type, point) {
|
53745 |
|
53746 | var snapValues = this._defaultSnaps[type];
|
53747 |
|
53748 | if (!snapValues) {
|
53749 | snapValues = this._defaultSnaps[type] = [];
|
53750 | }
|
53751 |
|
53752 | snapValues.push(point);
|
53753 | };
|
53754 |
|
53755 | |
53756 |
|
53757 |
|
53758 |
|
53759 |
|
53760 |
|
53761 | SnapContext.prototype.getSnapLocations = function() {
|
53762 | return this._snapLocations;
|
53763 | };
|
53764 |
|
53765 | |
53766 |
|
53767 |
|
53768 |
|
53769 |
|
53770 |
|
53771 |
|
53772 | SnapContext.prototype.setSnapLocations = function(snapLocations) {
|
53773 | this._snapLocations = snapLocations;
|
53774 | };
|
53775 |
|
53776 | |
53777 |
|
53778 |
|
53779 |
|
53780 |
|
53781 | SnapContext.prototype.pointsForTarget = function(target) {
|
53782 |
|
53783 | var targetId = target.id || target;
|
53784 |
|
53785 | var snapPoints = this._targets[targetId];
|
53786 |
|
53787 | if (!snapPoints) {
|
53788 | snapPoints = this._targets[targetId] = new SnapPoints();
|
53789 | snapPoints.initDefaults(this._defaultSnaps);
|
53790 | }
|
53791 |
|
53792 | return snapPoints;
|
53793 | };
|
53794 |
|
53795 |
|
53796 | |
53797 |
|
53798 |
|
53799 |
|
53800 |
|
53801 |
|
53802 | function SnapPoints(defaultSnaps) {
|
53803 |
|
53804 | |
53805 |
|
53806 |
|
53807 |
|
53808 |
|
53809 |
|
53810 | this._snapValues = {};
|
53811 | }
|
53812 |
|
53813 | SnapPoints.prototype.add = function(snapLocation, point) {
|
53814 |
|
53815 | var snapValues = this._snapValues[snapLocation];
|
53816 |
|
53817 | if (!snapValues) {
|
53818 | snapValues = this._snapValues[snapLocation] = { x: [], y: [] };
|
53819 | }
|
53820 |
|
53821 | if (snapValues.x.indexOf(point.x) === -1) {
|
53822 | snapValues.x.push(point.x);
|
53823 | }
|
53824 |
|
53825 | if (snapValues.y.indexOf(point.y) === -1) {
|
53826 | snapValues.y.push(point.y);
|
53827 | }
|
53828 | };
|
53829 |
|
53830 |
|
53831 | SnapPoints.prototype.snap = function(point, snapLocation, axis, tolerance) {
|
53832 | var snappingValues = this._snapValues[snapLocation];
|
53833 |
|
53834 | return snappingValues && snapTo(point[axis], snappingValues[axis], tolerance);
|
53835 | };
|
53836 |
|
53837 | |
53838 |
|
53839 |
|
53840 |
|
53841 |
|
53842 | SnapPoints.prototype.initDefaults = function(defaultSnaps) {
|
53843 |
|
53844 | var self = this;
|
53845 |
|
53846 | forEach(defaultSnaps || {}, function(snapPoints, snapLocation) {
|
53847 | forEach(snapPoints, function(point) {
|
53848 | self.add(snapLocation, point);
|
53849 | });
|
53850 | });
|
53851 | };
|
53852 |
|
53853 | var HIGHER_PRIORITY$3 = 1250;
|
53854 |
|
53855 |
|
53856 | |
53857 |
|
53858 |
|
53859 |
|
53860 |
|
53861 |
|
53862 |
|
53863 | function CreateMoveSnapping(elementRegistry, eventBus, snapping) {
|
53864 | var self = this;
|
53865 |
|
53866 | this._elementRegistry = elementRegistry;
|
53867 |
|
53868 | eventBus.on([
|
53869 | 'create.start',
|
53870 | 'shape.move.start'
|
53871 | ], function(event) {
|
53872 | self.initSnap(event);
|
53873 | });
|
53874 |
|
53875 | eventBus.on([
|
53876 | 'create.move',
|
53877 | 'create.end',
|
53878 | 'shape.move.move',
|
53879 | 'shape.move.end'
|
53880 | ], HIGHER_PRIORITY$3, function(event) {
|
53881 | var context = event.context,
|
53882 | shape = context.shape,
|
53883 | snapContext = context.snapContext,
|
53884 | target = context.target;
|
53885 |
|
53886 | if (event.originalEvent && isCmd(event.originalEvent)) {
|
53887 | return;
|
53888 | }
|
53889 |
|
53890 | if (isSnapped(event) || !target) {
|
53891 | return;
|
53892 | }
|
53893 |
|
53894 | var snapPoints = snapContext.pointsForTarget(target);
|
53895 |
|
53896 | if (!snapPoints.initialized) {
|
53897 | snapPoints = self.addSnapTargetPoints(snapPoints, shape, target);
|
53898 |
|
53899 | snapPoints.initialized = true;
|
53900 | }
|
53901 |
|
53902 | snapping.snap(event, snapPoints);
|
53903 | });
|
53904 |
|
53905 | eventBus.on([
|
53906 | 'create.cleanup',
|
53907 | 'shape.move.cleanup'
|
53908 | ], function() {
|
53909 | snapping.hide();
|
53910 | });
|
53911 | }
|
53912 |
|
53913 | CreateMoveSnapping.$inject = [
|
53914 | 'elementRegistry',
|
53915 | 'eventBus',
|
53916 | 'snapping'
|
53917 | ];
|
53918 |
|
53919 | CreateMoveSnapping.prototype.initSnap = function(event) {
|
53920 | var elementRegistry = this._elementRegistry;
|
53921 |
|
53922 | var context = event.context,
|
53923 | shape = context.shape,
|
53924 | snapContext = context.snapContext;
|
53925 |
|
53926 | if (!snapContext) {
|
53927 | snapContext = context.snapContext = new SnapContext();
|
53928 | }
|
53929 |
|
53930 | var shapeMid;
|
53931 |
|
53932 | if (elementRegistry.get(shape.id)) {
|
53933 |
|
53934 |
|
53935 | shapeMid = mid(shape, event);
|
53936 | } else {
|
53937 |
|
53938 |
|
53939 | shapeMid = {
|
53940 | x: event.x + mid(shape).x,
|
53941 | y: event.y + mid(shape).y
|
53942 | };
|
53943 | }
|
53944 |
|
53945 | var shapeTopLeft = {
|
53946 | x: shapeMid.x - shape.width / 2,
|
53947 | y: shapeMid.y - shape.height / 2
|
53948 | },
|
53949 | shapeBottomRight = {
|
53950 | x: shapeMid.x + shape.width / 2,
|
53951 | y: shapeMid.y + shape.height / 2
|
53952 | };
|
53953 |
|
53954 | snapContext.setSnapOrigin('mid', {
|
53955 | x: shapeMid.x - event.x,
|
53956 | y: shapeMid.y - event.y
|
53957 | });
|
53958 |
|
53959 |
|
53960 | if (isLabel$4(shape)) {
|
53961 | return snapContext;
|
53962 | }
|
53963 |
|
53964 | snapContext.setSnapOrigin('top-left', {
|
53965 | x: shapeTopLeft.x - event.x,
|
53966 | y: shapeTopLeft.y - event.y
|
53967 | });
|
53968 |
|
53969 | snapContext.setSnapOrigin('bottom-right', {
|
53970 | x: shapeBottomRight.x - event.x,
|
53971 | y: shapeBottomRight.y - event.y
|
53972 | });
|
53973 |
|
53974 | return snapContext;
|
53975 | };
|
53976 |
|
53977 | CreateMoveSnapping.prototype.addSnapTargetPoints = function(snapPoints, shape, target) {
|
53978 | var snapTargets = this.getSnapTargets(shape, target);
|
53979 |
|
53980 | forEach(snapTargets, function(snapTarget) {
|
53981 |
|
53982 |
|
53983 | if (isLabel$4(snapTarget)) {
|
53984 |
|
53985 | if (isLabel$4(shape)) {
|
53986 | snapPoints.add('mid', mid(snapTarget));
|
53987 | }
|
53988 |
|
53989 | return;
|
53990 | }
|
53991 |
|
53992 |
|
53993 | if (isConnection$8(snapTarget)) {
|
53994 |
|
53995 |
|
53996 | if (snapTarget.waypoints.length < 3) {
|
53997 | return;
|
53998 | }
|
53999 |
|
54000 |
|
54001 | var waypoints = snapTarget.waypoints.slice(1, -1);
|
54002 |
|
54003 | forEach(waypoints, function(waypoint) {
|
54004 | snapPoints.add('mid', waypoint);
|
54005 | });
|
54006 |
|
54007 | return;
|
54008 | }
|
54009 |
|
54010 |
|
54011 | snapPoints.add('mid', mid(snapTarget));
|
54012 | });
|
54013 |
|
54014 | if (!isNumber(shape.x) || !isNumber(shape.y)) {
|
54015 | return snapPoints;
|
54016 | }
|
54017 |
|
54018 |
|
54019 | if (this._elementRegistry.get(shape.id)) {
|
54020 | snapPoints.add('mid', mid(shape));
|
54021 | }
|
54022 |
|
54023 | return snapPoints;
|
54024 | };
|
54025 |
|
54026 | CreateMoveSnapping.prototype.getSnapTargets = function(shape, target) {
|
54027 | return getChildren$1(target).filter(function(child) {
|
54028 | return !isHidden(child);
|
54029 | });
|
54030 | };
|
54031 |
|
54032 |
|
54033 |
|
54034 | function isConnection$8(element) {
|
54035 | return !!element.waypoints;
|
54036 | }
|
54037 |
|
54038 | function isHidden(element) {
|
54039 | return !!element.hidden;
|
54040 | }
|
54041 |
|
54042 | function isLabel$4(element) {
|
54043 | return !!element.labelTarget;
|
54044 | }
|
54045 |
|
54046 | var HIGH_PRIORITY$g = 1500;
|
54047 |
|
54048 |
|
54049 | |
54050 |
|
54051 |
|
54052 |
|
54053 |
|
54054 |
|
54055 | function BpmnCreateMoveSnapping(eventBus, injector) {
|
54056 | injector.invoke(CreateMoveSnapping, this);
|
54057 |
|
54058 |
|
54059 | eventBus.on([ 'create.move', 'create.end' ], HIGH_PRIORITY$g, setSnappedIfConstrained);
|
54060 |
|
54061 |
|
54062 | eventBus.on([
|
54063 | 'create.move',
|
54064 | 'create.end',
|
54065 | 'shape.move.move',
|
54066 | 'shape.move.end'
|
54067 | ], HIGH_PRIORITY$g, function(event) {
|
54068 | var context = event.context,
|
54069 | canExecute = context.canExecute,
|
54070 | target = context.target;
|
54071 |
|
54072 | var canAttach = canExecute && (canExecute === 'attach' || canExecute.attach);
|
54073 |
|
54074 | if (canAttach && !isSnapped(event)) {
|
54075 | snapBoundaryEvent(event, target);
|
54076 | }
|
54077 | });
|
54078 | }
|
54079 |
|
54080 | inherits_browser(BpmnCreateMoveSnapping, CreateMoveSnapping);
|
54081 |
|
54082 | BpmnCreateMoveSnapping.$inject = [
|
54083 | 'eventBus',
|
54084 | 'injector'
|
54085 | ];
|
54086 |
|
54087 | BpmnCreateMoveSnapping.prototype.initSnap = function(event) {
|
54088 | var snapContext = CreateMoveSnapping.prototype.initSnap.call(this, event);
|
54089 |
|
54090 | var shape = event.shape;
|
54091 |
|
54092 |
|
54093 | forEach(shape.outgoing, function(connection) {
|
54094 | var docking = connection.waypoints[0];
|
54095 |
|
54096 | docking = docking.original || docking;
|
54097 |
|
54098 | snapContext.setSnapOrigin(connection.id + '-docking', {
|
54099 | x: docking.x - event.x,
|
54100 | y: docking.y - event.y
|
54101 | });
|
54102 | });
|
54103 |
|
54104 | forEach(shape.incoming, function(connection) {
|
54105 | var docking = connection.waypoints[connection.waypoints.length - 1];
|
54106 |
|
54107 | docking = docking.original || docking;
|
54108 |
|
54109 | snapContext.setSnapOrigin(connection.id + '-docking', {
|
54110 | x: docking.x - event.x,
|
54111 | y: docking.y - event.y
|
54112 | });
|
54113 | });
|
54114 |
|
54115 | if (is$1(shape, 'bpmn:Participant')) {
|
54116 |
|
54117 |
|
54118 | snapContext.setSnapLocations([ 'top-left', 'bottom-right', 'mid' ]);
|
54119 | }
|
54120 |
|
54121 | return snapContext;
|
54122 | };
|
54123 |
|
54124 | BpmnCreateMoveSnapping.prototype.addSnapTargetPoints = function(snapPoints, shape, target) {
|
54125 | CreateMoveSnapping.prototype.addSnapTargetPoints.call(this, snapPoints, shape, target);
|
54126 |
|
54127 | var snapTargets = this.getSnapTargets(shape, target);
|
54128 |
|
54129 | forEach(snapTargets, function(snapTarget) {
|
54130 |
|
54131 |
|
54132 |
|
54133 |
|
54134 |
|
54135 | if (isContainer(snapTarget) || areAll([ shape, snapTarget ], 'bpmn:TextAnnotation')) {
|
54136 | snapPoints.add('top-left', topLeft(snapTarget));
|
54137 | snapPoints.add('bottom-right', bottomRight(snapTarget));
|
54138 | }
|
54139 | });
|
54140 |
|
54141 |
|
54142 | forEach(shape.incoming, function(connection) {
|
54143 |
|
54144 | if (!includes$3(snapTargets, connection.source)) {
|
54145 | snapPoints.add('mid', getMid(connection.source));
|
54146 | }
|
54147 |
|
54148 | var docking = connection.waypoints[0];
|
54149 |
|
54150 | snapPoints.add(connection.id + '-docking', docking.original || docking);
|
54151 | });
|
54152 |
|
54153 |
|
54154 | forEach(shape.outgoing, function(connection) {
|
54155 |
|
54156 | if (!includes$3(snapTargets, connection.target)) {
|
54157 | snapPoints.add('mid', getMid(connection.target));
|
54158 | }
|
54159 |
|
54160 | var docking = connection.waypoints[ connection.waypoints.length - 1 ];
|
54161 |
|
54162 | snapPoints.add(connection.id + '-docking', docking.original || docking);
|
54163 | });
|
54164 |
|
54165 |
|
54166 | if (is$1(target, 'bpmn:SequenceFlow')) {
|
54167 | snapPoints = this.addSnapTargetPoints(snapPoints, shape, target.parent);
|
54168 | }
|
54169 |
|
54170 | return snapPoints;
|
54171 | };
|
54172 |
|
54173 | BpmnCreateMoveSnapping.prototype.getSnapTargets = function(shape, target) {
|
54174 | return CreateMoveSnapping.prototype.getSnapTargets.call(this, shape, target)
|
54175 | .filter(function(snapTarget) {
|
54176 |
|
54177 |
|
54178 | return !is$1(snapTarget, 'bpmn:Lane');
|
54179 | });
|
54180 | };
|
54181 |
|
54182 |
|
54183 |
|
54184 | function snapBoundaryEvent(event, target) {
|
54185 | var targetTRBL = asTRBL(target);
|
54186 |
|
54187 | var direction = getBoundaryAttachment(event, target);
|
54188 |
|
54189 | var context = event.context,
|
54190 | shape = context.shape;
|
54191 |
|
54192 | var offset;
|
54193 |
|
54194 | if (shape.parent) {
|
54195 | offset = { x: 0, y: 0 };
|
54196 | } else {
|
54197 | offset = getMid(shape);
|
54198 | }
|
54199 |
|
54200 | if (/top/.test(direction)) {
|
54201 | setSnapped(event, 'y', targetTRBL.top - offset.y);
|
54202 | } else if (/bottom/.test(direction)) {
|
54203 | setSnapped(event, 'y', targetTRBL.bottom - offset.y);
|
54204 | }
|
54205 |
|
54206 | if (/left/.test(direction)) {
|
54207 | setSnapped(event, 'x', targetTRBL.left - offset.x);
|
54208 | } else if (/right/.test(direction)) {
|
54209 | setSnapped(event, 'x', targetTRBL.right - offset.x);
|
54210 | }
|
54211 | }
|
54212 |
|
54213 | function areAll(elements, type) {
|
54214 | return elements.every(function(el) {
|
54215 | return is$1(el, type);
|
54216 | });
|
54217 | }
|
54218 |
|
54219 | function isContainer(element) {
|
54220 | if (is$1(element, 'bpmn:SubProcess') && isExpanded(element)) {
|
54221 | return true;
|
54222 | }
|
54223 |
|
54224 | return is$1(element, 'bpmn:Participant');
|
54225 | }
|
54226 |
|
54227 |
|
54228 | function setSnappedIfConstrained(event) {
|
54229 | var context = event.context,
|
54230 | createConstraints = context.createConstraints;
|
54231 |
|
54232 | if (!createConstraints) {
|
54233 | return;
|
54234 | }
|
54235 |
|
54236 | var top = createConstraints.top,
|
54237 | right = createConstraints.right,
|
54238 | bottom = createConstraints.bottom,
|
54239 | left = createConstraints.left;
|
54240 |
|
54241 | if ((left && left >= event.x) || (right && right <= event.x)) {
|
54242 | setSnapped(event, 'x', event.x);
|
54243 | }
|
54244 |
|
54245 | if ((top && top >= event.y) || (bottom && bottom <= event.y)) {
|
54246 | setSnapped(event, 'y', event.y);
|
54247 | }
|
54248 | }
|
54249 |
|
54250 | function includes$3(array, value) {
|
54251 | return array.indexOf(value) !== -1;
|
54252 | }
|
54253 |
|
54254 | var HIGHER_PRIORITY$4 = 1250;
|
54255 |
|
54256 |
|
54257 | |
54258 |
|
54259 |
|
54260 |
|
54261 |
|
54262 |
|
54263 | function ResizeSnapping(eventBus, snapping) {
|
54264 | var self = this;
|
54265 |
|
54266 | eventBus.on([ 'resize.start' ], function(event) {
|
54267 | self.initSnap(event);
|
54268 | });
|
54269 |
|
54270 | eventBus.on([
|
54271 | 'resize.move',
|
54272 | 'resize.end',
|
54273 | ], HIGHER_PRIORITY$4, function(event) {
|
54274 | var context = event.context,
|
54275 | shape = context.shape,
|
54276 | parent = shape.parent,
|
54277 | direction = context.direction,
|
54278 | snapContext = context.snapContext;
|
54279 |
|
54280 | if (event.originalEvent && isCmd(event.originalEvent)) {
|
54281 | return;
|
54282 | }
|
54283 |
|
54284 | if (isSnapped(event)) {
|
54285 | return;
|
54286 | }
|
54287 |
|
54288 | var snapPoints = snapContext.pointsForTarget(parent);
|
54289 |
|
54290 | if (!snapPoints.initialized) {
|
54291 | snapPoints = self.addSnapTargetPoints(snapPoints, shape, parent, direction);
|
54292 |
|
54293 | snapPoints.initialized = true;
|
54294 | }
|
54295 |
|
54296 | if (isHorizontal$2(direction)) {
|
54297 | setSnapped(event, 'x', event.x);
|
54298 | }
|
54299 |
|
54300 | if (isVertical(direction)) {
|
54301 | setSnapped(event, 'y', event.y);
|
54302 | }
|
54303 |
|
54304 | snapping.snap(event, snapPoints);
|
54305 | });
|
54306 |
|
54307 | eventBus.on([ 'resize.cleanup' ], function() {
|
54308 | snapping.hide();
|
54309 | });
|
54310 | }
|
54311 |
|
54312 | ResizeSnapping.prototype.initSnap = function(event) {
|
54313 | var context = event.context,
|
54314 | shape = context.shape,
|
54315 | direction = context.direction,
|
54316 | snapContext = context.snapContext;
|
54317 |
|
54318 | if (!snapContext) {
|
54319 | snapContext = context.snapContext = new SnapContext();
|
54320 | }
|
54321 |
|
54322 | var snapOrigin = getSnapOrigin(shape, direction);
|
54323 |
|
54324 | snapContext.setSnapOrigin('corner', {
|
54325 | x: snapOrigin.x - event.x,
|
54326 | y: snapOrigin.y - event.y
|
54327 | });
|
54328 |
|
54329 | return snapContext;
|
54330 | };
|
54331 |
|
54332 | ResizeSnapping.prototype.addSnapTargetPoints = function(snapPoints, shape, target, direction) {
|
54333 | var snapTargets = this.getSnapTargets(shape, target);
|
54334 |
|
54335 | forEach(snapTargets, function(snapTarget) {
|
54336 | snapPoints.add('corner', bottomRight(snapTarget));
|
54337 | snapPoints.add('corner', topLeft(snapTarget));
|
54338 | });
|
54339 |
|
54340 | snapPoints.add('corner', getSnapOrigin(shape, direction));
|
54341 |
|
54342 | return snapPoints;
|
54343 | };
|
54344 |
|
54345 | ResizeSnapping.$inject = [
|
54346 | 'eventBus',
|
54347 | 'snapping'
|
54348 | ];
|
54349 |
|
54350 | ResizeSnapping.prototype.getSnapTargets = function(shape, target) {
|
54351 | return getChildren$1(target).filter(function(child) {
|
54352 | return !isAttached(child, shape)
|
54353 | && !isConnection$9(child)
|
54354 | && !isHidden$1(child)
|
54355 | && !isLabel$5(child);
|
54356 | });
|
54357 | };
|
54358 |
|
54359 |
|
54360 |
|
54361 | function getSnapOrigin(shape, direction) {
|
54362 | var mid = getMid(shape),
|
54363 | trbl = asTRBL(shape);
|
54364 |
|
54365 | var snapOrigin = {
|
54366 | x: mid.x,
|
54367 | y: mid.y
|
54368 | };
|
54369 |
|
54370 | if (direction.indexOf('n') !== -1) {
|
54371 | snapOrigin.y = trbl.top;
|
54372 | } else if (direction.indexOf('s') !== -1) {
|
54373 | snapOrigin.y = trbl.bottom;
|
54374 | }
|
54375 |
|
54376 | if (direction.indexOf('e') !== -1) {
|
54377 | snapOrigin.x = trbl.right;
|
54378 | } else if (direction.indexOf('w') !== -1) {
|
54379 | snapOrigin.x = trbl.left;
|
54380 | }
|
54381 |
|
54382 | return snapOrigin;
|
54383 | }
|
54384 |
|
54385 | function isAttached(element, host) {
|
54386 | return element.host === host;
|
54387 | }
|
54388 |
|
54389 | function isConnection$9(element) {
|
54390 | return !!element.waypoints;
|
54391 | }
|
54392 |
|
54393 | function isHidden$1(element) {
|
54394 | return !!element.hidden;
|
54395 | }
|
54396 |
|
54397 | function isLabel$5(element) {
|
54398 | return !!element.labelTarget;
|
54399 | }
|
54400 |
|
54401 | function isHorizontal$2(direction) {
|
54402 | return direction === 'n' || direction === 's';
|
54403 | }
|
54404 |
|
54405 | function isVertical(direction) {
|
54406 | return direction === 'e' || direction === 'w';
|
54407 | }
|
54408 |
|
54409 | var SNAP_TOLERANCE = 7;
|
54410 |
|
54411 | var SNAP_LINE_HIDE_DELAY = 1000;
|
54412 |
|
54413 |
|
54414 | |
54415 |
|
54416 |
|
54417 |
|
54418 |
|
54419 |
|
54420 | function Snapping(canvas) {
|
54421 | this._canvas = canvas;
|
54422 |
|
54423 |
|
54424 | this._asyncHide = debounce(bind(this.hide, this), SNAP_LINE_HIDE_DELAY);
|
54425 | }
|
54426 |
|
54427 | Snapping.$inject = [ 'canvas' ];
|
54428 |
|
54429 | |
54430 |
|
54431 |
|
54432 |
|
54433 |
|
54434 |
|
54435 | Snapping.prototype.snap = function(event, snapPoints) {
|
54436 | var context = event.context,
|
54437 | snapContext = context.snapContext,
|
54438 | snapLocations = snapContext.getSnapLocations();
|
54439 |
|
54440 | var snapping = {
|
54441 | x: isSnapped(event, 'x'),
|
54442 | y: isSnapped(event, 'y')
|
54443 | };
|
54444 |
|
54445 | forEach(snapLocations, function(location) {
|
54446 | var snapOrigin = snapContext.getSnapOrigin(location);
|
54447 |
|
54448 | var snapCurrent = {
|
54449 | x: event.x + snapOrigin.x,
|
54450 | y: event.y + snapOrigin.y
|
54451 | };
|
54452 |
|
54453 |
|
54454 | forEach([ 'x', 'y' ], function(axis) {
|
54455 | var locationSnapping;
|
54456 |
|
54457 | if (!snapping[axis]) {
|
54458 | locationSnapping = snapPoints.snap(snapCurrent, location, axis, SNAP_TOLERANCE);
|
54459 |
|
54460 | if (locationSnapping !== undefined) {
|
54461 | snapping[axis] = {
|
54462 | value: locationSnapping,
|
54463 | originValue: locationSnapping - snapOrigin[axis]
|
54464 | };
|
54465 | }
|
54466 | }
|
54467 | });
|
54468 |
|
54469 |
|
54470 | if (snapping.x && snapping.y) {
|
54471 | return false;
|
54472 | }
|
54473 | });
|
54474 |
|
54475 |
|
54476 | this.showSnapLine('vertical', snapping.x && snapping.x.value);
|
54477 | this.showSnapLine('horizontal', snapping.y && snapping.y.value);
|
54478 |
|
54479 |
|
54480 | forEach([ 'x', 'y' ], function(axis) {
|
54481 | var axisSnapping = snapping[axis];
|
54482 |
|
54483 | if (isObject(axisSnapping)) {
|
54484 | setSnapped(event, axis, axisSnapping.originValue);
|
54485 | }
|
54486 | });
|
54487 | };
|
54488 |
|
54489 | Snapping.prototype._createLine = function(orientation) {
|
54490 | var root = this._canvas.getLayer('snap');
|
54491 |
|
54492 | var line = create('path');
|
54493 |
|
54494 | attr$1(line, { d: 'M0,0 L0,0' });
|
54495 |
|
54496 | classes$1(line).add('djs-snap-line');
|
54497 |
|
54498 | append(root, line);
|
54499 |
|
54500 | return {
|
54501 | update: function(position) {
|
54502 |
|
54503 | if (!isNumber(position)) {
|
54504 | attr$1(line, { display: 'none' });
|
54505 | } else {
|
54506 | if (orientation === 'horizontal') {
|
54507 | attr$1(line, {
|
54508 | d: 'M-100000,' + position + ' L+100000,' + position,
|
54509 | display: ''
|
54510 | });
|
54511 | } else {
|
54512 | attr$1(line, {
|
54513 | d: 'M ' + position + ',-100000 L ' + position + ', +100000',
|
54514 | display: ''
|
54515 | });
|
54516 | }
|
54517 | }
|
54518 | }
|
54519 | };
|
54520 | };
|
54521 |
|
54522 | Snapping.prototype._createSnapLines = function() {
|
54523 | this._snapLines = {
|
54524 | horizontal: this._createLine('horizontal'),
|
54525 | vertical: this._createLine('vertical')
|
54526 | };
|
54527 | };
|
54528 |
|
54529 | Snapping.prototype.showSnapLine = function(orientation, position) {
|
54530 |
|
54531 | var line = this.getSnapLine(orientation);
|
54532 |
|
54533 | if (line) {
|
54534 | line.update(position);
|
54535 | }
|
54536 |
|
54537 | this._asyncHide();
|
54538 | };
|
54539 |
|
54540 | Snapping.prototype.getSnapLine = function(orientation) {
|
54541 | if (!this._snapLines) {
|
54542 | this._createSnapLines();
|
54543 | }
|
54544 |
|
54545 | return this._snapLines[orientation];
|
54546 | };
|
54547 |
|
54548 | Snapping.prototype.hide = function() {
|
54549 | forEach(this._snapLines, function(snapLine) {
|
54550 | snapLine.update();
|
54551 | });
|
54552 | };
|
54553 |
|
54554 | var SnappingModule = {
|
54555 | __init__: [
|
54556 | 'createMoveSnapping',
|
54557 | 'resizeSnapping',
|
54558 | 'snapping'
|
54559 | ],
|
54560 | createMoveSnapping: [ 'type', CreateMoveSnapping ],
|
54561 | resizeSnapping: [ 'type', ResizeSnapping ],
|
54562 | snapping: [ 'type', Snapping ]
|
54563 | };
|
54564 |
|
54565 | var SnappingModule$1 = {
|
54566 | __depends__: [ SnappingModule ],
|
54567 | __init__: [
|
54568 | 'connectSnapping',
|
54569 | 'createMoveSnapping'
|
54570 | ],
|
54571 | connectSnapping: [ 'type', BpmnConnectSnapping ],
|
54572 | createMoveSnapping: [ 'type', BpmnCreateMoveSnapping ]
|
54573 | };
|
54574 |
|
54575 | |
54576 |
|
54577 |
|
54578 | function SearchPad(canvas, eventBus, overlays, selection) {
|
54579 | this._open = false;
|
54580 | this._results = [];
|
54581 | this._eventMaps = [];
|
54582 |
|
54583 | this._canvas = canvas;
|
54584 | this._eventBus = eventBus;
|
54585 | this._overlays = overlays;
|
54586 | this._selection = selection;
|
54587 |
|
54588 |
|
54589 | this._container = domify(SearchPad.BOX_HTML);
|
54590 | this._searchInput = query(SearchPad.INPUT_SELECTOR, this._container);
|
54591 | this._resultsContainer = query(SearchPad.RESULTS_CONTAINER_SELECTOR, this._container);
|
54592 |
|
54593 |
|
54594 | this._canvas.getContainer().appendChild(this._container);
|
54595 |
|
54596 |
|
54597 | eventBus.on([ 'canvas.destroy', 'diagram.destroy' ], this.close, this);
|
54598 | }
|
54599 |
|
54600 |
|
54601 | SearchPad.$inject = [
|
54602 | 'canvas',
|
54603 | 'eventBus',
|
54604 | 'overlays',
|
54605 | 'selection'
|
54606 | ];
|
54607 |
|
54608 |
|
54609 | |
54610 |
|
54611 |
|
54612 | SearchPad.prototype._bindEvents = function() {
|
54613 | var self = this;
|
54614 |
|
54615 | function listen(el, selector, type, fn) {
|
54616 | self._eventMaps.push({
|
54617 | el: el,
|
54618 | type: type,
|
54619 | listener: delegateEvents.bind(el, selector, type, fn)
|
54620 | });
|
54621 | }
|
54622 |
|
54623 |
|
54624 | listen(document, 'html', 'click', function(e) {
|
54625 | self.close();
|
54626 | });
|
54627 |
|
54628 |
|
54629 |
|
54630 | listen(this._container, SearchPad.INPUT_SELECTOR, 'click', function(e) {
|
54631 | e.stopPropagation();
|
54632 | e.delegateTarget.focus();
|
54633 | });
|
54634 |
|
54635 |
|
54636 | listen(this._container, SearchPad.RESULT_SELECTOR, 'mouseover', function(e) {
|
54637 | e.stopPropagation();
|
54638 | self._scrollToNode(e.delegateTarget);
|
54639 | self._preselect(e.delegateTarget);
|
54640 | });
|
54641 |
|
54642 |
|
54643 | listen(this._container, SearchPad.RESULT_SELECTOR, 'click', function(e) {
|
54644 | e.stopPropagation();
|
54645 | self._select(e.delegateTarget);
|
54646 | });
|
54647 |
|
54648 |
|
54649 |
|
54650 | listen(this._container, SearchPad.INPUT_SELECTOR, 'keydown', function(e) {
|
54651 |
|
54652 |
|
54653 | if (e.keyCode === 38) {
|
54654 | e.preventDefault();
|
54655 | }
|
54656 |
|
54657 |
|
54658 | if (e.keyCode === 40) {
|
54659 | e.preventDefault();
|
54660 | }
|
54661 | });
|
54662 |
|
54663 |
|
54664 | listen(this._container, SearchPad.INPUT_SELECTOR, 'keyup', function(e) {
|
54665 |
|
54666 |
|
54667 | if (e.keyCode === 27) {
|
54668 | return self.close();
|
54669 | }
|
54670 |
|
54671 |
|
54672 | if (e.keyCode === 13) {
|
54673 | var selected = self._getCurrentResult();
|
54674 |
|
54675 | return selected ? self._select(selected) : self.close();
|
54676 | }
|
54677 |
|
54678 |
|
54679 | if (e.keyCode === 38) {
|
54680 | return self._scrollToDirection(true);
|
54681 | }
|
54682 |
|
54683 |
|
54684 | if (e.keyCode === 40) {
|
54685 | return self._scrollToDirection();
|
54686 | }
|
54687 |
|
54688 |
|
54689 |
|
54690 | if (e.keyCode === 37 || e.keyCode === 39) {
|
54691 | return;
|
54692 | }
|
54693 |
|
54694 |
|
54695 | self._search(e.delegateTarget.value);
|
54696 | });
|
54697 | };
|
54698 |
|
54699 |
|
54700 | |
54701 |
|
54702 |
|
54703 | SearchPad.prototype._unbindEvents = function() {
|
54704 | this._eventMaps.forEach(function(m) {
|
54705 | delegateEvents.unbind(m.el, m.type, m.listener);
|
54706 | });
|
54707 | };
|
54708 |
|
54709 |
|
54710 | |
54711 |
|
54712 |
|
54713 |
|
54714 |
|
54715 | SearchPad.prototype._search = function(pattern) {
|
54716 | var self = this;
|
54717 |
|
54718 | this._clearResults();
|
54719 |
|
54720 |
|
54721 | if (!pattern || pattern === '') {
|
54722 | return;
|
54723 | }
|
54724 |
|
54725 | var searchResults = this._searchProvider.find(pattern);
|
54726 |
|
54727 | if (!searchResults.length) {
|
54728 | return;
|
54729 | }
|
54730 |
|
54731 |
|
54732 | searchResults.forEach(function(result) {
|
54733 | var id = result.element.id;
|
54734 | var node = self._createResultNode(result, id);
|
54735 | self._results[id] = {
|
54736 | element: result.element,
|
54737 | node: node
|
54738 | };
|
54739 | });
|
54740 |
|
54741 |
|
54742 | var node = query(SearchPad.RESULT_SELECTOR, this._resultsContainer);
|
54743 | this._scrollToNode(node);
|
54744 | this._preselect(node);
|
54745 | };
|
54746 |
|
54747 |
|
54748 | |
54749 |
|
54750 |
|
54751 |
|
54752 | SearchPad.prototype._scrollToDirection = function(previous) {
|
54753 | var selected = this._getCurrentResult();
|
54754 | if (!selected) {
|
54755 | return;
|
54756 | }
|
54757 |
|
54758 | var node = previous ? selected.previousElementSibling : selected.nextElementSibling;
|
54759 | if (node) {
|
54760 | this._scrollToNode(node);
|
54761 | this._preselect(node);
|
54762 | }
|
54763 | };
|
54764 |
|
54765 |
|
54766 | |
54767 |
|
54768 |
|
54769 |
|
54770 |
|
54771 | SearchPad.prototype._scrollToNode = function(node) {
|
54772 | if (!node || node === this._getCurrentResult()) {
|
54773 | return;
|
54774 | }
|
54775 |
|
54776 | var nodeOffset = node.offsetTop;
|
54777 | var containerScroll = this._resultsContainer.scrollTop;
|
54778 |
|
54779 | var bottomScroll = nodeOffset - this._resultsContainer.clientHeight + node.clientHeight;
|
54780 |
|
54781 | if (nodeOffset < containerScroll) {
|
54782 | this._resultsContainer.scrollTop = nodeOffset;
|
54783 | } else if (containerScroll < bottomScroll) {
|
54784 | this._resultsContainer.scrollTop = bottomScroll;
|
54785 | }
|
54786 | };
|
54787 |
|
54788 |
|
54789 | |
54790 |
|
54791 |
|
54792 | SearchPad.prototype._clearResults = function() {
|
54793 | clear(this._resultsContainer);
|
54794 |
|
54795 | this._results = [];
|
54796 |
|
54797 | this._resetOverlay();
|
54798 |
|
54799 | this._eventBus.fire('searchPad.cleared');
|
54800 | };
|
54801 |
|
54802 |
|
54803 | |
54804 |
|
54805 |
|
54806 |
|
54807 |
|
54808 | SearchPad.prototype._getCurrentResult = function() {
|
54809 | return query(SearchPad.RESULT_SELECTED_SELECTOR, this._resultsContainer);
|
54810 | };
|
54811 |
|
54812 |
|
54813 | |
54814 |
|
54815 |
|
54816 |
|
54817 |
|
54818 |
|
54819 |
|
54820 |
|
54821 |
|
54822 |
|
54823 |
|
54824 |
|
54825 | SearchPad.prototype._createResultNode = function(result, id) {
|
54826 | var node = domify(SearchPad.RESULT_HTML);
|
54827 |
|
54828 |
|
54829 | if (result.primaryTokens.length > 0) {
|
54830 | createInnerTextNode(node, result.primaryTokens, SearchPad.RESULT_PRIMARY_HTML);
|
54831 | }
|
54832 |
|
54833 |
|
54834 | createInnerTextNode(node, result.secondaryTokens, SearchPad.RESULT_SECONDARY_HTML);
|
54835 |
|
54836 | attr(node, SearchPad.RESULT_ID_ATTRIBUTE, id);
|
54837 |
|
54838 | this._resultsContainer.appendChild(node);
|
54839 |
|
54840 | return node;
|
54841 | };
|
54842 |
|
54843 |
|
54844 | |
54845 |
|
54846 |
|
54847 |
|
54848 |
|
54849 |
|
54850 |
|
54851 |
|
54852 | SearchPad.prototype.registerProvider = function(provider) {
|
54853 | this._searchProvider = provider;
|
54854 | };
|
54855 |
|
54856 |
|
54857 | |
54858 |
|
54859 |
|
54860 | SearchPad.prototype.open = function() {
|
54861 | if (!this._searchProvider) {
|
54862 | throw new Error('no search provider registered');
|
54863 | }
|
54864 |
|
54865 | if (this.isOpen()) {
|
54866 | return;
|
54867 | }
|
54868 |
|
54869 | this._bindEvents();
|
54870 |
|
54871 | this._open = true;
|
54872 |
|
54873 | classes(this._container).add('open');
|
54874 |
|
54875 | this._searchInput.focus();
|
54876 |
|
54877 | this._eventBus.fire('searchPad.opened');
|
54878 | };
|
54879 |
|
54880 |
|
54881 | |
54882 |
|
54883 |
|
54884 | SearchPad.prototype.close = function() {
|
54885 | if (!this.isOpen()) {
|
54886 | return;
|
54887 | }
|
54888 |
|
54889 | this._unbindEvents();
|
54890 |
|
54891 | this._open = false;
|
54892 |
|
54893 | classes(this._container).remove('open');
|
54894 |
|
54895 | this._clearResults();
|
54896 |
|
54897 | this._searchInput.value = '';
|
54898 | this._searchInput.blur();
|
54899 |
|
54900 | this._resetOverlay();
|
54901 |
|
54902 | this._eventBus.fire('searchPad.closed');
|
54903 | };
|
54904 |
|
54905 |
|
54906 | |
54907 |
|
54908 |
|
54909 | SearchPad.prototype.toggle = function() {
|
54910 | this.isOpen() ? this.close() : this.open();
|
54911 | };
|
54912 |
|
54913 |
|
54914 | |
54915 |
|
54916 |
|
54917 | SearchPad.prototype.isOpen = function() {
|
54918 | return this._open;
|
54919 | };
|
54920 |
|
54921 |
|
54922 | |
54923 |
|
54924 |
|
54925 |
|
54926 |
|
54927 | SearchPad.prototype._preselect = function(node) {
|
54928 | var selectedNode = this._getCurrentResult();
|
54929 |
|
54930 |
|
54931 | if (node === selectedNode) {
|
54932 | return;
|
54933 | }
|
54934 |
|
54935 |
|
54936 | if (selectedNode) {
|
54937 | classes(selectedNode).remove(SearchPad.RESULT_SELECTED_CLASS);
|
54938 | }
|
54939 |
|
54940 | var id = attr(node, SearchPad.RESULT_ID_ATTRIBUTE);
|
54941 | var element = this._results[id].element;
|
54942 |
|
54943 | classes(node).add(SearchPad.RESULT_SELECTED_CLASS);
|
54944 |
|
54945 | this._resetOverlay(element);
|
54946 |
|
54947 | this._centerViewbox(element);
|
54948 |
|
54949 | this._selection.select(element);
|
54950 |
|
54951 | this._eventBus.fire('searchPad.preselected', element);
|
54952 | };
|
54953 |
|
54954 |
|
54955 | |
54956 |
|
54957 |
|
54958 |
|
54959 |
|
54960 | SearchPad.prototype._select = function(node) {
|
54961 | var id = attr(node, SearchPad.RESULT_ID_ATTRIBUTE);
|
54962 | var element = this._results[id].element;
|
54963 |
|
54964 | this.close();
|
54965 |
|
54966 | this._resetOverlay();
|
54967 |
|
54968 | this._centerViewbox(element);
|
54969 |
|
54970 | this._selection.select(element);
|
54971 |
|
54972 | this._eventBus.fire('searchPad.selected', element);
|
54973 | };
|
54974 |
|
54975 |
|
54976 | |
54977 |
|
54978 |
|
54979 |
|
54980 |
|
54981 | SearchPad.prototype._centerViewbox = function(element) {
|
54982 | var viewbox = this._canvas.viewbox();
|
54983 |
|
54984 | var box = getBBox(element);
|
54985 |
|
54986 | var newViewbox = {
|
54987 | x: (box.x + box.width/2) - viewbox.outer.width/2,
|
54988 | y: (box.y + box.height/2) - viewbox.outer.height/2,
|
54989 | width: viewbox.outer.width,
|
54990 | height: viewbox.outer.height
|
54991 | };
|
54992 |
|
54993 | this._canvas.viewbox(newViewbox);
|
54994 |
|
54995 | this._canvas.zoom(viewbox.scale);
|
54996 | };
|
54997 |
|
54998 |
|
54999 | |
55000 |
|
55001 |
|
55002 |
|
55003 |
|
55004 |
|
55005 | SearchPad.prototype._resetOverlay = function(element) {
|
55006 | if (this._overlayId) {
|
55007 | this._overlays.remove(this._overlayId);
|
55008 | }
|
55009 |
|
55010 | if (element) {
|
55011 | var box = getBBox(element);
|
55012 | var overlay = constructOverlay(box);
|
55013 | this._overlayId = this._overlays.add(element, overlay);
|
55014 | }
|
55015 | };
|
55016 |
|
55017 |
|
55018 | |
55019 |
|
55020 |
|
55021 |
|
55022 |
|
55023 |
|
55024 | function constructOverlay(box) {
|
55025 |
|
55026 | var offset = 6;
|
55027 | var w = box.width + offset * 2;
|
55028 | var h = box.height + offset * 2;
|
55029 |
|
55030 | var styles = [
|
55031 | 'width: '+ w +'px',
|
55032 | 'height: '+ h + 'px'
|
55033 | ].join('; ');
|
55034 |
|
55035 | return {
|
55036 | position: {
|
55037 | bottom: h - offset,
|
55038 | right: w - offset
|
55039 | },
|
55040 | show: true,
|
55041 | html: '<div style="' + styles + '" class="' + SearchPad.OVERLAY_CLASS + '"></div>'
|
55042 | };
|
55043 | }
|
55044 |
|
55045 |
|
55046 | |
55047 |
|
55048 |
|
55049 |
|
55050 |
|
55051 |
|
55052 |
|
55053 | function createInnerTextNode(parentNode, tokens, template) {
|
55054 | var text = createHtmlText(tokens);
|
55055 | var childNode = domify(template);
|
55056 | childNode.innerHTML = text;
|
55057 | parentNode.appendChild(childNode);
|
55058 | }
|
55059 |
|
55060 | |
55061 |
|
55062 |
|
55063 |
|
55064 |
|
55065 |
|
55066 |
|
55067 | function createHtmlText(tokens) {
|
55068 | var htmlText = '';
|
55069 |
|
55070 | tokens.forEach(function(t) {
|
55071 | if (t.matched) {
|
55072 | htmlText += '<strong class="' + SearchPad.RESULT_HIGHLIGHT_CLASS + '">' + escapeHTML(t.matched) + '</strong>';
|
55073 | } else {
|
55074 | htmlText += escapeHTML(t.normal);
|
55075 | }
|
55076 | });
|
55077 |
|
55078 | return htmlText !== '' ? htmlText : null;
|
55079 | }
|
55080 |
|
55081 |
|
55082 | |
55083 |
|
55084 |
|
55085 | SearchPad.CONTAINER_SELECTOR = '.djs-search-container';
|
55086 | SearchPad.INPUT_SELECTOR = '.djs-search-input input';
|
55087 | SearchPad.RESULTS_CONTAINER_SELECTOR = '.djs-search-results';
|
55088 | SearchPad.RESULT_SELECTOR = '.djs-search-result';
|
55089 | SearchPad.RESULT_SELECTED_CLASS = 'djs-search-result-selected';
|
55090 | SearchPad.RESULT_SELECTED_SELECTOR = '.' + SearchPad.RESULT_SELECTED_CLASS;
|
55091 | SearchPad.RESULT_ID_ATTRIBUTE = 'data-result-id';
|
55092 | SearchPad.RESULT_HIGHLIGHT_CLASS = 'djs-search-highlight';
|
55093 | SearchPad.OVERLAY_CLASS = 'djs-search-overlay';
|
55094 |
|
55095 | SearchPad.BOX_HTML =
|
55096 | '<div class="djs-search-container djs-draggable djs-scrollable">' +
|
55097 | '<div class="djs-search-input">' +
|
55098 | '<input type="text"/>' +
|
55099 | '</div>' +
|
55100 | '<div class="djs-search-results"></div>' +
|
55101 | '</div>';
|
55102 |
|
55103 | SearchPad.RESULT_HTML =
|
55104 | '<div class="djs-search-result"></div>';
|
55105 |
|
55106 | SearchPad.RESULT_PRIMARY_HTML =
|
55107 | '<div class="djs-search-result-primary"></div>';
|
55108 |
|
55109 | SearchPad.RESULT_SECONDARY_HTML =
|
55110 | '<p class="djs-search-result-secondary"></p>';
|
55111 |
|
55112 | var SearchPadModule = {
|
55113 | __depends__: [
|
55114 | OverlaysModule,
|
55115 | SelectionModule
|
55116 | ],
|
55117 | searchPad: [ 'type', SearchPad ]
|
55118 | };
|
55119 |
|
55120 | |
55121 |
|
55122 |
|
55123 | function BpmnSearchProvider(elementRegistry, searchPad, canvas) {
|
55124 |
|
55125 | this._elementRegistry = elementRegistry;
|
55126 | this._canvas = canvas;
|
55127 |
|
55128 | searchPad.registerProvider(this);
|
55129 | }
|
55130 |
|
55131 | BpmnSearchProvider.$inject = [
|
55132 | 'elementRegistry',
|
55133 | 'searchPad',
|
55134 | 'canvas'
|
55135 | ];
|
55136 |
|
55137 |
|
55138 | |
55139 |
|
55140 |
|
55141 |
|
55142 |
|
55143 |
|
55144 |
|
55145 |
|
55146 |
|
55147 |
|
55148 |
|
55149 |
|
55150 |
|
55151 |
|
55152 |
|
55153 |
|
55154 |
|
55155 |
|
55156 | BpmnSearchProvider.prototype.find = function(pattern) {
|
55157 | var rootElement = this._canvas.getRootElement();
|
55158 |
|
55159 | var elements = this._elementRegistry.filter(function(element) {
|
55160 | if (element.labelTarget) {
|
55161 | return false;
|
55162 | }
|
55163 | return true;
|
55164 | });
|
55165 |
|
55166 |
|
55167 | elements = filter(elements, function(element) {
|
55168 | return element !== rootElement;
|
55169 | });
|
55170 |
|
55171 | elements = map(elements, function(element) {
|
55172 | return {
|
55173 | primaryTokens: matchAndSplit(getLabel(element), pattern),
|
55174 | secondaryTokens: matchAndSplit(element.id, pattern),
|
55175 | element: element
|
55176 | };
|
55177 | });
|
55178 |
|
55179 |
|
55180 | elements = filter(elements, function(element) {
|
55181 | return hasMatched(element.primaryTokens) || hasMatched(element.secondaryTokens);
|
55182 | });
|
55183 |
|
55184 | elements = sortBy(elements, function(element) {
|
55185 | return getLabel(element.element) + element.element.id;
|
55186 | });
|
55187 |
|
55188 | return elements;
|
55189 | };
|
55190 |
|
55191 |
|
55192 | function hasMatched(tokens) {
|
55193 | var matched = filter(tokens, function(t) {
|
55194 | return !!t.matched;
|
55195 | });
|
55196 |
|
55197 | return matched.length > 0;
|
55198 | }
|
55199 |
|
55200 |
|
55201 | function matchAndSplit(text, pattern) {
|
55202 | var tokens = [],
|
55203 | originalText = text;
|
55204 |
|
55205 | if (!text) {
|
55206 | return tokens;
|
55207 | }
|
55208 |
|
55209 | text = text.toLowerCase();
|
55210 | pattern = pattern.toLowerCase();
|
55211 |
|
55212 | var i = text.indexOf(pattern);
|
55213 |
|
55214 | if (i > -1) {
|
55215 | if (i !== 0) {
|
55216 | tokens.push({
|
55217 | normal: originalText.substr(0, i)
|
55218 | });
|
55219 | }
|
55220 |
|
55221 | tokens.push({
|
55222 | matched: originalText.substr(i, pattern.length)
|
55223 | });
|
55224 |
|
55225 | if (pattern.length + i < text.length) {
|
55226 | tokens.push({
|
55227 | normal: originalText.substr(pattern.length + i, text.length)
|
55228 | });
|
55229 | }
|
55230 | } else {
|
55231 | tokens.push({
|
55232 | normal: originalText
|
55233 | });
|
55234 | }
|
55235 |
|
55236 | return tokens;
|
55237 | }
|
55238 |
|
55239 | var SearchModule = {
|
55240 | __depends__: [
|
55241 | SearchPadModule
|
55242 | ],
|
55243 | __init__: [ 'bpmnSearch'],
|
55244 | bpmnSearch: [ 'type', BpmnSearchProvider ]
|
55245 | };
|
55246 |
|
55247 | var initialDiagram =
|
55248 | '<?xml version="1.0" encoding="UTF-8"?>' +
|
55249 | '<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
|
55250 | 'xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
|
55251 | 'xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" ' +
|
55252 | 'xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" ' +
|
55253 | 'targetNamespace="http://bpmn.io/schema/bpmn" ' +
|
55254 | 'id="Definitions_1">' +
|
55255 | '<bpmn:process id="Process_1" isExecutable="false">' +
|
55256 | '<bpmn:startEvent id="StartEvent_1"/>' +
|
55257 | '</bpmn:process>' +
|
55258 | '<bpmndi:BPMNDiagram id="BPMNDiagram_1">' +
|
55259 | '<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">' +
|
55260 | '<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">' +
|
55261 | '<dc:Bounds height="36.0" width="36.0" x="173.0" y="102.0"/>' +
|
55262 | '</bpmndi:BPMNShape>' +
|
55263 | '</bpmndi:BPMNPlane>' +
|
55264 | '</bpmndi:BPMNDiagram>' +
|
55265 | '</bpmn:definitions>';
|
55266 |
|
55267 |
|
55268 | |
55269 |
|
55270 |
|
55271 |
|
55272 |
|
55273 |
|
55274 |
|
55275 |
|
55276 |
|
55277 |
|
55278 |
|
55279 |
|
55280 |
|
55281 |
|
55282 |
|
55283 |
|
55284 |
|
55285 |
|
55286 |
|
55287 |
|
55288 |
|
55289 |
|
55290 |
|
55291 |
|
55292 |
|
55293 |
|
55294 |
|
55295 |
|
55296 |
|
55297 |
|
55298 |
|
55299 |
|
55300 |
|
55301 |
|
55302 |
|
55303 |
|
55304 |
|
55305 |
|
55306 |
|
55307 |
|
55308 |
|
55309 |
|
55310 |
|
55311 |
|
55312 |
|
55313 |
|
55314 |
|
55315 |
|
55316 |
|
55317 |
|
55318 |
|
55319 |
|
55320 |
|
55321 |
|
55322 |
|
55323 |
|
55324 |
|
55325 |
|
55326 |
|
55327 |
|
55328 |
|
55329 |
|
55330 |
|
55331 |
|
55332 |
|
55333 |
|
55334 |
|
55335 |
|
55336 |
|
55337 |
|
55338 |
|
55339 |
|
55340 | function Modeler(options) {
|
55341 | BaseModeler.call(this, options);
|
55342 | }
|
55343 |
|
55344 | inherits_browser(Modeler, BaseModeler);
|
55345 |
|
55346 |
|
55347 | Modeler.Viewer = Viewer;
|
55348 | Modeler.NavigatedViewer = NavigatedViewer;
|
55349 |
|
55350 | |
55351 |
|
55352 |
|
55353 |
|
55354 |
|
55355 | Modeler.prototype.createDiagram = function(done) {
|
55356 | return this.importXML(initialDiagram, done);
|
55357 | };
|
55358 |
|
55359 |
|
55360 | Modeler.prototype._interactionModules = [
|
55361 |
|
55362 |
|
55363 | KeyboardMoveModule,
|
55364 | MoveCanvasModule,
|
55365 | TouchModule$1,
|
55366 | ZoomScrollModule
|
55367 | ];
|
55368 |
|
55369 | Modeler.prototype._modelingModules = [
|
55370 |
|
55371 |
|
55372 | AlignElementsModule,
|
55373 | AutoPlaceModule,
|
55374 | AutoScrollModule,
|
55375 | AutoResizeModule,
|
55376 | BendpointsModule,
|
55377 | ConnectModule,
|
55378 | ConnectionPreviewModule,
|
55379 | ContextPadModule$1,
|
55380 | CopyPasteModule$1,
|
55381 | CreateModule,
|
55382 | DistributeElementsModule$1,
|
55383 | EditorActionsModule$1,
|
55384 | GridSnappingModule$1,
|
55385 | InteractionEventsModule$1,
|
55386 | KeyboardModule$1,
|
55387 | KeyboardMoveSelectionModule,
|
55388 | LabelEditingModule,
|
55389 | ModelingModule,
|
55390 | MoveModule,
|
55391 | PaletteModule$1,
|
55392 | ReplacePreviewModule,
|
55393 | ResizeModule,
|
55394 | SnappingModule$1,
|
55395 | SearchModule
|
55396 | ];
|
55397 |
|
55398 |
|
55399 |
|
55400 |
|
55401 |
|
55402 |
|
55403 |
|
55404 |
|
55405 | Modeler.prototype._modules = [].concat(
|
55406 | Viewer.prototype._modules,
|
55407 | Modeler.prototype._interactionModules,
|
55408 | Modeler.prototype._modelingModules
|
55409 | );
|
55410 |
|
55411 | return Modeler;
|
55412 |
|
55413 | }));
|