miyuan-editor 0.0.3
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/README.md +525 -0
- package/dist/core/index.cjs.js +40 -0
- package/dist/core/index.esm.js +4 -0
- package/dist/dist-5Q_Z9Ell.js +6390 -0
- package/dist/dist-5Q_Z9Ell.js.map +1 -0
- package/dist/dist-CMM6n8DO.cjs +4629 -0
- package/dist/dist-CMM6n8DO.cjs.map +1 -0
- package/dist/dist-CRSJDo2G.cjs +6617 -0
- package/dist/dist-CRSJDo2G.cjs.map +1 -0
- package/dist/dist-CZw77IJK.js +4612 -0
- package/dist/dist-CZw77IJK.js.map +1 -0
- package/dist/dist-CnVrDtsI.js +556 -0
- package/dist/dist-CnVrDtsI.js.map +1 -0
- package/dist/dist-rItBfhNb.cjs +591 -0
- package/dist/dist-rItBfhNb.cjs.map +1 -0
- package/dist/export-utils-CYaNoyVg.cjs +167 -0
- package/dist/export-utils-CYaNoyVg.cjs.map +1 -0
- package/dist/export-utils-DN0Gu8Vu.js +144 -0
- package/dist/export-utils-DN0Gu8Vu.js.map +1 -0
- package/dist/extension-BPFuYyzN.cjs +338 -0
- package/dist/extension-BPFuYyzN.cjs.map +1 -0
- package/dist/extension-Cl6x5MDR.js +321 -0
- package/dist/extension-Cl6x5MDR.js.map +1 -0
- package/dist/extensions/index.cjs.js +3462 -0
- package/dist/extensions/index.cjs.js.map +1 -0
- package/dist/extensions/index.esm.js +3412 -0
- package/dist/extensions/index.esm.js.map +1 -0
- package/dist/prompt-B4AOP8f_.js +24143 -0
- package/dist/prompt-B4AOP8f_.js.map +1 -0
- package/dist/prompt-CGLw2O21.cjs +25530 -0
- package/dist/prompt-CGLw2O21.cjs.map +1 -0
- package/dist/react/index.cjs.js +839 -0
- package/dist/react/index.cjs.js.map +1 -0
- package/dist/react/index.esm.js +820 -0
- package/dist/react/index.esm.js.map +1 -0
- package/dist/shortcut-panel-BskGXV8n.js +49468 -0
- package/dist/shortcut-panel-BskGXV8n.js.map +1 -0
- package/dist/shortcut-panel-yP4RPTFt.cjs +49563 -0
- package/dist/shortcut-panel-yP4RPTFt.cjs.map +1 -0
- package/dist/toc-extension-BESc0uEW.js +150 -0
- package/dist/toc-extension-BESc0uEW.js.map +1 -0
- package/dist/toc-extension-SRvSuskn.cjs +173 -0
- package/dist/toc-extension-SRvSuskn.cjs.map +1 -0
- package/dist/toolbar-config-Cgc9mV2v.js +243 -0
- package/dist/toolbar-config-Cgc9mV2v.js.map +1 -0
- package/dist/toolbar-config-Cjt_fPMi.cjs +260 -0
- package/dist/toolbar-config-Cjt_fPMi.cjs.map +1 -0
- package/dist/ui/index.cjs.js +18 -0
- package/dist/ui/index.esm.js +3 -0
- package/dist/vue/index.cjs.js +323 -0
- package/dist/vue/index.cjs.js.map +1 -0
- package/dist/vue/index.esm.js +307 -0
- package/dist/vue/index.esm.js.map +1 -0
- package/dist/vue2/index.cjs.js +323 -0
- package/dist/vue2/index.cjs.js.map +1 -0
- package/dist/vue2/index.esm.js +307 -0
- package/dist/vue2/index.esm.js.map +1 -0
- package/package.json +116 -0
|
@@ -0,0 +1,4629 @@
|
|
|
1
|
+
const require_dist = require("./dist-CRSJDo2G.cjs");
|
|
2
|
+
//#region node_modules/.pnpm/prosemirror-view@1.41.9/node_modules/prosemirror-view/dist/index.js
|
|
3
|
+
var domIndex = function(node) {
|
|
4
|
+
for (var index = 0;; index++) {
|
|
5
|
+
node = node.previousSibling;
|
|
6
|
+
if (!node) return index;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
var parentNode = function(node) {
|
|
10
|
+
let parent = node.assignedSlot || node.parentNode;
|
|
11
|
+
return parent && parent.nodeType == 11 ? parent.host : parent;
|
|
12
|
+
};
|
|
13
|
+
var reusedRange = null;
|
|
14
|
+
var textRange = function(node, from, to) {
|
|
15
|
+
let range = reusedRange || (reusedRange = document.createRange());
|
|
16
|
+
range.setEnd(node, to == null ? node.nodeValue.length : to);
|
|
17
|
+
range.setStart(node, from || 0);
|
|
18
|
+
return range;
|
|
19
|
+
};
|
|
20
|
+
var clearReusedRange = function() {
|
|
21
|
+
reusedRange = null;
|
|
22
|
+
};
|
|
23
|
+
var isEquivalentPosition = function(node, off, targetNode, targetOff) {
|
|
24
|
+
return targetNode && (scanFor(node, off, targetNode, targetOff, -1) || scanFor(node, off, targetNode, targetOff, 1));
|
|
25
|
+
};
|
|
26
|
+
var atomElements = /^(img|br|input|textarea|hr)$/i;
|
|
27
|
+
function scanFor(node, off, targetNode, targetOff, dir) {
|
|
28
|
+
var _a;
|
|
29
|
+
for (;;) {
|
|
30
|
+
if (node == targetNode && off == targetOff) return true;
|
|
31
|
+
if (off == (dir < 0 ? 0 : nodeSize(node))) {
|
|
32
|
+
let parent = node.parentNode;
|
|
33
|
+
if (!parent || parent.nodeType != 1 || hasBlockDesc(node) || atomElements.test(node.nodeName) || node.contentEditable == "false") return false;
|
|
34
|
+
off = domIndex(node) + (dir < 0 ? 0 : 1);
|
|
35
|
+
node = parent;
|
|
36
|
+
} else if (node.nodeType == 1) {
|
|
37
|
+
let child = node.childNodes[off + (dir < 0 ? -1 : 0)];
|
|
38
|
+
if (child.nodeType == 1 && child.contentEditable == "false") if ((_a = child.pmViewDesc) === null || _a === void 0 ? void 0 : _a.ignoreForSelection) off += dir;
|
|
39
|
+
else return false;
|
|
40
|
+
else {
|
|
41
|
+
node = child;
|
|
42
|
+
off = dir < 0 ? nodeSize(node) : 0;
|
|
43
|
+
}
|
|
44
|
+
} else return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function nodeSize(node) {
|
|
48
|
+
return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length;
|
|
49
|
+
}
|
|
50
|
+
function textNodeBefore$1(node, offset) {
|
|
51
|
+
for (;;) {
|
|
52
|
+
if (node.nodeType == 3 && offset) return node;
|
|
53
|
+
if (node.nodeType == 1 && offset > 0) {
|
|
54
|
+
if (node.contentEditable == "false") return null;
|
|
55
|
+
node = node.childNodes[offset - 1];
|
|
56
|
+
offset = nodeSize(node);
|
|
57
|
+
} else if (node.parentNode && !hasBlockDesc(node)) {
|
|
58
|
+
offset = domIndex(node);
|
|
59
|
+
node = node.parentNode;
|
|
60
|
+
} else return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function textNodeAfter$1(node, offset) {
|
|
64
|
+
for (;;) {
|
|
65
|
+
if (node.nodeType == 3 && offset < node.nodeValue.length) return node;
|
|
66
|
+
if (node.nodeType == 1 && offset < node.childNodes.length) {
|
|
67
|
+
if (node.contentEditable == "false") return null;
|
|
68
|
+
node = node.childNodes[offset];
|
|
69
|
+
offset = 0;
|
|
70
|
+
} else if (node.parentNode && !hasBlockDesc(node)) {
|
|
71
|
+
offset = domIndex(node) + 1;
|
|
72
|
+
node = node.parentNode;
|
|
73
|
+
} else return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function isOnEdge(node, offset, parent) {
|
|
77
|
+
for (let atStart = offset == 0, atEnd = offset == nodeSize(node); atStart || atEnd;) {
|
|
78
|
+
if (node == parent) return true;
|
|
79
|
+
let index = domIndex(node);
|
|
80
|
+
node = node.parentNode;
|
|
81
|
+
if (!node) return false;
|
|
82
|
+
atStart = atStart && index == 0;
|
|
83
|
+
atEnd = atEnd && index == nodeSize(node);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function hasBlockDesc(dom) {
|
|
87
|
+
let desc;
|
|
88
|
+
for (let cur = dom; cur; cur = cur.parentNode) if (desc = cur.pmViewDesc) break;
|
|
89
|
+
return desc && desc.node && desc.node.isBlock && (desc.dom == dom || desc.contentDOM == dom);
|
|
90
|
+
}
|
|
91
|
+
var selectionCollapsed = function(domSel) {
|
|
92
|
+
return domSel.focusNode && isEquivalentPosition(domSel.focusNode, domSel.focusOffset, domSel.anchorNode, domSel.anchorOffset);
|
|
93
|
+
};
|
|
94
|
+
function keyEvent(keyCode, key) {
|
|
95
|
+
let event = document.createEvent("Event");
|
|
96
|
+
event.initEvent("keydown", true, true);
|
|
97
|
+
event.keyCode = keyCode;
|
|
98
|
+
event.key = event.code = key;
|
|
99
|
+
return event;
|
|
100
|
+
}
|
|
101
|
+
function deepActiveElement(doc) {
|
|
102
|
+
let elt = doc.activeElement;
|
|
103
|
+
while (elt && elt.shadowRoot) elt = elt.shadowRoot.activeElement;
|
|
104
|
+
return elt;
|
|
105
|
+
}
|
|
106
|
+
function caretFromPoint(doc, x, y) {
|
|
107
|
+
if (doc.caretPositionFromPoint) try {
|
|
108
|
+
let pos = doc.caretPositionFromPoint(x, y);
|
|
109
|
+
if (pos) return {
|
|
110
|
+
node: pos.offsetNode,
|
|
111
|
+
offset: Math.min(nodeSize(pos.offsetNode), pos.offset)
|
|
112
|
+
};
|
|
113
|
+
} catch (_) {}
|
|
114
|
+
if (doc.caretRangeFromPoint) {
|
|
115
|
+
let range = doc.caretRangeFromPoint(x, y);
|
|
116
|
+
if (range) return {
|
|
117
|
+
node: range.startContainer,
|
|
118
|
+
offset: Math.min(nodeSize(range.startContainer), range.startOffset)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
var nav = typeof navigator != "undefined" ? navigator : null;
|
|
123
|
+
var doc = typeof document != "undefined" ? document : null;
|
|
124
|
+
var agent = nav && nav.userAgent || "";
|
|
125
|
+
var ie_edge = /Edge\/(\d+)/.exec(agent);
|
|
126
|
+
var ie_upto10 = /MSIE \d/.exec(agent);
|
|
127
|
+
var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(agent);
|
|
128
|
+
var ie = !!(ie_upto10 || ie_11up || ie_edge);
|
|
129
|
+
var ie_version = ie_upto10 ? document.documentMode : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0;
|
|
130
|
+
var gecko = !ie && /gecko\/(\d+)/i.test(agent);
|
|
131
|
+
gecko && +(/Firefox\/(\d+)/.exec(agent) || [0, 0])[1];
|
|
132
|
+
var _chrome = !ie && /Chrome\/(\d+)/.exec(agent);
|
|
133
|
+
var chrome = !!_chrome;
|
|
134
|
+
var chrome_version = _chrome ? +_chrome[1] : 0;
|
|
135
|
+
var safari = !ie && !!nav && /Apple Computer/.test(nav.vendor);
|
|
136
|
+
var ios = safari && (/Mobile\/\w+/.test(agent) || !!nav && nav.maxTouchPoints > 2);
|
|
137
|
+
var mac = ios || (nav ? /Mac/.test(nav.platform) : false);
|
|
138
|
+
var windows = nav ? /Win/.test(nav.platform) : false;
|
|
139
|
+
var android = /Android \d/.test(agent);
|
|
140
|
+
var webkit = !!doc && "webkitFontSmoothing" in doc.documentElement.style;
|
|
141
|
+
var webkit_version = webkit ? +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1] : 0;
|
|
142
|
+
function windowRect(doc) {
|
|
143
|
+
let vp = doc.defaultView && doc.defaultView.visualViewport;
|
|
144
|
+
if (vp) return {
|
|
145
|
+
left: 0,
|
|
146
|
+
right: vp.width,
|
|
147
|
+
top: 0,
|
|
148
|
+
bottom: vp.height
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
left: 0,
|
|
152
|
+
right: doc.documentElement.clientWidth,
|
|
153
|
+
top: 0,
|
|
154
|
+
bottom: doc.documentElement.clientHeight
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function getSide(value, side) {
|
|
158
|
+
return typeof value == "number" ? value : value[side];
|
|
159
|
+
}
|
|
160
|
+
function clientRect(node) {
|
|
161
|
+
let rect = node.getBoundingClientRect();
|
|
162
|
+
let scaleX = rect.width / node.offsetWidth || 1;
|
|
163
|
+
let scaleY = rect.height / node.offsetHeight || 1;
|
|
164
|
+
return {
|
|
165
|
+
left: rect.left,
|
|
166
|
+
right: rect.left + node.clientWidth * scaleX,
|
|
167
|
+
top: rect.top,
|
|
168
|
+
bottom: rect.top + node.clientHeight * scaleY
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function scrollRectIntoView(view, rect, startDOM) {
|
|
172
|
+
let scrollThreshold = view.someProp("scrollThreshold") || 0, scrollMargin = view.someProp("scrollMargin") || 5;
|
|
173
|
+
let doc = view.dom.ownerDocument;
|
|
174
|
+
for (let parent = startDOM || view.dom;;) {
|
|
175
|
+
if (!parent) break;
|
|
176
|
+
if (parent.nodeType != 1) {
|
|
177
|
+
parent = parentNode(parent);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
let elt = parent;
|
|
181
|
+
let atTop = elt == doc.body;
|
|
182
|
+
let bounding = atTop ? windowRect(doc) : clientRect(elt);
|
|
183
|
+
let moveX = 0, moveY = 0;
|
|
184
|
+
if (rect.top < bounding.top + getSide(scrollThreshold, "top")) moveY = -(bounding.top - rect.top + getSide(scrollMargin, "top"));
|
|
185
|
+
else if (rect.bottom > bounding.bottom - getSide(scrollThreshold, "bottom")) moveY = rect.bottom - rect.top > bounding.bottom - bounding.top ? rect.top + getSide(scrollMargin, "top") - bounding.top : rect.bottom - bounding.bottom + getSide(scrollMargin, "bottom");
|
|
186
|
+
if (rect.left < bounding.left + getSide(scrollThreshold, "left")) moveX = -(bounding.left - rect.left + getSide(scrollMargin, "left"));
|
|
187
|
+
else if (rect.right > bounding.right - getSide(scrollThreshold, "right")) moveX = rect.right - bounding.right + getSide(scrollMargin, "right");
|
|
188
|
+
if (moveX || moveY) if (atTop) doc.defaultView.scrollBy(moveX, moveY);
|
|
189
|
+
else {
|
|
190
|
+
let startX = elt.scrollLeft, startY = elt.scrollTop;
|
|
191
|
+
if (moveY) elt.scrollTop += moveY;
|
|
192
|
+
if (moveX) elt.scrollLeft += moveX;
|
|
193
|
+
let dX = elt.scrollLeft - startX, dY = elt.scrollTop - startY;
|
|
194
|
+
rect = {
|
|
195
|
+
left: rect.left - dX,
|
|
196
|
+
top: rect.top - dY,
|
|
197
|
+
right: rect.right - dX,
|
|
198
|
+
bottom: rect.bottom - dY
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
let pos = atTop ? "fixed" : getComputedStyle(parent).position;
|
|
202
|
+
if (/^(fixed|sticky)$/.test(pos)) break;
|
|
203
|
+
parent = pos == "absolute" ? parent.offsetParent : parentNode(parent);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function storeScrollPos(view) {
|
|
207
|
+
let rect = view.dom.getBoundingClientRect(), startY = Math.max(0, rect.top);
|
|
208
|
+
let refDOM, refTop;
|
|
209
|
+
for (let x = (rect.left + rect.right) / 2, y = startY + 1; y < Math.min(innerHeight, rect.bottom); y += 5) {
|
|
210
|
+
let dom = view.root.elementFromPoint(x, y);
|
|
211
|
+
if (!dom || dom == view.dom || !view.dom.contains(dom)) continue;
|
|
212
|
+
let localRect = dom.getBoundingClientRect();
|
|
213
|
+
if (localRect.top >= startY - 20) {
|
|
214
|
+
refDOM = dom;
|
|
215
|
+
refTop = localRect.top;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
refDOM,
|
|
221
|
+
refTop,
|
|
222
|
+
stack: scrollStack(view.dom)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function scrollStack(dom) {
|
|
226
|
+
let stack = [], doc = dom.ownerDocument;
|
|
227
|
+
for (let cur = dom; cur; cur = parentNode(cur)) {
|
|
228
|
+
stack.push({
|
|
229
|
+
dom: cur,
|
|
230
|
+
top: cur.scrollTop,
|
|
231
|
+
left: cur.scrollLeft
|
|
232
|
+
});
|
|
233
|
+
if (dom == doc) break;
|
|
234
|
+
}
|
|
235
|
+
return stack;
|
|
236
|
+
}
|
|
237
|
+
function resetScrollPos({ refDOM, refTop, stack }) {
|
|
238
|
+
let newRefTop = refDOM ? refDOM.getBoundingClientRect().top : 0;
|
|
239
|
+
restoreScrollStack(stack, newRefTop == 0 ? 0 : newRefTop - refTop);
|
|
240
|
+
}
|
|
241
|
+
function restoreScrollStack(stack, dTop) {
|
|
242
|
+
for (let i = 0; i < stack.length; i++) {
|
|
243
|
+
let { dom, top, left } = stack[i];
|
|
244
|
+
if (dom.scrollTop != top + dTop) dom.scrollTop = top + dTop;
|
|
245
|
+
if (dom.scrollLeft != left) dom.scrollLeft = left;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
var preventScrollSupported = null;
|
|
249
|
+
function focusPreventScroll(dom) {
|
|
250
|
+
if (dom.setActive) return dom.setActive();
|
|
251
|
+
if (preventScrollSupported) return dom.focus(preventScrollSupported);
|
|
252
|
+
let stored = scrollStack(dom);
|
|
253
|
+
dom.focus(preventScrollSupported == null ? { get preventScroll() {
|
|
254
|
+
preventScrollSupported = { preventScroll: true };
|
|
255
|
+
return true;
|
|
256
|
+
} } : void 0);
|
|
257
|
+
if (!preventScrollSupported) {
|
|
258
|
+
preventScrollSupported = false;
|
|
259
|
+
restoreScrollStack(stored, 0);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function findOffsetInNode(node, coords) {
|
|
263
|
+
let closest, dxClosest = 2e8, coordsClosest, offset = 0;
|
|
264
|
+
let rowBot = coords.top, rowTop = coords.top;
|
|
265
|
+
let firstBelow, coordsBelow;
|
|
266
|
+
for (let child = node.firstChild, childIndex = 0; child; child = child.nextSibling, childIndex++) {
|
|
267
|
+
let rects;
|
|
268
|
+
if (child.nodeType == 1) rects = child.getClientRects();
|
|
269
|
+
else if (child.nodeType == 3) rects = textRange(child).getClientRects();
|
|
270
|
+
else continue;
|
|
271
|
+
for (let i = 0; i < rects.length; i++) {
|
|
272
|
+
let rect = rects[i];
|
|
273
|
+
if (rect.top <= rowBot && rect.bottom >= rowTop) {
|
|
274
|
+
rowBot = Math.max(rect.bottom, rowBot);
|
|
275
|
+
rowTop = Math.min(rect.top, rowTop);
|
|
276
|
+
let dx = rect.left > coords.left ? rect.left - coords.left : rect.right < coords.left ? coords.left - rect.right : 0;
|
|
277
|
+
if (dx < dxClosest) {
|
|
278
|
+
closest = child;
|
|
279
|
+
dxClosest = dx;
|
|
280
|
+
coordsClosest = dx && closest.nodeType == 3 ? {
|
|
281
|
+
left: rect.right < coords.left ? rect.right : rect.left,
|
|
282
|
+
top: coords.top
|
|
283
|
+
} : coords;
|
|
284
|
+
if (child.nodeType == 1 && dx) offset = childIndex + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0);
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
} else if (rect.top > coords.top && !firstBelow && rect.left <= coords.left && rect.right >= coords.left) {
|
|
288
|
+
firstBelow = child;
|
|
289
|
+
coordsBelow = {
|
|
290
|
+
left: Math.max(rect.left, Math.min(rect.right, coords.left)),
|
|
291
|
+
top: rect.top
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
if (!closest && (coords.left >= rect.right && coords.top >= rect.top || coords.left >= rect.left && coords.top >= rect.bottom)) offset = childIndex + 1;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (!closest && firstBelow) {
|
|
298
|
+
closest = firstBelow;
|
|
299
|
+
coordsClosest = coordsBelow;
|
|
300
|
+
dxClosest = 0;
|
|
301
|
+
}
|
|
302
|
+
if (closest && closest.nodeType == 3) return findOffsetInText(closest, coordsClosest);
|
|
303
|
+
if (!closest || dxClosest && closest.nodeType == 1) return {
|
|
304
|
+
node,
|
|
305
|
+
offset
|
|
306
|
+
};
|
|
307
|
+
return findOffsetInNode(closest, coordsClosest);
|
|
308
|
+
}
|
|
309
|
+
function findOffsetInText(node, coords) {
|
|
310
|
+
let len = node.nodeValue.length;
|
|
311
|
+
let range = document.createRange(), result;
|
|
312
|
+
for (let i = 0; i < len; i++) {
|
|
313
|
+
range.setEnd(node, i + 1);
|
|
314
|
+
range.setStart(node, i);
|
|
315
|
+
let rect = singleRect(range, 1);
|
|
316
|
+
if (rect.top == rect.bottom) continue;
|
|
317
|
+
if (inRect(coords, rect)) {
|
|
318
|
+
result = {
|
|
319
|
+
node,
|
|
320
|
+
offset: i + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0)
|
|
321
|
+
};
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
range.detach();
|
|
326
|
+
return result || {
|
|
327
|
+
node,
|
|
328
|
+
offset: 0
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
function inRect(coords, rect) {
|
|
332
|
+
return coords.left >= rect.left - 1 && coords.left <= rect.right + 1 && coords.top >= rect.top - 1 && coords.top <= rect.bottom + 1;
|
|
333
|
+
}
|
|
334
|
+
function targetKludge(dom, coords) {
|
|
335
|
+
let parent = dom.parentNode;
|
|
336
|
+
if (parent && /^li$/i.test(parent.nodeName) && coords.left < dom.getBoundingClientRect().left) return parent;
|
|
337
|
+
return dom;
|
|
338
|
+
}
|
|
339
|
+
function posFromElement(view, elt, coords) {
|
|
340
|
+
let { node, offset } = findOffsetInNode(elt, coords), bias = -1;
|
|
341
|
+
if (node.nodeType == 1 && !node.firstChild) {
|
|
342
|
+
let rect = node.getBoundingClientRect();
|
|
343
|
+
bias = rect.left != rect.right && coords.left > (rect.left + rect.right) / 2 ? 1 : -1;
|
|
344
|
+
}
|
|
345
|
+
return view.docView.posFromDOM(node, offset, bias);
|
|
346
|
+
}
|
|
347
|
+
function posFromCaret(view, node, offset, coords) {
|
|
348
|
+
let outsideBlock = -1;
|
|
349
|
+
for (let cur = node, sawBlock = false;;) {
|
|
350
|
+
if (cur == view.dom) break;
|
|
351
|
+
let desc = view.docView.nearestDesc(cur, true), rect;
|
|
352
|
+
if (!desc) return null;
|
|
353
|
+
if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM) && ((rect = desc.dom.getBoundingClientRect()).width || rect.height)) {
|
|
354
|
+
if (desc.node.isBlock && desc.parent && !/^T(R|BODY|HEAD|FOOT)$/.test(desc.dom.nodeName)) {
|
|
355
|
+
if (!sawBlock && rect.left > coords.left || rect.top > coords.top) outsideBlock = desc.posBefore;
|
|
356
|
+
else if (!sawBlock && rect.right < coords.left || rect.bottom < coords.top) outsideBlock = desc.posAfter;
|
|
357
|
+
sawBlock = true;
|
|
358
|
+
}
|
|
359
|
+
if (!desc.contentDOM && outsideBlock < 0 && !desc.node.isText) return (desc.node.isBlock ? coords.top < (rect.top + rect.bottom) / 2 : coords.left < (rect.left + rect.right) / 2) ? desc.posBefore : desc.posAfter;
|
|
360
|
+
}
|
|
361
|
+
cur = desc.dom.parentNode;
|
|
362
|
+
}
|
|
363
|
+
return outsideBlock > -1 ? outsideBlock : view.docView.posFromDOM(node, offset, -1);
|
|
364
|
+
}
|
|
365
|
+
function elementFromPoint(element, coords, box) {
|
|
366
|
+
let len = element.childNodes.length;
|
|
367
|
+
if (len && box.top < box.bottom) for (let startI = Math.max(0, Math.min(len - 1, Math.floor(len * (coords.top - box.top) / (box.bottom - box.top)) - 2)), i = startI;;) {
|
|
368
|
+
let child = element.childNodes[i];
|
|
369
|
+
if (child.nodeType == 1) {
|
|
370
|
+
let rects = child.getClientRects();
|
|
371
|
+
for (let j = 0; j < rects.length; j++) {
|
|
372
|
+
let rect = rects[j];
|
|
373
|
+
if (inRect(coords, rect)) return elementFromPoint(child, coords, rect);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if ((i = (i + 1) % len) == startI) break;
|
|
377
|
+
}
|
|
378
|
+
return element;
|
|
379
|
+
}
|
|
380
|
+
function posAtCoords(view, coords) {
|
|
381
|
+
let doc = view.dom.ownerDocument, node, offset = 0;
|
|
382
|
+
let caret = caretFromPoint(doc, coords.left, coords.top);
|
|
383
|
+
if (caret) ({node, offset} = caret);
|
|
384
|
+
let elt = (view.root.elementFromPoint ? view.root : doc).elementFromPoint(coords.left, coords.top);
|
|
385
|
+
let pos;
|
|
386
|
+
if (!elt || !view.dom.contains(elt.nodeType != 1 ? elt.parentNode : elt)) {
|
|
387
|
+
let box = view.dom.getBoundingClientRect();
|
|
388
|
+
if (!inRect(coords, box)) return null;
|
|
389
|
+
elt = elementFromPoint(view.dom, coords, box);
|
|
390
|
+
if (!elt) return null;
|
|
391
|
+
}
|
|
392
|
+
if (safari) {
|
|
393
|
+
for (let p = elt; node && p; p = parentNode(p)) if (p.draggable) node = void 0;
|
|
394
|
+
}
|
|
395
|
+
elt = targetKludge(elt, coords);
|
|
396
|
+
if (node) {
|
|
397
|
+
if (gecko && node.nodeType == 1) {
|
|
398
|
+
offset = Math.min(offset, node.childNodes.length);
|
|
399
|
+
if (offset < node.childNodes.length) {
|
|
400
|
+
let next = node.childNodes[offset], box;
|
|
401
|
+
if (next.nodeName == "IMG" && (box = next.getBoundingClientRect()).right <= coords.left && box.bottom > coords.top) offset++;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
let prev;
|
|
405
|
+
if (webkit && offset && node.nodeType == 1 && (prev = node.childNodes[offset - 1]).nodeType == 1 && prev.contentEditable == "false" && prev.getBoundingClientRect().top >= coords.top) offset--;
|
|
406
|
+
if (node == view.dom && offset == node.childNodes.length - 1 && node.lastChild.nodeType == 1 && coords.top > node.lastChild.getBoundingClientRect().bottom) pos = view.state.doc.content.size;
|
|
407
|
+
else if (offset == 0 || node.nodeType != 1 || node.childNodes[offset - 1].nodeName != "BR") pos = posFromCaret(view, node, offset, coords);
|
|
408
|
+
}
|
|
409
|
+
if (pos == null) pos = posFromElement(view, elt, coords);
|
|
410
|
+
let desc = view.docView.nearestDesc(elt, true);
|
|
411
|
+
return {
|
|
412
|
+
pos,
|
|
413
|
+
inside: desc ? desc.posAtStart - desc.border : -1
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
function nonZero(rect) {
|
|
417
|
+
return rect.top < rect.bottom || rect.left < rect.right;
|
|
418
|
+
}
|
|
419
|
+
function singleRect(target, bias) {
|
|
420
|
+
let rects = target.getClientRects();
|
|
421
|
+
if (rects.length) {
|
|
422
|
+
let first = rects[bias < 0 ? 0 : rects.length - 1];
|
|
423
|
+
if (nonZero(first)) return first;
|
|
424
|
+
}
|
|
425
|
+
return Array.prototype.find.call(rects, nonZero) || target.getBoundingClientRect();
|
|
426
|
+
}
|
|
427
|
+
var BIDI = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
|
|
428
|
+
function coordsAtPos(view, pos, side) {
|
|
429
|
+
let { node, offset, atom } = view.docView.domFromPos(pos, side < 0 ? -1 : 1);
|
|
430
|
+
let supportEmptyRange = webkit || gecko;
|
|
431
|
+
if (node.nodeType == 3) if (supportEmptyRange && (BIDI.test(node.nodeValue) || (side < 0 ? !offset : offset == node.nodeValue.length))) {
|
|
432
|
+
let rect = singleRect(textRange(node, offset, offset), side);
|
|
433
|
+
if (gecko && offset && /\s/.test(node.nodeValue[offset - 1]) && offset < node.nodeValue.length) {
|
|
434
|
+
let rectBefore = singleRect(textRange(node, offset - 1, offset - 1), -1);
|
|
435
|
+
if (rectBefore.top == rect.top) {
|
|
436
|
+
let rectAfter = singleRect(textRange(node, offset, offset + 1), -1);
|
|
437
|
+
if (rectAfter.top != rect.top) return flattenV(rectAfter, rectAfter.left < rectBefore.left);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return rect;
|
|
441
|
+
} else {
|
|
442
|
+
let from = offset, to = offset, takeSide = side < 0 ? 1 : -1;
|
|
443
|
+
if (side < 0 && !offset) {
|
|
444
|
+
to++;
|
|
445
|
+
takeSide = -1;
|
|
446
|
+
} else if (side >= 0 && offset == node.nodeValue.length) {
|
|
447
|
+
from--;
|
|
448
|
+
takeSide = 1;
|
|
449
|
+
} else if (side < 0) from--;
|
|
450
|
+
else to++;
|
|
451
|
+
return flattenV(singleRect(textRange(node, from, to), takeSide), takeSide < 0);
|
|
452
|
+
}
|
|
453
|
+
if (!view.state.doc.resolve(pos - (atom || 0)).parent.inlineContent) {
|
|
454
|
+
if (atom == null && offset && (side < 0 || offset == nodeSize(node))) {
|
|
455
|
+
let before = node.childNodes[offset - 1];
|
|
456
|
+
if (before.nodeType == 1) return flattenH(before.getBoundingClientRect(), false);
|
|
457
|
+
}
|
|
458
|
+
if (atom == null && offset < nodeSize(node)) {
|
|
459
|
+
let after = node.childNodes[offset];
|
|
460
|
+
if (after.nodeType == 1) return flattenH(after.getBoundingClientRect(), true);
|
|
461
|
+
}
|
|
462
|
+
return flattenH(node.getBoundingClientRect(), side >= 0);
|
|
463
|
+
}
|
|
464
|
+
if (atom == null && offset && (side < 0 || offset == nodeSize(node))) {
|
|
465
|
+
let before = node.childNodes[offset - 1];
|
|
466
|
+
let target = before.nodeType == 3 ? textRange(before, nodeSize(before) - (supportEmptyRange ? 0 : 1)) : before.nodeType == 1 && (before.nodeName != "BR" || !before.nextSibling) ? before : null;
|
|
467
|
+
if (target) return flattenV(singleRect(target, 1), false);
|
|
468
|
+
}
|
|
469
|
+
if (atom == null && offset < nodeSize(node)) {
|
|
470
|
+
let after = node.childNodes[offset];
|
|
471
|
+
while (after.pmViewDesc && after.pmViewDesc.ignoreForCoords) after = after.nextSibling;
|
|
472
|
+
let target = !after ? null : after.nodeType == 3 ? textRange(after, 0, supportEmptyRange ? 0 : 1) : after.nodeType == 1 ? after : null;
|
|
473
|
+
if (target) return flattenV(singleRect(target, -1), true);
|
|
474
|
+
}
|
|
475
|
+
return flattenV(singleRect(node.nodeType == 3 ? textRange(node) : node, -side), side >= 0);
|
|
476
|
+
}
|
|
477
|
+
function flattenV(rect, left) {
|
|
478
|
+
if (rect.width == 0) return rect;
|
|
479
|
+
let x = left ? rect.left : rect.right;
|
|
480
|
+
return {
|
|
481
|
+
top: rect.top,
|
|
482
|
+
bottom: rect.bottom,
|
|
483
|
+
left: x,
|
|
484
|
+
right: x
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
function flattenH(rect, top) {
|
|
488
|
+
if (rect.height == 0) return rect;
|
|
489
|
+
let y = top ? rect.top : rect.bottom;
|
|
490
|
+
return {
|
|
491
|
+
top: y,
|
|
492
|
+
bottom: y,
|
|
493
|
+
left: rect.left,
|
|
494
|
+
right: rect.right
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
function withFlushedState(view, state, f) {
|
|
498
|
+
let viewState = view.state, active = view.root.activeElement;
|
|
499
|
+
if (viewState != state) view.updateState(state);
|
|
500
|
+
if (active != view.dom) view.focus();
|
|
501
|
+
try {
|
|
502
|
+
return f();
|
|
503
|
+
} finally {
|
|
504
|
+
if (viewState != state) view.updateState(viewState);
|
|
505
|
+
if (active != view.dom && active) active.focus();
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function endOfTextblockVertical(view, state, dir) {
|
|
509
|
+
let sel = state.selection;
|
|
510
|
+
let $pos = dir == "up" ? sel.$from : sel.$to;
|
|
511
|
+
return withFlushedState(view, state, () => {
|
|
512
|
+
let { node: dom } = view.docView.domFromPos($pos.pos, dir == "up" ? -1 : 1);
|
|
513
|
+
for (;;) {
|
|
514
|
+
let nearest = view.docView.nearestDesc(dom, true);
|
|
515
|
+
if (!nearest) break;
|
|
516
|
+
if (nearest.node.isBlock) {
|
|
517
|
+
dom = nearest.contentDOM || nearest.dom;
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
dom = nearest.dom.parentNode;
|
|
521
|
+
}
|
|
522
|
+
let coords = coordsAtPos(view, $pos.pos, 1);
|
|
523
|
+
for (let child = dom.firstChild; child; child = child.nextSibling) {
|
|
524
|
+
let boxes;
|
|
525
|
+
if (child.nodeType == 1) boxes = child.getClientRects();
|
|
526
|
+
else if (child.nodeType == 3) boxes = textRange(child, 0, child.nodeValue.length).getClientRects();
|
|
527
|
+
else continue;
|
|
528
|
+
for (let i = 0; i < boxes.length; i++) {
|
|
529
|
+
let box = boxes[i];
|
|
530
|
+
if (box.bottom > box.top + 1 && (dir == "up" ? coords.top - box.top > (box.bottom - coords.top) * 2 : box.bottom - coords.bottom > (coords.bottom - box.top) * 2)) return false;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return true;
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
var maybeRTL = /[\u0590-\u08ac]/;
|
|
537
|
+
function endOfTextblockHorizontal(view, state, dir) {
|
|
538
|
+
let { $head } = state.selection;
|
|
539
|
+
if (!$head.parent.isTextblock) return false;
|
|
540
|
+
let offset = $head.parentOffset, atStart = !offset, atEnd = offset == $head.parent.content.size;
|
|
541
|
+
let sel = view.domSelection();
|
|
542
|
+
if (!sel) return $head.pos == $head.start() || $head.pos == $head.end();
|
|
543
|
+
if (!maybeRTL.test($head.parent.textContent) || !sel.modify) return dir == "left" || dir == "backward" ? atStart : atEnd;
|
|
544
|
+
return withFlushedState(view, state, () => {
|
|
545
|
+
let { focusNode: oldNode, focusOffset: oldOff, anchorNode, anchorOffset } = view.domSelectionRange();
|
|
546
|
+
let oldBidiLevel = sel.caretBidiLevel;
|
|
547
|
+
sel.modify("move", dir, "character");
|
|
548
|
+
let parentDOM = $head.depth ? view.docView.domAfterPos($head.before()) : view.dom;
|
|
549
|
+
let { focusNode: newNode, focusOffset: newOff } = view.domSelectionRange();
|
|
550
|
+
let result = newNode && !parentDOM.contains(newNode.nodeType == 1 ? newNode : newNode.parentNode) || oldNode == newNode && oldOff == newOff;
|
|
551
|
+
try {
|
|
552
|
+
sel.collapse(anchorNode, anchorOffset);
|
|
553
|
+
if (oldNode && (oldNode != anchorNode || oldOff != anchorOffset) && sel.extend) sel.extend(oldNode, oldOff);
|
|
554
|
+
} catch (_) {}
|
|
555
|
+
if (oldBidiLevel != null) sel.caretBidiLevel = oldBidiLevel;
|
|
556
|
+
return result;
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
var cachedState = null;
|
|
560
|
+
var cachedDir = null;
|
|
561
|
+
var cachedResult = false;
|
|
562
|
+
function endOfTextblock(view, state, dir) {
|
|
563
|
+
if (cachedState == state && cachedDir == dir) return cachedResult;
|
|
564
|
+
cachedState = state;
|
|
565
|
+
cachedDir = dir;
|
|
566
|
+
return cachedResult = dir == "up" || dir == "down" ? endOfTextblockVertical(view, state, dir) : endOfTextblockHorizontal(view, state, dir);
|
|
567
|
+
}
|
|
568
|
+
var NOT_DIRTY = 0, CHILD_DIRTY = 1, CONTENT_DIRTY = 2, NODE_DIRTY = 3;
|
|
569
|
+
var ViewDesc = class {
|
|
570
|
+
constructor(parent, children, dom, contentDOM) {
|
|
571
|
+
this.parent = parent;
|
|
572
|
+
this.children = children;
|
|
573
|
+
this.dom = dom;
|
|
574
|
+
this.contentDOM = contentDOM;
|
|
575
|
+
this.dirty = NOT_DIRTY;
|
|
576
|
+
dom.pmViewDesc = this;
|
|
577
|
+
}
|
|
578
|
+
matchesWidget(widget) {
|
|
579
|
+
return false;
|
|
580
|
+
}
|
|
581
|
+
matchesMark(mark) {
|
|
582
|
+
return false;
|
|
583
|
+
}
|
|
584
|
+
matchesNode(node, outerDeco, innerDeco) {
|
|
585
|
+
return false;
|
|
586
|
+
}
|
|
587
|
+
matchesHack(nodeName) {
|
|
588
|
+
return false;
|
|
589
|
+
}
|
|
590
|
+
parseRule() {
|
|
591
|
+
return null;
|
|
592
|
+
}
|
|
593
|
+
stopEvent(event) {
|
|
594
|
+
return false;
|
|
595
|
+
}
|
|
596
|
+
get size() {
|
|
597
|
+
let size = 0;
|
|
598
|
+
for (let i = 0; i < this.children.length; i++) size += this.children[i].size;
|
|
599
|
+
return size;
|
|
600
|
+
}
|
|
601
|
+
get border() {
|
|
602
|
+
return 0;
|
|
603
|
+
}
|
|
604
|
+
destroy() {
|
|
605
|
+
this.parent = void 0;
|
|
606
|
+
if (this.dom.pmViewDesc == this) this.dom.pmViewDesc = void 0;
|
|
607
|
+
for (let i = 0; i < this.children.length; i++) this.children[i].destroy();
|
|
608
|
+
}
|
|
609
|
+
posBeforeChild(child) {
|
|
610
|
+
for (let i = 0, pos = this.posAtStart;; i++) {
|
|
611
|
+
let cur = this.children[i];
|
|
612
|
+
if (cur == child) return pos;
|
|
613
|
+
pos += cur.size;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
get posBefore() {
|
|
617
|
+
return this.parent.posBeforeChild(this);
|
|
618
|
+
}
|
|
619
|
+
get posAtStart() {
|
|
620
|
+
return this.parent ? this.parent.posBeforeChild(this) + this.border : 0;
|
|
621
|
+
}
|
|
622
|
+
get posAfter() {
|
|
623
|
+
return this.posBefore + this.size;
|
|
624
|
+
}
|
|
625
|
+
get posAtEnd() {
|
|
626
|
+
return this.posAtStart + this.size - 2 * this.border;
|
|
627
|
+
}
|
|
628
|
+
localPosFromDOM(dom, offset, bias) {
|
|
629
|
+
if (this.contentDOM && this.contentDOM.contains(dom.nodeType == 1 ? dom : dom.parentNode)) if (bias < 0) {
|
|
630
|
+
let domBefore, desc;
|
|
631
|
+
if (dom == this.contentDOM) domBefore = dom.childNodes[offset - 1];
|
|
632
|
+
else {
|
|
633
|
+
while (dom.parentNode != this.contentDOM) dom = dom.parentNode;
|
|
634
|
+
domBefore = dom.previousSibling;
|
|
635
|
+
}
|
|
636
|
+
while (domBefore && !((desc = domBefore.pmViewDesc) && desc.parent == this)) domBefore = domBefore.previousSibling;
|
|
637
|
+
return domBefore ? this.posBeforeChild(desc) + desc.size : this.posAtStart;
|
|
638
|
+
} else {
|
|
639
|
+
let domAfter, desc;
|
|
640
|
+
if (dom == this.contentDOM) domAfter = dom.childNodes[offset];
|
|
641
|
+
else {
|
|
642
|
+
while (dom.parentNode != this.contentDOM) dom = dom.parentNode;
|
|
643
|
+
domAfter = dom.nextSibling;
|
|
644
|
+
}
|
|
645
|
+
while (domAfter && !((desc = domAfter.pmViewDesc) && desc.parent == this)) domAfter = domAfter.nextSibling;
|
|
646
|
+
return domAfter ? this.posBeforeChild(desc) : this.posAtEnd;
|
|
647
|
+
}
|
|
648
|
+
let atEnd;
|
|
649
|
+
if (dom == this.dom && this.contentDOM) atEnd = offset > domIndex(this.contentDOM);
|
|
650
|
+
else if (this.contentDOM && this.contentDOM != this.dom && this.dom.contains(this.contentDOM)) atEnd = dom.compareDocumentPosition(this.contentDOM) & 2;
|
|
651
|
+
else if (this.dom.firstChild) {
|
|
652
|
+
if (offset == 0) for (let search = dom;; search = search.parentNode) {
|
|
653
|
+
if (search == this.dom) {
|
|
654
|
+
atEnd = false;
|
|
655
|
+
break;
|
|
656
|
+
}
|
|
657
|
+
if (search.previousSibling) break;
|
|
658
|
+
}
|
|
659
|
+
if (atEnd == null && offset == dom.childNodes.length) for (let search = dom;; search = search.parentNode) {
|
|
660
|
+
if (search == this.dom) {
|
|
661
|
+
atEnd = true;
|
|
662
|
+
break;
|
|
663
|
+
}
|
|
664
|
+
if (search.nextSibling) break;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
return (atEnd == null ? bias > 0 : atEnd) ? this.posAtEnd : this.posAtStart;
|
|
668
|
+
}
|
|
669
|
+
nearestDesc(dom, onlyNodes = false) {
|
|
670
|
+
for (let first = true, cur = dom; cur; cur = cur.parentNode) {
|
|
671
|
+
let desc = this.getDesc(cur), nodeDOM;
|
|
672
|
+
if (desc && (!onlyNodes || desc.node)) if (first && (nodeDOM = desc.nodeDOM) && !(nodeDOM.nodeType == 1 ? nodeDOM.contains(dom.nodeType == 1 ? dom : dom.parentNode) : nodeDOM == dom)) first = false;
|
|
673
|
+
else return desc;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
getDesc(dom) {
|
|
677
|
+
let desc = dom.pmViewDesc;
|
|
678
|
+
for (let cur = desc; cur; cur = cur.parent) if (cur == this) return desc;
|
|
679
|
+
}
|
|
680
|
+
posFromDOM(dom, offset, bias) {
|
|
681
|
+
for (let scan = dom; scan; scan = scan.parentNode) {
|
|
682
|
+
let desc = this.getDesc(scan);
|
|
683
|
+
if (desc) return desc.localPosFromDOM(dom, offset, bias);
|
|
684
|
+
}
|
|
685
|
+
return -1;
|
|
686
|
+
}
|
|
687
|
+
descAt(pos) {
|
|
688
|
+
for (let i = 0, offset = 0; i < this.children.length; i++) {
|
|
689
|
+
let child = this.children[i], end = offset + child.size;
|
|
690
|
+
if (offset == pos && end != offset) {
|
|
691
|
+
while (!child.border && child.children.length) for (let i = 0; i < child.children.length; i++) {
|
|
692
|
+
let inner = child.children[i];
|
|
693
|
+
if (inner.size) {
|
|
694
|
+
child = inner;
|
|
695
|
+
break;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
return child;
|
|
699
|
+
}
|
|
700
|
+
if (pos < end) return child.descAt(pos - offset - child.border);
|
|
701
|
+
offset = end;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
domFromPos(pos, side) {
|
|
705
|
+
if (!this.contentDOM) return {
|
|
706
|
+
node: this.dom,
|
|
707
|
+
offset: 0,
|
|
708
|
+
atom: pos + 1
|
|
709
|
+
};
|
|
710
|
+
let i = 0, offset = 0;
|
|
711
|
+
for (let curPos = 0; i < this.children.length; i++) {
|
|
712
|
+
let child = this.children[i], end = curPos + child.size;
|
|
713
|
+
if (end > pos || child instanceof TrailingHackViewDesc) {
|
|
714
|
+
offset = pos - curPos;
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
curPos = end;
|
|
718
|
+
}
|
|
719
|
+
if (offset) return this.children[i].domFromPos(offset - this.children[i].border, side);
|
|
720
|
+
for (let prev; i && !(prev = this.children[i - 1]).size && prev instanceof WidgetViewDesc && prev.side >= 0; i--);
|
|
721
|
+
if (side <= 0) {
|
|
722
|
+
let prev, enter = true;
|
|
723
|
+
for (;; i--, enter = false) {
|
|
724
|
+
prev = i ? this.children[i - 1] : null;
|
|
725
|
+
if (!prev || prev.dom.parentNode == this.contentDOM) break;
|
|
726
|
+
}
|
|
727
|
+
if (prev && side && enter && !prev.border && !prev.domAtom) return prev.domFromPos(prev.size, side);
|
|
728
|
+
return {
|
|
729
|
+
node: this.contentDOM,
|
|
730
|
+
offset: prev ? domIndex(prev.dom) + 1 : 0
|
|
731
|
+
};
|
|
732
|
+
} else {
|
|
733
|
+
let next, enter = true;
|
|
734
|
+
for (;; i++, enter = false) {
|
|
735
|
+
next = i < this.children.length ? this.children[i] : null;
|
|
736
|
+
if (!next || next.dom.parentNode == this.contentDOM) break;
|
|
737
|
+
}
|
|
738
|
+
if (next && enter && !next.border && !next.domAtom) return next.domFromPos(0, side);
|
|
739
|
+
return {
|
|
740
|
+
node: this.contentDOM,
|
|
741
|
+
offset: next ? domIndex(next.dom) : this.contentDOM.childNodes.length
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
parseRange(from, to, base = 0) {
|
|
746
|
+
if (this.children.length == 0) return {
|
|
747
|
+
node: this.contentDOM,
|
|
748
|
+
from,
|
|
749
|
+
to,
|
|
750
|
+
fromOffset: 0,
|
|
751
|
+
toOffset: this.contentDOM.childNodes.length
|
|
752
|
+
};
|
|
753
|
+
let fromOffset = -1, toOffset = -1;
|
|
754
|
+
for (let offset = base, i = 0;; i++) {
|
|
755
|
+
let child = this.children[i], end = offset + child.size;
|
|
756
|
+
if (fromOffset == -1 && from <= end) {
|
|
757
|
+
let childBase = offset + child.border;
|
|
758
|
+
if (from >= childBase && to <= end - child.border && child.node && child.contentDOM && this.contentDOM.contains(child.contentDOM)) return child.parseRange(from, to, childBase);
|
|
759
|
+
from = offset;
|
|
760
|
+
for (let j = i; j > 0; j--) {
|
|
761
|
+
let prev = this.children[j - 1];
|
|
762
|
+
if (prev.size && prev.dom.parentNode == this.contentDOM && !prev.emptyChildAt(1)) {
|
|
763
|
+
fromOffset = domIndex(prev.dom) + 1;
|
|
764
|
+
break;
|
|
765
|
+
}
|
|
766
|
+
from -= prev.size;
|
|
767
|
+
}
|
|
768
|
+
if (fromOffset == -1) fromOffset = 0;
|
|
769
|
+
}
|
|
770
|
+
if (fromOffset > -1 && (end > to || i == this.children.length - 1)) {
|
|
771
|
+
to = end;
|
|
772
|
+
for (let j = i + 1; j < this.children.length; j++) {
|
|
773
|
+
let next = this.children[j];
|
|
774
|
+
if (next.size && next.dom.parentNode == this.contentDOM && !next.emptyChildAt(-1)) {
|
|
775
|
+
toOffset = domIndex(next.dom);
|
|
776
|
+
break;
|
|
777
|
+
}
|
|
778
|
+
to += next.size;
|
|
779
|
+
}
|
|
780
|
+
if (toOffset == -1) toOffset = this.contentDOM.childNodes.length;
|
|
781
|
+
break;
|
|
782
|
+
}
|
|
783
|
+
offset = end;
|
|
784
|
+
}
|
|
785
|
+
return {
|
|
786
|
+
node: this.contentDOM,
|
|
787
|
+
from,
|
|
788
|
+
to,
|
|
789
|
+
fromOffset,
|
|
790
|
+
toOffset
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
emptyChildAt(side) {
|
|
794
|
+
if (this.border || !this.contentDOM || !this.children.length) return false;
|
|
795
|
+
let child = this.children[side < 0 ? 0 : this.children.length - 1];
|
|
796
|
+
return child.size == 0 || child.emptyChildAt(side);
|
|
797
|
+
}
|
|
798
|
+
domAfterPos(pos) {
|
|
799
|
+
let { node, offset } = this.domFromPos(pos, 0);
|
|
800
|
+
if (node.nodeType != 1 || offset == node.childNodes.length) throw new RangeError("No node after pos " + pos);
|
|
801
|
+
return node.childNodes[offset];
|
|
802
|
+
}
|
|
803
|
+
setSelection(anchor, head, view, force = false) {
|
|
804
|
+
let from = Math.min(anchor, head), to = Math.max(anchor, head);
|
|
805
|
+
for (let i = 0, offset = 0; i < this.children.length; i++) {
|
|
806
|
+
let child = this.children[i], end = offset + child.size;
|
|
807
|
+
if (from > offset && to < end) return child.setSelection(anchor - offset - child.border, head - offset - child.border, view, force);
|
|
808
|
+
offset = end;
|
|
809
|
+
}
|
|
810
|
+
let anchorDOM = this.domFromPos(anchor, anchor ? -1 : 1);
|
|
811
|
+
let headDOM = head == anchor ? anchorDOM : this.domFromPos(head, head ? -1 : 1);
|
|
812
|
+
let domSel = view.root.getSelection();
|
|
813
|
+
let selRange = view.domSelectionRange();
|
|
814
|
+
let brKludge = false;
|
|
815
|
+
if ((gecko || safari) && anchor == head) {
|
|
816
|
+
let { node, offset } = anchorDOM;
|
|
817
|
+
if (node.nodeType == 3) {
|
|
818
|
+
brKludge = !!(offset && node.nodeValue[offset - 1] == "\n");
|
|
819
|
+
if (brKludge && offset == node.nodeValue.length) for (let scan = node, after; scan; scan = scan.parentNode) {
|
|
820
|
+
if (after = scan.nextSibling) {
|
|
821
|
+
if (after.nodeName == "BR") anchorDOM = headDOM = {
|
|
822
|
+
node: after.parentNode,
|
|
823
|
+
offset: domIndex(after) + 1
|
|
824
|
+
};
|
|
825
|
+
break;
|
|
826
|
+
}
|
|
827
|
+
let desc = scan.pmViewDesc;
|
|
828
|
+
if (desc && desc.node && desc.node.isBlock) break;
|
|
829
|
+
}
|
|
830
|
+
} else {
|
|
831
|
+
let prev = node.childNodes[offset - 1];
|
|
832
|
+
brKludge = prev && (prev.nodeName == "BR" || prev.contentEditable == "false");
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
if (gecko && selRange.focusNode && selRange.focusNode != headDOM.node && selRange.focusNode.nodeType == 1) {
|
|
836
|
+
let after = selRange.focusNode.childNodes[selRange.focusOffset];
|
|
837
|
+
if (after && after.contentEditable == "false") force = true;
|
|
838
|
+
}
|
|
839
|
+
if (!(force || brKludge && safari) && isEquivalentPosition(anchorDOM.node, anchorDOM.offset, selRange.anchorNode, selRange.anchorOffset) && isEquivalentPosition(headDOM.node, headDOM.offset, selRange.focusNode, selRange.focusOffset)) return;
|
|
840
|
+
let domSelExtended = false;
|
|
841
|
+
if ((domSel.extend || anchor == head) && !(brKludge && gecko)) {
|
|
842
|
+
domSel.collapse(anchorDOM.node, anchorDOM.offset);
|
|
843
|
+
try {
|
|
844
|
+
if (anchor != head) domSel.extend(headDOM.node, headDOM.offset);
|
|
845
|
+
domSelExtended = true;
|
|
846
|
+
} catch (_) {}
|
|
847
|
+
}
|
|
848
|
+
if (!domSelExtended) {
|
|
849
|
+
if (anchor > head) {
|
|
850
|
+
let tmp = anchorDOM;
|
|
851
|
+
anchorDOM = headDOM;
|
|
852
|
+
headDOM = tmp;
|
|
853
|
+
}
|
|
854
|
+
let range = document.createRange();
|
|
855
|
+
range.setEnd(headDOM.node, headDOM.offset);
|
|
856
|
+
range.setStart(anchorDOM.node, anchorDOM.offset);
|
|
857
|
+
domSel.removeAllRanges();
|
|
858
|
+
domSel.addRange(range);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
ignoreMutation(mutation) {
|
|
862
|
+
return !this.contentDOM && mutation.type != "selection";
|
|
863
|
+
}
|
|
864
|
+
get contentLost() {
|
|
865
|
+
return this.contentDOM && this.contentDOM != this.dom && !this.dom.contains(this.contentDOM);
|
|
866
|
+
}
|
|
867
|
+
markDirty(from, to) {
|
|
868
|
+
for (let offset = 0, i = 0; i < this.children.length; i++) {
|
|
869
|
+
let child = this.children[i], end = offset + child.size;
|
|
870
|
+
if (offset == end ? from <= end && to >= offset : from < end && to > offset) {
|
|
871
|
+
let startInside = offset + child.border, endInside = end - child.border;
|
|
872
|
+
if (from >= startInside && to <= endInside) {
|
|
873
|
+
this.dirty = from == offset || to == end ? CONTENT_DIRTY : CHILD_DIRTY;
|
|
874
|
+
if (from == startInside && to == endInside && (child.contentLost || child.dom.parentNode != this.contentDOM)) child.dirty = NODE_DIRTY;
|
|
875
|
+
else child.markDirty(from - startInside, to - startInside);
|
|
876
|
+
return;
|
|
877
|
+
} else child.dirty = child.dom == child.contentDOM && child.dom.parentNode == this.contentDOM && !child.children.length ? CONTENT_DIRTY : NODE_DIRTY;
|
|
878
|
+
}
|
|
879
|
+
offset = end;
|
|
880
|
+
}
|
|
881
|
+
this.dirty = CONTENT_DIRTY;
|
|
882
|
+
}
|
|
883
|
+
markParentsDirty() {
|
|
884
|
+
let level = 1;
|
|
885
|
+
for (let node = this.parent; node; node = node.parent, level++) {
|
|
886
|
+
let dirty = level == 1 ? CONTENT_DIRTY : CHILD_DIRTY;
|
|
887
|
+
if (node.dirty < dirty) node.dirty = dirty;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
get domAtom() {
|
|
891
|
+
return false;
|
|
892
|
+
}
|
|
893
|
+
get ignoreForCoords() {
|
|
894
|
+
return false;
|
|
895
|
+
}
|
|
896
|
+
get ignoreForSelection() {
|
|
897
|
+
return false;
|
|
898
|
+
}
|
|
899
|
+
isText(text) {
|
|
900
|
+
return false;
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
var WidgetViewDesc = class extends ViewDesc {
|
|
904
|
+
constructor(parent, widget, view, pos) {
|
|
905
|
+
let self, dom = widget.type.toDOM;
|
|
906
|
+
if (typeof dom == "function") dom = dom(view, () => {
|
|
907
|
+
if (!self) return pos;
|
|
908
|
+
if (self.parent) return self.parent.posBeforeChild(self);
|
|
909
|
+
});
|
|
910
|
+
if (!widget.type.spec.raw) {
|
|
911
|
+
if (dom.nodeType != 1) {
|
|
912
|
+
let wrap = document.createElement("span");
|
|
913
|
+
wrap.appendChild(dom);
|
|
914
|
+
dom = wrap;
|
|
915
|
+
}
|
|
916
|
+
dom.contentEditable = "false";
|
|
917
|
+
dom.classList.add("ProseMirror-widget");
|
|
918
|
+
}
|
|
919
|
+
super(parent, [], dom, null);
|
|
920
|
+
this.widget = widget;
|
|
921
|
+
this.widget = widget;
|
|
922
|
+
self = this;
|
|
923
|
+
}
|
|
924
|
+
matchesWidget(widget) {
|
|
925
|
+
return this.dirty == NOT_DIRTY && widget.type.eq(this.widget.type);
|
|
926
|
+
}
|
|
927
|
+
parseRule() {
|
|
928
|
+
return { ignore: true };
|
|
929
|
+
}
|
|
930
|
+
stopEvent(event) {
|
|
931
|
+
let stop = this.widget.spec.stopEvent;
|
|
932
|
+
return stop ? stop(event) : false;
|
|
933
|
+
}
|
|
934
|
+
ignoreMutation(mutation) {
|
|
935
|
+
return mutation.type != "selection" || this.widget.spec.ignoreSelection;
|
|
936
|
+
}
|
|
937
|
+
destroy() {
|
|
938
|
+
this.widget.type.destroy(this.dom);
|
|
939
|
+
super.destroy();
|
|
940
|
+
}
|
|
941
|
+
get domAtom() {
|
|
942
|
+
return true;
|
|
943
|
+
}
|
|
944
|
+
get ignoreForSelection() {
|
|
945
|
+
return !!this.widget.type.spec.relaxedSide;
|
|
946
|
+
}
|
|
947
|
+
get side() {
|
|
948
|
+
return this.widget.type.side;
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
var CompositionViewDesc = class extends ViewDesc {
|
|
952
|
+
constructor(parent, dom, textDOM, text) {
|
|
953
|
+
super(parent, [], dom, null);
|
|
954
|
+
this.textDOM = textDOM;
|
|
955
|
+
this.text = text;
|
|
956
|
+
}
|
|
957
|
+
get size() {
|
|
958
|
+
return this.text.length;
|
|
959
|
+
}
|
|
960
|
+
localPosFromDOM(dom, offset) {
|
|
961
|
+
if (dom != this.textDOM) return this.posAtStart + (offset ? this.size : 0);
|
|
962
|
+
return this.posAtStart + offset;
|
|
963
|
+
}
|
|
964
|
+
domFromPos(pos) {
|
|
965
|
+
return {
|
|
966
|
+
node: this.textDOM,
|
|
967
|
+
offset: pos
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
ignoreMutation(mut) {
|
|
971
|
+
return mut.type === "characterData" && mut.target.nodeValue == mut.oldValue;
|
|
972
|
+
}
|
|
973
|
+
};
|
|
974
|
+
var MarkViewDesc = class MarkViewDesc extends ViewDesc {
|
|
975
|
+
constructor(parent, mark, dom, contentDOM, spec) {
|
|
976
|
+
super(parent, [], dom, contentDOM);
|
|
977
|
+
this.mark = mark;
|
|
978
|
+
this.spec = spec;
|
|
979
|
+
}
|
|
980
|
+
static create(parent, mark, inline, view) {
|
|
981
|
+
let custom = view.nodeViews[mark.type.name];
|
|
982
|
+
let spec = custom && custom(mark, view, inline);
|
|
983
|
+
if (!spec || !spec.dom) spec = require_dist.DOMSerializer.renderSpec(document, mark.type.spec.toDOM(mark, inline), null, mark.attrs);
|
|
984
|
+
return new MarkViewDesc(parent, mark, spec.dom, spec.contentDOM || spec.dom, spec);
|
|
985
|
+
}
|
|
986
|
+
parseRule() {
|
|
987
|
+
if (this.dirty & NODE_DIRTY || this.mark.type.spec.reparseInView) return null;
|
|
988
|
+
return {
|
|
989
|
+
mark: this.mark.type.name,
|
|
990
|
+
attrs: this.mark.attrs,
|
|
991
|
+
contentElement: this.contentDOM
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
matchesMark(mark) {
|
|
995
|
+
return this.dirty != NODE_DIRTY && this.mark.eq(mark);
|
|
996
|
+
}
|
|
997
|
+
markDirty(from, to) {
|
|
998
|
+
super.markDirty(from, to);
|
|
999
|
+
if (this.dirty != NOT_DIRTY) {
|
|
1000
|
+
let parent = this.parent;
|
|
1001
|
+
while (!parent.node) parent = parent.parent;
|
|
1002
|
+
if (parent.dirty < this.dirty) parent.dirty = this.dirty;
|
|
1003
|
+
this.dirty = NOT_DIRTY;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
slice(from, to, view) {
|
|
1007
|
+
let copy = MarkViewDesc.create(this.parent, this.mark, true, view);
|
|
1008
|
+
let nodes = this.children, size = this.size;
|
|
1009
|
+
if (to < size) nodes = replaceNodes(nodes, to, size, view);
|
|
1010
|
+
if (from > 0) nodes = replaceNodes(nodes, 0, from, view);
|
|
1011
|
+
for (let i = 0; i < nodes.length; i++) nodes[i].parent = copy;
|
|
1012
|
+
copy.children = nodes;
|
|
1013
|
+
return copy;
|
|
1014
|
+
}
|
|
1015
|
+
ignoreMutation(mutation) {
|
|
1016
|
+
return this.spec.ignoreMutation ? this.spec.ignoreMutation(mutation) : super.ignoreMutation(mutation);
|
|
1017
|
+
}
|
|
1018
|
+
destroy() {
|
|
1019
|
+
if (this.spec.destroy) this.spec.destroy();
|
|
1020
|
+
super.destroy();
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
var NodeViewDesc = class NodeViewDesc extends ViewDesc {
|
|
1024
|
+
constructor(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, view, pos) {
|
|
1025
|
+
super(parent, [], dom, contentDOM);
|
|
1026
|
+
this.node = node;
|
|
1027
|
+
this.outerDeco = outerDeco;
|
|
1028
|
+
this.innerDeco = innerDeco;
|
|
1029
|
+
this.nodeDOM = nodeDOM;
|
|
1030
|
+
}
|
|
1031
|
+
static create(parent, node, outerDeco, innerDeco, view, pos) {
|
|
1032
|
+
let custom = view.nodeViews[node.type.name], descObj;
|
|
1033
|
+
let spec = custom && custom(node, view, () => {
|
|
1034
|
+
if (!descObj) return pos;
|
|
1035
|
+
if (descObj.parent) return descObj.parent.posBeforeChild(descObj);
|
|
1036
|
+
}, outerDeco, innerDeco);
|
|
1037
|
+
let dom = spec && spec.dom, contentDOM = spec && spec.contentDOM;
|
|
1038
|
+
if (node.isText) {
|
|
1039
|
+
if (!dom) dom = document.createTextNode(node.text);
|
|
1040
|
+
else if (dom.nodeType != 3) throw new RangeError("Text must be rendered as a DOM text node");
|
|
1041
|
+
} else if (!dom) {
|
|
1042
|
+
let spec = require_dist.DOMSerializer.renderSpec(document, node.type.spec.toDOM(node), null, node.attrs);
|
|
1043
|
+
({dom, contentDOM} = spec);
|
|
1044
|
+
}
|
|
1045
|
+
if (!contentDOM && !node.isText && dom.nodeName != "BR") {
|
|
1046
|
+
if (!dom.hasAttribute("contenteditable")) dom.contentEditable = "false";
|
|
1047
|
+
if (node.type.spec.draggable) dom.draggable = true;
|
|
1048
|
+
}
|
|
1049
|
+
let nodeDOM = dom;
|
|
1050
|
+
dom = applyOuterDeco(dom, outerDeco, node);
|
|
1051
|
+
if (spec) return descObj = new CustomNodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM || null, nodeDOM, spec, view, pos + 1);
|
|
1052
|
+
else if (node.isText) return new TextViewDesc(parent, node, outerDeco, innerDeco, dom, nodeDOM, view);
|
|
1053
|
+
else return new NodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM || null, nodeDOM, view, pos + 1);
|
|
1054
|
+
}
|
|
1055
|
+
parseRule() {
|
|
1056
|
+
if (this.node.type.spec.reparseInView) return null;
|
|
1057
|
+
let rule = {
|
|
1058
|
+
node: this.node.type.name,
|
|
1059
|
+
attrs: this.node.attrs
|
|
1060
|
+
};
|
|
1061
|
+
if (this.node.type.whitespace == "pre") rule.preserveWhitespace = "full";
|
|
1062
|
+
if (!this.contentDOM) rule.getContent = () => this.node.content;
|
|
1063
|
+
else if (!this.contentLost) rule.contentElement = this.contentDOM;
|
|
1064
|
+
else {
|
|
1065
|
+
for (let i = this.children.length - 1; i >= 0; i--) {
|
|
1066
|
+
let child = this.children[i];
|
|
1067
|
+
if (this.dom.contains(child.dom.parentNode)) {
|
|
1068
|
+
rule.contentElement = child.dom.parentNode;
|
|
1069
|
+
break;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
if (!rule.contentElement) rule.getContent = () => require_dist.Fragment.empty;
|
|
1073
|
+
}
|
|
1074
|
+
return rule;
|
|
1075
|
+
}
|
|
1076
|
+
matchesNode(node, outerDeco, innerDeco) {
|
|
1077
|
+
return this.dirty == NOT_DIRTY && node.eq(this.node) && sameOuterDeco(outerDeco, this.outerDeco) && innerDeco.eq(this.innerDeco);
|
|
1078
|
+
}
|
|
1079
|
+
get size() {
|
|
1080
|
+
return this.node.nodeSize;
|
|
1081
|
+
}
|
|
1082
|
+
get border() {
|
|
1083
|
+
return this.node.isLeaf ? 0 : 1;
|
|
1084
|
+
}
|
|
1085
|
+
updateChildren(view, pos) {
|
|
1086
|
+
let inline = this.node.inlineContent, off = pos;
|
|
1087
|
+
let composition = view.composing ? this.localCompositionInfo(view, pos) : null;
|
|
1088
|
+
let localComposition = composition && composition.pos > -1 ? composition : null;
|
|
1089
|
+
let compositionInChild = composition && composition.pos < 0;
|
|
1090
|
+
let updater = new ViewTreeUpdater(this, localComposition && localComposition.node, view);
|
|
1091
|
+
iterDeco(this.node, this.innerDeco, (widget, i, insideNode) => {
|
|
1092
|
+
if (widget.spec.marks) updater.syncToMarks(widget.spec.marks, inline, view, i);
|
|
1093
|
+
else if (widget.type.side >= 0 && !insideNode) updater.syncToMarks(i == this.node.childCount ? require_dist.Mark.none : this.node.child(i).marks, inline, view, i);
|
|
1094
|
+
updater.placeWidget(widget, view, off);
|
|
1095
|
+
}, (child, outerDeco, innerDeco, i) => {
|
|
1096
|
+
updater.syncToMarks(child.marks, inline, view, i);
|
|
1097
|
+
let compIndex;
|
|
1098
|
+
if (updater.findNodeMatch(child, outerDeco, innerDeco, i));
|
|
1099
|
+
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));
|
|
1100
|
+
else if (updater.updateNextNode(child, outerDeco, innerDeco, view, i, off));
|
|
1101
|
+
else updater.addNode(child, outerDeco, innerDeco, view, off);
|
|
1102
|
+
off += child.nodeSize;
|
|
1103
|
+
});
|
|
1104
|
+
updater.syncToMarks([], inline, view, 0);
|
|
1105
|
+
if (this.node.isTextblock) updater.addTextblockHacks();
|
|
1106
|
+
updater.destroyRest();
|
|
1107
|
+
if (updater.changed || this.dirty == CONTENT_DIRTY) {
|
|
1108
|
+
if (localComposition) this.protectLocalComposition(view, localComposition);
|
|
1109
|
+
renderDescs(this.contentDOM, this.children, view);
|
|
1110
|
+
if (ios) iosHacks(this.dom);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
localCompositionInfo(view, pos) {
|
|
1114
|
+
let { from, to } = view.state.selection;
|
|
1115
|
+
if (!(view.state.selection instanceof require_dist.TextSelection) || from < pos || to > pos + this.node.content.size) return null;
|
|
1116
|
+
let textNode = view.input.compositionNode;
|
|
1117
|
+
if (!textNode || !this.dom.contains(textNode.parentNode)) return null;
|
|
1118
|
+
if (this.node.inlineContent) {
|
|
1119
|
+
let text = textNode.nodeValue;
|
|
1120
|
+
let textPos = findTextInFragment(this.node.content, text, from - pos, to - pos);
|
|
1121
|
+
return textPos < 0 ? null : {
|
|
1122
|
+
node: textNode,
|
|
1123
|
+
pos: textPos,
|
|
1124
|
+
text
|
|
1125
|
+
};
|
|
1126
|
+
} else return {
|
|
1127
|
+
node: textNode,
|
|
1128
|
+
pos: -1,
|
|
1129
|
+
text: ""
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
protectLocalComposition(view, { node, pos, text }) {
|
|
1133
|
+
if (this.getDesc(node)) return;
|
|
1134
|
+
let topNode = node;
|
|
1135
|
+
for (;; topNode = topNode.parentNode) {
|
|
1136
|
+
if (topNode.parentNode == this.contentDOM) break;
|
|
1137
|
+
while (topNode.previousSibling) topNode.parentNode.removeChild(topNode.previousSibling);
|
|
1138
|
+
while (topNode.nextSibling) topNode.parentNode.removeChild(topNode.nextSibling);
|
|
1139
|
+
if (topNode.pmViewDesc) topNode.pmViewDesc = void 0;
|
|
1140
|
+
}
|
|
1141
|
+
let desc = new CompositionViewDesc(this, topNode, node, text);
|
|
1142
|
+
view.input.compositionNodes.push(desc);
|
|
1143
|
+
this.children = replaceNodes(this.children, pos, pos + text.length, view, desc);
|
|
1144
|
+
}
|
|
1145
|
+
update(node, outerDeco, innerDeco, view) {
|
|
1146
|
+
if (this.dirty == NODE_DIRTY || !node.sameMarkup(this.node)) return false;
|
|
1147
|
+
this.updateInner(node, outerDeco, innerDeco, view);
|
|
1148
|
+
return true;
|
|
1149
|
+
}
|
|
1150
|
+
updateInner(node, outerDeco, innerDeco, view) {
|
|
1151
|
+
this.updateOuterDeco(outerDeco);
|
|
1152
|
+
this.node = node;
|
|
1153
|
+
this.innerDeco = innerDeco;
|
|
1154
|
+
if (this.contentDOM) this.updateChildren(view, this.posAtStart);
|
|
1155
|
+
this.dirty = NOT_DIRTY;
|
|
1156
|
+
}
|
|
1157
|
+
updateOuterDeco(outerDeco) {
|
|
1158
|
+
if (sameOuterDeco(outerDeco, this.outerDeco)) return;
|
|
1159
|
+
let needsWrap = this.nodeDOM.nodeType != 1;
|
|
1160
|
+
let oldDOM = this.dom;
|
|
1161
|
+
this.dom = patchOuterDeco(this.dom, this.nodeDOM, computeOuterDeco(this.outerDeco, this.node, needsWrap), computeOuterDeco(outerDeco, this.node, needsWrap));
|
|
1162
|
+
if (this.dom != oldDOM) {
|
|
1163
|
+
oldDOM.pmViewDesc = void 0;
|
|
1164
|
+
this.dom.pmViewDesc = this;
|
|
1165
|
+
}
|
|
1166
|
+
this.outerDeco = outerDeco;
|
|
1167
|
+
}
|
|
1168
|
+
selectNode() {
|
|
1169
|
+
if (this.nodeDOM.nodeType == 1) {
|
|
1170
|
+
this.nodeDOM.classList.add("ProseMirror-selectednode");
|
|
1171
|
+
if (this.contentDOM || !this.node.type.spec.draggable) this.nodeDOM.draggable = true;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
deselectNode() {
|
|
1175
|
+
if (this.nodeDOM.nodeType == 1) {
|
|
1176
|
+
this.nodeDOM.classList.remove("ProseMirror-selectednode");
|
|
1177
|
+
if (this.contentDOM || !this.node.type.spec.draggable) this.nodeDOM.removeAttribute("draggable");
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
get domAtom() {
|
|
1181
|
+
return this.node.isAtom;
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
function docViewDesc(doc, outerDeco, innerDeco, dom, view) {
|
|
1185
|
+
applyOuterDeco(dom, outerDeco, doc);
|
|
1186
|
+
let docView = new NodeViewDesc(void 0, doc, outerDeco, innerDeco, dom, dom, dom, view, 0);
|
|
1187
|
+
if (docView.contentDOM) docView.updateChildren(view, 0);
|
|
1188
|
+
return docView;
|
|
1189
|
+
}
|
|
1190
|
+
var TextViewDesc = class TextViewDesc extends NodeViewDesc {
|
|
1191
|
+
constructor(parent, node, outerDeco, innerDeco, dom, nodeDOM, view) {
|
|
1192
|
+
super(parent, node, outerDeco, innerDeco, dom, null, nodeDOM, view, 0);
|
|
1193
|
+
}
|
|
1194
|
+
parseRule() {
|
|
1195
|
+
let skip = this.nodeDOM.parentNode;
|
|
1196
|
+
while (skip && skip != this.dom && !skip.pmIsDeco) skip = skip.parentNode;
|
|
1197
|
+
return { skip: skip || true };
|
|
1198
|
+
}
|
|
1199
|
+
update(node, outerDeco, innerDeco, view) {
|
|
1200
|
+
if (this.dirty == NODE_DIRTY || this.dirty != NOT_DIRTY && !this.inParent() || !node.sameMarkup(this.node)) return false;
|
|
1201
|
+
this.updateOuterDeco(outerDeco);
|
|
1202
|
+
if ((this.dirty != NOT_DIRTY || node.text != this.node.text) && node.text != this.nodeDOM.nodeValue) {
|
|
1203
|
+
this.nodeDOM.nodeValue = node.text;
|
|
1204
|
+
if (view.trackWrites == this.nodeDOM) view.trackWrites = null;
|
|
1205
|
+
}
|
|
1206
|
+
this.node = node;
|
|
1207
|
+
this.dirty = NOT_DIRTY;
|
|
1208
|
+
return true;
|
|
1209
|
+
}
|
|
1210
|
+
inParent() {
|
|
1211
|
+
let parentDOM = this.parent.contentDOM;
|
|
1212
|
+
for (let n = this.nodeDOM; n; n = n.parentNode) if (n == parentDOM) return true;
|
|
1213
|
+
return false;
|
|
1214
|
+
}
|
|
1215
|
+
domFromPos(pos) {
|
|
1216
|
+
return {
|
|
1217
|
+
node: this.nodeDOM,
|
|
1218
|
+
offset: pos
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
localPosFromDOM(dom, offset, bias) {
|
|
1222
|
+
if (dom == this.nodeDOM) return this.posAtStart + Math.min(offset, this.node.text.length);
|
|
1223
|
+
return super.localPosFromDOM(dom, offset, bias);
|
|
1224
|
+
}
|
|
1225
|
+
ignoreMutation(mutation) {
|
|
1226
|
+
return mutation.type != "characterData" && mutation.type != "selection";
|
|
1227
|
+
}
|
|
1228
|
+
slice(from, to, view) {
|
|
1229
|
+
let node = this.node.cut(from, to), dom = document.createTextNode(node.text);
|
|
1230
|
+
return new TextViewDesc(this.parent, node, this.outerDeco, this.innerDeco, dom, dom, view);
|
|
1231
|
+
}
|
|
1232
|
+
markDirty(from, to) {
|
|
1233
|
+
super.markDirty(from, to);
|
|
1234
|
+
if (this.dom != this.nodeDOM && (from == 0 || to == this.nodeDOM.nodeValue.length)) this.dirty = NODE_DIRTY;
|
|
1235
|
+
}
|
|
1236
|
+
get domAtom() {
|
|
1237
|
+
return false;
|
|
1238
|
+
}
|
|
1239
|
+
isText(text) {
|
|
1240
|
+
return this.node.text == text;
|
|
1241
|
+
}
|
|
1242
|
+
};
|
|
1243
|
+
var TrailingHackViewDesc = class extends ViewDesc {
|
|
1244
|
+
parseRule() {
|
|
1245
|
+
return { ignore: true };
|
|
1246
|
+
}
|
|
1247
|
+
matchesHack(nodeName) {
|
|
1248
|
+
return this.dirty == NOT_DIRTY && this.dom.nodeName == nodeName;
|
|
1249
|
+
}
|
|
1250
|
+
get domAtom() {
|
|
1251
|
+
return true;
|
|
1252
|
+
}
|
|
1253
|
+
get ignoreForCoords() {
|
|
1254
|
+
return this.dom.nodeName == "IMG";
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
var CustomNodeViewDesc = class extends NodeViewDesc {
|
|
1258
|
+
constructor(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, spec, view, pos) {
|
|
1259
|
+
super(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, view, pos);
|
|
1260
|
+
this.spec = spec;
|
|
1261
|
+
}
|
|
1262
|
+
update(node, outerDeco, innerDeco, view) {
|
|
1263
|
+
if (this.dirty == NODE_DIRTY) return false;
|
|
1264
|
+
if (this.spec.update && (this.node.type == node.type || this.spec.multiType)) {
|
|
1265
|
+
let result = this.spec.update(node, outerDeco, innerDeco);
|
|
1266
|
+
if (result) this.updateInner(node, outerDeco, innerDeco, view);
|
|
1267
|
+
return result;
|
|
1268
|
+
} else if (!this.contentDOM && !node.isLeaf) return false;
|
|
1269
|
+
else return super.update(node, outerDeco, innerDeco, view);
|
|
1270
|
+
}
|
|
1271
|
+
selectNode() {
|
|
1272
|
+
this.spec.selectNode ? this.spec.selectNode() : super.selectNode();
|
|
1273
|
+
}
|
|
1274
|
+
deselectNode() {
|
|
1275
|
+
this.spec.deselectNode ? this.spec.deselectNode() : super.deselectNode();
|
|
1276
|
+
}
|
|
1277
|
+
setSelection(anchor, head, view, force) {
|
|
1278
|
+
this.spec.setSelection ? this.spec.setSelection(anchor, head, view.root) : super.setSelection(anchor, head, view, force);
|
|
1279
|
+
}
|
|
1280
|
+
destroy() {
|
|
1281
|
+
if (this.spec.destroy) this.spec.destroy();
|
|
1282
|
+
super.destroy();
|
|
1283
|
+
}
|
|
1284
|
+
stopEvent(event) {
|
|
1285
|
+
return this.spec.stopEvent ? this.spec.stopEvent(event) : false;
|
|
1286
|
+
}
|
|
1287
|
+
ignoreMutation(mutation) {
|
|
1288
|
+
return this.spec.ignoreMutation ? this.spec.ignoreMutation(mutation) : super.ignoreMutation(mutation);
|
|
1289
|
+
}
|
|
1290
|
+
};
|
|
1291
|
+
function renderDescs(parentDOM, descs, view) {
|
|
1292
|
+
let dom = parentDOM.firstChild, written = false;
|
|
1293
|
+
for (let i = 0; i < descs.length; i++) {
|
|
1294
|
+
let desc = descs[i], childDOM = desc.dom;
|
|
1295
|
+
if (childDOM.parentNode == parentDOM) {
|
|
1296
|
+
while (childDOM != dom) {
|
|
1297
|
+
dom = rm(dom);
|
|
1298
|
+
written = true;
|
|
1299
|
+
}
|
|
1300
|
+
dom = dom.nextSibling;
|
|
1301
|
+
} else {
|
|
1302
|
+
written = true;
|
|
1303
|
+
parentDOM.insertBefore(childDOM, dom);
|
|
1304
|
+
}
|
|
1305
|
+
if (desc instanceof MarkViewDesc) {
|
|
1306
|
+
let pos = dom ? dom.previousSibling : parentDOM.lastChild;
|
|
1307
|
+
renderDescs(desc.contentDOM, desc.children, view);
|
|
1308
|
+
dom = pos ? pos.nextSibling : parentDOM.firstChild;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
while (dom) {
|
|
1312
|
+
dom = rm(dom);
|
|
1313
|
+
written = true;
|
|
1314
|
+
}
|
|
1315
|
+
if (written && view.trackWrites == parentDOM) view.trackWrites = null;
|
|
1316
|
+
}
|
|
1317
|
+
var OuterDecoLevel = function(nodeName) {
|
|
1318
|
+
if (nodeName) this.nodeName = nodeName;
|
|
1319
|
+
};
|
|
1320
|
+
OuterDecoLevel.prototype = Object.create(null);
|
|
1321
|
+
var noDeco = [new OuterDecoLevel()];
|
|
1322
|
+
function computeOuterDeco(outerDeco, node, needsWrap) {
|
|
1323
|
+
if (outerDeco.length == 0) return noDeco;
|
|
1324
|
+
let top = needsWrap ? noDeco[0] : new OuterDecoLevel(), result = [top];
|
|
1325
|
+
for (let i = 0; i < outerDeco.length; i++) {
|
|
1326
|
+
let attrs = outerDeco[i].type.attrs;
|
|
1327
|
+
if (!attrs) continue;
|
|
1328
|
+
if (attrs.nodeName) result.push(top = new OuterDecoLevel(attrs.nodeName));
|
|
1329
|
+
for (let name in attrs) {
|
|
1330
|
+
let val = attrs[name];
|
|
1331
|
+
if (val == null) continue;
|
|
1332
|
+
if (needsWrap && result.length == 1) result.push(top = new OuterDecoLevel(node.isInline ? "span" : "div"));
|
|
1333
|
+
if (name == "class") top.class = (top.class ? top.class + " " : "") + val;
|
|
1334
|
+
else if (name == "style") top.style = (top.style ? top.style + ";" : "") + val;
|
|
1335
|
+
else if (name != "nodeName") top[name] = val;
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
return result;
|
|
1339
|
+
}
|
|
1340
|
+
function patchOuterDeco(outerDOM, nodeDOM, prevComputed, curComputed) {
|
|
1341
|
+
if (prevComputed == noDeco && curComputed == noDeco) return nodeDOM;
|
|
1342
|
+
let curDOM = nodeDOM;
|
|
1343
|
+
for (let i = 0; i < curComputed.length; i++) {
|
|
1344
|
+
let deco = curComputed[i], prev = prevComputed[i];
|
|
1345
|
+
if (i) {
|
|
1346
|
+
let parent;
|
|
1347
|
+
if (prev && prev.nodeName == deco.nodeName && curDOM != outerDOM && (parent = curDOM.parentNode) && parent.nodeName.toLowerCase() == deco.nodeName) curDOM = parent;
|
|
1348
|
+
else {
|
|
1349
|
+
parent = document.createElement(deco.nodeName);
|
|
1350
|
+
parent.pmIsDeco = true;
|
|
1351
|
+
parent.appendChild(curDOM);
|
|
1352
|
+
prev = noDeco[0];
|
|
1353
|
+
curDOM = parent;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
patchAttributes(curDOM, prev || noDeco[0], deco);
|
|
1357
|
+
}
|
|
1358
|
+
return curDOM;
|
|
1359
|
+
}
|
|
1360
|
+
function patchAttributes(dom, prev, cur) {
|
|
1361
|
+
for (let name in prev) if (name != "class" && name != "style" && name != "nodeName" && !(name in cur)) dom.removeAttribute(name);
|
|
1362
|
+
for (let name in cur) if (name != "class" && name != "style" && name != "nodeName" && cur[name] != prev[name]) dom.setAttribute(name, cur[name]);
|
|
1363
|
+
if (prev.class != cur.class) {
|
|
1364
|
+
let prevList = prev.class ? prev.class.split(" ").filter(Boolean) : [];
|
|
1365
|
+
let curList = cur.class ? cur.class.split(" ").filter(Boolean) : [];
|
|
1366
|
+
for (let i = 0; i < prevList.length; i++) if (curList.indexOf(prevList[i]) == -1) dom.classList.remove(prevList[i]);
|
|
1367
|
+
for (let i = 0; i < curList.length; i++) if (prevList.indexOf(curList[i]) == -1) dom.classList.add(curList[i]);
|
|
1368
|
+
if (dom.classList.length == 0) dom.removeAttribute("class");
|
|
1369
|
+
}
|
|
1370
|
+
if (prev.style != cur.style) {
|
|
1371
|
+
if (prev.style) {
|
|
1372
|
+
let prop = /\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g, m;
|
|
1373
|
+
while (m = prop.exec(prev.style)) dom.style.removeProperty(m[1]);
|
|
1374
|
+
}
|
|
1375
|
+
if (cur.style) dom.style.cssText += cur.style;
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
function applyOuterDeco(dom, deco, node) {
|
|
1379
|
+
return patchOuterDeco(dom, dom, noDeco, computeOuterDeco(deco, node, dom.nodeType != 1));
|
|
1380
|
+
}
|
|
1381
|
+
function sameOuterDeco(a, b) {
|
|
1382
|
+
if (a.length != b.length) return false;
|
|
1383
|
+
for (let i = 0; i < a.length; i++) if (!a[i].type.eq(b[i].type)) return false;
|
|
1384
|
+
return true;
|
|
1385
|
+
}
|
|
1386
|
+
function rm(dom) {
|
|
1387
|
+
let next = dom.nextSibling;
|
|
1388
|
+
dom.parentNode.removeChild(dom);
|
|
1389
|
+
return next;
|
|
1390
|
+
}
|
|
1391
|
+
var ViewTreeUpdater = class {
|
|
1392
|
+
constructor(top, lock, view) {
|
|
1393
|
+
this.lock = lock;
|
|
1394
|
+
this.view = view;
|
|
1395
|
+
this.index = 0;
|
|
1396
|
+
this.stack = [];
|
|
1397
|
+
this.changed = false;
|
|
1398
|
+
this.top = top;
|
|
1399
|
+
this.preMatch = preMatch(top.node.content, top);
|
|
1400
|
+
}
|
|
1401
|
+
destroyBetween(start, end) {
|
|
1402
|
+
if (start == end) return;
|
|
1403
|
+
for (let i = start; i < end; i++) this.top.children[i].destroy();
|
|
1404
|
+
this.top.children.splice(start, end - start);
|
|
1405
|
+
this.changed = true;
|
|
1406
|
+
}
|
|
1407
|
+
destroyRest() {
|
|
1408
|
+
this.destroyBetween(this.index, this.top.children.length);
|
|
1409
|
+
}
|
|
1410
|
+
syncToMarks(marks, inline, view, parentIndex) {
|
|
1411
|
+
let keep = 0, depth = this.stack.length >> 1;
|
|
1412
|
+
let maxKeep = Math.min(depth, marks.length);
|
|
1413
|
+
while (keep < maxKeep && (keep == depth - 1 ? this.top : this.stack[keep + 1 << 1]).matchesMark(marks[keep]) && marks[keep].type.spec.spanning !== false) keep++;
|
|
1414
|
+
while (keep < depth) {
|
|
1415
|
+
this.destroyRest();
|
|
1416
|
+
this.top.dirty = NOT_DIRTY;
|
|
1417
|
+
this.index = this.stack.pop();
|
|
1418
|
+
this.top = this.stack.pop();
|
|
1419
|
+
depth--;
|
|
1420
|
+
}
|
|
1421
|
+
while (depth < marks.length) {
|
|
1422
|
+
this.stack.push(this.top, this.index + 1);
|
|
1423
|
+
let found = -1, scanTo = this.top.children.length;
|
|
1424
|
+
if (parentIndex < this.preMatch.index) scanTo = Math.min(this.index + 3, scanTo);
|
|
1425
|
+
for (let i = this.index; i < scanTo; i++) {
|
|
1426
|
+
let next = this.top.children[i];
|
|
1427
|
+
if (next.matchesMark(marks[depth]) && !this.isLocked(next.dom)) {
|
|
1428
|
+
found = i;
|
|
1429
|
+
break;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
if (found > -1) {
|
|
1433
|
+
if (found > this.index) {
|
|
1434
|
+
this.changed = true;
|
|
1435
|
+
this.destroyBetween(this.index, found);
|
|
1436
|
+
}
|
|
1437
|
+
this.top = this.top.children[this.index];
|
|
1438
|
+
} else {
|
|
1439
|
+
let markDesc = MarkViewDesc.create(this.top, marks[depth], inline, view);
|
|
1440
|
+
this.top.children.splice(this.index, 0, markDesc);
|
|
1441
|
+
this.top = markDesc;
|
|
1442
|
+
this.changed = true;
|
|
1443
|
+
}
|
|
1444
|
+
this.index = 0;
|
|
1445
|
+
depth++;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
findNodeMatch(node, outerDeco, innerDeco, index) {
|
|
1449
|
+
let found = -1, targetDesc;
|
|
1450
|
+
if (index >= this.preMatch.index && (targetDesc = this.preMatch.matches[index - this.preMatch.index]).parent == this.top && targetDesc.matchesNode(node, outerDeco, innerDeco)) found = this.top.children.indexOf(targetDesc, this.index);
|
|
1451
|
+
else for (let i = this.index, e = Math.min(this.top.children.length, i + 5); i < e; i++) {
|
|
1452
|
+
let child = this.top.children[i];
|
|
1453
|
+
if (child.matchesNode(node, outerDeco, innerDeco) && !this.preMatch.matched.has(child)) {
|
|
1454
|
+
found = i;
|
|
1455
|
+
break;
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
if (found < 0) return false;
|
|
1459
|
+
this.destroyBetween(this.index, found);
|
|
1460
|
+
this.index++;
|
|
1461
|
+
return true;
|
|
1462
|
+
}
|
|
1463
|
+
updateNodeAt(node, outerDeco, innerDeco, index, view) {
|
|
1464
|
+
let child = this.top.children[index];
|
|
1465
|
+
if (child.dirty == NODE_DIRTY && child.dom == child.contentDOM) child.dirty = CONTENT_DIRTY;
|
|
1466
|
+
if (!child.update(node, outerDeco, innerDeco, view)) return false;
|
|
1467
|
+
this.destroyBetween(this.index, index);
|
|
1468
|
+
this.index++;
|
|
1469
|
+
return true;
|
|
1470
|
+
}
|
|
1471
|
+
findIndexWithChild(domNode) {
|
|
1472
|
+
for (;;) {
|
|
1473
|
+
let parent = domNode.parentNode;
|
|
1474
|
+
if (!parent) return -1;
|
|
1475
|
+
if (parent == this.top.contentDOM) {
|
|
1476
|
+
let desc = domNode.pmViewDesc;
|
|
1477
|
+
if (desc) {
|
|
1478
|
+
for (let i = this.index; i < this.top.children.length; i++) if (this.top.children[i] == desc) return i;
|
|
1479
|
+
}
|
|
1480
|
+
return -1;
|
|
1481
|
+
}
|
|
1482
|
+
domNode = parent;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
updateNextNode(node, outerDeco, innerDeco, view, index, pos) {
|
|
1486
|
+
for (let i = this.index; i < this.top.children.length; i++) {
|
|
1487
|
+
let next = this.top.children[i];
|
|
1488
|
+
if (next instanceof NodeViewDesc) {
|
|
1489
|
+
let preMatch = this.preMatch.matched.get(next);
|
|
1490
|
+
if (preMatch != null && preMatch != index) return false;
|
|
1491
|
+
let nextDOM = next.dom, updated;
|
|
1492
|
+
let locked = this.isLocked(nextDOM) && !(node.isText && next.node && next.node.isText && next.nodeDOM.nodeValue == node.text && next.dirty != NODE_DIRTY && sameOuterDeco(outerDeco, next.outerDeco));
|
|
1493
|
+
if (!locked && next.update(node, outerDeco, innerDeco, view)) {
|
|
1494
|
+
this.destroyBetween(this.index, i);
|
|
1495
|
+
if (next.dom != nextDOM) this.changed = true;
|
|
1496
|
+
this.index++;
|
|
1497
|
+
return true;
|
|
1498
|
+
} else if (!locked && (updated = this.recreateWrapper(next, node, outerDeco, innerDeco, view, pos))) {
|
|
1499
|
+
this.destroyBetween(this.index, i);
|
|
1500
|
+
this.top.children[this.index] = updated;
|
|
1501
|
+
if (updated.contentDOM) {
|
|
1502
|
+
updated.dirty = CONTENT_DIRTY;
|
|
1503
|
+
updated.updateChildren(view, pos + 1);
|
|
1504
|
+
updated.dirty = NOT_DIRTY;
|
|
1505
|
+
}
|
|
1506
|
+
this.changed = true;
|
|
1507
|
+
this.index++;
|
|
1508
|
+
return true;
|
|
1509
|
+
}
|
|
1510
|
+
break;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
return false;
|
|
1514
|
+
}
|
|
1515
|
+
recreateWrapper(next, node, outerDeco, innerDeco, view, pos) {
|
|
1516
|
+
if (next.dirty || node.isAtom || !next.children.length || !next.node.content.eq(node.content) || !sameOuterDeco(outerDeco, next.outerDeco) || !innerDeco.eq(next.innerDeco)) return null;
|
|
1517
|
+
let wrapper = NodeViewDesc.create(this.top, node, outerDeco, innerDeco, view, pos);
|
|
1518
|
+
if (wrapper.contentDOM) {
|
|
1519
|
+
wrapper.children = next.children;
|
|
1520
|
+
next.children = [];
|
|
1521
|
+
for (let ch of wrapper.children) ch.parent = wrapper;
|
|
1522
|
+
}
|
|
1523
|
+
next.destroy();
|
|
1524
|
+
return wrapper;
|
|
1525
|
+
}
|
|
1526
|
+
addNode(node, outerDeco, innerDeco, view, pos) {
|
|
1527
|
+
let desc = NodeViewDesc.create(this.top, node, outerDeco, innerDeco, view, pos);
|
|
1528
|
+
if (desc.contentDOM) desc.updateChildren(view, pos + 1);
|
|
1529
|
+
this.top.children.splice(this.index++, 0, desc);
|
|
1530
|
+
this.changed = true;
|
|
1531
|
+
}
|
|
1532
|
+
placeWidget(widget, view, pos) {
|
|
1533
|
+
let next = this.index < this.top.children.length ? this.top.children[this.index] : null;
|
|
1534
|
+
if (next && next.matchesWidget(widget) && (widget == next.widget || !next.widget.type.toDOM.parentNode)) this.index++;
|
|
1535
|
+
else {
|
|
1536
|
+
let desc = new WidgetViewDesc(this.top, widget, view, pos);
|
|
1537
|
+
this.top.children.splice(this.index++, 0, desc);
|
|
1538
|
+
this.changed = true;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
addTextblockHacks() {
|
|
1542
|
+
let lastChild = this.top.children[this.index - 1], parent = this.top;
|
|
1543
|
+
while (lastChild instanceof MarkViewDesc) {
|
|
1544
|
+
parent = lastChild;
|
|
1545
|
+
lastChild = parent.children[parent.children.length - 1];
|
|
1546
|
+
}
|
|
1547
|
+
if (!lastChild || !(lastChild instanceof TextViewDesc) || /\n$/.test(lastChild.node.text) || this.view.requiresGeckoHackNode && /\s$/.test(lastChild.node.text)) {
|
|
1548
|
+
if ((safari || chrome) && lastChild && lastChild.dom.contentEditable == "false") this.addHackNode("IMG", parent);
|
|
1549
|
+
this.addHackNode("BR", this.top);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
addHackNode(nodeName, parent) {
|
|
1553
|
+
if (parent == this.top && this.index < parent.children.length && parent.children[this.index].matchesHack(nodeName)) this.index++;
|
|
1554
|
+
else {
|
|
1555
|
+
let dom = document.createElement(nodeName);
|
|
1556
|
+
if (nodeName == "IMG") {
|
|
1557
|
+
dom.className = "ProseMirror-separator";
|
|
1558
|
+
dom.alt = "";
|
|
1559
|
+
}
|
|
1560
|
+
if (nodeName == "BR") dom.className = "ProseMirror-trailingBreak";
|
|
1561
|
+
let hack = new TrailingHackViewDesc(this.top, [], dom, null);
|
|
1562
|
+
if (parent != this.top) parent.children.push(hack);
|
|
1563
|
+
else parent.children.splice(this.index++, 0, hack);
|
|
1564
|
+
this.changed = true;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
isLocked(node) {
|
|
1568
|
+
return this.lock && (node == this.lock || node.nodeType == 1 && node.contains(this.lock.parentNode));
|
|
1569
|
+
}
|
|
1570
|
+
};
|
|
1571
|
+
function preMatch(frag, parentDesc) {
|
|
1572
|
+
let curDesc = parentDesc, descI = curDesc.children.length;
|
|
1573
|
+
let fI = frag.childCount, matched = /* @__PURE__ */ new Map(), matches = [];
|
|
1574
|
+
outer: while (fI > 0) {
|
|
1575
|
+
let desc;
|
|
1576
|
+
for (;;) if (descI) {
|
|
1577
|
+
let next = curDesc.children[descI - 1];
|
|
1578
|
+
if (next instanceof MarkViewDesc) {
|
|
1579
|
+
curDesc = next;
|
|
1580
|
+
descI = next.children.length;
|
|
1581
|
+
} else {
|
|
1582
|
+
desc = next;
|
|
1583
|
+
descI--;
|
|
1584
|
+
break;
|
|
1585
|
+
}
|
|
1586
|
+
} else if (curDesc == parentDesc) break outer;
|
|
1587
|
+
else {
|
|
1588
|
+
descI = curDesc.parent.children.indexOf(curDesc);
|
|
1589
|
+
curDesc = curDesc.parent;
|
|
1590
|
+
}
|
|
1591
|
+
let node = desc.node;
|
|
1592
|
+
if (!node) continue;
|
|
1593
|
+
if (node != frag.child(fI - 1)) break;
|
|
1594
|
+
--fI;
|
|
1595
|
+
matched.set(desc, fI);
|
|
1596
|
+
matches.push(desc);
|
|
1597
|
+
}
|
|
1598
|
+
return {
|
|
1599
|
+
index: fI,
|
|
1600
|
+
matched,
|
|
1601
|
+
matches: matches.reverse()
|
|
1602
|
+
};
|
|
1603
|
+
}
|
|
1604
|
+
function compareSide(a, b) {
|
|
1605
|
+
return a.type.side - b.type.side;
|
|
1606
|
+
}
|
|
1607
|
+
function iterDeco(parent, deco, onWidget, onNode) {
|
|
1608
|
+
let locals = deco.locals(parent), offset = 0;
|
|
1609
|
+
if (locals.length == 0) {
|
|
1610
|
+
for (let i = 0; i < parent.childCount; i++) {
|
|
1611
|
+
let child = parent.child(i);
|
|
1612
|
+
onNode(child, locals, deco.forChild(offset, child), i);
|
|
1613
|
+
offset += child.nodeSize;
|
|
1614
|
+
}
|
|
1615
|
+
return;
|
|
1616
|
+
}
|
|
1617
|
+
let decoIndex = 0, active = [], restNode = null;
|
|
1618
|
+
for (let parentIndex = 0;;) {
|
|
1619
|
+
let widget, widgets;
|
|
1620
|
+
while (decoIndex < locals.length && locals[decoIndex].to == offset) {
|
|
1621
|
+
let next = locals[decoIndex++];
|
|
1622
|
+
if (next.widget) if (!widget) widget = next;
|
|
1623
|
+
else (widgets || (widgets = [widget])).push(next);
|
|
1624
|
+
}
|
|
1625
|
+
if (widget) if (widgets) {
|
|
1626
|
+
widgets.sort(compareSide);
|
|
1627
|
+
for (let i = 0; i < widgets.length; i++) onWidget(widgets[i], parentIndex, !!restNode);
|
|
1628
|
+
} else onWidget(widget, parentIndex, !!restNode);
|
|
1629
|
+
let child, index;
|
|
1630
|
+
if (restNode) {
|
|
1631
|
+
index = -1;
|
|
1632
|
+
child = restNode;
|
|
1633
|
+
restNode = null;
|
|
1634
|
+
} else if (parentIndex < parent.childCount) {
|
|
1635
|
+
index = parentIndex;
|
|
1636
|
+
child = parent.child(parentIndex++);
|
|
1637
|
+
} else break;
|
|
1638
|
+
for (let i = 0; i < active.length; i++) if (active[i].to <= offset) active.splice(i--, 1);
|
|
1639
|
+
while (decoIndex < locals.length && locals[decoIndex].from <= offset && locals[decoIndex].to > offset) active.push(locals[decoIndex++]);
|
|
1640
|
+
let end = offset + child.nodeSize;
|
|
1641
|
+
if (child.isText) {
|
|
1642
|
+
let cutAt = end;
|
|
1643
|
+
if (decoIndex < locals.length && locals[decoIndex].from < cutAt) cutAt = locals[decoIndex].from;
|
|
1644
|
+
for (let i = 0; i < active.length; i++) if (active[i].to < cutAt) cutAt = active[i].to;
|
|
1645
|
+
if (cutAt < end) {
|
|
1646
|
+
restNode = child.cut(cutAt - offset);
|
|
1647
|
+
child = child.cut(0, cutAt - offset);
|
|
1648
|
+
end = cutAt;
|
|
1649
|
+
index = -1;
|
|
1650
|
+
}
|
|
1651
|
+
} else while (decoIndex < locals.length && locals[decoIndex].to < end) decoIndex++;
|
|
1652
|
+
let outerDeco = child.isInline && !child.isLeaf ? active.filter((d) => !d.inline) : active.slice();
|
|
1653
|
+
onNode(child, outerDeco, deco.forChild(offset, child), index);
|
|
1654
|
+
offset = end;
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
function iosHacks(dom) {
|
|
1658
|
+
if (dom.nodeName == "UL" || dom.nodeName == "OL") {
|
|
1659
|
+
let oldCSS = dom.style.cssText;
|
|
1660
|
+
dom.style.cssText = oldCSS + "; list-style: square !important";
|
|
1661
|
+
window.getComputedStyle(dom).listStyle;
|
|
1662
|
+
dom.style.cssText = oldCSS;
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
function findTextInFragment(frag, text, from, to) {
|
|
1666
|
+
for (let i = 0, pos = 0; i < frag.childCount && pos <= to;) {
|
|
1667
|
+
let child = frag.child(i++), childStart = pos;
|
|
1668
|
+
pos += child.nodeSize;
|
|
1669
|
+
if (!child.isText) continue;
|
|
1670
|
+
let str = child.text;
|
|
1671
|
+
while (i < frag.childCount) {
|
|
1672
|
+
let next = frag.child(i++);
|
|
1673
|
+
pos += next.nodeSize;
|
|
1674
|
+
if (!next.isText) break;
|
|
1675
|
+
str += next.text;
|
|
1676
|
+
}
|
|
1677
|
+
if (pos >= from) {
|
|
1678
|
+
if (pos >= to && str.slice(to - text.length - childStart, to - childStart) == text) return to - text.length;
|
|
1679
|
+
let found = childStart < to ? str.lastIndexOf(text, to - childStart - 1) : -1;
|
|
1680
|
+
if (found >= 0 && found + text.length + childStart >= from) return childStart + found;
|
|
1681
|
+
if (from == to && str.length >= to + text.length - childStart && str.slice(to - childStart, to - childStart + text.length) == text) return to;
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
return -1;
|
|
1685
|
+
}
|
|
1686
|
+
function replaceNodes(nodes, from, to, view, replacement) {
|
|
1687
|
+
let result = [];
|
|
1688
|
+
for (let i = 0, off = 0; i < nodes.length; i++) {
|
|
1689
|
+
let child = nodes[i], start = off, end = off += child.size;
|
|
1690
|
+
if (start >= to || end <= from) result.push(child);
|
|
1691
|
+
else {
|
|
1692
|
+
if (start < from) result.push(child.slice(0, from - start, view));
|
|
1693
|
+
if (replacement) {
|
|
1694
|
+
result.push(replacement);
|
|
1695
|
+
replacement = void 0;
|
|
1696
|
+
}
|
|
1697
|
+
if (end > to) result.push(child.slice(to - start, child.size, view));
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
return result;
|
|
1701
|
+
}
|
|
1702
|
+
function selectionFromDOM(view, origin = null) {
|
|
1703
|
+
let domSel = view.domSelectionRange(), doc = view.state.doc;
|
|
1704
|
+
if (!domSel.focusNode) return null;
|
|
1705
|
+
let nearestDesc = view.docView.nearestDesc(domSel.focusNode), inWidget = nearestDesc && nearestDesc.size == 0;
|
|
1706
|
+
let head = view.docView.posFromDOM(domSel.focusNode, domSel.focusOffset, 1);
|
|
1707
|
+
if (head < 0) return null;
|
|
1708
|
+
let $head = doc.resolve(head), anchor, selection;
|
|
1709
|
+
if (selectionCollapsed(domSel)) {
|
|
1710
|
+
anchor = head;
|
|
1711
|
+
while (nearestDesc && !nearestDesc.node) nearestDesc = nearestDesc.parent;
|
|
1712
|
+
let nearestDescNode = nearestDesc.node;
|
|
1713
|
+
if (nearestDesc && nearestDescNode.isAtom && require_dist.NodeSelection.isSelectable(nearestDescNode) && nearestDesc.parent && !(nearestDescNode.isInline && isOnEdge(domSel.focusNode, domSel.focusOffset, nearestDesc.dom))) {
|
|
1714
|
+
let pos = nearestDesc.posBefore;
|
|
1715
|
+
selection = new require_dist.NodeSelection(head == pos ? $head : doc.resolve(pos));
|
|
1716
|
+
}
|
|
1717
|
+
} else {
|
|
1718
|
+
if (domSel instanceof view.dom.ownerDocument.defaultView.Selection && domSel.rangeCount > 1) {
|
|
1719
|
+
let min = head, max = head;
|
|
1720
|
+
for (let i = 0; i < domSel.rangeCount; i++) {
|
|
1721
|
+
let range = domSel.getRangeAt(i);
|
|
1722
|
+
min = Math.min(min, view.docView.posFromDOM(range.startContainer, range.startOffset, 1));
|
|
1723
|
+
max = Math.max(max, view.docView.posFromDOM(range.endContainer, range.endOffset, -1));
|
|
1724
|
+
}
|
|
1725
|
+
if (min < 0) return null;
|
|
1726
|
+
[anchor, head] = max == view.state.selection.anchor ? [max, min] : [min, max];
|
|
1727
|
+
$head = doc.resolve(head);
|
|
1728
|
+
} else anchor = view.docView.posFromDOM(domSel.anchorNode, domSel.anchorOffset, 1);
|
|
1729
|
+
if (anchor < 0) return null;
|
|
1730
|
+
}
|
|
1731
|
+
let $anchor = doc.resolve(anchor);
|
|
1732
|
+
if (!selection) {
|
|
1733
|
+
let bias = origin == "pointer" || view.state.selection.head < $head.pos && !inWidget ? 1 : -1;
|
|
1734
|
+
selection = selectionBetween(view, $anchor, $head, bias);
|
|
1735
|
+
}
|
|
1736
|
+
return selection;
|
|
1737
|
+
}
|
|
1738
|
+
function editorOwnsSelection(view) {
|
|
1739
|
+
return view.editable ? view.hasFocus() : hasSelection(view) && document.activeElement && document.activeElement.contains(view.dom);
|
|
1740
|
+
}
|
|
1741
|
+
function selectionToDOM(view, force = false) {
|
|
1742
|
+
let sel = view.state.selection;
|
|
1743
|
+
syncNodeSelection(view, sel);
|
|
1744
|
+
if (!editorOwnsSelection(view)) return;
|
|
1745
|
+
let mouseDown = view.input.mouseDown;
|
|
1746
|
+
if (!force && chrome && mouseDown) {
|
|
1747
|
+
let domSel = view.domSelectionRange(), curSel = view.domObserver.currentSelection;
|
|
1748
|
+
if (domSel.anchorNode && curSel.anchorNode && isEquivalentPosition(domSel.anchorNode, domSel.anchorOffset, curSel.anchorNode, curSel.anchorOffset) && mouseDown.delaySelUpdate()) {
|
|
1749
|
+
view.domObserver.setCurSelection();
|
|
1750
|
+
return;
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
view.domObserver.disconnectSelection();
|
|
1754
|
+
if (view.cursorWrapper) selectCursorWrapper(view);
|
|
1755
|
+
else {
|
|
1756
|
+
let { anchor, head } = sel, resetEditableFrom, resetEditableTo;
|
|
1757
|
+
if (brokenSelectBetweenUneditable && !(sel instanceof require_dist.TextSelection)) {
|
|
1758
|
+
if (!sel.$from.parent.inlineContent) resetEditableFrom = temporarilyEditableNear(view, sel.from);
|
|
1759
|
+
if (!sel.empty && !sel.$from.parent.inlineContent) resetEditableTo = temporarilyEditableNear(view, sel.to);
|
|
1760
|
+
}
|
|
1761
|
+
view.docView.setSelection(anchor, head, view, force);
|
|
1762
|
+
if (brokenSelectBetweenUneditable) {
|
|
1763
|
+
if (resetEditableFrom) resetEditable(resetEditableFrom);
|
|
1764
|
+
if (resetEditableTo) resetEditable(resetEditableTo);
|
|
1765
|
+
}
|
|
1766
|
+
if (sel.visible) view.dom.classList.remove("ProseMirror-hideselection");
|
|
1767
|
+
else {
|
|
1768
|
+
view.dom.classList.add("ProseMirror-hideselection");
|
|
1769
|
+
if ("onselectionchange" in document) removeClassOnSelectionChange(view);
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
view.domObserver.setCurSelection();
|
|
1773
|
+
view.domObserver.connectSelection();
|
|
1774
|
+
}
|
|
1775
|
+
var brokenSelectBetweenUneditable = safari || chrome && chrome_version < 63;
|
|
1776
|
+
function temporarilyEditableNear(view, pos) {
|
|
1777
|
+
let { node, offset } = view.docView.domFromPos(pos, 0);
|
|
1778
|
+
let after = offset < node.childNodes.length ? node.childNodes[offset] : null;
|
|
1779
|
+
let before = offset ? node.childNodes[offset - 1] : null;
|
|
1780
|
+
if (safari && after && after.contentEditable == "false") return setEditable(after);
|
|
1781
|
+
if ((!after || after.contentEditable == "false") && (!before || before.contentEditable == "false")) {
|
|
1782
|
+
if (after) return setEditable(after);
|
|
1783
|
+
else if (before) return setEditable(before);
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
function setEditable(element) {
|
|
1787
|
+
element.contentEditable = "true";
|
|
1788
|
+
if (safari && element.draggable) {
|
|
1789
|
+
element.draggable = false;
|
|
1790
|
+
element.wasDraggable = true;
|
|
1791
|
+
}
|
|
1792
|
+
return element;
|
|
1793
|
+
}
|
|
1794
|
+
function resetEditable(element) {
|
|
1795
|
+
element.contentEditable = "false";
|
|
1796
|
+
if (element.wasDraggable) {
|
|
1797
|
+
element.draggable = true;
|
|
1798
|
+
element.wasDraggable = null;
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
function removeClassOnSelectionChange(view) {
|
|
1802
|
+
let doc = view.dom.ownerDocument;
|
|
1803
|
+
doc.removeEventListener("selectionchange", view.input.hideSelectionGuard);
|
|
1804
|
+
let domSel = view.domSelectionRange();
|
|
1805
|
+
let node = domSel.anchorNode, offset = domSel.anchorOffset;
|
|
1806
|
+
doc.addEventListener("selectionchange", view.input.hideSelectionGuard = () => {
|
|
1807
|
+
if (domSel.anchorNode != node || domSel.anchorOffset != offset) {
|
|
1808
|
+
doc.removeEventListener("selectionchange", view.input.hideSelectionGuard);
|
|
1809
|
+
setTimeout(() => {
|
|
1810
|
+
if (!editorOwnsSelection(view) || view.state.selection.visible) view.dom.classList.remove("ProseMirror-hideselection");
|
|
1811
|
+
}, 20);
|
|
1812
|
+
}
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
function selectCursorWrapper(view) {
|
|
1816
|
+
let domSel = view.domSelection();
|
|
1817
|
+
if (!domSel) return;
|
|
1818
|
+
let node = view.cursorWrapper.dom, img = node.nodeName == "IMG";
|
|
1819
|
+
if (img) domSel.collapse(node.parentNode, domIndex(node) + 1);
|
|
1820
|
+
else domSel.collapse(node, 0);
|
|
1821
|
+
if (!img && !view.state.selection.visible && ie && ie_version <= 11) {
|
|
1822
|
+
node.disabled = true;
|
|
1823
|
+
node.disabled = false;
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
function syncNodeSelection(view, sel) {
|
|
1827
|
+
if (sel instanceof require_dist.NodeSelection) {
|
|
1828
|
+
let desc = view.docView.descAt(sel.from);
|
|
1829
|
+
if (desc != view.lastSelectedViewDesc) {
|
|
1830
|
+
clearNodeSelection(view);
|
|
1831
|
+
if (desc) desc.selectNode();
|
|
1832
|
+
view.lastSelectedViewDesc = desc;
|
|
1833
|
+
}
|
|
1834
|
+
} else clearNodeSelection(view);
|
|
1835
|
+
}
|
|
1836
|
+
function clearNodeSelection(view) {
|
|
1837
|
+
if (view.lastSelectedViewDesc) {
|
|
1838
|
+
if (view.lastSelectedViewDesc.parent) view.lastSelectedViewDesc.deselectNode();
|
|
1839
|
+
view.lastSelectedViewDesc = void 0;
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
function selectionBetween(view, $anchor, $head, bias) {
|
|
1843
|
+
return view.someProp("createSelectionBetween", (f) => f(view, $anchor, $head)) || require_dist.TextSelection.between($anchor, $head, bias);
|
|
1844
|
+
}
|
|
1845
|
+
function hasFocusAndSelection(view) {
|
|
1846
|
+
if (view.editable && !view.hasFocus()) return false;
|
|
1847
|
+
return hasSelection(view);
|
|
1848
|
+
}
|
|
1849
|
+
function hasSelection(view) {
|
|
1850
|
+
let sel = view.domSelectionRange();
|
|
1851
|
+
if (!sel.anchorNode) return false;
|
|
1852
|
+
try {
|
|
1853
|
+
return view.dom.contains(sel.anchorNode.nodeType == 3 ? sel.anchorNode.parentNode : sel.anchorNode) && (view.editable || view.dom.contains(sel.focusNode.nodeType == 3 ? sel.focusNode.parentNode : sel.focusNode));
|
|
1854
|
+
} catch (_) {
|
|
1855
|
+
return false;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
function anchorInRightPlace(view) {
|
|
1859
|
+
let anchorDOM = view.docView.domFromPos(view.state.selection.anchor, 0);
|
|
1860
|
+
let domSel = view.domSelectionRange();
|
|
1861
|
+
return isEquivalentPosition(anchorDOM.node, anchorDOM.offset, domSel.anchorNode, domSel.anchorOffset);
|
|
1862
|
+
}
|
|
1863
|
+
function moveSelectionBlock(state, dir) {
|
|
1864
|
+
let { $anchor, $head } = state.selection;
|
|
1865
|
+
let $side = dir > 0 ? $anchor.max($head) : $anchor.min($head);
|
|
1866
|
+
let $start = !$side.parent.inlineContent ? $side : $side.depth ? state.doc.resolve(dir > 0 ? $side.after() : $side.before()) : null;
|
|
1867
|
+
return $start && require_dist.Selection.findFrom($start, dir);
|
|
1868
|
+
}
|
|
1869
|
+
function apply(view, sel) {
|
|
1870
|
+
view.dispatch(view.state.tr.setSelection(sel).scrollIntoView());
|
|
1871
|
+
return true;
|
|
1872
|
+
}
|
|
1873
|
+
function selectHorizontally(view, dir, mods) {
|
|
1874
|
+
let sel = view.state.selection;
|
|
1875
|
+
if (sel instanceof require_dist.TextSelection) {
|
|
1876
|
+
if (mods.indexOf("s") > -1) {
|
|
1877
|
+
let { $head } = sel, node = $head.textOffset ? null : dir < 0 ? $head.nodeBefore : $head.nodeAfter;
|
|
1878
|
+
if (!node || node.isText || !node.isLeaf) return false;
|
|
1879
|
+
let $newHead = view.state.doc.resolve($head.pos + node.nodeSize * (dir < 0 ? -1 : 1));
|
|
1880
|
+
return apply(view, new require_dist.TextSelection(sel.$anchor, $newHead));
|
|
1881
|
+
} else if (!sel.empty) return false;
|
|
1882
|
+
else if (view.endOfTextblock(dir > 0 ? "forward" : "backward")) {
|
|
1883
|
+
let next = moveSelectionBlock(view.state, dir);
|
|
1884
|
+
if (next && next instanceof require_dist.NodeSelection) return apply(view, next);
|
|
1885
|
+
return false;
|
|
1886
|
+
} else if (!(mac && mods.indexOf("m") > -1)) {
|
|
1887
|
+
let $head = sel.$head, node = $head.textOffset ? null : dir < 0 ? $head.nodeBefore : $head.nodeAfter, desc;
|
|
1888
|
+
if (!node || node.isText) return false;
|
|
1889
|
+
let nodePos = dir < 0 ? $head.pos - node.nodeSize : $head.pos;
|
|
1890
|
+
if (!(node.isAtom || (desc = view.docView.descAt(nodePos)) && !desc.contentDOM)) return false;
|
|
1891
|
+
if (require_dist.NodeSelection.isSelectable(node)) return apply(view, new require_dist.NodeSelection(dir < 0 ? view.state.doc.resolve($head.pos - node.nodeSize) : $head));
|
|
1892
|
+
else if (webkit) return apply(view, new require_dist.TextSelection(view.state.doc.resolve(dir < 0 ? nodePos : nodePos + node.nodeSize)));
|
|
1893
|
+
else return false;
|
|
1894
|
+
}
|
|
1895
|
+
} else if (sel instanceof require_dist.NodeSelection && sel.node.isInline) return apply(view, new require_dist.TextSelection(dir > 0 ? sel.$to : sel.$from));
|
|
1896
|
+
else {
|
|
1897
|
+
let next = moveSelectionBlock(view.state, dir);
|
|
1898
|
+
if (next) return apply(view, next);
|
|
1899
|
+
return false;
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
function nodeLen(node) {
|
|
1903
|
+
return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length;
|
|
1904
|
+
}
|
|
1905
|
+
function isIgnorable(dom, dir) {
|
|
1906
|
+
let desc = dom.pmViewDesc;
|
|
1907
|
+
return desc && desc.size == 0 && (dir < 0 || dom.nextSibling || dom.nodeName != "BR");
|
|
1908
|
+
}
|
|
1909
|
+
function skipIgnoredNodes(view, dir) {
|
|
1910
|
+
return dir < 0 ? skipIgnoredNodesBefore(view) : skipIgnoredNodesAfter(view);
|
|
1911
|
+
}
|
|
1912
|
+
function skipIgnoredNodesBefore(view) {
|
|
1913
|
+
let sel = view.domSelectionRange();
|
|
1914
|
+
let node = sel.focusNode, offset = sel.focusOffset;
|
|
1915
|
+
if (!node) return;
|
|
1916
|
+
let moveNode, moveOffset, force = false;
|
|
1917
|
+
if (gecko && node.nodeType == 1 && offset < nodeLen(node) && isIgnorable(node.childNodes[offset], -1)) force = true;
|
|
1918
|
+
for (;;) if (offset > 0) if (node.nodeType != 1) break;
|
|
1919
|
+
else {
|
|
1920
|
+
let before = node.childNodes[offset - 1];
|
|
1921
|
+
if (isIgnorable(before, -1)) {
|
|
1922
|
+
moveNode = node;
|
|
1923
|
+
moveOffset = --offset;
|
|
1924
|
+
} else if (before.nodeType == 3) {
|
|
1925
|
+
node = before;
|
|
1926
|
+
offset = node.nodeValue.length;
|
|
1927
|
+
} else break;
|
|
1928
|
+
}
|
|
1929
|
+
else if (isBlockNode(node)) break;
|
|
1930
|
+
else {
|
|
1931
|
+
let prev = node.previousSibling;
|
|
1932
|
+
while (prev && isIgnorable(prev, -1)) {
|
|
1933
|
+
moveNode = node.parentNode;
|
|
1934
|
+
moveOffset = domIndex(prev);
|
|
1935
|
+
prev = prev.previousSibling;
|
|
1936
|
+
}
|
|
1937
|
+
if (!prev) {
|
|
1938
|
+
node = node.parentNode;
|
|
1939
|
+
if (node == view.dom) break;
|
|
1940
|
+
offset = 0;
|
|
1941
|
+
} else {
|
|
1942
|
+
node = prev;
|
|
1943
|
+
offset = nodeLen(node);
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
if (force) setSelFocus(view, node, offset);
|
|
1947
|
+
else if (moveNode) setSelFocus(view, moveNode, moveOffset);
|
|
1948
|
+
}
|
|
1949
|
+
function skipIgnoredNodesAfter(view) {
|
|
1950
|
+
let sel = view.domSelectionRange();
|
|
1951
|
+
let node = sel.focusNode, offset = sel.focusOffset;
|
|
1952
|
+
if (!node) return;
|
|
1953
|
+
let len = nodeLen(node);
|
|
1954
|
+
let moveNode, moveOffset;
|
|
1955
|
+
for (;;) if (offset < len) {
|
|
1956
|
+
if (node.nodeType != 1) break;
|
|
1957
|
+
let after = node.childNodes[offset];
|
|
1958
|
+
if (isIgnorable(after, 1)) {
|
|
1959
|
+
moveNode = node;
|
|
1960
|
+
moveOffset = ++offset;
|
|
1961
|
+
} else break;
|
|
1962
|
+
} else if (isBlockNode(node)) break;
|
|
1963
|
+
else {
|
|
1964
|
+
let next = node.nextSibling;
|
|
1965
|
+
while (next && isIgnorable(next, 1)) {
|
|
1966
|
+
moveNode = next.parentNode;
|
|
1967
|
+
moveOffset = domIndex(next) + 1;
|
|
1968
|
+
next = next.nextSibling;
|
|
1969
|
+
}
|
|
1970
|
+
if (!next) {
|
|
1971
|
+
node = node.parentNode;
|
|
1972
|
+
if (node == view.dom) break;
|
|
1973
|
+
offset = len = 0;
|
|
1974
|
+
} else {
|
|
1975
|
+
node = next;
|
|
1976
|
+
offset = 0;
|
|
1977
|
+
len = nodeLen(node);
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
if (moveNode) setSelFocus(view, moveNode, moveOffset);
|
|
1981
|
+
}
|
|
1982
|
+
function isBlockNode(dom) {
|
|
1983
|
+
let desc = dom.pmViewDesc;
|
|
1984
|
+
return desc && desc.node && desc.node.isBlock;
|
|
1985
|
+
}
|
|
1986
|
+
function textNodeAfter(node, offset) {
|
|
1987
|
+
while (node && offset == node.childNodes.length && !hasBlockDesc(node)) {
|
|
1988
|
+
offset = domIndex(node) + 1;
|
|
1989
|
+
node = node.parentNode;
|
|
1990
|
+
}
|
|
1991
|
+
while (node && offset < node.childNodes.length) {
|
|
1992
|
+
let next = node.childNodes[offset];
|
|
1993
|
+
if (next.nodeType == 3) return next;
|
|
1994
|
+
if (next.nodeType == 1 && next.contentEditable == "false") break;
|
|
1995
|
+
node = next;
|
|
1996
|
+
offset = 0;
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
function textNodeBefore(node, offset) {
|
|
2000
|
+
while (node && !offset && !hasBlockDesc(node)) {
|
|
2001
|
+
offset = domIndex(node);
|
|
2002
|
+
node = node.parentNode;
|
|
2003
|
+
}
|
|
2004
|
+
while (node && offset) {
|
|
2005
|
+
let next = node.childNodes[offset - 1];
|
|
2006
|
+
if (next.nodeType == 3) return next;
|
|
2007
|
+
if (next.nodeType == 1 && next.contentEditable == "false") break;
|
|
2008
|
+
node = next;
|
|
2009
|
+
offset = node.childNodes.length;
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
function setSelFocus(view, node, offset) {
|
|
2013
|
+
if (node.nodeType != 3) {
|
|
2014
|
+
let before, after;
|
|
2015
|
+
if (after = textNodeAfter(node, offset)) {
|
|
2016
|
+
node = after;
|
|
2017
|
+
offset = 0;
|
|
2018
|
+
} else if (before = textNodeBefore(node, offset)) {
|
|
2019
|
+
node = before;
|
|
2020
|
+
offset = before.nodeValue.length;
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
let sel = view.domSelection();
|
|
2024
|
+
if (!sel) return;
|
|
2025
|
+
if (selectionCollapsed(sel)) {
|
|
2026
|
+
let range = document.createRange();
|
|
2027
|
+
range.setEnd(node, offset);
|
|
2028
|
+
range.setStart(node, offset);
|
|
2029
|
+
sel.removeAllRanges();
|
|
2030
|
+
sel.addRange(range);
|
|
2031
|
+
} else if (sel.extend) sel.extend(node, offset);
|
|
2032
|
+
view.domObserver.setCurSelection();
|
|
2033
|
+
let { state } = view;
|
|
2034
|
+
setTimeout(() => {
|
|
2035
|
+
if (view.state == state) selectionToDOM(view);
|
|
2036
|
+
}, 50);
|
|
2037
|
+
}
|
|
2038
|
+
function findDirection(view, pos) {
|
|
2039
|
+
let $pos = view.state.doc.resolve(pos);
|
|
2040
|
+
if (!(chrome || windows) && $pos.parent.inlineContent) {
|
|
2041
|
+
let coords = view.coordsAtPos(pos);
|
|
2042
|
+
if (pos > $pos.start()) {
|
|
2043
|
+
let before = view.coordsAtPos(pos - 1);
|
|
2044
|
+
let mid = (before.top + before.bottom) / 2;
|
|
2045
|
+
if (mid > coords.top && mid < coords.bottom && Math.abs(before.left - coords.left) > 1) return before.left < coords.left ? "ltr" : "rtl";
|
|
2046
|
+
}
|
|
2047
|
+
if (pos < $pos.end()) {
|
|
2048
|
+
let after = view.coordsAtPos(pos + 1);
|
|
2049
|
+
let mid = (after.top + after.bottom) / 2;
|
|
2050
|
+
if (mid > coords.top && mid < coords.bottom && Math.abs(after.left - coords.left) > 1) return after.left > coords.left ? "ltr" : "rtl";
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
return getComputedStyle(view.dom).direction == "rtl" ? "rtl" : "ltr";
|
|
2054
|
+
}
|
|
2055
|
+
function selectVertically(view, dir, mods) {
|
|
2056
|
+
let sel = view.state.selection;
|
|
2057
|
+
if (sel instanceof require_dist.TextSelection && !sel.empty || mods.indexOf("s") > -1) return false;
|
|
2058
|
+
if (mac && mods.indexOf("m") > -1) return false;
|
|
2059
|
+
let { $from, $to } = sel;
|
|
2060
|
+
if (!$from.parent.inlineContent || view.endOfTextblock(dir < 0 ? "up" : "down")) {
|
|
2061
|
+
let next = moveSelectionBlock(view.state, dir);
|
|
2062
|
+
if (next && next instanceof require_dist.NodeSelection) return apply(view, next);
|
|
2063
|
+
}
|
|
2064
|
+
if (!$from.parent.inlineContent) {
|
|
2065
|
+
let side = dir < 0 ? $from : $to;
|
|
2066
|
+
let beyond = sel instanceof require_dist.AllSelection ? require_dist.Selection.near(side, dir) : require_dist.Selection.findFrom(side, dir);
|
|
2067
|
+
return beyond ? apply(view, beyond) : false;
|
|
2068
|
+
}
|
|
2069
|
+
return false;
|
|
2070
|
+
}
|
|
2071
|
+
function stopNativeHorizontalDelete(view, dir) {
|
|
2072
|
+
if (!(view.state.selection instanceof require_dist.TextSelection)) return true;
|
|
2073
|
+
let { $head, $anchor, empty } = view.state.selection;
|
|
2074
|
+
if (!$head.sameParent($anchor)) return true;
|
|
2075
|
+
if (!empty) return false;
|
|
2076
|
+
if (view.endOfTextblock(dir > 0 ? "forward" : "backward")) return true;
|
|
2077
|
+
let nextNode = !$head.textOffset && (dir < 0 ? $head.nodeBefore : $head.nodeAfter);
|
|
2078
|
+
if (nextNode && !nextNode.isText) {
|
|
2079
|
+
let tr = view.state.tr;
|
|
2080
|
+
if (dir < 0) tr.delete($head.pos - nextNode.nodeSize, $head.pos);
|
|
2081
|
+
else tr.delete($head.pos, $head.pos + nextNode.nodeSize);
|
|
2082
|
+
view.dispatch(tr);
|
|
2083
|
+
return true;
|
|
2084
|
+
}
|
|
2085
|
+
return false;
|
|
2086
|
+
}
|
|
2087
|
+
function switchEditable(view, node, state) {
|
|
2088
|
+
view.domObserver.stop();
|
|
2089
|
+
node.contentEditable = state;
|
|
2090
|
+
view.domObserver.start();
|
|
2091
|
+
}
|
|
2092
|
+
function safariDownArrowBug(view) {
|
|
2093
|
+
if (!safari || view.state.selection.$head.parentOffset > 0) return false;
|
|
2094
|
+
let { focusNode, focusOffset } = view.domSelectionRange();
|
|
2095
|
+
if (focusNode && focusNode.nodeType == 1 && focusOffset == 0 && focusNode.firstChild && focusNode.firstChild.contentEditable == "false") {
|
|
2096
|
+
let child = focusNode.firstChild;
|
|
2097
|
+
switchEditable(view, child, "true");
|
|
2098
|
+
setTimeout(() => switchEditable(view, child, "false"), 20);
|
|
2099
|
+
}
|
|
2100
|
+
return false;
|
|
2101
|
+
}
|
|
2102
|
+
function getMods(event) {
|
|
2103
|
+
let result = "";
|
|
2104
|
+
if (event.ctrlKey) result += "c";
|
|
2105
|
+
if (event.metaKey) result += "m";
|
|
2106
|
+
if (event.altKey) result += "a";
|
|
2107
|
+
if (event.shiftKey) result += "s";
|
|
2108
|
+
return result;
|
|
2109
|
+
}
|
|
2110
|
+
function captureKeyDown(view, event) {
|
|
2111
|
+
let code = event.keyCode, mods = getMods(event);
|
|
2112
|
+
if (code == 8 || mac && code == 72 && mods == "c") return stopNativeHorizontalDelete(view, -1) || skipIgnoredNodes(view, -1);
|
|
2113
|
+
else if (code == 46 && !event.shiftKey || mac && code == 68 && mods == "c") return stopNativeHorizontalDelete(view, 1) || skipIgnoredNodes(view, 1);
|
|
2114
|
+
else if (code == 13 || code == 27) return true;
|
|
2115
|
+
else if (code == 37 || mac && code == 66 && mods == "c") {
|
|
2116
|
+
let dir = code == 37 ? findDirection(view, view.state.selection.from) == "ltr" ? -1 : 1 : -1;
|
|
2117
|
+
return selectHorizontally(view, dir, mods) || skipIgnoredNodes(view, dir);
|
|
2118
|
+
} else if (code == 39 || mac && code == 70 && mods == "c") {
|
|
2119
|
+
let dir = code == 39 ? findDirection(view, view.state.selection.from) == "ltr" ? 1 : -1 : 1;
|
|
2120
|
+
return selectHorizontally(view, dir, mods) || skipIgnoredNodes(view, dir);
|
|
2121
|
+
} else if (code == 38 || mac && code == 80 && mods == "c") return selectVertically(view, -1, mods) || skipIgnoredNodes(view, -1);
|
|
2122
|
+
else if (code == 40 || mac && code == 78 && mods == "c") return safariDownArrowBug(view) || selectVertically(view, 1, mods) || skipIgnoredNodes(view, 1);
|
|
2123
|
+
else if (mods == (mac ? "m" : "c") && (code == 66 || code == 73 || code == 89 || code == 90)) return true;
|
|
2124
|
+
return false;
|
|
2125
|
+
}
|
|
2126
|
+
function serializeForClipboard(view, slice) {
|
|
2127
|
+
view.someProp("transformCopied", (f) => {
|
|
2128
|
+
slice = f(slice, view);
|
|
2129
|
+
});
|
|
2130
|
+
let context = [], { content, openStart, openEnd } = slice;
|
|
2131
|
+
while (openStart > 1 && openEnd > 1 && content.childCount == 1 && content.firstChild.childCount == 1) {
|
|
2132
|
+
openStart--;
|
|
2133
|
+
openEnd--;
|
|
2134
|
+
let node = content.firstChild;
|
|
2135
|
+
context.push(node.type.name, node.attrs != node.type.defaultAttrs ? node.attrs : null);
|
|
2136
|
+
content = node.content;
|
|
2137
|
+
}
|
|
2138
|
+
let serializer = view.someProp("clipboardSerializer") || require_dist.DOMSerializer.fromSchema(view.state.schema);
|
|
2139
|
+
let doc = detachedDoc(), wrap = doc.createElement("div");
|
|
2140
|
+
wrap.appendChild(serializer.serializeFragment(content, { document: doc }));
|
|
2141
|
+
let firstChild = wrap.firstChild, needsWrap, wrappers = 0;
|
|
2142
|
+
while (firstChild && firstChild.nodeType == 1 && (needsWrap = wrapMap[firstChild.nodeName.toLowerCase()])) {
|
|
2143
|
+
for (let i = needsWrap.length - 1; i >= 0; i--) {
|
|
2144
|
+
let wrapper = doc.createElement(needsWrap[i]);
|
|
2145
|
+
while (wrap.firstChild) wrapper.appendChild(wrap.firstChild);
|
|
2146
|
+
wrap.appendChild(wrapper);
|
|
2147
|
+
wrappers++;
|
|
2148
|
+
}
|
|
2149
|
+
firstChild = wrap.firstChild;
|
|
2150
|
+
}
|
|
2151
|
+
if (firstChild && firstChild.nodeType == 1) firstChild.setAttribute("data-pm-slice", `${openStart} ${openEnd}${wrappers ? ` -${wrappers}` : ""} ${JSON.stringify(context)}`);
|
|
2152
|
+
return {
|
|
2153
|
+
dom: wrap,
|
|
2154
|
+
text: view.someProp("clipboardTextSerializer", (f) => f(slice, view)) || slice.content.textBetween(0, slice.content.size, "\n\n"),
|
|
2155
|
+
slice
|
|
2156
|
+
};
|
|
2157
|
+
}
|
|
2158
|
+
function parseFromClipboard(view, text, html, plainText, $context) {
|
|
2159
|
+
let inCode = $context.parent.type.spec.code;
|
|
2160
|
+
let dom, slice;
|
|
2161
|
+
if (!html && !text) return null;
|
|
2162
|
+
let asText = !!text && (plainText || inCode || !html);
|
|
2163
|
+
if (asText) {
|
|
2164
|
+
view.someProp("transformPastedText", (f) => {
|
|
2165
|
+
text = f(text, inCode || plainText, view);
|
|
2166
|
+
});
|
|
2167
|
+
if (inCode) {
|
|
2168
|
+
slice = new require_dist.Slice(require_dist.Fragment.from(view.state.schema.text(text.replace(/\r\n?/g, "\n"))), 0, 0);
|
|
2169
|
+
view.someProp("transformPasted", (f) => {
|
|
2170
|
+
slice = f(slice, view, true);
|
|
2171
|
+
});
|
|
2172
|
+
return slice;
|
|
2173
|
+
}
|
|
2174
|
+
let parsed = view.someProp("clipboardTextParser", (f) => f(text, $context, plainText, view));
|
|
2175
|
+
if (parsed) slice = parsed;
|
|
2176
|
+
else {
|
|
2177
|
+
let marks = $context.marks();
|
|
2178
|
+
let { schema } = view.state, serializer = require_dist.DOMSerializer.fromSchema(schema);
|
|
2179
|
+
dom = document.createElement("div");
|
|
2180
|
+
text.split(/(?:\r\n?|\n)+/).forEach((block) => {
|
|
2181
|
+
let p = dom.appendChild(document.createElement("p"));
|
|
2182
|
+
if (block) p.appendChild(serializer.serializeNode(schema.text(block, marks)));
|
|
2183
|
+
});
|
|
2184
|
+
}
|
|
2185
|
+
} else {
|
|
2186
|
+
view.someProp("transformPastedHTML", (f) => {
|
|
2187
|
+
html = f(html, view);
|
|
2188
|
+
});
|
|
2189
|
+
dom = readHTML(html);
|
|
2190
|
+
if (webkit) restoreReplacedSpaces(dom);
|
|
2191
|
+
}
|
|
2192
|
+
let contextNode = dom && dom.querySelector("[data-pm-slice]");
|
|
2193
|
+
let sliceData = contextNode && /^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(contextNode.getAttribute("data-pm-slice") || "");
|
|
2194
|
+
if (sliceData && sliceData[3]) for (let i = +sliceData[3]; i > 0; i--) {
|
|
2195
|
+
let child = dom.firstChild;
|
|
2196
|
+
while (child && child.nodeType != 1) child = child.nextSibling;
|
|
2197
|
+
if (!child) break;
|
|
2198
|
+
dom = child;
|
|
2199
|
+
}
|
|
2200
|
+
if (!slice) slice = (view.someProp("clipboardParser") || view.someProp("domParser") || require_dist.DOMParser.fromSchema(view.state.schema)).parseSlice(dom, {
|
|
2201
|
+
preserveWhitespace: !!(asText || sliceData),
|
|
2202
|
+
context: $context,
|
|
2203
|
+
ruleFromNode(dom) {
|
|
2204
|
+
if (dom.nodeName == "BR" && !dom.nextSibling && dom.parentNode && !inlineParents.test(dom.parentNode.nodeName)) return { ignore: true };
|
|
2205
|
+
return null;
|
|
2206
|
+
}
|
|
2207
|
+
});
|
|
2208
|
+
if (sliceData) slice = addContext(closeSlice(slice, +sliceData[1], +sliceData[2]), sliceData[4]);
|
|
2209
|
+
else {
|
|
2210
|
+
slice = require_dist.Slice.maxOpen(normalizeSiblings(slice.content, $context), true);
|
|
2211
|
+
if (slice.openStart || slice.openEnd) {
|
|
2212
|
+
let openStart = 0, openEnd = 0;
|
|
2213
|
+
for (let node = slice.content.firstChild; openStart < slice.openStart && !node.type.spec.isolating; openStart++, node = node.firstChild);
|
|
2214
|
+
for (let node = slice.content.lastChild; openEnd < slice.openEnd && !node.type.spec.isolating; openEnd++, node = node.lastChild);
|
|
2215
|
+
slice = closeSlice(slice, openStart, openEnd);
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
view.someProp("transformPasted", (f) => {
|
|
2219
|
+
slice = f(slice, view, asText);
|
|
2220
|
+
});
|
|
2221
|
+
return slice;
|
|
2222
|
+
}
|
|
2223
|
+
var inlineParents = /^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;
|
|
2224
|
+
function normalizeSiblings(fragment, $context) {
|
|
2225
|
+
if (fragment.childCount < 2) return fragment;
|
|
2226
|
+
for (let d = $context.depth; d >= 0; d--) {
|
|
2227
|
+
let match = $context.node(d).contentMatchAt($context.index(d));
|
|
2228
|
+
let lastWrap, result = [];
|
|
2229
|
+
fragment.forEach((node) => {
|
|
2230
|
+
if (!result) return;
|
|
2231
|
+
let wrap = match.findWrapping(node.type), inLast;
|
|
2232
|
+
if (!wrap) return result = null;
|
|
2233
|
+
if (inLast = result.length && lastWrap.length && addToSibling(wrap, lastWrap, node, result[result.length - 1], 0)) result[result.length - 1] = inLast;
|
|
2234
|
+
else {
|
|
2235
|
+
if (result.length) result[result.length - 1] = closeRight(result[result.length - 1], lastWrap.length);
|
|
2236
|
+
let wrapped = withWrappers(node, wrap);
|
|
2237
|
+
result.push(wrapped);
|
|
2238
|
+
match = match.matchType(wrapped.type);
|
|
2239
|
+
lastWrap = wrap;
|
|
2240
|
+
}
|
|
2241
|
+
});
|
|
2242
|
+
if (result) return require_dist.Fragment.from(result);
|
|
2243
|
+
}
|
|
2244
|
+
return fragment;
|
|
2245
|
+
}
|
|
2246
|
+
function withWrappers(node, wrap, from = 0) {
|
|
2247
|
+
for (let i = wrap.length - 1; i >= from; i--) node = wrap[i].create(null, require_dist.Fragment.from(node));
|
|
2248
|
+
return node;
|
|
2249
|
+
}
|
|
2250
|
+
function addToSibling(wrap, lastWrap, node, sibling, depth) {
|
|
2251
|
+
if (depth < wrap.length && depth < lastWrap.length && wrap[depth] == lastWrap[depth]) {
|
|
2252
|
+
let inner = addToSibling(wrap, lastWrap, node, sibling.lastChild, depth + 1);
|
|
2253
|
+
if (inner) return sibling.copy(sibling.content.replaceChild(sibling.childCount - 1, inner));
|
|
2254
|
+
if (sibling.contentMatchAt(sibling.childCount).matchType(depth == wrap.length - 1 ? node.type : wrap[depth + 1])) return sibling.copy(sibling.content.append(require_dist.Fragment.from(withWrappers(node, wrap, depth + 1))));
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
function closeRight(node, depth) {
|
|
2258
|
+
if (depth == 0) return node;
|
|
2259
|
+
let fragment = node.content.replaceChild(node.childCount - 1, closeRight(node.lastChild, depth - 1));
|
|
2260
|
+
let fill = node.contentMatchAt(node.childCount).fillBefore(require_dist.Fragment.empty, true);
|
|
2261
|
+
return node.copy(fragment.append(fill));
|
|
2262
|
+
}
|
|
2263
|
+
function closeRange(fragment, side, from, to, depth, openEnd) {
|
|
2264
|
+
let node = side < 0 ? fragment.firstChild : fragment.lastChild, inner = node.content;
|
|
2265
|
+
if (fragment.childCount > 1) openEnd = 0;
|
|
2266
|
+
if (depth < to - 1) inner = closeRange(inner, side, from, to, depth + 1, openEnd);
|
|
2267
|
+
if (depth >= from) inner = side < 0 ? node.contentMatchAt(0).fillBefore(inner, openEnd <= depth).append(inner) : inner.append(node.contentMatchAt(node.childCount).fillBefore(require_dist.Fragment.empty, true));
|
|
2268
|
+
return fragment.replaceChild(side < 0 ? 0 : fragment.childCount - 1, node.copy(inner));
|
|
2269
|
+
}
|
|
2270
|
+
function closeSlice(slice, openStart, openEnd) {
|
|
2271
|
+
if (openStart < slice.openStart) slice = new require_dist.Slice(closeRange(slice.content, -1, openStart, slice.openStart, 0, slice.openEnd), openStart, slice.openEnd);
|
|
2272
|
+
if (openEnd < slice.openEnd) slice = new require_dist.Slice(closeRange(slice.content, 1, openEnd, slice.openEnd, 0, 0), slice.openStart, openEnd);
|
|
2273
|
+
return slice;
|
|
2274
|
+
}
|
|
2275
|
+
var wrapMap = {
|
|
2276
|
+
thead: ["table"],
|
|
2277
|
+
tbody: ["table"],
|
|
2278
|
+
tfoot: ["table"],
|
|
2279
|
+
caption: ["table"],
|
|
2280
|
+
colgroup: ["table"],
|
|
2281
|
+
col: ["table", "colgroup"],
|
|
2282
|
+
tr: ["table", "tbody"],
|
|
2283
|
+
td: [
|
|
2284
|
+
"table",
|
|
2285
|
+
"tbody",
|
|
2286
|
+
"tr"
|
|
2287
|
+
],
|
|
2288
|
+
th: [
|
|
2289
|
+
"table",
|
|
2290
|
+
"tbody",
|
|
2291
|
+
"tr"
|
|
2292
|
+
]
|
|
2293
|
+
};
|
|
2294
|
+
var _detachedDoc = null;
|
|
2295
|
+
function detachedDoc() {
|
|
2296
|
+
return _detachedDoc || (_detachedDoc = document.implementation.createHTMLDocument("title"));
|
|
2297
|
+
}
|
|
2298
|
+
var _policy = null;
|
|
2299
|
+
function maybeWrapTrusted(html) {
|
|
2300
|
+
let trustedTypes = window.trustedTypes;
|
|
2301
|
+
if (!trustedTypes) return html;
|
|
2302
|
+
if (!_policy) _policy = trustedTypes.defaultPolicy || trustedTypes.createPolicy("ProseMirrorClipboard", { createHTML: (s) => s });
|
|
2303
|
+
return _policy.createHTML(html);
|
|
2304
|
+
}
|
|
2305
|
+
function readHTML(html) {
|
|
2306
|
+
let metas = /^(\s*<meta [^>]*>)*/.exec(html);
|
|
2307
|
+
if (metas) html = html.slice(metas[0].length);
|
|
2308
|
+
let elt = detachedDoc().createElement("div");
|
|
2309
|
+
let firstTag = /<([a-z][^>\s]+)/i.exec(html), wrap;
|
|
2310
|
+
if (wrap = firstTag && wrapMap[firstTag[1].toLowerCase()]) html = wrap.map((n) => "<" + n + ">").join("") + html + wrap.map((n) => "</" + n + ">").reverse().join("");
|
|
2311
|
+
elt.innerHTML = maybeWrapTrusted(html);
|
|
2312
|
+
if (wrap) for (let i = 0; i < wrap.length; i++) elt = elt.querySelector(wrap[i]) || elt;
|
|
2313
|
+
return elt;
|
|
2314
|
+
}
|
|
2315
|
+
function restoreReplacedSpaces(dom) {
|
|
2316
|
+
let nodes = dom.querySelectorAll(chrome ? "span:not([class]):not([style])" : "span.Apple-converted-space");
|
|
2317
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
2318
|
+
let node = nodes[i];
|
|
2319
|
+
if (node.childNodes.length == 1 && node.textContent == "\xA0" && node.parentNode) node.parentNode.replaceChild(dom.ownerDocument.createTextNode(" "), node);
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
function addContext(slice, context) {
|
|
2323
|
+
if (!slice.size) return slice;
|
|
2324
|
+
let schema = slice.content.firstChild.type.schema, array;
|
|
2325
|
+
try {
|
|
2326
|
+
array = JSON.parse(context);
|
|
2327
|
+
} catch (e) {
|
|
2328
|
+
return slice;
|
|
2329
|
+
}
|
|
2330
|
+
let { content, openStart, openEnd } = slice;
|
|
2331
|
+
for (let i = array.length - 2; i >= 0; i -= 2) {
|
|
2332
|
+
let type = schema.nodes[array[i]];
|
|
2333
|
+
if (!type || type.hasRequiredAttrs()) break;
|
|
2334
|
+
content = require_dist.Fragment.from(type.create(array[i + 1], content));
|
|
2335
|
+
openStart++;
|
|
2336
|
+
openEnd++;
|
|
2337
|
+
}
|
|
2338
|
+
return new require_dist.Slice(content, openStart, openEnd);
|
|
2339
|
+
}
|
|
2340
|
+
var handlers = {};
|
|
2341
|
+
var editHandlers = {};
|
|
2342
|
+
var passiveHandlers = {
|
|
2343
|
+
touchstart: true,
|
|
2344
|
+
touchmove: true
|
|
2345
|
+
};
|
|
2346
|
+
var InputState = class {
|
|
2347
|
+
constructor() {
|
|
2348
|
+
this.shiftKey = false;
|
|
2349
|
+
this.mouseDown = null;
|
|
2350
|
+
this.lastKeyCode = null;
|
|
2351
|
+
this.lastKeyCodeTime = 0;
|
|
2352
|
+
this.lastClick = {
|
|
2353
|
+
time: 0,
|
|
2354
|
+
x: 0,
|
|
2355
|
+
y: 0,
|
|
2356
|
+
type: "",
|
|
2357
|
+
button: 0
|
|
2358
|
+
};
|
|
2359
|
+
this.lastSelectionOrigin = null;
|
|
2360
|
+
this.lastSelectionTime = 0;
|
|
2361
|
+
this.lastIOSEnter = 0;
|
|
2362
|
+
this.lastIOSEnterFallbackTimeout = -1;
|
|
2363
|
+
this.lastFocus = 0;
|
|
2364
|
+
this.lastTouch = 0;
|
|
2365
|
+
this.lastChromeDelete = 0;
|
|
2366
|
+
this.composing = false;
|
|
2367
|
+
this.compositionNode = null;
|
|
2368
|
+
this.composingTimeout = -1;
|
|
2369
|
+
this.compositionNodes = [];
|
|
2370
|
+
this.compositionEndedAt = -2e8;
|
|
2371
|
+
this.compositionID = 1;
|
|
2372
|
+
this.badSafariComposition = false;
|
|
2373
|
+
this.compositionPendingChanges = 0;
|
|
2374
|
+
this.domChangeCount = 0;
|
|
2375
|
+
this.eventHandlers = Object.create(null);
|
|
2376
|
+
this.hideSelectionGuard = null;
|
|
2377
|
+
}
|
|
2378
|
+
};
|
|
2379
|
+
function initInput(view) {
|
|
2380
|
+
for (let event in handlers) {
|
|
2381
|
+
let handler = handlers[event];
|
|
2382
|
+
view.dom.addEventListener(event, view.input.eventHandlers[event] = (event) => {
|
|
2383
|
+
if (eventBelongsToView(view, event) && !runCustomHandler(view, event) && (view.editable || !(event.type in editHandlers))) handler(view, event);
|
|
2384
|
+
}, passiveHandlers[event] ? { passive: true } : void 0);
|
|
2385
|
+
}
|
|
2386
|
+
if (safari) view.dom.addEventListener("input", () => null);
|
|
2387
|
+
ensureListeners(view);
|
|
2388
|
+
}
|
|
2389
|
+
function setSelectionOrigin(view, origin) {
|
|
2390
|
+
view.input.lastSelectionOrigin = origin;
|
|
2391
|
+
view.input.lastSelectionTime = Date.now();
|
|
2392
|
+
}
|
|
2393
|
+
function destroyInput(view) {
|
|
2394
|
+
if (view.input.mouseDown) view.input.mouseDown.done();
|
|
2395
|
+
view.domObserver.stop();
|
|
2396
|
+
for (let type in view.input.eventHandlers) view.dom.removeEventListener(type, view.input.eventHandlers[type]);
|
|
2397
|
+
clearTimeout(view.input.composingTimeout);
|
|
2398
|
+
clearTimeout(view.input.lastIOSEnterFallbackTimeout);
|
|
2399
|
+
}
|
|
2400
|
+
function ensureListeners(view) {
|
|
2401
|
+
view.someProp("handleDOMEvents", (currentHandlers) => {
|
|
2402
|
+
for (let type in currentHandlers) if (!view.input.eventHandlers[type]) view.dom.addEventListener(type, view.input.eventHandlers[type] = (event) => runCustomHandler(view, event));
|
|
2403
|
+
});
|
|
2404
|
+
}
|
|
2405
|
+
function runCustomHandler(view, event) {
|
|
2406
|
+
return view.someProp("handleDOMEvents", (handlers) => {
|
|
2407
|
+
let handler = handlers[event.type];
|
|
2408
|
+
return handler ? handler(view, event) || event.defaultPrevented : false;
|
|
2409
|
+
});
|
|
2410
|
+
}
|
|
2411
|
+
function eventBelongsToView(view, event) {
|
|
2412
|
+
if (!event.bubbles) return true;
|
|
2413
|
+
if (event.defaultPrevented) return false;
|
|
2414
|
+
for (let node = event.target; node != view.dom; node = node.parentNode) if (!node || node.nodeType == 11 || node.pmViewDesc && node.pmViewDesc.stopEvent(event)) return false;
|
|
2415
|
+
return true;
|
|
2416
|
+
}
|
|
2417
|
+
function dispatchEvent(view, event) {
|
|
2418
|
+
if (!runCustomHandler(view, event) && handlers[event.type] && (view.editable || !(event.type in editHandlers))) handlers[event.type](view, event);
|
|
2419
|
+
}
|
|
2420
|
+
editHandlers.keydown = (view, _event) => {
|
|
2421
|
+
let event = _event;
|
|
2422
|
+
view.input.shiftKey = event.keyCode == 16 || event.shiftKey;
|
|
2423
|
+
if (inOrNearComposition(view)) return;
|
|
2424
|
+
view.input.lastKeyCode = event.keyCode;
|
|
2425
|
+
view.input.lastKeyCodeTime = Date.now();
|
|
2426
|
+
if (android && chrome && event.keyCode == 13) return;
|
|
2427
|
+
if (event.keyCode != 229) view.domObserver.forceFlush();
|
|
2428
|
+
if (ios && event.keyCode == 13 && !event.ctrlKey && !event.altKey && !event.metaKey) {
|
|
2429
|
+
let now = Date.now();
|
|
2430
|
+
view.input.lastIOSEnter = now;
|
|
2431
|
+
view.input.lastIOSEnterFallbackTimeout = setTimeout(() => {
|
|
2432
|
+
if (view.input.lastIOSEnter == now) {
|
|
2433
|
+
view.someProp("handleKeyDown", (f) => f(view, keyEvent(13, "Enter")));
|
|
2434
|
+
view.input.lastIOSEnter = 0;
|
|
2435
|
+
}
|
|
2436
|
+
}, 200);
|
|
2437
|
+
} else if (view.someProp("handleKeyDown", (f) => f(view, event)) || captureKeyDown(view, event)) event.preventDefault();
|
|
2438
|
+
else setSelectionOrigin(view, "key");
|
|
2439
|
+
};
|
|
2440
|
+
editHandlers.keyup = (view, event) => {
|
|
2441
|
+
if (event.keyCode == 16) view.input.shiftKey = false;
|
|
2442
|
+
};
|
|
2443
|
+
editHandlers.keypress = (view, _event) => {
|
|
2444
|
+
let event = _event;
|
|
2445
|
+
if (inOrNearComposition(view) || !event.charCode || event.ctrlKey && !event.altKey || mac && event.metaKey) return;
|
|
2446
|
+
if (view.someProp("handleKeyPress", (f) => f(view, event))) {
|
|
2447
|
+
event.preventDefault();
|
|
2448
|
+
return;
|
|
2449
|
+
}
|
|
2450
|
+
let sel = view.state.selection;
|
|
2451
|
+
if (!(sel instanceof require_dist.TextSelection) || !sel.$from.sameParent(sel.$to)) {
|
|
2452
|
+
let text = String.fromCharCode(event.charCode);
|
|
2453
|
+
let deflt = () => view.state.tr.insertText(text).scrollIntoView();
|
|
2454
|
+
if (!/[\r\n]/.test(text) && !view.someProp("handleTextInput", (f) => f(view, sel.$from.pos, sel.$to.pos, text, deflt))) view.dispatch(deflt());
|
|
2455
|
+
event.preventDefault();
|
|
2456
|
+
}
|
|
2457
|
+
};
|
|
2458
|
+
function eventCoords(event) {
|
|
2459
|
+
return {
|
|
2460
|
+
left: event.clientX,
|
|
2461
|
+
top: event.clientY
|
|
2462
|
+
};
|
|
2463
|
+
}
|
|
2464
|
+
function isNear(event, click) {
|
|
2465
|
+
let dx = click.x - event.clientX, dy = click.y - event.clientY;
|
|
2466
|
+
return dx * dx + dy * dy < 100;
|
|
2467
|
+
}
|
|
2468
|
+
function runHandlerOnContext(view, propName, pos, inside, event) {
|
|
2469
|
+
if (inside == -1) return false;
|
|
2470
|
+
let $pos = view.state.doc.resolve(inside);
|
|
2471
|
+
for (let i = $pos.depth + 1; i > 0; i--) if (view.someProp(propName, (f) => i > $pos.depth ? f(view, pos, $pos.nodeAfter, $pos.before(i), event, true) : f(view, pos, $pos.node(i), $pos.before(i), event, false))) return true;
|
|
2472
|
+
return false;
|
|
2473
|
+
}
|
|
2474
|
+
function updateSelection(view, selection, origin) {
|
|
2475
|
+
if (!view.focused) view.focus();
|
|
2476
|
+
if (view.state.selection.eq(selection)) return;
|
|
2477
|
+
let tr = view.state.tr.setSelection(selection);
|
|
2478
|
+
if (origin == "pointer") tr.setMeta("pointer", true);
|
|
2479
|
+
view.dispatch(tr);
|
|
2480
|
+
}
|
|
2481
|
+
function selectClickedLeaf(view, inside) {
|
|
2482
|
+
if (inside == -1) return false;
|
|
2483
|
+
let $pos = view.state.doc.resolve(inside), node = $pos.nodeAfter;
|
|
2484
|
+
if (node && node.isAtom && require_dist.NodeSelection.isSelectable(node)) {
|
|
2485
|
+
updateSelection(view, new require_dist.NodeSelection($pos), "pointer");
|
|
2486
|
+
return true;
|
|
2487
|
+
}
|
|
2488
|
+
return false;
|
|
2489
|
+
}
|
|
2490
|
+
function selectClickedNode(view, inside) {
|
|
2491
|
+
if (inside == -1) return false;
|
|
2492
|
+
let sel = view.state.selection, selectedNode, selectAt;
|
|
2493
|
+
if (sel instanceof require_dist.NodeSelection) selectedNode = sel.node;
|
|
2494
|
+
let $pos = view.state.doc.resolve(inside);
|
|
2495
|
+
for (let i = $pos.depth + 1; i > 0; i--) {
|
|
2496
|
+
let node = i > $pos.depth ? $pos.nodeAfter : $pos.node(i);
|
|
2497
|
+
if (require_dist.NodeSelection.isSelectable(node)) {
|
|
2498
|
+
if (selectedNode && sel.$from.depth > 0 && i >= sel.$from.depth && $pos.before(sel.$from.depth + 1) == sel.$from.pos) selectAt = $pos.before(sel.$from.depth);
|
|
2499
|
+
else selectAt = $pos.before(i);
|
|
2500
|
+
break;
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
if (selectAt != null) {
|
|
2504
|
+
updateSelection(view, require_dist.NodeSelection.create(view.state.doc, selectAt), "pointer");
|
|
2505
|
+
return true;
|
|
2506
|
+
} else return false;
|
|
2507
|
+
}
|
|
2508
|
+
function handleSingleClick(view, pos, inside, event, selectNode) {
|
|
2509
|
+
return runHandlerOnContext(view, "handleClickOn", pos, inside, event) || view.someProp("handleClick", (f) => f(view, pos, event)) || (selectNode ? selectClickedNode(view, inside) : selectClickedLeaf(view, inside));
|
|
2510
|
+
}
|
|
2511
|
+
function handleDoubleClick(view, pos, inside, event) {
|
|
2512
|
+
return runHandlerOnContext(view, "handleDoubleClickOn", pos, inside, event) || view.someProp("handleDoubleClick", (f) => f(view, pos, event));
|
|
2513
|
+
}
|
|
2514
|
+
function handleTripleClick(view, pos, inside, event) {
|
|
2515
|
+
return runHandlerOnContext(view, "handleTripleClickOn", pos, inside, event) || view.someProp("handleTripleClick", (f) => f(view, pos, event)) || defaultTripleClick(view, inside, event);
|
|
2516
|
+
}
|
|
2517
|
+
function defaultTripleClick(view, inside, event) {
|
|
2518
|
+
if (event.button != 0) return false;
|
|
2519
|
+
let selection = selectionForTripleClick(view, inside, true), doc = view.state.doc;
|
|
2520
|
+
if (!selection) return false;
|
|
2521
|
+
updateSelection(view, selection, "pointer");
|
|
2522
|
+
if (selection instanceof require_dist.TextSelection && doc.eq(view.state.doc)) view.input.mouseDown = new TripleClickDrag(view, selection);
|
|
2523
|
+
return true;
|
|
2524
|
+
}
|
|
2525
|
+
function selectionForTripleClick(view, inside, selectNodes) {
|
|
2526
|
+
let doc = view.state.doc;
|
|
2527
|
+
if (inside == -1) return doc.inlineContent ? require_dist.TextSelection.create(doc, 0, doc.content.size) : null;
|
|
2528
|
+
let $pos = doc.resolve(inside);
|
|
2529
|
+
for (let i = $pos.depth + 1; i > 0; i--) {
|
|
2530
|
+
let node = i > $pos.depth ? $pos.nodeAfter : $pos.node(i);
|
|
2531
|
+
let nodePos = $pos.before(i);
|
|
2532
|
+
if (node.inlineContent) return require_dist.TextSelection.create(doc, nodePos + 1, nodePos + 1 + node.content.size);
|
|
2533
|
+
else if (selectNodes && require_dist.NodeSelection.isSelectable(node)) return require_dist.NodeSelection.create(doc, nodePos);
|
|
2534
|
+
}
|
|
2535
|
+
return null;
|
|
2536
|
+
}
|
|
2537
|
+
function forceDOMFlush(view) {
|
|
2538
|
+
return endComposition(view);
|
|
2539
|
+
}
|
|
2540
|
+
var selectNodeModifier = mac ? "metaKey" : "ctrlKey";
|
|
2541
|
+
handlers.mousedown = (view, _event) => {
|
|
2542
|
+
let event = _event;
|
|
2543
|
+
view.input.shiftKey = event.shiftKey;
|
|
2544
|
+
let flushed = forceDOMFlush(view);
|
|
2545
|
+
let now = Date.now(), type = "singleClick";
|
|
2546
|
+
if (now - view.input.lastClick.time < 500 && isNear(event, view.input.lastClick) && !event[selectNodeModifier] && view.input.lastClick.button == event.button) {
|
|
2547
|
+
if (view.input.lastClick.type == "singleClick") type = "doubleClick";
|
|
2548
|
+
else if (view.input.lastClick.type == "doubleClick") type = "tripleClick";
|
|
2549
|
+
}
|
|
2550
|
+
view.input.lastClick = {
|
|
2551
|
+
time: now,
|
|
2552
|
+
x: event.clientX,
|
|
2553
|
+
y: event.clientY,
|
|
2554
|
+
type,
|
|
2555
|
+
button: event.button
|
|
2556
|
+
};
|
|
2557
|
+
if (view.input.mouseDown) view.input.mouseDown.done();
|
|
2558
|
+
let pos = view.posAtCoords(eventCoords(event));
|
|
2559
|
+
if (!pos) return;
|
|
2560
|
+
if (type == "singleClick") view.input.mouseDown = new LeftMouseDown(view, pos, event, !!flushed);
|
|
2561
|
+
else if ((type == "doubleClick" ? handleDoubleClick : handleTripleClick)(view, pos.pos, pos.inside, event)) event.preventDefault();
|
|
2562
|
+
else setSelectionOrigin(view, "pointer");
|
|
2563
|
+
};
|
|
2564
|
+
var MouseDown = class {
|
|
2565
|
+
constructor(view) {
|
|
2566
|
+
this.view = view;
|
|
2567
|
+
this.mightDrag = null;
|
|
2568
|
+
view.root.addEventListener("mouseup", this.up = this.up.bind(this));
|
|
2569
|
+
view.root.addEventListener("mousemove", this.move = this.move.bind(this));
|
|
2570
|
+
}
|
|
2571
|
+
up(event) {
|
|
2572
|
+
this.done();
|
|
2573
|
+
}
|
|
2574
|
+
move(event) {
|
|
2575
|
+
if (event.buttons == 0) this.done();
|
|
2576
|
+
}
|
|
2577
|
+
done() {
|
|
2578
|
+
this.view.root.removeEventListener("mouseup", this.up);
|
|
2579
|
+
this.view.root.removeEventListener("mousemove", this.move);
|
|
2580
|
+
if (this.view.input.mouseDown == this) this.view.input.mouseDown = null;
|
|
2581
|
+
}
|
|
2582
|
+
delaySelUpdate() {
|
|
2583
|
+
return false;
|
|
2584
|
+
}
|
|
2585
|
+
};
|
|
2586
|
+
var LeftMouseDown = class extends MouseDown {
|
|
2587
|
+
constructor(view, pos, event, flushed) {
|
|
2588
|
+
super(view);
|
|
2589
|
+
this.pos = pos;
|
|
2590
|
+
this.event = event;
|
|
2591
|
+
this.flushed = flushed;
|
|
2592
|
+
this.delayedSelectionSync = false;
|
|
2593
|
+
this.startDoc = view.state.doc;
|
|
2594
|
+
this.selectNode = !!event[selectNodeModifier];
|
|
2595
|
+
this.allowDefault = event.shiftKey;
|
|
2596
|
+
let targetNode, targetPos;
|
|
2597
|
+
if (pos.inside > -1) {
|
|
2598
|
+
targetNode = view.state.doc.nodeAt(pos.inside);
|
|
2599
|
+
targetPos = pos.inside;
|
|
2600
|
+
} else {
|
|
2601
|
+
let $pos = view.state.doc.resolve(pos.pos);
|
|
2602
|
+
targetNode = $pos.parent;
|
|
2603
|
+
targetPos = $pos.depth ? $pos.before() : 0;
|
|
2604
|
+
}
|
|
2605
|
+
const target = flushed ? null : event.target;
|
|
2606
|
+
const targetDesc = target ? view.docView.nearestDesc(target, true) : null;
|
|
2607
|
+
this.target = targetDesc && targetDesc.nodeDOM.nodeType == 1 ? targetDesc.nodeDOM : null;
|
|
2608
|
+
let { selection } = view.state;
|
|
2609
|
+
if (event.button == 0 && (targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false || selection instanceof require_dist.NodeSelection && selection.from <= targetPos && selection.to > targetPos)) this.mightDrag = {
|
|
2610
|
+
node: targetNode,
|
|
2611
|
+
pos: targetPos,
|
|
2612
|
+
addAttr: !!(this.target && !this.target.draggable),
|
|
2613
|
+
setUneditable: !!(this.target && gecko && !this.target.hasAttribute("contentEditable"))
|
|
2614
|
+
};
|
|
2615
|
+
if (this.target && this.mightDrag && (this.mightDrag.addAttr || this.mightDrag.setUneditable)) {
|
|
2616
|
+
this.view.domObserver.stop();
|
|
2617
|
+
if (this.mightDrag.addAttr) this.target.draggable = true;
|
|
2618
|
+
if (this.mightDrag.setUneditable) setTimeout(() => {
|
|
2619
|
+
if (this.view.input.mouseDown == this) this.target.setAttribute("contentEditable", "false");
|
|
2620
|
+
}, 20);
|
|
2621
|
+
this.view.domObserver.start();
|
|
2622
|
+
}
|
|
2623
|
+
setSelectionOrigin(view, "pointer");
|
|
2624
|
+
}
|
|
2625
|
+
done() {
|
|
2626
|
+
super.done();
|
|
2627
|
+
if (this.mightDrag && this.target) {
|
|
2628
|
+
this.view.domObserver.stop();
|
|
2629
|
+
if (this.mightDrag.addAttr) this.target.removeAttribute("draggable");
|
|
2630
|
+
if (this.mightDrag.setUneditable) this.target.removeAttribute("contentEditable");
|
|
2631
|
+
this.view.domObserver.start();
|
|
2632
|
+
}
|
|
2633
|
+
if (this.delayedSelectionSync) setTimeout(() => {
|
|
2634
|
+
if (!this.view.isDestroyed) selectionToDOM(this.view);
|
|
2635
|
+
});
|
|
2636
|
+
}
|
|
2637
|
+
up(event) {
|
|
2638
|
+
this.done();
|
|
2639
|
+
if (!this.view.dom.contains(event.target)) return;
|
|
2640
|
+
let pos = this.pos;
|
|
2641
|
+
if (this.view.state.doc != this.startDoc) pos = this.view.posAtCoords(eventCoords(event));
|
|
2642
|
+
this.updateAllowDefault(event);
|
|
2643
|
+
if (this.allowDefault || !pos) setSelectionOrigin(this.view, "pointer");
|
|
2644
|
+
else if (handleSingleClick(this.view, pos.pos, pos.inside, event, this.selectNode)) event.preventDefault();
|
|
2645
|
+
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)) {
|
|
2646
|
+
updateSelection(this.view, require_dist.Selection.near(this.view.state.doc.resolve(pos.pos)), "pointer");
|
|
2647
|
+
event.preventDefault();
|
|
2648
|
+
} else setSelectionOrigin(this.view, "pointer");
|
|
2649
|
+
}
|
|
2650
|
+
move(event) {
|
|
2651
|
+
this.updateAllowDefault(event);
|
|
2652
|
+
setSelectionOrigin(this.view, "pointer");
|
|
2653
|
+
super.move(event);
|
|
2654
|
+
}
|
|
2655
|
+
updateAllowDefault(event) {
|
|
2656
|
+
if (!this.allowDefault && (Math.abs(this.event.x - event.clientX) > 4 || Math.abs(this.event.y - event.clientY) > 4)) this.allowDefault = true;
|
|
2657
|
+
}
|
|
2658
|
+
delaySelUpdate() {
|
|
2659
|
+
if (!this.allowDefault) return false;
|
|
2660
|
+
this.delayedSelectionSync = true;
|
|
2661
|
+
return true;
|
|
2662
|
+
}
|
|
2663
|
+
};
|
|
2664
|
+
var TripleClickDrag = class extends MouseDown {
|
|
2665
|
+
constructor(view, startSelection) {
|
|
2666
|
+
super(view);
|
|
2667
|
+
this.startSelection = startSelection;
|
|
2668
|
+
this.startDoc = view.state.doc;
|
|
2669
|
+
}
|
|
2670
|
+
move(event) {
|
|
2671
|
+
if (event.buttons == 0 || this.view.isDestroyed || !this.view.state.doc.eq(this.startDoc)) {
|
|
2672
|
+
this.done();
|
|
2673
|
+
return;
|
|
2674
|
+
}
|
|
2675
|
+
event.preventDefault();
|
|
2676
|
+
setSelectionOrigin(this.view, "pointer");
|
|
2677
|
+
let pos = this.view.posAtCoords(eventCoords(event));
|
|
2678
|
+
let target = pos && selectionForTripleClick(this.view, pos.inside, false);
|
|
2679
|
+
if (!target) return;
|
|
2680
|
+
let { doc } = this.view.state, start = this.startSelection;
|
|
2681
|
+
let [anchor, head] = target.from < start.from ? [start.to, target.from] : [start.from, target.to];
|
|
2682
|
+
updateSelection(this.view, require_dist.TextSelection.create(doc, anchor, head), "pointer");
|
|
2683
|
+
}
|
|
2684
|
+
};
|
|
2685
|
+
handlers.touchstart = (view) => {
|
|
2686
|
+
view.input.lastTouch = Date.now();
|
|
2687
|
+
forceDOMFlush(view);
|
|
2688
|
+
setSelectionOrigin(view, "pointer");
|
|
2689
|
+
};
|
|
2690
|
+
handlers.touchmove = (view) => {
|
|
2691
|
+
view.input.lastTouch = Date.now();
|
|
2692
|
+
setSelectionOrigin(view, "pointer");
|
|
2693
|
+
};
|
|
2694
|
+
handlers.contextmenu = (view) => forceDOMFlush(view);
|
|
2695
|
+
function inOrNearComposition(view, event) {
|
|
2696
|
+
if (view.composing) return true;
|
|
2697
|
+
if (safari && Math.abs(Date.now() - view.input.compositionEndedAt) < 500) {
|
|
2698
|
+
view.input.compositionEndedAt = -2e8;
|
|
2699
|
+
return true;
|
|
2700
|
+
}
|
|
2701
|
+
return false;
|
|
2702
|
+
}
|
|
2703
|
+
var timeoutComposition = android ? 5e3 : -1;
|
|
2704
|
+
editHandlers.compositionstart = editHandlers.compositionupdate = (view) => {
|
|
2705
|
+
if (!view.composing) {
|
|
2706
|
+
view.domObserver.flush();
|
|
2707
|
+
let { state } = view, $pos = state.selection.$to;
|
|
2708
|
+
if (state.selection instanceof require_dist.TextSelection && (state.storedMarks || !$pos.textOffset && $pos.parentOffset && $pos.nodeBefore.marks.some((m) => m.type.spec.inclusive === false) || chrome && windows && selectionBeforeUneditable(view))) {
|
|
2709
|
+
view.markCursor = view.state.storedMarks || $pos.marks();
|
|
2710
|
+
endComposition(view, true);
|
|
2711
|
+
view.markCursor = null;
|
|
2712
|
+
} else {
|
|
2713
|
+
endComposition(view, !state.selection.empty);
|
|
2714
|
+
if (gecko && state.selection.empty && $pos.parentOffset && !$pos.textOffset && $pos.nodeBefore.marks.length) {
|
|
2715
|
+
let sel = view.domSelectionRange();
|
|
2716
|
+
for (let node = sel.focusNode, offset = sel.focusOffset; node && node.nodeType == 1 && offset != 0;) {
|
|
2717
|
+
let before = offset < 0 ? node.lastChild : node.childNodes[offset - 1];
|
|
2718
|
+
if (!before) break;
|
|
2719
|
+
if (before.nodeType == 3) {
|
|
2720
|
+
let sel = view.domSelection();
|
|
2721
|
+
if (sel) sel.collapse(before, before.nodeValue.length);
|
|
2722
|
+
break;
|
|
2723
|
+
} else {
|
|
2724
|
+
node = before;
|
|
2725
|
+
offset = -1;
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
view.input.composing = true;
|
|
2731
|
+
}
|
|
2732
|
+
scheduleComposeEnd(view, timeoutComposition);
|
|
2733
|
+
};
|
|
2734
|
+
function selectionBeforeUneditable(view) {
|
|
2735
|
+
let { focusNode, focusOffset } = view.domSelectionRange();
|
|
2736
|
+
if (!focusNode || focusNode.nodeType != 1 || focusOffset >= focusNode.childNodes.length) return false;
|
|
2737
|
+
let next = focusNode.childNodes[focusOffset];
|
|
2738
|
+
return next.nodeType == 1 && next.contentEditable == "false";
|
|
2739
|
+
}
|
|
2740
|
+
editHandlers.compositionend = (view, event) => {
|
|
2741
|
+
if (view.composing) {
|
|
2742
|
+
view.input.composing = false;
|
|
2743
|
+
view.input.compositionEndedAt = Date.now();
|
|
2744
|
+
view.input.compositionPendingChanges = view.domObserver.pendingRecords().length ? view.input.compositionID : 0;
|
|
2745
|
+
view.input.compositionNode = null;
|
|
2746
|
+
if (view.input.badSafariComposition) view.domObserver.forceFlush();
|
|
2747
|
+
else if (view.input.compositionPendingChanges) Promise.resolve().then(() => view.domObserver.flush());
|
|
2748
|
+
view.input.compositionID++;
|
|
2749
|
+
scheduleComposeEnd(view, 20);
|
|
2750
|
+
}
|
|
2751
|
+
};
|
|
2752
|
+
function scheduleComposeEnd(view, delay) {
|
|
2753
|
+
clearTimeout(view.input.composingTimeout);
|
|
2754
|
+
if (delay > -1) view.input.composingTimeout = setTimeout(() => endComposition(view), delay);
|
|
2755
|
+
}
|
|
2756
|
+
function clearComposition(view) {
|
|
2757
|
+
if (view.composing) {
|
|
2758
|
+
view.input.composing = false;
|
|
2759
|
+
view.input.compositionEndedAt = Date.now();
|
|
2760
|
+
}
|
|
2761
|
+
while (view.input.compositionNodes.length > 0) view.input.compositionNodes.pop().markParentsDirty();
|
|
2762
|
+
}
|
|
2763
|
+
function findCompositionNode(view) {
|
|
2764
|
+
let sel = view.domSelectionRange();
|
|
2765
|
+
if (!sel.focusNode) return null;
|
|
2766
|
+
let textBefore = textNodeBefore$1(sel.focusNode, sel.focusOffset);
|
|
2767
|
+
let textAfter = textNodeAfter$1(sel.focusNode, sel.focusOffset);
|
|
2768
|
+
if (textBefore && textAfter && textBefore != textAfter) {
|
|
2769
|
+
let descAfter = textAfter.pmViewDesc, lastChanged = view.domObserver.lastChangedTextNode;
|
|
2770
|
+
if (textBefore == lastChanged || textAfter == lastChanged) return lastChanged;
|
|
2771
|
+
if (!descAfter || !descAfter.isText(textAfter.nodeValue)) return textAfter;
|
|
2772
|
+
else if (view.input.compositionNode == textAfter) {
|
|
2773
|
+
let descBefore = textBefore.pmViewDesc;
|
|
2774
|
+
if (!(!descBefore || !descBefore.isText(textBefore.nodeValue))) return textAfter;
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
return textBefore || textAfter;
|
|
2778
|
+
}
|
|
2779
|
+
/**
|
|
2780
|
+
@internal
|
|
2781
|
+
*/
|
|
2782
|
+
function endComposition(view, restarting = false) {
|
|
2783
|
+
if (android && view.domObserver.flushingSoon >= 0) return;
|
|
2784
|
+
view.domObserver.forceFlush();
|
|
2785
|
+
clearComposition(view);
|
|
2786
|
+
if (restarting || view.docView && view.docView.dirty) {
|
|
2787
|
+
let sel = selectionFromDOM(view), cur = view.state.selection;
|
|
2788
|
+
if (sel && !sel.eq(cur)) view.dispatch(view.state.tr.setSelection(sel));
|
|
2789
|
+
else if ((view.markCursor || restarting) && !cur.$from.node(cur.$from.sharedDepth(cur.to)).inlineContent) view.dispatch(view.state.tr.deleteSelection());
|
|
2790
|
+
else view.updateState(view.state);
|
|
2791
|
+
return true;
|
|
2792
|
+
}
|
|
2793
|
+
return false;
|
|
2794
|
+
}
|
|
2795
|
+
function captureCopy(view, dom) {
|
|
2796
|
+
if (!view.dom.parentNode) return;
|
|
2797
|
+
let wrap = view.dom.parentNode.appendChild(document.createElement("div"));
|
|
2798
|
+
wrap.appendChild(dom);
|
|
2799
|
+
wrap.style.cssText = "position: fixed; left: -10000px; top: 10px";
|
|
2800
|
+
let sel = getSelection(), range = document.createRange();
|
|
2801
|
+
range.selectNodeContents(dom);
|
|
2802
|
+
view.dom.blur();
|
|
2803
|
+
sel.removeAllRanges();
|
|
2804
|
+
sel.addRange(range);
|
|
2805
|
+
setTimeout(() => {
|
|
2806
|
+
if (wrap.parentNode) wrap.parentNode.removeChild(wrap);
|
|
2807
|
+
view.focus();
|
|
2808
|
+
}, 50);
|
|
2809
|
+
}
|
|
2810
|
+
var brokenClipboardAPI = ie && ie_version < 15 || ios && webkit_version < 604;
|
|
2811
|
+
handlers.copy = editHandlers.cut = (view, _event) => {
|
|
2812
|
+
let event = _event;
|
|
2813
|
+
let sel = view.state.selection, cut = event.type == "cut";
|
|
2814
|
+
if (sel.empty) return;
|
|
2815
|
+
let data = brokenClipboardAPI ? null : event.clipboardData;
|
|
2816
|
+
let { dom, text } = serializeForClipboard(view, sel.content());
|
|
2817
|
+
if (data) {
|
|
2818
|
+
event.preventDefault();
|
|
2819
|
+
data.clearData();
|
|
2820
|
+
data.setData("text/html", dom.innerHTML);
|
|
2821
|
+
data.setData("text/plain", text);
|
|
2822
|
+
} else captureCopy(view, dom);
|
|
2823
|
+
if (cut) view.dispatch(view.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent", "cut"));
|
|
2824
|
+
};
|
|
2825
|
+
function sliceSingleNode(slice) {
|
|
2826
|
+
return slice.openStart == 0 && slice.openEnd == 0 && slice.content.childCount == 1 ? slice.content.firstChild : null;
|
|
2827
|
+
}
|
|
2828
|
+
function capturePaste(view, event) {
|
|
2829
|
+
if (!view.dom.parentNode) return;
|
|
2830
|
+
let plainText = view.input.shiftKey || view.state.selection.$from.parent.type.spec.code;
|
|
2831
|
+
let target = view.dom.parentNode.appendChild(document.createElement(plainText ? "textarea" : "div"));
|
|
2832
|
+
if (!plainText) target.contentEditable = "true";
|
|
2833
|
+
target.style.cssText = "position: fixed; left: -10000px; top: 10px";
|
|
2834
|
+
target.focus();
|
|
2835
|
+
let plain = view.input.shiftKey && view.input.lastKeyCode != 45;
|
|
2836
|
+
setTimeout(() => {
|
|
2837
|
+
view.focus();
|
|
2838
|
+
if (target.parentNode) target.parentNode.removeChild(target);
|
|
2839
|
+
if (plainText) doPaste(view, target.value, null, plain, event);
|
|
2840
|
+
else doPaste(view, target.textContent, target.innerHTML, plain, event);
|
|
2841
|
+
}, 50);
|
|
2842
|
+
}
|
|
2843
|
+
function doPaste(view, text, html, preferPlain, event) {
|
|
2844
|
+
let slice = parseFromClipboard(view, text, html, preferPlain, view.state.selection.$from);
|
|
2845
|
+
if (view.someProp("handlePaste", (f) => f(view, event, slice || require_dist.Slice.empty))) return true;
|
|
2846
|
+
if (!slice) return false;
|
|
2847
|
+
let singleNode = sliceSingleNode(slice);
|
|
2848
|
+
let tr = singleNode ? view.state.tr.replaceSelectionWith(singleNode, preferPlain) : view.state.tr.replaceSelection(slice);
|
|
2849
|
+
view.dispatch(tr.scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste"));
|
|
2850
|
+
return true;
|
|
2851
|
+
}
|
|
2852
|
+
function getText(clipboardData) {
|
|
2853
|
+
let text = clipboardData.getData("text/plain") || clipboardData.getData("Text");
|
|
2854
|
+
if (text) return text;
|
|
2855
|
+
let uris = clipboardData.getData("text/uri-list");
|
|
2856
|
+
return uris ? uris.replace(/\r?\n/g, " ") : "";
|
|
2857
|
+
}
|
|
2858
|
+
editHandlers.paste = (view, _event) => {
|
|
2859
|
+
let event = _event;
|
|
2860
|
+
if (view.composing && !android) return;
|
|
2861
|
+
let data = brokenClipboardAPI ? null : event.clipboardData;
|
|
2862
|
+
let plain = view.input.shiftKey && view.input.lastKeyCode != 45;
|
|
2863
|
+
if (data && doPaste(view, getText(data), data.getData("text/html"), plain, event)) event.preventDefault();
|
|
2864
|
+
else capturePaste(view, event);
|
|
2865
|
+
};
|
|
2866
|
+
var Dragging = class {
|
|
2867
|
+
constructor(slice, move, node) {
|
|
2868
|
+
this.slice = slice;
|
|
2869
|
+
this.move = move;
|
|
2870
|
+
this.node = node;
|
|
2871
|
+
}
|
|
2872
|
+
};
|
|
2873
|
+
var dragCopyModifier = mac ? "altKey" : "ctrlKey";
|
|
2874
|
+
function dragMoves(view, event) {
|
|
2875
|
+
let copy;
|
|
2876
|
+
view.someProp("dragCopies", (test) => {
|
|
2877
|
+
copy = copy || test(event);
|
|
2878
|
+
});
|
|
2879
|
+
return copy != null ? !copy : !event[dragCopyModifier];
|
|
2880
|
+
}
|
|
2881
|
+
handlers.dragstart = (view, _event) => {
|
|
2882
|
+
let event = _event;
|
|
2883
|
+
let mouseDown = view.input.mouseDown;
|
|
2884
|
+
if (mouseDown) mouseDown.done();
|
|
2885
|
+
if (!event.dataTransfer) return;
|
|
2886
|
+
let sel = view.state.selection;
|
|
2887
|
+
let pos = sel.empty ? null : view.posAtCoords(eventCoords(event));
|
|
2888
|
+
let node;
|
|
2889
|
+
if (pos && pos.pos >= sel.from && pos.pos <= (sel instanceof require_dist.NodeSelection ? sel.to - 1 : sel.to));
|
|
2890
|
+
else if (mouseDown && mouseDown.mightDrag) node = require_dist.NodeSelection.create(view.state.doc, mouseDown.mightDrag.pos);
|
|
2891
|
+
else if (event.target && event.target.nodeType == 1) {
|
|
2892
|
+
let desc = view.docView.nearestDesc(event.target, true);
|
|
2893
|
+
if (desc && desc.node.type.spec.draggable && desc != view.docView) node = require_dist.NodeSelection.create(view.state.doc, desc.posBefore);
|
|
2894
|
+
}
|
|
2895
|
+
let { dom, text, slice } = serializeForClipboard(view, (node || view.state.selection).content());
|
|
2896
|
+
if (!event.dataTransfer.files.length || !chrome || chrome_version > 120) event.dataTransfer.clearData();
|
|
2897
|
+
event.dataTransfer.setData(brokenClipboardAPI ? "Text" : "text/html", dom.innerHTML);
|
|
2898
|
+
event.dataTransfer.effectAllowed = "copyMove";
|
|
2899
|
+
if (!brokenClipboardAPI) event.dataTransfer.setData("text/plain", text);
|
|
2900
|
+
view.dragging = new Dragging(slice, dragMoves(view, event), node);
|
|
2901
|
+
};
|
|
2902
|
+
handlers.dragend = (view) => {
|
|
2903
|
+
let dragging = view.dragging;
|
|
2904
|
+
window.setTimeout(() => {
|
|
2905
|
+
if (view.dragging == dragging) view.dragging = null;
|
|
2906
|
+
}, 50);
|
|
2907
|
+
};
|
|
2908
|
+
editHandlers.dragover = editHandlers.dragenter = (_, e) => e.preventDefault();
|
|
2909
|
+
editHandlers.drop = (view, event) => {
|
|
2910
|
+
try {
|
|
2911
|
+
handleDrop(view, event, view.dragging);
|
|
2912
|
+
} finally {
|
|
2913
|
+
view.dragging = null;
|
|
2914
|
+
}
|
|
2915
|
+
};
|
|
2916
|
+
function handleDrop(view, event, dragging) {
|
|
2917
|
+
if (!event.dataTransfer) return;
|
|
2918
|
+
let eventPos = view.posAtCoords(eventCoords(event));
|
|
2919
|
+
if (!eventPos) return;
|
|
2920
|
+
let $mouse = view.state.doc.resolve(eventPos.pos);
|
|
2921
|
+
let slice = dragging && dragging.slice;
|
|
2922
|
+
if (slice) view.someProp("transformPasted", (f) => {
|
|
2923
|
+
slice = f(slice, view, false);
|
|
2924
|
+
});
|
|
2925
|
+
else slice = parseFromClipboard(view, getText(event.dataTransfer), brokenClipboardAPI ? null : event.dataTransfer.getData("text/html"), false, $mouse);
|
|
2926
|
+
let move = !!(dragging && dragMoves(view, event));
|
|
2927
|
+
if (view.someProp("handleDrop", (f) => f(view, event, slice || require_dist.Slice.empty, move))) {
|
|
2928
|
+
event.preventDefault();
|
|
2929
|
+
return;
|
|
2930
|
+
}
|
|
2931
|
+
if (!slice) return;
|
|
2932
|
+
event.preventDefault();
|
|
2933
|
+
let insertPos = slice ? require_dist.dropPoint(view.state.doc, $mouse.pos, slice) : $mouse.pos;
|
|
2934
|
+
if (insertPos == null) insertPos = $mouse.pos;
|
|
2935
|
+
let tr = view.state.tr;
|
|
2936
|
+
if (move) {
|
|
2937
|
+
let { node } = dragging;
|
|
2938
|
+
if (node) node.replace(tr);
|
|
2939
|
+
else tr.deleteSelection();
|
|
2940
|
+
}
|
|
2941
|
+
let pos = tr.mapping.map(insertPos);
|
|
2942
|
+
let isNode = slice.openStart == 0 && slice.openEnd == 0 && slice.content.childCount == 1;
|
|
2943
|
+
let beforeInsert = tr.doc;
|
|
2944
|
+
if (isNode) tr.replaceRangeWith(pos, pos, slice.content.firstChild);
|
|
2945
|
+
else tr.replaceRange(pos, pos, slice);
|
|
2946
|
+
if (tr.doc.eq(beforeInsert)) return;
|
|
2947
|
+
let $pos = tr.doc.resolve(pos);
|
|
2948
|
+
if (isNode && require_dist.NodeSelection.isSelectable(slice.content.firstChild) && $pos.nodeAfter && $pos.nodeAfter.sameMarkup(slice.content.firstChild)) tr.setSelection(new require_dist.NodeSelection($pos));
|
|
2949
|
+
else {
|
|
2950
|
+
let end = tr.mapping.map(insertPos);
|
|
2951
|
+
tr.mapping.maps[tr.mapping.maps.length - 1].forEach((_from, _to, _newFrom, newTo) => end = newTo);
|
|
2952
|
+
tr.setSelection(selectionBetween(view, $pos, tr.doc.resolve(end)));
|
|
2953
|
+
}
|
|
2954
|
+
view.focus();
|
|
2955
|
+
view.dispatch(tr.setMeta("uiEvent", "drop"));
|
|
2956
|
+
}
|
|
2957
|
+
handlers.focus = (view) => {
|
|
2958
|
+
view.input.lastFocus = Date.now();
|
|
2959
|
+
if (!view.focused) {
|
|
2960
|
+
view.domObserver.stop();
|
|
2961
|
+
view.dom.classList.add("ProseMirror-focused");
|
|
2962
|
+
view.domObserver.start();
|
|
2963
|
+
view.focused = true;
|
|
2964
|
+
setTimeout(() => {
|
|
2965
|
+
if (view.docView && view.hasFocus() && !view.domObserver.currentSelection.eq(view.domSelectionRange())) selectionToDOM(view);
|
|
2966
|
+
}, 20);
|
|
2967
|
+
}
|
|
2968
|
+
};
|
|
2969
|
+
handlers.blur = (view, _event) => {
|
|
2970
|
+
let event = _event;
|
|
2971
|
+
if (view.focused) {
|
|
2972
|
+
view.domObserver.stop();
|
|
2973
|
+
view.dom.classList.remove("ProseMirror-focused");
|
|
2974
|
+
view.domObserver.start();
|
|
2975
|
+
if (event.relatedTarget && view.dom.contains(event.relatedTarget)) view.domObserver.currentSelection.clear();
|
|
2976
|
+
view.focused = false;
|
|
2977
|
+
}
|
|
2978
|
+
};
|
|
2979
|
+
handlers.beforeinput = (view, _event) => {
|
|
2980
|
+
if (chrome && android && _event.inputType == "deleteContentBackward") {
|
|
2981
|
+
view.domObserver.flushSoon();
|
|
2982
|
+
let { domChangeCount } = view.input;
|
|
2983
|
+
setTimeout(() => {
|
|
2984
|
+
if (view.input.domChangeCount != domChangeCount) return;
|
|
2985
|
+
view.dom.blur();
|
|
2986
|
+
view.focus();
|
|
2987
|
+
if (view.someProp("handleKeyDown", (f) => f(view, keyEvent(8, "Backspace")))) return;
|
|
2988
|
+
let { $cursor } = view.state.selection;
|
|
2989
|
+
if ($cursor && $cursor.pos > 0) view.dispatch(view.state.tr.delete($cursor.pos - 1, $cursor.pos).scrollIntoView());
|
|
2990
|
+
}, 50);
|
|
2991
|
+
}
|
|
2992
|
+
};
|
|
2993
|
+
for (let prop in editHandlers) handlers[prop] = editHandlers[prop];
|
|
2994
|
+
function compareObjs(a, b) {
|
|
2995
|
+
if (a == b) return true;
|
|
2996
|
+
for (let p in a) if (a[p] !== b[p]) return false;
|
|
2997
|
+
for (let p in b) if (!(p in a)) return false;
|
|
2998
|
+
return true;
|
|
2999
|
+
}
|
|
3000
|
+
var WidgetType = class WidgetType {
|
|
3001
|
+
constructor(toDOM, spec) {
|
|
3002
|
+
this.toDOM = toDOM;
|
|
3003
|
+
this.spec = spec || noSpec;
|
|
3004
|
+
this.side = this.spec.side || 0;
|
|
3005
|
+
}
|
|
3006
|
+
map(mapping, span, offset, oldOffset) {
|
|
3007
|
+
let { pos, deleted } = mapping.mapResult(span.from + oldOffset, this.side < 0 ? -1 : 1);
|
|
3008
|
+
return deleted ? null : new Decoration(pos - offset, pos - offset, this);
|
|
3009
|
+
}
|
|
3010
|
+
valid() {
|
|
3011
|
+
return true;
|
|
3012
|
+
}
|
|
3013
|
+
eq(other) {
|
|
3014
|
+
return this == other || other instanceof WidgetType && (this.spec.key && this.spec.key == other.spec.key || this.toDOM == other.toDOM && compareObjs(this.spec, other.spec));
|
|
3015
|
+
}
|
|
3016
|
+
destroy(node) {
|
|
3017
|
+
if (this.spec.destroy) this.spec.destroy(node);
|
|
3018
|
+
}
|
|
3019
|
+
};
|
|
3020
|
+
var InlineType = class InlineType {
|
|
3021
|
+
constructor(attrs, spec) {
|
|
3022
|
+
this.attrs = attrs;
|
|
3023
|
+
this.spec = spec || noSpec;
|
|
3024
|
+
}
|
|
3025
|
+
map(mapping, span, offset, oldOffset) {
|
|
3026
|
+
let from = mapping.map(span.from + oldOffset, this.spec.inclusiveStart ? -1 : 1) - offset;
|
|
3027
|
+
let to = mapping.map(span.to + oldOffset, this.spec.inclusiveEnd ? 1 : -1) - offset;
|
|
3028
|
+
return from >= to ? null : new Decoration(from, to, this);
|
|
3029
|
+
}
|
|
3030
|
+
valid(_, span) {
|
|
3031
|
+
return span.from < span.to;
|
|
3032
|
+
}
|
|
3033
|
+
eq(other) {
|
|
3034
|
+
return this == other || other instanceof InlineType && compareObjs(this.attrs, other.attrs) && compareObjs(this.spec, other.spec);
|
|
3035
|
+
}
|
|
3036
|
+
static is(span) {
|
|
3037
|
+
return span.type instanceof InlineType;
|
|
3038
|
+
}
|
|
3039
|
+
destroy() {}
|
|
3040
|
+
};
|
|
3041
|
+
var NodeType = class NodeType {
|
|
3042
|
+
constructor(attrs, spec) {
|
|
3043
|
+
this.attrs = attrs;
|
|
3044
|
+
this.spec = spec || noSpec;
|
|
3045
|
+
}
|
|
3046
|
+
map(mapping, span, offset, oldOffset) {
|
|
3047
|
+
let from = mapping.mapResult(span.from + oldOffset, 1);
|
|
3048
|
+
if (from.deleted) return null;
|
|
3049
|
+
let to = mapping.mapResult(span.to + oldOffset, -1);
|
|
3050
|
+
if (to.deleted || to.pos <= from.pos) return null;
|
|
3051
|
+
return new Decoration(from.pos - offset, to.pos - offset, this);
|
|
3052
|
+
}
|
|
3053
|
+
valid(node, span) {
|
|
3054
|
+
let { index, offset } = node.content.findIndex(span.from), child;
|
|
3055
|
+
return offset == span.from && !(child = node.child(index)).isText && offset + child.nodeSize == span.to;
|
|
3056
|
+
}
|
|
3057
|
+
eq(other) {
|
|
3058
|
+
return this == other || other instanceof NodeType && compareObjs(this.attrs, other.attrs) && compareObjs(this.spec, other.spec);
|
|
3059
|
+
}
|
|
3060
|
+
destroy() {}
|
|
3061
|
+
};
|
|
3062
|
+
/**
|
|
3063
|
+
Decoration objects can be provided to the view through the
|
|
3064
|
+
[`decorations` prop](https://prosemirror.net/docs/ref/#view.EditorProps.decorations). They come in
|
|
3065
|
+
several variants—see the static members of this class for details.
|
|
3066
|
+
*/
|
|
3067
|
+
var Decoration = class Decoration {
|
|
3068
|
+
/**
|
|
3069
|
+
@internal
|
|
3070
|
+
*/
|
|
3071
|
+
constructor(from, to, type) {
|
|
3072
|
+
this.from = from;
|
|
3073
|
+
this.to = to;
|
|
3074
|
+
this.type = type;
|
|
3075
|
+
}
|
|
3076
|
+
/**
|
|
3077
|
+
@internal
|
|
3078
|
+
*/
|
|
3079
|
+
copy(from, to) {
|
|
3080
|
+
return new Decoration(from, to, this.type);
|
|
3081
|
+
}
|
|
3082
|
+
/**
|
|
3083
|
+
@internal
|
|
3084
|
+
*/
|
|
3085
|
+
eq(other, offset = 0) {
|
|
3086
|
+
return this.type.eq(other.type) && this.from + offset == other.from && this.to + offset == other.to;
|
|
3087
|
+
}
|
|
3088
|
+
/**
|
|
3089
|
+
@internal
|
|
3090
|
+
*/
|
|
3091
|
+
map(mapping, offset, oldOffset) {
|
|
3092
|
+
return this.type.map(mapping, this, offset, oldOffset);
|
|
3093
|
+
}
|
|
3094
|
+
/**
|
|
3095
|
+
Creates a widget decoration, which is a DOM node that's shown in
|
|
3096
|
+
the document at the given position. It is recommended that you
|
|
3097
|
+
delay rendering the widget by passing a function that will be
|
|
3098
|
+
called when the widget is actually drawn in a view, but you can
|
|
3099
|
+
also directly pass a DOM node. `getPos` can be used to find the
|
|
3100
|
+
widget's current document position.
|
|
3101
|
+
*/
|
|
3102
|
+
static widget(pos, toDOM, spec) {
|
|
3103
|
+
return new Decoration(pos, pos, new WidgetType(toDOM, spec));
|
|
3104
|
+
}
|
|
3105
|
+
/**
|
|
3106
|
+
Creates an inline decoration, which adds the given attributes to
|
|
3107
|
+
each inline node between `from` and `to`.
|
|
3108
|
+
*/
|
|
3109
|
+
static inline(from, to, attrs, spec) {
|
|
3110
|
+
return new Decoration(from, to, new InlineType(attrs, spec));
|
|
3111
|
+
}
|
|
3112
|
+
/**
|
|
3113
|
+
Creates a node decoration. `from` and `to` should point precisely
|
|
3114
|
+
before and after a node in the document. That node, and only that
|
|
3115
|
+
node, will receive the given attributes.
|
|
3116
|
+
*/
|
|
3117
|
+
static node(from, to, attrs, spec) {
|
|
3118
|
+
return new Decoration(from, to, new NodeType(attrs, spec));
|
|
3119
|
+
}
|
|
3120
|
+
/**
|
|
3121
|
+
The spec provided when creating this decoration. Can be useful
|
|
3122
|
+
if you've stored extra information in that object.
|
|
3123
|
+
*/
|
|
3124
|
+
get spec() {
|
|
3125
|
+
return this.type.spec;
|
|
3126
|
+
}
|
|
3127
|
+
/**
|
|
3128
|
+
@internal
|
|
3129
|
+
*/
|
|
3130
|
+
get inline() {
|
|
3131
|
+
return this.type instanceof InlineType;
|
|
3132
|
+
}
|
|
3133
|
+
/**
|
|
3134
|
+
@internal
|
|
3135
|
+
*/
|
|
3136
|
+
get widget() {
|
|
3137
|
+
return this.type instanceof WidgetType;
|
|
3138
|
+
}
|
|
3139
|
+
};
|
|
3140
|
+
var none = [], noSpec = {};
|
|
3141
|
+
/**
|
|
3142
|
+
A collection of [decorations](https://prosemirror.net/docs/ref/#view.Decoration), organized in such
|
|
3143
|
+
a way that the drawing algorithm can efficiently use and compare
|
|
3144
|
+
them. This is a persistent data structure—it is not modified,
|
|
3145
|
+
updates create a new value.
|
|
3146
|
+
*/
|
|
3147
|
+
var DecorationSet = class DecorationSet {
|
|
3148
|
+
/**
|
|
3149
|
+
@internal
|
|
3150
|
+
*/
|
|
3151
|
+
constructor(local, children) {
|
|
3152
|
+
this.local = local.length ? local : none;
|
|
3153
|
+
this.children = children.length ? children : none;
|
|
3154
|
+
}
|
|
3155
|
+
/**
|
|
3156
|
+
Create a set of decorations, using the structure of the given
|
|
3157
|
+
document. This will consume (modify) the `decorations` array, so
|
|
3158
|
+
you must make a copy if you want need to preserve that.
|
|
3159
|
+
*/
|
|
3160
|
+
static create(doc, decorations) {
|
|
3161
|
+
return decorations.length ? buildTree(decorations, doc, 0, noSpec) : empty;
|
|
3162
|
+
}
|
|
3163
|
+
/**
|
|
3164
|
+
Find all decorations in this set which touch the given range
|
|
3165
|
+
(including decorations that start or end directly at the
|
|
3166
|
+
boundaries) and match the given predicate on their spec. When
|
|
3167
|
+
`start` and `end` are omitted, all decorations in the set are
|
|
3168
|
+
considered. When `predicate` isn't given, all decorations are
|
|
3169
|
+
assumed to match.
|
|
3170
|
+
*/
|
|
3171
|
+
find(start, end, predicate) {
|
|
3172
|
+
let result = [];
|
|
3173
|
+
this.findInner(start == null ? 0 : start, end == null ? 1e9 : end, result, 0, predicate);
|
|
3174
|
+
return result;
|
|
3175
|
+
}
|
|
3176
|
+
findInner(start, end, result, offset, predicate) {
|
|
3177
|
+
for (let i = 0; i < this.local.length; i++) {
|
|
3178
|
+
let span = this.local[i];
|
|
3179
|
+
if (span.from <= end && span.to >= start && (!predicate || predicate(span.spec))) result.push(span.copy(span.from + offset, span.to + offset));
|
|
3180
|
+
}
|
|
3181
|
+
for (let i = 0; i < this.children.length; i += 3) if (this.children[i] < end && this.children[i + 1] > start) {
|
|
3182
|
+
let childOff = this.children[i] + 1;
|
|
3183
|
+
this.children[i + 2].findInner(start - childOff, end - childOff, result, offset + childOff, predicate);
|
|
3184
|
+
}
|
|
3185
|
+
}
|
|
3186
|
+
/**
|
|
3187
|
+
Map the set of decorations in response to a change in the
|
|
3188
|
+
document.
|
|
3189
|
+
*/
|
|
3190
|
+
map(mapping, doc, options) {
|
|
3191
|
+
if (this == empty || mapping.maps.length == 0) return this;
|
|
3192
|
+
return this.mapInner(mapping, doc, 0, 0, options || noSpec);
|
|
3193
|
+
}
|
|
3194
|
+
/**
|
|
3195
|
+
@internal
|
|
3196
|
+
*/
|
|
3197
|
+
mapInner(mapping, node, offset, oldOffset, options) {
|
|
3198
|
+
let newLocal;
|
|
3199
|
+
for (let i = 0; i < this.local.length; i++) {
|
|
3200
|
+
let mapped = this.local[i].map(mapping, offset, oldOffset);
|
|
3201
|
+
if (mapped && mapped.type.valid(node, mapped)) (newLocal || (newLocal = [])).push(mapped);
|
|
3202
|
+
else if (options.onRemove) options.onRemove(this.local[i].spec);
|
|
3203
|
+
}
|
|
3204
|
+
if (this.children.length) return mapChildren(this.children, newLocal || [], mapping, node, offset, oldOffset, options);
|
|
3205
|
+
else return newLocal ? new DecorationSet(newLocal.sort(byPos), none) : empty;
|
|
3206
|
+
}
|
|
3207
|
+
/**
|
|
3208
|
+
Add the given array of decorations to the ones in the set,
|
|
3209
|
+
producing a new set. Consumes the `decorations` array. Needs
|
|
3210
|
+
access to the current document to create the appropriate tree
|
|
3211
|
+
structure.
|
|
3212
|
+
*/
|
|
3213
|
+
add(doc, decorations) {
|
|
3214
|
+
if (!decorations.length) return this;
|
|
3215
|
+
if (this == empty) return DecorationSet.create(doc, decorations);
|
|
3216
|
+
return this.addInner(doc, decorations, 0);
|
|
3217
|
+
}
|
|
3218
|
+
addInner(doc, decorations, offset) {
|
|
3219
|
+
let children, childIndex = 0;
|
|
3220
|
+
doc.forEach((childNode, childOffset) => {
|
|
3221
|
+
let baseOffset = childOffset + offset, found;
|
|
3222
|
+
if (!(found = takeSpansForNode(decorations, childNode, baseOffset))) return;
|
|
3223
|
+
if (!children) children = this.children.slice();
|
|
3224
|
+
while (childIndex < children.length && children[childIndex] < childOffset) childIndex += 3;
|
|
3225
|
+
if (children[childIndex] == childOffset) children[childIndex + 2] = children[childIndex + 2].addInner(childNode, found, baseOffset + 1);
|
|
3226
|
+
else children.splice(childIndex, 0, childOffset, childOffset + childNode.nodeSize, buildTree(found, childNode, baseOffset + 1, noSpec));
|
|
3227
|
+
childIndex += 3;
|
|
3228
|
+
});
|
|
3229
|
+
let local = moveSpans(childIndex ? withoutNulls(decorations) : decorations, -offset);
|
|
3230
|
+
for (let i = 0; i < local.length; i++) if (!local[i].type.valid(doc, local[i])) local.splice(i--, 1);
|
|
3231
|
+
return new DecorationSet(local.length ? this.local.concat(local).sort(byPos) : this.local, children || this.children);
|
|
3232
|
+
}
|
|
3233
|
+
/**
|
|
3234
|
+
Create a new set that contains the decorations in this set, minus
|
|
3235
|
+
the ones in the given array.
|
|
3236
|
+
*/
|
|
3237
|
+
remove(decorations) {
|
|
3238
|
+
if (decorations.length == 0 || this == empty) return this;
|
|
3239
|
+
return this.removeInner(decorations, 0);
|
|
3240
|
+
}
|
|
3241
|
+
removeInner(decorations, offset) {
|
|
3242
|
+
let children = this.children, local = this.local;
|
|
3243
|
+
for (let i = 0; i < children.length; i += 3) {
|
|
3244
|
+
let found;
|
|
3245
|
+
let from = children[i] + offset, to = children[i + 1] + offset;
|
|
3246
|
+
for (let j = 0, span; j < decorations.length; j++) if (span = decorations[j]) {
|
|
3247
|
+
if (span.from > from && span.to < to) {
|
|
3248
|
+
decorations[j] = null;
|
|
3249
|
+
(found || (found = [])).push(span);
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
if (!found) continue;
|
|
3253
|
+
if (children == this.children) children = this.children.slice();
|
|
3254
|
+
let removed = children[i + 2].removeInner(found, from + 1);
|
|
3255
|
+
if (removed != empty) children[i + 2] = removed;
|
|
3256
|
+
else {
|
|
3257
|
+
children.splice(i, 3);
|
|
3258
|
+
i -= 3;
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3261
|
+
if (local.length) {
|
|
3262
|
+
for (let i = 0, span; i < decorations.length; i++) if (span = decorations[i]) {
|
|
3263
|
+
for (let j = 0; j < local.length; j++) if (local[j].eq(span, offset)) {
|
|
3264
|
+
if (local == this.local) local = this.local.slice();
|
|
3265
|
+
local.splice(j--, 1);
|
|
3266
|
+
}
|
|
3267
|
+
}
|
|
3268
|
+
}
|
|
3269
|
+
if (children == this.children && local == this.local) return this;
|
|
3270
|
+
return local.length || children.length ? new DecorationSet(local, children) : empty;
|
|
3271
|
+
}
|
|
3272
|
+
forChild(offset, node) {
|
|
3273
|
+
if (this == empty) return this;
|
|
3274
|
+
if (node.isLeaf) return DecorationSet.empty;
|
|
3275
|
+
let child, local;
|
|
3276
|
+
for (let i = 0; i < this.children.length; i += 3) if (this.children[i] >= offset) {
|
|
3277
|
+
if (this.children[i] == offset) child = this.children[i + 2];
|
|
3278
|
+
break;
|
|
3279
|
+
}
|
|
3280
|
+
let start = offset + 1, end = start + node.content.size;
|
|
3281
|
+
for (let i = 0; i < this.local.length; i++) {
|
|
3282
|
+
let dec = this.local[i];
|
|
3283
|
+
if (dec.from < end && dec.to > start && dec.type instanceof InlineType) {
|
|
3284
|
+
let from = Math.max(start, dec.from) - start, to = Math.min(end, dec.to) - start;
|
|
3285
|
+
if (from < to) (local || (local = [])).push(dec.copy(from, to));
|
|
3286
|
+
}
|
|
3287
|
+
}
|
|
3288
|
+
if (local) {
|
|
3289
|
+
let localSet = new DecorationSet(local.sort(byPos), none);
|
|
3290
|
+
return child ? new DecorationGroup([localSet, child]) : localSet;
|
|
3291
|
+
}
|
|
3292
|
+
return child || empty;
|
|
3293
|
+
}
|
|
3294
|
+
/**
|
|
3295
|
+
@internal
|
|
3296
|
+
*/
|
|
3297
|
+
eq(other) {
|
|
3298
|
+
if (this == other) return true;
|
|
3299
|
+
if (!(other instanceof DecorationSet) || this.local.length != other.local.length || this.children.length != other.children.length) return false;
|
|
3300
|
+
for (let i = 0; i < this.local.length; i++) if (!this.local[i].eq(other.local[i])) return false;
|
|
3301
|
+
for (let i = 0; i < this.children.length; i += 3) if (this.children[i] != other.children[i] || this.children[i + 1] != other.children[i + 1] || !this.children[i + 2].eq(other.children[i + 2])) return false;
|
|
3302
|
+
return true;
|
|
3303
|
+
}
|
|
3304
|
+
/**
|
|
3305
|
+
@internal
|
|
3306
|
+
*/
|
|
3307
|
+
locals(node) {
|
|
3308
|
+
return removeOverlap(this.localsInner(node));
|
|
3309
|
+
}
|
|
3310
|
+
/**
|
|
3311
|
+
@internal
|
|
3312
|
+
*/
|
|
3313
|
+
localsInner(node) {
|
|
3314
|
+
if (this == empty) return none;
|
|
3315
|
+
if (node.inlineContent || !this.local.some(InlineType.is)) return this.local;
|
|
3316
|
+
let result = [];
|
|
3317
|
+
for (let i = 0; i < this.local.length; i++) if (!(this.local[i].type instanceof InlineType)) result.push(this.local[i]);
|
|
3318
|
+
return result;
|
|
3319
|
+
}
|
|
3320
|
+
forEachSet(f) {
|
|
3321
|
+
f(this);
|
|
3322
|
+
}
|
|
3323
|
+
};
|
|
3324
|
+
/**
|
|
3325
|
+
The empty set of decorations.
|
|
3326
|
+
*/
|
|
3327
|
+
DecorationSet.empty = new DecorationSet([], []);
|
|
3328
|
+
/**
|
|
3329
|
+
@internal
|
|
3330
|
+
*/
|
|
3331
|
+
DecorationSet.removeOverlap = removeOverlap;
|
|
3332
|
+
var empty = DecorationSet.empty;
|
|
3333
|
+
var DecorationGroup = class DecorationGroup {
|
|
3334
|
+
constructor(members) {
|
|
3335
|
+
this.members = members;
|
|
3336
|
+
}
|
|
3337
|
+
map(mapping, doc) {
|
|
3338
|
+
const mappedDecos = this.members.map((member) => member.map(mapping, doc, noSpec));
|
|
3339
|
+
return DecorationGroup.from(mappedDecos);
|
|
3340
|
+
}
|
|
3341
|
+
forChild(offset, child) {
|
|
3342
|
+
if (child.isLeaf) return DecorationSet.empty;
|
|
3343
|
+
let found = [];
|
|
3344
|
+
for (let i = 0; i < this.members.length; i++) {
|
|
3345
|
+
let result = this.members[i].forChild(offset, child);
|
|
3346
|
+
if (result == empty) continue;
|
|
3347
|
+
if (result instanceof DecorationGroup) found = found.concat(result.members);
|
|
3348
|
+
else found.push(result);
|
|
3349
|
+
}
|
|
3350
|
+
return DecorationGroup.from(found);
|
|
3351
|
+
}
|
|
3352
|
+
eq(other) {
|
|
3353
|
+
if (!(other instanceof DecorationGroup) || other.members.length != this.members.length) return false;
|
|
3354
|
+
for (let i = 0; i < this.members.length; i++) if (!this.members[i].eq(other.members[i])) return false;
|
|
3355
|
+
return true;
|
|
3356
|
+
}
|
|
3357
|
+
locals(node) {
|
|
3358
|
+
let result, sorted = true;
|
|
3359
|
+
for (let i = 0; i < this.members.length; i++) {
|
|
3360
|
+
let locals = this.members[i].localsInner(node);
|
|
3361
|
+
if (!locals.length) continue;
|
|
3362
|
+
if (!result) result = locals;
|
|
3363
|
+
else {
|
|
3364
|
+
if (sorted) {
|
|
3365
|
+
result = result.slice();
|
|
3366
|
+
sorted = false;
|
|
3367
|
+
}
|
|
3368
|
+
for (let j = 0; j < locals.length; j++) result.push(locals[j]);
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
return result ? removeOverlap(sorted ? result : result.sort(byPos)) : none;
|
|
3372
|
+
}
|
|
3373
|
+
static from(members) {
|
|
3374
|
+
switch (members.length) {
|
|
3375
|
+
case 0: return empty;
|
|
3376
|
+
case 1: return members[0];
|
|
3377
|
+
default: return new DecorationGroup(members.every((m) => m instanceof DecorationSet) ? members : members.reduce((r, m) => r.concat(m instanceof DecorationSet ? m : m.members), []));
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3380
|
+
forEachSet(f) {
|
|
3381
|
+
for (let i = 0; i < this.members.length; i++) this.members[i].forEachSet(f);
|
|
3382
|
+
}
|
|
3383
|
+
};
|
|
3384
|
+
function mapChildren(oldChildren, newLocal, mapping, node, offset, oldOffset, options) {
|
|
3385
|
+
let children = oldChildren.slice();
|
|
3386
|
+
for (let i = 0, baseOffset = oldOffset; i < mapping.maps.length; i++) {
|
|
3387
|
+
let moved = 0;
|
|
3388
|
+
mapping.maps[i].forEach((oldStart, oldEnd, newStart, newEnd) => {
|
|
3389
|
+
let dSize = newEnd - newStart - (oldEnd - oldStart);
|
|
3390
|
+
for (let i = 0; i < children.length; i += 3) {
|
|
3391
|
+
let end = children[i + 1];
|
|
3392
|
+
if (end < 0 || oldStart > end + baseOffset - moved) continue;
|
|
3393
|
+
let start = children[i] + baseOffset - moved;
|
|
3394
|
+
if (oldEnd >= start) children[i + 1] = oldStart <= start ? -2 : -1;
|
|
3395
|
+
else if (oldStart >= baseOffset && dSize) {
|
|
3396
|
+
children[i] += dSize;
|
|
3397
|
+
children[i + 1] += dSize;
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
moved += dSize;
|
|
3401
|
+
});
|
|
3402
|
+
baseOffset = mapping.maps[i].map(baseOffset, -1);
|
|
3403
|
+
}
|
|
3404
|
+
let mustRebuild = false;
|
|
3405
|
+
for (let i = 0; i < children.length; i += 3) if (children[i + 1] < 0) {
|
|
3406
|
+
if (children[i + 1] == -2) {
|
|
3407
|
+
mustRebuild = true;
|
|
3408
|
+
children[i + 1] = -1;
|
|
3409
|
+
continue;
|
|
3410
|
+
}
|
|
3411
|
+
let from = mapping.map(oldChildren[i] + oldOffset), fromLocal = from - offset;
|
|
3412
|
+
if (fromLocal < 0 || fromLocal >= node.content.size) {
|
|
3413
|
+
mustRebuild = true;
|
|
3414
|
+
continue;
|
|
3415
|
+
}
|
|
3416
|
+
let toLocal = mapping.map(oldChildren[i + 1] + oldOffset, -1) - offset;
|
|
3417
|
+
let { index, offset: childOffset } = node.content.findIndex(fromLocal);
|
|
3418
|
+
let childNode = node.maybeChild(index);
|
|
3419
|
+
if (childNode && childOffset == fromLocal && childOffset + childNode.nodeSize == toLocal) {
|
|
3420
|
+
let mapped = children[i + 2].mapInner(mapping, childNode, from + 1, oldChildren[i] + oldOffset + 1, options);
|
|
3421
|
+
if (mapped != empty) {
|
|
3422
|
+
children[i] = fromLocal;
|
|
3423
|
+
children[i + 1] = toLocal;
|
|
3424
|
+
children[i + 2] = mapped;
|
|
3425
|
+
} else {
|
|
3426
|
+
children[i + 1] = -2;
|
|
3427
|
+
mustRebuild = true;
|
|
3428
|
+
}
|
|
3429
|
+
} else mustRebuild = true;
|
|
3430
|
+
}
|
|
3431
|
+
if (mustRebuild) {
|
|
3432
|
+
let built = buildTree(mapAndGatherRemainingDecorations(children, oldChildren, newLocal, mapping, offset, oldOffset, options), node, 0, options);
|
|
3433
|
+
newLocal = built.local;
|
|
3434
|
+
for (let i = 0; i < children.length; i += 3) if (children[i + 1] < 0) {
|
|
3435
|
+
children.splice(i, 3);
|
|
3436
|
+
i -= 3;
|
|
3437
|
+
}
|
|
3438
|
+
for (let i = 0, j = 0; i < built.children.length; i += 3) {
|
|
3439
|
+
let from = built.children[i];
|
|
3440
|
+
while (j < children.length && children[j] < from) j += 3;
|
|
3441
|
+
children.splice(j, 0, built.children[i], built.children[i + 1], built.children[i + 2]);
|
|
3442
|
+
}
|
|
3443
|
+
}
|
|
3444
|
+
return new DecorationSet(newLocal.sort(byPos), children);
|
|
3445
|
+
}
|
|
3446
|
+
function moveSpans(spans, offset) {
|
|
3447
|
+
if (!offset || !spans.length) return spans;
|
|
3448
|
+
let result = [];
|
|
3449
|
+
for (let i = 0; i < spans.length; i++) {
|
|
3450
|
+
let span = spans[i];
|
|
3451
|
+
result.push(new Decoration(span.from + offset, span.to + offset, span.type));
|
|
3452
|
+
}
|
|
3453
|
+
return result;
|
|
3454
|
+
}
|
|
3455
|
+
function mapAndGatherRemainingDecorations(children, oldChildren, decorations, mapping, offset, oldOffset, options) {
|
|
3456
|
+
function gather(set, oldOffset) {
|
|
3457
|
+
for (let i = 0; i < set.local.length; i++) {
|
|
3458
|
+
let mapped = set.local[i].map(mapping, offset, oldOffset);
|
|
3459
|
+
if (mapped) decorations.push(mapped);
|
|
3460
|
+
else if (options.onRemove) options.onRemove(set.local[i].spec);
|
|
3461
|
+
}
|
|
3462
|
+
for (let i = 0; i < set.children.length; i += 3) gather(set.children[i + 2], set.children[i] + oldOffset + 1);
|
|
3463
|
+
}
|
|
3464
|
+
for (let i = 0; i < children.length; i += 3) if (children[i + 1] == -1) gather(children[i + 2], oldChildren[i] + oldOffset + 1);
|
|
3465
|
+
return decorations;
|
|
3466
|
+
}
|
|
3467
|
+
function takeSpansForNode(spans, node, offset) {
|
|
3468
|
+
if (node.isLeaf) return null;
|
|
3469
|
+
let end = offset + node.nodeSize, found = null;
|
|
3470
|
+
for (let i = 0, span; i < spans.length; i++) if ((span = spans[i]) && span.from > offset && span.to < end) {
|
|
3471
|
+
(found || (found = [])).push(span);
|
|
3472
|
+
spans[i] = null;
|
|
3473
|
+
}
|
|
3474
|
+
return found;
|
|
3475
|
+
}
|
|
3476
|
+
function withoutNulls(array) {
|
|
3477
|
+
let result = [];
|
|
3478
|
+
for (let i = 0; i < array.length; i++) if (array[i] != null) result.push(array[i]);
|
|
3479
|
+
return result;
|
|
3480
|
+
}
|
|
3481
|
+
function buildTree(spans, node, offset, options) {
|
|
3482
|
+
let children = [], hasNulls = false;
|
|
3483
|
+
node.forEach((childNode, localStart) => {
|
|
3484
|
+
let found = takeSpansForNode(spans, childNode, localStart + offset);
|
|
3485
|
+
if (found) {
|
|
3486
|
+
hasNulls = true;
|
|
3487
|
+
let subtree = buildTree(found, childNode, offset + localStart + 1, options);
|
|
3488
|
+
if (subtree != empty) children.push(localStart, localStart + childNode.nodeSize, subtree);
|
|
3489
|
+
}
|
|
3490
|
+
});
|
|
3491
|
+
let locals = moveSpans(hasNulls ? withoutNulls(spans) : spans, -offset).sort(byPos);
|
|
3492
|
+
for (let i = 0; i < locals.length; i++) if (!locals[i].type.valid(node, locals[i])) {
|
|
3493
|
+
if (options.onRemove) options.onRemove(locals[i].spec);
|
|
3494
|
+
locals.splice(i--, 1);
|
|
3495
|
+
}
|
|
3496
|
+
return locals.length || children.length ? new DecorationSet(locals, children) : empty;
|
|
3497
|
+
}
|
|
3498
|
+
function byPos(a, b) {
|
|
3499
|
+
return a.from - b.from || a.to - b.to;
|
|
3500
|
+
}
|
|
3501
|
+
function removeOverlap(spans) {
|
|
3502
|
+
let working = spans;
|
|
3503
|
+
for (let i = 0; i < working.length - 1; i++) {
|
|
3504
|
+
let span = working[i];
|
|
3505
|
+
if (span.from != span.to) for (let j = i + 1; j < working.length; j++) {
|
|
3506
|
+
let next = working[j];
|
|
3507
|
+
if (next.from == span.from) {
|
|
3508
|
+
if (next.to != span.to) {
|
|
3509
|
+
if (working == spans) working = spans.slice();
|
|
3510
|
+
working[j] = next.copy(next.from, span.to);
|
|
3511
|
+
insertAhead(working, j + 1, next.copy(span.to, next.to));
|
|
3512
|
+
}
|
|
3513
|
+
continue;
|
|
3514
|
+
} else {
|
|
3515
|
+
if (next.from < span.to) {
|
|
3516
|
+
if (working == spans) working = spans.slice();
|
|
3517
|
+
working[i] = span.copy(span.from, next.from);
|
|
3518
|
+
insertAhead(working, j, span.copy(next.from, span.to));
|
|
3519
|
+
}
|
|
3520
|
+
break;
|
|
3521
|
+
}
|
|
3522
|
+
}
|
|
3523
|
+
}
|
|
3524
|
+
return working;
|
|
3525
|
+
}
|
|
3526
|
+
function insertAhead(array, i, deco) {
|
|
3527
|
+
while (i < array.length && byPos(deco, array[i]) > 0) i++;
|
|
3528
|
+
array.splice(i, 0, deco);
|
|
3529
|
+
}
|
|
3530
|
+
function viewDecorations(view) {
|
|
3531
|
+
let found = [];
|
|
3532
|
+
view.someProp("decorations", (f) => {
|
|
3533
|
+
let result = f(view.state);
|
|
3534
|
+
if (result && result != empty) found.push(result);
|
|
3535
|
+
});
|
|
3536
|
+
if (view.cursorWrapper) found.push(DecorationSet.create(view.state.doc, [view.cursorWrapper.deco]));
|
|
3537
|
+
return DecorationGroup.from(found);
|
|
3538
|
+
}
|
|
3539
|
+
var observeOptions = {
|
|
3540
|
+
childList: true,
|
|
3541
|
+
characterData: true,
|
|
3542
|
+
characterDataOldValue: true,
|
|
3543
|
+
attributes: true,
|
|
3544
|
+
attributeOldValue: true,
|
|
3545
|
+
subtree: true
|
|
3546
|
+
};
|
|
3547
|
+
var useCharData = ie && ie_version <= 11;
|
|
3548
|
+
var SelectionState = class {
|
|
3549
|
+
constructor() {
|
|
3550
|
+
this.anchorNode = null;
|
|
3551
|
+
this.anchorOffset = 0;
|
|
3552
|
+
this.focusNode = null;
|
|
3553
|
+
this.focusOffset = 0;
|
|
3554
|
+
}
|
|
3555
|
+
set(sel) {
|
|
3556
|
+
this.anchorNode = sel.anchorNode;
|
|
3557
|
+
this.anchorOffset = sel.anchorOffset;
|
|
3558
|
+
this.focusNode = sel.focusNode;
|
|
3559
|
+
this.focusOffset = sel.focusOffset;
|
|
3560
|
+
}
|
|
3561
|
+
clear() {
|
|
3562
|
+
this.anchorNode = this.focusNode = null;
|
|
3563
|
+
}
|
|
3564
|
+
eq(sel) {
|
|
3565
|
+
return sel.anchorNode == this.anchorNode && sel.anchorOffset == this.anchorOffset && sel.focusNode == this.focusNode && sel.focusOffset == this.focusOffset;
|
|
3566
|
+
}
|
|
3567
|
+
};
|
|
3568
|
+
var DOMObserver = class {
|
|
3569
|
+
constructor(view, handleDOMChange) {
|
|
3570
|
+
this.view = view;
|
|
3571
|
+
this.handleDOMChange = handleDOMChange;
|
|
3572
|
+
this.queue = [];
|
|
3573
|
+
this.flushingSoon = -1;
|
|
3574
|
+
this.observer = null;
|
|
3575
|
+
this.currentSelection = new SelectionState();
|
|
3576
|
+
this.onCharData = null;
|
|
3577
|
+
this.suppressingSelectionUpdates = false;
|
|
3578
|
+
this.lastChangedTextNode = null;
|
|
3579
|
+
this.observer = window.MutationObserver && new window.MutationObserver((mutations) => {
|
|
3580
|
+
for (let i = 0; i < mutations.length; i++) this.queue.push(mutations[i]);
|
|
3581
|
+
if (ie && ie_version <= 11 && mutations.some((m) => m.type == "childList" && m.removedNodes.length || m.type == "characterData" && m.oldValue.length > m.target.nodeValue.length)) this.flushSoon();
|
|
3582
|
+
else if (safari && view.composing && mutations.some((m) => m.type == "childList" && m.target.nodeName == "TR")) {
|
|
3583
|
+
view.input.badSafariComposition = true;
|
|
3584
|
+
this.flushSoon();
|
|
3585
|
+
} else this.flush();
|
|
3586
|
+
});
|
|
3587
|
+
if (useCharData) this.onCharData = (e) => {
|
|
3588
|
+
this.queue.push({
|
|
3589
|
+
target: e.target,
|
|
3590
|
+
type: "characterData",
|
|
3591
|
+
oldValue: e.prevValue
|
|
3592
|
+
});
|
|
3593
|
+
this.flushSoon();
|
|
3594
|
+
};
|
|
3595
|
+
this.onSelectionChange = this.onSelectionChange.bind(this);
|
|
3596
|
+
}
|
|
3597
|
+
flushSoon() {
|
|
3598
|
+
if (this.flushingSoon < 0) this.flushingSoon = window.setTimeout(() => {
|
|
3599
|
+
this.flushingSoon = -1;
|
|
3600
|
+
this.flush();
|
|
3601
|
+
}, 20);
|
|
3602
|
+
}
|
|
3603
|
+
forceFlush() {
|
|
3604
|
+
if (this.flushingSoon > -1) {
|
|
3605
|
+
window.clearTimeout(this.flushingSoon);
|
|
3606
|
+
this.flushingSoon = -1;
|
|
3607
|
+
this.flush();
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
start() {
|
|
3611
|
+
if (this.observer) {
|
|
3612
|
+
this.observer.takeRecords();
|
|
3613
|
+
this.observer.observe(this.view.dom, observeOptions);
|
|
3614
|
+
}
|
|
3615
|
+
if (this.onCharData) this.view.dom.addEventListener("DOMCharacterDataModified", this.onCharData);
|
|
3616
|
+
this.connectSelection();
|
|
3617
|
+
}
|
|
3618
|
+
stop() {
|
|
3619
|
+
if (this.observer) {
|
|
3620
|
+
let take = this.observer.takeRecords();
|
|
3621
|
+
if (take.length) {
|
|
3622
|
+
for (let i = 0; i < take.length; i++) this.queue.push(take[i]);
|
|
3623
|
+
window.setTimeout(() => this.flush(), 20);
|
|
3624
|
+
}
|
|
3625
|
+
this.observer.disconnect();
|
|
3626
|
+
}
|
|
3627
|
+
if (this.onCharData) this.view.dom.removeEventListener("DOMCharacterDataModified", this.onCharData);
|
|
3628
|
+
this.disconnectSelection();
|
|
3629
|
+
}
|
|
3630
|
+
connectSelection() {
|
|
3631
|
+
this.view.dom.ownerDocument.addEventListener("selectionchange", this.onSelectionChange);
|
|
3632
|
+
}
|
|
3633
|
+
disconnectSelection() {
|
|
3634
|
+
this.view.dom.ownerDocument.removeEventListener("selectionchange", this.onSelectionChange);
|
|
3635
|
+
}
|
|
3636
|
+
suppressSelectionUpdates() {
|
|
3637
|
+
this.suppressingSelectionUpdates = true;
|
|
3638
|
+
setTimeout(() => this.suppressingSelectionUpdates = false, 50);
|
|
3639
|
+
}
|
|
3640
|
+
onSelectionChange() {
|
|
3641
|
+
if (!hasFocusAndSelection(this.view)) return;
|
|
3642
|
+
if (this.suppressingSelectionUpdates) return selectionToDOM(this.view);
|
|
3643
|
+
if (ie && ie_version <= 11 && !this.view.state.selection.empty) {
|
|
3644
|
+
let sel = this.view.domSelectionRange();
|
|
3645
|
+
if (sel.focusNode && isEquivalentPosition(sel.focusNode, sel.focusOffset, sel.anchorNode, sel.anchorOffset)) return this.flushSoon();
|
|
3646
|
+
}
|
|
3647
|
+
this.flush();
|
|
3648
|
+
}
|
|
3649
|
+
setCurSelection() {
|
|
3650
|
+
this.currentSelection.set(this.view.domSelectionRange());
|
|
3651
|
+
}
|
|
3652
|
+
ignoreSelectionChange(sel) {
|
|
3653
|
+
if (!sel.focusNode) return true;
|
|
3654
|
+
let ancestors = /* @__PURE__ */ new Set(), container;
|
|
3655
|
+
for (let scan = sel.focusNode; scan; scan = parentNode(scan)) ancestors.add(scan);
|
|
3656
|
+
for (let scan = sel.anchorNode; scan; scan = parentNode(scan)) if (ancestors.has(scan)) {
|
|
3657
|
+
container = scan;
|
|
3658
|
+
break;
|
|
3659
|
+
}
|
|
3660
|
+
let desc = container && this.view.docView.nearestDesc(container);
|
|
3661
|
+
if (desc && desc.ignoreMutation({
|
|
3662
|
+
type: "selection",
|
|
3663
|
+
target: container.nodeType == 3 ? container.parentNode : container
|
|
3664
|
+
})) {
|
|
3665
|
+
this.setCurSelection();
|
|
3666
|
+
return true;
|
|
3667
|
+
}
|
|
3668
|
+
}
|
|
3669
|
+
pendingRecords() {
|
|
3670
|
+
if (this.observer) for (let mut of this.observer.takeRecords()) this.queue.push(mut);
|
|
3671
|
+
return this.queue;
|
|
3672
|
+
}
|
|
3673
|
+
flush() {
|
|
3674
|
+
let { view } = this;
|
|
3675
|
+
if (!view.docView || this.flushingSoon > -1) return;
|
|
3676
|
+
let mutations = this.pendingRecords();
|
|
3677
|
+
if (mutations.length) this.queue = [];
|
|
3678
|
+
let sel = view.domSelectionRange();
|
|
3679
|
+
let newSel = !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasFocusAndSelection(view) && !this.ignoreSelectionChange(sel);
|
|
3680
|
+
let from = -1, to = -1, typeOver = false, added = [];
|
|
3681
|
+
if (view.editable) for (let i = 0; i < mutations.length; i++) {
|
|
3682
|
+
let result = this.registerMutation(mutations[i], added);
|
|
3683
|
+
if (result) {
|
|
3684
|
+
from = from < 0 ? result.from : Math.min(result.from, from);
|
|
3685
|
+
to = to < 0 ? result.to : Math.max(result.to, to);
|
|
3686
|
+
if (result.typeOver) typeOver = true;
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
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))) {
|
|
3690
|
+
for (let node of added) if (node.nodeName == "BR" && node.parentNode) {
|
|
3691
|
+
let after = node.nextSibling;
|
|
3692
|
+
while (after && after.nodeType == 1) {
|
|
3693
|
+
if (after.contentEditable == "false") {
|
|
3694
|
+
node.parentNode.removeChild(node);
|
|
3695
|
+
break;
|
|
3696
|
+
}
|
|
3697
|
+
after = after.firstChild;
|
|
3698
|
+
}
|
|
3699
|
+
}
|
|
3700
|
+
} else if (gecko && added.length) {
|
|
3701
|
+
let brs = added.filter((n) => n.nodeName == "BR");
|
|
3702
|
+
if (brs.length == 2) {
|
|
3703
|
+
let [a, b] = brs;
|
|
3704
|
+
if (a.parentNode && a.parentNode.parentNode == b.parentNode) b.remove();
|
|
3705
|
+
else a.remove();
|
|
3706
|
+
} else {
|
|
3707
|
+
let { focusNode } = this.currentSelection;
|
|
3708
|
+
for (let br of brs) {
|
|
3709
|
+
let parent = br.parentNode;
|
|
3710
|
+
if (parent && parent.nodeName == "LI" && (!focusNode || blockParent(view, focusNode) != parent)) br.remove();
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
}
|
|
3714
|
+
let readSel = null;
|
|
3715
|
+
if (from < 0 && newSel && view.input.lastFocus > Date.now() - 200 && Math.max(view.input.lastTouch, view.input.lastClick.time) < Date.now() - 300 && selectionCollapsed(sel) && (readSel = selectionFromDOM(view)) && readSel.eq(require_dist.Selection.near(view.state.doc.resolve(0), 1))) {
|
|
3716
|
+
view.input.lastFocus = 0;
|
|
3717
|
+
selectionToDOM(view);
|
|
3718
|
+
this.currentSelection.set(sel);
|
|
3719
|
+
view.scrollToSelection();
|
|
3720
|
+
} else if (from > -1 || newSel) {
|
|
3721
|
+
if (from > -1) {
|
|
3722
|
+
view.docView.markDirty(from, to);
|
|
3723
|
+
checkCSS(view);
|
|
3724
|
+
}
|
|
3725
|
+
if (view.input.badSafariComposition) {
|
|
3726
|
+
view.input.badSafariComposition = false;
|
|
3727
|
+
fixUpBadSafariComposition(view, added);
|
|
3728
|
+
}
|
|
3729
|
+
this.handleDOMChange(from, to, typeOver, added);
|
|
3730
|
+
if (view.docView && view.docView.dirty) view.updateState(view.state);
|
|
3731
|
+
else if (!this.currentSelection.eq(sel)) selectionToDOM(view);
|
|
3732
|
+
this.currentSelection.set(sel);
|
|
3733
|
+
}
|
|
3734
|
+
}
|
|
3735
|
+
registerMutation(mut, added) {
|
|
3736
|
+
if (added.indexOf(mut.target) > -1) return null;
|
|
3737
|
+
let desc = this.view.docView.nearestDesc(mut.target);
|
|
3738
|
+
if (mut.type == "attributes" && (desc == this.view.docView || mut.attributeName == "contenteditable" || mut.attributeName == "style" && !mut.oldValue && !mut.target.getAttribute("style"))) return null;
|
|
3739
|
+
if (!desc || desc.ignoreMutation(mut)) return null;
|
|
3740
|
+
if (mut.type == "childList") {
|
|
3741
|
+
for (let i = 0; i < mut.addedNodes.length; i++) {
|
|
3742
|
+
let node = mut.addedNodes[i];
|
|
3743
|
+
added.push(node);
|
|
3744
|
+
if (node.nodeType == 3) this.lastChangedTextNode = node;
|
|
3745
|
+
}
|
|
3746
|
+
if (desc.contentDOM && desc.contentDOM != desc.dom && !desc.contentDOM.contains(mut.target)) return {
|
|
3747
|
+
from: desc.posBefore,
|
|
3748
|
+
to: desc.posAfter
|
|
3749
|
+
};
|
|
3750
|
+
let prev = mut.previousSibling, next = mut.nextSibling;
|
|
3751
|
+
if (ie && ie_version <= 11 && mut.addedNodes.length) for (let i = 0; i < mut.addedNodes.length; i++) {
|
|
3752
|
+
let { previousSibling, nextSibling } = mut.addedNodes[i];
|
|
3753
|
+
if (!previousSibling || Array.prototype.indexOf.call(mut.addedNodes, previousSibling) < 0) prev = previousSibling;
|
|
3754
|
+
if (!nextSibling || Array.prototype.indexOf.call(mut.addedNodes, nextSibling) < 0) next = nextSibling;
|
|
3755
|
+
}
|
|
3756
|
+
let fromOffset = prev && prev.parentNode == mut.target ? domIndex(prev) + 1 : 0;
|
|
3757
|
+
let from = desc.localPosFromDOM(mut.target, fromOffset, -1);
|
|
3758
|
+
let toOffset = next && next.parentNode == mut.target ? domIndex(next) : mut.target.childNodes.length;
|
|
3759
|
+
return {
|
|
3760
|
+
from,
|
|
3761
|
+
to: desc.localPosFromDOM(mut.target, toOffset, 1)
|
|
3762
|
+
};
|
|
3763
|
+
} else if (mut.type == "attributes") return {
|
|
3764
|
+
from: desc.posAtStart - desc.border,
|
|
3765
|
+
to: desc.posAtEnd + desc.border
|
|
3766
|
+
};
|
|
3767
|
+
else {
|
|
3768
|
+
this.lastChangedTextNode = mut.target;
|
|
3769
|
+
return {
|
|
3770
|
+
from: desc.posAtStart,
|
|
3771
|
+
to: desc.posAtEnd,
|
|
3772
|
+
typeOver: mut.target.nodeValue == mut.oldValue
|
|
3773
|
+
};
|
|
3774
|
+
}
|
|
3775
|
+
}
|
|
3776
|
+
};
|
|
3777
|
+
var cssChecked = /* @__PURE__ */ new WeakMap();
|
|
3778
|
+
var cssCheckWarned = false;
|
|
3779
|
+
function checkCSS(view) {
|
|
3780
|
+
if (cssChecked.has(view)) return;
|
|
3781
|
+
cssChecked.set(view, null);
|
|
3782
|
+
if ([
|
|
3783
|
+
"normal",
|
|
3784
|
+
"nowrap",
|
|
3785
|
+
"pre-line"
|
|
3786
|
+
].indexOf(getComputedStyle(view.dom).whiteSpace) !== -1) {
|
|
3787
|
+
view.requiresGeckoHackNode = gecko;
|
|
3788
|
+
if (cssCheckWarned) return;
|
|
3789
|
+
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.");
|
|
3790
|
+
cssCheckWarned = true;
|
|
3791
|
+
}
|
|
3792
|
+
}
|
|
3793
|
+
function rangeToSelectionRange(view, range) {
|
|
3794
|
+
let anchorNode = range.startContainer, anchorOffset = range.startOffset;
|
|
3795
|
+
let focusNode = range.endContainer, focusOffset = range.endOffset;
|
|
3796
|
+
let currentAnchor = view.domAtPos(view.state.selection.anchor);
|
|
3797
|
+
if (isEquivalentPosition(currentAnchor.node, currentAnchor.offset, focusNode, focusOffset)) [anchorNode, anchorOffset, focusNode, focusOffset] = [
|
|
3798
|
+
focusNode,
|
|
3799
|
+
focusOffset,
|
|
3800
|
+
anchorNode,
|
|
3801
|
+
anchorOffset
|
|
3802
|
+
];
|
|
3803
|
+
return {
|
|
3804
|
+
anchorNode,
|
|
3805
|
+
anchorOffset,
|
|
3806
|
+
focusNode,
|
|
3807
|
+
focusOffset
|
|
3808
|
+
};
|
|
3809
|
+
}
|
|
3810
|
+
function safariShadowSelectionRange(view, selection) {
|
|
3811
|
+
if (selection.getComposedRanges) {
|
|
3812
|
+
let range = selection.getComposedRanges(view.root)[0];
|
|
3813
|
+
if (range) return rangeToSelectionRange(view, range);
|
|
3814
|
+
}
|
|
3815
|
+
let found;
|
|
3816
|
+
function read(event) {
|
|
3817
|
+
event.preventDefault();
|
|
3818
|
+
event.stopImmediatePropagation();
|
|
3819
|
+
found = event.getTargetRanges()[0];
|
|
3820
|
+
}
|
|
3821
|
+
view.dom.addEventListener("beforeinput", read, true);
|
|
3822
|
+
document.execCommand("indent");
|
|
3823
|
+
view.dom.removeEventListener("beforeinput", read, true);
|
|
3824
|
+
return found ? rangeToSelectionRange(view, found) : null;
|
|
3825
|
+
}
|
|
3826
|
+
function blockParent(view, node) {
|
|
3827
|
+
for (let p = node.parentNode; p && p != view.dom; p = p.parentNode) {
|
|
3828
|
+
let desc = view.docView.nearestDesc(p, true);
|
|
3829
|
+
if (desc && desc.node.isBlock) return p;
|
|
3830
|
+
}
|
|
3831
|
+
return null;
|
|
3832
|
+
}
|
|
3833
|
+
function fixUpBadSafariComposition(view, addedNodes) {
|
|
3834
|
+
var _a;
|
|
3835
|
+
let { focusNode, focusOffset } = view.domSelectionRange();
|
|
3836
|
+
for (let node of addedNodes) if (((_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.nodeName) == "TR") {
|
|
3837
|
+
let nextCell = node.nextSibling;
|
|
3838
|
+
while (nextCell && nextCell.nodeName != "TD" && nextCell.nodeName != "TH") nextCell = nextCell.nextSibling;
|
|
3839
|
+
if (nextCell) {
|
|
3840
|
+
let parent = nextCell;
|
|
3841
|
+
for (;;) {
|
|
3842
|
+
let first = parent.firstChild;
|
|
3843
|
+
if (!first || first.nodeType != 1 || first.contentEditable == "false" || /^(BR|IMG)$/.test(first.nodeName)) break;
|
|
3844
|
+
parent = first;
|
|
3845
|
+
}
|
|
3846
|
+
parent.insertBefore(node, parent.firstChild);
|
|
3847
|
+
if (focusNode == node) view.domSelection().collapse(node, focusOffset);
|
|
3848
|
+
} else node.parentNode.removeChild(node);
|
|
3849
|
+
}
|
|
3850
|
+
}
|
|
3851
|
+
function parseBetween(view, from_, to_) {
|
|
3852
|
+
let { node: parent, fromOffset, toOffset, from, to } = view.docView.parseRange(from_, to_);
|
|
3853
|
+
let domSel = view.domSelectionRange();
|
|
3854
|
+
let find;
|
|
3855
|
+
let anchor = domSel.anchorNode;
|
|
3856
|
+
if (anchor && view.dom.contains(anchor.nodeType == 1 ? anchor : anchor.parentNode)) {
|
|
3857
|
+
find = [{
|
|
3858
|
+
node: anchor,
|
|
3859
|
+
offset: domSel.anchorOffset
|
|
3860
|
+
}];
|
|
3861
|
+
if (!selectionCollapsed(domSel)) find.push({
|
|
3862
|
+
node: domSel.focusNode,
|
|
3863
|
+
offset: domSel.focusOffset
|
|
3864
|
+
});
|
|
3865
|
+
}
|
|
3866
|
+
if (chrome && view.input.lastKeyCode === 8) for (let off = toOffset; off > fromOffset; off--) {
|
|
3867
|
+
let node = parent.childNodes[off - 1], desc = node.pmViewDesc;
|
|
3868
|
+
if (node.nodeName == "BR" && !desc) {
|
|
3869
|
+
toOffset = off;
|
|
3870
|
+
break;
|
|
3871
|
+
}
|
|
3872
|
+
if (!desc || desc.size) break;
|
|
3873
|
+
}
|
|
3874
|
+
let startDoc = view.state.doc;
|
|
3875
|
+
let parser = view.someProp("domParser") || require_dist.DOMParser.fromSchema(view.state.schema);
|
|
3876
|
+
let $from = startDoc.resolve(from);
|
|
3877
|
+
let sel = null, doc = parser.parse(parent, {
|
|
3878
|
+
topNode: $from.parent,
|
|
3879
|
+
topMatch: $from.parent.contentMatchAt($from.index()),
|
|
3880
|
+
topOpen: true,
|
|
3881
|
+
from: fromOffset,
|
|
3882
|
+
to: toOffset,
|
|
3883
|
+
preserveWhitespace: $from.parent.type.whitespace == "pre" ? "full" : true,
|
|
3884
|
+
findPositions: find,
|
|
3885
|
+
ruleFromNode,
|
|
3886
|
+
context: $from
|
|
3887
|
+
});
|
|
3888
|
+
if (find && find[0].pos != null) {
|
|
3889
|
+
let anchor = find[0].pos, head = find[1] && find[1].pos;
|
|
3890
|
+
if (head == null) head = anchor;
|
|
3891
|
+
sel = {
|
|
3892
|
+
anchor: anchor + from,
|
|
3893
|
+
head: head + from
|
|
3894
|
+
};
|
|
3895
|
+
}
|
|
3896
|
+
return {
|
|
3897
|
+
doc,
|
|
3898
|
+
sel,
|
|
3899
|
+
from,
|
|
3900
|
+
to
|
|
3901
|
+
};
|
|
3902
|
+
}
|
|
3903
|
+
function ruleFromNode(dom) {
|
|
3904
|
+
let desc = dom.pmViewDesc;
|
|
3905
|
+
if (desc) return desc.parseRule();
|
|
3906
|
+
else if (dom.nodeName == "BR" && dom.parentNode) {
|
|
3907
|
+
if (safari && /^(ul|ol)$/i.test(dom.parentNode.nodeName)) {
|
|
3908
|
+
let skip = document.createElement("div");
|
|
3909
|
+
skip.appendChild(document.createElement("li"));
|
|
3910
|
+
return { skip };
|
|
3911
|
+
} else if (dom.parentNode.lastChild == dom || safari && /^(tr|table)$/i.test(dom.parentNode.nodeName)) return { ignore: true };
|
|
3912
|
+
} else if (dom.nodeName == "IMG" && dom.getAttribute("mark-placeholder")) return { ignore: true };
|
|
3913
|
+
return null;
|
|
3914
|
+
}
|
|
3915
|
+
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;
|
|
3916
|
+
function readDOMChange(view, from, to, typeOver, addedNodes) {
|
|
3917
|
+
let compositionID = view.input.compositionPendingChanges || (view.composing ? view.input.compositionID : 0);
|
|
3918
|
+
view.input.compositionPendingChanges = 0;
|
|
3919
|
+
if (from < 0) {
|
|
3920
|
+
let origin = view.input.lastSelectionTime > Date.now() - 50 ? view.input.lastSelectionOrigin : null;
|
|
3921
|
+
let newSel = selectionFromDOM(view, origin);
|
|
3922
|
+
if (newSel && !view.state.selection.eq(newSel)) {
|
|
3923
|
+
if (chrome && android && view.input.lastKeyCode === 13 && Date.now() - 100 < view.input.lastKeyCodeTime && view.someProp("handleKeyDown", (f) => f(view, keyEvent(13, "Enter")))) return;
|
|
3924
|
+
let tr = view.state.tr.setSelection(newSel);
|
|
3925
|
+
if (origin == "pointer") tr.setMeta("pointer", true);
|
|
3926
|
+
else if (origin == "key") tr.scrollIntoView();
|
|
3927
|
+
if (compositionID) tr.setMeta("composition", compositionID);
|
|
3928
|
+
view.dispatch(tr);
|
|
3929
|
+
}
|
|
3930
|
+
return;
|
|
3931
|
+
}
|
|
3932
|
+
let $before = view.state.doc.resolve(from);
|
|
3933
|
+
let shared = $before.sharedDepth(to);
|
|
3934
|
+
from = $before.before(shared + 1);
|
|
3935
|
+
to = view.state.doc.resolve(to).after(shared + 1);
|
|
3936
|
+
let sel = view.state.selection;
|
|
3937
|
+
let parse = parseBetween(view, from, to);
|
|
3938
|
+
let doc = view.state.doc, compare = doc.slice(parse.from, parse.to);
|
|
3939
|
+
let preferredPos, preferredSide;
|
|
3940
|
+
if (view.input.lastKeyCode === 8 && Date.now() - 100 < view.input.lastKeyCodeTime) {
|
|
3941
|
+
preferredPos = view.state.selection.to;
|
|
3942
|
+
preferredSide = "end";
|
|
3943
|
+
} else {
|
|
3944
|
+
preferredPos = view.state.selection.from;
|
|
3945
|
+
preferredSide = "start";
|
|
3946
|
+
}
|
|
3947
|
+
view.input.lastKeyCode = null;
|
|
3948
|
+
let change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide);
|
|
3949
|
+
if (change) view.input.domChangeCount++;
|
|
3950
|
+
if ((ios && view.input.lastIOSEnter > Date.now() - 225 || android) && addedNodes.some((n) => n.nodeType == 1 && !isInline.test(n.nodeName)) && (!change || change.endA >= change.endB) && view.someProp("handleKeyDown", (f) => f(view, keyEvent(13, "Enter")))) {
|
|
3951
|
+
view.input.lastIOSEnter = 0;
|
|
3952
|
+
return;
|
|
3953
|
+
}
|
|
3954
|
+
if (!change) if (typeOver && sel instanceof require_dist.TextSelection && !sel.empty && sel.$head.sameParent(sel.$anchor) && !view.composing && !(parse.sel && parse.sel.anchor != parse.sel.head)) change = {
|
|
3955
|
+
start: sel.from,
|
|
3956
|
+
endA: sel.to,
|
|
3957
|
+
endB: sel.to
|
|
3958
|
+
};
|
|
3959
|
+
else {
|
|
3960
|
+
if (parse.sel) {
|
|
3961
|
+
let sel = resolveSelection(view, view.state.doc, parse.sel);
|
|
3962
|
+
if (sel && !sel.eq(view.state.selection)) {
|
|
3963
|
+
let tr = view.state.tr.setSelection(sel);
|
|
3964
|
+
if (compositionID) tr.setMeta("composition", compositionID);
|
|
3965
|
+
view.dispatch(tr);
|
|
3966
|
+
}
|
|
3967
|
+
}
|
|
3968
|
+
return;
|
|
3969
|
+
}
|
|
3970
|
+
if (view.state.selection.from < view.state.selection.to && change.start == change.endB && view.state.selection instanceof require_dist.TextSelection) {
|
|
3971
|
+
if (change.start > view.state.selection.from && change.start <= view.state.selection.from + 2 && view.state.selection.from >= parse.from) change.start = view.state.selection.from;
|
|
3972
|
+
else if (change.endA < view.state.selection.to && change.endA >= view.state.selection.to - 2 && view.state.selection.to <= parse.to) {
|
|
3973
|
+
change.endB += view.state.selection.to - change.endA;
|
|
3974
|
+
change.endA = view.state.selection.to;
|
|
3975
|
+
}
|
|
3976
|
+
}
|
|
3977
|
+
if (ie && 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") {
|
|
3978
|
+
change.start--;
|
|
3979
|
+
change.endA--;
|
|
3980
|
+
change.endB--;
|
|
3981
|
+
}
|
|
3982
|
+
let $from = parse.doc.resolveNoCache(change.start - parse.from);
|
|
3983
|
+
let $to = parse.doc.resolveNoCache(change.endB - parse.from);
|
|
3984
|
+
let $fromA = doc.resolve(change.start);
|
|
3985
|
+
let inlineChange = $from.sameParent($to) && $from.parent.inlineContent && $fromA.end() >= change.endA;
|
|
3986
|
+
if ((ios && view.input.lastIOSEnter > Date.now() - 225 && (!inlineChange || addedNodes.some((n) => n.nodeName == "DIV" || n.nodeName == "P")) || !inlineChange && $from.pos < parse.doc.content.size && (!$from.sameParent($to) || !$from.parent.inlineContent) && $from.pos < $to.pos && !/\S/.test(parse.doc.textBetween($from.pos, $to.pos, "", ""))) && view.someProp("handleKeyDown", (f) => f(view, keyEvent(13, "Enter")))) {
|
|
3987
|
+
view.input.lastIOSEnter = 0;
|
|
3988
|
+
return;
|
|
3989
|
+
}
|
|
3990
|
+
if (view.state.selection.anchor > change.start && looksLikeBackspace(doc, change.start, change.endA, $from, $to) && view.someProp("handleKeyDown", (f) => f(view, keyEvent(8, "Backspace")))) {
|
|
3991
|
+
if (android && chrome) view.domObserver.suppressSelectionUpdates();
|
|
3992
|
+
return;
|
|
3993
|
+
}
|
|
3994
|
+
if (chrome && change.endB == change.start) view.input.lastChromeDelete = Date.now();
|
|
3995
|
+
if (android && !inlineChange && $from.start() != $to.start() && $to.parentOffset == 0 && $from.depth == $to.depth && parse.sel && parse.sel.anchor == parse.sel.head && parse.sel.head == change.endA) {
|
|
3996
|
+
change.endB -= 2;
|
|
3997
|
+
$to = parse.doc.resolveNoCache(change.endB - parse.from);
|
|
3998
|
+
setTimeout(() => {
|
|
3999
|
+
view.someProp("handleKeyDown", function(f) {
|
|
4000
|
+
return f(view, keyEvent(13, "Enter"));
|
|
4001
|
+
});
|
|
4002
|
+
}, 20);
|
|
4003
|
+
}
|
|
4004
|
+
let chFrom = change.start, chTo = change.endA;
|
|
4005
|
+
let mkTr = (base) => {
|
|
4006
|
+
let tr = base || view.state.tr.replace(chFrom, chTo, parse.doc.slice(change.start - parse.from, change.endB - parse.from));
|
|
4007
|
+
if (parse.sel) {
|
|
4008
|
+
let sel = resolveSelection(view, tr.doc, parse.sel);
|
|
4009
|
+
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) || ie && sel.empty && sel.head == chFrom)) tr.setSelection(sel);
|
|
4010
|
+
}
|
|
4011
|
+
if (compositionID) tr.setMeta("composition", compositionID);
|
|
4012
|
+
return tr.scrollIntoView();
|
|
4013
|
+
};
|
|
4014
|
+
let markChange;
|
|
4015
|
+
if (inlineChange) if ($from.pos == $to.pos) {
|
|
4016
|
+
if (ie && ie_version <= 11 && $from.parentOffset == 0) {
|
|
4017
|
+
view.domObserver.suppressSelectionUpdates();
|
|
4018
|
+
setTimeout(() => selectionToDOM(view), 20);
|
|
4019
|
+
}
|
|
4020
|
+
let tr = mkTr(view.state.tr.delete(chFrom, chTo));
|
|
4021
|
+
let marks = doc.resolve(change.start).marksAcross(doc.resolve(change.endA));
|
|
4022
|
+
if (marks) tr.ensureMarks(marks);
|
|
4023
|
+
view.dispatch(tr);
|
|
4024
|
+
} else if (change.endA == change.endB && (markChange = isMarkChange($from.parent.content.cut($from.parentOffset, $to.parentOffset), $fromA.parent.content.cut($fromA.parentOffset, change.endA - $fromA.start())))) {
|
|
4025
|
+
let tr = mkTr(view.state.tr);
|
|
4026
|
+
if (markChange.type == "add") tr.addMark(chFrom, chTo, markChange.mark);
|
|
4027
|
+
else tr.removeMark(chFrom, chTo, markChange.mark);
|
|
4028
|
+
view.dispatch(tr);
|
|
4029
|
+
} else if ($from.parent.child($from.index()).isText && $from.index() == $to.index() - ($to.textOffset ? 0 : 1)) {
|
|
4030
|
+
let text = $from.parent.textBetween($from.parentOffset, $to.parentOffset);
|
|
4031
|
+
let deflt = () => mkTr(view.state.tr.insertText(text, chFrom, chTo));
|
|
4032
|
+
if (!view.someProp("handleTextInput", (f) => f(view, chFrom, chTo, text, deflt))) view.dispatch(deflt());
|
|
4033
|
+
} else view.dispatch(mkTr());
|
|
4034
|
+
else view.dispatch(mkTr());
|
|
4035
|
+
}
|
|
4036
|
+
function resolveSelection(view, doc, parsedSel) {
|
|
4037
|
+
if (Math.max(parsedSel.anchor, parsedSel.head) > doc.content.size) return null;
|
|
4038
|
+
return selectionBetween(view, doc.resolve(parsedSel.anchor), doc.resolve(parsedSel.head));
|
|
4039
|
+
}
|
|
4040
|
+
function isMarkChange(cur, prev) {
|
|
4041
|
+
let curMarks = cur.firstChild.marks, prevMarks = prev.firstChild.marks;
|
|
4042
|
+
let added = curMarks, removed = prevMarks, type, mark, update;
|
|
4043
|
+
for (let i = 0; i < prevMarks.length; i++) added = prevMarks[i].removeFromSet(added);
|
|
4044
|
+
for (let i = 0; i < curMarks.length; i++) removed = curMarks[i].removeFromSet(removed);
|
|
4045
|
+
if (added.length == 1 && removed.length == 0) {
|
|
4046
|
+
mark = added[0];
|
|
4047
|
+
type = "add";
|
|
4048
|
+
update = (node) => node.mark(mark.addToSet(node.marks));
|
|
4049
|
+
} else if (added.length == 0 && removed.length == 1) {
|
|
4050
|
+
mark = removed[0];
|
|
4051
|
+
type = "remove";
|
|
4052
|
+
update = (node) => node.mark(mark.removeFromSet(node.marks));
|
|
4053
|
+
} else return null;
|
|
4054
|
+
let updated = [];
|
|
4055
|
+
for (let i = 0; i < prev.childCount; i++) updated.push(update(prev.child(i)));
|
|
4056
|
+
if (require_dist.Fragment.from(updated).eq(cur)) return {
|
|
4057
|
+
mark,
|
|
4058
|
+
type
|
|
4059
|
+
};
|
|
4060
|
+
}
|
|
4061
|
+
function looksLikeBackspace(old, start, end, $newStart, $newEnd) {
|
|
4062
|
+
if (end - start <= $newEnd.pos - $newStart.pos || skipClosingAndOpening($newStart, true, false) < $newEnd.pos) return false;
|
|
4063
|
+
let $start = old.resolve(start);
|
|
4064
|
+
if (!$newStart.parent.isTextblock) {
|
|
4065
|
+
let after = $start.nodeAfter;
|
|
4066
|
+
return after != null && end == start + after.nodeSize;
|
|
4067
|
+
}
|
|
4068
|
+
if ($start.parentOffset < $start.parent.content.size || !$start.parent.isTextblock) return false;
|
|
4069
|
+
let $next = old.resolve(skipClosingAndOpening($start, true, true));
|
|
4070
|
+
if (!$next.parent.isTextblock || $next.pos > end || skipClosingAndOpening($next, true, false) < end) return false;
|
|
4071
|
+
return $newStart.parent.content.cut($newStart.parentOffset).eq($next.parent.content);
|
|
4072
|
+
}
|
|
4073
|
+
function skipClosingAndOpening($pos, fromEnd, mayOpen) {
|
|
4074
|
+
let depth = $pos.depth, end = fromEnd ? $pos.end() : $pos.pos;
|
|
4075
|
+
while (depth > 0 && (fromEnd || $pos.indexAfter(depth) == $pos.node(depth).childCount)) {
|
|
4076
|
+
depth--;
|
|
4077
|
+
end++;
|
|
4078
|
+
fromEnd = false;
|
|
4079
|
+
}
|
|
4080
|
+
if (mayOpen) {
|
|
4081
|
+
let next = $pos.node(depth).maybeChild($pos.indexAfter(depth));
|
|
4082
|
+
while (next && !next.isLeaf) {
|
|
4083
|
+
next = next.firstChild;
|
|
4084
|
+
end++;
|
|
4085
|
+
}
|
|
4086
|
+
}
|
|
4087
|
+
return end;
|
|
4088
|
+
}
|
|
4089
|
+
function findDiff(a, b, pos, preferredPos, preferredSide) {
|
|
4090
|
+
let start = a.findDiffStart(b, pos), lenA = pos + a.size, lenB = pos + b.size;
|
|
4091
|
+
if (start == null) return null;
|
|
4092
|
+
let { a: endA, b: endB } = a.findDiffEnd(b, lenA, lenB);
|
|
4093
|
+
if (preferredSide == "end") {
|
|
4094
|
+
let adjust = Math.max(0, start - Math.min(endA, endB));
|
|
4095
|
+
preferredPos -= endA + adjust - start;
|
|
4096
|
+
}
|
|
4097
|
+
if (endA < start && lenA < lenB) {
|
|
4098
|
+
let move = preferredPos <= start && preferredPos >= endA ? start - preferredPos : 0;
|
|
4099
|
+
start -= move;
|
|
4100
|
+
endB = start + (endB - endA);
|
|
4101
|
+
endA = start;
|
|
4102
|
+
} else if (endB < start) {
|
|
4103
|
+
let move = preferredPos <= start && preferredPos >= endB ? start - preferredPos : 0;
|
|
4104
|
+
start -= move;
|
|
4105
|
+
endA = start + (endA - endB);
|
|
4106
|
+
endB = start;
|
|
4107
|
+
}
|
|
4108
|
+
return {
|
|
4109
|
+
start,
|
|
4110
|
+
endA,
|
|
4111
|
+
endB
|
|
4112
|
+
};
|
|
4113
|
+
}
|
|
4114
|
+
/**
|
|
4115
|
+
An editor view manages the DOM structure that represents an
|
|
4116
|
+
editable document. Its state and behavior are determined by its
|
|
4117
|
+
[props](https://prosemirror.net/docs/ref/#view.DirectEditorProps).
|
|
4118
|
+
*/
|
|
4119
|
+
var EditorView = class {
|
|
4120
|
+
/**
|
|
4121
|
+
Create a view. `place` may be a DOM node that the editor should
|
|
4122
|
+
be appended to, a function that will place it into the document,
|
|
4123
|
+
or an object whose `mount` property holds the node to use as the
|
|
4124
|
+
document container. If it is `null`, the editor will not be
|
|
4125
|
+
added to the document.
|
|
4126
|
+
*/
|
|
4127
|
+
constructor(place, props) {
|
|
4128
|
+
this._root = null;
|
|
4129
|
+
/**
|
|
4130
|
+
@internal
|
|
4131
|
+
*/
|
|
4132
|
+
this.focused = false;
|
|
4133
|
+
/**
|
|
4134
|
+
Kludge used to work around a Chrome bug @internal
|
|
4135
|
+
*/
|
|
4136
|
+
this.trackWrites = null;
|
|
4137
|
+
this.mounted = false;
|
|
4138
|
+
/**
|
|
4139
|
+
@internal
|
|
4140
|
+
*/
|
|
4141
|
+
this.markCursor = null;
|
|
4142
|
+
/**
|
|
4143
|
+
@internal
|
|
4144
|
+
*/
|
|
4145
|
+
this.cursorWrapper = null;
|
|
4146
|
+
/**
|
|
4147
|
+
@internal
|
|
4148
|
+
*/
|
|
4149
|
+
this.lastSelectedViewDesc = void 0;
|
|
4150
|
+
/**
|
|
4151
|
+
@internal
|
|
4152
|
+
*/
|
|
4153
|
+
this.input = new InputState();
|
|
4154
|
+
this.prevDirectPlugins = [];
|
|
4155
|
+
this.pluginViews = [];
|
|
4156
|
+
/**
|
|
4157
|
+
Holds `true` when a hack node is needed in Firefox to prevent the
|
|
4158
|
+
[space is eaten issue](https://code.haverbeke.berlin/prosemirror/prosemirror/issues/651)
|
|
4159
|
+
@internal
|
|
4160
|
+
*/
|
|
4161
|
+
this.requiresGeckoHackNode = false;
|
|
4162
|
+
/**
|
|
4163
|
+
When editor content is being dragged, this object contains
|
|
4164
|
+
information about the dragged slice and whether it is being
|
|
4165
|
+
copied or moved. At any other time, it is null.
|
|
4166
|
+
*/
|
|
4167
|
+
this.dragging = null;
|
|
4168
|
+
this._props = props;
|
|
4169
|
+
this.state = props.state;
|
|
4170
|
+
this.directPlugins = props.plugins || [];
|
|
4171
|
+
this.directPlugins.forEach(checkStateComponent);
|
|
4172
|
+
this.dispatch = this.dispatch.bind(this);
|
|
4173
|
+
this.dom = place && place.mount || document.createElement("div");
|
|
4174
|
+
if (place) {
|
|
4175
|
+
if (place.appendChild) place.appendChild(this.dom);
|
|
4176
|
+
else if (typeof place == "function") place(this.dom);
|
|
4177
|
+
else if (place.mount) this.mounted = true;
|
|
4178
|
+
}
|
|
4179
|
+
this.editable = getEditable(this);
|
|
4180
|
+
updateCursorWrapper(this);
|
|
4181
|
+
this.nodeViews = buildNodeViews(this);
|
|
4182
|
+
this.docView = docViewDesc(this.state.doc, computeDocDeco(this), viewDecorations(this), this.dom, this);
|
|
4183
|
+
this.domObserver = new DOMObserver(this, (from, to, typeOver, added) => readDOMChange(this, from, to, typeOver, added));
|
|
4184
|
+
this.domObserver.start();
|
|
4185
|
+
initInput(this);
|
|
4186
|
+
this.updatePluginViews();
|
|
4187
|
+
}
|
|
4188
|
+
/**
|
|
4189
|
+
Holds `true` when a
|
|
4190
|
+
[composition](https://w3c.github.io/uievents/#events-compositionevents)
|
|
4191
|
+
is active.
|
|
4192
|
+
*/
|
|
4193
|
+
get composing() {
|
|
4194
|
+
return this.input.composing;
|
|
4195
|
+
}
|
|
4196
|
+
/**
|
|
4197
|
+
The view's current [props](https://prosemirror.net/docs/ref/#view.EditorProps).
|
|
4198
|
+
*/
|
|
4199
|
+
get props() {
|
|
4200
|
+
if (this._props.state != this.state) {
|
|
4201
|
+
let prev = this._props;
|
|
4202
|
+
this._props = {};
|
|
4203
|
+
for (let name in prev) this._props[name] = prev[name];
|
|
4204
|
+
this._props.state = this.state;
|
|
4205
|
+
}
|
|
4206
|
+
return this._props;
|
|
4207
|
+
}
|
|
4208
|
+
/**
|
|
4209
|
+
Update the view's props. Will immediately cause an update to
|
|
4210
|
+
the DOM.
|
|
4211
|
+
*/
|
|
4212
|
+
update(props) {
|
|
4213
|
+
if (props.handleDOMEvents != this._props.handleDOMEvents) ensureListeners(this);
|
|
4214
|
+
let prevProps = this._props;
|
|
4215
|
+
this._props = props;
|
|
4216
|
+
if (props.plugins) {
|
|
4217
|
+
props.plugins.forEach(checkStateComponent);
|
|
4218
|
+
this.directPlugins = props.plugins;
|
|
4219
|
+
}
|
|
4220
|
+
this.updateStateInner(props.state, prevProps);
|
|
4221
|
+
}
|
|
4222
|
+
/**
|
|
4223
|
+
Update the view by updating existing props object with the object
|
|
4224
|
+
given as argument. Equivalent to `view.update(Object.assign({},
|
|
4225
|
+
view.props, props))`.
|
|
4226
|
+
*/
|
|
4227
|
+
setProps(props) {
|
|
4228
|
+
let updated = {};
|
|
4229
|
+
for (let name in this._props) updated[name] = this._props[name];
|
|
4230
|
+
updated.state = this.state;
|
|
4231
|
+
for (let name in props) updated[name] = props[name];
|
|
4232
|
+
this.update(updated);
|
|
4233
|
+
}
|
|
4234
|
+
/**
|
|
4235
|
+
Update the editor's `state` prop, without touching any of the
|
|
4236
|
+
other props.
|
|
4237
|
+
*/
|
|
4238
|
+
updateState(state) {
|
|
4239
|
+
this.updateStateInner(state, this._props);
|
|
4240
|
+
}
|
|
4241
|
+
updateStateInner(state, prevProps) {
|
|
4242
|
+
var _a;
|
|
4243
|
+
let prev = this.state, redraw = false, updateSel = false;
|
|
4244
|
+
if (state.storedMarks && this.composing) {
|
|
4245
|
+
clearComposition(this);
|
|
4246
|
+
updateSel = true;
|
|
4247
|
+
}
|
|
4248
|
+
this.state = state;
|
|
4249
|
+
let pluginsChanged = prev.plugins != state.plugins || this._props.plugins != prevProps.plugins;
|
|
4250
|
+
if (pluginsChanged || this._props.plugins != prevProps.plugins || this._props.nodeViews != prevProps.nodeViews) {
|
|
4251
|
+
let nodeViews = buildNodeViews(this);
|
|
4252
|
+
if (changedNodeViews(nodeViews, this.nodeViews)) {
|
|
4253
|
+
this.nodeViews = nodeViews;
|
|
4254
|
+
redraw = true;
|
|
4255
|
+
}
|
|
4256
|
+
}
|
|
4257
|
+
if (pluginsChanged || prevProps.handleDOMEvents != this._props.handleDOMEvents) ensureListeners(this);
|
|
4258
|
+
this.editable = getEditable(this);
|
|
4259
|
+
updateCursorWrapper(this);
|
|
4260
|
+
let innerDeco = viewDecorations(this), outerDeco = computeDocDeco(this);
|
|
4261
|
+
let scroll = prev.plugins != state.plugins && !prev.doc.eq(state.doc) ? "reset" : state.scrollToSelection > prev.scrollToSelection ? "to selection" : "preserve";
|
|
4262
|
+
let updateDoc = redraw || !this.docView.matchesNode(state.doc, outerDeco, innerDeco);
|
|
4263
|
+
if (updateDoc || !state.selection.eq(prev.selection)) updateSel = true;
|
|
4264
|
+
let oldScrollPos = scroll == "preserve" && updateSel && this.dom.style.overflowAnchor == null && storeScrollPos(this);
|
|
4265
|
+
if (updateSel) {
|
|
4266
|
+
this.domObserver.stop();
|
|
4267
|
+
let forceSelUpdate = updateDoc && (ie || chrome) && !this.composing && !prev.selection.empty && !state.selection.empty && selectionContextChanged(prev.selection, state.selection);
|
|
4268
|
+
if (updateDoc) {
|
|
4269
|
+
let chromeKludge = chrome ? this.trackWrites = this.domSelectionRange().focusNode : null;
|
|
4270
|
+
if (this.composing) this.input.compositionNode = findCompositionNode(this);
|
|
4271
|
+
if (redraw || !this.docView.update(state.doc, outerDeco, innerDeco, this)) {
|
|
4272
|
+
this.docView.updateOuterDeco(outerDeco);
|
|
4273
|
+
this.docView.destroy();
|
|
4274
|
+
this.docView = docViewDesc(state.doc, outerDeco, innerDeco, this.dom, this);
|
|
4275
|
+
}
|
|
4276
|
+
if (chromeKludge && (!this.trackWrites || !this.dom.contains(this.trackWrites))) forceSelUpdate = true;
|
|
4277
|
+
}
|
|
4278
|
+
let mouseDown = this.input.mouseDown;
|
|
4279
|
+
if (forceSelUpdate || !(mouseDown && this.domObserver.currentSelection.eq(this.domSelectionRange()) && anchorInRightPlace(this) && mouseDown.delaySelUpdate())) selectionToDOM(this, forceSelUpdate);
|
|
4280
|
+
else {
|
|
4281
|
+
syncNodeSelection(this, state.selection);
|
|
4282
|
+
this.domObserver.setCurSelection();
|
|
4283
|
+
}
|
|
4284
|
+
this.domObserver.start();
|
|
4285
|
+
}
|
|
4286
|
+
this.updatePluginViews(prev);
|
|
4287
|
+
if (((_a = this.dragging) === null || _a === void 0 ? void 0 : _a.node) && !prev.doc.eq(state.doc)) this.updateDraggedNode(this.dragging, prev);
|
|
4288
|
+
if (scroll == "reset") this.dom.scrollTop = 0;
|
|
4289
|
+
else if (scroll == "to selection") this.scrollToSelection();
|
|
4290
|
+
else if (oldScrollPos) resetScrollPos(oldScrollPos);
|
|
4291
|
+
}
|
|
4292
|
+
/**
|
|
4293
|
+
@internal
|
|
4294
|
+
*/
|
|
4295
|
+
scrollToSelection() {
|
|
4296
|
+
let startDOM = this.domSelectionRange().focusNode;
|
|
4297
|
+
if (!startDOM || !this.dom.contains(startDOM.nodeType == 1 ? startDOM : startDOM.parentNode));
|
|
4298
|
+
else if (this.someProp("handleScrollToSelection", (f) => f(this)));
|
|
4299
|
+
else if (this.state.selection instanceof require_dist.NodeSelection) {
|
|
4300
|
+
let target = this.docView.domAfterPos(this.state.selection.from);
|
|
4301
|
+
if (target.nodeType == 1) scrollRectIntoView(this, target.getBoundingClientRect(), startDOM);
|
|
4302
|
+
} else scrollRectIntoView(this, this.coordsAtPos(this.state.selection.head, 1), startDOM);
|
|
4303
|
+
}
|
|
4304
|
+
destroyPluginViews() {
|
|
4305
|
+
let view;
|
|
4306
|
+
while (view = this.pluginViews.pop()) if (view.destroy) view.destroy();
|
|
4307
|
+
}
|
|
4308
|
+
updatePluginViews(prevState) {
|
|
4309
|
+
if (!prevState || prevState.plugins != this.state.plugins || this.directPlugins != this.prevDirectPlugins) {
|
|
4310
|
+
this.prevDirectPlugins = this.directPlugins;
|
|
4311
|
+
this.destroyPluginViews();
|
|
4312
|
+
for (let i = 0; i < this.directPlugins.length; i++) {
|
|
4313
|
+
let plugin = this.directPlugins[i];
|
|
4314
|
+
if (plugin.spec.view) this.pluginViews.push(plugin.spec.view(this));
|
|
4315
|
+
}
|
|
4316
|
+
for (let i = 0; i < this.state.plugins.length; i++) {
|
|
4317
|
+
let plugin = this.state.plugins[i];
|
|
4318
|
+
if (plugin.spec.view) this.pluginViews.push(plugin.spec.view(this));
|
|
4319
|
+
}
|
|
4320
|
+
} else for (let i = 0; i < this.pluginViews.length; i++) {
|
|
4321
|
+
let pluginView = this.pluginViews[i];
|
|
4322
|
+
if (pluginView.update) pluginView.update(this, prevState);
|
|
4323
|
+
}
|
|
4324
|
+
}
|
|
4325
|
+
updateDraggedNode(dragging, prev) {
|
|
4326
|
+
let sel = dragging.node, found = -1;
|
|
4327
|
+
if (sel.from < this.state.doc.content.size && this.state.doc.nodeAt(sel.from) == sel.node) found = sel.from;
|
|
4328
|
+
else {
|
|
4329
|
+
let movedPos = sel.from + (this.state.doc.content.size - prev.doc.content.size);
|
|
4330
|
+
if ((movedPos > 0 && movedPos < this.state.doc.content.size && this.state.doc.nodeAt(movedPos)) == sel.node) found = movedPos;
|
|
4331
|
+
}
|
|
4332
|
+
this.dragging = new Dragging(dragging.slice, dragging.move, found < 0 ? void 0 : require_dist.NodeSelection.create(this.state.doc, found));
|
|
4333
|
+
}
|
|
4334
|
+
someProp(propName, f) {
|
|
4335
|
+
let prop = this._props && this._props[propName], value;
|
|
4336
|
+
if (prop != null && (value = f ? f(prop) : prop)) return value;
|
|
4337
|
+
for (let i = 0; i < this.directPlugins.length; i++) {
|
|
4338
|
+
let prop = this.directPlugins[i].props[propName];
|
|
4339
|
+
if (prop != null && (value = f ? f(prop) : prop)) return value;
|
|
4340
|
+
}
|
|
4341
|
+
let plugins = this.state.plugins;
|
|
4342
|
+
if (plugins) for (let i = 0; i < plugins.length; i++) {
|
|
4343
|
+
let prop = plugins[i].props[propName];
|
|
4344
|
+
if (prop != null && (value = f ? f(prop) : prop)) return value;
|
|
4345
|
+
}
|
|
4346
|
+
}
|
|
4347
|
+
/**
|
|
4348
|
+
Query whether the view has focus.
|
|
4349
|
+
*/
|
|
4350
|
+
hasFocus() {
|
|
4351
|
+
if (ie) {
|
|
4352
|
+
let node = this.root.activeElement;
|
|
4353
|
+
if (node == this.dom) return true;
|
|
4354
|
+
if (!node || !this.dom.contains(node)) return false;
|
|
4355
|
+
while (node && this.dom != node && this.dom.contains(node)) {
|
|
4356
|
+
if (node.contentEditable == "false") return false;
|
|
4357
|
+
node = node.parentElement;
|
|
4358
|
+
}
|
|
4359
|
+
return true;
|
|
4360
|
+
}
|
|
4361
|
+
return this.root.activeElement == this.dom;
|
|
4362
|
+
}
|
|
4363
|
+
/**
|
|
4364
|
+
Focus the editor.
|
|
4365
|
+
*/
|
|
4366
|
+
focus() {
|
|
4367
|
+
this.domObserver.stop();
|
|
4368
|
+
if (this.editable) focusPreventScroll(this.dom);
|
|
4369
|
+
selectionToDOM(this);
|
|
4370
|
+
this.domObserver.start();
|
|
4371
|
+
}
|
|
4372
|
+
/**
|
|
4373
|
+
Get the document root in which the editor exists. This will
|
|
4374
|
+
usually be the top-level `document`, but might be a [shadow
|
|
4375
|
+
DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM)
|
|
4376
|
+
root if the editor is inside one.
|
|
4377
|
+
*/
|
|
4378
|
+
get root() {
|
|
4379
|
+
let cached = this._root;
|
|
4380
|
+
if (cached == null) {
|
|
4381
|
+
for (let search = this.dom.parentNode; search; search = search.parentNode) if (search.nodeType == 9 || search.nodeType == 11 && search.host) {
|
|
4382
|
+
if (!search.getSelection) Object.getPrototypeOf(search).getSelection = () => search.ownerDocument.getSelection();
|
|
4383
|
+
return this._root = search;
|
|
4384
|
+
}
|
|
4385
|
+
}
|
|
4386
|
+
return cached || document;
|
|
4387
|
+
}
|
|
4388
|
+
/**
|
|
4389
|
+
When an existing editor view is moved to a new document or
|
|
4390
|
+
shadow tree, call this to make it recompute its root.
|
|
4391
|
+
*/
|
|
4392
|
+
updateRoot() {
|
|
4393
|
+
this._root = null;
|
|
4394
|
+
}
|
|
4395
|
+
/**
|
|
4396
|
+
Given a pair of viewport coordinates, return the document
|
|
4397
|
+
position that corresponds to them. May return null if the given
|
|
4398
|
+
coordinates aren't inside of the editor. When an object is
|
|
4399
|
+
returned, its `pos` property is the position nearest to the
|
|
4400
|
+
coordinates, and its `inside` property holds the position of the
|
|
4401
|
+
inner node that the position falls inside of, or -1 if it is at
|
|
4402
|
+
the top level, not in any node.
|
|
4403
|
+
*/
|
|
4404
|
+
posAtCoords(coords) {
|
|
4405
|
+
return posAtCoords(this, coords);
|
|
4406
|
+
}
|
|
4407
|
+
/**
|
|
4408
|
+
Returns the viewport rectangle at a given document position.
|
|
4409
|
+
`left` and `right` will be the same number, as this returns a
|
|
4410
|
+
flat cursor-ish rectangle. If the position is between two things
|
|
4411
|
+
that aren't directly adjacent, `side` determines which element
|
|
4412
|
+
is used. When < 0, the element before the position is used,
|
|
4413
|
+
otherwise the element after.
|
|
4414
|
+
*/
|
|
4415
|
+
coordsAtPos(pos, side = 1) {
|
|
4416
|
+
return coordsAtPos(this, pos, side);
|
|
4417
|
+
}
|
|
4418
|
+
/**
|
|
4419
|
+
Find the DOM position that corresponds to the given document
|
|
4420
|
+
position. When `side` is negative, find the position as close as
|
|
4421
|
+
possible to the content before the position. When positive,
|
|
4422
|
+
prefer positions close to the content after the position. When
|
|
4423
|
+
zero, prefer as shallow a position as possible.
|
|
4424
|
+
|
|
4425
|
+
Note that you should **not** mutate the editor's internal DOM,
|
|
4426
|
+
only inspect it (and even that is usually not necessary).
|
|
4427
|
+
*/
|
|
4428
|
+
domAtPos(pos, side = 0) {
|
|
4429
|
+
return this.docView.domFromPos(pos, side);
|
|
4430
|
+
}
|
|
4431
|
+
/**
|
|
4432
|
+
Find the DOM node that represents the document node after the
|
|
4433
|
+
given position. May return `null` when the position doesn't point
|
|
4434
|
+
in front of a node or if the node is inside an opaque node view.
|
|
4435
|
+
|
|
4436
|
+
This is intended to be able to call things like
|
|
4437
|
+
`getBoundingClientRect` on that DOM node. Do **not** mutate the
|
|
4438
|
+
editor DOM directly, or add styling this way, since that will be
|
|
4439
|
+
immediately overriden by the editor as it redraws the node.
|
|
4440
|
+
*/
|
|
4441
|
+
nodeDOM(pos) {
|
|
4442
|
+
let desc = this.docView.descAt(pos);
|
|
4443
|
+
return desc ? desc.nodeDOM : null;
|
|
4444
|
+
}
|
|
4445
|
+
/**
|
|
4446
|
+
Find the document position that corresponds to a given DOM
|
|
4447
|
+
position. (Whenever possible, it is preferable to inspect the
|
|
4448
|
+
document structure directly, rather than poking around in the
|
|
4449
|
+
DOM, but sometimes—for example when interpreting an event
|
|
4450
|
+
target—you don't have a choice.)
|
|
4451
|
+
|
|
4452
|
+
The `bias` parameter can be used to influence which side of a DOM
|
|
4453
|
+
node to use when the position is inside a leaf node.
|
|
4454
|
+
*/
|
|
4455
|
+
posAtDOM(node, offset, bias = -1) {
|
|
4456
|
+
let pos = this.docView.posFromDOM(node, offset, bias);
|
|
4457
|
+
if (pos == null) throw new RangeError("DOM position not inside the editor");
|
|
4458
|
+
return pos;
|
|
4459
|
+
}
|
|
4460
|
+
/**
|
|
4461
|
+
Find out whether the selection is at the end of a textblock when
|
|
4462
|
+
moving in a given direction. When, for example, given `"left"`,
|
|
4463
|
+
it will return true if moving left from the current cursor
|
|
4464
|
+
position would leave that position's parent textblock. Will apply
|
|
4465
|
+
to the view's current state by default, but it is possible to
|
|
4466
|
+
pass a different state.
|
|
4467
|
+
*/
|
|
4468
|
+
endOfTextblock(dir, state) {
|
|
4469
|
+
return endOfTextblock(this, state || this.state, dir);
|
|
4470
|
+
}
|
|
4471
|
+
/**
|
|
4472
|
+
Run the editor's paste logic with the given HTML string. The
|
|
4473
|
+
`event`, if given, will be passed to the
|
|
4474
|
+
[`handlePaste`](https://prosemirror.net/docs/ref/#view.EditorProps.handlePaste) hook.
|
|
4475
|
+
*/
|
|
4476
|
+
pasteHTML(html, event) {
|
|
4477
|
+
return doPaste(this, "", html, false, event || new ClipboardEvent("paste"));
|
|
4478
|
+
}
|
|
4479
|
+
/**
|
|
4480
|
+
Run the editor's paste logic with the given plain-text input.
|
|
4481
|
+
*/
|
|
4482
|
+
pasteText(text, event) {
|
|
4483
|
+
return doPaste(this, text, null, true, event || new ClipboardEvent("paste"));
|
|
4484
|
+
}
|
|
4485
|
+
/**
|
|
4486
|
+
Serialize the given slice as it would be if it was copied from
|
|
4487
|
+
this editor. Returns a DOM element that contains a
|
|
4488
|
+
representation of the slice as its children, a textual
|
|
4489
|
+
representation, and the transformed slice (which can be
|
|
4490
|
+
different from the given input due to hooks like
|
|
4491
|
+
[`transformCopied`](https://prosemirror.net/docs/ref/#view.EditorProps.transformCopied)).
|
|
4492
|
+
*/
|
|
4493
|
+
serializeForClipboard(slice) {
|
|
4494
|
+
return serializeForClipboard(this, slice);
|
|
4495
|
+
}
|
|
4496
|
+
/**
|
|
4497
|
+
Removes the editor from the DOM and destroys all [node
|
|
4498
|
+
views](https://prosemirror.net/docs/ref/#view.NodeView).
|
|
4499
|
+
*/
|
|
4500
|
+
destroy() {
|
|
4501
|
+
if (!this.docView) return;
|
|
4502
|
+
destroyInput(this);
|
|
4503
|
+
this.destroyPluginViews();
|
|
4504
|
+
if (this.mounted) {
|
|
4505
|
+
this.docView.update(this.state.doc, [], viewDecorations(this), this);
|
|
4506
|
+
this.dom.textContent = "";
|
|
4507
|
+
} else if (this.dom.parentNode) this.dom.parentNode.removeChild(this.dom);
|
|
4508
|
+
this.docView.destroy();
|
|
4509
|
+
this.docView = null;
|
|
4510
|
+
clearReusedRange();
|
|
4511
|
+
}
|
|
4512
|
+
/**
|
|
4513
|
+
This is true when the view has been
|
|
4514
|
+
[destroyed](https://prosemirror.net/docs/ref/#view.EditorView.destroy) (and thus should not be
|
|
4515
|
+
used anymore).
|
|
4516
|
+
*/
|
|
4517
|
+
get isDestroyed() {
|
|
4518
|
+
return this.docView == null;
|
|
4519
|
+
}
|
|
4520
|
+
/**
|
|
4521
|
+
Used for testing.
|
|
4522
|
+
*/
|
|
4523
|
+
dispatchEvent(event) {
|
|
4524
|
+
return dispatchEvent(this, event);
|
|
4525
|
+
}
|
|
4526
|
+
/**
|
|
4527
|
+
@internal
|
|
4528
|
+
*/
|
|
4529
|
+
domSelectionRange() {
|
|
4530
|
+
let sel = this.domSelection();
|
|
4531
|
+
if (!sel) return {
|
|
4532
|
+
focusNode: null,
|
|
4533
|
+
focusOffset: 0,
|
|
4534
|
+
anchorNode: null,
|
|
4535
|
+
anchorOffset: 0
|
|
4536
|
+
};
|
|
4537
|
+
return safari && this.root.nodeType === 11 && deepActiveElement(this.dom.ownerDocument) == this.dom && safariShadowSelectionRange(this, sel) || sel;
|
|
4538
|
+
}
|
|
4539
|
+
/**
|
|
4540
|
+
@internal
|
|
4541
|
+
*/
|
|
4542
|
+
domSelection() {
|
|
4543
|
+
return this.root.getSelection();
|
|
4544
|
+
}
|
|
4545
|
+
};
|
|
4546
|
+
EditorView.prototype.dispatch = function(tr) {
|
|
4547
|
+
let dispatchTransaction = this._props.dispatchTransaction;
|
|
4548
|
+
if (dispatchTransaction) dispatchTransaction.call(this, tr);
|
|
4549
|
+
else this.updateState(this.state.apply(tr));
|
|
4550
|
+
};
|
|
4551
|
+
function computeDocDeco(view) {
|
|
4552
|
+
let attrs = Object.create(null);
|
|
4553
|
+
attrs.class = "ProseMirror";
|
|
4554
|
+
attrs.contenteditable = String(view.editable);
|
|
4555
|
+
view.someProp("attributes", (value) => {
|
|
4556
|
+
if (typeof value == "function") value = value(view.state);
|
|
4557
|
+
if (value) {
|
|
4558
|
+
for (let attr in value) if (attr == "class") attrs.class += " " + value[attr];
|
|
4559
|
+
else if (attr == "style") attrs.style = (attrs.style ? attrs.style + ";" : "") + value[attr];
|
|
4560
|
+
else if (!attrs[attr] && attr != "contenteditable" && attr != "nodeName") attrs[attr] = String(value[attr]);
|
|
4561
|
+
}
|
|
4562
|
+
});
|
|
4563
|
+
if (!attrs.translate) attrs.translate = "no";
|
|
4564
|
+
return [Decoration.node(0, view.state.doc.content.size, attrs)];
|
|
4565
|
+
}
|
|
4566
|
+
function updateCursorWrapper(view) {
|
|
4567
|
+
if (view.markCursor) {
|
|
4568
|
+
let dom = document.createElement("img");
|
|
4569
|
+
dom.className = "ProseMirror-separator";
|
|
4570
|
+
dom.setAttribute("mark-placeholder", "true");
|
|
4571
|
+
dom.setAttribute("alt", "");
|
|
4572
|
+
view.cursorWrapper = {
|
|
4573
|
+
dom,
|
|
4574
|
+
deco: Decoration.widget(view.state.selection.from, dom, {
|
|
4575
|
+
raw: true,
|
|
4576
|
+
marks: view.markCursor
|
|
4577
|
+
})
|
|
4578
|
+
};
|
|
4579
|
+
} else view.cursorWrapper = null;
|
|
4580
|
+
}
|
|
4581
|
+
function getEditable(view) {
|
|
4582
|
+
return !view.someProp("editable", (value) => value(view.state) === false);
|
|
4583
|
+
}
|
|
4584
|
+
function selectionContextChanged(sel1, sel2) {
|
|
4585
|
+
let depth = Math.min(sel1.$anchor.sharedDepth(sel1.head), sel2.$anchor.sharedDepth(sel2.head));
|
|
4586
|
+
return sel1.$anchor.start(depth) != sel2.$anchor.start(depth);
|
|
4587
|
+
}
|
|
4588
|
+
function buildNodeViews(view) {
|
|
4589
|
+
let result = Object.create(null);
|
|
4590
|
+
function add(obj) {
|
|
4591
|
+
for (let prop in obj) if (!Object.prototype.hasOwnProperty.call(result, prop)) result[prop] = obj[prop];
|
|
4592
|
+
}
|
|
4593
|
+
view.someProp("nodeViews", add);
|
|
4594
|
+
view.someProp("markViews", add);
|
|
4595
|
+
return result;
|
|
4596
|
+
}
|
|
4597
|
+
function changedNodeViews(a, b) {
|
|
4598
|
+
let nA = 0, nB = 0;
|
|
4599
|
+
for (let prop in a) {
|
|
4600
|
+
if (a[prop] != b[prop]) return true;
|
|
4601
|
+
nA++;
|
|
4602
|
+
}
|
|
4603
|
+
for (let _ in b) nB++;
|
|
4604
|
+
return nA != nB;
|
|
4605
|
+
}
|
|
4606
|
+
function checkStateComponent(plugin) {
|
|
4607
|
+
if (plugin.spec.state || plugin.spec.filterTransaction || plugin.spec.appendTransaction) throw new RangeError("Plugins passed directly to the view must not have a state component");
|
|
4608
|
+
}
|
|
4609
|
+
//#endregion
|
|
4610
|
+
Object.defineProperty(exports, "Decoration", {
|
|
4611
|
+
enumerable: true,
|
|
4612
|
+
get: function() {
|
|
4613
|
+
return Decoration;
|
|
4614
|
+
}
|
|
4615
|
+
});
|
|
4616
|
+
Object.defineProperty(exports, "DecorationSet", {
|
|
4617
|
+
enumerable: true,
|
|
4618
|
+
get: function() {
|
|
4619
|
+
return DecorationSet;
|
|
4620
|
+
}
|
|
4621
|
+
});
|
|
4622
|
+
Object.defineProperty(exports, "EditorView", {
|
|
4623
|
+
enumerable: true,
|
|
4624
|
+
get: function() {
|
|
4625
|
+
return EditorView;
|
|
4626
|
+
}
|
|
4627
|
+
});
|
|
4628
|
+
|
|
4629
|
+
//# sourceMappingURL=dist-CMM6n8DO.cjs.map
|