prosemirror-view 1.42.5 → 1.42.6
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 +14 -0
- package/dist/index.cjs +140 -125
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +153 -135
- package/package.json +1 -1
- package/src/capturekeys.ts +31 -35
- package/src/clipboard.ts +5 -4
- package/src/dom.ts +15 -8
- package/src/domchange.ts +3 -3
- package/src/domcoords.ts +52 -53
- package/src/domobserver.ts +6 -7
- package/src/index.ts +4 -4
- package/src/input.ts +7 -7
- package/src/selection.ts +19 -6
- package/src/viewdesc.ts +37 -33
package/dist/index.cjs
CHANGED
|
@@ -55,12 +55,12 @@ function scanFor(node, off, targetNode, targetOff, dir) {
|
|
|
55
55
|
if (node == targetNode && off == targetOff) return true;
|
|
56
56
|
if (off == (dir < 0 ? 0 : nodeSize(node))) {
|
|
57
57
|
var parent = node.parentNode;
|
|
58
|
-
if (!parent || parent
|
|
58
|
+
if (!parent || !isElt(parent) || hasBlockDesc(node) || atomElements.test(node.nodeName) || node.contentEditable == "false") return false;
|
|
59
59
|
off = domIndex(node) + (dir < 0 ? 0 : 1);
|
|
60
60
|
node = parent;
|
|
61
|
-
} else if (node
|
|
61
|
+
} else if (isElt(node)) {
|
|
62
62
|
var child = node.childNodes[off + (dir < 0 ? -1 : 0)];
|
|
63
|
-
if (child
|
|
63
|
+
if (isElt(child) && child.contentEditable == "false") {
|
|
64
64
|
if ((_a = child.pmViewDesc) === null || _a === void 0 ? void 0 : _a.ignoreForSelection) off += dir;else return false;
|
|
65
65
|
} else {
|
|
66
66
|
node = child;
|
|
@@ -74,10 +74,19 @@ function scanFor(node, off, targetNode, targetOff, dir) {
|
|
|
74
74
|
function nodeSize(node) {
|
|
75
75
|
return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length;
|
|
76
76
|
}
|
|
77
|
+
function isElt(node) {
|
|
78
|
+
return node.nodeType == 1;
|
|
79
|
+
}
|
|
80
|
+
function isText(node) {
|
|
81
|
+
return node.nodeType == 3;
|
|
82
|
+
}
|
|
83
|
+
function contains(parent, child) {
|
|
84
|
+
return child ? parent.contains(isElt(child) ? child : child.parentNode) : false;
|
|
85
|
+
}
|
|
77
86
|
function textNodeBefore$1(node, offset) {
|
|
78
87
|
for (;;) {
|
|
79
|
-
if (node
|
|
80
|
-
if (node
|
|
88
|
+
if (isText(node) && offset) return node;
|
|
89
|
+
if (isElt(node) && offset > 0) {
|
|
81
90
|
if (node.contentEditable == "false") return null;
|
|
82
91
|
node = node.childNodes[offset - 1];
|
|
83
92
|
offset = nodeSize(node);
|
|
@@ -91,8 +100,8 @@ function textNodeBefore$1(node, offset) {
|
|
|
91
100
|
}
|
|
92
101
|
function textNodeAfter$1(node, offset) {
|
|
93
102
|
for (;;) {
|
|
94
|
-
if (node
|
|
95
|
-
if (node
|
|
103
|
+
if (isText(node) && offset < node.nodeValue.length) return node;
|
|
104
|
+
if (isElt(node) && offset < node.childNodes.length) {
|
|
96
105
|
if (node.contentEditable == "false") return null;
|
|
97
106
|
node = node.childNodes[offset];
|
|
98
107
|
offset = 0;
|
|
@@ -208,13 +217,12 @@ function scrollRectIntoView(view, rect, startDOM) {
|
|
|
208
217
|
var doc = view.dom.ownerDocument;
|
|
209
218
|
for (var parent = startDOM || view.dom;;) {
|
|
210
219
|
if (!parent) break;
|
|
211
|
-
if (parent
|
|
220
|
+
if (!isElt(parent)) {
|
|
212
221
|
parent = parentNode(parent);
|
|
213
222
|
continue;
|
|
214
223
|
}
|
|
215
|
-
var
|
|
216
|
-
var
|
|
217
|
-
var bounding = atTop ? windowRect(doc) : clientRect(elt);
|
|
224
|
+
var atTop = parent == doc.body;
|
|
225
|
+
var bounding = atTop ? windowRect(doc) : clientRect(parent);
|
|
218
226
|
var moveX = 0,
|
|
219
227
|
moveY = 0;
|
|
220
228
|
if (rect.top < bounding.top + getSide(scrollThreshold, "top")) moveY = -(bounding.top - rect.top + getSide(scrollMargin, "top"));else if (rect.bottom > bounding.bottom - getSide(scrollThreshold, "bottom")) moveY = rect.bottom - rect.top > bounding.bottom - bounding.top ? rect.top + getSide(scrollMargin, "top") - bounding.top : rect.bottom - bounding.bottom + getSide(scrollMargin, "bottom");
|
|
@@ -223,12 +231,12 @@ function scrollRectIntoView(view, rect, startDOM) {
|
|
|
223
231
|
if (atTop) {
|
|
224
232
|
doc.defaultView.scrollBy(moveX, moveY);
|
|
225
233
|
} else {
|
|
226
|
-
var startX =
|
|
227
|
-
startY =
|
|
228
|
-
if (moveY)
|
|
229
|
-
if (moveX)
|
|
230
|
-
var dX =
|
|
231
|
-
dY =
|
|
234
|
+
var startX = parent.scrollLeft,
|
|
235
|
+
startY = parent.scrollTop;
|
|
236
|
+
if (moveY) parent.scrollTop += moveY;
|
|
237
|
+
if (moveX) parent.scrollLeft += moveX;
|
|
238
|
+
var dX = parent.scrollLeft - startX,
|
|
239
|
+
dY = parent.scrollTop - startY;
|
|
232
240
|
rect = {
|
|
233
241
|
left: rect.left - dX,
|
|
234
242
|
top: rect.top - dY,
|
|
@@ -311,8 +319,8 @@ function focusPreventScroll(dom) {
|
|
|
311
319
|
}
|
|
312
320
|
}
|
|
313
321
|
function findOffsetInNode(node, coords) {
|
|
314
|
-
var closest
|
|
315
|
-
|
|
322
|
+
var closest;
|
|
323
|
+
var dxClosest = 2e8,
|
|
316
324
|
coordsClosest,
|
|
317
325
|
offset = 0;
|
|
318
326
|
var rowBot = coords.top,
|
|
@@ -320,7 +328,7 @@ function findOffsetInNode(node, coords) {
|
|
|
320
328
|
var firstBelow, coordsBelow;
|
|
321
329
|
for (var child = node.firstChild, childIndex = 0; child; child = child.nextSibling, childIndex++) {
|
|
322
330
|
var rects = void 0;
|
|
323
|
-
if (child
|
|
331
|
+
if (isElt(child)) rects = child.getClientRects();else if (isText(child)) rects = textRange(child).getClientRects();else continue;
|
|
324
332
|
for (var i = 0; i < rects.length; i++) {
|
|
325
333
|
var rect = rects[i];
|
|
326
334
|
if (rect.top <= rowBot && rect.bottom >= rowTop) {
|
|
@@ -330,11 +338,11 @@ function findOffsetInNode(node, coords) {
|
|
|
330
338
|
if (dx < dxClosest) {
|
|
331
339
|
closest = child;
|
|
332
340
|
dxClosest = dx;
|
|
333
|
-
coordsClosest = dx && closest
|
|
341
|
+
coordsClosest = dx && isText(closest) ? {
|
|
334
342
|
left: rect.right < coords.left ? rect.right : rect.left,
|
|
335
343
|
top: coords.top
|
|
336
344
|
} : coords;
|
|
337
|
-
if (child
|
|
345
|
+
if (isElt(child) && dx) offset = childIndex + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0);
|
|
338
346
|
continue;
|
|
339
347
|
}
|
|
340
348
|
} else if (rect.top > coords.top && !firstBelow && rect.left <= coords.left && rect.right >= coords.left) {
|
|
@@ -352,8 +360,8 @@ function findOffsetInNode(node, coords) {
|
|
|
352
360
|
coordsClosest = coordsBelow;
|
|
353
361
|
dxClosest = 0;
|
|
354
362
|
}
|
|
355
|
-
if (closest && closest
|
|
356
|
-
if (!closest || dxClosest
|
|
363
|
+
if (closest && isText(closest)) return findOffsetInText(closest, coordsClosest);
|
|
364
|
+
if (!closest || dxClosest) return {
|
|
357
365
|
node: node,
|
|
358
366
|
offset: offset
|
|
359
367
|
};
|
|
@@ -395,7 +403,7 @@ function posFromElement(view, elt, coords) {
|
|
|
395
403
|
node = _findOffsetInNode.node,
|
|
396
404
|
offset = _findOffsetInNode.offset,
|
|
397
405
|
bias = -1;
|
|
398
|
-
if (node
|
|
406
|
+
if (isElt(node) && !node.firstChild) {
|
|
399
407
|
var rect = node.getBoundingClientRect();
|
|
400
408
|
bias = rect.left != rect.right && coords.left > (rect.left + rect.right) / 2 ? 1 : -1;
|
|
401
409
|
}
|
|
@@ -408,7 +416,7 @@ function posFromCaret(view, node, offset, coords) {
|
|
|
408
416
|
var desc = view.docView.nearestDesc(cur, true),
|
|
409
417
|
rect = void 0;
|
|
410
418
|
if (!desc) return null;
|
|
411
|
-
if (desc.dom
|
|
419
|
+
if (isElt(desc.dom) && (desc.node.isBlock && desc.parent || !desc.contentDOM) && ((rect = desc.dom.getBoundingClientRect()).width || rect.height)) {
|
|
412
420
|
if (desc.node.isBlock && desc.parent && !/^T(R|BODY|HEAD|FOOT)$/.test(desc.dom.nodeName)) {
|
|
413
421
|
if (!sawBlock && rect.left > coords.left || rect.top > coords.top) outsideBlock = desc.posBefore;else if (!sawBlock && rect.right < coords.left || rect.bottom < coords.top) outsideBlock = desc.posAfter;
|
|
414
422
|
sawBlock = true;
|
|
@@ -427,7 +435,7 @@ function elementFromPoint(element, coords, box) {
|
|
|
427
435
|
if (len && box.top < box.bottom) {
|
|
428
436
|
for (var startI = Math.max(0, Math.min(len - 1, Math.floor(len * (coords.top - box.top) / (box.bottom - box.top)) - 2)), i = startI;;) {
|
|
429
437
|
var child = element.childNodes[i];
|
|
430
|
-
if (child
|
|
438
|
+
if (isElt(child)) {
|
|
431
439
|
var rects = child.getClientRects();
|
|
432
440
|
for (var j = 0; j < rects.length; j++) {
|
|
433
441
|
var rect = rects[j];
|
|
@@ -450,7 +458,7 @@ function _posAtCoords(view, coords) {
|
|
|
450
458
|
}
|
|
451
459
|
var elt = (view.root.elementFromPoint ? view.root : doc).elementFromPoint(coords.left, coords.top);
|
|
452
460
|
var pos;
|
|
453
|
-
if (!elt || !view.dom.contains(elt
|
|
461
|
+
if (!elt || !view.dom.contains(elt)) {
|
|
454
462
|
var box = view.dom.getBoundingClientRect();
|
|
455
463
|
if (!inRect(coords, box)) return null;
|
|
456
464
|
elt = elementFromPoint(view.dom, coords, box);
|
|
@@ -461,7 +469,7 @@ function _posAtCoords(view, coords) {
|
|
|
461
469
|
}
|
|
462
470
|
elt = targetKludge(elt, coords);
|
|
463
471
|
if (node) {
|
|
464
|
-
if (gecko && node
|
|
472
|
+
if (gecko && isElt(node)) {
|
|
465
473
|
offset = Math.min(offset, node.childNodes.length);
|
|
466
474
|
if (offset < node.childNodes.length) {
|
|
467
475
|
var next = node.childNodes[offset],
|
|
@@ -470,8 +478,8 @@ function _posAtCoords(view, coords) {
|
|
|
470
478
|
}
|
|
471
479
|
}
|
|
472
480
|
var prev;
|
|
473
|
-
if (webkit && offset && node
|
|
474
|
-
if (node == view.dom && offset == node.childNodes.length - 1 && node.lastChild
|
|
481
|
+
if (webkit && offset && isElt(node) && isElt(prev = node.childNodes[offset - 1]) && prev.contentEditable == "false" && prev.getBoundingClientRect().top >= coords.top) offset--;
|
|
482
|
+
if (node == view.dom && offset == node.childNodes.length - 1 && isElt(node.lastChild) && coords.top > node.lastChild.getBoundingClientRect().bottom) pos = view.state.doc.content.size;else if (offset == 0 || !isElt(node) || node.childNodes[offset - 1].nodeName != "BR") pos = posFromCaret(view, node, offset, coords);
|
|
475
483
|
}
|
|
476
484
|
if (pos == null) pos = posFromElement(view, elt, coords);
|
|
477
485
|
var desc = view.docView.nearestDesc(elt, true);
|
|
@@ -498,7 +506,7 @@ function _coordsAtPos(view, pos, side) {
|
|
|
498
506
|
offset = _view$docView$domFrom.offset,
|
|
499
507
|
atom = _view$docView$domFrom.atom;
|
|
500
508
|
var supportEmptyRange = webkit || gecko;
|
|
501
|
-
if (node
|
|
509
|
+
if (isText(node)) {
|
|
502
510
|
if (supportEmptyRange && (BIDI.test(node.nodeValue) || (side < 0 ? !offset : offset == node.nodeValue.length))) {
|
|
503
511
|
var rect = singleRect(textRange(node, offset, offset), side);
|
|
504
512
|
if (gecko && offset && /\s/.test(node.nodeValue[offset - 1]) && offset < node.nodeValue.length) {
|
|
@@ -531,26 +539,26 @@ function _coordsAtPos(view, pos, side) {
|
|
|
531
539
|
if (!$dom.parent.inlineContent) {
|
|
532
540
|
if (atom == null && offset && (side < 0 || offset == nodeSize(node))) {
|
|
533
541
|
var before = node.childNodes[offset - 1];
|
|
534
|
-
if (before
|
|
542
|
+
if (isElt(before)) return flattenH(before.getBoundingClientRect(), false);
|
|
535
543
|
}
|
|
536
544
|
if (atom == null && offset < nodeSize(node)) {
|
|
537
545
|
var after = node.childNodes[offset];
|
|
538
|
-
if (after
|
|
546
|
+
if (isElt(after)) return flattenH(after.getBoundingClientRect(), true);
|
|
539
547
|
}
|
|
540
548
|
return flattenH(node.getBoundingClientRect(), side >= 0);
|
|
541
549
|
}
|
|
542
550
|
if (atom == null && offset && (side < 0 || offset == nodeSize(node))) {
|
|
543
551
|
var _before = node.childNodes[offset - 1];
|
|
544
|
-
var target = _before
|
|
552
|
+
var target = isText(_before) ? textRange(_before, nodeSize(_before) - (supportEmptyRange ? 0 : 1)) : isElt(_before) && (_before.nodeName != "BR" || !_before.nextSibling) ? _before : null;
|
|
545
553
|
if (target) return flattenV(singleRect(target, 1), false);
|
|
546
554
|
}
|
|
547
555
|
if (atom == null && offset < nodeSize(node)) {
|
|
548
556
|
var _after = node.childNodes[offset];
|
|
549
557
|
while (_after.pmViewDesc && _after.pmViewDesc.ignoreForCoords) _after = _after.nextSibling;
|
|
550
|
-
var _target = !_after ? null : _after
|
|
558
|
+
var _target = !_after ? null : isText(_after) ? textRange(_after, 0, supportEmptyRange ? 0 : 1) : isElt(_after) ? _after : null;
|
|
551
559
|
if (_target) return flattenV(singleRect(_target, -1), true);
|
|
552
560
|
}
|
|
553
|
-
return flattenV(singleRect(node
|
|
561
|
+
return flattenV(singleRect(isText(node) ? textRange(node) : node, -side), side >= 0);
|
|
554
562
|
}
|
|
555
563
|
function flattenV(rect, left) {
|
|
556
564
|
if (rect.width == 0) return rect;
|
|
@@ -602,7 +610,7 @@ function endOfTextblockVertical(view, state, dir) {
|
|
|
602
610
|
var coords = _coordsAtPos(view, $pos.pos, 1);
|
|
603
611
|
for (var child = dom.firstChild; child; child = child.nextSibling) {
|
|
604
612
|
var boxes = void 0;
|
|
605
|
-
if (child
|
|
613
|
+
if (isElt(child)) boxes = child.getClientRects();else if (isText(child)) boxes = textRange(child, 0, child.nodeValue.length).getClientRects();else continue;
|
|
606
614
|
for (var i = 0; i < boxes.length; i++) {
|
|
607
615
|
var box = boxes[i];
|
|
608
616
|
if (box.bottom > box.top + 1 && (dir == "up" ? coords.top - box.top > (box.bottom - coords.top) * 2 : box.bottom - coords.bottom > (coords.bottom - box.top) * 2)) return false;
|
|
@@ -633,7 +641,7 @@ function endOfTextblockHorizontal(view, state, dir) {
|
|
|
633
641
|
var _view$domSelectionRan2 = view.domSelectionRange(),
|
|
634
642
|
newNode = _view$domSelectionRan2.focusNode,
|
|
635
643
|
newOff = _view$domSelectionRan2.focusOffset;
|
|
636
|
-
var result = newNode && !
|
|
644
|
+
var result = newNode && !contains(parentDOM, newNode) || oldNode == newNode && oldOff == newOff;
|
|
637
645
|
try {
|
|
638
646
|
sel.collapse(anchorNode, anchorOffset);
|
|
639
647
|
if (oldNode && (oldNode != anchorNode || oldOff != anchorOffset) && sel.extend) sel.extend(oldNode, oldOff);
|
|
@@ -746,7 +754,7 @@ var ViewDesc = function () {
|
|
|
746
754
|
}, {
|
|
747
755
|
key: "localPosFromDOM",
|
|
748
756
|
value: function localPosFromDOM(dom, offset, bias) {
|
|
749
|
-
if (this.contentDOM && this.contentDOM
|
|
757
|
+
if (this.contentDOM && contains(this.contentDOM, dom)) {
|
|
750
758
|
if (bias < 0) {
|
|
751
759
|
var domBefore, desc;
|
|
752
760
|
if (dom == this.contentDOM) {
|
|
@@ -773,7 +781,7 @@ var ViewDesc = function () {
|
|
|
773
781
|
if (dom == this.dom && this.contentDOM) {
|
|
774
782
|
atEnd = offset > domIndex(this.contentDOM);
|
|
775
783
|
} else if (this.contentDOM && this.contentDOM != this.dom && this.dom.contains(this.contentDOM)) {
|
|
776
|
-
atEnd = dom.compareDocumentPosition(this.contentDOM) &
|
|
784
|
+
atEnd = !!(dom.compareDocumentPosition(this.contentDOM) & 4);
|
|
777
785
|
} else if (this.dom.firstChild) {
|
|
778
786
|
if (offset == 0) for (var search = dom;; search = search.parentNode) {
|
|
779
787
|
if (search == this.dom) {
|
|
@@ -800,7 +808,7 @@ var ViewDesc = function () {
|
|
|
800
808
|
var desc = this.getDesc(cur),
|
|
801
809
|
nodeDOM = void 0;
|
|
802
810
|
if (desc && (!onlyNodes || desc.node)) {
|
|
803
|
-
if (first && (nodeDOM = desc.nodeDOM) && !(nodeDOM
|
|
811
|
+
if (first && (nodeDOM = desc.nodeDOM) && !(isElt(nodeDOM) ? contains(nodeDOM, dom) : nodeDOM == dom)) first = false;else return desc;
|
|
804
812
|
}
|
|
805
813
|
}
|
|
806
814
|
}
|
|
@@ -854,14 +862,17 @@ var ViewDesc = function () {
|
|
|
854
862
|
for (var curPos = 0; i < this.children.length; i++) {
|
|
855
863
|
var child = this.children[i],
|
|
856
864
|
end = curPos + child.size;
|
|
857
|
-
if (end > pos
|
|
865
|
+
if (end > pos) {
|
|
858
866
|
offset = pos - curPos;
|
|
859
867
|
break;
|
|
860
868
|
}
|
|
861
869
|
curPos = end;
|
|
862
870
|
}
|
|
863
871
|
if (offset) return this.children[i].domFromPos(offset - this.children[i].border, side);
|
|
864
|
-
for (
|
|
872
|
+
for (; i > 0; i--) {
|
|
873
|
+
var prev = this.children[i - 1];
|
|
874
|
+
if (prev.size || !(prev instanceof BufferHackViewDesc || prev instanceof WidgetViewDesc && prev.side >= 0)) break;
|
|
875
|
+
}
|
|
865
876
|
if (side <= 0) {
|
|
866
877
|
var _prev,
|
|
867
878
|
enter = true;
|
|
@@ -954,7 +965,7 @@ var ViewDesc = function () {
|
|
|
954
965
|
var _this$domFromPos = this.domFromPos(pos, 0),
|
|
955
966
|
node = _this$domFromPos.node,
|
|
956
967
|
offset = _this$domFromPos.offset;
|
|
957
|
-
if (node
|
|
968
|
+
if (!isElt(node) || offset == node.childNodes.length) throw new RangeError("No node after pos " + pos);
|
|
958
969
|
return node.childNodes[offset];
|
|
959
970
|
}
|
|
960
971
|
}, {
|
|
@@ -978,7 +989,7 @@ var ViewDesc = function () {
|
|
|
978
989
|
var _anchorDOM = anchorDOM,
|
|
979
990
|
node = _anchorDOM.node,
|
|
980
991
|
_offset = _anchorDOM.offset;
|
|
981
|
-
if (node
|
|
992
|
+
if (isText(node)) {
|
|
982
993
|
brKludge = !!(_offset && node.nodeValue[_offset - 1] == "\n");
|
|
983
994
|
if (brKludge && _offset == node.nodeValue.length) {
|
|
984
995
|
for (var scan = node, after; scan; scan = scan.parentNode) {
|
|
@@ -998,7 +1009,7 @@ var ViewDesc = function () {
|
|
|
998
1009
|
brKludge = prev && (prev.nodeName == "BR" || prev.contentEditable == "false");
|
|
999
1010
|
}
|
|
1000
1011
|
}
|
|
1001
|
-
if (gecko && selRange.focusNode && selRange.focusNode != headDOM.node && selRange.focusNode
|
|
1012
|
+
if (gecko && selRange.focusNode && selRange.focusNode != headDOM.node && isElt(selRange.focusNode)) {
|
|
1002
1013
|
var _after2 = selRange.focusNode.childNodes[selRange.focusOffset];
|
|
1003
1014
|
if (_after2 && _after2.contentEditable == "false") force = true;
|
|
1004
1015
|
}
|
|
@@ -1100,13 +1111,10 @@ var WidgetViewDesc = function (_ViewDesc) {
|
|
|
1100
1111
|
if (self.parent) return self.parent.posBeforeChild(self);
|
|
1101
1112
|
});
|
|
1102
1113
|
if (!widget.type.spec.raw) {
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
}
|
|
1108
|
-
if (!dom.hasAttribute("contenteditable")) dom.contentEditable = "false";
|
|
1109
|
-
dom.classList.add("ProseMirror-widget");
|
|
1114
|
+
var elt = isElt(dom) ? dom : document.createElement("span");
|
|
1115
|
+
if (elt != dom) elt.appendChild(dom);
|
|
1116
|
+
if (!elt.hasAttribute("contenteditable")) elt.contentEditable = "false";
|
|
1117
|
+
elt.classList.add("ProseMirror-widget");
|
|
1110
1118
|
}
|
|
1111
1119
|
_this = _super.call(this, parent, [], dom, null);
|
|
1112
1120
|
_this.widget = widget;
|
|
@@ -1309,7 +1317,7 @@ var NodeViewDesc = function (_ViewDesc4) {
|
|
|
1309
1317
|
}
|
|
1310
1318
|
if (!rule.contentElement) {
|
|
1311
1319
|
var found = addedNodes && addedNodes.find(function (n) {
|
|
1312
|
-
return n
|
|
1320
|
+
return isElt(n) && addedNodes.indexOf(n.parentNode) < 0 && _this5.dom.contains(n);
|
|
1313
1321
|
});
|
|
1314
1322
|
if (found) rule.contentElement = found;else rule.getContent = function () {
|
|
1315
1323
|
return prosemirrorModel.Fragment.empty;
|
|
@@ -1343,16 +1351,20 @@ var NodeViewDesc = function (_ViewDesc4) {
|
|
|
1343
1351
|
var localComposition = composition && composition.pos > -1 ? composition : null;
|
|
1344
1352
|
var compositionInChild = composition && composition.pos < 0;
|
|
1345
1353
|
var updater = new ViewTreeUpdater(this, localComposition && localComposition.node, view);
|
|
1354
|
+
var addBuffers = this.node.inlineContent,
|
|
1355
|
+
atBufferPos = addBuffers && this.node.isBlock;
|
|
1346
1356
|
iterDeco(this.node, this.innerDeco, function (widget, i, insideNode) {
|
|
1347
1357
|
if (widget.spec.marks) updater.syncToMarks(widget.spec.marks, inline, view, i);else if (widget.type.side >= 0 && !insideNode) updater.syncToMarks(i == _this6.node.childCount ? prosemirrorModel.Mark.none : _this6.node.child(i).marks, inline, view, i);
|
|
1348
1358
|
updater.placeWidget(widget, view, off);
|
|
1349
1359
|
}, function (child, outerDeco, innerDeco, i) {
|
|
1350
1360
|
updater.syncToMarks(child.marks, inline, view, i);
|
|
1361
|
+
if (atBufferPos && child.isAtom && !child.isText) updater.addHackNode("IMG", updater.top);
|
|
1351
1362
|
var compIndex;
|
|
1352
1363
|
if (updater.findNodeMatch(child, outerDeco, innerDeco, i)) ;else if (compositionInChild && view.state.selection.from > off && view.state.selection.to < off + child.nodeSize && (compIndex = updater.findIndexWithChild(composition.node)) > -1 && updater.updateNodeAt(child, outerDeco, innerDeco, compIndex, view)) ;else if (updater.updateNextNode(child, outerDeco, innerDeco, view, i, off)) ;else {
|
|
1353
1364
|
updater.addNode(child, outerDeco, innerDeco, view, off);
|
|
1354
1365
|
}
|
|
1355
1366
|
off += child.nodeSize;
|
|
1367
|
+
if (addBuffers) atBufferPos = child.isAtom && !child.isText;
|
|
1356
1368
|
});
|
|
1357
1369
|
updater.syncToMarks([], inline, view, 0);
|
|
1358
1370
|
if (this.node.isTextblock) updater.addTextblockHacks();
|
|
@@ -1426,7 +1438,7 @@ var NodeViewDesc = function (_ViewDesc4) {
|
|
|
1426
1438
|
key: "updateOuterDeco",
|
|
1427
1439
|
value: function updateOuterDeco(outerDeco) {
|
|
1428
1440
|
if (sameOuterDeco(outerDeco, this.outerDeco)) return;
|
|
1429
|
-
var needsWrap = this.nodeDOM
|
|
1441
|
+
var needsWrap = !isElt(this.nodeDOM);
|
|
1430
1442
|
var oldDOM = this.dom;
|
|
1431
1443
|
this.dom = patchOuterDeco(this.dom, this.nodeDOM, computeOuterDeco(this.outerDeco, this.node, needsWrap), computeOuterDeco(outerDeco, this.node, needsWrap));
|
|
1432
1444
|
if (this.dom != oldDOM) {
|
|
@@ -1438,7 +1450,7 @@ var NodeViewDesc = function (_ViewDesc4) {
|
|
|
1438
1450
|
}, {
|
|
1439
1451
|
key: "selectNode",
|
|
1440
1452
|
value: function selectNode() {
|
|
1441
|
-
if (this.nodeDOM
|
|
1453
|
+
if (isElt(this.nodeDOM)) {
|
|
1442
1454
|
this.nodeDOM.classList.add("ProseMirror-selectednode");
|
|
1443
1455
|
if (this.contentDOM || !this.node.type.spec.draggable) this.nodeDOM.draggable = true;
|
|
1444
1456
|
}
|
|
@@ -1446,7 +1458,7 @@ var NodeViewDesc = function (_ViewDesc4) {
|
|
|
1446
1458
|
}, {
|
|
1447
1459
|
key: "deselectNode",
|
|
1448
1460
|
value: function deselectNode() {
|
|
1449
|
-
if (this.nodeDOM
|
|
1461
|
+
if (isElt(this.nodeDOM)) {
|
|
1450
1462
|
this.nodeDOM.classList.remove("ProseMirror-selectednode");
|
|
1451
1463
|
if (this.contentDOM || !this.node.type.spec.draggable) this.nodeDOM.removeAttribute("draggable");
|
|
1452
1464
|
}
|
|
@@ -1468,7 +1480,7 @@ var NodeViewDesc = function (_ViewDesc4) {
|
|
|
1468
1480
|
var dom = spec && spec.dom,
|
|
1469
1481
|
contentDOM = spec && spec.contentDOM;
|
|
1470
1482
|
if (node.isText) {
|
|
1471
|
-
if (!dom) dom = document.createTextNode(node.text);else if (dom
|
|
1483
|
+
if (!dom) dom = document.createTextNode(node.text);else if (!isText(dom)) throw new RangeError("Text must be rendered as a DOM text node");
|
|
1472
1484
|
} else if (!dom) {
|
|
1473
1485
|
var _spec = prosemirrorModel.DOMSerializer.renderSpec(document, node.type.spec.toDOM(node), null, node.attrs);
|
|
1474
1486
|
dom = _spec.dom;
|
|
@@ -1572,14 +1584,14 @@ var TextViewDesc = function (_NodeViewDesc) {
|
|
|
1572
1584
|
}]);
|
|
1573
1585
|
return TextViewDesc;
|
|
1574
1586
|
}(NodeViewDesc);
|
|
1575
|
-
var
|
|
1576
|
-
_inherits(
|
|
1577
|
-
var _super6 = _createSuper(
|
|
1578
|
-
function
|
|
1579
|
-
_classCallCheck(this,
|
|
1587
|
+
var BufferHackViewDesc = function (_ViewDesc5) {
|
|
1588
|
+
_inherits(BufferHackViewDesc, _ViewDesc5);
|
|
1589
|
+
var _super6 = _createSuper(BufferHackViewDesc);
|
|
1590
|
+
function BufferHackViewDesc() {
|
|
1591
|
+
_classCallCheck(this, BufferHackViewDesc);
|
|
1580
1592
|
return _super6.apply(this, arguments);
|
|
1581
1593
|
}
|
|
1582
|
-
_createClass(
|
|
1594
|
+
_createClass(BufferHackViewDesc, [{
|
|
1583
1595
|
key: "parseRule",
|
|
1584
1596
|
value: function parseRule() {
|
|
1585
1597
|
return {
|
|
@@ -1602,7 +1614,7 @@ var TrailingHackViewDesc = function (_ViewDesc5) {
|
|
|
1602
1614
|
return this.dom.nodeName == "IMG";
|
|
1603
1615
|
}
|
|
1604
1616
|
}]);
|
|
1605
|
-
return
|
|
1617
|
+
return BufferHackViewDesc;
|
|
1606
1618
|
}(ViewDesc);
|
|
1607
1619
|
var CustomNodeViewDesc = function (_NodeViewDesc2) {
|
|
1608
1620
|
_inherits(CustomNodeViewDesc, _NodeViewDesc2);
|
|
@@ -1754,7 +1766,7 @@ function patchAttributes(dom, prev, cur) {
|
|
|
1754
1766
|
}
|
|
1755
1767
|
}
|
|
1756
1768
|
function applyOuterDeco(dom, deco, node) {
|
|
1757
|
-
return patchOuterDeco(dom, dom, noDeco, computeOuterDeco(deco, node, dom
|
|
1769
|
+
return patchOuterDeco(dom, dom, noDeco, computeOuterDeco(deco, node, !isElt(dom)));
|
|
1758
1770
|
}
|
|
1759
1771
|
function sameOuterDeco(a, b) {
|
|
1760
1772
|
if (a.length != b.length) return false;
|
|
@@ -1990,7 +2002,7 @@ var ViewTreeUpdater = function () {
|
|
|
1990
2002
|
dom.alt = "";
|
|
1991
2003
|
}
|
|
1992
2004
|
if (nodeName == "BR") dom.className = "ProseMirror-trailingBreak";
|
|
1993
|
-
var hack = new
|
|
2005
|
+
var hack = new BufferHackViewDesc(this.top, [], dom, null);
|
|
1994
2006
|
if (parent != this.top) parent.children.push(hack);else parent.children.splice(this.index++, 0, hack);
|
|
1995
2007
|
this.changed = true;
|
|
1996
2008
|
}
|
|
@@ -1998,7 +2010,7 @@ var ViewTreeUpdater = function () {
|
|
|
1998
2010
|
}, {
|
|
1999
2011
|
key: "isLocked",
|
|
2000
2012
|
value: function isLocked(node) {
|
|
2001
|
-
return this.lock && (node == this.lock || node
|
|
2013
|
+
return this.lock && (node == this.lock || isElt(node) && node.contains(this.lock.parentNode));
|
|
2002
2014
|
}
|
|
2003
2015
|
}]);
|
|
2004
2016
|
return ViewTreeUpdater;
|
|
@@ -2175,10 +2187,17 @@ function selectionFromDOM(view) {
|
|
|
2175
2187
|
if (selectionCollapsed(domSel)) {
|
|
2176
2188
|
anchor = head;
|
|
2177
2189
|
while (nearestDesc && !nearestDesc.node) nearestDesc = nearestDesc.parent;
|
|
2178
|
-
|
|
2179
|
-
if (nearestDesc && nearestDescNode.isAtom && prosemirrorState.NodeSelection.isSelectable(nearestDescNode) && nearestDesc.parent && !(nearestDescNode.isInline && isOnEdge(domSel.focusNode, domSel.focusOffset, nearestDesc.dom))) {
|
|
2190
|
+
if (nearestDesc && nearestDesc.node.isAtom && prosemirrorState.NodeSelection.isSelectable(nearestDesc.node) && nearestDesc.parent && !(nearestDesc.node.isInline && isOnEdge(domSel.focusNode, domSel.focusOffset, nearestDesc.dom))) {
|
|
2180
2191
|
var pos = nearestDesc.posBefore;
|
|
2181
2192
|
selection = new prosemirrorState.NodeSelection(head == pos ? $head : doc.resolve(pos));
|
|
2193
|
+
} else if (gecko && origin == "key" && head > view.state.selection.to && isElt(domSel.focusNode) && domSel.focusOffset == domSel.focusNode.childNodes.length && nearestDesc && nearestDesc.posAtStart > view.state.selection.to) {
|
|
2194
|
+
for (var scan = domSel.focusNode;; scan = scan.parentNode) {
|
|
2195
|
+
if (getComputedStyle(scan).overflow != "visible") {
|
|
2196
|
+
selection = prosemirrorState.Selection.findFrom(doc.resolve(nearestDesc.posAtStart), 1);
|
|
2197
|
+
break;
|
|
2198
|
+
}
|
|
2199
|
+
if (scan == nearestDesc.dom || scan.nextSibling || !scan.parentNode || !isElt(scan.parentNode)) break;
|
|
2200
|
+
}
|
|
2182
2201
|
}
|
|
2183
2202
|
} else {
|
|
2184
2203
|
if (domSel instanceof view.dom.ownerDocument.defaultView.Selection && domSel.rangeCount > 1) {
|
|
@@ -2335,7 +2354,7 @@ function hasSelection(view) {
|
|
|
2335
2354
|
var sel = view.domSelectionRange();
|
|
2336
2355
|
if (!sel.anchorNode) return false;
|
|
2337
2356
|
try {
|
|
2338
|
-
return view.dom
|
|
2357
|
+
return contains(view.dom, sel.anchorNode) && (view.editable || contains(view.dom, sel.focusNode));
|
|
2339
2358
|
} catch (_) {
|
|
2340
2359
|
return false;
|
|
2341
2360
|
}
|
|
@@ -2381,10 +2400,8 @@ function selectHorizontally(view, dir, mods) {
|
|
|
2381
2400
|
if (!(_node.isAtom || (desc = view.docView.descAt(nodePos)) && !desc.contentDOM)) return false;
|
|
2382
2401
|
if (prosemirrorState.NodeSelection.isSelectable(_node)) {
|
|
2383
2402
|
return apply(view, new prosemirrorState.NodeSelection(dir < 0 ? view.state.doc.resolve(_$head.pos - _node.nodeSize) : _$head));
|
|
2384
|
-
} else if (webkit) {
|
|
2385
|
-
return apply(view, new prosemirrorState.TextSelection(view.state.doc.resolve(dir < 0 ? nodePos : nodePos + _node.nodeSize)));
|
|
2386
2403
|
} else {
|
|
2387
|
-
return
|
|
2404
|
+
return apply(view, new prosemirrorState.TextSelection(view.state.doc.resolve(dir < 0 ? nodePos : nodePos + _node.nodeSize)));
|
|
2388
2405
|
}
|
|
2389
2406
|
}
|
|
2390
2407
|
} else if (sel instanceof prosemirrorState.NodeSelection && sel.node.isInline) {
|
|
@@ -2395,12 +2412,9 @@ function selectHorizontally(view, dir, mods) {
|
|
|
2395
2412
|
return false;
|
|
2396
2413
|
}
|
|
2397
2414
|
}
|
|
2398
|
-
function nodeLen(node) {
|
|
2399
|
-
return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length;
|
|
2400
|
-
}
|
|
2401
2415
|
function isIgnorable(dom, dir) {
|
|
2402
2416
|
var desc = dom.pmViewDesc;
|
|
2403
|
-
return desc ? desc.size == 0 && (dir < 0 || dom.nextSibling || dom.nodeName != "BR") : dom
|
|
2417
|
+
return desc ? desc.size == 0 && (dir < 0 || dom.nextSibling || dom.nodeName != "BR") : isElt(dom) && dom.contentEditable == "false";
|
|
2404
2418
|
}
|
|
2405
2419
|
function skipIgnoredNodes(view, dir) {
|
|
2406
2420
|
return dir < 0 ? skipIgnoredNodesBefore(view) : skipIgnoredNodesAfter(view);
|
|
@@ -2413,20 +2427,19 @@ function skipIgnoredNodesBefore(view) {
|
|
|
2413
2427
|
var moveNode,
|
|
2414
2428
|
moveOffset,
|
|
2415
2429
|
force = false;
|
|
2416
|
-
if (gecko && node
|
|
2430
|
+
if (gecko && isElt(node) && offset < nodeSize(node) && isIgnorable(node.childNodes[offset], -1)) force = true;
|
|
2417
2431
|
for (;;) {
|
|
2418
2432
|
if (offset > 0) {
|
|
2419
|
-
if (node
|
|
2420
|
-
|
|
2433
|
+
if (!isElt(node)) break;
|
|
2434
|
+
var before = node.childNodes[offset - 1];
|
|
2435
|
+
if (isIgnorable(before, -1)) {
|
|
2436
|
+
moveNode = node;
|
|
2437
|
+
moveOffset = --offset;
|
|
2438
|
+
} else if (isText(before)) {
|
|
2439
|
+
node = before;
|
|
2440
|
+
offset = node.nodeValue.length;
|
|
2421
2441
|
} else {
|
|
2422
|
-
|
|
2423
|
-
if (isIgnorable(before, -1)) {
|
|
2424
|
-
moveNode = node;
|
|
2425
|
-
moveOffset = --offset;
|
|
2426
|
-
} else if (before.nodeType == 3) {
|
|
2427
|
-
node = before;
|
|
2428
|
-
offset = node.nodeValue.length;
|
|
2429
|
-
} else break;
|
|
2442
|
+
break;
|
|
2430
2443
|
}
|
|
2431
2444
|
} else if (isBlockNode(node)) {
|
|
2432
2445
|
break;
|
|
@@ -2443,7 +2456,7 @@ function skipIgnoredNodesBefore(view) {
|
|
|
2443
2456
|
offset = 0;
|
|
2444
2457
|
} else {
|
|
2445
2458
|
node = prev;
|
|
2446
|
-
offset =
|
|
2459
|
+
offset = nodeSize(node);
|
|
2447
2460
|
}
|
|
2448
2461
|
}
|
|
2449
2462
|
}
|
|
@@ -2454,16 +2467,18 @@ function skipIgnoredNodesAfter(view) {
|
|
|
2454
2467
|
var node = sel.focusNode,
|
|
2455
2468
|
offset = sel.focusOffset;
|
|
2456
2469
|
if (!node) return;
|
|
2457
|
-
var len =
|
|
2470
|
+
var len = nodeSize(node);
|
|
2458
2471
|
var moveNode, moveOffset;
|
|
2459
2472
|
for (;;) {
|
|
2460
2473
|
if (offset < len) {
|
|
2461
|
-
if (node
|
|
2474
|
+
if (!isElt(node)) break;
|
|
2462
2475
|
var after = node.childNodes[offset];
|
|
2463
2476
|
if (isIgnorable(after, 1)) {
|
|
2464
2477
|
moveNode = node;
|
|
2465
2478
|
moveOffset = ++offset;
|
|
2466
|
-
} else
|
|
2479
|
+
} else {
|
|
2480
|
+
break;
|
|
2481
|
+
}
|
|
2467
2482
|
} else if (isBlockNode(node)) {
|
|
2468
2483
|
break;
|
|
2469
2484
|
} else {
|
|
@@ -2480,7 +2495,7 @@ function skipIgnoredNodesAfter(view) {
|
|
|
2480
2495
|
} else {
|
|
2481
2496
|
node = next;
|
|
2482
2497
|
offset = 0;
|
|
2483
|
-
len =
|
|
2498
|
+
len = nodeSize(node);
|
|
2484
2499
|
}
|
|
2485
2500
|
}
|
|
2486
2501
|
}
|
|
@@ -2497,8 +2512,8 @@ function textNodeAfter(node, offset) {
|
|
|
2497
2512
|
}
|
|
2498
2513
|
while (node && offset < node.childNodes.length) {
|
|
2499
2514
|
var next = node.childNodes[offset];
|
|
2500
|
-
if (next
|
|
2501
|
-
if (next
|
|
2515
|
+
if (isText(next)) return next;
|
|
2516
|
+
if (isElt(next) && next.contentEditable == "false") break;
|
|
2502
2517
|
node = next;
|
|
2503
2518
|
offset = 0;
|
|
2504
2519
|
}
|
|
@@ -2510,14 +2525,14 @@ function textNodeBefore(node, offset) {
|
|
|
2510
2525
|
}
|
|
2511
2526
|
while (node && offset) {
|
|
2512
2527
|
var next = node.childNodes[offset - 1];
|
|
2513
|
-
if (next
|
|
2514
|
-
if (next
|
|
2528
|
+
if (isText(next)) return next;
|
|
2529
|
+
if (isElt(next) && next.contentEditable == "false") break;
|
|
2515
2530
|
node = next;
|
|
2516
2531
|
offset = node.childNodes.length;
|
|
2517
2532
|
}
|
|
2518
2533
|
}
|
|
2519
2534
|
function setSelFocus(view, node, offset) {
|
|
2520
|
-
if (node
|
|
2535
|
+
if (!isText(node)) {
|
|
2521
2536
|
var before, after;
|
|
2522
2537
|
if (after = textNodeAfter(node, offset)) {
|
|
2523
2538
|
node = after;
|
|
@@ -2607,7 +2622,7 @@ function safariDownArrowBug(view) {
|
|
|
2607
2622
|
var _view$domSelectionRan3 = view.domSelectionRange(),
|
|
2608
2623
|
focusNode = _view$domSelectionRan3.focusNode,
|
|
2609
2624
|
focusOffset = _view$domSelectionRan3.focusOffset;
|
|
2610
|
-
if (focusNode && focusNode
|
|
2625
|
+
if (focusNode && isElt(focusNode) && focusOffset == 0 && focusNode.firstChild && isElt(focusNode.firstChild) && focusNode.firstChild.contentEditable == "false") {
|
|
2611
2626
|
var child = focusNode.firstChild;
|
|
2612
2627
|
switchEditable(view, child, "true");
|
|
2613
2628
|
setTimeout(function () {
|
|
@@ -2673,7 +2688,7 @@ function _serializeForClipboard(view, slice) {
|
|
|
2673
2688
|
var firstChild = wrap.firstChild,
|
|
2674
2689
|
needsWrap,
|
|
2675
2690
|
wrappers = 0;
|
|
2676
|
-
while (firstChild && firstChild
|
|
2691
|
+
while (firstChild && isElt(firstChild) && (needsWrap = wrapMap[firstChild.nodeName.toLowerCase()])) {
|
|
2677
2692
|
for (var i = needsWrap.length - 1; i >= 0; i--) {
|
|
2678
2693
|
var wrapper = doc.createElement(needsWrap[i]);
|
|
2679
2694
|
while (wrap.firstChild) wrapper.appendChild(wrap.firstChild);
|
|
@@ -2682,7 +2697,7 @@ function _serializeForClipboard(view, slice) {
|
|
|
2682
2697
|
}
|
|
2683
2698
|
firstChild = wrap.firstChild;
|
|
2684
2699
|
}
|
|
2685
|
-
if (firstChild && firstChild
|
|
2700
|
+
if (firstChild && isElt(firstChild)) firstChild.setAttribute("data-pm-slice", "".concat(openStart, " ").concat(openEnd).concat(wrappers ? " -".concat(wrappers) : "", " ").concat(JSON.stringify(context)));
|
|
2686
2701
|
var text = view.someProp("clipboardTextSerializer", function (f) {
|
|
2687
2702
|
return f(slice, view);
|
|
2688
2703
|
}) || slice.content.textBetween(0, slice.content.size, "\n\n");
|
|
@@ -2734,7 +2749,7 @@ function parseFromClipboard(view, text, html, plainText, $context) {
|
|
|
2734
2749
|
var sliceData = contextNode && /^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(contextNode.getAttribute("data-pm-slice") || "");
|
|
2735
2750
|
if (sliceData && sliceData[3]) for (var i = +sliceData[3]; i > 0; i--) {
|
|
2736
2751
|
var child = dom.firstChild;
|
|
2737
|
-
while (child && child
|
|
2752
|
+
while (child && !isElt(child)) child = child.nextSibling;
|
|
2738
2753
|
if (!child) break;
|
|
2739
2754
|
dom = child;
|
|
2740
2755
|
}
|
|
@@ -3093,7 +3108,7 @@ function updateSelection(view, selection, origin) {
|
|
|
3093
3108
|
if (!view.focused) view.focus();
|
|
3094
3109
|
if (view.state.selection.eq(selection)) return;
|
|
3095
3110
|
var tr = view.state.tr.setSelection(selection);
|
|
3096
|
-
|
|
3111
|
+
tr.setMeta("pointer", true);
|
|
3097
3112
|
view.dispatch(tr);
|
|
3098
3113
|
}
|
|
3099
3114
|
function selectClickedLeaf(view, inside) {
|
|
@@ -3101,7 +3116,7 @@ function selectClickedLeaf(view, inside) {
|
|
|
3101
3116
|
var $pos = view.state.doc.resolve(inside),
|
|
3102
3117
|
node = $pos.nodeAfter;
|
|
3103
3118
|
if (node && node.isAtom && prosemirrorState.NodeSelection.isSelectable(node)) {
|
|
3104
|
-
updateSelection(view, new prosemirrorState.NodeSelection($pos)
|
|
3119
|
+
updateSelection(view, new prosemirrorState.NodeSelection($pos));
|
|
3105
3120
|
return true;
|
|
3106
3121
|
}
|
|
3107
3122
|
return false;
|
|
@@ -3121,7 +3136,7 @@ function selectClickedNode(view, inside) {
|
|
|
3121
3136
|
}
|
|
3122
3137
|
}
|
|
3123
3138
|
if (selectAt != null) {
|
|
3124
|
-
updateSelection(view, prosemirrorState.NodeSelection.create(view.state.doc, selectAt)
|
|
3139
|
+
updateSelection(view, prosemirrorState.NodeSelection.create(view.state.doc, selectAt));
|
|
3125
3140
|
return true;
|
|
3126
3141
|
} else {
|
|
3127
3142
|
return false;
|
|
@@ -3147,7 +3162,7 @@ function defaultTripleClick(view, inside, event) {
|
|
|
3147
3162
|
var selection = selectionForTripleClick(view, inside, true),
|
|
3148
3163
|
doc = view.state.doc;
|
|
3149
3164
|
if (!selection) return false;
|
|
3150
|
-
updateSelection(view, selection
|
|
3165
|
+
updateSelection(view, selection);
|
|
3151
3166
|
if (selection instanceof prosemirrorState.TextSelection && doc.eq(view.state.doc)) view.input.mouseDown = new TripleClickDrag(view, selection);
|
|
3152
3167
|
return true;
|
|
3153
3168
|
}
|
|
@@ -3251,7 +3266,7 @@ var LeftMouseDown = function (_MouseDown) {
|
|
|
3251
3266
|
}
|
|
3252
3267
|
var target = flushed ? null : event.target;
|
|
3253
3268
|
var targetDesc = target ? view.docView.nearestDesc(target, true) : null;
|
|
3254
|
-
_this8.target = targetDesc && targetDesc.nodeDOM
|
|
3269
|
+
_this8.target = targetDesc && isElt(targetDesc.nodeDOM) ? targetDesc.nodeDOM : null;
|
|
3255
3270
|
var selection = view.state.selection;
|
|
3256
3271
|
if (event.button == 0 && (targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false || selection instanceof prosemirrorState.NodeSelection && selection.from <= targetPos && selection.to > targetPos)) _this8.mightDrag = {
|
|
3257
3272
|
node: targetNode,
|
|
@@ -3298,7 +3313,7 @@ var LeftMouseDown = function (_MouseDown) {
|
|
|
3298
3313
|
} else if (handleSingleClick(this.view, pos.pos, pos.inside, event, this.selectNode)) {
|
|
3299
3314
|
event.preventDefault();
|
|
3300
3315
|
} 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)) {
|
|
3301
|
-
updateSelection(this.view, prosemirrorState.Selection.near(this.view.state.doc.resolve(pos.pos))
|
|
3316
|
+
updateSelection(this.view, prosemirrorState.Selection.near(this.view.state.doc.resolve(pos.pos)));
|
|
3302
3317
|
event.preventDefault();
|
|
3303
3318
|
} else {
|
|
3304
3319
|
setSelectionOrigin(this.view, "pointer");
|
|
@@ -3355,7 +3370,7 @@ var TripleClickDrag = function (_MouseDown2) {
|
|
|
3355
3370
|
_ref6 = _slicedToArray(_ref5, 2),
|
|
3356
3371
|
anchor = _ref6[0],
|
|
3357
3372
|
head = _ref6[1];
|
|
3358
|
-
updateSelection(this.view, prosemirrorState.TextSelection.create(doc, anchor, head)
|
|
3373
|
+
updateSelection(this.view, prosemirrorState.TextSelection.create(doc, anchor, head));
|
|
3359
3374
|
}
|
|
3360
3375
|
}]);
|
|
3361
3376
|
return TripleClickDrag;
|
|
@@ -3396,10 +3411,10 @@ editHandlers.compositionstart = editHandlers.compositionupdate = function (view)
|
|
|
3396
3411
|
endComposition(view, !state.selection.empty);
|
|
3397
3412
|
if (gecko && state.selection.empty && $pos.parentOffset && !$pos.textOffset && $pos.nodeBefore.marks.length) {
|
|
3398
3413
|
var sel = view.domSelectionRange();
|
|
3399
|
-
for (var node = sel.focusNode, offset = sel.focusOffset; node && node
|
|
3414
|
+
for (var node = sel.focusNode, offset = sel.focusOffset; node && isElt(node) && offset != 0;) {
|
|
3400
3415
|
var before = offset < 0 ? node.lastChild : node.childNodes[offset - 1];
|
|
3401
3416
|
if (!before) break;
|
|
3402
|
-
if (before
|
|
3417
|
+
if (isText(before)) {
|
|
3403
3418
|
var _sel = view.domSelection();
|
|
3404
3419
|
if (_sel) _sel.collapse(before, before.nodeValue.length);
|
|
3405
3420
|
break;
|
|
@@ -3418,9 +3433,9 @@ function selectionBeforeUneditable(view) {
|
|
|
3418
3433
|
var _view$domSelectionRan4 = view.domSelectionRange(),
|
|
3419
3434
|
focusNode = _view$domSelectionRan4.focusNode,
|
|
3420
3435
|
focusOffset = _view$domSelectionRan4.focusOffset;
|
|
3421
|
-
if (!focusNode || focusNode
|
|
3436
|
+
if (!focusNode || !isElt(focusNode) || focusOffset >= focusNode.childNodes.length) return false;
|
|
3422
3437
|
var next = focusNode.childNodes[focusOffset];
|
|
3423
|
-
return next
|
|
3438
|
+
return isElt(next) && next.contentEditable == "false";
|
|
3424
3439
|
}
|
|
3425
3440
|
editHandlers.compositionend = function (view, event) {
|
|
3426
3441
|
if (view.composing) {
|
|
@@ -3581,7 +3596,7 @@ handlers.dragstart = function (view, _event) {
|
|
|
3581
3596
|
var node;
|
|
3582
3597
|
if (pos && pos.pos >= sel.from && pos.pos <= (sel instanceof prosemirrorState.NodeSelection ? sel.to - 1 : sel.to)) ;else if (mouseDown && mouseDown.mightDrag) {
|
|
3583
3598
|
node = prosemirrorState.NodeSelection.create(view.state.doc, mouseDown.mightDrag.pos);
|
|
3584
|
-
} else if (event.target && event.target
|
|
3599
|
+
} else if (event.target && isElt(event.target)) {
|
|
3585
3600
|
var desc = view.docView.nearestDesc(event.target, true);
|
|
3586
3601
|
if (desc && desc.node.type.spec.draggable && desc != view.docView) node = prosemirrorState.NodeSelection.create(view.state.doc, desc.posBefore);
|
|
3587
3602
|
}
|
|
@@ -4459,7 +4474,7 @@ var DOMObserver = function () {
|
|
|
4459
4474
|
var desc = container && this.view.docView.nearestDesc(container);
|
|
4460
4475
|
if (desc && desc.ignoreMutation({
|
|
4461
4476
|
type: "selection",
|
|
4462
|
-
target: container
|
|
4477
|
+
target: isText(container) ? container.parentNode : container
|
|
4463
4478
|
})) {
|
|
4464
4479
|
this.setCurSelection();
|
|
4465
4480
|
return true;
|
|
@@ -4519,7 +4534,7 @@ var DOMObserver = function () {
|
|
|
4519
4534
|
var node = _step3.value;
|
|
4520
4535
|
if (node.nodeName == "BR" && node.parentNode) {
|
|
4521
4536
|
var after = node.nextSibling;
|
|
4522
|
-
while (after && after
|
|
4537
|
+
while (after && isElt(after)) {
|
|
4523
4538
|
if (after.contentEditable == "false") {
|
|
4524
4539
|
node.parentNode.removeChild(node);
|
|
4525
4540
|
break;
|
|
@@ -4590,7 +4605,7 @@ var DOMObserver = function () {
|
|
|
4590
4605
|
for (var i = 0; i < mut.addedNodes.length; i++) {
|
|
4591
4606
|
var node = mut.addedNodes[i];
|
|
4592
4607
|
added.push(node);
|
|
4593
|
-
if (node
|
|
4608
|
+
if (isText(node)) this.lastChangedTextNode = node;
|
|
4594
4609
|
}
|
|
4595
4610
|
if (desc.contentDOM && desc.contentDOM != desc.dom && !desc.contentDOM.contains(mut.target)) return {
|
|
4596
4611
|
from: desc.posBefore,
|
|
@@ -4704,7 +4719,7 @@ function fixUpBadSafariComposition(view, addedNodes) {
|
|
|
4704
4719
|
var parent = nextCell;
|
|
4705
4720
|
for (;;) {
|
|
4706
4721
|
var first = parent.firstChild;
|
|
4707
|
-
if (!first || first
|
|
4722
|
+
if (!first || !isElt(first) || first.contentEditable == "false" || /^(BR|IMG)$/.test(first.nodeName)) break;
|
|
4708
4723
|
parent = first;
|
|
4709
4724
|
}
|
|
4710
4725
|
parent.insertBefore(node, parent.firstChild);
|
|
@@ -4730,7 +4745,7 @@ function parseBetween(view, from_, to_, addedNodes) {
|
|
|
4730
4745
|
var domSel = view.domSelectionRange();
|
|
4731
4746
|
var find;
|
|
4732
4747
|
var anchor = domSel.anchorNode;
|
|
4733
|
-
if (anchor && view.dom
|
|
4748
|
+
if (anchor && contains(view.dom, anchor)) {
|
|
4734
4749
|
find = [{
|
|
4735
4750
|
node: anchor,
|
|
4736
4751
|
offset: domSel.anchorOffset
|
|
@@ -4845,7 +4860,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
|
|
|
4845
4860
|
var change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide);
|
|
4846
4861
|
if (change) view.input.domChangeCount++;
|
|
4847
4862
|
if ((ios && view.input.lastIOSEnter > Date.now() - 225 || android) && addedNodes.some(function (n) {
|
|
4848
|
-
return n
|
|
4863
|
+
return isElt(n) && !isInline.test(n.nodeName);
|
|
4849
4864
|
}) && (!change || change.endA >= change.endB) && view.someProp("handleKeyDown", function (f) {
|
|
4850
4865
|
return f(view, keyEvent(13, "Enter"));
|
|
4851
4866
|
})) {
|
|
@@ -5205,11 +5220,11 @@ var EditorView = function () {
|
|
|
5205
5220
|
value: function scrollToSelection() {
|
|
5206
5221
|
var _this17 = this;
|
|
5207
5222
|
var startDOM = this.domSelectionRange().focusNode;
|
|
5208
|
-
if (!startDOM || !this.dom
|
|
5223
|
+
if (!startDOM || !contains(this.dom, startDOM)) ;else if (this.someProp("handleScrollToSelection", function (f) {
|
|
5209
5224
|
return f(_this17);
|
|
5210
5225
|
})) ;else if (this.state.selection instanceof prosemirrorState.NodeSelection) {
|
|
5211
5226
|
var target = this.docView.domAfterPos(this.state.selection.from);
|
|
5212
|
-
if (target
|
|
5227
|
+
if (isElt(target)) scrollRectIntoView(this, target.getBoundingClientRect(), startDOM);
|
|
5213
5228
|
} else {
|
|
5214
5229
|
scrollRectIntoView(this, this.coordsAtPos(this.state.selection.head, 1), startDOM);
|
|
5215
5230
|
}
|
|
@@ -5403,7 +5418,7 @@ var EditorView = function () {
|
|
|
5403
5418
|
}, {
|
|
5404
5419
|
key: "domSelectionRange",
|
|
5405
5420
|
value: function domSelectionRange() {
|
|
5406
|
-
var sel = this.domSelection();
|
|
5421
|
+
var sel = this.dom.isConnected !== false && this.domSelection();
|
|
5407
5422
|
if (!sel) return {
|
|
5408
5423
|
focusNode: null,
|
|
5409
5424
|
focusOffset: 0,
|