@ni/nimble-components 33.12.1 → 34.0.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.
@@ -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
  }
@@ -26827,7 +26827,7 @@ so this becomes the fallback color for the slot */ ''}
26827
26827
  ?required="${x => x.required}"
26828
26828
  size="${x => x.size}"
26829
26829
  type="text"
26830
- inputmode="numeric"
26830
+ inputmode="text"
26831
26831
  min="${x => x.min}"
26832
26832
  max="${x => x.max}"
26833
26833
  step="${x => x.step}"
@@ -26889,11 +26889,53 @@ so this becomes the fallback color for the slot */ ''}
26889
26889
  this.appearance = NumberFieldAppearance.underline;
26890
26890
  this.fullBleed = false;
26891
26891
  this.appearanceReadOnly = false;
26892
+ this.decimalSeparator = '.';
26893
+ this.inputFilterRegExp = this.buildFilterRegExp(this.decimalSeparator);
26894
+ this.langSubscriber = {
26895
+ handleChange: () => this.updateDecimalSeparatorAndInputFilter()
26896
+ };
26892
26897
  }
26893
26898
  connectedCallback() {
26894
26899
  super.connectedCallback();
26895
26900
  // This is a workaround for FAST issue: https://github.com/microsoft/fast/issues/6148
26896
26901
  this.control.setAttribute('role', 'spinbutton');
26902
+ this.updateDecimalSeparatorAndInputFilter();
26903
+ lang.subscribe(this.langSubscriber, this);
26904
+ }
26905
+ disconnectedCallback() {
26906
+ super.disconnectedCallback();
26907
+ lang.unsubscribe(this.langSubscriber, this);
26908
+ }
26909
+ sanitizeInput(inputText) {
26910
+ return inputText.replace(this.inputFilterRegExp, '');
26911
+ }
26912
+ // this.value <-- this.control.value
26913
+ syncValueFromInnerControl() {
26914
+ this.value = this.decimalSeparator !== '.'
26915
+ ? this.control.value.replace(this.decimalSeparator, '.')
26916
+ : this.control.value;
26917
+ }
26918
+ // this.value --> this.control.value
26919
+ syncValueToInnerControl() {
26920
+ this.control.value = this.decimalSeparator !== '.'
26921
+ ? this.value.replace('.', this.decimalSeparator)
26922
+ : this.value;
26923
+ }
26924
+ updateDecimalSeparatorAndInputFilter() {
26925
+ const previousSeparator = this.decimalSeparator;
26926
+ this.decimalSeparator = this.getSeparatorForLanguange(lang.getValueFor(this));
26927
+ if (this.decimalSeparator !== previousSeparator) {
26928
+ this.inputFilterRegExp = this.buildFilterRegExp(this.decimalSeparator);
26929
+ this.control.value = this.control.value.replace(previousSeparator, this.decimalSeparator);
26930
+ }
26931
+ }
26932
+ getSeparatorForLanguange(language) {
26933
+ return Intl.NumberFormat(language)
26934
+ .formatToParts(1.1)
26935
+ .find(x => x.type === 'decimal').value;
26936
+ }
26937
+ buildFilterRegExp(decimalSeparator) {
26938
+ return new RegExp(`[^0-9\\-+e${decimalSeparator}]`, 'g');
26897
26939
  }
26898
26940
  }
26899
26941
  __decorate([
@@ -27564,7 +27606,7 @@ so this becomes the fallback color for the slot */ ''}
27564
27606
  position in this fragment. The result object will be reused
27565
27607
  (overwritten) the next time the function is called. @internal
27566
27608
  */
27567
- findIndex(pos, round = -1) {
27609
+ findIndex(pos) {
27568
27610
  if (pos == 0)
27569
27611
  return retIndex(0, pos);
27570
27612
  if (pos == this.size)
@@ -27574,7 +27616,7 @@ so this becomes the fallback color for the slot */ ''}
27574
27616
  for (let i = 0, curPos = 0;; i++) {
27575
27617
  let cur = this.child(i), end = curPos + cur.nodeSize;
27576
27618
  if (end >= pos) {
27577
- if (end == pos || round > 0)
27619
+ if (end == pos)
27578
27620
  return retIndex(i + 1, end);
27579
27621
  return retIndex(i, curPos);
27580
27622
  }
@@ -28535,7 +28577,7 @@ so this becomes the fallback color for the slot */ ''}
28535
28577
  `blockSeparator` is given, it will be inserted to separate text
28536
28578
  from different block nodes. If `leafText` is given, it'll be
28537
28579
  inserted for every non-text leaf node encountered, otherwise
28538
- [`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec^leafText) will be used.
28580
+ [`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec.leafText) will be used.
28539
28581
  */
28540
28582
  textBetween(from, to, blockSeparator, leafText) {
28541
28583
  return this.content.textBetween(from, to, blockSeparator, leafText);
@@ -29745,8 +29787,8 @@ so this becomes the fallback color for the slot */ ''}
29745
29787
  let type = this.marks[prop], excl = type.spec.excludes;
29746
29788
  type.excluded = excl == null ? [type] : excl == "" ? [] : gatherMarks(this, excl.split(" "));
29747
29789
  }
29748
- this.nodeFromJSON = this.nodeFromJSON.bind(this);
29749
- this.markFromJSON = this.markFromJSON.bind(this);
29790
+ this.nodeFromJSON = json => Node$2.fromJSON(this, json);
29791
+ this.markFromJSON = json => Mark$1.fromJSON(this, json);
29750
29792
  this.topNodeType = this.nodes[this.spec.topNode || "doc"];
29751
29793
  this.cached.wrappings = Object.create(null);
29752
29794
  }
@@ -29782,20 +29824,6 @@ so this becomes the fallback color for the slot */ ''}
29782
29824
  return type.create(attrs);
29783
29825
  }
29784
29826
  /**
29785
- Deserialize a node from its JSON representation. This method is
29786
- bound.
29787
- */
29788
- nodeFromJSON(json) {
29789
- return Node$2.fromJSON(this, json);
29790
- }
29791
- /**
29792
- Deserialize a mark from its JSON representation. This method is
29793
- bound.
29794
- */
29795
- markFromJSON(json) {
29796
- return Mark$1.fromJSON(this, json);
29797
- }
29798
- /**
29799
29827
  @internal
29800
29828
  */
29801
29829
  nodeType(name) {
@@ -29977,7 +30005,7 @@ so this becomes the fallback color for the slot */ ''}
29977
30005
  /**
29978
30006
  Construct a DOM parser using the parsing rules listed in a
29979
30007
  schema's [node specs](https://prosemirror.net/docs/ref/#model.NodeSpec.parseDOM), reordered by
29980
- [priority](https://prosemirror.net/docs/ref/#model.ParseRule.priority).
30008
+ [priority](https://prosemirror.net/docs/ref/#model.GenericParseRule.priority).
29981
30009
  */
29982
30010
  static fromSchema(schema) {
29983
30011
  return schema.cached.domParser ||
@@ -30001,7 +30029,7 @@ so this becomes the fallback color for the slot */ ''}
30001
30029
  if (preserveWhitespace != null)
30002
30030
  return (preserveWhitespace ? OPT_PRESERVE_WS : 0) |
30003
30031
  (preserveWhitespace === "full" ? OPT_PRESERVE_WS_FULL : 0);
30004
- return type && type.whitespace == "pre" ? OPT_PRESERVE_WS | OPT_PRESERVE_WS_FULL : base & -5;
30032
+ return type && type.whitespace == "pre" ? OPT_PRESERVE_WS | OPT_PRESERVE_WS_FULL : base & ~OPT_OPEN_LEFT;
30005
30033
  }
30006
30034
  class NodeContext {
30007
30035
  constructor(type, attrs, marks, solid, match, options) {
@@ -30728,6 +30756,8 @@ so this becomes the fallback color for the slot */ ''}
30728
30756
  let space = name.indexOf(" ");
30729
30757
  if (space > 0)
30730
30758
  dom.setAttributeNS(name.slice(0, space), name.slice(space + 1), attrs[name]);
30759
+ else if (name == "style" && dom.style)
30760
+ dom.style.cssText = attrs[name];
30731
30761
  else
30732
30762
  dom.setAttribute(name, attrs[name]);
30733
30763
  }
@@ -33437,7 +33467,7 @@ so this becomes the fallback color for the slot */ ''}
33437
33467
  throw new RangeError("Selection passed to setSelection must point at the current document");
33438
33468
  this.curSelection = selection;
33439
33469
  this.curSelectionFor = this.steps.length;
33440
- this.updated = (this.updated | UPDATED_SEL) & -3;
33470
+ this.updated = (this.updated | UPDATED_SEL) & ~UPDATED_MARKS;
33441
33471
  this.storedMarks = null;
33442
33472
  return this;
33443
33473
  }
@@ -33488,7 +33518,7 @@ so this becomes the fallback color for the slot */ ''}
33488
33518
  */
33489
33519
  addStep(step, doc) {
33490
33520
  super.addStep(step, doc);
33491
- this.updated = this.updated & -3;
33521
+ this.updated = this.updated & ~UPDATED_MARKS;
33492
33522
  this.storedMarks = null;
33493
33523
  }
33494
33524
  /**
@@ -41834,7 +41864,7 @@ so this becomes the fallback color for the slot */ ''}
41834
41864
  dropEvent = event;
41835
41865
  if (!isDroppedFromProseMirror) {
41836
41866
  const dragFromOtherEditor = tiptapDragFromOtherEditor;
41837
- if (dragFromOtherEditor) {
41867
+ if (dragFromOtherEditor === null || dragFromOtherEditor === void 0 ? void 0 : dragFromOtherEditor.isEditable) {
41838
41868
  // setTimeout to avoid the wrong content after drop, timeout arg can't be empty or 0
41839
41869
  setTimeout(() => {
41840
41870
  const selection = dragFromOtherEditor.state.selection;
@@ -42385,7 +42415,7 @@ so this becomes the fallback color for the slot */ ''}
42385
42415
  tr.deleteRange(originRange.from, originRange.to);
42386
42416
  const newPos = tr.mapping.map(targetPos);
42387
42417
  tr.insert(newPos, contentSlice.content);
42388
- tr.setSelection(new TextSelection(tr.doc.resolve(newPos - 1)));
42418
+ tr.setSelection(new TextSelection(tr.doc.resolve(Math.max(newPos - 1, 0))));
42389
42419
  return true;
42390
42420
  };
42391
42421
 
@@ -42817,25 +42847,42 @@ so this becomes the fallback color for the slot */ ''}
42817
42847
  ...options,
42818
42848
  };
42819
42849
  let content;
42820
- try {
42821
- content = createNodeFromContent(value, editor.schema, {
42822
- parseOptions: {
42823
- preserveWhitespace: 'full',
42824
- ...options.parseOptions,
42825
- },
42826
- errorOnInvalidContent: (_a = options.errorOnInvalidContent) !== null && _a !== void 0 ? _a : editor.options.enableContentCheck,
42827
- });
42828
- }
42829
- catch (e) {
42850
+ const emitContentError = (error) => {
42830
42851
  editor.emit('contentError', {
42831
42852
  editor,
42832
- error: e,
42853
+ error,
42833
42854
  disableCollaboration: () => {
42834
42855
  if (editor.storage.collaboration) {
42835
42856
  editor.storage.collaboration.isDisabled = true;
42836
42857
  }
42837
42858
  },
42838
42859
  });
42860
+ };
42861
+ const parseOptions = {
42862
+ preserveWhitespace: 'full',
42863
+ ...options.parseOptions,
42864
+ };
42865
+ // If `emitContentError` is enabled, we want to check the content for errors
42866
+ // but ignore them (do not remove the invalid content from the document)
42867
+ if (!options.errorOnInvalidContent && !editor.options.enableContentCheck && editor.options.emitContentError) {
42868
+ try {
42869
+ createNodeFromContent(value, editor.schema, {
42870
+ parseOptions,
42871
+ errorOnInvalidContent: true,
42872
+ });
42873
+ }
42874
+ catch (e) {
42875
+ emitContentError(e);
42876
+ }
42877
+ }
42878
+ try {
42879
+ content = createNodeFromContent(value, editor.schema, {
42880
+ parseOptions,
42881
+ errorOnInvalidContent: (_a = options.errorOnInvalidContent) !== null && _a !== void 0 ? _a : editor.options.enableContentCheck,
42882
+ });
42883
+ }
42884
+ catch (e) {
42885
+ emitContentError(e);
42839
42886
  return false;
42840
42887
  }
42841
42888
  let { from, to } = typeof position === 'number' ? { from: position, to: position } : { from: position.from, to: position.to };
@@ -44662,6 +44709,10 @@ so this becomes the fallback color for the slot */ ''}
44662
44709
  const isBlock = node.isBlock && !node.isTextblock;
44663
44710
  const isNonTextAtom = node.isAtom && !node.isText;
44664
44711
  const targetPos = this.pos + offset + (isNonTextAtom ? 0 : 1);
44712
+ // Check if targetPos is within valid document range
44713
+ if (targetPos < 0 || targetPos > this.resolvedPos.doc.nodeSize - 2) {
44714
+ return;
44715
+ }
44665
44716
  const $pos = this.resolvedPos.doc.resolve(targetPos);
44666
44717
  if (!isBlock && $pos.depth <= this.depth) {
44667
44718
  return;
@@ -44861,6 +44912,7 @@ img.ProseMirror-separator {
44861
44912
  enablePasteRules: true,
44862
44913
  enableCoreExtensions: true,
44863
44914
  enableContentCheck: false,
44915
+ emitContentError: false,
44864
44916
  onBeforeCreate: () => null,
44865
44917
  onCreate: () => null,
44866
44918
  onUpdate: () => null,
@@ -58880,6 +58932,13 @@ img.ProseMirror-separator {
58880
58932
  return filtered;
58881
58933
  }
58882
58934
 
58935
+ // From DOMPurify
58936
+ // https://github.com/cure53/DOMPurify/blob/main/src/regexp.ts
58937
+ const UNICODE_WHITESPACE_PATTERN = '[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]';
58938
+ const UNICODE_WHITESPACE_REGEX = new RegExp(UNICODE_WHITESPACE_PATTERN);
58939
+ const UNICODE_WHITESPACE_REGEX_END = new RegExp(`${UNICODE_WHITESPACE_PATTERN}$`);
58940
+ const UNICODE_WHITESPACE_REGEX_GLOBAL = new RegExp(UNICODE_WHITESPACE_PATTERN, 'g');
58941
+
58883
58942
  /**
58884
58943
  * Check if the provided tokens form a valid link structure, which can either be a single link token
58885
58944
  * or a link token surrounded by parentheses or square brackets.
@@ -58936,14 +58995,16 @@ img.ProseMirror-separator {
58936
58995
  textBlock = nodesInChangedRanges[0];
58937
58996
  textBeforeWhitespace = newState.doc.textBetween(textBlock.pos, textBlock.pos + textBlock.node.nodeSize, undefined, ' ');
58938
58997
  }
58939
- else if (nodesInChangedRanges.length
58940
- // We want to make sure to include the block seperator argument to treat hard breaks like spaces.
58941
- && newState.doc.textBetween(newRange.from, newRange.to, ' ', ' ').endsWith(' ')) {
58998
+ else if (nodesInChangedRanges.length) {
58999
+ const endText = newState.doc.textBetween(newRange.from, newRange.to, ' ', ' ');
59000
+ if (!UNICODE_WHITESPACE_REGEX_END.test(endText)) {
59001
+ return;
59002
+ }
58942
59003
  textBlock = nodesInChangedRanges[0];
58943
59004
  textBeforeWhitespace = newState.doc.textBetween(textBlock.pos, newRange.to, undefined, ' ');
58944
59005
  }
58945
59006
  if (textBlock && textBeforeWhitespace) {
58946
- const wordsBeforeWhitespace = textBeforeWhitespace.split(' ').filter(s => s !== '');
59007
+ const wordsBeforeWhitespace = textBeforeWhitespace.split(UNICODE_WHITESPACE_REGEX).filter(Boolean);
58947
59008
  if (wordsBeforeWhitespace.length <= 0) {
58948
59009
  return false;
58949
59010
  }
@@ -59055,10 +59116,6 @@ img.ProseMirror-separator {
59055
59116
  },
59056
59117
  });
59057
59118
  }
59058
- // From DOMPurify
59059
- // https://github.com/cure53/DOMPurify/blob/main/src/regexp.js
59060
- // eslint-disable-next-line no-control-regex
59061
- const ATTR_WHITESPACE = /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g;
59062
59119
  function isAllowedUri(uri, protocols) {
59063
59120
  const allowedProtocols = [
59064
59121
  'http',
@@ -59081,9 +59138,7 @@ img.ProseMirror-separator {
59081
59138
  });
59082
59139
  }
59083
59140
  return (!uri
59084
- || uri
59085
- .replace(ATTR_WHITESPACE, '')
59086
- .match(new RegExp(
59141
+ || uri.replace(UNICODE_WHITESPACE_REGEX_GLOBAL, '').match(new RegExp(
59087
59142
  // eslint-disable-next-line no-useless-escape
59088
59143
  `^(?:(?:${allowedProtocols.join('|')}):|[^a-z]|[a-z0-9+.\-]+(?:[^a-z+.\-:]|$))`, 'i')));
59089
59144
  }
@@ -59378,7 +59433,7 @@ img.ProseMirror-separator {
59378
59433
  * This utility allows you to create suggestions.
59379
59434
  * @see https://tiptap.dev/api/utilities/suggestion
59380
59435
  */
59381
- 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, }) {
59436
+ 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, }) {
59382
59437
  let props;
59383
59438
  const renderer = render === null || render === void 0 ? void 0 : render();
59384
59439
  const plugin = new Plugin({
@@ -59488,7 +59543,9 @@ img.ProseMirror-separator {
59488
59543
  // * a composition is active (see: https://github.com/ueberdosis/tiptap/issues/1449)
59489
59544
  if (isEditable && (empty || editor.view.composing)) {
59490
59545
  // Reset active state if we just left the previous suggestion range
59491
- if ((from < prev.range.from || from > prev.range.to) && !composing && !prev.composing) {
59546
+ if ((from < prev.range.from || from > prev.range.to)
59547
+ && !composing
59548
+ && !prev.composing) {
59492
59549
  next.active = false;
59493
59550
  }
59494
59551
  // Try to match against where our cursor currently is
@@ -59502,11 +59559,17 @@ img.ProseMirror-separator {
59502
59559
  });
59503
59560
  const decorationId = `id_${Math.floor(Math.random() * 0xffffffff)}`;
59504
59561
  // If we found a match, update the current state to show it
59505
- if (match && allow({
59506
- editor, state, range: match.range, isActive: prev.active,
59507
- })) {
59562
+ if (match
59563
+ && allow({
59564
+ editor,
59565
+ state,
59566
+ range: match.range,
59567
+ isActive: prev.active,
59568
+ })) {
59508
59569
  next.active = true;
59509
- next.decorationId = prev.decorationId ? prev.decorationId : decorationId;
59570
+ next.decorationId = prev.decorationId
59571
+ ? prev.decorationId
59572
+ : decorationId;
59510
59573
  next.range = match.range;
59511
59574
  next.query = match.query;
59512
59575
  next.text = match.text;
@@ -59540,15 +59603,21 @@ img.ProseMirror-separator {
59540
59603
  },
59541
59604
  // Setup decorator on the currently active suggestion.
59542
59605
  decorations(state) {
59543
- const { active, range, decorationId } = plugin.getState(state);
59606
+ const { active, range, decorationId, query, } = plugin.getState(state);
59544
59607
  if (!active) {
59545
59608
  return null;
59546
59609
  }
59610
+ const isEmpty = !(query === null || query === void 0 ? void 0 : query.length);
59611
+ const classNames = [decorationClass];
59612
+ if (isEmpty) {
59613
+ classNames.push(decorationEmptyClass);
59614
+ }
59547
59615
  return DecorationSet.create(state.doc, [
59548
59616
  Decoration.inline(range.from, range.to, {
59549
59617
  nodeName: decorationTag,
59550
- class: decorationClass,
59618
+ class: classNames.join(' '),
59551
59619
  'data-decoration-id': decorationId,
59620
+ 'data-decoration-content': decorationContent,
59552
59621
  }),
59553
59622
  ]);
59554
59623
  },
@@ -59558,10 +59627,91 @@ img.ProseMirror-separator {
59558
59627
  }
59559
59628
 
59560
59629
  /**
59561
- * The plugin key for the mention plugin.
59562
- * @default 'mention'
59630
+ * Returns the suggestion options for a trigger of the Mention extension. These
59631
+ * options are used to create a `Suggestion` ProseMirror plugin. Each plugin lets
59632
+ * you define a different trigger that opens the Mention menu. For example,
59633
+ * you can define a `@` trigger to mention users and a `#` trigger to mention
59634
+ * tags.
59635
+ *
59636
+ * @param param0 The configured options for the suggestion
59637
+ * @returns
59638
+ */
59639
+ function getSuggestionOptions({ editor: tiptapEditor, overrideSuggestionOptions, extensionName, char = '@', }) {
59640
+ const pluginKey = new PluginKey();
59641
+ return {
59642
+ editor: tiptapEditor,
59643
+ char,
59644
+ pluginKey,
59645
+ command: ({ editor, range, props }) => {
59646
+ var _a, _b, _c;
59647
+ // increase range.to by one when the next node is of type "text"
59648
+ // and starts with a space character
59649
+ const nodeAfter = editor.view.state.selection.$to.nodeAfter;
59650
+ const overrideSpace = (_a = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.text) === null || _a === void 0 ? void 0 : _a.startsWith(' ');
59651
+ if (overrideSpace) {
59652
+ range.to += 1;
59653
+ }
59654
+ editor
59655
+ .chain()
59656
+ .focus()
59657
+ .insertContentAt(range, [
59658
+ {
59659
+ type: extensionName,
59660
+ attrs: { ...props, mentionSuggestionChar: char },
59661
+ },
59662
+ {
59663
+ type: 'text',
59664
+ text: ' ',
59665
+ },
59666
+ ])
59667
+ .run();
59668
+ // get reference to `window` object from editor element, to support cross-frame JS usage
59669
+ (_c = (_b = editor.view.dom.ownerDocument.defaultView) === null || _b === void 0 ? void 0 : _b.getSelection()) === null || _c === void 0 ? void 0 : _c.collapseToEnd();
59670
+ },
59671
+ allow: ({ state, range }) => {
59672
+ const $from = state.doc.resolve(range.from);
59673
+ const type = state.schema.nodes[extensionName];
59674
+ const allow = !!$from.parent.type.contentMatch.matchType(type);
59675
+ return allow;
59676
+ },
59677
+ ...overrideSuggestionOptions,
59678
+ };
59679
+ }
59680
+
59681
+ /**
59682
+ * Returns the suggestions for the mention extension.
59683
+ *
59684
+ * @param options The extension options
59685
+ * @returns the suggestions
59686
+ */
59687
+ function getSuggestions(options) {
59688
+ return (options.options.suggestions.length ? options.options.suggestions : [options.options.suggestion]).map(suggestion => getSuggestionOptions({
59689
+ // @ts-ignore `editor` can be `undefined` when converting the document to HTML with the HTML utility
59690
+ editor: options.editor,
59691
+ overrideSuggestionOptions: suggestion,
59692
+ extensionName: options.name,
59693
+ char: suggestion.char,
59694
+ }));
59695
+ }
59696
+ /**
59697
+ * Returns the suggestion options of the mention that has a given character trigger. If not
59698
+ * found, it returns the first suggestion.
59699
+ *
59700
+ * @param options The extension options
59701
+ * @param char The character that triggers the mention
59702
+ * @returns The suggestion options
59563
59703
  */
59564
- const MentionPluginKey = new PluginKey('mention');
59704
+ function getSuggestionFromChar(options, char) {
59705
+ const suggestions = getSuggestions(options);
59706
+ const suggestion = suggestions.find(s => s.char === char);
59707
+ if (suggestion) {
59708
+ return suggestion;
59709
+ }
59710
+ if (suggestions.length) {
59711
+ return suggestions[0];
59712
+ }
59713
+ return null;
59714
+ }
59565
59715
  /**
59566
59716
  * This extension allows you to insert mentions into the editor.
59567
59717
  * @see https://www.tiptap.dev/api/extensions/mention
@@ -59572,55 +59722,21 @@ img.ProseMirror-separator {
59572
59722
  addOptions() {
59573
59723
  return {
59574
59724
  HTMLAttributes: {},
59575
- renderText({ options, node }) {
59576
- var _a;
59577
- return `${options.suggestion.char}${(_a = node.attrs.label) !== null && _a !== void 0 ? _a : node.attrs.id}`;
59725
+ renderText({ node, suggestion }) {
59726
+ var _a, _b;
59727
+ 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}`;
59578
59728
  },
59579
59729
  deleteTriggerWithBackspace: false,
59580
- renderHTML({ options, node }) {
59581
- var _a;
59730
+ renderHTML({ options, node, suggestion }) {
59731
+ var _a, _b;
59582
59732
  return [
59583
59733
  'span',
59584
59734
  mergeAttributes(this.HTMLAttributes, options.HTMLAttributes),
59585
- `${options.suggestion.char}${(_a = node.attrs.label) !== null && _a !== void 0 ? _a : node.attrs.id}`,
59735
+ `${(_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}`,
59586
59736
  ];
59587
59737
  },
59588
- suggestion: {
59589
- char: '@',
59590
- pluginKey: MentionPluginKey,
59591
- command: ({ editor, range, props }) => {
59592
- var _a, _b, _c;
59593
- // increase range.to by one when the next node is of type "text"
59594
- // and starts with a space character
59595
- const nodeAfter = editor.view.state.selection.$to.nodeAfter;
59596
- const overrideSpace = (_a = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.text) === null || _a === void 0 ? void 0 : _a.startsWith(' ');
59597
- if (overrideSpace) {
59598
- range.to += 1;
59599
- }
59600
- editor
59601
- .chain()
59602
- .focus()
59603
- .insertContentAt(range, [
59604
- {
59605
- type: this.name,
59606
- attrs: props,
59607
- },
59608
- {
59609
- type: 'text',
59610
- text: ' ',
59611
- },
59612
- ])
59613
- .run();
59614
- // get reference to `window` object from editor element, to support cross-frame JS usage
59615
- (_c = (_b = editor.view.dom.ownerDocument.defaultView) === null || _b === void 0 ? void 0 : _b.getSelection()) === null || _c === void 0 ? void 0 : _c.collapseToEnd();
59616
- },
59617
- allow: ({ state, range }) => {
59618
- const $from = state.doc.resolve(range.from);
59619
- const type = state.schema.nodes[this.name];
59620
- const allow = !!$from.parent.type.contentMatch.matchType(type);
59621
- return allow;
59622
- },
59623
- },
59738
+ suggestions: [],
59739
+ suggestion: {},
59624
59740
  };
59625
59741
  },
59626
59742
  group: 'inline',
@@ -59653,6 +59769,16 @@ img.ProseMirror-separator {
59653
59769
  };
59654
59770
  },
59655
59771
  },
59772
+ // When there are multiple types of mentions, this attribute helps distinguish them
59773
+ mentionSuggestionChar: {
59774
+ default: '@',
59775
+ parseHTML: element => element.getAttribute('data-mention-suggestion-char'),
59776
+ renderHTML: attributes => {
59777
+ return {
59778
+ 'data-mention-suggestion-char': attributes.mentionSuggestionChar,
59779
+ };
59780
+ },
59781
+ },
59656
59782
  };
59657
59783
  },
59658
59784
  parseHTML() {
@@ -59663,6 +59789,7 @@ img.ProseMirror-separator {
59663
59789
  ];
59664
59790
  },
59665
59791
  renderHTML({ node, HTMLAttributes }) {
59792
+ const suggestion = getSuggestionFromChar(this, node.attrs.mentionSuggestionChar);
59666
59793
  if (this.options.renderLabel !== undefined) {
59667
59794
  console.warn('renderLabel is deprecated use renderText and renderHTML instead');
59668
59795
  return [
@@ -59671,6 +59798,7 @@ img.ProseMirror-separator {
59671
59798
  this.options.renderLabel({
59672
59799
  options: this.options,
59673
59800
  node,
59801
+ suggestion,
59674
59802
  }),
59675
59803
  ];
59676
59804
  }
@@ -59679,6 +59807,7 @@ img.ProseMirror-separator {
59679
59807
  const html = this.options.renderHTML({
59680
59808
  options: mergedOptions,
59681
59809
  node,
59810
+ suggestion,
59682
59811
  });
59683
59812
  if (typeof html === 'string') {
59684
59813
  return [
@@ -59690,17 +59819,16 @@ img.ProseMirror-separator {
59690
59819
  return html;
59691
59820
  },
59692
59821
  renderText({ node }) {
59822
+ const args = {
59823
+ options: this.options,
59824
+ node,
59825
+ suggestion: getSuggestionFromChar(this, node.attrs.mentionSuggestionChar),
59826
+ };
59693
59827
  if (this.options.renderLabel !== undefined) {
59694
59828
  console.warn('renderLabel is deprecated use renderText and renderHTML instead');
59695
- return this.options.renderLabel({
59696
- options: this.options,
59697
- node,
59698
- });
59829
+ return this.options.renderLabel(args);
59699
59830
  }
59700
- return this.options.renderText({
59701
- options: this.options,
59702
- node,
59703
- });
59831
+ return this.options.renderText(args);
59704
59832
  },
59705
59833
  addKeyboardShortcuts() {
59706
59834
  return {
@@ -59718,17 +59846,27 @@ img.ProseMirror-separator {
59718
59846
  return false;
59719
59847
  }
59720
59848
  });
59849
+ // Store node and position for later use
59850
+ let mentionNode = new Node$2();
59851
+ let mentionPos = 0;
59852
+ state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
59853
+ if (node.type.name === this.name) {
59854
+ isMention = true;
59855
+ mentionNode = node;
59856
+ mentionPos = pos;
59857
+ return false;
59858
+ }
59859
+ });
59860
+ if (isMention) {
59861
+ tr.insertText(this.options.deleteTriggerWithBackspace ? '' : mentionNode.attrs.mentionSuggestionChar, mentionPos, mentionPos + mentionNode.nodeSize);
59862
+ }
59721
59863
  return isMention;
59722
59864
  }),
59723
59865
  };
59724
59866
  },
59725
59867
  addProseMirrorPlugins() {
59726
- return [
59727
- Suggestion({
59728
- editor: this.editor,
59729
- ...this.options.suggestion,
59730
- }),
59731
- ];
59868
+ // Create a plugin for each suggestion configuration
59869
+ return getSuggestions(this).map(Suggestion);
59732
59870
  },
59733
59871
  });
59734
59872
 
@@ -60091,7 +60229,8 @@ img.ProseMirror-separator {
60091
60229
  mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
60092
60230
  this.options.renderText({
60093
60231
  options: this.options,
60094
- node
60232
+ node,
60233
+ suggestion: null
60095
60234
  })
60096
60235
  ];
60097
60236
  }
@@ -68183,7 +68322,7 @@ focus outline in that case.
68183
68322
  return value;
68184
68323
  }
68185
68324
  }
68186
- const approxEqual = (a, b) => Math.abs(a - b) <= 1;
68325
+ const approxEqual = (a, b) => Math.abs(a - b) < 1.01;
68187
68326
  const debounce = (targetWindow, fn, ms) => {
68188
68327
  let timeoutId;
68189
68328
  return function(...args) {
@@ -68314,7 +68453,6 @@ focus outline in that case.
68314
68453
  this.scrollElement = null;
68315
68454
  this.targetWindow = null;
68316
68455
  this.isScrolling = false;
68317
- this.scrollToIndexTimeoutId = null;
68318
68456
  this.measurementsCache = [];
68319
68457
  this.itemSizeCache = /* @__PURE__ */ new Map();
68320
68458
  this.pendingMeasuredCacheIndexes = [];
@@ -68730,7 +68868,7 @@ focus outline in that case.
68730
68868
  } else if (align === "end") {
68731
68869
  toOffset -= size;
68732
68870
  }
68733
- const maxOffset = this.getTotalSize() - size;
68871
+ const maxOffset = this.getTotalSize() + this.options.scrollMargin - size;
68734
68872
  return Math.max(Math.min(maxOffset, toOffset), 0);
68735
68873
  };
68736
68874
  this.getOffsetForIndex = (index, align = "auto") => {
@@ -68757,14 +68895,7 @@ focus outline in that case.
68757
68895
  ];
68758
68896
  };
68759
68897
  this.isDynamicMode = () => this.elementsCache.size > 0;
68760
- this.cancelScrollToIndex = () => {
68761
- if (this.scrollToIndexTimeoutId !== null && this.targetWindow) {
68762
- this.targetWindow.clearTimeout(this.scrollToIndexTimeoutId);
68763
- this.scrollToIndexTimeoutId = null;
68764
- }
68765
- };
68766
68898
  this.scrollToOffset = (toOffset, { align = "start", behavior } = {}) => {
68767
- this.cancelScrollToIndex();
68768
68899
  if (behavior === "smooth" && this.isDynamicMode()) {
68769
68900
  console.warn(
68770
68901
  "The `smooth` scroll behavior is not fully supported with dynamic size."
@@ -68776,39 +68907,52 @@ focus outline in that case.
68776
68907
  });
68777
68908
  };
68778
68909
  this.scrollToIndex = (index, { align: initialAlign = "auto", behavior } = {}) => {
68779
- index = Math.max(0, Math.min(index, this.options.count - 1));
68780
- this.cancelScrollToIndex();
68781
68910
  if (behavior === "smooth" && this.isDynamicMode()) {
68782
68911
  console.warn(
68783
68912
  "The `smooth` scroll behavior is not fully supported with dynamic size."
68784
68913
  );
68785
68914
  }
68786
- const offsetAndAlign = this.getOffsetForIndex(index, initialAlign);
68787
- if (!offsetAndAlign) return;
68788
- const [offset, align] = offsetAndAlign;
68789
- this._scrollToOffset(offset, { adjustments: void 0, behavior });
68790
- if (behavior !== "smooth" && this.isDynamicMode() && this.targetWindow) {
68791
- this.scrollToIndexTimeoutId = this.targetWindow.setTimeout(() => {
68792
- this.scrollToIndexTimeoutId = null;
68793
- const elementInDOM = this.elementsCache.has(
68794
- this.options.getItemKey(index)
68795
- );
68796
- if (elementInDOM) {
68797
- const result = this.getOffsetForIndex(index, align);
68798
- if (!result) return;
68799
- const [latestOffset] = result;
68800
- const currentScrollOffset = this.getScrollOffset();
68801
- if (!approxEqual(latestOffset, currentScrollOffset)) {
68802
- this.scrollToIndex(index, { align, behavior });
68803
- }
68804
- } else {
68805
- this.scrollToIndex(index, { align, behavior });
68915
+ index = Math.max(0, Math.min(index, this.options.count - 1));
68916
+ let attempts = 0;
68917
+ const maxAttempts = 10;
68918
+ const tryScroll = (currentAlign) => {
68919
+ if (!this.targetWindow) return;
68920
+ const offsetInfo = this.getOffsetForIndex(index, currentAlign);
68921
+ if (!offsetInfo) {
68922
+ console.warn("Failed to get offset for index:", index);
68923
+ return;
68924
+ }
68925
+ const [offset, align] = offsetInfo;
68926
+ this._scrollToOffset(offset, { adjustments: void 0, behavior });
68927
+ this.targetWindow.requestAnimationFrame(() => {
68928
+ const currentOffset = this.getScrollOffset();
68929
+ const afterInfo = this.getOffsetForIndex(index, align);
68930
+ if (!afterInfo) {
68931
+ console.warn("Failed to get offset for index:", index);
68932
+ return;
68933
+ }
68934
+ if (!approxEqual(afterInfo[0], currentOffset)) {
68935
+ scheduleRetry(align);
68806
68936
  }
68807
68937
  });
68808
- }
68938
+ };
68939
+ const scheduleRetry = (align) => {
68940
+ if (!this.targetWindow) return;
68941
+ attempts++;
68942
+ if (attempts < maxAttempts) {
68943
+ if (this.options.debug) {
68944
+ console.info("Schedule retry", attempts, maxAttempts);
68945
+ }
68946
+ this.targetWindow.requestAnimationFrame(() => tryScroll(align));
68947
+ } else {
68948
+ console.warn(
68949
+ `Failed to scroll to index ${index} after ${maxAttempts} attempts.`
68950
+ );
68951
+ }
68952
+ };
68953
+ tryScroll(initialAlign);
68809
68954
  };
68810
68955
  this.scrollBy = (delta, { behavior } = {}) => {
68811
- this.cancelScrollToIndex();
68812
68956
  if (behavior === "smooth" && this.isDynamicMode()) {
68813
68957
  console.warn(
68814
68958
  "The `smooth` scroll behavior is not fully supported with dynamic size."
@@ -79737,7 +79881,7 @@ focus outline in that case.
79737
79881
  /** @ignore */ const isBoolean = (x) => typeof x === 'boolean';
79738
79882
  /** @ignore */ const isFunction = (x) => typeof x === 'function';
79739
79883
  /** @ignore */
79740
- // eslint-disable-next-line @typescript-eslint/ban-types
79884
+ // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
79741
79885
  const isObject$1 = (x) => x != null && Object(x) === x;
79742
79886
  /** @ignore */
79743
79887
  const isPromise = (x) => {
@@ -79908,6 +80052,7 @@ focus outline in that case.
79908
80052
  const pump$1 = (iterator) => { iterator.next(); return iterator; };
79909
80053
  /** @ignore */
79910
80054
  function* toArrayBufferViewIterator(ArrayCtor, source) {
80055
+ // eslint-disable-next-line unicorn/consistent-function-scoping
79911
80056
  const wrap = function* (x) { yield x; };
79912
80057
  const buffers = (typeof source === 'string') ? wrap(source)
79913
80058
  : (ArrayBuffer.isView(source)) ? wrap(source)
@@ -79930,6 +80075,7 @@ focus outline in that case.
79930
80075
  if (isPromise(source)) {
79931
80076
  return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(toArrayBufferViewAsyncIterator(ArrayCtor, yield __await(source))))));
79932
80077
  }
80078
+ // eslint-disable-next-line unicorn/consistent-function-scoping
79933
80079
  const wrap = function (x) { return __asyncGenerator(this, arguments, function* () { yield yield __await(yield __await(x)); }); };
79934
80080
  const emit = function (source) {
79935
80081
  return __asyncGenerator(this, arguments, function* () {
@@ -80054,7 +80200,8 @@ focus outline in that case.
80054
80200
  } while (!done);
80055
80201
  }
80056
80202
  catch (e) {
80057
- (threw = true) && (typeof it.throw === 'function') && (it.throw(e));
80203
+ threw = true;
80204
+ (typeof it.throw === 'function') && (it.throw(e));
80058
80205
  }
80059
80206
  finally {
80060
80207
  (threw === false) && (typeof it.return === 'function') && (it.return(null));
@@ -80098,7 +80245,8 @@ focus outline in that case.
80098
80245
  } while (!done);
80099
80246
  }
80100
80247
  catch (e) {
80101
- (threw = true) && (typeof it.throw === 'function') && (yield __await(it.throw(e)));
80248
+ threw = true;
80249
+ (typeof it.throw === 'function') && (yield __await(it.throw(e)));
80102
80250
  }
80103
80251
  finally {
80104
80252
  (threw === false) && (typeof it.return === 'function') && (yield __await(it.return(new Uint8Array(0))));
@@ -80146,7 +80294,8 @@ focus outline in that case.
80146
80294
  } while (!done);
80147
80295
  }
80148
80296
  catch (e) {
80149
- (threw = true) && (yield __await(it['cancel'](e)));
80297
+ threw = true;
80298
+ yield __await(it['cancel'](e));
80150
80299
  }
80151
80300
  finally {
80152
80301
  (threw === false) ? (yield __await(it['cancel']()))
@@ -86666,7 +86815,6 @@ focus outline in that case.
86666
86815
  // KIND, either express or implied. See the License for the
86667
86816
  // specific language governing permissions and limitations
86668
86817
  // under the License.
86669
- /* eslint-disable @typescript-eslint/naming-convention */
86670
86818
  var Builder$1 = Builder$2;
86671
86819
  var ByteBuffer$1 = ByteBuffer$2;
86672
86820
  /** @ignore */
@@ -88861,7 +89009,6 @@ focus outline in that case.
88861
89009
  // KIND, either express or implied. See the License for the
88862
89010
  // specific language governing permissions and limitations
88863
89011
  // under the License.
88864
- /* eslint-disable brace-style */
88865
89012
  /** @ignore */
88866
89013
  function schemaFromJSON(_schema, dictionaries = new Map()) {
88867
89014
  return new Schema(schemaFieldsFromJSON(_schema, dictionaries), customMetadataFromJSON(_schema['metadata']), dictionaries);
@@ -89033,7 +89180,6 @@ focus outline in that case.
89033
89180
  // KIND, either express or implied. See the License for the
89034
89181
  // specific language governing permissions and limitations
89035
89182
  // under the License.
89036
- /* eslint-disable brace-style */
89037
89183
  var Builder = Builder$2;
89038
89184
  var ByteBuffer = ByteBuffer$2;
89039
89185
  /**