camunda-bpmn-js 4.3.1 → 4.3.3

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.
@@ -107323,6 +107323,7 @@
107323
107323
  function FeelEditor({
107324
107324
  extensions: editorExtensions = [],
107325
107325
  container,
107326
+ contentAttributes = {},
107326
107327
  tooltipContainer,
107327
107328
  onChange = () => {},
107328
107329
  onKeyDown = () => {},
@@ -107374,6 +107375,7 @@
107374
107375
  bracketMatching(),
107375
107376
  changeHandler,
107376
107377
  closeBrackets(),
107378
+ EditorView.contentAttributes.of(contentAttributes),
107377
107379
  indentOnInput(),
107378
107380
  keyHandler,
107379
107381
  keymap.of([
@@ -109864,6 +109866,7 @@
109864
109866
  };
109865
109867
  const CodeEditor = N((props, ref) => {
109866
109868
  const {
109869
+ contentAttributes,
109867
109870
  enableGutters,
109868
109871
  value,
109869
109872
  onInput,
@@ -109909,7 +109912,8 @@
109909
109912
  tooltipContainer: tooltipContainer,
109910
109913
  value: localValue,
109911
109914
  variables: variables,
109912
- extensions: [...(enableGutters ? [lineNumbers()] : []), EditorView.lineWrapping]
109915
+ extensions: [...(enableGutters ? [lineNumbers()] : []), EditorView.lineWrapping],
109916
+ contentAttributes
109913
109917
  });
109914
109918
  setEditor(editor);
109915
109919
  return () => {
@@ -110999,9 +111003,12 @@
110999
111003
  disabled: feel !== 'optional' || disabled,
111000
111004
  onClick: handleFeelToggle
111001
111005
  }), feelActive ? u(CodeEditor, {
111002
- id: prefixId$5(id),
111003
111006
  name: id,
111004
111007
  onInput: handleLocalInput,
111008
+ contentAttributes: {
111009
+ 'id': prefixId$5(id),
111010
+ 'aria-label': label
111011
+ },
111005
111012
  disabled: disabled,
111006
111013
  popupOpen: popuOpen,
111007
111014
  onFeelToggle: () => {
@@ -135250,9 +135257,9 @@
135250
135257
  target[property] = [];
135251
135258
  }
135252
135259
 
135253
- const originToAdd = source[property].filter(o => !target.origin.includes(o));
135260
+ const propertiesToAdd = source[property].filter(o => !target[property].includes(o));
135254
135261
 
135255
- target[property].push(...originToAdd);
135262
+ target[property].push(...propertiesToAdd);
135256
135263
  }
135257
135264
 
135258
135265
  function mergeEntries(target, source, visited = []) {
@@ -157448,99 +157455,102 @@
157448
157455
  return true;
157449
157456
  };
157450
157457
 
157451
- const appendIcon = `<svg width="22" height="22" viewBox="0 0 5.82 5.82" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
157452
- <path d="M1.3 3.4c.3 0 .5-.2.5-.5s-.2-.4-.5-.4c-.2 0-.4.1-.4.4 0 .3.2.5.4.5zM3 3.4c.2 0 .4-.2.4-.5s-.2-.4-.4-.4c-.3 0-.5.1-.5.4 0 .3.2.5.5.5zM4.6 3.4c.2 0 .4-.2.4-.5s-.2-.4-.4-.4c-.3 0-.5.1-.5.4 0 .3.2.5.5.5z"/>
157453
- </svg>`;
157454
- const createIcon = `<svg width="46" height="46" viewBox="-2 -2 9.82 9.82" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
157455
- <path d="M1.3 3.4c.3 0 .5-.2.5-.5s-.2-.4-.5-.4c-.2 0-.4.1-.4.4 0 .3.2.5.4.5zM3 3.4c.2 0 .4-.2.4-.5s-.2-.4-.4-.4c-.3 0-.5.1-.5.4 0 .3.2.5.5.5zM4.6 3.4c.2 0 .4-.2.4-.5s-.2-.4-.4-.4c-.3 0-.5.1-.5.4 0 .3.2.5.5.5z"/>
157458
+ const appendIcon = `<svg width="22" height="22" viewBox="0 0 5.82 5.82" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
157459
+ <path d="M1.3 3.4c.3 0 .5-.2.5-.5s-.2-.4-.5-.4c-.2 0-.4.1-.4.4 0 .3.2.5.4.5zM3 3.4c.2 0 .4-.2.4-.5s-.2-.4-.4-.4c-.3 0-.5.1-.5.4 0 .3.2.5.5.5zM4.6 3.4c.2 0 .4-.2.4-.5s-.2-.4-.4-.4c-.3 0-.5.1-.5.4 0 .3.2.5.5.5z"/>
157460
+ </svg>`;
157461
+ const createIcon = `<svg width="46" height="46" viewBox="-2 -2 9.82 9.82" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
157462
+ <path d="M1.3 3.4c.3 0 .5-.2.5-.5s-.2-.4-.5-.4c-.2 0-.4.1-.4.4 0 .3.2.5.4.5zM3 3.4c.2 0 .4-.2.4-.5s-.2-.4-.4-.4c-.3 0-.5.1-.5.4 0 .3.2.5.5.5zM4.6 3.4c.2 0 .4-.2.4-.5s-.2-.4-.4-.4c-.3 0-.5.1-.5.4 0 .3.2.5.5.5z"/>
157456
157463
  </svg>`;
157457
157464
 
157458
- /**
157459
- * A provider for append context pad button
157460
- */
157461
- function AppendContextPadProvider(contextPad, popupMenu, translate, canvas) {
157462
-
157463
- this._contextPad = contextPad;
157464
- this._popupMenu = popupMenu;
157465
- this._translate = translate;
157466
- this._canvas = canvas;
157467
-
157468
- this.register();
157469
- }
157470
-
157471
- AppendContextPadProvider.$inject = [
157472
- 'contextPad',
157473
- 'popupMenu',
157474
- 'translate',
157475
- 'canvas'
157476
- ];
157477
-
157478
- /**
157479
- * Register append button provider in the context pad
157480
- */
157481
- AppendContextPadProvider.prototype.register = function() {
157482
- this._contextPad.registerProvider(this);
157483
- };
157484
-
157485
- /**
157486
- * Gets the append context pad entry
157487
- *
157488
- * @param {djs.model.Base} element
157489
- * @returns {Object} entries
157490
- */
157491
- AppendContextPadProvider.prototype.getContextPadEntries = function(element) {
157492
- const popupMenu = this._popupMenu;
157493
- const translate = this._translate;
157494
- const getAppendMenuPosition = this._getAppendMenuPosition.bind(this);
157495
-
157496
- if (!popupMenu.isEmpty(element, 'bpmn-append')) {
157497
-
157498
- // append menu entry
157499
- return {
157500
- 'append': {
157501
- group: 'model',
157502
- html: `<div class="entry">${appendIcon}</div>`,
157503
- title: translate('Append element'),
157504
- action: {
157505
- click: function(event, element) {
157506
-
157507
- const position = assign(getAppendMenuPosition(element), {
157508
- cursor: { x: event.x, y: event.y }
157509
- });
157510
-
157511
- popupMenu.open(element, 'bpmn-append', position, {
157512
- title: translate('Append element'),
157513
- width: 300,
157514
- search: true
157515
- });
157516
- }
157517
- }
157518
- }
157519
- };
157520
- }
157521
- };
157522
-
157523
- /**
157524
- * Calculates the position for the append menu relatively to the element
157525
- *
157526
- * @param {djs.model.Base} element
157527
- * @returns {Object}
157528
- */
157529
- AppendContextPadProvider.prototype._getAppendMenuPosition = function(element) {
157530
- const contextPad = this._contextPad;
157531
-
157532
- const X_OFFSET = 5;
157533
-
157534
- const pad = contextPad.getPad(element).html;
157535
-
157536
- const padRect = pad.getBoundingClientRect();
157537
-
157538
- const pos = {
157539
- x: padRect.right + X_OFFSET,
157540
- y: padRect.top
157541
- };
157542
-
157543
- return pos;
157465
+ /**
157466
+ * A provider for append context pad button
157467
+ */
157468
+ function AppendContextPadProvider(contextPad, popupMenu, translate, canvas, rules) {
157469
+
157470
+ this._contextPad = contextPad;
157471
+ this._popupMenu = popupMenu;
157472
+ this._translate = translate;
157473
+ this._canvas = canvas;
157474
+ this._rules = rules;
157475
+
157476
+ this.register();
157477
+ }
157478
+
157479
+ AppendContextPadProvider.$inject = [
157480
+ 'contextPad',
157481
+ 'popupMenu',
157482
+ 'translate',
157483
+ 'canvas',
157484
+ 'rules'
157485
+ ];
157486
+
157487
+ /**
157488
+ * Register append button provider in the context pad
157489
+ */
157490
+ AppendContextPadProvider.prototype.register = function() {
157491
+ this._contextPad.registerProvider(this);
157492
+ };
157493
+
157494
+ /**
157495
+ * Gets the append context pad entry
157496
+ *
157497
+ * @param {djs.model.Base} element
157498
+ * @returns {Object} entries
157499
+ */
157500
+ AppendContextPadProvider.prototype.getContextPadEntries = function(element) {
157501
+ const popupMenu = this._popupMenu;
157502
+ const translate = this._translate;
157503
+ const rules = this._rules;
157504
+ const getAppendMenuPosition = this._getAppendMenuPosition.bind(this);
157505
+
157506
+ if (rules.allowed('shape.append', { element })) {
157507
+
157508
+ // append menu entry
157509
+ return {
157510
+ 'append': {
157511
+ group: 'model',
157512
+ html: `<div class="entry">${appendIcon}</div>`,
157513
+ title: translate('Append element'),
157514
+ action: {
157515
+ click: function(event, element) {
157516
+
157517
+ const position = assign(getAppendMenuPosition(element), {
157518
+ cursor: { x: event.x, y: event.y }
157519
+ });
157520
+
157521
+ popupMenu.open(element, 'bpmn-append', position, {
157522
+ title: translate('Append element'),
157523
+ width: 300,
157524
+ search: true
157525
+ });
157526
+ }
157527
+ }
157528
+ }
157529
+ };
157530
+ }
157531
+ };
157532
+
157533
+ /**
157534
+ * Calculates the position for the append menu relatively to the element
157535
+ *
157536
+ * @param {djs.model.Base} element
157537
+ * @returns {Object}
157538
+ */
157539
+ AppendContextPadProvider.prototype._getAppendMenuPosition = function(element) {
157540
+ const contextPad = this._contextPad;
157541
+
157542
+ const X_OFFSET = 5;
157543
+
157544
+ const pad = contextPad.getPad(element).html;
157545
+
157546
+ const padRect = pad.getBoundingClientRect();
157547
+
157548
+ const pos = {
157549
+ x: padRect.right + X_OFFSET,
157550
+ y: padRect.top
157551
+ };
157552
+
157553
+ return pos;
157544
157554
  };
157545
157555
 
157546
157556
  function e(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}));}
@@ -158153,87 +158163,87 @@
158153
158163
  return el.querySelector(selector);
158154
158164
  }
158155
158165
 
158156
- const LOWER_PRIORITY = 900;
158157
-
158158
- /**
158159
- * A palette provider for the create elements menu.
158160
- */
158161
- function CreatePaletteProvider(palette, translate, popupMenu, canvas, mouse) {
158162
-
158163
- this._palette = palette;
158164
- this._translate = translate;
158165
- this._popupMenu = popupMenu;
158166
- this._canvas = canvas;
158167
- this._mouse = mouse;
158168
-
158169
- this.register();
158170
- }
158171
-
158172
- CreatePaletteProvider.$inject = [
158173
- 'palette',
158174
- 'translate',
158175
- 'popupMenu',
158176
- 'canvas',
158177
- 'mouse'
158178
- ];
158179
-
158180
- /**
158181
- * Register create button provider in the palette
158182
- */
158183
- CreatePaletteProvider.prototype.register = function() {
158184
- this._palette.registerProvider(LOWER_PRIORITY, this);
158185
- };
158186
-
158187
- /**
158188
- * Gets the palette create entry
158189
- *
158190
- * @param {djs.model.Base} element
158191
- * @returns {Object}
158192
- */
158193
- CreatePaletteProvider.prototype.getPaletteEntries = function(element) {
158194
- const translate = this._translate,
158195
- popupMenu = this._popupMenu,
158196
- canvas = this._canvas,
158197
- mouse = this._mouse;
158198
-
158199
- const getPosition = (event) => {
158200
- const X_OFFSET = 35;
158201
- const Y_OFFSET = 10;
158202
-
158203
- if (event instanceof KeyboardEvent) {
158204
- event = mouse.getLastMoveEvent();
158205
- return { x: event.x, y: event.y };
158206
- }
158207
-
158208
- const target = event && event.target || query('.djs-palette [data-action="create"]');
158209
- const targetPosition = target.getBoundingClientRect();
158210
-
158211
- return target && {
158212
- x: targetPosition.left + targetPosition.width / 2 + X_OFFSET,
158213
- y: targetPosition.top + targetPosition.height / 2 + Y_OFFSET
158214
- };
158215
- };
158216
-
158217
- return {
158218
- 'create': {
158219
- group: 'create',
158220
- html: `<div class="entry"> ${createIcon}</div>`,
158221
- title: translate('Create element'),
158222
- action: {
158223
- click: function(event) {
158224
- const position = getPosition(event);
158225
-
158226
- const element = canvas.getRootElement();
158227
-
158228
- popupMenu.open(element, 'bpmn-create', position, {
158229
- title: translate('Create element'),
158230
- width: 300,
158231
- search: true
158232
- });
158233
- }
158234
- }
158235
- }
158236
- };
158166
+ const LOWER_PRIORITY = 900;
158167
+
158168
+ /**
158169
+ * A palette provider for the create elements menu.
158170
+ */
158171
+ function CreatePaletteProvider(palette, translate, popupMenu, canvas, mouse) {
158172
+
158173
+ this._palette = palette;
158174
+ this._translate = translate;
158175
+ this._popupMenu = popupMenu;
158176
+ this._canvas = canvas;
158177
+ this._mouse = mouse;
158178
+
158179
+ this.register();
158180
+ }
158181
+
158182
+ CreatePaletteProvider.$inject = [
158183
+ 'palette',
158184
+ 'translate',
158185
+ 'popupMenu',
158186
+ 'canvas',
158187
+ 'mouse'
158188
+ ];
158189
+
158190
+ /**
158191
+ * Register create button provider in the palette
158192
+ */
158193
+ CreatePaletteProvider.prototype.register = function() {
158194
+ this._palette.registerProvider(LOWER_PRIORITY, this);
158195
+ };
158196
+
158197
+ /**
158198
+ * Gets the palette create entry
158199
+ *
158200
+ * @param {djs.model.Base} element
158201
+ * @returns {Object}
158202
+ */
158203
+ CreatePaletteProvider.prototype.getPaletteEntries = function(element) {
158204
+ const translate = this._translate,
158205
+ popupMenu = this._popupMenu,
158206
+ canvas = this._canvas,
158207
+ mouse = this._mouse;
158208
+
158209
+ const getPosition = (event) => {
158210
+ const X_OFFSET = 35;
158211
+ const Y_OFFSET = 10;
158212
+
158213
+ if (event instanceof KeyboardEvent) {
158214
+ event = mouse.getLastMoveEvent();
158215
+ return { x: event.x, y: event.y };
158216
+ }
158217
+
158218
+ const target = event && event.target || query('.djs-palette [data-action="create"]');
158219
+ const targetPosition = target.getBoundingClientRect();
158220
+
158221
+ return target && {
158222
+ x: targetPosition.left + targetPosition.width / 2 + X_OFFSET,
158223
+ y: targetPosition.top + targetPosition.height / 2 + Y_OFFSET
158224
+ };
158225
+ };
158226
+
158227
+ return {
158228
+ 'create': {
158229
+ group: 'create',
158230
+ html: `<div class="entry"> ${createIcon}</div>`,
158231
+ title: translate('Create element'),
158232
+ action: {
158233
+ click: function(event) {
158234
+ const position = getPosition(event);
158235
+
158236
+ const element = canvas.getRootElement();
158237
+
158238
+ popupMenu.open(element, 'bpmn-create', position, {
158239
+ title: translate('Create element'),
158240
+ width: 300,
158241
+ search: true
158242
+ });
158243
+ }
158244
+ }
158245
+ }
158246
+ };
158237
158247
  };
158238
158248
 
158239
158249
  var CreateMenuModule = {
@@ -160079,194 +160089,194 @@
160079
160089
  return ALL_OPTIONS;
160080
160090
  }
160081
160091
 
160082
- /**
160083
- * A replace menu provider that allows to replace elements with
160084
- * templates applied with the correspondent plain element.
160085
- */
160086
- function RemoveTemplateReplaceProvider(popupMenu, translate, elementTemplates) {
160087
-
160088
- this._popupMenu = popupMenu;
160089
- this._translate = translate;
160090
- this._elementTemplates = elementTemplates;
160091
-
160092
- this.register();
160093
- }
160094
-
160095
- RemoveTemplateReplaceProvider.$inject = [
160096
- 'popupMenu',
160097
- 'translate',
160098
- 'elementTemplates'
160099
- ];
160100
-
160101
- /**
160102
- * Register replace menu provider in the popup menu
160103
- */
160104
- RemoveTemplateReplaceProvider.prototype.register = function() {
160105
- this._popupMenu.registerProvider('bpmn-replace', this);
160106
- };
160107
-
160108
- /**
160109
- * Adds the element templates to the replace menu.
160110
- * @param {djs.model.Base} element
160111
- *
160112
- * @returns {Object}
160113
- */
160114
- RemoveTemplateReplaceProvider.prototype.getPopupMenuEntries = function(element) {
160115
-
160116
- return (entries) => {
160117
-
160118
- // convert our entries into something sortable
160119
- let entrySet = Object.entries(entries);
160120
-
160121
- if (this._elementTemplates && this._elementTemplates.get(element)) {
160122
-
160123
- // add remove template option
160124
- this.addPlainElementEntry(element, entrySet, this._translate, this._elementTemplates);
160125
- }
160126
-
160127
- // convert back to object
160128
- return entrySet.reduce((entries, [ key, value ]) => {
160129
- entries[key] = value;
160130
-
160131
- return entries;
160132
- }, {});
160133
- };
160134
- };
160135
-
160136
-
160137
- /**
160138
- * Adds the option to replace with plain element (remove template).
160139
- *
160140
- * @param {djs.model.Base} element
160141
- * @param {Array<Object>} entries
160142
- */
160143
- RemoveTemplateReplaceProvider.prototype.addPlainElementEntry = function(element, entries, translate, elementTemplates) {
160144
-
160145
- const replaceOption = this.getPlainEntry(element, entries, translate, elementTemplates);
160146
-
160147
- if (!replaceOption) {
160148
- return;
160149
- }
160150
-
160151
- const [
160152
- insertIndex,
160153
- entry
160154
- ] = replaceOption;
160155
-
160156
- // insert remove entry
160157
- entries.splice(insertIndex, 0, [ entry.id, entry ]);
160158
- };
160159
-
160160
- /**
160161
- * Returns the option to replace with plain element and the index where it should be inserted.
160162
- *
160163
- * @param {djs.model.Base} element
160164
- * @param {Array<Object>} entries
160165
- *
160166
- * @returns {Array<Object, number>}
160167
- */
160168
- RemoveTemplateReplaceProvider.prototype.getPlainEntry = function(element, entries, translate, elementTemplates) {
160169
-
160170
- const {
160171
- options,
160172
- option,
160173
- optionIndex
160174
- } = findReplaceOptions(element) || { };
160175
-
160176
- if (!options) {
160177
- return null;
160178
- }
160179
-
160180
- const entry = {
160181
- id: 'replace-remove-element-template',
160182
- action: () => {
160183
- elementTemplates.removeTemplate(element);
160184
- },
160185
- label: translate(option.label),
160186
- className: option.className
160187
- };
160188
-
160189
- // insert after previous option, if it exists
160190
- const previousIndex = getOptionIndex(options, optionIndex - 1, entries);
160191
-
160192
- if (previousIndex) {
160193
- return [
160194
- previousIndex + 1,
160195
- entry
160196
- ];
160197
- }
160198
-
160199
- // insert before next option, if it exists
160200
- const nextIndex = getOptionIndex(options, optionIndex + 1, entries);
160201
-
160202
- if (nextIndex) {
160203
- return [
160204
- nextIndex,
160205
- entry
160206
- ];
160207
- }
160208
-
160209
- // fallback to insert at start
160210
- return [
160211
- 0,
160212
- entry
160213
- ];
160214
- };
160215
-
160216
-
160217
- /**
160218
- * @param {ModdleElement} element
160219
- *
160220
- * @return { { options: Array<any>, option: any, optionIndex: number } | null }
160221
- */
160222
- function findReplaceOptions(element) {
160223
-
160224
- const isSameType = (element, option) => option.target && !isDifferentType(element)(option);
160225
-
160226
- return getReplaceOptionGroups().reduce((result, options) => {
160227
-
160228
- if (result) {
160229
- return result;
160230
- }
160231
-
160232
- const optionIndex = options.findIndex(option => isSameType(element, option));
160233
-
160234
- if (optionIndex === -1) {
160235
- return;
160236
- }
160237
-
160238
- return {
160239
- options,
160240
- option: options[optionIndex],
160241
- optionIndex
160242
- };
160243
- }, null);
160244
- }
160245
-
160246
- function getOptionIndex(options, index, entries) {
160247
- const option = options[index];
160248
-
160249
- if (!option) {
160250
- return false;
160251
- }
160252
-
160253
- return entries.findIndex(
160254
- ([ key ]) => key === option.actionName
160255
- );
160092
+ /**
160093
+ * A replace menu provider that allows to replace elements with
160094
+ * templates applied with the correspondent plain element.
160095
+ */
160096
+ function RemoveTemplateReplaceProvider(popupMenu, translate, elementTemplates) {
160097
+
160098
+ this._popupMenu = popupMenu;
160099
+ this._translate = translate;
160100
+ this._elementTemplates = elementTemplates;
160101
+
160102
+ this.register();
160103
+ }
160104
+
160105
+ RemoveTemplateReplaceProvider.$inject = [
160106
+ 'popupMenu',
160107
+ 'translate',
160108
+ 'elementTemplates'
160109
+ ];
160110
+
160111
+ /**
160112
+ * Register replace menu provider in the popup menu
160113
+ */
160114
+ RemoveTemplateReplaceProvider.prototype.register = function() {
160115
+ this._popupMenu.registerProvider('bpmn-replace', this);
160116
+ };
160117
+
160118
+ /**
160119
+ * Adds the element templates to the replace menu.
160120
+ * @param {djs.model.Base} element
160121
+ *
160122
+ * @returns {Object}
160123
+ */
160124
+ RemoveTemplateReplaceProvider.prototype.getPopupMenuEntries = function(element) {
160125
+
160126
+ return (entries) => {
160127
+
160128
+ // convert our entries into something sortable
160129
+ let entrySet = Object.entries(entries);
160130
+
160131
+ if (this._elementTemplates && this._elementTemplates.get(element)) {
160132
+
160133
+ // add remove template option
160134
+ this.addPlainElementEntry(element, entrySet, this._translate, this._elementTemplates);
160135
+ }
160136
+
160137
+ // convert back to object
160138
+ return entrySet.reduce((entries, [ key, value ]) => {
160139
+ entries[key] = value;
160140
+
160141
+ return entries;
160142
+ }, {});
160143
+ };
160144
+ };
160145
+
160146
+
160147
+ /**
160148
+ * Adds the option to replace with plain element (remove template).
160149
+ *
160150
+ * @param {djs.model.Base} element
160151
+ * @param {Array<Object>} entries
160152
+ */
160153
+ RemoveTemplateReplaceProvider.prototype.addPlainElementEntry = function(element, entries, translate, elementTemplates) {
160154
+
160155
+ const replaceOption = this.getPlainEntry(element, entries, translate, elementTemplates);
160156
+
160157
+ if (!replaceOption) {
160158
+ return;
160159
+ }
160160
+
160161
+ const [
160162
+ insertIndex,
160163
+ entry
160164
+ ] = replaceOption;
160165
+
160166
+ // insert remove entry
160167
+ entries.splice(insertIndex, 0, [ entry.id, entry ]);
160168
+ };
160169
+
160170
+ /**
160171
+ * Returns the option to replace with plain element and the index where it should be inserted.
160172
+ *
160173
+ * @param {djs.model.Base} element
160174
+ * @param {Array<Object>} entries
160175
+ *
160176
+ * @returns {Array<Object, number>}
160177
+ */
160178
+ RemoveTemplateReplaceProvider.prototype.getPlainEntry = function(element, entries, translate, elementTemplates) {
160179
+
160180
+ const {
160181
+ options,
160182
+ option,
160183
+ optionIndex
160184
+ } = findReplaceOptions(element) || { };
160185
+
160186
+ if (!options) {
160187
+ return null;
160188
+ }
160189
+
160190
+ const entry = {
160191
+ id: 'replace-remove-element-template',
160192
+ action: () => {
160193
+ elementTemplates.removeTemplate(element);
160194
+ },
160195
+ label: translate(option.label),
160196
+ className: option.className
160197
+ };
160198
+
160199
+ // insert after previous option, if it exists
160200
+ const previousIndex = getOptionIndex(options, optionIndex - 1, entries);
160201
+
160202
+ if (previousIndex) {
160203
+ return [
160204
+ previousIndex + 1,
160205
+ entry
160206
+ ];
160207
+ }
160208
+
160209
+ // insert before next option, if it exists
160210
+ const nextIndex = getOptionIndex(options, optionIndex + 1, entries);
160211
+
160212
+ if (nextIndex) {
160213
+ return [
160214
+ nextIndex,
160215
+ entry
160216
+ ];
160217
+ }
160218
+
160219
+ // fallback to insert at start
160220
+ return [
160221
+ 0,
160222
+ entry
160223
+ ];
160224
+ };
160225
+
160226
+
160227
+ /**
160228
+ * @param {ModdleElement} element
160229
+ *
160230
+ * @return { { options: Array<any>, option: any, optionIndex: number } | null }
160231
+ */
160232
+ function findReplaceOptions(element) {
160233
+
160234
+ const isSameType = (element, option) => option.target && !isDifferentType(element)(option);
160235
+
160236
+ return getReplaceOptionGroups().reduce((result, options) => {
160237
+
160238
+ if (result) {
160239
+ return result;
160240
+ }
160241
+
160242
+ const optionIndex = options.findIndex(option => isSameType(element, option));
160243
+
160244
+ if (optionIndex === -1) {
160245
+ return;
160246
+ }
160247
+
160248
+ return {
160249
+ options,
160250
+ option: options[optionIndex],
160251
+ optionIndex
160252
+ };
160253
+ }, null);
160254
+ }
160255
+
160256
+ function getOptionIndex(options, index, entries) {
160257
+ const option = options[index];
160258
+
160259
+ if (!option) {
160260
+ return false;
160261
+ }
160262
+
160263
+ return entries.findIndex(
160264
+ ([ key ]) => key === option.actionName
160265
+ );
160256
160266
  }
160257
160267
 
160258
- var RemoveTemplatesModule = {
160259
- __init__: [ 'removeTemplateReplaceProvider' ],
160260
- removeTemplateReplaceProvider: [ 'type', RemoveTemplateReplaceProvider ]
160268
+ var RemoveTemplatesModule = {
160269
+ __init__: [ 'removeTemplateReplaceProvider' ],
160270
+ removeTemplateReplaceProvider: [ 'type', RemoveTemplateReplaceProvider ]
160261
160271
  };
160262
160272
 
160263
- var index = {
160264
- __depends__: [
160265
- AppendElementTemplatesModule,
160266
- CreateElementTemplatesModule,
160267
- ReplaceElementTemplatesModule,
160268
- RemoveTemplatesModule
160269
- ]
160273
+ var index = {
160274
+ __depends__: [
160275
+ AppendElementTemplatesModule,
160276
+ CreateElementTemplatesModule,
160277
+ ReplaceElementTemplatesModule,
160278
+ RemoveTemplatesModule
160279
+ ]
160270
160280
  };
160271
160281
 
160272
160282
  /**