prosemirror-view 1.20.1 → 1.22.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,37 @@
1
+ ## 1.22.0 (2021-11-08)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue where some types of node decoration changes could cause an unnecessary cascade of node redraws.
6
+
7
+ ### New features
8
+
9
+ Widget decorations now accept a `destroy` option, which will be called when the widget is removed from the view.
10
+
11
+ ## 1.21.0 (2021-10-29)
12
+
13
+ ### Bug fixes
14
+
15
+ Fix issue where recent Mobile Safari versions weren't treated as Mac platforms.
16
+
17
+ ### New features
18
+
19
+ Multiple `style` properties provided through the `attributes` prop are now merged. Adjust mac detection for recent changes to navigator.platform on iOS
20
+
21
+ ## 1.20.3 (2021-10-13)
22
+
23
+ ### Bug fixes
24
+
25
+ Stop removing leading/trailing whitespace from pasted plain text.
26
+
27
+ Fix an issue that could cause invalid content to be produced when pasting HTML with isolating nodes in it.
28
+
29
+ ## 1.20.2 (2021-10-07)
30
+
31
+ ### Bug fixes
32
+
33
+ Fix a crash when pasting whitespace-only content as text.
34
+
1
35
  ## 1.20.1 (2021-09-09)
2
36
 
3
37
  ### Bug fixes
package/dist/index.es.js CHANGED
@@ -9,7 +9,6 @@ if (typeof navigator != "undefined" && typeof document != "undefined") {
9
9
  var ie_upto10 = /MSIE \d/.test(navigator.userAgent);
10
10
  var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
11
11
 
12
- result.mac = /Mac/.test(navigator.platform);
13
12
  var ie = result.ie = !!(ie_upto10 || ie_11up || ie_edge);
14
13
  result.ie_version = ie_upto10 ? document.documentMode || 6 : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : null;
15
14
  result.gecko = !ie && /gecko\/(\d+)/i.test(navigator.userAgent);
@@ -20,6 +19,7 @@ if (typeof navigator != "undefined" && typeof document != "undefined") {
20
19
  // Is true for both iOS and iPadOS for convenience
21
20
  result.safari = !ie && /Apple Computer/.test(navigator.vendor);
22
21
  result.ios = result.safari && (/Mobile\/\w+/.test(navigator.userAgent) || navigator.maxTouchPoints > 2);
22
+ result.mac = result.ios || /Mac/.test(navigator.platform);
23
23
  result.android = /Android \d/.test(navigator.userAgent);
24
24
  result.webkit = "webkitFontSmoothing" in document.documentElement.style;
25
25
  result.webkit_version = result.webkit && +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1];
@@ -357,19 +357,19 @@ function elementFromPoint(element, coords, box) {
357
357
  function posAtCoords(view, coords) {
358
358
  var assign, assign$1;
359
359
 
360
- var root = view.root, node, offset;
361
- if (root.caretPositionFromPoint) {
360
+ var doc = view.dom.ownerDocument, node, offset;
361
+ if (doc.caretPositionFromPoint) {
362
362
  try { // Firefox throws for this call in hard-to-predict circumstances (#994)
363
- var pos$1 = root.caretPositionFromPoint(coords.left, coords.top);
363
+ var pos$1 = doc.caretPositionFromPoint(coords.left, coords.top);
364
364
  if (pos$1) { ((assign = pos$1, node = assign.offsetNode, offset = assign.offset)); }
365
365
  } catch (_) {}
366
366
  }
367
- if (!node && root.caretRangeFromPoint) {
368
- var range = root.caretRangeFromPoint(coords.left, coords.top);
367
+ if (!node && doc.caretRangeFromPoint) {
368
+ var range = doc.caretRangeFromPoint(coords.left, coords.top);
369
369
  if (range) { ((assign$1 = range, node = assign$1.startContainer, offset = assign$1.startOffset)); }
370
370
  }
371
371
 
372
- var elt = root.elementFromPoint(coords.left, coords.top + 1), pos;
372
+ var elt = (view.root.elementFromPoint ? view.root : doc).elementFromPoint(coords.left, coords.top + 1), pos;
373
373
  if (!elt || !view.dom.contains(elt.nodeType != 1 ? elt.parentNode : elt)) {
374
374
  var box = view.dom.getBoundingClientRect();
375
375
  if (!inRect(coords, box)) { return null }
@@ -1121,6 +1121,11 @@ var WidgetViewDesc = /*@__PURE__*/(function (ViewDesc) {
1121
1121
  return mutation.type != "selection" || this.widget.spec.ignoreSelection
1122
1122
  };
1123
1123
 
1124
+ WidgetViewDesc.prototype.destroy = function destroy () {
1125
+ this.widget.type.destroy(this.dom);
1126
+ ViewDesc.prototype.destroy.call(this);
1127
+ };
1128
+
1124
1129
  prototypeAccessors$1.domAtom.get = function () { return true };
1125
1130
 
1126
1131
  Object.defineProperties( WidgetViewDesc.prototype, prototypeAccessors$1 );
@@ -1696,6 +1701,8 @@ function patchAttributes(dom, prev, cur) {
1696
1701
  { dom.classList.remove(prevList[i]); } }
1697
1702
  for (var i$1 = 0; i$1 < curList.length; i$1++) { if (prevList.indexOf(curList[i$1]) == -1)
1698
1703
  { dom.classList.add(curList[i$1]); } }
1704
+ if (dom.classList.length == 0)
1705
+ { dom.removeAttribute("class"); }
1699
1706
  }
1700
1707
  if (prev.style != cur.style) {
1701
1708
  if (prev.style) {
@@ -1803,10 +1810,12 @@ ViewTreeUpdater.prototype.syncToMarks = function syncToMarks (marks, inline, vie
1803
1810
  ViewTreeUpdater.prototype.findNodeMatch = function findNodeMatch (node, outerDeco, innerDeco, index) {
1804
1811
  var children = this.top.children, found = -1;
1805
1812
  if (index >= this.preMatch.index) {
1806
- for (var i = this.index; i < children.length; i++) { if (children[i].matchesNode(node, outerDeco, innerDeco)) {
1807
- found = i;
1808
- break
1809
- } }
1813
+ for (var i = this.index; i < children.length; i++) {
1814
+ if (this.preMatch.matched.get(children[i]) == index) {
1815
+ if (children[i].matchesNode(node, outerDeco, innerDeco)) { found = i; }
1816
+ break
1817
+ }
1818
+ }
1810
1819
  } else {
1811
1820
  for (var i$1 = this.index, e = Math.min(children.length, i$1 + 1); i$1 < e; i$1++) {
1812
1821
  var child = children[i$1];
@@ -1914,6 +1923,7 @@ ViewTreeUpdater.prototype.addHackNode = function addHackNode (nodeName) {
1914
1923
  } else {
1915
1924
  var dom = document.createElement(nodeName);
1916
1925
  if (nodeName == "IMG") { dom.className = "ProseMirror-separator"; }
1926
+ if (nodeName == "BR") { dom.className = "ProseMirror-trailingBreak"; }
1917
1927
  this.top.children.splice(this.index++, 0, new TrailingHackViewDesc(this.top, nothing, dom, null));
1918
1928
  this.changed = true;
1919
1929
  }
@@ -2940,7 +2950,7 @@ function parseFromClipboard(view, text, html, plainText, $context) {
2940
2950
  var asText = text && (plainText || inCode || !html);
2941
2951
  if (asText) {
2942
2952
  view.someProp("transformPastedText", function (f) { text = f(text, inCode || plainText); });
2943
- if (inCode) { return new Slice(Fragment.from(view.state.schema.text(text.replace(/\r\n?/g, "\n"))), 0, 0) }
2953
+ if (inCode) { return text ? new Slice(Fragment.from(view.state.schema.text(text.replace(/\r\n?/g, "\n"))), 0, 0) : Slice.empty }
2944
2954
  var parsed = view.someProp("clipboardTextParser", function (f) { return f(text, $context, plainText); });
2945
2955
  if (parsed) {
2946
2956
  slice = parsed;
@@ -2950,8 +2960,9 @@ function parseFromClipboard(view, text, html, plainText, $context) {
2950
2960
  var schema = ref.schema;
2951
2961
  var serializer = DOMSerializer.fromSchema(schema);
2952
2962
  dom = document.createElement("div");
2953
- text.trim().split(/(?:\r\n?|\n)+/).forEach(function (block) {
2954
- dom.appendChild(document.createElement("p")).appendChild(serializer.serializeNode(schema.text(block, marks)));
2963
+ text.split(/(?:\r\n?|\n)+/).forEach(function (block) {
2964
+ var p = dom.appendChild(document.createElement("p"));
2965
+ if (block) { p.appendChild(serializer.serializeNode(schema.text(block, marks))); }
2955
2966
  });
2956
2967
  }
2957
2968
  } else {
@@ -2966,10 +2977,19 @@ function parseFromClipboard(view, text, html, plainText, $context) {
2966
2977
  var parser = view.someProp("clipboardParser") || view.someProp("domParser") || DOMParser.fromSchema(view.state.schema);
2967
2978
  slice = parser.parseSlice(dom, {preserveWhitespace: !!(asText || sliceData), context: $context});
2968
2979
  }
2969
- if (sliceData)
2970
- { slice = addContext(closeSlice(slice, +sliceData[1], +sliceData[2]), sliceData[3]); }
2971
- else // HTML wasn't created by ProseMirror. Make sure top-level siblings are coherent
2972
- { slice = Slice.maxOpen(normalizeSiblings(slice.content, $context), false); }
2980
+ if (sliceData) {
2981
+ slice = addContext(closeSlice(slice, +sliceData[1], +sliceData[2]), sliceData[3]);
2982
+ } else { // HTML wasn't created by ProseMirror. Make sure top-level siblings are coherent
2983
+ slice = Slice.maxOpen(normalizeSiblings(slice.content, $context), true);
2984
+ if (slice.openStart || slice.openEnd) {
2985
+ var openStart = 0, openEnd = 0;
2986
+ for (var node = slice.content.firstChild; openStart < slice.openStart && !node.type.spec.isolating;
2987
+ openStart++, node = node.firstChild) {}
2988
+ for (var node$1 = slice.content.lastChild; openEnd < slice.openEnd && !node$1.type.spec.isolating;
2989
+ openEnd++, node$1 = node$1.lastChild) {}
2990
+ slice = closeSlice(slice, openStart, openEnd);
2991
+ }
2992
+ }
2973
2993
 
2974
2994
  view.someProp("transformPasted", function (f) { slice = f(slice); });
2975
2995
  return slice
@@ -4110,6 +4130,10 @@ WidgetType.prototype.eq = function eq (other) {
4110
4130
  this.toDOM == other.toDOM && compareObjs(this.spec, other.spec)))
4111
4131
  };
4112
4132
 
4133
+ WidgetType.prototype.destroy = function destroy (node) {
4134
+ if (this.spec.destroy) { this.spec.destroy(node); }
4135
+ };
4136
+
4113
4137
  var InlineType = function InlineType(attrs, spec) {
4114
4138
  this.spec = spec || noSpec;
4115
4139
  this.attrs = attrs;
@@ -4237,6 +4261,10 @@ Decoration.prototype.map = function map (mapping, offset, oldOffset) {
4237
4261
  // key are interchangeable—if widgets differ in, for example,
4238
4262
  // the behavior of some event handler, they should get
4239
4263
  // different keys.
4264
+ //
4265
+ // destroy:: ?(node: dom.Node)
4266
+ // Called when the widget decoration is removed as a result of
4267
+ // mapping
4240
4268
  Decoration.widget = function widget (pos, toDOM, spec) {
4241
4269
  return new Decoration(pos, pos, new WidgetType(toDOM, spec))
4242
4270
  };
@@ -5174,6 +5202,9 @@ function computeDocDeco(view) {
5174
5202
  if (value) { for (var attr in value) {
5175
5203
  if (attr == "class")
5176
5204
  { attrs.class += " " + value[attr]; }
5205
+ if (attr == "style") {
5206
+ attrs.style = (attrs.style ? attrs.style + ";" : "") + value[attr];
5207
+ }
5177
5208
  else if (!attrs[attr] && attr != "contenteditable" && attr != "nodeName")
5178
5209
  { attrs[attr] = String(value[attr]); }
5179
5210
  } }
@@ -5409,7 +5440,7 @@ function checkStateComponent(plugin) {
5409
5440
  // view](#state.PluginSpec.view) and
5410
5441
  // [props](#state.PluginSpec.props). Passing plugins with a state
5411
5442
  // component (a [state field](#state.PluginSpec.state) field or a
5412
- // [transaction)[#state.PluginSpec.filterTransaction] filter or
5443
+ // [transaction](#state.PluginSpec.filterTransaction) filter or
5413
5444
  // appender) will result in an error, since such plugins must be
5414
5445
  // present in the state to work.
5415
5446
  //