UNPKG

reactjs-tiptap-editor

Version:

A modern WYSIWYG rich text editor based on tiptap and shadcn ui for React

1,406 lines (1,405 loc) 56.2 kB
import { T as D, v as m, S as Z, x as V, y as ft, D as Be, F, z as ut, A as dt } from "./clsx-DaPvp9ji.js"; var $ = { 8: "Backspace", 9: "Tab", 10: "Enter", 12: "NumLock", 13: "Enter", 16: "Shift", 17: "Control", 18: "Alt", 20: "CapsLock", 27: "Escape", 32: " ", 33: "PageUp", 34: "PageDown", 35: "End", 36: "Home", 37: "ArrowLeft", 38: "ArrowUp", 39: "ArrowRight", 40: "ArrowDown", 44: "PrintScreen", 45: "Insert", 46: "Delete", 59: ";", 61: "=", 91: "Meta", 92: "Meta", 106: "*", 107: "+", 108: ",", 109: "-", 110: ".", 111: "/", 144: "NumLock", 145: "ScrollLock", 160: "Shift", 161: "Shift", 162: "Control", 163: "Control", 164: "Alt", 165: "Alt", 173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\", 221: "]", 222: "'" }, _ = { 48: ")", 49: "!", 50: "@", 51: "#", 52: "$", 53: "%", 54: "^", 55: "&", 56: "*", 57: "(", 59: ":", 61: "+", 173: "_", 186: ":", 187: "+", 188: "<", 189: "_", 190: ">", 191: "?", 192: "~", 219: "{", 220: "|", 221: "}", 222: '"' }, pt = typeof navigator < "u" && /Mac/.test(navigator.platform), ht = typeof navigator < "u" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent); for (var y = 0; y < 10; y++) $[48 + y] = $[96 + y] = String(y); for (var y = 1; y <= 24; y++) $[y + 111] = "F" + y; for (var y = 65; y <= 90; y++) $[y] = String.fromCharCode(y + 32), _[y] = String.fromCharCode(y); for (var le in $) _.hasOwnProperty(le) || (_[le] = $[le]); function mt(e) { var n = pt && e.metaKey && e.shiftKey && !e.ctrlKey && !e.altKey || ht && e.shiftKey && e.key && e.key.length == 1 || e.key == "Unidentified", t = !n && e.key || (e.shiftKey ? _ : $)[e.keyCode] || e.key || "Unidentified"; return t == "Esc" && (t = "Escape"), t == "Del" && (t = "Delete"), t == "Left" && (t = "ArrowLeft"), t == "Up" && (t = "ArrowUp"), t == "Right" && (t = "ArrowRight"), t == "Down" && (t = "ArrowDown"), t; } const gt = typeof navigator < "u" && /Mac|iP(hone|[oa]d)/.test(navigator.platform), yt = typeof navigator < "u" && /Win/.test(navigator.platform); function bt(e) { let n = e.split(/-(?!$)/), t = n[n.length - 1]; t == "Space" && (t = " "); let r, o, l, s; for (let i = 0; i < n.length - 1; i++) { let a = n[i]; if (/^(cmd|meta|m)$/i.test(a)) s = !0; else if (/^a(lt)?$/i.test(a)) r = !0; else if (/^(c|ctrl|control)$/i.test(a)) o = !0; else if (/^s(hift)?$/i.test(a)) l = !0; else if (/^mod$/i.test(a)) gt ? s = !0 : o = !0; else throw new Error("Unrecognized modifier name: " + a); } return r && (t = "Alt-" + t), o && (t = "Ctrl-" + t), s && (t = "Meta-" + t), l && (t = "Shift-" + t), t; } function Ct(e) { let n = /* @__PURE__ */ Object.create(null); for (let t in e) n[bt(t)] = e[t]; return n; } function se(e, n, t = !0) { return n.altKey && (e = "Alt-" + e), n.ctrlKey && (e = "Ctrl-" + e), n.metaKey && (e = "Meta-" + e), t && n.shiftKey && (e = "Shift-" + e), e; } function an(e) { let n = Ct(e); return function(t, r) { let o = mt(r), l, s = n[se(o, r)]; if (s && s(t.state, t.dispatch, t)) return !0; if (o.length == 1 && o != " ") { if (r.shiftKey) { let i = n[se(o, r, !1)]; if (i && i(t.state, t.dispatch, t)) return !0; } if ((r.altKey || r.metaKey || r.ctrlKey) && // Ctrl-Alt may be used for AltGr on Windows !(yt && r.ctrlKey && r.altKey) && (l = $[r.keyCode]) && l != o) { let i = n[se(l, r)]; if (i && i(t.state, t.dispatch, t)) return !0; } } return !1; }; } const B = function(e) { for (var n = 0; ; n++) if (e = e.previousSibling, !e) return n; }, qe = function(e, n, t, r) { return t && (xe(e, n, t, r, -1) || xe(e, n, t, r, 1)); }, St = /^(img|br|input|textarea|hr)$/i; function xe(e, n, t, r, o) { for (var l; ; ) { if (e == t && n == r) return !0; if (n == (o < 0 ? 0 : w(e))) { let s = e.parentNode; if (!s || s.nodeType != 1 || ge(e) || St.test(e.nodeName) || e.contentEditable == "false") return !1; n = B(e) + (o < 0 ? 0 : 1), e = s; } else if (e.nodeType == 1) { let s = e.childNodes[n + (o < 0 ? -1 : 0)]; if (s.nodeType == 1 && s.contentEditable == "false") if (!((l = s.pmViewDesc) === null || l === void 0) && l.ignoreForSelection) n += o; else return !1; else e = s, n = o < 0 ? w(e) : 0; } else return !1; } } function w(e) { return e.nodeType == 3 ? e.nodeValue.length : e.childNodes.length; } function Dt(e, n, t) { for (let r = n == 0, o = n == w(e); r || o; ) { if (e == t) return !0; let l = B(e); if (e = e.parentNode, !e) return !1; r = r && l == 0, o = o && l == w(e); } } function ge(e) { let n; for (let t = e; t && !(n = t.pmViewDesc); t = t.parentNode) ; return n && n.node && n.node.isBlock && (n.dom == e || n.contentDOM == e); } const He = function(e) { return e.focusNode && qe(e.focusNode, e.focusOffset, e.anchorNode, e.anchorOffset); }; function We(e, n) { let t = document.createEvent("Event"); return t.initEvent("keydown", !0, !0), t.keyCode = e, t.key = t.code = n, t; } const x = typeof navigator < "u" ? navigator : null, Ee = typeof document < "u" ? document : null, K = x && x.userAgent || "", ce = /Edge\/(\d+)/.exec(K), Ue = /MSIE \d/.exec(K), fe = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(K), J = !!(Ue || fe || ce), je = Ue ? document.documentMode : fe ? +fe[1] : ce ? +ce[1] : 0, re = !J && /gecko\/(\d+)/i.test(K); re && +(/Firefox\/(\d+)/.exec(K) || [0, 0])[1]; const ue = !J && /Chrome\/(\d+)/.exec(K), I = !!ue, Xe = ue ? +ue[1] : 0, q = !J && !!x && /Apple Computer/.test(x.vendor), ye = q && (/Mobile\/\w+/.test(K) || !!x && x.maxTouchPoints > 2), S = ye || (x ? /Mac/.test(x.platform) : !1), kt = x ? /Win/.test(x.platform) : !1, G = /Android \d/.test(K), be = !!Ee && "webkitFontSmoothing" in Ee.documentElement.style, Nt = be ? +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1] : 0; function Tt(e, n = null) { let t = e.domSelectionRange(), r = e.state.doc; if (!t.focusNode) return null; let o = e.docView.nearestDesc(t.focusNode), l = o && o.size == 0, s = e.docView.posFromDOM(t.focusNode, t.focusOffset, 1); if (s < 0) return null; let i = r.resolve(s), a, c; if (He(t)) { for (a = s; o && !o.node; ) o = o.parent; let u = o.node; if (o && u.isAtom && m.isSelectable(u) && o.parent && !(u.isInline && Dt(t.focusNode, t.focusOffset, o.dom))) { let d = o.posBefore; c = new m(s == d ? i : r.resolve(d)); } } else { if (t instanceof e.dom.ownerDocument.defaultView.Selection && t.rangeCount > 1) { let u = s, d = s; for (let p = 0; p < t.rangeCount; p++) { let h = t.getRangeAt(p); u = Math.min(u, e.docView.posFromDOM(h.startContainer, h.startOffset, 1)), d = Math.max(d, e.docView.posFromDOM(h.endContainer, h.endOffset, -1)); } if (u < 0) return null; [a, s] = d == e.state.selection.anchor ? [d, u] : [u, d], i = r.resolve(s); } else a = e.docView.posFromDOM(t.anchorNode, t.anchorOffset, 1); if (a < 0) return null; } let f = r.resolve(a); if (!c) { let u = n == "pointer" || e.state.selection.head < i.pos && !l ? 1 : -1; c = Je(e, f, i, u); } return c; } function Ye(e) { return e.editable ? e.hasFocus() : At(e) && document.activeElement && document.activeElement.contains(e.dom); } function Ce(e, n = !1) { let t = e.state.selection; if (Ot(e, t), !!Ye(e)) { if (!n && e.input.mouseDown && e.input.mouseDown.allowDefault && I) { let r = e.domSelectionRange(), o = e.domObserver.currentSelection; if (r.anchorNode && o.anchorNode && qe(r.anchorNode, r.anchorOffset, o.anchorNode, o.anchorOffset)) { e.input.mouseDown.delayedSelectionSync = !0, e.domObserver.setCurSelection(); return; } } if (e.domObserver.disconnectSelection(), e.cursorWrapper) Et(e); else { let { anchor: r, head: o } = t, l, s; Oe && !(t instanceof D) && (t.$from.parent.inlineContent || (l = Ae(e, t.from)), !t.empty && !t.$from.parent.inlineContent && (s = Ae(e, t.to))), e.docView.setSelection(r, o, e, n), Oe && (l && Me(l), s && Me(s)), t.visible ? e.dom.classList.remove("ProseMirror-hideselection") : (e.dom.classList.add("ProseMirror-hideselection"), "onselectionchange" in document && xt(e)); } e.domObserver.setCurSelection(), e.domObserver.connectSelection(); } } const Oe = q || I && Xe < 63; function Ae(e, n) { let { node: t, offset: r } = e.docView.domFromPos(n, 0), o = r < t.childNodes.length ? t.childNodes[r] : null, l = r ? t.childNodes[r - 1] : null; if (q && o && o.contentEditable == "false") return ie(o); if ((!o || o.contentEditable == "false") && (!l || l.contentEditable == "false")) { if (o) return ie(o); if (l) return ie(l); } } function ie(e) { return e.contentEditable = "true", q && e.draggable && (e.draggable = !1, e.wasDraggable = !0), e; } function Me(e) { e.contentEditable = "false", e.wasDraggable && (e.draggable = !0, e.wasDraggable = null); } function xt(e) { let n = e.dom.ownerDocument; n.removeEventListener("selectionchange", e.input.hideSelectionGuard); let t = e.domSelectionRange(), r = t.anchorNode, o = t.anchorOffset; n.addEventListener("selectionchange", e.input.hideSelectionGuard = () => { (t.anchorNode != r || t.anchorOffset != o) && (n.removeEventListener("selectionchange", e.input.hideSelectionGuard), setTimeout(() => { (!Ye(e) || e.state.selection.visible) && e.dom.classList.remove("ProseMirror-hideselection"); }, 20)); }); } function Et(e) { let n = e.domSelection(); if (!n) return; let t = e.cursorWrapper.dom, r = t.nodeName == "IMG"; r ? n.collapse(t.parentNode, B(t) + 1) : n.collapse(t, 0), !r && !e.state.selection.visible && J && je <= 11 && (t.disabled = !0, t.disabled = !1); } function Ot(e, n) { if (n instanceof m) { let t = e.docView.descAt(n.from); t != e.lastSelectedViewDesc && (Pe(e), t && t.selectNode(), e.lastSelectedViewDesc = t); } else Pe(e); } function Pe(e) { e.lastSelectedViewDesc && (e.lastSelectedViewDesc.parent && e.lastSelectedViewDesc.deselectNode(), e.lastSelectedViewDesc = void 0); } function Je(e, n, t, r) { return e.someProp("createSelectionBetween", (o) => o(e, n, t)) || D.between(n, t, r); } function At(e) { let n = e.domSelectionRange(); if (!n.anchorNode) return !1; try { return e.dom.contains(n.anchorNode.nodeType == 3 ? n.anchorNode.parentNode : n.anchorNode) && (e.editable || e.dom.contains(n.focusNode.nodeType == 3 ? n.focusNode.parentNode : n.focusNode)); } catch { return !1; } } function de(e, n) { let { $anchor: t, $head: r } = e.selection, o = n > 0 ? t.max(r) : t.min(r), l = o.parent.inlineContent ? o.depth ? e.doc.resolve(n > 0 ? o.after() : o.before()) : null : o; return l && Z.findFrom(l, n); } function A(e, n) { return e.dispatch(e.state.tr.setSelection(n).scrollIntoView()), !0; } function $e(e, n, t) { let r = e.state.selection; if (r instanceof D) if (t.indexOf("s") > -1) { let { $head: o } = r, l = o.textOffset ? null : n < 0 ? o.nodeBefore : o.nodeAfter; if (!l || l.isText || !l.isLeaf) return !1; let s = e.state.doc.resolve(o.pos + l.nodeSize * (n < 0 ? -1 : 1)); return A(e, new D(r.$anchor, s)); } else if (r.empty) { if (e.endOfTextblock(n > 0 ? "forward" : "backward")) { let o = de(e.state, n); return o && o instanceof m ? A(e, o) : !1; } else if (!(S && t.indexOf("m") > -1)) { let o = r.$head, l = o.textOffset ? null : n < 0 ? o.nodeBefore : o.nodeAfter, s; if (!l || l.isText) return !1; let i = n < 0 ? o.pos - l.nodeSize : o.pos; return l.isAtom || (s = e.docView.descAt(i)) && !s.contentDOM ? m.isSelectable(l) ? A(e, new m(n < 0 ? e.state.doc.resolve(o.pos - l.nodeSize) : o)) : be ? A(e, new D(e.state.doc.resolve(n < 0 ? i : i + l.nodeSize))) : !1 : !1; } } else return !1; else { if (r instanceof m && r.node.isInline) return A(e, new D(n > 0 ? r.$to : r.$from)); { let o = de(e.state, n); return o ? A(e, o) : !1; } } } function v(e) { return e.nodeType == 3 ? e.nodeValue.length : e.childNodes.length; } function j(e, n) { let t = e.pmViewDesc; return t && t.size == 0 && (n < 0 || e.nextSibling || e.nodeName != "BR"); } function H(e, n) { return n < 0 ? Mt(e) : Pt(e); } function Mt(e) { let n = e.domSelectionRange(), t = n.focusNode, r = n.focusOffset; if (!t) return; let o, l, s = !1; for (re && t.nodeType == 1 && r < v(t) && j(t.childNodes[r], -1) && (s = !0); ; ) if (r > 0) { if (t.nodeType != 1) break; { let i = t.childNodes[r - 1]; if (j(i, -1)) o = t, l = --r; else if (i.nodeType == 3) t = i, r = t.nodeValue.length; else break; } } else { if (Ge(t)) break; { let i = t.previousSibling; for (; i && j(i, -1); ) o = t.parentNode, l = B(i), i = i.previousSibling; if (i) t = i, r = v(t); else { if (t = t.parentNode, t == e.dom) break; r = 0; } } } s ? pe(e, t, r) : o && pe(e, o, l); } function Pt(e) { let n = e.domSelectionRange(), t = n.focusNode, r = n.focusOffset; if (!t) return; let o = v(t), l, s; for (; ; ) if (r < o) { if (t.nodeType != 1) break; let i = t.childNodes[r]; if (j(i, 1)) l = t, s = ++r; else break; } else { if (Ge(t)) break; { let i = t.nextSibling; for (; i && j(i, 1); ) l = i.parentNode, s = B(i) + 1, i = i.nextSibling; if (i) t = i, r = 0, o = v(t); else { if (t = t.parentNode, t == e.dom) break; r = o = 0; } } } l && pe(e, l, s); } function Ge(e) { let n = e.pmViewDesc; return n && n.node && n.node.isBlock; } function $t(e, n) { for (; e && n == e.childNodes.length && !ge(e); ) n = B(e) + 1, e = e.parentNode; for (; e && n < e.childNodes.length; ) { let t = e.childNodes[n]; if (t.nodeType == 3) return t; if (t.nodeType == 1 && t.contentEditable == "false") break; e = t, n = 0; } } function Kt(e, n) { for (; e && !n && !ge(e); ) n = B(e), e = e.parentNode; for (; e && n; ) { let t = e.childNodes[n - 1]; if (t.nodeType == 3) return t; if (t.nodeType == 1 && t.contentEditable == "false") break; e = t, n = e.childNodes.length; } } function pe(e, n, t) { if (n.nodeType != 3) { let l, s; (s = $t(n, t)) ? (n = s, t = 0) : (l = Kt(n, t)) && (n = l, t = l.nodeValue.length); } let r = e.domSelection(); if (!r) return; if (He(r)) { let l = document.createRange(); l.setEnd(n, t), l.setStart(n, t), r.removeAllRanges(), r.addRange(l); } else r.extend && r.extend(n, t); e.domObserver.setCurSelection(); let { state: o } = e; setTimeout(() => { e.state == o && Ce(e); }, 50); } function Ke(e, n) { let t = e.state.doc.resolve(n); if (!(I || kt) && t.parent.inlineContent) { let o = e.coordsAtPos(n); if (n > t.start()) { let l = e.coordsAtPos(n - 1), s = (l.top + l.bottom) / 2; if (s > o.top && s < o.bottom && Math.abs(l.left - o.left) > 1) return l.left < o.left ? "ltr" : "rtl"; } if (n < t.end()) { let l = e.coordsAtPos(n + 1), s = (l.top + l.bottom) / 2; if (s > o.top && s < o.bottom && Math.abs(l.left - o.left) > 1) return l.left > o.left ? "ltr" : "rtl"; } } return getComputedStyle(e.dom).direction == "rtl" ? "rtl" : "ltr"; } function Ie(e, n, t) { let r = e.state.selection; if (r instanceof D && !r.empty || t.indexOf("s") > -1 || S && t.indexOf("m") > -1) return !1; let { $from: o, $to: l } = r; if (!o.parent.inlineContent || e.endOfTextblock(n < 0 ? "up" : "down")) { let s = de(e.state, n); if (s && s instanceof m) return A(e, s); } if (!o.parent.inlineContent) { let s = n < 0 ? o : l, i = r instanceof dt ? Z.near(s, n) : Z.findFrom(s, n); return i ? A(e, i) : !1; } return !1; } function Re(e, n) { if (!(e.state.selection instanceof D)) return !0; let { $head: t, $anchor: r, empty: o } = e.state.selection; if (!t.sameParent(r)) return !0; if (!o) return !1; if (e.endOfTextblock(n > 0 ? "forward" : "backward")) return !0; let l = !t.textOffset && (n < 0 ? t.nodeBefore : t.nodeAfter); if (l && !l.isText) { let s = e.state.tr; return n < 0 ? s.delete(t.pos - l.nodeSize, t.pos) : s.delete(t.pos, t.pos + l.nodeSize), e.dispatch(s), !0; } return !1; } function Le(e, n, t) { e.domObserver.stop(), n.contentEditable = t, e.domObserver.start(); } function It(e) { if (!q || e.state.selection.$head.parentOffset > 0) return !1; let { focusNode: n, focusOffset: t } = e.domSelectionRange(); if (n && n.nodeType == 1 && t == 0 && n.firstChild && n.firstChild.contentEditable == "false") { let r = n.firstChild; Le(e, r, "true"), setTimeout(() => Le(e, r, "false"), 20); } return !1; } function Rt(e) { let n = ""; return e.ctrlKey && (n += "c"), e.metaKey && (n += "m"), e.altKey && (n += "a"), e.shiftKey && (n += "s"), n; } function Lt(e, n) { let t = n.keyCode, r = Rt(n); if (t == 8 || S && t == 72 && r == "c") return Re(e, -1) || H(e, -1); if (t == 46 && !n.shiftKey || S && t == 68 && r == "c") return Re(e, 1) || H(e, 1); if (t == 13 || t == 27) return !0; if (t == 37 || S && t == 66 && r == "c") { let o = t == 37 ? Ke(e, e.state.selection.from) == "ltr" ? -1 : 1 : -1; return $e(e, o, r) || H(e, o); } else if (t == 39 || S && t == 70 && r == "c") { let o = t == 39 ? Ke(e, e.state.selection.from) == "ltr" ? 1 : -1 : 1; return $e(e, o, r) || H(e, o); } else { if (t == 38 || S && t == 80 && r == "c") return Ie(e, -1, r) || H(e, -1); if (t == 40 || S && t == 78 && r == "c") return It(e) || Ie(e, 1, r) || H(e, 1); if (r == (S ? "m" : "c") && (t == 66 || t == 73 || t == 89 || t == 90)) return !0; } return !1; } function Qe(e, n) { e.someProp("transformCopied", (p) => { n = p(n, e); }); let t = [], { content: r, openStart: o, openEnd: l } = n; for (; o > 1 && l > 1 && r.childCount == 1 && r.firstChild.childCount == 1; ) { o--, l--; let p = r.firstChild; t.push(p.type.name, p.attrs != p.type.defaultAttrs ? p.attrs : null), r = p.content; } let s = e.someProp("clipboardSerializer") || Be.fromSchema(e.state.schema), i = tt(), a = i.createElement("div"); a.appendChild(s.serializeFragment(r, { document: i })); let c = a.firstChild, f, u = 0; for (; c && c.nodeType == 1 && (f = et[c.nodeName.toLowerCase()]); ) { for (let p = f.length - 1; p >= 0; p--) { let h = i.createElement(f[p]); for (; a.firstChild; ) h.appendChild(a.firstChild); a.appendChild(h), u++; } c = a.firstChild; } c && c.nodeType == 1 && c.setAttribute("data-pm-slice", `${o} ${l}${u ? ` -${u}` : ""} ${JSON.stringify(t)}`); let d = e.someProp("clipboardTextSerializer", (p) => p(n, e)) || n.content.textBetween(0, n.content.size, ` `); return { dom: a, text: d, slice: n }; } function Ze(e, n, t, r, o) { let l = o.parent.type.spec.code, s, i; if (!t && !n) return null; let a = !!n && (r || l || !t); if (a) { if (e.someProp("transformPastedText", (d) => { n = d(n, l || r, e); }), l) return i = new V(F.from(e.state.schema.text(n.replace(/\r\n?/g, ` `))), 0, 0), e.someProp("transformPasted", (d) => { i = d(i, e, !0); }), i; let u = e.someProp("clipboardTextParser", (d) => d(n, o, r, e)); if (u) i = u; else { let d = o.marks(), { schema: p } = e.state, h = Be.fromSchema(p); s = document.createElement("div"), n.split(/(?:\r\n?|\n)+/).forEach((O) => { let k = s.appendChild(document.createElement("p")); O && k.appendChild(h.serializeNode(p.text(O, d))); }); } } else e.someProp("transformPastedHTML", (u) => { t = u(t, e); }), s = Bt(t), be && qt(s); let c = s && s.querySelector("[data-pm-slice]"), f = c && /^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice") || ""); if (f && f[3]) for (let u = +f[3]; u > 0; u--) { let d = s.firstChild; for (; d && d.nodeType != 1; ) d = d.nextSibling; if (!d) break; s = d; } if (i || (i = (e.someProp("clipboardParser") || e.someProp("domParser") || ut.fromSchema(e.state.schema)).parseSlice(s, { preserveWhitespace: !!(a || f), context: o, ruleFromNode(d) { return d.nodeName == "BR" && !d.nextSibling && d.parentNode && !zt.test(d.parentNode.nodeName) ? { ignore: !0 } : null; } })), f) i = Ht(ze(i, +f[1], +f[2]), f[4]); else if (i = V.maxOpen(Vt(i.content, o), !0), i.openStart || i.openEnd) { let u = 0, d = 0; for (let p = i.content.firstChild; u < i.openStart && !p.type.spec.isolating; u++, p = p.firstChild) ; for (let p = i.content.lastChild; d < i.openEnd && !p.type.spec.isolating; d++, p = p.lastChild) ; i = ze(i, u, d); } return e.someProp("transformPasted", (u) => { i = u(i, e, a); }), i; } const zt = /^(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; function Vt(e, n) { if (e.childCount < 2) return e; for (let t = n.depth; t >= 0; t--) { let o = n.node(t).contentMatchAt(n.index(t)), l, s = []; if (e.forEach((i) => { if (!s) return; let a = o.findWrapping(i.type), c; if (!a) return s = null; if (c = s.length && l.length && we(a, l, i, s[s.length - 1], 0)) s[s.length - 1] = c; else { s.length && (s[s.length - 1] = ve(s[s.length - 1], l.length)); let f = _e(i, a); s.push(f), o = o.matchType(f.type), l = a; } }), s) return F.from(s); } return e; } function _e(e, n, t = 0) { for (let r = n.length - 1; r >= t; r--) e = n[r].create(null, F.from(e)); return e; } function we(e, n, t, r, o) { if (o < e.length && o < n.length && e[o] == n[o]) { let l = we(e, n, t, r.lastChild, o + 1); if (l) return r.copy(r.content.replaceChild(r.childCount - 1, l)); if (r.contentMatchAt(r.childCount).matchType(o == e.length - 1 ? t.type : e[o + 1])) return r.copy(r.content.append(F.from(_e(t, e, o + 1)))); } } function ve(e, n) { if (n == 0) return e; let t = e.content.replaceChild(e.childCount - 1, ve(e.lastChild, n - 1)), r = e.contentMatchAt(e.childCount).fillBefore(F.empty, !0); return e.copy(t.append(r)); } function he(e, n, t, r, o, l) { let s = n < 0 ? e.firstChild : e.lastChild, i = s.content; return e.childCount > 1 && (l = 0), o < r - 1 && (i = he(i, n, t, r, o + 1, l)), o >= t && (i = n < 0 ? s.contentMatchAt(0).fillBefore(i, l <= o).append(i) : i.append(s.contentMatchAt(s.childCount).fillBefore(F.empty, !0))), e.replaceChild(n < 0 ? 0 : e.childCount - 1, s.copy(i)); } function ze(e, n, t) { return n < e.openStart && (e = new V(he(e.content, -1, n, e.openStart, 0, e.openEnd), n, e.openEnd)), t < e.openEnd && (e = new V(he(e.content, 1, t, e.openEnd, 0, 0), e.openStart, t)), e; } const et = { thead: ["table"], tbody: ["table"], tfoot: ["table"], caption: ["table"], colgroup: ["table"], col: ["table", "colgroup"], tr: ["table", "tbody"], td: ["table", "tbody", "tr"], th: ["table", "tbody", "tr"] }; let Ve = null; function tt() { return Ve || (Ve = document.implementation.createHTMLDocument("title")); } let ae = null; function Ft(e) { let n = window.trustedTypes; return n ? (ae || (ae = n.defaultPolicy || n.createPolicy("ProseMirrorClipboard", { createHTML: (t) => t })), ae.createHTML(e)) : e; } function Bt(e) { let n = /^(\s*<meta [^>]*>)*/.exec(e); n && (e = e.slice(n[0].length)); let t = tt().createElement("div"), r = /<([a-z][^>\s]+)/i.exec(e), o; if ((o = r && et[r[1].toLowerCase()]) && (e = o.map((l) => "<" + l + ">").join("") + e + o.map((l) => "</" + l + ">").reverse().join("")), t.innerHTML = Ft(e), o) for (let l = 0; l < o.length; l++) t = t.querySelector(o[l]) || t; return t; } function qt(e) { let n = e.querySelectorAll(I ? "span:not([class]):not([style])" : "span.Apple-converted-space"); for (let t = 0; t < n.length; t++) { let r = n[t]; r.childNodes.length == 1 && r.textContent == " " && r.parentNode && r.parentNode.replaceChild(e.ownerDocument.createTextNode(" "), r); } } function Ht(e, n) { if (!e.size) return e; let t = e.content.firstChild.type.schema, r; try { r = JSON.parse(n); } catch { return e; } let { content: o, openStart: l, openEnd: s } = e; for (let i = r.length - 2; i >= 0; i -= 2) { let a = t.nodes[r[i]]; if (!a || a.hasRequiredAttrs()) break; o = F.from(a.create(r[i + 1], o)), l++, s++; } return new V(o, l, s); } const T = {}, C = {}; function M(e, n) { e.input.lastSelectionOrigin = n, e.input.lastSelectionTime = Date.now(); } C.keydown = (e, n) => { let t = n; if (e.input.shiftKey = t.keyCode == 16 || t.shiftKey, !rt(e, t) && (e.input.lastKeyCode = t.keyCode, e.input.lastKeyCodeTime = Date.now(), !(G && I && t.keyCode == 13))) if (t.keyCode != 229 && e.domObserver.forceFlush(), ye && t.keyCode == 13 && !t.ctrlKey && !t.altKey && !t.metaKey) { let r = Date.now(); e.input.lastIOSEnter = r, e.input.lastIOSEnterFallbackTimeout = setTimeout(() => { e.input.lastIOSEnter == r && (e.someProp("handleKeyDown", (o) => o(e, We(13, "Enter"))), e.input.lastIOSEnter = 0); }, 200); } else e.someProp("handleKeyDown", (r) => r(e, t)) || Lt(e, t) ? t.preventDefault() : M(e, "key"); }; C.keyup = (e, n) => { n.keyCode == 16 && (e.input.shiftKey = !1); }; C.keypress = (e, n) => { let t = n; if (rt(e, t) || !t.charCode || t.ctrlKey && !t.altKey || S && t.metaKey) return; if (e.someProp("handleKeyPress", (o) => o(e, t))) { t.preventDefault(); return; } let r = e.state.selection; if (!(r instanceof D) || !r.$from.sameParent(r.$to)) { let o = String.fromCharCode(t.charCode), l = () => e.state.tr.insertText(o).scrollIntoView(); !/[\r\n]/.test(o) && !e.someProp("handleTextInput", (s) => s(e, r.$from.pos, r.$to.pos, o, l)) && e.dispatch(l()), t.preventDefault(); } }; function oe(e) { return { left: e.clientX, top: e.clientY }; } function Wt(e, n) { let t = n.x - e.clientX, r = n.y - e.clientY; return t * t + r * r < 100; } function Se(e, n, t, r, o) { if (r == -1) return !1; let l = e.state.doc.resolve(r); for (let s = l.depth + 1; s > 0; s--) if (e.someProp(n, (i) => s > l.depth ? i(e, t, l.nodeAfter, l.before(s), o, !0) : i(e, t, l.node(s), l.before(s), o, !1))) return !0; return !1; } function U(e, n, t) { if (e.focused || e.focus(), e.state.selection.eq(n)) return; let r = e.state.tr.setSelection(n); r.setMeta("pointer", !0), e.dispatch(r); } function Ut(e, n) { if (n == -1) return !1; let t = e.state.doc.resolve(n), r = t.nodeAfter; return r && r.isAtom && m.isSelectable(r) ? (U(e, new m(t)), !0) : !1; } function jt(e, n) { if (n == -1) return !1; let t = e.state.selection, r, o; t instanceof m && (r = t.node); let l = e.state.doc.resolve(n); for (let s = l.depth + 1; s > 0; s--) { let i = s > l.depth ? l.nodeAfter : l.node(s); if (m.isSelectable(i)) { r && t.$from.depth > 0 && s >= t.$from.depth && l.before(t.$from.depth + 1) == t.$from.pos ? o = l.before(t.$from.depth) : o = l.before(s); break; } } return o != null ? (U(e, m.create(e.state.doc, o)), !0) : !1; } function Xt(e, n, t, r, o) { return Se(e, "handleClickOn", n, t, r) || e.someProp("handleClick", (l) => l(e, n, r)) || (o ? jt(e, t) : Ut(e, t)); } function Yt(e, n, t, r) { return Se(e, "handleDoubleClickOn", n, t, r) || e.someProp("handleDoubleClick", (o) => o(e, n, r)); } function Jt(e, n, t, r) { return Se(e, "handleTripleClickOn", n, t, r) || e.someProp("handleTripleClick", (o) => o(e, n, r)) || Gt(e, t, r); } function Gt(e, n, t) { if (t.button != 0) return !1; let r = e.state.doc; if (n == -1) return r.inlineContent ? (U(e, D.create(r, 0, r.content.size)), !0) : !1; let o = r.resolve(n); for (let l = o.depth + 1; l > 0; l--) { let s = l > o.depth ? o.nodeAfter : o.node(l), i = o.before(l); if (s.inlineContent) U(e, D.create(r, i + 1, i + 1 + s.content.size)); else if (m.isSelectable(s)) U(e, m.create(r, i)); else continue; return !0; } } function De(e) { return ee(e); } const nt = S ? "metaKey" : "ctrlKey"; T.mousedown = (e, n) => { let t = n; e.input.shiftKey = t.shiftKey; let r = De(e), o = Date.now(), l = "singleClick"; o - e.input.lastClick.time < 500 && Wt(t, e.input.lastClick) && !t[nt] && e.input.lastClick.button == t.button && (e.input.lastClick.type == "singleClick" ? l = "doubleClick" : e.input.lastClick.type == "doubleClick" && (l = "tripleClick")), e.input.lastClick = { time: o, x: t.clientX, y: t.clientY, type: l, button: t.button }; let s = e.posAtCoords(oe(t)); s && (l == "singleClick" ? (e.input.mouseDown && e.input.mouseDown.done(), e.input.mouseDown = new Qt(e, s, t, !!r)) : (l == "doubleClick" ? Yt : Jt)(e, s.pos, s.inside, t) ? t.preventDefault() : M(e, "pointer")); }; class Qt { constructor(n, t, r, o) { this.view = n, this.pos = t, this.event = r, this.flushed = o, this.delayedSelectionSync = !1, this.mightDrag = null, this.startDoc = n.state.doc, this.selectNode = !!r[nt], this.allowDefault = r.shiftKey; let l, s; if (t.inside > -1) l = n.state.doc.nodeAt(t.inside), s = t.inside; else { let f = n.state.doc.resolve(t.pos); l = f.parent, s = f.depth ? f.before() : 0; } const i = o ? null : r.target, a = i ? n.docView.nearestDesc(i, !0) : null; this.target = a && a.nodeDOM.nodeType == 1 ? a.nodeDOM : null; let { selection: c } = n.state; (r.button == 0 && l.type.spec.draggable && l.type.spec.selectable !== !1 || c instanceof m && c.from <= s && c.to > s) && (this.mightDrag = { node: l, pos: s, addAttr: !!(this.target && !this.target.draggable), setUneditable: !!(this.target && re && !this.target.hasAttribute("contentEditable")) }), this.target && this.mightDrag && (this.mightDrag.addAttr || this.mightDrag.setUneditable) && (this.view.domObserver.stop(), this.mightDrag.addAttr && (this.target.draggable = !0), this.mightDrag.setUneditable && setTimeout(() => { this.view.input.mouseDown == this && this.target.setAttribute("contentEditable", "false"); }, 20), this.view.domObserver.start()), n.root.addEventListener("mouseup", this.up = this.up.bind(this)), n.root.addEventListener("mousemove", this.move = this.move.bind(this)), M(n, "pointer"); } done() { this.view.root.removeEventListener("mouseup", this.up), this.view.root.removeEventListener("mousemove", this.move), this.mightDrag && this.target && (this.view.domObserver.stop(), this.mightDrag.addAttr && this.target.removeAttribute("draggable"), this.mightDrag.setUneditable && this.target.removeAttribute("contentEditable"), this.view.domObserver.start()), this.delayedSelectionSync && setTimeout(() => Ce(this.view)), this.view.input.mouseDown = null; } up(n) { if (this.done(), !this.view.dom.contains(n.target)) return; let t = this.pos; this.view.state.doc != this.startDoc && (t = this.view.posAtCoords(oe(n))), this.updateAllowDefault(n), this.allowDefault || !t ? M(this.view, "pointer") : Xt(this.view, t.pos, t.inside, n, this.selectNode) ? n.preventDefault() : n.button == 0 && (this.flushed || // Safari ignores clicks on draggable elements q && this.mightDrag && !this.mightDrag.node.isAtom || // Chrome will sometimes treat a node selection as a // cursor, but still report that the node is selected // when asked through getSelection. You'll then get a // situation where clicking at the point where that // (hidden) cursor is doesn't change the selection, and // thus doesn't get a reaction from ProseMirror. This // works around that. I && !this.view.state.selection.visible && Math.min(Math.abs(t.pos - this.view.state.selection.from), Math.abs(t.pos - this.view.state.selection.to)) <= 2) ? (U(this.view, Z.near(this.view.state.doc.resolve(t.pos))), n.preventDefault()) : M(this.view, "pointer"); } move(n) { this.updateAllowDefault(n), M(this.view, "pointer"), n.buttons == 0 && this.done(); } updateAllowDefault(n) { !this.allowDefault && (Math.abs(this.event.x - n.clientX) > 4 || Math.abs(this.event.y - n.clientY) > 4) && (this.allowDefault = !0); } } T.touchstart = (e) => { e.input.lastTouch = Date.now(), De(e), M(e, "pointer"); }; T.touchmove = (e) => { e.input.lastTouch = Date.now(), M(e, "pointer"); }; T.contextmenu = (e) => De(e); function rt(e, n) { return e.composing ? !0 : q && Math.abs(n.timeStamp - e.input.compositionEndedAt) < 500 ? (e.input.compositionEndedAt = -2e8, !0) : !1; } const Zt = G ? 5e3 : -1; C.compositionstart = C.compositionupdate = (e) => { if (!e.composing) { e.domObserver.flush(); let { state: n } = e, t = n.selection.$to; if (n.selection instanceof D && (n.storedMarks || !t.textOffset && t.parentOffset && t.nodeBefore.marks.some((r) => r.type.spec.inclusive === !1))) e.markCursor = e.state.storedMarks || t.marks(), ee(e, !0), e.markCursor = null; else if (ee(e, !n.selection.empty), re && n.selection.empty && t.parentOffset && !t.textOffset && t.nodeBefore.marks.length) { let r = e.domSelectionRange(); for (let o = r.focusNode, l = r.focusOffset; o && o.nodeType == 1 && l != 0; ) { let s = l < 0 ? o.lastChild : o.childNodes[l - 1]; if (!s) break; if (s.nodeType == 3) { let i = e.domSelection(); i && i.collapse(s, s.nodeValue.length); break; } else o = s, l = -1; } } e.input.composing = !0; } ot(e, Zt); }; C.compositionend = (e, n) => { e.composing && (e.input.composing = !1, e.input.compositionEndedAt = n.timeStamp, e.input.compositionPendingChanges = e.domObserver.pendingRecords().length ? e.input.compositionID : 0, e.input.compositionNode = null, e.input.compositionPendingChanges && Promise.resolve().then(() => e.domObserver.flush()), e.input.compositionID++, ot(e, 20)); }; function ot(e, n) { clearTimeout(e.input.composingTimeout), n > -1 && (e.input.composingTimeout = setTimeout(() => ee(e), n)); } function _t(e) { for (e.composing && (e.input.composing = !1, e.input.compositionEndedAt = wt()); e.input.compositionNodes.length > 0; ) e.input.compositionNodes.pop().markParentsDirty(); } function wt() { let e = document.createEvent("Event"); return e.initEvent("event", !0, !0), e.timeStamp; } function ee(e, n = !1) { if (!(G && e.domObserver.flushingSoon >= 0)) { if (e.domObserver.forceFlush(), _t(e), n || e.docView && e.docView.dirty) { let t = Tt(e), r = e.state.selection; return t && !t.eq(r) ? e.dispatch(e.state.tr.setSelection(t)) : (e.markCursor || n) && !r.$from.node(r.$from.sharedDepth(r.to)).inlineContent ? e.dispatch(e.state.tr.deleteSelection()) : e.updateState(e.state), !0; } return !1; } } function vt(e, n) { if (!e.dom.parentNode) return; let t = e.dom.parentNode.appendChild(document.createElement("div")); t.appendChild(n), t.style.cssText = "position: fixed; left: -10000px; top: 10px"; let r = getSelection(), o = document.createRange(); o.selectNodeContents(n), e.dom.blur(), r.removeAllRanges(), r.addRange(o), setTimeout(() => { t.parentNode && t.parentNode.removeChild(t), e.focus(); }, 50); } const X = J && je < 15 || ye && Nt < 604; T.copy = C.cut = (e, n) => { let t = n, r = e.state.selection, o = t.type == "cut"; if (r.empty) return; let l = X ? null : t.clipboardData, s = r.content(), { dom: i, text: a } = Qe(e, s); l ? (t.preventDefault(), l.clearData(), l.setData("text/html", i.innerHTML), l.setData("text/plain", a)) : vt(e, i), o && e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent", "cut")); }; function en(e) { return e.openStart == 0 && e.openEnd == 0 && e.content.childCount == 1 ? e.content.firstChild : null; } function tn(e, n) { if (!e.dom.parentNode) return; let t = e.input.shiftKey || e.state.selection.$from.parent.type.spec.code, r = e.dom.parentNode.appendChild(document.createElement(t ? "textarea" : "div")); t || (r.contentEditable = "true"), r.style.cssText = "position: fixed; left: -10000px; top: 10px", r.focus(); let o = e.input.shiftKey && e.input.lastKeyCode != 45; setTimeout(() => { e.focus(), r.parentNode && r.parentNode.removeChild(r), t ? me(e, r.value, null, o, n) : me(e, r.textContent, r.innerHTML, o, n); }, 50); } function me(e, n, t, r, o) { let l = Ze(e, n, t, r, e.state.selection.$from); if (e.someProp("handlePaste", (a) => a(e, o, l || V.empty))) return !0; if (!l) return !1; let s = en(l), i = s ? e.state.tr.replaceSelectionWith(s, r) : e.state.tr.replaceSelection(l); return e.dispatch(i.scrollIntoView().setMeta("paste", !0).setMeta("uiEvent", "paste")), !0; } function lt(e) { let n = e.getData("text/plain") || e.getData("Text"); if (n) return n; let t = e.getData("text/uri-list"); return t ? t.replace(/\r?\n/g, " ") : ""; } C.paste = (e, n) => { let t = n; if (e.composing && !G) return; let r = X ? null : t.clipboardData, o = e.input.shiftKey && e.input.lastKeyCode != 45; r && me(e, lt(r), r.getData("text/html"), o, t) ? t.preventDefault() : tn(e, t); }; class nn { constructor(n, t, r) { this.slice = n, this.move = t, this.node = r; } } const rn = S ? "altKey" : "ctrlKey"; function st(e, n) { let t = e.someProp("dragCopies", (r) => !r(n)); return t ?? !n[rn]; } T.dragstart = (e, n) => { let t = n, r = e.input.mouseDown; if (r && r.done(), !t.dataTransfer) return; let o = e.state.selection, l = o.empty ? null : e.posAtCoords(oe(t)), s; if (!(l && l.pos >= o.from && l.pos <= (o instanceof m ? o.to - 1 : o.to))) { if (r && r.mightDrag) s = m.create(e.state.doc, r.mightDrag.pos); else if (t.target && t.target.nodeType == 1) { let u = e.docView.nearestDesc(t.target, !0); u && u.node.type.spec.draggable && u != e.docView && (s = m.create(e.state.doc, u.posBefore)); } } let i = (s || e.state.selection).content(), { dom: a, text: c, slice: f } = Qe(e, i); (!t.dataTransfer.files.length || !I || Xe > 120) && t.dataTransfer.clearData(), t.dataTransfer.setData(X ? "Text" : "text/html", a.innerHTML), t.dataTransfer.effectAllowed = "copyMove", X || t.dataTransfer.setData("text/plain", c), e.dragging = new nn(f, st(e, t), s); }; T.dragend = (e) => { let n = e.dragging; window.setTimeout(() => { e.dragging == n && (e.dragging = null); }, 50); }; C.dragover = C.dragenter = (e, n) => n.preventDefault(); C.drop = (e, n) => { let t = n, r = e.dragging; if (e.dragging = null, !t.dataTransfer) return; let o = e.posAtCoords(oe(t)); if (!o) return; let l = e.state.doc.resolve(o.pos), s = r && r.slice; s ? e.someProp("transformPasted", (h) => { s = h(s, e, !1); }) : s = Ze(e, lt(t.dataTransfer), X ? null : t.dataTransfer.getData("text/html"), !1, l); let i = !!(r && st(e, t)); if (e.someProp("handleDrop", (h) => h(e, t, s || V.empty, i))) { t.preventDefault(); return; } if (!s) return; t.preventDefault(); let a = s ? ft(e.state.doc, l.pos, s) : l.pos; a == null && (a = l.pos); let c = e.state.tr; if (i) { let { node: h } = r; h ? h.replace(c) : c.deleteSelection(); } let f = c.mapping.map(a), u = s.openStart == 0 && s.openEnd == 0 && s.content.childCount == 1, d = c.doc; if (u ? c.replaceRangeWith(f, f, s.content.firstChild) : c.replaceRange(f, f, s), c.doc.eq(d)) return; let p = c.doc.resolve(f); if (u && m.isSelectable(s.content.firstChild) && p.nodeAfter && p.nodeAfter.sameMarkup(s.content.firstChild)) c.setSelection(new m(p)); else { let h = c.mapping.map(a); c.mapping.maps[c.mapping.maps.length - 1].forEach((O, k, N, Q) => h = Q), c.setSelection(Je(e, p, c.doc.resolve(h))); } e.focus(), e.dispatch(c.setMeta("uiEvent", "drop")); }; T.focus = (e) => { e.input.lastFocus = Date.now(), e.focused || (e.domObserver.stop(), e.dom.classList.add("ProseMirror-focused"), e.domObserver.start(), e.focused = !0, setTimeout(() => { e.docView && e.hasFocus() && !e.domObserver.currentSelection.eq(e.domSelectionRange()) && Ce(e); }, 20)); }; T.blur = (e, n) => { let t = n; e.focused && (e.domObserver.stop(), e.dom.classList.remove("ProseMirror-focused"), e.domObserver.start(), t.relatedTarget && e.dom.contains(t.relatedTarget) && e.domObserver.currentSelection.clear(), e.focused = !1); }; T.beforeinput = (e, n) => { if (I && G && n.inputType == "deleteContentBackward") { e.domObserver.flushSoon(); let { domChangeCount: r } = e.input; setTimeout(() => { if (e.input.domChangeCount != r || (e.dom.blur(), e.focus(), e.someProp("handleKeyDown", (l) => l(e, We(8, "Backspace"))))) return; let { $cursor: o } = e.state.selection; o && o.pos > 0 && e.dispatch(e.state.tr.delete(o.pos - 1, o.pos).scrollIntoView()); }, 50); } }; for (let e in C) T[e] = C[e]; function Y(e, n) { if (e == n) return !0; for (let t in e) if (e[t] !== n[t]) return !1; for (let t in n) if (!(t in e)) return !1; return !0; } class te { constructor(n, t) { this.toDOM = n, this.spec = t || L, this.side = this.spec.side || 0; } map(n, t, r, o) { let { pos: l, deleted: s } = n.mapResult(t.from + o, this.side < 0 ? -1 : 1); return s ? null : new E(l - r, l - r, this); } valid() { return !0; } eq(n) { return this == n || n instanceof te && (this.spec.key && this.spec.key == n.spec.key || this.toDOM == n.toDOM && Y(this.spec, n.spec)); } destroy(n) { this.spec.destroy && this.spec.destroy(n); } } class P { constructor(n, t) { this.attrs = n, this.spec = t || L; } map(n, t, r, o) { let l = n.map(t.from + o, this.spec.inclusiveStart ? -1 : 1) - r, s = n.map(t.to + o, this.spec.inclusiveEnd ? 1 : -1) - r; return l >= s ? null : new E(l, s, this); } valid(n, t) { return t.from < t.to; } eq(n) { return this == n || n instanceof P && Y(this.attrs, n.attrs) && Y(this.spec, n.spec); } static is(n) { return n.type instanceof P; } destroy() { } } class ke { constructor(n, t) { this.attrs = n, this.spec = t || L; } map(n, t, r, o) { let l = n.mapResult(t.from + o, 1); if (l.deleted) return null; let s = n.mapResult(t.to + o, -1); return s.deleted || s.pos <= l.pos ? null : new E(l.pos - r, s.pos - r, this); } valid(n, t) { let { index: r, offset: o } = n.content.findIndex(t.from), l; return o == t.from && !(l = n.child(r)).isText && o + l.nodeSize == t.to; } eq(n) { return this == n || n instanceof ke && Y(this.attrs, n.attrs) && Y(this.spec, n.spec); } destroy() { } } class E { /** @internal */ constructor(n, t, r) { this.from = n, this.to = t, this.type = r; } /** @internal */ copy(n, t) { return new E(n, t, this.type); } /** @internal */ eq(n, t = 0) { return this.type.eq(n.type) && this.from + t == n.from && this.to + t == n.to; } /** @internal */ map(n, t, r) { return this.type.map(n, this, t, r); } /** Creates a widget decoration, which is a DOM node that's shown in the document at the given position. It is recommended that you delay rendering the widget by passing a function that will be called when the widget is actually drawn in a view, but you can also directly pass a DOM node. `getPos` can be used to find the widget's current document position. */ static widget(n, t, r) { return new E(n, n, new te(t, r)); } /** Creates an inline decoration, which adds the given attributes to each inline node between `from` and `to`. */ static inline(n, t, r, o) { return new E(n, t, new P(r, o)); } /** Creates a node decoration. `from` and `to` should point precisely before and after a node in the document. That node, and only that node, will receive the given attributes. */ static node(n, t, r, o) { return new E(n, t, new ke(r, o)); } /** The spec provided when creating this decoration. Can be useful if you've stored extra information in that object. */ get spec() { return this.type.spec; } /** @internal */ get inline() { return this.type instanceof P; } /** @internal */ get widget() { return this.type instanceof te; } } const W = [], L = {}; class g { /** @internal */ constructor(n, t) { this.local = n.length ? n : W, this.children = t.length ? t : W; } /** Create a set of decorations, using the structure of the given document. This will consume (modify) the `decorations` array, so you must make a copy if you want need to preserve that. */ static create(n, t) { return t.length ? ne(t, n, 0, L) : b; } /** Find all decorations in this set which touch the given range (including decorations that start or end directly at the boundaries) and match the given predicate on their spec. When `start` and `end` are omitted, all decorations in the set are considered. When `predicate` isn't given, all decorations are assumed to match. */ find(n, t, r) { let o = []; return this.findInner(n ?? 0, t ?? 1e9, o, 0, r), o; } findInner(n, t, r, o, l) { for (let s = 0; s < this.local.length; s++) { let i = this.local[s]; i.from <= t && i.to >= n && (!l || l(i.spec)) && r.push(i.copy(i.from + o, i.to + o)); } for (let s = 0; s < this.children.length; s += 3) if (this.children[s] < t && this.children[s + 1] > n) { let i = this.children[s] + 1; this.children[s + 2].findInner(n - i, t - i, r, o + i, l); } } /** Map the set of decorations in response to a change in the document. */ map(n, t, r) { return this == b || n.maps.length == 0 ? this : this.mapInner(n, t, 0, 0, r || L); } /** @internal */ mapInner(n, t, r, o, l) { let s; for (let i = 0; i < this.local.length; i++) { let a = this.local[i].map(n, r, o); a && a.type.valid(t, a) ? (s || (s = [])).push(a) : l.onRemove && l.onRemove(this.local[i].spec); } return this.children.length ? on(this.children, s || [], n, t, r, o, l) : s ? new g(s.sort(z), W) : b; } /** Add the given array of decorations to the ones in the set, producing a new set. Consumes the `decorations` array. Needs access to the current document to create the appropriate tree structure. */ add(n, t) { return t.length ? this == b ? g.create(n, t) : this.addInner(n, t, 0) : this; } addInner(n, t, r) { let o, l = 0; n.forEach((i, a) => { let c = a + r, f; if (f = at(t, i, c)) { for (o || (o = this.children.slice()); l < o.length && o[l] < a; ) l += 3; o[l] == a ? o[l + 2] = o[l + 2].addInner(i, f, c + 1) : o.splice(l, 0, a, a + i.nodeSize, ne(f, i, c + 1, L)), l += 3; } }); let s = it(l ? ct(t) : t, -r); for (let i = 0; i < s.length; i++) s[i].type.valid(n, s[i]) || s.splice(i--, 1); return new g(s.length ? this.local.concat(s).sort(z) : this.local, o || this.children); } /** Create a new set that contains the decorations in this set, minus the ones in the given array. */ remove(n) { return n.length == 0 || this == b ? this : this.removeInner(n, 0); } removeInner(n, t) { let r = this.children, o = this.local; for (let l = 0; l < r.length; l += 3) { let s, i = r[l] + t, a = r[l + 1] + t; for (let f = 0, u; f < n.length; f++) (u = n[f]) && u.from > i && u.to < a && (n[f] = null, (s || (s = [])).push(u)); if (!s) continue; r == this.children && (r = this.children.slice()); let c = r[l + 2].removeInner(s, i + 1); c != b ? r[l + 2] = c : (r.splice(l, 3), l -= 3); } if (o.length) { for (let l = 0, s; l < n.length; l++) if (s = n[l]) for (let i = 0; i < o.length; i++) o[i].eq(s, t) && (o == this.local && (o = this.local.slice()), o.splice(i--, 1)); } return r == this.children && o == this.local ? this : o.length || r.length ? new g(o, r) : b; } forChild(n, t) { if (this == b) return this; if (t.isLeaf) return g.empty; let r, o; for (let i = 0; i < this.children.length; i += 3) if (this.children[i] >= n) { this.children[i] == n && (r = this.children[i + 2]); break; } let l = n + 1, s = l + t.content.size; for (let i = 0; i < this.local.length; i++) { let a = this.local[i]; if (a.from < s && a.to > l && a.type instanceof P) { let c = Math.max(l, a.from) - l, f = Math.min(s, a.to) - l; c < f && (o || (o = [])).push(a.copy(c, f)); } } if (o) { let i = new g(o.sort(z), W); return r ? new R([i, r]) : i; } return r || b; } /** @internal */ eq(n) { if (this == n) return !0; i