camunda-bpmn-js 4.20.0 → 4.20.1

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.
@@ -28164,7 +28164,6 @@
28164
28164
  scale,
28165
28165
  search,
28166
28166
  emptyPlaceholder,
28167
- searchFn,
28168
28167
  entries: originalEntries,
28169
28168
  onOpened,
28170
28169
  onClosed
@@ -28186,19 +28185,29 @@
28186
28185
  return originalEntries;
28187
28186
  }
28188
28187
 
28189
- if (!value) {
28190
- return originalEntries.filter(({ rank = 0 }) => rank >= 0);
28191
- }
28188
+ const filter = entry => {
28189
+ if (!value) {
28190
+ return (entry.rank || 0) >= 0;
28191
+ }
28192
+
28193
+ if (entry.searchable === false) {
28194
+ return false;
28195
+ }
28192
28196
 
28193
- const searchableEntries = originalEntries.filter(({ searchable }) => searchable !== false);
28197
+ const searchableFields = [
28198
+ entry.description || '',
28199
+ entry.label || '',
28200
+ entry.search || ''
28201
+ ].map(string => string.toLowerCase());
28194
28202
 
28195
- return searchFn(searchableEntries, value, {
28196
- keys: [
28197
- 'label',
28198
- 'description',
28199
- 'search'
28200
- ]
28201
- }).map(({ item }) => item);
28203
+ // every word of `value` should be included in one of the searchable fields
28204
+ return value
28205
+ .toLowerCase()
28206
+ .split(/\s/g)
28207
+ .every(word => searchableFields.some(field => field.includes(word)));
28208
+ };
28209
+
28210
+ return originalEntries.filter(filter);
28202
28211
  }, [ searchable ]);
28203
28212
 
28204
28213
  const [ entries, setEntries ] = p$2(filterEntries(originalEntries, value));
@@ -28455,10 +28464,9 @@
28455
28464
  * @param {EventBus} eventBus
28456
28465
  * @param {Canvas} canvas
28457
28466
  */
28458
- function PopupMenu(config, eventBus, canvas, search) {
28467
+ function PopupMenu(config, eventBus, canvas) {
28459
28468
  this._eventBus = eventBus;
28460
28469
  this._canvas = canvas;
28461
- this._search = search;
28462
28470
 
28463
28471
  this._current = null;
28464
28472
 
@@ -28490,8 +28498,7 @@
28490
28498
  PopupMenu.$inject = [
28491
28499
  'config.popupMenu',
28492
28500
  'eventBus',
28493
- 'canvas',
28494
- 'search'
28501
+ 'canvas'
28495
28502
  ];
28496
28503
 
28497
28504
  PopupMenu.prototype._render = function() {
@@ -28535,7 +28542,6 @@
28535
28542
  scale=${ scale }
28536
28543
  onOpened=${ this._onOpened.bind(this) }
28537
28544
  onClosed=${ this._onClosed.bind(this) }
28538
- searchFn=${ this._search }
28539
28545
  ...${{ ...options }}
28540
28546
  />
28541
28547
  `,
@@ -28946,6 +28952,7 @@
28946
28952
 
28947
28953
 
28948
28954
  PopupMenu.prototype._getEmptyPlaceholder = function(providers) {
28955
+
28949
28956
  const provider = providers.find(
28950
28957
  provider => isFunction(provider.getEmptyPlaceholder)
28951
28958
  );
@@ -29021,263 +29028,10 @@
29021
29028
  return entry;
29022
29029
  };
29023
29030
 
29024
- /**
29025
- * @typedef { {
29026
- * index: number;
29027
- * match: boolean;
29028
- * value: string;
29029
- * } } Token
29030
- *
29031
- * @typedef {Token[]} Tokens
29032
- *
29033
- * @typedef { {
29034
- * item: Object,
29035
- * tokens: Record<string, Tokens>
29036
- * } } SearchResult
29037
- *
29038
- * @typedef {SearchResult[]} SearchResults
29039
- */
29040
-
29041
- /**
29042
- * Search items by query.
29043
- *
29044
- * @param {Object[]} items
29045
- * @param {string} pattern
29046
- * @param { {
29047
- * keys: string[];
29048
- * } } options
29049
- *
29050
- * @returns {SearchResults}
29051
- */
29052
- function search(items, pattern, options) {
29053
- return items.reduce((results, item) => {
29054
- const tokens = getTokens(item, pattern, options.keys);
29055
-
29056
- if (Object.keys(tokens).length) {
29057
- const result = {
29058
- item,
29059
- tokens
29060
- };
29061
-
29062
- const index = getIndex(result, results, options.keys);
29063
-
29064
- results.splice(index, 0, result);
29065
- }
29066
-
29067
- return results;
29068
- }, []);
29069
- }
29070
-
29071
- /**
29072
- * Get tokens for item.
29073
- *
29074
- * @param {Object} item
29075
- * @param {string} pattern
29076
- * @param {string[]} keys
29077
- *
29078
- * @returns {Record<string, Tokens>}
29079
- */
29080
- function getTokens(item, pattern, keys) {
29081
- return keys.reduce((results, key) => {
29082
- const string = item[ key ];
29083
-
29084
- const tokens = getMatchingTokens(string, pattern);
29085
-
29086
- if (hasMatch$1(tokens)) {
29087
- results[ key ] = tokens;
29088
- }
29089
-
29090
- return results;
29091
- }, {});
29092
- }
29093
-
29094
- /**
29095
- * Get index of result in list of results.
29096
- *
29097
- * @param {SearchResult} result
29098
- * @param {SearchResults} results
29099
- * @param {string[]} keys
29100
- *
29101
- * @returns {number}
29102
- */
29103
- function getIndex(result, results, keys) {
29104
- if (!results.length) {
29105
- return 0;
29106
- }
29107
-
29108
- let index = 0;
29109
-
29110
- do {
29111
- for (const key of keys) {
29112
- const tokens = result.tokens[ key ],
29113
- tokensOther = results[ index ].tokens[ key ];
29114
-
29115
- if (tokens && !tokensOther) {
29116
- return index;
29117
- } else if (!tokens && tokensOther) {
29118
- index++;
29119
-
29120
- break;
29121
- } else if (!tokens && !tokensOther) {
29122
- continue;
29123
- }
29124
-
29125
- const tokenComparison = compareTokens$1(tokens, tokensOther);
29126
-
29127
- if (tokenComparison === -1) {
29128
- return index;
29129
- } else if (tokenComparison === 1) {
29130
- index++;
29131
-
29132
- break;
29133
- } else {
29134
- const stringComparison = compareStrings$1(result.item[ key ], results[ index ].item[ key ]);
29135
-
29136
- if (stringComparison === -1) {
29137
- return index;
29138
- } else if (stringComparison === 1) {
29139
- index++;
29140
-
29141
- break;
29142
- } else {
29143
- continue;
29144
- }
29145
- }
29146
- }
29147
- } while (index < results.length);
29148
-
29149
- return index;
29150
- }
29151
-
29152
- /**
29153
- * @param {Token} token
29154
- *
29155
- * @return {boolean}
29156
- */
29157
- function isMatch$1(token) {
29158
- return token.match;
29159
- }
29160
-
29161
- /**
29162
- * @param {Token[]} tokens
29163
- *
29164
- * @return {boolean}
29165
- */
29166
- function hasMatch$1(tokens) {
29167
- return tokens.find(isMatch$1);
29168
- }
29169
-
29170
- /**
29171
- * Compares two token arrays.
29172
- *
29173
- * @param {Token[]} tokensA
29174
- * @param {Token[]} tokensB
29175
- *
29176
- * @returns {number}
29177
- */
29178
- function compareTokens$1(tokensA, tokensB) {
29179
- const tokensAHasMatch = hasMatch$1(tokensA),
29180
- tokensBHasMatch = hasMatch$1(tokensB);
29181
-
29182
- if (tokensAHasMatch && !tokensBHasMatch) {
29183
- return -1;
29184
- }
29185
-
29186
- if (!tokensAHasMatch && tokensBHasMatch) {
29187
- return 1;
29188
- }
29189
-
29190
- if (!tokensAHasMatch && !tokensBHasMatch) {
29191
- return 0;
29192
- }
29193
-
29194
- const tokensAFirstMatch = tokensA.find(isMatch$1),
29195
- tokensBFirstMatch = tokensB.find(isMatch$1);
29196
-
29197
- if (tokensAFirstMatch.index < tokensBFirstMatch.index) {
29198
- return -1;
29199
- }
29200
-
29201
- if (tokensAFirstMatch.index > tokensBFirstMatch.index) {
29202
- return 1;
29203
- }
29204
-
29205
- return 0;
29206
- }
29207
-
29208
- /**
29209
- * Compares two strings.
29210
- *
29211
- * @param {string} a
29212
- * @param {string} b
29213
- *
29214
- * @returns {number}
29215
- */
29216
- function compareStrings$1(a, b) {
29217
- return a.localeCompare(b);
29218
- }
29219
-
29220
- /**
29221
- * @param {string} string
29222
- * @param {string} pattern
29223
- *
29224
- * @return {Token[]}
29225
- */
29226
- function getMatchingTokens(string, pattern) {
29227
- var tokens = [],
29228
- originalString = string;
29229
-
29230
- if (!string) {
29231
- return tokens;
29232
- }
29233
-
29234
- string = string.toLowerCase();
29235
- pattern = pattern.toLowerCase();
29236
-
29237
- var index = string.indexOf(pattern);
29238
-
29239
- if (index > -1) {
29240
- if (index !== 0) {
29241
- tokens.push({
29242
- value: originalString.slice(0, index),
29243
- index: 0
29244
- });
29245
- }
29246
-
29247
- tokens.push({
29248
- value: originalString.slice(index, index + pattern.length),
29249
- index: index,
29250
- match: true
29251
- });
29252
-
29253
- if (pattern.length + index < string.length) {
29254
- tokens.push({
29255
- value: originalString.slice(index + pattern.length),
29256
- index: index + pattern.length
29257
- });
29258
- }
29259
- } else {
29260
- tokens.push({
29261
- value: originalString,
29262
- index: 0
29263
- });
29264
- }
29265
-
29266
- return tokens;
29267
- }
29268
-
29269
- /**
29270
- * @type { import('didi').ModuleDeclaration }
29271
- */
29272
- var Search = {
29273
- search: [ 'value', search ]
29274
- };
29275
-
29276
29031
  /**
29277
29032
  * @type { import('didi').ModuleDeclaration }
29278
29033
  */
29279
29034
  var PopupMenuModule$1 = {
29280
- __depends__: [ Search ],
29281
29035
  __init__: [ 'popupMenu' ],
29282
29036
  popupMenu: [ 'type', PopupMenu ]
29283
29037
  };