@jylups/cmmn-js 0.0.0-stage → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/.babelrc +3 -0
  2. package/CHANGELOG.md +119 -0
  3. package/LICENSE +23 -0
  4. package/README.md +107 -2
  5. package/dist/assets/cmmn-font/css/cmmn-codes.css +41 -0
  6. package/dist/assets/cmmn-font/css/cmmn-embedded.css +94 -0
  7. package/dist/assets/cmmn-font/css/cmmn.css +97 -0
  8. package/dist/assets/cmmn-font/font/cmmn.eot +0 -0
  9. package/dist/assets/cmmn-font/font/cmmn.svg +90 -0
  10. package/dist/assets/cmmn-font/font/cmmn.ttf +0 -0
  11. package/dist/assets/cmmn-font/font/cmmn.woff +0 -0
  12. package/dist/assets/cmmn-font/font/cmmn.woff2 +0 -0
  13. package/dist/assets/diagram-js.css +713 -0
  14. package/dist/cmmn-modeler.development.js +44817 -0
  15. package/dist/cmmn-modeler.production.min.js +2 -0
  16. package/dist/cmmn-navigated-viewer.development.js +18131 -0
  17. package/dist/cmmn-navigated-viewer.production.min.js +2 -0
  18. package/dist/cmmn-viewer.development.js +17599 -0
  19. package/dist/cmmn-viewer.production.min.js +2 -0
  20. package/index.js +1 -0
  21. package/lib/Modeler.js +222 -0
  22. package/lib/NavigatedViewer.js +28 -0
  23. package/lib/Viewer.js +489 -0
  24. package/lib/core/ItemRegistry.js +316 -0
  25. package/lib/core/index.js +7 -0
  26. package/lib/draw/CmmnRenderer.js +1235 -0
  27. package/lib/draw/PathMap.js +335 -0
  28. package/lib/draw/index.js +5 -0
  29. package/lib/features/auto-resize/CmmnAutoResizeProvider.js +57 -0
  30. package/lib/features/auto-resize/index.js +7 -0
  31. package/lib/features/context-pad/ContextPadProvider.js +240 -0
  32. package/lib/features/context-pad/index.js +11 -0
  33. package/lib/features/editor-actions/CmmnEditorActions.js +105 -0
  34. package/lib/features/editor-actions/index.js +10 -0
  35. package/lib/features/keyboard/CmmnKeyboardBindings.js +159 -0
  36. package/lib/features/keyboard/index.js +7 -0
  37. package/lib/features/label-editing/LabelEditingProvider.js +221 -0
  38. package/lib/features/label-editing/LabelUtil.js +95 -0
  39. package/lib/features/label-editing/cmd/UpdateLabelHandler.js +63 -0
  40. package/lib/features/label-editing/index.js +9 -0
  41. package/lib/features/modeling/CmmnFactory.js +166 -0
  42. package/lib/features/modeling/CmmnLayouter.js +49 -0
  43. package/lib/features/modeling/CmmnUpdater.js +511 -0
  44. package/lib/features/modeling/ElementFactory.js +215 -0
  45. package/lib/features/modeling/Modeling.js +185 -0
  46. package/lib/features/modeling/behavior/AttachCriterionBehavior.js +58 -0
  47. package/lib/features/modeling/behavior/CaseFileItemUpdater.js +324 -0
  48. package/lib/features/modeling/behavior/LabelBehavior.js +139 -0
  49. package/lib/features/modeling/behavior/PlanItemDefinitionUpdater.js +449 -0
  50. package/lib/features/modeling/behavior/PlanningTableUpdater.js +620 -0
  51. package/lib/features/modeling/behavior/ReplaceConnectionBehavior.js +320 -0
  52. package/lib/features/modeling/behavior/ReplaceElementBehavior.js +395 -0
  53. package/lib/features/modeling/behavior/ResizeCasePlanModelBehavior.js +108 -0
  54. package/lib/features/modeling/behavior/SentryUpdater.js +678 -0
  55. package/lib/features/modeling/behavior/UnclaimIdBehavior.js +28 -0
  56. package/lib/features/modeling/behavior/index.js +24 -0
  57. package/lib/features/modeling/cmd/AppendShapeHandler.js +52 -0
  58. package/lib/features/modeling/cmd/IdClaimHandler.js +38 -0
  59. package/lib/features/modeling/cmd/ReconnectConnectionHandler.js +57 -0
  60. package/lib/features/modeling/cmd/ReplaceShapeHandler.js +46 -0
  61. package/lib/features/modeling/cmd/UpdateControlsHandler.js +221 -0
  62. package/lib/features/modeling/cmd/UpdatePropertiesHandler.js +240 -0
  63. package/lib/features/modeling/cmd/UpdateSemanticParentHandler.js +94 -0
  64. package/lib/features/modeling/index.js +20 -0
  65. package/lib/features/modeling/util/ModelingUtil.js +138 -0
  66. package/lib/features/modeling/util/PlanItemDefinitionUtil.js +183 -0
  67. package/lib/features/ordering/CmmnOrderingProvider.js +146 -0
  68. package/lib/features/ordering/index.js +4 -0
  69. package/lib/features/outline/Outline.js +47 -0
  70. package/lib/features/outline/index.js +6 -0
  71. package/lib/features/palette/PaletteProvider.js +171 -0
  72. package/lib/features/palette/index.js +12 -0
  73. package/lib/features/popup-menu/ReplaceMenuProvider.js +448 -0
  74. package/lib/features/popup-menu/index.js +4 -0
  75. package/lib/features/replace/CmmnReplace.js +355 -0
  76. package/lib/features/replace/ReplaceOptions.js +241 -0
  77. package/lib/features/replace/index.js +8 -0
  78. package/lib/features/replace-preview/CmmnReplacePreview.js +247 -0
  79. package/lib/features/replace-preview/index.js +7 -0
  80. package/lib/features/rules/CmmnRules.js +1040 -0
  81. package/lib/features/rules/index.js +7 -0
  82. package/lib/features/search/CmmnSearchProvider.js +129 -0
  83. package/lib/features/search/index.js +7 -0
  84. package/lib/features/snapping/CmmnConnectSnapping.js +110 -0
  85. package/lib/features/snapping/CmmnCreateMoveSnapping.js +148 -0
  86. package/lib/features/snapping/CmmnResizeSnapping.js +42 -0
  87. package/lib/features/snapping/CmmnSnappingUtil.js +76 -0
  88. package/lib/features/snapping/index.js +17 -0
  89. package/lib/import/CmmnImporter.js +251 -0
  90. package/lib/import/CmmnTreeWalker.js +410 -0
  91. package/lib/import/Importer.js +73 -0
  92. package/lib/import/Util.js +9 -0
  93. package/lib/import/index.js +3 -0
  94. package/lib/util/DiUtil.js +39 -0
  95. package/lib/util/LabelUtil.js +124 -0
  96. package/lib/util/ModelUtil.js +257 -0
  97. package/lib/util/PoweredByUtil.js +91 -0
  98. package/package.json +88 -4
  99. package/test/helper/index.js +231 -0
  100. package/test/util/KeyEvents.js +23 -0
  101. package/test/util/MockEvents.js +55 -0
  102. package/test/util/custom-rules/CustomRules.js +19 -0
  103. package/test/util/custom-rules/index.js +4 -0
@@ -0,0 +1,24 @@
1
+ module.exports = {
2
+ __init__: [
3
+ 'attachCriterionBehavior',
4
+ 'caseFileItemUpdater',
5
+ 'labelBehavior',
6
+ 'planItemDefinitionUpdater',
7
+ 'planningTableUpdater',
8
+ 'replaceConnectionBehavior',
9
+ 'replaceElementBehavior',
10
+ 'resizeCasePlanModelBehavior',
11
+ 'sentryUpdater',
12
+ 'unclaimIdBehavior'
13
+ ],
14
+ attachCriterionBehavior: [ 'type', require('./AttachCriterionBehavior') ],
15
+ caseFileItemUpdater: [ 'type', require('./CaseFileItemUpdater') ],
16
+ labelBehavior: [ 'type', require('./LabelBehavior') ],
17
+ planItemDefinitionUpdater: [ 'type', require('./PlanItemDefinitionUpdater') ],
18
+ planningTableUpdater: [ 'type', require('./PlanningTableUpdater') ],
19
+ replaceConnectionBehavior: [ 'type', require('./ReplaceConnectionBehavior') ],
20
+ replaceElementBehavior: [ 'type', require('./ReplaceElementBehavior') ],
21
+ resizeCasePlanModelBehavior: [ 'type', require('./ResizeCasePlanModelBehavior') ],
22
+ sentryUpdater: [ 'type', require('./SentryUpdater') ],
23
+ unclaimIdBehavior: [ 'type', require('./UnclaimIdBehavior') ]
24
+ };
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ var inherits = require('inherits');
4
+
5
+ var is = require('../../../util/ModelUtil').is;
6
+
7
+ var BaseHandler = require('diagram-js/lib/features/modeling/cmd/AppendShapeHandler').default;
8
+
9
+
10
+ function AppendShapeHandler(modeling, cmmnRules) {
11
+ this._modeling = modeling;
12
+ this._cmmnRules = cmmnRules;
13
+ }
14
+
15
+ inherits(AppendShapeHandler, BaseHandler);
16
+
17
+
18
+ AppendShapeHandler.$inject = [ 'modeling', 'cmmnRules' ];
19
+
20
+ module.exports = AppendShapeHandler;
21
+
22
+
23
+ // api /////////////////
24
+
25
+ AppendShapeHandler.prototype.preExecute = function(context) {
26
+
27
+ if (!context.source) {
28
+ throw new Error('source required');
29
+ }
30
+
31
+ var cmmnRules = this._cmmnRules;
32
+
33
+ var shape = context.shape,
34
+ source = context.source,
35
+ parent = context.target || context.source.parent,
36
+ position = context.position,
37
+ isAttach = context.attach;
38
+
39
+ if (isCriterion(shape)) {
40
+ isAttach = cmmnRules.canAttach(shape, parent, source, position) === 'attach';
41
+ }
42
+
43
+ context.shape = this._modeling.createShape(shape, position, parent, {
44
+ attach: isAttach,
45
+ nested: true
46
+ });
47
+
48
+ };
49
+
50
+ function isCriterion(element) {
51
+ return is(element, 'cmmn:Criterion');
52
+ }
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+
4
+ function IdClaimHandler(moddle) {
5
+ this._moddle = moddle;
6
+ }
7
+
8
+ IdClaimHandler.$inject = [ 'moddle' ];
9
+
10
+ module.exports = IdClaimHandler;
11
+
12
+
13
+ IdClaimHandler.prototype.execute = function(context) {
14
+ var ids = this._moddle.ids,
15
+ id = context.id,
16
+ element = context.element,
17
+ claiming = context.claiming;
18
+
19
+ if (claiming) {
20
+ ids.claim(id, element);
21
+ } else {
22
+ ids.unclaim(id);
23
+ }
24
+ };
25
+
26
+
27
+ IdClaimHandler.prototype.revert = function(context) {
28
+ var ids = this._moddle.ids,
29
+ id = context.id,
30
+ element = context.element,
31
+ claiming = context.claiming;
32
+
33
+ if (claiming) {
34
+ ids.unclaim(id);
35
+ } else {
36
+ ids.claim(id, element);
37
+ }
38
+ };
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ var inherits = require('inherits');
4
+
5
+ var isArray = require('min-dash').isArray;
6
+
7
+ var BaseHandler = require('diagram-js/lib/features/modeling/cmd/ReconnectConnectionHandler').default;
8
+
9
+ /**
10
+ * Overwrites the behavior of diagram-js/ReconnectConnectionHandler to enable
11
+ * a switch between source and target of a connection on reconnect.
12
+ */
13
+ function ReconnectConnectionHandler(injector) {
14
+ injector.invoke(BaseHandler, this);
15
+ }
16
+
17
+ inherits(ReconnectConnectionHandler, BaseHandler);
18
+
19
+ ReconnectConnectionHandler.$inject = [ 'injector' ];
20
+
21
+ module.exports = ReconnectConnectionHandler;
22
+
23
+
24
+ ReconnectConnectionHandler.prototype.execute = function(context) {
25
+
26
+ var newSource = context.newSource,
27
+ newTarget = context.newTarget,
28
+ connection = context.connection,
29
+ dockingOrPoints = context.dockingOrPoints;
30
+
31
+ if (!newSource && !newTarget) {
32
+ throw new Error('newSource or newTarget are required');
33
+ }
34
+
35
+ // removed from corresponding method in diagram-js@3.3.0
36
+
37
+ // if (newSource && newTarget) {
38
+ // throw new Error('must specify either newSource or newTarget');
39
+ // }
40
+
41
+ if (isArray(dockingOrPoints)) {
42
+ context.oldWaypoints = connection.waypoints;
43
+ connection.waypoints = dockingOrPoints;
44
+ }
45
+
46
+ if (newSource) {
47
+ context.oldSource = connection.source;
48
+ connection.source = newSource;
49
+ }
50
+
51
+ if (newTarget) {
52
+ context.oldTarget = connection.target;
53
+ connection.target = newTarget;
54
+ }
55
+
56
+ return connection;
57
+ };
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ var inherits = require('inherits');
4
+
5
+ var BaseHandler = require('diagram-js/lib/features/modeling/cmd/ReplaceShapeHandler').default;
6
+
7
+
8
+ function ReplaceShapeHandler(modeling, rules) {
9
+ this._modeling = modeling;
10
+ this._rules = rules;
11
+ }
12
+
13
+ inherits(ReplaceShapeHandler, BaseHandler);
14
+
15
+ ReplaceShapeHandler.$inject = [ 'modeling', 'rules' ];
16
+
17
+ module.exports = ReplaceShapeHandler;
18
+
19
+
20
+ // api /////////////////
21
+
22
+
23
+ ReplaceShapeHandler.prototype.createShape = function(shape, position, target) {
24
+ var modeling = this._modeling;
25
+ return modeling.createShape(shape, position, target, {
26
+ nested: true
27
+ });
28
+ };
29
+
30
+
31
+ ReplaceShapeHandler.prototype.reconnectStart = function(connection, newSource, dockingPoint) {
32
+ var modeling = this._modeling;
33
+ modeling.reconnectStart(connection, newSource, dockingPoint, {
34
+ nested: true,
35
+ startChanged: true
36
+ });
37
+ };
38
+
39
+
40
+ ReplaceShapeHandler.prototype.reconnectEnd = function(connection, newTarget, dockingPoint) {
41
+ var modeling = this._modeling;
42
+ modeling.reconnectEnd(connection, newTarget, dockingPoint, {
43
+ nested: true,
44
+ endChanged: true
45
+ });
46
+ };
@@ -0,0 +1,221 @@
1
+ 'use strict';
2
+
3
+ var filter = require('min-dash').filter,
4
+ forEach = require('min-dash').forEach;
5
+
6
+ var getBusinessObject = require('../../../util/ModelUtil').getBusinessObject,
7
+ getItemControl = require('../../../util/ModelUtil').getItemControl,
8
+ getDefaultControl = require('../../../util/ModelUtil').getDefaultControl,
9
+ getDefinition = require('../../../util/ModelUtil').getDefinition,
10
+ hasPlanningTable = require('../../../util/ModelUtil').hasPlanningTable;
11
+
12
+ var isPlanningTableCapable = require('../util/PlanItemDefinitionUtil').isPlanningTableCapable;
13
+
14
+
15
+ function UpdateControlsHandler(itemRegistry, modeling, cmmnReplace, cmmnFactory) {
16
+ this._itemRegistry = itemRegistry;
17
+ this._modeling = modeling;
18
+ this._cmmnReplace = cmmnReplace;
19
+ this._cmmnFactory = cmmnFactory;
20
+ }
21
+
22
+ UpdateControlsHandler.$inject = [ 'itemRegistry', 'modeling', 'cmmnReplace', 'cmmnFactory' ];
23
+
24
+ module.exports = UpdateControlsHandler;
25
+
26
+
27
+ var PLAN_ITEM_CONTROL_PROPS = [
28
+ 'requiredRule',
29
+ 'repetitionRule',
30
+ 'manualActivationRule'
31
+ ];
32
+
33
+ function getUpdate(key, value) {
34
+ var update = {};
35
+ update[key] = value;
36
+ return update;
37
+ }
38
+
39
+
40
+ UpdateControlsHandler.prototype.preExecute = function(context) {
41
+
42
+ var self = this;
43
+
44
+ var element = context.element,
45
+ values = context.values;
46
+
47
+ if (!element) {
48
+ throw new Error('element required');
49
+ }
50
+
51
+ forEach(values, function(value, key) {
52
+
53
+ if (PLAN_ITEM_CONTROL_PROPS.indexOf(key) !== -1) {
54
+ self._updateRule(element, key, value);
55
+ }
56
+ else {
57
+ self._updateDecorator(element, key, value);
58
+ }
59
+
60
+ });
61
+
62
+ };
63
+
64
+
65
+ UpdateControlsHandler.prototype.execute = function() {};
66
+
67
+ UpdateControlsHandler.prototype.revert = function() {};
68
+
69
+
70
+ // API ////////////////////////////////////////////////
71
+
72
+
73
+ UpdateControlsHandler.prototype._updateDecorator = function(element, key, value) {
74
+
75
+ var self = this,
76
+ modeling = self._modeling;
77
+
78
+ var definition = getDefinition(element),
79
+ update = getUpdate(key, value),
80
+ changed = [];
81
+
82
+ if (definition[key] !== value) {
83
+
84
+ changed = self._getReferencingShapes(definition);
85
+
86
+ if (changed.length > 1 && canReplaceDefinition(definition)) {
87
+ definition = self._replaceDefinition(element);
88
+ changed = element;
89
+ }
90
+
91
+ modeling.updateProperties(definition, update, changed);
92
+
93
+ }
94
+
95
+ };
96
+
97
+
98
+ UpdateControlsHandler.prototype._updateRule = function(element, rule, value) {
99
+
100
+ var self = this,
101
+ modeling = self._modeling,
102
+ cmmnFactory = self._cmmnFactory;
103
+
104
+ var itemControl = getItemControl(element),
105
+ defaultControl = getDefaultControl(element),
106
+ definition = getDefinition(element),
107
+ update = getUpdate(rule, value);
108
+
109
+
110
+ !value ? deleteRule() : setRule();
111
+
112
+
113
+ function deleteRule() {
114
+
115
+ var oldValue;
116
+
117
+ if (isRulePresent(itemControl, rule)) {
118
+ oldValue = itemControl[rule];
119
+ modeling.updateProperties(itemControl, update, element);
120
+ modeling.updateSemanticParent(oldValue);
121
+
122
+ if (canDeletePlanItemControl(itemControl)) {
123
+ modeling.updateProperties(element, { itemControl: undefined });
124
+ modeling.updateSemanticParent(itemControl);
125
+ }
126
+
127
+ }
128
+
129
+ if (isRulePresent(defaultControl, rule)) {
130
+ oldValue = defaultControl[rule];
131
+
132
+ var changed = self._getReferencingShapes(definition);
133
+
134
+ if (changed.length > 1 && canReplaceDefinition(definition)) {
135
+
136
+ changed = filter(changed, function(elem) {
137
+ var localItemControl = getItemControl(elem),
138
+ localDefaultControl = getDefaultControl(elem);
139
+
140
+ return !isRulePresent(localItemControl, rule) &&
141
+ isRulePresent(localDefaultControl, rule);
142
+ });
143
+
144
+ if (changed.length > 1) {
145
+ self._replaceDefinition(element);
146
+ defaultControl = getDefaultControl(element);
147
+ changed = element;
148
+ }
149
+
150
+ }
151
+
152
+ modeling.updateProperties(defaultControl, update, changed);
153
+ modeling.updateSemanticParent(oldValue);
154
+
155
+ if (canDeletePlanItemControl(defaultControl)) {
156
+ modeling.updateProperties(definition, { defaultControl: undefined }, changed);
157
+ modeling.updateSemanticParent(defaultControl);
158
+ }
159
+
160
+ }
161
+
162
+ }
163
+
164
+ function setRule() {
165
+
166
+ if (!itemControl) {
167
+ itemControl = createPlanItemControl();
168
+ modeling.updateProperties(element, { itemControl: itemControl });
169
+ modeling.updateSemanticParent(itemControl, getBusinessObject(element));
170
+ }
171
+
172
+ modeling.updateProperties(itemControl, update, element);
173
+ modeling.updateSemanticParent(value, itemControl);
174
+ }
175
+
176
+ function isRulePresent(control, rule) {
177
+ return control && control[rule];
178
+ }
179
+
180
+ function createPlanItemControl() {
181
+ return cmmnFactory.create('cmmn:PlanItemControl');
182
+ }
183
+
184
+ function canDeletePlanItemControl(control) {
185
+ return !!(control && !control.repetitionRule && !control.requiredRule && !control.manualActivationRule);
186
+ }
187
+
188
+ };
189
+
190
+
191
+ UpdateControlsHandler.prototype._replaceDefinition = function(element) {
192
+
193
+ var self = this,
194
+ modeling = self._modeling,
195
+ cmmnReplace = self._cmmnReplace;
196
+
197
+ var definition = getDefinition(element);
198
+
199
+ var newDefinition = cmmnReplace.replacePlanItemDefinition(definition);
200
+ modeling.updateProperties(element, { definitionRef: newDefinition });
201
+
202
+ modeling.updateSemanticParent(newDefinition, definition.$parent, 'planItemDefinitions');
203
+
204
+ return newDefinition;
205
+
206
+ };
207
+
208
+
209
+ UpdateControlsHandler.prototype._getReferencingShapes = function(definition) {
210
+
211
+ var self = this,
212
+ itemRegistry = self._itemRegistry;
213
+
214
+ return itemRegistry.getShapes(definition);
215
+
216
+ };
217
+
218
+
219
+ function canReplaceDefinition(definition) {
220
+ return !(isPlanningTableCapable(definition) && hasPlanningTable(definition));
221
+ }
@@ -0,0 +1,240 @@
1
+ 'use strict';
2
+
3
+ var reduce = require('min-dash').reduce,
4
+ keys = require('min-dash').keys,
5
+ forEach = require('min-dash').forEach,
6
+ assign = require('min-dash').assign;
7
+
8
+ var getBusinessObject = require('../../../util/ModelUtil').getBusinessObject;
9
+
10
+ var NAME = 'name',
11
+ STANDARD_EVENT = 'standardEvent',
12
+ ID = 'id',
13
+ DEFINITION_REF = 'definitionRef',
14
+ SENTRY_REF = 'sentryRef',
15
+ IS_STANDARD_EVENT_VISIBLE = 'isStandardEventVisible';
16
+
17
+ var flatten = require('min-dash').flatten;
18
+
19
+ /**
20
+ * A handler that implements a CMMN 1.1 property update.
21
+ *
22
+ * This should be used to set simple properties on elements with
23
+ * an underlying CMMN business object.
24
+ *
25
+ * Use respective diagram-js provided handlers if you would
26
+ * like to perform automated modeling.
27
+ */
28
+ function UpdatePropertiesHandler(elementRegistry, itemRegistry, moddle) {
29
+ this._elementRegistry = elementRegistry;
30
+ this._itemRegistry = itemRegistry;
31
+ this._moddle = moddle;
32
+ }
33
+
34
+ UpdatePropertiesHandler.$inject = [ 'elementRegistry', 'itemRegistry', 'moddle' ];
35
+
36
+ module.exports = UpdatePropertiesHandler;
37
+
38
+
39
+ // api /////////////////
40
+
41
+ UpdatePropertiesHandler.prototype.preExecute = function(context) {
42
+
43
+ var element = context.element,
44
+ shape = context.shape;
45
+
46
+ if (!element) {
47
+ throw new Error('element required');
48
+ }
49
+
50
+ var bo = element.businessObject || element;
51
+
52
+ context.businessObject = bo;
53
+
54
+ var changed = [];
55
+
56
+ if (element.businessObject) {
57
+ changed.push(element);
58
+ }
59
+
60
+ if (shape) {
61
+ changed.push(shape);
62
+ }
63
+
64
+ context.changed = flatten(changed);
65
+ };
66
+
67
+
68
+ /**
69
+ * Updates a CMMN element with a list of new properties
70
+ *
71
+ * @param {Object} context
72
+ * @param {djs.model.Base} context.element the element to update
73
+ * @param {Object} context.properties a list of properties to set on the element's
74
+ * businessObject (the CMMN model element)
75
+ *
76
+ * @return {Array<djs.mode.Base>} the updated element
77
+ */
78
+ UpdatePropertiesHandler.prototype.execute = function(context) {
79
+
80
+ var elementRegistry = this._elementRegistry,
81
+ itemRegistry = this._itemRegistry,
82
+ ids = this._moddle.ids;
83
+
84
+ var changed = context.changed;
85
+
86
+ var element = context.element,
87
+ businessObject = context.businessObject,
88
+ properties = unwrapBusinessObjects(context.properties),
89
+ oldProperties = context.oldProperties || getProperties(businessObject, keys(properties));
90
+
91
+ if (isIdChange(properties, businessObject)) {
92
+ ids.unclaim(businessObject[ID]);
93
+
94
+ itemRegistry.updateId(businessObject, properties[ID]);
95
+
96
+ var shape = elementRegistry.get(element.id);
97
+
98
+ if (shape) {
99
+ elementRegistry.updateId(shape, properties[ID]);
100
+ }
101
+
102
+ ids.claim(properties[ID], businessObject);
103
+ }
104
+
105
+ if (isDefinitionRefChange(properties, businessObject)) {
106
+ itemRegistry.updateReference(businessObject, properties[DEFINITION_REF]);
107
+ }
108
+
109
+ if (isSentryRefChange(properties, businessObject)) {
110
+ itemRegistry.updateReference(businessObject, properties[SENTRY_REF]);
111
+ }
112
+
113
+ if (NAME in properties) {
114
+
115
+ forEach(changed, function(changedShape) {
116
+ if (changedShape.label) {
117
+ changed.push(changedShape.label);
118
+ }
119
+ });
120
+
121
+ }
122
+
123
+ if (STANDARD_EVENT in properties || IS_STANDARD_EVENT_VISIBLE in properties) {
124
+
125
+ forEach(changed, function(changedShape) {
126
+ if (changedShape.label) {
127
+ changed.push(changedShape.label);
128
+ }
129
+ });
130
+
131
+ }
132
+
133
+ // update properties
134
+ setProperties(businessObject, properties);
135
+
136
+ // store old values
137
+ context.oldProperties = oldProperties;
138
+
139
+ // indicate changed on objects affected by the update
140
+ return changed;
141
+ };
142
+
143
+ /**
144
+ * Reverts the update on a CMMN elements properties.
145
+ *
146
+ * @param {Object} context
147
+ *
148
+ * @return {djs.mode.Base} the updated element
149
+ */
150
+ UpdatePropertiesHandler.prototype.revert = function(context) {
151
+
152
+ var properties = context.properties,
153
+ oldProperties = context.oldProperties,
154
+ businessObject = context.businessObject,
155
+ elementRegistry = this._elementRegistry,
156
+ itemRegistry = this._itemRegistry,
157
+ ids = this._moddle.ids;
158
+
159
+ if (isIdChange(oldProperties, businessObject)) {
160
+ itemRegistry.updateId(businessObject, oldProperties[ID]);
161
+ }
162
+
163
+ if (isDefinitionRefChange(oldProperties, businessObject)) {
164
+ itemRegistry.updateReference(businessObject, oldProperties[DEFINITION_REF]);
165
+ }
166
+
167
+ if (isSentryRefChange(oldProperties, businessObject)) {
168
+ itemRegistry.updateReference(businessObject, oldProperties[SENTRY_REF]);
169
+ }
170
+
171
+ // update properties
172
+ setProperties(businessObject, oldProperties);
173
+
174
+ if (isIdChange(properties, businessObject)) {
175
+ ids.unclaim(properties[ID]);
176
+
177
+ var shape = elementRegistry.get(properties[ID]);
178
+
179
+ if (shape) {
180
+ elementRegistry.updateId(shape, oldProperties[ID]);
181
+ }
182
+
183
+ ids.claim(oldProperties[ID], businessObject);
184
+ }
185
+
186
+ return context.changed;
187
+ };
188
+
189
+
190
+ function isIdChange(properties, businessObject) {
191
+ return ID in properties && properties[ID] !== businessObject[ID];
192
+ }
193
+
194
+ function isDefinitionRefChange(properties, businessObject) {
195
+ return DEFINITION_REF in properties && properties[DEFINITION_REF] !== businessObject[DEFINITION_REF];
196
+ }
197
+
198
+ function isSentryRefChange(properties, businessObject) {
199
+ return SENTRY_REF in properties && properties[SENTRY_REF] !== businessObject[SENTRY_REF];
200
+ }
201
+
202
+
203
+ function getProperties(businessObject, propertyNames) {
204
+ return reduce(propertyNames, function(result, key) {
205
+ result[key] = businessObject.get(key);
206
+ return result;
207
+ }, {});
208
+ }
209
+
210
+
211
+ function setProperties(businessObject, properties) {
212
+ forEach(properties, function(value, key) {
213
+ businessObject.set(key, value);
214
+ });
215
+ }
216
+
217
+
218
+ var referencePropertyNames = [ 'default' ];
219
+
220
+ /**
221
+ * Make sure we unwrap the actual business object
222
+ * behind diagram element that may have been
223
+ * passed as arguments.
224
+ *
225
+ * @param {Object} properties
226
+ *
227
+ * @return {Object} unwrappedProps
228
+ */
229
+ function unwrapBusinessObjects(properties) {
230
+
231
+ var unwrappedProps = assign({}, properties);
232
+
233
+ referencePropertyNames.forEach(function(name) {
234
+ if (name in properties) {
235
+ unwrappedProps[name] = getBusinessObject(unwrappedProps[name]);
236
+ }
237
+ });
238
+
239
+ return unwrappedProps;
240
+ }