prosemirror-view 1.31.5 → 1.31.6

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.31.6 (2023-07-14)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix a bug that caused `posAtCoords` to return incorrect results for coordinates over inline-decorated text.
6
+
7
+ Don't try to scroll fixed-positioned elements into view by scrolling their parent elements.
8
+
1
9
  ## 1.31.5 (2023-06-19)
2
10
 
3
11
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -238,7 +238,7 @@ function scrollRectIntoView(view, rect, startDOM) {
238
238
  }
239
239
  }
240
240
 
241
- if (atTop) break;
241
+ if (atTop || /^(fixed|sticky)$/.test(getComputedStyle(parent).position)) break;
242
242
  }
243
243
  }
244
244
 
@@ -441,7 +441,7 @@ function posFromCaret(view, node, offset, coords) {
441
441
  if (rect.left > coords.left || rect.top > coords.top) outsideBlock = desc.posBefore;else if (rect.right < coords.left || rect.bottom < coords.top) outsideBlock = desc.posAfter;
442
442
  }
443
443
 
444
- if (!desc.contentDOM && outsideBlock < 0) {
444
+ if (!desc.contentDOM && outsideBlock < 0 && !desc.node.isText) {
445
445
  var before = desc.node.isBlock ? coords.top < (rect.top + rect.bottom) / 2 : coords.left < (rect.left + rect.right) / 2;
446
446
  return before ? desc.posBefore : desc.posAfter;
447
447
  }
@@ -1393,7 +1393,7 @@ var MarkViewDesc = function (_ViewDesc3) {
1393
1393
  return {
1394
1394
  mark: this.mark.type.name,
1395
1395
  attrs: this.mark.attrs,
1396
- contentElement: this.contentDOM || undefined
1396
+ contentElement: this.contentDOM
1397
1397
  };
1398
1398
  }
1399
1399
  }, {
package/dist/index.js CHANGED
@@ -182,7 +182,7 @@ function scrollRectIntoView(view, rect, startDOM) {
182
182
  rect = { left: rect.left - dX, top: rect.top - dY, right: rect.right - dX, bottom: rect.bottom - dY };
183
183
  }
184
184
  }
185
- if (atTop)
185
+ if (atTop || /^(fixed|sticky)$/.test(getComputedStyle(parent).position))
186
186
  break;
187
187
  }
188
188
  }
@@ -356,7 +356,7 @@ function posFromCaret(view, node, offset, coords) {
356
356
  else if (rect.right < coords.left || rect.bottom < coords.top)
357
357
  outsideBlock = desc.posAfter;
358
358
  }
359
- if (!desc.contentDOM && outsideBlock < 0) {
359
+ if (!desc.contentDOM && outsideBlock < 0 && !desc.node.isText) {
360
360
  // If we are inside a leaf, return the side of the leaf closer to the coords
361
361
  let before = desc.node.isBlock ? coords.top < (rect.top + rect.bottom) / 2
362
362
  : coords.left < (rect.left + rect.right) / 2;
@@ -1145,7 +1145,7 @@ class MarkViewDesc extends ViewDesc {
1145
1145
  parseRule() {
1146
1146
  if ((this.dirty & NODE_DIRTY) || this.mark.type.spec.reparseInView)
1147
1147
  return null;
1148
- return { mark: this.mark.type.name, attrs: this.mark.attrs, contentElement: this.contentDOM || undefined };
1148
+ return { mark: this.mark.type.name, attrs: this.mark.attrs, contentElement: this.contentDOM };
1149
1149
  }
1150
1150
  matchesMark(mark) { return this.dirty != NODE_DIRTY && this.mark.eq(mark); }
1151
1151
  markDirty(from, to) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-view",
3
- "version": "1.31.5",
3
+ "version": "1.31.6",
4
4
  "description": "ProseMirror's view component",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
package/src/domcoords.ts CHANGED
@@ -53,7 +53,7 @@ export function scrollRectIntoView(view: EditorView, rect: Rect, startDOM: Node)
53
53
  rect = {left: rect.left - dX, top: rect.top - dY, right: rect.right - dX, bottom: rect.bottom - dY}
54
54
  }
55
55
  }
56
- if (atTop) break
56
+ if (atTop || /^(fixed|sticky)$/.test(getComputedStyle(parent as HTMLElement).position)) break
57
57
  }
58
58
  }
59
59
 
@@ -227,7 +227,7 @@ function posFromCaret(view: EditorView, node: Node, offset: number, coords: {top
227
227
  if (rect.left > coords.left || rect.top > coords.top) outsideBlock = desc.posBefore
228
228
  else if (rect.right < coords.left || rect.bottom < coords.top) outsideBlock = desc.posAfter
229
229
  }
230
- if (!desc.contentDOM && outsideBlock < 0) {
230
+ if (!desc.contentDOM && outsideBlock < 0 && !desc.node.isText) {
231
231
  // If we are inside a leaf, return the side of the leaf closer to the coords
232
232
  let before = desc.node.isBlock ? coords.top < (rect.top + rect.bottom) / 2
233
233
  : coords.left < (rect.left + rect.right) / 2
package/src/viewdesc.ts CHANGED
@@ -562,7 +562,7 @@ class CompositionViewDesc extends ViewDesc {
562
562
  // some cases they will be split more often than would appear
563
563
  // necessary.
564
564
  class MarkViewDesc extends ViewDesc {
565
- constructor(parent: ViewDesc, readonly mark: Mark, dom: DOMNode, contentDOM: HTMLElement | null) {
565
+ constructor(parent: ViewDesc, readonly mark: Mark, dom: DOMNode, contentDOM: HTMLElement) {
566
566
  super(parent, [], dom, contentDOM)
567
567
  }
568
568
 
@@ -576,7 +576,7 @@ class MarkViewDesc extends ViewDesc {
576
576
 
577
577
  parseRule(): ParseRule | null {
578
578
  if ((this.dirty & NODE_DIRTY) || this.mark.type.spec.reparseInView) return null
579
- return {mark: this.mark.type.name, attrs: this.mark.attrs, contentElement: this.contentDOM || undefined}
579
+ return {mark: this.mark.type.name, attrs: this.mark.attrs, contentElement: this.contentDOM!}
580
580
  }
581
581
 
582
582
  matchesMark(mark: Mark) { return this.dirty != NODE_DIRTY && this.mark.eq(mark) }