camunda-bpmn-js 0.23.0 → 0.24.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.
@@ -12,6 +12,7 @@ import {
12
12
  ZeebeDescriptionProvider
13
13
  } from 'bpmn-js-properties-panel';
14
14
 
15
+ import replaceModule from './features/replace';
15
16
 
16
17
  import { commonModdleExtensions, commonModules } from './util/commonModules';
17
18
 
@@ -44,7 +45,8 @@ Modeler.prototype._camundaCloudModules = [
44
45
  behaviorsModule,
45
46
  rulesModule,
46
47
  zeebePropertiesProviderModule,
47
- cloudElementTemplatesPropertiesProvider
48
+ cloudElementTemplatesPropertiesProvider,
49
+ replaceModule
48
50
  ];
49
51
 
50
52
  Modeler.prototype._modules = [].concat(
@@ -0,0 +1,249 @@
1
+ import {
2
+ isDifferentType
3
+ } from 'bpmn-js/lib/features/popup-menu/util/TypeUtil';
4
+
5
+ import {
6
+ getBusinessObject,
7
+ isAny
8
+ } from 'bpmn-js/lib/util/ModelUtil';
9
+
10
+ import {
11
+ getReplaceOptionGroups
12
+ } from './ReplaceOptionsUtil';
13
+
14
+ /**
15
+ * A replace menu provider that allows to replace elements with
16
+ * element templates.
17
+ */
18
+ export default function ElementTemplatesReplaceProvider(config, popupMenu, translate, elementTemplates) {
19
+
20
+ this._popupMenu = popupMenu;
21
+ this._translate = translate;
22
+ this._elementTemplates = elementTemplates;
23
+
24
+ const enabled = config && config.enabled;
25
+
26
+ if (enabled) {
27
+ this.register();
28
+ }
29
+ }
30
+
31
+ ElementTemplatesReplaceProvider.$inject = [
32
+ 'config.elementTemplatesReplaceProvider',
33
+ 'popupMenu',
34
+ 'translate',
35
+ 'elementTemplates'
36
+ ];
37
+
38
+ /**
39
+ * Register replace menu provider in the popup menu
40
+ */
41
+ ElementTemplatesReplaceProvider.prototype.register = function() {
42
+ this._popupMenu.registerProvider('bpmn-replace', this);
43
+ };
44
+
45
+ /**
46
+ * Adds the element templates to the replace menu.
47
+ * @param {djs.model.Base} element
48
+ *
49
+ * @returns {Object}
50
+ */
51
+ ElementTemplatesReplaceProvider.prototype.getPopupMenuEntries = function(element) {
52
+
53
+ return (entries) => {
54
+
55
+ // convert our entries into something sortable
56
+ let entrySet = Object.entries(entries);
57
+
58
+ // add unlink template option
59
+ this._addPlainElementEntry(element, entrySet);
60
+
61
+ // add template entries
62
+ entrySet = [ ...entrySet, ...this.getTemplateEntries(element) ];
63
+
64
+ // convert back to object
65
+ return entrySet.reduce((entries, [ key, value ]) => {
66
+ entries[key] = value;
67
+
68
+ return entries;
69
+ }, {});
70
+ };
71
+ };
72
+
73
+ /**
74
+ * Adds the option to replace with plain element (unlink template).
75
+ *
76
+ * @param {djs.model.Base} element
77
+ * @param {Array<Object>} entries
78
+ */
79
+ ElementTemplatesReplaceProvider.prototype._addPlainElementEntry = function(element, entries) {
80
+
81
+ const replaceOption = this._getPlainEntry(element, entries);
82
+
83
+ const [
84
+ insertIndex,
85
+ entry
86
+ ] = replaceOption;
87
+
88
+ // insert unlink entry
89
+ entries.splice(insertIndex, 0, [ entry.id, entry ]);
90
+ };
91
+
92
+ /**
93
+ * Returns the option to replace with plain element and the index where it should be inserted.
94
+ *
95
+ * @param {djs.model.Base} element
96
+ * @param {Array<Object>} entries
97
+ *
98
+ * @returns {Array<Object, number>}
99
+ */
100
+ ElementTemplatesReplaceProvider.prototype._getPlainEntry = function(element, entries) {
101
+
102
+ const {
103
+ options,
104
+ option,
105
+ optionIndex
106
+ } = findReplaceOptions(element) || { };
107
+
108
+ if (!options) {
109
+ return;
110
+ }
111
+
112
+ const entry = {
113
+ id: option.actionName,
114
+ action: () => {
115
+ this._elementTemplates.applyTemplate(element, null);
116
+ },
117
+ label: this._translate(option.label),
118
+ className: option.className
119
+ };
120
+
121
+ // insert after previous option, if it exists
122
+ const previousIndex = getOptionIndex(options, optionIndex - 1, entries);
123
+
124
+ if (previousIndex) {
125
+ return [
126
+ previousIndex + 1,
127
+ entry
128
+ ];
129
+ }
130
+
131
+ // insert before next option, if it exists
132
+ const nextIndex = getOptionIndex(options, optionIndex + 1, entries);
133
+
134
+ if (nextIndex) {
135
+ return [
136
+ nextIndex,
137
+ entry
138
+ ];
139
+ }
140
+
141
+ // fallback to insert at start
142
+ return [
143
+ 0,
144
+ entry
145
+ ];
146
+ };
147
+
148
+ /**
149
+ * Get all element templates that can be used to replace the given element.
150
+ *
151
+ * @param {djs.model.Base} element
152
+ *
153
+ * @return {Array<Object>} a list of element templates as menu entries
154
+ */
155
+ ElementTemplatesReplaceProvider.prototype.getTemplateEntries = function(element) {
156
+
157
+ const templates = this._getMatchingTemplates(element);
158
+ return templates.map(template => {
159
+
160
+ const {
161
+ icon = {},
162
+ category,
163
+ } = template;
164
+
165
+ const entryId = `replace-with-template-${template.id}`;
166
+
167
+ const defaultGroup = {
168
+ id: 'templates',
169
+ name: this._translate('Templates')
170
+ };
171
+
172
+ return [ entryId, {
173
+ name: template.name,
174
+ description: template.description,
175
+ documentationRef: template.documentationRef,
176
+ imageUrl: icon.contents,
177
+ group: category || defaultGroup,
178
+ action: () => {
179
+ this._elementTemplates.applyTemplate(element, template);
180
+ }
181
+ } ];
182
+ });
183
+ };
184
+
185
+ /**
186
+ * Returns the templates that can the element can be replaced with.
187
+ *
188
+ * @param {djs.model.Base} element
189
+ *
190
+ * @return {Array<ElementTemplate>}
191
+ */
192
+ ElementTemplatesReplaceProvider.prototype._getMatchingTemplates = function(element) {
193
+ return this._elementTemplates.getLatest().filter(template => {
194
+ return isAny(element, template.appliesTo) && !isTemplateApplied(element, template);
195
+ });
196
+ };
197
+
198
+
199
+ // helpers ////////////
200
+ export function isTemplateApplied(element, template) {
201
+ const businessObject = getBusinessObject(element);
202
+
203
+ if (businessObject) {
204
+ return businessObject.get('zeebe:modelerTemplate') === template.id;
205
+ }
206
+
207
+ return false;
208
+ }
209
+
210
+ function getOptionIndex(options, index, entries) {
211
+ const option = options[index];
212
+
213
+ if (!option) {
214
+ return false;
215
+ }
216
+
217
+ return entries.findIndex(
218
+ ([ key ]) => key === option.actionName
219
+ );
220
+ }
221
+
222
+ /**
223
+ * @param {ModdleElement} element
224
+ *
225
+ * @return { { options: Array<any>, option: any, optionIndex: number } | null }
226
+ */
227
+ function findReplaceOptions(element) {
228
+
229
+ const isSameType = (element, option) => option.target && !isDifferentType(element)(option);
230
+
231
+ return getReplaceOptionGroups().reduce((result, options) => {
232
+
233
+ if (result) {
234
+ return result;
235
+ }
236
+
237
+ const optionIndex = options.findIndex(option => isSameType(element, option));
238
+
239
+ if (optionIndex === -1) {
240
+ return;
241
+ }
242
+
243
+ return {
244
+ options,
245
+ option: options[optionIndex],
246
+ optionIndex
247
+ };
248
+ }, null);
249
+ }
@@ -0,0 +1,7 @@
1
+ import * as replaceOptions from 'bpmn-js/lib/features/replace/ReplaceOptions';
2
+
3
+ const ALL_OPTIONS = Object.values(replaceOptions);
4
+
5
+ export function getReplaceOptionGroups() {
6
+ return ALL_OPTIONS;
7
+ }
@@ -0,0 +1,6 @@
1
+ import ElementTemplatesReplaceProvider from './ElementTemplatesReplaceProvider';
2
+
3
+ export default {
4
+ __init__: [ 'elementTemplatesProvider' ],
5
+ elementTemplatesProvider: [ 'type', ElementTemplatesReplaceProvider ]
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camunda-bpmn-js",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "Embeddable Camunda modeling distributions based on bpmn-js",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -47,33 +47,36 @@
47
47
  "dependencies": {
48
48
  "@bpmn-io/align-to-origin": "^0.7.0",
49
49
  "@bpmn-io/element-templates-icons-renderer": "^0.3.0",
50
- "bpmn-js": "^10.2.0",
50
+ "bpmn-js": "^11.0.1",
51
51
  "bpmn-js-executable-fix": "^0.2.0",
52
52
  "camunda-bpmn-js-behaviors": "^0.4.0",
53
53
  "camunda-bpmn-moddle": "^7.0.1",
54
- "diagram-js": "^10.0.0",
54
+ "diagram-js": "^11.1.1",
55
55
  "diagram-js-minimap": "^3.0.0",
56
- "diagram-js-origin": "^1.3.4",
56
+ "diagram-js-origin": "^1.4.0",
57
57
  "inherits": "^2.0.4",
58
58
  "min-dash": "^4.0.0",
59
- "zeebe-bpmn-moddle": "^0.16.0"
59
+ "zeebe-bpmn-moddle": "^0.17.0"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@babel/core": "^7.18.13",
63
63
  "@bpmn-io/element-template-chooser": "^0.1.0",
64
- "@bpmn-io/properties-panel": "^0.24.0",
64
+ "@bpmn-io/properties-panel": "^1.0.1",
65
65
  "@rollup/plugin-commonjs": "^23.0.0",
66
66
  "@rollup/plugin-json": "^4.1.0",
67
67
  "@rollup/plugin-node-resolve": "^14.0.0",
68
68
  "babel-loader": "^9.0.0",
69
69
  "babel-plugin-istanbul": "^6.1.1",
70
- "bpmn-js-properties-panel": "^1.11.1",
71
- "chai": "^4.3.6",
70
+ "bpmn-js-connectors-extension": "^0.4.4",
71
+ "bpmn-js-properties-panel": "^1.12.0",
72
+ "chai": "^4.3.7",
72
73
  "cross-env": "^7.0.3",
73
74
  "del-cli": "^5.0.0",
75
+ "downloadjs": "^1.4.7",
74
76
  "eslint": "^8.24.0",
75
77
  "eslint-plugin-bpmn-io": "^0.16.0",
76
78
  "execa": "^5.0.0",
79
+ "file-drops": "^0.5.0",
77
80
  "karma": "^6.4.1",
78
81
  "karma-chai": "^0.1.0",
79
82
  "karma-chrome-launcher": "^3.1.1",
@@ -86,20 +89,20 @@
86
89
  "karma-sinon-chai": "^2.0.2",
87
90
  "karma-webpack": "^5.0.0",
88
91
  "min-dom": "^4.0.3",
89
- "mocha": "^10.0.0",
92
+ "mocha": "^10.1.0",
90
93
  "mocha-test-container-support": "^0.2.0",
91
94
  "npm-run-all": "^4.1.5",
92
- "puppeteer": "^19.0.0",
95
+ "puppeteer": "^19.3.0",
93
96
  "raw-loader": "^4.0.2",
94
97
  "rollup": "^2.38.4",
95
98
  "rollup-plugin-copy": "^3.3.0",
96
99
  "rollup-plugin-terser": "^7.0.2",
97
- "sinon": "^14.0.0",
100
+ "sinon": "^15.0.0",
98
101
  "sinon-chai": "^3.7.0",
99
102
  "webpack": "^5.74.0"
100
103
  },
101
104
  "peerDependencies": {
102
- "bpmn-js-properties-panel": ">= 1.11.1"
105
+ "bpmn-js-properties-panel": ">= 1.11.3"
103
106
  },
104
107
  "files": [
105
108
  "dist",