| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752 | 1×
1×
1×
1×
1×
1×
1×
68×
68×
1×
333×
1×
332×
332×
1×
331×
331×
331×
331×
59×
272×
59×
331×
55×
55×
331×
331×
331×
331×
331×
213×
213×
13×
8×
8×
213×
213×
213×
331×
192×
192×
192×
192×
139×
1×
331×
331×
22×
22×
1×
1×
84×
51×
51×
51×
51×
1×
51×
51×
84×
33×
33×
33×
33×
84×
33×
33×
33×
33×
33×
33×
84×
84×
7×
7×
331×
1×
84×
84×
5×
5×
5×
3×
2×
84×
12×
12×
12×
3×
9×
84×
1×
66×
2×
66×
2×
66×
2×
2×
1×
5×
5×
6×
6×
1×
331×
331×
233×
98×
98×
57×
57×
57×
57×
41×
41×
41×
41×
98×
98×
1×
1×
1×
1×
97×
17×
80×
1×
331×
331×
331×
118×
213×
213×
213×
56×
5×
5×
5×
157×
33×
124×
213×
1×
129×
95×
95×
34×
33×
33×
1×
227×
1×
226×
226×
3×
223×
223×
223×
1×
203×
203×
203×
203×
203×
203×
203×
227×
227×
227×
223×
4×
203×
203×
1×
223×
223×
223×
223×
223×
223×
223×
223×
223×
70×
223×
223×
84×
66×
18×
223×
102×
121×
37×
223×
70×
1×
84×
51×
51×
51×
51×
51×
51×
51×
51×
51×
51×
51×
3×
3×
3×
3×
3×
3×
3×
3×
3×
51×
3×
3×
3×
3×
3×
3×
3×
3×
3×
51×
51×
1×
1×
1×
2×
1×
1×
51×
51×
51×
84×
33×
33×
33×
33×
33×
33×
33×
33×
33×
33×
33×
2×
2×
2×
2×
2×
2×
2×
2×
2×
33×
9×
9×
9×
9×
9×
9×
9×
9×
9×
33×
33×
33×
33×
33×
1×
161×
161×
161×
161×
161×
183×
183×
17×
166×
166×
5×
5×
5×
5×
161×
161×
60×
101×
1×
102×
101×
101×
101×
101×
101×
101×
101×
101×
12×
12×
7×
7×
2×
2×
1×
1×
1×
1×
1×
2×
2×
2×
2×
43×
43×
6×
6×
6×
1×
1×
1×
5×
1×
4×
5×
1×
1×
5×
5×
4×
4×
1×
1×
1×
1×
1×
1×
1×
1×
3×
3×
3×
3×
101×
101×
102×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
4×
4×
4×
4×
4×
4×
4×
4×
4×
4×
4×
4×
4×
4×
4×
4×
4×
4×
2×
2×
2×
2×
2×
2×
4×
4×
4×
4×
4×
4×
4×
4×
4×
1×
37×
37×
37×
37×
37×
1×
1×
1×
2×
2×
2×
2×
5×
5×
5×
5×
5×
7×
7×
7×
7×
7×
14×
14×
1×
1×
3×
3×
1×
1×
1×
1×
1×
223×
41×
41×
41×
41×
4×
41×
182×
1×
68×
68×
1×
67613×
1×
1×
| var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
define(["require", "exports", "../enum/enum", "../utility/swim-lane-util", "../utility/diagram-util", "../utility/base-util"], function (require, exports, enum_1, swim_lane_util_1, diagram_util_1, base_util_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var DiagramCollaboration = (function () {
function DiagramCollaboration() {
this.collaborativeCollection = [];
this.isGroupAction = false;
}
DiagramCollaboration.prototype.serializeHistoryChange = function (args, diagram) {
if (!args) {
return [];
}
var historyEntry = args.change;
if (!historyEntry) {
return [];
}
var isUndo = args.action === 'Undo';
var isStartGroup = historyEntry.type === (isUndo ? 'EndGroup' : 'StartGroup');
var isEndGroup = historyEntry.type === (isUndo ? 'StartGroup' : 'EndGroup');
if (historyEntry.type === 'EndGroup') {
diagram.groupActionDepth += isUndo ? 1 : -1;
}
else if (historyEntry.type === 'StartGroup') {
diagram.groupActionDepth += isUndo ? -1 : 1;
}
if (isStartGroup && (diagram.groupActionDepth === 1)) {
this.collaborativeCollection = [];
this.isGroupAction = true;
}
var changedObjects = this.getChangedObjects(args, args.undoObject, args.redoObject, diagram);
var _a = this.categorizeAndEnrichObjects(changedObjects, args), nodes = _a.nodes, connectors = _a.connectors;
var propertyChanges = this.processHistoryEntryType(args, args.undoObject, args.redoObject, historyEntry, diagram);
var hasChanges = nodes.length > 0 || connectors.length > 0 || propertyChanges != null;
if (hasChanges) {
historyEntry.childTable = args.childTable;
if (args.childTable) {
for (var node in args.childTable) {
Eif (Object.prototype.hasOwnProperty.call(args.childTable, node)) {
historyEntry.childTable["" + node] = base_util_1.cloneObject(diagram.getNodeObject(node));
}
}
}
var value = {
modifiedNodes: nodes, modifiedConnectors: connectors,
entryType: historyEntry.type,
collectionChangedAction: historyEntry.changeType,
actionTrigger: args.action,
propertyChanges: propertyChanges,
historyAction: historyEntry.historyAction,
entry: historyEntry
};
var json = JSON.stringify(value);
this.collaborativeCollection.push(json);
}
if ((isEndGroup || !this.isGroupAction) && diagram.groupActionDepth === 0) {
var historyEntries = this.collaborativeCollection.slice();
this.collaborativeCollection = [];
this.isGroupAction = false;
return historyEntries;
}
return [];
};
DiagramCollaboration.prototype.processHistoryEntryType = function (args, oldValue, newValue, historyEntry, diagram) {
var action = null;
switch (historyEntry.type) {
case 'LabelCollectionChanged':
case 'PortCollectionChanged':
case 'PhaseCollectionChanged':
case 'LaneCollectionChanged': {
action = { newObjectValue: oldValue };
break;
}
case 'LanePositionChanged': {
action = args.action === 'Undo' ? { newObjectValue: oldValue } : args.action === 'Redo' ? { newObjectValue: newValue }
: { newObjectValue: args.source[0] };
break;
}
case 'PropertyChanged': {
if (newValue.nodes) {
for (var node in newValue.nodes) {
Eif (Object.prototype.hasOwnProperty.call(newValue.nodes, node)) {
var obj = newValue.nodes["" + node];
if (obj.style && obj.style.gradient) {
this.cloneGradientStops(obj.style.gradient);
}
var nodechildrenId = this.getChildrenIds(node, obj, diagram, true);
action = { childrenId: nodechildrenId };
}
}
}
if (oldValue.connectors) {
for (var connector in oldValue.connectors) {
Eif (Object.prototype.hasOwnProperty.call(oldValue.connectors, connector)) {
var obj = oldValue.connectors["" + connector];
this.cloneAsObject(obj);
}
}
}
if (newValue.connectors) {
for (var connector in newValue.connectors) {
Eif (Object.prototype.hasOwnProperty.call(newValue.connectors, connector)) {
var obj = newValue.connectors["" + connector];
this.cloneAsObject(obj);
var nodechildrenId = this.getChildrenIds(connector, obj, diagram, false);
action = { childrenId: nodechildrenId };
}
}
}
action = __assign({}, action, { sourceIds: args.sourceId, oldValue: { nodes: oldValue.nodes, connectors: oldValue.connectors }, newValue: { nodes: newValue.nodes, connectors: newValue.connectors } });
break;
}
case 'AddChildToGroupNode':
case 'RemoveChildFromGroupNode':
case 'AnnotationPropertyChanged': {
action = { objectId: args.objectId };
break;
}
}
return action;
};
DiagramCollaboration.prototype.getChildrenIds = function (index, obj, diagram, isNode) {
var childrenId = [];
if (obj.annotations) {
for (var annotation in obj.annotations) {
Eif (Object.prototype.hasOwnProperty.call(obj.annotations, annotation)) {
if (isNode) {
childrenId.push(diagram.nodes["" + index].annotations["" + annotation].id);
}
else {
childrenId.push(diagram.connectors["" + index].annotations["" + annotation].id);
}
}
}
}
if (obj.ports) {
for (var port in obj.ports) {
Eif (Object.prototype.hasOwnProperty.call(obj.ports, port)) {
if (isNode) {
childrenId.push(diagram.nodes["" + index].ports["" + port].id);
}
else {
childrenId.push(diagram.connectors["" + index].ports["" + port].id);
}
}
}
}
return childrenId;
};
DiagramCollaboration.prototype.cloneAsObject = function (obj) {
if (obj.sourceDecorator && obj.sourceDecorator.style && obj.sourceDecorator.style.gradient) {
this.cloneGradientStops(obj.sourceDecorator.style.gradient);
}
if (obj.targetDecorator && obj.targetDecorator.style && obj.targetDecorator.style.gradient) {
this.cloneGradientStops(obj.targetDecorator.style.gradient);
}
if (obj.segments) {
var clonedValue = base_util_1.cloneObject(obj.segments);
obj.segments = clonedValue;
}
};
DiagramCollaboration.prototype.cloneGradientStops = function (gradient) {
Eif (gradient && gradient.stops) {
for (var i = 0; i < gradient.stops.length; i++) {
var stop_1 = base_util_1.cloneObject(gradient.stops[parseInt(i.toString(), 10)]);
gradient.stops[parseInt(i.toString(), 10)] = stop_1;
}
}
};
DiagramCollaboration.prototype.getChangedObjects = function (args, undoObject, redoObject, diagram) {
var isUndoOrRedo = args.action === 'Undo' ||
args.action === 'Redo';
if (!isUndoOrRedo) {
return args.source;
}
var historyObject = undefined;
if (args.action === 'Undo') {
var undoHasId = !!(undoObject && undoObject.id &&
diagram.getObject(undoObject.id));
var undoIsSelector = !!(undoObject &&
undoObject.nodes &&
undoObject.connectors);
var isValidUndo = undoHasId || undoIsSelector;
historyObject = isValidUndo ? undoObject : undefined;
}
else {
var redoHasId = !!(redoObject && redoObject.id &&
diagram.getObject(redoObject.id));
var redoIsSelector = !!(redoObject &&
redoObject.nodes &&
redoObject.connectors);
var isValidRedo = redoHasId || redoIsSelector;
historyObject = isValidRedo ? redoObject : undefined;
}
var selector = historyObject;
if (selector && selector.nodes && selector.connectors) {
var objects = [];
objects.push.apply(objects, (selector.nodes));
objects.push.apply(objects, (selector.connectors));
return objects;
}
else if (historyObject && historyObject) {
return [historyObject];
}
return args.source;
};
DiagramCollaboration.prototype.categorizeAndEnrichObjects = function (changedObjects, historyEntry) {
var nodes = [];
var connectors = [];
if (!changedObjects || changedObjects.length === 0 || historyEntry.type === 'PropertyChanged') {
return { nodes: nodes, connectors: connectors };
}
for (var _i = 0, changedObjects_1 = changedObjects; _i < changedObjects_1.length; _i++) {
var obj = changedObjects_1[_i];
if (obj.nodes) {
for (var _a = 0, _b = obj.nodes; _a < _b.length; _a++) {
var node = _b[_a];
var nodeTyped = node;
this.updateNodeAndConnectors(nodeTyped, nodes, connectors);
}
}
else if (obj.connectors) {
for (var _c = 0, _d = obj.connectors; _c < _d.length; _c++) {
var connector = _d[_c];
var connectorTyped = connector;
this.updateNodeAndConnectors(connectorTyped, nodes, connectors);
}
}
else {
this.updateNodeAndConnectors(obj, nodes, connectors);
}
}
return { nodes: nodes, connectors: connectors };
};
DiagramCollaboration.prototype.updateNodeAndConnectors = function (obj, nodes, connectors) {
if (obj.offsetX !== undefined) {
obj.addInfo = { 'parentId': obj.parentId };
nodes.push(base_util_1.cloneObject(obj));
}
else if (obj.sourcePoint && obj.targetPoint) {
obj.addInfo = { 'parentId': obj.parentId };
connectors.push(base_util_1.cloneObject(obj));
}
};
DiagramCollaboration.prototype.validateDiagramChanges = function (data) {
if (typeof data !== 'object' || data === null) {
return null;
}
var changes = data;
if (!changes.entryType || typeof changes.entryType !== 'string') {
return null;
}
Iif (changes.modifiedNodes !== undefined && changes.modifiedNodes !== null && !Array.isArray(changes.modifiedNodes)) {
return null;
}
Iif (changes.modifiedConnectors !== undefined && changes.modifiedConnectors !== null && !Array.isArray(changes.modifiedConnectors)) {
return null;
}
return changes;
};
DiagramCollaboration.prototype.applyRemoteChanges = function (modifiedOperations, diagram) {
var _this = this;
Iif (!diagram.undoRedoModule) {
return;
}
Eif (modifiedOperations.length > 0) {
diagram.realActions |= enum_1.RealAction.PreventHistoryEntryForCollaboration;
var previous = diagram.getProtectPropertyChangeValue();
diagram.protectPropertyChange(true);
modifiedOperations.forEach(function (data) {
try {
var parsedData = _this.validateDiagramChanges(JSON.parse(data));
if (parsedData) {
_this.updateDiagram(parsedData, diagram);
}
else {
console.warn('[WARNING] :: Invalid diagram change payload received');
}
}
catch (error) {
console.warn('[WARNING] :: Failed to parse or apply diagram changes:', error);
}
});
diagram.realActions &= ~enum_1.RealAction.PreventHistoryEntryForCollaboration;
diagram.protectPropertyChange(previous);
}
};
DiagramCollaboration.prototype.updateDiagram = function (parsedData, diagram) {
var modifiedNodes = parsedData.modifiedNodes;
var modifiedConnectors = parsedData.modifiedConnectors;
var historyEntryType = parsedData.entryType;
var historyAction = parsedData.historyAction;
var historyEntryChangeType = parsedData.collectionChangedAction;
var propertyChanges = parsedData.propertyChanges;
var actionTrigger = parsedData.actionTrigger;
var entry = parsedData.entry;
if (actionTrigger === 'Undo' || actionTrigger === 'Redo') {
diagram.diagramActions |= enum_1.DiagramAction.UndoRedo;
}
var _a = this.getAdjustedHistoryTypes(historyEntryType, historyEntryChangeType, actionTrigger), adjustedHistoryType = _a.type, adjustedChangeType = _a.change;
if (historyEntryType === 'PropertyChanged') {
if (actionTrigger !== 'Undo') {
this.processPropertyChanges(propertyChanges.sourceIds, propertyChanges.oldValue, propertyChanges.newValue, propertyChanges.childrenId, diagram);
}
else {
this.processPropertyChanges(propertyChanges.sourceIds, propertyChanges.newValue, propertyChanges.oldValue, propertyChanges.childrenId, diagram);
}
}
if ((Array.isArray(modifiedNodes) && modifiedNodes.length > 0) || (propertyChanges && historyEntryType === 'LanePositionChanged')) {
this.processNodeChangesAsync(modifiedNodes, propertyChanges, adjustedHistoryType, entry, adjustedChangeType, historyAction, diagram);
}
else if (Array.isArray(modifiedConnectors) && modifiedConnectors.length > 0) {
this.processConnectorChangesAsync(modifiedConnectors, propertyChanges, adjustedHistoryType, adjustedChangeType, diagram);
}
if (actionTrigger === 'Undo' || actionTrigger === 'Redo') {
diagram.diagramActions &= ~enum_1.DiagramAction.UndoRedo;
}
};
DiagramCollaboration.prototype.processPropertyChanges = function (stringids, oldValues, newValues, childrenId, diagram) {
if (newValues.nodes) {
var newValue = [];
var oldValue = [];
var newData = newValues.nodes;
var oldData = oldValues.nodes;
for (var value in newData) {
Eif (Object.prototype.hasOwnProperty.call(newData, value)) {
newValue.push(newData["" + value]);
oldValue.push(oldData["" + value]);
}
}
for (var indexId = 0; indexId < stringids.length; indexId++) {
var obj = diagram.nameTable["" + stringids[parseInt(indexId.toString(), 10)]];
if (newValue[parseInt(indexId.toString(), 10)].annotations && childrenId && childrenId.length > 0) {
var index = 0;
for (var annotationIndex in newValue[parseInt(indexId.toString(), 10)].annotations) {
Eif (Object.prototype.hasOwnProperty.call(newValue[parseInt(indexId.toString(), 10)].annotations, annotationIndex)) {
for (var _i = 0, _a = obj.annotations; _i < _a.length; _i++) {
var current = _a[_i];
Eif (current.id === childrenId[parseInt(indexId.toString(), 10)]) {
this.updatePublicProperties(current, newValue[parseInt(indexId.toString(), 10)].annotations["" + annotationIndex]);
index++;
break;
}
}
}
}
}
if (newValue[parseInt(indexId.toString(), 10)].ports && childrenId && childrenId.length > 0) {
var index = 0;
for (var newPort in newValue[parseInt(indexId.toString(), 10)].ports) {
Eif (Object.prototype.hasOwnProperty.call(newValue[parseInt(indexId.toString(), 10)].ports, newPort)) {
for (var _b = 0, _c = obj.ports; _b < _c.length; _b++) {
var current = _c[_b];
Eif (current.id === childrenId[parseInt(index.toString(), 10)]) {
this.updatePublicProperties(current, newValue[parseInt(indexId.toString(), 10)].ports["" + newPort]);
index++;
break;
}
}
}
}
}
this.updatePublicProperties(obj, newValue[parseInt(indexId.toString(), 10)]);
if (newValue[parseInt(indexId.toString(), 10)].style && newValue[parseInt(indexId.toString(), 10)].style.gradient) {
var dstStops = newValue[parseInt(indexId.toString(), 10)].style.gradient.stops;
var srcStops = obj.style.gradient.stops;
for (var stopIndex = 0; stopIndex < dstStops.length; stopIndex++) {
dstStops[parseInt(stopIndex.toString(), 10)] = srcStops[parseInt(stopIndex.toString(), 10)];
}
diagram.updateGradient(newValue[parseInt(indexId.toString(), 10)], oldValue[parseInt(indexId.toString(), 10)], obj);
obj.oldGradientValue = base_util_1.cloneObject(newValue[parseInt(indexId.toString(), 10)].style.gradient);
}
var _oldNode = oldValue[parseInt(indexId.toString(), 10)];
var _newNode = newValue[parseInt(indexId.toString(), 10)];
diagram.nodePropertyChange(obj, _oldNode, _newNode, undefined, true, true);
}
}
if (newValues.connectors) {
var newValue = [];
var oldValue = [];
var newData = newValues.connectors;
var oldData = oldValues.connectors;
for (var value in newData) {
Eif (Object.prototype.hasOwnProperty.call(newData, value)) {
newValue.push(newData["" + value]);
oldValue.push(oldData["" + value]);
}
}
for (var i = 0; i < stringids.length; i++) {
var obj = diagram.nameTable["" + stringids[parseInt(i.toString(), 10)]];
if (newValue[parseInt(i.toString(), 10)].annotations &&
childrenId &&
childrenId.length > 0) {
var index = 0;
for (var annotationIndex in newValue[parseInt(i.toString(), 10)].annotations) {
Eif (Object.prototype.hasOwnProperty.call(newValue[parseInt(i.toString(), 10)].annotations, annotationIndex)) {
for (var _d = 0, _e = obj.annotations; _d < _e.length; _d++) {
var current = _e[_d];
Eif (current.id === childrenId[parseInt(index.toString(), 10)]) {
this.updatePublicProperties(current, newValue[parseInt(index.toString(), 10)].annotations["" + annotationIndex]);
index++;
break;
}
}
}
}
}
if (newValue[parseInt(i.toString(), 10)].ports &&
childrenId &&
childrenId.length > 0) {
var index = 0;
for (var newPort in newValue[parseInt(i.toString(), 10)].ports) {
Eif (Object.prototype.hasOwnProperty.call(newValue[parseInt(i.toString(), 10)].ports, newPort)) {
for (var _f = 0, _g = obj.ports; _f < _g.length; _f++) {
var port = _g[_f];
Eif (port.id === childrenId[parseInt(index.toString(), 10)]) {
this.updatePublicProperties(port, newValue[parseInt(i.toString(), 10)].ports["" + newPort]);
index++;
break;
}
}
}
}
}
var connectorNew = newValue[parseInt(i.toString(), 10)];
this.updatePublicProperties(obj, connectorNew);
var _oldConnector = oldValue["" + i];
var _newConnector = newValue["" + i];
diagram.connectorPropertyChange(obj, _oldConnector, _newConnector, undefined, true);
}
}
};
DiagramCollaboration.prototype.updatePublicProperties = function (source, target) {
Iif (!source || typeof source !== 'object') {
return;
}
var targetKeys = Object.keys(target);
var sourceAll = source;
var targetAll = target;
for (var _i = 0, targetKeys_1 = targetKeys; _i < targetKeys_1.length; _i++) {
var key = targetKeys_1[_i];
if (key === 'annotations' || key === 'ports') {
continue;
}
var isShape = targetAll["" + key];
if (isShape && isShape.type) {
var srcShape = sourceAll["" + key];
Eif (srcShape && srcShape.type !== isShape.type) {
sourceAll["" + key] = targetAll["" + key];
continue;
}
}
var isTargetPlainObject = targetAll["" + key] && typeof targetAll["" + key] === 'object' && !Array.isArray(targetAll["" + key]);
if (isTargetPlainObject) {
this.updatePublicProperties(sourceAll["" + key], targetAll["" + key]);
}
else {
sourceAll["" + key] = targetAll["" + key];
}
}
};
DiagramCollaboration.prototype.processNodeChangesAsync = function (nodes, propertyChanges, historyType, entry, changeType, historyAction, diagram) {
for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
var nodeObj = nodes_1[_i];
var objectToUpdate = diagram.getObject(nodeObj.id);
var previous = diagram.getProtectPropertyChangeValue();
diagram.protectPropertyChange(true);
Iif (!objectToUpdate && historyType !== 'Group' && historyType !== 'CollectionChanged' && historyType !== 'LanePositionChanged'
&& historyType !== 'PhaseCollectionChanged' && historyType !== 'LaneCollectionChanged') {
continue;
}
diagram.isCollaborativeContainerChanges =
(nodeObj && nodeObj.shape && nodeObj.shape.type === 'Container') ||
(!!(nodeObj && nodeObj.parentId) &&
diagram &&
diagram.nameTable &&
diagram.nameTable[nodeObj.parentId] &&
diagram.nameTable[nodeObj.parentId].shape &&
diagram.nameTable[nodeObj.parentId].shape.type === 'Container');
try {
switch (historyType) {
case 'Align':
case 'Distribute':
case 'PositionChanged': {
diagram.undoRedoModule.positionChanged(nodeObj, diagram);
break;
}
case 'SizeChanged':
case 'Sizing': {
diagram.undoRedoModule.nodeSizeChange(nodeObj, diagram, entry);
break;
}
case 'RotationChanged': {
diagram.undoRedoModule.rotateNode({ nodes: nodes }, nodeObj, diagram, entry, 'undo');
break;
}
case 'LabelCollectionChanged': {
Eif (propertyChanges) {
var annotation = propertyChanges.newObjectValue;
Eif (annotation) {
diagram.undoRedoModule.labelCollectionChanged(nodeObj, annotation, changeType, diagram);
}
}
break;
}
case 'ColumnWidthChanged': {
this.recordGridSizeChanged(nodeObj, diagram, false, false);
break;
}
case 'RowHeightChanged': {
this.recordGridSizeChanged(nodeObj, diagram, false, true);
break;
}
case 'CollectionChanged': {
diagram.undoRedoModule.collectionChanged(nodeObj, changeType, null, diagram);
break;
}
case 'PhaseCollectionChanged':
case 'LaneCollectionChanged': {
Eif (propertyChanges) {
diagram.undoRedoModule.laneOrPhaseCollectionChanged(changeType, nodeObj, propertyChanges.newObjectValue, diagram);
}
break;
}
case 'ChildCollectionChanged': {
diagram.isCollaborativeContainerChanges = true;
diagram.undoRedoModule.childCollectionChanged(nodeObj, diagram, false, historyAction);
break;
}
case 'PortCollectionChanged': {
if (changeType === 'Remove') {
diagram.removePorts(nodeObj, [propertyChanges.newObjectValue]);
}
else {
diagram.addPorts(nodeObj, [propertyChanges.newObjectValue]);
}
break;
}
case 'AnnotationPropertyChanged': {
this.annotationPropertyChange(nodeObj, propertyChanges.objectId, diagram);
break;
}
case 'Group': {
diagram.add(nodeObj);
break;
}
case 'UnGroup': {
diagram.commandHandler.unGroup(nodeObj);
break;
}
case 'SendBackward': {
diagram.commandHandler.sendBackward(objectToUpdate);
break;
}
case 'SendToBack': {
diagram.commandHandler.sendToBack(objectToUpdate);
break;
}
case 'BringToFront': {
diagram.commandHandler.bringToFront(objectToUpdate);
break;
}
case 'SendForward': {
diagram.commandHandler.sendForward(objectToUpdate);
break;
}
case 'AddChildToGroupNode': {
diagram.addChildToGroup(objectToUpdate, propertyChanges.objectId);
break;
}
case 'RemoveChildFromGroupNode': {
diagram.removeChildFromGroup(objectToUpdate, propertyChanges.objectId);
break;
}
}
}
finally {
diagram.isCollaborativeContainerChanges = false;
diagram.protectPropertyChange(previous);
}
}
if (propertyChanges && historyType === 'LanePositionChanged') {
var positionChangedArgs = propertyChanges.newObjectValue;
Eif (positionChangedArgs.source) {
var parent_1 = diagram.nameTable[positionChangedArgs.source.parentId];
Eif (parent_1 && parent_1.shape.type === 'SwimLane') {
swim_lane_util_1.laneInterChanged(diagram, positionChangedArgs.target, positionChangedArgs.source);
diagram.clearSelection();
}
}
}
};
DiagramCollaboration.prototype.annotationPropertyChange = function (obj, annotationId, diagram) {
var oldElement = diagram_util_1.findAnnotation(obj, annotationId);
var undoChanges = diagram.commandHandler.getAnnotationChanges(diagram.nameTable[obj.id], oldElement);
Eif (obj.offsetX) {
diagram.nodePropertyChange(diagram.nameTable[obj.id], {}, undoChanges);
}
else {
diagram.connectorPropertyChange(diagram.nameTable[obj.id], {}, undoChanges);
}
};
DiagramCollaboration.prototype.recordGridSizeChanged = function (nodeObj, diagram, isRedo, isRow) {
var obj = nodeObj;
Eif (obj.parentId) {
var swimlane = diagram.nameTable[obj.parentId];
var actualObject = diagram.nameTable[obj.id];
var x = swimlane.wrapper.bounds.x;
var y = swimlane.wrapper.bounds.y;
Eif (swimlane.shape.type === 'SwimLane') {
var grid = swimlane.wrapper.children[0];
var padding = swimlane.shape.padding;
var isUndoRedo = false;
Iif (diagram.diagramActions & enum_1.DiagramAction.UndoRedo) {
isUndoRedo = true;
}
var widthDiff = 0;
var heightDiff = 0;
Eif (obj.wrapper && obj.wrapper.actualSize && actualObject.wrapper && actualObject.wrapper.actualSize) {
widthDiff = obj.wrapper.actualSize.width - actualObject.wrapper.actualSize.width;
heightDiff = obj.wrapper.actualSize.height - actualObject.wrapper.actualSize.height;
}
swim_lane_util_1.updateSwimLaneObject(diagram, actualObject, swimlane, obj, widthDiff, heightDiff);
if (isRow) {
grid.updateRowHeight(obj.rowIndex, obj.wrapper.actualSize.height, true, padding, isUndoRedo);
swimlane.height = swimlane.wrapper.height = grid.height;
}
else {
grid.updateColumnWidth(obj.columnIndex, obj.wrapper.actualSize.width, true, padding, isUndoRedo);
swimlane.width = swimlane.wrapper.width = grid.width;
Eif (obj.isPhase) {
actualObject.maxWidth = actualObject.wrapper.maxWidth = obj.wrapper.actualSize.width;
}
}
swim_lane_util_1.swimLaneMeasureAndArrange(swimlane);
Eif (swimlane.shape.orientation === 'Horizontal') {
swim_lane_util_1.updatePhaseMaxWidth(swimlane, diagram, actualObject.wrapper, actualObject.columnIndex);
}
swim_lane_util_1.updateHeaderMaxWidth(diagram, swimlane);
var tx = x - swimlane.wrapper.bounds.x;
var ty = y - swimlane.wrapper.bounds.y;
diagram.drag(swimlane, tx, ty);
diagram.clearSelection();
diagram.updateDiagramObject(swimlane);
}
}
};
DiagramCollaboration.prototype.processConnectorChangesAsync = function (connectors, propertyChanges, historyType, changeType, diagram) {
for (var _i = 0, connectors_1 = connectors; _i < connectors_1.length; _i++) {
var connectorObj = connectors_1[_i];
var objectToUpdate = diagram.getObject(connectorObj.id);
Iif (!objectToUpdate && historyType !== 'CollectionChanged') {
continue;
}
switch (historyType) {
case 'PositionChanged':
case 'SizeChanged':
case 'RotationChanged': {
diagram.undoRedoModule.segmentChanged(connectorObj, diagram);
diagram.undoRedoModule.connectionChanged(connectorObj, diagram);
break;
}
case 'ConnectionChanged': {
diagram.undoRedoModule.recordConnectionChanged(connectorObj, diagram);
break;
}
case 'SegmentChanged': {
diagram.undoRedoModule.segmentChanged(connectorObj, diagram);
break;
}
case 'LabelCollectionChanged': {
Eif (propertyChanges) {
var annotation = propertyChanges.newObjectValue;
Eif (annotation) {
diagram.undoRedoModule.labelCollectionChanged(connectorObj, annotation, changeType, diagram);
}
}
break;
}
case 'PortCollectionChanged': {
Eif (propertyChanges) {
var port = propertyChanges.newObjectValue;
Eif (port) {
diagram.undoRedoModule.portCollectionChanged(connectorObj, port, changeType, diagram);
}
}
break;
}
case 'CollectionChanged': {
diagram.undoRedoModule.collectionChanged(connectorObj, changeType, null, diagram);
break;
}
case 'SendBackward': {
diagram.commandHandler.sendBackward(objectToUpdate);
break;
}
case 'SendToBack': {
diagram.commandHandler.sendToBack(objectToUpdate);
break;
}
case 'BringToFront': {
diagram.commandHandler.bringToFront(objectToUpdate);
break;
}
case 'SendForward': {
diagram.commandHandler.sendForward(objectToUpdate);
break;
}
}
}
};
DiagramCollaboration.prototype.getAdjustedHistoryTypes = function (type, change, trigger) {
if (trigger === 'Undo') {
var adjustedChange = change === 'Insert'
? 'Remove'
: 'Insert';
var adjustedTypeMap = {
Group: 'UnGroup',
UnGroup: 'Group',
AddChildToGroupNode: 'RemoveChildFromGroupNode',
RemoveChildFromGroupNode: 'AddChildToGroupNode'
};
var adjustedType = type;
if (Object.prototype.hasOwnProperty.call(adjustedTypeMap, String(type))) {
adjustedType = adjustedTypeMap[String(type)];
}
return { type: adjustedType, change: adjustedChange };
}
return { type: type, change: change };
};
DiagramCollaboration.prototype.destroy = function () {
this.collaborativeCollection = [];
this.isGroupAction = false;
};
DiagramCollaboration.prototype.getModuleName = function () {
return 'DiagramCollaboration';
};
return DiagramCollaboration;
}());
exports.DiagramCollaboration = DiagramCollaboration;
});
|