prosemirror-view 1.27.0 → 1.28.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,31 @@
1
+ ## 1.28.0 (2022-09-09)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue where the editor wouldn't realize it was focused on IE when IE's resize controls are on an element inside the content. Adjust Chrome click-override behavior to only happen for invisible selections
6
+
7
+ ### New features
8
+
9
+ The new `transformCopied` prop can be used to transform a copied/cut slice before it is serialized to the clipboard. Adjust doc comment
10
+
11
+ ## 1.27.2 (2022-08-19)
12
+
13
+ ### Bug fixes
14
+
15
+ Fix an issue where `DecorationSet.map`, given a mapping with multiple steps, could in some cases corrupt the decorations.
16
+
17
+ Stop calling `handleClick` when the mouse moved but failed to fire mousemove events (for example when dragging a scrollbar).
18
+
19
+ ## 1.27.1 (2022-08-16)
20
+
21
+ ### Bug fixes
22
+
23
+ Fix a bug in `DecorationSet.map` that could cause invalid mapping when step maps contain multiple replaced ranges.
24
+
25
+ Make sure that when the editor receives focus via tab or calling `.focus()` on its DOM element, the existing selection is restored.
26
+
27
+ Avoid collapsing of whitespace in Firefox when the editor doesn't have `white-space` set to `pre-wrap`.
28
+
1
29
  ## 1.27.0 (2022-07-20)
2
30
 
3
31
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -531,7 +531,7 @@ function _coordsAtPos(view, pos, side) {
531
531
  to++;
532
532
  }
533
533
 
534
- return flattenV(singleRect(textRange(node, from, to), takeSide), takeSide < 0);
534
+ return flattenV(singleRect(textRange(node, from, to), 1), takeSide < 0);
535
535
  }
536
536
  }
537
537
 
@@ -1462,7 +1462,7 @@ var NodeViewDesc = function (_ViewDesc4) {
1462
1462
  var composition = view.composing ? this.localCompositionInfo(view, pos) : null;
1463
1463
  var localComposition = composition && composition.pos > -1 ? composition : null;
1464
1464
  var compositionInChild = composition && composition.pos < 0;
1465
- var updater = new ViewTreeUpdater(this, localComposition && localComposition.node);
1465
+ var updater = new ViewTreeUpdater(this, localComposition && localComposition.node, view);
1466
1466
  iterDeco(this.node, this.innerDeco, function (widget, i, insideNode) {
1467
1467
  if (widget.spec.marks) updater.syncToMarks(widget.spec.marks, inline, view);else if (widget.type.side >= 0 && !insideNode) updater.syncToMarks(i == _this6.node.childCount ? prosemirrorModel.Mark.none : _this6.node.child(i).marks, inline, view);
1468
1468
  updater.placeWidget(widget, view, off);
@@ -1974,10 +1974,11 @@ function rm(dom) {
1974
1974
  }
1975
1975
 
1976
1976
  var ViewTreeUpdater = function () {
1977
- function ViewTreeUpdater(top, lock) {
1977
+ function ViewTreeUpdater(top, lock, view) {
1978
1978
  _classCallCheck(this, ViewTreeUpdater);
1979
1979
 
1980
1980
  this.lock = lock;
1981
+ this.view = view;
1981
1982
  this.index = 0;
1982
1983
  this.stack = [];
1983
1984
  this.changed = false;
@@ -2158,7 +2159,7 @@ var ViewTreeUpdater = function () {
2158
2159
  lastChild = parent.children[parent.children.length - 1];
2159
2160
  }
2160
2161
 
2161
- if (!lastChild || !(lastChild instanceof TextViewDesc) || /\n$/.test(lastChild.node.text)) {
2162
+ if (!lastChild || !(lastChild instanceof TextViewDesc) || /\n$/.test(lastChild.node.text) || this.view.requiresGeckoHackNode && /\s$/.test(lastChild.node.text)) {
2162
2163
  if ((safari || chrome) && lastChild && lastChild.dom.contentEditable == "false") this.addHackNode("IMG", parent);
2163
2164
  this.addHackNode("BR", this.top);
2164
2165
  }
@@ -2589,7 +2590,7 @@ function selectionBetween(view, $anchor, $head, bias) {
2589
2590
  }
2590
2591
 
2591
2592
  function hasFocusAndSelection(view) {
2592
- if (view.editable && view.root.activeElement != view.dom) return false;
2593
+ if (view.editable && !view.hasFocus()) return false;
2593
2594
  return hasSelection(view);
2594
2595
  }
2595
2596
 
@@ -2886,10 +2887,14 @@ function captureKeyDown(view, event) {
2886
2887
  }
2887
2888
 
2888
2889
  function serializeForClipboard(view, slice) {
2890
+ view.someProp("transformCopied", function (f) {
2891
+ slice = f(slice);
2892
+ });
2889
2893
  var context = [],
2890
- content = slice.content,
2891
- openStart = slice.openStart,
2892
- openEnd = slice.openEnd;
2894
+ _slice = slice,
2895
+ content = _slice.content,
2896
+ openStart = _slice.openStart,
2897
+ openEnd = _slice.openEnd;
2893
2898
 
2894
2899
  while (openStart > 1 && openEnd > 1 && content.childCount == 1 && content.firstChild.childCount == 1) {
2895
2900
  openStart--;
@@ -3164,6 +3169,10 @@ function addContext(slice, context) {
3164
3169
 
3165
3170
  var handlers = {};
3166
3171
  var editHandlers = {};
3172
+ var passiveHandlers = {
3173
+ touchstart: true,
3174
+ touchmove: true
3175
+ };
3167
3176
 
3168
3177
  var InputState = _createClass(function InputState() {
3169
3178
  _classCallCheck(this, InputState);
@@ -3182,6 +3191,8 @@ var InputState = _createClass(function InputState() {
3182
3191
  this.lastSelectionTime = 0;
3183
3192
  this.lastIOSEnter = 0;
3184
3193
  this.lastIOSEnterFallbackTimeout = -1;
3194
+ this.lastFocus = 0;
3195
+ this.lastTouch = 0;
3185
3196
  this.lastAndroidDelete = 0;
3186
3197
  this.composing = false;
3187
3198
  this.composingTimeout = -1;
@@ -3197,7 +3208,9 @@ function initInput(view) {
3197
3208
  var handler = handlers[event];
3198
3209
  view.dom.addEventListener(event, view.input.eventHandlers[event] = function (event) {
3199
3210
  if (eventBelongsToView(view, event) && !runCustomHandler(view, event) && (view.editable || !(event.type in editHandlers))) handler(view, event);
3200
- });
3211
+ }, passiveHandlers[event] ? {
3212
+ passive: true
3213
+ } : undefined);
3201
3214
  };
3202
3215
 
3203
3216
  for (var event in handlers) {
@@ -3547,12 +3560,13 @@ var MouseDown = function () {
3547
3560
  if (!this.view.dom.contains(event.target)) return;
3548
3561
  var pos = this.pos;
3549
3562
  if (this.view.state.doc != this.startDoc) pos = this.view.posAtCoords(eventCoords(event));
3563
+ this.updateAllowDefault(event);
3550
3564
 
3551
3565
  if (this.allowDefault || !pos) {
3552
3566
  setSelectionOrigin(this.view, "pointer");
3553
3567
  } else if (handleSingleClick(this.view, pos.pos, pos.inside, event, this.selectNode)) {
3554
3568
  event.preventDefault();
3555
- } else if (event.button == 0 && (this.flushed || safari && this.mightDrag && !this.mightDrag.node.isAtom || chrome && !(this.view.state.selection instanceof prosemirrorState.TextSelection) && Math.min(Math.abs(pos.pos - this.view.state.selection.from), Math.abs(pos.pos - this.view.state.selection.to)) <= 2)) {
3569
+ } else if (event.button == 0 && (this.flushed || safari && this.mightDrag && !this.mightDrag.node.isAtom || chrome && !this.view.state.selection.visible && Math.min(Math.abs(pos.pos - this.view.state.selection.from), Math.abs(pos.pos - this.view.state.selection.to)) <= 2)) {
3556
3570
  updateSelection(this.view, prosemirrorState.Selection.near(this.view.state.doc.resolve(pos.pos)), "pointer");
3557
3571
  event.preventDefault();
3558
3572
  } else {
@@ -3562,20 +3576,31 @@ var MouseDown = function () {
3562
3576
  }, {
3563
3577
  key: "move",
3564
3578
  value: function move(event) {
3565
- if (!this.allowDefault && (Math.abs(this.event.x - event.clientX) > 4 || Math.abs(this.event.y - event.clientY) > 4)) this.allowDefault = true;
3579
+ this.updateAllowDefault(event);
3566
3580
  setSelectionOrigin(this.view, "pointer");
3567
3581
  if (event.buttons == 0) this.done();
3568
3582
  }
3583
+ }, {
3584
+ key: "updateAllowDefault",
3585
+ value: function updateAllowDefault(event) {
3586
+ if (!this.allowDefault && (Math.abs(this.event.x - event.clientX) > 4 || Math.abs(this.event.y - event.clientY) > 4)) this.allowDefault = true;
3587
+ }
3569
3588
  }]);
3570
3589
 
3571
3590
  return MouseDown;
3572
3591
  }();
3573
3592
 
3574
- handlers.touchdown = function (view) {
3593
+ handlers.touchstart = function (view) {
3594
+ view.input.lastTouch = Date.now();
3575
3595
  forceDOMFlush(view);
3576
3596
  setSelectionOrigin(view, "pointer");
3577
3597
  };
3578
3598
 
3599
+ handlers.touchmove = function (view) {
3600
+ view.input.lastTouch = Date.now();
3601
+ setSelectionOrigin(view, "pointer");
3602
+ };
3603
+
3579
3604
  handlers.contextmenu = function (view) {
3580
3605
  return forceDOMFlush(view);
3581
3606
  };
@@ -3813,7 +3838,6 @@ editHandlers.drop = function (view, _event) {
3813
3838
  var eventPos = view.posAtCoords(eventCoords(event));
3814
3839
  if (!eventPos) return;
3815
3840
  var $mouse = view.state.doc.resolve(eventPos.pos);
3816
- if (!$mouse) return;
3817
3841
  var slice = dragging && dragging.slice;
3818
3842
 
3819
3843
  if (slice) {
@@ -3861,6 +3885,8 @@ editHandlers.drop = function (view, _event) {
3861
3885
  };
3862
3886
 
3863
3887
  handlers.focus = function (view) {
3888
+ view.input.lastFocus = Date.now();
3889
+
3864
3890
  if (!view.focused) {
3865
3891
  view.domObserver.stop();
3866
3892
  view.dom.classList.add("ProseMirror-focused");
@@ -4400,24 +4426,32 @@ var DecorationGroup = function () {
4400
4426
  function mapChildren(oldChildren, newLocal, mapping, node, offset, oldOffset, options) {
4401
4427
  var children = oldChildren.slice();
4402
4428
 
4403
- var shift = function shift(oldStart, oldEnd, newStart, newEnd) {
4404
- for (var i = 0; i < children.length; i += 3) {
4405
- var end = children[i + 1],
4406
- dSize = void 0;
4407
- if (end < 0 || oldStart > end + oldOffset) continue;
4408
- var start = children[i] + oldOffset;
4409
-
4410
- if (oldEnd >= start) {
4411
- children[i + 1] = oldStart <= start ? -2 : -1;
4412
- } else if (newStart >= offset && (dSize = newEnd - newStart - (oldEnd - oldStart))) {
4413
- children[i] += dSize;
4414
- children[i + 1] += dSize;
4429
+ var _loop4 = function _loop4(i, _baseOffset) {
4430
+ var moved = 0;
4431
+ mapping.maps[i].forEach(function (oldStart, oldEnd, newStart, newEnd) {
4432
+ var dSize = newEnd - newStart - (oldEnd - oldStart);
4433
+
4434
+ for (var _i12 = 0; _i12 < children.length; _i12 += 3) {
4435
+ var end = children[_i12 + 1];
4436
+ if (end < 0 || oldStart > end + _baseOffset - moved) continue;
4437
+ var start = children[_i12] + _baseOffset - moved;
4438
+
4439
+ if (oldEnd >= start) {
4440
+ children[_i12 + 1] = oldStart <= start ? -2 : -1;
4441
+ } else if (newStart >= offset && dSize) {
4442
+ children[_i12] += dSize;
4443
+ children[_i12 + 1] += dSize;
4444
+ }
4415
4445
  }
4416
- }
4446
+
4447
+ moved += dSize;
4448
+ });
4449
+ _baseOffset = mapping.maps[i].map(_baseOffset, -1);
4450
+ baseOffset = _baseOffset;
4417
4451
  };
4418
4452
 
4419
- for (var i = 0; i < mapping.maps.length; i++) {
4420
- mapping.maps[i].forEach(shift);
4453
+ for (var i = 0, baseOffset = oldOffset; i < mapping.maps.length; i++) {
4454
+ _loop4(i, baseOffset);
4421
4455
  }
4422
4456
 
4423
4457
  var mustRebuild = false;
@@ -4509,8 +4543,8 @@ function mapAndGatherRemainingDecorations(children, oldChildren, decorations, ma
4509
4543
  if (mapped) decorations.push(mapped);else if (options.onRemove) options.onRemove(set.local[i].spec);
4510
4544
  }
4511
4545
 
4512
- for (var _i12 = 0; _i12 < set.children.length; _i12 += 3) {
4513
- gather(set.children[_i12 + 2], set.children[_i12] + oldOffset + 1);
4546
+ for (var _i13 = 0; _i13 < set.children.length; _i13 += 3) {
4547
+ gather(set.children[_i13 + 2], set.children[_i13] + oldOffset + 1);
4514
4548
  }
4515
4549
  }
4516
4550
 
@@ -4816,7 +4850,8 @@ var DOMObserver = function () {
4816
4850
  }, {
4817
4851
  key: "flush",
4818
4852
  value: function flush() {
4819
- if (!this.view.docView || this.flushingSoon > -1) return;
4853
+ var view = this.view;
4854
+ if (!view.docView || this.flushingSoon > -1) return;
4820
4855
  var mutations = this.observer ? this.observer.takeRecords() : [];
4821
4856
 
4822
4857
  if (this.queue.length) {
@@ -4824,14 +4859,14 @@ var DOMObserver = function () {
4824
4859
  this.queue.length = 0;
4825
4860
  }
4826
4861
 
4827
- var sel = this.view.domSelection();
4828
- var newSel = !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasFocusAndSelection(this.view) && !this.ignoreSelectionChange(sel);
4862
+ var sel = view.domSelection();
4863
+ var newSel = !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasFocusAndSelection(view) && !this.ignoreSelectionChange(sel);
4829
4864
  var from = -1,
4830
4865
  to = -1,
4831
4866
  typeOver = false,
4832
4867
  added = [];
4833
4868
 
4834
- if (this.view.editable) {
4869
+ if (view.editable) {
4835
4870
  for (var i = 0; i < mutations.length; i++) {
4836
4871
  var result = this.registerMutation(mutations[i], added);
4837
4872
 
@@ -4855,14 +4890,21 @@ var DOMObserver = function () {
4855
4890
  }
4856
4891
  }
4857
4892
 
4858
- if (from > -1 || newSel) {
4893
+ var readSel = null;
4894
+
4895
+ if (from < 0 && newSel && view.input.lastFocus > Date.now() - 200 && view.input.lastTouch < Date.now() - 300 && selectionCollapsed(sel) && (readSel = selectionFromDOM(view)) && readSel.eq(prosemirrorState.Selection.near(view.state.doc.resolve(0), 1))) {
4896
+ view.input.lastFocus = 0;
4897
+ selectionToDOM(view);
4898
+ this.currentSelection.set(sel);
4899
+ view.scrollToSelection();
4900
+ } else if (from > -1 || newSel) {
4859
4901
  if (from > -1) {
4860
- this.view.docView.markDirty(from, to);
4861
- checkCSS(this.view);
4902
+ view.docView.markDirty(from, to);
4903
+ checkCSS(view);
4862
4904
  }
4863
4905
 
4864
4906
  this.handleDOMChange(from, to, typeOver, added);
4865
- if (this.view.docView && this.view.docView.dirty) this.view.updateState(this.view.state);else if (!this.currentSelection.eq(sel)) selectionToDOM(this.view);
4907
+ if (view.docView && view.docView.dirty) view.updateState(view.state);else if (!this.currentSelection.eq(sel)) selectionToDOM(view);
4866
4908
  this.currentSelection.set(sel);
4867
4909
  }
4868
4910
  }
@@ -4887,8 +4929,8 @@ var DOMObserver = function () {
4887
4929
  next = mut.nextSibling;
4888
4930
 
4889
4931
  if (ie && ie_version <= 11 && mut.addedNodes.length) {
4890
- for (var _i13 = 0; _i13 < mut.addedNodes.length; _i13++) {
4891
- var _mut$addedNodes$_i = mut.addedNodes[_i13],
4932
+ for (var _i14 = 0; _i14 < mut.addedNodes.length; _i14++) {
4933
+ var _mut$addedNodes$_i = mut.addedNodes[_i14],
4892
4934
  previousSibling = _mut$addedNodes$_i.previousSibling,
4893
4935
  nextSibling = _mut$addedNodes$_i.nextSibling;
4894
4936
  if (!previousSibling || Array.prototype.indexOf.call(mut.addedNodes, previousSibling) < 0) prev = previousSibling;
@@ -4922,12 +4964,19 @@ var DOMObserver = function () {
4922
4964
  return DOMObserver;
4923
4965
  }();
4924
4966
 
4925
- var cssChecked = false;
4967
+ var cssChecked = new WeakMap();
4968
+ var cssCheckWarned = false;
4926
4969
 
4927
4970
  function checkCSS(view) {
4928
- if (cssChecked) return;
4929
- cssChecked = true;
4930
- if (getComputedStyle(view.dom).whiteSpace == "normal") console["warn"]("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package.");
4971
+ if (cssChecked.has(view)) return;
4972
+ cssChecked.set(view, null);
4973
+
4974
+ if (['normal', 'nowrap', 'pre-line'].indexOf(getComputedStyle(view.dom).whiteSpace) !== -1) {
4975
+ view.requiresGeckoHackNode = gecko;
4976
+ if (cssCheckWarned) return;
4977
+ console["warn"]("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package.");
4978
+ cssCheckWarned = true;
4979
+ }
4931
4980
  }
4932
4981
 
4933
4982
  function parseBetween(view, from_, to_) {
@@ -5048,16 +5097,6 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
5048
5097
  to = view.state.doc.resolve(to).after(shared + 1);
5049
5098
  var sel = view.state.selection;
5050
5099
  var parse = parseBetween(view, from, to);
5051
-
5052
- if (chrome && view.cursorWrapper && parse.sel && parse.sel.anchor == view.cursorWrapper.deco.from && parse.sel.head == parse.sel.anchor) {
5053
- var text = view.cursorWrapper.deco.type.toDOM.nextSibling;
5054
- var size = text && text.nodeValue ? text.nodeValue.length : 1;
5055
- parse.sel = {
5056
- anchor: parse.sel.anchor + size,
5057
- head: parse.sel.anchor + size
5058
- };
5059
- }
5060
-
5061
5100
  var doc = view.state.doc,
5062
5101
  compare = doc.slice(parse.from, parse.to);
5063
5102
  var preferredPos, preferredSide;
@@ -5100,6 +5139,14 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
5100
5139
  }
5101
5140
  }
5102
5141
 
5142
+ if (chrome && view.cursorWrapper && parse.sel && parse.sel.anchor == view.cursorWrapper.deco.from && parse.sel.head == parse.sel.anchor) {
5143
+ var size = change.endB - change.start;
5144
+ parse.sel = {
5145
+ anchor: parse.sel.anchor + size,
5146
+ head: parse.sel.anchor + size
5147
+ };
5148
+ }
5149
+
5103
5150
  view.input.domChangeCount++;
5104
5151
 
5105
5152
  if (view.state.selection.from < view.state.selection.to && change.start == change.endB && view.state.selection instanceof prosemirrorState.TextSelection) {
@@ -5170,12 +5217,11 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
5170
5217
  tr = view.state.tr;
5171
5218
  if (markChange.type == "add") tr.addMark(chFrom, chTo, markChange.mark);else tr.removeMark(chFrom, chTo, markChange.mark);
5172
5219
  } else if ($from.parent.child($from.index()).isText && $from.index() == $to.index() - ($to.textOffset ? 0 : 1)) {
5173
- var _text = $from.parent.textBetween($from.parentOffset, $to.parentOffset);
5174
-
5220
+ var text = $from.parent.textBetween($from.parentOffset, $to.parentOffset);
5175
5221
  if (view.someProp("handleTextInput", function (f) {
5176
- return f(view, chFrom, chTo, _text);
5222
+ return f(view, chFrom, chTo, text);
5177
5223
  })) return;
5178
- tr = view.state.tr.insertText(_text, chFrom, chTo);
5224
+ tr = view.state.tr.insertText(text, chFrom, chTo);
5179
5225
  }
5180
5226
  }
5181
5227
 
@@ -5209,8 +5255,8 @@ function isMarkChange(cur, prev) {
5209
5255
  added = prevMarks[i].removeFromSet(added);
5210
5256
  }
5211
5257
 
5212
- for (var _i14 = 0; _i14 < curMarks.length; _i14++) {
5213
- removed = curMarks[_i14].removeFromSet(removed);
5258
+ for (var _i15 = 0; _i15 < curMarks.length; _i15++) {
5259
+ removed = curMarks[_i15].removeFromSet(removed);
5214
5260
  }
5215
5261
 
5216
5262
  if (added.length == 1 && removed.length == 0) {
@@ -5233,8 +5279,8 @@ function isMarkChange(cur, prev) {
5233
5279
 
5234
5280
  var updated = [];
5235
5281
 
5236
- for (var _i15 = 0; _i15 < prev.childCount; _i15++) {
5237
- updated.push(update(prev.child(_i15)));
5282
+ for (var _i16 = 0; _i16 < prev.childCount; _i16++) {
5283
+ updated.push(update(prev.child(_i16)));
5238
5284
  }
5239
5285
 
5240
5286
  if (prosemirrorModel.Fragment.from(updated).eq(cur)) return {
@@ -5327,6 +5373,7 @@ var EditorView = function () {
5327
5373
  this.input = new InputState();
5328
5374
  this.prevDirectPlugins = [];
5329
5375
  this.pluginViews = [];
5376
+ this.requiresGeckoHackNode = false;
5330
5377
  this.dragging = null;
5331
5378
  this._props = props;
5332
5379
  this.state = props.state;
@@ -5410,8 +5457,6 @@ var EditorView = function () {
5410
5457
  }, {
5411
5458
  key: "updateStateInner",
5412
5459
  value: function updateStateInner(state, reconfigured) {
5413
- var _this16 = this;
5414
-
5415
5460
  var prev = this.state,
5416
5461
  redraw = false,
5417
5462
  updateSel = false;
@@ -5474,19 +5519,26 @@ var EditorView = function () {
5474
5519
  if (scroll == "reset") {
5475
5520
  this.dom.scrollTop = 0;
5476
5521
  } else if (scroll == "to selection") {
5477
- var startDOM = this.domSelection().focusNode;
5478
- if (this.someProp("handleScrollToSelection", function (f) {
5479
- return f(_this16);
5480
- })) ;else if (state.selection instanceof prosemirrorState.NodeSelection) {
5481
- var target = this.docView.domAfterPos(state.selection.from);
5482
- if (target.nodeType == 1) scrollRectIntoView(this, target.getBoundingClientRect(), startDOM);
5483
- } else {
5484
- scrollRectIntoView(this, this.coordsAtPos(state.selection.head, 1), startDOM);
5485
- }
5522
+ this.scrollToSelection();
5486
5523
  } else if (oldScrollPos) {
5487
5524
  resetScrollPos(oldScrollPos);
5488
5525
  }
5489
5526
  }
5527
+ }, {
5528
+ key: "scrollToSelection",
5529
+ value: function scrollToSelection() {
5530
+ var _this16 = this;
5531
+
5532
+ var startDOM = this.domSelection().focusNode;
5533
+ if (this.someProp("handleScrollToSelection", function (f) {
5534
+ return f(_this16);
5535
+ })) ;else if (this.state.selection instanceof prosemirrorState.NodeSelection) {
5536
+ var target = this.docView.domAfterPos(this.state.selection.from);
5537
+ if (target.nodeType == 1) scrollRectIntoView(this, target.getBoundingClientRect(), startDOM);
5538
+ } else {
5539
+ scrollRectIntoView(this, this.coordsAtPos(this.state.selection.head, 1), startDOM);
5540
+ }
5541
+ }
5490
5542
  }, {
5491
5543
  key: "destroyPluginViews",
5492
5544
  value: function destroyPluginViews() {
@@ -5508,13 +5560,13 @@ var EditorView = function () {
5508
5560
  if (plugin.spec.view) this.pluginViews.push(plugin.spec.view(this));
5509
5561
  }
5510
5562
 
5511
- for (var _i16 = 0; _i16 < this.state.plugins.length; _i16++) {
5512
- var _plugin = this.state.plugins[_i16];
5563
+ for (var _i17 = 0; _i17 < this.state.plugins.length; _i17++) {
5564
+ var _plugin = this.state.plugins[_i17];
5513
5565
  if (_plugin.spec.view) this.pluginViews.push(_plugin.spec.view(this));
5514
5566
  }
5515
5567
  } else {
5516
- for (var _i17 = 0; _i17 < this.pluginViews.length; _i17++) {
5517
- var pluginView = this.pluginViews[_i17];
5568
+ for (var _i18 = 0; _i18 < this.pluginViews.length; _i18++) {
5569
+ var pluginView = this.pluginViews[_i18];
5518
5570
  if (pluginView.update) pluginView.update(this, prevState);
5519
5571
  }
5520
5572
  }
@@ -5532,14 +5584,27 @@ var EditorView = function () {
5532
5584
  }
5533
5585
 
5534
5586
  var plugins = this.state.plugins;
5535
- if (plugins) for (var _i18 = 0; _i18 < plugins.length; _i18++) {
5536
- var _prop2 = plugins[_i18].props[propName];
5587
+ if (plugins) for (var _i19 = 0; _i19 < plugins.length; _i19++) {
5588
+ var _prop2 = plugins[_i19].props[propName];
5537
5589
  if (_prop2 != null && (value = f ? f(_prop2) : _prop2)) return value;
5538
5590
  }
5539
5591
  }
5540
5592
  }, {
5541
5593
  key: "hasFocus",
5542
5594
  value: function hasFocus() {
5595
+ if (ie) {
5596
+ var node = this.root.activeElement;
5597
+ if (node == this.dom) return true;
5598
+ if (!node || !this.dom.contains(node)) return false;
5599
+
5600
+ while (node && this.dom != node && this.dom.contains(node)) {
5601
+ if (node.contentEditable == 'false') return false;
5602
+ node = node.parentElement;
5603
+ }
5604
+
5605
+ return true;
5606
+ }
5607
+
5543
5608
  return this.root.activeElement == this.dom;
5544
5609
  }
5545
5610
  }, {
@@ -5558,7 +5623,7 @@ var EditorView = function () {
5558
5623
  var cached = this._root;
5559
5624
 
5560
5625
  if (cached == null) {
5561
- var _loop4 = function _loop4(search) {
5626
+ var _loop5 = function _loop5(search) {
5562
5627
  if (search.nodeType == 9 || search.nodeType == 11 && search.host) {
5563
5628
  if (!search.getSelection) Object.getPrototypeOf(search).getSelection = function () {
5564
5629
  return search.ownerDocument.getSelection();
@@ -5570,7 +5635,7 @@ var EditorView = function () {
5570
5635
  };
5571
5636
 
5572
5637
  for (var search = this.dom.parentNode; search; search = search.parentNode) {
5573
- var _ret3 = _loop4(search);
5638
+ var _ret3 = _loop5(search);
5574
5639
 
5575
5640
  if (_typeof(_ret3) === "object") return _ret3.v;
5576
5641
  }
package/dist/index.d.ts CHANGED
@@ -696,11 +696,16 @@ interface EditorProps<P = any> {
696
696
  */
697
697
  clipboardTextParser?: (this: P, text: string, $context: ResolvedPos, plain: boolean) => Slice;
698
698
  /**
699
- Can be used to transform pasted content before it is applied to
700
- the document.
699
+ Can be used to transform pasted or dragged-and-dropped content
700
+ before it is applied to the document.
701
701
  */
702
702
  transformPasted?: (this: P, slice: Slice) => Slice;
703
703
  /**
704
+ Can be used to transform copied or cut content before it is
705
+ serialized to the clipboard.
706
+ */
707
+ transformCopied?: (this: P, slice: Slice) => Slice;
708
+ /**
704
709
  Allows you to pass custom rendering and behavior logic for
705
710
  nodes. Should map node names to constructor functions that
706
711
  produce a [`NodeView`](https://prosemirror.net/docs/ref/#view.NodeView) object implementing the