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 isArray(obj) {
|
234 | return nativeToString.call(obj) === '[object Array]';
|
235 | }
|
236 | function isObject(obj) {
|
237 | return nativeToString.call(obj) === '[object Object]';
|
238 | }
|
239 | function isNumber(obj) {
|
240 | return nativeToString.call(obj) === '[object Number]';
|
241 | }
|
242 | function isFunction(obj) {
|
243 | var tag = nativeToString.call(obj);
|
244 | return tag === '[object Function]' || tag === '[object AsyncFunction]' || tag === '[object GeneratorFunction]' || tag === '[object AsyncGeneratorFunction]' || tag === '[object Proxy]';
|
245 | }
|
246 | function isString(obj) {
|
247 | return nativeToString.call(obj) === '[object String]';
|
248 | }
|
249 | |
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 | function ensureArray(obj) {
|
256 | if (isArray(obj)) {
|
257 | return;
|
258 | }
|
259 |
|
260 | throw new Error('must supply array');
|
261 | }
|
262 | |
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 | function has(target, key) {
|
272 | return nativeHasOwnProperty.call(target, key);
|
273 | }
|
274 |
|
275 | |
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 | function find(collection, matcher) {
|
285 | matcher = toMatcher(matcher);
|
286 | var match;
|
287 | forEach(collection, function (val, key) {
|
288 | if (matcher(val, key)) {
|
289 | match = val;
|
290 | return false;
|
291 | }
|
292 | });
|
293 | return match;
|
294 | }
|
295 | |
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 | function findIndex(collection, matcher) {
|
305 | matcher = toMatcher(matcher);
|
306 | var idx = isArray(collection) ? -1 : undefined;
|
307 | forEach(collection, function (val, key) {
|
308 | if (matcher(val, key)) {
|
309 | idx = key;
|
310 | return false;
|
311 | }
|
312 | });
|
313 | return idx;
|
314 | }
|
315 | |
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 | function filter(collection, matcher) {
|
325 | var result = [];
|
326 | forEach(collection, function (val, key) {
|
327 | if (matcher(val, key)) {
|
328 | result.push(val);
|
329 | }
|
330 | });
|
331 | return result;
|
332 | }
|
333 | |
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 | function forEach(collection, iterator) {
|
344 | var val, result;
|
345 |
|
346 | if (isUndefined(collection)) {
|
347 | return;
|
348 | }
|
349 |
|
350 | var convertKey = isArray(collection) ? toNum : identity;
|
351 |
|
352 | for (var key in collection) {
|
353 | if (has(collection, key)) {
|
354 | val = collection[key];
|
355 | result = iterator(val, convertKey(key));
|
356 |
|
357 | if (result === false) {
|
358 | return val;
|
359 | }
|
360 | }
|
361 | }
|
362 | }
|
363 | |
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 | function without(arr, matcher) {
|
373 | if (isUndefined(arr)) {
|
374 | return [];
|
375 | }
|
376 |
|
377 | ensureArray(arr);
|
378 | matcher = toMatcher(matcher);
|
379 | return arr.filter(function (el, idx) {
|
380 | return !matcher(el, idx);
|
381 | });
|
382 | }
|
383 | |
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 | function reduce(collection, iterator, result) {
|
394 | forEach(collection, function (value, idx) {
|
395 | result = iterator(result, value, idx);
|
396 | });
|
397 | return result;
|
398 | }
|
399 | |
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 | function every(collection, matcher) {
|
410 | return !!reduce(collection, function (matches, val, key) {
|
411 | return matches && matcher(val, key);
|
412 | }, true);
|
413 | }
|
414 | |
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 | function some(collection, matcher) {
|
425 | return !!find(collection, matcher);
|
426 | }
|
427 | |
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 | function map(collection, fn) {
|
438 | var result = [];
|
439 | forEach(collection, function (val, key) {
|
440 | result.push(fn(val, key));
|
441 | });
|
442 | return result;
|
443 | }
|
444 | |
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 | function keys(collection) {
|
453 | return collection && Object.keys(collection) || [];
|
454 | }
|
455 | |
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 | function size(collection) {
|
464 | return keys(collection).length;
|
465 | }
|
466 | |
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 | function values(collection) {
|
475 | return map(collection, function (val) {
|
476 | return val;
|
477 | });
|
478 | }
|
479 | |
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 | function groupBy(collection, extractor) {
|
489 | var grouped = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
490 | extractor = toExtractor(extractor);
|
491 | forEach(collection, function (val) {
|
492 | var discriminator = extractor(val) || '_';
|
493 | var group = grouped[discriminator];
|
494 |
|
495 | if (!group) {
|
496 | group = grouped[discriminator] = [];
|
497 | }
|
498 |
|
499 | group.push(val);
|
500 | });
|
501 | return grouped;
|
502 | }
|
503 | function uniqueBy(extractor) {
|
504 | extractor = toExtractor(extractor);
|
505 | var grouped = {};
|
506 |
|
507 | for (var _len = arguments.length, collections = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
508 | collections[_key - 1] = arguments[_key];
|
509 | }
|
510 |
|
511 | forEach(collections, function (c) {
|
512 | return groupBy(c, extractor, grouped);
|
513 | });
|
514 | var result = map(grouped, function (val, key) {
|
515 | return val[0];
|
516 | });
|
517 | return result;
|
518 | }
|
519 | var unionBy = uniqueBy;
|
520 | |
521 |
|
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 |
|
529 | function sortBy(collection, extractor) {
|
530 | extractor = toExtractor(extractor);
|
531 | var sorted = [];
|
532 | forEach(collection, function (value, key) {
|
533 | var disc = extractor(value, key);
|
534 | var entry = {
|
535 | d: disc,
|
536 | v: value
|
537 | };
|
538 |
|
539 | for (var idx = 0; idx < sorted.length; idx++) {
|
540 | var d = sorted[idx].d;
|
541 |
|
542 | if (disc < d) {
|
543 | sorted.splice(idx, 0, entry);
|
544 | return;
|
545 | }
|
546 | }
|
547 |
|
548 |
|
549 | sorted.push(entry);
|
550 | });
|
551 | return map(sorted, function (e) {
|
552 | return e.v;
|
553 | });
|
554 | }
|
555 | |
556 |
|
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 |
|
569 | function matchPattern(pattern) {
|
570 | return function (el) {
|
571 | return every(pattern, function (val, key) {
|
572 | return el[key] === val;
|
573 | });
|
574 | };
|
575 | }
|
576 |
|
577 | function toExtractor(extractor) {
|
578 | return isFunction(extractor) ? extractor : function (e) {
|
579 | return e[extractor];
|
580 | };
|
581 | }
|
582 |
|
583 | function toMatcher(matcher) {
|
584 | return isFunction(matcher) ? matcher : function (e) {
|
585 | return e === matcher;
|
586 | };
|
587 | }
|
588 |
|
589 | function identity(arg) {
|
590 | return arg;
|
591 | }
|
592 |
|
593 | function toNum(arg) {
|
594 | return Number(arg);
|
595 | }
|
596 |
|
597 | |
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 | function debounce(fn, timeout) {
|
607 | var timer;
|
608 | var lastArgs;
|
609 | var lastThis;
|
610 | var lastNow;
|
611 |
|
612 | function fire() {
|
613 | var now = Date.now();
|
614 | var scheduledDiff = lastNow + timeout - now;
|
615 |
|
616 | if (scheduledDiff > 0) {
|
617 | return schedule(scheduledDiff);
|
618 | }
|
619 |
|
620 | fn.apply(lastThis, lastArgs);
|
621 | timer = lastNow = lastArgs = lastThis = undefined;
|
622 | }
|
623 |
|
624 | function schedule(timeout) {
|
625 | timer = setTimeout(fire, timeout);
|
626 | }
|
627 |
|
628 | return function () {
|
629 | lastNow = Date.now();
|
630 |
|
631 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
632 | args[_key] = arguments[_key];
|
633 | }
|
634 |
|
635 | lastArgs = args;
|
636 | lastThis = this;
|
637 |
|
638 | if (!timer) {
|
639 | schedule(timeout);
|
640 | }
|
641 | };
|
642 | }
|
643 | |
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 | function bind(fn, target) {
|
653 | return fn.bind(target);
|
654 | }
|
655 |
|
656 | function _extends() {
|
657 | _extends = Object.assign || function (target) {
|
658 | for (var i = 1; i < arguments.length; i++) {
|
659 | var source = arguments[i];
|
660 |
|
661 | for (var key in source) {
|
662 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
663 | target[key] = source[key];
|
664 | }
|
665 | }
|
666 | }
|
667 |
|
668 | return target;
|
669 | };
|
670 |
|
671 | return _extends.apply(this, arguments);
|
672 | }
|
673 |
|
674 | |
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 | function assign(target) {
|
684 | for (var _len = arguments.length, others = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
685 | others[_key - 1] = arguments[_key];
|
686 | }
|
687 |
|
688 | return _extends.apply(void 0, [target].concat(others));
|
689 | }
|
690 | |
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 | function pick(target, properties) {
|
700 | var result = {};
|
701 | var obj = Object(target);
|
702 | forEach(properties, function (prop) {
|
703 | if (prop in obj) {
|
704 | result[prop] = target[prop];
|
705 | }
|
706 | });
|
707 | return result;
|
708 | }
|
709 | |
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 |
|
717 |
|
718 | function omit(target, properties) {
|
719 | var result = {};
|
720 | var obj = Object(target);
|
721 | forEach(obj, function (prop, key) {
|
722 | if (properties.indexOf(key) === -1) {
|
723 | result[key] = prop;
|
724 | }
|
725 | });
|
726 | return result;
|
727 | }
|
728 |
|
729 | |
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 | function attr(el, name, val) {
|
738 |
|
739 | if (arguments.length == 2) {
|
740 | return el.getAttribute(name);
|
741 | }
|
742 |
|
743 |
|
744 | if (val === null) {
|
745 | return el.removeAttribute(name);
|
746 | }
|
747 |
|
748 |
|
749 | el.setAttribute(name, val);
|
750 |
|
751 | return el;
|
752 | }
|
753 |
|
754 | var indexOf = [].indexOf;
|
755 |
|
756 | var indexof = function(arr, obj){
|
757 | if (indexOf) return arr.indexOf(obj);
|
758 | for (var i = 0; i < arr.length; ++i) {
|
759 | if (arr[i] === obj) return i;
|
760 | }
|
761 | return -1;
|
762 | };
|
763 |
|
764 | |
765 |
|
766 |
|
767 |
|
768 |
|
769 |
|
770 | |
771 |
|
772 |
|
773 |
|
774 | var re = /\s+/;
|
775 |
|
776 | |
777 |
|
778 |
|
779 |
|
780 | var toString = Object.prototype.toString;
|
781 |
|
782 | |
783 |
|
784 |
|
785 |
|
786 |
|
787 |
|
788 |
|
789 |
|
790 | function classes(el) {
|
791 | return new ClassList(el);
|
792 | }
|
793 |
|
794 | |
795 |
|
796 |
|
797 |
|
798 |
|
799 |
|
800 |
|
801 | function ClassList(el) {
|
802 | if (!el || !el.nodeType) {
|
803 | throw new Error('A DOM element reference is required');
|
804 | }
|
805 | this.el = el;
|
806 | this.list = el.classList;
|
807 | }
|
808 |
|
809 | |
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 | ClassList.prototype.add = function (name) {
|
818 |
|
819 | if (this.list) {
|
820 | this.list.add(name);
|
821 | return this;
|
822 | }
|
823 |
|
824 |
|
825 | var arr = this.array();
|
826 | var i = indexof(arr, name);
|
827 | if (!~i) arr.push(name);
|
828 | this.el.className = arr.join(' ');
|
829 | return this;
|
830 | };
|
831 |
|
832 | |
833 |
|
834 |
|
835 |
|
836 |
|
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 | ClassList.prototype.remove = function (name) {
|
843 | if ('[object RegExp]' == toString.call(name)) {
|
844 | return this.removeMatching(name);
|
845 | }
|
846 |
|
847 |
|
848 | if (this.list) {
|
849 | this.list.remove(name);
|
850 | return this;
|
851 | }
|
852 |
|
853 |
|
854 | var arr = this.array();
|
855 | var i = indexof(arr, name);
|
856 | if (~i) arr.splice(i, 1);
|
857 | this.el.className = arr.join(' ');
|
858 | return this;
|
859 | };
|
860 |
|
861 | |
862 |
|
863 |
|
864 |
|
865 |
|
866 |
|
867 |
|
868 |
|
869 | ClassList.prototype.removeMatching = function (re) {
|
870 | var arr = this.array();
|
871 | for (var i = 0; i < arr.length; i++) {
|
872 | if (re.test(arr[i])) {
|
873 | this.remove(arr[i]);
|
874 | }
|
875 | }
|
876 | return this;
|
877 | };
|
878 |
|
879 | |
880 |
|
881 |
|
882 |
|
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 | ClassList.prototype.toggle = function (name, force) {
|
892 |
|
893 | if (this.list) {
|
894 | if ('undefined' !== typeof force) {
|
895 | if (force !== this.list.toggle(name, force)) {
|
896 | this.list.toggle(name);
|
897 | }
|
898 | } else {
|
899 | this.list.toggle(name);
|
900 | }
|
901 | return this;
|
902 | }
|
903 |
|
904 |
|
905 | if ('undefined' !== typeof force) {
|
906 | if (!force) {
|
907 | this.remove(name);
|
908 | } else {
|
909 | this.add(name);
|
910 | }
|
911 | } else {
|
912 | if (this.has(name)) {
|
913 | this.remove(name);
|
914 | } else {
|
915 | this.add(name);
|
916 | }
|
917 | }
|
918 |
|
919 | return this;
|
920 | };
|
921 |
|
922 | |
923 |
|
924 |
|
925 |
|
926 |
|
927 |
|
928 |
|
929 | ClassList.prototype.array = function () {
|
930 | var className = this.el.getAttribute('class') || '';
|
931 | var str = className.replace(/^\s+|\s+$/g, '');
|
932 | var arr = str.split(re);
|
933 | if ('' === arr[0]) arr.shift();
|
934 | return arr;
|
935 | };
|
936 |
|
937 | |
938 |
|
939 |
|
940 |
|
941 |
|
942 |
|
943 |
|
944 |
|
945 | ClassList.prototype.has = ClassList.prototype.contains = function (name) {
|
946 | return this.list ? this.list.contains(name) : !!~indexof(this.array(), name);
|
947 | };
|
948 |
|
949 | |
950 |
|
951 |
|
952 | function clear(el) {
|
953 |
|
954 | var c;
|
955 |
|
956 | while (el.childNodes.length) {
|
957 | c = el.childNodes[0];
|
958 | el.removeChild(c);
|
959 | }
|
960 |
|
961 | return el;
|
962 | }
|
963 |
|
964 | |
965 |
|
966 |
|
967 |
|
968 | var proto = Element.prototype;
|
969 |
|
970 | |
971 |
|
972 |
|
973 |
|
974 | var vendor = proto.matchesSelector
|
975 | || proto.webkitMatchesSelector
|
976 | || proto.mozMatchesSelector
|
977 | || proto.msMatchesSelector
|
978 | || proto.oMatchesSelector;
|
979 |
|
980 | |
981 |
|
982 |
|
983 |
|
984 | var matchesSelector = match;
|
985 |
|
986 | |
987 |
|
988 |
|
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 | function match(el, selector) {
|
996 | if (vendor) return vendor.call(el, selector);
|
997 | var nodes = el.parentNode.querySelectorAll(selector);
|
998 | for (var i = 0; i < nodes.length; ++i) {
|
999 | if (nodes[i] == el) return true;
|
1000 | }
|
1001 | return false;
|
1002 | }
|
1003 |
|
1004 | var closest = function (element, selector, checkYoSelf) {
|
1005 | var parent = checkYoSelf ? element : element.parentNode;
|
1006 |
|
1007 | while (parent && parent !== document) {
|
1008 | if (matchesSelector(parent, selector)) return parent;
|
1009 | parent = parent.parentNode;
|
1010 | }
|
1011 | };
|
1012 |
|
1013 | var bind$1 = window.addEventListener ? 'addEventListener' : 'attachEvent',
|
1014 | unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
|
1015 | prefix = bind$1 !== 'addEventListener' ? 'on' : '';
|
1016 |
|
1017 | |
1018 |
|
1019 |
|
1020 |
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 | var bind_1 = function(el, type, fn, capture){
|
1029 | el[bind$1](prefix + type, fn, capture || false);
|
1030 | return fn;
|
1031 | };
|
1032 |
|
1033 | |
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 | var unbind_1 = function(el, type, fn, capture){
|
1045 | el[unbind](prefix + type, fn, capture || false);
|
1046 | return fn;
|
1047 | };
|
1048 |
|
1049 | var componentEvent = {
|
1050 | bind: bind_1,
|
1051 | unbind: unbind_1
|
1052 | };
|
1053 |
|
1054 | |
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 | |
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 | var forceCaptureEvents = ['focus', 'blur'];
|
1077 |
|
1078 | var bind$1$1 = function(el, selector, type, fn, capture){
|
1079 | if (forceCaptureEvents.indexOf(type) !== -1) capture = true;
|
1080 |
|
1081 | return componentEvent.bind(el, type, function(e){
|
1082 | var target = e.target || e.srcElement;
|
1083 | e.delegateTarget = closest(target, selector, true);
|
1084 | if (e.delegateTarget) fn.call(el, e);
|
1085 | }, capture);
|
1086 | };
|
1087 |
|
1088 | |
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 |
|
1097 |
|
1098 | var unbind$1 = function(el, type, fn, capture){
|
1099 | if (forceCaptureEvents.indexOf(type) !== -1) capture = true;
|
1100 |
|
1101 | componentEvent.unbind(el, type, fn, capture);
|
1102 | };
|
1103 |
|
1104 | var delegateEvents = {
|
1105 | bind: bind$1$1,
|
1106 | unbind: unbind$1
|
1107 | };
|
1108 |
|
1109 | |
1110 |
|
1111 |
|
1112 |
|
1113 | var domify = parse;
|
1114 |
|
1115 | |
1116 |
|
1117 |
|
1118 |
|
1119 | var innerHTMLBug = false;
|
1120 | var bugTestDiv;
|
1121 | if (typeof document !== 'undefined') {
|
1122 | bugTestDiv = document.createElement('div');
|
1123 |
|
1124 | bugTestDiv.innerHTML = ' <link/><table></table><a href="/a">a</a><input type="checkbox"/>';
|
1125 |
|
1126 |
|
1127 | innerHTMLBug = !bugTestDiv.getElementsByTagName('link').length;
|
1128 | bugTestDiv = undefined;
|
1129 | }
|
1130 |
|
1131 | |
1132 |
|
1133 |
|
1134 |
|
1135 | var map$1 = {
|
1136 | legend: [1, '<fieldset>', '</fieldset>'],
|
1137 | tr: [2, '<table><tbody>', '</tbody></table>'],
|
1138 | col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
|
1139 |
|
1140 |
|
1141 | _default: innerHTMLBug ? [1, 'X<div>', '</div>'] : [0, '', '']
|
1142 | };
|
1143 |
|
1144 | map$1.td =
|
1145 | map$1.th = [3, '<table><tbody><tr>', '</tr></tbody></table>'];
|
1146 |
|
1147 | map$1.option =
|
1148 | map$1.optgroup = [1, '<select multiple="multiple">', '</select>'];
|
1149 |
|
1150 | map$1.thead =
|
1151 | map$1.tbody =
|
1152 | map$1.colgroup =
|
1153 | map$1.caption =
|
1154 | map$1.tfoot = [1, '<table>', '</table>'];
|
1155 |
|
1156 | map$1.polyline =
|
1157 | map$1.ellipse =
|
1158 | map$1.polygon =
|
1159 | map$1.circle =
|
1160 | map$1.text =
|
1161 | map$1.line =
|
1162 | map$1.path =
|
1163 | map$1.rect =
|
1164 | map$1.g = [1, '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">','</svg>'];
|
1165 |
|
1166 | |
1167 |
|
1168 |
|
1169 |
|
1170 |
|
1171 |
|
1172 |
|
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 | function parse(html, doc) {
|
1178 | if ('string' != typeof html) throw new TypeError('String expected');
|
1179 |
|
1180 |
|
1181 | if (!doc) doc = document;
|
1182 |
|
1183 |
|
1184 | var m = /<([\w:]+)/.exec(html);
|
1185 | if (!m) return doc.createTextNode(html);
|
1186 |
|
1187 | html = html.replace(/^\s+|\s+$/g, '');
|
1188 |
|
1189 | var tag = m[1];
|
1190 |
|
1191 |
|
1192 | if (tag == 'body') {
|
1193 | var el = doc.createElement('html');
|
1194 | el.innerHTML = html;
|
1195 | return el.removeChild(el.lastChild);
|
1196 | }
|
1197 |
|
1198 |
|
1199 | var wrap = map$1[tag] || map$1._default;
|
1200 | var depth = wrap[0];
|
1201 | var prefix = wrap[1];
|
1202 | var suffix = wrap[2];
|
1203 | var el = doc.createElement('div');
|
1204 | el.innerHTML = prefix + html + suffix;
|
1205 | while (depth--) el = el.lastChild;
|
1206 |
|
1207 |
|
1208 | if (el.firstChild == el.lastChild) {
|
1209 | return el.removeChild(el.firstChild);
|
1210 | }
|
1211 |
|
1212 |
|
1213 | var fragment = doc.createDocumentFragment();
|
1214 | while (el.firstChild) {
|
1215 | fragment.appendChild(el.removeChild(el.firstChild));
|
1216 | }
|
1217 |
|
1218 | return fragment;
|
1219 | }
|
1220 |
|
1221 | var proto$1 = typeof Element !== 'undefined' ? Element.prototype : {};
|
1222 | var vendor$1 = proto$1.matches
|
1223 | || proto$1.matchesSelector
|
1224 | || proto$1.webkitMatchesSelector
|
1225 | || proto$1.mozMatchesSelector
|
1226 | || proto$1.msMatchesSelector
|
1227 | || proto$1.oMatchesSelector;
|
1228 |
|
1229 | var matchesSelector$1 = match$1;
|
1230 |
|
1231 | |
1232 |
|
1233 |
|
1234 |
|
1235 |
|
1236 |
|
1237 |
|
1238 |
|
1239 |
|
1240 | function match$1(el, selector) {
|
1241 | if (!el || el.nodeType !== 1) return false;
|
1242 | if (vendor$1) return vendor$1.call(el, selector);
|
1243 | var nodes = el.parentNode.querySelectorAll(selector);
|
1244 | for (var i = 0; i < nodes.length; i++) {
|
1245 | if (nodes[i] == el) return true;
|
1246 | }
|
1247 | return false;
|
1248 | }
|
1249 |
|
1250 | function query(selector, el) {
|
1251 | el = el || document;
|
1252 |
|
1253 | return el.querySelector(selector);
|
1254 | }
|
1255 |
|
1256 | function all(selector, el) {
|
1257 | el = el || document;
|
1258 |
|
1259 | return el.querySelectorAll(selector);
|
1260 | }
|
1261 |
|
1262 | function remove(el) {
|
1263 | el.parentNode && el.parentNode.removeChild(el);
|
1264 | }
|
1265 |
|
1266 | function ensureImported(element, target) {
|
1267 |
|
1268 | if (element.ownerDocument !== target.ownerDocument) {
|
1269 | try {
|
1270 |
|
1271 | return target.ownerDocument.importNode(element, true);
|
1272 | } catch (e) {
|
1273 |
|
1274 | }
|
1275 | }
|
1276 |
|
1277 | return element;
|
1278 | }
|
1279 |
|
1280 | |
1281 |
|
1282 |
|
1283 |
|
1284 | |
1285 |
|
1286 |
|
1287 |
|
1288 |
|
1289 |
|
1290 |
|
1291 |
|
1292 | function appendTo(element, target) {
|
1293 | return target.appendChild(ensureImported(element, target));
|
1294 | }
|
1295 |
|
1296 | |
1297 |
|
1298 |
|
1299 |
|
1300 | |
1301 |
|
1302 |
|
1303 |
|
1304 |
|
1305 |
|
1306 |
|
1307 |
|
1308 | function append(target, node) {
|
1309 | appendTo(node, target);
|
1310 | return target;
|
1311 | }
|
1312 |
|
1313 | |
1314 |
|
1315 |
|
1316 |
|
1317 | var LENGTH_ATTR = 2;
|
1318 |
|
1319 | var CSS_PROPERTIES = {
|
1320 | 'alignment-baseline': 1,
|
1321 | 'baseline-shift': 1,
|
1322 | 'clip': 1,
|
1323 | 'clip-path': 1,
|
1324 | 'clip-rule': 1,
|
1325 | 'color': 1,
|
1326 | 'color-interpolation': 1,
|
1327 | 'color-interpolation-filters': 1,
|
1328 | 'color-profile': 1,
|
1329 | 'color-rendering': 1,
|
1330 | 'cursor': 1,
|
1331 | 'direction': 1,
|
1332 | 'display': 1,
|
1333 | 'dominant-baseline': 1,
|
1334 | 'enable-background': 1,
|
1335 | 'fill': 1,
|
1336 | 'fill-opacity': 1,
|
1337 | 'fill-rule': 1,
|
1338 | 'filter': 1,
|
1339 | 'flood-color': 1,
|
1340 | 'flood-opacity': 1,
|
1341 | 'font': 1,
|
1342 | 'font-family': 1,
|
1343 | 'font-size': LENGTH_ATTR,
|
1344 | 'font-size-adjust': 1,
|
1345 | 'font-stretch': 1,
|
1346 | 'font-style': 1,
|
1347 | 'font-variant': 1,
|
1348 | 'font-weight': 1,
|
1349 | 'glyph-orientation-horizontal': 1,
|
1350 | 'glyph-orientation-vertical': 1,
|
1351 | 'image-rendering': 1,
|
1352 | 'kerning': 1,
|
1353 | 'letter-spacing': 1,
|
1354 | 'lighting-color': 1,
|
1355 | 'marker': 1,
|
1356 | 'marker-end': 1,
|
1357 | 'marker-mid': 1,
|
1358 | 'marker-start': 1,
|
1359 | 'mask': 1,
|
1360 | 'opacity': 1,
|
1361 | 'overflow': 1,
|
1362 | 'pointer-events': 1,
|
1363 | 'shape-rendering': 1,
|
1364 | 'stop-color': 1,
|
1365 | 'stop-opacity': 1,
|
1366 | 'stroke': 1,
|
1367 | 'stroke-dasharray': 1,
|
1368 | 'stroke-dashoffset': 1,
|
1369 | 'stroke-linecap': 1,
|
1370 | 'stroke-linejoin': 1,
|
1371 | 'stroke-miterlimit': 1,
|
1372 | 'stroke-opacity': 1,
|
1373 | 'stroke-width': LENGTH_ATTR,
|
1374 | 'text-anchor': 1,
|
1375 | 'text-decoration': 1,
|
1376 | 'text-rendering': 1,
|
1377 | 'unicode-bidi': 1,
|
1378 | 'visibility': 1,
|
1379 | 'word-spacing': 1,
|
1380 | 'writing-mode': 1
|
1381 | };
|
1382 |
|
1383 |
|
1384 | function getAttribute(node, name) {
|
1385 | if (CSS_PROPERTIES[name]) {
|
1386 | return node.style[name];
|
1387 | } else {
|
1388 | return node.getAttributeNS(null, name);
|
1389 | }
|
1390 | }
|
1391 |
|
1392 | function setAttribute(node, name, value) {
|
1393 | var hyphenated = name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
1394 |
|
1395 | var type = CSS_PROPERTIES[hyphenated];
|
1396 |
|
1397 | if (type) {
|
1398 |
|
1399 | if (type === LENGTH_ATTR && typeof value === 'number') {
|
1400 | value = String(value) + 'px';
|
1401 | }
|
1402 |
|
1403 | node.style[hyphenated] = value;
|
1404 | } else {
|
1405 | node.setAttributeNS(null, name, value);
|
1406 | }
|
1407 | }
|
1408 |
|
1409 | function setAttributes(node, attrs) {
|
1410 |
|
1411 | var names = Object.keys(attrs), i, name;
|
1412 |
|
1413 | for (i = 0, name; (name = names[i]); i++) {
|
1414 | setAttribute(node, name, attrs[name]);
|
1415 | }
|
1416 | }
|
1417 |
|
1418 | |
1419 |
|
1420 |
|
1421 |
|
1422 |
|
1423 |
|
1424 |
|
1425 |
|
1426 |
|
1427 |
|
1428 | function attr$1(node, name, value) {
|
1429 | if (typeof name === 'string') {
|
1430 | if (value !== undefined) {
|
1431 | setAttribute(node, name, value);
|
1432 | } else {
|
1433 | return getAttribute(node, name);
|
1434 | }
|
1435 | } else {
|
1436 | setAttributes(node, name);
|
1437 | }
|
1438 |
|
1439 | return node;
|
1440 | }
|
1441 |
|
1442 | |
1443 |
|
1444 |
|
1445 | function index(arr, obj) {
|
1446 | if (arr.indexOf) {
|
1447 | return arr.indexOf(obj);
|
1448 | }
|
1449 |
|
1450 |
|
1451 | for (var i = 0; i < arr.length; ++i) {
|
1452 | if (arr[i] === obj) {
|
1453 | return i;
|
1454 | }
|
1455 | }
|
1456 |
|
1457 | return -1;
|
1458 | }
|
1459 |
|
1460 | var re$1 = /\s+/;
|
1461 |
|
1462 | var toString$1 = Object.prototype.toString;
|
1463 |
|
1464 | function defined(o) {
|
1465 | return typeof o !== 'undefined';
|
1466 | }
|
1467 |
|
1468 | |
1469 |
|
1470 |
|
1471 |
|
1472 |
|
1473 |
|
1474 |
|
1475 |
|
1476 | function classes$1(el) {
|
1477 | return new ClassList$1(el);
|
1478 | }
|
1479 |
|
1480 | function ClassList$1(el) {
|
1481 | if (!el || !el.nodeType) {
|
1482 | throw new Error('A DOM element reference is required');
|
1483 | }
|
1484 | this.el = el;
|
1485 | this.list = el.classList;
|
1486 | }
|
1487 |
|
1488 | |
1489 |
|
1490 |
|
1491 |
|
1492 |
|
1493 |
|
1494 |
|
1495 |
|
1496 | ClassList$1.prototype.add = function(name) {
|
1497 |
|
1498 |
|
1499 | if (this.list) {
|
1500 | this.list.add(name);
|
1501 | return this;
|
1502 | }
|
1503 |
|
1504 |
|
1505 | var arr = this.array();
|
1506 | var i = index(arr, name);
|
1507 | if (!~i) {
|
1508 | arr.push(name);
|
1509 | }
|
1510 |
|
1511 | if (defined(this.el.className.baseVal)) {
|
1512 | this.el.className.baseVal = arr.join(' ');
|
1513 | } else {
|
1514 | this.el.className = arr.join(' ');
|
1515 | }
|
1516 |
|
1517 | return this;
|
1518 | };
|
1519 |
|
1520 | |
1521 |
|
1522 |
|
1523 |
|
1524 |
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 |
|
1530 | ClassList$1.prototype.remove = function(name) {
|
1531 | if ('[object RegExp]' === toString$1.call(name)) {
|
1532 | return this.removeMatching(name);
|
1533 | }
|
1534 |
|
1535 |
|
1536 | if (this.list) {
|
1537 | this.list.remove(name);
|
1538 | return this;
|
1539 | }
|
1540 |
|
1541 |
|
1542 | var arr = this.array();
|
1543 | var i = index(arr, name);
|
1544 | if (~i) {
|
1545 | arr.splice(i, 1);
|
1546 | }
|
1547 | this.el.className.baseVal = arr.join(' ');
|
1548 | return this;
|
1549 | };
|
1550 |
|
1551 | |
1552 |
|
1553 |
|
1554 |
|
1555 |
|
1556 |
|
1557 |
|
1558 |
|
1559 | ClassList$1.prototype.removeMatching = function(re) {
|
1560 | var arr = this.array();
|
1561 | for (var i = 0; i < arr.length; i++) {
|
1562 | if (re.test(arr[i])) {
|
1563 | this.remove(arr[i]);
|
1564 | }
|
1565 | }
|
1566 | return this;
|
1567 | };
|
1568 |
|
1569 | |
1570 |
|
1571 |
|
1572 |
|
1573 |
|
1574 |
|
1575 |
|
1576 |
|
1577 |
|
1578 |
|
1579 |
|
1580 |
|
1581 | ClassList$1.prototype.toggle = function(name, force) {
|
1582 |
|
1583 | if (this.list) {
|
1584 | if (defined(force)) {
|
1585 | if (force !== this.list.toggle(name, force)) {
|
1586 | this.list.toggle(name);
|
1587 | }
|
1588 | } else {
|
1589 | this.list.toggle(name);
|
1590 | }
|
1591 | return this;
|
1592 | }
|
1593 |
|
1594 |
|
1595 | if (defined(force)) {
|
1596 | if (!force) {
|
1597 | this.remove(name);
|
1598 | } else {
|
1599 | this.add(name);
|
1600 | }
|
1601 | } else {
|
1602 | if (this.has(name)) {
|
1603 | this.remove(name);
|
1604 | } else {
|
1605 | this.add(name);
|
1606 | }
|
1607 | }
|
1608 |
|
1609 | return this;
|
1610 | };
|
1611 |
|
1612 | |
1613 |
|
1614 |
|
1615 |
|
1616 |
|
1617 |
|
1618 |
|
1619 | ClassList$1.prototype.array = function() {
|
1620 | var className = this.el.getAttribute('class') || '';
|
1621 | var str = className.replace(/^\s+|\s+$/g, '');
|
1622 | var arr = str.split(re$1);
|
1623 | if ('' === arr[0]) {
|
1624 | arr.shift();
|
1625 | }
|
1626 | return arr;
|
1627 | };
|
1628 |
|
1629 | |
1630 |
|
1631 |
|
1632 |
|
1633 |
|
1634 |
|
1635 |
|
1636 |
|
1637 | ClassList$1.prototype.has =
|
1638 | ClassList$1.prototype.contains = function(name) {
|
1639 | return (
|
1640 | this.list ?
|
1641 | this.list.contains(name) :
|
1642 | !! ~index(this.array(), name)
|
1643 | );
|
1644 | };
|
1645 |
|
1646 | function remove$1(element) {
|
1647 | var parent = element.parentNode;
|
1648 |
|
1649 | if (parent) {
|
1650 | parent.removeChild(element);
|
1651 | }
|
1652 |
|
1653 | return element;
|
1654 | }
|
1655 |
|
1656 | |
1657 |
|
1658 |
|
1659 |
|
1660 | |
1661 |
|
1662 |
|
1663 |
|
1664 |
|
1665 |
|
1666 | function clear$1(element) {
|
1667 | var child;
|
1668 |
|
1669 | while ((child = element.firstChild)) {
|
1670 | remove$1(child);
|
1671 | }
|
1672 |
|
1673 | return element;
|
1674 | }
|
1675 |
|
1676 | function clone(element) {
|
1677 | return element.cloneNode(true);
|
1678 | }
|
1679 |
|
1680 | var ns = {
|
1681 | svg: 'http://www.w3.org/2000/svg'
|
1682 | };
|
1683 |
|
1684 | |
1685 |
|
1686 |
|
1687 |
|
1688 | var SVG_START = '<svg xmlns="' + ns.svg + '"';
|
1689 |
|
1690 | function parse$1(svg) {
|
1691 |
|
1692 | var unwrap = false;
|
1693 |
|
1694 |
|
1695 | if (svg.substring(0, 4) === '<svg') {
|
1696 | if (svg.indexOf(ns.svg) === -1) {
|
1697 | svg = SVG_START + svg.substring(4);
|
1698 | }
|
1699 | } else {
|
1700 |
|
1701 | svg = SVG_START + '>' + svg + '</svg>';
|
1702 | unwrap = true;
|
1703 | }
|
1704 |
|
1705 | var parsed = parseDocument(svg);
|
1706 |
|
1707 | if (!unwrap) {
|
1708 | return parsed;
|
1709 | }
|
1710 |
|
1711 | var fragment = document.createDocumentFragment();
|
1712 |
|
1713 | var parent = parsed.firstChild;
|
1714 |
|
1715 | while (parent.firstChild) {
|
1716 | fragment.appendChild(parent.firstChild);
|
1717 | }
|
1718 |
|
1719 | return fragment;
|
1720 | }
|
1721 |
|
1722 | function parseDocument(svg) {
|
1723 |
|
1724 | var parser;
|
1725 |
|
1726 |
|
1727 | parser = new DOMParser();
|
1728 | parser.async = false;
|
1729 |
|
1730 | return parser.parseFromString(svg, 'text/xml');
|
1731 | }
|
1732 |
|
1733 | |
1734 |
|
1735 |
|
1736 |
|
1737 |
|
1738 | |
1739 |
|
1740 |
|
1741 |
|
1742 |
|
1743 |
|
1744 |
|
1745 |
|
1746 | function create(name, attrs) {
|
1747 | var element;
|
1748 |
|
1749 | if (name.charAt(0) === '<') {
|
1750 | element = parse$1(name).firstChild;
|
1751 | element = document.importNode(element, true);
|
1752 | } else {
|
1753 | element = document.createElementNS(ns.svg, name);
|
1754 | }
|
1755 |
|
1756 | if (attrs) {
|
1757 | attr$1(element, attrs);
|
1758 | }
|
1759 |
|
1760 | return element;
|
1761 | }
|
1762 |
|
1763 | |
1764 |
|
1765 |
|
1766 |
|
1767 |
|
1768 | var node = create('svg');
|
1769 |
|
1770 | function extend(object, props) {
|
1771 | var i, k, keys = Object.keys(props);
|
1772 |
|
1773 | for (i = 0; (k = keys[i]); i++) {
|
1774 | object[k] = props[k];
|
1775 | }
|
1776 |
|
1777 | return object;
|
1778 | }
|
1779 |
|
1780 | |
1781 |
|
1782 |
|
1783 |
|
1784 |
|
1785 |
|
1786 |
|
1787 |
|
1788 |
|
1789 |
|
1790 |
|
1791 | function createMatrix(a, b, c, d, e, f) {
|
1792 | var matrix = node.createSVGMatrix();
|
1793 |
|
1794 | switch (arguments.length) {
|
1795 | case 0:
|
1796 | return matrix;
|
1797 | case 1:
|
1798 | return extend(matrix, a);
|
1799 | case 6:
|
1800 | return extend(matrix, {
|
1801 | a: a,
|
1802 | b: b,
|
1803 | c: c,
|
1804 | d: d,
|
1805 | e: e,
|
1806 | f: f
|
1807 | });
|
1808 | }
|
1809 | }
|
1810 |
|
1811 | function createTransform(matrix) {
|
1812 | if (matrix) {
|
1813 | return node.createSVGTransformFromMatrix(matrix);
|
1814 | } else {
|
1815 | return node.createSVGTransform();
|
1816 | }
|
1817 | }
|
1818 |
|
1819 | |
1820 |
|
1821 |
|
1822 |
|
1823 | var TEXT_ENTITIES = /([&<>]{1})/g;
|
1824 | var ATTR_ENTITIES = /([\n\r"]{1})/g;
|
1825 |
|
1826 | var ENTITY_REPLACEMENT = {
|
1827 | '&': '&',
|
1828 | '<': '<',
|
1829 | '>': '>',
|
1830 | '"': '\''
|
1831 | };
|
1832 |
|
1833 | function escape(str, pattern) {
|
1834 |
|
1835 | function replaceFn(match, entity) {
|
1836 | return ENTITY_REPLACEMENT[entity] || entity;
|
1837 | }
|
1838 |
|
1839 | return str.replace(pattern, replaceFn);
|
1840 | }
|
1841 |
|
1842 | function serialize(node, output) {
|
1843 |
|
1844 | var i, len, attrMap, attrNode, childNodes;
|
1845 |
|
1846 | switch (node.nodeType) {
|
1847 |
|
1848 | case 3:
|
1849 |
|
1850 | output.push(escape(node.textContent, TEXT_ENTITIES));
|
1851 | break;
|
1852 |
|
1853 |
|
1854 | case 1:
|
1855 | output.push('<', node.tagName);
|
1856 |
|
1857 | if (node.hasAttributes()) {
|
1858 | attrMap = node.attributes;
|
1859 | for (i = 0, len = attrMap.length; i < len; ++i) {
|
1860 | attrNode = attrMap.item(i);
|
1861 | output.push(' ', attrNode.name, '="', escape(attrNode.value, ATTR_ENTITIES), '"');
|
1862 | }
|
1863 | }
|
1864 |
|
1865 | if (node.hasChildNodes()) {
|
1866 | output.push('>');
|
1867 | childNodes = node.childNodes;
|
1868 | for (i = 0, len = childNodes.length; i < len; ++i) {
|
1869 | serialize(childNodes.item(i), output);
|
1870 | }
|
1871 | output.push('</', node.tagName, '>');
|
1872 | } else {
|
1873 | output.push('/>');
|
1874 | }
|
1875 | break;
|
1876 |
|
1877 |
|
1878 | case 8:
|
1879 | output.push('<!--', escape(node.nodeValue, TEXT_ENTITIES), '-->');
|
1880 | break;
|
1881 |
|
1882 |
|
1883 | case 4:
|
1884 | output.push('<![CDATA[', node.nodeValue, ']]>');
|
1885 | break;
|
1886 |
|
1887 | default:
|
1888 | throw new Error('unable to handle node ' + node.nodeType);
|
1889 | }
|
1890 |
|
1891 | return output;
|
1892 | }
|
1893 |
|
1894 | |
1895 |
|
1896 |
|
1897 |
|
1898 |
|
1899 |
|
1900 | function set(element, svg) {
|
1901 |
|
1902 | var parsed = parse$1(svg);
|
1903 |
|
1904 |
|
1905 | clear$1(element);
|
1906 |
|
1907 | if (!svg) {
|
1908 | return;
|
1909 | }
|
1910 |
|
1911 | if (!isFragment(parsed)) {
|
1912 |
|
1913 | parsed = parsed.documentElement;
|
1914 | }
|
1915 |
|
1916 | var nodes = slice(parsed.childNodes);
|
1917 |
|
1918 |
|
1919 | for (var i = 0; i < nodes.length; i++) {
|
1920 | appendTo(nodes[i], element);
|
1921 | }
|
1922 |
|
1923 | }
|
1924 |
|
1925 | function get(element) {
|
1926 | var child = element.firstChild,
|
1927 | output = [];
|
1928 |
|
1929 | while (child) {
|
1930 | serialize(child, output);
|
1931 | child = child.nextSibling;
|
1932 | }
|
1933 |
|
1934 | return output.join('');
|
1935 | }
|
1936 |
|
1937 | function isFragment(node) {
|
1938 | return node.nodeName === '#document-fragment';
|
1939 | }
|
1940 |
|
1941 | function innerSVG(element, svg) {
|
1942 |
|
1943 | if (svg !== undefined) {
|
1944 |
|
1945 | try {
|
1946 | set(element, svg);
|
1947 | } catch (e) {
|
1948 | throw new Error('error parsing SVG: ' + e.message);
|
1949 | }
|
1950 |
|
1951 | return element;
|
1952 | } else {
|
1953 | return get(element);
|
1954 | }
|
1955 | }
|
1956 |
|
1957 |
|
1958 | function slice(arr) {
|
1959 | return Array.prototype.slice.call(arr);
|
1960 | }
|
1961 |
|
1962 | |
1963 |
|
1964 |
|
1965 |
|
1966 | function wrapMatrix(transformList, transform) {
|
1967 | if (transform instanceof SVGMatrix) {
|
1968 | return transformList.createSVGTransformFromMatrix(transform);
|
1969 | }
|
1970 |
|
1971 | return transform;
|
1972 | }
|
1973 |
|
1974 |
|
1975 | function setTransforms(transformList, transforms) {
|
1976 | var i, t;
|
1977 |
|
1978 | transformList.clear();
|
1979 |
|
1980 | for (i = 0; (t = transforms[i]); i++) {
|
1981 | transformList.appendItem(wrapMatrix(transformList, t));
|
1982 | }
|
1983 | }
|
1984 |
|
1985 | |
1986 |
|
1987 |
|
1988 |
|
1989 |
|
1990 |
|
1991 |
|
1992 |
|
1993 | function transform(node, transforms) {
|
1994 | var transformList = node.transform.baseVal;
|
1995 |
|
1996 | if (transforms) {
|
1997 |
|
1998 | if (!Array.isArray(transforms)) {
|
1999 | transforms = [ transforms ];
|
2000 | }
|
2001 |
|
2002 | setTransforms(transformList, transforms);
|
2003 | }
|
2004 |
|
2005 | return transformList.consolidate();
|
2006 | }
|
2007 |
|
2008 | var CLASS_PATTERN = /^class /;
|
2009 |
|
2010 | function isClass(fn) {
|
2011 | return CLASS_PATTERN.test(fn.toString());
|
2012 | }
|
2013 |
|
2014 | function isArray$1(obj) {
|
2015 | return Object.prototype.toString.call(obj) === '[object Array]';
|
2016 | }
|
2017 |
|
2018 | function annotate() {
|
2019 | var args = Array.prototype.slice.call(arguments);
|
2020 |
|
2021 | if (args.length === 1 && isArray$1(args[0])) {
|
2022 | args = args[0];
|
2023 | }
|
2024 |
|
2025 | var fn = args.pop();
|
2026 |
|
2027 | fn.$inject = args;
|
2028 |
|
2029 | return fn;
|
2030 | }
|
2031 |
|
2032 |
|
2033 |
|
2034 |
|
2035 |
|
2036 |
|
2037 |
|
2038 |
|
2039 |
|
2040 |
|
2041 |
|
2042 |
|
2043 |
|
2044 |
|
2045 | var CONSTRUCTOR_ARGS = /constructor\s*[^(]*\(\s*([^)]*)\)/m;
|
2046 | var FN_ARGS = /^function\s*[^(]*\(\s*([^)]*)\)/m;
|
2047 | var FN_ARG = /\/\*([^*]*)\*\//m;
|
2048 |
|
2049 | function parse$2(fn) {
|
2050 |
|
2051 | if (typeof fn !== 'function') {
|
2052 | throw new Error('Cannot annotate "' + fn + '". Expected a function!');
|
2053 | }
|
2054 |
|
2055 | var match = fn.toString().match(isClass(fn) ? CONSTRUCTOR_ARGS : FN_ARGS);
|
2056 |
|
2057 |
|
2058 | if (!match) {
|
2059 | return [];
|
2060 | }
|
2061 |
|
2062 | return match[1] && match[1].split(',').map(function (arg) {
|
2063 | match = arg.match(FN_ARG);
|
2064 | return match ? match[1].trim() : arg.trim();
|
2065 | }) || [];
|
2066 | }
|
2067 |
|
2068 | function Module() {
|
2069 | var providers = [];
|
2070 |
|
2071 | this.factory = function (name, factory) {
|
2072 | providers.push([name, 'factory', factory]);
|
2073 | return this;
|
2074 | };
|
2075 |
|
2076 | this.value = function (name, value) {
|
2077 | providers.push([name, 'value', value]);
|
2078 | return this;
|
2079 | };
|
2080 |
|
2081 | this.type = function (name, type) {
|
2082 | providers.push([name, 'type', type]);
|
2083 | return this;
|
2084 | };
|
2085 |
|
2086 | this.forEach = function (iterator) {
|
2087 | providers.forEach(iterator);
|
2088 | };
|
2089 | }
|
2090 |
|
2091 | 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; };
|
2092 |
|
2093 | 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); } }
|
2094 |
|
2095 | function Injector(modules, parent) {
|
2096 | parent = parent || {
|
2097 | get: function get(name, strict) {
|
2098 | currentlyResolving.push(name);
|
2099 |
|
2100 | if (strict === false) {
|
2101 | return null;
|
2102 | } else {
|
2103 | throw error('No provider for "' + name + '"!');
|
2104 | }
|
2105 | }
|
2106 | };
|
2107 |
|
2108 | var currentlyResolving = [];
|
2109 | var providers = this._providers = Object.create(parent._providers || null);
|
2110 | var instances = this._instances = Object.create(null);
|
2111 |
|
2112 | var self = instances.injector = this;
|
2113 |
|
2114 | var error = function error(msg) {
|
2115 | var stack = currentlyResolving.join(' -> ');
|
2116 | currentlyResolving.length = 0;
|
2117 | return new Error(stack ? msg + ' (Resolving: ' + stack + ')' : msg);
|
2118 | };
|
2119 |
|
2120 | |
2121 |
|
2122 |
|
2123 |
|
2124 |
|
2125 |
|
2126 |
|
2127 |
|
2128 | var get = function get(name, strict) {
|
2129 | if (!providers[name] && name.indexOf('.') !== -1) {
|
2130 | var parts = name.split('.');
|
2131 | var pivot = get(parts.shift());
|
2132 |
|
2133 | while (parts.length) {
|
2134 | pivot = pivot[parts.shift()];
|
2135 | }
|
2136 |
|
2137 | return pivot;
|
2138 | }
|
2139 |
|
2140 | if (hasProp(instances, name)) {
|
2141 | return instances[name];
|
2142 | }
|
2143 |
|
2144 | if (hasProp(providers, name)) {
|
2145 | if (currentlyResolving.indexOf(name) !== -1) {
|
2146 | currentlyResolving.push(name);
|
2147 | throw error('Cannot resolve circular dependency!');
|
2148 | }
|
2149 |
|
2150 | currentlyResolving.push(name);
|
2151 | instances[name] = providers[name][0](providers[name][1]);
|
2152 | currentlyResolving.pop();
|
2153 |
|
2154 | return instances[name];
|
2155 | }
|
2156 |
|
2157 | return parent.get(name, strict);
|
2158 | };
|
2159 |
|
2160 | var fnDef = function fnDef(fn) {
|
2161 | var locals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
2162 |
|
2163 | if (typeof fn !== 'function') {
|
2164 | if (isArray$1(fn)) {
|
2165 | fn = annotate(fn.slice());
|
2166 | } else {
|
2167 | throw new Error('Cannot invoke "' + fn + '". Expected a function!');
|
2168 | }
|
2169 | }
|
2170 |
|
2171 | var inject = fn.$inject || parse$2(fn);
|
2172 | var dependencies = inject.map(function (dep) {
|
2173 | if (hasProp(locals, dep)) {
|
2174 | return locals[dep];
|
2175 | } else {
|
2176 | return get(dep);
|
2177 | }
|
2178 | });
|
2179 |
|
2180 | return {
|
2181 | fn: fn,
|
2182 | dependencies: dependencies
|
2183 | };
|
2184 | };
|
2185 |
|
2186 | var instantiate = function instantiate(Type) {
|
2187 | var _fnDef = fnDef(Type),
|
2188 | dependencies = _fnDef.dependencies,
|
2189 | fn = _fnDef.fn;
|
2190 |
|
2191 | return new (Function.prototype.bind.apply(fn, [null].concat(_toConsumableArray(dependencies))))();
|
2192 | };
|
2193 |
|
2194 | var invoke = function invoke(func, context, locals) {
|
2195 | var _fnDef2 = fnDef(func, locals),
|
2196 | dependencies = _fnDef2.dependencies,
|
2197 | fn = _fnDef2.fn;
|
2198 |
|
2199 | return fn.call.apply(fn, [context].concat(_toConsumableArray(dependencies)));
|
2200 | };
|
2201 |
|
2202 | var createPrivateInjectorFactory = function createPrivateInjectorFactory(privateChildInjector) {
|
2203 | return annotate(function (key) {
|
2204 | return privateChildInjector.get(key);
|
2205 | });
|
2206 | };
|
2207 |
|
2208 | var createChild = function createChild(modules, forceNewInstances) {
|
2209 | if (forceNewInstances && forceNewInstances.length) {
|
2210 | var fromParentModule = Object.create(null);
|
2211 | var matchedScopes = Object.create(null);
|
2212 |
|
2213 | var privateInjectorsCache = [];
|
2214 | var privateChildInjectors = [];
|
2215 | var privateChildFactories = [];
|
2216 |
|
2217 | var provider;
|
2218 | var cacheIdx;
|
2219 | var privateChildInjector;
|
2220 | var privateChildInjectorFactory;
|
2221 | for (var name in providers) {
|
2222 | provider = providers[name];
|
2223 |
|
2224 | if (forceNewInstances.indexOf(name) !== -1) {
|
2225 | if (provider[2] === 'private') {
|
2226 | cacheIdx = privateInjectorsCache.indexOf(provider[3]);
|
2227 | if (cacheIdx === -1) {
|
2228 | privateChildInjector = provider[3].createChild([], forceNewInstances);
|
2229 | privateChildInjectorFactory = createPrivateInjectorFactory(privateChildInjector);
|
2230 | privateInjectorsCache.push(provider[3]);
|
2231 | privateChildInjectors.push(privateChildInjector);
|
2232 | privateChildFactories.push(privateChildInjectorFactory);
|
2233 | fromParentModule[name] = [privateChildInjectorFactory, name, 'private', privateChildInjector];
|
2234 | } else {
|
2235 | fromParentModule[name] = [privateChildFactories[cacheIdx], name, 'private', privateChildInjectors[cacheIdx]];
|
2236 | }
|
2237 | } else {
|
2238 | fromParentModule[name] = [provider[2], provider[1]];
|
2239 | }
|
2240 | matchedScopes[name] = true;
|
2241 | }
|
2242 |
|
2243 | if ((provider[2] === 'factory' || provider[2] === 'type') && provider[1].$scope) {
|
2244 |
|
2245 | forceNewInstances.forEach(function (scope) {
|
2246 | if (provider[1].$scope.indexOf(scope) !== -1) {
|
2247 | fromParentModule[name] = [provider[2], provider[1]];
|
2248 | matchedScopes[scope] = true;
|
2249 | }
|
2250 | });
|
2251 | }
|
2252 | }
|
2253 |
|
2254 | forceNewInstances.forEach(function (scope) {
|
2255 | if (!matchedScopes[scope]) {
|
2256 | throw new Error('No provider for "' + scope + '". Cannot use provider from the parent!');
|
2257 | }
|
2258 | });
|
2259 |
|
2260 | modules.unshift(fromParentModule);
|
2261 | }
|
2262 |
|
2263 | return new Injector(modules, self);
|
2264 | };
|
2265 |
|
2266 | var factoryMap = {
|
2267 | factory: invoke,
|
2268 | type: instantiate,
|
2269 | value: function value(_value) {
|
2270 | return _value;
|
2271 | }
|
2272 | };
|
2273 |
|
2274 | modules.forEach(function (module) {
|
2275 |
|
2276 | function arrayUnwrap(type, value) {
|
2277 | if (type !== 'value' && isArray$1(value)) {
|
2278 | value = annotate(value.slice());
|
2279 | }
|
2280 |
|
2281 | return value;
|
2282 | }
|
2283 |
|
2284 |
|
2285 | if (module instanceof Module) {
|
2286 | module.forEach(function (provider) {
|
2287 | var name = provider[0];
|
2288 | var type = provider[1];
|
2289 | var value = provider[2];
|
2290 |
|
2291 | providers[name] = [factoryMap[type], arrayUnwrap(type, value), type];
|
2292 | });
|
2293 | } else if ((typeof module === 'undefined' ? 'undefined' : _typeof(module)) === 'object') {
|
2294 | if (module.__exports__) {
|
2295 | var clonedModule = Object.keys(module).reduce(function (m, key) {
|
2296 | if (key.substring(0, 2) !== '__') {
|
2297 | m[key] = module[key];
|
2298 | }
|
2299 | return m;
|
2300 | }, Object.create(null));
|
2301 |
|
2302 | var privateInjector = new Injector((module.__modules__ || []).concat([clonedModule]), self);
|
2303 | var getFromPrivateInjector = annotate(function (key) {
|
2304 | return privateInjector.get(key);
|
2305 | });
|
2306 | module.__exports__.forEach(function (key) {
|
2307 | providers[key] = [getFromPrivateInjector, key, 'private', privateInjector];
|
2308 | });
|
2309 | } else {
|
2310 | Object.keys(module).forEach(function (name) {
|
2311 | if (module[name][2] === 'private') {
|
2312 | providers[name] = module[name];
|
2313 | return;
|
2314 | }
|
2315 |
|
2316 | var type = module[name][0];
|
2317 | var value = module[name][1];
|
2318 |
|
2319 | providers[name] = [factoryMap[type], arrayUnwrap(type, value), type];
|
2320 | });
|
2321 | }
|
2322 | }
|
2323 | });
|
2324 |
|
2325 |
|
2326 | this.get = get;
|
2327 | this.invoke = invoke;
|
2328 | this.instantiate = instantiate;
|
2329 | this.createChild = createChild;
|
2330 | }
|
2331 |
|
2332 | // helpers /////////////////
|
2333 |
|
2334 | function hasProp(obj, prop) {
|
2335 | return Object.hasOwnProperty.call(obj, prop);
|
2336 | }
|
2337 |
|
2338 | var DEFAULT_RENDER_PRIORITY = 1000;
|
2339 |
|
2340 | |
2341 |
|
2342 |
|
2343 |
|
2344 |
|
2345 |
|
2346 | function BaseRenderer(eventBus, renderPriority) {
|
2347 | var self = this;
|
2348 |
|
2349 | renderPriority = renderPriority || DEFAULT_RENDER_PRIORITY;
|
2350 |
|
2351 | eventBus.on([ 'render.shape', 'render.connection' ], renderPriority, function(evt, context) {
|
2352 | var type = evt.type,
|
2353 | element = context.element,
|
2354 | visuals = context.gfx;
|
2355 |
|
2356 | if (self.canRender(element)) {
|
2357 | if (type === 'render.shape') {
|
2358 | return self.drawShape(visuals, element);
|
2359 | } else {
|
2360 | return self.drawConnection(visuals, element);
|
2361 | }
|
2362 | }
|
2363 | });
|
2364 |
|
2365 | eventBus.on([ 'render.getShapePath', 'render.getConnectionPath'], renderPriority, function(evt, element) {
|
2366 | if (self.canRender(element)) {
|
2367 | if (evt.type === 'render.getShapePath') {
|
2368 | return self.getShapePath(element);
|
2369 | } else {
|
2370 | return self.getConnectionPath(element);
|
2371 | }
|
2372 | }
|
2373 | });
|
2374 | }
|
2375 |
|
2376 | |
2377 |
|
2378 |
|
2379 |
|
2380 |
|
2381 |
|
2382 |
|
2383 |
|
2384 | BaseRenderer.prototype.canRender = function() {};
|
2385 |
|
2386 | |
2387 |
|
2388 |
|
2389 |
|
2390 |
|
2391 |
|
2392 |
|
2393 |
|
2394 | BaseRenderer.prototype.drawShape = function() {};
|
2395 |
|
2396 | |
2397 |
|
2398 |
|
2399 |
|
2400 |
|
2401 |
|
2402 |
|
2403 |
|
2404 | BaseRenderer.prototype.drawConnection = function() {};
|
2405 |
|
2406 | |
2407 |
|
2408 |
|
2409 |
|
2410 |
|
2411 |
|
2412 |
|
2413 | BaseRenderer.prototype.getShapePath = function() {};
|
2414 |
|
2415 | |
2416 |
|
2417 |
|
2418 |
|
2419 |
|
2420 |
|
2421 |
|
2422 | BaseRenderer.prototype.getConnectionPath = function() {};
|
2423 |
|
2424 | function componentsToPath(elements) {
|
2425 | return elements.join(',').replace(/,?([A-z]),?/g, '$1');
|
2426 | }
|
2427 |
|
2428 | function toSVGPoints(points) {
|
2429 | var result = '';
|
2430 |
|
2431 | for (var i = 0, p; (p = points[i]); i++) {
|
2432 | result += p.x + ',' + p.y + ' ';
|
2433 | }
|
2434 |
|
2435 | return result;
|
2436 | }
|
2437 |
|
2438 | function createLine(points, attrs) {
|
2439 |
|
2440 | var line = create('polyline');
|
2441 | attr$1(line, { points: toSVGPoints(points) });
|
2442 |
|
2443 | if (attrs) {
|
2444 | attr$1(line, attrs);
|
2445 | }
|
2446 |
|
2447 | return line;
|
2448 | }
|
2449 |
|
2450 | function updateLine(gfx, points) {
|
2451 | attr$1(gfx, { points: toSVGPoints(points) });
|
2452 |
|
2453 | return gfx;
|
2454 | }
|
2455 |
|
2456 | |
2457 |
|
2458 |
|
2459 |
|
2460 |
|
2461 |
|
2462 |
|
2463 | function getParents(elements) {
|
2464 |
|
2465 |
|
2466 | return filter(elements, function(element) {
|
2467 | return !find(elements, function(e) {
|
2468 | return e !== element && getParent(element, e);
|
2469 | });
|
2470 | });
|
2471 | }
|
2472 |
|
2473 |
|
2474 | function getParent(element, parent) {
|
2475 | if (!parent) {
|
2476 | return;
|
2477 | }
|
2478 |
|
2479 | if (element === parent) {
|
2480 | return parent;
|
2481 | }
|
2482 |
|
2483 | if (!element.parent) {
|
2484 | return;
|
2485 | }
|
2486 |
|
2487 | return getParent(element.parent, parent);
|
2488 | }
|
2489 |
|
2490 |
|
2491 | |
2492 |
|
2493 |
|
2494 |
|
2495 |
|
2496 |
|
2497 |
|
2498 |
|
2499 | function add(elements, e, unique) {
|
2500 | var canAdd = !unique || elements.indexOf(e) === -1;
|
2501 |
|
2502 | if (canAdd) {
|
2503 | elements.push(e);
|
2504 | }
|
2505 |
|
2506 | return canAdd;
|
2507 | }
|
2508 |
|
2509 |
|
2510 | |
2511 |
|
2512 |
|
2513 |
|
2514 |
|
2515 |
|
2516 |
|
2517 |
|
2518 |
|
2519 |
|
2520 | function eachElement(elements, fn, depth) {
|
2521 |
|
2522 | depth = depth || 0;
|
2523 |
|
2524 | if (!isArray(elements)) {
|
2525 | elements = [ elements ];
|
2526 | }
|
2527 |
|
2528 | forEach(elements, function(s, i) {
|
2529 | var filter = fn(s, i, depth);
|
2530 |
|
2531 | if (isArray(filter) && filter.length) {
|
2532 | eachElement(filter, fn, depth + 1);
|
2533 | }
|
2534 | });
|
2535 | }
|
2536 |
|
2537 |
|
2538 | |
2539 |
|
2540 |
|
2541 |
|
2542 |
|
2543 |
|
2544 |
|
2545 |
|
2546 |
|
2547 | function selfAndChildren(elements, unique, maxDepth) {
|
2548 | var result = [],
|
2549 | processedChildren = [];
|
2550 |
|
2551 | eachElement(elements, function(element, i, depth) {
|
2552 | add(result, element, unique);
|
2553 |
|
2554 | var children = element.children;
|
2555 |
|
2556 |
|
2557 | if (maxDepth === -1 || depth < maxDepth) {
|
2558 |
|
2559 |
|
2560 | if (children && add(processedChildren, children, unique)) {
|
2561 | return children;
|
2562 | }
|
2563 | }
|
2564 | });
|
2565 |
|
2566 | return result;
|
2567 | }
|
2568 |
|
2569 |
|
2570 | |
2571 |
|
2572 |
|
2573 |
|
2574 |
|
2575 |
|
2576 |
|
2577 |
|
2578 | function selfAndAllChildren(elements, allowDuplicates) {
|
2579 | return selfAndChildren(elements, !allowDuplicates, -1);
|
2580 | }
|
2581 |
|
2582 |
|
2583 | |
2584 |
|
2585 |
|
2586 |
|
2587 |
|
2588 |
|
2589 |
|
2590 |
|
2591 |
|
2592 |
|
2593 | function getClosure(elements, isTopLevel, closure) {
|
2594 |
|
2595 | if (isUndefined(isTopLevel)) {
|
2596 | isTopLevel = true;
|
2597 | }
|
2598 |
|
2599 | if (isObject(isTopLevel)) {
|
2600 | closure = isTopLevel;
|
2601 | isTopLevel = true;
|
2602 | }
|
2603 |
|
2604 |
|
2605 | closure = closure || {};
|
2606 |
|
2607 | var allShapes = copyObject(closure.allShapes),
|
2608 | allConnections = copyObject(closure.allConnections),
|
2609 | enclosedElements = copyObject(closure.enclosedElements),
|
2610 | enclosedConnections = copyObject(closure.enclosedConnections);
|
2611 |
|
2612 | var topLevel = copyObject(
|
2613 | closure.topLevel,
|
2614 | isTopLevel && groupBy(elements, function(e) { return e.id; })
|
2615 | );
|
2616 |
|
2617 |
|
2618 | function handleConnection(c) {
|
2619 | if (topLevel[c.source.id] && topLevel[c.target.id]) {
|
2620 | topLevel[c.id] = [ c ];
|
2621 | }
|
2622 |
|
2623 |
|
2624 |
|
2625 | if (allShapes[c.source.id] && allShapes[c.target.id]) {
|
2626 | enclosedConnections[c.id] = enclosedElements[c.id] = c;
|
2627 | }
|
2628 |
|
2629 | allConnections[c.id] = c;
|
2630 | }
|
2631 |
|
2632 | function handleElement(element) {
|
2633 |
|
2634 | enclosedElements[element.id] = element;
|
2635 |
|
2636 | if (element.waypoints) {
|
2637 |
|
2638 |
|
2639 | enclosedConnections[element.id] = allConnections[element.id] = element;
|
2640 | } else {
|
2641 |
|
2642 |
|
2643 | allShapes[element.id] = element;
|
2644 |
|
2645 |
|
2646 | forEach(element.incoming, handleConnection);
|
2647 |
|
2648 | forEach(element.outgoing, handleConnection);
|
2649 |
|
2650 |
|
2651 | return element.children;
|
2652 | }
|
2653 | }
|
2654 |
|
2655 | eachElement(elements, handleElement);
|
2656 |
|
2657 | return {
|
2658 | allShapes: allShapes,
|
2659 | allConnections: allConnections,
|
2660 | topLevel: topLevel,
|
2661 | enclosedConnections: enclosedConnections,
|
2662 | enclosedElements: enclosedElements
|
2663 | };
|
2664 | }
|
2665 |
|
2666 | |
2667 |
|
2668 |
|
2669 |
|
2670 |
|
2671 |
|
2672 |
|
2673 | function getBBox(elements, stopRecursion) {
|
2674 |
|
2675 | stopRecursion = !!stopRecursion;
|
2676 | if (!isArray(elements)) {
|
2677 | elements = [elements];
|
2678 | }
|
2679 |
|
2680 | var minX,
|
2681 | minY,
|
2682 | maxX,
|
2683 | maxY;
|
2684 |
|
2685 | forEach(elements, function(element) {
|
2686 |
|
2687 |
|
2688 | var bbox = element;
|
2689 | if (element.waypoints && !stopRecursion) {
|
2690 | bbox = getBBox(element.waypoints, true);
|
2691 | }
|
2692 |
|
2693 | var x = bbox.x,
|
2694 | y = bbox.y,
|
2695 | height = bbox.height || 0,
|
2696 | width = bbox.width || 0;
|
2697 |
|
2698 | if (x < minX || minX === undefined) {
|
2699 | minX = x;
|
2700 | }
|
2701 | if (y < minY || minY === undefined) {
|
2702 | minY = y;
|
2703 | }
|
2704 |
|
2705 | if ((x + width) > maxX || maxX === undefined) {
|
2706 | maxX = x + width;
|
2707 | }
|
2708 | if ((y + height) > maxY || maxY === undefined) {
|
2709 | maxY = y + height;
|
2710 | }
|
2711 | });
|
2712 |
|
2713 | return {
|
2714 | x: minX,
|
2715 | y: minY,
|
2716 | height: maxY - minY,
|
2717 | width: maxX - minX
|
2718 | };
|
2719 | }
|
2720 |
|
2721 |
|
2722 | |
2723 |
|
2724 |
|
2725 |
|
2726 |
|
2727 |
|
2728 |
|
2729 |
|
2730 |
|
2731 |
|
2732 |
|
2733 |
|
2734 |
|
2735 | function getEnclosedElements(elements, bbox) {
|
2736 |
|
2737 | var filteredElements = {};
|
2738 |
|
2739 | forEach(elements, function(element) {
|
2740 |
|
2741 | var e = element;
|
2742 |
|
2743 | if (e.waypoints) {
|
2744 | e = getBBox(e);
|
2745 | }
|
2746 |
|
2747 | if (!isNumber(bbox.y) && (e.x > bbox.x)) {
|
2748 | filteredElements[element.id] = element;
|
2749 | }
|
2750 | if (!isNumber(bbox.x) && (e.y > bbox.y)) {
|
2751 | filteredElements[element.id] = element;
|
2752 | }
|
2753 | if (e.x > bbox.x && e.y > bbox.y) {
|
2754 | if (isNumber(bbox.width) && isNumber(bbox.height) &&
|
2755 | e.width + e.x < bbox.width + bbox.x &&
|
2756 | e.height + e.y < bbox.height + bbox.y) {
|
2757 |
|
2758 | filteredElements[element.id] = element;
|
2759 | } else if (!isNumber(bbox.width) || !isNumber(bbox.height)) {
|
2760 | filteredElements[element.id] = element;
|
2761 | }
|
2762 | }
|
2763 | });
|
2764 |
|
2765 | return filteredElements;
|
2766 | }
|
2767 |
|
2768 |
|
2769 | function getType(element) {
|
2770 |
|
2771 | if ('waypoints' in element) {
|
2772 | return 'connection';
|
2773 | }
|
2774 |
|
2775 | if ('x' in element) {
|
2776 | return 'shape';
|
2777 | }
|
2778 |
|
2779 | return 'root';
|
2780 | }
|
2781 |
|
2782 | function isFrameElement(element) {
|
2783 |
|
2784 | return !!(element && element.isFrame);
|
2785 | }
|
2786 |
|
2787 |
|
2788 |
|
2789 | function copyObject(src1, src2) {
|
2790 | return assign({}, src1 || {}, src2 || {});
|
2791 | }
|
2792 |
|
2793 |
|
2794 |
|
2795 | var DEFAULT_RENDER_PRIORITY$1 = 1;
|
2796 |
|
2797 | |
2798 |
|
2799 |
|
2800 |
|
2801 |
|
2802 |
|
2803 | function DefaultRenderer(eventBus, styles) {
|
2804 |
|
2805 |
|
2806 | BaseRenderer.call(this, eventBus, DEFAULT_RENDER_PRIORITY$1);
|
2807 |
|
2808 | this.CONNECTION_STYLE = styles.style([ 'no-fill' ], { strokeWidth: 5, stroke: 'fuchsia' });
|
2809 | this.SHAPE_STYLE = styles.style({ fill: 'white', stroke: 'fuchsia', strokeWidth: 2 });
|
2810 | this.FRAME_STYLE = styles.style([ 'no-fill' ], { stroke: 'fuchsia', strokeDasharray: 4, strokeWidth: 2 });
|
2811 | }
|
2812 |
|
2813 | inherits_browser(DefaultRenderer, BaseRenderer);
|
2814 |
|
2815 |
|
2816 | DefaultRenderer.prototype.canRender = function() {
|
2817 | return true;
|
2818 | };
|
2819 |
|
2820 | DefaultRenderer.prototype.drawShape = function drawShape(visuals, element) {
|
2821 | var rect = create('rect');
|
2822 |
|
2823 | attr$1(rect, {
|
2824 | x: 0,
|
2825 | y: 0,
|
2826 | width: element.width || 0,
|
2827 | height: element.height || 0
|
2828 | });
|
2829 |
|
2830 | if (isFrameElement(element)) {
|
2831 | attr$1(rect, this.FRAME_STYLE);
|
2832 | } else {
|
2833 | attr$1(rect, this.SHAPE_STYLE);
|
2834 | }
|
2835 |
|
2836 | append(visuals, rect);
|
2837 |
|
2838 | return rect;
|
2839 | };
|
2840 |
|
2841 | DefaultRenderer.prototype.drawConnection = function drawConnection(visuals, connection) {
|
2842 |
|
2843 | var line = createLine(connection.waypoints, this.CONNECTION_STYLE);
|
2844 | append(visuals, line);
|
2845 |
|
2846 | return line;
|
2847 | };
|
2848 |
|
2849 | DefaultRenderer.prototype.getShapePath = function getShapePath(shape) {
|
2850 |
|
2851 | var x = shape.x,
|
2852 | y = shape.y,
|
2853 | width = shape.width,
|
2854 | height = shape.height;
|
2855 |
|
2856 | var shapePath = [
|
2857 | ['M', x, y],
|
2858 | ['l', width, 0],
|
2859 | ['l', 0, height],
|
2860 | ['l', -width, 0],
|
2861 | ['z']
|
2862 | ];
|
2863 |
|
2864 | return componentsToPath(shapePath);
|
2865 | };
|
2866 |
|
2867 | DefaultRenderer.prototype.getConnectionPath = function getConnectionPath(connection) {
|
2868 | var waypoints = connection.waypoints;
|
2869 |
|
2870 | var idx, point, connectionPath = [];
|
2871 |
|
2872 | for (idx = 0; (point = waypoints[idx]); idx++) {
|
2873 |
|
2874 |
|
2875 |
|
2876 | point = point.original || point;
|
2877 |
|
2878 | connectionPath.push([ idx === 0 ? 'M' : 'L', point.x, point.y ]);
|
2879 | }
|
2880 |
|
2881 | return componentsToPath(connectionPath);
|
2882 | };
|
2883 |
|
2884 |
|
2885 | DefaultRenderer.$inject = [ 'eventBus', 'styles' ];
|
2886 |
|
2887 | |
2888 |
|
2889 |
|
2890 | function Styles() {
|
2891 |
|
2892 | var defaultTraits = {
|
2893 |
|
2894 | 'no-fill': {
|
2895 | fill: 'none'
|
2896 | },
|
2897 | 'no-border': {
|
2898 | strokeOpacity: 0.0
|
2899 | },
|
2900 | 'no-events': {
|
2901 | pointerEvents: 'none'
|
2902 | }
|
2903 | };
|
2904 |
|
2905 | var self = this;
|
2906 |
|
2907 | |
2908 |
|
2909 |
|
2910 |
|
2911 |
|
2912 |
|
2913 |
|
2914 |
|
2915 |
|
2916 | this.cls = function(className, traits, additionalAttrs) {
|
2917 | var attrs = this.style(traits, additionalAttrs);
|
2918 |
|
2919 | return assign(attrs, { 'class': className });
|
2920 | };
|
2921 |
|
2922 | |
2923 |
|
2924 |
|
2925 |
|
2926 |
|
2927 |
|
2928 |
|
2929 |
|
2930 | this.style = function(traits, additionalAttrs) {
|
2931 |
|
2932 | if (!isArray(traits) && !additionalAttrs) {
|
2933 | additionalAttrs = traits;
|
2934 | traits = [];
|
2935 | }
|
2936 |
|
2937 | var attrs = reduce(traits, function(attrs, t) {
|
2938 | return assign(attrs, defaultTraits[t] || {});
|
2939 | }, {});
|
2940 |
|
2941 | return additionalAttrs ? assign(attrs, additionalAttrs) : attrs;
|
2942 | };
|
2943 |
|
2944 | this.computeStyle = function(custom, traits, defaultStyles) {
|
2945 | if (!isArray(traits)) {
|
2946 | defaultStyles = traits;
|
2947 | traits = [];
|
2948 | }
|
2949 |
|
2950 | return self.style(traits || [], assign({}, defaultStyles, custom || {}));
|
2951 | };
|
2952 | }
|
2953 |
|
2954 | var DrawModule = {
|
2955 | __init__: [ 'defaultRenderer' ],
|
2956 | defaultRenderer: [ 'type', DefaultRenderer ],
|
2957 | styles: [ 'type', Styles ]
|
2958 | };
|
2959 |
|
2960 | |
2961 |
|
2962 |
|
2963 |
|
2964 |
|
2965 |
|
2966 |
|
2967 |
|
2968 | function remove$2(collection, element) {
|
2969 |
|
2970 | if (!collection || !element) {
|
2971 | return -1;
|
2972 | }
|
2973 |
|
2974 | var idx = collection.indexOf(element);
|
2975 |
|
2976 | if (idx !== -1) {
|
2977 | collection.splice(idx, 1);
|
2978 | }
|
2979 |
|
2980 | return idx;
|
2981 | }
|
2982 |
|
2983 | |
2984 |
|
2985 |
|
2986 |
|
2987 |
|
2988 |
|
2989 |
|
2990 |
|
2991 | function add$1(collection, element, idx) {
|
2992 |
|
2993 | if (!collection || !element) {
|
2994 | return;
|
2995 | }
|
2996 |
|
2997 | if (typeof idx !== 'number') {
|
2998 | idx = -1;
|
2999 | }
|
3000 |
|
3001 | var currentIdx = collection.indexOf(element);
|
3002 |
|
3003 | if (currentIdx !== -1) {
|
3004 |
|
3005 | if (currentIdx === idx) {
|
3006 |
|
3007 |
|
3008 | return;
|
3009 | } else {
|
3010 |
|
3011 | if (idx !== -1) {
|
3012 |
|
3013 |
|
3014 | collection.splice(currentIdx, 1);
|
3015 | } else {
|
3016 |
|
3017 |
|
3018 | return;
|
3019 | }
|
3020 | }
|
3021 | }
|
3022 |
|
3023 | if (idx !== -1) {
|
3024 |
|
3025 |
|
3026 | collection.splice(idx, 0, element);
|
3027 | } else {
|
3028 |
|
3029 |
|
3030 | collection.push(element);
|
3031 | }
|
3032 | }
|
3033 |
|
3034 |
|
3035 | |
3036 |
|
3037 |
|
3038 |
|
3039 |
|
3040 |
|
3041 |
|
3042 |
|
3043 |
|
3044 | function indexOf$1(collection, element) {
|
3045 |
|
3046 | if (!collection || !element) {
|
3047 | return -1;
|
3048 | }
|
3049 |
|
3050 | return collection.indexOf(element);
|
3051 | }
|
3052 |
|
3053 | function round(number, resolution) {
|
3054 | return Math.round(number * resolution) / resolution;
|
3055 | }
|
3056 |
|
3057 | function ensurePx(number) {
|
3058 | return isNumber(number) ? number + 'px' : number;
|
3059 | }
|
3060 |
|
3061 | |
3062 |
|
3063 |
|
3064 |
|
3065 |
|
3066 |
|
3067 |
|
3068 | function createContainer(options) {
|
3069 |
|
3070 | options = assign({}, { width: '100%', height: '100%' }, options);
|
3071 |
|
3072 | var container = options.container || document.body;
|
3073 |
|
3074 |
|
3075 |
|
3076 |
|
3077 | var parent = document.createElement('div');
|
3078 | parent.setAttribute('class', 'djs-container');
|
3079 |
|
3080 | assign(parent.style, {
|
3081 | position: 'relative',
|
3082 | overflow: 'hidden',
|
3083 | width: ensurePx(options.width),
|
3084 | height: ensurePx(options.height)
|
3085 | });
|
3086 |
|
3087 | container.appendChild(parent);
|
3088 |
|
3089 | return parent;
|
3090 | }
|
3091 |
|
3092 | function createGroup(parent, cls, childIndex) {
|
3093 | var group = create('g');
|
3094 | classes$1(group).add(cls);
|
3095 |
|
3096 | var index = childIndex !== undefined ? childIndex : parent.childNodes.length - 1;
|
3097 |
|
3098 |
|
3099 |
|
3100 | parent.insertBefore(group, parent.childNodes[index] || null);
|
3101 |
|
3102 | return group;
|
3103 | }
|
3104 |
|
3105 | var BASE_LAYER = 'base';
|
3106 |
|
3107 |
|
3108 | var REQUIRED_MODEL_ATTRS = {
|
3109 | shape: [ 'x', 'y', 'width', 'height' ],
|
3110 | connection: [ 'waypoints' ]
|
3111 | };
|
3112 |
|
3113 | |
3114 |
|
3115 |
|
3116 |
|
3117 |
|
3118 |
|
3119 |
|
3120 |
|
3121 |
|
3122 |
|
3123 |
|
3124 |
|
3125 |
|
3126 | function Canvas(config, eventBus, graphicsFactory, elementRegistry) {
|
3127 |
|
3128 | this._eventBus = eventBus;
|
3129 | this._elementRegistry = elementRegistry;
|
3130 | this._graphicsFactory = graphicsFactory;
|
3131 |
|
3132 | this._init(config || {});
|
3133 | }
|
3134 |
|
3135 | Canvas.$inject = [
|
3136 | 'config.canvas',
|
3137 | 'eventBus',
|
3138 | 'graphicsFactory',
|
3139 | 'elementRegistry'
|
3140 | ];
|
3141 |
|
3142 |
|
3143 | Canvas.prototype._init = function(config) {
|
3144 |
|
3145 | var eventBus = this._eventBus;
|
3146 |
|
3147 |
|
3148 |
|
3149 |
|
3150 |
|
3151 |
|
3152 |
|
3153 |
|
3154 |
|
3155 |
|
3156 |
|
3157 |
|
3158 |
|
3159 |
|
3160 | var container = this._container = createContainer(config);
|
3161 |
|
3162 | var svg = this._svg = create('svg');
|
3163 | attr$1(svg, { width: '100%', height: '100%' });
|
3164 |
|
3165 | append(container, svg);
|
3166 |
|
3167 | var viewport = this._viewport = createGroup(svg, 'viewport');
|
3168 |
|
3169 | this._layers = {};
|
3170 |
|
3171 |
|
3172 |
|
3173 | if (config.deferUpdate !== false) {
|
3174 | this._viewboxChanged = debounce(bind(this._viewboxChanged, this), 300);
|
3175 | }
|
3176 |
|
3177 | eventBus.on('diagram.init', function() {
|
3178 |
|
3179 | |
3180 |
|
3181 |
|
3182 |
|
3183 |
|
3184 |
|
3185 |
|
3186 |
|
3187 |
|
3188 |
|
3189 |
|
3190 | eventBus.fire('canvas.init', {
|
3191 | svg: svg,
|
3192 | viewport: viewport
|
3193 | });
|
3194 |
|
3195 | }, this);
|
3196 |
|
3197 |
|
3198 |
|
3199 | eventBus.on([
|
3200 | 'shape.added',
|
3201 | 'connection.added',
|
3202 | 'shape.removed',
|
3203 | 'connection.removed',
|
3204 | 'elements.changed'
|
3205 | ], function() {
|
3206 | delete this._cachedViewbox;
|
3207 | }, this);
|
3208 |
|
3209 | eventBus.on('diagram.destroy', 500, this._destroy, this);
|
3210 | eventBus.on('diagram.clear', 500, this._clear, this);
|
3211 | };
|
3212 |
|
3213 | Canvas.prototype._destroy = function(emit) {
|
3214 | this._eventBus.fire('canvas.destroy', {
|
3215 | svg: this._svg,
|
3216 | viewport: this._viewport
|
3217 | });
|
3218 |
|
3219 | var parent = this._container.parentNode;
|
3220 |
|
3221 | if (parent) {
|
3222 | parent.removeChild(this._container);
|
3223 | }
|
3224 |
|
3225 | delete this._svg;
|
3226 | delete this._container;
|
3227 | delete this._layers;
|
3228 | delete this._rootElement;
|
3229 | delete this._viewport;
|
3230 | };
|
3231 |
|
3232 | Canvas.prototype._clear = function() {
|
3233 |
|
3234 | var self = this;
|
3235 |
|
3236 | var allElements = this._elementRegistry.getAll();
|
3237 |
|
3238 |
|
3239 | allElements.forEach(function(element) {
|
3240 | var type = getType(element);
|
3241 |
|
3242 | if (type === 'root') {
|
3243 | self.setRootElement(null, true);
|
3244 | } else {
|
3245 | self._removeElement(element, type);
|
3246 | }
|
3247 | });
|
3248 |
|
3249 |
|
3250 | delete this._cachedViewbox;
|
3251 | };
|
3252 |
|
3253 | |
3254 |
|
3255 |
|
3256 |
|
3257 |
|
3258 |
|
3259 | Canvas.prototype.getDefaultLayer = function() {
|
3260 | return this.getLayer(BASE_LAYER, 0);
|
3261 | };
|
3262 |
|
3263 | |
3264 |
|
3265 |
|
3266 |
|
3267 |
|
3268 |
|
3269 |
|
3270 |
|
3271 |
|
3272 |
|
3273 |
|
3274 |
|
3275 |
|
3276 |
|
3277 |
|
3278 | Canvas.prototype.getLayer = function(name, index) {
|
3279 |
|
3280 | if (!name) {
|
3281 | throw new Error('must specify a name');
|
3282 | }
|
3283 |
|
3284 | var layer = this._layers[name];
|
3285 |
|
3286 | if (!layer) {
|
3287 | layer = this._layers[name] = this._createLayer(name, index);
|
3288 | }
|
3289 |
|
3290 |
|
3291 |
|
3292 | if (typeof index !== 'undefined' && layer.index !== index) {
|
3293 | throw new Error('layer <' + name + '> already created at index <' + index + '>');
|
3294 | }
|
3295 |
|
3296 | return layer.group;
|
3297 | };
|
3298 |
|
3299 | |
3300 |
|
3301 |
|
3302 |
|
3303 |
|
3304 |
|
3305 |
|
3306 |
|
3307 | Canvas.prototype._createLayer = function(name, index) {
|
3308 |
|
3309 | if (!index) {
|
3310 | index = 0;
|
3311 | }
|
3312 |
|
3313 | var childIndex = reduce(this._layers, function(childIndex, layer) {
|
3314 | if (index >= layer.index) {
|
3315 | childIndex++;
|
3316 | }
|
3317 |
|
3318 | return childIndex;
|
3319 | }, 0);
|
3320 |
|
3321 | return {
|
3322 | group: createGroup(this._viewport, 'layer-' + name, childIndex),
|
3323 | index: index
|
3324 | };
|
3325 |
|
3326 | };
|
3327 |
|
3328 | |
3329 |
|
3330 |
|
3331 |
|
3332 |
|
3333 |
|
3334 | Canvas.prototype.getContainer = function() {
|
3335 | return this._container;
|
3336 | };
|
3337 |
|
3338 |
|
3339 |
|
3340 |
|
3341 | Canvas.prototype._updateMarker = function(element, marker, add) {
|
3342 | var container;
|
3343 |
|
3344 | if (!element.id) {
|
3345 | element = this._elementRegistry.get(element);
|
3346 | }
|
3347 |
|
3348 |
|
3349 | container = this._elementRegistry._elements[element.id];
|
3350 |
|
3351 | if (!container) {
|
3352 | return;
|
3353 | }
|
3354 |
|
3355 | forEach([ container.gfx, container.secondaryGfx ], function(gfx) {
|
3356 | if (gfx) {
|
3357 |
|
3358 |
|
3359 | if (add) {
|
3360 | classes$1(gfx).add(marker);
|
3361 | } else {
|
3362 | classes$1(gfx).remove(marker);
|
3363 | }
|
3364 | }
|
3365 | });
|
3366 |
|
3367 | |
3368 |
|
3369 |
|
3370 |
|
3371 |
|
3372 |
|
3373 |
|
3374 |
|
3375 |
|
3376 |
|
3377 | this._eventBus.fire('element.marker.update', { element: element, gfx: container.gfx, marker: marker, add: !!add });
|
3378 | };
|
3379 |
|
3380 |
|
3381 | |
3382 |
|
3383 |
|
3384 |
|
3385 |
|
3386 |
|
3387 |
|
3388 |
|
3389 |
|
3390 |
|
3391 |
|
3392 |
|
3393 |
|
3394 |
|
3395 |
|
3396 |
|
3397 | Canvas.prototype.addMarker = function(element, marker) {
|
3398 | this._updateMarker(element, marker, true);
|
3399 | };
|
3400 |
|
3401 |
|
3402 | |
3403 |
|
3404 |
|
3405 |
|
3406 |
|
3407 |
|
3408 |
|
3409 |
|
3410 |
|
3411 | Canvas.prototype.removeMarker = function(element, marker) {
|
3412 | this._updateMarker(element, marker, false);
|
3413 | };
|
3414 |
|
3415 | |
3416 |
|
3417 |
|
3418 |
|
3419 |
|
3420 |
|
3421 | Canvas.prototype.hasMarker = function(element, marker) {
|
3422 | if (!element.id) {
|
3423 | element = this._elementRegistry.get(element);
|
3424 | }
|
3425 |
|
3426 | var gfx = this.getGraphics(element);
|
3427 |
|
3428 | return classes$1(gfx).has(marker);
|
3429 | };
|
3430 |
|
3431 | |
3432 |
|
3433 |
|
3434 |
|
3435 |
|
3436 |
|
3437 |
|
3438 |
|
3439 |
|
3440 | Canvas.prototype.toggleMarker = function(element, marker) {
|
3441 | if (this.hasMarker(element, marker)) {
|
3442 | this.removeMarker(element, marker);
|
3443 | } else {
|
3444 | this.addMarker(element, marker);
|
3445 | }
|
3446 | };
|
3447 |
|
3448 | Canvas.prototype.getRootElement = function() {
|
3449 | if (!this._rootElement) {
|
3450 | this.setRootElement({ id: '__implicitroot', children: [] });
|
3451 | }
|
3452 |
|
3453 | return this._rootElement;
|
3454 | };
|
3455 |
|
3456 |
|
3457 |
|
3458 |
|
3459 |
|
3460 | |
3461 |
|
3462 |
|
3463 |
|
3464 |
|
3465 |
|
3466 |
|
3467 |
|
3468 |
|
3469 | Canvas.prototype.setRootElement = function(element, override) {
|
3470 |
|
3471 | if (element) {
|
3472 | this._ensureValid('root', element);
|
3473 | }
|
3474 |
|
3475 | var currentRoot = this._rootElement,
|
3476 | elementRegistry = this._elementRegistry,
|
3477 | eventBus = this._eventBus;
|
3478 |
|
3479 | if (currentRoot) {
|
3480 | if (!override) {
|
3481 | throw new Error('rootElement already set, need to specify override');
|
3482 | }
|
3483 |
|
3484 |
|
3485 | eventBus.fire('root.remove', { element: currentRoot });
|
3486 | eventBus.fire('root.removed', { element: currentRoot });
|
3487 |
|
3488 | elementRegistry.remove(currentRoot);
|
3489 | }
|
3490 |
|
3491 | if (element) {
|
3492 | var gfx = this.getDefaultLayer();
|
3493 |
|
3494 |
|
3495 | eventBus.fire('root.add', { element: element });
|
3496 |
|
3497 | elementRegistry.add(element, gfx, this._svg);
|
3498 |
|
3499 | eventBus.fire('root.added', { element: element, gfx: gfx });
|
3500 | }
|
3501 |
|
3502 | this._rootElement = element;
|
3503 |
|
3504 | return element;
|
3505 | };
|
3506 |
|
3507 |
|
3508 |
|
3509 |
|
3510 |
|
3511 | Canvas.prototype._ensureValid = function(type, element) {
|
3512 | if (!element.id) {
|
3513 | throw new Error('element must have an id');
|
3514 | }
|
3515 |
|
3516 | if (this._elementRegistry.get(element.id)) {
|
3517 | throw new Error('element with id ' + element.id + ' already exists');
|
3518 | }
|
3519 |
|
3520 | var requiredAttrs = REQUIRED_MODEL_ATTRS[type];
|
3521 |
|
3522 | var valid = every(requiredAttrs, function(attr) {
|
3523 | return typeof element[attr] !== 'undefined';
|
3524 | });
|
3525 |
|
3526 | if (!valid) {
|
3527 | throw new Error(
|
3528 | 'must supply { ' + requiredAttrs.join(', ') + ' } with ' + type);
|
3529 | }
|
3530 | };
|
3531 |
|
3532 | Canvas.prototype._setParent = function(element, parent, parentIndex) {
|
3533 | add$1(parent.children, element, parentIndex);
|
3534 | element.parent = parent;
|
3535 | };
|
3536 |
|
3537 | |
3538 |
|
3539 |
|
3540 |
|
3541 |
|
3542 |
|
3543 |
|
3544 |
|
3545 |
|
3546 |
|
3547 |
|
3548 |
|
3549 |
|
3550 |
|
3551 |
|
3552 |
|
3553 |
|
3554 |
|
3555 |
|
3556 |
|
3557 | Canvas.prototype._addElement = function(type, element, parent, parentIndex) {
|
3558 |
|
3559 | parent = parent || this.getRootElement();
|
3560 |
|
3561 | var eventBus = this._eventBus,
|
3562 | graphicsFactory = this._graphicsFactory;
|
3563 |
|
3564 | this._ensureValid(type, element);
|
3565 |
|
3566 | eventBus.fire(type + '.add', { element: element, parent: parent });
|
3567 |
|
3568 | this._setParent(element, parent, parentIndex);
|
3569 |
|
3570 |
|
3571 | var gfx = graphicsFactory.create(type, element, parentIndex);
|
3572 |
|
3573 | this._elementRegistry.add(element, gfx);
|
3574 |
|
3575 |
|
3576 | graphicsFactory.update(type, element, gfx);
|
3577 |
|
3578 | eventBus.fire(type + '.added', { element: element, gfx: gfx });
|
3579 |
|
3580 | return element;
|
3581 | };
|
3582 |
|
3583 | |
3584 |
|
3585 |
|
3586 |
|
3587 |
|
3588 |
|
3589 |
|
3590 |
|
3591 |
|
3592 | Canvas.prototype.addShape = function(shape, parent, parentIndex) {
|
3593 | return this._addElement('shape', shape, parent, parentIndex);
|
3594 | };
|
3595 |
|
3596 | |
3597 |
|
3598 |
|
3599 |
|
3600 |
|
3601 |
|
3602 |
|
3603 |
|
3604 |
|
3605 | Canvas.prototype.addConnection = function(connection, parent, parentIndex) {
|
3606 | return this._addElement('connection', connection, parent, parentIndex);
|
3607 | };
|
3608 |
|
3609 |
|
3610 | |
3611 |
|
3612 |
|
3613 | Canvas.prototype._removeElement = function(element, type) {
|
3614 |
|
3615 | var elementRegistry = this._elementRegistry,
|
3616 | graphicsFactory = this._graphicsFactory,
|
3617 | eventBus = this._eventBus;
|
3618 |
|
3619 | element = elementRegistry.get(element.id || element);
|
3620 |
|
3621 | if (!element) {
|
3622 |
|
3623 |
|
3624 | return;
|
3625 | }
|
3626 |
|
3627 | eventBus.fire(type + '.remove', { element: element });
|
3628 |
|
3629 | graphicsFactory.remove(element);
|
3630 |
|
3631 |
|
3632 | remove$2(element.parent && element.parent.children, element);
|
3633 | element.parent = null;
|
3634 |
|
3635 | eventBus.fire(type + '.removed', { element: element });
|
3636 |
|
3637 | elementRegistry.remove(element);
|
3638 |
|
3639 | return element;
|
3640 | };
|
3641 |
|
3642 |
|
3643 | |
3644 |
|
3645 |
|
3646 |
|
3647 |
|
3648 |
|
3649 |
|
3650 | Canvas.prototype.removeShape = function(shape) {
|
3651 |
|
3652 | |
3653 |
|
3654 |
|
3655 |
|
3656 |
|
3657 |
|
3658 |
|
3659 |
|
3660 |
|
3661 |
|
3662 |
|
3663 | |
3664 |
|
3665 |
|
3666 |
|
3667 |
|
3668 |
|
3669 |
|
3670 |
|
3671 |
|
3672 |
|
3673 | return this._removeElement(shape, 'shape');
|
3674 | };
|
3675 |
|
3676 |
|
3677 | |
3678 |
|
3679 |
|
3680 |
|
3681 |
|
3682 |
|
3683 |
|
3684 | Canvas.prototype.removeConnection = function(connection) {
|
3685 |
|
3686 | |
3687 |
|
3688 |
|
3689 |
|
3690 |
|
3691 |
|
3692 |
|
3693 |
|
3694 |
|
3695 |
|
3696 |
|
3697 | |
3698 |
|
3699 |
|
3700 |
|
3701 |
|
3702 |
|
3703 |
|
3704 |
|
3705 |
|
3706 |
|
3707 | return this._removeElement(connection, 'connection');
|
3708 | };
|
3709 |
|
3710 |
|
3711 | |
3712 |
|
3713 |
|
3714 |
|
3715 |
|
3716 |
|
3717 |
|
3718 |
|
3719 | Canvas.prototype.getGraphics = function(element, secondary) {
|
3720 | return this._elementRegistry.getGraphics(element, secondary);
|
3721 | };
|
3722 |
|
3723 |
|
3724 | |
3725 |
|
3726 |
|
3727 |
|
3728 |
|
3729 | Canvas.prototype._changeViewbox = function(changeFn) {
|
3730 |
|
3731 |
|
3732 | this._eventBus.fire('canvas.viewbox.changing');
|
3733 |
|
3734 |
|
3735 | changeFn.apply(this);
|
3736 |
|
3737 |
|
3738 |
|
3739 |
|
3740 | this._cachedViewbox = null;
|
3741 |
|
3742 |
|
3743 |
|
3744 | this._viewboxChanged();
|
3745 | };
|
3746 |
|
3747 | Canvas.prototype._viewboxChanged = function() {
|
3748 | this._eventBus.fire('canvas.viewbox.changed', { viewbox: this.viewbox() });
|
3749 | };
|
3750 |
|
3751 |
|
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 | Canvas.prototype.viewbox = function(box) {
|
3798 |
|
3799 | if (box === undefined && this._cachedViewbox) {
|
3800 | return this._cachedViewbox;
|
3801 | }
|
3802 |
|
3803 | var viewport = this._viewport,
|
3804 | innerBox,
|
3805 | outerBox = this.getSize(),
|
3806 | matrix,
|
3807 | transform$1,
|
3808 | scale,
|
3809 | x, y;
|
3810 |
|
3811 | if (!box) {
|
3812 |
|
3813 |
|
3814 |
|
3815 |
|
3816 | innerBox = this.getDefaultLayer().getBBox();
|
3817 |
|
3818 | transform$1 = transform(viewport);
|
3819 | matrix = transform$1 ? transform$1.matrix : createMatrix();
|
3820 | scale = round(matrix.a, 1000);
|
3821 |
|
3822 | x = round(-matrix.e || 0, 1000);
|
3823 | y = round(-matrix.f || 0, 1000);
|
3824 |
|
3825 | box = this._cachedViewbox = {
|
3826 | x: x ? x / scale : 0,
|
3827 | y: y ? y / scale : 0,
|
3828 | width: outerBox.width / scale,
|
3829 | height: outerBox.height / scale,
|
3830 | scale: scale,
|
3831 | inner: {
|
3832 | width: innerBox.width,
|
3833 | height: innerBox.height,
|
3834 | x: innerBox.x,
|
3835 | y: innerBox.y
|
3836 | },
|
3837 | outer: outerBox
|
3838 | };
|
3839 |
|
3840 | return box;
|
3841 | } else {
|
3842 |
|
3843 | this._changeViewbox(function() {
|
3844 | scale = Math.min(outerBox.width / box.width, outerBox.height / box.height);
|
3845 |
|
3846 | var matrix = this._svg.createSVGMatrix()
|
3847 | .scale(scale)
|
3848 | .translate(-box.x, -box.y);
|
3849 |
|
3850 | transform(viewport, matrix);
|
3851 | });
|
3852 | }
|
3853 |
|
3854 | return box;
|
3855 | };
|
3856 |
|
3857 |
|
3858 | |
3859 |
|
3860 |
|
3861 |
|
3862 |
|
3863 |
|
3864 |
|
3865 |
|
3866 | Canvas.prototype.scroll = function(delta) {
|
3867 |
|
3868 | var node = this._viewport;
|
3869 | var matrix = node.getCTM();
|
3870 |
|
3871 | if (delta) {
|
3872 | this._changeViewbox(function() {
|
3873 | delta = assign({ dx: 0, dy: 0 }, delta || {});
|
3874 |
|
3875 | matrix = this._svg.createSVGMatrix().translate(delta.dx, delta.dy).multiply(matrix);
|
3876 |
|
3877 | setCTM(node, matrix);
|
3878 | });
|
3879 | }
|
3880 |
|
3881 | return { x: matrix.e, y: matrix.f };
|
3882 | };
|
3883 |
|
3884 |
|
3885 | |
3886 |
|
3887 |
|
3888 |
|
3889 |
|
3890 |
|
3891 |
|
3892 |
|
3893 |
|
3894 |
|
3895 |
|
3896 |
|
3897 |
|
3898 | Canvas.prototype.zoom = function(newScale, center) {
|
3899 |
|
3900 | if (!newScale) {
|
3901 | return this.viewbox(newScale).scale;
|
3902 | }
|
3903 |
|
3904 | if (newScale === 'fit-viewport') {
|
3905 | return this._fitViewport(center);
|
3906 | }
|
3907 |
|
3908 | var outer,
|
3909 | matrix;
|
3910 |
|
3911 | this._changeViewbox(function() {
|
3912 |
|
3913 | if (typeof center !== 'object') {
|
3914 | outer = this.viewbox().outer;
|
3915 |
|
3916 | center = {
|
3917 | x: outer.width / 2,
|
3918 | y: outer.height / 2
|
3919 | };
|
3920 | }
|
3921 |
|
3922 | matrix = this._setZoom(newScale, center);
|
3923 | });
|
3924 |
|
3925 | return round(matrix.a, 1000);
|
3926 | };
|
3927 |
|
3928 | function setCTM(node, m) {
|
3929 | var mstr = 'matrix(' + m.a + ',' + m.b + ',' + m.c + ',' + m.d + ',' + m.e + ',' + m.f + ')';
|
3930 | node.setAttribute('transform', mstr);
|
3931 | }
|
3932 |
|
3933 | Canvas.prototype._fitViewport = function(center) {
|
3934 |
|
3935 | var vbox = this.viewbox(),
|
3936 | outer = vbox.outer,
|
3937 | inner = vbox.inner,
|
3938 | newScale,
|
3939 | newViewbox;
|
3940 |
|
3941 |
|
3942 |
|
3943 |
|
3944 |
|
3945 |
|
3946 |
|
3947 |
|
3948 | if (inner.x >= 0 &&
|
3949 | inner.y >= 0 &&
|
3950 | inner.x + inner.width <= outer.width &&
|
3951 | inner.y + inner.height <= outer.height &&
|
3952 | !center) {
|
3953 |
|
3954 | newViewbox = {
|
3955 | x: 0,
|
3956 | y: 0,
|
3957 | width: Math.max(inner.width + inner.x, outer.width),
|
3958 | height: Math.max(inner.height + inner.y, outer.height)
|
3959 | };
|
3960 | } else {
|
3961 |
|
3962 | newScale = Math.min(1, outer.width / inner.width, outer.height / inner.height);
|
3963 | newViewbox = {
|
3964 | x: inner.x + (center ? inner.width / 2 - outer.width / newScale / 2 : 0),
|
3965 | y: inner.y + (center ? inner.height / 2 - outer.height / newScale / 2 : 0),
|
3966 | width: outer.width / newScale,
|
3967 | height: outer.height / newScale
|
3968 | };
|
3969 | }
|
3970 |
|
3971 | this.viewbox(newViewbox);
|
3972 |
|
3973 | return this.viewbox(false).scale;
|
3974 | };
|
3975 |
|
3976 |
|
3977 | Canvas.prototype._setZoom = function(scale, center) {
|
3978 |
|
3979 | var svg = this._svg,
|
3980 | viewport = this._viewport;
|
3981 |
|
3982 | var matrix = svg.createSVGMatrix();
|
3983 | var point = svg.createSVGPoint();
|
3984 |
|
3985 | var centerPoint,
|
3986 | originalPoint,
|
3987 | currentMatrix,
|
3988 | scaleMatrix,
|
3989 | newMatrix;
|
3990 |
|
3991 | currentMatrix = viewport.getCTM();
|
3992 |
|
3993 | var currentScale = currentMatrix.a;
|
3994 |
|
3995 | if (center) {
|
3996 | centerPoint = assign(point, center);
|
3997 |
|
3998 |
|
3999 | originalPoint = centerPoint.matrixTransform(currentMatrix.inverse());
|
4000 |
|
4001 |
|
4002 | scaleMatrix = matrix
|
4003 | .translate(originalPoint.x, originalPoint.y)
|
4004 | .scale(1 / currentScale * scale)
|
4005 | .translate(-originalPoint.x, -originalPoint.y);
|
4006 |
|
4007 | newMatrix = currentMatrix.multiply(scaleMatrix);
|
4008 | } else {
|
4009 | newMatrix = matrix.scale(scale);
|
4010 | }
|
4011 |
|
4012 | setCTM(this._viewport, newMatrix);
|
4013 |
|
4014 | return newMatrix;
|
4015 | };
|
4016 |
|
4017 |
|
4018 | |
4019 |
|
4020 |
|
4021 |
|
4022 |
|
4023 | Canvas.prototype.getSize = function() {
|
4024 | return {
|
4025 | width: this._container.clientWidth,
|
4026 | height: this._container.clientHeight
|
4027 | };
|
4028 | };
|
4029 |
|
4030 |
|
4031 | |
4032 |
|
4033 |
|
4034 |
|
4035 |
|
4036 |
|
4037 |
|
4038 |
|
4039 |
|
4040 |
|
4041 | Canvas.prototype.getAbsoluteBBox = function(element) {
|
4042 | var vbox = this.viewbox();
|
4043 | var bbox;
|
4044 |
|
4045 |
|
4046 |
|
4047 | if (element.waypoints) {
|
4048 | var gfx = this.getGraphics(element);
|
4049 |
|
4050 | bbox = gfx.getBBox();
|
4051 | }
|
4052 |
|
4053 |
|
4054 |
|
4055 | else {
|
4056 | bbox = element;
|
4057 | }
|
4058 |
|
4059 | var x = bbox.x * vbox.scale - vbox.x * vbox.scale;
|
4060 | var y = bbox.y * vbox.scale - vbox.y * vbox.scale;
|
4061 |
|
4062 | var width = bbox.width * vbox.scale;
|
4063 | var height = bbox.height * vbox.scale;
|
4064 |
|
4065 | return {
|
4066 | x: x,
|
4067 | y: y,
|
4068 | width: width,
|
4069 | height: height
|
4070 | };
|
4071 | };
|
4072 |
|
4073 | |
4074 |
|
4075 |
|
4076 |
|
4077 | Canvas.prototype.resized = function() {
|
4078 |
|
4079 |
|
4080 | delete this._cachedViewbox;
|
4081 |
|
4082 | this._eventBus.fire('canvas.resized');
|
4083 | };
|
4084 |
|
4085 | var ELEMENT_ID = 'data-element-id';
|
4086 |
|
4087 |
|
4088 | |
4089 |
|
4090 |
|
4091 |
|
4092 |
|
4093 | function ElementRegistry(eventBus) {
|
4094 | this._elements = {};
|
4095 |
|
4096 | this._eventBus = eventBus;
|
4097 | }
|
4098 |
|
4099 | ElementRegistry.$inject = [ 'eventBus' ];
|
4100 |
|
4101 | |
4102 |
|
4103 |
|
4104 |
|
4105 |
|
4106 |
|
4107 |
|
4108 | ElementRegistry.prototype.add = function(element, gfx, secondaryGfx) {
|
4109 |
|
4110 | var id = element.id;
|
4111 |
|
4112 | this._validateId(id);
|
4113 |
|
4114 |
|
4115 | attr$1(gfx, ELEMENT_ID, id);
|
4116 |
|
4117 | if (secondaryGfx) {
|
4118 | attr$1(secondaryGfx, ELEMENT_ID, id);
|
4119 | }
|
4120 |
|
4121 | this._elements[id] = { element: element, gfx: gfx, secondaryGfx: secondaryGfx };
|
4122 | };
|
4123 |
|
4124 | |
4125 |
|
4126 |
|
4127 |
|
4128 |
|
4129 | ElementRegistry.prototype.remove = function(element) {
|
4130 | var elements = this._elements,
|
4131 | id = element.id || element,
|
4132 | container = id && elements[id];
|
4133 |
|
4134 | if (container) {
|
4135 |
|
4136 |
|
4137 | attr$1(container.gfx, ELEMENT_ID, '');
|
4138 |
|
4139 | if (container.secondaryGfx) {
|
4140 | attr$1(container.secondaryGfx, ELEMENT_ID, '');
|
4141 | }
|
4142 |
|
4143 | delete elements[id];
|
4144 | }
|
4145 | };
|
4146 |
|
4147 | |
4148 |
|
4149 |
|
4150 |
|
4151 |
|
4152 |
|
4153 | ElementRegistry.prototype.updateId = function(element, newId) {
|
4154 |
|
4155 | this._validateId(newId);
|
4156 |
|
4157 | if (typeof element === 'string') {
|
4158 | element = this.get(element);
|
4159 | }
|
4160 |
|
4161 | this._eventBus.fire('element.updateId', {
|
4162 | element: element,
|
4163 | newId: newId
|
4164 | });
|
4165 |
|
4166 | var gfx = this.getGraphics(element),
|
4167 | secondaryGfx = this.getGraphics(element, true);
|
4168 |
|
4169 | this.remove(element);
|
4170 |
|
4171 | element.id = newId;
|
4172 |
|
4173 | this.add(element, gfx, secondaryGfx);
|
4174 | };
|
4175 |
|
4176 | |
4177 |
|
4178 |
|
4179 |
|
4180 |
|
4181 |
|
4182 |
|
4183 |
|
4184 |
|
4185 |
|
4186 |
|
4187 |
|
4188 |
|
4189 | ElementRegistry.prototype.get = function(filter) {
|
4190 | var id;
|
4191 |
|
4192 | if (typeof filter === 'string') {
|
4193 | id = filter;
|
4194 | } else {
|
4195 | id = filter && attr$1(filter, ELEMENT_ID);
|
4196 | }
|
4197 |
|
4198 | var container = this._elements[id];
|
4199 | return container && container.element;
|
4200 | };
|
4201 |
|
4202 | |
4203 |
|
4204 |
|
4205 |
|
4206 |
|
4207 |
|
4208 |
|
4209 | ElementRegistry.prototype.filter = function(fn) {
|
4210 |
|
4211 | var filtered = [];
|
4212 |
|
4213 | this.forEach(function(element, gfx) {
|
4214 | if (fn(element, gfx)) {
|
4215 | filtered.push(element);
|
4216 | }
|
4217 | });
|
4218 |
|
4219 | return filtered;
|
4220 | };
|
4221 |
|
4222 | |
4223 |
|
4224 |
|
4225 |
|
4226 |
|
4227 | ElementRegistry.prototype.getAll = function() {
|
4228 | return this.filter(function(e) { return e; });
|
4229 | };
|
4230 |
|
4231 | |
4232 |
|
4233 |
|
4234 |
|
4235 |
|
4236 | ElementRegistry.prototype.forEach = function(fn) {
|
4237 |
|
4238 | var map = this._elements;
|
4239 |
|
4240 | Object.keys(map).forEach(function(id) {
|
4241 | var container = map[id],
|
4242 | element = container.element,
|
4243 | gfx = container.gfx;
|
4244 |
|
4245 | return fn(element, gfx);
|
4246 | });
|
4247 | };
|
4248 |
|
4249 | |
4250 |
|
4251 |
|
4252 |
|
4253 |
|
4254 |
|
4255 |
|
4256 |
|
4257 |
|
4258 |
|
4259 |
|
4260 |
|
4261 |
|
4262 |
|
4263 |
|
4264 | ElementRegistry.prototype.getGraphics = function(filter, secondary) {
|
4265 | var id = filter.id || filter;
|
4266 |
|
4267 | var container = this._elements[id];
|
4268 | return container && (secondary ? container.secondaryGfx : container.gfx);
|
4269 | };
|
4270 |
|
4271 | |
4272 |
|
4273 |
|
4274 |
|
4275 |
|
4276 |
|
4277 |
|
4278 |
|
4279 | ElementRegistry.prototype._validateId = function(id) {
|
4280 | if (!id) {
|
4281 | throw new Error('element must have an id');
|
4282 | }
|
4283 |
|
4284 | if (this._elements[id]) {
|
4285 | throw new Error('element with id ' + id + ' already added');
|
4286 | }
|
4287 | };
|
4288 |
|
4289 | |
4290 |
|
4291 |
|
4292 |
|
4293 |
|
4294 |
|
4295 |
|
4296 | |
4297 |
|
4298 |
|
4299 |
|
4300 |
|
4301 |
|
4302 |
|
4303 |
|
4304 |
|
4305 |
|
4306 |
|
4307 |
|
4308 |
|
4309 | function extend$1(collection, refs, property, target) {
|
4310 |
|
4311 | var inverseProperty = property.inverse;
|
4312 |
|
4313 | |
4314 |
|
4315 |
|
4316 |
|
4317 |
|
4318 |
|
4319 |
|
4320 | Object.defineProperty(collection, 'remove', {
|
4321 | value: function(element) {
|
4322 | var idx = this.indexOf(element);
|
4323 | if (idx !== -1) {
|
4324 | this.splice(idx, 1);
|
4325 |
|
4326 |
|
4327 | refs.unset(element, inverseProperty, target);
|
4328 | }
|
4329 |
|
4330 | return element;
|
4331 | }
|
4332 | });
|
4333 |
|
4334 | |
4335 |
|
4336 |
|
4337 |
|
4338 |
|
4339 |
|
4340 |
|
4341 | Object.defineProperty(collection, 'contains', {
|
4342 | value: function(element) {
|
4343 | return this.indexOf(element) !== -1;
|
4344 | }
|
4345 | });
|
4346 |
|
4347 | |
4348 |
|
4349 |
|
4350 |
|
4351 |
|
4352 |
|
4353 |
|
4354 |
|
4355 |
|
4356 | Object.defineProperty(collection, 'add', {
|
4357 | value: function(element, idx) {
|
4358 |
|
4359 | var currentIdx = this.indexOf(element);
|
4360 |
|
4361 | if (typeof idx === 'undefined') {
|
4362 |
|
4363 | if (currentIdx !== -1) {
|
4364 |
|
4365 | return;
|
4366 | }
|
4367 |
|
4368 |
|
4369 | idx = this.length;
|
4370 | }
|
4371 |
|
4372 |
|
4373 | if (currentIdx !== -1) {
|
4374 |
|
4375 |
|
4376 | this.splice(currentIdx, 1);
|
4377 | }
|
4378 |
|
4379 |
|
4380 | this.splice(idx, 0, element);
|
4381 |
|
4382 | if (currentIdx === -1) {
|
4383 |
|
4384 |
|
4385 | refs.set(element, inverseProperty, target);
|
4386 | }
|
4387 | }
|
4388 | });
|
4389 |
|
4390 |
|
4391 |
|
4392 | Object.defineProperty(collection, '__refs_collection', {
|
4393 | value: true
|
4394 | });
|
4395 |
|
4396 | return collection;
|
4397 | }
|
4398 |
|
4399 |
|
4400 | function isExtended(collection) {
|
4401 | return collection.__refs_collection === true;
|
4402 | }
|
4403 |
|
4404 | var extend_1 = extend$1;
|
4405 |
|
4406 | var isExtended_1 = isExtended;
|
4407 |
|
4408 | var collection = {
|
4409 | extend: extend_1,
|
4410 | isExtended: isExtended_1
|
4411 | };
|
4412 |
|
4413 | function hasOwnProperty(e, property) {
|
4414 | return Object.prototype.hasOwnProperty.call(e, property.name || property);
|
4415 | }
|
4416 |
|
4417 | function defineCollectionProperty(ref, property, target) {
|
4418 |
|
4419 | var collection$1 = collection.extend(target[property.name] || [], ref, property, target);
|
4420 |
|
4421 | Object.defineProperty(target, property.name, {
|
4422 | enumerable: property.enumerable,
|
4423 | value: collection$1
|
4424 | });
|
4425 |
|
4426 | if (collection$1.length) {
|
4427 |
|
4428 | collection$1.forEach(function(o) {
|
4429 | ref.set(o, property.inverse, target);
|
4430 | });
|
4431 | }
|
4432 | }
|
4433 |
|
4434 |
|
4435 | function defineProperty(ref, property, target) {
|
4436 |
|
4437 | var inverseProperty = property.inverse;
|
4438 |
|
4439 | var _value = target[property.name];
|
4440 |
|
4441 | Object.defineProperty(target, property.name, {
|
4442 | configurable: property.configurable,
|
4443 | enumerable: property.enumerable,
|
4444 |
|
4445 | get: function() {
|
4446 | return _value;
|
4447 | },
|
4448 |
|
4449 | set: function(value) {
|
4450 |
|
4451 |
|
4452 | if (value === _value) {
|
4453 | return;
|
4454 | }
|
4455 |
|
4456 | var old = _value;
|
4457 |
|
4458 |
|
4459 | _value = null;
|
4460 |
|
4461 | if (old) {
|
4462 | ref.unset(old, inverseProperty, target);
|
4463 | }
|
4464 |
|
4465 |
|
4466 | _value = value;
|
4467 |
|
4468 |
|
4469 | ref.set(_value, inverseProperty, target);
|
4470 | }
|
4471 | });
|
4472 |
|
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 | function Refs(a, b) {
|
4519 |
|
4520 | if (!(this instanceof Refs)) {
|
4521 | return new Refs(a, b);
|
4522 | }
|
4523 |
|
4524 |
|
4525 | a.inverse = b;
|
4526 | b.inverse = a;
|
4527 |
|
4528 | this.props = {};
|
4529 | this.props[a.name] = a;
|
4530 | this.props[b.name] = b;
|
4531 | }
|
4532 |
|
4533 | |
4534 |
|
4535 |
|
4536 |
|
4537 |
|
4538 |
|
4539 |
|
4540 |
|
4541 |
|
4542 | Refs.prototype.bind = function(target, property) {
|
4543 | if (typeof property === 'string') {
|
4544 | if (!this.props[property]) {
|
4545 | throw new Error('no property <' + property + '> in ref');
|
4546 | }
|
4547 | property = this.props[property];
|
4548 | }
|
4549 |
|
4550 | if (property.collection) {
|
4551 | defineCollectionProperty(this, property, target);
|
4552 | } else {
|
4553 | defineProperty(this, property, target);
|
4554 | }
|
4555 | };
|
4556 |
|
4557 | Refs.prototype.ensureRefsCollection = function(target, property) {
|
4558 |
|
4559 | var collection$1 = target[property.name];
|
4560 |
|
4561 | if (!collection.isExtended(collection$1)) {
|
4562 | defineCollectionProperty(this, property, target);
|
4563 | }
|
4564 |
|
4565 | return collection$1;
|
4566 | };
|
4567 |
|
4568 | Refs.prototype.ensureBound = function(target, property) {
|
4569 | if (!hasOwnProperty(target, property)) {
|
4570 | this.bind(target, property);
|
4571 | }
|
4572 | };
|
4573 |
|
4574 | Refs.prototype.unset = function(target, property, value) {
|
4575 |
|
4576 | if (target) {
|
4577 | this.ensureBound(target, property);
|
4578 |
|
4579 | if (property.collection) {
|
4580 | this.ensureRefsCollection(target, property).remove(value);
|
4581 | } else {
|
4582 | target[property.name] = undefined;
|
4583 | }
|
4584 | }
|
4585 | };
|
4586 |
|
4587 | Refs.prototype.set = function(target, property, value) {
|
4588 |
|
4589 | if (target) {
|
4590 | this.ensureBound(target, property);
|
4591 |
|
4592 | if (property.collection) {
|
4593 | this.ensureRefsCollection(target, property).add(value);
|
4594 | } else {
|
4595 | target[property.name] = value;
|
4596 | }
|
4597 | }
|
4598 | };
|
4599 |
|
4600 | var refs = Refs;
|
4601 |
|
4602 | var objectRefs = refs;
|
4603 |
|
4604 | var Collection = collection;
|
4605 | objectRefs.Collection = Collection;
|
4606 |
|
4607 | var parentRefs = new objectRefs({ name: 'children', enumerable: true, collection: true }, { name: 'parent' }),
|
4608 | labelRefs = new objectRefs({ name: 'labels', enumerable: true, collection: true }, { name: 'labelTarget' }),
|
4609 | attacherRefs = new objectRefs({ name: 'attachers', collection: true }, { name: 'host' }),
|
4610 | outgoingRefs = new objectRefs({ name: 'outgoing', collection: true }, { name: 'source' }),
|
4611 | incomingRefs = new objectRefs({ name: 'incoming', collection: true }, { name: 'target' });
|
4612 |
|
4613 | |
4614 |
|
4615 |
|
4616 |
|
4617 | |
4618 |
|
4619 |
|
4620 |
|
4621 | |
4622 |
|
4623 |
|
4624 |
|
4625 |
|
4626 |
|
4627 |
|
4628 | function Base() {
|
4629 |
|
4630 | |
4631 |
|
4632 |
|
4633 |
|
4634 |
|
4635 |
|
4636 | Object.defineProperty(this, 'businessObject', {
|
4637 | writable: true
|
4638 | });
|
4639 |
|
4640 |
|
4641 | |
4642 |
|
4643 |
|
4644 |
|
4645 |
|
4646 |
|
4647 | Object.defineProperty(this, 'label', {
|
4648 | get: function() {
|
4649 | return this.labels[0];
|
4650 | },
|
4651 | set: function(newLabel) {
|
4652 |
|
4653 | var label = this.label,
|
4654 | labels = this.labels;
|
4655 |
|
4656 | if (!newLabel && label) {
|
4657 | labels.remove(label);
|
4658 | } else {
|
4659 | labels.add(newLabel, 0);
|
4660 | }
|
4661 | }
|
4662 | });
|
4663 |
|
4664 | |
4665 |
|
4666 |
|
4667 |
|
4668 |
|
4669 |
|
4670 | parentRefs.bind(this, 'parent');
|
4671 |
|
4672 | |
4673 |
|
4674 |
|
4675 |
|
4676 |
|
4677 |
|
4678 | labelRefs.bind(this, 'labels');
|
4679 |
|
4680 | |
4681 |
|
4682 |
|
4683 |
|
4684 |
|
4685 |
|
4686 | outgoingRefs.bind(this, 'outgoing');
|
4687 |
|
4688 | |
4689 |
|
4690 |
|
4691 |
|
4692 |
|
4693 |
|
4694 | incomingRefs.bind(this, 'incoming');
|
4695 | }
|
4696 |
|
4697 |
|
4698 | |
4699 |
|
4700 |
|
4701 |
|
4702 |
|
4703 |
|
4704 |
|
4705 |
|
4706 | function Shape() {
|
4707 | Base.call(this);
|
4708 |
|
4709 | |
4710 |
|
4711 |
|
4712 |
|
4713 |
|
4714 |
|
4715 |
|
4716 | |
4717 |
|
4718 |
|
4719 |
|
4720 |
|
4721 |
|
4722 | parentRefs.bind(this, 'children');
|
4723 |
|
4724 | |
4725 |
|
4726 |
|
4727 |
|
4728 | attacherRefs.bind(this, 'host');
|
4729 |
|
4730 | |
4731 |
|
4732 |
|
4733 |
|
4734 | attacherRefs.bind(this, 'attachers');
|
4735 | }
|
4736 |
|
4737 | inherits_browser(Shape, Base);
|
4738 |
|
4739 |
|
4740 | |
4741 |
|
4742 |
|
4743 |
|
4744 |
|
4745 |
|
4746 |
|
4747 |
|
4748 | function Root() {
|
4749 | Shape.call(this);
|
4750 | }
|
4751 |
|
4752 | inherits_browser(Root, Shape);
|
4753 |
|
4754 |
|
4755 | |
4756 |
|
4757 |
|
4758 |
|
4759 |
|
4760 |
|
4761 |
|
4762 |
|
4763 | function Label() {
|
4764 | Shape.call(this);
|
4765 |
|
4766 | |
4767 |
|
4768 |
|
4769 |
|
4770 |
|
4771 |
|
4772 | labelRefs.bind(this, 'labelTarget');
|
4773 | }
|
4774 |
|
4775 | inherits_browser(Label, Shape);
|
4776 |
|
4777 |
|
4778 | |
4779 |
|
4780 |
|
4781 |
|
4782 |
|
4783 |
|
4784 |
|
4785 |
|
4786 | function Connection() {
|
4787 | Base.call(this);
|
4788 |
|
4789 | |
4790 |
|
4791 |
|
4792 |
|
4793 |
|
4794 |
|
4795 | outgoingRefs.bind(this, 'source');
|
4796 |
|
4797 | |
4798 |
|
4799 |
|
4800 |
|
4801 |
|
4802 |
|
4803 | incomingRefs.bind(this, 'target');
|
4804 | }
|
4805 |
|
4806 | inherits_browser(Connection, Base);
|
4807 |
|
4808 |
|
4809 | var types = {
|
4810 | connection: Connection,
|
4811 | shape: Shape,
|
4812 | label: Label,
|
4813 | root: Root
|
4814 | };
|
4815 |
|
4816 | |
4817 |
|
4818 |
|
4819 |
|
4820 |
|
4821 |
|
4822 |
|
4823 |
|
4824 |
|
4825 |
|
4826 |
|
4827 |
|
4828 |
|
4829 |
|
4830 |
|
4831 |
|
4832 |
|
4833 | function create$1(type, attrs) {
|
4834 | var Type = types[type];
|
4835 | if (!Type) {
|
4836 | throw new Error('unknown type: <' + type + '>');
|
4837 | }
|
4838 | return assign(new Type(), attrs);
|
4839 | }
|
4840 |
|
4841 | |
4842 |
|
4843 |
|
4844 | function ElementFactory() {
|
4845 | this._uid = 12;
|
4846 | }
|
4847 |
|
4848 |
|
4849 | ElementFactory.prototype.createRoot = function(attrs) {
|
4850 | return this.create('root', attrs);
|
4851 | };
|
4852 |
|
4853 | ElementFactory.prototype.createLabel = function(attrs) {
|
4854 | return this.create('label', attrs);
|
4855 | };
|
4856 |
|
4857 | ElementFactory.prototype.createShape = function(attrs) {
|
4858 | return this.create('shape', attrs);
|
4859 | };
|
4860 |
|
4861 | ElementFactory.prototype.createConnection = function(attrs) {
|
4862 | return this.create('connection', attrs);
|
4863 | };
|
4864 |
|
4865 | |
4866 |
|
4867 |
|
4868 |
|
4869 |
|
4870 |
|
4871 |
|
4872 |
|
4873 | ElementFactory.prototype.create = function(type, attrs) {
|
4874 |
|
4875 | attrs = assign({}, attrs || {});
|
4876 |
|
4877 | if (!attrs.id) {
|
4878 | attrs.id = type + '_' + (this._uid++);
|
4879 | }
|
4880 |
|
4881 | return create$1(type, attrs);
|
4882 | };
|
4883 |
|
4884 | var FN_REF = '__fn';
|
4885 |
|
4886 | var DEFAULT_PRIORITY = 1000;
|
4887 |
|
4888 | var slice$1 = Array.prototype.slice;
|
4889 |
|
4890 | |
4891 |
|
4892 |
|
4893 |
|
4894 |
|
4895 |
|
4896 |
|
4897 |
|
4898 |
|
4899 |
|
4900 |
|
4901 |
|
4902 |
|
4903 |
|
4904 |
|
4905 |
|
4906 |
|
4907 |
|
4908 |
|
4909 |
|
4910 |
|
4911 |
|
4912 |
|
4913 |
|
4914 |
|
4915 |
|
4916 |
|
4917 |
|
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 | function EventBus() {
|
4974 | this._listeners = {};
|
4975 |
|
4976 |
|
4977 |
|
4978 | this.on('diagram.destroy', 1, this._destroy, this);
|
4979 | }
|
4980 |
|
4981 |
|
4982 | |
4983 |
|
4984 |
|
4985 |
|
4986 |
|
4987 |
|
4988 |
|
4989 |
|
4990 |
|
4991 |
|
4992 |
|
4993 |
|
4994 |
|
4995 |
|
4996 |
|
4997 |
|
4998 |
|
4999 | EventBus.prototype.on = function(events, priority, callback, that) {
|
5000 |
|
5001 | events = isArray(events) ? events : [ events ];
|
5002 |
|
5003 | if (isFunction(priority)) {
|
5004 | that = callback;
|
5005 | callback = priority;
|
5006 | priority = DEFAULT_PRIORITY;
|
5007 | }
|
5008 |
|
5009 | if (!isNumber(priority)) {
|
5010 | throw new Error('priority must be a number');
|
5011 | }
|
5012 |
|
5013 | var actualCallback = callback;
|
5014 |
|
5015 | if (that) {
|
5016 | actualCallback = bind(callback, that);
|
5017 |
|
5018 |
|
5019 |
|
5020 |
|
5021 | actualCallback[FN_REF] = callback[FN_REF] || callback;
|
5022 | }
|
5023 |
|
5024 | var self = this;
|
5025 |
|
5026 | events.forEach(function(e) {
|
5027 | self._addListener(e, {
|
5028 | priority: priority,
|
5029 | callback: actualCallback,
|
5030 | next: null
|
5031 | });
|
5032 | });
|
5033 | };
|
5034 |
|
5035 |
|
5036 | |
5037 |
|
5038 |
|
5039 |
|
5040 |
|
5041 |
|
5042 |
|
5043 |
|
5044 | EventBus.prototype.once = function(event, priority, callback, that) {
|
5045 | var self = this;
|
5046 |
|
5047 | if (isFunction(priority)) {
|
5048 | that = callback;
|
5049 | callback = priority;
|
5050 | priority = DEFAULT_PRIORITY;
|
5051 | }
|
5052 |
|
5053 | if (!isNumber(priority)) {
|
5054 | throw new Error('priority must be a number');
|
5055 | }
|
5056 |
|
5057 | function wrappedCallback() {
|
5058 | var result = callback.apply(that, arguments);
|
5059 |
|
5060 | self.off(event, wrappedCallback);
|
5061 |
|
5062 | return result;
|
5063 | }
|
5064 |
|
5065 |
|
5066 |
|
5067 |
|
5068 | wrappedCallback[FN_REF] = callback;
|
5069 |
|
5070 | this.on(event, priority, wrappedCallback);
|
5071 | };
|
5072 |
|
5073 |
|
5074 | |
5075 |
|
5076 |
|
5077 |
|
5078 |
|
5079 |
|
5080 |
|
5081 |
|
5082 | EventBus.prototype.off = function(events, callback) {
|
5083 |
|
5084 | events = isArray(events) ? events : [ events ];
|
5085 |
|
5086 | var self = this;
|
5087 |
|
5088 | events.forEach(function(event) {
|
5089 | self._removeListener(event, callback);
|
5090 | });
|
5091 |
|
5092 | };
|
5093 |
|
5094 |
|
5095 | |
5096 |
|
5097 |
|
5098 |
|
5099 |
|
5100 |
|
5101 |
|
5102 | EventBus.prototype.createEvent = function(data) {
|
5103 | var event = new InternalEvent();
|
5104 |
|
5105 | event.init(data);
|
5106 |
|
5107 | return event;
|
5108 | };
|
5109 |
|
5110 |
|
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 | EventBus.prototype.fire = function(type, data) {
|
5142 |
|
5143 | var event,
|
5144 | firstListener,
|
5145 | returnValue,
|
5146 | args;
|
5147 |
|
5148 | args = slice$1.call(arguments);
|
5149 |
|
5150 | if (typeof type === 'object') {
|
5151 | event = type;
|
5152 | type = event.type;
|
5153 | }
|
5154 |
|
5155 | if (!type) {
|
5156 | throw new Error('no event type specified');
|
5157 | }
|
5158 |
|
5159 | firstListener = this._listeners[type];
|
5160 |
|
5161 | if (!firstListener) {
|
5162 | return;
|
5163 | }
|
5164 |
|
5165 |
|
5166 |
|
5167 | if (data instanceof InternalEvent) {
|
5168 |
|
5169 |
|
5170 | event = data;
|
5171 | } else {
|
5172 | event = this.createEvent(data);
|
5173 | }
|
5174 |
|
5175 |
|
5176 | args[0] = event;
|
5177 |
|
5178 |
|
5179 | var originalType = event.type;
|
5180 |
|
5181 |
|
5182 | if (type !== originalType) {
|
5183 | event.type = type;
|
5184 | }
|
5185 |
|
5186 | try {
|
5187 | returnValue = this._invokeListeners(event, args, firstListener);
|
5188 | } finally {
|
5189 |
|
5190 |
|
5191 | if (type !== originalType) {
|
5192 | event.type = originalType;
|
5193 | }
|
5194 | }
|
5195 |
|
5196 |
|
5197 |
|
5198 | if (returnValue === undefined && event.defaultPrevented) {
|
5199 | returnValue = false;
|
5200 | }
|
5201 |
|
5202 | return returnValue;
|
5203 | };
|
5204 |
|
5205 |
|
5206 | EventBus.prototype.handleError = function(error) {
|
5207 | return this.fire('error', { error: error }) === false;
|
5208 | };
|
5209 |
|
5210 |
|
5211 | EventBus.prototype._destroy = function() {
|
5212 | this._listeners = {};
|
5213 | };
|
5214 |
|
5215 | EventBus.prototype._invokeListeners = function(event, args, listener) {
|
5216 |
|
5217 | var returnValue;
|
5218 |
|
5219 | while (listener) {
|
5220 |
|
5221 |
|
5222 | if (event.cancelBubble) {
|
5223 | break;
|
5224 | }
|
5225 |
|
5226 | returnValue = this._invokeListener(event, args, listener);
|
5227 |
|
5228 | listener = listener.next;
|
5229 | }
|
5230 |
|
5231 | return returnValue;
|
5232 | };
|
5233 |
|
5234 | EventBus.prototype._invokeListener = function(event, args, listener) {
|
5235 |
|
5236 | var returnValue;
|
5237 |
|
5238 | try {
|
5239 |
|
5240 |
|
5241 | returnValue = invokeFunction(listener.callback, args);
|
5242 |
|
5243 |
|
5244 | if (returnValue !== undefined) {
|
5245 | event.returnValue = returnValue;
|
5246 | event.stopPropagation();
|
5247 | }
|
5248 |
|
5249 |
|
5250 | if (returnValue === false) {
|
5251 | event.preventDefault();
|
5252 | }
|
5253 | } catch (e) {
|
5254 | if (!this.handleError(e)) {
|
5255 | console.error('unhandled error in event listener');
|
5256 | console.error(e.stack);
|
5257 |
|
5258 | throw e;
|
5259 | }
|
5260 | }
|
5261 |
|
5262 | return returnValue;
|
5263 | };
|
5264 |
|
5265 | |
5266 |
|
5267 |
|
5268 |
|
5269 |
|
5270 |
|
5271 |
|
5272 |
|
5273 |
|
5274 |
|
5275 |
|
5276 |
|
5277 |
|
5278 |
|
5279 |
|
5280 |
|
5281 | EventBus.prototype._addListener = function(event, newListener) {
|
5282 |
|
5283 | var listener = this._getListeners(event),
|
5284 | previousListener;
|
5285 |
|
5286 |
|
5287 | if (!listener) {
|
5288 | this._setListeners(event, newListener);
|
5289 |
|
5290 | return;
|
5291 | }
|
5292 |
|
5293 |
|
5294 |
|
5295 | while (listener) {
|
5296 |
|
5297 | if (listener.priority < newListener.priority) {
|
5298 |
|
5299 | newListener.next = listener;
|
5300 |
|
5301 | if (previousListener) {
|
5302 | previousListener.next = newListener;
|
5303 | } else {
|
5304 | this._setListeners(event, newListener);
|
5305 | }
|
5306 |
|
5307 | return;
|
5308 | }
|
5309 |
|
5310 | previousListener = listener;
|
5311 | listener = listener.next;
|
5312 | }
|
5313 |
|
5314 |
|
5315 | previousListener.next = newListener;
|
5316 | };
|
5317 |
|
5318 |
|
5319 | EventBus.prototype._getListeners = function(name) {
|
5320 | return this._listeners[name];
|
5321 | };
|
5322 |
|
5323 | EventBus.prototype._setListeners = function(name, listener) {
|
5324 | this._listeners[name] = listener;
|
5325 | };
|
5326 |
|
5327 | EventBus.prototype._removeListener = function(event, callback) {
|
5328 |
|
5329 | var listener = this._getListeners(event),
|
5330 | nextListener,
|
5331 | previousListener,
|
5332 | listenerCallback;
|
5333 |
|
5334 | if (!callback) {
|
5335 |
|
5336 |
|
5337 | this._setListeners(event, null);
|
5338 |
|
5339 | return;
|
5340 | }
|
5341 |
|
5342 | while (listener) {
|
5343 |
|
5344 | nextListener = listener.next;
|
5345 |
|
5346 | listenerCallback = listener.callback;
|
5347 |
|
5348 | if (listenerCallback === callback || listenerCallback[FN_REF] === callback) {
|
5349 | if (previousListener) {
|
5350 | previousListener.next = nextListener;
|
5351 | } else {
|
5352 |
|
5353 |
|
5354 | this._setListeners(event, nextListener);
|
5355 | }
|
5356 | }
|
5357 |
|
5358 | previousListener = listener;
|
5359 | listener = nextListener;
|
5360 | }
|
5361 | };
|
5362 |
|
5363 | |
5364 |
|
5365 |
|
5366 | function InternalEvent() { }
|
5367 |
|
5368 | InternalEvent.prototype.stopPropagation = function() {
|
5369 | this.cancelBubble = true;
|
5370 | };
|
5371 |
|
5372 | InternalEvent.prototype.preventDefault = function() {
|
5373 | this.defaultPrevented = true;
|
5374 | };
|
5375 |
|
5376 | InternalEvent.prototype.init = function(data) {
|
5377 | assign(this, data || {});
|
5378 | };
|
5379 |
|
5380 |
|
5381 | |
5382 |
|
5383 |
|
5384 |
|
5385 |
|
5386 |
|
5387 |
|
5388 |
|
5389 | function invokeFunction(fn, args) {
|
5390 | return fn.apply(null, args);
|
5391 | }
|
5392 |
|
5393 | |
5394 |
|
5395 |
|
5396 |
|
5397 |
|
5398 |
|
5399 |
|
5400 | |
5401 |
|
5402 |
|
5403 |
|
5404 |
|
5405 |
|
5406 |
|
5407 | function getVisual(gfx) {
|
5408 | return gfx.childNodes[0];
|
5409 | }
|
5410 |
|
5411 | |
5412 |
|
5413 |
|
5414 |
|
5415 |
|
5416 |
|
5417 | function getChildren(gfx) {
|
5418 | return gfx.parentNode.childNodes[1];
|
5419 | }
|
5420 |
|
5421 | |
5422 |
|
5423 |
|
5424 |
|
5425 |
|
5426 |
|
5427 |
|
5428 | function transform$1(gfx, x, y, angle, amount) {
|
5429 | var translate = createTransform();
|
5430 | translate.setTranslate(x, y);
|
5431 |
|
5432 | var rotate = createTransform();
|
5433 | rotate.setRotate(angle, 0, 0);
|
5434 |
|
5435 | var scale = createTransform();
|
5436 | scale.setScale(amount || 1, amount || 1);
|
5437 |
|
5438 | transform(gfx, [ translate, rotate, scale ]);
|
5439 | }
|
5440 |
|
5441 |
|
5442 | |
5443 |
|
5444 |
|
5445 |
|
5446 |
|
5447 | function translate(gfx, x, y) {
|
5448 | var translate = createTransform();
|
5449 | translate.setTranslate(x, y);
|
5450 |
|
5451 | transform(gfx, translate);
|
5452 | }
|
5453 |
|
5454 |
|
5455 | |
5456 |
|
5457 |
|
5458 |
|
5459 | function rotate(gfx, angle) {
|
5460 | var rotate = createTransform();
|
5461 | rotate.setRotate(angle, 0, 0);
|
5462 |
|
5463 | transform(gfx, rotate);
|
5464 | }
|
5465 |
|
5466 | |
5467 |
|
5468 |
|
5469 |
|
5470 |
|
5471 |
|
5472 | function GraphicsFactory(eventBus, elementRegistry) {
|
5473 | this._eventBus = eventBus;
|
5474 | this._elementRegistry = elementRegistry;
|
5475 | }
|
5476 |
|
5477 | GraphicsFactory.$inject = [ 'eventBus' , 'elementRegistry' ];
|
5478 |
|
5479 |
|
5480 | GraphicsFactory.prototype._getChildren = function(element) {
|
5481 |
|
5482 | var gfx = this._elementRegistry.getGraphics(element);
|
5483 |
|
5484 | var childrenGfx;
|
5485 |
|
5486 |
|
5487 | if (!element.parent) {
|
5488 | childrenGfx = gfx;
|
5489 | } else {
|
5490 | childrenGfx = getChildren(gfx);
|
5491 | if (!childrenGfx) {
|
5492 | childrenGfx = create('g');
|
5493 | classes$1(childrenGfx).add('djs-children');
|
5494 |
|
5495 | append(gfx.parentNode, childrenGfx);
|
5496 | }
|
5497 | }
|
5498 |
|
5499 | return childrenGfx;
|
5500 | };
|
5501 |
|
5502 | |
5503 |
|
5504 |
|
5505 |
|
5506 | GraphicsFactory.prototype._clear = function(gfx) {
|
5507 | var visual = getVisual(gfx);
|
5508 |
|
5509 | clear(visual);
|
5510 |
|
5511 | return visual;
|
5512 | };
|
5513 |
|
5514 | |
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 | GraphicsFactory.prototype._createContainer = function(
|
5542 | type, childrenGfx, parentIndex, isFrame
|
5543 | ) {
|
5544 | var outerGfx = create('g');
|
5545 | classes$1(outerGfx).add('djs-group');
|
5546 |
|
5547 |
|
5548 | if (typeof parentIndex !== 'undefined') {
|
5549 | prependTo(outerGfx, childrenGfx, childrenGfx.childNodes[parentIndex]);
|
5550 | } else {
|
5551 | append(childrenGfx, outerGfx);
|
5552 | }
|
5553 |
|
5554 | var gfx = create('g');
|
5555 | classes$1(gfx).add('djs-element');
|
5556 | classes$1(gfx).add('djs-' + type);
|
5557 |
|
5558 | if (isFrame) {
|
5559 | classes$1(gfx).add('djs-frame');
|
5560 | }
|
5561 |
|
5562 | append(outerGfx, gfx);
|
5563 |
|
5564 |
|
5565 | var visual = create('g');
|
5566 | classes$1(visual).add('djs-visual');
|
5567 |
|
5568 | append(gfx, visual);
|
5569 |
|
5570 | return gfx;
|
5571 | };
|
5572 |
|
5573 | GraphicsFactory.prototype.create = function(type, element, parentIndex) {
|
5574 | var childrenGfx = this._getChildren(element.parent);
|
5575 | return this._createContainer(type, childrenGfx, parentIndex, isFrameElement(element));
|
5576 | };
|
5577 |
|
5578 | GraphicsFactory.prototype.updateContainments = function(elements) {
|
5579 |
|
5580 | var self = this,
|
5581 | elementRegistry = this._elementRegistry,
|
5582 | parents;
|
5583 |
|
5584 | parents = reduce(elements, function(map, e) {
|
5585 |
|
5586 | if (e.parent) {
|
5587 | map[e.parent.id] = e.parent;
|
5588 | }
|
5589 |
|
5590 | return map;
|
5591 | }, {});
|
5592 |
|
5593 |
|
5594 |
|
5595 | forEach(parents, function(parent) {
|
5596 |
|
5597 | var children = parent.children;
|
5598 |
|
5599 | if (!children) {
|
5600 | return;
|
5601 | }
|
5602 |
|
5603 | var childGfx = self._getChildren(parent);
|
5604 |
|
5605 | forEach(children.slice().reverse(), function(c) {
|
5606 | var gfx = elementRegistry.getGraphics(c);
|
5607 |
|
5608 | prependTo(gfx.parentNode, childGfx);
|
5609 | });
|
5610 | });
|
5611 | };
|
5612 |
|
5613 | GraphicsFactory.prototype.drawShape = function(visual, element) {
|
5614 | var eventBus = this._eventBus;
|
5615 |
|
5616 | return eventBus.fire('render.shape', { gfx: visual, element: element });
|
5617 | };
|
5618 |
|
5619 | GraphicsFactory.prototype.getShapePath = function(element) {
|
5620 | var eventBus = this._eventBus;
|
5621 |
|
5622 | return eventBus.fire('render.getShapePath', element);
|
5623 | };
|
5624 |
|
5625 | GraphicsFactory.prototype.drawConnection = function(visual, element) {
|
5626 | var eventBus = this._eventBus;
|
5627 |
|
5628 | return eventBus.fire('render.connection', { gfx: visual, element: element });
|
5629 | };
|
5630 |
|
5631 | GraphicsFactory.prototype.getConnectionPath = function(waypoints) {
|
5632 | var eventBus = this._eventBus;
|
5633 |
|
5634 | return eventBus.fire('render.getConnectionPath', waypoints);
|
5635 | };
|
5636 |
|
5637 | GraphicsFactory.prototype.update = function(type, element, gfx) {
|
5638 |
|
5639 |
|
5640 | if (!element.parent) {
|
5641 | return;
|
5642 | }
|
5643 |
|
5644 | var visual = this._clear(gfx);
|
5645 |
|
5646 |
|
5647 | if (type === 'shape') {
|
5648 | this.drawShape(visual, element);
|
5649 |
|
5650 |
|
5651 | translate(gfx, element.x, element.y);
|
5652 | } else
|
5653 | if (type === 'connection') {
|
5654 | this.drawConnection(visual, element);
|
5655 | } else {
|
5656 | throw new Error('unknown type: ' + type);
|
5657 | }
|
5658 |
|
5659 | if (element.hidden) {
|
5660 | attr$1(gfx, 'display', 'none');
|
5661 | } else {
|
5662 | attr$1(gfx, 'display', 'block');
|
5663 | }
|
5664 | };
|
5665 |
|
5666 | GraphicsFactory.prototype.remove = function(element) {
|
5667 | var gfx = this._elementRegistry.getGraphics(element);
|
5668 |
|
5669 |
|
5670 | remove$1(gfx.parentNode);
|
5671 | };
|
5672 |
|
5673 |
|
5674 |
|
5675 |
|
5676 | function prependTo(newNode, parentNode, siblingNode) {
|
5677 | var node = siblingNode || parentNode.firstChild;
|
5678 |
|
5679 |
|
5680 |
|
5681 | if (newNode === node) {
|
5682 | return;
|
5683 | }
|
5684 |
|
5685 | parentNode.insertBefore(newNode, node);
|
5686 | }
|
5687 |
|
5688 | var CoreModule = {
|
5689 | __depends__: [ DrawModule ],
|
5690 | __init__: [ 'canvas' ],
|
5691 | canvas: [ 'type', Canvas ],
|
5692 | elementRegistry: [ 'type', ElementRegistry ],
|
5693 | elementFactory: [ 'type', ElementFactory ],
|
5694 | eventBus: [ 'type', EventBus ],
|
5695 | graphicsFactory: [ 'type', GraphicsFactory ]
|
5696 | };
|
5697 |
|
5698 | |
5699 |
|
5700 |
|
5701 |
|
5702 |
|
5703 |
|
5704 |
|
5705 |
|
5706 | function bootstrap(bootstrapModules) {
|
5707 |
|
5708 | var modules = [],
|
5709 | components = [];
|
5710 |
|
5711 | function hasModule(m) {
|
5712 | return modules.indexOf(m) >= 0;
|
5713 | }
|
5714 |
|
5715 | function addModule(m) {
|
5716 | modules.push(m);
|
5717 | }
|
5718 |
|
5719 | function visit(m) {
|
5720 | if (hasModule(m)) {
|
5721 | return;
|
5722 | }
|
5723 |
|
5724 | (m.__depends__ || []).forEach(visit);
|
5725 |
|
5726 | if (hasModule(m)) {
|
5727 | return;
|
5728 | }
|
5729 |
|
5730 | addModule(m);
|
5731 |
|
5732 | (m.__init__ || []).forEach(function(c) {
|
5733 | components.push(c);
|
5734 | });
|
5735 | }
|
5736 |
|
5737 | bootstrapModules.forEach(visit);
|
5738 |
|
5739 | var injector = new Injector(modules);
|
5740 |
|
5741 | components.forEach(function(c) {
|
5742 |
|
5743 | try {
|
5744 |
|
5745 |
|
5746 | injector[typeof c === 'string' ? 'get' : 'invoke'](c);
|
5747 | } catch (e) {
|
5748 | console.error('Failed to instantiate component');
|
5749 | console.error(e.stack);
|
5750 |
|
5751 | throw e;
|
5752 | }
|
5753 | });
|
5754 |
|
5755 | return injector;
|
5756 | }
|
5757 |
|
5758 | |
5759 |
|
5760 |
|
5761 |
|
5762 |
|
5763 |
|
5764 |
|
5765 | function createInjector(options) {
|
5766 |
|
5767 | options = options || {};
|
5768 |
|
5769 | var configModule = {
|
5770 | 'config': ['value', options]
|
5771 | };
|
5772 |
|
5773 | var modules = [ configModule, CoreModule ].concat(options.modules || []);
|
5774 |
|
5775 | return bootstrap(modules);
|
5776 | }
|
5777 |
|
5778 |
|
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 | function Diagram(options, injector) {
|
5829 |
|
5830 |
|
5831 | this.injector = injector = injector || createInjector(options);
|
5832 |
|
5833 |
|
5834 |
|
5835 | |
5836 |
|
5837 |
|
5838 |
|
5839 |
|
5840 |
|
5841 |
|
5842 |
|
5843 | this.get = injector.get;
|
5844 |
|
5845 | |
5846 |
|
5847 |
|
5848 |
|
5849 |
|
5850 |
|
5851 |
|
5852 |
|
5853 | this.invoke = injector.invoke;
|
5854 |
|
5855 |
|
5856 |
|
5857 |
|
5858 |
|
5859 |
|
5860 | |
5861 |
|
5862 |
|
5863 |
|
5864 |
|
5865 |
|
5866 |
|
5867 |
|
5868 |
|
5869 |
|
5870 |
|
5871 |
|
5872 |
|
5873 |
|
5874 |
|
5875 |
|
5876 |
|
5877 | this.get('eventBus').fire('diagram.init');
|
5878 | }
|
5879 |
|
5880 |
|
5881 | |
5882 |
|
5883 |
|
5884 |
|
5885 |
|
5886 | Diagram.prototype.destroy = function() {
|
5887 | this.get('eventBus').fire('diagram.destroy');
|
5888 | };
|
5889 |
|
5890 | |
5891 |
|
5892 |
|
5893 | Diagram.prototype.clear = function() {
|
5894 | this.get('eventBus').fire('diagram.clear');
|
5895 | };
|
5896 |
|
5897 | |
5898 |
|
5899 |
|
5900 | function Base$1() { }
|
5901 |
|
5902 | Base$1.prototype.get = function(name) {
|
5903 | return this.$model.properties.get(this, name);
|
5904 | };
|
5905 |
|
5906 | Base$1.prototype.set = function(name, value) {
|
5907 | this.$model.properties.set(this, name, value);
|
5908 | };
|
5909 |
|
5910 | |
5911 |
|
5912 |
|
5913 |
|
5914 |
|
5915 |
|
5916 | function Factory(model, properties) {
|
5917 | this.model = model;
|
5918 | this.properties = properties;
|
5919 | }
|
5920 |
|
5921 |
|
5922 | Factory.prototype.createType = function(descriptor) {
|
5923 |
|
5924 | var model = this.model;
|
5925 |
|
5926 | var props = this.properties,
|
5927 | prototype = Object.create(Base$1.prototype);
|
5928 |
|
5929 |
|
5930 | forEach(descriptor.properties, function(p) {
|
5931 | if (!p.isMany && p.default !== undefined) {
|
5932 | prototype[p.name] = p.default;
|
5933 | }
|
5934 | });
|
5935 |
|
5936 | props.defineModel(prototype, model);
|
5937 | props.defineDescriptor(prototype, descriptor);
|
5938 |
|
5939 | var name = descriptor.ns.name;
|
5940 |
|
5941 | |
5942 |
|
5943 |
|
5944 | function ModdleElement(attrs) {
|
5945 | props.define(this, '$type', { value: name, enumerable: true });
|
5946 | props.define(this, '$attrs', { value: {} });
|
5947 | props.define(this, '$parent', { writable: true });
|
5948 |
|
5949 | forEach(attrs, bind(function(val, key) {
|
5950 | this.set(key, val);
|
5951 | }, this));
|
5952 | }
|
5953 |
|
5954 | ModdleElement.prototype = prototype;
|
5955 |
|
5956 | ModdleElement.hasType = prototype.$instanceOf = this.model.hasType;
|
5957 |
|
5958 |
|
5959 | props.defineModel(ModdleElement, model);
|
5960 | props.defineDescriptor(ModdleElement, descriptor);
|
5961 |
|
5962 | return ModdleElement;
|
5963 | };
|
5964 |
|
5965 | |
5966 |
|
5967 |
|
5968 | var BUILTINS = {
|
5969 | String: true,
|
5970 | Boolean: true,
|
5971 | Integer: true,
|
5972 | Real: true,
|
5973 | Element: true
|
5974 | };
|
5975 |
|
5976 | |
5977 |
|
5978 |
|
5979 | var TYPE_CONVERTERS = {
|
5980 | String: function(s) { return s; },
|
5981 | Boolean: function(s) { return s === 'true'; },
|
5982 | Integer: function(s) { return parseInt(s, 10); },
|
5983 | Real: function(s) { return parseFloat(s, 10); }
|
5984 | };
|
5985 |
|
5986 | |
5987 |
|
5988 |
|
5989 | function coerceType(type, value) {
|
5990 |
|
5991 | var converter = TYPE_CONVERTERS[type];
|
5992 |
|
5993 | if (converter) {
|
5994 | return converter(value);
|
5995 | } else {
|
5996 | return value;
|
5997 | }
|
5998 | }
|
5999 |
|
6000 | |
6001 |
|
6002 |
|
6003 | function isBuiltIn(type) {
|
6004 | return !!BUILTINS[type];
|
6005 | }
|
6006 |
|
6007 | |
6008 |
|
6009 |
|
6010 | function isSimple(type) {
|
6011 | return !!TYPE_CONVERTERS[type];
|
6012 | }
|
6013 |
|
6014 | |
6015 |
|
6016 |
|
6017 |
|
6018 |
|
6019 |
|
6020 |
|
6021 |
|
6022 |
|
6023 | function parseName(name, defaultPrefix) {
|
6024 | var parts = name.split(/:/),
|
6025 | localName, prefix;
|
6026 |
|
6027 |
|
6028 | if (parts.length === 1) {
|
6029 | localName = name;
|
6030 | prefix = defaultPrefix;
|
6031 | } else
|
6032 |
|
6033 | if (parts.length === 2) {
|
6034 | localName = parts[1];
|
6035 | prefix = parts[0];
|
6036 | } else {
|
6037 | throw new Error('expected <prefix:localName> or <localName>, got ' + name);
|
6038 | }
|
6039 |
|
6040 | name = (prefix ? prefix + ':' : '') + localName;
|
6041 |
|
6042 | return {
|
6043 | name: name,
|
6044 | prefix: prefix,
|
6045 | localName: localName
|
6046 | };
|
6047 | }
|
6048 |
|
6049 | |
6050 |
|
6051 |
|
6052 | function DescriptorBuilder(nameNs) {
|
6053 | this.ns = nameNs;
|
6054 | this.name = nameNs.name;
|
6055 | this.allTypes = [];
|
6056 | this.allTypesByName = {};
|
6057 | this.properties = [];
|
6058 | this.propertiesByName = {};
|
6059 | }
|
6060 |
|
6061 |
|
6062 | DescriptorBuilder.prototype.build = function() {
|
6063 | return pick(this, [
|
6064 | 'ns',
|
6065 | 'name',
|
6066 | 'allTypes',
|
6067 | 'allTypesByName',
|
6068 | 'properties',
|
6069 | 'propertiesByName',
|
6070 | 'bodyProperty',
|
6071 | 'idProperty'
|
6072 | ]);
|
6073 | };
|
6074 |
|
6075 | |
6076 |
|
6077 |
|
6078 |
|
6079 |
|
6080 |
|
6081 |
|
6082 | DescriptorBuilder.prototype.addProperty = function(p, idx, validate) {
|
6083 |
|
6084 | if (typeof idx === 'boolean') {
|
6085 | validate = idx;
|
6086 | idx = undefined;
|
6087 | }
|
6088 |
|
6089 | this.addNamedProperty(p, validate !== false);
|
6090 |
|
6091 | var properties = this.properties;
|
6092 |
|
6093 | if (idx !== undefined) {
|
6094 | properties.splice(idx, 0, p);
|
6095 | } else {
|
6096 | properties.push(p);
|
6097 | }
|
6098 | };
|
6099 |
|
6100 |
|
6101 | DescriptorBuilder.prototype.replaceProperty = function(oldProperty, newProperty, replace) {
|
6102 | var oldNameNs = oldProperty.ns;
|
6103 |
|
6104 | var props = this.properties,
|
6105 | propertiesByName = this.propertiesByName,
|
6106 | rename = oldProperty.name !== newProperty.name;
|
6107 |
|
6108 | if (oldProperty.isId) {
|
6109 | if (!newProperty.isId) {
|
6110 | throw new Error(
|
6111 | 'property <' + newProperty.ns.name + '> must be id property ' +
|
6112 | 'to refine <' + oldProperty.ns.name + '>');
|
6113 | }
|
6114 |
|
6115 | this.setIdProperty(newProperty, false);
|
6116 | }
|
6117 |
|
6118 | if (oldProperty.isBody) {
|
6119 |
|
6120 | if (!newProperty.isBody) {
|
6121 | throw new Error(
|
6122 | 'property <' + newProperty.ns.name + '> must be body property ' +
|
6123 | 'to refine <' + oldProperty.ns.name + '>');
|
6124 | }
|
6125 |
|
6126 |
|
6127 | this.setBodyProperty(newProperty, false);
|
6128 | }
|
6129 |
|
6130 |
|
6131 | var idx = props.indexOf(oldProperty);
|
6132 | if (idx === -1) {
|
6133 | throw new Error('property <' + oldNameNs.name + '> not found in property list');
|
6134 | }
|
6135 |
|
6136 |
|
6137 | props.splice(idx, 1);
|
6138 |
|
6139 |
|
6140 |
|
6141 |
|
6142 |
|
6143 |
|
6144 | this.addProperty(newProperty, replace ? undefined : idx, rename);
|
6145 |
|
6146 |
|
6147 | propertiesByName[oldNameNs.name] = propertiesByName[oldNameNs.localName] = newProperty;
|
6148 | };
|
6149 |
|
6150 |
|
6151 | DescriptorBuilder.prototype.redefineProperty = function(p, targetPropertyName, replace) {
|
6152 |
|
6153 | var nsPrefix = p.ns.prefix;
|
6154 | var parts = targetPropertyName.split('#');
|
6155 |
|
6156 | var name = parseName(parts[0], nsPrefix);
|
6157 | var attrName = parseName(parts[1], name.prefix).name;
|
6158 |
|
6159 | var redefinedProperty = this.propertiesByName[attrName];
|
6160 | if (!redefinedProperty) {
|
6161 | throw new Error('refined property <' + attrName + '> not found');
|
6162 | } else {
|
6163 | this.replaceProperty(redefinedProperty, p, replace);
|
6164 | }
|
6165 |
|
6166 | delete p.redefines;
|
6167 | };
|
6168 |
|
6169 | DescriptorBuilder.prototype.addNamedProperty = function(p, validate) {
|
6170 | var ns = p.ns,
|
6171 | propsByName = this.propertiesByName;
|
6172 |
|
6173 | if (validate) {
|
6174 | this.assertNotDefined(p, ns.name);
|
6175 | this.assertNotDefined(p, ns.localName);
|
6176 | }
|
6177 |
|
6178 | propsByName[ns.name] = propsByName[ns.localName] = p;
|
6179 | };
|
6180 |
|
6181 | DescriptorBuilder.prototype.removeNamedProperty = function(p) {
|
6182 | var ns = p.ns,
|
6183 | propsByName = this.propertiesByName;
|
6184 |
|
6185 | delete propsByName[ns.name];
|
6186 | delete propsByName[ns.localName];
|
6187 | };
|
6188 |
|
6189 | DescriptorBuilder.prototype.setBodyProperty = function(p, validate) {
|
6190 |
|
6191 | if (validate && this.bodyProperty) {
|
6192 | throw new Error(
|
6193 | 'body property defined multiple times ' +
|
6194 | '(<' + this.bodyProperty.ns.name + '>, <' + p.ns.name + '>)');
|
6195 | }
|
6196 |
|
6197 | this.bodyProperty = p;
|
6198 | };
|
6199 |
|
6200 | DescriptorBuilder.prototype.setIdProperty = function(p, validate) {
|
6201 |
|
6202 | if (validate && this.idProperty) {
|
6203 | throw new Error(
|
6204 | 'id property defined multiple times ' +
|
6205 | '(<' + this.idProperty.ns.name + '>, <' + p.ns.name + '>)');
|
6206 | }
|
6207 |
|
6208 | this.idProperty = p;
|
6209 | };
|
6210 |
|
6211 | DescriptorBuilder.prototype.assertNotDefined = function(p, name) {
|
6212 | var propertyName = p.name,
|
6213 | definedProperty = this.propertiesByName[propertyName];
|
6214 |
|
6215 | if (definedProperty) {
|
6216 | throw new Error(
|
6217 | 'property <' + propertyName + '> already defined; ' +
|
6218 | 'override of <' + definedProperty.definedBy.ns.name + '#' + definedProperty.ns.name + '> by ' +
|
6219 | '<' + p.definedBy.ns.name + '#' + p.ns.name + '> not allowed without redefines');
|
6220 | }
|
6221 | };
|
6222 |
|
6223 | DescriptorBuilder.prototype.hasProperty = function(name) {
|
6224 | return this.propertiesByName[name];
|
6225 | };
|
6226 |
|
6227 | DescriptorBuilder.prototype.addTrait = function(t, inherited) {
|
6228 |
|
6229 | var typesByName = this.allTypesByName,
|
6230 | types = this.allTypes;
|
6231 |
|
6232 | var typeName = t.name;
|
6233 |
|
6234 | if (typeName in typesByName) {
|
6235 | return;
|
6236 | }
|
6237 |
|
6238 | forEach(t.properties, bind(function(p) {
|
6239 |
|
6240 |
|
6241 | p = assign({}, p, {
|
6242 | name: p.ns.localName,
|
6243 | inherited: inherited
|
6244 | });
|
6245 |
|
6246 | Object.defineProperty(p, 'definedBy', {
|
6247 | value: t
|
6248 | });
|
6249 |
|
6250 | var replaces = p.replaces,
|
6251 | redefines = p.redefines;
|
6252 |
|
6253 |
|
6254 | if (replaces || redefines) {
|
6255 | this.redefineProperty(p, replaces || redefines, replaces);
|
6256 | } else {
|
6257 | if (p.isBody) {
|
6258 | this.setBodyProperty(p);
|
6259 | }
|
6260 | if (p.isId) {
|
6261 | this.setIdProperty(p);
|
6262 | }
|
6263 | this.addProperty(p);
|
6264 | }
|
6265 | }, this));
|
6266 |
|
6267 | types.push(t);
|
6268 | typesByName[typeName] = t;
|
6269 | };
|
6270 |
|
6271 | |
6272 |
|
6273 |
|
6274 |
|
6275 |
|
6276 |
|
6277 | function Registry(packages, properties) {
|
6278 | this.packageMap = {};
|
6279 | this.typeMap = {};
|
6280 |
|
6281 | this.packages = [];
|
6282 |
|
6283 | this.properties = properties;
|
6284 |
|
6285 | forEach(packages, bind(this.registerPackage, this));
|
6286 | }
|
6287 |
|
6288 |
|
6289 | Registry.prototype.getPackage = function(uriOrPrefix) {
|
6290 | return this.packageMap[uriOrPrefix];
|
6291 | };
|
6292 |
|
6293 | Registry.prototype.getPackages = function() {
|
6294 | return this.packages;
|
6295 | };
|
6296 |
|
6297 |
|
6298 | Registry.prototype.registerPackage = function(pkg) {
|
6299 |
|
6300 |
|
6301 | pkg = assign({}, pkg);
|
6302 |
|
6303 | var pkgMap = this.packageMap;
|
6304 |
|
6305 | ensureAvailable(pkgMap, pkg, 'prefix');
|
6306 | ensureAvailable(pkgMap, pkg, 'uri');
|
6307 |
|
6308 |
|
6309 | forEach(pkg.types, bind(function(descriptor) {
|
6310 | this.registerType(descriptor, pkg);
|
6311 | }, this));
|
6312 |
|
6313 | pkgMap[pkg.uri] = pkgMap[pkg.prefix] = pkg;
|
6314 | this.packages.push(pkg);
|
6315 | };
|
6316 |
|
6317 |
|
6318 | |
6319 |
|
6320 |
|
6321 | Registry.prototype.registerType = function(type, pkg) {
|
6322 |
|
6323 | type = assign({}, type, {
|
6324 | superClass: (type.superClass || []).slice(),
|
6325 | extends: (type.extends || []).slice(),
|
6326 | properties: (type.properties || []).slice(),
|
6327 | meta: assign((type.meta || {}))
|
6328 | });
|
6329 |
|
6330 | var ns = parseName(type.name, pkg.prefix),
|
6331 | name = ns.name,
|
6332 | propertiesByName = {};
|
6333 |
|
6334 |
|
6335 | forEach(type.properties, bind(function(p) {
|
6336 |
|
6337 |
|
6338 | var propertyNs = parseName(p.name, ns.prefix),
|
6339 | propertyName = propertyNs.name;
|
6340 |
|
6341 |
|
6342 | if (!isBuiltIn(p.type)) {
|
6343 | p.type = parseName(p.type, propertyNs.prefix).name;
|
6344 | }
|
6345 |
|
6346 | assign(p, {
|
6347 | ns: propertyNs,
|
6348 | name: propertyName
|
6349 | });
|
6350 |
|
6351 | propertiesByName[propertyName] = p;
|
6352 | }, this));
|
6353 |
|
6354 |
|
6355 | assign(type, {
|
6356 | ns: ns,
|
6357 | name: name,
|
6358 | propertiesByName: propertiesByName
|
6359 | });
|
6360 |
|
6361 | forEach(type.extends, bind(function(extendsName) {
|
6362 | var extended = this.typeMap[extendsName];
|
6363 |
|
6364 | extended.traits = extended.traits || [];
|
6365 | extended.traits.push(name);
|
6366 | }, this));
|
6367 |
|
6368 |
|
6369 | this.definePackage(type, pkg);
|
6370 |
|
6371 |
|
6372 | this.typeMap[name] = type;
|
6373 | };
|
6374 |
|
6375 |
|
6376 | |
6377 |
|
6378 |
|
6379 |
|
6380 |
|
6381 |
|
6382 |
|
6383 |
|
6384 |
|
6385 | Registry.prototype.mapTypes = function(nsName, iterator, trait) {
|
6386 |
|
6387 | var type = isBuiltIn(nsName.name) ? { name: nsName.name } : this.typeMap[nsName.name];
|
6388 |
|
6389 | var self = this;
|
6390 |
|
6391 | |
6392 |
|
6393 |
|
6394 |
|
6395 |
|
6396 | function traverseTrait(cls) {
|
6397 | return traverseSuper(cls, true);
|
6398 | }
|
6399 |
|
6400 | |
6401 |
|
6402 |
|
6403 |
|
6404 |
|
6405 |
|
6406 | function traverseSuper(cls, trait) {
|
6407 | var parentNs = parseName(cls, isBuiltIn(cls) ? '' : nsName.prefix);
|
6408 | self.mapTypes(parentNs, iterator, trait);
|
6409 | }
|
6410 |
|
6411 | if (!type) {
|
6412 | throw new Error('unknown type <' + nsName.name + '>');
|
6413 | }
|
6414 |
|
6415 | forEach(type.superClass, trait ? traverseTrait : traverseSuper);
|
6416 |
|
6417 |
|
6418 | iterator(type, !trait);
|
6419 |
|
6420 | forEach(type.traits, traverseTrait);
|
6421 | };
|
6422 |
|
6423 |
|
6424 | |
6425 |
|
6426 |
|
6427 |
|
6428 |
|
6429 |
|
6430 |
|
6431 | Registry.prototype.getEffectiveDescriptor = function(name) {
|
6432 |
|
6433 | var nsName = parseName(name);
|
6434 |
|
6435 | var builder = new DescriptorBuilder(nsName);
|
6436 |
|
6437 | this.mapTypes(nsName, function(type, inherited) {
|
6438 | builder.addTrait(type, inherited);
|
6439 | });
|
6440 |
|
6441 | var descriptor = builder.build();
|
6442 |
|
6443 |
|
6444 | this.definePackage(descriptor, descriptor.allTypes[descriptor.allTypes.length - 1].$pkg);
|
6445 |
|
6446 | return descriptor;
|
6447 | };
|
6448 |
|
6449 |
|
6450 | Registry.prototype.definePackage = function(target, pkg) {
|
6451 | this.properties.define(target, '$pkg', { value: pkg });
|
6452 | };
|
6453 |
|
6454 |
|
6455 |
|
6456 |
|
6457 |
|
6458 | function ensureAvailable(packageMap, pkg, identifierKey) {
|
6459 |
|
6460 | var value = pkg[identifierKey];
|
6461 |
|
6462 | if (value in packageMap) {
|
6463 | throw new Error('package with ' + identifierKey + ' <' + value + '> already defined');
|
6464 | }
|
6465 | }
|
6466 |
|
6467 | |
6468 |
|
6469 |
|
6470 |
|
6471 |
|
6472 | function Properties(model) {
|
6473 | this.model = model;
|
6474 | }
|
6475 |
|
6476 |
|
6477 | |
6478 |
|
6479 |
|
6480 |
|
6481 |
|
6482 |
|
6483 |
|
6484 |
|
6485 | Properties.prototype.set = function(target, name, value) {
|
6486 |
|
6487 | var property = this.model.getPropertyDescriptor(target, name);
|
6488 |
|
6489 | var propertyName = property && property.name;
|
6490 |
|
6491 | if (isUndefined$1(value)) {
|
6492 |
|
6493 |
|
6494 | if (property) {
|
6495 | delete target[propertyName];
|
6496 | } else {
|
6497 | delete target.$attrs[name];
|
6498 | }
|
6499 | } else {
|
6500 |
|
6501 |
|
6502 | if (property) {
|
6503 | if (propertyName in target) {
|
6504 | target[propertyName] = value;
|
6505 | } else {
|
6506 | defineProperty$1(target, property, value);
|
6507 | }
|
6508 | } else {
|
6509 | target.$attrs[name] = value;
|
6510 | }
|
6511 | }
|
6512 | };
|
6513 |
|
6514 | |
6515 |
|
6516 |
|
6517 |
|
6518 |
|
6519 |
|
6520 |
|
6521 |
|
6522 | Properties.prototype.get = function(target, name) {
|
6523 |
|
6524 | var property = this.model.getPropertyDescriptor(target, name);
|
6525 |
|
6526 | if (!property) {
|
6527 | return target.$attrs[name];
|
6528 | }
|
6529 |
|
6530 | var propertyName = property.name;
|
6531 |
|
6532 |
|
6533 | if (!target[propertyName] && property.isMany) {
|
6534 | defineProperty$1(target, property, []);
|
6535 | }
|
6536 |
|
6537 | return target[propertyName];
|
6538 | };
|
6539 |
|
6540 |
|
6541 | |
6542 |
|
6543 |
|
6544 |
|
6545 |
|
6546 |
|
6547 |
|
6548 | Properties.prototype.define = function(target, name, options) {
|
6549 | Object.defineProperty(target, name, options);
|
6550 | };
|
6551 |
|
6552 |
|
6553 | |
6554 |
|
6555 |
|
6556 | Properties.prototype.defineDescriptor = function(target, descriptor) {
|
6557 | this.define(target, '$descriptor', { value: descriptor });
|
6558 | };
|
6559 |
|
6560 | |
6561 |
|
6562 |
|
6563 | Properties.prototype.defineModel = function(target, model) {
|
6564 | this.define(target, '$model', { value: model });
|
6565 | };
|
6566 |
|
6567 |
|
6568 | function isUndefined$1(val) {
|
6569 | return typeof val === 'undefined';
|
6570 | }
|
6571 |
|
6572 | function defineProperty$1(target, property, value) {
|
6573 | Object.defineProperty(target, property.name, {
|
6574 | enumerable: !property.isReference,
|
6575 | writable: true,
|
6576 | value: value,
|
6577 | configurable: true
|
6578 | });
|
6579 | }
|
6580 |
|
6581 |
|
6582 |
|
6583 | |
6584 |
|
6585 |
|
6586 |
|
6587 |
|
6588 |
|
6589 |
|
6590 |
|
6591 |
|
6592 |
|
6593 |
|
6594 |
|
6595 |
|
6596 |
|
6597 |
|
6598 |
|
6599 |
|
6600 |
|
6601 |
|
6602 |
|
6603 |
|
6604 | function Moddle(packages) {
|
6605 |
|
6606 | this.properties = new Properties(this);
|
6607 |
|
6608 | this.factory = new Factory(this, this.properties);
|
6609 | this.registry = new Registry(packages, this.properties);
|
6610 |
|
6611 | this.typeCache = {};
|
6612 | }
|
6613 |
|
6614 |
|
6615 | |
6616 |
|
6617 |
|
6618 |
|
6619 |
|
6620 |
|
6621 |
|
6622 |
|
6623 |
|
6624 |
|
6625 |
|
6626 |
|
6627 |
|
6628 |
|
6629 | Moddle.prototype.create = function(descriptor, attrs) {
|
6630 | var Type = this.getType(descriptor);
|
6631 |
|
6632 | if (!Type) {
|
6633 | throw new Error('unknown type <' + descriptor + '>');
|
6634 | }
|
6635 |
|
6636 | return new Type(attrs);
|
6637 | };
|
6638 |
|
6639 |
|
6640 | |
6641 |
|
6642 |
|
6643 |
|
6644 |
|
6645 |
|
6646 |
|
6647 |
|
6648 |
|
6649 |
|
6650 |
|
6651 |
|
6652 |
|
6653 | Moddle.prototype.getType = function(descriptor) {
|
6654 |
|
6655 | var cache = this.typeCache;
|
6656 |
|
6657 | var name = isString(descriptor) ? descriptor : descriptor.ns.name;
|
6658 |
|
6659 | var type = cache[name];
|
6660 |
|
6661 | if (!type) {
|
6662 | descriptor = this.registry.getEffectiveDescriptor(name);
|
6663 | type = cache[name] = this.factory.createType(descriptor);
|
6664 | }
|
6665 |
|
6666 | return type;
|
6667 | };
|
6668 |
|
6669 |
|
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 | Moddle.prototype.createAny = function(name, nsUri, properties) {
|
6698 |
|
6699 | var nameNs = parseName(name);
|
6700 |
|
6701 | var element = {
|
6702 | $type: name,
|
6703 | $instanceOf: function(type) {
|
6704 | return type === this.$type;
|
6705 | }
|
6706 | };
|
6707 |
|
6708 | var descriptor = {
|
6709 | name: name,
|
6710 | isGeneric: true,
|
6711 | ns: {
|
6712 | prefix: nameNs.prefix,
|
6713 | localName: nameNs.localName,
|
6714 | uri: nsUri
|
6715 | }
|
6716 | };
|
6717 |
|
6718 | this.properties.defineDescriptor(element, descriptor);
|
6719 | this.properties.defineModel(element, this);
|
6720 | this.properties.define(element, '$parent', { enumerable: false, writable: true });
|
6721 |
|
6722 | forEach(properties, function(a, key) {
|
6723 | if (isObject(a) && a.value !== undefined) {
|
6724 | element[a.name] = a.value;
|
6725 | } else {
|
6726 | element[key] = a;
|
6727 | }
|
6728 | });
|
6729 |
|
6730 | return element;
|
6731 | };
|
6732 |
|
6733 | |
6734 |
|
6735 |
|
6736 |
|
6737 |
|
6738 | Moddle.prototype.getPackage = function(uriOrPrefix) {
|
6739 | return this.registry.getPackage(uriOrPrefix);
|
6740 | };
|
6741 |
|
6742 | |
6743 |
|
6744 |
|
6745 |
|
6746 |
|
6747 | Moddle.prototype.getPackages = function() {
|
6748 | return this.registry.getPackages();
|
6749 | };
|
6750 |
|
6751 | |
6752 |
|
6753 |
|
6754 | Moddle.prototype.getElementDescriptor = function(element) {
|
6755 | return element.$descriptor;
|
6756 | };
|
6757 |
|
6758 | |
6759 |
|
6760 |
|
6761 |
|
6762 |
|
6763 |
|
6764 | Moddle.prototype.hasType = function(element, type) {
|
6765 | if (type === undefined) {
|
6766 | type = element;
|
6767 | element = this;
|
6768 | }
|
6769 |
|
6770 | var descriptor = element.$model.getElementDescriptor(element);
|
6771 |
|
6772 | return (type in descriptor.allTypesByName);
|
6773 | };
|
6774 |
|
6775 | |
6776 |
|
6777 |
|
6778 | Moddle.prototype.getPropertyDescriptor = function(element, property) {
|
6779 | return this.getElementDescriptor(element).propertiesByName[property];
|
6780 | };
|
6781 |
|
6782 | |
6783 |
|
6784 |
|
6785 | Moddle.prototype.getTypeDescriptor = function(type) {
|
6786 | return this.registry.typeMap[type];
|
6787 | };
|
6788 |
|
6789 | var fromCharCode = String.fromCharCode;
|
6790 |
|
6791 | var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
6792 |
|
6793 | var ENTITY_PATTERN = /&#(\d+);|&#x([0-9a-f]+);|&(\w+);/ig;
|
6794 |
|
6795 | var ENTITY_MAPPING = {
|
6796 | 'amp': '&',
|
6797 | 'apos': '\'',
|
6798 | 'gt': '>',
|
6799 | 'lt': '<',
|
6800 | 'quot': '"'
|
6801 | };
|
6802 |
|
6803 |
|
6804 | Object.keys(ENTITY_MAPPING).forEach(function(k) {
|
6805 | ENTITY_MAPPING[k.toUpperCase()] = ENTITY_MAPPING[k];
|
6806 | });
|
6807 |
|
6808 |
|
6809 | function replaceEntities(_, d, x, z) {
|
6810 |
|
6811 |
|
6812 | if (z) {
|
6813 | if (hasOwnProperty$1.call(ENTITY_MAPPING, z)) {
|
6814 | return ENTITY_MAPPING[z];
|
6815 | } else {
|
6816 |
|
6817 | return '&' + z + ';';
|
6818 | }
|
6819 | }
|
6820 |
|
6821 |
|
6822 | if (d) {
|
6823 | return fromCharCode(d);
|
6824 | }
|
6825 |
|
6826 |
|
6827 | return fromCharCode(parseInt(x, 16));
|
6828 | }
|
6829 |
|
6830 |
|
6831 | |
6832 |
|
6833 |
|
6834 |
|
6835 |
|
6836 |
|
6837 |
|
6838 |
|
6839 |
|
6840 | function decodeEntities(s) {
|
6841 | if (s.length > 3 && s.indexOf('&') !== -1) {
|
6842 | return s.replace(ENTITY_PATTERN, replaceEntities);
|
6843 | }
|
6844 |
|
6845 | return s;
|
6846 | }
|
6847 |
|
6848 | var XSI_URI = 'http://www.w3.org/2001/XMLSchema-instance';
|
6849 | var XSI_PREFIX = 'xsi';
|
6850 | var XSI_TYPE = 'xsi:type';
|
6851 |
|
6852 | var NON_WHITESPACE_OUTSIDE_ROOT_NODE = 'non-whitespace outside of root node';
|
6853 |
|
6854 | function error(msg) {
|
6855 | return new Error(msg);
|
6856 | }
|
6857 |
|
6858 | function missingNamespaceForPrefix(prefix) {
|
6859 | return 'missing namespace for prefix <' + prefix + '>';
|
6860 | }
|
6861 |
|
6862 | function getter(getFn) {
|
6863 | return {
|
6864 | 'get': getFn,
|
6865 | 'enumerable': true
|
6866 | };
|
6867 | }
|
6868 |
|
6869 | function cloneNsMatrix(nsMatrix) {
|
6870 | var clone = {}, key;
|
6871 | for (key in nsMatrix) {
|
6872 | clone[key] = nsMatrix[key];
|
6873 | }
|
6874 | return clone;
|
6875 | }
|
6876 |
|
6877 | function uriPrefix(prefix) {
|
6878 | return prefix + '$uri';
|
6879 | }
|
6880 |
|
6881 | function buildNsMatrix(nsUriToPrefix) {
|
6882 | var nsMatrix = {},
|
6883 | uri,
|
6884 | prefix;
|
6885 |
|
6886 | for (uri in nsUriToPrefix) {
|
6887 | prefix = nsUriToPrefix[uri];
|
6888 | nsMatrix[prefix] = prefix;
|
6889 | nsMatrix[uriPrefix(prefix)] = uri;
|
6890 | }
|
6891 |
|
6892 | return nsMatrix;
|
6893 | }
|
6894 |
|
6895 | function noopGetContext() {
|
6896 | return { 'line': 0, 'column': 0 };
|
6897 | }
|
6898 |
|
6899 | function throwFunc(err) {
|
6900 | throw err;
|
6901 | }
|
6902 |
|
6903 | |
6904 |
|
6905 |
|
6906 |
|
6907 |
|
6908 |
|
6909 |
|
6910 | function Parser(options) {
|
6911 |
|
6912 | if (!this) {
|
6913 | return new Parser(options);
|
6914 | }
|
6915 |
|
6916 | var proxy = options && options['proxy'];
|
6917 |
|
6918 | var onText,
|
6919 | onOpenTag,
|
6920 | onCloseTag,
|
6921 | onCDATA,
|
6922 | onError = throwFunc,
|
6923 | onWarning,
|
6924 | onComment,
|
6925 | onQuestion,
|
6926 | onAttention;
|
6927 |
|
6928 | var getContext = noopGetContext;
|
6929 |
|
6930 | |
6931 |
|
6932 |
|
6933 |
|
6934 |
|
6935 | var maybeNS = false;
|
6936 |
|
6937 | |
6938 |
|
6939 |
|
6940 |
|
6941 |
|
6942 | var isNamespace = false;
|
6943 |
|
6944 | |
6945 |
|
6946 |
|
6947 |
|
6948 |
|
6949 | var returnError = null;
|
6950 |
|
6951 | |
6952 |
|
6953 |
|
6954 |
|
6955 |
|
6956 | var parseStop = false;
|
6957 |
|
6958 | |
6959 |
|
6960 |
|
6961 |
|
6962 |
|
6963 |
|
6964 |
|
6965 |
|
6966 | var nsUriToPrefix;
|
6967 |
|
6968 | |
6969 |
|
6970 |
|
6971 |
|
6972 |
|
6973 | function handleError(err) {
|
6974 | if (!(err instanceof Error)) {
|
6975 | err = error(err);
|
6976 | }
|
6977 |
|
6978 | returnError = err;
|
6979 |
|
6980 | onError(err, getContext);
|
6981 | }
|
6982 |
|
6983 | |
6984 |
|
6985 |
|
6986 |
|
6987 |
|
6988 | function handleWarning(err) {
|
6989 |
|
6990 | if (!onWarning) {
|
6991 | return;
|
6992 | }
|
6993 |
|
6994 | if (!(err instanceof Error)) {
|
6995 | err = error(err);
|
6996 | }
|
6997 |
|
6998 | onWarning(err, getContext);
|
6999 | }
|
7000 |
|
7001 | |
7002 |
|
7003 |
|
7004 |
|
7005 |
|
7006 |
|
7007 |
|
7008 |
|
7009 | this['on'] = function(name, cb) {
|
7010 |
|
7011 | if (typeof cb !== 'function') {
|
7012 | throw error('required args <name, cb>');
|
7013 | }
|
7014 |
|
7015 | switch (name) {
|
7016 | case 'openTag': onOpenTag = cb; break;
|
7017 | case 'text': onText = cb; break;
|
7018 | case 'closeTag': onCloseTag = cb; break;
|
7019 | case 'error': onError = cb; break;
|
7020 | case 'warn': onWarning = cb; break;
|
7021 | case 'cdata': onCDATA = cb; break;
|
7022 | case 'attention': onAttention = cb; break;
|
7023 | case 'question': onQuestion = cb; break;
|
7024 | case 'comment': onComment = cb; break;
|
7025 | default:
|
7026 | throw error('unsupported event: ' + name);
|
7027 | }
|
7028 |
|
7029 | return this;
|
7030 | };
|
7031 |
|
7032 | |
7033 |
|
7034 |
|
7035 |
|
7036 |
|
7037 |
|
7038 |
|
7039 |
|
7040 |
|
7041 |
|
7042 |
|
7043 |
|
7044 |
|
7045 |
|
7046 | this['ns'] = function(nsMap) {
|
7047 |
|
7048 | if (typeof nsMap === 'undefined') {
|
7049 | nsMap = {};
|
7050 | }
|
7051 |
|
7052 | if (typeof nsMap !== 'object') {
|
7053 | throw error('required args <nsMap={}>');
|
7054 | }
|
7055 |
|
7056 | var _nsUriToPrefix = {}, k;
|
7057 |
|
7058 | for (k in nsMap) {
|
7059 | _nsUriToPrefix[k] = nsMap[k];
|
7060 | }
|
7061 |
|
7062 |
|
7063 | _nsUriToPrefix[XSI_URI] = XSI_PREFIX;
|
7064 |
|
7065 | isNamespace = true;
|
7066 | nsUriToPrefix = _nsUriToPrefix;
|
7067 |
|
7068 | return this;
|
7069 | };
|
7070 |
|
7071 | |
7072 |
|
7073 |
|
7074 |
|
7075 |
|
7076 |
|
7077 |
|
7078 | this['parse'] = function(xml) {
|
7079 | if (typeof xml !== 'string') {
|
7080 | throw error('required args <xml=string>');
|
7081 | }
|
7082 |
|
7083 | returnError = null;
|
7084 |
|
7085 | parse(xml);
|
7086 |
|
7087 | getContext = noopGetContext;
|
7088 | parseStop = false;
|
7089 |
|
7090 | return returnError;
|
7091 | };
|
7092 |
|
7093 | |
7094 |
|
7095 |
|
7096 | this['stop'] = function() {
|
7097 | parseStop = true;
|
7098 | };
|
7099 |
|
7100 | |
7101 |
|
7102 |
|
7103 |
|
7104 |
|
7105 | function parse(xml) {
|
7106 | var nsMatrixStack = isNamespace ? [] : null,
|
7107 | nsMatrix = isNamespace ? buildNsMatrix(nsUriToPrefix) : null,
|
7108 | _nsMatrix,
|
7109 | nodeStack = [],
|
7110 | anonymousNsCount = 0,
|
7111 | tagStart = false,
|
7112 | tagEnd = false,
|
7113 | i = 0, j = 0,
|
7114 | x, y, q, w,
|
7115 | xmlns,
|
7116 | elementName,
|
7117 | _elementName,
|
7118 | elementProxy
|
7119 | ;
|
7120 |
|
7121 | var attrsString = '',
|
7122 | attrsStart = 0,
|
7123 | cachedAttrs
|
7124 | ;
|
7125 |
|
7126 | |
7127 |
|
7128 |
|
7129 |
|
7130 |
|
7131 |
|
7132 |
|
7133 |
|
7134 | function getAttrs() {
|
7135 | if (cachedAttrs !== null) {
|
7136 | return cachedAttrs;
|
7137 | }
|
7138 |
|
7139 | var nsUri,
|
7140 | nsUriPrefix,
|
7141 | nsName,
|
7142 | defaultAlias = isNamespace && nsMatrix['xmlns'],
|
7143 | attrList = isNamespace && maybeNS ? [] : null,
|
7144 | i = attrsStart,
|
7145 | s = attrsString,
|
7146 | l = s.length,
|
7147 | hasNewMatrix,
|
7148 | newalias,
|
7149 | value,
|
7150 | alias,
|
7151 | name,
|
7152 | attrs = {},
|
7153 | seenAttrs = {},
|
7154 | skipAttr,
|
7155 | w,
|
7156 | j;
|
7157 |
|
7158 | parseAttr:
|
7159 | for (; i < l; i++) {
|
7160 | skipAttr = false;
|
7161 | w = s.charCodeAt(i);
|
7162 |
|
7163 | if (w === 32 || (w < 14 && w > 8)) {
|
7164 | continue;
|
7165 | }
|
7166 |
|
7167 |
|
7168 | if (w < 65 || w > 122 || (w > 90 && w < 97)) {
|
7169 | if (w !== 95 && w !== 58) {
|
7170 | handleWarning('illegal first char attribute name');
|
7171 | skipAttr = true;
|
7172 | }
|
7173 | }
|
7174 |
|
7175 |
|
7176 | for (j = i + 1; j < l; j++) {
|
7177 | w = s.charCodeAt(j);
|
7178 |
|
7179 | if (
|
7180 | w > 96 && w < 123 ||
|
7181 | w > 64 && w < 91 ||
|
7182 | w > 47 && w < 59 ||
|
7183 | w === 46 ||
|
7184 | w === 45 ||
|
7185 | w === 95
|
7186 | ) {
|
7187 | continue;
|
7188 | }
|
7189 |
|
7190 |
|
7191 | if (w === 32 || (w < 14 && w > 8)) {
|
7192 | handleWarning('missing attribute value');
|
7193 | i = j;
|
7194 |
|
7195 | continue parseAttr;
|
7196 | }
|
7197 |
|
7198 |
|
7199 | if (w === 61) {
|
7200 | break;
|
7201 | }
|
7202 |
|
7203 | handleWarning('illegal attribute name char');
|
7204 | skipAttr = true;
|
7205 | }
|
7206 |
|
7207 | name = s.substring(i, j);
|
7208 |
|
7209 | if (name === 'xmlns:xmlns') {
|
7210 | handleWarning('illegal declaration of xmlns');
|
7211 | skipAttr = true;
|
7212 | }
|
7213 |
|
7214 | w = s.charCodeAt(j + 1);
|
7215 |
|
7216 | if (w === 34) {
|
7217 | j = s.indexOf('"', i = j + 2);
|
7218 |
|
7219 | if (j === -1) {
|
7220 | j = s.indexOf('\'', i);
|
7221 |
|
7222 | if (j !== -1) {
|
7223 | handleWarning('attribute value quote missmatch');
|
7224 | skipAttr = true;
|
7225 | }
|
7226 | }
|
7227 |
|
7228 | } else if (w === 39) {
|
7229 | j = s.indexOf('\'', i = j + 2);
|
7230 |
|
7231 | if (j === -1) {
|
7232 | j = s.indexOf('"', i);
|
7233 |
|
7234 | if (j !== -1) {
|
7235 | handleWarning('attribute value quote missmatch');
|
7236 | skipAttr = true;
|
7237 | }
|
7238 | }
|
7239 |
|
7240 | } else {
|
7241 | handleWarning('missing attribute value quotes');
|
7242 | skipAttr = true;
|
7243 |
|
7244 |
|
7245 | for (j = j + 1; j < l; j++) {
|
7246 | w = s.charCodeAt(j + 1);
|
7247 |
|
7248 | if (w === 32 || (w < 14 && w > 8)) {
|
7249 | break;
|
7250 | }
|
7251 | }
|
7252 |
|
7253 | }
|
7254 |
|
7255 | if (j === -1) {
|
7256 | handleWarning('missing closing quotes');
|
7257 |
|
7258 | j = l;
|
7259 | skipAttr = true;
|
7260 | }
|
7261 |
|
7262 | if (!skipAttr) {
|
7263 | value = s.substring(i, j);
|
7264 | }
|
7265 |
|
7266 | i = j;
|
7267 |
|
7268 |
|
7269 |
|
7270 |
|
7271 | for (; j + 1 < l; j++) {
|
7272 | w = s.charCodeAt(j + 1);
|
7273 |
|
7274 | if (w === 32 || (w < 14 && w > 8)) {
|
7275 | break;
|
7276 | }
|
7277 |
|
7278 |
|
7279 | if (i === j) {
|
7280 | handleWarning('illegal character after attribute end');
|
7281 | skipAttr = true;
|
7282 | }
|
7283 | }
|
7284 |
|
7285 |
|
7286 | i = j + 1;
|
7287 |
|
7288 | if (skipAttr) {
|
7289 | continue parseAttr;
|
7290 | }
|
7291 |
|
7292 |
|
7293 | if (name in seenAttrs) {
|
7294 | handleWarning('attribute <' + name + '> already defined');
|
7295 | continue;
|
7296 | }
|
7297 |
|
7298 | seenAttrs[name] = true;
|
7299 |
|
7300 | if (!isNamespace) {
|
7301 | attrs[name] = value;
|
7302 | continue;
|
7303 | }
|
7304 |
|
7305 |
|
7306 | if (maybeNS) {
|
7307 | newalias = (
|
7308 | name === 'xmlns'
|
7309 | ? 'xmlns'
|
7310 | : (name.charCodeAt(0) === 120 && name.substr(0, 6) === 'xmlns:')
|
7311 | ? name.substr(6)
|
7312 | : null
|
7313 | );
|
7314 |
|
7315 |
|
7316 | if (newalias !== null) {
|
7317 | nsUri = decodeEntities(value);
|
7318 | nsUriPrefix = uriPrefix(newalias);
|
7319 |
|
7320 | alias = nsUriToPrefix[nsUri];
|
7321 |
|
7322 | if (!alias) {
|
7323 |
|
7324 | if (
|
7325 | (newalias === 'xmlns') ||
|
7326 | (nsUriPrefix in nsMatrix && nsMatrix[nsUriPrefix] !== nsUri)
|
7327 | ) {
|
7328 |
|
7329 | do {
|
7330 | alias = 'ns' + (anonymousNsCount++);
|
7331 | } while (typeof nsMatrix[alias] !== 'undefined');
|
7332 | } else {
|
7333 | alias = newalias;
|
7334 | }
|
7335 |
|
7336 | nsUriToPrefix[nsUri] = alias;
|
7337 | }
|
7338 |
|
7339 | if (nsMatrix[newalias] !== alias) {
|
7340 | if (!hasNewMatrix) {
|
7341 | nsMatrix = cloneNsMatrix(nsMatrix);
|
7342 | hasNewMatrix = true;
|
7343 | }
|
7344 |
|
7345 | nsMatrix[newalias] = alias;
|
7346 | if (newalias === 'xmlns') {
|
7347 | nsMatrix[uriPrefix(alias)] = nsUri;
|
7348 | defaultAlias = alias;
|
7349 | }
|
7350 |
|
7351 | nsMatrix[nsUriPrefix] = nsUri;
|
7352 | }
|
7353 |
|
7354 |
|
7355 | attrs[name] = value;
|
7356 | continue;
|
7357 | }
|
7358 |
|
7359 |
|
7360 |
|
7361 | attrList.push(name, value);
|
7362 | continue;
|
7363 |
|
7364 | }
|
7365 |
|
7366 |
|
7367 |
|
7368 | w = name.indexOf(':');
|
7369 | if (w === -1) {
|
7370 | attrs[name] = value;
|
7371 | continue;
|
7372 | }
|
7373 |
|
7374 |
|
7375 | if (!(nsName = nsMatrix[name.substring(0, w)])) {
|
7376 | handleWarning(missingNamespaceForPrefix(name.substring(0, w)));
|
7377 | continue;
|
7378 | }
|
7379 |
|
7380 | name = defaultAlias === nsName
|
7381 | ? name.substr(w + 1)
|
7382 | : nsName + name.substr(w);
|
7383 |
|
7384 |
|
7385 |
|
7386 | if (name === XSI_TYPE) {
|
7387 | w = value.indexOf(':');
|
7388 |
|
7389 | if (w !== -1) {
|
7390 | nsName = value.substring(0, w);
|
7391 |
|
7392 | nsName = nsMatrix[nsName] || nsName;
|
7393 | value = nsName + value.substring(w);
|
7394 | } else {
|
7395 | value = defaultAlias + ':' + value;
|
7396 | }
|
7397 | }
|
7398 |
|
7399 |
|
7400 | attrs[name] = value;
|
7401 | }
|
7402 |
|
7403 |
|
7404 |
|
7405 | if (maybeNS) {
|
7406 |
|
7407 |
|
7408 | for (i = 0, l = attrList.length; i < l; i++) {
|
7409 |
|
7410 | name = attrList[i++];
|
7411 | value = attrList[i];
|
7412 |
|
7413 | w = name.indexOf(':');
|
7414 |
|
7415 | if (w !== -1) {
|
7416 |
|
7417 | if (!(nsName = nsMatrix[name.substring(0, w)])) {
|
7418 | handleWarning(missingNamespaceForPrefix(name.substring(0, w)));
|
7419 | continue;
|
7420 | }
|
7421 |
|
7422 | name = defaultAlias === nsName
|
7423 | ? name.substr(w + 1)
|
7424 | : nsName + name.substr(w);
|
7425 |
|
7426 |
|
7427 |
|
7428 | if (name === XSI_TYPE) {
|
7429 | w = value.indexOf(':');
|
7430 |
|
7431 | if (w !== -1) {
|
7432 | nsName = value.substring(0, w);
|
7433 |
|
7434 | nsName = nsMatrix[nsName] || nsName;
|
7435 | value = nsName + value.substring(w);
|
7436 | } else {
|
7437 | value = defaultAlias + ':' + value;
|
7438 | }
|
7439 | }
|
7440 |
|
7441 | }
|
7442 |
|
7443 | attrs[name] = value;
|
7444 | }
|
7445 |
|
7446 | }
|
7447 |
|
7448 | return cachedAttrs = attrs;
|
7449 | }
|
7450 |
|
7451 | |
7452 |
|
7453 |
|
7454 |
|
7455 |
|
7456 |
|
7457 | function getParseContext() {
|
7458 | var splitsRe = /(\r\n|\r|\n)/g;
|
7459 |
|
7460 | var line = 0;
|
7461 | var column = 0;
|
7462 | var startOfLine = 0;
|
7463 | var endOfLine = j;
|
7464 | var match;
|
7465 | var data;
|
7466 |
|
7467 | while (i >= startOfLine) {
|
7468 |
|
7469 | match = splitsRe.exec(xml);
|
7470 |
|
7471 | if (!match) {
|
7472 | break;
|
7473 | }
|
7474 |
|
7475 |
|
7476 | endOfLine = match[0].length + match.index;
|
7477 |
|
7478 | if (endOfLine > i) {
|
7479 | break;
|
7480 | }
|
7481 |
|
7482 |
|
7483 | line += 1;
|
7484 |
|
7485 | startOfLine = endOfLine;
|
7486 | }
|
7487 |
|
7488 |
|
7489 | if (i == -1) {
|
7490 | column = endOfLine;
|
7491 | data = xml.substring(j);
|
7492 | } else
|
7493 |
|
7494 | if (j === 0) {
|
7495 | console.log(i - startOfLine);
|
7496 | data = xml.substring(j, i);
|
7497 | }
|
7498 |
|
7499 | else {
|
7500 | column = i - startOfLine;
|
7501 | data = (j == -1 ? xml.substring(i) : xml.substring(i, j + 1));
|
7502 | }
|
7503 |
|
7504 | return {
|
7505 | 'data': data,
|
7506 | 'line': line,
|
7507 | 'column': column
|
7508 | };
|
7509 | }
|
7510 |
|
7511 | getContext = getParseContext;
|
7512 |
|
7513 |
|
7514 | if (proxy) {
|
7515 | elementProxy = Object.create({}, {
|
7516 | 'name': getter(function() {
|
7517 | return elementName;
|
7518 | }),
|
7519 | 'originalName': getter(function() {
|
7520 | return _elementName;
|
7521 | }),
|
7522 | 'attrs': getter(getAttrs),
|
7523 | 'ns': getter(function() {
|
7524 | return nsMatrix;
|
7525 | })
|
7526 | });
|
7527 | }
|
7528 |
|
7529 |
|
7530 | while (j !== -1) {
|
7531 |
|
7532 | if (xml.charCodeAt(j) === 60) {
|
7533 | i = j;
|
7534 | } else {
|
7535 | i = xml.indexOf('<', j);
|
7536 | }
|
7537 |
|
7538 |
|
7539 | if (i === -1) {
|
7540 | if (nodeStack.length) {
|
7541 | return handleError('unexpected end of file');
|
7542 | }
|
7543 |
|
7544 | if (j === 0) {
|
7545 | return handleError('missing start tag');
|
7546 | }
|
7547 |
|
7548 | if (j < xml.length) {
|
7549 | if (xml.substring(j).trim()) {
|
7550 | handleWarning(NON_WHITESPACE_OUTSIDE_ROOT_NODE);
|
7551 | }
|
7552 | }
|
7553 |
|
7554 | return;
|
7555 | }
|
7556 |
|
7557 |
|
7558 | if (j !== i) {
|
7559 |
|
7560 | if (nodeStack.length) {
|
7561 | if (onText) {
|
7562 | onText(xml.substring(j, i), decodeEntities, getContext);
|
7563 |
|
7564 | if (parseStop) {
|
7565 | return;
|
7566 | }
|
7567 | }
|
7568 | } else {
|
7569 | if (xml.substring(j, i).trim()) {
|
7570 | handleWarning(NON_WHITESPACE_OUTSIDE_ROOT_NODE);
|
7571 |
|
7572 | if (parseStop) {
|
7573 | return;
|
7574 | }
|
7575 | }
|
7576 | }
|
7577 | }
|
7578 |
|
7579 | w = xml.charCodeAt(i+1);
|
7580 |
|
7581 |
|
7582 | if (w === 33) {
|
7583 | w = xml.charCodeAt(i+2);
|
7584 | if (w === 91 && xml.substr(i + 3, 6) === 'CDATA[') {
|
7585 | j = xml.indexOf(']]>', i);
|
7586 | if (j === -1) {
|
7587 | return handleError('unclosed cdata');
|
7588 | }
|
7589 |
|
7590 | if (onCDATA) {
|
7591 | onCDATA(xml.substring(i + 9, j), getContext);
|
7592 | if (parseStop) {
|
7593 | return;
|
7594 | }
|
7595 | }
|
7596 |
|
7597 | j += 3;
|
7598 | continue;
|
7599 | }
|
7600 |
|
7601 |
|
7602 | if (w === 45 && xml.charCodeAt(i + 3) === 45) {
|
7603 | j = xml.indexOf('-->', i);
|
7604 | if (j === -1) {
|
7605 | return handleError('unclosed comment');
|
7606 | }
|
7607 |
|
7608 |
|
7609 | if (onComment) {
|
7610 | onComment(xml.substring(i + 4, j), decodeEntities, getContext);
|
7611 | if (parseStop) {
|
7612 | return;
|
7613 | }
|
7614 | }
|
7615 |
|
7616 | j += 3;
|
7617 | continue;
|
7618 | }
|
7619 |
|
7620 | j = xml.indexOf('>', i + 1);
|
7621 | if (j === -1) {
|
7622 | return handleError('unclosed tag');
|
7623 | }
|
7624 |
|
7625 | if (onAttention) {
|
7626 | onAttention(xml.substring(i, j + 1), decodeEntities, getContext);
|
7627 | if (parseStop) {
|
7628 | return;
|
7629 | }
|
7630 | }
|
7631 |
|
7632 | j += 1;
|
7633 | continue;
|
7634 | }
|
7635 |
|
7636 | if (w === 63) {
|
7637 | j = xml.indexOf('?>', i);
|
7638 | if (j === -1) {
|
7639 | return handleError('unclosed question');
|
7640 | }
|
7641 |
|
7642 | if (onQuestion) {
|
7643 | onQuestion(xml.substring(i, j + 2), getContext);
|
7644 | if (parseStop) {
|
7645 | return;
|
7646 | }
|
7647 | }
|
7648 |
|
7649 | j += 2;
|
7650 | continue;
|
7651 | }
|
7652 |
|
7653 | j = xml.indexOf('>', i + 1);
|
7654 |
|
7655 | if (j == -1) {
|
7656 | return handleError('unclosed tag');
|
7657 | }
|
7658 |
|
7659 |
|
7660 |
|
7661 | cachedAttrs = {};
|
7662 |
|
7663 |
|
7664 | if (w === 47) {
|
7665 | tagStart = false;
|
7666 | tagEnd = true;
|
7667 |
|
7668 | if (!nodeStack.length) {
|
7669 | return handleError('missing open tag');
|
7670 | }
|
7671 |
|
7672 |
|
7673 | x = elementName = nodeStack.pop();
|
7674 | q = i + 2 + x.length;
|
7675 |
|
7676 | if (xml.substring(i + 2, q) !== x) {
|
7677 | return handleError('closing tag mismatch');
|
7678 | }
|
7679 |
|
7680 |
|
7681 | for (; q < j; q++) {
|
7682 | w = xml.charCodeAt(q);
|
7683 |
|
7684 | if (w === 32 || (w > 8 && w < 14)) {
|
7685 | continue;
|
7686 | }
|
7687 |
|
7688 | return handleError('close tag');
|
7689 | }
|
7690 |
|
7691 | } else {
|
7692 | if (xml.charCodeAt(j - 1) === 47) {
|
7693 | x = elementName = xml.substring(i + 1, j - 1);
|
7694 |
|
7695 | tagStart = true;
|
7696 | tagEnd = true;
|
7697 |
|
7698 | } else {
|
7699 | x = elementName = xml.substring(i + 1, j);
|
7700 |
|
7701 | tagStart = true;
|
7702 | tagEnd = false;
|
7703 | }
|
7704 |
|
7705 | if (!(w > 96 && w < 123 || w > 64 && w < 91 || w === 95 || w === 58)) {
|
7706 | return handleError('illegal first char nodeName');
|
7707 | }
|
7708 |
|
7709 | for (q = 1, y = x.length; q < y; q++) {
|
7710 | w = x.charCodeAt(q);
|
7711 |
|
7712 | if (w > 96 && w < 123 || w > 64 && w < 91 || w > 47 && w < 59 || w === 45 || w === 95 || w == 46) {
|
7713 | continue;
|
7714 | }
|
7715 |
|
7716 | if (w === 32 || (w < 14 && w > 8)) {
|
7717 | elementName = x.substring(0, q);
|
7718 |
|
7719 | cachedAttrs = null;
|
7720 | break;
|
7721 | }
|
7722 |
|
7723 | return handleError('invalid nodeName');
|
7724 | }
|
7725 |
|
7726 | if (!tagEnd) {
|
7727 | nodeStack.push(elementName);
|
7728 | }
|
7729 | }
|
7730 |
|
7731 | if (isNamespace) {
|
7732 |
|
7733 | _nsMatrix = nsMatrix;
|
7734 |
|
7735 | if (tagStart) {
|
7736 |
|
7737 |
|
7738 | if (!tagEnd) {
|
7739 | nsMatrixStack.push(_nsMatrix);
|
7740 | }
|
7741 |
|
7742 | if (cachedAttrs === null) {
|
7743 |
|
7744 |
|
7745 |
|
7746 | if ((maybeNS = x.indexOf('xmlns', q) !== -1)) {
|
7747 | attrsStart = q;
|
7748 | attrsString = x;
|
7749 |
|
7750 | getAttrs();
|
7751 |
|
7752 | maybeNS = false;
|
7753 | }
|
7754 | }
|
7755 | }
|
7756 |
|
7757 | _elementName = elementName;
|
7758 |
|
7759 | w = elementName.indexOf(':');
|
7760 | if (w !== -1) {
|
7761 | xmlns = nsMatrix[elementName.substring(0, w)];
|
7762 |
|
7763 |
|
7764 | if (!xmlns) {
|
7765 | return handleError('missing namespace on <' + _elementName + '>');
|
7766 | }
|
7767 |
|
7768 | elementName = elementName.substr(w + 1);
|
7769 | } else {
|
7770 | xmlns = nsMatrix['xmlns'];
|
7771 |
|
7772 |
|
7773 |
|
7774 |
|
7775 |
|
7776 |
|
7777 |
|
7778 | }
|
7779 |
|
7780 |
|
7781 | if (xmlns) {
|
7782 | elementName = xmlns + ':' + elementName;
|
7783 | }
|
7784 |
|
7785 | }
|
7786 |
|
7787 | if (tagStart) {
|
7788 | attrsStart = q;
|
7789 | attrsString = x;
|
7790 |
|
7791 | if (onOpenTag) {
|
7792 | if (proxy) {
|
7793 | onOpenTag(elementProxy, decodeEntities, tagEnd, getContext);
|
7794 | } else {
|
7795 | onOpenTag(elementName, getAttrs, decodeEntities, tagEnd, getContext);
|
7796 | }
|
7797 |
|
7798 | if (parseStop) {
|
7799 | return;
|
7800 | }
|
7801 | }
|
7802 |
|
7803 | }
|
7804 |
|
7805 | if (tagEnd) {
|
7806 |
|
7807 | if (onCloseTag) {
|
7808 | onCloseTag(proxy ? elementProxy : elementName, decodeEntities, tagStart, getContext);
|
7809 |
|
7810 | if (parseStop) {
|
7811 | return;
|
7812 | }
|
7813 | }
|
7814 |
|
7815 |
|
7816 | if (isNamespace) {
|
7817 | if (!tagStart) {
|
7818 | nsMatrix = nsMatrixStack.pop();
|
7819 | } else {
|
7820 | nsMatrix = _nsMatrix;
|
7821 | }
|
7822 | }
|
7823 | }
|
7824 |
|
7825 | j += 1;
|
7826 | }
|
7827 | }
|
7828 |
|
7829 | }
|
7830 |
|
7831 | function hasLowerCaseAlias(pkg) {
|
7832 | return pkg.xml && pkg.xml.tagAlias === 'lowerCase';
|
7833 | }
|
7834 |
|
7835 | var DEFAULT_NS_MAP = {
|
7836 | 'xsi': 'http://www.w3.org/2001/XMLSchema-instance'
|
7837 | };
|
7838 |
|
7839 | var XSI_TYPE$1 = 'xsi:type';
|
7840 |
|
7841 | function serializeFormat(element) {
|
7842 | return element.xml && element.xml.serialize;
|
7843 | }
|
7844 |
|
7845 | function serializeAsType(element) {
|
7846 | return serializeFormat(element) === XSI_TYPE$1;
|
7847 | }
|
7848 |
|
7849 | function serializeAsProperty(element) {
|
7850 | return serializeFormat(element) === 'property';
|
7851 | }
|
7852 |
|
7853 | function capitalize(str) {
|
7854 | return str.charAt(0).toUpperCase() + str.slice(1);
|
7855 | }
|
7856 |
|
7857 | function aliasToName(aliasNs, pkg) {
|
7858 |
|
7859 | if (!hasLowerCaseAlias(pkg)) {
|
7860 | return aliasNs.name;
|
7861 | }
|
7862 |
|
7863 | return aliasNs.prefix + ':' + capitalize(aliasNs.localName);
|
7864 | }
|
7865 |
|
7866 | function prefixedToName(nameNs, pkg) {
|
7867 |
|
7868 | var name = nameNs.name,
|
7869 | localName = nameNs.localName;
|
7870 |
|
7871 | var typePrefix = pkg.xml && pkg.xml.typePrefix;
|
7872 |
|
7873 | if (typePrefix && localName.indexOf(typePrefix) === 0) {
|
7874 | return nameNs.prefix + ':' + localName.slice(typePrefix.length);
|
7875 | } else {
|
7876 | return name;
|
7877 | }
|
7878 | }
|
7879 |
|
7880 | function normalizeXsiTypeName(name, model) {
|
7881 |
|
7882 | var nameNs = parseName(name);
|
7883 | var pkg = model.getPackage(nameNs.prefix);
|
7884 |
|
7885 | return prefixedToName(nameNs, pkg);
|
7886 | }
|
7887 |
|
7888 | function error$1(message) {
|
7889 | return new Error(message);
|
7890 | }
|
7891 |
|
7892 | |
7893 |
|
7894 |
|
7895 |
|
7896 |
|
7897 |
|
7898 |
|
7899 | function getModdleDescriptor(element) {
|
7900 | return element.$descriptor;
|
7901 | }
|
7902 |
|
7903 | function defer(fn) {
|
7904 | setTimeout(fn, 0);
|
7905 | }
|
7906 |
|
7907 | |
7908 |
|
7909 |
|
7910 |
|
7911 |
|
7912 |
|
7913 |
|
7914 |
|
7915 |
|
7916 | function Context(options) {
|
7917 |
|
7918 | |
7919 |
|
7920 |
|
7921 |
|
7922 | |
7923 |
|
7924 |
|
7925 |
|
7926 | assign(this, options);
|
7927 |
|
7928 | this.elementsById = {};
|
7929 | this.references = [];
|
7930 | this.warnings = [];
|
7931 |
|
7932 | |
7933 |
|
7934 |
|
7935 |
|
7936 |
|
7937 | this.addReference = function(reference) {
|
7938 | this.references.push(reference);
|
7939 | };
|
7940 |
|
7941 | |
7942 |
|
7943 |
|
7944 |
|
7945 |
|
7946 | this.addElement = function(element) {
|
7947 |
|
7948 | if (!element) {
|
7949 | throw error$1('expected element');
|
7950 | }
|
7951 |
|
7952 | var elementsById = this.elementsById;
|
7953 |
|
7954 | var descriptor = getModdleDescriptor(element);
|
7955 |
|
7956 | var idProperty = descriptor.idProperty,
|
7957 | id;
|
7958 |
|
7959 | if (idProperty) {
|
7960 | id = element.get(idProperty.name);
|
7961 |
|
7962 | if (id) {
|
7963 |
|
7964 | if (!/^([a-z][\w-.]*:)?[a-z_][\w-.]*$/i.test(id)) {
|
7965 | throw new Error('illegal ID <' + id + '>');
|
7966 | }
|
7967 |
|
7968 | if (elementsById[id]) {
|
7969 | throw error$1('duplicate ID <' + id + '>');
|
7970 | }
|
7971 |
|
7972 | elementsById[id] = element;
|
7973 | }
|
7974 | }
|
7975 | };
|
7976 |
|
7977 | |
7978 |
|
7979 |
|
7980 |
|
7981 |
|
7982 |
|
7983 |
|
7984 | this.addWarning = function(warning) {
|
7985 | this.warnings.push(warning);
|
7986 | };
|
7987 | }
|
7988 |
|
7989 | function BaseHandler() {}
|
7990 |
|
7991 | BaseHandler.prototype.handleEnd = function() {};
|
7992 | BaseHandler.prototype.handleText = function() {};
|
7993 | BaseHandler.prototype.handleNode = function() {};
|
7994 |
|
7995 |
|
7996 | |
7997 |
|
7998 |
|
7999 |
|
8000 |
|
8001 |
|
8002 |
|
8003 | function NoopHandler() { }
|
8004 |
|
8005 | NoopHandler.prototype = Object.create(BaseHandler.prototype);
|
8006 |
|
8007 | NoopHandler.prototype.handleNode = function() {
|
8008 | return this;
|
8009 | };
|
8010 |
|
8011 | function BodyHandler() {}
|
8012 |
|
8013 | BodyHandler.prototype = Object.create(BaseHandler.prototype);
|
8014 |
|
8015 | BodyHandler.prototype.handleText = function(text) {
|
8016 | this.body = (this.body || '') + text;
|
8017 | };
|
8018 |
|
8019 | function ReferenceHandler(property, context) {
|
8020 | this.property = property;
|
8021 | this.context = context;
|
8022 | }
|
8023 |
|
8024 | ReferenceHandler.prototype = Object.create(BodyHandler.prototype);
|
8025 |
|
8026 | ReferenceHandler.prototype.handleNode = function(node) {
|
8027 |
|
8028 | if (this.element) {
|
8029 | throw error$1('expected no sub nodes');
|
8030 | } else {
|
8031 | this.element = this.createReference(node);
|
8032 | }
|
8033 |
|
8034 | return this;
|
8035 | };
|
8036 |
|
8037 | ReferenceHandler.prototype.handleEnd = function() {
|
8038 | this.element.id = this.body;
|
8039 | };
|
8040 |
|
8041 | ReferenceHandler.prototype.createReference = function(node) {
|
8042 | return {
|
8043 | property: this.property.ns.name,
|
8044 | id: ''
|
8045 | };
|
8046 | };
|
8047 |
|
8048 | function ValueHandler(propertyDesc, element) {
|
8049 | this.element = element;
|
8050 | this.propertyDesc = propertyDesc;
|
8051 | }
|
8052 |
|
8053 | ValueHandler.prototype = Object.create(BodyHandler.prototype);
|
8054 |
|
8055 | ValueHandler.prototype.handleEnd = function() {
|
8056 |
|
8057 | var value = this.body || '',
|
8058 | element = this.element,
|
8059 | propertyDesc = this.propertyDesc;
|
8060 |
|
8061 | value = coerceType(propertyDesc.type, value);
|
8062 |
|
8063 | if (propertyDesc.isMany) {
|
8064 | element.get(propertyDesc.name).push(value);
|
8065 | } else {
|
8066 | element.set(propertyDesc.name, value);
|
8067 | }
|
8068 | };
|
8069 |
|
8070 |
|
8071 | function BaseElementHandler() {}
|
8072 |
|
8073 | BaseElementHandler.prototype = Object.create(BodyHandler.prototype);
|
8074 |
|
8075 | BaseElementHandler.prototype.handleNode = function(node) {
|
8076 | var parser = this,
|
8077 | element = this.element;
|
8078 |
|
8079 | if (!element) {
|
8080 | element = this.element = this.createElement(node);
|
8081 |
|
8082 | this.context.addElement(element);
|
8083 | } else {
|
8084 | parser = this.handleChild(node);
|
8085 | }
|
8086 |
|
8087 | return parser;
|
8088 | };
|
8089 |
|
8090 | |
8091 |
|
8092 |
|
8093 |
|
8094 | function ElementHandler(model, typeName, context) {
|
8095 | this.model = model;
|
8096 | this.type = model.getType(typeName);
|
8097 | this.context = context;
|
8098 | }
|
8099 |
|
8100 | ElementHandler.prototype = Object.create(BaseElementHandler.prototype);
|
8101 |
|
8102 | ElementHandler.prototype.addReference = function(reference) {
|
8103 | this.context.addReference(reference);
|
8104 | };
|
8105 |
|
8106 | ElementHandler.prototype.handleText = function(text) {
|
8107 |
|
8108 | var element = this.element,
|
8109 | descriptor = getModdleDescriptor(element),
|
8110 | bodyProperty = descriptor.bodyProperty;
|
8111 |
|
8112 | if (!bodyProperty) {
|
8113 | throw error$1('unexpected body text <' + text + '>');
|
8114 | }
|
8115 |
|
8116 | BodyHandler.prototype.handleText.call(this, text);
|
8117 | };
|
8118 |
|
8119 | ElementHandler.prototype.handleEnd = function() {
|
8120 |
|
8121 | var value = this.body,
|
8122 | element = this.element,
|
8123 | descriptor = getModdleDescriptor(element),
|
8124 | bodyProperty = descriptor.bodyProperty;
|
8125 |
|
8126 | if (bodyProperty && value !== undefined) {
|
8127 | value = coerceType(bodyProperty.type, value);
|
8128 | element.set(bodyProperty.name, value);
|
8129 | }
|
8130 | };
|
8131 |
|
8132 | |
8133 |
|
8134 |
|
8135 |
|
8136 |
|
8137 | ElementHandler.prototype.createElement = function(node) {
|
8138 | var attributes = node.attributes,
|
8139 | Type = this.type,
|
8140 | descriptor = getModdleDescriptor(Type),
|
8141 | context = this.context,
|
8142 | instance = new Type({}),
|
8143 | model = this.model,
|
8144 | propNameNs;
|
8145 |
|
8146 | forEach(attributes, function(value, name) {
|
8147 |
|
8148 | var prop = descriptor.propertiesByName[name],
|
8149 | values;
|
8150 |
|
8151 | if (prop && prop.isReference) {
|
8152 |
|
8153 | if (!prop.isMany) {
|
8154 | context.addReference({
|
8155 | element: instance,
|
8156 | property: prop.ns.name,
|
8157 | id: value
|
8158 | });
|
8159 | } else {
|
8160 |
|
8161 | values = value.split(' ');
|
8162 |
|
8163 | forEach(values, function(v) {
|
8164 | context.addReference({
|
8165 | element: instance,
|
8166 | property: prop.ns.name,
|
8167 | id: v
|
8168 | });
|
8169 | });
|
8170 | }
|
8171 |
|
8172 | } else {
|
8173 | if (prop) {
|
8174 | value = coerceType(prop.type, value);
|
8175 | } else
|
8176 | if (name !== 'xmlns') {
|
8177 | propNameNs = parseName(name, descriptor.ns.prefix);
|
8178 |
|
8179 |
|
8180 |
|
8181 | if (model.getPackage(propNameNs.prefix)) {
|
8182 |
|
8183 | context.addWarning({
|
8184 | message: 'unknown attribute <' + name + '>',
|
8185 | element: instance,
|
8186 | property: name,
|
8187 | value: value
|
8188 | });
|
8189 | }
|
8190 | }
|
8191 |
|
8192 | instance.set(name, value);
|
8193 | }
|
8194 | });
|
8195 |
|
8196 | return instance;
|
8197 | };
|
8198 |
|
8199 | ElementHandler.prototype.getPropertyForNode = function(node) {
|
8200 |
|
8201 | var name = node.name;
|
8202 | var nameNs = parseName(name);
|
8203 |
|
8204 | var type = this.type,
|
8205 | model = this.model,
|
8206 | descriptor = getModdleDescriptor(type);
|
8207 |
|
8208 | var propertyName = nameNs.name,
|
8209 | property = descriptor.propertiesByName[propertyName],
|
8210 | elementTypeName,
|
8211 | elementType;
|
8212 |
|
8213 |
|
8214 |
|
8215 | if (property) {
|
8216 |
|
8217 | if (serializeAsType(property)) {
|
8218 | elementTypeName = node.attributes[XSI_TYPE$1];
|
8219 |
|
8220 |
|
8221 |
|
8222 | if (elementTypeName) {
|
8223 |
|
8224 |
|
8225 |
|
8226 | elementTypeName = normalizeXsiTypeName(elementTypeName, model);
|
8227 |
|
8228 | elementType = model.getType(elementTypeName);
|
8229 |
|
8230 | return assign({}, property, {
|
8231 | effectiveType: getModdleDescriptor(elementType).name
|
8232 | });
|
8233 | }
|
8234 | }
|
8235 |
|
8236 |
|
8237 | return property;
|
8238 | }
|
8239 |
|
8240 | var pkg = model.getPackage(nameNs.prefix);
|
8241 |
|
8242 | if (pkg) {
|
8243 | elementTypeName = aliasToName(nameNs, pkg);
|
8244 | elementType = model.getType(elementTypeName);
|
8245 |
|
8246 |
|
8247 | property = find(descriptor.properties, function(p) {
|
8248 | return !p.isVirtual && !p.isReference && !p.isAttribute && elementType.hasType(p.type);
|
8249 | });
|
8250 |
|
8251 | if (property) {
|
8252 | return assign({}, property, {
|
8253 | effectiveType: getModdleDescriptor(elementType).name
|
8254 | });
|
8255 | }
|
8256 | } else {
|
8257 |
|
8258 | property = find(descriptor.properties, function(p) {
|
8259 | return !p.isReference && !p.isAttribute && p.type === 'Element';
|
8260 | });
|
8261 |
|
8262 | if (property) {
|
8263 | return property;
|
8264 | }
|
8265 | }
|
8266 |
|
8267 | throw error$1('unrecognized element <' + nameNs.name + '>');
|
8268 | };
|
8269 |
|
8270 | ElementHandler.prototype.toString = function() {
|
8271 | return 'ElementDescriptor[' + getModdleDescriptor(this.type).name + ']';
|
8272 | };
|
8273 |
|
8274 | ElementHandler.prototype.valueHandler = function(propertyDesc, element) {
|
8275 | return new ValueHandler(propertyDesc, element);
|
8276 | };
|
8277 |
|
8278 | ElementHandler.prototype.referenceHandler = function(propertyDesc) {
|
8279 | return new ReferenceHandler(propertyDesc, this.context);
|
8280 | };
|
8281 |
|
8282 | ElementHandler.prototype.handler = function(type) {
|
8283 | if (type === 'Element') {
|
8284 | return new GenericElementHandler(this.model, type, this.context);
|
8285 | } else {
|
8286 | return new ElementHandler(this.model, type, this.context);
|
8287 | }
|
8288 | };
|
8289 |
|
8290 | |
8291 |
|
8292 |
|
8293 |
|
8294 |
|
8295 | ElementHandler.prototype.handleChild = function(node) {
|
8296 | var propertyDesc, type, element, childHandler;
|
8297 |
|
8298 | propertyDesc = this.getPropertyForNode(node);
|
8299 | element = this.element;
|
8300 |
|
8301 | type = propertyDesc.effectiveType || propertyDesc.type;
|
8302 |
|
8303 | if (isSimple(type)) {
|
8304 | return this.valueHandler(propertyDesc, element);
|
8305 | }
|
8306 |
|
8307 | if (propertyDesc.isReference) {
|
8308 | childHandler = this.referenceHandler(propertyDesc).handleNode(node);
|
8309 | } else {
|
8310 | childHandler = this.handler(type).handleNode(node);
|
8311 | }
|
8312 |
|
8313 | var newElement = childHandler.element;
|
8314 |
|
8315 |
|
8316 |
|
8317 | if (newElement !== undefined) {
|
8318 |
|
8319 | if (propertyDesc.isMany) {
|
8320 | element.get(propertyDesc.name).push(newElement);
|
8321 | } else {
|
8322 | element.set(propertyDesc.name, newElement);
|
8323 | }
|
8324 |
|
8325 | if (propertyDesc.isReference) {
|
8326 | assign(newElement, {
|
8327 | element: element
|
8328 | });
|
8329 |
|
8330 | this.context.addReference(newElement);
|
8331 | } else {
|
8332 |
|
8333 | newElement.$parent = element;
|
8334 | }
|
8335 | }
|
8336 |
|
8337 | return childHandler;
|
8338 | };
|
8339 |
|
8340 | |
8341 |
|
8342 |
|
8343 |
|
8344 |
|
8345 |
|
8346 |
|
8347 |
|
8348 |
|
8349 | function RootElementHandler(model, typeName, context) {
|
8350 | ElementHandler.call(this, model, typeName, context);
|
8351 | }
|
8352 |
|
8353 | RootElementHandler.prototype = Object.create(ElementHandler.prototype);
|
8354 |
|
8355 | RootElementHandler.prototype.createElement = function(node) {
|
8356 |
|
8357 | var name = node.name,
|
8358 | nameNs = parseName(name),
|
8359 | model = this.model,
|
8360 | type = this.type,
|
8361 | pkg = model.getPackage(nameNs.prefix),
|
8362 | typeName = pkg && aliasToName(nameNs, pkg) || name;
|
8363 |
|
8364 |
|
8365 |
|
8366 |
|
8367 |
|
8368 | if (!type.hasType(typeName)) {
|
8369 | throw error$1('unexpected element <' + node.originalName + '>');
|
8370 | }
|
8371 |
|
8372 | return ElementHandler.prototype.createElement.call(this, node);
|
8373 | };
|
8374 |
|
8375 |
|
8376 | function GenericElementHandler(model, typeName, context) {
|
8377 | this.model = model;
|
8378 | this.context = context;
|
8379 | }
|
8380 |
|
8381 | GenericElementHandler.prototype = Object.create(BaseElementHandler.prototype);
|
8382 |
|
8383 | GenericElementHandler.prototype.createElement = function(node) {
|
8384 |
|
8385 | var name = node.name,
|
8386 | ns = parseName(name),
|
8387 | prefix = ns.prefix,
|
8388 | uri = node.ns[prefix + '$uri'],
|
8389 | attributes = node.attributes;
|
8390 |
|
8391 | return this.model.createAny(name, uri, attributes);
|
8392 | };
|
8393 |
|
8394 | GenericElementHandler.prototype.handleChild = function(node) {
|
8395 |
|
8396 | var handler = new GenericElementHandler(this.model, 'Element', this.context).handleNode(node),
|
8397 | element = this.element;
|
8398 |
|
8399 | var newElement = handler.element,
|
8400 | children;
|
8401 |
|
8402 | if (newElement !== undefined) {
|
8403 | children = element.$children = element.$children || [];
|
8404 | children.push(newElement);
|
8405 |
|
8406 |
|
8407 | newElement.$parent = element;
|
8408 | }
|
8409 |
|
8410 | return handler;
|
8411 | };
|
8412 |
|
8413 | GenericElementHandler.prototype.handleEnd = function() {
|
8414 | if (this.body) {
|
8415 | this.element.$body = this.body;
|
8416 | }
|
8417 | };
|
8418 |
|
8419 | |
8420 |
|
8421 |
|
8422 |
|
8423 |
|
8424 |
|
8425 |
|
8426 | function Reader(options) {
|
8427 |
|
8428 | if (options instanceof Moddle) {
|
8429 | options = {
|
8430 | model: options
|
8431 | };
|
8432 | }
|
8433 |
|
8434 | assign(this, { lax: false }, options);
|
8435 | }
|
8436 |
|
8437 |
|
8438 | |
8439 |
|
8440 |
|
8441 |
|
8442 |
|
8443 |
|
8444 |
|
8445 | Reader.prototype.fromXML = function(xml, options, done) {
|
8446 |
|
8447 | var rootHandler = options.rootHandler;
|
8448 |
|
8449 | if (options instanceof ElementHandler) {
|
8450 |
|
8451 | rootHandler = options;
|
8452 | options = {};
|
8453 | } else {
|
8454 | if (typeof options === 'string') {
|
8455 |
|
8456 | rootHandler = this.handler(options);
|
8457 | options = {};
|
8458 | } else if (typeof rootHandler === 'string') {
|
8459 |
|
8460 | rootHandler = this.handler(rootHandler);
|
8461 | }
|
8462 | }
|
8463 |
|
8464 | var model = this.model,
|
8465 | lax = this.lax;
|
8466 |
|
8467 | var context = new Context(assign({}, options, { rootHandler: rootHandler })),
|
8468 | parser = new Parser({ proxy: true }),
|
8469 | stack = createStack();
|
8470 |
|
8471 | rootHandler.context = context;
|
8472 |
|
8473 |
|
8474 | stack.push(rootHandler);
|
8475 |
|
8476 |
|
8477 | |
8478 |
|
8479 |
|
8480 |
|
8481 |
|
8482 |
|
8483 |
|
8484 |
|
8485 |
|
8486 | function handleError(err, getContext, lax) {
|
8487 |
|
8488 | var ctx = getContext();
|
8489 |
|
8490 | var line = ctx.line,
|
8491 | column = ctx.column,
|
8492 | data = ctx.data;
|
8493 |
|
8494 |
|
8495 |
|
8496 |
|
8497 | if (data.charAt(0) === '<' && data.indexOf(' ') !== -1) {
|
8498 | data = data.slice(0, data.indexOf(' ')) + '>';
|
8499 | }
|
8500 |
|
8501 | var message =
|
8502 | 'unparsable content ' + (data ? data + ' ' : '') + 'detected\n\t' +
|
8503 | 'line: ' + line + '\n\t' +
|
8504 | 'column: ' + column + '\n\t' +
|
8505 | 'nested error: ' + err.message;
|
8506 |
|
8507 | if (lax) {
|
8508 | context.addWarning({
|
8509 | message: message,
|
8510 | error: err
|
8511 | });
|
8512 |
|
8513 | return true;
|
8514 | } else {
|
8515 | throw error$1(message);
|
8516 | }
|
8517 | }
|
8518 |
|
8519 | function handleWarning(err, getContext) {
|
8520 |
|
8521 | return handleError(err, getContext, true);
|
8522 | }
|
8523 |
|
8524 | |
8525 |
|
8526 |
|
8527 | function resolveReferences() {
|
8528 |
|
8529 | var elementsById = context.elementsById;
|
8530 | var references = context.references;
|
8531 |
|
8532 | var i, r;
|
8533 |
|
8534 | for (i = 0; (r = references[i]); i++) {
|
8535 | var element = r.element;
|
8536 | var reference = elementsById[r.id];
|
8537 | var property = getModdleDescriptor(element).propertiesByName[r.property];
|
8538 |
|
8539 | if (!reference) {
|
8540 | context.addWarning({
|
8541 | message: 'unresolved reference <' + r.id + '>',
|
8542 | element: r.element,
|
8543 | property: r.property,
|
8544 | value: r.id
|
8545 | });
|
8546 | }
|
8547 |
|
8548 | if (property.isMany) {
|
8549 | var collection = element.get(property.name),
|
8550 | idx = collection.indexOf(r);
|
8551 |
|
8552 |
|
8553 |
|
8554 | if (idx === -1) {
|
8555 | idx = collection.length;
|
8556 | }
|
8557 |
|
8558 | if (!reference) {
|
8559 |
|
8560 | collection.splice(idx, 1);
|
8561 | } else {
|
8562 |
|
8563 | collection[idx] = reference;
|
8564 | }
|
8565 | } else {
|
8566 | element.set(property.name, reference);
|
8567 | }
|
8568 | }
|
8569 | }
|
8570 |
|
8571 | function handleClose() {
|
8572 | stack.pop().handleEnd();
|
8573 | }
|
8574 |
|
8575 | var PREAMBLE_START_PATTERN = /^<\?xml /i;
|
8576 |
|
8577 | var ENCODING_PATTERN = / encoding="([^"]+)"/i;
|
8578 |
|
8579 | var UTF_8_PATTERN = /^utf-8$/i;
|
8580 |
|
8581 | function handleQuestion(question) {
|
8582 |
|
8583 | if (!PREAMBLE_START_PATTERN.test(question)) {
|
8584 | return;
|
8585 | }
|
8586 |
|
8587 | var match = ENCODING_PATTERN.exec(question);
|
8588 | var encoding = match && match[1];
|
8589 |
|
8590 | if (!encoding || UTF_8_PATTERN.test(encoding)) {
|
8591 | return;
|
8592 | }
|
8593 |
|
8594 | context.addWarning({
|
8595 | message:
|
8596 | 'unsupported document encoding <' + encoding + '>, ' +
|
8597 | 'falling back to UTF-8'
|
8598 | });
|
8599 | }
|
8600 |
|
8601 | function handleOpen(node, getContext) {
|
8602 | var handler = stack.peek();
|
8603 |
|
8604 | try {
|
8605 | stack.push(handler.handleNode(node));
|
8606 | } catch (err) {
|
8607 |
|
8608 | if (handleError(err, getContext, lax)) {
|
8609 | stack.push(new NoopHandler());
|
8610 | }
|
8611 | }
|
8612 | }
|
8613 |
|
8614 | function handleCData(text, getContext) {
|
8615 |
|
8616 | try {
|
8617 | stack.peek().handleText(text);
|
8618 | } catch (err) {
|
8619 | handleWarning(err, getContext);
|
8620 | }
|
8621 | }
|
8622 |
|
8623 | function handleText(text, getContext) {
|
8624 |
|
8625 |
|
8626 | text = text.trim();
|
8627 |
|
8628 | if (!text) {
|
8629 | return;
|
8630 | }
|
8631 |
|
8632 | handleCData(text, getContext);
|
8633 | }
|
8634 |
|
8635 | var uriMap = model.getPackages().reduce(function(uriMap, p) {
|
8636 | uriMap[p.uri] = p.prefix;
|
8637 |
|
8638 | return uriMap;
|
8639 | }, {});
|
8640 |
|
8641 | parser
|
8642 | .ns(uriMap)
|
8643 | .on('openTag', function(obj, decodeStr, selfClosing, getContext) {
|
8644 |
|
8645 |
|
8646 | var attrs = obj.attrs || {};
|
8647 |
|
8648 | var decodedAttrs = Object.keys(attrs).reduce(function(d, key) {
|
8649 | var value = decodeStr(attrs[key]);
|
8650 |
|
8651 | d[key] = value;
|
8652 |
|
8653 | return d;
|
8654 | }, {});
|
8655 |
|
8656 | var node = {
|
8657 | name: obj.name,
|
8658 | originalName: obj.originalName,
|
8659 | attributes: decodedAttrs,
|
8660 | ns: obj.ns
|
8661 | };
|
8662 |
|
8663 | handleOpen(node, getContext);
|
8664 | })
|
8665 | .on('question', handleQuestion)
|
8666 | .on('closeTag', handleClose)
|
8667 | .on('cdata', handleCData)
|
8668 | .on('text', function(text, decodeEntities, getContext) {
|
8669 | handleText(decodeEntities(text), getContext);
|
8670 | })
|
8671 | .on('error', handleError)
|
8672 | .on('warn', handleWarning);
|
8673 |
|
8674 |
|
8675 |
|
8676 |
|
8677 |
|
8678 | defer(function() {
|
8679 | var err;
|
8680 |
|
8681 | try {
|
8682 | parser.parse(xml);
|
8683 |
|
8684 | resolveReferences();
|
8685 | } catch (e) {
|
8686 | err = e;
|
8687 | }
|
8688 |
|
8689 | var element = rootHandler.element;
|
8690 |
|
8691 |
|
8692 |
|
8693 | if (!err && !element) {
|
8694 | err = error$1('failed to parse document as <' + rootHandler.type.$descriptor.name + '>');
|
8695 | }
|
8696 |
|
8697 | done(err, err ? undefined : element, context);
|
8698 | });
|
8699 | };
|
8700 |
|
8701 | Reader.prototype.handler = function(name) {
|
8702 | return new RootElementHandler(this.model, name);
|
8703 | };
|
8704 |
|
8705 |
|
8706 |
|
8707 |
|
8708 | function createStack() {
|
8709 | var stack = [];
|
8710 |
|
8711 | Object.defineProperty(stack, 'peek', {
|
8712 | value: function() {
|
8713 | return this[this.length - 1];
|
8714 | }
|
8715 | });
|
8716 |
|
8717 | return stack;
|
8718 | }
|
8719 |
|
8720 | var XML_PREAMBLE = '<?xml version="1.0" encoding="UTF-8"?>\n';
|
8721 |
|
8722 | var ESCAPE_ATTR_CHARS = /<|>|'|"|&|\n\r|\n/g;
|
8723 | var ESCAPE_CHARS = /<|>|&/g;
|
8724 |
|
8725 |
|
8726 | function Namespaces(parent) {
|
8727 |
|
8728 | var prefixMap = {};
|
8729 | var uriMap = {};
|
8730 | var used = {};
|
8731 |
|
8732 | var wellknown = [];
|
8733 | var custom = [];
|
8734 |
|
8735 |
|
8736 |
|
8737 | this.byUri = function(uri) {
|
8738 | return uriMap[uri] || (
|
8739 | parent && parent.byUri(uri)
|
8740 | );
|
8741 | };
|
8742 |
|
8743 | this.add = function(ns, isWellknown) {
|
8744 |
|
8745 | uriMap[ns.uri] = ns;
|
8746 |
|
8747 | if (isWellknown) {
|
8748 | wellknown.push(ns);
|
8749 | } else {
|
8750 | custom.push(ns);
|
8751 | }
|
8752 |
|
8753 | this.mapPrefix(ns.prefix, ns.uri);
|
8754 | };
|
8755 |
|
8756 | this.uriByPrefix = function(prefix) {
|
8757 | return prefixMap[prefix || 'xmlns'];
|
8758 | };
|
8759 |
|
8760 | this.mapPrefix = function(prefix, uri) {
|
8761 | prefixMap[prefix || 'xmlns'] = uri;
|
8762 | };
|
8763 |
|
8764 | this.logUsed = function(ns) {
|
8765 | var uri = ns.uri;
|
8766 |
|
8767 | used[uri] = this.byUri(uri);
|
8768 | };
|
8769 |
|
8770 | this.getUsed = function(ns) {
|
8771 |
|
8772 | function isUsed(ns) {
|
8773 | return used[ns.uri];
|
8774 | }
|
8775 |
|
8776 | var allNs = [].concat(wellknown, custom);
|
8777 |
|
8778 | return allNs.filter(isUsed);
|
8779 | };
|
8780 |
|
8781 | }
|
8782 |
|
8783 | function lower(string) {
|
8784 | return string.charAt(0).toLowerCase() + string.slice(1);
|
8785 | }
|
8786 |
|
8787 | function nameToAlias(name, pkg) {
|
8788 | if (hasLowerCaseAlias(pkg)) {
|
8789 | return lower(name);
|
8790 | } else {
|
8791 | return name;
|
8792 | }
|
8793 | }
|
8794 |
|
8795 | function inherits(ctor, superCtor) {
|
8796 | ctor.super_ = superCtor;
|
8797 | ctor.prototype = Object.create(superCtor.prototype, {
|
8798 | constructor: {
|
8799 | value: ctor,
|
8800 | enumerable: false,
|
8801 | writable: true,
|
8802 | configurable: true
|
8803 | }
|
8804 | });
|
8805 | }
|
8806 |
|
8807 | function nsName(ns) {
|
8808 | if (isString(ns)) {
|
8809 | return ns;
|
8810 | } else {
|
8811 | return (ns.prefix ? ns.prefix + ':' : '') + ns.localName;
|
8812 | }
|
8813 | }
|
8814 |
|
8815 | function getNsAttrs(namespaces) {
|
8816 |
|
8817 | return map(namespaces.getUsed(), function(ns) {
|
8818 | var name = 'xmlns' + (ns.prefix ? ':' + ns.prefix : '');
|
8819 | return { name: name, value: ns.uri };
|
8820 | });
|
8821 |
|
8822 | }
|
8823 |
|
8824 | function getElementNs(ns, descriptor) {
|
8825 | if (descriptor.isGeneric) {
|
8826 | return assign({ localName: descriptor.ns.localName }, ns);
|
8827 | } else {
|
8828 | return assign({ localName: nameToAlias(descriptor.ns.localName, descriptor.$pkg) }, ns);
|
8829 | }
|
8830 | }
|
8831 |
|
8832 | function getPropertyNs(ns, descriptor) {
|
8833 | return assign({ localName: descriptor.ns.localName }, ns);
|
8834 | }
|
8835 |
|
8836 | function getSerializableProperties(element) {
|
8837 | var descriptor = element.$descriptor;
|
8838 |
|
8839 | return filter(descriptor.properties, function(p) {
|
8840 | var name = p.name;
|
8841 |
|
8842 | if (p.isVirtual) {
|
8843 | return false;
|
8844 | }
|
8845 |
|
8846 |
|
8847 | if (!element.hasOwnProperty(name)) {
|
8848 | return false;
|
8849 | }
|
8850 |
|
8851 | var value = element[name];
|
8852 |
|
8853 |
|
8854 | if (value === p.default) {
|
8855 | return false;
|
8856 | }
|
8857 |
|
8858 |
|
8859 | if (value === null) {
|
8860 | return false;
|
8861 | }
|
8862 |
|
8863 | return p.isMany ? value.length : true;
|
8864 | });
|
8865 | }
|
8866 |
|
8867 | var ESCAPE_ATTR_MAP = {
|
8868 | '\n': '#10',
|
8869 | '\n\r': '#10',
|
8870 | '"': '#34',
|
8871 | '\'': '#39',
|
8872 | '<': '#60',
|
8873 | '>': '#62',
|
8874 | '&': '#38'
|
8875 | };
|
8876 |
|
8877 | var ESCAPE_MAP = {
|
8878 | '<': 'lt',
|
8879 | '>': 'gt',
|
8880 | '&': 'amp'
|
8881 | };
|
8882 |
|
8883 | function escape$1(str, charPattern, replaceMap) {
|
8884 |
|
8885 |
|
8886 | str = isString(str) ? str : '' + str;
|
8887 |
|
8888 | return str.replace(charPattern, function(s) {
|
8889 | return '&' + replaceMap[s] + ';';
|
8890 | });
|
8891 | }
|
8892 |
|
8893 | |
8894 |
|
8895 |
|
8896 |
|
8897 |
|
8898 |
|
8899 | function escapeAttr(str) {
|
8900 | return escape$1(str, ESCAPE_ATTR_CHARS, ESCAPE_ATTR_MAP);
|
8901 | }
|
8902 |
|
8903 | function escapeBody(str) {
|
8904 | return escape$1(str, ESCAPE_CHARS, ESCAPE_MAP);
|
8905 | }
|
8906 |
|
8907 | function filterAttributes(props) {
|
8908 | return filter(props, function(p) { return p.isAttr; });
|
8909 | }
|
8910 |
|
8911 | function filterContained(props) {
|
8912 | return filter(props, function(p) { return !p.isAttr; });
|
8913 | }
|
8914 |
|
8915 |
|
8916 | function ReferenceSerializer(tagName) {
|
8917 | this.tagName = tagName;
|
8918 | }
|
8919 |
|
8920 | ReferenceSerializer.prototype.build = function(element) {
|
8921 | this.element = element;
|
8922 | return this;
|
8923 | };
|
8924 |
|
8925 | ReferenceSerializer.prototype.serializeTo = function(writer) {
|
8926 | writer
|
8927 | .appendIndent()
|
8928 | .append('<' + this.tagName + '>' + this.element.id + '</' + this.tagName + '>')
|
8929 | .appendNewLine();
|
8930 | };
|
8931 |
|
8932 | function BodySerializer() {}
|
8933 |
|
8934 | BodySerializer.prototype.serializeValue =
|
8935 | BodySerializer.prototype.serializeTo = function(writer) {
|
8936 | writer.append(
|
8937 | this.escape
|
8938 | ? escapeBody(this.value)
|
8939 | : this.value
|
8940 | );
|
8941 | };
|
8942 |
|
8943 | BodySerializer.prototype.build = function(prop, value) {
|
8944 | this.value = value;
|
8945 |
|
8946 | if (prop.type === 'String' && value.search(ESCAPE_CHARS) !== -1) {
|
8947 | this.escape = true;
|
8948 | }
|
8949 |
|
8950 | return this;
|
8951 | };
|
8952 |
|
8953 | function ValueSerializer(tagName) {
|
8954 | this.tagName = tagName;
|
8955 | }
|
8956 |
|
8957 | inherits(ValueSerializer, BodySerializer);
|
8958 |
|
8959 | ValueSerializer.prototype.serializeTo = function(writer) {
|
8960 |
|
8961 | writer
|
8962 | .appendIndent()
|
8963 | .append('<' + this.tagName + '>');
|
8964 |
|
8965 | this.serializeValue(writer);
|
8966 |
|
8967 | writer
|
8968 | .append('</' + this.tagName + '>')
|
8969 | .appendNewLine();
|
8970 | };
|
8971 |
|
8972 | function ElementSerializer(parent, propertyDescriptor) {
|
8973 | this.body = [];
|
8974 | this.attrs = [];
|
8975 |
|
8976 | this.parent = parent;
|
8977 | this.propertyDescriptor = propertyDescriptor;
|
8978 | }
|
8979 |
|
8980 | ElementSerializer.prototype.build = function(element) {
|
8981 | this.element = element;
|
8982 |
|
8983 | var elementDescriptor = element.$descriptor,
|
8984 | propertyDescriptor = this.propertyDescriptor;
|
8985 |
|
8986 | var otherAttrs,
|
8987 | properties;
|
8988 |
|
8989 | var isGeneric = elementDescriptor.isGeneric;
|
8990 |
|
8991 | if (isGeneric) {
|
8992 | otherAttrs = this.parseGeneric(element);
|
8993 | } else {
|
8994 | otherAttrs = this.parseNsAttributes(element);
|
8995 | }
|
8996 |
|
8997 | if (propertyDescriptor) {
|
8998 | this.ns = this.nsPropertyTagName(propertyDescriptor);
|
8999 | } else {
|
9000 | this.ns = this.nsTagName(elementDescriptor);
|
9001 | }
|
9002 |
|
9003 |
|
9004 | this.tagName = this.addTagName(this.ns);
|
9005 |
|
9006 | if (!isGeneric) {
|
9007 | properties = getSerializableProperties(element);
|
9008 |
|
9009 | this.parseAttributes(filterAttributes(properties));
|
9010 | this.parseContainments(filterContained(properties));
|
9011 | }
|
9012 |
|
9013 | this.parseGenericAttributes(element, otherAttrs);
|
9014 |
|
9015 | return this;
|
9016 | };
|
9017 |
|
9018 | ElementSerializer.prototype.nsTagName = function(descriptor) {
|
9019 | var effectiveNs = this.logNamespaceUsed(descriptor.ns);
|
9020 | return getElementNs(effectiveNs, descriptor);
|
9021 | };
|
9022 |
|
9023 | ElementSerializer.prototype.nsPropertyTagName = function(descriptor) {
|
9024 | var effectiveNs = this.logNamespaceUsed(descriptor.ns);
|
9025 | return getPropertyNs(effectiveNs, descriptor);
|
9026 | };
|
9027 |
|
9028 | ElementSerializer.prototype.isLocalNs = function(ns) {
|
9029 | return ns.uri === this.ns.uri;
|
9030 | };
|
9031 |
|
9032 | |
9033 |
|
9034 |
|
9035 |
|
9036 |
|
9037 |
|
9038 |
|
9039 |
|
9040 | ElementSerializer.prototype.nsAttributeName = function(element) {
|
9041 |
|
9042 | var ns;
|
9043 |
|
9044 | if (isString(element)) {
|
9045 | ns = parseName(element);
|
9046 | } else {
|
9047 | ns = element.ns;
|
9048 | }
|
9049 |
|
9050 |
|
9051 | if (element.inherited) {
|
9052 | return { localName: ns.localName };
|
9053 | }
|
9054 |
|
9055 |
|
9056 | var effectiveNs = this.logNamespaceUsed(ns);
|
9057 |
|
9058 |
|
9059 | this.getNamespaces().logUsed(effectiveNs);
|
9060 |
|
9061 |
|
9062 | if (this.isLocalNs(effectiveNs)) {
|
9063 | return { localName: ns.localName };
|
9064 | } else {
|
9065 | return assign({ localName: ns.localName }, effectiveNs);
|
9066 | }
|
9067 | };
|
9068 |
|
9069 | ElementSerializer.prototype.parseGeneric = function(element) {
|
9070 |
|
9071 | var self = this,
|
9072 | body = this.body;
|
9073 |
|
9074 | var attributes = [];
|
9075 |
|
9076 | forEach(element, function(val, key) {
|
9077 |
|
9078 | var nonNsAttr;
|
9079 |
|
9080 | if (key === '$body') {
|
9081 | body.push(new BodySerializer().build({ type: 'String' }, val));
|
9082 | } else
|
9083 | if (key === '$children') {
|
9084 | forEach(val, function(child) {
|
9085 | body.push(new ElementSerializer(self).build(child));
|
9086 | });
|
9087 | } else
|
9088 | if (key.indexOf('$') !== 0) {
|
9089 | nonNsAttr = self.parseNsAttribute(element, key, val);
|
9090 |
|
9091 | if (nonNsAttr) {
|
9092 | attributes.push({ name: key, value: val });
|
9093 | }
|
9094 | }
|
9095 | });
|
9096 |
|
9097 | return attributes;
|
9098 | };
|
9099 |
|
9100 | ElementSerializer.prototype.parseNsAttribute = function(element, name, value) {
|
9101 | var model = element.$model;
|
9102 |
|
9103 | var nameNs = parseName(name);
|
9104 |
|
9105 | var ns;
|
9106 |
|
9107 |
|
9108 | if (nameNs.prefix === 'xmlns') {
|
9109 | ns = { prefix: nameNs.localName, uri: value };
|
9110 | }
|
9111 |
|
9112 |
|
9113 | if (!nameNs.prefix && nameNs.localName === 'xmlns') {
|
9114 | ns = { uri: value };
|
9115 | }
|
9116 |
|
9117 | if (!ns) {
|
9118 | return {
|
9119 | name: name,
|
9120 | value: value
|
9121 | };
|
9122 | }
|
9123 |
|
9124 | if (model && model.getPackage(value)) {
|
9125 |
|
9126 | this.logNamespace(ns, true, true);
|
9127 | } else {
|
9128 |
|
9129 | var actualNs = this.logNamespaceUsed(ns, true);
|
9130 |
|
9131 | this.getNamespaces().logUsed(actualNs);
|
9132 | }
|
9133 | };
|
9134 |
|
9135 |
|
9136 | |
9137 |
|
9138 |
|
9139 |
|
9140 |
|
9141 |
|
9142 | ElementSerializer.prototype.parseNsAttributes = function(element, attrs) {
|
9143 | var self = this;
|
9144 |
|
9145 | var genericAttrs = element.$attrs;
|
9146 |
|
9147 | var attributes = [];
|
9148 |
|
9149 |
|
9150 |
|
9151 |
|
9152 | forEach(genericAttrs, function(value, name) {
|
9153 |
|
9154 | var nonNsAttr = self.parseNsAttribute(element, name, value);
|
9155 |
|
9156 | if (nonNsAttr) {
|
9157 | attributes.push(nonNsAttr);
|
9158 | }
|
9159 | });
|
9160 |
|
9161 | return attributes;
|
9162 | };
|
9163 |
|
9164 | ElementSerializer.prototype.parseGenericAttributes = function(element, attributes) {
|
9165 |
|
9166 | var self = this;
|
9167 |
|
9168 | forEach(attributes, function(attr) {
|
9169 |
|
9170 |
|
9171 |
|
9172 | if (attr.name === XSI_TYPE$1) {
|
9173 | return;
|
9174 | }
|
9175 |
|
9176 | try {
|
9177 | self.addAttribute(self.nsAttributeName(attr.name), attr.value);
|
9178 | } catch (e) {
|
9179 | console.warn(
|
9180 | 'missing namespace information for ',
|
9181 | attr.name, '=', attr.value, 'on', element,
|
9182 | e);
|
9183 | }
|
9184 | });
|
9185 | };
|
9186 |
|
9187 | ElementSerializer.prototype.parseContainments = function(properties) {
|
9188 |
|
9189 | var self = this,
|
9190 | body = this.body,
|
9191 | element = this.element;
|
9192 |
|
9193 | forEach(properties, function(p) {
|
9194 | var value = element.get(p.name),
|
9195 | isReference = p.isReference,
|
9196 | isMany = p.isMany;
|
9197 |
|
9198 | if (!isMany) {
|
9199 | value = [ value ];
|
9200 | }
|
9201 |
|
9202 | if (p.isBody) {
|
9203 | body.push(new BodySerializer().build(p, value[0]));
|
9204 | } else
|
9205 | if (isSimple(p.type)) {
|
9206 | forEach(value, function(v) {
|
9207 | body.push(new ValueSerializer(self.addTagName(self.nsPropertyTagName(p))).build(p, v));
|
9208 | });
|
9209 | } else
|
9210 | if (isReference) {
|
9211 | forEach(value, function(v) {
|
9212 | body.push(new ReferenceSerializer(self.addTagName(self.nsPropertyTagName(p))).build(v));
|
9213 | });
|
9214 | } else {
|
9215 |
|
9216 |
|
9217 | var asType = serializeAsType(p),
|
9218 | asProperty = serializeAsProperty(p);
|
9219 |
|
9220 | forEach(value, function(v) {
|
9221 | var serializer;
|
9222 |
|
9223 | if (asType) {
|
9224 | serializer = new TypeSerializer(self, p);
|
9225 | } else
|
9226 | if (asProperty) {
|
9227 | serializer = new ElementSerializer(self, p);
|
9228 | } else {
|
9229 | serializer = new ElementSerializer(self);
|
9230 | }
|
9231 |
|
9232 | body.push(serializer.build(v));
|
9233 | });
|
9234 | }
|
9235 | });
|
9236 | };
|
9237 |
|
9238 | ElementSerializer.prototype.getNamespaces = function(local) {
|
9239 |
|
9240 | var namespaces = this.namespaces,
|
9241 | parent = this.parent,
|
9242 | parentNamespaces;
|
9243 |
|
9244 | if (!namespaces) {
|
9245 | parentNamespaces = parent && parent.getNamespaces();
|
9246 |
|
9247 | if (local || !parentNamespaces) {
|
9248 | this.namespaces = namespaces = new Namespaces(parentNamespaces);
|
9249 | } else {
|
9250 | namespaces = parentNamespaces;
|
9251 | }
|
9252 | }
|
9253 |
|
9254 | return namespaces;
|
9255 | };
|
9256 |
|
9257 | ElementSerializer.prototype.logNamespace = function(ns, wellknown, local) {
|
9258 | var namespaces = this.getNamespaces(local);
|
9259 |
|
9260 | var nsUri = ns.uri,
|
9261 | nsPrefix = ns.prefix;
|
9262 |
|
9263 | var existing = namespaces.byUri(nsUri);
|
9264 |
|
9265 | if (!existing) {
|
9266 | namespaces.add(ns, wellknown);
|
9267 | }
|
9268 |
|
9269 | namespaces.mapPrefix(nsPrefix, nsUri);
|
9270 |
|
9271 | return ns;
|
9272 | };
|
9273 |
|
9274 | ElementSerializer.prototype.logNamespaceUsed = function(ns, local) {
|
9275 | var element = this.element,
|
9276 | model = element.$model,
|
9277 | namespaces = this.getNamespaces(local);
|
9278 |
|
9279 |
|
9280 |
|
9281 |
|
9282 |
|
9283 |
|
9284 |
|
9285 | var prefix = ns.prefix,
|
9286 | uri = ns.uri,
|
9287 | newPrefix, idx,
|
9288 | wellknownUri;
|
9289 |
|
9290 |
|
9291 | if (!prefix && !uri) {
|
9292 | return { localName: ns.localName };
|
9293 | }
|
9294 |
|
9295 | wellknownUri = DEFAULT_NS_MAP[prefix] || model && (model.getPackage(prefix) || {}).uri;
|
9296 |
|
9297 | uri = uri || wellknownUri || namespaces.uriByPrefix(prefix);
|
9298 |
|
9299 | if (!uri) {
|
9300 | throw new Error('no namespace uri given for prefix <' + prefix + '>');
|
9301 | }
|
9302 |
|
9303 | ns = namespaces.byUri(uri);
|
9304 |
|
9305 | if (!ns) {
|
9306 | newPrefix = prefix;
|
9307 | idx = 1;
|
9308 |
|
9309 |
|
9310 | while (namespaces.uriByPrefix(newPrefix)) {
|
9311 | newPrefix = prefix + '_' + idx++;
|
9312 | }
|
9313 |
|
9314 | ns = this.logNamespace({ prefix: newPrefix, uri: uri }, wellknownUri === uri);
|
9315 | }
|
9316 |
|
9317 | if (prefix) {
|
9318 | namespaces.mapPrefix(prefix, uri);
|
9319 | }
|
9320 |
|
9321 | return ns;
|
9322 | };
|
9323 |
|
9324 | ElementSerializer.prototype.parseAttributes = function(properties) {
|
9325 | var self = this,
|
9326 | element = this.element;
|
9327 |
|
9328 | forEach(properties, function(p) {
|
9329 |
|
9330 | var value = element.get(p.name);
|
9331 |
|
9332 | if (p.isReference) {
|
9333 |
|
9334 | if (!p.isMany) {
|
9335 | value = value.id;
|
9336 | }
|
9337 | else {
|
9338 | var values = [];
|
9339 | forEach(value, function(v) {
|
9340 | values.push(v.id);
|
9341 | });
|
9342 |
|
9343 | value = values.join(' ');
|
9344 | }
|
9345 |
|
9346 | }
|
9347 |
|
9348 | self.addAttribute(self.nsAttributeName(p), value);
|
9349 | });
|
9350 | };
|
9351 |
|
9352 | ElementSerializer.prototype.addTagName = function(nsTagName) {
|
9353 | var actualNs = this.logNamespaceUsed(nsTagName);
|
9354 |
|
9355 | this.getNamespaces().logUsed(actualNs);
|
9356 |
|
9357 | return nsName(nsTagName);
|
9358 | };
|
9359 |
|
9360 | ElementSerializer.prototype.addAttribute = function(name, value) {
|
9361 | var attrs = this.attrs;
|
9362 |
|
9363 | if (isString(value)) {
|
9364 | value = escapeAttr(value);
|
9365 | }
|
9366 |
|
9367 | attrs.push({ name: name, value: value });
|
9368 | };
|
9369 |
|
9370 | ElementSerializer.prototype.serializeAttributes = function(writer) {
|
9371 | var attrs = this.attrs,
|
9372 | namespaces = this.namespaces;
|
9373 |
|
9374 | if (namespaces) {
|
9375 | attrs = getNsAttrs(namespaces).concat(attrs);
|
9376 | }
|
9377 |
|
9378 | forEach(attrs, function(a) {
|
9379 | writer
|
9380 | .append(' ')
|
9381 | .append(nsName(a.name)).append('="').append(a.value).append('"');
|
9382 | });
|
9383 | };
|
9384 |
|
9385 | ElementSerializer.prototype.serializeTo = function(writer) {
|
9386 | var firstBody = this.body[0],
|
9387 | indent = firstBody && firstBody.constructor !== BodySerializer;
|
9388 |
|
9389 | writer
|
9390 | .appendIndent()
|
9391 | .append('<' + this.tagName);
|
9392 |
|
9393 | this.serializeAttributes(writer);
|
9394 |
|
9395 | writer.append(firstBody ? '>' : ' />');
|
9396 |
|
9397 | if (firstBody) {
|
9398 |
|
9399 | if (indent) {
|
9400 | writer
|
9401 | .appendNewLine()
|
9402 | .indent();
|
9403 | }
|
9404 |
|
9405 | forEach(this.body, function(b) {
|
9406 | b.serializeTo(writer);
|
9407 | });
|
9408 |
|
9409 | if (indent) {
|
9410 | writer
|
9411 | .unindent()
|
9412 | .appendIndent();
|
9413 | }
|
9414 |
|
9415 | writer.append('</' + this.tagName + '>');
|
9416 | }
|
9417 |
|
9418 | writer.appendNewLine();
|
9419 | };
|
9420 |
|
9421 | |
9422 |
|
9423 |
|
9424 | function TypeSerializer(parent, propertyDescriptor) {
|
9425 | ElementSerializer.call(this, parent, propertyDescriptor);
|
9426 | }
|
9427 |
|
9428 | inherits(TypeSerializer, ElementSerializer);
|
9429 |
|
9430 | TypeSerializer.prototype.parseNsAttributes = function(element) {
|
9431 |
|
9432 |
|
9433 | var attributes = ElementSerializer.prototype.parseNsAttributes.call(this, element);
|
9434 |
|
9435 | var descriptor = element.$descriptor;
|
9436 |
|
9437 |
|
9438 | if (descriptor.name === this.propertyDescriptor.type) {
|
9439 | return attributes;
|
9440 | }
|
9441 |
|
9442 | var typeNs = this.typeNs = this.nsTagName(descriptor);
|
9443 | this.getNamespaces().logUsed(this.typeNs);
|
9444 |
|
9445 |
|
9446 |
|
9447 |
|
9448 | var pkg = element.$model.getPackage(typeNs.uri),
|
9449 | typePrefix = (pkg.xml && pkg.xml.typePrefix) || '';
|
9450 |
|
9451 | this.addAttribute(
|
9452 | this.nsAttributeName(XSI_TYPE$1),
|
9453 | (typeNs.prefix ? typeNs.prefix + ':' : '') + typePrefix + descriptor.ns.localName
|
9454 | );
|
9455 |
|
9456 | return attributes;
|
9457 | };
|
9458 |
|
9459 | TypeSerializer.prototype.isLocalNs = function(ns) {
|
9460 | return ns.uri === (this.typeNs || this.ns).uri;
|
9461 | };
|
9462 |
|
9463 | function SavingWriter() {
|
9464 | this.value = '';
|
9465 |
|
9466 | this.write = function(str) {
|
9467 | this.value += str;
|
9468 | };
|
9469 | }
|
9470 |
|
9471 | function FormatingWriter(out, format) {
|
9472 |
|
9473 | var indent = [''];
|
9474 |
|
9475 | this.append = function(str) {
|
9476 | out.write(str);
|
9477 |
|
9478 | return this;
|
9479 | };
|
9480 |
|
9481 | this.appendNewLine = function() {
|
9482 | if (format) {
|
9483 | out.write('\n');
|
9484 | }
|
9485 |
|
9486 | return this;
|
9487 | };
|
9488 |
|
9489 | this.appendIndent = function() {
|
9490 | if (format) {
|
9491 | out.write(indent.join(' '));
|
9492 | }
|
9493 |
|
9494 | return this;
|
9495 | };
|
9496 |
|
9497 | this.indent = function() {
|
9498 | indent.push('');
|
9499 | return this;
|
9500 | };
|
9501 |
|
9502 | this.unindent = function() {
|
9503 | indent.pop();
|
9504 | return this;
|
9505 | };
|
9506 | }
|
9507 |
|
9508 | |
9509 |
|
9510 |
|
9511 |
|
9512 |
|
9513 | function Writer(options) {
|
9514 |
|
9515 | options = assign({ format: false, preamble: true }, options || {});
|
9516 |
|
9517 | function toXML(tree, writer) {
|
9518 | var internalWriter = writer || new SavingWriter();
|
9519 | var formatingWriter = new FormatingWriter(internalWriter, options.format);
|
9520 |
|
9521 | if (options.preamble) {
|
9522 | formatingWriter.append(XML_PREAMBLE);
|
9523 | }
|
9524 |
|
9525 | new ElementSerializer().build(tree).serializeTo(formatingWriter);
|
9526 |
|
9527 | if (!writer) {
|
9528 | return internalWriter.value;
|
9529 | }
|
9530 | }
|
9531 |
|
9532 | return {
|
9533 | toXML: toXML
|
9534 | };
|
9535 | }
|
9536 |
|
9537 | |
9538 |
|
9539 |
|
9540 |
|
9541 |
|
9542 |
|
9543 |
|
9544 |
|
9545 |
|
9546 | function BpmnModdle(packages, options) {
|
9547 | Moddle.call(this, packages, options);
|
9548 | }
|
9549 |
|
9550 | BpmnModdle.prototype = Object.create(Moddle.prototype);
|
9551 |
|
9552 |
|
9553 | |
9554 |
|
9555 |
|
9556 |
|
9557 |
|
9558 |
|
9559 |
|
9560 |
|
9561 |
|
9562 | BpmnModdle.prototype.fromXML = function(xmlStr, typeName, options, done) {
|
9563 |
|
9564 | if (!isString(typeName)) {
|
9565 | done = options;
|
9566 | options = typeName;
|
9567 | typeName = 'bpmn:Definitions';
|
9568 | }
|
9569 |
|
9570 | if (isFunction(options)) {
|
9571 | done = options;
|
9572 | options = {};
|
9573 | }
|
9574 |
|
9575 | var reader = new Reader(assign({ model: this, lax: true }, options));
|
9576 | var rootHandler = reader.handler(typeName);
|
9577 |
|
9578 | reader.fromXML(xmlStr, rootHandler, done);
|
9579 | };
|
9580 |
|
9581 |
|
9582 | |
9583 |
|
9584 |
|
9585 |
|
9586 |
|
9587 |
|
9588 |
|
9589 | BpmnModdle.prototype.toXML = function(element, options, done) {
|
9590 |
|
9591 | if (isFunction(options)) {
|
9592 | done = options;
|
9593 | options = {};
|
9594 | }
|
9595 |
|
9596 | var writer = new Writer(options);
|
9597 |
|
9598 | var result;
|
9599 | var err;
|
9600 |
|
9601 | try {
|
9602 | result = writer.toXML(element);
|
9603 | } catch (e) {
|
9604 | err = e;
|
9605 | }
|
9606 |
|
9607 | return done(err, result);
|
9608 | };
|
9609 |
|
9610 | var name = "BPMN20";
|
9611 | var uri = "http://www.omg.org/spec/BPMN/20100524/MODEL";
|
9612 | var associations = [
|
9613 | ];
|
9614 | var types$1 = [
|
9615 | {
|
9616 | name: "Interface",
|
9617 | superClass: [
|
9618 | "RootElement"
|
9619 | ],
|
9620 | properties: [
|
9621 | {
|
9622 | name: "name",
|
9623 | isAttr: true,
|
9624 | type: "String"
|
9625 | },
|
9626 | {
|
9627 | name: "operations",
|
9628 | type: "Operation",
|
9629 | isMany: true
|
9630 | },
|
9631 | {
|
9632 | name: "implementationRef",
|
9633 | type: "String",
|
9634 | isAttr: true
|
9635 | }
|
9636 | ]
|
9637 | },
|
9638 | {
|
9639 | name: "Operation",
|
9640 | superClass: [
|
9641 | "BaseElement"
|
9642 | ],
|
9643 | properties: [
|
9644 | {
|
9645 | name: "name",
|
9646 | isAttr: true,
|
9647 | type: "String"
|
9648 | },
|
9649 | {
|
9650 | name: "inMessageRef",
|
9651 | type: "Message",
|
9652 | isReference: true
|
9653 | },
|
9654 | {
|
9655 | name: "outMessageRef",
|
9656 | type: "Message",
|
9657 | isReference: true
|
9658 | },
|
9659 | {
|
9660 | name: "errorRef",
|
9661 | type: "Error",
|
9662 | isMany: true,
|
9663 | isReference: true
|
9664 | },
|
9665 | {
|
9666 | name: "implementationRef",
|
9667 | type: "String",
|
9668 | isAttr: true
|
9669 | }
|
9670 | ]
|
9671 | },
|
9672 | {
|
9673 | name: "EndPoint",
|
9674 | superClass: [
|
9675 | "RootElement"
|
9676 | ]
|
9677 | },
|
9678 | {
|
9679 | name: "Auditing",
|
9680 | superClass: [
|
9681 | "BaseElement"
|
9682 | ]
|
9683 | },
|
9684 | {
|
9685 | name: "GlobalTask",
|
9686 | superClass: [
|
9687 | "CallableElement"
|
9688 | ],
|
9689 | properties: [
|
9690 | {
|
9691 | name: "resources",
|
9692 | type: "ResourceRole",
|
9693 | isMany: true
|
9694 | }
|
9695 | ]
|
9696 | },
|
9697 | {
|
9698 | name: "Monitoring",
|
9699 | superClass: [
|
9700 | "BaseElement"
|
9701 | ]
|
9702 | },
|
9703 | {
|
9704 | name: "Performer",
|
9705 | superClass: [
|
9706 | "ResourceRole"
|
9707 | ]
|
9708 | },
|
9709 | {
|
9710 | name: "Process",
|
9711 | superClass: [
|
9712 | "FlowElementsContainer",
|
9713 | "CallableElement"
|
9714 | ],
|
9715 | properties: [
|
9716 | {
|
9717 | name: "processType",
|
9718 | type: "ProcessType",
|
9719 | isAttr: true
|
9720 | },
|
9721 | {
|
9722 | name: "isClosed",
|
9723 | isAttr: true,
|
9724 | type: "Boolean"
|
9725 | },
|
9726 | {
|
9727 | name: "auditing",
|
9728 | type: "Auditing"
|
9729 | },
|
9730 | {
|
9731 | name: "monitoring",
|
9732 | type: "Monitoring"
|
9733 | },
|
9734 | {
|
9735 | name: "properties",
|
9736 | type: "Property",
|
9737 | isMany: true
|
9738 | },
|
9739 | {
|
9740 | name: "laneSets",
|
9741 | type: "LaneSet",
|
9742 | isMany: true,
|
9743 | replaces: "FlowElementsContainer#laneSets"
|
9744 | },
|
9745 | {
|
9746 | name: "flowElements",
|
9747 | type: "FlowElement",
|
9748 | isMany: true,
|
9749 | replaces: "FlowElementsContainer#flowElements"
|
9750 | },
|
9751 | {
|
9752 | name: "artifacts",
|
9753 | type: "Artifact",
|
9754 | isMany: true
|
9755 | },
|
9756 | {
|
9757 | name: "resources",
|
9758 | type: "ResourceRole",
|
9759 | isMany: true
|
9760 | },
|
9761 | {
|
9762 | name: "correlationSubscriptions",
|
9763 | type: "CorrelationSubscription",
|
9764 | isMany: true
|
9765 | },
|
9766 | {
|
9767 | name: "supports",
|
9768 | type: "Process",
|
9769 | isMany: true,
|
9770 | isReference: true
|
9771 | },
|
9772 | {
|
9773 | name: "definitionalCollaborationRef",
|
9774 | type: "Collaboration",
|
9775 | isAttr: true,
|
9776 | isReference: true
|
9777 | },
|
9778 | {
|
9779 | name: "isExecutable",
|
9780 | isAttr: true,
|
9781 | type: "Boolean"
|
9782 | }
|
9783 | ]
|
9784 | },
|
9785 | {
|
9786 | name: "LaneSet",
|
9787 | superClass: [
|
9788 | "BaseElement"
|
9789 | ],
|
9790 | properties: [
|
9791 | {
|
9792 | name: "lanes",
|
9793 | type: "Lane",
|
9794 | isMany: true
|
9795 | },
|
9796 | {
|
9797 | name: "name",
|
9798 | isAttr: true,
|
9799 | type: "String"
|
9800 | }
|
9801 | ]
|
9802 | },
|
9803 | {
|
9804 | name: "Lane",
|
9805 | superClass: [
|
9806 | "BaseElement"
|
9807 | ],
|
9808 | properties: [
|
9809 | {
|
9810 | name: "name",
|
9811 | isAttr: true,
|
9812 | type: "String"
|
9813 | },
|
9814 | {
|
9815 | name: "partitionElementRef",
|
9816 | type: "BaseElement",
|
9817 | isAttr: true,
|
9818 | isReference: true
|
9819 | },
|
9820 | {
|
9821 | name: "partitionElement",
|
9822 | type: "BaseElement"
|
9823 | },
|
9824 | {
|
9825 | name: "flowNodeRef",
|
9826 | type: "FlowNode",
|
9827 | isMany: true,
|
9828 | isReference: true
|
9829 | },
|
9830 | {
|
9831 | name: "childLaneSet",
|
9832 | type: "LaneSet",
|
9833 | xml: {
|
9834 | serialize: "xsi:type"
|
9835 | }
|
9836 | }
|
9837 | ]
|
9838 | },
|
9839 | {
|
9840 | name: "GlobalManualTask",
|
9841 | superClass: [
|
9842 | "GlobalTask"
|
9843 | ]
|
9844 | },
|
9845 | {
|
9846 | name: "ManualTask",
|
9847 | superClass: [
|
9848 | "Task"
|
9849 | ]
|
9850 | },
|
9851 | {
|
9852 | name: "UserTask",
|
9853 | superClass: [
|
9854 | "Task"
|
9855 | ],
|
9856 | properties: [
|
9857 | {
|
9858 | name: "renderings",
|
9859 | type: "Rendering",
|
9860 | isMany: true
|
9861 | },
|
9862 | {
|
9863 | name: "implementation",
|
9864 | isAttr: true,
|
9865 | type: "String"
|
9866 | }
|
9867 | ]
|
9868 | },
|
9869 | {
|
9870 | name: "Rendering",
|
9871 | superClass: [
|
9872 | "BaseElement"
|
9873 | ]
|
9874 | },
|
9875 | {
|
9876 | name: "HumanPerformer",
|
9877 | superClass: [
|
9878 | "Performer"
|
9879 | ]
|
9880 | },
|
9881 | {
|
9882 | name: "PotentialOwner",
|
9883 | superClass: [
|
9884 | "HumanPerformer"
|
9885 | ]
|
9886 | },
|
9887 | {
|
9888 | name: "GlobalUserTask",
|
9889 | superClass: [
|
9890 | "GlobalTask"
|
9891 | ],
|
9892 | properties: [
|
9893 | {
|
9894 | name: "implementation",
|
9895 | isAttr: true,
|
9896 | type: "String"
|
9897 | },
|
9898 | {
|
9899 | name: "renderings",
|
9900 | type: "Rendering",
|
9901 | isMany: true
|
9902 | }
|
9903 | ]
|
9904 | },
|
9905 | {
|
9906 | name: "Gateway",
|
9907 | isAbstract: true,
|
9908 | superClass: [
|
9909 | "FlowNode"
|
9910 | ],
|
9911 | properties: [
|
9912 | {
|
9913 | name: "gatewayDirection",
|
9914 | type: "GatewayDirection",
|
9915 | "default": "Unspecified",
|
9916 | isAttr: true
|
9917 | }
|
9918 | ]
|
9919 | },
|
9920 | {
|
9921 | name: "EventBasedGateway",
|
9922 | superClass: [
|
9923 | "Gateway"
|
9924 | ],
|
9925 | properties: [
|
9926 | {
|
9927 | name: "instantiate",
|
9928 | "default": false,
|
9929 | isAttr: true,
|
9930 | type: "Boolean"
|
9931 | },
|
9932 | {
|
9933 | name: "eventGatewayType",
|
9934 | type: "EventBasedGatewayType",
|
9935 | isAttr: true,
|
9936 | "default": "Exclusive"
|
9937 | }
|
9938 | ]
|
9939 | },
|
9940 | {
|
9941 | name: "ComplexGateway",
|
9942 | superClass: [
|
9943 | "Gateway"
|
9944 | ],
|
9945 | properties: [
|
9946 | {
|
9947 | name: "activationCondition",
|
9948 | type: "Expression",
|
9949 | xml: {
|
9950 | serialize: "xsi:type"
|
9951 | }
|
9952 | },
|
9953 | {
|
9954 | name: "default",
|
9955 | type: "SequenceFlow",
|
9956 | isAttr: true,
|
9957 | isReference: true
|
9958 | }
|
9959 | ]
|
9960 | },
|
9961 | {
|
9962 | name: "ExclusiveGateway",
|
9963 | superClass: [
|
9964 | "Gateway"
|
9965 | ],
|
9966 | properties: [
|
9967 | {
|
9968 | name: "default",
|
9969 | type: "SequenceFlow",
|
9970 | isAttr: true,
|
9971 | isReference: true
|
9972 | }
|
9973 | ]
|
9974 | },
|
9975 | {
|
9976 | name: "InclusiveGateway",
|
9977 | superClass: [
|
9978 | "Gateway"
|
9979 | ],
|
9980 | properties: [
|
9981 | {
|
9982 | name: "default",
|
9983 | type: "SequenceFlow",
|
9984 | isAttr: true,
|
9985 | isReference: true
|
9986 | }
|
9987 | ]
|
9988 | },
|
9989 | {
|
9990 | name: "ParallelGateway",
|
9991 | superClass: [
|
9992 | "Gateway"
|
9993 | ]
|
9994 | },
|
9995 | {
|
9996 | name: "RootElement",
|
9997 | isAbstract: true,
|
9998 | superClass: [
|
9999 | "BaseElement"
|
10000 | ]
|
10001 | },
|
10002 | {
|
10003 | name: "Relationship",
|
10004 | superClass: [
|
10005 | "BaseElement"
|
10006 | ],
|
10007 | properties: [
|
10008 | {
|
10009 | name: "type",
|
10010 | isAttr: true,
|
10011 | type: "String"
|
10012 | },
|
10013 | {
|
10014 | name: "direction",
|
10015 | type: "RelationshipDirection",
|
10016 | isAttr: true
|
10017 | },
|
10018 | {
|
10019 | name: "source",
|
10020 | isMany: true,
|
10021 | isReference: true,
|
10022 | type: "Element"
|
10023 | },
|
10024 | {
|
10025 | name: "target",
|
10026 | isMany: true,
|
10027 | isReference: true,
|
10028 | type: "Element"
|
10029 | }
|
10030 | ]
|
10031 | },
|
10032 | {
|
10033 | name: "BaseElement",
|
10034 | isAbstract: true,
|
10035 | properties: [
|
10036 | {
|
10037 | name: "id",
|
10038 | isAttr: true,
|
10039 | type: "String",
|
10040 | isId: true
|
10041 | },
|
10042 | {
|
10043 | name: "documentation",
|
10044 | type: "Documentation",
|
10045 | isMany: true
|
10046 | },
|
10047 | {
|
10048 | name: "extensionDefinitions",
|
10049 | type: "ExtensionDefinition",
|
10050 | isMany: true,
|
10051 | isReference: true
|
10052 | },
|
10053 | {
|
10054 | name: "extensionElements",
|
10055 | type: "ExtensionElements"
|
10056 | }
|
10057 | ]
|
10058 | },
|
10059 | {
|
10060 | name: "Extension",
|
10061 | properties: [
|
10062 | {
|
10063 | name: "mustUnderstand",
|
10064 | "default": false,
|
10065 | isAttr: true,
|
10066 | type: "Boolean"
|
10067 | },
|
10068 | {
|
10069 | name: "definition",
|
10070 | type: "ExtensionDefinition",
|
10071 | isAttr: true,
|
10072 | isReference: true
|
10073 | }
|
10074 | ]
|
10075 | },
|
10076 | {
|
10077 | name: "ExtensionDefinition",
|
10078 | properties: [
|
10079 | {
|
10080 | name: "name",
|
10081 | isAttr: true,
|
10082 | type: "String"
|
10083 | },
|
10084 | {
|
10085 | name: "extensionAttributeDefinitions",
|
10086 | type: "ExtensionAttributeDefinition",
|
10087 | isMany: true
|
10088 | }
|
10089 | ]
|
10090 | },
|
10091 | {
|
10092 | name: "ExtensionAttributeDefinition",
|
10093 | properties: [
|
10094 | {
|
10095 | name: "name",
|
10096 | isAttr: true,
|
10097 | type: "String"
|
10098 | },
|
10099 | {
|
10100 | name: "type",
|
10101 | isAttr: true,
|
10102 | type: "String"
|
10103 | },
|
10104 | {
|
10105 | name: "isReference",
|
10106 | "default": false,
|
10107 | isAttr: true,
|
10108 | type: "Boolean"
|
10109 | },
|
10110 | {
|
10111 | name: "extensionDefinition",
|
10112 | type: "ExtensionDefinition",
|
10113 | isAttr: true,
|
10114 | isReference: true
|
10115 | }
|
10116 | ]
|
10117 | },
|
10118 | {
|
10119 | name: "ExtensionElements",
|
10120 | properties: [
|
10121 | {
|
10122 | name: "valueRef",
|
10123 | isAttr: true,
|
10124 | isReference: true,
|
10125 | type: "Element"
|
10126 | },
|
10127 | {
|
10128 | name: "values",
|
10129 | type: "Element",
|
10130 | isMany: true
|
10131 | },
|
10132 | {
|
10133 | name: "extensionAttributeDefinition",
|
10134 | type: "ExtensionAttributeDefinition",
|
10135 | isAttr: true,
|
10136 | isReference: true
|
10137 | }
|
10138 | ]
|
10139 | },
|
10140 | {
|
10141 | name: "Documentation",
|
10142 | superClass: [
|
10143 | "BaseElement"
|
10144 | ],
|
10145 | properties: [
|
10146 | {
|
10147 | name: "text",
|
10148 | type: "String",
|
10149 | isBody: true
|
10150 | },
|
10151 | {
|
10152 | name: "textFormat",
|
10153 | "default": "text/plain",
|
10154 | isAttr: true,
|
10155 | type: "String"
|
10156 | }
|
10157 | ]
|
10158 | },
|
10159 | {
|
10160 | name: "Event",
|
10161 | isAbstract: true,
|
10162 | superClass: [
|
10163 | "FlowNode",
|
10164 | "InteractionNode"
|
10165 | ],
|
10166 | properties: [
|
10167 | {
|
10168 | name: "properties",
|
10169 | type: "Property",
|
10170 | isMany: true
|
10171 | }
|
10172 | ]
|
10173 | },
|
10174 | {
|
10175 | name: "IntermediateCatchEvent",
|
10176 | superClass: [
|
10177 | "CatchEvent"
|
10178 | ]
|
10179 | },
|
10180 | {
|
10181 | name: "IntermediateThrowEvent",
|
10182 | superClass: [
|
10183 | "ThrowEvent"
|
10184 | ]
|
10185 | },
|
10186 | {
|
10187 | name: "EndEvent",
|
10188 | superClass: [
|
10189 | "ThrowEvent"
|
10190 | ]
|
10191 | },
|
10192 | {
|
10193 | name: "StartEvent",
|
10194 | superClass: [
|
10195 | "CatchEvent"
|
10196 | ],
|
10197 | properties: [
|
10198 | {
|
10199 | name: "isInterrupting",
|
10200 | "default": true,
|
10201 | isAttr: true,
|
10202 | type: "Boolean"
|
10203 | }
|
10204 | ]
|
10205 | },
|
10206 | {
|
10207 | name: "ThrowEvent",
|
10208 | isAbstract: true,
|
10209 | superClass: [
|
10210 | "Event"
|
10211 | ],
|
10212 | properties: [
|
10213 | {
|
10214 | name: "dataInputs",
|
10215 | type: "DataInput",
|
10216 | isMany: true
|
10217 | },
|
10218 | {
|
10219 | name: "dataInputAssociations",
|
10220 | type: "DataInputAssociation",
|
10221 | isMany: true
|
10222 | },
|
10223 | {
|
10224 | name: "inputSet",
|
10225 | type: "InputSet"
|
10226 | },
|
10227 | {
|
10228 | name: "eventDefinitions",
|
10229 | type: "EventDefinition",
|
10230 | isMany: true
|
10231 | },
|
10232 | {
|
10233 | name: "eventDefinitionRef",
|
10234 | type: "EventDefinition",
|
10235 | isMany: true,
|
10236 | isReference: true
|
10237 | }
|
10238 | ]
|
10239 | },
|
10240 | {
|
10241 | name: "CatchEvent",
|
10242 | isAbstract: true,
|
10243 | superClass: [
|
10244 | "Event"
|
10245 | ],
|
10246 | properties: [
|
10247 | {
|
10248 | name: "parallelMultiple",
|
10249 | isAttr: true,
|
10250 | type: "Boolean",
|
10251 | "default": false
|
10252 | },
|
10253 | {
|
10254 | name: "dataOutputs",
|
10255 | type: "DataOutput",
|
10256 | isMany: true
|
10257 | },
|
10258 | {
|
10259 | name: "dataOutputAssociations",
|
10260 | type: "DataOutputAssociation",
|
10261 | isMany: true
|
10262 | },
|
10263 | {
|
10264 | name: "outputSet",
|
10265 | type: "OutputSet"
|
10266 | },
|
10267 | {
|
10268 | name: "eventDefinitions",
|
10269 | type: "EventDefinition",
|
10270 | isMany: true
|
10271 | },
|
10272 | {
|
10273 | name: "eventDefinitionRef",
|
10274 | type: "EventDefinition",
|
10275 | isMany: true,
|
10276 | isReference: true
|
10277 | }
|
10278 | ]
|
10279 | },
|
10280 | {
|
10281 | name: "BoundaryEvent",
|
10282 | superClass: [
|
10283 | "CatchEvent"
|
10284 | ],
|
10285 | properties: [
|
10286 | {
|
10287 | name: "cancelActivity",
|
10288 | "default": true,
|
10289 | isAttr: true,
|
10290 | type: "Boolean"
|
10291 | },
|
10292 | {
|
10293 | name: "attachedToRef",
|
10294 | type: "Activity",
|
10295 | isAttr: true,
|
10296 | isReference: true
|
10297 | }
|
10298 | ]
|
10299 | },
|
10300 | {
|
10301 | name: "EventDefinition",
|
10302 | isAbstract: true,
|
10303 | superClass: [
|
10304 | "RootElement"
|
10305 | ]
|
10306 | },
|
10307 | {
|
10308 | name: "CancelEventDefinition",
|
10309 | superClass: [
|
10310 | "EventDefinition"
|
10311 | ]
|
10312 | },
|
10313 | {
|
10314 | name: "ErrorEventDefinition",
|
10315 | superClass: [
|
10316 | "EventDefinition"
|
10317 | ],
|
10318 | properties: [
|
10319 | {
|
10320 | name: "errorRef",
|
10321 | type: "Error",
|
10322 | isAttr: true,
|
10323 | isReference: true
|
10324 | }
|
10325 | ]
|
10326 | },
|
10327 | {
|
10328 | name: "TerminateEventDefinition",
|
10329 | superClass: [
|
10330 | "EventDefinition"
|
10331 | ]
|
10332 | },
|
10333 | {
|
10334 | name: "EscalationEventDefinition",
|
10335 | superClass: [
|
10336 | "EventDefinition"
|
10337 | ],
|
10338 | properties: [
|
10339 | {
|
10340 | name: "escalationRef",
|
10341 | type: "Escalation",
|
10342 | isAttr: true,
|
10343 | isReference: true
|
10344 | }
|
10345 | ]
|
10346 | },
|
10347 | {
|
10348 | name: "Escalation",
|
10349 | properties: [
|
10350 | {
|
10351 | name: "structureRef",
|
10352 | type: "ItemDefinition",
|
10353 | isAttr: true,
|
10354 | isReference: true
|
10355 | },
|
10356 | {
|
10357 | name: "name",
|
10358 | isAttr: true,
|
10359 | type: "String"
|
10360 | },
|
10361 | {
|
10362 | name: "escalationCode",
|
10363 | isAttr: true,
|
10364 | type: "String"
|
10365 | }
|
10366 | ],
|
10367 | superClass: [
|
10368 | "RootElement"
|
10369 | ]
|
10370 | },
|
10371 | {
|
10372 | name: "CompensateEventDefinition",
|
10373 | superClass: [
|
10374 | "EventDefinition"
|
10375 | ],
|
10376 | properties: [
|
10377 | {
|
10378 | name: "waitForCompletion",
|
10379 | isAttr: true,
|
10380 | type: "Boolean",
|
10381 | "default": true
|
10382 | },
|
10383 | {
|
10384 | name: "activityRef",
|
10385 | type: "Activity",
|
10386 | isAttr: true,
|
10387 | isReference: true
|
10388 | }
|
10389 | ]
|
10390 | },
|
10391 | {
|
10392 | name: "TimerEventDefinition",
|
10393 | superClass: [
|
10394 | "EventDefinition"
|
10395 | ],
|
10396 | properties: [
|
10397 | {
|
10398 | name: "timeDate",
|
10399 | type: "Expression",
|
10400 | xml: {
|
10401 | serialize: "xsi:type"
|
10402 | }
|
10403 | },
|
10404 | {
|
10405 | name: "timeCycle",
|
10406 | type: "Expression",
|
10407 | xml: {
|
10408 | serialize: "xsi:type"
|
10409 | }
|
10410 | },
|
10411 | {
|
10412 | name: "timeDuration",
|
10413 | type: "Expression",
|
10414 | xml: {
|
10415 | serialize: "xsi:type"
|
10416 | }
|
10417 | }
|
10418 | ]
|
10419 | },
|
10420 | {
|
10421 | name: "LinkEventDefinition",
|
10422 | superClass: [
|
10423 | "EventDefinition"
|
10424 | ],
|
10425 | properties: [
|
10426 | {
|
10427 | name: "name",
|
10428 | isAttr: true,
|
10429 | type: "String"
|
10430 | },
|
10431 | {
|
10432 | name: "target",
|
10433 | type: "LinkEventDefinition",
|
10434 | isAttr: true,
|
10435 | isReference: true
|
10436 | },
|
10437 | {
|
10438 | name: "source",
|
10439 | type: "LinkEventDefinition",
|
10440 | isMany: true,
|
10441 | isReference: true
|
10442 | }
|
10443 | ]
|
10444 | },
|
10445 | {
|
10446 | name: "MessageEventDefinition",
|
10447 | superClass: [
|
10448 | "EventDefinition"
|
10449 | ],
|
10450 | properties: [
|
10451 | {
|
10452 | name: "messageRef",
|
10453 | type: "Message",
|
10454 | isAttr: true,
|
10455 | isReference: true
|
10456 | },
|
10457 | {
|
10458 | name: "operationRef",
|
10459 | type: "Operation",
|
10460 | isAttr: true,
|
10461 | isReference: true
|
10462 | }
|
10463 | ]
|
10464 | },
|
10465 | {
|
10466 | name: "ConditionalEventDefinition",
|
10467 | superClass: [
|
10468 | "EventDefinition"
|
10469 | ],
|
10470 | properties: [
|
10471 | {
|
10472 | name: "condition",
|
10473 | type: "Expression",
|
10474 | xml: {
|
10475 | serialize: "xsi:type"
|
10476 | }
|
10477 | }
|
10478 | ]
|
10479 | },
|
10480 | {
|
10481 | name: "SignalEventDefinition",
|
10482 | superClass: [
|
10483 | "EventDefinition"
|
10484 | ],
|
10485 | properties: [
|
10486 | {
|
10487 | name: "signalRef",
|
10488 | type: "Signal",
|
10489 | isAttr: true,
|
10490 | isReference: true
|
10491 | }
|
10492 | ]
|
10493 | },
|
10494 | {
|
10495 | name: "Signal",
|
10496 | superClass: [
|
10497 | "RootElement"
|
10498 | ],
|
10499 | properties: [
|
10500 | {
|
10501 | name: "structureRef",
|
10502 | type: "ItemDefinition",
|
10503 | isAttr: true,
|
10504 | isReference: true
|
10505 | },
|
10506 | {
|
10507 | name: "name",
|
10508 | isAttr: true,
|
10509 | type: "String"
|
10510 | }
|
10511 | ]
|
10512 | },
|
10513 | {
|
10514 | name: "ImplicitThrowEvent",
|
10515 | superClass: [
|
10516 | "ThrowEvent"
|
10517 | ]
|
10518 | },
|
10519 | {
|
10520 | name: "DataState",
|
10521 | superClass: [
|
10522 | "BaseElement"
|
10523 | ],
|
10524 | properties: [
|
10525 | {
|
10526 | name: "name",
|
10527 | isAttr: true,
|
10528 | type: "String"
|
10529 | }
|
10530 | ]
|
10531 | },
|
10532 | {
|
10533 | name: "ItemAwareElement",
|
10534 | superClass: [
|
10535 | "BaseElement"
|
10536 | ],
|
10537 | properties: [
|
10538 | {
|
10539 | name: "itemSubjectRef",
|
10540 | type: "ItemDefinition",
|
10541 | isAttr: true,
|
10542 | isReference: true
|
10543 | },
|
10544 | {
|
10545 | name: "dataState",
|
10546 | type: "DataState"
|
10547 | }
|
10548 | ]
|
10549 | },
|
10550 | {
|
10551 | name: "DataAssociation",
|
10552 | superClass: [
|
10553 | "BaseElement"
|
10554 | ],
|
10555 | properties: [
|
10556 | {
|
10557 | name: "assignment",
|
10558 | type: "Assignment",
|
10559 | isMany: true
|
10560 | },
|
10561 | {
|
10562 | name: "sourceRef",
|
10563 | type: "ItemAwareElement",
|
10564 | isMany: true,
|
10565 | isReference: true
|
10566 | },
|
10567 | {
|
10568 | name: "targetRef",
|
10569 | type: "ItemAwareElement",
|
10570 | isReference: true
|
10571 | },
|
10572 | {
|
10573 | name: "transformation",
|
10574 | type: "FormalExpression",
|
10575 | xml: {
|
10576 | serialize: "property"
|
10577 | }
|
10578 | }
|
10579 | ]
|
10580 | },
|
10581 | {
|
10582 | name: "DataInput",
|
10583 | superClass: [
|
10584 | "ItemAwareElement"
|
10585 | ],
|
10586 | properties: [
|
10587 | {
|
10588 | name: "name",
|
10589 | isAttr: true,
|
10590 | type: "String"
|
10591 | },
|
10592 | {
|
10593 | name: "isCollection",
|
10594 | "default": false,
|
10595 | isAttr: true,
|
10596 | type: "Boolean"
|
10597 | },
|
10598 | {
|
10599 | name: "inputSetRef",
|
10600 | type: "InputSet",
|
10601 | isVirtual: true,
|
10602 | isMany: true,
|
10603 | isReference: true
|
10604 | },
|
10605 | {
|
10606 | name: "inputSetWithOptional",
|
10607 | type: "InputSet",
|
10608 | isVirtual: true,
|
10609 | isMany: true,
|
10610 | isReference: true
|
10611 | },
|
10612 | {
|
10613 | name: "inputSetWithWhileExecuting",
|
10614 | type: "InputSet",
|
10615 | isVirtual: true,
|
10616 | isMany: true,
|
10617 | isReference: true
|
10618 | }
|
10619 | ]
|
10620 | },
|
10621 | {
|
10622 | name: "DataOutput",
|
10623 | superClass: [
|
10624 | "ItemAwareElement"
|
10625 | ],
|
10626 | properties: [
|
10627 | {
|
10628 | name: "name",
|
10629 | isAttr: true,
|
10630 | type: "String"
|
10631 | },
|
10632 | {
|
10633 | name: "isCollection",
|
10634 | "default": false,
|
10635 | isAttr: true,
|
10636 | type: "Boolean"
|
10637 | },
|
10638 | {
|
10639 | name: "outputSetRef",
|
10640 | type: "OutputSet",
|
10641 | isVirtual: true,
|
10642 | isMany: true,
|
10643 | isReference: true
|
10644 | },
|
10645 | {
|
10646 | name: "outputSetWithOptional",
|
10647 | type: "OutputSet",
|
10648 | isVirtual: true,
|
10649 | isMany: true,
|
10650 | isReference: true
|
10651 | },
|
10652 | {
|
10653 | name: "outputSetWithWhileExecuting",
|
10654 | type: "OutputSet",
|
10655 | isVirtual: true,
|
10656 | isMany: true,
|
10657 | isReference: true
|
10658 | }
|
10659 | ]
|
10660 | },
|
10661 | {
|
10662 | name: "InputSet",
|
10663 | superClass: [
|
10664 | "BaseElement"
|
10665 | ],
|
10666 | properties: [
|
10667 | {
|
10668 | name: "name",
|
10669 | isAttr: true,
|
10670 | type: "String"
|
10671 | },
|
10672 | {
|
10673 | name: "dataInputRefs",
|
10674 | type: "DataInput",
|
10675 | isMany: true,
|
10676 | isReference: true
|
10677 | },
|
10678 | {
|
10679 | name: "optionalInputRefs",
|
10680 | type: "DataInput",
|
10681 | isMany: true,
|
10682 | isReference: true
|
10683 | },
|
10684 | {
|
10685 | name: "whileExecutingInputRefs",
|
10686 | type: "DataInput",
|
10687 | isMany: true,
|
10688 | isReference: true
|
10689 | },
|
10690 | {
|
10691 | name: "outputSetRefs",
|
10692 | type: "OutputSet",
|
10693 | isMany: true,
|
10694 | isReference: true
|
10695 | }
|
10696 | ]
|
10697 | },
|
10698 | {
|
10699 | name: "OutputSet",
|
10700 | superClass: [
|
10701 | "BaseElement"
|
10702 | ],
|
10703 | properties: [
|
10704 | {
|
10705 | name: "dataOutputRefs",
|
10706 | type: "DataOutput",
|
10707 | isMany: true,
|
10708 | isReference: true
|
10709 | },
|
10710 | {
|
10711 | name: "name",
|
10712 | isAttr: true,
|
10713 | type: "String"
|
10714 | },
|
10715 | {
|
10716 | name: "inputSetRefs",
|
10717 | type: "InputSet",
|
10718 | isMany: true,
|
10719 | isReference: true
|
10720 | },
|
10721 | {
|
10722 | name: "optionalOutputRefs",
|
10723 | type: "DataOutput",
|
10724 | isMany: true,
|
10725 | isReference: true
|
10726 | },
|
10727 | {
|
10728 | name: "whileExecutingOutputRefs",
|
10729 | type: "DataOutput",
|
10730 | isMany: true,
|
10731 | isReference: true
|
10732 | }
|
10733 | ]
|
10734 | },
|
10735 | {
|
10736 | name: "Property",
|
10737 | superClass: [
|
10738 | "ItemAwareElement"
|
10739 | ],
|
10740 | properties: [
|
10741 | {
|
10742 | name: "name",
|
10743 | isAttr: true,
|
10744 | type: "String"
|
10745 | }
|
10746 | ]
|
10747 | },
|
10748 | {
|
10749 | name: "DataInputAssociation",
|
10750 | superClass: [
|
10751 | "DataAssociation"
|
10752 | ]
|
10753 | },
|
10754 | {
|
10755 | name: "DataOutputAssociation",
|
10756 | superClass: [
|
10757 | "DataAssociation"
|
10758 | ]
|
10759 | },
|
10760 | {
|
10761 | name: "InputOutputSpecification",
|
10762 | superClass: [
|
10763 | "BaseElement"
|
10764 | ],
|
10765 | properties: [
|
10766 | {
|
10767 | name: "dataInputs",
|
10768 | type: "DataInput",
|
10769 | isMany: true
|
10770 | },
|
10771 | {
|
10772 | name: "dataOutputs",
|
10773 | type: "DataOutput",
|
10774 | isMany: true
|
10775 | },
|
10776 | {
|
10777 | name: "inputSets",
|
10778 | type: "InputSet",
|
10779 | isMany: true
|
10780 | },
|
10781 | {
|
10782 | name: "outputSets",
|
10783 | type: "OutputSet",
|
10784 | isMany: true
|
10785 | }
|
10786 | ]
|
10787 | },
|
10788 | {
|
10789 | name: "DataObject",
|
10790 | superClass: [
|
10791 | "FlowElement",
|
10792 | "ItemAwareElement"
|
10793 | ],
|
10794 | properties: [
|
10795 | {
|
10796 | name: "isCollection",
|
10797 | "default": false,
|
10798 | isAttr: true,
|
10799 | type: "Boolean"
|
10800 | }
|
10801 | ]
|
10802 | },
|
10803 | {
|
10804 | name: "InputOutputBinding",
|
10805 | properties: [
|
10806 | {
|
10807 | name: "inputDataRef",
|
10808 | type: "InputSet",
|
10809 | isAttr: true,
|
10810 | isReference: true
|
10811 | },
|
10812 | {
|
10813 | name: "outputDataRef",
|
10814 | type: "OutputSet",
|
10815 | isAttr: true,
|
10816 | isReference: true
|
10817 | },
|
10818 | {
|
10819 | name: "operationRef",
|
10820 | type: "Operation",
|
10821 | isAttr: true,
|
10822 | isReference: true
|
10823 | }
|
10824 | ]
|
10825 | },
|
10826 | {
|
10827 | name: "Assignment",
|
10828 | superClass: [
|
10829 | "BaseElement"
|
10830 | ],
|
10831 | properties: [
|
10832 | {
|
10833 | name: "from",
|
10834 | type: "Expression",
|
10835 | xml: {
|
10836 | serialize: "xsi:type"
|
10837 | }
|
10838 | },
|
10839 | {
|
10840 | name: "to",
|
10841 | type: "Expression",
|
10842 | xml: {
|
10843 | serialize: "xsi:type"
|
10844 | }
|
10845 | }
|
10846 | ]
|
10847 | },
|
10848 | {
|
10849 | name: "DataStore",
|
10850 | superClass: [
|
10851 | "RootElement",
|
10852 | "ItemAwareElement"
|
10853 | ],
|
10854 | properties: [
|
10855 | {
|
10856 | name: "name",
|
10857 | isAttr: true,
|
10858 | type: "String"
|
10859 | },
|
10860 | {
|
10861 | name: "capacity",
|
10862 | isAttr: true,
|
10863 | type: "Integer"
|
10864 | },
|
10865 | {
|
10866 | name: "isUnlimited",
|
10867 | "default": true,
|
10868 | isAttr: true,
|
10869 | type: "Boolean"
|
10870 | }
|
10871 | ]
|
10872 | },
|
10873 | {
|
10874 | name: "DataStoreReference",
|
10875 | superClass: [
|
10876 | "ItemAwareElement",
|
10877 | "FlowElement"
|
10878 | ],
|
10879 | properties: [
|
10880 | {
|
10881 | name: "dataStoreRef",
|
10882 | type: "DataStore",
|
10883 | isAttr: true,
|
10884 | isReference: true
|
10885 | }
|
10886 | ]
|
10887 | },
|
10888 | {
|
10889 | name: "DataObjectReference",
|
10890 | superClass: [
|
10891 | "ItemAwareElement",
|
10892 | "FlowElement"
|
10893 | ],
|
10894 | properties: [
|
10895 | {
|
10896 | name: "dataObjectRef",
|
10897 | type: "DataObject",
|
10898 | isAttr: true,
|
10899 | isReference: true
|
10900 | }
|
10901 | ]
|
10902 | },
|
10903 | {
|
10904 | name: "ConversationLink",
|
10905 | superClass: [
|
10906 | "BaseElement"
|
10907 | ],
|
10908 | properties: [
|
10909 | {
|
10910 | name: "sourceRef",
|
10911 | type: "InteractionNode",
|
10912 | isAttr: true,
|
10913 | isReference: true
|
10914 | },
|
10915 | {
|
10916 | name: "targetRef",
|
10917 | type: "InteractionNode",
|
10918 | isAttr: true,
|
10919 | isReference: true
|
10920 | },
|
10921 | {
|
10922 | name: "name",
|
10923 | isAttr: true,
|
10924 | type: "String"
|
10925 | }
|
10926 | ]
|
10927 | },
|
10928 | {
|
10929 | name: "ConversationAssociation",
|
10930 | superClass: [
|
10931 | "BaseElement"
|
10932 | ],
|
10933 | properties: [
|
10934 | {
|
10935 | name: "innerConversationNodeRef",
|
10936 | type: "ConversationNode",
|
10937 | isAttr: true,
|
10938 | isReference: true
|
10939 | },
|
10940 | {
|
10941 | name: "outerConversationNodeRef",
|
10942 | type: "ConversationNode",
|
10943 | isAttr: true,
|
10944 | isReference: true
|
10945 | }
|
10946 | ]
|
10947 | },
|
10948 | {
|
10949 | name: "CallConversation",
|
10950 | superClass: [
|
10951 | "ConversationNode"
|
10952 | ],
|
10953 | properties: [
|
10954 | {
|
10955 | name: "calledCollaborationRef",
|
10956 | type: "Collaboration",
|
10957 | isAttr: true,
|
10958 | isReference: true
|
10959 | },
|
10960 | {
|
10961 | name: "participantAssociations",
|
10962 | type: "ParticipantAssociation",
|
10963 | isMany: true
|
10964 | }
|
10965 | ]
|
10966 | },
|
10967 | {
|
10968 | name: "Conversation",
|
10969 | superClass: [
|
10970 | "ConversationNode"
|
10971 | ]
|
10972 | },
|
10973 | {
|
10974 | name: "SubConversation",
|
10975 | superClass: [
|
10976 | "ConversationNode"
|
10977 | ],
|
10978 | properties: [
|
10979 | {
|
10980 | name: "conversationNodes",
|
10981 | type: "ConversationNode",
|
10982 | isMany: true
|
10983 | }
|
10984 | ]
|
10985 | },
|
10986 | {
|
10987 | name: "ConversationNode",
|
10988 | isAbstract: true,
|
10989 | superClass: [
|
10990 | "InteractionNode",
|
10991 | "BaseElement"
|
10992 | ],
|
10993 | properties: [
|
10994 | {
|
10995 | name: "name",
|
10996 | isAttr: true,
|
10997 | type: "String"
|
10998 | },
|
10999 | {
|
11000 | name: "participantRef",
|
11001 | type: "Participant",
|
11002 | isMany: true,
|
11003 | isReference: true
|
11004 | },
|
11005 | {
|
11006 | name: "messageFlowRefs",
|
11007 | type: "MessageFlow",
|
11008 | isMany: true,
|
11009 | isReference: true
|
11010 | },
|
11011 | {
|
11012 | name: "correlationKeys",
|
11013 | type: "CorrelationKey",
|
11014 | isMany: true
|
11015 | }
|
11016 | ]
|
11017 | },
|
11018 | {
|
11019 | name: "GlobalConversation",
|
11020 | superClass: [
|
11021 | "Collaboration"
|
11022 | ]
|
11023 | },
|
11024 | {
|
11025 | name: "PartnerEntity",
|
11026 | superClass: [
|
11027 | "RootElement"
|
11028 | ],
|
11029 | properties: [
|
11030 | {
|
11031 | name: "name",
|
11032 | isAttr: true,
|
11033 | type: "String"
|
11034 | },
|
11035 | {
|
11036 | name: "participantRef",
|
11037 | type: "Participant",
|
11038 | isMany: true,
|
11039 | isReference: true
|
11040 | }
|
11041 | ]
|
11042 | },
|
11043 | {
|
11044 | name: "PartnerRole",
|
11045 | superClass: [
|
11046 | "RootElement"
|
11047 | ],
|
11048 | properties: [
|
11049 | {
|
11050 | name: "name",
|
11051 | isAttr: true,
|
11052 | type: "String"
|
11053 | },
|
11054 | {
|
11055 | name: "participantRef",
|
11056 | type: "Participant",
|
11057 | isMany: true,
|
11058 | isReference: true
|
11059 | }
|
11060 | ]
|
11061 | },
|
11062 | {
|
11063 | name: "CorrelationProperty",
|
11064 | superClass: [
|
11065 | "RootElement"
|
11066 | ],
|
11067 | properties: [
|
11068 | {
|
11069 | name: "correlationPropertyRetrievalExpression",
|
11070 | type: "CorrelationPropertyRetrievalExpression",
|
11071 | isMany: true
|
11072 | },
|
11073 | {
|
11074 | name: "name",
|
11075 | isAttr: true,
|
11076 | type: "String"
|
11077 | },
|
11078 | {
|
11079 | name: "type",
|
11080 | type: "ItemDefinition",
|
11081 | isAttr: true,
|
11082 | isReference: true
|
11083 | }
|
11084 | ]
|
11085 | },
|
11086 | {
|
11087 | name: "Error",
|
11088 | superClass: [
|
11089 | "RootElement"
|
11090 | ],
|
11091 | properties: [
|
11092 | {
|
11093 | name: "structureRef",
|
11094 | type: "ItemDefinition",
|
11095 | isAttr: true,
|
11096 | isReference: true
|
11097 | },
|
11098 | {
|
11099 | name: "name",
|
11100 | isAttr: true,
|
11101 | type: "String"
|
11102 | },
|
11103 | {
|
11104 | name: "errorCode",
|
11105 | isAttr: true,
|
11106 | type: "String"
|
11107 | }
|
11108 | ]
|
11109 | },
|
11110 | {
|
11111 | name: "CorrelationKey",
|
11112 | superClass: [
|
11113 | "BaseElement"
|
11114 | ],
|
11115 | properties: [
|
11116 | {
|
11117 | name: "correlationPropertyRef",
|
11118 | type: "CorrelationProperty",
|
11119 | isMany: true,
|
11120 | isReference: true
|
11121 | },
|
11122 | {
|
11123 | name: "name",
|
11124 | isAttr: true,
|
11125 | type: "String"
|
11126 | }
|
11127 | ]
|
11128 | },
|
11129 | {
|
11130 | name: "Expression",
|
11131 | superClass: [
|
11132 | "BaseElement"
|
11133 | ],
|
11134 | isAbstract: false,
|
11135 | properties: [
|
11136 | {
|
11137 | name: "body",
|
11138 | type: "String",
|
11139 | isBody: true
|
11140 | }
|
11141 | ]
|
11142 | },
|
11143 | {
|
11144 | name: "FormalExpression",
|
11145 | superClass: [
|
11146 | "Expression"
|
11147 | ],
|
11148 | properties: [
|
11149 | {
|
11150 | name: "language",
|
11151 | isAttr: true,
|
11152 | type: "String"
|
11153 | },
|
11154 | {
|
11155 | name: "evaluatesToTypeRef",
|
11156 | type: "ItemDefinition",
|
11157 | isAttr: true,
|
11158 | isReference: true
|
11159 | }
|
11160 | ]
|
11161 | },
|
11162 | {
|
11163 | name: "Message",
|
11164 | superClass: [
|
11165 | "RootElement"
|
11166 | ],
|
11167 | properties: [
|
11168 | {
|
11169 | name: "name",
|
11170 | isAttr: true,
|
11171 | type: "String"
|
11172 | },
|
11173 | {
|
11174 | name: "itemRef",
|
11175 | type: "ItemDefinition",
|
11176 | isAttr: true,
|
11177 | isReference: true
|
11178 | }
|
11179 | ]
|
11180 | },
|
11181 | {
|
11182 | name: "ItemDefinition",
|
11183 | superClass: [
|
11184 | "RootElement"
|
11185 | ],
|
11186 | properties: [
|
11187 | {
|
11188 | name: "itemKind",
|
11189 | type: "ItemKind",
|
11190 | isAttr: true
|
11191 | },
|
11192 | {
|
11193 | name: "structureRef",
|
11194 | type: "String",
|
11195 | isAttr: true
|
11196 | },
|
11197 | {
|
11198 | name: "isCollection",
|
11199 | "default": false,
|
11200 | isAttr: true,
|
11201 | type: "Boolean"
|
11202 | },
|
11203 | {
|
11204 | name: "import",
|
11205 | type: "Import",
|
11206 | isAttr: true,
|
11207 | isReference: true
|
11208 | }
|
11209 | ]
|
11210 | },
|
11211 | {
|
11212 | name: "FlowElement",
|
11213 | isAbstract: true,
|
11214 | superClass: [
|
11215 | "BaseElement"
|
11216 | ],
|
11217 | properties: [
|
11218 | {
|
11219 | name: "name",
|
11220 | isAttr: true,
|
11221 | type: "String"
|
11222 | },
|
11223 | {
|
11224 | name: "auditing",
|
11225 | type: "Auditing"
|
11226 | },
|
11227 | {
|
11228 | name: "monitoring",
|
11229 | type: "Monitoring"
|
11230 | },
|
11231 | {
|
11232 | name: "categoryValueRef",
|
11233 | type: "CategoryValue",
|
11234 | isMany: true,
|
11235 | isReference: true
|
11236 | }
|
11237 | ]
|
11238 | },
|
11239 | {
|
11240 | name: "SequenceFlow",
|
11241 | superClass: [
|
11242 | "FlowElement"
|
11243 | ],
|
11244 | properties: [
|
11245 | {
|
11246 | name: "isImmediate",
|
11247 | isAttr: true,
|
11248 | type: "Boolean"
|
11249 | },
|
11250 | {
|
11251 | name: "conditionExpression",
|
11252 | type: "Expression",
|
11253 | xml: {
|
11254 | serialize: "xsi:type"
|
11255 | }
|
11256 | },
|
11257 | {
|
11258 | name: "sourceRef",
|
11259 | type: "FlowNode",
|
11260 | isAttr: true,
|
11261 | isReference: true
|
11262 | },
|
11263 | {
|
11264 | name: "targetRef",
|
11265 | type: "FlowNode",
|
11266 | isAttr: true,
|
11267 | isReference: true
|
11268 | }
|
11269 | ]
|
11270 | },
|
11271 | {
|
11272 | name: "FlowElementsContainer",
|
11273 | isAbstract: true,
|
11274 | superClass: [
|
11275 | "BaseElement"
|
11276 | ],
|
11277 | properties: [
|
11278 | {
|
11279 | name: "laneSets",
|
11280 | type: "LaneSet",
|
11281 | isMany: true
|
11282 | },
|
11283 | {
|
11284 | name: "flowElements",
|
11285 | type: "FlowElement",
|
11286 | isMany: true
|
11287 | }
|
11288 | ]
|
11289 | },
|
11290 | {
|
11291 | name: "CallableElement",
|
11292 | isAbstract: true,
|
11293 | superClass: [
|
11294 | "RootElement"
|
11295 | ],
|
11296 | properties: [
|
11297 | {
|
11298 | name: "name",
|
11299 | isAttr: true,
|
11300 | type: "String"
|
11301 | },
|
11302 | {
|
11303 | name: "ioSpecification",
|
11304 | type: "InputOutputSpecification",
|
11305 | xml: {
|
11306 | serialize: "property"
|
11307 | }
|
11308 | },
|
11309 | {
|
11310 | name: "supportedInterfaceRef",
|
11311 | type: "Interface",
|
11312 | isMany: true,
|
11313 | isReference: true
|
11314 | },
|
11315 | {
|
11316 | name: "ioBinding",
|
11317 | type: "InputOutputBinding",
|
11318 | isMany: true,
|
11319 | xml: {
|
11320 | serialize: "property"
|
11321 | }
|
11322 | }
|
11323 | ]
|
11324 | },
|
11325 | {
|
11326 | name: "FlowNode",
|
11327 | isAbstract: true,
|
11328 | superClass: [
|
11329 | "FlowElement"
|
11330 | ],
|
11331 | properties: [
|
11332 | {
|
11333 | name: "incoming",
|
11334 | type: "SequenceFlow",
|
11335 | isMany: true,
|
11336 | isReference: true
|
11337 | },
|
11338 | {
|
11339 | name: "outgoing",
|
11340 | type: "SequenceFlow",
|
11341 | isMany: true,
|
11342 | isReference: true
|
11343 | },
|
11344 | {
|
11345 | name: "lanes",
|
11346 | type: "Lane",
|
11347 | isVirtual: true,
|
11348 | isMany: true,
|
11349 | isReference: true
|
11350 | }
|
11351 | ]
|
11352 | },
|
11353 | {
|
11354 | name: "CorrelationPropertyRetrievalExpression",
|
11355 | superClass: [
|
11356 | "BaseElement"
|
11357 | ],
|
11358 | properties: [
|
11359 | {
|
11360 | name: "messagePath",
|
11361 | type: "FormalExpression"
|
11362 | },
|
11363 | {
|
11364 | name: "messageRef",
|
11365 | type: "Message",
|
11366 | isAttr: true,
|
11367 | isReference: true
|
11368 | }
|
11369 | ]
|
11370 | },
|
11371 | {
|
11372 | name: "CorrelationPropertyBinding",
|
11373 | superClass: [
|
11374 | "BaseElement"
|
11375 | ],
|
11376 | properties: [
|
11377 | {
|
11378 | name: "dataPath",
|
11379 | type: "FormalExpression"
|
11380 | },
|
11381 | {
|
11382 | name: "correlationPropertyRef",
|
11383 | type: "CorrelationProperty",
|
11384 | isAttr: true,
|
11385 | isReference: true
|
11386 | }
|
11387 | ]
|
11388 | },
|
11389 | {
|
11390 | name: "Resource",
|
11391 | superClass: [
|
11392 | "RootElement"
|
11393 | ],
|
11394 | properties: [
|
11395 | {
|
11396 | name: "name",
|
11397 | isAttr: true,
|
11398 | type: "String"
|
11399 | },
|
11400 | {
|
11401 | name: "resourceParameters",
|
11402 | type: "ResourceParameter",
|
11403 | isMany: true
|
11404 | }
|
11405 | ]
|
11406 | },
|
11407 | {
|
11408 | name: "ResourceParameter",
|
11409 | superClass: [
|
11410 | "BaseElement"
|
11411 | ],
|
11412 | properties: [
|
11413 | {
|
11414 | name: "name",
|
11415 | isAttr: true,
|
11416 | type: "String"
|
11417 | },
|
11418 | {
|
11419 | name: "isRequired",
|
11420 | isAttr: true,
|
11421 | type: "Boolean"
|
11422 | },
|
11423 | {
|
11424 | name: "type",
|
11425 | type: "ItemDefinition",
|
11426 | isAttr: true,
|
11427 | isReference: true
|
11428 | }
|
11429 | ]
|
11430 | },
|
11431 | {
|
11432 | name: "CorrelationSubscription",
|
11433 | superClass: [
|
11434 | "BaseElement"
|
11435 | ],
|
11436 | properties: [
|
11437 | {
|
11438 | name: "correlationKeyRef",
|
11439 | type: "CorrelationKey",
|
11440 | isAttr: true,
|
11441 | isReference: true
|
11442 | },
|
11443 | {
|
11444 | name: "correlationPropertyBinding",
|
11445 | type: "CorrelationPropertyBinding",
|
11446 | isMany: true
|
11447 | }
|
11448 | ]
|
11449 | },
|
11450 | {
|
11451 | name: "MessageFlow",
|
11452 | superClass: [
|
11453 | "BaseElement"
|
11454 | ],
|
11455 | properties: [
|
11456 | {
|
11457 | name: "name",
|
11458 | isAttr: true,
|
11459 | type: "String"
|
11460 | },
|
11461 | {
|
11462 | name: "sourceRef",
|
11463 | type: "InteractionNode",
|
11464 | isAttr: true,
|
11465 | isReference: true
|
11466 | },
|
11467 | {
|
11468 | name: "targetRef",
|
11469 | type: "InteractionNode",
|
11470 | isAttr: true,
|
11471 | isReference: true
|
11472 | },
|
11473 | {
|
11474 | name: "messageRef",
|
11475 | type: "Message",
|
11476 | isAttr: true,
|
11477 | isReference: true
|
11478 | }
|
11479 | ]
|
11480 | },
|
11481 | {
|
11482 | name: "MessageFlowAssociation",
|
11483 | superClass: [
|
11484 | "BaseElement"
|
11485 | ],
|
11486 | properties: [
|
11487 | {
|
11488 | name: "innerMessageFlowRef",
|
11489 | type: "MessageFlow",
|
11490 | isAttr: true,
|
11491 | isReference: true
|
11492 | },
|
11493 | {
|
11494 | name: "outerMessageFlowRef",
|
11495 | type: "MessageFlow",
|
11496 | isAttr: true,
|
11497 | isReference: true
|
11498 | }
|
11499 | ]
|
11500 | },
|
11501 | {
|
11502 | name: "InteractionNode",
|
11503 | isAbstract: true,
|
11504 | properties: [
|
11505 | {
|
11506 | name: "incomingConversationLinks",
|
11507 | type: "ConversationLink",
|
11508 | isVirtual: true,
|
11509 | isMany: true,
|
11510 | isReference: true
|
11511 | },
|
11512 | {
|
11513 | name: "outgoingConversationLinks",
|
11514 | type: "ConversationLink",
|
11515 | isVirtual: true,
|
11516 | isMany: true,
|
11517 | isReference: true
|
11518 | }
|
11519 | ]
|
11520 | },
|
11521 | {
|
11522 | name: "Participant",
|
11523 | superClass: [
|
11524 | "InteractionNode",
|
11525 | "BaseElement"
|
11526 | ],
|
11527 | properties: [
|
11528 | {
|
11529 | name: "name",
|
11530 | isAttr: true,
|
11531 | type: "String"
|
11532 | },
|
11533 | {
|
11534 | name: "interfaceRef",
|
11535 | type: "Interface",
|
11536 | isMany: true,
|
11537 | isReference: true
|
11538 | },
|
11539 | {
|
11540 | name: "participantMultiplicity",
|
11541 | type: "ParticipantMultiplicity"
|
11542 | },
|
11543 | {
|
11544 | name: "endPointRefs",
|
11545 | type: "EndPoint",
|
11546 | isMany: true,
|
11547 | isReference: true
|
11548 | },
|
11549 | {
|
11550 | name: "processRef",
|
11551 | type: "Process",
|
11552 | isAttr: true,
|
11553 | isReference: true
|
11554 | }
|
11555 | ]
|
11556 | },
|
11557 | {
|
11558 | name: "ParticipantAssociation",
|
11559 | superClass: [
|
11560 | "BaseElement"
|
11561 | ],
|
11562 | properties: [
|
11563 | {
|
11564 | name: "innerParticipantRef",
|
11565 | type: "Participant",
|
11566 | isAttr: true,
|
11567 | isReference: true
|
11568 | },
|
11569 | {
|
11570 | name: "outerParticipantRef",
|
11571 | type: "Participant",
|
11572 | isAttr: true,
|
11573 | isReference: true
|
11574 | }
|
11575 | ]
|
11576 | },
|
11577 | {
|
11578 | name: "ParticipantMultiplicity",
|
11579 | properties: [
|
11580 | {
|
11581 | name: "minimum",
|
11582 | "default": 0,
|
11583 | isAttr: true,
|
11584 | type: "Integer"
|
11585 | },
|
11586 | {
|
11587 | name: "maximum",
|
11588 | "default": 1,
|
11589 | isAttr: true,
|
11590 | type: "Integer"
|
11591 | }
|
11592 | ],
|
11593 | superClass: [
|
11594 | "BaseElement"
|
11595 | ]
|
11596 | },
|
11597 | {
|
11598 | name: "Collaboration",
|
11599 | superClass: [
|
11600 | "RootElement"
|
11601 | ],
|
11602 | properties: [
|
11603 | {
|
11604 | name: "name",
|
11605 | isAttr: true,
|
11606 | type: "String"
|
11607 | },
|
11608 | {
|
11609 | name: "isClosed",
|
11610 | isAttr: true,
|
11611 | type: "Boolean"
|
11612 | },
|
11613 | {
|
11614 | name: "participants",
|
11615 | type: "Participant",
|
11616 | isMany: true
|
11617 | },
|
11618 | {
|
11619 | name: "messageFlows",
|
11620 | type: "MessageFlow",
|
11621 | isMany: true
|
11622 | },
|
11623 | {
|
11624 | name: "artifacts",
|
11625 | type: "Artifact",
|
11626 | isMany: true
|
11627 | },
|
11628 | {
|
11629 | name: "conversations",
|
11630 | type: "ConversationNode",
|
11631 | isMany: true
|
11632 | },
|
11633 | {
|
11634 | name: "conversationAssociations",
|
11635 | type: "ConversationAssociation"
|
11636 | },
|
11637 | {
|
11638 | name: "participantAssociations",
|
11639 | type: "ParticipantAssociation",
|
11640 | isMany: true
|
11641 | },
|
11642 | {
|
11643 | name: "messageFlowAssociations",
|
11644 | type: "MessageFlowAssociation",
|
11645 | isMany: true
|
11646 | },
|
11647 | {
|
11648 | name: "correlationKeys",
|
11649 | type: "CorrelationKey",
|
11650 | isMany: true
|
11651 | },
|
11652 | {
|
11653 | name: "choreographyRef",
|
11654 | type: "Choreography",
|
11655 | isMany: true,
|
11656 | isReference: true
|
11657 | },
|
11658 | {
|
11659 | name: "conversationLinks",
|
11660 | type: "ConversationLink",
|
11661 | isMany: true
|
11662 | }
|
11663 | ]
|
11664 | },
|
11665 | {
|
11666 | name: "ChoreographyActivity",
|
11667 | isAbstract: true,
|
11668 | superClass: [
|
11669 | "FlowNode"
|
11670 | ],
|
11671 | properties: [
|
11672 | {
|
11673 | name: "participantRef",
|
11674 | type: "Participant",
|
11675 | isMany: true,
|
11676 | isReference: true
|
11677 | },
|
11678 | {
|
11679 | name: "initiatingParticipantRef",
|
11680 | type: "Participant",
|
11681 | isAttr: true,
|
11682 | isReference: true
|
11683 | },
|
11684 | {
|
11685 | name: "correlationKeys",
|
11686 | type: "CorrelationKey",
|
11687 | isMany: true
|
11688 | },
|
11689 | {
|
11690 | name: "loopType",
|
11691 | type: "ChoreographyLoopType",
|
11692 | "default": "None",
|
11693 | isAttr: true
|
11694 | }
|
11695 | ]
|
11696 | },
|
11697 | {
|
11698 | name: "CallChoreography",
|
11699 | superClass: [
|
11700 | "ChoreographyActivity"
|
11701 | ],
|
11702 | properties: [
|
11703 | {
|
11704 | name: "calledChoreographyRef",
|
11705 | type: "Choreography",
|
11706 | isAttr: true,
|
11707 | isReference: true
|
11708 | },
|
11709 | {
|
11710 | name: "participantAssociations",
|
11711 | type: "ParticipantAssociation",
|
11712 | isMany: true
|
11713 | }
|
11714 | ]
|
11715 | },
|
11716 | {
|
11717 | name: "SubChoreography",
|
11718 | superClass: [
|
11719 | "ChoreographyActivity",
|
11720 | "FlowElementsContainer"
|
11721 | ],
|
11722 | properties: [
|
11723 | {
|
11724 | name: "artifacts",
|
11725 | type: "Artifact",
|
11726 | isMany: true
|
11727 | }
|
11728 | ]
|
11729 | },
|
11730 | {
|
11731 | name: "ChoreographyTask",
|
11732 | superClass: [
|
11733 | "ChoreographyActivity"
|
11734 | ],
|
11735 | properties: [
|
11736 | {
|
11737 | name: "messageFlowRef",
|
11738 | type: "MessageFlow",
|
11739 | isMany: true,
|
11740 | isReference: true
|
11741 | }
|
11742 | ]
|
11743 | },
|
11744 | {
|
11745 | name: "Choreography",
|
11746 | superClass: [
|
11747 | "Collaboration",
|
11748 | "FlowElementsContainer"
|
11749 | ]
|
11750 | },
|
11751 | {
|
11752 | name: "GlobalChoreographyTask",
|
11753 | superClass: [
|
11754 | "Choreography"
|
11755 | ],
|
11756 | properties: [
|
11757 | {
|
11758 | name: "initiatingParticipantRef",
|
11759 | type: "Participant",
|
11760 | isAttr: true,
|
11761 | isReference: true
|
11762 | }
|
11763 | ]
|
11764 | },
|
11765 | {
|
11766 | name: "TextAnnotation",
|
11767 | superClass: [
|
11768 | "Artifact"
|
11769 | ],
|
11770 | properties: [
|
11771 | {
|
11772 | name: "text",
|
11773 | type: "String"
|
11774 | },
|
11775 | {
|
11776 | name: "textFormat",
|
11777 | "default": "text/plain",
|
11778 | isAttr: true,
|
11779 | type: "String"
|
11780 | }
|
11781 | ]
|
11782 | },
|
11783 | {
|
11784 | name: "Group",
|
11785 | superClass: [
|
11786 | "Artifact"
|
11787 | ],
|
11788 | properties: [
|
11789 | {
|
11790 | name: "categoryValueRef",
|
11791 | type: "CategoryValue",
|
11792 | isAttr: true,
|
11793 | isReference: true
|
11794 | }
|
11795 | ]
|
11796 | },
|
11797 | {
|
11798 | name: "Association",
|
11799 | superClass: [
|
11800 | "Artifact"
|
11801 | ],
|
11802 | properties: [
|
11803 | {
|
11804 | name: "associationDirection",
|
11805 | type: "AssociationDirection",
|
11806 | isAttr: true
|
11807 | },
|
11808 | {
|
11809 | name: "sourceRef",
|
11810 | type: "BaseElement",
|
11811 | isAttr: true,
|
11812 | isReference: true
|
11813 | },
|
11814 | {
|
11815 | name: "targetRef",
|
11816 | type: "BaseElement",
|
11817 | isAttr: true,
|
11818 | isReference: true
|
11819 | }
|
11820 | ]
|
11821 | },
|
11822 | {
|
11823 | name: "Category",
|
11824 | superClass: [
|
11825 | "RootElement"
|
11826 | ],
|
11827 | properties: [
|
11828 | {
|
11829 | name: "categoryValue",
|
11830 | type: "CategoryValue",
|
11831 | isMany: true
|
11832 | },
|
11833 | {
|
11834 | name: "name",
|
11835 | isAttr: true,
|
11836 | type: "String"
|
11837 | }
|
11838 | ]
|
11839 | },
|
11840 | {
|
11841 | name: "Artifact",
|
11842 | isAbstract: true,
|
11843 | superClass: [
|
11844 | "BaseElement"
|
11845 | ]
|
11846 | },
|
11847 | {
|
11848 | name: "CategoryValue",
|
11849 | superClass: [
|
11850 | "BaseElement"
|
11851 | ],
|
11852 | properties: [
|
11853 | {
|
11854 | name: "categorizedFlowElements",
|
11855 | type: "FlowElement",
|
11856 | isVirtual: true,
|
11857 | isMany: true,
|
11858 | isReference: true
|
11859 | },
|
11860 | {
|
11861 | name: "value",
|
11862 | isAttr: true,
|
11863 | type: "String"
|
11864 | }
|
11865 | ]
|
11866 | },
|
11867 | {
|
11868 | name: "Activity",
|
11869 | isAbstract: true,
|
11870 | superClass: [
|
11871 | "FlowNode"
|
11872 | ],
|
11873 | properties: [
|
11874 | {
|
11875 | name: "isForCompensation",
|
11876 | "default": false,
|
11877 | isAttr: true,
|
11878 | type: "Boolean"
|
11879 | },
|
11880 | {
|
11881 | name: "default",
|
11882 | type: "SequenceFlow",
|
11883 | isAttr: true,
|
11884 | isReference: true
|
11885 | },
|
11886 | {
|
11887 | name: "ioSpecification",
|
11888 | type: "InputOutputSpecification",
|
11889 | xml: {
|
11890 | serialize: "property"
|
11891 | }
|
11892 | },
|
11893 | {
|
11894 | name: "boundaryEventRefs",
|
11895 | type: "BoundaryEvent",
|
11896 | isMany: true,
|
11897 | isReference: true
|
11898 | },
|
11899 | {
|
11900 | name: "properties",
|
11901 | type: "Property",
|
11902 | isMany: true
|
11903 | },
|
11904 | {
|
11905 | name: "dataInputAssociations",
|
11906 | type: "DataInputAssociation",
|
11907 | isMany: true
|
11908 | },
|
11909 | {
|
11910 | name: "dataOutputAssociations",
|
11911 | type: "DataOutputAssociation",
|
11912 | isMany: true
|
11913 | },
|
11914 | {
|
11915 | name: "startQuantity",
|
11916 | "default": 1,
|
11917 | isAttr: true,
|
11918 | type: "Integer"
|
11919 | },
|
11920 | {
|
11921 | name: "resources",
|
11922 | type: "ResourceRole",
|
11923 | isMany: true
|
11924 | },
|
11925 | {
|
11926 | name: "completionQuantity",
|
11927 | "default": 1,
|
11928 | isAttr: true,
|
11929 | type: "Integer"
|
11930 | },
|
11931 | {
|
11932 | name: "loopCharacteristics",
|
11933 | type: "LoopCharacteristics"
|
11934 | }
|
11935 | ]
|
11936 | },
|
11937 | {
|
11938 | name: "ServiceTask",
|
11939 | superClass: [
|
11940 | "Task"
|
11941 | ],
|
11942 | properties: [
|
11943 | {
|
11944 | name: "implementation",
|
11945 | isAttr: true,
|
11946 | type: "String"
|
11947 | },
|
11948 | {
|
11949 | name: "operationRef",
|
11950 | type: "Operation",
|
11951 | isAttr: true,
|
11952 | isReference: true
|
11953 | }
|
11954 | ]
|
11955 | },
|
11956 | {
|
11957 | name: "SubProcess",
|
11958 | superClass: [
|
11959 | "Activity",
|
11960 | "FlowElementsContainer",
|
11961 | "InteractionNode"
|
11962 | ],
|
11963 | properties: [
|
11964 | {
|
11965 | name: "triggeredByEvent",
|
11966 | "default": false,
|
11967 | isAttr: true,
|
11968 | type: "Boolean"
|
11969 | },
|
11970 | {
|
11971 | name: "artifacts",
|
11972 | type: "Artifact",
|
11973 | isMany: true
|
11974 | }
|
11975 | ]
|
11976 | },
|
11977 | {
|
11978 | name: "LoopCharacteristics",
|
11979 | isAbstract: true,
|
11980 | superClass: [
|
11981 | "BaseElement"
|
11982 | ]
|
11983 | },
|
11984 | {
|
11985 | name: "MultiInstanceLoopCharacteristics",
|
11986 | superClass: [
|
11987 | "LoopCharacteristics"
|
11988 | ],
|
11989 | properties: [
|
11990 | {
|
11991 | name: "isSequential",
|
11992 | "default": false,
|
11993 | isAttr: true,
|
11994 | type: "Boolean"
|
11995 | },
|
11996 | {
|
11997 | name: "behavior",
|
11998 | type: "MultiInstanceBehavior",
|
11999 | "default": "All",
|
12000 | isAttr: true
|
12001 | },
|
12002 | {
|
12003 | name: "loopCardinality",
|
12004 | type: "Expression",
|
12005 | xml: {
|
12006 | serialize: "xsi:type"
|
12007 | }
|
12008 | },
|
12009 | {
|
12010 | name: "loopDataInputRef",
|
12011 | type: "ItemAwareElement",
|
12012 | isReference: true
|
12013 | },
|
12014 | {
|
12015 | name: "loopDataOutputRef",
|
12016 | type: "ItemAwareElement",
|
12017 | isReference: true
|
12018 | },
|
12019 | {
|
12020 | name: "inputDataItem",
|
12021 | type: "DataInput",
|
12022 | xml: {
|
12023 | serialize: "property"
|
12024 | }
|
12025 | },
|
12026 | {
|
12027 | name: "outputDataItem",
|
12028 | type: "DataOutput",
|
12029 | xml: {
|
12030 | serialize: "property"
|
12031 | }
|
12032 | },
|
12033 | {
|
12034 | name: "complexBehaviorDefinition",
|
12035 | type: "ComplexBehaviorDefinition",
|
12036 | isMany: true
|
12037 | },
|
12038 | {
|
12039 | name: "completionCondition",
|
12040 | type: "Expression",
|
12041 | xml: {
|
12042 | serialize: "xsi:type"
|
12043 | }
|
12044 | },
|
12045 | {
|
12046 | name: "oneBehaviorEventRef",
|
12047 | type: "EventDefinition",
|
12048 | isAttr: true,
|
12049 | isReference: true
|
12050 | },
|
12051 | {
|
12052 | name: "noneBehaviorEventRef",
|
12053 | type: "EventDefinition",
|
12054 | isAttr: true,
|
12055 | isReference: true
|
12056 | }
|
12057 | ]
|
12058 | },
|
12059 | {
|
12060 | name: "StandardLoopCharacteristics",
|
12061 | superClass: [
|
12062 | "LoopCharacteristics"
|
12063 | ],
|
12064 | properties: [
|
12065 | {
|
12066 | name: "testBefore",
|
12067 | "default": false,
|
12068 | isAttr: true,
|
12069 | type: "Boolean"
|
12070 | },
|
12071 | {
|
12072 | name: "loopCondition",
|
12073 | type: "Expression",
|
12074 | xml: {
|
12075 | serialize: "xsi:type"
|
12076 | }
|
12077 | },
|
12078 | {
|
12079 | name: "loopMaximum",
|
12080 | type: "Integer",
|
12081 | isAttr: true
|
12082 | }
|
12083 | ]
|
12084 | },
|
12085 | {
|
12086 | name: "CallActivity",
|
12087 | superClass: [
|
12088 | "Activity"
|
12089 | ],
|
12090 | properties: [
|
12091 | {
|
12092 | name: "calledElement",
|
12093 | type: "String",
|
12094 | isAttr: true
|
12095 | }
|
12096 | ]
|
12097 | },
|
12098 | {
|
12099 | name: "Task",
|
12100 | superClass: [
|
12101 | "Activity",
|
12102 | "InteractionNode"
|
12103 | ]
|
12104 | },
|
12105 | {
|
12106 | name: "SendTask",
|
12107 | superClass: [
|
12108 | "Task"
|
12109 | ],
|
12110 | properties: [
|
12111 | {
|
12112 | name: "implementation",
|
12113 | isAttr: true,
|
12114 | type: "String"
|
12115 | },
|
12116 | {
|
12117 | name: "operationRef",
|
12118 | type: "Operation",
|
12119 | isAttr: true,
|
12120 | isReference: true
|
12121 | },
|
12122 | {
|
12123 | name: "messageRef",
|
12124 | type: "Message",
|
12125 | isAttr: true,
|
12126 | isReference: true
|
12127 | }
|
12128 | ]
|
12129 | },
|
12130 | {
|
12131 | name: "ReceiveTask",
|
12132 | superClass: [
|
12133 | "Task"
|
12134 | ],
|
12135 | properties: [
|
12136 | {
|
12137 | name: "implementation",
|
12138 | isAttr: true,
|
12139 | type: "String"
|
12140 | },
|
12141 | {
|
12142 | name: "instantiate",
|
12143 | "default": false,
|
12144 | isAttr: true,
|
12145 | type: "Boolean"
|
12146 | },
|
12147 | {
|
12148 | name: "operationRef",
|
12149 | type: "Operation",
|
12150 | isAttr: true,
|
12151 | isReference: true
|
12152 | },
|
12153 | {
|
12154 | name: "messageRef",
|
12155 | type: "Message",
|
12156 | isAttr: true,
|
12157 | isReference: true
|
12158 | }
|
12159 | ]
|
12160 | },
|
12161 | {
|
12162 | name: "ScriptTask",
|
12163 | superClass: [
|
12164 | "Task"
|
12165 | ],
|
12166 | properties: [
|
12167 | {
|
12168 | name: "scriptFormat",
|
12169 | isAttr: true,
|
12170 | type: "String"
|
12171 | },
|
12172 | {
|
12173 | name: "script",
|
12174 | type: "String"
|
12175 | }
|
12176 | ]
|
12177 | },
|
12178 | {
|
12179 | name: "BusinessRuleTask",
|
12180 | superClass: [
|
12181 | "Task"
|
12182 | ],
|
12183 | properties: [
|
12184 | {
|
12185 | name: "implementation",
|
12186 | isAttr: true,
|
12187 | type: "String"
|
12188 | }
|
12189 | ]
|
12190 | },
|
12191 | {
|
12192 | name: "AdHocSubProcess",
|
12193 | superClass: [
|
12194 | "SubProcess"
|
12195 | ],
|
12196 | properties: [
|
12197 | {
|
12198 | name: "completionCondition",
|
12199 | type: "Expression",
|
12200 | xml: {
|
12201 | serialize: "xsi:type"
|
12202 | }
|
12203 | },
|
12204 | {
|
12205 | name: "ordering",
|
12206 | type: "AdHocOrdering",
|
12207 | isAttr: true
|
12208 | },
|
12209 | {
|
12210 | name: "cancelRemainingInstances",
|
12211 | "default": true,
|
12212 | isAttr: true,
|
12213 | type: "Boolean"
|
12214 | }
|
12215 | ]
|
12216 | },
|
12217 | {
|
12218 | name: "Transaction",
|
12219 | superClass: [
|
12220 | "SubProcess"
|
12221 | ],
|
12222 | properties: [
|
12223 | {
|
12224 | name: "protocol",
|
12225 | isAttr: true,
|
12226 | type: "String"
|
12227 | },
|
12228 | {
|
12229 | name: "method",
|
12230 | isAttr: true,
|
12231 | type: "String"
|
12232 | }
|
12233 | ]
|
12234 | },
|
12235 | {
|
12236 | name: "GlobalScriptTask",
|
12237 | superClass: [
|
12238 | "GlobalTask"
|
12239 | ],
|
12240 | properties: [
|
12241 | {
|
12242 | name: "scriptLanguage",
|
12243 | isAttr: true,
|
12244 | type: "String"
|
12245 | },
|
12246 | {
|
12247 | name: "script",
|
12248 | isAttr: true,
|
12249 | type: "String"
|
12250 | }
|
12251 | ]
|
12252 | },
|
12253 | {
|
12254 | name: "GlobalBusinessRuleTask",
|
12255 | superClass: [
|
12256 | "GlobalTask"
|
12257 | ],
|
12258 | properties: [
|
12259 | {
|
12260 | name: "implementation",
|
12261 | isAttr: true,
|
12262 | type: "String"
|
12263 | }
|
12264 | ]
|
12265 | },
|
12266 | {
|
12267 | name: "ComplexBehaviorDefinition",
|
12268 | superClass: [
|
12269 | "BaseElement"
|
12270 | ],
|
12271 | properties: [
|
12272 | {
|
12273 | name: "condition",
|
12274 | type: "FormalExpression"
|
12275 | },
|
12276 | {
|
12277 | name: "event",
|
12278 | type: "ImplicitThrowEvent"
|
12279 | }
|
12280 | ]
|
12281 | },
|
12282 | {
|
12283 | name: "ResourceRole",
|
12284 | superClass: [
|
12285 | "BaseElement"
|
12286 | ],
|
12287 | properties: [
|
12288 | {
|
12289 | name: "resourceRef",
|
12290 | type: "Resource",
|
12291 | isReference: true
|
12292 | },
|
12293 | {
|
12294 | name: "resourceParameterBindings",
|
12295 | type: "ResourceParameterBinding",
|
12296 | isMany: true
|
12297 | },
|
12298 | {
|
12299 | name: "resourceAssignmentExpression",
|
12300 | type: "ResourceAssignmentExpression"
|
12301 | },
|
12302 | {
|
12303 | name: "name",
|
12304 | isAttr: true,
|
12305 | type: "String"
|
12306 | }
|
12307 | ]
|
12308 | },
|
12309 | {
|
12310 | name: "ResourceParameterBinding",
|
12311 | properties: [
|
12312 | {
|
12313 | name: "expression",
|
12314 | type: "Expression",
|
12315 | xml: {
|
12316 | serialize: "xsi:type"
|
12317 | }
|
12318 | },
|
12319 | {
|
12320 | name: "parameterRef",
|
12321 | type: "ResourceParameter",
|
12322 | isAttr: true,
|
12323 | isReference: true
|
12324 | }
|
12325 | ],
|
12326 | superClass: [
|
12327 | "BaseElement"
|
12328 | ]
|
12329 | },
|
12330 | {
|
12331 | name: "ResourceAssignmentExpression",
|
12332 | properties: [
|
12333 | {
|
12334 | name: "expression",
|
12335 | type: "Expression",
|
12336 | xml: {
|
12337 | serialize: "xsi:type"
|
12338 | }
|
12339 | }
|
12340 | ],
|
12341 | superClass: [
|
12342 | "BaseElement"
|
12343 | ]
|
12344 | },
|
12345 | {
|
12346 | name: "Import",
|
12347 | properties: [
|
12348 | {
|
12349 | name: "importType",
|
12350 | isAttr: true,
|
12351 | type: "String"
|
12352 | },
|
12353 | {
|
12354 | name: "location",
|
12355 | isAttr: true,
|
12356 | type: "String"
|
12357 | },
|
12358 | {
|
12359 | name: "namespace",
|
12360 | isAttr: true,
|
12361 | type: "String"
|
12362 | }
|
12363 | ]
|
12364 | },
|
12365 | {
|
12366 | name: "Definitions",
|
12367 | superClass: [
|
12368 | "BaseElement"
|
12369 | ],
|
12370 | properties: [
|
12371 | {
|
12372 | name: "name",
|
12373 | isAttr: true,
|
12374 | type: "String"
|
12375 | },
|
12376 | {
|
12377 | name: "targetNamespace",
|
12378 | isAttr: true,
|
12379 | type: "String"
|
12380 | },
|
12381 | {
|
12382 | name: "expressionLanguage",
|
12383 | "default": "http://www.w3.org/1999/XPath",
|
12384 | isAttr: true,
|
12385 | type: "String"
|
12386 | },
|
12387 | {
|
12388 | name: "typeLanguage",
|
12389 | "default": "http://www.w3.org/2001/XMLSchema",
|
12390 | isAttr: true,
|
12391 | type: "String"
|
12392 | },
|
12393 | {
|
12394 | name: "imports",
|
12395 | type: "Import",
|
12396 | isMany: true
|
12397 | },
|
12398 | {
|
12399 | name: "extensions",
|
12400 | type: "Extension",
|
12401 | isMany: true
|
12402 | },
|
12403 | {
|
12404 | name: "rootElements",
|
12405 | type: "RootElement",
|
12406 | isMany: true
|
12407 | },
|
12408 | {
|
12409 | name: "diagrams",
|
12410 | isMany: true,
|
12411 | type: "bpmndi:BPMNDiagram"
|
12412 | },
|
12413 | {
|
12414 | name: "exporter",
|
12415 | isAttr: true,
|
12416 | type: "String"
|
12417 | },
|
12418 | {
|
12419 | name: "relationships",
|
12420 | type: "Relationship",
|
12421 | isMany: true
|
12422 | },
|
12423 | {
|
12424 | name: "exporterVersion",
|
12425 | isAttr: true,
|
12426 | type: "String"
|
12427 | }
|
12428 | ]
|
12429 | }
|
12430 | ];
|
12431 | var enumerations = [
|
12432 | {
|
12433 | name: "ProcessType",
|
12434 | literalValues: [
|
12435 | {
|
12436 | name: "None"
|
12437 | },
|
12438 | {
|
12439 | name: "Public"
|
12440 | },
|
12441 | {
|
12442 | name: "Private"
|
12443 | }
|
12444 | ]
|
12445 | },
|
12446 | {
|
12447 | name: "GatewayDirection",
|
12448 | literalValues: [
|
12449 | {
|
12450 | name: "Unspecified"
|
12451 | },
|
12452 | {
|
12453 | name: "Converging"
|
12454 | },
|
12455 | {
|
12456 | name: "Diverging"
|
12457 | },
|
12458 | {
|
12459 | name: "Mixed"
|
12460 | }
|
12461 | ]
|
12462 | },
|
12463 | {
|
12464 | name: "EventBasedGatewayType",
|
12465 | literalValues: [
|
12466 | {
|
12467 | name: "Parallel"
|
12468 | },
|
12469 | {
|
12470 | name: "Exclusive"
|
12471 | }
|
12472 | ]
|
12473 | },
|
12474 | {
|
12475 | name: "RelationshipDirection",
|
12476 | literalValues: [
|
12477 | {
|
12478 | name: "None"
|
12479 | },
|
12480 | {
|
12481 | name: "Forward"
|
12482 | },
|
12483 | {
|
12484 | name: "Backward"
|
12485 | },
|
12486 | {
|
12487 | name: "Both"
|
12488 | }
|
12489 | ]
|
12490 | },
|
12491 | {
|
12492 | name: "ItemKind",
|
12493 | literalValues: [
|
12494 | {
|
12495 | name: "Physical"
|
12496 | },
|
12497 | {
|
12498 | name: "Information"
|
12499 | }
|
12500 | ]
|
12501 | },
|
12502 | {
|
12503 | name: "ChoreographyLoopType",
|
12504 | literalValues: [
|
12505 | {
|
12506 | name: "None"
|
12507 | },
|
12508 | {
|
12509 | name: "Standard"
|
12510 | },
|
12511 | {
|
12512 | name: "MultiInstanceSequential"
|
12513 | },
|
12514 | {
|
12515 | name: "MultiInstanceParallel"
|
12516 | }
|
12517 | ]
|
12518 | },
|
12519 | {
|
12520 | name: "AssociationDirection",
|
12521 | literalValues: [
|
12522 | {
|
12523 | name: "None"
|
12524 | },
|
12525 | {
|
12526 | name: "One"
|
12527 | },
|
12528 | {
|
12529 | name: "Both"
|
12530 | }
|
12531 | ]
|
12532 | },
|
12533 | {
|
12534 | name: "MultiInstanceBehavior",
|
12535 | literalValues: [
|
12536 | {
|
12537 | name: "None"
|
12538 | },
|
12539 | {
|
12540 | name: "One"
|
12541 | },
|
12542 | {
|
12543 | name: "All"
|
12544 | },
|
12545 | {
|
12546 | name: "Complex"
|
12547 | }
|
12548 | ]
|
12549 | },
|
12550 | {
|
12551 | name: "AdHocOrdering",
|
12552 | literalValues: [
|
12553 | {
|
12554 | name: "Parallel"
|
12555 | },
|
12556 | {
|
12557 | name: "Sequential"
|
12558 | }
|
12559 | ]
|
12560 | }
|
12561 | ];
|
12562 | var prefix$1 = "bpmn";
|
12563 | var xml = {
|
12564 | tagAlias: "lowerCase",
|
12565 | typePrefix: "t"
|
12566 | };
|
12567 | var BpmnPackage = {
|
12568 | name: name,
|
12569 | uri: uri,
|
12570 | associations: associations,
|
12571 | types: types$1,
|
12572 | enumerations: enumerations,
|
12573 | prefix: prefix$1,
|
12574 | xml: xml
|
12575 | };
|
12576 |
|
12577 | var name$1 = "BPMNDI";
|
12578 | var uri$1 = "http://www.omg.org/spec/BPMN/20100524/DI";
|
12579 | var types$1$1 = [
|
12580 | {
|
12581 | name: "BPMNDiagram",
|
12582 | properties: [
|
12583 | {
|
12584 | name: "plane",
|
12585 | type: "BPMNPlane",
|
12586 | redefines: "di:Diagram#rootElement"
|
12587 | },
|
12588 | {
|
12589 | name: "labelStyle",
|
12590 | type: "BPMNLabelStyle",
|
12591 | isMany: true
|
12592 | }
|
12593 | ],
|
12594 | superClass: [
|
12595 | "di:Diagram"
|
12596 | ]
|
12597 | },
|
12598 | {
|
12599 | name: "BPMNPlane",
|
12600 | properties: [
|
12601 | {
|
12602 | name: "bpmnElement",
|
12603 | isAttr: true,
|
12604 | isReference: true,
|
12605 | type: "bpmn:BaseElement",
|
12606 | redefines: "di:DiagramElement#modelElement"
|
12607 | }
|
12608 | ],
|
12609 | superClass: [
|
12610 | "di:Plane"
|
12611 | ]
|
12612 | },
|
12613 | {
|
12614 | name: "BPMNShape",
|
12615 | properties: [
|
12616 | {
|
12617 | name: "bpmnElement",
|
12618 | isAttr: true,
|
12619 | isReference: true,
|
12620 | type: "bpmn:BaseElement",
|
12621 | redefines: "di:DiagramElement#modelElement"
|
12622 | },
|
12623 | {
|
12624 | name: "isHorizontal",
|
12625 | isAttr: true,
|
12626 | type: "Boolean"
|
12627 | },
|
12628 | {
|
12629 | name: "isExpanded",
|
12630 | isAttr: true,
|
12631 | type: "Boolean"
|
12632 | },
|
12633 | {
|
12634 | name: "isMarkerVisible",
|
12635 | isAttr: true,
|
12636 | type: "Boolean"
|
12637 | },
|
12638 | {
|
12639 | name: "label",
|
12640 | type: "BPMNLabel"
|
12641 | },
|
12642 | {
|
12643 | name: "isMessageVisible",
|
12644 | isAttr: true,
|
12645 | type: "Boolean"
|
12646 | },
|
12647 | {
|
12648 | name: "participantBandKind",
|
12649 | type: "ParticipantBandKind",
|
12650 | isAttr: true
|
12651 | },
|
12652 | {
|
12653 | name: "choreographyActivityShape",
|
12654 | type: "BPMNShape",
|
12655 | isAttr: true,
|
12656 | isReference: true
|
12657 | }
|
12658 | ],
|
12659 | superClass: [
|
12660 | "di:LabeledShape"
|
12661 | ]
|
12662 | },
|
12663 | {
|
12664 | name: "BPMNEdge",
|
12665 | properties: [
|
12666 | {
|
12667 | name: "label",
|
12668 | type: "BPMNLabel"
|
12669 | },
|
12670 | {
|
12671 | name: "bpmnElement",
|
12672 | isAttr: true,
|
12673 | isReference: true,
|
12674 | type: "bpmn:BaseElement",
|
12675 | redefines: "di:DiagramElement#modelElement"
|
12676 | },
|
12677 | {
|
12678 | name: "sourceElement",
|
12679 | isAttr: true,
|
12680 | isReference: true,
|
12681 | type: "di:DiagramElement",
|
12682 | redefines: "di:Edge#source"
|
12683 | },
|
12684 | {
|
12685 | name: "targetElement",
|
12686 | isAttr: true,
|
12687 | isReference: true,
|
12688 | type: "di:DiagramElement",
|
12689 | redefines: "di:Edge#target"
|
12690 | },
|
12691 | {
|
12692 | name: "messageVisibleKind",
|
12693 | type: "MessageVisibleKind",
|
12694 | isAttr: true,
|
12695 | "default": "initiating"
|
12696 | }
|
12697 | ],
|
12698 | superClass: [
|
12699 | "di:LabeledEdge"
|
12700 | ]
|
12701 | },
|
12702 | {
|
12703 | name: "BPMNLabel",
|
12704 | properties: [
|
12705 | {
|
12706 | name: "labelStyle",
|
12707 | type: "BPMNLabelStyle",
|
12708 | isAttr: true,
|
12709 | isReference: true,
|
12710 | redefines: "di:DiagramElement#style"
|
12711 | }
|
12712 | ],
|
12713 | superClass: [
|
12714 | "di:Label"
|
12715 | ]
|
12716 | },
|
12717 | {
|
12718 | name: "BPMNLabelStyle",
|
12719 | properties: [
|
12720 | {
|
12721 | name: "font",
|
12722 | type: "dc:Font"
|
12723 | }
|
12724 | ],
|
12725 | superClass: [
|
12726 | "di:Style"
|
12727 | ]
|
12728 | }
|
12729 | ];
|
12730 | var enumerations$1 = [
|
12731 | {
|
12732 | name: "ParticipantBandKind",
|
12733 | literalValues: [
|
12734 | {
|
12735 | name: "top_initiating"
|
12736 | },
|
12737 | {
|
12738 | name: "middle_initiating"
|
12739 | },
|
12740 | {
|
12741 | name: "bottom_initiating"
|
12742 | },
|
12743 | {
|
12744 | name: "top_non_initiating"
|
12745 | },
|
12746 | {
|
12747 | name: "middle_non_initiating"
|
12748 | },
|
12749 | {
|
12750 | name: "bottom_non_initiating"
|
12751 | }
|
12752 | ]
|
12753 | },
|
12754 | {
|
12755 | name: "MessageVisibleKind",
|
12756 | literalValues: [
|
12757 | {
|
12758 | name: "initiating"
|
12759 | },
|
12760 | {
|
12761 | name: "non_initiating"
|
12762 | }
|
12763 | ]
|
12764 | }
|
12765 | ];
|
12766 | var associations$1 = [
|
12767 | ];
|
12768 | var prefix$1$1 = "bpmndi";
|
12769 | var BpmnDiPackage = {
|
12770 | name: name$1,
|
12771 | uri: uri$1,
|
12772 | types: types$1$1,
|
12773 | enumerations: enumerations$1,
|
12774 | associations: associations$1,
|
12775 | prefix: prefix$1$1
|
12776 | };
|
12777 |
|
12778 | var name$2 = "DC";
|
12779 | var uri$2 = "http://www.omg.org/spec/DD/20100524/DC";
|
12780 | var types$2 = [
|
12781 | {
|
12782 | name: "Boolean"
|
12783 | },
|
12784 | {
|
12785 | name: "Integer"
|
12786 | },
|
12787 | {
|
12788 | name: "Real"
|
12789 | },
|
12790 | {
|
12791 | name: "String"
|
12792 | },
|
12793 | {
|
12794 | name: "Font",
|
12795 | properties: [
|
12796 | {
|
12797 | name: "name",
|
12798 | type: "String",
|
12799 | isAttr: true
|
12800 | },
|
12801 | {
|
12802 | name: "size",
|
12803 | type: "Real",
|
12804 | isAttr: true
|
12805 | },
|
12806 | {
|
12807 | name: "isBold",
|
12808 | type: "Boolean",
|
12809 | isAttr: true
|
12810 | },
|
12811 | {
|
12812 | name: "isItalic",
|
12813 | type: "Boolean",
|
12814 | isAttr: true
|
12815 | },
|
12816 | {
|
12817 | name: "isUnderline",
|
12818 | type: "Boolean",
|
12819 | isAttr: true
|
12820 | },
|
12821 | {
|
12822 | name: "isStrikeThrough",
|
12823 | type: "Boolean",
|
12824 | isAttr: true
|
12825 | }
|
12826 | ]
|
12827 | },
|
12828 | {
|
12829 | name: "Point",
|
12830 | properties: [
|
12831 | {
|
12832 | name: "x",
|
12833 | type: "Real",
|
12834 | "default": "0",
|
12835 | isAttr: true
|
12836 | },
|
12837 | {
|
12838 | name: "y",
|
12839 | type: "Real",
|
12840 | "default": "0",
|
12841 | isAttr: true
|
12842 | }
|
12843 | ]
|
12844 | },
|
12845 | {
|
12846 | name: "Bounds",
|
12847 | properties: [
|
12848 | {
|
12849 | name: "x",
|
12850 | type: "Real",
|
12851 | "default": "0",
|
12852 | isAttr: true
|
12853 | },
|
12854 | {
|
12855 | name: "y",
|
12856 | type: "Real",
|
12857 | "default": "0",
|
12858 | isAttr: true
|
12859 | },
|
12860 | {
|
12861 | name: "width",
|
12862 | type: "Real",
|
12863 | isAttr: true
|
12864 | },
|
12865 | {
|
12866 | name: "height",
|
12867 | type: "Real",
|
12868 | isAttr: true
|
12869 | }
|
12870 | ]
|
12871 | }
|
12872 | ];
|
12873 | var prefix$2 = "dc";
|
12874 | var associations$2 = [
|
12875 | ];
|
12876 | var DcPackage = {
|
12877 | name: name$2,
|
12878 | uri: uri$2,
|
12879 | types: types$2,
|
12880 | prefix: prefix$2,
|
12881 | associations: associations$2
|
12882 | };
|
12883 |
|
12884 | var name$3 = "DI";
|
12885 | var uri$3 = "http://www.omg.org/spec/DD/20100524/DI";
|
12886 | var types$3 = [
|
12887 | {
|
12888 | name: "DiagramElement",
|
12889 | isAbstract: true,
|
12890 | properties: [
|
12891 | {
|
12892 | name: "id",
|
12893 | type: "String",
|
12894 | isAttr: true,
|
12895 | isId: true
|
12896 | },
|
12897 | {
|
12898 | name: "extension",
|
12899 | type: "Extension"
|
12900 | },
|
12901 | {
|
12902 | name: "owningDiagram",
|
12903 | type: "Diagram",
|
12904 | isReadOnly: true,
|
12905 | isVirtual: true,
|
12906 | isReference: true
|
12907 | },
|
12908 | {
|
12909 | name: "owningElement",
|
12910 | type: "DiagramElement",
|
12911 | isReadOnly: true,
|
12912 | isVirtual: true,
|
12913 | isReference: true
|
12914 | },
|
12915 | {
|
12916 | name: "modelElement",
|
12917 | isReadOnly: true,
|
12918 | isVirtual: true,
|
12919 | isReference: true,
|
12920 | type: "Element"
|
12921 | },
|
12922 | {
|
12923 | name: "style",
|
12924 | type: "Style",
|
12925 | isReadOnly: true,
|
12926 | isVirtual: true,
|
12927 | isReference: true
|
12928 | },
|
12929 | {
|
12930 | name: "ownedElement",
|
12931 | type: "DiagramElement",
|
12932 | isReadOnly: true,
|
12933 | isVirtual: true,
|
12934 | isMany: true
|
12935 | }
|
12936 | ]
|
12937 | },
|
12938 | {
|
12939 | name: "Node",
|
12940 | isAbstract: true,
|
12941 | superClass: [
|
12942 | "DiagramElement"
|
12943 | ]
|
12944 | },
|
12945 | {
|
12946 | name: "Edge",
|
12947 | isAbstract: true,
|
12948 | superClass: [
|
12949 | "DiagramElement"
|
12950 | ],
|
12951 | properties: [
|
12952 | {
|
12953 | name: "source",
|
12954 | type: "DiagramElement",
|
12955 | isReadOnly: true,
|
12956 | isVirtual: true,
|
12957 | isReference: true
|
12958 | },
|
12959 | {
|
12960 | name: "target",
|
12961 | type: "DiagramElement",
|
12962 | isReadOnly: true,
|
12963 | isVirtual: true,
|
12964 | isReference: true
|
12965 | },
|
12966 | {
|
12967 | name: "waypoint",
|
12968 | isUnique: false,
|
12969 | isMany: true,
|
12970 | type: "dc:Point",
|
12971 | xml: {
|
12972 | serialize: "xsi:type"
|
12973 | }
|
12974 | }
|
12975 | ]
|
12976 | },
|
12977 | {
|
12978 | name: "Diagram",
|
12979 | isAbstract: true,
|
12980 | properties: [
|
12981 | {
|
12982 | name: "id",
|
12983 | type: "String",
|
12984 | isAttr: true,
|
12985 | isId: true
|
12986 | },
|
12987 | {
|
12988 | name: "rootElement",
|
12989 | type: "DiagramElement",
|
12990 | isReadOnly: true,
|
12991 | isVirtual: true
|
12992 | },
|
12993 | {
|
12994 | name: "name",
|
12995 | isAttr: true,
|
12996 | type: "String"
|
12997 | },
|
12998 | {
|
12999 | name: "documentation",
|
13000 | isAttr: true,
|
13001 | type: "String"
|
13002 | },
|
13003 | {
|
13004 | name: "resolution",
|
13005 | isAttr: true,
|
13006 | type: "Real"
|
13007 | },
|
13008 | {
|
13009 | name: "ownedStyle",
|
13010 | type: "Style",
|
13011 | isReadOnly: true,
|
13012 | isVirtual: true,
|
13013 | isMany: true
|
13014 | }
|
13015 | ]
|
13016 | },
|
13017 | {
|
13018 | name: "Shape",
|
13019 | isAbstract: true,
|
13020 | superClass: [
|
13021 | "Node"
|
13022 | ],
|
13023 | properties: [
|
13024 | {
|
13025 | name: "bounds",
|
13026 | type: "dc:Bounds"
|
13027 | }
|
13028 | ]
|
13029 | },
|
13030 | {
|
13031 | name: "Plane",
|
13032 | isAbstract: true,
|
13033 | superClass: [
|
13034 | "Node"
|
13035 | ],
|
13036 | properties: [
|
13037 | {
|
13038 | name: "planeElement",
|
13039 | type: "DiagramElement",
|
13040 | subsettedProperty: "DiagramElement-ownedElement",
|
13041 | isMany: true
|
13042 | }
|
13043 | ]
|
13044 | },
|
13045 | {
|
13046 | name: "LabeledEdge",
|
13047 | isAbstract: true,
|
13048 | superClass: [
|
13049 | "Edge"
|
13050 | ],
|
13051 | properties: [
|
13052 | {
|
13053 | name: "ownedLabel",
|
13054 | type: "Label",
|
13055 | isReadOnly: true,
|
13056 | subsettedProperty: "DiagramElement-ownedElement",
|
13057 | isVirtual: true,
|
13058 | isMany: true
|
13059 | }
|
13060 | ]
|
13061 | },
|
13062 | {
|
13063 | name: "LabeledShape",
|
13064 | isAbstract: true,
|
13065 | superClass: [
|
13066 | "Shape"
|
13067 | ],
|
13068 | properties: [
|
13069 | {
|
13070 | name: "ownedLabel",
|
13071 | type: "Label",
|
13072 | isReadOnly: true,
|
13073 | subsettedProperty: "DiagramElement-ownedElement",
|
13074 | isVirtual: true,
|
13075 | isMany: true
|
13076 | }
|
13077 | ]
|
13078 | },
|
13079 | {
|
13080 | name: "Label",
|
13081 | isAbstract: true,
|
13082 | superClass: [
|
13083 | "Node"
|
13084 | ],
|
13085 | properties: [
|
13086 | {
|
13087 | name: "bounds",
|
13088 | type: "dc:Bounds"
|
13089 | }
|
13090 | ]
|
13091 | },
|
13092 | {
|
13093 | name: "Style",
|
13094 | isAbstract: true,
|
13095 | properties: [
|
13096 | {
|
13097 | name: "id",
|
13098 | type: "String",
|
13099 | isAttr: true,
|
13100 | isId: true
|
13101 | }
|
13102 | ]
|
13103 | },
|
13104 | {
|
13105 | name: "Extension",
|
13106 | properties: [
|
13107 | {
|
13108 | name: "values",
|
13109 | type: "Element",
|
13110 | isMany: true
|
13111 | }
|
13112 | ]
|
13113 | }
|
13114 | ];
|
13115 | var associations$3 = [
|
13116 | ];
|
13117 | var prefix$3 = "di";
|
13118 | var xml$1 = {
|
13119 | tagAlias: "lowerCase"
|
13120 | };
|
13121 | var DiPackage = {
|
13122 | name: name$3,
|
13123 | uri: uri$3,
|
13124 | types: types$3,
|
13125 | associations: associations$3,
|
13126 | prefix: prefix$3,
|
13127 | xml: xml$1
|
13128 | };
|
13129 |
|
13130 | var name$4 = "bpmn.io colors for BPMN";
|
13131 | var uri$4 = "http://bpmn.io/schema/bpmn/biocolor/1.0";
|
13132 | var prefix$4 = "bioc";
|
13133 | var types$4 = [
|
13134 | {
|
13135 | name: "ColoredShape",
|
13136 | "extends": [
|
13137 | "bpmndi:BPMNShape"
|
13138 | ],
|
13139 | properties: [
|
13140 | {
|
13141 | name: "stroke",
|
13142 | isAttr: true,
|
13143 | type: "String"
|
13144 | },
|
13145 | {
|
13146 | name: "fill",
|
13147 | isAttr: true,
|
13148 | type: "String"
|
13149 | }
|
13150 | ]
|
13151 | },
|
13152 | {
|
13153 | name: "ColoredEdge",
|
13154 | "extends": [
|
13155 | "bpmndi:BPMNEdge"
|
13156 | ],
|
13157 | properties: [
|
13158 | {
|
13159 | name: "stroke",
|
13160 | isAttr: true,
|
13161 | type: "String"
|
13162 | },
|
13163 | {
|
13164 | name: "fill",
|
13165 | isAttr: true,
|
13166 | type: "String"
|
13167 | }
|
13168 | ]
|
13169 | }
|
13170 | ];
|
13171 | var enumerations$2 = [
|
13172 | ];
|
13173 | var associations$4 = [
|
13174 | ];
|
13175 | var BiocPackage = {
|
13176 | name: name$4,
|
13177 | uri: uri$4,
|
13178 | prefix: prefix$4,
|
13179 | types: types$4,
|
13180 | enumerations: enumerations$2,
|
13181 | associations: associations$4
|
13182 | };
|
13183 |
|
13184 | var packages = {
|
13185 | bpmn: BpmnPackage,
|
13186 | bpmndi: BpmnDiPackage,
|
13187 | dc: DcPackage,
|
13188 | di: DiPackage,
|
13189 | bioc: BiocPackage
|
13190 | };
|
13191 |
|
13192 | function simple(additionalPackages, options) {
|
13193 | var pks = assign({}, packages, additionalPackages);
|
13194 |
|
13195 | return new BpmnModdle(pks, options);
|
13196 | }
|
13197 |
|
13198 | function elementToString(e) {
|
13199 | if (!e) {
|
13200 | return '<null>';
|
13201 | }
|
13202 |
|
13203 | return '<' + e.$type + (e.id ? ' id="' + e.id : '') + '" />';
|
13204 | }
|
13205 |
|
13206 | var diRefs = new objectRefs(
|
13207 | { name: 'bpmnElement', enumerable: true },
|
13208 | { name: 'di', configurable: true }
|
13209 | );
|
13210 |
|
13211 | |
13212 |
|
13213 |
|
13214 |
|
13215 |
|
13216 |
|
13217 |
|
13218 |
|
13219 | function is(element, type) {
|
13220 | return element.$instanceOf(type);
|
13221 | }
|
13222 |
|
13223 |
|
13224 | |
13225 |
|
13226 |
|
13227 |
|
13228 | function findDisplayCandidate(definitions) {
|
13229 | return find(definitions.rootElements, function(e) {
|
13230 | return is(e, 'bpmn:Process') || is(e, 'bpmn:Collaboration');
|
13231 | });
|
13232 | }
|
13233 |
|
13234 |
|
13235 | function BpmnTreeWalker(handler, translate) {
|
13236 |
|
13237 |
|
13238 | var handledElements = {};
|
13239 |
|
13240 |
|
13241 |
|
13242 | var deferred = [];
|
13243 |
|
13244 |
|
13245 |
|
13246 | function contextual(fn, ctx) {
|
13247 | return function(e) {
|
13248 | fn(e, ctx);
|
13249 | };
|
13250 | }
|
13251 |
|
13252 | function handled(element) {
|
13253 | handledElements[element.id] = element;
|
13254 | }
|
13255 |
|
13256 | function isHandled(element) {
|
13257 | return handledElements[element.id];
|
13258 | }
|
13259 |
|
13260 | function visit(element, ctx) {
|
13261 |
|
13262 | var gfx = element.gfx;
|
13263 |
|
13264 |
|
13265 | if (gfx) {
|
13266 | throw new Error(
|
13267 | translate('already rendered {element}', { element: elementToString(element) })
|
13268 | );
|
13269 | }
|
13270 |
|
13271 |
|
13272 | return handler.element(element, ctx);
|
13273 | }
|
13274 |
|
13275 | function visitRoot(element, diagram) {
|
13276 | return handler.root(element, diagram);
|
13277 | }
|
13278 |
|
13279 | function visitIfDi(element, ctx) {
|
13280 |
|
13281 | try {
|
13282 | var gfx = element.di && visit(element, ctx);
|
13283 |
|
13284 | handled(element);
|
13285 |
|
13286 | return gfx;
|
13287 | } catch (e) {
|
13288 | logError(e.message, { element: element, error: e });
|
13289 |
|
13290 | console.error(translate('failed to import {element}', { element: elementToString(element) }));
|
13291 | console.error(e);
|
13292 | }
|
13293 | }
|
13294 |
|
13295 | function logError(message, context) {
|
13296 | handler.error(message, context);
|
13297 | }
|
13298 |
|
13299 |
|
13300 |
|
13301 | function registerDi(di) {
|
13302 | var bpmnElement = di.bpmnElement;
|
13303 |
|
13304 | if (bpmnElement) {
|
13305 | if (bpmnElement.di) {
|
13306 | logError(
|
13307 | translate('multiple DI elements defined for {element}', {
|
13308 | element: elementToString(bpmnElement)
|
13309 | }),
|
13310 | { element: bpmnElement }
|
13311 | );
|
13312 | } else {
|
13313 | diRefs.bind(bpmnElement, 'di');
|
13314 | bpmnElement.di = di;
|
13315 | }
|
13316 | } else {
|
13317 | logError(
|
13318 | translate('no bpmnElement referenced in {element}', {
|
13319 | element: elementToString(di)
|
13320 | }),
|
13321 | { element: di }
|
13322 | );
|
13323 | }
|
13324 | }
|
13325 |
|
13326 | function handleDiagram(diagram) {
|
13327 | handlePlane(diagram.plane);
|
13328 | }
|
13329 |
|
13330 | function handlePlane(plane) {
|
13331 | registerDi(plane);
|
13332 |
|
13333 | forEach(plane.planeElement, handlePlaneElement);
|
13334 | }
|
13335 |
|
13336 | function handlePlaneElement(planeElement) {
|
13337 | registerDi(planeElement);
|
13338 | }
|
13339 |
|
13340 |
|
13341 |
|
13342 |
|
13343 | |
13344 |
|
13345 |
|
13346 |
|
13347 |
|
13348 |
|
13349 |
|
13350 |
|
13351 | function handleDefinitions(definitions, diagram) {
|
13352 |
|
13353 |
|
13354 |
|
13355 | var diagrams = definitions.diagrams;
|
13356 |
|
13357 | if (diagram && diagrams.indexOf(diagram) === -1) {
|
13358 | throw new Error(translate('diagram not part of bpmn:Definitions'));
|
13359 | }
|
13360 |
|
13361 | if (!diagram && diagrams && diagrams.length) {
|
13362 | diagram = diagrams[0];
|
13363 | }
|
13364 |
|
13365 |
|
13366 | if (!diagram) {
|
13367 | throw new Error(translate('no diagram to display'));
|
13368 | }
|
13369 |
|
13370 |
|
13371 | handleDiagram(diagram);
|
13372 |
|
13373 |
|
13374 | var plane = diagram.plane;
|
13375 |
|
13376 | if (!plane) {
|
13377 | throw new Error(translate(
|
13378 | 'no plane for {element}',
|
13379 | { element: elementToString(diagram) }
|
13380 | ));
|
13381 | }
|
13382 |
|
13383 | var rootElement = plane.bpmnElement;
|
13384 |
|
13385 |
|
13386 |
|
13387 | if (!rootElement) {
|
13388 | rootElement = findDisplayCandidate(definitions);
|
13389 |
|
13390 | if (!rootElement) {
|
13391 | throw new Error(translate('no process or collaboration to display'));
|
13392 | } else {
|
13393 |
|
13394 | logError(
|
13395 | translate('correcting missing bpmnElement on {plane} to {rootElement}', {
|
13396 | plane: elementToString(plane),
|
13397 | rootElement: elementToString(rootElement)
|
13398 | })
|
13399 | );
|
13400 |
|
13401 |
|
13402 | plane.bpmnElement = rootElement;
|
13403 | registerDi(plane);
|
13404 | }
|
13405 | }
|
13406 |
|
13407 |
|
13408 | var ctx = visitRoot(rootElement, plane);
|
13409 |
|
13410 | if (is(rootElement, 'bpmn:Process')) {
|
13411 | handleProcess(rootElement, ctx);
|
13412 | } else if (is(rootElement, 'bpmn:Collaboration')) {
|
13413 | handleCollaboration(rootElement);
|
13414 |
|
13415 |
|
13416 | handleUnhandledProcesses(definitions.rootElements, ctx);
|
13417 | } else {
|
13418 | throw new Error(
|
13419 | translate('unsupported bpmnElement for {plane}: {rootElement}', {
|
13420 | plane: elementToString(plane),
|
13421 | rootElement: elementToString(rootElement)
|
13422 | })
|
13423 | );
|
13424 | }
|
13425 |
|
13426 |
|
13427 | handleDeferred();
|
13428 | }
|
13429 |
|
13430 | function handleDeferred() {
|
13431 |
|
13432 | var fn;
|
13433 |
|
13434 |
|
13435 | while (deferred.length) {
|
13436 | fn = deferred.shift();
|
13437 |
|
13438 | fn();
|
13439 | }
|
13440 | }
|
13441 |
|
13442 | function handleProcess(process, context) {
|
13443 | handleFlowElementsContainer(process, context);
|
13444 | handleIoSpecification(process.ioSpecification, context);
|
13445 |
|
13446 | handleArtifacts(process.artifacts, context);
|
13447 |
|
13448 |
|
13449 | handled(process);
|
13450 | }
|
13451 |
|
13452 | function handleUnhandledProcesses(rootElements, ctx) {
|
13453 |
|
13454 |
|
13455 |
|
13456 |
|
13457 | var processes = filter(rootElements, function(e) {
|
13458 | return !isHandled(e) && is(e, 'bpmn:Process') && e.laneSets;
|
13459 | });
|
13460 |
|
13461 | processes.forEach(contextual(handleProcess, ctx));
|
13462 | }
|
13463 |
|
13464 | function handleMessageFlow(messageFlow, context) {
|
13465 | visitIfDi(messageFlow, context);
|
13466 | }
|
13467 |
|
13468 | function handleMessageFlows(messageFlows, context) {
|
13469 | forEach(messageFlows, contextual(handleMessageFlow, context));
|
13470 | }
|
13471 |
|
13472 | function handleDataAssociation(association, context) {
|
13473 | visitIfDi(association, context);
|
13474 | }
|
13475 |
|
13476 | function handleDataInput(dataInput, context) {
|
13477 | visitIfDi(dataInput, context);
|
13478 | }
|
13479 |
|
13480 | function handleDataOutput(dataOutput, context) {
|
13481 | visitIfDi(dataOutput, context);
|
13482 | }
|
13483 |
|
13484 | function handleArtifact(artifact, context) {
|
13485 |
|
13486 |
|
13487 |
|
13488 |
|
13489 |
|
13490 | visitIfDi(artifact, context);
|
13491 | }
|
13492 |
|
13493 | function handleArtifacts(artifacts, context) {
|
13494 |
|
13495 | forEach(artifacts, function(e) {
|
13496 | if (is(e, 'bpmn:Association')) {
|
13497 | deferred.push(function() {
|
13498 | handleArtifact(e, context);
|
13499 | });
|
13500 | } else {
|
13501 | handleArtifact(e, context);
|
13502 | }
|
13503 | });
|
13504 | }
|
13505 |
|
13506 | function handleIoSpecification(ioSpecification, context) {
|
13507 |
|
13508 | if (!ioSpecification) {
|
13509 | return;
|
13510 | }
|
13511 |
|
13512 | forEach(ioSpecification.dataInputs, contextual(handleDataInput, context));
|
13513 | forEach(ioSpecification.dataOutputs, contextual(handleDataOutput, context));
|
13514 | }
|
13515 |
|
13516 | function handleSubProcess(subProcess, context) {
|
13517 | handleFlowElementsContainer(subProcess, context);
|
13518 | handleArtifacts(subProcess.artifacts, context);
|
13519 | }
|
13520 |
|
13521 | function handleFlowNode(flowNode, context) {
|
13522 | var childCtx = visitIfDi(flowNode, context);
|
13523 |
|
13524 | if (is(flowNode, 'bpmn:SubProcess')) {
|
13525 | handleSubProcess(flowNode, childCtx || context);
|
13526 | }
|
13527 |
|
13528 | if (is(flowNode, 'bpmn:Activity')) {
|
13529 | handleIoSpecification(flowNode.ioSpecification, context);
|
13530 | }
|
13531 |
|
13532 |
|
13533 |
|
13534 |
|
13535 |
|
13536 |
|
13537 |
|
13538 |
|
13539 | deferred.push(function() {
|
13540 | forEach(flowNode.dataInputAssociations, contextual(handleDataAssociation, context));
|
13541 | forEach(flowNode.dataOutputAssociations, contextual(handleDataAssociation, context));
|
13542 | });
|
13543 | }
|
13544 |
|
13545 | function handleSequenceFlow(sequenceFlow, context) {
|
13546 | visitIfDi(sequenceFlow, context);
|
13547 | }
|
13548 |
|
13549 | function handleDataElement(dataObject, context) {
|
13550 | visitIfDi(dataObject, context);
|
13551 | }
|
13552 |
|
13553 | function handleLane(lane, context) {
|
13554 |
|
13555 | deferred.push(function() {
|
13556 |
|
13557 | var newContext = visitIfDi(lane, context);
|
13558 |
|
13559 | if (lane.childLaneSet) {
|
13560 | handleLaneSet(lane.childLaneSet, newContext || context);
|
13561 | }
|
13562 |
|
13563 | wireFlowNodeRefs(lane);
|
13564 | });
|
13565 | }
|
13566 |
|
13567 | function handleLaneSet(laneSet, context) {
|
13568 | forEach(laneSet.lanes, contextual(handleLane, context));
|
13569 | }
|
13570 |
|
13571 | function handleLaneSets(laneSets, context) {
|
13572 | forEach(laneSets, contextual(handleLaneSet, context));
|
13573 | }
|
13574 |
|
13575 | function handleFlowElementsContainer(container, context) {
|
13576 | handleFlowElements(container.flowElements, context);
|
13577 |
|
13578 | if (container.laneSets) {
|
13579 | handleLaneSets(container.laneSets, context);
|
13580 | }
|
13581 | }
|
13582 |
|
13583 | function handleFlowElements(flowElements, context) {
|
13584 | forEach(flowElements, function(e) {
|
13585 | if (is(e, 'bpmn:SequenceFlow')) {
|
13586 | deferred.push(function() {
|
13587 | handleSequenceFlow(e, context);
|
13588 | });
|
13589 | } else if (is(e, 'bpmn:BoundaryEvent')) {
|
13590 | deferred.unshift(function() {
|
13591 | handleFlowNode(e, context);
|
13592 | });
|
13593 | } else if (is(e, 'bpmn:FlowNode')) {
|
13594 | handleFlowNode(e, context);
|
13595 | } else if (is(e, 'bpmn:DataObject')) ; else if (is(e, 'bpmn:DataStoreReference')) {
|
13596 | handleDataElement(e, context);
|
13597 | } else if (is(e, 'bpmn:DataObjectReference')) {
|
13598 | handleDataElement(e, context);
|
13599 | } else {
|
13600 | logError(
|
13601 | translate('unrecognized flowElement {element} in context {context}', {
|
13602 | element: elementToString(e),
|
13603 | context: (context ? elementToString(context.businessObject) : 'null')
|
13604 | }),
|
13605 | { element: e, context: context }
|
13606 | );
|
13607 | }
|
13608 | });
|
13609 | }
|
13610 |
|
13611 | function handleParticipant(participant, context) {
|
13612 | var newCtx = visitIfDi(participant, context);
|
13613 |
|
13614 | var process = participant.processRef;
|
13615 | if (process) {
|
13616 | handleProcess(process, newCtx || context);
|
13617 | }
|
13618 | }
|
13619 |
|
13620 | function handleCollaboration(collaboration) {
|
13621 |
|
13622 | forEach(collaboration.participants, contextual(handleParticipant));
|
13623 |
|
13624 | handleArtifacts(collaboration.artifacts);
|
13625 |
|
13626 |
|
13627 | deferred.push(function() {
|
13628 | handleMessageFlows(collaboration.messageFlows);
|
13629 | });
|
13630 | }
|
13631 |
|
13632 |
|
13633 | function wireFlowNodeRefs(lane) {
|
13634 |
|
13635 |
|
13636 | forEach(lane.flowNodeRef, function(flowNode) {
|
13637 | var lanes = flowNode.get('lanes');
|
13638 |
|
13639 | if (lanes) {
|
13640 | lanes.push(lane);
|
13641 | }
|
13642 | });
|
13643 | }
|
13644 |
|
13645 |
|
13646 |
|
13647 | return {
|
13648 | handleDeferred: handleDeferred,
|
13649 | handleDefinitions: handleDefinitions,
|
13650 | handleSubProcess: handleSubProcess,
|
13651 | registerDi: registerDi
|
13652 | };
|
13653 | }
|
13654 |
|
13655 | |
13656 |
|
13657 |
|
13658 |
|
13659 |
|
13660 |
|
13661 |
|
13662 |
|
13663 |
|
13664 |
|
13665 |
|
13666 | function importBpmnDiagram(diagram, definitions, bpmnDiagram, done) {
|
13667 |
|
13668 | if (isFunction(bpmnDiagram)) {
|
13669 | done = bpmnDiagram;
|
13670 | bpmnDiagram = null;
|
13671 | }
|
13672 |
|
13673 | var importer,
|
13674 | eventBus,
|
13675 | translate;
|
13676 |
|
13677 | var error,
|
13678 | warnings = [];
|
13679 |
|
13680 | |
13681 |
|
13682 |
|
13683 |
|
13684 |
|
13685 |
|
13686 |
|
13687 | function render(definitions, bpmnDiagram) {
|
13688 |
|
13689 | var visitor = {
|
13690 |
|
13691 | root: function(element) {
|
13692 | return importer.add(element);
|
13693 | },
|
13694 |
|
13695 | element: function(element, parentShape) {
|
13696 | return importer.add(element, parentShape);
|
13697 | },
|
13698 |
|
13699 | error: function(message, context) {
|
13700 | warnings.push({ message: message, context: context });
|
13701 | }
|
13702 | };
|
13703 |
|
13704 | var walker = new BpmnTreeWalker(visitor, translate);
|
13705 |
|
13706 |
|
13707 |
|
13708 | walker.handleDefinitions(definitions, bpmnDiagram);
|
13709 | }
|
13710 |
|
13711 | try {
|
13712 | importer = diagram.get('bpmnImporter');
|
13713 | eventBus = diagram.get('eventBus');
|
13714 | translate = diagram.get('translate');
|
13715 |
|
13716 | eventBus.fire('import.render.start', { definitions: definitions });
|
13717 |
|
13718 | render(definitions, bpmnDiagram);
|
13719 |
|
13720 | eventBus.fire('import.render.complete', {
|
13721 | error: error,
|
13722 | warnings: warnings
|
13723 | });
|
13724 | } catch (e) {
|
13725 | error = e;
|
13726 | }
|
13727 |
|
13728 | done(error, warnings);
|
13729 | }
|
13730 |
|
13731 | |
13732 |
|
13733 |
|
13734 |
|
13735 |
|
13736 |
|
13737 |
|
13738 |
|
13739 | function is$1(element, type) {
|
13740 | var bo = getBusinessObject(element);
|
13741 |
|
13742 | return bo && (typeof bo.$instanceOf === 'function') && bo.$instanceOf(type);
|
13743 | }
|
13744 |
|
13745 |
|
13746 | |
13747 |
|
13748 |
|
13749 |
|
13750 |
|
13751 |
|
13752 |
|
13753 | function getBusinessObject(element) {
|
13754 | return (element && element.businessObject) || element;
|
13755 | }
|
13756 |
|
13757 | function isExpanded(element) {
|
13758 |
|
13759 | if (is$1(element, 'bpmn:CallActivity')) {
|
13760 | return false;
|
13761 | }
|
13762 |
|
13763 | if (is$1(element, 'bpmn:SubProcess')) {
|
13764 | return !!getBusinessObject(element).di.isExpanded;
|
13765 | }
|
13766 |
|
13767 | if (is$1(element, 'bpmn:Participant')) {
|
13768 | return !!getBusinessObject(element).processRef;
|
13769 | }
|
13770 |
|
13771 | return true;
|
13772 | }
|
13773 |
|
13774 | function isInterrupting(element) {
|
13775 | return element && getBusinessObject(element).isInterrupting !== false;
|
13776 | }
|
13777 |
|
13778 | function isEventSubProcess(element) {
|
13779 | return element && !!getBusinessObject(element).triggeredByEvent;
|
13780 | }
|
13781 |
|
13782 | function hasEventDefinition(element, eventType) {
|
13783 | var bo = getBusinessObject(element),
|
13784 | hasEventDefinition = false;
|
13785 |
|
13786 | if (bo.eventDefinitions) {
|
13787 | forEach(bo.eventDefinitions, function(event) {
|
13788 | if (is$1(event, eventType)) {
|
13789 | hasEventDefinition = true;
|
13790 | }
|
13791 | });
|
13792 | }
|
13793 |
|
13794 | return hasEventDefinition;
|
13795 | }
|
13796 |
|
13797 | function hasErrorEventDefinition(element) {
|
13798 | return hasEventDefinition(element, 'bpmn:ErrorEventDefinition');
|
13799 | }
|
13800 |
|
13801 | function hasEscalationEventDefinition(element) {
|
13802 | return hasEventDefinition(element, 'bpmn:EscalationEventDefinition');
|
13803 | }
|
13804 |
|
13805 | function hasCompensateEventDefinition(element) {
|
13806 | return hasEventDefinition(element, 'bpmn:CompensateEventDefinition');
|
13807 | }
|
13808 |
|
13809 | function getLabelAttr(semantic) {
|
13810 | if (
|
13811 | is$1(semantic, 'bpmn:FlowElement') ||
|
13812 | is$1(semantic, 'bpmn:Participant') ||
|
13813 | is$1(semantic, 'bpmn:Lane') ||
|
13814 | is$1(semantic, 'bpmn:SequenceFlow') ||
|
13815 | is$1(semantic, 'bpmn:MessageFlow') ||
|
13816 | is$1(semantic, 'bpmn:DataInput') ||
|
13817 | is$1(semantic, 'bpmn:DataOutput')
|
13818 | ) {
|
13819 | return 'name';
|
13820 | }
|
13821 |
|
13822 | if (is$1(semantic, 'bpmn:TextAnnotation')) {
|
13823 | return 'text';
|
13824 | }
|
13825 |
|
13826 | if (is$1(semantic, 'bpmn:Group')) {
|
13827 | return 'categoryValueRef';
|
13828 | }
|
13829 | }
|
13830 |
|
13831 | function getCategoryValue(semantic) {
|
13832 | var categoryValueRef = semantic['categoryValueRef'];
|
13833 |
|
13834 | if (!categoryValueRef) {
|
13835 | return '';
|
13836 | }
|
13837 |
|
13838 |
|
13839 | return categoryValueRef.value || '';
|
13840 | }
|
13841 |
|
13842 | function getLabel(element) {
|
13843 | var semantic = element.businessObject,
|
13844 | attr = getLabelAttr(semantic);
|
13845 |
|
13846 | if (attr) {
|
13847 |
|
13848 | if (attr === 'categoryValueRef') {
|
13849 |
|
13850 | return getCategoryValue(semantic);
|
13851 | }
|
13852 |
|
13853 | return semantic[attr] || '';
|
13854 | }
|
13855 | }
|
13856 |
|
13857 |
|
13858 | function setLabel(element, text, isExternal) {
|
13859 | var semantic = element.businessObject,
|
13860 | attr = getLabelAttr(semantic);
|
13861 |
|
13862 | if (attr) {
|
13863 |
|
13864 | if (attr === 'categoryValueRef') {
|
13865 | semantic['categoryValueRef'].value = text;
|
13866 | } else {
|
13867 | semantic[attr] = text;
|
13868 | }
|
13869 |
|
13870 | }
|
13871 |
|
13872 | return element;
|
13873 | }
|
13874 |
|
13875 |
|
13876 |
|
13877 | |
13878 |
|
13879 |
|
13880 |
|
13881 |
|
13882 | function isTypedEvent(event, eventDefinitionType, filter) {
|
13883 |
|
13884 | function matches(definition, filter) {
|
13885 | return every(filter, function(val, key) {
|
13886 |
|
13887 |
|
13888 |
|
13889 |
|
13890 | return definition[key] == val;
|
13891 | });
|
13892 | }
|
13893 |
|
13894 | return some(event.eventDefinitions, function(definition) {
|
13895 | return definition.$type === eventDefinitionType && matches(event, filter);
|
13896 | });
|
13897 | }
|
13898 |
|
13899 | function isThrowEvent(event) {
|
13900 | return (event.$type === 'bpmn:IntermediateThrowEvent') || (event.$type === 'bpmn:EndEvent');
|
13901 | }
|
13902 |
|
13903 | function isCollection(element) {
|
13904 | var dataObject = element.dataObjectRef;
|
13905 |
|
13906 | return element.isCollection || (dataObject && dataObject.isCollection);
|
13907 | }
|
13908 |
|
13909 | function getDi(element) {
|
13910 | return element.businessObject.di;
|
13911 | }
|
13912 |
|
13913 | function getSemantic(element) {
|
13914 | return element.businessObject;
|
13915 | }
|
13916 |
|
13917 |
|
13918 |
|
13919 |
|
13920 | function getFillColor(element, defaultColor) {
|
13921 | return getDi(element).get('bioc:fill') || defaultColor || 'white';
|
13922 | }
|
13923 |
|
13924 | function getStrokeColor(element, defaultColor) {
|
13925 | return getDi(element).get('bioc:stroke') || defaultColor || 'black';
|
13926 | }
|
13927 |
|
13928 |
|
13929 |
|
13930 |
|
13931 | function getCirclePath(shape) {
|
13932 |
|
13933 | var cx = shape.x + shape.width / 2,
|
13934 | cy = shape.y + shape.height / 2,
|
13935 | radius = shape.width / 2;
|
13936 |
|
13937 | var circlePath = [
|
13938 | ['M', cx, cy],
|
13939 | ['m', 0, -radius],
|
13940 | ['a', radius, radius, 0, 1, 1, 0, 2 * radius],
|
13941 | ['a', radius, radius, 0, 1, 1, 0, -2 * radius],
|
13942 | ['z']
|
13943 | ];
|
13944 |
|
13945 | return componentsToPath(circlePath);
|
13946 | }
|
13947 |
|
13948 | function getRoundRectPath(shape, borderRadius) {
|
13949 |
|
13950 | var x = shape.x,
|
13951 | y = shape.y,
|
13952 | width = shape.width,
|
13953 | height = shape.height;
|
13954 |
|
13955 | var roundRectPath = [
|
13956 | ['M', x + borderRadius, y],
|
13957 | ['l', width - borderRadius * 2, 0],
|
13958 | ['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, borderRadius],
|
13959 | ['l', 0, height - borderRadius * 2],
|
13960 | ['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, borderRadius],
|
13961 | ['l', borderRadius * 2 - width, 0],
|
13962 | ['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, -borderRadius],
|
13963 | ['l', 0, borderRadius * 2 - height],
|
13964 | ['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, -borderRadius],
|
13965 | ['z']
|
13966 | ];
|
13967 |
|
13968 | return componentsToPath(roundRectPath);
|
13969 | }
|
13970 |
|
13971 | function getDiamondPath(shape) {
|
13972 |
|
13973 | var width = shape.width,
|
13974 | height = shape.height,
|
13975 | x = shape.x,
|
13976 | y = shape.y,
|
13977 | halfWidth = width / 2,
|
13978 | halfHeight = height / 2;
|
13979 |
|
13980 | var diamondPath = [
|
13981 | ['M', x + halfWidth, y],
|
13982 | ['l', halfWidth, halfHeight],
|
13983 | ['l', -halfWidth, halfHeight],
|
13984 | ['l', -halfWidth, -halfHeight],
|
13985 | ['z']
|
13986 | ];
|
13987 |
|
13988 | return componentsToPath(diamondPath);
|
13989 | }
|
13990 |
|
13991 | function getRectPath(shape) {
|
13992 | var x = shape.x,
|
13993 | y = shape.y,
|
13994 | width = shape.width,
|
13995 | height = shape.height;
|
13996 |
|
13997 | var rectPath = [
|
13998 | ['M', x, y],
|
13999 | ['l', width, 0],
|
14000 | ['l', 0, height],
|
14001 | ['l', -width, 0],
|
14002 | ['z']
|
14003 | ];
|
14004 |
|
14005 | return componentsToPath(rectPath);
|
14006 | }
|
14007 |
|
14008 | var RENDERER_IDS = new Ids();
|
14009 |
|
14010 | var TASK_BORDER_RADIUS = 10;
|
14011 | var INNER_OUTER_DIST = 3;
|
14012 |
|
14013 | var DEFAULT_FILL_OPACITY = .95,
|
14014 | HIGH_FILL_OPACITY = .35;
|
14015 |
|
14016 |
|
14017 | function BpmnRenderer(
|
14018 | config, eventBus, styles, pathMap,
|
14019 | canvas, textRenderer, priority) {
|
14020 |
|
14021 | BaseRenderer.call(this, eventBus, priority);
|
14022 |
|
14023 | var defaultFillColor = config && config.defaultFillColor,
|
14024 | defaultStrokeColor = config && config.defaultStrokeColor;
|
14025 |
|
14026 | var rendererId = RENDERER_IDS.next();
|
14027 |
|
14028 | var markers = {};
|
14029 |
|
14030 | var computeStyle = styles.computeStyle;
|
14031 |
|
14032 | function addMarker(id, options) {
|
14033 | var attrs = assign({
|
14034 | fill: 'black',
|
14035 | strokeWidth: 1,
|
14036 | strokeLinecap: 'round',
|
14037 | strokeDasharray: 'none'
|
14038 | }, options.attrs);
|
14039 |
|
14040 | var ref = options.ref || { x: 0, y: 0 };
|
14041 |
|
14042 | var scale = options.scale || 1;
|
14043 |
|
14044 |
|
14045 |
|
14046 | if (attrs.strokeDasharray === 'none') {
|
14047 | attrs.strokeDasharray = [10000, 1];
|
14048 | }
|
14049 |
|
14050 | var marker = create('marker');
|
14051 |
|
14052 | attr$1(options.element, attrs);
|
14053 |
|
14054 | append(marker, options.element);
|
14055 |
|
14056 | attr$1(marker, {
|
14057 | id: id,
|
14058 | viewBox: '0 0 20 20',
|
14059 | refX: ref.x,
|
14060 | refY: ref.y,
|
14061 | markerWidth: 20 * scale,
|
14062 | markerHeight: 20 * scale,
|
14063 | orient: 'auto'
|
14064 | });
|
14065 |
|
14066 | var defs = query('defs', canvas._svg);
|
14067 |
|
14068 | if (!defs) {
|
14069 | defs = create('defs');
|
14070 |
|
14071 | append(canvas._svg, defs);
|
14072 | }
|
14073 |
|
14074 | append(defs, marker);
|
14075 |
|
14076 | markers[id] = marker;
|
14077 | }
|
14078 |
|
14079 | function colorEscape(str) {
|
14080 | return str.replace(/[()\s,#]+/g, '_');
|
14081 | }
|
14082 |
|
14083 | function marker(type, fill, stroke) {
|
14084 | var id = type + '-' + colorEscape(fill) + '-' + colorEscape(stroke) + '-' + rendererId;
|
14085 |
|
14086 | if (!markers[id]) {
|
14087 | createMarker(id, type, fill, stroke);
|
14088 | }
|
14089 |
|
14090 | return 'url(#' + id + ')';
|
14091 | }
|
14092 |
|
14093 | function createMarker(id, type, fill, stroke) {
|
14094 |
|
14095 | if (type === 'sequenceflow-end') {
|
14096 | var sequenceflowEnd = create('path');
|
14097 | attr$1(sequenceflowEnd, { d: 'M 1 5 L 11 10 L 1 15 Z' });
|
14098 |
|
14099 | addMarker(id, {
|
14100 | element: sequenceflowEnd,
|
14101 | ref: { x: 11, y: 10 },
|
14102 | scale: 0.5,
|
14103 | attrs: {
|
14104 | fill: stroke,
|
14105 | stroke: stroke
|
14106 | }
|
14107 | });
|
14108 | }
|
14109 |
|
14110 | if (type === 'messageflow-start') {
|
14111 | var messageflowStart = create('circle');
|
14112 | attr$1(messageflowStart, { cx: 6, cy: 6, r: 3.5 });
|
14113 |
|
14114 | addMarker(id, {
|
14115 | element: messageflowStart,
|
14116 | attrs: {
|
14117 | fill: fill,
|
14118 | stroke: stroke
|
14119 | },
|
14120 | ref: { x: 6, y: 6 }
|
14121 | });
|
14122 | }
|
14123 |
|
14124 | if (type === 'messageflow-end') {
|
14125 | var messageflowEnd = create('path');
|
14126 | attr$1(messageflowEnd, { d: 'm 1 5 l 0 -3 l 7 3 l -7 3 z' });
|
14127 |
|
14128 | addMarker(id, {
|
14129 | element: messageflowEnd,
|
14130 | attrs: {
|
14131 | fill: fill,
|
14132 | stroke: stroke,
|
14133 | strokeLinecap: 'butt'
|
14134 | },
|
14135 | ref: { x: 8.5, y: 5 }
|
14136 | });
|
14137 | }
|
14138 |
|
14139 | if (type === 'association-start') {
|
14140 | var associationStart = create('path');
|
14141 | attr$1(associationStart, { d: 'M 11 5 L 1 10 L 11 15' });
|
14142 |
|
14143 | addMarker(id, {
|
14144 | element: associationStart,
|
14145 | attrs: {
|
14146 | fill: 'none',
|
14147 | stroke: stroke,
|
14148 | strokeWidth: 1.5
|
14149 | },
|
14150 | ref: { x: 1, y: 10 },
|
14151 | scale: 0.5
|
14152 | });
|
14153 | }
|
14154 |
|
14155 | if (type === 'association-end') {
|
14156 | var associationEnd = create('path');
|
14157 | attr$1(associationEnd, { d: 'M 1 5 L 11 10 L 1 15' });
|
14158 |
|
14159 | addMarker(id, {
|
14160 | element: associationEnd,
|
14161 | attrs: {
|
14162 | fill: 'none',
|
14163 | stroke: stroke,
|
14164 | strokeWidth: 1.5
|
14165 | },
|
14166 | ref: { x: 12, y: 10 },
|
14167 | scale: 0.5
|
14168 | });
|
14169 | }
|
14170 |
|
14171 | if (type === 'conditional-flow-marker') {
|
14172 | var conditionalflowMarker = create('path');
|
14173 | attr$1(conditionalflowMarker, { d: 'M 0 10 L 8 6 L 16 10 L 8 14 Z' });
|
14174 |
|
14175 | addMarker(id, {
|
14176 | element: conditionalflowMarker,
|
14177 | attrs: {
|
14178 | fill: fill,
|
14179 | stroke: stroke
|
14180 | },
|
14181 | ref: { x: -1, y: 10 },
|
14182 | scale: 0.5
|
14183 | });
|
14184 | }
|
14185 |
|
14186 | if (type === 'conditional-default-flow-marker') {
|
14187 | var conditionaldefaultflowMarker = create('path');
|
14188 | attr$1(conditionaldefaultflowMarker, { d: 'M 6 4 L 10 16' });
|
14189 |
|
14190 | addMarker(id, {
|
14191 | element: conditionaldefaultflowMarker,
|
14192 | attrs: {
|
14193 | stroke: stroke
|
14194 | },
|
14195 | ref: { x: 0, y: 10 },
|
14196 | scale: 0.5
|
14197 | });
|
14198 | }
|
14199 | }
|
14200 |
|
14201 | function drawCircle(parentGfx, width, height, offset, attrs) {
|
14202 |
|
14203 | if (isObject(offset)) {
|
14204 | attrs = offset;
|
14205 | offset = 0;
|
14206 | }
|
14207 |
|
14208 | offset = offset || 0;
|
14209 |
|
14210 | attrs = computeStyle(attrs, {
|
14211 | stroke: 'black',
|
14212 | strokeWidth: 2,
|
14213 | fill: 'white'
|
14214 | });
|
14215 |
|
14216 | if (attrs.fill === 'none') {
|
14217 | delete attrs.fillOpacity;
|
14218 | }
|
14219 |
|
14220 | var cx = width / 2,
|
14221 | cy = height / 2;
|
14222 |
|
14223 | var circle = create('circle');
|
14224 | attr$1(circle, {
|
14225 | cx: cx,
|
14226 | cy: cy,
|
14227 | r: Math.round((width + height) / 4 - offset)
|
14228 | });
|
14229 | attr$1(circle, attrs);
|
14230 |
|
14231 | append(parentGfx, circle);
|
14232 |
|
14233 | return circle;
|
14234 | }
|
14235 |
|
14236 | function drawRect(parentGfx, width, height, r, offset, attrs) {
|
14237 |
|
14238 | if (isObject(offset)) {
|
14239 | attrs = offset;
|
14240 | offset = 0;
|
14241 | }
|
14242 |
|
14243 | offset = offset || 0;
|
14244 |
|
14245 | attrs = computeStyle(attrs, {
|
14246 | stroke: 'black',
|
14247 | strokeWidth: 2,
|
14248 | fill: 'white'
|
14249 | });
|
14250 |
|
14251 | var rect = create('rect');
|
14252 | attr$1(rect, {
|
14253 | x: offset,
|
14254 | y: offset,
|
14255 | width: width - offset * 2,
|
14256 | height: height - offset * 2,
|
14257 | rx: r,
|
14258 | ry: r
|
14259 | });
|
14260 | attr$1(rect, attrs);
|
14261 |
|
14262 | append(parentGfx, rect);
|
14263 |
|
14264 | return rect;
|
14265 | }
|
14266 |
|
14267 | function drawDiamond(parentGfx, width, height, attrs) {
|
14268 |
|
14269 | var x_2 = width / 2;
|
14270 | var y_2 = height / 2;
|
14271 |
|
14272 | var points = [{ x: x_2, y: 0 }, { x: width, y: y_2 }, { x: x_2, y: height }, { x: 0, y: y_2 }];
|
14273 |
|
14274 | var pointsString = points.map(function(point) {
|
14275 | return point.x + ',' + point.y;
|
14276 | }).join(' ');
|
14277 |
|
14278 | attrs = computeStyle(attrs, {
|
14279 | stroke: 'black',
|
14280 | strokeWidth: 2,
|
14281 | fill: 'white'
|
14282 | });
|
14283 |
|
14284 | var polygon = create('polygon');
|
14285 | attr$1(polygon, {
|
14286 | points: pointsString
|
14287 | });
|
14288 | attr$1(polygon, attrs);
|
14289 |
|
14290 | append(parentGfx, polygon);
|
14291 |
|
14292 | return polygon;
|
14293 | }
|
14294 |
|
14295 | function drawLine(parentGfx, waypoints, attrs) {
|
14296 | attrs = computeStyle(attrs, [ 'no-fill' ], {
|
14297 | stroke: 'black',
|
14298 | strokeWidth: 2,
|
14299 | fill: 'none'
|
14300 | });
|
14301 |
|
14302 | var line = createLine(waypoints, attrs);
|
14303 |
|
14304 | append(parentGfx, line);
|
14305 |
|
14306 | return line;
|
14307 | }
|
14308 |
|
14309 | function drawPath(parentGfx, d, attrs) {
|
14310 |
|
14311 | attrs = computeStyle(attrs, [ 'no-fill' ], {
|
14312 | strokeWidth: 2,
|
14313 | stroke: 'black'
|
14314 | });
|
14315 |
|
14316 | var path = create('path');
|
14317 | attr$1(path, { d: d });
|
14318 | attr$1(path, attrs);
|
14319 |
|
14320 | append(parentGfx, path);
|
14321 |
|
14322 | return path;
|
14323 | }
|
14324 |
|
14325 | function drawMarker(type, parentGfx, path, attrs) {
|
14326 | return drawPath(parentGfx, path, assign({ 'data-marker': type }, attrs));
|
14327 | }
|
14328 |
|
14329 | function as(type) {
|
14330 | return function(parentGfx, element) {
|
14331 | return handlers[type](parentGfx, element);
|
14332 | };
|
14333 | }
|
14334 |
|
14335 | function renderer(type) {
|
14336 | return handlers[type];
|
14337 | }
|
14338 |
|
14339 | function renderEventContent(element, parentGfx) {
|
14340 |
|
14341 | var event = getSemantic(element);
|
14342 | var isThrowing = isThrowEvent(event);
|
14343 |
|
14344 | if (event.eventDefinitions && event.eventDefinitions.length>1) {
|
14345 | if (event.parallelMultiple) {
|
14346 | return renderer('bpmn:ParallelMultipleEventDefinition')(parentGfx, element, isThrowing);
|
14347 | }
|
14348 | else {
|
14349 | return renderer('bpmn:MultipleEventDefinition')(parentGfx, element, isThrowing);
|
14350 | }
|
14351 | }
|
14352 |
|
14353 | if (isTypedEvent(event, 'bpmn:MessageEventDefinition')) {
|
14354 | return renderer('bpmn:MessageEventDefinition')(parentGfx, element, isThrowing);
|
14355 | }
|
14356 |
|
14357 | if (isTypedEvent(event, 'bpmn:TimerEventDefinition')) {
|
14358 | return renderer('bpmn:TimerEventDefinition')(parentGfx, element, isThrowing);
|
14359 | }
|
14360 |
|
14361 | if (isTypedEvent(event, 'bpmn:ConditionalEventDefinition')) {
|
14362 | return renderer('bpmn:ConditionalEventDefinition')(parentGfx, element);
|
14363 | }
|
14364 |
|
14365 | if (isTypedEvent(event, 'bpmn:SignalEventDefinition')) {
|
14366 | return renderer('bpmn:SignalEventDefinition')(parentGfx, element, isThrowing);
|
14367 | }
|
14368 |
|
14369 | if (isTypedEvent(event, 'bpmn:EscalationEventDefinition')) {
|
14370 | return renderer('bpmn:EscalationEventDefinition')(parentGfx, element, isThrowing);
|
14371 | }
|
14372 |
|
14373 | if (isTypedEvent(event, 'bpmn:LinkEventDefinition')) {
|
14374 | return renderer('bpmn:LinkEventDefinition')(parentGfx, element, isThrowing);
|
14375 | }
|
14376 |
|
14377 | if (isTypedEvent(event, 'bpmn:ErrorEventDefinition')) {
|
14378 | return renderer('bpmn:ErrorEventDefinition')(parentGfx, element, isThrowing);
|
14379 | }
|
14380 |
|
14381 | if (isTypedEvent(event, 'bpmn:CancelEventDefinition')) {
|
14382 | return renderer('bpmn:CancelEventDefinition')(parentGfx, element, isThrowing);
|
14383 | }
|
14384 |
|
14385 | if (isTypedEvent(event, 'bpmn:CompensateEventDefinition')) {
|
14386 | return renderer('bpmn:CompensateEventDefinition')(parentGfx, element, isThrowing);
|
14387 | }
|
14388 |
|
14389 | if (isTypedEvent(event, 'bpmn:TerminateEventDefinition')) {
|
14390 | return renderer('bpmn:TerminateEventDefinition')(parentGfx, element, isThrowing);
|
14391 | }
|
14392 |
|
14393 | return null;
|
14394 | }
|
14395 |
|
14396 | function renderLabel(parentGfx, label, options) {
|
14397 |
|
14398 | options = assign({
|
14399 | size: {
|
14400 | width: 100
|
14401 | }
|
14402 | }, options);
|
14403 |
|
14404 | var text = textRenderer.createText(label || '', options);
|
14405 |
|
14406 | classes$1(text).add('djs-label');
|
14407 |
|
14408 | append(parentGfx, text);
|
14409 |
|
14410 | return text;
|
14411 | }
|
14412 |
|
14413 | function renderEmbeddedLabel(parentGfx, element, align) {
|
14414 | var semantic = getSemantic(element);
|
14415 |
|
14416 | return renderLabel(parentGfx, semantic.name, {
|
14417 | box: element,
|
14418 | align: align,
|
14419 | padding: 5,
|
14420 | style: {
|
14421 | fill: getStrokeColor(element, defaultStrokeColor)
|
14422 | }
|
14423 | });
|
14424 | }
|
14425 |
|
14426 | function renderExternalLabel(parentGfx, element) {
|
14427 |
|
14428 | var box = {
|
14429 | width: 90,
|
14430 | height: 30,
|
14431 | x: element.width / 2 + element.x,
|
14432 | y: element.height / 2 + element.y
|
14433 | };
|
14434 |
|
14435 | return renderLabel(parentGfx, getLabel(element), {
|
14436 | box: box,
|
14437 | fitBox: true,
|
14438 | style: assign(
|
14439 | {},
|
14440 | textRenderer.getExternalStyle(),
|
14441 | {
|
14442 | fill: getStrokeColor(element, defaultStrokeColor)
|
14443 | }
|
14444 | )
|
14445 | });
|
14446 | }
|
14447 |
|
14448 | function renderLaneLabel(parentGfx, text, element) {
|
14449 | var textBox = renderLabel(parentGfx, text, {
|
14450 | box: {
|
14451 | height: 30,
|
14452 | width: element.height
|
14453 | },
|
14454 | align: 'center-middle',
|
14455 | style: {
|
14456 | fill: getStrokeColor(element, defaultStrokeColor)
|
14457 | }
|
14458 | });
|
14459 |
|
14460 | var top = -1 * element.height;
|
14461 |
|
14462 | transform$1(textBox, 0, -top, 270);
|
14463 | }
|
14464 |
|
14465 | function createPathFromConnection(connection) {
|
14466 | var waypoints = connection.waypoints;
|
14467 |
|
14468 | var pathData = 'm ' + waypoints[0].x + ',' + waypoints[0].y;
|
14469 | for (var i = 1; i < waypoints.length; i++) {
|
14470 | pathData += 'L' + waypoints[i].x + ',' + waypoints[i].y + ' ';
|
14471 | }
|
14472 | return pathData;
|
14473 | }
|
14474 |
|
14475 | var handlers = this.handlers = {
|
14476 | 'bpmn:Event': function(parentGfx, element, attrs) {
|
14477 |
|
14478 | if (!('fillOpacity' in attrs)) {
|
14479 | attrs.fillOpacity = DEFAULT_FILL_OPACITY;
|
14480 | }
|
14481 |
|
14482 | return drawCircle(parentGfx, element.width, element.height, attrs);
|
14483 | },
|
14484 | 'bpmn:StartEvent': function(parentGfx, element) {
|
14485 | var attrs = {
|
14486 | fill: getFillColor(element, defaultFillColor),
|
14487 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14488 | };
|
14489 |
|
14490 | var semantic = getSemantic(element);
|
14491 |
|
14492 | if (!semantic.isInterrupting) {
|
14493 | attrs = {
|
14494 | strokeDasharray: '6',
|
14495 | strokeLinecap: 'round',
|
14496 | fill: getFillColor(element, defaultFillColor),
|
14497 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14498 | };
|
14499 | }
|
14500 |
|
14501 | var circle = renderer('bpmn:Event')(parentGfx, element, attrs);
|
14502 |
|
14503 | renderEventContent(element, parentGfx);
|
14504 |
|
14505 | return circle;
|
14506 | },
|
14507 | 'bpmn:MessageEventDefinition': function(parentGfx, element, isThrowing) {
|
14508 | var pathData = pathMap.getScaledPath('EVENT_MESSAGE', {
|
14509 | xScaleFactor: 0.9,
|
14510 | yScaleFactor: 0.9,
|
14511 | containerWidth: element.width,
|
14512 | containerHeight: element.height,
|
14513 | position: {
|
14514 | mx: 0.235,
|
14515 | my: 0.315
|
14516 | }
|
14517 | });
|
14518 |
|
14519 | var fill = isThrowing ? getStrokeColor(element, defaultStrokeColor) : getFillColor(element, defaultFillColor);
|
14520 | var stroke = isThrowing ? getFillColor(element, defaultFillColor) : getStrokeColor(element, defaultStrokeColor);
|
14521 |
|
14522 | var messagePath = drawPath(parentGfx, pathData, {
|
14523 | strokeWidth: 1,
|
14524 | fill: fill,
|
14525 | stroke: stroke
|
14526 | });
|
14527 |
|
14528 | return messagePath;
|
14529 | },
|
14530 | 'bpmn:TimerEventDefinition': function(parentGfx, element) {
|
14531 | var circle = drawCircle(parentGfx, element.width, element.height, 0.2 * element.height, {
|
14532 | strokeWidth: 2,
|
14533 | fill: getFillColor(element, defaultFillColor),
|
14534 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14535 | });
|
14536 |
|
14537 | var pathData = pathMap.getScaledPath('EVENT_TIMER_WH', {
|
14538 | xScaleFactor: 0.75,
|
14539 | yScaleFactor: 0.75,
|
14540 | containerWidth: element.width,
|
14541 | containerHeight: element.height,
|
14542 | position: {
|
14543 | mx: 0.5,
|
14544 | my: 0.5
|
14545 | }
|
14546 | });
|
14547 |
|
14548 | drawPath(parentGfx, pathData, {
|
14549 | strokeWidth: 2,
|
14550 | strokeLinecap: 'square',
|
14551 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14552 | });
|
14553 |
|
14554 | for (var i = 0;i < 12; i++) {
|
14555 |
|
14556 | var linePathData = pathMap.getScaledPath('EVENT_TIMER_LINE', {
|
14557 | xScaleFactor: 0.75,
|
14558 | yScaleFactor: 0.75,
|
14559 | containerWidth: element.width,
|
14560 | containerHeight: element.height,
|
14561 | position: {
|
14562 | mx: 0.5,
|
14563 | my: 0.5
|
14564 | }
|
14565 | });
|
14566 |
|
14567 | var width = element.width / 2;
|
14568 | var height = element.height / 2;
|
14569 |
|
14570 | drawPath(parentGfx, linePathData, {
|
14571 | strokeWidth: 1,
|
14572 | strokeLinecap: 'square',
|
14573 | transform: 'rotate(' + (i * 30) + ',' + height + ',' + width + ')',
|
14574 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14575 | });
|
14576 | }
|
14577 |
|
14578 | return circle;
|
14579 | },
|
14580 | 'bpmn:EscalationEventDefinition': function(parentGfx, event, isThrowing) {
|
14581 | var pathData = pathMap.getScaledPath('EVENT_ESCALATION', {
|
14582 | xScaleFactor: 1,
|
14583 | yScaleFactor: 1,
|
14584 | containerWidth: event.width,
|
14585 | containerHeight: event.height,
|
14586 | position: {
|
14587 | mx: 0.5,
|
14588 | my: 0.2
|
14589 | }
|
14590 | });
|
14591 |
|
14592 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
14593 |
|
14594 | return drawPath(parentGfx, pathData, {
|
14595 | strokeWidth: 1,
|
14596 | fill: fill,
|
14597 | stroke: getStrokeColor(event, defaultStrokeColor)
|
14598 | });
|
14599 | },
|
14600 | 'bpmn:ConditionalEventDefinition': function(parentGfx, event) {
|
14601 | var pathData = pathMap.getScaledPath('EVENT_CONDITIONAL', {
|
14602 | xScaleFactor: 1,
|
14603 | yScaleFactor: 1,
|
14604 | containerWidth: event.width,
|
14605 | containerHeight: event.height,
|
14606 | position: {
|
14607 | mx: 0.5,
|
14608 | my: 0.222
|
14609 | }
|
14610 | });
|
14611 |
|
14612 | return drawPath(parentGfx, pathData, {
|
14613 | strokeWidth: 1,
|
14614 | stroke: getStrokeColor(event, defaultStrokeColor)
|
14615 | });
|
14616 | },
|
14617 | 'bpmn:LinkEventDefinition': function(parentGfx, event, isThrowing) {
|
14618 | var pathData = pathMap.getScaledPath('EVENT_LINK', {
|
14619 | xScaleFactor: 1,
|
14620 | yScaleFactor: 1,
|
14621 | containerWidth: event.width,
|
14622 | containerHeight: event.height,
|
14623 | position: {
|
14624 | mx: 0.57,
|
14625 | my: 0.263
|
14626 | }
|
14627 | });
|
14628 |
|
14629 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
14630 |
|
14631 | return drawPath(parentGfx, pathData, {
|
14632 | strokeWidth: 1,
|
14633 | fill: fill,
|
14634 | stroke: getStrokeColor(event, defaultStrokeColor)
|
14635 | });
|
14636 | },
|
14637 | 'bpmn:ErrorEventDefinition': function(parentGfx, event, isThrowing) {
|
14638 | var pathData = pathMap.getScaledPath('EVENT_ERROR', {
|
14639 | xScaleFactor: 1.1,
|
14640 | yScaleFactor: 1.1,
|
14641 | containerWidth: event.width,
|
14642 | containerHeight: event.height,
|
14643 | position: {
|
14644 | mx: 0.2,
|
14645 | my: 0.722
|
14646 | }
|
14647 | });
|
14648 |
|
14649 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
14650 |
|
14651 | return drawPath(parentGfx, pathData, {
|
14652 | strokeWidth: 1,
|
14653 | fill: fill,
|
14654 | stroke: getStrokeColor(event, defaultStrokeColor)
|
14655 | });
|
14656 | },
|
14657 | 'bpmn:CancelEventDefinition': function(parentGfx, event, isThrowing) {
|
14658 | var pathData = pathMap.getScaledPath('EVENT_CANCEL_45', {
|
14659 | xScaleFactor: 1.0,
|
14660 | yScaleFactor: 1.0,
|
14661 | containerWidth: event.width,
|
14662 | containerHeight: event.height,
|
14663 | position: {
|
14664 | mx: 0.638,
|
14665 | my: -0.055
|
14666 | }
|
14667 | });
|
14668 |
|
14669 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
14670 |
|
14671 | var path = drawPath(parentGfx, pathData, {
|
14672 | strokeWidth: 1,
|
14673 | fill: fill,
|
14674 | stroke: getStrokeColor(event, defaultStrokeColor)
|
14675 | });
|
14676 |
|
14677 | rotate(path, 45);
|
14678 |
|
14679 | return path;
|
14680 | },
|
14681 | 'bpmn:CompensateEventDefinition': function(parentGfx, event, isThrowing) {
|
14682 | var pathData = pathMap.getScaledPath('EVENT_COMPENSATION', {
|
14683 | xScaleFactor: 1,
|
14684 | yScaleFactor: 1,
|
14685 | containerWidth: event.width,
|
14686 | containerHeight: event.height,
|
14687 | position: {
|
14688 | mx: 0.22,
|
14689 | my: 0.5
|
14690 | }
|
14691 | });
|
14692 |
|
14693 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
14694 |
|
14695 | return drawPath(parentGfx, pathData, {
|
14696 | strokeWidth: 1,
|
14697 | fill: fill,
|
14698 | stroke: getStrokeColor(event, defaultStrokeColor)
|
14699 | });
|
14700 | },
|
14701 | 'bpmn:SignalEventDefinition': function(parentGfx, event, isThrowing) {
|
14702 | var pathData = pathMap.getScaledPath('EVENT_SIGNAL', {
|
14703 | xScaleFactor: 0.9,
|
14704 | yScaleFactor: 0.9,
|
14705 | containerWidth: event.width,
|
14706 | containerHeight: event.height,
|
14707 | position: {
|
14708 | mx: 0.5,
|
14709 | my: 0.2
|
14710 | }
|
14711 | });
|
14712 |
|
14713 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
14714 |
|
14715 | return drawPath(parentGfx, pathData, {
|
14716 | strokeWidth: 1,
|
14717 | fill: fill,
|
14718 | stroke: getStrokeColor(event, defaultStrokeColor)
|
14719 | });
|
14720 | },
|
14721 | 'bpmn:MultipleEventDefinition': function(parentGfx, event, isThrowing) {
|
14722 | var pathData = pathMap.getScaledPath('EVENT_MULTIPLE', {
|
14723 | xScaleFactor: 1.1,
|
14724 | yScaleFactor: 1.1,
|
14725 | containerWidth: event.width,
|
14726 | containerHeight: event.height,
|
14727 | position: {
|
14728 | mx: 0.222,
|
14729 | my: 0.36
|
14730 | }
|
14731 | });
|
14732 |
|
14733 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
14734 |
|
14735 | return drawPath(parentGfx, pathData, {
|
14736 | strokeWidth: 1,
|
14737 | fill: fill
|
14738 | });
|
14739 | },
|
14740 | 'bpmn:ParallelMultipleEventDefinition': function(parentGfx, event) {
|
14741 | var pathData = pathMap.getScaledPath('EVENT_PARALLEL_MULTIPLE', {
|
14742 | xScaleFactor: 1.2,
|
14743 | yScaleFactor: 1.2,
|
14744 | containerWidth: event.width,
|
14745 | containerHeight: event.height,
|
14746 | position: {
|
14747 | mx: 0.458,
|
14748 | my: 0.194
|
14749 | }
|
14750 | });
|
14751 |
|
14752 | return drawPath(parentGfx, pathData, {
|
14753 | strokeWidth: 1,
|
14754 | fill: getStrokeColor(event, defaultStrokeColor),
|
14755 | stroke: getStrokeColor(event, defaultStrokeColor)
|
14756 | });
|
14757 | },
|
14758 | 'bpmn:EndEvent': function(parentGfx, element) {
|
14759 | var circle = renderer('bpmn:Event')(parentGfx, element, {
|
14760 | strokeWidth: 4,
|
14761 | fill: getFillColor(element, defaultFillColor),
|
14762 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14763 | });
|
14764 |
|
14765 | renderEventContent(element, parentGfx);
|
14766 |
|
14767 | return circle;
|
14768 | },
|
14769 | 'bpmn:TerminateEventDefinition': function(parentGfx, element) {
|
14770 | var circle = drawCircle(parentGfx, element.width, element.height, 8, {
|
14771 | strokeWidth: 4,
|
14772 | fill: getStrokeColor(element, defaultStrokeColor),
|
14773 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14774 | });
|
14775 |
|
14776 | return circle;
|
14777 | },
|
14778 | 'bpmn:IntermediateEvent': function(parentGfx, element) {
|
14779 | var outer = renderer('bpmn:Event')(parentGfx, element, {
|
14780 | strokeWidth: 1,
|
14781 | fill: getFillColor(element, defaultFillColor),
|
14782 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14783 | });
|
14784 |
|
14785 |
|
14786 | drawCircle(parentGfx, element.width, element.height, INNER_OUTER_DIST, {
|
14787 | strokeWidth: 1,
|
14788 | fill: getFillColor(element, 'none'),
|
14789 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14790 | });
|
14791 |
|
14792 | renderEventContent(element, parentGfx);
|
14793 |
|
14794 | return outer;
|
14795 | },
|
14796 | 'bpmn:IntermediateCatchEvent': as('bpmn:IntermediateEvent'),
|
14797 | 'bpmn:IntermediateThrowEvent': as('bpmn:IntermediateEvent'),
|
14798 |
|
14799 | 'bpmn:Activity': function(parentGfx, element, attrs) {
|
14800 |
|
14801 | attrs = attrs || {};
|
14802 |
|
14803 | if (!('fillOpacity' in attrs)) {
|
14804 | attrs.fillOpacity = DEFAULT_FILL_OPACITY;
|
14805 | }
|
14806 |
|
14807 | return drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS, attrs);
|
14808 | },
|
14809 |
|
14810 | 'bpmn:Task': function(parentGfx, element) {
|
14811 | var attrs = {
|
14812 | fill: getFillColor(element, defaultFillColor),
|
14813 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14814 | };
|
14815 |
|
14816 | var rect = renderer('bpmn:Activity')(parentGfx, element, attrs);
|
14817 |
|
14818 | renderEmbeddedLabel(parentGfx, element, 'center-middle');
|
14819 | attachTaskMarkers(parentGfx, element);
|
14820 |
|
14821 | return rect;
|
14822 | },
|
14823 | 'bpmn:ServiceTask': function(parentGfx, element) {
|
14824 | var task = renderer('bpmn:Task')(parentGfx, element);
|
14825 |
|
14826 | var pathDataBG = pathMap.getScaledPath('TASK_TYPE_SERVICE', {
|
14827 | abspos: {
|
14828 | x: 12,
|
14829 | y: 18
|
14830 | }
|
14831 | });
|
14832 |
|
14833 | drawPath(parentGfx, pathDataBG, {
|
14834 | strokeWidth: 1,
|
14835 | fill: getFillColor(element, defaultFillColor),
|
14836 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14837 | });
|
14838 |
|
14839 | var fillPathData = pathMap.getScaledPath('TASK_TYPE_SERVICE_FILL', {
|
14840 | abspos: {
|
14841 | x: 17.2,
|
14842 | y: 18
|
14843 | }
|
14844 | });
|
14845 |
|
14846 | drawPath(parentGfx, fillPathData, {
|
14847 | strokeWidth: 0,
|
14848 | fill: getFillColor(element, defaultFillColor)
|
14849 | });
|
14850 |
|
14851 | var pathData = pathMap.getScaledPath('TASK_TYPE_SERVICE', {
|
14852 | abspos: {
|
14853 | x: 17,
|
14854 | y: 22
|
14855 | }
|
14856 | });
|
14857 |
|
14858 | drawPath(parentGfx, pathData, {
|
14859 | strokeWidth: 1,
|
14860 | fill: getFillColor(element, defaultFillColor),
|
14861 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14862 | });
|
14863 |
|
14864 | return task;
|
14865 | },
|
14866 | 'bpmn:UserTask': function(parentGfx, element) {
|
14867 | var task = renderer('bpmn:Task')(parentGfx, element);
|
14868 |
|
14869 | var x = 15;
|
14870 | var y = 12;
|
14871 |
|
14872 | var pathData = pathMap.getScaledPath('TASK_TYPE_USER_1', {
|
14873 | abspos: {
|
14874 | x: x,
|
14875 | y: y
|
14876 | }
|
14877 | });
|
14878 |
|
14879 | drawPath(parentGfx, pathData, {
|
14880 | strokeWidth: 0.5,
|
14881 | fill: getFillColor(element, defaultFillColor),
|
14882 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14883 | });
|
14884 |
|
14885 | var pathData2 = pathMap.getScaledPath('TASK_TYPE_USER_2', {
|
14886 | abspos: {
|
14887 | x: x,
|
14888 | y: y
|
14889 | }
|
14890 | });
|
14891 |
|
14892 | drawPath(parentGfx, pathData2, {
|
14893 | strokeWidth: 0.5,
|
14894 | fill: getFillColor(element, defaultFillColor),
|
14895 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14896 | });
|
14897 |
|
14898 | var pathData3 = pathMap.getScaledPath('TASK_TYPE_USER_3', {
|
14899 | abspos: {
|
14900 | x: x,
|
14901 | y: y
|
14902 | }
|
14903 | });
|
14904 |
|
14905 | drawPath(parentGfx, pathData3, {
|
14906 | strokeWidth: 0.5,
|
14907 | fill: getStrokeColor(element, defaultStrokeColor),
|
14908 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14909 | });
|
14910 |
|
14911 | return task;
|
14912 | },
|
14913 | 'bpmn:ManualTask': function(parentGfx, element) {
|
14914 | var task = renderer('bpmn:Task')(parentGfx, element);
|
14915 |
|
14916 | var pathData = pathMap.getScaledPath('TASK_TYPE_MANUAL', {
|
14917 | abspos: {
|
14918 | x: 17,
|
14919 | y: 15
|
14920 | }
|
14921 | });
|
14922 |
|
14923 | drawPath(parentGfx, pathData, {
|
14924 | strokeWidth: 0.5,
|
14925 | fill: getFillColor(element, defaultFillColor),
|
14926 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14927 | });
|
14928 |
|
14929 | return task;
|
14930 | },
|
14931 | 'bpmn:SendTask': function(parentGfx, element) {
|
14932 | var task = renderer('bpmn:Task')(parentGfx, element);
|
14933 |
|
14934 | var pathData = pathMap.getScaledPath('TASK_TYPE_SEND', {
|
14935 | xScaleFactor: 1,
|
14936 | yScaleFactor: 1,
|
14937 | containerWidth: 21,
|
14938 | containerHeight: 14,
|
14939 | position: {
|
14940 | mx: 0.285,
|
14941 | my: 0.357
|
14942 | }
|
14943 | });
|
14944 |
|
14945 | drawPath(parentGfx, pathData, {
|
14946 | strokeWidth: 1,
|
14947 | fill: getStrokeColor(element, defaultStrokeColor),
|
14948 | stroke: getFillColor(element, defaultFillColor)
|
14949 | });
|
14950 |
|
14951 | return task;
|
14952 | },
|
14953 | 'bpmn:ReceiveTask' : function(parentGfx, element) {
|
14954 | var semantic = getSemantic(element);
|
14955 |
|
14956 | var task = renderer('bpmn:Task')(parentGfx, element);
|
14957 | var pathData;
|
14958 |
|
14959 | if (semantic.instantiate) {
|
14960 | drawCircle(parentGfx, 28, 28, 20 * 0.22, { strokeWidth: 1 });
|
14961 |
|
14962 | pathData = pathMap.getScaledPath('TASK_TYPE_INSTANTIATING_SEND', {
|
14963 | abspos: {
|
14964 | x: 7.77,
|
14965 | y: 9.52
|
14966 | }
|
14967 | });
|
14968 | } else {
|
14969 |
|
14970 | pathData = pathMap.getScaledPath('TASK_TYPE_SEND', {
|
14971 | xScaleFactor: 0.9,
|
14972 | yScaleFactor: 0.9,
|
14973 | containerWidth: 21,
|
14974 | containerHeight: 14,
|
14975 | position: {
|
14976 | mx: 0.3,
|
14977 | my: 0.4
|
14978 | }
|
14979 | });
|
14980 | }
|
14981 |
|
14982 | drawPath(parentGfx, pathData, {
|
14983 | strokeWidth: 1,
|
14984 | fill: getFillColor(element, defaultFillColor),
|
14985 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14986 | });
|
14987 |
|
14988 | return task;
|
14989 | },
|
14990 | 'bpmn:ScriptTask': function(parentGfx, element) {
|
14991 | var task = renderer('bpmn:Task')(parentGfx, element);
|
14992 |
|
14993 | var pathData = pathMap.getScaledPath('TASK_TYPE_SCRIPT', {
|
14994 | abspos: {
|
14995 | x: 15,
|
14996 | y: 20
|
14997 | }
|
14998 | });
|
14999 |
|
15000 | drawPath(parentGfx, pathData, {
|
15001 | strokeWidth: 1,
|
15002 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15003 | });
|
15004 |
|
15005 | return task;
|
15006 | },
|
15007 | 'bpmn:BusinessRuleTask': function(parentGfx, element) {
|
15008 | var task = renderer('bpmn:Task')(parentGfx, element);
|
15009 |
|
15010 | var headerPathData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_HEADER', {
|
15011 | abspos: {
|
15012 | x: 8,
|
15013 | y: 8
|
15014 | }
|
15015 | });
|
15016 |
|
15017 | var businessHeaderPath = drawPath(parentGfx, headerPathData);
|
15018 | attr$1(businessHeaderPath, {
|
15019 | strokeWidth: 1,
|
15020 | fill: getFillColor(element, '#aaaaaa'),
|
15021 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15022 | });
|
15023 |
|
15024 | var headerData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_MAIN', {
|
15025 | abspos: {
|
15026 | x: 8,
|
15027 | y: 8
|
15028 | }
|
15029 | });
|
15030 |
|
15031 | var businessPath = drawPath(parentGfx, headerData);
|
15032 | attr$1(businessPath, {
|
15033 | strokeWidth: 1,
|
15034 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15035 | });
|
15036 |
|
15037 | return task;
|
15038 | },
|
15039 | 'bpmn:SubProcess': function(parentGfx, element, attrs) {
|
15040 | attrs = assign({
|
15041 | fill: getFillColor(element, defaultFillColor),
|
15042 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15043 | }, attrs);
|
15044 |
|
15045 | var rect = renderer('bpmn:Activity')(parentGfx, element, attrs);
|
15046 |
|
15047 | var expanded = isExpanded(element);
|
15048 |
|
15049 | if (isEventSubProcess(element)) {
|
15050 | attr$1(rect, {
|
15051 | strokeDasharray: '1,2'
|
15052 | });
|
15053 | }
|
15054 |
|
15055 | renderEmbeddedLabel(parentGfx, element, expanded ? 'center-top' : 'center-middle');
|
15056 |
|
15057 | if (expanded) {
|
15058 | attachTaskMarkers(parentGfx, element);
|
15059 | } else {
|
15060 | attachTaskMarkers(parentGfx, element, ['SubProcessMarker']);
|
15061 | }
|
15062 |
|
15063 | return rect;
|
15064 | },
|
15065 | 'bpmn:AdHocSubProcess': function(parentGfx, element) {
|
15066 | return renderer('bpmn:SubProcess')(parentGfx, element);
|
15067 | },
|
15068 | 'bpmn:Transaction': function(parentGfx, element) {
|
15069 | var outer = renderer('bpmn:SubProcess')(parentGfx, element);
|
15070 |
|
15071 | var innerAttrs = styles.style([ 'no-fill', 'no-events' ], {
|
15072 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15073 | });
|
15074 |
|
15075 | drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS - 2, INNER_OUTER_DIST, innerAttrs);
|
15076 |
|
15077 | return outer;
|
15078 | },
|
15079 | 'bpmn:CallActivity': function(parentGfx, element) {
|
15080 | return renderer('bpmn:SubProcess')(parentGfx, element, {
|
15081 | strokeWidth: 5
|
15082 | });
|
15083 | },
|
15084 | 'bpmn:Participant': function(parentGfx, element) {
|
15085 |
|
15086 | var attrs = {
|
15087 | fillOpacity: DEFAULT_FILL_OPACITY,
|
15088 | fill: getFillColor(element, defaultFillColor),
|
15089 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15090 | };
|
15091 |
|
15092 | var lane = renderer('bpmn:Lane')(parentGfx, element, attrs);
|
15093 |
|
15094 | var expandedPool = isExpanded(element);
|
15095 |
|
15096 | if (expandedPool) {
|
15097 | drawLine(parentGfx, [
|
15098 | { x: 30, y: 0 },
|
15099 | { x: 30, y: element.height }
|
15100 | ], {
|
15101 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15102 | });
|
15103 | var text = getSemantic(element).name;
|
15104 | renderLaneLabel(parentGfx, text, element);
|
15105 | } else {
|
15106 |
|
15107 |
|
15108 | var text2 = getSemantic(element).name;
|
15109 | renderLabel(parentGfx, text2, {
|
15110 | box: element, align: 'center-middle',
|
15111 | style: {
|
15112 | fill: getStrokeColor(element, defaultStrokeColor)
|
15113 | }
|
15114 | });
|
15115 | }
|
15116 |
|
15117 | var participantMultiplicity = !!(getSemantic(element).participantMultiplicity);
|
15118 |
|
15119 | if (participantMultiplicity) {
|
15120 | renderer('ParticipantMultiplicityMarker')(parentGfx, element);
|
15121 | }
|
15122 |
|
15123 | return lane;
|
15124 | },
|
15125 | 'bpmn:Lane': function(parentGfx, element, attrs) {
|
15126 | var rect = drawRect(parentGfx, element.width, element.height, 0, assign({
|
15127 | fill: getFillColor(element, defaultFillColor),
|
15128 | fillOpacity: HIGH_FILL_OPACITY,
|
15129 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15130 | }, attrs));
|
15131 |
|
15132 | var semantic = getSemantic(element);
|
15133 |
|
15134 | if (semantic.$type === 'bpmn:Lane') {
|
15135 | var text = semantic.name;
|
15136 | renderLaneLabel(parentGfx, text, element);
|
15137 | }
|
15138 |
|
15139 | return rect;
|
15140 | },
|
15141 | 'bpmn:InclusiveGateway': function(parentGfx, element) {
|
15142 | var diamond = renderer('bpmn:Gateway')(parentGfx, element);
|
15143 |
|
15144 |
|
15145 | drawCircle(parentGfx, element.width, element.height, element.height * 0.24, {
|
15146 | strokeWidth: 2.5,
|
15147 | fill: getFillColor(element, defaultFillColor),
|
15148 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15149 | });
|
15150 |
|
15151 | return diamond;
|
15152 | },
|
15153 | 'bpmn:ExclusiveGateway': function(parentGfx, element) {
|
15154 | var diamond = renderer('bpmn:Gateway')(parentGfx, element);
|
15155 |
|
15156 | var pathData = pathMap.getScaledPath('GATEWAY_EXCLUSIVE', {
|
15157 | xScaleFactor: 0.4,
|
15158 | yScaleFactor: 0.4,
|
15159 | containerWidth: element.width,
|
15160 | containerHeight: element.height,
|
15161 | position: {
|
15162 | mx: 0.32,
|
15163 | my: 0.3
|
15164 | }
|
15165 | });
|
15166 |
|
15167 | if ((getDi(element).isMarkerVisible)) {
|
15168 | drawPath(parentGfx, pathData, {
|
15169 | strokeWidth: 1,
|
15170 | fill: getStrokeColor(element, defaultStrokeColor),
|
15171 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15172 | });
|
15173 | }
|
15174 |
|
15175 | return diamond;
|
15176 | },
|
15177 | 'bpmn:ComplexGateway': function(parentGfx, element) {
|
15178 | var diamond = renderer('bpmn:Gateway')(parentGfx, element);
|
15179 |
|
15180 | var pathData = pathMap.getScaledPath('GATEWAY_COMPLEX', {
|
15181 | xScaleFactor: 0.5,
|
15182 | yScaleFactor:0.5,
|
15183 | containerWidth: element.width,
|
15184 | containerHeight: element.height,
|
15185 | position: {
|
15186 | mx: 0.46,
|
15187 | my: 0.26
|
15188 | }
|
15189 | });
|
15190 |
|
15191 | drawPath(parentGfx, pathData, {
|
15192 | strokeWidth: 1,
|
15193 | fill: getStrokeColor(element, defaultStrokeColor),
|
15194 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15195 | });
|
15196 |
|
15197 | return diamond;
|
15198 | },
|
15199 | 'bpmn:ParallelGateway': function(parentGfx, element) {
|
15200 | var diamond = renderer('bpmn:Gateway')(parentGfx, element);
|
15201 |
|
15202 | var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', {
|
15203 | xScaleFactor: 0.6,
|
15204 | yScaleFactor:0.6,
|
15205 | containerWidth: element.width,
|
15206 | containerHeight: element.height,
|
15207 | position: {
|
15208 | mx: 0.46,
|
15209 | my: 0.2
|
15210 | }
|
15211 | });
|
15212 |
|
15213 | drawPath(parentGfx, pathData, {
|
15214 | strokeWidth: 1,
|
15215 | fill: getStrokeColor(element, defaultStrokeColor),
|
15216 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15217 | });
|
15218 |
|
15219 | return diamond;
|
15220 | },
|
15221 | 'bpmn:EventBasedGateway': function(parentGfx, element) {
|
15222 |
|
15223 | var semantic = getSemantic(element);
|
15224 |
|
15225 | var diamond = renderer('bpmn:Gateway')(parentGfx, element);
|
15226 |
|
15227 | drawCircle(parentGfx, element.width, element.height, element.height * 0.20, {
|
15228 | strokeWidth: 1,
|
15229 | fill: 'none',
|
15230 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15231 | });
|
15232 |
|
15233 | var type = semantic.eventGatewayType;
|
15234 | var instantiate = !!semantic.instantiate;
|
15235 |
|
15236 | function drawEvent() {
|
15237 |
|
15238 | var pathData = pathMap.getScaledPath('GATEWAY_EVENT_BASED', {
|
15239 | xScaleFactor: 0.18,
|
15240 | yScaleFactor: 0.18,
|
15241 | containerWidth: element.width,
|
15242 | containerHeight: element.height,
|
15243 | position: {
|
15244 | mx: 0.36,
|
15245 | my: 0.44
|
15246 | }
|
15247 | });
|
15248 |
|
15249 | var attrs = {
|
15250 | strokeWidth: 2,
|
15251 | fill: getFillColor(element, 'none'),
|
15252 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15253 | };
|
15254 |
|
15255 | drawPath(parentGfx, pathData, attrs);
|
15256 | }
|
15257 |
|
15258 | if (type === 'Parallel') {
|
15259 |
|
15260 | var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', {
|
15261 | xScaleFactor: 0.4,
|
15262 | yScaleFactor:0.4,
|
15263 | containerWidth: element.width,
|
15264 | containerHeight: element.height,
|
15265 | position: {
|
15266 | mx: 0.474,
|
15267 | my: 0.296
|
15268 | }
|
15269 | });
|
15270 |
|
15271 | var parallelPath = drawPath(parentGfx, pathData);
|
15272 | attr$1(parallelPath, {
|
15273 | strokeWidth: 1,
|
15274 | fill: 'none'
|
15275 | });
|
15276 | } else if (type === 'Exclusive') {
|
15277 |
|
15278 | if (!instantiate) {
|
15279 | var innerCircle = drawCircle(parentGfx, element.width, element.height, element.height * 0.26);
|
15280 | attr$1(innerCircle, {
|
15281 | strokeWidth: 1,
|
15282 | fill: 'none',
|
15283 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15284 | });
|
15285 | }
|
15286 |
|
15287 | drawEvent();
|
15288 | }
|
15289 |
|
15290 |
|
15291 | return diamond;
|
15292 | },
|
15293 | 'bpmn:Gateway': function(parentGfx, element) {
|
15294 | var attrs = {
|
15295 | fill: getFillColor(element, defaultFillColor),
|
15296 | fillOpacity: DEFAULT_FILL_OPACITY,
|
15297 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15298 | };
|
15299 |
|
15300 | return drawDiamond(parentGfx, element.width, element.height, attrs);
|
15301 | },
|
15302 | 'bpmn:SequenceFlow': function(parentGfx, element) {
|
15303 | var pathData = createPathFromConnection(element);
|
15304 |
|
15305 | var fill = getFillColor(element, defaultFillColor),
|
15306 | stroke = getStrokeColor(element, defaultStrokeColor);
|
15307 |
|
15308 | var attrs = {
|
15309 | strokeLinejoin: 'round',
|
15310 | markerEnd: marker('sequenceflow-end', fill, stroke),
|
15311 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15312 | };
|
15313 |
|
15314 | var path = drawPath(parentGfx, pathData, attrs);
|
15315 |
|
15316 | var sequenceFlow = getSemantic(element);
|
15317 |
|
15318 | var source;
|
15319 |
|
15320 | if (element.source) {
|
15321 | source = element.source.businessObject;
|
15322 |
|
15323 |
|
15324 | if (sequenceFlow.conditionExpression && source.$instanceOf('bpmn:Activity')) {
|
15325 | attr$1(path, {
|
15326 | markerStart: marker('conditional-flow-marker', fill, stroke)
|
15327 | });
|
15328 | }
|
15329 |
|
15330 |
|
15331 | if (source.default && (source.$instanceOf('bpmn:Gateway') || source.$instanceOf('bpmn:Activity')) &&
|
15332 | source.default === sequenceFlow) {
|
15333 | attr$1(path, {
|
15334 | markerStart: marker('conditional-default-flow-marker', fill, stroke)
|
15335 | });
|
15336 | }
|
15337 | }
|
15338 |
|
15339 | return path;
|
15340 | },
|
15341 | 'bpmn:Association': function(parentGfx, element, attrs) {
|
15342 |
|
15343 | var semantic = getSemantic(element);
|
15344 |
|
15345 | var fill = getFillColor(element, defaultFillColor),
|
15346 | stroke = getStrokeColor(element, defaultStrokeColor);
|
15347 |
|
15348 | attrs = assign({
|
15349 | strokeDasharray: '0.5, 5',
|
15350 | strokeLinecap: 'round',
|
15351 | strokeLinejoin: 'round',
|
15352 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15353 | }, attrs || {});
|
15354 |
|
15355 | if (semantic.associationDirection === 'One' ||
|
15356 | semantic.associationDirection === 'Both') {
|
15357 | attrs.markerEnd = marker('association-end', fill, stroke);
|
15358 | }
|
15359 |
|
15360 | if (semantic.associationDirection === 'Both') {
|
15361 | attrs.markerStart = marker('association-start', fill, stroke);
|
15362 | }
|
15363 |
|
15364 | return drawLine(parentGfx, element.waypoints, attrs);
|
15365 | },
|
15366 | 'bpmn:DataInputAssociation': function(parentGfx, element) {
|
15367 | var fill = getFillColor(element, defaultFillColor),
|
15368 | stroke = getStrokeColor(element, defaultStrokeColor);
|
15369 |
|
15370 | return renderer('bpmn:Association')(parentGfx, element, {
|
15371 | markerEnd: marker('association-end', fill, stroke)
|
15372 | });
|
15373 | },
|
15374 | 'bpmn:DataOutputAssociation': function(parentGfx, element) {
|
15375 | var fill = getFillColor(element, defaultFillColor),
|
15376 | stroke = getStrokeColor(element, defaultStrokeColor);
|
15377 |
|
15378 | return renderer('bpmn:Association')(parentGfx, element, {
|
15379 | markerEnd: marker('association-end', fill, stroke)
|
15380 | });
|
15381 | },
|
15382 | 'bpmn:MessageFlow': function(parentGfx, element) {
|
15383 |
|
15384 | var semantic = getSemantic(element),
|
15385 | di = getDi(element);
|
15386 |
|
15387 | var fill = getFillColor(element, defaultFillColor),
|
15388 | stroke = getStrokeColor(element, defaultStrokeColor);
|
15389 |
|
15390 | var pathData = createPathFromConnection(element);
|
15391 |
|
15392 | var attrs = {
|
15393 | markerEnd: marker('messageflow-end', fill, stroke),
|
15394 | markerStart: marker('messageflow-start', fill, stroke),
|
15395 | strokeDasharray: '10, 12',
|
15396 | strokeLinecap: 'round',
|
15397 | strokeLinejoin: 'round',
|
15398 | strokeWidth: '1.5px',
|
15399 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15400 | };
|
15401 |
|
15402 | var path = drawPath(parentGfx, pathData, attrs);
|
15403 |
|
15404 | if (semantic.messageRef) {
|
15405 | var midPoint = path.getPointAtLength(path.getTotalLength() / 2);
|
15406 |
|
15407 | var markerPathData = pathMap.getScaledPath('MESSAGE_FLOW_MARKER', {
|
15408 | abspos: {
|
15409 | x: midPoint.x,
|
15410 | y: midPoint.y
|
15411 | }
|
15412 | });
|
15413 |
|
15414 | var messageAttrs = { strokeWidth: 1 };
|
15415 |
|
15416 | if (di.messageVisibleKind === 'initiating') {
|
15417 | messageAttrs.fill = 'white';
|
15418 | messageAttrs.stroke = 'black';
|
15419 | } else {
|
15420 | messageAttrs.fill = '#888';
|
15421 | messageAttrs.stroke = 'white';
|
15422 | }
|
15423 |
|
15424 | drawPath(parentGfx, markerPathData, messageAttrs);
|
15425 | }
|
15426 |
|
15427 | return path;
|
15428 | },
|
15429 | 'bpmn:DataObject': function(parentGfx, element) {
|
15430 | var pathData = pathMap.getScaledPath('DATA_OBJECT_PATH', {
|
15431 | xScaleFactor: 1,
|
15432 | yScaleFactor: 1,
|
15433 | containerWidth: element.width,
|
15434 | containerHeight: element.height,
|
15435 | position: {
|
15436 | mx: 0.474,
|
15437 | my: 0.296
|
15438 | }
|
15439 | });
|
15440 |
|
15441 | var elementObject = drawPath(parentGfx, pathData, {
|
15442 | fill: getFillColor(element, defaultFillColor),
|
15443 | fillOpacity: DEFAULT_FILL_OPACITY,
|
15444 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15445 | });
|
15446 |
|
15447 | var semantic = getSemantic(element);
|
15448 |
|
15449 | if (isCollection(semantic)) {
|
15450 | renderDataItemCollection(parentGfx, element);
|
15451 | }
|
15452 |
|
15453 | return elementObject;
|
15454 | },
|
15455 | 'bpmn:DataObjectReference': as('bpmn:DataObject'),
|
15456 | 'bpmn:DataInput': function(parentGfx, element) {
|
15457 |
|
15458 | var arrowPathData = pathMap.getRawPath('DATA_ARROW');
|
15459 |
|
15460 |
|
15461 | var elementObject = renderer('bpmn:DataObject')(parentGfx, element);
|
15462 |
|
15463 | drawPath(parentGfx, arrowPathData, { strokeWidth: 1 });
|
15464 |
|
15465 | return elementObject;
|
15466 | },
|
15467 | 'bpmn:DataOutput': function(parentGfx, element) {
|
15468 | var arrowPathData = pathMap.getRawPath('DATA_ARROW');
|
15469 |
|
15470 |
|
15471 | var elementObject = renderer('bpmn:DataObject')(parentGfx, element);
|
15472 |
|
15473 | drawPath(parentGfx, arrowPathData, {
|
15474 | strokeWidth: 1,
|
15475 | fill: 'black'
|
15476 | });
|
15477 |
|
15478 | return elementObject;
|
15479 | },
|
15480 | 'bpmn:DataStoreReference': function(parentGfx, element) {
|
15481 | var DATA_STORE_PATH = pathMap.getScaledPath('DATA_STORE', {
|
15482 | xScaleFactor: 1,
|
15483 | yScaleFactor: 1,
|
15484 | containerWidth: element.width,
|
15485 | containerHeight: element.height,
|
15486 | position: {
|
15487 | mx: 0,
|
15488 | my: 0.133
|
15489 | }
|
15490 | });
|
15491 |
|
15492 | var elementStore = drawPath(parentGfx, DATA_STORE_PATH, {
|
15493 | strokeWidth: 2,
|
15494 | fill: getFillColor(element, defaultFillColor),
|
15495 | fillOpacity: DEFAULT_FILL_OPACITY,
|
15496 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15497 | });
|
15498 |
|
15499 | return elementStore;
|
15500 | },
|
15501 | 'bpmn:BoundaryEvent': function(parentGfx, element) {
|
15502 |
|
15503 | var semantic = getSemantic(element),
|
15504 | cancel = semantic.cancelActivity;
|
15505 |
|
15506 | var attrs = {
|
15507 | strokeWidth: 1,
|
15508 | fill: getFillColor(element, defaultFillColor),
|
15509 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15510 | };
|
15511 |
|
15512 | if (!cancel) {
|
15513 | attrs.strokeDasharray = '6';
|
15514 | attrs.strokeLinecap = 'round';
|
15515 | }
|
15516 |
|
15517 |
|
15518 | var outerAttrs = assign({}, attrs, {
|
15519 | fillOpacity: 1
|
15520 | });
|
15521 |
|
15522 |
|
15523 | var innerAttrs = assign({}, attrs, {
|
15524 | fill: 'none'
|
15525 | });
|
15526 |
|
15527 | var outer = renderer('bpmn:Event')(parentGfx, element, outerAttrs);
|
15528 |
|
15529 | drawCircle(parentGfx, element.width, element.height, INNER_OUTER_DIST, innerAttrs);
|
15530 |
|
15531 | renderEventContent(element, parentGfx);
|
15532 |
|
15533 | return outer;
|
15534 | },
|
15535 | 'bpmn:Group': function(parentGfx, element) {
|
15536 |
|
15537 | var group = drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS, {
|
15538 | strokeWidth: 1,
|
15539 | strokeDasharray: '8,3,1,3',
|
15540 | fill: 'none',
|
15541 | pointerEvents: 'none'
|
15542 | });
|
15543 |
|
15544 | return group;
|
15545 | },
|
15546 | 'label': function(parentGfx, element) {
|
15547 | return renderExternalLabel(parentGfx, element);
|
15548 | },
|
15549 | 'bpmn:TextAnnotation': function(parentGfx, element) {
|
15550 | var style = {
|
15551 | 'fill': 'none',
|
15552 | 'stroke': 'none'
|
15553 | };
|
15554 |
|
15555 | var textElement = drawRect(parentGfx, element.width, element.height, 0, 0, style);
|
15556 |
|
15557 | var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', {
|
15558 | xScaleFactor: 1,
|
15559 | yScaleFactor: 1,
|
15560 | containerWidth: element.width,
|
15561 | containerHeight: element.height,
|
15562 | position: {
|
15563 | mx: 0.0,
|
15564 | my: 0.0
|
15565 | }
|
15566 | });
|
15567 |
|
15568 | drawPath(parentGfx, textPathData, {
|
15569 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15570 | });
|
15571 |
|
15572 | var text = getSemantic(element).text || '';
|
15573 | renderLabel(parentGfx, text, {
|
15574 | box: element,
|
15575 | align: 'left-top',
|
15576 | padding: 5,
|
15577 | style: {
|
15578 | fill: getStrokeColor(element, defaultStrokeColor)
|
15579 | }
|
15580 | });
|
15581 |
|
15582 | return textElement;
|
15583 | },
|
15584 | 'ParticipantMultiplicityMarker': function(parentGfx, element) {
|
15585 | var markerPath = pathMap.getScaledPath('MARKER_PARALLEL', {
|
15586 | xScaleFactor: 1,
|
15587 | yScaleFactor: 1,
|
15588 | containerWidth: element.width,
|
15589 | containerHeight: element.height,
|
15590 | position: {
|
15591 | mx: ((element.width / 2) / element.width),
|
15592 | my: (element.height - 15) / element.height
|
15593 | }
|
15594 | });
|
15595 |
|
15596 | drawMarker('participant-multiplicity', parentGfx, markerPath, {
|
15597 | strokeWidth: 1,
|
15598 | fill: getFillColor(element, defaultFillColor),
|
15599 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15600 | });
|
15601 | },
|
15602 | 'SubProcessMarker': function(parentGfx, element) {
|
15603 | var markerRect = drawRect(parentGfx, 14, 14, 0, {
|
15604 | strokeWidth: 1,
|
15605 | fill: getFillColor(element, defaultFillColor),
|
15606 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15607 | });
|
15608 |
|
15609 |
|
15610 |
|
15611 | translate(markerRect, element.width / 2 - 7.5, element.height - 20);
|
15612 |
|
15613 | var markerPath = pathMap.getScaledPath('MARKER_SUB_PROCESS', {
|
15614 | xScaleFactor: 1.5,
|
15615 | yScaleFactor: 1.5,
|
15616 | containerWidth: element.width,
|
15617 | containerHeight: element.height,
|
15618 | position: {
|
15619 | mx: (element.width / 2 - 7.5) / element.width,
|
15620 | my: (element.height - 20) / element.height
|
15621 | }
|
15622 | });
|
15623 |
|
15624 | drawMarker('sub-process', parentGfx, markerPath, {
|
15625 | fill: getFillColor(element, defaultFillColor),
|
15626 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15627 | });
|
15628 | },
|
15629 | 'ParallelMarker': function(parentGfx, element, position) {
|
15630 | var markerPath = pathMap.getScaledPath('MARKER_PARALLEL', {
|
15631 | xScaleFactor: 1,
|
15632 | yScaleFactor: 1,
|
15633 | containerWidth: element.width,
|
15634 | containerHeight: element.height,
|
15635 | position: {
|
15636 | mx: ((element.width / 2 + position.parallel) / element.width),
|
15637 | my: (element.height - 20) / element.height
|
15638 | }
|
15639 | });
|
15640 |
|
15641 | drawMarker('parallel', parentGfx, markerPath, {
|
15642 | fill: getFillColor(element, defaultFillColor),
|
15643 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15644 | });
|
15645 | },
|
15646 | 'SequentialMarker': function(parentGfx, element, position) {
|
15647 | var markerPath = pathMap.getScaledPath('MARKER_SEQUENTIAL', {
|
15648 | xScaleFactor: 1,
|
15649 | yScaleFactor: 1,
|
15650 | containerWidth: element.width,
|
15651 | containerHeight: element.height,
|
15652 | position: {
|
15653 | mx: ((element.width / 2 + position.seq) / element.width),
|
15654 | my: (element.height - 19) / element.height
|
15655 | }
|
15656 | });
|
15657 |
|
15658 | drawMarker('sequential', parentGfx, markerPath, {
|
15659 | fill: getFillColor(element, defaultFillColor),
|
15660 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15661 | });
|
15662 | },
|
15663 | 'CompensationMarker': function(parentGfx, element, position) {
|
15664 | var markerMath = pathMap.getScaledPath('MARKER_COMPENSATION', {
|
15665 | xScaleFactor: 1,
|
15666 | yScaleFactor: 1,
|
15667 | containerWidth: element.width,
|
15668 | containerHeight: element.height,
|
15669 | position: {
|
15670 | mx: ((element.width / 2 + position.compensation) / element.width),
|
15671 | my: (element.height - 13) / element.height
|
15672 | }
|
15673 | });
|
15674 |
|
15675 | drawMarker('compensation', parentGfx, markerMath, {
|
15676 | strokeWidth: 1,
|
15677 | fill: getFillColor(element, defaultFillColor),
|
15678 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15679 | });
|
15680 | },
|
15681 | 'LoopMarker': function(parentGfx, element, position) {
|
15682 | var markerPath = pathMap.getScaledPath('MARKER_LOOP', {
|
15683 | xScaleFactor: 1,
|
15684 | yScaleFactor: 1,
|
15685 | containerWidth: element.width,
|
15686 | containerHeight: element.height,
|
15687 | position: {
|
15688 | mx: ((element.width / 2 + position.loop) / element.width),
|
15689 | my: (element.height - 7) / element.height
|
15690 | }
|
15691 | });
|
15692 |
|
15693 | drawMarker('loop', parentGfx, markerPath, {
|
15694 | strokeWidth: 1,
|
15695 | fill: getFillColor(element, defaultFillColor),
|
15696 | stroke: getStrokeColor(element, defaultStrokeColor),
|
15697 | strokeLinecap: 'round',
|
15698 | strokeMiterlimit: 0.5
|
15699 | });
|
15700 | },
|
15701 | 'AdhocMarker': function(parentGfx, element, position) {
|
15702 | var markerPath = pathMap.getScaledPath('MARKER_ADHOC', {
|
15703 | xScaleFactor: 1,
|
15704 | yScaleFactor: 1,
|
15705 | containerWidth: element.width,
|
15706 | containerHeight: element.height,
|
15707 | position: {
|
15708 | mx: ((element.width / 2 + position.adhoc) / element.width),
|
15709 | my: (element.height - 15) / element.height
|
15710 | }
|
15711 | });
|
15712 |
|
15713 | drawMarker('adhoc', parentGfx, markerPath, {
|
15714 | strokeWidth: 1,
|
15715 | fill: getStrokeColor(element, defaultStrokeColor),
|
15716 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15717 | });
|
15718 | }
|
15719 | };
|
15720 |
|
15721 | function attachTaskMarkers(parentGfx, element, taskMarkers) {
|
15722 | var obj = getSemantic(element);
|
15723 |
|
15724 | var subprocess = taskMarkers && taskMarkers.indexOf('SubProcessMarker') !== -1;
|
15725 | var position;
|
15726 |
|
15727 | if (subprocess) {
|
15728 | position = {
|
15729 | seq: -21,
|
15730 | parallel: -22,
|
15731 | compensation: -42,
|
15732 | loop: -18,
|
15733 | adhoc: 10
|
15734 | };
|
15735 | } else {
|
15736 | position = {
|
15737 | seq: -3,
|
15738 | parallel: -6,
|
15739 | compensation: -27,
|
15740 | loop: 0,
|
15741 | adhoc: 10
|
15742 | };
|
15743 | }
|
15744 |
|
15745 | forEach(taskMarkers, function(marker) {
|
15746 | renderer(marker)(parentGfx, element, position);
|
15747 | });
|
15748 |
|
15749 | if (obj.isForCompensation) {
|
15750 | renderer('CompensationMarker')(parentGfx, element, position);
|
15751 | }
|
15752 |
|
15753 | if (obj.$type === 'bpmn:AdHocSubProcess') {
|
15754 | renderer('AdhocMarker')(parentGfx, element, position);
|
15755 | }
|
15756 |
|
15757 | var loopCharacteristics = obj.loopCharacteristics,
|
15758 | isSequential = loopCharacteristics && loopCharacteristics.isSequential;
|
15759 |
|
15760 | if (loopCharacteristics) {
|
15761 |
|
15762 | if (isSequential === undefined) {
|
15763 | renderer('LoopMarker')(parentGfx, element, position);
|
15764 | }
|
15765 |
|
15766 | if (isSequential === false) {
|
15767 | renderer('ParallelMarker')(parentGfx, element, position);
|
15768 | }
|
15769 |
|
15770 | if (isSequential === true) {
|
15771 | renderer('SequentialMarker')(parentGfx, element, position);
|
15772 | }
|
15773 | }
|
15774 | }
|
15775 |
|
15776 | function renderDataItemCollection(parentGfx, element) {
|
15777 |
|
15778 | var yPosition = (element.height - 16) / element.height;
|
15779 |
|
15780 | var pathData = pathMap.getScaledPath('DATA_OBJECT_COLLECTION_PATH', {
|
15781 | xScaleFactor: 1,
|
15782 | yScaleFactor: 1,
|
15783 | containerWidth: element.width,
|
15784 | containerHeight: element.height,
|
15785 | position: {
|
15786 | mx: 0.451,
|
15787 | my: yPosition
|
15788 | }
|
15789 | });
|
15790 |
|
15791 | drawPath(parentGfx, pathData, {
|
15792 | strokeWidth: 2
|
15793 | });
|
15794 | }
|
15795 |
|
15796 |
|
15797 |
|
15798 | this._drawPath = drawPath;
|
15799 |
|
15800 | }
|
15801 |
|
15802 |
|
15803 | inherits_browser(BpmnRenderer, BaseRenderer);
|
15804 |
|
15805 | BpmnRenderer.$inject = [
|
15806 | 'config.bpmnRenderer',
|
15807 | 'eventBus',
|
15808 | 'styles',
|
15809 | 'pathMap',
|
15810 | 'canvas',
|
15811 | 'textRenderer'
|
15812 | ];
|
15813 |
|
15814 |
|
15815 | BpmnRenderer.prototype.canRender = function(element) {
|
15816 | return is$1(element, 'bpmn:BaseElement');
|
15817 | };
|
15818 |
|
15819 | BpmnRenderer.prototype.drawShape = function(parentGfx, element) {
|
15820 | var type = element.type;
|
15821 | var h = this.handlers[type];
|
15822 |
|
15823 |
|
15824 | return h(parentGfx, element);
|
15825 | };
|
15826 |
|
15827 | BpmnRenderer.prototype.drawConnection = function(parentGfx, element) {
|
15828 | var type = element.type;
|
15829 | var h = this.handlers[type];
|
15830 |
|
15831 |
|
15832 | return h(parentGfx, element);
|
15833 | };
|
15834 |
|
15835 | BpmnRenderer.prototype.getShapePath = function(element) {
|
15836 |
|
15837 | if (is$1(element, 'bpmn:Event')) {
|
15838 | return getCirclePath(element);
|
15839 | }
|
15840 |
|
15841 | if (is$1(element, 'bpmn:Activity')) {
|
15842 | return getRoundRectPath(element, TASK_BORDER_RADIUS);
|
15843 | }
|
15844 |
|
15845 | if (is$1(element, 'bpmn:Gateway')) {
|
15846 | return getDiamondPath(element);
|
15847 | }
|
15848 |
|
15849 | return getRectPath(element);
|
15850 | };
|
15851 |
|
15852 | var DEFAULT_BOX_PADDING = 0;
|
15853 |
|
15854 | var DEFAULT_LABEL_SIZE = {
|
15855 | width: 150,
|
15856 | height: 50
|
15857 | };
|
15858 |
|
15859 |
|
15860 | function parseAlign(align) {
|
15861 |
|
15862 | var parts = align.split('-');
|
15863 |
|
15864 | return {
|
15865 | horizontal: parts[0] || 'center',
|
15866 | vertical: parts[1] || 'top'
|
15867 | };
|
15868 | }
|
15869 |
|
15870 | function parsePadding(padding) {
|
15871 |
|
15872 | if (isObject(padding)) {
|
15873 | return assign({ top: 0, left: 0, right: 0, bottom: 0 }, padding);
|
15874 | } else {
|
15875 | return {
|
15876 | top: padding,
|
15877 | left: padding,
|
15878 | right: padding,
|
15879 | bottom: padding
|
15880 | };
|
15881 | }
|
15882 | }
|
15883 |
|
15884 | function getTextBBox(text, fakeText) {
|
15885 |
|
15886 | fakeText.textContent = text;
|
15887 |
|
15888 | var textBBox;
|
15889 |
|
15890 | try {
|
15891 | var bbox,
|
15892 | emptyLine = text === '';
|
15893 |
|
15894 |
|
15895 |
|
15896 | fakeText.textContent = emptyLine ? 'dummy' : text;
|
15897 |
|
15898 | textBBox = fakeText.getBBox();
|
15899 |
|
15900 |
|
15901 |
|
15902 | bbox = {
|
15903 | width: textBBox.width + textBBox.x * 2,
|
15904 | height: textBBox.height
|
15905 | };
|
15906 |
|
15907 | if (emptyLine) {
|
15908 |
|
15909 |
|
15910 | bbox.width = 0;
|
15911 | }
|
15912 |
|
15913 | return bbox;
|
15914 | } catch (e) {
|
15915 | return { width: 0, height: 0 };
|
15916 | }
|
15917 | }
|
15918 |
|
15919 |
|
15920 | |
15921 |
|
15922 |
|
15923 |
|
15924 |
|
15925 |
|
15926 |
|
15927 |
|
15928 | function layoutNext(lines, maxWidth, fakeText) {
|
15929 |
|
15930 | var originalLine = lines.shift(),
|
15931 | fitLine = originalLine;
|
15932 |
|
15933 | var textBBox;
|
15934 |
|
15935 | for (;;) {
|
15936 | textBBox = getTextBBox(fitLine, fakeText);
|
15937 |
|
15938 | textBBox.width = fitLine ? textBBox.width : 0;
|
15939 |
|
15940 |
|
15941 | if (fitLine === ' ' || fitLine === '' || textBBox.width < Math.round(maxWidth) || fitLine.length < 2) {
|
15942 | return fit(lines, fitLine, originalLine, textBBox);
|
15943 | }
|
15944 |
|
15945 | fitLine = shortenLine(fitLine, textBBox.width, maxWidth);
|
15946 | }
|
15947 | }
|
15948 |
|
15949 | function fit(lines, fitLine, originalLine, textBBox) {
|
15950 | if (fitLine.length < originalLine.length) {
|
15951 | var remainder = originalLine.slice(fitLine.length).trim();
|
15952 |
|
15953 | lines.unshift(remainder);
|
15954 | }
|
15955 |
|
15956 | return {
|
15957 | width: textBBox.width,
|
15958 | height: textBBox.height,
|
15959 | text: fitLine
|
15960 | };
|
15961 | }
|
15962 |
|
15963 |
|
15964 | |
15965 |
|
15966 |
|
15967 |
|
15968 |
|
15969 |
|
15970 |
|
15971 |
|
15972 | function semanticShorten(line, maxLength) {
|
15973 | var parts = line.split(/(\s|-)/g),
|
15974 | part,
|
15975 | shortenedParts = [],
|
15976 | length = 0;
|
15977 |
|
15978 |
|
15979 | if (parts.length > 1) {
|
15980 | while ((part = parts.shift())) {
|
15981 | if (part.length + length < maxLength) {
|
15982 | shortenedParts.push(part);
|
15983 | length += part.length;
|
15984 | } else {
|
15985 |
|
15986 |
|
15987 | if (part === '-') {
|
15988 | shortenedParts.pop();
|
15989 | }
|
15990 |
|
15991 | break;
|
15992 | }
|
15993 | }
|
15994 | }
|
15995 |
|
15996 | return shortenedParts.join('');
|
15997 | }
|
15998 |
|
15999 |
|
16000 | function shortenLine(line, width, maxWidth) {
|
16001 | var length = Math.max(line.length * (maxWidth / width), 1);
|
16002 |
|
16003 |
|
16004 | var shortenedLine = semanticShorten(line, length);
|
16005 |
|
16006 | if (!shortenedLine) {
|
16007 |
|
16008 |
|
16009 | shortenedLine = line.slice(0, Math.max(Math.round(length - 1), 1));
|
16010 | }
|
16011 |
|
16012 | return shortenedLine;
|
16013 | }
|
16014 |
|
16015 |
|
16016 | function getHelperSvg() {
|
16017 | var helperSvg = document.getElementById('helper-svg');
|
16018 |
|
16019 | if (!helperSvg) {
|
16020 | helperSvg = create('svg');
|
16021 |
|
16022 | attr$1(helperSvg, {
|
16023 | id: 'helper-svg',
|
16024 | width: 0,
|
16025 | height: 0,
|
16026 | style: 'visibility: hidden; position: fixed'
|
16027 | });
|
16028 |
|
16029 | document.body.appendChild(helperSvg);
|
16030 | }
|
16031 |
|
16032 | return helperSvg;
|
16033 | }
|
16034 |
|
16035 |
|
16036 | |
16037 |
|
16038 |
|
16039 |
|
16040 |
|
16041 |
|
16042 |
|
16043 |
|
16044 |
|
16045 | function Text(config) {
|
16046 |
|
16047 | this._config = assign({}, {
|
16048 | size: DEFAULT_LABEL_SIZE,
|
16049 | padding: DEFAULT_BOX_PADDING,
|
16050 | style: {},
|
16051 | align: 'center-top'
|
16052 | }, config || {});
|
16053 | }
|
16054 |
|
16055 | |
16056 |
|
16057 |
|
16058 |
|
16059 |
|
16060 |
|
16061 |
|
16062 |
|
16063 | Text.prototype.createText = function(text, options) {
|
16064 | return this.layoutText(text, options).element;
|
16065 | };
|
16066 |
|
16067 | |
16068 |
|
16069 |
|
16070 |
|
16071 |
|
16072 |
|
16073 |
|
16074 |
|
16075 | Text.prototype.getDimensions = function(text, options) {
|
16076 | return this.layoutText(text, options).dimensions;
|
16077 | };
|
16078 |
|
16079 | |
16080 |
|
16081 |
|
16082 |
|
16083 |
|
16084 |
|
16085 |
|
16086 |
|
16087 |
|
16088 |
|
16089 |
|
16090 |
|
16091 |
|
16092 |
|
16093 |
|
16094 |
|
16095 | Text.prototype.layoutText = function(text, options) {
|
16096 | var box = assign({}, this._config.size, options.box),
|
16097 | style = assign({}, this._config.style, options.style),
|
16098 | align = parseAlign(options.align || this._config.align),
|
16099 | padding = parsePadding(options.padding !== undefined ? options.padding : this._config.padding),
|
16100 | fitBox = options.fitBox || false;
|
16101 |
|
16102 | var lineHeight = getLineHeight(style);
|
16103 |
|
16104 | var lines = text.split(/\r?\n/g),
|
16105 | layouted = [];
|
16106 |
|
16107 | var maxWidth = box.width - padding.left - padding.right;
|
16108 |
|
16109 |
|
16110 | var helperText = create('text');
|
16111 | attr$1(helperText, { x: 0, y: 0 });
|
16112 | attr$1(helperText, style);
|
16113 |
|
16114 | var helperSvg = getHelperSvg();
|
16115 |
|
16116 | append(helperSvg, helperText);
|
16117 |
|
16118 | while (lines.length) {
|
16119 | layouted.push(layoutNext(lines, maxWidth, helperText));
|
16120 | }
|
16121 |
|
16122 | if (align.vertical === 'middle') {
|
16123 | padding.top = padding.bottom = 0;
|
16124 | }
|
16125 |
|
16126 | var totalHeight = reduce(layouted, function(sum, line, idx) {
|
16127 | return sum + (lineHeight || line.height);
|
16128 | }, 0) + padding.top + padding.bottom;
|
16129 |
|
16130 | var maxLineWidth = reduce(layouted, function(sum, line, idx) {
|
16131 | return line.width > sum ? line.width : sum;
|
16132 | }, 0);
|
16133 |
|
16134 |
|
16135 | var y = padding.top;
|
16136 |
|
16137 | if (align.vertical === 'middle') {
|
16138 | y += (box.height - totalHeight) / 2;
|
16139 | }
|
16140 |
|
16141 |
|
16142 | y -= (lineHeight || layouted[0].height) / 4;
|
16143 |
|
16144 |
|
16145 | var textElement = create('text');
|
16146 |
|
16147 | attr$1(textElement, style);
|
16148 |
|
16149 |
|
16150 |
|
16151 | forEach(layouted, function(line) {
|
16152 |
|
16153 | var x;
|
16154 |
|
16155 | y += (lineHeight || line.height);
|
16156 |
|
16157 | switch (align.horizontal) {
|
16158 | case 'left':
|
16159 | x = padding.left;
|
16160 | break;
|
16161 |
|
16162 | case 'right':
|
16163 | x = ((fitBox ? maxLineWidth : maxWidth)
|
16164 | - padding.right - line.width);
|
16165 | break;
|
16166 |
|
16167 | default:
|
16168 |
|
16169 |
|
16170 | x = Math.max((((fitBox ? maxLineWidth : maxWidth)
|
16171 | - line.width) / 2 + padding.left), 0);
|
16172 | }
|
16173 |
|
16174 | var tspan = create('tspan');
|
16175 | attr$1(tspan, { x: x, y: y });
|
16176 |
|
16177 | tspan.textContent = line.text;
|
16178 |
|
16179 | append(textElement, tspan);
|
16180 | });
|
16181 |
|
16182 | remove$1(helperText);
|
16183 |
|
16184 | var dimensions = {
|
16185 | width: maxLineWidth,
|
16186 | height: totalHeight
|
16187 | };
|
16188 |
|
16189 | return {
|
16190 | dimensions: dimensions,
|
16191 | element: textElement
|
16192 | };
|
16193 | };
|
16194 |
|
16195 |
|
16196 | function getLineHeight(style) {
|
16197 | if ('fontSize' in style && 'lineHeight' in style) {
|
16198 | return style.lineHeight * parseInt(style.fontSize, 10);
|
16199 | }
|
16200 | }
|
16201 |
|
16202 | var DEFAULT_FONT_SIZE = 12;
|
16203 | var LINE_HEIGHT_RATIO = 1.2;
|
16204 |
|
16205 | var MIN_TEXT_ANNOTATION_HEIGHT = 30;
|
16206 |
|
16207 |
|
16208 | function TextRenderer(config) {
|
16209 |
|
16210 | var defaultStyle = assign({
|
16211 | fontFamily: 'Arial, sans-serif',
|
16212 | fontSize: DEFAULT_FONT_SIZE,
|
16213 | fontWeight: 'normal',
|
16214 | lineHeight: LINE_HEIGHT_RATIO
|
16215 | }, config && config.defaultStyle || {});
|
16216 |
|
16217 | var fontSize = parseInt(defaultStyle.fontSize, 10) - 1;
|
16218 |
|
16219 | var externalStyle = assign({}, defaultStyle, {
|
16220 | fontSize: fontSize
|
16221 | }, config && config.externalStyle || {});
|
16222 |
|
16223 | var textUtil = new Text({
|
16224 | style: defaultStyle
|
16225 | });
|
16226 |
|
16227 | |
16228 |
|
16229 |
|
16230 |
|
16231 |
|
16232 |
|
16233 |
|
16234 |
|
16235 |
|
16236 | this.getExternalLabelBounds = function(bounds, text) {
|
16237 |
|
16238 | var layoutedDimensions = textUtil.getDimensions(text, {
|
16239 | box: {
|
16240 | width: 90,
|
16241 | height: 30,
|
16242 | x: bounds.width / 2 + bounds.x,
|
16243 | y: bounds.height / 2 + bounds.y
|
16244 | },
|
16245 | style: externalStyle
|
16246 | });
|
16247 |
|
16248 |
|
16249 | return {
|
16250 | x: Math.round(bounds.x + bounds.width / 2 - layoutedDimensions.width / 2),
|
16251 | y: Math.round(bounds.y),
|
16252 | width: Math.ceil(layoutedDimensions.width),
|
16253 | height: Math.ceil(layoutedDimensions.height)
|
16254 | };
|
16255 |
|
16256 | };
|
16257 |
|
16258 | |
16259 |
|
16260 |
|
16261 |
|
16262 |
|
16263 |
|
16264 |
|
16265 |
|
16266 | this.getTextAnnotationBounds = function(bounds, text) {
|
16267 |
|
16268 | var layoutedDimensions = textUtil.getDimensions(text, {
|
16269 | box: bounds,
|
16270 | style: defaultStyle,
|
16271 | align: 'left-top',
|
16272 | padding: 5
|
16273 | });
|
16274 |
|
16275 | return {
|
16276 | x: bounds.x,
|
16277 | y: bounds.y,
|
16278 | width: bounds.width,
|
16279 | height: Math.max(MIN_TEXT_ANNOTATION_HEIGHT, Math.round(layoutedDimensions.height))
|
16280 | };
|
16281 | };
|
16282 |
|
16283 | |
16284 |
|
16285 |
|
16286 |
|
16287 |
|
16288 |
|
16289 |
|
16290 |
|
16291 | this.createText = function(text, options) {
|
16292 | return textUtil.createText(text, options || {});
|
16293 | };
|
16294 |
|
16295 | |
16296 |
|
16297 |
|
16298 | this.getDefaultStyle = function() {
|
16299 | return defaultStyle;
|
16300 | };
|
16301 |
|
16302 | |
16303 |
|
16304 |
|
16305 | this.getExternalStyle = function() {
|
16306 | return externalStyle;
|
16307 | };
|
16308 |
|
16309 | }
|
16310 |
|
16311 | TextRenderer.$inject = [
|
16312 | 'config.textRenderer'
|
16313 | ];
|
16314 |
|
16315 | |
16316 |
|
16317 |
|
16318 |
|
16319 | function PathMap() {
|
16320 |
|
16321 | |
16322 |
|
16323 |
|
16324 |
|
16325 |
|
16326 |
|
16327 |
|
16328 |
|
16329 |
|
16330 |
|
16331 |
|
16332 |
|
16333 |
|
16334 |
|
16335 |
|
16336 |
|
16337 |
|
16338 |
|
16339 |
|
16340 |
|
16341 |
|
16342 |
|
16343 |
|
16344 |
|
16345 |
|
16346 |
|
16347 |
|
16348 |
|
16349 |
|
16350 |
|
16351 |
|
16352 | this.pathMap = {
|
16353 | 'EVENT_MESSAGE': {
|
16354 | 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}',
|
16355 | height: 36,
|
16356 | width: 36,
|
16357 | heightElements: [6, 14],
|
16358 | widthElements: [10.5, 21]
|
16359 | },
|
16360 | 'EVENT_SIGNAL': {
|
16361 | d: 'M {mx},{my} l {e.x0},{e.y0} l -{e.x1},0 Z',
|
16362 | height: 36,
|
16363 | width: 36,
|
16364 | heightElements: [18],
|
16365 | widthElements: [10, 20]
|
16366 | },
|
16367 | 'EVENT_ESCALATION': {
|
16368 | d: 'M {mx},{my} l {e.x0},{e.y0} l -{e.x0},-{e.y1} l -{e.x0},{e.y1} Z',
|
16369 | height: 36,
|
16370 | width: 36,
|
16371 | heightElements: [20, 7],
|
16372 | widthElements: [8]
|
16373 | },
|
16374 | 'EVENT_CONDITIONAL': {
|
16375 | d: 'M {e.x0},{e.y0} l {e.x1},0 l 0,{e.y2} l -{e.x1},0 Z ' +
|
16376 | 'M {e.x2},{e.y3} l {e.x0},0 ' +
|
16377 | 'M {e.x2},{e.y4} l {e.x0},0 ' +
|
16378 | 'M {e.x2},{e.y5} l {e.x0},0 ' +
|
16379 | 'M {e.x2},{e.y6} l {e.x0},0 ' +
|
16380 | 'M {e.x2},{e.y7} l {e.x0},0 ' +
|
16381 | 'M {e.x2},{e.y8} l {e.x0},0 ',
|
16382 | height: 36,
|
16383 | width: 36,
|
16384 | heightElements: [8.5, 14.5, 18, 11.5, 14.5, 17.5, 20.5, 23.5, 26.5],
|
16385 | widthElements: [10.5, 14.5, 12.5]
|
16386 | },
|
16387 | 'EVENT_LINK': {
|
16388 | 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',
|
16389 | height: 36,
|
16390 | width: 36,
|
16391 | heightElements: [4.4375, 6.75, 7.8125],
|
16392 | widthElements: [9.84375, 13.5]
|
16393 | },
|
16394 | 'EVENT_ERROR': {
|
16395 | 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',
|
16396 | height: 36,
|
16397 | width: 36,
|
16398 | heightElements: [0.023, 8.737, 8.151, 16.564, 10.591, 8.714],
|
16399 | widthElements: [0.085, 6.672, 6.97, 4.273, 5.337, 6.636]
|
16400 | },
|
16401 | 'EVENT_CANCEL_45': {
|
16402 | d: 'm {mx},{my} -{e.x1},0 0,{e.x0} {e.x1},0 0,{e.y1} {e.x0},0 ' +
|
16403 | '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z',
|
16404 | height: 36,
|
16405 | width: 36,
|
16406 | heightElements: [4.75, 8.5],
|
16407 | widthElements: [4.75, 8.5]
|
16408 | },
|
16409 | 'EVENT_COMPENSATION': {
|
16410 | 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',
|
16411 | height: 36,
|
16412 | width: 36,
|
16413 | heightElements: [6.5, 13, 0.4, 6.1],
|
16414 | widthElements: [9, 9.3, 8.7]
|
16415 | },
|
16416 | 'EVENT_TIMER_WH': {
|
16417 | d: 'M {mx},{my} l {e.x0},-{e.y0} m -{e.x0},{e.y0} l {e.x1},{e.y1} ',
|
16418 | height: 36,
|
16419 | width: 36,
|
16420 | heightElements: [10, 2],
|
16421 | widthElements: [3, 7]
|
16422 | },
|
16423 | 'EVENT_TIMER_LINE': {
|
16424 | d: 'M {mx},{my} ' +
|
16425 | 'm {e.x0},{e.y0} l -{e.x1},{e.y1} ',
|
16426 | height: 36,
|
16427 | width: 36,
|
16428 | heightElements: [10, 3],
|
16429 | widthElements: [0, 0]
|
16430 | },
|
16431 | 'EVENT_MULTIPLE': {
|
16432 | d:'m {mx},{my} {e.x1},-{e.y0} {e.x1},{e.y0} -{e.x0},{e.y1} -{e.x2},0 z',
|
16433 | height: 36,
|
16434 | width: 36,
|
16435 | heightElements: [6.28099, 12.56199],
|
16436 | widthElements: [3.1405, 9.42149, 12.56198]
|
16437 | },
|
16438 | 'EVENT_PARALLEL_MULTIPLE': {
|
16439 | d:'m {mx},{my} {e.x0},0 0,{e.y1} {e.x1},0 0,{e.y0} -{e.x1},0 0,{e.y1} ' +
|
16440 | '-{e.x0},0 0,-{e.y1} -{e.x1},0 0,-{e.y0} {e.x1},0 z',
|
16441 | height: 36,
|
16442 | width: 36,
|
16443 | heightElements: [2.56228, 7.68683],
|
16444 | widthElements: [2.56228, 7.68683]
|
16445 | },
|
16446 | 'GATEWAY_EXCLUSIVE': {
|
16447 | d:'m {mx},{my} {e.x0},{e.y0} {e.x1},{e.y0} {e.x2},0 {e.x4},{e.y2} ' +
|
16448 | '{e.x4},{e.y1} {e.x2},0 {e.x1},{e.y3} {e.x0},{e.y3} ' +
|
16449 | '{e.x3},0 {e.x5},{e.y1} {e.x5},{e.y2} {e.x3},0 z',
|
16450 | height: 17.5,
|
16451 | width: 17.5,
|
16452 | heightElements: [8.5, 6.5312, -6.5312, -8.5],
|
16453 | widthElements: [6.5, -6.5, 3, -3, 5, -5]
|
16454 | },
|
16455 | 'GATEWAY_PARALLEL': {
|
16456 | d:'m {mx},{my} 0,{e.y1} -{e.x1},0 0,{e.y0} {e.x1},0 0,{e.y1} {e.x0},0 ' +
|
16457 | '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z',
|
16458 | height: 30,
|
16459 | width: 30,
|
16460 | heightElements: [5, 12.5],
|
16461 | widthElements: [5, 12.5]
|
16462 | },
|
16463 | 'GATEWAY_EVENT_BASED': {
|
16464 | d:'m {mx},{my} {e.x0},{e.y0} {e.x0},{e.y1} {e.x1},{e.y2} {e.x2},0 z',
|
16465 | height: 11,
|
16466 | width: 11,
|
16467 | heightElements: [-6, 6, 12, -12],
|
16468 | widthElements: [9, -3, -12]
|
16469 | },
|
16470 | 'GATEWAY_COMPLEX': {
|
16471 | 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} ' +
|
16472 | '{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} ' +
|
16473 | '{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} ' +
|
16474 | '-{e.x0},{e.y1} 0,-{e.y0} -{e.x3},0 z',
|
16475 | height: 17.125,
|
16476 | width: 17.125,
|
16477 | heightElements: [4.875, 3.4375, 2.125, 3],
|
16478 | widthElements: [3.4375, 2.125, 4.875, 3]
|
16479 | },
|
16480 | 'DATA_OBJECT_PATH': {
|
16481 | 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',
|
16482 | height: 61,
|
16483 | width: 51,
|
16484 | heightElements: [10, 50, 60],
|
16485 | widthElements: [10, 40, 50, 60]
|
16486 | },
|
16487 | 'DATA_OBJECT_COLLECTION_PATH': {
|
16488 | d:'m {mx}, {my} ' +
|
16489 | 'm 0 15 l 0 -15 ' +
|
16490 | 'm 4 15 l 0 -15 ' +
|
16491 | 'm 4 15 l 0 -15 ',
|
16492 | height: 61,
|
16493 | width: 51,
|
16494 | heightElements: [12],
|
16495 | widthElements: [1, 6, 12, 15]
|
16496 | },
|
16497 | 'DATA_ARROW': {
|
16498 | d:'m 5,9 9,0 0,-3 5,5 -5,5 0,-3 -9,0 z',
|
16499 | height: 61,
|
16500 | width: 51,
|
16501 | heightElements: [],
|
16502 | widthElements: []
|
16503 | },
|
16504 | 'DATA_STORE': {
|
16505 | d:'m {mx},{my} ' +
|
16506 | 'l 0,{e.y2} ' +
|
16507 | 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' +
|
16508 | 'l 0,-{e.y2} ' +
|
16509 | 'c -{e.x0},-{e.y1} -{e.x1},-{e.y1} -{e.x2},0' +
|
16510 | 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' +
|
16511 | 'm -{e.x2},{e.y0}' +
|
16512 | 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0' +
|
16513 | 'm -{e.x2},{e.y0}' +
|
16514 | 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0',
|
16515 | height: 61,
|
16516 | width: 61,
|
16517 | heightElements: [7, 10, 45],
|
16518 | widthElements: [2, 58, 60]
|
16519 | },
|
16520 | 'TEXT_ANNOTATION': {
|
16521 | d: 'm {mx}, {my} m 10,0 l -10,0 l 0,{e.y0} l 10,0',
|
16522 | height: 30,
|
16523 | width: 10,
|
16524 | heightElements: [30],
|
16525 | widthElements: [10]
|
16526 | },
|
16527 | 'MARKER_SUB_PROCESS': {
|
16528 | d: 'm{mx},{my} m 7,2 l 0,10 m -5,-5 l 10,0',
|
16529 | height: 10,
|
16530 | width: 10,
|
16531 | heightElements: [],
|
16532 | widthElements: []
|
16533 | },
|
16534 | 'MARKER_PARALLEL': {
|
16535 | d: 'm{mx},{my} m 3,2 l 0,10 m 3,-10 l 0,10 m 3,-10 l 0,10',
|
16536 | height: 10,
|
16537 | width: 10,
|
16538 | heightElements: [],
|
16539 | widthElements: []
|
16540 | },
|
16541 | 'MARKER_SEQUENTIAL': {
|
16542 | d: 'm{mx},{my} m 0,3 l 10,0 m -10,3 l 10,0 m -10,3 l 10,0',
|
16543 | height: 10,
|
16544 | width: 10,
|
16545 | heightElements: [],
|
16546 | widthElements: []
|
16547 | },
|
16548 | 'MARKER_COMPENSATION': {
|
16549 | 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',
|
16550 | height: 10,
|
16551 | width: 21,
|
16552 | heightElements: [],
|
16553 | widthElements: []
|
16554 | },
|
16555 | 'MARKER_LOOP': {
|
16556 | d: 'm {mx},{my} c 3.526979,0 6.386161,-2.829858 6.386161,-6.320661 0,-3.490806 -2.859182,-6.320661 ' +
|
16557 | '-6.386161,-6.320661 -3.526978,0 -6.38616,2.829855 -6.38616,6.320661 0,1.745402 ' +
|
16558 | '0.714797,3.325567 1.870463,4.469381 0.577834,0.571908 1.265885,1.034728 2.029916,1.35457 ' +
|
16559 | 'l -0.718163,-3.909793 m 0.718163,3.909793 -3.885211,0.802902',
|
16560 | height: 13.9,
|
16561 | width: 13.7,
|
16562 | heightElements: [],
|
16563 | widthElements: []
|
16564 | },
|
16565 | 'MARKER_ADHOC': {
|
16566 | 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 ' +
|
16567 | '3.85579,1.15803 5.76082,1.79107 1.06385,0.34139996 2.24454,0.1438 3.18759,-0.43767 0.61743,-0.33642 ' +
|
16568 | '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 ' +
|
16569 | '-3.6918,1.66181996 -1.24459,0.0927 -2.46671,-0.2491 -3.59505,-0.74812 -1.35789,-0.55965 ' +
|
16570 | '-2.75133,-1.33436996 -4.27027,-1.18121996 -1.37741,0.14601 -2.41842,1.13685996 -3.44288,1.96782996 z',
|
16571 | height: 4,
|
16572 | width: 15,
|
16573 | heightElements: [],
|
16574 | widthElements: []
|
16575 | },
|
16576 | 'TASK_TYPE_SEND': {
|
16577 | 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}',
|
16578 | height: 14,
|
16579 | width: 21,
|
16580 | heightElements: [6, 14],
|
16581 | widthElements: [10.5, 21]
|
16582 | },
|
16583 | 'TASK_TYPE_SCRIPT': {
|
16584 | d: 'm {mx},{my} c 9.966553,-6.27276 -8.000926,-7.91932 2.968968,-14.938 l -8.802728,0 ' +
|
16585 | 'c -10.969894,7.01868 6.997585,8.66524 -2.968967,14.938 z ' +
|
16586 | 'm -7,-12 l 5,0 ' +
|
16587 | 'm -4.5,3 l 4.5,0 ' +
|
16588 | 'm -3,3 l 5,0' +
|
16589 | 'm -4,3 l 5,0',
|
16590 | height: 15,
|
16591 | width: 12.6,
|
16592 | heightElements: [6, 14],
|
16593 | widthElements: [10.5, 21]
|
16594 | },
|
16595 | 'TASK_TYPE_USER_1': {
|
16596 | d: 'm {mx},{my} c 0.909,-0.845 1.594,-2.049 1.594,-3.385 0,-2.554 -1.805,-4.62199999 ' +
|
16597 | '-4.357,-4.62199999 -2.55199998,0 -4.28799998,2.06799999 -4.28799998,4.62199999 0,1.348 ' +
|
16598 | '0.974,2.562 1.89599998,3.405 -0.52899998,0.187 -5.669,2.097 -5.794,4.7560005 v 6.718 ' +
|
16599 | 'h 17 v -6.718 c 0,-2.2980005 -5.5279996,-4.5950005 -6.0509996,-4.7760005 z' +
|
16600 | 'm -8,6 l 0,5.5 m 11,0 l 0,-5'
|
16601 | },
|
16602 | 'TASK_TYPE_USER_2': {
|
16603 | d: 'm {mx},{my} m 2.162,1.009 c 0,2.4470005 -2.158,4.4310005 -4.821,4.4310005 ' +
|
16604 | '-2.66499998,0 -4.822,-1.981 -4.822,-4.4310005 '
|
16605 | },
|
16606 | 'TASK_TYPE_USER_3': {
|
16607 | 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 ' +
|
16608 | '4.124,0.965 -0.098,-0.57 -0.117,-3.79099999 -4.191,-4.13599999 -3.57499998,0.001 ' +
|
16609 | '-4.20799998,3.36699999 -4.20699998,4.34799999 z'
|
16610 | },
|
16611 | 'TASK_TYPE_MANUAL': {
|
16612 | 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 ' +
|
16613 | '-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 ' +
|
16614 | '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 ' +
|
16615 | '-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 ' +
|
16616 | '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 ' +
|
16617 | '-10.86,-0.003 -11.0829995,-0.003 -0.022,-0.047 -0.045,-0.094 -0.069,-0.139 0.3939995,-0.319 ' +
|
16618 | '2.0409995,-1.626 2.4149995,-2.017 0.469,-0.4870005 0.519,-1.1650005 0.162,-1.6040005 -0.414,-0.511 ' +
|
16619 | '-0.973,-0.5 -1.48,-0.236 -1.4609995,0.764 -6.5999995,3.6430005 -7.7329995,4.2710005 -0.9,0.499 ' +
|
16620 | '-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 ' +
|
16621 | '-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 ' +
|
16622 | '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 ' +
|
16623 | '-5.824,-0.004 -6.04,-0.004 10e-4,-0.084 0.003,-0.586 10e-4,-0.67 z'
|
16624 | },
|
16625 | 'TASK_TYPE_INSTANTIATING_SEND': {
|
16626 | 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'
|
16627 | },
|
16628 | 'TASK_TYPE_SERVICE': {
|
16629 | d: 'm {mx},{my} v -1.71335 c 0.352326,-0.0705 0.703932,-0.17838 1.047628,-0.32133 ' +
|
16630 | '0.344416,-0.14465 0.665822,-0.32133 0.966377,-0.52145 l 1.19431,1.18005 1.567487,-1.57688 ' +
|
16631 | '-1.195028,-1.18014 c 0.403376,-0.61394 0.683079,-1.29908 0.825447,-2.01824 l 1.622133,-0.01 ' +
|
16632 | 'v -2.2196 l -1.636514,0.01 c -0.07333,-0.35153 -0.178319,-0.70024 -0.323564,-1.04372 ' +
|
16633 | '-0.145244,-0.34406 -0.321407,-0.6644 -0.522735,-0.96217 l 1.131035,-1.13631 -1.583305,-1.56293 ' +
|
16634 | '-1.129598,1.13589 c -0.614052,-0.40108 -1.302883,-0.68093 -2.022633,-0.82247 l 0.0093,-1.61852 ' +
|
16635 | '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 ' +
|
16636 | '-0.665102,0.32092 -0.9635006,0.52046 l -1.1698628,-1.15823 -1.5667691,1.5792 1.1684265,1.15669 ' +
|
16637 | 'c -0.4026573,0.61283 -0.68308,1.29797 -0.8247287,2.01713 l -1.6588041,0.003 v 2.22174 ' +
|
16638 | 'l 1.6724648,-0.006 c 0.073327,0.35077 0.1797598,0.70243 0.3242851,1.04472 0.1452428,0.34448 ' +
|
16639 | '0.3214064,0.6644 0.5227339,0.96066 l -1.1993431,1.19723 1.5840256,1.56011 1.1964668,-1.19348 ' +
|
16640 | 'c 0.6140517,0.40346 1.3028827,0.68232 2.0233517,0.82331 l 7.19e-4,1.69892 h 2.226848 z ' +
|
16641 | 'm 0.221462,-3.9957 c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' +
|
16642 | '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' +
|
16643 | '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z'
|
16644 | },
|
16645 | 'TASK_TYPE_SERVICE_FILL': {
|
16646 | d: 'm {mx},{my} c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' +
|
16647 | '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' +
|
16648 | '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z'
|
16649 | },
|
16650 | 'TASK_TYPE_BUSINESS_RULE_HEADER': {
|
16651 | d: 'm {mx},{my} 0,4 20,0 0,-4 z'
|
16652 | },
|
16653 | 'TASK_TYPE_BUSINESS_RULE_MAIN': {
|
16654 | d: 'm {mx},{my} 0,12 20,0 0,-12 z' +
|
16655 | 'm 0,8 l 20,0 ' +
|
16656 | 'm -13,-4 l 0,8'
|
16657 | },
|
16658 | 'MESSAGE_FLOW_MARKER': {
|
16659 | 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'
|
16660 | }
|
16661 | };
|
16662 |
|
16663 | this.getRawPath = function getRawPath(pathId) {
|
16664 | return this.pathMap[pathId].d;
|
16665 | };
|
16666 |
|
16667 | |
16668 |
|
16669 |
|
16670 |
|
16671 |
|
16672 |
|
16673 |
|
16674 |
|
16675 |
|
16676 |
|
16677 |
|
16678 |
|
16679 |
|
16680 |
|
16681 |
|
16682 |
|
16683 |
|
16684 |
|
16685 |
|
16686 |
|
16687 |
|
16688 |
|
16689 |
|
16690 |
|
16691 |
|
16692 |
|
16693 |
|
16694 |
|
16695 |
|
16696 |
|
16697 |
|
16698 |
|
16699 |
|
16700 |
|
16701 |
|
16702 |
|
16703 |
|
16704 |
|
16705 |
|
16706 |
|
16707 |
|
16708 |
|
16709 |
|
16710 |
|
16711 |
|
16712 |
|
16713 |
|
16714 |
|
16715 |
|
16716 | this.getScaledPath = function getScaledPath(pathId, param) {
|
16717 | var rawPath = this.pathMap[pathId];
|
16718 |
|
16719 |
|
16720 |
|
16721 | var mx, my;
|
16722 |
|
16723 | if (param.abspos) {
|
16724 | mx = param.abspos.x;
|
16725 | my = param.abspos.y;
|
16726 | } else {
|
16727 | mx = param.containerWidth * param.position.mx;
|
16728 | my = param.containerHeight * param.position.my;
|
16729 | }
|
16730 |
|
16731 | var coordinates = {};
|
16732 | if (param.position) {
|
16733 |
|
16734 |
|
16735 | var heightRatio = (param.containerHeight / rawPath.height) * param.yScaleFactor;
|
16736 | var widthRatio = (param.containerWidth / rawPath.width) * param.xScaleFactor;
|
16737 |
|
16738 |
|
16739 |
|
16740 | for (var heightIndex = 0; heightIndex < rawPath.heightElements.length; heightIndex++) {
|
16741 | coordinates['y' + heightIndex] = rawPath.heightElements[heightIndex] * heightRatio;
|
16742 | }
|
16743 |
|
16744 |
|
16745 | for (var widthIndex = 0; widthIndex < rawPath.widthElements.length; widthIndex++) {
|
16746 | coordinates['x' + widthIndex] = rawPath.widthElements[widthIndex] * widthRatio;
|
16747 | }
|
16748 | }
|
16749 |
|
16750 |
|
16751 | var path = format(
|
16752 | rawPath.d, {
|
16753 | mx: mx,
|
16754 | my: my,
|
16755 | e: coordinates
|
16756 | }
|
16757 | );
|
16758 | return path;
|
16759 | };
|
16760 | }
|
16761 |
|
16762 |
|
16763 |
|
16764 |
|
16765 | var tokenRegex = /\{([^}]+)\}/g,
|
16766 | objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g;
|
16767 |
|
16768 | function replacer(all, key, obj) {
|
16769 | var res = obj;
|
16770 | key.replace(objNotationRegex, function(all, name, quote, quotedName, isFunc) {
|
16771 | name = name || quotedName;
|
16772 | if (res) {
|
16773 | if (name in res) {
|
16774 | res = res[name];
|
16775 | }
|
16776 | typeof res == 'function' && isFunc && (res = res());
|
16777 | }
|
16778 | });
|
16779 | res = (res == null || res == obj ? all : res) + '';
|
16780 |
|
16781 | return res;
|
16782 | }
|
16783 |
|
16784 | function format(str, obj) {
|
16785 | return String(str).replace(tokenRegex, function(all, key) {
|
16786 | return replacer(all, key, obj);
|
16787 | });
|
16788 | }
|
16789 |
|
16790 | var DrawModule$1 = {
|
16791 | __init__: [ 'bpmnRenderer' ],
|
16792 | bpmnRenderer: [ 'type', BpmnRenderer ],
|
16793 | textRenderer: [ 'type', TextRenderer ],
|
16794 | pathMap: [ 'type', PathMap ]
|
16795 | };
|
16796 |
|
16797 | |
16798 |
|
16799 |
|
16800 |
|
16801 |
|
16802 |
|
16803 |
|
16804 |
|
16805 |
|
16806 |
|
16807 |
|
16808 |
|
16809 |
|
16810 |
|
16811 |
|
16812 |
|
16813 |
|
16814 |
|
16815 | function translate$1(template, replacements) {
|
16816 |
|
16817 | replacements = replacements || {};
|
16818 |
|
16819 | return template.replace(/{([^}]+)}/g, function(_, key) {
|
16820 | return replacements[key] || '{' + key + '}';
|
16821 | });
|
16822 | }
|
16823 |
|
16824 | var translate$2 = {
|
16825 | translate: [ 'value', translate$1 ]
|
16826 | };
|
16827 |
|
16828 | var DEFAULT_LABEL_SIZE$1 = {
|
16829 | width: 90,
|
16830 | height: 20
|
16831 | };
|
16832 |
|
16833 | var FLOW_LABEL_INDENT = 15;
|
16834 |
|
16835 |
|
16836 | |
16837 |
|
16838 |
|
16839 |
|
16840 |
|
16841 |
|
16842 | function isLabelExternal(semantic) {
|
16843 | return is$1(semantic, 'bpmn:Event') ||
|
16844 | is$1(semantic, 'bpmn:Gateway') ||
|
16845 | is$1(semantic, 'bpmn:DataStoreReference') ||
|
16846 | is$1(semantic, 'bpmn:DataObjectReference') ||
|
16847 | is$1(semantic, 'bpmn:DataInput') ||
|
16848 | is$1(semantic, 'bpmn:DataOutput') ||
|
16849 | is$1(semantic, 'bpmn:SequenceFlow') ||
|
16850 | is$1(semantic, 'bpmn:MessageFlow') ||
|
16851 | is$1(semantic, 'bpmn:Group');
|
16852 | }
|
16853 |
|
16854 | |
16855 |
|
16856 |
|
16857 |
|
16858 |
|
16859 |
|
16860 | function hasExternalLabel(element) {
|
16861 | return isLabel(element.label);
|
16862 | }
|
16863 |
|
16864 | |
16865 |
|
16866 |
|
16867 |
|
16868 |
|
16869 |
|
16870 | function getFlowLabelPosition(waypoints) {
|
16871 |
|
16872 |
|
16873 | var mid = waypoints.length / 2 - 1;
|
16874 |
|
16875 | var first = waypoints[Math.floor(mid)];
|
16876 | var second = waypoints[Math.ceil(mid + 0.01)];
|
16877 |
|
16878 |
|
16879 | var position = getWaypointsMid(waypoints);
|
16880 |
|
16881 |
|
16882 | var angle = Math.atan((second.y - first.y) / (second.x - first.x));
|
16883 |
|
16884 | var x = position.x,
|
16885 | y = position.y;
|
16886 |
|
16887 | if (Math.abs(angle) < Math.PI / 2) {
|
16888 | y -= FLOW_LABEL_INDENT;
|
16889 | } else {
|
16890 | x += FLOW_LABEL_INDENT;
|
16891 | }
|
16892 |
|
16893 | return { x: x, y: y };
|
16894 | }
|
16895 |
|
16896 |
|
16897 | |
16898 |
|
16899 |
|
16900 |
|
16901 |
|
16902 |
|
16903 | function getWaypointsMid(waypoints) {
|
16904 |
|
16905 | var mid = waypoints.length / 2 - 1;
|
16906 |
|
16907 | var first = waypoints[Math.floor(mid)];
|
16908 | var second = waypoints[Math.ceil(mid + 0.01)];
|
16909 |
|
16910 | return {
|
16911 | x: first.x + (second.x - first.x) / 2,
|
16912 | y: first.y + (second.y - first.y) / 2
|
16913 | };
|
16914 | }
|
16915 |
|
16916 |
|
16917 | function getExternalLabelMid(element) {
|
16918 |
|
16919 | if (element.waypoints) {
|
16920 | return getFlowLabelPosition(element.waypoints);
|
16921 | } else if (is$1(element, 'bpmn:Group')) {
|
16922 | return {
|
16923 | x: element.x + element.width / 2,
|
16924 | y: element.y + DEFAULT_LABEL_SIZE$1.height / 2
|
16925 | };
|
16926 | } else {
|
16927 | return {
|
16928 | x: element.x + element.width / 2,
|
16929 | y: element.y + element.height + DEFAULT_LABEL_SIZE$1.height / 2
|
16930 | };
|
16931 | }
|
16932 | }
|
16933 |
|
16934 |
|
16935 | |
16936 |
|
16937 |
|
16938 |
|
16939 |
|
16940 |
|
16941 |
|
16942 | function getExternalLabelBounds(semantic, element) {
|
16943 |
|
16944 | var mid,
|
16945 | size,
|
16946 | bounds,
|
16947 | di = semantic.di,
|
16948 | label = di.label;
|
16949 |
|
16950 | if (label && label.bounds) {
|
16951 | bounds = label.bounds;
|
16952 |
|
16953 | size = {
|
16954 | width: Math.max(DEFAULT_LABEL_SIZE$1.width, bounds.width),
|
16955 | height: bounds.height
|
16956 | };
|
16957 |
|
16958 | mid = {
|
16959 | x: bounds.x + bounds.width / 2,
|
16960 | y: bounds.y + bounds.height / 2
|
16961 | };
|
16962 | } else {
|
16963 |
|
16964 | mid = getExternalLabelMid(element);
|
16965 |
|
16966 | size = DEFAULT_LABEL_SIZE$1;
|
16967 | }
|
16968 |
|
16969 | return assign({
|
16970 | x: mid.x - size.width / 2,
|
16971 | y: mid.y - size.height / 2
|
16972 | }, size);
|
16973 | }
|
16974 |
|
16975 | function isLabel(element) {
|
16976 | return element && !!element.labelTarget;
|
16977 | }
|
16978 |
|
16979 | |
16980 |
|
16981 |
|
16982 |
|
16983 |
|
16984 |
|
16985 |
|
16986 |
|
16987 | function pointDistance(a, b) {
|
16988 | if (!a || !b) {
|
16989 | return -1;
|
16990 | }
|
16991 |
|
16992 | return Math.sqrt(
|
16993 | Math.pow(a.x - b.x, 2) +
|
16994 | Math.pow(a.y - b.y, 2)
|
16995 | );
|
16996 | }
|
16997 |
|
16998 |
|
16999 | |
17000 |
|
17001 |
|
17002 |
|
17003 |
|
17004 |
|
17005 |
|
17006 |
|
17007 |
|
17008 |
|
17009 | function pointsOnLine(p, q, r, accuracy) {
|
17010 |
|
17011 | if (typeof accuracy === 'undefined') {
|
17012 | accuracy = 5;
|
17013 | }
|
17014 |
|
17015 | if (!p || !q || !r) {
|
17016 | return false;
|
17017 | }
|
17018 |
|
17019 | var val = (q.x - p.x) * (r.y - p.y) - (q.y - p.y) * (r.x - p.x),
|
17020 | dist = pointDistance(p, q);
|
17021 |
|
17022 |
|
17023 | return Math.abs(val / dist) <= accuracy;
|
17024 | }
|
17025 |
|
17026 |
|
17027 | var ALIGNED_THRESHOLD = 2;
|
17028 |
|
17029 | |
17030 |
|
17031 |
|
17032 |
|
17033 |
|
17034 |
|
17035 |
|
17036 |
|
17037 | function pointsAligned(a, b) {
|
17038 | var points;
|
17039 |
|
17040 | if (isArray(a)) {
|
17041 | points = a;
|
17042 | } else {
|
17043 | points = [ a, b ];
|
17044 | }
|
17045 |
|
17046 | if (pointsAlignedHorizontally(points)) {
|
17047 | return 'h';
|
17048 | }
|
17049 |
|
17050 | if (pointsAlignedVertically(points)) {
|
17051 | return 'v';
|
17052 | }
|
17053 |
|
17054 | return false;
|
17055 | }
|
17056 |
|
17057 | function pointsAlignedHorizontally(a, b) {
|
17058 | var points;
|
17059 |
|
17060 | if (isArray(a)) {
|
17061 | points = a;
|
17062 | } else {
|
17063 | points = [ a, b ];
|
17064 | }
|
17065 |
|
17066 | var firstPoint = points.slice().shift();
|
17067 |
|
17068 | return every(points, function(point) {
|
17069 | return Math.abs(firstPoint.y - point.y) <= ALIGNED_THRESHOLD;
|
17070 | });
|
17071 | }
|
17072 |
|
17073 | function pointsAlignedVertically(a, b) {
|
17074 | var points;
|
17075 |
|
17076 | if (isArray(a)) {
|
17077 | points = a;
|
17078 | } else {
|
17079 | points = [ a, b ];
|
17080 | }
|
17081 |
|
17082 | var firstPoint = points.slice().shift();
|
17083 |
|
17084 | return every(points, function(point) {
|
17085 | return Math.abs(firstPoint.x - point.x) <= ALIGNED_THRESHOLD;
|
17086 | });
|
17087 | }
|
17088 |
|
17089 |
|
17090 |
|
17091 | |
17092 |
|
17093 |
|
17094 |
|
17095 |
|
17096 |
|
17097 |
|
17098 |
|
17099 |
|
17100 | function pointInRect(p, rect, tolerance) {
|
17101 | tolerance = tolerance || 0;
|
17102 |
|
17103 | return p.x > rect.x - tolerance &&
|
17104 | p.y > rect.y - tolerance &&
|
17105 | p.x < rect.x + rect.width + tolerance &&
|
17106 | p.y < rect.y + rect.height + tolerance;
|
17107 | }
|
17108 |
|
17109 | |
17110 |
|
17111 |
|
17112 |
|
17113 |
|
17114 |
|
17115 |
|
17116 |
|
17117 | function getMidPoint(p, q) {
|
17118 | return {
|
17119 | x: Math.round(p.x + ((q.x - p.x) / 2.0)),
|
17120 | y: Math.round(p.y + ((q.y - p.y) / 2.0))
|
17121 | };
|
17122 | }
|
17123 |
|
17124 | |
17125 |
|
17126 |
|
17127 |
|
17128 |
|
17129 |
|
17130 |
|
17131 |
|
17132 | var has$1 = 'hasOwnProperty',
|
17133 | p2s = /,?([a-z]),?/gi,
|
17134 | toFloat = parseFloat,
|
17135 | math = Math,
|
17136 | PI = math.PI,
|
17137 | mmin = math.min,
|
17138 | mmax = math.max,
|
17139 | pow = math.pow,
|
17140 | abs = math.abs,
|
17141 | pathCommand = /([a-z])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?[\s]*,?[\s]*)+)/ig,
|
17142 | pathValues = /(-?\d*\.?\d*(?:e[-+]?\\d+)?)[\s]*,?[\s]*/ig;
|
17143 |
|
17144 | function is$2(o, type) {
|
17145 | type = String.prototype.toLowerCase.call(type);
|
17146 |
|
17147 | if (type == 'finite') {
|
17148 | return isFinite(o);
|
17149 | }
|
17150 |
|
17151 | if (type == 'array' && (o instanceof Array || Array.isArray && Array.isArray(o))) {
|
17152 | return true;
|
17153 | }
|
17154 |
|
17155 | return (type == 'null' && o === null) ||
|
17156 | (type == typeof o && o !== null) ||
|
17157 | (type == 'object' && o === Object(o)) ||
|
17158 | Object.prototype.toString.call(o).slice(8, -1).toLowerCase() == type;
|
17159 | }
|
17160 |
|
17161 | function clone$1(obj) {
|
17162 |
|
17163 | if (typeof obj == 'function' || Object(obj) !== obj) {
|
17164 | return obj;
|
17165 | }
|
17166 |
|
17167 | var res = new obj.constructor;
|
17168 |
|
17169 | for (var key in obj) if (obj[has$1](key)) {
|
17170 | res[key] = clone$1(obj[key]);
|
17171 | }
|
17172 |
|
17173 | return res;
|
17174 | }
|
17175 |
|
17176 | function repush(array, item) {
|
17177 | for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
|
17178 | return array.push(array.splice(i, 1)[0]);
|
17179 | }
|
17180 | }
|
17181 |
|
17182 | function cacher(f, scope, postprocessor) {
|
17183 |
|
17184 | function newf() {
|
17185 |
|
17186 | var arg = Array.prototype.slice.call(arguments, 0),
|
17187 | args = arg.join('\u2400'),
|
17188 | cache = newf.cache = newf.cache || {},
|
17189 | count = newf.count = newf.count || [];
|
17190 |
|
17191 | if (cache[has$1](args)) {
|
17192 | repush(count, args);
|
17193 | return postprocessor ? postprocessor(cache[args]) : cache[args];
|
17194 | }
|
17195 |
|
17196 | count.length >= 1e3 && delete cache[count.shift()];
|
17197 | count.push(args);
|
17198 | cache[args] = f.apply(scope, arg);
|
17199 |
|
17200 | return postprocessor ? postprocessor(cache[args]) : cache[args];
|
17201 | }
|
17202 | return newf;
|
17203 | }
|
17204 |
|
17205 | function parsePathString(pathString) {
|
17206 |
|
17207 | if (!pathString) {
|
17208 | return null;
|
17209 | }
|
17210 |
|
17211 | var pth = paths(pathString);
|
17212 |
|
17213 | if (pth.arr) {
|
17214 | return clone$1(pth.arr);
|
17215 | }
|
17216 |
|
17217 | var paramCounts = { a: 7, c: 6, o: 2, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, u: 3, z: 0 },
|
17218 | data = [];
|
17219 |
|
17220 | if (is$2(pathString, 'array') && is$2(pathString[0], 'array')) {
|
17221 | data = clone$1(pathString);
|
17222 | }
|
17223 |
|
17224 | if (!data.length) {
|
17225 |
|
17226 | String(pathString).replace(pathCommand, function(a, b, c) {
|
17227 | var params = [],
|
17228 | name = b.toLowerCase();
|
17229 |
|
17230 | c.replace(pathValues, function(a, b) {
|
17231 | b && params.push(+b);
|
17232 | });
|
17233 |
|
17234 | if (name == 'm' && params.length > 2) {
|
17235 | data.push([b].concat(params.splice(0, 2)));
|
17236 | name = 'l';
|
17237 | b = b == 'm' ? 'l' : 'L';
|
17238 | }
|
17239 |
|
17240 | if (name == 'o' && params.length == 1) {
|
17241 | data.push([b, params[0]]);
|
17242 | }
|
17243 |
|
17244 | if (name == 'r') {
|
17245 | data.push([b].concat(params));
|
17246 | } else while (params.length >= paramCounts[name]) {
|
17247 | data.push([b].concat(params.splice(0, paramCounts[name])));
|
17248 | if (!paramCounts[name]) {
|
17249 | break;
|
17250 | }
|
17251 | }
|
17252 | });
|
17253 | }
|
17254 |
|
17255 | data.toString = paths.toString;
|
17256 | pth.arr = clone$1(data);
|
17257 |
|
17258 | return data;
|
17259 | }
|
17260 |
|
17261 | function paths(ps) {
|
17262 | var p = paths.ps = paths.ps || {};
|
17263 |
|
17264 | if (p[ps]) {
|
17265 | p[ps].sleep = 100;
|
17266 | } else {
|
17267 | p[ps] = {
|
17268 | sleep: 100
|
17269 | };
|
17270 | }
|
17271 |
|
17272 | setTimeout(function() {
|
17273 | for (var key in p) if (p[has$1](key) && key != ps) {
|
17274 | p[key].sleep--;
|
17275 | !p[key].sleep && delete p[key];
|
17276 | }
|
17277 | });
|
17278 |
|
17279 | return p[ps];
|
17280 | }
|
17281 |
|
17282 | function box(x, y, width, height) {
|
17283 | if (x == null) {
|
17284 | x = y = width = height = 0;
|
17285 | }
|
17286 |
|
17287 | if (y == null) {
|
17288 | y = x.y;
|
17289 | width = x.width;
|
17290 | height = x.height;
|
17291 | x = x.x;
|
17292 | }
|
17293 |
|
17294 | return {
|
17295 | x: x,
|
17296 | y: y,
|
17297 | width: width,
|
17298 | w: width,
|
17299 | height: height,
|
17300 | h: height,
|
17301 | x2: x + width,
|
17302 | y2: y + height,
|
17303 | cx: x + width / 2,
|
17304 | cy: y + height / 2,
|
17305 | r1: math.min(width, height) / 2,
|
17306 | r2: math.max(width, height) / 2,
|
17307 | r0: math.sqrt(width * width + height * height) / 2,
|
17308 | path: rectPath(x, y, width, height),
|
17309 | vb: [x, y, width, height].join(' ')
|
17310 | };
|
17311 | }
|
17312 |
|
17313 | function pathToString() {
|
17314 | return this.join(',').replace(p2s, '$1');
|
17315 | }
|
17316 |
|
17317 | function pathClone(pathArray) {
|
17318 | var res = clone$1(pathArray);
|
17319 | res.toString = pathToString;
|
17320 | return res;
|
17321 | }
|
17322 |
|
17323 | function findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
|
17324 | var t1 = 1 - t,
|
17325 | t13 = pow(t1, 3),
|
17326 | t12 = pow(t1, 2),
|
17327 | t2 = t * t,
|
17328 | t3 = t2 * t,
|
17329 | x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x,
|
17330 | y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y,
|
17331 | mx = p1x + 2 * t * (c1x - p1x) + t2 * (c2x - 2 * c1x + p1x),
|
17332 | my = p1y + 2 * t * (c1y - p1y) + t2 * (c2y - 2 * c1y + p1y),
|
17333 | nx = c1x + 2 * t * (c2x - c1x) + t2 * (p2x - 2 * c2x + c1x),
|
17334 | ny = c1y + 2 * t * (c2y - c1y) + t2 * (p2y - 2 * c2y + c1y),
|
17335 | ax = t1 * p1x + t * c1x,
|
17336 | ay = t1 * p1y + t * c1y,
|
17337 | cx = t1 * c2x + t * p2x,
|
17338 | cy = t1 * c2y + t * p2y,
|
17339 | alpha = (90 - math.atan2(mx - nx, my - ny) * 180 / PI);
|
17340 |
|
17341 | return {
|
17342 | x: x,
|
17343 | y: y,
|
17344 | m: { x: mx, y: my },
|
17345 | n: { x: nx, y: ny },
|
17346 | start: { x: ax, y: ay },
|
17347 | end: { x: cx, y: cy },
|
17348 | alpha: alpha
|
17349 | };
|
17350 | }
|
17351 |
|
17352 | function bezierBBox(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
|
17353 |
|
17354 | if (!is$2(p1x, 'array')) {
|
17355 | p1x = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y];
|
17356 | }
|
17357 |
|
17358 | var bbox = curveBBox.apply(null, p1x);
|
17359 |
|
17360 | return box(
|
17361 | bbox.min.x,
|
17362 | bbox.min.y,
|
17363 | bbox.max.x - bbox.min.x,
|
17364 | bbox.max.y - bbox.min.y
|
17365 | );
|
17366 | }
|
17367 |
|
17368 | function isPointInsideBBox(bbox, x, y) {
|
17369 | return x >= bbox.x &&
|
17370 | x <= bbox.x + bbox.width &&
|
17371 | y >= bbox.y &&
|
17372 | y <= bbox.y + bbox.height;
|
17373 | }
|
17374 |
|
17375 | function isBBoxIntersect(bbox1, bbox2) {
|
17376 | bbox1 = box(bbox1);
|
17377 | bbox2 = box(bbox2);
|
17378 | return isPointInsideBBox(bbox2, bbox1.x, bbox1.y)
|
17379 | || isPointInsideBBox(bbox2, bbox1.x2, bbox1.y)
|
17380 | || isPointInsideBBox(bbox2, bbox1.x, bbox1.y2)
|
17381 | || isPointInsideBBox(bbox2, bbox1.x2, bbox1.y2)
|
17382 | || isPointInsideBBox(bbox1, bbox2.x, bbox2.y)
|
17383 | || isPointInsideBBox(bbox1, bbox2.x2, bbox2.y)
|
17384 | || isPointInsideBBox(bbox1, bbox2.x, bbox2.y2)
|
17385 | || isPointInsideBBox(bbox1, bbox2.x2, bbox2.y2)
|
17386 | || (bbox1.x < bbox2.x2 && bbox1.x > bbox2.x
|
17387 | || bbox2.x < bbox1.x2 && bbox2.x > bbox1.x)
|
17388 | && (bbox1.y < bbox2.y2 && bbox1.y > bbox2.y
|
17389 | || bbox2.y < bbox1.y2 && bbox2.y > bbox1.y);
|
17390 | }
|
17391 |
|
17392 | function base3(t, p1, p2, p3, p4) {
|
17393 | var t1 = -3 * p1 + 9 * p2 - 9 * p3 + 3 * p4,
|
17394 | t2 = t * t1 + 6 * p1 - 12 * p2 + 6 * p3;
|
17395 | return t * t2 - 3 * p1 + 3 * p2;
|
17396 | }
|
17397 |
|
17398 | function bezlen(x1, y1, x2, y2, x3, y3, x4, y4, z) {
|
17399 |
|
17400 | if (z == null) {
|
17401 | z = 1;
|
17402 | }
|
17403 |
|
17404 | z = z > 1 ? 1 : z < 0 ? 0 : z;
|
17405 |
|
17406 | var z2 = z / 2,
|
17407 | n = 12,
|
17408 | Tvalues = [-.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816],
|
17409 | 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],
|
17410 | sum = 0;
|
17411 |
|
17412 | for (var i = 0; i < n; i++) {
|
17413 | var ct = z2 * Tvalues[i] + z2,
|
17414 | xbase = base3(ct, x1, x2, x3, x4),
|
17415 | ybase = base3(ct, y1, y2, y3, y4),
|
17416 | comb = xbase * xbase + ybase * ybase;
|
17417 |
|
17418 | sum += Cvalues[i] * math.sqrt(comb);
|
17419 | }
|
17420 |
|
17421 | return z2 * sum;
|
17422 | }
|
17423 |
|
17424 |
|
17425 | function intersectLines(x1, y1, x2, y2, x3, y3, x4, y4) {
|
17426 |
|
17427 | if (
|
17428 | mmax(x1, x2) < mmin(x3, x4) ||
|
17429 | mmin(x1, x2) > mmax(x3, x4) ||
|
17430 | mmax(y1, y2) < mmin(y3, y4) ||
|
17431 | mmin(y1, y2) > mmax(y3, y4)
|
17432 | ) {
|
17433 | return;
|
17434 | }
|
17435 |
|
17436 | var nx = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4),
|
17437 | ny = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4),
|
17438 | denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
|
17439 |
|
17440 | if (!denominator) {
|
17441 | return;
|
17442 | }
|
17443 |
|
17444 | var px = nx / denominator,
|
17445 | py = ny / denominator,
|
17446 | px2 = +px.toFixed(2),
|
17447 | py2 = +py.toFixed(2);
|
17448 |
|
17449 | if (
|
17450 | px2 < +mmin(x1, x2).toFixed(2) ||
|
17451 | px2 > +mmax(x1, x2).toFixed(2) ||
|
17452 | px2 < +mmin(x3, x4).toFixed(2) ||
|
17453 | px2 > +mmax(x3, x4).toFixed(2) ||
|
17454 | py2 < +mmin(y1, y2).toFixed(2) ||
|
17455 | py2 > +mmax(y1, y2).toFixed(2) ||
|
17456 | py2 < +mmin(y3, y4).toFixed(2) ||
|
17457 | py2 > +mmax(y3, y4).toFixed(2)
|
17458 | ) {
|
17459 | return;
|
17460 | }
|
17461 |
|
17462 | return { x: px, y: py };
|
17463 | }
|
17464 |
|
17465 | function findBezierIntersections(bez1, bez2, justCount) {
|
17466 | var bbox1 = bezierBBox(bez1),
|
17467 | bbox2 = bezierBBox(bez2);
|
17468 |
|
17469 | if (!isBBoxIntersect(bbox1, bbox2)) {
|
17470 | return justCount ? 0 : [];
|
17471 | }
|
17472 |
|
17473 | var l1 = bezlen.apply(0, bez1),
|
17474 | l2 = bezlen.apply(0, bez2),
|
17475 | n1 = ~~(l1 / 5),
|
17476 | n2 = ~~(l2 / 5),
|
17477 | dots1 = [],
|
17478 | dots2 = [],
|
17479 | xy = {},
|
17480 | res = justCount ? 0 : [];
|
17481 |
|
17482 | for (var i = 0; i < n1 + 1; i++) {
|
17483 | var p = findDotsAtSegment.apply(0, bez1.concat(i / n1));
|
17484 | dots1.push({ x: p.x, y: p.y, t: i / n1 });
|
17485 | }
|
17486 |
|
17487 | for (i = 0; i < n2 + 1; i++) {
|
17488 | p = findDotsAtSegment.apply(0, bez2.concat(i / n2));
|
17489 | dots2.push({ x: p.x, y: p.y, t: i / n2 });
|
17490 | }
|
17491 |
|
17492 | for (i = 0; i < n1; i++) {
|
17493 |
|
17494 | for (var j = 0; j < n2; j++) {
|
17495 | var di = dots1[i],
|
17496 | di1 = dots1[i + 1],
|
17497 | dj = dots2[j],
|
17498 | dj1 = dots2[j + 1],
|
17499 | ci = abs(di1.x - di.x) < .01 ? 'y' : 'x',
|
17500 | cj = abs(dj1.x - dj.x) < .01 ? 'y' : 'x',
|
17501 | is = intersectLines(di.x, di.y, di1.x, di1.y, dj.x, dj.y, dj1.x, dj1.y);
|
17502 |
|
17503 | if (is) {
|
17504 |
|
17505 | if (xy[is.x.toFixed(0)] == is.y.toFixed(0)) {
|
17506 | continue;
|
17507 | }
|
17508 |
|
17509 | xy[is.x.toFixed(0)] = is.y.toFixed(0);
|
17510 |
|
17511 | var t1 = di.t + abs((is[ci] - di[ci]) / (di1[ci] - di[ci])) * (di1.t - di.t),
|
17512 | t2 = dj.t + abs((is[cj] - dj[cj]) / (dj1[cj] - dj[cj])) * (dj1.t - dj.t);
|
17513 |
|
17514 | if (t1 >= 0 && t1 <= 1 && t2 >= 0 && t2 <= 1) {
|
17515 |
|
17516 | if (justCount) {
|
17517 | res++;
|
17518 | } else {
|
17519 | res.push({
|
17520 | x: is.x,
|
17521 | y: is.y,
|
17522 | t1: t1,
|
17523 | t2: t2
|
17524 | });
|
17525 | }
|
17526 | }
|
17527 | }
|
17528 | }
|
17529 | }
|
17530 |
|
17531 | return res;
|
17532 | }
|
17533 |
|
17534 |
|
17535 | |
17536 |
|
17537 |
|
17538 |
|
17539 |
|
17540 |
|
17541 |
|
17542 |
|
17543 |
|
17544 |
|
17545 |
|
17546 |
|
17547 |
|
17548 |
|
17549 |
|
17550 |
|
17551 |
|
17552 |
|
17553 |
|
17554 |
|
17555 |
|
17556 |
|
17557 |
|
17558 |
|
17559 |
|
17560 |
|
17561 |
|
17562 |
|
17563 |
|
17564 |
|
17565 | function findPathIntersections(path1, path2, justCount) {
|
17566 | path1 = pathToCurve(path1);
|
17567 | path2 = pathToCurve(path2);
|
17568 |
|
17569 | var x1, y1, x2, y2, x1m, y1m, x2m, y2m, bez1, bez2,
|
17570 | res = justCount ? 0 : [];
|
17571 |
|
17572 | for (var i = 0, ii = path1.length; i < ii; i++) {
|
17573 | var pi = path1[i];
|
17574 |
|
17575 | if (pi[0] == 'M') {
|
17576 | x1 = x1m = pi[1];
|
17577 | y1 = y1m = pi[2];
|
17578 | } else {
|
17579 |
|
17580 | if (pi[0] == 'C') {
|
17581 | bez1 = [x1, y1].concat(pi.slice(1));
|
17582 | x1 = bez1[6];
|
17583 | y1 = bez1[7];
|
17584 | } else {
|
17585 | bez1 = [x1, y1, x1, y1, x1m, y1m, x1m, y1m];
|
17586 | x1 = x1m;
|
17587 | y1 = y1m;
|
17588 | }
|
17589 |
|
17590 | for (var j = 0, jj = path2.length; j < jj; j++) {
|
17591 | var pj = path2[j];
|
17592 |
|
17593 | if (pj[0] == 'M') {
|
17594 | x2 = x2m = pj[1];
|
17595 | y2 = y2m = pj[2];
|
17596 | } else {
|
17597 |
|
17598 | if (pj[0] == 'C') {
|
17599 | bez2 = [x2, y2].concat(pj.slice(1));
|
17600 | x2 = bez2[6];
|
17601 | y2 = bez2[7];
|
17602 | } else {
|
17603 | bez2 = [x2, y2, x2, y2, x2m, y2m, x2m, y2m];
|
17604 | x2 = x2m;
|
17605 | y2 = y2m;
|
17606 | }
|
17607 |
|
17608 | var intr = findBezierIntersections(bez1, bez2, justCount);
|
17609 |
|
17610 | if (justCount) {
|
17611 | res += intr;
|
17612 | } else {
|
17613 |
|
17614 | for (var k = 0, kk = intr.length; k < kk; k++) {
|
17615 | intr[k].segment1 = i;
|
17616 | intr[k].segment2 = j;
|
17617 | intr[k].bez1 = bez1;
|
17618 | intr[k].bez2 = bez2;
|
17619 | }
|
17620 |
|
17621 | res = res.concat(intr);
|
17622 | }
|
17623 | }
|
17624 | }
|
17625 | }
|
17626 | }
|
17627 |
|
17628 | return res;
|
17629 | }
|
17630 |
|
17631 |
|
17632 | function rectPath(x, y, w, h, r) {
|
17633 | if (r) {
|
17634 | return [
|
17635 | ['M', +x + (+r), y],
|
17636 | ['l', w - r * 2, 0],
|
17637 | ['a', r, r, 0, 0, 1, r, r],
|
17638 | ['l', 0, h - r * 2],
|
17639 | ['a', r, r, 0, 0, 1, -r, r],
|
17640 | ['l', r * 2 - w, 0],
|
17641 | ['a', r, r, 0, 0, 1, -r, -r],
|
17642 | ['l', 0, r * 2 - h],
|
17643 | ['a', r, r, 0, 0, 1, r, -r],
|
17644 | ['z']
|
17645 | ];
|
17646 | }
|
17647 |
|
17648 | var res = [['M', x, y], ['l', w, 0], ['l', 0, h], ['l', -w, 0], ['z']];
|
17649 | res.toString = pathToString;
|
17650 |
|
17651 | return res;
|
17652 | }
|
17653 |
|
17654 | function ellipsePath(x, y, rx, ry, a) {
|
17655 | if (a == null && ry == null) {
|
17656 | ry = rx;
|
17657 | }
|
17658 |
|
17659 | x = +x;
|
17660 | y = +y;
|
17661 | rx = +rx;
|
17662 | ry = +ry;
|
17663 |
|
17664 | if (a != null) {
|
17665 | var rad = Math.PI / 180,
|
17666 | x1 = x + rx * Math.cos(-ry * rad),
|
17667 | x2 = x + rx * Math.cos(-a * rad),
|
17668 | y1 = y + rx * Math.sin(-ry * rad),
|
17669 | y2 = y + rx * Math.sin(-a * rad),
|
17670 | res = [['M', x1, y1], ['A', rx, rx, 0, +(a - ry > 180), 0, x2, y2]];
|
17671 | } else {
|
17672 | res = [
|
17673 | ['M', x, y],
|
17674 | ['m', 0, -ry],
|
17675 | ['a', rx, ry, 0, 1, 1, 0, 2 * ry],
|
17676 | ['a', rx, ry, 0, 1, 1, 0, -2 * ry],
|
17677 | ['z']
|
17678 | ];
|
17679 | }
|
17680 |
|
17681 | res.toString = pathToString;
|
17682 |
|
17683 | return res;
|
17684 | }
|
17685 |
|
17686 |
|
17687 | function pathToAbsolute(pathArray) {
|
17688 | var pth = paths(pathArray);
|
17689 |
|
17690 | if (pth.abs) {
|
17691 | return pathClone(pth.abs);
|
17692 | }
|
17693 |
|
17694 | if (!is$2(pathArray, 'array') || !is$2(pathArray && pathArray[0], 'array')) {
|
17695 | pathArray = parsePathString(pathArray);
|
17696 | }
|
17697 |
|
17698 | if (!pathArray || !pathArray.length) {
|
17699 | return [['M', 0, 0]];
|
17700 | }
|
17701 |
|
17702 | var res = [],
|
17703 | x = 0,
|
17704 | y = 0,
|
17705 | mx = 0,
|
17706 | my = 0,
|
17707 | start = 0,
|
17708 | pa0;
|
17709 |
|
17710 | if (pathArray[0][0] == 'M') {
|
17711 | x = +pathArray[0][1];
|
17712 | y = +pathArray[0][2];
|
17713 | mx = x;
|
17714 | my = y;
|
17715 | start++;
|
17716 | res[0] = ['M', x, y];
|
17717 | }
|
17718 |
|
17719 | var crz = pathArray.length == 3 &&
|
17720 | pathArray[0][0] == 'M' &&
|
17721 | pathArray[1][0].toUpperCase() == 'R' &&
|
17722 | pathArray[2][0].toUpperCase() == 'Z';
|
17723 |
|
17724 | for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) {
|
17725 | res.push(r = []);
|
17726 | pa = pathArray[i];
|
17727 | pa0 = pa[0];
|
17728 |
|
17729 | if (pa0 != pa0.toUpperCase()) {
|
17730 | r[0] = pa0.toUpperCase();
|
17731 |
|
17732 | switch (r[0]) {
|
17733 | case 'A':
|
17734 | r[1] = pa[1];
|
17735 | r[2] = pa[2];
|
17736 | r[3] = pa[3];
|
17737 | r[4] = pa[4];
|
17738 | r[5] = pa[5];
|
17739 | r[6] = +pa[6] + x;
|
17740 | r[7] = +pa[7] + y;
|
17741 | break;
|
17742 | case 'V':
|
17743 | r[1] = +pa[1] + y;
|
17744 | break;
|
17745 | case 'H':
|
17746 | r[1] = +pa[1] + x;
|
17747 | break;
|
17748 | case 'R':
|
17749 | var dots = [x, y].concat(pa.slice(1));
|
17750 |
|
17751 | for (var j = 2, jj = dots.length; j < jj; j++) {
|
17752 | dots[j] = +dots[j] + x;
|
17753 | dots[++j] = +dots[j] + y;
|
17754 | }
|
17755 |
|
17756 | res.pop();
|
17757 | res = res.concat(catmulRomToBezier(dots, crz));
|
17758 | break;
|
17759 | case 'O':
|
17760 | res.pop();
|
17761 | dots = ellipsePath(x, y, pa[1], pa[2]);
|
17762 | dots.push(dots[0]);
|
17763 | res = res.concat(dots);
|
17764 | break;
|
17765 | case 'U':
|
17766 | res.pop();
|
17767 | res = res.concat(ellipsePath(x, y, pa[1], pa[2], pa[3]));
|
17768 | r = ['U'].concat(res[res.length - 1].slice(-2));
|
17769 | break;
|
17770 | case 'M':
|
17771 | mx = +pa[1] + x;
|
17772 | my = +pa[2] + y;
|
17773 | default:
|
17774 |
|
17775 | for (j = 1, jj = pa.length; j < jj; j++) {
|
17776 | r[j] = +pa[j] + ((j % 2) ? x : y);
|
17777 | }
|
17778 | }
|
17779 | } else if (pa0 == 'R') {
|
17780 | dots = [x, y].concat(pa.slice(1));
|
17781 | res.pop();
|
17782 | res = res.concat(catmulRomToBezier(dots, crz));
|
17783 | r = ['R'].concat(pa.slice(-2));
|
17784 | } else if (pa0 == 'O') {
|
17785 | res.pop();
|
17786 | dots = ellipsePath(x, y, pa[1], pa[2]);
|
17787 | dots.push(dots[0]);
|
17788 | res = res.concat(dots);
|
17789 | } else if (pa0 == 'U') {
|
17790 | res.pop();
|
17791 | res = res.concat(ellipsePath(x, y, pa[1], pa[2], pa[3]));
|
17792 | r = ['U'].concat(res[res.length - 1].slice(-2));
|
17793 | } else {
|
17794 |
|
17795 | for (var k = 0, kk = pa.length; k < kk; k++) {
|
17796 | r[k] = pa[k];
|
17797 | }
|
17798 | }
|
17799 | pa0 = pa0.toUpperCase();
|
17800 |
|
17801 | if (pa0 != 'O') {
|
17802 | switch (r[0]) {
|
17803 | case 'Z':
|
17804 | x = +mx;
|
17805 | y = +my;
|
17806 | break;
|
17807 | case 'H':
|
17808 | x = r[1];
|
17809 | break;
|
17810 | case 'V':
|
17811 | y = r[1];
|
17812 | break;
|
17813 | case 'M':
|
17814 | mx = r[r.length - 2];
|
17815 | my = r[r.length - 1];
|
17816 | default:
|
17817 | x = r[r.length - 2];
|
17818 | y = r[r.length - 1];
|
17819 | }
|
17820 | }
|
17821 | }
|
17822 |
|
17823 | res.toString = pathToString;
|
17824 | pth.abs = pathClone(res);
|
17825 |
|
17826 | return res;
|
17827 | }
|
17828 |
|
17829 | function lineToCurve(x1, y1, x2, y2) {
|
17830 | return [
|
17831 | x1, y1, x2,
|
17832 | y2, x2, y2
|
17833 | ];
|
17834 | }
|
17835 |
|
17836 | function qubicToCurve(x1, y1, ax, ay, x2, y2) {
|
17837 | var _13 = 1 / 3,
|
17838 | _23 = 2 / 3;
|
17839 |
|
17840 | return [
|
17841 | _13 * x1 + _23 * ax,
|
17842 | _13 * y1 + _23 * ay,
|
17843 | _13 * x2 + _23 * ax,
|
17844 | _13 * y2 + _23 * ay,
|
17845 | x2,
|
17846 | y2
|
17847 | ];
|
17848 | }
|
17849 |
|
17850 | function arcToCurve(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
|
17851 |
|
17852 |
|
17853 |
|
17854 | var _120 = PI * 120 / 180,
|
17855 | rad = PI / 180 * (+angle || 0),
|
17856 | res = [],
|
17857 | xy,
|
17858 | rotate = cacher(function(x, y, rad) {
|
17859 | var X = x * math.cos(rad) - y * math.sin(rad),
|
17860 | Y = x * math.sin(rad) + y * math.cos(rad);
|
17861 |
|
17862 | return { x: X, y: Y };
|
17863 | });
|
17864 |
|
17865 | if (!recursive) {
|
17866 | xy = rotate(x1, y1, -rad);
|
17867 | x1 = xy.x;
|
17868 | y1 = xy.y;
|
17869 | xy = rotate(x2, y2, -rad);
|
17870 | x2 = xy.x;
|
17871 | y2 = xy.y;
|
17872 |
|
17873 | var x = (x1 - x2) / 2,
|
17874 | y = (y1 - y2) / 2;
|
17875 |
|
17876 | var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
|
17877 |
|
17878 | if (h > 1) {
|
17879 | h = math.sqrt(h);
|
17880 | rx = h * rx;
|
17881 | ry = h * ry;
|
17882 | }
|
17883 |
|
17884 | var rx2 = rx * rx,
|
17885 | ry2 = ry * ry,
|
17886 | k = (large_arc_flag == sweep_flag ? -1 : 1) *
|
17887 | math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
|
17888 | cx = k * rx * y / ry + (x1 + x2) / 2,
|
17889 | cy = k * -ry * x / rx + (y1 + y2) / 2,
|
17890 | f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
|
17891 | f2 = math.asin(((y2 - cy) / ry).toFixed(9));
|
17892 |
|
17893 | f1 = x1 < cx ? PI - f1 : f1;
|
17894 | f2 = x2 < cx ? PI - f2 : f2;
|
17895 | f1 < 0 && (f1 = PI * 2 + f1);
|
17896 | f2 < 0 && (f2 = PI * 2 + f2);
|
17897 |
|
17898 | if (sweep_flag && f1 > f2) {
|
17899 | f1 = f1 - PI * 2;
|
17900 | }
|
17901 | if (!sweep_flag && f2 > f1) {
|
17902 | f2 = f2 - PI * 2;
|
17903 | }
|
17904 | } else {
|
17905 | f1 = recursive[0];
|
17906 | f2 = recursive[1];
|
17907 | cx = recursive[2];
|
17908 | cy = recursive[3];
|
17909 | }
|
17910 |
|
17911 | var df = f2 - f1;
|
17912 |
|
17913 | if (abs(df) > _120) {
|
17914 | var f2old = f2,
|
17915 | x2old = x2,
|
17916 | y2old = y2;
|
17917 |
|
17918 | f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
|
17919 | x2 = cx + rx * math.cos(f2);
|
17920 | y2 = cy + ry * math.sin(f2);
|
17921 | res = arcToCurve(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
|
17922 | }
|
17923 |
|
17924 | df = f2 - f1;
|
17925 |
|
17926 | var c1 = math.cos(f1),
|
17927 | s1 = math.sin(f1),
|
17928 | c2 = math.cos(f2),
|
17929 | s2 = math.sin(f2),
|
17930 | t = math.tan(df / 4),
|
17931 | hx = 4 / 3 * rx * t,
|
17932 | hy = 4 / 3 * ry * t,
|
17933 | m1 = [x1, y1],
|
17934 | m2 = [x1 + hx * s1, y1 - hy * c1],
|
17935 | m3 = [x2 + hx * s2, y2 - hy * c2],
|
17936 | m4 = [x2, y2];
|
17937 |
|
17938 | m2[0] = 2 * m1[0] - m2[0];
|
17939 | m2[1] = 2 * m1[1] - m2[1];
|
17940 |
|
17941 | if (recursive) {
|
17942 | return [m2, m3, m4].concat(res);
|
17943 | } else {
|
17944 | res = [m2, m3, m4].concat(res).join().split(',');
|
17945 | var newres = [];
|
17946 |
|
17947 | for (var i = 0, ii = res.length; i < ii; i++) {
|
17948 | newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
|
17949 | }
|
17950 |
|
17951 | return newres;
|
17952 | }
|
17953 | }
|
17954 |
|
17955 |
|
17956 | function catmulRomToBezier(crp, z) {
|
17957 | var d = [];
|
17958 |
|
17959 | for (var i = 0, iLen = crp.length; iLen - 2 * !z > i; i += 2) {
|
17960 | var p = [
|
17961 | { x: +crp[i - 2], y: +crp[i - 1] },
|
17962 | { x: +crp[i], y: +crp[i + 1] },
|
17963 | { x: +crp[i + 2], y: +crp[i + 3] },
|
17964 | { x: +crp[i + 4], y: +crp[i + 5] }
|
17965 | ];
|
17966 |
|
17967 | if (z) {
|
17968 |
|
17969 | if (!i) {
|
17970 | p[0] = { x: +crp[iLen - 2], y: +crp[iLen - 1] };
|
17971 | } else if (iLen - 4 == i) {
|
17972 | p[3] = { x: +crp[0], y: +crp[1] };
|
17973 | } else if (iLen - 2 == i) {
|
17974 | p[2] = { x: +crp[0], y: +crp[1] };
|
17975 | p[3] = { x: +crp[2], y: +crp[3] };
|
17976 | }
|
17977 |
|
17978 | } else {
|
17979 |
|
17980 | if (iLen - 4 == i) {
|
17981 | p[3] = p[2];
|
17982 | } else if (!i) {
|
17983 | p[0] = { x: +crp[i], y: +crp[i + 1] };
|
17984 | }
|
17985 |
|
17986 | }
|
17987 |
|
17988 | d.push(['C',
|
17989 | (-p[0].x + 6 * p[1].x + p[2].x) / 6,
|
17990 | (-p[0].y + 6 * p[1].y + p[2].y) / 6,
|
17991 | (p[1].x + 6 * p[2].x - p[3].x) / 6,
|
17992 | (p[1].y + 6*p[2].y - p[3].y) / 6,
|
17993 | p[2].x,
|
17994 | p[2].y
|
17995 | ]);
|
17996 | }
|
17997 |
|
17998 | return d;
|
17999 | }
|
18000 |
|
18001 |
|
18002 |
|
18003 |
|
18004 |
|
18005 | function curveBBox(x0, y0, x1, y1, x2, y2, x3, y3) {
|
18006 | var tvalues = [],
|
18007 | bounds = [[], []],
|
18008 | a, b, c, t, t1, t2, b2ac, sqrtb2ac;
|
18009 |
|
18010 | for (var i = 0; i < 2; ++i) {
|
18011 |
|
18012 | if (i == 0) {
|
18013 | b = 6 * x0 - 12 * x1 + 6 * x2;
|
18014 | a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
|
18015 | c = 3 * x1 - 3 * x0;
|
18016 | } else {
|
18017 | b = 6 * y0 - 12 * y1 + 6 * y2;
|
18018 | a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
|
18019 | c = 3 * y1 - 3 * y0;
|
18020 | }
|
18021 |
|
18022 | if (abs(a) < 1e-12) {
|
18023 |
|
18024 | if (abs(b) < 1e-12) {
|
18025 | continue;
|
18026 | }
|
18027 |
|
18028 | t = -c / b;
|
18029 |
|
18030 | if (0 < t && t < 1) {
|
18031 | tvalues.push(t);
|
18032 | }
|
18033 |
|
18034 | continue;
|
18035 | }
|
18036 |
|
18037 | b2ac = b * b - 4 * c * a;
|
18038 | sqrtb2ac = math.sqrt(b2ac);
|
18039 |
|
18040 | if (b2ac < 0) {
|
18041 | continue;
|
18042 | }
|
18043 |
|
18044 | t1 = (-b + sqrtb2ac) / (2 * a);
|
18045 |
|
18046 | if (0 < t1 && t1 < 1) {
|
18047 | tvalues.push(t1);
|
18048 | }
|
18049 |
|
18050 | t2 = (-b - sqrtb2ac) / (2 * a);
|
18051 |
|
18052 | if (0 < t2 && t2 < 1) {
|
18053 | tvalues.push(t2);
|
18054 | }
|
18055 | }
|
18056 |
|
18057 | var j = tvalues.length,
|
18058 | jlen = j,
|
18059 | mt;
|
18060 |
|
18061 | while (j--) {
|
18062 | t = tvalues[j];
|
18063 | mt = 1 - t;
|
18064 | bounds[0][j] = (mt * mt * mt * x0) + (3 * mt * mt * t * x1) + (3 * mt * t * t * x2) + (t * t * t * x3);
|
18065 | bounds[1][j] = (mt * mt * mt * y0) + (3 * mt * mt * t * y1) + (3 * mt * t * t * y2) + (t * t * t * y3);
|
18066 | }
|
18067 |
|
18068 | bounds[0][jlen] = x0;
|
18069 | bounds[1][jlen] = y0;
|
18070 | bounds[0][jlen + 1] = x3;
|
18071 | bounds[1][jlen + 1] = y3;
|
18072 | bounds[0].length = bounds[1].length = jlen + 2;
|
18073 |
|
18074 | return {
|
18075 | min: { x: mmin.apply(0, bounds[0]), y: mmin.apply(0, bounds[1]) },
|
18076 | max: { x: mmax.apply(0, bounds[0]), y: mmax.apply(0, bounds[1]) }
|
18077 | };
|
18078 | }
|
18079 |
|
18080 | function pathToCurve(path, path2) {
|
18081 | var pth = !path2 && paths(path);
|
18082 |
|
18083 | if (!path2 && pth.curve) {
|
18084 | return pathClone(pth.curve);
|
18085 | }
|
18086 |
|
18087 | var p = pathToAbsolute(path),
|
18088 | p2 = path2 && pathToAbsolute(path2),
|
18089 | attrs = { x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null },
|
18090 | attrs2 = { x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null },
|
18091 | processPath = function(path, d, pcom) {
|
18092 | var nx, ny;
|
18093 |
|
18094 | if (!path) {
|
18095 | return ['C', d.x, d.y, d.x, d.y, d.x, d.y];
|
18096 | }
|
18097 |
|
18098 | !(path[0] in { T: 1, Q: 1 }) && (d.qx = d.qy = null);
|
18099 |
|
18100 | switch (path[0]) {
|
18101 | case 'M':
|
18102 | d.X = path[1];
|
18103 | d.Y = path[2];
|
18104 | break;
|
18105 | case 'A':
|
18106 | path = ['C'].concat(arcToCurve.apply(0, [d.x, d.y].concat(path.slice(1))));
|
18107 | break;
|
18108 | case 'S':
|
18109 | if (pcom == 'C' || pcom == 'S') {
|
18110 |
|
18111 | nx = d.x * 2 - d.bx;
|
18112 |
|
18113 | ny = d.y * 2 - d.by;
|
18114 |
|
18115 | }
|
18116 | else {
|
18117 |
|
18118 | nx = d.x;
|
18119 | ny = d.y;
|
18120 | }
|
18121 | path = ['C', nx, ny].concat(path.slice(1));
|
18122 | break;
|
18123 | case 'T':
|
18124 | if (pcom == 'Q' || pcom == 'T') {
|
18125 |
|
18126 | d.qx = d.x * 2 - d.qx;
|
18127 |
|
18128 | d.qy = d.y * 2 - d.qy;
|
18129 |
|
18130 | }
|
18131 | else {
|
18132 |
|
18133 | d.qx = d.x;
|
18134 | d.qy = d.y;
|
18135 | }
|
18136 | path = ['C'].concat(qubicToCurve(d.x, d.y, d.qx, d.qy, path[1], path[2]));
|
18137 | break;
|
18138 | case 'Q':
|
18139 | d.qx = path[1];
|
18140 | d.qy = path[2];
|
18141 | path = ['C'].concat(qubicToCurve(d.x, d.y, path[1], path[2], path[3], path[4]));
|
18142 | break;
|
18143 | case 'L':
|
18144 | path = ['C'].concat(lineToCurve(d.x, d.y, path[1], path[2]));
|
18145 | break;
|
18146 | case 'H':
|
18147 | path = ['C'].concat(lineToCurve(d.x, d.y, path[1], d.y));
|
18148 | break;
|
18149 | case 'V':
|
18150 | path = ['C'].concat(lineToCurve(d.x, d.y, d.x, path[1]));
|
18151 | break;
|
18152 | case 'Z':
|
18153 | path = ['C'].concat(lineToCurve(d.x, d.y, d.X, d.Y));
|
18154 | break;
|
18155 | }
|
18156 |
|
18157 | return path;
|
18158 | },
|
18159 |
|
18160 | fixArc = function(pp, i) {
|
18161 |
|
18162 | if (pp[i].length > 7) {
|
18163 | pp[i].shift();
|
18164 | var pi = pp[i];
|
18165 |
|
18166 | while (pi.length) {
|
18167 | pcoms1[i] = 'A';
|
18168 | p2 && (pcoms2[i] = 'A');
|
18169 | pp.splice(i++, 0, ['C'].concat(pi.splice(0, 6)));
|
18170 | }
|
18171 |
|
18172 | pp.splice(i, 1);
|
18173 | ii = mmax(p.length, p2 && p2.length || 0);
|
18174 | }
|
18175 | },
|
18176 |
|
18177 | fixM = function(path1, path2, a1, a2, i) {
|
18178 |
|
18179 | if (path1 && path2 && path1[i][0] == 'M' && path2[i][0] != 'M') {
|
18180 | path2.splice(i, 0, ['M', a2.x, a2.y]);
|
18181 | a1.bx = 0;
|
18182 | a1.by = 0;
|
18183 | a1.x = path1[i][1];
|
18184 | a1.y = path1[i][2];
|
18185 | ii = mmax(p.length, p2 && p2.length || 0);
|
18186 | }
|
18187 | },
|
18188 |
|
18189 | pcoms1 = [],
|
18190 | pcoms2 = [],
|
18191 | pfirst = '',
|
18192 | pcom = '';
|
18193 |
|
18194 | for (var i = 0, ii = mmax(p.length, p2 && p2.length || 0); i < ii; i++) {
|
18195 | p[i] && (pfirst = p[i][0]);
|
18196 |
|
18197 | if (pfirst != 'C')
|
18198 | {
|
18199 | pcoms1[i] = pfirst;
|
18200 | i && (pcom = pcoms1[i - 1]);
|
18201 | }
|
18202 | p[i] = processPath(p[i], attrs, pcom);
|
18203 |
|
18204 | if (pcoms1[i] != 'A' && pfirst == 'C') pcoms1[i] = 'C';
|
18205 |
|
18206 |
|
18207 |
|
18208 | fixArc(p, i);
|
18209 |
|
18210 | if (p2) {
|
18211 | p2[i] && (pfirst = p2[i][0]);
|
18212 |
|
18213 | if (pfirst != 'C') {
|
18214 | pcoms2[i] = pfirst;
|
18215 | i && (pcom = pcoms2[i - 1]);
|
18216 | }
|
18217 |
|
18218 | p2[i] = processPath(p2[i], attrs2, pcom);
|
18219 |
|
18220 | if (pcoms2[i] != 'A' && pfirst == 'C') {
|
18221 | pcoms2[i] = 'C';
|
18222 | }
|
18223 |
|
18224 | fixArc(p2, i);
|
18225 | }
|
18226 |
|
18227 | fixM(p, p2, attrs, attrs2, i);
|
18228 | fixM(p2, p, attrs2, attrs, i);
|
18229 |
|
18230 | var seg = p[i],
|
18231 | seg2 = p2 && p2[i],
|
18232 | seglen = seg.length,
|
18233 | seg2len = p2 && seg2.length;
|
18234 |
|
18235 | attrs.x = seg[seglen - 2];
|
18236 | attrs.y = seg[seglen - 1];
|
18237 | attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
|
18238 | attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
|
18239 | attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
|
18240 | attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
|
18241 | attrs2.x = p2 && seg2[seg2len - 2];
|
18242 | attrs2.y = p2 && seg2[seg2len - 1];
|
18243 | }
|
18244 |
|
18245 | if (!p2) {
|
18246 | pth.curve = pathClone(p);
|
18247 | }
|
18248 |
|
18249 | return p2 ? [p, p2] : p;
|
18250 | }
|
18251 |
|
18252 | var intersect = findPathIntersections;
|
18253 |
|
18254 | function roundBounds(bounds) {
|
18255 | return {
|
18256 | x: Math.round(bounds.x),
|
18257 | y: Math.round(bounds.y),
|
18258 | width: Math.round(bounds.width),
|
18259 | height: Math.round(bounds.height)
|
18260 | };
|
18261 | }
|
18262 |
|
18263 |
|
18264 | function roundPoint(point) {
|
18265 |
|
18266 | return {
|
18267 | x: Math.round(point.x),
|
18268 | y: Math.round(point.y)
|
18269 | };
|
18270 | }
|
18271 |
|
18272 |
|
18273 | |
18274 |
|
18275 |
|
18276 |
|
18277 |
|
18278 |
|
18279 |
|
18280 | function asTRBL(bounds) {
|
18281 | return {
|
18282 | top: bounds.y,
|
18283 | right: bounds.x + (bounds.width || 0),
|
18284 | bottom: bounds.y + (bounds.height || 0),
|
18285 | left: bounds.x
|
18286 | };
|
18287 | }
|
18288 |
|
18289 |
|
18290 | |
18291 |
|
18292 |
|
18293 |
|
18294 |
|
18295 |
|
18296 |
|
18297 | function asBounds(trbl) {
|
18298 | return {
|
18299 | x: trbl.left,
|
18300 | y: trbl.top,
|
18301 | width: trbl.right - trbl.left,
|
18302 | height: trbl.bottom - trbl.top
|
18303 | };
|
18304 | }
|
18305 |
|
18306 |
|
18307 | |
18308 |
|
18309 |
|
18310 |
|
18311 |
|
18312 |
|
18313 |
|
18314 | function getMid(bounds) {
|
18315 | return roundPoint({
|
18316 | x: bounds.x + (bounds.width || 0) / 2,
|
18317 | y: bounds.y + (bounds.height || 0) / 2
|
18318 | });
|
18319 | }
|
18320 |
|
18321 |
|
18322 |
|
18323 |
|
18324 | |
18325 |
|
18326 |
|
18327 |
|
18328 |
|
18329 |
|
18330 |
|
18331 |
|
18332 |
|
18333 |
|
18334 |
|
18335 |
|
18336 |
|
18337 | function getOrientation(rect, reference, padding) {
|
18338 |
|
18339 | padding = padding || 0;
|
18340 |
|
18341 |
|
18342 |
|
18343 | if (!isObject(padding)) {
|
18344 | padding = { x: padding, y: padding };
|
18345 | }
|
18346 |
|
18347 |
|
18348 | var rectOrientation = asTRBL(rect),
|
18349 | referenceOrientation = asTRBL(reference);
|
18350 |
|
18351 | var top = rectOrientation.bottom + padding.y <= referenceOrientation.top,
|
18352 | right = rectOrientation.left - padding.x >= referenceOrientation.right,
|
18353 | bottom = rectOrientation.top - padding.y >= referenceOrientation.bottom,
|
18354 | left = rectOrientation.right + padding.x <= referenceOrientation.left;
|
18355 |
|
18356 | var vertical = top ? 'top' : (bottom ? 'bottom' : null),
|
18357 | horizontal = left ? 'left' : (right ? 'right' : null);
|
18358 |
|
18359 | if (horizontal && vertical) {
|
18360 | return vertical + '-' + horizontal;
|
18361 | } else {
|
18362 | return horizontal || vertical || 'intersect';
|
18363 | }
|
18364 | }
|
18365 |
|
18366 |
|
18367 |
|
18368 |
|
18369 | |
18370 |
|
18371 |
|
18372 |
|
18373 |
|
18374 |
|
18375 |
|
18376 |
|
18377 |
|
18378 | function getElementLineIntersection(elementPath, linePath, cropStart) {
|
18379 |
|
18380 | var intersections = getIntersections(elementPath, linePath);
|
18381 |
|
18382 |
|
18383 |
|
18384 |
|
18385 |
|
18386 |
|
18387 | if (intersections.length === 1) {
|
18388 | return roundPoint(intersections[0]);
|
18389 | } else if (intersections.length === 2 && pointDistance(intersections[0], intersections[1]) < 1) {
|
18390 | return roundPoint(intersections[0]);
|
18391 | } else if (intersections.length > 1) {
|
18392 |
|
18393 |
|
18394 |
|
18395 | intersections = sortBy(intersections, function(i) {
|
18396 | var distance = Math.floor(i.t2 * 100) || 1;
|
18397 |
|
18398 | distance = 100 - distance;
|
18399 |
|
18400 | distance = (distance < 10 ? '0' : '') + distance;
|
18401 |
|
18402 |
|
18403 |
|
18404 |
|
18405 | return i.segment2 + '#' + distance;
|
18406 | });
|
18407 |
|
18408 | return roundPoint(intersections[cropStart ? 0 : intersections.length - 1]);
|
18409 | }
|
18410 |
|
18411 | return null;
|
18412 | }
|
18413 |
|
18414 |
|
18415 | function getIntersections(a, b) {
|
18416 | return intersect(a, b);
|
18417 | }
|
18418 |
|
18419 |
|
18420 | function filterRedundantWaypoints(waypoints) {
|
18421 |
|
18422 |
|
18423 | waypoints = waypoints.slice();
|
18424 |
|
18425 | var idx = 0,
|
18426 | point,
|
18427 | previousPoint,
|
18428 | nextPoint;
|
18429 |
|
18430 | while (waypoints[idx]) {
|
18431 | point = waypoints[idx];
|
18432 | previousPoint = waypoints[idx - 1];
|
18433 | nextPoint = waypoints[idx + 1];
|
18434 |
|
18435 | if (pointDistance(point, nextPoint) === 0 ||
|
18436 | pointsOnLine(previousPoint, nextPoint, point)) {
|
18437 |
|
18438 |
|
18439 |
|
18440 | waypoints.splice(idx, 1);
|
18441 | } else {
|
18442 | idx++;
|
18443 | }
|
18444 | }
|
18445 |
|
18446 | return waypoints;
|
18447 | }
|
18448 |
|
18449 | function elementData(semantic, attrs) {
|
18450 | return assign({
|
18451 | id: semantic.id,
|
18452 | type: semantic.$type,
|
18453 | businessObject: semantic
|
18454 | }, attrs);
|
18455 | }
|
18456 |
|
18457 | function getWaypoints(bo, source, target) {
|
18458 |
|
18459 | var waypoints = bo.di.waypoint;
|
18460 |
|
18461 | if (!waypoints || waypoints.length < 2) {
|
18462 | return [ getMid(source), getMid(target) ];
|
18463 | }
|
18464 |
|
18465 | return waypoints.map(function(p) {
|
18466 | return { x: p.x, y: p.y };
|
18467 | });
|
18468 | }
|
18469 |
|
18470 | function notYetDrawn(translate, semantic, refSemantic, property) {
|
18471 | return new Error(translate('element {element} referenced by {referenced}#{property} not yet drawn', {
|
18472 | element: elementToString(refSemantic),
|
18473 | referenced: elementToString(semantic),
|
18474 | property: property
|
18475 | }));
|
18476 | }
|
18477 |
|
18478 |
|
18479 | |
18480 |
|
18481 |
|
18482 |
|
18483 |
|
18484 |
|
18485 |
|
18486 |
|
18487 |
|
18488 |
|
18489 | function BpmnImporter(
|
18490 | eventBus, canvas, elementFactory,
|
18491 | elementRegistry, translate, textRenderer) {
|
18492 |
|
18493 | this._eventBus = eventBus;
|
18494 | this._canvas = canvas;
|
18495 | this._elementFactory = elementFactory;
|
18496 | this._elementRegistry = elementRegistry;
|
18497 | this._translate = translate;
|
18498 | this._textRenderer = textRenderer;
|
18499 | }
|
18500 |
|
18501 | BpmnImporter.$inject = [
|
18502 | 'eventBus',
|
18503 | 'canvas',
|
18504 | 'elementFactory',
|
18505 | 'elementRegistry',
|
18506 | 'translate',
|
18507 | 'textRenderer'
|
18508 | ];
|
18509 |
|
18510 |
|
18511 | |
18512 |
|
18513 |
|
18514 |
|
18515 | BpmnImporter.prototype.add = function(semantic, parentElement) {
|
18516 |
|
18517 | var di = semantic.di,
|
18518 | element,
|
18519 | translate = this._translate,
|
18520 | hidden;
|
18521 |
|
18522 | var parentIndex;
|
18523 |
|
18524 |
|
18525 |
|
18526 |
|
18527 | if (is$1(di, 'bpmndi:BPMNPlane')) {
|
18528 |
|
18529 |
|
18530 | element = this._elementFactory.createRoot(elementData(semantic));
|
18531 |
|
18532 | this._canvas.setRootElement(element);
|
18533 | }
|
18534 |
|
18535 |
|
18536 | else if (is$1(di, 'bpmndi:BPMNShape')) {
|
18537 |
|
18538 | var collapsed = !isExpanded(semantic);
|
18539 | hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
|
18540 |
|
18541 | var bounds = semantic.di.bounds;
|
18542 |
|
18543 | element = this._elementFactory.createShape(elementData(semantic, {
|
18544 | collapsed: collapsed,
|
18545 | hidden: hidden,
|
18546 | x: Math.round(bounds.x),
|
18547 | y: Math.round(bounds.y),
|
18548 | width: Math.round(bounds.width),
|
18549 | height: Math.round(bounds.height)
|
18550 | }));
|
18551 |
|
18552 | if (is$1(semantic, 'bpmn:BoundaryEvent')) {
|
18553 | this._attachBoundary(semantic, element);
|
18554 | }
|
18555 |
|
18556 |
|
18557 | if (is$1(semantic, 'bpmn:Lane')) {
|
18558 | parentIndex = 0;
|
18559 | }
|
18560 |
|
18561 | if (is$1(semantic, 'bpmn:DataStoreReference')) {
|
18562 |
|
18563 |
|
18564 | if (!isPointInsideBBox$1(parentElement, getMid(bounds))) {
|
18565 | parentElement = this._canvas.getRootElement();
|
18566 | }
|
18567 | }
|
18568 |
|
18569 | this._canvas.addShape(element, parentElement, parentIndex);
|
18570 | }
|
18571 |
|
18572 |
|
18573 | else if (is$1(di, 'bpmndi:BPMNEdge')) {
|
18574 |
|
18575 | var source = this._getSource(semantic),
|
18576 | target = this._getTarget(semantic);
|
18577 |
|
18578 | hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
|
18579 |
|
18580 | element = this._elementFactory.createConnection(elementData(semantic, {
|
18581 | hidden: hidden,
|
18582 | source: source,
|
18583 | target: target,
|
18584 | waypoints: getWaypoints(semantic, source, target)
|
18585 | }));
|
18586 |
|
18587 | if (is$1(semantic, 'bpmn:DataAssociation')) {
|
18588 |
|
18589 |
|
18590 |
|
18591 |
|
18592 |
|
18593 | parentElement = null;
|
18594 | }
|
18595 |
|
18596 |
|
18597 | if (is$1(semantic, 'bpmn:SequenceFlow')) {
|
18598 | parentIndex = 0;
|
18599 | }
|
18600 |
|
18601 | this._canvas.addConnection(element, parentElement, parentIndex);
|
18602 | } else {
|
18603 | throw new Error(translate('unknown di {di} for element {semantic}', {
|
18604 | di: elementToString(di),
|
18605 | semantic: elementToString(semantic)
|
18606 | }));
|
18607 | }
|
18608 |
|
18609 |
|
18610 | if (isLabelExternal(semantic) && getLabel(element)) {
|
18611 | this.addLabel(semantic, element);
|
18612 | }
|
18613 |
|
18614 |
|
18615 | this._eventBus.fire('bpmnElement.added', { element: element });
|
18616 |
|
18617 | return element;
|
18618 | };
|
18619 |
|
18620 |
|
18621 | |
18622 |
|
18623 |
|
18624 |
|
18625 |
|
18626 |
|
18627 | BpmnImporter.prototype._attachBoundary = function(boundarySemantic, boundaryElement) {
|
18628 | var translate = this._translate;
|
18629 | var hostSemantic = boundarySemantic.attachedToRef;
|
18630 |
|
18631 | if (!hostSemantic) {
|
18632 | throw new Error(translate('missing {semantic}#attachedToRef', {
|
18633 | semantic: elementToString(boundarySemantic)
|
18634 | }));
|
18635 | }
|
18636 |
|
18637 | var host = this._elementRegistry.get(hostSemantic.id),
|
18638 | attachers = host && host.attachers;
|
18639 |
|
18640 | if (!host) {
|
18641 | throw notYetDrawn(translate, boundarySemantic, hostSemantic, 'attachedToRef');
|
18642 | }
|
18643 |
|
18644 |
|
18645 | boundaryElement.host = host;
|
18646 |
|
18647 | if (!attachers) {
|
18648 | host.attachers = attachers = [];
|
18649 | }
|
18650 |
|
18651 | if (attachers.indexOf(boundaryElement) === -1) {
|
18652 | attachers.push(boundaryElement);
|
18653 | }
|
18654 | };
|
18655 |
|
18656 |
|
18657 | |
18658 |
|
18659 |
|
18660 | BpmnImporter.prototype.addLabel = function(semantic, element) {
|
18661 | var bounds,
|
18662 | text,
|
18663 | label;
|
18664 |
|
18665 | bounds = getExternalLabelBounds(semantic, element);
|
18666 |
|
18667 | text = getLabel(element);
|
18668 |
|
18669 | if (text) {
|
18670 |
|
18671 |
|
18672 | bounds = this._textRenderer.getExternalLabelBounds(bounds, text);
|
18673 | }
|
18674 |
|
18675 | label = this._elementFactory.createLabel(elementData(semantic, {
|
18676 | id: semantic.id + '_label',
|
18677 | labelTarget: element,
|
18678 | type: 'label',
|
18679 | hidden: element.hidden || !getLabel(element),
|
18680 | x: Math.round(bounds.x),
|
18681 | y: Math.round(bounds.y),
|
18682 | width: Math.round(bounds.width),
|
18683 | height: Math.round(bounds.height)
|
18684 | }));
|
18685 |
|
18686 | return this._canvas.addShape(label, element.parent);
|
18687 | };
|
18688 |
|
18689 | |
18690 |
|
18691 |
|
18692 |
|
18693 |
|
18694 | BpmnImporter.prototype._getEnd = function(semantic, side) {
|
18695 |
|
18696 | var element,
|
18697 | refSemantic,
|
18698 | type = semantic.$type,
|
18699 | translate = this._translate;
|
18700 |
|
18701 | refSemantic = semantic[side + 'Ref'];
|
18702 |
|
18703 |
|
18704 | if (side === 'source' && type === 'bpmn:DataInputAssociation') {
|
18705 | refSemantic = refSemantic && refSemantic[0];
|
18706 | }
|
18707 |
|
18708 |
|
18709 | if (side === 'source' && type === 'bpmn:DataOutputAssociation' ||
|
18710 | side === 'target' && type === 'bpmn:DataInputAssociation') {
|
18711 |
|
18712 | refSemantic = semantic.$parent;
|
18713 | }
|
18714 |
|
18715 | element = refSemantic && this._getElement(refSemantic);
|
18716 |
|
18717 | if (element) {
|
18718 | return element;
|
18719 | }
|
18720 |
|
18721 | if (refSemantic) {
|
18722 | throw notYetDrawn(translate, semantic, refSemantic, side + 'Ref');
|
18723 | } else {
|
18724 | throw new Error(translate('{semantic}#{side} Ref not specified', {
|
18725 | semantic: elementToString(semantic),
|
18726 | side: side
|
18727 | }));
|
18728 | }
|
18729 | };
|
18730 |
|
18731 | BpmnImporter.prototype._getSource = function(semantic) {
|
18732 | return this._getEnd(semantic, 'source');
|
18733 | };
|
18734 |
|
18735 | BpmnImporter.prototype._getTarget = function(semantic) {
|
18736 | return this._getEnd(semantic, 'target');
|
18737 | };
|
18738 |
|
18739 |
|
18740 | BpmnImporter.prototype._getElement = function(semantic) {
|
18741 | return this._elementRegistry.get(semantic.id);
|
18742 | };
|
18743 |
|
18744 |
|
18745 |
|
18746 |
|
18747 | function isPointInsideBBox$1(bbox, point) {
|
18748 | var x = point.x,
|
18749 | y = point.y;
|
18750 |
|
18751 | return x >= bbox.x &&
|
18752 | x <= bbox.x + bbox.width &&
|
18753 | y >= bbox.y &&
|
18754 | y <= bbox.y + bbox.height;
|
18755 | }
|
18756 |
|
18757 | var ImportModule = {
|
18758 | __depends__: [
|
18759 | translate$2
|
18760 | ],
|
18761 | bpmnImporter: [ 'type', BpmnImporter ]
|
18762 | };
|
18763 |
|
18764 | var CoreModule$1 = {
|
18765 | __depends__: [
|
18766 | DrawModule$1,
|
18767 | ImportModule
|
18768 | ]
|
18769 | };
|
18770 |
|
18771 | function __stopPropagation(event) {
|
18772 | if (!event || typeof event.stopPropagation !== 'function') {
|
18773 | return;
|
18774 | }
|
18775 |
|
18776 | event.stopPropagation();
|
18777 | }
|
18778 |
|
18779 |
|
18780 | function getOriginal(event) {
|
18781 | return event.originalEvent || event.srcEvent;
|
18782 | }
|
18783 |
|
18784 |
|
18785 | function stopPropagation(event, immediate) {
|
18786 | __stopPropagation(event);
|
18787 | __stopPropagation(getOriginal(event));
|
18788 | }
|
18789 |
|
18790 |
|
18791 | function toPoint(event) {
|
18792 |
|
18793 | if (event.pointers && event.pointers.length) {
|
18794 | event = event.pointers[0];
|
18795 | }
|
18796 |
|
18797 | if (event.touches && event.touches.length) {
|
18798 | event = event.touches[0];
|
18799 | }
|
18800 |
|
18801 | return event ? {
|
18802 | x: event.clientX,
|
18803 | y: event.clientY
|
18804 | } : null;
|
18805 | }
|
18806 |
|
18807 | function isMac() {
|
18808 | return (/mac/i).test(navigator.platform);
|
18809 | }
|
18810 |
|
18811 | function isPrimaryButton(event) {
|
18812 |
|
18813 |
|
18814 | return !(getOriginal(event) || event).button;
|
18815 | }
|
18816 |
|
18817 | function hasPrimaryModifier(event) {
|
18818 | var originalEvent = getOriginal(event) || event;
|
18819 |
|
18820 | if (!isPrimaryButton(event)) {
|
18821 | return false;
|
18822 | }
|
18823 |
|
18824 |
|
18825 | if (isMac()) {
|
18826 | return originalEvent.metaKey;
|
18827 | } else {
|
18828 | return originalEvent.ctrlKey;
|
18829 | }
|
18830 | }
|
18831 |
|
18832 |
|
18833 | function hasSecondaryModifier(event) {
|
18834 | var originalEvent = getOriginal(event) || event;
|
18835 |
|
18836 | return isPrimaryButton(event) && originalEvent.shiftKey;
|
18837 | }
|
18838 |
|
18839 | function allowAll(e) { return true; }
|
18840 |
|
18841 | var LOW_PRIORITY = 500;
|
18842 |
|
18843 |
|
18844 | |
18845 |
|
18846 |
|
18847 |
|
18848 |
|
18849 |
|
18850 |
|
18851 |
|
18852 |
|
18853 |
|
18854 |
|
18855 |
|
18856 |
|
18857 |
|
18858 |
|
18859 |
|
18860 |
|
18861 |
|
18862 |
|
18863 |
|
18864 |
|
18865 | function InteractionEvents(eventBus, elementRegistry, styles) {
|
18866 |
|
18867 | var self = this;
|
18868 |
|
18869 | |
18870 |
|
18871 |
|
18872 |
|
18873 |
|
18874 |
|
18875 |
|
18876 |
|
18877 | function fire(type, event, element) {
|
18878 |
|
18879 | if (isIgnored(type, event)) {
|
18880 | return;
|
18881 | }
|
18882 |
|
18883 | var target, gfx, returnValue;
|
18884 |
|
18885 | if (!element) {
|
18886 | target = event.delegateTarget || event.target;
|
18887 |
|
18888 | if (target) {
|
18889 | gfx = target;
|
18890 | element = elementRegistry.get(gfx);
|
18891 | }
|
18892 | } else {
|
18893 | gfx = elementRegistry.getGraphics(element);
|
18894 | }
|
18895 |
|
18896 | if (!gfx || !element) {
|
18897 | return;
|
18898 | }
|
18899 |
|
18900 | returnValue = eventBus.fire(type, {
|
18901 | element: element,
|
18902 | gfx: gfx,
|
18903 | originalEvent: event
|
18904 | });
|
18905 |
|
18906 | if (returnValue === false) {
|
18907 | event.stopPropagation();
|
18908 | event.preventDefault();
|
18909 | }
|
18910 | }
|
18911 |
|
18912 |
|
18913 | var handlers = {};
|
18914 |
|
18915 | function mouseHandler(localEventName) {
|
18916 | return handlers[localEventName];
|
18917 | }
|
18918 |
|
18919 | function isIgnored(localEventName, event) {
|
18920 |
|
18921 | var filter = ignoredFilters[localEventName] || isPrimaryButton;
|
18922 |
|
18923 |
|
18924 |
|
18925 |
|
18926 | return !filter(event);
|
18927 | }
|
18928 |
|
18929 | var bindings = {
|
18930 | click: 'element.click',
|
18931 | contextmenu: 'element.contextmenu',
|
18932 | dblclick: 'element.dblclick',
|
18933 | mousedown: 'element.mousedown',
|
18934 | mousemove: 'element.mousemove',
|
18935 | mouseover: 'element.hover',
|
18936 | mouseout: 'element.out',
|
18937 | mouseup: 'element.mouseup',
|
18938 | };
|
18939 |
|
18940 | var ignoredFilters = {
|
18941 | 'element.contextmenu': allowAll
|
18942 | };
|
18943 |
|
18944 |
|
18945 |
|
18946 |
|
18947 | |
18948 |
|
18949 |
|
18950 |
|
18951 |
|
18952 |
|
18953 |
|
18954 |
|
18955 | function triggerMouseEvent(eventName, event, targetElement) {
|
18956 |
|
18957 |
|
18958 | var localEventName = bindings[eventName];
|
18959 |
|
18960 | if (!localEventName) {
|
18961 | throw new Error('unmapped DOM event name <' + eventName + '>');
|
18962 | }
|
18963 |
|
18964 | return fire(localEventName, event, targetElement);
|
18965 | }
|
18966 |
|
18967 |
|
18968 | var ELEMENT_SELECTOR = 'svg, .djs-element';
|
18969 |
|
18970 |
|
18971 |
|
18972 | function registerEvent(node, event, localEvent, ignoredFilter) {
|
18973 |
|
18974 | var handler = handlers[localEvent] = function(event) {
|
18975 | fire(localEvent, event);
|
18976 | };
|
18977 |
|
18978 | if (ignoredFilter) {
|
18979 | ignoredFilters[localEvent] = ignoredFilter;
|
18980 | }
|
18981 |
|
18982 | handler.$delegate = delegateEvents.bind(node, ELEMENT_SELECTOR, event, handler);
|
18983 | }
|
18984 |
|
18985 | function unregisterEvent(node, event, localEvent) {
|
18986 |
|
18987 | var handler = mouseHandler(localEvent);
|
18988 |
|
18989 | if (!handler) {
|
18990 | return;
|
18991 | }
|
18992 |
|
18993 | delegateEvents.unbind(node, event, handler.$delegate);
|
18994 | }
|
18995 |
|
18996 | function registerEvents(svg) {
|
18997 | forEach(bindings, function(val, key) {
|
18998 | registerEvent(svg, key, val);
|
18999 | });
|
19000 | }
|
19001 |
|
19002 | function unregisterEvents(svg) {
|
19003 | forEach(bindings, function(val, key) {
|
19004 | unregisterEvent(svg, key, val);
|
19005 | });
|
19006 | }
|
19007 |
|
19008 | eventBus.on('canvas.destroy', function(event) {
|
19009 | unregisterEvents(event.svg);
|
19010 | });
|
19011 |
|
19012 | eventBus.on('canvas.init', function(event) {
|
19013 | registerEvents(event.svg);
|
19014 | });
|
19015 |
|
19016 |
|
19017 |
|
19018 |
|
19019 | eventBus.on([ 'shape.added', 'connection.added' ], function(event) {
|
19020 | var element = event.element,
|
19021 | gfx = event.gfx;
|
19022 |
|
19023 | eventBus.fire('interactionEvents.createHit', { element: element, gfx: gfx });
|
19024 | });
|
19025 |
|
19026 |
|
19027 |
|
19028 |
|
19029 | eventBus.on([
|
19030 | 'shape.changed',
|
19031 | 'connection.changed'
|
19032 | ], LOW_PRIORITY, function(event) {
|
19033 |
|
19034 | var element = event.element,
|
19035 | gfx = event.gfx;
|
19036 |
|
19037 | eventBus.fire('interactionEvents.updateHit', { element: element, gfx: gfx });
|
19038 | });
|
19039 |
|
19040 | eventBus.on('interactionEvents.createHit', LOW_PRIORITY, function(event) {
|
19041 | var element = event.element,
|
19042 | gfx = event.gfx;
|
19043 |
|
19044 | self.createDefaultHit(element, gfx);
|
19045 | });
|
19046 |
|
19047 | eventBus.on('interactionEvents.updateHit', function(event) {
|
19048 | var element = event.element,
|
19049 | gfx = event.gfx;
|
19050 |
|
19051 | self.updateDefaultHit(element, gfx);
|
19052 | });
|
19053 |
|
19054 |
|
19055 |
|
19056 |
|
19057 | var STROKE_HIT_STYLE = createHitStyle('djs-hit djs-hit-stroke');
|
19058 |
|
19059 | var CLICK_STROKE_HIT_STYLE = createHitStyle('djs-hit djs-hit-click-stroke');
|
19060 |
|
19061 | var ALL_HIT_STYLE = createHitStyle('djs-hit djs-hit-all');
|
19062 |
|
19063 | var HIT_TYPES = {
|
19064 | 'all': ALL_HIT_STYLE,
|
19065 | 'click-stroke': CLICK_STROKE_HIT_STYLE,
|
19066 | 'stroke': STROKE_HIT_STYLE
|
19067 | };
|
19068 |
|
19069 | function createHitStyle(classNames, attrs) {
|
19070 |
|
19071 | attrs = assign({
|
19072 | stroke: 'white',
|
19073 | strokeWidth: 15
|
19074 | }, attrs || {});
|
19075 |
|
19076 | return styles.cls(classNames, [ 'no-fill', 'no-border' ], attrs);
|
19077 | }
|
19078 |
|
19079 |
|
19080 |
|
19081 |
|
19082 | function applyStyle(hit, type) {
|
19083 |
|
19084 | var attrs = HIT_TYPES[type];
|
19085 |
|
19086 | if (!attrs) {
|
19087 | throw new Error('invalid hit type <' + type + '>');
|
19088 | }
|
19089 |
|
19090 | attr$1(hit, attrs);
|
19091 |
|
19092 | return hit;
|
19093 | }
|
19094 |
|
19095 | function appendHit(gfx, hit) {
|
19096 | append(gfx, hit);
|
19097 | }
|
19098 |
|
19099 |
|
19100 |
|
19101 |
|
19102 | |
19103 |
|
19104 |
|
19105 |
|
19106 |
|
19107 | this.removeHits = function(gfx) {
|
19108 | var hits = all('.djs-hit', gfx);
|
19109 |
|
19110 | forEach(hits, remove$1);
|
19111 | };
|
19112 |
|
19113 | |
19114 |
|
19115 |
|
19116 |
|
19117 |
|
19118 |
|
19119 |
|
19120 |
|
19121 | this.createDefaultHit = function(element, gfx) {
|
19122 | var waypoints = element.waypoints,
|
19123 | isFrame = element.isFrame,
|
19124 | boxType;
|
19125 |
|
19126 | if (waypoints) {
|
19127 | return this.createWaypointsHit(gfx, waypoints);
|
19128 | } else {
|
19129 |
|
19130 | boxType = isFrame ? 'stroke' : 'all';
|
19131 |
|
19132 | return this.createBoxHit(gfx, boxType, {
|
19133 | width: element.width,
|
19134 | height: element.height
|
19135 | });
|
19136 | }
|
19137 | };
|
19138 |
|
19139 | |
19140 |
|
19141 |
|
19142 |
|
19143 |
|
19144 |
|
19145 |
|
19146 |
|
19147 | this.createWaypointsHit = function(gfx, waypoints) {
|
19148 |
|
19149 | var hit = createLine(waypoints);
|
19150 |
|
19151 | applyStyle(hit, 'stroke');
|
19152 |
|
19153 | appendHit(gfx, hit);
|
19154 |
|
19155 | return hit;
|
19156 | };
|
19157 |
|
19158 | |
19159 |
|
19160 |
|
19161 |
|
19162 |
|
19163 |
|
19164 |
|
19165 |
|
19166 |
|
19167 | this.createBoxHit = function(gfx, type, attrs) {
|
19168 |
|
19169 | attrs = assign({
|
19170 | x: 0,
|
19171 | y: 0
|
19172 | }, attrs);
|
19173 |
|
19174 | var hit = create('rect');
|
19175 |
|
19176 | applyStyle(hit, type);
|
19177 |
|
19178 | attr$1(hit, attrs);
|
19179 |
|
19180 | appendHit(gfx, hit);
|
19181 |
|
19182 | return hit;
|
19183 | };
|
19184 |
|
19185 | |
19186 |
|
19187 |
|
19188 |
|
19189 |
|
19190 |
|
19191 |
|
19192 |
|
19193 | this.updateDefaultHit = function(element, gfx) {
|
19194 |
|
19195 | var hit = query('.djs-hit', gfx);
|
19196 |
|
19197 | if (!hit) {
|
19198 | return;
|
19199 | }
|
19200 |
|
19201 | if (element.waypoints) {
|
19202 | updateLine(hit, element.waypoints);
|
19203 | } else {
|
19204 | attr$1(hit, {
|
19205 | width: element.width,
|
19206 | height: element.height
|
19207 | });
|
19208 | }
|
19209 |
|
19210 | return hit;
|
19211 | };
|
19212 |
|
19213 | this.fire = fire;
|
19214 |
|
19215 | this.triggerMouseEvent = triggerMouseEvent;
|
19216 |
|
19217 | this.mouseHandler = mouseHandler;
|
19218 |
|
19219 | this.registerEvent = registerEvent;
|
19220 | this.unregisterEvent = unregisterEvent;
|
19221 | }
|
19222 |
|
19223 |
|
19224 | InteractionEvents.$inject = [
|
19225 | 'eventBus',
|
19226 | 'elementRegistry',
|
19227 | 'styles'
|
19228 | ];
|
19229 |
|
19230 |
|
19231 | |
19232 |
|
19233 |
|
19234 |
|
19235 |
|
19236 |
|
19237 |
|
19238 |
|
19239 |
|
19240 |
|
19241 |
|
19242 | |
19243 |
|
19244 |
|
19245 |
|
19246 |
|
19247 |
|
19248 |
|
19249 |
|
19250 |
|
19251 |
|
19252 |
|
19253 | |
19254 |
|
19255 |
|
19256 |
|
19257 |
|
19258 |
|
19259 |
|
19260 |
|
19261 |
|
19262 |
|
19263 |
|
19264 | |
19265 |
|
19266 |
|
19267 |
|
19268 |
|
19269 |
|
19270 |
|
19271 |
|
19272 |
|
19273 |
|
19274 |
|
19275 | |
19276 |
|
19277 |
|
19278 |
|
19279 |
|
19280 |
|
19281 |
|
19282 |
|
19283 |
|
19284 |
|
19285 |
|
19286 | |
19287 |
|
19288 |
|
19289 |
|
19290 |
|
19291 |
|
19292 |
|
19293 |
|
19294 |
|
19295 |
|
19296 |
|
19297 | |
19298 |
|
19299 |
|
19300 |
|
19301 |
|
19302 |
|
19303 |
|
19304 |
|
19305 |
|
19306 |
|
19307 |
|
19308 |
|
19309 | var InteractionEventsModule = {
|
19310 | __init__: [ 'interactionEvents' ],
|
19311 | interactionEvents: [ 'type', InteractionEvents ]
|
19312 | };
|
19313 |
|
19314 | var LOW_PRIORITY$1 = 500;
|
19315 |
|
19316 |
|
19317 | |
19318 |
|
19319 |
|
19320 |
|
19321 |
|
19322 |
|
19323 |
|
19324 |
|
19325 |
|
19326 |
|
19327 | function Outline(eventBus, styles, elementRegistry) {
|
19328 |
|
19329 | this.offset = 6;
|
19330 |
|
19331 | var OUTLINE_STYLE = styles.cls('djs-outline', [ 'no-fill' ]);
|
19332 |
|
19333 | var self = this;
|
19334 |
|
19335 | function createOutline(gfx, bounds) {
|
19336 | var outline = create('rect');
|
19337 |
|
19338 | attr$1(outline, assign({
|
19339 | x: 10,
|
19340 | y: 10,
|
19341 | width: 100,
|
19342 | height: 100
|
19343 | }, OUTLINE_STYLE));
|
19344 |
|
19345 | append(gfx, outline);
|
19346 |
|
19347 | return outline;
|
19348 | }
|
19349 |
|
19350 |
|
19351 |
|
19352 | eventBus.on([ 'shape.added', 'shape.changed' ], LOW_PRIORITY$1, function(event) {
|
19353 | var element = event.element,
|
19354 | gfx = event.gfx;
|
19355 |
|
19356 | var outline = query('.djs-outline', gfx);
|
19357 |
|
19358 | if (!outline) {
|
19359 | outline = createOutline(gfx);
|
19360 | }
|
19361 |
|
19362 | self.updateShapeOutline(outline, element);
|
19363 | });
|
19364 |
|
19365 | eventBus.on([ 'connection.added', 'connection.changed' ], function(event) {
|
19366 | var element = event.element,
|
19367 | gfx = event.gfx;
|
19368 |
|
19369 | var outline = query('.djs-outline', gfx);
|
19370 |
|
19371 | if (!outline) {
|
19372 | outline = createOutline(gfx);
|
19373 | }
|
19374 |
|
19375 | self.updateConnectionOutline(outline, element);
|
19376 | });
|
19377 | }
|
19378 |
|
19379 |
|
19380 | |
19381 |
|
19382 |
|
19383 |
|
19384 |
|
19385 |
|
19386 |
|
19387 | Outline.prototype.updateShapeOutline = function(outline, element) {
|
19388 |
|
19389 | attr$1(outline, {
|
19390 | x: -this.offset,
|
19391 | y: -this.offset,
|
19392 | width: element.width + this.offset * 2,
|
19393 | height: element.height + this.offset * 2
|
19394 | });
|
19395 |
|
19396 | };
|
19397 |
|
19398 |
|
19399 | |
19400 |
|
19401 |
|
19402 |
|
19403 |
|
19404 |
|
19405 |
|
19406 | Outline.prototype.updateConnectionOutline = function(outline, connection) {
|
19407 |
|
19408 | var bbox = getBBox(connection);
|
19409 |
|
19410 | attr$1(outline, {
|
19411 | x: bbox.x - this.offset,
|
19412 | y: bbox.y - this.offset,
|
19413 | width: bbox.width + this.offset * 2,
|
19414 | height: bbox.height + this.offset * 2
|
19415 | });
|
19416 |
|
19417 | };
|
19418 |
|
19419 |
|
19420 | Outline.$inject = ['eventBus', 'styles', 'elementRegistry'];
|
19421 |
|
19422 | var OutlineModule = {
|
19423 | __init__: [ 'outline' ],
|
19424 | outline: [ 'type', Outline ]
|
19425 | };
|
19426 |
|
19427 | |
19428 |
|
19429 |
|
19430 |
|
19431 |
|
19432 |
|
19433 |
|
19434 |
|
19435 | function Selection(eventBus) {
|
19436 |
|
19437 | this._eventBus = eventBus;
|
19438 |
|
19439 | this._selectedElements = [];
|
19440 |
|
19441 | var self = this;
|
19442 |
|
19443 | eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
|
19444 | var element = e.element;
|
19445 | self.deselect(element);
|
19446 | });
|
19447 |
|
19448 | eventBus.on([ 'diagram.clear' ], function(e) {
|
19449 | self.select(null);
|
19450 | });
|
19451 | }
|
19452 |
|
19453 | Selection.$inject = [ 'eventBus' ];
|
19454 |
|
19455 |
|
19456 | Selection.prototype.deselect = function(element) {
|
19457 | var selectedElements = this._selectedElements;
|
19458 |
|
19459 | var idx = selectedElements.indexOf(element);
|
19460 |
|
19461 | if (idx !== -1) {
|
19462 | var oldSelection = selectedElements.slice();
|
19463 |
|
19464 | selectedElements.splice(idx, 1);
|
19465 |
|
19466 | this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
|
19467 | }
|
19468 | };
|
19469 |
|
19470 |
|
19471 | Selection.prototype.get = function() {
|
19472 | return this._selectedElements;
|
19473 | };
|
19474 |
|
19475 | Selection.prototype.isSelected = function(element) {
|
19476 | return this._selectedElements.indexOf(element) !== -1;
|
19477 | };
|
19478 |
|
19479 |
|
19480 | |
19481 |
|
19482 |
|
19483 |
|
19484 |
|
19485 |
|
19486 |
|
19487 |
|
19488 |
|
19489 |
|
19490 |
|
19491 | Selection.prototype.select = function(elements, add) {
|
19492 | var selectedElements = this._selectedElements,
|
19493 | oldSelection = selectedElements.slice();
|
19494 |
|
19495 | if (!isArray(elements)) {
|
19496 | elements = elements ? [ elements ] : [];
|
19497 | }
|
19498 |
|
19499 |
|
19500 |
|
19501 | if (add) {
|
19502 | forEach(elements, function(element) {
|
19503 | if (selectedElements.indexOf(element) !== -1) {
|
19504 |
|
19505 |
|
19506 | return;
|
19507 | } else {
|
19508 | selectedElements.push(element);
|
19509 | }
|
19510 | });
|
19511 | } else {
|
19512 | this._selectedElements = selectedElements = elements.slice();
|
19513 | }
|
19514 |
|
19515 | this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
|
19516 | };
|
19517 |
|
19518 | var MARKER_HOVER = 'hover',
|
19519 | MARKER_SELECTED = 'selected';
|
19520 |
|
19521 |
|
19522 | |
19523 |
|
19524 |
|
19525 |
|
19526 |
|
19527 |
|
19528 |
|
19529 |
|
19530 |
|
19531 |
|
19532 |
|
19533 |
|
19534 | function SelectionVisuals(events, canvas, selection, styles) {
|
19535 |
|
19536 | this._multiSelectionBox = null;
|
19537 |
|
19538 | function addMarker(e, cls) {
|
19539 | canvas.addMarker(e, cls);
|
19540 | }
|
19541 |
|
19542 | function removeMarker(e, cls) {
|
19543 | canvas.removeMarker(e, cls);
|
19544 | }
|
19545 |
|
19546 | events.on('element.hover', function(event) {
|
19547 | addMarker(event.element, MARKER_HOVER);
|
19548 | });
|
19549 |
|
19550 | events.on('element.out', function(event) {
|
19551 | removeMarker(event.element, MARKER_HOVER);
|
19552 | });
|
19553 |
|
19554 | events.on('selection.changed', function(event) {
|
19555 |
|
19556 | function deselect(s) {
|
19557 | removeMarker(s, MARKER_SELECTED);
|
19558 | }
|
19559 |
|
19560 | function select(s) {
|
19561 | addMarker(s, MARKER_SELECTED);
|
19562 | }
|
19563 |
|
19564 | var oldSelection = event.oldSelection,
|
19565 | newSelection = event.newSelection;
|
19566 |
|
19567 | forEach(oldSelection, function(e) {
|
19568 | if (newSelection.indexOf(e) === -1) {
|
19569 | deselect(e);
|
19570 | }
|
19571 | });
|
19572 |
|
19573 | forEach(newSelection, function(e) {
|
19574 | if (oldSelection.indexOf(e) === -1) {
|
19575 | select(e);
|
19576 | }
|
19577 | });
|
19578 | });
|
19579 | }
|
19580 |
|
19581 | SelectionVisuals.$inject = [
|
19582 | 'eventBus',
|
19583 | 'canvas',
|
19584 | 'selection',
|
19585 | 'styles'
|
19586 | ];
|
19587 |
|
19588 | function SelectionBehavior(
|
19589 | eventBus, selection, canvas,
|
19590 | elementRegistry) {
|
19591 |
|
19592 | eventBus.on('create.end', 500, function(e) {
|
19593 |
|
19594 | var context = e.context,
|
19595 | canExecute = context.canExecute,
|
19596 | elements = context.elements,
|
19597 | hints = context.hints || {},
|
19598 | autoSelect = hints.autoSelect;
|
19599 |
|
19600 |
|
19601 | if (canExecute) {
|
19602 | if (autoSelect === false) {
|
19603 |
|
19604 |
|
19605 | return;
|
19606 | }
|
19607 |
|
19608 | if (isArray(autoSelect)) {
|
19609 | selection.select(autoSelect);
|
19610 | } else {
|
19611 |
|
19612 |
|
19613 | selection.select(elements);
|
19614 | }
|
19615 | }
|
19616 | });
|
19617 |
|
19618 | eventBus.on('connect.end', 500, function(e) {
|
19619 |
|
19620 |
|
19621 |
|
19622 | if (e.context.canExecute && e.context.target) {
|
19623 | selection.select(e.context.target);
|
19624 | }
|
19625 | });
|
19626 |
|
19627 | eventBus.on('shape.move.end', 500, function(e) {
|
19628 | var previousSelection = e.previousSelection || [];
|
19629 |
|
19630 | var shape = elementRegistry.get(e.context.shape.id);
|
19631 |
|
19632 |
|
19633 |
|
19634 | var inSelection = find(previousSelection, function(selectedShape) {
|
19635 | return shape.id === selectedShape.id;
|
19636 | });
|
19637 |
|
19638 | if (!inSelection) {
|
19639 | selection.select(shape);
|
19640 | }
|
19641 | });
|
19642 |
|
19643 |
|
19644 | eventBus.on('element.click', function(event) {
|
19645 |
|
19646 | var element = event.element;
|
19647 |
|
19648 |
|
19649 |
|
19650 | if (element === canvas.getRootElement()) {
|
19651 | element = null;
|
19652 | }
|
19653 |
|
19654 | var isSelected = selection.isSelected(element),
|
19655 | isMultiSelect = selection.get().length > 1;
|
19656 |
|
19657 |
|
19658 | var add = hasPrimaryModifier(event);
|
19659 |
|
19660 |
|
19661 | if (isSelected && isMultiSelect) {
|
19662 | if (add) {
|
19663 | return selection.deselect(element);
|
19664 | } else {
|
19665 | return selection.select(element);
|
19666 | }
|
19667 | } else
|
19668 | if (!isSelected) {
|
19669 | selection.select(element, add);
|
19670 | } else {
|
19671 | selection.deselect(element);
|
19672 | }
|
19673 | });
|
19674 | }
|
19675 |
|
19676 | SelectionBehavior.$inject = [
|
19677 | 'eventBus',
|
19678 | 'selection',
|
19679 | 'canvas',
|
19680 | 'elementRegistry'
|
19681 | ];
|
19682 |
|
19683 | var SelectionModule = {
|
19684 | __init__: [ 'selectionVisuals', 'selectionBehavior' ],
|
19685 | __depends__: [
|
19686 | InteractionEventsModule,
|
19687 | OutlineModule
|
19688 | ],
|
19689 | selection: [ 'type', Selection ],
|
19690 | selectionVisuals: [ 'type', SelectionVisuals ],
|
19691 | selectionBehavior: [ 'type', SelectionBehavior ]
|
19692 | };
|
19693 |
|
19694 | |
19695 |
|
19696 |
|
19697 |
|
19698 |
|
19699 |
|
19700 |
|
19701 |
|
19702 |
|
19703 |
|
19704 |
|
19705 | function IdGenerator(prefix) {
|
19706 |
|
19707 | this._counter = 0;
|
19708 | this._prefix = (prefix ? prefix + '-' : '') + Math.floor(Math.random() * 1000000000) + '-';
|
19709 | }
|
19710 |
|
19711 | |
19712 |
|
19713 |
|
19714 |
|
19715 |
|
19716 |
|
19717 |
|
19718 | IdGenerator.prototype.next = function() {
|
19719 | return this._prefix + (++this._counter);
|
19720 | };
|
19721 |
|
19722 |
|
19723 | var ids = new IdGenerator('ov');
|
19724 |
|
19725 | var LOW_PRIORITY$2 = 500;
|
19726 |
|
19727 |
|
19728 | |
19729 |
|
19730 |
|
19731 |
|
19732 |
|
19733 |
|
19734 |
|
19735 |
|
19736 |
|
19737 |
|
19738 |
|
19739 |
|
19740 |
|
19741 |
|
19742 |
|
19743 |
|
19744 |
|
19745 |
|
19746 |
|
19747 |
|
19748 |
|
19749 |
|
19750 |
|
19751 |
|
19752 |
|
19753 |
|
19754 |
|
19755 |
|
19756 |
|
19757 |
|
19758 |
|
19759 |
|
19760 |
|
19761 |
|
19762 |
|
19763 |
|
19764 |
|
19765 |
|
19766 |
|
19767 |
|
19768 |
|
19769 |
|
19770 |
|
19771 |
|
19772 |
|
19773 |
|
19774 |
|
19775 |
|
19776 |
|
19777 |
|
19778 |
|
19779 |
|
19780 |
|
19781 |
|
19782 |
|
19783 |
|
19784 |
|
19785 |
|
19786 |
|
19787 |
|
19788 |
|
19789 |
|
19790 |
|
19791 |
|
19792 | function Overlays(config, eventBus, canvas, elementRegistry) {
|
19793 |
|
19794 | this._eventBus = eventBus;
|
19795 | this._canvas = canvas;
|
19796 | this._elementRegistry = elementRegistry;
|
19797 |
|
19798 | this._ids = ids;
|
19799 |
|
19800 | this._overlayDefaults = assign({
|
19801 |
|
19802 |
|
19803 | show: null,
|
19804 |
|
19805 |
|
19806 | scale: true
|
19807 | }, config && config.defaults);
|
19808 |
|
19809 | |
19810 |
|
19811 |
|
19812 | this._overlays = {};
|
19813 |
|
19814 | |
19815 |
|
19816 |
|
19817 | this._overlayContainers = [];
|
19818 |
|
19819 |
|
19820 | this._overlayRoot = createRoot(canvas.getContainer());
|
19821 |
|
19822 | this._init();
|
19823 | }
|
19824 |
|
19825 |
|
19826 | Overlays.$inject = [
|
19827 | 'config.overlays',
|
19828 | 'eventBus',
|
19829 | 'canvas',
|
19830 | 'elementRegistry'
|
19831 | ];
|
19832 |
|
19833 |
|
19834 | |
19835 |
|
19836 |
|
19837 |
|
19838 |
|
19839 |
|
19840 |
|
19841 |
|
19842 |
|
19843 |
|
19844 |
|
19845 |
|
19846 |
|
19847 |
|
19848 |
|
19849 |
|
19850 |
|
19851 |
|
19852 |
|
19853 |
|
19854 |
|
19855 |
|
19856 |
|
19857 |
|
19858 |
|
19859 |
|
19860 | Overlays.prototype.get = function(search) {
|
19861 |
|
19862 | if (isString(search)) {
|
19863 | search = { id: search };
|
19864 | }
|
19865 |
|
19866 | if (isString(search.element)) {
|
19867 | search.element = this._elementRegistry.get(search.element);
|
19868 | }
|
19869 |
|
19870 | if (search.element) {
|
19871 | var container = this._getOverlayContainer(search.element, true);
|
19872 |
|
19873 |
|
19874 | if (container) {
|
19875 | return search.type ? filter(container.overlays, matchPattern({ type: search.type })) : container.overlays.slice();
|
19876 | } else {
|
19877 | return [];
|
19878 | }
|
19879 | } else
|
19880 | if (search.type) {
|
19881 | return filter(this._overlays, matchPattern({ type: search.type }));
|
19882 | } else {
|
19883 |
|
19884 |
|
19885 | return search.id ? this._overlays[search.id] : null;
|
19886 | }
|
19887 | };
|
19888 |
|
19889 | |
19890 |
|
19891 |
|
19892 |
|
19893 |
|
19894 |
|
19895 |
|
19896 |
|
19897 |
|
19898 |
|
19899 |
|
19900 |
|
19901 |
|
19902 |
|
19903 |
|
19904 |
|
19905 |
|
19906 |
|
19907 |
|
19908 |
|
19909 |
|
19910 |
|
19911 |
|
19912 | Overlays.prototype.add = function(element, type, overlay) {
|
19913 |
|
19914 | if (isObject(type)) {
|
19915 | overlay = type;
|
19916 | type = null;
|
19917 | }
|
19918 |
|
19919 | if (!element.id) {
|
19920 | element = this._elementRegistry.get(element);
|
19921 | }
|
19922 |
|
19923 | if (!overlay.position) {
|
19924 | throw new Error('must specifiy overlay position');
|
19925 | }
|
19926 |
|
19927 | if (!overlay.html) {
|
19928 | throw new Error('must specifiy overlay html');
|
19929 | }
|
19930 |
|
19931 | if (!element) {
|
19932 | throw new Error('invalid element specified');
|
19933 | }
|
19934 |
|
19935 | var id = this._ids.next();
|
19936 |
|
19937 | overlay = assign({}, this._overlayDefaults, overlay, {
|
19938 | id: id,
|
19939 | type: type,
|
19940 | element: element,
|
19941 | html: overlay.html
|
19942 | });
|
19943 |
|
19944 | this._addOverlay(overlay);
|
19945 |
|
19946 | return id;
|
19947 | };
|
19948 |
|
19949 |
|
19950 | |
19951 |
|
19952 |
|
19953 |
|
19954 |
|
19955 |
|
19956 |
|
19957 |
|
19958 | Overlays.prototype.remove = function(filter) {
|
19959 |
|
19960 | var overlays = this.get(filter) || [];
|
19961 |
|
19962 | if (!isArray(overlays)) {
|
19963 | overlays = [ overlays ];
|
19964 | }
|
19965 |
|
19966 | var self = this;
|
19967 |
|
19968 | forEach(overlays, function(overlay) {
|
19969 |
|
19970 | var container = self._getOverlayContainer(overlay.element, true);
|
19971 |
|
19972 | if (overlay) {
|
19973 | remove(overlay.html);
|
19974 | remove(overlay.htmlContainer);
|
19975 |
|
19976 | delete overlay.htmlContainer;
|
19977 | delete overlay.element;
|
19978 |
|
19979 | delete self._overlays[overlay.id];
|
19980 | }
|
19981 |
|
19982 | if (container) {
|
19983 | var idx = container.overlays.indexOf(overlay);
|
19984 | if (idx !== -1) {
|
19985 | container.overlays.splice(idx, 1);
|
19986 | }
|
19987 | }
|
19988 | });
|
19989 |
|
19990 | };
|
19991 |
|
19992 |
|
19993 | Overlays.prototype.show = function() {
|
19994 | setVisible(this._overlayRoot);
|
19995 | };
|
19996 |
|
19997 |
|
19998 | Overlays.prototype.hide = function() {
|
19999 | setVisible(this._overlayRoot, false);
|
20000 | };
|
20001 |
|
20002 | Overlays.prototype.clear = function() {
|
20003 | this._overlays = {};
|
20004 |
|
20005 | this._overlayContainers = [];
|
20006 |
|
20007 | clear(this._overlayRoot);
|
20008 | };
|
20009 |
|
20010 | Overlays.prototype._updateOverlayContainer = function(container) {
|
20011 | var element = container.element,
|
20012 | html = container.html;
|
20013 |
|
20014 |
|
20015 |
|
20016 |
|
20017 | var x = element.x,
|
20018 | y = element.y;
|
20019 |
|
20020 | if (element.waypoints) {
|
20021 | var bbox = getBBox(element);
|
20022 | x = bbox.x;
|
20023 | y = bbox.y;
|
20024 | }
|
20025 |
|
20026 | setPosition(html, x, y);
|
20027 |
|
20028 | attr(container.html, 'data-container-id', element.id);
|
20029 | };
|
20030 |
|
20031 |
|
20032 | Overlays.prototype._updateOverlay = function(overlay) {
|
20033 |
|
20034 | var position = overlay.position,
|
20035 | htmlContainer = overlay.htmlContainer,
|
20036 | element = overlay.element;
|
20037 |
|
20038 |
|
20039 |
|
20040 |
|
20041 |
|
20042 | var left = position.left,
|
20043 | top = position.top;
|
20044 |
|
20045 | if (position.right !== undefined) {
|
20046 |
|
20047 | var width;
|
20048 |
|
20049 | if (element.waypoints) {
|
20050 | width = getBBox(element).width;
|
20051 | } else {
|
20052 | width = element.width;
|
20053 | }
|
20054 |
|
20055 | left = position.right * -1 + width;
|
20056 | }
|
20057 |
|
20058 | if (position.bottom !== undefined) {
|
20059 |
|
20060 | var height;
|
20061 |
|
20062 | if (element.waypoints) {
|
20063 | height = getBBox(element).height;
|
20064 | } else {
|
20065 | height = element.height;
|
20066 | }
|
20067 |
|
20068 | top = position.bottom * -1 + height;
|
20069 | }
|
20070 |
|
20071 | setPosition(htmlContainer, left || 0, top || 0);
|
20072 | };
|
20073 |
|
20074 |
|
20075 | Overlays.prototype._createOverlayContainer = function(element) {
|
20076 | var html = domify('<div class="djs-overlays" style="position: absolute" />');
|
20077 |
|
20078 | this._overlayRoot.appendChild(html);
|
20079 |
|
20080 | var container = {
|
20081 | html: html,
|
20082 | element: element,
|
20083 | overlays: []
|
20084 | };
|
20085 |
|
20086 | this._updateOverlayContainer(container);
|
20087 |
|
20088 | this._overlayContainers.push(container);
|
20089 |
|
20090 | return container;
|
20091 | };
|
20092 |
|
20093 |
|
20094 | Overlays.prototype._updateRoot = function(viewbox) {
|
20095 | var scale = viewbox.scale || 1;
|
20096 |
|
20097 | var matrix = 'matrix(' +
|
20098 | [
|
20099 | scale,
|
20100 | 0,
|
20101 | 0,
|
20102 | scale,
|
20103 | -1 * viewbox.x * scale,
|
20104 | -1 * viewbox.y * scale
|
20105 | ].join(',') +
|
20106 | ')';
|
20107 |
|
20108 | setTransform(this._overlayRoot, matrix);
|
20109 | };
|
20110 |
|
20111 |
|
20112 | Overlays.prototype._getOverlayContainer = function(element, raw) {
|
20113 | var container = find(this._overlayContainers, function(c) {
|
20114 | return c.element === element;
|
20115 | });
|
20116 |
|
20117 |
|
20118 | if (!container && !raw) {
|
20119 | return this._createOverlayContainer(element);
|
20120 | }
|
20121 |
|
20122 | return container;
|
20123 | };
|
20124 |
|
20125 |
|
20126 | Overlays.prototype._addOverlay = function(overlay) {
|
20127 |
|
20128 | var id = overlay.id,
|
20129 | element = overlay.element,
|
20130 | html = overlay.html,
|
20131 | htmlContainer,
|
20132 | overlayContainer;
|
20133 |
|
20134 |
|
20135 | if (html.get && html.constructor.prototype.jquery) {
|
20136 | html = html.get(0);
|
20137 | }
|
20138 |
|
20139 |
|
20140 |
|
20141 | if (isString(html)) {
|
20142 | html = domify(html);
|
20143 | }
|
20144 |
|
20145 | overlayContainer = this._getOverlayContainer(element);
|
20146 |
|
20147 | htmlContainer = domify('<div class="djs-overlay" data-overlay-id="' + id + '" style="position: absolute">');
|
20148 |
|
20149 | htmlContainer.appendChild(html);
|
20150 |
|
20151 | if (overlay.type) {
|
20152 | classes(htmlContainer).add('djs-overlay-' + overlay.type);
|
20153 | }
|
20154 |
|
20155 | overlay.htmlContainer = htmlContainer;
|
20156 |
|
20157 | overlayContainer.overlays.push(overlay);
|
20158 | overlayContainer.html.appendChild(htmlContainer);
|
20159 |
|
20160 | this._overlays[id] = overlay;
|
20161 |
|
20162 | this._updateOverlay(overlay);
|
20163 | this._updateOverlayVisibilty(overlay, this._canvas.viewbox());
|
20164 | };
|
20165 |
|
20166 |
|
20167 | Overlays.prototype._updateOverlayVisibilty = function(overlay, viewbox) {
|
20168 | var show = overlay.show,
|
20169 | minZoom = show && show.minZoom,
|
20170 | maxZoom = show && show.maxZoom,
|
20171 | htmlContainer = overlay.htmlContainer,
|
20172 | visible = true;
|
20173 |
|
20174 | if (show) {
|
20175 | if (
|
20176 | (isDefined(minZoom) && minZoom > viewbox.scale) ||
|
20177 | (isDefined(maxZoom) && maxZoom < viewbox.scale)
|
20178 | ) {
|
20179 | visible = false;
|
20180 | }
|
20181 |
|
20182 | setVisible(htmlContainer, visible);
|
20183 | }
|
20184 |
|
20185 | this._updateOverlayScale(overlay, viewbox);
|
20186 | };
|
20187 |
|
20188 |
|
20189 | Overlays.prototype._updateOverlayScale = function(overlay, viewbox) {
|
20190 | var shouldScale = overlay.scale,
|
20191 | minScale,
|
20192 | maxScale,
|
20193 | htmlContainer = overlay.htmlContainer;
|
20194 |
|
20195 | var scale, transform = '';
|
20196 |
|
20197 | if (shouldScale !== true) {
|
20198 |
|
20199 | if (shouldScale === false) {
|
20200 | minScale = 1;
|
20201 | maxScale = 1;
|
20202 | } else {
|
20203 | minScale = shouldScale.min;
|
20204 | maxScale = shouldScale.max;
|
20205 | }
|
20206 |
|
20207 | if (isDefined(minScale) && viewbox.scale < minScale) {
|
20208 | scale = (1 / viewbox.scale || 1) * minScale;
|
20209 | }
|
20210 |
|
20211 | if (isDefined(maxScale) && viewbox.scale > maxScale) {
|
20212 | scale = (1 / viewbox.scale || 1) * maxScale;
|
20213 | }
|
20214 | }
|
20215 |
|
20216 | if (isDefined(scale)) {
|
20217 | transform = 'scale(' + scale + ',' + scale + ')';
|
20218 | }
|
20219 |
|
20220 | setTransform(htmlContainer, transform);
|
20221 | };
|
20222 |
|
20223 |
|
20224 | Overlays.prototype._updateOverlaysVisibilty = function(viewbox) {
|
20225 |
|
20226 | var self = this;
|
20227 |
|
20228 | forEach(this._overlays, function(overlay) {
|
20229 | self._updateOverlayVisibilty(overlay, viewbox);
|
20230 | });
|
20231 | };
|
20232 |
|
20233 |
|
20234 | Overlays.prototype._init = function() {
|
20235 |
|
20236 | var eventBus = this._eventBus;
|
20237 |
|
20238 | var self = this;
|
20239 |
|
20240 |
|
20241 |
|
20242 |
|
20243 | function updateViewbox(viewbox) {
|
20244 | self._updateRoot(viewbox);
|
20245 | self._updateOverlaysVisibilty(viewbox);
|
20246 |
|
20247 | self.show();
|
20248 | }
|
20249 |
|
20250 | eventBus.on('canvas.viewbox.changing', function(event) {
|
20251 | self.hide();
|
20252 | });
|
20253 |
|
20254 | eventBus.on('canvas.viewbox.changed', function(event) {
|
20255 | updateViewbox(event.viewbox);
|
20256 | });
|
20257 |
|
20258 |
|
20259 |
|
20260 |
|
20261 | eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
|
20262 | var element = e.element;
|
20263 | var overlays = self.get({ element: element });
|
20264 |
|
20265 | forEach(overlays, function(o) {
|
20266 | self.remove(o.id);
|
20267 | });
|
20268 |
|
20269 | var container = self._getOverlayContainer(element);
|
20270 |
|
20271 | if (container) {
|
20272 | remove(container.html);
|
20273 | var i = self._overlayContainers.indexOf(container);
|
20274 | if (i !== -1) {
|
20275 | self._overlayContainers.splice(i, 1);
|
20276 | }
|
20277 | }
|
20278 | });
|
20279 |
|
20280 |
|
20281 |
|
20282 |
|
20283 | eventBus.on('element.changed', LOW_PRIORITY$2, function(e) {
|
20284 | var element = e.element;
|
20285 |
|
20286 | var container = self._getOverlayContainer(element, true);
|
20287 |
|
20288 | if (container) {
|
20289 | forEach(container.overlays, function(overlay) {
|
20290 | self._updateOverlay(overlay);
|
20291 | });
|
20292 |
|
20293 | self._updateOverlayContainer(container);
|
20294 | }
|
20295 | });
|
20296 |
|
20297 |
|
20298 |
|
20299 |
|
20300 | eventBus.on('element.marker.update', function(e) {
|
20301 | var container = self._getOverlayContainer(e.element, true);
|
20302 | if (container) {
|
20303 | classes(container.html)[e.add ? 'add' : 'remove'](e.marker);
|
20304 | }
|
20305 | });
|
20306 |
|
20307 |
|
20308 |
|
20309 |
|
20310 | eventBus.on('diagram.clear', this.clear, this);
|
20311 | };
|
20312 |
|
20313 |
|
20314 |
|
20315 |
|
20316 |
|
20317 | function createRoot(parentNode) {
|
20318 | var root = domify(
|
20319 | '<div class="djs-overlay-container" style="position: absolute; width: 0; height: 0;" />'
|
20320 | );
|
20321 |
|
20322 | parentNode.insertBefore(root, parentNode.firstChild);
|
20323 |
|
20324 | return root;
|
20325 | }
|
20326 |
|
20327 | function setPosition(el, x, y) {
|
20328 | assign(el.style, { left: x + 'px', top: y + 'px' });
|
20329 | }
|
20330 |
|
20331 | function setVisible(el, visible) {
|
20332 | el.style.display = visible === false ? 'none' : '';
|
20333 | }
|
20334 |
|
20335 | function setTransform(el, transform) {
|
20336 |
|
20337 | el.style['transform-origin'] = 'top left';
|
20338 |
|
20339 | [ '', '-ms-', '-webkit-' ].forEach(function(prefix) {
|
20340 | el.style[prefix + 'transform'] = transform;
|
20341 | });
|
20342 | }
|
20343 |
|
20344 | var OverlaysModule = {
|
20345 | __init__: [ 'overlays' ],
|
20346 | overlays: [ 'type', Overlays ]
|
20347 | };
|
20348 |
|
20349 | |
20350 |
|
20351 |
|
20352 |
|
20353 |
|
20354 |
|
20355 |
|
20356 |
|
20357 | 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>';
|
20358 |
|
20359 | var BPMNIO_LOGO_URL = 'data:image/svg+xml,' + encodeURIComponent(BPMNIO_LOGO_SVG);
|
20360 |
|
20361 | var BPMNIO_IMG = '<img width="52" height="52" src="' + BPMNIO_LOGO_URL + '" />';
|
20362 |
|
20363 | function css(attrs) {
|
20364 | return attrs.join(';');
|
20365 | }
|
20366 |
|
20367 | var LIGHTBOX_STYLES = css([
|
20368 | 'z-index: 1001',
|
20369 | 'position: fixed',
|
20370 | 'top: 0',
|
20371 | 'left: 0',
|
20372 | 'right: 0',
|
20373 | 'bottom: 0'
|
20374 | ]);
|
20375 |
|
20376 | var BACKDROP_STYLES = css([
|
20377 | 'width: 100%',
|
20378 | 'height: 100%',
|
20379 | 'background: rgba(0,0,0,0.2)'
|
20380 | ]);
|
20381 |
|
20382 | var NOTICE_STYLES = css([
|
20383 | 'position: absolute',
|
20384 | 'left: 50%',
|
20385 | 'top: 40%',
|
20386 | 'margin: 0 -130px',
|
20387 | 'width: 260px',
|
20388 | 'padding: 10px',
|
20389 | 'background: white',
|
20390 | 'border: solid 1px #AAA',
|
20391 | 'border-radius: 3px',
|
20392 | 'font-family: Helvetica, Arial, sans-serif',
|
20393 | 'font-size: 14px',
|
20394 | 'line-height: 1.2em'
|
20395 | ]);
|
20396 |
|
20397 | var LIGHTBOX_MARKUP =
|
20398 | '<div class="bjs-powered-by-lightbox" style="' + LIGHTBOX_STYLES + '">' +
|
20399 | '<div class="backdrop" style="' + BACKDROP_STYLES + '"></div>' +
|
20400 | '<div class="notice" style="' + NOTICE_STYLES + '">' +
|
20401 | '<a href="http://bpmn.io" target="_blank" style="float: left; margin-right: 10px">' +
|
20402 | BPMNIO_IMG +
|
20403 | '</a>' +
|
20404 | 'Web-based tooling for BPMN, DMN and CMMN diagrams ' +
|
20405 | 'powered by <a href="http://bpmn.io" target="_blank">bpmn.io</a>.' +
|
20406 | '</div>' +
|
20407 | '</div>';
|
20408 |
|
20409 |
|
20410 | var lightbox;
|
20411 |
|
20412 | function open() {
|
20413 |
|
20414 | if (!lightbox) {
|
20415 | lightbox = domify(LIGHTBOX_MARKUP);
|
20416 |
|
20417 | delegateEvents.bind(lightbox, '.backdrop', 'click', function(event) {
|
20418 | document.body.removeChild(lightbox);
|
20419 | });
|
20420 | }
|
20421 |
|
20422 | document.body.appendChild(lightbox);
|
20423 | }
|
20424 |
|
20425 | |
20426 |
|
20427 |
|
20428 |
|
20429 |
|
20430 |
|
20431 |
|
20432 |
|
20433 | function checkValidationError(err) {
|
20434 |
|
20435 |
|
20436 |
|
20437 |
|
20438 | var pattern = /unparsable content <([^>]+)> detected([\s\S]*)$/;
|
20439 | var match = pattern.exec(err.message);
|
20440 |
|
20441 | if (match) {
|
20442 | err.message =
|
20443 | 'unparsable content <' + match[1] + '> detected; ' +
|
20444 | 'this may indicate an invalid BPMN 2.0 diagram file' + match[2];
|
20445 | }
|
20446 |
|
20447 | return err;
|
20448 | }
|
20449 |
|
20450 | var DEFAULT_OPTIONS = {
|
20451 | width: '100%',
|
20452 | height: '100%',
|
20453 | position: 'relative'
|
20454 | };
|
20455 |
|
20456 |
|
20457 | |
20458 |
|
20459 |
|
20460 | function ensureUnit(val) {
|
20461 | return val + (isNumber(val) ? 'px' : '');
|
20462 | }
|
20463 |
|
20464 |
|
20465 | |
20466 |
|
20467 |
|
20468 |
|
20469 |
|
20470 |
|
20471 |
|
20472 |
|
20473 | function findBPMNDiagram(definitions, diagramId) {
|
20474 | if (!diagramId) {
|
20475 | return null;
|
20476 | }
|
20477 |
|
20478 | return find(definitions.diagrams, function(element) {
|
20479 | return element.id === diagramId;
|
20480 | }) || null;
|
20481 | }
|
20482 |
|
20483 | |
20484 |
|
20485 |
|
20486 |
|
20487 |
|
20488 |
|
20489 |
|
20490 |
|
20491 |
|
20492 |
|
20493 |
|
20494 |
|
20495 |
|
20496 |
|
20497 |
|
20498 |
|
20499 |
|
20500 |
|
20501 |
|
20502 |
|
20503 |
|
20504 |
|
20505 |
|
20506 |
|
20507 |
|
20508 |
|
20509 |
|
20510 |
|
20511 |
|
20512 |
|
20513 |
|
20514 |
|
20515 |
|
20516 |
|
20517 |
|
20518 |
|
20519 |
|
20520 |
|
20521 |
|
20522 |
|
20523 |
|
20524 |
|
20525 |
|
20526 |
|
20527 |
|
20528 |
|
20529 |
|
20530 | function Viewer(options) {
|
20531 |
|
20532 | options = assign({}, DEFAULT_OPTIONS, options);
|
20533 |
|
20534 | this._moddle = this._createModdle(options);
|
20535 |
|
20536 | this._container = this._createContainer(options);
|
20537 |
|
20538 |
|
20539 |
|
20540 | addProjectLogo(this._container);
|
20541 |
|
20542 |
|
20543 |
|
20544 | this._init(this._container, this._moddle, options);
|
20545 | }
|
20546 |
|
20547 | inherits_browser(Viewer, Diagram);
|
20548 |
|
20549 |
|
20550 | |
20551 |
|
20552 |
|
20553 |
|
20554 |
|
20555 |
|
20556 |
|
20557 |
|
20558 |
|
20559 |
|
20560 |
|
20561 |
|
20562 |
|
20563 |
|
20564 |
|
20565 |
|
20566 |
|
20567 |
|
20568 |
|
20569 |
|
20570 |
|
20571 |
|
20572 | Viewer.prototype.importXML = function(xml, bpmnDiagram, done) {
|
20573 |
|
20574 | if (isFunction(bpmnDiagram)) {
|
20575 | done = bpmnDiagram;
|
20576 | bpmnDiagram = null;
|
20577 | }
|
20578 |
|
20579 |
|
20580 | done = done || function() {};
|
20581 |
|
20582 | var self = this;
|
20583 |
|
20584 |
|
20585 |
|
20586 | xml = this._emit('import.parse.start', { xml: xml }) || xml;
|
20587 |
|
20588 | this._moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions, context) {
|
20589 |
|
20590 |
|
20591 |
|
20592 | definitions = self._emit('import.parse.complete', {
|
20593 | error: err,
|
20594 | definitions: definitions,
|
20595 | context: context
|
20596 | }) || definitions;
|
20597 |
|
20598 | var parseWarnings = context.warnings;
|
20599 |
|
20600 | if (err) {
|
20601 | err = checkValidationError(err);
|
20602 |
|
20603 | self._emit('import.done', { error: err, warnings: parseWarnings });
|
20604 |
|
20605 | return done(err, parseWarnings);
|
20606 | }
|
20607 |
|
20608 | self.importDefinitions(definitions, bpmnDiagram, function(err, importWarnings) {
|
20609 | var allWarnings = [].concat(parseWarnings, importWarnings || []);
|
20610 |
|
20611 | self._emit('import.done', { error: err, warnings: allWarnings });
|
20612 |
|
20613 | done(err, allWarnings);
|
20614 | });
|
20615 | });
|
20616 | };
|
20617 |
|
20618 | |
20619 |
|
20620 |
|
20621 |
|
20622 |
|
20623 |
|
20624 |
|
20625 |
|
20626 |
|
20627 |
|
20628 |
|
20629 |
|
20630 |
|
20631 |
|
20632 |
|
20633 |
|
20634 |
|
20635 |
|
20636 |
|
20637 | Viewer.prototype.importDefinitions = function(definitions, bpmnDiagram, done) {
|
20638 |
|
20639 | if (isFunction(bpmnDiagram)) {
|
20640 | done = bpmnDiagram;
|
20641 | bpmnDiagram = null;
|
20642 | }
|
20643 |
|
20644 |
|
20645 | done = done || function() {};
|
20646 |
|
20647 | this._setDefinitions(definitions);
|
20648 |
|
20649 | return this.open(bpmnDiagram, done);
|
20650 | };
|
20651 |
|
20652 | |
20653 |
|
20654 |
|
20655 |
|
20656 |
|
20657 |
|
20658 |
|
20659 |
|
20660 |
|
20661 |
|
20662 |
|
20663 |
|
20664 |
|
20665 |
|
20666 |
|
20667 |
|
20668 |
|
20669 |
|
20670 | Viewer.prototype.open = function(bpmnDiagramOrId, done) {
|
20671 |
|
20672 | if (isFunction(bpmnDiagramOrId)) {
|
20673 | done = bpmnDiagramOrId;
|
20674 | bpmnDiagramOrId = null;
|
20675 | }
|
20676 |
|
20677 | var definitions = this._definitions;
|
20678 | var bpmnDiagram = bpmnDiagramOrId;
|
20679 |
|
20680 |
|
20681 | done = done || function() {};
|
20682 |
|
20683 | if (!definitions) {
|
20684 | return done(new Error('no XML imported'));
|
20685 | }
|
20686 |
|
20687 | if (typeof bpmnDiagramOrId === 'string') {
|
20688 | bpmnDiagram = findBPMNDiagram(definitions, bpmnDiagramOrId);
|
20689 |
|
20690 | if (!bpmnDiagram) {
|
20691 | return done(new Error('BPMNDiagram <' + bpmnDiagramOrId + '> not found'));
|
20692 | }
|
20693 | }
|
20694 |
|
20695 |
|
20696 |
|
20697 | try {
|
20698 | this.clear();
|
20699 | } catch (error) {
|
20700 | return done(error);
|
20701 | }
|
20702 |
|
20703 |
|
20704 | return importBpmnDiagram(this, definitions, bpmnDiagram, done);
|
20705 | };
|
20706 |
|
20707 | |
20708 |
|
20709 |
|
20710 |
|
20711 |
|
20712 |
|
20713 |
|
20714 |
|
20715 |
|
20716 |
|
20717 |
|
20718 |
|
20719 |
|
20720 |
|
20721 |
|
20722 |
|
20723 |
|
20724 |
|
20725 |
|
20726 |
|
20727 | Viewer.prototype.saveXML = function(options, done) {
|
20728 |
|
20729 | if (!done) {
|
20730 | done = options;
|
20731 | options = {};
|
20732 | }
|
20733 |
|
20734 | var self = this;
|
20735 |
|
20736 | var definitions = this._definitions;
|
20737 |
|
20738 | if (!definitions) {
|
20739 | return done(new Error('no definitions loaded'));
|
20740 | }
|
20741 |
|
20742 |
|
20743 | definitions = this._emit('saveXML.start', {
|
20744 | definitions: definitions
|
20745 | }) || definitions;
|
20746 |
|
20747 | this._moddle.toXML(definitions, options, function(err, xml) {
|
20748 |
|
20749 | try {
|
20750 | xml = self._emit('saveXML.serialized', {
|
20751 | error: err,
|
20752 | xml: xml
|
20753 | }) || xml;
|
20754 |
|
20755 | self._emit('saveXML.done', {
|
20756 | error: err,
|
20757 | xml: xml
|
20758 | });
|
20759 | } catch (e) {
|
20760 | console.error('error in saveXML life-cycle listener', e);
|
20761 | }
|
20762 |
|
20763 | done(err, xml);
|
20764 | });
|
20765 | };
|
20766 |
|
20767 | |
20768 |
|
20769 |
|
20770 |
|
20771 |
|
20772 |
|
20773 |
|
20774 |
|
20775 |
|
20776 |
|
20777 |
|
20778 |
|
20779 |
|
20780 |
|
20781 |
|
20782 |
|
20783 | Viewer.prototype.saveSVG = function(options, done) {
|
20784 |
|
20785 | if (!done) {
|
20786 | done = options;
|
20787 | options = {};
|
20788 | }
|
20789 |
|
20790 | this._emit('saveSVG.start');
|
20791 |
|
20792 | var svg, err;
|
20793 |
|
20794 | try {
|
20795 | var canvas = this.get('canvas');
|
20796 |
|
20797 | var contentNode = canvas.getDefaultLayer(),
|
20798 | defsNode = query('defs', canvas._svg);
|
20799 |
|
20800 | var contents = innerSVG(contentNode),
|
20801 | defs = defsNode ? '<defs>' + innerSVG(defsNode) + '</defs>' : '';
|
20802 |
|
20803 | var bbox = contentNode.getBBox();
|
20804 |
|
20805 | svg =
|
20806 | '<?xml version="1.0" encoding="utf-8"?>\n' +
|
20807 | '<!-- created with bpmn-js / http://bpmn.io -->\n' +
|
20808 | '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
|
20809 | '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +
|
20810 | 'width="' + bbox.width + '" height="' + bbox.height + '" ' +
|
20811 | 'viewBox="' + bbox.x + ' ' + bbox.y + ' ' + bbox.width + ' ' + bbox.height + '" version="1.1">' +
|
20812 | defs + contents +
|
20813 | '</svg>';
|
20814 | } catch (e) {
|
20815 | err = e;
|
20816 | }
|
20817 |
|
20818 | this._emit('saveSVG.done', {
|
20819 | error: err,
|
20820 | svg: svg
|
20821 | });
|
20822 |
|
20823 | done(err, svg);
|
20824 | };
|
20825 |
|
20826 | |
20827 |
|
20828 |
|
20829 |
|
20830 |
|
20831 |
|
20832 |
|
20833 |
|
20834 |
|
20835 |
|
20836 |
|
20837 |
|
20838 |
|
20839 |
|
20840 |
|
20841 | |
20842 |
|
20843 |
|
20844 |
|
20845 |
|
20846 |
|
20847 |
|
20848 |
|
20849 |
|
20850 |
|
20851 |
|
20852 |
|
20853 |
|
20854 |
|
20855 |
|
20856 |
|
20857 |
|
20858 | Viewer.prototype._setDefinitions = function(definitions) {
|
20859 | this._definitions = definitions;
|
20860 | };
|
20861 |
|
20862 | Viewer.prototype.getModules = function() {
|
20863 | return this._modules;
|
20864 | };
|
20865 |
|
20866 | |
20867 |
|
20868 |
|
20869 |
|
20870 |
|
20871 |
|
20872 |
|
20873 |
|
20874 | Viewer.prototype.clear = function() {
|
20875 |
|
20876 |
|
20877 |
|
20878 |
|
20879 |
|
20880 |
|
20881 | this.get('elementRegistry').forEach(function(element) {
|
20882 | var bo = element.businessObject;
|
20883 |
|
20884 | if (bo && bo.di) {
|
20885 | delete bo.di;
|
20886 | }
|
20887 | });
|
20888 |
|
20889 |
|
20890 | Diagram.prototype.clear.call(this);
|
20891 | };
|
20892 |
|
20893 | |
20894 |
|
20895 |
|
20896 |
|
20897 | Viewer.prototype.destroy = function() {
|
20898 |
|
20899 |
|
20900 | Diagram.prototype.destroy.call(this);
|
20901 |
|
20902 |
|
20903 | remove(this._container);
|
20904 | };
|
20905 |
|
20906 | |
20907 |
|
20908 |
|
20909 |
|
20910 |
|
20911 |
|
20912 |
|
20913 |
|
20914 |
|
20915 |
|
20916 | Viewer.prototype.on = function(event, priority, callback, target) {
|
20917 | return this.get('eventBus').on(event, priority, callback, target);
|
20918 | };
|
20919 |
|
20920 | |
20921 |
|
20922 |
|
20923 |
|
20924 |
|
20925 |
|
20926 | Viewer.prototype.off = function(event, callback) {
|
20927 | this.get('eventBus').off(event, callback);
|
20928 | };
|
20929 |
|
20930 | Viewer.prototype.attachTo = function(parentNode) {
|
20931 |
|
20932 | if (!parentNode) {
|
20933 | throw new Error('parentNode required');
|
20934 | }
|
20935 |
|
20936 |
|
20937 |
|
20938 | this.detach();
|
20939 |
|
20940 |
|
20941 | if (parentNode.get && parentNode.constructor.prototype.jquery) {
|
20942 | parentNode = parentNode.get(0);
|
20943 | }
|
20944 |
|
20945 | if (typeof parentNode === 'string') {
|
20946 | parentNode = query(parentNode);
|
20947 | }
|
20948 |
|
20949 | parentNode.appendChild(this._container);
|
20950 |
|
20951 | this._emit('attach', {});
|
20952 |
|
20953 | this.get('canvas').resized();
|
20954 | };
|
20955 |
|
20956 | Viewer.prototype.getDefinitions = function() {
|
20957 | return this._definitions;
|
20958 | };
|
20959 |
|
20960 | Viewer.prototype.detach = function() {
|
20961 |
|
20962 | var container = this._container,
|
20963 | parentNode = container.parentNode;
|
20964 |
|
20965 | if (!parentNode) {
|
20966 | return;
|
20967 | }
|
20968 |
|
20969 | this._emit('detach', {});
|
20970 |
|
20971 | parentNode.removeChild(container);
|
20972 | };
|
20973 |
|
20974 | Viewer.prototype._init = function(container, moddle, options) {
|
20975 |
|
20976 | var baseModules = options.modules || this.getModules(),
|
20977 | additionalModules = options.additionalModules || [],
|
20978 | staticModules = [
|
20979 | {
|
20980 | bpmnjs: [ 'value', this ],
|
20981 | moddle: [ 'value', moddle ]
|
20982 | }
|
20983 | ];
|
20984 |
|
20985 | var diagramModules = [].concat(staticModules, baseModules, additionalModules);
|
20986 |
|
20987 | var diagramOptions = assign(omit(options, [ 'additionalModules' ]), {
|
20988 | canvas: assign({}, options.canvas, { container: container }),
|
20989 | modules: diagramModules
|
20990 | });
|
20991 |
|
20992 |
|
20993 | Diagram.call(this, diagramOptions);
|
20994 |
|
20995 | if (options && options.container) {
|
20996 | this.attachTo(options.container);
|
20997 | }
|
20998 | };
|
20999 |
|
21000 | |
21001 |
|
21002 |
|
21003 |
|
21004 |
|
21005 |
|
21006 |
|
21007 |
|
21008 | Viewer.prototype._emit = function(type, event) {
|
21009 | return this.get('eventBus').fire(type, event);
|
21010 | };
|
21011 |
|
21012 | Viewer.prototype._createContainer = function(options) {
|
21013 |
|
21014 | var container = domify('<div class="bjs-container"></div>');
|
21015 |
|
21016 | assign(container.style, {
|
21017 | width: ensureUnit(options.width),
|
21018 | height: ensureUnit(options.height),
|
21019 | position: options.position
|
21020 | });
|
21021 |
|
21022 | return container;
|
21023 | };
|
21024 |
|
21025 | Viewer.prototype._createModdle = function(options) {
|
21026 | var moddleOptions = assign({}, this._moddleExtensions, options.moddleExtensions);
|
21027 |
|
21028 | return new simple(moddleOptions);
|
21029 | };
|
21030 |
|
21031 |
|
21032 | Viewer.prototype._modules = [
|
21033 | CoreModule$1,
|
21034 | translate$2,
|
21035 | SelectionModule,
|
21036 | OverlaysModule
|
21037 | ];
|
21038 |
|
21039 |
|
21040 | Viewer.prototype._moddleExtensions = {};
|
21041 |
|
21042 | |
21043 |
|
21044 |
|
21045 |
|
21046 |
|
21047 |
|
21048 |
|
21049 |
|
21050 | function addProjectLogo(container) {
|
21051 | var img = BPMNIO_IMG;
|
21052 |
|
21053 | var linkMarkup =
|
21054 | '<a href="http://bpmn.io" ' +
|
21055 | 'target="_blank" ' +
|
21056 | 'class="bjs-powered-by" ' +
|
21057 | 'title="Powered by bpmn.io" ' +
|
21058 | 'style="position: absolute; bottom: 15px; right: 15px; z-index: 100">' +
|
21059 | img +
|
21060 | '</a>';
|
21061 |
|
21062 | var linkElement = domify(linkMarkup);
|
21063 |
|
21064 | container.appendChild(linkElement);
|
21065 |
|
21066 | componentEvent.bind(linkElement, 'click', function(event) {
|
21067 | open();
|
21068 |
|
21069 | event.preventDefault();
|
21070 | });
|
21071 | }
|
21072 |
|
21073 |
|
21074 |
|
21075 | |
21076 |
|
21077 |
|
21078 |
|
21079 | function hasModifier(event) {
|
21080 | return (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey);
|
21081 | }
|
21082 |
|
21083 | |
21084 |
|
21085 |
|
21086 | function isCmd(event) {
|
21087 |
|
21088 |
|
21089 |
|
21090 | if (event.altKey) {
|
21091 | return false;
|
21092 | }
|
21093 |
|
21094 | return event.ctrlKey || event.metaKey;
|
21095 | }
|
21096 |
|
21097 | |
21098 |
|
21099 |
|
21100 |
|
21101 |
|
21102 |
|
21103 | function isKey(keys, event) {
|
21104 | keys = isArray(keys) ? keys : [ keys ];
|
21105 |
|
21106 | return keys.indexOf(event.key) > -1;
|
21107 | }
|
21108 |
|
21109 | |
21110 |
|
21111 |
|
21112 | function isShift(event) {
|
21113 | return event.shiftKey;
|
21114 | }
|
21115 |
|
21116 | var KEYDOWN_EVENT = 'keyboard.keydown',
|
21117 | KEYUP_EVENT = 'keyboard.keyup';
|
21118 |
|
21119 | var DEFAULT_PRIORITY$1 = 1000;
|
21120 |
|
21121 |
|
21122 | |
21123 |
|
21124 |
|
21125 |
|
21126 |
|
21127 |
|
21128 |
|
21129 |
|
21130 |
|
21131 |
|
21132 |
|
21133 |
|
21134 |
|
21135 |
|
21136 |
|
21137 |
|
21138 |
|
21139 |
|
21140 |
|
21141 |
|
21142 |
|
21143 |
|
21144 |
|
21145 |
|
21146 | function Keyboard(config, eventBus) {
|
21147 | var self = this;
|
21148 |
|
21149 | this._config = config || {};
|
21150 | this._eventBus = eventBus;
|
21151 |
|
21152 | this._keydownHandler = this._keydownHandler.bind(this);
|
21153 | this._keyupHandler = this._keyupHandler.bind(this);
|
21154 |
|
21155 |
|
21156 | eventBus.on('diagram.destroy', function() {
|
21157 | self._fire('destroy');
|
21158 |
|
21159 | self.unbind();
|
21160 | });
|
21161 |
|
21162 | eventBus.on('diagram.init', function() {
|
21163 | self._fire('init');
|
21164 | });
|
21165 |
|
21166 | eventBus.on('attach', function() {
|
21167 | if (config && config.bindTo) {
|
21168 | self.bind(config.bindTo);
|
21169 | }
|
21170 | });
|
21171 |
|
21172 | eventBus.on('detach', function() {
|
21173 | self.unbind();
|
21174 | });
|
21175 | }
|
21176 |
|
21177 | Keyboard.$inject = [
|
21178 | 'config.keyboard',
|
21179 | 'eventBus'
|
21180 | ];
|
21181 |
|
21182 | Keyboard.prototype._keydownHandler = function(event) {
|
21183 | this._keyHandler(event, KEYDOWN_EVENT);
|
21184 | };
|
21185 |
|
21186 | Keyboard.prototype._keyupHandler = function(event) {
|
21187 | this._keyHandler(event, KEYUP_EVENT);
|
21188 | };
|
21189 |
|
21190 | Keyboard.prototype._keyHandler = function(event, type) {
|
21191 | var target = event.target,
|
21192 | eventBusResult;
|
21193 |
|
21194 | if (isInput(target)) {
|
21195 | return;
|
21196 | }
|
21197 |
|
21198 | var context = {
|
21199 | keyEvent: event
|
21200 | };
|
21201 |
|
21202 | eventBusResult = this._eventBus.fire(type || KEYDOWN_EVENT, context);
|
21203 |
|
21204 | if (eventBusResult) {
|
21205 | event.preventDefault();
|
21206 | }
|
21207 | };
|
21208 |
|
21209 | Keyboard.prototype.bind = function(node) {
|
21210 |
|
21211 |
|
21212 | this.unbind();
|
21213 |
|
21214 | this._node = node;
|
21215 |
|
21216 |
|
21217 | componentEvent.bind(node, 'keydown', this._keydownHandler, true);
|
21218 | componentEvent.bind(node, 'keyup', this._keyupHandler, true);
|
21219 |
|
21220 | this._fire('bind');
|
21221 | };
|
21222 |
|
21223 | Keyboard.prototype.getBinding = function() {
|
21224 | return this._node;
|
21225 | };
|
21226 |
|
21227 | Keyboard.prototype.unbind = function() {
|
21228 | var node = this._node;
|
21229 |
|
21230 | if (node) {
|
21231 | this._fire('unbind');
|
21232 |
|
21233 |
|
21234 | componentEvent.unbind(node, 'keydown', this._keydownHandler, true);
|
21235 | componentEvent.unbind(node, 'keyup', this._keyupHandler, true);
|
21236 | }
|
21237 |
|
21238 | this._node = null;
|
21239 | };
|
21240 |
|
21241 | Keyboard.prototype._fire = function(event) {
|
21242 | this._eventBus.fire('keyboard.' + event, { node: this._node });
|
21243 | };
|
21244 |
|
21245 | |
21246 |
|
21247 |
|
21248 |
|
21249 |
|
21250 |
|
21251 |
|
21252 |
|
21253 |
|
21254 | Keyboard.prototype.addListener = function(priority, listener, type) {
|
21255 | if (isFunction(priority)) {
|
21256 | type = listener;
|
21257 | listener = priority;
|
21258 | priority = DEFAULT_PRIORITY$1;
|
21259 | }
|
21260 |
|
21261 | this._eventBus.on(type || KEYDOWN_EVENT, priority, listener);
|
21262 | };
|
21263 |
|
21264 | Keyboard.prototype.removeListener = function(listener, type) {
|
21265 | this._eventBus.off(type || KEYDOWN_EVENT, listener);
|
21266 | };
|
21267 |
|
21268 | Keyboard.prototype.hasModifier = hasModifier;
|
21269 | Keyboard.prototype.isCmd = isCmd;
|
21270 | Keyboard.prototype.isShift = isShift;
|
21271 | Keyboard.prototype.isKey = isKey;
|
21272 |
|
21273 |
|
21274 |
|
21275 |
|
21276 |
|
21277 | function isInput(target) {
|
21278 | return target && (matchesSelector$1(target, 'input, textarea') || target.contentEditable === 'true');
|
21279 | }
|
21280 |
|
21281 | var LOW_PRIORITY$3 = 500;
|
21282 |
|
21283 |
|
21284 | |
21285 |
|
21286 |
|
21287 |
|
21288 |
|
21289 |
|
21290 |
|
21291 |
|
21292 |
|
21293 | function KeyboardBindings(eventBus, keyboard) {
|
21294 |
|
21295 | var self = this;
|
21296 |
|
21297 | eventBus.on('editorActions.init', LOW_PRIORITY$3, function(event) {
|
21298 |
|
21299 | var editorActions = event.editorActions;
|
21300 |
|
21301 | self.registerBindings(keyboard, editorActions);
|
21302 | });
|
21303 | }
|
21304 |
|
21305 | KeyboardBindings.$inject = [
|
21306 | 'eventBus',
|
21307 | 'keyboard'
|
21308 | ];
|
21309 |
|
21310 |
|
21311 | |
21312 |
|
21313 |
|
21314 |
|
21315 |
|
21316 |
|
21317 | KeyboardBindings.prototype.registerBindings = function(keyboard, editorActions) {
|
21318 |
|
21319 | |
21320 |
|
21321 |
|
21322 |
|
21323 |
|
21324 |
|
21325 |
|
21326 | function addListener(action, fn) {
|
21327 |
|
21328 | if (editorActions.isRegistered(action)) {
|
21329 | keyboard.addListener(fn);
|
21330 | }
|
21331 | }
|
21332 |
|
21333 |
|
21334 |
|
21335 |
|
21336 | addListener('undo', function(context) {
|
21337 |
|
21338 | var event = context.keyEvent;
|
21339 |
|
21340 | if (isCmd(event) && !isShift(event) && isKey(['z', 'Z'], event)) {
|
21341 | editorActions.trigger('undo');
|
21342 |
|
21343 | return true;
|
21344 | }
|
21345 | });
|
21346 |
|
21347 |
|
21348 |
|
21349 |
|
21350 | addListener('redo', function(context) {
|
21351 |
|
21352 | var event = context.keyEvent;
|
21353 |
|
21354 | if (isCmd(event) && (isKey(['y', 'Y'], event) || (isKey(['z', 'Z'], event) && isShift(event)))) {
|
21355 | editorActions.trigger('redo');
|
21356 |
|
21357 | return true;
|
21358 | }
|
21359 | });
|
21360 |
|
21361 |
|
21362 |
|
21363 | addListener('copy', function(context) {
|
21364 |
|
21365 | var event = context.keyEvent;
|
21366 |
|
21367 | if (isCmd(event) && isKey(['c', 'C'], event)) {
|
21368 | editorActions.trigger('copy');
|
21369 |
|
21370 | return true;
|
21371 | }
|
21372 | });
|
21373 |
|
21374 |
|
21375 |
|
21376 | addListener('paste', function(context) {
|
21377 |
|
21378 | var event = context.keyEvent;
|
21379 |
|
21380 | if (isCmd(event) && isKey(['v', 'V'], event)) {
|
21381 | editorActions.trigger('paste');
|
21382 |
|
21383 | return true;
|
21384 | }
|
21385 | });
|
21386 |
|
21387 |
|
21388 |
|
21389 | addListener('stepZoom', function(context) {
|
21390 |
|
21391 | var event = context.keyEvent;
|
21392 |
|
21393 | if (isKey([ '+', 'Add' ], event) && isCmd(event)) {
|
21394 | editorActions.trigger('stepZoom', { value: 1 });
|
21395 |
|
21396 | return true;
|
21397 | }
|
21398 | });
|
21399 |
|
21400 |
|
21401 |
|
21402 | addListener('stepZoom', function(context) {
|
21403 |
|
21404 | var event = context.keyEvent;
|
21405 |
|
21406 | if (isKey([ '-', 'Subtract' ], event) && isCmd(event)) {
|
21407 | editorActions.trigger('stepZoom', { value: -1 });
|
21408 |
|
21409 | return true;
|
21410 | }
|
21411 | });
|
21412 |
|
21413 |
|
21414 |
|
21415 | addListener('zoom', function(context) {
|
21416 |
|
21417 | var event = context.keyEvent;
|
21418 |
|
21419 | if (isKey('0', event) && isCmd(event)) {
|
21420 | editorActions.trigger('zoom', { value: 1 });
|
21421 |
|
21422 | return true;
|
21423 | }
|
21424 | });
|
21425 |
|
21426 |
|
21427 |
|
21428 | addListener('removeSelection', function(context) {
|
21429 |
|
21430 | var event = context.keyEvent;
|
21431 |
|
21432 | if (isKey([ 'Delete', 'Del' ], event)) {
|
21433 | editorActions.trigger('removeSelection');
|
21434 |
|
21435 | return true;
|
21436 | }
|
21437 | });
|
21438 | };
|
21439 |
|
21440 | var KeyboardModule = {
|
21441 | __init__: [ 'keyboard', 'keyboardBindings' ],
|
21442 | keyboard: [ 'type', Keyboard ],
|
21443 | keyboardBindings: [ 'type', KeyboardBindings ]
|
21444 | };
|
21445 |
|
21446 | var DEFAULT_CONFIG = {
|
21447 | moveSpeed: 50,
|
21448 | moveSpeedAccelerated: 200
|
21449 | };
|
21450 |
|
21451 |
|
21452 | |
21453 |
|
21454 |
|
21455 |
|
21456 |
|
21457 |
|
21458 |
|
21459 |
|
21460 |
|
21461 | function KeyboardMove(
|
21462 | config,
|
21463 | keyboard,
|
21464 | canvas
|
21465 | ) {
|
21466 |
|
21467 | var self = this;
|
21468 |
|
21469 | this._config = assign({}, DEFAULT_CONFIG, config || {});
|
21470 |
|
21471 | keyboard.addListener(arrowsListener);
|
21472 |
|
21473 |
|
21474 | function arrowsListener(context) {
|
21475 |
|
21476 | var event = context.keyEvent,
|
21477 | config = self._config;
|
21478 |
|
21479 | if (!keyboard.isCmd(event)) {
|
21480 | return;
|
21481 | }
|
21482 |
|
21483 | if (keyboard.isKey([
|
21484 | 'ArrowLeft', 'Left',
|
21485 | 'ArrowUp', 'Up',
|
21486 | 'ArrowDown', 'Down',
|
21487 | 'ArrowRight', 'Right'
|
21488 | ], event)) {
|
21489 |
|
21490 | var speed = (
|
21491 | keyboard.isShift(event) ?
|
21492 | config.moveSpeedAccelerated :
|
21493 | config.moveSpeed
|
21494 | );
|
21495 |
|
21496 | var direction;
|
21497 |
|
21498 | switch (event.key) {
|
21499 | case 'ArrowLeft':
|
21500 | case 'Left':
|
21501 | direction = 'left';
|
21502 | break;
|
21503 | case 'ArrowUp':
|
21504 | case 'Up':
|
21505 | direction = 'up';
|
21506 | break;
|
21507 | case 'ArrowRight':
|
21508 | case 'Right':
|
21509 | direction = 'right';
|
21510 | break;
|
21511 | case 'ArrowDown':
|
21512 | case 'Down':
|
21513 | direction = 'down';
|
21514 | break;
|
21515 | }
|
21516 |
|
21517 | self.moveCanvas({
|
21518 | speed: speed,
|
21519 | direction: direction
|
21520 | });
|
21521 |
|
21522 | return true;
|
21523 | }
|
21524 | }
|
21525 |
|
21526 | this.moveCanvas = function(opts) {
|
21527 |
|
21528 | var dx = 0,
|
21529 | dy = 0,
|
21530 | speed = opts.speed;
|
21531 |
|
21532 | var actualSpeed = speed / Math.min(Math.sqrt(canvas.viewbox().scale), 1);
|
21533 |
|
21534 | switch (opts.direction) {
|
21535 | case 'left':
|
21536 | dx = actualSpeed;
|
21537 | break;
|
21538 | case 'up':
|
21539 | dy = actualSpeed;
|
21540 | break;
|
21541 | case 'right':
|
21542 | dx = -actualSpeed;
|
21543 | break;
|
21544 | case 'down':
|
21545 | dy = -actualSpeed;
|
21546 | break;
|
21547 | }
|
21548 |
|
21549 | canvas.scroll({
|
21550 | dx: dx,
|
21551 | dy: dy
|
21552 | });
|
21553 | };
|
21554 |
|
21555 | }
|
21556 |
|
21557 |
|
21558 | KeyboardMove.$inject = [
|
21559 | 'config.keyboardMove',
|
21560 | 'keyboard',
|
21561 | 'canvas'
|
21562 | ];
|
21563 |
|
21564 | var KeyboardMoveModule = {
|
21565 | __depends__: [
|
21566 | KeyboardModule
|
21567 | ],
|
21568 | __init__: [ 'keyboardMove' ],
|
21569 | keyboardMove: [ 'type', KeyboardMove ]
|
21570 | };
|
21571 |
|
21572 | var CURSOR_CLS_PATTERN = /^djs-cursor-.*$/;
|
21573 |
|
21574 |
|
21575 | function set$1(mode) {
|
21576 | var classes$1 = classes(document.body);
|
21577 |
|
21578 | classes$1.removeMatching(CURSOR_CLS_PATTERN);
|
21579 |
|
21580 | if (mode) {
|
21581 | classes$1.add('djs-cursor-' + mode);
|
21582 | }
|
21583 | }
|
21584 |
|
21585 | function unset() {
|
21586 | set$1(null);
|
21587 | }
|
21588 |
|
21589 | var TRAP_PRIORITY = 5000;
|
21590 |
|
21591 | /**
|
21592 | * Installs a click trap that prevents a ghost click following a dragging operation.
|
21593 | *
|
21594 | * @return {Function} a function to immediately remove the installed trap.
|
21595 | */
|
21596 | function install(eventBus, eventName) {
|
21597 |
|
21598 | eventName = eventName || 'element.click';
|
21599 |
|
21600 | function trap() {
|
21601 | return false;
|
21602 | }
|
21603 |
|
21604 | eventBus.once(eventName, TRAP_PRIORITY, trap);
|
21605 |
|
21606 | return function() {
|
21607 | eventBus.off(eventName, trap);
|
21608 | };
|
21609 | }
|
21610 |
|
21611 | function center(bounds) {
|
21612 | return {
|
21613 | x: bounds.x + (bounds.width / 2),
|
21614 | y: bounds.y + (bounds.height / 2)
|
21615 | };
|
21616 | }
|
21617 |
|
21618 |
|
21619 | function delta(a, b) {
|
21620 | return {
|
21621 | x: a.x - b.x,
|
21622 | y: a.y - b.y
|
21623 | };
|
21624 | }
|
21625 |
|
21626 | var THRESHOLD = 15;
|
21627 |
|
21628 |
|
21629 | |
21630 |
|
21631 |
|
21632 |
|
21633 |
|
21634 |
|
21635 | function MoveCanvas(eventBus, canvas) {
|
21636 |
|
21637 | var context;
|
21638 |
|
21639 |
|
21640 |
|
21641 |
|
21642 |
|
21643 | eventBus.on('element.mousedown', 500, function(e) {
|
21644 | return handleStart(e.originalEvent);
|
21645 | });
|
21646 |
|
21647 |
|
21648 | function handleMove(event) {
|
21649 |
|
21650 | var start = context.start,
|
21651 | position = toPoint(event),
|
21652 | delta$1 = delta(position, start);
|
21653 |
|
21654 | if (!context.dragging && length(delta$1) > THRESHOLD) {
|
21655 | context.dragging = true;
|
21656 |
|
21657 | install(eventBus);
|
21658 |
|
21659 | set$1('grab');
|
21660 | }
|
21661 |
|
21662 | if (context.dragging) {
|
21663 |
|
21664 | var lastPosition = context.last || context.start;
|
21665 |
|
21666 | delta$1 = delta(position, lastPosition);
|
21667 |
|
21668 | canvas.scroll({
|
21669 | dx: delta$1.x,
|
21670 | dy: delta$1.y
|
21671 | });
|
21672 |
|
21673 | context.last = position;
|
21674 | }
|
21675 |
|
21676 |
|
21677 | event.preventDefault();
|
21678 | }
|
21679 |
|
21680 |
|
21681 | function handleEnd(event) {
|
21682 | componentEvent.unbind(document, 'mousemove', handleMove);
|
21683 | componentEvent.unbind(document, 'mouseup', handleEnd);
|
21684 |
|
21685 | context = null;
|
21686 |
|
21687 | unset();
|
21688 | }
|
21689 |
|
21690 | function handleStart(event) {
|
21691 |
|
21692 |
|
21693 | if (closest(event.target, '.djs-draggable')) {
|
21694 | return;
|
21695 | }
|
21696 |
|
21697 |
|
21698 |
|
21699 | if (event.button || event.ctrlKey || event.shiftKey || event.altKey) {
|
21700 | return;
|
21701 | }
|
21702 |
|
21703 | context = {
|
21704 | start: toPoint(event)
|
21705 | };
|
21706 |
|
21707 | componentEvent.bind(document, 'mousemove', handleMove);
|
21708 | componentEvent.bind(document, 'mouseup', handleEnd);
|
21709 |
|
21710 |
|
21711 | return true;
|
21712 | }
|
21713 | }
|
21714 |
|
21715 |
|
21716 | MoveCanvas.$inject = [
|
21717 | 'eventBus',
|
21718 | 'canvas'
|
21719 | ];
|
21720 |
|
21721 |
|
21722 |
|
21723 |
|
21724 |
|
21725 | function length(point) {
|
21726 | return Math.sqrt(Math.pow(point.x, 2) + Math.pow(point.y, 2));
|
21727 | }
|
21728 |
|
21729 | var MoveCanvasModule = {
|
21730 | __init__: [ 'moveCanvas' ],
|
21731 | moveCanvas: [ 'type', MoveCanvas ]
|
21732 | };
|
21733 |
|
21734 | |
21735 |
|
21736 |
|
21737 |
|
21738 | function log10(x) {
|
21739 | return Math.log(x) / Math.log(10);
|
21740 | }
|
21741 |
|
21742 | |
21743 |
|
21744 |
|
21745 |
|
21746 |
|
21747 |
|
21748 |
|
21749 | function getStepSize(range, steps) {
|
21750 |
|
21751 | var minLinearRange = log10(range.min),
|
21752 | maxLinearRange = log10(range.max);
|
21753 |
|
21754 | var absoluteLinearRange = Math.abs(minLinearRange) + Math.abs(maxLinearRange);
|
21755 |
|
21756 | return absoluteLinearRange / steps;
|
21757 | }
|
21758 |
|
21759 | function cap(range, scale) {
|
21760 | return Math.max(range.min, Math.min(range.max, scale));
|
21761 | }
|
21762 |
|
21763 | var sign = Math.sign || function(n) {
|
21764 | return n >= 0 ? 1 : -1;
|
21765 | };
|
21766 |
|
21767 | var RANGE = { min: 0.2, max: 4 },
|
21768 | NUM_STEPS = 10;
|
21769 |
|
21770 | var DELTA_THRESHOLD = 0.1;
|
21771 |
|
21772 | var DEFAULT_SCALE = 0.75;
|
21773 |
|
21774 | |
21775 |
|
21776 |
|
21777 |
|
21778 |
|
21779 |
|
21780 |
|
21781 |
|
21782 |
|
21783 |
|
21784 |
|
21785 |
|
21786 |
|
21787 | function ZoomScroll(config, eventBus, canvas) {
|
21788 |
|
21789 | config = config || {};
|
21790 |
|
21791 | this._enabled = false;
|
21792 |
|
21793 | this._canvas = canvas;
|
21794 | this._container = canvas._container;
|
21795 |
|
21796 | this._handleWheel = bind(this._handleWheel, this);
|
21797 |
|
21798 | this._totalDelta = 0;
|
21799 | this._scale = config.scale || DEFAULT_SCALE;
|
21800 |
|
21801 | var self = this;
|
21802 |
|
21803 | eventBus.on('canvas.init', function(e) {
|
21804 | self._init(config.enabled !== false);
|
21805 | });
|
21806 | }
|
21807 |
|
21808 | ZoomScroll.$inject = [
|
21809 | 'config.zoomScroll',
|
21810 | 'eventBus',
|
21811 | 'canvas'
|
21812 | ];
|
21813 |
|
21814 | ZoomScroll.prototype.scroll = function scroll(delta) {
|
21815 | this._canvas.scroll(delta);
|
21816 | };
|
21817 |
|
21818 |
|
21819 | ZoomScroll.prototype.reset = function reset() {
|
21820 | this._canvas.zoom('fit-viewport');
|
21821 | };
|
21822 |
|
21823 | |
21824 |
|
21825 |
|
21826 |
|
21827 |
|
21828 |
|
21829 | ZoomScroll.prototype.zoom = function zoom(delta, position) {
|
21830 |
|
21831 |
|
21832 | var stepSize = getStepSize(RANGE, NUM_STEPS * 2);
|
21833 |
|
21834 |
|
21835 | this._totalDelta += delta;
|
21836 |
|
21837 | if (Math.abs(this._totalDelta) > DELTA_THRESHOLD) {
|
21838 | this._zoom(delta, position, stepSize);
|
21839 |
|
21840 |
|
21841 | this._totalDelta = 0;
|
21842 | }
|
21843 | };
|
21844 |
|
21845 |
|
21846 | ZoomScroll.prototype._handleWheel = function handleWheel(event) {
|
21847 |
|
21848 |
|
21849 | if (closest(event.target, '.djs-scrollable', true)) {
|
21850 | return;
|
21851 | }
|
21852 |
|
21853 | var element = this._container;
|
21854 |
|
21855 | event.preventDefault();
|
21856 |
|
21857 |
|
21858 |
|
21859 |
|
21860 | var isZoom = event.ctrlKey;
|
21861 |
|
21862 | var isHorizontalScroll = event.shiftKey;
|
21863 |
|
21864 | var factor = -1 * this._scale,
|
21865 | delta;
|
21866 |
|
21867 | if (isZoom) {
|
21868 | factor *= event.deltaMode === 0 ? 0.020 : 0.32;
|
21869 | } else {
|
21870 | factor *= event.deltaMode === 0 ? 1.0 : 16.0;
|
21871 | }
|
21872 |
|
21873 | if (isZoom) {
|
21874 | var elementRect = element.getBoundingClientRect();
|
21875 |
|
21876 | var offset = {
|
21877 | x: event.clientX - elementRect.left,
|
21878 | y: event.clientY - elementRect.top
|
21879 | };
|
21880 |
|
21881 | delta = (
|
21882 | Math.sqrt(
|
21883 | Math.pow(event.deltaY, 2) +
|
21884 | Math.pow(event.deltaX, 2)
|
21885 | ) * sign(event.deltaY) * factor
|
21886 | );
|
21887 |
|
21888 |
|
21889 | this.zoom(delta, offset);
|
21890 | } else {
|
21891 |
|
21892 | if (isHorizontalScroll) {
|
21893 | delta = {
|
21894 | dx: factor * event.deltaY,
|
21895 | dy: 0
|
21896 | };
|
21897 | } else {
|
21898 | delta = {
|
21899 | dx: factor * event.deltaX,
|
21900 | dy: factor * event.deltaY
|
21901 | };
|
21902 | }
|
21903 |
|
21904 | this.scroll(delta);
|
21905 | }
|
21906 | };
|
21907 |
|
21908 | |
21909 |
|
21910 |
|
21911 |
|
21912 |
|
21913 |
|
21914 | ZoomScroll.prototype.stepZoom = function stepZoom(delta, position) {
|
21915 |
|
21916 | var stepSize = getStepSize(RANGE, NUM_STEPS);
|
21917 |
|
21918 | this._zoom(delta, position, stepSize);
|
21919 | };
|
21920 |
|
21921 |
|
21922 | |
21923 |
|
21924 |
|
21925 |
|
21926 |
|
21927 |
|
21928 |
|
21929 | ZoomScroll.prototype._zoom = function(delta, position, stepSize) {
|
21930 | var canvas = this._canvas;
|
21931 |
|
21932 | var direction = delta > 0 ? 1 : -1;
|
21933 |
|
21934 | var currentLinearZoomLevel = log10(canvas.zoom());
|
21935 |
|
21936 |
|
21937 | var newLinearZoomLevel = Math.round(currentLinearZoomLevel / stepSize) * stepSize;
|
21938 |
|
21939 |
|
21940 | newLinearZoomLevel += stepSize * direction;
|
21941 |
|
21942 |
|
21943 |
|
21944 | var newLogZoomLevel = Math.pow(10, newLinearZoomLevel);
|
21945 |
|
21946 | canvas.zoom(cap(RANGE, newLogZoomLevel), position);
|
21947 | };
|
21948 |
|
21949 |
|
21950 | |
21951 |
|
21952 |
|
21953 |
|
21954 |
|
21955 | ZoomScroll.prototype.toggle = function toggle(newEnabled) {
|
21956 |
|
21957 | var element = this._container;
|
21958 | var handleWheel = this._handleWheel;
|
21959 |
|
21960 | var oldEnabled = this._enabled;
|
21961 |
|
21962 | if (typeof newEnabled === 'undefined') {
|
21963 | newEnabled = !oldEnabled;
|
21964 | }
|
21965 |
|
21966 |
|
21967 | if (oldEnabled !== newEnabled) {
|
21968 |
|
21969 |
|
21970 |
|
21971 | componentEvent[newEnabled ? 'bind' : 'unbind'](element, 'wheel', handleWheel, false);
|
21972 | }
|
21973 |
|
21974 | this._enabled = newEnabled;
|
21975 |
|
21976 | return newEnabled;
|
21977 | };
|
21978 |
|
21979 |
|
21980 | ZoomScroll.prototype._init = function(newEnabled) {
|
21981 | this.toggle(newEnabled);
|
21982 | };
|
21983 |
|
21984 | var ZoomScrollModule = {
|
21985 | __init__: [ 'zoomScroll' ],
|
21986 | zoomScroll: [ 'type', ZoomScroll ]
|
21987 | };
|
21988 |
|
21989 | |
21990 |
|
21991 |
|
21992 |
|
21993 |
|
21994 | function NavigatedViewer(options) {
|
21995 | Viewer.call(this, options);
|
21996 | }
|
21997 |
|
21998 | inherits_browser(NavigatedViewer, Viewer);
|
21999 |
|
22000 | NavigatedViewer.prototype._navigationModules = [
|
22001 | KeyboardMoveModule,
|
22002 | MoveCanvasModule,
|
22003 | ZoomScrollModule
|
22004 | ];
|
22005 |
|
22006 | NavigatedViewer.prototype._modules = [].concat(
|
22007 | NavigatedViewer.prototype._modules,
|
22008 | NavigatedViewer.prototype._navigationModules);
|
22009 |
|
22010 | var hammer = createCommonjsModule(function (module) {
|
22011 | |
22012 |
|
22013 |
|
22014 |
|
22015 |
|
22016 | (function(window, document, exportName, undefined$1) {
|
22017 |
|
22018 | var VENDOR_PREFIXES = ['', 'webkit', 'Moz', 'MS', 'ms', 'o'];
|
22019 | var TEST_ELEMENT = document.createElement('div');
|
22020 |
|
22021 | var TYPE_FUNCTION = 'function';
|
22022 |
|
22023 | var round = Math.round;
|
22024 | var abs = Math.abs;
|
22025 | var now = Date.now;
|
22026 |
|
22027 | |
22028 |
|
22029 |
|
22030 |
|
22031 |
|
22032 |
|
22033 |
|
22034 | function setTimeoutContext(fn, timeout, context) {
|
22035 | return setTimeout(bindFn(fn, context), timeout);
|
22036 | }
|
22037 |
|
22038 | |
22039 |
|
22040 |
|
22041 |
|
22042 |
|
22043 |
|
22044 |
|
22045 |
|
22046 |
|
22047 | function invokeArrayArg(arg, fn, context) {
|
22048 | if (Array.isArray(arg)) {
|
22049 | each(arg, context[fn], context);
|
22050 | return true;
|
22051 | }
|
22052 | return false;
|
22053 | }
|
22054 |
|
22055 | |
22056 |
|
22057 |
|
22058 |
|
22059 |
|
22060 |
|
22061 | function each(obj, iterator, context) {
|
22062 | var i;
|
22063 |
|
22064 | if (!obj) {
|
22065 | return;
|
22066 | }
|
22067 |
|
22068 | if (obj.forEach) {
|
22069 | obj.forEach(iterator, context);
|
22070 | } else if (obj.length !== undefined$1) {
|
22071 | i = 0;
|
22072 | while (i < obj.length) {
|
22073 | iterator.call(context, obj[i], i, obj);
|
22074 | i++;
|
22075 | }
|
22076 | } else {
|
22077 | for (i in obj) {
|
22078 | obj.hasOwnProperty(i) && iterator.call(context, obj[i], i, obj);
|
22079 | }
|
22080 | }
|
22081 | }
|
22082 |
|
22083 | |
22084 |
|
22085 |
|
22086 |
|
22087 |
|
22088 |
|
22089 |
|
22090 | function deprecate(method, name, message) {
|
22091 | var deprecationMessage = 'DEPRECATED METHOD: ' + name + '\n' + message + ' AT \n';
|
22092 | return function() {
|
22093 | var e = new Error('get-stack-trace');
|
22094 | var stack = e && e.stack ? e.stack.replace(/^[^\(]+?[\n$]/gm, '')
|
22095 | .replace(/^\s+at\s+/gm, '')
|
22096 | .replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@') : 'Unknown Stack Trace';
|
22097 |
|
22098 | var log = window.console && (window.console.warn || window.console.log);
|
22099 | if (log) {
|
22100 | log.call(window.console, deprecationMessage, stack);
|
22101 | }
|
22102 | return method.apply(this, arguments);
|
22103 | };
|
22104 | }
|
22105 |
|
22106 | |
22107 |
|
22108 |
|
22109 |
|
22110 |
|
22111 |
|
22112 |
|
22113 | var assign;
|
22114 | if (typeof Object.assign !== 'function') {
|
22115 | assign = function assign(target) {
|
22116 | if (target === undefined$1 || target === null) {
|
22117 | throw new TypeError('Cannot convert undefined or null to object');
|
22118 | }
|
22119 |
|
22120 | var output = Object(target);
|
22121 | for (var index = 1; index < arguments.length; index++) {
|
22122 | var source = arguments[index];
|
22123 | if (source !== undefined$1 && source !== null) {
|
22124 | for (var nextKey in source) {
|
22125 | if (source.hasOwnProperty(nextKey)) {
|
22126 | output[nextKey] = source[nextKey];
|
22127 | }
|
22128 | }
|
22129 | }
|
22130 | }
|
22131 | return output;
|
22132 | };
|
22133 | } else {
|
22134 | assign = Object.assign;
|
22135 | }
|
22136 |
|
22137 | |
22138 |
|
22139 |
|
22140 |
|
22141 |
|
22142 |
|
22143 |
|
22144 |
|
22145 | var extend = deprecate(function extend(dest, src, merge) {
|
22146 | var keys = Object.keys(src);
|
22147 | var i = 0;
|
22148 | while (i < keys.length) {
|
22149 | if (!merge || (merge && dest[keys[i]] === undefined$1)) {
|
22150 | dest[keys[i]] = src[keys[i]];
|
22151 | }
|
22152 | i++;
|
22153 | }
|
22154 | return dest;
|
22155 | }, 'extend', 'Use `assign`.');
|
22156 |
|
22157 | |
22158 |
|
22159 |
|
22160 |
|
22161 |
|
22162 |
|
22163 |
|
22164 | var merge = deprecate(function merge(dest, src) {
|
22165 | return extend(dest, src, true);
|
22166 | }, 'merge', 'Use `assign`.');
|
22167 |
|
22168 | |
22169 |
|
22170 |
|
22171 |
|
22172 |
|
22173 |
|
22174 | function inherit(child, base, properties) {
|
22175 | var baseP = base.prototype,
|
22176 | childP;
|
22177 |
|
22178 | childP = child.prototype = Object.create(baseP);
|
22179 | childP.constructor = child;
|
22180 | childP._super = baseP;
|
22181 |
|
22182 | if (properties) {
|
22183 | assign(childP, properties);
|
22184 | }
|
22185 | }
|
22186 |
|
22187 | |
22188 |
|
22189 |
|
22190 |
|
22191 |
|
22192 |
|
22193 | function bindFn(fn, context) {
|
22194 | return function boundFn() {
|
22195 | return fn.apply(context, arguments);
|
22196 | };
|
22197 | }
|
22198 |
|
22199 | |
22200 |
|
22201 |
|
22202 |
|
22203 |
|
22204 |
|
22205 |
|
22206 | function boolOrFn(val, args) {
|
22207 | if (typeof val == TYPE_FUNCTION) {
|
22208 | return val.apply(args ? args[0] || undefined$1 : undefined$1, args);
|
22209 | }
|
22210 | return val;
|
22211 | }
|
22212 |
|
22213 | |
22214 |
|
22215 |
|
22216 |
|
22217 |
|
22218 |
|
22219 | function ifUndefined(val1, val2) {
|
22220 | return (val1 === undefined$1) ? val2 : val1;
|
22221 | }
|
22222 |
|
22223 | |
22224 |
|
22225 |
|
22226 |
|
22227 |
|
22228 |
|
22229 | function addEventListeners(target, types, handler) {
|
22230 | each(splitStr(types), function(type) {
|
22231 | target.addEventListener(type, handler, false);
|
22232 | });
|
22233 | }
|
22234 |
|
22235 | |
22236 |
|
22237 |
|
22238 |
|
22239 |
|
22240 |
|
22241 | function removeEventListeners(target, types, handler) {
|
22242 | each(splitStr(types), function(type) {
|
22243 | target.removeEventListener(type, handler, false);
|
22244 | });
|
22245 | }
|
22246 |
|
22247 | |
22248 |
|
22249 |
|
22250 |
|
22251 |
|
22252 |
|
22253 |
|
22254 | function hasParent(node, parent) {
|
22255 | while (node) {
|
22256 | if (node == parent) {
|
22257 | return true;
|
22258 | }
|
22259 | node = node.parentNode;
|
22260 | }
|
22261 | return false;
|
22262 | }
|
22263 |
|
22264 | |
22265 |
|
22266 |
|
22267 |
|
22268 |
|
22269 |
|
22270 | function inStr(str, find) {
|
22271 | return str.indexOf(find) > -1;
|
22272 | }
|
22273 |
|
22274 | |
22275 |
|
22276 |
|
22277 |
|
22278 |
|
22279 | function splitStr(str) {
|
22280 | return str.trim().split(/\s+/g);
|
22281 | }
|
22282 |
|
22283 | |
22284 |
|
22285 |
|
22286 |
|
22287 |
|
22288 |
|
22289 |
|
22290 | function inArray(src, find, findByKey) {
|
22291 | if (src.indexOf && !findByKey) {
|
22292 | return src.indexOf(find);
|
22293 | } else {
|
22294 | var i = 0;
|
22295 | while (i < src.length) {
|
22296 | if ((findByKey && src[i][findByKey] == find) || (!findByKey && src[i] === find)) {
|
22297 | return i;
|
22298 | }
|
22299 | i++;
|
22300 | }
|
22301 | return -1;
|
22302 | }
|
22303 | }
|
22304 |
|
22305 | |
22306 |
|
22307 |
|
22308 |
|
22309 |
|
22310 | function toArray(obj) {
|
22311 | return Array.prototype.slice.call(obj, 0);
|
22312 | }
|
22313 |
|
22314 | |
22315 |
|
22316 |
|
22317 |
|
22318 |
|
22319 |
|
22320 |
|
22321 | function uniqueArray(src, key, sort) {
|
22322 | var results = [];
|
22323 | var values = [];
|
22324 | var i = 0;
|
22325 |
|
22326 | while (i < src.length) {
|
22327 | var val = key ? src[i][key] : src[i];
|
22328 | if (inArray(values, val) < 0) {
|
22329 | results.push(src[i]);
|
22330 | }
|
22331 | values[i] = val;
|
22332 | i++;
|
22333 | }
|
22334 |
|
22335 | if (sort) {
|
22336 | if (!key) {
|
22337 | results = results.sort();
|
22338 | } else {
|
22339 | results = results.sort(function sortUniqueArray(a, b) {
|
22340 | return a[key] > b[key];
|
22341 | });
|
22342 | }
|
22343 | }
|
22344 |
|
22345 | return results;
|
22346 | }
|
22347 |
|
22348 | |
22349 |
|
22350 |
|
22351 |
|
22352 |
|
22353 |
|
22354 | function prefixed(obj, property) {
|
22355 | var prefix, prop;
|
22356 | var camelProp = property[0].toUpperCase() + property.slice(1);
|
22357 |
|
22358 | var i = 0;
|
22359 | while (i < VENDOR_PREFIXES.length) {
|
22360 | prefix = VENDOR_PREFIXES[i];
|
22361 | prop = (prefix) ? prefix + camelProp : property;
|
22362 |
|
22363 | if (prop in obj) {
|
22364 | return prop;
|
22365 | }
|
22366 | i++;
|
22367 | }
|
22368 | return undefined$1;
|
22369 | }
|
22370 |
|
22371 | |
22372 |
|
22373 |
|
22374 |
|
22375 | var _uniqueId = 1;
|
22376 | function uniqueId() {
|
22377 | return _uniqueId++;
|
22378 | }
|
22379 |
|
22380 | |
22381 |
|
22382 |
|
22383 |
|
22384 |
|
22385 | function getWindowForElement(element) {
|
22386 | var doc = element.ownerDocument || element;
|
22387 | return (doc.defaultView || doc.parentWindow || window);
|
22388 | }
|
22389 |
|
22390 | var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
|
22391 |
|
22392 | var SUPPORT_TOUCH = ('ontouchstart' in window);
|
22393 | var SUPPORT_POINTER_EVENTS = prefixed(window, 'PointerEvent') !== undefined$1;
|
22394 | var SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent);
|
22395 |
|
22396 | var INPUT_TYPE_TOUCH = 'touch';
|
22397 | var INPUT_TYPE_PEN = 'pen';
|
22398 | var INPUT_TYPE_MOUSE = 'mouse';
|
22399 | var INPUT_TYPE_KINECT = 'kinect';
|
22400 |
|
22401 | var COMPUTE_INTERVAL = 25;
|
22402 |
|
22403 | var INPUT_START = 1;
|
22404 | var INPUT_MOVE = 2;
|
22405 | var INPUT_END = 4;
|
22406 | var INPUT_CANCEL = 8;
|
22407 |
|
22408 | var DIRECTION_NONE = 1;
|
22409 | var DIRECTION_LEFT = 2;
|
22410 | var DIRECTION_RIGHT = 4;
|
22411 | var DIRECTION_UP = 8;
|
22412 | var DIRECTION_DOWN = 16;
|
22413 |
|
22414 | var DIRECTION_HORIZONTAL = DIRECTION_LEFT | DIRECTION_RIGHT;
|
22415 | var DIRECTION_VERTICAL = DIRECTION_UP | DIRECTION_DOWN;
|
22416 | var DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL;
|
22417 |
|
22418 | var PROPS_XY = ['x', 'y'];
|
22419 | var PROPS_CLIENT_XY = ['clientX', 'clientY'];
|
22420 |
|
22421 | |
22422 |
|
22423 |
|
22424 |
|
22425 |
|
22426 |
|
22427 |
|
22428 | function Input(manager, callback) {
|
22429 | var self = this;
|
22430 | this.manager = manager;
|
22431 | this.callback = callback;
|
22432 | this.element = manager.element;
|
22433 | this.target = manager.options.inputTarget;
|
22434 |
|
22435 |
|
22436 |
|
22437 | this.domHandler = function(ev) {
|
22438 | if (boolOrFn(manager.options.enable, [manager])) {
|
22439 | self.handler(ev);
|
22440 | }
|
22441 | };
|
22442 |
|
22443 | this.init();
|
22444 |
|
22445 | }
|
22446 |
|
22447 | Input.prototype = {
|
22448 | |
22449 |
|
22450 |
|
22451 |
|
22452 | handler: function() { },
|
22453 |
|
22454 | |
22455 |
|
22456 |
|
22457 | init: function() {
|
22458 | this.evEl && addEventListeners(this.element, this.evEl, this.domHandler);
|
22459 | this.evTarget && addEventListeners(this.target, this.evTarget, this.domHandler);
|
22460 | this.evWin && addEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
|
22461 | },
|
22462 |
|
22463 | |
22464 |
|
22465 |
|
22466 | destroy: function() {
|
22467 | this.evEl && removeEventListeners(this.element, this.evEl, this.domHandler);
|
22468 | this.evTarget && removeEventListeners(this.target, this.evTarget, this.domHandler);
|
22469 | this.evWin && removeEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
|
22470 | }
|
22471 | };
|
22472 |
|
22473 | |
22474 |
|
22475 |
|
22476 |
|
22477 |
|
22478 |
|
22479 | function createInputInstance(manager) {
|
22480 | var Type;
|
22481 | var inputClass = manager.options.inputClass;
|
22482 |
|
22483 | if (inputClass) {
|
22484 | Type = inputClass;
|
22485 | } else if (SUPPORT_POINTER_EVENTS) {
|
22486 | Type = PointerEventInput;
|
22487 | } else if (SUPPORT_ONLY_TOUCH) {
|
22488 | Type = TouchInput;
|
22489 | } else if (!SUPPORT_TOUCH) {
|
22490 | Type = MouseInput;
|
22491 | } else {
|
22492 | Type = TouchMouseInput;
|
22493 | }
|
22494 | return new (Type)(manager, inputHandler);
|
22495 | }
|
22496 |
|
22497 | |
22498 |
|
22499 |
|
22500 |
|
22501 |
|
22502 |
|
22503 | function inputHandler(manager, eventType, input) {
|
22504 | var pointersLen = input.pointers.length;
|
22505 | var changedPointersLen = input.changedPointers.length;
|
22506 | var isFirst = (eventType & INPUT_START && (pointersLen - changedPointersLen === 0));
|
22507 | var isFinal = (eventType & (INPUT_END | INPUT_CANCEL) && (pointersLen - changedPointersLen === 0));
|
22508 |
|
22509 | input.isFirst = !!isFirst;
|
22510 | input.isFinal = !!isFinal;
|
22511 |
|
22512 | if (isFirst) {
|
22513 | manager.session = {};
|
22514 | }
|
22515 |
|
22516 |
|
22517 |
|
22518 | input.eventType = eventType;
|
22519 |
|
22520 |
|
22521 | computeInputData(manager, input);
|
22522 |
|
22523 |
|
22524 | manager.emit('hammer.input', input);
|
22525 |
|
22526 | manager.recognize(input);
|
22527 | manager.session.prevInput = input;
|
22528 | }
|
22529 |
|
22530 | |
22531 |
|
22532 |
|
22533 |
|
22534 |
|
22535 | function computeInputData(manager, input) {
|
22536 | var session = manager.session;
|
22537 | var pointers = input.pointers;
|
22538 | var pointersLength = pointers.length;
|
22539 |
|
22540 |
|
22541 | if (!session.firstInput) {
|
22542 | session.firstInput = simpleCloneInputData(input);
|
22543 | }
|
22544 |
|
22545 |
|
22546 | if (pointersLength > 1 && !session.firstMultiple) {
|
22547 | session.firstMultiple = simpleCloneInputData(input);
|
22548 | } else if (pointersLength === 1) {
|
22549 | session.firstMultiple = false;
|
22550 | }
|
22551 |
|
22552 | var firstInput = session.firstInput;
|
22553 | var firstMultiple = session.firstMultiple;
|
22554 | var offsetCenter = firstMultiple ? firstMultiple.center : firstInput.center;
|
22555 |
|
22556 | var center = input.center = getCenter(pointers);
|
22557 | input.timeStamp = now();
|
22558 | input.deltaTime = input.timeStamp - firstInput.timeStamp;
|
22559 |
|
22560 | input.angle = getAngle(offsetCenter, center);
|
22561 | input.distance = getDistance(offsetCenter, center);
|
22562 |
|
22563 | computeDeltaXY(session, input);
|
22564 | input.offsetDirection = getDirection(input.deltaX, input.deltaY);
|
22565 |
|
22566 | var overallVelocity = getVelocity(input.deltaTime, input.deltaX, input.deltaY);
|
22567 | input.overallVelocityX = overallVelocity.x;
|
22568 | input.overallVelocityY = overallVelocity.y;
|
22569 | input.overallVelocity = (abs(overallVelocity.x) > abs(overallVelocity.y)) ? overallVelocity.x : overallVelocity.y;
|
22570 |
|
22571 | input.scale = firstMultiple ? getScale(firstMultiple.pointers, pointers) : 1;
|
22572 | input.rotation = firstMultiple ? getRotation(firstMultiple.pointers, pointers) : 0;
|
22573 |
|
22574 | input.maxPointers = !session.prevInput ? input.pointers.length : ((input.pointers.length >
|
22575 | session.prevInput.maxPointers) ? input.pointers.length : session.prevInput.maxPointers);
|
22576 |
|
22577 | computeIntervalInputData(session, input);
|
22578 |
|
22579 |
|
22580 | var target = manager.element;
|
22581 | if (hasParent(input.srcEvent.target, target)) {
|
22582 | target = input.srcEvent.target;
|
22583 | }
|
22584 | input.target = target;
|
22585 | }
|
22586 |
|
22587 | function computeDeltaXY(session, input) {
|
22588 | var center = input.center;
|
22589 | var offset = session.offsetDelta || {};
|
22590 | var prevDelta = session.prevDelta || {};
|
22591 | var prevInput = session.prevInput || {};
|
22592 |
|
22593 | if (input.eventType === INPUT_START || prevInput.eventType === INPUT_END) {
|
22594 | prevDelta = session.prevDelta = {
|
22595 | x: prevInput.deltaX || 0,
|
22596 | y: prevInput.deltaY || 0
|
22597 | };
|
22598 |
|
22599 | offset = session.offsetDelta = {
|
22600 | x: center.x,
|
22601 | y: center.y
|
22602 | };
|
22603 | }
|
22604 |
|
22605 | input.deltaX = prevDelta.x + (center.x - offset.x);
|
22606 | input.deltaY = prevDelta.y + (center.y - offset.y);
|
22607 | }
|
22608 |
|
22609 | |
22610 |
|
22611 |
|
22612 |
|
22613 |
|
22614 | function computeIntervalInputData(session, input) {
|
22615 | var last = session.lastInterval || input,
|
22616 | deltaTime = input.timeStamp - last.timeStamp,
|
22617 | velocity, velocityX, velocityY, direction;
|
22618 |
|
22619 | if (input.eventType != INPUT_CANCEL && (deltaTime > COMPUTE_INTERVAL || last.velocity === undefined$1)) {
|
22620 | var deltaX = input.deltaX - last.deltaX;
|
22621 | var deltaY = input.deltaY - last.deltaY;
|
22622 |
|
22623 | var v = getVelocity(deltaTime, deltaX, deltaY);
|
22624 | velocityX = v.x;
|
22625 | velocityY = v.y;
|
22626 | velocity = (abs(v.x) > abs(v.y)) ? v.x : v.y;
|
22627 | direction = getDirection(deltaX, deltaY);
|
22628 |
|
22629 | session.lastInterval = input;
|
22630 | } else {
|
22631 |
|
22632 | velocity = last.velocity;
|
22633 | velocityX = last.velocityX;
|
22634 | velocityY = last.velocityY;
|
22635 | direction = last.direction;
|
22636 | }
|
22637 |
|
22638 | input.velocity = velocity;
|
22639 | input.velocityX = velocityX;
|
22640 | input.velocityY = velocityY;
|
22641 | input.direction = direction;
|
22642 | }
|
22643 |
|
22644 | |
22645 |
|
22646 |
|
22647 |
|
22648 |
|
22649 | function simpleCloneInputData(input) {
|
22650 |
|
22651 |
|
22652 | var pointers = [];
|
22653 | var i = 0;
|
22654 | while (i < input.pointers.length) {
|
22655 | pointers[i] = {
|
22656 | clientX: round(input.pointers[i].clientX),
|
22657 | clientY: round(input.pointers[i].clientY)
|
22658 | };
|
22659 | i++;
|
22660 | }
|
22661 |
|
22662 | return {
|
22663 | timeStamp: now(),
|
22664 | pointers: pointers,
|
22665 | center: getCenter(pointers),
|
22666 | deltaX: input.deltaX,
|
22667 | deltaY: input.deltaY
|
22668 | };
|
22669 | }
|
22670 |
|
22671 | |
22672 |
|
22673 |
|
22674 |
|
22675 |
|
22676 | function getCenter(pointers) {
|
22677 | var pointersLength = pointers.length;
|
22678 |
|
22679 |
|
22680 | if (pointersLength === 1) {
|
22681 | return {
|
22682 | x: round(pointers[0].clientX),
|
22683 | y: round(pointers[0].clientY)
|
22684 | };
|
22685 | }
|
22686 |
|
22687 | var x = 0, y = 0, i = 0;
|
22688 | while (i < pointersLength) {
|
22689 | x += pointers[i].clientX;
|
22690 | y += pointers[i].clientY;
|
22691 | i++;
|
22692 | }
|
22693 |
|
22694 | return {
|
22695 | x: round(x / pointersLength),
|
22696 | y: round(y / pointersLength)
|
22697 | };
|
22698 | }
|
22699 |
|
22700 | |
22701 |
|
22702 |
|
22703 |
|
22704 |
|
22705 |
|
22706 |
|
22707 | function getVelocity(deltaTime, x, y) {
|
22708 | return {
|
22709 | x: x / deltaTime || 0,
|
22710 | y: y / deltaTime || 0
|
22711 | };
|
22712 | }
|
22713 |
|
22714 | |
22715 |
|
22716 |
|
22717 |
|
22718 |
|
22719 |
|
22720 | function getDirection(x, y) {
|
22721 | if (x === y) {
|
22722 | return DIRECTION_NONE;
|
22723 | }
|
22724 |
|
22725 | if (abs(x) >= abs(y)) {
|
22726 | return x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
22727 | }
|
22728 | return y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
|
22729 | }
|
22730 |
|
22731 | |
22732 |
|
22733 |
|
22734 |
|
22735 |
|
22736 |
|
22737 |
|
22738 | function getDistance(p1, p2, props) {
|
22739 | if (!props) {
|
22740 | props = PROPS_XY;
|
22741 | }
|
22742 | var x = p2[props[0]] - p1[props[0]],
|
22743 | y = p2[props[1]] - p1[props[1]];
|
22744 |
|
22745 | return Math.sqrt((x * x) + (y * y));
|
22746 | }
|
22747 |
|
22748 | |
22749 |
|
22750 |
|
22751 |
|
22752 |
|
22753 |
|
22754 |
|
22755 | function getAngle(p1, p2, props) {
|
22756 | if (!props) {
|
22757 | props = PROPS_XY;
|
22758 | }
|
22759 | var x = p2[props[0]] - p1[props[0]],
|
22760 | y = p2[props[1]] - p1[props[1]];
|
22761 | return Math.atan2(y, x) * 180 / Math.PI;
|
22762 | }
|
22763 |
|
22764 | |
22765 |
|
22766 |
|
22767 |
|
22768 |
|
22769 |
|
22770 | function getRotation(start, end) {
|
22771 | return getAngle(end[1], end[0], PROPS_CLIENT_XY) + getAngle(start[1], start[0], PROPS_CLIENT_XY);
|
22772 | }
|
22773 |
|
22774 | |
22775 |
|
22776 |
|
22777 |
|
22778 |
|
22779 |
|
22780 |
|
22781 | function getScale(start, end) {
|
22782 | return getDistance(end[0], end[1], PROPS_CLIENT_XY) / getDistance(start[0], start[1], PROPS_CLIENT_XY);
|
22783 | }
|
22784 |
|
22785 | var MOUSE_INPUT_MAP = {
|
22786 | mousedown: INPUT_START,
|
22787 | mousemove: INPUT_MOVE,
|
22788 | mouseup: INPUT_END
|
22789 | };
|
22790 |
|
22791 | var MOUSE_ELEMENT_EVENTS = 'mousedown';
|
22792 | var MOUSE_WINDOW_EVENTS = 'mousemove mouseup';
|
22793 |
|
22794 | |
22795 |
|
22796 |
|
22797 |
|
22798 |
|
22799 | function MouseInput() {
|
22800 | this.evEl = MOUSE_ELEMENT_EVENTS;
|
22801 | this.evWin = MOUSE_WINDOW_EVENTS;
|
22802 |
|
22803 | this.pressed = false;
|
22804 |
|
22805 | Input.apply(this, arguments);
|
22806 | }
|
22807 |
|
22808 | inherit(MouseInput, Input, {
|
22809 | |
22810 |
|
22811 |
|
22812 |
|
22813 | handler: function MEhandler(ev) {
|
22814 | var eventType = MOUSE_INPUT_MAP[ev.type];
|
22815 |
|
22816 |
|
22817 | if (eventType & INPUT_START && ev.button === 0) {
|
22818 | this.pressed = true;
|
22819 | }
|
22820 |
|
22821 | if (eventType & INPUT_MOVE && ev.which !== 1) {
|
22822 | eventType = INPUT_END;
|
22823 | }
|
22824 |
|
22825 |
|
22826 | if (!this.pressed) {
|
22827 | return;
|
22828 | }
|
22829 |
|
22830 | if (eventType & INPUT_END) {
|
22831 | this.pressed = false;
|
22832 | }
|
22833 |
|
22834 | this.callback(this.manager, eventType, {
|
22835 | pointers: [ev],
|
22836 | changedPointers: [ev],
|
22837 | pointerType: INPUT_TYPE_MOUSE,
|
22838 | srcEvent: ev
|
22839 | });
|
22840 | }
|
22841 | });
|
22842 |
|
22843 | var POINTER_INPUT_MAP = {
|
22844 | pointerdown: INPUT_START,
|
22845 | pointermove: INPUT_MOVE,
|
22846 | pointerup: INPUT_END,
|
22847 | pointercancel: INPUT_CANCEL,
|
22848 | pointerout: INPUT_CANCEL
|
22849 | };
|
22850 |
|
22851 |
|
22852 | var IE10_POINTER_TYPE_ENUM = {
|
22853 | 2: INPUT_TYPE_TOUCH,
|
22854 | 3: INPUT_TYPE_PEN,
|
22855 | 4: INPUT_TYPE_MOUSE,
|
22856 | 5: INPUT_TYPE_KINECT
|
22857 | };
|
22858 |
|
22859 | var POINTER_ELEMENT_EVENTS = 'pointerdown';
|
22860 | var POINTER_WINDOW_EVENTS = 'pointermove pointerup pointercancel';
|
22861 |
|
22862 |
|
22863 | if (window.MSPointerEvent && !window.PointerEvent) {
|
22864 | POINTER_ELEMENT_EVENTS = 'MSPointerDown';
|
22865 | POINTER_WINDOW_EVENTS = 'MSPointerMove MSPointerUp MSPointerCancel';
|
22866 | }
|
22867 |
|
22868 | |
22869 |
|
22870 |
|
22871 |
|
22872 |
|
22873 | function PointerEventInput() {
|
22874 | this.evEl = POINTER_ELEMENT_EVENTS;
|
22875 | this.evWin = POINTER_WINDOW_EVENTS;
|
22876 |
|
22877 | Input.apply(this, arguments);
|
22878 |
|
22879 | this.store = (this.manager.session.pointerEvents = []);
|
22880 | }
|
22881 |
|
22882 | inherit(PointerEventInput, Input, {
|
22883 | |
22884 |
|
22885 |
|
22886 |
|
22887 | handler: function PEhandler(ev) {
|
22888 | var store = this.store;
|
22889 | var removePointer = false;
|
22890 |
|
22891 | var eventTypeNormalized = ev.type.toLowerCase().replace('ms', '');
|
22892 | var eventType = POINTER_INPUT_MAP[eventTypeNormalized];
|
22893 | var pointerType = IE10_POINTER_TYPE_ENUM[ev.pointerType] || ev.pointerType;
|
22894 |
|
22895 | var isTouch = (pointerType == INPUT_TYPE_TOUCH);
|
22896 |
|
22897 |
|
22898 | var storeIndex = inArray(store, ev.pointerId, 'pointerId');
|
22899 |
|
22900 |
|
22901 | if (eventType & INPUT_START && (ev.button === 0 || isTouch)) {
|
22902 | if (storeIndex < 0) {
|
22903 | store.push(ev);
|
22904 | storeIndex = store.length - 1;
|
22905 | }
|
22906 | } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
|
22907 | removePointer = true;
|
22908 | }
|
22909 |
|
22910 |
|
22911 | if (storeIndex < 0) {
|
22912 | return;
|
22913 | }
|
22914 |
|
22915 |
|
22916 | store[storeIndex] = ev;
|
22917 |
|
22918 | this.callback(this.manager, eventType, {
|
22919 | pointers: store,
|
22920 | changedPointers: [ev],
|
22921 | pointerType: pointerType,
|
22922 | srcEvent: ev
|
22923 | });
|
22924 |
|
22925 | if (removePointer) {
|
22926 |
|
22927 | store.splice(storeIndex, 1);
|
22928 | }
|
22929 | }
|
22930 | });
|
22931 |
|
22932 | var SINGLE_TOUCH_INPUT_MAP = {
|
22933 | touchstart: INPUT_START,
|
22934 | touchmove: INPUT_MOVE,
|
22935 | touchend: INPUT_END,
|
22936 | touchcancel: INPUT_CANCEL
|
22937 | };
|
22938 |
|
22939 | var SINGLE_TOUCH_TARGET_EVENTS = 'touchstart';
|
22940 | var SINGLE_TOUCH_WINDOW_EVENTS = 'touchstart touchmove touchend touchcancel';
|
22941 |
|
22942 | |
22943 |
|
22944 |
|
22945 |
|
22946 |
|
22947 | function SingleTouchInput() {
|
22948 | this.evTarget = SINGLE_TOUCH_TARGET_EVENTS;
|
22949 | this.evWin = SINGLE_TOUCH_WINDOW_EVENTS;
|
22950 | this.started = false;
|
22951 |
|
22952 | Input.apply(this, arguments);
|
22953 | }
|
22954 |
|
22955 | inherit(SingleTouchInput, Input, {
|
22956 | handler: function TEhandler(ev) {
|
22957 | var type = SINGLE_TOUCH_INPUT_MAP[ev.type];
|
22958 |
|
22959 |
|
22960 | if (type === INPUT_START) {
|
22961 | this.started = true;
|
22962 | }
|
22963 |
|
22964 | if (!this.started) {
|
22965 | return;
|
22966 | }
|
22967 |
|
22968 | var touches = normalizeSingleTouches.call(this, ev, type);
|
22969 |
|
22970 |
|
22971 | if (type & (INPUT_END | INPUT_CANCEL) && touches[0].length - touches[1].length === 0) {
|
22972 | this.started = false;
|
22973 | }
|
22974 |
|
22975 | this.callback(this.manager, type, {
|
22976 | pointers: touches[0],
|
22977 | changedPointers: touches[1],
|
22978 | pointerType: INPUT_TYPE_TOUCH,
|
22979 | srcEvent: ev
|
22980 | });
|
22981 | }
|
22982 | });
|
22983 |
|
22984 | |
22985 |
|
22986 |
|
22987 |
|
22988 |
|
22989 |
|
22990 | function normalizeSingleTouches(ev, type) {
|
22991 | var all = toArray(ev.touches);
|
22992 | var changed = toArray(ev.changedTouches);
|
22993 |
|
22994 | if (type & (INPUT_END | INPUT_CANCEL)) {
|
22995 | all = uniqueArray(all.concat(changed), 'identifier', true);
|
22996 | }
|
22997 |
|
22998 | return [all, changed];
|
22999 | }
|
23000 |
|
23001 | var TOUCH_INPUT_MAP = {
|
23002 | touchstart: INPUT_START,
|
23003 | touchmove: INPUT_MOVE,
|
23004 | touchend: INPUT_END,
|
23005 | touchcancel: INPUT_CANCEL
|
23006 | };
|
23007 |
|
23008 | var TOUCH_TARGET_EVENTS = 'touchstart touchmove touchend touchcancel';
|
23009 |
|
23010 | |
23011 |
|
23012 |
|
23013 |
|
23014 |
|
23015 | function TouchInput() {
|
23016 | this.evTarget = TOUCH_TARGET_EVENTS;
|
23017 | this.targetIds = {};
|
23018 |
|
23019 | Input.apply(this, arguments);
|
23020 | }
|
23021 |
|
23022 | inherit(TouchInput, Input, {
|
23023 | handler: function MTEhandler(ev) {
|
23024 | var type = TOUCH_INPUT_MAP[ev.type];
|
23025 | var touches = getTouches.call(this, ev, type);
|
23026 | if (!touches) {
|
23027 | return;
|
23028 | }
|
23029 |
|
23030 | this.callback(this.manager, type, {
|
23031 | pointers: touches[0],
|
23032 | changedPointers: touches[1],
|
23033 | pointerType: INPUT_TYPE_TOUCH,
|
23034 | srcEvent: ev
|
23035 | });
|
23036 | }
|
23037 | });
|
23038 |
|
23039 | |
23040 |
|
23041 |
|
23042 |
|
23043 |
|
23044 |
|
23045 | function getTouches(ev, type) {
|
23046 | var allTouches = toArray(ev.touches);
|
23047 | var targetIds = this.targetIds;
|
23048 |
|
23049 |
|
23050 | if (type & (INPUT_START | INPUT_MOVE) && allTouches.length === 1) {
|
23051 | targetIds[allTouches[0].identifier] = true;
|
23052 | return [allTouches, allTouches];
|
23053 | }
|
23054 |
|
23055 | var i,
|
23056 | targetTouches,
|
23057 | changedTouches = toArray(ev.changedTouches),
|
23058 | changedTargetTouches = [],
|
23059 | target = this.target;
|
23060 |
|
23061 |
|
23062 | targetTouches = allTouches.filter(function(touch) {
|
23063 | return hasParent(touch.target, target);
|
23064 | });
|
23065 |
|
23066 |
|
23067 | if (type === INPUT_START) {
|
23068 | i = 0;
|
23069 | while (i < targetTouches.length) {
|
23070 | targetIds[targetTouches[i].identifier] = true;
|
23071 | i++;
|
23072 | }
|
23073 | }
|
23074 |
|
23075 |
|
23076 | i = 0;
|
23077 | while (i < changedTouches.length) {
|
23078 | if (targetIds[changedTouches[i].identifier]) {
|
23079 | changedTargetTouches.push(changedTouches[i]);
|
23080 | }
|
23081 |
|
23082 |
|
23083 | if (type & (INPUT_END | INPUT_CANCEL)) {
|
23084 | delete targetIds[changedTouches[i].identifier];
|
23085 | }
|
23086 | i++;
|
23087 | }
|
23088 |
|
23089 | if (!changedTargetTouches.length) {
|
23090 | return;
|
23091 | }
|
23092 |
|
23093 | return [
|
23094 |
|
23095 | uniqueArray(targetTouches.concat(changedTargetTouches), 'identifier', true),
|
23096 | changedTargetTouches
|
23097 | ];
|
23098 | }
|
23099 |
|
23100 | |
23101 |
|
23102 |
|
23103 |
|
23104 |
|
23105 |
|
23106 |
|
23107 |
|
23108 |
|
23109 |
|
23110 | var DEDUP_TIMEOUT = 2500;
|
23111 | var DEDUP_DISTANCE = 25;
|
23112 |
|
23113 | function TouchMouseInput() {
|
23114 | Input.apply(this, arguments);
|
23115 |
|
23116 | var handler = bindFn(this.handler, this);
|
23117 | this.touch = new TouchInput(this.manager, handler);
|
23118 | this.mouse = new MouseInput(this.manager, handler);
|
23119 |
|
23120 | this.primaryTouch = null;
|
23121 | this.lastTouches = [];
|
23122 | }
|
23123 |
|
23124 | inherit(TouchMouseInput, Input, {
|
23125 | |
23126 |
|
23127 |
|
23128 |
|
23129 |
|
23130 |
|
23131 | handler: function TMEhandler(manager, inputEvent, inputData) {
|
23132 | var isTouch = (inputData.pointerType == INPUT_TYPE_TOUCH),
|
23133 | isMouse = (inputData.pointerType == INPUT_TYPE_MOUSE);
|
23134 |
|
23135 | if (isMouse && inputData.sourceCapabilities && inputData.sourceCapabilities.firesTouchEvents) {
|
23136 | return;
|
23137 | }
|
23138 |
|
23139 |
|
23140 | if (isTouch) {
|
23141 | recordTouches.call(this, inputEvent, inputData);
|
23142 | } else if (isMouse && isSyntheticEvent.call(this, inputData)) {
|
23143 | return;
|
23144 | }
|
23145 |
|
23146 | this.callback(manager, inputEvent, inputData);
|
23147 | },
|
23148 |
|
23149 | |
23150 |
|
23151 |
|
23152 | destroy: function destroy() {
|
23153 | this.touch.destroy();
|
23154 | this.mouse.destroy();
|
23155 | }
|
23156 | });
|
23157 |
|
23158 | function recordTouches(eventType, eventData) {
|
23159 | if (eventType & INPUT_START) {
|
23160 | this.primaryTouch = eventData.changedPointers[0].identifier;
|
23161 | setLastTouch.call(this, eventData);
|
23162 | } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
|
23163 | setLastTouch.call(this, eventData);
|
23164 | }
|
23165 | }
|
23166 |
|
23167 | function setLastTouch(eventData) {
|
23168 | var touch = eventData.changedPointers[0];
|
23169 |
|
23170 | if (touch.identifier === this.primaryTouch) {
|
23171 | var lastTouch = {x: touch.clientX, y: touch.clientY};
|
23172 | this.lastTouches.push(lastTouch);
|
23173 | var lts = this.lastTouches;
|
23174 | var removeLastTouch = function() {
|
23175 | var i = lts.indexOf(lastTouch);
|
23176 | if (i > -1) {
|
23177 | lts.splice(i, 1);
|
23178 | }
|
23179 | };
|
23180 | setTimeout(removeLastTouch, DEDUP_TIMEOUT);
|
23181 | }
|
23182 | }
|
23183 |
|
23184 | function isSyntheticEvent(eventData) {
|
23185 | var x = eventData.srcEvent.clientX, y = eventData.srcEvent.clientY;
|
23186 | for (var i = 0; i < this.lastTouches.length; i++) {
|
23187 | var t = this.lastTouches[i];
|
23188 | var dx = Math.abs(x - t.x), dy = Math.abs(y - t.y);
|
23189 | if (dx <= DEDUP_DISTANCE && dy <= DEDUP_DISTANCE) {
|
23190 | return true;
|
23191 | }
|
23192 | }
|
23193 | return false;
|
23194 | }
|
23195 |
|
23196 | var PREFIXED_TOUCH_ACTION = prefixed(TEST_ELEMENT.style, 'touchAction');
|
23197 | var NATIVE_TOUCH_ACTION = PREFIXED_TOUCH_ACTION !== undefined$1;
|
23198 |
|
23199 |
|
23200 | var TOUCH_ACTION_COMPUTE = 'compute';
|
23201 | var TOUCH_ACTION_AUTO = 'auto';
|
23202 | var TOUCH_ACTION_MANIPULATION = 'manipulation';
|
23203 | var TOUCH_ACTION_NONE = 'none';
|
23204 | var TOUCH_ACTION_PAN_X = 'pan-x';
|
23205 | var TOUCH_ACTION_PAN_Y = 'pan-y';
|
23206 | var TOUCH_ACTION_MAP = getTouchActionProps();
|
23207 |
|
23208 | |
23209 |
|
23210 |
|
23211 |
|
23212 |
|
23213 |
|
23214 |
|
23215 | function TouchAction(manager, value) {
|
23216 | this.manager = manager;
|
23217 | this.set(value);
|
23218 | }
|
23219 |
|
23220 | TouchAction.prototype = {
|
23221 | |
23222 |
|
23223 |
|
23224 |
|
23225 | set: function(value) {
|
23226 |
|
23227 | if (value == TOUCH_ACTION_COMPUTE) {
|
23228 | value = this.compute();
|
23229 | }
|
23230 |
|
23231 | if (NATIVE_TOUCH_ACTION && this.manager.element.style && TOUCH_ACTION_MAP[value]) {
|
23232 | this.manager.element.style[PREFIXED_TOUCH_ACTION] = value;
|
23233 | }
|
23234 | this.actions = value.toLowerCase().trim();
|
23235 | },
|
23236 |
|
23237 | |
23238 |
|
23239 |
|
23240 | update: function() {
|
23241 | this.set(this.manager.options.touchAction);
|
23242 | },
|
23243 |
|
23244 | |
23245 |
|
23246 |
|
23247 |
|
23248 | compute: function() {
|
23249 | var actions = [];
|
23250 | each(this.manager.recognizers, function(recognizer) {
|
23251 | if (boolOrFn(recognizer.options.enable, [recognizer])) {
|
23252 | actions = actions.concat(recognizer.getTouchAction());
|
23253 | }
|
23254 | });
|
23255 | return cleanTouchActions(actions.join(' '));
|
23256 | },
|
23257 |
|
23258 | |
23259 |
|
23260 |
|
23261 |
|
23262 | preventDefaults: function(input) {
|
23263 | var srcEvent = input.srcEvent;
|
23264 | var direction = input.offsetDirection;
|
23265 |
|
23266 |
|
23267 | if (this.manager.session.prevented) {
|
23268 | srcEvent.preventDefault();
|
23269 | return;
|
23270 | }
|
23271 |
|
23272 | var actions = this.actions;
|
23273 | var hasNone = inStr(actions, TOUCH_ACTION_NONE) && !TOUCH_ACTION_MAP[TOUCH_ACTION_NONE];
|
23274 | var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_Y];
|
23275 | var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_X];
|
23276 |
|
23277 | if (hasNone) {
|
23278 |
|
23279 |
|
23280 | var isTapPointer = input.pointers.length === 1;
|
23281 | var isTapMovement = input.distance < 2;
|
23282 | var isTapTouchTime = input.deltaTime < 250;
|
23283 |
|
23284 | if (isTapPointer && isTapMovement && isTapTouchTime) {
|
23285 | return;
|
23286 | }
|
23287 | }
|
23288 |
|
23289 | if (hasPanX && hasPanY) {
|
23290 |
|
23291 | return;
|
23292 | }
|
23293 |
|
23294 | if (hasNone ||
|
23295 | (hasPanY && direction & DIRECTION_HORIZONTAL) ||
|
23296 | (hasPanX && direction & DIRECTION_VERTICAL)) {
|
23297 | return this.preventSrc(srcEvent);
|
23298 | }
|
23299 | },
|
23300 |
|
23301 | |
23302 |
|
23303 |
|
23304 |
|
23305 | preventSrc: function(srcEvent) {
|
23306 | this.manager.session.prevented = true;
|
23307 | srcEvent.preventDefault();
|
23308 | }
|
23309 | };
|
23310 |
|
23311 | |
23312 |
|
23313 |
|
23314 |
|
23315 |
|
23316 | function cleanTouchActions(actions) {
|
23317 |
|
23318 | if (inStr(actions, TOUCH_ACTION_NONE)) {
|
23319 | return TOUCH_ACTION_NONE;
|
23320 | }
|
23321 |
|
23322 | var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
|
23323 | var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y);
|
23324 |
|
23325 |
|
23326 |
|
23327 |
|
23328 |
|
23329 | if (hasPanX && hasPanY) {
|
23330 | return TOUCH_ACTION_NONE;
|
23331 | }
|
23332 |
|
23333 |
|
23334 | if (hasPanX || hasPanY) {
|
23335 | return hasPanX ? TOUCH_ACTION_PAN_X : TOUCH_ACTION_PAN_Y;
|
23336 | }
|
23337 |
|
23338 |
|
23339 | if (inStr(actions, TOUCH_ACTION_MANIPULATION)) {
|
23340 | return TOUCH_ACTION_MANIPULATION;
|
23341 | }
|
23342 |
|
23343 | return TOUCH_ACTION_AUTO;
|
23344 | }
|
23345 |
|
23346 | function getTouchActionProps() {
|
23347 | if (!NATIVE_TOUCH_ACTION) {
|
23348 | return false;
|
23349 | }
|
23350 | var touchMap = {};
|
23351 | var cssSupports = window.CSS && window.CSS.supports;
|
23352 | ['auto', 'manipulation', 'pan-y', 'pan-x', 'pan-x pan-y', 'none'].forEach(function(val) {
|
23353 |
|
23354 |
|
23355 |
|
23356 | touchMap[val] = cssSupports ? window.CSS.supports('touch-action', val) : true;
|
23357 | });
|
23358 | return touchMap;
|
23359 | }
|
23360 |
|
23361 | |
23362 |
|
23363 |
|
23364 |
|
23365 |
|
23366 |
|
23367 |
|
23368 |
|
23369 |
|
23370 |
|
23371 |
|
23372 |
|
23373 |
|
23374 |
|
23375 |
|
23376 |
|
23377 |
|
23378 |
|
23379 |
|
23380 |
|
23381 |
|
23382 |
|
23383 |
|
23384 |
|
23385 |
|
23386 |
|
23387 |
|
23388 | var STATE_POSSIBLE = 1;
|
23389 | var STATE_BEGAN = 2;
|
23390 | var STATE_CHANGED = 4;
|
23391 | var STATE_ENDED = 8;
|
23392 | var STATE_RECOGNIZED = STATE_ENDED;
|
23393 | var STATE_CANCELLED = 16;
|
23394 | var STATE_FAILED = 32;
|
23395 |
|
23396 | |
23397 |
|
23398 |
|
23399 |
|
23400 |
|
23401 |
|
23402 | function Recognizer(options) {
|
23403 | this.options = assign({}, this.defaults, options || {});
|
23404 |
|
23405 | this.id = uniqueId();
|
23406 |
|
23407 | this.manager = null;
|
23408 |
|
23409 |
|
23410 | this.options.enable = ifUndefined(this.options.enable, true);
|
23411 |
|
23412 | this.state = STATE_POSSIBLE;
|
23413 |
|
23414 | this.simultaneous = {};
|
23415 | this.requireFail = [];
|
23416 | }
|
23417 |
|
23418 | Recognizer.prototype = {
|
23419 | |
23420 |
|
23421 |
|
23422 |
|
23423 | defaults: {},
|
23424 |
|
23425 | |
23426 |
|
23427 |
|
23428 |
|
23429 |
|
23430 | set: function(options) {
|
23431 | assign(this.options, options);
|
23432 |
|
23433 |
|
23434 | this.manager && this.manager.touchAction.update();
|
23435 | return this;
|
23436 | },
|
23437 |
|
23438 | |
23439 |
|
23440 |
|
23441 |
|
23442 |
|
23443 | recognizeWith: function(otherRecognizer) {
|
23444 | if (invokeArrayArg(otherRecognizer, 'recognizeWith', this)) {
|
23445 | return this;
|
23446 | }
|
23447 |
|
23448 | var simultaneous = this.simultaneous;
|
23449 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
23450 | if (!simultaneous[otherRecognizer.id]) {
|
23451 | simultaneous[otherRecognizer.id] = otherRecognizer;
|
23452 | otherRecognizer.recognizeWith(this);
|
23453 | }
|
23454 | return this;
|
23455 | },
|
23456 |
|
23457 | |
23458 |
|
23459 |
|
23460 |
|
23461 |
|
23462 | dropRecognizeWith: function(otherRecognizer) {
|
23463 | if (invokeArrayArg(otherRecognizer, 'dropRecognizeWith', this)) {
|
23464 | return this;
|
23465 | }
|
23466 |
|
23467 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
23468 | delete this.simultaneous[otherRecognizer.id];
|
23469 | return this;
|
23470 | },
|
23471 |
|
23472 | |
23473 |
|
23474 |
|
23475 |
|
23476 |
|
23477 | requireFailure: function(otherRecognizer) {
|
23478 | if (invokeArrayArg(otherRecognizer, 'requireFailure', this)) {
|
23479 | return this;
|
23480 | }
|
23481 |
|
23482 | var requireFail = this.requireFail;
|
23483 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
23484 | if (inArray(requireFail, otherRecognizer) === -1) {
|
23485 | requireFail.push(otherRecognizer);
|
23486 | otherRecognizer.requireFailure(this);
|
23487 | }
|
23488 | return this;
|
23489 | },
|
23490 |
|
23491 | |
23492 |
|
23493 |
|
23494 |
|
23495 |
|
23496 | dropRequireFailure: function(otherRecognizer) {
|
23497 | if (invokeArrayArg(otherRecognizer, 'dropRequireFailure', this)) {
|
23498 | return this;
|
23499 | }
|
23500 |
|
23501 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
23502 | var index = inArray(this.requireFail, otherRecognizer);
|
23503 | if (index > -1) {
|
23504 | this.requireFail.splice(index, 1);
|
23505 | }
|
23506 | return this;
|
23507 | },
|
23508 |
|
23509 | |
23510 |
|
23511 |
|
23512 |
|
23513 | hasRequireFailures: function() {
|
23514 | return this.requireFail.length > 0;
|
23515 | },
|
23516 |
|
23517 | |
23518 |
|
23519 |
|
23520 |
|
23521 |
|
23522 | canRecognizeWith: function(otherRecognizer) {
|
23523 | return !!this.simultaneous[otherRecognizer.id];
|
23524 | },
|
23525 |
|
23526 | |
23527 |
|
23528 |
|
23529 |
|
23530 |
|
23531 | emit: function(input) {
|
23532 | var self = this;
|
23533 | var state = this.state;
|
23534 |
|
23535 | function emit(event) {
|
23536 | self.manager.emit(event, input);
|
23537 | }
|
23538 |
|
23539 |
|
23540 | if (state < STATE_ENDED) {
|
23541 | emit(self.options.event + stateStr(state));
|
23542 | }
|
23543 |
|
23544 | emit(self.options.event);
|
23545 |
|
23546 | if (input.additionalEvent) {
|
23547 | emit(input.additionalEvent);
|
23548 | }
|
23549 |
|
23550 |
|
23551 | if (state >= STATE_ENDED) {
|
23552 | emit(self.options.event + stateStr(state));
|
23553 | }
|
23554 | },
|
23555 |
|
23556 | |
23557 |
|
23558 |
|
23559 |
|
23560 |
|
23561 |
|
23562 | tryEmit: function(input) {
|
23563 | if (this.canEmit()) {
|
23564 | return this.emit(input);
|
23565 | }
|
23566 |
|
23567 | this.state = STATE_FAILED;
|
23568 | },
|
23569 |
|
23570 | |
23571 |
|
23572 |
|
23573 |
|
23574 | canEmit: function() {
|
23575 | var i = 0;
|
23576 | while (i < this.requireFail.length) {
|
23577 | if (!(this.requireFail[i].state & (STATE_FAILED | STATE_POSSIBLE))) {
|
23578 | return false;
|
23579 | }
|
23580 | i++;
|
23581 | }
|
23582 | return true;
|
23583 | },
|
23584 |
|
23585 | |
23586 |
|
23587 |
|
23588 |
|
23589 | recognize: function(inputData) {
|
23590 |
|
23591 |
|
23592 | var inputDataClone = assign({}, inputData);
|
23593 |
|
23594 |
|
23595 | if (!boolOrFn(this.options.enable, [this, inputDataClone])) {
|
23596 | this.reset();
|
23597 | this.state = STATE_FAILED;
|
23598 | return;
|
23599 | }
|
23600 |
|
23601 |
|
23602 | if (this.state & (STATE_RECOGNIZED | STATE_CANCELLED | STATE_FAILED)) {
|
23603 | this.state = STATE_POSSIBLE;
|
23604 | }
|
23605 |
|
23606 | this.state = this.process(inputDataClone);
|
23607 |
|
23608 |
|
23609 |
|
23610 | if (this.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED | STATE_CANCELLED)) {
|
23611 | this.tryEmit(inputDataClone);
|
23612 | }
|
23613 | },
|
23614 |
|
23615 | |
23616 |
|
23617 |
|
23618 |
|
23619 |
|
23620 |
|
23621 |
|
23622 | process: function(inputData) { },
|
23623 |
|
23624 | |
23625 |
|
23626 |
|
23627 |
|
23628 |
|
23629 | getTouchAction: function() { },
|
23630 |
|
23631 | |
23632 |
|
23633 |
|
23634 |
|
23635 |
|
23636 | reset: function() { }
|
23637 | };
|
23638 |
|
23639 | |
23640 |
|
23641 |
|
23642 |
|
23643 |
|
23644 | function stateStr(state) {
|
23645 | if (state & STATE_CANCELLED) {
|
23646 | return 'cancel';
|
23647 | } else if (state & STATE_ENDED) {
|
23648 | return 'end';
|
23649 | } else if (state & STATE_CHANGED) {
|
23650 | return 'move';
|
23651 | } else if (state & STATE_BEGAN) {
|
23652 | return 'start';
|
23653 | }
|
23654 | return '';
|
23655 | }
|
23656 |
|
23657 | |
23658 |
|
23659 |
|
23660 |
|
23661 |
|
23662 | function directionStr(direction) {
|
23663 | if (direction == DIRECTION_DOWN) {
|
23664 | return 'down';
|
23665 | } else if (direction == DIRECTION_UP) {
|
23666 | return 'up';
|
23667 | } else if (direction == DIRECTION_LEFT) {
|
23668 | return 'left';
|
23669 | } else if (direction == DIRECTION_RIGHT) {
|
23670 | return 'right';
|
23671 | }
|
23672 | return '';
|
23673 | }
|
23674 |
|
23675 | |
23676 |
|
23677 |
|
23678 |
|
23679 |
|
23680 |
|
23681 | function getRecognizerByNameIfManager(otherRecognizer, recognizer) {
|
23682 | var manager = recognizer.manager;
|
23683 | if (manager) {
|
23684 | return manager.get(otherRecognizer);
|
23685 | }
|
23686 | return otherRecognizer;
|
23687 | }
|
23688 |
|
23689 | |
23690 |
|
23691 |
|
23692 |
|
23693 |
|
23694 | function AttrRecognizer() {
|
23695 | Recognizer.apply(this, arguments);
|
23696 | }
|
23697 |
|
23698 | inherit(AttrRecognizer, Recognizer, {
|
23699 | |
23700 |
|
23701 |
|
23702 |
|
23703 | defaults: {
|
23704 | |
23705 |
|
23706 |
|
23707 |
|
23708 | pointers: 1
|
23709 | },
|
23710 |
|
23711 | |
23712 |
|
23713 |
|
23714 |
|
23715 |
|
23716 |
|
23717 | attrTest: function(input) {
|
23718 | var optionPointers = this.options.pointers;
|
23719 | return optionPointers === 0 || input.pointers.length === optionPointers;
|
23720 | },
|
23721 |
|
23722 | |
23723 |
|
23724 |
|
23725 |
|
23726 |
|
23727 |
|
23728 | process: function(input) {
|
23729 | var state = this.state;
|
23730 | var eventType = input.eventType;
|
23731 |
|
23732 | var isRecognized = state & (STATE_BEGAN | STATE_CHANGED);
|
23733 | var isValid = this.attrTest(input);
|
23734 |
|
23735 |
|
23736 | if (isRecognized && (eventType & INPUT_CANCEL || !isValid)) {
|
23737 | return state | STATE_CANCELLED;
|
23738 | } else if (isRecognized || isValid) {
|
23739 | if (eventType & INPUT_END) {
|
23740 | return state | STATE_ENDED;
|
23741 | } else if (!(state & STATE_BEGAN)) {
|
23742 | return STATE_BEGAN;
|
23743 | }
|
23744 | return state | STATE_CHANGED;
|
23745 | }
|
23746 | return STATE_FAILED;
|
23747 | }
|
23748 | });
|
23749 |
|
23750 | |
23751 |
|
23752 |
|
23753 |
|
23754 |
|
23755 |
|
23756 | function PanRecognizer() {
|
23757 | AttrRecognizer.apply(this, arguments);
|
23758 |
|
23759 | this.pX = null;
|
23760 | this.pY = null;
|
23761 | }
|
23762 |
|
23763 | inherit(PanRecognizer, AttrRecognizer, {
|
23764 | |
23765 |
|
23766 |
|
23767 |
|
23768 | defaults: {
|
23769 | event: 'pan',
|
23770 | threshold: 10,
|
23771 | pointers: 1,
|
23772 | direction: DIRECTION_ALL
|
23773 | },
|
23774 |
|
23775 | getTouchAction: function() {
|
23776 | var direction = this.options.direction;
|
23777 | var actions = [];
|
23778 | if (direction & DIRECTION_HORIZONTAL) {
|
23779 | actions.push(TOUCH_ACTION_PAN_Y);
|
23780 | }
|
23781 | if (direction & DIRECTION_VERTICAL) {
|
23782 | actions.push(TOUCH_ACTION_PAN_X);
|
23783 | }
|
23784 | return actions;
|
23785 | },
|
23786 |
|
23787 | directionTest: function(input) {
|
23788 | var options = this.options;
|
23789 | var hasMoved = true;
|
23790 | var distance = input.distance;
|
23791 | var direction = input.direction;
|
23792 | var x = input.deltaX;
|
23793 | var y = input.deltaY;
|
23794 |
|
23795 |
|
23796 | if (!(direction & options.direction)) {
|
23797 | if (options.direction & DIRECTION_HORIZONTAL) {
|
23798 | direction = (x === 0) ? DIRECTION_NONE : (x < 0) ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
23799 | hasMoved = x != this.pX;
|
23800 | distance = Math.abs(input.deltaX);
|
23801 | } else {
|
23802 | direction = (y === 0) ? DIRECTION_NONE : (y < 0) ? DIRECTION_UP : DIRECTION_DOWN;
|
23803 | hasMoved = y != this.pY;
|
23804 | distance = Math.abs(input.deltaY);
|
23805 | }
|
23806 | }
|
23807 | input.direction = direction;
|
23808 | return hasMoved && distance > options.threshold && direction & options.direction;
|
23809 | },
|
23810 |
|
23811 | attrTest: function(input) {
|
23812 | return AttrRecognizer.prototype.attrTest.call(this, input) &&
|
23813 | (this.state & STATE_BEGAN || (!(this.state & STATE_BEGAN) && this.directionTest(input)));
|
23814 | },
|
23815 |
|
23816 | emit: function(input) {
|
23817 |
|
23818 | this.pX = input.deltaX;
|
23819 | this.pY = input.deltaY;
|
23820 |
|
23821 | var direction = directionStr(input.direction);
|
23822 |
|
23823 | if (direction) {
|
23824 | input.additionalEvent = this.options.event + direction;
|
23825 | }
|
23826 | this._super.emit.call(this, input);
|
23827 | }
|
23828 | });
|
23829 |
|
23830 | |
23831 |
|
23832 |
|
23833 |
|
23834 |
|
23835 |
|
23836 | function PinchRecognizer() {
|
23837 | AttrRecognizer.apply(this, arguments);
|
23838 | }
|
23839 |
|
23840 | inherit(PinchRecognizer, AttrRecognizer, {
|
23841 | |
23842 |
|
23843 |
|
23844 |
|
23845 | defaults: {
|
23846 | event: 'pinch',
|
23847 | threshold: 0,
|
23848 | pointers: 2
|
23849 | },
|
23850 |
|
23851 | getTouchAction: function() {
|
23852 | return [TOUCH_ACTION_NONE];
|
23853 | },
|
23854 |
|
23855 | attrTest: function(input) {
|
23856 | return this._super.attrTest.call(this, input) &&
|
23857 | (Math.abs(input.scale - 1) > this.options.threshold || this.state & STATE_BEGAN);
|
23858 | },
|
23859 |
|
23860 | emit: function(input) {
|
23861 | if (input.scale !== 1) {
|
23862 | var inOut = input.scale < 1 ? 'in' : 'out';
|
23863 | input.additionalEvent = this.options.event + inOut;
|
23864 | }
|
23865 | this._super.emit.call(this, input);
|
23866 | }
|
23867 | });
|
23868 |
|
23869 | |
23870 |
|
23871 |
|
23872 |
|
23873 |
|
23874 |
|
23875 | function PressRecognizer() {
|
23876 | Recognizer.apply(this, arguments);
|
23877 |
|
23878 | this._timer = null;
|
23879 | this._input = null;
|
23880 | }
|
23881 |
|
23882 | inherit(PressRecognizer, Recognizer, {
|
23883 | |
23884 |
|
23885 |
|
23886 |
|
23887 | defaults: {
|
23888 | event: 'press',
|
23889 | pointers: 1,
|
23890 | time: 251,
|
23891 | threshold: 9
|
23892 | },
|
23893 |
|
23894 | getTouchAction: function() {
|
23895 | return [TOUCH_ACTION_AUTO];
|
23896 | },
|
23897 |
|
23898 | process: function(input) {
|
23899 | var options = this.options;
|
23900 | var validPointers = input.pointers.length === options.pointers;
|
23901 | var validMovement = input.distance < options.threshold;
|
23902 | var validTime = input.deltaTime > options.time;
|
23903 |
|
23904 | this._input = input;
|
23905 |
|
23906 |
|
23907 |
|
23908 | if (!validMovement || !validPointers || (input.eventType & (INPUT_END | INPUT_CANCEL) && !validTime)) {
|
23909 | this.reset();
|
23910 | } else if (input.eventType & INPUT_START) {
|
23911 | this.reset();
|
23912 | this._timer = setTimeoutContext(function() {
|
23913 | this.state = STATE_RECOGNIZED;
|
23914 | this.tryEmit();
|
23915 | }, options.time, this);
|
23916 | } else if (input.eventType & INPUT_END) {
|
23917 | return STATE_RECOGNIZED;
|
23918 | }
|
23919 | return STATE_FAILED;
|
23920 | },
|
23921 |
|
23922 | reset: function() {
|
23923 | clearTimeout(this._timer);
|
23924 | },
|
23925 |
|
23926 | emit: function(input) {
|
23927 | if (this.state !== STATE_RECOGNIZED) {
|
23928 | return;
|
23929 | }
|
23930 |
|
23931 | if (input && (input.eventType & INPUT_END)) {
|
23932 | this.manager.emit(this.options.event + 'up', input);
|
23933 | } else {
|
23934 | this._input.timeStamp = now();
|
23935 | this.manager.emit(this.options.event, this._input);
|
23936 | }
|
23937 | }
|
23938 | });
|
23939 |
|
23940 | |
23941 |
|
23942 |
|
23943 |
|
23944 |
|
23945 |
|
23946 | function RotateRecognizer() {
|
23947 | AttrRecognizer.apply(this, arguments);
|
23948 | }
|
23949 |
|
23950 | inherit(RotateRecognizer, AttrRecognizer, {
|
23951 | |
23952 |
|
23953 |
|
23954 |
|
23955 | defaults: {
|
23956 | event: 'rotate',
|
23957 | threshold: 0,
|
23958 | pointers: 2
|
23959 | },
|
23960 |
|
23961 | getTouchAction: function() {
|
23962 | return [TOUCH_ACTION_NONE];
|
23963 | },
|
23964 |
|
23965 | attrTest: function(input) {
|
23966 | return this._super.attrTest.call(this, input) &&
|
23967 | (Math.abs(input.rotation) > this.options.threshold || this.state & STATE_BEGAN);
|
23968 | }
|
23969 | });
|
23970 |
|
23971 | |
23972 |
|
23973 |
|
23974 |
|
23975 |
|
23976 |
|
23977 | function SwipeRecognizer() {
|
23978 | AttrRecognizer.apply(this, arguments);
|
23979 | }
|
23980 |
|
23981 | inherit(SwipeRecognizer, AttrRecognizer, {
|
23982 | |
23983 |
|
23984 |
|
23985 |
|
23986 | defaults: {
|
23987 | event: 'swipe',
|
23988 | threshold: 10,
|
23989 | velocity: 0.3,
|
23990 | direction: DIRECTION_HORIZONTAL | DIRECTION_VERTICAL,
|
23991 | pointers: 1
|
23992 | },
|
23993 |
|
23994 | getTouchAction: function() {
|
23995 | return PanRecognizer.prototype.getTouchAction.call(this);
|
23996 | },
|
23997 |
|
23998 | attrTest: function(input) {
|
23999 | var direction = this.options.direction;
|
24000 | var velocity;
|
24001 |
|
24002 | if (direction & (DIRECTION_HORIZONTAL | DIRECTION_VERTICAL)) {
|
24003 | velocity = input.overallVelocity;
|
24004 | } else if (direction & DIRECTION_HORIZONTAL) {
|
24005 | velocity = input.overallVelocityX;
|
24006 | } else if (direction & DIRECTION_VERTICAL) {
|
24007 | velocity = input.overallVelocityY;
|
24008 | }
|
24009 |
|
24010 | return this._super.attrTest.call(this, input) &&
|
24011 | direction & input.offsetDirection &&
|
24012 | input.distance > this.options.threshold &&
|
24013 | input.maxPointers == this.options.pointers &&
|
24014 | abs(velocity) > this.options.velocity && input.eventType & INPUT_END;
|
24015 | },
|
24016 |
|
24017 | emit: function(input) {
|
24018 | var direction = directionStr(input.offsetDirection);
|
24019 | if (direction) {
|
24020 | this.manager.emit(this.options.event + direction, input);
|
24021 | }
|
24022 |
|
24023 | this.manager.emit(this.options.event, input);
|
24024 | }
|
24025 | });
|
24026 |
|
24027 | |
24028 |
|
24029 |
|
24030 |
|
24031 |
|
24032 |
|
24033 |
|
24034 |
|
24035 |
|
24036 |
|
24037 | function TapRecognizer() {
|
24038 | Recognizer.apply(this, arguments);
|
24039 |
|
24040 |
|
24041 |
|
24042 | this.pTime = false;
|
24043 | this.pCenter = false;
|
24044 |
|
24045 | this._timer = null;
|
24046 | this._input = null;
|
24047 | this.count = 0;
|
24048 | }
|
24049 |
|
24050 | inherit(TapRecognizer, Recognizer, {
|
24051 | |
24052 |
|
24053 |
|
24054 |
|
24055 | defaults: {
|
24056 | event: 'tap',
|
24057 | pointers: 1,
|
24058 | taps: 1,
|
24059 | interval: 300,
|
24060 | time: 250,
|
24061 | threshold: 9,
|
24062 | posThreshold: 10
|
24063 | },
|
24064 |
|
24065 | getTouchAction: function() {
|
24066 | return [TOUCH_ACTION_MANIPULATION];
|
24067 | },
|
24068 |
|
24069 | process: function(input) {
|
24070 | var options = this.options;
|
24071 |
|
24072 | var validPointers = input.pointers.length === options.pointers;
|
24073 | var validMovement = input.distance < options.threshold;
|
24074 | var validTouchTime = input.deltaTime < options.time;
|
24075 |
|
24076 | this.reset();
|
24077 |
|
24078 | if ((input.eventType & INPUT_START) && (this.count === 0)) {
|
24079 | return this.failTimeout();
|
24080 | }
|
24081 |
|
24082 |
|
24083 |
|
24084 | if (validMovement && validTouchTime && validPointers) {
|
24085 | if (input.eventType != INPUT_END) {
|
24086 | return this.failTimeout();
|
24087 | }
|
24088 |
|
24089 | var validInterval = this.pTime ? (input.timeStamp - this.pTime < options.interval) : true;
|
24090 | var validMultiTap = !this.pCenter || getDistance(this.pCenter, input.center) < options.posThreshold;
|
24091 |
|
24092 | this.pTime = input.timeStamp;
|
24093 | this.pCenter = input.center;
|
24094 |
|
24095 | if (!validMultiTap || !validInterval) {
|
24096 | this.count = 1;
|
24097 | } else {
|
24098 | this.count += 1;
|
24099 | }
|
24100 |
|
24101 | this._input = input;
|
24102 |
|
24103 |
|
24104 |
|
24105 | var tapCount = this.count % options.taps;
|
24106 | if (tapCount === 0) {
|
24107 |
|
24108 |
|
24109 | if (!this.hasRequireFailures()) {
|
24110 | return STATE_RECOGNIZED;
|
24111 | } else {
|
24112 | this._timer = setTimeoutContext(function() {
|
24113 | this.state = STATE_RECOGNIZED;
|
24114 | this.tryEmit();
|
24115 | }, options.interval, this);
|
24116 | return STATE_BEGAN;
|
24117 | }
|
24118 | }
|
24119 | }
|
24120 | return STATE_FAILED;
|
24121 | },
|
24122 |
|
24123 | failTimeout: function() {
|
24124 | this._timer = setTimeoutContext(function() {
|
24125 | this.state = STATE_FAILED;
|
24126 | }, this.options.interval, this);
|
24127 | return STATE_FAILED;
|
24128 | },
|
24129 |
|
24130 | reset: function() {
|
24131 | clearTimeout(this._timer);
|
24132 | },
|
24133 |
|
24134 | emit: function() {
|
24135 | if (this.state == STATE_RECOGNIZED) {
|
24136 | this._input.tapCount = this.count;
|
24137 | this.manager.emit(this.options.event, this._input);
|
24138 | }
|
24139 | }
|
24140 | });
|
24141 |
|
24142 | |
24143 |
|
24144 |
|
24145 |
|
24146 |
|
24147 |
|
24148 | function Hammer(element, options) {
|
24149 | options = options || {};
|
24150 | options.recognizers = ifUndefined(options.recognizers, Hammer.defaults.preset);
|
24151 | return new Manager(element, options);
|
24152 | }
|
24153 |
|
24154 | |
24155 |
|
24156 |
|
24157 | Hammer.VERSION = '2.0.7';
|
24158 |
|
24159 | |
24160 |
|
24161 |
|
24162 |
|
24163 | Hammer.defaults = {
|
24164 | |
24165 |
|
24166 |
|
24167 |
|
24168 |
|
24169 |
|
24170 | domEvents: false,
|
24171 |
|
24172 | |
24173 |
|
24174 |
|
24175 |
|
24176 |
|
24177 |
|
24178 | touchAction: TOUCH_ACTION_COMPUTE,
|
24179 |
|
24180 | |
24181 |
|
24182 |
|
24183 |
|
24184 | enable: true,
|
24185 |
|
24186 | |
24187 |
|
24188 |
|
24189 |
|
24190 |
|
24191 |
|
24192 |
|
24193 | inputTarget: null,
|
24194 |
|
24195 | |
24196 |
|
24197 |
|
24198 |
|
24199 |
|
24200 | inputClass: null,
|
24201 |
|
24202 | |
24203 |
|
24204 |
|
24205 |
|
24206 |
|
24207 | preset: [
|
24208 |
|
24209 | [RotateRecognizer, {enable: false}],
|
24210 | [PinchRecognizer, {enable: false}, ['rotate']],
|
24211 | [SwipeRecognizer, {direction: DIRECTION_HORIZONTAL}],
|
24212 | [PanRecognizer, {direction: DIRECTION_HORIZONTAL}, ['swipe']],
|
24213 | [TapRecognizer],
|
24214 | [TapRecognizer, {event: 'doubletap', taps: 2}, ['tap']],
|
24215 | [PressRecognizer]
|
24216 | ],
|
24217 |
|
24218 | |
24219 |
|
24220 |
|
24221 |
|
24222 |
|
24223 | cssProps: {
|
24224 | |
24225 |
|
24226 |
|
24227 |
|
24228 |
|
24229 | userSelect: 'none',
|
24230 |
|
24231 | |
24232 |
|
24233 |
|
24234 |
|
24235 |
|
24236 | touchSelect: 'none',
|
24237 |
|
24238 | |
24239 |
|
24240 |
|
24241 |
|
24242 |
|
24243 |
|
24244 |
|
24245 | touchCallout: 'none',
|
24246 |
|
24247 | |
24248 |
|
24249 |
|
24250 |
|
24251 |
|
24252 | contentZooming: 'none',
|
24253 |
|
24254 | |
24255 |
|
24256 |
|
24257 |
|
24258 |
|
24259 | userDrag: 'none',
|
24260 |
|
24261 | |
24262 |
|
24263 |
|
24264 |
|
24265 |
|
24266 |
|
24267 | tapHighlightColor: 'rgba(0,0,0,0)'
|
24268 | }
|
24269 | };
|
24270 |
|
24271 | var STOP = 1;
|
24272 | var FORCED_STOP = 2;
|
24273 |
|
24274 | |
24275 |
|
24276 |
|
24277 |
|
24278 |
|
24279 |
|
24280 | function Manager(element, options) {
|
24281 | this.options = assign({}, Hammer.defaults, options || {});
|
24282 |
|
24283 | this.options.inputTarget = this.options.inputTarget || element;
|
24284 |
|
24285 | this.handlers = {};
|
24286 | this.session = {};
|
24287 | this.recognizers = [];
|
24288 | this.oldCssProps = {};
|
24289 |
|
24290 | this.element = element;
|
24291 | this.input = createInputInstance(this);
|
24292 | this.touchAction = new TouchAction(this, this.options.touchAction);
|
24293 |
|
24294 | toggleCssProps(this, true);
|
24295 |
|
24296 | each(this.options.recognizers, function(item) {
|
24297 | var recognizer = this.add(new (item[0])(item[1]));
|
24298 | item[2] && recognizer.recognizeWith(item[2]);
|
24299 | item[3] && recognizer.requireFailure(item[3]);
|
24300 | }, this);
|
24301 | }
|
24302 |
|
24303 | Manager.prototype = {
|
24304 | |
24305 |
|
24306 |
|
24307 |
|
24308 |
|
24309 | set: function(options) {
|
24310 | assign(this.options, options);
|
24311 |
|
24312 |
|
24313 | if (options.touchAction) {
|
24314 | this.touchAction.update();
|
24315 | }
|
24316 | if (options.inputTarget) {
|
24317 |
|
24318 | this.input.destroy();
|
24319 | this.input.target = options.inputTarget;
|
24320 | this.input.init();
|
24321 | }
|
24322 | return this;
|
24323 | },
|
24324 |
|
24325 | |
24326 |
|
24327 |
|
24328 |
|
24329 |
|
24330 |
|
24331 | stop: function(force) {
|
24332 | this.session.stopped = force ? FORCED_STOP : STOP;
|
24333 | },
|
24334 |
|
24335 | |
24336 |
|
24337 |
|
24338 |
|
24339 |
|
24340 |
|
24341 | recognize: function(inputData) {
|
24342 | var session = this.session;
|
24343 | if (session.stopped) {
|
24344 | return;
|
24345 | }
|
24346 |
|
24347 |
|
24348 | this.touchAction.preventDefaults(inputData);
|
24349 |
|
24350 | var recognizer;
|
24351 | var recognizers = this.recognizers;
|
24352 |
|
24353 |
|
24354 |
|
24355 |
|
24356 | var curRecognizer = session.curRecognizer;
|
24357 |
|
24358 |
|
24359 |
|
24360 | if (!curRecognizer || (curRecognizer && curRecognizer.state & STATE_RECOGNIZED)) {
|
24361 | curRecognizer = session.curRecognizer = null;
|
24362 | }
|
24363 |
|
24364 | var i = 0;
|
24365 | while (i < recognizers.length) {
|
24366 | recognizer = recognizers[i];
|
24367 |
|
24368 |
|
24369 |
|
24370 |
|
24371 |
|
24372 |
|
24373 |
|
24374 | if (session.stopped !== FORCED_STOP && (
|
24375 | !curRecognizer || recognizer == curRecognizer ||
|
24376 | recognizer.canRecognizeWith(curRecognizer))) {
|
24377 | recognizer.recognize(inputData);
|
24378 | } else {
|
24379 | recognizer.reset();
|
24380 | }
|
24381 |
|
24382 |
|
24383 |
|
24384 | if (!curRecognizer && recognizer.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED)) {
|
24385 | curRecognizer = session.curRecognizer = recognizer;
|
24386 | }
|
24387 | i++;
|
24388 | }
|
24389 | },
|
24390 |
|
24391 | |
24392 |
|
24393 |
|
24394 |
|
24395 |
|
24396 | get: function(recognizer) {
|
24397 | if (recognizer instanceof Recognizer) {
|
24398 | return recognizer;
|
24399 | }
|
24400 |
|
24401 | var recognizers = this.recognizers;
|
24402 | for (var i = 0; i < recognizers.length; i++) {
|
24403 | if (recognizers[i].options.event == recognizer) {
|
24404 | return recognizers[i];
|
24405 | }
|
24406 | }
|
24407 | return null;
|
24408 | },
|
24409 |
|
24410 | |
24411 |
|
24412 |
|
24413 |
|
24414 |
|
24415 |
|
24416 | add: function(recognizer) {
|
24417 | if (invokeArrayArg(recognizer, 'add', this)) {
|
24418 | return this;
|
24419 | }
|
24420 |
|
24421 |
|
24422 | var existing = this.get(recognizer.options.event);
|
24423 | if (existing) {
|
24424 | this.remove(existing);
|
24425 | }
|
24426 |
|
24427 | this.recognizers.push(recognizer);
|
24428 | recognizer.manager = this;
|
24429 |
|
24430 | this.touchAction.update();
|
24431 | return recognizer;
|
24432 | },
|
24433 |
|
24434 | |
24435 |
|
24436 |
|
24437 |
|
24438 |
|
24439 | remove: function(recognizer) {
|
24440 | if (invokeArrayArg(recognizer, 'remove', this)) {
|
24441 | return this;
|
24442 | }
|
24443 |
|
24444 | recognizer = this.get(recognizer);
|
24445 |
|
24446 |
|
24447 | if (recognizer) {
|
24448 | var recognizers = this.recognizers;
|
24449 | var index = inArray(recognizers, recognizer);
|
24450 |
|
24451 | if (index !== -1) {
|
24452 | recognizers.splice(index, 1);
|
24453 | this.touchAction.update();
|
24454 | }
|
24455 | }
|
24456 |
|
24457 | return this;
|
24458 | },
|
24459 |
|
24460 | |
24461 |
|
24462 |
|
24463 |
|
24464 |
|
24465 |
|
24466 | on: function(events, handler) {
|
24467 | if (events === undefined$1) {
|
24468 | return;
|
24469 | }
|
24470 | if (handler === undefined$1) {
|
24471 | return;
|
24472 | }
|
24473 |
|
24474 | var handlers = this.handlers;
|
24475 | each(splitStr(events), function(event) {
|
24476 | handlers[event] = handlers[event] || [];
|
24477 | handlers[event].push(handler);
|
24478 | });
|
24479 | return this;
|
24480 | },
|
24481 |
|
24482 | |
24483 |
|
24484 |
|
24485 |
|
24486 |
|
24487 |
|
24488 | off: function(events, handler) {
|
24489 | if (events === undefined$1) {
|
24490 | return;
|
24491 | }
|
24492 |
|
24493 | var handlers = this.handlers;
|
24494 | each(splitStr(events), function(event) {
|
24495 | if (!handler) {
|
24496 | delete handlers[event];
|
24497 | } else {
|
24498 | handlers[event] && handlers[event].splice(inArray(handlers[event], handler), 1);
|
24499 | }
|
24500 | });
|
24501 | return this;
|
24502 | },
|
24503 |
|
24504 | |
24505 |
|
24506 |
|
24507 |
|
24508 |
|
24509 | emit: function(event, data) {
|
24510 |
|
24511 | if (this.options.domEvents) {
|
24512 | triggerDomEvent(event, data);
|
24513 | }
|
24514 |
|
24515 |
|
24516 | var handlers = this.handlers[event] && this.handlers[event].slice();
|
24517 | if (!handlers || !handlers.length) {
|
24518 | return;
|
24519 | }
|
24520 |
|
24521 | data.type = event;
|
24522 | data.preventDefault = function() {
|
24523 | data.srcEvent.preventDefault();
|
24524 | };
|
24525 |
|
24526 | var i = 0;
|
24527 | while (i < handlers.length) {
|
24528 | handlers[i](data);
|
24529 | i++;
|
24530 | }
|
24531 | },
|
24532 |
|
24533 | |
24534 |
|
24535 |
|
24536 |
|
24537 | destroy: function() {
|
24538 | this.element && toggleCssProps(this, false);
|
24539 |
|
24540 | this.handlers = {};
|
24541 | this.session = {};
|
24542 | this.input.destroy();
|
24543 | this.element = null;
|
24544 | }
|
24545 | };
|
24546 |
|
24547 | |
24548 |
|
24549 |
|
24550 |
|
24551 |
|
24552 | function toggleCssProps(manager, add) {
|
24553 | var element = manager.element;
|
24554 | if (!element.style) {
|
24555 | return;
|
24556 | }
|
24557 | var prop;
|
24558 | each(manager.options.cssProps, function(value, name) {
|
24559 | prop = prefixed(element.style, name);
|
24560 | if (add) {
|
24561 | manager.oldCssProps[prop] = element.style[prop];
|
24562 | element.style[prop] = value;
|
24563 | } else {
|
24564 | element.style[prop] = manager.oldCssProps[prop] || '';
|
24565 | }
|
24566 | });
|
24567 | if (!add) {
|
24568 | manager.oldCssProps = {};
|
24569 | }
|
24570 | }
|
24571 |
|
24572 | |
24573 |
|
24574 |
|
24575 |
|
24576 |
|
24577 | function triggerDomEvent(event, data) {
|
24578 | var gestureEvent = document.createEvent('Event');
|
24579 | gestureEvent.initEvent(event, true, true);
|
24580 | gestureEvent.gesture = data;
|
24581 | data.target.dispatchEvent(gestureEvent);
|
24582 | }
|
24583 |
|
24584 | assign(Hammer, {
|
24585 | INPUT_START: INPUT_START,
|
24586 | INPUT_MOVE: INPUT_MOVE,
|
24587 | INPUT_END: INPUT_END,
|
24588 | INPUT_CANCEL: INPUT_CANCEL,
|
24589 |
|
24590 | STATE_POSSIBLE: STATE_POSSIBLE,
|
24591 | STATE_BEGAN: STATE_BEGAN,
|
24592 | STATE_CHANGED: STATE_CHANGED,
|
24593 | STATE_ENDED: STATE_ENDED,
|
24594 | STATE_RECOGNIZED: STATE_RECOGNIZED,
|
24595 | STATE_CANCELLED: STATE_CANCELLED,
|
24596 | STATE_FAILED: STATE_FAILED,
|
24597 |
|
24598 | DIRECTION_NONE: DIRECTION_NONE,
|
24599 | DIRECTION_LEFT: DIRECTION_LEFT,
|
24600 | DIRECTION_RIGHT: DIRECTION_RIGHT,
|
24601 | DIRECTION_UP: DIRECTION_UP,
|
24602 | DIRECTION_DOWN: DIRECTION_DOWN,
|
24603 | DIRECTION_HORIZONTAL: DIRECTION_HORIZONTAL,
|
24604 | DIRECTION_VERTICAL: DIRECTION_VERTICAL,
|
24605 | DIRECTION_ALL: DIRECTION_ALL,
|
24606 |
|
24607 | Manager: Manager,
|
24608 | Input: Input,
|
24609 | TouchAction: TouchAction,
|
24610 |
|
24611 | TouchInput: TouchInput,
|
24612 | MouseInput: MouseInput,
|
24613 | PointerEventInput: PointerEventInput,
|
24614 | TouchMouseInput: TouchMouseInput,
|
24615 | SingleTouchInput: SingleTouchInput,
|
24616 |
|
24617 | Recognizer: Recognizer,
|
24618 | AttrRecognizer: AttrRecognizer,
|
24619 | Tap: TapRecognizer,
|
24620 | Pan: PanRecognizer,
|
24621 | Swipe: SwipeRecognizer,
|
24622 | Pinch: PinchRecognizer,
|
24623 | Rotate: RotateRecognizer,
|
24624 | Press: PressRecognizer,
|
24625 |
|
24626 | on: addEventListeners,
|
24627 | off: removeEventListeners,
|
24628 | each: each,
|
24629 | merge: merge,
|
24630 | extend: extend,
|
24631 | assign: assign,
|
24632 | inherit: inherit,
|
24633 | bindFn: bindFn,
|
24634 | prefixed: prefixed
|
24635 | });
|
24636 |
|
24637 |
|
24638 |
|
24639 | var freeGlobal = (typeof window !== 'undefined' ? window : (typeof self !== 'undefined' ? self : {}));
|
24640 | freeGlobal.Hammer = Hammer;
|
24641 |
|
24642 | if (typeof undefined$1 === 'function' && undefined$1.amd) {
|
24643 | undefined$1(function() {
|
24644 | return Hammer;
|
24645 | });
|
24646 | } else if ( module.exports) {
|
24647 | module.exports = Hammer;
|
24648 | } else {
|
24649 | window[exportName] = Hammer;
|
24650 | }
|
24651 |
|
24652 | })(window, document, 'Hammer');
|
24653 | });
|
24654 |
|
24655 | var MIN_ZOOM = 0.2,
|
24656 | MAX_ZOOM = 4;
|
24657 |
|
24658 | var mouseEvents = [
|
24659 | 'mousedown',
|
24660 | 'mouseup',
|
24661 | 'mouseover',
|
24662 | 'mouseout',
|
24663 | 'click',
|
24664 | 'dblclick'
|
24665 | ];
|
24666 |
|
24667 | function get$1(service, injector) {
|
24668 | return injector.get(service, false);
|
24669 | }
|
24670 |
|
24671 | function stopEvent(event) {
|
24672 |
|
24673 | event.preventDefault();
|
24674 | event.stopPropagation();
|
24675 |
|
24676 | if (typeof event.stopImmediatePropagation === 'function') {
|
24677 | event.stopImmediatePropagation();
|
24678 | }
|
24679 | }
|
24680 |
|
24681 |
|
24682 | function createTouchRecognizer(node) {
|
24683 |
|
24684 | function stopMouse(event) {
|
24685 |
|
24686 | forEach(mouseEvents, function(e) {
|
24687 | componentEvent.bind(node, e, stopEvent, true);
|
24688 | });
|
24689 | }
|
24690 |
|
24691 | function allowMouse(event) {
|
24692 | setTimeout(function() {
|
24693 | forEach(mouseEvents, function(e) {
|
24694 | componentEvent.unbind(node, e, stopEvent, true);
|
24695 | });
|
24696 | }, 500);
|
24697 | }
|
24698 |
|
24699 | componentEvent.bind(node, 'touchstart', stopMouse, true);
|
24700 | componentEvent.bind(node, 'touchend', allowMouse, true);
|
24701 | componentEvent.bind(node, 'touchcancel', allowMouse, true);
|
24702 |
|
24703 |
|
24704 |
|
24705 |
|
24706 |
|
24707 | var recognizer = new hammer.Manager(node, {
|
24708 | inputClass: hammer.TouchInput,
|
24709 | recognizers: []
|
24710 | });
|
24711 |
|
24712 |
|
24713 | var tap = new hammer.Tap();
|
24714 | var pan = new hammer.Pan({ threshold: 10 });
|
24715 | var press = new hammer.Press();
|
24716 | var pinch = new hammer.Pinch();
|
24717 |
|
24718 | var doubleTap = new hammer.Tap({ event: 'doubletap', taps: 2 });
|
24719 |
|
24720 | pinch.requireFailure(pan);
|
24721 | pinch.requireFailure(press);
|
24722 |
|
24723 | recognizer.add([ pan, press, pinch, doubleTap, tap ]);
|
24724 |
|
24725 | recognizer.reset = function(force) {
|
24726 | var recognizers = this.recognizers,
|
24727 | session = this.session;
|
24728 |
|
24729 | if (session.stopped) {
|
24730 | return;
|
24731 | }
|
24732 |
|
24733 | recognizer.stop(force);
|
24734 |
|
24735 | setTimeout(function() {
|
24736 | var i, r;
|
24737 | for (i = 0; (r = recognizers[i]); i++) {
|
24738 | r.reset();
|
24739 | r.state = 8;
|
24740 | }
|
24741 |
|
24742 | session.curRecognizer = null;
|
24743 | }, 0);
|
24744 | };
|
24745 |
|
24746 | recognizer.on('hammer.input', function(event) {
|
24747 | if (event.srcEvent.defaultPrevented) {
|
24748 | recognizer.reset(true);
|
24749 | }
|
24750 | });
|
24751 |
|
24752 | return recognizer;
|
24753 | }
|
24754 |
|
24755 | |
24756 |
|
24757 |
|
24758 |
|
24759 |
|
24760 |
|
24761 | function TouchInteractionEvents(
|
24762 | injector, canvas, eventBus,
|
24763 | elementRegistry, interactionEvents) {
|
24764 |
|
24765 |
|
24766 | var dragging = get$1('dragging', injector),
|
24767 | move = get$1('move', injector),
|
24768 | contextPad = get$1('contextPad', injector),
|
24769 | palette = get$1('palette', injector);
|
24770 |
|
24771 | // the touch recognizer
|
24772 | var recognizer;
|
24773 |
|
24774 | function handler(type) {
|
24775 |
|
24776 | return function(event) {
|
24777 |
|
24778 | interactionEvents.fire(type, event);
|
24779 | };
|
24780 | }
|
24781 |
|
24782 | function getGfx(target) {
|
24783 | var node = closest(target, 'svg, .djs-element', true);
|
24784 | return node;
|
24785 | }
|
24786 |
|
24787 | function initEvents(svg) {
|
24788 |
|
24789 |
|
24790 | recognizer = createTouchRecognizer(svg);
|
24791 |
|
24792 | recognizer.on('doubletap', handler('element.dblclick'));
|
24793 |
|
24794 | recognizer.on('tap', handler('element.click'));
|
24795 |
|
24796 | function startGrabCanvas(event) {
|
24797 |
|
24798 | var lx = 0, ly = 0;
|
24799 |
|
24800 | function update(e) {
|
24801 |
|
24802 | var dx = e.deltaX - lx,
|
24803 | dy = e.deltaY - ly;
|
24804 |
|
24805 | canvas.scroll({ dx: dx, dy: dy });
|
24806 |
|
24807 | lx = e.deltaX;
|
24808 | ly = e.deltaY;
|
24809 | }
|
24810 |
|
24811 | function end(e) {
|
24812 | recognizer.off('panmove', update);
|
24813 | recognizer.off('panend', end);
|
24814 | recognizer.off('pancancel', end);
|
24815 | }
|
24816 |
|
24817 | recognizer.on('panmove', update);
|
24818 | recognizer.on('panend', end);
|
24819 | recognizer.on('pancancel', end);
|
24820 | }
|
24821 |
|
24822 | function startGrab(event) {
|
24823 |
|
24824 | var gfx = getGfx(event.target),
|
24825 | element = gfx && elementRegistry.get(gfx);
|
24826 |
|
24827 |
|
24828 | if (move && canvas.getRootElement() !== element) {
|
24829 | return move.start(event, element, true);
|
24830 | } else {
|
24831 | startGrabCanvas();
|
24832 | }
|
24833 | }
|
24834 |
|
24835 | function startZoom(e) {
|
24836 |
|
24837 | var zoom = canvas.zoom(),
|
24838 | mid = e.center;
|
24839 |
|
24840 | function update(e) {
|
24841 |
|
24842 | var ratio = 1 - (1 - e.scale) / 1.50,
|
24843 | newZoom = Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, ratio * zoom));
|
24844 |
|
24845 | canvas.zoom(newZoom, mid);
|
24846 |
|
24847 | stopEvent(e);
|
24848 | }
|
24849 |
|
24850 | function end(e) {
|
24851 | recognizer.off('pinchmove', update);
|
24852 | recognizer.off('pinchend', end);
|
24853 | recognizer.off('pinchcancel', end);
|
24854 |
|
24855 | recognizer.reset(true);
|
24856 | }
|
24857 |
|
24858 | recognizer.on('pinchmove', update);
|
24859 | recognizer.on('pinchend', end);
|
24860 | recognizer.on('pinchcancel', end);
|
24861 | }
|
24862 |
|
24863 | recognizer.on('panstart', startGrab);
|
24864 | recognizer.on('press', startGrab);
|
24865 |
|
24866 | recognizer.on('pinchstart', startZoom);
|
24867 | }
|
24868 |
|
24869 | if (dragging) {
|
24870 |
|
24871 |
|
24872 | eventBus.on('drag.move', function(event) {
|
24873 |
|
24874 | var originalEvent = event.originalEvent;
|
24875 |
|
24876 | if (!originalEvent || originalEvent instanceof MouseEvent) {
|
24877 | return;
|
24878 | }
|
24879 |
|
24880 | var position = toPoint(originalEvent);
|
24881 |
|
24882 |
|
24883 | var node = document.elementFromPoint(position.x, position.y),
|
24884 | gfx = getGfx(node),
|
24885 | element = gfx && elementRegistry.get(gfx);
|
24886 |
|
24887 | if (element !== event.hover) {
|
24888 | if (event.hover) {
|
24889 | dragging.out(event);
|
24890 | }
|
24891 |
|
24892 | if (element) {
|
24893 | dragging.hover({ element: element, gfx: gfx });
|
24894 |
|
24895 | event.hover = element;
|
24896 | event.hoverGfx = gfx;
|
24897 | }
|
24898 | }
|
24899 | });
|
24900 | }
|
24901 |
|
24902 | if (contextPad) {
|
24903 |
|
24904 | eventBus.on('contextPad.create', function(event) {
|
24905 | var node = event.pad.html;
|
24906 |
|
24907 |
|
24908 | var padRecognizer = createTouchRecognizer(node);
|
24909 |
|
24910 | padRecognizer.on('panstart', function(event) {
|
24911 | contextPad.trigger('dragstart', event, true);
|
24912 | });
|
24913 |
|
24914 | padRecognizer.on('press', function(event) {
|
24915 | contextPad.trigger('dragstart', event, true);
|
24916 | });
|
24917 |
|
24918 | padRecognizer.on('tap', function(event) {
|
24919 | contextPad.trigger('click', event);
|
24920 | });
|
24921 | });
|
24922 | }
|
24923 |
|
24924 | if (palette) {
|
24925 | eventBus.on('palette.create', function(event) {
|
24926 | var node = event.container;
|
24927 |
|
24928 |
|
24929 | var padRecognizer = createTouchRecognizer(node);
|
24930 |
|
24931 | padRecognizer.on('panstart', function(event) {
|
24932 | palette.trigger('dragstart', event, true);
|
24933 | });
|
24934 |
|
24935 | padRecognizer.on('press', function(event) {
|
24936 | palette.trigger('dragstart', event, true);
|
24937 | });
|
24938 |
|
24939 | padRecognizer.on('tap', function(event) {
|
24940 | palette.trigger('click', event);
|
24941 | });
|
24942 | });
|
24943 | }
|
24944 |
|
24945 | eventBus.on('canvas.init', function(event) {
|
24946 | initEvents(event.svg);
|
24947 | });
|
24948 | }
|
24949 |
|
24950 |
|
24951 | TouchInteractionEvents.$inject = [
|
24952 | 'injector',
|
24953 | 'canvas',
|
24954 | 'eventBus',
|
24955 | 'elementRegistry',
|
24956 | 'interactionEvents',
|
24957 | 'touchFix'
|
24958 | ];
|
24959 |
|
24960 | function TouchFix(canvas, eventBus) {
|
24961 |
|
24962 | var self = this;
|
24963 |
|
24964 | eventBus.on('canvas.init', function(e) {
|
24965 | self.addBBoxMarker(e.svg);
|
24966 | });
|
24967 | }
|
24968 |
|
24969 | TouchFix.$inject = [ 'canvas', 'eventBus' ];
|
24970 |
|
24971 |
|
24972 | |
24973 |
|
24974 |
|
24975 |
|
24976 |
|
24977 |
|
24978 |
|
24979 | TouchFix.prototype.addBBoxMarker = function(svg) {
|
24980 |
|
24981 | var markerStyle = {
|
24982 | fill: 'none',
|
24983 | class: 'outer-bound-marker'
|
24984 | };
|
24985 |
|
24986 | var rect1 = create('rect');
|
24987 | attr$1(rect1, {
|
24988 | x: -10000,
|
24989 | y: 10000,
|
24990 | width: 10,
|
24991 | height: 10
|
24992 | });
|
24993 | attr$1(rect1, markerStyle);
|
24994 |
|
24995 | append(svg, rect1);
|
24996 |
|
24997 | var rect2 = create('rect');
|
24998 | attr$1(rect2, {
|
24999 | x: 10000,
|
25000 | y: 10000,
|
25001 | width: 10,
|
25002 | height: 10
|
25003 | });
|
25004 | attr$1(rect2, markerStyle);
|
25005 |
|
25006 | append(svg, rect2);
|
25007 | };
|
25008 |
|
25009 | var TouchModule = {
|
25010 | __depends__: [ InteractionEventsModule ],
|
25011 | __init__: [ 'touchInteractionEvents' ],
|
25012 | touchInteractionEvents: [ 'type', TouchInteractionEvents ],
|
25013 | touchFix: [ 'type', TouchFix ]
|
25014 | };
|
25015 |
|
25016 | var TouchModule$1 = {
|
25017 | __depends__: [
|
25018 | TouchModule
|
25019 | ]
|
25020 | };
|
25021 |
|
25022 | function last(arr) {
|
25023 | return arr && arr[arr.length - 1];
|
25024 | }
|
25025 |
|
25026 | function sortTopOrMiddle(element) {
|
25027 | return element.y;
|
25028 | }
|
25029 |
|
25030 | function sortLeftOrCenter(element) {
|
25031 | return element.x;
|
25032 | }
|
25033 |
|
25034 | |
25035 |
|
25036 |
|
25037 |
|
25038 |
|
25039 |
|
25040 |
|
25041 | var ALIGNMENT_SORTING = {
|
25042 | left: sortLeftOrCenter,
|
25043 | center: sortLeftOrCenter,
|
25044 | right: function(element) {
|
25045 | return element.x + element.width;
|
25046 | },
|
25047 | top: sortTopOrMiddle,
|
25048 | middle: sortTopOrMiddle,
|
25049 | bottom: function(element) {
|
25050 | return element.y + element.height;
|
25051 | }
|
25052 | };
|
25053 |
|
25054 |
|
25055 | function AlignElements(modeling) {
|
25056 | this._modeling = modeling;
|
25057 | }
|
25058 |
|
25059 | AlignElements.$inject = [ 'modeling' ];
|
25060 |
|
25061 |
|
25062 | |
25063 |
|
25064 |
|
25065 |
|
25066 |
|
25067 |
|
25068 |
|
25069 | AlignElements.prototype._getOrientationDetails = function(type) {
|
25070 | var vertical = [ 'top', 'bottom', 'middle' ],
|
25071 | axis = 'x',
|
25072 | dimension = 'width';
|
25073 |
|
25074 | if (vertical.indexOf(type) !== -1) {
|
25075 | axis = 'y';
|
25076 | dimension = 'height';
|
25077 | }
|
25078 |
|
25079 | return {
|
25080 | axis: axis,
|
25081 | dimension: dimension
|
25082 | };
|
25083 | };
|
25084 |
|
25085 | AlignElements.prototype._isType = function(type, types) {
|
25086 | return types.indexOf(type) !== -1;
|
25087 | };
|
25088 |
|
25089 | |
25090 |
|
25091 |
|
25092 |
|
25093 |
|
25094 |
|
25095 |
|
25096 |
|
25097 | AlignElements.prototype._alignmentPosition = function(type, sortedElements) {
|
25098 | var orientation = this._getOrientationDetails(type),
|
25099 | axis = orientation.axis,
|
25100 | dimension = orientation.dimension,
|
25101 | alignment = {},
|
25102 | centers = {},
|
25103 | hasSharedCenters = false,
|
25104 | centeredElements,
|
25105 | firstElement,
|
25106 | lastElement;
|
25107 |
|
25108 | function getMiddleOrTop(first, last) {
|
25109 | return Math.round((first[axis] + last[axis] + last[dimension]) / 2);
|
25110 | }
|
25111 |
|
25112 | if (this._isType(type, [ 'left', 'top' ])) {
|
25113 | alignment[type] = sortedElements[0][axis];
|
25114 |
|
25115 | } else if (this._isType(type, [ 'right', 'bottom' ])) {
|
25116 | lastElement = last(sortedElements);
|
25117 |
|
25118 | alignment[type] = lastElement[axis] + lastElement[dimension];
|
25119 |
|
25120 | } else if (this._isType(type, [ 'center', 'middle' ])) {
|
25121 |
|
25122 |
|
25123 |
|
25124 | forEach(sortedElements, function(element) {
|
25125 | var center = element[axis] + Math.round(element[dimension] / 2);
|
25126 |
|
25127 | if (centers[center]) {
|
25128 | centers[center].elements.push(element);
|
25129 | } else {
|
25130 | centers[center] = {
|
25131 | elements: [ element ],
|
25132 | center: center
|
25133 | };
|
25134 | }
|
25135 | });
|
25136 |
|
25137 | centeredElements = sortBy(centers, function(center) {
|
25138 | if (center.elements.length > 1) {
|
25139 | hasSharedCenters = true;
|
25140 | }
|
25141 |
|
25142 | return center.elements.length;
|
25143 | });
|
25144 |
|
25145 | if (hasSharedCenters) {
|
25146 | alignment[type] = last(centeredElements).center;
|
25147 |
|
25148 | return alignment;
|
25149 | }
|
25150 |
|
25151 | firstElement = sortedElements[0];
|
25152 |
|
25153 | sortedElements = sortBy(sortedElements, function(element) {
|
25154 | return element[axis] + element[dimension];
|
25155 | });
|
25156 |
|
25157 | lastElement = last(sortedElements);
|
25158 |
|
25159 | alignment[type] = getMiddleOrTop(firstElement, lastElement);
|
25160 | }
|
25161 |
|
25162 | return alignment;
|
25163 | };
|
25164 |
|
25165 | |
25166 |
|
25167 |
|
25168 |
|
25169 |
|
25170 |
|
25171 | AlignElements.prototype.trigger = function(elements, type) {
|
25172 | var modeling = this._modeling;
|
25173 |
|
25174 | var filteredElements = filter(elements, function(element) {
|
25175 | return !(element.waypoints || element.host || element.labelTarget);
|
25176 | });
|
25177 |
|
25178 | var sortFn = ALIGNMENT_SORTING[type];
|
25179 |
|
25180 | var sortedElements = sortBy(filteredElements, sortFn);
|
25181 |
|
25182 | var alignment = this._alignmentPosition(type, sortedElements);
|
25183 |
|
25184 | modeling.alignElements(sortedElements, alignment);
|
25185 | };
|
25186 |
|
25187 | var AlignElementsModule = {
|
25188 | __init__: [ 'alignElements' ],
|
25189 | alignElements: [ 'type', AlignElements ]
|
25190 | };
|
25191 |
|
25192 | |
25193 |
|
25194 |
|
25195 |
|
25196 |
|
25197 |
|
25198 |
|
25199 |
|
25200 | function isAny(element, types) {
|
25201 | return some(types, function(t) {
|
25202 | return is$1(element, t);
|
25203 | });
|
25204 | }
|
25205 |
|
25206 |
|
25207 | |
25208 |
|
25209 |
|
25210 |
|
25211 |
|
25212 |
|
25213 |
|
25214 |
|
25215 | function getParent$1(element, anyType) {
|
25216 |
|
25217 | if (typeof anyType === 'string') {
|
25218 | anyType = [ anyType ];
|
25219 | }
|
25220 |
|
25221 | while ((element = element.parent)) {
|
25222 | if (isAny(element, anyType)) {
|
25223 | return element;
|
25224 | }
|
25225 | }
|
25226 |
|
25227 | return null;
|
25228 | }
|
25229 |
|
25230 | var DEFAULT_HORIZONTAL_DISTANCE = 50;
|
25231 |
|
25232 | var MAX_HORIZONTAL_DISTANCE = 250;
|
25233 |
|
25234 |
|
25235 | var PLACEMENT_DETECTION_PAD = 10;
|
25236 |
|
25237 | |
25238 |
|
25239 |
|
25240 |
|
25241 |
|
25242 |
|
25243 |
|
25244 |
|
25245 |
|
25246 | function getNewShapePosition(source, element) {
|
25247 |
|
25248 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
25249 | return getTextAnnotationPosition(source, element);
|
25250 | }
|
25251 |
|
25252 | if (isAny(element, [ 'bpmn:DataObjectReference', 'bpmn:DataStoreReference' ])) {
|
25253 | return getDataElementPosition(source, element);
|
25254 | }
|
25255 |
|
25256 | if (is$1(element, 'bpmn:FlowNode')) {
|
25257 | return getFlowNodePosition(source, element);
|
25258 | }
|
25259 |
|
25260 | return getDefaultPosition(source, element);
|
25261 | }
|
25262 |
|
25263 | |
25264 |
|
25265 |
|
25266 |
|
25267 | function getFlowNodePosition(source, element) {
|
25268 |
|
25269 | var sourceTrbl = asTRBL(source);
|
25270 | var sourceMid = getMid(source);
|
25271 |
|
25272 | var horizontalDistance = getFlowNodeDistance(source);
|
25273 |
|
25274 | var orientation = 'left',
|
25275 | rowSize = 80,
|
25276 | margin = 30;
|
25277 |
|
25278 | if (is$1(source, 'bpmn:BoundaryEvent')) {
|
25279 | orientation = getOrientation(source, source.host, -25);
|
25280 |
|
25281 | if (orientation.indexOf('top') !== -1) {
|
25282 | margin *= -1;
|
25283 | }
|
25284 | }
|
25285 |
|
25286 | function getVerticalDistance(orient) {
|
25287 | if (orient.indexOf('top') != -1) {
|
25288 | return -1 * rowSize;
|
25289 | } else if (orient.indexOf('bottom') != -1) {
|
25290 | return rowSize;
|
25291 | } else {
|
25292 | return 0;
|
25293 | }
|
25294 | }
|
25295 |
|
25296 | var position = {
|
25297 | x: sourceTrbl.right + horizontalDistance + element.width / 2,
|
25298 | y: sourceMid.y + getVerticalDistance(orientation)
|
25299 | };
|
25300 |
|
25301 | var escapeDirection = {
|
25302 | y: {
|
25303 | margin: margin,
|
25304 | rowSize: rowSize
|
25305 | }
|
25306 | };
|
25307 |
|
25308 | return deconflictPosition(source, element, position, escapeDirection);
|
25309 | }
|
25310 |
|
25311 |
|
25312 | |
25313 |
|
25314 |
|
25315 |
|
25316 |
|
25317 |
|
25318 |
|
25319 |
|
25320 |
|
25321 | function getFlowNodeDistance(source, element) {
|
25322 |
|
25323 | var sourceTrbl = asTRBL(source);
|
25324 |
|
25325 |
|
25326 | function isReference(c) {
|
25327 | return is$1(c, 'bpmn:SequenceFlow');
|
25328 | }
|
25329 |
|
25330 | function toTargetNode(weight) {
|
25331 |
|
25332 | return function(shape) {
|
25333 | return {
|
25334 | shape: shape,
|
25335 | weight: weight,
|
25336 | distanceTo: function(shape) {
|
25337 | var shapeTrbl = asTRBL(shape);
|
25338 |
|
25339 | return shapeTrbl.left - sourceTrbl.right;
|
25340 | }
|
25341 | };
|
25342 | };
|
25343 | }
|
25344 |
|
25345 | function toSourceNode(weight) {
|
25346 | return function(shape) {
|
25347 | return {
|
25348 | shape: shape,
|
25349 | weight: weight,
|
25350 | distanceTo: function(shape) {
|
25351 | var shapeTrbl = asTRBL(shape);
|
25352 |
|
25353 | return sourceTrbl.left - shapeTrbl.right;
|
25354 | }
|
25355 | };
|
25356 | };
|
25357 | }
|
25358 |
|
25359 |
|
25360 |
|
25361 |
|
25362 |
|
25363 |
|
25364 |
|
25365 | var nodes = reduce([].concat(
|
25366 | getTargets(source, isReference).map(toTargetNode(5)),
|
25367 | getSources(source, isReference).map(toSourceNode(1))
|
25368 | ), function(nodes, node) {
|
25369 |
|
25370 |
|
25371 | nodes[node.shape.id + '__weight_' + node.weight] = node;
|
25372 |
|
25373 | return nodes;
|
25374 | }, {});
|
25375 |
|
25376 |
|
25377 |
|
25378 |
|
25379 | var distancesGrouped = reduce(nodes, function(result, node) {
|
25380 |
|
25381 | var shape = node.shape,
|
25382 | weight = node.weight,
|
25383 | distanceTo = node.distanceTo;
|
25384 |
|
25385 | var fav = result.fav,
|
25386 | currentDistance,
|
25387 | currentDistanceCount,
|
25388 | currentDistanceEntry;
|
25389 |
|
25390 | currentDistance = distanceTo(shape);
|
25391 |
|
25392 |
|
25393 |
|
25394 | if (currentDistance < 0 || currentDistance > MAX_HORIZONTAL_DISTANCE) {
|
25395 | return result;
|
25396 | }
|
25397 |
|
25398 | currentDistanceEntry = result[String(currentDistance)] =
|
25399 | result[String(currentDistance)] || {
|
25400 | value: currentDistance,
|
25401 | count: 0
|
25402 | };
|
25403 |
|
25404 |
|
25405 | currentDistanceCount = currentDistanceEntry.count += 1 * weight;
|
25406 |
|
25407 | if (!fav || fav.count < currentDistanceCount) {
|
25408 | result.fav = currentDistanceEntry;
|
25409 | }
|
25410 |
|
25411 | return result;
|
25412 | }, { });
|
25413 |
|
25414 |
|
25415 | if (distancesGrouped.fav) {
|
25416 | return distancesGrouped.fav.value;
|
25417 | } else {
|
25418 | return DEFAULT_HORIZONTAL_DISTANCE;
|
25419 | }
|
25420 | }
|
25421 |
|
25422 |
|
25423 | |
25424 |
|
25425 |
|
25426 | function getTextAnnotationPosition(source, element) {
|
25427 |
|
25428 | var sourceTrbl = asTRBL(source);
|
25429 |
|
25430 | var position = {
|
25431 | x: sourceTrbl.right + element.width / 2,
|
25432 | y: sourceTrbl.top - 50 - element.height / 2
|
25433 | };
|
25434 |
|
25435 | var escapeDirection = {
|
25436 | y: {
|
25437 | margin: -30,
|
25438 | rowSize: 20
|
25439 | }
|
25440 | };
|
25441 |
|
25442 | return deconflictPosition(source, element, position, escapeDirection);
|
25443 | }
|
25444 |
|
25445 |
|
25446 | |
25447 |
|
25448 |
|
25449 | function getDataElementPosition(source, element) {
|
25450 |
|
25451 | var sourceTrbl = asTRBL(source);
|
25452 |
|
25453 | var position = {
|
25454 | x: sourceTrbl.right - 10 + element.width / 2,
|
25455 | y: sourceTrbl.bottom + 40 + element.width / 2
|
25456 | };
|
25457 |
|
25458 | var escapeDirection = {
|
25459 | x: {
|
25460 | margin: 30,
|
25461 | rowSize: 30
|
25462 | }
|
25463 | };
|
25464 |
|
25465 | return deconflictPosition(source, element, position, escapeDirection);
|
25466 | }
|
25467 |
|
25468 |
|
25469 | |
25470 |
|
25471 |
|
25472 | function getDefaultPosition(source, element) {
|
25473 |
|
25474 | var sourceTrbl = asTRBL(source);
|
25475 |
|
25476 | var sourceMid = getMid(source);
|
25477 |
|
25478 |
|
25479 | return {
|
25480 | x: sourceTrbl.right + DEFAULT_HORIZONTAL_DISTANCE + element.width / 2,
|
25481 | y: sourceMid.y
|
25482 | };
|
25483 | }
|
25484 |
|
25485 |
|
25486 | |
25487 |
|
25488 |
|
25489 |
|
25490 |
|
25491 |
|
25492 |
|
25493 |
|
25494 |
|
25495 |
|
25496 |
|
25497 |
|
25498 |
|
25499 |
|
25500 | function getAutoPlaceClosure(source, element) {
|
25501 |
|
25502 | var allConnected = getConnected(source);
|
25503 |
|
25504 | if (source.host) {
|
25505 | allConnected = allConnected.concat(getConnected(source.host));
|
25506 | }
|
25507 |
|
25508 | if (source.attachers) {
|
25509 | allConnected = allConnected.concat(source.attachers.reduce(function(shapes, attacher) {
|
25510 | return shapes.concat(getConnected(attacher));
|
25511 | }, []));
|
25512 | }
|
25513 |
|
25514 | return allConnected;
|
25515 | }
|
25516 |
|
25517 | |
25518 |
|
25519 |
|
25520 |
|
25521 |
|
25522 |
|
25523 | function getConnectedAtPosition(source, position, element) {
|
25524 |
|
25525 | var bounds = {
|
25526 | x: position.x - (element.width / 2),
|
25527 | y: position.y - (element.height / 2),
|
25528 | width: element.width,
|
25529 | height: element.height
|
25530 | };
|
25531 |
|
25532 | var closure = getAutoPlaceClosure(source);
|
25533 |
|
25534 | return find(closure, function(target) {
|
25535 |
|
25536 | if (target === element) {
|
25537 | return false;
|
25538 | }
|
25539 |
|
25540 | var orientation = getOrientation(target, bounds, PLACEMENT_DETECTION_PAD);
|
25541 |
|
25542 | return orientation === 'intersect';
|
25543 | });
|
25544 | }
|
25545 |
|
25546 |
|
25547 | |
25548 |
|
25549 |
|
25550 |
|
25551 |
|
25552 |
|
25553 |
|
25554 |
|
25555 |
|
25556 |
|
25557 |
|
25558 |
|
25559 |
|
25560 |
|
25561 |
|
25562 | function deconflictPosition(source, element, position, escapeDelta) {
|
25563 |
|
25564 | function nextPosition(existingElement) {
|
25565 |
|
25566 | var newPosition = {
|
25567 | x: position.x,
|
25568 | y: position.y
|
25569 | };
|
25570 |
|
25571 | [ 'x', 'y' ].forEach(function(axis) {
|
25572 |
|
25573 | var axisDelta = escapeDelta[axis];
|
25574 |
|
25575 | if (!axisDelta) {
|
25576 | return;
|
25577 | }
|
25578 |
|
25579 | var dimension = axis === 'x' ? 'width' : 'height';
|
25580 |
|
25581 | var margin = axisDelta.margin,
|
25582 | rowSize = axisDelta.rowSize;
|
25583 |
|
25584 | if (margin < 0) {
|
25585 | newPosition[axis] = Math.min(
|
25586 | existingElement[axis] + margin - element[dimension] / 2,
|
25587 | position[axis] - rowSize + margin
|
25588 | );
|
25589 | } else {
|
25590 | newPosition[axis] = Math.max(
|
25591 | existingTarget[axis] + existingTarget[dimension] + margin + element[dimension] / 2,
|
25592 | position[axis] + rowSize + margin
|
25593 | );
|
25594 | }
|
25595 | });
|
25596 |
|
25597 | return newPosition;
|
25598 | }
|
25599 |
|
25600 | var existingTarget;
|
25601 |
|
25602 |
|
25603 | while ((existingTarget = getConnectedAtPosition(source, position, element))) {
|
25604 | position = nextPosition(existingTarget);
|
25605 | }
|
25606 |
|
25607 | return position;
|
25608 | }
|
25609 |
|
25610 |
|
25611 |
|
25612 |
|
25613 |
|
25614 | function noneFilter() {
|
25615 | return true;
|
25616 | }
|
25617 |
|
25618 | function getConnected(element, connectionFilter) {
|
25619 | return [].concat(
|
25620 | getTargets(element, connectionFilter),
|
25621 | getSources(element, connectionFilter)
|
25622 | );
|
25623 | }
|
25624 |
|
25625 | function getSources(shape, connectionFilter) {
|
25626 |
|
25627 | if (!connectionFilter) {
|
25628 | connectionFilter = noneFilter;
|
25629 | }
|
25630 |
|
25631 | return shape.incoming.filter(connectionFilter).map(function(c) {
|
25632 | return c.source;
|
25633 | });
|
25634 | }
|
25635 |
|
25636 | function getTargets(shape, connectionFilter) {
|
25637 |
|
25638 | if (!connectionFilter) {
|
25639 | connectionFilter = noneFilter;
|
25640 | }
|
25641 |
|
25642 | return shape.outgoing.filter(connectionFilter).map(function(c) {
|
25643 | return c.target;
|
25644 | });
|
25645 | }
|
25646 |
|
25647 | |
25648 |
|
25649 |
|
25650 |
|
25651 |
|
25652 |
|
25653 |
|
25654 | function AutoPlace(eventBus, modeling) {
|
25655 |
|
25656 | function emit(event, payload) {
|
25657 | return eventBus.fire(event, payload);
|
25658 | }
|
25659 |
|
25660 |
|
25661 | |
25662 |
|
25663 |
|
25664 |
|
25665 |
|
25666 |
|
25667 |
|
25668 |
|
25669 | this.append = function(source, shape) {
|
25670 |
|
25671 |
|
25672 | var position = emit('autoPlace', {
|
25673 | source: source,
|
25674 | shape: shape
|
25675 | });
|
25676 |
|
25677 | if (!position) {
|
25678 | position = getNewShapePosition(source, shape);
|
25679 | }
|
25680 |
|
25681 | var newShape = modeling.appendShape(source, shape, position, source.parent);
|
25682 |
|
25683 |
|
25684 | emit('autoPlace.end', {
|
25685 | shape: newShape
|
25686 | });
|
25687 |
|
25688 | return newShape;
|
25689 | };
|
25690 |
|
25691 | }
|
25692 |
|
25693 | AutoPlace.$inject = [
|
25694 | 'eventBus',
|
25695 | 'modeling'
|
25696 | ];
|
25697 |
|
25698 | |
25699 |
|
25700 |
|
25701 |
|
25702 |
|
25703 |
|
25704 | function AutoPlaceSelectionBehavior(eventBus, selection) {
|
25705 |
|
25706 | eventBus.on('autoPlace.end', 500, function(e) {
|
25707 | selection.select(e.shape);
|
25708 | });
|
25709 |
|
25710 | }
|
25711 |
|
25712 | AutoPlaceSelectionBehavior.$inject = [
|
25713 | 'eventBus',
|
25714 | 'selection'
|
25715 | ];
|
25716 |
|
25717 | var AutoPlaceModule = {
|
25718 | __init__: [ 'autoPlaceSelectionBehavior' ],
|
25719 | autoPlace: [ 'type', AutoPlace ],
|
25720 | autoPlaceSelectionBehavior: [ 'type', AutoPlaceSelectionBehavior ]
|
25721 | };
|
25722 |
|
25723 | var DEFAULT_PRIORITY$2 = 1000;
|
25724 |
|
25725 | |
25726 |
|
25727 |
|
25728 |
|
25729 |
|
25730 |
|
25731 |
|
25732 |
|
25733 |
|
25734 |
|
25735 |
|
25736 |
|
25737 |
|
25738 |
|
25739 |
|
25740 |
|
25741 |
|
25742 |
|
25743 |
|
25744 |
|
25745 |
|
25746 |
|
25747 |
|
25748 | function CommandInterceptor(eventBus) {
|
25749 | this._eventBus = eventBus;
|
25750 | }
|
25751 |
|
25752 | CommandInterceptor.$inject = [ 'eventBus' ];
|
25753 |
|
25754 | function unwrapEvent(fn, that) {
|
25755 | return function(event) {
|
25756 | return fn.call(that || null, event.context, event.command, event);
|
25757 | };
|
25758 | }
|
25759 |
|
25760 | |
25761 |
|
25762 |
|
25763 |
|
25764 |
|
25765 |
|
25766 |
|
25767 |
|
25768 |
|
25769 |
|
25770 |
|
25771 | CommandInterceptor.prototype.on = function(events, hook, priority, handlerFn, unwrap, that) {
|
25772 |
|
25773 | if (isFunction(hook) || isNumber(hook)) {
|
25774 | that = unwrap;
|
25775 | unwrap = handlerFn;
|
25776 | handlerFn = priority;
|
25777 | priority = hook;
|
25778 | hook = null;
|
25779 | }
|
25780 |
|
25781 | if (isFunction(priority)) {
|
25782 | that = unwrap;
|
25783 | unwrap = handlerFn;
|
25784 | handlerFn = priority;
|
25785 | priority = DEFAULT_PRIORITY$2;
|
25786 | }
|
25787 |
|
25788 | if (isObject(unwrap)) {
|
25789 | that = unwrap;
|
25790 | unwrap = false;
|
25791 | }
|
25792 |
|
25793 | if (!isFunction(handlerFn)) {
|
25794 | throw new Error('handlerFn must be a function');
|
25795 | }
|
25796 |
|
25797 | if (!isArray(events)) {
|
25798 | events = [ events ];
|
25799 | }
|
25800 |
|
25801 | var eventBus = this._eventBus;
|
25802 |
|
25803 | forEach(events, function(event) {
|
25804 |
|
25805 |
|
25806 | var fullEvent = [ 'commandStack', event, hook ].filter(function(e) { return e; }).join('.');
|
25807 |
|
25808 | eventBus.on(fullEvent, priority, unwrap ? unwrapEvent(handlerFn, that) : handlerFn, that);
|
25809 | });
|
25810 | };
|
25811 |
|
25812 |
|
25813 | var hooks = [
|
25814 | 'canExecute',
|
25815 | 'preExecute',
|
25816 | 'preExecuted',
|
25817 | 'execute',
|
25818 | 'executed',
|
25819 | 'postExecute',
|
25820 | 'postExecuted',
|
25821 | 'revert',
|
25822 | 'reverted'
|
25823 | ];
|
25824 |
|
25825 | |
25826 |
|
25827 |
|
25828 |
|
25829 |
|
25830 |
|
25831 | forEach(hooks, function(hook) {
|
25832 |
|
25833 | |
25834 |
|
25835 |
|
25836 |
|
25837 |
|
25838 |
|
25839 |
|
25840 |
|
25841 |
|
25842 |
|
25843 |
|
25844 |
|
25845 | CommandInterceptor.prototype[hook] = function(events, priority, handlerFn, unwrap, that) {
|
25846 |
|
25847 | if (isFunction(events) || isNumber(events)) {
|
25848 | that = unwrap;
|
25849 | unwrap = handlerFn;
|
25850 | handlerFn = priority;
|
25851 | priority = events;
|
25852 | events = null;
|
25853 | }
|
25854 |
|
25855 | this.on(events, hook, priority, handlerFn, unwrap, that);
|
25856 | };
|
25857 | });
|
25858 |
|
25859 | |
25860 |
|
25861 |
|
25862 |
|
25863 |
|
25864 |
|
25865 |
|
25866 |
|
25867 |
|
25868 | function AutoResize(eventBus, elementRegistry, modeling, rules) {
|
25869 |
|
25870 | CommandInterceptor.call(this, eventBus);
|
25871 |
|
25872 | this._elementRegistry = elementRegistry;
|
25873 | this._modeling = modeling;
|
25874 | this._rules = rules;
|
25875 |
|
25876 | var self = this;
|
25877 |
|
25878 | this.postExecuted([ 'shape.create' ], function(event) {
|
25879 | var context = event.context,
|
25880 | hints = context.hints || {},
|
25881 | shape = context.shape,
|
25882 | parent = context.parent || context.newParent;
|
25883 |
|
25884 | if (hints.autoResize === false) {
|
25885 | return;
|
25886 | }
|
25887 |
|
25888 | self._expand([ shape ], parent);
|
25889 | });
|
25890 |
|
25891 | this.postExecuted([ 'elements.move' ], function(event) {
|
25892 | var context = event.context,
|
25893 | elements = flatten(values(context.closure.topLevel)),
|
25894 | hints = context.hints;
|
25895 |
|
25896 | var autoResize = hints ? hints.autoResize : true;
|
25897 |
|
25898 | if (autoResize === false) {
|
25899 | return;
|
25900 | }
|
25901 |
|
25902 | var expandings = groupBy(elements, function(element) {
|
25903 | return element.parent.id;
|
25904 | });
|
25905 |
|
25906 | forEach(expandings, function(elements, parentId) {
|
25907 |
|
25908 |
|
25909 | if (isArray(autoResize)) {
|
25910 | elements = elements.filter(function(element) {
|
25911 | return find(autoResize, matchPattern({ id: element.id }));
|
25912 | });
|
25913 | }
|
25914 |
|
25915 | self._expand(elements, parentId);
|
25916 | });
|
25917 | });
|
25918 |
|
25919 | this.postExecuted([ 'shape.toggleCollapse' ], function(event) {
|
25920 | var context = event.context,
|
25921 | hints = context.hints,
|
25922 | shape = context.shape;
|
25923 |
|
25924 | if (hints && hints.autoResize === false) {
|
25925 | return;
|
25926 | }
|
25927 |
|
25928 | if (shape.collapsed) {
|
25929 | return;
|
25930 | }
|
25931 |
|
25932 | self._expand(shape.children || [], shape);
|
25933 | });
|
25934 |
|
25935 | this.postExecuted([ 'shape.resize' ], function(event) {
|
25936 | var context = event.context,
|
25937 | hints = context.hints,
|
25938 | shape = context.shape,
|
25939 | parent = shape.parent;
|
25940 |
|
25941 | if (hints && hints.autoResize === false) {
|
25942 | return;
|
25943 | }
|
25944 |
|
25945 | if (parent) {
|
25946 | self._expand([ shape ], parent);
|
25947 | }
|
25948 | });
|
25949 |
|
25950 | }
|
25951 |
|
25952 | AutoResize.$inject = [
|
25953 | 'eventBus',
|
25954 | 'elementRegistry',
|
25955 | 'modeling',
|
25956 | 'rules'
|
25957 | ];
|
25958 |
|
25959 | inherits_browser(AutoResize, CommandInterceptor);
|
25960 |
|
25961 |
|
25962 | |
25963 |
|
25964 |
|
25965 |
|
25966 |
|
25967 |
|
25968 |
|
25969 |
|
25970 |
|
25971 |
|
25972 | AutoResize.prototype._getOptimalBounds = function(elements, target) {
|
25973 |
|
25974 | var offset = this.getOffset(target),
|
25975 | padding = this.getPadding(target);
|
25976 |
|
25977 | var elementsTrbl = asTRBL(getBBox(elements)),
|
25978 | targetTrbl = asTRBL(target);
|
25979 |
|
25980 | var newTrbl = {};
|
25981 |
|
25982 | if (elementsTrbl.top - targetTrbl.top < padding.top) {
|
25983 | newTrbl.top = elementsTrbl.top - offset.top;
|
25984 | }
|
25985 |
|
25986 | if (elementsTrbl.left - targetTrbl.left < padding.left) {
|
25987 | newTrbl.left = elementsTrbl.left - offset.left;
|
25988 | }
|
25989 |
|
25990 | if (targetTrbl.right - elementsTrbl.right < padding.right) {
|
25991 | newTrbl.right = elementsTrbl.right + offset.right;
|
25992 | }
|
25993 |
|
25994 | if (targetTrbl.bottom - elementsTrbl.bottom < padding.bottom) {
|
25995 | newTrbl.bottom = elementsTrbl.bottom + offset.bottom;
|
25996 | }
|
25997 |
|
25998 | return asBounds(assign({}, targetTrbl, newTrbl));
|
25999 | };
|
26000 |
|
26001 |
|
26002 | |
26003 |
|
26004 |
|
26005 |
|
26006 |
|
26007 |
|
26008 | AutoResize.prototype._expand = function(elements, target) {
|
26009 |
|
26010 | if (typeof target === 'string') {
|
26011 | target = this._elementRegistry.get(target);
|
26012 | }
|
26013 |
|
26014 | var allowed = this._rules.allowed('element.autoResize', {
|
26015 | elements: elements,
|
26016 | target: target
|
26017 | });
|
26018 |
|
26019 | if (!allowed) {
|
26020 | return;
|
26021 | }
|
26022 |
|
26023 |
|
26024 | var newBounds = this._getOptimalBounds(elements, target);
|
26025 |
|
26026 | if (!boundsChanged(newBounds, target)) {
|
26027 | return;
|
26028 | }
|
26029 |
|
26030 | var resizeDirections = getResizeDirections(pick(target, [ 'x', 'y', 'width', 'height' ]), newBounds);
|
26031 |
|
26032 |
|
26033 | this.resize(target, newBounds, {
|
26034 | autoResize: resizeDirections
|
26035 | });
|
26036 |
|
26037 | var parent = target.parent;
|
26038 |
|
26039 |
|
26040 | if (parent) {
|
26041 | this._expand([ target ], parent);
|
26042 | }
|
26043 | };
|
26044 |
|
26045 |
|
26046 | |
26047 |
|
26048 |
|
26049 |
|
26050 |
|
26051 |
|
26052 |
|
26053 | AutoResize.prototype.getOffset = function(shape) {
|
26054 | return { top: 60, bottom: 60, left: 100, right: 100 };
|
26055 | };
|
26056 |
|
26057 |
|
26058 | |
26059 |
|
26060 |
|
26061 |
|
26062 |
|
26063 |
|
26064 |
|
26065 |
|
26066 | AutoResize.prototype.getPadding = function(shape) {
|
26067 | return { top: 2, bottom: 2, left: 15, right: 15 };
|
26068 | };
|
26069 |
|
26070 |
|
26071 | |
26072 |
|
26073 |
|
26074 |
|
26075 |
|
26076 |
|
26077 |
|
26078 |
|
26079 | AutoResize.prototype.resize = function(shape, newBounds, hints) {
|
26080 | this._modeling.resizeShape(shape, newBounds, null, hints);
|
26081 | };
|
26082 |
|
26083 |
|
26084 | function boundsChanged(newBounds, oldBounds) {
|
26085 | return (
|
26086 | newBounds.x !== oldBounds.x ||
|
26087 | newBounds.y !== oldBounds.y ||
|
26088 | newBounds.width !== oldBounds.width ||
|
26089 | newBounds.height !== oldBounds.height
|
26090 | );
|
26091 | }
|
26092 |
|
26093 | |
26094 |
|
26095 |
|
26096 |
|
26097 |
|
26098 |
|
26099 |
|
26100 |
|
26101 | function getResizeDirections(oldBounds, newBounds) {
|
26102 | var directions = '';
|
26103 |
|
26104 | oldBounds = asTRBL(oldBounds);
|
26105 | newBounds = asTRBL(newBounds);
|
26106 |
|
26107 | if (oldBounds.top > newBounds.top) {
|
26108 | directions = directions.concat('n');
|
26109 | }
|
26110 |
|
26111 | if (oldBounds.right < newBounds.right) {
|
26112 | directions = directions.concat('w');
|
26113 | }
|
26114 |
|
26115 | if (oldBounds.bottom < newBounds.bottom) {
|
26116 | directions = directions.concat('s');
|
26117 | }
|
26118 |
|
26119 | if (oldBounds.left > newBounds.left) {
|
26120 | directions = directions.concat('e');
|
26121 | }
|
26122 |
|
26123 | return directions;
|
26124 | }
|
26125 |
|
26126 | |
26127 |
|
26128 |
|
26129 |
|
26130 | function BpmnAutoResize(injector) {
|
26131 |
|
26132 | injector.invoke(AutoResize, this);
|
26133 | }
|
26134 |
|
26135 | BpmnAutoResize.$inject = [
|
26136 | 'injector'
|
26137 | ];
|
26138 |
|
26139 | inherits_browser(BpmnAutoResize, AutoResize);
|
26140 |
|
26141 |
|
26142 | |
26143 |
|
26144 |
|
26145 |
|
26146 |
|
26147 |
|
26148 |
|
26149 | BpmnAutoResize.prototype.resize = function(target, newBounds, hints) {
|
26150 |
|
26151 | if (is$1(target, 'bpmn:Participant')) {
|
26152 | this._modeling.resizeLane(target, newBounds, null, hints);
|
26153 | } else {
|
26154 | this._modeling.resizeShape(target, newBounds, null, hints);
|
26155 | }
|
26156 | };
|
26157 |
|
26158 | |
26159 |
|
26160 |
|
26161 |
|
26162 |
|
26163 |
|
26164 |
|
26165 |
|
26166 | function RuleProvider(eventBus) {
|
26167 | CommandInterceptor.call(this, eventBus);
|
26168 |
|
26169 | this.init();
|
26170 | }
|
26171 |
|
26172 | RuleProvider.$inject = [ 'eventBus' ];
|
26173 |
|
26174 | inherits_browser(RuleProvider, CommandInterceptor);
|
26175 |
|
26176 |
|
26177 | |
26178 |
|
26179 |
|
26180 |
|
26181 |
|
26182 |
|
26183 |
|
26184 |
|
26185 |
|
26186 |
|
26187 |
|
26188 |
|
26189 |
|
26190 |
|
26191 |
|
26192 |
|
26193 |
|
26194 |
|
26195 |
|
26196 |
|
26197 |
|
26198 |
|
26199 |
|
26200 |
|
26201 |
|
26202 |
|
26203 |
|
26204 |
|
26205 |
|
26206 |
|
26207 |
|
26208 |
|
26209 |
|
26210 |
|
26211 |
|
26212 |
|
26213 |
|
26214 |
|
26215 |
|
26216 |
|
26217 |
|
26218 |
|
26219 |
|
26220 |
|
26221 | RuleProvider.prototype.addRule = function(actions, priority, fn) {
|
26222 |
|
26223 | var self = this;
|
26224 |
|
26225 | if (typeof actions === 'string') {
|
26226 | actions = [ actions ];
|
26227 | }
|
26228 |
|
26229 | actions.forEach(function(action) {
|
26230 |
|
26231 | self.canExecute(action, priority, function(context, action, event) {
|
26232 | return fn(context);
|
26233 | }, true);
|
26234 | });
|
26235 | };
|
26236 |
|
26237 | |
26238 |
|
26239 |
|
26240 | RuleProvider.prototype.init = function() {};
|
26241 |
|
26242 | |
26243 |
|
26244 |
|
26245 | function AutoResizeProvider(eventBus) {
|
26246 |
|
26247 | RuleProvider.call(this, eventBus);
|
26248 |
|
26249 | var self = this;
|
26250 |
|
26251 | this.addRule('element.autoResize', function(context) {
|
26252 | return self.canResize(context.elements, context.target);
|
26253 | });
|
26254 | }
|
26255 |
|
26256 | AutoResizeProvider.$inject = [ 'eventBus' ];
|
26257 |
|
26258 | inherits_browser(AutoResizeProvider, RuleProvider);
|
26259 |
|
26260 | |
26261 |
|
26262 |
|
26263 |
|
26264 |
|
26265 |
|
26266 |
|
26267 |
|
26268 | AutoResizeProvider.prototype.canResize = function(elements, target) {
|
26269 | return false;
|
26270 | };
|
26271 |
|
26272 | |
26273 |
|
26274 |
|
26275 | function BpmnAutoResizeProvider(eventBus, modeling) {
|
26276 | AutoResizeProvider.call(this, eventBus);
|
26277 |
|
26278 | this._modeling = modeling;
|
26279 | }
|
26280 |
|
26281 | inherits_browser(BpmnAutoResizeProvider, AutoResizeProvider);
|
26282 |
|
26283 | BpmnAutoResizeProvider.$inject = [
|
26284 | 'eventBus',
|
26285 | 'modeling'
|
26286 | ];
|
26287 |
|
26288 |
|
26289 | |
26290 |
|
26291 |
|
26292 |
|
26293 |
|
26294 |
|
26295 |
|
26296 | BpmnAutoResizeProvider.prototype.canResize = function(elements, target) {
|
26297 |
|
26298 | if (!is$1(target, 'bpmn:Participant') && !is$1(target, 'bpmn:Lane') && !(is$1(target, 'bpmn:SubProcess'))) {
|
26299 | return false;
|
26300 | }
|
26301 |
|
26302 | var canResize = true;
|
26303 |
|
26304 | forEach(elements, function(element) {
|
26305 |
|
26306 | if (is$1(element, 'bpmn:Lane') || element.labelTarget) {
|
26307 | canResize = false;
|
26308 | return;
|
26309 | }
|
26310 | });
|
26311 |
|
26312 | return canResize;
|
26313 | };
|
26314 |
|
26315 | var AutoResizeModule = {
|
26316 | __init__: [
|
26317 | 'bpmnAutoResize',
|
26318 | 'bpmnAutoResizeProvider'
|
26319 | ],
|
26320 | bpmnAutoResize: [ 'type', BpmnAutoResize ],
|
26321 | bpmnAutoResizeProvider: [ 'type', BpmnAutoResizeProvider ]
|
26322 | };
|
26323 |
|
26324 |
|
26325 |
|
26326 | var round$1 = Math.round;
|
26327 |
|
26328 | var DRAG_ACTIVE_CLS = 'djs-drag-active';
|
26329 |
|
26330 |
|
26331 | function preventDefault(event) {
|
26332 | event.preventDefault();
|
26333 | }
|
26334 |
|
26335 | function isTouchEvent(event) {
|
26336 |
|
26337 |
|
26338 |
|
26339 | return typeof TouchEvent !== 'undefined' && event instanceof TouchEvent;
|
26340 | }
|
26341 |
|
26342 | function getLength(point) {
|
26343 | return Math.sqrt(Math.pow(point.x, 2) + Math.pow(point.y, 2));
|
26344 | }
|
26345 |
|
26346 | |
26347 |
|
26348 |
|
26349 |
|
26350 |
|
26351 |
|
26352 |
|
26353 |
|
26354 |
|
26355 |
|
26356 |
|
26357 |
|
26358 |
|
26359 |
|
26360 |
|
26361 |
|
26362 |
|
26363 |
|
26364 |
|
26365 |
|
26366 |
|
26367 |
|
26368 |
|
26369 |
|
26370 |
|
26371 |
|
26372 |
|
26373 |
|
26374 |
|
26375 |
|
26376 |
|
26377 |
|
26378 |
|
26379 |
|
26380 |
|
26381 |
|
26382 |
|
26383 |
|
26384 |
|
26385 |
|
26386 |
|
26387 |
|
26388 |
|
26389 |
|
26390 |
|
26391 |
|
26392 |
|
26393 |
|
26394 |
|
26395 |
|
26396 |
|
26397 |
|
26398 |
|
26399 |
|
26400 |
|
26401 |
|
26402 |
|
26403 |
|
26404 |
|
26405 |
|
26406 |
|
26407 |
|
26408 |
|
26409 |
|
26410 |
|
26411 |
|
26412 |
|
26413 |
|
26414 |
|
26415 |
|
26416 |
|
26417 |
|
26418 |
|
26419 |
|
26420 |
|
26421 |
|
26422 |
|
26423 |
|
26424 | function Dragging(eventBus, canvas, selection) {
|
26425 |
|
26426 | var defaultOptions = {
|
26427 | threshold: 5,
|
26428 | trapClick: true
|
26429 | };
|
26430 |
|
26431 |
|
26432 |
|
26433 |
|
26434 |
|
26435 | var context;
|
26436 |
|
26437 |
|
26438 | function toLocalPoint(globalPosition) {
|
26439 |
|
26440 | var viewbox = canvas.viewbox();
|
26441 |
|
26442 | var clientRect = canvas._container.getBoundingClientRect();
|
26443 |
|
26444 | return {
|
26445 | x: viewbox.x + (globalPosition.x - clientRect.left) / viewbox.scale,
|
26446 | y: viewbox.y + (globalPosition.y - clientRect.top) / viewbox.scale
|
26447 | };
|
26448 | }
|
26449 |
|
26450 |
|
26451 |
|
26452 | function fire(type, dragContext) {
|
26453 | dragContext = dragContext || context;
|
26454 |
|
26455 | var event = eventBus.createEvent(
|
26456 | assign(
|
26457 | {},
|
26458 | dragContext.payload,
|
26459 | dragContext.data,
|
26460 | { isTouch: dragContext.isTouch }
|
26461 | )
|
26462 | );
|
26463 |
|
26464 |
|
26465 | if (eventBus.fire('drag.' + type, event) === false) {
|
26466 | return false;
|
26467 | }
|
26468 |
|
26469 | return eventBus.fire(dragContext.prefix + '.' + type, event);
|
26470 | }
|
26471 |
|
26472 |
|
26473 |
|
26474 | function move(event, activate) {
|
26475 | var payload = context.payload,
|
26476 | displacement = context.displacement;
|
26477 |
|
26478 | var globalStart = context.globalStart,
|
26479 | globalCurrent = toPoint(event),
|
26480 | globalDelta = delta(globalCurrent, globalStart);
|
26481 |
|
26482 | var localStart = context.localStart,
|
26483 | localCurrent = toLocalPoint(globalCurrent),
|
26484 | localDelta = delta(localCurrent, localStart);
|
26485 |
|
26486 |
|
26487 |
|
26488 | if (!context.active && (activate || getLength(globalDelta) > context.threshold)) {
|
26489 |
|
26490 |
|
26491 |
|
26492 |
|
26493 | assign(payload, {
|
26494 | x: round$1(localStart.x + displacement.x),
|
26495 | y: round$1(localStart.y + displacement.y),
|
26496 | dx: 0,
|
26497 | dy: 0
|
26498 | }, { originalEvent: event });
|
26499 |
|
26500 | if (false === fire('start')) {
|
26501 | return cancel();
|
26502 | }
|
26503 |
|
26504 | context.active = true;
|
26505 |
|
26506 |
|
26507 |
|
26508 |
|
26509 | if (!context.keepSelection) {
|
26510 | payload.previousSelection = selection.get();
|
26511 | selection.select(null);
|
26512 | }
|
26513 |
|
26514 |
|
26515 | if (context.cursor) {
|
26516 | set$1(context.cursor);
|
26517 | }
|
26518 |
|
26519 | // indicate dragging via marker on root element
|
26520 | canvas.addMarker(canvas.getRootElement(), DRAG_ACTIVE_CLS);
|
26521 | }
|
26522 |
|
26523 | stopPropagation(event);
|
26524 |
|
26525 | if (context.active) {
|
26526 |
|
26527 |
|
26528 | assign(payload, {
|
26529 | x: round$1(localCurrent.x + displacement.x),
|
26530 | y: round$1(localCurrent.y + displacement.y),
|
26531 | dx: round$1(localDelta.x),
|
26532 | dy: round$1(localDelta.y)
|
26533 | }, { originalEvent: event });
|
26534 |
|
26535 |
|
26536 | fire('move');
|
26537 | }
|
26538 | }
|
26539 |
|
26540 | function end(event) {
|
26541 | var previousContext,
|
26542 | returnValue = true;
|
26543 |
|
26544 | if (context.active) {
|
26545 |
|
26546 | if (event) {
|
26547 | context.payload.originalEvent = event;
|
26548 |
|
26549 |
|
26550 |
|
26551 | stopPropagation(event);
|
26552 | }
|
26553 |
|
26554 |
|
26555 |
|
26556 |
|
26557 | returnValue = fire('end');
|
26558 | }
|
26559 |
|
26560 | if (returnValue === false) {
|
26561 | fire('rejected');
|
26562 | }
|
26563 |
|
26564 | previousContext = cleanup(returnValue !== true);
|
26565 |
|
26566 |
|
26567 |
|
26568 | fire('ended', previousContext);
|
26569 | }
|
26570 |
|
26571 |
|
26572 |
|
26573 |
|
26574 |
|
26575 | function checkCancel(event) {
|
26576 |
|
26577 | if (event.which === 27) {
|
26578 | preventDefault(event);
|
26579 |
|
26580 | cancel();
|
26581 | }
|
26582 | }
|
26583 |
|
26584 |
|
26585 |
|
26586 |
|
26587 |
|
26588 | function trapClickAndEnd(event) {
|
26589 |
|
26590 | var untrap;
|
26591 |
|
26592 |
|
26593 |
|
26594 |
|
26595 | if (context.active) {
|
26596 |
|
26597 | untrap = install(eventBus);
|
26598 |
|
26599 |
|
26600 | setTimeout(untrap, 400);
|
26601 |
|
26602 |
|
26603 | preventDefault(event);
|
26604 | }
|
26605 |
|
26606 | end(event);
|
26607 | }
|
26608 |
|
26609 | function trapTouch(event) {
|
26610 | move(event);
|
26611 | }
|
26612 |
|
26613 |
|
26614 |
|
26615 |
|
26616 |
|
26617 | function hover(event) {
|
26618 | var payload = context.payload;
|
26619 |
|
26620 | payload.hoverGfx = event.gfx;
|
26621 | payload.hover = event.element;
|
26622 |
|
26623 | fire('hover');
|
26624 | }
|
26625 |
|
26626 | function out(event) {
|
26627 | fire('out');
|
26628 |
|
26629 | var payload = context.payload;
|
26630 |
|
26631 | payload.hoverGfx = null;
|
26632 | payload.hover = null;
|
26633 | }
|
26634 |
|
26635 |
|
26636 |
|
26637 |
|
26638 | function cancel(restore) {
|
26639 | var previousContext;
|
26640 |
|
26641 | if (!context) {
|
26642 | return;
|
26643 | }
|
26644 |
|
26645 | var wasActive = context.active;
|
26646 |
|
26647 | if (wasActive) {
|
26648 | fire('cancel');
|
26649 | }
|
26650 |
|
26651 | previousContext = cleanup(restore);
|
26652 |
|
26653 | if (wasActive) {
|
26654 |
|
26655 |
|
26656 |
|
26657 | fire('canceled', previousContext);
|
26658 | }
|
26659 | }
|
26660 |
|
26661 | function cleanup(restore) {
|
26662 | var previousContext,
|
26663 | endDrag;
|
26664 |
|
26665 | fire('cleanup');
|
26666 |
|
26667 |
|
26668 | unset();
|
26669 |
|
26670 | if (context.trapClick) {
|
26671 | endDrag = trapClickAndEnd;
|
26672 | } else {
|
26673 | endDrag = end;
|
26674 | }
|
26675 |
|
26676 |
|
26677 | componentEvent.unbind(document, 'mousemove', move);
|
26678 |
|
26679 | componentEvent.unbind(document, 'dragstart', preventDefault);
|
26680 | componentEvent.unbind(document, 'selectstart', preventDefault);
|
26681 |
|
26682 | componentEvent.unbind(document, 'mousedown', endDrag, true);
|
26683 | componentEvent.unbind(document, 'mouseup', endDrag, true);
|
26684 |
|
26685 | componentEvent.unbind(document, 'keyup', checkCancel);
|
26686 |
|
26687 | componentEvent.unbind(document, 'touchstart', trapTouch, true);
|
26688 | componentEvent.unbind(document, 'touchcancel', cancel, true);
|
26689 | componentEvent.unbind(document, 'touchmove', move, true);
|
26690 | componentEvent.unbind(document, 'touchend', end, true);
|
26691 |
|
26692 | eventBus.off('element.hover', hover);
|
26693 | eventBus.off('element.out', out);
|
26694 |
|
26695 |
|
26696 | canvas.removeMarker(canvas.getRootElement(), DRAG_ACTIVE_CLS);
|
26697 |
|
26698 |
|
26699 | var previousSelection = context.payload.previousSelection;
|
26700 |
|
26701 | if (restore !== false && previousSelection && !selection.get().length) {
|
26702 | selection.select(previousSelection);
|
26703 | }
|
26704 |
|
26705 | previousContext = context;
|
26706 |
|
26707 | context = null;
|
26708 |
|
26709 | return previousContext;
|
26710 | }
|
26711 |
|
26712 | |
26713 |
|
26714 |
|
26715 |
|
26716 |
|
26717 |
|
26718 |
|
26719 |
|
26720 |
|
26721 |
|
26722 |
|
26723 | function init(event, relativeTo, prefix, options) {
|
26724 |
|
26725 |
|
26726 | if (context) {
|
26727 | cancel(false);
|
26728 | }
|
26729 |
|
26730 | if (typeof relativeTo === 'string') {
|
26731 | options = prefix;
|
26732 | prefix = relativeTo;
|
26733 | relativeTo = null;
|
26734 | }
|
26735 |
|
26736 | options = assign({}, defaultOptions, options || {});
|
26737 |
|
26738 | var data = options.data || {},
|
26739 | originalEvent,
|
26740 | globalStart,
|
26741 | localStart,
|
26742 | endDrag,
|
26743 | isTouch;
|
26744 |
|
26745 | if (options.trapClick) {
|
26746 | endDrag = trapClickAndEnd;
|
26747 | } else {
|
26748 | endDrag = end;
|
26749 | }
|
26750 |
|
26751 | if (event) {
|
26752 | originalEvent = getOriginal(event) || event;
|
26753 | globalStart = toPoint(event);
|
26754 |
|
26755 | stopPropagation(event);
|
26756 |
|
26757 |
|
26758 | if (originalEvent.type === 'dragstart') {
|
26759 | preventDefault(originalEvent);
|
26760 | }
|
26761 | } else {
|
26762 | originalEvent = null;
|
26763 | globalStart = { x: 0, y: 0 };
|
26764 | }
|
26765 |
|
26766 | localStart = toLocalPoint(globalStart);
|
26767 |
|
26768 | if (!relativeTo) {
|
26769 | relativeTo = localStart;
|
26770 | }
|
26771 |
|
26772 | isTouch = isTouchEvent(originalEvent);
|
26773 |
|
26774 | context = assign({
|
26775 | prefix: prefix,
|
26776 | data: data,
|
26777 | payload: {},
|
26778 | globalStart: globalStart,
|
26779 | displacement: delta(relativeTo, localStart),
|
26780 | localStart: localStart,
|
26781 | isTouch: isTouch
|
26782 | }, options);
|
26783 |
|
26784 |
|
26785 |
|
26786 | if (!options.manual) {
|
26787 |
|
26788 |
|
26789 |
|
26790 | if (isTouch) {
|
26791 | componentEvent.bind(document, 'touchstart', trapTouch, true);
|
26792 | componentEvent.bind(document, 'touchcancel', cancel, true);
|
26793 | componentEvent.bind(document, 'touchmove', move, true);
|
26794 | componentEvent.bind(document, 'touchend', end, true);
|
26795 | } else {
|
26796 |
|
26797 |
|
26798 | componentEvent.bind(document, 'mousemove', move);
|
26799 |
|
26800 |
|
26801 | componentEvent.bind(document, 'dragstart', preventDefault);
|
26802 | componentEvent.bind(document, 'selectstart', preventDefault);
|
26803 |
|
26804 | componentEvent.bind(document, 'mousedown', endDrag, true);
|
26805 | componentEvent.bind(document, 'mouseup', endDrag, true);
|
26806 | }
|
26807 |
|
26808 | componentEvent.bind(document, 'keyup', checkCancel);
|
26809 |
|
26810 | eventBus.on('element.hover', hover);
|
26811 | eventBus.on('element.out', out);
|
26812 | }
|
26813 |
|
26814 | fire('init');
|
26815 |
|
26816 | if (options.autoActivate) {
|
26817 | move(event, true);
|
26818 | }
|
26819 | }
|
26820 |
|
26821 |
|
26822 | eventBus.on('diagram.destroy', cancel);
|
26823 |
|
26824 |
|
26825 |
|
26826 |
|
26827 | this.init = init;
|
26828 | this.move = move;
|
26829 | this.hover = hover;
|
26830 | this.out = out;
|
26831 | this.end = end;
|
26832 |
|
26833 | this.cancel = cancel;
|
26834 |
|
26835 |
|
26836 |
|
26837 | this.context = function() {
|
26838 | return context;
|
26839 | };
|
26840 |
|
26841 | this.setOptions = function(options) {
|
26842 | assign(defaultOptions, options);
|
26843 | };
|
26844 | }
|
26845 |
|
26846 | Dragging.$inject = [
|
26847 | 'eventBus',
|
26848 | 'canvas',
|
26849 | 'selection'
|
26850 | ];
|
26851 |
|
26852 | var HIGH_PRIORITY = 1500;
|
26853 |
|
26854 |
|
26855 | |
26856 |
|
26857 |
|
26858 |
|
26859 |
|
26860 |
|
26861 |
|
26862 |
|
26863 |
|
26864 |
|
26865 |
|
26866 |
|
26867 |
|
26868 |
|
26869 |
|
26870 | function HoverFix(eventBus, dragging, elementRegistry) {
|
26871 |
|
26872 | var self = this;
|
26873 |
|
26874 | |
26875 |
|
26876 |
|
26877 |
|
26878 |
|
26879 | function ensureHover(event) {
|
26880 |
|
26881 | if (event.hover) {
|
26882 | return;
|
26883 | }
|
26884 |
|
26885 | var originalEvent = event.originalEvent;
|
26886 |
|
26887 | var gfx = self._findTargetGfx(originalEvent);
|
26888 |
|
26889 | var element = gfx && elementRegistry.get(gfx);
|
26890 |
|
26891 | if (gfx && element) {
|
26892 |
|
26893 |
|
26894 | event.stopPropagation();
|
26895 |
|
26896 |
|
26897 | dragging.hover({ element: element, gfx: gfx });
|
26898 |
|
26899 |
|
26900 | dragging.move(originalEvent);
|
26901 | }
|
26902 | }
|
26903 |
|
26904 | |
26905 |
|
26906 |
|
26907 |
|
26908 |
|
26909 |
|
26910 |
|
26911 |
|
26912 |
|
26913 | eventBus.on('drag.start', function(event) {
|
26914 |
|
26915 | eventBus.once('drag.move', HIGH_PRIORITY, function(event) {
|
26916 |
|
26917 | ensureHover(event);
|
26918 |
|
26919 | });
|
26920 |
|
26921 | });
|
26922 |
|
26923 |
|
26924 | |
26925 |
|
26926 |
|
26927 |
|
26928 |
|
26929 |
|
26930 |
|
26931 |
|
26932 |
|
26933 |
|
26934 | eventBus.on('drag.init', function() {
|
26935 |
|
26936 | var hover, hoverGfx;
|
26937 |
|
26938 | function setDragHover(event) {
|
26939 | hover = event.hover;
|
26940 | hoverGfx = event.hoverGfx;
|
26941 | }
|
26942 |
|
26943 | function unsetHover() {
|
26944 | hover = null;
|
26945 | hoverGfx = null;
|
26946 | }
|
26947 |
|
26948 | function ensureOut() {
|
26949 |
|
26950 | if (!hover) {
|
26951 | return;
|
26952 | }
|
26953 |
|
26954 | var element = hover,
|
26955 | gfx = hoverGfx;
|
26956 |
|
26957 | hover = null;
|
26958 | hoverGfx = null;
|
26959 |
|
26960 |
|
26961 | dragging.out({
|
26962 | element: element,
|
26963 | gfx: gfx
|
26964 | });
|
26965 | }
|
26966 |
|
26967 | eventBus.on('drag.hover', setDragHover);
|
26968 | eventBus.on('element.out', unsetHover);
|
26969 | eventBus.on('element.hover', HIGH_PRIORITY, ensureOut);
|
26970 |
|
26971 | eventBus.once('drag.cleanup', function() {
|
26972 | eventBus.off('drag.hover', setDragHover);
|
26973 | eventBus.off('element.out', unsetHover);
|
26974 | eventBus.off('element.hover', ensureOut);
|
26975 | });
|
26976 |
|
26977 | });
|
26978 |
|
26979 | this._findTargetGfx = function(event) {
|
26980 | var position,
|
26981 | target;
|
26982 |
|
26983 | if (!(event instanceof MouseEvent)) {
|
26984 | return;
|
26985 | }
|
26986 |
|
26987 | position = toPoint(event);
|
26988 |
|
26989 |
|
26990 | target = document.elementFromPoint(position.x, position.y);
|
26991 |
|
26992 | return getGfx(target);
|
26993 | };
|
26994 |
|
26995 | }
|
26996 |
|
26997 | HoverFix.$inject = [
|
26998 | 'eventBus',
|
26999 | 'dragging',
|
27000 | 'elementRegistry'
|
27001 | ];
|
27002 |
|
27003 |
|
27004 |
|
27005 |
|
27006 | function getGfx(target) {
|
27007 | return closest(target, 'svg, .djs-element', true);
|
27008 | }
|
27009 |
|
27010 | var DraggingModule = {
|
27011 | __init__: [
|
27012 | 'hoverFix'
|
27013 | ],
|
27014 | __depends__: [
|
27015 | SelectionModule
|
27016 | ],
|
27017 | dragging: [ 'type', Dragging ],
|
27018 | hoverFix: [ 'type', HoverFix ]
|
27019 | };
|
27020 |
|
27021 | |
27022 |
|
27023 |
|
27024 |
|
27025 |
|
27026 |
|
27027 |
|
27028 |
|
27029 |
|
27030 |
|
27031 |
|
27032 |
|
27033 |
|
27034 |
|
27035 | function AutoScroll(config, eventBus, canvas) {
|
27036 |
|
27037 | this._canvas = canvas;
|
27038 |
|
27039 | this._opts = assign({
|
27040 | scrollThresholdIn: [ 20, 20, 20, 20 ],
|
27041 | scrollThresholdOut: [ 0, 0, 0, 0 ],
|
27042 | scrollRepeatTimeout: 15,
|
27043 | scrollStep: 10
|
27044 | }, config);
|
27045 |
|
27046 | var self = this;
|
27047 |
|
27048 | eventBus.on('drag.move', function(e) {
|
27049 | var point = self._toBorderPoint(e);
|
27050 |
|
27051 | self.startScroll(point);
|
27052 | });
|
27053 |
|
27054 | eventBus.on([ 'drag.cleanup' ], function() {
|
27055 | self.stopScroll();
|
27056 | });
|
27057 | }
|
27058 |
|
27059 | AutoScroll.$inject = [
|
27060 | 'config.autoScroll',
|
27061 | 'eventBus',
|
27062 | 'canvas'
|
27063 | ];
|
27064 |
|
27065 |
|
27066 | |
27067 |
|
27068 |
|
27069 |
|
27070 |
|
27071 |
|
27072 | AutoScroll.prototype.startScroll = function(point) {
|
27073 |
|
27074 | var canvas = this._canvas;
|
27075 | var opts = this._opts;
|
27076 | var self = this;
|
27077 |
|
27078 | var clientRect = canvas.getContainer().getBoundingClientRect();
|
27079 |
|
27080 | var diff = [
|
27081 | point.x,
|
27082 | point.y,
|
27083 | clientRect.width - point.x,
|
27084 | clientRect.height - point.y
|
27085 | ];
|
27086 |
|
27087 | this.stopScroll();
|
27088 |
|
27089 | var dx = 0,
|
27090 | dy = 0;
|
27091 |
|
27092 | for (var i = 0; i < 4; i++) {
|
27093 | if (between(diff[i], opts.scrollThresholdOut[i], opts.scrollThresholdIn[i])) {
|
27094 | if (i === 0) {
|
27095 | dx = opts.scrollStep;
|
27096 | } else if (i == 1) {
|
27097 | dy = opts.scrollStep;
|
27098 | } else if (i == 2) {
|
27099 | dx = -opts.scrollStep;
|
27100 | } else if (i == 3) {
|
27101 | dy = -opts.scrollStep;
|
27102 | }
|
27103 | }
|
27104 | }
|
27105 |
|
27106 | if (dx !== 0 || dy !== 0) {
|
27107 | canvas.scroll({ dx: dx, dy: dy });
|
27108 |
|
27109 | this._scrolling = setTimeout(function() {
|
27110 | self.startScroll(point);
|
27111 | }, opts.scrollRepeatTimeout);
|
27112 | }
|
27113 | };
|
27114 |
|
27115 | function between(val, start, end) {
|
27116 | if (start < val && val < end) {
|
27117 | return true;
|
27118 | }
|
27119 |
|
27120 | return false;
|
27121 | }
|
27122 |
|
27123 |
|
27124 | |
27125 |
|
27126 |
|
27127 | AutoScroll.prototype.stopScroll = function() {
|
27128 | clearTimeout(this._scrolling);
|
27129 | };
|
27130 |
|
27131 |
|
27132 | |
27133 |
|
27134 |
|
27135 |
|
27136 |
|
27137 | AutoScroll.prototype.setOptions = function(options) {
|
27138 | this._opts = assign({}, this._opts, options);
|
27139 | };
|
27140 |
|
27141 |
|
27142 | |
27143 |
|
27144 |
|
27145 |
|
27146 |
|
27147 |
|
27148 | AutoScroll.prototype._toBorderPoint = function(event) {
|
27149 | var clientRect = this._canvas._container.getBoundingClientRect();
|
27150 |
|
27151 | var globalPosition = toPoint(event.originalEvent);
|
27152 |
|
27153 | return {
|
27154 | x: globalPosition.x - clientRect.left,
|
27155 | y: globalPosition.y - clientRect.top
|
27156 | };
|
27157 | };
|
27158 |
|
27159 | var AutoScrollModule = {
|
27160 | __depends__: [
|
27161 | DraggingModule,
|
27162 | ],
|
27163 | __init__: [ 'autoScroll' ],
|
27164 | autoScroll: [ 'type', AutoScroll ]
|
27165 | };
|
27166 |
|
27167 | |
27168 |
|
27169 |
|
27170 |
|
27171 |
|
27172 |
|
27173 |
|
27174 |
|
27175 |
|
27176 |
|
27177 |
|
27178 |
|
27179 |
|
27180 |
|
27181 | function Rules(injector) {
|
27182 | this._commandStack = injector.get('commandStack', false);
|
27183 | }
|
27184 |
|
27185 | Rules.$inject = [ 'injector' ];
|
27186 |
|
27187 |
|
27188 | |
27189 |
|
27190 |
|
27191 |
|
27192 |
|
27193 |
|
27194 |
|
27195 |
|
27196 |
|
27197 |
|
27198 |
|
27199 |
|
27200 |
|
27201 | Rules.prototype.allowed = function(action, context) {
|
27202 | var allowed = true;
|
27203 |
|
27204 | var commandStack = this._commandStack;
|
27205 |
|
27206 | if (commandStack) {
|
27207 | allowed = commandStack.canExecute(action, context);
|
27208 | }
|
27209 |
|
27210 |
|
27211 | return allowed === undefined ? true : allowed;
|
27212 | };
|
27213 |
|
27214 | var RulesModule = {
|
27215 | __init__: [ 'rules' ],
|
27216 | rules: [ 'type', Rules ]
|
27217 | };
|
27218 |
|
27219 | var round$2 = Math.round,
|
27220 | max = Math.max;
|
27221 |
|
27222 |
|
27223 | function circlePath(center, r) {
|
27224 | var x = center.x,
|
27225 | y = center.y;
|
27226 |
|
27227 | return [
|
27228 | ['M', x, y],
|
27229 | ['m', 0, -r],
|
27230 | ['a', r, r, 0, 1, 1, 0, 2 * r],
|
27231 | ['a', r, r, 0, 1, 1, 0, -2 * r],
|
27232 | ['z']
|
27233 | ];
|
27234 | }
|
27235 |
|
27236 | function linePath(points) {
|
27237 | var segments = [];
|
27238 |
|
27239 | points.forEach(function(p, idx) {
|
27240 | segments.push([ idx === 0 ? 'M' : 'L', p.x, p.y ]);
|
27241 | });
|
27242 |
|
27243 | return segments;
|
27244 | }
|
27245 |
|
27246 |
|
27247 | var INTERSECTION_THRESHOLD = 10;
|
27248 |
|
27249 | function getBendpointIntersection(waypoints, reference) {
|
27250 |
|
27251 | var i, w;
|
27252 |
|
27253 | for (i = 0; (w = waypoints[i]); i++) {
|
27254 |
|
27255 | if (pointDistance(w, reference) <= INTERSECTION_THRESHOLD) {
|
27256 | return {
|
27257 | point: waypoints[i],
|
27258 | bendpoint: true,
|
27259 | index: i
|
27260 | };
|
27261 | }
|
27262 | }
|
27263 |
|
27264 | return null;
|
27265 | }
|
27266 |
|
27267 | function getPathIntersection(waypoints, reference) {
|
27268 |
|
27269 | var intersections = intersect(circlePath(reference, INTERSECTION_THRESHOLD), linePath(waypoints));
|
27270 |
|
27271 | var a = intersections[0],
|
27272 | b = intersections[intersections.length - 1],
|
27273 | idx;
|
27274 |
|
27275 | if (!a) {
|
27276 |
|
27277 |
|
27278 | return null;
|
27279 | }
|
27280 |
|
27281 | if (a !== b) {
|
27282 |
|
27283 | if (a.segment2 !== b.segment2) {
|
27284 |
|
27285 |
|
27286 |
|
27287 |
|
27288 | idx = max(a.segment2, b.segment2) - 1;
|
27289 |
|
27290 | return {
|
27291 | point: waypoints[idx],
|
27292 | bendpoint: true,
|
27293 | index: idx
|
27294 | };
|
27295 | }
|
27296 |
|
27297 | return {
|
27298 | point: {
|
27299 | x: (round$2(a.x + b.x) / 2),
|
27300 | y: (round$2(a.y + b.y) / 2)
|
27301 | },
|
27302 | index: a.segment2
|
27303 | };
|
27304 | }
|
27305 |
|
27306 | return {
|
27307 | point: {
|
27308 | x: round$2(a.x),
|
27309 | y: round$2(a.y)
|
27310 | },
|
27311 | index: a.segment2
|
27312 | };
|
27313 | }
|
27314 |
|
27315 | |
27316 |
|
27317 |
|
27318 |
|
27319 |
|
27320 |
|
27321 |
|
27322 |
|
27323 | function getApproxIntersection(waypoints, reference) {
|
27324 | return getBendpointIntersection(waypoints, reference) || getPathIntersection(waypoints, reference);
|
27325 | }
|
27326 |
|
27327 | var BENDPOINT_CLS = 'djs-bendpoint';
|
27328 | var SEGMENT_DRAGGER_CLS = 'djs-segment-dragger';
|
27329 |
|
27330 | function toCanvasCoordinates(canvas, event) {
|
27331 |
|
27332 | var position = toPoint(event),
|
27333 | clientRect = canvas._container.getBoundingClientRect(),
|
27334 | offset;
|
27335 |
|
27336 |
|
27337 |
|
27338 | offset = {
|
27339 | x: clientRect.left,
|
27340 | y: clientRect.top
|
27341 | };
|
27342 |
|
27343 |
|
27344 |
|
27345 | var viewbox = canvas.viewbox();
|
27346 |
|
27347 | return {
|
27348 | x: viewbox.x + (position.x - offset.x) / viewbox.scale,
|
27349 | y: viewbox.y + (position.y - offset.y) / viewbox.scale
|
27350 | };
|
27351 | }
|
27352 |
|
27353 | function getConnectionIntersection(canvas, waypoints, event) {
|
27354 | var localPosition = toCanvasCoordinates(canvas, event),
|
27355 | intersection = getApproxIntersection(waypoints, localPosition);
|
27356 |
|
27357 | return intersection;
|
27358 | }
|
27359 |
|
27360 | function addBendpoint(parentGfx, cls) {
|
27361 | var groupGfx = create('g');
|
27362 | classes$1(groupGfx).add(BENDPOINT_CLS);
|
27363 |
|
27364 | append(parentGfx, groupGfx);
|
27365 |
|
27366 | var visual = create('circle');
|
27367 | attr$1(visual, {
|
27368 | cx: 0,
|
27369 | cy: 0,
|
27370 | r: 4
|
27371 | });
|
27372 | classes$1(visual).add('djs-visual');
|
27373 |
|
27374 | append(groupGfx, visual);
|
27375 |
|
27376 | var hit = create('circle');
|
27377 | attr$1(hit, {
|
27378 | cx: 0,
|
27379 | cy: 0,
|
27380 | r: 10
|
27381 | });
|
27382 | classes$1(hit).add('djs-hit');
|
27383 |
|
27384 | append(groupGfx, hit);
|
27385 |
|
27386 | if (cls) {
|
27387 | classes$1(groupGfx).add(cls);
|
27388 | }
|
27389 |
|
27390 | return groupGfx;
|
27391 | }
|
27392 |
|
27393 | function createParallelDragger(parentGfx, segmentStart, segmentEnd, alignment) {
|
27394 | var draggerGfx = create('g');
|
27395 |
|
27396 | append(parentGfx, draggerGfx);
|
27397 |
|
27398 | var width = 14,
|
27399 | height = 3,
|
27400 | padding = 6,
|
27401 | hitWidth = calculateHitWidth(segmentStart, segmentEnd, alignment),
|
27402 | hitHeight = height + padding;
|
27403 |
|
27404 | var visual = create('rect');
|
27405 | attr$1(visual, {
|
27406 | x: -width / 2,
|
27407 | y: -height / 2,
|
27408 | width: width,
|
27409 | height: height
|
27410 | });
|
27411 | classes$1(visual).add('djs-visual');
|
27412 |
|
27413 | append(draggerGfx, visual);
|
27414 |
|
27415 | var hit = create('rect');
|
27416 | attr$1(hit, {
|
27417 | x: -hitWidth / 2,
|
27418 | y: -hitHeight / 2,
|
27419 | width: hitWidth,
|
27420 | height: hitHeight
|
27421 | });
|
27422 | classes$1(hit).add('djs-hit');
|
27423 |
|
27424 | append(draggerGfx, hit);
|
27425 |
|
27426 | rotate(draggerGfx, alignment === 'v' ? 90 : 0);
|
27427 |
|
27428 | return draggerGfx;
|
27429 | }
|
27430 |
|
27431 |
|
27432 | function addSegmentDragger(parentGfx, segmentStart, segmentEnd) {
|
27433 |
|
27434 | var groupGfx = create('g'),
|
27435 | mid = getMidPoint(segmentStart, segmentEnd),
|
27436 | alignment = pointsAligned(segmentStart, segmentEnd);
|
27437 |
|
27438 | append(parentGfx, groupGfx);
|
27439 |
|
27440 | createParallelDragger(groupGfx, segmentStart, segmentEnd, alignment);
|
27441 |
|
27442 | classes$1(groupGfx).add(SEGMENT_DRAGGER_CLS);
|
27443 | classes$1(groupGfx).add(alignment === 'h' ? 'horizontal' : 'vertical');
|
27444 |
|
27445 | translate(groupGfx, mid.x, mid.y);
|
27446 |
|
27447 | return groupGfx;
|
27448 | }
|
27449 |
|
27450 | |
27451 |
|
27452 |
|
27453 |
|
27454 |
|
27455 |
|
27456 | function calculateSegmentMoveRegion(segmentLength) {
|
27457 | return Math.abs(Math.round(segmentLength * 2 / 3));
|
27458 | }
|
27459 |
|
27460 |
|
27461 |
|
27462 | function calculateHitWidth(segmentStart, segmentEnd, alignment) {
|
27463 | var segmentLengthXAxis = segmentEnd.x - segmentStart.x,
|
27464 | segmentLengthYAxis = segmentEnd.y - segmentStart.y;
|
27465 |
|
27466 | return alignment === 'h' ?
|
27467 | calculateSegmentMoveRegion(segmentLengthXAxis) :
|
27468 | calculateSegmentMoveRegion(segmentLengthYAxis);
|
27469 | }
|
27470 |
|
27471 | var css_escape = createCommonjsModule(function (module, exports) {
|
27472 | (function(root, factory) {
|
27473 |
|
27474 | {
|
27475 |
|
27476 | module.exports = factory(root);
|
27477 | }
|
27478 | }(typeof commonjsGlobal != 'undefined' ? commonjsGlobal : commonjsGlobal, function(root) {
|
27479 |
|
27480 | if (root.CSS && root.CSS.escape) {
|
27481 | return root.CSS.escape;
|
27482 | }
|
27483 |
|
27484 |
|
27485 | var cssEscape = function(value) {
|
27486 | if (arguments.length == 0) {
|
27487 | throw new TypeError('`CSS.escape` requires an argument.');
|
27488 | }
|
27489 | var string = String(value);
|
27490 | var length = string.length;
|
27491 | var index = -1;
|
27492 | var codeUnit;
|
27493 | var result = '';
|
27494 | var firstCodeUnit = string.charCodeAt(0);
|
27495 | while (++index < length) {
|
27496 | codeUnit = string.charCodeAt(index);
|
27497 |
|
27498 |
|
27499 |
|
27500 |
|
27501 |
|
27502 | if (codeUnit == 0x0000) {
|
27503 | result += '\uFFFD';
|
27504 | continue;
|
27505 | }
|
27506 |
|
27507 | if (
|
27508 |
|
27509 |
|
27510 | (codeUnit >= 0x0001 && codeUnit <= 0x001F) || codeUnit == 0x007F ||
|
27511 |
|
27512 |
|
27513 | (index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039) ||
|
27514 |
|
27515 |
|
27516 | (
|
27517 | index == 1 &&
|
27518 | codeUnit >= 0x0030 && codeUnit <= 0x0039 &&
|
27519 | firstCodeUnit == 0x002D
|
27520 | )
|
27521 | ) {
|
27522 |
|
27523 | result += '\\' + codeUnit.toString(16) + ' ';
|
27524 | continue;
|
27525 | }
|
27526 |
|
27527 | if (
|
27528 |
|
27529 |
|
27530 | index == 0 &&
|
27531 | length == 1 &&
|
27532 | codeUnit == 0x002D
|
27533 | ) {
|
27534 | result += '\\' + string.charAt(index);
|
27535 | continue;
|
27536 | }
|
27537 |
|
27538 |
|
27539 |
|
27540 |
|
27541 |
|
27542 | if (
|
27543 | codeUnit >= 0x0080 ||
|
27544 | codeUnit == 0x002D ||
|
27545 | codeUnit == 0x005F ||
|
27546 | codeUnit >= 0x0030 && codeUnit <= 0x0039 ||
|
27547 | codeUnit >= 0x0041 && codeUnit <= 0x005A ||
|
27548 | codeUnit >= 0x0061 && codeUnit <= 0x007A
|
27549 | ) {
|
27550 |
|
27551 | result += string.charAt(index);
|
27552 | continue;
|
27553 | }
|
27554 |
|
27555 |
|
27556 |
|
27557 | result += '\\' + string.charAt(index);
|
27558 |
|
27559 | }
|
27560 | return result;
|
27561 | };
|
27562 |
|
27563 | if (!root.CSS) {
|
27564 | root.CSS = {};
|
27565 | }
|
27566 |
|
27567 | root.CSS.escape = cssEscape;
|
27568 | return cssEscape;
|
27569 |
|
27570 | }));
|
27571 | });
|
27572 |
|
27573 | var HTML_ESCAPE_MAP = {
|
27574 | '&': '&',
|
27575 | '<': '<',
|
27576 | '>': '>',
|
27577 | '"': '"',
|
27578 | '\'': '''
|
27579 | };
|
27580 |
|
27581 | function escapeHTML(str) {
|
27582 | str = '' + str;
|
27583 |
|
27584 | return str && str.replace(/[&<>"']/g, function(match) {
|
27585 | return HTML_ESCAPE_MAP[match];
|
27586 | });
|
27587 | }
|
27588 |
|
27589 | |
27590 |
|
27591 |
|
27592 | function Bendpoints(
|
27593 | eventBus, canvas, interactionEvents,
|
27594 | bendpointMove, connectionSegmentMove) {
|
27595 |
|
27596 | |
27597 |
|
27598 |
|
27599 |
|
27600 | function isIntersectionMiddle(intersection, waypoints, treshold) {
|
27601 | var idx = intersection.index,
|
27602 | p = intersection.point,
|
27603 | p0, p1, mid, aligned, xDelta, yDelta;
|
27604 |
|
27605 | if (idx <= 0 || intersection.bendpoint) {
|
27606 | return false;
|
27607 | }
|
27608 |
|
27609 | p0 = waypoints[idx - 1];
|
27610 | p1 = waypoints[idx];
|
27611 | mid = getMidPoint(p0, p1),
|
27612 | aligned = pointsAligned(p0, p1);
|
27613 | xDelta = Math.abs(p.x - mid.x);
|
27614 | yDelta = Math.abs(p.y - mid.y);
|
27615 |
|
27616 | return aligned && xDelta <= treshold && yDelta <= treshold;
|
27617 | }
|
27618 |
|
27619 | |
27620 |
|
27621 |
|
27622 | function calculateIntersectionThreshold(connection, intersection) {
|
27623 | var waypoints = connection.waypoints,
|
27624 | relevantSegment, alignment, segmentLength, threshold;
|
27625 |
|
27626 | if (intersection.index <= 0 || intersection.bendpoint) {
|
27627 | return null;
|
27628 | }
|
27629 |
|
27630 |
|
27631 | relevantSegment = {
|
27632 | start: waypoints[intersection.index - 1],
|
27633 | end: waypoints[intersection.index]
|
27634 | };
|
27635 |
|
27636 | alignment = pointsAligned(relevantSegment.start, relevantSegment.end);
|
27637 |
|
27638 | if (!alignment) {
|
27639 | return null;
|
27640 | }
|
27641 |
|
27642 | if (alignment === 'h') {
|
27643 | segmentLength = relevantSegment.end.x - relevantSegment.start.x;
|
27644 | } else {
|
27645 | segmentLength = relevantSegment.end.y - relevantSegment.start.y;
|
27646 | }
|
27647 |
|
27648 |
|
27649 | threshold = calculateSegmentMoveRegion(segmentLength) / 2;
|
27650 |
|
27651 | return threshold;
|
27652 | }
|
27653 |
|
27654 | function activateBendpointMove(event, connection) {
|
27655 | var waypoints = connection.waypoints,
|
27656 | intersection = getConnectionIntersection(canvas, waypoints, event),
|
27657 | threshold;
|
27658 |
|
27659 | if (!intersection) {
|
27660 | return;
|
27661 | }
|
27662 |
|
27663 | threshold = calculateIntersectionThreshold(connection, intersection);
|
27664 |
|
27665 | if (isIntersectionMiddle(intersection, waypoints, threshold)) {
|
27666 | connectionSegmentMove.start(event, connection, intersection.index);
|
27667 | } else {
|
27668 | bendpointMove.start(event, connection, intersection.index, !intersection.bendpoint);
|
27669 | }
|
27670 |
|
27671 |
|
27672 | return true;
|
27673 | }
|
27674 |
|
27675 | function bindInteractionEvents(node, eventName, element) {
|
27676 |
|
27677 | componentEvent.bind(node, eventName, function(event) {
|
27678 | interactionEvents.triggerMouseEvent(eventName, event, element);
|
27679 | event.stopPropagation();
|
27680 | });
|
27681 | }
|
27682 |
|
27683 | function getBendpointsContainer(element, create$1) {
|
27684 |
|
27685 | var layer = canvas.getLayer('overlays'),
|
27686 | gfx = query('.djs-bendpoints[data-element-id="' + css_escape(element.id) + '"]', layer);
|
27687 |
|
27688 | if (!gfx && create$1) {
|
27689 | gfx = create('g');
|
27690 | attr$1(gfx, { 'data-element-id': element.id });
|
27691 | classes$1(gfx).add('djs-bendpoints');
|
27692 |
|
27693 | append(layer, gfx);
|
27694 |
|
27695 | bindInteractionEvents(gfx, 'mousedown', element);
|
27696 | bindInteractionEvents(gfx, 'click', element);
|
27697 | bindInteractionEvents(gfx, 'dblclick', element);
|
27698 | }
|
27699 |
|
27700 | return gfx;
|
27701 | }
|
27702 |
|
27703 | function getSegmentDragger(idx, parentGfx) {
|
27704 | return query(
|
27705 | '.djs-segment-dragger[data-segment-idx="' + idx + '"]',
|
27706 | parentGfx
|
27707 | );
|
27708 | }
|
27709 |
|
27710 | function createBendpoints(gfx, connection) {
|
27711 | connection.waypoints.forEach(function(p, idx) {
|
27712 | var bendpoint = addBendpoint(gfx);
|
27713 |
|
27714 | append(gfx, bendpoint);
|
27715 |
|
27716 | translate(bendpoint, p.x, p.y);
|
27717 | });
|
27718 |
|
27719 |
|
27720 | addBendpoint(gfx, 'floating');
|
27721 | }
|
27722 |
|
27723 | function createSegmentDraggers(gfx, connection) {
|
27724 |
|
27725 | var waypoints = connection.waypoints;
|
27726 |
|
27727 | var segmentStart,
|
27728 | segmentEnd,
|
27729 | segmentDraggerGfx;
|
27730 |
|
27731 | for (var i = 1; i < waypoints.length; i++) {
|
27732 |
|
27733 | segmentStart = waypoints[i - 1];
|
27734 | segmentEnd = waypoints[i];
|
27735 |
|
27736 | if (pointsAligned(segmentStart, segmentEnd)) {
|
27737 | segmentDraggerGfx = addSegmentDragger(gfx, segmentStart, segmentEnd);
|
27738 |
|
27739 | attr$1(segmentDraggerGfx, { 'data-segment-idx': i });
|
27740 |
|
27741 | bindInteractionEvents(segmentDraggerGfx, 'mousemove', connection);
|
27742 | }
|
27743 | }
|
27744 | }
|
27745 |
|
27746 | function clearBendpoints(gfx) {
|
27747 | forEach(all('.' + BENDPOINT_CLS, gfx), function(node) {
|
27748 | remove$1(node);
|
27749 | });
|
27750 | }
|
27751 |
|
27752 | function clearSegmentDraggers(gfx) {
|
27753 | forEach(all('.' + SEGMENT_DRAGGER_CLS, gfx), function(node) {
|
27754 | remove$1(node);
|
27755 | });
|
27756 | }
|
27757 |
|
27758 | function addHandles(connection) {
|
27759 |
|
27760 | var gfx = getBendpointsContainer(connection);
|
27761 |
|
27762 | if (!gfx) {
|
27763 | gfx = getBendpointsContainer(connection, true);
|
27764 |
|
27765 | createBendpoints(gfx, connection);
|
27766 | createSegmentDraggers(gfx, connection);
|
27767 | }
|
27768 |
|
27769 | return gfx;
|
27770 | }
|
27771 |
|
27772 | function updateHandles(connection) {
|
27773 |
|
27774 | var gfx = getBendpointsContainer(connection);
|
27775 |
|
27776 | if (gfx) {
|
27777 | clearSegmentDraggers(gfx);
|
27778 | clearBendpoints(gfx);
|
27779 | createSegmentDraggers(gfx, connection);
|
27780 | createBendpoints(gfx, connection);
|
27781 | }
|
27782 | }
|
27783 |
|
27784 | function updateFloatingBendpointPosition(parentGfx, intersection) {
|
27785 | var floating = query('.floating', parentGfx),
|
27786 | point = intersection.point;
|
27787 |
|
27788 | if (!floating) {
|
27789 | return;
|
27790 | }
|
27791 |
|
27792 | translate(floating, point.x, point.y);
|
27793 |
|
27794 | }
|
27795 |
|
27796 | function updateSegmentDraggerPosition(parentGfx, intersection, waypoints) {
|
27797 |
|
27798 | var draggerGfx = getSegmentDragger(intersection.index, parentGfx),
|
27799 | segmentStart = waypoints[intersection.index - 1],
|
27800 | segmentEnd = waypoints[intersection.index],
|
27801 | point = intersection.point,
|
27802 | mid = getMidPoint(segmentStart, segmentEnd),
|
27803 | alignment = pointsAligned(segmentStart, segmentEnd),
|
27804 | draggerVisual, relativePosition;
|
27805 |
|
27806 | if (!draggerGfx) {
|
27807 | return;
|
27808 | }
|
27809 |
|
27810 | draggerVisual = getDraggerVisual(draggerGfx);
|
27811 |
|
27812 | relativePosition = {
|
27813 | x: point.x - mid.x,
|
27814 | y: point.y - mid.y
|
27815 | };
|
27816 |
|
27817 | if (alignment === 'v') {
|
27818 |
|
27819 |
|
27820 | relativePosition = {
|
27821 | x: relativePosition.y,
|
27822 | y: relativePosition.x
|
27823 | };
|
27824 | }
|
27825 |
|
27826 | translate(draggerVisual, relativePosition.x, relativePosition.y);
|
27827 | }
|
27828 |
|
27829 | eventBus.on('connection.changed', function(event) {
|
27830 | updateHandles(event.element);
|
27831 | });
|
27832 |
|
27833 | eventBus.on('connection.remove', function(event) {
|
27834 | var gfx = getBendpointsContainer(event.element);
|
27835 |
|
27836 | if (gfx) {
|
27837 | remove$1(gfx);
|
27838 | }
|
27839 | });
|
27840 |
|
27841 | eventBus.on('element.marker.update', function(event) {
|
27842 |
|
27843 | var element = event.element,
|
27844 | bendpointsGfx;
|
27845 |
|
27846 | if (!element.waypoints) {
|
27847 | return;
|
27848 | }
|
27849 |
|
27850 | bendpointsGfx = addHandles(element);
|
27851 |
|
27852 | if (event.add) {
|
27853 | classes$1(bendpointsGfx).add(event.marker);
|
27854 | } else {
|
27855 | classes$1(bendpointsGfx).remove(event.marker);
|
27856 | }
|
27857 | });
|
27858 |
|
27859 | eventBus.on('element.mousemove', function(event) {
|
27860 |
|
27861 | var element = event.element,
|
27862 | waypoints = element.waypoints,
|
27863 | bendpointsGfx,
|
27864 | intersection;
|
27865 |
|
27866 | if (waypoints) {
|
27867 | bendpointsGfx = getBendpointsContainer(element, true);
|
27868 |
|
27869 | intersection = getConnectionIntersection(canvas, waypoints, event.originalEvent);
|
27870 |
|
27871 | if (!intersection) {
|
27872 | return;
|
27873 | }
|
27874 |
|
27875 | updateFloatingBendpointPosition(bendpointsGfx, intersection);
|
27876 |
|
27877 | if (!intersection.bendpoint) {
|
27878 | updateSegmentDraggerPosition(bendpointsGfx, intersection, waypoints);
|
27879 | }
|
27880 |
|
27881 | }
|
27882 | });
|
27883 |
|
27884 | eventBus.on('element.mousedown', function(event) {
|
27885 |
|
27886 | var originalEvent = event.originalEvent,
|
27887 | element = event.element,
|
27888 | waypoints = element.waypoints;
|
27889 |
|
27890 | if (!waypoints) {
|
27891 | return;
|
27892 | }
|
27893 |
|
27894 | return activateBendpointMove(originalEvent, element);
|
27895 | });
|
27896 |
|
27897 | eventBus.on('selection.changed', function(event) {
|
27898 | var newSelection = event.newSelection,
|
27899 | primary = newSelection[0];
|
27900 |
|
27901 | if (primary && primary.waypoints) {
|
27902 | addHandles(primary);
|
27903 | }
|
27904 | });
|
27905 |
|
27906 | eventBus.on('element.hover', function(event) {
|
27907 | var element = event.element;
|
27908 |
|
27909 | if (element.waypoints) {
|
27910 | addHandles(element);
|
27911 | interactionEvents.registerEvent(event.gfx, 'mousemove', 'element.mousemove');
|
27912 | }
|
27913 | });
|
27914 |
|
27915 | eventBus.on('element.out', function(event) {
|
27916 | interactionEvents.unregisterEvent(event.gfx, 'mousemove', 'element.mousemove');
|
27917 | });
|
27918 |
|
27919 |
|
27920 | eventBus.on('element.updateId', function(context) {
|
27921 | var element = context.element,
|
27922 | newId = context.newId;
|
27923 |
|
27924 | if (element.waypoints) {
|
27925 | var bendpointContainer = getBendpointsContainer(element);
|
27926 |
|
27927 | if (bendpointContainer) {
|
27928 | attr$1(bendpointContainer, { 'data-element-id': newId });
|
27929 | }
|
27930 | }
|
27931 | });
|
27932 |
|
27933 |
|
27934 |
|
27935 | this.addHandles = addHandles;
|
27936 | this.updateHandles = updateHandles;
|
27937 | this.getBendpointsContainer = getBendpointsContainer;
|
27938 | this.getSegmentDragger = getSegmentDragger;
|
27939 | }
|
27940 |
|
27941 | Bendpoints.$inject = [
|
27942 | 'eventBus',
|
27943 | 'canvas',
|
27944 | 'interactionEvents',
|
27945 | 'bendpointMove',
|
27946 | 'connectionSegmentMove'
|
27947 | ];
|
27948 |
|
27949 |
|
27950 |
|
27951 |
|
27952 |
|
27953 | function getDraggerVisual(draggerGfx) {
|
27954 | return query('.djs-visual', draggerGfx);
|
27955 | }
|
27956 |
|
27957 | var COMMAND_BENDPOINT_UPDATE = 'connection.updateWaypoints',
|
27958 | COMMAND_RECONNECT_START = 'connection.reconnectStart',
|
27959 | COMMAND_RECONNECT_END = 'connection.reconnectEnd';
|
27960 |
|
27961 | var round$3 = Math.round;
|
27962 |
|
27963 |
|
27964 | |
27965 |
|
27966 |
|
27967 | function BendpointMove(injector, eventBus, canvas, dragging, rules, modeling) {
|
27968 |
|
27969 |
|
27970 | var connectionDocking = injector.get('connectionDocking', false);
|
27971 |
|
27972 |
|
27973 |
|
27974 | this.start = function(event, connection, bendpointIndex, insert) {
|
27975 |
|
27976 | var type,
|
27977 | context,
|
27978 | waypoints = connection.waypoints,
|
27979 | gfx = canvas.getGraphics(connection);
|
27980 |
|
27981 | if (!insert && bendpointIndex === 0) {
|
27982 | type = COMMAND_RECONNECT_START;
|
27983 | } else
|
27984 | if (!insert && bendpointIndex === waypoints.length - 1) {
|
27985 | type = COMMAND_RECONNECT_END;
|
27986 | } else {
|
27987 | type = COMMAND_BENDPOINT_UPDATE;
|
27988 | }
|
27989 |
|
27990 | context = {
|
27991 | connection: connection,
|
27992 | bendpointIndex: bendpointIndex,
|
27993 | insert: insert,
|
27994 | type: type
|
27995 | };
|
27996 |
|
27997 | var allowed = context.allowed = rules.allowed(context.type, context);
|
27998 |
|
27999 | if (allowed === false) {
|
28000 | return;
|
28001 | }
|
28002 |
|
28003 | dragging.init(event, 'bendpoint.move', {
|
28004 | data: {
|
28005 | connection: connection,
|
28006 | connectionGfx: gfx,
|
28007 | context: context
|
28008 | }
|
28009 | });
|
28010 | };
|
28011 |
|
28012 | eventBus.on('bendpoint.move.hover', function(event) {
|
28013 | var context = event.context;
|
28014 |
|
28015 | context.hover = event.hover;
|
28016 |
|
28017 | if (event.hover) {
|
28018 |
|
28019 |
|
28020 |
|
28021 | var allowed = context.allowed = rules.allowed(context.type, context);
|
28022 |
|
28023 | if (allowed) {
|
28024 | context.target = context.hover;
|
28025 | }
|
28026 | }
|
28027 | });
|
28028 |
|
28029 | eventBus.on([ 'bendpoint.move.out', 'bendpoint.move.cleanup' ], function(event) {
|
28030 | var context = event.context;
|
28031 |
|
28032 | context.target = null;
|
28033 | context.allowed = false;
|
28034 | });
|
28035 |
|
28036 | eventBus.on('bendpoint.move.end', function(event) {
|
28037 |
|
28038 | var context = event.context,
|
28039 | connection = context.connection,
|
28040 | originalWaypoints = connection.waypoints,
|
28041 | newWaypoints = originalWaypoints.slice(),
|
28042 | bendpointIndex = context.bendpointIndex,
|
28043 | allowed = context.allowed,
|
28044 | insert = context.insert,
|
28045 | bendpoint,
|
28046 | hints;
|
28047 |
|
28048 |
|
28049 |
|
28050 | bendpoint = {
|
28051 | x: round$3(event.x),
|
28052 | y: round$3(event.y)
|
28053 | };
|
28054 |
|
28055 | if (allowed && context.type === COMMAND_RECONNECT_START) {
|
28056 | modeling.reconnectStart(context.connection, context.target, bendpoint);
|
28057 | } else if (allowed && context.type === COMMAND_RECONNECT_END) {
|
28058 | modeling.reconnectEnd(context.connection, context.target, bendpoint);
|
28059 | } else if (allowed !== false && context.type === COMMAND_BENDPOINT_UPDATE) {
|
28060 | if (insert) {
|
28061 |
|
28062 |
|
28063 | newWaypoints.splice(bendpointIndex, 0, bendpoint);
|
28064 | } else {
|
28065 |
|
28066 |
|
28067 | newWaypoints[bendpointIndex] = bendpoint;
|
28068 | }
|
28069 |
|
28070 |
|
28071 |
|
28072 | hints = {
|
28073 | bendpointMove: {
|
28074 | insert: insert,
|
28075 | bendpointIndex: bendpointIndex
|
28076 | }
|
28077 | };
|
28078 |
|
28079 | if (connectionDocking) {
|
28080 |
|
28081 |
|
28082 | connection.waypoints = newWaypoints;
|
28083 |
|
28084 |
|
28085 | connection.waypoints = connectionDocking.getCroppedWaypoints(connection);
|
28086 | newWaypoints = connection.waypoints;
|
28087 |
|
28088 |
|
28089 | connection.waypoints = originalWaypoints;
|
28090 | }
|
28091 |
|
28092 | modeling.updateWaypoints(context.connection, filterRedundantWaypoints(newWaypoints), hints);
|
28093 | } else {
|
28094 | return false;
|
28095 | }
|
28096 | });
|
28097 | }
|
28098 |
|
28099 | BendpointMove.$inject = [
|
28100 | 'injector',
|
28101 | 'eventBus',
|
28102 | 'canvas',
|
28103 | 'dragging',
|
28104 | 'rules',
|
28105 | 'modeling'
|
28106 | ];
|
28107 |
|
28108 | var MARKER_OK = 'connect-ok',
|
28109 | MARKER_NOT_OK = 'connect-not-ok',
|
28110 | MARKER_CONNECT_HOVER = 'connect-hover',
|
28111 | MARKER_CONNECT_UPDATING = 'djs-updating',
|
28112 | MARKER_ELEMENT_HIDDEN = 'djs-element-hidden';
|
28113 |
|
28114 | var COMMAND_RECONNECT_START$1 = 'connection.reconnectStart',
|
28115 | COMMAND_RECONNECT_END$1 = 'connection.reconnectEnd';
|
28116 |
|
28117 | var HIGH_PRIORITY$1 = 1100;
|
28118 |
|
28119 | |
28120 |
|
28121 |
|
28122 | function BendpointMovePreview(injector, eventBus, canvas) {
|
28123 |
|
28124 | var connectionPreview = injector.get('connectionPreview', false),
|
28125 | connectionDocking = injector.get('connectionDocking', false);
|
28126 |
|
28127 |
|
28128 |
|
28129 | eventBus.on('bendpoint.move.start', function(event) {
|
28130 |
|
28131 | var context = event.context,
|
28132 | connection = context.connection,
|
28133 | originalWaypoints = connection.waypoints,
|
28134 | waypoints = originalWaypoints.slice(),
|
28135 | insert = context.insert,
|
28136 | idx = context.bendpointIndex;
|
28137 |
|
28138 |
|
28139 | context.originalWaypoints = originalWaypoints;
|
28140 |
|
28141 | if (insert) {
|
28142 |
|
28143 |
|
28144 | waypoints.splice(idx, 0, { x: event.x, y: event.y });
|
28145 | }
|
28146 |
|
28147 | connection.waypoints = waypoints;
|
28148 |
|
28149 |
|
28150 | context.draggerGfx = addBendpoint(canvas.getLayer('overlays'));
|
28151 | classes$1(context.draggerGfx).add('djs-dragging');
|
28152 |
|
28153 | canvas.addMarker(connection, MARKER_CONNECT_UPDATING);
|
28154 | canvas.addMarker(connection, MARKER_ELEMENT_HIDDEN);
|
28155 | });
|
28156 |
|
28157 | eventBus.on('bendpoint.move.hover', function(event) {
|
28158 | var context = event.context,
|
28159 | allowed = context.allowed,
|
28160 | hover = context.hover,
|
28161 | moveType = context.type;
|
28162 |
|
28163 | if (hover) {
|
28164 | canvas.addMarker(hover, MARKER_CONNECT_HOVER);
|
28165 |
|
28166 | if (
|
28167 | moveType !== COMMAND_RECONNECT_START$1 &&
|
28168 | moveType !== COMMAND_RECONNECT_END$1
|
28169 | ) {
|
28170 | return;
|
28171 | }
|
28172 |
|
28173 | if (allowed) {
|
28174 | canvas.removeMarker(hover, MARKER_NOT_OK);
|
28175 | canvas.addMarker(hover, MARKER_OK);
|
28176 | } else if (allowed === false) {
|
28177 | canvas.removeMarker(hover, MARKER_OK);
|
28178 | canvas.addMarker(hover, MARKER_NOT_OK);
|
28179 | }
|
28180 | }
|
28181 | });
|
28182 |
|
28183 | eventBus.on([
|
28184 | 'bendpoint.move.out',
|
28185 | 'bendpoint.move.cleanup'
|
28186 | ], HIGH_PRIORITY$1, function(event) {
|
28187 |
|
28188 |
|
28189 |
|
28190 | var hover = event.context.hover;
|
28191 |
|
28192 | if (hover) {
|
28193 | canvas.removeMarker(hover, MARKER_CONNECT_HOVER);
|
28194 | canvas.removeMarker(hover, event.context.target ? MARKER_OK : MARKER_NOT_OK);
|
28195 | }
|
28196 | });
|
28197 |
|
28198 | eventBus.on('bendpoint.move.move', function(event) {
|
28199 |
|
28200 | var context = event.context,
|
28201 | moveType = context.type,
|
28202 | connection = event.connection,
|
28203 | originalWaypoints = connection.waypoints,
|
28204 | waypoints = originalWaypoints.slice(),
|
28205 | bendpoint = { x: event.x, y: event.y },
|
28206 | hints;
|
28207 |
|
28208 | if (connectionPreview) {
|
28209 | hints = {
|
28210 | source: connection.source,
|
28211 | target: connection.target
|
28212 | };
|
28213 |
|
28214 | if (moveType === COMMAND_RECONNECT_START$1) {
|
28215 | hints.source = context.target;
|
28216 | hints.connectionStart = bendpoint;
|
28217 | } else if (moveType === COMMAND_RECONNECT_END$1) {
|
28218 | hints.target = context.target;
|
28219 | hints.connectionEnd = bendpoint;
|
28220 | } else {
|
28221 | hints.noCropping = true;
|
28222 | hints.noLayout = true;
|
28223 | waypoints[context.bendpointIndex] = bendpoint;
|
28224 | }
|
28225 |
|
28226 | if (connectionDocking) {
|
28227 |
|
28228 |
|
28229 | connection.waypoints = waypoints;
|
28230 |
|
28231 |
|
28232 | connection.waypoints = connectionDocking.getCroppedWaypoints(connection);
|
28233 | waypoints = connection.waypoints;
|
28234 |
|
28235 |
|
28236 | connection.waypoints = originalWaypoints;
|
28237 | }
|
28238 |
|
28239 |
|
28240 | hints.waypoints = filterRedundantWaypoints(waypoints);
|
28241 |
|
28242 | connectionPreview.drawPreview(context, context.allowed, hints);
|
28243 | }
|
28244 |
|
28245 |
|
28246 | translate(context.draggerGfx, event.x, event.y);
|
28247 | });
|
28248 |
|
28249 | eventBus.on([
|
28250 | 'bendpoint.move.end',
|
28251 | 'bendpoint.move.cancel'
|
28252 | ], HIGH_PRIORITY$1, function(event) {
|
28253 |
|
28254 | var context = event.context,
|
28255 | hover = context.hover,
|
28256 | connection = context.connection;
|
28257 |
|
28258 |
|
28259 | connection.waypoints = context.originalWaypoints;
|
28260 |
|
28261 |
|
28262 | remove$1(context.draggerGfx);
|
28263 |
|
28264 | canvas.removeMarker(connection, MARKER_CONNECT_UPDATING);
|
28265 | canvas.removeMarker(connection, MARKER_ELEMENT_HIDDEN);
|
28266 |
|
28267 | if (hover) {
|
28268 | canvas.removeMarker(hover, MARKER_OK);
|
28269 | canvas.removeMarker(hover, context.target ? MARKER_OK : MARKER_NOT_OK);
|
28270 | }
|
28271 |
|
28272 | if (connectionPreview) {
|
28273 | connectionPreview.cleanUp(context);
|
28274 | }
|
28275 | });
|
28276 | }
|
28277 |
|
28278 | BendpointMovePreview.$inject = [
|
28279 | 'injector',
|
28280 | 'eventBus',
|
28281 | 'canvas'
|
28282 | ];
|
28283 |
|
28284 | var MARKER_CONNECT_HOVER$1 = 'connect-hover',
|
28285 | MARKER_CONNECT_UPDATING$1 = 'djs-updating';
|
28286 |
|
28287 |
|
28288 | function axisAdd(point, axis, delta) {
|
28289 | return axisSet(point, axis, point[axis] + delta);
|
28290 | }
|
28291 |
|
28292 | function axisSet(point, axis, value) {
|
28293 | return {
|
28294 | x: (axis === 'x' ? value : point.x),
|
28295 | y: (axis === 'y' ? value : point.y)
|
28296 | };
|
28297 | }
|
28298 |
|
28299 | function axisFenced(position, segmentStart, segmentEnd, axis) {
|
28300 |
|
28301 | var maxValue = Math.max(segmentStart[axis], segmentEnd[axis]),
|
28302 | minValue = Math.min(segmentStart[axis], segmentEnd[axis]);
|
28303 |
|
28304 | var padding = 20;
|
28305 |
|
28306 | var fencedValue = Math.min(Math.max(minValue + padding, position[axis]), maxValue - padding);
|
28307 |
|
28308 | return axisSet(segmentStart, axis, fencedValue);
|
28309 | }
|
28310 |
|
28311 | function flipAxis(axis) {
|
28312 | return axis === 'x' ? 'y' : 'x';
|
28313 | }
|
28314 |
|
28315 | |
28316 |
|
28317 |
|
28318 |
|
28319 |
|
28320 |
|
28321 |
|
28322 |
|
28323 |
|
28324 |
|
28325 |
|
28326 | function getDocking(point, referenceElement, moveAxis) {
|
28327 |
|
28328 | var referenceMid,
|
28329 | inverseAxis;
|
28330 |
|
28331 | if (point.original) {
|
28332 | return point.original;
|
28333 | } else {
|
28334 | referenceMid = getMid(referenceElement);
|
28335 | inverseAxis = flipAxis(moveAxis);
|
28336 |
|
28337 | return axisSet(point, inverseAxis, referenceMid[inverseAxis]);
|
28338 | }
|
28339 | }
|
28340 |
|
28341 | |
28342 |
|
28343 |
|
28344 | function ConnectionSegmentMove(
|
28345 | injector, eventBus, canvas,
|
28346 | dragging, graphicsFactory, modeling) {
|
28347 |
|
28348 |
|
28349 | var connectionDocking = injector.get('connectionDocking', false);
|
28350 |
|
28351 |
|
28352 |
|
28353 |
|
28354 | this.start = function(event, connection, idx) {
|
28355 |
|
28356 | var context,
|
28357 | gfx = canvas.getGraphics(connection),
|
28358 | segmentStartIndex = idx - 1,
|
28359 | segmentEndIndex = idx,
|
28360 | waypoints = connection.waypoints,
|
28361 | segmentStart = waypoints[segmentStartIndex],
|
28362 | segmentEnd = waypoints[segmentEndIndex],
|
28363 | intersection = getConnectionIntersection(canvas, waypoints, event),
|
28364 | direction, axis, dragPosition;
|
28365 |
|
28366 | direction = pointsAligned(segmentStart, segmentEnd);
|
28367 |
|
28368 |
|
28369 | if (!direction) {
|
28370 | return;
|
28371 | }
|
28372 |
|
28373 |
|
28374 | axis = direction === 'v' ? 'x' : 'y';
|
28375 |
|
28376 | if (segmentStartIndex === 0) {
|
28377 | segmentStart = getDocking(segmentStart, connection.source, axis);
|
28378 | }
|
28379 |
|
28380 | if (segmentEndIndex === waypoints.length - 1) {
|
28381 | segmentEnd = getDocking(segmentEnd, connection.target, axis);
|
28382 | }
|
28383 |
|
28384 | if (intersection) {
|
28385 | dragPosition = intersection.point;
|
28386 | } else {
|
28387 |
|
28388 |
|
28389 | dragPosition = {
|
28390 | x: (segmentStart.x + segmentEnd.x) / 2,
|
28391 | y: (segmentStart.y + segmentEnd.y) / 2
|
28392 | };
|
28393 | }
|
28394 |
|
28395 | context = {
|
28396 | connection: connection,
|
28397 | segmentStartIndex: segmentStartIndex,
|
28398 | segmentEndIndex: segmentEndIndex,
|
28399 | segmentStart: segmentStart,
|
28400 | segmentEnd: segmentEnd,
|
28401 | axis: axis,
|
28402 | dragPosition: dragPosition
|
28403 | };
|
28404 |
|
28405 | dragging.init(event, dragPosition, 'connectionSegment.move', {
|
28406 | cursor: axis === 'x' ? 'resize-ew' : 'resize-ns',
|
28407 | data: {
|
28408 | connection: connection,
|
28409 | connectionGfx: gfx,
|
28410 | context: context
|
28411 | }
|
28412 | });
|
28413 | };
|
28414 |
|
28415 | |
28416 |
|
28417 |
|
28418 |
|
28419 |
|
28420 |
|
28421 |
|
28422 |
|
28423 | function cropConnection(connection, newWaypoints) {
|
28424 |
|
28425 |
|
28426 | if (!connectionDocking) {
|
28427 | return newWaypoints;
|
28428 | }
|
28429 |
|
28430 | var oldWaypoints = connection.waypoints,
|
28431 | croppedWaypoints;
|
28432 |
|
28433 |
|
28434 | connection.waypoints = newWaypoints;
|
28435 |
|
28436 | croppedWaypoints = connectionDocking.getCroppedWaypoints(connection);
|
28437 |
|
28438 |
|
28439 | connection.waypoints = oldWaypoints;
|
28440 |
|
28441 | return croppedWaypoints;
|
28442 | }
|
28443 |
|
28444 |
|
28445 |
|
28446 | function redrawConnection(data) {
|
28447 | graphicsFactory.update('connection', data.connection, data.connectionGfx);
|
28448 | }
|
28449 |
|
28450 | function updateDragger(context, segmentOffset, event) {
|
28451 |
|
28452 | var newWaypoints = context.newWaypoints,
|
28453 | segmentStartIndex = context.segmentStartIndex + segmentOffset,
|
28454 | segmentStart = newWaypoints[segmentStartIndex],
|
28455 | segmentEndIndex = context.segmentEndIndex + segmentOffset,
|
28456 | segmentEnd = newWaypoints[segmentEndIndex],
|
28457 | axis = flipAxis(context.axis);
|
28458 |
|
28459 |
|
28460 |
|
28461 | var draggerPosition = axisFenced(event, segmentStart, segmentEnd, axis);
|
28462 |
|
28463 |
|
28464 | translate(context.draggerGfx, draggerPosition.x, draggerPosition.y);
|
28465 | }
|
28466 |
|
28467 | |
28468 |
|
28469 |
|
28470 |
|
28471 |
|
28472 |
|
28473 |
|
28474 |
|
28475 |
|
28476 | function filterRedundantWaypoints(waypoints, segmentStartIndex) {
|
28477 |
|
28478 | var segmentOffset = 0;
|
28479 |
|
28480 | var filteredWaypoints = waypoints.filter(function(r, idx) {
|
28481 | if (pointsOnLine(waypoints[idx - 1], waypoints[idx + 1], r)) {
|
28482 |
|
28483 |
|
28484 | segmentOffset = idx <= segmentStartIndex ? segmentOffset - 1 : segmentOffset;
|
28485 | return false;
|
28486 | }
|
28487 |
|
28488 |
|
28489 | return true;
|
28490 | });
|
28491 |
|
28492 | return {
|
28493 | waypoints: filteredWaypoints,
|
28494 | segmentOffset: segmentOffset
|
28495 | };
|
28496 | }
|
28497 |
|
28498 | eventBus.on('connectionSegment.move.start', function(event) {
|
28499 |
|
28500 | var context = event.context,
|
28501 | connection = event.connection,
|
28502 | layer = canvas.getLayer('overlays');
|
28503 |
|
28504 | context.originalWaypoints = connection.waypoints.slice();
|
28505 |
|
28506 |
|
28507 | context.draggerGfx = addSegmentDragger(layer, context.segmentStart, context.segmentEnd);
|
28508 | classes$1(context.draggerGfx).add('djs-dragging');
|
28509 |
|
28510 | canvas.addMarker(connection, MARKER_CONNECT_UPDATING$1);
|
28511 | });
|
28512 |
|
28513 | eventBus.on('connectionSegment.move.move', function(event) {
|
28514 |
|
28515 | var context = event.context,
|
28516 | connection = context.connection,
|
28517 | segmentStartIndex = context.segmentStartIndex,
|
28518 | segmentEndIndex = context.segmentEndIndex,
|
28519 | segmentStart = context.segmentStart,
|
28520 | segmentEnd = context.segmentEnd,
|
28521 | axis = context.axis;
|
28522 |
|
28523 | var newWaypoints = context.originalWaypoints.slice(),
|
28524 | newSegmentStart = axisAdd(segmentStart, axis, event['d' + axis]),
|
28525 | newSegmentEnd = axisAdd(segmentEnd, axis, event['d' + axis]);
|
28526 |
|
28527 |
|
28528 |
|
28529 |
|
28530 | var waypointCount = newWaypoints.length,
|
28531 | segmentOffset = 0;
|
28532 |
|
28533 |
|
28534 | newWaypoints[segmentStartIndex] = newSegmentStart;
|
28535 | newWaypoints[segmentEndIndex] = newSegmentEnd;
|
28536 |
|
28537 | var sourceToSegmentOrientation,
|
28538 | targetToSegmentOrientation;
|
28539 |
|
28540 |
|
28541 | if (segmentStartIndex < 2) {
|
28542 | sourceToSegmentOrientation = getOrientation(connection.source, newSegmentStart);
|
28543 |
|
28544 |
|
28545 | if (segmentStartIndex === 1) {
|
28546 |
|
28547 | if (sourceToSegmentOrientation === 'intersect') {
|
28548 | newWaypoints.shift();
|
28549 | newWaypoints[0] = newSegmentStart;
|
28550 | segmentOffset--;
|
28551 | }
|
28552 | }
|
28553 |
|
28554 |
|
28555 | else {
|
28556 | if (sourceToSegmentOrientation !== 'intersect') {
|
28557 | newWaypoints.unshift(segmentStart);
|
28558 | segmentOffset++;
|
28559 | }
|
28560 | }
|
28561 | }
|
28562 |
|
28563 |
|
28564 | if (segmentEndIndex > waypointCount - 3) {
|
28565 | targetToSegmentOrientation = getOrientation(connection.target, newSegmentEnd);
|
28566 |
|
28567 |
|
28568 | if (segmentEndIndex === waypointCount - 2) {
|
28569 |
|
28570 | if (targetToSegmentOrientation === 'intersect') {
|
28571 | newWaypoints.pop();
|
28572 | newWaypoints[newWaypoints.length - 1] = newSegmentEnd;
|
28573 | }
|
28574 | }
|
28575 |
|
28576 |
|
28577 | else {
|
28578 | if (targetToSegmentOrientation !== 'intersect') {
|
28579 | newWaypoints.push(segmentEnd);
|
28580 | }
|
28581 | }
|
28582 | }
|
28583 |
|
28584 |
|
28585 | context.newWaypoints = connection.waypoints = cropConnection(connection, newWaypoints);
|
28586 |
|
28587 |
|
28588 | updateDragger(context, segmentOffset, event);
|
28589 |
|
28590 |
|
28591 | context.newSegmentStartIndex = segmentStartIndex + segmentOffset;
|
28592 |
|
28593 |
|
28594 | redrawConnection(event);
|
28595 | });
|
28596 |
|
28597 | eventBus.on('connectionSegment.move.hover', function(event) {
|
28598 |
|
28599 | event.context.hover = event.hover;
|
28600 | canvas.addMarker(event.hover, MARKER_CONNECT_HOVER$1);
|
28601 | });
|
28602 |
|
28603 | eventBus.on([
|
28604 | 'connectionSegment.move.out',
|
28605 | 'connectionSegment.move.cleanup'
|
28606 | ], function(event) {
|
28607 |
|
28608 |
|
28609 |
|
28610 | var hover = event.context.hover;
|
28611 |
|
28612 | if (hover) {
|
28613 | canvas.removeMarker(hover, MARKER_CONNECT_HOVER$1);
|
28614 | }
|
28615 | });
|
28616 |
|
28617 | eventBus.on('connectionSegment.move.cleanup', function(event) {
|
28618 |
|
28619 | var context = event.context,
|
28620 | connection = context.connection;
|
28621 |
|
28622 |
|
28623 | if (context.draggerGfx) {
|
28624 | remove$1(context.draggerGfx);
|
28625 | }
|
28626 |
|
28627 | canvas.removeMarker(connection, MARKER_CONNECT_UPDATING$1);
|
28628 | });
|
28629 |
|
28630 | eventBus.on([
|
28631 | 'connectionSegment.move.cancel',
|
28632 | 'connectionSegment.move.end'
|
28633 | ], function(event) {
|
28634 | var context = event.context,
|
28635 | connection = context.connection;
|
28636 |
|
28637 | connection.waypoints = context.originalWaypoints;
|
28638 |
|
28639 | redrawConnection(event);
|
28640 | });
|
28641 |
|
28642 | eventBus.on('connectionSegment.move.end', function(event) {
|
28643 |
|
28644 | var context = event.context,
|
28645 | connection = context.connection,
|
28646 | newWaypoints = context.newWaypoints,
|
28647 | newSegmentStartIndex = context.newSegmentStartIndex;
|
28648 |
|
28649 |
|
28650 |
|
28651 | newWaypoints = newWaypoints.map(function(p) {
|
28652 | return {
|
28653 | original: p.original,
|
28654 | x: Math.round(p.x),
|
28655 | y: Math.round(p.y)
|
28656 | };
|
28657 | });
|
28658 |
|
28659 |
|
28660 | var filtered = filterRedundantWaypoints(newWaypoints, newSegmentStartIndex);
|
28661 |
|
28662 |
|
28663 | var filteredWaypoints = filtered.waypoints,
|
28664 | croppedWaypoints = cropConnection(connection, filteredWaypoints),
|
28665 | segmentOffset = filtered.segmentOffset;
|
28666 |
|
28667 | var hints = {
|
28668 | segmentMove: {
|
28669 | segmentStartIndex: context.segmentStartIndex,
|
28670 | newSegmentStartIndex: newSegmentStartIndex + segmentOffset
|
28671 | }
|
28672 | };
|
28673 |
|
28674 | modeling.updateWaypoints(connection, croppedWaypoints, hints);
|
28675 | });
|
28676 | }
|
28677 |
|
28678 | ConnectionSegmentMove.$inject = [
|
28679 | 'injector',
|
28680 | 'eventBus',
|
28681 | 'canvas',
|
28682 | 'dragging',
|
28683 | 'graphicsFactory',
|
28684 | 'modeling'
|
28685 | ];
|
28686 |
|
28687 | var abs$1 = Math.abs,
|
28688 | round$4 = Math.round;
|
28689 |
|
28690 |
|
28691 | |
28692 |
|
28693 |
|
28694 |
|
28695 |
|
28696 |
|
28697 |
|
28698 |
|
28699 |
|
28700 | function snapTo(value, values, tolerance) {
|
28701 | tolerance = tolerance === undefined ? 10 : tolerance;
|
28702 |
|
28703 | var idx, snapValue;
|
28704 |
|
28705 | for (idx = 0; idx < values.length; idx++) {
|
28706 | snapValue = values[idx];
|
28707 |
|
28708 | if (abs$1(snapValue - value) <= tolerance) {
|
28709 | return snapValue;
|
28710 | }
|
28711 | }
|
28712 | }
|
28713 |
|
28714 |
|
28715 | function topLeft(bounds) {
|
28716 | return {
|
28717 | x: bounds.x,
|
28718 | y: bounds.y
|
28719 | };
|
28720 | }
|
28721 |
|
28722 | function topRight(bounds) {
|
28723 | return {
|
28724 | x: bounds.x + bounds.width,
|
28725 | y: bounds.y
|
28726 | };
|
28727 | }
|
28728 |
|
28729 | function bottomLeft(bounds) {
|
28730 | return {
|
28731 | x: bounds.x,
|
28732 | y: bounds.y + bounds.height
|
28733 | };
|
28734 | }
|
28735 |
|
28736 | function bottomRight(bounds) {
|
28737 | return {
|
28738 | x: bounds.x + bounds.width,
|
28739 | y: bounds.y + bounds.height
|
28740 | };
|
28741 | }
|
28742 |
|
28743 | function mid(bounds, defaultValue) {
|
28744 |
|
28745 | if (!bounds || isNaN(bounds.x) || isNaN(bounds.y)) {
|
28746 | return defaultValue;
|
28747 | }
|
28748 |
|
28749 | return {
|
28750 | x: round$4(bounds.x + bounds.width / 2),
|
28751 | y: round$4(bounds.y + bounds.height / 2)
|
28752 | };
|
28753 | }
|
28754 |
|
28755 |
|
28756 | |
28757 |
|
28758 |
|
28759 |
|
28760 |
|
28761 |
|
28762 |
|
28763 |
|
28764 |
|
28765 | function isSnapped(event, axis) {
|
28766 | var snapped = event.snapped;
|
28767 |
|
28768 | if (!snapped) {
|
28769 | return false;
|
28770 | }
|
28771 |
|
28772 | if (typeof axis === 'string') {
|
28773 | return snapped[axis];
|
28774 | }
|
28775 |
|
28776 | return snapped.x && snapped.y;
|
28777 | }
|
28778 |
|
28779 |
|
28780 | |
28781 |
|
28782 |
|
28783 |
|
28784 |
|
28785 |
|
28786 |
|
28787 |
|
28788 |
|
28789 |
|
28790 |
|
28791 |
|
28792 | function setSnapped(event, axis, value) {
|
28793 | if (typeof axis !== 'string') {
|
28794 | throw new Error('axis must be in [x, y]');
|
28795 | }
|
28796 |
|
28797 | if (typeof value !== 'number' && value !== false) {
|
28798 | throw new Error('value must be Number or false');
|
28799 | }
|
28800 |
|
28801 | var delta,
|
28802 | previousValue = event[axis];
|
28803 |
|
28804 | var snapped = event.snapped = (event.snapped || {});
|
28805 |
|
28806 |
|
28807 | if (value === false) {
|
28808 | snapped[axis] = false;
|
28809 | } else {
|
28810 | snapped[axis] = true;
|
28811 |
|
28812 | delta = value - previousValue;
|
28813 |
|
28814 | event[axis] += delta;
|
28815 | event['d' + axis] += delta;
|
28816 | }
|
28817 |
|
28818 | return previousValue;
|
28819 | }
|
28820 |
|
28821 | |
28822 |
|
28823 |
|
28824 |
|
28825 |
|
28826 |
|
28827 |
|
28828 | function getChildren$1(parent) {
|
28829 | return parent.children || [];
|
28830 | }
|
28831 |
|
28832 | var abs$2= Math.abs,
|
28833 | round$5 = Math.round;
|
28834 |
|
28835 | var TOLERANCE = 10;
|
28836 |
|
28837 |
|
28838 | function BendpointSnapping(eventBus) {
|
28839 |
|
28840 | function snapTo(values, value) {
|
28841 |
|
28842 | if (isArray(values)) {
|
28843 | var i = values.length;
|
28844 |
|
28845 | while (i--) if (abs$2(values[i] - value) <= TOLERANCE) {
|
28846 | return values[i];
|
28847 | }
|
28848 | } else {
|
28849 | values = +values;
|
28850 | var rem = value % values;
|
28851 |
|
28852 | if (rem < TOLERANCE) {
|
28853 | return value - rem;
|
28854 | }
|
28855 |
|
28856 | if (rem > values - TOLERANCE) {
|
28857 | return value - rem + values;
|
28858 | }
|
28859 | }
|
28860 |
|
28861 | return value;
|
28862 | }
|
28863 |
|
28864 | function mid(element) {
|
28865 | if (element.width) {
|
28866 | return {
|
28867 | x: round$5(element.width / 2 + element.x),
|
28868 | y: round$5(element.height / 2 + element.y)
|
28869 | };
|
28870 | }
|
28871 | }
|
28872 |
|
28873 |
|
28874 |
|
28875 | function getConnectionSegmentSnaps(context) {
|
28876 |
|
28877 | var snapPoints = context.snapPoints,
|
28878 | connection = context.connection,
|
28879 | waypoints = connection.waypoints,
|
28880 | segmentStart = context.segmentStart,
|
28881 | segmentStartIndex = context.segmentStartIndex,
|
28882 | segmentEnd = context.segmentEnd,
|
28883 | segmentEndIndex = context.segmentEndIndex,
|
28884 | axis = context.axis;
|
28885 |
|
28886 | if (snapPoints) {
|
28887 | return snapPoints;
|
28888 | }
|
28889 |
|
28890 | var referenceWaypoints = [
|
28891 | waypoints[segmentStartIndex - 1],
|
28892 | segmentStart,
|
28893 | segmentEnd,
|
28894 | waypoints[segmentEndIndex + 1]
|
28895 | ];
|
28896 |
|
28897 | if (segmentStartIndex < 2) {
|
28898 | referenceWaypoints.unshift(mid(connection.source));
|
28899 | }
|
28900 |
|
28901 | if (segmentEndIndex > waypoints.length - 3) {
|
28902 | referenceWaypoints.unshift(mid(connection.target));
|
28903 | }
|
28904 |
|
28905 | context.snapPoints = snapPoints = { horizontal: [] , vertical: [] };
|
28906 |
|
28907 | forEach(referenceWaypoints, function(p) {
|
28908 |
|
28909 |
|
28910 |
|
28911 | if (p) {
|
28912 | p = p.original || p;
|
28913 |
|
28914 | if (axis === 'y') {
|
28915 | snapPoints.horizontal.push(p.y);
|
28916 | }
|
28917 |
|
28918 | if (axis === 'x') {
|
28919 | snapPoints.vertical.push(p.x);
|
28920 | }
|
28921 | }
|
28922 | });
|
28923 |
|
28924 | return snapPoints;
|
28925 | }
|
28926 |
|
28927 | eventBus.on('connectionSegment.move.move', 1500, function(event) {
|
28928 | var context = event.context,
|
28929 | snapPoints = getConnectionSegmentSnaps(context),
|
28930 | x = event.x,
|
28931 | y = event.y,
|
28932 | sx, sy;
|
28933 |
|
28934 | if (!snapPoints) {
|
28935 | return;
|
28936 | }
|
28937 |
|
28938 |
|
28939 | sx = snapTo(snapPoints.vertical, x);
|
28940 | sy = snapTo(snapPoints.horizontal, y);
|
28941 |
|
28942 |
|
28943 |
|
28944 | var cx = (x - sx),
|
28945 | cy = (y - sy);
|
28946 |
|
28947 |
|
28948 | assign(event, {
|
28949 | dx: event.dx - cx,
|
28950 | dy: event.dy - cy,
|
28951 | x: sx,
|
28952 | y: sy
|
28953 | });
|
28954 |
|
28955 |
|
28956 | if (cx || snapPoints.vertical.indexOf(x) !== -1) {
|
28957 | setSnapped(event, 'x', sx);
|
28958 | }
|
28959 |
|
28960 | if (cy || snapPoints.horizontal.indexOf(y) !== -1) {
|
28961 | setSnapped(event, 'y', sy);
|
28962 | }
|
28963 | });
|
28964 |
|
28965 |
|
28966 |
|
28967 |
|
28968 | function getBendpointSnaps(context) {
|
28969 |
|
28970 | var snapPoints = context.snapPoints,
|
28971 | waypoints = context.connection.waypoints,
|
28972 | bendpointIndex = context.bendpointIndex;
|
28973 |
|
28974 | if (snapPoints) {
|
28975 | return snapPoints;
|
28976 | }
|
28977 |
|
28978 | var referenceWaypoints = [ waypoints[bendpointIndex - 1], waypoints[bendpointIndex + 1] ];
|
28979 |
|
28980 | context.snapPoints = snapPoints = { horizontal: [] , vertical: [] };
|
28981 |
|
28982 | forEach(referenceWaypoints, function(p) {
|
28983 |
|
28984 |
|
28985 |
|
28986 | if (p) {
|
28987 | p = p.original || p;
|
28988 |
|
28989 | snapPoints.horizontal.push(p.y);
|
28990 | snapPoints.vertical.push(p.x);
|
28991 | }
|
28992 | });
|
28993 |
|
28994 | return snapPoints;
|
28995 | }
|
28996 |
|
28997 |
|
28998 | eventBus.on([ 'bendpoint.move.move', 'bendpoint.move.end' ], 1500, function(event) {
|
28999 |
|
29000 | var context = event.context,
|
29001 | snapPoints = getBendpointSnaps(context),
|
29002 | target = context.target,
|
29003 | targetMid = target && mid(target),
|
29004 | x = event.x,
|
29005 | y = event.y,
|
29006 | sx, sy;
|
29007 |
|
29008 | if (!snapPoints) {
|
29009 | return;
|
29010 | }
|
29011 |
|
29012 |
|
29013 | sx = snapTo(targetMid ? snapPoints.vertical.concat([ targetMid.x ]) : snapPoints.vertical, x);
|
29014 | sy = snapTo(targetMid ? snapPoints.horizontal.concat([ targetMid.y ]) : snapPoints.horizontal, y);
|
29015 |
|
29016 |
|
29017 | var cx = (x - sx),
|
29018 | cy = (y - sy);
|
29019 |
|
29020 |
|
29021 | assign(event, {
|
29022 | dx: event.dx - cx,
|
29023 | dy: event.dy - cy,
|
29024 | x: event.x - cx,
|
29025 | y: event.y - cy
|
29026 | });
|
29027 |
|
29028 |
|
29029 | if (cx || snapPoints.vertical.indexOf(x) !== -1) {
|
29030 | setSnapped(event, 'x', sx);
|
29031 | }
|
29032 |
|
29033 | if (cy || snapPoints.horizontal.indexOf(y) !== -1) {
|
29034 | setSnapped(event, 'y', sy);
|
29035 | }
|
29036 | });
|
29037 | }
|
29038 |
|
29039 |
|
29040 | BendpointSnapping.$inject = [ 'eventBus' ];
|
29041 |
|
29042 | var BendpointsModule = {
|
29043 | __depends__: [
|
29044 | DraggingModule,
|
29045 | RulesModule
|
29046 | ],
|
29047 | __init__: [ 'bendpoints', 'bendpointSnapping', 'bendpointMovePreview' ],
|
29048 | bendpoints: [ 'type', Bendpoints ],
|
29049 | bendpointMove: [ 'type', BendpointMove ],
|
29050 | bendpointMovePreview: [ 'type', BendpointMovePreview ],
|
29051 | connectionSegmentMove: [ 'type', ConnectionSegmentMove ],
|
29052 | bendpointSnapping: [ 'type', BendpointSnapping ]
|
29053 | };
|
29054 |
|
29055 | function Connect(eventBus, dragging, modeling, rules) {
|
29056 |
|
29057 |
|
29058 |
|
29059 | function canConnect(source, target) {
|
29060 | return rules.allowed('connection.create', {
|
29061 | source: source,
|
29062 | target: target
|
29063 | });
|
29064 | }
|
29065 |
|
29066 |
|
29067 |
|
29068 |
|
29069 | eventBus.on('connect.hover', function(event) {
|
29070 | var context = event.context,
|
29071 | source = context.source,
|
29072 | hover = event.hover,
|
29073 | canExecute;
|
29074 |
|
29075 | canExecute = context.canExecute = canConnect(source, hover);
|
29076 |
|
29077 |
|
29078 | if (canExecute === null) {
|
29079 | return;
|
29080 | }
|
29081 |
|
29082 | context.target = hover;
|
29083 | });
|
29084 |
|
29085 | eventBus.on([ 'connect.out', 'connect.cleanup' ], function(event) {
|
29086 | var context = event.context;
|
29087 |
|
29088 | context.target = null;
|
29089 | context.canExecute = false;
|
29090 | });
|
29091 |
|
29092 | eventBus.on('connect.end', function(event) {
|
29093 |
|
29094 | var context = event.context,
|
29095 | source = context.source,
|
29096 | sourcePosition = context.sourcePosition,
|
29097 | target = context.target,
|
29098 | targetPosition = {
|
29099 | x: event.x,
|
29100 | y: event.y
|
29101 | },
|
29102 | canExecute = context.canExecute || canConnect(source, target);
|
29103 |
|
29104 | if (!canExecute) {
|
29105 | return false;
|
29106 | }
|
29107 |
|
29108 | var attrs = null,
|
29109 | hints = {
|
29110 | connectionStart: sourcePosition,
|
29111 | connectionEnd: targetPosition
|
29112 | };
|
29113 |
|
29114 | if (typeof canExecute === 'object') {
|
29115 | attrs = canExecute;
|
29116 | }
|
29117 |
|
29118 | modeling.connect(source, target, attrs, hints);
|
29119 | });
|
29120 |
|
29121 |
|
29122 |
|
29123 |
|
29124 | |
29125 |
|
29126 |
|
29127 |
|
29128 |
|
29129 |
|
29130 |
|
29131 |
|
29132 | this.start = function(event, source, sourcePosition, autoActivate) {
|
29133 |
|
29134 | if (typeof sourcePosition !== 'object') {
|
29135 | autoActivate = sourcePosition;
|
29136 | sourcePosition = getMid(source);
|
29137 | }
|
29138 |
|
29139 | dragging.init(event, 'connect', {
|
29140 | autoActivate: autoActivate,
|
29141 | data: {
|
29142 | shape: source,
|
29143 | context: {
|
29144 | source: source,
|
29145 | sourcePosition: sourcePosition
|
29146 | }
|
29147 | }
|
29148 | });
|
29149 | };
|
29150 | }
|
29151 |
|
29152 | Connect.$inject = [
|
29153 | 'eventBus',
|
29154 | 'dragging',
|
29155 | 'modeling',
|
29156 | 'rules'
|
29157 | ];
|
29158 |
|
29159 | var HIGH_PRIORITY$2 = 1100,
|
29160 | LOW_PRIORITY$4 = 900;
|
29161 |
|
29162 | var MARKER_OK$1 = 'connect-ok',
|
29163 | MARKER_NOT_OK$1 = 'connect-not-ok';
|
29164 |
|
29165 | |
29166 |
|
29167 |
|
29168 |
|
29169 |
|
29170 |
|
29171 |
|
29172 | function ConnectPreview(injector, eventBus, canvas) {
|
29173 | var connectionPreview = injector.get('connectionPreview', false);
|
29174 |
|
29175 | connectionPreview && eventBus.on('connect.move', function(event) {
|
29176 | var context = event.context,
|
29177 | source = context.source,
|
29178 | target = context.target,
|
29179 | canConnect = context.canExecute;
|
29180 |
|
29181 | var endPosition = {
|
29182 | x: event.x,
|
29183 | y: event.y
|
29184 | };
|
29185 |
|
29186 | connectionPreview.drawPreview(context, canConnect, {
|
29187 | source: source,
|
29188 | target: target,
|
29189 | connectionEnd: endPosition
|
29190 | });
|
29191 | });
|
29192 |
|
29193 | eventBus.on('connect.hover', LOW_PRIORITY$4, function(event) {
|
29194 | var context = event.context,
|
29195 | hover = event.hover,
|
29196 | canExecute = context.canExecute;
|
29197 |
|
29198 |
|
29199 | if (canExecute === null) {
|
29200 | return;
|
29201 | }
|
29202 |
|
29203 | canvas.addMarker(hover, canExecute ? MARKER_OK$1 : MARKER_NOT_OK$1);
|
29204 | });
|
29205 |
|
29206 | eventBus.on([ 'connect.out', 'connect.cleanup' ], HIGH_PRIORITY$2, function(event) {
|
29207 | var context = event.context;
|
29208 |
|
29209 |
|
29210 | if (context.target) {
|
29211 | canvas.removeMarker(context.target, context.canExecute ? MARKER_OK$1 : MARKER_NOT_OK$1);
|
29212 | }
|
29213 | });
|
29214 |
|
29215 | connectionPreview && eventBus.on('connect.cleanup', function(event) {
|
29216 | connectionPreview.cleanUp(event.context);
|
29217 | });
|
29218 | }
|
29219 |
|
29220 | ConnectPreview.$inject = [
|
29221 | 'injector',
|
29222 | 'eventBus',
|
29223 | 'canvas'
|
29224 | ];
|
29225 |
|
29226 | var ConnectModule = {
|
29227 | __depends__: [
|
29228 | SelectionModule,
|
29229 | RulesModule,
|
29230 | DraggingModule
|
29231 | ],
|
29232 | __init__: [
|
29233 | 'connectPreview'
|
29234 | ],
|
29235 | connect: [ 'type', Connect ],
|
29236 | connectPreview: [ 'type', ConnectPreview ]
|
29237 | };
|
29238 |
|
29239 | var MARKER_CONNECTION_PREVIEW = 'djs-connection-preview';
|
29240 |
|
29241 | |
29242 |
|
29243 |
|
29244 |
|
29245 |
|
29246 |
|
29247 |
|
29248 |
|
29249 |
|
29250 | function ConnectionPreview(
|
29251 | injector,
|
29252 | canvas,
|
29253 | graphicsFactory,
|
29254 | elementFactory
|
29255 | ) {
|
29256 | this._canvas = canvas;
|
29257 | this._graphicsFactory = graphicsFactory;
|
29258 | this._elementFactory = elementFactory;
|
29259 |
|
29260 |
|
29261 | this._connectionDocking = injector.get('connectionDocking', false);
|
29262 | this._layouter = injector.get('layouter', false);
|
29263 | }
|
29264 |
|
29265 | ConnectionPreview.$inject = [
|
29266 | 'injector',
|
29267 | 'canvas',
|
29268 | 'graphicsFactory',
|
29269 | 'elementFactory'
|
29270 | ];
|
29271 |
|
29272 | |
29273 |
|
29274 |
|
29275 |
|
29276 |
|
29277 |
|
29278 |
|
29279 |
|
29280 |
|
29281 |
|
29282 |
|
29283 |
|
29284 |
|
29285 |
|
29286 |
|
29287 |
|
29288 |
|
29289 |
|
29290 | ConnectionPreview.prototype.drawPreview = function(context, canConnect, hints) {
|
29291 |
|
29292 | hints = hints || {};
|
29293 |
|
29294 | var connectionPreviewGfx = context.connectionPreviewGfx,
|
29295 | getConnection = context.getConnection,
|
29296 | source = hints.source,
|
29297 | target = hints.target,
|
29298 | waypoints = hints.waypoints,
|
29299 | connectionStart = hints.connectionStart,
|
29300 | connectionEnd = hints.connectionEnd,
|
29301 | noLayout = hints.noLayout,
|
29302 | noCropping = hints.noCropping,
|
29303 | noNoop = hints.noNoop,
|
29304 | connection;
|
29305 |
|
29306 | var self = this;
|
29307 |
|
29308 | if (!connectionPreviewGfx) {
|
29309 | connectionPreviewGfx = context.connectionPreviewGfx = this.createConnectionPreviewGfx();
|
29310 | }
|
29311 |
|
29312 | clear$1(connectionPreviewGfx);
|
29313 |
|
29314 | if (!getConnection) {
|
29315 | getConnection = context.getConnection = cacheReturnValues(function(canConnect, source, target) {
|
29316 | return self.getConnection(canConnect, source, target);
|
29317 | });
|
29318 | }
|
29319 |
|
29320 | if (canConnect) {
|
29321 | connection = getConnection(canConnect, source, target);
|
29322 | }
|
29323 |
|
29324 | if (!connection) {
|
29325 | !noNoop && this.drawNoopPreview(connectionPreviewGfx, hints);
|
29326 | return;
|
29327 | }
|
29328 |
|
29329 | connection.waypoints = waypoints || [];
|
29330 |
|
29331 |
|
29332 | if (this._layouter && !noLayout) {
|
29333 | connection.waypoints = this._layouter.layoutConnection(connection, {
|
29334 | source: source,
|
29335 | target: target,
|
29336 | connectionStart: connectionStart,
|
29337 | connectionEnd: connectionEnd
|
29338 | });
|
29339 | }
|
29340 |
|
29341 |
|
29342 | if (!connection.waypoints || !connection.waypoints.length) {
|
29343 | connection.waypoints = [
|
29344 | source ? getMid(source) : connectionStart,
|
29345 | target ? getMid(target) : connectionEnd
|
29346 | ];
|
29347 | }
|
29348 |
|
29349 |
|
29350 | if (this._connectionDocking && (source || target) && !noCropping) {
|
29351 | connection.waypoints = this._connectionDocking.getCroppedWaypoints(connection, source, target);
|
29352 | }
|
29353 |
|
29354 | this._graphicsFactory.drawConnection(connectionPreviewGfx, connection);
|
29355 | };
|
29356 |
|
29357 | |
29358 |
|
29359 |
|
29360 |
|
29361 |
|
29362 |
|
29363 |
|
29364 |
|
29365 |
|
29366 |
|
29367 | ConnectionPreview.prototype.drawNoopPreview = function(connectionPreviewGfx, hints) {
|
29368 | var source = hints.source,
|
29369 | target = hints.target,
|
29370 | start = hints.connectionStart || getMid(source),
|
29371 | end = hints.connectionEnd || getMid(target);
|
29372 |
|
29373 | var waypoints = this.cropWaypoints(start, end, source, target);
|
29374 |
|
29375 | var connection = this.createNoopConnection(waypoints[0], waypoints[1]);
|
29376 |
|
29377 | append(connectionPreviewGfx, connection);
|
29378 | };
|
29379 |
|
29380 | |
29381 |
|
29382 |
|
29383 |
|
29384 |
|
29385 |
|
29386 |
|
29387 |
|
29388 |
|
29389 |
|
29390 | ConnectionPreview.prototype.cropWaypoints = function(start, end, source, target) {
|
29391 | var graphicsFactory = this._graphicsFactory,
|
29392 | sourcePath = source && graphicsFactory.getShapePath(source),
|
29393 | targetPath = target && graphicsFactory.getShapePath(target),
|
29394 | connectionPath = graphicsFactory.getConnectionPath({ waypoints: [ start, end ] });
|
29395 |
|
29396 | start = (source && getElementLineIntersection(sourcePath, connectionPath, true)) || start;
|
29397 | end = (target && getElementLineIntersection(targetPath, connectionPath, false)) || end;
|
29398 |
|
29399 | return [ start, end ];
|
29400 | };
|
29401 |
|
29402 | |
29403 |
|
29404 |
|
29405 |
|
29406 |
|
29407 |
|
29408 | ConnectionPreview.prototype.cleanUp = function(context) {
|
29409 | if (context && context.connectionPreviewGfx) {
|
29410 | remove$1(context.connectionPreviewGfx);
|
29411 | }
|
29412 | };
|
29413 |
|
29414 | |
29415 |
|
29416 |
|
29417 |
|
29418 |
|
29419 |
|
29420 |
|
29421 | ConnectionPreview.prototype.getConnection = function(canConnect) {
|
29422 | var attrs = ensureConnectionAttrs(canConnect);
|
29423 |
|
29424 | return this._elementFactory.createConnection(attrs);
|
29425 | };
|
29426 |
|
29427 |
|
29428 | |
29429 |
|
29430 |
|
29431 |
|
29432 |
|
29433 | ConnectionPreview.prototype.createConnectionPreviewGfx = function() {
|
29434 | var gfx = create('g');
|
29435 |
|
29436 | attr$1(gfx, {
|
29437 | pointerEvents: 'none'
|
29438 | });
|
29439 |
|
29440 | classes$1(gfx).add(MARKER_CONNECTION_PREVIEW);
|
29441 |
|
29442 | append(this._canvas.getDefaultLayer(), gfx);
|
29443 |
|
29444 | return gfx;
|
29445 | };
|
29446 |
|
29447 | |
29448 |
|
29449 |
|
29450 |
|
29451 |
|
29452 |
|
29453 |
|
29454 |
|
29455 | ConnectionPreview.prototype.createNoopConnection = function(start, end) {
|
29456 | var connection = create('polyline');
|
29457 |
|
29458 | attr$1(connection, {
|
29459 | 'stroke': '#333',
|
29460 | 'strokeDasharray': [ 1 ],
|
29461 | 'strokeWidth': 2,
|
29462 | 'pointer-events': 'none'
|
29463 | });
|
29464 |
|
29465 | attr$1(connection, { 'points': [ start.x, start.y, end.x, end.y ] });
|
29466 |
|
29467 | return connection;
|
29468 | };
|
29469 |
|
29470 |
|
29471 |
|
29472 | |
29473 |
|
29474 |
|
29475 |
|
29476 |
|
29477 |
|
29478 |
|
29479 | function cacheReturnValues(fn) {
|
29480 | var returnValues = {};
|
29481 |
|
29482 | |
29483 |
|
29484 |
|
29485 |
|
29486 |
|
29487 | return function(firstArgument) {
|
29488 | var key = JSON.stringify(firstArgument);
|
29489 |
|
29490 | var returnValue = returnValues[key];
|
29491 |
|
29492 | if (!returnValue) {
|
29493 | returnValue = returnValues[key] = fn.apply(null, arguments);
|
29494 | }
|
29495 |
|
29496 | return returnValue;
|
29497 | };
|
29498 | }
|
29499 |
|
29500 | |
29501 |
|
29502 |
|
29503 |
|
29504 |
|
29505 |
|
29506 |
|
29507 | function ensureConnectionAttrs(canConnect) {
|
29508 | if (isObject(canConnect)) {
|
29509 | return canConnect;
|
29510 | } else {
|
29511 | return {};
|
29512 | }
|
29513 | }
|
29514 |
|
29515 | var ConnectionPreviewModule = {
|
29516 | __init__: [ 'connectionPreview' ],
|
29517 | connectionPreview: [ 'type', ConnectionPreview ]
|
29518 | };
|
29519 |
|
29520 | var min = Math.min,
|
29521 | max$1 = Math.max;
|
29522 |
|
29523 | function preventDefault$1(e) {
|
29524 | e.preventDefault();
|
29525 | }
|
29526 |
|
29527 | function stopPropagation$1(e) {
|
29528 | e.stopPropagation();
|
29529 | }
|
29530 |
|
29531 | function isTextNode(node) {
|
29532 | return node.nodeType === Node.TEXT_NODE;
|
29533 | }
|
29534 |
|
29535 | function toArray(nodeList) {
|
29536 | return [].slice.call(nodeList);
|
29537 | }
|
29538 |
|
29539 | |
29540 |
|
29541 |
|
29542 |
|
29543 |
|
29544 |
|
29545 |
|
29546 |
|
29547 |
|
29548 |
|
29549 |
|
29550 |
|
29551 |
|
29552 |
|
29553 |
|
29554 | function TextBox(options) {
|
29555 | this.container = options.container;
|
29556 |
|
29557 | this.parent = domify(
|
29558 | '<div class="djs-direct-editing-parent">' +
|
29559 | '<div class="djs-direct-editing-content" contenteditable="true"></div>' +
|
29560 | '</div>'
|
29561 | );
|
29562 |
|
29563 | this.content = query('[contenteditable]', this.parent);
|
29564 |
|
29565 | this.keyHandler = options.keyHandler || function() {};
|
29566 | this.resizeHandler = options.resizeHandler || function() {};
|
29567 |
|
29568 | this.autoResize = bind(this.autoResize, this);
|
29569 | this.handlePaste = bind(this.handlePaste, this);
|
29570 | }
|
29571 |
|
29572 |
|
29573 | |
29574 |
|
29575 |
|
29576 |
|
29577 |
|
29578 |
|
29579 |
|
29580 |
|
29581 |
|
29582 |
|
29583 |
|
29584 |
|
29585 |
|
29586 |
|
29587 |
|
29588 |
|
29589 |
|
29590 | TextBox.prototype.create = function(bounds, style, value, options) {
|
29591 | var self = this;
|
29592 |
|
29593 | var parent = this.parent,
|
29594 | content = this.content,
|
29595 | container = this.container;
|
29596 |
|
29597 | options = this.options = options || {};
|
29598 |
|
29599 | style = this.style = style || {};
|
29600 |
|
29601 | var parentStyle = pick(style, [
|
29602 | 'width',
|
29603 | 'height',
|
29604 | 'maxWidth',
|
29605 | 'maxHeight',
|
29606 | 'minWidth',
|
29607 | 'minHeight',
|
29608 | 'left',
|
29609 | 'top',
|
29610 | 'backgroundColor',
|
29611 | 'position',
|
29612 | 'overflow',
|
29613 | 'border',
|
29614 | 'wordWrap',
|
29615 | 'textAlign',
|
29616 | 'outline',
|
29617 | 'transform'
|
29618 | ]);
|
29619 |
|
29620 | assign(parent.style, {
|
29621 | width: bounds.width + 'px',
|
29622 | height: bounds.height + 'px',
|
29623 | maxWidth: bounds.maxWidth + 'px',
|
29624 | maxHeight: bounds.maxHeight + 'px',
|
29625 | minWidth: bounds.minWidth + 'px',
|
29626 | minHeight: bounds.minHeight + 'px',
|
29627 | left: bounds.x + 'px',
|
29628 | top: bounds.y + 'px',
|
29629 | backgroundColor: '#ffffff',
|
29630 | position: 'absolute',
|
29631 | overflow: 'visible',
|
29632 | border: '1px solid #ccc',
|
29633 | boxSizing: 'border-box',
|
29634 | wordWrap: 'normal',
|
29635 | textAlign: 'center',
|
29636 | outline: 'none'
|
29637 | }, parentStyle);
|
29638 |
|
29639 | var contentStyle = pick(style, [
|
29640 | 'fontFamily',
|
29641 | 'fontSize',
|
29642 | 'fontWeight',
|
29643 | 'lineHeight',
|
29644 | 'padding',
|
29645 | 'paddingTop',
|
29646 | 'paddingRight',
|
29647 | 'paddingBottom',
|
29648 | 'paddingLeft'
|
29649 | ]);
|
29650 |
|
29651 | assign(content.style, {
|
29652 | boxSizing: 'border-box',
|
29653 | width: '100%',
|
29654 | outline: 'none',
|
29655 | wordWrap: 'break-word'
|
29656 | }, contentStyle);
|
29657 |
|
29658 | if (options.centerVertically) {
|
29659 | assign(content.style, {
|
29660 | position: 'absolute',
|
29661 | top: '50%',
|
29662 | transform: 'translate(0, -50%)'
|
29663 | }, contentStyle);
|
29664 | }
|
29665 |
|
29666 | content.innerText = value;
|
29667 |
|
29668 | componentEvent.bind(content, 'keydown', this.keyHandler);
|
29669 | componentEvent.bind(content, 'mousedown', stopPropagation$1);
|
29670 | componentEvent.bind(content, 'paste', self.handlePaste);
|
29671 |
|
29672 | if (options.autoResize) {
|
29673 | componentEvent.bind(content, 'input', this.autoResize);
|
29674 | }
|
29675 |
|
29676 | if (options.resizable) {
|
29677 | this.resizable(style);
|
29678 | }
|
29679 |
|
29680 | container.appendChild(parent);
|
29681 |
|
29682 |
|
29683 | this.setSelection(content.lastChild, content.lastChild && content.lastChild.length);
|
29684 |
|
29685 | return parent;
|
29686 | };
|
29687 |
|
29688 | |
29689 |
|
29690 |
|
29691 | TextBox.prototype.handlePaste = function(e) {
|
29692 | var options = this.options,
|
29693 | style = this.style;
|
29694 |
|
29695 | e.preventDefault();
|
29696 |
|
29697 | var text;
|
29698 |
|
29699 | if (e.clipboardData) {
|
29700 |
|
29701 |
|
29702 | text = e.clipboardData.getData('text/plain');
|
29703 | } else {
|
29704 |
|
29705 |
|
29706 | text = window.clipboardData.getData('Text');
|
29707 | }
|
29708 |
|
29709 | this.insertText(text);
|
29710 |
|
29711 | if (options.autoResize) {
|
29712 | var hasResized = this.autoResize(style);
|
29713 |
|
29714 | if (hasResized) {
|
29715 | this.resizeHandler(hasResized);
|
29716 | }
|
29717 | }
|
29718 | };
|
29719 |
|
29720 | TextBox.prototype.insertText = function(text) {
|
29721 |
|
29722 |
|
29723 | var success = document.execCommand('insertText', false, text);
|
29724 |
|
29725 | if (success) {
|
29726 | return;
|
29727 | }
|
29728 |
|
29729 | this._insertTextIE(text);
|
29730 | };
|
29731 |
|
29732 | TextBox.prototype._insertTextIE = function(text) {
|
29733 |
|
29734 |
|
29735 | var range = this.getSelection(),
|
29736 | startContainer = range.startContainer,
|
29737 | endContainer = range.endContainer,
|
29738 | startOffset = range.startOffset,
|
29739 | endOffset = range.endOffset,
|
29740 | commonAncestorContainer = range.commonAncestorContainer;
|
29741 |
|
29742 | var childNodesArray = toArray(commonAncestorContainer.childNodes);
|
29743 |
|
29744 | var container,
|
29745 | offset;
|
29746 |
|
29747 | if (isTextNode(commonAncestorContainer)) {
|
29748 | var containerTextContent = startContainer.textContent;
|
29749 |
|
29750 | startContainer.textContent =
|
29751 | containerTextContent.substring(0, startOffset)
|
29752 | + text
|
29753 | + containerTextContent.substring(endOffset);
|
29754 |
|
29755 | container = startContainer;
|
29756 | offset = startOffset + text.length;
|
29757 |
|
29758 | } else if (startContainer === this.content && endContainer === this.content) {
|
29759 | var textNode = document.createTextNode(text);
|
29760 |
|
29761 | this.content.insertBefore(textNode, childNodesArray[startOffset]);
|
29762 |
|
29763 | container = textNode;
|
29764 | offset = textNode.textContent.length;
|
29765 | } else {
|
29766 | var startContainerChildIndex = childNodesArray.indexOf(startContainer),
|
29767 | endContainerChildIndex = childNodesArray.indexOf(endContainer);
|
29768 |
|
29769 | childNodesArray.forEach(function(childNode, index) {
|
29770 |
|
29771 | if (index === startContainerChildIndex) {
|
29772 | childNode.textContent =
|
29773 | startContainer.textContent.substring(0, startOffset) +
|
29774 | text +
|
29775 | endContainer.textContent.substring(endOffset);
|
29776 | } else if (index > startContainerChildIndex && index <= endContainerChildIndex) {
|
29777 | remove(childNode);
|
29778 | }
|
29779 | });
|
29780 |
|
29781 | container = startContainer;
|
29782 | offset = startOffset + text.length;
|
29783 | }
|
29784 |
|
29785 | if (container && offset !== undefined) {
|
29786 |
|
29787 |
|
29788 | setTimeout(function() {
|
29789 | self.setSelection(container, offset);
|
29790 | });
|
29791 | }
|
29792 | };
|
29793 |
|
29794 | |
29795 |
|
29796 |
|
29797 | TextBox.prototype.autoResize = function() {
|
29798 | var parent = this.parent,
|
29799 | content = this.content;
|
29800 |
|
29801 | var fontSize = parseInt(this.style.fontSize) || 12;
|
29802 |
|
29803 | if (content.scrollHeight > parent.offsetHeight ||
|
29804 | content.scrollHeight < parent.offsetHeight - fontSize) {
|
29805 | var bounds = parent.getBoundingClientRect();
|
29806 |
|
29807 | var height = content.scrollHeight;
|
29808 | parent.style.height = height + 'px';
|
29809 |
|
29810 | this.resizeHandler({
|
29811 | width: bounds.width,
|
29812 | height: bounds.height,
|
29813 | dx: 0,
|
29814 | dy: height - bounds.height
|
29815 | });
|
29816 | }
|
29817 | };
|
29818 |
|
29819 | |
29820 |
|
29821 |
|
29822 | TextBox.prototype.resizable = function() {
|
29823 | var self = this;
|
29824 |
|
29825 | var parent = this.parent,
|
29826 | resizeHandle = this.resizeHandle;
|
29827 |
|
29828 | var minWidth = parseInt(this.style.minWidth) || 0,
|
29829 | minHeight = parseInt(this.style.minHeight) || 0,
|
29830 | maxWidth = parseInt(this.style.maxWidth) || Infinity,
|
29831 | maxHeight = parseInt(this.style.maxHeight) || Infinity;
|
29832 |
|
29833 | if (!resizeHandle) {
|
29834 | resizeHandle = this.resizeHandle = domify(
|
29835 | '<div class="djs-direct-editing-resize-handle"></div>'
|
29836 | );
|
29837 |
|
29838 | var startX, startY, startWidth, startHeight;
|
29839 |
|
29840 | var onMouseDown = function(e) {
|
29841 | preventDefault$1(e);
|
29842 | stopPropagation$1(e);
|
29843 |
|
29844 | startX = e.clientX;
|
29845 | startY = e.clientY;
|
29846 |
|
29847 | var bounds = parent.getBoundingClientRect();
|
29848 |
|
29849 | startWidth = bounds.width;
|
29850 | startHeight = bounds.height;
|
29851 |
|
29852 | componentEvent.bind(document, 'mousemove', onMouseMove);
|
29853 | componentEvent.bind(document, 'mouseup', onMouseUp);
|
29854 | };
|
29855 |
|
29856 | var onMouseMove = function(e) {
|
29857 | preventDefault$1(e);
|
29858 | stopPropagation$1(e);
|
29859 |
|
29860 | var newWidth = min(max$1(startWidth + e.clientX - startX, minWidth), maxWidth);
|
29861 | var newHeight = min(max$1(startHeight + e.clientY - startY, minHeight), maxHeight);
|
29862 |
|
29863 | parent.style.width = newWidth + 'px';
|
29864 | parent.style.height = newHeight + 'px';
|
29865 |
|
29866 | self.resizeHandler({
|
29867 | width: startWidth,
|
29868 | height: startHeight,
|
29869 | dx: e.clientX - startX,
|
29870 | dy: e.clientY - startY
|
29871 | });
|
29872 | };
|
29873 |
|
29874 | var onMouseUp = function(e) {
|
29875 | preventDefault$1(e);
|
29876 | stopPropagation$1(e);
|
29877 |
|
29878 | componentEvent.unbind(document,'mousemove', onMouseMove, false);
|
29879 | componentEvent.unbind(document, 'mouseup', onMouseUp, false);
|
29880 | };
|
29881 |
|
29882 | componentEvent.bind(resizeHandle, 'mousedown', onMouseDown);
|
29883 | }
|
29884 |
|
29885 | assign(resizeHandle.style, {
|
29886 | position: 'absolute',
|
29887 | bottom: '0px',
|
29888 | right: '0px',
|
29889 | cursor: 'nwse-resize',
|
29890 | width: '0',
|
29891 | height: '0',
|
29892 | borderTop: (parseInt(this.style.fontSize) / 4 || 3) + 'px solid transparent',
|
29893 | borderRight: (parseInt(this.style.fontSize) / 4 || 3) + 'px solid #ccc',
|
29894 | borderBottom: (parseInt(this.style.fontSize) / 4 || 3) + 'px solid #ccc',
|
29895 | borderLeft: (parseInt(this.style.fontSize) / 4 || 3) + 'px solid transparent'
|
29896 | });
|
29897 |
|
29898 | parent.appendChild(resizeHandle);
|
29899 | };
|
29900 |
|
29901 |
|
29902 | |
29903 |
|
29904 |
|
29905 |
|
29906 | TextBox.prototype.destroy = function() {
|
29907 | var parent = this.parent,
|
29908 | content = this.content,
|
29909 | resizeHandle = this.resizeHandle;
|
29910 |
|
29911 |
|
29912 | content.innerText = '';
|
29913 |
|
29914 |
|
29915 | parent.removeAttribute('style');
|
29916 | content.removeAttribute('style');
|
29917 |
|
29918 | componentEvent.unbind(content, 'keydown', this.keyHandler);
|
29919 | componentEvent.unbind(content, 'mousedown', stopPropagation$1);
|
29920 | componentEvent.unbind(content, 'input', this.autoResize);
|
29921 | componentEvent.unbind(content, 'paste', this.handlePaste);
|
29922 |
|
29923 | if (resizeHandle) {
|
29924 | resizeHandle.removeAttribute('style');
|
29925 |
|
29926 | remove(resizeHandle);
|
29927 | }
|
29928 |
|
29929 | remove(parent);
|
29930 | };
|
29931 |
|
29932 |
|
29933 | TextBox.prototype.getValue = function() {
|
29934 | return this.content.innerText.trim();
|
29935 | };
|
29936 |
|
29937 |
|
29938 | TextBox.prototype.getSelection = function() {
|
29939 | var selection = window.getSelection(),
|
29940 | range = selection.getRangeAt(0);
|
29941 |
|
29942 | return range;
|
29943 | };
|
29944 |
|
29945 |
|
29946 | TextBox.prototype.setSelection = function(container, offset) {
|
29947 | var range = document.createRange();
|
29948 |
|
29949 | if (container === null) {
|
29950 | range.selectNodeContents(this.content);
|
29951 | } else {
|
29952 | range.setStart(container, offset);
|
29953 | range.setEnd(container, offset);
|
29954 | }
|
29955 |
|
29956 | var selection = window.getSelection();
|
29957 |
|
29958 | selection.removeAllRanges();
|
29959 | selection.addRange(range);
|
29960 | };
|
29961 |
|
29962 | |
29963 |
|
29964 |
|
29965 |
|
29966 |
|
29967 |
|
29968 | function DirectEditing(eventBus, canvas) {
|
29969 |
|
29970 | this._eventBus = eventBus;
|
29971 |
|
29972 | this._providers = [];
|
29973 | this._textbox = new TextBox({
|
29974 | container: canvas.getContainer(),
|
29975 | keyHandler: bind(this._handleKey, this),
|
29976 | resizeHandler: bind(this._handleResize, this)
|
29977 | });
|
29978 | }
|
29979 |
|
29980 | DirectEditing.$inject = [ 'eventBus', 'canvas' ];
|
29981 |
|
29982 |
|
29983 | |
29984 |
|
29985 |
|
29986 |
|
29987 |
|
29988 |
|
29989 |
|
29990 |
|
29991 |
|
29992 | DirectEditing.prototype.registerProvider = function(provider) {
|
29993 | this._providers.push(provider);
|
29994 | };
|
29995 |
|
29996 |
|
29997 | |
29998 |
|
29999 |
|
30000 |
|
30001 |
|
30002 | DirectEditing.prototype.isActive = function() {
|
30003 | return !!this._active;
|
30004 | };
|
30005 |
|
30006 |
|
30007 | |
30008 |
|
30009 |
|
30010 | DirectEditing.prototype.cancel = function() {
|
30011 | if (!this._active) {
|
30012 | return;
|
30013 | }
|
30014 |
|
30015 | this._fire('cancel');
|
30016 | this.close();
|
30017 | };
|
30018 |
|
30019 |
|
30020 | DirectEditing.prototype._fire = function(event, context) {
|
30021 | this._eventBus.fire('directEditing.' + event, context || { active: this._active });
|
30022 | };
|
30023 |
|
30024 | DirectEditing.prototype.close = function() {
|
30025 | this._textbox.destroy();
|
30026 |
|
30027 | this._fire('deactivate');
|
30028 |
|
30029 | this._active = null;
|
30030 |
|
30031 | this.resizable = undefined;
|
30032 | };
|
30033 |
|
30034 |
|
30035 | DirectEditing.prototype.complete = function() {
|
30036 |
|
30037 | var active = this._active;
|
30038 |
|
30039 | if (!active) {
|
30040 | return;
|
30041 | }
|
30042 |
|
30043 | var containerBounds,
|
30044 | previousBounds = active.context.bounds,
|
30045 | newBounds = this.$textbox.getBoundingClientRect(),
|
30046 | newText = this.getValue(),
|
30047 | previousText = active.context.text;
|
30048 |
|
30049 | if (
|
30050 | newText !== previousText ||
|
30051 | newBounds.height !== previousBounds.height ||
|
30052 | newBounds.width !== previousBounds.width
|
30053 | ) {
|
30054 | containerBounds = this._textbox.container.getBoundingClientRect();
|
30055 |
|
30056 | active.provider.update(active.element, newText, active.context.text, {
|
30057 | x: newBounds.left - containerBounds.left,
|
30058 | y: newBounds.top - containerBounds.top,
|
30059 | width: newBounds.width,
|
30060 | height: newBounds.height
|
30061 | });
|
30062 | }
|
30063 |
|
30064 | this._fire('complete');
|
30065 |
|
30066 | this.close();
|
30067 | };
|
30068 |
|
30069 |
|
30070 | DirectEditing.prototype.getValue = function() {
|
30071 | return this._textbox.getValue();
|
30072 | };
|
30073 |
|
30074 |
|
30075 | DirectEditing.prototype._handleKey = function(e) {
|
30076 |
|
30077 |
|
30078 | e.stopPropagation();
|
30079 |
|
30080 | var key = e.keyCode || e.charCode;
|
30081 |
|
30082 |
|
30083 | if (key === 27) {
|
30084 | e.preventDefault();
|
30085 | return this.cancel();
|
30086 | }
|
30087 |
|
30088 |
|
30089 | if (key === 13 && !e.shiftKey) {
|
30090 | e.preventDefault();
|
30091 | return this.complete();
|
30092 | }
|
30093 | };
|
30094 |
|
30095 |
|
30096 | DirectEditing.prototype._handleResize = function(event) {
|
30097 | this._fire('resize', event);
|
30098 | };
|
30099 |
|
30100 |
|
30101 | |
30102 |
|
30103 |
|
30104 |
|
30105 |
|
30106 |
|
30107 | DirectEditing.prototype.activate = function(element) {
|
30108 | if (this.isActive()) {
|
30109 | this.cancel();
|
30110 | }
|
30111 |
|
30112 |
|
30113 | var context;
|
30114 |
|
30115 | var provider = find(this._providers, function(p) {
|
30116 | return (context = p.activate(element)) ? p : null;
|
30117 | });
|
30118 |
|
30119 |
|
30120 | if (context) {
|
30121 | this.$textbox = this._textbox.create(
|
30122 | context.bounds,
|
30123 | context.style,
|
30124 | context.text,
|
30125 | context.options
|
30126 | );
|
30127 |
|
30128 | this._active = {
|
30129 | element: element,
|
30130 | context: context,
|
30131 | provider: provider
|
30132 | };
|
30133 |
|
30134 | if (context.options && context.options.resizable) {
|
30135 | this.resizable = true;
|
30136 | }
|
30137 |
|
30138 | this._fire('activate');
|
30139 | }
|
30140 |
|
30141 | return !!context;
|
30142 | };
|
30143 |
|
30144 | var DirectEditingModule = {
|
30145 | __depends__: [
|
30146 | InteractionEventsModule
|
30147 | ],
|
30148 | __init__: [ 'directEditing' ],
|
30149 | directEditing: [ 'type', DirectEditing ]
|
30150 | };
|
30151 |
|
30152 | var entrySelector = '.entry';
|
30153 |
|
30154 |
|
30155 | |
30156 |
|
30157 |
|
30158 |
|
30159 |
|
30160 |
|
30161 |
|
30162 |
|
30163 |
|
30164 |
|
30165 |
|
30166 | function ContextPad(config, eventBus, overlays) {
|
30167 |
|
30168 | this._providers = [];
|
30169 |
|
30170 | this._eventBus = eventBus;
|
30171 | this._overlays = overlays;
|
30172 |
|
30173 | var scale = isDefined(config && config.scale) ? config.scale : {
|
30174 | min: 1,
|
30175 | max: 1.5
|
30176 | };
|
30177 |
|
30178 | this._overlaysConfig = {
|
30179 | position: {
|
30180 | right: -9,
|
30181 | top: -6
|
30182 | },
|
30183 | scale: scale
|
30184 | };
|
30185 |
|
30186 | this._current = null;
|
30187 |
|
30188 | this._init();
|
30189 | }
|
30190 |
|
30191 | ContextPad.$inject = [
|
30192 | 'config.contextPad',
|
30193 | 'eventBus',
|
30194 | 'overlays'
|
30195 | ];
|
30196 |
|
30197 |
|
30198 | |
30199 |
|
30200 |
|
30201 | ContextPad.prototype._init = function() {
|
30202 |
|
30203 | var eventBus = this._eventBus;
|
30204 |
|
30205 | var self = this;
|
30206 |
|
30207 | eventBus.on('selection.changed', function(e) {
|
30208 |
|
30209 | var selection = e.newSelection;
|
30210 |
|
30211 | if (selection.length === 1) {
|
30212 | self.open(selection[0]);
|
30213 | } else {
|
30214 | self.close();
|
30215 | }
|
30216 | });
|
30217 |
|
30218 | eventBus.on('elements.delete', function(event) {
|
30219 | var elements = event.elements;
|
30220 |
|
30221 | forEach(elements, function(e) {
|
30222 | if (self.isOpen(e)) {
|
30223 | self.close();
|
30224 | }
|
30225 | });
|
30226 | });
|
30227 |
|
30228 | eventBus.on('element.changed', function(event) {
|
30229 | var element = event.element,
|
30230 | current = self._current;
|
30231 |
|
30232 |
|
30233 | if (current && current.element === element) {
|
30234 | self.open(element, true);
|
30235 | }
|
30236 | });
|
30237 | };
|
30238 |
|
30239 |
|
30240 | |
30241 |
|
30242 |
|
30243 |
|
30244 |
|
30245 | ContextPad.prototype.registerProvider = function(provider) {
|
30246 | this._providers.push(provider);
|
30247 | };
|
30248 |
|
30249 |
|
30250 | |
30251 |
|
30252 |
|
30253 |
|
30254 |
|
30255 |
|
30256 |
|
30257 | ContextPad.prototype.getEntries = function(element) {
|
30258 | var entries = {};
|
30259 |
|
30260 |
|
30261 |
|
30262 | forEach(this._providers, function(provider) {
|
30263 | var e = provider.getContextPadEntries(element);
|
30264 |
|
30265 | forEach(e, function(entry, id) {
|
30266 | entries[id] = entry;
|
30267 | });
|
30268 | });
|
30269 |
|
30270 | return entries;
|
30271 | };
|
30272 |
|
30273 |
|
30274 | |
30275 |
|
30276 |
|
30277 |
|
30278 |
|
30279 |
|
30280 |
|
30281 | ContextPad.prototype.trigger = function(action, event, autoActivate) {
|
30282 |
|
30283 | var element = this._current.element,
|
30284 | entries = this._current.entries,
|
30285 | entry,
|
30286 | handler,
|
30287 | originalEvent,
|
30288 | button = event.delegateTarget || event.target;
|
30289 |
|
30290 | if (!button) {
|
30291 | return event.preventDefault();
|
30292 | }
|
30293 |
|
30294 | entry = entries[attr(button, 'data-action')];
|
30295 | handler = entry.action;
|
30296 |
|
30297 | originalEvent = event.originalEvent || event;
|
30298 |
|
30299 |
|
30300 | if (isFunction(handler)) {
|
30301 | if (action === 'click') {
|
30302 | return handler(originalEvent, element, autoActivate);
|
30303 | }
|
30304 | } else {
|
30305 | if (handler[action]) {
|
30306 | return handler[action](originalEvent, element, autoActivate);
|
30307 | }
|
30308 | }
|
30309 |
|
30310 |
|
30311 | event.preventDefault();
|
30312 | };
|
30313 |
|
30314 |
|
30315 | |
30316 |
|
30317 |
|
30318 |
|
30319 |
|
30320 |
|
30321 | ContextPad.prototype.open = function(element, force) {
|
30322 | if (!force && this.isOpen(element)) {
|
30323 | return;
|
30324 | }
|
30325 |
|
30326 | this.close();
|
30327 | this._updateAndOpen(element);
|
30328 | };
|
30329 |
|
30330 |
|
30331 | ContextPad.prototype._updateAndOpen = function(element) {
|
30332 |
|
30333 | var entries = this.getEntries(element),
|
30334 | pad = this.getPad(element),
|
30335 | html = pad.html;
|
30336 |
|
30337 | forEach(entries, function(entry, id) {
|
30338 | var grouping = entry.group || 'default',
|
30339 | control = domify(entry.html || '<div class="entry" draggable="true"></div>'),
|
30340 | container;
|
30341 |
|
30342 | attr(control, 'data-action', id);
|
30343 |
|
30344 | container = query('[data-group=' + grouping + ']', html);
|
30345 | if (!container) {
|
30346 | container = domify('<div class="group" data-group="' + grouping + '"></div>');
|
30347 | html.appendChild(container);
|
30348 | }
|
30349 |
|
30350 | container.appendChild(control);
|
30351 |
|
30352 | if (entry.className) {
|
30353 | addClasses(control, entry.className);
|
30354 | }
|
30355 |
|
30356 | if (entry.title) {
|
30357 | attr(control, 'title', entry.title);
|
30358 | }
|
30359 |
|
30360 | if (entry.imageUrl) {
|
30361 | control.appendChild(domify('<img src="' + entry.imageUrl + '">'));
|
30362 | }
|
30363 | });
|
30364 |
|
30365 | classes(html).add('open');
|
30366 |
|
30367 | this._current = {
|
30368 | element: element,
|
30369 | pad: pad,
|
30370 | entries: entries
|
30371 | };
|
30372 |
|
30373 | this._eventBus.fire('contextPad.open', { current: this._current });
|
30374 | };
|
30375 |
|
30376 |
|
30377 | ContextPad.prototype.getPad = function(element) {
|
30378 | if (this.isOpen()) {
|
30379 | return this._current.pad;
|
30380 | }
|
30381 |
|
30382 | var self = this;
|
30383 |
|
30384 | var overlays = this._overlays;
|
30385 |
|
30386 | var html = domify('<div class="djs-context-pad"></div>');
|
30387 |
|
30388 | var overlaysConfig = assign({
|
30389 | html: html
|
30390 | }, this._overlaysConfig);
|
30391 |
|
30392 | delegateEvents.bind(html, entrySelector, 'click', function(event) {
|
30393 | self.trigger('click', event);
|
30394 | });
|
30395 |
|
30396 | delegateEvents.bind(html, entrySelector, 'dragstart', function(event) {
|
30397 | self.trigger('dragstart', event);
|
30398 | });
|
30399 |
|
30400 |
|
30401 | componentEvent.bind(html, 'mousedown', function(event) {
|
30402 | event.stopPropagation();
|
30403 | });
|
30404 |
|
30405 | this._overlayId = overlays.add(element, 'context-pad', overlaysConfig);
|
30406 |
|
30407 | var pad = overlays.get(this._overlayId);
|
30408 |
|
30409 | this._eventBus.fire('contextPad.create', { element: element, pad: pad });
|
30410 |
|
30411 | return pad;
|
30412 | };
|
30413 |
|
30414 |
|
30415 | |
30416 |
|
30417 |
|
30418 | ContextPad.prototype.close = function() {
|
30419 | if (!this.isOpen()) {
|
30420 | return;
|
30421 | }
|
30422 |
|
30423 | this._overlays.remove(this._overlayId);
|
30424 |
|
30425 | this._overlayId = null;
|
30426 |
|
30427 | this._eventBus.fire('contextPad.close', { current: this._current });
|
30428 |
|
30429 | this._current = null;
|
30430 | };
|
30431 |
|
30432 | |
30433 |
|
30434 |
|
30435 |
|
30436 |
|
30437 |
|
30438 |
|
30439 | ContextPad.prototype.isOpen = function(element) {
|
30440 | return !!this._current && (!element ? true : this._current.element === element);
|
30441 | };
|
30442 |
|
30443 |
|
30444 |
|
30445 |
|
30446 |
|
30447 |
|
30448 | function addClasses(element, classNames) {
|
30449 |
|
30450 | var classes$1 = classes(element);
|
30451 |
|
30452 | var actualClassNames = isArray(classNames) ? classNames : classNames.split(/\s+/g);
|
30453 | actualClassNames.forEach(function(cls) {
|
30454 | classes$1.add(cls);
|
30455 | });
|
30456 | }
|
30457 |
|
30458 | var ContextPadModule = {
|
30459 | __depends__: [
|
30460 | InteractionEventsModule,
|
30461 | OverlaysModule
|
30462 | ],
|
30463 | contextPad: [ 'type', ContextPad ]
|
30464 | };
|
30465 |
|
30466 | var MARKER_TYPES = [
|
30467 | 'marker-start',
|
30468 | 'marker-mid',
|
30469 | 'marker-end'
|
30470 | ];
|
30471 |
|
30472 | var NODES_CAN_HAVE_MARKER = [
|
30473 | 'circle',
|
30474 | 'ellipse',
|
30475 | 'line',
|
30476 | 'path',
|
30477 | 'polygon',
|
30478 | 'polyline',
|
30479 | 'rect'
|
30480 | ];
|
30481 |
|
30482 |
|
30483 | |
30484 |
|
30485 |
|
30486 | function PreviewSupport(elementRegistry, eventBus, canvas, styles) {
|
30487 | this._elementRegistry = elementRegistry;
|
30488 | this._canvas = canvas;
|
30489 | this._styles = styles;
|
30490 |
|
30491 | this._clonedMarkers = {};
|
30492 |
|
30493 | var self = this;
|
30494 |
|
30495 | eventBus.on('drag.cleanup', function() {
|
30496 | forEach(self._clonedMarkers, function(clonedMarker) {
|
30497 | remove$1(clonedMarker);
|
30498 | });
|
30499 |
|
30500 | self._clonedMarkers = {};
|
30501 | });
|
30502 | }
|
30503 |
|
30504 | PreviewSupport.$inject = [
|
30505 | 'elementRegistry',
|
30506 | 'eventBus',
|
30507 | 'canvas',
|
30508 | 'styles'
|
30509 | ];
|
30510 |
|
30511 |
|
30512 | |
30513 |
|
30514 |
|
30515 |
|
30516 |
|
30517 |
|
30518 |
|
30519 | PreviewSupport.prototype.getGfx = function(element) {
|
30520 | return this._elementRegistry.getGraphics(element);
|
30521 | };
|
30522 |
|
30523 | |
30524 |
|
30525 |
|
30526 |
|
30527 |
|
30528 |
|
30529 |
|
30530 |
|
30531 |
|
30532 | PreviewSupport.prototype.addDragger = function(element, group, gfx) {
|
30533 | gfx = gfx || this.getGfx(element);
|
30534 |
|
30535 | var dragger = clone(gfx);
|
30536 | var bbox = gfx.getBoundingClientRect();
|
30537 |
|
30538 | this._cloneMarkers(getVisual(dragger));
|
30539 |
|
30540 | attr$1(dragger, this._styles.cls('djs-dragger', [], {
|
30541 | x: bbox.top,
|
30542 | y: bbox.left
|
30543 | }));
|
30544 |
|
30545 | append(group, dragger);
|
30546 |
|
30547 | return dragger;
|
30548 | };
|
30549 |
|
30550 | |
30551 |
|
30552 |
|
30553 |
|
30554 |
|
30555 |
|
30556 |
|
30557 |
|
30558 | PreviewSupport.prototype.addFrame = function(shape, group) {
|
30559 |
|
30560 | var frame = create('rect', {
|
30561 | class: 'djs-resize-overlay',
|
30562 | width: shape.width,
|
30563 | height: shape.height,
|
30564 | x: shape.x,
|
30565 | y: shape.y
|
30566 | });
|
30567 |
|
30568 | append(group, frame);
|
30569 |
|
30570 | return frame;
|
30571 | };
|
30572 |
|
30573 | |
30574 |
|
30575 |
|
30576 |
|
30577 |
|
30578 | PreviewSupport.prototype._cloneMarkers = function(gfx) {
|
30579 | var self = this;
|
30580 |
|
30581 | if (gfx.childNodes) {
|
30582 |
|
30583 |
|
30584 | for (var i = 0; i < gfx.childNodes.length; i++) {
|
30585 |
|
30586 |
|
30587 | self._cloneMarkers(gfx.childNodes[ i ]);
|
30588 | }
|
30589 | }
|
30590 |
|
30591 | if (!canHaveMarker(gfx)) {
|
30592 | return;
|
30593 | }
|
30594 |
|
30595 | MARKER_TYPES.forEach(function(markerType) {
|
30596 | if (attr$1(gfx, markerType)) {
|
30597 | var marker = getMarker(gfx, markerType, self._canvas.getContainer());
|
30598 |
|
30599 | self._cloneMarker(gfx, marker, markerType);
|
30600 | }
|
30601 | });
|
30602 | };
|
30603 |
|
30604 | |
30605 |
|
30606 |
|
30607 |
|
30608 |
|
30609 |
|
30610 |
|
30611 | PreviewSupport.prototype._cloneMarker = function(gfx, marker, markerType) {
|
30612 | var markerId = marker.id;
|
30613 |
|
30614 | var clonedMarker = this._clonedMarkers[ markerId ];
|
30615 |
|
30616 | if (!clonedMarker) {
|
30617 | clonedMarker = clone(marker);
|
30618 |
|
30619 | var clonedMarkerId = markerId + '-clone';
|
30620 |
|
30621 | clonedMarker.id = clonedMarkerId;
|
30622 |
|
30623 | classes$1(clonedMarker)
|
30624 | .add('djs-dragger')
|
30625 | .add('djs-dragger-marker');
|
30626 |
|
30627 | this._clonedMarkers[ markerId ] = clonedMarker;
|
30628 |
|
30629 | var defs = query('defs', this._canvas._svg);
|
30630 |
|
30631 | if (!defs) {
|
30632 | defs = create('defs');
|
30633 |
|
30634 | append(this._canvas._svg, defs);
|
30635 | }
|
30636 |
|
30637 | append(defs, clonedMarker);
|
30638 | }
|
30639 |
|
30640 | var reference = idToReference(this._clonedMarkers[ markerId ].id);
|
30641 |
|
30642 | attr$1(gfx, markerType, reference);
|
30643 | };
|
30644 |
|
30645 |
|
30646 |
|
30647 | |
30648 |
|
30649 |
|
30650 |
|
30651 |
|
30652 |
|
30653 |
|
30654 |
|
30655 |
|
30656 | function getMarker(node, markerType, parentNode) {
|
30657 | var id = referenceToId(attr$1(node, markerType));
|
30658 |
|
30659 | return query('marker#' + id, parentNode || document);
|
30660 | }
|
30661 |
|
30662 | |
30663 |
|
30664 |
|
30665 |
|
30666 |
|
30667 |
|
30668 |
|
30669 |
|
30670 | function referenceToId(reference) {
|
30671 | return reference.match(/url\(['"]?#([^'"]*)['"]?\)/)[1];
|
30672 | }
|
30673 |
|
30674 | |
30675 |
|
30676 |
|
30677 |
|
30678 |
|
30679 |
|
30680 |
|
30681 | function idToReference(id) {
|
30682 | return 'url(#' + id + ')';
|
30683 | }
|
30684 |
|
30685 | |
30686 |
|
30687 |
|
30688 |
|
30689 |
|
30690 |
|
30691 |
|
30692 | function canHaveMarker(node) {
|
30693 | return NODES_CAN_HAVE_MARKER.indexOf(node.nodeName) !== -1;
|
30694 | }
|
30695 |
|
30696 | var PreviewSupportModule = {
|
30697 | __init__: [ 'previewSupport' ],
|
30698 | previewSupport: [ 'type', PreviewSupport ]
|
30699 | };
|
30700 |
|
30701 | var MARKER_OK$2 = 'drop-ok',
|
30702 | MARKER_NOT_OK$2 = 'drop-not-ok',
|
30703 | MARKER_ATTACH = 'attach-ok',
|
30704 | MARKER_NEW_PARENT = 'new-parent';
|
30705 |
|
30706 |
|
30707 | |
30708 |
|
30709 |
|
30710 |
|
30711 |
|
30712 |
|
30713 |
|
30714 |
|
30715 |
|
30716 | function Create(
|
30717 | canvas,
|
30718 | dragging,
|
30719 | eventBus,
|
30720 | modeling,
|
30721 | rules
|
30722 | ) {
|
30723 |
|
30724 |
|
30725 |
|
30726 | |
30727 |
|
30728 |
|
30729 |
|
30730 |
|
30731 |
|
30732 |
|
30733 |
|
30734 |
|
30735 |
|
30736 | function canCreate(elements, target, position, source) {
|
30737 | if (!target) {
|
30738 | return false;
|
30739 | }
|
30740 |
|
30741 |
|
30742 | elements = filter(elements, function(element) {
|
30743 | return !element.parent;
|
30744 | });
|
30745 |
|
30746 | var shape = find(elements, function(element) {
|
30747 | return !isConnection(element);
|
30748 | });
|
30749 |
|
30750 | var attach = false,
|
30751 | connect = false,
|
30752 | create = false;
|
30753 |
|
30754 |
|
30755 | if (isSingleShape(elements)) {
|
30756 | attach = rules.allowed('shape.attach', {
|
30757 | position: position,
|
30758 | shape: shape,
|
30759 | target: target
|
30760 | });
|
30761 | }
|
30762 |
|
30763 | if (!attach) {
|
30764 |
|
30765 |
|
30766 | if (isSingleShape(elements)) {
|
30767 | create = rules.allowed('shape.create', {
|
30768 | position: position,
|
30769 | shape: shape,
|
30770 | source: source,
|
30771 | target: target
|
30772 | });
|
30773 | } else {
|
30774 | create = rules.allowed('elements.create', {
|
30775 | elements: elements,
|
30776 | position: position,
|
30777 | target: target
|
30778 | });
|
30779 | }
|
30780 |
|
30781 | }
|
30782 |
|
30783 |
|
30784 | if (create || attach) {
|
30785 |
|
30786 | if (shape && source) {
|
30787 | connect = rules.allowed('connection.create', {
|
30788 | source: source,
|
30789 | target: shape,
|
30790 | hints: {
|
30791 | targetParent: target,
|
30792 | targetAttach: attach
|
30793 | }
|
30794 | });
|
30795 | }
|
30796 |
|
30797 | return {
|
30798 | attach: attach,
|
30799 | connect: connect
|
30800 | };
|
30801 | }
|
30802 |
|
30803 |
|
30804 | if (create === null || attach === null) {
|
30805 | return null;
|
30806 | }
|
30807 |
|
30808 | return false;
|
30809 | }
|
30810 |
|
30811 | function setMarker(element, marker) {
|
30812 | [ MARKER_ATTACH, MARKER_OK$2, MARKER_NOT_OK$2, MARKER_NEW_PARENT ].forEach(function(m) {
|
30813 |
|
30814 | if (m === marker) {
|
30815 | canvas.addMarker(element, m);
|
30816 | } else {
|
30817 | canvas.removeMarker(element, m);
|
30818 | }
|
30819 | });
|
30820 | }
|
30821 |
|
30822 |
|
30823 |
|
30824 | eventBus.on([ 'create.move', 'create.hover' ], function(event) {
|
30825 | var context = event.context,
|
30826 | elements = context.elements,
|
30827 | hover = event.hover,
|
30828 | source = context.source;
|
30829 |
|
30830 | if (!hover) {
|
30831 | context.canExecute = false;
|
30832 | context.target = null;
|
30833 |
|
30834 | return;
|
30835 | }
|
30836 |
|
30837 | ensureConstraints(event);
|
30838 |
|
30839 | var position = {
|
30840 | x: event.x,
|
30841 | y: event.y
|
30842 | };
|
30843 |
|
30844 | var canExecute = context.canExecute = hover && canCreate(elements, hover, position, source);
|
30845 |
|
30846 | if (hover && canExecute !== null) {
|
30847 | context.target = hover;
|
30848 |
|
30849 | if (canExecute && canExecute.attach) {
|
30850 | setMarker(hover, MARKER_ATTACH);
|
30851 | } else {
|
30852 | setMarker(hover, canExecute ? MARKER_NEW_PARENT : MARKER_NOT_OK$2);
|
30853 | }
|
30854 | }
|
30855 | });
|
30856 |
|
30857 | eventBus.on([ 'create.end', 'create.out', 'create.cleanup' ], function(event) {
|
30858 | var hover = event.hover;
|
30859 |
|
30860 | if (hover) {
|
30861 | setMarker(hover, null);
|
30862 | }
|
30863 | });
|
30864 |
|
30865 | eventBus.on('create.end', function(event) {
|
30866 | var context = event.context,
|
30867 | source = context.source,
|
30868 | shape = context.shape,
|
30869 | elements = context.elements,
|
30870 | target = context.target,
|
30871 | hints = context.hints,
|
30872 | canExecute = context.canExecute,
|
30873 | attach = canExecute && canExecute.attach,
|
30874 | connect = canExecute && canExecute.connect;
|
30875 |
|
30876 | if (canExecute === false || !target) {
|
30877 | return false;
|
30878 | }
|
30879 |
|
30880 | ensureConstraints(event);
|
30881 |
|
30882 | var position = {
|
30883 | x: event.x,
|
30884 | y: event.y
|
30885 | };
|
30886 |
|
30887 | if (connect) {
|
30888 | shape = modeling.appendShape(source, shape, position, target, {
|
30889 | attach: attach,
|
30890 | connection: connect === true ? {} : connect
|
30891 | });
|
30892 | } else {
|
30893 | elements = modeling.createElements(elements, position, target, assign({}, hints, {
|
30894 | attach: attach
|
30895 | }));
|
30896 |
|
30897 |
|
30898 | shape = find(elements, function(element) {
|
30899 | return !isConnection(element);
|
30900 | });
|
30901 | }
|
30902 |
|
30903 |
|
30904 | assign(context, {
|
30905 | elements: elements,
|
30906 | shape: shape
|
30907 | });
|
30908 |
|
30909 | assign(event, {
|
30910 | elements: elements,
|
30911 | shape: shape
|
30912 | });
|
30913 | });
|
30914 |
|
30915 |
|
30916 |
|
30917 | this.start = function(event, elements, context) {
|
30918 | if (!isArray(elements)) {
|
30919 | elements = [ elements ];
|
30920 | }
|
30921 |
|
30922 | var shape = find(elements, function(element) {
|
30923 | return !isConnection(element);
|
30924 | });
|
30925 |
|
30926 | if (!shape) {
|
30927 |
|
30928 |
|
30929 | return;
|
30930 | }
|
30931 |
|
30932 | context = assign({
|
30933 | elements: elements,
|
30934 | hints: {},
|
30935 | shape: shape
|
30936 | }, context || {});
|
30937 |
|
30938 |
|
30939 | forEach(elements, function(element) {
|
30940 | if (!isNumber(element.x)) {
|
30941 | element.x = 0;
|
30942 | }
|
30943 |
|
30944 | if (!isNumber(element.y)) {
|
30945 | element.y = 0;
|
30946 | }
|
30947 | });
|
30948 |
|
30949 | var bbox = getBBox(elements);
|
30950 |
|
30951 |
|
30952 | forEach(elements, function(element) {
|
30953 | if (isConnection(element)) {
|
30954 | element.waypoints = map(element.waypoints, function(waypoint) {
|
30955 | return {
|
30956 | x: waypoint.x - bbox.x - bbox.width / 2,
|
30957 | y: waypoint.y - bbox.y - bbox.height / 2
|
30958 | };
|
30959 | });
|
30960 | }
|
30961 |
|
30962 | assign(element, {
|
30963 | x: element.x - bbox.x - bbox.width / 2,
|
30964 | y: element.y - bbox.y - bbox.height / 2
|
30965 | });
|
30966 | });
|
30967 |
|
30968 | dragging.init(event, 'create', {
|
30969 | cursor: 'grabbing',
|
30970 | autoActivate: true,
|
30971 | data: {
|
30972 | shape: shape,
|
30973 | elements: elements,
|
30974 | context: context
|
30975 | }
|
30976 | });
|
30977 | };
|
30978 | }
|
30979 |
|
30980 | Create.$inject = [
|
30981 | 'canvas',
|
30982 | 'dragging',
|
30983 | 'eventBus',
|
30984 | 'modeling',
|
30985 | 'rules'
|
30986 | ];
|
30987 |
|
30988 |
|
30989 |
|
30990 | function ensureConstraints(event) {
|
30991 | var context = event.context,
|
30992 | createConstraints = context.createConstraints;
|
30993 |
|
30994 | if (!createConstraints) {
|
30995 | return;
|
30996 | }
|
30997 |
|
30998 | if (createConstraints.left) {
|
30999 | event.x = Math.max(event.x, createConstraints.left);
|
31000 | }
|
31001 |
|
31002 | if (createConstraints.right) {
|
31003 | event.x = Math.min(event.x, createConstraints.right);
|
31004 | }
|
31005 |
|
31006 | if (createConstraints.top) {
|
31007 | event.y = Math.max(event.y, createConstraints.top);
|
31008 | }
|
31009 |
|
31010 | if (createConstraints.bottom) {
|
31011 | event.y = Math.min(event.y, createConstraints.bottom);
|
31012 | }
|
31013 | }
|
31014 |
|
31015 | function isConnection(element) {
|
31016 | return !!element.waypoints;
|
31017 | }
|
31018 |
|
31019 | function isSingleShape(elements) {
|
31020 | return elements && elements.length === 1 && !isConnection(elements[0]);
|
31021 | }
|
31022 |
|
31023 | var LOW_PRIORITY$5 = 750;
|
31024 |
|
31025 |
|
31026 | function CreatePreview(
|
31027 | canvas,
|
31028 | eventBus,
|
31029 | graphicsFactory,
|
31030 | previewSupport,
|
31031 | styles
|
31032 | ) {
|
31033 | function createDragGroup(elements) {
|
31034 | var dragGroup = create('g');
|
31035 |
|
31036 | attr$1(dragGroup, styles.cls('djs-drag-group', [ 'no-events' ]));
|
31037 |
|
31038 | var defaultLayer = canvas.getDefaultLayer();
|
31039 |
|
31040 | append(defaultLayer, dragGroup);
|
31041 |
|
31042 | var childrenGfx = create('g');
|
31043 |
|
31044 | elements.forEach(function(element) {
|
31045 |
|
31046 |
|
31047 | var gfx;
|
31048 |
|
31049 | if (element.waypoints) {
|
31050 | gfx = graphicsFactory._createContainer('connection', childrenGfx);
|
31051 |
|
31052 | graphicsFactory.drawConnection(getVisual(gfx), element);
|
31053 | } else {
|
31054 | gfx = graphicsFactory._createContainer('shape', childrenGfx);
|
31055 |
|
31056 | graphicsFactory.drawShape(getVisual(gfx), element);
|
31057 |
|
31058 | translate(gfx, element.x, element.y);
|
31059 | }
|
31060 |
|
31061 |
|
31062 | previewSupport.addDragger(element, dragGroup, gfx);
|
31063 | });
|
31064 |
|
31065 | return dragGroup;
|
31066 | }
|
31067 |
|
31068 | eventBus.on('create.move', LOW_PRIORITY$5, function(event) {
|
31069 |
|
31070 | var context = event.context,
|
31071 | elements = context.elements,
|
31072 | dragGroup = context.dragGroup;
|
31073 |
|
31074 |
|
31075 | if (!dragGroup) {
|
31076 | dragGroup = context.dragGroup = createDragGroup(elements);
|
31077 | }
|
31078 |
|
31079 | translate(dragGroup, event.x, event.y);
|
31080 | });
|
31081 |
|
31082 | eventBus.on('create.cleanup', function(event) {
|
31083 | var context = event.context,
|
31084 | dragGroup = context.dragGroup;
|
31085 |
|
31086 | if (dragGroup) {
|
31087 | remove$1(dragGroup);
|
31088 | }
|
31089 | });
|
31090 | }
|
31091 |
|
31092 | CreatePreview.$inject = [
|
31093 | 'canvas',
|
31094 | 'eventBus',
|
31095 | 'graphicsFactory',
|
31096 | 'previewSupport',
|
31097 | 'styles'
|
31098 | ];
|
31099 |
|
31100 | var CreateModule = {
|
31101 | __depends__: [
|
31102 | DraggingModule,
|
31103 | PreviewSupportModule,
|
31104 | RulesModule,
|
31105 | SelectionModule
|
31106 | ],
|
31107 | __init__: [
|
31108 | 'create',
|
31109 | 'createPreview'
|
31110 | ],
|
31111 | create: [ 'type', Create ],
|
31112 | createPreview: [ 'type', CreatePreview ]
|
31113 | };
|
31114 |
|
31115 | var DATA_REF = 'data-id';
|
31116 |
|
31117 |
|
31118 | |
31119 |
|
31120 |
|
31121 |
|
31122 |
|
31123 |
|
31124 |
|
31125 |
|
31126 |
|
31127 |
|
31128 |
|
31129 |
|
31130 |
|
31131 | function PopupMenu(config, eventBus, canvas) {
|
31132 |
|
31133 | var scale = isDefined(config && config.scale) ? config.scale : {
|
31134 | min: 1,
|
31135 | max: 1.5
|
31136 | };
|
31137 |
|
31138 | this._config = {
|
31139 | scale: scale
|
31140 | };
|
31141 |
|
31142 | this._eventBus = eventBus;
|
31143 | this._canvas = canvas;
|
31144 | this._providers = {};
|
31145 | this._current = {};
|
31146 | }
|
31147 |
|
31148 | PopupMenu.$inject = [
|
31149 | 'config.popupMenu',
|
31150 | 'eventBus',
|
31151 | 'canvas'
|
31152 | ];
|
31153 |
|
31154 | |
31155 |
|
31156 |
|
31157 |
|
31158 |
|
31159 |
|
31160 |
|
31161 |
|
31162 |
|
31163 |
|
31164 |
|
31165 |
|
31166 |
|
31167 |
|
31168 |
|
31169 |
|
31170 |
|
31171 |
|
31172 |
|
31173 |
|
31174 | PopupMenu.prototype.registerProvider = function(id, provider) {
|
31175 | this._providers[id] = provider;
|
31176 | };
|
31177 |
|
31178 |
|
31179 | |
31180 |
|
31181 |
|
31182 |
|
31183 |
|
31184 | PopupMenu.prototype.isEmpty = function(element, providerId) {
|
31185 | if (!element) {
|
31186 | throw new Error('element parameter is missing');
|
31187 | }
|
31188 |
|
31189 | if (!providerId) {
|
31190 | throw new Error('providerId parameter is missing');
|
31191 | }
|
31192 |
|
31193 | var provider = this._providers[providerId];
|
31194 |
|
31195 | var entries = provider.getEntries(element),
|
31196 | headerEntries = provider.getHeaderEntries && provider.getHeaderEntries(element);
|
31197 |
|
31198 | var hasEntries = entries.length > 0,
|
31199 | hasHeaderEntries = headerEntries && headerEntries.length > 0;
|
31200 |
|
31201 | return !hasEntries && !hasHeaderEntries;
|
31202 | };
|
31203 |
|
31204 |
|
31205 | |
31206 |
|
31207 |
|
31208 |
|
31209 |
|
31210 |
|
31211 |
|
31212 |
|
31213 |
|
31214 | PopupMenu.prototype.open = function(element, id, position) {
|
31215 |
|
31216 | var provider = this._providers[id];
|
31217 |
|
31218 | if (!element) {
|
31219 | throw new Error('Element is missing');
|
31220 | }
|
31221 |
|
31222 | if (!provider) {
|
31223 | throw new Error('Provider is not registered: ' + id);
|
31224 | }
|
31225 |
|
31226 | if (!position) {
|
31227 | throw new Error('the position argument is missing');
|
31228 | }
|
31229 |
|
31230 | if (this.isOpen()) {
|
31231 | this.close();
|
31232 | }
|
31233 |
|
31234 | this._emit('open');
|
31235 |
|
31236 | var current = this._current = {
|
31237 | provider: provider,
|
31238 | className: id,
|
31239 | element: element,
|
31240 | position: position
|
31241 | };
|
31242 |
|
31243 | if (provider.getHeaderEntries) {
|
31244 | current.headerEntries = provider.getHeaderEntries(element);
|
31245 | }
|
31246 |
|
31247 | current.entries = provider.getEntries(element);
|
31248 |
|
31249 | current.container = this._createContainer();
|
31250 |
|
31251 | var headerEntries = current.headerEntries || [],
|
31252 | entries = current.entries || [];
|
31253 |
|
31254 | if (headerEntries.length) {
|
31255 | current.container.appendChild(
|
31256 | this._createEntries(current.headerEntries, 'djs-popup-header')
|
31257 | );
|
31258 | }
|
31259 |
|
31260 | if (entries.length) {
|
31261 | current.container.appendChild(
|
31262 | this._createEntries(current.entries, 'djs-popup-body')
|
31263 | );
|
31264 | }
|
31265 |
|
31266 | var canvas = this._canvas,
|
31267 | parent = canvas.getContainer();
|
31268 |
|
31269 | this._attachContainer(current.container, parent, position.cursor);
|
31270 | };
|
31271 |
|
31272 |
|
31273 | |
31274 |
|
31275 |
|
31276 | PopupMenu.prototype.close = function() {
|
31277 |
|
31278 | if (!this.isOpen()) {
|
31279 | return;
|
31280 | }
|
31281 |
|
31282 | this._emit('close');
|
31283 |
|
31284 | this._unbindHandlers();
|
31285 | remove(this._current.container);
|
31286 | this._current.container = null;
|
31287 | };
|
31288 |
|
31289 |
|
31290 | |
31291 |
|
31292 |
|
31293 |
|
31294 |
|
31295 | PopupMenu.prototype.isOpen = function() {
|
31296 | return !!this._current.container;
|
31297 | };
|
31298 |
|
31299 |
|
31300 | |
31301 |
|
31302 |
|
31303 |
|
31304 |
|
31305 |
|
31306 |
|
31307 | PopupMenu.prototype.trigger = function(event) {
|
31308 |
|
31309 |
|
31310 | event.preventDefault();
|
31311 |
|
31312 | var element = event.delegateTarget || event.target,
|
31313 | entryId = attr(element, DATA_REF);
|
31314 |
|
31315 | var entry = this._getEntry(entryId);
|
31316 |
|
31317 | if (entry.action) {
|
31318 | return entry.action.call(null, event, entry);
|
31319 | }
|
31320 | };
|
31321 |
|
31322 | |
31323 |
|
31324 |
|
31325 |
|
31326 |
|
31327 |
|
31328 |
|
31329 | PopupMenu.prototype._getEntry = function(entryId) {
|
31330 |
|
31331 | var search = matchPattern({ id: entryId });
|
31332 |
|
31333 | var entry = find(this._current.entries, search) || find(this._current.headerEntries, search);
|
31334 |
|
31335 | if (!entry) {
|
31336 | throw new Error('entry not found');
|
31337 | }
|
31338 |
|
31339 | return entry;
|
31340 | };
|
31341 |
|
31342 | PopupMenu.prototype._emit = function(eventName) {
|
31343 | this._eventBus.fire('popupMenu.' + eventName);
|
31344 | };
|
31345 |
|
31346 | |
31347 |
|
31348 |
|
31349 |
|
31350 |
|
31351 | PopupMenu.prototype._createContainer = function() {
|
31352 | var container = domify('<div class="djs-popup">'),
|
31353 | position = this._current.position,
|
31354 | className = this._current.className;
|
31355 |
|
31356 | assign(container.style, {
|
31357 | position: 'absolute',
|
31358 | left: position.x + 'px',
|
31359 | top: position.y + 'px',
|
31360 | visibility: 'hidden'
|
31361 | });
|
31362 |
|
31363 | classes(container).add(className);
|
31364 |
|
31365 | return container;
|
31366 | };
|
31367 |
|
31368 |
|
31369 | |
31370 |
|
31371 |
|
31372 |
|
31373 |
|
31374 |
|
31375 | PopupMenu.prototype._attachContainer = function(container, parent, cursor) {
|
31376 | var self = this;
|
31377 |
|
31378 |
|
31379 | delegateEvents.bind(container, '.entry' ,'click', function(event) {
|
31380 | self.trigger(event);
|
31381 | });
|
31382 |
|
31383 | this._updateScale(container);
|
31384 |
|
31385 |
|
31386 | parent.appendChild(container);
|
31387 |
|
31388 | if (cursor) {
|
31389 | this._assureIsInbounds(container, cursor);
|
31390 | }
|
31391 |
|
31392 |
|
31393 | this._bindHandlers();
|
31394 | };
|
31395 |
|
31396 |
|
31397 | |
31398 |
|
31399 |
|
31400 |
|
31401 |
|
31402 |
|
31403 |
|
31404 | PopupMenu.prototype._updateScale = function(container) {
|
31405 | var zoom = this._canvas.zoom();
|
31406 |
|
31407 | var scaleConfig = this._config.scale,
|
31408 | minScale,
|
31409 | maxScale,
|
31410 | scale = zoom;
|
31411 |
|
31412 | if (scaleConfig !== true) {
|
31413 |
|
31414 | if (scaleConfig === false) {
|
31415 | minScale = 1;
|
31416 | maxScale = 1;
|
31417 | } else {
|
31418 | minScale = scaleConfig.min;
|
31419 | maxScale = scaleConfig.max;
|
31420 | }
|
31421 |
|
31422 | if (isDefined(minScale) && zoom < minScale) {
|
31423 | scale = minScale;
|
31424 | }
|
31425 |
|
31426 | if (isDefined(maxScale) && zoom > maxScale) {
|
31427 | scale = maxScale;
|
31428 | }
|
31429 |
|
31430 | }
|
31431 |
|
31432 | setTransform$1(container, 'scale(' + scale + ')');
|
31433 | };
|
31434 |
|
31435 |
|
31436 | |
31437 |
|
31438 |
|
31439 |
|
31440 |
|
31441 |
|
31442 |
|
31443 |
|
31444 | PopupMenu.prototype._assureIsInbounds = function(container, cursor) {
|
31445 | var canvas = this._canvas,
|
31446 | clientRect = canvas._container.getBoundingClientRect();
|
31447 |
|
31448 | var containerX = container.offsetLeft,
|
31449 | containerY = container.offsetTop,
|
31450 | containerWidth = container.scrollWidth,
|
31451 | containerHeight = container.scrollHeight,
|
31452 | overAxis = {},
|
31453 | left, top;
|
31454 |
|
31455 | var cursorPosition = {
|
31456 | x: cursor.x - clientRect.left,
|
31457 | y: cursor.y - clientRect.top
|
31458 | };
|
31459 |
|
31460 | if (containerX + containerWidth > clientRect.width) {
|
31461 | overAxis.x = true;
|
31462 | }
|
31463 |
|
31464 | if (containerY + containerHeight > clientRect.height) {
|
31465 | overAxis.y = true;
|
31466 | }
|
31467 |
|
31468 | if (overAxis.x && overAxis.y) {
|
31469 | left = cursorPosition.x - containerWidth + 'px';
|
31470 | top = cursorPosition.y - containerHeight + 'px';
|
31471 | } else if (overAxis.x) {
|
31472 | left = cursorPosition.x - containerWidth + 'px';
|
31473 | top = cursorPosition.y + 'px';
|
31474 | } else if (overAxis.y && cursorPosition.y < containerHeight) {
|
31475 | left = cursorPosition.x + 'px';
|
31476 | top = 10 + 'px';
|
31477 | } else if (overAxis.y) {
|
31478 | left = cursorPosition.x + 'px';
|
31479 | top = cursorPosition.y - containerHeight + 'px';
|
31480 | }
|
31481 |
|
31482 | assign(container.style, { left: left, top: top }, { visibility: 'visible', 'z-index': 1000 });
|
31483 | };
|
31484 |
|
31485 |
|
31486 | |
31487 |
|
31488 |
|
31489 |
|
31490 |
|
31491 |
|
31492 |
|
31493 |
|
31494 | PopupMenu.prototype._createEntries = function(entries, className) {
|
31495 |
|
31496 | var entriesContainer = domify('<div>'),
|
31497 | self = this;
|
31498 |
|
31499 | classes(entriesContainer).add(className);
|
31500 |
|
31501 | forEach(entries, function(entry) {
|
31502 | var entryContainer = self._createEntry(entry, entriesContainer);
|
31503 | entriesContainer.appendChild(entryContainer);
|
31504 | });
|
31505 |
|
31506 | return entriesContainer;
|
31507 | };
|
31508 |
|
31509 |
|
31510 | |
31511 |
|
31512 |
|
31513 |
|
31514 |
|
31515 |
|
31516 |
|
31517 | PopupMenu.prototype._createEntry = function(entry) {
|
31518 |
|
31519 | if (!entry.id) {
|
31520 | throw new Error ('every entry must have the id property set');
|
31521 | }
|
31522 |
|
31523 | var entryContainer = domify('<div>'),
|
31524 | entryClasses = classes(entryContainer);
|
31525 |
|
31526 | entryClasses.add('entry');
|
31527 |
|
31528 | if (entry.className) {
|
31529 | entry.className.split(' ').forEach(function(className) {
|
31530 | entryClasses.add(className);
|
31531 | });
|
31532 | }
|
31533 |
|
31534 | attr(entryContainer, DATA_REF, entry.id);
|
31535 |
|
31536 | if (entry.label) {
|
31537 | var label = domify('<span>');
|
31538 | label.textContent = entry.label;
|
31539 | entryContainer.appendChild(label);
|
31540 | }
|
31541 |
|
31542 | if (entry.imageUrl) {
|
31543 | entryContainer.appendChild(domify('<img src="' + entry.imageUrl + '" />'));
|
31544 | }
|
31545 |
|
31546 | if (entry.active === true) {
|
31547 | entryClasses.add('active');
|
31548 | }
|
31549 |
|
31550 | if (entry.disabled === true) {
|
31551 | entryClasses.add('disabled');
|
31552 | }
|
31553 |
|
31554 | if (entry.title) {
|
31555 | entryContainer.title = entry.title;
|
31556 | }
|
31557 |
|
31558 | return entryContainer;
|
31559 | };
|
31560 |
|
31561 |
|
31562 | |
31563 |
|
31564 |
|
31565 | PopupMenu.prototype._bindHandlers = function() {
|
31566 |
|
31567 | var eventBus = this._eventBus,
|
31568 | self = this;
|
31569 |
|
31570 | function close() {
|
31571 | self.close();
|
31572 | }
|
31573 |
|
31574 | eventBus.once('contextPad.close', close);
|
31575 | eventBus.once('canvas.viewbox.changing', close);
|
31576 | eventBus.once('commandStack.changed', close);
|
31577 | };
|
31578 |
|
31579 |
|
31580 | |
31581 |
|
31582 |
|
31583 | PopupMenu.prototype._unbindHandlers = function() {
|
31584 |
|
31585 | var eventBus = this._eventBus,
|
31586 | self = this;
|
31587 |
|
31588 | function close() {
|
31589 | self.close();
|
31590 | }
|
31591 |
|
31592 | eventBus.off('contextPad.close', close);
|
31593 | eventBus.off('canvas.viewbox.changed', close);
|
31594 | eventBus.off('commandStack.changed', close);
|
31595 | };
|
31596 |
|
31597 |
|
31598 |
|
31599 |
|
31600 |
|
31601 | function setTransform$1(element, transform) {
|
31602 | element.style['transform-origin'] = 'top left';
|
31603 |
|
31604 | [ '', '-ms-', '-webkit-' ].forEach(function(prefix) {
|
31605 | element.style[prefix + 'transform'] = transform;
|
31606 | });
|
31607 | }
|
31608 |
|
31609 | var PopupMenuModule = {
|
31610 | __init__: [ 'popupMenu' ],
|
31611 | popupMenu: [ 'type', PopupMenu ]
|
31612 | };
|
31613 |
|
31614 | |
31615 |
|
31616 |
|
31617 | function Clipboard() {}
|
31618 |
|
31619 |
|
31620 | Clipboard.prototype.get = function() {
|
31621 | return this._data;
|
31622 | };
|
31623 |
|
31624 | Clipboard.prototype.set = function(data) {
|
31625 | this._data = data;
|
31626 | };
|
31627 |
|
31628 | Clipboard.prototype.clear = function() {
|
31629 | var data = this._data;
|
31630 |
|
31631 | delete this._data;
|
31632 |
|
31633 | return data;
|
31634 | };
|
31635 |
|
31636 | Clipboard.prototype.isEmpty = function() {
|
31637 | return !this._data;
|
31638 | };
|
31639 |
|
31640 | var ClipboardModule = {
|
31641 | clipboard: [ 'type', Clipboard ]
|
31642 | };
|
31643 |
|
31644 | function Mouse(eventBus) {
|
31645 | var self = this;
|
31646 |
|
31647 | this._lastMoveEvent = null;
|
31648 |
|
31649 | function setLastMoveEvent(mousemoveEvent) {
|
31650 | self._lastMoveEvent = mousemoveEvent;
|
31651 | }
|
31652 |
|
31653 | eventBus.on('canvas.init', function(context) {
|
31654 | var svg = self._svg = context.svg;
|
31655 |
|
31656 | svg.addEventListener('mousemove', setLastMoveEvent);
|
31657 | });
|
31658 |
|
31659 | eventBus.on('canvas.destroy', function() {
|
31660 | self._lastMouseEvent = null;
|
31661 |
|
31662 | self._svg.removeEventListener('mousemove', setLastMoveEvent);
|
31663 | });
|
31664 | }
|
31665 |
|
31666 | Mouse.$inject = [ 'eventBus' ];
|
31667 |
|
31668 | Mouse.prototype.getLastMoveEvent = function() {
|
31669 | return this._lastMoveEvent || createMoveEvent(0, 0);
|
31670 | };
|
31671 |
|
31672 |
|
31673 |
|
31674 | function createMoveEvent(x, y) {
|
31675 | var event = document.createEvent('MouseEvent');
|
31676 |
|
31677 | var screenX = x,
|
31678 | screenY = y,
|
31679 | clientX = x,
|
31680 | clientY = y;
|
31681 |
|
31682 | if (event.initMouseEvent) {
|
31683 | event.initMouseEvent(
|
31684 | 'mousemove',
|
31685 | true,
|
31686 | true,
|
31687 | window,
|
31688 | 0,
|
31689 | screenX,
|
31690 | screenY,
|
31691 | clientX,
|
31692 | clientY,
|
31693 | false,
|
31694 | false,
|
31695 | false,
|
31696 | false,
|
31697 | 0,
|
31698 | null
|
31699 | );
|
31700 | }
|
31701 |
|
31702 | return event;
|
31703 | }
|
31704 |
|
31705 | var MouseModule = {
|
31706 | __init__: [ 'mouse' ],
|
31707 | mouse: [ 'type', Mouse ]
|
31708 | };
|
31709 |
|
31710 | |
31711 |
|
31712 |
|
31713 |
|
31714 |
|
31715 |
|
31716 |
|
31717 |
|
31718 |
|
31719 |
|
31720 | |
31721 |
|
31722 |
|
31723 |
|
31724 |
|
31725 |
|
31726 |
|
31727 |
|
31728 |
|
31729 | |
31730 |
|
31731 |
|
31732 |
|
31733 |
|
31734 |
|
31735 |
|
31736 |
|
31737 | |
31738 |
|
31739 |
|
31740 |
|
31741 |
|
31742 |
|
31743 |
|
31744 |
|
31745 | |
31746 |
|
31747 |
|
31748 |
|
31749 |
|
31750 |
|
31751 |
|
31752 | |
31753 |
|
31754 |
|
31755 |
|
31756 |
|
31757 |
|
31758 |
|
31759 |
|
31760 |
|
31761 |
|
31762 |
|
31763 |
|
31764 | function CopyPaste(
|
31765 | canvas,
|
31766 | create,
|
31767 | clipboard,
|
31768 | elementFactory,
|
31769 | eventBus,
|
31770 | modeling,
|
31771 | mouse,
|
31772 | rules
|
31773 | ) {
|
31774 |
|
31775 | this._canvas = canvas;
|
31776 | this._create = create;
|
31777 | this._clipboard = clipboard;
|
31778 | this._elementFactory = elementFactory;
|
31779 | this._eventBus = eventBus;
|
31780 | this._modeling = modeling;
|
31781 | this._mouse = mouse;
|
31782 | this._rules = rules;
|
31783 |
|
31784 | eventBus.on('copyPaste.copyElement', function(context) {
|
31785 | var descriptor = context.descriptor,
|
31786 | element = context.element,
|
31787 | elements = context.elements;
|
31788 |
|
31789 |
|
31790 | descriptor.priority = 1;
|
31791 |
|
31792 | descriptor.id = element.id;
|
31793 |
|
31794 | var parentCopied = find(elements, function(e) {
|
31795 | return e === element.parent;
|
31796 | });
|
31797 |
|
31798 |
|
31799 | if (parentCopied) {
|
31800 | descriptor.parent = element.parent.id;
|
31801 | }
|
31802 |
|
31803 |
|
31804 | if (isAttacher(element)) {
|
31805 | descriptor.priority = 2;
|
31806 |
|
31807 | descriptor.host = element.host.id;
|
31808 | }
|
31809 |
|
31810 |
|
31811 | if (isConnection$1(element)) {
|
31812 | descriptor.priority = 3;
|
31813 |
|
31814 | descriptor.source = element.source.id;
|
31815 | descriptor.target = element.target.id;
|
31816 |
|
31817 | descriptor.waypoints = copyWaypoints(element);
|
31818 | }
|
31819 |
|
31820 |
|
31821 | if (isLabel$1(element)) {
|
31822 | descriptor.priority = 4;
|
31823 |
|
31824 | descriptor.labelTarget = element.labelTarget.id;
|
31825 | }
|
31826 |
|
31827 | forEach([ 'x', 'y', 'width', 'height' ], function(property) {
|
31828 | if (isNumber(element[ property ])) {
|
31829 | descriptor[ property ] = element[ property ];
|
31830 | }
|
31831 | });
|
31832 | });
|
31833 |
|
31834 | eventBus.on('copyPaste.pasteElements', function(context) {
|
31835 | var hints = context.hints;
|
31836 |
|
31837 | assign(hints, {
|
31838 | createElementsBehavior: false
|
31839 | });
|
31840 | });
|
31841 | }
|
31842 |
|
31843 | CopyPaste.$inject = [
|
31844 | 'canvas',
|
31845 | 'create',
|
31846 | 'clipboard',
|
31847 | 'elementFactory',
|
31848 | 'eventBus',
|
31849 | 'modeling',
|
31850 | 'mouse',
|
31851 | 'rules'
|
31852 | ];
|
31853 |
|
31854 |
|
31855 | |
31856 |
|
31857 |
|
31858 |
|
31859 |
|
31860 |
|
31861 |
|
31862 | CopyPaste.prototype.copy = function(elements) {
|
31863 | var allowed,
|
31864 | tree;
|
31865 |
|
31866 | if (!isArray(elements)) {
|
31867 | elements = elements ? [ elements ] : [];
|
31868 | }
|
31869 |
|
31870 | allowed = this._eventBus.fire('copyPaste.canCopyElements', {
|
31871 | elements: elements
|
31872 | });
|
31873 |
|
31874 | if (allowed === false) {
|
31875 | tree = {};
|
31876 | } else {
|
31877 | tree = this.createTree(isArray(allowed) ? allowed : elements);
|
31878 | }
|
31879 |
|
31880 |
|
31881 |
|
31882 | this._clipboard.set(tree);
|
31883 |
|
31884 | this._eventBus.fire('copyPaste.elementsCopied', {
|
31885 | elements: elements,
|
31886 | tree: tree
|
31887 | });
|
31888 |
|
31889 | return tree;
|
31890 | };
|
31891 |
|
31892 | |
31893 |
|
31894 |
|
31895 |
|
31896 |
|
31897 |
|
31898 |
|
31899 | CopyPaste.prototype.paste = function(context) {
|
31900 | var tree = this._clipboard.get();
|
31901 |
|
31902 | if (this._clipboard.isEmpty()) {
|
31903 | return;
|
31904 | }
|
31905 |
|
31906 | var hints = {};
|
31907 |
|
31908 | this._eventBus.fire('copyPaste.pasteElements', {
|
31909 | hints: hints
|
31910 | });
|
31911 |
|
31912 | var elements = this._createElements(tree);
|
31913 |
|
31914 |
|
31915 | if (context && context.element && context.point) {
|
31916 | return this._paste(elements, context.element, context.point, hints);
|
31917 | }
|
31918 |
|
31919 | this._create.start(this._mouse.getLastMoveEvent(), elements, {
|
31920 | hints: hints || {}
|
31921 | });
|
31922 | };
|
31923 |
|
31924 | |
31925 |
|
31926 |
|
31927 |
|
31928 |
|
31929 |
|
31930 |
|
31931 |
|
31932 | CopyPaste.prototype._paste = function(elements, target, position, hints) {
|
31933 |
|
31934 |
|
31935 | forEach(elements, function(element) {
|
31936 | if (!isNumber(element.x)) {
|
31937 | element.x = 0;
|
31938 | }
|
31939 |
|
31940 | if (!isNumber(element.y)) {
|
31941 | element.y = 0;
|
31942 | }
|
31943 | });
|
31944 |
|
31945 | var bbox = getBBox(elements);
|
31946 |
|
31947 |
|
31948 | forEach(elements, function(element) {
|
31949 | if (isConnection$1(element)) {
|
31950 | element.waypoints = map(element.waypoints, function(waypoint) {
|
31951 | return {
|
31952 | x: waypoint.x - bbox.x - bbox.width / 2,
|
31953 | y: waypoint.y - bbox.y - bbox.height / 2
|
31954 | };
|
31955 | });
|
31956 | }
|
31957 |
|
31958 | assign(element, {
|
31959 | x: element.x - bbox.x - bbox.width / 2,
|
31960 | y: element.y - bbox.y - bbox.height / 2
|
31961 | });
|
31962 | });
|
31963 |
|
31964 | return this._modeling.createElements(elements, position, target, assign({}, hints));
|
31965 | };
|
31966 |
|
31967 | |
31968 |
|
31969 |
|
31970 | CopyPaste.prototype._createElements = function(tree) {
|
31971 | var self = this;
|
31972 |
|
31973 | var eventBus = this._eventBus;
|
31974 |
|
31975 | var cache = {};
|
31976 |
|
31977 | var elements = [];
|
31978 |
|
31979 | forEach(tree, function(branch, depth) {
|
31980 |
|
31981 |
|
31982 | branch = sortBy(branch, 'priority');
|
31983 |
|
31984 | forEach(branch, function(descriptor) {
|
31985 |
|
31986 |
|
31987 | var attrs = assign({}, omit(descriptor, [ 'priority' ]));
|
31988 |
|
31989 | if (cache[ descriptor.parent ]) {
|
31990 | attrs.parent = cache[ descriptor.parent ];
|
31991 | } else {
|
31992 | delete attrs.parent;
|
31993 | }
|
31994 |
|
31995 | eventBus.fire('copyPaste.pasteElement', {
|
31996 | cache: cache,
|
31997 | descriptor: attrs
|
31998 | });
|
31999 |
|
32000 | var element;
|
32001 |
|
32002 | if (isConnection$1(attrs)) {
|
32003 | attrs.source = cache[ descriptor.source ];
|
32004 | attrs.target = cache[ descriptor.target ];
|
32005 |
|
32006 | element = cache[ descriptor.id ] = self.createConnection(attrs);
|
32007 |
|
32008 | elements.push(element);
|
32009 |
|
32010 | return;
|
32011 | }
|
32012 |
|
32013 | if (isLabel$1(attrs)) {
|
32014 | attrs.labelTarget = cache[ attrs.labelTarget ];
|
32015 |
|
32016 | element = cache[ descriptor.id ] = self.createLabel(attrs);
|
32017 |
|
32018 | elements.push(element);
|
32019 |
|
32020 | return;
|
32021 | }
|
32022 |
|
32023 | if (attrs.host) {
|
32024 | attrs.host = cache[ attrs.host ];
|
32025 | }
|
32026 |
|
32027 | element = cache[ descriptor.id ] = self.createShape(attrs);
|
32028 |
|
32029 | elements.push(element);
|
32030 | });
|
32031 |
|
32032 | });
|
32033 |
|
32034 | return elements;
|
32035 | };
|
32036 |
|
32037 | CopyPaste.prototype.createConnection = function(attrs) {
|
32038 | var connection = this._elementFactory.createConnection(omit(attrs, [ 'id' ]));
|
32039 |
|
32040 | return connection;
|
32041 | };
|
32042 |
|
32043 | CopyPaste.prototype.createLabel = function(attrs) {
|
32044 | var label = this._elementFactory.createLabel(omit(attrs, [ 'id' ]));
|
32045 |
|
32046 | return label;
|
32047 | };
|
32048 |
|
32049 | CopyPaste.prototype.createShape = function(attrs) {
|
32050 | var shape = this._elementFactory.createShape(omit(attrs, [ 'id' ]));
|
32051 |
|
32052 | return shape;
|
32053 | };
|
32054 |
|
32055 | |
32056 |
|
32057 |
|
32058 |
|
32059 |
|
32060 |
|
32061 |
|
32062 |
|
32063 | CopyPaste.prototype.hasRelations = function(element, elements) {
|
32064 | var labelTarget,
|
32065 | source,
|
32066 | target;
|
32067 |
|
32068 | if (isConnection$1(element)) {
|
32069 | source = find(elements, matchPattern({ id: element.source.id }));
|
32070 | target = find(elements, matchPattern({ id: element.target.id }));
|
32071 |
|
32072 | if (!source || !target) {
|
32073 | return false;
|
32074 | }
|
32075 | }
|
32076 |
|
32077 | if (isLabel$1(element)) {
|
32078 | labelTarget = find(elements, matchPattern({ id: element.labelTarget.id }));
|
32079 |
|
32080 | if (!labelTarget) {
|
32081 | return false;
|
32082 | }
|
32083 | }
|
32084 |
|
32085 | return true;
|
32086 | };
|
32087 |
|
32088 | |
32089 |
|
32090 |
|
32091 |
|
32092 |
|
32093 |
|
32094 |
|
32095 |
|
32096 |
|
32097 |
|
32098 |
|
32099 |
|
32100 |
|
32101 |
|
32102 |
|
32103 |
|
32104 |
|
32105 |
|
32106 |
|
32107 |
|
32108 |
|
32109 | CopyPaste.prototype.createTree = function(elements) {
|
32110 | var rules = this._rules,
|
32111 | self = this;
|
32112 |
|
32113 | var tree = {},
|
32114 | elementsData = [];
|
32115 |
|
32116 | var parents = getParents(elements);
|
32117 |
|
32118 | function canCopy(element, elements) {
|
32119 | return rules.allowed('element.copy', {
|
32120 | element: element,
|
32121 | elements: elements
|
32122 | });
|
32123 | }
|
32124 |
|
32125 | function addElementData(element, depth) {
|
32126 |
|
32127 |
|
32128 | var foundElementData = find(elementsData, function(elementsData) {
|
32129 | return element === elementsData.element;
|
32130 | });
|
32131 |
|
32132 |
|
32133 | if (!foundElementData) {
|
32134 | elementsData.push({
|
32135 | element: element,
|
32136 | depth: depth
|
32137 | });
|
32138 |
|
32139 | return;
|
32140 | }
|
32141 |
|
32142 |
|
32143 | if (foundElementData.depth < depth) {
|
32144 | elementsData = removeElementData(foundElementData, elementsData);
|
32145 |
|
32146 | elementsData.push({
|
32147 | element: foundElementData.element,
|
32148 | depth: depth
|
32149 | });
|
32150 | }
|
32151 | }
|
32152 |
|
32153 | function removeElementData(elementData, elementsData) {
|
32154 | var index = elementsData.indexOf(elementData);
|
32155 |
|
32156 | if (index !== -1) {
|
32157 | elementsData.splice(index, 1);
|
32158 | }
|
32159 |
|
32160 | return elementsData;
|
32161 | }
|
32162 |
|
32163 |
|
32164 | eachElement(parents, function(element, _index, depth) {
|
32165 |
|
32166 |
|
32167 | if (isLabel$1(element)) {
|
32168 | return;
|
32169 | }
|
32170 |
|
32171 |
|
32172 | forEach(element.labels, function(label) {
|
32173 | addElementData(label, depth);
|
32174 | });
|
32175 |
|
32176 | function addRelatedElements(elements) {
|
32177 | elements && elements.length && forEach(elements, function(element) {
|
32178 |
|
32179 |
|
32180 | forEach(element.labels, function(label) {
|
32181 | addElementData(label, depth);
|
32182 | });
|
32183 |
|
32184 | addElementData(element, depth);
|
32185 | });
|
32186 | }
|
32187 |
|
32188 | forEach([ element.attachers, element.incoming, element.outgoing ], addRelatedElements);
|
32189 |
|
32190 | addElementData(element, depth);
|
32191 |
|
32192 | return element.children;
|
32193 | });
|
32194 |
|
32195 | elements = map(elementsData, function(elementData) {
|
32196 | return elementData.element;
|
32197 | });
|
32198 |
|
32199 |
|
32200 | elementsData = map(elementsData, function(elementData) {
|
32201 | elementData.descriptor = {};
|
32202 |
|
32203 | self._eventBus.fire('copyPaste.copyElement', {
|
32204 | descriptor: elementData.descriptor,
|
32205 | element: elementData.element,
|
32206 | elements: elements
|
32207 | });
|
32208 |
|
32209 | return elementData;
|
32210 | });
|
32211 |
|
32212 |
|
32213 | elementsData = sortBy(elementsData, function(elementData) {
|
32214 | return elementData.descriptor.priority;
|
32215 | });
|
32216 |
|
32217 | elements = map(elementsData, function(elementData) {
|
32218 | return elementData.element;
|
32219 | });
|
32220 |
|
32221 |
|
32222 | forEach(elementsData, function(elementData) {
|
32223 | var depth = elementData.depth;
|
32224 |
|
32225 | if (!self.hasRelations(elementData.element, elements)) {
|
32226 | removeElement(elementData.element, elements);
|
32227 |
|
32228 | return;
|
32229 | }
|
32230 |
|
32231 | if (!canCopy(elementData.element, elements)) {
|
32232 | removeElement(elementData.element, elements);
|
32233 |
|
32234 | return;
|
32235 | }
|
32236 |
|
32237 | if (!tree[depth]) {
|
32238 | tree[depth] = [];
|
32239 | }
|
32240 |
|
32241 | tree[depth].push(elementData.descriptor);
|
32242 | });
|
32243 |
|
32244 | return tree;
|
32245 | };
|
32246 |
|
32247 |
|
32248 |
|
32249 | function isAttacher(element) {
|
32250 | return !!element.host;
|
32251 | }
|
32252 |
|
32253 | function isConnection$1(element) {
|
32254 | return !!element.waypoints;
|
32255 | }
|
32256 |
|
32257 | function isLabel$1(element) {
|
32258 | return !!element.labelTarget;
|
32259 | }
|
32260 |
|
32261 | function copyWaypoints(element) {
|
32262 | return map(element.waypoints, function(waypoint) {
|
32263 |
|
32264 | waypoint = copyWaypoint(waypoint);
|
32265 |
|
32266 | if (waypoint.original) {
|
32267 | waypoint.original = copyWaypoint(waypoint.original);
|
32268 | }
|
32269 |
|
32270 | return waypoint;
|
32271 | });
|
32272 | }
|
32273 |
|
32274 | function copyWaypoint(waypoint) {
|
32275 | return assign({}, waypoint);
|
32276 | }
|
32277 |
|
32278 | function removeElement(element, elements) {
|
32279 | var index = elements.indexOf(element);
|
32280 |
|
32281 | if (index === -1) {
|
32282 | return elements;
|
32283 | }
|
32284 |
|
32285 | return elements.splice(index, 1);
|
32286 | }
|
32287 |
|
32288 | var CopyPasteModule = {
|
32289 | __depends__: [
|
32290 | ClipboardModule,
|
32291 | CreateModule,
|
32292 | MouseModule,
|
32293 | RulesModule
|
32294 | ],
|
32295 | __init__: [ 'copyPaste' ],
|
32296 | copyPaste: [ 'type', CopyPaste ]
|
32297 | };
|
32298 |
|
32299 | function copyProperties(source, target, properties) {
|
32300 | if (!isArray(properties)) {
|
32301 | properties = [ properties ];
|
32302 | }
|
32303 |
|
32304 | forEach(properties, function(property) {
|
32305 | if (!isUndefined(source[property])) {
|
32306 | target[property] = source[property];
|
32307 | }
|
32308 | });
|
32309 | }
|
32310 |
|
32311 | function removeProperties(element, properties) {
|
32312 | if (!isArray(properties)) {
|
32313 | properties = [ properties ];
|
32314 | }
|
32315 |
|
32316 | forEach(properties, function(property) {
|
32317 | if (element[property]) {
|
32318 | delete element[property];
|
32319 | }
|
32320 | });
|
32321 | }
|
32322 |
|
32323 | var LOW_PRIORITY$6 = 750;
|
32324 |
|
32325 |
|
32326 | function BpmnCopyPaste(bpmnFactory, eventBus, moddleCopy) {
|
32327 |
|
32328 | eventBus.on('copyPaste.copyElement', LOW_PRIORITY$6, function(context) {
|
32329 | var descriptor = context.descriptor,
|
32330 | element = context.element;
|
32331 |
|
32332 | var businessObject = descriptor.oldBusinessObject = getBusinessObject(element);
|
32333 |
|
32334 | descriptor.type = element.type;
|
32335 |
|
32336 | copyProperties(businessObject, descriptor, 'name');
|
32337 |
|
32338 | descriptor.di = {};
|
32339 |
|
32340 |
|
32341 | copyProperties(businessObject.di, descriptor.di, [
|
32342 | 'fill',
|
32343 | 'stroke'
|
32344 | ]);
|
32345 |
|
32346 | copyProperties(businessObject.di, descriptor, 'isExpanded');
|
32347 |
|
32348 | if (isLabel$2(descriptor)) {
|
32349 | return descriptor;
|
32350 | }
|
32351 |
|
32352 |
|
32353 | if (businessObject.default) {
|
32354 | descriptor.default = businessObject.default.id;
|
32355 | }
|
32356 | });
|
32357 |
|
32358 | eventBus.on('moddleCopy.canCopyProperty', function(context) {
|
32359 | var parent = context.parent,
|
32360 | property = context.property,
|
32361 | propertyName = context.propertyName;
|
32362 |
|
32363 | if (is$1(parent, 'bpmn:Participant') &&
|
32364 | is$1(property, 'bpmn:Process') &&
|
32365 | propertyName === 'processRef') {
|
32366 | return bpmnFactory.create('bpmn:Process');
|
32367 | }
|
32368 | });
|
32369 |
|
32370 | var references;
|
32371 |
|
32372 | function resolveReferences(descriptor) {
|
32373 | var businessObject = getBusinessObject(descriptor);
|
32374 |
|
32375 |
|
32376 | if (descriptor.default) {
|
32377 | references[ descriptor.default ] = {
|
32378 | element: businessObject,
|
32379 | property: 'default'
|
32380 | };
|
32381 | }
|
32382 |
|
32383 | references = omit(references, reduce(references, function(array, reference, key) {
|
32384 | var element = reference.element,
|
32385 | property = reference.property;
|
32386 |
|
32387 | if (key === descriptor.id) {
|
32388 | element[ property ] = businessObject;
|
32389 |
|
32390 | array.push(descriptor.id);
|
32391 | }
|
32392 |
|
32393 | return array;
|
32394 | }, []));
|
32395 | }
|
32396 |
|
32397 | eventBus.on('copyPaste.pasteElements', function() {
|
32398 | references = {};
|
32399 | });
|
32400 |
|
32401 | eventBus.on('copyPaste.pasteElement', function(context) {
|
32402 | var cache = context.cache,
|
32403 | descriptor = context.descriptor,
|
32404 | oldBusinessObject = descriptor.oldBusinessObject,
|
32405 | newBusinessObject;
|
32406 |
|
32407 |
|
32408 | if (isLabel$2(descriptor)) {
|
32409 | descriptor.businessObject = getBusinessObject(cache[ descriptor.labelTarget ]);
|
32410 |
|
32411 | return;
|
32412 | }
|
32413 |
|
32414 | newBusinessObject = bpmnFactory.create(oldBusinessObject.$type);
|
32415 |
|
32416 | descriptor.businessObject = moddleCopy.copyElement(
|
32417 | oldBusinessObject,
|
32418 | newBusinessObject
|
32419 | );
|
32420 |
|
32421 |
|
32422 | resolveReferences(descriptor);
|
32423 |
|
32424 | copyProperties(descriptor, newBusinessObject, [
|
32425 | 'isExpanded',
|
32426 | 'name'
|
32427 | ]);
|
32428 |
|
32429 | removeProperties(descriptor, 'oldBusinessObject');
|
32430 | });
|
32431 |
|
32432 | }
|
32433 |
|
32434 |
|
32435 | BpmnCopyPaste.$inject = [
|
32436 | 'bpmnFactory',
|
32437 | 'eventBus',
|
32438 | 'moddleCopy'
|
32439 | ];
|
32440 |
|
32441 |
|
32442 |
|
32443 | function isLabel$2(element) {
|
32444 | return !!element.labelTarget;
|
32445 | }
|
32446 |
|
32447 | var DISALLOWED_PROPERTIES = [
|
32448 | 'artifacts',
|
32449 | 'dataInputAssociations',
|
32450 | 'dataOutputAssociations',
|
32451 | 'default',
|
32452 | 'flowElements',
|
32453 | 'lanes',
|
32454 | 'incoming',
|
32455 | 'outgoing'
|
32456 | ];
|
32457 |
|
32458 | |
32459 |
|
32460 |
|
32461 |
|
32462 |
|
32463 |
|
32464 |
|
32465 |
|
32466 |
|
32467 |
|
32468 |
|
32469 |
|
32470 | |
32471 |
|
32472 |
|
32473 |
|
32474 |
|
32475 |
|
32476 |
|
32477 |
|
32478 |
|
32479 |
|
32480 |
|
32481 |
|
32482 | |
32483 |
|
32484 |
|
32485 |
|
32486 |
|
32487 |
|
32488 |
|
32489 |
|
32490 |
|
32491 |
|
32492 |
|
32493 |
|
32494 | |
32495 |
|
32496 |
|
32497 |
|
32498 |
|
32499 |
|
32500 |
|
32501 | function ModdleCopy(eventBus, bpmnFactory, moddle) {
|
32502 | this._bpmnFactory = bpmnFactory;
|
32503 | this._eventBus = eventBus;
|
32504 | this._moddle = moddle;
|
32505 |
|
32506 |
|
32507 | eventBus.on('moddleCopy.canCopyProperties', function(context) {
|
32508 | var propertyNames = context.propertyNames;
|
32509 |
|
32510 | if (!propertyNames || !propertyNames.length) {
|
32511 | return;
|
32512 | }
|
32513 |
|
32514 | return sortBy(propertyNames, function(propertyName) {
|
32515 | return propertyName === 'extensionElements';
|
32516 | });
|
32517 | });
|
32518 |
|
32519 |
|
32520 | eventBus.on('moddleCopy.canCopyProperty', function(context) {
|
32521 | var parent = context.parent,
|
32522 | parentDescriptor = isObject(parent) && parent.$descriptor,
|
32523 | propertyName = context.propertyName;
|
32524 |
|
32525 | if (propertyName && DISALLOWED_PROPERTIES.indexOf(propertyName) !== -1) {
|
32526 |
|
32527 |
|
32528 | return false;
|
32529 | }
|
32530 |
|
32531 | if (propertyName &&
|
32532 | parentDescriptor &&
|
32533 | !find(parentDescriptor.properties, matchPattern({ name: propertyName }))) {
|
32534 |
|
32535 |
|
32536 | return false;
|
32537 | }
|
32538 | });
|
32539 |
|
32540 |
|
32541 | eventBus.on('moddleCopy.canSetCopiedProperty', function(context) {
|
32542 | var property = context.property;
|
32543 |
|
32544 | if (is$3(property, 'bpmn:ExtensionElements') && (!property.values || !property.values.length)) {
|
32545 |
|
32546 |
|
32547 | return false;
|
32548 | }
|
32549 | });
|
32550 | }
|
32551 |
|
32552 | ModdleCopy.$inject = [
|
32553 | 'eventBus',
|
32554 | 'bpmnFactory',
|
32555 | 'moddle'
|
32556 | ];
|
32557 |
|
32558 | |
32559 |
|
32560 |
|
32561 |
|
32562 |
|
32563 |
|
32564 |
|
32565 |
|
32566 |
|
32567 | ModdleCopy.prototype.copyElement = function(sourceElement, targetElement, propertyNames) {
|
32568 | var self = this;
|
32569 |
|
32570 | if (propertyNames && !isArray(propertyNames)) {
|
32571 | propertyNames = [ propertyNames ];
|
32572 | }
|
32573 |
|
32574 | propertyNames = propertyNames || getPropertyNames(sourceElement.$descriptor);
|
32575 |
|
32576 | var canCopyProperties = this._eventBus.fire('moddleCopy.canCopyProperties', {
|
32577 | propertyNames: propertyNames,
|
32578 | sourceElement: sourceElement,
|
32579 | targetElement: targetElement
|
32580 | });
|
32581 |
|
32582 | if (canCopyProperties === false) {
|
32583 | return targetElement;
|
32584 | }
|
32585 |
|
32586 | if (isArray(canCopyProperties)) {
|
32587 | propertyNames = canCopyProperties;
|
32588 | }
|
32589 |
|
32590 |
|
32591 | forEach(propertyNames, function(propertyName) {
|
32592 | var sourceProperty;
|
32593 |
|
32594 | if (has(sourceElement, propertyName)) {
|
32595 | sourceProperty = sourceElement.get(propertyName);
|
32596 | }
|
32597 |
|
32598 | var copiedProperty = self.copyProperty(sourceProperty, targetElement, propertyName);
|
32599 |
|
32600 | var canSetProperty = self._eventBus.fire('moddleCopy.canSetCopiedProperty', {
|
32601 | parent: parent,
|
32602 | property: copiedProperty,
|
32603 | propertyName: propertyName
|
32604 | });
|
32605 |
|
32606 | if (canSetProperty === false) {
|
32607 | return;
|
32608 | }
|
32609 |
|
32610 | if (isDefined(copiedProperty)) {
|
32611 | targetElement.set(propertyName, copiedProperty);
|
32612 | }
|
32613 | });
|
32614 |
|
32615 | return targetElement;
|
32616 | };
|
32617 |
|
32618 | |
32619 |
|
32620 |
|
32621 |
|
32622 |
|
32623 |
|
32624 |
|
32625 |
|
32626 |
|
32627 | ModdleCopy.prototype.copyProperty = function(property, parent, propertyName) {
|
32628 | var self = this;
|
32629 |
|
32630 |
|
32631 | var copiedProperty = this._eventBus.fire('moddleCopy.canCopyProperty', {
|
32632 | parent: parent,
|
32633 | property: property,
|
32634 | propertyName: propertyName
|
32635 | });
|
32636 |
|
32637 |
|
32638 | if (copiedProperty === false) {
|
32639 | return;
|
32640 | }
|
32641 |
|
32642 | if (copiedProperty) {
|
32643 | if (isObject(copiedProperty) && copiedProperty.$type && !copiedProperty.$parent) {
|
32644 | copiedProperty.$parent = parent;
|
32645 | }
|
32646 |
|
32647 | return copiedProperty;
|
32648 | }
|
32649 |
|
32650 | var propertyDescriptor = this._moddle.getPropertyDescriptor(parent, propertyName);
|
32651 |
|
32652 |
|
32653 | if (propertyDescriptor.isId || propertyDescriptor.isReference) {
|
32654 | return;
|
32655 | }
|
32656 |
|
32657 |
|
32658 | if (isArray(property)) {
|
32659 | return reduce(property, function(childProperties, childProperty) {
|
32660 |
|
32661 |
|
32662 | copiedProperty = self.copyProperty(childProperty, parent, propertyName);
|
32663 |
|
32664 |
|
32665 | if (copiedProperty) {
|
32666 | copiedProperty.$parent = parent;
|
32667 |
|
32668 | return childProperties.concat(copiedProperty);
|
32669 | }
|
32670 |
|
32671 | return childProperties;
|
32672 | }, []);
|
32673 | }
|
32674 |
|
32675 |
|
32676 | if (isObject(property) && property.$type) {
|
32677 | copiedProperty = self._bpmnFactory.create(property.$type);
|
32678 |
|
32679 | copiedProperty.$parent = parent;
|
32680 |
|
32681 |
|
32682 | copiedProperty = self.copyElement(property, copiedProperty);
|
32683 |
|
32684 | return copiedProperty;
|
32685 | }
|
32686 |
|
32687 |
|
32688 | return property;
|
32689 | };
|
32690 |
|
32691 |
|
32692 |
|
32693 | function getPropertyNames(descriptor, keepDefaultProperties) {
|
32694 | return reduce(descriptor.properties, function(properties, property) {
|
32695 |
|
32696 | if (keepDefaultProperties && property.default) {
|
32697 | return properties;
|
32698 | }
|
32699 |
|
32700 | return properties.concat(property.name);
|
32701 | }, []);
|
32702 | }
|
32703 |
|
32704 | function is$3(element, type) {
|
32705 | return element && (typeof element.$instanceOf === 'function') && element.$instanceOf(type);
|
32706 | }
|
32707 |
|
32708 | var CopyPasteModule$1 = {
|
32709 | __depends__: [
|
32710 | CopyPasteModule
|
32711 | ],
|
32712 | __init__: [ 'bpmnCopyPaste', 'moddleCopy' ],
|
32713 | bpmnCopyPaste: [ 'type', BpmnCopyPaste ],
|
32714 | moddleCopy: [ 'type', ModdleCopy ]
|
32715 | };
|
32716 |
|
32717 | var round$6 = Math.round;
|
32718 |
|
32719 | |
32720 |
|
32721 |
|
32722 | function Replace(modeling) {
|
32723 |
|
32724 | this._modeling = modeling;
|
32725 | }
|
32726 |
|
32727 | Replace.$inject = [ 'modeling' ];
|
32728 |
|
32729 | |
32730 |
|
32731 |
|
32732 |
|
32733 |
|
32734 |
|
32735 |
|
32736 |
|
32737 | Replace.prototype.replaceElement = function(oldElement, newElementData, options) {
|
32738 |
|
32739 | var modeling = this._modeling;
|
32740 |
|
32741 | var newElement = null;
|
32742 |
|
32743 | if (oldElement.waypoints) ; else {
|
32744 |
|
32745 |
|
32746 |
|
32747 | newElementData.x = round$6(oldElement.x + (newElementData.width || oldElement.width) / 2);
|
32748 | newElementData.y = round$6(oldElement.y + (newElementData.height || oldElement.height) / 2);
|
32749 |
|
32750 | newElement = modeling.replaceShape(oldElement, newElementData, options);
|
32751 | }
|
32752 |
|
32753 | return newElement;
|
32754 | };
|
32755 |
|
32756 | var ReplaceModule = {
|
32757 | __init__: [ 'replace' ],
|
32758 | replace: [ 'type', Replace ]
|
32759 | };
|
32760 |
|
32761 | function copyProperties$1(source, target, properties) {
|
32762 | if (!isArray(properties)) {
|
32763 | properties = [ properties ];
|
32764 | }
|
32765 |
|
32766 | forEach(properties, function(property) {
|
32767 | if (!isUndefined(source[property])) {
|
32768 | target[property] = source[property];
|
32769 | }
|
32770 | });
|
32771 | }
|
32772 |
|
32773 | var CUSTOM_PROPERTIES = [
|
32774 | 'cancelActivity',
|
32775 | 'instantiate',
|
32776 | 'eventGatewayType',
|
32777 | 'triggeredByEvent',
|
32778 | 'isInterrupting'
|
32779 | ];
|
32780 |
|
32781 |
|
32782 | function toggeling(element, target) {
|
32783 |
|
32784 | var oldCollapsed = (
|
32785 | element && has(element, 'collapsed') ? element.collapsed : !isExpanded(element)
|
32786 | );
|
32787 |
|
32788 | var targetCollapsed;
|
32789 |
|
32790 | if (target && (has(target, 'collapsed') || has(target, 'isExpanded'))) {
|
32791 |
|
32792 |
|
32793 | targetCollapsed = (
|
32794 | has(target, 'collapsed') ? target.collapsed : !target.isExpanded
|
32795 | );
|
32796 | } else {
|
32797 |
|
32798 |
|
32799 | targetCollapsed = oldCollapsed;
|
32800 | }
|
32801 |
|
32802 | if (oldCollapsed !== targetCollapsed) {
|
32803 | element.collapsed = oldCollapsed;
|
32804 | return true;
|
32805 | }
|
32806 |
|
32807 | return false;
|
32808 | }
|
32809 |
|
32810 |
|
32811 |
|
32812 | |
32813 |
|
32814 |
|
32815 | function BpmnReplace(
|
32816 | bpmnFactory,
|
32817 | elementFactory,
|
32818 | moddleCopy,
|
32819 | modeling,
|
32820 | replace,
|
32821 | selection
|
32822 | ) {
|
32823 |
|
32824 | |
32825 |
|
32826 |
|
32827 |
|
32828 |
|
32829 |
|
32830 |
|
32831 |
|
32832 |
|
32833 |
|
32834 | function replaceElement(element, target, hints) {
|
32835 |
|
32836 | hints = hints || {};
|
32837 |
|
32838 | var type = target.type,
|
32839 | oldBusinessObject = element.businessObject;
|
32840 |
|
32841 | if (isSubProcess(oldBusinessObject)) {
|
32842 | if (type === 'bpmn:SubProcess') {
|
32843 | if (toggeling(element, target)) {
|
32844 |
|
32845 |
|
32846 | modeling.toggleCollapse(element);
|
32847 |
|
32848 | return element;
|
32849 | }
|
32850 | }
|
32851 | }
|
32852 |
|
32853 | var newBusinessObject = bpmnFactory.create(type);
|
32854 |
|
32855 | var newElement = {
|
32856 | type: type,
|
32857 | businessObject: newBusinessObject
|
32858 | };
|
32859 |
|
32860 | var elementProps = getPropertyNames(oldBusinessObject.$descriptor),
|
32861 | newElementProps = getPropertyNames(newBusinessObject.$descriptor, true),
|
32862 | copyProps = intersection(elementProps, newElementProps);
|
32863 |
|
32864 |
|
32865 | assign(newBusinessObject, pick(target, CUSTOM_PROPERTIES));
|
32866 |
|
32867 | var properties = filter(copyProps, function(propertyName) {
|
32868 |
|
32869 |
|
32870 | if (propertyName === 'eventDefinitions') {
|
32871 | return hasEventDefinition$1(element, target.eventDefinitionType);
|
32872 | }
|
32873 |
|
32874 |
|
32875 |
|
32876 | if (propertyName === 'loopCharacteristics') {
|
32877 | return !isEventSubProcess(newBusinessObject);
|
32878 | }
|
32879 |
|
32880 |
|
32881 | if (newBusinessObject.hasOwnProperty(propertyName)) {
|
32882 | return false;
|
32883 | }
|
32884 |
|
32885 | if (propertyName === 'processRef' && target.isExpanded === false) {
|
32886 | return false;
|
32887 | }
|
32888 |
|
32889 | if (propertyName === 'triggeredByEvent') {
|
32890 | return false;
|
32891 | }
|
32892 |
|
32893 | return true;
|
32894 | });
|
32895 |
|
32896 | newBusinessObject = moddleCopy.copyElement(
|
32897 | oldBusinessObject,
|
32898 | newBusinessObject,
|
32899 | properties
|
32900 | );
|
32901 |
|
32902 |
|
32903 | if (target.eventDefinitionType) {
|
32904 |
|
32905 |
|
32906 |
|
32907 |
|
32908 | if (!hasEventDefinition$1(newBusinessObject, target.eventDefinitionType)) {
|
32909 | newElement.eventDefinitionType = target.eventDefinitionType;
|
32910 | }
|
32911 | }
|
32912 |
|
32913 | if (is$1(oldBusinessObject, 'bpmn:Activity')) {
|
32914 |
|
32915 | if (isSubProcess(oldBusinessObject)) {
|
32916 |
|
32917 |
|
32918 | newElement.isExpanded = isExpanded(oldBusinessObject);
|
32919 | }
|
32920 |
|
32921 |
|
32922 | else if (target && has(target, 'isExpanded')) {
|
32923 | newElement.isExpanded = target.isExpanded;
|
32924 | }
|
32925 |
|
32926 |
|
32927 |
|
32928 |
|
32929 | if ((isExpanded(oldBusinessObject) && !is$1(oldBusinessObject, 'bpmn:Task')) && newElement.isExpanded) {
|
32930 | newElement.width = element.width;
|
32931 | newElement.height = element.height;
|
32932 | }
|
32933 | }
|
32934 |
|
32935 |
|
32936 | if (isSubProcess(oldBusinessObject) && !isSubProcess(newBusinessObject)) {
|
32937 | hints.moveChildren = false;
|
32938 | }
|
32939 |
|
32940 |
|
32941 | if (is$1(oldBusinessObject, 'bpmn:Participant')) {
|
32942 |
|
32943 |
|
32944 | if (target.isExpanded === true) {
|
32945 | newBusinessObject.processRef = bpmnFactory.create('bpmn:Process');
|
32946 | } else {
|
32947 |
|
32948 |
|
32949 | hints.moveChildren = false;
|
32950 | }
|
32951 |
|
32952 |
|
32953 | newElement.width = element.width;
|
32954 | newElement.height = elementFactory._getDefaultSize(newBusinessObject).height;
|
32955 | }
|
32956 |
|
32957 | newBusinessObject.name = oldBusinessObject.name;
|
32958 |
|
32959 |
|
32960 | if (
|
32961 | isAny(oldBusinessObject, [
|
32962 | 'bpmn:ExclusiveGateway',
|
32963 | 'bpmn:InclusiveGateway',
|
32964 | 'bpmn:Activity'
|
32965 | ]) &&
|
32966 | isAny(newBusinessObject, [
|
32967 | 'bpmn:ExclusiveGateway',
|
32968 | 'bpmn:InclusiveGateway',
|
32969 | 'bpmn:Activity'
|
32970 | ])
|
32971 | ) {
|
32972 | newBusinessObject.default = oldBusinessObject.default;
|
32973 | }
|
32974 |
|
32975 | if (
|
32976 | target.host &&
|
32977 | !is$1(oldBusinessObject, 'bpmn:BoundaryEvent') &&
|
32978 | is$1(newBusinessObject, 'bpmn:BoundaryEvent')
|
32979 | ) {
|
32980 | newElement.host = target.host;
|
32981 | }
|
32982 |
|
32983 | newElement.di = {};
|
32984 |
|
32985 |
|
32986 | copyProperties$1(oldBusinessObject.di, newElement.di, [
|
32987 | 'fill',
|
32988 | 'stroke'
|
32989 | ]);
|
32990 |
|
32991 | newElement = replace.replaceElement(element, newElement, hints);
|
32992 |
|
32993 | if (hints.select !== false) {
|
32994 | selection.select(newElement);
|
32995 | }
|
32996 |
|
32997 | return newElement;
|
32998 | }
|
32999 |
|
33000 | this.replaceElement = replaceElement;
|
33001 | }
|
33002 |
|
33003 | BpmnReplace.$inject = [
|
33004 | 'bpmnFactory',
|
33005 | 'elementFactory',
|
33006 | 'moddleCopy',
|
33007 | 'modeling',
|
33008 | 'replace',
|
33009 | 'selection'
|
33010 | ];
|
33011 |
|
33012 |
|
33013 | function isSubProcess(bo) {
|
33014 | return is$1(bo, 'bpmn:SubProcess');
|
33015 | }
|
33016 |
|
33017 | function hasEventDefinition$1(element, type) {
|
33018 |
|
33019 | var bo = getBusinessObject(element);
|
33020 |
|
33021 | return type && bo.get('eventDefinitions').some(function(definition) {
|
33022 | return is$1(definition, type);
|
33023 | });
|
33024 | }
|
33025 |
|
33026 | |
33027 |
|
33028 |
|
33029 | function intersection(a1, a2) {
|
33030 | return a1.filter(function(el) {
|
33031 | return a2.indexOf(el) !== -1;
|
33032 | });
|
33033 | }
|
33034 |
|
33035 | var ReplaceModule$1 = {
|
33036 | __depends__: [
|
33037 | CopyPasteModule$1,
|
33038 | ReplaceModule,
|
33039 | SelectionModule
|
33040 | ],
|
33041 | bpmnReplace: [ 'type', BpmnReplace ]
|
33042 | };
|
33043 |
|
33044 | |
33045 |
|
33046 |
|
33047 |
|
33048 |
|
33049 |
|
33050 |
|
33051 |
|
33052 |
|
33053 | function isDifferentType(element) {
|
33054 |
|
33055 | return function(entry) {
|
33056 | var target = entry.target;
|
33057 |
|
33058 | var businessObject = getBusinessObject(element),
|
33059 | eventDefinition = businessObject.eventDefinitions && businessObject.eventDefinitions[0];
|
33060 |
|
33061 | var isTypeEqual = businessObject.$type === target.type;
|
33062 |
|
33063 | var isEventDefinitionEqual = (
|
33064 | (eventDefinition && eventDefinition.$type) === target.eventDefinitionType
|
33065 | );
|
33066 |
|
33067 | var isTriggeredByEventEqual = (
|
33068 | businessObject.triggeredByEvent === target.triggeredByEvent
|
33069 | );
|
33070 |
|
33071 | var isExpandedEqual = (
|
33072 | target.isExpanded === undefined ||
|
33073 | target.isExpanded === isExpanded(businessObject)
|
33074 | );
|
33075 |
|
33076 | return !isTypeEqual || !isEventDefinitionEqual || !isTriggeredByEventEqual || !isExpandedEqual;
|
33077 | };
|
33078 | }
|
33079 |
|
33080 | var START_EVENT = [
|
33081 | {
|
33082 | label: 'Start Event',
|
33083 | actionName: 'replace-with-none-start',
|
33084 | className: 'bpmn-icon-start-event-none',
|
33085 | target: {
|
33086 | type: 'bpmn:StartEvent'
|
33087 | }
|
33088 | },
|
33089 | {
|
33090 | label: 'Intermediate Throw Event',
|
33091 | actionName: 'replace-with-none-intermediate-throwing',
|
33092 | className: 'bpmn-icon-intermediate-event-none',
|
33093 | target: {
|
33094 | type: 'bpmn:IntermediateThrowEvent'
|
33095 | }
|
33096 | },
|
33097 | {
|
33098 | label: 'End Event',
|
33099 | actionName: 'replace-with-none-end',
|
33100 | className: 'bpmn-icon-end-event-none',
|
33101 | target: {
|
33102 | type: 'bpmn:EndEvent'
|
33103 | }
|
33104 | },
|
33105 | {
|
33106 | label: 'Message Start Event',
|
33107 | actionName: 'replace-with-message-start',
|
33108 | className: 'bpmn-icon-start-event-message',
|
33109 | target: {
|
33110 | type: 'bpmn:StartEvent',
|
33111 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
33112 | }
|
33113 | },
|
33114 | {
|
33115 | label: 'Timer Start Event',
|
33116 | actionName: 'replace-with-timer-start',
|
33117 | className: 'bpmn-icon-start-event-timer',
|
33118 | target: {
|
33119 | type: 'bpmn:StartEvent',
|
33120 | eventDefinitionType: 'bpmn:TimerEventDefinition'
|
33121 | }
|
33122 | },
|
33123 | {
|
33124 | label: 'Conditional Start Event',
|
33125 | actionName: 'replace-with-conditional-start',
|
33126 | className: 'bpmn-icon-start-event-condition',
|
33127 | target: {
|
33128 | type: 'bpmn:StartEvent',
|
33129 | eventDefinitionType: 'bpmn:ConditionalEventDefinition'
|
33130 | }
|
33131 | },
|
33132 | {
|
33133 | label: 'Signal Start Event',
|
33134 | actionName: 'replace-with-signal-start',
|
33135 | className: 'bpmn-icon-start-event-signal',
|
33136 | target: {
|
33137 | type: 'bpmn:StartEvent',
|
33138 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
33139 | }
|
33140 | }
|
33141 | ];
|
33142 |
|
33143 | var INTERMEDIATE_EVENT = [
|
33144 | {
|
33145 | label: 'Start Event',
|
33146 | actionName: 'replace-with-none-start',
|
33147 | className: 'bpmn-icon-start-event-none',
|
33148 | target: {
|
33149 | type: 'bpmn:StartEvent'
|
33150 | }
|
33151 | },
|
33152 | {
|
33153 | label: 'Intermediate Throw Event',
|
33154 | actionName: 'replace-with-none-intermediate-throw',
|
33155 | className: 'bpmn-icon-intermediate-event-none',
|
33156 | target: {
|
33157 | type: 'bpmn:IntermediateThrowEvent'
|
33158 | }
|
33159 | },
|
33160 | {
|
33161 | label: 'End Event',
|
33162 | actionName: 'replace-with-none-end',
|
33163 | className: 'bpmn-icon-end-event-none',
|
33164 | target: {
|
33165 | type: 'bpmn:EndEvent'
|
33166 | }
|
33167 | },
|
33168 | {
|
33169 | label: 'Message Intermediate Catch Event',
|
33170 | actionName: 'replace-with-message-intermediate-catch',
|
33171 | className: 'bpmn-icon-intermediate-event-catch-message',
|
33172 | target: {
|
33173 | type: 'bpmn:IntermediateCatchEvent',
|
33174 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
33175 | }
|
33176 | },
|
33177 | {
|
33178 | label: 'Message Intermediate Throw Event',
|
33179 | actionName: 'replace-with-message-intermediate-throw',
|
33180 | className: 'bpmn-icon-intermediate-event-throw-message',
|
33181 | target: {
|
33182 | type: 'bpmn:IntermediateThrowEvent',
|
33183 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
33184 | }
|
33185 | },
|
33186 | {
|
33187 | label: 'Timer Intermediate Catch Event',
|
33188 | actionName: 'replace-with-timer-intermediate-catch',
|
33189 | className: 'bpmn-icon-intermediate-event-catch-timer',
|
33190 | target: {
|
33191 | type: 'bpmn:IntermediateCatchEvent',
|
33192 | eventDefinitionType: 'bpmn:TimerEventDefinition'
|
33193 | }
|
33194 | },
|
33195 | {
|
33196 | label: 'Escalation Intermediate Throw Event',
|
33197 | actionName: 'replace-with-escalation-intermediate-throw',
|
33198 | className: 'bpmn-icon-intermediate-event-throw-escalation',
|
33199 | target: {
|
33200 | type: 'bpmn:IntermediateThrowEvent',
|
33201 | eventDefinitionType: 'bpmn:EscalationEventDefinition'
|
33202 | }
|
33203 | },
|
33204 | {
|
33205 | label: 'Conditional Intermediate Catch Event',
|
33206 | actionName: 'replace-with-conditional-intermediate-catch',
|
33207 | className: 'bpmn-icon-intermediate-event-catch-condition',
|
33208 | target: {
|
33209 | type: 'bpmn:IntermediateCatchEvent',
|
33210 | eventDefinitionType: 'bpmn:ConditionalEventDefinition'
|
33211 | }
|
33212 | },
|
33213 | {
|
33214 | label: 'Link Intermediate Catch Event',
|
33215 | actionName: 'replace-with-link-intermediate-catch',
|
33216 | className: 'bpmn-icon-intermediate-event-catch-link',
|
33217 | target: {
|
33218 | type: 'bpmn:IntermediateCatchEvent',
|
33219 | eventDefinitionType: 'bpmn:LinkEventDefinition'
|
33220 | }
|
33221 | },
|
33222 | {
|
33223 | label: 'Link Intermediate Throw Event',
|
33224 | actionName: 'replace-with-link-intermediate-throw',
|
33225 | className: 'bpmn-icon-intermediate-event-throw-link',
|
33226 | target: {
|
33227 | type: 'bpmn:IntermediateThrowEvent',
|
33228 | eventDefinitionType: 'bpmn:LinkEventDefinition'
|
33229 | }
|
33230 | },
|
33231 | {
|
33232 | label: 'Compensation Intermediate Throw Event',
|
33233 | actionName: 'replace-with-compensation-intermediate-throw',
|
33234 | className: 'bpmn-icon-intermediate-event-throw-compensation',
|
33235 | target: {
|
33236 | type: 'bpmn:IntermediateThrowEvent',
|
33237 | eventDefinitionType: 'bpmn:CompensateEventDefinition'
|
33238 | }
|
33239 | },
|
33240 | {
|
33241 | label: 'Signal Intermediate Catch Event',
|
33242 | actionName: 'replace-with-signal-intermediate-catch',
|
33243 | className: 'bpmn-icon-intermediate-event-catch-signal',
|
33244 | target: {
|
33245 | type: 'bpmn:IntermediateCatchEvent',
|
33246 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
33247 | }
|
33248 | },
|
33249 | {
|
33250 | label: 'Signal Intermediate Throw Event',
|
33251 | actionName: 'replace-with-signal-intermediate-throw',
|
33252 | className: 'bpmn-icon-intermediate-event-throw-signal',
|
33253 | target: {
|
33254 | type: 'bpmn:IntermediateThrowEvent',
|
33255 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
33256 | }
|
33257 | }
|
33258 | ];
|
33259 |
|
33260 | var END_EVENT = [
|
33261 | {
|
33262 | label: 'Start Event',
|
33263 | actionName: 'replace-with-none-start',
|
33264 | className: 'bpmn-icon-start-event-none',
|
33265 | target: {
|
33266 | type: 'bpmn:StartEvent'
|
33267 | }
|
33268 | },
|
33269 | {
|
33270 | label: 'Intermediate Throw Event',
|
33271 | actionName: 'replace-with-none-intermediate-throw',
|
33272 | className: 'bpmn-icon-intermediate-event-none',
|
33273 | target: {
|
33274 | type: 'bpmn:IntermediateThrowEvent'
|
33275 | }
|
33276 | },
|
33277 | {
|
33278 | label: 'End Event',
|
33279 | actionName: 'replace-with-none-end',
|
33280 | className: 'bpmn-icon-end-event-none',
|
33281 | target: {
|
33282 | type: 'bpmn:EndEvent'
|
33283 | }
|
33284 | },
|
33285 | {
|
33286 | label: 'Message End Event',
|
33287 | actionName: 'replace-with-message-end',
|
33288 | className: 'bpmn-icon-end-event-message',
|
33289 | target: {
|
33290 | type: 'bpmn:EndEvent',
|
33291 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
33292 | }
|
33293 | },
|
33294 | {
|
33295 | label: 'Escalation End Event',
|
33296 | actionName: 'replace-with-escalation-end',
|
33297 | className: 'bpmn-icon-end-event-escalation',
|
33298 | target: {
|
33299 | type: 'bpmn:EndEvent',
|
33300 | eventDefinitionType: 'bpmn:EscalationEventDefinition'
|
33301 | }
|
33302 | },
|
33303 | {
|
33304 | label: 'Error End Event',
|
33305 | actionName: 'replace-with-error-end',
|
33306 | className: 'bpmn-icon-end-event-error',
|
33307 | target: {
|
33308 | type: 'bpmn:EndEvent',
|
33309 | eventDefinitionType: 'bpmn:ErrorEventDefinition'
|
33310 | }
|
33311 | },
|
33312 | {
|
33313 | label: 'Cancel End Event',
|
33314 | actionName: 'replace-with-cancel-end',
|
33315 | className: 'bpmn-icon-end-event-cancel',
|
33316 | target: {
|
33317 | type: 'bpmn:EndEvent',
|
33318 | eventDefinitionType: 'bpmn:CancelEventDefinition'
|
33319 | }
|
33320 | },
|
33321 | {
|
33322 | label: 'Compensation End Event',
|
33323 | actionName: 'replace-with-compensation-end',
|
33324 | className: 'bpmn-icon-end-event-compensation',
|
33325 | target: {
|
33326 | type: 'bpmn:EndEvent',
|
33327 | eventDefinitionType: 'bpmn:CompensateEventDefinition'
|
33328 | }
|
33329 | },
|
33330 | {
|
33331 | label: 'Signal End Event',
|
33332 | actionName: 'replace-with-signal-end',
|
33333 | className: 'bpmn-icon-end-event-signal',
|
33334 | target: {
|
33335 | type: 'bpmn:EndEvent',
|
33336 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
33337 | }
|
33338 | },
|
33339 | {
|
33340 | label: 'Terminate End Event',
|
33341 | actionName: 'replace-with-terminate-end',
|
33342 | className: 'bpmn-icon-end-event-terminate',
|
33343 | target: {
|
33344 | type: 'bpmn:EndEvent',
|
33345 | eventDefinitionType: 'bpmn:TerminateEventDefinition'
|
33346 | }
|
33347 | }
|
33348 | ];
|
33349 |
|
33350 | var GATEWAY = [
|
33351 | {
|
33352 | label: 'Exclusive Gateway',
|
33353 | actionName: 'replace-with-exclusive-gateway',
|
33354 | className: 'bpmn-icon-gateway-xor',
|
33355 | target: {
|
33356 | type: 'bpmn:ExclusiveGateway'
|
33357 | }
|
33358 | },
|
33359 | {
|
33360 | label: 'Parallel Gateway',
|
33361 | actionName: 'replace-with-parallel-gateway',
|
33362 | className: 'bpmn-icon-gateway-parallel',
|
33363 | target: {
|
33364 | type: 'bpmn:ParallelGateway'
|
33365 | }
|
33366 | },
|
33367 | {
|
33368 | label: 'Inclusive Gateway',
|
33369 | actionName: 'replace-with-inclusive-gateway',
|
33370 | className: 'bpmn-icon-gateway-or',
|
33371 | target: {
|
33372 | type: 'bpmn:InclusiveGateway'
|
33373 | }
|
33374 | },
|
33375 | {
|
33376 | label: 'Complex Gateway',
|
33377 | actionName: 'replace-with-complex-gateway',
|
33378 | className: 'bpmn-icon-gateway-complex',
|
33379 | target: {
|
33380 | type: 'bpmn:ComplexGateway'
|
33381 | }
|
33382 | },
|
33383 | {
|
33384 | label: 'Event based Gateway',
|
33385 | actionName: 'replace-with-event-based-gateway',
|
33386 | className: 'bpmn-icon-gateway-eventbased',
|
33387 | target: {
|
33388 | type: 'bpmn:EventBasedGateway',
|
33389 | instantiate: false,
|
33390 | eventGatewayType: 'Exclusive'
|
33391 | }
|
33392 | }
|
33393 |
|
33394 |
|
33395 |
|
33396 |
|
33397 |
|
33398 |
|
33399 |
|
33400 |
|
33401 |
|
33402 |
|
33403 |
|
33404 |
|
33405 |
|
33406 |
|
33407 |
|
33408 |
|
33409 |
|
33410 |
|
33411 |
|
33412 |
|
33413 |
|
33414 |
|
33415 |
|
33416 |
|
33417 | ];
|
33418 |
|
33419 | var SUBPROCESS_EXPANDED = [
|
33420 | {
|
33421 | label: 'Transaction',
|
33422 | actionName: 'replace-with-transaction',
|
33423 | className: 'bpmn-icon-transaction',
|
33424 | target: {
|
33425 | type: 'bpmn:Transaction',
|
33426 | isExpanded: true
|
33427 | }
|
33428 | },
|
33429 | {
|
33430 | label: 'Event Sub Process',
|
33431 | actionName: 'replace-with-event-subprocess',
|
33432 | className: 'bpmn-icon-event-subprocess-expanded',
|
33433 | target: {
|
33434 | type: 'bpmn:SubProcess',
|
33435 | triggeredByEvent: true,
|
33436 | isExpanded: true
|
33437 | }
|
33438 | },
|
33439 | {
|
33440 | label: 'Sub Process (collapsed)',
|
33441 | actionName: 'replace-with-collapsed-subprocess',
|
33442 | className: 'bpmn-icon-subprocess-collapsed',
|
33443 | target: {
|
33444 | type: 'bpmn:SubProcess',
|
33445 | isExpanded: false
|
33446 | }
|
33447 | }
|
33448 | ];
|
33449 |
|
33450 | var TRANSACTION = [
|
33451 | {
|
33452 | label: 'Sub Process',
|
33453 | actionName: 'replace-with-subprocess',
|
33454 | className: 'bpmn-icon-subprocess-expanded',
|
33455 | target: {
|
33456 | type: 'bpmn:SubProcess',
|
33457 | isExpanded: true
|
33458 | }
|
33459 | },
|
33460 | {
|
33461 | label: 'Event Sub Process',
|
33462 | actionName: 'replace-with-event-subprocess',
|
33463 | className: 'bpmn-icon-event-subprocess-expanded',
|
33464 | target: {
|
33465 | type: 'bpmn:SubProcess',
|
33466 | triggeredByEvent: true,
|
33467 | isExpanded: true
|
33468 | }
|
33469 | }
|
33470 | ];
|
33471 |
|
33472 | var EVENT_SUB_PROCESS = [
|
33473 | {
|
33474 | label: 'Sub Process',
|
33475 | actionName: 'replace-with-subprocess',
|
33476 | className: 'bpmn-icon-subprocess-expanded',
|
33477 | target: {
|
33478 | type: 'bpmn:SubProcess',
|
33479 | isExpanded: true
|
33480 | }
|
33481 | },
|
33482 | {
|
33483 | label: 'Transaction',
|
33484 | actionName: 'replace-with-transaction',
|
33485 | className: 'bpmn-icon-transaction',
|
33486 | target: {
|
33487 | type: 'bpmn:Transaction',
|
33488 | isExpanded: true
|
33489 | }
|
33490 | }
|
33491 | ];
|
33492 |
|
33493 | var TASK = [
|
33494 | {
|
33495 | label: 'Task',
|
33496 | actionName: 'replace-with-task',
|
33497 | className: 'bpmn-icon-task',
|
33498 | target: {
|
33499 | type: 'bpmn:Task'
|
33500 | }
|
33501 | },
|
33502 | {
|
33503 | label: 'Send Task',
|
33504 | actionName: 'replace-with-send-task',
|
33505 | className: 'bpmn-icon-send',
|
33506 | target: {
|
33507 | type: 'bpmn:SendTask'
|
33508 | }
|
33509 | },
|
33510 | {
|
33511 | label: 'Receive Task',
|
33512 | actionName: 'replace-with-receive-task',
|
33513 | className: 'bpmn-icon-receive',
|
33514 | target: {
|
33515 | type: 'bpmn:ReceiveTask'
|
33516 | }
|
33517 | },
|
33518 | {
|
33519 | label: 'User Task',
|
33520 | actionName: 'replace-with-user-task',
|
33521 | className: 'bpmn-icon-user',
|
33522 | target: {
|
33523 | type: 'bpmn:UserTask'
|
33524 | }
|
33525 | },
|
33526 | {
|
33527 | label: 'Manual Task',
|
33528 | actionName: 'replace-with-manual-task',
|
33529 | className: 'bpmn-icon-manual',
|
33530 | target: {
|
33531 | type: 'bpmn:ManualTask'
|
33532 | }
|
33533 | },
|
33534 | {
|
33535 | label: 'Business Rule Task',
|
33536 | actionName: 'replace-with-rule-task',
|
33537 | className: 'bpmn-icon-business-rule',
|
33538 | target: {
|
33539 | type: 'bpmn:BusinessRuleTask'
|
33540 | }
|
33541 | },
|
33542 | {
|
33543 | label: 'Service Task',
|
33544 | actionName: 'replace-with-service-task',
|
33545 | className: 'bpmn-icon-service',
|
33546 | target: {
|
33547 | type: 'bpmn:ServiceTask'
|
33548 | }
|
33549 | },
|
33550 | {
|
33551 | label: 'Script Task',
|
33552 | actionName: 'replace-with-script-task',
|
33553 | className: 'bpmn-icon-script',
|
33554 | target: {
|
33555 | type: 'bpmn:ScriptTask'
|
33556 | }
|
33557 | },
|
33558 | {
|
33559 | label: 'Call Activity',
|
33560 | actionName: 'replace-with-call-activity',
|
33561 | className: 'bpmn-icon-call-activity',
|
33562 | target: {
|
33563 | type: 'bpmn:CallActivity'
|
33564 | }
|
33565 | },
|
33566 | {
|
33567 | label: 'Sub Process (collapsed)',
|
33568 | actionName: 'replace-with-collapsed-subprocess',
|
33569 | className: 'bpmn-icon-subprocess-collapsed',
|
33570 | target: {
|
33571 | type: 'bpmn:SubProcess',
|
33572 | isExpanded: false
|
33573 | }
|
33574 | },
|
33575 | {
|
33576 | label: 'Sub Process (expanded)',
|
33577 | actionName: 'replace-with-expanded-subprocess',
|
33578 | className: 'bpmn-icon-subprocess-expanded',
|
33579 | target: {
|
33580 | type: 'bpmn:SubProcess',
|
33581 | isExpanded: true
|
33582 | }
|
33583 | }
|
33584 | ];
|
33585 |
|
33586 | var BOUNDARY_EVENT = [
|
33587 | {
|
33588 | label: 'Message Boundary Event',
|
33589 | actionName: 'replace-with-message-boundary',
|
33590 | className: 'bpmn-icon-intermediate-event-catch-message',
|
33591 | target: {
|
33592 | type: 'bpmn:BoundaryEvent',
|
33593 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
33594 | }
|
33595 | },
|
33596 | {
|
33597 | label: 'Timer Boundary Event',
|
33598 | actionName: 'replace-with-timer-boundary',
|
33599 | className: 'bpmn-icon-intermediate-event-catch-timer',
|
33600 | target: {
|
33601 | type: 'bpmn:BoundaryEvent',
|
33602 | eventDefinitionType: 'bpmn:TimerEventDefinition'
|
33603 | }
|
33604 | },
|
33605 | {
|
33606 | label: 'Escalation Boundary Event',
|
33607 | actionName: 'replace-with-escalation-boundary',
|
33608 | className: 'bpmn-icon-intermediate-event-catch-escalation',
|
33609 | target: {
|
33610 | type: 'bpmn:BoundaryEvent',
|
33611 | eventDefinitionType: 'bpmn:EscalationEventDefinition'
|
33612 | }
|
33613 | },
|
33614 | {
|
33615 | label: 'Conditional Boundary Event',
|
33616 | actionName: 'replace-with-conditional-boundary',
|
33617 | className: 'bpmn-icon-intermediate-event-catch-condition',
|
33618 | target: {
|
33619 | type: 'bpmn:BoundaryEvent',
|
33620 | eventDefinitionType: 'bpmn:ConditionalEventDefinition'
|
33621 | }
|
33622 | },
|
33623 | {
|
33624 | label: 'Error Boundary Event',
|
33625 | actionName: 'replace-with-error-boundary',
|
33626 | className: 'bpmn-icon-intermediate-event-catch-error',
|
33627 | target: {
|
33628 | type: 'bpmn:BoundaryEvent',
|
33629 | eventDefinitionType: 'bpmn:ErrorEventDefinition'
|
33630 | }
|
33631 | },
|
33632 | {
|
33633 | label: 'Cancel Boundary Event',
|
33634 | actionName: 'replace-with-cancel-boundary',
|
33635 | className: 'bpmn-icon-intermediate-event-catch-cancel',
|
33636 | target: {
|
33637 | type: 'bpmn:BoundaryEvent',
|
33638 | eventDefinitionType: 'bpmn:CancelEventDefinition'
|
33639 | }
|
33640 | },
|
33641 | {
|
33642 | label: 'Signal Boundary Event',
|
33643 | actionName: 'replace-with-signal-boundary',
|
33644 | className: 'bpmn-icon-intermediate-event-catch-signal',
|
33645 | target: {
|
33646 | type: 'bpmn:BoundaryEvent',
|
33647 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
33648 | }
|
33649 | },
|
33650 | {
|
33651 | label: 'Compensation Boundary Event',
|
33652 | actionName: 'replace-with-compensation-boundary',
|
33653 | className: 'bpmn-icon-intermediate-event-catch-compensation',
|
33654 | target: {
|
33655 | type: 'bpmn:BoundaryEvent',
|
33656 | eventDefinitionType: 'bpmn:CompensateEventDefinition'
|
33657 | }
|
33658 | },
|
33659 | {
|
33660 | label: 'Message Boundary Event (non-interrupting)',
|
33661 | actionName: 'replace-with-non-interrupting-message-boundary',
|
33662 | className: 'bpmn-icon-intermediate-event-catch-non-interrupting-message',
|
33663 | target: {
|
33664 | type: 'bpmn:BoundaryEvent',
|
33665 | eventDefinitionType: 'bpmn:MessageEventDefinition',
|
33666 | cancelActivity: false
|
33667 | }
|
33668 | },
|
33669 | {
|
33670 | label: 'Timer Boundary Event (non-interrupting)',
|
33671 | actionName: 'replace-with-non-interrupting-timer-boundary',
|
33672 | className: 'bpmn-icon-intermediate-event-catch-non-interrupting-timer',
|
33673 | target: {
|
33674 | type: 'bpmn:BoundaryEvent',
|
33675 | eventDefinitionType: 'bpmn:TimerEventDefinition',
|
33676 | cancelActivity: false
|
33677 | }
|
33678 | },
|
33679 | {
|
33680 | label: 'Escalation Boundary Event (non-interrupting)',
|
33681 | actionName: 'replace-with-non-interrupting-escalation-boundary',
|
33682 | className: 'bpmn-icon-intermediate-event-catch-non-interrupting-escalation',
|
33683 | target: {
|
33684 | type: 'bpmn:BoundaryEvent',
|
33685 | eventDefinitionType: 'bpmn:EscalationEventDefinition',
|
33686 | cancelActivity: false
|
33687 | }
|
33688 | },
|
33689 | {
|
33690 | label: 'Conditional Boundary Event (non-interrupting)',
|
33691 | actionName: 'replace-with-non-interrupting-conditional-boundary',
|
33692 | className: 'bpmn-icon-intermediate-event-catch-non-interrupting-condition',
|
33693 | target: {
|
33694 | type: 'bpmn:BoundaryEvent',
|
33695 | eventDefinitionType: 'bpmn:ConditionalEventDefinition',
|
33696 | cancelActivity: false
|
33697 | }
|
33698 | },
|
33699 | {
|
33700 | label: 'Signal Boundary Event (non-interrupting)',
|
33701 | actionName: 'replace-with-non-interrupting-signal-boundary',
|
33702 | className: 'bpmn-icon-intermediate-event-catch-non-interrupting-signal',
|
33703 | target: {
|
33704 | type: 'bpmn:BoundaryEvent',
|
33705 | eventDefinitionType: 'bpmn:SignalEventDefinition',
|
33706 | cancelActivity: false
|
33707 | }
|
33708 | }
|
33709 | ];
|
33710 |
|
33711 | var EVENT_SUB_PROCESS_START_EVENT = [
|
33712 | {
|
33713 | label: 'Message Start Event',
|
33714 | actionName: 'replace-with-message-start',
|
33715 | className: 'bpmn-icon-start-event-message',
|
33716 | target: {
|
33717 | type: 'bpmn:StartEvent',
|
33718 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
33719 | }
|
33720 | },
|
33721 | {
|
33722 | label: 'Timer Start Event',
|
33723 | actionName: 'replace-with-timer-start',
|
33724 | className: 'bpmn-icon-start-event-timer',
|
33725 | target: {
|
33726 | type: 'bpmn:StartEvent',
|
33727 | eventDefinitionType: 'bpmn:TimerEventDefinition'
|
33728 | }
|
33729 | },
|
33730 | {
|
33731 | label: 'Conditional Start Event',
|
33732 | actionName: 'replace-with-conditional-start',
|
33733 | className: 'bpmn-icon-start-event-condition',
|
33734 | target: {
|
33735 | type: 'bpmn:StartEvent',
|
33736 | eventDefinitionType: 'bpmn:ConditionalEventDefinition'
|
33737 | }
|
33738 | },
|
33739 | {
|
33740 | label: 'Signal Start Event',
|
33741 | actionName: 'replace-with-signal-start',
|
33742 | className: 'bpmn-icon-start-event-signal',
|
33743 | target: {
|
33744 | type: 'bpmn:StartEvent',
|
33745 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
33746 | }
|
33747 | },
|
33748 | {
|
33749 | label: 'Error Start Event',
|
33750 | actionName: 'replace-with-error-start',
|
33751 | className: 'bpmn-icon-start-event-error',
|
33752 | target: {
|
33753 | type: 'bpmn:StartEvent',
|
33754 | eventDefinitionType: 'bpmn:ErrorEventDefinition'
|
33755 | }
|
33756 | },
|
33757 | {
|
33758 | label: 'Escalation Start Event',
|
33759 | actionName: 'replace-with-escalation-start',
|
33760 | className: 'bpmn-icon-start-event-escalation',
|
33761 | target: {
|
33762 | type: 'bpmn:StartEvent',
|
33763 | eventDefinitionType: 'bpmn:EscalationEventDefinition'
|
33764 | }
|
33765 | },
|
33766 | {
|
33767 | label: 'Compensation Start Event',
|
33768 | actionName: 'replace-with-compensation-start',
|
33769 | className: 'bpmn-icon-start-event-compensation',
|
33770 | target: {
|
33771 | type: 'bpmn:StartEvent',
|
33772 | eventDefinitionType: 'bpmn:CompensateEventDefinition'
|
33773 | }
|
33774 | },
|
33775 | {
|
33776 | label: 'Message Start Event (non-interrupting)',
|
33777 | actionName: 'replace-with-non-interrupting-message-start',
|
33778 | className: 'bpmn-icon-start-event-non-interrupting-message',
|
33779 | target: {
|
33780 | type: 'bpmn:StartEvent',
|
33781 | eventDefinitionType: 'bpmn:MessageEventDefinition',
|
33782 | isInterrupting: false
|
33783 | }
|
33784 | },
|
33785 | {
|
33786 | label: 'Timer Start Event (non-interrupting)',
|
33787 | actionName: 'replace-with-non-interrupting-timer-start',
|
33788 | className: 'bpmn-icon-start-event-non-interrupting-timer',
|
33789 | target: {
|
33790 | type: 'bpmn:StartEvent',
|
33791 | eventDefinitionType: 'bpmn:TimerEventDefinition',
|
33792 | isInterrupting: false
|
33793 | }
|
33794 | },
|
33795 | {
|
33796 | label: 'Conditional Start Event (non-interrupting)',
|
33797 | actionName: 'replace-with-non-interrupting-conditional-start',
|
33798 | className: 'bpmn-icon-start-event-non-interrupting-condition',
|
33799 | target: {
|
33800 | type: 'bpmn:StartEvent',
|
33801 | eventDefinitionType: 'bpmn:ConditionalEventDefinition',
|
33802 | isInterrupting: false
|
33803 | }
|
33804 | },
|
33805 | {
|
33806 | label: 'Signal Start Event (non-interrupting)',
|
33807 | actionName: 'replace-with-non-interrupting-signal-start',
|
33808 | className: 'bpmn-icon-start-event-non-interrupting-signal',
|
33809 | target: {
|
33810 | type: 'bpmn:StartEvent',
|
33811 | eventDefinitionType: 'bpmn:SignalEventDefinition',
|
33812 | isInterrupting: false
|
33813 | }
|
33814 | },
|
33815 | {
|
33816 | label: 'Escalation Start Event (non-interrupting)',
|
33817 | actionName: 'replace-with-non-interrupting-escalation-start',
|
33818 | className: 'bpmn-icon-start-event-non-interrupting-escalation',
|
33819 | target: {
|
33820 | type: 'bpmn:StartEvent',
|
33821 | eventDefinitionType: 'bpmn:EscalationEventDefinition',
|
33822 | isInterrupting: false
|
33823 | }
|
33824 | }
|
33825 | ];
|
33826 |
|
33827 | var SEQUENCE_FLOW = [
|
33828 | {
|
33829 | label: 'Sequence Flow',
|
33830 | actionName: 'replace-with-sequence-flow',
|
33831 | className: 'bpmn-icon-connection'
|
33832 | },
|
33833 | {
|
33834 | label: 'Default Flow',
|
33835 | actionName: 'replace-with-default-flow',
|
33836 | className: 'bpmn-icon-default-flow'
|
33837 | },
|
33838 | {
|
33839 | label: 'Conditional Flow',
|
33840 | actionName: 'replace-with-conditional-flow',
|
33841 | className: 'bpmn-icon-conditional-flow'
|
33842 | }
|
33843 | ];
|
33844 |
|
33845 | var PARTICIPANT = [
|
33846 | {
|
33847 | label: 'Expanded Pool',
|
33848 | actionName: 'replace-with-expanded-pool',
|
33849 | className: 'bpmn-icon-participant',
|
33850 | target: {
|
33851 | type: 'bpmn:Participant',
|
33852 | isExpanded: true
|
33853 | }
|
33854 | },
|
33855 | {
|
33856 | label: 'Collapsed Pool',
|
33857 | actionName: 'replace-with-collapsed-pool',
|
33858 |
|
33859 |
|
33860 | className: 'bpmn-icon-lane',
|
33861 | target: {
|
33862 | type: 'bpmn:Participant',
|
33863 | isExpanded: false
|
33864 | }
|
33865 | }
|
33866 | ];
|
33867 |
|
33868 | |
33869 |
|
33870 |
|
33871 | function ReplaceMenuProvider(
|
33872 | popupMenu, modeling, moddle,
|
33873 | bpmnReplace, rules, translate) {
|
33874 |
|
33875 | this._popupMenu = popupMenu;
|
33876 | this._modeling = modeling;
|
33877 | this._moddle = moddle;
|
33878 | this._bpmnReplace = bpmnReplace;
|
33879 | this._rules = rules;
|
33880 | this._translate = translate;
|
33881 |
|
33882 | this.register();
|
33883 | }
|
33884 |
|
33885 | ReplaceMenuProvider.$inject = [
|
33886 | 'popupMenu',
|
33887 | 'modeling',
|
33888 | 'moddle',
|
33889 | 'bpmnReplace',
|
33890 | 'rules',
|
33891 | 'translate'
|
33892 | ];
|
33893 |
|
33894 |
|
33895 | |
33896 |
|
33897 |
|
33898 | ReplaceMenuProvider.prototype.register = function() {
|
33899 | this._popupMenu.registerProvider('bpmn-replace', this);
|
33900 | };
|
33901 |
|
33902 |
|
33903 | |
33904 |
|
33905 |
|
33906 |
|
33907 |
|
33908 |
|
33909 |
|
33910 |
|
33911 | ReplaceMenuProvider.prototype.getEntries = function(element) {
|
33912 |
|
33913 | var businessObject = element.businessObject;
|
33914 |
|
33915 | var rules = this._rules;
|
33916 |
|
33917 | var entries;
|
33918 |
|
33919 | if (!rules.allowed('shape.replace', { element: element })) {
|
33920 | return [];
|
33921 | }
|
33922 |
|
33923 | var differentType = isDifferentType(element);
|
33924 |
|
33925 |
|
33926 | if (is$1(businessObject, 'bpmn:StartEvent') && !isEventSubProcess(businessObject.$parent)) {
|
33927 |
|
33928 | entries = filter(START_EVENT, differentType);
|
33929 |
|
33930 | return this._createEntries(element, entries);
|
33931 | }
|
33932 |
|
33933 |
|
33934 | if (is$1(businessObject, 'bpmn:Participant')) {
|
33935 |
|
33936 | entries = filter(PARTICIPANT, function(entry) {
|
33937 | return isExpanded(businessObject) !== entry.target.isExpanded;
|
33938 | });
|
33939 |
|
33940 | return this._createEntries(element, entries);
|
33941 | }
|
33942 |
|
33943 |
|
33944 | if (is$1(businessObject, 'bpmn:StartEvent') && isEventSubProcess(businessObject.$parent)) {
|
33945 |
|
33946 | entries = filter(EVENT_SUB_PROCESS_START_EVENT, function(entry) {
|
33947 |
|
33948 | var target = entry.target;
|
33949 |
|
33950 | var isInterrupting = target.isInterrupting !== false;
|
33951 |
|
33952 | var isInterruptingEqual = getBusinessObject(element).isInterrupting === isInterrupting;
|
33953 |
|
33954 |
|
33955 | return differentType(entry) || !differentType(entry) && !isInterruptingEqual;
|
33956 |
|
33957 | });
|
33958 |
|
33959 | return this._createEntries(element, entries);
|
33960 | }
|
33961 |
|
33962 |
|
33963 | if (is$1(businessObject, 'bpmn:EndEvent')) {
|
33964 |
|
33965 | entries = filter(END_EVENT, function(entry) {
|
33966 | var target = entry.target;
|
33967 |
|
33968 |
|
33969 | if (target.eventDefinitionType == 'bpmn:CancelEventDefinition' && !is$1(businessObject.$parent, 'bpmn:Transaction')) {
|
33970 | return false;
|
33971 | }
|
33972 |
|
33973 | return differentType(entry);
|
33974 | });
|
33975 |
|
33976 | return this._createEntries(element, entries);
|
33977 | }
|
33978 |
|
33979 |
|
33980 | if (is$1(businessObject, 'bpmn:BoundaryEvent')) {
|
33981 |
|
33982 | entries = filter(BOUNDARY_EVENT, function(entry) {
|
33983 |
|
33984 | var target = entry.target;
|
33985 |
|
33986 | if (target.eventDefinition == 'bpmn:CancelEventDefinition' &&
|
33987 | !is$1(businessObject.attachedToRef, 'bpmn:Transaction')) {
|
33988 | return false;
|
33989 | }
|
33990 | var cancelActivity = target.cancelActivity !== false;
|
33991 |
|
33992 | var isCancelActivityEqual = businessObject.cancelActivity == cancelActivity;
|
33993 |
|
33994 | return differentType(entry) || !differentType(entry) && !isCancelActivityEqual;
|
33995 | });
|
33996 |
|
33997 | return this._createEntries(element, entries);
|
33998 | }
|
33999 |
|
34000 |
|
34001 | if (is$1(businessObject, 'bpmn:IntermediateCatchEvent') ||
|
34002 | is$1(businessObject, 'bpmn:IntermediateThrowEvent')) {
|
34003 |
|
34004 | entries = filter(INTERMEDIATE_EVENT, differentType);
|
34005 |
|
34006 | return this._createEntries(element, entries);
|
34007 | }
|
34008 |
|
34009 |
|
34010 | if (is$1(businessObject, 'bpmn:Gateway')) {
|
34011 |
|
34012 | entries = filter(GATEWAY, differentType);
|
34013 |
|
34014 | return this._createEntries(element, entries);
|
34015 | }
|
34016 |
|
34017 |
|
34018 | if (is$1(businessObject, 'bpmn:Transaction')) {
|
34019 |
|
34020 | entries = filter(TRANSACTION, differentType);
|
34021 |
|
34022 | return this._createEntries(element, entries);
|
34023 | }
|
34024 |
|
34025 |
|
34026 | if (isEventSubProcess(businessObject) && isExpanded(businessObject)) {
|
34027 |
|
34028 | entries = filter(EVENT_SUB_PROCESS, differentType);
|
34029 |
|
34030 | return this._createEntries(element, entries);
|
34031 | }
|
34032 |
|
34033 |
|
34034 | if (is$1(businessObject, 'bpmn:SubProcess') && isExpanded(businessObject)) {
|
34035 |
|
34036 | entries = filter(SUBPROCESS_EXPANDED, differentType);
|
34037 |
|
34038 | return this._createEntries(element, entries);
|
34039 | }
|
34040 |
|
34041 |
|
34042 | if (is$1(businessObject, 'bpmn:AdHocSubProcess') && !isExpanded(businessObject)) {
|
34043 |
|
34044 | entries = filter(TASK, function(entry) {
|
34045 |
|
34046 | var target = entry.target;
|
34047 |
|
34048 | var isTargetSubProcess = target.type === 'bpmn:SubProcess';
|
34049 |
|
34050 | var isTargetExpanded = target.isExpanded === true;
|
34051 |
|
34052 | return isDifferentType(element) && (!isTargetSubProcess || isTargetExpanded);
|
34053 | });
|
34054 |
|
34055 | return this._createEntries(element, entries);
|
34056 | }
|
34057 |
|
34058 |
|
34059 | if (is$1(businessObject, 'bpmn:SequenceFlow')) {
|
34060 | return this._createSequenceFlowEntries(element, SEQUENCE_FLOW);
|
34061 | }
|
34062 |
|
34063 |
|
34064 | if (is$1(businessObject, 'bpmn:FlowNode')) {
|
34065 | entries = filter(TASK, differentType);
|
34066 |
|
34067 |
|
34068 | if (is$1(businessObject, 'bpmn:SubProcess') && !isExpanded(businessObject)) {
|
34069 | entries = filter(entries, function(entry) {
|
34070 | return entry.label !== 'Sub Process (collapsed)';
|
34071 | });
|
34072 | }
|
34073 |
|
34074 | return this._createEntries(element, entries);
|
34075 | }
|
34076 |
|
34077 | return [];
|
34078 | };
|
34079 |
|
34080 |
|
34081 | |
34082 |
|
34083 |
|
34084 |
|
34085 |
|
34086 |
|
34087 |
|
34088 |
|
34089 | ReplaceMenuProvider.prototype.getHeaderEntries = function(element) {
|
34090 |
|
34091 | var headerEntries = [];
|
34092 |
|
34093 | if (is$1(element, 'bpmn:Activity') && !isEventSubProcess(element)) {
|
34094 | headerEntries = headerEntries.concat(this._getLoopEntries(element));
|
34095 | }
|
34096 |
|
34097 | if (is$1(element, 'bpmn:SubProcess') &&
|
34098 | !is$1(element, 'bpmn:Transaction') &&
|
34099 | !isEventSubProcess(element)) {
|
34100 | headerEntries.push(this._getAdHocEntry(element));
|
34101 | }
|
34102 |
|
34103 | return headerEntries;
|
34104 | };
|
34105 |
|
34106 |
|
34107 | |
34108 |
|
34109 |
|
34110 |
|
34111 |
|
34112 |
|
34113 |
|
34114 |
|
34115 |
|
34116 | ReplaceMenuProvider.prototype._createEntries = function(element, replaceOptions) {
|
34117 | var menuEntries = [];
|
34118 |
|
34119 | var self = this;
|
34120 |
|
34121 | forEach(replaceOptions, function(definition) {
|
34122 | var entry = self._createMenuEntry(definition, element);
|
34123 |
|
34124 | menuEntries.push(entry);
|
34125 | });
|
34126 |
|
34127 | return menuEntries;
|
34128 | };
|
34129 |
|
34130 | |
34131 |
|
34132 |
|
34133 |
|
34134 |
|
34135 |
|
34136 |
|
34137 |
|
34138 | ReplaceMenuProvider.prototype._createSequenceFlowEntries = function(element, replaceOptions) {
|
34139 |
|
34140 | var businessObject = getBusinessObject(element);
|
34141 |
|
34142 | var menuEntries = [];
|
34143 |
|
34144 | var modeling = this._modeling,
|
34145 | moddle = this._moddle;
|
34146 |
|
34147 | var self = this;
|
34148 |
|
34149 | forEach(replaceOptions, function(entry) {
|
34150 |
|
34151 | switch (entry.actionName) {
|
34152 | case 'replace-with-default-flow':
|
34153 | if (businessObject.sourceRef.default !== businessObject &&
|
34154 | (is$1(businessObject.sourceRef, 'bpmn:ExclusiveGateway') ||
|
34155 | is$1(businessObject.sourceRef, 'bpmn:InclusiveGateway') ||
|
34156 | is$1(businessObject.sourceRef, 'bpmn:ComplexGateway') ||
|
34157 | is$1(businessObject.sourceRef, 'bpmn:Activity'))) {
|
34158 |
|
34159 | menuEntries.push(self._createMenuEntry(entry, element, function() {
|
34160 | modeling.updateProperties(element.source, { default: businessObject });
|
34161 | }));
|
34162 | }
|
34163 | break;
|
34164 | case 'replace-with-conditional-flow':
|
34165 | if (!businessObject.conditionExpression && is$1(businessObject.sourceRef, 'bpmn:Activity')) {
|
34166 |
|
34167 | menuEntries.push(self._createMenuEntry(entry, element, function() {
|
34168 | var conditionExpression = moddle.create('bpmn:FormalExpression', { body: '' });
|
34169 |
|
34170 | modeling.updateProperties(element, { conditionExpression: conditionExpression });
|
34171 | }));
|
34172 | }
|
34173 | break;
|
34174 | default:
|
34175 |
|
34176 |
|
34177 | if (is$1(businessObject.sourceRef, 'bpmn:Activity') && businessObject.conditionExpression) {
|
34178 | return menuEntries.push(self._createMenuEntry(entry, element, function() {
|
34179 | modeling.updateProperties(element, { conditionExpression: undefined });
|
34180 | }));
|
34181 | }
|
34182 |
|
34183 |
|
34184 | if ((is$1(businessObject.sourceRef, 'bpmn:ExclusiveGateway') ||
|
34185 | is$1(businessObject.sourceRef, 'bpmn:InclusiveGateway') ||
|
34186 | is$1(businessObject.sourceRef, 'bpmn:ComplexGateway') ||
|
34187 | is$1(businessObject.sourceRef, 'bpmn:Activity')) &&
|
34188 | businessObject.sourceRef.default === businessObject) {
|
34189 |
|
34190 | return menuEntries.push(self._createMenuEntry(entry, element, function() {
|
34191 | modeling.updateProperties(element.source, { default: undefined });
|
34192 | }));
|
34193 | }
|
34194 | }
|
34195 | });
|
34196 |
|
34197 | return menuEntries;
|
34198 | };
|
34199 |
|
34200 |
|
34201 | |
34202 |
|
34203 |
|
34204 |
|
34205 |
|
34206 |
|
34207 |
|
34208 |
|
34209 |
|
34210 |
|
34211 | ReplaceMenuProvider.prototype._createMenuEntry = function(definition, element, action) {
|
34212 | var translate = this._translate;
|
34213 | var replaceElement = this._bpmnReplace.replaceElement;
|
34214 |
|
34215 | var replaceAction = function() {
|
34216 | return replaceElement(element, definition.target);
|
34217 | };
|
34218 |
|
34219 | action = action || replaceAction;
|
34220 |
|
34221 | var menuEntry = {
|
34222 | label: translate(definition.label),
|
34223 | className: definition.className,
|
34224 | id: definition.actionName,
|
34225 | action: action
|
34226 | };
|
34227 |
|
34228 | return menuEntry;
|
34229 | };
|
34230 |
|
34231 | |
34232 |
|
34233 |
|
34234 |
|
34235 |
|
34236 |
|
34237 |
|
34238 | ReplaceMenuProvider.prototype._getLoopEntries = function(element) {
|
34239 |
|
34240 | var self = this;
|
34241 | var translate = this._translate;
|
34242 |
|
34243 | function toggleLoopEntry(event, entry) {
|
34244 | var loopCharacteristics;
|
34245 |
|
34246 | if (entry.active) {
|
34247 | loopCharacteristics = undefined;
|
34248 | } else {
|
34249 | loopCharacteristics = self._moddle.create(entry.options.loopCharacteristics);
|
34250 |
|
34251 | if (entry.options.isSequential) {
|
34252 | loopCharacteristics.isSequential = entry.options.isSequential;
|
34253 | }
|
34254 | }
|
34255 | self._modeling.updateProperties(element, { loopCharacteristics: loopCharacteristics });
|
34256 | }
|
34257 |
|
34258 | var businessObject = getBusinessObject(element),
|
34259 | loopCharacteristics = businessObject.loopCharacteristics;
|
34260 |
|
34261 | var isSequential,
|
34262 | isLoop,
|
34263 | isParallel;
|
34264 |
|
34265 | if (loopCharacteristics) {
|
34266 | isSequential = loopCharacteristics.isSequential;
|
34267 | isLoop = loopCharacteristics.isSequential === undefined;
|
34268 | isParallel = loopCharacteristics.isSequential !== undefined && !loopCharacteristics.isSequential;
|
34269 | }
|
34270 |
|
34271 |
|
34272 | var loopEntries = [
|
34273 | {
|
34274 | id: 'toggle-parallel-mi',
|
34275 | className: 'bpmn-icon-parallel-mi-marker',
|
34276 | title: translate('Parallel Multi Instance'),
|
34277 | active: isParallel,
|
34278 | action: toggleLoopEntry,
|
34279 | options: {
|
34280 | loopCharacteristics: 'bpmn:MultiInstanceLoopCharacteristics',
|
34281 | isSequential: false
|
34282 | }
|
34283 | },
|
34284 | {
|
34285 | id: 'toggle-sequential-mi',
|
34286 | className: 'bpmn-icon-sequential-mi-marker',
|
34287 | title: translate('Sequential Multi Instance'),
|
34288 | active: isSequential,
|
34289 | action: toggleLoopEntry,
|
34290 | options: {
|
34291 | loopCharacteristics: 'bpmn:MultiInstanceLoopCharacteristics',
|
34292 | isSequential: true
|
34293 | }
|
34294 | },
|
34295 | {
|
34296 | id: 'toggle-loop',
|
34297 | className: 'bpmn-icon-loop-marker',
|
34298 | title: translate('Loop'),
|
34299 | active: isLoop,
|
34300 | action: toggleLoopEntry,
|
34301 | options: {
|
34302 | loopCharacteristics: 'bpmn:StandardLoopCharacteristics'
|
34303 | }
|
34304 | }
|
34305 | ];
|
34306 | return loopEntries;
|
34307 | };
|
34308 |
|
34309 |
|
34310 | |
34311 |
|
34312 |
|
34313 |
|
34314 |
|
34315 |
|
34316 |
|
34317 | ReplaceMenuProvider.prototype._getAdHocEntry = function(element) {
|
34318 | var translate = this._translate;
|
34319 | var businessObject = getBusinessObject(element);
|
34320 |
|
34321 | var isAdHoc = is$1(businessObject, 'bpmn:AdHocSubProcess');
|
34322 |
|
34323 | var replaceElement = this._bpmnReplace.replaceElement;
|
34324 |
|
34325 | var adHocEntry = {
|
34326 | id: 'toggle-adhoc',
|
34327 | className: 'bpmn-icon-ad-hoc-marker',
|
34328 | title: translate('Ad-hoc'),
|
34329 | active: isAdHoc,
|
34330 | action: function(event, entry) {
|
34331 | if (isAdHoc) {
|
34332 | return replaceElement(element, { type: 'bpmn:SubProcess' });
|
34333 | } else {
|
34334 | return replaceElement(element, { type: 'bpmn:AdHocSubProcess' });
|
34335 | }
|
34336 | }
|
34337 | };
|
34338 |
|
34339 | return adHocEntry;
|
34340 | };
|
34341 |
|
34342 | var PopupMenuModule$1 = {
|
34343 | __depends__: [
|
34344 | PopupMenuModule,
|
34345 | ReplaceModule$1
|
34346 | ],
|
34347 | __init__: [ 'replaceMenuProvider' ],
|
34348 | replaceMenuProvider: [ 'type', ReplaceMenuProvider ]
|
34349 | };
|
34350 |
|
34351 | var max$2 = Math.max,
|
34352 | min$1 = Math.min;
|
34353 |
|
34354 | var DEFAULT_CHILD_BOX_PADDING = 20;
|
34355 |
|
34356 |
|
34357 | |
34358 |
|
34359 |
|
34360 |
|
34361 |
|
34362 |
|
34363 |
|
34364 |
|
34365 | function substractTRBL(trblA, trblB) {
|
34366 | return {
|
34367 | top: trblA.top - trblB.top,
|
34368 | right: trblA.right - trblB.right,
|
34369 | bottom: trblA.bottom - trblB.bottom,
|
34370 | left: trblA.left - trblB.left
|
34371 | };
|
34372 | }
|
34373 |
|
34374 | |
34375 |
|
34376 |
|
34377 |
|
34378 |
|
34379 |
|
34380 |
|
34381 |
|
34382 |
|
34383 | function resizeBounds(bounds, direction, delta) {
|
34384 |
|
34385 | var dx = delta.x,
|
34386 | dy = delta.y;
|
34387 |
|
34388 | switch (direction) {
|
34389 |
|
34390 | case 'nw':
|
34391 | return {
|
34392 | x: bounds.x + dx,
|
34393 | y: bounds.y + dy,
|
34394 | width: bounds.width - dx,
|
34395 | height: bounds.height - dy
|
34396 | };
|
34397 |
|
34398 | case 'sw':
|
34399 | return {
|
34400 | x: bounds.x + dx,
|
34401 | y: bounds.y,
|
34402 | width: bounds.width - dx,
|
34403 | height: bounds.height + dy
|
34404 | };
|
34405 |
|
34406 | case 'ne':
|
34407 | return {
|
34408 | x: bounds.x,
|
34409 | y: bounds.y + dy,
|
34410 | width: bounds.width + dx,
|
34411 | height: bounds.height - dy
|
34412 | };
|
34413 |
|
34414 | case 'se':
|
34415 | return {
|
34416 | x: bounds.x,
|
34417 | y: bounds.y,
|
34418 | width: bounds.width + dx,
|
34419 | height: bounds.height + dy
|
34420 | };
|
34421 |
|
34422 | default:
|
34423 | throw new Error('unrecognized direction: ' + direction);
|
34424 | }
|
34425 | }
|
34426 |
|
34427 |
|
34428 | |
34429 |
|
34430 |
|
34431 |
|
34432 |
|
34433 |
|
34434 |
|
34435 |
|
34436 |
|
34437 | function resizeTRBL(bounds, resize) {
|
34438 | return {
|
34439 | x: bounds.x + (resize.left || 0),
|
34440 | y: bounds.y + (resize.top || 0),
|
34441 | width: bounds.width - (resize.left || 0) + (resize.right || 0),
|
34442 | height: bounds.height - (resize.top || 0) + (resize.bottom || 0)
|
34443 | };
|
34444 | }
|
34445 |
|
34446 |
|
34447 | function applyConstraints(attr, trbl, resizeConstraints) {
|
34448 |
|
34449 | var value = trbl[attr],
|
34450 | minValue = resizeConstraints.min && resizeConstraints.min[attr],
|
34451 | maxValue = resizeConstraints.max && resizeConstraints.max[attr];
|
34452 |
|
34453 | if (isNumber(minValue)) {
|
34454 | value = (/top|left/.test(attr) ? min$1 : max$2)(value, minValue);
|
34455 | }
|
34456 |
|
34457 | if (isNumber(maxValue)) {
|
34458 | value = (/top|left/.test(attr) ? max$2 : min$1)(value, maxValue);
|
34459 | }
|
34460 |
|
34461 | return value;
|
34462 | }
|
34463 |
|
34464 | function ensureConstraints$1(currentBounds, resizeConstraints) {
|
34465 |
|
34466 | if (!resizeConstraints) {
|
34467 | return currentBounds;
|
34468 | }
|
34469 |
|
34470 | var currentTrbl = asTRBL(currentBounds);
|
34471 |
|
34472 | return asBounds({
|
34473 | top: applyConstraints('top', currentTrbl, resizeConstraints),
|
34474 | right: applyConstraints('right', currentTrbl, resizeConstraints),
|
34475 | bottom: applyConstraints('bottom', currentTrbl, resizeConstraints),
|
34476 | left: applyConstraints('left', currentTrbl, resizeConstraints)
|
34477 | });
|
34478 | }
|
34479 |
|
34480 |
|
34481 | function getMinResizeBounds(direction, currentBounds, minDimensions, childrenBounds) {
|
34482 |
|
34483 | var currentBox = asTRBL(currentBounds);
|
34484 |
|
34485 | var minBox = {
|
34486 | top: /n/.test(direction) ? currentBox.bottom - minDimensions.height : currentBox.top,
|
34487 | left: /w/.test(direction) ? currentBox.right - minDimensions.width : currentBox.left,
|
34488 | bottom: /s/.test(direction) ? currentBox.top + minDimensions.height : currentBox.bottom,
|
34489 | right: /e/.test(direction) ? currentBox.left + minDimensions.width : currentBox.right
|
34490 | };
|
34491 |
|
34492 | var childrenBox = childrenBounds ? asTRBL(childrenBounds) : minBox;
|
34493 |
|
34494 | var combinedBox = {
|
34495 | top: min$1(minBox.top, childrenBox.top),
|
34496 | left: min$1(minBox.left, childrenBox.left),
|
34497 | bottom: max$2(minBox.bottom, childrenBox.bottom),
|
34498 | right: max$2(minBox.right, childrenBox.right)
|
34499 | };
|
34500 |
|
34501 | return asBounds(combinedBox);
|
34502 | }
|
34503 |
|
34504 | function asPadding(mayBePadding, defaultValue) {
|
34505 | if (typeof mayBePadding !== 'undefined') {
|
34506 | return mayBePadding;
|
34507 | } else {
|
34508 | return DEFAULT_CHILD_BOX_PADDING;
|
34509 | }
|
34510 | }
|
34511 |
|
34512 | function addPadding(bbox, padding) {
|
34513 | var left, right, top, bottom;
|
34514 |
|
34515 | if (typeof padding === 'object') {
|
34516 | left = asPadding(padding.left);
|
34517 | right = asPadding(padding.right);
|
34518 | top = asPadding(padding.top);
|
34519 | bottom = asPadding(padding.bottom);
|
34520 | } else {
|
34521 | left = right = top = bottom = asPadding(padding);
|
34522 | }
|
34523 |
|
34524 | return {
|
34525 | x: bbox.x - left,
|
34526 | y: bbox.y - top,
|
34527 | width: bbox.width + left + right,
|
34528 | height: bbox.height + top + bottom
|
34529 | };
|
34530 | }
|
34531 |
|
34532 |
|
34533 | |
34534 |
|
34535 |
|
34536 |
|
34537 |
|
34538 |
|
34539 |
|
34540 |
|
34541 |
|
34542 | function isBBoxChild(element) {
|
34543 |
|
34544 |
|
34545 | if (element.waypoints) {
|
34546 | return false;
|
34547 | }
|
34548 |
|
34549 |
|
34550 | if (element.type === 'label') {
|
34551 | return false;
|
34552 | }
|
34553 |
|
34554 | return true;
|
34555 | }
|
34556 |
|
34557 | |
34558 |
|
34559 |
|
34560 |
|
34561 |
|
34562 |
|
34563 |
|
34564 |
|
34565 |
|
34566 | function computeChildrenBBox(shapeOrChildren, padding) {
|
34567 |
|
34568 | var elements;
|
34569 |
|
34570 |
|
34571 | if (shapeOrChildren.length === undefined) {
|
34572 |
|
34573 |
|
34574 |
|
34575 | elements = filter(shapeOrChildren.children, isBBoxChild);
|
34576 |
|
34577 | } else {
|
34578 | elements = shapeOrChildren;
|
34579 | }
|
34580 |
|
34581 | if (elements.length) {
|
34582 | return addPadding(getBBox(elements), padding);
|
34583 | }
|
34584 | }
|
34585 |
|
34586 | var abs$3 = Math.abs;
|
34587 |
|
34588 |
|
34589 | function getTRBLResize(oldBounds, newBounds) {
|
34590 | return substractTRBL(asTRBL(newBounds), asTRBL(oldBounds));
|
34591 | }
|
34592 |
|
34593 |
|
34594 | var LANE_PARENTS = [
|
34595 | 'bpmn:Participant',
|
34596 | 'bpmn:Process',
|
34597 | 'bpmn:SubProcess'
|
34598 | ];
|
34599 |
|
34600 | var LANE_INDENTATION = 30;
|
34601 |
|
34602 |
|
34603 | |
34604 |
|
34605 |
|
34606 |
|
34607 |
|
34608 |
|
34609 |
|
34610 |
|
34611 | function collectLanes(shape, collectedShapes) {
|
34612 |
|
34613 | collectedShapes = collectedShapes || [];
|
34614 |
|
34615 | shape.children.filter(function(s) {
|
34616 | if (is$1(s, 'bpmn:Lane')) {
|
34617 | collectLanes(s, collectedShapes);
|
34618 |
|
34619 | collectedShapes.push(s);
|
34620 | }
|
34621 | });
|
34622 |
|
34623 | return collectedShapes;
|
34624 | }
|
34625 |
|
34626 |
|
34627 | |
34628 |
|
34629 |
|
34630 |
|
34631 |
|
34632 |
|
34633 |
|
34634 | function getChildLanes(shape) {
|
34635 | return shape.children.filter(function(c) {
|
34636 | return is$1(c, 'bpmn:Lane');
|
34637 | });
|
34638 | }
|
34639 |
|
34640 |
|
34641 | |
34642 |
|
34643 |
|
34644 |
|
34645 |
|
34646 |
|
34647 |
|
34648 | function getLanesRoot(shape) {
|
34649 | return getParent$1(shape, LANE_PARENTS) || shape;
|
34650 | }
|
34651 |
|
34652 |
|
34653 | |
34654 |
|
34655 |
|
34656 |
|
34657 |
|
34658 |
|
34659 |
|
34660 |
|
34661 |
|
34662 |
|
34663 | function computeLanesResize(shape, newBounds) {
|
34664 |
|
34665 | var rootElement = getLanesRoot(shape);
|
34666 |
|
34667 | var initialShapes = is$1(rootElement, 'bpmn:Process') ? [] : [ rootElement ];
|
34668 |
|
34669 | var allLanes = collectLanes(rootElement, initialShapes),
|
34670 | shapeTrbl = asTRBL(shape),
|
34671 | shapeNewTrbl = asTRBL(newBounds),
|
34672 | trblResize = getTRBLResize(shape, newBounds),
|
34673 | resizeNeeded = [];
|
34674 |
|
34675 | allLanes.forEach(function(other) {
|
34676 |
|
34677 | if (other === shape) {
|
34678 | return;
|
34679 | }
|
34680 |
|
34681 | var topResize = 0,
|
34682 | rightResize = trblResize.right,
|
34683 | bottomResize = 0,
|
34684 | leftResize = trblResize.left;
|
34685 |
|
34686 | var otherTrbl = asTRBL(other);
|
34687 |
|
34688 | if (trblResize.top) {
|
34689 | if (abs$3(otherTrbl.bottom - shapeTrbl.top) < 10) {
|
34690 | bottomResize = shapeNewTrbl.top - otherTrbl.bottom;
|
34691 | }
|
34692 |
|
34693 | if (abs$3(otherTrbl.top - shapeTrbl.top) < 5) {
|
34694 | topResize = shapeNewTrbl.top - otherTrbl.top;
|
34695 | }
|
34696 | }
|
34697 |
|
34698 | if (trblResize.bottom) {
|
34699 | if (abs$3(otherTrbl.top - shapeTrbl.bottom) < 10) {
|
34700 | topResize = shapeNewTrbl.bottom - otherTrbl.top;
|
34701 | }
|
34702 |
|
34703 | if (abs$3(otherTrbl.bottom - shapeTrbl.bottom) < 5) {
|
34704 | bottomResize = shapeNewTrbl.bottom - otherTrbl.bottom;
|
34705 | }
|
34706 | }
|
34707 |
|
34708 | if (topResize || rightResize || bottomResize || leftResize) {
|
34709 |
|
34710 | resizeNeeded.push({
|
34711 | shape: other,
|
34712 | newBounds: resizeTRBL(other, {
|
34713 | top: topResize,
|
34714 | right: rightResize,
|
34715 | bottom: bottomResize,
|
34716 | left: leftResize
|
34717 | })
|
34718 | });
|
34719 | }
|
34720 |
|
34721 | });
|
34722 |
|
34723 | return resizeNeeded;
|
34724 | }
|
34725 |
|
34726 | |
34727 |
|
34728 |
|
34729 | function ContextPadProvider(
|
34730 | config, injector, eventBus,
|
34731 | contextPad, modeling, elementFactory,
|
34732 | connect, create, popupMenu,
|
34733 | canvas, rules, translate) {
|
34734 |
|
34735 | config = config || {};
|
34736 |
|
34737 | contextPad.registerProvider(this);
|
34738 |
|
34739 | this._contextPad = contextPad;
|
34740 |
|
34741 | this._modeling = modeling;
|
34742 |
|
34743 | this._elementFactory = elementFactory;
|
34744 | this._connect = connect;
|
34745 | this._create = create;
|
34746 | this._popupMenu = popupMenu;
|
34747 | this._canvas = canvas;
|
34748 | this._rules = rules;
|
34749 | this._translate = translate;
|
34750 |
|
34751 | if (config.autoPlace !== false) {
|
34752 | this._autoPlace = injector.get('autoPlace', false);
|
34753 | }
|
34754 |
|
34755 | eventBus.on('create.end', 250, function(event) {
|
34756 | var shape = event.context.shape;
|
34757 |
|
34758 | if (!hasPrimaryModifier(event)) {
|
34759 | return;
|
34760 | }
|
34761 |
|
34762 | var entries = contextPad.getEntries(shape);
|
34763 |
|
34764 | if (entries.replace) {
|
34765 | entries.replace.action.click(event, shape);
|
34766 | }
|
34767 | });
|
34768 | }
|
34769 |
|
34770 | ContextPadProvider.$inject = [
|
34771 | 'config.contextPad',
|
34772 | 'injector',
|
34773 | 'eventBus',
|
34774 | 'contextPad',
|
34775 | 'modeling',
|
34776 | 'elementFactory',
|
34777 | 'connect',
|
34778 | 'create',
|
34779 | 'popupMenu',
|
34780 | 'canvas',
|
34781 | 'rules',
|
34782 | 'translate'
|
34783 | ];
|
34784 |
|
34785 |
|
34786 | ContextPadProvider.prototype.getContextPadEntries = function(element) {
|
34787 |
|
34788 | var contextPad = this._contextPad,
|
34789 | modeling = this._modeling,
|
34790 |
|
34791 | elementFactory = this._elementFactory,
|
34792 | connect = this._connect,
|
34793 | create = this._create,
|
34794 | popupMenu = this._popupMenu,
|
34795 | canvas = this._canvas,
|
34796 | rules = this._rules,
|
34797 | autoPlace = this._autoPlace,
|
34798 | translate = this._translate;
|
34799 |
|
34800 | var actions = {};
|
34801 |
|
34802 | if (element.type === 'label') {
|
34803 | return actions;
|
34804 | }
|
34805 |
|
34806 | var businessObject = element.businessObject;
|
34807 |
|
34808 | function startConnect(event, element) {
|
34809 | connect.start(event, element);
|
34810 | }
|
34811 |
|
34812 | function removeElement(e) {
|
34813 | modeling.removeElements([ element ]);
|
34814 | }
|
34815 |
|
34816 | function getReplaceMenuPosition(element) {
|
34817 |
|
34818 | var Y_OFFSET = 5;
|
34819 |
|
34820 | var diagramContainer = canvas.getContainer(),
|
34821 | pad = contextPad.getPad(element).html;
|
34822 |
|
34823 | var diagramRect = diagramContainer.getBoundingClientRect(),
|
34824 | padRect = pad.getBoundingClientRect();
|
34825 |
|
34826 | var top = padRect.top - diagramRect.top;
|
34827 | var left = padRect.left - diagramRect.left;
|
34828 |
|
34829 | var pos = {
|
34830 | x: left,
|
34831 | y: top + padRect.height + Y_OFFSET
|
34832 | };
|
34833 |
|
34834 | return pos;
|
34835 | }
|
34836 |
|
34837 |
|
34838 | |
34839 |
|
34840 |
|
34841 |
|
34842 |
|
34843 |
|
34844 |
|
34845 |
|
34846 |
|
34847 |
|
34848 | function appendAction(type, className, title, options) {
|
34849 |
|
34850 | if (typeof title !== 'string') {
|
34851 | options = title;
|
34852 | title = translate('Append {type}', { type: type.replace(/^bpmn:/, '') });
|
34853 | }
|
34854 |
|
34855 | function appendStart(event, element) {
|
34856 |
|
34857 | var shape = elementFactory.createShape(assign({ type: type }, options));
|
34858 | create.start(event, shape, {
|
34859 | source: element
|
34860 | });
|
34861 | }
|
34862 |
|
34863 |
|
34864 | var append = autoPlace ? function(event, element) {
|
34865 | var shape = elementFactory.createShape(assign({ type: type }, options));
|
34866 |
|
34867 | autoPlace.append(element, shape);
|
34868 | } : appendStart;
|
34869 |
|
34870 |
|
34871 | return {
|
34872 | group: 'model',
|
34873 | className: className,
|
34874 | title: title,
|
34875 | action: {
|
34876 | dragstart: appendStart,
|
34877 | click: append
|
34878 | }
|
34879 | };
|
34880 | }
|
34881 |
|
34882 | function splitLaneHandler(count) {
|
34883 |
|
34884 | return function(event, element) {
|
34885 |
|
34886 |
|
34887 | modeling.splitLane(element, count);
|
34888 |
|
34889 |
|
34890 |
|
34891 | contextPad.open(element, true);
|
34892 | };
|
34893 | }
|
34894 |
|
34895 |
|
34896 | if (isAny(businessObject, [ 'bpmn:Lane', 'bpmn:Participant' ]) && isExpanded(businessObject)) {
|
34897 |
|
34898 | var childLanes = getChildLanes(element);
|
34899 |
|
34900 | assign(actions, {
|
34901 | 'lane-insert-above': {
|
34902 | group: 'lane-insert-above',
|
34903 | className: 'bpmn-icon-lane-insert-above',
|
34904 | title: translate('Add Lane above'),
|
34905 | action: {
|
34906 | click: function(event, element) {
|
34907 | modeling.addLane(element, 'top');
|
34908 | }
|
34909 | }
|
34910 | }
|
34911 | });
|
34912 |
|
34913 | if (childLanes.length < 2) {
|
34914 |
|
34915 | if (element.height >= 120) {
|
34916 | assign(actions, {
|
34917 | 'lane-divide-two': {
|
34918 | group: 'lane-divide',
|
34919 | className: 'bpmn-icon-lane-divide-two',
|
34920 | title: translate('Divide into two Lanes'),
|
34921 | action: {
|
34922 | click: splitLaneHandler(2)
|
34923 | }
|
34924 | }
|
34925 | });
|
34926 | }
|
34927 |
|
34928 | if (element.height >= 180) {
|
34929 | assign(actions, {
|
34930 | 'lane-divide-three': {
|
34931 | group: 'lane-divide',
|
34932 | className: 'bpmn-icon-lane-divide-three',
|
34933 | title: translate('Divide into three Lanes'),
|
34934 | action: {
|
34935 | click: splitLaneHandler(3)
|
34936 | }
|
34937 | }
|
34938 | });
|
34939 | }
|
34940 | }
|
34941 |
|
34942 | assign(actions, {
|
34943 | 'lane-insert-below': {
|
34944 | group: 'lane-insert-below',
|
34945 | className: 'bpmn-icon-lane-insert-below',
|
34946 | title: translate('Add Lane below'),
|
34947 | action: {
|
34948 | click: function(event, element) {
|
34949 | modeling.addLane(element, 'bottom');
|
34950 | }
|
34951 | }
|
34952 | }
|
34953 | });
|
34954 |
|
34955 | }
|
34956 |
|
34957 | if (is$1(businessObject, 'bpmn:FlowNode')) {
|
34958 |
|
34959 | if (is$1(businessObject, 'bpmn:EventBasedGateway')) {
|
34960 |
|
34961 | assign(actions, {
|
34962 | 'append.receive-task': appendAction(
|
34963 | 'bpmn:ReceiveTask',
|
34964 | 'bpmn-icon-receive-task'
|
34965 | ),
|
34966 | 'append.message-intermediate-event': appendAction(
|
34967 | 'bpmn:IntermediateCatchEvent',
|
34968 | 'bpmn-icon-intermediate-event-catch-message',
|
34969 | translate('Append MessageIntermediateCatchEvent'),
|
34970 | { eventDefinitionType: 'bpmn:MessageEventDefinition' }
|
34971 | ),
|
34972 | 'append.timer-intermediate-event': appendAction(
|
34973 | 'bpmn:IntermediateCatchEvent',
|
34974 | 'bpmn-icon-intermediate-event-catch-timer',
|
34975 | translate('Append TimerIntermediateCatchEvent'),
|
34976 | { eventDefinitionType: 'bpmn:TimerEventDefinition' }
|
34977 | ),
|
34978 | 'append.condtion-intermediate-event': appendAction(
|
34979 | 'bpmn:IntermediateCatchEvent',
|
34980 | 'bpmn-icon-intermediate-event-catch-condition',
|
34981 | translate('Append ConditionIntermediateCatchEvent'),
|
34982 | { eventDefinitionType: 'bpmn:ConditionalEventDefinition' }
|
34983 | ),
|
34984 | 'append.signal-intermediate-event': appendAction(
|
34985 | 'bpmn:IntermediateCatchEvent',
|
34986 | 'bpmn-icon-intermediate-event-catch-signal',
|
34987 | translate('Append SignalIntermediateCatchEvent'),
|
34988 | { eventDefinitionType: 'bpmn:SignalEventDefinition' }
|
34989 | )
|
34990 | });
|
34991 | } else
|
34992 |
|
34993 | if (isEventType(businessObject, 'bpmn:BoundaryEvent', 'bpmn:CompensateEventDefinition')) {
|
34994 |
|
34995 | assign(actions, {
|
34996 | 'append.compensation-activity':
|
34997 | appendAction(
|
34998 | 'bpmn:Task',
|
34999 | 'bpmn-icon-task',
|
35000 | translate('Append compensation activity'),
|
35001 | {
|
35002 | isForCompensation: true
|
35003 | }
|
35004 | )
|
35005 | });
|
35006 | } else
|
35007 |
|
35008 | if (!is$1(businessObject, 'bpmn:EndEvent') &&
|
35009 | !businessObject.isForCompensation &&
|
35010 | !isEventType(businessObject, 'bpmn:IntermediateThrowEvent', 'bpmn:LinkEventDefinition') &&
|
35011 | !isEventSubProcess(businessObject)) {
|
35012 |
|
35013 | assign(actions, {
|
35014 | 'append.end-event': appendAction(
|
35015 | 'bpmn:EndEvent',
|
35016 | 'bpmn-icon-end-event-none',
|
35017 | translate('Append EndEvent')
|
35018 | ),
|
35019 | 'append.gateway': appendAction(
|
35020 | 'bpmn:ExclusiveGateway',
|
35021 | 'bpmn-icon-gateway-none',
|
35022 | translate('Append Gateway')
|
35023 | ),
|
35024 | 'append.append-task': appendAction(
|
35025 | 'bpmn:Task',
|
35026 | 'bpmn-icon-task',
|
35027 | translate('Append Task')
|
35028 | ),
|
35029 | 'append.intermediate-event': appendAction(
|
35030 | 'bpmn:IntermediateThrowEvent',
|
35031 | 'bpmn-icon-intermediate-event-none',
|
35032 | translate('Append Intermediate/Boundary Event')
|
35033 | )
|
35034 | });
|
35035 | }
|
35036 | }
|
35037 |
|
35038 | if (!popupMenu.isEmpty(element, 'bpmn-replace')) {
|
35039 |
|
35040 |
|
35041 | assign(actions, {
|
35042 | 'replace': {
|
35043 | group: 'edit',
|
35044 | className: 'bpmn-icon-screw-wrench',
|
35045 | title: translate('Change type'),
|
35046 | action: {
|
35047 | click: function(event, element) {
|
35048 |
|
35049 | var position = assign(getReplaceMenuPosition(element), {
|
35050 | cursor: { x: event.x, y: event.y }
|
35051 | });
|
35052 |
|
35053 | popupMenu.open(element, 'bpmn-replace', position);
|
35054 | }
|
35055 | }
|
35056 | }
|
35057 | });
|
35058 | }
|
35059 |
|
35060 | if (isAny(businessObject, [
|
35061 | 'bpmn:FlowNode',
|
35062 | 'bpmn:InteractionNode',
|
35063 | 'bpmn:DataObjectReference',
|
35064 | 'bpmn:DataStoreReference'
|
35065 | ])) {
|
35066 |
|
35067 | assign(actions, {
|
35068 | 'append.text-annotation': appendAction('bpmn:TextAnnotation', 'bpmn-icon-text-annotation'),
|
35069 |
|
35070 | 'connect': {
|
35071 | group: 'connect',
|
35072 | className: 'bpmn-icon-connection-multi',
|
35073 | title: translate('Connect using ' +
|
35074 | (businessObject.isForCompensation ? '' : 'Sequence/MessageFlow or ') +
|
35075 | 'Association'),
|
35076 | action: {
|
35077 | click: startConnect,
|
35078 | dragstart: startConnect
|
35079 | }
|
35080 | }
|
35081 | });
|
35082 | }
|
35083 |
|
35084 | if (isAny(businessObject, [ 'bpmn:DataObjectReference', 'bpmn:DataStoreReference' ])) {
|
35085 | assign(actions, {
|
35086 | 'connect': {
|
35087 | group: 'connect',
|
35088 | className: 'bpmn-icon-connection-multi',
|
35089 | title: translate('Connect using DataInputAssociation'),
|
35090 | action: {
|
35091 | click: startConnect,
|
35092 | dragstart: startConnect
|
35093 | }
|
35094 | }
|
35095 | });
|
35096 | }
|
35097 |
|
35098 |
|
35099 | var deleteAllowed = rules.allowed('elements.delete', { elements: [ element ] });
|
35100 |
|
35101 | if (isArray(deleteAllowed)) {
|
35102 |
|
35103 |
|
35104 | deleteAllowed = deleteAllowed[0] === element;
|
35105 | }
|
35106 |
|
35107 | if (deleteAllowed) {
|
35108 | assign(actions, {
|
35109 | 'delete': {
|
35110 | group: 'edit',
|
35111 | className: 'bpmn-icon-trash',
|
35112 | title: translate('Remove'),
|
35113 | action: {
|
35114 | click: removeElement
|
35115 | }
|
35116 | }
|
35117 | });
|
35118 | }
|
35119 |
|
35120 | return actions;
|
35121 | };
|
35122 |
|
35123 | function isEventType(eventBo, type, definition) {
|
35124 |
|
35125 | var isType = eventBo.$instanceOf(type);
|
35126 | var isDefinition = false;
|
35127 |
|
35128 | var definitions = eventBo.eventDefinitions || [];
|
35129 | forEach(definitions, function(def) {
|
35130 | if (def.$type === definition) {
|
35131 | isDefinition = true;
|
35132 | }
|
35133 | });
|
35134 |
|
35135 | return isType && isDefinition;
|
35136 | }
|
35137 |
|
35138 | var ContextPadModule$1 = {
|
35139 | __depends__: [
|
35140 | DirectEditingModule,
|
35141 | ContextPadModule,
|
35142 | SelectionModule,
|
35143 | ConnectModule,
|
35144 | CreateModule,
|
35145 | PopupMenuModule$1
|
35146 | ],
|
35147 | __init__: [ 'contextPadProvider' ],
|
35148 | contextPadProvider: [ 'type', ContextPadProvider ]
|
35149 | };
|
35150 |
|
35151 | var AXIS_DIMENSIONS = {
|
35152 | horizontal: [ 'x', 'width' ],
|
35153 | vertical: [ 'y', 'height' ]
|
35154 | };
|
35155 |
|
35156 | var THRESHOLD$1 = 5;
|
35157 |
|
35158 |
|
35159 | |
35160 |
|
35161 |
|
35162 | function DistributeElements(modeling) {
|
35163 | this._modeling = modeling;
|
35164 |
|
35165 | this._filters = [];
|
35166 |
|
35167 |
|
35168 | this.registerFilter(function(elements, axis, dimension) {
|
35169 | var elementsSize = 0,
|
35170 | numOfShapes = 0,
|
35171 | avgDimension;
|
35172 |
|
35173 | forEach(elements, function(element) {
|
35174 | if (element.waypoints || element.labelTarget) {
|
35175 | return;
|
35176 | }
|
35177 |
|
35178 | elementsSize += element[dimension];
|
35179 |
|
35180 | numOfShapes += 1;
|
35181 | });
|
35182 |
|
35183 | avgDimension = Math.round(elementsSize / numOfShapes);
|
35184 |
|
35185 | return filter(elements, function(element) {
|
35186 | return element[dimension] < (avgDimension + 50);
|
35187 | });
|
35188 | });
|
35189 |
|
35190 | }
|
35191 |
|
35192 | DistributeElements.$inject = [ 'modeling' ];
|
35193 |
|
35194 |
|
35195 | |
35196 |
|
35197 |
|
35198 |
|
35199 |
|
35200 |
|
35201 | DistributeElements.prototype.registerFilter = function(filterFn) {
|
35202 | if (typeof filterFn !== 'function') {
|
35203 | throw new Error('the filter has to be a function');
|
35204 | }
|
35205 |
|
35206 | this._filters.push(filterFn);
|
35207 | };
|
35208 |
|
35209 | |
35210 |
|
35211 |
|
35212 |
|
35213 |
|
35214 |
|
35215 | DistributeElements.prototype.trigger = function(elements, orientation) {
|
35216 | var modeling = this._modeling;
|
35217 |
|
35218 | var groups,
|
35219 | distributableElements;
|
35220 |
|
35221 | if (elements.length < 3) {
|
35222 | return;
|
35223 | }
|
35224 |
|
35225 | this._setOrientation(orientation);
|
35226 |
|
35227 | distributableElements = this._filterElements(elements);
|
35228 |
|
35229 | groups = this._createGroups(distributableElements);
|
35230 |
|
35231 |
|
35232 | if (groups.length <= 2) {
|
35233 | return;
|
35234 | }
|
35235 |
|
35236 | modeling.distributeElements(groups, this._axis, this._dimension);
|
35237 |
|
35238 | return groups;
|
35239 | };
|
35240 |
|
35241 | |
35242 |
|
35243 |
|
35244 |
|
35245 |
|
35246 |
|
35247 |
|
35248 | DistributeElements.prototype._filterElements = function(elements) {
|
35249 | var filters = this._filters,
|
35250 | axis = this._axis,
|
35251 | dimension = this._dimension,
|
35252 | distributableElements = [].concat(elements);
|
35253 |
|
35254 | if (!filters.length) {
|
35255 | return elements;
|
35256 | }
|
35257 |
|
35258 | forEach(filters, function(filterFn) {
|
35259 | distributableElements = filterFn(distributableElements, axis, dimension);
|
35260 | });
|
35261 |
|
35262 | return distributableElements;
|
35263 | };
|
35264 |
|
35265 |
|
35266 | |
35267 |
|
35268 |
|
35269 |
|
35270 |
|
35271 |
|
35272 |
|
35273 |
|
35274 |
|
35275 |
|
35276 |
|
35277 |
|
35278 |
|
35279 |
|
35280 |
|
35281 |
|
35282 |
|
35283 |
|
35284 |
|
35285 | DistributeElements.prototype._createGroups = function(elements) {
|
35286 | var rangeGroups = [],
|
35287 | self = this,
|
35288 | axis = this._axis,
|
35289 | dimension = this._dimension;
|
35290 |
|
35291 | if (!axis) {
|
35292 | throw new Error('must have a defined "axis" and "dimension"');
|
35293 | }
|
35294 |
|
35295 |
|
35296 | var sortedElements = sortBy(elements, axis);
|
35297 |
|
35298 | forEach(sortedElements, function(element, idx) {
|
35299 | var elementRange = self._findRange(element, axis, dimension),
|
35300 | range;
|
35301 |
|
35302 | var previous = rangeGroups[rangeGroups.length - 1];
|
35303 |
|
35304 | if (previous && self._hasIntersection(previous.range, elementRange)) {
|
35305 | rangeGroups[rangeGroups.length - 1].elements.push(element);
|
35306 | } else {
|
35307 | range = { range: elementRange, elements: [ element ] };
|
35308 |
|
35309 | rangeGroups.push(range);
|
35310 | }
|
35311 | });
|
35312 |
|
35313 | return rangeGroups;
|
35314 | };
|
35315 |
|
35316 |
|
35317 | |
35318 |
|
35319 |
|
35320 |
|
35321 |
|
35322 | DistributeElements.prototype._setOrientation = function(direction) {
|
35323 | var orientation = AXIS_DIMENSIONS[direction];
|
35324 |
|
35325 | this._axis = orientation[0];
|
35326 | this._dimension = orientation[1];
|
35327 | };
|
35328 |
|
35329 |
|
35330 | |
35331 |
|
35332 |
|
35333 |
|
35334 |
|
35335 |
|
35336 |
|
35337 |
|
35338 | DistributeElements.prototype._hasIntersection = function(rangeA, rangeB) {
|
35339 | return Math.max(rangeA.min, rangeA.max) >= Math.min(rangeB.min, rangeB.max) &&
|
35340 | Math.min(rangeA.min, rangeA.max) <= Math.max(rangeB.min, rangeB.max);
|
35341 | };
|
35342 |
|
35343 |
|
35344 | |
35345 |
|
35346 |
|
35347 |
|
35348 |
|
35349 |
|
35350 |
|
35351 |
|
35352 |
|
35353 | DistributeElements.prototype._findRange = function(element) {
|
35354 | var axis = element[this._axis],
|
35355 | dimension = element[this._dimension];
|
35356 |
|
35357 | return {
|
35358 | min: axis + THRESHOLD$1,
|
35359 | max: axis + dimension - THRESHOLD$1
|
35360 | };
|
35361 | };
|
35362 |
|
35363 | var DistributeElementsModule = {
|
35364 | __init__: [ 'distributeElements' ],
|
35365 | distributeElements: [ 'type', DistributeElements ]
|
35366 | };
|
35367 |
|
35368 | |
35369 |
|
35370 |
|
35371 |
|
35372 | function BpmnDistributeElements(distributeElements) {
|
35373 |
|
35374 | distributeElements.registerFilter(function(elements) {
|
35375 | return filter(elements, function(element) {
|
35376 | var cannotDistribute = isAny(element, [
|
35377 | 'bpmn:Association',
|
35378 | 'bpmn:BoundaryEvent',
|
35379 | 'bpmn:DataInputAssociation',
|
35380 | 'bpmn:DataOutputAssociation',
|
35381 | 'bpmn:Lane',
|
35382 | 'bpmn:MessageFlow',
|
35383 | 'bpmn:Participant',
|
35384 | 'bpmn:SequenceFlow',
|
35385 | 'bpmn:TextAnnotation'
|
35386 | ]);
|
35387 |
|
35388 | return !(element.labelTarget || cannotDistribute);
|
35389 | });
|
35390 | });
|
35391 | }
|
35392 |
|
35393 | BpmnDistributeElements.$inject = [ 'distributeElements' ];
|
35394 |
|
35395 | var DistributeElementsModule$1 = {
|
35396 | __depends__: [
|
35397 | DistributeElementsModule
|
35398 | ],
|
35399 | __init__: [ 'bpmnDistributeElements' ],
|
35400 | bpmnDistributeElements: [ 'type', BpmnDistributeElements ]
|
35401 | };
|
35402 |
|
35403 | var NOT_REGISTERED_ERROR = 'is not a registered action',
|
35404 | IS_REGISTERED_ERROR = 'is already registered';
|
35405 |
|
35406 |
|
35407 | |
35408 |
|
35409 |
|
35410 |
|
35411 |
|
35412 |
|
35413 |
|
35414 |
|
35415 |
|
35416 |
|
35417 |
|
35418 |
|
35419 |
|
35420 |
|
35421 |
|
35422 |
|
35423 |
|
35424 |
|
35425 |
|
35426 |
|
35427 | function EditorActions(eventBus, injector) {
|
35428 |
|
35429 |
|
35430 | this._actions = {};
|
35431 |
|
35432 | var self = this;
|
35433 |
|
35434 | eventBus.on('diagram.init', function() {
|
35435 |
|
35436 |
|
35437 |
|
35438 | self._registerDefaultActions(injector);
|
35439 |
|
35440 |
|
35441 |
|
35442 | eventBus.fire('editorActions.init', {
|
35443 | editorActions: self
|
35444 | });
|
35445 | });
|
35446 |
|
35447 | }
|
35448 |
|
35449 | EditorActions.$inject = [
|
35450 | 'eventBus',
|
35451 | 'injector'
|
35452 | ];
|
35453 |
|
35454 | |
35455 |
|
35456 |
|
35457 |
|
35458 |
|
35459 | EditorActions.prototype._registerDefaultActions = function(injector) {
|
35460 |
|
35461 |
|
35462 |
|
35463 | var commandStack = injector.get('commandStack', false);
|
35464 | var modeling = injector.get('modeling', false);
|
35465 | var selection = injector.get('selection', false);
|
35466 | var zoomScroll = injector.get('zoomScroll', false);
|
35467 | var copyPaste = injector.get('copyPaste', false);
|
35468 | var canvas = injector.get('canvas', false);
|
35469 | var rules = injector.get('rules', false);
|
35470 | var keyboardMove = injector.get('keyboardMove', false);
|
35471 | var keyboardMoveSelection = injector.get('keyboardMoveSelection', false);
|
35472 |
|
35473 |
|
35474 |
|
35475 | if (commandStack) {
|
35476 | this.register('undo', function() {
|
35477 | commandStack.undo();
|
35478 | });
|
35479 |
|
35480 | this.register('redo', function() {
|
35481 | commandStack.redo();
|
35482 | });
|
35483 | }
|
35484 |
|
35485 | if (copyPaste && selection) {
|
35486 | this.register('copy', function() {
|
35487 | var selectedElements = selection.get();
|
35488 |
|
35489 | copyPaste.copy(selectedElements);
|
35490 | });
|
35491 | }
|
35492 |
|
35493 | if (copyPaste) {
|
35494 | this.register('paste', function() {
|
35495 | copyPaste.paste();
|
35496 | });
|
35497 | }
|
35498 |
|
35499 | if (zoomScroll) {
|
35500 | this.register('stepZoom', function(opts) {
|
35501 | zoomScroll.stepZoom(opts.value);
|
35502 | });
|
35503 | }
|
35504 |
|
35505 | if (canvas) {
|
35506 | this.register('zoom', function(opts) {
|
35507 | canvas.zoom(opts.value);
|
35508 | });
|
35509 | }
|
35510 |
|
35511 | if (modeling && selection && rules) {
|
35512 | this.register('removeSelection', function() {
|
35513 |
|
35514 | var selectedElements = selection.get();
|
35515 |
|
35516 | if (!selectedElements.length) {
|
35517 | return;
|
35518 | }
|
35519 |
|
35520 | var allowed = rules.allowed('elements.delete', { elements: selectedElements }),
|
35521 | removableElements;
|
35522 |
|
35523 | if (allowed === false) {
|
35524 | return;
|
35525 | }
|
35526 | else if (isArray(allowed)) {
|
35527 | removableElements = allowed;
|
35528 | }
|
35529 | else {
|
35530 | removableElements = selectedElements;
|
35531 | }
|
35532 |
|
35533 | if (removableElements.length) {
|
35534 | modeling.removeElements(removableElements.slice());
|
35535 | }
|
35536 | });
|
35537 | }
|
35538 |
|
35539 | if (keyboardMove) {
|
35540 | this.register('moveCanvas', function(opts) {
|
35541 | keyboardMove.moveCanvas(opts);
|
35542 | });
|
35543 | }
|
35544 |
|
35545 | if (keyboardMoveSelection) {
|
35546 | this.register('moveSelection', function(opts) {
|
35547 | keyboardMoveSelection.moveSelection(opts.direction, opts.accelerated);
|
35548 | });
|
35549 | }
|
35550 |
|
35551 | };
|
35552 |
|
35553 |
|
35554 | |
35555 |
|
35556 |
|
35557 |
|
35558 |
|
35559 |
|
35560 |
|
35561 |
|
35562 | EditorActions.prototype.trigger = function(action, opts) {
|
35563 | if (!this._actions[action]) {
|
35564 | throw error$2(action, NOT_REGISTERED_ERROR);
|
35565 | }
|
35566 |
|
35567 | return this._actions[action](opts);
|
35568 | };
|
35569 |
|
35570 |
|
35571 | |
35572 |
|
35573 |
|
35574 |
|
35575 |
|
35576 |
|
35577 |
|
35578 |
|
35579 |
|
35580 |
|
35581 |
|
35582 |
|
35583 |
|
35584 |
|
35585 |
|
35586 |
|
35587 |
|
35588 |
|
35589 |
|
35590 |
|
35591 |
|
35592 |
|
35593 | EditorActions.prototype.register = function(actions, listener) {
|
35594 | var self = this;
|
35595 |
|
35596 | if (typeof actions === 'string') {
|
35597 | return this._registerAction(actions, listener);
|
35598 | }
|
35599 |
|
35600 | forEach(actions, function(listener, action) {
|
35601 | self._registerAction(action, listener);
|
35602 | });
|
35603 | };
|
35604 |
|
35605 | |
35606 |
|
35607 |
|
35608 |
|
35609 |
|
35610 |
|
35611 | EditorActions.prototype._registerAction = function(action, listener) {
|
35612 | if (this.isRegistered(action)) {
|
35613 | throw error$2(action, IS_REGISTERED_ERROR);
|
35614 | }
|
35615 |
|
35616 | this._actions[action] = listener;
|
35617 | };
|
35618 |
|
35619 | |
35620 |
|
35621 |
|
35622 |
|
35623 |
|
35624 | EditorActions.prototype.unregister = function(action) {
|
35625 | if (!this.isRegistered(action)) {
|
35626 | throw error$2(action, NOT_REGISTERED_ERROR);
|
35627 | }
|
35628 |
|
35629 | this._actions[action] = undefined;
|
35630 | };
|
35631 |
|
35632 | |
35633 |
|
35634 |
|
35635 |
|
35636 |
|
35637 | EditorActions.prototype.getActions = function() {
|
35638 | return Object.keys(this._actions);
|
35639 | };
|
35640 |
|
35641 | |
35642 |
|
35643 |
|
35644 |
|
35645 |
|
35646 |
|
35647 |
|
35648 | EditorActions.prototype.isRegistered = function(action) {
|
35649 | return !!this._actions[action];
|
35650 | };
|
35651 |
|
35652 |
|
35653 | function error$2(action, message) {
|
35654 | return new Error(action + ' ' + message);
|
35655 | }
|
35656 |
|
35657 | var EditorActionsModule = {
|
35658 | __init__: [ 'editorActions' ],
|
35659 | editorActions: [ 'type', EditorActions ]
|
35660 | };
|
35661 |
|
35662 | |
35663 |
|
35664 |
|
35665 |
|
35666 |
|
35667 | function BpmnEditorActions(injector) {
|
35668 | injector.invoke(EditorActions, this);
|
35669 | }
|
35670 |
|
35671 | inherits_browser(BpmnEditorActions, EditorActions);
|
35672 |
|
35673 | BpmnEditorActions.$inject = [
|
35674 | 'injector'
|
35675 | ];
|
35676 |
|
35677 | |
35678 |
|
35679 |
|
35680 |
|
35681 |
|
35682 | BpmnEditorActions.prototype._registerDefaultActions = function(injector) {
|
35683 |
|
35684 |
|
35685 |
|
35686 | EditorActions.prototype._registerDefaultActions.call(this, injector);
|
35687 |
|
35688 |
|
35689 |
|
35690 | var canvas = injector.get('canvas', false);
|
35691 | var elementRegistry = injector.get('elementRegistry', false);
|
35692 | var selection = injector.get('selection', false);
|
35693 | var spaceTool = injector.get('spaceTool', false);
|
35694 | var lassoTool = injector.get('lassoTool', false);
|
35695 | var handTool = injector.get('handTool', false);
|
35696 | var globalConnect = injector.get('globalConnect', false);
|
35697 | var distributeElements = injector.get('distributeElements', false);
|
35698 | var alignElements = injector.get('alignElements', false);
|
35699 | var directEditing = injector.get('directEditing', false);
|
35700 | var searchPad = injector.get('searchPad', false);
|
35701 | var modeling = injector.get('modeling', false);
|
35702 |
|
35703 |
|
35704 |
|
35705 | if (canvas && elementRegistry && selection) {
|
35706 | this._registerAction('selectElements', function() {
|
35707 |
|
35708 |
|
35709 |
|
35710 | var rootElement = canvas.getRootElement();
|
35711 |
|
35712 | var elements = elementRegistry.filter(function(element) {
|
35713 | return element !== rootElement;
|
35714 | });
|
35715 |
|
35716 | selection.select(elements);
|
35717 |
|
35718 | return elements;
|
35719 | });
|
35720 | }
|
35721 |
|
35722 | if (spaceTool) {
|
35723 | this._registerAction('spaceTool', function() {
|
35724 | spaceTool.toggle();
|
35725 | });
|
35726 | }
|
35727 |
|
35728 | if (lassoTool) {
|
35729 | this._registerAction('lassoTool', function() {
|
35730 | lassoTool.toggle();
|
35731 | });
|
35732 | }
|
35733 |
|
35734 | if (handTool) {
|
35735 | this._registerAction('handTool', function() {
|
35736 | handTool.toggle();
|
35737 | });
|
35738 | }
|
35739 |
|
35740 | if (globalConnect) {
|
35741 | this._registerAction('globalConnectTool', function() {
|
35742 | globalConnect.toggle();
|
35743 | });
|
35744 | }
|
35745 |
|
35746 | if (selection && distributeElements) {
|
35747 | this._registerAction('distributeElements', function(opts) {
|
35748 | var currentSelection = selection.get(),
|
35749 | type = opts.type;
|
35750 |
|
35751 | if (currentSelection.length) {
|
35752 | distributeElements.trigger(currentSelection, type);
|
35753 | }
|
35754 | });
|
35755 | }
|
35756 |
|
35757 | if (selection && alignElements) {
|
35758 | this._registerAction('alignElements', function(opts) {
|
35759 | var currentSelection = selection.get(),
|
35760 | aligneableElements = [],
|
35761 | type = opts.type;
|
35762 |
|
35763 | if (currentSelection.length) {
|
35764 | aligneableElements = filter(currentSelection, function(element) {
|
35765 | return !is$1(element, 'bpmn:Lane');
|
35766 | });
|
35767 |
|
35768 | alignElements.trigger(aligneableElements, type);
|
35769 | }
|
35770 | });
|
35771 | }
|
35772 |
|
35773 | if (selection && modeling) {
|
35774 | this._registerAction('setColor', function(opts) {
|
35775 | var currentSelection = selection.get();
|
35776 |
|
35777 | if (currentSelection.length) {
|
35778 | modeling.setColor(currentSelection, opts);
|
35779 | }
|
35780 | });
|
35781 | }
|
35782 |
|
35783 | if (selection && directEditing) {
|
35784 | this._registerAction('directEditing', function() {
|
35785 | var currentSelection = selection.get();
|
35786 |
|
35787 | if (currentSelection.length) {
|
35788 | directEditing.activate(currentSelection[0]);
|
35789 | }
|
35790 | });
|
35791 | }
|
35792 |
|
35793 | if (searchPad) {
|
35794 | this._registerAction('find', function() {
|
35795 | searchPad.toggle();
|
35796 | });
|
35797 | }
|
35798 |
|
35799 | if (canvas && modeling) {
|
35800 | this._registerAction('moveToOrigin', function() {
|
35801 | var rootElement = canvas.getRootElement(),
|
35802 | boundingBox,
|
35803 | elements;
|
35804 |
|
35805 | if (is$1(rootElement, 'bpmn:Collaboration')) {
|
35806 | elements = elementRegistry.filter(function(element) {
|
35807 | return is$1(element.parent, 'bpmn:Collaboration');
|
35808 | });
|
35809 | } else {
|
35810 | elements = elementRegistry.filter(function(element) {
|
35811 | return element !== rootElement && !is$1(element.parent, 'bpmn:SubProcess');
|
35812 | });
|
35813 | }
|
35814 |
|
35815 | boundingBox = getBBox(elements);
|
35816 |
|
35817 | modeling.moveElements(
|
35818 | elements,
|
35819 | { x: -boundingBox.x, y: -boundingBox.y },
|
35820 | rootElement
|
35821 | );
|
35822 | });
|
35823 | }
|
35824 |
|
35825 | };
|
35826 |
|
35827 | var EditorActionsModule$1 = {
|
35828 | __depends__: [
|
35829 | EditorActionsModule
|
35830 | ],
|
35831 | editorActions: [ 'type', BpmnEditorActions ]
|
35832 | };
|
35833 |
|
35834 | function BpmnGridSnapping(eventBus) {
|
35835 | eventBus.on([
|
35836 | 'create.init',
|
35837 | 'shape.move.init'
|
35838 | ], function(event) {
|
35839 | var context = event.context,
|
35840 | shape = event.shape;
|
35841 |
|
35842 | if (isAny(shape, [
|
35843 | 'bpmn:Participant',
|
35844 | 'bpmn:SubProcess',
|
35845 | 'bpmn:TextAnnotation'
|
35846 | ])) {
|
35847 | if (!context.gridSnappingContext) {
|
35848 | context.gridSnappingContext = {};
|
35849 | }
|
35850 |
|
35851 | context.gridSnappingContext.snapLocation = 'top-left';
|
35852 | }
|
35853 | });
|
35854 | }
|
35855 |
|
35856 | BpmnGridSnapping.$inject = [ 'eventBus' ];
|
35857 |
|
35858 | var SPACING = 10;
|
35859 |
|
35860 | function quantize(value, quantum, fn) {
|
35861 | if (!fn) {
|
35862 | fn = 'round';
|
35863 | }
|
35864 |
|
35865 | return Math[ fn ](value / quantum) * quantum;
|
35866 | }
|
35867 |
|
35868 | var LOWER_PRIORITY = 1200;
|
35869 | var LOW_PRIORITY$7 = 800;
|
35870 |
|
35871 | |
35872 |
|
35873 |
|
35874 |
|
35875 | function GridSnapping(elementRegistry, eventBus, config) {
|
35876 |
|
35877 | var active = !config || config.active !== false;
|
35878 |
|
35879 | this._eventBus = eventBus;
|
35880 |
|
35881 | var self = this;
|
35882 |
|
35883 | eventBus.on('diagram.init', LOW_PRIORITY$7, function() {
|
35884 | self.setActive(active);
|
35885 | });
|
35886 |
|
35887 | eventBus.on([
|
35888 | 'create.move',
|
35889 | 'create.end',
|
35890 | 'bendpoint.move.move',
|
35891 | 'bendpoint.move.end',
|
35892 | 'connect.move',
|
35893 | 'connect.end',
|
35894 | 'connectionSegment.move.move',
|
35895 | 'connectionSegment.move.end',
|
35896 | 'resize.move',
|
35897 | 'resize.end',
|
35898 | 'shape.move.move',
|
35899 | 'shape.move.end'
|
35900 | ], LOWER_PRIORITY, function(event) {
|
35901 | var originalEvent = event.originalEvent;
|
35902 |
|
35903 | if (!self.active || (originalEvent && isCmd(originalEvent))) {
|
35904 | return;
|
35905 | }
|
35906 |
|
35907 | var context = event.context,
|
35908 | gridSnappingContext = context.gridSnappingContext;
|
35909 |
|
35910 | if (!gridSnappingContext) {
|
35911 | gridSnappingContext = context.gridSnappingContext = {};
|
35912 | }
|
35913 |
|
35914 | [ 'x', 'y' ].forEach(function(axis) {
|
35915 | var options = {};
|
35916 |
|
35917 |
|
35918 | var snapOffset = getSnapOffset(event, axis, elementRegistry);
|
35919 |
|
35920 | if (snapOffset) {
|
35921 | options.offset = snapOffset;
|
35922 | }
|
35923 |
|
35924 |
|
35925 | var snapConstraints = getSnapConstraints(event, axis);
|
35926 |
|
35927 | if (snapConstraints) {
|
35928 | assign(options, snapConstraints);
|
35929 | }
|
35930 |
|
35931 | if (!isSnapped(event, axis)) {
|
35932 | self.snapEvent(event, axis, options);
|
35933 | }
|
35934 | });
|
35935 | });
|
35936 | }
|
35937 |
|
35938 | |
35939 |
|
35940 |
|
35941 |
|
35942 |
|
35943 |
|
35944 |
|
35945 |
|
35946 |
|
35947 | GridSnapping.prototype.snapEvent = function(event, axis, options) {
|
35948 | var snappedValue = this.snapValue(event[ axis ], options);
|
35949 |
|
35950 | setSnapped(event, axis, snappedValue);
|
35951 | };
|
35952 |
|
35953 | |
35954 |
|
35955 |
|
35956 |
|
35957 |
|
35958 | GridSnapping.prototype.getGridSpacing = function() {
|
35959 | return SPACING;
|
35960 | };
|
35961 |
|
35962 | |
35963 |
|
35964 |
|
35965 |
|
35966 |
|
35967 |
|
35968 |
|
35969 |
|
35970 |
|
35971 | GridSnapping.prototype.snapValue = function(value, options) {
|
35972 | var offset = 0;
|
35973 |
|
35974 | if (options && options.offset) {
|
35975 | offset = options.offset;
|
35976 | }
|
35977 |
|
35978 | value += offset;
|
35979 |
|
35980 | value = quantize(value, SPACING);
|
35981 |
|
35982 | var min, max;
|
35983 |
|
35984 | if (options && options.min) {
|
35985 | min = options.min;
|
35986 |
|
35987 | if (isNumber(min)) {
|
35988 | min = quantize(min + offset, SPACING, 'ceil');
|
35989 |
|
35990 | value = Math.max(value, min);
|
35991 | }
|
35992 | }
|
35993 |
|
35994 | if (options && options.max) {
|
35995 | max = options.max;
|
35996 |
|
35997 | if (isNumber(max)) {
|
35998 | max = quantize(max + offset, SPACING, 'floor');
|
35999 |
|
36000 | value = Math.min(value, max);
|
36001 | }
|
36002 | }
|
36003 |
|
36004 | value -= offset;
|
36005 |
|
36006 | return value;
|
36007 | };
|
36008 |
|
36009 | GridSnapping.prototype.isActive = function() {
|
36010 | return this.active;
|
36011 | };
|
36012 |
|
36013 | GridSnapping.prototype.setActive = function(active) {
|
36014 | this.active = active;
|
36015 |
|
36016 | this._eventBus.fire('gridSnapping.toggle', { active: active });
|
36017 | };
|
36018 |
|
36019 | GridSnapping.prototype.toggleActive = function() {
|
36020 | this.setActive(!this.active);
|
36021 | };
|
36022 |
|
36023 | GridSnapping.$inject = [
|
36024 | 'elementRegistry',
|
36025 | 'eventBus',
|
36026 | 'config.gridSnapping'
|
36027 | ];
|
36028 |
|
36029 |
|
36030 |
|
36031 | |
36032 |
|
36033 |
|
36034 |
|
36035 |
|
36036 |
|
36037 |
|
36038 |
|
36039 |
|
36040 |
|
36041 | function getSnapConstraints(event, axis) {
|
36042 | var context = event.context,
|
36043 | createConstraints = context.createConstraints,
|
36044 | resizeConstraints = context.resizeConstraints || {},
|
36045 | gridSnappingContext = context.gridSnappingContext,
|
36046 | snapConstraints = gridSnappingContext.snapConstraints;
|
36047 |
|
36048 |
|
36049 | if (snapConstraints && snapConstraints[ axis ]) {
|
36050 | return snapConstraints[ axis ];
|
36051 | }
|
36052 |
|
36053 | if (!snapConstraints) {
|
36054 | snapConstraints = gridSnappingContext.snapConstraints = {};
|
36055 | }
|
36056 |
|
36057 | if (!snapConstraints[ axis ]) {
|
36058 | snapConstraints[ axis ] = {};
|
36059 | }
|
36060 |
|
36061 | var direction = context.direction;
|
36062 |
|
36063 |
|
36064 | if (createConstraints) {
|
36065 | if (isHorizontal(axis)) {
|
36066 | snapConstraints.x.min = createConstraints.left;
|
36067 | snapConstraints.x.max = createConstraints.right;
|
36068 | } else {
|
36069 | snapConstraints.y.min = createConstraints.top;
|
36070 | snapConstraints.y.max = createConstraints.bottom;
|
36071 | }
|
36072 | }
|
36073 |
|
36074 |
|
36075 | var minResizeConstraints = resizeConstraints.min,
|
36076 | maxResizeConstraints = resizeConstraints.max;
|
36077 |
|
36078 | if (minResizeConstraints) {
|
36079 | if (isHorizontal(axis)) {
|
36080 |
|
36081 | if (isWest(direction)) {
|
36082 | snapConstraints.x.max = minResizeConstraints.left;
|
36083 | } else {
|
36084 | snapConstraints.x.min = minResizeConstraints.right;
|
36085 | }
|
36086 |
|
36087 | } else {
|
36088 |
|
36089 | if (isNorth(direction)) {
|
36090 | snapConstraints.y.max = minResizeConstraints.top;
|
36091 | } else {
|
36092 | snapConstraints.y.min = minResizeConstraints.bottom;
|
36093 | }
|
36094 |
|
36095 | }
|
36096 | }
|
36097 |
|
36098 | if (maxResizeConstraints) {
|
36099 | if (isHorizontal(axis)) {
|
36100 |
|
36101 | if (isWest(direction)) {
|
36102 | snapConstraints.x.min = maxResizeConstraints.left;
|
36103 | } else {
|
36104 | snapConstraints.x.max = maxResizeConstraints.right;
|
36105 | }
|
36106 |
|
36107 | } else {
|
36108 |
|
36109 | if (isNorth(direction)) {
|
36110 | snapConstraints.y.min = maxResizeConstraints.top;
|
36111 | } else {
|
36112 | snapConstraints.y.max = maxResizeConstraints.bottom;
|
36113 | }
|
36114 |
|
36115 | }
|
36116 | }
|
36117 |
|
36118 | return snapConstraints[ axis ];
|
36119 | }
|
36120 |
|
36121 | |
36122 |
|
36123 |
|
36124 |
|
36125 |
|
36126 |
|
36127 |
|
36128 |
|
36129 |
|
36130 |
|
36131 | function getSnapOffset(event, axis, elementRegistry) {
|
36132 | var context = event.context,
|
36133 | shape = event.shape,
|
36134 | gridSnappingContext = context.gridSnappingContext,
|
36135 | snapLocation = gridSnappingContext.snapLocation,
|
36136 | snapOffset = gridSnappingContext.snapOffset;
|
36137 |
|
36138 |
|
36139 | if (snapOffset && isNumber(snapOffset[ axis ])) {
|
36140 | return snapOffset[ axis ];
|
36141 | }
|
36142 |
|
36143 | if (!snapOffset) {
|
36144 | snapOffset = gridSnappingContext.snapOffset = {};
|
36145 | }
|
36146 |
|
36147 | if (!isNumber(snapOffset[ axis ])) {
|
36148 | snapOffset[ axis ] = 0;
|
36149 | }
|
36150 |
|
36151 | if (!shape) {
|
36152 | return snapOffset[ axis ];
|
36153 | }
|
36154 |
|
36155 | if (!elementRegistry.get(shape.id)) {
|
36156 |
|
36157 | if (isHorizontal(axis)) {
|
36158 | snapOffset[ axis ] += shape[ axis ] + shape.width / 2;
|
36159 | } else {
|
36160 | snapOffset[ axis ] += shape[ axis ] + shape.height / 2;
|
36161 | }
|
36162 | }
|
36163 |
|
36164 | if (!snapLocation) {
|
36165 | return snapOffset[ axis ];
|
36166 | }
|
36167 |
|
36168 | if (axis === 'x') {
|
36169 | if (/left/.test(snapLocation)) {
|
36170 | snapOffset[ axis ] -= shape.width / 2;
|
36171 | } else if (/right/.test(snapLocation)) {
|
36172 | snapOffset[ axis ] += shape.width / 2;
|
36173 | }
|
36174 | } else {
|
36175 | if (/top/.test(snapLocation)) {
|
36176 | snapOffset[ axis ] -= shape.height / 2;
|
36177 | } else if (/bottom/.test(snapLocation)) {
|
36178 | snapOffset[ axis ] += shape.height / 2;
|
36179 | }
|
36180 | }
|
36181 |
|
36182 | return snapOffset[ axis ];
|
36183 | }
|
36184 |
|
36185 | function isHorizontal(axis) {
|
36186 | return axis === 'x';
|
36187 | }
|
36188 |
|
36189 | function isNorth(direction) {
|
36190 | return direction.charAt(0) === 'n';
|
36191 | }
|
36192 |
|
36193 | function isWest(direction) {
|
36194 | return direction.charAt(1) === 'w';
|
36195 | }
|
36196 |
|
36197 | |
36198 |
|
36199 |
|
36200 | function ResizeBehavior(eventBus, gridSnapping) {
|
36201 | CommandInterceptor.call(this, eventBus);
|
36202 |
|
36203 | this._gridSnapping = gridSnapping;
|
36204 |
|
36205 | var self = this;
|
36206 |
|
36207 | this.preExecute('shape.resize', function(event) {
|
36208 | var context = event.context,
|
36209 | hints = context.hints || {},
|
36210 | autoResize = hints.autoResize;
|
36211 |
|
36212 | if (!autoResize) {
|
36213 | return;
|
36214 | }
|
36215 |
|
36216 | var shape = context.shape,
|
36217 | newBounds = context.newBounds;
|
36218 |
|
36219 | if (isString(autoResize)) {
|
36220 | context.newBounds = self.snapComplex(newBounds, autoResize);
|
36221 | } else {
|
36222 | context.newBounds = self.snapSimple(shape, newBounds);
|
36223 | }
|
36224 | });
|
36225 | }
|
36226 |
|
36227 | ResizeBehavior.$inject = [
|
36228 | 'eventBus',
|
36229 | 'gridSnapping',
|
36230 | 'modeling'
|
36231 | ];
|
36232 |
|
36233 | inherits_browser(ResizeBehavior, CommandInterceptor);
|
36234 |
|
36235 | |
36236 |
|
36237 |
|
36238 |
|
36239 |
|
36240 |
|
36241 |
|
36242 |
|
36243 | ResizeBehavior.prototype.snapSimple = function(shape, newBounds) {
|
36244 | var gridSnapping = this._gridSnapping;
|
36245 |
|
36246 | newBounds.width = gridSnapping.snapValue(newBounds.width, {
|
36247 | min: newBounds.width
|
36248 | });
|
36249 |
|
36250 | newBounds.height = gridSnapping.snapValue(newBounds.height, {
|
36251 | min: newBounds.height
|
36252 | });
|
36253 |
|
36254 | newBounds.x = shape.x + (shape.width / 2) - (newBounds.width / 2);
|
36255 | newBounds.y = shape.y + (shape.height / 2) - (newBounds.height / 2);
|
36256 |
|
36257 | return newBounds;
|
36258 | };
|
36259 |
|
36260 | |
36261 |
|
36262 |
|
36263 |
|
36264 |
|
36265 |
|
36266 |
|
36267 |
|
36268 | ResizeBehavior.prototype.snapComplex = function(newBounds, directions) {
|
36269 | if (/w|e/.test(directions)) {
|
36270 | newBounds = this.snapHorizontally(newBounds, directions);
|
36271 | }
|
36272 |
|
36273 | if (/n|s/.test(directions)) {
|
36274 | newBounds = this.snapVertically(newBounds, directions);
|
36275 | }
|
36276 |
|
36277 | return newBounds;
|
36278 | };
|
36279 |
|
36280 | |
36281 |
|
36282 |
|
36283 |
|
36284 |
|
36285 |
|
36286 |
|
36287 |
|
36288 | ResizeBehavior.prototype.snapHorizontally = function(newBounds, directions) {
|
36289 | var gridSnapping = this._gridSnapping,
|
36290 | west = /w/.test(directions),
|
36291 | east = /e/.test(directions);
|
36292 |
|
36293 | var snappedNewBounds = {};
|
36294 |
|
36295 | snappedNewBounds.width = gridSnapping.snapValue(newBounds.width, {
|
36296 | min: newBounds.width
|
36297 | });
|
36298 |
|
36299 | if (east) {
|
36300 |
|
36301 |
|
36302 | if (west) {
|
36303 | snappedNewBounds.x = gridSnapping.snapValue(newBounds.x, {
|
36304 | max: newBounds.x
|
36305 | });
|
36306 |
|
36307 | snappedNewBounds.width += gridSnapping.snapValue(newBounds.x - snappedNewBounds.x, {
|
36308 | min: newBounds.x - snappedNewBounds.x
|
36309 | });
|
36310 | }
|
36311 |
|
36312 |
|
36313 | else {
|
36314 | newBounds.x = newBounds.x + newBounds.width - snappedNewBounds.width;
|
36315 | }
|
36316 | }
|
36317 |
|
36318 |
|
36319 | assign(newBounds, snappedNewBounds);
|
36320 |
|
36321 | return newBounds;
|
36322 | };
|
36323 |
|
36324 | |
36325 |
|
36326 |
|
36327 |
|
36328 |
|
36329 |
|
36330 |
|
36331 |
|
36332 | ResizeBehavior.prototype.snapVertically = function(newBounds, directions) {
|
36333 | var gridSnapping = this._gridSnapping,
|
36334 | north = /n/.test(directions),
|
36335 | south = /s/.test(directions);
|
36336 |
|
36337 | var snappedNewBounds = {};
|
36338 |
|
36339 | snappedNewBounds.height = gridSnapping.snapValue(newBounds.height, {
|
36340 | min: newBounds.height
|
36341 | });
|
36342 |
|
36343 | if (north) {
|
36344 |
|
36345 |
|
36346 | if (south) {
|
36347 | snappedNewBounds.y = gridSnapping.snapValue(newBounds.y, {
|
36348 | max: newBounds.y
|
36349 | });
|
36350 |
|
36351 | snappedNewBounds.height += gridSnapping.snapValue(newBounds.y - snappedNewBounds.y, {
|
36352 | min: newBounds.y - snappedNewBounds.y
|
36353 | });
|
36354 | }
|
36355 |
|
36356 |
|
36357 | else {
|
36358 | newBounds.y = newBounds.y + newBounds.height - snappedNewBounds.height;
|
36359 | }
|
36360 | }
|
36361 |
|
36362 |
|
36363 | assign(newBounds, snappedNewBounds);
|
36364 |
|
36365 | return newBounds;
|
36366 | };
|
36367 |
|
36368 | var HIGH_PRIORITY$3 = 2000;
|
36369 |
|
36370 | |
36371 |
|
36372 |
|
36373 | function SpaceToolBehavior(eventBus, gridSnapping) {
|
36374 | eventBus.on([
|
36375 | 'spaceTool.move',
|
36376 | 'spaceTool.end'
|
36377 | ], HIGH_PRIORITY$3, function(event) {
|
36378 | var context = event.context;
|
36379 |
|
36380 | if (!context.initialized) {
|
36381 | return;
|
36382 | }
|
36383 |
|
36384 | var axis = context.axis;
|
36385 |
|
36386 | if (axis === 'x') {
|
36387 |
|
36388 |
|
36389 | event.dx = gridSnapping.snapValue(event.dx);
|
36390 | } else {
|
36391 |
|
36392 |
|
36393 | event.dy = gridSnapping.snapValue(event.dy);
|
36394 | }
|
36395 | });
|
36396 | }
|
36397 |
|
36398 | SpaceToolBehavior.$inject = [
|
36399 | 'eventBus',
|
36400 | 'gridSnapping'
|
36401 | ];
|
36402 |
|
36403 | var GridSnappingBehaviorModule = {
|
36404 | __init__: [
|
36405 | 'gridSnappingResizeBehavior',
|
36406 | 'gridSnappingSpaceToolBehavior'
|
36407 | ],
|
36408 | gridSnappingResizeBehavior: [ 'type', ResizeBehavior ],
|
36409 | gridSnappingSpaceToolBehavior: [ 'type', SpaceToolBehavior ]
|
36410 | };
|
36411 |
|
36412 | var GridSnappingModule = {
|
36413 | __depends__: [ GridSnappingBehaviorModule ],
|
36414 | __init__: [ 'gridSnapping' ],
|
36415 | gridSnapping: [ 'type', GridSnapping ]
|
36416 | };
|
36417 |
|
36418 | function AutoPlaceBehavior(eventBus, gridSnapping) {
|
36419 | eventBus.on('autoPlace', function(context) {
|
36420 | var source = context.source,
|
36421 | sourceMid = getMid(source),
|
36422 | shape = context.shape;
|
36423 |
|
36424 | var position = getNewShapePosition(source, shape);
|
36425 |
|
36426 | [ 'x', 'y' ].forEach(function(axis) {
|
36427 | var options = {};
|
36428 |
|
36429 |
|
36430 | if (position[ axis ] === sourceMid[ axis ]) {
|
36431 | return;
|
36432 | }
|
36433 |
|
36434 | if (position[ axis ] > sourceMid[ axis ]) {
|
36435 | options.min = position[ axis ];
|
36436 | } else {
|
36437 | options.max = position[ axis ];
|
36438 | }
|
36439 |
|
36440 | if (is$1(shape, 'bpmn:TextAnnotation')) {
|
36441 |
|
36442 | if (isHorizontal$1(axis)) {
|
36443 | options.offset = -shape.width / 2;
|
36444 | } else {
|
36445 | options.offset = -shape.height / 2;
|
36446 | }
|
36447 |
|
36448 | }
|
36449 |
|
36450 | position[ axis ] = gridSnapping.snapValue(position[ axis ], options);
|
36451 |
|
36452 | });
|
36453 |
|
36454 |
|
36455 | return position;
|
36456 | });
|
36457 | }
|
36458 |
|
36459 | AutoPlaceBehavior.$inject = [
|
36460 | 'eventBus',
|
36461 | 'gridSnapping'
|
36462 | ];
|
36463 |
|
36464 |
|
36465 |
|
36466 | function isHorizontal$1(axis) {
|
36467 | return axis === 'x';
|
36468 | }
|
36469 |
|
36470 | var HIGHER_PRIORITY = 1750;
|
36471 |
|
36472 |
|
36473 | function CreateParticipantBehavior(canvas, eventBus, gridSnapping) {
|
36474 | eventBus.on([
|
36475 | 'create.start',
|
36476 | 'shape.move.start'
|
36477 | ], HIGHER_PRIORITY, function(event) {
|
36478 | var context = event.context,
|
36479 | shape = context.shape,
|
36480 | rootElement = canvas.getRootElement();
|
36481 |
|
36482 | if (!is$1(shape, 'bpmn:Participant') ||
|
36483 | !is$1(rootElement, 'bpmn:Process') ||
|
36484 | !rootElement.children.length) {
|
36485 | return;
|
36486 | }
|
36487 |
|
36488 | var createConstraints = context.createConstraints;
|
36489 |
|
36490 | if (!createConstraints) {
|
36491 | return;
|
36492 | }
|
36493 |
|
36494 | shape.width = gridSnapping.snapValue(shape.width, { min: shape.width });
|
36495 | shape.height = gridSnapping.snapValue(shape.height, { min: shape.height });
|
36496 | });
|
36497 | }
|
36498 |
|
36499 | CreateParticipantBehavior.$inject = [
|
36500 | 'canvas',
|
36501 | 'eventBus',
|
36502 | 'gridSnapping'
|
36503 | ];
|
36504 |
|
36505 | var HIGH_PRIORITY$4 = 3000;
|
36506 |
|
36507 |
|
36508 | |
36509 |
|
36510 |
|
36511 | function LayoutConnectionBehavior(eventBus, gridSnapping, modeling) {
|
36512 | CommandInterceptor.call(this, eventBus);
|
36513 |
|
36514 | this._gridSnapping = gridSnapping;
|
36515 |
|
36516 | var self = this;
|
36517 |
|
36518 | this.postExecuted([
|
36519 | 'connection.create',
|
36520 | 'connection.layout'
|
36521 | ], HIGH_PRIORITY$4, function(event) {
|
36522 | var context = event.context,
|
36523 | connection = context.connection,
|
36524 | hints = context.hints || {},
|
36525 | waypoints = connection.waypoints;
|
36526 |
|
36527 | if (hints.connectionStart || hints.connectionEnd) {
|
36528 | return;
|
36529 | }
|
36530 |
|
36531 | if (!hasMiddleSegments(waypoints)) {
|
36532 | return;
|
36533 | }
|
36534 |
|
36535 | modeling.updateWaypoints(connection, self.snapMiddleSegments(waypoints));
|
36536 | });
|
36537 | }
|
36538 |
|
36539 | LayoutConnectionBehavior.$inject = [
|
36540 | 'eventBus',
|
36541 | 'gridSnapping',
|
36542 | 'modeling'
|
36543 | ];
|
36544 |
|
36545 | inherits_browser(LayoutConnectionBehavior, CommandInterceptor);
|
36546 |
|
36547 | |
36548 |
|
36549 |
|
36550 |
|
36551 |
|
36552 |
|
36553 |
|
36554 | LayoutConnectionBehavior.prototype.snapMiddleSegments = function(waypoints) {
|
36555 | var gridSnapping = this._gridSnapping,
|
36556 | snapped;
|
36557 |
|
36558 | waypoints = waypoints.slice();
|
36559 |
|
36560 | for (var i = 1; i < waypoints.length - 2; i++) {
|
36561 |
|
36562 | snapped = snapSegment(gridSnapping, waypoints[i], waypoints[i + 1]);
|
36563 |
|
36564 | waypoints[i] = snapped[0];
|
36565 | waypoints[i + 1] = snapped[1];
|
36566 | }
|
36567 |
|
36568 | return waypoints;
|
36569 | };
|
36570 |
|
36571 |
|
36572 |
|
36573 |
|
36574 | |
36575 |
|
36576 |
|
36577 |
|
36578 |
|
36579 |
|
36580 |
|
36581 | function hasMiddleSegments(waypoints) {
|
36582 | return waypoints.length > 3;
|
36583 | }
|
36584 |
|
36585 | |
36586 |
|
36587 |
|
36588 |
|
36589 |
|
36590 |
|
36591 |
|
36592 | function horizontallyAligned(aligned) {
|
36593 | return aligned === 'h';
|
36594 | }
|
36595 |
|
36596 | |
36597 |
|
36598 |
|
36599 |
|
36600 |
|
36601 |
|
36602 |
|
36603 | function verticallyAligned(aligned) {
|
36604 | return aligned === 'v';
|
36605 | }
|
36606 |
|
36607 | |
36608 |
|
36609 |
|
36610 |
|
36611 |
|
36612 |
|
36613 |
|
36614 | function snapSegment(gridSnapping, segmentStart, segmentEnd) {
|
36615 |
|
36616 | var aligned = pointsAligned(segmentStart, segmentEnd);
|
36617 |
|
36618 | var snapped = {};
|
36619 |
|
36620 | if (horizontallyAligned(aligned)) {
|
36621 |
|
36622 |
|
36623 | snapped.y = gridSnapping.snapValue(segmentStart.y);
|
36624 | }
|
36625 |
|
36626 | if (verticallyAligned(aligned)) {
|
36627 |
|
36628 |
|
36629 | snapped.x = gridSnapping.snapValue(segmentStart.x);
|
36630 | }
|
36631 |
|
36632 | if ('x' in snapped || 'y' in snapped) {
|
36633 | segmentStart = assign({}, segmentStart, snapped);
|
36634 | segmentEnd = assign({}, segmentEnd, snapped);
|
36635 | }
|
36636 |
|
36637 | return [ segmentStart, segmentEnd ];
|
36638 | }
|
36639 |
|
36640 | var GridSnappingBehaviorModule$1 = {
|
36641 | __init__: [
|
36642 | 'gridSnappingAutoPlaceBehavior',
|
36643 | 'gridSnappingCreateParticipantBehavior',
|
36644 | 'gridSnappingLayoutConnectionBehavior',
|
36645 | ],
|
36646 | gridSnappingAutoPlaceBehavior: [ 'type', AutoPlaceBehavior ],
|
36647 | gridSnappingCreateParticipantBehavior: [ 'type', CreateParticipantBehavior ],
|
36648 | gridSnappingLayoutConnectionBehavior: [ 'type', LayoutConnectionBehavior ]
|
36649 | };
|
36650 |
|
36651 | var GridSnappingModule$1 = {
|
36652 | __depends__: [
|
36653 | GridSnappingModule,
|
36654 | GridSnappingBehaviorModule$1
|
36655 | ],
|
36656 | __init__: [ 'bpmnGridSnapping' ],
|
36657 | bpmnGridSnapping: [ 'type', BpmnGridSnapping ]
|
36658 | };
|
36659 |
|
36660 | var LABEL_WIDTH = 30,
|
36661 | LABEL_HEIGHT = 30;
|
36662 |
|
36663 |
|
36664 | |
36665 |
|
36666 |
|
36667 |
|
36668 |
|
36669 |
|
36670 | function BpmnInteractionEvents(eventBus, interactionEvents) {
|
36671 |
|
36672 | this._interactionEvents = interactionEvents;
|
36673 |
|
36674 | var self = this;
|
36675 |
|
36676 | eventBus.on([
|
36677 | 'interactionEvents.createHit',
|
36678 | 'interactionEvents.updateHit'
|
36679 | ], function(context) {
|
36680 | var element = context.element,
|
36681 | gfx = context.gfx;
|
36682 |
|
36683 | if (is$1(element, 'bpmn:Lane')) {
|
36684 | return self.createParticipantHit(element, gfx);
|
36685 | } else
|
36686 |
|
36687 | if (is$1(element, 'bpmn:Participant')) {
|
36688 | if (isExpanded(element)) {
|
36689 | return self.createParticipantHit(element, gfx);
|
36690 | } else {
|
36691 | return self.createDefaultHit(element, gfx);
|
36692 | }
|
36693 | } else
|
36694 |
|
36695 | if (is$1(element, 'bpmn:SubProcess')) {
|
36696 | if (isExpanded(element)) {
|
36697 | return self.createSubProcessHit(element, gfx);
|
36698 | } else {
|
36699 | return self.createDefaultHit(element, gfx);
|
36700 | }
|
36701 | }
|
36702 | });
|
36703 |
|
36704 | }
|
36705 |
|
36706 | BpmnInteractionEvents.$inject = [
|
36707 | 'eventBus',
|
36708 | 'interactionEvents'
|
36709 | ];
|
36710 |
|
36711 |
|
36712 | BpmnInteractionEvents.prototype.createDefaultHit = function(element, gfx) {
|
36713 | this._interactionEvents.removeHits(gfx);
|
36714 |
|
36715 | this._interactionEvents.createDefaultHit(element, gfx);
|
36716 |
|
36717 |
|
36718 | return true;
|
36719 | };
|
36720 |
|
36721 | BpmnInteractionEvents.prototype.createParticipantHit = function(element, gfx) {
|
36722 |
|
36723 |
|
36724 | this._interactionEvents.removeHits(gfx);
|
36725 |
|
36726 |
|
36727 | this._interactionEvents.createBoxHit(gfx, 'click-stroke', {
|
36728 | width: element.width,
|
36729 | height: element.height
|
36730 | });
|
36731 |
|
36732 |
|
36733 | this._interactionEvents.createBoxHit(gfx, 'all', {
|
36734 | width: LABEL_WIDTH,
|
36735 | height: element.height
|
36736 | });
|
36737 |
|
36738 |
|
36739 | return true;
|
36740 | };
|
36741 |
|
36742 | BpmnInteractionEvents.prototype.createSubProcessHit = function(element, gfx) {
|
36743 |
|
36744 |
|
36745 | this._interactionEvents.removeHits(gfx);
|
36746 |
|
36747 |
|
36748 | this._interactionEvents.createBoxHit(gfx, 'click-stroke', {
|
36749 | width: element.width,
|
36750 | height: element.height
|
36751 | });
|
36752 |
|
36753 |
|
36754 | this._interactionEvents.createBoxHit(gfx, 'all', {
|
36755 | width: element.width,
|
36756 | height: LABEL_HEIGHT
|
36757 | });
|
36758 |
|
36759 |
|
36760 | return true;
|
36761 | };
|
36762 |
|
36763 | var InteractionEventsModule$1 = {
|
36764 | __init__: [ 'bpmnInteractionEvents' ],
|
36765 | bpmnInteractionEvents: [ 'type', BpmnInteractionEvents ]
|
36766 | };
|
36767 |
|
36768 | |
36769 |
|
36770 |
|
36771 |
|
36772 |
|
36773 | function BpmnKeyboardBindings(injector) {
|
36774 | injector.invoke(KeyboardBindings, this);
|
36775 | }
|
36776 |
|
36777 | inherits_browser(BpmnKeyboardBindings, KeyboardBindings);
|
36778 |
|
36779 | BpmnKeyboardBindings.$inject = [
|
36780 | 'injector'
|
36781 | ];
|
36782 |
|
36783 |
|
36784 | |
36785 |
|
36786 |
|
36787 |
|
36788 |
|
36789 |
|
36790 | BpmnKeyboardBindings.prototype.registerBindings = function(keyboard, editorActions) {
|
36791 |
|
36792 |
|
36793 | KeyboardBindings.prototype.registerBindings.call(this, keyboard, editorActions);
|
36794 |
|
36795 | |
36796 |
|
36797 |
|
36798 |
|
36799 |
|
36800 |
|
36801 |
|
36802 | function addListener(action, fn) {
|
36803 |
|
36804 | if (editorActions.isRegistered(action)) {
|
36805 | keyboard.addListener(fn);
|
36806 | }
|
36807 | }
|
36808 |
|
36809 |
|
36810 |
|
36811 | addListener('selectElements', function(context) {
|
36812 |
|
36813 | var event = context.keyEvent;
|
36814 |
|
36815 | if (keyboard.isKey(['a', 'A'], event) && keyboard.isCmd(event)) {
|
36816 | editorActions.trigger('selectElements');
|
36817 |
|
36818 | return true;
|
36819 | }
|
36820 | });
|
36821 |
|
36822 |
|
36823 |
|
36824 | addListener('find', function(context) {
|
36825 |
|
36826 | var event = context.keyEvent;
|
36827 |
|
36828 | if (keyboard.isKey(['f', 'F'], event) && keyboard.isCmd(event)) {
|
36829 | editorActions.trigger('find');
|
36830 |
|
36831 | return true;
|
36832 | }
|
36833 | });
|
36834 |
|
36835 |
|
36836 |
|
36837 | addListener('spaceTool', function(context) {
|
36838 |
|
36839 | var event = context.keyEvent;
|
36840 |
|
36841 | if (keyboard.hasModifier(event)) {
|
36842 | return;
|
36843 | }
|
36844 |
|
36845 | if (keyboard.isKey(['s', 'S'], event)) {
|
36846 | editorActions.trigger('spaceTool');
|
36847 |
|
36848 | return true;
|
36849 | }
|
36850 | });
|
36851 |
|
36852 |
|
36853 |
|
36854 | addListener('lassoTool', function(context) {
|
36855 |
|
36856 | var event = context.keyEvent;
|
36857 |
|
36858 | if (keyboard.hasModifier(event)) {
|
36859 | return;
|
36860 | }
|
36861 |
|
36862 | if (keyboard.isKey(['l', 'L'], event)) {
|
36863 | editorActions.trigger('lassoTool');
|
36864 |
|
36865 | return true;
|
36866 | }
|
36867 | });
|
36868 |
|
36869 |
|
36870 |
|
36871 | addListener('handTool', function(context) {
|
36872 |
|
36873 | var event = context.keyEvent;
|
36874 |
|
36875 | if (keyboard.hasModifier(event)) {
|
36876 | return;
|
36877 | }
|
36878 |
|
36879 | if (keyboard.isKey(['h', 'H'], event)) {
|
36880 | editorActions.trigger('handTool');
|
36881 |
|
36882 | return true;
|
36883 | }
|
36884 | });
|
36885 |
|
36886 |
|
36887 |
|
36888 | addListener('globalConnectTool', function(context) {
|
36889 |
|
36890 | var event = context.keyEvent;
|
36891 |
|
36892 | if (keyboard.hasModifier(event)) {
|
36893 | return;
|
36894 | }
|
36895 |
|
36896 | if (keyboard.isKey(['c', 'C'], event)) {
|
36897 | editorActions.trigger('globalConnectTool');
|
36898 |
|
36899 | return true;
|
36900 | }
|
36901 | });
|
36902 |
|
36903 |
|
36904 |
|
36905 | addListener('directEditing', function(context) {
|
36906 |
|
36907 | var event = context.keyEvent;
|
36908 |
|
36909 | if (keyboard.hasModifier(event)) {
|
36910 | return;
|
36911 | }
|
36912 |
|
36913 | if (keyboard.isKey(['e', 'E'], event)) {
|
36914 | editorActions.trigger('directEditing');
|
36915 |
|
36916 | return true;
|
36917 | }
|
36918 | });
|
36919 |
|
36920 | };
|
36921 |
|
36922 | var KeyboardModule$1 = {
|
36923 | __depends__: [
|
36924 | KeyboardModule
|
36925 | ],
|
36926 | __init__: [ 'keyboardBindings' ],
|
36927 | keyboardBindings: [ 'type', BpmnKeyboardBindings ]
|
36928 | };
|
36929 |
|
36930 | var DEFAULT_CONFIG$1 = {
|
36931 | moveSpeed: 1,
|
36932 | moveSpeedAccelerated: 10
|
36933 | };
|
36934 |
|
36935 | var HIGHER_PRIORITY$1 = 1500;
|
36936 |
|
36937 | var LEFT = 'left';
|
36938 | var UP = 'up';
|
36939 | var RIGHT = 'right';
|
36940 | var DOWN = 'down';
|
36941 |
|
36942 | var KEY_TO_DIRECTION = {
|
36943 | ArrowLeft: LEFT,
|
36944 | Left: LEFT,
|
36945 | ArrowUp: UP,
|
36946 | Up: UP,
|
36947 | ArrowRight: RIGHT,
|
36948 | Right: RIGHT,
|
36949 | ArrowDown: DOWN,
|
36950 | Down: DOWN
|
36951 | };
|
36952 |
|
36953 | var DIRECTIONS_DELTA = {
|
36954 | left: function(speed) {
|
36955 | return {
|
36956 | x: -speed,
|
36957 | y: 0
|
36958 | };
|
36959 | },
|
36960 | up: function(speed) {
|
36961 | return {
|
36962 | x: 0,
|
36963 | y: -speed
|
36964 | };
|
36965 | },
|
36966 | right: function(speed) {
|
36967 | return {
|
36968 | x: speed,
|
36969 | y: 0
|
36970 | };
|
36971 | },
|
36972 | down: function(speed) {
|
36973 | return {
|
36974 | x: 0,
|
36975 | y: speed
|
36976 | };
|
36977 | }
|
36978 | };
|
36979 |
|
36980 |
|
36981 | |
36982 |
|
36983 |
|
36984 |
|
36985 |
|
36986 |
|
36987 |
|
36988 |
|
36989 |
|
36990 |
|
36991 |
|
36992 |
|
36993 | function KeyboardMoveSelection(
|
36994 | config, keyboard,
|
36995 | modeling, selection
|
36996 | ) {
|
36997 |
|
36998 | var self = this;
|
36999 |
|
37000 | this._config = assign({}, DEFAULT_CONFIG$1, config || {});
|
37001 |
|
37002 | keyboard.addListener(HIGHER_PRIORITY$1, function(event) {
|
37003 |
|
37004 | var keyEvent = event.keyEvent;
|
37005 |
|
37006 | var direction = KEY_TO_DIRECTION[keyEvent.key];
|
37007 |
|
37008 | if (!direction) {
|
37009 | return;
|
37010 | }
|
37011 |
|
37012 | if (keyboard.isCmd(keyEvent)) {
|
37013 | return;
|
37014 | }
|
37015 |
|
37016 | var accelerated = keyboard.isShift(keyEvent);
|
37017 |
|
37018 | self.moveSelection(direction, accelerated);
|
37019 |
|
37020 | return true;
|
37021 | });
|
37022 |
|
37023 |
|
37024 | |
37025 |
|
37026 |
|
37027 |
|
37028 |
|
37029 |
|
37030 |
|
37031 | this.moveSelection = function(direction, accelerated) {
|
37032 |
|
37033 | var selectedElements = selection.get();
|
37034 |
|
37035 | if (!selectedElements.length) {
|
37036 | return;
|
37037 | }
|
37038 |
|
37039 | var speed = this._config[
|
37040 | accelerated ?
|
37041 | 'moveSpeedAccelerated' :
|
37042 | 'moveSpeed'
|
37043 | ];
|
37044 |
|
37045 | var delta = DIRECTIONS_DELTA[direction](speed);
|
37046 |
|
37047 | modeling.moveElements(selectedElements, delta);
|
37048 | };
|
37049 |
|
37050 | }
|
37051 |
|
37052 | KeyboardMoveSelection.$inject = [
|
37053 | 'config.keyboardMoveSelection',
|
37054 | 'keyboard',
|
37055 | 'modeling',
|
37056 | 'selection'
|
37057 | ];
|
37058 |
|
37059 | var KeyboardMoveSelectionModule = {
|
37060 | __depends__: [
|
37061 | KeyboardModule,
|
37062 | SelectionModule
|
37063 | ],
|
37064 | __init__: [
|
37065 | 'keyboardMoveSelection'
|
37066 | ],
|
37067 | keyboardMoveSelection: [ 'type', KeyboardMoveSelection ]
|
37068 | };
|
37069 |
|
37070 | |
37071 |
|
37072 |
|
37073 |
|
37074 |
|
37075 |
|
37076 |
|
37077 |
|
37078 |
|
37079 |
|
37080 |
|
37081 |
|
37082 | function ChangeSupport(
|
37083 | eventBus, canvas, elementRegistry,
|
37084 | graphicsFactory) {
|
37085 |
|
37086 |
|
37087 |
|
37088 |
|
37089 | eventBus.on('element.changed', function(event) {
|
37090 |
|
37091 | var element = event.element;
|
37092 |
|
37093 |
|
37094 |
|
37095 | if (element.parent || element === canvas.getRootElement()) {
|
37096 | event.gfx = elementRegistry.getGraphics(element);
|
37097 | }
|
37098 |
|
37099 |
|
37100 | if (!event.gfx) {
|
37101 | return;
|
37102 | }
|
37103 |
|
37104 | eventBus.fire(getType(element) + '.changed', event);
|
37105 | });
|
37106 |
|
37107 | eventBus.on('elements.changed', function(event) {
|
37108 |
|
37109 | var elements = event.elements;
|
37110 |
|
37111 | elements.forEach(function(e) {
|
37112 | eventBus.fire('element.changed', { element: e });
|
37113 | });
|
37114 |
|
37115 | graphicsFactory.updateContainments(elements);
|
37116 | });
|
37117 |
|
37118 | eventBus.on('shape.changed', function(event) {
|
37119 | graphicsFactory.update('shape', event.element, event.gfx);
|
37120 | });
|
37121 |
|
37122 | eventBus.on('connection.changed', function(event) {
|
37123 | graphicsFactory.update('connection', event.element, event.gfx);
|
37124 | });
|
37125 | }
|
37126 |
|
37127 | ChangeSupport.$inject = [
|
37128 | 'eventBus',
|
37129 | 'canvas',
|
37130 | 'elementRegistry',
|
37131 | 'graphicsFactory'
|
37132 | ];
|
37133 |
|
37134 | var ChangeSupportModule = {
|
37135 | __init__: [ 'changeSupport'],
|
37136 | changeSupport: [ 'type', ChangeSupport ]
|
37137 | };
|
37138 |
|
37139 | var DEFAULT_MIN_WIDTH = 10;
|
37140 |
|
37141 |
|
37142 | |
37143 |
|
37144 |
|
37145 |
|
37146 |
|
37147 |
|
37148 |
|
37149 |
|
37150 |
|
37151 |
|
37152 |
|
37153 |
|
37154 |
|
37155 |
|
37156 |
|
37157 |
|
37158 |
|
37159 |
|
37160 |
|
37161 |
|
37162 |
|
37163 |
|
37164 |
|
37165 |
|
37166 |
|
37167 |
|
37168 |
|
37169 |
|
37170 |
|
37171 |
|
37172 |
|
37173 |
|
37174 |
|
37175 |
|
37176 |
|
37177 |
|
37178 |
|
37179 | function Resize(eventBus, rules, modeling, dragging) {
|
37180 |
|
37181 | this._dragging = dragging;
|
37182 | this._rules = rules;
|
37183 |
|
37184 | var self = this;
|
37185 |
|
37186 |
|
37187 | |
37188 |
|
37189 |
|
37190 |
|
37191 |
|
37192 |
|
37193 | function handleMove(context, delta) {
|
37194 |
|
37195 | var shape = context.shape,
|
37196 | direction = context.direction,
|
37197 | resizeConstraints = context.resizeConstraints,
|
37198 | newBounds;
|
37199 |
|
37200 | context.delta = delta;
|
37201 |
|
37202 | newBounds = resizeBounds(shape, direction, delta);
|
37203 |
|
37204 |
|
37205 | context.newBounds = ensureConstraints$1(newBounds, resizeConstraints);
|
37206 |
|
37207 |
|
37208 | context.canExecute = self.canResize(context);
|
37209 | }
|
37210 |
|
37211 | |
37212 |
|
37213 |
|
37214 |
|
37215 |
|
37216 | function handleStart(context) {
|
37217 |
|
37218 | var resizeConstraints = context.resizeConstraints,
|
37219 |
|
37220 |
|
37221 | minBounds = context.minBounds;
|
37222 |
|
37223 | if (resizeConstraints !== undefined) {
|
37224 | return;
|
37225 | }
|
37226 |
|
37227 | if (minBounds === undefined) {
|
37228 | minBounds = self.computeMinResizeBox(context);
|
37229 | }
|
37230 |
|
37231 | context.resizeConstraints = {
|
37232 | min: asTRBL(minBounds)
|
37233 | };
|
37234 | }
|
37235 |
|
37236 | |
37237 |
|
37238 |
|
37239 |
|
37240 |
|
37241 | function handleEnd(context) {
|
37242 | var shape = context.shape,
|
37243 | canExecute = context.canExecute,
|
37244 | newBounds = context.newBounds;
|
37245 |
|
37246 | if (canExecute) {
|
37247 |
|
37248 |
|
37249 |
|
37250 | newBounds = roundBounds(newBounds);
|
37251 |
|
37252 | if (!boundsChanged$1(shape, newBounds)) {
|
37253 |
|
37254 |
|
37255 | return;
|
37256 | }
|
37257 |
|
37258 |
|
37259 | modeling.resizeShape(shape, newBounds);
|
37260 | }
|
37261 | }
|
37262 |
|
37263 |
|
37264 | eventBus.on('resize.start', function(event) {
|
37265 | handleStart(event.context);
|
37266 | });
|
37267 |
|
37268 | eventBus.on('resize.move', function(event) {
|
37269 | var delta = {
|
37270 | x: event.dx,
|
37271 | y: event.dy
|
37272 | };
|
37273 |
|
37274 | handleMove(event.context, delta);
|
37275 | });
|
37276 |
|
37277 | eventBus.on('resize.end', function(event) {
|
37278 | handleEnd(event.context);
|
37279 | });
|
37280 |
|
37281 | }
|
37282 |
|
37283 |
|
37284 | Resize.prototype.canResize = function(context) {
|
37285 | var rules = this._rules;
|
37286 |
|
37287 | var ctx = pick(context, [ 'newBounds', 'shape', 'delta', 'direction' ]);
|
37288 |
|
37289 | return rules.allowed('shape.resize', ctx);
|
37290 | };
|
37291 |
|
37292 | |
37293 |
|
37294 |
|
37295 |
|
37296 |
|
37297 |
|
37298 |
|
37299 |
|
37300 |
|
37301 |
|
37302 | Resize.prototype.activate = function(event, shape, contextOrDirection) {
|
37303 | var dragging = this._dragging,
|
37304 | context,
|
37305 | direction;
|
37306 |
|
37307 | if (typeof contextOrDirection === 'string') {
|
37308 | contextOrDirection = {
|
37309 | direction: contextOrDirection
|
37310 | };
|
37311 | }
|
37312 |
|
37313 | context = assign({ shape: shape }, contextOrDirection);
|
37314 |
|
37315 | direction = context.direction;
|
37316 |
|
37317 | if (!direction) {
|
37318 | throw new Error('must provide a direction (nw|se|ne|sw)');
|
37319 | }
|
37320 |
|
37321 | var referencePoint = {
|
37322 | x: /w/.test(direction) ? shape.x : shape.x + shape.width,
|
37323 | y: /n/.test(direction) ? shape.y : shape.y + shape.height
|
37324 | };
|
37325 |
|
37326 | dragging.init(event, referencePoint, 'resize', {
|
37327 | autoActivate: true,
|
37328 | cursor: 'resize-' + (/nw|se/.test(direction) ? 'nwse' : 'nesw'),
|
37329 | data: {
|
37330 | shape: shape,
|
37331 | context: context
|
37332 | }
|
37333 | });
|
37334 | };
|
37335 |
|
37336 | Resize.prototype.computeMinResizeBox = function(context) {
|
37337 | var shape = context.shape,
|
37338 | direction = context.direction,
|
37339 | minDimensions,
|
37340 | childrenBounds;
|
37341 |
|
37342 | minDimensions = context.minDimensions || {
|
37343 | width: DEFAULT_MIN_WIDTH,
|
37344 | height: DEFAULT_MIN_WIDTH
|
37345 | };
|
37346 |
|
37347 |
|
37348 | childrenBounds = computeChildrenBBox(shape, context.childrenBoxPadding);
|
37349 |
|
37350 |
|
37351 |
|
37352 | return getMinResizeBounds(direction, shape, minDimensions, childrenBounds);
|
37353 | };
|
37354 |
|
37355 |
|
37356 | Resize.$inject = [
|
37357 | 'eventBus',
|
37358 | 'rules',
|
37359 | 'modeling',
|
37360 | 'dragging'
|
37361 | ];
|
37362 |
|
37363 |
|
37364 |
|
37365 | function boundsChanged$1(shape, newBounds) {
|
37366 | return shape.x !== newBounds.x ||
|
37367 | shape.y !== newBounds.y ||
|
37368 | shape.width !== newBounds.width ||
|
37369 | shape.height !== newBounds.height;
|
37370 | }
|
37371 |
|
37372 | var MARKER_RESIZING = 'djs-resizing',
|
37373 | MARKER_RESIZE_NOT_OK = 'resize-not-ok';
|
37374 |
|
37375 | var LOW_PRIORITY$8 = 500;
|
37376 |
|
37377 |
|
37378 | |
37379 |
|
37380 |
|
37381 |
|
37382 |
|
37383 |
|
37384 |
|
37385 | function ResizePreview(eventBus, canvas, previewSupport) {
|
37386 |
|
37387 | |
37388 |
|
37389 |
|
37390 |
|
37391 |
|
37392 | function updateFrame(context) {
|
37393 |
|
37394 | var shape = context.shape,
|
37395 | bounds = context.newBounds,
|
37396 | frame = context.frame;
|
37397 |
|
37398 | if (!frame) {
|
37399 | frame = context.frame = previewSupport.addFrame(shape, canvas.getDefaultLayer());
|
37400 |
|
37401 | canvas.addMarker(shape, MARKER_RESIZING);
|
37402 | }
|
37403 |
|
37404 | if (bounds.width > 5) {
|
37405 | attr$1(frame, { x: bounds.x, width: bounds.width });
|
37406 | }
|
37407 |
|
37408 | if (bounds.height > 5) {
|
37409 | attr$1(frame, { y: bounds.y, height: bounds.height });
|
37410 | }
|
37411 |
|
37412 | if (context.canExecute) {
|
37413 | classes$1(frame).remove(MARKER_RESIZE_NOT_OK);
|
37414 | } else {
|
37415 | classes$1(frame).add(MARKER_RESIZE_NOT_OK);
|
37416 | }
|
37417 | }
|
37418 |
|
37419 | |
37420 |
|
37421 |
|
37422 |
|
37423 |
|
37424 | function removeFrame(context) {
|
37425 | var shape = context.shape,
|
37426 | frame = context.frame;
|
37427 |
|
37428 | if (frame) {
|
37429 | remove$1(context.frame);
|
37430 | }
|
37431 |
|
37432 | canvas.removeMarker(shape, MARKER_RESIZING);
|
37433 | }
|
37434 |
|
37435 |
|
37436 | eventBus.on('resize.move', LOW_PRIORITY$8, function(event) {
|
37437 | updateFrame(event.context);
|
37438 | });
|
37439 |
|
37440 |
|
37441 | eventBus.on('resize.cleanup', function(event) {
|
37442 | removeFrame(event.context);
|
37443 | });
|
37444 |
|
37445 | }
|
37446 |
|
37447 | ResizePreview.$inject = [
|
37448 | 'eventBus',
|
37449 | 'canvas',
|
37450 | 'previewSupport'
|
37451 | ];
|
37452 |
|
37453 | var HANDLE_OFFSET = -2,
|
37454 | HANDLE_SIZE = 5,
|
37455 | HANDLE_HIT_SIZE = 20;
|
37456 |
|
37457 | var CLS_RESIZER = 'djs-resizer';
|
37458 |
|
37459 |
|
37460 | |
37461 |
|
37462 |
|
37463 |
|
37464 |
|
37465 |
|
37466 |
|
37467 |
|
37468 | function ResizeHandles(eventBus, canvas, selection, resize) {
|
37469 |
|
37470 | this._resize = resize;
|
37471 | this._canvas = canvas;
|
37472 |
|
37473 | var self = this;
|
37474 |
|
37475 | eventBus.on('selection.changed', function(e) {
|
37476 | var newSelection = e.newSelection;
|
37477 |
|
37478 |
|
37479 | self.removeResizers();
|
37480 |
|
37481 |
|
37482 | if (newSelection.length === 1) {
|
37483 | forEach(newSelection, bind(self.addResizer, self));
|
37484 | }
|
37485 | });
|
37486 |
|
37487 | eventBus.on('shape.changed', function(e) {
|
37488 | var shape = e.element;
|
37489 |
|
37490 | if (selection.isSelected(shape)) {
|
37491 | self.removeResizers();
|
37492 |
|
37493 | self.addResizer(shape);
|
37494 | }
|
37495 | });
|
37496 | }
|
37497 |
|
37498 |
|
37499 | ResizeHandles.prototype.makeDraggable = function(element, gfx, direction) {
|
37500 | var resize = this._resize;
|
37501 |
|
37502 | function startResize(event) {
|
37503 |
|
37504 |
|
37505 | if (isPrimaryButton(event)) {
|
37506 | resize.activate(event, element, direction);
|
37507 | }
|
37508 | }
|
37509 |
|
37510 | componentEvent.bind(gfx, 'mousedown', startResize);
|
37511 | componentEvent.bind(gfx, 'touchstart', startResize);
|
37512 | };
|
37513 |
|
37514 |
|
37515 | ResizeHandles.prototype._createResizer = function(element, x, y, rotation, direction) {
|
37516 | var resizersParent = this._getResizersParent();
|
37517 |
|
37518 | var group = create('g');
|
37519 | classes$1(group).add(CLS_RESIZER);
|
37520 | classes$1(group).add(CLS_RESIZER + '-' + element.id);
|
37521 | classes$1(group).add(CLS_RESIZER + '-' + direction);
|
37522 |
|
37523 | append(resizersParent, group);
|
37524 |
|
37525 | var origin = -HANDLE_SIZE + HANDLE_OFFSET;
|
37526 |
|
37527 |
|
37528 | var visual = create('rect');
|
37529 | attr$1(visual, {
|
37530 | x: origin,
|
37531 | y: origin,
|
37532 | width: HANDLE_SIZE,
|
37533 | height: HANDLE_SIZE
|
37534 | });
|
37535 | classes$1(visual).add(CLS_RESIZER + '-visual');
|
37536 |
|
37537 | append(group, visual);
|
37538 |
|
37539 | var hit = create('rect');
|
37540 | attr$1(hit, {
|
37541 | x: origin,
|
37542 | y: origin,
|
37543 | width: HANDLE_HIT_SIZE,
|
37544 | height: HANDLE_HIT_SIZE
|
37545 | });
|
37546 | classes$1(hit).add(CLS_RESIZER + '-hit');
|
37547 |
|
37548 | append(group, hit);
|
37549 |
|
37550 | transform$1(group, x, y, rotation);
|
37551 |
|
37552 | return group;
|
37553 | };
|
37554 |
|
37555 | ResizeHandles.prototype.createResizer = function(element, direction) {
|
37556 | var resizer;
|
37557 |
|
37558 | var trbl = asTRBL(element);
|
37559 |
|
37560 | if (direction === 'nw') {
|
37561 | resizer = this._createResizer(element, trbl.left, trbl.top, 0, direction);
|
37562 | } else if (direction === 'ne') {
|
37563 | resizer = this._createResizer(element, trbl.right, trbl.top, 90, direction);
|
37564 | } else if (direction === 'se') {
|
37565 | resizer = this._createResizer(element, trbl.right, trbl.bottom, 180, direction);
|
37566 | } else {
|
37567 | resizer = this._createResizer(element, trbl.left, trbl.bottom, 270, direction);
|
37568 | }
|
37569 |
|
37570 | this.makeDraggable(element, resizer, direction);
|
37571 | };
|
37572 |
|
37573 |
|
37574 |
|
37575 | |
37576 |
|
37577 |
|
37578 |
|
37579 |
|
37580 | ResizeHandles.prototype.addResizer = function(shape) {
|
37581 | var resize = this._resize;
|
37582 |
|
37583 | if (!resize.canResize({ shape: shape })) {
|
37584 | return;
|
37585 | }
|
37586 |
|
37587 | this.createResizer(shape, 'nw');
|
37588 | this.createResizer(shape, 'ne');
|
37589 | this.createResizer(shape, 'se');
|
37590 | this.createResizer(shape, 'sw');
|
37591 | };
|
37592 |
|
37593 | |
37594 |
|
37595 |
|
37596 | ResizeHandles.prototype.removeResizers = function() {
|
37597 | var resizersParent = this._getResizersParent();
|
37598 |
|
37599 | clear$1(resizersParent);
|
37600 | };
|
37601 |
|
37602 | ResizeHandles.prototype._getResizersParent = function() {
|
37603 | return this._canvas.getLayer('resizers');
|
37604 | };
|
37605 |
|
37606 | ResizeHandles.$inject = [
|
37607 | 'eventBus',
|
37608 | 'canvas',
|
37609 | 'selection',
|
37610 | 'resize'
|
37611 | ];
|
37612 |
|
37613 | var ResizeModule = {
|
37614 | __depends__: [
|
37615 | RulesModule,
|
37616 | DraggingModule,
|
37617 | PreviewSupportModule
|
37618 | ],
|
37619 | __init__: [
|
37620 | 'resize',
|
37621 | 'resizePreview',
|
37622 | 'resizeHandles'
|
37623 | ],
|
37624 | resize: [ 'type', Resize ],
|
37625 | resizePreview: [ 'type', ResizePreview ],
|
37626 | resizeHandles: [ 'type', ResizeHandles ]
|
37627 | };
|
37628 |
|
37629 | |
37630 |
|
37631 |
|
37632 |
|
37633 |
|
37634 |
|
37635 |
|
37636 |
|
37637 | function createCategoryValue(definitions, bpmnFactory) {
|
37638 | var categoryValue = bpmnFactory.create('bpmn:CategoryValue'),
|
37639 | category = bpmnFactory.create('bpmn:Category', {
|
37640 | categoryValue: [ categoryValue ]
|
37641 | });
|
37642 |
|
37643 |
|
37644 | add$1(definitions.get('rootElements'), category);
|
37645 | getBusinessObject(category).$parent = definitions;
|
37646 | getBusinessObject(categoryValue).$parent = category;
|
37647 |
|
37648 | return categoryValue;
|
37649 |
|
37650 | }
|
37651 |
|
37652 | function LabelEditingProvider(
|
37653 | eventBus, bpmnFactory, canvas, directEditing,
|
37654 | modeling, resizeHandles, textRenderer) {
|
37655 |
|
37656 | this._bpmnFactory = bpmnFactory;
|
37657 | this._canvas = canvas;
|
37658 | this._modeling = modeling;
|
37659 | this._textRenderer = textRenderer;
|
37660 |
|
37661 | directEditing.registerProvider(this);
|
37662 |
|
37663 |
|
37664 | eventBus.on('element.dblclick', function(event) {
|
37665 | activateDirectEdit(event.element, true);
|
37666 | });
|
37667 |
|
37668 |
|
37669 | eventBus.on([
|
37670 | 'element.mousedown',
|
37671 | 'drag.init',
|
37672 | 'canvas.viewbox.changing',
|
37673 | 'autoPlace',
|
37674 | 'popupMenu.open'
|
37675 | ], function(event) {
|
37676 |
|
37677 | if (directEditing.isActive()) {
|
37678 | directEditing.complete();
|
37679 | }
|
37680 | });
|
37681 |
|
37682 |
|
37683 | eventBus.on([ 'commandStack.changed' ], function(e) {
|
37684 | if (directEditing.isActive()) {
|
37685 | directEditing.cancel();
|
37686 | }
|
37687 | });
|
37688 |
|
37689 |
|
37690 | eventBus.on('directEditing.activate', function(event) {
|
37691 | resizeHandles.removeResizers();
|
37692 | });
|
37693 |
|
37694 | eventBus.on('create.end', 500, function(event) {
|
37695 |
|
37696 | var context = event.context,
|
37697 | element = context.shape,
|
37698 | canExecute = event.context.canExecute,
|
37699 | isTouch = event.isTouch;
|
37700 |
|
37701 |
|
37702 |
|
37703 |
|
37704 |
|
37705 |
|
37706 |
|
37707 |
|
37708 |
|
37709 | if (isTouch) {
|
37710 | return;
|
37711 | }
|
37712 |
|
37713 | if (!canExecute) {
|
37714 | return;
|
37715 | }
|
37716 |
|
37717 | if (context.hints && context.hints.createElementsBehavior === false) {
|
37718 | return;
|
37719 | }
|
37720 |
|
37721 | activateDirectEdit(element);
|
37722 | });
|
37723 |
|
37724 | eventBus.on('autoPlace.end', 500, function(event) {
|
37725 | activateDirectEdit(event.shape);
|
37726 | });
|
37727 |
|
37728 |
|
37729 | function activateDirectEdit(element, force) {
|
37730 | if (force ||
|
37731 | isAny(element, [ 'bpmn:Task', 'bpmn:TextAnnotation', 'bpmn:Group' ]) ||
|
37732 | isCollapsedSubProcess(element)) {
|
37733 |
|
37734 | directEditing.activate(element);
|
37735 | }
|
37736 | }
|
37737 |
|
37738 | }
|
37739 |
|
37740 | LabelEditingProvider.$inject = [
|
37741 | 'eventBus',
|
37742 | 'bpmnFactory',
|
37743 | 'canvas',
|
37744 | 'directEditing',
|
37745 | 'modeling',
|
37746 | 'resizeHandles',
|
37747 | 'textRenderer'
|
37748 | ];
|
37749 |
|
37750 |
|
37751 | |
37752 |
|
37753 |
|
37754 |
|
37755 |
|
37756 |
|
37757 |
|
37758 | LabelEditingProvider.prototype.activate = function(element) {
|
37759 |
|
37760 |
|
37761 | var text = getLabel(element);
|
37762 |
|
37763 | if (text === undefined) {
|
37764 | return;
|
37765 | }
|
37766 |
|
37767 | var context = {
|
37768 | text: text
|
37769 | };
|
37770 |
|
37771 |
|
37772 | var bounds = this.getEditingBBox(element);
|
37773 |
|
37774 | assign(context, bounds);
|
37775 |
|
37776 | var options = {};
|
37777 |
|
37778 |
|
37779 | if (
|
37780 | isAny(element, [
|
37781 | 'bpmn:Task',
|
37782 | 'bpmn:Participant',
|
37783 | 'bpmn:Lane',
|
37784 | 'bpmn:CallActivity'
|
37785 | ]) ||
|
37786 | isCollapsedSubProcess(element)
|
37787 | ) {
|
37788 | assign(options, {
|
37789 | centerVertically: true
|
37790 | });
|
37791 | }
|
37792 |
|
37793 |
|
37794 | if (isLabelExternal(element)) {
|
37795 | assign(options, {
|
37796 | autoResize: true
|
37797 | });
|
37798 | }
|
37799 |
|
37800 |
|
37801 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
37802 | assign(options, {
|
37803 | resizable: true,
|
37804 | autoResize: true
|
37805 | });
|
37806 | }
|
37807 |
|
37808 | assign(context, {
|
37809 | options: options
|
37810 | });
|
37811 |
|
37812 | return context;
|
37813 | };
|
37814 |
|
37815 |
|
37816 | |
37817 |
|
37818 |
|
37819 |
|
37820 |
|
37821 |
|
37822 |
|
37823 |
|
37824 | LabelEditingProvider.prototype.getEditingBBox = function(element) {
|
37825 | var canvas = this._canvas;
|
37826 |
|
37827 | var target = element.label || element;
|
37828 |
|
37829 | var bbox = canvas.getAbsoluteBBox(target);
|
37830 |
|
37831 | var mid = {
|
37832 | x: bbox.x + bbox.width / 2,
|
37833 | y: bbox.y + bbox.height / 2
|
37834 | };
|
37835 |
|
37836 |
|
37837 | var bounds = { x: bbox.x, y: bbox.y };
|
37838 |
|
37839 | var zoom = canvas.zoom();
|
37840 |
|
37841 | var defaultStyle = this._textRenderer.getDefaultStyle(),
|
37842 | externalStyle = this._textRenderer.getExternalStyle();
|
37843 |
|
37844 |
|
37845 | var externalFontSize = externalStyle.fontSize * zoom,
|
37846 | externalLineHeight = externalStyle.lineHeight,
|
37847 | defaultFontSize = defaultStyle.fontSize * zoom,
|
37848 | defaultLineHeight = defaultStyle.lineHeight;
|
37849 |
|
37850 | var style = {
|
37851 | fontFamily: this._textRenderer.getDefaultStyle().fontFamily,
|
37852 | fontWeight: this._textRenderer.getDefaultStyle().fontWeight
|
37853 | };
|
37854 |
|
37855 |
|
37856 | if (is$1(element, 'bpmn:Lane') || isExpandedPool(element)) {
|
37857 |
|
37858 | assign(bounds, {
|
37859 | width: bbox.height,
|
37860 | height: 30 * zoom,
|
37861 | x: bbox.x - bbox.height / 2 + (15 * zoom),
|
37862 | y: mid.y - (30 * zoom) / 2
|
37863 | });
|
37864 |
|
37865 | assign(style, {
|
37866 | fontSize: defaultFontSize + 'px',
|
37867 | lineHeight: defaultLineHeight,
|
37868 | paddingTop: (7 * zoom) + 'px',
|
37869 | paddingBottom: (7 * zoom) + 'px',
|
37870 | paddingLeft: (5 * zoom) + 'px',
|
37871 | paddingRight: (5 * zoom) + 'px',
|
37872 | transform: 'rotate(-90deg)'
|
37873 | });
|
37874 | }
|
37875 |
|
37876 |
|
37877 |
|
37878 |
|
37879 | if (isAny(element, [ 'bpmn:Task', 'bpmn:CallActivity']) ||
|
37880 | isCollapsedPool(element) ||
|
37881 | isCollapsedSubProcess(element)) {
|
37882 |
|
37883 | assign(bounds, {
|
37884 | width: bbox.width,
|
37885 | height: bbox.height
|
37886 | });
|
37887 |
|
37888 | assign(style, {
|
37889 | fontSize: defaultFontSize + 'px',
|
37890 | lineHeight: defaultLineHeight,
|
37891 | paddingTop: (7 * zoom) + 'px',
|
37892 | paddingBottom: (7 * zoom) + 'px',
|
37893 | paddingLeft: (5 * zoom) + 'px',
|
37894 | paddingRight: (5 * zoom) + 'px'
|
37895 | });
|
37896 | }
|
37897 |
|
37898 |
|
37899 |
|
37900 | if (isExpandedSubProcess(element)) {
|
37901 | assign(bounds, {
|
37902 | width: bbox.width,
|
37903 | x: bbox.x
|
37904 | });
|
37905 |
|
37906 | assign(style, {
|
37907 | fontSize: defaultFontSize + 'px',
|
37908 | lineHeight: defaultLineHeight,
|
37909 | paddingTop: (7 * zoom) + 'px',
|
37910 | paddingBottom: (7 * zoom) + 'px',
|
37911 | paddingLeft: (5 * zoom) + 'px',
|
37912 | paddingRight: (5 * zoom) + 'px'
|
37913 | });
|
37914 | }
|
37915 |
|
37916 | var width = 90 * zoom,
|
37917 | paddingTop = 7 * zoom,
|
37918 | paddingBottom = 4 * zoom;
|
37919 |
|
37920 |
|
37921 | if (target.labelTarget) {
|
37922 | assign(bounds, {
|
37923 | width: width,
|
37924 | height: bbox.height + paddingTop + paddingBottom,
|
37925 | x: mid.x - width / 2,
|
37926 | y: bbox.y - paddingTop
|
37927 | });
|
37928 |
|
37929 | assign(style, {
|
37930 | fontSize: externalFontSize + 'px',
|
37931 | lineHeight: externalLineHeight,
|
37932 | paddingTop: paddingTop + 'px',
|
37933 | paddingBottom: paddingBottom + 'px'
|
37934 | });
|
37935 | }
|
37936 |
|
37937 |
|
37938 | if (isLabelExternal(target)
|
37939 | && !hasExternalLabel(target)
|
37940 | && !isLabel(target)) {
|
37941 |
|
37942 | var externalLabelMid = getExternalLabelMid(element);
|
37943 |
|
37944 | var absoluteBBox = canvas.getAbsoluteBBox({
|
37945 | x: externalLabelMid.x,
|
37946 | y: externalLabelMid.y,
|
37947 | width: 0,
|
37948 | height: 0
|
37949 | });
|
37950 |
|
37951 | var height = externalFontSize + paddingTop + paddingBottom;
|
37952 |
|
37953 | assign(bounds, {
|
37954 | width: width,
|
37955 | height: height,
|
37956 | x: absoluteBBox.x - width / 2,
|
37957 | y: absoluteBBox.y - height / 2
|
37958 | });
|
37959 |
|
37960 | assign(style, {
|
37961 | fontSize: externalFontSize + 'px',
|
37962 | lineHeight: externalLineHeight,
|
37963 | paddingTop: paddingTop + 'px',
|
37964 | paddingBottom: paddingBottom + 'px'
|
37965 | });
|
37966 | }
|
37967 |
|
37968 |
|
37969 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
37970 | assign(bounds, {
|
37971 | width: bbox.width,
|
37972 | height: bbox.height,
|
37973 | minWidth: 30 * zoom,
|
37974 | minHeight: 10 * zoom
|
37975 | });
|
37976 |
|
37977 | assign(style, {
|
37978 | textAlign: 'left',
|
37979 | paddingTop: (5 * zoom) + 'px',
|
37980 | paddingBottom: (7 * zoom) + 'px',
|
37981 | paddingLeft: (7 * zoom) + 'px',
|
37982 | paddingRight: (5 * zoom) + 'px',
|
37983 | fontSize: defaultFontSize + 'px',
|
37984 | lineHeight: defaultLineHeight
|
37985 | });
|
37986 | }
|
37987 |
|
37988 | return { bounds: bounds, style: style };
|
37989 | };
|
37990 |
|
37991 |
|
37992 | LabelEditingProvider.prototype.update = function(
|
37993 | element, newLabel,
|
37994 | activeContextText, bounds) {
|
37995 |
|
37996 | var newBounds,
|
37997 | bbox;
|
37998 |
|
37999 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
38000 |
|
38001 | bbox = this._canvas.getAbsoluteBBox(element);
|
38002 |
|
38003 | newBounds = {
|
38004 | x: element.x,
|
38005 | y: element.y,
|
38006 | width: element.width / bbox.width * bounds.width,
|
38007 | height: element.height / bbox.height * bounds.height
|
38008 | };
|
38009 | }
|
38010 |
|
38011 | if (is$1(element, 'bpmn:Group')) {
|
38012 |
|
38013 | var businessObject = getBusinessObject(element);
|
38014 |
|
38015 |
|
38016 | if (!businessObject.categoryValueRef) {
|
38017 |
|
38018 | var rootElement = this._canvas.getRootElement(),
|
38019 | definitions = getBusinessObject(rootElement).$parent;
|
38020 |
|
38021 | var categoryValue = createCategoryValue(definitions, this._bpmnFactory);
|
38022 |
|
38023 | getBusinessObject(element).categoryValueRef = categoryValue;
|
38024 | }
|
38025 |
|
38026 | }
|
38027 |
|
38028 | if (isEmptyText(newLabel)) {
|
38029 | newLabel = null;
|
38030 | }
|
38031 |
|
38032 | this._modeling.updateLabel(element, newLabel, newBounds);
|
38033 | };
|
38034 |
|
38035 |
|
38036 |
|
38037 |
|
38038 |
|
38039 | function isCollapsedSubProcess(element) {
|
38040 | return is$1(element, 'bpmn:SubProcess') && !isExpanded(element);
|
38041 | }
|
38042 |
|
38043 | function isExpandedSubProcess(element) {
|
38044 | return is$1(element, 'bpmn:SubProcess') && isExpanded(element);
|
38045 | }
|
38046 |
|
38047 | function isCollapsedPool(element) {
|
38048 | return is$1(element, 'bpmn:Participant') && !isExpanded(element);
|
38049 | }
|
38050 |
|
38051 | function isExpandedPool(element) {
|
38052 | return is$1(element, 'bpmn:Participant') && isExpanded(element);
|
38053 | }
|
38054 |
|
38055 | function isEmptyText(label) {
|
38056 | return !label || !label.trim();
|
38057 | }
|
38058 |
|
38059 | var MARKER_HIDDEN = 'djs-element-hidden',
|
38060 | MARKER_LABEL_HIDDEN = 'djs-label-hidden';
|
38061 |
|
38062 |
|
38063 | function LabelEditingPreview(
|
38064 | eventBus, canvas, elementRegistry,
|
38065 | pathMap) {
|
38066 |
|
38067 | var self = this;
|
38068 |
|
38069 | var defaultLayer = canvas.getDefaultLayer();
|
38070 |
|
38071 | var element, absoluteElementBBox, gfx;
|
38072 |
|
38073 | eventBus.on('directEditing.activate', function(context) {
|
38074 | var activeProvider = context.active;
|
38075 |
|
38076 | element = activeProvider.element.label || activeProvider.element;
|
38077 |
|
38078 |
|
38079 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
38080 | absoluteElementBBox = canvas.getAbsoluteBBox(element);
|
38081 |
|
38082 | gfx = create('g');
|
38083 |
|
38084 | var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', {
|
38085 | xScaleFactor: 1,
|
38086 | yScaleFactor: 1,
|
38087 | containerWidth: element.width,
|
38088 | containerHeight: element.height,
|
38089 | position: {
|
38090 | mx: 0.0,
|
38091 | my: 0.0
|
38092 | }
|
38093 | });
|
38094 |
|
38095 | var path = self.path = create('path');
|
38096 |
|
38097 | attr$1(path, {
|
38098 | d: textPathData,
|
38099 | strokeWidth: 2,
|
38100 | stroke: getStrokeColor$1(element)
|
38101 | });
|
38102 |
|
38103 | append(gfx, path);
|
38104 |
|
38105 | append(defaultLayer, gfx);
|
38106 |
|
38107 | translate(gfx, element.x, element.y);
|
38108 | }
|
38109 |
|
38110 | if (is$1(element, 'bpmn:TextAnnotation') ||
|
38111 | element.labelTarget) {
|
38112 | canvas.addMarker(element, MARKER_HIDDEN);
|
38113 | } else if (is$1(element, 'bpmn:Task') ||
|
38114 | is$1(element, 'bpmn:CallActivity') ||
|
38115 | is$1(element, 'bpmn:SubProcess') ||
|
38116 | is$1(element, 'bpmn:Participant')) {
|
38117 | canvas.addMarker(element, MARKER_LABEL_HIDDEN);
|
38118 | }
|
38119 | });
|
38120 |
|
38121 | eventBus.on('directEditing.resize', function(context) {
|
38122 |
|
38123 |
|
38124 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
38125 | var height = context.height,
|
38126 | dy = context.dy;
|
38127 |
|
38128 | var newElementHeight = Math.max(element.height / absoluteElementBBox.height * (height + dy), 0);
|
38129 |
|
38130 | var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', {
|
38131 | xScaleFactor: 1,
|
38132 | yScaleFactor: 1,
|
38133 | containerWidth: element.width,
|
38134 | containerHeight: newElementHeight,
|
38135 | position: {
|
38136 | mx: 0.0,
|
38137 | my: 0.0
|
38138 | }
|
38139 | });
|
38140 |
|
38141 | attr$1(self.path, {
|
38142 | d: textPathData
|
38143 | });
|
38144 | }
|
38145 | });
|
38146 |
|
38147 | eventBus.on([ 'directEditing.complete', 'directEditing.cancel' ], function(context) {
|
38148 | var activeProvider = context.active;
|
38149 |
|
38150 | if (activeProvider) {
|
38151 | canvas.removeMarker(activeProvider.element.label || activeProvider.element, MARKER_HIDDEN);
|
38152 | canvas.removeMarker(element, MARKER_LABEL_HIDDEN);
|
38153 | }
|
38154 |
|
38155 | element = undefined;
|
38156 | absoluteElementBBox = undefined;
|
38157 |
|
38158 | if (gfx) {
|
38159 | remove$1(gfx);
|
38160 |
|
38161 | gfx = undefined;
|
38162 | }
|
38163 | });
|
38164 | }
|
38165 |
|
38166 | LabelEditingPreview.$inject = [
|
38167 | 'eventBus',
|
38168 | 'canvas',
|
38169 | 'elementRegistry',
|
38170 | 'pathMap'
|
38171 | ];
|
38172 |
|
38173 |
|
38174 |
|
38175 |
|
38176 | function getStrokeColor$1(element, defaultColor) {
|
38177 | var bo = getBusinessObject(element);
|
38178 |
|
38179 | return bo.di.get('stroke') || defaultColor || 'black';
|
38180 | }
|
38181 |
|
38182 | var LabelEditingModule = {
|
38183 | __depends__: [
|
38184 | ChangeSupportModule,
|
38185 | ResizeModule,
|
38186 | DirectEditingModule
|
38187 | ],
|
38188 | __init__: [
|
38189 | 'labelEditingProvider',
|
38190 | 'labelEditingPreview'
|
38191 | ],
|
38192 | labelEditingProvider: [ 'type', LabelEditingProvider ],
|
38193 | labelEditingPreview: [ 'type', LabelEditingPreview ]
|
38194 | };
|
38195 |
|
38196 | var ALIGNMENTS = [
|
38197 | 'top',
|
38198 | 'bottom',
|
38199 | 'left',
|
38200 | 'right'
|
38201 | ];
|
38202 |
|
38203 | var ELEMENT_LABEL_DISTANCE = 10;
|
38204 |
|
38205 | |
38206 |
|
38207 |
|
38208 |
|
38209 |
|
38210 |
|
38211 |
|
38212 |
|
38213 | function AdaptiveLabelPositioningBehavior(eventBus, modeling) {
|
38214 |
|
38215 | CommandInterceptor.call(this, eventBus);
|
38216 |
|
38217 | this.postExecuted([
|
38218 | 'connection.create',
|
38219 | 'connection.layout',
|
38220 | 'connection.updateWaypoints'
|
38221 | ], function(event) {
|
38222 |
|
38223 | var context = event.context,
|
38224 | connection = context.connection;
|
38225 |
|
38226 | var source = connection.source,
|
38227 | target = connection.target;
|
38228 |
|
38229 | checkLabelAdjustment(source);
|
38230 | checkLabelAdjustment(target);
|
38231 | });
|
38232 |
|
38233 |
|
38234 | this.postExecuted([
|
38235 | 'label.create'
|
38236 | ], function(event) {
|
38237 | checkLabelAdjustment(event.context.shape.labelTarget);
|
38238 | });
|
38239 |
|
38240 |
|
38241 | function checkLabelAdjustment(element) {
|
38242 |
|
38243 |
|
38244 | if (!hasExternalLabel(element)) {
|
38245 | return;
|
38246 | }
|
38247 |
|
38248 | var optimalPosition = getOptimalPosition(element);
|
38249 |
|
38250 |
|
38251 | if (!optimalPosition) {
|
38252 | return;
|
38253 | }
|
38254 |
|
38255 | adjustLabelPosition(element, optimalPosition);
|
38256 | }
|
38257 |
|
38258 | function adjustLabelPosition(element, orientation) {
|
38259 |
|
38260 | var elementMid = getMid(element),
|
38261 | label = element.label,
|
38262 | labelMid = getMid(label);
|
38263 |
|
38264 | var elementTrbl = asTRBL(element);
|
38265 |
|
38266 | var newLabelMid;
|
38267 |
|
38268 | switch (orientation) {
|
38269 | case 'top':
|
38270 | newLabelMid = {
|
38271 | x: elementMid.x,
|
38272 | y: elementTrbl.top - ELEMENT_LABEL_DISTANCE - label.height / 2
|
38273 | };
|
38274 |
|
38275 | break;
|
38276 |
|
38277 | case 'left':
|
38278 |
|
38279 | newLabelMid = {
|
38280 | x: elementTrbl.left - ELEMENT_LABEL_DISTANCE - label.width / 2,
|
38281 | y: elementMid.y
|
38282 | };
|
38283 |
|
38284 | break;
|
38285 |
|
38286 | case 'bottom':
|
38287 |
|
38288 | newLabelMid = {
|
38289 | x: elementMid.x,
|
38290 | y: elementTrbl.bottom + ELEMENT_LABEL_DISTANCE + label.height / 2
|
38291 | };
|
38292 |
|
38293 | break;
|
38294 |
|
38295 | case 'right':
|
38296 |
|
38297 | newLabelMid = {
|
38298 | x: elementTrbl.right + ELEMENT_LABEL_DISTANCE + label.width / 2,
|
38299 | y: elementMid.y
|
38300 | };
|
38301 |
|
38302 | break;
|
38303 | }
|
38304 |
|
38305 |
|
38306 | var delta$1 = delta(newLabelMid, labelMid);
|
38307 |
|
38308 | modeling.moveShape(label, delta$1);
|
38309 | }
|
38310 |
|
38311 | }
|
38312 |
|
38313 | inherits_browser(AdaptiveLabelPositioningBehavior, CommandInterceptor);
|
38314 |
|
38315 | AdaptiveLabelPositioningBehavior.$inject = [
|
38316 | 'eventBus',
|
38317 | 'modeling'
|
38318 | ];
|
38319 |
|
38320 |
|
38321 |
|
38322 |
|
38323 | |
38324 |
|
38325 |
|
38326 |
|
38327 |
|
38328 |
|
38329 |
|
38330 | function getTakenHostAlignments(element) {
|
38331 |
|
38332 | var hostElement = element.host,
|
38333 | elementMid = getMid(element),
|
38334 | hostOrientation = getOrientation(elementMid, hostElement);
|
38335 |
|
38336 | var freeAlignments;
|
38337 |
|
38338 |
|
38339 | if (hostOrientation.indexOf('-') >= 0) {
|
38340 | freeAlignments = hostOrientation.split('-');
|
38341 | } else {
|
38342 | freeAlignments = [ hostOrientation ];
|
38343 | }
|
38344 |
|
38345 | var takenAlignments = ALIGNMENTS.filter(function(alignment) {
|
38346 |
|
38347 | return freeAlignments.indexOf(alignment) === -1;
|
38348 | });
|
38349 |
|
38350 | return takenAlignments;
|
38351 |
|
38352 | }
|
38353 |
|
38354 | |
38355 |
|
38356 |
|
38357 |
|
38358 |
|
38359 |
|
38360 |
|
38361 | function getTakenConnectionAlignments(element) {
|
38362 |
|
38363 | var elementMid = getMid(element);
|
38364 |
|
38365 | var takenAlignments = [].concat(
|
38366 | element.incoming.map(function(c) {
|
38367 | return c.waypoints[c.waypoints.length - 2 ];
|
38368 | }),
|
38369 | element.outgoing.map(function(c) {
|
38370 | return c.waypoints[1];
|
38371 | })
|
38372 | ).map(function(point) {
|
38373 | return getApproximateOrientation(elementMid, point);
|
38374 | });
|
38375 |
|
38376 | return takenAlignments;
|
38377 | }
|
38378 |
|
38379 | |
38380 |
|
38381 |
|
38382 |
|
38383 |
|
38384 |
|
38385 |
|
38386 |
|
38387 | function getOptimalPosition(element) {
|
38388 |
|
38389 | var labelMid = getMid(element.label);
|
38390 |
|
38391 | var elementMid = getMid(element);
|
38392 |
|
38393 | var labelOrientation = getApproximateOrientation(elementMid, labelMid);
|
38394 |
|
38395 | if (!isAligned(labelOrientation)) {
|
38396 | return;
|
38397 | }
|
38398 |
|
38399 | var takenAlignments = getTakenConnectionAlignments(element);
|
38400 |
|
38401 | if (element.host) {
|
38402 | var takenHostAlignments = getTakenHostAlignments(element);
|
38403 |
|
38404 | takenAlignments = takenAlignments.concat(takenHostAlignments);
|
38405 | }
|
38406 |
|
38407 | var freeAlignments = ALIGNMENTS.filter(function(alignment) {
|
38408 |
|
38409 | return takenAlignments.indexOf(alignment) === -1;
|
38410 | });
|
38411 |
|
38412 |
|
38413 | if (freeAlignments.indexOf(labelOrientation) !== -1) {
|
38414 | return;
|
38415 | }
|
38416 |
|
38417 | return freeAlignments[0];
|
38418 | }
|
38419 |
|
38420 | function getApproximateOrientation(p0, p1) {
|
38421 | return getOrientation(p1, p0, 5);
|
38422 | }
|
38423 |
|
38424 | function isAligned(orientation) {
|
38425 | return ALIGNMENTS.indexOf(orientation) !== -1;
|
38426 | }
|
38427 |
|
38428 | function AppendBehavior(eventBus, elementFactory, bpmnRules) {
|
38429 |
|
38430 | CommandInterceptor.call(this, eventBus);
|
38431 |
|
38432 |
|
38433 |
|
38434 | this.preExecute('shape.append', function(context) {
|
38435 |
|
38436 | var source = context.source,
|
38437 | shape = context.shape;
|
38438 |
|
38439 | if (!context.position) {
|
38440 |
|
38441 | if (is$1(shape, 'bpmn:TextAnnotation')) {
|
38442 | context.position = {
|
38443 | x: source.x + source.width / 2 + 75,
|
38444 | y: source.y - (50) - shape.height / 2
|
38445 | };
|
38446 | } else {
|
38447 | context.position = {
|
38448 | x: source.x + source.width + 80 + shape.width / 2,
|
38449 | y: source.y + source.height / 2
|
38450 | };
|
38451 | }
|
38452 | }
|
38453 | }, true);
|
38454 | }
|
38455 |
|
38456 | inherits_browser(AppendBehavior, CommandInterceptor);
|
38457 |
|
38458 | AppendBehavior.$inject = [
|
38459 | 'eventBus',
|
38460 | 'elementFactory',
|
38461 | 'bpmnRules'
|
38462 | ];
|
38463 |
|
38464 | |
38465 |
|
38466 |
|
38467 | function AttachEventBehavior(eventBus, bpmnReplace) {
|
38468 |
|
38469 | CommandInterceptor.call(this, eventBus);
|
38470 |
|
38471 | |
38472 |
|
38473 |
|
38474 |
|
38475 |
|
38476 | this.preExecute('elements.move', function(context) {
|
38477 | var shapes = context.shapes,
|
38478 | host = context.newHost,
|
38479 | shape,
|
38480 | eventDefinition,
|
38481 | boundaryEvent,
|
38482 | newShape;
|
38483 |
|
38484 | if (shapes.length !== 1) {
|
38485 | return;
|
38486 | }
|
38487 |
|
38488 | shape = shapes[0];
|
38489 |
|
38490 | if (host && isAny(shape, [ 'bpmn:IntermediateThrowEvent', 'bpmn:IntermediateCatchEvent' ])) {
|
38491 |
|
38492 | eventDefinition = getEventDefinition(shape);
|
38493 |
|
38494 | boundaryEvent = {
|
38495 | type: 'bpmn:BoundaryEvent',
|
38496 | host: host
|
38497 | };
|
38498 |
|
38499 | if (eventDefinition) {
|
38500 | boundaryEvent.eventDefinitionType = eventDefinition.$type;
|
38501 | }
|
38502 |
|
38503 | newShape = bpmnReplace.replaceElement(shape, boundaryEvent, { layoutConnection: false });
|
38504 |
|
38505 | context.shapes = [ newShape ];
|
38506 | }
|
38507 | }, true);
|
38508 | }
|
38509 |
|
38510 | AttachEventBehavior.$inject = [
|
38511 | 'eventBus',
|
38512 | 'bpmnReplace'
|
38513 | ];
|
38514 |
|
38515 | inherits_browser(AttachEventBehavior, CommandInterceptor);
|
38516 |
|
38517 |
|
38518 |
|
38519 |
|
38520 | function getEventDefinition(element) {
|
38521 | var bo = getBusinessObject(element);
|
38522 |
|
38523 | return bo && bo.eventDefinitions && bo.eventDefinitions[0];
|
38524 | }
|
38525 |
|
38526 | |
38527 |
|
38528 |
|
38529 | function BoundaryEventBehavior(eventBus, modeling) {
|
38530 |
|
38531 | CommandInterceptor.call(this, eventBus);
|
38532 |
|
38533 | function getBoundaryEvents(element) {
|
38534 | return filter(element.attachers, function(attacher) {
|
38535 | return is$1(attacher, 'bpmn:BoundaryEvent');
|
38536 | });
|
38537 | }
|
38538 |
|
38539 |
|
38540 | this.postExecute('connection.create', function(event) {
|
38541 | var source = event.context.source,
|
38542 | target = event.context.target,
|
38543 | boundaryEvents = getBoundaryEvents(target);
|
38544 |
|
38545 | if (
|
38546 | is$1(source, 'bpmn:EventBasedGateway') &&
|
38547 | is$1(target, 'bpmn:ReceiveTask') &&
|
38548 | boundaryEvents.length > 0
|
38549 | ) {
|
38550 | modeling.removeElements(boundaryEvents);
|
38551 | }
|
38552 |
|
38553 | });
|
38554 |
|
38555 |
|
38556 | this.postExecute('connection.reconnectStart', function(event) {
|
38557 | var oldSource = event.context.oldSource,
|
38558 | newSource = event.context.newSource;
|
38559 |
|
38560 | if (is$1(oldSource, 'bpmn:Gateway') &&
|
38561 | is$1(newSource, 'bpmn:EventBasedGateway')) {
|
38562 | forEach(newSource.outgoing, function(connection) {
|
38563 | var target = connection.target,
|
38564 | attachedboundaryEvents = getBoundaryEvents(target);
|
38565 |
|
38566 | if (is$1(target, 'bpmn:ReceiveTask') &&
|
38567 | attachedboundaryEvents.length > 0) {
|
38568 | modeling.removeElements(attachedboundaryEvents);
|
38569 | }
|
38570 | });
|
38571 | }
|
38572 | });
|
38573 | }
|
38574 |
|
38575 | BoundaryEventBehavior.$inject = [
|
38576 | 'eventBus',
|
38577 | 'modeling'
|
38578 | ];
|
38579 |
|
38580 | inherits_browser(BoundaryEventBehavior, CommandInterceptor);
|
38581 |
|
38582 | function CreateBehavior(injector) {
|
38583 | injector.invoke(CommandInterceptor, this);
|
38584 |
|
38585 | this.preExecute('shape.create', 1500, function(event) {
|
38586 | var context = event.context,
|
38587 | parent = context.parent;
|
38588 |
|
38589 | if (is$1(parent, 'bpmn:Lane')) {
|
38590 | context.parent = getParent$1(parent, 'bpmn:Participant');
|
38591 | }
|
38592 | });
|
38593 |
|
38594 | }
|
38595 |
|
38596 |
|
38597 | CreateBehavior.$inject = [ 'injector' ];
|
38598 |
|
38599 | inherits_browser(CreateBehavior, CommandInterceptor);
|
38600 |
|
38601 | var HIGH_PRIORITY$5 = 1500;
|
38602 | var HIGHEST_PRIORITY = 2000;
|
38603 |
|
38604 |
|
38605 | |
38606 |
|
38607 |
|
38608 |
|
38609 |
|
38610 |
|
38611 |
|
38612 | function FixHoverBehavior(elementRegistry, eventBus, canvas) {
|
38613 |
|
38614 | eventBus.on([
|
38615 | 'create.hover',
|
38616 | 'create.move',
|
38617 | 'create.end',
|
38618 | 'shape.move.hover',
|
38619 | 'shape.move.move',
|
38620 | 'shape.move.end'
|
38621 | ], HIGH_PRIORITY$5, function(event) {
|
38622 | var context = event.context,
|
38623 | shape = context.shape || event.shape,
|
38624 | hover = event.hover;
|
38625 |
|
38626 |
|
38627 |
|
38628 | if (is$1(hover, 'bpmn:Lane') && !isAny(shape, [ 'bpmn:Lane', 'bpmn:Participant' ])) {
|
38629 | event.hover = getLanesRoot(hover);
|
38630 | event.hoverGfx = elementRegistry.getGraphics(event.hover);
|
38631 | }
|
38632 |
|
38633 | var rootElement = canvas.getRootElement();
|
38634 |
|
38635 |
|
38636 |
|
38637 | if (hover !== rootElement && (shape.labelTarget || is$1(shape, 'bpmn:Group'))) {
|
38638 | event.hover = rootElement;
|
38639 | event.hoverGfx = elementRegistry.getGraphics(event.hover);
|
38640 | }
|
38641 | });
|
38642 |
|
38643 |
|
38644 | eventBus.on([
|
38645 | 'connect.hover',
|
38646 | 'global-connect.hover'
|
38647 | ], HIGH_PRIORITY$5, function(event) {
|
38648 | var hover = event.hover;
|
38649 |
|
38650 |
|
38651 |
|
38652 | if (is$1(hover, 'bpmn:Lane')) {
|
38653 | event.hover = getLanesRoot(hover) || hover;
|
38654 | event.hoverGfx = elementRegistry.getGraphics(event.hover);
|
38655 | }
|
38656 | });
|
38657 |
|
38658 |
|
38659 | eventBus.on([
|
38660 | 'bendpoint.move.hover'
|
38661 | ], HIGH_PRIORITY$5, function(event) {
|
38662 | var context = event.context,
|
38663 | type = context.type,
|
38664 | hover = event.hover;
|
38665 |
|
38666 |
|
38667 |
|
38668 | if (is$1(hover, 'bpmn:Lane') && /reconnect/.test(type)) {
|
38669 | event.hover = getLanesRoot(hover) || hover;
|
38670 | event.hoverGfx = elementRegistry.getGraphics(event.hover);
|
38671 | }
|
38672 | });
|
38673 |
|
38674 |
|
38675 | eventBus.on([
|
38676 | 'connect.start'
|
38677 | ], HIGH_PRIORITY$5, function(event) {
|
38678 |
|
38679 | var context = event.context,
|
38680 | source = context.source;
|
38681 |
|
38682 |
|
38683 |
|
38684 | if (is$1(source, 'bpmn:Lane')) {
|
38685 | context.source = getLanesRoot(source) || source;
|
38686 | }
|
38687 | });
|
38688 |
|
38689 |
|
38690 |
|
38691 | eventBus.on('shape.move.start', HIGHEST_PRIORITY, function(event) {
|
38692 | var shape = event.shape;
|
38693 |
|
38694 | if (is$1(shape, 'bpmn:Lane')) {
|
38695 | event.shape = getLanesRoot(shape) || shape;
|
38696 | }
|
38697 | });
|
38698 |
|
38699 | }
|
38700 |
|
38701 | FixHoverBehavior.$inject = [
|
38702 | 'elementRegistry',
|
38703 | 'eventBus',
|
38704 | 'canvas'
|
38705 | ];
|
38706 |
|
38707 | |
38708 |
|
38709 |
|
38710 | function CreateBoundaryEventBehavior(
|
38711 | eventBus, modeling, elementFactory,
|
38712 | bpmnFactory) {
|
38713 |
|
38714 | CommandInterceptor.call(this, eventBus);
|
38715 |
|
38716 | |
38717 |
|
38718 |
|
38719 |
|
38720 |
|
38721 | this.preExecute('shape.create', function(context) {
|
38722 | var shape = context.shape,
|
38723 | host = context.host,
|
38724 | businessObject,
|
38725 | boundaryEvent;
|
38726 |
|
38727 | var attrs = {
|
38728 | cancelActivity: true
|
38729 | };
|
38730 |
|
38731 | if (host && is$1(shape, 'bpmn:IntermediateThrowEvent')) {
|
38732 | attrs.attachedToRef = host.businessObject;
|
38733 |
|
38734 | businessObject = bpmnFactory.create('bpmn:BoundaryEvent', attrs);
|
38735 |
|
38736 | boundaryEvent = {
|
38737 | type: 'bpmn:BoundaryEvent',
|
38738 | businessObject: businessObject
|
38739 | };
|
38740 |
|
38741 | context.shape = elementFactory.createShape(boundaryEvent);
|
38742 | }
|
38743 | }, true);
|
38744 | }
|
38745 |
|
38746 | CreateBoundaryEventBehavior.$inject = [
|
38747 | 'eventBus',
|
38748 | 'modeling',
|
38749 | 'elementFactory',
|
38750 | 'bpmnFactory'
|
38751 | ];
|
38752 |
|
38753 | inherits_browser(CreateBoundaryEventBehavior, CommandInterceptor);
|
38754 |
|
38755 | |
38756 |
|
38757 |
|
38758 | function CreateDataObjectBehavior(eventBus, bpmnFactory, moddle) {
|
38759 |
|
38760 | CommandInterceptor.call(this, eventBus);
|
38761 |
|
38762 | this.preExecute('shape.create', function(event) {
|
38763 |
|
38764 | var context = event.context,
|
38765 | shape = context.shape;
|
38766 |
|
38767 | if (is$1(shape, 'bpmn:DataObjectReference') && shape.type !== 'label') {
|
38768 |
|
38769 |
|
38770 | var dataObject = bpmnFactory.create('bpmn:DataObject');
|
38771 |
|
38772 |
|
38773 | shape.businessObject.dataObjectRef = dataObject;
|
38774 | }
|
38775 | });
|
38776 |
|
38777 | }
|
38778 |
|
38779 | CreateDataObjectBehavior.$inject = [
|
38780 | 'eventBus',
|
38781 | 'bpmnFactory',
|
38782 | 'moddle'
|
38783 | ];
|
38784 |
|
38785 | inherits_browser(CreateDataObjectBehavior, CommandInterceptor);
|
38786 |
|
38787 | var HORIZONTAL_PARTICIPANT_PADDING = 20,
|
38788 | VERTICAL_PARTICIPANT_PADDING = 20;
|
38789 |
|
38790 | var PARTICIPANT_BORDER_WIDTH = 30;
|
38791 |
|
38792 | var HIGH_PRIORITY$6 = 2000;
|
38793 |
|
38794 |
|
38795 | |
38796 |
|
38797 |
|
38798 | function CreateParticipantBehavior$1(canvas, eventBus, modeling) {
|
38799 | CommandInterceptor.call(this, eventBus);
|
38800 |
|
38801 |
|
38802 | eventBus.on([
|
38803 | 'create.start',
|
38804 | 'shape.move.start'
|
38805 | ], HIGH_PRIORITY$6, function(event) {
|
38806 | var context = event.context,
|
38807 | shape = context.shape,
|
38808 | rootElement = canvas.getRootElement();
|
38809 |
|
38810 | if (!is$1(shape, 'bpmn:Participant') ||
|
38811 | !is$1(rootElement, 'bpmn:Process') ||
|
38812 | !rootElement.children.length) {
|
38813 | return;
|
38814 | }
|
38815 |
|
38816 |
|
38817 | var children = rootElement.children.filter(function(element) {
|
38818 | return !is$1(element, 'bpmn:Group') &&
|
38819 | !isLabel(element) &&
|
38820 | !isConnection$2(element);
|
38821 | });
|
38822 |
|
38823 |
|
38824 | if (!children.length) {
|
38825 | return;
|
38826 | }
|
38827 |
|
38828 | var childrenBBox = getBBox(children);
|
38829 |
|
38830 | var participantBounds = getParticipantBounds(shape, childrenBBox);
|
38831 |
|
38832 |
|
38833 | assign(shape, participantBounds);
|
38834 |
|
38835 |
|
38836 | context.createConstraints = getParticipantCreateConstraints(shape, childrenBBox);
|
38837 | });
|
38838 |
|
38839 |
|
38840 | eventBus.on('create.start', HIGH_PRIORITY$6, function(event) {
|
38841 | var context = event.context,
|
38842 | shape = context.shape,
|
38843 | rootElement = canvas.getRootElement(),
|
38844 | rootElementGfx = canvas.getGraphics(rootElement);
|
38845 |
|
38846 | function ensureHoveringProcess(event) {
|
38847 | event.element = rootElement;
|
38848 | event.gfx = rootElementGfx;
|
38849 | }
|
38850 |
|
38851 | if (is$1(shape, 'bpmn:Participant') && is$1(rootElement, 'bpmn:Process')) {
|
38852 | eventBus.on('element.hover', HIGH_PRIORITY$6, ensureHoveringProcess);
|
38853 |
|
38854 | eventBus.once('create.cleanup', function() {
|
38855 | eventBus.off('element.hover', ensureHoveringProcess);
|
38856 | });
|
38857 | }
|
38858 | });
|
38859 |
|
38860 | function ensureCollaboration(context) {
|
38861 | var parent = context.parent,
|
38862 | collaboration;
|
38863 |
|
38864 | var rootElement = canvas.getRootElement();
|
38865 |
|
38866 | if (is$1(rootElement, 'bpmn:Collaboration')) {
|
38867 | collaboration = rootElement;
|
38868 | } else {
|
38869 |
|
38870 |
|
38871 | collaboration = modeling.makeCollaboration();
|
38872 |
|
38873 |
|
38874 | context.process = parent;
|
38875 | }
|
38876 |
|
38877 | context.parent = collaboration;
|
38878 | }
|
38879 |
|
38880 |
|
38881 | this.preExecute('shape.create', function(context) {
|
38882 | var parent = context.parent,
|
38883 | shape = context.shape;
|
38884 |
|
38885 | if (is$1(shape, 'bpmn:Participant') && is$1(parent, 'bpmn:Process')) {
|
38886 | ensureCollaboration(context);
|
38887 | }
|
38888 | }, true);
|
38889 |
|
38890 | this.execute('shape.create', function(context) {
|
38891 | var process = context.process,
|
38892 | shape = context.shape;
|
38893 |
|
38894 | if (process) {
|
38895 | context.oldProcessRef = shape.businessObject.processRef;
|
38896 |
|
38897 |
|
38898 | shape.businessObject.processRef = process.businessObject;
|
38899 | }
|
38900 | }, true);
|
38901 |
|
38902 | this.revert('shape.create', function(context) {
|
38903 | var process = context.process,
|
38904 | shape = context.shape;
|
38905 |
|
38906 | if (process) {
|
38907 |
|
38908 |
|
38909 | shape.businessObject.processRef = context.oldProcessRef;
|
38910 | }
|
38911 | }, true);
|
38912 |
|
38913 | this.postExecute('shape.create', function(context) {
|
38914 | var process = context.process,
|
38915 | shape = context.shape;
|
38916 |
|
38917 | if (process) {
|
38918 |
|
38919 |
|
38920 | var processChildren = process.children.slice();
|
38921 |
|
38922 | modeling.moveElements(processChildren, { x: 0, y: 0 }, shape);
|
38923 | }
|
38924 |
|
38925 | }, true);
|
38926 |
|
38927 |
|
38928 | this.preExecute('elements.create', HIGH_PRIORITY$6, function(context) {
|
38929 | var elements = context.elements,
|
38930 | parent = context.parent,
|
38931 | participant;
|
38932 |
|
38933 | var hasParticipants = findParticipant(elements);
|
38934 |
|
38935 | if (hasParticipants && is$1(parent, 'bpmn:Process')) {
|
38936 | ensureCollaboration(context);
|
38937 |
|
38938 | participant = findParticipant(elements);
|
38939 |
|
38940 | context.oldProcessRef = participant.businessObject.processRef;
|
38941 |
|
38942 |
|
38943 | participant.businessObject.processRef = parent.businessObject;
|
38944 | }
|
38945 | }, true);
|
38946 |
|
38947 | this.revert('elements.create', function(context) {
|
38948 | var elements = context.elements,
|
38949 | process = context.process,
|
38950 | participant;
|
38951 |
|
38952 | if (process) {
|
38953 | participant = findParticipant(elements);
|
38954 |
|
38955 |
|
38956 | participant.businessObject.processRef = context.oldProcessRef;
|
38957 | }
|
38958 | }, true);
|
38959 |
|
38960 | this.postExecute('elements.create', function(context) {
|
38961 | var elements = context.elements,
|
38962 | process = context.process,
|
38963 | participant;
|
38964 |
|
38965 | if (process) {
|
38966 | participant = findParticipant(elements);
|
38967 |
|
38968 |
|
38969 | var processChildren = process.children.slice();
|
38970 |
|
38971 | modeling.moveElements(processChildren, { x: 0, y: 0 }, participant);
|
38972 | }
|
38973 |
|
38974 | }, true);
|
38975 |
|
38976 | }
|
38977 |
|
38978 | CreateParticipantBehavior$1.$inject = [
|
38979 | 'canvas',
|
38980 | 'eventBus',
|
38981 | 'modeling'
|
38982 | ];
|
38983 |
|
38984 | inherits_browser(CreateParticipantBehavior$1, CommandInterceptor);
|
38985 |
|
38986 |
|
38987 |
|
38988 | function getParticipantBounds(shape, childrenBBox) {
|
38989 | childrenBBox = {
|
38990 | width: childrenBBox.width + HORIZONTAL_PARTICIPANT_PADDING * 2 + PARTICIPANT_BORDER_WIDTH,
|
38991 | height: childrenBBox.height + VERTICAL_PARTICIPANT_PADDING * 2
|
38992 | };
|
38993 |
|
38994 | var width = Math.max(shape.width, childrenBBox.width),
|
38995 | height = Math.max(shape.height, childrenBBox.height);
|
38996 |
|
38997 | return {
|
38998 | x: -width / 2,
|
38999 | y: -height / 2,
|
39000 | width: width,
|
39001 | height: height
|
39002 | };
|
39003 | }
|
39004 |
|
39005 | function getParticipantCreateConstraints(shape, childrenBBox) {
|
39006 | childrenBBox = asTRBL(childrenBBox);
|
39007 |
|
39008 | return {
|
39009 | bottom: childrenBBox.top + shape.height / 2 - VERTICAL_PARTICIPANT_PADDING,
|
39010 | left: childrenBBox.right - shape.width / 2 + HORIZONTAL_PARTICIPANT_PADDING,
|
39011 | top: childrenBBox.bottom - shape.height / 2 + VERTICAL_PARTICIPANT_PADDING,
|
39012 | right: childrenBBox.left + shape.width / 2 - HORIZONTAL_PARTICIPANT_PADDING - PARTICIPANT_BORDER_WIDTH
|
39013 | };
|
39014 | }
|
39015 |
|
39016 | function isConnection$2(element) {
|
39017 | return !!element.waypoints;
|
39018 | }
|
39019 |
|
39020 | function findParticipant(elements) {
|
39021 | return find(elements, function(element) {
|
39022 | return is$1(element, 'bpmn:Participant');
|
39023 | });
|
39024 | }
|
39025 |
|
39026 | var TARGET_REF_PLACEHOLDER_NAME = '__targetRef_placeholder';
|
39027 |
|
39028 |
|
39029 | |
39030 |
|
39031 |
|
39032 |
|
39033 |
|
39034 |
|
39035 |
|
39036 |
|
39037 |
|
39038 |
|
39039 |
|
39040 |
|
39041 | function DataInputAssociationBehavior(eventBus, bpmnFactory) {
|
39042 |
|
39043 | CommandInterceptor.call(this, eventBus);
|
39044 |
|
39045 |
|
39046 | this.executed([
|
39047 | 'connection.create',
|
39048 | 'connection.delete',
|
39049 | 'connection.move',
|
39050 | 'connection.reconnectEnd'
|
39051 | ], ifDataInputAssociation(fixTargetRef));
|
39052 |
|
39053 | this.reverted([
|
39054 | 'connection.create',
|
39055 | 'connection.delete',
|
39056 | 'connection.move',
|
39057 | 'connection.reconnectEnd'
|
39058 | ], ifDataInputAssociation(fixTargetRef));
|
39059 |
|
39060 |
|
39061 | function usesTargetRef(element, targetRef, removedConnection) {
|
39062 |
|
39063 | var inputAssociations = element.get('dataInputAssociations');
|
39064 |
|
39065 | return find(inputAssociations, function(association) {
|
39066 | return association !== removedConnection &&
|
39067 | association.targetRef === targetRef;
|
39068 | });
|
39069 | }
|
39070 |
|
39071 | function getTargetRef(element, create) {
|
39072 |
|
39073 | var properties = element.get('properties');
|
39074 |
|
39075 | var targetRefProp = find(properties, function(p) {
|
39076 | return p.name === TARGET_REF_PLACEHOLDER_NAME;
|
39077 | });
|
39078 |
|
39079 | if (!targetRefProp && create) {
|
39080 | targetRefProp = bpmnFactory.create('bpmn:Property', {
|
39081 | name: TARGET_REF_PLACEHOLDER_NAME
|
39082 | });
|
39083 |
|
39084 | add$1(properties, targetRefProp);
|
39085 | }
|
39086 |
|
39087 | return targetRefProp;
|
39088 | }
|
39089 |
|
39090 | function cleanupTargetRef(element, connection) {
|
39091 |
|
39092 | var targetRefProp = getTargetRef(element);
|
39093 |
|
39094 | if (!targetRefProp) {
|
39095 | return;
|
39096 | }
|
39097 |
|
39098 | if (!usesTargetRef(element, targetRefProp, connection)) {
|
39099 | remove$2(element.get('properties'), targetRefProp);
|
39100 | }
|
39101 | }
|
39102 |
|
39103 | |
39104 |
|
39105 |
|
39106 |
|
39107 |
|
39108 |
|
39109 | function fixTargetRef(event) {
|
39110 |
|
39111 | var context = event.context,
|
39112 | connection = context.connection,
|
39113 | connectionBo = connection.businessObject,
|
39114 | target = connection.target,
|
39115 | targetBo = target && target.businessObject,
|
39116 | newTarget = context.newTarget,
|
39117 | newTargetBo = newTarget && newTarget.businessObject,
|
39118 | oldTarget = context.oldTarget || context.target,
|
39119 | oldTargetBo = oldTarget && oldTarget.businessObject;
|
39120 |
|
39121 | var dataAssociation = connection.businessObject,
|
39122 | targetRefProp;
|
39123 |
|
39124 | if (oldTargetBo && oldTargetBo !== targetBo) {
|
39125 | cleanupTargetRef(oldTargetBo, connectionBo);
|
39126 | }
|
39127 |
|
39128 | if (newTargetBo && newTargetBo !== targetBo) {
|
39129 | cleanupTargetRef(newTargetBo, connectionBo);
|
39130 | }
|
39131 |
|
39132 | if (targetBo) {
|
39133 | targetRefProp = getTargetRef(targetBo, true);
|
39134 | dataAssociation.targetRef = targetRefProp;
|
39135 | } else {
|
39136 | dataAssociation.targetRef = null;
|
39137 | }
|
39138 | }
|
39139 | }
|
39140 |
|
39141 | DataInputAssociationBehavior.$inject = [
|
39142 | 'eventBus',
|
39143 | 'bpmnFactory'
|
39144 | ];
|
39145 |
|
39146 | inherits_browser(DataInputAssociationBehavior, CommandInterceptor);
|
39147 |
|
39148 |
|
39149 | |
39150 |
|
39151 |
|
39152 |
|
39153 |
|
39154 |
|
39155 |
|
39156 | function ifDataInputAssociation(fn) {
|
39157 |
|
39158 | return function(event) {
|
39159 | var context = event.context,
|
39160 | connection = context.connection;
|
39161 |
|
39162 | if (is$1(connection, 'bpmn:DataInputAssociation')) {
|
39163 | return fn(event);
|
39164 | }
|
39165 | };
|
39166 | }
|
39167 |
|
39168 | function UpdateSemanticParentHandler(bpmnUpdater) {
|
39169 | this._bpmnUpdater = bpmnUpdater;
|
39170 | }
|
39171 |
|
39172 | UpdateSemanticParentHandler.$inject = [ 'bpmnUpdater' ];
|
39173 |
|
39174 |
|
39175 | UpdateSemanticParentHandler.prototype.execute = function(context) {
|
39176 | var dataStoreBo = context.dataStoreBo,
|
39177 | newSemanticParent = context.newSemanticParent,
|
39178 | newDiParent = context.newDiParent;
|
39179 |
|
39180 | context.oldSemanticParent = dataStoreBo.$parent;
|
39181 | context.oldDiParent = dataStoreBo.di.$parent;
|
39182 |
|
39183 |
|
39184 | this._bpmnUpdater.updateSemanticParent(dataStoreBo, newSemanticParent);
|
39185 |
|
39186 |
|
39187 | this._bpmnUpdater.updateDiParent(dataStoreBo.di, newDiParent);
|
39188 | };
|
39189 |
|
39190 | UpdateSemanticParentHandler.prototype.revert = function(context) {
|
39191 | var dataStoreBo = context.dataStoreBo,
|
39192 | oldSemanticParent = context.oldSemanticParent,
|
39193 | oldDiParent = context.oldDiParent;
|
39194 |
|
39195 |
|
39196 | this._bpmnUpdater.updateSemanticParent(dataStoreBo, oldSemanticParent);
|
39197 |
|
39198 |
|
39199 | this._bpmnUpdater.updateDiParent(dataStoreBo.di, oldDiParent);
|
39200 | };
|
39201 |
|
39202 | |
39203 |
|
39204 |
|
39205 | function DataStoreBehavior(
|
39206 | canvas, commandStack, elementRegistry,
|
39207 | eventBus) {
|
39208 |
|
39209 | CommandInterceptor.call(this, eventBus);
|
39210 |
|
39211 | commandStack.registerHandler('dataStore.updateContainment', UpdateSemanticParentHandler);
|
39212 |
|
39213 | function getFirstParticipant() {
|
39214 | return elementRegistry.filter(function(element) {
|
39215 | return is$1(element, 'bpmn:Participant');
|
39216 | })[0];
|
39217 | }
|
39218 |
|
39219 | function getDataStores(element) {
|
39220 | return element.children.filter(function(child) {
|
39221 | return is$1(child, 'bpmn:DataStoreReference') && !child.labelTarget;
|
39222 | });
|
39223 | }
|
39224 |
|
39225 | function updateDataStoreParent(dataStore, newDataStoreParent) {
|
39226 | var dataStoreBo = dataStore.businessObject || dataStore;
|
39227 |
|
39228 | newDataStoreParent = newDataStoreParent || getFirstParticipant();
|
39229 |
|
39230 | if (newDataStoreParent) {
|
39231 | var newDataStoreParentBo = newDataStoreParent.businessObject || newDataStoreParent;
|
39232 |
|
39233 | commandStack.execute('dataStore.updateContainment', {
|
39234 | dataStoreBo: dataStoreBo,
|
39235 | newSemanticParent: newDataStoreParentBo.processRef || newDataStoreParentBo,
|
39236 | newDiParent: newDataStoreParentBo.di
|
39237 | });
|
39238 | }
|
39239 | }
|
39240 |
|
39241 |
|
39242 |
|
39243 | this.preExecute('shape.create', function(event) {
|
39244 |
|
39245 | var context = event.context,
|
39246 | shape = context.shape;
|
39247 |
|
39248 | if (is$1(shape, 'bpmn:DataStoreReference') &&
|
39249 | shape.type !== 'label') {
|
39250 |
|
39251 | if (!context.hints) {
|
39252 | context.hints = {};
|
39253 | }
|
39254 |
|
39255 |
|
39256 | context.hints.autoResize = false;
|
39257 | }
|
39258 | });
|
39259 |
|
39260 |
|
39261 |
|
39262 | this.preExecute('elements.move', function(event) {
|
39263 | var context = event.context,
|
39264 | shapes = context.shapes;
|
39265 |
|
39266 | var dataStoreReferences = shapes.filter(function(shape) {
|
39267 | return is$1(shape, 'bpmn:DataStoreReference');
|
39268 | });
|
39269 |
|
39270 | if (dataStoreReferences.length) {
|
39271 | if (!context.hints) {
|
39272 | context.hints = {};
|
39273 | }
|
39274 |
|
39275 |
|
39276 | context.hints.autoResize = shapes.filter(function(shape) {
|
39277 | return !is$1(shape, 'bpmn:DataStoreReference');
|
39278 | });
|
39279 | }
|
39280 | });
|
39281 |
|
39282 |
|
39283 |
|
39284 | this.postExecute('shape.create', function(event) {
|
39285 | var context = event.context,
|
39286 | shape = context.shape,
|
39287 | parent = shape.parent;
|
39288 |
|
39289 |
|
39290 | if (is$1(shape, 'bpmn:DataStoreReference') &&
|
39291 | shape.type !== 'label' &&
|
39292 | is$1(parent, 'bpmn:Collaboration')) {
|
39293 |
|
39294 | updateDataStoreParent(shape);
|
39295 | }
|
39296 | });
|
39297 |
|
39298 |
|
39299 |
|
39300 | this.postExecute('shape.move', function(event) {
|
39301 | var context = event.context,
|
39302 | shape = context.shape,
|
39303 | oldParent = context.oldParent,
|
39304 | parent = shape.parent;
|
39305 |
|
39306 | if (is$1(oldParent, 'bpmn:Collaboration')) {
|
39307 |
|
39308 |
|
39309 | return;
|
39310 | }
|
39311 |
|
39312 | if (is$1(shape, 'bpmn:DataStoreReference') &&
|
39313 | shape.type !== 'label' &&
|
39314 | is$1(parent, 'bpmn:Collaboration')) {
|
39315 |
|
39316 | var participant = is$1(oldParent, 'bpmn:Participant') ?
|
39317 | oldParent :
|
39318 | getAncestor(oldParent, 'bpmn:Participant');
|
39319 |
|
39320 | updateDataStoreParent(shape, participant);
|
39321 | }
|
39322 | });
|
39323 |
|
39324 |
|
39325 |
|
39326 | this.postExecute('shape.delete', function(event) {
|
39327 | var context = event.context,
|
39328 | shape = context.shape,
|
39329 | rootElement = canvas.getRootElement();
|
39330 |
|
39331 | if (isAny(shape, [ 'bpmn:Participant', 'bpmn:SubProcess' ])
|
39332 | && is$1(rootElement, 'bpmn:Collaboration')) {
|
39333 | getDataStores(rootElement)
|
39334 | .filter(function(dataStore) {
|
39335 | return isDescendant(dataStore, shape);
|
39336 | })
|
39337 | .forEach(function(dataStore) {
|
39338 | updateDataStoreParent(dataStore);
|
39339 | });
|
39340 | }
|
39341 | });
|
39342 |
|
39343 |
|
39344 | this.postExecute('canvas.updateRoot', function(event) {
|
39345 | var context = event.context,
|
39346 | oldRoot = context.oldRoot,
|
39347 | newRoot = context.newRoot;
|
39348 |
|
39349 | var dataStores = getDataStores(oldRoot);
|
39350 |
|
39351 | dataStores.forEach(function(dataStore) {
|
39352 |
|
39353 | if (is$1(newRoot, 'bpmn:Process')) {
|
39354 | updateDataStoreParent(dataStore, newRoot);
|
39355 | }
|
39356 |
|
39357 | });
|
39358 | });
|
39359 | }
|
39360 |
|
39361 | DataStoreBehavior.$inject = [
|
39362 | 'canvas',
|
39363 | 'commandStack',
|
39364 | 'elementRegistry',
|
39365 | 'eventBus',
|
39366 | ];
|
39367 |
|
39368 | inherits_browser(DataStoreBehavior, CommandInterceptor);
|
39369 |
|
39370 |
|
39371 |
|
39372 |
|
39373 | function isDescendant(descendant, ancestor) {
|
39374 | var descendantBo = descendant.businessObject || descendant,
|
39375 | ancestorBo = ancestor.businessObject || ancestor;
|
39376 |
|
39377 | while (descendantBo.$parent) {
|
39378 | if (descendantBo.$parent === ancestorBo.processRef || ancestorBo) {
|
39379 | return true;
|
39380 | }
|
39381 |
|
39382 | descendantBo = descendantBo.$parent;
|
39383 | }
|
39384 |
|
39385 | return false;
|
39386 | }
|
39387 |
|
39388 | function getAncestor(element, type) {
|
39389 |
|
39390 | while (element.parent) {
|
39391 | if (is$1(element.parent, type)) {
|
39392 | return element.parent;
|
39393 | }
|
39394 |
|
39395 | element = element.parent;
|
39396 | }
|
39397 | }
|
39398 |
|
39399 | var LOW_PRIORITY$9 = 500;
|
39400 |
|
39401 |
|
39402 | |
39403 |
|
39404 |
|
39405 | function DeleteLaneBehavior(eventBus, modeling, spaceTool) {
|
39406 |
|
39407 | CommandInterceptor.call(this, eventBus);
|
39408 |
|
39409 |
|
39410 | function compensateLaneDelete(shape, oldParent) {
|
39411 |
|
39412 | var siblings = getChildLanes(oldParent);
|
39413 |
|
39414 | var topAffected = [];
|
39415 | var bottomAffected = [];
|
39416 |
|
39417 | eachElement(siblings, function(element) {
|
39418 |
|
39419 | if (element.y > shape.y) {
|
39420 | bottomAffected.push(element);
|
39421 | } else {
|
39422 | topAffected.push(element);
|
39423 | }
|
39424 |
|
39425 | return element.children;
|
39426 | });
|
39427 |
|
39428 | if (!siblings.length) {
|
39429 | return;
|
39430 | }
|
39431 |
|
39432 | var offset;
|
39433 |
|
39434 | if (bottomAffected.length && topAffected.length) {
|
39435 | offset = shape.height / 2;
|
39436 | } else {
|
39437 | offset = shape.height;
|
39438 | }
|
39439 |
|
39440 | var topAdjustments,
|
39441 | bottomAdjustments;
|
39442 |
|
39443 | if (topAffected.length) {
|
39444 | topAdjustments = spaceTool.calculateAdjustments(
|
39445 | topAffected, 'y', offset, shape.y - 10);
|
39446 |
|
39447 | spaceTool.makeSpace(
|
39448 | topAdjustments.movingShapes,
|
39449 | topAdjustments.resizingShapes,
|
39450 | { x: 0, y: offset }, 's');
|
39451 | }
|
39452 |
|
39453 | if (bottomAffected.length) {
|
39454 | bottomAdjustments = spaceTool.calculateAdjustments(
|
39455 | bottomAffected, 'y', -offset, shape.y + shape.height + 10);
|
39456 |
|
39457 | spaceTool.makeSpace(
|
39458 | bottomAdjustments.movingShapes,
|
39459 | bottomAdjustments.resizingShapes,
|
39460 | { x: 0, y: -offset }, 'n');
|
39461 | }
|
39462 | }
|
39463 |
|
39464 |
|
39465 | |
39466 |
|
39467 |
|
39468 | this.postExecuted('shape.delete', LOW_PRIORITY$9, function(event) {
|
39469 |
|
39470 | var context = event.context,
|
39471 | hints = context.hints,
|
39472 | shape = context.shape,
|
39473 | oldParent = context.oldParent;
|
39474 |
|
39475 |
|
39476 | if (!is$1(shape, 'bpmn:Lane')) {
|
39477 | return;
|
39478 | }
|
39479 |
|
39480 |
|
39481 | if (hints && hints.nested) {
|
39482 | return;
|
39483 | }
|
39484 |
|
39485 | compensateLaneDelete(shape, oldParent);
|
39486 | });
|
39487 | }
|
39488 |
|
39489 | DeleteLaneBehavior.$inject = [
|
39490 | 'eventBus',
|
39491 | 'modeling',
|
39492 | 'spaceTool'
|
39493 | ];
|
39494 |
|
39495 | inherits_browser(DeleteLaneBehavior, CommandInterceptor);
|
39496 |
|
39497 | |
39498 |
|
39499 |
|
39500 | function DetachEventBehavior(eventBus, bpmnReplace) {
|
39501 |
|
39502 | CommandInterceptor.call(this, eventBus);
|
39503 |
|
39504 | |
39505 |
|
39506 |
|
39507 |
|
39508 |
|
39509 | this.preExecute('elements.move', function(context) {
|
39510 | var shapes = context.shapes,
|
39511 | host = context.newHost,
|
39512 | shape,
|
39513 | eventDefinition,
|
39514 | intermediateEvent,
|
39515 | newShape;
|
39516 |
|
39517 | if (shapes.length !== 1) {
|
39518 | return;
|
39519 | }
|
39520 |
|
39521 | shape = shapes[0];
|
39522 |
|
39523 | if (!isLabel(shape) && !host && is$1(shape, 'bpmn:BoundaryEvent')) {
|
39524 |
|
39525 | eventDefinition = getEventDefinition$1(shape);
|
39526 |
|
39527 | if (eventDefinition) {
|
39528 | intermediateEvent = {
|
39529 | type: 'bpmn:IntermediateCatchEvent',
|
39530 | eventDefinitionType: eventDefinition.$type
|
39531 | };
|
39532 | } else {
|
39533 | intermediateEvent = {
|
39534 | type: 'bpmn:IntermediateThrowEvent'
|
39535 | };
|
39536 | }
|
39537 |
|
39538 | newShape = bpmnReplace.replaceElement(shape, intermediateEvent, { layoutConnection: false });
|
39539 |
|
39540 | context.shapes = [ newShape ];
|
39541 | }
|
39542 | }, true);
|
39543 | }
|
39544 |
|
39545 | DetachEventBehavior.$inject = [
|
39546 | 'eventBus',
|
39547 | 'bpmnReplace'
|
39548 | ];
|
39549 |
|
39550 | inherits_browser(DetachEventBehavior, CommandInterceptor);
|
39551 |
|
39552 |
|
39553 |
|
39554 |
|
39555 | function getEventDefinition$1(element) {
|
39556 | var bo = getBusinessObject(element);
|
39557 |
|
39558 | return bo && bo.eventDefinitions && bo.eventDefinitions[0];
|
39559 | }
|
39560 |
|
39561 | function DropOnFlowBehavior(eventBus, bpmnRules, modeling) {
|
39562 |
|
39563 | CommandInterceptor.call(this, eventBus);
|
39564 |
|
39565 | |
39566 |
|
39567 |
|
39568 |
|
39569 |
|
39570 | function insertShape(shape, targetFlow, position) {
|
39571 | var waypoints = targetFlow.waypoints,
|
39572 | waypointsBefore,
|
39573 | waypointsAfter,
|
39574 | dockingPoint,
|
39575 | source,
|
39576 | target,
|
39577 | incomingConnection,
|
39578 | outgoingConnection,
|
39579 | oldOutgoing = shape.outgoing.slice(),
|
39580 | oldIncoming = shape.incoming.slice();
|
39581 |
|
39582 | var intersection = getApproxIntersection(waypoints, position);
|
39583 |
|
39584 | if (intersection) {
|
39585 | waypointsBefore = waypoints.slice(0, intersection.index);
|
39586 | waypointsAfter = waypoints.slice(intersection.index + (intersection.bendpoint ? 1 : 0));
|
39587 |
|
39588 |
|
39589 | if (!waypointsBefore.length || !waypointsAfter.length) {
|
39590 | return;
|
39591 | }
|
39592 |
|
39593 | dockingPoint = intersection.bendpoint ? waypoints[intersection.index] : position;
|
39594 |
|
39595 |
|
39596 | if (!isPointInsideBBox$2(shape, waypointsBefore[waypointsBefore.length-1])) {
|
39597 | waypointsBefore.push(copy(dockingPoint));
|
39598 | }
|
39599 |
|
39600 |
|
39601 | if (!isPointInsideBBox$2(shape, waypointsAfter[0])) {
|
39602 | waypointsAfter.unshift(copy(dockingPoint));
|
39603 | }
|
39604 | }
|
39605 |
|
39606 | source = targetFlow.source;
|
39607 | target = targetFlow.target;
|
39608 |
|
39609 | if (bpmnRules.canConnect(source, shape, targetFlow)) {
|
39610 |
|
39611 |
|
39612 | modeling.reconnectEnd(targetFlow, shape, waypointsBefore || position);
|
39613 |
|
39614 | incomingConnection = targetFlow;
|
39615 | }
|
39616 |
|
39617 | if (bpmnRules.canConnect(shape, target, targetFlow)) {
|
39618 |
|
39619 | if (!incomingConnection) {
|
39620 |
|
39621 |
|
39622 | modeling.reconnectStart(targetFlow, shape, waypointsAfter || position);
|
39623 |
|
39624 | outgoingConnection = targetFlow;
|
39625 | } else {
|
39626 | outgoingConnection = modeling.connect(
|
39627 | shape, target, { type: targetFlow.type, waypoints: waypointsAfter }
|
39628 | );
|
39629 | }
|
39630 | }
|
39631 |
|
39632 | var duplicateConnections = [].concat(
|
39633 |
|
39634 | incomingConnection && filter(oldIncoming, function(connection) {
|
39635 | return connection.source === incomingConnection.source;
|
39636 | }) || [],
|
39637 |
|
39638 | outgoingConnection && filter(oldOutgoing, function(connection) {
|
39639 | return connection.source === outgoingConnection.source;
|
39640 | }) || []
|
39641 | );
|
39642 |
|
39643 | if (duplicateConnections.length) {
|
39644 | modeling.removeElements(duplicateConnections);
|
39645 | }
|
39646 | }
|
39647 |
|
39648 | this.preExecute('elements.move', function(context) {
|
39649 |
|
39650 | var newParent = context.newParent,
|
39651 | shapes = context.shapes,
|
39652 | delta = context.delta,
|
39653 | shape = shapes[0];
|
39654 |
|
39655 | if (!shape || !newParent) {
|
39656 | return;
|
39657 | }
|
39658 |
|
39659 |
|
39660 |
|
39661 | if (newParent && newParent.waypoints) {
|
39662 | context.newParent = newParent = newParent.parent;
|
39663 | }
|
39664 |
|
39665 | var shapeMid = getMid$1(shape);
|
39666 | var newShapeMid = {
|
39667 | x: shapeMid.x + delta.x,
|
39668 | y: shapeMid.y + delta.y
|
39669 | };
|
39670 |
|
39671 |
|
39672 |
|
39673 | var connection = find(newParent.children, function(element) {
|
39674 | var canInsert = bpmnRules.canInsert(shapes, element);
|
39675 |
|
39676 | return canInsert && getApproxIntersection(element.waypoints, newShapeMid);
|
39677 | });
|
39678 |
|
39679 | if (connection) {
|
39680 | context.targetFlow = connection;
|
39681 | context.position = newShapeMid;
|
39682 | }
|
39683 |
|
39684 | }, true);
|
39685 |
|
39686 | this.postExecuted('elements.move', function(context) {
|
39687 |
|
39688 | var shapes = context.shapes,
|
39689 | targetFlow = context.targetFlow,
|
39690 | position = context.position;
|
39691 |
|
39692 | if (targetFlow) {
|
39693 | insertShape(shapes[0], targetFlow, position);
|
39694 | }
|
39695 |
|
39696 | }, true);
|
39697 |
|
39698 | this.preExecute('shape.create', function(context) {
|
39699 |
|
39700 | var parent = context.parent,
|
39701 | shape = context.shape;
|
39702 |
|
39703 | if (bpmnRules.canInsert(shape, parent)) {
|
39704 | context.targetFlow = parent;
|
39705 | context.parent = parent.parent;
|
39706 | }
|
39707 | }, true);
|
39708 |
|
39709 | this.postExecuted('shape.create', function(context) {
|
39710 |
|
39711 | var shape = context.shape,
|
39712 | targetFlow = context.targetFlow,
|
39713 | position = context.position;
|
39714 |
|
39715 | if (targetFlow) {
|
39716 | insertShape(shape, targetFlow, position);
|
39717 | }
|
39718 | }, true);
|
39719 | }
|
39720 |
|
39721 | inherits_browser(DropOnFlowBehavior, CommandInterceptor);
|
39722 |
|
39723 | DropOnFlowBehavior.$inject = [
|
39724 | 'eventBus',
|
39725 | 'bpmnRules',
|
39726 | 'modeling'
|
39727 | ];
|
39728 |
|
39729 |
|
39730 |
|
39731 |
|
39732 | function isPointInsideBBox$2(bbox, point) {
|
39733 | var x = point.x,
|
39734 | y = point.y;
|
39735 |
|
39736 | return x >= bbox.x &&
|
39737 | x <= bbox.x + bbox.width &&
|
39738 | y >= bbox.y &&
|
39739 | y <= bbox.y + bbox.height;
|
39740 | }
|
39741 |
|
39742 | function copy(obj) {
|
39743 | return assign({}, obj);
|
39744 | }
|
39745 |
|
39746 | function getMid$1(bounds) {
|
39747 |
|
39748 | return {
|
39749 | x: Math.round(bounds.x + bounds.width / 2),
|
39750 | y: Math.round(bounds.y + bounds.height / 2)
|
39751 | };
|
39752 | }
|
39753 |
|
39754 | function EventBasedGatewayBehavior(eventBus, modeling) {
|
39755 |
|
39756 | CommandInterceptor.call(this, eventBus);
|
39757 |
|
39758 | |
39759 |
|
39760 |
|
39761 |
|
39762 | this.preExecuted('connection.create', function(event) {
|
39763 |
|
39764 | var context = event.context,
|
39765 | source = context.source,
|
39766 | target = context.target,
|
39767 | existingIncomingConnections = target.incoming.slice();
|
39768 |
|
39769 | if (context.hints && context.hints.createElementsBehavior === false) {
|
39770 | return;
|
39771 | }
|
39772 |
|
39773 | if (
|
39774 | is$1(source, 'bpmn:EventBasedGateway') &&
|
39775 | target.incoming.length
|
39776 | ) {
|
39777 |
|
39778 | existingIncomingConnections.filter(isSequenceFlow)
|
39779 | .forEach(function(sequenceFlow) {
|
39780 | modeling.removeConnection(sequenceFlow);
|
39781 | });
|
39782 | }
|
39783 | });
|
39784 |
|
39785 | |
39786 |
|
39787 |
|
39788 |
|
39789 |
|
39790 | this.preExecuted('shape.replace', function(event) {
|
39791 |
|
39792 | var newShape = event.context.newShape,
|
39793 | newShapeTargets,
|
39794 | newShapeTargetsIncomingSequenceFlows;
|
39795 |
|
39796 | if (!is$1(newShape, 'bpmn:EventBasedGateway')) {
|
39797 | return;
|
39798 | }
|
39799 |
|
39800 | newShapeTargets = newShape.outgoing.filter(isSequenceFlow)
|
39801 | .map(function(sequenceFlow) {
|
39802 | return sequenceFlow.target;
|
39803 | });
|
39804 |
|
39805 | newShapeTargetsIncomingSequenceFlows = newShapeTargets.reduce(function(sequenceFlows, target) {
|
39806 | var incomingSequenceFlows = target.incoming.filter(isSequenceFlow);
|
39807 |
|
39808 | return sequenceFlows.concat(incomingSequenceFlows);
|
39809 | }, []);
|
39810 |
|
39811 | newShapeTargetsIncomingSequenceFlows.forEach(function(sequenceFlow) {
|
39812 | if (sequenceFlow.source !== newShape) {
|
39813 | modeling.removeConnection(sequenceFlow);
|
39814 | }
|
39815 | });
|
39816 | });
|
39817 | }
|
39818 |
|
39819 | EventBasedGatewayBehavior.$inject = [
|
39820 | 'eventBus',
|
39821 | 'modeling'
|
39822 | ];
|
39823 |
|
39824 | inherits_browser(EventBasedGatewayBehavior, CommandInterceptor);
|
39825 |
|
39826 |
|
39827 |
|
39828 |
|
39829 |
|
39830 | function isSequenceFlow(connection) {
|
39831 | return is$1(connection, 'bpmn:SequenceFlow');
|
39832 | }
|
39833 |
|
39834 | var HIGH_PRIORITY$7 = 2000;
|
39835 |
|
39836 |
|
39837 | |
39838 |
|
39839 |
|
39840 | function GroupBehavior(
|
39841 | bpmnFactory,
|
39842 | canvas,
|
39843 | elementRegistry,
|
39844 | eventBus,
|
39845 | injector,
|
39846 | moddleCopy
|
39847 | ) {
|
39848 | injector.invoke(CommandInterceptor, this);
|
39849 |
|
39850 | |
39851 |
|
39852 |
|
39853 |
|
39854 |
|
39855 | function getDefinitions() {
|
39856 | var rootElement = canvas.getRootElement(),
|
39857 | businessObject = getBusinessObject(rootElement);
|
39858 |
|
39859 | return businessObject.$parent;
|
39860 | }
|
39861 |
|
39862 | |
39863 |
|
39864 |
|
39865 |
|
39866 |
|
39867 | function removeReferencedCategoryValue(shape) {
|
39868 |
|
39869 | var businessObject = getBusinessObject(shape),
|
39870 | categoryValue = businessObject.categoryValueRef;
|
39871 |
|
39872 | if (!categoryValue) {
|
39873 | return;
|
39874 | }
|
39875 |
|
39876 | var category = categoryValue.$parent;
|
39877 |
|
39878 | if (!categoryValue) {
|
39879 | return;
|
39880 | }
|
39881 |
|
39882 | remove$2(category.categoryValue, categoryValue);
|
39883 |
|
39884 |
|
39885 | if (category && !category.categoryValue.length) {
|
39886 | removeCategory(category);
|
39887 | }
|
39888 | }
|
39889 |
|
39890 | |
39891 |
|
39892 |
|
39893 |
|
39894 |
|
39895 | function removeCategory(category) {
|
39896 |
|
39897 | var definitions = getDefinitions();
|
39898 |
|
39899 | remove$2(definitions.get('rootElements'), category);
|
39900 | }
|
39901 |
|
39902 | |
39903 |
|
39904 |
|
39905 |
|
39906 |
|
39907 | function getGroupElements() {
|
39908 | return elementRegistry.filter(function(e) {
|
39909 | return is$1(e, 'bpmn:Group');
|
39910 | });
|
39911 | }
|
39912 |
|
39913 | |
39914 |
|
39915 |
|
39916 |
|
39917 |
|
39918 |
|
39919 |
|
39920 | function isReferenced(elements, categoryValue) {
|
39921 | return elements.some(function(e) {
|
39922 |
|
39923 | var businessObject = getBusinessObject(e);
|
39924 |
|
39925 | return businessObject.categoryValueRef
|
39926 | && businessObject.categoryValueRef === categoryValue;
|
39927 | });
|
39928 | }
|
39929 |
|
39930 | |
39931 |
|
39932 |
|
39933 | this.executed('shape.delete', function(event) {
|
39934 |
|
39935 | var context = event.context,
|
39936 | shape = context.shape;
|
39937 |
|
39938 | if (is$1(shape, 'bpmn:Group')) {
|
39939 |
|
39940 | var businessObject = getBusinessObject(shape),
|
39941 | categoryValueRef = businessObject.categoryValueRef,
|
39942 | groupElements = getGroupElements();
|
39943 |
|
39944 | if (!isReferenced(groupElements, categoryValueRef)) {
|
39945 | removeReferencedCategoryValue(shape);
|
39946 | }
|
39947 | }
|
39948 | });
|
39949 |
|
39950 | |
39951 |
|
39952 |
|
39953 | this.reverted('shape.delete', function(event) {
|
39954 |
|
39955 | var context = event.context,
|
39956 | shape = context.shape;
|
39957 |
|
39958 | if (is$1(shape, 'bpmn:Group')) {
|
39959 |
|
39960 | var businessObject = getBusinessObject(shape),
|
39961 | categoryValueRef = businessObject.categoryValueRef,
|
39962 | definitions = getDefinitions(),
|
39963 | category = categoryValueRef ? categoryValueRef.$parent : null;
|
39964 |
|
39965 | add$1(category.get('categoryValue'), categoryValueRef);
|
39966 | add$1(definitions.get('rootElements'), category);
|
39967 | }
|
39968 | });
|
39969 |
|
39970 | |
39971 |
|
39972 |
|
39973 | this.execute('shape.create', function(event) {
|
39974 | var context = event.context,
|
39975 | shape = context.shape,
|
39976 | businessObject = getBusinessObject(shape);
|
39977 |
|
39978 | if (is$1(businessObject, 'bpmn:Group') && !businessObject.categoryValueRef) {
|
39979 |
|
39980 | var definitions = getDefinitions(),
|
39981 | categoryValue = createCategoryValue(definitions, bpmnFactory);
|
39982 |
|
39983 |
|
39984 | businessObject.categoryValueRef = categoryValue;
|
39985 | }
|
39986 | });
|
39987 |
|
39988 |
|
39989 | this.revert('shape.create', function(event) {
|
39990 |
|
39991 | var context = event.context,
|
39992 | shape = context.shape;
|
39993 |
|
39994 | if (is$1(shape, 'bpmn:Group')) {
|
39995 | removeReferencedCategoryValue(shape);
|
39996 |
|
39997 | delete getBusinessObject(shape).categoryValueRef;
|
39998 |
|
39999 | }
|
40000 | });
|
40001 |
|
40002 |
|
40003 | eventBus.on('moddleCopy.canCopyProperty', HIGH_PRIORITY$7, function(context) {
|
40004 | var property = context.property,
|
40005 | categoryValue;
|
40006 |
|
40007 | if (is$1(property, 'bpmn:CategoryValue')) {
|
40008 | categoryValue = createCategoryValue(getDefinitions(), bpmnFactory);
|
40009 |
|
40010 |
|
40011 | return moddleCopy.copyElement(property, categoryValue);
|
40012 | }
|
40013 | });
|
40014 |
|
40015 | }
|
40016 |
|
40017 | GroupBehavior.$inject = [
|
40018 | 'bpmnFactory',
|
40019 | 'canvas',
|
40020 | 'elementRegistry',
|
40021 | 'eventBus',
|
40022 | 'injector',
|
40023 | 'moddleCopy'
|
40024 | ];
|
40025 |
|
40026 | inherits_browser(GroupBehavior, CommandInterceptor);
|
40027 |
|
40028 | |
40029 |
|
40030 |
|
40031 |
|
40032 |
|
40033 |
|
40034 |
|
40035 |
|
40036 |
|
40037 |
|
40038 | function lineIntersect(l1s, l1e, l2s, l2e) {
|
40039 |
|
40040 |
|
40041 |
|
40042 |
|
40043 | var denominator, a, b, c, numerator;
|
40044 |
|
40045 | denominator = ((l2e.y - l2s.y) * (l1e.x - l1s.x)) - ((l2e.x - l2s.x) * (l1e.y - l1s.y));
|
40046 |
|
40047 | if (denominator == 0) {
|
40048 | return null;
|
40049 | }
|
40050 |
|
40051 | a = l1s.y - l2s.y;
|
40052 | b = l1s.x - l2s.x;
|
40053 | numerator = ((l2e.x - l2s.x) * a) - ((l2e.y - l2s.y) * b);
|
40054 |
|
40055 | c = numerator / denominator;
|
40056 |
|
40057 |
|
40058 |
|
40059 | return {
|
40060 | x: Math.round(l1s.x + (c * (l1e.x - l1s.x))),
|
40061 | y: Math.round(l1s.y + (c * (l1e.y - l1s.y)))
|
40062 | };
|
40063 | }
|
40064 |
|
40065 | |
40066 |
|
40067 |
|
40068 |
|
40069 |
|
40070 | function ImportDockingFix(eventBus) {
|
40071 |
|
40072 | function adjustDocking(startPoint, nextPoint, elementMid) {
|
40073 |
|
40074 | var elementTop = {
|
40075 | x: elementMid.x,
|
40076 | y: elementMid.y - 50
|
40077 | };
|
40078 |
|
40079 | var elementLeft = {
|
40080 | x: elementMid.x - 50,
|
40081 | y: elementMid.y
|
40082 | };
|
40083 |
|
40084 | var verticalIntersect = lineIntersect(startPoint, nextPoint, elementMid, elementTop),
|
40085 | horizontalIntersect = lineIntersect(startPoint, nextPoint, elementMid, elementLeft);
|
40086 |
|
40087 |
|
40088 | var centerIntersect;
|
40089 |
|
40090 | if (verticalIntersect && horizontalIntersect) {
|
40091 | if (getDistance(verticalIntersect, elementMid) > getDistance(horizontalIntersect, elementMid)) {
|
40092 | centerIntersect = horizontalIntersect;
|
40093 | } else {
|
40094 | centerIntersect = verticalIntersect;
|
40095 | }
|
40096 | } else {
|
40097 | centerIntersect = verticalIntersect || horizontalIntersect;
|
40098 | }
|
40099 |
|
40100 | startPoint.original = centerIntersect;
|
40101 | }
|
40102 |
|
40103 | function fixDockings(connection) {
|
40104 | var waypoints = connection.waypoints;
|
40105 |
|
40106 | adjustDocking(
|
40107 | waypoints[0],
|
40108 | waypoints[1],
|
40109 | getMid(connection.source)
|
40110 | );
|
40111 |
|
40112 | adjustDocking(
|
40113 | waypoints[waypoints.length - 1],
|
40114 | waypoints[waypoints.length - 2],
|
40115 | getMid(connection.target)
|
40116 | );
|
40117 | }
|
40118 |
|
40119 | eventBus.on('bpmnElement.added', function(e) {
|
40120 |
|
40121 | var element = e.element;
|
40122 |
|
40123 | if (element.waypoints) {
|
40124 | fixDockings(element);
|
40125 | }
|
40126 | });
|
40127 | }
|
40128 |
|
40129 | ImportDockingFix.$inject = [
|
40130 | 'eventBus'
|
40131 | ];
|
40132 |
|
40133 |
|
40134 |
|
40135 |
|
40136 | function getDistance(p1, p2) {
|
40137 | return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
|
40138 | }
|
40139 |
|
40140 | |
40141 |
|
40142 |
|
40143 |
|
40144 |
|
40145 |
|
40146 | function IsHorizontalFix(eventBus) {
|
40147 |
|
40148 | CommandInterceptor.call(this, eventBus);
|
40149 |
|
40150 | var elementTypesToUpdate = [
|
40151 | 'bpmn:Participant',
|
40152 | 'bpmn:Lane'
|
40153 | ];
|
40154 |
|
40155 | this.executed([ 'shape.move', 'shape.create', 'shape.resize' ], function(event) {
|
40156 | var bo = getBusinessObject(event.context.shape);
|
40157 |
|
40158 | if (isAny(bo, elementTypesToUpdate) && !bo.di.get('isHorizontal')) {
|
40159 |
|
40160 |
|
40161 | bo.di.set('isHorizontal', true);
|
40162 | }
|
40163 | });
|
40164 |
|
40165 | }
|
40166 |
|
40167 | IsHorizontalFix.$inject = [ 'eventBus' ];
|
40168 |
|
40169 | inherits_browser(IsHorizontalFix, CommandInterceptor);
|
40170 |
|
40171 | |
40172 |
|
40173 |
|
40174 |
|
40175 |
|
40176 |
|
40177 | function vectorLength(v) {
|
40178 | return Math.sqrt(Math.pow(v.x, 2) + Math.pow(v.y, 2));
|
40179 | }
|
40180 |
|
40181 |
|
40182 | |
40183 |
|
40184 |
|
40185 |
|
40186 |
|
40187 |
|
40188 | function getAngle(line) {
|
40189 |
|
40190 |
|
40191 |
|
40192 | return Math.atan((line[1].y - line[0].y) / (line[1].x - line[0].x));
|
40193 | }
|
40194 |
|
40195 |
|
40196 | |
40197 |
|
40198 |
|
40199 |
|
40200 |
|
40201 |
|
40202 |
|
40203 | function rotateVector(vector, angle) {
|
40204 | return (!angle) ? vector : {
|
40205 | x: Math.cos(angle) * vector.x - Math.sin(angle) * vector.y,
|
40206 | y: Math.sin(angle) * vector.x + Math.cos(angle) * vector.y
|
40207 | };
|
40208 | }
|
40209 |
|
40210 |
|
40211 | |
40212 |
|
40213 |
|
40214 |
|
40215 |
|
40216 |
|
40217 |
|
40218 |
|
40219 |
|
40220 | function solveLambaSystem(a, b, c) {
|
40221 |
|
40222 |
|
40223 | var system = [
|
40224 | { n: a[0] - c[0], lambda: b[0] },
|
40225 | { n: a[1] - c[1], lambda: b[1] }
|
40226 | ];
|
40227 |
|
40228 |
|
40229 | var n = system[0].n * b[0] + system[1].n * b[1],
|
40230 | l = system[0].lambda * b[0] + system[1].lambda * b[1];
|
40231 |
|
40232 | return -n/l;
|
40233 | }
|
40234 |
|
40235 |
|
40236 | |
40237 |
|
40238 |
|
40239 |
|
40240 |
|
40241 |
|
40242 |
|
40243 | function perpendicularFoot(point, line) {
|
40244 |
|
40245 | var a = line[0], b = line[1];
|
40246 |
|
40247 |
|
40248 | var bd = { x: b.x - a.x, y: b.y - a.y };
|
40249 |
|
40250 |
|
40251 | var r = solveLambaSystem([ a.x, a.y ], [ bd.x, bd.y ], [ point.x, point.y ]);
|
40252 |
|
40253 | return { x: a.x + r*bd.x, y: a.y + r*bd.y };
|
40254 | }
|
40255 |
|
40256 |
|
40257 | |
40258 |
|
40259 |
|
40260 |
|
40261 |
|
40262 |
|
40263 |
|
40264 | function getDistancePointLine(point, line) {
|
40265 |
|
40266 | var pfPoint = perpendicularFoot(point, line);
|
40267 |
|
40268 |
|
40269 | var connectionVector = {
|
40270 | x: pfPoint.x - point.x,
|
40271 | y: pfPoint.y - point.y
|
40272 | };
|
40273 |
|
40274 | return vectorLength(connectionVector);
|
40275 | }
|
40276 |
|
40277 |
|
40278 | |
40279 |
|
40280 |
|
40281 |
|
40282 |
|
40283 |
|
40284 |
|
40285 | function getDistancePointPoint(point1, point2) {
|
40286 |
|
40287 | return vectorLength({
|
40288 | x: point1.x - point2.x,
|
40289 | y: point1.y - point2.y
|
40290 | });
|
40291 | }
|
40292 |
|
40293 | var sqrt = Math.sqrt,
|
40294 | min$2 = Math.min,
|
40295 | max$3 = Math.max,
|
40296 | abs$4 = Math.abs;
|
40297 |
|
40298 | |
40299 |
|
40300 |
|
40301 |
|
40302 |
|
40303 |
|
40304 |
|
40305 | function sq(n) {
|
40306 | return Math.pow(n, 2);
|
40307 | }
|
40308 |
|
40309 | |
40310 |
|
40311 |
|
40312 |
|
40313 |
|
40314 |
|
40315 |
|
40316 |
|
40317 | function getDistance$1(p1, p2) {
|
40318 | return sqrt(sq(p1.x - p2.x) + sq(p1.y - p2.y));
|
40319 | }
|
40320 |
|
40321 | |
40322 |
|
40323 |
|
40324 |
|
40325 |
|
40326 |
|
40327 |
|
40328 |
|
40329 |
|
40330 |
|
40331 |
|
40332 |
|
40333 |
|
40334 |
|
40335 |
|
40336 |
|
40337 |
|
40338 |
|
40339 |
|
40340 |
|
40341 |
|
40342 |
|
40343 |
|
40344 |
|
40345 |
|
40346 |
|
40347 | function getAttachment(point, line) {
|
40348 |
|
40349 | var idx = 0,
|
40350 | segmentStart,
|
40351 | segmentEnd,
|
40352 | segmentStartDistance,
|
40353 | segmentEndDistance,
|
40354 | attachmentPosition,
|
40355 | minDistance,
|
40356 | intersections,
|
40357 | attachment,
|
40358 | attachmentDistance,
|
40359 | closestAttachmentDistance,
|
40360 | closestAttachment;
|
40361 |
|
40362 | for (idx = 0; idx < line.length - 1; idx++) {
|
40363 |
|
40364 | segmentStart = line[idx];
|
40365 | segmentEnd = line[idx + 1];
|
40366 |
|
40367 | if (pointsEqual(segmentStart, segmentEnd)) {
|
40368 | intersections = [ segmentStart ];
|
40369 | } else {
|
40370 | segmentStartDistance = getDistance$1(point, segmentStart);
|
40371 | segmentEndDistance = getDistance$1(point, segmentEnd);
|
40372 |
|
40373 | minDistance = min$2(segmentStartDistance, segmentEndDistance);
|
40374 |
|
40375 | intersections = getCircleSegmentIntersections(segmentStart, segmentEnd, point, minDistance);
|
40376 | }
|
40377 |
|
40378 | if (intersections.length < 1) {
|
40379 | throw new Error('expected between [1, 2] circle -> line intersections');
|
40380 | }
|
40381 |
|
40382 |
|
40383 | if (intersections.length === 1) {
|
40384 | attachment = {
|
40385 | type: 'bendpoint',
|
40386 | position: intersections[0],
|
40387 | segmentIndex: idx,
|
40388 | bendpointIndex: pointsEqual(segmentStart, intersections[0]) ? idx : idx + 1
|
40389 | };
|
40390 | }
|
40391 |
|
40392 |
|
40393 | if (intersections.length === 2) {
|
40394 |
|
40395 | attachmentPosition = mid$1(intersections[0], intersections[1]);
|
40396 |
|
40397 | attachment = {
|
40398 | type: 'segment',
|
40399 | position: attachmentPosition,
|
40400 | segmentIndex: idx,
|
40401 | relativeLocation: getDistance$1(segmentStart, attachmentPosition) / getDistance$1(segmentStart, segmentEnd)
|
40402 | };
|
40403 | }
|
40404 |
|
40405 | attachmentDistance = getDistance$1(attachment.position, point);
|
40406 |
|
40407 | if (!closestAttachment || closestAttachmentDistance > attachmentDistance) {
|
40408 | closestAttachment = attachment;
|
40409 | closestAttachmentDistance = attachmentDistance;
|
40410 | }
|
40411 | }
|
40412 |
|
40413 | return closestAttachment;
|
40414 | }
|
40415 |
|
40416 | |
40417 |
|
40418 |
|
40419 |
|
40420 |
|
40421 |
|
40422 |
|
40423 |
|
40424 |
|
40425 |
|
40426 | function getCircleSegmentIntersections(s1, s2, cc, cr) {
|
40427 |
|
40428 | var baX = s2.x - s1.x;
|
40429 | var baY = s2.y - s1.y;
|
40430 | var caX = cc.x - s1.x;
|
40431 | var caY = cc.y - s1.y;
|
40432 |
|
40433 | var a = baX * baX + baY * baY;
|
40434 | var bBy2 = baX * caX + baY * caY;
|
40435 | var c = caX * caX + caY * caY - cr * cr;
|
40436 |
|
40437 | var pBy2 = bBy2 / a;
|
40438 | var q = c / a;
|
40439 |
|
40440 | var disc = pBy2 * pBy2 - q;
|
40441 |
|
40442 |
|
40443 |
|
40444 |
|
40445 | if (disc < 0 && disc > -0.000001) {
|
40446 | disc = 0;
|
40447 | }
|
40448 |
|
40449 | if (disc < 0) {
|
40450 | return [];
|
40451 | }
|
40452 |
|
40453 |
|
40454 | var tmpSqrt = sqrt(disc);
|
40455 | var abScalingFactor1 = -pBy2 + tmpSqrt;
|
40456 | var abScalingFactor2 = -pBy2 - tmpSqrt;
|
40457 |
|
40458 | var i1 = {
|
40459 | x: s1.x - baX * abScalingFactor1,
|
40460 | y: s1.y - baY * abScalingFactor1
|
40461 | };
|
40462 |
|
40463 | if (disc === 0) {
|
40464 | return [ i1 ];
|
40465 | }
|
40466 |
|
40467 | var i2 = {
|
40468 | x: s1.x - baX * abScalingFactor2,
|
40469 | y: s1.y - baY * abScalingFactor2
|
40470 | };
|
40471 |
|
40472 |
|
40473 | return [ i1, i2 ].filter(function(p) {
|
40474 | return isPointInSegment(p, s1, s2);
|
40475 | });
|
40476 | }
|
40477 |
|
40478 |
|
40479 | function isPointInSegment(p, segmentStart, segmentEnd) {
|
40480 | return (
|
40481 | fenced(p.x, segmentStart.x, segmentEnd.x) &&
|
40482 | fenced(p.y, segmentStart.y, segmentEnd.y)
|
40483 | );
|
40484 | }
|
40485 |
|
40486 | function fenced(n, rangeStart, rangeEnd) {
|
40487 |
|
40488 |
|
40489 |
|
40490 |
|
40491 | return (
|
40492 | n >= min$2(rangeStart, rangeEnd) - EQUAL_THRESHOLD &&
|
40493 | n <= max$3(rangeStart, rangeEnd) + EQUAL_THRESHOLD
|
40494 | );
|
40495 | }
|
40496 |
|
40497 | |
40498 |
|
40499 |
|
40500 |
|
40501 |
|
40502 |
|
40503 |
|
40504 |
|
40505 | function mid$1(p1, p2) {
|
40506 |
|
40507 | return {
|
40508 | x: (p1.x + p2.x) / 2,
|
40509 | y: (p1.y + p2.y) / 2
|
40510 | };
|
40511 | }
|
40512 |
|
40513 | var EQUAL_THRESHOLD = 0.1;
|
40514 |
|
40515 | function pointsEqual(p1, p2) {
|
40516 |
|
40517 | return (
|
40518 | abs$4(p1.x - p2.x) <= EQUAL_THRESHOLD &&
|
40519 | abs$4(p1.y - p2.y) <= EQUAL_THRESHOLD
|
40520 | );
|
40521 | }
|
40522 |
|
40523 | function findNewLabelLineStartIndex(oldWaypoints, newWaypoints, attachment, hints) {
|
40524 |
|
40525 | var index = attachment.segmentIndex;
|
40526 |
|
40527 | var offset = newWaypoints.length - oldWaypoints.length;
|
40528 |
|
40529 |
|
40530 | if (hints.segmentMove) {
|
40531 |
|
40532 | var oldSegmentStartIndex = hints.segmentMove.segmentStartIndex,
|
40533 | newSegmentStartIndex = hints.segmentMove.newSegmentStartIndex;
|
40534 |
|
40535 |
|
40536 | if (index === oldSegmentStartIndex) {
|
40537 | return newSegmentStartIndex;
|
40538 | }
|
40539 |
|
40540 |
|
40541 | if (index >= newSegmentStartIndex) {
|
40542 | return (index+offset < newSegmentStartIndex) ? newSegmentStartIndex : index+offset;
|
40543 | }
|
40544 |
|
40545 |
|
40546 | return index;
|
40547 | }
|
40548 |
|
40549 |
|
40550 | if (hints.bendpointMove) {
|
40551 |
|
40552 | var insert = hints.bendpointMove.insert,
|
40553 | bendpointIndex = hints.bendpointMove.bendpointIndex,
|
40554 | newIndex;
|
40555 |
|
40556 |
|
40557 | if (offset === 0) {
|
40558 | return index;
|
40559 | }
|
40560 |
|
40561 |
|
40562 | if (index >= bendpointIndex) {
|
40563 | newIndex = insert ? index + 1 : index - 1;
|
40564 | }
|
40565 |
|
40566 |
|
40567 | if (index < bendpointIndex) {
|
40568 |
|
40569 | newIndex = index;
|
40570 |
|
40571 |
|
40572 | if (insert && attachment.type !== 'bendpoint' && bendpointIndex-1 === index) {
|
40573 |
|
40574 | var rel = relativePositionMidWaypoint(newWaypoints, bendpointIndex);
|
40575 |
|
40576 | if (rel < attachment.relativeLocation) {
|
40577 | newIndex++;
|
40578 | }
|
40579 | }
|
40580 | }
|
40581 |
|
40582 | return newIndex;
|
40583 | }
|
40584 |
|
40585 |
|
40586 | if (offset === 0) {
|
40587 | return index;
|
40588 | }
|
40589 |
|
40590 | if (hints.connectionStart) {
|
40591 | return (index === 0) ? 0 : null;
|
40592 | }
|
40593 |
|
40594 | if (hints.connectionEnd) {
|
40595 | return (index === oldWaypoints.length - 2) ? newWaypoints.length - 2 : null;
|
40596 | }
|
40597 |
|
40598 |
|
40599 | return null;
|
40600 | }
|
40601 |
|
40602 |
|
40603 | |
40604 |
|
40605 |
|
40606 |
|
40607 |
|
40608 |
|
40609 |
|
40610 |
|
40611 |
|
40612 |
|
40613 |
|
40614 | function getLabelAdjustment(label, newWaypoints, oldWaypoints, hints) {
|
40615 |
|
40616 | var x = 0,
|
40617 | y = 0;
|
40618 |
|
40619 | var labelPosition = getLabelMid(label);
|
40620 |
|
40621 |
|
40622 | var attachment = getAttachment(labelPosition, oldWaypoints),
|
40623 | oldLabelLineIndex = attachment.segmentIndex,
|
40624 | newLabelLineIndex = findNewLabelLineStartIndex(oldWaypoints, newWaypoints, attachment, hints);
|
40625 |
|
40626 | if (newLabelLineIndex === null) {
|
40627 | return { x: x, y: y };
|
40628 | }
|
40629 |
|
40630 |
|
40631 |
|
40632 | if (newLabelLineIndex < 0 ||
|
40633 | newLabelLineIndex > newWaypoints.length - 2) {
|
40634 | return { x: x, y: y };
|
40635 | }
|
40636 |
|
40637 | var oldLabelLine = getLine(oldWaypoints, oldLabelLineIndex),
|
40638 | newLabelLine = getLine(newWaypoints, newLabelLineIndex),
|
40639 | oldFoot = attachment.position;
|
40640 |
|
40641 | var relativeFootPosition = getRelativeFootPosition(oldLabelLine, oldFoot),
|
40642 | angleDelta = getAngleDelta(oldLabelLine, newLabelLine);
|
40643 |
|
40644 |
|
40645 | if (attachment.type === 'bendpoint') {
|
40646 |
|
40647 | var offset = newWaypoints.length - oldWaypoints.length,
|
40648 | oldBendpointIndex = attachment.bendpointIndex,
|
40649 | oldBendpoint = oldWaypoints[oldBendpointIndex];
|
40650 |
|
40651 |
|
40652 | if (newWaypoints.indexOf(oldBendpoint) !== -1) {
|
40653 | return { x: x, y: y };
|
40654 | }
|
40655 |
|
40656 |
|
40657 | if (offset === 0) {
|
40658 | var newBendpoint = newWaypoints[oldBendpointIndex];
|
40659 |
|
40660 | return {
|
40661 | x: newBendpoint.x - attachment.position.x,
|
40662 | y: newBendpoint.y - attachment.position.y
|
40663 | };
|
40664 | }
|
40665 |
|
40666 |
|
40667 | if (offset < 0 && oldBendpointIndex !== 0 && oldBendpointIndex < oldWaypoints.length - 1) {
|
40668 | relativeFootPosition = relativePositionMidWaypoint(oldWaypoints, oldBendpointIndex);
|
40669 | }
|
40670 | }
|
40671 |
|
40672 | var newFoot = {
|
40673 | x: (newLabelLine[1].x - newLabelLine[0].x) * relativeFootPosition + newLabelLine[0].x,
|
40674 | y: (newLabelLine[1].y - newLabelLine[0].y) * relativeFootPosition + newLabelLine[0].y
|
40675 | };
|
40676 |
|
40677 |
|
40678 | var newLabelVector = rotateVector({
|
40679 | x: labelPosition.x - oldFoot.x,
|
40680 | y: labelPosition.y - oldFoot.y
|
40681 | }, angleDelta);
|
40682 |
|
40683 |
|
40684 | x = newFoot.x + newLabelVector.x - labelPosition.x;
|
40685 | y = newFoot.y + newLabelVector.y - labelPosition.y;
|
40686 |
|
40687 | return roundPoint({
|
40688 | x: x,
|
40689 | y: y
|
40690 | });
|
40691 | }
|
40692 |
|
40693 |
|
40694 |
|
40695 |
|
40696 | function relativePositionMidWaypoint(waypoints, idx) {
|
40697 |
|
40698 | var distanceSegment1 = getDistancePointPoint(waypoints[idx-1], waypoints[idx]),
|
40699 | distanceSegment2 = getDistancePointPoint(waypoints[idx], waypoints[idx+1]);
|
40700 |
|
40701 | var relativePosition = distanceSegment1 / (distanceSegment1 + distanceSegment2);
|
40702 |
|
40703 | return relativePosition;
|
40704 | }
|
40705 |
|
40706 | function getLabelMid(label) {
|
40707 | return {
|
40708 | x: label.x + label.width / 2,
|
40709 | y: label.y + label.height / 2
|
40710 | };
|
40711 | }
|
40712 |
|
40713 | function getAngleDelta(l1, l2) {
|
40714 | var a1 = getAngle(l1),
|
40715 | a2 = getAngle(l2);
|
40716 | return a2 - a1;
|
40717 | }
|
40718 |
|
40719 | function getLine(waypoints, idx) {
|
40720 | return [ waypoints[idx], waypoints[idx+1] ];
|
40721 | }
|
40722 |
|
40723 | function getRelativeFootPosition(line, foot) {
|
40724 |
|
40725 | var length = getDistancePointPoint(line[0], line[1]),
|
40726 | lengthToFoot = getDistancePointPoint(line[0], foot);
|
40727 |
|
40728 | return length === 0 ? 0 : lengthToFoot / length;
|
40729 | }
|
40730 |
|
40731 | |
40732 |
|
40733 |
|
40734 |
|
40735 |
|
40736 |
|
40737 |
|
40738 |
|
40739 |
|
40740 | function getNewAttachPoint(point, oldBounds, newBounds) {
|
40741 | var oldCenter = center(oldBounds),
|
40742 | newCenter = center(newBounds),
|
40743 | oldDelta = delta(point, oldCenter);
|
40744 |
|
40745 | var newDelta = {
|
40746 | x: oldDelta.x * (newBounds.width / oldBounds.width),
|
40747 | y: oldDelta.y * (newBounds.height / oldBounds.height)
|
40748 | };
|
40749 |
|
40750 | return roundPoint({
|
40751 | x: newCenter.x + newDelta.x,
|
40752 | y: newCenter.y + newDelta.y
|
40753 | });
|
40754 | }
|
40755 |
|
40756 |
|
40757 | |
40758 |
|
40759 |
|
40760 |
|
40761 |
|
40762 |
|
40763 |
|
40764 |
|
40765 |
|
40766 |
|
40767 | function getNewAttachShapeDelta(shape, oldBounds, newBounds) {
|
40768 | var shapeCenter = center(shape),
|
40769 | oldCenter = center(oldBounds),
|
40770 | newCenter = center(newBounds),
|
40771 | shapeDelta = delta(shape, shapeCenter),
|
40772 | oldCenterDelta = delta(shapeCenter, oldCenter);
|
40773 |
|
40774 | var newCenterDelta = {
|
40775 | x: oldCenterDelta.x * (newBounds.width / oldBounds.width),
|
40776 | y: oldCenterDelta.y * (newBounds.height / oldBounds.height)
|
40777 | };
|
40778 |
|
40779 | var newShapeCenter = {
|
40780 | x: newCenter.x + newCenterDelta.x,
|
40781 | y: newCenter.y + newCenterDelta.y
|
40782 | };
|
40783 |
|
40784 | return roundPoint({
|
40785 | x: newShapeCenter.x + shapeDelta.x - shape.x,
|
40786 | y: newShapeCenter.y + shapeDelta.y - shape.y
|
40787 | });
|
40788 | }
|
40789 |
|
40790 | var DEFAULT_LABEL_DIMENSIONS = {
|
40791 | width: 90,
|
40792 | height: 20
|
40793 | };
|
40794 |
|
40795 | var NAME_PROPERTY = 'name';
|
40796 | var TEXT_PROPERTY = 'text';
|
40797 |
|
40798 | |
40799 |
|
40800 |
|
40801 |
|
40802 |
|
40803 |
|
40804 |
|
40805 |
|
40806 |
|
40807 |
|
40808 | function LabelBehavior(
|
40809 | eventBus, modeling, bpmnFactory,
|
40810 | textRenderer) {
|
40811 |
|
40812 | CommandInterceptor.call(this, eventBus);
|
40813 |
|
40814 |
|
40815 | this.postExecute('element.updateProperties', function(e) {
|
40816 | var context = e.context,
|
40817 | element = context.element,
|
40818 | properties = context.properties;
|
40819 |
|
40820 | if (NAME_PROPERTY in properties) {
|
40821 | modeling.updateLabel(element, properties[NAME_PROPERTY]);
|
40822 | }
|
40823 |
|
40824 | if (TEXT_PROPERTY in properties
|
40825 | && is$1(element, 'bpmn:TextAnnotation')) {
|
40826 |
|
40827 | var newBounds = textRenderer.getTextAnnotationBounds(
|
40828 | {
|
40829 | x: element.x,
|
40830 | y: element.y,
|
40831 | width: element.width,
|
40832 | height: element.height
|
40833 | },
|
40834 | properties[TEXT_PROPERTY] || ''
|
40835 | );
|
40836 |
|
40837 | modeling.updateLabel(element, properties.text, newBounds);
|
40838 | }
|
40839 | });
|
40840 |
|
40841 |
|
40842 | this.postExecute([ 'shape.create', 'connection.create' ], function(e) {
|
40843 | var context = e.context,
|
40844 | hints = context.hints || {};
|
40845 |
|
40846 | if (hints.createElementsBehavior === false) {
|
40847 | return;
|
40848 | }
|
40849 |
|
40850 | var element = context.shape || context.connection,
|
40851 | businessObject = element.businessObject;
|
40852 |
|
40853 | if (!isLabelExternal(element)) {
|
40854 | return;
|
40855 | }
|
40856 |
|
40857 |
|
40858 | if (!getLabel(element)) {
|
40859 | return;
|
40860 | }
|
40861 |
|
40862 | var labelCenter = getExternalLabelMid(element);
|
40863 |
|
40864 |
|
40865 | var labelDimensions = textRenderer.getExternalLabelBounds(
|
40866 | DEFAULT_LABEL_DIMENSIONS,
|
40867 | getLabel(element)
|
40868 | );
|
40869 |
|
40870 | modeling.createLabel(element, labelCenter, {
|
40871 | id: businessObject.id + '_label',
|
40872 | businessObject: businessObject,
|
40873 | width: labelDimensions.width,
|
40874 | height: labelDimensions.height
|
40875 | });
|
40876 | });
|
40877 |
|
40878 |
|
40879 | this.postExecute('shape.delete', function(event) {
|
40880 | var context = event.context,
|
40881 | labelTarget = context.labelTarget,
|
40882 | hints = context.hints || {};
|
40883 |
|
40884 |
|
40885 | if (labelTarget && hints.unsetLabel !== false) {
|
40886 | modeling.updateLabel(labelTarget, null, null, { removeShape: false });
|
40887 | }
|
40888 | });
|
40889 |
|
40890 |
|
40891 | this.postExecute([ 'label.create' ], function(event) {
|
40892 |
|
40893 | var context = event.context,
|
40894 | element = context.shape,
|
40895 | businessObject,
|
40896 | di;
|
40897 |
|
40898 |
|
40899 | if (!element.labelTarget) {
|
40900 | return;
|
40901 | }
|
40902 |
|
40903 |
|
40904 | if (!is$1(element.labelTarget || element, 'bpmn:BaseElement')) {
|
40905 | return;
|
40906 | }
|
40907 |
|
40908 | businessObject = element.businessObject,
|
40909 | di = businessObject.di;
|
40910 |
|
40911 |
|
40912 | if (!di.label) {
|
40913 | di.label = bpmnFactory.create('bpmndi:BPMNLabel', {
|
40914 | bounds: bpmnFactory.create('dc:Bounds')
|
40915 | });
|
40916 | }
|
40917 |
|
40918 | assign(di.label.bounds, {
|
40919 | x: element.x,
|
40920 | y: element.y,
|
40921 | width: element.width,
|
40922 | height: element.height
|
40923 | });
|
40924 | });
|
40925 |
|
40926 | function getVisibleLabelAdjustment(event) {
|
40927 |
|
40928 | var context = event.context,
|
40929 | connection = context.connection,
|
40930 | label = connection.label,
|
40931 | hints = assign({}, context.hints),
|
40932 | newWaypoints = context.newWaypoints || connection.waypoints,
|
40933 | oldWaypoints = context.oldWaypoints;
|
40934 |
|
40935 |
|
40936 | if (typeof hints.startChanged === 'undefined') {
|
40937 | hints.startChanged = !!hints.connectionStart;
|
40938 | }
|
40939 |
|
40940 | if (typeof hints.endChanged === 'undefined') {
|
40941 | hints.endChanged = !!hints.connectionEnd;
|
40942 | }
|
40943 |
|
40944 | return getLabelAdjustment(label, newWaypoints, oldWaypoints, hints);
|
40945 | }
|
40946 |
|
40947 | this.postExecute([
|
40948 | 'connection.layout',
|
40949 | 'connection.updateWaypoints'
|
40950 | ], function(event) {
|
40951 |
|
40952 | var label = event.context.connection.label,
|
40953 | labelAdjustment;
|
40954 |
|
40955 | if (!label) {
|
40956 | return;
|
40957 | }
|
40958 |
|
40959 | labelAdjustment = getVisibleLabelAdjustment(event);
|
40960 |
|
40961 | modeling.moveShape(label, labelAdjustment);
|
40962 | });
|
40963 |
|
40964 |
|
40965 |
|
40966 | this.postExecute([ 'shape.replace' ], function(event) {
|
40967 | var context = event.context,
|
40968 | newShape = context.newShape,
|
40969 | oldShape = context.oldShape;
|
40970 |
|
40971 | var businessObject = getBusinessObject(newShape);
|
40972 |
|
40973 | if (businessObject
|
40974 | && isLabelExternal(businessObject)
|
40975 | && oldShape.label
|
40976 | && newShape.label) {
|
40977 | newShape.label.x = oldShape.label.x;
|
40978 | newShape.label.y = oldShape.label.y;
|
40979 | }
|
40980 | });
|
40981 |
|
40982 |
|
40983 |
|
40984 | this.postExecute('shape.resize', function(event) {
|
40985 |
|
40986 | var context = event.context,
|
40987 | shape = context.shape,
|
40988 | newBounds = context.newBounds,
|
40989 | oldBounds = context.oldBounds;
|
40990 |
|
40991 | if (hasExternalLabel(shape)) {
|
40992 |
|
40993 | var label = shape.label,
|
40994 | labelMid = getMid(label),
|
40995 | edges = asEdges(oldBounds);
|
40996 |
|
40997 |
|
40998 | var referencePoint = getReferencePoint(labelMid, edges);
|
40999 |
|
41000 | var delta = getReferencePointDelta(referencePoint, oldBounds, newBounds);
|
41001 |
|
41002 | modeling.moveShape(label, delta);
|
41003 |
|
41004 | }
|
41005 |
|
41006 | });
|
41007 |
|
41008 | }
|
41009 |
|
41010 | inherits_browser(LabelBehavior, CommandInterceptor);
|
41011 |
|
41012 | LabelBehavior.$inject = [
|
41013 | 'eventBus',
|
41014 | 'modeling',
|
41015 | 'bpmnFactory',
|
41016 | 'textRenderer'
|
41017 | ];
|
41018 |
|
41019 |
|
41020 |
|
41021 | |
41022 |
|
41023 |
|
41024 |
|
41025 |
|
41026 |
|
41027 |
|
41028 |
|
41029 |
|
41030 |
|
41031 | function getReferencePointDelta(referencePoint, oldBounds, newBounds) {
|
41032 |
|
41033 | var newReferencePoint = getNewAttachPoint(referencePoint, oldBounds, newBounds);
|
41034 |
|
41035 | return roundPoint(delta(newReferencePoint, referencePoint));
|
41036 | }
|
41037 |
|
41038 | |
41039 |
|
41040 |
|
41041 |
|
41042 |
|
41043 |
|
41044 |
|
41045 |
|
41046 |
|
41047 | function getReferencePoint(point, lines) {
|
41048 |
|
41049 | if (!lines.length) {
|
41050 | return;
|
41051 | }
|
41052 |
|
41053 | var nearestLine = getNearestLine(point, lines);
|
41054 |
|
41055 | return perpendicularFoot(point, nearestLine);
|
41056 | }
|
41057 |
|
41058 | |
41059 |
|
41060 |
|
41061 |
|
41062 |
|
41063 |
|
41064 |
|
41065 | function asEdges(bounds) {
|
41066 | return [
|
41067 | [
|
41068 | {
|
41069 | x: bounds.x,
|
41070 | y: bounds.y
|
41071 | },
|
41072 | {
|
41073 | x: bounds.x + (bounds.width || 0),
|
41074 | y: bounds.y
|
41075 | }
|
41076 | ],
|
41077 | [
|
41078 | {
|
41079 | x: bounds.x + (bounds.width || 0),
|
41080 | y: bounds.y
|
41081 | },
|
41082 | {
|
41083 | x: bounds.x + (bounds.width || 0),
|
41084 | y: bounds.y + (bounds.height || 0)
|
41085 | }
|
41086 | ],
|
41087 | [
|
41088 | {
|
41089 | x: bounds.x,
|
41090 | y: bounds.y + (bounds.height || 0)
|
41091 | },
|
41092 | {
|
41093 | x: bounds.x + (bounds.width || 0),
|
41094 | y: bounds.y + (bounds.height || 0)
|
41095 | }
|
41096 | ],
|
41097 | [
|
41098 | {
|
41099 | x: bounds.x,
|
41100 | y: bounds.y
|
41101 | },
|
41102 | {
|
41103 | x: bounds.x,
|
41104 | y: bounds.y + (bounds.height || 0)
|
41105 | }
|
41106 | ]
|
41107 | ];
|
41108 | }
|
41109 |
|
41110 | |
41111 |
|
41112 |
|
41113 |
|
41114 |
|
41115 |
|
41116 |
|
41117 | function getNearestLine(point, lines) {
|
41118 |
|
41119 | var distances = lines.map(function(l) {
|
41120 | return {
|
41121 | line: l,
|
41122 | distance: getDistancePointLine(point, l)
|
41123 | };
|
41124 | });
|
41125 |
|
41126 | var sorted = sortBy(distances, 'distance');
|
41127 |
|
41128 | return sorted[0].line;
|
41129 | }
|
41130 |
|
41131 | var COLLAB_ERR_MSG = 'flow elements must be children of pools/participants',
|
41132 | PROCESS_ERR_MSG = 'participants cannot be pasted onto a non-empty process diagram';
|
41133 |
|
41134 |
|
41135 | function ModelingFeedback(eventBus, tooltips, translate) {
|
41136 |
|
41137 | function showError(position, message, timeout) {
|
41138 | tooltips.add({
|
41139 | position: {
|
41140 | x: position.x + 5,
|
41141 | y: position.y + 5
|
41142 | },
|
41143 | type: 'error',
|
41144 | timeout: timeout || 2000,
|
41145 | html: '<div>' + message + '</div>'
|
41146 | });
|
41147 | }
|
41148 |
|
41149 | eventBus.on([ 'shape.move.rejected', 'create.rejected' ], function(event) {
|
41150 | var context = event.context,
|
41151 | shape = context.shape,
|
41152 | target = context.target;
|
41153 |
|
41154 | if (is$1(target, 'bpmn:Collaboration') && is$1(shape, 'bpmn:FlowNode')) {
|
41155 | showError(event, translate(COLLAB_ERR_MSG));
|
41156 | }
|
41157 | });
|
41158 |
|
41159 | eventBus.on([ 'elements.paste.rejected' ], function(event) {
|
41160 | var context = event.context,
|
41161 | position = context.position,
|
41162 | target = context.target;
|
41163 |
|
41164 | if (is$1(target, 'bpmn:Collaboration')) {
|
41165 | showError(position, translate(COLLAB_ERR_MSG));
|
41166 | }
|
41167 |
|
41168 | if (is$1(target, 'bpmn:Process')) {
|
41169 | showError(position, translate(PROCESS_ERR_MSG), 3000);
|
41170 | }
|
41171 | });
|
41172 | }
|
41173 |
|
41174 | ModelingFeedback.$inject = [
|
41175 | 'eventBus',
|
41176 | 'tooltips',
|
41177 | 'translate'
|
41178 | ];
|
41179 |
|
41180 | function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules, injector) {
|
41181 |
|
41182 | CommandInterceptor.call(this, eventBus);
|
41183 |
|
41184 | var dragging = injector.get('dragging', false);
|
41185 |
|
41186 | function fixConnection(connection) {
|
41187 |
|
41188 | var source = connection.source,
|
41189 | target = connection.target,
|
41190 | parent = connection.parent;
|
41191 |
|
41192 |
|
41193 |
|
41194 |
|
41195 | if (!parent) {
|
41196 | return;
|
41197 | }
|
41198 |
|
41199 | var replacementType,
|
41200 | remove;
|
41201 |
|
41202 | |
41203 |
|
41204 |
|
41205 |
|
41206 |
|
41207 |
|
41208 |
|
41209 |
|
41210 | if (is$1(connection, 'bpmn:SequenceFlow')) {
|
41211 | if (!bpmnRules.canConnectSequenceFlow(source, target)) {
|
41212 | remove = true;
|
41213 | }
|
41214 |
|
41215 | if (bpmnRules.canConnectMessageFlow(source, target)) {
|
41216 | replacementType = 'bpmn:MessageFlow';
|
41217 | }
|
41218 | }
|
41219 |
|
41220 |
|
41221 |
|
41222 | if (is$1(connection, 'bpmn:MessageFlow')) {
|
41223 |
|
41224 | if (!bpmnRules.canConnectMessageFlow(source, target)) {
|
41225 | remove = true;
|
41226 | }
|
41227 |
|
41228 | if (bpmnRules.canConnectSequenceFlow(source, target)) {
|
41229 | replacementType = 'bpmn:SequenceFlow';
|
41230 | }
|
41231 | }
|
41232 |
|
41233 | if (is$1(connection, 'bpmn:Association') && !bpmnRules.canConnectAssociation(source, target)) {
|
41234 | remove = true;
|
41235 | }
|
41236 |
|
41237 |
|
41238 |
|
41239 |
|
41240 | if (remove) {
|
41241 | modeling.removeConnection(connection);
|
41242 | }
|
41243 |
|
41244 |
|
41245 |
|
41246 | if (replacementType) {
|
41247 | modeling.connect(source, target, {
|
41248 | type: replacementType,
|
41249 | waypoints: connection.waypoints.slice()
|
41250 | });
|
41251 | }
|
41252 | }
|
41253 |
|
41254 | function replaceReconnectedConnection(event) {
|
41255 |
|
41256 | var context = event.context,
|
41257 | connection = context.connection,
|
41258 | source = context.newSource || connection.source,
|
41259 | target = context.newTarget || connection.target,
|
41260 | allowed,
|
41261 | replacement;
|
41262 |
|
41263 | allowed = bpmnRules.canConnect(source, target);
|
41264 |
|
41265 | if (!allowed || allowed.type === connection.type) {
|
41266 | return;
|
41267 | }
|
41268 |
|
41269 | replacement = modeling.connect(source, target, {
|
41270 | type: allowed.type,
|
41271 | waypoints: connection.waypoints.slice()
|
41272 | });
|
41273 |
|
41274 |
|
41275 | modeling.removeConnection(connection);
|
41276 |
|
41277 |
|
41278 | context.connection = replacement;
|
41279 |
|
41280 | if (dragging) {
|
41281 | cleanDraggingSelection(connection, replacement);
|
41282 | }
|
41283 | }
|
41284 |
|
41285 |
|
41286 | function cleanDraggingSelection(oldConnection, newConnection) {
|
41287 | var context = dragging.context(),
|
41288 | previousSelection = context && context.payload.previousSelection,
|
41289 | index;
|
41290 |
|
41291 |
|
41292 | if (!previousSelection || !previousSelection.length) {
|
41293 | return;
|
41294 | }
|
41295 |
|
41296 | index = previousSelection.indexOf(oldConnection);
|
41297 |
|
41298 | if (index === -1) {
|
41299 | return;
|
41300 | }
|
41301 |
|
41302 | previousSelection.splice(index, 1, newConnection);
|
41303 | }
|
41304 |
|
41305 |
|
41306 |
|
41307 | this.postExecuted('elements.move', function(context) {
|
41308 |
|
41309 | var closure = context.closure,
|
41310 | allConnections = closure.allConnections;
|
41311 |
|
41312 | forEach(allConnections, fixConnection);
|
41313 | }, true);
|
41314 |
|
41315 | this.preExecute([
|
41316 | 'connection.reconnectStart',
|
41317 | 'connection.reconnectEnd'
|
41318 | ], replaceReconnectedConnection);
|
41319 |
|
41320 | this.postExecuted('element.updateProperties', function(event) {
|
41321 | var context = event.context,
|
41322 | properties = context.properties,
|
41323 | element = context.element,
|
41324 | businessObject = element.businessObject,
|
41325 | connection;
|
41326 |
|
41327 |
|
41328 | if (properties.default) {
|
41329 | connection = find(
|
41330 | element.outgoing,
|
41331 | matchPattern({ id: element.businessObject.default.id })
|
41332 | );
|
41333 |
|
41334 | if (connection) {
|
41335 | modeling.updateProperties(connection, { conditionExpression: undefined });
|
41336 | }
|
41337 | }
|
41338 |
|
41339 |
|
41340 | if (properties.conditionExpression && businessObject.sourceRef.default === businessObject) {
|
41341 | modeling.updateProperties(element.source, { default: undefined });
|
41342 | }
|
41343 | });
|
41344 | }
|
41345 |
|
41346 | inherits_browser(ReplaceConnectionBehavior, CommandInterceptor);
|
41347 |
|
41348 | ReplaceConnectionBehavior.$inject = [
|
41349 | 'eventBus',
|
41350 | 'modeling',
|
41351 | 'bpmnRules',
|
41352 | 'injector'
|
41353 | ];
|
41354 |
|
41355 | |
41356 |
|
41357 |
|
41358 | function RemoveParticipantBehavior(eventBus, modeling) {
|
41359 |
|
41360 | CommandInterceptor.call(this, eventBus);
|
41361 |
|
41362 |
|
41363 | |
41364 |
|
41365 |
|
41366 |
|
41367 |
|
41368 | this.preExecute('shape.delete', function(context) {
|
41369 |
|
41370 | var shape = context.shape,
|
41371 | parent = shape.parent;
|
41372 |
|
41373 |
|
41374 |
|
41375 | if (is$1(shape, 'bpmn:Participant')) {
|
41376 | context.collaborationRoot = parent;
|
41377 | }
|
41378 | }, true);
|
41379 |
|
41380 | this.postExecute('shape.delete', function(context) {
|
41381 |
|
41382 | var collaborationRoot = context.collaborationRoot;
|
41383 |
|
41384 | if (collaborationRoot && !collaborationRoot.businessObject.participants.length) {
|
41385 |
|
41386 |
|
41387 | modeling.makeProcess();
|
41388 | }
|
41389 | }, true);
|
41390 |
|
41391 | }
|
41392 |
|
41393 | RemoveParticipantBehavior.$inject = [ 'eventBus', 'modeling' ];
|
41394 |
|
41395 | inherits_browser(RemoveParticipantBehavior, CommandInterceptor);
|
41396 |
|
41397 | |
41398 |
|
41399 |
|
41400 |
|
41401 | function ReplaceElementBehaviour(
|
41402 | eventBus, bpmnReplace, bpmnRules,
|
41403 | elementRegistry, selection, modeling) {
|
41404 |
|
41405 | CommandInterceptor.call(this, eventBus);
|
41406 |
|
41407 | this._bpmnReplace = bpmnReplace;
|
41408 | this._elementRegistry = elementRegistry;
|
41409 | this._selection = selection;
|
41410 | this._modeling = modeling;
|
41411 |
|
41412 | this.postExecuted([ 'elements.move' ], 500, function(event) {
|
41413 |
|
41414 | var context = event.context,
|
41415 | target = context.newParent,
|
41416 | newHost = context.newHost,
|
41417 | elements = [];
|
41418 |
|
41419 | forEach(context.closure.topLevel, function(topLevelElements) {
|
41420 | if (isEventSubProcess(topLevelElements)) {
|
41421 | elements = elements.concat(topLevelElements.children);
|
41422 | } else {
|
41423 | elements = elements.concat(topLevelElements);
|
41424 | }
|
41425 | });
|
41426 |
|
41427 |
|
41428 | if (elements.length === 1 && newHost) {
|
41429 | target = newHost;
|
41430 | }
|
41431 |
|
41432 | var canReplace = bpmnRules.canReplace(elements, target);
|
41433 |
|
41434 | if (canReplace) {
|
41435 | this.replaceElements(elements, canReplace.replacements, newHost);
|
41436 | }
|
41437 | }, this);
|
41438 |
|
41439 |
|
41440 | this.postExecute([ 'shape.replace' ], 1500, function(e) {
|
41441 |
|
41442 | var context = e.context,
|
41443 | oldShape = context.oldShape,
|
41444 | newShape = context.newShape,
|
41445 | attachers = oldShape.attachers,
|
41446 | canReplace;
|
41447 |
|
41448 | if (attachers && attachers.length) {
|
41449 | canReplace = bpmnRules.canReplace(attachers, newShape);
|
41450 |
|
41451 | this.replaceElements(attachers, canReplace.replacements);
|
41452 | }
|
41453 |
|
41454 | }, this);
|
41455 |
|
41456 | this.postExecuted([ 'shape.replace' ], 1500, function(e) {
|
41457 | var context = e.context,
|
41458 | oldShape = context.oldShape,
|
41459 | newShape = context.newShape;
|
41460 |
|
41461 | modeling.unclaimId(oldShape.businessObject.id, oldShape.businessObject);
|
41462 | modeling.updateProperties(newShape, { id: oldShape.id });
|
41463 | });
|
41464 | }
|
41465 |
|
41466 | inherits_browser(ReplaceElementBehaviour, CommandInterceptor);
|
41467 |
|
41468 |
|
41469 | ReplaceElementBehaviour.prototype.replaceElements = function(elements, newElements, newHost) {
|
41470 | var elementRegistry = this._elementRegistry,
|
41471 | bpmnReplace = this._bpmnReplace,
|
41472 | selection = this._selection,
|
41473 | modeling = this._modeling;
|
41474 |
|
41475 | forEach(newElements, function(replacement) {
|
41476 |
|
41477 | var newElement = {
|
41478 | type: replacement.newElementType
|
41479 | };
|
41480 |
|
41481 | var oldElement = elementRegistry.get(replacement.oldElementId);
|
41482 |
|
41483 | if (newHost && is$1(oldElement, 'bpmn:BoundaryEvent')) {
|
41484 | modeling.updateAttachment(oldElement, null);
|
41485 | }
|
41486 |
|
41487 | var idx = elements.indexOf(oldElement);
|
41488 |
|
41489 | elements[idx] = bpmnReplace.replaceElement(oldElement, newElement, { select: false });
|
41490 |
|
41491 | if (newHost && is$1(elements[idx], 'bpmn:BoundaryEvent')) {
|
41492 | modeling.updateAttachment(elements[idx], newHost);
|
41493 | }
|
41494 | });
|
41495 |
|
41496 | if (newElements) {
|
41497 | selection.select(elements);
|
41498 | }
|
41499 | };
|
41500 |
|
41501 | ReplaceElementBehaviour.$inject = [
|
41502 | 'eventBus',
|
41503 | 'bpmnReplace',
|
41504 | 'bpmnRules',
|
41505 | 'elementRegistry',
|
41506 | 'selection',
|
41507 | 'modeling'
|
41508 | ];
|
41509 |
|
41510 | var abs$5 = Math.abs,
|
41511 | min$3 = Math.min,
|
41512 | max$4 = Math.max;
|
41513 |
|
41514 |
|
41515 | function addToTrbl(trbl, attr, value, choice) {
|
41516 | var current = trbl[attr];
|
41517 |
|
41518 |
|
41519 |
|
41520 |
|
41521 | trbl[attr] = current === undefined ? value : choice(value, current);
|
41522 | }
|
41523 |
|
41524 | function addMin(trbl, attr, value) {
|
41525 | return addToTrbl(trbl, attr, value, min$3);
|
41526 | }
|
41527 |
|
41528 | function addMax(trbl, attr, value) {
|
41529 | return addToTrbl(trbl, attr, value, max$4);
|
41530 | }
|
41531 |
|
41532 | var LANE_MIN_HEIGHT = 60,
|
41533 | LANE_MIN_WIDTH = 300,
|
41534 | LANE_RIGHT_PADDING = 20,
|
41535 | LANE_LEFT_PADDING = 50,
|
41536 | LANE_TOP_PADDING = 20,
|
41537 | LANE_BOTTOM_PADDING = 20;
|
41538 |
|
41539 |
|
41540 | function getParticipantResizeConstraints(laneShape, resizeDirection, balanced) {
|
41541 | var lanesRoot = getLanesRoot(laneShape);
|
41542 |
|
41543 | var isFirst = true,
|
41544 | isLast = true;
|
41545 |
|
41546 |
|
41547 | var allLanes = collectLanes(lanesRoot, [ lanesRoot ]);
|
41548 |
|
41549 | var laneTrbl = asTRBL(laneShape);
|
41550 |
|
41551 | var maxTrbl = {},
|
41552 | minTrbl = {};
|
41553 |
|
41554 | if (/e/.test(resizeDirection)) {
|
41555 | minTrbl.right = laneTrbl.left + LANE_MIN_WIDTH;
|
41556 | } else
|
41557 | if (/w/.test(resizeDirection)) {
|
41558 | minTrbl.left = laneTrbl.right - LANE_MIN_WIDTH;
|
41559 | }
|
41560 |
|
41561 | allLanes.forEach(function(other) {
|
41562 |
|
41563 | var otherTrbl = asTRBL(other);
|
41564 |
|
41565 | if (/n/.test(resizeDirection)) {
|
41566 |
|
41567 | if (otherTrbl.top < (laneTrbl.top - 10)) {
|
41568 | isFirst = false;
|
41569 | }
|
41570 |
|
41571 |
|
41572 | if (balanced && abs$5(laneTrbl.top - otherTrbl.bottom) < 10) {
|
41573 | addMax(maxTrbl, 'top', otherTrbl.top + LANE_MIN_HEIGHT);
|
41574 | }
|
41575 |
|
41576 |
|
41577 | if (abs$5(laneTrbl.top - otherTrbl.top) < 5) {
|
41578 | addMin(minTrbl, 'top', otherTrbl.bottom - LANE_MIN_HEIGHT);
|
41579 | }
|
41580 | }
|
41581 |
|
41582 | if (/s/.test(resizeDirection)) {
|
41583 |
|
41584 | if (otherTrbl.bottom > (laneTrbl.bottom + 10)) {
|
41585 | isLast = false;
|
41586 | }
|
41587 |
|
41588 |
|
41589 | if (balanced && abs$5(laneTrbl.bottom - otherTrbl.top) < 10) {
|
41590 | addMin(maxTrbl, 'bottom', otherTrbl.bottom - LANE_MIN_HEIGHT);
|
41591 | }
|
41592 |
|
41593 |
|
41594 | if (abs$5(laneTrbl.bottom - otherTrbl.bottom) < 5) {
|
41595 | addMax(minTrbl, 'bottom', otherTrbl.top + LANE_MIN_HEIGHT);
|
41596 | }
|
41597 | }
|
41598 | });
|
41599 |
|
41600 |
|
41601 | var flowElements = lanesRoot.children.filter(function(s) {
|
41602 | return !s.hidden && !s.waypoints && (is$1(s, 'bpmn:FlowElement') || is$1(s, 'bpmn:Artifact'));
|
41603 | });
|
41604 |
|
41605 | flowElements.forEach(function(flowElement) {
|
41606 |
|
41607 | var flowElementTrbl = asTRBL(flowElement);
|
41608 |
|
41609 | if (isFirst && /n/.test(resizeDirection)) {
|
41610 | addMin(minTrbl, 'top', flowElementTrbl.top - LANE_TOP_PADDING);
|
41611 | }
|
41612 |
|
41613 | if (/e/.test(resizeDirection)) {
|
41614 | addMax(minTrbl, 'right', flowElementTrbl.right + LANE_RIGHT_PADDING);
|
41615 | }
|
41616 |
|
41617 | if (isLast && /s/.test(resizeDirection)) {
|
41618 | addMax(minTrbl, 'bottom', flowElementTrbl.bottom + LANE_BOTTOM_PADDING);
|
41619 | }
|
41620 |
|
41621 | if (/w/.test(resizeDirection)) {
|
41622 | addMin(minTrbl, 'left', flowElementTrbl.left - LANE_LEFT_PADDING);
|
41623 | }
|
41624 | });
|
41625 |
|
41626 | return {
|
41627 | min: minTrbl,
|
41628 | max: maxTrbl
|
41629 | };
|
41630 | }
|
41631 |
|
41632 | var HIGH_PRIORITY$8 = 1500;
|
41633 |
|
41634 | var PARTICIPANT_MIN_DIMENSIONS = { width: 300, height: 150 },
|
41635 | SUB_PROCESS_MIN_DIMENSIONS = { width: 140, height: 120 },
|
41636 | TEXT_ANNOTATION_MIN_DIMENSIONS = { width: 50, height: 30 };
|
41637 |
|
41638 |
|
41639 | |
41640 |
|
41641 |
|
41642 |
|
41643 |
|
41644 | function ResizeBehavior$1(eventBus) {
|
41645 | eventBus.on('resize.start', HIGH_PRIORITY$8, function(event) {
|
41646 | var context = event.context,
|
41647 | shape = context.shape,
|
41648 | direction = context.direction,
|
41649 | balanced = context.balanced;
|
41650 |
|
41651 | if (is$1(shape, 'bpmn:Lane') || is$1(shape, 'bpmn:Participant')) {
|
41652 | context.resizeConstraints = getParticipantResizeConstraints(shape, direction, balanced);
|
41653 | }
|
41654 |
|
41655 | if (is$1(shape, 'bpmn:Participant')) {
|
41656 | context.minDimensions = PARTICIPANT_MIN_DIMENSIONS;
|
41657 | }
|
41658 |
|
41659 | if (is$1(shape, 'bpmn:SubProcess') && isExpanded(shape)) {
|
41660 | context.minDimensions = SUB_PROCESS_MIN_DIMENSIONS;
|
41661 | }
|
41662 |
|
41663 | if (is$1(shape, 'bpmn:TextAnnotation')) {
|
41664 | context.minDimensions = TEXT_ANNOTATION_MIN_DIMENSIONS;
|
41665 | }
|
41666 | });
|
41667 | }
|
41668 |
|
41669 | ResizeBehavior$1.$inject = [ 'eventBus' ];
|
41670 |
|
41671 | var SLIGHTLY_HIGHER_PRIORITY = 1001;
|
41672 |
|
41673 |
|
41674 | |
41675 |
|
41676 |
|
41677 |
|
41678 |
|
41679 | function ResizeLaneBehavior(eventBus, modeling) {
|
41680 |
|
41681 | eventBus.on('resize.start', SLIGHTLY_HIGHER_PRIORITY + 500, function(event) {
|
41682 | var context = event.context,
|
41683 | shape = context.shape;
|
41684 |
|
41685 | if (is$1(shape, 'bpmn:Lane') || is$1(shape, 'bpmn:Participant')) {
|
41686 |
|
41687 |
|
41688 |
|
41689 | context.balanced = !hasPrimaryModifier(event);
|
41690 | }
|
41691 | });
|
41692 |
|
41693 | |
41694 |
|
41695 |
|
41696 | eventBus.on('resize.end', SLIGHTLY_HIGHER_PRIORITY, function(event) {
|
41697 | var context = event.context,
|
41698 | shape = context.shape,
|
41699 | canExecute = context.canExecute,
|
41700 | newBounds = context.newBounds;
|
41701 |
|
41702 | if (is$1(shape, 'bpmn:Lane') || is$1(shape, 'bpmn:Participant')) {
|
41703 |
|
41704 | if (canExecute) {
|
41705 |
|
41706 |
|
41707 |
|
41708 | newBounds = roundBounds(newBounds);
|
41709 |
|
41710 |
|
41711 | modeling.resizeLane(shape, newBounds, context.balanced);
|
41712 | }
|
41713 |
|
41714 |
|
41715 | return false;
|
41716 | }
|
41717 | });
|
41718 | }
|
41719 |
|
41720 | ResizeLaneBehavior.$inject = [
|
41721 | 'eventBus',
|
41722 | 'modeling'
|
41723 | ];
|
41724 |
|
41725 | function RemoveElementBehavior(eventBus, bpmnRules, modeling) {
|
41726 |
|
41727 | CommandInterceptor.call(this, eventBus);
|
41728 |
|
41729 | |
41730 |
|
41731 |
|
41732 |
|
41733 |
|
41734 | this.preExecute('shape.delete', function(e) {
|
41735 |
|
41736 | var shape = e.context.shape;
|
41737 |
|
41738 |
|
41739 | if (shape.incoming.length !== 1 || shape.outgoing.length !== 1) {
|
41740 | return;
|
41741 | }
|
41742 |
|
41743 | var inConnection = shape.incoming[0],
|
41744 | outConnection = shape.outgoing[0];
|
41745 |
|
41746 |
|
41747 | if (!is$1(inConnection, 'bpmn:SequenceFlow') || !is$1(outConnection, 'bpmn:SequenceFlow')) {
|
41748 | return;
|
41749 | }
|
41750 |
|
41751 | if (bpmnRules.canConnect(inConnection.source, outConnection.target, inConnection)) {
|
41752 |
|
41753 |
|
41754 | var newWaypoints = getNewWaypoints(inConnection.waypoints, outConnection.waypoints);
|
41755 |
|
41756 | modeling.reconnectEnd(inConnection, outConnection.target, newWaypoints);
|
41757 | }
|
41758 | });
|
41759 |
|
41760 | }
|
41761 |
|
41762 | inherits_browser(RemoveElementBehavior, CommandInterceptor);
|
41763 |
|
41764 | RemoveElementBehavior.$inject = [
|
41765 | 'eventBus',
|
41766 | 'bpmnRules',
|
41767 | 'modeling'
|
41768 | ];
|
41769 |
|
41770 |
|
41771 |
|
41772 |
|
41773 | function getDocking$1(point) {
|
41774 | return point.original || point;
|
41775 | }
|
41776 |
|
41777 |
|
41778 | function getNewWaypoints(inWaypoints, outWaypoints) {
|
41779 |
|
41780 | var intersection = lineIntersect(
|
41781 | getDocking$1(inWaypoints[inWaypoints.length - 2]),
|
41782 | getDocking$1(inWaypoints[inWaypoints.length - 1]),
|
41783 | getDocking$1(outWaypoints[1]),
|
41784 | getDocking$1(outWaypoints[0]));
|
41785 |
|
41786 | if (intersection) {
|
41787 | return [].concat(
|
41788 | inWaypoints.slice(0, inWaypoints.length - 1),
|
41789 | [ intersection ],
|
41790 | outWaypoints.slice(1));
|
41791 | } else {
|
41792 | return [
|
41793 | getDocking$1(inWaypoints[0]),
|
41794 | getDocking$1(outWaypoints[outWaypoints.length - 1])
|
41795 | ];
|
41796 | }
|
41797 | }
|
41798 |
|
41799 | |
41800 |
|
41801 |
|
41802 |
|
41803 |
|
41804 |
|
41805 | function SubProcessStartEventBehavior(injector, modeling) {
|
41806 | injector.invoke(CommandInterceptor, this);
|
41807 |
|
41808 | this.postExecuted('shape.replace', function(event) {
|
41809 | var oldShape = event.context.oldShape,
|
41810 | newShape = event.context.newShape;
|
41811 |
|
41812 | if (
|
41813 | !is$1(newShape, 'bpmn:SubProcess') ||
|
41814 | !is$1(oldShape, 'bpmn:Task') ||
|
41815 | !isExpanded(newShape)
|
41816 | ) {
|
41817 | return;
|
41818 | }
|
41819 |
|
41820 | var position = getStartEventPosition(newShape);
|
41821 |
|
41822 | modeling.createShape({ type: 'bpmn:StartEvent' }, position, newShape);
|
41823 | });
|
41824 | }
|
41825 |
|
41826 | SubProcessStartEventBehavior.$inject = [
|
41827 | 'injector',
|
41828 | 'modeling'
|
41829 | ];
|
41830 |
|
41831 | inherits_browser(SubProcessStartEventBehavior, CommandInterceptor);
|
41832 |
|
41833 |
|
41834 |
|
41835 | function getStartEventPosition(shape) {
|
41836 | return {
|
41837 | x: shape.x + shape.width / 6,
|
41838 | y: shape.y + shape.height / 2
|
41839 | };
|
41840 | }
|
41841 |
|
41842 | var LOW_PRIORITY$a = 500;
|
41843 |
|
41844 |
|
41845 | function ToggleElementCollapseBehaviour(
|
41846 | eventBus, elementFactory, modeling,
|
41847 | resize) {
|
41848 |
|
41849 | CommandInterceptor.call(this, eventBus);
|
41850 |
|
41851 |
|
41852 | function hideEmptyLables(children) {
|
41853 | if (children.length) {
|
41854 | children.forEach(function(child) {
|
41855 | if (child.type === 'label' && !child.businessObject.name) {
|
41856 | child.hidden = true;
|
41857 | }
|
41858 | });
|
41859 | }
|
41860 | }
|
41861 |
|
41862 | function expandedBounds(shape, defaultSize) {
|
41863 | var children = shape.children,
|
41864 | newBounds = defaultSize,
|
41865 | visibleElements,
|
41866 | visibleBBox;
|
41867 |
|
41868 | visibleElements = filterVisible(children).concat([ shape ]);
|
41869 |
|
41870 | visibleBBox = computeChildrenBBox(visibleElements);
|
41871 |
|
41872 | if (visibleBBox) {
|
41873 |
|
41874 |
|
41875 | newBounds.width = Math.max(visibleBBox.width, newBounds.width);
|
41876 | newBounds.height = Math.max(visibleBBox.height, newBounds.height);
|
41877 |
|
41878 | newBounds.x = visibleBBox.x + (visibleBBox.width - newBounds.width) / 2;
|
41879 | newBounds.y = visibleBBox.y + (visibleBBox.height - newBounds.height) / 2;
|
41880 | } else {
|
41881 |
|
41882 |
|
41883 | newBounds.x = shape.x + (shape.width - newBounds.width) / 2;
|
41884 | newBounds.y = shape.y + (shape.height - newBounds.height) / 2;
|
41885 | }
|
41886 |
|
41887 | return newBounds;
|
41888 | }
|
41889 |
|
41890 | function collapsedBounds(shape, defaultSize) {
|
41891 |
|
41892 | return {
|
41893 | x: shape.x + (shape.width - defaultSize.width) / 2,
|
41894 | y: shape.y + (shape.height - defaultSize.height) / 2,
|
41895 | width: defaultSize.width,
|
41896 | height: defaultSize.height
|
41897 | };
|
41898 | }
|
41899 |
|
41900 | this.executed([ 'shape.toggleCollapse' ], LOW_PRIORITY$a, function(e) {
|
41901 |
|
41902 | var context = e.context,
|
41903 | shape = context.shape;
|
41904 |
|
41905 | if (!is$1(shape, 'bpmn:SubProcess')) {
|
41906 | return;
|
41907 | }
|
41908 |
|
41909 | if (!shape.collapsed) {
|
41910 |
|
41911 |
|
41912 | hideEmptyLables(shape.children);
|
41913 |
|
41914 |
|
41915 | getBusinessObject(shape).di.isExpanded = true;
|
41916 | } else {
|
41917 |
|
41918 |
|
41919 | getBusinessObject(shape).di.isExpanded = false;
|
41920 | }
|
41921 | });
|
41922 |
|
41923 | this.reverted([ 'shape.toggleCollapse' ], LOW_PRIORITY$a, function(e) {
|
41924 |
|
41925 | var context = e.context;
|
41926 | var shape = context.shape;
|
41927 |
|
41928 |
|
41929 |
|
41930 | if (!shape.collapsed) {
|
41931 | getBusinessObject(shape).di.isExpanded = true;
|
41932 |
|
41933 | } else {
|
41934 | getBusinessObject(shape).di.isExpanded = false;
|
41935 | }
|
41936 | });
|
41937 |
|
41938 | this.postExecuted([ 'shape.toggleCollapse' ], LOW_PRIORITY$a, function(e) {
|
41939 | var shape = e.context.shape,
|
41940 | defaultSize = elementFactory._getDefaultSize(shape),
|
41941 | newBounds;
|
41942 |
|
41943 | if (shape.collapsed) {
|
41944 |
|
41945 |
|
41946 | newBounds = collapsedBounds(shape, defaultSize);
|
41947 | } else {
|
41948 |
|
41949 |
|
41950 | newBounds = expandedBounds(shape, defaultSize);
|
41951 | }
|
41952 |
|
41953 | modeling.resizeShape(shape, newBounds, null, {
|
41954 | autoResize: shape.collapsed ? false : 'nwse'
|
41955 | });
|
41956 | });
|
41957 |
|
41958 | }
|
41959 |
|
41960 |
|
41961 | inherits_browser(ToggleElementCollapseBehaviour, CommandInterceptor);
|
41962 |
|
41963 | ToggleElementCollapseBehaviour.$inject = [
|
41964 | 'eventBus',
|
41965 | 'elementFactory',
|
41966 | 'modeling'
|
41967 | ];
|
41968 |
|
41969 |
|
41970 |
|
41971 |
|
41972 | function filterVisible(elements) {
|
41973 | return elements.filter(function(e) {
|
41974 | return !e.hidden;
|
41975 | });
|
41976 | }
|
41977 |
|
41978 | |
41979 |
|
41980 |
|
41981 |
|
41982 |
|
41983 |
|
41984 | function UnclaimIdBehavior(eventBus, modeling) {
|
41985 |
|
41986 | CommandInterceptor.call(this, eventBus);
|
41987 |
|
41988 | this.preExecute('elements.delete', function(event) {
|
41989 | var context = event.context,
|
41990 | elements = context.elements;
|
41991 |
|
41992 | forEach(elements, function(element) {
|
41993 | modeling.unclaimId(element.businessObject.id, element.businessObject);
|
41994 | });
|
41995 |
|
41996 | });
|
41997 | }
|
41998 |
|
41999 | inherits_browser(UnclaimIdBehavior, CommandInterceptor);
|
42000 |
|
42001 | UnclaimIdBehavior.$inject = [ 'eventBus', 'modeling' ];
|
42002 |
|
42003 | var LOW_PRIORITY$b = 500,
|
42004 | HIGH_PRIORITY$9 = 5000;
|
42005 |
|
42006 |
|
42007 | |
42008 |
|
42009 |
|
42010 | function UpdateFlowNodeRefsBehavior(eventBus, modeling, translate) {
|
42011 |
|
42012 | CommandInterceptor.call(this, eventBus);
|
42013 |
|
42014 | |
42015 |
|
42016 |
|
42017 |
|
42018 |
|
42019 |
|
42020 |
|
42021 |
|
42022 |
|
42023 |
|
42024 |
|
42025 |
|
42026 |
|
42027 |
|
42028 | var context;
|
42029 |
|
42030 |
|
42031 | function initContext() {
|
42032 | context = context || new UpdateContext();
|
42033 | context.enter();
|
42034 |
|
42035 | return context;
|
42036 | }
|
42037 |
|
42038 | function getContext() {
|
42039 | if (!context) {
|
42040 | throw new Error(translate('out of bounds release'));
|
42041 | }
|
42042 |
|
42043 | return context;
|
42044 | }
|
42045 |
|
42046 | function releaseContext() {
|
42047 |
|
42048 | if (!context) {
|
42049 | throw new Error(translate('out of bounds release'));
|
42050 | }
|
42051 |
|
42052 | var triggerUpdate = context.leave();
|
42053 |
|
42054 | if (triggerUpdate) {
|
42055 | modeling.updateLaneRefs(context.flowNodes, context.lanes);
|
42056 |
|
42057 | context = null;
|
42058 | }
|
42059 |
|
42060 | return triggerUpdate;
|
42061 | }
|
42062 |
|
42063 |
|
42064 | var laneRefUpdateEvents = [
|
42065 | 'spaceTool',
|
42066 | 'lane.add',
|
42067 | 'lane.resize',
|
42068 | 'lane.split',
|
42069 | 'elements.move',
|
42070 | 'elements.delete',
|
42071 | 'shape.create',
|
42072 | 'shape.delete',
|
42073 | 'shape.move',
|
42074 | 'shape.resize'
|
42075 | ];
|
42076 |
|
42077 |
|
42078 |
|
42079 |
|
42080 | this.preExecute(laneRefUpdateEvents, HIGH_PRIORITY$9, function(event) {
|
42081 | initContext();
|
42082 | });
|
42083 |
|
42084 | this.postExecuted(laneRefUpdateEvents, LOW_PRIORITY$b, function(event) {
|
42085 | releaseContext();
|
42086 | });
|
42087 |
|
42088 |
|
42089 |
|
42090 |
|
42091 | this.preExecute([
|
42092 | 'shape.create',
|
42093 | 'shape.move',
|
42094 | 'shape.delete',
|
42095 | 'shape.resize'
|
42096 | ], function(event) {
|
42097 |
|
42098 | var context = event.context,
|
42099 | shape = context.shape;
|
42100 |
|
42101 | var updateContext = getContext();
|
42102 |
|
42103 |
|
42104 | if (shape.labelTarget) {
|
42105 | return;
|
42106 | }
|
42107 |
|
42108 | if (is$1(shape, 'bpmn:Lane')) {
|
42109 | updateContext.addLane(shape);
|
42110 | }
|
42111 |
|
42112 | if (is$1(shape, 'bpmn:FlowNode')) {
|
42113 | updateContext.addFlowNode(shape);
|
42114 | }
|
42115 | });
|
42116 | }
|
42117 |
|
42118 | UpdateFlowNodeRefsBehavior.$inject = [
|
42119 | 'eventBus',
|
42120 | 'modeling' ,
|
42121 | 'translate'
|
42122 | ];
|
42123 |
|
42124 | inherits_browser(UpdateFlowNodeRefsBehavior, CommandInterceptor);
|
42125 |
|
42126 |
|
42127 | function UpdateContext() {
|
42128 |
|
42129 | this.flowNodes = [];
|
42130 | this.lanes = [];
|
42131 |
|
42132 | this.counter = 0;
|
42133 |
|
42134 | this.addLane = function(lane) {
|
42135 | this.lanes.push(lane);
|
42136 | };
|
42137 |
|
42138 | this.addFlowNode = function(flowNode) {
|
42139 | this.flowNodes.push(flowNode);
|
42140 | };
|
42141 |
|
42142 | this.enter = function() {
|
42143 | this.counter++;
|
42144 | };
|
42145 |
|
42146 | this.leave = function() {
|
42147 | this.counter--;
|
42148 |
|
42149 | return !this.counter;
|
42150 | };
|
42151 | }
|
42152 |
|
42153 | |
42154 |
|
42155 |
|
42156 |
|
42157 |
|
42158 |
|
42159 |
|
42160 |
|
42161 | function DeleteSequenceFlowBehavior(eventBus, modeling) {
|
42162 |
|
42163 | CommandInterceptor.call(this, eventBus);
|
42164 |
|
42165 |
|
42166 | this.preExecute('connection.delete', function(event) {
|
42167 | var context = event.context,
|
42168 | connection = context.connection,
|
42169 | source = connection.source;
|
42170 |
|
42171 | if (isDefaultFlow(connection, source)) {
|
42172 | modeling.updateProperties(source, {
|
42173 | 'default': null
|
42174 | });
|
42175 | }
|
42176 | });
|
42177 | }
|
42178 |
|
42179 | inherits_browser(DeleteSequenceFlowBehavior, CommandInterceptor);
|
42180 |
|
42181 | DeleteSequenceFlowBehavior.$inject = [
|
42182 | 'eventBus',
|
42183 | 'modeling'
|
42184 | ];
|
42185 |
|
42186 |
|
42187 |
|
42188 |
|
42189 | function isDefaultFlow(connection, source) {
|
42190 |
|
42191 | if (!is$1(connection, 'bpmn:SequenceFlow')) {
|
42192 | return false;
|
42193 | }
|
42194 |
|
42195 | var sourceBo = getBusinessObject(source),
|
42196 | sequenceFlow = getBusinessObject(connection);
|
42197 |
|
42198 | return sourceBo.get('default') === sequenceFlow;
|
42199 | }
|
42200 |
|
42201 | var BehaviorModule = {
|
42202 | __init__: [
|
42203 | 'adaptiveLabelPositioningBehavior',
|
42204 | 'appendBehavior',
|
42205 | 'attachEventBehavior',
|
42206 | 'boundaryEventBehavior',
|
42207 | 'createBehavior',
|
42208 | 'fixHoverBehavior',
|
42209 | 'createBoundaryEventBehavior',
|
42210 | 'createDataObjectBehavior',
|
42211 | 'createParticipantBehavior',
|
42212 | 'dataStoreBehavior',
|
42213 | 'dataInputAssociationBehavior',
|
42214 | 'deleteLaneBehavior',
|
42215 | 'detachEventBehavior',
|
42216 | 'dropOnFlowBehavior',
|
42217 | 'eventBasedGatewayBehavior',
|
42218 | 'groupBehavior',
|
42219 | 'importDockingFix',
|
42220 | 'isHorizontalFix',
|
42221 | 'labelBehavior',
|
42222 | 'modelingFeedback',
|
42223 | 'removeElementBehavior',
|
42224 | 'removeParticipantBehavior',
|
42225 | 'replaceConnectionBehavior',
|
42226 | 'replaceElementBehaviour',
|
42227 | 'resizeBehavior',
|
42228 | 'resizeLaneBehavior',
|
42229 | 'toggleElementCollapseBehaviour',
|
42230 | 'subProcessStartEventBehavior',
|
42231 | 'unclaimIdBehavior',
|
42232 | 'unsetDefaultFlowBehavior',
|
42233 | 'updateFlowNodeRefsBehavior'
|
42234 | ],
|
42235 | adaptiveLabelPositioningBehavior: [ 'type', AdaptiveLabelPositioningBehavior ],
|
42236 | appendBehavior: [ 'type', AppendBehavior ],
|
42237 | attachEventBehavior: [ 'type', AttachEventBehavior ],
|
42238 | boundaryEventBehavior: [ 'type', BoundaryEventBehavior ],
|
42239 | createBehavior: [ 'type', CreateBehavior ],
|
42240 | fixHoverBehavior: [ 'type', FixHoverBehavior ],
|
42241 | createBoundaryEventBehavior: [ 'type', CreateBoundaryEventBehavior ],
|
42242 | createDataObjectBehavior: [ 'type', CreateDataObjectBehavior ],
|
42243 | createParticipantBehavior: [ 'type', CreateParticipantBehavior$1 ],
|
42244 | dataInputAssociationBehavior: [ 'type', DataInputAssociationBehavior ],
|
42245 | dataStoreBehavior: [ 'type', DataStoreBehavior ],
|
42246 | deleteLaneBehavior: [ 'type', DeleteLaneBehavior ],
|
42247 | detachEventBehavior: [ 'type', DetachEventBehavior ],
|
42248 | dropOnFlowBehavior: [ 'type', DropOnFlowBehavior ],
|
42249 | eventBasedGatewayBehavior: [ 'type', EventBasedGatewayBehavior ],
|
42250 | groupBehavior: [ 'type', GroupBehavior ],
|
42251 | importDockingFix: [ 'type', ImportDockingFix ],
|
42252 | isHorizontalFix: [ 'type', IsHorizontalFix ],
|
42253 | labelBehavior: [ 'type', LabelBehavior ],
|
42254 | modelingFeedback: [ 'type', ModelingFeedback ],
|
42255 | replaceConnectionBehavior: [ 'type', ReplaceConnectionBehavior ],
|
42256 | removeParticipantBehavior: [ 'type', RemoveParticipantBehavior ],
|
42257 | replaceElementBehaviour: [ 'type', ReplaceElementBehaviour ],
|
42258 | resizeBehavior: [ 'type', ResizeBehavior$1 ],
|
42259 | resizeLaneBehavior: [ 'type', ResizeLaneBehavior ],
|
42260 | removeElementBehavior: [ 'type', RemoveElementBehavior ],
|
42261 | toggleElementCollapseBehaviour : [ 'type', ToggleElementCollapseBehaviour ],
|
42262 | subProcessStartEventBehavior: [ 'type', SubProcessStartEventBehavior ],
|
42263 | unclaimIdBehavior: [ 'type', UnclaimIdBehavior ],
|
42264 | updateFlowNodeRefsBehavior: [ 'type', UpdateFlowNodeRefsBehavior ],
|
42265 | unsetDefaultFlowBehavior: [ 'type', DeleteSequenceFlowBehavior ]
|
42266 | };
|
42267 |
|
42268 | function getBoundaryAttachment(position, targetBounds) {
|
42269 |
|
42270 | var orientation = getOrientation(position, targetBounds, -15);
|
42271 |
|
42272 | if (orientation !== 'intersect') {
|
42273 | return orientation;
|
42274 | } else {
|
42275 | return null;
|
42276 | }
|
42277 | }
|
42278 |
|
42279 | |
42280 |
|
42281 |
|
42282 | function BpmnRules(eventBus) {
|
42283 | RuleProvider.call(this, eventBus);
|
42284 | }
|
42285 |
|
42286 | inherits_browser(BpmnRules, RuleProvider);
|
42287 |
|
42288 | BpmnRules.$inject = [ 'eventBus' ];
|
42289 |
|
42290 | BpmnRules.prototype.init = function() {
|
42291 |
|
42292 | this.addRule('connection.start', function(context) {
|
42293 | var source = context.source;
|
42294 |
|
42295 | return canStartConnection(source);
|
42296 | });
|
42297 |
|
42298 | this.addRule('connection.create', function(context) {
|
42299 | var source = context.source,
|
42300 | target = context.target,
|
42301 | hints = context.hints || {},
|
42302 | targetParent = hints.targetParent,
|
42303 | targetAttach = hints.targetAttach;
|
42304 |
|
42305 |
|
42306 |
|
42307 |
|
42308 | if (targetAttach) {
|
42309 | return false;
|
42310 | }
|
42311 |
|
42312 |
|
42313 |
|
42314 | if (targetParent) {
|
42315 | target.parent = targetParent;
|
42316 | }
|
42317 |
|
42318 | try {
|
42319 | return canConnect(source, target);
|
42320 | } finally {
|
42321 |
|
42322 |
|
42323 | if (targetParent) {
|
42324 | target.parent = null;
|
42325 | }
|
42326 | }
|
42327 | });
|
42328 |
|
42329 | this.addRule('connection.reconnectStart', function(context) {
|
42330 |
|
42331 | var connection = context.connection,
|
42332 | source = context.hover || context.source,
|
42333 | target = connection.target;
|
42334 |
|
42335 | return canConnect(source, target, connection);
|
42336 | });
|
42337 |
|
42338 | this.addRule('connection.reconnectEnd', function(context) {
|
42339 |
|
42340 | var connection = context.connection,
|
42341 | source = connection.source,
|
42342 | target = context.hover || context.target;
|
42343 |
|
42344 | return canConnect(source, target, connection);
|
42345 | });
|
42346 |
|
42347 | this.addRule('connection.updateWaypoints', function(context) {
|
42348 | return {
|
42349 | type: context.connection.type
|
42350 | };
|
42351 | });
|
42352 |
|
42353 | this.addRule('shape.resize', function(context) {
|
42354 |
|
42355 | var shape = context.shape,
|
42356 | newBounds = context.newBounds;
|
42357 |
|
42358 | return canResize(shape, newBounds);
|
42359 | });
|
42360 |
|
42361 | this.addRule('elements.create', function(context) {
|
42362 | var elements = context.elements,
|
42363 | position = context.position,
|
42364 | target = context.target;
|
42365 |
|
42366 | return every(elements, function(element) {
|
42367 | if (isConnection$3(element)) {
|
42368 | return canConnect(element.source, element.target, element);
|
42369 | }
|
42370 |
|
42371 | if (element.host) {
|
42372 | return canAttach(element, element.host, null, position);
|
42373 | }
|
42374 |
|
42375 | return canCreate(element, target, null);
|
42376 | });
|
42377 | });
|
42378 |
|
42379 | this.addRule('elements.move', function(context) {
|
42380 |
|
42381 | var target = context.target,
|
42382 | shapes = context.shapes,
|
42383 | position = context.position;
|
42384 |
|
42385 | return canAttach(shapes, target, null, position) ||
|
42386 | canReplace(shapes, target, position) ||
|
42387 | canMove(shapes, target) ||
|
42388 | canInsert(shapes, target);
|
42389 | });
|
42390 |
|
42391 | this.addRule('shape.create', function(context) {
|
42392 | return canCreate(
|
42393 | context.shape,
|
42394 | context.target,
|
42395 | context.source,
|
42396 | context.position
|
42397 | );
|
42398 | });
|
42399 |
|
42400 | this.addRule('shape.attach', function(context) {
|
42401 |
|
42402 | return canAttach(
|
42403 | context.shape,
|
42404 | context.target,
|
42405 | null,
|
42406 | context.position
|
42407 | );
|
42408 | });
|
42409 |
|
42410 | this.addRule('element.copy', function(context) {
|
42411 | var element = context.element,
|
42412 | elements = context.elements;
|
42413 |
|
42414 | return canCopy(elements, element);
|
42415 | });
|
42416 | };
|
42417 |
|
42418 | BpmnRules.prototype.canConnectMessageFlow = canConnectMessageFlow;
|
42419 |
|
42420 | BpmnRules.prototype.canConnectSequenceFlow = canConnectSequenceFlow;
|
42421 |
|
42422 | BpmnRules.prototype.canConnectDataAssociation = canConnectDataAssociation;
|
42423 |
|
42424 | BpmnRules.prototype.canConnectAssociation = canConnectAssociation;
|
42425 |
|
42426 | BpmnRules.prototype.canMove = canMove;
|
42427 |
|
42428 | BpmnRules.prototype.canAttach = canAttach;
|
42429 |
|
42430 | BpmnRules.prototype.canReplace = canReplace;
|
42431 |
|
42432 | BpmnRules.prototype.canDrop = canDrop;
|
42433 |
|
42434 | BpmnRules.prototype.canInsert = canInsert;
|
42435 |
|
42436 | BpmnRules.prototype.canCreate = canCreate;
|
42437 |
|
42438 | BpmnRules.prototype.canConnect = canConnect;
|
42439 |
|
42440 | BpmnRules.prototype.canResize = canResize;
|
42441 |
|
42442 | BpmnRules.prototype.canCopy = canCopy;
|
42443 |
|
42444 | |
42445 |
|
42446 |
|
42447 |
|
42448 | |
42449 |
|
42450 |
|
42451 |
|
42452 |
|
42453 |
|
42454 | function canStartConnection(element) {
|
42455 | if (nonExistingOrLabel(element)) {
|
42456 | return null;
|
42457 | }
|
42458 |
|
42459 | return isAny(element, [
|
42460 | 'bpmn:FlowNode',
|
42461 | 'bpmn:InteractionNode',
|
42462 | 'bpmn:DataObjectReference',
|
42463 | 'bpmn:DataStoreReference'
|
42464 | ]);
|
42465 | }
|
42466 |
|
42467 | function nonExistingOrLabel(element) {
|
42468 | return !element || isLabel(element);
|
42469 | }
|
42470 |
|
42471 | function isSame(a, b) {
|
42472 | return a === b;
|
42473 | }
|
42474 |
|
42475 | function getOrganizationalParent(element) {
|
42476 |
|
42477 | do {
|
42478 | if (is$1(element, 'bpmn:Process')) {
|
42479 | return getBusinessObject(element);
|
42480 | }
|
42481 |
|
42482 | if (is$1(element, 'bpmn:Participant')) {
|
42483 | return (
|
42484 | getBusinessObject(element).processRef ||
|
42485 | getBusinessObject(element)
|
42486 | );
|
42487 | }
|
42488 | } while ((element = element.parent));
|
42489 |
|
42490 | }
|
42491 |
|
42492 | function isTextAnnotation(element) {
|
42493 | return is$1(element, 'bpmn:TextAnnotation');
|
42494 | }
|
42495 |
|
42496 | function isGroup(element) {
|
42497 | return is$1(element, 'bpmn:Group') && !element.labelTarget;
|
42498 | }
|
42499 |
|
42500 | function isCompensationBoundary(element) {
|
42501 | return is$1(element, 'bpmn:BoundaryEvent') &&
|
42502 | hasEventDefinition$2(element, 'bpmn:CompensateEventDefinition');
|
42503 | }
|
42504 |
|
42505 | function isForCompensation(e) {
|
42506 | return getBusinessObject(e).isForCompensation;
|
42507 | }
|
42508 |
|
42509 | function isSameOrganization(a, b) {
|
42510 | var parentA = getOrganizationalParent(a),
|
42511 | parentB = getOrganizationalParent(b);
|
42512 |
|
42513 | return parentA === parentB;
|
42514 | }
|
42515 |
|
42516 | function isMessageFlowSource(element) {
|
42517 | return (
|
42518 | is$1(element, 'bpmn:InteractionNode') && (
|
42519 | !is$1(element, 'bpmn:Event') || (
|
42520 | is$1(element, 'bpmn:ThrowEvent') &&
|
42521 | hasEventDefinitionOrNone(element, 'bpmn:MessageEventDefinition')
|
42522 | )
|
42523 | )
|
42524 | );
|
42525 | }
|
42526 |
|
42527 | function isMessageFlowTarget(element) {
|
42528 | return (
|
42529 | is$1(element, 'bpmn:InteractionNode') &&
|
42530 | !isForCompensation(element) && (
|
42531 | !is$1(element, 'bpmn:Event') || (
|
42532 | is$1(element, 'bpmn:CatchEvent') &&
|
42533 | hasEventDefinitionOrNone(element, 'bpmn:MessageEventDefinition')
|
42534 | )
|
42535 | )
|
42536 | );
|
42537 | }
|
42538 |
|
42539 | function getScopeParent(element) {
|
42540 |
|
42541 | var parent = element;
|
42542 |
|
42543 | while ((parent = parent.parent)) {
|
42544 |
|
42545 | if (is$1(parent, 'bpmn:FlowElementsContainer')) {
|
42546 | return getBusinessObject(parent);
|
42547 | }
|
42548 |
|
42549 | if (is$1(parent, 'bpmn:Participant')) {
|
42550 | return getBusinessObject(parent).processRef;
|
42551 | }
|
42552 | }
|
42553 |
|
42554 | return null;
|
42555 | }
|
42556 |
|
42557 | function isSameScope(a, b) {
|
42558 | var scopeParentA = getScopeParent(a),
|
42559 | scopeParentB = getScopeParent(b);
|
42560 |
|
42561 | return scopeParentA === scopeParentB;
|
42562 | }
|
42563 |
|
42564 | function hasEventDefinition$2(element, eventDefinition) {
|
42565 | var bo = getBusinessObject(element);
|
42566 |
|
42567 | return !!find(bo.eventDefinitions || [], function(definition) {
|
42568 | return is$1(definition, eventDefinition);
|
42569 | });
|
42570 | }
|
42571 |
|
42572 | function hasEventDefinitionOrNone(element, eventDefinition) {
|
42573 | var bo = getBusinessObject(element);
|
42574 |
|
42575 | return (bo.eventDefinitions || []).every(function(definition) {
|
42576 | return is$1(definition, eventDefinition);
|
42577 | });
|
42578 | }
|
42579 |
|
42580 | function isSequenceFlowSource(element) {
|
42581 | return (
|
42582 | is$1(element, 'bpmn:FlowNode') &&
|
42583 | !is$1(element, 'bpmn:EndEvent') &&
|
42584 | !isEventSubProcess(element) &&
|
42585 | !(is$1(element, 'bpmn:IntermediateThrowEvent') &&
|
42586 | hasEventDefinition$2(element, 'bpmn:LinkEventDefinition')
|
42587 | ) &&
|
42588 | !isCompensationBoundary(element) &&
|
42589 | !isForCompensation(element)
|
42590 | );
|
42591 | }
|
42592 |
|
42593 | function isSequenceFlowTarget(element) {
|
42594 | return (
|
42595 | is$1(element, 'bpmn:FlowNode') &&
|
42596 | !is$1(element, 'bpmn:StartEvent') &&
|
42597 | !is$1(element, 'bpmn:BoundaryEvent') &&
|
42598 | !isEventSubProcess(element) &&
|
42599 | !(is$1(element, 'bpmn:IntermediateCatchEvent') &&
|
42600 | hasEventDefinition$2(element, 'bpmn:LinkEventDefinition')
|
42601 | ) &&
|
42602 | !isForCompensation(element)
|
42603 | );
|
42604 | }
|
42605 |
|
42606 | function isEventBasedTarget(element) {
|
42607 | return (
|
42608 | is$1(element, 'bpmn:ReceiveTask') || (
|
42609 | is$1(element, 'bpmn:IntermediateCatchEvent') && (
|
42610 | hasEventDefinition$2(element, 'bpmn:MessageEventDefinition') ||
|
42611 | hasEventDefinition$2(element, 'bpmn:TimerEventDefinition') ||
|
42612 | hasEventDefinition$2(element, 'bpmn:ConditionalEventDefinition') ||
|
42613 | hasEventDefinition$2(element, 'bpmn:SignalEventDefinition')
|
42614 | )
|
42615 | )
|
42616 | );
|
42617 | }
|
42618 |
|
42619 | function isConnection$3(element) {
|
42620 | return element.waypoints;
|
42621 | }
|
42622 |
|
42623 | function getParents$1(element) {
|
42624 |
|
42625 | var parents = [];
|
42626 |
|
42627 | while (element) {
|
42628 | element = element.parent;
|
42629 |
|
42630 | if (element) {
|
42631 | parents.push(element);
|
42632 | }
|
42633 | }
|
42634 |
|
42635 | return parents;
|
42636 | }
|
42637 |
|
42638 | function isParent(possibleParent, element) {
|
42639 | var allParents = getParents$1(element);
|
42640 | return allParents.indexOf(possibleParent) !== -1;
|
42641 | }
|
42642 |
|
42643 | function canConnect(source, target, connection) {
|
42644 |
|
42645 | if (nonExistingOrLabel(source) || nonExistingOrLabel(target)) {
|
42646 | return null;
|
42647 | }
|
42648 |
|
42649 | if (!is$1(connection, 'bpmn:DataAssociation')) {
|
42650 |
|
42651 | if (canConnectMessageFlow(source, target)) {
|
42652 | return { type: 'bpmn:MessageFlow' };
|
42653 | }
|
42654 |
|
42655 | if (canConnectSequenceFlow(source, target)) {
|
42656 | return { type: 'bpmn:SequenceFlow' };
|
42657 | }
|
42658 | }
|
42659 |
|
42660 | var connectDataAssociation = canConnectDataAssociation(source, target);
|
42661 |
|
42662 | if (connectDataAssociation) {
|
42663 | return connectDataAssociation;
|
42664 | }
|
42665 |
|
42666 | if (isCompensationBoundary(source) && isForCompensation(target)) {
|
42667 | return {
|
42668 | type: 'bpmn:Association',
|
42669 | associationDirection: 'One'
|
42670 | };
|
42671 | }
|
42672 |
|
42673 | if (canConnectAssociation(source, target)) {
|
42674 |
|
42675 | return {
|
42676 | type: 'bpmn:Association'
|
42677 | };
|
42678 | }
|
42679 |
|
42680 | return false;
|
42681 | }
|
42682 |
|
42683 | |
42684 |
|
42685 |
|
42686 |
|
42687 |
|
42688 | function canDrop(element, target, position) {
|
42689 |
|
42690 |
|
42691 | if (isLabel(element) || isGroup(element)) {
|
42692 | return true;
|
42693 | }
|
42694 |
|
42695 |
|
42696 |
|
42697 | if (is$1(target, 'bpmn:Participant') && !isExpanded(target)) {
|
42698 | return false;
|
42699 | }
|
42700 |
|
42701 |
|
42702 |
|
42703 | if (is$1(element, 'bpmn:Participant')) {
|
42704 | return is$1(target, 'bpmn:Process') || is$1(target, 'bpmn:Collaboration');
|
42705 | }
|
42706 |
|
42707 |
|
42708 | if (isAny(element, [ 'bpmn:DataInput', 'bpmn:DataOutput' ])) {
|
42709 |
|
42710 | if (element.parent) {
|
42711 | return target === element.parent;
|
42712 | }
|
42713 | }
|
42714 |
|
42715 |
|
42716 | if (is$1(element, 'bpmn:Lane')) {
|
42717 | return is$1(target, 'bpmn:Participant') || is$1(target, 'bpmn:Lane');
|
42718 | }
|
42719 |
|
42720 |
|
42721 | if (is$1(element, 'bpmn:BoundaryEvent') && !isDroppableBoundaryEvent(element)) {
|
42722 | return false;
|
42723 | }
|
42724 |
|
42725 |
|
42726 |
|
42727 | if (is$1(element, 'bpmn:FlowElement') && !is$1(element, 'bpmn:DataStoreReference')) {
|
42728 | if (is$1(target, 'bpmn:FlowElementsContainer')) {
|
42729 | return isExpanded(target);
|
42730 | }
|
42731 |
|
42732 | return isAny(target, [ 'bpmn:Participant', 'bpmn:Lane' ]);
|
42733 | }
|
42734 |
|
42735 |
|
42736 |
|
42737 |
|
42738 |
|
42739 | if (isAny(element, [ 'bpmn:Artifact', 'bpmn:DataAssociation', 'bpmn:DataStoreReference' ])) {
|
42740 | return isAny(target, [
|
42741 | 'bpmn:Collaboration',
|
42742 | 'bpmn:Lane',
|
42743 | 'bpmn:Participant',
|
42744 | 'bpmn:Process',
|
42745 | 'bpmn:SubProcess' ]);
|
42746 | }
|
42747 |
|
42748 | if (is$1(element, 'bpmn:MessageFlow')) {
|
42749 | return is$1(target, 'bpmn:Collaboration')
|
42750 | || element.source.parent == target
|
42751 | || element.target.parent == target;
|
42752 | }
|
42753 |
|
42754 | return false;
|
42755 | }
|
42756 |
|
42757 | function isDroppableBoundaryEvent(event) {
|
42758 | return getBusinessObject(event).cancelActivity && (
|
42759 | hasNoEventDefinition(event) || hasCommonBoundaryIntermediateEventDefinition(event)
|
42760 | );
|
42761 | }
|
42762 |
|
42763 | function isBoundaryEvent(element) {
|
42764 | return !isLabel(element) && is$1(element, 'bpmn:BoundaryEvent');
|
42765 | }
|
42766 |
|
42767 | function isLane(element) {
|
42768 | return is$1(element, 'bpmn:Lane');
|
42769 | }
|
42770 |
|
42771 | |
42772 |
|
42773 |
|
42774 |
|
42775 | function isBoundaryCandidate(element) {
|
42776 | if (isBoundaryEvent(element)) {
|
42777 | return true;
|
42778 | }
|
42779 |
|
42780 | if (is$1(element, 'bpmn:IntermediateThrowEvent') && hasNoEventDefinition(element)) {
|
42781 | return true;
|
42782 | }
|
42783 |
|
42784 | return (
|
42785 | is$1(element, 'bpmn:IntermediateCatchEvent') &&
|
42786 | hasCommonBoundaryIntermediateEventDefinition(element)
|
42787 | );
|
42788 | }
|
42789 |
|
42790 | function hasNoEventDefinition(element) {
|
42791 | var bo = getBusinessObject(element);
|
42792 |
|
42793 | return bo && !(bo.eventDefinitions && bo.eventDefinitions.length);
|
42794 | }
|
42795 |
|
42796 | function hasCommonBoundaryIntermediateEventDefinition(element) {
|
42797 | return hasOneOfEventDefinitions(element, [
|
42798 | 'bpmn:MessageEventDefinition',
|
42799 | 'bpmn:TimerEventDefinition',
|
42800 | 'bpmn:SignalEventDefinition',
|
42801 | 'bpmn:ConditionalEventDefinition'
|
42802 | ]);
|
42803 | }
|
42804 |
|
42805 | function hasOneOfEventDefinitions(element, eventDefinitions) {
|
42806 | return eventDefinitions.some(function(definition) {
|
42807 | return hasEventDefinition$2(element, definition);
|
42808 | });
|
42809 | }
|
42810 |
|
42811 | function isReceiveTaskAfterEventBasedGateway(element) {
|
42812 | return (
|
42813 | is$1(element, 'bpmn:ReceiveTask') &&
|
42814 | find(element.incoming, function(incoming) {
|
42815 | return is$1(incoming.source, 'bpmn:EventBasedGateway');
|
42816 | })
|
42817 | );
|
42818 | }
|
42819 |
|
42820 |
|
42821 | function canAttach(elements, target, source, position) {
|
42822 |
|
42823 | if (!Array.isArray(elements)) {
|
42824 | elements = [ elements ];
|
42825 | }
|
42826 |
|
42827 |
|
42828 | if (elements.length !== 1) {
|
42829 | return false;
|
42830 | }
|
42831 |
|
42832 | var element = elements[0];
|
42833 |
|
42834 |
|
42835 | if (isLabel(element)) {
|
42836 | return false;
|
42837 | }
|
42838 |
|
42839 |
|
42840 | if (!isBoundaryCandidate(element)) {
|
42841 | return false;
|
42842 | }
|
42843 |
|
42844 |
|
42845 | if (isEventSubProcess(target)) {
|
42846 | return false;
|
42847 | }
|
42848 |
|
42849 |
|
42850 | if (!is$1(target, 'bpmn:Activity') || isForCompensation(target)) {
|
42851 | return false;
|
42852 | }
|
42853 |
|
42854 |
|
42855 | if (position && !getBoundaryAttachment(position, target)) {
|
42856 | return false;
|
42857 | }
|
42858 |
|
42859 |
|
42860 | if (isReceiveTaskAfterEventBasedGateway(target)) {
|
42861 | return false;
|
42862 | }
|
42863 |
|
42864 | return 'attach';
|
42865 | }
|
42866 |
|
42867 |
|
42868 | |
42869 |
|
42870 |
|
42871 |
|
42872 |
|
42873 |
|
42874 |
|
42875 |
|
42876 |
|
42877 |
|
42878 |
|
42879 |
|
42880 |
|
42881 |
|
42882 |
|
42883 |
|
42884 |
|
42885 |
|
42886 |
|
42887 | function canReplace(elements, target, position) {
|
42888 |
|
42889 | if (!target) {
|
42890 | return false;
|
42891 | }
|
42892 |
|
42893 | var canExecute = {
|
42894 | replacements: []
|
42895 | };
|
42896 |
|
42897 | forEach(elements, function(element) {
|
42898 |
|
42899 | if (!isEventSubProcess(target)) {
|
42900 |
|
42901 | if (is$1(element, 'bpmn:StartEvent') &&
|
42902 | element.type !== 'label' &&
|
42903 | canDrop(element, target)) {
|
42904 |
|
42905 |
|
42906 |
|
42907 | if (!isInterrupting(element)) {
|
42908 | canExecute.replacements.push({
|
42909 | oldElementId: element.id,
|
42910 | newElementType: 'bpmn:StartEvent'
|
42911 | });
|
42912 | }
|
42913 |
|
42914 |
|
42915 |
|
42916 | if (hasErrorEventDefinition(element) ||
|
42917 | hasEscalationEventDefinition(element) ||
|
42918 | hasCompensateEventDefinition(element)) {
|
42919 | canExecute.replacements.push({
|
42920 | oldElementId: element.id,
|
42921 | newElementType: 'bpmn:StartEvent'
|
42922 | });
|
42923 | }
|
42924 | }
|
42925 | }
|
42926 |
|
42927 | if (!is$1(target, 'bpmn:Transaction')) {
|
42928 | if (hasEventDefinition$2(element, 'bpmn:CancelEventDefinition') &&
|
42929 | element.type !== 'label') {
|
42930 |
|
42931 | if (is$1(element, 'bpmn:EndEvent') && canDrop(element, target)) {
|
42932 | canExecute.replacements.push({
|
42933 | oldElementId: element.id,
|
42934 | newElementType: 'bpmn:EndEvent'
|
42935 | });
|
42936 | }
|
42937 |
|
42938 | if (is$1(element, 'bpmn:BoundaryEvent') && canAttach(element, target, null, position)) {
|
42939 | canExecute.replacements.push({
|
42940 | oldElementId: element.id,
|
42941 | newElementType: 'bpmn:BoundaryEvent'
|
42942 | });
|
42943 | }
|
42944 | }
|
42945 | }
|
42946 | });
|
42947 |
|
42948 | return canExecute.replacements.length ? canExecute : false;
|
42949 | }
|
42950 |
|
42951 | function canMove(elements, target) {
|
42952 |
|
42953 |
|
42954 | if (some(elements, isLane)) {
|
42955 | return false;
|
42956 | }
|
42957 |
|
42958 |
|
42959 | if (!target) {
|
42960 | return true;
|
42961 | }
|
42962 |
|
42963 | return elements.every(function(element) {
|
42964 | return canDrop(element, target);
|
42965 | });
|
42966 | }
|
42967 |
|
42968 | function canCreate(shape, target, source, position) {
|
42969 |
|
42970 | if (!target) {
|
42971 | return false;
|
42972 | }
|
42973 |
|
42974 | if (isLabel(shape) || isGroup(shape)) {
|
42975 | return true;
|
42976 | }
|
42977 |
|
42978 | if (isSame(source, target)) {
|
42979 | return false;
|
42980 | }
|
42981 |
|
42982 |
|
42983 |
|
42984 | if (source && isParent(source, target)) {
|
42985 | return false;
|
42986 | }
|
42987 |
|
42988 | return canDrop(shape, target) || canInsert(shape, target);
|
42989 | }
|
42990 |
|
42991 | function canResize(shape, newBounds) {
|
42992 | if (is$1(shape, 'bpmn:SubProcess')) {
|
42993 | return (
|
42994 | isExpanded(shape) && (
|
42995 | !newBounds || (newBounds.width >= 100 && newBounds.height >= 80)
|
42996 | )
|
42997 | );
|
42998 | }
|
42999 |
|
43000 | if (is$1(shape, 'bpmn:Lane')) {
|
43001 | return !newBounds || (newBounds.width >= 130 && newBounds.height >= 60);
|
43002 | }
|
43003 |
|
43004 | if (is$1(shape, 'bpmn:Participant')) {
|
43005 | return !newBounds || (newBounds.width >= 250 && newBounds.height >= 50);
|
43006 | }
|
43007 |
|
43008 | if (isTextAnnotation(shape)) {
|
43009 | return true;
|
43010 | }
|
43011 |
|
43012 | if (isGroup(shape)) {
|
43013 | return true;
|
43014 | }
|
43015 |
|
43016 | return false;
|
43017 | }
|
43018 |
|
43019 | |
43020 |
|
43021 |
|
43022 |
|
43023 | function isOneTextAnnotation(source, target) {
|
43024 |
|
43025 | var sourceTextAnnotation = isTextAnnotation(source),
|
43026 | targetTextAnnotation = isTextAnnotation(target);
|
43027 |
|
43028 | return (
|
43029 | (sourceTextAnnotation || targetTextAnnotation) &&
|
43030 | (sourceTextAnnotation !== targetTextAnnotation)
|
43031 | );
|
43032 | }
|
43033 |
|
43034 |
|
43035 | function canConnectAssociation(source, target) {
|
43036 |
|
43037 |
|
43038 | if (isConnection$3(source) || isConnection$3(target)) {
|
43039 | return false;
|
43040 | }
|
43041 |
|
43042 |
|
43043 | if (isCompensationBoundary(source) && isForCompensation(target)) {
|
43044 | return true;
|
43045 | }
|
43046 |
|
43047 |
|
43048 | if (isParent(target, source) || isParent(source, target)) {
|
43049 | return false;
|
43050 | }
|
43051 |
|
43052 |
|
43053 | return isOneTextAnnotation(source, target);
|
43054 | }
|
43055 |
|
43056 | function canConnectMessageFlow(source, target) {
|
43057 |
|
43058 |
|
43059 |
|
43060 | if (getRootElement(source) && !getRootElement(target)) {
|
43061 | return false;
|
43062 | }
|
43063 |
|
43064 | return (
|
43065 | isMessageFlowSource(source) &&
|
43066 | isMessageFlowTarget(target) &&
|
43067 | !isSameOrganization(source, target)
|
43068 | );
|
43069 | }
|
43070 |
|
43071 | function canConnectSequenceFlow(source, target) {
|
43072 |
|
43073 | if (
|
43074 | isEventBasedTarget(target) &&
|
43075 | target.incoming.length > 0 &&
|
43076 | areOutgoingEventBasedGatewayConnections(target.incoming) &&
|
43077 | !is$1(source, 'bpmn:EventBasedGateway')
|
43078 | ) {
|
43079 | return false;
|
43080 | }
|
43081 |
|
43082 | return isSequenceFlowSource(source) &&
|
43083 | isSequenceFlowTarget(target) &&
|
43084 | isSameScope(source, target) &&
|
43085 | !(is$1(source, 'bpmn:EventBasedGateway') && !isEventBasedTarget(target));
|
43086 | }
|
43087 |
|
43088 |
|
43089 | function canConnectDataAssociation(source, target) {
|
43090 |
|
43091 | if (isAny(source, [ 'bpmn:DataObjectReference', 'bpmn:DataStoreReference' ]) &&
|
43092 | isAny(target, [ 'bpmn:Activity', 'bpmn:ThrowEvent' ])) {
|
43093 | return { type: 'bpmn:DataInputAssociation' };
|
43094 | }
|
43095 |
|
43096 | if (isAny(target, [ 'bpmn:DataObjectReference', 'bpmn:DataStoreReference' ]) &&
|
43097 | isAny(source, [ 'bpmn:Activity', 'bpmn:CatchEvent' ])) {
|
43098 | return { type: 'bpmn:DataOutputAssociation' };
|
43099 | }
|
43100 |
|
43101 | return false;
|
43102 | }
|
43103 |
|
43104 | function canInsert(shape, flow, position) {
|
43105 |
|
43106 | if (!flow) {
|
43107 | return false;
|
43108 | }
|
43109 |
|
43110 | if (Array.isArray(shape)) {
|
43111 | if (shape.length !== 1) {
|
43112 | return false;
|
43113 | }
|
43114 |
|
43115 | shape = shape[0];
|
43116 | }
|
43117 |
|
43118 | if (flow.source === shape ||
|
43119 | flow.target === shape) {
|
43120 | return false;
|
43121 | }
|
43122 |
|
43123 |
|
43124 |
|
43125 |
|
43126 |
|
43127 |
|
43128 |
|
43129 | return (
|
43130 | isAny(flow, [ 'bpmn:SequenceFlow', 'bpmn:MessageFlow' ]) &&
|
43131 | !isLabel(flow) &&
|
43132 | is$1(shape, 'bpmn:FlowNode') &&
|
43133 | !is$1(shape, 'bpmn:BoundaryEvent') &&
|
43134 | canDrop(shape, flow.parent));
|
43135 | }
|
43136 |
|
43137 | function includes(elements, element) {
|
43138 | return (elements && element) && elements.indexOf(element) !== -1;
|
43139 | }
|
43140 |
|
43141 | function canCopy(elements, element) {
|
43142 | if (isLabel(element)) {
|
43143 | return true;
|
43144 | }
|
43145 |
|
43146 | if (is$1(element, 'bpmn:Lane') && !includes(elements, element.parent)) {
|
43147 | return false;
|
43148 | }
|
43149 |
|
43150 | if (is$1(element, 'bpmn:BoundaryEvent') && !includes(elements, element.host)) {
|
43151 | return false;
|
43152 | }
|
43153 |
|
43154 | return true;
|
43155 | }
|
43156 |
|
43157 | function isOutgoingEventBasedGatewayConnection(connection) {
|
43158 |
|
43159 | if (connection && connection.source) {
|
43160 | return is$1(connection.source, 'bpmn:EventBasedGateway');
|
43161 | }
|
43162 | }
|
43163 |
|
43164 | function areOutgoingEventBasedGatewayConnections(connections) {
|
43165 | connections = connections || [];
|
43166 |
|
43167 | return connections.some(isOutgoingEventBasedGatewayConnection);
|
43168 | }
|
43169 |
|
43170 | function getRootElement(element) {
|
43171 | return getParent$1(element, 'bpmn:Process') || getParent$1(element, 'bpmn:Collaboration');
|
43172 | }
|
43173 |
|
43174 | var RulesModule$1 = {
|
43175 | __depends__: [
|
43176 | RulesModule
|
43177 | ],
|
43178 | __init__: [ 'bpmnRules' ],
|
43179 | bpmnRules: [ 'type', BpmnRules ]
|
43180 | };
|
43181 |
|
43182 | |
43183 |
|
43184 |
|
43185 |
|
43186 |
|
43187 |
|
43188 |
|
43189 |
|
43190 |
|
43191 |
|
43192 |
|
43193 |
|
43194 |
|
43195 |
|
43196 |
|
43197 |
|
43198 |
|
43199 |
|
43200 |
|
43201 |
|
43202 |
|
43203 |
|
43204 |
|
43205 |
|
43206 |
|
43207 |
|
43208 |
|
43209 |
|
43210 |
|
43211 | function OrderingProvider(eventBus) {
|
43212 |
|
43213 | CommandInterceptor.call(this, eventBus);
|
43214 |
|
43215 |
|
43216 | var self = this;
|
43217 |
|
43218 | this.preExecute([ 'shape.create', 'connection.create' ], function(event) {
|
43219 |
|
43220 | var context = event.context,
|
43221 | element = context.shape || context.connection,
|
43222 | parent = context.parent;
|
43223 |
|
43224 | var ordering = self.getOrdering(element, parent);
|
43225 |
|
43226 | if (ordering) {
|
43227 |
|
43228 | if (ordering.parent !== undefined) {
|
43229 | context.parent = ordering.parent;
|
43230 | }
|
43231 |
|
43232 | context.parentIndex = ordering.index;
|
43233 | }
|
43234 | });
|
43235 |
|
43236 | this.preExecute([ 'shape.move', 'connection.move' ], function(event) {
|
43237 |
|
43238 | var context = event.context,
|
43239 | element = context.shape || context.connection,
|
43240 | parent = context.newParent || element.parent;
|
43241 |
|
43242 | var ordering = self.getOrdering(element, parent);
|
43243 |
|
43244 | if (ordering) {
|
43245 |
|
43246 | if (ordering.parent !== undefined) {
|
43247 | context.newParent = ordering.parent;
|
43248 | }
|
43249 |
|
43250 | context.newParentIndex = ordering.index;
|
43251 | }
|
43252 | });
|
43253 | }
|
43254 |
|
43255 | |
43256 |
|
43257 |
|
43258 |
|
43259 |
|
43260 |
|
43261 |
|
43262 |
|
43263 |
|
43264 |
|
43265 |
|
43266 |
|
43267 | OrderingProvider.prototype.getOrdering = function(element, newParent) {
|
43268 | return null;
|
43269 | };
|
43270 |
|
43271 | inherits_browser(OrderingProvider, CommandInterceptor);
|
43272 |
|
43273 | |
43274 |
|
43275 |
|
43276 |
|
43277 |
|
43278 |
|
43279 | function BpmnOrderingProvider(eventBus, canvas, translate) {
|
43280 |
|
43281 | OrderingProvider.call(this, eventBus);
|
43282 |
|
43283 | var orders = [
|
43284 | { type: 'bpmn:SubProcess', order: { level: 6 } },
|
43285 | {
|
43286 | type: 'bpmn:SequenceFlow',
|
43287 | order: {
|
43288 | level: 3,
|
43289 | containers: [
|
43290 | 'bpmn:Participant',
|
43291 | 'bpmn:FlowElementsContainer'
|
43292 | ]
|
43293 | }
|
43294 | },
|
43295 |
|
43296 |
|
43297 | {
|
43298 | type: 'bpmn:DataAssociation',
|
43299 | order: {
|
43300 | level: 9,
|
43301 | containers: [
|
43302 | 'bpmn:Collaboration',
|
43303 | 'bpmn:Process'
|
43304 | ]
|
43305 | }
|
43306 | },
|
43307 | {
|
43308 | type: 'bpmn:MessageFlow', order: {
|
43309 | level: 9,
|
43310 | containers: [ 'bpmn:Collaboration' ]
|
43311 | }
|
43312 | },
|
43313 | {
|
43314 | type: 'bpmn:Association',
|
43315 | order: {
|
43316 | level: 6,
|
43317 | containers: [
|
43318 | 'bpmn:Participant',
|
43319 | 'bpmn:FlowElementsContainer',
|
43320 | 'bpmn:Collaboration'
|
43321 | ]
|
43322 | }
|
43323 | },
|
43324 | { type: 'bpmn:BoundaryEvent', order: { level: 8 } },
|
43325 | {
|
43326 | type: 'bpmn:Group',
|
43327 | order: {
|
43328 | level: 10,
|
43329 | containers: [
|
43330 | 'bpmn:Collaboration',
|
43331 | 'bpmn:Process'
|
43332 | ]
|
43333 | }
|
43334 | },
|
43335 | { type: 'bpmn:FlowElement', order: { level: 5 } },
|
43336 | { type: 'bpmn:Participant', order: { level: -2 } },
|
43337 | { type: 'bpmn:Lane', order: { level: -1 } }
|
43338 | ];
|
43339 |
|
43340 | function computeOrder(element) {
|
43341 | if (element.labelTarget) {
|
43342 | return { level: 10 };
|
43343 | }
|
43344 |
|
43345 | var entry = find(orders, function(o) {
|
43346 | return isAny(element, [ o.type ]);
|
43347 | });
|
43348 |
|
43349 | return entry && entry.order || { level: 1 };
|
43350 | }
|
43351 |
|
43352 | function getOrder(element) {
|
43353 |
|
43354 | var order = element.order;
|
43355 |
|
43356 | if (!order) {
|
43357 | element.order = order = computeOrder(element);
|
43358 | }
|
43359 |
|
43360 | return order;
|
43361 | }
|
43362 |
|
43363 | function findActualParent(element, newParent, containers) {
|
43364 |
|
43365 | var actualParent = newParent;
|
43366 |
|
43367 | while (actualParent) {
|
43368 |
|
43369 | if (isAny(actualParent, containers)) {
|
43370 | break;
|
43371 | }
|
43372 |
|
43373 | actualParent = actualParent.parent;
|
43374 | }
|
43375 |
|
43376 | if (!actualParent) {
|
43377 | throw new Error(translate('no parent for {element} in {parent}', {
|
43378 | element: element.id,
|
43379 | parent: newParent.id
|
43380 | }));
|
43381 | }
|
43382 |
|
43383 | return actualParent;
|
43384 | }
|
43385 |
|
43386 | this.getOrdering = function(element, newParent) {
|
43387 |
|
43388 |
|
43389 | if (element.labelTarget) {
|
43390 | return {
|
43391 | parent: canvas.getRootElement(),
|
43392 | index: -1
|
43393 | };
|
43394 | }
|
43395 |
|
43396 | var elementOrder = getOrder(element);
|
43397 |
|
43398 |
|
43399 | if (elementOrder.containers) {
|
43400 | newParent = findActualParent(element, newParent, elementOrder.containers);
|
43401 | }
|
43402 |
|
43403 |
|
43404 | var currentIndex = newParent.children.indexOf(element);
|
43405 |
|
43406 | var insertIndex = findIndex(newParent.children, function(child) {
|
43407 |
|
43408 |
|
43409 |
|
43410 |
|
43411 | if (!element.labelTarget && child.labelTarget) {
|
43412 | return false;
|
43413 | }
|
43414 |
|
43415 | return elementOrder.level < getOrder(child).level;
|
43416 | });
|
43417 |
|
43418 |
|
43419 |
|
43420 |
|
43421 |
|
43422 |
|
43423 | if (insertIndex !== -1) {
|
43424 | if (currentIndex !== -1 && currentIndex < insertIndex) {
|
43425 | insertIndex -= 1;
|
43426 | }
|
43427 | }
|
43428 |
|
43429 | return {
|
43430 | index: insertIndex,
|
43431 | parent: newParent
|
43432 | };
|
43433 | };
|
43434 | }
|
43435 |
|
43436 | BpmnOrderingProvider.$inject = [ 'eventBus', 'canvas', 'translate' ];
|
43437 |
|
43438 | inherits_browser(BpmnOrderingProvider, OrderingProvider);
|
43439 |
|
43440 | var OrderingModule = {
|
43441 | __depends__: [
|
43442 | translate$2
|
43443 | ],
|
43444 | __init__: [ 'bpmnOrderingProvider' ],
|
43445 | bpmnOrderingProvider: [ 'type', BpmnOrderingProvider ]
|
43446 | };
|
43447 |
|
43448 | |
43449 |
|
43450 |
|
43451 |
|
43452 |
|
43453 |
|
43454 |
|
43455 |
|
43456 |
|
43457 |
|
43458 |
|
43459 |
|
43460 |
|
43461 |
|
43462 |
|
43463 |
|
43464 |
|
43465 |
|
43466 |
|
43467 |
|
43468 |
|
43469 |
|
43470 |
|
43471 |
|
43472 |
|
43473 |
|
43474 |
|
43475 |
|
43476 |
|
43477 |
|
43478 |
|
43479 |
|
43480 |
|
43481 |
|
43482 |
|
43483 |
|
43484 |
|
43485 |
|
43486 |
|
43487 |
|
43488 |
|
43489 |
|
43490 |
|
43491 |
|
43492 |
|
43493 |
|
43494 |
|
43495 |
|
43496 |
|
43497 |
|
43498 |
|
43499 |
|
43500 |
|
43501 |
|
43502 |
|
43503 |
|
43504 |
|
43505 |
|
43506 |
|
43507 |
|
43508 |
|
43509 |
|
43510 |
|
43511 |
|
43512 |
|
43513 |
|
43514 |
|
43515 |
|
43516 |
|
43517 |
|
43518 |
|
43519 |
|
43520 |
|
43521 |
|
43522 |
|
43523 |
|
43524 | function CommandStack(eventBus, injector) {
|
43525 |
|
43526 | |
43527 |
|
43528 |
|
43529 |
|
43530 |
|
43531 | this._handlerMap = {};
|
43532 |
|
43533 | |
43534 |
|
43535 |
|
43536 |
|
43537 |
|
43538 | this._stack = [];
|
43539 |
|
43540 | |
43541 |
|
43542 |
|
43543 |
|
43544 |
|
43545 | this._stackIdx = -1;
|
43546 |
|
43547 | |
43548 |
|
43549 |
|
43550 |
|
43551 |
|
43552 | this._currentExecution = {
|
43553 | actions: [],
|
43554 | dirty: []
|
43555 | };
|
43556 |
|
43557 |
|
43558 | this._injector = injector;
|
43559 | this._eventBus = eventBus;
|
43560 |
|
43561 | this._uid = 1;
|
43562 |
|
43563 | eventBus.on([
|
43564 | 'diagram.destroy',
|
43565 | 'diagram.clear'
|
43566 | ], function() {
|
43567 | this.clear(false);
|
43568 | }, this);
|
43569 | }
|
43570 |
|
43571 | CommandStack.$inject = [ 'eventBus', 'injector' ];
|
43572 |
|
43573 |
|
43574 | |
43575 |
|
43576 |
|
43577 |
|
43578 |
|
43579 |
|
43580 | CommandStack.prototype.execute = function(command, context) {
|
43581 | if (!command) {
|
43582 | throw new Error('command required');
|
43583 | }
|
43584 |
|
43585 | var action = { command: command, context: context };
|
43586 |
|
43587 | this._pushAction(action);
|
43588 | this._internalExecute(action);
|
43589 | this._popAction(action);
|
43590 | };
|
43591 |
|
43592 |
|
43593 | |
43594 |
|
43595 |
|
43596 |
|
43597 |
|
43598 |
|
43599 |
|
43600 |
|
43601 |
|
43602 |
|
43603 |
|
43604 |
|
43605 |
|
43606 |
|
43607 |
|
43608 |
|
43609 |
|
43610 |
|
43611 |
|
43612 |
|
43613 | CommandStack.prototype.canExecute = function(command, context) {
|
43614 |
|
43615 | var action = { command: command, context: context };
|
43616 |
|
43617 | var handler = this._getHandler(command);
|
43618 |
|
43619 | var result = this._fire(command, 'canExecute', action);
|
43620 |
|
43621 |
|
43622 |
|
43623 | if (result === undefined) {
|
43624 | if (!handler) {
|
43625 | return false;
|
43626 | }
|
43627 |
|
43628 | if (handler.canExecute) {
|
43629 | result = handler.canExecute(context);
|
43630 | }
|
43631 | }
|
43632 |
|
43633 | return result;
|
43634 | };
|
43635 |
|
43636 |
|
43637 | |
43638 |
|
43639 |
|
43640 | CommandStack.prototype.clear = function(emit) {
|
43641 | this._stack.length = 0;
|
43642 | this._stackIdx = -1;
|
43643 |
|
43644 | if (emit !== false) {
|
43645 | this._fire('changed');
|
43646 | }
|
43647 | };
|
43648 |
|
43649 |
|
43650 | |
43651 |
|
43652 |
|
43653 | CommandStack.prototype.undo = function() {
|
43654 | var action = this._getUndoAction(),
|
43655 | next;
|
43656 |
|
43657 | if (action) {
|
43658 | this._pushAction(action);
|
43659 |
|
43660 | while (action) {
|
43661 | this._internalUndo(action);
|
43662 | next = this._getUndoAction();
|
43663 |
|
43664 | if (!next || next.id !== action.id) {
|
43665 | break;
|
43666 | }
|
43667 |
|
43668 | action = next;
|
43669 | }
|
43670 |
|
43671 | this._popAction();
|
43672 | }
|
43673 | };
|
43674 |
|
43675 |
|
43676 | |
43677 |
|
43678 |
|
43679 | CommandStack.prototype.redo = function() {
|
43680 | var action = this._getRedoAction(),
|
43681 | next;
|
43682 |
|
43683 | if (action) {
|
43684 | this._pushAction(action);
|
43685 |
|
43686 | while (action) {
|
43687 | this._internalExecute(action, true);
|
43688 | next = this._getRedoAction();
|
43689 |
|
43690 | if (!next || next.id !== action.id) {
|
43691 | break;
|
43692 | }
|
43693 |
|
43694 | action = next;
|
43695 | }
|
43696 |
|
43697 | this._popAction();
|
43698 | }
|
43699 | };
|
43700 |
|
43701 |
|
43702 | |
43703 |
|
43704 |
|
43705 |
|
43706 |
|
43707 |
|
43708 | CommandStack.prototype.register = function(command, handler) {
|
43709 | this._setHandler(command, handler);
|
43710 | };
|
43711 |
|
43712 |
|
43713 | |
43714 |
|
43715 |
|
43716 |
|
43717 |
|
43718 |
|
43719 |
|
43720 | CommandStack.prototype.registerHandler = function(command, handlerCls) {
|
43721 |
|
43722 | if (!command || !handlerCls) {
|
43723 | throw new Error('command and handlerCls must be defined');
|
43724 | }
|
43725 |
|
43726 | var handler = this._injector.instantiate(handlerCls);
|
43727 | this.register(command, handler);
|
43728 | };
|
43729 |
|
43730 | CommandStack.prototype.canUndo = function() {
|
43731 | return !!this._getUndoAction();
|
43732 | };
|
43733 |
|
43734 | CommandStack.prototype.canRedo = function() {
|
43735 | return !!this._getRedoAction();
|
43736 | };
|
43737 |
|
43738 |
|
43739 |
|
43740 | CommandStack.prototype._getRedoAction = function() {
|
43741 | return this._stack[this._stackIdx + 1];
|
43742 | };
|
43743 |
|
43744 |
|
43745 | CommandStack.prototype._getUndoAction = function() {
|
43746 | return this._stack[this._stackIdx];
|
43747 | };
|
43748 |
|
43749 |
|
43750 |
|
43751 |
|
43752 | CommandStack.prototype._internalUndo = function(action) {
|
43753 | var self = this;
|
43754 |
|
43755 | var command = action.command,
|
43756 | context = action.context;
|
43757 |
|
43758 | var handler = this._getHandler(command);
|
43759 |
|
43760 |
|
43761 | this._atomicDo(function() {
|
43762 | self._fire(command, 'revert', action);
|
43763 |
|
43764 | if (handler.revert) {
|
43765 | self._markDirty(handler.revert(context));
|
43766 | }
|
43767 |
|
43768 | self._revertedAction(action);
|
43769 |
|
43770 | self._fire(command, 'reverted', action);
|
43771 | });
|
43772 | };
|
43773 |
|
43774 |
|
43775 | CommandStack.prototype._fire = function(command, qualifier, event) {
|
43776 | if (arguments.length < 3) {
|
43777 | event = qualifier;
|
43778 | qualifier = null;
|
43779 | }
|
43780 |
|
43781 | var names = qualifier ? [ command + '.' + qualifier, qualifier ] : [ command ],
|
43782 | i, name, result;
|
43783 |
|
43784 | event = this._eventBus.createEvent(event);
|
43785 |
|
43786 | for (i = 0; (name = names[i]); i++) {
|
43787 | result = this._eventBus.fire('commandStack.' + name, event);
|
43788 |
|
43789 | if (event.cancelBubble) {
|
43790 | break;
|
43791 | }
|
43792 | }
|
43793 |
|
43794 | return result;
|
43795 | };
|
43796 |
|
43797 | CommandStack.prototype._createId = function() {
|
43798 | return this._uid++;
|
43799 | };
|
43800 |
|
43801 | CommandStack.prototype._atomicDo = function(fn) {
|
43802 |
|
43803 | var execution = this._currentExecution;
|
43804 |
|
43805 | execution.atomic = true;
|
43806 |
|
43807 | try {
|
43808 | fn();
|
43809 | } finally {
|
43810 | execution.atomic = false;
|
43811 | }
|
43812 | };
|
43813 |
|
43814 | CommandStack.prototype._internalExecute = function(action, redo) {
|
43815 | var self = this;
|
43816 |
|
43817 | var command = action.command,
|
43818 | context = action.context;
|
43819 |
|
43820 | var handler = this._getHandler(command);
|
43821 |
|
43822 | if (!handler) {
|
43823 | throw new Error('no command handler registered for <' + command + '>');
|
43824 | }
|
43825 |
|
43826 | this._pushAction(action);
|
43827 |
|
43828 | if (!redo) {
|
43829 | this._fire(command, 'preExecute', action);
|
43830 |
|
43831 | if (handler.preExecute) {
|
43832 | handler.preExecute(context);
|
43833 | }
|
43834 |
|
43835 | this._fire(command, 'preExecuted', action);
|
43836 | }
|
43837 |
|
43838 |
|
43839 | this._atomicDo(function() {
|
43840 |
|
43841 | self._fire(command, 'execute', action);
|
43842 |
|
43843 | if (handler.execute) {
|
43844 |
|
43845 |
|
43846 | self._markDirty(handler.execute(context));
|
43847 | }
|
43848 |
|
43849 |
|
43850 | self._executedAction(action, redo);
|
43851 |
|
43852 | self._fire(command, 'executed', action);
|
43853 | });
|
43854 |
|
43855 | if (!redo) {
|
43856 | this._fire(command, 'postExecute', action);
|
43857 |
|
43858 | if (handler.postExecute) {
|
43859 | handler.postExecute(context);
|
43860 | }
|
43861 |
|
43862 | this._fire(command, 'postExecuted', action);
|
43863 | }
|
43864 |
|
43865 | this._popAction(action);
|
43866 | };
|
43867 |
|
43868 |
|
43869 | CommandStack.prototype._pushAction = function(action) {
|
43870 |
|
43871 | var execution = this._currentExecution,
|
43872 | actions = execution.actions;
|
43873 |
|
43874 | var baseAction = actions[0];
|
43875 |
|
43876 | if (execution.atomic) {
|
43877 | throw new Error('illegal invocation in <execute> or <revert> phase (action: ' + action.command + ')');
|
43878 | }
|
43879 |
|
43880 | if (!action.id) {
|
43881 | action.id = (baseAction && baseAction.id) || this._createId();
|
43882 | }
|
43883 |
|
43884 | actions.push(action);
|
43885 | };
|
43886 |
|
43887 |
|
43888 | CommandStack.prototype._popAction = function() {
|
43889 | var execution = this._currentExecution,
|
43890 | actions = execution.actions,
|
43891 | dirty = execution.dirty;
|
43892 |
|
43893 | actions.pop();
|
43894 |
|
43895 | if (!actions.length) {
|
43896 | this._eventBus.fire('elements.changed', { elements: uniqueBy('id', dirty) });
|
43897 |
|
43898 | dirty.length = 0;
|
43899 |
|
43900 | this._fire('changed');
|
43901 | }
|
43902 | };
|
43903 |
|
43904 |
|
43905 | CommandStack.prototype._markDirty = function(elements) {
|
43906 | var execution = this._currentExecution;
|
43907 |
|
43908 | if (!elements) {
|
43909 | return;
|
43910 | }
|
43911 |
|
43912 | elements = isArray(elements) ? elements : [ elements ];
|
43913 |
|
43914 | execution.dirty = execution.dirty.concat(elements);
|
43915 | };
|
43916 |
|
43917 |
|
43918 | CommandStack.prototype._executedAction = function(action, redo) {
|
43919 | var stackIdx = ++this._stackIdx;
|
43920 |
|
43921 | if (!redo) {
|
43922 | this._stack.splice(stackIdx, this._stack.length, action);
|
43923 | }
|
43924 | };
|
43925 |
|
43926 |
|
43927 | CommandStack.prototype._revertedAction = function(action) {
|
43928 | this._stackIdx--;
|
43929 | };
|
43930 |
|
43931 |
|
43932 | CommandStack.prototype._getHandler = function(command) {
|
43933 | return this._handlerMap[command];
|
43934 | };
|
43935 |
|
43936 | CommandStack.prototype._setHandler = function(command, handler) {
|
43937 | if (!command || !handler) {
|
43938 | throw new Error('command and handler required');
|
43939 | }
|
43940 |
|
43941 | if (this._handlerMap[command]) {
|
43942 | throw new Error('overriding handler for command <' + command + '>');
|
43943 | }
|
43944 |
|
43945 | this._handlerMap[command] = handler;
|
43946 | };
|
43947 |
|
43948 | var CommandModule = {
|
43949 | commandStack: [ 'type', CommandStack ]
|
43950 | };
|
43951 |
|
43952 |
|
43953 | var ids$1 = new IdGenerator('tt');
|
43954 |
|
43955 |
|
43956 | function createRoot$1(parentNode) {
|
43957 | var root = domify(
|
43958 | '<div class="djs-tooltip-container" style="position: absolute; width: 0; height: 0;" />'
|
43959 | );
|
43960 |
|
43961 | parentNode.insertBefore(root, parentNode.firstChild);
|
43962 |
|
43963 | return root;
|
43964 | }
|
43965 |
|
43966 |
|
43967 | function setPosition$1(el, x, y) {
|
43968 | assign(el.style, { left: x + 'px', top: y + 'px' });
|
43969 | }
|
43970 |
|
43971 | function setVisible$1(el, visible) {
|
43972 | el.style.display = visible === false ? 'none' : '';
|
43973 | }
|
43974 |
|
43975 |
|
43976 | var tooltipClass = 'djs-tooltip',
|
43977 | tooltipSelector = '.' + tooltipClass;
|
43978 |
|
43979 | |
43980 |
|
43981 |
|
43982 |
|
43983 |
|
43984 |
|
43985 |
|
43986 |
|
43987 |
|
43988 |
|
43989 |
|
43990 |
|
43991 |
|
43992 |
|
43993 |
|
43994 |
|
43995 |
|
43996 |
|
43997 |
|
43998 |
|
43999 |
|
44000 |
|
44001 |
|
44002 |
|
44003 |
|
44004 |
|
44005 |
|
44006 |
|
44007 |
|
44008 |
|
44009 |
|
44010 |
|
44011 |
|
44012 |
|
44013 |
|
44014 |
|
44015 |
|
44016 | function Tooltips(eventBus, canvas) {
|
44017 |
|
44018 | this._eventBus = eventBus;
|
44019 | this._canvas = canvas;
|
44020 |
|
44021 | this._ids = ids$1;
|
44022 |
|
44023 | this._tooltipDefaults = {
|
44024 | show: {
|
44025 | minZoom: 0.7,
|
44026 | maxZoom: 5.0
|
44027 | }
|
44028 | };
|
44029 |
|
44030 | |
44031 |
|
44032 |
|
44033 | this._tooltips = {};
|
44034 |
|
44035 |
|
44036 | this._tooltipRoot = createRoot$1(canvas.getContainer());
|
44037 |
|
44038 |
|
44039 | var self = this;
|
44040 |
|
44041 | delegateEvents.bind(this._tooltipRoot, tooltipSelector, 'mousedown', function(event) {
|
44042 | event.stopPropagation();
|
44043 | });
|
44044 |
|
44045 | delegateEvents.bind(this._tooltipRoot, tooltipSelector, 'mouseover', function(event) {
|
44046 | self.trigger('mouseover', event);
|
44047 | });
|
44048 |
|
44049 | delegateEvents.bind(this._tooltipRoot, tooltipSelector, 'mouseout', function(event) {
|
44050 | self.trigger('mouseout', event);
|
44051 | });
|
44052 |
|
44053 | this._init();
|
44054 | }
|
44055 |
|
44056 |
|
44057 | Tooltips.$inject = [ 'eventBus', 'canvas' ];
|
44058 |
|
44059 |
|
44060 | |
44061 |
|
44062 |
|
44063 |
|
44064 |
|
44065 |
|
44066 |
|
44067 |
|
44068 |
|
44069 |
|
44070 |
|
44071 |
|
44072 |
|
44073 |
|
44074 |
|
44075 |
|
44076 |
|
44077 |
|
44078 | Tooltips.prototype.add = function(tooltip) {
|
44079 |
|
44080 | if (!tooltip.position) {
|
44081 | throw new Error('must specifiy tooltip position');
|
44082 | }
|
44083 |
|
44084 | if (!tooltip.html) {
|
44085 | throw new Error('must specifiy tooltip html');
|
44086 | }
|
44087 |
|
44088 | var id = this._ids.next();
|
44089 |
|
44090 | tooltip = assign({}, this._tooltipDefaults, tooltip, {
|
44091 | id: id
|
44092 | });
|
44093 |
|
44094 | this._addTooltip(tooltip);
|
44095 |
|
44096 | if (tooltip.timeout) {
|
44097 | this.setTimeout(tooltip);
|
44098 | }
|
44099 |
|
44100 | return id;
|
44101 | };
|
44102 |
|
44103 | Tooltips.prototype.trigger = function(action, event) {
|
44104 |
|
44105 | var node = event.delegateTarget || event.target;
|
44106 |
|
44107 | var tooltip = this.get(attr(node, 'data-tooltip-id'));
|
44108 |
|
44109 | if (!tooltip) {
|
44110 | return;
|
44111 | }
|
44112 |
|
44113 | if (action === 'mouseover' && tooltip.timeout) {
|
44114 | this.clearTimeout(tooltip);
|
44115 | }
|
44116 |
|
44117 | if (action === 'mouseout' && tooltip.timeout) {
|
44118 |
|
44119 |
|
44120 | tooltip.timeout = 1000;
|
44121 |
|
44122 | this.setTimeout(tooltip);
|
44123 | }
|
44124 | };
|
44125 |
|
44126 | |
44127 |
|
44128 |
|
44129 |
|
44130 |
|
44131 | Tooltips.prototype.get = function(id) {
|
44132 |
|
44133 | if (typeof id !== 'string') {
|
44134 | id = id.id;
|
44135 | }
|
44136 |
|
44137 | return this._tooltips[id];
|
44138 | };
|
44139 |
|
44140 | Tooltips.prototype.clearTimeout = function(tooltip) {
|
44141 |
|
44142 | tooltip = this.get(tooltip);
|
44143 |
|
44144 | if (!tooltip) {
|
44145 | return;
|
44146 | }
|
44147 |
|
44148 | var removeTimer = tooltip.removeTimer;
|
44149 |
|
44150 | if (removeTimer) {
|
44151 | clearTimeout(removeTimer);
|
44152 | tooltip.removeTimer = null;
|
44153 | }
|
44154 | };
|
44155 |
|
44156 | Tooltips.prototype.setTimeout = function(tooltip) {
|
44157 |
|
44158 | tooltip = this.get(tooltip);
|
44159 |
|
44160 | if (!tooltip) {
|
44161 | return;
|
44162 | }
|
44163 |
|
44164 | this.clearTimeout(tooltip);
|
44165 |
|
44166 | var self = this;
|
44167 |
|
44168 | tooltip.removeTimer = setTimeout(function() {
|
44169 | self.remove(tooltip);
|
44170 | }, tooltip.timeout);
|
44171 | };
|
44172 |
|
44173 | |
44174 |
|
44175 |
|
44176 |
|
44177 |
|
44178 | Tooltips.prototype.remove = function(id) {
|
44179 |
|
44180 | var tooltip = this.get(id);
|
44181 |
|
44182 | if (tooltip) {
|
44183 | remove(tooltip.html);
|
44184 | remove(tooltip.htmlContainer);
|
44185 |
|
44186 | delete tooltip.htmlContainer;
|
44187 |
|
44188 | delete this._tooltips[tooltip.id];
|
44189 | }
|
44190 | };
|
44191 |
|
44192 |
|
44193 | Tooltips.prototype.show = function() {
|
44194 | setVisible$1(this._tooltipRoot);
|
44195 | };
|
44196 |
|
44197 |
|
44198 | Tooltips.prototype.hide = function() {
|
44199 | setVisible$1(this._tooltipRoot, false);
|
44200 | };
|
44201 |
|
44202 |
|
44203 | Tooltips.prototype._updateRoot = function(viewbox) {
|
44204 | var a = viewbox.scale || 1;
|
44205 | var d = viewbox.scale || 1;
|
44206 |
|
44207 | var matrix = 'matrix(' + a + ',0,0,' + d + ',' + (-1 * viewbox.x * a) + ',' + (-1 * viewbox.y * d) + ')';
|
44208 |
|
44209 | this._tooltipRoot.style.transform = matrix;
|
44210 | this._tooltipRoot.style['-ms-transform'] = matrix;
|
44211 | };
|
44212 |
|
44213 |
|
44214 | Tooltips.prototype._addTooltip = function(tooltip) {
|
44215 |
|
44216 | var id = tooltip.id,
|
44217 | html = tooltip.html,
|
44218 | htmlContainer,
|
44219 | tooltipRoot = this._tooltipRoot;
|
44220 |
|
44221 |
|
44222 | if (html.get && html.constructor.prototype.jquery) {
|
44223 | html = html.get(0);
|
44224 | }
|
44225 |
|
44226 |
|
44227 |
|
44228 | if (isString(html)) {
|
44229 | html = domify(html);
|
44230 | }
|
44231 |
|
44232 | htmlContainer = domify('<div data-tooltip-id="' + id + '" class="' + tooltipClass + '" style="position: absolute">');
|
44233 |
|
44234 | htmlContainer.appendChild(html);
|
44235 |
|
44236 | if (tooltip.type) {
|
44237 | classes(htmlContainer).add('djs-tooltip-' + tooltip.type);
|
44238 | }
|
44239 |
|
44240 | if (tooltip.className) {
|
44241 | classes(htmlContainer).add(tooltip.className);
|
44242 | }
|
44243 |
|
44244 | tooltip.htmlContainer = htmlContainer;
|
44245 |
|
44246 | tooltipRoot.appendChild(htmlContainer);
|
44247 |
|
44248 | this._tooltips[id] = tooltip;
|
44249 |
|
44250 | this._updateTooltip(tooltip);
|
44251 | };
|
44252 |
|
44253 |
|
44254 | Tooltips.prototype._updateTooltip = function(tooltip) {
|
44255 |
|
44256 | var position = tooltip.position,
|
44257 | htmlContainer = tooltip.htmlContainer;
|
44258 |
|
44259 |
|
44260 |
|
44261 | setPosition$1(htmlContainer, position.x, position.y);
|
44262 | };
|
44263 |
|
44264 |
|
44265 | Tooltips.prototype._updateTooltipVisibilty = function(viewbox) {
|
44266 |
|
44267 | forEach(this._tooltips, function(tooltip) {
|
44268 | var show = tooltip.show,
|
44269 | htmlContainer = tooltip.htmlContainer,
|
44270 | visible = true;
|
44271 |
|
44272 | if (show) {
|
44273 | if (show.minZoom > viewbox.scale ||
|
44274 | show.maxZoom < viewbox.scale) {
|
44275 | visible = false;
|
44276 | }
|
44277 |
|
44278 | setVisible$1(htmlContainer, visible);
|
44279 | }
|
44280 | });
|
44281 | };
|
44282 |
|
44283 | Tooltips.prototype._init = function() {
|
44284 |
|
44285 | var self = this;
|
44286 |
|
44287 |
|
44288 |
|
44289 | function updateViewbox(viewbox) {
|
44290 | self._updateRoot(viewbox);
|
44291 | self._updateTooltipVisibilty(viewbox);
|
44292 |
|
44293 | self.show();
|
44294 | }
|
44295 |
|
44296 | this._eventBus.on('canvas.viewbox.changing', function(event) {
|
44297 | self.hide();
|
44298 | });
|
44299 |
|
44300 | this._eventBus.on('canvas.viewbox.changed', function(event) {
|
44301 | updateViewbox(event.viewbox);
|
44302 | });
|
44303 | };
|
44304 |
|
44305 | var TooltipsModule = {
|
44306 | __init__: [ 'tooltips' ],
|
44307 | tooltips: [ 'type', Tooltips ]
|
44308 | };
|
44309 |
|
44310 | |
44311 |
|
44312 |
|
44313 |
|
44314 |
|
44315 |
|
44316 |
|
44317 |
|
44318 |
|
44319 |
|
44320 |
|
44321 |
|
44322 |
|
44323 |
|
44324 |
|
44325 |
|
44326 | function saveClear(collection, removeFn) {
|
44327 |
|
44328 | if (typeof removeFn !== 'function') {
|
44329 | throw new Error('removeFn iterator must be a function');
|
44330 | }
|
44331 |
|
44332 | if (!collection) {
|
44333 | return;
|
44334 | }
|
44335 |
|
44336 | var e;
|
44337 |
|
44338 | while ((e = collection[0])) {
|
44339 | removeFn(e);
|
44340 | }
|
44341 |
|
44342 | return collection;
|
44343 | }
|
44344 |
|
44345 | var LOW_PRIORITY$c = 250,
|
44346 | HIGH_PRIORITY$a = 1400;
|
44347 |
|
44348 |
|
44349 | |
44350 |
|
44351 |
|
44352 |
|
44353 |
|
44354 |
|
44355 |
|
44356 |
|
44357 | function LabelSupport(injector, eventBus, modeling) {
|
44358 |
|
44359 | CommandInterceptor.call(this, eventBus);
|
44360 |
|
44361 | var movePreview = injector.get('movePreview', false);
|
44362 |
|
44363 |
|
44364 |
|
44365 | eventBus.on('shape.move.start', HIGH_PRIORITY$a, function(e) {
|
44366 |
|
44367 | var context = e.context,
|
44368 | shapes = context.shapes,
|
44369 | validatedShapes = context.validatedShapes;
|
44370 |
|
44371 | context.shapes = removeLabels(shapes);
|
44372 | context.validatedShapes = removeLabels(validatedShapes);
|
44373 | });
|
44374 |
|
44375 |
|
44376 | movePreview && eventBus.on('shape.move.start', LOW_PRIORITY$c, function(e) {
|
44377 |
|
44378 | var context = e.context,
|
44379 | shapes = context.shapes;
|
44380 |
|
44381 | var labels = [];
|
44382 |
|
44383 | forEach(shapes, function(element) {
|
44384 |
|
44385 | forEach(element.labels, function(label) {
|
44386 |
|
44387 | if (!label.hidden && context.shapes.indexOf(label) === -1) {
|
44388 | labels.push(label);
|
44389 | }
|
44390 |
|
44391 | if (element.labelTarget) {
|
44392 | labels.push(element);
|
44393 | }
|
44394 | });
|
44395 | });
|
44396 |
|
44397 | forEach(labels, function(label) {
|
44398 | movePreview.makeDraggable(context, label, true);
|
44399 | });
|
44400 |
|
44401 | });
|
44402 |
|
44403 |
|
44404 | this.preExecuted('elements.move', HIGH_PRIORITY$a, function(e) {
|
44405 | var context = e.context,
|
44406 | closure = context.closure,
|
44407 | enclosedElements = closure.enclosedElements;
|
44408 |
|
44409 | var enclosedLabels = [];
|
44410 |
|
44411 |
|
44412 |
|
44413 | forEach(enclosedElements, function(element) {
|
44414 | forEach(element.labels, function(label) {
|
44415 |
|
44416 | if (!enclosedElements[label.id]) {
|
44417 | enclosedLabels.push(label);
|
44418 | }
|
44419 | });
|
44420 | });
|
44421 |
|
44422 | closure.addAll(enclosedLabels);
|
44423 | });
|
44424 |
|
44425 |
|
44426 | this.preExecute([
|
44427 | 'connection.delete',
|
44428 | 'shape.delete'
|
44429 | ], function(e) {
|
44430 |
|
44431 | var context = e.context,
|
44432 | element = context.connection || context.shape;
|
44433 |
|
44434 | saveClear(element.labels, function(label) {
|
44435 | modeling.removeShape(label, { nested: true });
|
44436 | });
|
44437 | });
|
44438 |
|
44439 |
|
44440 | this.execute('shape.delete', function(e) {
|
44441 |
|
44442 | var context = e.context,
|
44443 | shape = context.shape,
|
44444 | labelTarget = shape.labelTarget;
|
44445 |
|
44446 |
|
44447 | if (labelTarget) {
|
44448 | context.labelTargetIndex = indexOf$1(labelTarget.labels, shape);
|
44449 | context.labelTarget = labelTarget;
|
44450 |
|
44451 | shape.labelTarget = null;
|
44452 | }
|
44453 | });
|
44454 |
|
44455 | this.revert('shape.delete', function(e) {
|
44456 |
|
44457 | var context = e.context,
|
44458 | shape = context.shape,
|
44459 | labelTarget = context.labelTarget,
|
44460 | labelTargetIndex = context.labelTargetIndex;
|
44461 |
|
44462 |
|
44463 | if (labelTarget) {
|
44464 | add$1(labelTarget.labels, shape, labelTargetIndex);
|
44465 |
|
44466 | shape.labelTarget = labelTarget;
|
44467 | }
|
44468 | });
|
44469 |
|
44470 | }
|
44471 |
|
44472 | inherits_browser(LabelSupport, CommandInterceptor);
|
44473 |
|
44474 | LabelSupport.$inject = [
|
44475 | 'injector',
|
44476 | 'eventBus',
|
44477 | 'modeling'
|
44478 | ];
|
44479 |
|
44480 |
|
44481 | |
44482 |
|
44483 |
|
44484 |
|
44485 |
|
44486 |
|
44487 |
|
44488 |
|
44489 |
|
44490 | function removeLabels(elements) {
|
44491 |
|
44492 | return filter(elements, function(element) {
|
44493 |
|
44494 |
|
44495 |
|
44496 | return elements.indexOf(element.labelTarget) === -1;
|
44497 | });
|
44498 | }
|
44499 |
|
44500 | var LabelSupportModule = {
|
44501 | __init__: [ 'labelSupport'],
|
44502 | labelSupport: [ 'type', LabelSupport ]
|
44503 | };
|
44504 |
|
44505 | var LOW_PRIORITY$d = 251,
|
44506 | HIGH_PRIORITY$b = 1401;
|
44507 |
|
44508 | var MARKER_ATTACH$1 = 'attach-ok';
|
44509 |
|
44510 |
|
44511 | |
44512 |
|
44513 |
|
44514 |
|
44515 |
|
44516 |
|
44517 |
|
44518 |
|
44519 |
|
44520 |
|
44521 |
|
44522 |
|
44523 |
|
44524 |
|
44525 |
|
44526 | function AttachSupport(injector, eventBus, canvas, rules, modeling) {
|
44527 |
|
44528 | CommandInterceptor.call(this, eventBus);
|
44529 |
|
44530 | var movePreview = injector.get('movePreview', false);
|
44531 |
|
44532 |
|
44533 |
|
44534 |
|
44535 | eventBus.on('shape.move.start', HIGH_PRIORITY$b, function(e) {
|
44536 |
|
44537 | var context = e.context,
|
44538 | shapes = context.shapes,
|
44539 | validatedShapes = context.validatedShapes;
|
44540 |
|
44541 | context.shapes = addAttached(shapes);
|
44542 |
|
44543 | context.validatedShapes = removeAttached(validatedShapes);
|
44544 | });
|
44545 |
|
44546 |
|
44547 | movePreview && eventBus.on('shape.move.start', LOW_PRIORITY$d, function(e) {
|
44548 |
|
44549 | var context = e.context,
|
44550 | shapes = context.shapes,
|
44551 | attachers = getAttachers(shapes);
|
44552 |
|
44553 | forEach(attachers, function(attacher) {
|
44554 | movePreview.makeDraggable(context, attacher, true);
|
44555 |
|
44556 | forEach(attacher.labels, function(label) {
|
44557 | movePreview.makeDraggable(context, label, true);
|
44558 | });
|
44559 | });
|
44560 | });
|
44561 |
|
44562 |
|
44563 | movePreview && eventBus.on('shape.move.start', function(event) {
|
44564 | var context = event.context,
|
44565 | shapes = context.shapes;
|
44566 |
|
44567 | if (shapes.length !== 1) {
|
44568 | return;
|
44569 | }
|
44570 |
|
44571 | var shape = shapes[0];
|
44572 |
|
44573 | var host = shape.host;
|
44574 |
|
44575 | if (host) {
|
44576 | canvas.addMarker(host, MARKER_ATTACH$1);
|
44577 |
|
44578 | eventBus.once([
|
44579 | 'shape.move.out',
|
44580 | 'shape.move.cleanup'
|
44581 | ], function() {
|
44582 | canvas.removeMarker(host, MARKER_ATTACH$1);
|
44583 | });
|
44584 | }
|
44585 | });
|
44586 |
|
44587 |
|
44588 | this.preExecuted('elements.move', HIGH_PRIORITY$b, function(e) {
|
44589 | var context = e.context,
|
44590 | closure = context.closure,
|
44591 | shapes = context.shapes,
|
44592 | attachers = getAttachers(shapes);
|
44593 |
|
44594 | forEach(attachers, function(attacher) {
|
44595 | closure.add(attacher, closure.topLevel[attacher.host.id]);
|
44596 | });
|
44597 | });
|
44598 |
|
44599 |
|
44600 | this.postExecuted('elements.move', function(e) {
|
44601 |
|
44602 | var context = e.context,
|
44603 | shapes = context.shapes,
|
44604 | newHost = context.newHost,
|
44605 | attachers;
|
44606 |
|
44607 |
|
44608 | if (shapes.length !== 1) {
|
44609 | return;
|
44610 | }
|
44611 |
|
44612 | if (newHost) {
|
44613 |
|
44614 | attachers = shapes;
|
44615 | } else {
|
44616 |
|
44617 | attachers = filter(shapes, function(s) {
|
44618 | return !!s.host;
|
44619 | });
|
44620 | }
|
44621 |
|
44622 | forEach(attachers, function(attacher) {
|
44623 | modeling.updateAttachment(attacher, newHost);
|
44624 | });
|
44625 | });
|
44626 |
|
44627 |
|
44628 | this.postExecuted('elements.move', function(e) {
|
44629 |
|
44630 | var shapes = e.context.shapes;
|
44631 |
|
44632 | forEach(shapes, function(shape) {
|
44633 |
|
44634 | forEach(shape.attachers, function(attacher) {
|
44635 |
|
44636 |
|
44637 | forEach(attacher.outgoing.slice(), function(connection) {
|
44638 | var allowed = rules.allowed('connection.reconnectStart', {
|
44639 | connection: connection,
|
44640 | source: connection.source,
|
44641 | target: connection.target
|
44642 | });
|
44643 |
|
44644 | if (!allowed) {
|
44645 | modeling.removeConnection(connection);
|
44646 | }
|
44647 | });
|
44648 |
|
44649 |
|
44650 | forEach(attacher.incoming.slice(), function(connection) {
|
44651 | var allowed = rules.allowed('connection.reconnectEnd', {
|
44652 | connection: connection,
|
44653 | source: connection.source,
|
44654 | target: connection.target
|
44655 | });
|
44656 |
|
44657 | if (!allowed) {
|
44658 | modeling.removeConnection(connection);
|
44659 | }
|
44660 | });
|
44661 | });
|
44662 | });
|
44663 | });
|
44664 |
|
44665 | this.postExecute('shape.create', function(e) {
|
44666 | var context = e.context,
|
44667 | shape = context.shape,
|
44668 | host = context.host;
|
44669 |
|
44670 | if (host) {
|
44671 | modeling.updateAttachment(shape, host);
|
44672 | }
|
44673 | });
|
44674 |
|
44675 |
|
44676 | this.postExecute('shape.replace', function(e) {
|
44677 |
|
44678 | var context = e.context,
|
44679 | oldShape = context.oldShape,
|
44680 | newShape = context.newShape;
|
44681 |
|
44682 |
|
44683 | saveClear(oldShape.attachers, function(attacher) {
|
44684 | var allowed = rules.allowed('elements.move', {
|
44685 | target: newShape,
|
44686 | shapes: [attacher]
|
44687 | });
|
44688 |
|
44689 | if (allowed === 'attach') {
|
44690 | modeling.updateAttachment(attacher, newShape);
|
44691 | } else {
|
44692 | modeling.removeShape(attacher);
|
44693 | }
|
44694 | });
|
44695 |
|
44696 |
|
44697 | if (newShape.attachers.length) {
|
44698 |
|
44699 | forEach(newShape.attachers, function(attacher) {
|
44700 | var delta = getNewAttachShapeDelta(attacher, oldShape, newShape);
|
44701 | modeling.moveShape(attacher, delta, attacher.parent);
|
44702 | });
|
44703 | }
|
44704 |
|
44705 | });
|
44706 |
|
44707 |
|
44708 | this.postExecute('shape.resize', function(event) {
|
44709 | var context = event.context,
|
44710 | shape = context.shape,
|
44711 | oldBounds = context.oldBounds,
|
44712 | newBounds = context.newBounds,
|
44713 | attachers = shape.attachers;
|
44714 |
|
44715 | forEach(attachers, function(attacher) {
|
44716 | var delta = getNewAttachShapeDelta(attacher, oldBounds, newBounds);
|
44717 |
|
44718 | modeling.moveShape(attacher, delta, attacher.parent);
|
44719 |
|
44720 | forEach(attacher.labels, function(label) {
|
44721 | modeling.moveShape(label, delta, label.parent);
|
44722 | });
|
44723 | });
|
44724 | });
|
44725 |
|
44726 |
|
44727 | this.preExecute('shape.delete', function(event) {
|
44728 |
|
44729 | var shape = event.context.shape;
|
44730 |
|
44731 | saveClear(shape.attachers, function(attacher) {
|
44732 | modeling.removeShape(attacher);
|
44733 | });
|
44734 |
|
44735 | if (shape.host) {
|
44736 | modeling.updateAttachment(shape, null);
|
44737 | }
|
44738 | });
|
44739 |
|
44740 |
|
44741 |
|
44742 |
|
44743 | eventBus.on('spaceTool.move', function(event) {
|
44744 |
|
44745 | var context = event.context,
|
44746 | initialized = context.initialized,
|
44747 | attachSupportInitialized = context.attachSupportInitialized;
|
44748 |
|
44749 | if (!initialized || attachSupportInitialized) {
|
44750 | return;
|
44751 | }
|
44752 |
|
44753 | var movingShapes = context.movingShapes;
|
44754 |
|
44755 |
|
44756 | var staticAttachers = filter(movingShapes, function(shape) {
|
44757 | var host = shape.host;
|
44758 |
|
44759 | return host && movingShapes.indexOf(host) === -1;
|
44760 | });
|
44761 |
|
44762 |
|
44763 | forEach(staticAttachers, function(shape) {
|
44764 | remove$2(movingShapes, shape);
|
44765 |
|
44766 | forEach(shape.labels, function(label) {
|
44767 | remove$2(movingShapes, shape.label);
|
44768 | });
|
44769 | });
|
44770 |
|
44771 | context.attachSupportInitialized = true;
|
44772 | });
|
44773 | }
|
44774 |
|
44775 | inherits_browser(AttachSupport, CommandInterceptor);
|
44776 |
|
44777 | AttachSupport.$inject = [
|
44778 | 'injector',
|
44779 | 'eventBus',
|
44780 | 'canvas',
|
44781 | 'rules',
|
44782 | 'modeling'
|
44783 | ];
|
44784 |
|
44785 |
|
44786 | |
44787 |
|
44788 |
|
44789 |
|
44790 |
|
44791 |
|
44792 | function getAttachers(shapes) {
|
44793 | return flatten(map(shapes, function(s) {
|
44794 | return s.attachers || [];
|
44795 | }));
|
44796 | }
|
44797 |
|
44798 | |
44799 |
|
44800 |
|
44801 |
|
44802 |
|
44803 |
|
44804 |
|
44805 | function addAttached(elements) {
|
44806 | var attachers = getAttachers(elements);
|
44807 |
|
44808 | return unionBy('id', elements, attachers);
|
44809 | }
|
44810 |
|
44811 | |
44812 |
|
44813 |
|
44814 |
|
44815 |
|
44816 |
|
44817 |
|
44818 |
|
44819 |
|
44820 | function removeAttached(elements) {
|
44821 |
|
44822 | var ids = groupBy(elements, 'id');
|
44823 |
|
44824 | return filter(elements, function(element) {
|
44825 | while (element) {
|
44826 |
|
44827 |
|
44828 | if (element.host && ids[element.host.id]) {
|
44829 | return false;
|
44830 | }
|
44831 |
|
44832 | element = element.parent;
|
44833 | }
|
44834 |
|
44835 | return true;
|
44836 | });
|
44837 | }
|
44838 |
|
44839 | var AttachSupportModule = {
|
44840 | __depends__: [
|
44841 | RulesModule
|
44842 | ],
|
44843 | __init__: [ 'attachSupport' ],
|
44844 | attachSupport: [ 'type', AttachSupport ]
|
44845 | };
|
44846 |
|
44847 | var LOW_PRIORITY$e = 250;
|
44848 |
|
44849 | |
44850 |
|
44851 |
|
44852 |
|
44853 |
|
44854 |
|
44855 |
|
44856 | function ToolManager(eventBus, dragging) {
|
44857 | this._eventBus = eventBus;
|
44858 | this._dragging = dragging;
|
44859 |
|
44860 | this._tools = [];
|
44861 | this._active = null;
|
44862 | }
|
44863 |
|
44864 | ToolManager.$inject = [ 'eventBus', 'dragging' ];
|
44865 |
|
44866 | ToolManager.prototype.registerTool = function(name, events) {
|
44867 | var tools = this._tools;
|
44868 |
|
44869 | if (!events) {
|
44870 | throw new Error('A tool has to be registered with it\'s "events"');
|
44871 | }
|
44872 |
|
44873 | tools.push(name);
|
44874 |
|
44875 | this.bindEvents(name, events);
|
44876 | };
|
44877 |
|
44878 | ToolManager.prototype.isActive = function(tool) {
|
44879 | return tool && this._active === tool;
|
44880 | };
|
44881 |
|
44882 | ToolManager.prototype.length = function(tool) {
|
44883 | return this._tools.length;
|
44884 | };
|
44885 |
|
44886 | ToolManager.prototype.setActive = function(tool) {
|
44887 | var eventBus = this._eventBus;
|
44888 |
|
44889 | if (this._active !== tool) {
|
44890 | this._active = tool;
|
44891 |
|
44892 | eventBus.fire('tool-manager.update', { tool: tool });
|
44893 | }
|
44894 | };
|
44895 |
|
44896 | ToolManager.prototype.bindEvents = function(name, events) {
|
44897 | var eventBus = this._eventBus,
|
44898 | dragging = this._dragging;
|
44899 |
|
44900 | var eventsToRegister = [];
|
44901 |
|
44902 | eventBus.on(events.tool + '.init', function(event) {
|
44903 | var context = event.context;
|
44904 |
|
44905 |
|
44906 | if (!context.reactivate && this.isActive(name)) {
|
44907 | this.setActive(null);
|
44908 |
|
44909 | dragging.cancel();
|
44910 | return;
|
44911 | }
|
44912 |
|
44913 | this.setActive(name);
|
44914 |
|
44915 | }, this);
|
44916 |
|
44917 |
|
44918 | forEach(events, function(event) {
|
44919 | eventsToRegister.push(event + '.ended');
|
44920 | eventsToRegister.push(event + '.canceled');
|
44921 | });
|
44922 |
|
44923 | eventBus.on(eventsToRegister, LOW_PRIORITY$e, function(event) {
|
44924 | var originalEvent = event.originalEvent;
|
44925 |
|
44926 |
|
44927 |
|
44928 |
|
44929 | if (!this._active) {
|
44930 | return;
|
44931 | }
|
44932 |
|
44933 | if (originalEvent && closest(originalEvent.target, '.group[data-group="tools"]')) {
|
44934 | return;
|
44935 | }
|
44936 |
|
44937 | this.setActive(null);
|
44938 | }, this);
|
44939 | };
|
44940 |
|
44941 | var ToolManagerModule = {
|
44942 | __depends__: [
|
44943 | DraggingModule
|
44944 | ],
|
44945 | __init__: [ 'toolManager' ],
|
44946 | toolManager: [ 'type', ToolManager ]
|
44947 | };
|
44948 |
|
44949 | |
44950 |
|
44951 |
|
44952 |
|
44953 |
|
44954 |
|
44955 |
|
44956 |
|
44957 | function getDirection(axis, offset) {
|
44958 |
|
44959 | if (axis === 'x') {
|
44960 | if (offset > 0) {
|
44961 | return 'e';
|
44962 | }
|
44963 |
|
44964 | if (offset < 0) {
|
44965 | return 'w';
|
44966 | }
|
44967 | }
|
44968 |
|
44969 | if (axis === 'y') {
|
44970 | if (offset > 0) {
|
44971 | return 's';
|
44972 | }
|
44973 |
|
44974 | if (offset < 0) {
|
44975 | return 'n';
|
44976 | }
|
44977 | }
|
44978 |
|
44979 | return null;
|
44980 | }
|
44981 |
|
44982 |
|
44983 | |
44984 |
|
44985 |
|
44986 |
|
44987 |
|
44988 |
|
44989 |
|
44990 |
|
44991 |
|
44992 | function resizeBounds$1(bounds, direction, delta) {
|
44993 |
|
44994 | var dx = delta.x,
|
44995 | dy = delta.y;
|
44996 |
|
44997 | switch (direction) {
|
44998 |
|
44999 | case 'n':
|
45000 | return {
|
45001 | x: bounds.x,
|
45002 | y: bounds.y + dy,
|
45003 | width: bounds.width,
|
45004 | height: bounds.height - dy
|
45005 | };
|
45006 |
|
45007 | case 's':
|
45008 | return {
|
45009 | x: bounds.x,
|
45010 | y: bounds.y,
|
45011 | width: bounds.width,
|
45012 | height: bounds.height + dy
|
45013 | };
|
45014 |
|
45015 | case 'w':
|
45016 | return {
|
45017 | x: bounds.x + dx,
|
45018 | y: bounds.y,
|
45019 | width: bounds.width - dx,
|
45020 | height: bounds.height
|
45021 | };
|
45022 |
|
45023 | case 'e':
|
45024 | return {
|
45025 | x: bounds.x,
|
45026 | y: bounds.y,
|
45027 | width: bounds.width + dx,
|
45028 | height: bounds.height
|
45029 | };
|
45030 |
|
45031 | default:
|
45032 | throw new Error('unrecognized direction: ' + direction);
|
45033 | }
|
45034 | }
|
45035 |
|
45036 | var abs$6 = Math.abs,
|
45037 | round$7 = Math.round;
|
45038 |
|
45039 | var HIGH_PRIORITY$c = 1500,
|
45040 | SPACE_TOOL_CURSOR = 'crosshair';
|
45041 |
|
45042 | var AXIS_TO_DIMENSION = { x: 'width', y: 'height' },
|
45043 | AXIS_INVERTED = { x: 'y', y: 'x' };
|
45044 |
|
45045 |
|
45046 | |
45047 |
|
45048 |
|
45049 |
|
45050 |
|
45051 | function SpaceTool(
|
45052 | eventBus, dragging, canvas,
|
45053 | modeling, rules, toolManager) {
|
45054 |
|
45055 | this._canvas = canvas;
|
45056 | this._dragging = dragging;
|
45057 | this._modeling = modeling;
|
45058 | this._rules = rules;
|
45059 | this._toolManager = toolManager;
|
45060 |
|
45061 | var self = this;
|
45062 |
|
45063 | toolManager.registerTool('space', {
|
45064 | tool: 'spaceTool.selection',
|
45065 | dragging: 'spaceTool'
|
45066 | });
|
45067 |
|
45068 | eventBus.on('spaceTool.selection.end', function(event) {
|
45069 | var target = event.originalEvent.target;
|
45070 |
|
45071 |
|
45072 |
|
45073 | if (!event.hover && !(target instanceof SVGElement)) {
|
45074 | return;
|
45075 | }
|
45076 |
|
45077 | eventBus.once('spaceTool.selection.ended', function() {
|
45078 | self.activateMakeSpace(event.originalEvent);
|
45079 | });
|
45080 | });
|
45081 |
|
45082 |
|
45083 | eventBus.on('spaceTool.move', HIGH_PRIORITY$c , function(event) {
|
45084 |
|
45085 | var context = event.context;
|
45086 |
|
45087 | if (!context.initialized) {
|
45088 | context.initialized = self.initializeMakeSpace(event, context);
|
45089 | }
|
45090 | });
|
45091 |
|
45092 |
|
45093 | eventBus.on('spaceTool.end', function(event) {
|
45094 |
|
45095 | var context = event.context,
|
45096 | axis = context.axis,
|
45097 | direction = context.direction,
|
45098 | movingShapes = context.movingShapes,
|
45099 | resizingShapes = context.resizingShapes;
|
45100 |
|
45101 |
|
45102 | if (!context.initialized) {
|
45103 | return;
|
45104 | }
|
45105 |
|
45106 | var delta = { x: round$7(event.dx), y: round$7(event.dy) };
|
45107 | delta[ AXIS_INVERTED[ axis ] ] = 0;
|
45108 |
|
45109 | var insideBounds = true;
|
45110 |
|
45111 |
|
45112 |
|
45113 | forEach(resizingShapes, function(shape) {
|
45114 |
|
45115 | if ((direction === 'w' && event.x > shape.x + shape.width) ||
|
45116 | (direction === 'e' && event.x < shape.x) ||
|
45117 | (direction === 'n' && event.y > shape.y + shape.height) ||
|
45118 | (direction === 's' && event.y < shape.y)) {
|
45119 |
|
45120 | insideBounds = false;
|
45121 | return;
|
45122 | }
|
45123 | });
|
45124 |
|
45125 | if (insideBounds) {
|
45126 |
|
45127 |
|
45128 | self.makeSpace(movingShapes, resizingShapes, delta, direction);
|
45129 | }
|
45130 |
|
45131 | eventBus.once('spaceTool.ended', function(event) {
|
45132 |
|
45133 |
|
45134 | self.activateSelection(event.originalEvent, true, true);
|
45135 | });
|
45136 |
|
45137 | });
|
45138 | }
|
45139 |
|
45140 | SpaceTool.$inject = [
|
45141 | 'eventBus',
|
45142 | 'dragging',
|
45143 | 'canvas',
|
45144 | 'modeling',
|
45145 | 'rules',
|
45146 | 'toolManager'
|
45147 | ];
|
45148 |
|
45149 |
|
45150 | |
45151 |
|
45152 |
|
45153 |
|
45154 |
|
45155 |
|
45156 | SpaceTool.prototype.activateSelection = function(event, autoActivate, reactivate) {
|
45157 | this._dragging.init(event, 'spaceTool.selection', {
|
45158 | trapClick: false,
|
45159 | cursor: SPACE_TOOL_CURSOR,
|
45160 | autoActivate: autoActivate,
|
45161 | data: {
|
45162 | context: {
|
45163 | reactivate: reactivate
|
45164 | }
|
45165 | }
|
45166 | });
|
45167 | };
|
45168 |
|
45169 | |
45170 |
|
45171 |
|
45172 |
|
45173 |
|
45174 | SpaceTool.prototype.activateMakeSpace = function(event) {
|
45175 | this._dragging.init(event, 'spaceTool', {
|
45176 | autoActivate: true,
|
45177 | cursor: SPACE_TOOL_CURSOR,
|
45178 | data: {
|
45179 | context: {}
|
45180 | }
|
45181 | });
|
45182 | };
|
45183 |
|
45184 | |
45185 |
|
45186 |
|
45187 |
|
45188 |
|
45189 |
|
45190 |
|
45191 |
|
45192 | SpaceTool.prototype.makeSpace = function(movingShapes, resizingShapes, delta, direction) {
|
45193 | return this._modeling.createSpace(movingShapes, resizingShapes, delta, direction);
|
45194 | };
|
45195 |
|
45196 | |
45197 |
|
45198 |
|
45199 |
|
45200 |
|
45201 |
|
45202 |
|
45203 |
|
45204 | SpaceTool.prototype.initializeMakeSpace = function(event, context) {
|
45205 |
|
45206 | var axis = abs$6(event.dx) > abs$6(event.dy) ? 'x' : 'y',
|
45207 | offset = event['d' + axis],
|
45208 |
|
45209 |
|
45210 | spacePos = event[axis] - offset;
|
45211 |
|
45212 | if (abs$6(offset) < 5) {
|
45213 | return false;
|
45214 | }
|
45215 |
|
45216 |
|
45217 | if (offset < 0) {
|
45218 | offset *= -1;
|
45219 | }
|
45220 |
|
45221 |
|
45222 |
|
45223 |
|
45224 | if (hasPrimaryModifier(event)) {
|
45225 | offset *= -1;
|
45226 | }
|
45227 |
|
45228 | var rootShape = this._canvas.getRootElement();
|
45229 |
|
45230 | var allShapes = selfAndAllChildren(rootShape, true);
|
45231 |
|
45232 | var adjustments = this.calculateAdjustments(allShapes, axis, offset, spacePos);
|
45233 |
|
45234 |
|
45235 | assign(context, adjustments, {
|
45236 | axis: axis,
|
45237 | direction: getDirection(axis, offset)
|
45238 | });
|
45239 |
|
45240 | set$1('resize-' + (axis === 'x' ? 'ew' : 'ns'));
|
45241 |
|
45242 | return true;
|
45243 | };
|
45244 |
|
45245 | /**
|
45246 | * Calculate adjustments needed when making space
|
45247 | *
|
45248 | * @param {Array<djs.model.Shape>} elements
|
45249 | * @param {String} axis
|
45250 | * @param {Number} offset
|
45251 | * @param {Number} spacePos
|
45252 | *
|
45253 | * @return {Object}
|
45254 | */
|
45255 | SpaceTool.prototype.calculateAdjustments = function(elements, axis, offset, spacePos) {
|
45256 |
|
45257 | var movingShapes = [],
|
45258 | resizingShapes = [];
|
45259 |
|
45260 | var rules = this._rules;
|
45261 |
|
45262 |
|
45263 |
|
45264 | elements.forEach(function(shape) {
|
45265 |
|
45266 | var shapeStart = shape[axis],
|
45267 | shapeEnd = shapeStart + shape[AXIS_TO_DIMENSION[axis]];
|
45268 |
|
45269 |
|
45270 | if (!shape.parent) {
|
45271 | return;
|
45272 | }
|
45273 |
|
45274 |
|
45275 | if (shape.waypoints) {
|
45276 | return;
|
45277 | }
|
45278 |
|
45279 |
|
45280 | if (offset > 0 && shapeStart > spacePos) {
|
45281 | return movingShapes.push(shape);
|
45282 | }
|
45283 |
|
45284 |
|
45285 | if (offset < 0 && shapeEnd < spacePos) {
|
45286 | return movingShapes.push(shape);
|
45287 | }
|
45288 |
|
45289 |
|
45290 | if (shapeStart < spacePos &&
|
45291 | shapeEnd > spacePos &&
|
45292 | rules.allowed('shape.resize', { shape: shape })) {
|
45293 |
|
45294 | return resizingShapes.push(shape);
|
45295 | }
|
45296 | });
|
45297 |
|
45298 | return {
|
45299 | movingShapes: movingShapes,
|
45300 | resizingShapes: resizingShapes
|
45301 | };
|
45302 | };
|
45303 |
|
45304 | SpaceTool.prototype.toggle = function() {
|
45305 | if (this.isActive()) {
|
45306 | this._dragging.cancel();
|
45307 | } else {
|
45308 | this.activateSelection();
|
45309 | }
|
45310 | };
|
45311 |
|
45312 | SpaceTool.prototype.isActive = function() {
|
45313 | var context = this._dragging.context();
|
45314 |
|
45315 | return context && /^spaceTool/.test(context.prefix);
|
45316 | };
|
45317 |
|
45318 | var MARKER_DRAGGING = 'djs-dragging',
|
45319 | MARKER_RESIZING$1 = 'djs-resizing';
|
45320 |
|
45321 | var LOW_PRIORITY$f = 250;
|
45322 |
|
45323 | var max$5 = Math.max;
|
45324 |
|
45325 |
|
45326 | |
45327 |
|
45328 |
|
45329 |
|
45330 |
|
45331 |
|
45332 |
|
45333 |
|
45334 | function SpaceToolPreview(
|
45335 | eventBus, elementRegistry, canvas,
|
45336 | styles, previewSupport) {
|
45337 |
|
45338 | function addPreviewGfx(collection, dragGroup) {
|
45339 | forEach(collection, function(element) {
|
45340 | previewSupport.addDragger(element, dragGroup);
|
45341 |
|
45342 | canvas.addMarker(element, MARKER_DRAGGING);
|
45343 | });
|
45344 | }
|
45345 |
|
45346 |
|
45347 | eventBus.on('spaceTool.selection.start', function(event) {
|
45348 | var space = canvas.getLayer('space'),
|
45349 | context = event.context;
|
45350 |
|
45351 | var orientation = {
|
45352 | x: 'M 0,-10000 L 0,10000',
|
45353 | y: 'M -10000,0 L 10000,0'
|
45354 | };
|
45355 |
|
45356 | var crosshairGroup = create('g');
|
45357 | attr$1(crosshairGroup, styles.cls('djs-crosshair-group', [ 'no-events' ]));
|
45358 |
|
45359 | append(space, crosshairGroup);
|
45360 |
|
45361 |
|
45362 | var pathX = create('path');
|
45363 | attr$1(pathX, 'd', orientation.x);
|
45364 | classes$1(pathX).add('djs-crosshair');
|
45365 |
|
45366 | append(crosshairGroup, pathX);
|
45367 |
|
45368 |
|
45369 | var pathY = create('path');
|
45370 | attr$1(pathY, 'd', orientation.y);
|
45371 | classes$1(pathY).add('djs-crosshair');
|
45372 |
|
45373 | append(crosshairGroup, pathY);
|
45374 |
|
45375 | context.crosshairGroup = crosshairGroup;
|
45376 | });
|
45377 |
|
45378 |
|
45379 | eventBus.on('spaceTool.selection.move', function(event) {
|
45380 | var crosshairGroup = event.context.crosshairGroup;
|
45381 |
|
45382 | translate(crosshairGroup, event.x, event.y);
|
45383 | });
|
45384 |
|
45385 |
|
45386 | eventBus.on('spaceTool.selection.cleanup', function(event) {
|
45387 | var context = event.context,
|
45388 | crosshairGroup = context.crosshairGroup;
|
45389 |
|
45390 | if (crosshairGroup) {
|
45391 | remove$1(crosshairGroup);
|
45392 | }
|
45393 | });
|
45394 |
|
45395 |
|
45396 | eventBus.on('spaceTool.move', LOW_PRIORITY$f, function(event) {
|
45397 |
|
45398 | var context = event.context,
|
45399 | line = context.line,
|
45400 | axis = context.axis,
|
45401 | movingShapes = context.movingShapes,
|
45402 | resizingShapes = context.resizingShapes;
|
45403 |
|
45404 | if (!context.initialized) {
|
45405 | return;
|
45406 | }
|
45407 |
|
45408 | if (!context.dragGroup) {
|
45409 | var spaceLayer = canvas.getLayer('space');
|
45410 |
|
45411 | line = create('path');
|
45412 | attr$1(line, 'd', 'M0,0 L0,0');
|
45413 | classes$1(line).add('djs-crosshair');
|
45414 |
|
45415 | append(spaceLayer, line);
|
45416 |
|
45417 | context.line = line;
|
45418 |
|
45419 | var dragGroup = create('g');
|
45420 | attr$1(dragGroup, styles.cls('djs-drag-group', [ 'no-events' ]));
|
45421 |
|
45422 | append(canvas.getDefaultLayer(), dragGroup);
|
45423 |
|
45424 |
|
45425 | addPreviewGfx(movingShapes, dragGroup);
|
45426 |
|
45427 |
|
45428 | var movingConnections = context.movingConnections = elementRegistry.filter(function(element) {
|
45429 | var sourceIsMoving = false;
|
45430 |
|
45431 | forEach(movingShapes, function(shape) {
|
45432 | forEach(shape.outgoing, function(connection) {
|
45433 | if (element === connection) {
|
45434 | sourceIsMoving = true;
|
45435 | }
|
45436 | });
|
45437 | });
|
45438 |
|
45439 | var targetIsMoving = false;
|
45440 |
|
45441 | forEach(movingShapes, function(shape) {
|
45442 | forEach(shape.incoming, function(connection) {
|
45443 | if (element === connection) {
|
45444 | targetIsMoving = true;
|
45445 | }
|
45446 | });
|
45447 | });
|
45448 |
|
45449 | var sourceIsResizing = false;
|
45450 |
|
45451 | forEach(resizingShapes, function(shape) {
|
45452 | forEach(shape.outgoing, function(connection) {
|
45453 | if (element === connection) {
|
45454 | sourceIsResizing = true;
|
45455 | }
|
45456 | });
|
45457 | });
|
45458 |
|
45459 | var targetIsResizing = false;
|
45460 |
|
45461 | forEach(resizingShapes, function(shape) {
|
45462 | forEach(shape.incoming, function(connection) {
|
45463 | if (element === connection) {
|
45464 | targetIsResizing = true;
|
45465 | }
|
45466 | });
|
45467 | });
|
45468 |
|
45469 | return isConnection$4(element)
|
45470 | && (sourceIsMoving || sourceIsResizing)
|
45471 | && (targetIsMoving || targetIsResizing);
|
45472 | });
|
45473 |
|
45474 |
|
45475 | addPreviewGfx(movingConnections, dragGroup);
|
45476 |
|
45477 | context.dragGroup = dragGroup;
|
45478 | }
|
45479 |
|
45480 | if (!context.frameGroup) {
|
45481 | var frameGroup = create('g');
|
45482 | attr$1(frameGroup, styles.cls('djs-frame-group', [ 'no-events' ]));
|
45483 |
|
45484 | append(canvas.getDefaultLayer(), frameGroup);
|
45485 |
|
45486 | var frames = [];
|
45487 |
|
45488 | forEach(resizingShapes, function(shape) {
|
45489 | var frame = previewSupport.addFrame(shape, frameGroup);
|
45490 |
|
45491 | var initialBounds = frame.getBBox();
|
45492 |
|
45493 | frames.push({
|
45494 | element: frame,
|
45495 | initialBounds: initialBounds
|
45496 | });
|
45497 |
|
45498 | canvas.addMarker(shape, MARKER_RESIZING$1);
|
45499 | });
|
45500 |
|
45501 | context.frameGroup = frameGroup;
|
45502 | context.frames = frames;
|
45503 | }
|
45504 |
|
45505 | var orientation = {
|
45506 | x: 'M' + event.x + ', -10000 L' + event.x + ', 10000',
|
45507 | y: 'M -10000, ' + event.y + ' L 10000, ' + event.y
|
45508 | };
|
45509 |
|
45510 | attr$1(line, { path: orientation[ axis ], display: '' });
|
45511 |
|
45512 | var opposite = { x: 'y', y: 'x' };
|
45513 | var delta = { x: event.dx, y: event.dy };
|
45514 | delta[ opposite[ context.axis ] ] = 0;
|
45515 |
|
45516 |
|
45517 | translate(context.dragGroup, delta.x, delta.y);
|
45518 |
|
45519 |
|
45520 | forEach(context.frames, function(frame) {
|
45521 | var element = frame.element,
|
45522 | initialBounds = frame.initialBounds,
|
45523 | width,
|
45524 | height;
|
45525 |
|
45526 | if (context.direction === 'e') {
|
45527 | attr$1(element, {
|
45528 | width: max$5(initialBounds.width + delta.x, 5)
|
45529 | });
|
45530 | } else {
|
45531 | width = max$5(initialBounds.width - delta.x, 5);
|
45532 |
|
45533 | attr$1(element, {
|
45534 | width: width,
|
45535 | x: initialBounds.x + initialBounds.width - width
|
45536 | });
|
45537 | }
|
45538 |
|
45539 | if (context.direction === 's') {
|
45540 | attr$1(element, {
|
45541 | height: max$5(initialBounds.height + delta.y, 5)
|
45542 | });
|
45543 | } else {
|
45544 | height = max$5(initialBounds.height - delta.y, 5);
|
45545 |
|
45546 | attr$1(element, {
|
45547 | height: height,
|
45548 | y: initialBounds.y + initialBounds.height - height
|
45549 | });
|
45550 | }
|
45551 | });
|
45552 |
|
45553 | });
|
45554 |
|
45555 |
|
45556 | eventBus.on('spaceTool.cleanup', function(event) {
|
45557 |
|
45558 | var context = event.context,
|
45559 | movingShapes = context.movingShapes,
|
45560 | movingConnections = context.movingConnections,
|
45561 | resizingShapes = context.resizingShapes,
|
45562 | line = context.line,
|
45563 | dragGroup = context.dragGroup,
|
45564 | frameGroup = context.frameGroup;
|
45565 |
|
45566 |
|
45567 | forEach(movingShapes, function(shape) {
|
45568 | canvas.removeMarker(shape, MARKER_DRAGGING);
|
45569 | });
|
45570 |
|
45571 |
|
45572 | forEach(movingConnections, function(connection) {
|
45573 | canvas.removeMarker(connection, MARKER_DRAGGING);
|
45574 | });
|
45575 |
|
45576 | if (dragGroup) {
|
45577 | remove$1(line);
|
45578 | remove$1(dragGroup);
|
45579 | }
|
45580 |
|
45581 | forEach(resizingShapes, function(shape) {
|
45582 | canvas.removeMarker(shape, MARKER_RESIZING$1);
|
45583 | });
|
45584 |
|
45585 | if (frameGroup) {
|
45586 | remove$1(frameGroup);
|
45587 | }
|
45588 | });
|
45589 | }
|
45590 |
|
45591 | SpaceToolPreview.$inject = [
|
45592 | 'eventBus',
|
45593 | 'elementRegistry',
|
45594 | 'canvas',
|
45595 | 'styles',
|
45596 | 'previewSupport'
|
45597 | ];
|
45598 |
|
45599 |
|
45600 |
|
45601 |
|
45602 | |
45603 |
|
45604 |
|
45605 | function isConnection$4(element) {
|
45606 | return element.waypoints;
|
45607 | }
|
45608 |
|
45609 | var SpaceToolModule = {
|
45610 | __init__: ['spaceToolPreview'],
|
45611 | __depends__: [
|
45612 | DraggingModule,
|
45613 | RulesModule,
|
45614 | ToolManagerModule,
|
45615 | PreviewSupportModule
|
45616 | ],
|
45617 | spaceTool: ['type', SpaceTool ],
|
45618 | spaceToolPreview: ['type', SpaceToolPreview ]
|
45619 | };
|
45620 |
|
45621 | function BpmnFactory(moddle) {
|
45622 | this._model = moddle;
|
45623 | }
|
45624 |
|
45625 | BpmnFactory.$inject = [ 'moddle' ];
|
45626 |
|
45627 |
|
45628 | BpmnFactory.prototype._needsId = function(element) {
|
45629 | return isAny(element, [
|
45630 | 'bpmn:RootElement',
|
45631 | 'bpmn:FlowElement',
|
45632 | 'bpmn:MessageFlow',
|
45633 | 'bpmn:DataAssociation',
|
45634 | 'bpmn:Artifact',
|
45635 | 'bpmn:Participant',
|
45636 | 'bpmn:Lane',
|
45637 | 'bpmn:LaneSet',
|
45638 | 'bpmn:Process',
|
45639 | 'bpmn:Collaboration',
|
45640 | 'bpmndi:BPMNShape',
|
45641 | 'bpmndi:BPMNEdge',
|
45642 | 'bpmndi:BPMNDiagram',
|
45643 | 'bpmndi:BPMNPlane',
|
45644 | 'bpmn:Property',
|
45645 | 'bpmn:CategoryValue'
|
45646 | ]);
|
45647 | };
|
45648 |
|
45649 | BpmnFactory.prototype._ensureId = function(element) {
|
45650 |
|
45651 |
|
45652 |
|
45653 | var prefix = (element.$type || '').replace(/^[^:]*:/g, '') + '_';
|
45654 |
|
45655 | if (!element.id && this._needsId(element)) {
|
45656 | element.id = this._model.ids.nextPrefixed(prefix, element);
|
45657 | }
|
45658 | };
|
45659 |
|
45660 |
|
45661 | BpmnFactory.prototype.create = function(type, attrs) {
|
45662 | var element = this._model.create(type, attrs || {});
|
45663 |
|
45664 | this._ensureId(element);
|
45665 |
|
45666 | return element;
|
45667 | };
|
45668 |
|
45669 |
|
45670 | BpmnFactory.prototype.createDiLabel = function() {
|
45671 | return this.create('bpmndi:BPMNLabel', {
|
45672 | bounds: this.createDiBounds()
|
45673 | });
|
45674 | };
|
45675 |
|
45676 |
|
45677 | BpmnFactory.prototype.createDiShape = function(semantic, bounds, attrs) {
|
45678 |
|
45679 | return this.create('bpmndi:BPMNShape', assign({
|
45680 | bpmnElement: semantic,
|
45681 | bounds: this.createDiBounds(bounds)
|
45682 | }, attrs));
|
45683 | };
|
45684 |
|
45685 |
|
45686 | BpmnFactory.prototype.createDiBounds = function(bounds) {
|
45687 | return this.create('dc:Bounds', bounds);
|
45688 | };
|
45689 |
|
45690 |
|
45691 | BpmnFactory.prototype.createDiWaypoints = function(waypoints) {
|
45692 | var self = this;
|
45693 |
|
45694 | return map(waypoints, function(pos) {
|
45695 | return self.createDiWaypoint(pos);
|
45696 | });
|
45697 | };
|
45698 |
|
45699 | BpmnFactory.prototype.createDiWaypoint = function(point) {
|
45700 | return this.create('dc:Point', pick(point, [ 'x', 'y' ]));
|
45701 | };
|
45702 |
|
45703 |
|
45704 | BpmnFactory.prototype.createDiEdge = function(semantic, waypoints, attrs) {
|
45705 | return this.create('bpmndi:BPMNEdge', assign({
|
45706 | bpmnElement: semantic
|
45707 | }, attrs));
|
45708 | };
|
45709 |
|
45710 | BpmnFactory.prototype.createDiPlane = function(semantic) {
|
45711 | return this.create('bpmndi:BPMNPlane', {
|
45712 | bpmnElement: semantic
|
45713 | });
|
45714 | };
|
45715 |
|
45716 | |
45717 |
|
45718 |
|
45719 |
|
45720 | function BpmnUpdater(
|
45721 | eventBus, bpmnFactory, connectionDocking,
|
45722 | translate) {
|
45723 |
|
45724 | CommandInterceptor.call(this, eventBus);
|
45725 |
|
45726 | this._bpmnFactory = bpmnFactory;
|
45727 | this._translate = translate;
|
45728 |
|
45729 | var self = this;
|
45730 |
|
45731 |
|
45732 |
|
45733 |
|
45734 |
|
45735 |
|
45736 | function cropConnection(e) {
|
45737 | var context = e.context,
|
45738 | connection;
|
45739 |
|
45740 | if (!context.cropped) {
|
45741 | connection = context.connection;
|
45742 | connection.waypoints = connectionDocking.getCroppedWaypoints(connection);
|
45743 | context.cropped = true;
|
45744 | }
|
45745 | }
|
45746 |
|
45747 | this.executed([
|
45748 | 'connection.layout',
|
45749 | 'connection.create'
|
45750 | ], cropConnection);
|
45751 |
|
45752 | this.reverted([ 'connection.layout' ], function(e) {
|
45753 | delete e.context.cropped;
|
45754 | });
|
45755 |
|
45756 |
|
45757 |
|
45758 |
|
45759 |
|
45760 |
|
45761 |
|
45762 | function updateParent(e) {
|
45763 | var context = e.context;
|
45764 |
|
45765 | self.updateParent(context.shape || context.connection, context.oldParent);
|
45766 | }
|
45767 |
|
45768 | function reverseUpdateParent(e) {
|
45769 | var context = e.context;
|
45770 |
|
45771 | var element = context.shape || context.connection,
|
45772 |
|
45773 |
|
45774 | oldParent = context.parent || context.newParent;
|
45775 |
|
45776 | self.updateParent(element, oldParent);
|
45777 | }
|
45778 |
|
45779 | this.executed([
|
45780 | 'shape.move',
|
45781 | 'shape.create',
|
45782 | 'shape.delete',
|
45783 | 'connection.create',
|
45784 | 'connection.move',
|
45785 | 'connection.delete'
|
45786 | ], ifBpmn(updateParent));
|
45787 |
|
45788 | this.reverted([
|
45789 | 'shape.move',
|
45790 | 'shape.create',
|
45791 | 'shape.delete',
|
45792 | 'connection.create',
|
45793 | 'connection.move',
|
45794 | 'connection.delete'
|
45795 | ], ifBpmn(reverseUpdateParent));
|
45796 |
|
45797 | |
45798 |
|
45799 |
|
45800 |
|
45801 |
|
45802 |
|
45803 |
|
45804 |
|
45805 | function updateRoot(event) {
|
45806 | var context = event.context,
|
45807 | oldRoot = context.oldRoot,
|
45808 | children = oldRoot.children;
|
45809 |
|
45810 | forEach(children, function(child) {
|
45811 | if (is$1(child, 'bpmn:BaseElement')) {
|
45812 | self.updateParent(child);
|
45813 | }
|
45814 | });
|
45815 | }
|
45816 |
|
45817 | this.executed([ 'canvas.updateRoot' ], updateRoot);
|
45818 | this.reverted([ 'canvas.updateRoot' ], updateRoot);
|
45819 |
|
45820 |
|
45821 |
|
45822 | function updateBounds(e) {
|
45823 | var shape = e.context.shape;
|
45824 |
|
45825 | if (!is$1(shape, 'bpmn:BaseElement')) {
|
45826 | return;
|
45827 | }
|
45828 |
|
45829 | self.updateBounds(shape);
|
45830 | }
|
45831 |
|
45832 | this.executed([ 'shape.move', 'shape.create', 'shape.resize' ], ifBpmn(function(event) {
|
45833 |
|
45834 |
|
45835 | if (event.context.shape.type === 'label') {
|
45836 | return;
|
45837 | }
|
45838 |
|
45839 | updateBounds(event);
|
45840 | }));
|
45841 |
|
45842 | this.reverted([ 'shape.move', 'shape.create', 'shape.resize' ], ifBpmn(function(event) {
|
45843 |
|
45844 |
|
45845 | if (event.context.shape.type === 'label') {
|
45846 | return;
|
45847 | }
|
45848 |
|
45849 | updateBounds(event);
|
45850 | }));
|
45851 |
|
45852 |
|
45853 |
|
45854 | eventBus.on('shape.changed', function(event) {
|
45855 | if (event.element.type === 'label') {
|
45856 | updateBounds({ context: { shape: event.element } });
|
45857 | }
|
45858 | });
|
45859 |
|
45860 |
|
45861 | function updateConnection(e) {
|
45862 | self.updateConnection(e.context);
|
45863 | }
|
45864 |
|
45865 | this.executed([
|
45866 | 'connection.create',
|
45867 | 'connection.move',
|
45868 | 'connection.delete',
|
45869 | 'connection.reconnectEnd',
|
45870 | 'connection.reconnectStart'
|
45871 | ], ifBpmn(updateConnection));
|
45872 |
|
45873 | this.reverted([
|
45874 | 'connection.create',
|
45875 | 'connection.move',
|
45876 | 'connection.delete',
|
45877 | 'connection.reconnectEnd',
|
45878 | 'connection.reconnectStart'
|
45879 | ], ifBpmn(updateConnection));
|
45880 |
|
45881 |
|
45882 |
|
45883 | function updateConnectionWaypoints(e) {
|
45884 | self.updateConnectionWaypoints(e.context.connection);
|
45885 | }
|
45886 |
|
45887 | this.executed([
|
45888 | 'connection.layout',
|
45889 | 'connection.move',
|
45890 | 'connection.updateWaypoints',
|
45891 | ], ifBpmn(updateConnectionWaypoints));
|
45892 |
|
45893 | this.reverted([
|
45894 | 'connection.layout',
|
45895 | 'connection.move',
|
45896 | 'connection.updateWaypoints',
|
45897 | ], ifBpmn(updateConnectionWaypoints));
|
45898 |
|
45899 |
|
45900 |
|
45901 | this.executed([
|
45902 | 'connection.reconnectEnd',
|
45903 | 'connection.reconnectStart'
|
45904 | ], ifBpmn(function(e) {
|
45905 | var context = e.context,
|
45906 | connection = context.connection,
|
45907 | businessObject = getBusinessObject(connection),
|
45908 | oldSource = getBusinessObject(context.oldSource),
|
45909 | oldTarget = getBusinessObject(context.oldTarget),
|
45910 | newSource = getBusinessObject(connection.source),
|
45911 | newTarget = getBusinessObject(connection.target);
|
45912 |
|
45913 | if (oldSource === newSource || oldTarget === newTarget) {
|
45914 | return;
|
45915 | }
|
45916 |
|
45917 |
|
45918 | if (oldSource && oldSource.default === businessObject) {
|
45919 | context.default = oldSource.default;
|
45920 | oldSource.default = undefined;
|
45921 | }
|
45922 |
|
45923 |
|
45924 | if ((businessObject.sourceRef && businessObject.sourceRef.default) &&
|
45925 | !(is$1(newTarget, 'bpmn:Activity') ||
|
45926 | is$1(newTarget, 'bpmn:EndEvent') ||
|
45927 | is$1(newTarget, 'bpmn:Gateway') ||
|
45928 | is$1(newTarget, 'bpmn:IntermediateThrowEvent'))) {
|
45929 | context.default = businessObject.sourceRef.default;
|
45930 | businessObject.sourceRef.default = undefined;
|
45931 | }
|
45932 |
|
45933 |
|
45934 | if (oldSource && (businessObject.conditionExpression) &&
|
45935 | !(is$1(newSource, 'bpmn:Activity') ||
|
45936 | is$1(newSource, 'bpmn:Gateway'))) {
|
45937 | context.conditionExpression = businessObject.conditionExpression;
|
45938 | businessObject.conditionExpression = undefined;
|
45939 | }
|
45940 |
|
45941 |
|
45942 | if (oldTarget && (businessObject.conditionExpression) &&
|
45943 | !(is$1(newTarget, 'bpmn:Activity') ||
|
45944 | is$1(newTarget, 'bpmn:EndEvent') ||
|
45945 | is$1(newTarget, 'bpmn:Gateway') ||
|
45946 | is$1(newTarget, 'bpmn:IntermediateThrowEvent'))) {
|
45947 | context.conditionExpression = businessObject.conditionExpression;
|
45948 | businessObject.conditionExpression = undefined;
|
45949 | }
|
45950 | }));
|
45951 |
|
45952 | this.reverted([
|
45953 | 'connection.reconnectEnd',
|
45954 | 'connection.reconnectStart'
|
45955 | ], ifBpmn(function(e) {
|
45956 | var context = e.context,
|
45957 | connection = context.connection,
|
45958 | businessObject = getBusinessObject(connection),
|
45959 | newSource = getBusinessObject(connection.source);
|
45960 |
|
45961 |
|
45962 | if (context.default) {
|
45963 | if (is$1(newSource, 'bpmn:ExclusiveGateway') || is$1(newSource, 'bpmn:InclusiveGateway') ||
|
45964 | is$1(newSource, 'bpmn:Activity')) {
|
45965 | newSource.default = context.default;
|
45966 | }
|
45967 | }
|
45968 |
|
45969 |
|
45970 | if (context.conditionExpression && is$1(newSource, 'bpmn:Activity')) {
|
45971 | businessObject.conditionExpression = context.conditionExpression;
|
45972 | }
|
45973 | }));
|
45974 |
|
45975 |
|
45976 | function updateAttachment(e) {
|
45977 | self.updateAttachment(e.context);
|
45978 | }
|
45979 |
|
45980 | this.executed([ 'element.updateAttachment' ], ifBpmn(updateAttachment));
|
45981 | this.reverted([ 'element.updateAttachment' ], ifBpmn(updateAttachment));
|
45982 | }
|
45983 |
|
45984 | inherits_browser(BpmnUpdater, CommandInterceptor);
|
45985 |
|
45986 | BpmnUpdater.$inject = [
|
45987 | 'eventBus',
|
45988 | 'bpmnFactory',
|
45989 | 'connectionDocking',
|
45990 | 'translate'
|
45991 | ];
|
45992 |
|
45993 |
|
45994 |
|
45995 |
|
45996 | BpmnUpdater.prototype.updateAttachment = function(context) {
|
45997 |
|
45998 | var shape = context.shape,
|
45999 | businessObject = shape.businessObject,
|
46000 | host = shape.host;
|
46001 |
|
46002 | businessObject.attachedToRef = host && host.businessObject;
|
46003 | };
|
46004 |
|
46005 | BpmnUpdater.prototype.updateParent = function(element, oldParent) {
|
46006 |
|
46007 |
|
46008 | if (element instanceof Label) {
|
46009 | return;
|
46010 | }
|
46011 |
|
46012 |
|
46013 | if (is$1(element, 'bpmn:DataStoreReference') &&
|
46014 | element.parent &&
|
46015 | is$1(element.parent, 'bpmn:Collaboration')) {
|
46016 | return;
|
46017 | }
|
46018 |
|
46019 | var parentShape = element.parent;
|
46020 |
|
46021 | var businessObject = element.businessObject,
|
46022 | parentBusinessObject = parentShape && parentShape.businessObject,
|
46023 | parentDi = parentBusinessObject && parentBusinessObject.di;
|
46024 |
|
46025 | if (is$1(element, 'bpmn:FlowNode')) {
|
46026 | this.updateFlowNodeRefs(businessObject, parentBusinessObject, oldParent && oldParent.businessObject);
|
46027 | }
|
46028 |
|
46029 | if (is$1(element, 'bpmn:DataOutputAssociation')) {
|
46030 | if (element.source) {
|
46031 | parentBusinessObject = element.source.businessObject;
|
46032 | } else {
|
46033 | parentBusinessObject = null;
|
46034 | }
|
46035 | }
|
46036 |
|
46037 | if (is$1(element, 'bpmn:DataInputAssociation')) {
|
46038 | if (element.target) {
|
46039 | parentBusinessObject = element.target.businessObject;
|
46040 | } else {
|
46041 | parentBusinessObject = null;
|
46042 | }
|
46043 | }
|
46044 |
|
46045 | this.updateSemanticParent(businessObject, parentBusinessObject);
|
46046 |
|
46047 | if (is$1(element, 'bpmn:DataObjectReference') && businessObject.dataObjectRef) {
|
46048 | this.updateSemanticParent(businessObject.dataObjectRef, parentBusinessObject);
|
46049 | }
|
46050 |
|
46051 | this.updateDiParent(businessObject.di, parentDi);
|
46052 | };
|
46053 |
|
46054 |
|
46055 | BpmnUpdater.prototype.updateBounds = function(shape) {
|
46056 |
|
46057 | var di = shape.businessObject.di;
|
46058 |
|
46059 | var target = (shape instanceof Label) ? this._getLabel(di) : di;
|
46060 |
|
46061 | var bounds = target.bounds;
|
46062 |
|
46063 | if (!bounds) {
|
46064 | bounds = this._bpmnFactory.createDiBounds();
|
46065 | target.set('bounds', bounds);
|
46066 | }
|
46067 |
|
46068 | assign(bounds, {
|
46069 | x: shape.x,
|
46070 | y: shape.y,
|
46071 | width: shape.width,
|
46072 | height: shape.height
|
46073 | });
|
46074 | };
|
46075 |
|
46076 | BpmnUpdater.prototype.updateFlowNodeRefs = function(businessObject, newContainment, oldContainment) {
|
46077 |
|
46078 | if (oldContainment === newContainment) {
|
46079 | return;
|
46080 | }
|
46081 |
|
46082 | var oldRefs, newRefs;
|
46083 |
|
46084 | if (is$1 (oldContainment, 'bpmn:Lane')) {
|
46085 | oldRefs = oldContainment.get('flowNodeRef');
|
46086 | remove$2(oldRefs, businessObject);
|
46087 | }
|
46088 |
|
46089 | if (is$1(newContainment, 'bpmn:Lane')) {
|
46090 | newRefs = newContainment.get('flowNodeRef');
|
46091 | add$1(newRefs, businessObject);
|
46092 | }
|
46093 | };
|
46094 |
|
46095 |
|
46096 |
|
46097 | BpmnUpdater.prototype.updateDiConnection = function(di, newSource, newTarget) {
|
46098 |
|
46099 | if (di.sourceElement && di.sourceElement.bpmnElement !== newSource) {
|
46100 | di.sourceElement = newSource && newSource.di;
|
46101 | }
|
46102 |
|
46103 | if (di.targetElement && di.targetElement.bpmnElement !== newTarget) {
|
46104 | di.targetElement = newTarget && newTarget.di;
|
46105 | }
|
46106 |
|
46107 | };
|
46108 |
|
46109 |
|
46110 | BpmnUpdater.prototype.updateDiParent = function(di, parentDi) {
|
46111 |
|
46112 | if (parentDi && !is$1(parentDi, 'bpmndi:BPMNPlane')) {
|
46113 | parentDi = parentDi.$parent;
|
46114 | }
|
46115 |
|
46116 | if (di.$parent === parentDi) {
|
46117 | return;
|
46118 | }
|
46119 |
|
46120 | var planeElements = (parentDi || di.$parent).get('planeElement');
|
46121 |
|
46122 | if (parentDi) {
|
46123 | planeElements.push(di);
|
46124 | di.$parent = parentDi;
|
46125 | } else {
|
46126 | remove$2(planeElements, di);
|
46127 | di.$parent = null;
|
46128 | }
|
46129 | };
|
46130 |
|
46131 | function getDefinitions(element) {
|
46132 | while (element && !is$1(element, 'bpmn:Definitions')) {
|
46133 | element = element.$parent;
|
46134 | }
|
46135 |
|
46136 | return element;
|
46137 | }
|
46138 |
|
46139 | BpmnUpdater.prototype.getLaneSet = function(container) {
|
46140 |
|
46141 | var laneSet, laneSets;
|
46142 |
|
46143 |
|
46144 | if (is$1(container, 'bpmn:Lane')) {
|
46145 | laneSet = container.childLaneSet;
|
46146 |
|
46147 | if (!laneSet) {
|
46148 | laneSet = this._bpmnFactory.create('bpmn:LaneSet');
|
46149 | container.childLaneSet = laneSet;
|
46150 | laneSet.$parent = container;
|
46151 | }
|
46152 |
|
46153 | return laneSet;
|
46154 | }
|
46155 |
|
46156 |
|
46157 | if (is$1(container, 'bpmn:Participant')) {
|
46158 | container = container.processRef;
|
46159 | }
|
46160 |
|
46161 |
|
46162 | laneSets = container.get('laneSets');
|
46163 | laneSet = laneSets[0];
|
46164 |
|
46165 | if (!laneSet) {
|
46166 | laneSet = this._bpmnFactory.create('bpmn:LaneSet');
|
46167 | laneSet.$parent = container;
|
46168 | laneSets.push(laneSet);
|
46169 | }
|
46170 |
|
46171 | return laneSet;
|
46172 | };
|
46173 |
|
46174 | BpmnUpdater.prototype.updateSemanticParent = function(businessObject, newParent, visualParent) {
|
46175 |
|
46176 | var containment,
|
46177 | translate = this._translate;
|
46178 |
|
46179 | if (businessObject.$parent === newParent) {
|
46180 | return;
|
46181 | }
|
46182 |
|
46183 | if (is$1(businessObject, 'bpmn:DataInput') || is$1(businessObject, 'bpmn:DataOutput')) {
|
46184 |
|
46185 | if (is$1(newParent, 'bpmn:Participant') && 'processRef' in newParent) {
|
46186 | newParent = newParent.processRef;
|
46187 | }
|
46188 |
|
46189 |
|
46190 | if ('ioSpecification' in newParent && newParent.ioSpecification === businessObject.$parent) {
|
46191 | return;
|
46192 | }
|
46193 | }
|
46194 |
|
46195 | if (is$1(businessObject, 'bpmn:Lane')) {
|
46196 |
|
46197 | if (newParent) {
|
46198 | newParent = this.getLaneSet(newParent);
|
46199 | }
|
46200 |
|
46201 | containment = 'lanes';
|
46202 | } else
|
46203 |
|
46204 | if (is$1(businessObject, 'bpmn:FlowElement')) {
|
46205 |
|
46206 | if (newParent) {
|
46207 |
|
46208 | if (is$1(newParent, 'bpmn:Participant')) {
|
46209 | newParent = newParent.processRef;
|
46210 | } else
|
46211 |
|
46212 | if (is$1(newParent, 'bpmn:Lane')) {
|
46213 | do {
|
46214 |
|
46215 |
|
46216 | newParent = newParent.$parent.$parent;
|
46217 | } while (is$1(newParent, 'bpmn:Lane'));
|
46218 |
|
46219 | }
|
46220 | }
|
46221 |
|
46222 | containment = 'flowElements';
|
46223 |
|
46224 | } else
|
46225 |
|
46226 | if (is$1(businessObject, 'bpmn:Artifact')) {
|
46227 |
|
46228 | while (newParent &&
|
46229 | !is$1(newParent, 'bpmn:Process') &&
|
46230 | !is$1(newParent, 'bpmn:SubProcess') &&
|
46231 | !is$1(newParent, 'bpmn:Collaboration')) {
|
46232 |
|
46233 | if (is$1(newParent, 'bpmn:Participant')) {
|
46234 | newParent = newParent.processRef;
|
46235 | break;
|
46236 | } else {
|
46237 | newParent = newParent.$parent;
|
46238 | }
|
46239 | }
|
46240 |
|
46241 | containment = 'artifacts';
|
46242 | } else
|
46243 |
|
46244 | if (is$1(businessObject, 'bpmn:MessageFlow')) {
|
46245 | containment = 'messageFlows';
|
46246 |
|
46247 | } else
|
46248 |
|
46249 | if (is$1(businessObject, 'bpmn:Participant')) {
|
46250 | containment = 'participants';
|
46251 |
|
46252 |
|
46253 |
|
46254 |
|
46255 | var process = businessObject.processRef,
|
46256 | definitions;
|
46257 |
|
46258 | if (process) {
|
46259 | definitions = getDefinitions(businessObject.$parent || newParent);
|
46260 |
|
46261 | if (businessObject.$parent) {
|
46262 | remove$2(definitions.get('rootElements'), process);
|
46263 | process.$parent = null;
|
46264 | }
|
46265 |
|
46266 | if (newParent) {
|
46267 | add$1(definitions.get('rootElements'), process);
|
46268 | process.$parent = definitions;
|
46269 | }
|
46270 | }
|
46271 | } else
|
46272 |
|
46273 | if (is$1(businessObject, 'bpmn:DataOutputAssociation')) {
|
46274 | containment = 'dataOutputAssociations';
|
46275 | } else
|
46276 |
|
46277 | if (is$1(businessObject, 'bpmn:DataInputAssociation')) {
|
46278 | containment = 'dataInputAssociations';
|
46279 | }
|
46280 |
|
46281 | if (!containment) {
|
46282 | throw new Error(translate(
|
46283 | 'no parent for {element} in {parent}',
|
46284 | {
|
46285 | element: businessObject.id,
|
46286 | parent: newParent.id
|
46287 | }
|
46288 | ));
|
46289 | }
|
46290 |
|
46291 | var children;
|
46292 |
|
46293 | if (businessObject.$parent) {
|
46294 |
|
46295 |
|
46296 | children = businessObject.$parent.get(containment);
|
46297 | remove$2(children, businessObject);
|
46298 | }
|
46299 |
|
46300 | if (!newParent) {
|
46301 | businessObject.$parent = null;
|
46302 | } else {
|
46303 |
|
46304 |
|
46305 | children = newParent.get(containment);
|
46306 | children.push(businessObject);
|
46307 | businessObject.$parent = newParent;
|
46308 | }
|
46309 |
|
46310 | if (visualParent) {
|
46311 | var diChildren = visualParent.get(containment);
|
46312 |
|
46313 | remove$2(children, businessObject);
|
46314 |
|
46315 | if (newParent) {
|
46316 |
|
46317 | if (!diChildren) {
|
46318 | diChildren = [];
|
46319 | newParent.set(containment, diChildren);
|
46320 | }
|
46321 |
|
46322 | diChildren.push(businessObject);
|
46323 | }
|
46324 | }
|
46325 | };
|
46326 |
|
46327 |
|
46328 | BpmnUpdater.prototype.updateConnectionWaypoints = function(connection) {
|
46329 | connection.businessObject.di.set('waypoint', this._bpmnFactory.createDiWaypoints(connection.waypoints));
|
46330 | };
|
46331 |
|
46332 |
|
46333 | BpmnUpdater.prototype.updateConnection = function(context) {
|
46334 |
|
46335 | var connection = context.connection,
|
46336 | businessObject = getBusinessObject(connection),
|
46337 | newSource = getBusinessObject(connection.source),
|
46338 | newTarget = getBusinessObject(connection.target),
|
46339 | visualParent;
|
46340 |
|
46341 | if (!is$1(businessObject, 'bpmn:DataAssociation')) {
|
46342 |
|
46343 | var inverseSet = is$1(businessObject, 'bpmn:SequenceFlow');
|
46344 |
|
46345 | if (businessObject.sourceRef !== newSource) {
|
46346 | if (inverseSet) {
|
46347 | remove$2(businessObject.sourceRef && businessObject.sourceRef.get('outgoing'), businessObject);
|
46348 |
|
46349 | if (newSource && newSource.get('outgoing')) {
|
46350 | newSource.get('outgoing').push(businessObject);
|
46351 | }
|
46352 | }
|
46353 |
|
46354 | businessObject.sourceRef = newSource;
|
46355 | }
|
46356 |
|
46357 | if (businessObject.targetRef !== newTarget) {
|
46358 | if (inverseSet) {
|
46359 | remove$2(businessObject.targetRef && businessObject.targetRef.get('incoming'), businessObject);
|
46360 |
|
46361 | if (newTarget && newTarget.get('incoming')) {
|
46362 | newTarget.get('incoming').push(businessObject);
|
46363 | }
|
46364 | }
|
46365 |
|
46366 | businessObject.targetRef = newTarget;
|
46367 | }
|
46368 | } else
|
46369 |
|
46370 | if (is$1(businessObject, 'bpmn:DataInputAssociation')) {
|
46371 |
|
46372 |
|
46373 | businessObject.get('sourceRef')[0] = newSource;
|
46374 |
|
46375 | visualParent = context.parent || context.newParent || newTarget;
|
46376 |
|
46377 | this.updateSemanticParent(businessObject, newTarget, visualParent);
|
46378 | } else
|
46379 |
|
46380 | if (is$1(businessObject, 'bpmn:DataOutputAssociation')) {
|
46381 | visualParent = context.parent || context.newParent || newSource;
|
46382 |
|
46383 | this.updateSemanticParent(businessObject, newSource, visualParent);
|
46384 |
|
46385 |
|
46386 | businessObject.targetRef = newTarget;
|
46387 | }
|
46388 |
|
46389 | this.updateConnectionWaypoints(connection);
|
46390 |
|
46391 | this.updateDiConnection(businessObject.di, newSource, newTarget);
|
46392 | };
|
46393 |
|
46394 |
|
46395 |
|
46396 |
|
46397 | BpmnUpdater.prototype._getLabel = function(di) {
|
46398 | if (!di.label) {
|
46399 | di.label = this._bpmnFactory.createDiLabel();
|
46400 | }
|
46401 |
|
46402 | return di.label;
|
46403 | };
|
46404 |
|
46405 |
|
46406 | |
46407 |
|
46408 |
|
46409 |
|
46410 |
|
46411 |
|
46412 |
|
46413 | function ifBpmn(fn) {
|
46414 |
|
46415 | return function(event) {
|
46416 |
|
46417 | var context = event.context,
|
46418 | element = context.shape || context.connection;
|
46419 |
|
46420 | if (is$1(element, 'bpmn:BaseElement')) {
|
46421 | fn(event);
|
46422 | }
|
46423 | };
|
46424 | }
|
46425 |
|
46426 | |
46427 |
|
46428 |
|
46429 | function ElementFactory$1(bpmnFactory, moddle, translate) {
|
46430 | ElementFactory.call(this);
|
46431 |
|
46432 | this._bpmnFactory = bpmnFactory;
|
46433 | this._moddle = moddle;
|
46434 | this._translate = translate;
|
46435 | }
|
46436 |
|
46437 | inherits_browser(ElementFactory$1, ElementFactory);
|
46438 |
|
46439 | ElementFactory$1.$inject = [
|
46440 | 'bpmnFactory',
|
46441 | 'moddle',
|
46442 | 'translate'
|
46443 | ];
|
46444 |
|
46445 | ElementFactory$1.prototype.baseCreate = ElementFactory.prototype.create;
|
46446 |
|
46447 | ElementFactory$1.prototype.create = function(elementType, attrs) {
|
46448 |
|
46449 |
|
46450 |
|
46451 |
|
46452 | if (elementType === 'label') {
|
46453 | return this.baseCreate(elementType, assign({ type: 'label' }, DEFAULT_LABEL_SIZE$1, attrs));
|
46454 | }
|
46455 |
|
46456 | return this.createBpmnElement(elementType, attrs);
|
46457 | };
|
46458 |
|
46459 | ElementFactory$1.prototype.createBpmnElement = function(elementType, attrs) {
|
46460 | var size,
|
46461 | translate = this._translate;
|
46462 |
|
46463 | attrs = attrs || {};
|
46464 |
|
46465 | var businessObject = attrs.businessObject;
|
46466 |
|
46467 | if (!businessObject) {
|
46468 | if (!attrs.type) {
|
46469 | throw new Error(translate('no shape type specified'));
|
46470 | }
|
46471 |
|
46472 | businessObject = this._bpmnFactory.create(attrs.type);
|
46473 | }
|
46474 |
|
46475 | if (!businessObject.di) {
|
46476 | if (elementType === 'root') {
|
46477 | businessObject.di = this._bpmnFactory.createDiPlane(businessObject, [], {
|
46478 | id: businessObject.id + '_di'
|
46479 | });
|
46480 | } else
|
46481 | if (elementType === 'connection') {
|
46482 | businessObject.di = this._bpmnFactory.createDiEdge(businessObject, [], {
|
46483 | id: businessObject.id + '_di'
|
46484 | });
|
46485 | } else {
|
46486 | businessObject.di = this._bpmnFactory.createDiShape(businessObject, {}, {
|
46487 | id: businessObject.id + '_di'
|
46488 | });
|
46489 | }
|
46490 | }
|
46491 |
|
46492 | if (is$1(businessObject, 'bpmn:Group')) {
|
46493 | attrs = assign({
|
46494 | isFrame: true
|
46495 | }, attrs);
|
46496 | }
|
46497 |
|
46498 | if (attrs.di) {
|
46499 | assign(businessObject.di, attrs.di);
|
46500 |
|
46501 | delete attrs.di;
|
46502 | }
|
46503 |
|
46504 | applyAttributes(businessObject, attrs, [
|
46505 | 'processRef',
|
46506 | 'isInterrupting',
|
46507 | 'associationDirection',
|
46508 | 'isForCompensation'
|
46509 | ]);
|
46510 |
|
46511 | if (attrs.isExpanded) {
|
46512 | applyAttribute(businessObject.di, attrs, 'isExpanded');
|
46513 | }
|
46514 |
|
46515 | if (is$1(businessObject, 'bpmn:ExclusiveGateway')) {
|
46516 | businessObject.di.isMarkerVisible = true;
|
46517 | }
|
46518 |
|
46519 | var eventDefinitions,
|
46520 | newEventDefinition;
|
46521 |
|
46522 | if (attrs.eventDefinitionType) {
|
46523 | eventDefinitions = businessObject.get('eventDefinitions') || [];
|
46524 | newEventDefinition = this._moddle.create(attrs.eventDefinitionType);
|
46525 |
|
46526 | if (attrs.eventDefinitionType === 'bpmn:ConditionalEventDefinition') {
|
46527 | newEventDefinition.condition = this._moddle.create('bpmn:FormalExpression');
|
46528 | }
|
46529 |
|
46530 | eventDefinitions.push(newEventDefinition);
|
46531 |
|
46532 | newEventDefinition.$parent = businessObject;
|
46533 | businessObject.eventDefinitions = eventDefinitions;
|
46534 |
|
46535 | delete attrs.eventDefinitionType;
|
46536 | }
|
46537 |
|
46538 | size = this._getDefaultSize(businessObject);
|
46539 |
|
46540 | attrs = assign({
|
46541 | businessObject: businessObject,
|
46542 | id: businessObject.id
|
46543 | }, size, attrs);
|
46544 |
|
46545 | return this.baseCreate(elementType, attrs);
|
46546 | };
|
46547 |
|
46548 |
|
46549 | ElementFactory$1.prototype._getDefaultSize = function(semantic) {
|
46550 |
|
46551 | if (is$1(semantic, 'bpmn:SubProcess')) {
|
46552 |
|
46553 | if (isExpanded(semantic)) {
|
46554 | return { width: 350, height: 200 };
|
46555 | } else {
|
46556 | return { width: 100, height: 80 };
|
46557 | }
|
46558 | }
|
46559 |
|
46560 | if (is$1(semantic, 'bpmn:Task')) {
|
46561 | return { width: 100, height: 80 };
|
46562 | }
|
46563 |
|
46564 | if (is$1(semantic, 'bpmn:Gateway')) {
|
46565 | return { width: 50, height: 50 };
|
46566 | }
|
46567 |
|
46568 | if (is$1(semantic, 'bpmn:Event')) {
|
46569 | return { width: 36, height: 36 };
|
46570 | }
|
46571 |
|
46572 | if (is$1(semantic, 'bpmn:Participant')) {
|
46573 | if (isExpanded(semantic)) {
|
46574 | return { width: 600, height: 250 };
|
46575 | } else {
|
46576 | return { width: 400, height: 60 };
|
46577 | }
|
46578 | }
|
46579 |
|
46580 | if (is$1(semantic, 'bpmn:Lane')) {
|
46581 | return { width: 400, height: 100 };
|
46582 | }
|
46583 |
|
46584 | if (is$1(semantic, 'bpmn:DataObjectReference')) {
|
46585 | return { width: 36, height: 50 };
|
46586 | }
|
46587 |
|
46588 | if (is$1(semantic, 'bpmn:DataStoreReference')) {
|
46589 | return { width: 50, height: 50 };
|
46590 | }
|
46591 |
|
46592 | if (is$1(semantic, 'bpmn:TextAnnotation')) {
|
46593 | return { width: 100, height: 30 };
|
46594 | }
|
46595 |
|
46596 | if (is$1(semantic, 'bpmn:Group')) {
|
46597 | return { width: 300, height: 300 };
|
46598 | }
|
46599 |
|
46600 | return { width: 100, height: 80 };
|
46601 | };
|
46602 |
|
46603 |
|
46604 | |
46605 |
|
46606 |
|
46607 |
|
46608 |
|
46609 |
|
46610 |
|
46611 | ElementFactory$1.prototype.createParticipantShape = function(attrs) {
|
46612 |
|
46613 | if (!isObject(attrs)) {
|
46614 | attrs = { isExpanded: attrs };
|
46615 | }
|
46616 |
|
46617 | attrs = assign({ type: 'bpmn:Participant' }, attrs || {});
|
46618 |
|
46619 |
|
46620 | if (attrs.isExpanded !== false) {
|
46621 | attrs.processRef = this._bpmnFactory.create('bpmn:Process');
|
46622 | }
|
46623 |
|
46624 | return this.createShape(attrs);
|
46625 | };
|
46626 |
|
46627 |
|
46628 |
|
46629 |
|
46630 | |
46631 |
|
46632 |
|
46633 |
|
46634 |
|
46635 |
|
46636 |
|
46637 |
|
46638 | function applyAttributes(element, attrs, attributeNames) {
|
46639 |
|
46640 | forEach(attributeNames, function(property) {
|
46641 | if (attrs[property] !== undefined) {
|
46642 | applyAttribute(element, attrs, property);
|
46643 | }
|
46644 | });
|
46645 | }
|
46646 |
|
46647 | |
46648 |
|
46649 |
|
46650 |
|
46651 |
|
46652 |
|
46653 |
|
46654 |
|
46655 | function applyAttribute(element, attrs, attributeName) {
|
46656 | element[attributeName] = attrs[attributeName];
|
46657 |
|
46658 | delete attrs[attributeName];
|
46659 | }
|
46660 |
|
46661 | |
46662 |
|
46663 |
|
46664 |
|
46665 | function AlignElements$1(modeling, canvas) {
|
46666 | this._modeling = modeling;
|
46667 | this._canvas = canvas;
|
46668 | }
|
46669 |
|
46670 | AlignElements$1.$inject = [ 'modeling', 'canvas' ];
|
46671 |
|
46672 |
|
46673 | AlignElements$1.prototype.preExecute = function(context) {
|
46674 | var modeling = this._modeling;
|
46675 |
|
46676 | var elements = context.elements,
|
46677 | alignment = context.alignment;
|
46678 |
|
46679 |
|
46680 | forEach(elements, function(element) {
|
46681 | var delta = {
|
46682 | x: 0,
|
46683 | y: 0
|
46684 | };
|
46685 |
|
46686 | if (alignment.left) {
|
46687 | delta.x = alignment.left - element.x;
|
46688 |
|
46689 | } else if (alignment.right) {
|
46690 | delta.x = (alignment.right - element.width) - element.x;
|
46691 |
|
46692 | } else if (alignment.center) {
|
46693 | delta.x = (alignment.center - Math.round(element.width / 2)) - element.x;
|
46694 |
|
46695 | } else if (alignment.top) {
|
46696 | delta.y = alignment.top - element.y;
|
46697 |
|
46698 | } else if (alignment.bottom) {
|
46699 | delta.y = (alignment.bottom - element.height) - element.y;
|
46700 |
|
46701 | } else if (alignment.middle) {
|
46702 | delta.y = (alignment.middle - Math.round(element.height / 2)) - element.y;
|
46703 | }
|
46704 |
|
46705 | modeling.moveElements([ element ], delta, element.parent);
|
46706 | });
|
46707 | };
|
46708 |
|
46709 | AlignElements$1.prototype.postExecute = function(context) {
|
46710 |
|
46711 | };
|
46712 |
|
46713 | |
46714 |
|
46715 |
|
46716 |
|
46717 |
|
46718 |
|
46719 |
|
46720 |
|
46721 | function AppendShapeHandler(modeling) {
|
46722 | this._modeling = modeling;
|
46723 | }
|
46724 |
|
46725 | AppendShapeHandler.$inject = [ 'modeling' ];
|
46726 |
|
46727 |
|
46728 |
|
46729 |
|
46730 |
|
46731 | |
46732 |
|
46733 |
|
46734 |
|
46735 |
|
46736 |
|
46737 |
|
46738 |
|
46739 |
|
46740 | AppendShapeHandler.prototype.preExecute = function(context) {
|
46741 |
|
46742 | var source = context.source;
|
46743 |
|
46744 | if (!source) {
|
46745 | throw new Error('source required');
|
46746 | }
|
46747 |
|
46748 | var target = context.target || source.parent,
|
46749 | shape = context.shape;
|
46750 |
|
46751 | shape = context.shape =
|
46752 | this._modeling.createShape(
|
46753 | shape,
|
46754 | context.position,
|
46755 | target, { attach: context.attach });
|
46756 |
|
46757 | context.shape = shape;
|
46758 | };
|
46759 |
|
46760 | AppendShapeHandler.prototype.postExecute = function(context) {
|
46761 | var parent = context.connectionParent || context.shape.parent;
|
46762 |
|
46763 | if (!existsConnection(context.source, context.shape)) {
|
46764 |
|
46765 |
|
46766 | this._modeling.connect(context.source, context.shape, context.connection, parent);
|
46767 | }
|
46768 | };
|
46769 |
|
46770 |
|
46771 | function existsConnection(source, target) {
|
46772 | return some(source.outgoing, function(c) {
|
46773 | return c.target === target;
|
46774 | });
|
46775 | }
|
46776 |
|
46777 | function CreateConnectionHandler(canvas, layouter) {
|
46778 | this._canvas = canvas;
|
46779 | this._layouter = layouter;
|
46780 | }
|
46781 |
|
46782 | CreateConnectionHandler.$inject = [ 'canvas', 'layouter' ];
|
46783 |
|
46784 |
|
46785 |
|
46786 |
|
46787 |
|
46788 | |
46789 |
|
46790 |
|
46791 |
|
46792 |
|
46793 |
|
46794 |
|
46795 |
|
46796 | CreateConnectionHandler.prototype.execute = function(context) {
|
46797 |
|
46798 | var connection = context.connection,
|
46799 | source = context.source,
|
46800 | target = context.target,
|
46801 | parent = context.parent,
|
46802 | parentIndex = context.parentIndex,
|
46803 | hints = context.hints;
|
46804 |
|
46805 | if (!source || !target) {
|
46806 | throw new Error('source and target required');
|
46807 | }
|
46808 |
|
46809 | if (!parent) {
|
46810 | throw new Error('parent required');
|
46811 | }
|
46812 |
|
46813 | connection.source = source;
|
46814 | connection.target = target;
|
46815 |
|
46816 | if (!connection.waypoints) {
|
46817 | connection.waypoints = this._layouter.layoutConnection(connection, hints);
|
46818 | }
|
46819 |
|
46820 |
|
46821 | this._canvas.addConnection(connection, parent, parentIndex);
|
46822 |
|
46823 | return connection;
|
46824 | };
|
46825 |
|
46826 | CreateConnectionHandler.prototype.revert = function(context) {
|
46827 | var connection = context.connection;
|
46828 |
|
46829 | this._canvas.removeConnection(connection);
|
46830 |
|
46831 | connection.source = null;
|
46832 | connection.target = null;
|
46833 | };
|
46834 |
|
46835 | var round$8 = Math.round;
|
46836 |
|
46837 | function CreateElementsHandler(modeling) {
|
46838 | this._modeling = modeling;
|
46839 | }
|
46840 |
|
46841 | CreateElementsHandler.$inject = [
|
46842 | 'modeling'
|
46843 | ];
|
46844 |
|
46845 | CreateElementsHandler.prototype.preExecute = function(context) {
|
46846 | var elements = context.elements,
|
46847 | parent = context.parent,
|
46848 | parentIndex = context.parentIndex,
|
46849 | position = context.position,
|
46850 | hints = context.hints;
|
46851 |
|
46852 | var modeling = this._modeling;
|
46853 |
|
46854 |
|
46855 | forEach(elements, function(element) {
|
46856 | if (!isNumber(element.x)) {
|
46857 | element.x = 0;
|
46858 | }
|
46859 |
|
46860 | if (!isNumber(element.y)) {
|
46861 | element.y = 0;
|
46862 | }
|
46863 | });
|
46864 |
|
46865 | var bbox = getBBox(elements);
|
46866 |
|
46867 |
|
46868 | forEach(elements, function(element) {
|
46869 | if (isConnection$5(element)) {
|
46870 | element.waypoints = map(element.waypoints, function(waypoint) {
|
46871 | return {
|
46872 | x: round$8(waypoint.x - bbox.x - bbox.width / 2 + position.x),
|
46873 | y: round$8(waypoint.y - bbox.y - bbox.height / 2 + position.y)
|
46874 | };
|
46875 | });
|
46876 | }
|
46877 |
|
46878 | assign(element, {
|
46879 | x: round$8(element.x - bbox.x - bbox.width / 2 + position.x),
|
46880 | y: round$8(element.y - bbox.y - bbox.height / 2 + position.y)
|
46881 | });
|
46882 | });
|
46883 |
|
46884 | var parents = getParents(elements);
|
46885 |
|
46886 | var cache = {};
|
46887 |
|
46888 | forEach(elements, function(element) {
|
46889 | if (isConnection$5(element)) {
|
46890 | cache[ element.id ] = isNumber(parentIndex) ?
|
46891 | modeling.createConnection(
|
46892 | cache[ element.source.id ],
|
46893 | cache[ element.target.id ],
|
46894 | parentIndex,
|
46895 | element,
|
46896 | element.parent || parent,
|
46897 | hints
|
46898 | ) :
|
46899 | modeling.createConnection(
|
46900 | cache[ element.source.id ],
|
46901 | cache[ element.target.id ],
|
46902 | element,
|
46903 | element.parent || parent,
|
46904 | hints
|
46905 | );
|
46906 |
|
46907 | return;
|
46908 | }
|
46909 |
|
46910 | var createShapeHints = assign({}, hints);
|
46911 |
|
46912 | if (parents.indexOf(element) === -1) {
|
46913 | createShapeHints.autoResize = false;
|
46914 | }
|
46915 |
|
46916 | cache[ element.id ] = isNumber(parentIndex) ?
|
46917 | modeling.createShape(
|
46918 | element,
|
46919 | pick(element, [ 'x', 'y', 'width', 'height' ]),
|
46920 | element.parent || parent,
|
46921 | parentIndex,
|
46922 | createShapeHints
|
46923 | ) :
|
46924 | modeling.createShape(
|
46925 | element,
|
46926 | pick(element, [ 'x', 'y', 'width', 'height' ]),
|
46927 | element.parent || parent,
|
46928 | createShapeHints
|
46929 | );
|
46930 | });
|
46931 |
|
46932 | context.elements = values(cache);
|
46933 | };
|
46934 |
|
46935 |
|
46936 |
|
46937 | function isConnection$5(element) {
|
46938 | return !!element.waypoints;
|
46939 | }
|
46940 |
|
46941 | var round$9 = Math.round;
|
46942 |
|
46943 |
|
46944 | |
46945 |
|
46946 |
|
46947 |
|
46948 |
|
46949 | function CreateShapeHandler(canvas) {
|
46950 | this._canvas = canvas;
|
46951 | }
|
46952 |
|
46953 | CreateShapeHandler.$inject = [ 'canvas' ];
|
46954 |
|
46955 |
|
46956 |
|
46957 |
|
46958 |
|
46959 | |
46960 |
|
46961 |
|
46962 |
|
46963 |
|
46964 |
|
46965 |
|
46966 | CreateShapeHandler.prototype.execute = function(context) {
|
46967 |
|
46968 | var shape = context.shape,
|
46969 | positionOrBounds = context.position,
|
46970 | parent = context.parent,
|
46971 | parentIndex = context.parentIndex;
|
46972 |
|
46973 | if (!parent) {
|
46974 | throw new Error('parent required');
|
46975 | }
|
46976 |
|
46977 | if (!positionOrBounds) {
|
46978 | throw new Error('position required');
|
46979 | }
|
46980 |
|
46981 |
|
46982 | if (positionOrBounds.width !== undefined) {
|
46983 | assign(shape, positionOrBounds);
|
46984 | } else {
|
46985 | assign(shape, {
|
46986 | x: positionOrBounds.x - round$9(shape.width / 2),
|
46987 | y: positionOrBounds.y - round$9(shape.height / 2)
|
46988 | });
|
46989 | }
|
46990 |
|
46991 |
|
46992 | this._canvas.addShape(shape, parent, parentIndex);
|
46993 |
|
46994 | return shape;
|
46995 | };
|
46996 |
|
46997 |
|
46998 | |
46999 |
|
47000 |
|
47001 | CreateShapeHandler.prototype.revert = function(context) {
|
47002 |
|
47003 |
|
47004 | this._canvas.removeShape(context.shape);
|
47005 | };
|
47006 |
|
47007 | |
47008 |
|
47009 |
|
47010 |
|
47011 |
|
47012 | function CreateLabelHandler(canvas) {
|
47013 | CreateShapeHandler.call(this, canvas);
|
47014 | }
|
47015 |
|
47016 | inherits_browser(CreateLabelHandler, CreateShapeHandler);
|
47017 |
|
47018 | CreateLabelHandler.$inject = [ 'canvas' ];
|
47019 |
|
47020 |
|
47021 |
|
47022 |
|
47023 |
|
47024 | var originalExecute = CreateShapeHandler.prototype.execute;
|
47025 |
|
47026 | |
47027 |
|
47028 |
|
47029 |
|
47030 |
|
47031 |
|
47032 |
|
47033 |
|
47034 |
|
47035 |
|
47036 | CreateLabelHandler.prototype.execute = function(context) {
|
47037 |
|
47038 | var label = context.shape;
|
47039 |
|
47040 | ensureValidDimensions(label);
|
47041 |
|
47042 | label.labelTarget = context.labelTarget;
|
47043 |
|
47044 | return originalExecute.call(this, context);
|
47045 | };
|
47046 |
|
47047 | var originalRevert = CreateShapeHandler.prototype.revert;
|
47048 |
|
47049 | |
47050 |
|
47051 |
|
47052 | CreateLabelHandler.prototype.revert = function(context) {
|
47053 | context.shape.labelTarget = null;
|
47054 |
|
47055 | return originalRevert.call(this, context);
|
47056 | };
|
47057 |
|
47058 |
|
47059 |
|
47060 |
|
47061 | function ensureValidDimensions(label) {
|
47062 |
|
47063 |
|
47064 | [ 'width', 'height' ].forEach(function(prop) {
|
47065 | if (typeof label[prop] === 'undefined') {
|
47066 | label[prop] = 0;
|
47067 | }
|
47068 | });
|
47069 | }
|
47070 |
|
47071 | |
47072 |
|
47073 |
|
47074 | function DeleteConnectionHandler(canvas, modeling) {
|
47075 | this._canvas = canvas;
|
47076 | this._modeling = modeling;
|
47077 | }
|
47078 |
|
47079 | DeleteConnectionHandler.$inject = [
|
47080 | 'canvas',
|
47081 | 'modeling'
|
47082 | ];
|
47083 |
|
47084 |
|
47085 | DeleteConnectionHandler.prototype.execute = function(context) {
|
47086 |
|
47087 | var connection = context.connection,
|
47088 | parent = connection.parent;
|
47089 |
|
47090 | context.parent = parent;
|
47091 |
|
47092 |
|
47093 | context.parentIndex = indexOf$1(parent.children, connection);
|
47094 |
|
47095 | context.source = connection.source;
|
47096 | context.target = connection.target;
|
47097 |
|
47098 | this._canvas.removeConnection(connection);
|
47099 |
|
47100 | connection.source = null;
|
47101 | connection.target = null;
|
47102 |
|
47103 | return connection;
|
47104 | };
|
47105 |
|
47106 | |
47107 |
|
47108 |
|
47109 | DeleteConnectionHandler.prototype.revert = function(context) {
|
47110 |
|
47111 | var connection = context.connection,
|
47112 | parent = context.parent,
|
47113 | parentIndex = context.parentIndex;
|
47114 |
|
47115 | connection.source = context.source;
|
47116 | connection.target = context.target;
|
47117 |
|
47118 |
|
47119 | add$1(parent.children, connection, parentIndex);
|
47120 |
|
47121 | this._canvas.addConnection(connection, parent);
|
47122 |
|
47123 | return connection;
|
47124 | };
|
47125 |
|
47126 | function DeleteElementsHandler(modeling, elementRegistry) {
|
47127 | this._modeling = modeling;
|
47128 | this._elementRegistry = elementRegistry;
|
47129 | }
|
47130 |
|
47131 | DeleteElementsHandler.$inject = [
|
47132 | 'modeling',
|
47133 | 'elementRegistry'
|
47134 | ];
|
47135 |
|
47136 |
|
47137 | DeleteElementsHandler.prototype.postExecute = function(context) {
|
47138 |
|
47139 | var modeling = this._modeling,
|
47140 | elementRegistry = this._elementRegistry,
|
47141 | elements = context.elements;
|
47142 |
|
47143 | forEach(elements, function(element) {
|
47144 |
|
47145 |
|
47146 |
|
47147 | if (!elementRegistry.get(element.id)) {
|
47148 | return;
|
47149 | }
|
47150 |
|
47151 | if (element.waypoints) {
|
47152 | modeling.removeConnection(element);
|
47153 | } else {
|
47154 | modeling.removeShape(element);
|
47155 | }
|
47156 | });
|
47157 | };
|
47158 |
|
47159 | |
47160 |
|
47161 |
|
47162 |
|
47163 | function DeleteShapeHandler(canvas, modeling) {
|
47164 | this._canvas = canvas;
|
47165 | this._modeling = modeling;
|
47166 | }
|
47167 |
|
47168 | DeleteShapeHandler.$inject = [ 'canvas', 'modeling' ];
|
47169 |
|
47170 |
|
47171 | |
47172 |
|
47173 |
|
47174 |
|
47175 | DeleteShapeHandler.prototype.preExecute = function(context) {
|
47176 |
|
47177 | var modeling = this._modeling;
|
47178 |
|
47179 | var shape = context.shape;
|
47180 |
|
47181 |
|
47182 | saveClear(shape.incoming, function(connection) {
|
47183 |
|
47184 |
|
47185 |
|
47186 | modeling.removeConnection(connection, { nested: true });
|
47187 | });
|
47188 |
|
47189 | saveClear(shape.outgoing, function(connection) {
|
47190 | modeling.removeConnection(connection, { nested: true });
|
47191 | });
|
47192 |
|
47193 |
|
47194 | saveClear(shape.children, function(child) {
|
47195 | if (isConnection$6(child)) {
|
47196 | modeling.removeConnection(child, { nested: true });
|
47197 | } else {
|
47198 | modeling.removeShape(child, { nested: true });
|
47199 | }
|
47200 | });
|
47201 | };
|
47202 |
|
47203 | |
47204 |
|
47205 |
|
47206 | DeleteShapeHandler.prototype.execute = function(context) {
|
47207 | var canvas = this._canvas;
|
47208 |
|
47209 | var shape = context.shape,
|
47210 | oldParent = shape.parent;
|
47211 |
|
47212 | context.oldParent = oldParent;
|
47213 |
|
47214 |
|
47215 | context.oldParentIndex = indexOf$1(oldParent.children, shape);
|
47216 |
|
47217 |
|
47218 | canvas.removeShape(shape);
|
47219 |
|
47220 | return shape;
|
47221 | };
|
47222 |
|
47223 |
|
47224 | |
47225 |
|
47226 |
|
47227 | DeleteShapeHandler.prototype.revert = function(context) {
|
47228 |
|
47229 | var canvas = this._canvas;
|
47230 |
|
47231 | var shape = context.shape,
|
47232 | oldParent = context.oldParent,
|
47233 | oldParentIndex = context.oldParentIndex;
|
47234 |
|
47235 |
|
47236 | add$1(oldParent.children, shape, oldParentIndex);
|
47237 |
|
47238 | canvas.addShape(shape, oldParent);
|
47239 |
|
47240 | return shape;
|
47241 | };
|
47242 |
|
47243 | function isConnection$6(element) {
|
47244 | return element.waypoints;
|
47245 | }
|
47246 |
|
47247 | |
47248 |
|
47249 |
|
47250 | function DistributeElements$1(modeling) {
|
47251 | this._modeling = modeling;
|
47252 | }
|
47253 |
|
47254 | DistributeElements$1.$inject = [ 'modeling' ];
|
47255 |
|
47256 | var OFF_AXIS = {
|
47257 | x: 'y',
|
47258 | y: 'x'
|
47259 | };
|
47260 |
|
47261 | DistributeElements$1.prototype.preExecute = function(context) {
|
47262 | var modeling = this._modeling;
|
47263 |
|
47264 | var groups = context.groups,
|
47265 | axis = context.axis,
|
47266 | dimension = context.dimension;
|
47267 |
|
47268 | function updateRange(group, element) {
|
47269 | group.range.min = Math.min(element[axis], group.range.min);
|
47270 | group.range.max = Math.max(element[axis] + element[dimension], group.range.max);
|
47271 | }
|
47272 |
|
47273 | function center(element) {
|
47274 | return element[axis] + element[dimension] / 2;
|
47275 | }
|
47276 |
|
47277 | function lastIdx(arr) {
|
47278 | return arr.length - 1;
|
47279 | }
|
47280 |
|
47281 | function rangeDiff(range) {
|
47282 | return range.max - range.min;
|
47283 | }
|
47284 |
|
47285 | function centerElement(refCenter, element) {
|
47286 | var delta = { y: 0 };
|
47287 |
|
47288 | delta[axis] = refCenter - center(element);
|
47289 |
|
47290 | if (delta[axis]) {
|
47291 |
|
47292 | delta[OFF_AXIS[axis]] = 0;
|
47293 |
|
47294 | modeling.moveElements([ element ], delta, element.parent);
|
47295 | }
|
47296 | }
|
47297 |
|
47298 | var firstGroup = groups[0],
|
47299 | lastGroupIdx = lastIdx(groups),
|
47300 | lastGroup = groups[ lastGroupIdx ];
|
47301 |
|
47302 | var margin,
|
47303 | spaceInBetween,
|
47304 | groupsSize = 0;
|
47305 |
|
47306 | forEach(groups, function(group, idx) {
|
47307 | var sortedElements,
|
47308 | refElem,
|
47309 | refCenter;
|
47310 |
|
47311 | if (group.elements.length < 2) {
|
47312 | if (idx && idx !== groups.length - 1) {
|
47313 | updateRange(group, group.elements[0]);
|
47314 |
|
47315 | groupsSize += rangeDiff(group.range);
|
47316 | }
|
47317 | return;
|
47318 | }
|
47319 |
|
47320 | sortedElements = sortBy(group.elements, axis);
|
47321 |
|
47322 | refElem = sortedElements[0];
|
47323 |
|
47324 | if (idx === lastGroupIdx) {
|
47325 | refElem = sortedElements[lastIdx(sortedElements)];
|
47326 | }
|
47327 |
|
47328 | refCenter = center(refElem);
|
47329 |
|
47330 |
|
47331 | group.range = null;
|
47332 |
|
47333 | forEach(sortedElements, function(element) {
|
47334 |
|
47335 | centerElement(refCenter, element);
|
47336 |
|
47337 | if (group.range === null) {
|
47338 | group.range = {
|
47339 | min: element[axis],
|
47340 | max: element[axis] + element[dimension]
|
47341 | };
|
47342 |
|
47343 | return;
|
47344 | }
|
47345 |
|
47346 |
|
47347 | updateRange(group, element);
|
47348 | });
|
47349 |
|
47350 | if (idx && idx !== groups.length - 1) {
|
47351 | groupsSize += rangeDiff(group.range);
|
47352 | }
|
47353 | });
|
47354 |
|
47355 | spaceInBetween = Math.abs(lastGroup.range.min - firstGroup.range.max);
|
47356 |
|
47357 | margin = Math.round((spaceInBetween - groupsSize) / (groups.length - 1));
|
47358 |
|
47359 | if (margin < groups.length - 1) {
|
47360 | return;
|
47361 | }
|
47362 |
|
47363 | forEach(groups, function(group, groupIdx) {
|
47364 | var delta = {},
|
47365 | prevGroup;
|
47366 |
|
47367 | if (group === firstGroup || group === lastGroup) {
|
47368 | return;
|
47369 | }
|
47370 |
|
47371 | prevGroup = groups[groupIdx - 1];
|
47372 |
|
47373 | group.range.max = 0;
|
47374 |
|
47375 | forEach(group.elements, function(element, idx) {
|
47376 | delta[OFF_AXIS[axis]] = 0;
|
47377 | delta[axis] = (prevGroup.range.max - element[axis]) + margin;
|
47378 |
|
47379 | if (group.range.min !== element[axis]) {
|
47380 | delta[axis] += element[axis] - group.range.min;
|
47381 | }
|
47382 |
|
47383 | if (delta[axis]) {
|
47384 | modeling.moveElements([ element ], delta, element.parent);
|
47385 | }
|
47386 |
|
47387 | group.range.max = Math.max(element[axis] + element[dimension], idx ? group.range.max : 0);
|
47388 | });
|
47389 | });
|
47390 | };
|
47391 |
|
47392 | DistributeElements$1.prototype.postExecute = function(context) {
|
47393 |
|
47394 | };
|
47395 |
|
47396 | |
47397 |
|
47398 |
|
47399 | function LayoutConnectionHandler(layouter, canvas) {
|
47400 | this._layouter = layouter;
|
47401 | this._canvas = canvas;
|
47402 | }
|
47403 |
|
47404 | LayoutConnectionHandler.$inject = [ 'layouter', 'canvas' ];
|
47405 |
|
47406 | LayoutConnectionHandler.prototype.execute = function(context) {
|
47407 |
|
47408 | var connection = context.connection;
|
47409 |
|
47410 | var oldWaypoints = connection.waypoints;
|
47411 |
|
47412 | assign(context, {
|
47413 | oldWaypoints: oldWaypoints
|
47414 | });
|
47415 |
|
47416 | connection.waypoints = this._layouter.layoutConnection(connection, context.hints);
|
47417 |
|
47418 | return connection;
|
47419 | };
|
47420 |
|
47421 | LayoutConnectionHandler.prototype.revert = function(context) {
|
47422 |
|
47423 | var connection = context.connection;
|
47424 |
|
47425 | connection.waypoints = context.oldWaypoints;
|
47426 |
|
47427 | return connection;
|
47428 | };
|
47429 |
|
47430 | |
47431 |
|
47432 |
|
47433 |
|
47434 |
|
47435 |
|
47436 | function MoveConnectionHandler() { }
|
47437 |
|
47438 |
|
47439 | MoveConnectionHandler.prototype.execute = function(context) {
|
47440 |
|
47441 | var connection = context.connection,
|
47442 | delta = context.delta;
|
47443 |
|
47444 | var newParent = context.newParent || connection.parent,
|
47445 | newParentIndex = context.newParentIndex,
|
47446 | oldParent = connection.parent;
|
47447 |
|
47448 |
|
47449 | context.oldParent = oldParent;
|
47450 | context.oldParentIndex = remove$2(oldParent.children, connection);
|
47451 |
|
47452 |
|
47453 | add$1(newParent.children, connection, newParentIndex);
|
47454 |
|
47455 |
|
47456 | connection.parent = newParent;
|
47457 |
|
47458 |
|
47459 | forEach(connection.waypoints, function(p) {
|
47460 | p.x += delta.x;
|
47461 | p.y += delta.y;
|
47462 |
|
47463 | if (p.original) {
|
47464 | p.original.x += delta.x;
|
47465 | p.original.y += delta.y;
|
47466 | }
|
47467 | });
|
47468 |
|
47469 | return connection;
|
47470 | };
|
47471 |
|
47472 | MoveConnectionHandler.prototype.revert = function(context) {
|
47473 |
|
47474 | var connection = context.connection,
|
47475 | newParent = connection.parent,
|
47476 | oldParent = context.oldParent,
|
47477 | oldParentIndex = context.oldParentIndex,
|
47478 | delta = context.delta;
|
47479 |
|
47480 |
|
47481 | remove$2(newParent.children, connection);
|
47482 |
|
47483 |
|
47484 | add$1(oldParent.children, connection, oldParentIndex);
|
47485 |
|
47486 |
|
47487 | connection.parent = oldParent;
|
47488 |
|
47489 |
|
47490 | forEach(connection.waypoints, function(p) {
|
47491 | p.x -= delta.x;
|
47492 | p.y -= delta.y;
|
47493 |
|
47494 | if (p.original) {
|
47495 | p.original.x -= delta.x;
|
47496 | p.original.y -= delta.y;
|
47497 | }
|
47498 | });
|
47499 |
|
47500 | return connection;
|
47501 | };
|
47502 |
|
47503 | function getResizedSourceAnchor(connection, shape, oldBounds) {
|
47504 |
|
47505 | var waypoints = safeGetWaypoints(connection),
|
47506 | oldAnchor = waypoints[0];
|
47507 |
|
47508 | return getNewAttachPoint(oldAnchor.original || oldAnchor, oldBounds, shape);
|
47509 | }
|
47510 |
|
47511 |
|
47512 | function getResizedTargetAnchor(connection, shape, oldBounds) {
|
47513 |
|
47514 | var waypoints = safeGetWaypoints(connection),
|
47515 | oldAnchor = waypoints[waypoints.length - 1];
|
47516 |
|
47517 | return getNewAttachPoint(oldAnchor.original || oldAnchor, oldBounds, shape);
|
47518 | }
|
47519 |
|
47520 |
|
47521 | function getMovedSourceAnchor(connection, source, moveDelta) {
|
47522 | return getResizedSourceAnchor(connection, source, substractPosition(source, moveDelta));
|
47523 | }
|
47524 |
|
47525 |
|
47526 | function getMovedTargetAnchor(connection, target, moveDelta) {
|
47527 | return getResizedTargetAnchor(connection, target, substractPosition(target, moveDelta));
|
47528 | }
|
47529 |
|
47530 |
|
47531 |
|
47532 |
|
47533 | function substractPosition(bounds, delta) {
|
47534 | return {
|
47535 | x: bounds.x - delta.x,
|
47536 | y: bounds.y - delta.y,
|
47537 | width: bounds.width,
|
47538 | height: bounds.height
|
47539 | };
|
47540 | }
|
47541 |
|
47542 |
|
47543 | |
47544 |
|
47545 |
|
47546 |
|
47547 |
|
47548 |
|
47549 |
|
47550 | function safeGetWaypoints(connection) {
|
47551 |
|
47552 | var waypoints = connection.waypoints;
|
47553 |
|
47554 | if (!waypoints.length) {
|
47555 | throw new Error('connection#' + connection.id + ': no waypoints');
|
47556 | }
|
47557 |
|
47558 | return waypoints;
|
47559 | }
|
47560 |
|
47561 | function MoveClosure() {
|
47562 |
|
47563 | this.allShapes = {};
|
47564 | this.allConnections = {};
|
47565 |
|
47566 | this.enclosedElements = {};
|
47567 | this.enclosedConnections = {};
|
47568 |
|
47569 | this.topLevel = {};
|
47570 | }
|
47571 |
|
47572 |
|
47573 | MoveClosure.prototype.add = function(element, isTopLevel) {
|
47574 | return this.addAll([ element ], isTopLevel);
|
47575 | };
|
47576 |
|
47577 |
|
47578 | MoveClosure.prototype.addAll = function(elements, isTopLevel) {
|
47579 |
|
47580 | var newClosure = getClosure(elements, !!isTopLevel, this);
|
47581 |
|
47582 | assign(this, newClosure);
|
47583 |
|
47584 | return this;
|
47585 | };
|
47586 |
|
47587 | |
47588 |
|
47589 |
|
47590 |
|
47591 |
|
47592 |
|
47593 | function MoveHelper(modeling) {
|
47594 | this._modeling = modeling;
|
47595 | }
|
47596 |
|
47597 | |
47598 |
|
47599 |
|
47600 |
|
47601 |
|
47602 |
|
47603 |
|
47604 |
|
47605 |
|
47606 |
|
47607 |
|
47608 |
|
47609 | MoveHelper.prototype.moveRecursive = function(elements, delta, newParent) {
|
47610 | if (!elements) {
|
47611 | return [];
|
47612 | } else {
|
47613 | return this.moveClosure(this.getClosure(elements), delta, newParent);
|
47614 | }
|
47615 | };
|
47616 |
|
47617 | |
47618 |
|
47619 |
|
47620 |
|
47621 |
|
47622 |
|
47623 |
|
47624 |
|
47625 | MoveHelper.prototype.moveClosure = function(closure, delta, newParent, newHost, primaryShape) {
|
47626 | var modeling = this._modeling;
|
47627 |
|
47628 | var allShapes = closure.allShapes,
|
47629 | allConnections = closure.allConnections,
|
47630 | enclosedConnections = closure.enclosedConnections,
|
47631 | topLevel = closure.topLevel,
|
47632 | keepParent = false;
|
47633 |
|
47634 | if (primaryShape && primaryShape.parent === newParent) {
|
47635 | keepParent = true;
|
47636 | }
|
47637 |
|
47638 |
|
47639 | forEach(allShapes, function(shape) {
|
47640 |
|
47641 |
|
47642 | modeling.moveShape(shape, delta, topLevel[shape.id] && !keepParent && newParent, {
|
47643 | recurse: false,
|
47644 | layout: false
|
47645 | });
|
47646 | });
|
47647 |
|
47648 |
|
47649 | forEach(allConnections, function(c) {
|
47650 |
|
47651 | var sourceMoved = !!allShapes[c.source.id],
|
47652 | targetMoved = !!allShapes[c.target.id];
|
47653 |
|
47654 | if (enclosedConnections[c.id] && sourceMoved && targetMoved) {
|
47655 | modeling.moveConnection(c, delta, topLevel[c.id] && !keepParent && newParent);
|
47656 | } else {
|
47657 | modeling.layoutConnection(c, {
|
47658 | connectionStart: sourceMoved && getMovedSourceAnchor(c, c.source, delta),
|
47659 | connectionEnd: targetMoved && getMovedTargetAnchor(c, c.target, delta)
|
47660 | });
|
47661 | }
|
47662 | });
|
47663 | };
|
47664 |
|
47665 | |
47666 |
|
47667 |
|
47668 |
|
47669 |
|
47670 |
|
47671 | MoveHelper.prototype.getClosure = function(elements) {
|
47672 | return new MoveClosure().addAll(elements, true);
|
47673 | };
|
47674 |
|
47675 | |
47676 |
|
47677 |
|
47678 | function MoveElementsHandler(modeling) {
|
47679 | this._helper = new MoveHelper(modeling);
|
47680 | }
|
47681 |
|
47682 | MoveElementsHandler.$inject = [ 'modeling' ];
|
47683 |
|
47684 | MoveElementsHandler.prototype.preExecute = function(context) {
|
47685 | context.closure = this._helper.getClosure(context.shapes);
|
47686 | };
|
47687 |
|
47688 | MoveElementsHandler.prototype.postExecute = function(context) {
|
47689 |
|
47690 | var hints = context.hints,
|
47691 | primaryShape;
|
47692 |
|
47693 | if (hints && hints.primaryShape) {
|
47694 | primaryShape = hints.primaryShape;
|
47695 | hints.oldParent = primaryShape.parent;
|
47696 | }
|
47697 |
|
47698 | this._helper.moveClosure(
|
47699 | context.closure,
|
47700 | context.delta,
|
47701 | context.newParent,
|
47702 | context.newHost,
|
47703 | primaryShape
|
47704 | );
|
47705 | };
|
47706 |
|
47707 | |
47708 |
|
47709 |
|
47710 | function MoveShapeHandler(modeling) {
|
47711 | this._modeling = modeling;
|
47712 |
|
47713 | this._helper = new MoveHelper(modeling);
|
47714 | }
|
47715 |
|
47716 | MoveShapeHandler.$inject = [ 'modeling' ];
|
47717 |
|
47718 |
|
47719 | MoveShapeHandler.prototype.execute = function(context) {
|
47720 |
|
47721 | var shape = context.shape,
|
47722 | delta = context.delta,
|
47723 | newParent = context.newParent || shape.parent,
|
47724 | newParentIndex = context.newParentIndex,
|
47725 | oldParent = shape.parent;
|
47726 |
|
47727 | context.oldBounds = pick(shape, [ 'x', 'y', 'width', 'height']);
|
47728 |
|
47729 |
|
47730 | context.oldParent = oldParent;
|
47731 | context.oldParentIndex = remove$2(oldParent.children, shape);
|
47732 |
|
47733 |
|
47734 | add$1(newParent.children, shape, newParentIndex);
|
47735 |
|
47736 |
|
47737 | assign(shape, {
|
47738 | parent: newParent,
|
47739 | x: shape.x + delta.x,
|
47740 | y: shape.y + delta.y
|
47741 | });
|
47742 |
|
47743 | return shape;
|
47744 | };
|
47745 |
|
47746 | MoveShapeHandler.prototype.postExecute = function(context) {
|
47747 |
|
47748 | var shape = context.shape,
|
47749 | delta = context.delta,
|
47750 | hints = context.hints;
|
47751 |
|
47752 | var modeling = this._modeling;
|
47753 |
|
47754 | if (hints.layout !== false) {
|
47755 |
|
47756 | forEach(shape.incoming, function(c) {
|
47757 | modeling.layoutConnection(c, {
|
47758 | connectionEnd: getMovedTargetAnchor(c, shape, delta)
|
47759 | });
|
47760 | });
|
47761 |
|
47762 | forEach(shape.outgoing, function(c) {
|
47763 | modeling.layoutConnection(c, {
|
47764 | connectionStart: getMovedSourceAnchor(c, shape, delta)
|
47765 | });
|
47766 | });
|
47767 | }
|
47768 |
|
47769 | if (hints.recurse !== false) {
|
47770 | this.moveChildren(context);
|
47771 | }
|
47772 | };
|
47773 |
|
47774 | MoveShapeHandler.prototype.revert = function(context) {
|
47775 |
|
47776 | var shape = context.shape,
|
47777 | oldParent = context.oldParent,
|
47778 | oldParentIndex = context.oldParentIndex,
|
47779 | delta = context.delta;
|
47780 |
|
47781 |
|
47782 | add$1(oldParent.children, shape, oldParentIndex);
|
47783 |
|
47784 |
|
47785 | assign(shape, {
|
47786 | parent: oldParent,
|
47787 | x: shape.x - delta.x,
|
47788 | y: shape.y - delta.y
|
47789 | });
|
47790 |
|
47791 | return shape;
|
47792 | };
|
47793 |
|
47794 | MoveShapeHandler.prototype.moveChildren = function(context) {
|
47795 |
|
47796 | var delta = context.delta,
|
47797 | shape = context.shape;
|
47798 |
|
47799 | this._helper.moveRecursive(shape.children, delta, null);
|
47800 | };
|
47801 |
|
47802 | MoveShapeHandler.prototype.getNewParent = function(context) {
|
47803 | return context.newParent || context.shape.parent;
|
47804 | };
|
47805 |
|
47806 | |
47807 |
|
47808 |
|
47809 | function ReconnectConnectionHandler(modeling) {
|
47810 | this._modeling = modeling;
|
47811 | }
|
47812 |
|
47813 | ReconnectConnectionHandler.$inject = [ 'modeling' ];
|
47814 |
|
47815 | ReconnectConnectionHandler.prototype.execute = function(context) {
|
47816 |
|
47817 | var newSource = context.newSource,
|
47818 | newTarget = context.newTarget,
|
47819 | connection = context.connection,
|
47820 | dockingOrPoints = context.dockingOrPoints;
|
47821 |
|
47822 | if (!newSource && !newTarget) {
|
47823 | throw new Error('newSource or newTarget are required');
|
47824 | }
|
47825 |
|
47826 | if (newSource && newTarget) {
|
47827 | throw new Error('must specify either newSource or newTarget');
|
47828 | }
|
47829 |
|
47830 | if (isArray(dockingOrPoints)) {
|
47831 | context.oldWaypoints = connection.waypoints;
|
47832 | connection.waypoints = dockingOrPoints;
|
47833 | }
|
47834 |
|
47835 | if (newSource) {
|
47836 | context.oldSource = connection.source;
|
47837 | connection.source = newSource;
|
47838 | }
|
47839 |
|
47840 | if (newTarget) {
|
47841 | context.oldTarget = connection.target;
|
47842 | connection.target = newTarget;
|
47843 | }
|
47844 |
|
47845 | return connection;
|
47846 | };
|
47847 |
|
47848 | ReconnectConnectionHandler.prototype.postExecute = function(context) {
|
47849 | var connection = context.connection,
|
47850 | dockingOrPoints = context.dockingOrPoints,
|
47851 | newSource = context.newSource,
|
47852 | movedEnd = newSource ? 'connectionStart' : 'connectionEnd',
|
47853 | newWaypoint,
|
47854 | hints = context.hints,
|
47855 | layoutHints = {};
|
47856 |
|
47857 | if (hints.layoutConnection === false) {
|
47858 | return;
|
47859 | }
|
47860 |
|
47861 | if (isArray(dockingOrPoints)) {
|
47862 | newWaypoint = newSource ? dockingOrPoints[0] : dockingOrPoints[dockingOrPoints.length - 1];
|
47863 | } else {
|
47864 | newWaypoint = dockingOrPoints;
|
47865 | }
|
47866 |
|
47867 | layoutHints[movedEnd] = getDocking$2(newWaypoint);
|
47868 |
|
47869 | this._modeling.layoutConnection(connection, layoutHints);
|
47870 | };
|
47871 |
|
47872 | ReconnectConnectionHandler.prototype.revert = function(context) {
|
47873 |
|
47874 | var oldSource = context.oldSource,
|
47875 | oldTarget = context.oldTarget,
|
47876 | oldWaypoints = context.oldWaypoints,
|
47877 | connection = context.connection;
|
47878 |
|
47879 | if (oldSource) {
|
47880 | connection.source = oldSource;
|
47881 | }
|
47882 |
|
47883 | if (oldTarget) {
|
47884 | connection.target = oldTarget;
|
47885 | }
|
47886 |
|
47887 | if (oldWaypoints) {
|
47888 | connection.waypoints = oldWaypoints;
|
47889 | }
|
47890 |
|
47891 | return connection;
|
47892 | };
|
47893 |
|
47894 |
|
47895 |
|
47896 |
|
47897 |
|
47898 | function getDocking$2(point) {
|
47899 | return point.original || point;
|
47900 | }
|
47901 |
|
47902 | |
47903 |
|
47904 |
|
47905 |
|
47906 |
|
47907 |
|
47908 |
|
47909 |
|
47910 |
|
47911 |
|
47912 | function ReplaceShapeHandler(modeling, rules) {
|
47913 | this._modeling = modeling;
|
47914 | this._rules = rules;
|
47915 | }
|
47916 |
|
47917 | ReplaceShapeHandler.$inject = [ 'modeling', 'rules' ];
|
47918 |
|
47919 |
|
47920 |
|
47921 |
|
47922 |
|
47923 | |
47924 |
|
47925 |
|
47926 |
|
47927 |
|
47928 |
|
47929 |
|
47930 |
|
47931 |
|
47932 |
|
47933 | ReplaceShapeHandler.prototype.preExecute = function(context) {
|
47934 |
|
47935 | var self = this,
|
47936 | modeling = this._modeling,
|
47937 | rules = this._rules;
|
47938 |
|
47939 | var oldShape = context.oldShape,
|
47940 | newData = context.newData,
|
47941 | hints = context.hints,
|
47942 | newShape;
|
47943 |
|
47944 | function canReconnect(type, source, target, connection) {
|
47945 | return rules.allowed(type, {
|
47946 | source: source,
|
47947 | target: target,
|
47948 | connection: connection
|
47949 | });
|
47950 | }
|
47951 |
|
47952 |
|
47953 |
|
47954 |
|
47955 | var position = {
|
47956 | x: newData.x,
|
47957 | y: newData.y
|
47958 | };
|
47959 |
|
47960 | newShape = context.newShape =
|
47961 | context.newShape ||
|
47962 | self.createShape(newData, position, oldShape.parent, hints);
|
47963 |
|
47964 |
|
47965 |
|
47966 |
|
47967 | if (oldShape.host) {
|
47968 | modeling.updateAttachment(newShape, oldShape.host);
|
47969 | }
|
47970 |
|
47971 |
|
47972 |
|
47973 |
|
47974 | var children;
|
47975 |
|
47976 | if (hints.moveChildren !== false) {
|
47977 | children = oldShape.children.slice();
|
47978 |
|
47979 | modeling.moveElements(children, { x: 0, y: 0 }, newShape);
|
47980 | }
|
47981 |
|
47982 |
|
47983 |
|
47984 | var incoming = oldShape.incoming.slice(),
|
47985 | outgoing = oldShape.outgoing.slice();
|
47986 |
|
47987 | forEach(incoming, function(connection) {
|
47988 | var waypoints = connection.waypoints,
|
47989 | docking = waypoints[waypoints.length - 1],
|
47990 | source = connection.source,
|
47991 | allowed = canReconnect('connection.reconnectEnd', source, newShape, connection);
|
47992 |
|
47993 | if (allowed) {
|
47994 | self.reconnectEnd(connection, newShape, docking, { layoutConnection: hints.layoutConnection });
|
47995 | }
|
47996 | });
|
47997 |
|
47998 | forEach(outgoing, function(connection) {
|
47999 | var waypoints = connection.waypoints,
|
48000 | docking = waypoints[0],
|
48001 | target = connection.target,
|
48002 | allowed = canReconnect('connection.reconnectStart', newShape, target, connection);
|
48003 |
|
48004 | if (allowed) {
|
48005 | self.reconnectStart(connection, newShape, docking, { layoutConnection: hints.layoutConnection });
|
48006 | }
|
48007 |
|
48008 | });
|
48009 | };
|
48010 |
|
48011 |
|
48012 | ReplaceShapeHandler.prototype.postExecute = function(context) {
|
48013 | var modeling = this._modeling;
|
48014 |
|
48015 | var oldShape = context.oldShape,
|
48016 | newShape = context.newShape,
|
48017 | layoutConnection = context.hints.layoutConnection;
|
48018 |
|
48019 |
|
48020 | if (layoutConnection !== false) {
|
48021 | forEach(newShape.incoming, function(c) {
|
48022 | modeling.layoutConnection(c, { endChanged: true });
|
48023 | });
|
48024 |
|
48025 | forEach(newShape.outgoing, function(c) {
|
48026 | modeling.layoutConnection(c, { startChanged: true });
|
48027 | });
|
48028 | }
|
48029 |
|
48030 | modeling.removeShape(oldShape);
|
48031 | };
|
48032 |
|
48033 |
|
48034 | ReplaceShapeHandler.prototype.execute = function(context) {};
|
48035 |
|
48036 | ReplaceShapeHandler.prototype.revert = function(context) {};
|
48037 |
|
48038 |
|
48039 | ReplaceShapeHandler.prototype.createShape = function(shape, position, target, hints) {
|
48040 | return this._modeling.createShape(shape, position, target, hints);
|
48041 | };
|
48042 |
|
48043 |
|
48044 | ReplaceShapeHandler.prototype.reconnectStart = function(connection, newSource, dockingPoint, hints) {
|
48045 | this._modeling.reconnectStart(connection, newSource, dockingPoint, hints);
|
48046 | };
|
48047 |
|
48048 |
|
48049 | ReplaceShapeHandler.prototype.reconnectEnd = function(connection, newTarget, dockingPoint, hints) {
|
48050 | this._modeling.reconnectEnd(connection, newTarget, dockingPoint, hints);
|
48051 | };
|
48052 |
|
48053 | |
48054 |
|
48055 |
|
48056 |
|
48057 |
|
48058 | function ResizeShapeHandler(modeling) {
|
48059 | this._modeling = modeling;
|
48060 | }
|
48061 |
|
48062 | ResizeShapeHandler.$inject = [ 'modeling' ];
|
48063 |
|
48064 | |
48065 |
|
48066 |
|
48067 |
|
48068 |
|
48069 |
|
48070 |
|
48071 |
|
48072 |
|
48073 |
|
48074 |
|
48075 |
|
48076 | ResizeShapeHandler.prototype.execute = function(context) {
|
48077 | var shape = context.shape,
|
48078 | newBounds = context.newBounds,
|
48079 | minBounds = context.minBounds;
|
48080 |
|
48081 | if (newBounds.x === undefined || newBounds.y === undefined ||
|
48082 | newBounds.width === undefined || newBounds.height === undefined) {
|
48083 | throw new Error('newBounds must have {x, y, width, height} properties');
|
48084 | }
|
48085 |
|
48086 | if (minBounds && (newBounds.width < minBounds.width
|
48087 | || newBounds.height < minBounds.height)) {
|
48088 | throw new Error('width and height cannot be less than minimum height and width');
|
48089 | } else if (!minBounds
|
48090 | && newBounds.width < 10 || newBounds.height < 10) {
|
48091 | throw new Error('width and height cannot be less than 10px');
|
48092 | }
|
48093 |
|
48094 |
|
48095 | context.oldBounds = {
|
48096 | width: shape.width,
|
48097 | height: shape.height,
|
48098 | x: shape.x,
|
48099 | y: shape.y
|
48100 | };
|
48101 |
|
48102 |
|
48103 | assign(shape, {
|
48104 | width: newBounds.width,
|
48105 | height: newBounds.height,
|
48106 | x: newBounds.x,
|
48107 | y: newBounds.y
|
48108 | });
|
48109 |
|
48110 | return shape;
|
48111 | };
|
48112 |
|
48113 | ResizeShapeHandler.prototype.postExecute = function(context) {
|
48114 |
|
48115 | var shape = context.shape,
|
48116 | oldBounds = context.oldBounds;
|
48117 |
|
48118 | var modeling = this._modeling;
|
48119 |
|
48120 | forEach(shape.incoming, function(c) {
|
48121 | modeling.layoutConnection(c, {
|
48122 | connectionEnd: getResizedTargetAnchor(c, shape, oldBounds)
|
48123 | });
|
48124 | });
|
48125 |
|
48126 | forEach(shape.outgoing, function(c) {
|
48127 | modeling.layoutConnection(c, {
|
48128 | connectionStart: getResizedSourceAnchor(c, shape, oldBounds)
|
48129 | });
|
48130 | });
|
48131 |
|
48132 | };
|
48133 |
|
48134 | ResizeShapeHandler.prototype.revert = function(context) {
|
48135 |
|
48136 | var shape = context.shape,
|
48137 | oldBounds = context.oldBounds;
|
48138 |
|
48139 |
|
48140 | assign(shape, {
|
48141 | width: oldBounds.width,
|
48142 | height: oldBounds.height,
|
48143 | x: oldBounds.x,
|
48144 | y: oldBounds.y
|
48145 | });
|
48146 |
|
48147 | return shape;
|
48148 | };
|
48149 |
|
48150 | |
48151 |
|
48152 |
|
48153 |
|
48154 |
|
48155 |
|
48156 |
|
48157 |
|
48158 | function SpaceToolHandler(modeling) {
|
48159 | this._modeling = modeling;
|
48160 | }
|
48161 |
|
48162 | SpaceToolHandler.$inject = [ 'modeling' ];
|
48163 |
|
48164 |
|
48165 | SpaceToolHandler.prototype.preExecute = function(context) {
|
48166 |
|
48167 |
|
48168 | var modeling = this._modeling,
|
48169 | resizingShapes = context.resizingShapes,
|
48170 | delta = context.delta,
|
48171 | direction = context.direction;
|
48172 |
|
48173 | forEach(resizingShapes, function(shape) {
|
48174 | var newBounds = resizeBounds$1(shape, direction, delta);
|
48175 |
|
48176 | modeling.resizeShape(shape, newBounds);
|
48177 | });
|
48178 | };
|
48179 |
|
48180 | SpaceToolHandler.prototype.postExecute = function(context) {
|
48181 |
|
48182 |
|
48183 | var modeling = this._modeling,
|
48184 | movingShapes = context.movingShapes,
|
48185 | delta = context.delta;
|
48186 |
|
48187 | modeling.moveElements(movingShapes, delta, undefined, { autoResize: false, attach: false });
|
48188 | };
|
48189 |
|
48190 | SpaceToolHandler.prototype.execute = function(context) {};
|
48191 | SpaceToolHandler.prototype.revert = function(context) {};
|
48192 |
|
48193 | |
48194 |
|
48195 |
|
48196 |
|
48197 |
|
48198 |
|
48199 | function ToggleShapeCollapseHandler(modeling) {
|
48200 | this._modeling = modeling;
|
48201 | }
|
48202 |
|
48203 | ToggleShapeCollapseHandler.$inject = [ 'modeling' ];
|
48204 |
|
48205 |
|
48206 | ToggleShapeCollapseHandler.prototype.execute = function(context) {
|
48207 |
|
48208 | var shape = context.shape,
|
48209 | children = shape.children;
|
48210 |
|
48211 |
|
48212 | context.oldChildrenVisibility = getElementsVisibility(children);
|
48213 |
|
48214 |
|
48215 | shape.collapsed = !shape.collapsed;
|
48216 |
|
48217 |
|
48218 | setHidden(children, shape.collapsed);
|
48219 |
|
48220 | return [shape].concat(children);
|
48221 | };
|
48222 |
|
48223 |
|
48224 | ToggleShapeCollapseHandler.prototype.revert = function(context) {
|
48225 |
|
48226 | var shape = context.shape,
|
48227 | oldChildrenVisibility = context.oldChildrenVisibility;
|
48228 |
|
48229 | var children = shape.children;
|
48230 |
|
48231 |
|
48232 | restoreVisibility(children, oldChildrenVisibility);
|
48233 |
|
48234 |
|
48235 | shape.collapsed = !shape.collapsed;
|
48236 |
|
48237 | return [shape].concat(children);
|
48238 | };
|
48239 |
|
48240 |
|
48241 |
|
48242 |
|
48243 | |
48244 |
|
48245 |
|
48246 |
|
48247 |
|
48248 |
|
48249 |
|
48250 | function getElementsVisibility(elements) {
|
48251 |
|
48252 | var result = {};
|
48253 |
|
48254 | elements.forEach(function(e) {
|
48255 | result[e.id] = e.hidden;
|
48256 | });
|
48257 |
|
48258 | return result;
|
48259 | }
|
48260 |
|
48261 |
|
48262 | function setHidden(elements, newHidden) {
|
48263 | elements.forEach(function(element) {
|
48264 | element.hidden = newHidden;
|
48265 | });
|
48266 | }
|
48267 |
|
48268 | function restoreVisibility(elements, lastState) {
|
48269 | elements.forEach(function(e) {
|
48270 | e.hidden = lastState[e.id];
|
48271 | });
|
48272 | }
|
48273 |
|
48274 | |
48275 |
|
48276 |
|
48277 | function UpdateAttachmentHandler(modeling) {
|
48278 | this._modeling = modeling;
|
48279 | }
|
48280 |
|
48281 | UpdateAttachmentHandler.$inject = [ 'modeling' ];
|
48282 |
|
48283 |
|
48284 | UpdateAttachmentHandler.prototype.execute = function(context) {
|
48285 | var shape = context.shape,
|
48286 | newHost = context.newHost,
|
48287 | oldHost = shape.host;
|
48288 |
|
48289 |
|
48290 | context.oldHost = oldHost;
|
48291 | context.attacherIdx = removeAttacher(oldHost, shape);
|
48292 |
|
48293 |
|
48294 | addAttacher(newHost, shape);
|
48295 |
|
48296 |
|
48297 | shape.host = newHost;
|
48298 |
|
48299 | return shape;
|
48300 | };
|
48301 |
|
48302 | UpdateAttachmentHandler.prototype.revert = function(context) {
|
48303 | var shape = context.shape,
|
48304 | newHost = context.newHost,
|
48305 | oldHost = context.oldHost,
|
48306 | attacherIdx = context.attacherIdx;
|
48307 |
|
48308 |
|
48309 | shape.host = oldHost;
|
48310 |
|
48311 |
|
48312 | removeAttacher(newHost, shape);
|
48313 |
|
48314 |
|
48315 | addAttacher(oldHost, shape, attacherIdx);
|
48316 |
|
48317 | return shape;
|
48318 | };
|
48319 |
|
48320 |
|
48321 | function removeAttacher(host, attacher) {
|
48322 |
|
48323 |
|
48324 | return remove$2(host && host.attachers, attacher);
|
48325 | }
|
48326 |
|
48327 | function addAttacher(host, attacher, idx) {
|
48328 |
|
48329 | if (!host) {
|
48330 | return;
|
48331 | }
|
48332 |
|
48333 | var attachers = host.attachers;
|
48334 |
|
48335 | if (!attachers) {
|
48336 | host.attachers = attachers = [];
|
48337 | }
|
48338 |
|
48339 | add$1(attachers, attacher, idx);
|
48340 | }
|
48341 |
|
48342 | function UpdateWaypointsHandler() { }
|
48343 |
|
48344 | UpdateWaypointsHandler.prototype.execute = function(context) {
|
48345 |
|
48346 | var connection = context.connection,
|
48347 | newWaypoints = context.newWaypoints;
|
48348 |
|
48349 | context.oldWaypoints = connection.waypoints;
|
48350 |
|
48351 | connection.waypoints = newWaypoints;
|
48352 |
|
48353 | return connection;
|
48354 | };
|
48355 |
|
48356 | UpdateWaypointsHandler.prototype.revert = function(context) {
|
48357 |
|
48358 | var connection = context.connection,
|
48359 | oldWaypoints = context.oldWaypoints;
|
48360 |
|
48361 | connection.waypoints = oldWaypoints;
|
48362 |
|
48363 | return connection;
|
48364 | };
|
48365 |
|
48366 | |
48367 |
|
48368 |
|
48369 |
|
48370 |
|
48371 |
|
48372 |
|
48373 | function Modeling(eventBus, elementFactory, commandStack) {
|
48374 | this._eventBus = eventBus;
|
48375 | this._elementFactory = elementFactory;
|
48376 | this._commandStack = commandStack;
|
48377 |
|
48378 | var self = this;
|
48379 |
|
48380 | eventBus.on('diagram.init', function() {
|
48381 |
|
48382 |
|
48383 | self.registerHandlers(commandStack);
|
48384 | });
|
48385 | }
|
48386 |
|
48387 | Modeling.$inject = [ 'eventBus', 'elementFactory', 'commandStack' ];
|
48388 |
|
48389 |
|
48390 | Modeling.prototype.getHandlers = function() {
|
48391 | return {
|
48392 | 'shape.append': AppendShapeHandler,
|
48393 | 'shape.create': CreateShapeHandler,
|
48394 | 'shape.delete': DeleteShapeHandler,
|
48395 | 'shape.move': MoveShapeHandler,
|
48396 | 'shape.resize': ResizeShapeHandler,
|
48397 | 'shape.replace': ReplaceShapeHandler,
|
48398 | 'shape.toggleCollapse': ToggleShapeCollapseHandler,
|
48399 |
|
48400 | 'spaceTool': SpaceToolHandler,
|
48401 |
|
48402 | 'label.create': CreateLabelHandler,
|
48403 |
|
48404 | 'connection.create': CreateConnectionHandler,
|
48405 | 'connection.delete': DeleteConnectionHandler,
|
48406 | 'connection.move': MoveConnectionHandler,
|
48407 | 'connection.layout': LayoutConnectionHandler,
|
48408 |
|
48409 | 'connection.updateWaypoints': UpdateWaypointsHandler,
|
48410 |
|
48411 | 'connection.reconnectStart': ReconnectConnectionHandler,
|
48412 | 'connection.reconnectEnd': ReconnectConnectionHandler,
|
48413 |
|
48414 | 'elements.create': CreateElementsHandler,
|
48415 | 'elements.move': MoveElementsHandler,
|
48416 | 'elements.delete': DeleteElementsHandler,
|
48417 |
|
48418 | 'elements.distribute': DistributeElements$1,
|
48419 | 'elements.align': AlignElements$1,
|
48420 |
|
48421 | 'element.updateAttachment': UpdateAttachmentHandler
|
48422 | };
|
48423 | };
|
48424 |
|
48425 | |
48426 |
|
48427 |
|
48428 |
|
48429 |
|
48430 | Modeling.prototype.registerHandlers = function(commandStack) {
|
48431 | forEach(this.getHandlers(), function(handler, id) {
|
48432 | commandStack.registerHandler(id, handler);
|
48433 | });
|
48434 | };
|
48435 |
|
48436 |
|
48437 |
|
48438 |
|
48439 | Modeling.prototype.moveShape = function(shape, delta, newParent, newParentIndex, hints) {
|
48440 |
|
48441 | if (typeof newParentIndex === 'object') {
|
48442 | hints = newParentIndex;
|
48443 | newParentIndex = null;
|
48444 | }
|
48445 |
|
48446 | var context = {
|
48447 | shape: shape,
|
48448 | delta: delta,
|
48449 | newParent: newParent,
|
48450 | newParentIndex: newParentIndex,
|
48451 | hints: hints || {}
|
48452 | };
|
48453 |
|
48454 | this._commandStack.execute('shape.move', context);
|
48455 | };
|
48456 |
|
48457 |
|
48458 | |
48459 |
|
48460 |
|
48461 |
|
48462 |
|
48463 |
|
48464 | Modeling.prototype.updateAttachment = function(shape, newHost) {
|
48465 | var context = {
|
48466 | shape: shape,
|
48467 | newHost: newHost
|
48468 | };
|
48469 |
|
48470 | this._commandStack.execute('element.updateAttachment', context);
|
48471 | };
|
48472 |
|
48473 |
|
48474 | |
48475 |
|
48476 |
|
48477 |
|
48478 |
|
48479 |
|
48480 |
|
48481 |
|
48482 |
|
48483 |
|
48484 | Modeling.prototype.moveElements = function(shapes, delta, target, hints) {
|
48485 |
|
48486 | hints = hints || {};
|
48487 |
|
48488 | var attach = hints.attach;
|
48489 |
|
48490 | var newParent = target,
|
48491 | newHost;
|
48492 |
|
48493 | if (attach === true) {
|
48494 | newHost = target;
|
48495 | newParent = target.parent;
|
48496 | } else
|
48497 |
|
48498 | if (attach === false) {
|
48499 | newHost = null;
|
48500 | }
|
48501 |
|
48502 | var context = {
|
48503 | shapes: shapes,
|
48504 | delta: delta,
|
48505 | newParent: newParent,
|
48506 | newHost: newHost,
|
48507 | hints: hints
|
48508 | };
|
48509 |
|
48510 | this._commandStack.execute('elements.move', context);
|
48511 | };
|
48512 |
|
48513 |
|
48514 | Modeling.prototype.moveConnection = function(connection, delta, newParent, newParentIndex, hints) {
|
48515 |
|
48516 | if (typeof newParentIndex === 'object') {
|
48517 | hints = newParentIndex;
|
48518 | newParentIndex = undefined;
|
48519 | }
|
48520 |
|
48521 | var context = {
|
48522 | connection: connection,
|
48523 | delta: delta,
|
48524 | newParent: newParent,
|
48525 | newParentIndex: newParentIndex,
|
48526 | hints: hints || {}
|
48527 | };
|
48528 |
|
48529 | this._commandStack.execute('connection.move', context);
|
48530 | };
|
48531 |
|
48532 |
|
48533 | Modeling.prototype.layoutConnection = function(connection, hints) {
|
48534 | var context = {
|
48535 | connection: connection,
|
48536 | hints: hints || {}
|
48537 | };
|
48538 |
|
48539 | this._commandStack.execute('connection.layout', context);
|
48540 | };
|
48541 |
|
48542 |
|
48543 | |
48544 |
|
48545 |
|
48546 |
|
48547 |
|
48548 |
|
48549 |
|
48550 |
|
48551 |
|
48552 |
|
48553 |
|
48554 |
|
48555 | Modeling.prototype.createConnection = function(source, target, parentIndex, connection, parent, hints) {
|
48556 |
|
48557 | if (typeof parentIndex === 'object') {
|
48558 | hints = parent;
|
48559 | parent = connection;
|
48560 | connection = parentIndex;
|
48561 | parentIndex = undefined;
|
48562 | }
|
48563 |
|
48564 | connection = this._create('connection', connection);
|
48565 |
|
48566 | var context = {
|
48567 | source: source,
|
48568 | target: target,
|
48569 | parent: parent,
|
48570 | parentIndex: parentIndex,
|
48571 | connection: connection,
|
48572 | hints: hints
|
48573 | };
|
48574 |
|
48575 | this._commandStack.execute('connection.create', context);
|
48576 |
|
48577 | return context.connection;
|
48578 | };
|
48579 |
|
48580 |
|
48581 | |
48582 |
|
48583 |
|
48584 |
|
48585 |
|
48586 |
|
48587 |
|
48588 |
|
48589 |
|
48590 |
|
48591 |
|
48592 |
|
48593 | Modeling.prototype.createShape = function(shape, position, target, parentIndex, hints) {
|
48594 |
|
48595 | if (typeof parentIndex !== 'number') {
|
48596 | hints = parentIndex;
|
48597 | parentIndex = undefined;
|
48598 | }
|
48599 |
|
48600 | hints = hints || {};
|
48601 |
|
48602 | var attach = hints.attach,
|
48603 | parent,
|
48604 | host;
|
48605 |
|
48606 | shape = this._create('shape', shape);
|
48607 |
|
48608 | if (attach) {
|
48609 | parent = target.parent;
|
48610 | host = target;
|
48611 | } else {
|
48612 | parent = target;
|
48613 | }
|
48614 |
|
48615 | var context = {
|
48616 | position: position,
|
48617 | shape: shape,
|
48618 | parent: parent,
|
48619 | parentIndex: parentIndex,
|
48620 | host: host,
|
48621 | hints: hints
|
48622 | };
|
48623 |
|
48624 | this._commandStack.execute('shape.create', context);
|
48625 |
|
48626 | return context.shape;
|
48627 | };
|
48628 |
|
48629 |
|
48630 | Modeling.prototype.createElements = function(elements, position, parent, parentIndex, hints) {
|
48631 | if (!isArray(elements)) {
|
48632 | elements = [ elements ];
|
48633 | }
|
48634 |
|
48635 | if (typeof parentIndex !== 'number') {
|
48636 | hints = parentIndex;
|
48637 | parentIndex = undefined;
|
48638 | }
|
48639 |
|
48640 | hints = hints || {};
|
48641 |
|
48642 | var context = {
|
48643 | position: position,
|
48644 | elements: elements,
|
48645 | parent: parent,
|
48646 | parentIndex: parentIndex,
|
48647 | hints: hints
|
48648 | };
|
48649 |
|
48650 | this._commandStack.execute('elements.create', context);
|
48651 |
|
48652 | return context.elements;
|
48653 | };
|
48654 |
|
48655 |
|
48656 | Modeling.prototype.createLabel = function(labelTarget, position, label, parent) {
|
48657 |
|
48658 | label = this._create('label', label);
|
48659 |
|
48660 | var context = {
|
48661 | labelTarget: labelTarget,
|
48662 | position: position,
|
48663 | parent: parent || labelTarget.parent,
|
48664 | shape: label
|
48665 | };
|
48666 |
|
48667 | this._commandStack.execute('label.create', context);
|
48668 |
|
48669 | return context.shape;
|
48670 | };
|
48671 |
|
48672 |
|
48673 | |
48674 |
|
48675 |
|
48676 |
|
48677 |
|
48678 |
|
48679 |
|
48680 |
|
48681 |
|
48682 |
|
48683 |
|
48684 |
|
48685 |
|
48686 |
|
48687 |
|
48688 | Modeling.prototype.appendShape = function(source, shape, position, target, hints) {
|
48689 |
|
48690 | hints = hints || {};
|
48691 |
|
48692 | shape = this._create('shape', shape);
|
48693 |
|
48694 | var context = {
|
48695 | source: source,
|
48696 | position: position,
|
48697 | target: target,
|
48698 | shape: shape,
|
48699 | connection: hints.connection,
|
48700 | connectionParent: hints.connectionParent,
|
48701 | attach: hints.attach
|
48702 | };
|
48703 |
|
48704 | this._commandStack.execute('shape.append', context);
|
48705 |
|
48706 | return context.shape;
|
48707 | };
|
48708 |
|
48709 |
|
48710 | Modeling.prototype.removeElements = function(elements) {
|
48711 | var context = {
|
48712 | elements: elements
|
48713 | };
|
48714 |
|
48715 | this._commandStack.execute('elements.delete', context);
|
48716 | };
|
48717 |
|
48718 |
|
48719 | Modeling.prototype.distributeElements = function(groups, axis, dimension) {
|
48720 | var context = {
|
48721 | groups: groups,
|
48722 | axis: axis,
|
48723 | dimension: dimension
|
48724 | };
|
48725 |
|
48726 | this._commandStack.execute('elements.distribute', context);
|
48727 | };
|
48728 |
|
48729 |
|
48730 | Modeling.prototype.removeShape = function(shape, hints) {
|
48731 | var context = {
|
48732 | shape: shape,
|
48733 | hints: hints || {}
|
48734 | };
|
48735 |
|
48736 | this._commandStack.execute('shape.delete', context);
|
48737 | };
|
48738 |
|
48739 |
|
48740 | Modeling.prototype.removeConnection = function(connection, hints) {
|
48741 | var context = {
|
48742 | connection: connection,
|
48743 | hints: hints || {}
|
48744 | };
|
48745 |
|
48746 | this._commandStack.execute('connection.delete', context);
|
48747 | };
|
48748 |
|
48749 | Modeling.prototype.replaceShape = function(oldShape, newShape, hints) {
|
48750 | var context = {
|
48751 | oldShape: oldShape,
|
48752 | newData: newShape,
|
48753 | hints: hints || {}
|
48754 | };
|
48755 |
|
48756 | this._commandStack.execute('shape.replace', context);
|
48757 |
|
48758 | return context.newShape;
|
48759 | };
|
48760 |
|
48761 | Modeling.prototype.alignElements = function(elements, alignment) {
|
48762 | var context = {
|
48763 | elements: elements,
|
48764 | alignment: alignment
|
48765 | };
|
48766 |
|
48767 | this._commandStack.execute('elements.align', context);
|
48768 | };
|
48769 |
|
48770 | Modeling.prototype.resizeShape = function(shape, newBounds, minBounds, hints) {
|
48771 | var context = {
|
48772 | shape: shape,
|
48773 | newBounds: newBounds,
|
48774 | minBounds: minBounds,
|
48775 | hints: hints
|
48776 | };
|
48777 |
|
48778 | this._commandStack.execute('shape.resize', context);
|
48779 | };
|
48780 |
|
48781 | Modeling.prototype.createSpace = function(movingShapes, resizingShapes, delta, direction) {
|
48782 | var context = {
|
48783 | movingShapes: movingShapes,
|
48784 | resizingShapes: resizingShapes,
|
48785 | delta: delta,
|
48786 | direction: direction
|
48787 | };
|
48788 |
|
48789 | this._commandStack.execute('spaceTool', context);
|
48790 | };
|
48791 |
|
48792 | Modeling.prototype.updateWaypoints = function(connection, newWaypoints, hints) {
|
48793 | var context = {
|
48794 | connection: connection,
|
48795 | newWaypoints: newWaypoints,
|
48796 | hints: hints || {}
|
48797 | };
|
48798 |
|
48799 | this._commandStack.execute('connection.updateWaypoints', context);
|
48800 | };
|
48801 |
|
48802 | Modeling.prototype.reconnectStart = function(connection, newSource, dockingOrPoints, hints) {
|
48803 | var context = {
|
48804 | connection: connection,
|
48805 | newSource: newSource,
|
48806 | dockingOrPoints: dockingOrPoints,
|
48807 | hints: hints || {}
|
48808 | };
|
48809 |
|
48810 | this._commandStack.execute('connection.reconnectStart', context);
|
48811 | };
|
48812 |
|
48813 | Modeling.prototype.reconnectEnd = function(connection, newTarget, dockingOrPoints, hints) {
|
48814 | var context = {
|
48815 | connection: connection,
|
48816 | newTarget: newTarget,
|
48817 | dockingOrPoints: dockingOrPoints,
|
48818 | hints: hints || {}
|
48819 | };
|
48820 |
|
48821 | this._commandStack.execute('connection.reconnectEnd', context);
|
48822 | };
|
48823 |
|
48824 | Modeling.prototype.connect = function(source, target, attrs, hints) {
|
48825 | return this.createConnection(source, target, attrs || {}, source.parent, hints);
|
48826 | };
|
48827 |
|
48828 | Modeling.prototype._create = function(type, attrs) {
|
48829 | if (attrs instanceof Base) {
|
48830 | return attrs;
|
48831 | } else {
|
48832 | return this._elementFactory.create(type, attrs);
|
48833 | }
|
48834 | };
|
48835 |
|
48836 | Modeling.prototype.toggleCollapse = function(shape, hints) {
|
48837 | var context = {
|
48838 | shape: shape,
|
48839 | hints: hints || {}
|
48840 | };
|
48841 |
|
48842 | this._commandStack.execute('shape.toggleCollapse', context);
|
48843 | };
|
48844 |
|
48845 | var DEFAULT_FLOW = 'default',
|
48846 | ID = 'id',
|
48847 | DI = 'di';
|
48848 |
|
48849 | var NULL_DIMENSIONS = {
|
48850 | width: 0,
|
48851 | height: 0
|
48852 | };
|
48853 |
|
48854 | |
48855 |
|
48856 |
|
48857 |
|
48858 |
|
48859 |
|
48860 |
|
48861 |
|
48862 |
|
48863 | function UpdatePropertiesHandler(
|
48864 | elementRegistry, moddle, translate,
|
48865 | modeling, textRenderer) {
|
48866 |
|
48867 | this._elementRegistry = elementRegistry;
|
48868 | this._moddle = moddle;
|
48869 | this._translate = translate;
|
48870 | this._modeling = modeling;
|
48871 | this._textRenderer = textRenderer;
|
48872 | }
|
48873 |
|
48874 | UpdatePropertiesHandler.$inject = [
|
48875 | 'elementRegistry',
|
48876 | 'moddle',
|
48877 | 'translate',
|
48878 | 'modeling',
|
48879 | 'textRenderer'
|
48880 | ];
|
48881 |
|
48882 |
|
48883 |
|
48884 |
|
48885 | |
48886 |
|
48887 |
|
48888 |
|
48889 |
|
48890 |
|
48891 |
|
48892 |
|
48893 |
|
48894 |
|
48895 | UpdatePropertiesHandler.prototype.execute = function(context) {
|
48896 |
|
48897 | var element = context.element,
|
48898 | changed = [ element ],
|
48899 | translate = this._translate;
|
48900 |
|
48901 | if (!element) {
|
48902 | throw new Error(translate('element required'));
|
48903 | }
|
48904 |
|
48905 | var elementRegistry = this._elementRegistry,
|
48906 | ids = this._moddle.ids;
|
48907 |
|
48908 | var businessObject = element.businessObject,
|
48909 | properties = unwrapBusinessObjects(context.properties),
|
48910 | oldProperties = context.oldProperties || getProperties(businessObject, properties);
|
48911 |
|
48912 | if (isIdChange(properties, businessObject)) {
|
48913 | ids.unclaim(businessObject[ID]);
|
48914 |
|
48915 | elementRegistry.updateId(element, properties[ID]);
|
48916 |
|
48917 | ids.claim(properties[ID], businessObject);
|
48918 | }
|
48919 |
|
48920 |
|
48921 | if (DEFAULT_FLOW in properties) {
|
48922 |
|
48923 | if (properties[DEFAULT_FLOW]) {
|
48924 | changed.push(elementRegistry.get(properties[DEFAULT_FLOW].id));
|
48925 | }
|
48926 |
|
48927 | if (businessObject[DEFAULT_FLOW]) {
|
48928 | changed.push(elementRegistry.get(businessObject[DEFAULT_FLOW].id));
|
48929 | }
|
48930 | }
|
48931 |
|
48932 |
|
48933 | setProperties(businessObject, properties);
|
48934 |
|
48935 |
|
48936 | context.oldProperties = oldProperties;
|
48937 | context.changed = changed;
|
48938 |
|
48939 |
|
48940 | return changed;
|
48941 | };
|
48942 |
|
48943 |
|
48944 | UpdatePropertiesHandler.prototype.postExecute = function(context) {
|
48945 | var element = context.element,
|
48946 | label = element.label;
|
48947 |
|
48948 | var text = label && getBusinessObject(label).name;
|
48949 |
|
48950 | if (!text) {
|
48951 | return;
|
48952 | }
|
48953 |
|
48954 |
|
48955 |
|
48956 | var newLabelBounds = this._textRenderer.getExternalLabelBounds(label, text);
|
48957 |
|
48958 | this._modeling.resizeShape(label, newLabelBounds, NULL_DIMENSIONS);
|
48959 | };
|
48960 |
|
48961 | |
48962 |
|
48963 |
|
48964 |
|
48965 |
|
48966 |
|
48967 |
|
48968 | UpdatePropertiesHandler.prototype.revert = function(context) {
|
48969 |
|
48970 | var element = context.element,
|
48971 | properties = context.properties,
|
48972 | oldProperties = context.oldProperties,
|
48973 | businessObject = element.businessObject,
|
48974 | elementRegistry = this._elementRegistry,
|
48975 | ids = this._moddle.ids;
|
48976 |
|
48977 |
|
48978 | setProperties(businessObject, oldProperties);
|
48979 |
|
48980 | if (isIdChange(properties, businessObject)) {
|
48981 | ids.unclaim(properties[ID]);
|
48982 |
|
48983 | elementRegistry.updateId(element, oldProperties[ID]);
|
48984 |
|
48985 | ids.claim(oldProperties[ID], businessObject);
|
48986 | }
|
48987 |
|
48988 | return context.changed;
|
48989 | };
|
48990 |
|
48991 |
|
48992 | function isIdChange(properties, businessObject) {
|
48993 | return ID in properties && properties[ID] !== businessObject[ID];
|
48994 | }
|
48995 |
|
48996 |
|
48997 | function getProperties(businessObject, properties) {
|
48998 | var propertyNames = keys(properties);
|
48999 |
|
49000 | return reduce(propertyNames, function(result, key) {
|
49001 |
|
49002 |
|
49003 | if (key !== DI) {
|
49004 | result[key] = businessObject.get(key);
|
49005 | } else {
|
49006 | result[key] = getDiProperties(businessObject.di, keys(properties.di));
|
49007 | }
|
49008 |
|
49009 | return result;
|
49010 | }, {});
|
49011 | }
|
49012 |
|
49013 |
|
49014 | function getDiProperties(di, propertyNames) {
|
49015 | return reduce(propertyNames, function(result, key) {
|
49016 | result[key] = di.get(key);
|
49017 |
|
49018 | return result;
|
49019 | }, {});
|
49020 | }
|
49021 |
|
49022 |
|
49023 | function setProperties(businessObject, properties) {
|
49024 | forEach(properties, function(value, key) {
|
49025 |
|
49026 | if (key !== DI) {
|
49027 | businessObject.set(key, value);
|
49028 | } else {
|
49029 |
|
49030 |
|
49031 | if (businessObject.di) {
|
49032 | setDiProperties(businessObject.di, value);
|
49033 | }
|
49034 | }
|
49035 | });
|
49036 | }
|
49037 |
|
49038 |
|
49039 | function setDiProperties(di, properties) {
|
49040 | forEach(properties, function(value, key) {
|
49041 | di.set(key, value);
|
49042 | });
|
49043 | }
|
49044 |
|
49045 |
|
49046 | var referencePropertyNames = [ 'default' ];
|
49047 |
|
49048 | |
49049 |
|
49050 |
|
49051 |
|
49052 |
|
49053 |
|
49054 |
|
49055 |
|
49056 |
|
49057 | function unwrapBusinessObjects(properties) {
|
49058 |
|
49059 | var unwrappedProps = assign({}, properties);
|
49060 |
|
49061 | referencePropertyNames.forEach(function(name) {
|
49062 | if (name in properties) {
|
49063 | unwrappedProps[name] = getBusinessObject(unwrappedProps[name]);
|
49064 | }
|
49065 | });
|
49066 |
|
49067 | return unwrappedProps;
|
49068 | }
|
49069 |
|
49070 | function UpdateCanvasRootHandler(canvas, modeling) {
|
49071 | this._canvas = canvas;
|
49072 | this._modeling = modeling;
|
49073 | }
|
49074 |
|
49075 | UpdateCanvasRootHandler.$inject = [
|
49076 | 'canvas',
|
49077 | 'modeling'
|
49078 | ];
|
49079 |
|
49080 |
|
49081 | UpdateCanvasRootHandler.prototype.execute = function(context) {
|
49082 |
|
49083 | var canvas = this._canvas;
|
49084 |
|
49085 | var newRoot = context.newRoot,
|
49086 | newRootBusinessObject = newRoot.businessObject,
|
49087 | oldRoot = canvas.getRootElement(),
|
49088 | oldRootBusinessObject = oldRoot.businessObject,
|
49089 | bpmnDefinitions = oldRootBusinessObject.$parent,
|
49090 | diPlane = oldRootBusinessObject.di;
|
49091 |
|
49092 |
|
49093 | canvas.setRootElement(newRoot, true);
|
49094 |
|
49095 |
|
49096 | add$1(bpmnDefinitions.rootElements, newRootBusinessObject);
|
49097 | newRootBusinessObject.$parent = bpmnDefinitions;
|
49098 |
|
49099 | remove$2(bpmnDefinitions.rootElements, oldRootBusinessObject);
|
49100 | oldRootBusinessObject.$parent = null;
|
49101 |
|
49102 |
|
49103 | oldRootBusinessObject.di = null;
|
49104 |
|
49105 | diPlane.bpmnElement = newRootBusinessObject;
|
49106 | newRootBusinessObject.di = diPlane;
|
49107 |
|
49108 | context.oldRoot = oldRoot;
|
49109 |
|
49110 |
|
49111 |
|
49112 | };
|
49113 |
|
49114 |
|
49115 | UpdateCanvasRootHandler.prototype.revert = function(context) {
|
49116 |
|
49117 | var canvas = this._canvas;
|
49118 |
|
49119 | var newRoot = context.newRoot,
|
49120 | newRootBusinessObject = newRoot.businessObject,
|
49121 | oldRoot = context.oldRoot,
|
49122 | oldRootBusinessObject = oldRoot.businessObject,
|
49123 | bpmnDefinitions = newRootBusinessObject.$parent,
|
49124 | diPlane = newRootBusinessObject.di;
|
49125 |
|
49126 |
|
49127 | canvas.setRootElement(oldRoot, true);
|
49128 |
|
49129 |
|
49130 | remove$2(bpmnDefinitions.rootElements, newRootBusinessObject);
|
49131 | newRootBusinessObject.$parent = null;
|
49132 |
|
49133 | add$1(bpmnDefinitions.rootElements, oldRootBusinessObject);
|
49134 | oldRootBusinessObject.$parent = bpmnDefinitions;
|
49135 |
|
49136 |
|
49137 | newRootBusinessObject.di = null;
|
49138 |
|
49139 | diPlane.bpmnElement = oldRootBusinessObject;
|
49140 | oldRootBusinessObject.di = diPlane;
|
49141 |
|
49142 |
|
49143 |
|
49144 | };
|
49145 |
|
49146 | |
49147 |
|
49148 |
|
49149 |
|
49150 |
|
49151 |
|
49152 | function AddLaneHandler(modeling, spaceTool) {
|
49153 | this._modeling = modeling;
|
49154 | this._spaceTool = spaceTool;
|
49155 | }
|
49156 |
|
49157 | AddLaneHandler.$inject = [
|
49158 | 'modeling',
|
49159 | 'spaceTool'
|
49160 | ];
|
49161 |
|
49162 |
|
49163 | AddLaneHandler.prototype.preExecute = function(context) {
|
49164 |
|
49165 | var spaceTool = this._spaceTool,
|
49166 | modeling = this._modeling;
|
49167 |
|
49168 | var shape = context.shape,
|
49169 | location = context.location;
|
49170 |
|
49171 | var lanesRoot = getLanesRoot(shape);
|
49172 |
|
49173 | var isRoot = lanesRoot === shape,
|
49174 | laneParent = isRoot ? shape : shape.parent;
|
49175 |
|
49176 | var existingChildLanes = getChildLanes(laneParent);
|
49177 |
|
49178 |
|
49179 | if (!existingChildLanes.length) {
|
49180 | modeling.createShape({ type: 'bpmn:Lane' }, {
|
49181 | x: shape.x + LANE_INDENTATION,
|
49182 | y: shape.y,
|
49183 | width: shape.width - LANE_INDENTATION,
|
49184 | height: shape.height
|
49185 | }, laneParent);
|
49186 | }
|
49187 |
|
49188 |
|
49189 | var allAffected = [];
|
49190 |
|
49191 | eachElement(lanesRoot, function(element) {
|
49192 | allAffected.push(element);
|
49193 |
|
49194 | if (element === shape) {
|
49195 | return [];
|
49196 | }
|
49197 |
|
49198 | return filter(element.children, function(c) {
|
49199 | return c !== shape;
|
49200 | });
|
49201 | });
|
49202 |
|
49203 | var offset = location === 'top' ? -120 : 120,
|
49204 | lanePosition = location === 'top' ? shape.y : shape.y + shape.height,
|
49205 | spacePos = lanePosition + (location === 'top' ? 10 : -10),
|
49206 | direction = location === 'top' ? 'n' : 's';
|
49207 |
|
49208 | var adjustments = spaceTool.calculateAdjustments(allAffected, 'y', offset, spacePos);
|
49209 |
|
49210 | spaceTool.makeSpace(adjustments.movingShapes, adjustments.resizingShapes, { x: 0, y: offset }, direction);
|
49211 |
|
49212 |
|
49213 | context.newLane = modeling.createShape({ type: 'bpmn:Lane' }, {
|
49214 | x: shape.x + (isRoot ? LANE_INDENTATION : 0),
|
49215 | y: lanePosition - (location === 'top' ? 120 : 0),
|
49216 | width: shape.width - (isRoot ? LANE_INDENTATION : 0),
|
49217 | height: 120
|
49218 | }, laneParent);
|
49219 | };
|
49220 |
|
49221 | |
49222 |
|
49223 |
|
49224 |
|
49225 |
|
49226 |
|
49227 | function SplitLaneHandler(modeling, translate) {
|
49228 | this._modeling = modeling;
|
49229 | this._translate = translate;
|
49230 | }
|
49231 |
|
49232 | SplitLaneHandler.$inject = [
|
49233 | 'modeling',
|
49234 | 'translate'
|
49235 | ];
|
49236 |
|
49237 |
|
49238 | SplitLaneHandler.prototype.preExecute = function(context) {
|
49239 |
|
49240 | var modeling = this._modeling,
|
49241 | translate = this._translate;
|
49242 |
|
49243 | var shape = context.shape,
|
49244 | newLanesCount = context.count;
|
49245 |
|
49246 | var childLanes = getChildLanes(shape),
|
49247 | existingLanesCount = childLanes.length;
|
49248 |
|
49249 | if (existingLanesCount > newLanesCount) {
|
49250 | throw new Error(translate('more than {count} child lanes', { count: newLanesCount }));
|
49251 | }
|
49252 |
|
49253 | var newLanesHeight = Math.round(shape.height / newLanesCount);
|
49254 |
|
49255 |
|
49256 |
|
49257 |
|
49258 |
|
49259 |
|
49260 |
|
49261 | var laneY,
|
49262 | laneHeight,
|
49263 | laneBounds,
|
49264 | newLaneAttrs,
|
49265 | idx;
|
49266 |
|
49267 | for (idx = 0; idx < newLanesCount; idx++) {
|
49268 |
|
49269 | laneY = shape.y + idx * newLanesHeight;
|
49270 |
|
49271 |
|
49272 | if (idx === newLanesCount - 1) {
|
49273 | laneHeight = shape.height - (newLanesHeight * idx);
|
49274 | } else {
|
49275 | laneHeight = newLanesHeight;
|
49276 | }
|
49277 |
|
49278 | laneBounds = {
|
49279 | x: shape.x + LANE_INDENTATION,
|
49280 | y: laneY,
|
49281 | width: shape.width - LANE_INDENTATION,
|
49282 | height: laneHeight
|
49283 | };
|
49284 |
|
49285 | if (idx < existingLanesCount) {
|
49286 |
|
49287 |
|
49288 | modeling.resizeShape(childLanes[idx], laneBounds);
|
49289 | } else {
|
49290 |
|
49291 |
|
49292 | newLaneAttrs = {
|
49293 | type: 'bpmn:Lane'
|
49294 | };
|
49295 |
|
49296 | modeling.createShape(newLaneAttrs, laneBounds, shape);
|
49297 | }
|
49298 | }
|
49299 | };
|
49300 |
|
49301 | |
49302 |
|
49303 |
|
49304 |
|
49305 |
|
49306 | function ResizeLaneHandler(modeling, spaceTool) {
|
49307 | this._modeling = modeling;
|
49308 | this._spaceTool = spaceTool;
|
49309 | }
|
49310 |
|
49311 | ResizeLaneHandler.$inject = [
|
49312 | 'modeling',
|
49313 | 'spaceTool'
|
49314 | ];
|
49315 |
|
49316 |
|
49317 | ResizeLaneHandler.prototype.preExecute = function(context) {
|
49318 |
|
49319 | var shape = context.shape,
|
49320 | newBounds = context.newBounds,
|
49321 | balanced = context.balanced;
|
49322 |
|
49323 | if (balanced !== false) {
|
49324 | this.resizeBalanced(shape, newBounds);
|
49325 | } else {
|
49326 | this.resizeSpace(shape, newBounds);
|
49327 | }
|
49328 | };
|
49329 |
|
49330 |
|
49331 | |
49332 |
|
49333 |
|
49334 |
|
49335 |
|
49336 |
|
49337 | ResizeLaneHandler.prototype.resizeBalanced = function(shape, newBounds) {
|
49338 |
|
49339 | var modeling = this._modeling;
|
49340 |
|
49341 | var resizeNeeded = computeLanesResize(shape, newBounds);
|
49342 |
|
49343 |
|
49344 | modeling.resizeShape(shape, newBounds);
|
49345 |
|
49346 |
|
49347 | resizeNeeded.forEach(function(r) {
|
49348 | modeling.resizeShape(r.shape, r.newBounds);
|
49349 | });
|
49350 | };
|
49351 |
|
49352 |
|
49353 | |
49354 |
|
49355 |
|
49356 |
|
49357 |
|
49358 |
|
49359 | ResizeLaneHandler.prototype.resizeSpace = function(shape, newBounds) {
|
49360 | var spaceTool = this._spaceTool;
|
49361 |
|
49362 | var shapeTrbl = asTRBL(shape),
|
49363 | newTrbl = asTRBL(newBounds);
|
49364 |
|
49365 | var trblDiff = substractTRBL(newTrbl, shapeTrbl);
|
49366 |
|
49367 | var lanesRoot = getLanesRoot(shape);
|
49368 |
|
49369 | var allAffected = [],
|
49370 | allLanes = [];
|
49371 |
|
49372 | eachElement(lanesRoot, function(element) {
|
49373 | allAffected.push(element);
|
49374 |
|
49375 | if (is$1(element, 'bpmn:Lane') || is$1(element, 'bpmn:Participant')) {
|
49376 | allLanes.push(element);
|
49377 | }
|
49378 |
|
49379 | return element.children;
|
49380 | });
|
49381 |
|
49382 | var change,
|
49383 | spacePos,
|
49384 | direction,
|
49385 | offset,
|
49386 | adjustments;
|
49387 |
|
49388 | if (trblDiff.bottom || trblDiff.top) {
|
49389 |
|
49390 | change = trblDiff.bottom || trblDiff.top;
|
49391 | spacePos = shape.y + (trblDiff.bottom ? shape.height : 0) + (trblDiff.bottom ? -10 : 10);
|
49392 | direction = trblDiff.bottom ? 's' : 'n';
|
49393 |
|
49394 | offset = trblDiff.top > 0 || trblDiff.bottom < 0 ? -change : change;
|
49395 |
|
49396 | adjustments = spaceTool.calculateAdjustments(allAffected, 'y', offset, spacePos);
|
49397 |
|
49398 | spaceTool.makeSpace(adjustments.movingShapes, adjustments.resizingShapes, { x: 0, y: change }, direction);
|
49399 | }
|
49400 |
|
49401 |
|
49402 | if (trblDiff.left || trblDiff.right) {
|
49403 |
|
49404 | change = trblDiff.right || trblDiff.left;
|
49405 | spacePos = shape.x + (trblDiff.right ? shape.width : 0) + (trblDiff.right ? -10 : 100);
|
49406 | direction = trblDiff.right ? 'e' : 'w';
|
49407 |
|
49408 | offset = trblDiff.left > 0 || trblDiff.right < 0 ? -change : change;
|
49409 |
|
49410 | adjustments = spaceTool.calculateAdjustments(allLanes, 'x', offset, spacePos);
|
49411 |
|
49412 | spaceTool.makeSpace(adjustments.movingShapes, adjustments.resizingShapes, { x: change, y: 0 }, direction);
|
49413 | }
|
49414 | };
|
49415 |
|
49416 | var FLOW_NODE_REFS_ATTR = 'flowNodeRef',
|
49417 | LANES_ATTR = 'lanes';
|
49418 |
|
49419 |
|
49420 | |
49421 |
|
49422 |
|
49423 | function UpdateFlowNodeRefsHandler(elementRegistry) {
|
49424 | this._elementRegistry = elementRegistry;
|
49425 | }
|
49426 |
|
49427 | UpdateFlowNodeRefsHandler.$inject = [
|
49428 | 'elementRegistry'
|
49429 | ];
|
49430 |
|
49431 |
|
49432 | UpdateFlowNodeRefsHandler.prototype.computeUpdates = function(flowNodeShapes, laneShapes) {
|
49433 |
|
49434 | var handledNodes = {};
|
49435 |
|
49436 | var updates = [];
|
49437 |
|
49438 | var participantCache = {};
|
49439 |
|
49440 | var allFlowNodeShapes = [];
|
49441 |
|
49442 | function isInLaneShape(element, laneShape) {
|
49443 |
|
49444 | var laneTrbl = asTRBL(laneShape);
|
49445 |
|
49446 | var elementMid = {
|
49447 | x: element.x + element.width / 2,
|
49448 | y: element.y + element.height / 2
|
49449 | };
|
49450 |
|
49451 | return elementMid.x > laneTrbl.left &&
|
49452 | elementMid.x < laneTrbl.right &&
|
49453 | elementMid.y > laneTrbl.top &&
|
49454 | elementMid.y < laneTrbl.bottom;
|
49455 | }
|
49456 |
|
49457 | function addFlowNodeShape(flowNodeShape) {
|
49458 | if (!handledNodes[flowNodeShape.id]) {
|
49459 | allFlowNodeShapes.push(flowNodeShape);
|
49460 | handledNodes[flowNodeShape.id] = flowNodeShape;
|
49461 | }
|
49462 | }
|
49463 |
|
49464 | function getAllLaneShapes(flowNodeShape) {
|
49465 |
|
49466 | var root = getLanesRoot(flowNodeShape);
|
49467 |
|
49468 | if (!participantCache[root.id]) {
|
49469 | participantCache[root.id] = collectLanes(root);
|
49470 | }
|
49471 |
|
49472 | return participantCache[root.id];
|
49473 | }
|
49474 |
|
49475 | function getNewLanes(flowNodeShape) {
|
49476 | if (!flowNodeShape.parent) {
|
49477 | return [];
|
49478 | }
|
49479 |
|
49480 | var allLaneShapes = getAllLaneShapes(flowNodeShape);
|
49481 |
|
49482 | return allLaneShapes.filter(function(l) {
|
49483 | return isInLaneShape(flowNodeShape, l);
|
49484 | }).map(function(shape) {
|
49485 | return shape.businessObject;
|
49486 | });
|
49487 | }
|
49488 |
|
49489 | laneShapes.forEach(function(laneShape) {
|
49490 | var root = getLanesRoot(laneShape);
|
49491 |
|
49492 | if (!root || handledNodes[root.id]) {
|
49493 | return;
|
49494 | }
|
49495 |
|
49496 | var children = root.children.filter(function(c) {
|
49497 | return is$1(c, 'bpmn:FlowNode');
|
49498 | });
|
49499 |
|
49500 | children.forEach(addFlowNodeShape);
|
49501 |
|
49502 | handledNodes[root.id] = root;
|
49503 | });
|
49504 |
|
49505 | flowNodeShapes.forEach(addFlowNodeShape);
|
49506 |
|
49507 |
|
49508 | allFlowNodeShapes.forEach(function(flowNodeShape) {
|
49509 |
|
49510 | var flowNode = flowNodeShape.businessObject;
|
49511 |
|
49512 | var lanes = flowNode.get(LANES_ATTR),
|
49513 | remove = lanes.slice(),
|
49514 | add = getNewLanes(flowNodeShape);
|
49515 |
|
49516 | updates.push({ flowNode: flowNode, remove: remove, add: add });
|
49517 | });
|
49518 |
|
49519 | laneShapes.forEach(function(laneShape) {
|
49520 |
|
49521 | var lane = laneShape.businessObject;
|
49522 |
|
49523 |
|
49524 | if (!laneShape.parent) {
|
49525 | lane.get(FLOW_NODE_REFS_ATTR).forEach(function(flowNode) {
|
49526 | updates.push({ flowNode: flowNode, remove: [ lane ], add: [] });
|
49527 | });
|
49528 | }
|
49529 | });
|
49530 |
|
49531 | return updates;
|
49532 | };
|
49533 |
|
49534 | UpdateFlowNodeRefsHandler.prototype.execute = function(context) {
|
49535 |
|
49536 | var updates = context.updates;
|
49537 |
|
49538 | if (!updates) {
|
49539 | updates = context.updates = this.computeUpdates(context.flowNodeShapes, context.laneShapes);
|
49540 | }
|
49541 |
|
49542 |
|
49543 | updates.forEach(function(update) {
|
49544 |
|
49545 | var flowNode = update.flowNode,
|
49546 | lanes = flowNode.get(LANES_ATTR);
|
49547 |
|
49548 |
|
49549 | update.remove.forEach(function(oldLane) {
|
49550 | remove$2(lanes, oldLane);
|
49551 | remove$2(oldLane.get(FLOW_NODE_REFS_ATTR), flowNode);
|
49552 | });
|
49553 |
|
49554 |
|
49555 | update.add.forEach(function(newLane) {
|
49556 | add$1(lanes, newLane);
|
49557 | add$1(newLane.get(FLOW_NODE_REFS_ATTR), flowNode);
|
49558 | });
|
49559 | });
|
49560 |
|
49561 |
|
49562 |
|
49563 | };
|
49564 |
|
49565 |
|
49566 | UpdateFlowNodeRefsHandler.prototype.revert = function(context) {
|
49567 |
|
49568 | var updates = context.updates;
|
49569 |
|
49570 | updates.forEach(function(update) {
|
49571 |
|
49572 | var flowNode = update.flowNode,
|
49573 | lanes = flowNode.get(LANES_ATTR);
|
49574 |
|
49575 |
|
49576 | update.add.forEach(function(newLane) {
|
49577 | remove$2(lanes, newLane);
|
49578 | remove$2(newLane.get(FLOW_NODE_REFS_ATTR), flowNode);
|
49579 | });
|
49580 |
|
49581 |
|
49582 | update.remove.forEach(function(oldLane) {
|
49583 | add$1(lanes, oldLane);
|
49584 | add$1(oldLane.get(FLOW_NODE_REFS_ATTR), flowNode);
|
49585 | });
|
49586 | });
|
49587 |
|
49588 |
|
49589 |
|
49590 | };
|
49591 |
|
49592 | function IdClaimHandler(moddle) {
|
49593 | this._moddle = moddle;
|
49594 | }
|
49595 |
|
49596 | IdClaimHandler.$inject = [ 'moddle' ];
|
49597 |
|
49598 |
|
49599 | IdClaimHandler.prototype.execute = function(context) {
|
49600 | var ids = this._moddle.ids,
|
49601 | id = context.id,
|
49602 | element = context.element,
|
49603 | claiming = context.claiming;
|
49604 |
|
49605 | if (claiming) {
|
49606 | ids.claim(id, element);
|
49607 | } else {
|
49608 | ids.unclaim(id);
|
49609 | }
|
49610 | };
|
49611 |
|
49612 | |
49613 |
|
49614 |
|
49615 | IdClaimHandler.prototype.revert = function(context) {
|
49616 | var ids = this._moddle.ids,
|
49617 | id = context.id,
|
49618 | element = context.element,
|
49619 | claiming = context.claiming;
|
49620 |
|
49621 | if (claiming) {
|
49622 | ids.unclaim(id);
|
49623 | } else {
|
49624 | ids.claim(id, element);
|
49625 | }
|
49626 | };
|
49627 |
|
49628 | var DEFAULT_COLORS = {
|
49629 | fill: undefined,
|
49630 | stroke: undefined
|
49631 | };
|
49632 |
|
49633 |
|
49634 | function SetColorHandler(commandStack) {
|
49635 | this._commandStack = commandStack;
|
49636 | }
|
49637 |
|
49638 | SetColorHandler.$inject = [
|
49639 | 'commandStack'
|
49640 | ];
|
49641 |
|
49642 |
|
49643 | SetColorHandler.prototype.postExecute = function(context) {
|
49644 | var elements = context.elements,
|
49645 | colors = context.colors || DEFAULT_COLORS;
|
49646 |
|
49647 | var self = this;
|
49648 |
|
49649 | var di = {};
|
49650 |
|
49651 | if ('fill' in colors) {
|
49652 | assign(di, { fill: colors.fill });
|
49653 | }
|
49654 |
|
49655 | if ('stroke' in colors) {
|
49656 | assign(di, { stroke: colors.stroke });
|
49657 | }
|
49658 |
|
49659 | forEach(elements, function(element) {
|
49660 |
|
49661 | self._commandStack.execute('element.updateProperties', {
|
49662 | element: element,
|
49663 | properties: {
|
49664 | di: di
|
49665 | }
|
49666 | });
|
49667 | });
|
49668 |
|
49669 | };
|
49670 |
|
49671 | var NULL_DIMENSIONS$1 = {
|
49672 | width: 0,
|
49673 | height: 0
|
49674 | };
|
49675 |
|
49676 |
|
49677 | |
49678 |
|
49679 |
|
49680 | function UpdateLabelHandler(modeling, textRenderer) {
|
49681 |
|
49682 | |
49683 |
|
49684 |
|
49685 |
|
49686 |
|
49687 |
|
49688 |
|
49689 |
|
49690 | function setText(element, text) {
|
49691 |
|
49692 |
|
49693 | var label = element.label || element;
|
49694 |
|
49695 | var labelTarget = element.labelTarget || element;
|
49696 |
|
49697 | setLabel(label, text);
|
49698 |
|
49699 | return [ label, labelTarget ];
|
49700 | }
|
49701 |
|
49702 | function preExecute(ctx) {
|
49703 | var element = ctx.element,
|
49704 | businessObject = element.businessObject,
|
49705 | newLabel = ctx.newLabel;
|
49706 |
|
49707 | if (!isLabel(element)
|
49708 | && isLabelExternal(element)
|
49709 | && !hasExternalLabel(element)
|
49710 | && !isEmptyText$1(newLabel)) {
|
49711 |
|
49712 |
|
49713 | var paddingTop = 7;
|
49714 |
|
49715 | var labelCenter = getExternalLabelMid(element);
|
49716 |
|
49717 | labelCenter = {
|
49718 | x: labelCenter.x,
|
49719 | y: labelCenter.y + paddingTop
|
49720 | };
|
49721 |
|
49722 | modeling.createLabel(element, labelCenter, {
|
49723 | id: businessObject.id + '_label',
|
49724 | businessObject: businessObject
|
49725 | });
|
49726 | }
|
49727 | }
|
49728 |
|
49729 | function execute(ctx) {
|
49730 | ctx.oldLabel = getLabel(ctx.element);
|
49731 | return setText(ctx.element, ctx.newLabel);
|
49732 | }
|
49733 |
|
49734 | function revert(ctx) {
|
49735 | return setText(ctx.element, ctx.oldLabel);
|
49736 | }
|
49737 |
|
49738 | function postExecute(ctx) {
|
49739 | var element = ctx.element,
|
49740 | label = element.label || element,
|
49741 | newLabel = ctx.newLabel,
|
49742 | newBounds = ctx.newBounds,
|
49743 | hints = ctx.hints || {};
|
49744 |
|
49745 | if (isLabel(label) && isEmptyText$1(newLabel)) {
|
49746 |
|
49747 | if (hints.removeShape !== false) {
|
49748 | modeling.removeShape(label, { unsetLabel: false });
|
49749 | }
|
49750 |
|
49751 | return;
|
49752 | }
|
49753 |
|
49754 |
|
49755 | if (!isLabelExternal(element) && !is$1(element, 'bpmn:TextAnnotation')) {
|
49756 | return;
|
49757 | }
|
49758 |
|
49759 | var text = getLabel(label);
|
49760 |
|
49761 |
|
49762 | if (!text) {
|
49763 | return;
|
49764 | }
|
49765 |
|
49766 |
|
49767 | if (typeof newBounds === 'undefined') {
|
49768 | newBounds = textRenderer.getExternalLabelBounds(label, text);
|
49769 | }
|
49770 |
|
49771 |
|
49772 |
|
49773 | if (newBounds) {
|
49774 | modeling.resizeShape(label, newBounds, NULL_DIMENSIONS$1);
|
49775 | }
|
49776 | }
|
49777 |
|
49778 |
|
49779 |
|
49780 | this.preExecute = preExecute;
|
49781 | this.execute = execute;
|
49782 | this.revert = revert;
|
49783 | this.postExecute = postExecute;
|
49784 | }
|
49785 |
|
49786 | UpdateLabelHandler.$inject = [
|
49787 | 'modeling',
|
49788 | 'textRenderer'
|
49789 | ];
|
49790 |
|
49791 |
|
49792 |
|
49793 |
|
49794 | function isEmptyText$1(label) {
|
49795 | return !label || !label.trim();
|
49796 | }
|
49797 |
|
49798 | |
49799 |
|
49800 |
|
49801 |
|
49802 |
|
49803 |
|
49804 |
|
49805 |
|
49806 | function Modeling$1(
|
49807 | eventBus, elementFactory, commandStack,
|
49808 | bpmnRules) {
|
49809 |
|
49810 | Modeling.call(this, eventBus, elementFactory, commandStack);
|
49811 |
|
49812 | this._bpmnRules = bpmnRules;
|
49813 | }
|
49814 |
|
49815 | inherits_browser(Modeling$1, Modeling);
|
49816 |
|
49817 | Modeling$1.$inject = [
|
49818 | 'eventBus',
|
49819 | 'elementFactory',
|
49820 | 'commandStack',
|
49821 | 'bpmnRules'
|
49822 | ];
|
49823 |
|
49824 |
|
49825 | Modeling$1.prototype.getHandlers = function() {
|
49826 | var handlers = Modeling.prototype.getHandlers.call(this);
|
49827 |
|
49828 | handlers['element.updateProperties'] = UpdatePropertiesHandler;
|
49829 | handlers['canvas.updateRoot'] = UpdateCanvasRootHandler;
|
49830 | handlers['lane.add'] = AddLaneHandler;
|
49831 | handlers['lane.resize'] = ResizeLaneHandler;
|
49832 | handlers['lane.split'] = SplitLaneHandler;
|
49833 | handlers['lane.updateRefs'] = UpdateFlowNodeRefsHandler;
|
49834 | handlers['id.updateClaim'] = IdClaimHandler;
|
49835 | handlers['element.setColor'] = SetColorHandler;
|
49836 | handlers['element.updateLabel'] = UpdateLabelHandler;
|
49837 |
|
49838 | return handlers;
|
49839 | };
|
49840 |
|
49841 |
|
49842 | Modeling$1.prototype.updateLabel = function(element, newLabel, newBounds, hints) {
|
49843 | this._commandStack.execute('element.updateLabel', {
|
49844 | element: element,
|
49845 | newLabel: newLabel,
|
49846 | newBounds: newBounds,
|
49847 | hints: hints || {}
|
49848 | });
|
49849 | };
|
49850 |
|
49851 |
|
49852 | Modeling$1.prototype.connect = function(source, target, attrs, hints) {
|
49853 |
|
49854 | var bpmnRules = this._bpmnRules;
|
49855 |
|
49856 | if (!attrs) {
|
49857 | attrs = bpmnRules.canConnect(source, target);
|
49858 | }
|
49859 |
|
49860 | if (!attrs) {
|
49861 | return;
|
49862 | }
|
49863 |
|
49864 | return this.createConnection(source, target, attrs, source.parent, hints);
|
49865 | };
|
49866 |
|
49867 |
|
49868 | Modeling$1.prototype.updateProperties = function(element, properties) {
|
49869 | this._commandStack.execute('element.updateProperties', {
|
49870 | element: element,
|
49871 | properties: properties
|
49872 | });
|
49873 | };
|
49874 |
|
49875 | Modeling$1.prototype.resizeLane = function(laneShape, newBounds, balanced) {
|
49876 | this._commandStack.execute('lane.resize', {
|
49877 | shape: laneShape,
|
49878 | newBounds: newBounds,
|
49879 | balanced: balanced
|
49880 | });
|
49881 | };
|
49882 |
|
49883 | Modeling$1.prototype.addLane = function(targetLaneShape, location) {
|
49884 | var context = {
|
49885 | shape: targetLaneShape,
|
49886 | location: location
|
49887 | };
|
49888 |
|
49889 | this._commandStack.execute('lane.add', context);
|
49890 |
|
49891 | return context.newLane;
|
49892 | };
|
49893 |
|
49894 | Modeling$1.prototype.splitLane = function(targetLane, count) {
|
49895 | this._commandStack.execute('lane.split', {
|
49896 | shape: targetLane,
|
49897 | count: count
|
49898 | });
|
49899 | };
|
49900 |
|
49901 | |
49902 |
|
49903 |
|
49904 |
|
49905 |
|
49906 | Modeling$1.prototype.makeCollaboration = function() {
|
49907 |
|
49908 | var collaborationElement = this._create('root', {
|
49909 | type: 'bpmn:Collaboration'
|
49910 | });
|
49911 |
|
49912 | var context = {
|
49913 | newRoot: collaborationElement
|
49914 | };
|
49915 |
|
49916 | this._commandStack.execute('canvas.updateRoot', context);
|
49917 |
|
49918 | return collaborationElement;
|
49919 | };
|
49920 |
|
49921 | Modeling$1.prototype.updateLaneRefs = function(flowNodeShapes, laneShapes) {
|
49922 |
|
49923 | this._commandStack.execute('lane.updateRefs', {
|
49924 | flowNodeShapes: flowNodeShapes,
|
49925 | laneShapes: laneShapes
|
49926 | });
|
49927 | };
|
49928 |
|
49929 | |
49930 |
|
49931 |
|
49932 |
|
49933 |
|
49934 | Modeling$1.prototype.makeProcess = function() {
|
49935 |
|
49936 | var processElement = this._create('root', {
|
49937 | type: 'bpmn:Process'
|
49938 | });
|
49939 |
|
49940 | var context = {
|
49941 | newRoot: processElement
|
49942 | };
|
49943 |
|
49944 | this._commandStack.execute('canvas.updateRoot', context);
|
49945 | };
|
49946 |
|
49947 |
|
49948 | Modeling$1.prototype.claimId = function(id, moddleElement) {
|
49949 | this._commandStack.execute('id.updateClaim', {
|
49950 | id: id,
|
49951 | element: moddleElement,
|
49952 | claiming: true
|
49953 | });
|
49954 | };
|
49955 |
|
49956 |
|
49957 | Modeling$1.prototype.unclaimId = function(id, moddleElement) {
|
49958 | this._commandStack.execute('id.updateClaim', {
|
49959 | id: id,
|
49960 | element: moddleElement
|
49961 | });
|
49962 | };
|
49963 |
|
49964 | Modeling$1.prototype.setColor = function(elements, colors) {
|
49965 | if (!elements.length) {
|
49966 | elements = [ elements ];
|
49967 | }
|
49968 |
|
49969 | this._commandStack.execute('element.setColor', {
|
49970 | elements: elements,
|
49971 | colors: colors
|
49972 | });
|
49973 | };
|
49974 |
|
49975 | |
49976 |
|
49977 |
|
49978 |
|
49979 |
|
49980 | function BaseLayouter() {}
|
49981 |
|
49982 |
|
49983 | |
49984 |
|
49985 |
|
49986 |
|
49987 |
|
49988 |
|
49989 |
|
49990 |
|
49991 |
|
49992 |
|
49993 |
|
49994 |
|
49995 |
|
49996 |
|
49997 |
|
49998 | BaseLayouter.prototype.layoutConnection = function(connection, hints) {
|
49999 |
|
50000 | hints = hints || {};
|
50001 |
|
50002 | return [
|
50003 | hints.connectionStart || getMid(hints.source || connection.source),
|
50004 | hints.connectionEnd || getMid(hints.target || connection.target)
|
50005 | ];
|
50006 | };
|
50007 |
|
50008 | var MIN_SEGMENT_LENGTH = 20,
|
50009 | POINT_ORIENTATION_PADDING = 5;
|
50010 |
|
50011 | var round$a = Math.round;
|
50012 |
|
50013 | var INTERSECTION_THRESHOLD$1 = 20,
|
50014 | ORIENTATION_THRESHOLD = {
|
50015 | 'h:h': 20,
|
50016 | 'v:v': 20,
|
50017 | 'h:v': -10,
|
50018 | 'v:h': -10
|
50019 | };
|
50020 |
|
50021 | function needsTurn(orientation, startDirection) {
|
50022 | return !{
|
50023 | t: /top/,
|
50024 | r: /right/,
|
50025 | b: /bottom/,
|
50026 | l: /left/,
|
50027 | h: /./,
|
50028 | v: /./
|
50029 | }[startDirection].test(orientation);
|
50030 | }
|
50031 |
|
50032 | function canLayoutStraight(direction, targetOrientation) {
|
50033 | return {
|
50034 | t: /top/,
|
50035 | r: /right/,
|
50036 | b: /bottom/,
|
50037 | l: /left/,
|
50038 | h: /left|right/,
|
50039 | v: /top|bottom/
|
50040 | }[direction].test(targetOrientation);
|
50041 | }
|
50042 |
|
50043 | function getSegmentBendpoints(a, b, directions) {
|
50044 | var orientation = getOrientation(b, a, POINT_ORIENTATION_PADDING);
|
50045 |
|
50046 | var startDirection = directions.split(':')[0];
|
50047 |
|
50048 | var xmid = round$a((b.x - a.x) / 2 + a.x),
|
50049 | ymid = round$a((b.y - a.y) / 2 + a.y);
|
50050 |
|
50051 | var segmentEnd, segmentDirections;
|
50052 |
|
50053 | var layoutStraight = canLayoutStraight(startDirection, orientation),
|
50054 | layoutHorizontal = /h|r|l/.test(startDirection),
|
50055 | layoutTurn = false;
|
50056 |
|
50057 | var turnNextDirections = false;
|
50058 |
|
50059 | if (layoutStraight) {
|
50060 | segmentEnd = layoutHorizontal ? { x: xmid, y: a.y } : { x: a.x, y: ymid };
|
50061 |
|
50062 | segmentDirections = layoutHorizontal ? 'h:h' : 'v:v';
|
50063 | } else {
|
50064 | layoutTurn = needsTurn(orientation, startDirection);
|
50065 |
|
50066 | segmentDirections = layoutHorizontal ? 'h:v' : 'v:h';
|
50067 |
|
50068 | if (layoutTurn) {
|
50069 |
|
50070 | if (layoutHorizontal) {
|
50071 | turnNextDirections = ymid === a.y;
|
50072 |
|
50073 | segmentEnd = {
|
50074 | x: a.x + MIN_SEGMENT_LENGTH * (/l/.test(startDirection) ? -1 : 1),
|
50075 | y: turnNextDirections ? ymid + MIN_SEGMENT_LENGTH : ymid
|
50076 | };
|
50077 | } else {
|
50078 | turnNextDirections = xmid === a.x;
|
50079 |
|
50080 | segmentEnd = {
|
50081 | x: turnNextDirections ? xmid + MIN_SEGMENT_LENGTH : xmid,
|
50082 | y: a.y + MIN_SEGMENT_LENGTH * (/t/.test(startDirection) ? -1 : 1)
|
50083 | };
|
50084 | }
|
50085 |
|
50086 | } else {
|
50087 | segmentEnd = {
|
50088 | x: xmid,
|
50089 | y: ymid
|
50090 | };
|
50091 | }
|
50092 | }
|
50093 |
|
50094 | return {
|
50095 | waypoints: getBendpoints(a, segmentEnd, segmentDirections).concat(segmentEnd),
|
50096 | directions: segmentDirections,
|
50097 | turnNextDirections: turnNextDirections
|
50098 | };
|
50099 | }
|
50100 |
|
50101 | function getStartSegment(a, b, directions) {
|
50102 | return getSegmentBendpoints(a, b, directions);
|
50103 | }
|
50104 |
|
50105 | function getEndSegment(a, b, directions) {
|
50106 | var invertedSegment = getSegmentBendpoints(b, a, invertDirections(directions));
|
50107 |
|
50108 | return {
|
50109 | waypoints: invertedSegment.waypoints.slice().reverse(),
|
50110 | directions: invertDirections(invertedSegment.directions),
|
50111 | turnNextDirections: invertedSegment.turnNextDirections
|
50112 | };
|
50113 | }
|
50114 |
|
50115 | function getMidSegment(startSegment, endSegment) {
|
50116 |
|
50117 | var startDirection = startSegment.directions.split(':')[1],
|
50118 | endDirection = endSegment.directions.split(':')[0];
|
50119 |
|
50120 | if (startSegment.turnNextDirections) {
|
50121 | startDirection = startDirection == 'h' ? 'v' : 'h';
|
50122 | }
|
50123 |
|
50124 | if (endSegment.turnNextDirections) {
|
50125 | endDirection = endDirection == 'h' ? 'v' : 'h';
|
50126 | }
|
50127 |
|
50128 | var directions = startDirection + ':' + endDirection;
|
50129 |
|
50130 | var bendpoints = getBendpoints(
|
50131 | startSegment.waypoints[startSegment.waypoints.length - 1],
|
50132 | endSegment.waypoints[0],
|
50133 | directions
|
50134 | );
|
50135 |
|
50136 | return {
|
50137 | waypoints: bendpoints,
|
50138 | directions: directions
|
50139 | };
|
50140 | }
|
50141 |
|
50142 | function invertDirections(directions) {
|
50143 | return directions.split(':').reverse().join(':');
|
50144 | }
|
50145 |
|
50146 | |
50147 |
|
50148 |
|
50149 | function getSimpleBendpoints(a, b, directions) {
|
50150 |
|
50151 | var xmid = round$a((b.x - a.x) / 2 + a.x),
|
50152 | ymid = round$a((b.y - a.y) / 2 + a.y);
|
50153 |
|
50154 |
|
50155 | if (directions === 'h:v') {
|
50156 | return [ { x: b.x, y: a.y } ];
|
50157 | }
|
50158 |
|
50159 |
|
50160 | if (directions === 'v:h') {
|
50161 | return [ { x: a.x, y: b.y } ];
|
50162 | }
|
50163 |
|
50164 |
|
50165 | if (directions === 'h:h') {
|
50166 | return [
|
50167 | { x: xmid, y: a.y },
|
50168 | { x: xmid, y: b.y }
|
50169 | ];
|
50170 | }
|
50171 |
|
50172 |
|
50173 | if (directions === 'v:v') {
|
50174 | return [
|
50175 | { x: a.x, y: ymid },
|
50176 | { x: b.x, y: ymid }
|
50177 | ];
|
50178 | }
|
50179 |
|
50180 | throw new Error('invalid directions: can only handle varians of [hv]:[hv]');
|
50181 | }
|
50182 |
|
50183 |
|
50184 | |
50185 |
|
50186 |
|
50187 |
|
50188 |
|
50189 |
|
50190 |
|
50191 |
|
50192 |
|
50193 |
|
50194 |
|
50195 |
|
50196 |
|
50197 |
|
50198 |
|
50199 |
|
50200 |
|
50201 |
|
50202 |
|
50203 |
|
50204 |
|
50205 |
|
50206 |
|
50207 |
|
50208 |
|
50209 |
|
50210 |
|
50211 | function getBendpoints(a, b, directions) {
|
50212 | directions = directions || 'h:h';
|
50213 |
|
50214 | if (!isValidDirections(directions)) {
|
50215 | throw new Error(
|
50216 | 'unknown directions: <' + directions + '>: ' +
|
50217 | 'must be specified as <start>:<end> ' +
|
50218 | 'with start/end in { h,v,t,r,b,l }'
|
50219 | );
|
50220 | }
|
50221 |
|
50222 |
|
50223 |
|
50224 | if (isExplicitDirections(directions)) {
|
50225 | var startSegment = getStartSegment(a, b, directions),
|
50226 | endSegment = getEndSegment(a, b, directions),
|
50227 | midSegment = getMidSegment(startSegment, endSegment);
|
50228 |
|
50229 | return [].concat(
|
50230 | startSegment.waypoints,
|
50231 | midSegment.waypoints,
|
50232 | endSegment.waypoints
|
50233 | );
|
50234 | }
|
50235 |
|
50236 |
|
50237 | return getSimpleBendpoints(a, b, directions);
|
50238 | }
|
50239 |
|
50240 | |
50241 |
|
50242 |
|
50243 |
|
50244 |
|
50245 |
|
50246 |
|
50247 |
|
50248 |
|
50249 |
|
50250 |
|
50251 |
|
50252 | function connectPoints(a, b, directions) {
|
50253 |
|
50254 | var points = getBendpoints(a, b, directions);
|
50255 |
|
50256 | points.unshift(a);
|
50257 | points.push(b);
|
50258 |
|
50259 | return withoutRedundantPoints(points);
|
50260 | }
|
50261 |
|
50262 |
|
50263 | |
50264 |
|
50265 |
|
50266 |
|
50267 |
|
50268 |
|
50269 |
|
50270 |
|
50271 |
|
50272 |
|
50273 |
|
50274 |
|
50275 |
|
50276 |
|
50277 |
|
50278 |
|
50279 | function connectRectangles(source, target, start, end, hints) {
|
50280 |
|
50281 | var preferredLayouts = hints && hints.preferredLayouts || [];
|
50282 |
|
50283 | var preferredLayout = without(preferredLayouts, 'straight')[0] || 'h:h';
|
50284 |
|
50285 | var threshold = ORIENTATION_THRESHOLD[preferredLayout] || 0;
|
50286 |
|
50287 | var orientation = getOrientation(source, target, threshold);
|
50288 |
|
50289 | var directions = getDirections(orientation, preferredLayout);
|
50290 |
|
50291 | start = start || getMid(source);
|
50292 | end = end || getMid(target);
|
50293 |
|
50294 | var directionSplit = directions.split(':');
|
50295 |
|
50296 |
|
50297 |
|
50298 |
|
50299 | var startDocking = getDockingPoint(start, source, directionSplit[0], invertOrientation(orientation)),
|
50300 | endDocking = getDockingPoint(end, target, directionSplit[1], orientation);
|
50301 |
|
50302 | return connectPoints(startDocking, endDocking, directions);
|
50303 | }
|
50304 |
|
50305 |
|
50306 | |
50307 |
|
50308 |
|
50309 |
|
50310 |
|
50311 |
|
50312 |
|
50313 |
|
50314 |
|
50315 |
|
50316 |
|
50317 |
|
50318 |
|
50319 |
|
50320 |
|
50321 | function repairConnection(source, target, start, end, waypoints, hints) {
|
50322 |
|
50323 | if (isArray(start)) {
|
50324 | waypoints = start;
|
50325 | hints = end;
|
50326 |
|
50327 | start = getMid(source);
|
50328 | end = getMid(target);
|
50329 | }
|
50330 |
|
50331 | hints = assign({ preferredLayouts: [] }, hints);
|
50332 | waypoints = waypoints || [];
|
50333 |
|
50334 | var preferredLayouts = hints.preferredLayouts,
|
50335 | preferStraight = preferredLayouts.indexOf('straight') !== -1,
|
50336 | repairedWaypoints;
|
50337 |
|
50338 |
|
50339 |
|
50340 |
|
50341 |
|
50342 | repairedWaypoints = preferStraight && tryLayoutStraight(source, target, start, end, hints);
|
50343 |
|
50344 | if (repairedWaypoints) {
|
50345 | return repairedWaypoints;
|
50346 | }
|
50347 |
|
50348 |
|
50349 | repairedWaypoints = hints.connectionEnd && tryRepairConnectionEnd(target, source, end, waypoints);
|
50350 |
|
50351 | if (repairedWaypoints) {
|
50352 | return repairedWaypoints;
|
50353 | }
|
50354 |
|
50355 |
|
50356 | repairedWaypoints = hints.connectionStart && tryRepairConnectionStart(source, target, start, waypoints);
|
50357 |
|
50358 | if (repairedWaypoints) {
|
50359 | return repairedWaypoints;
|
50360 | }
|
50361 |
|
50362 |
|
50363 | if (!hints.connectionStart && !hints.connectionEnd && waypoints && waypoints.length) {
|
50364 | return waypoints;
|
50365 | }
|
50366 |
|
50367 |
|
50368 | return connectRectangles(source, target, start, end, hints);
|
50369 | }
|
50370 |
|
50371 |
|
50372 | function inRange(a, start, end) {
|
50373 | return a >= start && a <= end;
|
50374 | }
|
50375 |
|
50376 | function isInRange(axis, a, b) {
|
50377 | var size = {
|
50378 | x: 'width',
|
50379 | y: 'height'
|
50380 | };
|
50381 |
|
50382 | return inRange(a[axis], b[axis], b[axis] + b[size[axis]]);
|
50383 | }
|
50384 |
|
50385 | |
50386 |
|
50387 |
|
50388 |
|
50389 |
|
50390 |
|
50391 |
|
50392 |
|
50393 |
|
50394 |
|
50395 |
|
50396 | function tryLayoutStraight(source, target, start, end, hints) {
|
50397 | var axis = {},
|
50398 | primaryAxis,
|
50399 | orientation;
|
50400 |
|
50401 | orientation = getOrientation(source, target);
|
50402 |
|
50403 |
|
50404 |
|
50405 | if (!/^(top|bottom|left|right)$/.test(orientation)) {
|
50406 | return null;
|
50407 | }
|
50408 |
|
50409 | if (/top|bottom/.test(orientation)) {
|
50410 | primaryAxis = 'x';
|
50411 | }
|
50412 |
|
50413 | if (/left|right/.test(orientation)) {
|
50414 | primaryAxis = 'y';
|
50415 | }
|
50416 |
|
50417 | if (hints.preserveDocking === 'target') {
|
50418 |
|
50419 | if (!isInRange(primaryAxis, end, source)) {
|
50420 | return null;
|
50421 | }
|
50422 |
|
50423 | axis[primaryAxis] = end[primaryAxis];
|
50424 |
|
50425 | return [
|
50426 | {
|
50427 | x: axis.x !== undefined ? axis.x : start.x,
|
50428 | y: axis.y !== undefined ? axis.y : start.y,
|
50429 | original: {
|
50430 | x: axis.x !== undefined ? axis.x : start.x,
|
50431 | y: axis.y !== undefined ? axis.y : start.y
|
50432 | }
|
50433 | },
|
50434 | {
|
50435 | x: end.x,
|
50436 | y: end.y
|
50437 | }
|
50438 | ];
|
50439 |
|
50440 | } else {
|
50441 |
|
50442 | if (!isInRange(primaryAxis, start, target)) {
|
50443 | return null;
|
50444 | }
|
50445 |
|
50446 | axis[primaryAxis] = start[primaryAxis];
|
50447 |
|
50448 | return [
|
50449 | {
|
50450 | x: start.x,
|
50451 | y: start.y
|
50452 | },
|
50453 | {
|
50454 | x: axis.x !== undefined ? axis.x : end.x,
|
50455 | y: axis.y !== undefined ? axis.y : end.y,
|
50456 | original: {
|
50457 | x: axis.x !== undefined ? axis.x : end.x,
|
50458 | y: axis.y !== undefined ? axis.y : end.y
|
50459 | }
|
50460 | }
|
50461 | ];
|
50462 | }
|
50463 |
|
50464 | }
|
50465 |
|
50466 | |
50467 |
|
50468 |
|
50469 |
|
50470 |
|
50471 |
|
50472 |
|
50473 |
|
50474 |
|
50475 |
|
50476 | function tryRepairConnectionStart(moved, other, newDocking, points) {
|
50477 | return _tryRepairConnectionSide(moved, other, newDocking, points);
|
50478 | }
|
50479 |
|
50480 | |
50481 |
|
50482 |
|
50483 |
|
50484 |
|
50485 |
|
50486 |
|
50487 |
|
50488 |
|
50489 |
|
50490 | function tryRepairConnectionEnd(moved, other, newDocking, points) {
|
50491 | var waypoints = points.slice().reverse();
|
50492 |
|
50493 | waypoints = _tryRepairConnectionSide(moved, other, newDocking, waypoints);
|
50494 |
|
50495 | return waypoints ? waypoints.reverse() : null;
|
50496 | }
|
50497 |
|
50498 | |
50499 |
|
50500 |
|
50501 |
|
50502 |
|
50503 |
|
50504 |
|
50505 |
|
50506 |
|
50507 |
|
50508 | function _tryRepairConnectionSide(moved, other, newDocking, points) {
|
50509 |
|
50510 | function needsRelayout(points) {
|
50511 | if (points.length < 3) {
|
50512 | return true;
|
50513 | }
|
50514 |
|
50515 | if (points.length > 4) {
|
50516 | return false;
|
50517 | }
|
50518 |
|
50519 |
|
50520 |
|
50521 | return !!find(points, function(p, idx) {
|
50522 | var q = points[idx - 1];
|
50523 |
|
50524 | return q && pointDistance(p, q) < 3;
|
50525 | });
|
50526 | }
|
50527 |
|
50528 | function repairBendpoint(candidate, oldPeer, newPeer) {
|
50529 |
|
50530 | var alignment = pointsAligned(oldPeer, candidate);
|
50531 |
|
50532 | switch (alignment) {
|
50533 | case 'v':
|
50534 |
|
50535 |
|
50536 | return { x: newPeer.x, y: candidate.y };
|
50537 | case 'h':
|
50538 |
|
50539 |
|
50540 | return { x: candidate.x, y: newPeer.y };
|
50541 | }
|
50542 |
|
50543 | return { x: candidate.x, y: candidate. y };
|
50544 | }
|
50545 |
|
50546 | function removeOverlapping(points, a, b) {
|
50547 | var i;
|
50548 |
|
50549 | for (i = points.length - 2; i !== 0; i--) {
|
50550 |
|
50551 |
|
50552 | if (pointInRect(points[i], a, INTERSECTION_THRESHOLD$1) ||
|
50553 | pointInRect(points[i], b, INTERSECTION_THRESHOLD$1)) {
|
50554 |
|
50555 |
|
50556 | return points.slice(i);
|
50557 | }
|
50558 | }
|
50559 |
|
50560 | return points;
|
50561 | }
|
50562 |
|
50563 |
|
50564 |
|
50565 |
|
50566 |
|
50567 |
|
50568 | if (needsRelayout(points)) {
|
50569 | return null;
|
50570 | }
|
50571 |
|
50572 | var oldDocking = points[0],
|
50573 | newPoints = points.slice(),
|
50574 | slicedPoints;
|
50575 |
|
50576 |
|
50577 |
|
50578 | newPoints[0] = newDocking;
|
50579 | newPoints[1] = repairBendpoint(newPoints[1], oldDocking, newDocking);
|
50580 |
|
50581 |
|
50582 |
|
50583 |
|
50584 | slicedPoints = removeOverlapping(newPoints, moved, other);
|
50585 |
|
50586 | if (slicedPoints !== newPoints) {
|
50587 | newPoints = _tryRepairConnectionSide(moved, other, newDocking, slicedPoints);
|
50588 | }
|
50589 |
|
50590 |
|
50591 | if (newPoints && pointsAligned(newPoints)) {
|
50592 | return null;
|
50593 | }
|
50594 |
|
50595 | return newPoints;
|
50596 | }
|
50597 |
|
50598 |
|
50599 | |
50600 |
|
50601 |
|
50602 |
|
50603 |
|
50604 |
|
50605 |
|
50606 |
|
50607 |
|
50608 |
|
50609 |
|
50610 |
|
50611 |
|
50612 |
|
50613 |
|
50614 |
|
50615 |
|
50616 |
|
50617 |
|
50618 |
|
50619 |
|
50620 | function getDirections(orientation, defaultLayout) {
|
50621 |
|
50622 |
|
50623 | if (isExplicitDirections(defaultLayout)) {
|
50624 | return defaultLayout;
|
50625 | }
|
50626 |
|
50627 | switch (orientation) {
|
50628 | case 'intersect':
|
50629 | return 't:t';
|
50630 |
|
50631 | case 'top':
|
50632 | case 'bottom':
|
50633 | return 'v:v';
|
50634 |
|
50635 | case 'left':
|
50636 | case 'right':
|
50637 | return 'h:h';
|
50638 |
|
50639 |
|
50640 |
|
50641 |
|
50642 |
|
50643 | default:
|
50644 | return defaultLayout;
|
50645 | }
|
50646 | }
|
50647 |
|
50648 | function isValidDirections(directions) {
|
50649 | return directions && /^h|v|t|r|b|l:h|v|t|r|b|l$/.test(directions);
|
50650 | }
|
50651 |
|
50652 | function isExplicitDirections(directions) {
|
50653 | return directions && /t|r|b|l/.test(directions);
|
50654 | }
|
50655 |
|
50656 | function invertOrientation(orientation) {
|
50657 | return {
|
50658 | 'top': 'bottom',
|
50659 | 'bottom': 'top',
|
50660 | 'left': 'right',
|
50661 | 'right': 'left',
|
50662 | 'top-left': 'bottom-right',
|
50663 | 'bottom-right': 'top-left',
|
50664 | 'top-right': 'bottom-left',
|
50665 | 'bottom-left': 'top-right',
|
50666 | }[orientation];
|
50667 | }
|
50668 |
|
50669 | function getDockingPoint(point, rectangle, dockingDirection, targetOrientation) {
|
50670 |
|
50671 |
|
50672 |
|
50673 |
|
50674 | if (dockingDirection === 'h') {
|
50675 | dockingDirection = /left/.test(targetOrientation) ? 'l' : 'r';
|
50676 | }
|
50677 |
|
50678 | if (dockingDirection === 'v') {
|
50679 | dockingDirection = /top/.test(targetOrientation) ? 't' : 'b';
|
50680 | }
|
50681 |
|
50682 | if (dockingDirection === 't') {
|
50683 | return { original: point, x: point.x, y: rectangle.y };
|
50684 | }
|
50685 |
|
50686 | if (dockingDirection === 'r') {
|
50687 | return { original: point, x: rectangle.x + rectangle.width, y: point.y };
|
50688 | }
|
50689 |
|
50690 | if (dockingDirection === 'b') {
|
50691 | return { original: point, x: point.x, y: rectangle.y + rectangle.height };
|
50692 | }
|
50693 |
|
50694 | if (dockingDirection === 'l') {
|
50695 | return { original: point, x: rectangle.x, y: point.y };
|
50696 | }
|
50697 |
|
50698 | throw new Error('unexpected dockingDirection: <' + dockingDirection + '>');
|
50699 | }
|
50700 |
|
50701 |
|
50702 | |
50703 |
|
50704 |
|
50705 |
|
50706 |
|
50707 |
|
50708 |
|
50709 |
|
50710 |
|
50711 |
|
50712 |
|
50713 |
|
50714 |
|
50715 |
|
50716 |
|
50717 |
|
50718 |
|
50719 |
|
50720 |
|
50721 |
|
50722 |
|
50723 | function withoutRedundantPoints(waypoints) {
|
50724 | return waypoints.reduce(function(points, p, idx) {
|
50725 |
|
50726 | var previous = points[points.length - 1],
|
50727 | next = waypoints[idx + 1];
|
50728 |
|
50729 | if (!pointsOnLine(previous, next, p, 0)) {
|
50730 | points.push(p);
|
50731 | }
|
50732 |
|
50733 | return points;
|
50734 | }, []);
|
50735 | }
|
50736 |
|
50737 | var BOUNDARY_TO_HOST_THRESHOLD = 40;
|
50738 |
|
50739 | function BpmnLayouter() {}
|
50740 |
|
50741 | inherits_browser(BpmnLayouter, BaseLayouter);
|
50742 |
|
50743 |
|
50744 | BpmnLayouter.prototype.layoutConnection = function(connection, hints) {
|
50745 | hints = hints || {};
|
50746 |
|
50747 | var source = hints.source || connection.source,
|
50748 | target = hints.target || connection.target,
|
50749 | waypoints = connection.waypoints,
|
50750 | start = hints.connectionStart,
|
50751 | end = hints.connectionEnd;
|
50752 |
|
50753 | var manhattanOptions,
|
50754 | updatedWaypoints;
|
50755 |
|
50756 | if (!start) {
|
50757 | start = getConnectionDocking(waypoints && waypoints[0], source);
|
50758 | }
|
50759 |
|
50760 | if (!end) {
|
50761 | end = getConnectionDocking(waypoints && waypoints[waypoints.length - 1], target);
|
50762 | }
|
50763 |
|
50764 |
|
50765 |
|
50766 |
|
50767 | if (is$1(connection, 'bpmn:Association') ||
|
50768 | is$1(connection, 'bpmn:DataAssociation')) {
|
50769 |
|
50770 | if (waypoints && !isCompensationAssociation(source, target)) {
|
50771 | return [].concat([ start ], waypoints.slice(1, -1), [ end ]);
|
50772 | }
|
50773 | }
|
50774 |
|
50775 |
|
50776 | if (is$1(connection, 'bpmn:MessageFlow')) {
|
50777 | manhattanOptions = getMessageFlowManhattanOptions(source, target);
|
50778 |
|
50779 | } else
|
50780 |
|
50781 |
|
50782 |
|
50783 |
|
50784 |
|
50785 |
|
50786 |
|
50787 |
|
50788 |
|
50789 |
|
50790 | if (is$1(connection, 'bpmn:SequenceFlow') ||
|
50791 | isCompensationAssociation(source, target)) {
|
50792 |
|
50793 | if (source === target) {
|
50794 | manhattanOptions = {
|
50795 | preferredLayouts: getLoopPreferredLayout(source, connection)
|
50796 | };
|
50797 | } else
|
50798 |
|
50799 | if (is$1(source, 'bpmn:BoundaryEvent')) {
|
50800 |
|
50801 | manhattanOptions = {
|
50802 | preferredLayouts: getBoundaryEventPreferredLayouts(source, target, end)
|
50803 | };
|
50804 |
|
50805 | } else
|
50806 |
|
50807 | if (is$1(source, 'bpmn:Gateway')) {
|
50808 |
|
50809 | manhattanOptions = {
|
50810 | preferredLayouts: [ 'v:h' ]
|
50811 | };
|
50812 | } else
|
50813 |
|
50814 | if (is$1(target, 'bpmn:Gateway')) {
|
50815 |
|
50816 | manhattanOptions = {
|
50817 | preferredLayouts: [ 'h:v' ]
|
50818 | };
|
50819 | }
|
50820 |
|
50821 | else {
|
50822 | manhattanOptions = {
|
50823 | preferredLayouts: [ 'h:h' ]
|
50824 | };
|
50825 | }
|
50826 |
|
50827 | }
|
50828 |
|
50829 | if (manhattanOptions) {
|
50830 |
|
50831 | manhattanOptions = assign(manhattanOptions, hints);
|
50832 |
|
50833 | updatedWaypoints =
|
50834 | withoutRedundantPoints(
|
50835 | repairConnection(
|
50836 | source, target,
|
50837 | start, end,
|
50838 | waypoints,
|
50839 | manhattanOptions
|
50840 | )
|
50841 | );
|
50842 | }
|
50843 |
|
50844 | return updatedWaypoints || [ start, end ];
|
50845 | };
|
50846 |
|
50847 |
|
50848 | function getAttachOrientation(attachedElement) {
|
50849 |
|
50850 | var hostElement = attachedElement.host,
|
50851 | padding = -10;
|
50852 |
|
50853 | return getOrientation(getMid(attachedElement), hostElement, padding);
|
50854 | }
|
50855 |
|
50856 |
|
50857 | function getMessageFlowManhattanOptions(source, target) {
|
50858 | return {
|
50859 | preferredLayouts: [ 'straight', 'v:v' ],
|
50860 | preserveDocking: getMessageFlowPreserveDocking(source, target)
|
50861 | };
|
50862 | }
|
50863 |
|
50864 |
|
50865 | function getMessageFlowPreserveDocking(source, target) {
|
50866 |
|
50867 |
|
50868 |
|
50869 | if (is$1(target, 'bpmn:Participant')) {
|
50870 | return 'source';
|
50871 | }
|
50872 |
|
50873 | if (is$1(source, 'bpmn:Participant')) {
|
50874 | return 'target';
|
50875 | }
|
50876 |
|
50877 |
|
50878 |
|
50879 | if (isExpandedSubProcess$1(target)) {
|
50880 | return 'source';
|
50881 | }
|
50882 |
|
50883 | if (isExpandedSubProcess$1(source)) {
|
50884 | return 'target';
|
50885 | }
|
50886 |
|
50887 |
|
50888 |
|
50889 | if (is$1(target, 'bpmn:Event')) {
|
50890 | return 'target';
|
50891 | }
|
50892 |
|
50893 | if (is$1(source, 'bpmn:Event')) {
|
50894 | return 'source';
|
50895 | }
|
50896 |
|
50897 | return null;
|
50898 | }
|
50899 |
|
50900 |
|
50901 | function getConnectionDocking(point, shape) {
|
50902 | return point ? (point.original || point) : getMid(shape);
|
50903 | }
|
50904 |
|
50905 | function isCompensationAssociation(source, target) {
|
50906 | return is$1(target, 'bpmn:Activity') &&
|
50907 | is$1(source, 'bpmn:BoundaryEvent') &&
|
50908 | target.businessObject.isForCompensation;
|
50909 | }
|
50910 |
|
50911 |
|
50912 | function isExpandedSubProcess$1(element) {
|
50913 | return is$1(element, 'bpmn:SubProcess') && isExpanded(element);
|
50914 | }
|
50915 |
|
50916 | function isSame$1(a, b) {
|
50917 | return a === b;
|
50918 | }
|
50919 |
|
50920 | function isAnyOrientation(orientation, orientations) {
|
50921 | return orientations.indexOf(orientation) !== -1;
|
50922 | }
|
50923 |
|
50924 | var oppositeOrientationMapping = {
|
50925 | 'top': 'bottom',
|
50926 | 'top-right': 'bottom-left',
|
50927 | 'top-left': 'bottom-right',
|
50928 | 'right': 'left',
|
50929 | 'bottom': 'top',
|
50930 | 'bottom-right': 'top-left',
|
50931 | 'bottom-left': 'top-right',
|
50932 | 'left': 'right'
|
50933 | };
|
50934 |
|
50935 | var orientationDirectionMapping = {
|
50936 | top: 't',
|
50937 | right: 'r',
|
50938 | bottom: 'b',
|
50939 | left: 'l'
|
50940 | };
|
50941 |
|
50942 | function getHorizontalOrientation(orientation) {
|
50943 | var matches = /right|left/.exec(orientation);
|
50944 |
|
50945 | return matches && matches[0];
|
50946 | }
|
50947 |
|
50948 | function getVerticalOrientation(orientation) {
|
50949 | var matches = /top|bottom/.exec(orientation);
|
50950 |
|
50951 | return matches && matches[0];
|
50952 | }
|
50953 |
|
50954 | function isOppositeOrientation(a, b) {
|
50955 | return oppositeOrientationMapping[a] === b;
|
50956 | }
|
50957 |
|
50958 | function isOppositeHorizontalOrientation(a, b) {
|
50959 | var horizontalOrientation = getHorizontalOrientation(a);
|
50960 |
|
50961 | var oppositeHorizontalOrientation = oppositeOrientationMapping[horizontalOrientation];
|
50962 |
|
50963 | return b.indexOf(oppositeHorizontalOrientation) !== -1;
|
50964 | }
|
50965 |
|
50966 | function isOppositeVerticalOrientation(a, b) {
|
50967 | var verticalOrientation = getVerticalOrientation(a);
|
50968 |
|
50969 | var oppositeVerticalOrientation = oppositeOrientationMapping[verticalOrientation];
|
50970 |
|
50971 | return b.indexOf(oppositeVerticalOrientation) !== -1;
|
50972 | }
|
50973 |
|
50974 | function isHorizontalOrientation(orientation) {
|
50975 | return orientation === 'right' || orientation === 'left';
|
50976 | }
|
50977 |
|
50978 | function getLoopPreferredLayout(source, connection) {
|
50979 | var waypoints = connection.waypoints;
|
50980 |
|
50981 | var orientation = waypoints && waypoints.length && getOrientation(waypoints[0], source);
|
50982 |
|
50983 | if (orientation === 'top') {
|
50984 | return [ 't:r' ];
|
50985 | } else if (orientation === 'right') {
|
50986 | return [ 'r:b' ];
|
50987 | } else if (orientation === 'left') {
|
50988 | return [ 'l:t' ];
|
50989 | }
|
50990 |
|
50991 | return [ 'b:l' ];
|
50992 | }
|
50993 |
|
50994 | function getBoundaryEventPreferredLayouts(source, target, end) {
|
50995 | var sourceMid = getMid(source),
|
50996 | targetMid = getMid(target),
|
50997 | attachOrientation = getAttachOrientation(source),
|
50998 | sourceLayout,
|
50999 | targetLayout;
|
51000 |
|
51001 | var isLoop = isSame$1(source.host, target);
|
51002 |
|
51003 | var attachedToSide = isAnyOrientation(attachOrientation, [ 'top', 'right', 'bottom', 'left' ]);
|
51004 |
|
51005 | var targetOrientation = getOrientation(targetMid, sourceMid, {
|
51006 | x: source.width / 2 + target.width / 2,
|
51007 | y: source.height / 2 + target.height / 2
|
51008 | });
|
51009 |
|
51010 | if (isLoop) {
|
51011 | return getBoundaryEventLoopLayout(attachOrientation, attachedToSide, source, target, end);
|
51012 | }
|
51013 |
|
51014 |
|
51015 | sourceLayout = getBoundaryEventSourceLayout(attachOrientation, targetOrientation, attachedToSide);
|
51016 |
|
51017 |
|
51018 | targetLayout = getBoundaryEventTargetLayout(attachOrientation, targetOrientation, attachedToSide);
|
51019 |
|
51020 | return [ sourceLayout + ':' + targetLayout ];
|
51021 | }
|
51022 |
|
51023 | function getBoundaryEventLoopLayout(attachOrientation, attachedToSide, source, target, end) {
|
51024 |
|
51025 | var sourceLayout = orientationDirectionMapping[attachedToSide ? attachOrientation : getVerticalOrientation(attachOrientation)],
|
51026 | targetLayout;
|
51027 |
|
51028 | if (attachedToSide) {
|
51029 | if (isHorizontalOrientation(attachOrientation)) {
|
51030 | targetLayout = shouldConnectToSameSide('y', source, target, end) ? 'h' : 'b';
|
51031 | } else {
|
51032 | targetLayout = shouldConnectToSameSide('x', source, target, end) ? 'v' : 'l';
|
51033 | }
|
51034 | } else {
|
51035 | targetLayout = 'v';
|
51036 | }
|
51037 |
|
51038 | return [ sourceLayout + ':' + targetLayout ];
|
51039 | }
|
51040 |
|
51041 | function shouldConnectToSameSide(axis, source, target, end) {
|
51042 | var threshold = BOUNDARY_TO_HOST_THRESHOLD;
|
51043 |
|
51044 | return !(
|
51045 | areCloseOnAxis(axis, end, target, threshold) ||
|
51046 | areCloseOnAxis(axis, end, { x: target.x + target.width, y: target.y + target.height }, threshold) ||
|
51047 | areCloseOnAxis(axis, end, getMid(source), threshold)
|
51048 | );
|
51049 | }
|
51050 |
|
51051 | function areCloseOnAxis(axis, a, b, threshold) {
|
51052 | return Math.abs(a[axis] - b[axis]) < threshold;
|
51053 | }
|
51054 |
|
51055 | function getBoundaryEventSourceLayout(attachOrientation, targetOrientation, attachedToSide) {
|
51056 |
|
51057 |
|
51058 | if (attachedToSide) {
|
51059 | return orientationDirectionMapping[attachOrientation];
|
51060 | }
|
51061 |
|
51062 |
|
51063 |
|
51064 |
|
51065 | if (isSame$1(
|
51066 | getVerticalOrientation(attachOrientation), getVerticalOrientation(targetOrientation)
|
51067 | ) || isOppositeOrientation(
|
51068 | getHorizontalOrientation(attachOrientation), getHorizontalOrientation(targetOrientation)
|
51069 | )) {
|
51070 | return orientationDirectionMapping[getVerticalOrientation(attachOrientation)];
|
51071 | }
|
51072 |
|
51073 |
|
51074 | return orientationDirectionMapping[getHorizontalOrientation(attachOrientation)];
|
51075 | }
|
51076 |
|
51077 | function getBoundaryEventTargetLayout(attachOrientation, targetOrientation, attachedToSide) {
|
51078 |
|
51079 |
|
51080 | if (attachedToSide) {
|
51081 | if (isHorizontalOrientation(attachOrientation)) {
|
51082 |
|
51083 |
|
51084 |
|
51085 |
|
51086 | if (
|
51087 | isOppositeHorizontalOrientation(attachOrientation, targetOrientation) ||
|
51088 | isSame$1(attachOrientation, targetOrientation)
|
51089 | ) {
|
51090 | return 'h';
|
51091 | }
|
51092 |
|
51093 |
|
51094 | return 'v';
|
51095 | } else {
|
51096 |
|
51097 |
|
51098 |
|
51099 |
|
51100 | if (
|
51101 | isOppositeVerticalOrientation(attachOrientation, targetOrientation) ||
|
51102 | isSame$1(attachOrientation, targetOrientation)
|
51103 | ) {
|
51104 | return 'v';
|
51105 | }
|
51106 |
|
51107 |
|
51108 | return 'h';
|
51109 | }
|
51110 | }
|
51111 |
|
51112 |
|
51113 |
|
51114 |
|
51115 |
|
51116 | if (isHorizontalOrientation(targetOrientation) ||
|
51117 | (isSame$1(getVerticalOrientation(attachOrientation), getVerticalOrientation(targetOrientation)) &&
|
51118 | getHorizontalOrientation(targetOrientation))) {
|
51119 | return 'h';
|
51120 | } else {
|
51121 | return 'v';
|
51122 | }
|
51123 | }
|
51124 |
|
51125 | function dockingToPoint(docking) {
|
51126 |
|
51127 |
|
51128 |
|
51129 | return assign({ original: docking.point.original || docking.point }, docking.actual);
|
51130 | }
|
51131 |
|
51132 |
|
51133 | |
51134 |
|
51135 |
|
51136 |
|
51137 |
|
51138 |
|
51139 | function CroppingConnectionDocking(elementRegistry, graphicsFactory) {
|
51140 | this._elementRegistry = elementRegistry;
|
51141 | this._graphicsFactory = graphicsFactory;
|
51142 | }
|
51143 |
|
51144 | CroppingConnectionDocking.$inject = [ 'elementRegistry', 'graphicsFactory' ];
|
51145 |
|
51146 |
|
51147 | |
51148 |
|
51149 |
|
51150 | CroppingConnectionDocking.prototype.getCroppedWaypoints = function(connection, source, target) {
|
51151 |
|
51152 | source = source || connection.source;
|
51153 | target = target || connection.target;
|
51154 |
|
51155 | var sourceDocking = this.getDockingPoint(connection, source, true),
|
51156 | targetDocking = this.getDockingPoint(connection, target);
|
51157 |
|
51158 | var croppedWaypoints = connection.waypoints.slice(sourceDocking.idx + 1, targetDocking.idx);
|
51159 |
|
51160 | croppedWaypoints.unshift(dockingToPoint(sourceDocking));
|
51161 | croppedWaypoints.push(dockingToPoint(targetDocking));
|
51162 |
|
51163 | return croppedWaypoints;
|
51164 | };
|
51165 |
|
51166 | |
51167 |
|
51168 |
|
51169 |
|
51170 |
|
51171 | CroppingConnectionDocking.prototype.getDockingPoint = function(connection, shape, dockStart) {
|
51172 |
|
51173 | var waypoints = connection.waypoints,
|
51174 | dockingIdx,
|
51175 | dockingPoint,
|
51176 | croppedPoint;
|
51177 |
|
51178 | dockingIdx = dockStart ? 0 : waypoints.length - 1;
|
51179 | dockingPoint = waypoints[dockingIdx];
|
51180 |
|
51181 | croppedPoint = this._getIntersection(shape, connection, dockStart);
|
51182 |
|
51183 | return {
|
51184 | point: dockingPoint,
|
51185 | actual: croppedPoint || dockingPoint,
|
51186 | idx: dockingIdx
|
51187 | };
|
51188 | };
|
51189 |
|
51190 |
|
51191 |
|
51192 |
|
51193 | CroppingConnectionDocking.prototype._getIntersection = function(shape, connection, takeFirst) {
|
51194 |
|
51195 | var shapePath = this._getShapePath(shape),
|
51196 | connectionPath = this._getConnectionPath(connection);
|
51197 |
|
51198 | return getElementLineIntersection(shapePath, connectionPath, takeFirst);
|
51199 | };
|
51200 |
|
51201 | CroppingConnectionDocking.prototype._getConnectionPath = function(connection) {
|
51202 | return this._graphicsFactory.getConnectionPath(connection);
|
51203 | };
|
51204 |
|
51205 | CroppingConnectionDocking.prototype._getShapePath = function(shape) {
|
51206 | return this._graphicsFactory.getShapePath(shape);
|
51207 | };
|
51208 |
|
51209 | CroppingConnectionDocking.prototype._getGfx = function(element) {
|
51210 | return this._elementRegistry.getGraphics(element);
|
51211 | };
|
51212 |
|
51213 | var ModelingModule = {
|
51214 | __init__: [
|
51215 | 'modeling',
|
51216 | 'bpmnUpdater'
|
51217 | ],
|
51218 | __depends__: [
|
51219 | BehaviorModule,
|
51220 | RulesModule$1,
|
51221 | OrderingModule,
|
51222 | ReplaceModule$1,
|
51223 | CommandModule,
|
51224 | TooltipsModule,
|
51225 | LabelSupportModule,
|
51226 | AttachSupportModule,
|
51227 | SelectionModule,
|
51228 | ChangeSupportModule,
|
51229 | SpaceToolModule
|
51230 | ],
|
51231 | bpmnFactory: [ 'type', BpmnFactory ],
|
51232 | bpmnUpdater: [ 'type', BpmnUpdater ],
|
51233 | elementFactory: [ 'type', ElementFactory$1 ],
|
51234 | modeling: [ 'type', Modeling$1 ],
|
51235 | layouter: [ 'type', BpmnLayouter ],
|
51236 | connectionDocking: [ 'type', CroppingConnectionDocking ]
|
51237 | };
|
51238 |
|
51239 | var LOW_PRIORITY$g = 500,
|
51240 | MEDIUM_PRIORITY = 1250,
|
51241 | HIGH_PRIORITY$d = 1500;
|
51242 |
|
51243 | var round$b = Math.round;
|
51244 |
|
51245 | function mid$2(element) {
|
51246 | return {
|
51247 | x: element.x + round$b(element.width / 2),
|
51248 | y: element.y + round$b(element.height / 2)
|
51249 | };
|
51250 | }
|
51251 |
|
51252 | |
51253 |
|
51254 |
|
51255 |
|
51256 |
|
51257 |
|
51258 |
|
51259 |
|
51260 |
|
51261 | function MoveEvents(
|
51262 | eventBus, dragging, modeling,
|
51263 | selection, rules) {
|
51264 |
|
51265 |
|
51266 |
|
51267 | function canMove(shapes, delta, position, target) {
|
51268 |
|
51269 | return rules.allowed('elements.move', {
|
51270 | shapes: shapes,
|
51271 | delta: delta,
|
51272 | position: position,
|
51273 | target: target
|
51274 | });
|
51275 | }
|
51276 |
|
51277 |
|
51278 |
|
51279 |
|
51280 |
|
51281 |
|
51282 |
|
51283 |
|
51284 |
|
51285 |
|
51286 |
|
51287 |
|
51288 |
|
51289 |
|
51290 |
|
51291 | eventBus.on('shape.move.start', HIGH_PRIORITY$d, function(event) {
|
51292 |
|
51293 | var context = event.context,
|
51294 | shape = event.shape,
|
51295 | shapes = selection.get().slice();
|
51296 |
|
51297 |
|
51298 |
|
51299 | if (shapes.indexOf(shape) === -1) {
|
51300 | shapes = [ shape ];
|
51301 | }
|
51302 |
|
51303 |
|
51304 |
|
51305 | shapes = removeNested(shapes);
|
51306 |
|
51307 |
|
51308 | assign(context, {
|
51309 | shapes: shapes,
|
51310 | validatedShapes: shapes,
|
51311 | shape: shape
|
51312 | });
|
51313 | });
|
51314 |
|
51315 |
|
51316 |
|
51317 |
|
51318 |
|
51319 |
|
51320 | eventBus.on('shape.move.start', MEDIUM_PRIORITY, function(event) {
|
51321 |
|
51322 | var context = event.context,
|
51323 | validatedShapes = context.validatedShapes,
|
51324 | canExecute;
|
51325 |
|
51326 | canExecute = context.canExecute = canMove(validatedShapes);
|
51327 |
|
51328 |
|
51329 | if (!canExecute) {
|
51330 | return false;
|
51331 | }
|
51332 | });
|
51333 |
|
51334 |
|
51335 |
|
51336 |
|
51337 |
|
51338 | eventBus.on('shape.move.move', LOW_PRIORITY$g, function(event) {
|
51339 |
|
51340 | var context = event.context,
|
51341 | validatedShapes = context.validatedShapes,
|
51342 | hover = event.hover,
|
51343 | delta = { x: event.dx, y: event.dy },
|
51344 | position = { x: event.x, y: event.y },
|
51345 | canExecute;
|
51346 |
|
51347 |
|
51348 | canExecute = canMove(validatedShapes, delta, position, hover);
|
51349 |
|
51350 | context.delta = delta;
|
51351 | context.canExecute = canExecute;
|
51352 |
|
51353 |
|
51354 | if (canExecute === null) {
|
51355 | context.target = null;
|
51356 |
|
51357 | return;
|
51358 | }
|
51359 |
|
51360 | context.target = hover;
|
51361 | });
|
51362 |
|
51363 | eventBus.on('shape.move.end', function(event) {
|
51364 |
|
51365 | var context = event.context;
|
51366 |
|
51367 | var delta = context.delta,
|
51368 | canExecute = context.canExecute,
|
51369 | isAttach = canExecute === 'attach',
|
51370 | shapes = context.shapes;
|
51371 |
|
51372 | if (canExecute === false) {
|
51373 | return false;
|
51374 | }
|
51375 |
|
51376 |
|
51377 |
|
51378 | delta.x = round$b(delta.x);
|
51379 | delta.y = round$b(delta.y);
|
51380 |
|
51381 | if (delta.x === 0 && delta.y === 0) {
|
51382 |
|
51383 |
|
51384 | return;
|
51385 | }
|
51386 |
|
51387 | modeling.moveElements(shapes, delta, context.target, {
|
51388 | primaryShape: context.shape,
|
51389 | attach: isAttach
|
51390 | });
|
51391 | });
|
51392 |
|
51393 |
|
51394 |
|
51395 |
|
51396 | eventBus.on('element.mousedown', function(event) {
|
51397 |
|
51398 | var originalEvent = getOriginal(event);
|
51399 |
|
51400 | if (!originalEvent) {
|
51401 | throw new Error('must supply DOM mousedown event');
|
51402 | }
|
51403 |
|
51404 | return start(originalEvent, event.element);
|
51405 | });
|
51406 |
|
51407 | |
51408 |
|
51409 |
|
51410 |
|
51411 |
|
51412 |
|
51413 |
|
51414 |
|
51415 | function start(event, element, activate, context) {
|
51416 | if (isObject(activate)) {
|
51417 | context = activate;
|
51418 | activate = false;
|
51419 | }
|
51420 |
|
51421 |
|
51422 | if (element.waypoints || !element.parent) {
|
51423 | return;
|
51424 | }
|
51425 |
|
51426 | var referencePoint = mid$2(element);
|
51427 |
|
51428 | dragging.init(event, referencePoint, 'shape.move', {
|
51429 | cursor: 'grabbing',
|
51430 | autoActivate: activate,
|
51431 | data: {
|
51432 | shape: element,
|
51433 | context: context || {}
|
51434 | }
|
51435 | });
|
51436 |
|
51437 |
|
51438 | return true;
|
51439 | }
|
51440 |
|
51441 |
|
51442 |
|
51443 | this.start = start;
|
51444 | }
|
51445 |
|
51446 | MoveEvents.$inject = [
|
51447 | 'eventBus',
|
51448 | 'dragging',
|
51449 | 'modeling',
|
51450 | 'selection',
|
51451 | 'rules'
|
51452 | ];
|
51453 |
|
51454 |
|
51455 | |
51456 |
|
51457 |
|
51458 |
|
51459 |
|
51460 |
|
51461 |
|
51462 |
|
51463 | function removeNested(elements) {
|
51464 |
|
51465 | var ids = groupBy(elements, 'id');
|
51466 |
|
51467 | return filter(elements, function(element) {
|
51468 | while ((element = element.parent)) {
|
51469 |
|
51470 |
|
51471 | if (ids[element.id]) {
|
51472 | return false;
|
51473 | }
|
51474 | }
|
51475 |
|
51476 | return true;
|
51477 | });
|
51478 | }
|
51479 |
|
51480 | var LOW_PRIORITY$h = 499;
|
51481 |
|
51482 | var MARKER_DRAGGING$1 = 'djs-dragging',
|
51483 | MARKER_OK$3 = 'drop-ok',
|
51484 | MARKER_NOT_OK$3 = 'drop-not-ok',
|
51485 | MARKER_NEW_PARENT$1 = 'new-parent',
|
51486 | MARKER_ATTACH$2 = 'attach-ok';
|
51487 |
|
51488 |
|
51489 | |
51490 |
|
51491 |
|
51492 |
|
51493 |
|
51494 |
|
51495 |
|
51496 |
|
51497 | function MovePreview(
|
51498 | eventBus, canvas, styles, previewSupport) {
|
51499 |
|
51500 | function getVisualDragShapes(shapes) {
|
51501 | var elements = getAllDraggedElements(shapes);
|
51502 |
|
51503 | var filteredElements = removeEdges(elements);
|
51504 |
|
51505 | return filteredElements;
|
51506 | }
|
51507 |
|
51508 | function getAllDraggedElements(shapes) {
|
51509 | var allShapes = selfAndAllChildren(shapes, true);
|
51510 |
|
51511 | var allConnections = map(allShapes, function(shape) {
|
51512 | return (shape.incoming || []).concat(shape.outgoing || []);
|
51513 | });
|
51514 |
|
51515 | return flatten(allShapes.concat(allConnections));
|
51516 | }
|
51517 |
|
51518 | |
51519 |
|
51520 |
|
51521 | function setMarker(element, marker) {
|
51522 |
|
51523 | [ MARKER_ATTACH$2, MARKER_OK$3, MARKER_NOT_OK$3, MARKER_NEW_PARENT$1 ].forEach(function(m) {
|
51524 |
|
51525 | if (m === marker) {
|
51526 | canvas.addMarker(element, m);
|
51527 | } else {
|
51528 | canvas.removeMarker(element, m);
|
51529 | }
|
51530 | });
|
51531 | }
|
51532 |
|
51533 | |
51534 |
|
51535 |
|
51536 |
|
51537 |
|
51538 |
|
51539 |
|
51540 | function makeDraggable(context, element, addMarker) {
|
51541 |
|
51542 | previewSupport.addDragger(element, context.dragGroup);
|
51543 |
|
51544 | if (addMarker) {
|
51545 | canvas.addMarker(element, MARKER_DRAGGING$1);
|
51546 | }
|
51547 |
|
51548 | if (context.allDraggedElements) {
|
51549 | context.allDraggedElements.push(element);
|
51550 | } else {
|
51551 | context.allDraggedElements = [ element ];
|
51552 | }
|
51553 | }
|
51554 |
|
51555 |
|
51556 |
|
51557 |
|
51558 | eventBus.on('shape.move.start', LOW_PRIORITY$h, function(event) {
|
51559 | var context = event.context,
|
51560 | dragShapes = context.shapes,
|
51561 | allDraggedElements = context.allDraggedElements;
|
51562 |
|
51563 | var visuallyDraggedShapes = getVisualDragShapes(dragShapes);
|
51564 |
|
51565 | if (!context.dragGroup) {
|
51566 | var dragGroup = create('g');
|
51567 |
|
51568 | attr$1(dragGroup, styles.cls('djs-drag-group', [ 'no-events' ]));
|
51569 |
|
51570 | var defaultLayer = canvas.getDefaultLayer();
|
51571 |
|
51572 | append(defaultLayer, dragGroup);
|
51573 |
|
51574 | context.dragGroup = dragGroup;
|
51575 | }
|
51576 |
|
51577 |
|
51578 | visuallyDraggedShapes.forEach(function(shape) {
|
51579 | previewSupport.addDragger(shape, context.dragGroup);
|
51580 | });
|
51581 |
|
51582 |
|
51583 |
|
51584 | if (!allDraggedElements) {
|
51585 | allDraggedElements = getAllDraggedElements(dragShapes);
|
51586 | } else {
|
51587 | allDraggedElements = flatten([
|
51588 | allDraggedElements,
|
51589 | getAllDraggedElements(dragShapes)
|
51590 | ]);
|
51591 | }
|
51592 |
|
51593 |
|
51594 | forEach(allDraggedElements, function(e) {
|
51595 | canvas.addMarker(e, MARKER_DRAGGING$1);
|
51596 | });
|
51597 |
|
51598 | context.allDraggedElements = allDraggedElements;
|
51599 |
|
51600 |
|
51601 | context.differentParents = haveDifferentParents(dragShapes);
|
51602 | });
|
51603 |
|
51604 |
|
51605 | eventBus.on('shape.move.move', LOW_PRIORITY$h, function(event) {
|
51606 |
|
51607 | var context = event.context,
|
51608 | dragGroup = context.dragGroup,
|
51609 | target = context.target,
|
51610 | parent = context.shape.parent,
|
51611 | canExecute = context.canExecute;
|
51612 |
|
51613 | if (target) {
|
51614 | if (canExecute === 'attach') {
|
51615 | setMarker(target, MARKER_ATTACH$2);
|
51616 | } else if (context.canExecute && target && target.id !== parent.id) {
|
51617 | setMarker(target, MARKER_NEW_PARENT$1);
|
51618 | } else {
|
51619 | setMarker(target, context.canExecute ? MARKER_OK$3 : MARKER_NOT_OK$3);
|
51620 | }
|
51621 | }
|
51622 |
|
51623 | translate(dragGroup, event.dx, event.dy);
|
51624 | });
|
51625 |
|
51626 | eventBus.on([ 'shape.move.out', 'shape.move.cleanup' ], function(event) {
|
51627 | var context = event.context,
|
51628 | target = context.target;
|
51629 |
|
51630 | if (target) {
|
51631 | setMarker(target, null);
|
51632 | }
|
51633 | });
|
51634 |
|
51635 |
|
51636 | eventBus.on('shape.move.cleanup', function(event) {
|
51637 |
|
51638 | var context = event.context,
|
51639 | allDraggedElements = context.allDraggedElements,
|
51640 | dragGroup = context.dragGroup;
|
51641 |
|
51642 |
|
51643 |
|
51644 | forEach(allDraggedElements, function(e) {
|
51645 | canvas.removeMarker(e, MARKER_DRAGGING$1);
|
51646 | });
|
51647 |
|
51648 | if (dragGroup) {
|
51649 | remove$1(dragGroup);
|
51650 | }
|
51651 | });
|
51652 |
|
51653 |
|
51654 |
|
51655 |
|
51656 | |
51657 |
|
51658 |
|
51659 |
|
51660 |
|
51661 |
|
51662 |
|
51663 | this.makeDraggable = makeDraggable;
|
51664 | }
|
51665 |
|
51666 | MovePreview.$inject = [
|
51667 | 'eventBus',
|
51668 | 'canvas',
|
51669 | 'styles',
|
51670 | 'previewSupport'
|
51671 | ];
|
51672 |
|
51673 |
|
51674 |
|
51675 |
|
51676 | |
51677 |
|
51678 |
|
51679 |
|
51680 | function removeEdges(elements) {
|
51681 |
|
51682 | var filteredElements = filter(elements, function(element) {
|
51683 |
|
51684 | if (!isConnection$7(element)) {
|
51685 | return true;
|
51686 | } else {
|
51687 |
|
51688 | return (
|
51689 | find(elements, matchPattern({ id: element.source.id })) &&
|
51690 | find(elements, matchPattern({ id: element.target.id }))
|
51691 | );
|
51692 | }
|
51693 | });
|
51694 |
|
51695 | return filteredElements;
|
51696 | }
|
51697 |
|
51698 | function haveDifferentParents(elements) {
|
51699 | return size(groupBy(elements, function(e) { return e.parent && e.parent.id; })) !== 1;
|
51700 | }
|
51701 |
|
51702 | |
51703 |
|
51704 |
|
51705 | function isConnection$7(element) {
|
51706 | return element.waypoints;
|
51707 | }
|
51708 |
|
51709 | var MoveModule = {
|
51710 | __depends__: [
|
51711 | InteractionEventsModule,
|
51712 | SelectionModule,
|
51713 | OutlineModule,
|
51714 | RulesModule,
|
51715 | DraggingModule,
|
51716 | PreviewSupportModule
|
51717 | ],
|
51718 | __init__: [
|
51719 | 'move',
|
51720 | 'movePreview'
|
51721 | ],
|
51722 | move: [ 'type', MoveEvents ],
|
51723 | movePreview: [ 'type', MovePreview ]
|
51724 | };
|
51725 |
|
51726 | var TOGGLE_SELECTOR = '.djs-palette-toggle',
|
51727 | ENTRY_SELECTOR = '.entry',
|
51728 | ELEMENT_SELECTOR = TOGGLE_SELECTOR + ', ' + ENTRY_SELECTOR;
|
51729 |
|
51730 | var PALETTE_OPEN_CLS = 'open',
|
51731 | PALETTE_TWO_COLUMN_CLS = 'two-column';
|
51732 |
|
51733 |
|
51734 | |
51735 |
|
51736 |
|
51737 | function Palette(eventBus, canvas) {
|
51738 |
|
51739 | this._eventBus = eventBus;
|
51740 | this._canvas = canvas;
|
51741 |
|
51742 | this._providers = [];
|
51743 |
|
51744 | var self = this;
|
51745 |
|
51746 | eventBus.on('tool-manager.update', function(event) {
|
51747 | var tool = event.tool;
|
51748 |
|
51749 | self.updateToolHighlight(tool);
|
51750 | });
|
51751 |
|
51752 | eventBus.on('i18n.changed', function() {
|
51753 | self._update();
|
51754 | });
|
51755 |
|
51756 | eventBus.on('diagram.init', function() {
|
51757 |
|
51758 | self._diagramInitialized = true;
|
51759 |
|
51760 |
|
51761 | if (self._providers.length) {
|
51762 | self._init();
|
51763 |
|
51764 | self._update();
|
51765 | }
|
51766 | });
|
51767 | }
|
51768 |
|
51769 | Palette.$inject = [ 'eventBus', 'canvas' ];
|
51770 |
|
51771 |
|
51772 | |
51773 |
|
51774 |
|
51775 |
|
51776 |
|
51777 | Palette.prototype.registerProvider = function(provider) {
|
51778 | this._providers.push(provider);
|
51779 |
|
51780 |
|
51781 | if (!this._diagramInitialized) {
|
51782 | return;
|
51783 | }
|
51784 |
|
51785 | if (!this._container) {
|
51786 | this._init();
|
51787 | }
|
51788 |
|
51789 | this._update();
|
51790 | };
|
51791 |
|
51792 |
|
51793 | |
51794 |
|
51795 |
|
51796 |
|
51797 |
|
51798 | Palette.prototype.getEntries = function() {
|
51799 |
|
51800 | var entries = {};
|
51801 |
|
51802 |
|
51803 |
|
51804 | forEach(this._providers, function(provider) {
|
51805 | var e = provider.getPaletteEntries();
|
51806 |
|
51807 | forEach(e, function(entry, id) {
|
51808 | entries[id] = entry;
|
51809 | });
|
51810 | });
|
51811 |
|
51812 | return entries;
|
51813 | };
|
51814 |
|
51815 | |
51816 |
|
51817 |
|
51818 | Palette.prototype._init = function() {
|
51819 | var self = this;
|
51820 |
|
51821 | var eventBus = this._eventBus;
|
51822 |
|
51823 | var parentContainer = this._getParentContainer();
|
51824 |
|
51825 | var container = this._container = domify(Palette.HTML_MARKUP);
|
51826 |
|
51827 | parentContainer.appendChild(container);
|
51828 |
|
51829 | delegateEvents.bind(container, ELEMENT_SELECTOR, 'click', function(event) {
|
51830 |
|
51831 | var target = event.delegateTarget;
|
51832 |
|
51833 | if (matchesSelector$1(target, TOGGLE_SELECTOR)) {
|
51834 | return self.toggle();
|
51835 | }
|
51836 |
|
51837 | self.trigger('click', event);
|
51838 | });
|
51839 |
|
51840 |
|
51841 | componentEvent.bind(container, 'mousedown', function(event) {
|
51842 | event.stopPropagation();
|
51843 | });
|
51844 |
|
51845 |
|
51846 | delegateEvents.bind(container, ENTRY_SELECTOR, 'dragstart', function(event) {
|
51847 | self.trigger('dragstart', event);
|
51848 | });
|
51849 |
|
51850 | eventBus.on('canvas.resized', this._layoutChanged, this);
|
51851 |
|
51852 | eventBus.fire('palette.create', {
|
51853 | container: container
|
51854 | });
|
51855 | };
|
51856 |
|
51857 | |
51858 |
|
51859 |
|
51860 |
|
51861 |
|
51862 | Palette.prototype._toggleState = function(state) {
|
51863 |
|
51864 | state = state || {};
|
51865 |
|
51866 | var parent = this._getParentContainer(),
|
51867 | container = this._container;
|
51868 |
|
51869 | var eventBus = this._eventBus;
|
51870 |
|
51871 | var twoColumn;
|
51872 |
|
51873 | var cls = classes(container);
|
51874 |
|
51875 | if ('twoColumn' in state) {
|
51876 | twoColumn = state.twoColumn;
|
51877 | } else {
|
51878 | twoColumn = this._needsCollapse(parent.clientHeight, this._entries || {});
|
51879 | }
|
51880 |
|
51881 |
|
51882 | cls.toggle(PALETTE_TWO_COLUMN_CLS, twoColumn);
|
51883 |
|
51884 | if ('open' in state) {
|
51885 | cls.toggle(PALETTE_OPEN_CLS, state.open);
|
51886 | }
|
51887 |
|
51888 | eventBus.fire('palette.changed', {
|
51889 | twoColumn: twoColumn,
|
51890 | open: this.isOpen()
|
51891 | });
|
51892 | };
|
51893 |
|
51894 | Palette.prototype._update = function() {
|
51895 |
|
51896 | var entriesContainer = query('.djs-palette-entries', this._container),
|
51897 | entries = this._entries = this.getEntries();
|
51898 |
|
51899 | clear(entriesContainer);
|
51900 |
|
51901 | forEach(entries, function(entry, id) {
|
51902 |
|
51903 | var grouping = entry.group || 'default';
|
51904 |
|
51905 | var container = query('[data-group=' + grouping + ']', entriesContainer);
|
51906 | if (!container) {
|
51907 | container = domify('<div class="group" data-group="' + grouping + '"></div>');
|
51908 | entriesContainer.appendChild(container);
|
51909 | }
|
51910 |
|
51911 | var html = entry.html || (
|
51912 | entry.separator ?
|
51913 | '<hr class="separator" />' :
|
51914 | '<div class="entry" draggable="true"></div>');
|
51915 |
|
51916 |
|
51917 | var control = domify(html);
|
51918 | container.appendChild(control);
|
51919 |
|
51920 | if (!entry.separator) {
|
51921 | attr(control, 'data-action', id);
|
51922 |
|
51923 | if (entry.title) {
|
51924 | attr(control, 'title', entry.title);
|
51925 | }
|
51926 |
|
51927 | if (entry.className) {
|
51928 | addClasses$1(control, entry.className);
|
51929 | }
|
51930 |
|
51931 | if (entry.imageUrl) {
|
51932 | control.appendChild(domify('<img src="' + entry.imageUrl + '">'));
|
51933 | }
|
51934 | }
|
51935 | });
|
51936 |
|
51937 |
|
51938 | this.open();
|
51939 | };
|
51940 |
|
51941 |
|
51942 | |
51943 |
|
51944 |
|
51945 |
|
51946 |
|
51947 |
|
51948 | Palette.prototype.trigger = function(action, event, autoActivate) {
|
51949 | var entries = this._entries,
|
51950 | entry,
|
51951 | handler,
|
51952 | originalEvent,
|
51953 | button = event.delegateTarget || event.target;
|
51954 |
|
51955 | if (!button) {
|
51956 | return event.preventDefault();
|
51957 | }
|
51958 |
|
51959 | entry = entries[attr(button, 'data-action')];
|
51960 |
|
51961 |
|
51962 | if (!entry) {
|
51963 | return;
|
51964 | }
|
51965 |
|
51966 | handler = entry.action;
|
51967 |
|
51968 | originalEvent = event.originalEvent || event;
|
51969 |
|
51970 |
|
51971 | if (isFunction(handler)) {
|
51972 | if (action === 'click') {
|
51973 | handler(originalEvent, autoActivate);
|
51974 | }
|
51975 | } else {
|
51976 | if (handler[action]) {
|
51977 | handler[action](originalEvent, autoActivate);
|
51978 | }
|
51979 | }
|
51980 |
|
51981 |
|
51982 | event.preventDefault();
|
51983 | };
|
51984 |
|
51985 | Palette.prototype._layoutChanged = function() {
|
51986 | this._toggleState({});
|
51987 | };
|
51988 |
|
51989 | |
51990 |
|
51991 |
|
51992 |
|
51993 |
|
51994 |
|
51995 |
|
51996 |
|
51997 | Palette.prototype._needsCollapse = function(availableHeight, entries) {
|
51998 |
|
51999 |
|
52000 |
|
52001 |
|
52002 | var margin = 20 + 10 + 20;
|
52003 |
|
52004 | var entriesHeight = Object.keys(entries).length * 46;
|
52005 |
|
52006 | return availableHeight < entriesHeight + margin;
|
52007 | };
|
52008 |
|
52009 | |
52010 |
|
52011 |
|
52012 | Palette.prototype.close = function() {
|
52013 |
|
52014 | this._toggleState({
|
52015 | open: false,
|
52016 | twoColumn: false
|
52017 | });
|
52018 | };
|
52019 |
|
52020 |
|
52021 | |
52022 |
|
52023 |
|
52024 | Palette.prototype.open = function() {
|
52025 | this._toggleState({ open: true });
|
52026 | };
|
52027 |
|
52028 |
|
52029 | Palette.prototype.toggle = function(open) {
|
52030 | if (this.isOpen()) {
|
52031 | this.close();
|
52032 | } else {
|
52033 | this.open();
|
52034 | }
|
52035 | };
|
52036 |
|
52037 | Palette.prototype.isActiveTool = function(tool) {
|
52038 | return tool && this._activeTool === tool;
|
52039 | };
|
52040 |
|
52041 | Palette.prototype.updateToolHighlight = function(name) {
|
52042 | var entriesContainer,
|
52043 | toolsContainer;
|
52044 |
|
52045 | if (!this._toolsContainer) {
|
52046 | entriesContainer = query('.djs-palette-entries', this._container);
|
52047 |
|
52048 | this._toolsContainer = query('[data-group=tools]', entriesContainer);
|
52049 | }
|
52050 |
|
52051 | toolsContainer = this._toolsContainer;
|
52052 |
|
52053 | forEach(toolsContainer.children, function(tool) {
|
52054 | var actionName = tool.getAttribute('data-action');
|
52055 |
|
52056 | if (!actionName) {
|
52057 | return;
|
52058 | }
|
52059 |
|
52060 | var toolClasses = classes(tool);
|
52061 |
|
52062 | actionName = actionName.replace('-tool', '');
|
52063 |
|
52064 | if (toolClasses.contains('entry') && actionName === name) {
|
52065 | toolClasses.add('highlighted-entry');
|
52066 | } else {
|
52067 | toolClasses.remove('highlighted-entry');
|
52068 | }
|
52069 | });
|
52070 | };
|
52071 |
|
52072 |
|
52073 | |
52074 |
|
52075 |
|
52076 |
|
52077 |
|
52078 |
|
52079 |
|
52080 |
|
52081 |
|
52082 |
|
52083 |
|
52084 |
|
52085 |
|
52086 | Palette.prototype.isOpen = function() {
|
52087 | return classes(this._container).has(PALETTE_OPEN_CLS);
|
52088 | };
|
52089 |
|
52090 | |
52091 |
|
52092 |
|
52093 |
|
52094 |
|
52095 | Palette.prototype._getParentContainer = function() {
|
52096 | return this._canvas.getContainer();
|
52097 | };
|
52098 |
|
52099 |
|
52100 |
|
52101 |
|
52102 | Palette.HTML_MARKUP =
|
52103 | '<div class="djs-palette">' +
|
52104 | '<div class="djs-palette-entries"></div>' +
|
52105 | '<div class="djs-palette-toggle"></div>' +
|
52106 | '</div>';
|
52107 |
|
52108 |
|
52109 |
|
52110 |
|
52111 | function addClasses$1(element, classNames) {
|
52112 |
|
52113 | var classes$1 = classes(element);
|
52114 |
|
52115 | var actualClassNames = isArray(classNames) ? classNames : classNames.split(/\s+/g);
|
52116 | actualClassNames.forEach(function(cls) {
|
52117 | classes$1.add(cls);
|
52118 | });
|
52119 | }
|
52120 |
|
52121 | var PaletteModule = {
|
52122 | __init__: [ 'palette' ],
|
52123 | palette: [ 'type', Palette ]
|
52124 | };
|
52125 |
|
52126 | var LASSO_TOOL_CURSOR = 'crosshair';
|
52127 |
|
52128 |
|
52129 | function LassoTool(
|
52130 | eventBus, canvas, dragging,
|
52131 | elementRegistry, selection, toolManager) {
|
52132 |
|
52133 | this._selection = selection;
|
52134 | this._dragging = dragging;
|
52135 |
|
52136 | var self = this;
|
52137 |
|
52138 |
|
52139 |
|
52140 | |
52141 |
|
52142 |
|
52143 | var visuals = {
|
52144 |
|
52145 | create: function(context) {
|
52146 | var container = canvas.getDefaultLayer(),
|
52147 | frame;
|
52148 |
|
52149 | frame = context.frame = create('rect');
|
52150 | attr$1(frame, {
|
52151 | class: 'djs-lasso-overlay',
|
52152 | width: 1,
|
52153 | height: 1,
|
52154 | x: 0,
|
52155 | y: 0
|
52156 | });
|
52157 |
|
52158 | append(container, frame);
|
52159 | },
|
52160 |
|
52161 | update: function(context) {
|
52162 | var frame = context.frame,
|
52163 | bbox = context.bbox;
|
52164 |
|
52165 | attr$1(frame, {
|
52166 | x: bbox.x,
|
52167 | y: bbox.y,
|
52168 | width: bbox.width,
|
52169 | height: bbox.height
|
52170 | });
|
52171 | },
|
52172 |
|
52173 | remove: function(context) {
|
52174 |
|
52175 | if (context.frame) {
|
52176 | remove$1(context.frame);
|
52177 | }
|
52178 | }
|
52179 | };
|
52180 |
|
52181 | toolManager.registerTool('lasso', {
|
52182 | tool: 'lasso.selection',
|
52183 | dragging: 'lasso'
|
52184 | });
|
52185 |
|
52186 | eventBus.on('lasso.selection.end', function(event) {
|
52187 | var target = event.originalEvent.target;
|
52188 |
|
52189 |
|
52190 |
|
52191 | if (!event.hover && !(target instanceof SVGElement)) {
|
52192 | return;
|
52193 | }
|
52194 |
|
52195 | eventBus.once('lasso.selection.ended', function() {
|
52196 | self.activateLasso(event.originalEvent, true);
|
52197 | });
|
52198 | });
|
52199 |
|
52200 |
|
52201 |
|
52202 | eventBus.on('lasso.end', function(event) {
|
52203 |
|
52204 | var bbox = toBBox(event);
|
52205 |
|
52206 | var elements = elementRegistry.filter(function(element) {
|
52207 | return element;
|
52208 | });
|
52209 |
|
52210 | self.select(elements, bbox);
|
52211 | });
|
52212 |
|
52213 | eventBus.on('lasso.start', function(event) {
|
52214 |
|
52215 | var context = event.context;
|
52216 |
|
52217 | context.bbox = toBBox(event);
|
52218 | visuals.create(context);
|
52219 | });
|
52220 |
|
52221 | eventBus.on('lasso.move', function(event) {
|
52222 |
|
52223 | var context = event.context;
|
52224 |
|
52225 | context.bbox = toBBox(event);
|
52226 | visuals.update(context);
|
52227 | });
|
52228 |
|
52229 | eventBus.on('lasso.cleanup', function(event) {
|
52230 |
|
52231 | var context = event.context;
|
52232 |
|
52233 | visuals.remove(context);
|
52234 | });
|
52235 |
|
52236 |
|
52237 |
|
52238 |
|
52239 | eventBus.on('element.mousedown', 1500, function(event) {
|
52240 |
|
52241 | if (hasSecondaryModifier(event)) {
|
52242 | self.activateLasso(event.originalEvent);
|
52243 |
|
52244 |
|
52245 | return true;
|
52246 | }
|
52247 | });
|
52248 | }
|
52249 |
|
52250 | LassoTool.$inject = [
|
52251 | 'eventBus',
|
52252 | 'canvas',
|
52253 | 'dragging',
|
52254 | 'elementRegistry',
|
52255 | 'selection',
|
52256 | 'toolManager'
|
52257 | ];
|
52258 |
|
52259 |
|
52260 | LassoTool.prototype.activateLasso = function(event, autoActivate) {
|
52261 |
|
52262 | this._dragging.init(event, 'lasso', {
|
52263 | autoActivate: autoActivate,
|
52264 | cursor: LASSO_TOOL_CURSOR,
|
52265 | data: {
|
52266 | context: {}
|
52267 | }
|
52268 | });
|
52269 | };
|
52270 |
|
52271 | LassoTool.prototype.activateSelection = function(event) {
|
52272 |
|
52273 | this._dragging.init(event, 'lasso.selection', {
|
52274 | trapClick: false,
|
52275 | cursor: LASSO_TOOL_CURSOR,
|
52276 | data: {
|
52277 | context: {}
|
52278 | }
|
52279 | });
|
52280 | };
|
52281 |
|
52282 | LassoTool.prototype.select = function(elements, bbox) {
|
52283 | var selectedElements = getEnclosedElements(elements, bbox);
|
52284 |
|
52285 | this._selection.select(values(selectedElements));
|
52286 | };
|
52287 |
|
52288 | LassoTool.prototype.toggle = function() {
|
52289 | if (this.isActive()) {
|
52290 | this._dragging.cancel();
|
52291 | } else {
|
52292 | this.activateSelection();
|
52293 | }
|
52294 | };
|
52295 |
|
52296 | LassoTool.prototype.isActive = function() {
|
52297 | var context = this._dragging.context();
|
52298 |
|
52299 | return context && /^lasso/.test(context.prefix);
|
52300 | };
|
52301 |
|
52302 |
|
52303 |
|
52304 | function toBBox(event) {
|
52305 |
|
52306 | var start = {
|
52307 |
|
52308 | x: event.x - event.dx,
|
52309 | y: event.y - event.dy
|
52310 | };
|
52311 |
|
52312 | var end = {
|
52313 | x: event.x,
|
52314 | y: event.y
|
52315 | };
|
52316 |
|
52317 | var bbox;
|
52318 |
|
52319 | if ((start.x <= end.x && start.y < end.y) ||
|
52320 | (start.x < end.x && start.y <= end.y)) {
|
52321 |
|
52322 | bbox = {
|
52323 | x: start.x,
|
52324 | y: start.y,
|
52325 | width: end.x - start.x,
|
52326 | height: end.y - start.y
|
52327 | };
|
52328 | } else if ((start.x >= end.x && start.y < end.y) ||
|
52329 | (start.x > end.x && start.y <= end.y)) {
|
52330 |
|
52331 | bbox = {
|
52332 | x: end.x,
|
52333 | y: start.y,
|
52334 | width: start.x - end.x,
|
52335 | height: end.y - start.y
|
52336 | };
|
52337 | } else if ((start.x <= end.x && start.y > end.y) ||
|
52338 | (start.x < end.x && start.y >= end.y)) {
|
52339 |
|
52340 | bbox = {
|
52341 | x: start.x,
|
52342 | y: end.y,
|
52343 | width: end.x - start.x,
|
52344 | height: start.y - end.y
|
52345 | };
|
52346 | } else if ((start.x >= end.x && start.y > end.y) ||
|
52347 | (start.x > end.x && start.y >= end.y)) {
|
52348 |
|
52349 | bbox = {
|
52350 | x: end.x,
|
52351 | y: end.y,
|
52352 | width: start.x - end.x,
|
52353 | height: start.y - end.y
|
52354 | };
|
52355 | } else {
|
52356 |
|
52357 | bbox = {
|
52358 | x: end.x,
|
52359 | y: end.y,
|
52360 | width: 0,
|
52361 | height: 0
|
52362 | };
|
52363 | }
|
52364 | return bbox;
|
52365 | }
|
52366 |
|
52367 | var LassoToolModule = {
|
52368 | __depends__: [
|
52369 | ToolManagerModule
|
52370 | ],
|
52371 | __init__: [ 'lassoTool' ],
|
52372 | lassoTool: [ 'type', LassoTool ]
|
52373 | };
|
52374 |
|
52375 | var HIGH_PRIORITY$e = 1500;
|
52376 | var HAND_CURSOR = 'grab';
|
52377 |
|
52378 |
|
52379 | function HandTool(eventBus, canvas, dragging, injector, toolManager) {
|
52380 | this._dragging = dragging;
|
52381 |
|
52382 | var self = this,
|
52383 | keyboard = injector.get('keyboard', false);
|
52384 |
|
52385 | toolManager.registerTool('hand', {
|
52386 | tool: 'hand',
|
52387 | dragging: 'hand.move'
|
52388 | });
|
52389 |
|
52390 | eventBus.on('element.mousedown', HIGH_PRIORITY$e, function(event) {
|
52391 | if (hasPrimaryModifier(event)) {
|
52392 | this.activateMove(event.originalEvent);
|
52393 |
|
52394 | return false;
|
52395 | }
|
52396 | }, this);
|
52397 |
|
52398 | keyboard && keyboard.addListener(HIGH_PRIORITY$e, function(e) {
|
52399 | if (!isSpace(e.keyEvent)) {
|
52400 | return;
|
52401 | }
|
52402 |
|
52403 | if (self.isActive()) {
|
52404 | return;
|
52405 | }
|
52406 |
|
52407 | function activateMove(event) {
|
52408 | self.activateMove(event);
|
52409 |
|
52410 | window.removeEventListener('mousemove', activateMove);
|
52411 | }
|
52412 |
|
52413 | window.addEventListener('mousemove', activateMove);
|
52414 |
|
52415 | function deactivateMove(e) {
|
52416 | if (!isSpace(e.keyEvent)) {
|
52417 | return;
|
52418 | }
|
52419 |
|
52420 | window.removeEventListener('mousemove', activateMove);
|
52421 |
|
52422 | keyboard.removeListener(deactivateMove, 'keyboard.keyup');
|
52423 |
|
52424 | dragging.cancel();
|
52425 | }
|
52426 |
|
52427 | keyboard.addListener(HIGH_PRIORITY$e, deactivateMove, 'keyboard.keyup');
|
52428 | }, 'keyboard.keydown');
|
52429 |
|
52430 | eventBus.on('hand.end', function(event) {
|
52431 | var target = event.originalEvent.target;
|
52432 |
|
52433 |
|
52434 |
|
52435 | if (!event.hover && !(target instanceof SVGElement)) {
|
52436 | return false;
|
52437 | }
|
52438 |
|
52439 | eventBus.once('hand.ended', function() {
|
52440 | this.activateMove(event.originalEvent, { reactivate: true });
|
52441 | }, this);
|
52442 |
|
52443 | }, this);
|
52444 |
|
52445 |
|
52446 | eventBus.on('hand.move.move', function(event) {
|
52447 | var scale = canvas.viewbox().scale;
|
52448 |
|
52449 | canvas.scroll({
|
52450 | dx: event.dx * scale,
|
52451 | dy: event.dy * scale
|
52452 | });
|
52453 | });
|
52454 |
|
52455 | eventBus.on('hand.move.end', function(event) {
|
52456 | var context = event.context,
|
52457 | reactivate = context.reactivate;
|
52458 |
|
52459 |
|
52460 | if (!hasPrimaryModifier(event) && reactivate) {
|
52461 |
|
52462 | eventBus.once('hand.move.ended', function(event) {
|
52463 | this.activateHand(event.originalEvent, true, true);
|
52464 | }, this);
|
52465 |
|
52466 | }
|
52467 |
|
52468 | return false;
|
52469 | }, this);
|
52470 |
|
52471 | }
|
52472 |
|
52473 | HandTool.$inject = [
|
52474 | 'eventBus',
|
52475 | 'canvas',
|
52476 | 'dragging',
|
52477 | 'injector',
|
52478 | 'toolManager'
|
52479 | ];
|
52480 |
|
52481 |
|
52482 | HandTool.prototype.activateMove = function(event, autoActivate, context) {
|
52483 | if (typeof autoActivate === 'object') {
|
52484 | context = autoActivate;
|
52485 | autoActivate = false;
|
52486 | }
|
52487 |
|
52488 | this._dragging.init(event, 'hand.move', {
|
52489 | autoActivate: autoActivate,
|
52490 | cursor: HAND_CURSOR,
|
52491 | data: {
|
52492 | context: context || {}
|
52493 | }
|
52494 | });
|
52495 | };
|
52496 |
|
52497 | HandTool.prototype.activateHand = function(event, autoActivate, reactivate) {
|
52498 | this._dragging.init(event, 'hand', {
|
52499 | trapClick: false,
|
52500 | autoActivate: autoActivate,
|
52501 | cursor: HAND_CURSOR,
|
52502 | data: {
|
52503 | context: {
|
52504 | reactivate: reactivate
|
52505 | }
|
52506 | }
|
52507 | });
|
52508 | };
|
52509 |
|
52510 | HandTool.prototype.toggle = function() {
|
52511 | if (this.isActive()) {
|
52512 | this._dragging.cancel();
|
52513 | } else {
|
52514 | this.activateHand();
|
52515 | }
|
52516 | };
|
52517 |
|
52518 | HandTool.prototype.isActive = function() {
|
52519 | var context = this._dragging.context();
|
52520 |
|
52521 | if (context) {
|
52522 | return /^(hand|hand\.move)$/.test(context.prefix);
|
52523 | }
|
52524 |
|
52525 | return false;
|
52526 | };
|
52527 |
|
52528 |
|
52529 |
|
52530 | function isSpace(keyEvent) {
|
52531 | return isKey(' ', keyEvent);
|
52532 | }
|
52533 |
|
52534 | var HandToolModule = {
|
52535 | __depends__: [
|
52536 | ToolManagerModule
|
52537 | ],
|
52538 | __init__: [ 'handTool' ],
|
52539 | handTool: [ 'type', HandTool ]
|
52540 | };
|
52541 |
|
52542 | var MARKER_OK$4 = 'connect-ok',
|
52543 | MARKER_NOT_OK$4 = 'connect-not-ok';
|
52544 |
|
52545 | |
52546 |
|
52547 |
|
52548 |
|
52549 |
|
52550 |
|
52551 |
|
52552 |
|
52553 |
|
52554 |
|
52555 |
|
52556 | function GlobalConnect(
|
52557 | eventBus, dragging, connect,
|
52558 | canvas, toolManager, rules) {
|
52559 |
|
52560 | var self = this;
|
52561 |
|
52562 | this._dragging = dragging;
|
52563 | this._rules = rules;
|
52564 |
|
52565 | toolManager.registerTool('global-connect', {
|
52566 | tool: 'global-connect',
|
52567 | dragging: 'global-connect.drag'
|
52568 | });
|
52569 |
|
52570 | eventBus.on('global-connect.hover', function(event) {
|
52571 | var context = event.context,
|
52572 | startTarget = event.hover;
|
52573 |
|
52574 | var canStartConnect = context.canStartConnect = self.canStartConnect(startTarget);
|
52575 |
|
52576 |
|
52577 | if (canStartConnect === null) {
|
52578 | return;
|
52579 | }
|
52580 |
|
52581 | context.startTarget = startTarget;
|
52582 |
|
52583 | canvas.addMarker(startTarget, canStartConnect ? MARKER_OK$4 : MARKER_NOT_OK$4);
|
52584 | });
|
52585 |
|
52586 |
|
52587 | eventBus.on([ 'global-connect.out', 'global-connect.cleanup' ], function(event) {
|
52588 | var startTarget = event.context.startTarget,
|
52589 | canStartConnect = event.context.canStartConnect;
|
52590 |
|
52591 | if (startTarget) {
|
52592 | canvas.removeMarker(startTarget, canStartConnect ? MARKER_OK$4 : MARKER_NOT_OK$4);
|
52593 | }
|
52594 | });
|
52595 |
|
52596 |
|
52597 | eventBus.on([ 'global-connect.ended' ], function(event) {
|
52598 | var context = event.context,
|
52599 | startTarget = context.startTarget,
|
52600 | startPosition = {
|
52601 | x: event.x,
|
52602 | y: event.y
|
52603 | };
|
52604 |
|
52605 | var canStartConnect = self.canStartConnect(startTarget);
|
52606 |
|
52607 | if (!canStartConnect) {
|
52608 | return;
|
52609 | }
|
52610 |
|
52611 | eventBus.once('element.out', function() {
|
52612 | eventBus.once([ 'connect.ended', 'connect.canceled' ], function() {
|
52613 | eventBus.fire('global-connect.drag.ended');
|
52614 | });
|
52615 |
|
52616 | connect.start(null, startTarget, startPosition);
|
52617 | });
|
52618 |
|
52619 | return false;
|
52620 | });
|
52621 | }
|
52622 |
|
52623 | GlobalConnect.$inject = [
|
52624 | 'eventBus',
|
52625 | 'dragging',
|
52626 | 'connect',
|
52627 | 'canvas',
|
52628 | 'toolManager',
|
52629 | 'rules'
|
52630 | ];
|
52631 |
|
52632 | |
52633 |
|
52634 |
|
52635 | GlobalConnect.prototype.start = function(event) {
|
52636 | this._dragging.init(event, 'global-connect', {
|
52637 | trapClick: false,
|
52638 | data: {
|
52639 | context: {}
|
52640 | }
|
52641 | });
|
52642 | };
|
52643 |
|
52644 | GlobalConnect.prototype.toggle = function() {
|
52645 | if (this.isActive()) {
|
52646 | this._dragging.cancel();
|
52647 | } else {
|
52648 | this.start();
|
52649 | }
|
52650 | };
|
52651 |
|
52652 | GlobalConnect.prototype.isActive = function() {
|
52653 | var context = this._dragging.context();
|
52654 |
|
52655 | return context && /^global-connect/.test(context.prefix);
|
52656 | };
|
52657 |
|
52658 | |
52659 |
|
52660 |
|
52661 |
|
52662 |
|
52663 |
|
52664 | GlobalConnect.prototype.canStartConnect = function(startTarget) {
|
52665 | return this._rules.allowed('connection.start', { source: startTarget });
|
52666 | };
|
52667 |
|
52668 | var GlobalConnectModule = {
|
52669 | __depends__: [
|
52670 | ConnectModule,
|
52671 | RulesModule,
|
52672 | DraggingModule,
|
52673 | ToolManagerModule
|
52674 | ],
|
52675 | globalConnect: [ 'type', GlobalConnect ]
|
52676 | };
|
52677 |
|
52678 | |
52679 |
|
52680 |
|
52681 | function PaletteProvider(
|
52682 | palette, create, elementFactory,
|
52683 | spaceTool, lassoTool, handTool,
|
52684 | globalConnect, translate) {
|
52685 |
|
52686 | this._palette = palette;
|
52687 | this._create = create;
|
52688 | this._elementFactory = elementFactory;
|
52689 | this._spaceTool = spaceTool;
|
52690 | this._lassoTool = lassoTool;
|
52691 | this._handTool = handTool;
|
52692 | this._globalConnect = globalConnect;
|
52693 | this._translate = translate;
|
52694 |
|
52695 | palette.registerProvider(this);
|
52696 | }
|
52697 |
|
52698 | PaletteProvider.$inject = [
|
52699 | 'palette',
|
52700 | 'create',
|
52701 | 'elementFactory',
|
52702 | 'spaceTool',
|
52703 | 'lassoTool',
|
52704 | 'handTool',
|
52705 | 'globalConnect',
|
52706 | 'translate'
|
52707 | ];
|
52708 |
|
52709 |
|
52710 | PaletteProvider.prototype.getPaletteEntries = function(element) {
|
52711 |
|
52712 | var actions = {},
|
52713 | create = this._create,
|
52714 | elementFactory = this._elementFactory,
|
52715 | spaceTool = this._spaceTool,
|
52716 | lassoTool = this._lassoTool,
|
52717 | handTool = this._handTool,
|
52718 | globalConnect = this._globalConnect,
|
52719 | translate = this._translate;
|
52720 |
|
52721 | function createAction(type, group, className, title, options) {
|
52722 |
|
52723 | function createListener(event) {
|
52724 | var shape = elementFactory.createShape(assign({ type: type }, options));
|
52725 |
|
52726 | if (options) {
|
52727 | shape.businessObject.di.isExpanded = options.isExpanded;
|
52728 | }
|
52729 |
|
52730 | create.start(event, shape);
|
52731 | }
|
52732 |
|
52733 | var shortType = type.replace(/^bpmn:/, '');
|
52734 |
|
52735 | return {
|
52736 | group: group,
|
52737 | className: className,
|
52738 | title: title || translate('Create {type}', { type: shortType }),
|
52739 | action: {
|
52740 | dragstart: createListener,
|
52741 | click: createListener
|
52742 | }
|
52743 | };
|
52744 | }
|
52745 |
|
52746 | function createSubprocess(event) {
|
52747 | var subProcess = elementFactory.createShape({
|
52748 | type: 'bpmn:SubProcess',
|
52749 | x: 0,
|
52750 | y: 0,
|
52751 | isExpanded: true
|
52752 | });
|
52753 |
|
52754 | var startEvent = elementFactory.createShape({
|
52755 | type: 'bpmn:StartEvent',
|
52756 | x: 40,
|
52757 | y: 82,
|
52758 | parent: subProcess
|
52759 | });
|
52760 |
|
52761 | create.start(event, [ subProcess, startEvent ], {
|
52762 | hints: {
|
52763 | autoSelect: [ startEvent ]
|
52764 | }
|
52765 | });
|
52766 | }
|
52767 |
|
52768 | function createParticipant(event) {
|
52769 | create.start(event, elementFactory.createParticipantShape());
|
52770 | }
|
52771 |
|
52772 | assign(actions, {
|
52773 | 'hand-tool': {
|
52774 | group: 'tools',
|
52775 | className: 'bpmn-icon-hand-tool',
|
52776 | title: translate('Activate the hand tool'),
|
52777 | action: {
|
52778 | click: function(event) {
|
52779 | handTool.activateHand(event);
|
52780 | }
|
52781 | }
|
52782 | },
|
52783 | 'lasso-tool': {
|
52784 | group: 'tools',
|
52785 | className: 'bpmn-icon-lasso-tool',
|
52786 | title: translate('Activate the lasso tool'),
|
52787 | action: {
|
52788 | click: function(event) {
|
52789 | lassoTool.activateSelection(event);
|
52790 | }
|
52791 | }
|
52792 | },
|
52793 | 'space-tool': {
|
52794 | group: 'tools',
|
52795 | className: 'bpmn-icon-space-tool',
|
52796 | title: translate('Activate the create/remove space tool'),
|
52797 | action: {
|
52798 | click: function(event) {
|
52799 | spaceTool.activateSelection(event);
|
52800 | }
|
52801 | }
|
52802 | },
|
52803 | 'global-connect-tool': {
|
52804 | group: 'tools',
|
52805 | className: 'bpmn-icon-connection-multi',
|
52806 | title: translate('Activate the global connect tool'),
|
52807 | action: {
|
52808 | click: function(event) {
|
52809 | globalConnect.toggle(event);
|
52810 | }
|
52811 | }
|
52812 | },
|
52813 | 'tool-separator': {
|
52814 | group: 'tools',
|
52815 | separator: true
|
52816 | },
|
52817 | 'create.start-event': createAction(
|
52818 | 'bpmn:StartEvent', 'event', 'bpmn-icon-start-event-none',
|
52819 | translate('Create StartEvent')
|
52820 | ),
|
52821 | 'create.intermediate-event': createAction(
|
52822 | 'bpmn:IntermediateThrowEvent', 'event', 'bpmn-icon-intermediate-event-none',
|
52823 | translate('Create Intermediate/Boundary Event')
|
52824 | ),
|
52825 | 'create.end-event': createAction(
|
52826 | 'bpmn:EndEvent', 'event', 'bpmn-icon-end-event-none',
|
52827 | translate('Create EndEvent')
|
52828 | ),
|
52829 | 'create.exclusive-gateway': createAction(
|
52830 | 'bpmn:ExclusiveGateway', 'gateway', 'bpmn-icon-gateway-none',
|
52831 | translate('Create Gateway')
|
52832 | ),
|
52833 | 'create.task': createAction(
|
52834 | 'bpmn:Task', 'activity', 'bpmn-icon-task',
|
52835 | translate('Create Task')
|
52836 | ),
|
52837 | 'create.data-object': createAction(
|
52838 | 'bpmn:DataObjectReference', 'data-object', 'bpmn-icon-data-object',
|
52839 | translate('Create DataObjectReference')
|
52840 | ),
|
52841 | 'create.data-store': createAction(
|
52842 | 'bpmn:DataStoreReference', 'data-store', 'bpmn-icon-data-store',
|
52843 | translate('Create DataStoreReference')
|
52844 | ),
|
52845 | 'create.subprocess-expanded': {
|
52846 | group: 'activity',
|
52847 | className: 'bpmn-icon-subprocess-expanded',
|
52848 | title: translate('Create expanded SubProcess'),
|
52849 | action: {
|
52850 | dragstart: createSubprocess,
|
52851 | click: createSubprocess
|
52852 | }
|
52853 | },
|
52854 | 'create.participant-expanded': {
|
52855 | group: 'collaboration',
|
52856 | className: 'bpmn-icon-participant',
|
52857 | title: translate('Create Pool/Participant'),
|
52858 | action: {
|
52859 | dragstart: createParticipant,
|
52860 | click: createParticipant
|
52861 | }
|
52862 | },
|
52863 | 'create.group': createAction(
|
52864 | 'bpmn:Group', 'artifact', 'bpmn-icon-group',
|
52865 | translate('Create Group')
|
52866 | ),
|
52867 | });
|
52868 |
|
52869 | return actions;
|
52870 | };
|
52871 |
|
52872 | var PaletteModule$1 = {
|
52873 | __depends__: [
|
52874 | PaletteModule,
|
52875 | CreateModule,
|
52876 | SpaceToolModule,
|
52877 | LassoToolModule,
|
52878 | HandToolModule,
|
52879 | GlobalConnectModule,
|
52880 | translate$2
|
52881 | ],
|
52882 | __init__: [ 'paletteProvider' ],
|
52883 | paletteProvider: [ 'type', PaletteProvider ]
|
52884 | };
|
52885 |
|
52886 | var LOW_PRIORITY$i = 250;
|
52887 |
|
52888 |
|
52889 | function BpmnReplacePreview(
|
52890 | eventBus, elementRegistry, elementFactory,
|
52891 | canvas, previewSupport) {
|
52892 |
|
52893 | CommandInterceptor.call(this, eventBus);
|
52894 |
|
52895 | |
52896 |
|
52897 |
|
52898 |
|
52899 |
|
52900 | function replaceVisual(context) {
|
52901 |
|
52902 | var replacements = context.canExecute.replacements;
|
52903 |
|
52904 | forEach(replacements, function(replacement) {
|
52905 |
|
52906 | var id = replacement.oldElementId;
|
52907 |
|
52908 | var newElement = {
|
52909 | type: replacement.newElementType
|
52910 | };
|
52911 |
|
52912 |
|
52913 | if (context.visualReplacements[id]) {
|
52914 | return;
|
52915 | }
|
52916 |
|
52917 | var element = elementRegistry.get(id);
|
52918 |
|
52919 | assign(newElement, { x: element.x, y: element.y });
|
52920 |
|
52921 |
|
52922 | var tempShape = elementFactory.createShape(newElement);
|
52923 |
|
52924 | canvas.addShape(tempShape, element.parent);
|
52925 |
|
52926 |
|
52927 | var gfx = query('[data-element-id="' + css_escape(element.id) + '"]', context.dragGroup);
|
52928 |
|
52929 | if (gfx) {
|
52930 | attr$1(gfx, { display: 'none' });
|
52931 | }
|
52932 |
|
52933 |
|
52934 | var dragger = previewSupport.addDragger(tempShape, context.dragGroup);
|
52935 |
|
52936 | context.visualReplacements[id] = dragger;
|
52937 |
|
52938 | canvas.removeShape(tempShape);
|
52939 | });
|
52940 | }
|
52941 |
|
52942 | |
52943 |
|
52944 |
|
52945 |
|
52946 |
|
52947 | function restoreVisual(context) {
|
52948 |
|
52949 | var visualReplacements = context.visualReplacements;
|
52950 |
|
52951 | forEach(visualReplacements, function(dragger, id) {
|
52952 |
|
52953 | var originalGfx = query('[data-element-id="' + css_escape(id) + '"]', context.dragGroup);
|
52954 |
|
52955 | if (originalGfx) {
|
52956 | attr$1(originalGfx, { display: 'inline' });
|
52957 | }
|
52958 |
|
52959 | dragger.remove();
|
52960 |
|
52961 | if (visualReplacements[id]) {
|
52962 | delete visualReplacements[id];
|
52963 | }
|
52964 | });
|
52965 | }
|
52966 |
|
52967 | eventBus.on('shape.move.move', LOW_PRIORITY$i, function(event) {
|
52968 |
|
52969 | var context = event.context,
|
52970 | canExecute = context.canExecute;
|
52971 |
|
52972 | if (!context.visualReplacements) {
|
52973 | context.visualReplacements = {};
|
52974 | }
|
52975 |
|
52976 | if (canExecute && canExecute.replacements) {
|
52977 | replaceVisual(context);
|
52978 | } else {
|
52979 | restoreVisual(context);
|
52980 | }
|
52981 | });
|
52982 | }
|
52983 |
|
52984 | BpmnReplacePreview.$inject = [
|
52985 | 'eventBus',
|
52986 | 'elementRegistry',
|
52987 | 'elementFactory',
|
52988 | 'canvas',
|
52989 | 'previewSupport'
|
52990 | ];
|
52991 |
|
52992 | inherits_browser(BpmnReplacePreview, CommandInterceptor);
|
52993 |
|
52994 | var ReplacePreviewModule = {
|
52995 | __depends__: [
|
52996 | PreviewSupportModule
|
52997 | ],
|
52998 | __init__: [ 'bpmnReplacePreview' ],
|
52999 | bpmnReplacePreview: [ 'type', BpmnReplacePreview ]
|
53000 | };
|
53001 |
|
53002 | var HIGHER_PRIORITY$2 = 1250;
|
53003 |
|
53004 | var BOUNDARY_TO_HOST_THRESHOLD$1 = 40;
|
53005 |
|
53006 | var TARGET_BOUNDS_PADDING = 20;
|
53007 |
|
53008 | var TARGET_CENTER_PADDING = 20;
|
53009 |
|
53010 | var AXES = [ 'x', 'y' ];
|
53011 |
|
53012 | var abs$7 = Math.abs;
|
53013 |
|
53014 | |
53015 |
|
53016 |
|
53017 |
|
53018 |
|
53019 |
|
53020 | function BpmnConnectSnapping(eventBus, rules) {
|
53021 | eventBus.on([
|
53022 | 'connect.hover',
|
53023 | 'connect.move',
|
53024 | 'connect.end',
|
53025 | ], HIGHER_PRIORITY$2, function(event) {
|
53026 | var context = event.context,
|
53027 | source = context.source,
|
53028 | target = context.target;
|
53029 |
|
53030 | if (event.originalEvent && isCmd(event.originalEvent)) {
|
53031 | return;
|
53032 | }
|
53033 |
|
53034 | if (!context.initialSourcePosition) {
|
53035 | context.initialSourcePosition = context.sourcePosition;
|
53036 | }
|
53037 |
|
53038 | var connectionAttrs = rules.allowed('connection.create', {
|
53039 | source: source,
|
53040 | target: target
|
53041 | });
|
53042 |
|
53043 | if (target && connectionAttrs) {
|
53044 | snapInsideTarget(event, target, getTargetBoundsPadding(target));
|
53045 | }
|
53046 |
|
53047 | if (target && isAnyType(connectionAttrs, [
|
53048 | 'bpmn:Association',
|
53049 | 'bpmn:DataInputAssociation',
|
53050 | 'bpmn:DataOutputAssociation',
|
53051 | 'bpmn:SequenceFlow'
|
53052 | ])) {
|
53053 |
|
53054 |
|
53055 | context.sourcePosition = mid(source);
|
53056 |
|
53057 | if (isAny(target, ['bpmn:Event', 'bpmn:Gateway'])) {
|
53058 | snapToPosition(event, mid(target));
|
53059 | }
|
53060 |
|
53061 | if (is$1(target, 'bpmn:Task')) {
|
53062 | snapTargetMidOnCenter(event, target);
|
53063 | }
|
53064 |
|
53065 | if (is$1(source, 'bpmn:BoundaryEvent') && target === source.host) {
|
53066 | snapBoundaryEventLoop(event, source, target);
|
53067 | }
|
53068 |
|
53069 | } else if (isType(connectionAttrs, 'bpmn:MessageFlow')) {
|
53070 |
|
53071 | if (is$1(source, 'bpmn:Event')) {
|
53072 |
|
53073 |
|
53074 | context.sourcePosition = mid(source);
|
53075 | }
|
53076 |
|
53077 | if (is$1(target, 'bpmn:Event')) {
|
53078 |
|
53079 |
|
53080 | snapToPosition(event, mid(target));
|
53081 | }
|
53082 |
|
53083 | } else {
|
53084 |
|
53085 |
|
53086 | context.sourcePosition = context.initialSourcePosition;
|
53087 | }
|
53088 | });
|
53089 | }
|
53090 |
|
53091 | BpmnConnectSnapping.$inject = [
|
53092 | 'eventBus',
|
53093 | 'rules'
|
53094 | ];
|
53095 |
|
53096 | function snapInsideTarget(event, target, padding) {
|
53097 |
|
53098 | AXES.forEach(function(axis) {
|
53099 | var matchingTargetDimension = getDimensionForAxis(axis, target),
|
53100 | newCoordinate;
|
53101 |
|
53102 | if (event[axis] < target[axis] + padding) {
|
53103 | newCoordinate = target[axis] + padding;
|
53104 | } else if (event[axis] > target[axis] + matchingTargetDimension - padding) {
|
53105 | newCoordinate = target[axis] + matchingTargetDimension - padding;
|
53106 | }
|
53107 |
|
53108 | if (newCoordinate) {
|
53109 | setSnapped(event, axis, newCoordinate);
|
53110 | }
|
53111 | });
|
53112 | }
|
53113 |
|
53114 |
|
53115 | function snapTargetMidOnCenter(event, target) {
|
53116 |
|
53117 | var isCenter = every(AXES, function(axis) {
|
53118 | var coordinate = event[axis],
|
53119 | matchingTargetDimension = getDimensionForAxis(axis, target);
|
53120 |
|
53121 | return coordinate > target[axis] + TARGET_CENTER_PADDING
|
53122 | && coordinate < target[axis] + matchingTargetDimension - TARGET_CENTER_PADDING;
|
53123 | });
|
53124 |
|
53125 | if (isCenter) {
|
53126 | snapToPosition(event, mid(target));
|
53127 | }
|
53128 |
|
53129 | }
|
53130 |
|
53131 |
|
53132 | function snapBoundaryEventLoop(event, source, target) {
|
53133 | var sourceMid = mid(source),
|
53134 | orientation = getOrientation(sourceMid, target, -10),
|
53135 | snappingAxes = [];
|
53136 |
|
53137 | if (/top|bottom/.test(orientation)) {
|
53138 | snappingAxes.push('x');
|
53139 | }
|
53140 |
|
53141 | if (/left|right/.test(orientation)) {
|
53142 | snappingAxes.push('y');
|
53143 | }
|
53144 |
|
53145 | snappingAxes.forEach(function(axis) {
|
53146 | var coordinate = event[axis], newCoordinate;
|
53147 |
|
53148 | if (abs$7(coordinate - sourceMid[axis]) < BOUNDARY_TO_HOST_THRESHOLD$1) {
|
53149 | if (coordinate > sourceMid[axis]) {
|
53150 | newCoordinate = sourceMid[axis] + BOUNDARY_TO_HOST_THRESHOLD$1;
|
53151 | }
|
53152 | else {
|
53153 | newCoordinate = sourceMid[axis] - BOUNDARY_TO_HOST_THRESHOLD$1;
|
53154 | }
|
53155 |
|
53156 | setSnapped(event, axis, newCoordinate);
|
53157 | }
|
53158 | });
|
53159 | }
|
53160 |
|
53161 |
|
53162 |
|
53163 | function snapToPosition(event, position) {
|
53164 | setSnapped(event, 'x', position.x);
|
53165 | setSnapped(event, 'y', position.y);
|
53166 | }
|
53167 |
|
53168 | function isType(attrs, type) {
|
53169 | return attrs && attrs.type === type;
|
53170 | }
|
53171 |
|
53172 | function isAnyType(attrs, types) {
|
53173 | return some(types, function(type) {
|
53174 | return isType(attrs, type);
|
53175 | });
|
53176 | }
|
53177 |
|
53178 | function getDimensionForAxis(axis, element) {
|
53179 | return axis === 'x' ? element.width : element.height;
|
53180 | }
|
53181 |
|
53182 | function getTargetBoundsPadding(target) {
|
53183 | if (is$1(target, 'bpmn:Task')) {
|
53184 | return 10;
|
53185 | } else {
|
53186 | return TARGET_BOUNDS_PADDING;
|
53187 | }
|
53188 | }
|
53189 |
|
53190 | |
53191 |
|
53192 |
|
53193 |
|
53194 |
|
53195 | function SnapContext() {
|
53196 |
|
53197 | |
53198 |
|
53199 |
|
53200 |
|
53201 |
|
53202 |
|
53203 | this._targets = {};
|
53204 |
|
53205 | |
53206 |
|
53207 |
|
53208 |
|
53209 |
|
53210 |
|
53211 | this._snapOrigins = {};
|
53212 |
|
53213 | |
53214 |
|
53215 |
|
53216 |
|
53217 |
|
53218 | this._snapLocations = [];
|
53219 |
|
53220 | |
53221 |
|
53222 |
|
53223 |
|
53224 |
|
53225 | this._defaultSnaps = {};
|
53226 | }
|
53227 |
|
53228 |
|
53229 | SnapContext.prototype.getSnapOrigin = function(snapLocation) {
|
53230 | return this._snapOrigins[snapLocation];
|
53231 | };
|
53232 |
|
53233 |
|
53234 | SnapContext.prototype.setSnapOrigin = function(snapLocation, initialValue) {
|
53235 | this._snapOrigins[snapLocation] = initialValue;
|
53236 |
|
53237 | if (this._snapLocations.indexOf(snapLocation) === -1) {
|
53238 | this._snapLocations.push(snapLocation);
|
53239 | }
|
53240 | };
|
53241 |
|
53242 |
|
53243 | SnapContext.prototype.addDefaultSnap = function(type, point) {
|
53244 |
|
53245 | var snapValues = this._defaultSnaps[type];
|
53246 |
|
53247 | if (!snapValues) {
|
53248 | snapValues = this._defaultSnaps[type] = [];
|
53249 | }
|
53250 |
|
53251 | snapValues.push(point);
|
53252 | };
|
53253 |
|
53254 | |
53255 |
|
53256 |
|
53257 |
|
53258 |
|
53259 |
|
53260 | SnapContext.prototype.getSnapLocations = function() {
|
53261 | return this._snapLocations;
|
53262 | };
|
53263 |
|
53264 | |
53265 |
|
53266 |
|
53267 |
|
53268 |
|
53269 |
|
53270 |
|
53271 | SnapContext.prototype.setSnapLocations = function(snapLocations) {
|
53272 | this._snapLocations = snapLocations;
|
53273 | };
|
53274 |
|
53275 | |
53276 |
|
53277 |
|
53278 |
|
53279 |
|
53280 | SnapContext.prototype.pointsForTarget = function(target) {
|
53281 |
|
53282 | var targetId = target.id || target;
|
53283 |
|
53284 | var snapPoints = this._targets[targetId];
|
53285 |
|
53286 | if (!snapPoints) {
|
53287 | snapPoints = this._targets[targetId] = new SnapPoints();
|
53288 | snapPoints.initDefaults(this._defaultSnaps);
|
53289 | }
|
53290 |
|
53291 | return snapPoints;
|
53292 | };
|
53293 |
|
53294 |
|
53295 | |
53296 |
|
53297 |
|
53298 |
|
53299 |
|
53300 |
|
53301 | function SnapPoints(defaultSnaps) {
|
53302 |
|
53303 | |
53304 |
|
53305 |
|
53306 |
|
53307 |
|
53308 |
|
53309 | this._snapValues = {};
|
53310 | }
|
53311 |
|
53312 | SnapPoints.prototype.add = function(snapLocation, point) {
|
53313 |
|
53314 | var snapValues = this._snapValues[snapLocation];
|
53315 |
|
53316 | if (!snapValues) {
|
53317 | snapValues = this._snapValues[snapLocation] = { x: [], y: [] };
|
53318 | }
|
53319 |
|
53320 | if (snapValues.x.indexOf(point.x) === -1) {
|
53321 | snapValues.x.push(point.x);
|
53322 | }
|
53323 |
|
53324 | if (snapValues.y.indexOf(point.y) === -1) {
|
53325 | snapValues.y.push(point.y);
|
53326 | }
|
53327 | };
|
53328 |
|
53329 |
|
53330 | SnapPoints.prototype.snap = function(point, snapLocation, axis, tolerance) {
|
53331 | var snappingValues = this._snapValues[snapLocation];
|
53332 |
|
53333 | return snappingValues && snapTo(point[axis], snappingValues[axis], tolerance);
|
53334 | };
|
53335 |
|
53336 | |
53337 |
|
53338 |
|
53339 |
|
53340 |
|
53341 | SnapPoints.prototype.initDefaults = function(defaultSnaps) {
|
53342 |
|
53343 | var self = this;
|
53344 |
|
53345 | forEach(defaultSnaps || {}, function(snapPoints, snapLocation) {
|
53346 | forEach(snapPoints, function(point) {
|
53347 | self.add(snapLocation, point);
|
53348 | });
|
53349 | });
|
53350 | };
|
53351 |
|
53352 | var HIGHER_PRIORITY$3 = 1250;
|
53353 |
|
53354 |
|
53355 | |
53356 |
|
53357 |
|
53358 |
|
53359 |
|
53360 |
|
53361 |
|
53362 | function CreateMoveSnapping(elementRegistry, eventBus, snapping) {
|
53363 | var self = this;
|
53364 |
|
53365 | this._elementRegistry = elementRegistry;
|
53366 |
|
53367 | eventBus.on([
|
53368 | 'create.start',
|
53369 | 'shape.move.start'
|
53370 | ], function(event) {
|
53371 | self.initSnap(event);
|
53372 | });
|
53373 |
|
53374 | eventBus.on([
|
53375 | 'create.move',
|
53376 | 'create.end',
|
53377 | 'shape.move.move',
|
53378 | 'shape.move.end'
|
53379 | ], HIGHER_PRIORITY$3, function(event) {
|
53380 | var context = event.context,
|
53381 | shape = context.shape,
|
53382 | snapContext = context.snapContext,
|
53383 | target = context.target;
|
53384 |
|
53385 | if (event.originalEvent && isCmd(event.originalEvent)) {
|
53386 | return;
|
53387 | }
|
53388 |
|
53389 | if (isSnapped(event) || !target) {
|
53390 | return;
|
53391 | }
|
53392 |
|
53393 | var snapPoints = snapContext.pointsForTarget(target);
|
53394 |
|
53395 | if (!snapPoints.initialized) {
|
53396 | snapPoints = self.addSnapTargetPoints(snapPoints, shape, target);
|
53397 |
|
53398 | snapPoints.initialized = true;
|
53399 | }
|
53400 |
|
53401 | snapping.snap(event, snapPoints);
|
53402 | });
|
53403 |
|
53404 | eventBus.on([
|
53405 | 'create.cleanup',
|
53406 | 'shape.move.cleanup'
|
53407 | ], function() {
|
53408 | snapping.hide();
|
53409 | });
|
53410 | }
|
53411 |
|
53412 | CreateMoveSnapping.$inject = [
|
53413 | 'elementRegistry',
|
53414 | 'eventBus',
|
53415 | 'snapping'
|
53416 | ];
|
53417 |
|
53418 | CreateMoveSnapping.prototype.initSnap = function(event) {
|
53419 | var elementRegistry = this._elementRegistry;
|
53420 |
|
53421 | var context = event.context,
|
53422 | shape = context.shape,
|
53423 | snapContext = context.snapContext;
|
53424 |
|
53425 | if (!snapContext) {
|
53426 | snapContext = context.snapContext = new SnapContext();
|
53427 | }
|
53428 |
|
53429 | var shapeMid;
|
53430 |
|
53431 | if (elementRegistry.get(shape.id)) {
|
53432 |
|
53433 |
|
53434 | shapeMid = mid(shape, event);
|
53435 | } else {
|
53436 |
|
53437 |
|
53438 | shapeMid = {
|
53439 | x: event.x + mid(shape).x,
|
53440 | y: event.y + mid(shape).y
|
53441 | };
|
53442 | }
|
53443 |
|
53444 | var shapeTopLeft = {
|
53445 | x: shapeMid.x - shape.width / 2,
|
53446 | y: shapeMid.y - shape.height / 2
|
53447 | },
|
53448 | shapeBottomRight = {
|
53449 | x: shapeMid.x + shape.width / 2,
|
53450 | y: shapeMid.y + shape.height / 2
|
53451 | };
|
53452 |
|
53453 | snapContext.setSnapOrigin('mid', {
|
53454 | x: shapeMid.x - event.x,
|
53455 | y: shapeMid.y - event.y
|
53456 | });
|
53457 |
|
53458 |
|
53459 | if (isLabel$3(shape)) {
|
53460 | return snapContext;
|
53461 | }
|
53462 |
|
53463 | snapContext.setSnapOrigin('top-left', {
|
53464 | x: shapeTopLeft.x - event.x,
|
53465 | y: shapeTopLeft.y - event.y
|
53466 | });
|
53467 |
|
53468 | snapContext.setSnapOrigin('bottom-right', {
|
53469 | x: shapeBottomRight.x - event.x,
|
53470 | y: shapeBottomRight.y - event.y
|
53471 | });
|
53472 |
|
53473 | return snapContext;
|
53474 | };
|
53475 |
|
53476 | CreateMoveSnapping.prototype.addSnapTargetPoints = function(snapPoints, shape, target) {
|
53477 | var snapTargets = this.getSnapTargets(shape, target);
|
53478 |
|
53479 | forEach(snapTargets, function(snapTarget) {
|
53480 |
|
53481 |
|
53482 | if (isLabel$3(snapTarget)) {
|
53483 |
|
53484 | if (isLabel$3(shape)) {
|
53485 | snapPoints.add('mid', mid(snapTarget));
|
53486 | }
|
53487 |
|
53488 | return;
|
53489 | }
|
53490 |
|
53491 |
|
53492 | if (isConnection$8(snapTarget)) {
|
53493 |
|
53494 |
|
53495 | if (snapTarget.waypoints.length < 3) {
|
53496 | return;
|
53497 | }
|
53498 |
|
53499 |
|
53500 | var waypoints = snapTarget.waypoints.slice(1, -1);
|
53501 |
|
53502 | forEach(waypoints, function(waypoint) {
|
53503 | snapPoints.add('mid', waypoint);
|
53504 | });
|
53505 |
|
53506 | return;
|
53507 | }
|
53508 |
|
53509 |
|
53510 | snapPoints.add('mid', mid(snapTarget));
|
53511 | });
|
53512 |
|
53513 | if (!isNumber(shape.x) || !isNumber(shape.y)) {
|
53514 | return snapPoints;
|
53515 | }
|
53516 |
|
53517 |
|
53518 | if (this._elementRegistry.get(shape.id)) {
|
53519 | snapPoints.add('mid', mid(shape));
|
53520 | }
|
53521 |
|
53522 | return snapPoints;
|
53523 | };
|
53524 |
|
53525 | CreateMoveSnapping.prototype.getSnapTargets = function(shape, target) {
|
53526 | return getChildren$1(target).filter(function(child) {
|
53527 | return !isHidden(child);
|
53528 | });
|
53529 | };
|
53530 |
|
53531 |
|
53532 |
|
53533 | function isConnection$8(element) {
|
53534 | return !!element.waypoints;
|
53535 | }
|
53536 |
|
53537 | function isHidden(element) {
|
53538 | return !!element.hidden;
|
53539 | }
|
53540 |
|
53541 | function isLabel$3(element) {
|
53542 | return !!element.labelTarget;
|
53543 | }
|
53544 |
|
53545 | var HIGH_PRIORITY$f = 1500;
|
53546 |
|
53547 |
|
53548 | |
53549 |
|
53550 |
|
53551 |
|
53552 |
|
53553 |
|
53554 |
|
53555 | function BpmnCreateMoveSnapping(bpmnRules, eventBus, injector) {
|
53556 | injector.invoke(CreateMoveSnapping, this);
|
53557 |
|
53558 |
|
53559 | eventBus.on([ 'create.move', 'create.end' ], HIGH_PRIORITY$f, setSnappedIfConstrained);
|
53560 |
|
53561 | function canAttach(shape, target, position) {
|
53562 | return bpmnRules.canAttach([ shape ], target, null, position) === 'attach';
|
53563 | }
|
53564 |
|
53565 |
|
53566 | eventBus.on([
|
53567 | 'create.move',
|
53568 | 'create.end',
|
53569 | 'shape.move.move',
|
53570 | 'shape.move.end'
|
53571 | ], HIGH_PRIORITY$f, function(event) {
|
53572 | var context = event.context,
|
53573 | target = context.target,
|
53574 | shape = context.shape;
|
53575 |
|
53576 | if (target && canAttach(shape, target, event) && !isSnapped(event)) {
|
53577 | snapBoundaryEvent(event, target);
|
53578 | }
|
53579 | });
|
53580 | }
|
53581 |
|
53582 | inherits_browser(BpmnCreateMoveSnapping, CreateMoveSnapping);
|
53583 |
|
53584 | BpmnCreateMoveSnapping.$inject = [
|
53585 | 'bpmnRules',
|
53586 | 'eventBus',
|
53587 | 'injector'
|
53588 | ];
|
53589 |
|
53590 | BpmnCreateMoveSnapping.prototype.initSnap = function(event) {
|
53591 | var snapContext = CreateMoveSnapping.prototype.initSnap.call(this, event);
|
53592 |
|
53593 | var shape = event.shape;
|
53594 |
|
53595 |
|
53596 | forEach(shape.outgoing, function(connection) {
|
53597 | var docking = connection.waypoints[0];
|
53598 |
|
53599 | docking = docking.original || docking;
|
53600 |
|
53601 | snapContext.setSnapOrigin(connection.id + '-docking', {
|
53602 | x: docking.x - event.x,
|
53603 | y: docking.y - event.y
|
53604 | });
|
53605 | });
|
53606 |
|
53607 | forEach(shape.incoming, function(connection) {
|
53608 | var docking = connection.waypoints[connection.waypoints.length - 1];
|
53609 |
|
53610 | docking = docking.original || docking;
|
53611 |
|
53612 | snapContext.setSnapOrigin(connection.id + '-docking', {
|
53613 | x: docking.x - event.x,
|
53614 | y: docking.y - event.y
|
53615 | });
|
53616 | });
|
53617 |
|
53618 | if (is$1(shape, 'bpmn:Participant')) {
|
53619 |
|
53620 |
|
53621 | snapContext.setSnapLocations([ 'top-left', 'bottom-right', 'mid' ]);
|
53622 | }
|
53623 |
|
53624 | return snapContext;
|
53625 | };
|
53626 |
|
53627 | BpmnCreateMoveSnapping.prototype.addSnapTargetPoints = function(snapPoints, shape, target) {
|
53628 | CreateMoveSnapping.prototype.addSnapTargetPoints.call(this, snapPoints, shape, target);
|
53629 |
|
53630 | var snapTargets = this.getSnapTargets(shape, target);
|
53631 |
|
53632 | forEach(snapTargets, function(snapTarget) {
|
53633 |
|
53634 |
|
53635 |
|
53636 |
|
53637 |
|
53638 | if (isContainer(snapTarget) || areAll([ shape, snapTarget ], 'bpmn:TextAnnotation')) {
|
53639 | snapPoints.add('top-left', topLeft(snapTarget));
|
53640 | snapPoints.add('bottom-right', bottomRight(snapTarget));
|
53641 | }
|
53642 | });
|
53643 |
|
53644 |
|
53645 | forEach(shape.incoming, function(connection) {
|
53646 |
|
53647 | if (!includes$1(snapTargets, connection.source)) {
|
53648 | snapPoints.add('mid', getMid(connection.source));
|
53649 | }
|
53650 |
|
53651 | var docking = connection.waypoints[0];
|
53652 |
|
53653 | snapPoints.add(connection.id + '-docking', docking.original || docking);
|
53654 | });
|
53655 |
|
53656 |
|
53657 | forEach(shape.outgoing, function(connection) {
|
53658 |
|
53659 | if (!includes$1(snapTargets, connection.target)) {
|
53660 | snapPoints.add('mid', getMid(connection.target));
|
53661 | }
|
53662 |
|
53663 | var docking = connection.waypoints[ connection.waypoints.length - 1 ];
|
53664 |
|
53665 | snapPoints.add(connection.id + '-docking', docking.original || docking);
|
53666 | });
|
53667 |
|
53668 |
|
53669 | if (is$1(target, 'bpmn:SequenceFlow')) {
|
53670 | snapPoints = this.addSnapTargetPoints(snapPoints, shape, target.parent);
|
53671 | }
|
53672 |
|
53673 | return snapPoints;
|
53674 | };
|
53675 |
|
53676 | BpmnCreateMoveSnapping.prototype.getSnapTargets = function(shape, target) {
|
53677 | return CreateMoveSnapping.prototype.getSnapTargets.call(this, shape, target)
|
53678 | .filter(function(snapTarget) {
|
53679 |
|
53680 |
|
53681 | return !is$1(snapTarget, 'bpmn:Lane');
|
53682 | });
|
53683 | };
|
53684 |
|
53685 |
|
53686 |
|
53687 | function snapBoundaryEvent(event, target) {
|
53688 | var targetTRBL = asTRBL(target);
|
53689 |
|
53690 | var direction = getBoundaryAttachment(event, target);
|
53691 |
|
53692 | if (/top/.test(direction)) {
|
53693 | setSnapped(event, 'y', targetTRBL.top);
|
53694 | } else
|
53695 | if (/bottom/.test(direction)) {
|
53696 | setSnapped(event, 'y', targetTRBL.bottom);
|
53697 | }
|
53698 |
|
53699 | if (/left/.test(direction)) {
|
53700 | setSnapped(event, 'x', targetTRBL.left);
|
53701 | } else
|
53702 | if (/right/.test(direction)) {
|
53703 | setSnapped(event, 'x', targetTRBL.right);
|
53704 | }
|
53705 | }
|
53706 |
|
53707 | function areAll(elements, type) {
|
53708 | return elements.every(function(el) {
|
53709 | return is$1(el, type);
|
53710 | });
|
53711 | }
|
53712 |
|
53713 | function isContainer(element) {
|
53714 | if (is$1(element, 'bpmn:SubProcess') && isExpanded(element)) {
|
53715 | return true;
|
53716 | }
|
53717 |
|
53718 | return is$1(element, 'bpmn:Participant');
|
53719 | }
|
53720 |
|
53721 |
|
53722 | function setSnappedIfConstrained(event) {
|
53723 | var context = event.context,
|
53724 | createConstraints = context.createConstraints;
|
53725 |
|
53726 | if (!createConstraints) {
|
53727 | return;
|
53728 | }
|
53729 |
|
53730 | var top = createConstraints.top,
|
53731 | right = createConstraints.right,
|
53732 | bottom = createConstraints.bottom,
|
53733 | left = createConstraints.left;
|
53734 |
|
53735 | if ((left && left >= event.x) || (right && right <= event.x)) {
|
53736 | setSnapped(event, 'x', event.x);
|
53737 | }
|
53738 |
|
53739 | if ((top && top >= event.y) || (bottom && bottom <= event.y)) {
|
53740 | setSnapped(event, 'y', event.y);
|
53741 | }
|
53742 | }
|
53743 |
|
53744 | function includes$1(array, value) {
|
53745 | return array.indexOf(value) !== -1;
|
53746 | }
|
53747 |
|
53748 | var HIGHER_PRIORITY$4 = 1250;
|
53749 |
|
53750 |
|
53751 | |
53752 |
|
53753 |
|
53754 |
|
53755 |
|
53756 |
|
53757 | function ResizeSnapping(eventBus, snapping) {
|
53758 | var self = this;
|
53759 |
|
53760 | eventBus.on([ 'resize.start' ], function(event) {
|
53761 | self.initSnap(event);
|
53762 | });
|
53763 |
|
53764 | eventBus.on([
|
53765 | 'resize.move',
|
53766 | 'resize.end',
|
53767 | ], HIGHER_PRIORITY$4, function(event) {
|
53768 | var context = event.context,
|
53769 | shape = context.shape,
|
53770 | parent = shape.parent,
|
53771 | direction = context.direction,
|
53772 | snapContext = context.snapContext;
|
53773 |
|
53774 | if (event.originalEvent && isCmd(event.originalEvent)) {
|
53775 | return;
|
53776 | }
|
53777 |
|
53778 | if (isSnapped(event)) {
|
53779 | return;
|
53780 | }
|
53781 |
|
53782 | var snapPoints = snapContext.pointsForTarget(parent);
|
53783 |
|
53784 | if (!snapPoints.initialized) {
|
53785 | snapPoints = self.addSnapTargetPoints(snapPoints, shape, parent, direction);
|
53786 |
|
53787 | snapPoints.initialized = true;
|
53788 | }
|
53789 |
|
53790 | snapping.snap(event, snapPoints);
|
53791 | });
|
53792 |
|
53793 | eventBus.on([ 'resize.cleanup' ], function() {
|
53794 | snapping.hide();
|
53795 | });
|
53796 | }
|
53797 |
|
53798 | ResizeSnapping.prototype.initSnap = function(event) {
|
53799 | var context = event.context,
|
53800 | shape = context.shape,
|
53801 | direction = context.direction,
|
53802 | snapContext = context.snapContext;
|
53803 |
|
53804 | if (!snapContext) {
|
53805 | snapContext = context.snapContext = new SnapContext();
|
53806 | }
|
53807 |
|
53808 | var snapCorner = getCorner(shape, direction);
|
53809 |
|
53810 | snapContext.setSnapOrigin('corner', {
|
53811 | x: snapCorner.x - event.x,
|
53812 | y: snapCorner.y - event.y
|
53813 | });
|
53814 |
|
53815 | return snapContext;
|
53816 | };
|
53817 |
|
53818 | ResizeSnapping.prototype.addSnapTargetPoints = function(snapPoints, shape, target, direction) {
|
53819 | var snapTargets = this.getSnapTargets(shape, target);
|
53820 |
|
53821 | forEach(snapTargets, function(snapTarget) {
|
53822 | snapPoints.add('corner', bottomRight(snapTarget));
|
53823 | snapPoints.add('corner', topLeft(snapTarget));
|
53824 | });
|
53825 |
|
53826 | snapPoints.add('corner', getCorner(shape, direction));
|
53827 |
|
53828 | return snapPoints;
|
53829 | };
|
53830 |
|
53831 | ResizeSnapping.$inject = [
|
53832 | 'eventBus',
|
53833 | 'snapping'
|
53834 | ];
|
53835 |
|
53836 | ResizeSnapping.prototype.getSnapTargets = function(shape, target) {
|
53837 | return getChildren$1(target).filter(function(child) {
|
53838 | return !isAttached(child, shape)
|
53839 | && !isConnection$9(child)
|
53840 | && !isHidden$1(child)
|
53841 | && !isLabel$4(child);
|
53842 | });
|
53843 | };
|
53844 |
|
53845 |
|
53846 |
|
53847 | function getCorner(shape, direction) {
|
53848 | if (direction === 'nw') {
|
53849 | return topLeft(shape);
|
53850 | } else if (direction === 'ne') {
|
53851 | return topRight(shape);
|
53852 | } else if (direction === 'sw') {
|
53853 | return bottomLeft(shape);
|
53854 | } else {
|
53855 | return bottomRight(shape);
|
53856 | }
|
53857 | }
|
53858 |
|
53859 | function isAttached(element, host) {
|
53860 | return element.host === host;
|
53861 | }
|
53862 |
|
53863 | function isConnection$9(element) {
|
53864 | return !!element.waypoints;
|
53865 | }
|
53866 |
|
53867 | function isHidden$1(element) {
|
53868 | return !!element.hidden;
|
53869 | }
|
53870 |
|
53871 | function isLabel$4(element) {
|
53872 | return !!element.labelTarget;
|
53873 | }
|
53874 |
|
53875 | var SNAP_TOLERANCE = 7;
|
53876 |
|
53877 | var SNAP_LINE_HIDE_DELAY = 1000;
|
53878 |
|
53879 |
|
53880 | |
53881 |
|
53882 |
|
53883 |
|
53884 |
|
53885 |
|
53886 | function Snapping(canvas) {
|
53887 | this._canvas = canvas;
|
53888 |
|
53889 |
|
53890 | this._asyncHide = debounce(bind(this.hide, this), SNAP_LINE_HIDE_DELAY);
|
53891 | }
|
53892 |
|
53893 | Snapping.$inject = [ 'canvas' ];
|
53894 |
|
53895 | |
53896 |
|
53897 |
|
53898 |
|
53899 |
|
53900 |
|
53901 | Snapping.prototype.snap = function(event, snapPoints) {
|
53902 | var context = event.context,
|
53903 | snapContext = context.snapContext,
|
53904 | snapLocations = snapContext.getSnapLocations();
|
53905 |
|
53906 | var snapping = {
|
53907 | x: isSnapped(event, 'x'),
|
53908 | y: isSnapped(event, 'y')
|
53909 | };
|
53910 |
|
53911 | forEach(snapLocations, function(location) {
|
53912 | var snapOrigin = snapContext.getSnapOrigin(location);
|
53913 |
|
53914 | var snapCurrent = {
|
53915 | x: event.x + snapOrigin.x,
|
53916 | y: event.y + snapOrigin.y
|
53917 | };
|
53918 |
|
53919 |
|
53920 | forEach([ 'x', 'y' ], function(axis) {
|
53921 | var locationSnapping;
|
53922 |
|
53923 | if (!snapping[axis]) {
|
53924 | locationSnapping = snapPoints.snap(snapCurrent, location, axis, SNAP_TOLERANCE);
|
53925 |
|
53926 | if (locationSnapping !== undefined) {
|
53927 | snapping[axis] = {
|
53928 | value: locationSnapping,
|
53929 | originValue: locationSnapping - snapOrigin[axis]
|
53930 | };
|
53931 | }
|
53932 | }
|
53933 | });
|
53934 |
|
53935 |
|
53936 | if (snapping.x && snapping.y) {
|
53937 | return false;
|
53938 | }
|
53939 | });
|
53940 |
|
53941 |
|
53942 | this.showSnapLine('vertical', snapping.x && snapping.x.value);
|
53943 | this.showSnapLine('horizontal', snapping.y && snapping.y.value);
|
53944 |
|
53945 |
|
53946 | forEach([ 'x', 'y' ], function(axis) {
|
53947 | var axisSnapping = snapping[axis];
|
53948 |
|
53949 | if (isObject(axisSnapping)) {
|
53950 | setSnapped(event, axis, axisSnapping.originValue);
|
53951 | }
|
53952 | });
|
53953 | };
|
53954 |
|
53955 | Snapping.prototype._createLine = function(orientation) {
|
53956 | var root = this._canvas.getLayer('snap');
|
53957 |
|
53958 | var line = create('path');
|
53959 |
|
53960 | attr$1(line, { d: 'M0,0 L0,0' });
|
53961 |
|
53962 | classes$1(line).add('djs-snap-line');
|
53963 |
|
53964 | append(root, line);
|
53965 |
|
53966 | return {
|
53967 | update: function(position) {
|
53968 |
|
53969 | if (!isNumber(position)) {
|
53970 | attr$1(line, { display: 'none' });
|
53971 | } else {
|
53972 | if (orientation === 'horizontal') {
|
53973 | attr$1(line, {
|
53974 | d: 'M-100000,' + position + ' L+100000,' + position,
|
53975 | display: ''
|
53976 | });
|
53977 | } else {
|
53978 | attr$1(line, {
|
53979 | d: 'M ' + position + ',-100000 L ' + position + ', +100000',
|
53980 | display: ''
|
53981 | });
|
53982 | }
|
53983 | }
|
53984 | }
|
53985 | };
|
53986 | };
|
53987 |
|
53988 | Snapping.prototype._createSnapLines = function() {
|
53989 | this._snapLines = {
|
53990 | horizontal: this._createLine('horizontal'),
|
53991 | vertical: this._createLine('vertical')
|
53992 | };
|
53993 | };
|
53994 |
|
53995 | Snapping.prototype.showSnapLine = function(orientation, position) {
|
53996 |
|
53997 | var line = this.getSnapLine(orientation);
|
53998 |
|
53999 | if (line) {
|
54000 | line.update(position);
|
54001 | }
|
54002 |
|
54003 | this._asyncHide();
|
54004 | };
|
54005 |
|
54006 | Snapping.prototype.getSnapLine = function(orientation) {
|
54007 | if (!this._snapLines) {
|
54008 | this._createSnapLines();
|
54009 | }
|
54010 |
|
54011 | return this._snapLines[orientation];
|
54012 | };
|
54013 |
|
54014 | Snapping.prototype.hide = function() {
|
54015 | forEach(this._snapLines, function(snapLine) {
|
54016 | snapLine.update();
|
54017 | });
|
54018 | };
|
54019 |
|
54020 | var SnappingModule = {
|
54021 | __init__: [
|
54022 | 'createMoveSnapping',
|
54023 | 'resizeSnapping',
|
54024 | 'snapping'
|
54025 | ],
|
54026 | createMoveSnapping: [ 'type', CreateMoveSnapping ],
|
54027 | resizeSnapping: [ 'type', ResizeSnapping ],
|
54028 | snapping: [ 'type', Snapping ]
|
54029 | };
|
54030 |
|
54031 | var SnappingModule$1 = {
|
54032 | __depends__: [ SnappingModule ],
|
54033 | __init__: [
|
54034 | 'connectSnapping',
|
54035 | 'createMoveSnapping'
|
54036 | ],
|
54037 | connectSnapping: [ 'type', BpmnConnectSnapping ],
|
54038 | createMoveSnapping: [ 'type', BpmnCreateMoveSnapping ]
|
54039 | };
|
54040 |
|
54041 | |
54042 |
|
54043 |
|
54044 | function SearchPad(canvas, eventBus, overlays, selection) {
|
54045 | this._open = false;
|
54046 | this._results = [];
|
54047 | this._eventMaps = [];
|
54048 |
|
54049 | this._canvas = canvas;
|
54050 | this._eventBus = eventBus;
|
54051 | this._overlays = overlays;
|
54052 | this._selection = selection;
|
54053 |
|
54054 |
|
54055 | this._container = domify(SearchPad.BOX_HTML);
|
54056 | this._searchInput = query(SearchPad.INPUT_SELECTOR, this._container);
|
54057 | this._resultsContainer = query(SearchPad.RESULTS_CONTAINER_SELECTOR, this._container);
|
54058 |
|
54059 |
|
54060 | this._canvas.getContainer().appendChild(this._container);
|
54061 |
|
54062 |
|
54063 | eventBus.on([ 'canvas.destroy', 'diagram.destroy' ], this.close, this);
|
54064 | }
|
54065 |
|
54066 |
|
54067 | SearchPad.$inject = [
|
54068 | 'canvas',
|
54069 | 'eventBus',
|
54070 | 'overlays',
|
54071 | 'selection'
|
54072 | ];
|
54073 |
|
54074 |
|
54075 | |
54076 |
|
54077 |
|
54078 | SearchPad.prototype._bindEvents = function() {
|
54079 | var self = this;
|
54080 |
|
54081 | function listen(el, selector, type, fn) {
|
54082 | self._eventMaps.push({
|
54083 | el: el,
|
54084 | type: type,
|
54085 | listener: delegateEvents.bind(el, selector, type, fn)
|
54086 | });
|
54087 | }
|
54088 |
|
54089 |
|
54090 | listen(document, 'html', 'click', function(e) {
|
54091 | self.close();
|
54092 | });
|
54093 |
|
54094 |
|
54095 |
|
54096 | listen(this._container, SearchPad.INPUT_SELECTOR, 'click', function(e) {
|
54097 | e.stopPropagation();
|
54098 | e.delegateTarget.focus();
|
54099 | });
|
54100 |
|
54101 |
|
54102 | listen(this._container, SearchPad.RESULT_SELECTOR, 'mouseover', function(e) {
|
54103 | e.stopPropagation();
|
54104 | self._scrollToNode(e.delegateTarget);
|
54105 | self._preselect(e.delegateTarget);
|
54106 | });
|
54107 |
|
54108 |
|
54109 | listen(this._container, SearchPad.RESULT_SELECTOR, 'click', function(e) {
|
54110 | e.stopPropagation();
|
54111 | self._select(e.delegateTarget);
|
54112 | });
|
54113 |
|
54114 |
|
54115 |
|
54116 | listen(this._container, SearchPad.INPUT_SELECTOR, 'keydown', function(e) {
|
54117 |
|
54118 |
|
54119 | if (e.keyCode === 38) {
|
54120 | e.preventDefault();
|
54121 | }
|
54122 |
|
54123 |
|
54124 | if (e.keyCode === 40) {
|
54125 | e.preventDefault();
|
54126 | }
|
54127 | });
|
54128 |
|
54129 |
|
54130 | listen(this._container, SearchPad.INPUT_SELECTOR, 'keyup', function(e) {
|
54131 |
|
54132 |
|
54133 | if (e.keyCode === 27) {
|
54134 | return self.close();
|
54135 | }
|
54136 |
|
54137 |
|
54138 | if (e.keyCode === 13) {
|
54139 | var selected = self._getCurrentResult();
|
54140 |
|
54141 | return selected ? self._select(selected) : self.close();
|
54142 | }
|
54143 |
|
54144 |
|
54145 | if (e.keyCode === 38) {
|
54146 | return self._scrollToDirection(true);
|
54147 | }
|
54148 |
|
54149 |
|
54150 | if (e.keyCode === 40) {
|
54151 | return self._scrollToDirection();
|
54152 | }
|
54153 |
|
54154 |
|
54155 |
|
54156 | if (e.keyCode === 37 || e.keyCode === 39) {
|
54157 | return;
|
54158 | }
|
54159 |
|
54160 |
|
54161 | self._search(e.delegateTarget.value);
|
54162 | });
|
54163 | };
|
54164 |
|
54165 |
|
54166 | |
54167 |
|
54168 |
|
54169 | SearchPad.prototype._unbindEvents = function() {
|
54170 | this._eventMaps.forEach(function(m) {
|
54171 | delegateEvents.unbind(m.el, m.type, m.listener);
|
54172 | });
|
54173 | };
|
54174 |
|
54175 |
|
54176 | |
54177 |
|
54178 |
|
54179 |
|
54180 |
|
54181 | SearchPad.prototype._search = function(pattern) {
|
54182 | var self = this;
|
54183 |
|
54184 | this._clearResults();
|
54185 |
|
54186 |
|
54187 | if (!pattern || pattern === '') {
|
54188 | return;
|
54189 | }
|
54190 |
|
54191 | var searchResults = this._searchProvider.find(pattern);
|
54192 |
|
54193 | if (!searchResults.length) {
|
54194 | return;
|
54195 | }
|
54196 |
|
54197 |
|
54198 | searchResults.forEach(function(result) {
|
54199 | var id = result.element.id;
|
54200 | var node = self._createResultNode(result, id);
|
54201 | self._results[id] = {
|
54202 | element: result.element,
|
54203 | node: node
|
54204 | };
|
54205 | });
|
54206 |
|
54207 |
|
54208 | var node = query(SearchPad.RESULT_SELECTOR, this._resultsContainer);
|
54209 | this._scrollToNode(node);
|
54210 | this._preselect(node);
|
54211 | };
|
54212 |
|
54213 |
|
54214 | |
54215 |
|
54216 |
|
54217 |
|
54218 | SearchPad.prototype._scrollToDirection = function(previous) {
|
54219 | var selected = this._getCurrentResult();
|
54220 | if (!selected) {
|
54221 | return;
|
54222 | }
|
54223 |
|
54224 | var node = previous ? selected.previousElementSibling : selected.nextElementSibling;
|
54225 | if (node) {
|
54226 | this._scrollToNode(node);
|
54227 | this._preselect(node);
|
54228 | }
|
54229 | };
|
54230 |
|
54231 |
|
54232 | |
54233 |
|
54234 |
|
54235 |
|
54236 |
|
54237 | SearchPad.prototype._scrollToNode = function(node) {
|
54238 | if (!node || node === this._getCurrentResult()) {
|
54239 | return;
|
54240 | }
|
54241 |
|
54242 | var nodeOffset = node.offsetTop;
|
54243 | var containerScroll = this._resultsContainer.scrollTop;
|
54244 |
|
54245 | var bottomScroll = nodeOffset - this._resultsContainer.clientHeight + node.clientHeight;
|
54246 |
|
54247 | if (nodeOffset < containerScroll) {
|
54248 | this._resultsContainer.scrollTop = nodeOffset;
|
54249 | } else if (containerScroll < bottomScroll) {
|
54250 | this._resultsContainer.scrollTop = bottomScroll;
|
54251 | }
|
54252 | };
|
54253 |
|
54254 |
|
54255 | |
54256 |
|
54257 |
|
54258 | SearchPad.prototype._clearResults = function() {
|
54259 | clear(this._resultsContainer);
|
54260 |
|
54261 | this._results = [];
|
54262 |
|
54263 | this._resetOverlay();
|
54264 |
|
54265 | this._eventBus.fire('searchPad.cleared');
|
54266 | };
|
54267 |
|
54268 |
|
54269 | |
54270 |
|
54271 |
|
54272 |
|
54273 |
|
54274 | SearchPad.prototype._getCurrentResult = function() {
|
54275 | return query(SearchPad.RESULT_SELECTED_SELECTOR, this._resultsContainer);
|
54276 | };
|
54277 |
|
54278 |
|
54279 | |
54280 |
|
54281 |
|
54282 |
|
54283 |
|
54284 |
|
54285 |
|
54286 |
|
54287 |
|
54288 |
|
54289 |
|
54290 |
|
54291 | SearchPad.prototype._createResultNode = function(result, id) {
|
54292 | var node = domify(SearchPad.RESULT_HTML);
|
54293 |
|
54294 |
|
54295 | if (result.primaryTokens.length > 0) {
|
54296 | createInnerTextNode(node, result.primaryTokens, SearchPad.RESULT_PRIMARY_HTML);
|
54297 | }
|
54298 |
|
54299 |
|
54300 | createInnerTextNode(node, result.secondaryTokens, SearchPad.RESULT_SECONDARY_HTML);
|
54301 |
|
54302 | attr(node, SearchPad.RESULT_ID_ATTRIBUTE, id);
|
54303 |
|
54304 | this._resultsContainer.appendChild(node);
|
54305 |
|
54306 | return node;
|
54307 | };
|
54308 |
|
54309 |
|
54310 | |
54311 |
|
54312 |
|
54313 |
|
54314 |
|
54315 |
|
54316 |
|
54317 |
|
54318 | SearchPad.prototype.registerProvider = function(provider) {
|
54319 | this._searchProvider = provider;
|
54320 | };
|
54321 |
|
54322 |
|
54323 | |
54324 |
|
54325 |
|
54326 | SearchPad.prototype.open = function() {
|
54327 | if (!this._searchProvider) {
|
54328 | throw new Error('no search provider registered');
|
54329 | }
|
54330 |
|
54331 | if (this.isOpen()) {
|
54332 | return;
|
54333 | }
|
54334 |
|
54335 | this._bindEvents();
|
54336 |
|
54337 | this._open = true;
|
54338 |
|
54339 | classes(this._container).add('open');
|
54340 |
|
54341 | this._searchInput.focus();
|
54342 |
|
54343 | this._eventBus.fire('searchPad.opened');
|
54344 | };
|
54345 |
|
54346 |
|
54347 | |
54348 |
|
54349 |
|
54350 | SearchPad.prototype.close = function() {
|
54351 | if (!this.isOpen()) {
|
54352 | return;
|
54353 | }
|
54354 |
|
54355 | this._unbindEvents();
|
54356 |
|
54357 | this._open = false;
|
54358 |
|
54359 | classes(this._container).remove('open');
|
54360 |
|
54361 | this._clearResults();
|
54362 |
|
54363 | this._searchInput.value = '';
|
54364 | this._searchInput.blur();
|
54365 |
|
54366 | this._resetOverlay();
|
54367 |
|
54368 | this._eventBus.fire('searchPad.closed');
|
54369 | };
|
54370 |
|
54371 |
|
54372 | |
54373 |
|
54374 |
|
54375 | SearchPad.prototype.toggle = function() {
|
54376 | this.isOpen() ? this.close() : this.open();
|
54377 | };
|
54378 |
|
54379 |
|
54380 | |
54381 |
|
54382 |
|
54383 | SearchPad.prototype.isOpen = function() {
|
54384 | return this._open;
|
54385 | };
|
54386 |
|
54387 |
|
54388 | |
54389 |
|
54390 |
|
54391 |
|
54392 |
|
54393 | SearchPad.prototype._preselect = function(node) {
|
54394 | var selectedNode = this._getCurrentResult();
|
54395 |
|
54396 |
|
54397 | if (node === selectedNode) {
|
54398 | return;
|
54399 | }
|
54400 |
|
54401 |
|
54402 | if (selectedNode) {
|
54403 | classes(selectedNode).remove(SearchPad.RESULT_SELECTED_CLASS);
|
54404 | }
|
54405 |
|
54406 | var id = attr(node, SearchPad.RESULT_ID_ATTRIBUTE);
|
54407 | var element = this._results[id].element;
|
54408 |
|
54409 | classes(node).add(SearchPad.RESULT_SELECTED_CLASS);
|
54410 |
|
54411 | this._resetOverlay(element);
|
54412 |
|
54413 | this._centerViewbox(element);
|
54414 |
|
54415 | this._selection.select(element);
|
54416 |
|
54417 | this._eventBus.fire('searchPad.preselected', element);
|
54418 | };
|
54419 |
|
54420 |
|
54421 | |
54422 |
|
54423 |
|
54424 |
|
54425 |
|
54426 | SearchPad.prototype._select = function(node) {
|
54427 | var id = attr(node, SearchPad.RESULT_ID_ATTRIBUTE);
|
54428 | var element = this._results[id].element;
|
54429 |
|
54430 | this.close();
|
54431 |
|
54432 | this._resetOverlay();
|
54433 |
|
54434 | this._centerViewbox(element);
|
54435 |
|
54436 | this._selection.select(element);
|
54437 |
|
54438 | this._eventBus.fire('searchPad.selected', element);
|
54439 | };
|
54440 |
|
54441 |
|
54442 | |
54443 |
|
54444 |
|
54445 |
|
54446 |
|
54447 | SearchPad.prototype._centerViewbox = function(element) {
|
54448 | var viewbox = this._canvas.viewbox();
|
54449 |
|
54450 | var box = getBBox(element);
|
54451 |
|
54452 | var newViewbox = {
|
54453 | x: (box.x + box.width/2) - viewbox.outer.width/2,
|
54454 | y: (box.y + box.height/2) - viewbox.outer.height/2,
|
54455 | width: viewbox.outer.width,
|
54456 | height: viewbox.outer.height
|
54457 | };
|
54458 |
|
54459 | this._canvas.viewbox(newViewbox);
|
54460 |
|
54461 | this._canvas.zoom(viewbox.scale);
|
54462 | };
|
54463 |
|
54464 |
|
54465 | |
54466 |
|
54467 |
|
54468 |
|
54469 |
|
54470 |
|
54471 | SearchPad.prototype._resetOverlay = function(element) {
|
54472 | if (this._overlayId) {
|
54473 | this._overlays.remove(this._overlayId);
|
54474 | }
|
54475 |
|
54476 | if (element) {
|
54477 | var box = getBBox(element);
|
54478 | var overlay = constructOverlay(box);
|
54479 | this._overlayId = this._overlays.add(element, overlay);
|
54480 | }
|
54481 | };
|
54482 |
|
54483 |
|
54484 | |
54485 |
|
54486 |
|
54487 |
|
54488 |
|
54489 |
|
54490 | function constructOverlay(box) {
|
54491 |
|
54492 | var offset = 6;
|
54493 | var w = box.width + offset * 2;
|
54494 | var h = box.height + offset * 2;
|
54495 |
|
54496 | var styles = [
|
54497 | 'width: '+ w +'px',
|
54498 | 'height: '+ h + 'px'
|
54499 | ].join('; ');
|
54500 |
|
54501 | return {
|
54502 | position: {
|
54503 | bottom: h - offset,
|
54504 | right: w - offset
|
54505 | },
|
54506 | show: true,
|
54507 | html: '<div style="' + styles + '" class="' + SearchPad.OVERLAY_CLASS + '"></div>'
|
54508 | };
|
54509 | }
|
54510 |
|
54511 |
|
54512 | |
54513 |
|
54514 |
|
54515 |
|
54516 |
|
54517 |
|
54518 |
|
54519 | function createInnerTextNode(parentNode, tokens, template) {
|
54520 | var text = createHtmlText(tokens);
|
54521 | var childNode = domify(template);
|
54522 | childNode.innerHTML = text;
|
54523 | parentNode.appendChild(childNode);
|
54524 | }
|
54525 |
|
54526 | |
54527 |
|
54528 |
|
54529 |
|
54530 |
|
54531 |
|
54532 |
|
54533 | function createHtmlText(tokens) {
|
54534 | var htmlText = '';
|
54535 |
|
54536 | tokens.forEach(function(t) {
|
54537 | if (t.matched) {
|
54538 | htmlText += '<strong class="' + SearchPad.RESULT_HIGHLIGHT_CLASS + '">' + escapeHTML(t.matched) + '</strong>';
|
54539 | } else {
|
54540 | htmlText += escapeHTML(t.normal);
|
54541 | }
|
54542 | });
|
54543 |
|
54544 | return htmlText !== '' ? htmlText : null;
|
54545 | }
|
54546 |
|
54547 |
|
54548 | |
54549 |
|
54550 |
|
54551 | SearchPad.CONTAINER_SELECTOR = '.djs-search-container';
|
54552 | SearchPad.INPUT_SELECTOR = '.djs-search-input input';
|
54553 | SearchPad.RESULTS_CONTAINER_SELECTOR = '.djs-search-results';
|
54554 | SearchPad.RESULT_SELECTOR = '.djs-search-result';
|
54555 | SearchPad.RESULT_SELECTED_CLASS = 'djs-search-result-selected';
|
54556 | SearchPad.RESULT_SELECTED_SELECTOR = '.' + SearchPad.RESULT_SELECTED_CLASS;
|
54557 | SearchPad.RESULT_ID_ATTRIBUTE = 'data-result-id';
|
54558 | SearchPad.RESULT_HIGHLIGHT_CLASS = 'djs-search-highlight';
|
54559 | SearchPad.OVERLAY_CLASS = 'djs-search-overlay';
|
54560 |
|
54561 | SearchPad.BOX_HTML =
|
54562 | '<div class="djs-search-container djs-draggable djs-scrollable">' +
|
54563 | '<div class="djs-search-input">' +
|
54564 | '<input type="text"/>' +
|
54565 | '</div>' +
|
54566 | '<div class="djs-search-results"></div>' +
|
54567 | '</div>';
|
54568 |
|
54569 | SearchPad.RESULT_HTML =
|
54570 | '<div class="djs-search-result"></div>';
|
54571 |
|
54572 | SearchPad.RESULT_PRIMARY_HTML =
|
54573 | '<div class="djs-search-result-primary"></div>';
|
54574 |
|
54575 | SearchPad.RESULT_SECONDARY_HTML =
|
54576 | '<p class="djs-search-result-secondary"></p>';
|
54577 |
|
54578 | var SearchPadModule = {
|
54579 | __depends__: [
|
54580 | OverlaysModule,
|
54581 | SelectionModule
|
54582 | ],
|
54583 | searchPad: [ 'type', SearchPad ]
|
54584 | };
|
54585 |
|
54586 | |
54587 |
|
54588 |
|
54589 | function BpmnSearchProvider(elementRegistry, searchPad, canvas) {
|
54590 |
|
54591 | this._elementRegistry = elementRegistry;
|
54592 | this._canvas = canvas;
|
54593 |
|
54594 | searchPad.registerProvider(this);
|
54595 | }
|
54596 |
|
54597 | BpmnSearchProvider.$inject = [
|
54598 | 'elementRegistry',
|
54599 | 'searchPad',
|
54600 | 'canvas'
|
54601 | ];
|
54602 |
|
54603 |
|
54604 | |
54605 |
|
54606 |
|
54607 |
|
54608 |
|
54609 |
|
54610 |
|
54611 |
|
54612 |
|
54613 |
|
54614 |
|
54615 |
|
54616 |
|
54617 |
|
54618 |
|
54619 |
|
54620 |
|
54621 |
|
54622 | BpmnSearchProvider.prototype.find = function(pattern) {
|
54623 | var rootElement = this._canvas.getRootElement();
|
54624 |
|
54625 | var elements = this._elementRegistry.filter(function(element) {
|
54626 | if (element.labelTarget) {
|
54627 | return false;
|
54628 | }
|
54629 | return true;
|
54630 | });
|
54631 |
|
54632 |
|
54633 | elements = filter(elements, function(element) {
|
54634 | return element !== rootElement;
|
54635 | });
|
54636 |
|
54637 | elements = map(elements, function(element) {
|
54638 | return {
|
54639 | primaryTokens: matchAndSplit(getLabel(element), pattern),
|
54640 | secondaryTokens: matchAndSplit(element.id, pattern),
|
54641 | element: element
|
54642 | };
|
54643 | });
|
54644 |
|
54645 |
|
54646 | elements = filter(elements, function(element) {
|
54647 | return hasMatched(element.primaryTokens) || hasMatched(element.secondaryTokens);
|
54648 | });
|
54649 |
|
54650 | elements = sortBy(elements, function(element) {
|
54651 | return getLabel(element.element) + element.element.id;
|
54652 | });
|
54653 |
|
54654 | return elements;
|
54655 | };
|
54656 |
|
54657 |
|
54658 | function hasMatched(tokens) {
|
54659 | var matched = filter(tokens, function(t) {
|
54660 | return !!t.matched;
|
54661 | });
|
54662 |
|
54663 | return matched.length > 0;
|
54664 | }
|
54665 |
|
54666 |
|
54667 | function matchAndSplit(text, pattern) {
|
54668 | var tokens = [],
|
54669 | originalText = text;
|
54670 |
|
54671 | if (!text) {
|
54672 | return tokens;
|
54673 | }
|
54674 |
|
54675 | text = text.toLowerCase();
|
54676 | pattern = pattern.toLowerCase();
|
54677 |
|
54678 | var i = text.indexOf(pattern);
|
54679 |
|
54680 | if (i > -1) {
|
54681 | if (i !== 0) {
|
54682 | tokens.push({
|
54683 | normal: originalText.substr(0, i)
|
54684 | });
|
54685 | }
|
54686 |
|
54687 | tokens.push({
|
54688 | matched: originalText.substr(i, pattern.length)
|
54689 | });
|
54690 |
|
54691 | if (pattern.length + i < text.length) {
|
54692 | tokens.push({
|
54693 | normal: originalText.substr(pattern.length + i, text.length)
|
54694 | });
|
54695 | }
|
54696 | } else {
|
54697 | tokens.push({
|
54698 | normal: originalText
|
54699 | });
|
54700 | }
|
54701 |
|
54702 | return tokens;
|
54703 | }
|
54704 |
|
54705 | var SearchModule = {
|
54706 | __depends__: [
|
54707 | SearchPadModule
|
54708 | ],
|
54709 | __init__: [ 'bpmnSearch'],
|
54710 | bpmnSearch: [ 'type', BpmnSearchProvider ]
|
54711 | };
|
54712 |
|
54713 | var initialDiagram =
|
54714 | '<?xml version="1.0" encoding="UTF-8"?>' +
|
54715 | '<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
|
54716 | 'xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
|
54717 | 'xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" ' +
|
54718 | 'xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" ' +
|
54719 | 'targetNamespace="http://bpmn.io/schema/bpmn" ' +
|
54720 | 'id="Definitions_1">' +
|
54721 | '<bpmn:process id="Process_1" isExecutable="false">' +
|
54722 | '<bpmn:startEvent id="StartEvent_1"/>' +
|
54723 | '</bpmn:process>' +
|
54724 | '<bpmndi:BPMNDiagram id="BPMNDiagram_1">' +
|
54725 | '<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">' +
|
54726 | '<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">' +
|
54727 | '<dc:Bounds height="36.0" width="36.0" x="173.0" y="102.0"/>' +
|
54728 | '</bpmndi:BPMNShape>' +
|
54729 | '</bpmndi:BPMNPlane>' +
|
54730 | '</bpmndi:BPMNDiagram>' +
|
54731 | '</bpmn:definitions>';
|
54732 |
|
54733 |
|
54734 | |
54735 |
|
54736 |
|
54737 |
|
54738 |
|
54739 |
|
54740 |
|
54741 |
|
54742 |
|
54743 |
|
54744 |
|
54745 |
|
54746 |
|
54747 |
|
54748 |
|
54749 |
|
54750 |
|
54751 |
|
54752 |
|
54753 |
|
54754 |
|
54755 |
|
54756 |
|
54757 |
|
54758 |
|
54759 |
|
54760 |
|
54761 |
|
54762 |
|
54763 |
|
54764 |
|
54765 |
|
54766 |
|
54767 |
|
54768 |
|
54769 |
|
54770 |
|
54771 |
|
54772 |
|
54773 |
|
54774 |
|
54775 |
|
54776 |
|
54777 |
|
54778 |
|
54779 |
|
54780 |
|
54781 |
|
54782 |
|
54783 |
|
54784 |
|
54785 |
|
54786 |
|
54787 |
|
54788 |
|
54789 |
|
54790 |
|
54791 |
|
54792 |
|
54793 |
|
54794 |
|
54795 |
|
54796 |
|
54797 |
|
54798 |
|
54799 |
|
54800 |
|
54801 |
|
54802 |
|
54803 |
|
54804 |
|
54805 |
|
54806 | function Modeler(options) {
|
54807 | Viewer.call(this, options);
|
54808 |
|
54809 |
|
54810 | this.on('import.parse.complete', function(event) {
|
54811 | if (!event.error) {
|
54812 | this._collectIds(event.definitions, event.context);
|
54813 | }
|
54814 | }, this);
|
54815 |
|
54816 | this.on('diagram.destroy', function() {
|
54817 | this.get('moddle').ids.clear();
|
54818 | }, this);
|
54819 | }
|
54820 |
|
54821 | inherits_browser(Modeler, Viewer);
|
54822 |
|
54823 | Modeler.Viewer = Viewer;
|
54824 | Modeler.NavigatedViewer = NavigatedViewer;
|
54825 |
|
54826 | |
54827 |
|
54828 |
|
54829 |
|
54830 |
|
54831 | Modeler.prototype.createDiagram = function(done) {
|
54832 | return this.importXML(initialDiagram, done);
|
54833 | };
|
54834 |
|
54835 | |
54836 |
|
54837 |
|
54838 |
|
54839 |
|
54840 | Modeler.prototype._createModdle = function(options) {
|
54841 | var moddle = Viewer.prototype._createModdle.call(this, options);
|
54842 |
|
54843 |
|
54844 |
|
54845 |
|
54846 | moddle.ids = new Ids([ 32, 36, 1 ]);
|
54847 |
|
54848 | return moddle;
|
54849 | };
|
54850 |
|
54851 | |
54852 |
|
54853 |
|
54854 |
|
54855 |
|
54856 |
|
54857 |
|
54858 | Modeler.prototype._collectIds = function(definitions, context) {
|
54859 |
|
54860 | var moddle = definitions.$model,
|
54861 | ids = moddle.ids,
|
54862 | id;
|
54863 |
|
54864 |
|
54865 | ids.clear();
|
54866 |
|
54867 | for (id in context.elementsById) {
|
54868 | ids.claim(id, context.elementsById[id]);
|
54869 | }
|
54870 | };
|
54871 |
|
54872 | Modeler.prototype._interactionModules = [
|
54873 |
|
54874 |
|
54875 | KeyboardMoveModule,
|
54876 | MoveCanvasModule,
|
54877 | TouchModule$1,
|
54878 | ZoomScrollModule
|
54879 | ];
|
54880 |
|
54881 | Modeler.prototype._modelingModules = [
|
54882 |
|
54883 |
|
54884 | AlignElementsModule,
|
54885 | AutoPlaceModule,
|
54886 | AutoScrollModule,
|
54887 | AutoResizeModule,
|
54888 | BendpointsModule,
|
54889 | ConnectModule,
|
54890 | ConnectionPreviewModule,
|
54891 | ContextPadModule$1,
|
54892 | CopyPasteModule$1,
|
54893 | CreateModule,
|
54894 | DistributeElementsModule$1,
|
54895 | EditorActionsModule$1,
|
54896 | GridSnappingModule$1,
|
54897 | InteractionEventsModule$1,
|
54898 | KeyboardModule$1,
|
54899 | KeyboardMoveSelectionModule,
|
54900 | LabelEditingModule,
|
54901 | ModelingModule,
|
54902 | MoveModule,
|
54903 | PaletteModule$1,
|
54904 | ReplacePreviewModule,
|
54905 | ResizeModule,
|
54906 | SnappingModule$1,
|
54907 | SearchModule
|
54908 | ];
|
54909 |
|
54910 |
|
54911 |
|
54912 |
|
54913 |
|
54914 |
|
54915 |
|
54916 |
|
54917 | Modeler.prototype._modules = [].concat(
|
54918 | Modeler.prototype._modules,
|
54919 | Modeler.prototype._interactionModules,
|
54920 | Modeler.prototype._modelingModules);
|
54921 |
|
54922 | return Modeler;
|
54923 |
|
54924 | }));
|