prosemirror-view 1.20.0 → 1.21.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 +69 -43
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +69 -43
- 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 +2 -2
- package/src/domcoords.js +11 -8
- package/src/index.js +3 -0
- package/src/viewdesc.js +31 -22
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 }
|
|
@@ -484,7 +484,8 @@ function coordsAtPos(view, pos, side) {
|
|
|
484
484
|
}
|
|
485
485
|
if (offset < nodeSize(node)) {
|
|
486
486
|
var after$1 = node.childNodes[offset];
|
|
487
|
-
|
|
487
|
+
while (after$1.pmViewDesc && after$1.pmViewDesc.ignoreForCoords) { after$1 = after$1.nextSibling; }
|
|
488
|
+
var target$1 = !after$1 ? null : after$1.nodeType == 3 ? textRange(after$1, 0, (supportEmptyRange ? 0 : 1))
|
|
488
489
|
: after$1.nodeType == 1 ? after$1 : null;
|
|
489
490
|
if (target$1) { return flattenV(singleRect(target$1, -1), true) }
|
|
490
491
|
}
|
|
@@ -539,7 +540,9 @@ function endOfTextblockVertical(view, state, dir) {
|
|
|
539
540
|
else { continue }
|
|
540
541
|
for (var i = 0; i < boxes.length; i++) {
|
|
541
542
|
var box = boxes[i];
|
|
542
|
-
if (box.bottom > box.top
|
|
543
|
+
if (box.bottom > box.top + 1 &&
|
|
544
|
+
(dir == "up" ? coords.top - box.top > (box.bottom - coords.top) * 2
|
|
545
|
+
: box.bottom - coords.bottom > (coords.bottom - box.top) * 2))
|
|
543
546
|
{ return false }
|
|
544
547
|
}
|
|
545
548
|
}
|
|
@@ -691,7 +694,7 @@ var ViewDesc = function ViewDesc(parent, children, dom, contentDOM) {
|
|
|
691
694
|
this.dirty = NOT_DIRTY;
|
|
692
695
|
};
|
|
693
696
|
|
|
694
|
-
var prototypeAccessors = {
|
|
697
|
+
var prototypeAccessors = { size: { configurable: true },border: { configurable: true },posBefore: { configurable: true },posAtStart: { configurable: true },posAfter: { configurable: true },posAtEnd: { configurable: true },contentLost: { configurable: true },domAtom: { configurable: true },ignoreForCoords: { configurable: true } };
|
|
695
698
|
|
|
696
699
|
// Used to check whether a given description corresponds to a
|
|
697
700
|
// widget/mark/node.
|
|
@@ -700,8 +703,6 @@ ViewDesc.prototype.matchesMark = function matchesMark () { return false };
|
|
|
700
703
|
ViewDesc.prototype.matchesNode = function matchesNode () { return false };
|
|
701
704
|
ViewDesc.prototype.matchesHack = function matchesHack (_nodeName) { return false };
|
|
702
705
|
|
|
703
|
-
prototypeAccessors.beforePosition.get = function () { return false };
|
|
704
|
-
|
|
705
706
|
// : () → ?ParseRule
|
|
706
707
|
// When parsing in-editor content (in domchange.js), we allow
|
|
707
708
|
// descriptions to determine the parse rules that should be used to
|
|
@@ -850,23 +851,34 @@ ViewDesc.prototype.descAt = function descAt (pos) {
|
|
|
850
851
|
// : (number, number) → {node: dom.Node, offset: number}
|
|
851
852
|
ViewDesc.prototype.domFromPos = function domFromPos (pos, side) {
|
|
852
853
|
if (!this.contentDOM) { return {node: this.dom, offset: 0} }
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
854
|
+
// First find the position in the child array
|
|
855
|
+
var i = 0, offset = 0;
|
|
856
|
+
for (var curPos = 0; i < this.children.length; i++) {
|
|
857
|
+
var child = this.children[i], end = curPos + child.size;
|
|
858
|
+
if (end > pos || child instanceof TrailingHackViewDesc) { offset = pos - curPos; break }
|
|
859
|
+
curPos = end;
|
|
860
|
+
}
|
|
861
|
+
// If this points into the middle of a child, call through
|
|
862
|
+
if (offset) { return this.children[i].domFromPos(offset - this.children[i].border, side) }
|
|
863
|
+
// Go back if there were any zero-length widgets with side >= 0 before this point
|
|
864
|
+
for (var prev = (void 0); i && !(prev = this.children[i - 1]).size && prev instanceof WidgetViewDesc && prev.widget.type.side >= 0; i--) {}
|
|
865
|
+
// Scan towards the first useable node
|
|
866
|
+
if (side <= 0) {
|
|
867
|
+
var prev$1, enter = true;
|
|
868
|
+
for (;; i--, enter = false) {
|
|
869
|
+
prev$1 = i ? this.children[i - 1] : null;
|
|
870
|
+
if (!prev$1 || prev$1.dom.parentNode == this.contentDOM) { break }
|
|
871
|
+
}
|
|
872
|
+
if (prev$1 && side && enter && !prev$1.border && !prev$1.domAtom) { return prev$1.domFromPos(prev$1.size, side) }
|
|
873
|
+
return {node: this.contentDOM, offset: prev$1 ? domIndex(prev$1.dom) + 1 : 0}
|
|
874
|
+
} else {
|
|
875
|
+
var next, enter$1 = true;
|
|
876
|
+
for (;; i++, enter$1 = false) {
|
|
877
|
+
next = i < this.children.length ? this.children[i] : null;
|
|
878
|
+
if (!next || next.dom.parentNode == this.contentDOM) { break }
|
|
879
|
+
}
|
|
880
|
+
if (next && enter$1 && !next.border && !next.domAtom) { return next.domFromPos(0, side) }
|
|
881
|
+
return {node: this.contentDOM, offset: next ? domIndex(next.dom) : this.contentDOM.childNodes.length}
|
|
870
882
|
}
|
|
871
883
|
};
|
|
872
884
|
|
|
@@ -1061,6 +1073,8 @@ ViewDesc.prototype.markParentsDirty = function markParentsDirty () {
|
|
|
1061
1073
|
|
|
1062
1074
|
prototypeAccessors.domAtom.get = function () { return false };
|
|
1063
1075
|
|
|
1076
|
+
prototypeAccessors.ignoreForCoords.get = function () { return false };
|
|
1077
|
+
|
|
1064
1078
|
Object.defineProperties( ViewDesc.prototype, prototypeAccessors );
|
|
1065
1079
|
|
|
1066
1080
|
// Reused array to avoid allocating fresh arrays for things that will
|
|
@@ -1094,11 +1108,7 @@ var WidgetViewDesc = /*@__PURE__*/(function (ViewDesc) {
|
|
|
1094
1108
|
WidgetViewDesc.prototype = Object.create( ViewDesc && ViewDesc.prototype );
|
|
1095
1109
|
WidgetViewDesc.prototype.constructor = WidgetViewDesc;
|
|
1096
1110
|
|
|
1097
|
-
var prototypeAccessors$1 = {
|
|
1098
|
-
|
|
1099
|
-
prototypeAccessors$1.beforePosition.get = function () {
|
|
1100
|
-
return this.widget.type.side < 0
|
|
1101
|
-
};
|
|
1111
|
+
var prototypeAccessors$1 = { domAtom: { configurable: true } };
|
|
1102
1112
|
|
|
1103
1113
|
WidgetViewDesc.prototype.matchesWidget = function matchesWidget (widget) {
|
|
1104
1114
|
return this.dirty == NOT_DIRTY && widget.type.eq(this.widget.type)
|
|
@@ -1524,11 +1534,12 @@ var TrailingHackViewDesc = /*@__PURE__*/(function (ViewDesc) {
|
|
|
1524
1534
|
TrailingHackViewDesc.prototype = Object.create( ViewDesc && ViewDesc.prototype );
|
|
1525
1535
|
TrailingHackViewDesc.prototype.constructor = TrailingHackViewDesc;
|
|
1526
1536
|
|
|
1527
|
-
var prototypeAccessors$5 = { domAtom: { configurable: true } };
|
|
1537
|
+
var prototypeAccessors$5 = { domAtom: { configurable: true },ignoreForCoords: { configurable: true } };
|
|
1528
1538
|
|
|
1529
1539
|
TrailingHackViewDesc.prototype.parseRule = function parseRule () { return {ignore: true} };
|
|
1530
1540
|
TrailingHackViewDesc.prototype.matchesHack = function matchesHack (nodeName) { return this.dirty == NOT_DIRTY && this.dom.nodeName == nodeName };
|
|
1531
1541
|
prototypeAccessors$5.domAtom.get = function () { return true };
|
|
1542
|
+
prototypeAccessors$5.ignoreForCoords.get = function () { return this.dom.nodeName == "IMG" };
|
|
1532
1543
|
|
|
1533
1544
|
Object.defineProperties( TrailingHackViewDesc.prototype, prototypeAccessors$5 );
|
|
1534
1545
|
|
|
@@ -1907,6 +1918,7 @@ ViewTreeUpdater.prototype.addHackNode = function addHackNode (nodeName) {
|
|
|
1907
1918
|
} else {
|
|
1908
1919
|
var dom = document.createElement(nodeName);
|
|
1909
1920
|
if (nodeName == "IMG") { dom.className = "ProseMirror-separator"; }
|
|
1921
|
+
if (nodeName == "BR") { dom.className = "ProseMirror-trailingBreak"; }
|
|
1910
1922
|
this.top.children.splice(this.index++, 0, new TrailingHackViewDesc(this.top, nothing, dom, null));
|
|
1911
1923
|
this.changed = true;
|
|
1912
1924
|
}
|
|
@@ -2933,7 +2945,7 @@ function parseFromClipboard(view, text, html, plainText, $context) {
|
|
|
2933
2945
|
var asText = text && (plainText || inCode || !html);
|
|
2934
2946
|
if (asText) {
|
|
2935
2947
|
view.someProp("transformPastedText", function (f) { text = f(text, inCode || plainText); });
|
|
2936
|
-
if (inCode) { return new prosemirrorModel.Slice(prosemirrorModel.Fragment.from(view.state.schema.text(text.replace(/\r\n?/g, "\n"))), 0, 0) }
|
|
2948
|
+
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 }
|
|
2937
2949
|
var parsed = view.someProp("clipboardTextParser", function (f) { return f(text, $context, plainText); });
|
|
2938
2950
|
if (parsed) {
|
|
2939
2951
|
slice = parsed;
|
|
@@ -2943,8 +2955,9 @@ function parseFromClipboard(view, text, html, plainText, $context) {
|
|
|
2943
2955
|
var schema = ref.schema;
|
|
2944
2956
|
var serializer = prosemirrorModel.DOMSerializer.fromSchema(schema);
|
|
2945
2957
|
dom = document.createElement("div");
|
|
2946
|
-
text.
|
|
2947
|
-
dom.appendChild(document.createElement("p"))
|
|
2958
|
+
text.split(/(?:\r\n?|\n)+/).forEach(function (block) {
|
|
2959
|
+
var p = dom.appendChild(document.createElement("p"));
|
|
2960
|
+
if (block) { p.appendChild(serializer.serializeNode(schema.text(block, marks))); }
|
|
2948
2961
|
});
|
|
2949
2962
|
}
|
|
2950
2963
|
} else {
|
|
@@ -2959,10 +2972,19 @@ function parseFromClipboard(view, text, html, plainText, $context) {
|
|
|
2959
2972
|
var parser = view.someProp("clipboardParser") || view.someProp("domParser") || prosemirrorModel.DOMParser.fromSchema(view.state.schema);
|
|
2960
2973
|
slice = parser.parseSlice(dom, {preserveWhitespace: !!(asText || sliceData), context: $context});
|
|
2961
2974
|
}
|
|
2962
|
-
if (sliceData)
|
|
2963
|
-
|
|
2964
|
-
else // HTML wasn't created by ProseMirror. Make sure top-level siblings are coherent
|
|
2965
|
-
|
|
2975
|
+
if (sliceData) {
|
|
2976
|
+
slice = addContext(closeSlice(slice, +sliceData[1], +sliceData[2]), sliceData[3]);
|
|
2977
|
+
} else { // HTML wasn't created by ProseMirror. Make sure top-level siblings are coherent
|
|
2978
|
+
slice = prosemirrorModel.Slice.maxOpen(normalizeSiblings(slice.content, $context), true);
|
|
2979
|
+
if (slice.openStart || slice.openEnd) {
|
|
2980
|
+
var openStart = 0, openEnd = 0;
|
|
2981
|
+
for (var node = slice.content.firstChild; openStart < slice.openStart && !node.type.spec.isolating;
|
|
2982
|
+
openStart++, node = node.firstChild) {}
|
|
2983
|
+
for (var node$1 = slice.content.lastChild; openEnd < slice.openEnd && !node$1.type.spec.isolating;
|
|
2984
|
+
openEnd++, node$1 = node$1.lastChild) {}
|
|
2985
|
+
slice = closeSlice(slice, openStart, openEnd);
|
|
2986
|
+
}
|
|
2987
|
+
}
|
|
2966
2988
|
|
|
2967
2989
|
view.someProp("transformPasted", function (f) { slice = f(slice); });
|
|
2968
2990
|
return slice
|
|
@@ -4141,7 +4163,8 @@ NodeType.prototype.valid = function valid (node, span) {
|
|
|
4141
4163
|
var ref = node.content.findIndex(span.from);
|
|
4142
4164
|
var index = ref.index;
|
|
4143
4165
|
var offset = ref.offset;
|
|
4144
|
-
|
|
4166
|
+
var child;
|
|
4167
|
+
return offset == span.from && !(child = node.child(index)).isText && offset + child.nodeSize == span.to
|
|
4145
4168
|
};
|
|
4146
4169
|
|
|
4147
4170
|
NodeType.prototype.eq = function eq (other) {
|
|
@@ -5166,6 +5189,9 @@ function computeDocDeco(view) {
|
|
|
5166
5189
|
if (value) { for (var attr in value) {
|
|
5167
5190
|
if (attr == "class")
|
|
5168
5191
|
{ attrs.class += " " + value[attr]; }
|
|
5192
|
+
if (attr == "style") {
|
|
5193
|
+
attrs.style = (attrs.style ? attrs.style + ";" : "") + value[attr];
|
|
5194
|
+
}
|
|
5169
5195
|
else if (!attrs[attr] && attr != "contenteditable" && attr != "nodeName")
|
|
5170
5196
|
{ attrs[attr] = String(value[attr]); }
|
|
5171
5197
|
} }
|