@ni/nimble-components 35.1.0 → 35.1.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.
@@ -33189,6 +33189,27 @@ so this becomes the fallback color for the slot */ ''}
33189
33189
  return this.steps.length > 0;
33190
33190
  }
33191
33191
  /**
33192
+ Return a single range, in post-transform document positions,
33193
+ that covers all content changed by this transform. Returns null
33194
+ if no replacements are made. Note that this will ignore changes
33195
+ that add/remove marks without replacing the underlying content.
33196
+ */
33197
+ changedRange() {
33198
+ let from = 1e9, to = -1e9;
33199
+ for (let i = 0; i < this.mapping.maps.length; i++) {
33200
+ let map = this.mapping.maps[i];
33201
+ if (i) {
33202
+ from = map.map(from, 1);
33203
+ to = map.map(to, -1);
33204
+ }
33205
+ map.forEach((_f, _t, fromB, toB) => {
33206
+ from = Math.min(from, fromB);
33207
+ to = Math.max(to, toB);
33208
+ });
33209
+ }
33210
+ return from == 1e9 ? null : { from, to };
33211
+ }
33212
+ /**
33192
33213
  @internal
33193
33214
  */
33194
33215
  addStep(step, doc) {
@@ -41840,8 +41861,12 @@ so this becomes the fallback color for the slot */ ''}
41840
41861
  }
41841
41862
  });
41842
41863
  };
41843
- if (view.hasFocus() && position === null || position === false) {
41844
- return true;
41864
+ try {
41865
+ if (view.hasFocus() && position === null || position === false) {
41866
+ return true;
41867
+ }
41868
+ } catch {
41869
+ return false;
41845
41870
  }
41846
41871
  if (dispatch && position === null && !isTextSelection(editor.state.selection)) {
41847
41872
  delayedFocus();
@@ -45286,19 +45311,20 @@ so this becomes the fallback color for the slot */ ''}
45286
45311
  this.node.content.forEach((node, offset) => {
45287
45312
  const isBlock = node.isBlock && !node.isTextblock;
45288
45313
  const isNonTextAtom = node.isAtom && !node.isText;
45314
+ const isInline = node.isInline;
45289
45315
  const targetPos = this.pos + offset + (isNonTextAtom ? 0 : 1);
45290
45316
  if (targetPos < 0 || targetPos > this.resolvedPos.doc.nodeSize - 2) {
45291
45317
  return;
45292
45318
  }
45293
45319
  const $pos = this.resolvedPos.doc.resolve(targetPos);
45294
- if (!isBlock && $pos.depth <= this.depth) {
45320
+ if (!isBlock && !isInline && $pos.depth <= this.depth) {
45295
45321
  return;
45296
45322
  }
45297
- const childNodePos = new _NodePos($pos, this.editor, isBlock, isBlock ? node : null);
45323
+ const childNodePos = new _NodePos($pos, this.editor, isBlock, isBlock || isInline ? node : null);
45298
45324
  if (isBlock) {
45299
45325
  childNodePos.actualDepth = this.depth + 1;
45300
45326
  }
45301
- children.push(new _NodePos($pos, this.editor, isBlock, isBlock ? node : null));
45327
+ children.push(childNodePos);
45302
45328
  });
45303
45329
  return children;
45304
45330
  }
@@ -56586,8 +56612,7 @@ ${renderedContent}
56586
56612
  }
56587
56613
  if (node && node.isText && marks.some(mark => {
56588
56614
  let info = this.getMark(mark.type.name);
56589
- return info && info.expelEnclosingWhitespace &&
56590
- (index == parent.childCount - 1 || !mark.isInSet(parent.child(index + 1).marks));
56615
+ return info && info.expelEnclosingWhitespace && !this.isMarkAhead(parent, index + 1, mark);
56591
56616
  })) {
56592
56617
  let [_, rest, trail] = /^(.*?)(\s*)$/m.exec(node.text);
56593
56618
  if (trail) {
@@ -56731,6 +56756,19 @@ ${renderedContent}
56731
56756
  trailing: (text.match(/(\s+)$/) || [undefined])[0]
56732
56757
  };
56733
56758
  }
56759
+ /**
56760
+ @internal
56761
+ */
56762
+ isMarkAhead(parent, index, mark) {
56763
+ for (;; index++) {
56764
+ if (index == parent.childCount)
56765
+ return false;
56766
+ let next = parent.child(index);
56767
+ if (next.type.name != this.options.hardBreakNodeName)
56768
+ return mark.isInSet(next.marks);
56769
+ index++;
56770
+ }
56771
+ }
56734
56772
  }
56735
56773
 
56736
56774
  var _a$4;
@@ -59429,31 +59467,33 @@ ${renderedContent}
59429
59467
  if (!view.editable) {
59430
59468
  return false;
59431
59469
  }
59470
+ let link = null;
59471
+ if (event.target instanceof HTMLAnchorElement) {
59472
+ link = event.target;
59473
+ } else {
59474
+ const target = event.target;
59475
+ if (!target) {
59476
+ return false;
59477
+ }
59478
+ const root = options.editor.view.dom;
59479
+ link = target.closest("a");
59480
+ if (link && !root.contains(link)) {
59481
+ link = null;
59482
+ }
59483
+ }
59484
+ if (!link) {
59485
+ return false;
59486
+ }
59432
59487
  let handled = false;
59433
59488
  if (options.enableClickSelection) {
59434
59489
  const commandResult = options.editor.commands.extendMarkRange(options.type.name);
59435
59490
  handled = commandResult;
59436
59491
  }
59437
59492
  if (options.openOnClick) {
59438
- let link = null;
59439
- if (event.target instanceof HTMLAnchorElement) {
59440
- link = event.target;
59441
- } else {
59442
- let a = event.target;
59443
- const els = [];
59444
- while (a.nodeName !== "DIV") {
59445
- els.push(a);
59446
- a = a.parentNode;
59447
- }
59448
- link = els.find((value) => value.nodeName === "A");
59449
- }
59450
- if (!link) {
59451
- return handled;
59452
- }
59453
59493
  const attrs = getAttributes(view.state, options.type.name);
59454
- const href = (_a = link == null ? void 0 : link.href) != null ? _a : attrs.href;
59455
- const target = (_b = link == null ? void 0 : link.target) != null ? _b : attrs.target;
59456
- if (link && href) {
59494
+ const href = (_a = link.href) != null ? _a : attrs.href;
59495
+ const target = (_b = link.target) != null ? _b : attrs.target;
59496
+ if (href) {
59457
59497
  window.open(href, target);
59458
59498
  handled = true;
59459
59499
  }
@@ -59890,11 +59930,13 @@ ${renderedContent}
59890
59930
  node,
59891
59931
  h,
59892
59932
  (context) => {
59933
+ var _a, _b;
59893
59934
  if (context.parentType === "bulletList") {
59894
59935
  return "- ";
59895
59936
  }
59896
59937
  if (context.parentType === "orderedList") {
59897
- return `${context.index + 1}. `;
59938
+ const start = ((_b = (_a = context.meta) == null ? void 0 : _a.parentAttrs) == null ? void 0 : _b.start) || 1;
59939
+ return `${start + context.index}. `;
59898
59940
  }
59899
59941
  return "- ";
59900
59942
  },
@@ -61346,6 +61388,8 @@ ${nextLine.slice(indentLevel + 2)}`;
61346
61388
  var index_default$2 = Mention;
61347
61389
 
61348
61390
  // src/paragraph.ts
61391
+ var EMPTY_PARAGRAPH_MARKDOWN = "&nbsp;";
61392
+ var NBSP_CHAR = "\xA0";
61349
61393
  var Paragraph = Node3.create({
61350
61394
  name: "paragraph",
61351
61395
  priority: 1e3,
@@ -61367,18 +61411,21 @@ ${nextLine.slice(indentLevel + 2)}`;
61367
61411
  if (tokens.length === 1 && tokens[0].type === "image") {
61368
61412
  return helpers.parseChildren([tokens[0]]);
61369
61413
  }
61370
- return helpers.createNode(
61371
- "paragraph",
61372
- void 0,
61373
- // no attributes for paragraph
61374
- helpers.parseInline(tokens)
61375
- );
61414
+ const content = helpers.parseInline(tokens);
61415
+ if (content.length === 1 && content[0].type === "text" && (content[0].text === EMPTY_PARAGRAPH_MARKDOWN || content[0].text === NBSP_CHAR)) {
61416
+ return helpers.createNode("paragraph", void 0, []);
61417
+ }
61418
+ return helpers.createNode("paragraph", void 0, content);
61376
61419
  },
61377
61420
  renderMarkdown: (node, h) => {
61378
- if (!node || !Array.isArray(node.content)) {
61421
+ if (!node) {
61379
61422
  return "";
61380
61423
  }
61381
- return h.renderChildren(node.content);
61424
+ const content = Array.isArray(node.content) ? node.content : [];
61425
+ if (content.length === 0) {
61426
+ return EMPTY_PARAGRAPH_MARKDOWN;
61427
+ }
61428
+ return h.renderChildren(content);
61382
61429
  },
61383
61430
  addCommands() {
61384
61431
  return {
@@ -62589,12 +62636,17 @@ ${nextLine.slice(indentLevel + 2)}`;
62589
62636
  };
62590
62637
  }
62591
62638
  });
62639
+ var DEFAULT_DATA_ATTRIBUTE = "placeholder";
62640
+ function preparePlaceholderAttribute(attr) {
62641
+ return attr.replace(/\s+/g, "-").replace(/[^a-zA-Z0-9-]/g, "").replace(/^[0-9-]+/, "").replace(/^-+/, "").toLowerCase();
62642
+ }
62592
62643
  var Placeholder = Extension.create({
62593
62644
  name: "placeholder",
62594
62645
  addOptions() {
62595
62646
  return {
62596
62647
  emptyEditorClass: "is-editor-empty",
62597
62648
  emptyNodeClass: "is-empty",
62649
+ dataAttribute: DEFAULT_DATA_ATTRIBUTE,
62598
62650
  placeholder: "Write something \u2026",
62599
62651
  showOnlyWhenEditable: true,
62600
62652
  showOnlyCurrent: true,
@@ -62602,6 +62654,7 @@ ${nextLine.slice(indentLevel + 2)}`;
62602
62654
  };
62603
62655
  },
62604
62656
  addProseMirrorPlugins() {
62657
+ const dataAttribute = this.options.dataAttribute ? `data-${preparePlaceholderAttribute(this.options.dataAttribute)}` : `data-${DEFAULT_DATA_ATTRIBUTE}`;
62605
62658
  return [
62606
62659
  new Plugin({
62607
62660
  key: new PluginKey("placeholder"),
@@ -62624,7 +62677,7 @@ ${nextLine.slice(indentLevel + 2)}`;
62624
62677
  }
62625
62678
  const decoration = Decoration.node(pos, pos + node.nodeSize, {
62626
62679
  class: classes.join(" "),
62627
- "data-placeholder": typeof this.options.placeholder === "function" ? this.options.placeholder({
62680
+ [dataAttribute]: typeof this.options.placeholder === "function" ? this.options.placeholder({
62628
62681
  editor: this.editor,
62629
62682
  node,
62630
62683
  pos,