@ni/spright-components 5.5.4 → 6.0.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.
@@ -5264,7 +5264,7 @@
5264
5264
  * Returns all displayed elements inside of a root node that match a provided selector
5265
5265
  */
5266
5266
  function getDisplayedNodes(rootNode, selector) {
5267
- if (!rootNode || false || !isHTMLElement(rootNode)) {
5267
+ if (!rootNode || !selector || !isHTMLElement(rootNode)) {
5268
5268
  return;
5269
5269
  }
5270
5270
  const nodes = Array.from(rootNode.querySelectorAll(selector));
@@ -11497,7 +11497,7 @@
11497
11497
  */
11498
11498
  getValidValue(value) {
11499
11499
  var _a, _b;
11500
- let validValue = parseFloat(parseFloat(value).toPrecision(12));
11500
+ let validValue = parseFloat(parseFloat(value).toPrecision(15));
11501
11501
  if (isNaN(validValue)) {
11502
11502
  validValue = "";
11503
11503
  }
@@ -27607,7 +27607,7 @@ so this becomes the fallback color for the slot */ ''}
27607
27607
  position in this fragment. The result object will be reused
27608
27608
  (overwritten) the next time the function is called. @internal
27609
27609
  */
27610
- findIndex(pos, round = -1) {
27610
+ findIndex(pos) {
27611
27611
  if (pos == 0)
27612
27612
  return retIndex(0, pos);
27613
27613
  if (pos == this.size)
@@ -27617,7 +27617,7 @@ so this becomes the fallback color for the slot */ ''}
27617
27617
  for (let i = 0, curPos = 0;; i++) {
27618
27618
  let cur = this.child(i), end = curPos + cur.nodeSize;
27619
27619
  if (end >= pos) {
27620
- if (end == pos || round > 0)
27620
+ if (end == pos)
27621
27621
  return retIndex(i + 1, end);
27622
27622
  return retIndex(i, curPos);
27623
27623
  }
@@ -28578,7 +28578,7 @@ so this becomes the fallback color for the slot */ ''}
28578
28578
  `blockSeparator` is given, it will be inserted to separate text
28579
28579
  from different block nodes. If `leafText` is given, it'll be
28580
28580
  inserted for every non-text leaf node encountered, otherwise
28581
- [`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec^leafText) will be used.
28581
+ [`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec.leafText) will be used.
28582
28582
  */
28583
28583
  textBetween(from, to, blockSeparator, leafText) {
28584
28584
  return this.content.textBetween(from, to, blockSeparator, leafText);
@@ -29788,8 +29788,8 @@ so this becomes the fallback color for the slot */ ''}
29788
29788
  let type = this.marks[prop], excl = type.spec.excludes;
29789
29789
  type.excluded = excl == null ? [type] : excl == "" ? [] : gatherMarks(this, excl.split(" "));
29790
29790
  }
29791
- this.nodeFromJSON = this.nodeFromJSON.bind(this);
29792
- this.markFromJSON = this.markFromJSON.bind(this);
29791
+ this.nodeFromJSON = json => Node$2.fromJSON(this, json);
29792
+ this.markFromJSON = json => Mark$1.fromJSON(this, json);
29793
29793
  this.topNodeType = this.nodes[this.spec.topNode || "doc"];
29794
29794
  this.cached.wrappings = Object.create(null);
29795
29795
  }
@@ -29825,20 +29825,6 @@ so this becomes the fallback color for the slot */ ''}
29825
29825
  return type.create(attrs);
29826
29826
  }
29827
29827
  /**
29828
- Deserialize a node from its JSON representation. This method is
29829
- bound.
29830
- */
29831
- nodeFromJSON(json) {
29832
- return Node$2.fromJSON(this, json);
29833
- }
29834
- /**
29835
- Deserialize a mark from its JSON representation. This method is
29836
- bound.
29837
- */
29838
- markFromJSON(json) {
29839
- return Mark$1.fromJSON(this, json);
29840
- }
29841
- /**
29842
29828
  @internal
29843
29829
  */
29844
29830
  nodeType(name) {
@@ -30020,7 +30006,7 @@ so this becomes the fallback color for the slot */ ''}
30020
30006
  /**
30021
30007
  Construct a DOM parser using the parsing rules listed in a
30022
30008
  schema's [node specs](https://prosemirror.net/docs/ref/#model.NodeSpec.parseDOM), reordered by
30023
- [priority](https://prosemirror.net/docs/ref/#model.ParseRule.priority).
30009
+ [priority](https://prosemirror.net/docs/ref/#model.GenericParseRule.priority).
30024
30010
  */
30025
30011
  static fromSchema(schema) {
30026
30012
  return schema.cached.domParser ||
@@ -30044,7 +30030,7 @@ so this becomes the fallback color for the slot */ ''}
30044
30030
  if (preserveWhitespace != null)
30045
30031
  return (preserveWhitespace ? OPT_PRESERVE_WS : 0) |
30046
30032
  (preserveWhitespace === "full" ? OPT_PRESERVE_WS_FULL : 0);
30047
- return type && type.whitespace == "pre" ? OPT_PRESERVE_WS | OPT_PRESERVE_WS_FULL : base & -5;
30033
+ return type && type.whitespace == "pre" ? OPT_PRESERVE_WS | OPT_PRESERVE_WS_FULL : base & ~OPT_OPEN_LEFT;
30048
30034
  }
30049
30035
  class NodeContext {
30050
30036
  constructor(type, attrs, marks, solid, match, options) {
@@ -30771,6 +30757,8 @@ so this becomes the fallback color for the slot */ ''}
30771
30757
  let space = name.indexOf(" ");
30772
30758
  if (space > 0)
30773
30759
  dom.setAttributeNS(name.slice(0, space), name.slice(space + 1), attrs[name]);
30760
+ else if (name == "style" && dom.style)
30761
+ dom.style.cssText = attrs[name];
30774
30762
  else
30775
30763
  dom.setAttribute(name, attrs[name]);
30776
30764
  }
@@ -33480,7 +33468,7 @@ so this becomes the fallback color for the slot */ ''}
33480
33468
  throw new RangeError("Selection passed to setSelection must point at the current document");
33481
33469
  this.curSelection = selection;
33482
33470
  this.curSelectionFor = this.steps.length;
33483
- this.updated = (this.updated | UPDATED_SEL) & -3;
33471
+ this.updated = (this.updated | UPDATED_SEL) & ~UPDATED_MARKS;
33484
33472
  this.storedMarks = null;
33485
33473
  return this;
33486
33474
  }
@@ -33531,7 +33519,7 @@ so this becomes the fallback color for the slot */ ''}
33531
33519
  */
33532
33520
  addStep(step, doc) {
33533
33521
  super.addStep(step, doc);
33534
- this.updated = this.updated & -3;
33522
+ this.updated = this.updated & ~UPDATED_MARKS;
33535
33523
  this.storedMarks = null;
33536
33524
  }
33537
33525
  /**
@@ -41877,7 +41865,7 @@ so this becomes the fallback color for the slot */ ''}
41877
41865
  dropEvent = event;
41878
41866
  if (!isDroppedFromProseMirror) {
41879
41867
  const dragFromOtherEditor = tiptapDragFromOtherEditor;
41880
- if (dragFromOtherEditor) {
41868
+ if (dragFromOtherEditor === null || dragFromOtherEditor === void 0 ? void 0 : dragFromOtherEditor.isEditable) {
41881
41869
  // setTimeout to avoid the wrong content after drop, timeout arg can't be empty or 0
41882
41870
  setTimeout(() => {
41883
41871
  const selection = dragFromOtherEditor.state.selection;
@@ -42428,7 +42416,7 @@ so this becomes the fallback color for the slot */ ''}
42428
42416
  tr.deleteRange(originRange.from, originRange.to);
42429
42417
  const newPos = tr.mapping.map(targetPos);
42430
42418
  tr.insert(newPos, contentSlice.content);
42431
- tr.setSelection(new TextSelection(tr.doc.resolve(newPos - 1)));
42419
+ tr.setSelection(new TextSelection(tr.doc.resolve(Math.max(newPos - 1, 0))));
42432
42420
  return true;
42433
42421
  };
42434
42422
 
@@ -42860,25 +42848,42 @@ so this becomes the fallback color for the slot */ ''}
42860
42848
  ...options,
42861
42849
  };
42862
42850
  let content;
42863
- try {
42864
- content = createNodeFromContent(value, editor.schema, {
42865
- parseOptions: {
42866
- preserveWhitespace: 'full',
42867
- ...options.parseOptions,
42868
- },
42869
- errorOnInvalidContent: (_a = options.errorOnInvalidContent) !== null && _a !== void 0 ? _a : editor.options.enableContentCheck,
42870
- });
42871
- }
42872
- catch (e) {
42851
+ const emitContentError = (error) => {
42873
42852
  editor.emit('contentError', {
42874
42853
  editor,
42875
- error: e,
42854
+ error,
42876
42855
  disableCollaboration: () => {
42877
42856
  if (editor.storage.collaboration) {
42878
42857
  editor.storage.collaboration.isDisabled = true;
42879
42858
  }
42880
42859
  },
42881
42860
  });
42861
+ };
42862
+ const parseOptions = {
42863
+ preserveWhitespace: 'full',
42864
+ ...options.parseOptions,
42865
+ };
42866
+ // If `emitContentError` is enabled, we want to check the content for errors
42867
+ // but ignore them (do not remove the invalid content from the document)
42868
+ if (!options.errorOnInvalidContent && !editor.options.enableContentCheck && editor.options.emitContentError) {
42869
+ try {
42870
+ createNodeFromContent(value, editor.schema, {
42871
+ parseOptions,
42872
+ errorOnInvalidContent: true,
42873
+ });
42874
+ }
42875
+ catch (e) {
42876
+ emitContentError(e);
42877
+ }
42878
+ }
42879
+ try {
42880
+ content = createNodeFromContent(value, editor.schema, {
42881
+ parseOptions,
42882
+ errorOnInvalidContent: (_a = options.errorOnInvalidContent) !== null && _a !== void 0 ? _a : editor.options.enableContentCheck,
42883
+ });
42884
+ }
42885
+ catch (e) {
42886
+ emitContentError(e);
42882
42887
  return false;
42883
42888
  }
42884
42889
  let { from, to } = typeof position === 'number' ? { from: position, to: position } : { from: position.from, to: position.to };
@@ -44705,6 +44710,10 @@ so this becomes the fallback color for the slot */ ''}
44705
44710
  const isBlock = node.isBlock && !node.isTextblock;
44706
44711
  const isNonTextAtom = node.isAtom && !node.isText;
44707
44712
  const targetPos = this.pos + offset + (isNonTextAtom ? 0 : 1);
44713
+ // Check if targetPos is within valid document range
44714
+ if (targetPos < 0 || targetPos > this.resolvedPos.doc.nodeSize - 2) {
44715
+ return;
44716
+ }
44708
44717
  const $pos = this.resolvedPos.doc.resolve(targetPos);
44709
44718
  if (!isBlock && $pos.depth <= this.depth) {
44710
44719
  return;
@@ -44904,6 +44913,7 @@ img.ProseMirror-separator {
44904
44913
  enablePasteRules: true,
44905
44914
  enableCoreExtensions: true,
44906
44915
  enableContentCheck: false,
44916
+ emitContentError: false,
44907
44917
  onBeforeCreate: () => null,
44908
44918
  onCreate: () => null,
44909
44919
  onUpdate: () => null,
@@ -58923,6 +58933,13 @@ img.ProseMirror-separator {
58923
58933
  return filtered;
58924
58934
  }
58925
58935
 
58936
+ // From DOMPurify
58937
+ // https://github.com/cure53/DOMPurify/blob/main/src/regexp.ts
58938
+ const UNICODE_WHITESPACE_PATTERN = '[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]';
58939
+ const UNICODE_WHITESPACE_REGEX = new RegExp(UNICODE_WHITESPACE_PATTERN);
58940
+ const UNICODE_WHITESPACE_REGEX_END = new RegExp(`${UNICODE_WHITESPACE_PATTERN}$`);
58941
+ const UNICODE_WHITESPACE_REGEX_GLOBAL = new RegExp(UNICODE_WHITESPACE_PATTERN, 'g');
58942
+
58926
58943
  /**
58927
58944
  * Check if the provided tokens form a valid link structure, which can either be a single link token
58928
58945
  * or a link token surrounded by parentheses or square brackets.
@@ -58979,14 +58996,16 @@ img.ProseMirror-separator {
58979
58996
  textBlock = nodesInChangedRanges[0];
58980
58997
  textBeforeWhitespace = newState.doc.textBetween(textBlock.pos, textBlock.pos + textBlock.node.nodeSize, undefined, ' ');
58981
58998
  }
58982
- else if (nodesInChangedRanges.length
58983
- // We want to make sure to include the block seperator argument to treat hard breaks like spaces.
58984
- && newState.doc.textBetween(newRange.from, newRange.to, ' ', ' ').endsWith(' ')) {
58999
+ else if (nodesInChangedRanges.length) {
59000
+ const endText = newState.doc.textBetween(newRange.from, newRange.to, ' ', ' ');
59001
+ if (!UNICODE_WHITESPACE_REGEX_END.test(endText)) {
59002
+ return;
59003
+ }
58985
59004
  textBlock = nodesInChangedRanges[0];
58986
59005
  textBeforeWhitespace = newState.doc.textBetween(textBlock.pos, newRange.to, undefined, ' ');
58987
59006
  }
58988
59007
  if (textBlock && textBeforeWhitespace) {
58989
- const wordsBeforeWhitespace = textBeforeWhitespace.split(' ').filter(s => s !== '');
59008
+ const wordsBeforeWhitespace = textBeforeWhitespace.split(UNICODE_WHITESPACE_REGEX).filter(Boolean);
58990
59009
  if (wordsBeforeWhitespace.length <= 0) {
58991
59010
  return false;
58992
59011
  }
@@ -59098,10 +59117,6 @@ img.ProseMirror-separator {
59098
59117
  },
59099
59118
  });
59100
59119
  }
59101
- // From DOMPurify
59102
- // https://github.com/cure53/DOMPurify/blob/main/src/regexp.js
59103
- // eslint-disable-next-line no-control-regex
59104
- const ATTR_WHITESPACE = /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g;
59105
59120
  function isAllowedUri(uri, protocols) {
59106
59121
  const allowedProtocols = [
59107
59122
  'http',
@@ -59124,9 +59139,7 @@ img.ProseMirror-separator {
59124
59139
  });
59125
59140
  }
59126
59141
  return (!uri
59127
- || uri
59128
- .replace(ATTR_WHITESPACE, '')
59129
- .match(new RegExp(
59142
+ || uri.replace(UNICODE_WHITESPACE_REGEX_GLOBAL, '').match(new RegExp(
59130
59143
  // eslint-disable-next-line no-useless-escape
59131
59144
  `^(?:(?:${allowedProtocols.join('|')}):|[^a-z]|[a-z0-9+.\-]+(?:[^a-z+.\-:]|$))`, 'i')));
59132
59145
  }
@@ -59421,7 +59434,7 @@ img.ProseMirror-separator {
59421
59434
  * This utility allows you to create suggestions.
59422
59435
  * @see https://tiptap.dev/api/utilities/suggestion
59423
59436
  */
59424
- function Suggestion({ pluginKey = SuggestionPluginKey, editor, char = '@', allowSpaces = false, allowToIncludeChar = false, allowedPrefixes = [' '], startOfLine = false, decorationTag = 'span', decorationClass = 'suggestion', command = () => null, items = () => [], render = () => ({}), allow = () => true, findSuggestionMatch: findSuggestionMatch$1 = findSuggestionMatch, }) {
59437
+ function Suggestion({ pluginKey = SuggestionPluginKey, editor, char = '@', allowSpaces = false, allowToIncludeChar = false, allowedPrefixes = [' '], startOfLine = false, decorationTag = 'span', decorationClass = 'suggestion', decorationContent = '', decorationEmptyClass = 'is-empty', command = () => null, items = () => [], render = () => ({}), allow = () => true, findSuggestionMatch: findSuggestionMatch$1 = findSuggestionMatch, }) {
59425
59438
  let props;
59426
59439
  const renderer = render === null || render === void 0 ? void 0 : render();
59427
59440
  const plugin = new Plugin({
@@ -59531,7 +59544,9 @@ img.ProseMirror-separator {
59531
59544
  // * a composition is active (see: https://github.com/ueberdosis/tiptap/issues/1449)
59532
59545
  if (isEditable && (empty || editor.view.composing)) {
59533
59546
  // Reset active state if we just left the previous suggestion range
59534
- if ((from < prev.range.from || from > prev.range.to) && !composing && !prev.composing) {
59547
+ if ((from < prev.range.from || from > prev.range.to)
59548
+ && !composing
59549
+ && !prev.composing) {
59535
59550
  next.active = false;
59536
59551
  }
59537
59552
  // Try to match against where our cursor currently is
@@ -59545,11 +59560,17 @@ img.ProseMirror-separator {
59545
59560
  });
59546
59561
  const decorationId = `id_${Math.floor(Math.random() * 0xffffffff)}`;
59547
59562
  // If we found a match, update the current state to show it
59548
- if (match && allow({
59549
- editor, state, range: match.range, isActive: prev.active,
59550
- })) {
59563
+ if (match
59564
+ && allow({
59565
+ editor,
59566
+ state,
59567
+ range: match.range,
59568
+ isActive: prev.active,
59569
+ })) {
59551
59570
  next.active = true;
59552
- next.decorationId = prev.decorationId ? prev.decorationId : decorationId;
59571
+ next.decorationId = prev.decorationId
59572
+ ? prev.decorationId
59573
+ : decorationId;
59553
59574
  next.range = match.range;
59554
59575
  next.query = match.query;
59555
59576
  next.text = match.text;
@@ -59583,15 +59604,21 @@ img.ProseMirror-separator {
59583
59604
  },
59584
59605
  // Setup decorator on the currently active suggestion.
59585
59606
  decorations(state) {
59586
- const { active, range, decorationId } = plugin.getState(state);
59607
+ const { active, range, decorationId, query, } = plugin.getState(state);
59587
59608
  if (!active) {
59588
59609
  return null;
59589
59610
  }
59611
+ const isEmpty = !(query === null || query === void 0 ? void 0 : query.length);
59612
+ const classNames = [decorationClass];
59613
+ if (isEmpty) {
59614
+ classNames.push(decorationEmptyClass);
59615
+ }
59590
59616
  return DecorationSet.create(state.doc, [
59591
59617
  Decoration.inline(range.from, range.to, {
59592
59618
  nodeName: decorationTag,
59593
- class: decorationClass,
59619
+ class: classNames.join(' '),
59594
59620
  'data-decoration-id': decorationId,
59621
+ 'data-decoration-content': decorationContent,
59595
59622
  }),
59596
59623
  ]);
59597
59624
  },
@@ -59601,10 +59628,91 @@ img.ProseMirror-separator {
59601
59628
  }
59602
59629
 
59603
59630
  /**
59604
- * The plugin key for the mention plugin.
59605
- * @default 'mention'
59631
+ * Returns the suggestion options for a trigger of the Mention extension. These
59632
+ * options are used to create a `Suggestion` ProseMirror plugin. Each plugin lets
59633
+ * you define a different trigger that opens the Mention menu. For example,
59634
+ * you can define a `@` trigger to mention users and a `#` trigger to mention
59635
+ * tags.
59636
+ *
59637
+ * @param param0 The configured options for the suggestion
59638
+ * @returns
59606
59639
  */
59607
- const MentionPluginKey = new PluginKey('mention');
59640
+ function getSuggestionOptions({ editor: tiptapEditor, overrideSuggestionOptions, extensionName, char = '@', }) {
59641
+ const pluginKey = new PluginKey();
59642
+ return {
59643
+ editor: tiptapEditor,
59644
+ char,
59645
+ pluginKey,
59646
+ command: ({ editor, range, props }) => {
59647
+ var _a, _b, _c;
59648
+ // increase range.to by one when the next node is of type "text"
59649
+ // and starts with a space character
59650
+ const nodeAfter = editor.view.state.selection.$to.nodeAfter;
59651
+ const overrideSpace = (_a = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.text) === null || _a === void 0 ? void 0 : _a.startsWith(' ');
59652
+ if (overrideSpace) {
59653
+ range.to += 1;
59654
+ }
59655
+ editor
59656
+ .chain()
59657
+ .focus()
59658
+ .insertContentAt(range, [
59659
+ {
59660
+ type: extensionName,
59661
+ attrs: { ...props, mentionSuggestionChar: char },
59662
+ },
59663
+ {
59664
+ type: 'text',
59665
+ text: ' ',
59666
+ },
59667
+ ])
59668
+ .run();
59669
+ // get reference to `window` object from editor element, to support cross-frame JS usage
59670
+ (_c = (_b = editor.view.dom.ownerDocument.defaultView) === null || _b === void 0 ? void 0 : _b.getSelection()) === null || _c === void 0 ? void 0 : _c.collapseToEnd();
59671
+ },
59672
+ allow: ({ state, range }) => {
59673
+ const $from = state.doc.resolve(range.from);
59674
+ const type = state.schema.nodes[extensionName];
59675
+ const allow = !!$from.parent.type.contentMatch.matchType(type);
59676
+ return allow;
59677
+ },
59678
+ ...overrideSuggestionOptions,
59679
+ };
59680
+ }
59681
+
59682
+ /**
59683
+ * Returns the suggestions for the mention extension.
59684
+ *
59685
+ * @param options The extension options
59686
+ * @returns the suggestions
59687
+ */
59688
+ function getSuggestions(options) {
59689
+ return (options.options.suggestions.length ? options.options.suggestions : [options.options.suggestion]).map(suggestion => getSuggestionOptions({
59690
+ // @ts-ignore `editor` can be `undefined` when converting the document to HTML with the HTML utility
59691
+ editor: options.editor,
59692
+ overrideSuggestionOptions: suggestion,
59693
+ extensionName: options.name,
59694
+ char: suggestion.char,
59695
+ }));
59696
+ }
59697
+ /**
59698
+ * Returns the suggestion options of the mention that has a given character trigger. If not
59699
+ * found, it returns the first suggestion.
59700
+ *
59701
+ * @param options The extension options
59702
+ * @param char The character that triggers the mention
59703
+ * @returns The suggestion options
59704
+ */
59705
+ function getSuggestionFromChar(options, char) {
59706
+ const suggestions = getSuggestions(options);
59707
+ const suggestion = suggestions.find(s => s.char === char);
59708
+ if (suggestion) {
59709
+ return suggestion;
59710
+ }
59711
+ if (suggestions.length) {
59712
+ return suggestions[0];
59713
+ }
59714
+ return null;
59715
+ }
59608
59716
  /**
59609
59717
  * This extension allows you to insert mentions into the editor.
59610
59718
  * @see https://www.tiptap.dev/api/extensions/mention
@@ -59615,55 +59723,21 @@ img.ProseMirror-separator {
59615
59723
  addOptions() {
59616
59724
  return {
59617
59725
  HTMLAttributes: {},
59618
- renderText({ options, node }) {
59619
- var _a;
59620
- return `${options.suggestion.char}${(_a = node.attrs.label) !== null && _a !== void 0 ? _a : node.attrs.id}`;
59726
+ renderText({ node, suggestion }) {
59727
+ var _a, _b;
59728
+ return `${(_a = suggestion === null || suggestion === void 0 ? void 0 : suggestion.char) !== null && _a !== void 0 ? _a : '@'}${(_b = node.attrs.label) !== null && _b !== void 0 ? _b : node.attrs.id}`;
59621
59729
  },
59622
59730
  deleteTriggerWithBackspace: false,
59623
- renderHTML({ options, node }) {
59624
- var _a;
59731
+ renderHTML({ options, node, suggestion }) {
59732
+ var _a, _b;
59625
59733
  return [
59626
59734
  'span',
59627
59735
  mergeAttributes(this.HTMLAttributes, options.HTMLAttributes),
59628
- `${options.suggestion.char}${(_a = node.attrs.label) !== null && _a !== void 0 ? _a : node.attrs.id}`,
59736
+ `${(_a = suggestion === null || suggestion === void 0 ? void 0 : suggestion.char) !== null && _a !== void 0 ? _a : '@'}${(_b = node.attrs.label) !== null && _b !== void 0 ? _b : node.attrs.id}`,
59629
59737
  ];
59630
59738
  },
59631
- suggestion: {
59632
- char: '@',
59633
- pluginKey: MentionPluginKey,
59634
- command: ({ editor, range, props }) => {
59635
- var _a, _b, _c;
59636
- // increase range.to by one when the next node is of type "text"
59637
- // and starts with a space character
59638
- const nodeAfter = editor.view.state.selection.$to.nodeAfter;
59639
- const overrideSpace = (_a = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.text) === null || _a === void 0 ? void 0 : _a.startsWith(' ');
59640
- if (overrideSpace) {
59641
- range.to += 1;
59642
- }
59643
- editor
59644
- .chain()
59645
- .focus()
59646
- .insertContentAt(range, [
59647
- {
59648
- type: this.name,
59649
- attrs: props,
59650
- },
59651
- {
59652
- type: 'text',
59653
- text: ' ',
59654
- },
59655
- ])
59656
- .run();
59657
- // get reference to `window` object from editor element, to support cross-frame JS usage
59658
- (_c = (_b = editor.view.dom.ownerDocument.defaultView) === null || _b === void 0 ? void 0 : _b.getSelection()) === null || _c === void 0 ? void 0 : _c.collapseToEnd();
59659
- },
59660
- allow: ({ state, range }) => {
59661
- const $from = state.doc.resolve(range.from);
59662
- const type = state.schema.nodes[this.name];
59663
- const allow = !!$from.parent.type.contentMatch.matchType(type);
59664
- return allow;
59665
- },
59666
- },
59739
+ suggestions: [],
59740
+ suggestion: {},
59667
59741
  };
59668
59742
  },
59669
59743
  group: 'inline',
@@ -59696,6 +59770,16 @@ img.ProseMirror-separator {
59696
59770
  };
59697
59771
  },
59698
59772
  },
59773
+ // When there are multiple types of mentions, this attribute helps distinguish them
59774
+ mentionSuggestionChar: {
59775
+ default: '@',
59776
+ parseHTML: element => element.getAttribute('data-mention-suggestion-char'),
59777
+ renderHTML: attributes => {
59778
+ return {
59779
+ 'data-mention-suggestion-char': attributes.mentionSuggestionChar,
59780
+ };
59781
+ },
59782
+ },
59699
59783
  };
59700
59784
  },
59701
59785
  parseHTML() {
@@ -59706,6 +59790,7 @@ img.ProseMirror-separator {
59706
59790
  ];
59707
59791
  },
59708
59792
  renderHTML({ node, HTMLAttributes }) {
59793
+ const suggestion = getSuggestionFromChar(this, node.attrs.mentionSuggestionChar);
59709
59794
  if (this.options.renderLabel !== undefined) {
59710
59795
  console.warn('renderLabel is deprecated use renderText and renderHTML instead');
59711
59796
  return [
@@ -59714,6 +59799,7 @@ img.ProseMirror-separator {
59714
59799
  this.options.renderLabel({
59715
59800
  options: this.options,
59716
59801
  node,
59802
+ suggestion,
59717
59803
  }),
59718
59804
  ];
59719
59805
  }
@@ -59722,6 +59808,7 @@ img.ProseMirror-separator {
59722
59808
  const html = this.options.renderHTML({
59723
59809
  options: mergedOptions,
59724
59810
  node,
59811
+ suggestion,
59725
59812
  });
59726
59813
  if (typeof html === 'string') {
59727
59814
  return [
@@ -59733,17 +59820,16 @@ img.ProseMirror-separator {
59733
59820
  return html;
59734
59821
  },
59735
59822
  renderText({ node }) {
59823
+ const args = {
59824
+ options: this.options,
59825
+ node,
59826
+ suggestion: getSuggestionFromChar(this, node.attrs.mentionSuggestionChar),
59827
+ };
59736
59828
  if (this.options.renderLabel !== undefined) {
59737
59829
  console.warn('renderLabel is deprecated use renderText and renderHTML instead');
59738
- return this.options.renderLabel({
59739
- options: this.options,
59740
- node,
59741
- });
59830
+ return this.options.renderLabel(args);
59742
59831
  }
59743
- return this.options.renderText({
59744
- options: this.options,
59745
- node,
59746
- });
59832
+ return this.options.renderText(args);
59747
59833
  },
59748
59834
  addKeyboardShortcuts() {
59749
59835
  return {
@@ -59761,17 +59847,27 @@ img.ProseMirror-separator {
59761
59847
  return false;
59762
59848
  }
59763
59849
  });
59850
+ // Store node and position for later use
59851
+ let mentionNode = new Node$2();
59852
+ let mentionPos = 0;
59853
+ state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
59854
+ if (node.type.name === this.name) {
59855
+ isMention = true;
59856
+ mentionNode = node;
59857
+ mentionPos = pos;
59858
+ return false;
59859
+ }
59860
+ });
59861
+ if (isMention) {
59862
+ tr.insertText(this.options.deleteTriggerWithBackspace ? '' : mentionNode.attrs.mentionSuggestionChar, mentionPos, mentionPos + mentionNode.nodeSize);
59863
+ }
59764
59864
  return isMention;
59765
59865
  }),
59766
59866
  };
59767
59867
  },
59768
59868
  addProseMirrorPlugins() {
59769
- return [
59770
- Suggestion({
59771
- editor: this.editor,
59772
- ...this.options.suggestion,
59773
- }),
59774
- ];
59869
+ // Create a plugin for each suggestion configuration
59870
+ return getSuggestions(this).map(Suggestion);
59775
59871
  },
59776
59872
  });
59777
59873
 
@@ -60134,7 +60230,8 @@ img.ProseMirror-separator {
60134
60230
  mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
60135
60231
  this.options.renderText({
60136
60232
  options: this.options,
60137
- node
60233
+ node,
60234
+ suggestion: null
60138
60235
  })
60139
60236
  ];
60140
60237
  }
@@ -68226,7 +68323,7 @@ focus outline in that case.
68226
68323
  return value;
68227
68324
  }
68228
68325
  }
68229
- const approxEqual = (a, b) => Math.abs(a - b) <= 1;
68326
+ const approxEqual = (a, b) => Math.abs(a - b) < 1.01;
68230
68327
  const debounce = (targetWindow, fn, ms) => {
68231
68328
  let timeoutId;
68232
68329
  return function(...args) {
@@ -68357,7 +68454,6 @@ focus outline in that case.
68357
68454
  this.scrollElement = null;
68358
68455
  this.targetWindow = null;
68359
68456
  this.isScrolling = false;
68360
- this.scrollToIndexTimeoutId = null;
68361
68457
  this.measurementsCache = [];
68362
68458
  this.itemSizeCache = /* @__PURE__ */ new Map();
68363
68459
  this.pendingMeasuredCacheIndexes = [];
@@ -68773,7 +68869,7 @@ focus outline in that case.
68773
68869
  } else if (align === "end") {
68774
68870
  toOffset -= size;
68775
68871
  }
68776
- const maxOffset = this.getTotalSize() - size;
68872
+ const maxOffset = this.getTotalSize() + this.options.scrollMargin - size;
68777
68873
  return Math.max(Math.min(maxOffset, toOffset), 0);
68778
68874
  };
68779
68875
  this.getOffsetForIndex = (index, align = "auto") => {
@@ -68800,14 +68896,7 @@ focus outline in that case.
68800
68896
  ];
68801
68897
  };
68802
68898
  this.isDynamicMode = () => this.elementsCache.size > 0;
68803
- this.cancelScrollToIndex = () => {
68804
- if (this.scrollToIndexTimeoutId !== null && this.targetWindow) {
68805
- this.targetWindow.clearTimeout(this.scrollToIndexTimeoutId);
68806
- this.scrollToIndexTimeoutId = null;
68807
- }
68808
- };
68809
68899
  this.scrollToOffset = (toOffset, { align = "start", behavior } = {}) => {
68810
- this.cancelScrollToIndex();
68811
68900
  if (behavior === "smooth" && this.isDynamicMode()) {
68812
68901
  console.warn(
68813
68902
  "The `smooth` scroll behavior is not fully supported with dynamic size."
@@ -68819,39 +68908,52 @@ focus outline in that case.
68819
68908
  });
68820
68909
  };
68821
68910
  this.scrollToIndex = (index, { align: initialAlign = "auto", behavior } = {}) => {
68822
- index = Math.max(0, Math.min(index, this.options.count - 1));
68823
- this.cancelScrollToIndex();
68824
68911
  if (behavior === "smooth" && this.isDynamicMode()) {
68825
68912
  console.warn(
68826
68913
  "The `smooth` scroll behavior is not fully supported with dynamic size."
68827
68914
  );
68828
68915
  }
68829
- const offsetAndAlign = this.getOffsetForIndex(index, initialAlign);
68830
- if (!offsetAndAlign) return;
68831
- const [offset, align] = offsetAndAlign;
68832
- this._scrollToOffset(offset, { adjustments: void 0, behavior });
68833
- if (behavior !== "smooth" && this.isDynamicMode() && this.targetWindow) {
68834
- this.scrollToIndexTimeoutId = this.targetWindow.setTimeout(() => {
68835
- this.scrollToIndexTimeoutId = null;
68836
- const elementInDOM = this.elementsCache.has(
68837
- this.options.getItemKey(index)
68838
- );
68839
- if (elementInDOM) {
68840
- const result = this.getOffsetForIndex(index, align);
68841
- if (!result) return;
68842
- const [latestOffset] = result;
68843
- const currentScrollOffset = this.getScrollOffset();
68844
- if (!approxEqual(latestOffset, currentScrollOffset)) {
68845
- this.scrollToIndex(index, { align, behavior });
68846
- }
68847
- } else {
68848
- this.scrollToIndex(index, { align, behavior });
68916
+ index = Math.max(0, Math.min(index, this.options.count - 1));
68917
+ let attempts = 0;
68918
+ const maxAttempts = 10;
68919
+ const tryScroll = (currentAlign) => {
68920
+ if (!this.targetWindow) return;
68921
+ const offsetInfo = this.getOffsetForIndex(index, currentAlign);
68922
+ if (!offsetInfo) {
68923
+ console.warn("Failed to get offset for index:", index);
68924
+ return;
68925
+ }
68926
+ const [offset, align] = offsetInfo;
68927
+ this._scrollToOffset(offset, { adjustments: void 0, behavior });
68928
+ this.targetWindow.requestAnimationFrame(() => {
68929
+ const currentOffset = this.getScrollOffset();
68930
+ const afterInfo = this.getOffsetForIndex(index, align);
68931
+ if (!afterInfo) {
68932
+ console.warn("Failed to get offset for index:", index);
68933
+ return;
68934
+ }
68935
+ if (!approxEqual(afterInfo[0], currentOffset)) {
68936
+ scheduleRetry(align);
68849
68937
  }
68850
68938
  });
68851
- }
68939
+ };
68940
+ const scheduleRetry = (align) => {
68941
+ if (!this.targetWindow) return;
68942
+ attempts++;
68943
+ if (attempts < maxAttempts) {
68944
+ if (this.options.debug) {
68945
+ console.info("Schedule retry", attempts, maxAttempts);
68946
+ }
68947
+ this.targetWindow.requestAnimationFrame(() => tryScroll(align));
68948
+ } else {
68949
+ console.warn(
68950
+ `Failed to scroll to index ${index} after ${maxAttempts} attempts.`
68951
+ );
68952
+ }
68953
+ };
68954
+ tryScroll(initialAlign);
68852
68955
  };
68853
68956
  this.scrollBy = (delta, { behavior } = {}) => {
68854
- this.cancelScrollToIndex();
68855
68957
  if (behavior === "smooth" && this.isDynamicMode()) {
68856
68958
  console.warn(
68857
68959
  "The `smooth` scroll behavior is not fully supported with dynamic size."
@@ -79780,7 +79882,7 @@ focus outline in that case.
79780
79882
  /** @ignore */ const isBoolean = (x) => typeof x === 'boolean';
79781
79883
  /** @ignore */ const isFunction = (x) => typeof x === 'function';
79782
79884
  /** @ignore */
79783
- // eslint-disable-next-line @typescript-eslint/ban-types
79885
+ // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
79784
79886
  const isObject$1 = (x) => x != null && Object(x) === x;
79785
79887
  /** @ignore */
79786
79888
  const isPromise = (x) => {
@@ -79951,6 +80053,7 @@ focus outline in that case.
79951
80053
  const pump$1 = (iterator) => { iterator.next(); return iterator; };
79952
80054
  /** @ignore */
79953
80055
  function* toArrayBufferViewIterator(ArrayCtor, source) {
80056
+ // eslint-disable-next-line unicorn/consistent-function-scoping
79954
80057
  const wrap = function* (x) { yield x; };
79955
80058
  const buffers = (typeof source === 'string') ? wrap(source)
79956
80059
  : (ArrayBuffer.isView(source)) ? wrap(source)
@@ -79973,6 +80076,7 @@ focus outline in that case.
79973
80076
  if (isPromise(source)) {
79974
80077
  return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(toArrayBufferViewAsyncIterator(ArrayCtor, yield __await(source))))));
79975
80078
  }
80079
+ // eslint-disable-next-line unicorn/consistent-function-scoping
79976
80080
  const wrap = function (x) { return __asyncGenerator(this, arguments, function* () { yield yield __await(yield __await(x)); }); };
79977
80081
  const emit = function (source) {
79978
80082
  return __asyncGenerator(this, arguments, function* () {
@@ -80097,7 +80201,8 @@ focus outline in that case.
80097
80201
  } while (!done);
80098
80202
  }
80099
80203
  catch (e) {
80100
- (threw = true) && (typeof it.throw === 'function') && (it.throw(e));
80204
+ threw = true;
80205
+ (typeof it.throw === 'function') && (it.throw(e));
80101
80206
  }
80102
80207
  finally {
80103
80208
  (threw === false) && (typeof it.return === 'function') && (it.return(null));
@@ -80141,7 +80246,8 @@ focus outline in that case.
80141
80246
  } while (!done);
80142
80247
  }
80143
80248
  catch (e) {
80144
- (threw = true) && (typeof it.throw === 'function') && (yield __await(it.throw(e)));
80249
+ threw = true;
80250
+ (typeof it.throw === 'function') && (yield __await(it.throw(e)));
80145
80251
  }
80146
80252
  finally {
80147
80253
  (threw === false) && (typeof it.return === 'function') && (yield __await(it.return(new Uint8Array(0))));
@@ -80189,7 +80295,8 @@ focus outline in that case.
80189
80295
  } while (!done);
80190
80296
  }
80191
80297
  catch (e) {
80192
- (threw = true) && (yield __await(it['cancel'](e)));
80298
+ threw = true;
80299
+ yield __await(it['cancel'](e));
80193
80300
  }
80194
80301
  finally {
80195
80302
  (threw === false) ? (yield __await(it['cancel']()))
@@ -86709,7 +86816,6 @@ focus outline in that case.
86709
86816
  // KIND, either express or implied. See the License for the
86710
86817
  // specific language governing permissions and limitations
86711
86818
  // under the License.
86712
- /* eslint-disable @typescript-eslint/naming-convention */
86713
86819
  var Builder$1 = Builder$2;
86714
86820
  var ByteBuffer$1 = ByteBuffer$2;
86715
86821
  /** @ignore */
@@ -88904,7 +89010,6 @@ focus outline in that case.
88904
89010
  // KIND, either express or implied. See the License for the
88905
89011
  // specific language governing permissions and limitations
88906
89012
  // under the License.
88907
- /* eslint-disable brace-style */
88908
89013
  /** @ignore */
88909
89014
  function schemaFromJSON(_schema, dictionaries = new Map()) {
88910
89015
  return new Schema(schemaFieldsFromJSON(_schema, dictionaries), customMetadataFromJSON(_schema['metadata']), dictionaries);
@@ -89076,7 +89181,6 @@ focus outline in that case.
89076
89181
  // KIND, either express or implied. See the License for the
89077
89182
  // specific language governing permissions and limitations
89078
89183
  // under the License.
89079
- /* eslint-disable brace-style */
89080
89184
  var Builder = Builder$2;
89081
89185
  var ByteBuffer = ByteBuffer$2;
89082
89186
  /**
@@ -93708,17 +93812,6 @@ focus outline in that case.
93708
93812
  */
93709
93813
  this.disableSendButton = true;
93710
93814
  }
93711
- /**
93712
- * Clears the text input and gives it focus.
93713
- */
93714
- resetInput() {
93715
- this.value = '';
93716
- this.disableSendButton = true;
93717
- if (this.textArea) {
93718
- this.textArea.value = '';
93719
- this.textArea.focus();
93720
- }
93721
- }
93722
93815
  /**
93723
93816
  * @internal
93724
93817
  */
@@ -93763,11 +93856,20 @@ focus outline in that case.
93763
93856
  const eventDetail = {
93764
93857
  text: this.textArea.value
93765
93858
  };
93859
+ this.resetInput();
93766
93860
  this.$emit('send', eventDetail);
93767
93861
  }
93768
93862
  shouldDisableSendButton() {
93769
93863
  return this.textArea.value.length === 0;
93770
93864
  }
93865
+ resetInput() {
93866
+ this.value = '';
93867
+ this.disableSendButton = true;
93868
+ if (this.textArea) {
93869
+ this.textArea.value = '';
93870
+ this.textArea.focus();
93871
+ }
93872
+ }
93771
93873
  }
93772
93874
  __decorate([
93773
93875
  attr