prosemirror-view 1.42.5 → 1.42.7
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 +30 -0
- package/dist/index.cjs +296 -239
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +229 -171
- package/package.json +1 -1
- package/src/capturekeys.ts +42 -44
- package/src/clipboard.ts +5 -4
- package/src/decoration.ts +37 -13
- package/src/dom.ts +15 -8
- package/src/domchange.ts +7 -6
- package/src/domcoords.ts +52 -53
- package/src/domobserver.ts +15 -13
- package/src/index.ts +4 -4
- package/src/input.ts +7 -7
- package/src/selection.ts +19 -6
- package/src/viewdesc.ts +42 -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,8 @@ var ViewDesc = function () {
|
|
|
746
754
|
}, {
|
|
747
755
|
key: "localPosFromDOM",
|
|
748
756
|
value: function localPosFromDOM(dom, offset, bias) {
|
|
749
|
-
|
|
757
|
+
var _this = this;
|
|
758
|
+
if (this.contentDOM && contains(this.contentDOM, dom)) {
|
|
750
759
|
if (bias < 0) {
|
|
751
760
|
var domBefore, desc;
|
|
752
761
|
if (dom == this.contentDOM) {
|
|
@@ -773,7 +782,14 @@ var ViewDesc = function () {
|
|
|
773
782
|
if (dom == this.dom && this.contentDOM) {
|
|
774
783
|
atEnd = offset > domIndex(this.contentDOM);
|
|
775
784
|
} else if (this.contentDOM && this.contentDOM != this.dom && this.dom.contains(this.contentDOM)) {
|
|
776
|
-
|
|
785
|
+
var rel = dom.compareDocumentPosition(this.contentDOM);
|
|
786
|
+
if (rel & 16) {
|
|
787
|
+
atEnd = offset > Array.from(dom.childNodes).findIndex(function (n) {
|
|
788
|
+
return n.contains(_this.contentDOM);
|
|
789
|
+
});
|
|
790
|
+
} else {
|
|
791
|
+
atEnd = !(rel & 4);
|
|
792
|
+
}
|
|
777
793
|
} else if (this.dom.firstChild) {
|
|
778
794
|
if (offset == 0) for (var search = dom;; search = search.parentNode) {
|
|
779
795
|
if (search == this.dom) {
|
|
@@ -800,7 +816,7 @@ var ViewDesc = function () {
|
|
|
800
816
|
var desc = this.getDesc(cur),
|
|
801
817
|
nodeDOM = void 0;
|
|
802
818
|
if (desc && (!onlyNodes || desc.node)) {
|
|
803
|
-
if (first && (nodeDOM = desc.nodeDOM) && !(nodeDOM
|
|
819
|
+
if (first && (nodeDOM = desc.nodeDOM) && !(isElt(nodeDOM) ? contains(nodeDOM, dom) : nodeDOM == dom)) first = false;else return desc;
|
|
804
820
|
}
|
|
805
821
|
}
|
|
806
822
|
}
|
|
@@ -854,14 +870,17 @@ var ViewDesc = function () {
|
|
|
854
870
|
for (var curPos = 0; i < this.children.length; i++) {
|
|
855
871
|
var child = this.children[i],
|
|
856
872
|
end = curPos + child.size;
|
|
857
|
-
if (end > pos
|
|
873
|
+
if (end > pos) {
|
|
858
874
|
offset = pos - curPos;
|
|
859
875
|
break;
|
|
860
876
|
}
|
|
861
877
|
curPos = end;
|
|
862
878
|
}
|
|
863
879
|
if (offset) return this.children[i].domFromPos(offset - this.children[i].border, side);
|
|
864
|
-
for (
|
|
880
|
+
for (; i > 0; i--) {
|
|
881
|
+
var prev = this.children[i - 1];
|
|
882
|
+
if (prev.size || !(prev instanceof BufferHackViewDesc || prev instanceof WidgetViewDesc && prev.side >= 0)) break;
|
|
883
|
+
}
|
|
865
884
|
if (side <= 0) {
|
|
866
885
|
var _prev,
|
|
867
886
|
enter = true;
|
|
@@ -954,7 +973,7 @@ var ViewDesc = function () {
|
|
|
954
973
|
var _this$domFromPos = this.domFromPos(pos, 0),
|
|
955
974
|
node = _this$domFromPos.node,
|
|
956
975
|
offset = _this$domFromPos.offset;
|
|
957
|
-
if (node
|
|
976
|
+
if (!isElt(node) || offset == node.childNodes.length) throw new RangeError("No node after pos " + pos);
|
|
958
977
|
return node.childNodes[offset];
|
|
959
978
|
}
|
|
960
979
|
}, {
|
|
@@ -978,7 +997,7 @@ var ViewDesc = function () {
|
|
|
978
997
|
var _anchorDOM = anchorDOM,
|
|
979
998
|
node = _anchorDOM.node,
|
|
980
999
|
_offset = _anchorDOM.offset;
|
|
981
|
-
if (node
|
|
1000
|
+
if (isText(node)) {
|
|
982
1001
|
brKludge = !!(_offset && node.nodeValue[_offset - 1] == "\n");
|
|
983
1002
|
if (brKludge && _offset == node.nodeValue.length) {
|
|
984
1003
|
for (var scan = node, after; scan; scan = scan.parentNode) {
|
|
@@ -998,7 +1017,7 @@ var ViewDesc = function () {
|
|
|
998
1017
|
brKludge = prev && (prev.nodeName == "BR" || prev.contentEditable == "false");
|
|
999
1018
|
}
|
|
1000
1019
|
}
|
|
1001
|
-
if (gecko && selRange.focusNode && selRange.focusNode != headDOM.node && selRange.focusNode
|
|
1020
|
+
if (gecko && selRange.focusNode && selRange.focusNode != headDOM.node && isElt(selRange.focusNode)) {
|
|
1002
1021
|
var _after2 = selRange.focusNode.childNodes[selRange.focusOffset];
|
|
1003
1022
|
if (_after2 && _after2.contentEditable == "false") force = true;
|
|
1004
1023
|
}
|
|
@@ -1091,7 +1110,7 @@ var WidgetViewDesc = function (_ViewDesc) {
|
|
|
1091
1110
|
_inherits(WidgetViewDesc, _ViewDesc);
|
|
1092
1111
|
var _super = _createSuper(WidgetViewDesc);
|
|
1093
1112
|
function WidgetViewDesc(parent, widget, view, pos) {
|
|
1094
|
-
var
|
|
1113
|
+
var _this2;
|
|
1095
1114
|
_classCallCheck(this, WidgetViewDesc);
|
|
1096
1115
|
var self,
|
|
1097
1116
|
dom = widget.type.toDOM;
|
|
@@ -1100,19 +1119,16 @@ var WidgetViewDesc = function (_ViewDesc) {
|
|
|
1100
1119
|
if (self.parent) return self.parent.posBeforeChild(self);
|
|
1101
1120
|
});
|
|
1102
1121
|
if (!widget.type.spec.raw) {
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
_this.widget = widget;
|
|
1114
|
-
self = _assertThisInitialized(_this);
|
|
1115
|
-
return _this;
|
|
1122
|
+
var elt = isElt(dom) ? dom : document.createElement("span");
|
|
1123
|
+
if (elt != dom) elt.appendChild(dom);
|
|
1124
|
+
if (!elt.hasAttribute("contenteditable")) elt.contentEditable = "false";
|
|
1125
|
+
elt.classList.add("ProseMirror-widget");
|
|
1126
|
+
}
|
|
1127
|
+
_this2 = _super.call(this, parent, [], dom, null);
|
|
1128
|
+
_this2.widget = widget;
|
|
1129
|
+
_this2.widget = widget;
|
|
1130
|
+
self = _assertThisInitialized(_this2);
|
|
1131
|
+
return _this2;
|
|
1116
1132
|
}
|
|
1117
1133
|
_createClass(WidgetViewDesc, [{
|
|
1118
1134
|
key: "matchesWidget",
|
|
@@ -1165,12 +1181,12 @@ var CompositionViewDesc = function (_ViewDesc2) {
|
|
|
1165
1181
|
_inherits(CompositionViewDesc, _ViewDesc2);
|
|
1166
1182
|
var _super2 = _createSuper(CompositionViewDesc);
|
|
1167
1183
|
function CompositionViewDesc(parent, dom, textDOM, text) {
|
|
1168
|
-
var
|
|
1184
|
+
var _this3;
|
|
1169
1185
|
_classCallCheck(this, CompositionViewDesc);
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
return
|
|
1186
|
+
_this3 = _super2.call(this, parent, [], dom, null);
|
|
1187
|
+
_this3.textDOM = textDOM;
|
|
1188
|
+
_this3.text = text;
|
|
1189
|
+
return _this3;
|
|
1174
1190
|
}
|
|
1175
1191
|
_createClass(CompositionViewDesc, [{
|
|
1176
1192
|
key: "size",
|
|
@@ -1203,12 +1219,12 @@ var MarkViewDesc = function (_ViewDesc3) {
|
|
|
1203
1219
|
_inherits(MarkViewDesc, _ViewDesc3);
|
|
1204
1220
|
var _super3 = _createSuper(MarkViewDesc);
|
|
1205
1221
|
function MarkViewDesc(parent, mark, dom, contentDOM, spec) {
|
|
1206
|
-
var
|
|
1222
|
+
var _this4;
|
|
1207
1223
|
_classCallCheck(this, MarkViewDesc);
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
return
|
|
1224
|
+
_this4 = _super3.call(this, parent, [], dom, contentDOM);
|
|
1225
|
+
_this4.mark = mark;
|
|
1226
|
+
_this4.spec = spec;
|
|
1227
|
+
return _this4;
|
|
1212
1228
|
}
|
|
1213
1229
|
_createClass(MarkViewDesc, [{
|
|
1214
1230
|
key: "parseRule",
|
|
@@ -1274,19 +1290,19 @@ var NodeViewDesc = function (_ViewDesc4) {
|
|
|
1274
1290
|
_inherits(NodeViewDesc, _ViewDesc4);
|
|
1275
1291
|
var _super4 = _createSuper(NodeViewDesc);
|
|
1276
1292
|
function NodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM) {
|
|
1277
|
-
var
|
|
1293
|
+
var _this5;
|
|
1278
1294
|
_classCallCheck(this, NodeViewDesc);
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
return
|
|
1295
|
+
_this5 = _super4.call(this, parent, [], dom, contentDOM);
|
|
1296
|
+
_this5.node = node;
|
|
1297
|
+
_this5.outerDeco = outerDeco;
|
|
1298
|
+
_this5.innerDeco = innerDeco;
|
|
1299
|
+
_this5.nodeDOM = nodeDOM;
|
|
1300
|
+
return _this5;
|
|
1285
1301
|
}
|
|
1286
1302
|
_createClass(NodeViewDesc, [{
|
|
1287
1303
|
key: "parseRule",
|
|
1288
1304
|
value: function parseRule(addedNodes) {
|
|
1289
|
-
var
|
|
1305
|
+
var _this6 = this;
|
|
1290
1306
|
if (this.node.type.spec.reparseInView) return null;
|
|
1291
1307
|
var rule = {
|
|
1292
1308
|
node: this.node.type.name,
|
|
@@ -1295,7 +1311,7 @@ var NodeViewDesc = function (_ViewDesc4) {
|
|
|
1295
1311
|
if (this.node.type.whitespace == "pre") rule.preserveWhitespace = "full";
|
|
1296
1312
|
if (!this.contentDOM) {
|
|
1297
1313
|
rule.getContent = function () {
|
|
1298
|
-
return
|
|
1314
|
+
return _this6.node.content;
|
|
1299
1315
|
};
|
|
1300
1316
|
} else if (!this.contentLost) {
|
|
1301
1317
|
rule.contentElement = this.contentDOM;
|
|
@@ -1309,7 +1325,7 @@ var NodeViewDesc = function (_ViewDesc4) {
|
|
|
1309
1325
|
}
|
|
1310
1326
|
if (!rule.contentElement) {
|
|
1311
1327
|
var found = addedNodes && addedNodes.find(function (n) {
|
|
1312
|
-
return n
|
|
1328
|
+
return isElt(n) && addedNodes.indexOf(n.parentNode) < 0 && _this6.dom.contains(n);
|
|
1313
1329
|
});
|
|
1314
1330
|
if (found) rule.contentElement = found;else rule.getContent = function () {
|
|
1315
1331
|
return prosemirrorModel.Fragment.empty;
|
|
@@ -1336,23 +1352,27 @@ var NodeViewDesc = function (_ViewDesc4) {
|
|
|
1336
1352
|
}, {
|
|
1337
1353
|
key: "updateChildren",
|
|
1338
1354
|
value: function updateChildren(view, pos) {
|
|
1339
|
-
var
|
|
1355
|
+
var _this7 = this;
|
|
1340
1356
|
var inline = this.node.inlineContent,
|
|
1341
1357
|
off = pos;
|
|
1342
1358
|
var composition = view.composing ? this.localCompositionInfo(view, pos) : null;
|
|
1343
1359
|
var localComposition = composition && composition.pos > -1 ? composition : null;
|
|
1344
1360
|
var compositionInChild = composition && composition.pos < 0;
|
|
1345
1361
|
var updater = new ViewTreeUpdater(this, localComposition && localComposition.node, view);
|
|
1362
|
+
var addBuffers = this.node.inlineContent,
|
|
1363
|
+
atBufferPos = addBuffers && this.node.isBlock;
|
|
1346
1364
|
iterDeco(this.node, this.innerDeco, function (widget, i, insideNode) {
|
|
1347
|
-
if (widget.spec.marks) updater.syncToMarks(widget.spec.marks, inline, view, i);else if (widget.type.side >= 0 && !insideNode) updater.syncToMarks(i ==
|
|
1365
|
+
if (widget.spec.marks) updater.syncToMarks(widget.spec.marks, inline, view, i);else if (widget.type.side >= 0 && !insideNode) updater.syncToMarks(i == _this7.node.childCount ? prosemirrorModel.Mark.none : _this7.node.child(i).marks, inline, view, i);
|
|
1348
1366
|
updater.placeWidget(widget, view, off);
|
|
1349
1367
|
}, function (child, outerDeco, innerDeco, i) {
|
|
1350
1368
|
updater.syncToMarks(child.marks, inline, view, i);
|
|
1369
|
+
if (atBufferPos && child.isAtom && !child.isText) updater.addHackNode("IMG", updater.top);
|
|
1351
1370
|
var compIndex;
|
|
1352
1371
|
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
1372
|
updater.addNode(child, outerDeco, innerDeco, view, off);
|
|
1354
1373
|
}
|
|
1355
1374
|
off += child.nodeSize;
|
|
1375
|
+
if (addBuffers) atBufferPos = child.isAtom && !child.isText;
|
|
1356
1376
|
});
|
|
1357
1377
|
updater.syncToMarks([], inline, view, 0);
|
|
1358
1378
|
if (this.node.isTextblock) updater.addTextblockHacks();
|
|
@@ -1426,7 +1446,7 @@ var NodeViewDesc = function (_ViewDesc4) {
|
|
|
1426
1446
|
key: "updateOuterDeco",
|
|
1427
1447
|
value: function updateOuterDeco(outerDeco) {
|
|
1428
1448
|
if (sameOuterDeco(outerDeco, this.outerDeco)) return;
|
|
1429
|
-
var needsWrap = this.nodeDOM
|
|
1449
|
+
var needsWrap = !isElt(this.nodeDOM);
|
|
1430
1450
|
var oldDOM = this.dom;
|
|
1431
1451
|
this.dom = patchOuterDeco(this.dom, this.nodeDOM, computeOuterDeco(this.outerDeco, this.node, needsWrap), computeOuterDeco(outerDeco, this.node, needsWrap));
|
|
1432
1452
|
if (this.dom != oldDOM) {
|
|
@@ -1438,7 +1458,7 @@ var NodeViewDesc = function (_ViewDesc4) {
|
|
|
1438
1458
|
}, {
|
|
1439
1459
|
key: "selectNode",
|
|
1440
1460
|
value: function selectNode() {
|
|
1441
|
-
if (this.nodeDOM
|
|
1461
|
+
if (isElt(this.nodeDOM)) {
|
|
1442
1462
|
this.nodeDOM.classList.add("ProseMirror-selectednode");
|
|
1443
1463
|
if (this.contentDOM || !this.node.type.spec.draggable) this.nodeDOM.draggable = true;
|
|
1444
1464
|
}
|
|
@@ -1446,7 +1466,7 @@ var NodeViewDesc = function (_ViewDesc4) {
|
|
|
1446
1466
|
}, {
|
|
1447
1467
|
key: "deselectNode",
|
|
1448
1468
|
value: function deselectNode() {
|
|
1449
|
-
if (this.nodeDOM
|
|
1469
|
+
if (isElt(this.nodeDOM)) {
|
|
1450
1470
|
this.nodeDOM.classList.remove("ProseMirror-selectednode");
|
|
1451
1471
|
if (this.contentDOM || !this.node.type.spec.draggable) this.nodeDOM.removeAttribute("draggable");
|
|
1452
1472
|
}
|
|
@@ -1468,7 +1488,7 @@ var NodeViewDesc = function (_ViewDesc4) {
|
|
|
1468
1488
|
var dom = spec && spec.dom,
|
|
1469
1489
|
contentDOM = spec && spec.contentDOM;
|
|
1470
1490
|
if (node.isText) {
|
|
1471
|
-
if (!dom) dom = document.createTextNode(node.text);else if (dom
|
|
1491
|
+
if (!dom) dom = document.createTextNode(node.text);else if (!isText(dom)) throw new RangeError("Text must be rendered as a DOM text node");
|
|
1472
1492
|
} else if (!dom) {
|
|
1473
1493
|
var _spec = prosemirrorModel.DOMSerializer.renderSpec(document, node.type.spec.toDOM(node), null, node.attrs);
|
|
1474
1494
|
dom = _spec.dom;
|
|
@@ -1572,14 +1592,14 @@ var TextViewDesc = function (_NodeViewDesc) {
|
|
|
1572
1592
|
}]);
|
|
1573
1593
|
return TextViewDesc;
|
|
1574
1594
|
}(NodeViewDesc);
|
|
1575
|
-
var
|
|
1576
|
-
_inherits(
|
|
1577
|
-
var _super6 = _createSuper(
|
|
1578
|
-
function
|
|
1579
|
-
_classCallCheck(this,
|
|
1595
|
+
var BufferHackViewDesc = function (_ViewDesc5) {
|
|
1596
|
+
_inherits(BufferHackViewDesc, _ViewDesc5);
|
|
1597
|
+
var _super6 = _createSuper(BufferHackViewDesc);
|
|
1598
|
+
function BufferHackViewDesc() {
|
|
1599
|
+
_classCallCheck(this, BufferHackViewDesc);
|
|
1580
1600
|
return _super6.apply(this, arguments);
|
|
1581
1601
|
}
|
|
1582
|
-
_createClass(
|
|
1602
|
+
_createClass(BufferHackViewDesc, [{
|
|
1583
1603
|
key: "parseRule",
|
|
1584
1604
|
value: function parseRule() {
|
|
1585
1605
|
return {
|
|
@@ -1602,17 +1622,17 @@ var TrailingHackViewDesc = function (_ViewDesc5) {
|
|
|
1602
1622
|
return this.dom.nodeName == "IMG";
|
|
1603
1623
|
}
|
|
1604
1624
|
}]);
|
|
1605
|
-
return
|
|
1625
|
+
return BufferHackViewDesc;
|
|
1606
1626
|
}(ViewDesc);
|
|
1607
1627
|
var CustomNodeViewDesc = function (_NodeViewDesc2) {
|
|
1608
1628
|
_inherits(CustomNodeViewDesc, _NodeViewDesc2);
|
|
1609
1629
|
var _super7 = _createSuper(CustomNodeViewDesc);
|
|
1610
1630
|
function CustomNodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, spec) {
|
|
1611
|
-
var
|
|
1631
|
+
var _this8;
|
|
1612
1632
|
_classCallCheck(this, CustomNodeViewDesc);
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
return
|
|
1633
|
+
_this8 = _super7.call(this, parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM);
|
|
1634
|
+
_this8.spec = spec;
|
|
1635
|
+
return _this8;
|
|
1616
1636
|
}
|
|
1617
1637
|
_createClass(CustomNodeViewDesc, [{
|
|
1618
1638
|
key: "update",
|
|
@@ -1754,7 +1774,7 @@ function patchAttributes(dom, prev, cur) {
|
|
|
1754
1774
|
}
|
|
1755
1775
|
}
|
|
1756
1776
|
function applyOuterDeco(dom, deco, node) {
|
|
1757
|
-
return patchOuterDeco(dom, dom, noDeco, computeOuterDeco(deco, node, dom
|
|
1777
|
+
return patchOuterDeco(dom, dom, noDeco, computeOuterDeco(deco, node, !isElt(dom)));
|
|
1758
1778
|
}
|
|
1759
1779
|
function sameOuterDeco(a, b) {
|
|
1760
1780
|
if (a.length != b.length) return false;
|
|
@@ -1990,7 +2010,7 @@ var ViewTreeUpdater = function () {
|
|
|
1990
2010
|
dom.alt = "";
|
|
1991
2011
|
}
|
|
1992
2012
|
if (nodeName == "BR") dom.className = "ProseMirror-trailingBreak";
|
|
1993
|
-
var hack = new
|
|
2013
|
+
var hack = new BufferHackViewDesc(this.top, [], dom, null);
|
|
1994
2014
|
if (parent != this.top) parent.children.push(hack);else parent.children.splice(this.index++, 0, hack);
|
|
1995
2015
|
this.changed = true;
|
|
1996
2016
|
}
|
|
@@ -1998,7 +2018,7 @@ var ViewTreeUpdater = function () {
|
|
|
1998
2018
|
}, {
|
|
1999
2019
|
key: "isLocked",
|
|
2000
2020
|
value: function isLocked(node) {
|
|
2001
|
-
return this.lock && (node == this.lock || node
|
|
2021
|
+
return this.lock && (node == this.lock || isElt(node) && node.contains(this.lock.parentNode));
|
|
2002
2022
|
}
|
|
2003
2023
|
}]);
|
|
2004
2024
|
return ViewTreeUpdater;
|
|
@@ -2175,10 +2195,17 @@ function selectionFromDOM(view) {
|
|
|
2175
2195
|
if (selectionCollapsed(domSel)) {
|
|
2176
2196
|
anchor = head;
|
|
2177
2197
|
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))) {
|
|
2198
|
+
if (nearestDesc && nearestDesc.node.isAtom && prosemirrorState.NodeSelection.isSelectable(nearestDesc.node) && nearestDesc.parent && !(nearestDesc.node.isInline && isOnEdge(domSel.focusNode, domSel.focusOffset, nearestDesc.dom))) {
|
|
2180
2199
|
var pos = nearestDesc.posBefore;
|
|
2181
2200
|
selection = new prosemirrorState.NodeSelection(head == pos ? $head : doc.resolve(pos));
|
|
2201
|
+
} 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) {
|
|
2202
|
+
for (var scan = domSel.focusNode;; scan = scan.parentNode) {
|
|
2203
|
+
if (getComputedStyle(scan).overflow != "visible") {
|
|
2204
|
+
selection = prosemirrorState.Selection.findFrom(doc.resolve(nearestDesc.posAtStart), 1);
|
|
2205
|
+
break;
|
|
2206
|
+
}
|
|
2207
|
+
if (scan == nearestDesc.dom || scan.nextSibling || !scan.parentNode || !isElt(scan.parentNode)) break;
|
|
2208
|
+
}
|
|
2182
2209
|
}
|
|
2183
2210
|
} else {
|
|
2184
2211
|
if (domSel instanceof view.dom.ownerDocument.defaultView.Selection && domSel.rangeCount > 1) {
|
|
@@ -2335,7 +2362,7 @@ function hasSelection(view) {
|
|
|
2335
2362
|
var sel = view.domSelectionRange();
|
|
2336
2363
|
if (!sel.anchorNode) return false;
|
|
2337
2364
|
try {
|
|
2338
|
-
return view.dom
|
|
2365
|
+
return contains(view.dom, sel.anchorNode) && (view.editable || contains(view.dom, sel.focusNode));
|
|
2339
2366
|
} catch (_) {
|
|
2340
2367
|
return false;
|
|
2341
2368
|
}
|
|
@@ -2372,7 +2399,7 @@ function selectHorizontally(view, dir, mods) {
|
|
|
2372
2399
|
var next = moveSelectionBlock(view.state, dir);
|
|
2373
2400
|
if (next && next instanceof prosemirrorState.NodeSelection) return apply(view, next);
|
|
2374
2401
|
return false;
|
|
2375
|
-
} else if (!
|
|
2402
|
+
} else if (!mac || mods.indexOf("m") < 0) {
|
|
2376
2403
|
var _$head = sel.$head,
|
|
2377
2404
|
_node = _$head.textOffset ? null : dir < 0 ? _$head.nodeBefore : _$head.nodeAfter,
|
|
2378
2405
|
desc;
|
|
@@ -2381,10 +2408,8 @@ function selectHorizontally(view, dir, mods) {
|
|
|
2381
2408
|
if (!(_node.isAtom || (desc = view.docView.descAt(nodePos)) && !desc.contentDOM)) return false;
|
|
2382
2409
|
if (prosemirrorState.NodeSelection.isSelectable(_node)) {
|
|
2383
2410
|
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
2411
|
} else {
|
|
2387
|
-
return
|
|
2412
|
+
return apply(view, new prosemirrorState.TextSelection(view.state.doc.resolve(dir < 0 ? nodePos : nodePos + _node.nodeSize)));
|
|
2388
2413
|
}
|
|
2389
2414
|
}
|
|
2390
2415
|
} else if (sel instanceof prosemirrorState.NodeSelection && sel.node.isInline) {
|
|
@@ -2395,12 +2420,9 @@ function selectHorizontally(view, dir, mods) {
|
|
|
2395
2420
|
return false;
|
|
2396
2421
|
}
|
|
2397
2422
|
}
|
|
2398
|
-
function nodeLen(node) {
|
|
2399
|
-
return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length;
|
|
2400
|
-
}
|
|
2401
2423
|
function isIgnorable(dom, dir) {
|
|
2402
2424
|
var desc = dom.pmViewDesc;
|
|
2403
|
-
return desc ? desc.size == 0 && (dir < 0 || dom.nextSibling || dom.nodeName != "BR") : dom
|
|
2425
|
+
return desc ? desc.size == 0 && (dir < 0 || dom.nextSibling || dom.nodeName != "BR") : isElt(dom) && dom.contentEditable == "false";
|
|
2404
2426
|
}
|
|
2405
2427
|
function skipIgnoredNodes(view, dir) {
|
|
2406
2428
|
return dir < 0 ? skipIgnoredNodesBefore(view) : skipIgnoredNodesAfter(view);
|
|
@@ -2413,20 +2435,19 @@ function skipIgnoredNodesBefore(view) {
|
|
|
2413
2435
|
var moveNode,
|
|
2414
2436
|
moveOffset,
|
|
2415
2437
|
force = false;
|
|
2416
|
-
if (gecko && node
|
|
2438
|
+
if (gecko && isElt(node) && offset < nodeSize(node) && isIgnorable(node.childNodes[offset], -1)) force = true;
|
|
2417
2439
|
for (;;) {
|
|
2418
2440
|
if (offset > 0) {
|
|
2419
|
-
if (node
|
|
2420
|
-
|
|
2441
|
+
if (!isElt(node)) break;
|
|
2442
|
+
var before = node.childNodes[offset - 1];
|
|
2443
|
+
if (isIgnorable(before, -1)) {
|
|
2444
|
+
moveNode = node;
|
|
2445
|
+
moveOffset = --offset;
|
|
2446
|
+
} else if (isText(before)) {
|
|
2447
|
+
node = before;
|
|
2448
|
+
offset = node.nodeValue.length;
|
|
2421
2449
|
} 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;
|
|
2450
|
+
break;
|
|
2430
2451
|
}
|
|
2431
2452
|
} else if (isBlockNode(node)) {
|
|
2432
2453
|
break;
|
|
@@ -2443,7 +2464,7 @@ function skipIgnoredNodesBefore(view) {
|
|
|
2443
2464
|
offset = 0;
|
|
2444
2465
|
} else {
|
|
2445
2466
|
node = prev;
|
|
2446
|
-
offset =
|
|
2467
|
+
offset = nodeSize(node);
|
|
2447
2468
|
}
|
|
2448
2469
|
}
|
|
2449
2470
|
}
|
|
@@ -2454,16 +2475,18 @@ function skipIgnoredNodesAfter(view) {
|
|
|
2454
2475
|
var node = sel.focusNode,
|
|
2455
2476
|
offset = sel.focusOffset;
|
|
2456
2477
|
if (!node) return;
|
|
2457
|
-
var len =
|
|
2478
|
+
var len = nodeSize(node);
|
|
2458
2479
|
var moveNode, moveOffset;
|
|
2459
2480
|
for (;;) {
|
|
2460
2481
|
if (offset < len) {
|
|
2461
|
-
if (node
|
|
2482
|
+
if (!isElt(node)) break;
|
|
2462
2483
|
var after = node.childNodes[offset];
|
|
2463
2484
|
if (isIgnorable(after, 1)) {
|
|
2464
2485
|
moveNode = node;
|
|
2465
2486
|
moveOffset = ++offset;
|
|
2466
|
-
} else
|
|
2487
|
+
} else {
|
|
2488
|
+
break;
|
|
2489
|
+
}
|
|
2467
2490
|
} else if (isBlockNode(node)) {
|
|
2468
2491
|
break;
|
|
2469
2492
|
} else {
|
|
@@ -2480,7 +2503,7 @@ function skipIgnoredNodesAfter(view) {
|
|
|
2480
2503
|
} else {
|
|
2481
2504
|
node = next;
|
|
2482
2505
|
offset = 0;
|
|
2483
|
-
len =
|
|
2506
|
+
len = nodeSize(node);
|
|
2484
2507
|
}
|
|
2485
2508
|
}
|
|
2486
2509
|
}
|
|
@@ -2497,8 +2520,8 @@ function textNodeAfter(node, offset) {
|
|
|
2497
2520
|
}
|
|
2498
2521
|
while (node && offset < node.childNodes.length) {
|
|
2499
2522
|
var next = node.childNodes[offset];
|
|
2500
|
-
if (next
|
|
2501
|
-
if (next
|
|
2523
|
+
if (isText(next)) return next;
|
|
2524
|
+
if (isElt(next) && next.contentEditable == "false") break;
|
|
2502
2525
|
node = next;
|
|
2503
2526
|
offset = 0;
|
|
2504
2527
|
}
|
|
@@ -2510,14 +2533,14 @@ function textNodeBefore(node, offset) {
|
|
|
2510
2533
|
}
|
|
2511
2534
|
while (node && offset) {
|
|
2512
2535
|
var next = node.childNodes[offset - 1];
|
|
2513
|
-
if (next
|
|
2514
|
-
if (next
|
|
2536
|
+
if (isText(next)) return next;
|
|
2537
|
+
if (isElt(next) && next.contentEditable == "false") break;
|
|
2515
2538
|
node = next;
|
|
2516
2539
|
offset = node.childNodes.length;
|
|
2517
2540
|
}
|
|
2518
2541
|
}
|
|
2519
2542
|
function setSelFocus(view, node, offset) {
|
|
2520
|
-
if (node
|
|
2543
|
+
if (!isText(node)) {
|
|
2521
2544
|
var before, after;
|
|
2522
2545
|
if (after = textNodeAfter(node, offset)) {
|
|
2523
2546
|
node = after;
|
|
@@ -2527,15 +2550,13 @@ function setSelFocus(view, node, offset) {
|
|
|
2527
2550
|
offset = before.nodeValue.length;
|
|
2528
2551
|
}
|
|
2529
2552
|
}
|
|
2530
|
-
var sel = view.domSelection()
|
|
2553
|
+
var sel = view.domSelection(),
|
|
2554
|
+
range = view.domSelectionRange();
|
|
2531
2555
|
if (!sel) return;
|
|
2532
|
-
if (selectionCollapsed(
|
|
2533
|
-
|
|
2534
|
-
range.setEnd(node, offset);
|
|
2535
|
-
range.setStart(node, offset);
|
|
2536
|
-
sel.removeAllRanges();
|
|
2537
|
-
sel.addRange(range);
|
|
2556
|
+
if (selectionCollapsed(range)) {
|
|
2557
|
+
sel.collapse(node, offset);
|
|
2538
2558
|
} else if (sel.extend) {
|
|
2559
|
+
sel.collapse(range.anchorNode, range.anchorOffset);
|
|
2539
2560
|
sel.extend(node, offset);
|
|
2540
2561
|
}
|
|
2541
2562
|
view.domObserver.setCurSelection();
|
|
@@ -2559,7 +2580,12 @@ function findDirection(view, pos) {
|
|
|
2559
2580
|
if (_mid > coords.top && _mid < coords.bottom && Math.abs(after.left - coords.left) > 1) return after.left > coords.left ? "ltr" : "rtl";
|
|
2560
2581
|
}
|
|
2561
2582
|
}
|
|
2562
|
-
var
|
|
2583
|
+
var block = view.dom;
|
|
2584
|
+
for (var d = $pos.depth; d > 0; d--) if ($pos.node(d).isBlock) {
|
|
2585
|
+
block = view.nodeDOM($pos.before(d)) || block;
|
|
2586
|
+
break;
|
|
2587
|
+
}
|
|
2588
|
+
var computed = getComputedStyle(block).direction;
|
|
2563
2589
|
return computed == "rtl" ? "rtl" : "ltr";
|
|
2564
2590
|
}
|
|
2565
2591
|
function selectVertically(view, dir, mods) {
|
|
@@ -2607,7 +2633,7 @@ function safariDownArrowBug(view) {
|
|
|
2607
2633
|
var _view$domSelectionRan3 = view.domSelectionRange(),
|
|
2608
2634
|
focusNode = _view$domSelectionRan3.focusNode,
|
|
2609
2635
|
focusOffset = _view$domSelectionRan3.focusOffset;
|
|
2610
|
-
if (focusNode && focusNode
|
|
2636
|
+
if (focusNode && isElt(focusNode) && focusOffset == 0 && focusNode.firstChild && isElt(focusNode.firstChild) && focusNode.firstChild.contentEditable == "false") {
|
|
2611
2637
|
var child = focusNode.firstChild;
|
|
2612
2638
|
switchEditable(view, child, "true");
|
|
2613
2639
|
setTimeout(function () {
|
|
@@ -2673,7 +2699,7 @@ function _serializeForClipboard(view, slice) {
|
|
|
2673
2699
|
var firstChild = wrap.firstChild,
|
|
2674
2700
|
needsWrap,
|
|
2675
2701
|
wrappers = 0;
|
|
2676
|
-
while (firstChild && firstChild
|
|
2702
|
+
while (firstChild && isElt(firstChild) && (needsWrap = wrapMap[firstChild.nodeName.toLowerCase()])) {
|
|
2677
2703
|
for (var i = needsWrap.length - 1; i >= 0; i--) {
|
|
2678
2704
|
var wrapper = doc.createElement(needsWrap[i]);
|
|
2679
2705
|
while (wrap.firstChild) wrapper.appendChild(wrap.firstChild);
|
|
@@ -2682,7 +2708,7 @@ function _serializeForClipboard(view, slice) {
|
|
|
2682
2708
|
}
|
|
2683
2709
|
firstChild = wrap.firstChild;
|
|
2684
2710
|
}
|
|
2685
|
-
if (firstChild && firstChild
|
|
2711
|
+
if (firstChild && isElt(firstChild)) firstChild.setAttribute("data-pm-slice", "".concat(openStart, " ").concat(openEnd).concat(wrappers ? " -".concat(wrappers) : "", " ").concat(JSON.stringify(context)));
|
|
2686
2712
|
var text = view.someProp("clipboardTextSerializer", function (f) {
|
|
2687
2713
|
return f(slice, view);
|
|
2688
2714
|
}) || slice.content.textBetween(0, slice.content.size, "\n\n");
|
|
@@ -2734,7 +2760,7 @@ function parseFromClipboard(view, text, html, plainText, $context) {
|
|
|
2734
2760
|
var sliceData = contextNode && /^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(contextNode.getAttribute("data-pm-slice") || "");
|
|
2735
2761
|
if (sliceData && sliceData[3]) for (var i = +sliceData[3]; i > 0; i--) {
|
|
2736
2762
|
var child = dom.firstChild;
|
|
2737
|
-
while (child && child
|
|
2763
|
+
while (child && !isElt(child)) child = child.nextSibling;
|
|
2738
2764
|
if (!child) break;
|
|
2739
2765
|
dom = child;
|
|
2740
2766
|
}
|
|
@@ -3093,7 +3119,7 @@ function updateSelection(view, selection, origin) {
|
|
|
3093
3119
|
if (!view.focused) view.focus();
|
|
3094
3120
|
if (view.state.selection.eq(selection)) return;
|
|
3095
3121
|
var tr = view.state.tr.setSelection(selection);
|
|
3096
|
-
|
|
3122
|
+
tr.setMeta("pointer", true);
|
|
3097
3123
|
view.dispatch(tr);
|
|
3098
3124
|
}
|
|
3099
3125
|
function selectClickedLeaf(view, inside) {
|
|
@@ -3101,7 +3127,7 @@ function selectClickedLeaf(view, inside) {
|
|
|
3101
3127
|
var $pos = view.state.doc.resolve(inside),
|
|
3102
3128
|
node = $pos.nodeAfter;
|
|
3103
3129
|
if (node && node.isAtom && prosemirrorState.NodeSelection.isSelectable(node)) {
|
|
3104
|
-
updateSelection(view, new prosemirrorState.NodeSelection($pos)
|
|
3130
|
+
updateSelection(view, new prosemirrorState.NodeSelection($pos));
|
|
3105
3131
|
return true;
|
|
3106
3132
|
}
|
|
3107
3133
|
return false;
|
|
@@ -3121,7 +3147,7 @@ function selectClickedNode(view, inside) {
|
|
|
3121
3147
|
}
|
|
3122
3148
|
}
|
|
3123
3149
|
if (selectAt != null) {
|
|
3124
|
-
updateSelection(view, prosemirrorState.NodeSelection.create(view.state.doc, selectAt)
|
|
3150
|
+
updateSelection(view, prosemirrorState.NodeSelection.create(view.state.doc, selectAt));
|
|
3125
3151
|
return true;
|
|
3126
3152
|
} else {
|
|
3127
3153
|
return false;
|
|
@@ -3147,7 +3173,7 @@ function defaultTripleClick(view, inside, event) {
|
|
|
3147
3173
|
var selection = selectionForTripleClick(view, inside, true),
|
|
3148
3174
|
doc = view.state.doc;
|
|
3149
3175
|
if (!selection) return false;
|
|
3150
|
-
updateSelection(view, selection
|
|
3176
|
+
updateSelection(view, selection);
|
|
3151
3177
|
if (selection instanceof prosemirrorState.TextSelection && doc.eq(view.state.doc)) view.input.mouseDown = new TripleClickDrag(view, selection);
|
|
3152
3178
|
return true;
|
|
3153
3179
|
}
|
|
@@ -3230,16 +3256,16 @@ var LeftMouseDown = function (_MouseDown) {
|
|
|
3230
3256
|
_inherits(LeftMouseDown, _MouseDown);
|
|
3231
3257
|
var _super8 = _createSuper(LeftMouseDown);
|
|
3232
3258
|
function LeftMouseDown(view, pos, event, flushed) {
|
|
3233
|
-
var
|
|
3259
|
+
var _this9;
|
|
3234
3260
|
_classCallCheck(this, LeftMouseDown);
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3261
|
+
_this9 = _super8.call(this, view);
|
|
3262
|
+
_this9.pos = pos;
|
|
3263
|
+
_this9.event = event;
|
|
3264
|
+
_this9.flushed = flushed;
|
|
3265
|
+
_this9.delayedSelectionSync = false;
|
|
3266
|
+
_this9.startDoc = view.state.doc;
|
|
3267
|
+
_this9.selectNode = !!event[selectNodeModifier];
|
|
3268
|
+
_this9.allowDefault = event.shiftKey;
|
|
3243
3269
|
var targetNode, targetPos;
|
|
3244
3270
|
if (pos.inside > -1) {
|
|
3245
3271
|
targetNode = view.state.doc.nodeAt(pos.inside);
|
|
@@ -3251,29 +3277,29 @@ var LeftMouseDown = function (_MouseDown) {
|
|
|
3251
3277
|
}
|
|
3252
3278
|
var target = flushed ? null : event.target;
|
|
3253
3279
|
var targetDesc = target ? view.docView.nearestDesc(target, true) : null;
|
|
3254
|
-
|
|
3280
|
+
_this9.target = targetDesc && isElt(targetDesc.nodeDOM) ? targetDesc.nodeDOM : null;
|
|
3255
3281
|
var selection = view.state.selection;
|
|
3256
|
-
if (event.button == 0 && (targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false || selection instanceof prosemirrorState.NodeSelection && selection.from <= targetPos && selection.to > targetPos))
|
|
3282
|
+
if (event.button == 0 && (targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false || selection instanceof prosemirrorState.NodeSelection && selection.from <= targetPos && selection.to > targetPos)) _this9.mightDrag = {
|
|
3257
3283
|
node: targetNode,
|
|
3258
3284
|
pos: targetPos,
|
|
3259
|
-
addAttr: !!(
|
|
3260
|
-
setUneditable: !!(
|
|
3285
|
+
addAttr: !!(_this9.target && !_this9.target.draggable),
|
|
3286
|
+
setUneditable: !!(_this9.target && gecko && !_this9.target.hasAttribute("contentEditable"))
|
|
3261
3287
|
};
|
|
3262
|
-
if (
|
|
3263
|
-
|
|
3264
|
-
if (
|
|
3265
|
-
if (
|
|
3266
|
-
if (
|
|
3288
|
+
if (_this9.target && _this9.mightDrag && (_this9.mightDrag.addAttr || _this9.mightDrag.setUneditable)) {
|
|
3289
|
+
_this9.view.domObserver.stop();
|
|
3290
|
+
if (_this9.mightDrag.addAttr) _this9.target.draggable = true;
|
|
3291
|
+
if (_this9.mightDrag.setUneditable) setTimeout(function () {
|
|
3292
|
+
if (_this9.view.input.mouseDown == _assertThisInitialized(_this9)) _this9.target.setAttribute("contentEditable", "false");
|
|
3267
3293
|
}, 20);
|
|
3268
|
-
|
|
3294
|
+
_this9.view.domObserver.start();
|
|
3269
3295
|
}
|
|
3270
3296
|
setSelectionOrigin(view, "pointer");
|
|
3271
|
-
return
|
|
3297
|
+
return _this9;
|
|
3272
3298
|
}
|
|
3273
3299
|
_createClass(LeftMouseDown, [{
|
|
3274
3300
|
key: "done",
|
|
3275
3301
|
value: function done() {
|
|
3276
|
-
var
|
|
3302
|
+
var _this10 = this;
|
|
3277
3303
|
_get(_getPrototypeOf(LeftMouseDown.prototype), "done", this).call(this);
|
|
3278
3304
|
if (this.mightDrag && this.target) {
|
|
3279
3305
|
this.view.domObserver.stop();
|
|
@@ -3282,7 +3308,7 @@ var LeftMouseDown = function (_MouseDown) {
|
|
|
3282
3308
|
this.view.domObserver.start();
|
|
3283
3309
|
}
|
|
3284
3310
|
if (this.delayedSelectionSync) setTimeout(function () {
|
|
3285
|
-
if (!
|
|
3311
|
+
if (!_this10.view.isDestroyed) selectionToDOM(_this10.view);
|
|
3286
3312
|
});
|
|
3287
3313
|
}
|
|
3288
3314
|
}, {
|
|
@@ -3298,7 +3324,7 @@ var LeftMouseDown = function (_MouseDown) {
|
|
|
3298
3324
|
} else if (handleSingleClick(this.view, pos.pos, pos.inside, event, this.selectNode)) {
|
|
3299
3325
|
event.preventDefault();
|
|
3300
3326
|
} 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))
|
|
3327
|
+
updateSelection(this.view, prosemirrorState.Selection.near(this.view.state.doc.resolve(pos.pos)));
|
|
3302
3328
|
event.preventDefault();
|
|
3303
3329
|
} else {
|
|
3304
3330
|
setSelectionOrigin(this.view, "pointer");
|
|
@@ -3330,12 +3356,12 @@ var TripleClickDrag = function (_MouseDown2) {
|
|
|
3330
3356
|
_inherits(TripleClickDrag, _MouseDown2);
|
|
3331
3357
|
var _super9 = _createSuper(TripleClickDrag);
|
|
3332
3358
|
function TripleClickDrag(view, startSelection) {
|
|
3333
|
-
var
|
|
3359
|
+
var _this11;
|
|
3334
3360
|
_classCallCheck(this, TripleClickDrag);
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
return
|
|
3361
|
+
_this11 = _super9.call(this, view);
|
|
3362
|
+
_this11.startSelection = startSelection;
|
|
3363
|
+
_this11.startDoc = view.state.doc;
|
|
3364
|
+
return _this11;
|
|
3339
3365
|
}
|
|
3340
3366
|
_createClass(TripleClickDrag, [{
|
|
3341
3367
|
key: "move",
|
|
@@ -3355,7 +3381,7 @@ var TripleClickDrag = function (_MouseDown2) {
|
|
|
3355
3381
|
_ref6 = _slicedToArray(_ref5, 2),
|
|
3356
3382
|
anchor = _ref6[0],
|
|
3357
3383
|
head = _ref6[1];
|
|
3358
|
-
updateSelection(this.view, prosemirrorState.TextSelection.create(doc, anchor, head)
|
|
3384
|
+
updateSelection(this.view, prosemirrorState.TextSelection.create(doc, anchor, head));
|
|
3359
3385
|
}
|
|
3360
3386
|
}]);
|
|
3361
3387
|
return TripleClickDrag;
|
|
@@ -3396,10 +3422,10 @@ editHandlers.compositionstart = editHandlers.compositionupdate = function (view)
|
|
|
3396
3422
|
endComposition(view, !state.selection.empty);
|
|
3397
3423
|
if (gecko && state.selection.empty && $pos.parentOffset && !$pos.textOffset && $pos.nodeBefore.marks.length) {
|
|
3398
3424
|
var sel = view.domSelectionRange();
|
|
3399
|
-
for (var node = sel.focusNode, offset = sel.focusOffset; node && node
|
|
3425
|
+
for (var node = sel.focusNode, offset = sel.focusOffset; node && isElt(node) && offset != 0;) {
|
|
3400
3426
|
var before = offset < 0 ? node.lastChild : node.childNodes[offset - 1];
|
|
3401
3427
|
if (!before) break;
|
|
3402
|
-
if (before
|
|
3428
|
+
if (isText(before)) {
|
|
3403
3429
|
var _sel = view.domSelection();
|
|
3404
3430
|
if (_sel) _sel.collapse(before, before.nodeValue.length);
|
|
3405
3431
|
break;
|
|
@@ -3418,9 +3444,9 @@ function selectionBeforeUneditable(view) {
|
|
|
3418
3444
|
var _view$domSelectionRan4 = view.domSelectionRange(),
|
|
3419
3445
|
focusNode = _view$domSelectionRan4.focusNode,
|
|
3420
3446
|
focusOffset = _view$domSelectionRan4.focusOffset;
|
|
3421
|
-
if (!focusNode || focusNode
|
|
3447
|
+
if (!focusNode || !isElt(focusNode) || focusOffset >= focusNode.childNodes.length) return false;
|
|
3422
3448
|
var next = focusNode.childNodes[focusOffset];
|
|
3423
|
-
return next
|
|
3449
|
+
return isElt(next) && next.contentEditable == "false";
|
|
3424
3450
|
}
|
|
3425
3451
|
editHandlers.compositionend = function (view, event) {
|
|
3426
3452
|
if (view.composing) {
|
|
@@ -3581,7 +3607,7 @@ handlers.dragstart = function (view, _event) {
|
|
|
3581
3607
|
var node;
|
|
3582
3608
|
if (pos && pos.pos >= sel.from && pos.pos <= (sel instanceof prosemirrorState.NodeSelection ? sel.to - 1 : sel.to)) ;else if (mouseDown && mouseDown.mightDrag) {
|
|
3583
3609
|
node = prosemirrorState.NodeSelection.create(view.state.doc, mouseDown.mightDrag.pos);
|
|
3584
|
-
} else if (event.target && event.target
|
|
3610
|
+
} else if (event.target && isElt(event.target)) {
|
|
3585
3611
|
var desc = view.docView.nearestDesc(event.target, true);
|
|
3586
3612
|
if (desc && desc.node.type.spec.draggable && desc != view.docView) node = prosemirrorState.NodeSelection.create(view.state.doc, desc.posBefore);
|
|
3587
3613
|
}
|
|
@@ -3705,6 +3731,27 @@ function compareObjs(a, b) {
|
|
|
3705
3731
|
for (var _p in b) if (!(_p in a)) return false;
|
|
3706
3732
|
return true;
|
|
3707
3733
|
}
|
|
3734
|
+
var FragmentCursor = function () {
|
|
3735
|
+
function FragmentCursor(frag) {
|
|
3736
|
+
_classCallCheck(this, FragmentCursor);
|
|
3737
|
+
this.frag = frag;
|
|
3738
|
+
this.index = 0;
|
|
3739
|
+
this.off = 0;
|
|
3740
|
+
}
|
|
3741
|
+
_createClass(FragmentCursor, [{
|
|
3742
|
+
key: "nodeAt",
|
|
3743
|
+
value: function nodeAt(off) {
|
|
3744
|
+
while (this.off <= off && this.index < this.frag.childCount) {
|
|
3745
|
+
var next = this.frag.child(this.index);
|
|
3746
|
+
if (this.off == off) return next;
|
|
3747
|
+
this.off += next.nodeSize;
|
|
3748
|
+
this.index++;
|
|
3749
|
+
}
|
|
3750
|
+
return null;
|
|
3751
|
+
}
|
|
3752
|
+
}]);
|
|
3753
|
+
return FragmentCursor;
|
|
3754
|
+
}();
|
|
3708
3755
|
var WidgetType = function () {
|
|
3709
3756
|
function WidgetType(toDOM, spec) {
|
|
3710
3757
|
_classCallCheck(this, WidgetType);
|
|
@@ -3789,12 +3836,9 @@ var NodeType = function () {
|
|
|
3789
3836
|
}
|
|
3790
3837
|
}, {
|
|
3791
3838
|
key: "valid",
|
|
3792
|
-
value: function valid(node, span) {
|
|
3793
|
-
var
|
|
3794
|
-
|
|
3795
|
-
offset = _node$content$findInd.offset,
|
|
3796
|
-
child;
|
|
3797
|
-
return offset == span.from && !(child = node.child(index)).isText && offset + child.nodeSize == span.to;
|
|
3839
|
+
value: function valid(node, span, cursor) {
|
|
3840
|
+
var found = cursor.nodeAt(span.from);
|
|
3841
|
+
return !!found && !found.isText && span.from + found.nodeSize == span.to;
|
|
3798
3842
|
}
|
|
3799
3843
|
}, {
|
|
3800
3844
|
key: "eq",
|
|
@@ -3902,9 +3946,12 @@ var DecorationSet = function () {
|
|
|
3902
3946
|
key: "mapInner",
|
|
3903
3947
|
value: function mapInner(mapping, node, offset, oldOffset, options) {
|
|
3904
3948
|
var newLocal;
|
|
3905
|
-
|
|
3906
|
-
var
|
|
3907
|
-
|
|
3949
|
+
if (this.local.length) {
|
|
3950
|
+
var cur = new FragmentCursor(node.content);
|
|
3951
|
+
for (var i = 0; i < this.local.length; i++) {
|
|
3952
|
+
var mapped = this.local[i].map(mapping, offset, oldOffset);
|
|
3953
|
+
if (mapped && mapped.type.valid(node, mapped, cur)) (newLocal || (newLocal = [])).push(mapped);else if (options.onRemove) options.onRemove(this.local[i].spec);
|
|
3954
|
+
}
|
|
3908
3955
|
}
|
|
3909
3956
|
if (this.children.length) return mapChildren(this.children, newLocal || [], mapping, node, offset, oldOffset, options);else return newLocal ? new DecorationSet(newLocal.sort(byPos), none) : empty;
|
|
3910
3957
|
}
|
|
@@ -3918,20 +3965,23 @@ var DecorationSet = function () {
|
|
|
3918
3965
|
}, {
|
|
3919
3966
|
key: "addInner",
|
|
3920
3967
|
value: function addInner(doc, decorations, offset) {
|
|
3921
|
-
var
|
|
3968
|
+
var _this12 = this;
|
|
3922
3969
|
var children,
|
|
3923
3970
|
childIndex = 0;
|
|
3924
3971
|
doc.forEach(function (childNode, childOffset) {
|
|
3925
3972
|
var baseOffset = childOffset + offset,
|
|
3926
3973
|
found;
|
|
3927
3974
|
if (!(found = takeSpansForNode(decorations, childNode, baseOffset))) return;
|
|
3928
|
-
if (!children) children =
|
|
3975
|
+
if (!children) children = _this12.children.slice();
|
|
3929
3976
|
while (childIndex < children.length && children[childIndex] < childOffset) childIndex += 3;
|
|
3930
3977
|
if (children[childIndex] == childOffset) children[childIndex + 2] = children[childIndex + 2].addInner(childNode, found, baseOffset + 1);else children.splice(childIndex, 0, childOffset, childOffset + childNode.nodeSize, buildTree(found, childNode, baseOffset + 1, noSpec));
|
|
3931
3978
|
childIndex += 3;
|
|
3932
3979
|
});
|
|
3933
3980
|
var local = moveSpans(childIndex ? withoutNulls(decorations) : decorations, -offset);
|
|
3934
|
-
|
|
3981
|
+
if (local.length) {
|
|
3982
|
+
var cur = new FragmentCursor(doc.content);
|
|
3983
|
+
for (var i = 0; i < local.length; i++) if (!local[i].type.valid(doc, local[i], cur)) local.splice(i--, 1);
|
|
3984
|
+
}
|
|
3935
3985
|
return new DecorationSet(local.length ? this.local.concat(local).sort(byPos) : this.local, children || this.children);
|
|
3936
3986
|
}
|
|
3937
3987
|
}, {
|
|
@@ -4157,9 +4207,9 @@ function mapChildren(oldChildren, newLocal, mapping, node, offset, oldOffset, op
|
|
|
4157
4207
|
}
|
|
4158
4208
|
var to = mapping.map(oldChildren[_i11 + 1] + oldOffset, -1),
|
|
4159
4209
|
toLocal = to - offset;
|
|
4160
|
-
var _node$content$
|
|
4161
|
-
index = _node$content$
|
|
4162
|
-
childOffset = _node$content$
|
|
4210
|
+
var _node$content$findInd = node.content.findIndex(fromLocal),
|
|
4211
|
+
index = _node$content$findInd.index,
|
|
4212
|
+
childOffset = _node$content$findInd.offset;
|
|
4163
4213
|
var childNode = node.maybeChild(index);
|
|
4164
4214
|
if (childNode && childOffset == fromLocal && childOffset + childNode.nodeSize == toLocal) {
|
|
4165
4215
|
var mapped = children[_i11 + 2].mapInner(mapping, childNode, from + 1, oldChildren[_i11] + oldOffset + 1, options);
|
|
@@ -4240,9 +4290,12 @@ function buildTree(spans, node, offset, options) {
|
|
|
4240
4290
|
}
|
|
4241
4291
|
});
|
|
4242
4292
|
var locals = moveSpans(hasNulls ? withoutNulls(spans) : spans, -offset).sort(byPos);
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
locals.
|
|
4293
|
+
if (locals.length) {
|
|
4294
|
+
var cur = new FragmentCursor(node.content);
|
|
4295
|
+
for (var i = 0; i < locals.length; i++) if (!locals[i].type.valid(node, locals[i], cur)) {
|
|
4296
|
+
if (options.onRemove) options.onRemove(locals[i].spec);
|
|
4297
|
+
locals.splice(i--, 1);
|
|
4298
|
+
}
|
|
4246
4299
|
}
|
|
4247
4300
|
return locals.length || children.length ? new DecorationSet(locals, children) : empty;
|
|
4248
4301
|
}
|
|
@@ -4327,7 +4380,7 @@ var SelectionState = function () {
|
|
|
4327
4380
|
}();
|
|
4328
4381
|
var DOMObserver = function () {
|
|
4329
4382
|
function DOMObserver(view, handleDOMChange) {
|
|
4330
|
-
var
|
|
4383
|
+
var _this13 = this;
|
|
4331
4384
|
_classCallCheck(this, DOMObserver);
|
|
4332
4385
|
this.view = view;
|
|
4333
4386
|
this.handleDOMChange = handleDOMChange;
|
|
@@ -4339,28 +4392,28 @@ var DOMObserver = function () {
|
|
|
4339
4392
|
this.suppressingSelectionUpdates = false;
|
|
4340
4393
|
this.lastChangedTextNode = null;
|
|
4341
4394
|
this.observer = window.MutationObserver && new window.MutationObserver(function (mutations) {
|
|
4342
|
-
for (var i = 0; i < mutations.length; i++)
|
|
4395
|
+
for (var i = 0; i < mutations.length; i++) _this13.queue.push(mutations[i]);
|
|
4343
4396
|
if (ie && ie_version <= 11 && mutations.some(function (m) {
|
|
4344
4397
|
return m.type == "childList" && m.removedNodes.length || m.type == "characterData" && m.oldValue.length > m.target.nodeValue.length;
|
|
4345
4398
|
})) {
|
|
4346
|
-
|
|
4399
|
+
_this13.flushSoon();
|
|
4347
4400
|
} else if (safari && view.composing && mutations.some(function (m) {
|
|
4348
4401
|
return m.type == "childList" && m.target.nodeName == "TR";
|
|
4349
4402
|
})) {
|
|
4350
4403
|
view.input.badSafariComposition = true;
|
|
4351
|
-
|
|
4404
|
+
_this13.flushSoon();
|
|
4352
4405
|
} else {
|
|
4353
|
-
|
|
4406
|
+
_this13.flush();
|
|
4354
4407
|
}
|
|
4355
4408
|
});
|
|
4356
4409
|
if (useCharData) {
|
|
4357
4410
|
this.onCharData = function (e) {
|
|
4358
|
-
|
|
4411
|
+
_this13.queue.push({
|
|
4359
4412
|
target: e.target,
|
|
4360
4413
|
type: "characterData",
|
|
4361
4414
|
oldValue: e.prevValue
|
|
4362
4415
|
});
|
|
4363
|
-
|
|
4416
|
+
_this13.flushSoon();
|
|
4364
4417
|
};
|
|
4365
4418
|
}
|
|
4366
4419
|
this.onSelectionChange = this.onSelectionChange.bind(this);
|
|
@@ -4368,10 +4421,10 @@ var DOMObserver = function () {
|
|
|
4368
4421
|
_createClass(DOMObserver, [{
|
|
4369
4422
|
key: "flushSoon",
|
|
4370
4423
|
value: function flushSoon() {
|
|
4371
|
-
var
|
|
4424
|
+
var _this14 = this;
|
|
4372
4425
|
if (this.flushingSoon < 0) this.flushingSoon = window.setTimeout(function () {
|
|
4373
|
-
|
|
4374
|
-
|
|
4426
|
+
_this14.flushingSoon = -1;
|
|
4427
|
+
_this14.flush();
|
|
4375
4428
|
}, 20);
|
|
4376
4429
|
}
|
|
4377
4430
|
}, {
|
|
@@ -4396,13 +4449,13 @@ var DOMObserver = function () {
|
|
|
4396
4449
|
}, {
|
|
4397
4450
|
key: "stop",
|
|
4398
4451
|
value: function stop() {
|
|
4399
|
-
var
|
|
4452
|
+
var _this15 = this;
|
|
4400
4453
|
if (this.observer) {
|
|
4401
4454
|
var take = this.observer.takeRecords();
|
|
4402
4455
|
if (take.length) {
|
|
4403
4456
|
for (var i = 0; i < take.length; i++) this.queue.push(take[i]);
|
|
4404
4457
|
window.setTimeout(function () {
|
|
4405
|
-
return
|
|
4458
|
+
return _this15.flush();
|
|
4406
4459
|
}, 20);
|
|
4407
4460
|
}
|
|
4408
4461
|
this.observer.disconnect();
|
|
@@ -4423,10 +4476,10 @@ var DOMObserver = function () {
|
|
|
4423
4476
|
}, {
|
|
4424
4477
|
key: "suppressSelectionUpdates",
|
|
4425
4478
|
value: function suppressSelectionUpdates() {
|
|
4426
|
-
var
|
|
4479
|
+
var _this16 = this;
|
|
4427
4480
|
this.suppressingSelectionUpdates = true;
|
|
4428
4481
|
setTimeout(function () {
|
|
4429
|
-
return
|
|
4482
|
+
return _this16.suppressingSelectionUpdates = false;
|
|
4430
4483
|
}, 50);
|
|
4431
4484
|
}
|
|
4432
4485
|
}, {
|
|
@@ -4459,7 +4512,7 @@ var DOMObserver = function () {
|
|
|
4459
4512
|
var desc = container && this.view.docView.nearestDesc(container);
|
|
4460
4513
|
if (desc && desc.ignoreMutation({
|
|
4461
4514
|
type: "selection",
|
|
4462
|
-
target: container
|
|
4515
|
+
target: isText(container) ? container.parentNode : container
|
|
4463
4516
|
})) {
|
|
4464
4517
|
this.setCurSelection();
|
|
4465
4518
|
return true;
|
|
@@ -4491,8 +4544,12 @@ var DOMObserver = function () {
|
|
|
4491
4544
|
if (!view.docView || this.flushingSoon > -1) return;
|
|
4492
4545
|
var mutations = this.pendingRecords();
|
|
4493
4546
|
if (mutations.length) this.queue = [];
|
|
4494
|
-
var
|
|
4495
|
-
|
|
4547
|
+
var selRange,
|
|
4548
|
+
newSel = false;
|
|
4549
|
+
if (!this.suppressingSelectionUpdates && hasFocusAndSelection(view)) {
|
|
4550
|
+
selRange = view.domSelectionRange();
|
|
4551
|
+
newSel = !this.currentSelection.eq(selRange) && !this.ignoreSelectionChange(selRange);
|
|
4552
|
+
}
|
|
4496
4553
|
var from = -1,
|
|
4497
4554
|
to = -1,
|
|
4498
4555
|
typeOver = false,
|
|
@@ -4519,7 +4576,7 @@ var DOMObserver = function () {
|
|
|
4519
4576
|
var node = _step3.value;
|
|
4520
4577
|
if (node.nodeName == "BR" && node.parentNode) {
|
|
4521
4578
|
var after = node.nextSibling;
|
|
4522
|
-
while (after && after
|
|
4579
|
+
while (after && isElt(after)) {
|
|
4523
4580
|
if (after.contentEditable == "false") {
|
|
4524
4581
|
node.parentNode.removeChild(node);
|
|
4525
4582
|
break;
|
|
@@ -4560,10 +4617,10 @@ var DOMObserver = function () {
|
|
|
4560
4617
|
}
|
|
4561
4618
|
}
|
|
4562
4619
|
var readSel = null;
|
|
4563
|
-
if (from < 0 && newSel && view.input.lastFocus > Date.now() - 200 && Math.max(view.input.lastTouch, view.input.lastClick.time) < Date.now() - 300 && selectionCollapsed(
|
|
4620
|
+
if (from < 0 && newSel && view.input.lastFocus > Date.now() - 200 && Math.max(view.input.lastTouch, view.input.lastClick.time) < Date.now() - 300 && selectionCollapsed(selRange) && (readSel = selectionFromDOM(view)) && readSel.eq(prosemirrorState.Selection.near(view.state.doc.resolve(0), 1))) {
|
|
4564
4621
|
view.input.lastFocus = 0;
|
|
4565
4622
|
selectionToDOM(view);
|
|
4566
|
-
this.currentSelection.set(
|
|
4623
|
+
this.currentSelection.set(selRange);
|
|
4567
4624
|
view.scrollToSelection();
|
|
4568
4625
|
} else if (from > -1 || newSel) {
|
|
4569
4626
|
if (from > -1) {
|
|
@@ -4575,8 +4632,8 @@ var DOMObserver = function () {
|
|
|
4575
4632
|
fixUpBadSafariComposition(view, added);
|
|
4576
4633
|
}
|
|
4577
4634
|
this.handleDOMChange(from, to, typeOver, added);
|
|
4578
|
-
if (view.docView && view.docView.dirty) view.updateState(view.state);else if (!this.currentSelection.eq(
|
|
4579
|
-
this.currentSelection.set(
|
|
4635
|
+
if (view.docView && view.docView.dirty) view.updateState(view.state);else if (selRange && !this.currentSelection.eq(selRange)) selectionToDOM(view);
|
|
4636
|
+
if (selRange) this.currentSelection.set(selRange);
|
|
4580
4637
|
}
|
|
4581
4638
|
}
|
|
4582
4639
|
}, {
|
|
@@ -4590,7 +4647,7 @@ var DOMObserver = function () {
|
|
|
4590
4647
|
for (var i = 0; i < mut.addedNodes.length; i++) {
|
|
4591
4648
|
var node = mut.addedNodes[i];
|
|
4592
4649
|
added.push(node);
|
|
4593
|
-
if (node
|
|
4650
|
+
if (isText(node)) this.lastChangedTextNode = node;
|
|
4594
4651
|
}
|
|
4595
4652
|
if (desc.contentDOM && desc.contentDOM != desc.dom && !desc.contentDOM.contains(mut.target)) return {
|
|
4596
4653
|
from: desc.posBefore,
|
|
@@ -4704,7 +4761,7 @@ function fixUpBadSafariComposition(view, addedNodes) {
|
|
|
4704
4761
|
var parent = nextCell;
|
|
4705
4762
|
for (;;) {
|
|
4706
4763
|
var first = parent.firstChild;
|
|
4707
|
-
if (!first || first
|
|
4764
|
+
if (!first || !isElt(first) || first.contentEditable == "false" || /^(BR|IMG)$/.test(first.nodeName)) break;
|
|
4708
4765
|
parent = first;
|
|
4709
4766
|
}
|
|
4710
4767
|
parent.insertBefore(node, parent.firstChild);
|
|
@@ -4730,7 +4787,7 @@ function parseBetween(view, from_, to_, addedNodes) {
|
|
|
4730
4787
|
var domSel = view.domSelectionRange();
|
|
4731
4788
|
var find;
|
|
4732
4789
|
var anchor = domSel.anchorNode;
|
|
4733
|
-
if (anchor && view.dom
|
|
4790
|
+
if (anchor && contains(view.dom, anchor)) {
|
|
4734
4791
|
find = [{
|
|
4735
4792
|
node: anchor,
|
|
4736
4793
|
offset: domSel.anchorOffset
|
|
@@ -4845,7 +4902,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
|
|
|
4845
4902
|
var change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide);
|
|
4846
4903
|
if (change) view.input.domChangeCount++;
|
|
4847
4904
|
if ((ios && view.input.lastIOSEnter > Date.now() - 225 || android) && addedNodes.some(function (n) {
|
|
4848
|
-
return n
|
|
4905
|
+
return isElt(n) && !isInline.test(n.nodeName);
|
|
4849
4906
|
}) && (!change || change.endA >= change.endB) && view.someProp("handleKeyDown", function (f) {
|
|
4850
4907
|
return f(view, keyEvent(13, "Enter"));
|
|
4851
4908
|
})) {
|
|
@@ -4896,7 +4953,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
|
|
|
4896
4953
|
view.input.lastIOSEnter = 0;
|
|
4897
4954
|
return;
|
|
4898
4955
|
}
|
|
4899
|
-
if (view.state.selection.anchor > change.start &&
|
|
4956
|
+
if (view.state.selection.anchor > change.start && (inlineChange ? change.endA > change.start && change.endB == change.start : looksLikeBlockJoin(doc, change.start, change.endA, $from, $to)) && view.someProp("handleKeyDown", function (f) {
|
|
4900
4957
|
return f(view, keyEvent(8, "Backspace"));
|
|
4901
4958
|
})) {
|
|
4902
4959
|
if (android && chrome) view.domObserver.suppressSelectionUpdates();
|
|
@@ -4991,10 +5048,10 @@ function isMarkChange(cur, prev) {
|
|
|
4991
5048
|
type: type
|
|
4992
5049
|
};
|
|
4993
5050
|
}
|
|
4994
|
-
function
|
|
5051
|
+
function looksLikeBlockJoin(old, start, end, $newStart, $newEnd) {
|
|
4995
5052
|
if (end - start <= $newEnd.pos - $newStart.pos || skipClosingAndOpening($newStart, true, false) < $newEnd.pos) return false;
|
|
4996
5053
|
var $start = old.resolve(start);
|
|
4997
|
-
if (!$newStart.parent.
|
|
5054
|
+
if (!$newStart.parent.inlineContent) {
|
|
4998
5055
|
var after = $start.nodeAfter;
|
|
4999
5056
|
return after != null && end == start + after.nodeSize;
|
|
5000
5057
|
}
|
|
@@ -5061,7 +5118,7 @@ var __parseFromClipboard = parseFromClipboard;
|
|
|
5061
5118
|
var __endComposition = endComposition;
|
|
5062
5119
|
var EditorView = function () {
|
|
5063
5120
|
function EditorView(place, props) {
|
|
5064
|
-
var
|
|
5121
|
+
var _this17 = this;
|
|
5065
5122
|
_classCallCheck(this, EditorView);
|
|
5066
5123
|
this._root = null;
|
|
5067
5124
|
this.focused = false;
|
|
@@ -5089,7 +5146,7 @@ var EditorView = function () {
|
|
|
5089
5146
|
this.nodeViews = buildNodeViews(this);
|
|
5090
5147
|
this.docView = docViewDesc(this.state.doc, computeDocDeco(this), viewDecorations(this), this.dom, this);
|
|
5091
5148
|
this.domObserver = new DOMObserver(this, function (from, to, typeOver, added) {
|
|
5092
|
-
return readDOMChange(
|
|
5149
|
+
return readDOMChange(_this17, from, to, typeOver, added);
|
|
5093
5150
|
});
|
|
5094
5151
|
this.domObserver.start();
|
|
5095
5152
|
initInput(this);
|
|
@@ -5203,13 +5260,13 @@ var EditorView = function () {
|
|
|
5203
5260
|
}, {
|
|
5204
5261
|
key: "scrollToSelection",
|
|
5205
5262
|
value: function scrollToSelection() {
|
|
5206
|
-
var
|
|
5263
|
+
var _this18 = this;
|
|
5207
5264
|
var startDOM = this.domSelectionRange().focusNode;
|
|
5208
|
-
if (!startDOM || !this.dom
|
|
5209
|
-
return f(
|
|
5265
|
+
if (!startDOM || !contains(this.dom, startDOM)) ;else if (this.someProp("handleScrollToSelection", function (f) {
|
|
5266
|
+
return f(_this18);
|
|
5210
5267
|
})) ;else if (this.state.selection instanceof prosemirrorState.NodeSelection) {
|
|
5211
5268
|
var target = this.docView.domAfterPos(this.state.selection.from);
|
|
5212
|
-
if (target
|
|
5269
|
+
if (isElt(target)) scrollRectIntoView(this, target.getBoundingClientRect(), startDOM);
|
|
5213
5270
|
} else {
|
|
5214
5271
|
scrollRectIntoView(this, this.coordsAtPos(this.state.selection.head, 1), startDOM);
|
|
5215
5272
|
}
|
|
@@ -5297,7 +5354,7 @@ var EditorView = function () {
|
|
|
5297
5354
|
}, {
|
|
5298
5355
|
key: "root",
|
|
5299
5356
|
get: function get() {
|
|
5300
|
-
var
|
|
5357
|
+
var _this19 = this;
|
|
5301
5358
|
var cached = this._root;
|
|
5302
5359
|
if (cached == null) {
|
|
5303
5360
|
var _loop5 = function _loop5(search) {
|
|
@@ -5306,7 +5363,7 @@ var EditorView = function () {
|
|
|
5306
5363
|
return search.ownerDocument.getSelection();
|
|
5307
5364
|
};
|
|
5308
5365
|
return {
|
|
5309
|
-
v:
|
|
5366
|
+
v: _this19._root = search
|
|
5310
5367
|
};
|
|
5311
5368
|
}
|
|
5312
5369
|
},
|
|
@@ -5403,7 +5460,7 @@ var EditorView = function () {
|
|
|
5403
5460
|
}, {
|
|
5404
5461
|
key: "domSelectionRange",
|
|
5405
5462
|
value: function domSelectionRange() {
|
|
5406
|
-
var sel = this.domSelection();
|
|
5463
|
+
var sel = this.dom.isConnected !== false && this.domSelection();
|
|
5407
5464
|
if (!sel) return {
|
|
5408
5465
|
focusNode: null,
|
|
5409
5466
|
focusOffset: 0,
|