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 +34 -0
- package/dist/index.es.js +50 -19
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +50 -19
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/browser.js +1 -1
- package/src/clipboard.js +16 -6
- package/src/decoration.js +8 -0
- package/src/domcoords.js +6 -6
- package/src/index.js +4 -1
- package/src/viewdesc.js +13 -3
package/dist/index.js
CHANGED
|
@@ -13,7 +13,6 @@ if (typeof navigator != "undefined" && typeof document != "undefined") {
|
|
|
13
13
|
var ie_upto10 = /MSIE \d/.test(navigator.userAgent);
|
|
14
14
|
var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
|
|
15
15
|
|
|
16
|
-
result.mac = /Mac/.test(navigator.platform);
|
|
17
16
|
var ie = result.ie = !!(ie_upto10 || ie_11up || ie_edge);
|
|
18
17
|
result.ie_version = ie_upto10 ? document.documentMode || 6 : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : null;
|
|
19
18
|
result.gecko = !ie && /gecko\/(\d+)/i.test(navigator.userAgent);
|
|
@@ -24,6 +23,7 @@ if (typeof navigator != "undefined" && typeof document != "undefined") {
|
|
|
24
23
|
// Is true for both iOS and iPadOS for convenience
|
|
25
24
|
result.safari = !ie && /Apple Computer/.test(navigator.vendor);
|
|
26
25
|
result.ios = result.safari && (/Mobile\/\w+/.test(navigator.userAgent) || navigator.maxTouchPoints > 2);
|
|
26
|
+
result.mac = result.ios || /Mac/.test(navigator.platform);
|
|
27
27
|
result.android = /Android \d/.test(navigator.userAgent);
|
|
28
28
|
result.webkit = "webkitFontSmoothing" in document.documentElement.style;
|
|
29
29
|
result.webkit_version = result.webkit && +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1];
|
|
@@ -361,19 +361,19 @@ function elementFromPoint(element, coords, box) {
|
|
|
361
361
|
function posAtCoords(view, coords) {
|
|
362
362
|
var assign, assign$1;
|
|
363
363
|
|
|
364
|
-
var
|
|
365
|
-
if (
|
|
364
|
+
var doc = view.dom.ownerDocument, node, offset;
|
|
365
|
+
if (doc.caretPositionFromPoint) {
|
|
366
366
|
try { // Firefox throws for this call in hard-to-predict circumstances (#994)
|
|
367
|
-
var pos$1 =
|
|
367
|
+
var pos$1 = doc.caretPositionFromPoint(coords.left, coords.top);
|
|
368
368
|
if (pos$1) { ((assign = pos$1, node = assign.offsetNode, offset = assign.offset)); }
|
|
369
369
|
} catch (_) {}
|
|
370
370
|
}
|
|
371
|
-
if (!node &&
|
|
372
|
-
var range =
|
|
371
|
+
if (!node && doc.caretRangeFromPoint) {
|
|
372
|
+
var range = doc.caretRangeFromPoint(coords.left, coords.top);
|
|
373
373
|
if (range) { ((assign$1 = range, node = assign$1.startContainer, offset = assign$1.startOffset)); }
|
|
374
374
|
}
|
|
375
375
|
|
|
376
|
-
var elt = root.elementFromPoint(coords.left, coords.top + 1), pos;
|
|
376
|
+
var elt = (view.root.elementFromPoint ? view.root : doc).elementFromPoint(coords.left, coords.top + 1), pos;
|
|
377
377
|
if (!elt || !view.dom.contains(elt.nodeType != 1 ? elt.parentNode : elt)) {
|
|
378
378
|
var box = view.dom.getBoundingClientRect();
|
|
379
379
|
if (!inRect(coords, box)) { return null }
|
|
@@ -1125,6 +1125,11 @@ var WidgetViewDesc = /*@__PURE__*/(function (ViewDesc) {
|
|
|
1125
1125
|
return mutation.type != "selection" || this.widget.spec.ignoreSelection
|
|
1126
1126
|
};
|
|
1127
1127
|
|
|
1128
|
+
WidgetViewDesc.prototype.destroy = function destroy () {
|
|
1129
|
+
this.widget.type.destroy(this.dom);
|
|
1130
|
+
ViewDesc.prototype.destroy.call(this);
|
|
1131
|
+
};
|
|
1132
|
+
|
|
1128
1133
|
prototypeAccessors$1.domAtom.get = function () { return true };
|
|
1129
1134
|
|
|
1130
1135
|
Object.defineProperties( WidgetViewDesc.prototype, prototypeAccessors$1 );
|
|
@@ -1700,6 +1705,8 @@ function patchAttributes(dom, prev, cur) {
|
|
|
1700
1705
|
{ dom.classList.remove(prevList[i]); } }
|
|
1701
1706
|
for (var i$1 = 0; i$1 < curList.length; i$1++) { if (prevList.indexOf(curList[i$1]) == -1)
|
|
1702
1707
|
{ dom.classList.add(curList[i$1]); } }
|
|
1708
|
+
if (dom.classList.length == 0)
|
|
1709
|
+
{ dom.removeAttribute("class"); }
|
|
1703
1710
|
}
|
|
1704
1711
|
if (prev.style != cur.style) {
|
|
1705
1712
|
if (prev.style) {
|
|
@@ -1807,10 +1814,12 @@ ViewTreeUpdater.prototype.syncToMarks = function syncToMarks (marks, inline, vie
|
|
|
1807
1814
|
ViewTreeUpdater.prototype.findNodeMatch = function findNodeMatch (node, outerDeco, innerDeco, index) {
|
|
1808
1815
|
var children = this.top.children, found = -1;
|
|
1809
1816
|
if (index >= this.preMatch.index) {
|
|
1810
|
-
for (var i = this.index; i < children.length; i++) {
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1817
|
+
for (var i = this.index; i < children.length; i++) {
|
|
1818
|
+
if (this.preMatch.matched.get(children[i]) == index) {
|
|
1819
|
+
if (children[i].matchesNode(node, outerDeco, innerDeco)) { found = i; }
|
|
1820
|
+
break
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1814
1823
|
} else {
|
|
1815
1824
|
for (var i$1 = this.index, e = Math.min(children.length, i$1 + 1); i$1 < e; i$1++) {
|
|
1816
1825
|
var child = children[i$1];
|
|
@@ -1918,6 +1927,7 @@ ViewTreeUpdater.prototype.addHackNode = function addHackNode (nodeName) {
|
|
|
1918
1927
|
} else {
|
|
1919
1928
|
var dom = document.createElement(nodeName);
|
|
1920
1929
|
if (nodeName == "IMG") { dom.className = "ProseMirror-separator"; }
|
|
1930
|
+
if (nodeName == "BR") { dom.className = "ProseMirror-trailingBreak"; }
|
|
1921
1931
|
this.top.children.splice(this.index++, 0, new TrailingHackViewDesc(this.top, nothing, dom, null));
|
|
1922
1932
|
this.changed = true;
|
|
1923
1933
|
}
|
|
@@ -2944,7 +2954,7 @@ function parseFromClipboard(view, text, html, plainText, $context) {
|
|
|
2944
2954
|
var asText = text && (plainText || inCode || !html);
|
|
2945
2955
|
if (asText) {
|
|
2946
2956
|
view.someProp("transformPastedText", function (f) { text = f(text, inCode || plainText); });
|
|
2947
|
-
if (inCode) { return new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(view.state.schema.text(text.replace(/\r\n?/g, "\n"))), 0, 0) }
|
|
2957
|
+
if (inCode) { return text ? new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(view.state.schema.text(text.replace(/\r\n?/g, "\n"))), 0, 0) : prosemirrorModel.Slice.empty }
|
|
2948
2958
|
var parsed = view.someProp("clipboardTextParser", function (f) { return f(text, $context, plainText); });
|
|
2949
2959
|
if (parsed) {
|
|
2950
2960
|
slice = parsed;
|
|
@@ -2954,8 +2964,9 @@ function parseFromClipboard(view, text, html, plainText, $context) {
|
|
|
2954
2964
|
var schema = ref.schema;
|
|
2955
2965
|
var serializer = prosemirrorModel.DOMSerializer.fromSchema(schema);
|
|
2956
2966
|
dom = document.createElement("div");
|
|
2957
|
-
text.
|
|
2958
|
-
dom.appendChild(document.createElement("p"))
|
|
2967
|
+
text.split(/(?:\r\n?|\n)+/).forEach(function (block) {
|
|
2968
|
+
var p = dom.appendChild(document.createElement("p"));
|
|
2969
|
+
if (block) { p.appendChild(serializer.serializeNode(schema.text(block, marks))); }
|
|
2959
2970
|
});
|
|
2960
2971
|
}
|
|
2961
2972
|
} else {
|
|
@@ -2970,10 +2981,19 @@ function parseFromClipboard(view, text, html, plainText, $context) {
|
|
|
2970
2981
|
var parser = view.someProp("clipboardParser") || view.someProp("domParser") || prosemirrorModel.DOMParser.fromSchema(view.state.schema);
|
|
2971
2982
|
slice = parser.parseSlice(dom, {preserveWhitespace: !!(asText || sliceData), context: $context});
|
|
2972
2983
|
}
|
|
2973
|
-
if (sliceData)
|
|
2974
|
-
|
|
2975
|
-
else // HTML wasn't created by ProseMirror. Make sure top-level siblings are coherent
|
|
2976
|
-
|
|
2984
|
+
if (sliceData) {
|
|
2985
|
+
slice = addContext(closeSlice(slice, +sliceData[1], +sliceData[2]), sliceData[3]);
|
|
2986
|
+
} else { // HTML wasn't created by ProseMirror. Make sure top-level siblings are coherent
|
|
2987
|
+
slice = prosemirrorModel.Slice.maxOpen(normalizeSiblings(slice.content, $context), true);
|
|
2988
|
+
if (slice.openStart || slice.openEnd) {
|
|
2989
|
+
var openStart = 0, openEnd = 0;
|
|
2990
|
+
for (var node = slice.content.firstChild; openStart < slice.openStart && !node.type.spec.isolating;
|
|
2991
|
+
openStart++, node = node.firstChild) {}
|
|
2992
|
+
for (var node$1 = slice.content.lastChild; openEnd < slice.openEnd && !node$1.type.spec.isolating;
|
|
2993
|
+
openEnd++, node$1 = node$1.lastChild) {}
|
|
2994
|
+
slice = closeSlice(slice, openStart, openEnd);
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2977
2997
|
|
|
2978
2998
|
view.someProp("transformPasted", function (f) { slice = f(slice); });
|
|
2979
2999
|
return slice
|
|
@@ -4114,6 +4134,10 @@ WidgetType.prototype.eq = function eq (other) {
|
|
|
4114
4134
|
this.toDOM == other.toDOM && compareObjs(this.spec, other.spec)))
|
|
4115
4135
|
};
|
|
4116
4136
|
|
|
4137
|
+
WidgetType.prototype.destroy = function destroy (node) {
|
|
4138
|
+
if (this.spec.destroy) { this.spec.destroy(node); }
|
|
4139
|
+
};
|
|
4140
|
+
|
|
4117
4141
|
var InlineType = function InlineType(attrs, spec) {
|
|
4118
4142
|
this.spec = spec || noSpec;
|
|
4119
4143
|
this.attrs = attrs;
|
|
@@ -4241,6 +4265,10 @@ Decoration.prototype.map = function map (mapping, offset, oldOffset) {
|
|
|
4241
4265
|
// key are interchangeable—if widgets differ in, for example,
|
|
4242
4266
|
// the behavior of some event handler, they should get
|
|
4243
4267
|
// different keys.
|
|
4268
|
+
//
|
|
4269
|
+
// destroy:: ?(node: dom.Node)
|
|
4270
|
+
// Called when the widget decoration is removed as a result of
|
|
4271
|
+
// mapping
|
|
4244
4272
|
Decoration.widget = function widget (pos, toDOM, spec) {
|
|
4245
4273
|
return new Decoration(pos, pos, new WidgetType(toDOM, spec))
|
|
4246
4274
|
};
|
|
@@ -5178,6 +5206,9 @@ function computeDocDeco(view) {
|
|
|
5178
5206
|
if (value) { for (var attr in value) {
|
|
5179
5207
|
if (attr == "class")
|
|
5180
5208
|
{ attrs.class += " " + value[attr]; }
|
|
5209
|
+
if (attr == "style") {
|
|
5210
|
+
attrs.style = (attrs.style ? attrs.style + ";" : "") + value[attr];
|
|
5211
|
+
}
|
|
5181
5212
|
else if (!attrs[attr] && attr != "contenteditable" && attr != "nodeName")
|
|
5182
5213
|
{ attrs[attr] = String(value[attr]); }
|
|
5183
5214
|
} }
|
|
@@ -5413,7 +5444,7 @@ function checkStateComponent(plugin) {
|
|
|
5413
5444
|
// view](#state.PluginSpec.view) and
|
|
5414
5445
|
// [props](#state.PluginSpec.props). Passing plugins with a state
|
|
5415
5446
|
// component (a [state field](#state.PluginSpec.state) field or a
|
|
5416
|
-
// [transaction
|
|
5447
|
+
// [transaction](#state.PluginSpec.filterTransaction) filter or
|
|
5417
5448
|
// appender) will result in an error, since such plugins must be
|
|
5418
5449
|
// present in the state to work.
|
|
5419
5450
|
//
|