prosemirror-view 1.26.4 → 1.26.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 1.26.5 (2022-07-07)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue where a composition happening at the same time as widget insertion/removal could corrupt the rendered DOM.
6
+
7
+ Fix a problem where `coordsAtPos` would look inside the DOM for atomic nodes, and sometimes return very odd positions that way.
8
+
1
9
  ## 1.26.4 (2022-07-04)
2
10
 
3
11
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -495,7 +495,8 @@ var BIDI = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
495
495
  function _coordsAtPos(view, pos, side) {
496
496
  var _view$docView$domFrom = view.docView.domFromPos(pos, side < 0 ? -1 : 1),
497
497
  node = _view$docView$domFrom.node,
498
- offset = _view$docView$domFrom.offset;
498
+ offset = _view$docView$domFrom.offset,
499
+ atom = _view$docView$domFrom.atom;
499
500
 
500
501
  var supportEmptyRange = webkit || gecko;
501
502
 
@@ -534,13 +535,15 @@ function _coordsAtPos(view, pos, side) {
534
535
  }
535
536
  }
536
537
 
537
- if (!view.state.doc.resolve(pos).parent.inlineContent) {
538
- if (offset && (side < 0 || offset == nodeSize(node))) {
538
+ var $dom = view.state.doc.resolve(pos - (atom || 0));
539
+
540
+ if (!$dom.parent.inlineContent) {
541
+ if (atom == null && offset && (side < 0 || offset == nodeSize(node))) {
539
542
  var before = node.childNodes[offset - 1];
540
543
  if (before.nodeType == 1) return flattenH(before.getBoundingClientRect(), false);
541
544
  }
542
545
 
543
- if (offset < nodeSize(node)) {
546
+ if (atom == null && offset < nodeSize(node)) {
544
547
  var after = node.childNodes[offset];
545
548
  if (after.nodeType == 1) return flattenH(after.getBoundingClientRect(), true);
546
549
  }
@@ -548,13 +551,13 @@ function _coordsAtPos(view, pos, side) {
548
551
  return flattenH(node.getBoundingClientRect(), side >= 0);
549
552
  }
550
553
 
551
- if (offset && (side < 0 || offset == nodeSize(node))) {
554
+ if (atom == null && offset && (side < 0 || offset == nodeSize(node))) {
552
555
  var _before = node.childNodes[offset - 1];
553
556
  var target = _before.nodeType == 3 ? textRange(_before, nodeSize(_before) - (supportEmptyRange ? 0 : 1)) : _before.nodeType == 1 && (_before.nodeName != "BR" || !_before.nextSibling) ? _before : null;
554
557
  if (target) return flattenV(singleRect(target, 1), false);
555
558
  }
556
559
 
557
- if (offset < nodeSize(node)) {
560
+ if (atom == null && offset < nodeSize(node)) {
558
561
  var _after = node.childNodes[offset];
559
562
 
560
563
  while (_after.pmViewDesc && _after.pmViewDesc.ignoreForCoords) {
@@ -905,7 +908,8 @@ var ViewDesc = function () {
905
908
  value: function domFromPos(pos, side) {
906
909
  if (!this.contentDOM) return {
907
910
  node: this.dom,
908
- offset: 0
911
+ offset: 0,
912
+ atom: pos + 1
909
913
  };
910
914
  var i = 0,
911
915
  offset = 0;
@@ -2077,7 +2081,7 @@ var ViewTreeUpdater = function () {
2077
2081
  if (child.dirty == NODE_DIRTY && child.dom == child.contentDOM) child.dirty = CONTENT_DIRTY;
2078
2082
  if (!child.update(node, outerDeco, innerDeco, view)) return false;
2079
2083
  this.destroyBetween(this.index, index);
2080
- this.index = index + 1;
2084
+ this.index++;
2081
2085
  return true;
2082
2086
  }
2083
2087
  }, {
package/dist/index.d.ts CHANGED
@@ -326,6 +326,7 @@ declare class ViewDesc {
326
326
  domFromPos(pos: number, side: number): {
327
327
  node: DOMNode;
328
328
  offset: number;
329
+ atom?: number;
329
330
  };
330
331
  parseRange(from: number, to: number, base?: number): {
331
332
  node: DOMNode;
package/dist/index.js CHANGED
@@ -422,7 +422,7 @@ const BIDI = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
422
422
  // Given a position in the document model, get a bounding box of the
423
423
  // character at that position, relative to the window.
424
424
  function coordsAtPos(view, pos, side) {
425
- let { node, offset } = view.docView.domFromPos(pos, side < 0 ? -1 : 1);
425
+ let { node, offset, atom } = view.docView.domFromPos(pos, side < 0 ? -1 : 1);
426
426
  let supportEmptyRange = webkit || gecko;
427
427
  if (node.nodeType == 3) {
428
428
  // These browsers support querying empty text ranges. Prefer that in
@@ -461,14 +461,15 @@ function coordsAtPos(view, pos, side) {
461
461
  return flattenV(singleRect(textRange(node, from, to), takeSide), takeSide < 0);
462
462
  }
463
463
  }
464
+ let $dom = view.state.doc.resolve(pos - (atom || 0));
464
465
  // Return a horizontal line in block context
465
- if (!view.state.doc.resolve(pos).parent.inlineContent) {
466
- if (offset && (side < 0 || offset == nodeSize(node))) {
466
+ if (!$dom.parent.inlineContent) {
467
+ if (atom == null && offset && (side < 0 || offset == nodeSize(node))) {
467
468
  let before = node.childNodes[offset - 1];
468
469
  if (before.nodeType == 1)
469
470
  return flattenH(before.getBoundingClientRect(), false);
470
471
  }
471
- if (offset < nodeSize(node)) {
472
+ if (atom == null && offset < nodeSize(node)) {
472
473
  let after = node.childNodes[offset];
473
474
  if (after.nodeType == 1)
474
475
  return flattenH(after.getBoundingClientRect(), true);
@@ -476,7 +477,7 @@ function coordsAtPos(view, pos, side) {
476
477
  return flattenH(node.getBoundingClientRect(), side >= 0);
477
478
  }
478
479
  // Inline, not in text node (this is not Bidi-safe)
479
- if (offset && (side < 0 || offset == nodeSize(node))) {
480
+ if (atom == null && offset && (side < 0 || offset == nodeSize(node))) {
480
481
  let before = node.childNodes[offset - 1];
481
482
  let target = before.nodeType == 3 ? textRange(before, nodeSize(before) - (supportEmptyRange ? 0 : 1))
482
483
  // BR nodes tend to only return the rectangle before them.
@@ -485,7 +486,7 @@ function coordsAtPos(view, pos, side) {
485
486
  if (target)
486
487
  return flattenV(singleRect(target, 1), false);
487
488
  }
488
- if (offset < nodeSize(node)) {
489
+ if (atom == null && offset < nodeSize(node)) {
489
490
  let after = node.childNodes[offset];
490
491
  while (after.pmViewDesc && after.pmViewDesc.ignoreForCoords)
491
492
  after = after.nextSibling;
@@ -797,7 +798,7 @@ class ViewDesc {
797
798
  }
798
799
  domFromPos(pos, side) {
799
800
  if (!this.contentDOM)
800
- return { node: this.dom, offset: 0 };
801
+ return { node: this.dom, offset: 0, atom: pos + 1 };
801
802
  // First find the position in the child array
802
803
  let i = 0, offset = 0;
803
804
  for (let curPos = 0; i < this.children.length; i++) {
@@ -1723,7 +1724,7 @@ class ViewTreeUpdater {
1723
1724
  if (!child.update(node, outerDeco, innerDeco, view))
1724
1725
  return false;
1725
1726
  this.destroyBetween(this.index, index);
1726
- this.index = index + 1;
1727
+ this.index++;
1727
1728
  return true;
1728
1729
  }
1729
1730
  findIndexWithChild(domNode) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-view",
3
- "version": "1.26.4",
3
+ "version": "1.26.5",
4
4
  "description": "ProseMirror's view component",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
package/src/domcoords.ts CHANGED
@@ -315,7 +315,7 @@ const BIDI = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/
315
315
  // Given a position in the document model, get a bounding box of the
316
316
  // character at that position, relative to the window.
317
317
  export function coordsAtPos(view: EditorView, pos: number, side: number): Rect {
318
- let {node, offset} = view.docView.domFromPos(pos, side < 0 ? -1 : 1)
318
+ let {node, offset, atom} = view.docView.domFromPos(pos, side < 0 ? -1 : 1)
319
319
 
320
320
  let supportEmptyRange = browser.webkit || browser.gecko
321
321
  if (node.nodeType == 3) {
@@ -345,13 +345,14 @@ export function coordsAtPos(view: EditorView, pos: number, side: number): Rect {
345
345
  }
346
346
  }
347
347
 
348
+ let $dom = view.state.doc.resolve(pos - (atom || 0))
348
349
  // Return a horizontal line in block context
349
- if (!view.state.doc.resolve(pos).parent.inlineContent) {
350
- if (offset && (side < 0 || offset == nodeSize(node))) {
350
+ if (!$dom.parent.inlineContent) {
351
+ if (atom == null && offset && (side < 0 || offset == nodeSize(node))) {
351
352
  let before = node.childNodes[offset - 1]
352
353
  if (before.nodeType == 1) return flattenH((before as HTMLElement).getBoundingClientRect(), false)
353
354
  }
354
- if (offset < nodeSize(node)) {
355
+ if (atom == null && offset < nodeSize(node)) {
355
356
  let after = node.childNodes[offset]
356
357
  if (after.nodeType == 1) return flattenH((after as HTMLElement).getBoundingClientRect(), true)
357
358
  }
@@ -359,7 +360,7 @@ export function coordsAtPos(view: EditorView, pos: number, side: number): Rect {
359
360
  }
360
361
 
361
362
  // Inline, not in text node (this is not Bidi-safe)
362
- if (offset && (side < 0 || offset == nodeSize(node))) {
363
+ if (atom == null && offset && (side < 0 || offset == nodeSize(node))) {
363
364
  let before = node.childNodes[offset - 1]
364
365
  let target = before.nodeType == 3 ? textRange(before as Text, nodeSize(before) - (supportEmptyRange ? 0 : 1))
365
366
  // BR nodes tend to only return the rectangle before them.
@@ -367,7 +368,7 @@ export function coordsAtPos(view: EditorView, pos: number, side: number): Rect {
367
368
  : before.nodeType == 1 && (before.nodeName != "BR" || !before.nextSibling) ? before : null
368
369
  if (target) return flattenV(singleRect(target as Range | HTMLElement, 1), false)
369
370
  }
370
- if (offset < nodeSize(node)) {
371
+ if (atom == null && offset < nodeSize(node)) {
371
372
  let after = node.childNodes[offset]
372
373
  while (after.pmViewDesc && after.pmViewDesc.ignoreForCoords) after = after.nextSibling!
373
374
  let target = !after ? null : after.nodeType == 3 ? textRange(after as Text, 0, (supportEmptyRange ? 0 : 1))
package/src/viewdesc.ts CHANGED
@@ -262,8 +262,8 @@ export class ViewDesc {
262
262
  }
263
263
  }
264
264
 
265
- domFromPos(pos: number, side: number): {node: DOMNode, offset: number} {
266
- if (!this.contentDOM) return {node: this.dom, offset: 0}
265
+ domFromPos(pos: number, side: number): {node: DOMNode, offset: number, atom?: number} {
266
+ if (!this.contentDOM) return {node: this.dom, offset: 0, atom: pos + 1}
267
267
  // First find the position in the child array
268
268
  let i = 0, offset = 0
269
269
  for (let curPos = 0; i < this.children.length; i++) {
@@ -1196,7 +1196,7 @@ class ViewTreeUpdater {
1196
1196
  if (child.dirty == NODE_DIRTY && child.dom == child.contentDOM) child.dirty = CONTENT_DIRTY
1197
1197
  if (!child.update(node, outerDeco, innerDeco, view)) return false
1198
1198
  this.destroyBetween(this.index, index)
1199
- this.index = index + 1
1199
+ this.index++
1200
1200
  return true
1201
1201
  }
1202
1202