prosemirror-view 1.37.1 → 1.38.0

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,17 @@
1
+ ## 1.38.0 (2025-02-12)
2
+
3
+ ### New features
4
+
5
+ The clipboard serialization logic is now available as a `serializeToClipboard` method on the view object.
6
+
7
+ ## 1.37.2 (2025-01-22)
8
+
9
+ ### Bug fixes
10
+
11
+ Fix a bug that caused `EditorView.nodeDOM` to sometimes not return a DOM node when querying a node next to a widget.
12
+
13
+ Fix an issue where an editor would, when scrolling the selection into view, try to do so even if the selection wasn't in that editor.
14
+
1
15
  ## 1.37.1 (2024-12-11)
2
16
 
3
17
  ### Bug fixes
@@ -2068,18 +2082,14 @@ Transactions that update the selection because of mouse or touch input now get a
2068
2082
 
2069
2083
  ## 0.16.0 (2016-12-23)
2070
2084
 
2071
- ### Bug fixes
2072
-
2073
- Solve problem where setting a node selection would trigger a DOM read, leading to the selection being reset.
2074
-
2075
- ## 0.16.0 (2016-12-23)
2076
-
2077
2085
  ### Breaking changes
2078
2086
 
2079
2087
  The `spellcheck`, `label`, and `class` props are now replaced by an [`attributes` prop](https://prosemirror.net/docs/ref/version/0.16.0.html#view.EditorProps.attributes).
2080
2088
 
2081
2089
  ### Bug fixes
2082
2090
 
2091
+ Solve problem where setting a node selection would trigger a DOM read, leading to the selection being reset.
2092
+
2083
2093
  Ignoring/aborting an action should no longer lead to the DOM being stuck in an outdated state.
2084
2094
 
2085
2095
  Typing at the end of a textblock which ends in a non-text node now actually works.
package/dist/index.cjs CHANGED
@@ -810,7 +810,15 @@ var ViewDesc = function () {
810
810
  var child = this.children[i],
811
811
  end = offset + child.size;
812
812
  if (offset == pos && end != offset) {
813
- while (!child.border && child.children.length) child = child.children[0];
813
+ while (!child.border && child.children.length) {
814
+ for (var _i = 0; _i < child.children.length; _i++) {
815
+ var inner = child.children[_i];
816
+ if (inner.size) {
817
+ child = inner;
818
+ break;
819
+ }
820
+ }
821
+ }
814
822
  return child;
815
823
  }
816
824
  if (pos < end) return child.descAt(pos - offset - child.border);
@@ -1700,7 +1708,7 @@ function patchAttributes(dom, prev, cur) {
1700
1708
  var prevList = prev["class"] ? prev["class"].split(" ").filter(Boolean) : [];
1701
1709
  var curList = cur["class"] ? cur["class"].split(" ").filter(Boolean) : [];
1702
1710
  for (var i = 0; i < prevList.length; i++) if (curList.indexOf(prevList[i]) == -1) dom.classList.remove(prevList[i]);
1703
- for (var _i = 0; _i < curList.length; _i++) if (prevList.indexOf(curList[_i]) == -1) dom.classList.add(curList[_i]);
1711
+ for (var _i2 = 0; _i2 < curList.length; _i2++) if (prevList.indexOf(curList[_i2]) == -1) dom.classList.add(curList[_i2]);
1704
1712
  if (dom.classList.length == 0) dom.removeAttribute("class");
1705
1713
  }
1706
1714
  if (prev.style != cur.style) {
@@ -2020,7 +2028,7 @@ function iterDeco(parent, deco, onWidget, onNode) {
2020
2028
  if (widget) {
2021
2029
  if (widgets) {
2022
2030
  widgets.sort(compareSide);
2023
- for (var _i2 = 0; _i2 < widgets.length; _i2++) onWidget(widgets[_i2], parentIndex, !!restNode);
2031
+ for (var _i3 = 0; _i3 < widgets.length; _i3++) onWidget(widgets[_i3], parentIndex, !!restNode);
2024
2032
  } else {
2025
2033
  onWidget(widget, parentIndex, !!restNode);
2026
2034
  }
@@ -2037,13 +2045,13 @@ function iterDeco(parent, deco, onWidget, onNode) {
2037
2045
  } else {
2038
2046
  break;
2039
2047
  }
2040
- for (var _i3 = 0; _i3 < active.length; _i3++) if (active[_i3].to <= offset) active.splice(_i3--, 1);
2048
+ for (var _i4 = 0; _i4 < active.length; _i4++) if (active[_i4].to <= offset) active.splice(_i4--, 1);
2041
2049
  while (decoIndex < locals.length && locals[decoIndex].from <= offset && locals[decoIndex].to > offset) active.push(locals[decoIndex++]);
2042
2050
  var end = offset + _child.nodeSize;
2043
2051
  if (_child.isText) {
2044
2052
  var cutAt = end;
2045
2053
  if (decoIndex < locals.length && locals[decoIndex].from < cutAt) cutAt = locals[decoIndex].from;
2046
- for (var _i4 = 0; _i4 < active.length; _i4++) if (active[_i4].to < cutAt) cutAt = active[_i4].to;
2054
+ for (var _i5 = 0; _i5 < active.length; _i5++) if (active[_i5].to < cutAt) cutAt = active[_i5].to;
2047
2055
  if (cutAt < end) {
2048
2056
  restNode = _child.cut(cutAt - offset);
2049
2057
  _child = _child.cut(0, cutAt - offset);
@@ -2601,7 +2609,7 @@ function captureKeyDown(view, event) {
2601
2609
  }
2602
2610
  return false;
2603
2611
  }
2604
- function serializeForClipboard(view, slice) {
2612
+ function _serializeForClipboard(view, slice) {
2605
2613
  view.someProp("transformCopied", function (f) {
2606
2614
  slice = f(slice, view);
2607
2615
  });
@@ -3346,7 +3354,7 @@ handlers.copy = editHandlers.cut = function (view, _event) {
3346
3354
  if (sel.empty) return;
3347
3355
  var data = brokenClipboardAPI ? null : event.clipboardData;
3348
3356
  var slice = sel.content(),
3349
- _serializeForClipboar = serializeForClipboard(view, slice),
3357
+ _serializeForClipboar = _serializeForClipboard(view, slice),
3350
3358
  dom = _serializeForClipboar.dom,
3351
3359
  text = _serializeForClipboar.text;
3352
3360
  if (data) {
@@ -3422,7 +3430,7 @@ handlers.dragstart = function (view, _event) {
3422
3430
  if (desc && desc.node.type.spec.draggable && desc != view.docView) node = prosemirrorState.NodeSelection.create(view.state.doc, desc.posBefore);
3423
3431
  }
3424
3432
  var draggedSlice = (node || view.state.selection).content();
3425
- var _serializeForClipboar2 = serializeForClipboard(view, draggedSlice),
3433
+ var _serializeForClipboar2 = _serializeForClipboard(view, draggedSlice),
3426
3434
  dom = _serializeForClipboar2.dom,
3427
3435
  text = _serializeForClipboar2.text,
3428
3436
  slice = _serializeForClipboar2.slice;
@@ -3717,10 +3725,10 @@ var DecorationSet = function () {
3717
3725
  var span = this.local[i];
3718
3726
  if (span.from <= end && span.to >= start && (!predicate || predicate(span.spec))) result.push(span.copy(span.from + offset, span.to + offset));
3719
3727
  }
3720
- for (var _i5 = 0; _i5 < this.children.length; _i5 += 3) {
3721
- if (this.children[_i5] < end && this.children[_i5 + 1] > start) {
3722
- var childOff = this.children[_i5] + 1;
3723
- this.children[_i5 + 2].findInner(start - childOff, end - childOff, result, offset + childOff, predicate);
3728
+ for (var _i6 = 0; _i6 < this.children.length; _i6 += 3) {
3729
+ if (this.children[_i6] < end && this.children[_i6 + 1] > start) {
3730
+ var childOff = this.children[_i6] + 1;
3731
+ this.children[_i6 + 2].findInner(start - childOff, end - childOff, result, offset + childOff, predicate);
3724
3732
  }
3725
3733
  }
3726
3734
  }
@@ -3797,7 +3805,7 @@ var DecorationSet = function () {
3797
3805
  i -= 3;
3798
3806
  }
3799
3807
  }
3800
- if (local.length) for (var _i6 = 0, _span; _i6 < decorations.length; _i6++) if (_span = decorations[_i6]) {
3808
+ if (local.length) for (var _i7 = 0, _span; _i7 < decorations.length; _i7++) if (_span = decorations[_i7]) {
3801
3809
  for (var _j2 = 0; _j2 < local.length; _j2++) if (local[_j2].eq(_span, offset)) {
3802
3810
  if (local == this.local) local = this.local.slice();
3803
3811
  local.splice(_j2--, 1);
@@ -3818,8 +3826,8 @@ var DecorationSet = function () {
3818
3826
  }
3819
3827
  var start = offset + 1,
3820
3828
  end = start + node.content.size;
3821
- for (var _i7 = 0; _i7 < this.local.length; _i7++) {
3822
- var dec = this.local[_i7];
3829
+ for (var _i8 = 0; _i8 < this.local.length; _i8++) {
3830
+ var dec = this.local[_i8];
3823
3831
  if (dec.from < end && dec.to > start && dec.type instanceof InlineType) {
3824
3832
  var from = Math.max(start, dec.from) - start,
3825
3833
  to = Math.min(end, dec.to) - start;
@@ -3838,7 +3846,7 @@ var DecorationSet = function () {
3838
3846
  if (this == other) return true;
3839
3847
  if (!(other instanceof DecorationSet) || this.local.length != other.local.length || this.children.length != other.children.length) return false;
3840
3848
  for (var i = 0; i < this.local.length; i++) if (!this.local[i].eq(other.local[i])) return false;
3841
- for (var _i8 = 0; _i8 < this.children.length; _i8 += 3) if (this.children[_i8] != other.children[_i8] || this.children[_i8 + 1] != other.children[_i8 + 1] || !this.children[_i8 + 2].eq(other.children[_i8 + 2])) return false;
3849
+ for (var _i9 = 0; _i9 < this.children.length; _i9 += 3) if (this.children[_i9] != other.children[_i9] || this.children[_i9 + 1] != other.children[_i9 + 1] || !this.children[_i9 + 2].eq(other.children[_i9 + 2])) return false;
3842
3850
  return true;
3843
3851
  }
3844
3852
  }, {
@@ -3955,15 +3963,15 @@ function mapChildren(oldChildren, newLocal, mapping, node, offset, oldOffset, op
3955
3963
  var moved = 0;
3956
3964
  mapping.maps[i].forEach(function (oldStart, oldEnd, newStart, newEnd) {
3957
3965
  var dSize = newEnd - newStart - (oldEnd - oldStart);
3958
- for (var _i12 = 0; _i12 < children.length; _i12 += 3) {
3959
- var end = children[_i12 + 1];
3966
+ for (var _i13 = 0; _i13 < children.length; _i13 += 3) {
3967
+ var end = children[_i13 + 1];
3960
3968
  if (end < 0 || oldStart > end + _baseOffset - moved) continue;
3961
- var start = children[_i12] + _baseOffset - moved;
3969
+ var start = children[_i13] + _baseOffset - moved;
3962
3970
  if (oldEnd >= start) {
3963
- children[_i12 + 1] = oldStart <= start ? -2 : -1;
3971
+ children[_i13 + 1] = oldStart <= start ? -2 : -1;
3964
3972
  } else if (oldStart >= _baseOffset && dSize) {
3965
- children[_i12] += dSize;
3966
- children[_i12 + 1] += dSize;
3973
+ children[_i13] += dSize;
3974
+ children[_i13 + 1] += dSize;
3967
3975
  }
3968
3976
  }
3969
3977
  moved += dSize;
@@ -3975,32 +3983,32 @@ function mapChildren(oldChildren, newLocal, mapping, node, offset, oldOffset, op
3975
3983
  _loop4(baseOffset);
3976
3984
  }
3977
3985
  var mustRebuild = false;
3978
- for (var _i9 = 0; _i9 < children.length; _i9 += 3) if (children[_i9 + 1] < 0) {
3979
- if (children[_i9 + 1] == -2) {
3986
+ for (var _i10 = 0; _i10 < children.length; _i10 += 3) if (children[_i10 + 1] < 0) {
3987
+ if (children[_i10 + 1] == -2) {
3980
3988
  mustRebuild = true;
3981
- children[_i9 + 1] = -1;
3989
+ children[_i10 + 1] = -1;
3982
3990
  continue;
3983
3991
  }
3984
- var from = mapping.map(oldChildren[_i9] + oldOffset),
3992
+ var from = mapping.map(oldChildren[_i10] + oldOffset),
3985
3993
  fromLocal = from - offset;
3986
3994
  if (fromLocal < 0 || fromLocal >= node.content.size) {
3987
3995
  mustRebuild = true;
3988
3996
  continue;
3989
3997
  }
3990
- var to = mapping.map(oldChildren[_i9 + 1] + oldOffset, -1),
3998
+ var to = mapping.map(oldChildren[_i10 + 1] + oldOffset, -1),
3991
3999
  toLocal = to - offset;
3992
4000
  var _node$content$findInd2 = node.content.findIndex(fromLocal),
3993
4001
  index = _node$content$findInd2.index,
3994
4002
  childOffset = _node$content$findInd2.offset;
3995
4003
  var childNode = node.maybeChild(index);
3996
4004
  if (childNode && childOffset == fromLocal && childOffset + childNode.nodeSize == toLocal) {
3997
- var mapped = children[_i9 + 2].mapInner(mapping, childNode, from + 1, oldChildren[_i9] + oldOffset + 1, options);
4005
+ var mapped = children[_i10 + 2].mapInner(mapping, childNode, from + 1, oldChildren[_i10] + oldOffset + 1, options);
3998
4006
  if (mapped != empty) {
3999
- children[_i9] = fromLocal;
4000
- children[_i9 + 1] = toLocal;
4001
- children[_i9 + 2] = mapped;
4007
+ children[_i10] = fromLocal;
4008
+ children[_i10 + 1] = toLocal;
4009
+ children[_i10 + 2] = mapped;
4002
4010
  } else {
4003
- children[_i9 + 1] = -2;
4011
+ children[_i10 + 1] = -2;
4004
4012
  mustRebuild = true;
4005
4013
  }
4006
4014
  } else {
@@ -4011,14 +4019,14 @@ function mapChildren(oldChildren, newLocal, mapping, node, offset, oldOffset, op
4011
4019
  var decorations = mapAndGatherRemainingDecorations(children, oldChildren, newLocal, mapping, offset, oldOffset, options);
4012
4020
  var built = buildTree(decorations, node, 0, options);
4013
4021
  newLocal = built.local;
4014
- for (var _i10 = 0; _i10 < children.length; _i10 += 3) if (children[_i10 + 1] < 0) {
4015
- children.splice(_i10, 3);
4016
- _i10 -= 3;
4022
+ for (var _i11 = 0; _i11 < children.length; _i11 += 3) if (children[_i11 + 1] < 0) {
4023
+ children.splice(_i11, 3);
4024
+ _i11 -= 3;
4017
4025
  }
4018
- for (var _i11 = 0, j = 0; _i11 < built.children.length; _i11 += 3) {
4019
- var _from2 = built.children[_i11];
4026
+ for (var _i12 = 0, j = 0; _i12 < built.children.length; _i12 += 3) {
4027
+ var _from2 = built.children[_i12];
4020
4028
  while (j < children.length && children[j] < _from2) j += 3;
4021
- children.splice(j, 0, built.children[_i11], built.children[_i11 + 1], built.children[_i11 + 2]);
4029
+ children.splice(j, 0, built.children[_i12], built.children[_i12 + 1], built.children[_i12 + 2]);
4022
4030
  }
4023
4031
  }
4024
4032
  return new DecorationSet(newLocal.sort(byPos), children);
@@ -4038,7 +4046,7 @@ function mapAndGatherRemainingDecorations(children, oldChildren, decorations, ma
4038
4046
  var mapped = set.local[i].map(mapping, offset, oldOffset);
4039
4047
  if (mapped) decorations.push(mapped);else if (options.onRemove) options.onRemove(set.local[i].spec);
4040
4048
  }
4041
- for (var _i13 = 0; _i13 < set.children.length; _i13 += 3) gather(set.children[_i13 + 2], set.children[_i13] + oldOffset + 1);
4049
+ for (var _i14 = 0; _i14 < set.children.length; _i14 += 3) gather(set.children[_i14 + 2], set.children[_i14] + oldOffset + 1);
4042
4050
  }
4043
4051
  for (var i = 0; i < children.length; i += 3) if (children[i + 1] == -1) gather(children[i + 2], oldChildren[i] + oldOffset + 1);
4044
4052
  return decorations;
@@ -4361,7 +4369,6 @@ var DOMObserver = function () {
4361
4369
  view.input.lastFocus = 0;
4362
4370
  selectionToDOM(view);
4363
4371
  this.currentSelection.set(sel);
4364
- view.scrollToSelection();
4365
4372
  } else if (from > -1 || newSel) {
4366
4373
  if (from > -1) {
4367
4374
  view.docView.markDirty(from, to);
@@ -4392,8 +4399,8 @@ var DOMObserver = function () {
4392
4399
  var prev = mut.previousSibling,
4393
4400
  next = mut.nextSibling;
4394
4401
  if (ie && ie_version <= 11 && mut.addedNodes.length) {
4395
- for (var _i14 = 0; _i14 < mut.addedNodes.length; _i14++) {
4396
- var _mut$addedNodes$_i = mut.addedNodes[_i14],
4402
+ for (var _i15 = 0; _i15 < mut.addedNodes.length; _i15++) {
4403
+ var _mut$addedNodes$_i = mut.addedNodes[_i15],
4397
4404
  previousSibling = _mut$addedNodes$_i.previousSibling,
4398
4405
  nextSibling = _mut$addedNodes$_i.nextSibling;
4399
4406
  if (!previousSibling || Array.prototype.indexOf.call(mut.addedNodes, previousSibling) < 0) prev = previousSibling;
@@ -4717,7 +4724,7 @@ function isMarkChange(cur, prev) {
4717
4724
  mark,
4718
4725
  update;
4719
4726
  for (var i = 0; i < prevMarks.length; i++) added = prevMarks[i].removeFromSet(added);
4720
- for (var _i15 = 0; _i15 < curMarks.length; _i15++) removed = curMarks[_i15].removeFromSet(removed);
4727
+ for (var _i16 = 0; _i16 < curMarks.length; _i16++) removed = curMarks[_i16].removeFromSet(removed);
4721
4728
  if (added.length == 1 && removed.length == 0) {
4722
4729
  mark = added[0];
4723
4730
  type = "add";
@@ -4734,7 +4741,7 @@ function isMarkChange(cur, prev) {
4734
4741
  return null;
4735
4742
  }
4736
4743
  var updated = [];
4737
- for (var _i16 = 0; _i16 < prev.childCount; _i16++) updated.push(update(prev.child(_i16)));
4744
+ for (var _i17 = 0; _i17 < prev.childCount; _i17++) updated.push(update(prev.child(_i17)));
4738
4745
  if (prosemirrorModel.Fragment.from(updated).eq(cur)) return {
4739
4746
  mark: mark,
4740
4747
  type: type
@@ -4804,7 +4811,6 @@ function isSurrogatePair(str) {
4804
4811
  b = str.charCodeAt(1);
4805
4812
  return a >= 0xDC00 && a <= 0xDFFF && b >= 0xD800 && b <= 0xDBFF;
4806
4813
  }
4807
- var __serializeForClipboard = serializeForClipboard;
4808
4814
  var __parseFromClipboard = parseFromClipboard;
4809
4815
  var __endComposition = endComposition;
4810
4816
  var EditorView = function () {
@@ -4952,7 +4958,7 @@ var EditorView = function () {
4952
4958
  value: function scrollToSelection() {
4953
4959
  var _this16 = this;
4954
4960
  var startDOM = this.domSelectionRange().focusNode;
4955
- if (this.someProp("handleScrollToSelection", function (f) {
4961
+ if (!startDOM || !this.dom.contains(startDOM.nodeType == 1 ? startDOM : startDOM.parentNode)) ;else if (this.someProp("handleScrollToSelection", function (f) {
4956
4962
  return f(_this16);
4957
4963
  })) ;else if (this.state.selection instanceof prosemirrorState.NodeSelection) {
4958
4964
  var target = this.docView.domAfterPos(this.state.selection.from);
@@ -4977,13 +4983,13 @@ var EditorView = function () {
4977
4983
  var plugin = this.directPlugins[i];
4978
4984
  if (plugin.spec.view) this.pluginViews.push(plugin.spec.view(this));
4979
4985
  }
4980
- for (var _i17 = 0; _i17 < this.state.plugins.length; _i17++) {
4981
- var _plugin = this.state.plugins[_i17];
4986
+ for (var _i18 = 0; _i18 < this.state.plugins.length; _i18++) {
4987
+ var _plugin = this.state.plugins[_i18];
4982
4988
  if (_plugin.spec.view) this.pluginViews.push(_plugin.spec.view(this));
4983
4989
  }
4984
4990
  } else {
4985
- for (var _i18 = 0; _i18 < this.pluginViews.length; _i18++) {
4986
- var pluginView = this.pluginViews[_i18];
4991
+ for (var _i19 = 0; _i19 < this.pluginViews.length; _i19++) {
4992
+ var pluginView = this.pluginViews[_i19];
4987
4993
  if (pluginView.update) pluginView.update(this, prevState);
4988
4994
  }
4989
4995
  }
@@ -5013,8 +5019,8 @@ var EditorView = function () {
5013
5019
  if (_prop != null && (value = f ? f(_prop) : _prop)) return value;
5014
5020
  }
5015
5021
  var plugins = this.state.plugins;
5016
- if (plugins) for (var _i19 = 0; _i19 < plugins.length; _i19++) {
5017
- var _prop2 = plugins[_i19].props[propName];
5022
+ if (plugins) for (var _i20 = 0; _i20 < plugins.length; _i20++) {
5023
+ var _prop2 = plugins[_i20].props[propName];
5018
5024
  if (_prop2 != null && (value = f ? f(_prop2) : _prop2)) return value;
5019
5025
  }
5020
5026
  }
@@ -5116,6 +5122,11 @@ var EditorView = function () {
5116
5122
  value: function pasteText(text, event) {
5117
5123
  return doPaste(this, text, null, true, event || new ClipboardEvent("paste"));
5118
5124
  }
5125
+ }, {
5126
+ key: "serializeForClipboard",
5127
+ value: function serializeForClipboard(slice) {
5128
+ return _serializeForClipboard(this, slice);
5129
+ }
5119
5130
  }, {
5120
5131
  key: "destroy",
5121
5132
  value: function destroy() {
@@ -5234,4 +5245,3 @@ exports.DecorationSet = DecorationSet;
5234
5245
  exports.EditorView = EditorView;
5235
5246
  exports.__endComposition = __endComposition;
5236
5247
  exports.__parseFromClipboard = __parseFromClipboard;
5237
- exports.__serializeForClipboard = __serializeForClipboard;
package/dist/index.d.cts CHANGED
@@ -650,6 +650,19 @@ declare class EditorView {
650
650
  */
651
651
  pasteText(text: string, event?: ClipboardEvent): boolean;
652
652
  /**
653
+ Serialize the given slice as it would be if it was copied from
654
+ this editor. Returns a DOM element that contains a
655
+ representation of the slice as its children, a textual
656
+ representation, and the transformed slice (which can be
657
+ different from the given input due to hooks like
658
+ [`transformCopied`](https://prosemirror.net/docs/ref/#view.EditorProps.transformCopied)).
659
+ */
660
+ serializeForClipboard(slice: Slice): {
661
+ dom: HTMLElement;
662
+ text: string;
663
+ slice: Slice;
664
+ };
665
+ /**
653
666
  Removes the editor from the DOM and destroys all [node
654
667
  views](https://prosemirror.net/docs/ref/#view.NodeView).
655
668
  */
package/dist/index.d.ts CHANGED
@@ -650,6 +650,19 @@ declare class EditorView {
650
650
  */
651
651
  pasteText(text: string, event?: ClipboardEvent): boolean;
652
652
  /**
653
+ Serialize the given slice as it would be if it was copied from
654
+ this editor. Returns a DOM element that contains a
655
+ representation of the slice as its children, a textual
656
+ representation, and the transformed slice (which can be
657
+ different from the given input due to hooks like
658
+ [`transformCopied`](https://prosemirror.net/docs/ref/#view.EditorProps.transformCopied)).
659
+ */
660
+ serializeForClipboard(slice: Slice): {
661
+ dom: HTMLElement;
662
+ text: string;
663
+ slice: Slice;
664
+ };
665
+ /**
653
666
  Removes the editor from the DOM and destroys all [node
654
667
  views](https://prosemirror.net/docs/ref/#view.NodeView).
655
668
  */
package/dist/index.js CHANGED
@@ -885,8 +885,15 @@ class ViewDesc {
885
885
  for (let i = 0, offset = 0; i < this.children.length; i++) {
886
886
  let child = this.children[i], end = offset + child.size;
887
887
  if (offset == pos && end != offset) {
888
- while (!child.border && child.children.length)
889
- child = child.children[0];
888
+ while (!child.border && child.children.length) {
889
+ for (let i = 0; i < child.children.length; i++) {
890
+ let inner = child.children[i];
891
+ if (inner.size) {
892
+ child = inner;
893
+ break;
894
+ }
895
+ }
896
+ }
890
897
  return child;
891
898
  }
892
899
  if (pos < end)
@@ -4698,7 +4705,6 @@ class DOMObserver {
4698
4705
  view.input.lastFocus = 0;
4699
4706
  selectionToDOM(view);
4700
4707
  this.currentSelection.set(sel);
4701
- view.scrollToSelection();
4702
4708
  }
4703
4709
  else if (from > -1 || newSel) {
4704
4710
  if (from > -1) {
@@ -5200,10 +5206,6 @@ function isSurrogatePair(str) {
5200
5206
  return a >= 0xDC00 && a <= 0xDFFF && b >= 0xD800 && b <= 0xDBFF;
5201
5207
  }
5202
5208
 
5203
- /**
5204
- @internal
5205
- */
5206
- const __serializeForClipboard = serializeForClipboard;
5207
5209
  /**
5208
5210
  @internal
5209
5211
  */
@@ -5432,7 +5434,8 @@ class EditorView {
5432
5434
  */
5433
5435
  scrollToSelection() {
5434
5436
  let startDOM = this.domSelectionRange().focusNode;
5435
- if (this.someProp("handleScrollToSelection", f => f(this))) ;
5437
+ if (!startDOM || !this.dom.contains(startDOM.nodeType == 1 ? startDOM : startDOM.parentNode)) ;
5438
+ else if (this.someProp("handleScrollToSelection", f => f(this))) ;
5436
5439
  else if (this.state.selection instanceof NodeSelection) {
5437
5440
  let target = this.docView.domAfterPos(this.state.selection.from);
5438
5441
  if (target.nodeType == 1)
@@ -5652,6 +5655,17 @@ class EditorView {
5652
5655
  return doPaste(this, text, null, true, event || new ClipboardEvent("paste"));
5653
5656
  }
5654
5657
  /**
5658
+ Serialize the given slice as it would be if it was copied from
5659
+ this editor. Returns a DOM element that contains a
5660
+ representation of the slice as its children, a textual
5661
+ representation, and the transformed slice (which can be
5662
+ different from the given input due to hooks like
5663
+ [`transformCopied`](https://prosemirror.net/docs/ref/#view.EditorProps.transformCopied)).
5664
+ */
5665
+ serializeForClipboard(slice) {
5666
+ return serializeForClipboard(this, slice);
5667
+ }
5668
+ /**
5655
5669
  Removes the editor from the DOM and destroys all [node
5656
5670
  views](https://prosemirror.net/docs/ref/#view.NodeView).
5657
5671
  */
@@ -5785,4 +5799,4 @@ function checkStateComponent(plugin) {
5785
5799
  throw new RangeError("Plugins passed directly to the view must not have a state component");
5786
5800
  }
5787
5801
 
5788
- export { Decoration, DecorationSet, EditorView, __endComposition, __parseFromClipboard, __serializeForClipboard };
5802
+ export { Decoration, DecorationSet, EditorView, __endComposition, __parseFromClipboard };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-view",
3
- "version": "1.37.1",
3
+ "version": "1.38.0",
4
4
  "description": "ProseMirror's view component",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -211,7 +211,6 @@ export class DOMObserver {
211
211
  view.input.lastFocus = 0
212
212
  selectionToDOM(view)
213
213
  this.currentSelection.set(sel)
214
- view.scrollToSelection()
215
214
  } else if (from > -1 || newSel) {
216
215
  if (from > -1) {
217
216
  view.docView.markDirty(from, to)
package/src/index.ts CHANGED
@@ -20,8 +20,6 @@ export {NodeView, MarkView, ViewMutationRecord} from "./viewdesc"
20
20
  import {serializeForClipboard, parseFromClipboard} from "./clipboard"
21
21
  import {endComposition} from "./input"
22
22
  /// @internal
23
- export const __serializeForClipboard = serializeForClipboard
24
- /// @internal
25
23
  export const __parseFromClipboard = parseFromClipboard
26
24
  /// @internal
27
25
  export const __endComposition = endComposition
@@ -235,8 +233,10 @@ export class EditorView {
235
233
 
236
234
  /// @internal
237
235
  scrollToSelection() {
238
- let startDOM = this.domSelectionRange().focusNode!
239
- if (this.someProp("handleScrollToSelection", f => f(this))) {
236
+ let startDOM = this.domSelectionRange().focusNode
237
+ if (!startDOM || !this.dom.contains(startDOM.nodeType == 1 ? startDOM : startDOM.parentNode)) {
238
+ // Ignore selections outside the editor
239
+ } else if (this.someProp("handleScrollToSelection", f => f(this))) {
240
240
  // Handled
241
241
  } else if (this.state.selection instanceof NodeSelection) {
242
242
  let target = this.docView.domAfterPos(this.state.selection.from)
@@ -444,6 +444,16 @@ export class EditorView {
444
444
  return doPaste(this, text, null, true, event || new ClipboardEvent("paste"))
445
445
  }
446
446
 
447
+ /// Serialize the given slice as it would be if it was copied from
448
+ /// this editor. Returns a DOM element that contains a
449
+ /// representation of the slice as its children, a textual
450
+ /// representation, and the transformed slice (which can be
451
+ /// different from the given input due to hooks like
452
+ /// [`transformCopied`](#view.EditorProps.transformCopied)).
453
+ serializeForClipboard(slice: Slice): {dom: HTMLElement, text: string, slice: Slice} {
454
+ return serializeForClipboard(this, slice)
455
+ }
456
+
447
457
  /// Removes the editor from the DOM and destroys all [node
448
458
  /// views](#view.NodeView).
449
459
  destroy() {
package/src/viewdesc.ts CHANGED
@@ -289,7 +289,12 @@ export class ViewDesc {
289
289
  for (let i = 0, offset = 0; i < this.children.length; i++) {
290
290
  let child = this.children[i], end = offset + child.size
291
291
  if (offset == pos && end != offset) {
292
- while (!child.border && child.children.length) child = child.children[0]
292
+ while (!child.border && child.children.length) {
293
+ for (let i = 0; i < child.children.length; i++) {
294
+ let inner = child.children[i]
295
+ if (inner.size) { child = inner; break }
296
+ }
297
+ }
293
298
  return child
294
299
  }
295
300
  if (pos < end) return child.descAt(pos - offset - child.border)