@lumel/mention 5.2.1 → 5.2.4

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.
package/lib/index.esm.js CHANGED
@@ -11,26 +11,21 @@ function _extends() {
11
11
  _extends = Object.assign ? Object.assign.bind() : function (target) {
12
12
  for (var i = 1; i < arguments.length; i++) {
13
13
  var source = arguments[i];
14
-
15
14
  for (var key in source) {
16
15
  if (Object.prototype.hasOwnProperty.call(source, key)) {
17
16
  target[key] = source[key];
18
17
  }
19
18
  }
20
19
  }
21
-
22
20
  return target;
23
21
  };
24
22
  return _extends.apply(this, arguments);
25
23
  }
26
-
27
24
  function _inheritsLoose(subClass, superClass) {
28
25
  subClass.prototype = Object.create(superClass.prototype);
29
26
  subClass.prototype.constructor = subClass;
30
-
31
27
  _setPrototypeOf(subClass, superClass);
32
28
  }
33
-
34
29
  function _setPrototypeOf(o, p) {
35
30
  _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
36
31
  o.__proto__ = p;
@@ -38,22 +33,18 @@ function _setPrototypeOf(o, p) {
38
33
  };
39
34
  return _setPrototypeOf(o, p);
40
35
  }
41
-
42
36
  function _objectWithoutPropertiesLoose(source, excluded) {
43
37
  if (source == null) return {};
44
38
  var target = {};
45
39
  var sourceKeys = Object.keys(source);
46
40
  var key, i;
47
-
48
41
  for (i = 0; i < sourceKeys.length; i++) {
49
42
  key = sourceKeys[i];
50
43
  if (excluded.indexOf(key) >= 0) continue;
51
44
  target[key] = source[key];
52
45
  }
53
-
54
46
  return target;
55
47
  }
56
-
57
48
  function _unsupportedIterableToArray(o, minLen) {
58
49
  if (!o) return;
59
50
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -62,20 +53,15 @@ function _unsupportedIterableToArray(o, minLen) {
62
53
  if (n === "Map" || n === "Set") return Array.from(o);
63
54
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
64
55
  }
65
-
66
56
  function _arrayLikeToArray(arr, len) {
67
57
  if (len == null || len > arr.length) len = arr.length;
68
-
69
58
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
70
-
71
59
  return arr2;
72
60
  }
73
-
74
61
  function _createForOfIteratorHelperLoose(o, allowArrayLike) {
75
62
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
76
63
  if (it) return (it = it.call(o)).next.bind(it);
77
-
78
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
64
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike) {
79
65
  if (it) o = it;
80
66
  var i = 0;
81
67
  return function () {
@@ -88,14 +74,13 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
88
74
  };
89
75
  };
90
76
  }
91
-
92
77
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
93
78
  }
94
79
 
95
80
  function MentionLink(_ref) {
96
81
  var mention = _ref.mention,
97
- children = _ref.children,
98
- className = _ref.className;
82
+ children = _ref.children,
83
+ className = _ref.className;
99
84
  return /*#__PURE__*/React.createElement("a", {
100
85
  href: mention.link,
101
86
  className: className,
@@ -103,26 +88,24 @@ function MentionLink(_ref) {
103
88
  "data-testid": "mentionLink"
104
89
  }, children);
105
90
  }
106
-
107
91
  function MentionText(_ref2) {
108
92
  var children = _ref2.children,
109
- className = _ref2.className;
93
+ className = _ref2.className;
110
94
  return /*#__PURE__*/React.createElement("span", {
111
95
  className: className,
112
96
  spellCheck: false,
113
97
  "data-testid": "mentionText"
114
98
  }, children);
115
99
  }
116
-
117
100
  function Mention(props) {
118
101
  var entityKey = props.entityKey,
119
- _props$theme = props.theme,
120
- theme = _props$theme === void 0 ? {} : _props$theme,
121
- mentionComponent = props.mentionComponent,
122
- children = props.children,
123
- decoratedText = props.decoratedText,
124
- className = props.className,
125
- contentState = props.contentState;
102
+ _props$theme = props.theme,
103
+ theme = _props$theme === void 0 ? {} : _props$theme,
104
+ mentionComponent = props.mentionComponent,
105
+ children = props.children,
106
+ decoratedText = props.decoratedText,
107
+ className = props.className,
108
+ contentState = props.contentState;
126
109
  var combinedClassName = clsx(theme.mention, className);
127
110
  var mention = contentState.getEntity(entityKey).getData().mention;
128
111
  var Component = mentionComponent || (mention.link ? MentionLink : MentionText);
@@ -147,7 +130,6 @@ function getSearchTextAt(blockText, position, triggers) {
147
130
  var matches = str.matchAll(TRIGGER_REGEX);
148
131
  var triggerStartIndex = 0;
149
132
  var valueStartIndex = 0;
150
-
151
133
  for (var _iterator = _createForOfIteratorHelperLoose(matches), _step; !(_step = _iterator()).done;) {
152
134
  var match = _step.value;
153
135
  var spaceLen = match[1].length;
@@ -155,7 +137,6 @@ function getSearchTextAt(blockText, position, triggers) {
155
137
  triggerStartIndex = (match.index || 0) + spaceLen;
156
138
  valueStartIndex = triggerStartIndex + matchLen;
157
139
  }
158
-
159
140
  var matchingString = str.slice(valueStartIndex);
160
141
  var end = str.length;
161
142
  return {
@@ -184,36 +165,33 @@ function addMention(editorState, mention, mentionPrefix, mentionTrigger, entityM
184
165
  });
185
166
  var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
186
167
  var currentSelectionState = editorState.getSelection();
187
-
188
168
  var _getSearchText = getSearchText(editorState, currentSelectionState, [mentionTrigger]),
189
- begin = _getSearchText.begin,
190
- end = _getSearchText.end; // get selection of the @mention search text
191
-
169
+ begin = _getSearchText.begin,
170
+ end = _getSearchText.end;
192
171
 
172
+ // get selection of the @mention search text
193
173
  var mentionTextSelection = currentSelectionState.merge({
194
174
  anchorOffset: begin,
195
175
  focusOffset: end
196
176
  });
197
- var mentionReplacedContent = Modifier.replaceText(editorState.getCurrentContent(), mentionTextSelection, "" + mentionPrefix + mention.name, editorState.getCurrentInlineStyle(), entityKey); // If the mention is inserted at the end, a space is appended right after for
198
- // a smooth writing experience.
177
+ var mentionReplacedContent = Modifier.replaceText(editorState.getCurrentContent(), mentionTextSelection, "" + mentionPrefix + mention.name, editorState.getCurrentInlineStyle(), entityKey);
199
178
 
179
+ // If the mention is inserted at the end, a space is appended right after for
180
+ // a smooth writing experience.
200
181
  var blockKey = mentionTextSelection.getAnchorKey();
201
182
  var blockSize = editorState.getCurrentContent().getBlockForKey(blockKey).getLength();
202
-
203
183
  if (blockSize === end) {
204
184
  mentionReplacedContent = Modifier.insertText(mentionReplacedContent, mentionReplacedContent.getSelectionAfter(), ' ');
205
185
  }
206
-
207
186
  var newEditorState = EditorState.push(editorState, mentionReplacedContent, 'insert-fragment');
208
187
  return EditorState.forceSelection(newEditorState, mentionReplacedContent.getSelectionAfter());
209
188
  }
210
189
 
211
190
  var decodeOffsetKey = function decodeOffsetKey(offsetKey) {
212
191
  var _offsetKey$split = offsetKey.split('-'),
213
- blockKey = _offsetKey$split[0],
214
- decoratorKey = _offsetKey$split[1],
215
- leafKey = _offsetKey$split[2];
216
-
192
+ blockKey = _offsetKey$split[0],
193
+ decoratorKey = _offsetKey$split[1],
194
+ leafKey = _offsetKey$split[2];
217
195
  return {
218
196
  blockKey: blockKey,
219
197
  decoratorKey: parseInt(decoratorKey, 10),
@@ -221,65 +199,64 @@ var decodeOffsetKey = function decodeOffsetKey(offsetKey) {
221
199
  };
222
200
  };
223
201
 
224
- var decodeOffsetKey$1 = decodeOffsetKey;
225
-
226
202
  function filterUndefineds(value) {
227
203
  return value !== undefined;
228
204
  }
229
-
230
205
  function getTriggerForMention(editorState, searches, mentionTriggers) {
231
206
  // get the current selection
232
207
  var selection = editorState.getSelection();
233
208
  var anchorKey = selection.getAnchorKey();
234
- var anchorOffset = selection.getAnchorOffset(); // the list should not be visible if a range is selected or the editor has no focus
235
-
209
+ var anchorOffset = selection.getAnchorOffset();
210
+ // the list should not be visible if a range is selected or the editor has no focus
236
211
  if (!selection.isCollapsed() || !selection.getHasFocus()) {
237
212
  return null;
238
- } // identify the start & end positon of each search-text
239
-
213
+ }
240
214
 
215
+ // identify the start & end positon of each search-text
241
216
  var offsetDetails = searches.map(function (offsetKey) {
242
- return decodeOffsetKey$1(offsetKey);
243
- }); // a leave can be empty when it is removed due event.g. using backspace
244
- // do not check leaves, use full decorated portal text
217
+ return decodeOffsetKey(offsetKey);
218
+ });
245
219
 
220
+ // a leave can be empty when it is removed due event.g. using backspace
221
+ // do not check leaves, use full decorated portal text
246
222
  var leaves = offsetDetails.filter(function (offsetDetail) {
247
223
  return offsetDetail.blockKey === anchorKey;
248
224
  }).map(function (offsetDetail) {
249
225
  return editorState.getBlockTree(offsetDetail.blockKey).getIn([offsetDetail.decoratorKey]);
250
- }); // if all leaves are undefined the popover should be removed
226
+ });
251
227
 
228
+ // if all leaves are undefined the popover should be removed
252
229
  if (leaves.every(function (leave) {
253
230
  return leave === undefined;
254
231
  })) {
255
232
  return null;
256
- } // Checks that the cursor is after the @ character but still somewhere in
233
+ }
234
+ // Checks that the cursor is after the @ character but still somewhere in
257
235
  // the word (search term). Setting it to allow the cursor to be left of
258
236
  // the @ causes troubles due selection confusion.
259
-
260
-
261
237
  var blockText = editorState.getCurrentContent().getBlockForKey(anchorKey).getText();
262
238
  var triggerForSelectionInsideWord = leaves.filter(filterUndefineds).map(function (_ref) {
263
239
  var start = _ref.start,
264
- end = _ref.end;
240
+ end = _ref.end;
265
241
  return mentionTriggers.map(function (trigger) {
266
- return (// @ is the first character
267
- start === 0 && anchorOffset >= start + trigger.length && //should not trigger if the cursor is before the trigger
268
- blockText.substr(0, trigger.length) === trigger && anchorOffset <= end || // @ is in the text or at the end, multi triggers
269
- mentionTriggers.length > 1 && anchorOffset >= start + trigger.length && (blockText.substr(start + 1, trigger.length) === trigger || blockText.substr(start, trigger.length) === trigger) && anchorOffset <= end || // @ is in the text or at the end, single trigger
242
+ return (
243
+ // @ is the first character
244
+ start === 0 && anchorOffset >= start + trigger.length &&
245
+ //should not trigger if the cursor is before the trigger
246
+ blockText.substr(0, trigger.length) === trigger && anchorOffset <= end ||
247
+ // @ is in the text or at the end, multi triggers
248
+ mentionTriggers.length > 1 && anchorOffset >= start + trigger.length && (blockText.substr(start + 1, trigger.length) === trigger || blockText.substr(start, trigger.length) === trigger) && anchorOffset <= end ||
249
+ // @ is in the text or at the end, single trigger
270
250
  mentionTriggers.length === 1 && anchorOffset >= start + trigger.length && anchorOffset <= end ? trigger : undefined
271
251
  );
272
252
  }).filter(filterUndefineds)[0];
273
253
  }).filter(filterUndefineds);
274
-
275
254
  if (triggerForSelectionInsideWord.isEmpty()) {
276
255
  return null;
277
256
  }
278
-
279
257
  var _triggerForSelectionI = triggerForSelectionInsideWord.entrySeq().first(),
280
- activeOffsetKey = _triggerForSelectionI[0],
281
- activeTrigger = _triggerForSelectionI[1];
282
-
258
+ activeOffsetKey = _triggerForSelectionI[0],
259
+ activeTrigger = _triggerForSelectionI[1];
283
260
  return {
284
261
  activeOffsetKey: activeOffsetKey,
285
262
  activeTrigger: activeTrigger
@@ -290,23 +267,18 @@ var getRelativeParent = function getRelativeParent(element) {
290
267
  if (!element) {
291
268
  return null;
292
269
  }
293
-
294
270
  var position = window.getComputedStyle(element).getPropertyValue('position');
295
-
296
271
  if (position !== 'static') {
297
272
  return element;
298
273
  }
299
-
300
274
  return getRelativeParent(element.parentElement);
301
275
  };
302
-
303
276
  function positionSuggestions(_ref) {
304
277
  var decoratorRect = _ref.decoratorRect,
305
- popover = _ref.popover,
306
- props = _ref.props;
278
+ popover = _ref.popover,
279
+ props = _ref.props;
307
280
  var relativeParent = getRelativeParent(popover.parentElement);
308
281
  var relativeRect;
309
-
310
282
  if (relativeParent) {
311
283
  var relativeParentRect = relativeParent.getBoundingClientRect();
312
284
  relativeRect = {
@@ -323,12 +295,10 @@ function positionSuggestions(_ref) {
323
295
  left: decoratorRect.left
324
296
  };
325
297
  }
326
-
327
298
  var left = relativeRect.left + relativeRect.scrollLeft;
328
299
  var top = relativeRect.top + relativeRect.scrollTop;
329
300
  var transform;
330
301
  var transition;
331
-
332
302
  if (props.open) {
333
303
  if (props.suggestions.length > 0) {
334
304
  transform = 'scale(1)';
@@ -338,7 +308,6 @@ function positionSuggestions(_ref) {
338
308
  transition = 'all 0.35s cubic-bezier(.3,1,.2,1)';
339
309
  }
340
310
  }
341
-
342
311
  return {
343
312
  left: left + "px",
344
313
  top: top + "px",
@@ -357,9 +326,8 @@ var warning = once(function (text) {
357
326
 
358
327
  function Avatar(_ref) {
359
328
  var mention = _ref.mention,
360
- _ref$theme = _ref.theme,
361
- theme = _ref$theme === void 0 ? {} : _ref$theme;
362
-
329
+ _ref$theme = _ref.theme,
330
+ theme = _ref$theme === void 0 ? {} : _ref$theme;
363
331
  if (mention.avatar) {
364
332
  return /*#__PURE__*/React.createElement("img", {
365
333
  src: mention.avatar,
@@ -367,19 +335,17 @@ function Avatar(_ref) {
367
335
  role: "presentation"
368
336
  });
369
337
  }
370
-
371
338
  return null;
372
339
  }
373
340
 
374
341
  var _excluded$1 = ["mention", "theme", "isFocused", "searchValue", "selectMention"];
375
342
  function DefaultEntryComponent(props) {
376
343
  var mention = props.mention,
377
- theme = props.theme,
378
- isFocused = props.isFocused;
379
- props.searchValue;
380
- props.selectMention;
381
- var parentProps = _objectWithoutPropertiesLoose(props, _excluded$1);
382
-
344
+ theme = props.theme,
345
+ isFocused = props.isFocused;
346
+ props.searchValue;
347
+ props.selectMention;
348
+ var parentProps = _objectWithoutPropertiesLoose(props, _excluded$1);
383
349
  return /*#__PURE__*/React.createElement("div", _extends({}, parentProps, {
384
350
  "aria-selected": isFocused
385
351
  }), /*#__PURE__*/React.createElement(Avatar, {
@@ -392,14 +358,14 @@ function DefaultEntryComponent(props) {
392
358
 
393
359
  var Entry = function Entry(_ref) {
394
360
  var onMentionSelect = _ref.onMentionSelect,
395
- mention = _ref.mention,
396
- theme = _ref.theme,
397
- index = _ref.index,
398
- onMentionFocus = _ref.onMentionFocus,
399
- isFocused = _ref.isFocused,
400
- id = _ref.id,
401
- searchValue = _ref.searchValue,
402
- EntryComponent = _ref.entryComponent;
361
+ mention = _ref.mention,
362
+ theme = _ref.theme,
363
+ index = _ref.index,
364
+ onMentionFocus = _ref.onMentionFocus,
365
+ isFocused = _ref.isFocused,
366
+ id = _ref.id,
367
+ searchValue = _ref.searchValue,
368
+ EntryComponent = _ref.entryComponent;
403
369
  var mouseDown = useRef(false);
404
370
  var ref = useRef(null);
405
371
  useEffect(function () {
@@ -407,7 +373,6 @@ var Entry = function Entry(_ref) {
407
373
  //delay the scrolling as the popup needs some time for positioning
408
374
  requestAnimationFrame(function () {
409
375
  var _ref$current;
410
-
411
376
  return (_ref$current = ref.current) == null ? void 0 : _ref$current.scrollIntoView({
412
377
  behavior: 'smooth',
413
378
  block: 'nearest'
@@ -418,24 +383,20 @@ var Entry = function Entry(_ref) {
418
383
  useEffect(function () {
419
384
  mouseDown.current = false;
420
385
  });
421
-
422
386
  var onMouseUp = function onMouseUp() {
423
387
  if (mouseDown.current) {
424
388
  onMentionSelect(mention);
425
389
  mouseDown.current = false;
426
390
  }
427
391
  };
428
-
429
392
  var onMouseDown = function onMouseDown(event) {
430
393
  // Note: important to avoid a content edit change
431
394
  event.preventDefault();
432
395
  mouseDown.current = true;
433
396
  };
434
-
435
397
  var onMouseEnter = function onMouseEnter() {
436
398
  onMentionFocus(index);
437
399
  };
438
-
439
400
  var className = isFocused ? theme.mentionSuggestionsEntryFocused : theme.mentionSuggestionsEntry;
440
401
  return /*#__PURE__*/React.createElement("div", {
441
402
  ref: ref
@@ -454,38 +415,32 @@ var Entry = function Entry(_ref) {
454
415
  selectMention: onMentionSelect
455
416
  }));
456
417
  };
457
-
458
418
  Entry.propTypes = {
459
419
  entryComponent: PropTypes.any.isRequired,
460
420
  searchValue: PropTypes.string,
461
421
  // eslint-disable-next-line react/no-unused-prop-types
462
422
  onMentionSelect: PropTypes.func
463
423
  };
464
- var Entry$1 = Entry;
465
424
 
466
425
  function Popover(_ref) {
467
426
  var store = _ref.store,
468
- children = _ref.children,
469
- theme = _ref.theme,
470
- _ref$popperOptions = _ref.popperOptions,
471
- popperOptions = _ref$popperOptions === void 0 ? {
472
- placement: 'bottom-start'
473
- } : _ref$popperOptions;
474
-
427
+ children = _ref.children,
428
+ theme = _ref.theme,
429
+ _ref$popperOptions = _ref.popperOptions,
430
+ popperOptions = _ref$popperOptions === void 0 ? {
431
+ placement: 'bottom-start'
432
+ } : _ref$popperOptions;
475
433
  var _useState = useState(function () {
476
- return clsx(theme.mentionSuggestions, theme.mentionSuggestionsPopup);
477
- }),
478
- className = _useState[0],
479
- setClassName = _useState[1];
480
-
434
+ return clsx(theme.mentionSuggestions, theme.mentionSuggestionsPopup);
435
+ }),
436
+ className = _useState[0],
437
+ setClassName = _useState[1];
481
438
  var _useState2 = useState(null),
482
- popperElement = _useState2[0],
483
- setPopperElement = _useState2[1];
484
-
439
+ popperElement = _useState2[0],
440
+ setPopperElement = _useState2[1];
485
441
  var _usePopper = usePopper(store.getReferenceElement(), popperElement, popperOptions),
486
- styles = _usePopper.styles,
487
- attributes = _usePopper.attributes;
488
-
442
+ styles = _usePopper.styles,
443
+ attributes = _usePopper.attributes;
489
444
  useEffect(function () {
490
445
  requestAnimationFrame(function () {
491
446
  return setClassName(clsx(theme.mentionSuggestions, theme.mentionSuggestionsPopup, theme.mentionSuggestionsPopupVisible));
@@ -503,208 +458,157 @@ function Popover(_ref) {
503
458
  var _excluded = ["entryComponent", "popoverComponent", "popperOptions", "popoverContainer", "onOpenChange", "onAddMention", "onSearchChange", "suggestions", "ariaProps", "callbacks", "theme", "store", "entityMutability", "positionSuggestions", "mentionTriggers", "mentionPrefix"];
504
459
  var MentionSuggestions = /*#__PURE__*/function (_Component) {
505
460
  _inheritsLoose(MentionSuggestions, _Component);
506
-
507
461
  function MentionSuggestions(props) {
508
462
  var _this;
509
-
510
463
  _this = _Component.call(this, props) || this;
511
464
  _this.state = {
512
465
  focusedOptionIndex: 0
513
466
  };
514
467
  _this.key = genKey();
515
- _this.popover = void 0;
516
- _this.activeOffsetKey = void 0;
517
- _this.lastSearchValue = void 0;
518
468
  _this.lastActiveTrigger = '';
519
- _this.lastSelectionIsInsideWord = void 0;
520
-
521
469
  _this.onEditorStateChange = function (editorState) {
522
- var searches = _this.props.store.getAllSearches(); // if no search portal is active there is no need to show the popover
523
-
524
-
470
+ var searches = _this.props.store.getAllSearches();
471
+ // if no search portal is active there is no need to show the popover
525
472
  if (searches.size === 0) {
526
473
  return editorState;
527
474
  }
528
-
529
475
  var removeList = function removeList() {
530
476
  _this.props.store.resetEscapedSearch();
531
-
532
477
  _this.closeDropdown();
533
-
534
478
  return editorState;
535
479
  };
536
-
537
480
  var triggerForMention = getTriggerForMention(editorState, searches, _this.props.mentionTriggers);
538
-
539
481
  if (!triggerForMention) {
540
482
  return removeList();
541
483
  }
542
-
543
484
  var lastActiveOffsetKey = _this.activeOffsetKey;
544
485
  _this.activeOffsetKey = triggerForMention.activeOffsetKey;
486
+ _this.onSearchChange(editorState, editorState.getSelection(), _this.activeOffsetKey, lastActiveOffsetKey, triggerForMention.activeTrigger);
545
487
 
546
- _this.onSearchChange(editorState, editorState.getSelection(), _this.activeOffsetKey, lastActiveOffsetKey, triggerForMention.activeTrigger); // make sure the escaped search is reseted in the cursor since the user
488
+ // make sure the escaped search is reseted in the cursor since the user
547
489
  // already switched to another mention search
548
-
549
-
550
490
  if (!_this.props.store.isEscaped(_this.activeOffsetKey || '')) {
551
491
  _this.props.store.resetEscapedSearch();
552
- } // If none of the above triggered to close the window, it's safe to assume
492
+ }
493
+
494
+ // If none of the above triggered to close the window, it's safe to assume
553
495
  // the dropdown should be open. This is useful when a user focuses on another
554
496
  // input field and then comes back: the dropdown will show again.
555
-
556
-
557
497
  if (!_this.props.open && !_this.props.store.isEscaped(_this.activeOffsetKey || '')) {
558
498
  _this.openDropdown();
559
- } // makes sure the focused index is reseted every time a new selection opens
499
+ }
500
+ // makes sure the focused index is reseted every time a new selection opens
560
501
  // or the selection was moved to another mention search
561
-
562
-
563
502
  if (lastActiveOffsetKey !== _this.activeOffsetKey) {
564
503
  _this.setState({
565
504
  focusedOptionIndex: 0
566
505
  });
567
506
  }
568
-
569
507
  return editorState;
570
508
  };
571
-
572
509
  _this.onSearchChange = function (editorState, selection, activeOffsetKey, lastActiveOffsetKey, trigger) {
573
510
  var _getSearchText = getSearchText(editorState, selection, [trigger]),
574
- searchValue = _getSearchText.matchingString;
575
-
511
+ searchValue = _getSearchText.matchingString;
576
512
  if (_this.lastActiveTrigger !== trigger || _this.lastSearchValue !== searchValue || activeOffsetKey !== lastActiveOffsetKey) {
577
513
  _this.lastActiveTrigger = trigger;
578
514
  _this.lastSearchValue = searchValue;
579
-
580
515
  _this.props.onSearchChange({
581
516
  trigger: trigger,
582
517
  value: searchValue
583
- }); //reset focus item if search is cahnged
584
-
585
-
518
+ });
519
+ //reset focus item if search is cahnged
586
520
  _this.setState({
587
521
  focusedOptionIndex: 0
588
522
  });
589
523
  }
590
524
  };
591
-
592
525
  _this.onDownArrow = function (keyboardEvent) {
593
526
  keyboardEvent.preventDefault();
594
527
  var newIndex = _this.state.focusedOptionIndex + 1;
595
-
596
528
  _this.onMentionFocus(newIndex >= _this.props.suggestions.length ? 0 : newIndex);
597
529
  };
598
-
599
530
  _this.onTab = function (keyboardEvent) {
600
531
  keyboardEvent.preventDefault();
601
-
602
532
  _this.commitSelection();
603
533
  };
604
-
605
534
  _this.onUpArrow = function (keyboardEvent) {
606
535
  keyboardEvent.preventDefault();
607
-
608
536
  if (_this.props.suggestions.length > 0) {
609
537
  var newIndex = _this.state.focusedOptionIndex - 1;
610
-
611
538
  _this.onMentionFocus(newIndex < 0 ? _this.props.suggestions.length - 1 : newIndex);
612
539
  }
613
540
  };
614
-
615
541
  _this.onEscape = function (keyboardEvent) {
616
542
  keyboardEvent.preventDefault();
617
-
618
543
  _this.props.store.escapeSearch(_this.activeOffsetKey || '');
544
+ _this.closeDropdown();
619
545
 
620
- _this.closeDropdown(); // to force a re-render of the outer component to change the aria props
621
-
622
-
546
+ // to force a re-render of the outer component to change the aria props
623
547
  _this.props.store.setEditorState(_this.props.store.getEditorState());
624
548
  };
625
-
626
549
  _this.onMentionSelect = function (mention) {
627
550
  // Note: This can happen in case a user typed @xxx (invalid mention) and
628
551
  // then hit Enter. Then the mention will be undefined.
629
552
  if (!mention) {
630
553
  return;
631
554
  }
632
-
633
555
  if (_this.props.onAddMention) {
634
556
  _this.props.onAddMention(mention);
635
557
  }
636
-
637
558
  _this.closeDropdown();
638
-
639
559
  var newEditorState = addMention(_this.props.store.getEditorState(), mention, _this.props.mentionPrefix, _this.lastActiveTrigger || '', _this.props.entityMutability);
640
-
641
560
  _this.props.store.setEditorState(newEditorState);
642
561
  };
643
-
644
562
  _this.onMentionFocus = function (index) {
645
563
  var descendant = "mention-option-" + _this.key + "-" + index;
646
564
  _this.props.ariaProps.ariaActiveDescendantID = descendant;
647
-
648
565
  _this.setState({
649
566
  focusedOptionIndex: index
650
- }); // to force a re-render of the outer component to change the aria props
651
-
567
+ });
652
568
 
569
+ // to force a re-render of the outer component to change the aria props
653
570
  _this.props.store.setEditorState(_this.props.store.getEditorState());
654
571
  };
655
-
656
572
  _this.commitSelection = function () {
657
573
  var mention = _this.props.suggestions[_this.state.focusedOptionIndex];
658
-
659
574
  if (!_this.props.store.getIsOpened() || !mention) {
660
575
  return 'not-handled';
661
576
  }
662
-
663
577
  _this.onMentionSelect(mention);
664
-
665
578
  return 'handled';
666
579
  };
667
-
668
580
  _this.openDropdown = function () {
669
581
  // This is a really nasty way of attaching & releasing the key related functions.
670
582
  // It assumes that the keyFunctions object will not loose its reference and
671
583
  // by this we can replace inner parameters spread over different modules.
672
584
  // This better be some registering & unregistering logic. PRs are welcome :)
673
585
  _this.props.callbacks.handleReturn = _this.commitSelection;
674
-
675
586
  _this.props.callbacks.keyBindingFn = function (keyboardEvent) {
676
587
  // arrow down
677
588
  if (keyboardEvent.keyCode === 40) {
678
589
  _this.onDownArrow(keyboardEvent);
679
- } // arrow up
680
-
681
-
590
+ }
591
+ // arrow up
682
592
  if (keyboardEvent.keyCode === 38) {
683
593
  _this.onUpArrow(keyboardEvent);
684
- } // escape
685
-
686
-
594
+ }
595
+ // escape
687
596
  if (keyboardEvent.keyCode === 27) {
688
597
  _this.onEscape(keyboardEvent);
689
- } // tab
690
-
691
-
598
+ }
599
+ // tab
692
600
  if (keyboardEvent.keyCode === 9) {
693
601
  _this.onTab(keyboardEvent);
694
602
  }
695
-
696
603
  return undefined;
697
604
  };
698
-
699
605
  var descendant = "mention-option-" + _this.key + "-" + _this.state.focusedOptionIndex;
700
606
  _this.props.ariaProps.ariaActiveDescendantID = descendant;
701
607
  _this.props.ariaProps.ariaOwneeID = "mentions-list-" + _this.key;
702
608
  _this.props.ariaProps.ariaHasPopup = 'true';
703
609
  _this.props.ariaProps.ariaExpanded = true;
704
-
705
610
  _this.props.onOpenChange(true);
706
611
  };
707
-
708
612
  _this.closeDropdown = function () {
709
613
  // make sure none of these callbacks are triggered
710
614
  _this.props.callbacks.handleReturn = undefined;
@@ -713,37 +617,31 @@ var MentionSuggestions = /*#__PURE__*/function (_Component) {
713
617
  _this.props.ariaProps.ariaExpanded = false;
714
618
  _this.props.ariaProps.ariaActiveDescendantID = undefined;
715
619
  _this.props.ariaProps.ariaOwneeID = undefined;
716
-
717
620
  _this.props.onOpenChange(false);
718
621
  };
719
-
720
622
  _this.props.callbacks.onChange = _this.onEditorStateChange;
721
623
  return _this;
722
624
  }
723
-
724
625
  var _proto = MentionSuggestions.prototype;
725
-
726
626
  _proto.componentDidUpdate = function componentDidUpdate() {
727
627
  if (this.popover) {
728
628
  // In case the list shrinks there should be still an option focused.
729
629
  // Note: this might run multiple times and deduct 1 until the condition is
730
630
  // not fullfilled anymore.
731
631
  var size = this.props.suggestions.length;
732
-
733
632
  if (size > 0 && this.state.focusedOptionIndex >= size) {
734
633
  this.setState({
735
634
  focusedOptionIndex: size - 1
736
635
  });
737
- } // Note: this is a simple protection for the error when componentDidUpdate
636
+ }
637
+
638
+ // Note: this is a simple protection for the error when componentDidUpdate
738
639
  // try to get new getPortalClientRect, but the key already was deleted by
739
640
  // previous action. (right now, it only can happened when set the mention
740
641
  // trigger to be multi-characters which not supported anyway!)
741
-
742
-
743
642
  if (!this.props.store.getAllSearches().has(this.activeOffsetKey)) {
744
643
  return;
745
644
  }
746
-
747
645
  var decoratorRect = this.props.store.getPortalClientRect(this.activeOffsetKey);
748
646
  var positionSuggestions$1 = this.props.positionSuggestions || positionSuggestions;
749
647
  var newStyles = positionSuggestions$1({
@@ -751,49 +649,49 @@ var MentionSuggestions = /*#__PURE__*/function (_Component) {
751
649
  props: this.props,
752
650
  popover: this.popover
753
651
  });
754
-
755
652
  for (var _i = 0, _Object$entries = Object.entries(newStyles); _i < _Object$entries.length; _i++) {
756
653
  var _Object$entries$_i = _Object$entries[_i],
757
- key = _Object$entries$_i[0],
758
- value = _Object$entries$_i[1];
654
+ key = _Object$entries$_i[0],
655
+ value = _Object$entries$_i[1];
759
656
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
760
657
  this.popover.style[key] = value;
761
658
  }
762
659
  }
763
660
  };
764
-
765
661
  _proto.componentWillUnmount = function componentWillUnmount() {
766
662
  this.props.callbacks.onChange = undefined;
767
663
  };
768
-
664
+ _proto.getMentionKey = function getMentionKey(mention, index) {
665
+ if (mention.key != null) return String(mention.key);
666
+ if (mention.id != null) return String(mention.id);
667
+ if (mention.name != null) return mention.name;
668
+ return String(index); // ultimate fallback
669
+ };
769
670
  _proto.render = function render() {
770
671
  var _this2 = this;
771
-
772
672
  if (!this.props.open) {
773
673
  return null;
774
674
  }
775
-
776
675
  var _this$props = this.props,
777
- entryComponent = _this$props.entryComponent,
778
- popoverComponent = _this$props.popoverComponent,
779
- popperOptions = _this$props.popperOptions,
780
- _this$props$popoverCo = _this$props.popoverContainer,
781
- PopoverContainer = _this$props$popoverCo === void 0 ? Popover : _this$props$popoverCo;
782
- _this$props.onOpenChange;
783
- _this$props.onAddMention;
784
- _this$props.onSearchChange;
785
- _this$props.suggestions;
786
- _this$props.ariaProps;
787
- _this$props.callbacks;
788
- var _this$props$theme = _this$props.theme,
789
- theme = _this$props$theme === void 0 ? {} : _this$props$theme;
790
- _this$props.store;
791
- _this$props.entityMutability;
792
- var positionSuggestions = _this$props.positionSuggestions;
793
- _this$props.mentionTriggers;
794
- _this$props.mentionPrefix;
795
- var elementProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
796
-
676
+ entryComponent = _this$props.entryComponent,
677
+ popoverComponent = _this$props.popoverComponent,
678
+ popperOptions = _this$props.popperOptions,
679
+ _this$props$popoverCo = _this$props.popoverContainer,
680
+ PopoverContainer = _this$props$popoverCo === void 0 ? Popover : _this$props$popoverCo;
681
+ _this$props.onOpenChange;
682
+ _this$props.onAddMention;
683
+ _this$props.onSearchChange;
684
+ _this$props.suggestions;
685
+ _this$props.ariaProps;
686
+ _this$props.callbacks;
687
+ var _this$props$theme = _this$props.theme,
688
+ theme = _this$props$theme === void 0 ? {} : _this$props$theme;
689
+ _this$props.store;
690
+ _this$props.entityMutability;
691
+ var positionSuggestions = _this$props.positionSuggestions;
692
+ _this$props.mentionTriggers;
693
+ _this$props.mentionPrefix;
694
+ var elementProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
797
695
  if (popoverComponent || positionSuggestions) {
798
696
  warning('The properties `popoverComponent` and `positionSuggestions` are deprecated and will be removed in @draft-js-plugins/mentions 6.0 . Use `popperOptions` instead');
799
697
  return /*#__PURE__*/React.cloneElement(popoverComponent || /*#__PURE__*/React.createElement("div", null), _extends({}, elementProps, {
@@ -804,8 +702,8 @@ var MentionSuggestions = /*#__PURE__*/function (_Component) {
804
702
  _this2.popover = element;
805
703
  }
806
704
  }), this.props.suggestions.map(function (mention, index) {
807
- return /*#__PURE__*/React.createElement(Entry$1, {
808
- key: mention.id != null ? mention.id : mention.name,
705
+ return /*#__PURE__*/React.createElement(Entry, {
706
+ key: _this2.getMentionKey(mention, index),
809
707
  onMentionSelect: _this2.onMentionSelect,
810
708
  onMentionFocus: _this2.onMentionFocus,
811
709
  isFocused: _this2.state.focusedOptionIndex === index,
@@ -818,18 +716,16 @@ var MentionSuggestions = /*#__PURE__*/function (_Component) {
818
716
  });
819
717
  }));
820
718
  }
821
-
822
719
  if (!this.props.renderEmptyPopup && this.props.suggestions.length === 0) {
823
720
  return null;
824
721
  }
825
-
826
722
  return /*#__PURE__*/React.createElement(PopoverContainer, {
827
723
  store: this.props.store,
828
724
  popperOptions: popperOptions,
829
725
  theme: theme
830
726
  }, this.props.suggestions.map(function (mention, index) {
831
- return /*#__PURE__*/React.createElement(Entry$1, {
832
- key: mention.id != null ? mention.id : mention.name,
727
+ return /*#__PURE__*/React.createElement(Entry, {
728
+ key: _this2.getMentionKey(mention, index),
833
729
  onMentionSelect: _this2.onMentionSelect,
834
730
  onMentionFocus: _this2.onMentionFocus,
835
731
  isFocused: _this2.state.focusedOptionIndex === index,
@@ -842,7 +738,6 @@ var MentionSuggestions = /*#__PURE__*/function (_Component) {
842
738
  });
843
739
  }));
844
740
  };
845
-
846
741
  return MentionSuggestions;
847
742
  }(Component);
848
743
  MentionSuggestions.propTypes = {
@@ -853,36 +748,35 @@ MentionSuggestions.propTypes = {
853
748
  onAddMention: PropTypes.func,
854
749
  suggestions: PropTypes.array.isRequired
855
750
  };
856
- var MentionSuggestions$1 = MentionSuggestions;
857
751
 
858
- var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
752
+ var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
859
753
  function MentionSuggestionsPortal(props) {
860
- var searchPortal = useRef(); // Note: this is a workaround for an obscure issue: https://github.com/draft-js-plugins/draft-js-plugins/pull/667/files
861
- // Ideally we can remove this in the future.
754
+ var searchPortal = useRef();
862
755
 
756
+ // Note: this is a workaround for an obscure issue: https://github.com/draft-js-plugins/draft-js-plugins/pull/667/files
757
+ // Ideally we can remove this in the future.
863
758
  var searchPortalRef = function searchPortalRef(element) {
864
759
  searchPortal.current = element;
865
760
  props.store.setReferenceElement(element);
866
761
  };
867
-
868
762
  var updatePortalClientRect = function updatePortalClientRect(currentProps) {
869
763
  currentProps.store.updatePortalClientRect(currentProps.offsetKey, function () {
870
764
  return searchPortal.current.getBoundingClientRect();
871
765
  });
872
- }; // When inputting Japanese characters (or any complex alphabet which requires
766
+ };
767
+
768
+ // When inputting Japanese characters (or any complex alphabet which requires
873
769
  // hitting enter to commit the characters), that action was causing a race
874
770
  // condition when we used UNSAFE_componentWillMount. By using componentDidMount
875
771
  // instead of UNSAFE_componentWillMount, the component will unmount unregister and
876
772
  // then properly mount and register after. Prior to this change,
877
773
  // UNSAFE_componentWillMount would not fire after componentWillUnmount even though it
878
774
  // was still in the DOM, so it wasn't re-registering the offsetkey.
879
-
880
-
881
775
  useIsomorphicLayoutEffect(function () {
882
776
  props.store.register(props.offsetKey);
883
777
  props.store.setIsOpened(true);
884
- updatePortalClientRect(props); // trigger a re-render so the MentionSuggestions becomes active
885
-
778
+ updatePortalClientRect(props);
779
+ // trigger a re-render so the MentionSuggestions becomes active
886
780
  props.store.setEditorState(props.store.getEditorState());
887
781
  return function () {
888
782
  props.store.unregister(props.offsetKey);
@@ -890,6 +784,12 @@ function MentionSuggestionsPortal(props) {
890
784
  props.store.setReferenceElement(null);
891
785
  };
892
786
  }, []);
787
+ useEffect(function () {
788
+ // Use hook to set reference element. CFR: https://github.com/draft-js-plugins/draft-js-plugins/issues/2966
789
+ if (searchPortal.current) {
790
+ props.store.setReferenceElement(searchPortal.current);
791
+ }
792
+ }, [searchPortal.current]);
893
793
  useEffect(function () {
894
794
  updatePortalClientRect(props);
895
795
  });
@@ -898,19 +798,29 @@ function MentionSuggestionsPortal(props) {
898
798
  }, props.children);
899
799
  }
900
800
 
901
- var defaultRegExp = '[' + '\\w-' + // Latin-1 Supplement (letters only) - https://en.wikipedia.org/wiki/List_of_Unicode_characters#Latin-1_Supplement
902
- "\xC0-\xD6" + "\xD8-\xF6" + "\xF8-\xFF" + // Latin Extended-A (without deprecated character) - https://en.wikipedia.org/wiki/List_of_Unicode_characters#Latin_Extended-A
903
- "\u0100-\u0148" + "\u014A-\u017F" + // Cyrillic symbols: \u0410-\u044F - https://en.wikipedia.org/wiki/Cyrillic_script_in_Unicode
904
- "\u0410-\u044F" + // Symbols that are sometimes used in Japanese names: \u3005-\u3006
905
- "\u3005-\u3006" + // hiragana (japanese): \u3040-\u309F - https://gist.github.com/ryanmcgrath/982242#file-japaneseregex-js
906
- "\u3040-\u309F" + // katakana (japanese): \u30A0-\u30FF - https://gist.github.com/ryanmcgrath/982242#file-japaneseregex-js
907
- "\u30A0-\u30FF" + // For an advanced explaination about Hangul see https://github.com/draft-js-plugins/draft-js-plugins/pull/480#issuecomment-254055437
801
+ var defaultRegExp = '[' + '\\w-' +
802
+ // Latin-1 Supplement (letters only) - https://en.wikipedia.org/wiki/List_of_Unicode_characters#Latin-1_Supplement
803
+ "\xC0-\xD6" + "\xD8-\xF6" + "\xF8-\xFF" +
804
+ // Latin Extended-A (without deprecated character) - https://en.wikipedia.org/wiki/List_of_Unicode_characters#Latin_Extended-A
805
+ "\u0100-\u0148" + "\u014A-\u017F" +
806
+ // Cyrillic symbols: \u0410-\u044F - https://en.wikipedia.org/wiki/Cyrillic_script_in_Unicode
807
+ "\u0410-\u044F" +
808
+ // Symbols that are sometimes used in Japanese names: \u3005-\u3006
809
+ "\u3005-\u3006" +
810
+ // hiragana (japanese): \u3040-\u309F - https://gist.github.com/ryanmcgrath/982242#file-japaneseregex-js
811
+ "\u3040-\u309F" +
812
+ // katakana (japanese): \u30A0-\u30FF - https://gist.github.com/ryanmcgrath/982242#file-japaneseregex-js
813
+ "\u30A0-\u30FF" +
814
+ // For an advanced explaination about Hangul see https://github.com/draft-js-plugins/draft-js-plugins/pull/480#issuecomment-254055437
908
815
  // Hangul Jamo (korean): \u3130-\u318F - https://en.wikipedia.org/wiki/Korean_language_and_computers#Hangul_in_Unicode
909
816
  // Hangul Syllables (korean): \uAC00-\uD7A3 - https://en.wikipedia.org/wiki/Korean_language_and_computers#Hangul_in_Unicode
910
- "\u3130-\u318F" + "\uAC00-\uD7A3" + // common chinese symbols: \u4e00-\u9eff - http://stackoverflow.com/a/1366113/837709
817
+ "\u3130-\u318F" + "\uAC00-\uD7A3" +
818
+ // common chinese symbols: \u4e00-\u9eff - http://stackoverflow.com/a/1366113/837709
911
819
  // extended to \u9fa5 https://github.com/draft-js-plugins/draft-js-plugins/issues/1888
912
- "\u4E00-\u9FA5" + // Arabic https://en.wikipedia.org/wiki/Arabic_(Unicode_block)
913
- "\u0600-\u06FF" + // Vietnamese http://vietunicode.sourceforge.net/charset/
820
+ "\u4E00-\u9FA5" +
821
+ // Arabic https://en.wikipedia.org/wiki/Arabic_(Unicode_block)
822
+ "\u0600-\u06FF" +
823
+ // Vietnamese http://vietunicode.sourceforge.net/charset/
914
824
  "\xC0-\u1EF9" + ']';
915
825
 
916
826
  var defaultTheme = {
@@ -937,74 +847,63 @@ var findMentionEntities = function findMentionEntities(triggers) {
937
847
  };
938
848
  };
939
849
 
940
- var mentionStrategy = findMentionEntities;
941
-
942
850
  var whitespaceRegEx = /\s/;
943
-
944
851
  function checkForWhiteSpaceBeforeTrigger(text, index) {
945
852
  if (index === 0) {
946
853
  return true;
947
854
  }
948
-
949
855
  return whitespaceRegEx.test(text[index - 1]);
950
856
  }
951
-
952
857
  function findInContentBlock(regex, text, nonEntityStart, callback) {
953
858
  var matchArr;
954
859
  var start;
955
- var prevLastIndex = regex.lastIndex; // Go through all matches in the text and return the indices to the callback
956
- // Break the loop if lastIndex is not changed
860
+ var prevLastIndex = regex.lastIndex;
957
861
 
862
+ // Go through all matches in the text and return the indices to the callback
863
+ // Break the loop if lastIndex is not changed
958
864
  while ((matchArr = regex.exec(text)) !== null) {
959
865
  if (regex.lastIndex === prevLastIndex) {
960
866
  break;
961
867
  }
962
-
963
868
  prevLastIndex = regex.lastIndex;
964
869
  start = nonEntityStart + matchArr.index;
965
-
966
870
  var _end = start + matchArr[0].length;
967
-
968
871
  if (whitespaceRegEx.test(text[start])) {
969
872
  //trim the result so that we have no whitespaces
970
873
  start += 1;
971
874
  }
972
-
973
875
  callback(start, _end);
974
876
  }
975
877
  }
976
-
977
878
  function findInContentBlockWithWhitespace(regex, text, nonEntityStart, callback) {
978
879
  var matchArr;
979
880
  var start;
980
- var prevLastIndex = regex.lastIndex; // Go through all matches in the text and return the indices to the callback
981
- // Break the loop if lastIndex is not changed
881
+ var prevLastIndex = regex.lastIndex;
982
882
 
883
+ // Go through all matches in the text and return the indices to the callback
884
+ // Break the loop if lastIndex is not changed
983
885
  while ((matchArr = regex.exec(text)) !== null) {
984
886
  if (regex.lastIndex === prevLastIndex) {
985
887
  break;
986
888
  }
987
-
988
889
  prevLastIndex = regex.lastIndex;
989
890
  start = nonEntityStart + matchArr.index;
891
+ var _end2 = start + matchArr[0].length;
990
892
 
991
- var _end2 = start + matchArr[0].length; //check if whitespace support is active that the char before the trigger is a white space #1844
992
-
993
-
893
+ //check if whitespace support is active that the char before the trigger is a white space #1844
994
894
  if (checkForWhiteSpaceBeforeTrigger(text, matchArr.index)) {
995
895
  callback(start, _end2);
996
896
  }
997
897
  }
998
898
  }
999
-
1000
899
  var findWithRegex = function findWithRegex(regex, contentBlock, supportWhiteSpace, callback) {
1001
- var contentBlockText = contentBlock.getText(); // exclude entities, when matching
900
+ var contentBlockText = contentBlock.getText();
1002
901
 
902
+ // exclude entities, when matching
1003
903
  contentBlock.findEntityRanges(function (character) {
1004
904
  return !character.getEntity();
1005
905
  }, function (nonEntityStart, nonEntityEnd) {
1006
906
  var text = contentBlockText.slice(nonEntityStart, nonEntityEnd);
1007
-
1008
907
  if (supportWhiteSpace) {
1009
908
  findInContentBlockWithWhitespace(regex, text, nonEntityStart, callback);
1010
909
  } else {
@@ -1012,7 +911,6 @@ var findWithRegex = function findWithRegex(regex, contentBlock, supportWhiteSpac
1012
911
  }
1013
912
  });
1014
913
  };
1015
-
1016
914
  var mentionSuggestionsStrategy = (function (triggers, supportWhiteSpace, regExp) {
1017
915
  var triggerPattern = "(" + triggers.map(function (trigger) {
1018
916
  return escapeRegExp(trigger);
@@ -1024,6 +922,7 @@ var mentionSuggestionsStrategy = (function (triggers, supportWhiteSpace, regExp)
1024
922
  });
1025
923
 
1026
924
  // Get the first 5 suggestions that match
925
+
1027
926
  var defaultSuggestionsFilter$1 = function defaultSuggestionsFilter(searchValue, suggestions, trigger) {
1028
927
  var value = searchValue.toLowerCase();
1029
928
  var triggerSuggestions = trigger && !Array.isArray(suggestions) ? suggestions[trigger] : suggestions;
@@ -1034,13 +933,10 @@ var defaultSuggestionsFilter$1 = function defaultSuggestionsFilter(searchValue,
1034
933
  return filteredSuggestions.slice(0, length);
1035
934
  };
1036
935
 
1037
- var suggestionsFilter = defaultSuggestionsFilter$1;
1038
-
1039
936
  var index = (function (config) {
1040
937
  if (config === void 0) {
1041
938
  config = {};
1042
939
  }
1043
-
1044
940
  var callbacks = {
1045
941
  keyBindingFn: undefined,
1046
942
  handleKeyCommand: undefined,
@@ -1098,31 +994,32 @@ var index = (function (config) {
1098
994
  setReferenceElement: function setReferenceElement(element) {
1099
995
  referenceElement = element;
1100
996
  }
1101
- }; // Styles are overwritten instead of merged as merging causes a lot of confusion.
997
+ };
998
+
999
+ // Styles are overwritten instead of merged as merging causes a lot of confusion.
1102
1000
  //
1103
1001
  // Why? Because when merging a developer needs to know all of the underlying
1104
1002
  // styles which needs a deep dive into the code. Merging also makes it prone to
1105
1003
  // errors when upgrading as basically every styling change would become a major
1106
1004
  // breaking change. 1px of an increased padding can break a whole layout.
1107
-
1108
1005
  var _config = config,
1109
- _config$mentionPrefix = _config.mentionPrefix,
1110
- mentionPrefix = _config$mentionPrefix === void 0 ? '' : _config$mentionPrefix,
1111
- _config$theme = _config.theme,
1112
- theme = _config$theme === void 0 ? defaultTheme : _config$theme,
1113
- positionSuggestions = _config.positionSuggestions,
1114
- mentionComponent = _config.mentionComponent,
1115
- _config$mentionSugges = _config.mentionSuggestionsComponent,
1116
- MentionSuggestionsComponent = _config$mentionSugges === void 0 ? MentionSuggestions$1 : _config$mentionSugges,
1117
- _config$entityMutabil = _config.entityMutability,
1118
- entityMutability = _config$entityMutabil === void 0 ? 'SEGMENTED' : _config$entityMutabil,
1119
- _config$mentionTrigge = _config.mentionTrigger,
1120
- mentionTrigger = _config$mentionTrigge === void 0 ? '@' : _config$mentionTrigge,
1121
- _config$mentionRegExp = _config.mentionRegExp,
1122
- mentionRegExp = _config$mentionRegExp === void 0 ? defaultRegExp : _config$mentionRegExp,
1123
- _config$supportWhites = _config.supportWhitespace,
1124
- supportWhitespace = _config$supportWhites === void 0 ? false : _config$supportWhites,
1125
- popperOptions = _config.popperOptions;
1006
+ _config$mentionPrefix = _config.mentionPrefix,
1007
+ mentionPrefix = _config$mentionPrefix === void 0 ? '' : _config$mentionPrefix,
1008
+ _config$theme = _config.theme,
1009
+ theme = _config$theme === void 0 ? defaultTheme : _config$theme,
1010
+ positionSuggestions = _config.positionSuggestions,
1011
+ mentionComponent = _config.mentionComponent,
1012
+ _config$mentionSugges = _config.mentionSuggestionsComponent,
1013
+ MentionSuggestionsComponent = _config$mentionSugges === void 0 ? MentionSuggestions : _config$mentionSugges,
1014
+ _config$entityMutabil = _config.entityMutability,
1015
+ entityMutability = _config$entityMutabil === void 0 ? 'SEGMENTED' : _config$entityMutabil,
1016
+ _config$mentionTrigge = _config.mentionTrigger,
1017
+ mentionTrigger = _config$mentionTrigge === void 0 ? '@' : _config$mentionTrigge,
1018
+ _config$mentionRegExp = _config.mentionRegExp,
1019
+ mentionRegExp = _config$mentionRegExp === void 0 ? defaultRegExp : _config$mentionRegExp,
1020
+ _config$supportWhites = _config.supportWhitespace,
1021
+ supportWhitespace = _config$supportWhites === void 0 ? false : _config$supportWhites,
1022
+ popperOptions = _config.popperOptions;
1126
1023
  var mentionTriggers = typeof mentionTrigger === 'string' ? [mentionTrigger] : mentionTrigger;
1127
1024
  var mentionSearchProps = {
1128
1025
  ariaProps: ariaProps,
@@ -1135,28 +1032,24 @@ var index = (function (config) {
1135
1032
  mentionPrefix: mentionPrefix,
1136
1033
  popperOptions: popperOptions
1137
1034
  };
1138
-
1139
1035
  var DecoratedMentionSuggestionsComponent = function DecoratedMentionSuggestionsComponent(props) {
1140
1036
  return /*#__PURE__*/React.createElement(MentionSuggestionsComponent, _extends({}, props, mentionSearchProps));
1141
1037
  };
1142
-
1143
1038
  var DecoratedMention = function DecoratedMention(props) {
1144
1039
  return /*#__PURE__*/React.createElement(Mention, _extends({}, props, {
1145
1040
  theme: theme,
1146
1041
  mentionComponent: mentionComponent
1147
1042
  }));
1148
1043
  };
1149
-
1150
1044
  var DecoratedMentionSuggestionsPortal = function DecoratedMentionSuggestionsPortal(props) {
1151
1045
  return /*#__PURE__*/React.createElement(MentionSuggestionsPortal, _extends({}, props, {
1152
1046
  store: store
1153
1047
  }));
1154
1048
  };
1155
-
1156
1049
  return {
1157
1050
  MentionSuggestions: DecoratedMentionSuggestionsComponent,
1158
1051
  decorators: [{
1159
- strategy: mentionStrategy(mentionTriggers),
1052
+ strategy: findMentionEntities(mentionTriggers),
1160
1053
  component: DecoratedMention
1161
1054
  }, {
1162
1055
  strategy: mentionSuggestionsStrategy(mentionTriggers, supportWhitespace, mentionRegExp),
@@ -1174,7 +1067,7 @@ var index = (function (config) {
1174
1067
  },
1175
1068
  initialize: function initialize(_ref) {
1176
1069
  var getEditorState = _ref.getEditorState,
1177
- setEditorState = _ref.setEditorState;
1070
+ setEditorState = _ref.setEditorState;
1178
1071
  store.getEditorState = getEditorState;
1179
1072
  store.setEditorState = setEditorState;
1180
1073
  },
@@ -1188,11 +1081,10 @@ var index = (function (config) {
1188
1081
  if (callbacks.onChange) {
1189
1082
  return callbacks.onChange(editorState);
1190
1083
  }
1191
-
1192
1084
  return editorState;
1193
1085
  }
1194
1086
  };
1195
1087
  });
1196
- var defaultSuggestionsFilter = suggestionsFilter;
1088
+ var defaultSuggestionsFilter = defaultSuggestionsFilter$1;
1197
1089
 
1198
- export { MentionSuggestions$1 as MentionSuggestions, Popover, addMention, index as default, defaultSuggestionsFilter, defaultTheme };
1090
+ export { MentionSuggestions, Popover, addMention, index as default, defaultSuggestionsFilter, defaultTheme };