@ni/nimble-components 35.5.3 → 35.5.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.
@@ -32801,7 +32801,8 @@ so this becomes the fallback color for the slot */ ''}
32801
32801
  return new ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to));
32802
32802
  }
32803
32803
  map(mapping) {
32804
- let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
32804
+ let to = mapping.mapResult(this.to, -1);
32805
+ let from = this.from == this.to && ReplaceStep.MAP_BIAS < 0 ? to : mapping.mapResult(this.from, 1);
32805
32806
  if (from.deletedAcross && to.deletedAcross)
32806
32807
  return null;
32807
32808
  return new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice, this.structure);
@@ -32840,6 +32841,15 @@ so this becomes the fallback color for the slot */ ''}
32840
32841
  return new ReplaceStep(json.from, json.to, Slice.fromJSON(schema, json.slice), !!json.structure);
32841
32842
  }
32842
32843
  }
32844
+ /**
32845
+ By default, for backwards compatibility, an inserting step
32846
+ mapped over an insertion at that same position fill move after
32847
+ the inserted content. In a collaborative editing situation, that
32848
+ can make redone insertions appear in unexpected places. You can
32849
+ set this to -1 to make such mapping keep the step before the
32850
+ insertion instead.
32851
+ */
32852
+ ReplaceStep.MAP_BIAS = 1;
32843
32853
  Step$1.jsonID("replace", ReplaceStep);
32844
32854
  /**
32845
32855
  Replace a part of the document with a slice of content, but
@@ -33826,6 +33836,26 @@ so this becomes the fallback color for the slot */ ''}
33826
33836
  }
33827
33837
  function deleteRange$1(tr, from, to) {
33828
33838
  let $from = tr.doc.resolve(from), $to = tr.doc.resolve(to);
33839
+ // When the deleted range spans from the start of one textblock to
33840
+ // the start of another one, move out of the start of both blocks.
33841
+ if ($from.parent.isTextblock && $to.parent.isTextblock && $from.start() != $to.start() &&
33842
+ $from.parentOffset == 0 && $to.parentOffset == 0) {
33843
+ let shared = $from.sharedDepth(to), isolated = false;
33844
+ for (let d = $from.depth; d > shared; d--)
33845
+ if ($from.node(d).type.spec.isolating)
33846
+ isolated = true;
33847
+ for (let d = $to.depth; d > shared; d--)
33848
+ if ($to.node(d).type.spec.isolating)
33849
+ isolated = true;
33850
+ if (!isolated) {
33851
+ for (let d = $from.depth; d > 0 && from == $from.start(d); d--)
33852
+ from = $from.before(d);
33853
+ for (let d = $to.depth; d > 0 && to == $to.start(d); d--)
33854
+ to = $to.before(d);
33855
+ $from = tr.doc.resolve(from);
33856
+ $to = tr.doc.resolve(to);
33857
+ }
33858
+ }
33829
33859
  let covered = coveredDepths($from, $to);
33830
33860
  for (let i = 0; i < covered.length; i++) {
33831
33861
  let depth = covered[i], last = i == covered.length - 1;
@@ -42574,7 +42604,6 @@ so this becomes the fallback color for the slot */ ''}
42574
42604
  return !!findMarkInSet(marks, type, attributes);
42575
42605
  }
42576
42606
  function getMarkRange($pos, type, attributes) {
42577
- var _a;
42578
42607
  if (!$pos || !type) {
42579
42608
  return;
42580
42609
  }
@@ -42585,7 +42614,12 @@ so this becomes the fallback color for the slot */ ''}
42585
42614
  if (!start.node || !start.node.marks.some((mark2) => mark2.type === type)) {
42586
42615
  return;
42587
42616
  }
42588
- attributes = attributes || ((_a = start.node.marks[0]) == null ? void 0 : _a.attrs);
42617
+ if (!attributes) {
42618
+ const firstMark = start.node.marks.find((mark2) => mark2.type === type);
42619
+ if (firstMark) {
42620
+ attributes = firstMark.attrs;
42621
+ }
42622
+ }
42589
42623
  const mark = findMarkInSet([...start.node.marks], type, attributes);
42590
42624
  if (!mark) {
42591
42625
  return;
@@ -42620,7 +42654,7 @@ so this becomes the fallback color for the slot */ ''}
42620
42654
  }
42621
42655
 
42622
42656
  // src/commands/extendMarkRange.ts
42623
- var extendMarkRange = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
42657
+ var extendMarkRange = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
42624
42658
  const type = getMarkType(typeOrName, state.schema);
42625
42659
  const { doc, selection } = tr;
42626
42660
  const { $from, from, to } = selection;
@@ -45875,7 +45909,7 @@ so this becomes the fallback color for the slot */ ''}
45875
45909
  const newEnd = mapping.slice(index).map(step.to);
45876
45910
  const oldStart = mapping.invert().map(newStart, -1);
45877
45911
  const oldEnd = mapping.invert().map(newEnd);
45878
- const foundBeforeMark = (_a3 = nextTransaction.doc.nodeAt(newStart - 1)) == null ? void 0 : _a3.marks.some((mark) => mark.eq(step.mark));
45912
+ const foundBeforeMark = newStart > 0 ? (_a3 = nextTransaction.doc.nodeAt(newStart - 1)) == null ? void 0 : _a3.marks.some((mark) => mark.eq(step.mark)) : false;
45879
45913
  const foundAfterMark = (_b3 = nextTransaction.doc.nodeAt(newEnd)) == null ? void 0 : _b3.marks.some((mark) => mark.eq(step.mark));
45880
45914
  this.editor.emit("delete", {
45881
45915
  type: "mark",
@@ -61856,6 +61890,19 @@ ${nextLine.slice(indentLevel + 2)}`;
61856
61890
  }
61857
61891
 
61858
61892
  // src/suggestion.ts
61893
+ function hasInsertedWhitespace(transaction) {
61894
+ if (!transaction.docChanged) {
61895
+ return false;
61896
+ }
61897
+ return transaction.steps.some((step) => {
61898
+ const slice = step.slice;
61899
+ if (!(slice == null ? void 0 : slice.content)) {
61900
+ return false;
61901
+ }
61902
+ const inserted = slice.content.textBetween(0, slice.content.size, "\n");
61903
+ return /\s/.test(inserted);
61904
+ });
61905
+ }
61859
61906
  var SuggestionPluginKey = new PluginKey("suggestion");
61860
61907
  function Suggestion({
61861
61908
  pluginKey = SuggestionPluginKey,
@@ -61874,10 +61921,12 @@ ${nextLine.slice(indentLevel + 2)}`;
61874
61921
  render = () => ({}),
61875
61922
  allow = () => true,
61876
61923
  findSuggestionMatch: findSuggestionMatch2 = findSuggestionMatch,
61877
- shouldShow
61924
+ shouldShow,
61925
+ shouldResetDismissed
61878
61926
  }) {
61879
61927
  let props;
61880
61928
  const renderer = render == null ? void 0 : render();
61929
+ const effectiveAllowSpaces = allowSpaces && !allowToIncludeChar;
61881
61930
  const getAnchorClientRect = () => {
61882
61931
  const pos = editor.state.selection.$anchor.pos;
61883
61932
  const coords = editor.view.coordsAtPos(pos);
@@ -61899,6 +61948,27 @@ ${nextLine.slice(indentLevel + 2)}`;
61899
61948
  return (currentDecorationNode == null ? void 0 : currentDecorationNode.getBoundingClientRect()) || null;
61900
61949
  };
61901
61950
  };
61951
+ const shouldKeepDismissed = ({
61952
+ match,
61953
+ dismissedRange,
61954
+ state,
61955
+ transaction
61956
+ }) => {
61957
+ if (shouldResetDismissed == null ? void 0 : shouldResetDismissed({
61958
+ editor,
61959
+ state,
61960
+ range: dismissedRange,
61961
+ match,
61962
+ transaction,
61963
+ allowSpaces: effectiveAllowSpaces
61964
+ })) {
61965
+ return false;
61966
+ }
61967
+ if (effectiveAllowSpaces) {
61968
+ return match.range.from === dismissedRange.from;
61969
+ }
61970
+ return match.range.from === dismissedRange.from && !hasInsertedWhitespace(transaction);
61971
+ };
61902
61972
  function dispatchExit(view, pluginKeyRef) {
61903
61973
  var _a;
61904
61974
  try {
@@ -62001,7 +62071,8 @@ ${nextLine.slice(indentLevel + 2)}`;
62001
62071
  },
62002
62072
  query: null,
62003
62073
  text: null,
62004
- composing: false
62074
+ composing: false,
62075
+ dismissedRange: null
62005
62076
  };
62006
62077
  return state;
62007
62078
  },
@@ -62019,9 +62090,16 @@ ${nextLine.slice(indentLevel + 2)}`;
62019
62090
  next.range = { from: 0, to: 0 };
62020
62091
  next.query = null;
62021
62092
  next.text = null;
62093
+ next.dismissedRange = prev.active ? { ...prev.range } : prev.dismissedRange;
62022
62094
  return next;
62023
62095
  }
62024
62096
  next.composing = composing;
62097
+ if (transaction.docChanged && next.dismissedRange !== null) {
62098
+ next.dismissedRange = {
62099
+ from: transaction.mapping.map(next.dismissedRange.from),
62100
+ to: transaction.mapping.map(next.dismissedRange.to)
62101
+ };
62102
+ }
62025
62103
  if (isEditable && (empty || editor.view.composing)) {
62026
62104
  if ((from < prev.range.from || from > prev.range.to) && !composing && !prev.composing) {
62027
62105
  next.active = false;
@@ -62047,12 +62125,27 @@ ${nextLine.slice(indentLevel + 2)}`;
62047
62125
  text: match.text,
62048
62126
  transaction
62049
62127
  }))) {
62050
- next.active = true;
62051
- next.decorationId = prev.decorationId ? prev.decorationId : decorationId;
62052
- next.range = match.range;
62053
- next.query = match.query;
62054
- next.text = match.text;
62128
+ if (next.dismissedRange !== null && !shouldKeepDismissed({
62129
+ match,
62130
+ dismissedRange: next.dismissedRange,
62131
+ state,
62132
+ transaction
62133
+ })) {
62134
+ next.dismissedRange = null;
62135
+ }
62136
+ if (next.dismissedRange === null) {
62137
+ next.active = true;
62138
+ next.decorationId = prev.decorationId ? prev.decorationId : decorationId;
62139
+ next.range = match.range;
62140
+ next.query = match.query;
62141
+ next.text = match.text;
62142
+ } else {
62143
+ next.active = false;
62144
+ }
62055
62145
  } else {
62146
+ if (!match) {
62147
+ next.dismissedRange = null;
62148
+ }
62056
62149
  next.active = false;
62057
62150
  }
62058
62151
  } else {
@@ -62070,41 +62163,18 @@ ${nextLine.slice(indentLevel + 2)}`;
62070
62163
  props: {
62071
62164
  // Call the keydown hook if suggestion is active.
62072
62165
  handleKeyDown(view, event) {
62073
- var _a, _b, _c, _d;
62166
+ var _a, _b;
62074
62167
  const { active, range } = plugin.getState(view.state);
62075
62168
  if (!active) {
62076
62169
  return false;
62077
62170
  }
62078
62171
  if (event.key === "Escape" || event.key === "Esc") {
62079
62172
  const state = plugin.getState(view.state);
62080
- const cachedNode = (_a = props == null ? void 0 : props.decorationNode) != null ? _a : null;
62081
- const decorationNode = cachedNode != null ? cachedNode : (state == null ? void 0 : state.decorationId) ? view.dom.querySelector(`[data-decoration-id="${state.decorationId}"]`) : null;
62082
- const handledByKeyDown = ((_b = renderer == null ? void 0 : renderer.onKeyDown) == null ? void 0 : _b.call(renderer, { view, event, range: state.range })) || false;
62083
- if (handledByKeyDown) {
62084
- return true;
62085
- }
62086
- const exitProps = {
62087
- editor,
62088
- range: state.range,
62089
- query: state.query,
62090
- text: state.text,
62091
- items: [],
62092
- command: (commandProps) => {
62093
- return command({ editor, range: state.range, props: commandProps });
62094
- },
62095
- decorationNode,
62096
- // If we have a cached decoration node, use it for the clientRect
62097
- // to avoid another DOM lookup. If not, leave clientRect null and
62098
- // let consumer decide if they want to query.
62099
- clientRect: decorationNode ? () => {
62100
- return decorationNode.getBoundingClientRect() || null;
62101
- } : null
62102
- };
62103
- (_c = renderer == null ? void 0 : renderer.onExit) == null ? void 0 : _c.call(renderer, exitProps);
62173
+ (_a = renderer == null ? void 0 : renderer.onKeyDown) == null ? void 0 : _a.call(renderer, { view, event, range: state.range });
62104
62174
  dispatchExit(view, pluginKey);
62105
62175
  return true;
62106
62176
  }
62107
- const handled = ((_d = renderer == null ? void 0 : renderer.onKeyDown) == null ? void 0 : _d.call(renderer, { view, event, range })) || false;
62177
+ const handled = ((_b = renderer == null ? void 0 : renderer.onKeyDown) == null ? void 0 : _b.call(renderer, { view, event, range })) || false;
62108
62178
  return handled;
62109
62179
  },
62110
62180
  // Setup decorator on the currently active suggestion.
@@ -62397,7 +62467,8 @@ ${nextLine.slice(indentLevel + 2)}`;
62397
62467
  return helpers.parseChildren([tokens[0]]);
62398
62468
  }
62399
62469
  const content = helpers.parseInline(tokens);
62400
- if (content.length === 1 && content[0].type === "text" && (content[0].text === EMPTY_PARAGRAPH_MARKDOWN || content[0].text === NBSP_CHAR)) {
62470
+ const hasExplicitEmptyParagraphMarker = tokens.length === 1 && tokens[0].type === "text" && (tokens[0].raw === EMPTY_PARAGRAPH_MARKDOWN || tokens[0].text === EMPTY_PARAGRAPH_MARKDOWN || tokens[0].raw === NBSP_CHAR || tokens[0].text === NBSP_CHAR);
62471
+ if (hasExplicitEmptyParagraphMarker && content.length === 1 && content[0].type === "text" && (content[0].text === EMPTY_PARAGRAPH_MARKDOWN || content[0].text === NBSP_CHAR)) {
62401
62472
  return helpers.createNode("paragraph", void 0, []);
62402
62473
  }
62403
62474
  return helpers.createNode("paragraph", void 0, content);
@@ -63714,6 +63785,7 @@ ${nextLine.slice(indentLevel + 2)}`;
63714
63785
  ];
63715
63786
  }
63716
63787
  });
63788
+ var skipTrailingNodeMeta = "skipTrailingNode";
63717
63789
  function nodeEqualsType({ types, node }) {
63718
63790
  return node && Array.isArray(types) && types.includes(node.type) || (node == null ? void 0 : node.type) === types;
63719
63791
  }
@@ -63733,11 +63805,14 @@ ${nextLine.slice(indentLevel + 2)}`;
63733
63805
  return [
63734
63806
  new Plugin({
63735
63807
  key: plugin,
63736
- appendTransaction: (_, __, state) => {
63808
+ appendTransaction: (transactions, __, state) => {
63737
63809
  const { doc, tr, schema } = state;
63738
63810
  const shouldInsertNodeAtEnd = plugin.getState(state);
63739
63811
  const endPosition = doc.content.size;
63740
63812
  const type = schema.nodes[defaultNode];
63813
+ if (transactions.some((transaction) => transaction.getMeta(skipTrailingNodeMeta))) {
63814
+ return;
63815
+ }
63741
63816
  if (!shouldInsertNodeAtEnd) {
63742
63817
  return;
63743
63818
  }