@burger-editor/client 4.0.0-alpha.78 → 4.0.0-alpha.79
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/dist/client.js +1696 -1228
- package/dist/client.js.map +1 -1
- package/dist/{editable-area-view-CAeVDyOh.js → editable-area-view-DhEipEQV.js} +23 -23
- package/dist/editable-area-view-DhEipEQV.js.map +1 -0
- package/dist/ui.js +19 -19
- package/dist/ui.js.map +1 -1
- package/package.json +11 -11
- package/dist/editable-area-view-CAeVDyOh.js.map +0 -1
package/dist/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as BurgerEditorEngine } from "./dist-DYydjVsL.js";
|
|
2
|
-
import { _ as BlockCatalog, c as RootErrorBoundary, d as DraftSwitcher, f as registerEngineCommands, g as BlockOptions, h as EditorDialog, m as ItemEditorHost, p as useUIState, t as EditableAreaView, u as reactMount } from "./editable-area-view-
|
|
2
|
+
import { _ as BlockCatalog, c as RootErrorBoundary, d as DraftSwitcher, f as registerEngineCommands, g as BlockOptions, h as EditorDialog, m as ItemEditorHost, p as useUIState, t as EditableAreaView, u as reactMount } from "./editable-area-view-DhEipEQV.js";
|
|
3
3
|
import { n as useEngine, t as EngineProvider } from "./engine-context-oEEsvNSx.js";
|
|
4
4
|
import { c } from "react/compiler-runtime";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -3505,9 +3505,10 @@ var Mapping = class Mapping {
|
|
|
3505
3505
|
mirroring information).
|
|
3506
3506
|
*/
|
|
3507
3507
|
appendMapping(mapping) {
|
|
3508
|
-
for (let i =
|
|
3508
|
+
for (let i = mapping.from, startSize = this._maps.length; i < mapping.to; i++) {
|
|
3509
3509
|
let mirr = mapping.getMirror(i);
|
|
3510
|
-
|
|
3510
|
+
if (mirr != null) mirr = mirr < i && mirr >= mapping.from ? startSize + (mirr - mapping.from) : void 0;
|
|
3511
|
+
this.appendMap(mapping._maps[i], mirr);
|
|
3511
3512
|
}
|
|
3512
3513
|
}
|
|
3513
3514
|
/**
|
|
@@ -3531,9 +3532,10 @@ var Mapping = class Mapping {
|
|
|
3531
3532
|
Append the inverse of the given mapping to this one.
|
|
3532
3533
|
*/
|
|
3533
3534
|
appendMappingInverted(mapping) {
|
|
3534
|
-
for (let i = mapping.
|
|
3535
|
+
for (let i = mapping.to - 1, totalSize = this._maps.length + mapping._maps.length; i >= mapping.from; i--) {
|
|
3535
3536
|
let mirr = mapping.getMirror(i);
|
|
3536
|
-
|
|
3537
|
+
if (mirr != null) mirr = mirr > i && mirr < mapping.to ? totalSize - (mirr - mapping.from) - 1 : void 0;
|
|
3538
|
+
this.appendMap(mapping._maps[i].invert(), mirr);
|
|
3537
3539
|
}
|
|
3538
3540
|
}
|
|
3539
3541
|
/**
|
|
@@ -4451,14 +4453,20 @@ function dropPoint(doc, pos, slice) {
|
|
|
4451
4453
|
for (let i = 0; i < slice.openStart; i++) content = content.firstChild.content;
|
|
4452
4454
|
for (let pass = 1; pass <= (slice.openStart == 0 && slice.size ? 2 : 1); pass++) for (let d = $pos.depth; d >= 0; d--) {
|
|
4453
4455
|
let bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1;
|
|
4454
|
-
let
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4456
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
4457
|
+
if (attempt) {
|
|
4458
|
+
if (!bias) break;
|
|
4459
|
+
bias = -bias;
|
|
4460
|
+
}
|
|
4461
|
+
let insertPos = $pos.index(d) + (bias > 0 ? 1 : 0);
|
|
4462
|
+
let parent = $pos.node(d), fits = false;
|
|
4463
|
+
if (pass == 1) fits = parent.canReplace(insertPos, insertPos, content);
|
|
4464
|
+
else {
|
|
4465
|
+
let wrapping = parent.contentMatchAt(insertPos).findWrapping(content.firstChild.type);
|
|
4466
|
+
fits = wrapping && parent.canReplaceWith(insertPos, insertPos, wrapping[0]);
|
|
4467
|
+
}
|
|
4468
|
+
if (fits) return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1);
|
|
4460
4469
|
}
|
|
4461
|
-
if (fits) return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1);
|
|
4462
4470
|
}
|
|
4463
4471
|
return null;
|
|
4464
4472
|
}
|
|
@@ -6829,23 +6837,23 @@ var domIndex = function(node) {
|
|
|
6829
6837
|
if (!node) return index;
|
|
6830
6838
|
}
|
|
6831
6839
|
};
|
|
6832
|
-
|
|
6840
|
+
function parentNode(node) {
|
|
6833
6841
|
let parent = node.assignedSlot || node.parentNode;
|
|
6834
6842
|
return parent && parent.nodeType == 11 ? parent.host : parent;
|
|
6835
|
-
}
|
|
6843
|
+
}
|
|
6836
6844
|
var reusedRange = null;
|
|
6837
|
-
|
|
6845
|
+
function textRange(node, from, to) {
|
|
6838
6846
|
let range = reusedRange || (reusedRange = document.createRange());
|
|
6839
6847
|
range.setEnd(node, to == null ? node.nodeValue.length : to);
|
|
6840
6848
|
range.setStart(node, from || 0);
|
|
6841
6849
|
return range;
|
|
6842
|
-
}
|
|
6843
|
-
|
|
6850
|
+
}
|
|
6851
|
+
function clearReusedRange() {
|
|
6844
6852
|
reusedRange = null;
|
|
6845
|
-
}
|
|
6846
|
-
|
|
6853
|
+
}
|
|
6854
|
+
function isEquivalentPosition(node, off, targetNode, targetOff) {
|
|
6847
6855
|
return targetNode && (scanFor(node, off, targetNode, targetOff, -1) || scanFor(node, off, targetNode, targetOff, 1));
|
|
6848
|
-
}
|
|
6856
|
+
}
|
|
6849
6857
|
var atomElements = /^(img|br|input|textarea|hr)$/i;
|
|
6850
6858
|
function scanFor(node, off, targetNode, targetOff, dir) {
|
|
6851
6859
|
var _a;
|
|
@@ -6853,7 +6861,7 @@ function scanFor(node, off, targetNode, targetOff, dir) {
|
|
|
6853
6861
|
if (node == targetNode && off == targetOff) return true;
|
|
6854
6862
|
if (off == (dir < 0 ? 0 : nodeSize(node))) {
|
|
6855
6863
|
let parent = node.parentNode;
|
|
6856
|
-
if (!parent || !isElt(parent) ||
|
|
6864
|
+
if (!parent || !isElt(parent) || hasNodeDesc(node) || atomElements.test(node.nodeName) || node.contentEditable == "false") return false;
|
|
6857
6865
|
off = domIndex(node) + (dir < 0 ? 0 : 1);
|
|
6858
6866
|
node = parent;
|
|
6859
6867
|
} else if (isElt(node)) {
|
|
@@ -6861,7 +6869,8 @@ function scanFor(node, off, targetNode, targetOff, dir) {
|
|
|
6861
6869
|
if (isElt(child) && child.contentEditable == "false") {
|
|
6862
6870
|
if ((_a = child.pmViewDesc) === null || _a === void 0 ? void 0 : _a.ignoreForSelection) off += dir;
|
|
6863
6871
|
else return false;
|
|
6864
|
-
} else
|
|
6872
|
+
} else if (hasNodeDesc(child) || atomElements.test(child.nodeName)) return false;
|
|
6873
|
+
else {
|
|
6865
6874
|
node = child;
|
|
6866
6875
|
off = dir < 0 ? nodeSize(node) : 0;
|
|
6867
6876
|
}
|
|
@@ -6880,27 +6889,27 @@ function isText(node) {
|
|
|
6880
6889
|
function contains(parent, child) {
|
|
6881
6890
|
return child ? parent.contains(isElt(child) ? child : child.parentNode) : false;
|
|
6882
6891
|
}
|
|
6883
|
-
function textNodeBefore
|
|
6892
|
+
function textNodeBefore(node, offset) {
|
|
6884
6893
|
for (;;) {
|
|
6885
6894
|
if (isText(node) && offset) return node;
|
|
6886
6895
|
if (isElt(node) && offset > 0) {
|
|
6887
6896
|
if (node.contentEditable == "false") return null;
|
|
6888
6897
|
node = node.childNodes[offset - 1];
|
|
6889
6898
|
offset = nodeSize(node);
|
|
6890
|
-
} else if (node.parentNode && !
|
|
6899
|
+
} else if (node.parentNode && !hasNodeDesc(node, true)) {
|
|
6891
6900
|
offset = domIndex(node);
|
|
6892
6901
|
node = node.parentNode;
|
|
6893
6902
|
} else return null;
|
|
6894
6903
|
}
|
|
6895
6904
|
}
|
|
6896
|
-
function textNodeAfter
|
|
6905
|
+
function textNodeAfter(node, offset) {
|
|
6897
6906
|
for (;;) {
|
|
6898
6907
|
if (isText(node) && offset < node.nodeValue.length) return node;
|
|
6899
6908
|
if (isElt(node) && offset < node.childNodes.length) {
|
|
6900
6909
|
if (node.contentEditable == "false") return null;
|
|
6901
6910
|
node = node.childNodes[offset];
|
|
6902
6911
|
offset = 0;
|
|
6903
|
-
} else if (node.parentNode && !
|
|
6912
|
+
} else if (node.parentNode && !hasNodeDesc(node, true)) {
|
|
6904
6913
|
offset = domIndex(node) + 1;
|
|
6905
6914
|
node = node.parentNode;
|
|
6906
6915
|
} else return null;
|
|
@@ -6916,14 +6925,18 @@ function isOnEdge(node, offset, parent) {
|
|
|
6916
6925
|
atEnd = atEnd && index == nodeSize(node);
|
|
6917
6926
|
}
|
|
6918
6927
|
}
|
|
6919
|
-
function
|
|
6928
|
+
function hasNodeDesc(dom, isBlock = false) {
|
|
6920
6929
|
let desc;
|
|
6921
6930
|
for (let cur = dom; cur; cur = cur.parentNode) if (desc = cur.pmViewDesc) break;
|
|
6922
|
-
return desc && desc.node && desc.node.isBlock && (desc.dom == dom || desc.contentDOM == dom);
|
|
6931
|
+
return desc && desc.node && (!isBlock || desc.node.isBlock) && (desc.dom == dom || desc.contentDOM == dom);
|
|
6923
6932
|
}
|
|
6924
|
-
|
|
6933
|
+
function selectionCollapsed(domSel) {
|
|
6925
6934
|
return domSel.focusNode && isEquivalentPosition(domSel.focusNode, domSel.focusOffset, domSel.anchorNode, domSel.anchorOffset);
|
|
6926
|
-
}
|
|
6935
|
+
}
|
|
6936
|
+
function writeSelection(sel, range) {
|
|
6937
|
+
sel.collapse(range.anchorNode, range.anchorOffset);
|
|
6938
|
+
if (range.focusNode != range.anchorNode || range.focusOffset != range.anchorOffset) sel.extend(range.focusNode, range.focusOffset);
|
|
6939
|
+
}
|
|
6927
6940
|
function keyEvent(keyCode, key) {
|
|
6928
6941
|
let event = document.createEvent("Event");
|
|
6929
6942
|
event.initEvent("keydown", true, true);
|
|
@@ -6955,17 +6968,12 @@ function caretFromPoint(doc, x, y) {
|
|
|
6955
6968
|
var nav = typeof navigator != "undefined" ? navigator : null;
|
|
6956
6969
|
var doc = typeof document != "undefined" ? document : null;
|
|
6957
6970
|
var agent = nav && nav.userAgent || "";
|
|
6958
|
-
var
|
|
6959
|
-
var ie_upto10 = /MSIE \d/.exec(agent);
|
|
6960
|
-
var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(agent);
|
|
6961
|
-
var ie$1 = !!(ie_upto10 || ie_11up || ie_edge);
|
|
6962
|
-
var ie_version = ie_upto10 ? document.documentMode : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0;
|
|
6963
|
-
var gecko = !ie$1 && /gecko\/(\d+)/i.test(agent);
|
|
6971
|
+
var gecko = /gecko\/(\d+)/i.test(agent) && !/edge?\//i.test(agent);
|
|
6964
6972
|
gecko && +(/Firefox\/(\d+)/.exec(agent) || [0, 0])[1];
|
|
6965
|
-
var _chrome =
|
|
6973
|
+
var _chrome = /Chrome\/(\d+)/.exec(agent);
|
|
6966
6974
|
var chrome = !!_chrome;
|
|
6967
6975
|
var chrome_version = _chrome ? +_chrome[1] : 0;
|
|
6968
|
-
var safari =
|
|
6976
|
+
var safari = !!nav && /Apple Computer/.test(nav.vendor);
|
|
6969
6977
|
var ios = safari && (/Mobile\/\w+/.test(agent) || !!nav && nav.maxTouchPoints > 2);
|
|
6970
6978
|
var mac$2 = ios || (nav ? /Mac/.test(nav.platform) : false);
|
|
6971
6979
|
var windows$1 = nav ? /Win/.test(nav.platform) : false;
|
|
@@ -7001,6 +7009,21 @@ function clientRect(node) {
|
|
|
7001
7009
|
bottom: rect.top + node.clientHeight * scaleY
|
|
7002
7010
|
};
|
|
7003
7011
|
}
|
|
7012
|
+
function rectNextTo(node, offset, dir) {
|
|
7013
|
+
for (;;) if (dir < 0 ? offset : offset < nodeSize(node)) {
|
|
7014
|
+
if (isText(node)) return singleRect(textRange(node, offset + (dir < 0 ? -1 : 0), offset + (dir > 0 ? 1 : 0)), -dir);
|
|
7015
|
+
let next = node.childNodes[dir < 0 ? offset - 1 : offset];
|
|
7016
|
+
if (isText(next)) {
|
|
7017
|
+
node = next;
|
|
7018
|
+
offset = dir < 0 ? next.nodeValue.length : 0;
|
|
7019
|
+
} else if (isElt(next)) return singleRect(next, -dir);
|
|
7020
|
+
else return null;
|
|
7021
|
+
} else if (hasNodeDesc(node, true) || !node.parentNode) return null;
|
|
7022
|
+
else {
|
|
7023
|
+
offset = domIndex(node) + (dir < 0 ? 0 : 1);
|
|
7024
|
+
node = node.parentNode;
|
|
7025
|
+
}
|
|
7026
|
+
}
|
|
7004
7027
|
function scrollRectIntoView(view, rect, startDOM) {
|
|
7005
7028
|
if (!nonZero(rect) && rect.left == 0) return;
|
|
7006
7029
|
let scrollThreshold = view.someProp("scrollThreshold") || 0, scrollMargin = view.someProp("scrollMargin") || 5;
|
|
@@ -7178,25 +7201,46 @@ function posFromElement(view, elt, coords) {
|
|
|
7178
7201
|
let rect = node.getBoundingClientRect();
|
|
7179
7202
|
bias = rect.left != rect.right && coords.left > (rect.left + rect.right) / 2 ? 1 : -1;
|
|
7180
7203
|
}
|
|
7181
|
-
return
|
|
7204
|
+
return {
|
|
7205
|
+
pos: view.docView.posFromDOM(node, offset, bias),
|
|
7206
|
+
affinity: affinityFromCoords(node, offset, coords)
|
|
7207
|
+
};
|
|
7208
|
+
}
|
|
7209
|
+
function horizDist(x, rect) {
|
|
7210
|
+
return x < rect.left ? rect.left - x : x > rect.right ? x - rect.right : 0;
|
|
7211
|
+
}
|
|
7212
|
+
function affinityFromCoords(node, offset, coords) {
|
|
7213
|
+
let before = rectNextTo(node, offset, -1), after = rectNextTo(node, offset, 1);
|
|
7214
|
+
if (!before) return 1;
|
|
7215
|
+
if (!after) return -1;
|
|
7216
|
+
if (before.bottom <= after.top) return coords.top > (before.bottom + after.top) / 2 ? 1 : -1;
|
|
7217
|
+
return horizDist(coords.left, before) < horizDist(coords.left, after) ? -1 : 1;
|
|
7182
7218
|
}
|
|
7183
7219
|
function posFromCaret(view, node, offset, coords) {
|
|
7184
7220
|
let outsideBlock = -1;
|
|
7185
|
-
for (let cur = node
|
|
7186
|
-
if (cur == view.dom) break;
|
|
7221
|
+
for (let cur = node; cur != view.dom;) {
|
|
7187
7222
|
let desc = view.docView.nearestDesc(cur, true), rect;
|
|
7188
7223
|
if (!desc) return null;
|
|
7189
|
-
if (isElt(desc.dom) && (
|
|
7190
|
-
if (desc.node.
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7224
|
+
if (isElt(desc.dom) && ((rect = desc.dom.getBoundingClientRect()).width || rect.height)) {
|
|
7225
|
+
if (!desc.contentDOM && !desc.node.isText && coords.left >= rect.left && coords.left <= rect.right && coords.top >= rect.top && coords.top <= rect.bottom) {
|
|
7226
|
+
let before = desc.node.isBlock ? coords.top < (rect.top + rect.bottom) / 2 : coords.left < (rect.left + rect.right) / 2;
|
|
7227
|
+
return {
|
|
7228
|
+
pos: before ? desc.posBefore : desc.posAfter,
|
|
7229
|
+
affinity: before ? 1 : -1
|
|
7230
|
+
};
|
|
7194
7231
|
}
|
|
7195
|
-
if (
|
|
7232
|
+
if (desc.node.isBlock && desc.parent && !/^T(R|BODY|HEAD|FOOT)$/.test(desc.dom.nodeName) && (coords.top < rect.top || coords.top > rect.bottom)) outsideBlock = coords.top < rect.top ? desc.posBefore : desc.posAfter;
|
|
7196
7233
|
}
|
|
7197
7234
|
cur = desc.dom.parentNode;
|
|
7198
7235
|
}
|
|
7199
|
-
|
|
7236
|
+
if (outsideBlock > -1) return {
|
|
7237
|
+
pos: outsideBlock,
|
|
7238
|
+
affinity: 0
|
|
7239
|
+
};
|
|
7240
|
+
return {
|
|
7241
|
+
pos: view.docView.posFromDOM(node, offset, -1),
|
|
7242
|
+
affinity: affinityFromCoords(node, offset, coords)
|
|
7243
|
+
};
|
|
7200
7244
|
}
|
|
7201
7245
|
function elementFromPoint(element, coords, box) {
|
|
7202
7246
|
let len = element.childNodes.length;
|
|
@@ -7218,7 +7262,7 @@ function posAtCoords(view, coords) {
|
|
|
7218
7262
|
let caret = caretFromPoint(doc, coords.left, coords.top);
|
|
7219
7263
|
if (caret) ({node, offset} = caret);
|
|
7220
7264
|
let elt = (view.root.elementFromPoint ? view.root : doc).elementFromPoint(coords.left, coords.top);
|
|
7221
|
-
let pos;
|
|
7265
|
+
let pos, affinity = 0;
|
|
7222
7266
|
if (!elt || !view.dom.contains(elt)) {
|
|
7223
7267
|
let box = view.dom.getBoundingClientRect();
|
|
7224
7268
|
if (!inRect(coords, box)) return null;
|
|
@@ -7240,13 +7284,17 @@ function posAtCoords(view, coords) {
|
|
|
7240
7284
|
let prev;
|
|
7241
7285
|
if (webkit && offset && isElt(node) && isElt(prev = node.childNodes[offset - 1]) && prev.contentEditable == "false" && prev.getBoundingClientRect().top >= coords.top) offset--;
|
|
7242
7286
|
if (node == view.dom && offset == node.childNodes.length - 1 && isElt(node.lastChild) && coords.top > node.lastChild.getBoundingClientRect().bottom) pos = view.state.doc.content.size;
|
|
7243
|
-
else if (offset == 0 || !isElt(node) || node.childNodes[offset - 1].nodeName != "BR")
|
|
7287
|
+
else if (offset == 0 || !isElt(node) || node.childNodes[offset - 1].nodeName != "BR") {
|
|
7288
|
+
let found = posFromCaret(view, node, offset, coords);
|
|
7289
|
+
if (found) ({pos, affinity} = found);
|
|
7290
|
+
}
|
|
7244
7291
|
}
|
|
7245
|
-
if (pos == null) pos = posFromElement(view, elt, coords);
|
|
7292
|
+
if (pos == null) ({pos, affinity} = posFromElement(view, elt, coords));
|
|
7246
7293
|
let desc = view.docView.nearestDesc(elt, true);
|
|
7247
7294
|
return {
|
|
7248
7295
|
pos,
|
|
7249
|
-
inside: desc ? desc.posAtStart - desc.border : -1
|
|
7296
|
+
inside: desc ? desc.posAtStart - desc.border : -1,
|
|
7297
|
+
affinity
|
|
7250
7298
|
};
|
|
7251
7299
|
}
|
|
7252
7300
|
function nonZero(rect) {
|
|
@@ -7380,16 +7428,13 @@ function endOfTextblockHorizontal(view, state, dir) {
|
|
|
7380
7428
|
if (!sel) return $head.pos == $head.start() || $head.pos == $head.end();
|
|
7381
7429
|
if (!maybeRTL.test($head.parent.textContent) || !sel.modify) return dir == "left" || dir == "backward" ? atStart : atEnd;
|
|
7382
7430
|
return withFlushedState(view, state, () => {
|
|
7383
|
-
let
|
|
7431
|
+
let range = view.domSel.readRange();
|
|
7384
7432
|
let oldBidiLevel = sel.caretBidiLevel;
|
|
7385
7433
|
sel.modify("move", dir, "character");
|
|
7386
7434
|
let parentDOM = $head.depth ? view.docView.domAfterPos($head.before()) : view.dom;
|
|
7387
|
-
let { focusNode: newNode, focusOffset: newOff } = view.
|
|
7388
|
-
let result = newNode && !contains(parentDOM, newNode) ||
|
|
7389
|
-
|
|
7390
|
-
sel.collapse(anchorNode, anchorOffset);
|
|
7391
|
-
if (oldNode && (oldNode != anchorNode || oldOff != anchorOffset) && sel.extend) sel.extend(oldNode, oldOff);
|
|
7392
|
-
} catch (_) {}
|
|
7435
|
+
let { focusNode: newNode, focusOffset: newOff } = view.domSel.readRange();
|
|
7436
|
+
let result = newNode && !contains(parentDOM, newNode) || range.focusNode == newNode && range.focusOffset == newOff;
|
|
7437
|
+
writeSelection(sel, range);
|
|
7393
7438
|
if (oldBidiLevel != null) sel.caretBidiLevel = oldBidiLevel;
|
|
7394
7439
|
return result;
|
|
7395
7440
|
});
|
|
@@ -7403,17 +7448,13 @@ function endOfTextblock(view, state, dir) {
|
|
|
7403
7448
|
cachedDir = dir;
|
|
7404
7449
|
return cachedResult = dir == "up" || dir == "down" ? endOfTextblockVertical(view, state, dir) : endOfTextblockHorizontal(view, state, dir);
|
|
7405
7450
|
}
|
|
7406
|
-
var NOT_DIRTY = 0;
|
|
7407
|
-
var CHILD_DIRTY = 1;
|
|
7408
|
-
var CONTENT_DIRTY = 2;
|
|
7409
|
-
var NODE_DIRTY = 3;
|
|
7410
7451
|
var ViewDesc = class {
|
|
7411
7452
|
constructor(parent, children, dom, contentDOM) {
|
|
7412
7453
|
this.parent = parent;
|
|
7413
7454
|
this.children = children;
|
|
7414
7455
|
this.dom = dom;
|
|
7415
7456
|
this.contentDOM = contentDOM;
|
|
7416
|
-
this.
|
|
7457
|
+
this.damage = 0;
|
|
7417
7458
|
dom.pmViewDesc = this;
|
|
7418
7459
|
}
|
|
7419
7460
|
matchesWidget(widget) {
|
|
@@ -7651,91 +7692,24 @@ var ViewDesc = class {
|
|
|
7651
7692
|
if (!isElt(node) || offset == node.childNodes.length) throw new RangeError("No node after pos " + pos);
|
|
7652
7693
|
return node.childNodes[offset];
|
|
7653
7694
|
}
|
|
7654
|
-
setSelection(anchor, head, view, force = false) {
|
|
7655
|
-
let from = Math.min(anchor, head), to = Math.max(anchor, head);
|
|
7656
|
-
for (let i = 0, offset = 0; i < this.children.length; i++) {
|
|
7657
|
-
let child = this.children[i], end = offset + child.size;
|
|
7658
|
-
if (from > offset && to < end) return child.setSelection(anchor - offset - child.border, head - offset - child.border, view, force);
|
|
7659
|
-
offset = end;
|
|
7660
|
-
}
|
|
7661
|
-
let anchorDOM = this.domFromPos(anchor, anchor ? -1 : 1);
|
|
7662
|
-
let headDOM = head == anchor ? anchorDOM : this.domFromPos(head, head ? -1 : 1);
|
|
7663
|
-
let domSel = view.root.getSelection();
|
|
7664
|
-
let selRange = view.domSelectionRange();
|
|
7665
|
-
let brKludge = false;
|
|
7666
|
-
if ((gecko || safari) && anchor == head) {
|
|
7667
|
-
let { node, offset } = anchorDOM;
|
|
7668
|
-
if (isText(node)) {
|
|
7669
|
-
brKludge = !!(offset && node.nodeValue[offset - 1] == "\n");
|
|
7670
|
-
if (brKludge && offset == node.nodeValue.length) for (let scan = node, after; scan; scan = scan.parentNode) {
|
|
7671
|
-
if (after = scan.nextSibling) {
|
|
7672
|
-
if (after.nodeName == "BR") anchorDOM = headDOM = {
|
|
7673
|
-
node: after.parentNode,
|
|
7674
|
-
offset: domIndex(after) + 1
|
|
7675
|
-
};
|
|
7676
|
-
break;
|
|
7677
|
-
}
|
|
7678
|
-
let desc = scan.pmViewDesc;
|
|
7679
|
-
if (desc && desc.node && desc.node.isBlock) break;
|
|
7680
|
-
}
|
|
7681
|
-
} else {
|
|
7682
|
-
let prev = node.childNodes[offset - 1];
|
|
7683
|
-
brKludge = prev && (prev.nodeName == "BR" || prev.contentEditable == "false");
|
|
7684
|
-
}
|
|
7685
|
-
}
|
|
7686
|
-
if (gecko && selRange.focusNode && selRange.focusNode != headDOM.node && isElt(selRange.focusNode)) {
|
|
7687
|
-
let after = selRange.focusNode.childNodes[selRange.focusOffset];
|
|
7688
|
-
if (after && after.contentEditable == "false") force = true;
|
|
7689
|
-
}
|
|
7690
|
-
if (!(force || brKludge && safari) && isEquivalentPosition(anchorDOM.node, anchorDOM.offset, selRange.anchorNode, selRange.anchorOffset) && isEquivalentPosition(headDOM.node, headDOM.offset, selRange.focusNode, selRange.focusOffset)) return;
|
|
7691
|
-
let domSelExtended = false;
|
|
7692
|
-
if ((domSel.extend || anchor == head) && !(brKludge && gecko)) {
|
|
7693
|
-
domSel.collapse(anchorDOM.node, anchorDOM.offset);
|
|
7694
|
-
try {
|
|
7695
|
-
if (anchor != head) domSel.extend(headDOM.node, headDOM.offset);
|
|
7696
|
-
domSelExtended = true;
|
|
7697
|
-
} catch (_) {}
|
|
7698
|
-
}
|
|
7699
|
-
if (!domSelExtended) {
|
|
7700
|
-
if (anchor > head) {
|
|
7701
|
-
let tmp = anchorDOM;
|
|
7702
|
-
anchorDOM = headDOM;
|
|
7703
|
-
headDOM = tmp;
|
|
7704
|
-
}
|
|
7705
|
-
let range = document.createRange();
|
|
7706
|
-
range.setEnd(headDOM.node, headDOM.offset);
|
|
7707
|
-
range.setStart(anchorDOM.node, anchorDOM.offset);
|
|
7708
|
-
domSel.removeAllRanges();
|
|
7709
|
-
domSel.addRange(range);
|
|
7710
|
-
}
|
|
7711
|
-
}
|
|
7712
7695
|
ignoreMutation(mutation) {
|
|
7713
7696
|
return !this.contentDOM && mutation.type != "selection";
|
|
7714
7697
|
}
|
|
7715
7698
|
get contentLost() {
|
|
7716
7699
|
return this.contentDOM && this.contentDOM != this.dom && !this.dom.contains(this.contentDOM);
|
|
7717
7700
|
}
|
|
7718
|
-
|
|
7719
|
-
|
|
7720
|
-
|
|
7721
|
-
|
|
7722
|
-
let startInside = offset + child.border, endInside = end - child.border;
|
|
7723
|
-
if (from >= startInside && to <= endInside) {
|
|
7724
|
-
this.dirty = from == offset || to == end ? CONTENT_DIRTY : CHILD_DIRTY;
|
|
7725
|
-
if (from == startInside && to == endInside && (child.contentLost || child.dom.parentNode != this.contentDOM)) child.dirty = NODE_DIRTY;
|
|
7726
|
-
else child.markDirty(from - startInside, to - startInside);
|
|
7727
|
-
return;
|
|
7728
|
-
} else child.dirty = child.dom == child.contentDOM && child.dom.parentNode == this.contentDOM && !child.children.length ? CONTENT_DIRTY : NODE_DIRTY;
|
|
7729
|
-
}
|
|
7730
|
-
offset = end;
|
|
7701
|
+
markDamage(damage) {
|
|
7702
|
+
if (damage) {
|
|
7703
|
+
this.damage |= damage;
|
|
7704
|
+
this.markParentDamage();
|
|
7731
7705
|
}
|
|
7732
|
-
this.dirty = CONTENT_DIRTY;
|
|
7733
7706
|
}
|
|
7734
|
-
|
|
7735
|
-
let
|
|
7736
|
-
|
|
7737
|
-
|
|
7738
|
-
|
|
7707
|
+
markParentDamage() {
|
|
7708
|
+
for (let cur = this;;) {
|
|
7709
|
+
let { parent } = cur;
|
|
7710
|
+
if (!parent || parent.damage & 1) break;
|
|
7711
|
+
parent.damage |= 1;
|
|
7712
|
+
cur = parent;
|
|
7739
7713
|
}
|
|
7740
7714
|
}
|
|
7741
7715
|
get domAtom() {
|
|
@@ -7773,7 +7747,7 @@ var WidgetViewDesc = class extends ViewDesc {
|
|
|
7773
7747
|
self = this;
|
|
7774
7748
|
}
|
|
7775
7749
|
matchesWidget(widget) {
|
|
7776
|
-
return this.
|
|
7750
|
+
return !this.damage && widget.type.eq(this.widget.type);
|
|
7777
7751
|
}
|
|
7778
7752
|
parseRule() {
|
|
7779
7753
|
return { ignore: true };
|
|
@@ -7835,7 +7809,7 @@ var MarkViewDesc = class MarkViewDesc extends ViewDesc {
|
|
|
7835
7809
|
return new MarkViewDesc(parent, mark, spec.dom, spec.contentDOM || spec.dom, spec);
|
|
7836
7810
|
}
|
|
7837
7811
|
parseRule() {
|
|
7838
|
-
if (this.
|
|
7812
|
+
if (this.damage & 4 || this.mark.type.spec.reparseInView) return null;
|
|
7839
7813
|
return {
|
|
7840
7814
|
mark: this.mark.type.name,
|
|
7841
7815
|
attrs: this.mark.attrs,
|
|
@@ -7843,16 +7817,12 @@ var MarkViewDesc = class MarkViewDesc extends ViewDesc {
|
|
|
7843
7817
|
};
|
|
7844
7818
|
}
|
|
7845
7819
|
matchesMark(mark) {
|
|
7846
|
-
return this.
|
|
7820
|
+
return !(this.damage & 4) && this.mark.eq(mark);
|
|
7847
7821
|
}
|
|
7848
|
-
|
|
7849
|
-
|
|
7850
|
-
|
|
7851
|
-
|
|
7852
|
-
while (!parent.node) parent = parent.parent;
|
|
7853
|
-
if (parent.dirty < this.dirty) parent.dirty = this.dirty;
|
|
7854
|
-
this.dirty = NOT_DIRTY;
|
|
7855
|
-
}
|
|
7822
|
+
markDamage(damage) {
|
|
7823
|
+
var _a;
|
|
7824
|
+
this.damage |= damage;
|
|
7825
|
+
(_a = this.parent) === null || _a === void 0 || _a.markDamage(2);
|
|
7856
7826
|
}
|
|
7857
7827
|
slice(from, to, view) {
|
|
7858
7828
|
let copy = MarkViewDesc.create(this.parent, this.mark, true, view);
|
|
@@ -7929,7 +7899,7 @@ var NodeViewDesc = class NodeViewDesc extends ViewDesc {
|
|
|
7929
7899
|
return rule;
|
|
7930
7900
|
}
|
|
7931
7901
|
matchesNode(node, outerDeco, innerDeco) {
|
|
7932
|
-
return this.
|
|
7902
|
+
return !this.damage && node.eq(this.node) && sameOuterDeco(outerDeco, this.outerDeco) && innerDeco.eq(this.innerDeco);
|
|
7933
7903
|
}
|
|
7934
7904
|
get size() {
|
|
7935
7905
|
return this.node.nodeSize;
|
|
@@ -7953,7 +7923,7 @@ var NodeViewDesc = class NodeViewDesc extends ViewDesc {
|
|
|
7953
7923
|
if (atBufferPos && child.isAtom && !child.isText) updater.addHackNode("IMG", updater.top);
|
|
7954
7924
|
let compIndex;
|
|
7955
7925
|
if (updater.findNodeMatch(child, outerDeco, innerDeco, i));
|
|
7956
|
-
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));
|
|
7926
|
+
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, off));
|
|
7957
7927
|
else if (updater.updateNextNode(child, outerDeco, innerDeco, view, i, off));
|
|
7958
7928
|
else updater.addNode(child, outerDeco, innerDeco, view, off);
|
|
7959
7929
|
off += child.nodeSize;
|
|
@@ -7962,7 +7932,7 @@ var NodeViewDesc = class NodeViewDesc extends ViewDesc {
|
|
|
7962
7932
|
updater.syncToMarks([], inline, view, 0);
|
|
7963
7933
|
if (this.node.isTextblock) updater.addTextblockHacks();
|
|
7964
7934
|
updater.destroyRest();
|
|
7965
|
-
if (updater.changed || this.
|
|
7935
|
+
if (updater.changed || this.damage & 2) {
|
|
7966
7936
|
if (localComposition) this.protectLocalComposition(view, localComposition);
|
|
7967
7937
|
renderDescs(this.contentDOM, this.children, view);
|
|
7968
7938
|
if (ios) iosHacks(this.dom);
|
|
@@ -8000,17 +7970,17 @@ var NodeViewDesc = class NodeViewDesc extends ViewDesc {
|
|
|
8000
7970
|
view.input.compositionNodes.push(desc);
|
|
8001
7971
|
this.children = replaceNodes(this.children, pos, pos + text.length, view, desc);
|
|
8002
7972
|
}
|
|
8003
|
-
update(node, outerDeco, innerDeco, view) {
|
|
8004
|
-
if (this.
|
|
8005
|
-
this.updateInner(node, outerDeco, innerDeco, view);
|
|
7973
|
+
update(node, outerDeco, innerDeco, view, pos) {
|
|
7974
|
+
if (this.damage & 4 || !node.sameMarkup(this.node)) return false;
|
|
7975
|
+
this.updateInner(node, outerDeco, innerDeco, view, pos);
|
|
8006
7976
|
return true;
|
|
8007
7977
|
}
|
|
8008
|
-
updateInner(node, outerDeco, innerDeco, view) {
|
|
7978
|
+
updateInner(node, outerDeco, innerDeco, view, pos) {
|
|
8009
7979
|
this.updateOuterDeco(outerDeco);
|
|
8010
7980
|
this.node = node;
|
|
8011
7981
|
this.innerDeco = innerDeco;
|
|
8012
|
-
if (this.contentDOM) this.updateChildren(view,
|
|
8013
|
-
this.
|
|
7982
|
+
if (this.contentDOM) this.updateChildren(view, pos + 1);
|
|
7983
|
+
this.damage = 0;
|
|
8014
7984
|
}
|
|
8015
7985
|
updateOuterDeco(outerDeco) {
|
|
8016
7986
|
if (sameOuterDeco(outerDeco, this.outerDeco)) return;
|
|
@@ -8039,8 +8009,9 @@ var NodeViewDesc = class NodeViewDesc extends ViewDesc {
|
|
|
8039
8009
|
return this.node.isAtom;
|
|
8040
8010
|
}
|
|
8041
8011
|
};
|
|
8042
|
-
function docViewDesc(doc, outerDeco, innerDeco, dom, view) {
|
|
8043
|
-
applyOuterDeco(dom, outerDeco, doc);
|
|
8012
|
+
function docViewDesc(doc, outerDeco, innerDeco, dom, view, prevOuterDeco) {
|
|
8013
|
+
if (!prevOuterDeco) applyOuterDeco(dom, outerDeco, doc);
|
|
8014
|
+
else patchOuterDeco(dom, dom, computeOuterDeco(prevOuterDeco, doc, false), computeOuterDeco(outerDeco, doc, false));
|
|
8044
8015
|
let docView = new NodeViewDesc(void 0, doc, outerDeco, innerDeco, dom, dom, dom);
|
|
8045
8016
|
if (docView.contentDOM) docView.updateChildren(view, 0);
|
|
8046
8017
|
return docView;
|
|
@@ -8055,14 +8026,14 @@ var TextViewDesc = class TextViewDesc extends NodeViewDesc {
|
|
|
8055
8026
|
return { skip: skip || true };
|
|
8056
8027
|
}
|
|
8057
8028
|
update(node, outerDeco, innerDeco, view) {
|
|
8058
|
-
if (this.
|
|
8029
|
+
if (this.damage & 4 || this.damage && !this.inParent() || !node.sameMarkup(this.node)) return false;
|
|
8059
8030
|
this.updateOuterDeco(outerDeco);
|
|
8060
|
-
if ((this.
|
|
8031
|
+
if ((this.damage & 8 || node.text != this.node.text) && node.text != this.nodeDOM.nodeValue) {
|
|
8061
8032
|
this.nodeDOM.nodeValue = node.text;
|
|
8062
8033
|
if (view.trackWrites == this.nodeDOM) view.trackWrites = null;
|
|
8063
8034
|
}
|
|
8064
8035
|
this.node = node;
|
|
8065
|
-
this.
|
|
8036
|
+
this.damage = 0;
|
|
8066
8037
|
return true;
|
|
8067
8038
|
}
|
|
8068
8039
|
inParent() {
|
|
@@ -8081,16 +8052,12 @@ var TextViewDesc = class TextViewDesc extends NodeViewDesc {
|
|
|
8081
8052
|
return super.localPosFromDOM(dom, offset, bias);
|
|
8082
8053
|
}
|
|
8083
8054
|
ignoreMutation(mutation) {
|
|
8084
|
-
return
|
|
8055
|
+
return false;
|
|
8085
8056
|
}
|
|
8086
8057
|
slice(from, to, _view) {
|
|
8087
8058
|
let node = this.node.cut(from, to), dom = document.createTextNode(node.text);
|
|
8088
8059
|
return new TextViewDesc(this.parent, node, this.outerDeco, this.innerDeco, dom, dom);
|
|
8089
8060
|
}
|
|
8090
|
-
markDirty(from, to) {
|
|
8091
|
-
super.markDirty(from, to);
|
|
8092
|
-
if (this.dom != this.nodeDOM && (from == 0 || to == this.nodeDOM.nodeValue.length)) this.dirty = NODE_DIRTY;
|
|
8093
|
-
}
|
|
8094
8061
|
get domAtom() {
|
|
8095
8062
|
return false;
|
|
8096
8063
|
}
|
|
@@ -8103,7 +8070,7 @@ var BufferHackViewDesc = class extends ViewDesc {
|
|
|
8103
8070
|
return { ignore: true };
|
|
8104
8071
|
}
|
|
8105
8072
|
matchesHack(nodeName) {
|
|
8106
|
-
return this.
|
|
8073
|
+
return !this.damage && this.dom.nodeName == nodeName;
|
|
8107
8074
|
}
|
|
8108
8075
|
get domAtom() {
|
|
8109
8076
|
return true;
|
|
@@ -8117,14 +8084,14 @@ var CustomNodeViewDesc = class extends NodeViewDesc {
|
|
|
8117
8084
|
super(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM);
|
|
8118
8085
|
this.spec = spec;
|
|
8119
8086
|
}
|
|
8120
|
-
update(node, outerDeco, innerDeco, view) {
|
|
8121
|
-
if (this.
|
|
8087
|
+
update(node, outerDeco, innerDeco, view, pos) {
|
|
8088
|
+
if (this.damage & 4) return false;
|
|
8122
8089
|
if (this.spec.update && (this.node.type == node.type || this.spec.multiType)) {
|
|
8123
8090
|
let result = this.spec.update(node, outerDeco, innerDeco);
|
|
8124
|
-
if (result) this.updateInner(node, outerDeco, innerDeco, view);
|
|
8091
|
+
if (result) this.updateInner(node, outerDeco, innerDeco, view, pos);
|
|
8125
8092
|
return result;
|
|
8126
8093
|
} else if (!this.contentDOM && !node.isLeaf) return false;
|
|
8127
|
-
else return super.update(node, outerDeco, innerDeco, view);
|
|
8094
|
+
else return super.update(node, outerDeco, innerDeco, view, pos);
|
|
8128
8095
|
}
|
|
8129
8096
|
selectNode() {
|
|
8130
8097
|
this.spec.selectNode ? this.spec.selectNode() : super.selectNode();
|
|
@@ -8132,9 +8099,6 @@ var CustomNodeViewDesc = class extends NodeViewDesc {
|
|
|
8132
8099
|
deselectNode() {
|
|
8133
8100
|
this.spec.deselectNode ? this.spec.deselectNode() : super.deselectNode();
|
|
8134
8101
|
}
|
|
8135
|
-
setSelection(anchor, head, view, force) {
|
|
8136
|
-
this.spec.setSelection ? this.spec.setSelection(anchor, head, view.root) : super.setSelection(anchor, head, view, force);
|
|
8137
|
-
}
|
|
8138
8102
|
destroy() {
|
|
8139
8103
|
if (this.spec.destroy) this.spec.destroy();
|
|
8140
8104
|
super.destroy();
|
|
@@ -8271,7 +8235,7 @@ var ViewTreeUpdater = class {
|
|
|
8271
8235
|
while (keep < maxKeep && (keep == depth - 1 ? this.top : this.stack[keep + 1 << 1]).matchesMark(marks[keep]) && marks[keep].type.spec.spanning !== false) keep++;
|
|
8272
8236
|
while (keep < depth) {
|
|
8273
8237
|
this.destroyRest();
|
|
8274
|
-
this.top.
|
|
8238
|
+
this.top.damage = 0;
|
|
8275
8239
|
this.index = this.stack.pop();
|
|
8276
8240
|
this.top = this.stack.pop();
|
|
8277
8241
|
depth--;
|
|
@@ -8289,7 +8253,7 @@ var ViewTreeUpdater = class {
|
|
|
8289
8253
|
}
|
|
8290
8254
|
if (found < 0 && this.index < this.top.children.length) {
|
|
8291
8255
|
let cur = this.top.children[this.index];
|
|
8292
|
-
if (cur instanceof MarkViewDesc && cur.
|
|
8256
|
+
if (cur instanceof MarkViewDesc && !(cur.damage & 4) && cur.mark.type == marks[depth].type && cur.spec.update && !this.isLocked(cur.dom) && cur.spec.update(marks[depth])) {
|
|
8293
8257
|
cur.mark = marks[depth];
|
|
8294
8258
|
found = this.index;
|
|
8295
8259
|
this.changed = true;
|
|
@@ -8326,10 +8290,10 @@ var ViewTreeUpdater = class {
|
|
|
8326
8290
|
this.index++;
|
|
8327
8291
|
return true;
|
|
8328
8292
|
}
|
|
8329
|
-
updateNodeAt(node, outerDeco, innerDeco, index, view) {
|
|
8293
|
+
updateNodeAt(node, outerDeco, innerDeco, index, view, pos) {
|
|
8330
8294
|
let child = this.top.children[index];
|
|
8331
|
-
if (child.
|
|
8332
|
-
if (!child.update(node, outerDeco, innerDeco, view)) return false;
|
|
8295
|
+
if (child.damage & 4 && child.dom == child.contentDOM) child.damage = 2;
|
|
8296
|
+
if (!child.update(node, outerDeco, innerDeco, view, pos)) return false;
|
|
8333
8297
|
this.destroyBetween(this.index, index);
|
|
8334
8298
|
this.index++;
|
|
8335
8299
|
return true;
|
|
@@ -8355,8 +8319,8 @@ var ViewTreeUpdater = class {
|
|
|
8355
8319
|
let preMatch = this.preMatch.matched.get(next);
|
|
8356
8320
|
if (preMatch != null && preMatch != index) return false;
|
|
8357
8321
|
let nextDOM = next.dom, updated;
|
|
8358
|
-
let locked = this.isLocked(nextDOM) && !(node.isText && next.node && next.node.isText && next.nodeDOM.nodeValue == node.text && next.
|
|
8359
|
-
if (!locked && next.update(node, outerDeco, innerDeco, view)) {
|
|
8322
|
+
let locked = this.isLocked(nextDOM) && !(node.isText && next.node && next.node.isText && next.nodeDOM.nodeValue == node.text && !(next.damage & 4) && sameOuterDeco(outerDeco, next.outerDeco));
|
|
8323
|
+
if (!locked && next.update(node, outerDeco, innerDeco, view, pos)) {
|
|
8360
8324
|
this.destroyBetween(this.index, i);
|
|
8361
8325
|
if (next.dom != nextDOM) this.changed = true;
|
|
8362
8326
|
this.index++;
|
|
@@ -8365,9 +8329,9 @@ var ViewTreeUpdater = class {
|
|
|
8365
8329
|
this.destroyBetween(this.index, i);
|
|
8366
8330
|
this.top.children[this.index] = updated;
|
|
8367
8331
|
if (updated.contentDOM) {
|
|
8368
|
-
updated.
|
|
8332
|
+
updated.damage |= 2;
|
|
8369
8333
|
updated.updateChildren(view, pos + 1);
|
|
8370
|
-
updated.
|
|
8334
|
+
updated.damage = 0;
|
|
8371
8335
|
}
|
|
8372
8336
|
this.changed = true;
|
|
8373
8337
|
this.index++;
|
|
@@ -8379,7 +8343,7 @@ var ViewTreeUpdater = class {
|
|
|
8379
8343
|
return false;
|
|
8380
8344
|
}
|
|
8381
8345
|
recreateWrapper(next, node, outerDeco, innerDeco, view, pos) {
|
|
8382
|
-
if (next.
|
|
8346
|
+
if (next.damage & 3 || node.isAtom || !next.children.length || !next.node.content.eq(node.content) || !sameOuterDeco(outerDeco, next.outerDeco) || !innerDeco.eq(next.innerDeco)) return null;
|
|
8383
8347
|
let wrapper = NodeViewDesc.create(this.top, node, outerDeco, innerDeco, view, pos);
|
|
8384
8348
|
if (wrapper.contentDOM) {
|
|
8385
8349
|
wrapper.children = next.children;
|
|
@@ -8435,13 +8399,14 @@ var ViewTreeUpdater = class {
|
|
|
8435
8399
|
}
|
|
8436
8400
|
};
|
|
8437
8401
|
function preMatch(frag, parentDesc) {
|
|
8438
|
-
let curDesc = parentDesc, descI = curDesc.children.length;
|
|
8402
|
+
let curDesc = parentDesc, descI = curDesc.children.length, stack = [];
|
|
8439
8403
|
let fI = frag.childCount, matched = /* @__PURE__ */ new Map(), matches = [];
|
|
8440
8404
|
outer: while (fI > 0) {
|
|
8441
8405
|
let desc;
|
|
8442
8406
|
for (;;) if (descI) {
|
|
8443
8407
|
let next = curDesc.children[descI - 1];
|
|
8444
8408
|
if (next instanceof MarkViewDesc) {
|
|
8409
|
+
stack.push(descI - 1);
|
|
8445
8410
|
curDesc = next;
|
|
8446
8411
|
descI = next.children.length;
|
|
8447
8412
|
} else {
|
|
@@ -8451,7 +8416,7 @@ function preMatch(frag, parentDesc) {
|
|
|
8451
8416
|
}
|
|
8452
8417
|
} else if (curDesc == parentDesc) break outer;
|
|
8453
8418
|
else {
|
|
8454
|
-
descI =
|
|
8419
|
+
descI = stack.pop();
|
|
8455
8420
|
curDesc = curDesc.parent;
|
|
8456
8421
|
}
|
|
8457
8422
|
let node = desc.node;
|
|
@@ -8569,172 +8534,6 @@ function replaceNodes(nodes, from, to, view, replacement) {
|
|
|
8569
8534
|
}
|
|
8570
8535
|
return result;
|
|
8571
8536
|
}
|
|
8572
|
-
function selectionFromDOM(view, origin = null) {
|
|
8573
|
-
let domSel = view.domSelectionRange(), doc = view.state.doc;
|
|
8574
|
-
if (!domSel.focusNode) return null;
|
|
8575
|
-
let nearestDesc = view.docView.nearestDesc(domSel.focusNode), inWidget = nearestDesc && nearestDesc.size == 0;
|
|
8576
|
-
let head = view.docView.posFromDOM(domSel.focusNode, domSel.focusOffset, 1);
|
|
8577
|
-
if (head < 0) return null;
|
|
8578
|
-
let $head = doc.resolve(head), anchor, selection;
|
|
8579
|
-
if (selectionCollapsed(domSel)) {
|
|
8580
|
-
anchor = head;
|
|
8581
|
-
while (nearestDesc && !nearestDesc.node) nearestDesc = nearestDesc.parent;
|
|
8582
|
-
if (nearestDesc && nearestDesc.node.isAtom && NodeSelection.isSelectable(nearestDesc.node) && nearestDesc.parent && !(nearestDesc.node.isInline && isOnEdge(domSel.focusNode, domSel.focusOffset, nearestDesc.dom))) {
|
|
8583
|
-
let pos = nearestDesc.posBefore;
|
|
8584
|
-
selection = new NodeSelection(head == pos ? $head : doc.resolve(pos));
|
|
8585
|
-
} 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) for (let scan = domSel.focusNode;; scan = scan.parentNode) {
|
|
8586
|
-
if (getComputedStyle(scan).overflow != "visible") {
|
|
8587
|
-
selection = Selection$1.findFrom(doc.resolve(nearestDesc.posAtStart), 1);
|
|
8588
|
-
break;
|
|
8589
|
-
}
|
|
8590
|
-
if (scan == nearestDesc.dom || scan.nextSibling || !scan.parentNode || !isElt(scan.parentNode)) break;
|
|
8591
|
-
}
|
|
8592
|
-
} else {
|
|
8593
|
-
if (domSel instanceof view.dom.ownerDocument.defaultView.Selection && domSel.rangeCount > 1) {
|
|
8594
|
-
let min = head, max = head;
|
|
8595
|
-
for (let i = 0; i < domSel.rangeCount; i++) {
|
|
8596
|
-
let range = domSel.getRangeAt(i);
|
|
8597
|
-
min = Math.min(min, view.docView.posFromDOM(range.startContainer, range.startOffset, 1));
|
|
8598
|
-
max = Math.max(max, view.docView.posFromDOM(range.endContainer, range.endOffset, -1));
|
|
8599
|
-
}
|
|
8600
|
-
if (min < 0) return null;
|
|
8601
|
-
[anchor, head] = max == view.state.selection.anchor ? [max, min] : [min, max];
|
|
8602
|
-
$head = doc.resolve(head);
|
|
8603
|
-
} else anchor = view.docView.posFromDOM(domSel.anchorNode, domSel.anchorOffset, 1);
|
|
8604
|
-
if (anchor < 0) return null;
|
|
8605
|
-
}
|
|
8606
|
-
let $anchor = doc.resolve(anchor);
|
|
8607
|
-
if (!selection) {
|
|
8608
|
-
let bias = origin == "pointer" || view.state.selection.head < $head.pos && !inWidget ? 1 : -1;
|
|
8609
|
-
selection = selectionBetween(view, $anchor, $head, bias);
|
|
8610
|
-
}
|
|
8611
|
-
return selection;
|
|
8612
|
-
}
|
|
8613
|
-
function editorOwnsSelection(view) {
|
|
8614
|
-
return view.editable ? view.hasFocus() : hasSelection(view) && document.activeElement && document.activeElement.contains(view.dom);
|
|
8615
|
-
}
|
|
8616
|
-
function selectionToDOM(view, force = false) {
|
|
8617
|
-
let sel = view.state.selection;
|
|
8618
|
-
syncNodeSelection(view, sel);
|
|
8619
|
-
if (!editorOwnsSelection(view)) return;
|
|
8620
|
-
let mouseDown = view.input.mouseDown;
|
|
8621
|
-
if (!force && chrome && mouseDown) {
|
|
8622
|
-
let domSel = view.domSelectionRange(), curSel = view.domObserver.currentSelection;
|
|
8623
|
-
if (domSel.anchorNode && curSel.anchorNode && isEquivalentPosition(domSel.anchorNode, domSel.anchorOffset, curSel.anchorNode, curSel.anchorOffset) && mouseDown.delaySelUpdate()) {
|
|
8624
|
-
view.domObserver.setCurSelection();
|
|
8625
|
-
return;
|
|
8626
|
-
}
|
|
8627
|
-
}
|
|
8628
|
-
view.domObserver.disconnectSelection();
|
|
8629
|
-
if (view.cursorWrapper) selectCursorWrapper(view);
|
|
8630
|
-
else {
|
|
8631
|
-
let { anchor, head } = sel, resetEditableFrom, resetEditableTo;
|
|
8632
|
-
if (brokenSelectBetweenUneditable && !(sel instanceof TextSelection)) {
|
|
8633
|
-
if (!sel.$from.parent.inlineContent) resetEditableFrom = temporarilyEditableNear(view, sel.from);
|
|
8634
|
-
if (!sel.empty && !sel.$from.parent.inlineContent) resetEditableTo = temporarilyEditableNear(view, sel.to);
|
|
8635
|
-
}
|
|
8636
|
-
view.docView.setSelection(anchor, head, view, force);
|
|
8637
|
-
if (brokenSelectBetweenUneditable) {
|
|
8638
|
-
if (resetEditableFrom) resetEditable(resetEditableFrom);
|
|
8639
|
-
if (resetEditableTo) resetEditable(resetEditableTo);
|
|
8640
|
-
}
|
|
8641
|
-
if (sel.visible) view.dom.classList.remove("ProseMirror-hideselection");
|
|
8642
|
-
else {
|
|
8643
|
-
view.dom.classList.add("ProseMirror-hideselection");
|
|
8644
|
-
if ("onselectionchange" in document) removeClassOnSelectionChange(view);
|
|
8645
|
-
}
|
|
8646
|
-
}
|
|
8647
|
-
view.domObserver.setCurSelection();
|
|
8648
|
-
view.domObserver.connectSelection();
|
|
8649
|
-
}
|
|
8650
|
-
var brokenSelectBetweenUneditable = safari || chrome && chrome_version < 63;
|
|
8651
|
-
function temporarilyEditableNear(view, pos) {
|
|
8652
|
-
let { node, offset } = view.docView.domFromPos(pos, 0);
|
|
8653
|
-
let after = offset < node.childNodes.length ? node.childNodes[offset] : null;
|
|
8654
|
-
let before = offset ? node.childNodes[offset - 1] : null;
|
|
8655
|
-
if (safari && after && after.contentEditable == "false") return setEditable(after);
|
|
8656
|
-
if ((!after || after.contentEditable == "false") && (!before || before.contentEditable == "false")) {
|
|
8657
|
-
if (after) return setEditable(after);
|
|
8658
|
-
else if (before) return setEditable(before);
|
|
8659
|
-
}
|
|
8660
|
-
}
|
|
8661
|
-
function setEditable(element) {
|
|
8662
|
-
element.contentEditable = "true";
|
|
8663
|
-
if (safari && element.draggable) {
|
|
8664
|
-
element.draggable = false;
|
|
8665
|
-
element.wasDraggable = true;
|
|
8666
|
-
}
|
|
8667
|
-
return element;
|
|
8668
|
-
}
|
|
8669
|
-
function resetEditable(element) {
|
|
8670
|
-
element.contentEditable = "false";
|
|
8671
|
-
if (element.wasDraggable) {
|
|
8672
|
-
element.draggable = true;
|
|
8673
|
-
element.wasDraggable = null;
|
|
8674
|
-
}
|
|
8675
|
-
}
|
|
8676
|
-
function removeClassOnSelectionChange(view) {
|
|
8677
|
-
let doc = view.dom.ownerDocument;
|
|
8678
|
-
doc.removeEventListener("selectionchange", view.input.hideSelectionGuard);
|
|
8679
|
-
let domSel = view.domSelectionRange();
|
|
8680
|
-
let node = domSel.anchorNode, offset = domSel.anchorOffset;
|
|
8681
|
-
doc.addEventListener("selectionchange", view.input.hideSelectionGuard = () => {
|
|
8682
|
-
if (domSel.anchorNode != node || domSel.anchorOffset != offset) {
|
|
8683
|
-
doc.removeEventListener("selectionchange", view.input.hideSelectionGuard);
|
|
8684
|
-
setTimeout(() => {
|
|
8685
|
-
if (!editorOwnsSelection(view) || view.state.selection.visible) view.dom.classList.remove("ProseMirror-hideselection");
|
|
8686
|
-
}, 20);
|
|
8687
|
-
}
|
|
8688
|
-
});
|
|
8689
|
-
}
|
|
8690
|
-
function selectCursorWrapper(view) {
|
|
8691
|
-
let domSel = view.domSelection();
|
|
8692
|
-
if (!domSel) return;
|
|
8693
|
-
let node = view.cursorWrapper.dom, img = node.nodeName == "IMG";
|
|
8694
|
-
if (img) domSel.collapse(node.parentNode, domIndex(node) + 1);
|
|
8695
|
-
else domSel.collapse(node, 0);
|
|
8696
|
-
if (!img && !view.state.selection.visible && ie$1 && ie_version <= 11) {
|
|
8697
|
-
node.disabled = true;
|
|
8698
|
-
node.disabled = false;
|
|
8699
|
-
}
|
|
8700
|
-
}
|
|
8701
|
-
function syncNodeSelection(view, sel) {
|
|
8702
|
-
if (sel instanceof NodeSelection) {
|
|
8703
|
-
let desc = view.docView.descAt(sel.from);
|
|
8704
|
-
if (desc != view.lastSelectedViewDesc) {
|
|
8705
|
-
clearNodeSelection(view);
|
|
8706
|
-
if (desc) desc.selectNode();
|
|
8707
|
-
view.lastSelectedViewDesc = desc;
|
|
8708
|
-
}
|
|
8709
|
-
} else clearNodeSelection(view);
|
|
8710
|
-
}
|
|
8711
|
-
function clearNodeSelection(view) {
|
|
8712
|
-
if (view.lastSelectedViewDesc) {
|
|
8713
|
-
if (view.lastSelectedViewDesc.parent) view.lastSelectedViewDesc.deselectNode();
|
|
8714
|
-
view.lastSelectedViewDesc = void 0;
|
|
8715
|
-
}
|
|
8716
|
-
}
|
|
8717
|
-
function selectionBetween(view, $anchor, $head, bias) {
|
|
8718
|
-
return view.someProp("createSelectionBetween", (f) => f(view, $anchor, $head)) || TextSelection.between($anchor, $head, bias);
|
|
8719
|
-
}
|
|
8720
|
-
function hasFocusAndSelection(view) {
|
|
8721
|
-
if (view.editable && !view.hasFocus()) return false;
|
|
8722
|
-
return hasSelection(view);
|
|
8723
|
-
}
|
|
8724
|
-
function hasSelection(view) {
|
|
8725
|
-
let sel = view.domSelectionRange();
|
|
8726
|
-
if (!sel.anchorNode) return false;
|
|
8727
|
-
try {
|
|
8728
|
-
return contains(view.dom, sel.anchorNode) && (view.editable || contains(view.dom, sel.focusNode));
|
|
8729
|
-
} catch (_) {
|
|
8730
|
-
return false;
|
|
8731
|
-
}
|
|
8732
|
-
}
|
|
8733
|
-
function anchorInRightPlace(view) {
|
|
8734
|
-
let anchorDOM = view.docView.domFromPos(view.state.selection.anchor, 0);
|
|
8735
|
-
let domSel = view.domSelectionRange();
|
|
8736
|
-
return isEquivalentPosition(anchorDOM.node, anchorDOM.offset, domSel.anchorNode, domSel.anchorOffset);
|
|
8737
|
-
}
|
|
8738
8537
|
function moveSelectionBlock(state, dir) {
|
|
8739
8538
|
let { $anchor, $head } = state.selection;
|
|
8740
8539
|
let $side = dir > 0 ? $anchor.max($head) : $anchor.min($head);
|
|
@@ -8781,7 +8580,7 @@ function skipIgnoredNodes(view, dir) {
|
|
|
8781
8580
|
return dir < 0 ? skipIgnoredNodesBefore(view) : skipIgnoredNodesAfter(view);
|
|
8782
8581
|
}
|
|
8783
8582
|
function skipIgnoredNodesBefore(view) {
|
|
8784
|
-
let sel = view.
|
|
8583
|
+
let sel = view.domSel.readRange();
|
|
8785
8584
|
let node = sel.focusNode, offset = sel.focusOffset;
|
|
8786
8585
|
if (!node) return;
|
|
8787
8586
|
let moveNode, moveOffset, force = false;
|
|
@@ -8817,7 +8616,7 @@ function skipIgnoredNodesBefore(view) {
|
|
|
8817
8616
|
else if (moveNode) setSelFocus(view, moveNode, moveOffset);
|
|
8818
8617
|
}
|
|
8819
8618
|
function skipIgnoredNodesAfter(view) {
|
|
8820
|
-
let sel = view.
|
|
8619
|
+
let sel = view.domSel.readRange();
|
|
8821
8620
|
let node = sel.focusNode, offset = sel.focusOffset;
|
|
8822
8621
|
if (!node) return;
|
|
8823
8622
|
let len = nodeSize(node);
|
|
@@ -8850,34 +8649,11 @@ function skipIgnoredNodesAfter(view) {
|
|
|
8850
8649
|
if (moveNode) setSelFocus(view, moveNode, moveOffset);
|
|
8851
8650
|
}
|
|
8852
8651
|
function isBlockNode(dom) {
|
|
8853
|
-
let
|
|
8854
|
-
|
|
8855
|
-
|
|
8856
|
-
function textNodeAfter(node, offset) {
|
|
8857
|
-
while (node && offset == node.childNodes.length && !hasBlockDesc(node)) {
|
|
8858
|
-
offset = domIndex(node) + 1;
|
|
8859
|
-
node = node.parentNode;
|
|
8860
|
-
}
|
|
8861
|
-
while (node && offset < node.childNodes.length) {
|
|
8862
|
-
let next = node.childNodes[offset];
|
|
8863
|
-
if (isText(next)) return next;
|
|
8864
|
-
if (isElt(next) && next.contentEditable == "false") break;
|
|
8865
|
-
node = next;
|
|
8866
|
-
offset = 0;
|
|
8867
|
-
}
|
|
8868
|
-
}
|
|
8869
|
-
function textNodeBefore(node, offset) {
|
|
8870
|
-
while (node && !offset && !hasBlockDesc(node)) {
|
|
8871
|
-
offset = domIndex(node);
|
|
8872
|
-
node = node.parentNode;
|
|
8873
|
-
}
|
|
8874
|
-
while (node && offset) {
|
|
8875
|
-
let next = node.childNodes[offset - 1];
|
|
8876
|
-
if (isText(next)) return next;
|
|
8877
|
-
if (isElt(next) && next.contentEditable == "false") break;
|
|
8878
|
-
node = next;
|
|
8879
|
-
offset = node.childNodes.length;
|
|
8652
|
+
for (let scan = dom; scan; scan = scan.parentNode) {
|
|
8653
|
+
let desc = scan.pmViewDesc;
|
|
8654
|
+
if (desc) return desc.node ? desc.node.isBlock : false;
|
|
8880
8655
|
}
|
|
8656
|
+
return false;
|
|
8881
8657
|
}
|
|
8882
8658
|
function setSelFocus(view, node, offset) {
|
|
8883
8659
|
if (!isText(node)) {
|
|
@@ -8890,17 +8666,17 @@ function setSelFocus(view, node, offset) {
|
|
|
8890
8666
|
offset = before.nodeValue.length;
|
|
8891
8667
|
}
|
|
8892
8668
|
}
|
|
8893
|
-
let sel = view.domSelection(), range = view.
|
|
8669
|
+
let sel = view.domSelection(), range = view.domSel.readRange();
|
|
8894
8670
|
if (!sel) return;
|
|
8895
8671
|
if (selectionCollapsed(range)) sel.collapse(node, offset);
|
|
8896
8672
|
else if (sel.extend) {
|
|
8897
8673
|
sel.collapse(range.anchorNode, range.anchorOffset);
|
|
8898
8674
|
sel.extend(node, offset);
|
|
8899
8675
|
}
|
|
8900
|
-
view.
|
|
8676
|
+
view.domSel.ignore();
|
|
8901
8677
|
let { state } = view;
|
|
8902
8678
|
setTimeout(() => {
|
|
8903
|
-
if (view.state == state)
|
|
8679
|
+
if (view.state == state) view.domSel.sync();
|
|
8904
8680
|
}, 50);
|
|
8905
8681
|
}
|
|
8906
8682
|
function findDirection(view, pos) {
|
|
@@ -8958,13 +8734,11 @@ function stopNativeHorizontalDelete(view, dir) {
|
|
|
8958
8734
|
return false;
|
|
8959
8735
|
}
|
|
8960
8736
|
function switchEditable(view, node, state) {
|
|
8961
|
-
view.domObserver.
|
|
8962
|
-
node.contentEditable = state;
|
|
8963
|
-
view.domObserver.start();
|
|
8737
|
+
view.domObserver.stopped(() => node.contentEditable = state);
|
|
8964
8738
|
}
|
|
8965
8739
|
function safariDownArrowBug(view) {
|
|
8966
8740
|
if (!safari || view.state.selection.$head.parentOffset > 0) return false;
|
|
8967
|
-
let { focusNode, focusOffset } = view.
|
|
8741
|
+
let { focusNode, focusOffset } = view.domSel.readRange();
|
|
8968
8742
|
if (focusNode && isElt(focusNode) && focusOffset == 0 && focusNode.firstChild && isElt(focusNode.firstChild) && focusNode.firstChild.contentEditable == "false") {
|
|
8969
8743
|
let child = focusNode.firstChild;
|
|
8970
8744
|
switchEditable(view, child, "true");
|
|
@@ -9089,7 +8863,7 @@ function parseFromClipboard(view, text, html, plainText, $context) {
|
|
|
9089
8863
|
}
|
|
9090
8864
|
}
|
|
9091
8865
|
view.someProp("transformPasted", (f) => {
|
|
9092
|
-
slice = f(slice, view,
|
|
8866
|
+
slice = f(slice, view, plainText);
|
|
9093
8867
|
});
|
|
9094
8868
|
return slice;
|
|
9095
8869
|
}
|
|
@@ -9217,7 +8991,7 @@ function addContext(slice, context) {
|
|
|
9217
8991
|
let { content, openStart, openEnd } = slice;
|
|
9218
8992
|
for (let i = array.length - 2; i >= 0; i -= 2) {
|
|
9219
8993
|
let type = schema.nodes[array[i]];
|
|
9220
|
-
if (!type || type.hasRequiredAttrs()) break;
|
|
8994
|
+
if (!type || type.hasRequiredAttrs() || !type.createAndFill(null, content)) break;
|
|
9221
8995
|
try {
|
|
9222
8996
|
content = Fragment$1.from(type.create(array[i + 1], content));
|
|
9223
8997
|
} catch (e) {
|
|
@@ -9228,60 +9002,407 @@ function addContext(slice, context) {
|
|
|
9228
9002
|
}
|
|
9229
9003
|
return new Slice(content, openStart, openEnd);
|
|
9230
9004
|
}
|
|
9231
|
-
var
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9238
|
-
|
|
9239
|
-
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9243
|
-
this.
|
|
9244
|
-
this.lastClick = {
|
|
9245
|
-
time: 0,
|
|
9246
|
-
x: 0,
|
|
9247
|
-
y: 0,
|
|
9248
|
-
type: "",
|
|
9249
|
-
button: 0
|
|
9250
|
-
};
|
|
9251
|
-
this.lastSelectionOrigin = null;
|
|
9252
|
-
this.lastSelectionTime = 0;
|
|
9253
|
-
this.lastIOSEnter = 0;
|
|
9254
|
-
this.lastIOSEnterFallbackTimeout = -1;
|
|
9255
|
-
this.lastFocus = 0;
|
|
9256
|
-
this.lastTouch = 0;
|
|
9257
|
-
this.lastChromeDelete = 0;
|
|
9258
|
-
this.composing = false;
|
|
9259
|
-
this.compositionNode = null;
|
|
9260
|
-
this.composingTimeout = -1;
|
|
9261
|
-
this.compositionNodes = [];
|
|
9262
|
-
this.compositionEndedAt = -2e8;
|
|
9263
|
-
this.compositionID = 1;
|
|
9264
|
-
this.badSafariComposition = false;
|
|
9265
|
-
this.compositionPendingChanges = 0;
|
|
9266
|
-
this.domChangeCount = 0;
|
|
9267
|
-
this.eventHandlers = Object.create(null);
|
|
9268
|
-
this.hideSelectionGuard = null;
|
|
9005
|
+
var StoredDOMSel = class StoredDOMSel {
|
|
9006
|
+
constructor(anchorNode, anchorOffset, focusNode, focusOffset) {
|
|
9007
|
+
this.anchorNode = anchorNode;
|
|
9008
|
+
this.anchorOffset = anchorOffset;
|
|
9009
|
+
this.focusNode = focusNode;
|
|
9010
|
+
this.focusOffset = focusOffset;
|
|
9011
|
+
}
|
|
9012
|
+
static from(range) {
|
|
9013
|
+
if (range instanceof StoredDOMSel) return range;
|
|
9014
|
+
return new StoredDOMSel(range.anchorNode, range.anchorOffset, range.focusNode, range.focusOffset);
|
|
9015
|
+
}
|
|
9016
|
+
eq(sel) {
|
|
9017
|
+
return sel.anchorNode == this.anchorNode && sel.anchorOffset == this.anchorOffset && sel.focusNode == this.focusNode && sel.focusOffset == this.focusOffset;
|
|
9269
9018
|
}
|
|
9270
9019
|
};
|
|
9271
|
-
|
|
9272
|
-
|
|
9273
|
-
|
|
9274
|
-
|
|
9275
|
-
|
|
9276
|
-
|
|
9020
|
+
StoredDOMSel.null = new StoredDOMSel(null, 0, null, 0);
|
|
9021
|
+
var DOMSelState = class {
|
|
9022
|
+
constructor(view) {
|
|
9023
|
+
this.view = view;
|
|
9024
|
+
this.range = StoredDOMSel.null;
|
|
9025
|
+
this.active = false;
|
|
9026
|
+
this.synced = false;
|
|
9027
|
+
this.suppress = false;
|
|
9028
|
+
this.currentDocument = null;
|
|
9029
|
+
this.onSelectionChange = this.onSelectionChange.bind(this);
|
|
9277
9030
|
}
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
|
|
9282
|
-
|
|
9283
|
-
|
|
9284
|
-
}
|
|
9031
|
+
ensureListener() {
|
|
9032
|
+
let doc = this.view.dom.ownerDocument;
|
|
9033
|
+
if (doc != this.currentDocument) {
|
|
9034
|
+
if (this.currentDocument) this.currentDocument.removeEventListener("selectionchange", this.onSelectionChange);
|
|
9035
|
+
this.currentDocument = doc;
|
|
9036
|
+
doc.addEventListener("selectionchange", this.onSelectionChange);
|
|
9037
|
+
}
|
|
9038
|
+
}
|
|
9039
|
+
destroy() {
|
|
9040
|
+
if (this.currentDocument) {
|
|
9041
|
+
this.currentDocument.removeEventListener("selectionchange", this.onSelectionChange);
|
|
9042
|
+
this.currentDocument = null;
|
|
9043
|
+
}
|
|
9044
|
+
this.active = false;
|
|
9045
|
+
this.range = StoredDOMSel.null;
|
|
9046
|
+
}
|
|
9047
|
+
suppressChanges() {
|
|
9048
|
+
this.suppress = true;
|
|
9049
|
+
setTimeout(() => this.suppress = false, 50);
|
|
9050
|
+
}
|
|
9051
|
+
onSelectionChange() {
|
|
9052
|
+
if (this.suppress && this.view.hasFocus()) return this.sync();
|
|
9053
|
+
if (this.read()) this.view.domObserver.flush(false);
|
|
9054
|
+
}
|
|
9055
|
+
readRange() {
|
|
9056
|
+
let { view } = this;
|
|
9057
|
+
let sel = view.dom.isConnected !== false && view.domSelection();
|
|
9058
|
+
if (!sel) return StoredDOMSel.null;
|
|
9059
|
+
if (safari && view.root.nodeType === 11 && deepActiveElement(view.dom.ownerDocument) == view.dom) return StoredDOMSel.from(safariShadowSelectionRange(view, sel) || sel);
|
|
9060
|
+
return StoredDOMSel.from(sel);
|
|
9061
|
+
}
|
|
9062
|
+
read() {
|
|
9063
|
+
this.ensureListener();
|
|
9064
|
+
let sel = hasFocusAndSelection(this.view);
|
|
9065
|
+
if (!sel) {
|
|
9066
|
+
this.active = false;
|
|
9067
|
+
this.range = StoredDOMSel.null;
|
|
9068
|
+
return;
|
|
9069
|
+
}
|
|
9070
|
+
this.active = true;
|
|
9071
|
+
if (this.range.eq(sel)) return false;
|
|
9072
|
+
this.range = sel;
|
|
9073
|
+
this.synced = false;
|
|
9074
|
+
return true;
|
|
9075
|
+
}
|
|
9076
|
+
sync(force = false) {
|
|
9077
|
+
let { view } = this;
|
|
9078
|
+
if (!view.docView) return;
|
|
9079
|
+
this.ensureListener();
|
|
9080
|
+
view.domObserver.stopped(() => {
|
|
9081
|
+
syncNodeSelection(view, view.state.selection);
|
|
9082
|
+
let sel = view.state.selection;
|
|
9083
|
+
if (view.input.mouseSelecting || editorOwnsSelection(view)) {
|
|
9084
|
+
let { desc, start } = innerViewDesc(view.docView, sel.from, sel.to, 0);
|
|
9085
|
+
if (view.cursorWrapper) selectCursorWrapper(view);
|
|
9086
|
+
else if (desc instanceof CustomNodeViewDesc && desc.spec.setSelection) desc.spec.setSelection(sel.anchor - start, sel.head - start, view.root);
|
|
9087
|
+
else selectionToDOM(view, force, desc, start);
|
|
9088
|
+
this.synced = this.active = true;
|
|
9089
|
+
}
|
|
9090
|
+
if (sel.visible == view.dom.classList.contains("ProseMirror-hideselection")) {
|
|
9091
|
+
if (sel.visible) view.dom.classList.remove("ProseMirror-hideselection");
|
|
9092
|
+
else {
|
|
9093
|
+
view.dom.classList.add("ProseMirror-hideselection");
|
|
9094
|
+
removeClassOnSelectionChange(view);
|
|
9095
|
+
}
|
|
9096
|
+
}
|
|
9097
|
+
this.range = this.readRange();
|
|
9098
|
+
});
|
|
9099
|
+
}
|
|
9100
|
+
ignore(sel = this.readRange()) {
|
|
9101
|
+
this.range = StoredDOMSel.from(sel);
|
|
9102
|
+
this.synced = true;
|
|
9103
|
+
}
|
|
9104
|
+
deactivate() {
|
|
9105
|
+
this.range = StoredDOMSel.null;
|
|
9106
|
+
this.active = this.synced = false;
|
|
9107
|
+
}
|
|
9108
|
+
};
|
|
9109
|
+
function safariShadowSelectionRange(view, selection) {
|
|
9110
|
+
if (selection.getComposedRanges) {
|
|
9111
|
+
let range = selection.getComposedRanges({ shadowRoots: [view.root] })[0];
|
|
9112
|
+
if (range) return rangeToSelectionRange(view, range);
|
|
9113
|
+
}
|
|
9114
|
+
let found;
|
|
9115
|
+
function read(event) {
|
|
9116
|
+
event.preventDefault();
|
|
9117
|
+
event.stopImmediatePropagation();
|
|
9118
|
+
found = event.getTargetRanges()[0];
|
|
9119
|
+
}
|
|
9120
|
+
view.dom.addEventListener("beforeinput", read, true);
|
|
9121
|
+
document.execCommand("indent");
|
|
9122
|
+
view.dom.removeEventListener("beforeinput", read, true);
|
|
9123
|
+
return found ? rangeToSelectionRange(view, found) : null;
|
|
9124
|
+
}
|
|
9125
|
+
function rangeToSelectionRange(view, range) {
|
|
9126
|
+
let anchorNode = range.startContainer, anchorOffset = range.startOffset;
|
|
9127
|
+
let focusNode = range.endContainer, focusOffset = range.endOffset;
|
|
9128
|
+
let currentAnchor = view.domAtPos(view.state.selection.anchor);
|
|
9129
|
+
if (isEquivalentPosition(currentAnchor.node, currentAnchor.offset, focusNode, focusOffset)) [anchorNode, anchorOffset, focusNode, focusOffset] = [
|
|
9130
|
+
focusNode,
|
|
9131
|
+
focusOffset,
|
|
9132
|
+
anchorNode,
|
|
9133
|
+
anchorOffset
|
|
9134
|
+
];
|
|
9135
|
+
return new StoredDOMSel(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
9136
|
+
}
|
|
9137
|
+
function selectionFromDOM(view, domSel, origin = null) {
|
|
9138
|
+
let doc = view.state.doc;
|
|
9139
|
+
if (!domSel.focusNode) return null;
|
|
9140
|
+
let nearestDesc = view.docView.nearestDesc(domSel.focusNode), inWidget = nearestDesc && nearestDesc.size == 0;
|
|
9141
|
+
let head = view.docView.posFromDOM(domSel.focusNode, domSel.focusOffset, 1);
|
|
9142
|
+
if (head < 0) return null;
|
|
9143
|
+
let $head = doc.resolve(head), anchor, selection;
|
|
9144
|
+
if (selectionCollapsed(domSel)) {
|
|
9145
|
+
anchor = head;
|
|
9146
|
+
while (nearestDesc && !nearestDesc.node) nearestDesc = nearestDesc.parent;
|
|
9147
|
+
if (nearestDesc && nearestDesc.node.isAtom && NodeSelection.isSelectable(nearestDesc.node) && nearestDesc.parent && !(nearestDesc.node.isInline && isOnEdge(domSel.focusNode, domSel.focusOffset, nearestDesc.dom))) {
|
|
9148
|
+
let pos = nearestDesc.posBefore;
|
|
9149
|
+
selection = new NodeSelection(head == pos ? $head : doc.resolve(pos));
|
|
9150
|
+
} 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) for (let scan = domSel.focusNode;; scan = scan.parentNode) {
|
|
9151
|
+
if (getComputedStyle(scan).overflow != "visible") {
|
|
9152
|
+
selection = Selection$1.findFrom(doc.resolve(nearestDesc.posAtStart), 1);
|
|
9153
|
+
break;
|
|
9154
|
+
}
|
|
9155
|
+
if (scan == nearestDesc.dom || scan.nextSibling || !scan.parentNode || !isElt(scan.parentNode)) break;
|
|
9156
|
+
}
|
|
9157
|
+
} else {
|
|
9158
|
+
if (domSel instanceof view.dom.ownerDocument.defaultView.Selection && domSel.rangeCount > 1) {
|
|
9159
|
+
let min = head, max = head;
|
|
9160
|
+
for (let i = 0; i < domSel.rangeCount; i++) {
|
|
9161
|
+
let range = domSel.getRangeAt(i);
|
|
9162
|
+
min = Math.min(min, view.docView.posFromDOM(range.startContainer, range.startOffset, 1));
|
|
9163
|
+
max = Math.max(max, view.docView.posFromDOM(range.endContainer, range.endOffset, -1));
|
|
9164
|
+
}
|
|
9165
|
+
if (min < 0) return null;
|
|
9166
|
+
[anchor, head] = max == view.state.selection.anchor ? [max, min] : [min, max];
|
|
9167
|
+
$head = doc.resolve(head);
|
|
9168
|
+
} else anchor = view.docView.posFromDOM(domSel.anchorNode, domSel.anchorOffset, 1);
|
|
9169
|
+
if (anchor < 0) return null;
|
|
9170
|
+
}
|
|
9171
|
+
let $anchor = doc.resolve(anchor);
|
|
9172
|
+
if (!selection) {
|
|
9173
|
+
let bias = origin == "pointer" || view.state.selection.head < $head.pos && !inWidget ? 1 : -1;
|
|
9174
|
+
selection = selectionBetween(view, $anchor, $head, bias);
|
|
9175
|
+
}
|
|
9176
|
+
return selection;
|
|
9177
|
+
}
|
|
9178
|
+
function editorOwnsSelection(view) {
|
|
9179
|
+
return view.editable ? view.hasFocus() : hasSelection(view, view.domSel.readRange()) && (!document.activeElement || document.activeElement.contains(view.dom));
|
|
9180
|
+
}
|
|
9181
|
+
function selectionToDOM(view, force, desc, start) {
|
|
9182
|
+
let sel = view.state.selection;
|
|
9183
|
+
let { anchor, head } = sel, resetEditableFrom, resetEditableTo;
|
|
9184
|
+
if (brokenSelectBetweenUneditable && !(sel instanceof TextSelection)) {
|
|
9185
|
+
if (!sel.$from.parent.inlineContent) resetEditableFrom = temporarilyEditableNear(view, sel.from);
|
|
9186
|
+
if (!sel.empty && !sel.$from.parent.inlineContent) resetEditableTo = temporarilyEditableNear(view, sel.to);
|
|
9187
|
+
}
|
|
9188
|
+
let anchorDOM = desc.domFromPos(anchor - start, anchor > start ? -1 : 1);
|
|
9189
|
+
setSelection(anchor, head, anchorDOM, head == anchor ? anchorDOM : desc.domFromPos(head - start, head > start ? -1 : 1), view, force);
|
|
9190
|
+
if (brokenSelectBetweenUneditable) {
|
|
9191
|
+
if (resetEditableFrom) resetEditable(resetEditableFrom);
|
|
9192
|
+
if (resetEditableTo) resetEditable(resetEditableTo);
|
|
9193
|
+
}
|
|
9194
|
+
}
|
|
9195
|
+
function innerViewDesc(desc, from, to, start = 0) {
|
|
9196
|
+
for (let i = 0, off = start; i < desc.children.length; i++) {
|
|
9197
|
+
let child = desc.children[i], end = off + child.size;
|
|
9198
|
+
if (from > off && to < end) return innerViewDesc(child, from, to, off + child.border);
|
|
9199
|
+
off = end;
|
|
9200
|
+
}
|
|
9201
|
+
return {
|
|
9202
|
+
desc,
|
|
9203
|
+
start
|
|
9204
|
+
};
|
|
9205
|
+
}
|
|
9206
|
+
function setSelection(anchor, head, anchorDOM, headDOM, view, force) {
|
|
9207
|
+
let brKludge = false;
|
|
9208
|
+
if ((gecko || safari) && anchor == head) {
|
|
9209
|
+
let { node, offset } = anchorDOM;
|
|
9210
|
+
if (isText(node)) {
|
|
9211
|
+
brKludge = !!(offset && node.nodeValue[offset - 1] == "\n");
|
|
9212
|
+
if (brKludge && offset == node.nodeValue.length) for (let scan = node, after; scan; scan = scan.parentNode) {
|
|
9213
|
+
if (after = scan.nextSibling) {
|
|
9214
|
+
if (after.nodeName == "BR") anchorDOM = headDOM = {
|
|
9215
|
+
node: after.parentNode,
|
|
9216
|
+
offset: domIndex(after) + 1
|
|
9217
|
+
};
|
|
9218
|
+
break;
|
|
9219
|
+
}
|
|
9220
|
+
let desc = scan.pmViewDesc;
|
|
9221
|
+
if (desc && desc.node && desc.node.isBlock) break;
|
|
9222
|
+
}
|
|
9223
|
+
} else {
|
|
9224
|
+
let prev = node.childNodes[offset - 1];
|
|
9225
|
+
brKludge = prev && (prev.nodeName == "BR" || prev.contentEditable == "false");
|
|
9226
|
+
}
|
|
9227
|
+
}
|
|
9228
|
+
let selRange = view.domSel.readRange();
|
|
9229
|
+
if (gecko && selRange.focusNode && selRange.focusNode != headDOM.node && isElt(selRange.focusNode)) {
|
|
9230
|
+
let after = selRange.focusNode.childNodes[selRange.focusOffset];
|
|
9231
|
+
if (after && after.contentEditable == "false") force = true;
|
|
9232
|
+
}
|
|
9233
|
+
if (!(force || brKludge && safari) && isEquivalentPosition(anchorDOM.node, anchorDOM.offset, selRange.anchorNode, selRange.anchorOffset) && isEquivalentPosition(headDOM.node, headDOM.offset, selRange.focusNode, selRange.focusOffset)) return;
|
|
9234
|
+
let domSel = view.domSelection(), mouse = view.input.mouseSelecting;
|
|
9235
|
+
if (mouse && mouse.affinity && anchor == head && mouse.pos == anchor) {
|
|
9236
|
+
let { affinity } = mouse;
|
|
9237
|
+
let { node, offset } = headDOM, targetNode, targetOffset = 0;
|
|
9238
|
+
if (isText(node) && (affinity > 0 ? offset < nodeSize(node) : offset > 0)) {
|
|
9239
|
+
targetNode = node;
|
|
9240
|
+
targetOffset = offset + affinity;
|
|
9241
|
+
} else {
|
|
9242
|
+
targetNode = (affinity > 0 ? textNodeAfter : textNodeBefore)(node, offset);
|
|
9243
|
+
if (targetNode) targetOffset = affinity > 0 ? 1 : targetNode.nodeValue.length - 1;
|
|
9244
|
+
}
|
|
9245
|
+
if (targetNode) {
|
|
9246
|
+
domSel.collapse(targetNode, targetOffset);
|
|
9247
|
+
domSel.modify("move", affinity > 0 ? "backward" : "forward", "lineboundary");
|
|
9248
|
+
let { focusNode, focusOffset } = domSel;
|
|
9249
|
+
if (safari && view.root.nodeType == 11) {
|
|
9250
|
+
let ranges = domSel.getComposedRanges({ shadowRoots: [view.root] });
|
|
9251
|
+
if (ranges.length) {
|
|
9252
|
+
focusNode = ranges[0].startContainer;
|
|
9253
|
+
focusOffset = ranges[0].startOffset;
|
|
9254
|
+
}
|
|
9255
|
+
}
|
|
9256
|
+
if (isEquivalentPosition(node, offset, focusNode, focusOffset)) return;
|
|
9257
|
+
}
|
|
9258
|
+
}
|
|
9259
|
+
writeSelection(domSel, {
|
|
9260
|
+
focusNode: headDOM.node,
|
|
9261
|
+
focusOffset: headDOM.offset,
|
|
9262
|
+
anchorNode: anchorDOM.node,
|
|
9263
|
+
anchorOffset: anchorDOM.offset
|
|
9264
|
+
});
|
|
9265
|
+
}
|
|
9266
|
+
var brokenSelectBetweenUneditable = safari || chrome && chrome_version < 63;
|
|
9267
|
+
function temporarilyEditableNear(view, pos) {
|
|
9268
|
+
let { node, offset } = view.docView.domFromPos(pos, 0);
|
|
9269
|
+
let after = offset < node.childNodes.length ? node.childNodes[offset] : null;
|
|
9270
|
+
let before = offset ? node.childNodes[offset - 1] : null;
|
|
9271
|
+
if (safari && after && after.contentEditable == "false") return setEditable(after);
|
|
9272
|
+
if ((!after || after.contentEditable == "false") && (!before || before.contentEditable == "false")) {
|
|
9273
|
+
if (after) return setEditable(after);
|
|
9274
|
+
else if (before) return setEditable(before);
|
|
9275
|
+
}
|
|
9276
|
+
}
|
|
9277
|
+
function setEditable(element) {
|
|
9278
|
+
element.contentEditable = "true";
|
|
9279
|
+
if (safari && element.draggable) {
|
|
9280
|
+
element.draggable = false;
|
|
9281
|
+
element.wasDraggable = true;
|
|
9282
|
+
}
|
|
9283
|
+
return element;
|
|
9284
|
+
}
|
|
9285
|
+
function resetEditable(element) {
|
|
9286
|
+
element.contentEditable = "false";
|
|
9287
|
+
if (element.wasDraggable) {
|
|
9288
|
+
element.draggable = true;
|
|
9289
|
+
element.wasDraggable = null;
|
|
9290
|
+
}
|
|
9291
|
+
}
|
|
9292
|
+
function removeClassOnSelectionChange(view) {
|
|
9293
|
+
let doc = view.dom.ownerDocument;
|
|
9294
|
+
doc.removeEventListener("selectionchange", view.input.hideSelectionGuard);
|
|
9295
|
+
let domSel = view.domSel.readRange();
|
|
9296
|
+
let node = domSel.anchorNode, offset = domSel.anchorOffset;
|
|
9297
|
+
doc.addEventListener("selectionchange", view.input.hideSelectionGuard = () => {
|
|
9298
|
+
if (domSel.anchorNode != node || domSel.anchorOffset != offset) {
|
|
9299
|
+
doc.removeEventListener("selectionchange", view.input.hideSelectionGuard);
|
|
9300
|
+
setTimeout(() => {
|
|
9301
|
+
if (!editorOwnsSelection(view) || view.state.selection.visible) view.dom.classList.remove("ProseMirror-hideselection");
|
|
9302
|
+
}, 20);
|
|
9303
|
+
}
|
|
9304
|
+
});
|
|
9305
|
+
}
|
|
9306
|
+
function selectCursorWrapper(view) {
|
|
9307
|
+
let domSel = view.domSelection();
|
|
9308
|
+
if (!domSel) return;
|
|
9309
|
+
let node = view.cursorWrapper.dom;
|
|
9310
|
+
if (node.nodeName == "IMG") domSel.collapse(node.parentNode, domIndex(node) + 1);
|
|
9311
|
+
else domSel.collapse(node, 0);
|
|
9312
|
+
}
|
|
9313
|
+
function syncNodeSelection(view, sel) {
|
|
9314
|
+
if (sel instanceof NodeSelection) {
|
|
9315
|
+
let desc = view.docView.descAt(sel.from);
|
|
9316
|
+
if (desc != view.lastSelectedViewDesc) {
|
|
9317
|
+
clearNodeSelection(view);
|
|
9318
|
+
if (desc) desc.selectNode();
|
|
9319
|
+
view.lastSelectedViewDesc = desc;
|
|
9320
|
+
}
|
|
9321
|
+
} else clearNodeSelection(view);
|
|
9322
|
+
}
|
|
9323
|
+
function clearNodeSelection(view) {
|
|
9324
|
+
if (view.lastSelectedViewDesc) {
|
|
9325
|
+
if (view.lastSelectedViewDesc.parent) view.lastSelectedViewDesc.deselectNode();
|
|
9326
|
+
view.lastSelectedViewDesc = void 0;
|
|
9327
|
+
}
|
|
9328
|
+
}
|
|
9329
|
+
function selectionBetween(view, $anchor, $head, bias) {
|
|
9330
|
+
let sel = view.someProp("createSelectionBetween", (f) => f(view, $anchor, $head)) || TextSelection.between($anchor, $head, bias);
|
|
9331
|
+
view.someProp("adjustSelectionFromDOM", (f) => {
|
|
9332
|
+
sel = f(view, sel);
|
|
9333
|
+
});
|
|
9334
|
+
return sel;
|
|
9335
|
+
}
|
|
9336
|
+
function hasFocusAndSelection(view) {
|
|
9337
|
+
if (view.editable && !view.hasFocus()) return null;
|
|
9338
|
+
let sel = view.domSel.readRange();
|
|
9339
|
+
return sel && hasSelection(view, sel) ? sel : null;
|
|
9340
|
+
}
|
|
9341
|
+
function hasSelection(view, sel) {
|
|
9342
|
+
if (!sel.anchorNode) return false;
|
|
9343
|
+
try {
|
|
9344
|
+
return contains(view.dom, sel.anchorNode) && (view.editable || contains(view.dom, sel.focusNode));
|
|
9345
|
+
} catch (_) {
|
|
9346
|
+
return false;
|
|
9347
|
+
}
|
|
9348
|
+
}
|
|
9349
|
+
var handlers = {};
|
|
9350
|
+
var editHandlers = {};
|
|
9351
|
+
var passiveHandlers = {
|
|
9352
|
+
touchstart: true,
|
|
9353
|
+
touchmove: true
|
|
9354
|
+
};
|
|
9355
|
+
var InputState = class {
|
|
9356
|
+
constructor() {
|
|
9357
|
+
this.shiftKey = false;
|
|
9358
|
+
this.mouseDown = null;
|
|
9359
|
+
this.lastKeyCode = null;
|
|
9360
|
+
this.lastKeyCodeTime = 0;
|
|
9361
|
+
this.lastKeyDispatched = false;
|
|
9362
|
+
this.lastClick = {
|
|
9363
|
+
time: 0,
|
|
9364
|
+
x: 0,
|
|
9365
|
+
y: 0,
|
|
9366
|
+
type: "",
|
|
9367
|
+
button: 0
|
|
9368
|
+
};
|
|
9369
|
+
this.lastSelectionOrigin = null;
|
|
9370
|
+
this.lastSelectionTime = 0;
|
|
9371
|
+
this.lastIOSEnter = 0;
|
|
9372
|
+
this.lastIOSEnterFallbackTimeout = -1;
|
|
9373
|
+
this.lastFocus = 0;
|
|
9374
|
+
this.lastTouch = 0;
|
|
9375
|
+
this.lastChromeDelete = 0;
|
|
9376
|
+
this.composing = false;
|
|
9377
|
+
this.compositionNode = null;
|
|
9378
|
+
this.composingTimeout = -1;
|
|
9379
|
+
this.compositionNodes = [];
|
|
9380
|
+
this.compositionEndedAt = -2e8;
|
|
9381
|
+
this.compositionID = 1;
|
|
9382
|
+
this.mouseSelecting = null;
|
|
9383
|
+
this.badSafariComposition = false;
|
|
9384
|
+
this.compositionPendingChanges = 0;
|
|
9385
|
+
this.domChangeCount = 0;
|
|
9386
|
+
this.eventHandlers = Object.create(null);
|
|
9387
|
+
this.hideSelectionGuard = null;
|
|
9388
|
+
}
|
|
9389
|
+
};
|
|
9390
|
+
function initInput(view) {
|
|
9391
|
+
for (let event in handlers) {
|
|
9392
|
+
let handler = handlers[event];
|
|
9393
|
+
view.dom.addEventListener(event, view.input.eventHandlers[event] = (event) => {
|
|
9394
|
+
if (!eventBelongsToView(view, event)) return;
|
|
9395
|
+
if (view.input.composing && (event.type == "keydown" || event.type == "beforeinput") && event.isComposing === false) leaveComposition(view, true);
|
|
9396
|
+
if (!runCustomHandler(view, event) && (view.editable || !(event.type in editHandlers))) handler(view, event);
|
|
9397
|
+
}, passiveHandlers[event] ? { passive: true } : void 0);
|
|
9398
|
+
}
|
|
9399
|
+
if (safari) view.dom.addEventListener("input", () => null);
|
|
9400
|
+
ensureListeners(view);
|
|
9401
|
+
}
|
|
9402
|
+
function setSelectionOrigin(view, origin) {
|
|
9403
|
+
view.input.lastSelectionOrigin = origin;
|
|
9404
|
+
view.input.lastSelectionTime = Date.now();
|
|
9405
|
+
}
|
|
9285
9406
|
function destroyInput(view) {
|
|
9286
9407
|
if (view.input.mouseDown) view.input.mouseDown.done();
|
|
9287
9408
|
view.domObserver.stop();
|
|
@@ -9319,12 +9440,10 @@ function dispatchKey(view, event) {
|
|
|
9319
9440
|
editHandlers.keydown = (view, _event) => {
|
|
9320
9441
|
let event = _event;
|
|
9321
9442
|
view.input.shiftKey = event.keyCode == 16 || event.shiftKey;
|
|
9322
|
-
if (inOrNearComposition(view)) return;
|
|
9323
9443
|
view.input.lastKeyCode = event.keyCode;
|
|
9324
9444
|
view.input.lastKeyCodeTime = Date.now();
|
|
9325
9445
|
view.input.lastKeyDispatched = false;
|
|
9326
9446
|
if (android && chrome && event.keyCode == 13) return;
|
|
9327
|
-
if (event.keyCode != 229) view.domObserver.forceFlush();
|
|
9328
9447
|
if (ios && event.keyCode == 13 && !event.ctrlKey && !event.altKey && !event.metaKey) {
|
|
9329
9448
|
let now = Date.now();
|
|
9330
9449
|
view.input.lastIOSEnter = now;
|
|
@@ -9334,7 +9453,10 @@ editHandlers.keydown = (view, _event) => {
|
|
|
9334
9453
|
view.input.lastIOSEnter = 0;
|
|
9335
9454
|
}
|
|
9336
9455
|
}, 200);
|
|
9337
|
-
|
|
9456
|
+
return;
|
|
9457
|
+
}
|
|
9458
|
+
if (event.keyCode != 229) view.domObserver.forceFlush(true);
|
|
9459
|
+
if (dispatchKey(view, event) || captureKeyDown(view, event)) event.preventDefault();
|
|
9338
9460
|
else setSelectionOrigin(view, "key");
|
|
9339
9461
|
};
|
|
9340
9462
|
editHandlers.keyup = (view, event) => {
|
|
@@ -9412,18 +9534,9 @@ function handleDoubleClick(view, pos, inside, event) {
|
|
|
9412
9534
|
return runHandlerOnContext(view, "handleDoubleClickOn", pos, inside, event) || view.someProp("handleDoubleClick", (f) => f(view, pos, event));
|
|
9413
9535
|
}
|
|
9414
9536
|
function handleTripleClick$1(view, pos, inside, event) {
|
|
9415
|
-
return runHandlerOnContext(view, "handleTripleClickOn", pos, inside, event) || view.someProp("handleTripleClick", (f) => f(view, pos, event))
|
|
9416
|
-
}
|
|
9417
|
-
function defaultTripleClick(view, inside, event) {
|
|
9418
|
-
if (event.button != 0) return false;
|
|
9419
|
-
let selection = selectionForTripleClick(view, inside, true), doc = view.state.doc;
|
|
9420
|
-
if (!selection) return false;
|
|
9421
|
-
updateSelection(view, selection);
|
|
9422
|
-
if (selection instanceof TextSelection && doc.eq(view.state.doc)) view.input.mouseDown = new TripleClickDrag(view, selection);
|
|
9423
|
-
return true;
|
|
9537
|
+
return runHandlerOnContext(view, "handleTripleClickOn", pos, inside, event) || view.someProp("handleTripleClick", (f) => f(view, pos, event));
|
|
9424
9538
|
}
|
|
9425
|
-
function selectionForTripleClick(
|
|
9426
|
-
let doc = view.state.doc;
|
|
9539
|
+
function selectionForTripleClick(doc, inside, selectNodes) {
|
|
9427
9540
|
if (inside == -1) return doc.inlineContent ? TextSelection.create(doc, 0, doc.content.size) : null;
|
|
9428
9541
|
let $pos = doc.resolve(inside);
|
|
9429
9542
|
for (let i = $pos.depth + 1; i > 0; i--) {
|
|
@@ -9434,15 +9547,67 @@ function selectionForTripleClick(view, inside, selectNodes) {
|
|
|
9434
9547
|
}
|
|
9435
9548
|
return null;
|
|
9436
9549
|
}
|
|
9437
|
-
|
|
9438
|
-
|
|
9550
|
+
var wordRE = /[\w_\u00a1-\uffff]+/g;
|
|
9551
|
+
try {
|
|
9552
|
+
wordRE = /* @__PURE__ */ new RegExp("[\\p{L}\\p{N}_]+", "gu");
|
|
9553
|
+
} catch (_a) {}
|
|
9554
|
+
function getWordAt(doc, pos) {
|
|
9555
|
+
let $pos = doc.resolve(pos), parent = $pos.node();
|
|
9556
|
+
let context = "", from = pos, to = pos;
|
|
9557
|
+
for (let i = $pos.indexAfter(), sawNonWS = false; i > 0; i--) {
|
|
9558
|
+
let prev = parent.child(i - 1);
|
|
9559
|
+
if (!prev.text) break;
|
|
9560
|
+
let end = from == pos ? pos - $pos.posAtIndex(i - 1) : prev.text.length, start = end;
|
|
9561
|
+
for (; start > 0; start--) if (/\S/.test(prev.text[start - 1])) sawNonWS = true;
|
|
9562
|
+
else if (sawNonWS) break;
|
|
9563
|
+
context = prev.text.slice(start, end) + context;
|
|
9564
|
+
from -= end - start;
|
|
9565
|
+
if (start || from < pos - 50) break;
|
|
9566
|
+
}
|
|
9567
|
+
for (let i = $pos.index(), sawNonWS = false; i < parent.childCount; i++) {
|
|
9568
|
+
let next = parent.child(i);
|
|
9569
|
+
if (!next.text) break;
|
|
9570
|
+
let start = to == pos ? pos - $pos.posAtIndex(i) : 0, end = start;
|
|
9571
|
+
for (; end < next.text.length; end++) if (/\S/.test(next.text[end])) sawNonWS = true;
|
|
9572
|
+
else if (sawNonWS) break;
|
|
9573
|
+
context += next.text.slice(start, end);
|
|
9574
|
+
to += end - start;
|
|
9575
|
+
if (end < next.text.length || to > pos + 50) break;
|
|
9576
|
+
}
|
|
9577
|
+
let lastBefore = from, firstAfter = to;
|
|
9578
|
+
if (Intl.Segmenter) {
|
|
9579
|
+
for (let segment of new Intl.Segmenter(void 0, { granularity: "word" }).segment(context)) if (segment.isWordLike) {
|
|
9580
|
+
let start = segment.index + from, end = start + segment.segment.length;
|
|
9581
|
+
if (end < pos) lastBefore = end;
|
|
9582
|
+
else if (start > pos) {
|
|
9583
|
+
firstAfter = start;
|
|
9584
|
+
break;
|
|
9585
|
+
} else return TextSelection.create(doc, start, end);
|
|
9586
|
+
}
|
|
9587
|
+
} else {
|
|
9588
|
+
wordRE.lastIndex = 0;
|
|
9589
|
+
for (let m; m = wordRE.exec(context);) {
|
|
9590
|
+
let start = m.index + from, end = start + m[0].length;
|
|
9591
|
+
if (end < pos) lastBefore = end;
|
|
9592
|
+
else if (start > pos) {
|
|
9593
|
+
firstAfter = start;
|
|
9594
|
+
break;
|
|
9595
|
+
} else return TextSelection.create(doc, start, end);
|
|
9596
|
+
}
|
|
9597
|
+
}
|
|
9598
|
+
let before = context.slice(lastBefore - from, pos - from), after = context.slice(pos - from, firstAfter - from);
|
|
9599
|
+
let nonSpaceBefore = /\S*$/.exec(before)[0].length, nonSpaceAfter = /^\S*/.exec(after)[0].length;
|
|
9600
|
+
if (nonSpaceBefore || nonSpaceAfter) return TextSelection.create(doc, pos - nonSpaceBefore, pos + nonSpaceAfter);
|
|
9601
|
+
let spaceBefore = /\s*$/.exec(before)[0].length, spaceAfter = /^\s*/.exec(after)[0].length;
|
|
9602
|
+
return TextSelection.create(doc, pos - spaceBefore, pos + spaceAfter);
|
|
9439
9603
|
}
|
|
9440
9604
|
var selectNodeModifier = mac$2 ? "metaKey" : "ctrlKey";
|
|
9441
9605
|
handlers.mousedown = (view, _event) => {
|
|
9442
|
-
let event = _event;
|
|
9606
|
+
let event = _event, now = Date.now();
|
|
9443
9607
|
view.input.shiftKey = event.shiftKey;
|
|
9444
|
-
|
|
9445
|
-
|
|
9608
|
+
if (view.input.lastTouch > now - 500) return false;
|
|
9609
|
+
endComposition(view);
|
|
9610
|
+
let type = "singleClick";
|
|
9446
9611
|
if (now - view.input.lastClick.time < 500 && isNear(event, view.input.lastClick) && !event[selectNodeModifier] && view.input.lastClick.button == event.button) {
|
|
9447
9612
|
if (view.input.lastClick.type == "singleClick") type = "doubleClick";
|
|
9448
9613
|
else if (view.input.lastClick.type == "doubleClick") type = "tripleClick";
|
|
@@ -9457,141 +9622,183 @@ handlers.mousedown = (view, _event) => {
|
|
|
9457
9622
|
if (view.input.mouseDown) view.input.mouseDown.done();
|
|
9458
9623
|
let pos = view.posAtCoords(eventCoords(event));
|
|
9459
9624
|
if (!pos) return;
|
|
9460
|
-
if (
|
|
9461
|
-
|
|
9462
|
-
|
|
9625
|
+
if (event.button == 0) {
|
|
9626
|
+
if (!view.hasFocus()) {
|
|
9627
|
+
focusPreventScroll(view.dom);
|
|
9628
|
+
let active = view.root.activeElement;
|
|
9629
|
+
if (active && !active.contains(view.dom)) active.blur();
|
|
9630
|
+
}
|
|
9631
|
+
if (!(view.input.mouseDown = new MouseDown(view, pos, event, type)).mightDrag) event.preventDefault();
|
|
9632
|
+
} else setSelectionOrigin(view, "pointer");
|
|
9463
9633
|
};
|
|
9464
9634
|
var MouseDown = class {
|
|
9465
|
-
constructor(view) {
|
|
9635
|
+
constructor(view, startPos, event, type) {
|
|
9636
|
+
var _a;
|
|
9466
9637
|
this.view = view;
|
|
9467
|
-
this.
|
|
9468
|
-
view.root.addEventListener("mouseup", this.up = this.up.bind(this));
|
|
9469
|
-
view.root.addEventListener("mousemove", this.move = this.move.bind(this));
|
|
9470
|
-
}
|
|
9471
|
-
up(event) {
|
|
9472
|
-
this.done();
|
|
9473
|
-
}
|
|
9474
|
-
move(event) {
|
|
9475
|
-
if (event.buttons == 0) this.done();
|
|
9476
|
-
}
|
|
9477
|
-
done() {
|
|
9478
|
-
this.view.root.removeEventListener("mouseup", this.up);
|
|
9479
|
-
this.view.root.removeEventListener("mousemove", this.move);
|
|
9480
|
-
if (this.view.input.mouseDown == this) this.view.input.mouseDown = null;
|
|
9481
|
-
}
|
|
9482
|
-
delaySelUpdate() {
|
|
9483
|
-
return false;
|
|
9484
|
-
}
|
|
9485
|
-
};
|
|
9486
|
-
var LeftMouseDown = class extends MouseDown {
|
|
9487
|
-
constructor(view, pos, event, flushed) {
|
|
9488
|
-
super(view);
|
|
9489
|
-
this.pos = pos;
|
|
9638
|
+
this.startPos = startPos;
|
|
9490
9639
|
this.event = event;
|
|
9491
|
-
this.
|
|
9492
|
-
this.
|
|
9640
|
+
this.type = type;
|
|
9641
|
+
this.didMove = false;
|
|
9642
|
+
this.lastPos = -1;
|
|
9643
|
+
this.anchorRange = null;
|
|
9493
9644
|
this.startDoc = view.state.doc;
|
|
9494
9645
|
this.selectNode = !!event[selectNodeModifier];
|
|
9495
|
-
this.
|
|
9496
|
-
|
|
9497
|
-
|
|
9498
|
-
|
|
9499
|
-
|
|
9500
|
-
|
|
9501
|
-
|
|
9502
|
-
|
|
9503
|
-
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
|
|
9509
|
-
|
|
9510
|
-
|
|
9511
|
-
|
|
9512
|
-
|
|
9513
|
-
|
|
9646
|
+
this.extend = event.shiftKey;
|
|
9647
|
+
this.anchorDoc = this.startDoc;
|
|
9648
|
+
let startBase = docBase(view);
|
|
9649
|
+
if (this.extend) {
|
|
9650
|
+
let sel = view.state.selection;
|
|
9651
|
+
this.anchorRange = sel instanceof NodeSelection ? {
|
|
9652
|
+
from: sel.from,
|
|
9653
|
+
to: sel.to
|
|
9654
|
+
} : {
|
|
9655
|
+
from: sel.anchor,
|
|
9656
|
+
to: sel.anchor
|
|
9657
|
+
};
|
|
9658
|
+
let rect = sel instanceof NodeSelection ? view.nodeDOM(sel.from).getBoundingClientRect() : view.coordsAtPos(sel.anchor);
|
|
9659
|
+
this.anchorOffset = {
|
|
9660
|
+
x: (rect.left + rect.right) / 2 - startBase.x,
|
|
9661
|
+
y: (rect.top + rect.bottom) / 2 - startBase.y
|
|
9662
|
+
};
|
|
9663
|
+
} else this.anchorOffset = {
|
|
9664
|
+
x: event.clientX - startBase.x,
|
|
9665
|
+
y: event.clientY - startBase.y
|
|
9514
9666
|
};
|
|
9515
|
-
if (
|
|
9516
|
-
|
|
9517
|
-
|
|
9518
|
-
if (
|
|
9519
|
-
|
|
9520
|
-
|
|
9521
|
-
|
|
9522
|
-
|
|
9523
|
-
|
|
9667
|
+
if (type == "singleClick") {
|
|
9668
|
+
let { selection } = view.state;
|
|
9669
|
+
let targetNode, targetPos, targetSelected = false;
|
|
9670
|
+
if (selection instanceof NodeSelection && selection.from <= startPos.pos && selection.to >= startPos.pos) {
|
|
9671
|
+
targetPos = selection.from;
|
|
9672
|
+
targetNode = selection.node;
|
|
9673
|
+
targetSelected = true;
|
|
9674
|
+
} else if (startPos.inside > -1) {
|
|
9675
|
+
targetNode = view.state.doc.nodeAt(startPos.inside);
|
|
9676
|
+
targetPos = startPos.inside;
|
|
9677
|
+
} else {
|
|
9678
|
+
let $pos = view.state.doc.resolve(startPos.pos);
|
|
9679
|
+
targetNode = $pos.parent;
|
|
9680
|
+
targetPos = $pos.depth ? $pos.before() : -1;
|
|
9681
|
+
}
|
|
9682
|
+
if (targetSelected || targetPos > -1 && targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false) {
|
|
9683
|
+
let elt = (_a = view.docView.descAt(targetPos)) === null || _a === void 0 ? void 0 : _a.nodeDOM;
|
|
9684
|
+
this.mightDrag = {
|
|
9685
|
+
node: targetNode,
|
|
9686
|
+
elt,
|
|
9687
|
+
pos: targetPos,
|
|
9688
|
+
addAttr: false
|
|
9689
|
+
};
|
|
9690
|
+
if (elt && !elt.draggable) {
|
|
9691
|
+
this.mightDrag.addAttr = true;
|
|
9692
|
+
view.domObserver.stopped(() => elt.draggable = true);
|
|
9693
|
+
}
|
|
9694
|
+
} else this.mightDrag = isInSelection(view, event);
|
|
9695
|
+
} else this.mightDrag = false;
|
|
9696
|
+
view.root.addEventListener("mouseup", this.up = this.up.bind(this));
|
|
9697
|
+
view.root.addEventListener("mousemove", this.move = this.move.bind(this));
|
|
9698
|
+
if (!this.mightDrag) this.select(this.startPos, true);
|
|
9524
9699
|
}
|
|
9525
9700
|
done() {
|
|
9526
|
-
|
|
9527
|
-
|
|
9528
|
-
|
|
9529
|
-
|
|
9530
|
-
|
|
9531
|
-
|
|
9532
|
-
|
|
9533
|
-
if (this.delayedSelectionSync) setTimeout(() => {
|
|
9534
|
-
if (!this.view.isDestroyed) selectionToDOM(this.view);
|
|
9535
|
-
});
|
|
9701
|
+
this.view.root.removeEventListener("mouseup", this.up);
|
|
9702
|
+
this.view.root.removeEventListener("mousemove", this.move);
|
|
9703
|
+
if (this.view.input.mouseDown == this) this.view.input.mouseDown = null;
|
|
9704
|
+
if (typeof this.mightDrag == "object" && this.mightDrag.addAttr) this.view.domObserver.stopped(() => this.mightDrag.elt.removeAttribute("draggable"));
|
|
9705
|
+
}
|
|
9706
|
+
maybeRunHandler(pos, event) {
|
|
9707
|
+
return (this.type == "singleClick" ? handleSingleClick : this.type == "doubleClick" ? handleDoubleClick : handleTripleClick$1)(this.view, pos.pos, pos.inside, event, this.selectNode);
|
|
9536
9708
|
}
|
|
9537
9709
|
up(event) {
|
|
9538
9710
|
this.done();
|
|
9539
9711
|
if (!this.view.dom.contains(event.target)) return;
|
|
9540
|
-
let pos = this.
|
|
9712
|
+
let pos = this.startPos;
|
|
9541
9713
|
if (this.view.state.doc != this.startDoc) pos = this.view.posAtCoords(eventCoords(event));
|
|
9542
|
-
|
|
9543
|
-
if (this.
|
|
9544
|
-
|
|
9545
|
-
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)) {
|
|
9546
|
-
updateSelection(this.view, Selection$1.near(this.view.state.doc.resolve(pos.pos)));
|
|
9547
|
-
event.preventDefault();
|
|
9548
|
-
} else setSelectionOrigin(this.view, "pointer");
|
|
9549
|
-
}
|
|
9550
|
-
move(event) {
|
|
9551
|
-
this.updateAllowDefault(event);
|
|
9552
|
-
setSelectionOrigin(this.view, "pointer");
|
|
9553
|
-
super.move(event);
|
|
9554
|
-
}
|
|
9555
|
-
updateAllowDefault(event) {
|
|
9556
|
-
if (!this.allowDefault && (Math.abs(this.event.x - event.clientX) > 4 || Math.abs(this.event.y - event.clientY) > 4)) this.allowDefault = true;
|
|
9557
|
-
}
|
|
9558
|
-
delaySelUpdate() {
|
|
9559
|
-
if (!this.allowDefault) return false;
|
|
9560
|
-
this.delayedSelectionSync = true;
|
|
9561
|
-
return true;
|
|
9562
|
-
}
|
|
9563
|
-
};
|
|
9564
|
-
var TripleClickDrag = class extends MouseDown {
|
|
9565
|
-
constructor(view, startSelection) {
|
|
9566
|
-
super(view);
|
|
9567
|
-
this.startSelection = startSelection;
|
|
9568
|
-
this.startDoc = view.state.doc;
|
|
9714
|
+
if (!pos) return;
|
|
9715
|
+
if (!this.didMove) this.maybeRunHandler(pos, event) || this.select(pos, true);
|
|
9716
|
+
event.preventDefault();
|
|
9569
9717
|
}
|
|
9570
9718
|
move(event) {
|
|
9571
|
-
if (event.buttons == 0
|
|
9719
|
+
if (event.buttons == 0) {
|
|
9572
9720
|
this.done();
|
|
9573
9721
|
return;
|
|
9574
9722
|
}
|
|
9723
|
+
if (!this.didMove && (Math.abs(this.event.x - event.clientX) > 8 || Math.abs(this.event.y - event.clientY) > 8)) {
|
|
9724
|
+
this.didMove = true;
|
|
9725
|
+
this.mightDrag = false;
|
|
9726
|
+
}
|
|
9727
|
+
if (!this.mightDrag) {
|
|
9728
|
+
let pos = this.view.posAtCoords(eventCoords(event));
|
|
9729
|
+
if (pos) this.select(pos, false);
|
|
9730
|
+
}
|
|
9575
9731
|
event.preventDefault();
|
|
9576
|
-
|
|
9577
|
-
|
|
9578
|
-
|
|
9579
|
-
|
|
9580
|
-
let {
|
|
9581
|
-
let
|
|
9582
|
-
|
|
9732
|
+
}
|
|
9733
|
+
select(pos, first) {
|
|
9734
|
+
if (pos.pos == this.lastPos) return;
|
|
9735
|
+
this.lastPos = pos.pos;
|
|
9736
|
+
let { view } = this, { doc } = view.state;
|
|
9737
|
+
let selection = this.type == "singleClick" ? clickedRange(view, doc, pos) : this.type == "doubleClick" ? getWordAt(doc, pos.pos) : selectionForTripleClick(doc, pos.inside, first);
|
|
9738
|
+
if (!selection) return;
|
|
9739
|
+
if (first && !this.extend) this.anchorRange = selection;
|
|
9740
|
+
else if (!first || this.extend) {
|
|
9741
|
+
if (!doc.eq(this.anchorDoc)) this.restoreAnchor();
|
|
9742
|
+
if (this.anchorRange && this.anchorRange.from < selection.from) selection = selectionBetween(view, doc.resolve(this.anchorRange.from), doc.resolve(selection.to));
|
|
9743
|
+
else if (this.anchorRange && this.anchorRange.to > selection.to) selection = selectionBetween(view, doc.resolve(this.anchorRange.to), doc.resolve(selection.from));
|
|
9744
|
+
}
|
|
9745
|
+
if (!selection.eq(view.state.selection)) {
|
|
9746
|
+
view.input.mouseSelecting = pos;
|
|
9747
|
+
view.dispatch(view.state.tr.setSelection(selection).setMeta("pointer", true).scrollIntoView());
|
|
9748
|
+
view.input.mouseSelecting = null;
|
|
9749
|
+
}
|
|
9750
|
+
}
|
|
9751
|
+
restoreAnchor() {
|
|
9752
|
+
let base = docBase(this.view);
|
|
9753
|
+
let pos = this.view.posAtCoords({
|
|
9754
|
+
left: this.anchorOffset.x + base.x,
|
|
9755
|
+
top: this.anchorOffset.y + base.y
|
|
9756
|
+
});
|
|
9757
|
+
if (!pos) this.anchorRange = null;
|
|
9758
|
+
else {
|
|
9759
|
+
let { doc } = this.view.state;
|
|
9760
|
+
this.anchorRange = this.type == "singleClick" ? clickedRange(this.view, doc, pos) : this.type == "doubleClick" ? getWordAt(doc, pos.pos) : selectionForTripleClick(doc, pos.inside, false);
|
|
9761
|
+
this.anchorDoc = this.view.state.doc;
|
|
9762
|
+
}
|
|
9583
9763
|
}
|
|
9584
9764
|
};
|
|
9765
|
+
function docBase(view) {
|
|
9766
|
+
let rect = view.dom.getBoundingClientRect();
|
|
9767
|
+
return {
|
|
9768
|
+
x: rect.left - view.dom.scrollLeft,
|
|
9769
|
+
y: rect.top - view.dom.scrollTop
|
|
9770
|
+
};
|
|
9771
|
+
}
|
|
9772
|
+
function clickedRange(view, doc, pos) {
|
|
9773
|
+
if (pos.inside > -1) {
|
|
9774
|
+
let target = doc.nodeAt(pos.inside);
|
|
9775
|
+
if (target.isAtom && NodeSelection.isSelectable(target)) return NodeSelection.create(doc, pos.inside);
|
|
9776
|
+
}
|
|
9777
|
+
let $pos = doc.resolve(pos.pos);
|
|
9778
|
+
return selectionBetween(view, $pos, $pos);
|
|
9779
|
+
}
|
|
9780
|
+
function isInSelection(view, event) {
|
|
9781
|
+
let { selection } = view.state;
|
|
9782
|
+
if (selection.empty) return false;
|
|
9783
|
+
let sel = view.domSelection();
|
|
9784
|
+
if (!sel || sel.rangeCount == 0) return true;
|
|
9785
|
+
let rects = sel.getRangeAt(0).getClientRects();
|
|
9786
|
+
for (let i = 0; i < rects.length; i++) {
|
|
9787
|
+
let rect = rects[i];
|
|
9788
|
+
if (rect.left <= event.clientX && rect.right >= event.clientX && rect.top <= event.clientY && rect.bottom >= event.clientY) return true;
|
|
9789
|
+
}
|
|
9790
|
+
return false;
|
|
9791
|
+
}
|
|
9585
9792
|
handlers.touchstart = (view) => {
|
|
9586
9793
|
view.input.lastTouch = Date.now();
|
|
9587
|
-
|
|
9794
|
+
endComposition(view);
|
|
9588
9795
|
setSelectionOrigin(view, "pointer");
|
|
9589
9796
|
};
|
|
9590
9797
|
handlers.touchmove = (view) => {
|
|
9591
9798
|
view.input.lastTouch = Date.now();
|
|
9592
9799
|
setSelectionOrigin(view, "pointer");
|
|
9593
9800
|
};
|
|
9594
|
-
handlers.contextmenu = (view) =>
|
|
9801
|
+
handlers.contextmenu = (view) => endComposition(view);
|
|
9595
9802
|
function inOrNearComposition(view, event) {
|
|
9596
9803
|
if (view.composing) return true;
|
|
9597
9804
|
if (safari && Math.abs(Date.now() - view.input.compositionEndedAt) < 500) {
|
|
@@ -9611,19 +9818,16 @@ editHandlers.compositionstart = editHandlers.compositionupdate = (view) => {
|
|
|
9611
9818
|
view.markCursor = null;
|
|
9612
9819
|
} else {
|
|
9613
9820
|
endComposition(view, !state.selection.empty);
|
|
9614
|
-
if (gecko && state.selection.empty && $pos.parentOffset && !$pos.textOffset && $pos.nodeBefore.marks.length) {
|
|
9615
|
-
let
|
|
9616
|
-
|
|
9617
|
-
|
|
9618
|
-
|
|
9619
|
-
if (
|
|
9620
|
-
|
|
9621
|
-
|
|
9622
|
-
|
|
9623
|
-
|
|
9624
|
-
node = before;
|
|
9625
|
-
offset = -1;
|
|
9626
|
-
}
|
|
9821
|
+
if (gecko && view.domSel.active && state.selection.empty && $pos.parentOffset && !$pos.textOffset && $pos.nodeBefore.marks.length) for (let { focusNode: node, focusOffset: offset } = view.domSel.range; node && isElt(node) && offset != 0;) {
|
|
9822
|
+
let before = offset < 0 ? node.lastChild : node.childNodes[offset - 1];
|
|
9823
|
+
if (!before) break;
|
|
9824
|
+
if (isText(before)) {
|
|
9825
|
+
let sel = view.domSelection();
|
|
9826
|
+
if (sel) sel.collapse(before, before.nodeValue.length);
|
|
9827
|
+
break;
|
|
9828
|
+
} else {
|
|
9829
|
+
node = before;
|
|
9830
|
+
offset = -1;
|
|
9627
9831
|
}
|
|
9628
9832
|
}
|
|
9629
9833
|
}
|
|
@@ -9632,23 +9836,25 @@ editHandlers.compositionstart = editHandlers.compositionupdate = (view) => {
|
|
|
9632
9836
|
scheduleComposeEnd(view, timeoutComposition);
|
|
9633
9837
|
};
|
|
9634
9838
|
function selectionBeforeUneditable(view) {
|
|
9635
|
-
let { focusNode, focusOffset } = view.
|
|
9839
|
+
let { focusNode, focusOffset } = view.domSel.range;
|
|
9636
9840
|
if (!focusNode || !isElt(focusNode) || focusOffset >= focusNode.childNodes.length) return false;
|
|
9637
9841
|
let next = focusNode.childNodes[focusOffset];
|
|
9638
9842
|
return isElt(next) && next.contentEditable == "false";
|
|
9639
9843
|
}
|
|
9640
9844
|
editHandlers.compositionend = (view, event) => {
|
|
9641
|
-
if (view.composing)
|
|
9642
|
-
|
|
9643
|
-
|
|
9644
|
-
|
|
9645
|
-
|
|
9646
|
-
|
|
9647
|
-
|
|
9648
|
-
|
|
9649
|
-
|
|
9650
|
-
|
|
9651
|
-
|
|
9845
|
+
if (view.composing) leaveComposition(view);
|
|
9846
|
+
};
|
|
9847
|
+
function leaveComposition(view, sync = false) {
|
|
9848
|
+
view.input.composing = false;
|
|
9849
|
+
view.input.compositionEndedAt = Date.now();
|
|
9850
|
+
view.input.compositionPendingChanges = view.domObserver.pendingRecords().length ? view.input.compositionID : 0;
|
|
9851
|
+
view.input.compositionNode = null;
|
|
9852
|
+
if (view.input.badSafariComposition) view.domObserver.forceFlush();
|
|
9853
|
+
else if (view.input.compositionPendingChanges) Promise.resolve().then(() => view.domObserver.flush());
|
|
9854
|
+
view.input.compositionID++;
|
|
9855
|
+
if (sync) endComposition(view);
|
|
9856
|
+
else scheduleComposeEnd(view, 20);
|
|
9857
|
+
}
|
|
9652
9858
|
function scheduleComposeEnd(view, delay) {
|
|
9653
9859
|
clearTimeout(view.input.composingTimeout);
|
|
9654
9860
|
if (delay > -1) view.input.composingTimeout = setTimeout(() => endComposition(view), delay);
|
|
@@ -9658,13 +9864,13 @@ function clearComposition(view) {
|
|
|
9658
9864
|
view.input.composing = false;
|
|
9659
9865
|
view.input.compositionEndedAt = Date.now();
|
|
9660
9866
|
}
|
|
9661
|
-
|
|
9867
|
+
for (let node; node = view.input.compositionNodes.pop();) node.markParentDamage();
|
|
9662
9868
|
}
|
|
9663
9869
|
function findCompositionNode(view) {
|
|
9664
|
-
let sel = view.
|
|
9665
|
-
if (!sel.focusNode) return null;
|
|
9666
|
-
let textBefore = textNodeBefore
|
|
9667
|
-
let textAfter = textNodeAfter
|
|
9870
|
+
let sel = view.domSel.range;
|
|
9871
|
+
if (!view.domSel.active || !sel.focusNode) return null;
|
|
9872
|
+
let textBefore = textNodeBefore(sel.focusNode, sel.focusOffset);
|
|
9873
|
+
let textAfter = textNodeAfter(sel.focusNode, sel.focusOffset);
|
|
9668
9874
|
if (textBefore && textAfter && textBefore != textAfter) {
|
|
9669
9875
|
let descAfter = textAfter.pmViewDesc, lastChanged = view.domObserver.lastChangedTextNode;
|
|
9670
9876
|
if (textBefore == lastChanged || textAfter == lastChanged) return lastChanged;
|
|
@@ -9683,14 +9889,12 @@ function endComposition(view, restarting = false) {
|
|
|
9683
9889
|
if (android && view.domObserver.flushingSoon >= 0) return;
|
|
9684
9890
|
view.domObserver.forceFlush();
|
|
9685
9891
|
clearComposition(view);
|
|
9686
|
-
if (restarting || view.docView && view.docView.
|
|
9687
|
-
let sel = selectionFromDOM(view), cur = view.state.selection;
|
|
9892
|
+
if (restarting || view.docView && view.docView.damage) {
|
|
9893
|
+
let sel = selectionFromDOM(view, view.domSel.readRange()), cur = view.state.selection;
|
|
9688
9894
|
if (sel && !sel.eq(cur)) view.dispatch(view.state.tr.setSelection(sel));
|
|
9689
9895
|
else if ((view.markCursor || restarting) && !cur.$from.node(cur.$from.sharedDepth(cur.to)).inlineContent) view.dispatch(view.state.tr.deleteSelection());
|
|
9690
9896
|
else view.updateState(view.state);
|
|
9691
|
-
return true;
|
|
9692
9897
|
}
|
|
9693
|
-
return false;
|
|
9694
9898
|
}
|
|
9695
9899
|
function captureCopy(view, dom) {
|
|
9696
9900
|
if (!view.dom.parentNode) return;
|
|
@@ -9707,7 +9911,7 @@ function captureCopy(view, dom) {
|
|
|
9707
9911
|
view.focus();
|
|
9708
9912
|
}, 50);
|
|
9709
9913
|
}
|
|
9710
|
-
var brokenClipboardAPI =
|
|
9914
|
+
var brokenClipboardAPI = ios && webkit_version < 604;
|
|
9711
9915
|
handlers.copy = editHandlers.cut = (view, _event) => {
|
|
9712
9916
|
let event = _event;
|
|
9713
9917
|
let sel = view.state.selection, cut = event.type == "cut";
|
|
@@ -9787,7 +9991,7 @@ handlers.dragstart = (view, _event) => {
|
|
|
9787
9991
|
let pos = sel.empty ? null : view.posAtCoords(eventCoords(event));
|
|
9788
9992
|
let node;
|
|
9789
9993
|
if (pos && pos.pos >= sel.from && pos.pos <= (sel instanceof NodeSelection ? sel.to - 1 : sel.to));
|
|
9790
|
-
else if (mouseDown && mouseDown.mightDrag) node = NodeSelection.create(view.state.doc, mouseDown.mightDrag.pos);
|
|
9994
|
+
else if (mouseDown && typeof mouseDown.mightDrag == "object") node = NodeSelection.create(view.state.doc, mouseDown.mightDrag.pos);
|
|
9791
9995
|
else if (event.target && isElt(event.target)) {
|
|
9792
9996
|
let desc = view.docView.nearestDesc(event.target, true);
|
|
9793
9997
|
if (desc && desc.node.type.spec.draggable && desc != view.docView) node = NodeSelection.create(view.state.doc, desc.posBefore);
|
|
@@ -9857,16 +10061,14 @@ function handleDrop(view, event, dragging) {
|
|
|
9857
10061
|
handlers.focus = (view) => {
|
|
9858
10062
|
view.input.lastFocus = Date.now();
|
|
9859
10063
|
if (!view.focused) {
|
|
9860
|
-
view.domObserver.
|
|
9861
|
-
view.dom.classList.add("ProseMirror-focused");
|
|
9862
|
-
view.domObserver.start();
|
|
10064
|
+
view.domObserver.stopped(() => view.dom.classList.add("ProseMirror-focused"));
|
|
9863
10065
|
view.focused = true;
|
|
9864
|
-
|
|
9865
|
-
if (!view.
|
|
9866
|
-
let
|
|
10066
|
+
view.domSel.read();
|
|
10067
|
+
if (!view.domSel.synced) {
|
|
10068
|
+
let startSel = view.domSel.range;
|
|
9867
10069
|
setTimeout(() => {
|
|
9868
|
-
let
|
|
9869
|
-
if (
|
|
10070
|
+
let curSel = view.domSel.readRange();
|
|
10071
|
+
if (curSel && startSel.eq(curSel)) view.domSel.sync();
|
|
9870
10072
|
}, 20);
|
|
9871
10073
|
}
|
|
9872
10074
|
}
|
|
@@ -9874,10 +10076,8 @@ handlers.focus = (view) => {
|
|
|
9874
10076
|
handlers.blur = (view, _event) => {
|
|
9875
10077
|
let event = _event;
|
|
9876
10078
|
if (view.focused) {
|
|
9877
|
-
view.domObserver.
|
|
9878
|
-
view.dom.
|
|
9879
|
-
view.domObserver.start();
|
|
9880
|
-
if (event.relatedTarget && view.dom.contains(event.relatedTarget)) view.domObserver.currentSelection.clear();
|
|
10079
|
+
view.domObserver.stopped(() => view.dom.classList.remove("ProseMirror-focused"));
|
|
10080
|
+
if (event.relatedTarget && view.dom.contains(event.relatedTarget)) view.domSel.deactivate();
|
|
9881
10081
|
view.focused = false;
|
|
9882
10082
|
}
|
|
9883
10083
|
};
|
|
@@ -10098,11 +10298,15 @@ var DecorationSet = class DecorationSet {
|
|
|
10098
10298
|
findInner(start, end, result, offset, predicate) {
|
|
10099
10299
|
for (let i = 0; i < this.local.length; i++) {
|
|
10100
10300
|
let span = this.local[i];
|
|
10101
|
-
if (span.from
|
|
10301
|
+
if (span.from > end) break;
|
|
10302
|
+
if (span.to >= start && (!predicate || predicate(span.spec))) result.push(span.copy(span.from + offset, span.to + offset));
|
|
10102
10303
|
}
|
|
10103
|
-
for (let i = 0; i < this.children.length; i += 3)
|
|
10104
|
-
|
|
10105
|
-
this.children[i +
|
|
10304
|
+
for (let i = 0; i < this.children.length; i += 3) {
|
|
10305
|
+
if (this.children[i] >= end) break;
|
|
10306
|
+
if (this.children[i + 1] > start) {
|
|
10307
|
+
let childOff = this.children[i] + 1;
|
|
10308
|
+
this.children[i + 2].findInner(start - childOff, end - childOff, result, offset + childOff, predicate);
|
|
10309
|
+
}
|
|
10106
10310
|
}
|
|
10107
10311
|
}
|
|
10108
10312
|
/**
|
|
@@ -10151,7 +10355,7 @@ var DecorationSet = class DecorationSet {
|
|
|
10151
10355
|
else children.splice(childIndex, 0, childOffset, childOffset + childNode.nodeSize, buildTree(found, childNode, baseOffset + 1, noSpec));
|
|
10152
10356
|
childIndex += 3;
|
|
10153
10357
|
});
|
|
10154
|
-
let local = moveSpans(childIndex ? withoutNulls(decorations) : decorations, -offset);
|
|
10358
|
+
let local = moveSpans(childIndex ? withoutNulls(decorations) : decorations, -offset).sort(byPos);
|
|
10155
10359
|
if (local.length) {
|
|
10156
10360
|
let cur = new FragmentCursor(doc.content);
|
|
10157
10361
|
for (let i = 0; i < local.length; i++) if (!local[i].type.valid(doc, local[i], cur)) local.splice(i--, 1);
|
|
@@ -10201,9 +10405,15 @@ var DecorationSet = class DecorationSet {
|
|
|
10201
10405
|
if (this == empty) return this;
|
|
10202
10406
|
if (node.isLeaf) return DecorationSet.empty;
|
|
10203
10407
|
let child, local;
|
|
10204
|
-
|
|
10205
|
-
|
|
10206
|
-
|
|
10408
|
+
let low = 0, high = this.children.length / 3;
|
|
10409
|
+
while (low < high) {
|
|
10410
|
+
let mid = low + high >>> 1, index = mid * 3, start = this.children[index];
|
|
10411
|
+
if (start < offset) low = mid + 1;
|
|
10412
|
+
else if (start > offset) high = mid;
|
|
10413
|
+
else {
|
|
10414
|
+
child = this.children[index + 2];
|
|
10415
|
+
break;
|
|
10416
|
+
}
|
|
10207
10417
|
}
|
|
10208
10418
|
let start = offset + 1, end = start + node.content.size;
|
|
10209
10419
|
for (let i = 0; i < this.local.length; i++) {
|
|
@@ -10371,420 +10581,105 @@ function mapChildren(oldChildren, newLocal, mapping, node, offset, oldOffset, op
|
|
|
10371
10581
|
}
|
|
10372
10582
|
return new DecorationSet(newLocal.sort(byPos), children);
|
|
10373
10583
|
}
|
|
10374
|
-
function moveSpans(spans, offset) {
|
|
10375
|
-
if (!offset || !spans.length) return spans;
|
|
10376
|
-
let result = [];
|
|
10377
|
-
for (let i = 0; i < spans.length; i++) {
|
|
10378
|
-
let span = spans[i];
|
|
10379
|
-
result.push(new Decoration(span.from + offset, span.to + offset, span.type));
|
|
10380
|
-
}
|
|
10381
|
-
return result;
|
|
10382
|
-
}
|
|
10383
|
-
function mapAndGatherRemainingDecorations(children, oldChildren, decorations, mapping, offset, oldOffset, options) {
|
|
10384
|
-
function gather(set, oldOffset) {
|
|
10385
|
-
for (let i = 0; i < set.local.length; i++) {
|
|
10386
|
-
let mapped = set.local[i].map(mapping, offset, oldOffset);
|
|
10387
|
-
if (mapped) decorations.push(mapped);
|
|
10388
|
-
else if (options.onRemove) options.onRemove(set.local[i].spec);
|
|
10389
|
-
}
|
|
10390
|
-
for (let i = 0; i < set.children.length; i += 3) gather(set.children[i + 2], set.children[i] + oldOffset + 1);
|
|
10391
|
-
}
|
|
10392
|
-
for (let i = 0; i < children.length; i += 3) if (children[i + 1] == -1) gather(children[i + 2], oldChildren[i] + oldOffset + 1);
|
|
10393
|
-
return decorations;
|
|
10394
|
-
}
|
|
10395
|
-
function takeSpansForNode(spans, node, offset) {
|
|
10396
|
-
if (node.isLeaf) return null;
|
|
10397
|
-
let end = offset + node.nodeSize, found = null;
|
|
10398
|
-
for (let i = 0, span; i < spans.length; i++) if ((span = spans[i]) && span.from > offset && span.to < end) {
|
|
10399
|
-
(found || (found = [])).push(span);
|
|
10400
|
-
spans[i] = null;
|
|
10401
|
-
}
|
|
10402
|
-
return found;
|
|
10403
|
-
}
|
|
10404
|
-
function withoutNulls(array) {
|
|
10405
|
-
let result = [];
|
|
10406
|
-
for (let i = 0; i < array.length; i++) if (array[i] != null) result.push(array[i]);
|
|
10407
|
-
return result;
|
|
10408
|
-
}
|
|
10409
|
-
function buildTree(spans, node, offset, options) {
|
|
10410
|
-
let children = [], hasNulls = false;
|
|
10411
|
-
node.forEach((childNode, localStart) => {
|
|
10412
|
-
let found = takeSpansForNode(spans, childNode, localStart + offset);
|
|
10413
|
-
if (found) {
|
|
10414
|
-
hasNulls = true;
|
|
10415
|
-
let subtree = buildTree(found, childNode, offset + localStart + 1, options);
|
|
10416
|
-
if (subtree != empty) children.push(localStart, localStart + childNode.nodeSize, subtree);
|
|
10417
|
-
}
|
|
10418
|
-
});
|
|
10419
|
-
let locals = moveSpans(hasNulls ? withoutNulls(spans) : spans, -offset).sort(byPos);
|
|
10420
|
-
if (locals.length) {
|
|
10421
|
-
let cur = new FragmentCursor(node.content);
|
|
10422
|
-
for (let i = 0; i < locals.length; i++) if (!locals[i].type.valid(node, locals[i], cur)) {
|
|
10423
|
-
if (options.onRemove) options.onRemove(locals[i].spec);
|
|
10424
|
-
locals.splice(i--, 1);
|
|
10425
|
-
}
|
|
10426
|
-
}
|
|
10427
|
-
return locals.length || children.length ? new DecorationSet(locals, children) : empty;
|
|
10428
|
-
}
|
|
10429
|
-
function byPos(a, b) {
|
|
10430
|
-
return a.from - b.from || a.to - b.to;
|
|
10431
|
-
}
|
|
10432
|
-
function removeOverlap(spans) {
|
|
10433
|
-
let working = spans;
|
|
10434
|
-
for (let i = 0; i < working.length - 1; i++) {
|
|
10435
|
-
let span = working[i];
|
|
10436
|
-
if (span.from != span.to) for (let j = i + 1; j < working.length; j++) {
|
|
10437
|
-
let next = working[j];
|
|
10438
|
-
if (next.from == span.from) {
|
|
10439
|
-
if (next.to != span.to) {
|
|
10440
|
-
if (working == spans) working = spans.slice();
|
|
10441
|
-
working[j] = next.copy(next.from, span.to);
|
|
10442
|
-
insertAhead(working, j + 1, next.copy(span.to, next.to));
|
|
10443
|
-
}
|
|
10444
|
-
continue;
|
|
10445
|
-
} else {
|
|
10446
|
-
if (next.from < span.to) {
|
|
10447
|
-
if (working == spans) working = spans.slice();
|
|
10448
|
-
working[i] = span.copy(span.from, next.from);
|
|
10449
|
-
insertAhead(working, j, span.copy(next.from, span.to));
|
|
10450
|
-
}
|
|
10451
|
-
break;
|
|
10452
|
-
}
|
|
10453
|
-
}
|
|
10454
|
-
}
|
|
10455
|
-
return working;
|
|
10456
|
-
}
|
|
10457
|
-
function insertAhead(array, i, deco) {
|
|
10458
|
-
while (i < array.length && byPos(deco, array[i]) > 0) i++;
|
|
10459
|
-
array.splice(i, 0, deco);
|
|
10460
|
-
}
|
|
10461
|
-
function viewDecorations(view) {
|
|
10462
|
-
let found = [];
|
|
10463
|
-
view.someProp("decorations", (f) => {
|
|
10464
|
-
let result = f(view.state);
|
|
10465
|
-
if (result && result != empty) found.push(result);
|
|
10466
|
-
});
|
|
10467
|
-
if (view.cursorWrapper) found.push(DecorationSet.create(view.state.doc, [view.cursorWrapper.deco]));
|
|
10468
|
-
return DecorationGroup.from(found);
|
|
10469
|
-
}
|
|
10470
|
-
var observeOptions = {
|
|
10471
|
-
childList: true,
|
|
10472
|
-
characterData: true,
|
|
10473
|
-
characterDataOldValue: true,
|
|
10474
|
-
attributes: true,
|
|
10475
|
-
attributeOldValue: true,
|
|
10476
|
-
subtree: true
|
|
10477
|
-
};
|
|
10478
|
-
var useCharData = ie$1 && ie_version <= 11;
|
|
10479
|
-
var SelectionState = class {
|
|
10480
|
-
constructor() {
|
|
10481
|
-
this.anchorNode = null;
|
|
10482
|
-
this.anchorOffset = 0;
|
|
10483
|
-
this.focusNode = null;
|
|
10484
|
-
this.focusOffset = 0;
|
|
10485
|
-
}
|
|
10486
|
-
set(sel) {
|
|
10487
|
-
this.anchorNode = sel.anchorNode;
|
|
10488
|
-
this.anchorOffset = sel.anchorOffset;
|
|
10489
|
-
this.focusNode = sel.focusNode;
|
|
10490
|
-
this.focusOffset = sel.focusOffset;
|
|
10491
|
-
}
|
|
10492
|
-
clear() {
|
|
10493
|
-
this.anchorNode = this.focusNode = null;
|
|
10494
|
-
}
|
|
10495
|
-
eq(sel) {
|
|
10496
|
-
return sel.anchorNode == this.anchorNode && sel.anchorOffset == this.anchorOffset && sel.focusNode == this.focusNode && sel.focusOffset == this.focusOffset;
|
|
10497
|
-
}
|
|
10498
|
-
};
|
|
10499
|
-
var DOMObserver = class {
|
|
10500
|
-
constructor(view, handleDOMChange) {
|
|
10501
|
-
this.view = view;
|
|
10502
|
-
this.handleDOMChange = handleDOMChange;
|
|
10503
|
-
this.queue = [];
|
|
10504
|
-
this.flushingSoon = -1;
|
|
10505
|
-
this.observer = null;
|
|
10506
|
-
this.currentSelection = new SelectionState();
|
|
10507
|
-
this.onCharData = null;
|
|
10508
|
-
this.suppressingSelectionUpdates = false;
|
|
10509
|
-
this.lastChangedTextNode = null;
|
|
10510
|
-
this.observer = window.MutationObserver && new window.MutationObserver((mutations) => {
|
|
10511
|
-
for (let i = 0; i < mutations.length; i++) this.queue.push(mutations[i]);
|
|
10512
|
-
if (ie$1 && ie_version <= 11 && mutations.some((m) => m.type == "childList" && m.removedNodes.length || m.type == "characterData" && m.oldValue.length > m.target.nodeValue.length)) this.flushSoon();
|
|
10513
|
-
else if (safari && view.composing && mutations.some((m) => m.type == "childList" && m.target.nodeName == "TR")) {
|
|
10514
|
-
view.input.badSafariComposition = true;
|
|
10515
|
-
this.flushSoon();
|
|
10516
|
-
} else this.flush();
|
|
10517
|
-
});
|
|
10518
|
-
if (useCharData) this.onCharData = (e) => {
|
|
10519
|
-
this.queue.push({
|
|
10520
|
-
target: e.target,
|
|
10521
|
-
type: "characterData",
|
|
10522
|
-
oldValue: e.prevValue
|
|
10523
|
-
});
|
|
10524
|
-
this.flushSoon();
|
|
10525
|
-
};
|
|
10526
|
-
this.onSelectionChange = this.onSelectionChange.bind(this);
|
|
10527
|
-
}
|
|
10528
|
-
flushSoon() {
|
|
10529
|
-
if (this.flushingSoon < 0) this.flushingSoon = window.setTimeout(() => {
|
|
10530
|
-
this.flushingSoon = -1;
|
|
10531
|
-
this.flush();
|
|
10532
|
-
}, 20);
|
|
10533
|
-
}
|
|
10534
|
-
forceFlush() {
|
|
10535
|
-
if (this.flushingSoon > -1) {
|
|
10536
|
-
window.clearTimeout(this.flushingSoon);
|
|
10537
|
-
this.flushingSoon = -1;
|
|
10538
|
-
this.flush();
|
|
10539
|
-
}
|
|
10540
|
-
}
|
|
10541
|
-
start() {
|
|
10542
|
-
if (this.observer) {
|
|
10543
|
-
this.observer.takeRecords();
|
|
10544
|
-
this.observer.observe(this.view.dom, observeOptions);
|
|
10545
|
-
}
|
|
10546
|
-
if (this.onCharData) this.view.dom.addEventListener("DOMCharacterDataModified", this.onCharData);
|
|
10547
|
-
this.connectSelection();
|
|
10548
|
-
}
|
|
10549
|
-
stop() {
|
|
10550
|
-
if (this.observer) {
|
|
10551
|
-
let take = this.observer.takeRecords();
|
|
10552
|
-
if (take.length) {
|
|
10553
|
-
for (let i = 0; i < take.length; i++) this.queue.push(take[i]);
|
|
10554
|
-
window.setTimeout(() => this.flush(), 20);
|
|
10555
|
-
}
|
|
10556
|
-
this.observer.disconnect();
|
|
10557
|
-
}
|
|
10558
|
-
if (this.onCharData) this.view.dom.removeEventListener("DOMCharacterDataModified", this.onCharData);
|
|
10559
|
-
this.disconnectSelection();
|
|
10560
|
-
}
|
|
10561
|
-
connectSelection() {
|
|
10562
|
-
this.view.dom.ownerDocument.addEventListener("selectionchange", this.onSelectionChange);
|
|
10563
|
-
}
|
|
10564
|
-
disconnectSelection() {
|
|
10565
|
-
this.view.dom.ownerDocument.removeEventListener("selectionchange", this.onSelectionChange);
|
|
10566
|
-
}
|
|
10567
|
-
suppressSelectionUpdates() {
|
|
10568
|
-
this.suppressingSelectionUpdates = true;
|
|
10569
|
-
setTimeout(() => this.suppressingSelectionUpdates = false, 50);
|
|
10570
|
-
}
|
|
10571
|
-
onSelectionChange() {
|
|
10572
|
-
if (!hasFocusAndSelection(this.view)) return;
|
|
10573
|
-
if (this.suppressingSelectionUpdates) return selectionToDOM(this.view);
|
|
10574
|
-
if (ie$1 && ie_version <= 11 && !this.view.state.selection.empty) {
|
|
10575
|
-
let sel = this.view.domSelectionRange();
|
|
10576
|
-
if (sel.focusNode && isEquivalentPosition(sel.focusNode, sel.focusOffset, sel.anchorNode, sel.anchorOffset)) return this.flushSoon();
|
|
10577
|
-
}
|
|
10578
|
-
this.flush();
|
|
10579
|
-
}
|
|
10580
|
-
setCurSelection() {
|
|
10581
|
-
this.currentSelection.set(this.view.domSelectionRange());
|
|
10582
|
-
}
|
|
10583
|
-
ignoreSelectionChange(sel) {
|
|
10584
|
-
if (!sel.focusNode) return true;
|
|
10585
|
-
let ancestors = /* @__PURE__ */ new Set(), container;
|
|
10586
|
-
for (let scan = sel.focusNode; scan; scan = parentNode(scan)) ancestors.add(scan);
|
|
10587
|
-
for (let scan = sel.anchorNode; scan; scan = parentNode(scan)) if (ancestors.has(scan)) {
|
|
10588
|
-
container = scan;
|
|
10589
|
-
break;
|
|
10590
|
-
}
|
|
10591
|
-
let desc = container && this.view.docView.nearestDesc(container);
|
|
10592
|
-
if (desc && desc.ignoreMutation({
|
|
10593
|
-
type: "selection",
|
|
10594
|
-
target: isText(container) ? container.parentNode : container
|
|
10595
|
-
})) {
|
|
10596
|
-
this.setCurSelection();
|
|
10597
|
-
return true;
|
|
10598
|
-
}
|
|
10599
|
-
}
|
|
10600
|
-
pendingRecords() {
|
|
10601
|
-
if (this.observer) for (let mut of this.observer.takeRecords()) this.queue.push(mut);
|
|
10602
|
-
return this.queue;
|
|
10603
|
-
}
|
|
10604
|
-
flush() {
|
|
10605
|
-
let { view } = this;
|
|
10606
|
-
if (!view.docView || this.flushingSoon > -1) return;
|
|
10607
|
-
let mutations = this.pendingRecords();
|
|
10608
|
-
if (mutations.length) this.queue = [];
|
|
10609
|
-
let selRange, newSel = false;
|
|
10610
|
-
if (!this.suppressingSelectionUpdates && hasFocusAndSelection(view)) {
|
|
10611
|
-
selRange = view.domSelectionRange();
|
|
10612
|
-
newSel = !this.currentSelection.eq(selRange) && !this.ignoreSelectionChange(selRange);
|
|
10613
|
-
}
|
|
10614
|
-
let from = -1, to = -1, typeOver = false, added = [];
|
|
10615
|
-
if (view.editable) for (let i = 0; i < mutations.length; i++) {
|
|
10616
|
-
let result = this.registerMutation(mutations[i], added);
|
|
10617
|
-
if (result) {
|
|
10618
|
-
from = from < 0 ? result.from : Math.min(result.from, from);
|
|
10619
|
-
to = to < 0 ? result.to : Math.max(result.to, to);
|
|
10620
|
-
if (result.typeOver) typeOver = true;
|
|
10621
|
-
}
|
|
10622
|
-
}
|
|
10623
|
-
if (added.some((n) => n.nodeName == "BR") && (view.input.lastKeyCode == 8 || view.input.lastKeyCode == 46 || chrome && (view.composing || view.input.compositionEndedAt > Date.now() - 50) && mutations.some((m) => m.type == "childList" && m.removedNodes.length))) {
|
|
10624
|
-
for (let node of added) if (node.nodeName == "BR" && node.parentNode) {
|
|
10625
|
-
let after = node.nextSibling;
|
|
10626
|
-
while (after && isElt(after)) {
|
|
10627
|
-
if (after.contentEditable == "false") {
|
|
10628
|
-
node.parentNode.removeChild(node);
|
|
10629
|
-
break;
|
|
10630
|
-
}
|
|
10631
|
-
after = after.firstChild;
|
|
10632
|
-
}
|
|
10633
|
-
}
|
|
10634
|
-
} else if (gecko && added.length) {
|
|
10635
|
-
let brs = added.filter((n) => n.nodeName == "BR");
|
|
10636
|
-
if (brs.length == 2) {
|
|
10637
|
-
let [a, b] = brs;
|
|
10638
|
-
if (a.parentNode && a.parentNode.parentNode == b.parentNode) b.remove();
|
|
10639
|
-
else a.remove();
|
|
10640
|
-
} else {
|
|
10641
|
-
let { focusNode } = this.currentSelection;
|
|
10642
|
-
for (let br of brs) {
|
|
10643
|
-
let parent = br.parentNode;
|
|
10644
|
-
if (parent && parent.nodeName == "LI" && (!focusNode || blockParent(view, focusNode) != parent)) br.remove();
|
|
10645
|
-
}
|
|
10646
|
-
}
|
|
10647
|
-
}
|
|
10648
|
-
let readSel = null;
|
|
10649
|
-
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(Selection$1.near(view.state.doc.resolve(0), 1))) {
|
|
10650
|
-
view.input.lastFocus = 0;
|
|
10651
|
-
selectionToDOM(view);
|
|
10652
|
-
this.currentSelection.set(selRange);
|
|
10653
|
-
view.scrollToSelection();
|
|
10654
|
-
} else if (from > -1 || newSel) {
|
|
10655
|
-
if (from > -1) {
|
|
10656
|
-
view.docView.markDirty(from, to);
|
|
10657
|
-
checkCSS(view);
|
|
10658
|
-
}
|
|
10659
|
-
if (view.input.badSafariComposition) {
|
|
10660
|
-
view.input.badSafariComposition = false;
|
|
10661
|
-
fixUpBadSafariComposition(view, added);
|
|
10662
|
-
}
|
|
10663
|
-
this.handleDOMChange(from, to, typeOver, added);
|
|
10664
|
-
if (view.docView && view.docView.dirty) view.updateState(view.state);
|
|
10665
|
-
else if (selRange && !this.currentSelection.eq(selRange)) selectionToDOM(view);
|
|
10666
|
-
if (selRange) this.currentSelection.set(selRange);
|
|
10667
|
-
}
|
|
10668
|
-
}
|
|
10669
|
-
registerMutation(mut, added) {
|
|
10670
|
-
if (added.indexOf(mut.target) > -1) return null;
|
|
10671
|
-
let desc = this.view.docView.nearestDesc(mut.target);
|
|
10672
|
-
if (mut.type == "attributes" && (desc == this.view.docView || mut.attributeName == "contenteditable" || mut.attributeName == "style" && !mut.oldValue && !mut.target.getAttribute("style"))) return null;
|
|
10673
|
-
if (!desc || desc.ignoreMutation(mut)) return null;
|
|
10674
|
-
if (mut.type == "childList") {
|
|
10675
|
-
for (let i = 0; i < mut.addedNodes.length; i++) {
|
|
10676
|
-
let node = mut.addedNodes[i];
|
|
10677
|
-
added.push(node);
|
|
10678
|
-
if (isText(node)) this.lastChangedTextNode = node;
|
|
10679
|
-
}
|
|
10680
|
-
if (desc.contentDOM && desc.contentDOM != desc.dom && !desc.contentDOM.contains(mut.target)) return {
|
|
10681
|
-
from: desc.posBefore,
|
|
10682
|
-
to: desc.posAfter
|
|
10683
|
-
};
|
|
10684
|
-
let prev = mut.previousSibling, next = mut.nextSibling;
|
|
10685
|
-
if (ie$1 && ie_version <= 11 && mut.addedNodes.length) for (let i = 0; i < mut.addedNodes.length; i++) {
|
|
10686
|
-
let { previousSibling, nextSibling } = mut.addedNodes[i];
|
|
10687
|
-
if (!previousSibling || Array.prototype.indexOf.call(mut.addedNodes, previousSibling) < 0) prev = previousSibling;
|
|
10688
|
-
if (!nextSibling || Array.prototype.indexOf.call(mut.addedNodes, nextSibling) < 0) next = nextSibling;
|
|
10689
|
-
}
|
|
10690
|
-
let fromOffset = prev && prev.parentNode == mut.target ? domIndex(prev) + 1 : 0;
|
|
10691
|
-
let from = desc.localPosFromDOM(mut.target, fromOffset, -1);
|
|
10692
|
-
let toOffset = next && next.parentNode == mut.target ? domIndex(next) : mut.target.childNodes.length;
|
|
10693
|
-
return {
|
|
10694
|
-
from,
|
|
10695
|
-
to: desc.localPosFromDOM(mut.target, toOffset, 1)
|
|
10696
|
-
};
|
|
10697
|
-
} else if (mut.type == "attributes") return {
|
|
10698
|
-
from: desc.posAtStart - desc.border,
|
|
10699
|
-
to: desc.posAtEnd + desc.border
|
|
10700
|
-
};
|
|
10701
|
-
else {
|
|
10702
|
-
this.lastChangedTextNode = mut.target;
|
|
10703
|
-
return {
|
|
10704
|
-
from: desc.posAtStart,
|
|
10705
|
-
to: desc.posAtEnd,
|
|
10706
|
-
typeOver: mut.target.nodeValue == mut.oldValue
|
|
10707
|
-
};
|
|
10708
|
-
}
|
|
10709
|
-
}
|
|
10710
|
-
};
|
|
10711
|
-
var cssChecked = /* @__PURE__ */ new WeakMap();
|
|
10712
|
-
var cssCheckWarned = false;
|
|
10713
|
-
function checkCSS(view) {
|
|
10714
|
-
if (cssChecked.has(view)) return;
|
|
10715
|
-
cssChecked.set(view, null);
|
|
10716
|
-
if ([
|
|
10717
|
-
"normal",
|
|
10718
|
-
"nowrap",
|
|
10719
|
-
"pre-line"
|
|
10720
|
-
].indexOf(getComputedStyle(view.dom).whiteSpace) !== -1) {
|
|
10721
|
-
view.requiresGeckoHackNode = gecko;
|
|
10722
|
-
if (cssCheckWarned) return;
|
|
10723
|
-
console["warn"]("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package.");
|
|
10724
|
-
cssCheckWarned = true;
|
|
10725
|
-
}
|
|
10726
|
-
}
|
|
10727
|
-
function rangeToSelectionRange(view, range) {
|
|
10728
|
-
let anchorNode = range.startContainer, anchorOffset = range.startOffset;
|
|
10729
|
-
let focusNode = range.endContainer, focusOffset = range.endOffset;
|
|
10730
|
-
let currentAnchor = view.domAtPos(view.state.selection.anchor);
|
|
10731
|
-
if (isEquivalentPosition(currentAnchor.node, currentAnchor.offset, focusNode, focusOffset)) [anchorNode, anchorOffset, focusNode, focusOffset] = [
|
|
10732
|
-
focusNode,
|
|
10733
|
-
focusOffset,
|
|
10734
|
-
anchorNode,
|
|
10735
|
-
anchorOffset
|
|
10736
|
-
];
|
|
10737
|
-
return {
|
|
10738
|
-
anchorNode,
|
|
10739
|
-
anchorOffset,
|
|
10740
|
-
focusNode,
|
|
10741
|
-
focusOffset
|
|
10742
|
-
};
|
|
10743
|
-
}
|
|
10744
|
-
function safariShadowSelectionRange(view, selection) {
|
|
10745
|
-
if (selection.getComposedRanges) {
|
|
10746
|
-
let range = selection.getComposedRanges(view.root)[0];
|
|
10747
|
-
if (range) return rangeToSelectionRange(view, range);
|
|
10584
|
+
function moveSpans(spans, offset) {
|
|
10585
|
+
if (!offset || !spans.length) return spans;
|
|
10586
|
+
let result = [];
|
|
10587
|
+
for (let i = 0; i < spans.length; i++) {
|
|
10588
|
+
let span = spans[i];
|
|
10589
|
+
result.push(new Decoration(span.from + offset, span.to + offset, span.type));
|
|
10748
10590
|
}
|
|
10749
|
-
|
|
10750
|
-
|
|
10751
|
-
|
|
10752
|
-
|
|
10753
|
-
|
|
10591
|
+
return result;
|
|
10592
|
+
}
|
|
10593
|
+
function mapAndGatherRemainingDecorations(children, oldChildren, decorations, mapping, offset, oldOffset, options) {
|
|
10594
|
+
function gather(set, oldOffset) {
|
|
10595
|
+
for (let i = 0; i < set.local.length; i++) {
|
|
10596
|
+
let mapped = set.local[i].map(mapping, offset, oldOffset);
|
|
10597
|
+
if (mapped) decorations.push(mapped);
|
|
10598
|
+
else if (options.onRemove) options.onRemove(set.local[i].spec);
|
|
10599
|
+
}
|
|
10600
|
+
for (let i = 0; i < set.children.length; i += 3) gather(set.children[i + 2], set.children[i] + oldOffset + 1);
|
|
10754
10601
|
}
|
|
10755
|
-
|
|
10756
|
-
|
|
10757
|
-
view.dom.removeEventListener("beforeinput", read, true);
|
|
10758
|
-
return found ? rangeToSelectionRange(view, found) : null;
|
|
10602
|
+
for (let i = 0; i < children.length; i += 3) if (children[i + 1] == -1) gather(children[i + 2], oldChildren[i] + oldOffset + 1);
|
|
10603
|
+
return decorations;
|
|
10759
10604
|
}
|
|
10760
|
-
function
|
|
10761
|
-
|
|
10762
|
-
|
|
10763
|
-
|
|
10605
|
+
function takeSpansForNode(spans, node, offset) {
|
|
10606
|
+
if (node.isLeaf) return null;
|
|
10607
|
+
let end = offset + node.nodeSize, found = null;
|
|
10608
|
+
for (let i = 0, span; i < spans.length; i++) if ((span = spans[i]) && span.from > offset && span.to < end) {
|
|
10609
|
+
(found || (found = [])).push(span);
|
|
10610
|
+
spans[i] = null;
|
|
10764
10611
|
}
|
|
10765
|
-
return
|
|
10612
|
+
return found;
|
|
10766
10613
|
}
|
|
10767
|
-
function
|
|
10768
|
-
|
|
10769
|
-
let
|
|
10770
|
-
|
|
10771
|
-
|
|
10772
|
-
|
|
10773
|
-
|
|
10774
|
-
|
|
10775
|
-
|
|
10776
|
-
|
|
10777
|
-
|
|
10778
|
-
|
|
10614
|
+
function withoutNulls(array) {
|
|
10615
|
+
let result = [];
|
|
10616
|
+
for (let i = 0; i < array.length; i++) if (array[i] != null) result.push(array[i]);
|
|
10617
|
+
return result;
|
|
10618
|
+
}
|
|
10619
|
+
function buildTree(spans, node, offset, options) {
|
|
10620
|
+
let children = [], hasNulls = false;
|
|
10621
|
+
node.forEach((childNode, localStart) => {
|
|
10622
|
+
let found = takeSpansForNode(spans, childNode, localStart + offset);
|
|
10623
|
+
if (found) {
|
|
10624
|
+
hasNulls = true;
|
|
10625
|
+
let subtree = buildTree(found, childNode, offset + localStart + 1, options);
|
|
10626
|
+
if (subtree != empty) children.push(localStart, localStart + childNode.nodeSize, subtree);
|
|
10627
|
+
}
|
|
10628
|
+
});
|
|
10629
|
+
let locals = moveSpans(hasNulls ? withoutNulls(spans) : spans, -offset).sort(byPos);
|
|
10630
|
+
if (locals.length) {
|
|
10631
|
+
let cur = new FragmentCursor(node.content);
|
|
10632
|
+
for (let i = 0; i < locals.length; i++) if (!locals[i].type.valid(node, locals[i], cur)) {
|
|
10633
|
+
if (options.onRemove) options.onRemove(locals[i].spec);
|
|
10634
|
+
locals.splice(i--, 1);
|
|
10635
|
+
}
|
|
10636
|
+
}
|
|
10637
|
+
return locals.length || children.length ? new DecorationSet(locals, children) : empty;
|
|
10638
|
+
}
|
|
10639
|
+
function byPos(a, b) {
|
|
10640
|
+
return a.from - b.from || a.to - b.to;
|
|
10641
|
+
}
|
|
10642
|
+
function removeOverlap(spans) {
|
|
10643
|
+
let working = spans;
|
|
10644
|
+
for (let i = 0; i < working.length - 1; i++) {
|
|
10645
|
+
let span = working[i];
|
|
10646
|
+
if (span.from != span.to) for (let j = i + 1; j < working.length; j++) {
|
|
10647
|
+
let next = working[j];
|
|
10648
|
+
if (next.from == span.from) {
|
|
10649
|
+
if (next.to != span.to) {
|
|
10650
|
+
if (working == spans) working = spans.slice();
|
|
10651
|
+
working[j] = next.copy(next.from, span.to);
|
|
10652
|
+
insertAhead(working, j + 1, next.copy(span.to, next.to));
|
|
10653
|
+
}
|
|
10654
|
+
continue;
|
|
10655
|
+
} else {
|
|
10656
|
+
if (next.from < span.to) {
|
|
10657
|
+
if (working == spans) working = spans.slice();
|
|
10658
|
+
working[i] = span.copy(span.from, next.from);
|
|
10659
|
+
insertAhead(working, j, span.copy(next.from, span.to));
|
|
10660
|
+
}
|
|
10661
|
+
break;
|
|
10779
10662
|
}
|
|
10780
|
-
|
|
10781
|
-
if (focusNode == node) view.domSelection().collapse(node, focusOffset);
|
|
10782
|
-
} else node.parentNode.removeChild(node);
|
|
10663
|
+
}
|
|
10783
10664
|
}
|
|
10665
|
+
return working;
|
|
10666
|
+
}
|
|
10667
|
+
function insertAhead(array, i, deco) {
|
|
10668
|
+
while (i < array.length && byPos(deco, array[i]) > 0) i++;
|
|
10669
|
+
array.splice(i, 0, deco);
|
|
10670
|
+
}
|
|
10671
|
+
function viewDecorations(view) {
|
|
10672
|
+
let found = [];
|
|
10673
|
+
view.someProp("decorations", (f) => {
|
|
10674
|
+
let result = f(view.state);
|
|
10675
|
+
if (result && result != empty) found.push(result);
|
|
10676
|
+
});
|
|
10677
|
+
if (view.cursorWrapper) found.push(DecorationSet.create(view.state.doc, [view.cursorWrapper.deco]));
|
|
10678
|
+
return DecorationGroup.from(found);
|
|
10784
10679
|
}
|
|
10785
10680
|
function parseBetween(view, from_, to_, addedNodes) {
|
|
10786
10681
|
let { node: parent, fromOffset, toOffset, from, to } = view.docView.parseRange(from_, to_);
|
|
10787
|
-
let domSel = view.
|
|
10682
|
+
let domSel = view.domSel.range;
|
|
10788
10683
|
let find;
|
|
10789
10684
|
let anchor = domSel.anchorNode;
|
|
10790
10685
|
if (anchor && contains(view.dom, anchor)) {
|
|
@@ -10847,13 +10742,13 @@ var ruleFromNode = (added) => (dom) => {
|
|
|
10847
10742
|
return null;
|
|
10848
10743
|
};
|
|
10849
10744
|
var isInline = /^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;
|
|
10850
|
-
function readDOMChange(view, from, to, typeOver, addedNodes) {
|
|
10745
|
+
function readDOMChange(view, from, to, selChange, typeOver, addedNodes) {
|
|
10851
10746
|
let compositionID = view.input.compositionPendingChanges || (view.composing ? view.input.compositionID : 0);
|
|
10852
10747
|
view.input.compositionPendingChanges = 0;
|
|
10853
10748
|
if (from < 0) {
|
|
10854
10749
|
let origin = view.input.lastSelectionTime > Date.now() - 50 ? view.input.lastSelectionOrigin : null;
|
|
10855
|
-
let newSel = selectionFromDOM(view, origin);
|
|
10856
|
-
if (newSel && !view.state.selection.eq(newSel)) {
|
|
10750
|
+
let newSel = selectionFromDOM(view, view.domSel.range, origin);
|
|
10751
|
+
if (newSel && !view.state.selection.eq(newSel) && view.domSel.active) {
|
|
10857
10752
|
if (chrome && android && view.input.lastKeyCode === 13 && Date.now() - 100 < view.input.lastKeyCodeTime && dispatchKey(view, "Enter")) return;
|
|
10858
10753
|
let tr = view.state.tr.setSelection(newSel);
|
|
10859
10754
|
if (origin == "pointer") tr.setMeta("pointer", true);
|
|
@@ -10910,11 +10805,6 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
|
|
|
10910
10805
|
change.endA = view.state.selection.to;
|
|
10911
10806
|
}
|
|
10912
10807
|
}
|
|
10913
|
-
if (ie$1 && ie_version <= 11 && change.endB == change.start + 1 && change.endA == change.start && change.start > parse.from && parse.doc.textBetween(change.start - parse.from - 1, change.start - parse.from + 1) == " \xA0") {
|
|
10914
|
-
change.start--;
|
|
10915
|
-
change.endA--;
|
|
10916
|
-
change.endB--;
|
|
10917
|
-
}
|
|
10918
10808
|
let $from = parse.doc.resolveNoCache(change.start - parse.from);
|
|
10919
10809
|
let $to = parse.doc.resolveNoCache(change.endB - parse.from);
|
|
10920
10810
|
let $fromA = doc.resolve(change.start);
|
|
@@ -10924,7 +10814,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
|
|
|
10924
10814
|
return;
|
|
10925
10815
|
}
|
|
10926
10816
|
if (view.state.selection.anchor > change.start && (inlineChange ? change.endA > change.start && change.endB == change.start : looksLikeBlockJoin(doc, change.start, change.endA, $from, $to)) && dispatchKey(view, "Backspace")) {
|
|
10927
|
-
if (android && chrome) view.
|
|
10817
|
+
if (android && chrome) view.domSel.suppressChanges();
|
|
10928
10818
|
return;
|
|
10929
10819
|
}
|
|
10930
10820
|
if (chrome && change.endB == change.start) view.input.lastChromeDelete = Date.now();
|
|
@@ -10938,7 +10828,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
|
|
|
10938
10828
|
let tr = base || view.state.tr.replace(chFrom, chTo, parse.doc.slice(change.start - parse.from, change.endB - parse.from));
|
|
10939
10829
|
if (parse.sel) {
|
|
10940
10830
|
let sel = resolveSelection(view, tr.doc, parse.sel);
|
|
10941
|
-
if (sel && !(chrome && view.composing && sel.empty && (change.start != change.endB || view.input.lastChromeDelete < Date.now() - 100) && (sel.head == chFrom || sel.head == tr.mapping.map(chTo) - 1)
|
|
10831
|
+
if (sel && !(chrome && view.composing && sel.empty && (change.start != change.endB || view.input.lastChromeDelete < Date.now() - 100) && (sel.head == chFrom || sel.head == tr.mapping.map(chTo) - 1))) tr.setSelection(sel);
|
|
10942
10832
|
}
|
|
10943
10833
|
if (compositionID) tr.setMeta("composition", compositionID);
|
|
10944
10834
|
return tr.scrollIntoView();
|
|
@@ -10946,10 +10836,6 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
|
|
|
10946
10836
|
let markChange;
|
|
10947
10837
|
if (inlineChange) {
|
|
10948
10838
|
if ($from.pos == $to.pos) {
|
|
10949
|
-
if (ie$1 && ie_version <= 11 && $from.parentOffset == 0) {
|
|
10950
|
-
view.domObserver.suppressSelectionUpdates();
|
|
10951
|
-
setTimeout(() => selectionToDOM(view), 20);
|
|
10952
|
-
}
|
|
10953
10839
|
let tr = mkTr(view.state.tr.delete(chFrom, chTo));
|
|
10954
10840
|
let marks = doc.resolve(change.start).marksAcross(doc.resolve(change.endA));
|
|
10955
10841
|
if (marks) tr.ensureMarks(marks);
|
|
@@ -11025,32 +10911,258 @@ function skipClosingAndOpening($pos, fromEnd, mayOpen) {
|
|
|
11025
10911
|
end++;
|
|
11026
10912
|
}
|
|
11027
10913
|
}
|
|
11028
|
-
return end;
|
|
10914
|
+
return end;
|
|
10915
|
+
}
|
|
10916
|
+
function findDiff(a, b, pos, preferredPos, preferredSide) {
|
|
10917
|
+
let start = a.findDiffStart(b, pos), lenA = pos + a.size, lenB = pos + b.size;
|
|
10918
|
+
if (start == null) return null;
|
|
10919
|
+
let { a: endA, b: endB } = a.findDiffEnd(b, lenA, lenB);
|
|
10920
|
+
if (preferredSide == "end") {
|
|
10921
|
+
let adjust = Math.max(0, start - Math.min(endA, endB));
|
|
10922
|
+
preferredPos -= endA + adjust - start;
|
|
10923
|
+
}
|
|
10924
|
+
if (endA < start && lenA < lenB) {
|
|
10925
|
+
let move = preferredPos <= start && preferredPos >= endA ? start - preferredPos : 0;
|
|
10926
|
+
start -= move;
|
|
10927
|
+
endB = start + (endB - endA);
|
|
10928
|
+
endA = start;
|
|
10929
|
+
} else if (endB < start) {
|
|
10930
|
+
let move = preferredPos <= start && preferredPos >= endB ? start - preferredPos : 0;
|
|
10931
|
+
start -= move;
|
|
10932
|
+
endA = start + (endA - endB);
|
|
10933
|
+
endB = start;
|
|
10934
|
+
}
|
|
10935
|
+
return {
|
|
10936
|
+
start,
|
|
10937
|
+
endA,
|
|
10938
|
+
endB
|
|
10939
|
+
};
|
|
10940
|
+
}
|
|
10941
|
+
var observeOptions = {
|
|
10942
|
+
childList: true,
|
|
10943
|
+
characterData: true,
|
|
10944
|
+
characterDataOldValue: true,
|
|
10945
|
+
attributes: true,
|
|
10946
|
+
attributeOldValue: true,
|
|
10947
|
+
subtree: true
|
|
10948
|
+
};
|
|
10949
|
+
var DOMObserver = class {
|
|
10950
|
+
constructor(view) {
|
|
10951
|
+
this.view = view;
|
|
10952
|
+
this.queue = [];
|
|
10953
|
+
this.flushingSoon = -1;
|
|
10954
|
+
this.suppressingSelectionUpdates = false;
|
|
10955
|
+
this.lastChangedTextNode = null;
|
|
10956
|
+
this.started = false;
|
|
10957
|
+
this.observer = new window.MutationObserver((mutations) => {
|
|
10958
|
+
for (let i = 0; i < mutations.length; i++) this.queue.push(mutations[i]);
|
|
10959
|
+
if (safari && view.composing && mutations.some((m) => m.type == "childList" && m.target.nodeName == "TR")) {
|
|
10960
|
+
view.input.badSafariComposition = true;
|
|
10961
|
+
this.flushSoon();
|
|
10962
|
+
} else this.flush();
|
|
10963
|
+
});
|
|
10964
|
+
}
|
|
10965
|
+
flushSoon() {
|
|
10966
|
+
if (this.flushingSoon < 0) this.flushingSoon = window.setTimeout(() => {
|
|
10967
|
+
this.flushingSoon = -1;
|
|
10968
|
+
this.flush();
|
|
10969
|
+
}, 20);
|
|
10970
|
+
}
|
|
10971
|
+
forceFlush(always = false) {
|
|
10972
|
+
if (this.flushingSoon > -1) {
|
|
10973
|
+
window.clearTimeout(this.flushingSoon);
|
|
10974
|
+
this.flushingSoon = -1;
|
|
10975
|
+
this.flush(true);
|
|
10976
|
+
} else if (always) this.flush(true);
|
|
10977
|
+
}
|
|
10978
|
+
start() {
|
|
10979
|
+
this.observer.takeRecords();
|
|
10980
|
+
this.observer.observe(this.view.dom, observeOptions);
|
|
10981
|
+
this.started = true;
|
|
10982
|
+
}
|
|
10983
|
+
stop() {
|
|
10984
|
+
let take = this.observer.takeRecords();
|
|
10985
|
+
if (take.length) {
|
|
10986
|
+
for (let i = 0; i < take.length; i++) this.queue.push(take[i]);
|
|
10987
|
+
window.setTimeout(() => this.flush(), 20);
|
|
10988
|
+
}
|
|
10989
|
+
this.observer.disconnect();
|
|
10990
|
+
this.started = false;
|
|
10991
|
+
}
|
|
10992
|
+
stopped(f) {
|
|
10993
|
+
if (!this.started) return f();
|
|
10994
|
+
this.stop();
|
|
10995
|
+
try {
|
|
10996
|
+
return f();
|
|
10997
|
+
} finally {
|
|
10998
|
+
this.start();
|
|
10999
|
+
}
|
|
11000
|
+
}
|
|
11001
|
+
ignoreSelectionChange(sel) {
|
|
11002
|
+
if (!sel.focusNode) return true;
|
|
11003
|
+
let ancestors = /* @__PURE__ */ new Set(), container;
|
|
11004
|
+
for (let scan = sel.focusNode; scan; scan = parentNode(scan)) ancestors.add(scan);
|
|
11005
|
+
for (let scan = sel.anchorNode; scan; scan = parentNode(scan)) if (ancestors.has(scan)) {
|
|
11006
|
+
container = scan;
|
|
11007
|
+
break;
|
|
11008
|
+
}
|
|
11009
|
+
let desc = container && this.view.docView.nearestDesc(container);
|
|
11010
|
+
if (desc && desc.ignoreMutation({
|
|
11011
|
+
type: "selection",
|
|
11012
|
+
target: isText(container) ? container.parentNode : container
|
|
11013
|
+
})) {
|
|
11014
|
+
this.view.domSel.ignore(sel);
|
|
11015
|
+
return true;
|
|
11016
|
+
}
|
|
11017
|
+
}
|
|
11018
|
+
pendingRecords() {
|
|
11019
|
+
for (let mut of this.observer.takeRecords()) this.queue.push(mut);
|
|
11020
|
+
return this.queue;
|
|
11021
|
+
}
|
|
11022
|
+
flush(readSel = true) {
|
|
11023
|
+
let { view } = this;
|
|
11024
|
+
if (!view.docView || this.flushingSoon > -1) return;
|
|
11025
|
+
let mutations = this.pendingRecords();
|
|
11026
|
+
if (mutations.length) this.queue = [];
|
|
11027
|
+
if (readSel) view.domSel.read();
|
|
11028
|
+
let selChange = !view.domSel.suppress && !view.domSel.synced && !!hasFocusAndSelection(view) && !this.ignoreSelectionChange(view.domSel.range);
|
|
11029
|
+
let from = -1, to = -1, typeOver = false, added = [];
|
|
11030
|
+
if (view.editable) for (let i = 0; i < mutations.length; i++) {
|
|
11031
|
+
let result = this.registerMutation(mutations[i], added);
|
|
11032
|
+
if (result) {
|
|
11033
|
+
from = from < 0 ? result.from : Math.min(result.from, from);
|
|
11034
|
+
to = to < 0 ? result.to : Math.max(result.to, to);
|
|
11035
|
+
if (result.typeOver) typeOver = true;
|
|
11036
|
+
}
|
|
11037
|
+
}
|
|
11038
|
+
if (added.some((n) => n.nodeName == "BR") && (view.input.lastKeyCode == 8 || view.input.lastKeyCode == 46 || chrome && (view.composing || view.input.compositionEndedAt > Date.now() - 50) && mutations.some((m) => m.type == "childList" && m.removedNodes.length))) {
|
|
11039
|
+
for (let node of added) if (node.nodeName == "BR" && node.parentNode) {
|
|
11040
|
+
let after = node.nextSibling;
|
|
11041
|
+
while (after && isElt(after)) {
|
|
11042
|
+
if (after.contentEditable == "false") {
|
|
11043
|
+
node.parentNode.removeChild(node);
|
|
11044
|
+
break;
|
|
11045
|
+
}
|
|
11046
|
+
after = after.firstChild;
|
|
11047
|
+
}
|
|
11048
|
+
}
|
|
11049
|
+
} else if (gecko && added.length) {
|
|
11050
|
+
let brs = added.filter((n) => n.nodeName == "BR");
|
|
11051
|
+
if (brs.length == 2) {
|
|
11052
|
+
let [a, b] = brs;
|
|
11053
|
+
if (a.parentNode && a.parentNode.parentNode == b.parentNode) b.remove();
|
|
11054
|
+
else a.remove();
|
|
11055
|
+
} else {
|
|
11056
|
+
let { focusNode } = view.domSel.range;
|
|
11057
|
+
for (let br of brs) {
|
|
11058
|
+
let parent = br.parentNode;
|
|
11059
|
+
if (parent && parent.nodeName == "LI" && (!focusNode || blockParent(view, focusNode) != parent)) br.remove();
|
|
11060
|
+
}
|
|
11061
|
+
}
|
|
11062
|
+
}
|
|
11063
|
+
let newSel = null;
|
|
11064
|
+
if (from < 0 && selChange && view.domSel.active && view.input.lastFocus > Date.now() - 200 && view.input.lastTouch < Date.now() - 300 && selectionCollapsed(view.domSel.range) && (newSel = selectionFromDOM(view, view.domSel.range)) && newSel.eq(Selection$1.near(view.state.doc.resolve(0), 1))) {
|
|
11065
|
+
view.input.lastFocus = 0;
|
|
11066
|
+
view.domSel.sync();
|
|
11067
|
+
view.scrollToSelection();
|
|
11068
|
+
} else if (from > -1 || selChange) {
|
|
11069
|
+
if (from > -1) checkCSS(view);
|
|
11070
|
+
if (view.input.badSafariComposition) {
|
|
11071
|
+
view.input.badSafariComposition = false;
|
|
11072
|
+
fixUpBadSafariComposition(view, added);
|
|
11073
|
+
}
|
|
11074
|
+
readDOMChange(this.view, from, to, selChange, typeOver, added);
|
|
11075
|
+
if (view.docView && view.docView.damage) view.updateState(view.state);
|
|
11076
|
+
else if (selChange) view.domSel.sync();
|
|
11077
|
+
}
|
|
11078
|
+
}
|
|
11079
|
+
registerMutation(mut, added) {
|
|
11080
|
+
var _a;
|
|
11081
|
+
if (added.indexOf(mut.target) > -1) return null;
|
|
11082
|
+
let desc;
|
|
11083
|
+
for (let scan = mut.target; scan; scan = scan.parentNode) if (desc = this.view.docView.getDesc(scan)) break;
|
|
11084
|
+
if (mut.type == "attributes" && (desc == this.view.docView || mut.attributeName == "contenteditable" || mut.attributeName == "style" && !mut.oldValue && !mut.target.getAttribute("style"))) return null;
|
|
11085
|
+
if (!desc || desc.ignoreMutation(mut)) return null;
|
|
11086
|
+
if (mut.type == "childList") {
|
|
11087
|
+
for (let i = 0; i < mut.addedNodes.length; i++) {
|
|
11088
|
+
let node = mut.addedNodes[i];
|
|
11089
|
+
added.push(node);
|
|
11090
|
+
if (isText(node)) this.lastChangedTextNode = node;
|
|
11091
|
+
}
|
|
11092
|
+
if (desc.contentDOM && desc.contentDOM != desc.dom && !desc.contentDOM.contains(mut.target)) {
|
|
11093
|
+
desc.markDamage(4);
|
|
11094
|
+
return {
|
|
11095
|
+
from: desc.posBefore,
|
|
11096
|
+
to: desc.posAfter
|
|
11097
|
+
};
|
|
11098
|
+
}
|
|
11099
|
+
let prev = mut.previousSibling, next = mut.nextSibling;
|
|
11100
|
+
let fromOffset = prev && prev.parentNode == mut.target ? domIndex(prev) + 1 : 0;
|
|
11101
|
+
let from = desc.localPosFromDOM(mut.target, fromOffset, -1);
|
|
11102
|
+
let toOffset = next && next.parentNode == mut.target ? domIndex(next) : mut.target.childNodes.length;
|
|
11103
|
+
let to = desc.localPosFromDOM(mut.target, toOffset, 1);
|
|
11104
|
+
desc.markDamage(((_a = desc.contentDOM) === null || _a === void 0 ? void 0 : _a.contains(mut.target)) ? 2 : 4);
|
|
11105
|
+
return {
|
|
11106
|
+
from,
|
|
11107
|
+
to
|
|
11108
|
+
};
|
|
11109
|
+
} else if (mut.type == "attributes") {
|
|
11110
|
+
desc.markDamage(4);
|
|
11111
|
+
return {
|
|
11112
|
+
from: desc.posAtStart - desc.border,
|
|
11113
|
+
to: desc.posAtEnd + desc.border
|
|
11114
|
+
};
|
|
11115
|
+
} else {
|
|
11116
|
+
this.lastChangedTextNode = mut.target;
|
|
11117
|
+
desc.markDamage(desc instanceof TextViewDesc && mut.target == desc.nodeDOM ? 8 : 4);
|
|
11118
|
+
return {
|
|
11119
|
+
from: desc.posAtStart,
|
|
11120
|
+
to: desc.posAtEnd,
|
|
11121
|
+
typeOver: mut.target.nodeValue == mut.oldValue
|
|
11122
|
+
};
|
|
11123
|
+
}
|
|
11124
|
+
}
|
|
11125
|
+
};
|
|
11126
|
+
var cssChecked = /* @__PURE__ */ new WeakMap();
|
|
11127
|
+
var cssCheckWarned = false;
|
|
11128
|
+
function checkCSS(view) {
|
|
11129
|
+
if (cssChecked.has(view)) return;
|
|
11130
|
+
cssChecked.set(view, null);
|
|
11131
|
+
if ([
|
|
11132
|
+
"normal",
|
|
11133
|
+
"nowrap",
|
|
11134
|
+
"pre-line"
|
|
11135
|
+
].indexOf(getComputedStyle(view.dom).whiteSpace) !== -1) {
|
|
11136
|
+
view.requiresGeckoHackNode = gecko;
|
|
11137
|
+
if (cssCheckWarned) return;
|
|
11138
|
+
console["warn"]("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package.");
|
|
11139
|
+
cssCheckWarned = true;
|
|
11140
|
+
}
|
|
11029
11141
|
}
|
|
11030
|
-
function
|
|
11031
|
-
let
|
|
11032
|
-
|
|
11033
|
-
|
|
11034
|
-
if (preferredSide == "end") {
|
|
11035
|
-
let adjust = Math.max(0, start - Math.min(endA, endB));
|
|
11036
|
-
preferredPos -= endA + adjust - start;
|
|
11142
|
+
function blockParent(view, node) {
|
|
11143
|
+
for (let p = node.parentNode; p && p != view.dom; p = p.parentNode) {
|
|
11144
|
+
let desc = view.docView.nearestDesc(p, true);
|
|
11145
|
+
if (desc && desc.node.isBlock) return p;
|
|
11037
11146
|
}
|
|
11038
|
-
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
|
|
11043
|
-
|
|
11044
|
-
let
|
|
11045
|
-
|
|
11046
|
-
|
|
11047
|
-
|
|
11147
|
+
return null;
|
|
11148
|
+
}
|
|
11149
|
+
function fixUpBadSafariComposition(view, addedNodes) {
|
|
11150
|
+
var _a;
|
|
11151
|
+
let { focusNode, focusOffset } = view.domSel.range;
|
|
11152
|
+
for (let node of addedNodes) if (((_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.nodeName) == "TR") {
|
|
11153
|
+
let nextCell = node.nextSibling;
|
|
11154
|
+
while (nextCell && nextCell.nodeName != "TD" && nextCell.nodeName != "TH") nextCell = nextCell.nextSibling;
|
|
11155
|
+
if (nextCell) {
|
|
11156
|
+
let parent = nextCell;
|
|
11157
|
+
for (;;) {
|
|
11158
|
+
let first = parent.firstChild;
|
|
11159
|
+
if (!first || !isElt(first) || first.contentEditable == "false" || /^(BR|IMG)$/.test(first.nodeName)) break;
|
|
11160
|
+
parent = first;
|
|
11161
|
+
}
|
|
11162
|
+
parent.insertBefore(node, parent.firstChild);
|
|
11163
|
+
if (focusNode == node) view.domSelection().collapse(node, focusOffset);
|
|
11164
|
+
} else node.parentNode.removeChild(node);
|
|
11048
11165
|
}
|
|
11049
|
-
return {
|
|
11050
|
-
start,
|
|
11051
|
-
endA,
|
|
11052
|
-
endB
|
|
11053
|
-
};
|
|
11054
11166
|
}
|
|
11055
11167
|
/**
|
|
11056
11168
|
An editor view manages the DOM structure that represents an
|
|
@@ -11121,8 +11233,10 @@ var EditorView = class {
|
|
|
11121
11233
|
updateCursorWrapper(this);
|
|
11122
11234
|
this.nodeViews = buildNodeViews(this);
|
|
11123
11235
|
this.docView = docViewDesc(this.state.doc, computeDocDeco(this), viewDecorations(this), this.dom, this);
|
|
11124
|
-
this.domObserver = new DOMObserver(this
|
|
11236
|
+
this.domObserver = new DOMObserver(this);
|
|
11237
|
+
this.domSel = new DOMSelState(this);
|
|
11125
11238
|
this.domObserver.start();
|
|
11239
|
+
this.domSel.read();
|
|
11126
11240
|
initInput(this);
|
|
11127
11241
|
this.updatePluginViews();
|
|
11128
11242
|
}
|
|
@@ -11203,27 +11317,20 @@ var EditorView = class {
|
|
|
11203
11317
|
let updateDoc = redraw || !this.docView.matchesNode(state.doc, outerDeco, innerDeco);
|
|
11204
11318
|
if (updateDoc || !state.selection.eq(prev.selection)) updateSel = true;
|
|
11205
11319
|
let oldScrollPos = scroll == "preserve" && updateSel && this.dom.style.overflowAnchor == null && storeScrollPos(this);
|
|
11206
|
-
if (updateSel) {
|
|
11207
|
-
this.
|
|
11208
|
-
let forceSelUpdate = updateDoc && (ie$1 || chrome) && !this.composing && !prev.selection.empty && !state.selection.empty && selectionContextChanged(prev.selection, state.selection);
|
|
11320
|
+
if (updateSel) this.domObserver.stopped(() => {
|
|
11321
|
+
let forceSelUpdate = updateDoc && chrome && !this.composing && !prev.selection.empty && !state.selection.empty && selectionContextChanged(prev.selection, state.selection);
|
|
11209
11322
|
if (updateDoc) {
|
|
11210
|
-
let chromeKludge = chrome ? this.trackWrites = this.
|
|
11323
|
+
let chromeKludge = chrome ? this.trackWrites = this.domSel.range.focusNode : null;
|
|
11211
11324
|
if (this.composing) this.input.compositionNode = findCompositionNode(this);
|
|
11212
|
-
if (redraw || !this.docView.update(state.doc, outerDeco, innerDeco, this)) {
|
|
11213
|
-
this.docView.
|
|
11325
|
+
if (redraw || !this.docView.update(state.doc, outerDeco, innerDeco, this, -1)) {
|
|
11326
|
+
let prevOuter = this.docView.outerDeco;
|
|
11214
11327
|
this.docView.destroy();
|
|
11215
|
-
this.docView = docViewDesc(state.doc, outerDeco, innerDeco, this.dom, this);
|
|
11328
|
+
this.docView = docViewDesc(state.doc, outerDeco, innerDeco, this.dom, this, prevOuter);
|
|
11216
11329
|
}
|
|
11217
11330
|
if (chromeKludge && (!this.trackWrites || !this.dom.contains(this.trackWrites))) forceSelUpdate = true;
|
|
11218
11331
|
}
|
|
11219
|
-
|
|
11220
|
-
|
|
11221
|
-
else {
|
|
11222
|
-
syncNodeSelection(this, state.selection);
|
|
11223
|
-
this.domObserver.setCurSelection();
|
|
11224
|
-
}
|
|
11225
|
-
this.domObserver.start();
|
|
11226
|
-
}
|
|
11332
|
+
this.domSel.sync(forceSelUpdate);
|
|
11333
|
+
});
|
|
11227
11334
|
this.updatePluginViews(prev);
|
|
11228
11335
|
if (((_a = this.dragging) === null || _a === void 0 ? void 0 : _a.node) && !prev.doc.eq(state.doc)) this.updateDraggedNode(this.dragging, prev);
|
|
11229
11336
|
if (scroll == "reset") this.dom.scrollTop = 0;
|
|
@@ -11234,8 +11341,8 @@ var EditorView = class {
|
|
|
11234
11341
|
@internal
|
|
11235
11342
|
*/
|
|
11236
11343
|
scrollToSelection() {
|
|
11237
|
-
let startDOM = this.
|
|
11238
|
-
if (!startDOM || !
|
|
11344
|
+
let startDOM = this.domSel.range.focusNode;
|
|
11345
|
+
if (!startDOM || !this.domSel.active);
|
|
11239
11346
|
else if (this.someProp("handleScrollToSelection", (f) => f(this)));
|
|
11240
11347
|
else if (this.state.selection instanceof NodeSelection) {
|
|
11241
11348
|
let target = this.docView.domAfterPos(this.state.selection.from);
|
|
@@ -11289,26 +11396,14 @@ var EditorView = class {
|
|
|
11289
11396
|
Query whether the view has focus.
|
|
11290
11397
|
*/
|
|
11291
11398
|
hasFocus() {
|
|
11292
|
-
if (ie$1) {
|
|
11293
|
-
let node = this.root.activeElement;
|
|
11294
|
-
if (node == this.dom) return true;
|
|
11295
|
-
if (!node || !this.dom.contains(node)) return false;
|
|
11296
|
-
while (node && this.dom != node && this.dom.contains(node)) {
|
|
11297
|
-
if (node.contentEditable == "false") return false;
|
|
11298
|
-
node = node.parentElement;
|
|
11299
|
-
}
|
|
11300
|
-
return true;
|
|
11301
|
-
}
|
|
11302
11399
|
return this.root.activeElement == this.dom;
|
|
11303
11400
|
}
|
|
11304
11401
|
/**
|
|
11305
11402
|
Focus the editor.
|
|
11306
11403
|
*/
|
|
11307
11404
|
focus() {
|
|
11308
|
-
this.domObserver.stop();
|
|
11309
11405
|
if (this.editable) focusPreventScroll(this.dom);
|
|
11310
|
-
|
|
11311
|
-
this.domObserver.start();
|
|
11406
|
+
this.domSel.sync();
|
|
11312
11407
|
}
|
|
11313
11408
|
/**
|
|
11314
11409
|
Get the document root in which the editor exists. This will
|
|
@@ -11317,8 +11412,10 @@ var EditorView = class {
|
|
|
11317
11412
|
root if the editor is inside one.
|
|
11318
11413
|
*/
|
|
11319
11414
|
get root() {
|
|
11415
|
+
let connected = this.dom.isConnected !== false;
|
|
11416
|
+
if (!connected) this._root = null;
|
|
11320
11417
|
let cached = this._root;
|
|
11321
|
-
if (cached == null) {
|
|
11418
|
+
if (cached == null && connected) {
|
|
11322
11419
|
for (let search = this.dom.parentNode; search; search = search.parentNode) if (search.nodeType == 9 || search.nodeType == 11 && search.host) {
|
|
11323
11420
|
if (!search.getSelection) Object.getPrototypeOf(search).getSelection = () => search.ownerDocument.getSelection();
|
|
11324
11421
|
return this._root = search;
|
|
@@ -11441,9 +11538,10 @@ var EditorView = class {
|
|
|
11441
11538
|
destroy() {
|
|
11442
11539
|
if (!this.docView) return;
|
|
11443
11540
|
destroyInput(this);
|
|
11541
|
+
this.domSel.destroy();
|
|
11444
11542
|
this.destroyPluginViews();
|
|
11445
11543
|
if (this.mounted) {
|
|
11446
|
-
this.docView.update(this.state.doc, [], viewDecorations(this), this);
|
|
11544
|
+
this.docView.update(this.state.doc, [], viewDecorations(this), this, -1);
|
|
11447
11545
|
this.dom.textContent = "";
|
|
11448
11546
|
} else if (this.dom.parentNode) this.dom.parentNode.removeChild(this.dom);
|
|
11449
11547
|
this.docView.destroy();
|
|
@@ -11467,19 +11565,6 @@ var EditorView = class {
|
|
|
11467
11565
|
/**
|
|
11468
11566
|
@internal
|
|
11469
11567
|
*/
|
|
11470
|
-
domSelectionRange() {
|
|
11471
|
-
let sel = this.dom.isConnected !== false && this.domSelection();
|
|
11472
|
-
if (!sel) return {
|
|
11473
|
-
focusNode: null,
|
|
11474
|
-
focusOffset: 0,
|
|
11475
|
-
anchorNode: null,
|
|
11476
|
-
anchorOffset: 0
|
|
11477
|
-
};
|
|
11478
|
-
return safari && this.root.nodeType === 11 && deepActiveElement(this.dom.ownerDocument) == this.dom && safariShadowSelectionRange(this, sel) || sel;
|
|
11479
|
-
}
|
|
11480
|
-
/**
|
|
11481
|
-
@internal
|
|
11482
|
-
*/
|
|
11483
11568
|
domSelection() {
|
|
11484
11569
|
return this.root.getSelection();
|
|
11485
11570
|
}
|
|
@@ -12372,25 +12457,47 @@ var blur = () => ({ editor, view }) => {
|
|
|
12372
12457
|
var clearContent = (emitUpdate = true) => ({ commands }) => {
|
|
12373
12458
|
return commands.setContent("", { emitUpdate });
|
|
12374
12459
|
};
|
|
12375
|
-
var clearNodes = () => ({
|
|
12460
|
+
var clearNodes = () => ({ tr, dispatch }) => {
|
|
12376
12461
|
const { selection } = tr;
|
|
12377
12462
|
const { ranges } = selection;
|
|
12378
12463
|
if (!dispatch) return true;
|
|
12464
|
+
const startMapsLength = tr.mapping.maps.length;
|
|
12379
12465
|
ranges.forEach(({ $from, $to }) => {
|
|
12380
|
-
|
|
12381
|
-
|
|
12382
|
-
|
|
12383
|
-
|
|
12384
|
-
|
|
12385
|
-
|
|
12386
|
-
if (!nodeRange) return;
|
|
12387
|
-
const targetLiftDepth = liftTarget(nodeRange);
|
|
12388
|
-
if (node.type.isTextblock) {
|
|
12389
|
-
const { defaultType } = $mappedFrom.parent.contentMatchAt($mappedFrom.index());
|
|
12390
|
-
tr.setNodeMarkup(nodeRange.start, defaultType);
|
|
12391
|
-
}
|
|
12392
|
-
if (targetLiftDepth || targetLiftDepth === 0) tr.lift(nodeRange, targetLiftDepth);
|
|
12466
|
+
const from = $from.pos;
|
|
12467
|
+
const to = $to.pos;
|
|
12468
|
+
const depthMapping = tr.mapping.slice(startMapsLength);
|
|
12469
|
+
let maxSweeps = 1;
|
|
12470
|
+
tr.doc.nodesBetween(depthMapping.map(from), depthMapping.map(to), (_node, pos) => {
|
|
12471
|
+
maxSweeps = Math.max(maxSweeps, tr.doc.resolve(pos).depth + 1);
|
|
12393
12472
|
});
|
|
12473
|
+
for (let sweep = 0; sweep < maxSweeps; sweep += 1) {
|
|
12474
|
+
const docBefore = tr.doc;
|
|
12475
|
+
const sweepMapsLength = tr.mapping.maps.length;
|
|
12476
|
+
const rangeMapping = tr.mapping.slice(startMapsLength);
|
|
12477
|
+
let cachedMapsLength = sweepMapsLength;
|
|
12478
|
+
let sweepMapping = tr.mapping.slice(sweepMapsLength);
|
|
12479
|
+
const mappedFrom = rangeMapping.map(from);
|
|
12480
|
+
const mappedTo = rangeMapping.map(to);
|
|
12481
|
+
docBefore.nodesBetween(mappedFrom, mappedTo, (node, pos) => {
|
|
12482
|
+
if (node.type.isText) return;
|
|
12483
|
+
if (tr.mapping.maps.length !== cachedMapsLength) {
|
|
12484
|
+
cachedMapsLength = tr.mapping.maps.length;
|
|
12485
|
+
sweepMapping = tr.mapping.slice(sweepMapsLength);
|
|
12486
|
+
}
|
|
12487
|
+
const $mappedFrom = tr.doc.resolve(sweepMapping.map(pos));
|
|
12488
|
+
const $mappedTo = tr.doc.resolve(sweepMapping.map(pos + node.nodeSize));
|
|
12489
|
+
const nodeRange = $mappedFrom.blockRange($mappedTo);
|
|
12490
|
+
if (!nodeRange) return;
|
|
12491
|
+
const targetLiftDepth = liftTarget(nodeRange);
|
|
12492
|
+
if (node.type.isTextblock) {
|
|
12493
|
+
const { defaultType } = $mappedFrom.parent.contentMatchAt($mappedFrom.index());
|
|
12494
|
+
const target = tr.doc.nodeAt(nodeRange.start);
|
|
12495
|
+
if (defaultType && target && !target.hasMarkup(defaultType) && defaultType.validContent(target.content)) tr.setNodeMarkup(nodeRange.start, defaultType);
|
|
12496
|
+
}
|
|
12497
|
+
if (targetLiftDepth || targetLiftDepth === 0) tr.lift(nodeRange, targetLiftDepth);
|
|
12498
|
+
});
|
|
12499
|
+
if (tr.doc.eq(docBefore)) break;
|
|
12500
|
+
}
|
|
12394
12501
|
});
|
|
12395
12502
|
return true;
|
|
12396
12503
|
};
|
|
@@ -12490,6 +12597,7 @@ var deleteSelection = () => ({ state, dispatch }) => {
|
|
|
12490
12597
|
if (dispatch) {
|
|
12491
12598
|
const tr = state.tr;
|
|
12492
12599
|
const { ranges } = state.selection;
|
|
12600
|
+
const marks = state.selection instanceof TextSelection ? state.selection.$from.marksAcross(state.selection.$to) : null;
|
|
12493
12601
|
const mapFrom = tr.steps.length;
|
|
12494
12602
|
ranges.forEach((range) => {
|
|
12495
12603
|
const mapping = tr.mapping.slice(mapFrom);
|
|
@@ -12497,6 +12605,7 @@ var deleteSelection = () => ({ state, dispatch }) => {
|
|
|
12497
12605
|
tr.deleteRange(from, to);
|
|
12498
12606
|
});
|
|
12499
12607
|
if (!tr.selection.empty) tr.setSelection(TextSelection.near(tr.doc.resolve(tr.selection.from)));
|
|
12608
|
+
if (marks) tr.ensureMarks(marks);
|
|
12500
12609
|
tr.scrollIntoView();
|
|
12501
12610
|
dispatch(tr);
|
|
12502
12611
|
}
|
|
@@ -13268,25 +13377,114 @@ function getHTMLFromFragment(fragment, schema) {
|
|
|
13268
13377
|
container.appendChild(documentFragment);
|
|
13269
13378
|
return container.innerHTML;
|
|
13270
13379
|
}
|
|
13271
|
-
|
|
13272
|
-
|
|
13380
|
+
/**
|
|
13381
|
+
* Combines external attribute structure with local attribute behavior.
|
|
13382
|
+
* @param attributes The attributes from resolved local extensions
|
|
13383
|
+
* @param schema The schema that defines the allowed attributes
|
|
13384
|
+
* @returns Only attributes present in the schema
|
|
13385
|
+
*/
|
|
13386
|
+
function getSchemaAttributes(attributes, schema) {
|
|
13387
|
+
const attributesByType = /* @__PURE__ */ new Map();
|
|
13388
|
+
for (const attribute of attributes) {
|
|
13389
|
+
var _attributesByType$get;
|
|
13390
|
+
const typeAttributes = (_attributesByType$get = attributesByType.get(attribute.type)) !== null && _attributesByType$get !== void 0 ? _attributesByType$get : /* @__PURE__ */ new Map();
|
|
13391
|
+
typeAttributes.set(attribute.name, attribute);
|
|
13392
|
+
attributesByType.set(attribute.type, typeAttributes);
|
|
13393
|
+
}
|
|
13394
|
+
return [...Object.values(schema.nodes), ...Object.values(schema.marks)].flatMap((type) => {
|
|
13395
|
+
var _type$spec$attrs;
|
|
13396
|
+
return Object.entries((_type$spec$attrs = type.spec.attrs) !== null && _type$spec$attrs !== void 0 ? _type$spec$attrs : {}).map(([name, spec]) => {
|
|
13397
|
+
var _attributesByType$get2;
|
|
13398
|
+
const local = (_attributesByType$get2 = attributesByType.get(type.name)) === null || _attributesByType$get2 === void 0 ? void 0 : _attributesByType$get2.get(name);
|
|
13399
|
+
const hasDefault = Object.hasOwn(spec, "default");
|
|
13400
|
+
return {
|
|
13401
|
+
type: type.name,
|
|
13402
|
+
name,
|
|
13403
|
+
attribute: {
|
|
13404
|
+
rendered: true,
|
|
13405
|
+
renderHTML: null,
|
|
13406
|
+
parseHTML: null,
|
|
13407
|
+
keepOnSplit: true,
|
|
13408
|
+
...local === null || local === void 0 ? void 0 : local.attribute,
|
|
13409
|
+
default: spec.default,
|
|
13410
|
+
isRequired: !hasDefault,
|
|
13411
|
+
validate: spec.validate
|
|
13412
|
+
}
|
|
13413
|
+
};
|
|
13414
|
+
});
|
|
13415
|
+
});
|
|
13416
|
+
}
|
|
13417
|
+
var nodeSchemaFields = {
|
|
13418
|
+
content: "string",
|
|
13419
|
+
marks: "string",
|
|
13420
|
+
group: "string",
|
|
13421
|
+
inline: "boolean",
|
|
13422
|
+
atom: "boolean",
|
|
13423
|
+
selectable: "boolean",
|
|
13424
|
+
draggable: "boolean",
|
|
13425
|
+
code: "boolean",
|
|
13426
|
+
whitespace: ["pre", "normal"],
|
|
13427
|
+
definingAsContext: "boolean",
|
|
13428
|
+
definingForContent: "boolean",
|
|
13429
|
+
defining: "boolean",
|
|
13430
|
+
isolating: "boolean",
|
|
13431
|
+
linebreakReplacement: "boolean"
|
|
13432
|
+
};
|
|
13433
|
+
var markSchemaFields = {
|
|
13434
|
+
inclusive: "boolean",
|
|
13435
|
+
excludes: "string",
|
|
13436
|
+
group: "string",
|
|
13437
|
+
spanning: "boolean",
|
|
13438
|
+
code: "boolean"
|
|
13439
|
+
};
|
|
13440
|
+
function structuralFields(spec, fields, path) {
|
|
13441
|
+
return Object.fromEntries(Object.entries(fields).flatMap(([name, expected]) => {
|
|
13442
|
+
const value = spec[name];
|
|
13443
|
+
if (value === void 0) return [];
|
|
13444
|
+
if (!(typeof expected === "string" ? typeof value === expected : typeof value === "string" && expected.includes(value))) throw new RangeError(`Invalid schemaSpec field '${path}.${name}'`);
|
|
13445
|
+
return [[name, value]];
|
|
13446
|
+
}));
|
|
13447
|
+
}
|
|
13448
|
+
function mergeType(name, local, external, fields) {
|
|
13449
|
+
return {
|
|
13450
|
+
...Object.fromEntries(Object.entries(local).filter(([key]) => key !== "attrs" && !Object.hasOwn(fields, key))),
|
|
13451
|
+
...structuralFields(external, fields, name),
|
|
13452
|
+
attrs: external.attrs
|
|
13453
|
+
};
|
|
13454
|
+
}
|
|
13455
|
+
function checkTypes(local, external, kind) {
|
|
13456
|
+
for (const name of Object.keys(external)) if (!Object.hasOwn(local, name)) throw new RangeError(`schemaSpec requires a local ${kind} extension named '${name}'`);
|
|
13457
|
+
for (const name of Object.keys(local)) if (!Object.hasOwn(external, name)) throw new RangeError(`Local ${kind} extension '${name}' is not in schemaSpec`);
|
|
13273
13458
|
}
|
|
13274
13459
|
/**
|
|
13275
|
-
*
|
|
13276
|
-
*
|
|
13277
|
-
* @param
|
|
13278
|
-
* @
|
|
13279
|
-
* @param props Optional props to pass to function.
|
|
13460
|
+
* Combines external structure with local DOM behavior and extension metadata.
|
|
13461
|
+
* @param local The specifications generated by resolved local extensions
|
|
13462
|
+
* @param external The schema compiled from the provided specification
|
|
13463
|
+
* @returns A specification in the external schema's node and mark order
|
|
13280
13464
|
*/
|
|
13281
|
-
function
|
|
13282
|
-
|
|
13283
|
-
|
|
13284
|
-
|
|
13285
|
-
|
|
13286
|
-
|
|
13465
|
+
function mergeSchemaSpec(local, external) {
|
|
13466
|
+
checkTypes(local.nodes, external.nodes, "node");
|
|
13467
|
+
checkTypes(local.marks, external.marks, "mark");
|
|
13468
|
+
let nodes = external.spec.nodes;
|
|
13469
|
+
let marks = external.spec.marks;
|
|
13470
|
+
external.spec.nodes.forEach((name, spec) => {
|
|
13471
|
+
nodes = nodes.update(name, mergeType(name, local.nodes[name], spec, nodeSchemaFields));
|
|
13472
|
+
});
|
|
13473
|
+
external.spec.marks.forEach((name, spec) => {
|
|
13474
|
+
marks = marks.update(name, mergeType(name, local.marks[name], spec, markSchemaFields));
|
|
13475
|
+
});
|
|
13476
|
+
return {
|
|
13477
|
+
topNode: external.topNodeType.name,
|
|
13478
|
+
nodes,
|
|
13479
|
+
marks
|
|
13480
|
+
};
|
|
13287
13481
|
}
|
|
13288
|
-
|
|
13289
|
-
|
|
13482
|
+
/**
|
|
13483
|
+
* Find duplicates in an array.
|
|
13484
|
+
*/
|
|
13485
|
+
function findDuplicates(items) {
|
|
13486
|
+
const filtered = items.filter((el, index) => items.indexOf(el) !== index);
|
|
13487
|
+
return Array.from(new Set(filtered));
|
|
13290
13488
|
}
|
|
13291
13489
|
function splitExtensions(extensions) {
|
|
13292
13490
|
return {
|
|
@@ -13368,6 +13566,26 @@ function getAttributesFromExtensions(extensions) {
|
|
|
13368
13566
|
});
|
|
13369
13567
|
return extensionAttributes;
|
|
13370
13568
|
}
|
|
13569
|
+
function isFunction(value) {
|
|
13570
|
+
return typeof value === "function";
|
|
13571
|
+
}
|
|
13572
|
+
/**
|
|
13573
|
+
* Optionally calls `value` as a function.
|
|
13574
|
+
* Otherwise it is returned directly.
|
|
13575
|
+
* @param value Function or any value.
|
|
13576
|
+
* @param context Optional context to bind to function.
|
|
13577
|
+
* @param props Optional props to pass to function.
|
|
13578
|
+
*/
|
|
13579
|
+
function callOrReturn(value, context = void 0, ...props) {
|
|
13580
|
+
if (isFunction(value)) {
|
|
13581
|
+
if (context) return value.bind(context)(...props);
|
|
13582
|
+
return value(...props);
|
|
13583
|
+
}
|
|
13584
|
+
return value;
|
|
13585
|
+
}
|
|
13586
|
+
function isEmptyObject(value = {}) {
|
|
13587
|
+
return Object.keys(value).length === 0 && value.constructor === Object;
|
|
13588
|
+
}
|
|
13371
13589
|
/** Splits a CSS style string into declarations, ignoring semicolons inside quotes/parentheses. */
|
|
13372
13590
|
function splitStyleDeclarations(styles) {
|
|
13373
13591
|
const result = [];
|
|
@@ -13515,16 +13733,16 @@ function buildAttributeSpec(extensionAttribute) {
|
|
|
13515
13733
|
return [extensionAttribute.name, spec];
|
|
13516
13734
|
}
|
|
13517
13735
|
/**
|
|
13518
|
-
*
|
|
13736
|
+
* Builds schema specifications without compiling content expressions.
|
|
13519
13737
|
* @param extensions An array of Tiptap extensions
|
|
13520
13738
|
* @param editor The editor instance
|
|
13521
|
-
* @
|
|
13739
|
+
* @param allAttributes The effective attributes used for schema and DOM behavior
|
|
13740
|
+
* @returns The node and mark specifications
|
|
13522
13741
|
*/
|
|
13523
|
-
function
|
|
13742
|
+
function getSchemaSpecByResolvedExtensions(extensions, editor, allAttributes = getAttributesFromExtensions(extensions)) {
|
|
13524
13743
|
var _nodeExtensions$find;
|
|
13525
|
-
const allAttributes = getAttributesFromExtensions(extensions);
|
|
13526
13744
|
const { nodeExtensions, markExtensions } = splitExtensions(extensions);
|
|
13527
|
-
return
|
|
13745
|
+
return {
|
|
13528
13746
|
topNode: (_nodeExtensions$find = nodeExtensions.find((extension) => getExtensionField(extension, "topNode"))) === null || _nodeExtensions$find === void 0 ? void 0 : _nodeExtensions$find.name,
|
|
13529
13747
|
nodes: Object.fromEntries(nodeExtensions.map((extension) => {
|
|
13530
13748
|
const extensionAttributes = allAttributes.filter((attribute) => attribute.type === extension.name);
|
|
@@ -13599,14 +13817,21 @@ function getSchemaByResolvedExtensions(extensions, editor) {
|
|
|
13599
13817
|
});
|
|
13600
13818
|
return [extension.name, schema];
|
|
13601
13819
|
}))
|
|
13602
|
-
}
|
|
13820
|
+
};
|
|
13603
13821
|
}
|
|
13604
13822
|
/**
|
|
13605
|
-
*
|
|
13823
|
+
* Creates a ProseMirror schema from resolved extensions.
|
|
13824
|
+
* @param extensions The flattened and sorted extensions
|
|
13825
|
+
* @param editor The editor instance
|
|
13826
|
+
* @param schemaSpec The external structure to use with local extension behavior
|
|
13827
|
+
* @returns A ProseMirror schema
|
|
13606
13828
|
*/
|
|
13607
|
-
function
|
|
13608
|
-
|
|
13609
|
-
|
|
13829
|
+
function getSchemaByResolvedExtensions(extensions, editor, schemaSpec) {
|
|
13830
|
+
if (schemaSpec === void 0) return new Schema(getSchemaSpecByResolvedExtensions(extensions, editor));
|
|
13831
|
+
const duplicates = findDuplicates(extensions.filter((extension) => extension.type !== "extension").map((extension) => extension.name));
|
|
13832
|
+
if (duplicates.length) throw new RangeError(`Duplicate local schema types: ${duplicates.join(", ")}`);
|
|
13833
|
+
const external = new Schema(schemaSpec);
|
|
13834
|
+
return new Schema(mergeSchemaSpec(getSchemaSpecByResolvedExtensions(extensions, editor, getSchemaAttributes(getAttributesFromExtensions(extensions), external)), external));
|
|
13610
13835
|
}
|
|
13611
13836
|
/**
|
|
13612
13837
|
* Sort extensions by priority.
|
|
@@ -13743,6 +13968,7 @@ function simplifyChangedRanges(changes) {
|
|
|
13743
13968
|
function getChangedRanges(transform) {
|
|
13744
13969
|
const { mapping, steps } = transform;
|
|
13745
13970
|
const changes = [];
|
|
13971
|
+
const inverted = mapping.invert();
|
|
13746
13972
|
mapping.maps.forEach((stepMap, index) => {
|
|
13747
13973
|
const ranges = [];
|
|
13748
13974
|
if (!stepMap.ranges.length) {
|
|
@@ -13758,11 +13984,12 @@ function getChangedRanges(transform) {
|
|
|
13758
13984
|
to
|
|
13759
13985
|
});
|
|
13760
13986
|
});
|
|
13987
|
+
const rest = mapping.slice(index);
|
|
13761
13988
|
ranges.forEach(({ from, to }) => {
|
|
13762
|
-
const newStart =
|
|
13763
|
-
const newEnd =
|
|
13764
|
-
const oldStart =
|
|
13765
|
-
const oldEnd =
|
|
13989
|
+
const newStart = rest.map(from, -1);
|
|
13990
|
+
const newEnd = rest.map(to);
|
|
13991
|
+
const oldStart = inverted.map(newStart, -1);
|
|
13992
|
+
const oldEnd = inverted.map(newEnd);
|
|
13766
13993
|
changes.push({
|
|
13767
13994
|
oldRange: {
|
|
13768
13995
|
from: oldStart,
|
|
@@ -14004,6 +14231,36 @@ function isNodeSelection(value) {
|
|
|
14004
14231
|
return value instanceof NodeSelection;
|
|
14005
14232
|
}
|
|
14006
14233
|
/**
|
|
14234
|
+
* Checks if a value is a ProseMirror step
|
|
14235
|
+
* @param value The value to check
|
|
14236
|
+
* @returns - A boolean, if the boolean is true the value is a ProseMirror Step
|
|
14237
|
+
* @example ```js
|
|
14238
|
+
* isProseMirrorStep(transaction.steps[0])
|
|
14239
|
+
* ```
|
|
14240
|
+
*/
|
|
14241
|
+
function isProseMirrorStep(value) {
|
|
14242
|
+
if (value === null || typeof value !== "object") return false;
|
|
14243
|
+
const step = value;
|
|
14244
|
+
if (typeof step.apply !== "function" || typeof step.getMap !== "function" || typeof step.invert !== "function" || typeof step.map !== "function" || typeof step.merge !== "function" || typeof step.toJSON !== "function") return false;
|
|
14245
|
+
return true;
|
|
14246
|
+
}
|
|
14247
|
+
/**
|
|
14248
|
+
* Checks if a value is a ProseMirror replace step result
|
|
14249
|
+
* @param value The value to check
|
|
14250
|
+
* @returns - A boolean, if the boolean is true the value is a ProseMirror ReplaceStep
|
|
14251
|
+
* @example ```js
|
|
14252
|
+
* isProseMirrorReplaceStep(transaction.steps[0])
|
|
14253
|
+
* ```
|
|
14254
|
+
*/
|
|
14255
|
+
function isProseMirrorReplaceStep(value) {
|
|
14256
|
+
if (value === null || typeof value !== "object") return false;
|
|
14257
|
+
const step = value;
|
|
14258
|
+
if (!isProseMirrorStep(step)) return false;
|
|
14259
|
+
const json = step.toJSON();
|
|
14260
|
+
if (json === null || typeof json !== "object" || json.stepType !== "replace") return false;
|
|
14261
|
+
return true;
|
|
14262
|
+
}
|
|
14263
|
+
/**
|
|
14007
14264
|
* A class that represents a mappable position in the editor. It can be extended
|
|
14008
14265
|
* by other extensions to add additional position mapping capabilities.
|
|
14009
14266
|
*/
|
|
@@ -14303,6 +14560,80 @@ var splitListItem = (typeOrName, overrideAttrs = {}) => ({ tr, state, dispatch,
|
|
|
14303
14560
|
}
|
|
14304
14561
|
return true;
|
|
14305
14562
|
};
|
|
14563
|
+
/** Creates a node when its content and required attributes are valid. */
|
|
14564
|
+
function createNode(type, content, attrs) {
|
|
14565
|
+
if (!type.validContent(content)) return null;
|
|
14566
|
+
try {
|
|
14567
|
+
return type.create(attrs, content);
|
|
14568
|
+
} catch {
|
|
14569
|
+
return null;
|
|
14570
|
+
}
|
|
14571
|
+
}
|
|
14572
|
+
/** Converts and appends the content accumulated for the current list item. */
|
|
14573
|
+
function flushPendingContent(state, itemType) {
|
|
14574
|
+
if (state.pendingContent.length === 0) return true;
|
|
14575
|
+
const item = createNode(itemType, Fragment$1.from(state.pendingContent));
|
|
14576
|
+
if (!item) return false;
|
|
14577
|
+
state.items.push(item);
|
|
14578
|
+
state.pendingContent = [];
|
|
14579
|
+
return true;
|
|
14580
|
+
}
|
|
14581
|
+
/** Appends a content node to the current item or starts a new item when needed. */
|
|
14582
|
+
function appendContentNode(node, state, itemType) {
|
|
14583
|
+
if (itemType.validContent(Fragment$1.from([...state.pendingContent, node]))) {
|
|
14584
|
+
state.pendingContent.push(node);
|
|
14585
|
+
return true;
|
|
14586
|
+
}
|
|
14587
|
+
if (!flushPendingContent(state, itemType) || !itemType.validContent(Fragment$1.from(node))) return false;
|
|
14588
|
+
state.pendingContent.push(node);
|
|
14589
|
+
return true;
|
|
14590
|
+
}
|
|
14591
|
+
/** Preserves a nested list when supported or flattens its converted items. */
|
|
14592
|
+
function appendNestedList(sourceList, state, context, convertListItems) {
|
|
14593
|
+
const nestedItems = convertListItems(sourceList, context);
|
|
14594
|
+
if (!nestedItems) return false;
|
|
14595
|
+
const nestedList = createNode(context.listType, Fragment$1.from(nestedItems), sourceList.attrs);
|
|
14596
|
+
if (!nestedList) return false;
|
|
14597
|
+
if (context.itemType.validContent(Fragment$1.from([...state.pendingContent, nestedList]))) {
|
|
14598
|
+
state.pendingContent.push(nestedList);
|
|
14599
|
+
return true;
|
|
14600
|
+
}
|
|
14601
|
+
if (!flushPendingContent(state, context.itemType)) return false;
|
|
14602
|
+
state.items.push(...nestedItems);
|
|
14603
|
+
return true;
|
|
14604
|
+
}
|
|
14605
|
+
/** Converts one source list item into one or more target list items. */
|
|
14606
|
+
function convertListItem(sourceItem, context, convertListItems) {
|
|
14607
|
+
const state = {
|
|
14608
|
+
items: [],
|
|
14609
|
+
pendingContent: []
|
|
14610
|
+
};
|
|
14611
|
+
for (let index = 0; index < sourceItem.childCount; index += 1) {
|
|
14612
|
+
const child = sourceItem.child(index);
|
|
14613
|
+
if (!(context.isListNode(child) ? appendNestedList(child, state, context, convertListItems) : appendContentNode(child, state, context.itemType))) return null;
|
|
14614
|
+
}
|
|
14615
|
+
return flushPendingContent(state, context.itemType) ? state.items : null;
|
|
14616
|
+
}
|
|
14617
|
+
/** Recursively converts all items in a source list to the target list schema. */
|
|
14618
|
+
function convertListItems(sourceList, context) {
|
|
14619
|
+
const convertedItems = [];
|
|
14620
|
+
for (let index = 0; index < sourceList.childCount; index += 1) {
|
|
14621
|
+
const items = convertListItem(sourceList.child(index), context, convertListItems);
|
|
14622
|
+
if (!items) return null;
|
|
14623
|
+
convertedItems.push(...items);
|
|
14624
|
+
}
|
|
14625
|
+
return convertedItems;
|
|
14626
|
+
}
|
|
14627
|
+
/** Finds a descendant node's position relative to its root node. */
|
|
14628
|
+
function findNodePosition(root, target) {
|
|
14629
|
+
let targetPos = null;
|
|
14630
|
+
root.descendants((node, pos) => {
|
|
14631
|
+
if (node !== target) return true;
|
|
14632
|
+
targetPos = pos;
|
|
14633
|
+
return false;
|
|
14634
|
+
});
|
|
14635
|
+
return targetPos;
|
|
14636
|
+
}
|
|
14306
14637
|
/**
|
|
14307
14638
|
* Normalise a list type attribute for comparison.
|
|
14308
14639
|
* Treats null, undefined, and "1" as equivalent (the default numeric type).
|
|
@@ -14383,6 +14714,43 @@ var toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {}) =>
|
|
|
14383
14714
|
tr.setNodeMarkup(currentList.pos, listType);
|
|
14384
14715
|
return true;
|
|
14385
14716
|
}).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
|
|
14717
|
+
if (isList(currentList.node.type.name, extensions)) {
|
|
14718
|
+
var _currentList$node$fir;
|
|
14719
|
+
const currentItemType = (_currentList$node$fir = currentList.node.firstChild) === null || _currentList$node$fir === void 0 ? void 0 : _currentList$node$fir.type;
|
|
14720
|
+
if (currentItemType && currentItemType !== itemType) {
|
|
14721
|
+
const convertedItems = convertListItems(currentList.node, {
|
|
14722
|
+
listType,
|
|
14723
|
+
itemType,
|
|
14724
|
+
isListNode: (node) => isList(node.type.name, extensions)
|
|
14725
|
+
});
|
|
14726
|
+
const convertedContent = convertedItems ? Fragment$1.from(convertedItems) : null;
|
|
14727
|
+
if (!convertedContent || !listType.validContent(convertedContent)) return false;
|
|
14728
|
+
return chain().command(() => {
|
|
14729
|
+
const { $anchor, $head } = tr.selection;
|
|
14730
|
+
const anchorParent = $anchor.parent;
|
|
14731
|
+
const headParent = $head.parent;
|
|
14732
|
+
const anchorOffset = $anchor.parentOffset;
|
|
14733
|
+
const headOffset = $head.parentOffset;
|
|
14734
|
+
let newList;
|
|
14735
|
+
try {
|
|
14736
|
+
newList = listType.create(attributes, convertedContent);
|
|
14737
|
+
} catch {
|
|
14738
|
+
return false;
|
|
14739
|
+
}
|
|
14740
|
+
tr.replaceWith(currentList.pos, currentList.pos + currentList.node.nodeSize, newList);
|
|
14741
|
+
if (anchorParent.inlineContent && headParent.inlineContent) {
|
|
14742
|
+
const anchorParentPos = findNodePosition(newList, anchorParent);
|
|
14743
|
+
const headParentPos = findNodePosition(newList, headParent);
|
|
14744
|
+
if (anchorParentPos !== null && headParentPos !== null) {
|
|
14745
|
+
const anchor = currentList.pos + anchorParentPos + 2 + anchorOffset;
|
|
14746
|
+
const head = currentList.pos + headParentPos + 2 + headOffset;
|
|
14747
|
+
tr.setSelection(TextSelection.create(tr.doc, anchor, head));
|
|
14748
|
+
}
|
|
14749
|
+
}
|
|
14750
|
+
return true;
|
|
14751
|
+
}).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
|
|
14752
|
+
}
|
|
14753
|
+
}
|
|
14386
14754
|
}
|
|
14387
14755
|
if (!keepMarks || !marks || !dispatch) return chain().command(() => {
|
|
14388
14756
|
if (can().wrapInList(listType, attributes)) return true;
|
|
@@ -15316,6 +15684,34 @@ function isPlainObject(value) {
|
|
|
15316
15684
|
function isValidCSSStyleValue(value) {
|
|
15317
15685
|
return typeof value === "string" && value.trim().length > 0 && !/[;{}]/.test(value);
|
|
15318
15686
|
}
|
|
15687
|
+
function dedentLine(line, indentSize) {
|
|
15688
|
+
return line.replace(/^[ \t]*/, (whitespace) => {
|
|
15689
|
+
const tabSize = 4;
|
|
15690
|
+
let columns = 0;
|
|
15691
|
+
for (const character of whitespace) columns += character === " " ? tabSize - columns % tabSize : 1;
|
|
15692
|
+
return " ".repeat(Math.max(0, columns - indentSize));
|
|
15693
|
+
});
|
|
15694
|
+
}
|
|
15695
|
+
function continuesParagraph(line, blockTokens) {
|
|
15696
|
+
const source = `text\n${line}\n`;
|
|
15697
|
+
const token = blockTokens(source)[0];
|
|
15698
|
+
return ((token === null || token === void 0 ? void 0 : token.type) === "paragraph" || (token === null || token === void 0 ? void 0 : token.type) === "text") && token.raw === source;
|
|
15699
|
+
}
|
|
15700
|
+
/** Joins paragraph continuation lines and leaves nested blocks for separate parsing. */
|
|
15701
|
+
function parseContinuation(mainContent, nestedContent, lexer) {
|
|
15702
|
+
var _lexer$isParagraphCon;
|
|
15703
|
+
const lines = nestedContent.split("\n");
|
|
15704
|
+
const isContinuation = (_lexer$isParagraphCon = lexer.isParagraphContinuation) !== null && _lexer$isParagraphCon !== void 0 ? _lexer$isParagraphCon : ((line) => continuesParagraph(line, lexer.blockTokens));
|
|
15705
|
+
let continuationLength = 0;
|
|
15706
|
+
for (const line of lines) {
|
|
15707
|
+
if (!line.trim() || !isContinuation(line)) break;
|
|
15708
|
+
continuationLength += 1;
|
|
15709
|
+
}
|
|
15710
|
+
return {
|
|
15711
|
+
mainContent: [mainContent, ...lines.slice(0, continuationLength).map((line) => line.trimStart())].join("\n"),
|
|
15712
|
+
nestedContent: lines.slice(continuationLength).join("\n")
|
|
15713
|
+
};
|
|
15714
|
+
}
|
|
15319
15715
|
/**
|
|
15320
15716
|
* Parses markdown text into hierarchical indented blocks with proper nesting.
|
|
15321
15717
|
*
|
|
@@ -15398,7 +15794,9 @@ function parseIndentedBlocks(src, config, lexer) {
|
|
|
15398
15794
|
let nestedTokens;
|
|
15399
15795
|
const nestedContent = itemContent.slice(1);
|
|
15400
15796
|
if (nestedContent.length > 0) {
|
|
15401
|
-
const
|
|
15797
|
+
const continuation = parseContinuation(mainContent, nestedContent.map((nestedLine) => dedentLine(nestedLine, indentLevel + baseIndentSize)).join("\n"), lexer);
|
|
15798
|
+
itemData.mainContent = continuation.mainContent;
|
|
15799
|
+
const dedentedNested = continuation.nestedContent;
|
|
15402
15800
|
if (dedentedNested.trim()) {
|
|
15403
15801
|
if (config.customNestedParser) nestedTokens = config.customNestedParser(dedentedNested);
|
|
15404
15802
|
else nestedTokens = lexer.blockTokens(dedentedNested);
|
|
@@ -15410,7 +15808,7 @@ function parseIndentedBlocks(src, config, lexer) {
|
|
|
15410
15808
|
if (items.length === 0) return;
|
|
15411
15809
|
return {
|
|
15412
15810
|
items,
|
|
15413
|
-
raw: totalRaw
|
|
15811
|
+
raw: totalRaw.slice(0, src.length)
|
|
15414
15812
|
};
|
|
15415
15813
|
}
|
|
15416
15814
|
/**
|
|
@@ -15433,6 +15831,7 @@ function parseIndentedBlocks(src, config, lexer) {
|
|
|
15433
15831
|
* @param options - Optional rendering options
|
|
15434
15832
|
* @param options.alignNestedToPrefix - Indent nested content to the width of the prefix
|
|
15435
15833
|
* instead of the configured indent size, when the configured one is narrower
|
|
15834
|
+
* @param options.indentMainContent - Indent continuation lines in the opening paragraph
|
|
15436
15835
|
* @returns The rendered markdown string
|
|
15437
15836
|
*
|
|
15438
15837
|
* @example
|
|
@@ -15482,7 +15881,8 @@ function renderNestedMarkdownContent(node, h, prefixOrGenerator, ctx, options) {
|
|
|
15482
15881
|
if (!node || !Array.isArray(node.content)) return "";
|
|
15483
15882
|
const prefix = typeof prefixOrGenerator === "function" ? prefixOrGenerator(ctx) : prefixOrGenerator;
|
|
15484
15883
|
const [content, ...children] = node.content;
|
|
15485
|
-
|
|
15884
|
+
const mainContent = h.renderChildren([content]);
|
|
15885
|
+
let output = `${prefix}${(options === null || options === void 0 ? void 0 : options.indentMainContent) ? mainContent.split("\n").map((line, index) => index === 0 ? line : h.indent(line)).join("\n") : mainContent}`;
|
|
15486
15886
|
if (children && children.length > 0) children.forEach((child, index) => {
|
|
15487
15887
|
var _h$renderChild, _h$renderChild2;
|
|
15488
15888
|
const childContent = (_h$renderChild = (_h$renderChild2 = h.renderChild) === null || _h$renderChild2 === void 0 ? void 0 : _h$renderChild2.call(h, child, index + 1)) !== null && _h$renderChild !== void 0 ? _h$renderChild : h.renderChildren([child]);
|
|
@@ -15671,8 +16071,17 @@ function inputRulesPlugin(props) {
|
|
|
15671
16071
|
return null;
|
|
15672
16072
|
},
|
|
15673
16073
|
apply(tr, prev, state) {
|
|
16074
|
+
var _tr$getMeta;
|
|
15674
16075
|
const stored = tr.getMeta(plugin);
|
|
15675
16076
|
if (stored) return stored;
|
|
16077
|
+
if (prev && ((_tr$getMeta = tr.getMeta("appendedTransaction")) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.getMeta(plugin))) {
|
|
16078
|
+
const transform = new Transform(prev.transform.before);
|
|
16079
|
+
for (const step of [...prev.transform.steps, ...tr.steps]) transform.step(step);
|
|
16080
|
+
return {
|
|
16081
|
+
...prev,
|
|
16082
|
+
transform
|
|
16083
|
+
};
|
|
16084
|
+
}
|
|
15676
16085
|
const simulatedInputMeta = tr.getMeta("applyInputRules");
|
|
15677
16086
|
if (!!simulatedInputMeta) setTimeout(() => {
|
|
15678
16087
|
let { text } = simulatedInputMeta;
|
|
@@ -16020,7 +16429,8 @@ var ExtensionManager = class {
|
|
|
16020
16429
|
this.editor = editor;
|
|
16021
16430
|
this.baseExtensions = extensions;
|
|
16022
16431
|
this.extensions = resolveExtensions(extensions);
|
|
16023
|
-
this.
|
|
16432
|
+
this.hasSchemaSpec = editor.options.schemaSpec !== void 0;
|
|
16433
|
+
this.schema = getSchemaByResolvedExtensions(this.extensions, editor, editor.options.schemaSpec);
|
|
16024
16434
|
this.setupExtensions();
|
|
16025
16435
|
}
|
|
16026
16436
|
/**
|
|
@@ -16146,7 +16556,8 @@ var ExtensionManager = class {
|
|
|
16146
16556
|
* @returns An array of attributes
|
|
16147
16557
|
*/
|
|
16148
16558
|
get attributes() {
|
|
16149
|
-
|
|
16559
|
+
const attributes = getAttributesFromExtensions(this.extensions);
|
|
16560
|
+
return this.hasSchemaSpec ? getSchemaAttributes(attributes, this.schema) : attributes;
|
|
16150
16561
|
}
|
|
16151
16562
|
/**
|
|
16152
16563
|
* Get all node views from the extensions.
|
|
@@ -16506,6 +16917,12 @@ var FocusEvents = Extension.create({
|
|
|
16506
16917
|
})];
|
|
16507
16918
|
}
|
|
16508
16919
|
});
|
|
16920
|
+
/** Checks if a non-empty selection spans the whole document. */
|
|
16921
|
+
function isWholeDocumentSelected(state) {
|
|
16922
|
+
const { empty, from, to } = state.selection;
|
|
16923
|
+
if (empty) return false;
|
|
16924
|
+
return from === Selection$1.atStart(state.doc).from && to === Selection$1.atEnd(state.doc).to;
|
|
16925
|
+
}
|
|
16509
16926
|
var Keymap = Extension.create({
|
|
16510
16927
|
name: "keymap",
|
|
16511
16928
|
addKeyboardShortcuts() {
|
|
@@ -16571,10 +16988,7 @@ var Keymap = Extension.create({
|
|
|
16571
16988
|
const docChanges = transactions.some((transaction) => transaction.docChanged) && !oldState.doc.eq(newState.doc);
|
|
16572
16989
|
const ignoreTr = transactions.some((transaction) => transaction.getMeta("preventClearDocument"));
|
|
16573
16990
|
if (!docChanges || ignoreTr) return;
|
|
16574
|
-
|
|
16575
|
-
const allFrom = Selection$1.atStart(oldState.doc).from;
|
|
16576
|
-
const allEnd = Selection$1.atEnd(oldState.doc).to;
|
|
16577
|
-
if (empty || !(from === allFrom && to === allEnd)) return;
|
|
16991
|
+
if (!isWholeDocumentSelected(oldState)) return;
|
|
16578
16992
|
if (!isNodeEmpty(newState.doc)) return;
|
|
16579
16993
|
const tr = newState.tr;
|
|
16580
16994
|
const state = createChainableState({
|
|
@@ -16586,8 +17000,8 @@ var Keymap = Extension.create({
|
|
|
16586
17000
|
state
|
|
16587
17001
|
});
|
|
16588
17002
|
commands.clearNodes();
|
|
16589
|
-
if (!tr.steps.length) return;
|
|
16590
|
-
return tr;
|
|
17003
|
+
if (!tr.steps.length && !newState.storedMarks) return;
|
|
17004
|
+
return tr.setStoredMarks(null);
|
|
16591
17005
|
}
|
|
16592
17006
|
})];
|
|
16593
17007
|
}
|
|
@@ -16698,10 +17112,12 @@ function warnOnDuplicatedProseMirrorModel(schema) {
|
|
|
16698
17112
|
hasChecked = true;
|
|
16699
17113
|
let content;
|
|
16700
17114
|
try {
|
|
16701
|
-
|
|
17115
|
+
const step = ReplaceStep.fromJSON(schema, {
|
|
16702
17116
|
from: 0,
|
|
16703
17117
|
to: 0
|
|
16704
|
-
})
|
|
17118
|
+
});
|
|
17119
|
+
if (!isProseMirrorReplaceStep(step)) return;
|
|
17120
|
+
content = step.slice.content;
|
|
16705
17121
|
} catch {
|
|
16706
17122
|
return;
|
|
16707
17123
|
}
|
|
@@ -17508,8 +17924,10 @@ function nodeInputRule(config) {
|
|
|
17508
17924
|
let matchStart = start + match[0].lastIndexOf(match[1]);
|
|
17509
17925
|
if (matchStart > end) matchStart = end;
|
|
17510
17926
|
else end = matchStart + match[1].length;
|
|
17511
|
-
|
|
17512
|
-
|
|
17927
|
+
if (range.to - range.from < match[0].length) {
|
|
17928
|
+
const lastChar = match[0][match[0].length - 1];
|
|
17929
|
+
tr.insertText(lastChar, start + match[0].length - 1);
|
|
17930
|
+
}
|
|
17513
17931
|
tr.replaceWith(matchStart, end, newNode);
|
|
17514
17932
|
} else if (match[0]) {
|
|
17515
17933
|
const insertionStart = config.type.isInline ? start : start - 1;
|
|
@@ -17663,6 +18081,13 @@ var ResizableNodeView = class {
|
|
|
17663
18081
|
this.isShiftKeyPressed = false;
|
|
17664
18082
|
this.lastEditableState = void 0;
|
|
17665
18083
|
this.handleMap = /* @__PURE__ */ new Map();
|
|
18084
|
+
this.handleEditorUpdate = () => {
|
|
18085
|
+
const isEditable = this.editor.isEditable;
|
|
18086
|
+
if (isEditable === this.lastEditableState) return;
|
|
18087
|
+
this.lastEditableState = isEditable;
|
|
18088
|
+
if (!isEditable) this.removeHandles();
|
|
18089
|
+
else if (isEditable && this.handleMap.size === 0) this.attachHandles();
|
|
18090
|
+
};
|
|
17666
18091
|
this.handleMouseMove = (event) => {
|
|
17667
18092
|
if (!this.isResizing || !this.activeHandle) return;
|
|
17668
18093
|
const deltaX = event.clientX - this.startX;
|
|
@@ -17724,7 +18149,7 @@ var ResizableNodeView = class {
|
|
|
17724
18149
|
this.container = this.createContainer();
|
|
17725
18150
|
this.applyInitialSize();
|
|
17726
18151
|
this.attachHandles();
|
|
17727
|
-
this.editor.on("update", this.handleEditorUpdate
|
|
18152
|
+
this.editor.on("update", this.handleEditorUpdate);
|
|
17728
18153
|
}
|
|
17729
18154
|
/**
|
|
17730
18155
|
* Returns the top-level DOM node that should be placed in the editor.
|
|
@@ -17741,13 +18166,6 @@ var ResizableNodeView = class {
|
|
|
17741
18166
|
var _this$contentElement;
|
|
17742
18167
|
return (_this$contentElement = this.contentElement) !== null && _this$contentElement !== void 0 ? _this$contentElement : null;
|
|
17743
18168
|
}
|
|
17744
|
-
handleEditorUpdate() {
|
|
17745
|
-
const isEditable = this.editor.isEditable;
|
|
17746
|
-
if (isEditable === this.lastEditableState) return;
|
|
17747
|
-
this.lastEditableState = isEditable;
|
|
17748
|
-
if (!isEditable) this.removeHandles();
|
|
17749
|
-
else if (isEditable && this.handleMap.size === 0) this.attachHandles();
|
|
17750
|
-
}
|
|
17751
18169
|
/**
|
|
17752
18170
|
* Called when the node's content or attributes change.
|
|
17753
18171
|
*
|
|
@@ -17783,7 +18201,7 @@ var ResizableNodeView = class {
|
|
|
17783
18201
|
this.isResizing = false;
|
|
17784
18202
|
this.activeHandle = null;
|
|
17785
18203
|
}
|
|
17786
|
-
this.editor.off("update", this.handleEditorUpdate
|
|
18204
|
+
this.editor.off("update", this.handleEditorUpdate);
|
|
17787
18205
|
this.container.remove();
|
|
17788
18206
|
}
|
|
17789
18207
|
/**
|
|
@@ -18216,7 +18634,7 @@ var handleBackspace$1 = (editor, type) => {
|
|
|
18216
18634
|
const content = $from.parent.content;
|
|
18217
18635
|
const slice = new Slice(content, 0, 0);
|
|
18218
18636
|
tr.replace(targetPos, $from.after(), slice);
|
|
18219
|
-
tr.setSelection(TextSelection.create(tr.doc, targetPos
|
|
18637
|
+
tr.setSelection(TextSelection.create(tr.doc, targetPos));
|
|
18220
18638
|
tr.scrollIntoView();
|
|
18221
18639
|
dispatch(tr);
|
|
18222
18640
|
return true;
|
|
@@ -18850,8 +19268,10 @@ var Heading = Node$2.create({
|
|
|
18850
19268
|
0
|
|
18851
19269
|
];
|
|
18852
19270
|
},
|
|
18853
|
-
parseMarkdown
|
|
18854
|
-
|
|
19271
|
+
parseMarkdown(token, helpers) {
|
|
19272
|
+
const level = token.depth || 1;
|
|
19273
|
+
if (!this.options.levels.includes(level)) return helpers.createNode("paragraph", void 0, helpers.parseInline(token.tokens || []));
|
|
19274
|
+
return helpers.createNode("heading", { level }, helpers.parseInline(token.tokens || []));
|
|
18855
19275
|
},
|
|
18856
19276
|
renderMarkdown: (node, h) => {
|
|
18857
19277
|
var _node$attrs;
|
|
@@ -20946,7 +21366,7 @@ var Link = Mark.create({
|
|
|
20946
21366
|
const foundLinks = [];
|
|
20947
21367
|
if (text) {
|
|
20948
21368
|
const { protocols, defaultProtocol } = this.options;
|
|
20949
|
-
find(text).filter((item) => item.isLink && this.options.isAllowedUri(item.value, {
|
|
21369
|
+
find(text, { defaultProtocol }).filter((item) => item.isLink && this.options.isAllowedUri(item.value, {
|
|
20950
21370
|
defaultValidate: (href) => !!isAllowedUri(href, protocols),
|
|
20951
21371
|
protocols,
|
|
20952
21372
|
defaultProtocol
|
|
@@ -21388,6 +21808,24 @@ function getListMarker(type, index, separator = ". ") {
|
|
|
21388
21808
|
default: return `${position}${separator}`;
|
|
21389
21809
|
}
|
|
21390
21810
|
}
|
|
21811
|
+
function ensureLeadingParagraph(content) {
|
|
21812
|
+
if (!content[0] || content[0].type === "paragraph") return content;
|
|
21813
|
+
return [{
|
|
21814
|
+
type: "paragraph",
|
|
21815
|
+
content: []
|
|
21816
|
+
}, ...content];
|
|
21817
|
+
}
|
|
21818
|
+
function hasEmptyLeadingParagraph(node) {
|
|
21819
|
+
var _node$content, _first$content;
|
|
21820
|
+
const first = (_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content[0];
|
|
21821
|
+
return (first === null || first === void 0 ? void 0 : first.type) === "paragraph" && !((_first$content = first.content) === null || _first$content === void 0 ? void 0 : _first$content.length);
|
|
21822
|
+
}
|
|
21823
|
+
var EMPTY_ITEM_TEXT = " ";
|
|
21824
|
+
var TOP_LEVEL = 1;
|
|
21825
|
+
var isNested = (ctx) => {
|
|
21826
|
+
var _ctx$level;
|
|
21827
|
+
return ((_ctx$level = ctx === null || ctx === void 0 ? void 0 : ctx.level) !== null && _ctx$level !== void 0 ? _ctx$level : TOP_LEVEL) > TOP_LEVEL;
|
|
21828
|
+
};
|
|
21391
21829
|
function isSameLineOrderedListToken(token) {
|
|
21392
21830
|
var _token$tokens, _token$tokens2;
|
|
21393
21831
|
const nestedToken = (_token$tokens = token.tokens) === null || _token$tokens === void 0 ? void 0 : _token$tokens[0];
|
|
@@ -21440,20 +21878,28 @@ var ListItem = Node$2.create({
|
|
|
21440
21878
|
content: parseSameLineOrderedListText(token.text || "", helpers)
|
|
21441
21879
|
}]
|
|
21442
21880
|
};
|
|
21443
|
-
|
|
21444
|
-
|
|
21445
|
-
|
|
21446
|
-
|
|
21447
|
-
|
|
21881
|
+
const [firstToken, ...remainingTokens] = token.tokens;
|
|
21882
|
+
if (firstToken.type === "heading") {
|
|
21883
|
+
var _firstToken$tokens;
|
|
21884
|
+
return {
|
|
21885
|
+
type: "listItem",
|
|
21886
|
+
content: [{
|
|
21448
21887
|
type: "paragraph",
|
|
21449
|
-
content: helpers.parseInline(firstToken.tokens)
|
|
21450
|
-
}]
|
|
21451
|
-
|
|
21452
|
-
const additionalContent = parseBlockChildren(token.tokens.slice(1));
|
|
21453
|
-
content.push(...additionalContent);
|
|
21454
|
-
}
|
|
21455
|
-
} else content = parseBlockChildren(token.tokens);
|
|
21888
|
+
content: helpers.parseInline((_firstToken$tokens = firstToken.tokens) !== null && _firstToken$tokens !== void 0 ? _firstToken$tokens : [])
|
|
21889
|
+
}, ...remainingTokens.length > 0 ? parseBlockChildren(remainingTokens) : []]
|
|
21890
|
+
};
|
|
21456
21891
|
}
|
|
21892
|
+
if (token.tokens.some((t) => t.type === "paragraph")) content = parseBlockChildren(token.tokens);
|
|
21893
|
+
else if (firstToken.type === "text" && firstToken.tokens && firstToken.tokens.length > 0) {
|
|
21894
|
+
content = [{
|
|
21895
|
+
type: "paragraph",
|
|
21896
|
+
content: helpers.parseInline(firstToken.tokens)
|
|
21897
|
+
}];
|
|
21898
|
+
if (token.tokens.length > 1) {
|
|
21899
|
+
const additionalContent = parseBlockChildren(token.tokens.slice(1));
|
|
21900
|
+
content.push(...additionalContent);
|
|
21901
|
+
}
|
|
21902
|
+
} else content = parseBlockChildren(token.tokens);
|
|
21457
21903
|
}
|
|
21458
21904
|
if (content.length === 0) content = [{
|
|
21459
21905
|
type: "paragraph",
|
|
@@ -21461,11 +21907,11 @@ var ListItem = Node$2.create({
|
|
|
21461
21907
|
}];
|
|
21462
21908
|
return {
|
|
21463
21909
|
type: "listItem",
|
|
21464
|
-
content
|
|
21910
|
+
content: ensureLeadingParagraph(content)
|
|
21465
21911
|
};
|
|
21466
21912
|
},
|
|
21467
21913
|
renderMarkdown: (node, h, ctx) => {
|
|
21468
|
-
|
|
21914
|
+
const getPrefix = (context) => {
|
|
21469
21915
|
if (context.parentType === "bulletList") return "- ";
|
|
21470
21916
|
if (context.parentType === "orderedList") {
|
|
21471
21917
|
var _context$meta, _context$meta2;
|
|
@@ -21473,7 +21919,11 @@ var ListItem = Node$2.create({
|
|
|
21473
21919
|
return getListMarker((_context$meta2 = context.meta) === null || _context$meta2 === void 0 || (_context$meta2 = _context$meta2.parentAttrs) === null || _context$meta2 === void 0 ? void 0 : _context$meta2.type, start - 1 + (context.index || 0), ". ");
|
|
21474
21920
|
}
|
|
21475
21921
|
return "- ";
|
|
21476
|
-
}
|
|
21922
|
+
};
|
|
21923
|
+
const output = renderNestedMarkdownContent(node, h, getPrefix, ctx, { alignNestedToPrefix: (ctx === null || ctx === void 0 ? void 0 : ctx.parentType) === "orderedList" });
|
|
21924
|
+
if (!hasEmptyLeadingParagraph(node) || !isNested(ctx)) return output;
|
|
21925
|
+
const prefix = getPrefix(ctx);
|
|
21926
|
+
return `${prefix}${EMPTY_ITEM_TEXT}${output.slice(prefix.length)}`;
|
|
21477
21927
|
},
|
|
21478
21928
|
addExtensions() {
|
|
21479
21929
|
return [createBranchingListDeleteKeymap(this.name, [this.options.bulletListTypeName, this.options.orderedListTypeName])];
|
|
@@ -21536,10 +21986,15 @@ var handleBackspace = (editor, name, parentListTypes) => {
|
|
|
21536
21986
|
const lastItem = listDescendants.at(-1);
|
|
21537
21987
|
if (!lastItem) return false;
|
|
21538
21988
|
const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1);
|
|
21539
|
-
return editor.chain().
|
|
21540
|
-
|
|
21541
|
-
|
|
21542
|
-
|
|
21989
|
+
return editor.chain().command(({ tr }) => {
|
|
21990
|
+
const target = $lastItemPos.end();
|
|
21991
|
+
tr.delete($anchor.before(), $anchor.after()).insert(target, $anchor.parent);
|
|
21992
|
+
tr.setSelection(TextSelection.create(tr.doc, target + 1));
|
|
21993
|
+
return true;
|
|
21994
|
+
}).command(({ state, dispatch }) => {
|
|
21995
|
+
joinTextblockBackward(state, dispatch);
|
|
21996
|
+
return true;
|
|
21997
|
+
}).run();
|
|
21543
21998
|
}
|
|
21544
21999
|
if (!isNodeActive(editor.state, name)) return false;
|
|
21545
22000
|
if (!isAtStartOfNode(editor.state)) return false;
|
|
@@ -21565,11 +22020,9 @@ var nextListIsHigher = (typeOrName, state) => {
|
|
|
21565
22020
|
var handleDelete = (editor, name) => {
|
|
21566
22021
|
if (!isNodeActive(editor.state, name)) return false;
|
|
21567
22022
|
if (!isAtEndOfNode(editor.state, name)) return false;
|
|
21568
|
-
|
|
21569
|
-
const { $from, $to } = selection;
|
|
21570
|
-
if (!selection.empty && $from.sameParent($to)) return false;
|
|
22023
|
+
if (!editor.state.selection.empty) return false;
|
|
21571
22024
|
if (nextListIsDeeper(name, editor.state)) return editor.chain().focus(editor.state.selection.from + 4).lift(name).joinBackward().run();
|
|
21572
|
-
if (nextListIsHigher(name, editor.state)) return editor.
|
|
22025
|
+
if (nextListIsHigher(name, editor.state)) return editor.commands.command(({ state, dispatch }) => joinTextblockForward(state, dispatch));
|
|
21573
22026
|
return editor.commands.joinItemForward();
|
|
21574
22027
|
};
|
|
21575
22028
|
var handleTab = (editor, name, parentListTypes) => {
|
|
@@ -22208,7 +22661,7 @@ var TaskItem = Node$2.create({
|
|
|
22208
22661
|
},
|
|
22209
22662
|
renderMarkdown: (node, h) => {
|
|
22210
22663
|
var _node$attrs;
|
|
22211
|
-
return renderNestedMarkdownContent(node, h, `- [${((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.checked) ? "x" : " "}]
|
|
22664
|
+
return renderNestedMarkdownContent(node, h, `- [${((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.checked) ? "x" : " "}] `, void 0, { indentMainContent: true });
|
|
22212
22665
|
},
|
|
22213
22666
|
addExtensions() {
|
|
22214
22667
|
if (!this.options.nested) return [];
|
|
@@ -22616,24 +23069,35 @@ var Underline = Mark.create({
|
|
|
22616
23069
|
return helpers.applyMark(this.name || "underline", helpers.parseInline(token.tokens || []));
|
|
22617
23070
|
},
|
|
22618
23071
|
renderMarkdown(node, helpers) {
|
|
22619
|
-
return
|
|
23072
|
+
return `<u>${helpers.renderChildren(node)}</u>`;
|
|
22620
23073
|
},
|
|
22621
23074
|
markdownTokenizer: {
|
|
22622
23075
|
name: "underline",
|
|
22623
23076
|
level: "inline",
|
|
22624
23077
|
start(src) {
|
|
22625
|
-
return src.indexOf("
|
|
23078
|
+
return src.toLowerCase().indexOf("<u>");
|
|
22626
23079
|
},
|
|
22627
23080
|
tokenize(src, _tokens, lexer) {
|
|
22628
|
-
|
|
22629
|
-
|
|
22630
|
-
|
|
22631
|
-
|
|
22632
|
-
|
|
22633
|
-
|
|
22634
|
-
|
|
22635
|
-
|
|
22636
|
-
|
|
23081
|
+
if (!/^<u>/i.test(src)) return;
|
|
23082
|
+
const delimiters = /\\[\s\S]|`+|<\/u>/gi;
|
|
23083
|
+
delimiters.lastIndex = 3;
|
|
23084
|
+
let match = delimiters.exec(src);
|
|
23085
|
+
while (match) {
|
|
23086
|
+
if (match[0].startsWith("`")) {
|
|
23087
|
+
const codeSpan = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/.exec(src.slice(match.index));
|
|
23088
|
+
if (codeSpan) delimiters.lastIndex = match.index + codeSpan[0].length;
|
|
23089
|
+
} else if (!match[0].startsWith("\\")) {
|
|
23090
|
+
const text = src.slice(3, match.index);
|
|
23091
|
+
if (!text) return;
|
|
23092
|
+
return {
|
|
23093
|
+
type: "underline",
|
|
23094
|
+
raw: src.slice(0, delimiters.lastIndex),
|
|
23095
|
+
text,
|
|
23096
|
+
tokens: lexer.inlineTokens(text)
|
|
23097
|
+
};
|
|
23098
|
+
}
|
|
23099
|
+
match = delimiters.exec(src);
|
|
23100
|
+
}
|
|
22637
23101
|
}
|
|
22638
23102
|
},
|
|
22639
23103
|
addCommands() {
|
|
@@ -23315,13 +23779,18 @@ function resolveTopLevelRange(doc, pos) {
|
|
|
23315
23779
|
};
|
|
23316
23780
|
}
|
|
23317
23781
|
/**
|
|
23318
|
-
*
|
|
23319
|
-
* `Node#nodesBetween` and `Node#forEach`
|
|
23782
|
+
* Clamps a top-level block range from `resolveTopLevelRange` to the document
|
|
23783
|
+
* content, giving the positions used by `Node#nodesBetween` and `Node#forEach`
|
|
23784
|
+
* offsets.
|
|
23785
|
+
*
|
|
23786
|
+
* A top-level node at `Node#forEach` offset `n` already sits at document
|
|
23787
|
+
* position `n`, so the range must not be shifted: a node decoration spans
|
|
23788
|
+
* exactly `[n, n + nodeSize]` and has to stay inside the range to be replaced.
|
|
23320
23789
|
*/
|
|
23321
23790
|
function toContentRelativeRange(doc, range) {
|
|
23322
23791
|
return {
|
|
23323
|
-
from: Math.max(0, range.from
|
|
23324
|
-
to: Math.min(doc.content.size, range.to
|
|
23792
|
+
from: Math.max(0, range.from),
|
|
23793
|
+
to: Math.min(doc.content.size, range.to)
|
|
23325
23794
|
};
|
|
23326
23795
|
}
|
|
23327
23796
|
/**
|
|
@@ -26167,7 +26636,7 @@ var TableView = class {
|
|
|
26167
26636
|
this.contentDOM = this.table.appendChild(document.createElement("tbody"));
|
|
26168
26637
|
}
|
|
26169
26638
|
update(node) {
|
|
26170
|
-
if (node.
|
|
26639
|
+
if (!node.sameMarkup(this.node)) return false;
|
|
26171
26640
|
this.node = node;
|
|
26172
26641
|
updateColumns(node, this.colgroup, this.table, this.cellMinWidth);
|
|
26173
26642
|
return true;
|
|
@@ -26637,7 +27106,7 @@ var Table$1 = Node$2.create({
|
|
|
26637
27106
|
handleWidth: this.options.handleWidth,
|
|
26638
27107
|
cellMinWidth: this.options.cellMinWidth,
|
|
26639
27108
|
defaultCellMinWidth: this.options.cellMinWidth,
|
|
26640
|
-
View:
|
|
27109
|
+
View: null,
|
|
26641
27110
|
lastColumnResizable: this.options.lastColumnResizable
|
|
26642
27111
|
})] : [],
|
|
26643
27112
|
tableEditing({ allowTableNodeSelection: this.options.allowTableNodeSelection }),
|
|
@@ -26645,9 +27114,8 @@ var Table$1 = Node$2.create({
|
|
|
26645
27114
|
];
|
|
26646
27115
|
},
|
|
26647
27116
|
addNodeView() {
|
|
26648
|
-
const isResizable = this.options.resizable && this.editor.isEditable;
|
|
26649
27117
|
const View = this.options.View;
|
|
26650
|
-
if (
|
|
27118
|
+
if (!View) return null;
|
|
26651
27119
|
return ({ node, view, HTMLAttributes }) => {
|
|
26652
27120
|
const mergedAttributes = mergeAttributes(this.options.HTMLAttributes, HTMLAttributes);
|
|
26653
27121
|
return new View(node, this.options.cellMinWidth, view, mergedAttributes);
|
|
@@ -28429,7 +28897,7 @@ function parseConfig(config) {
|
|
|
28429
28897
|
}
|
|
28430
28898
|
}
|
|
28431
28899
|
// src/index.tsx
|
|
28432
|
-
var version = "4.0.0-alpha.
|
|
28900
|
+
var version = "4.0.0-alpha.79";
|
|
28433
28901
|
/**
|
|
28434
28902
|
* 本稿⇄下書き切替UIをビューエリアの直前にマウントする
|
|
28435
28903
|
*
|