UNPKG

devi-rich-editor

Version:

Reusable Rich Text Editor built with TipTap and React.

1,562 lines (1,558 loc) 833 kB
import ae, { forwardRef as gg, useRef as wa, useState as hn, useDebugValue as kd, useEffect as Aa, createContext as xd, useContext as yg, useLayoutEffect as bg, useCallback as Kc } from "react"; import Sg from "react-dom"; var pl = { exports: {} }, yr = {}; /** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var qc; function kg() { if (qc) return yr; qc = 1; var n = ae, e = Symbol.for("react.element"), t = Symbol.for("react.fragment"), r = Object.prototype.hasOwnProperty, i = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, s = { key: !0, ref: !0, __self: !0, __source: !0 }; function o(l, a, c) { var u, f = {}, d = null, h = null; c !== void 0 && (d = "" + c), a.key !== void 0 && (d = "" + a.key), a.ref !== void 0 && (h = a.ref); for (u in a) r.call(a, u) && !s.hasOwnProperty(u) && (f[u] = a[u]); if (l && l.defaultProps) for (u in a = l.defaultProps, a) f[u] === void 0 && (f[u] = a[u]); return { $$typeof: e, type: l, key: d, ref: h, props: f, _owner: i.current }; } return yr.Fragment = t, yr.jsx = o, yr.jsxs = o, yr; } var br = {}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Jc; function xg() { return Jc || (Jc = 1, process.env.NODE_ENV !== "production" && function() { var n = ae, e = Symbol.for("react.element"), t = Symbol.for("react.portal"), r = Symbol.for("react.fragment"), i = Symbol.for("react.strict_mode"), s = Symbol.for("react.profiler"), o = Symbol.for("react.provider"), l = Symbol.for("react.context"), a = Symbol.for("react.forward_ref"), c = Symbol.for("react.suspense"), u = Symbol.for("react.suspense_list"), f = Symbol.for("react.memo"), d = Symbol.for("react.lazy"), h = Symbol.for("react.offscreen"), p = Symbol.iterator, m = "@@iterator"; function g(y) { if (y === null || typeof y != "object") return null; var k = p && y[p] || y[m]; return typeof k == "function" ? k : null; } var b = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function S(y) { { for (var k = arguments.length, O = new Array(k > 1 ? k - 1 : 0), v = 1; v < k; v++) O[v - 1] = arguments[v]; T("error", y, O); } } function T(y, k, O) { { var v = b.ReactDebugCurrentFrame, K = v.getStackAddendum(); K !== "" && (k += "%s", O = O.concat([K])); var U = O.map(function(W) { return String(W); }); U.unshift("Warning: " + k), Function.prototype.apply.call(console[y], console, U); } } var w = !1, E = !1, A = !1, P = !1, V = !1, R; R = Symbol.for("react.module.reference"); function ie(y) { return !!(typeof y == "string" || typeof y == "function" || y === r || y === s || V || y === i || y === c || y === u || P || y === h || w || E || A || typeof y == "object" && y !== null && (y.$$typeof === d || y.$$typeof === f || y.$$typeof === o || y.$$typeof === l || y.$$typeof === a || // This needs to include all possible module reference object // types supported by any Flight configuration anywhere since // we don't know which Flight build this will end up being used // with. y.$$typeof === R || y.getModuleId !== void 0)); } function He(y, k, O) { var v = y.displayName; if (v) return v; var K = k.displayName || k.name || ""; return K !== "" ? O + "(" + K + ")" : O; } function $e(y) { return y.displayName || "Context"; } function me(y) { if (y == null) return null; if (typeof y.tag == "number" && S("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof y == "function") return y.displayName || y.name || null; if (typeof y == "string") return y; switch (y) { case r: return "Fragment"; case t: return "Portal"; case s: return "Profiler"; case i: return "StrictMode"; case c: return "Suspense"; case u: return "SuspenseList"; } if (typeof y == "object") switch (y.$$typeof) { case l: var k = y; return $e(k) + ".Consumer"; case o: var O = y; return $e(O._context) + ".Provider"; case a: return He(y, y.render, "ForwardRef"); case f: var v = y.displayName || null; return v !== null ? v : me(y.type) || "Memo"; case d: { var K = y, U = K._payload, W = K._init; try { return me(W(U)); } catch { return null; } } } return null; } var Me = Object.assign, Je = 0, je, Ue, Mc, Oc, wc, Ac, Nc; function Dc() { } Dc.__reactDisabledLog = !0; function Wm() { { if (Je === 0) { je = console.log, Ue = console.info, Mc = console.warn, Oc = console.error, wc = console.group, Ac = console.groupCollapsed, Nc = console.groupEnd; var y = { configurable: !0, enumerable: !0, value: Dc, writable: !0 }; Object.defineProperties(console, { info: y, log: y, warn: y, error: y, group: y, groupCollapsed: y, groupEnd: y }); } Je++; } } function _m() { { if (Je--, Je === 0) { var y = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: Me({}, y, { value: je }), info: Me({}, y, { value: Ue }), warn: Me({}, y, { value: Mc }), error: Me({}, y, { value: Oc }), group: Me({}, y, { value: wc }), groupCollapsed: Me({}, y, { value: Ac }), groupEnd: Me({}, y, { value: Nc }) }); } Je < 0 && S("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var bo = b.ReactCurrentDispatcher, So; function yi(y, k, O) { { if (So === void 0) try { throw Error(); } catch (K) { var v = K.stack.trim().match(/\n( *(at )?)/); So = v && v[1] || ""; } return ` ` + So + y; } } var ko = !1, bi; { var Km = typeof WeakMap == "function" ? WeakMap : Map; bi = new Km(); } function Rc(y, k) { if (!y || ko) return ""; { var O = bi.get(y); if (O !== void 0) return O; } var v; ko = !0; var K = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var U; U = bo.current, bo.current = null, Wm(); try { if (k) { var W = function() { throw Error(); }; if (Object.defineProperty(W.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(W, []); } catch (Le) { v = Le; } Reflect.construct(y, [], W); } else { try { W.call(); } catch (Le) { v = Le; } y.call(W.prototype); } } else { try { throw Error(); } catch (Le) { v = Le; } y(); } } catch (Le) { if (Le && v && typeof Le.stack == "string") { for (var F = Le.stack.split(` `), Oe = v.stack.split(` `), ne = F.length - 1, se = Oe.length - 1; ne >= 1 && se >= 0 && F[ne] !== Oe[se]; ) se--; for (; ne >= 1 && se >= 0; ne--, se--) if (F[ne] !== Oe[se]) { if (ne !== 1 || se !== 1) do if (ne--, se--, se < 0 || F[ne] !== Oe[se]) { var Ge = ` ` + F[ne].replace(" at new ", " at "); return y.displayName && Ge.includes("<anonymous>") && (Ge = Ge.replace("<anonymous>", y.displayName)), typeof y == "function" && bi.set(y, Ge), Ge; } while (ne >= 1 && se >= 0); break; } } } finally { ko = !1, bo.current = U, _m(), Error.prepareStackTrace = K; } var Bn = y ? y.displayName || y.name : "", rn = Bn ? yi(Bn) : ""; return typeof y == "function" && bi.set(y, rn), rn; } function qm(y, k, O) { return Rc(y, !1); } function Jm(y) { var k = y.prototype; return !!(k && k.isReactComponent); } function Si(y, k, O) { if (y == null) return ""; if (typeof y == "function") return Rc(y, Jm(y)); if (typeof y == "string") return yi(y); switch (y) { case c: return yi("Suspense"); case u: return yi("SuspenseList"); } if (typeof y == "object") switch (y.$$typeof) { case a: return qm(y.render); case f: return Si(y.type, k, O); case d: { var v = y, K = v._payload, U = v._init; try { return Si(U(K), k, O); } catch { } } } return ""; } var mr = Object.prototype.hasOwnProperty, vc = {}, Ic = b.ReactDebugCurrentFrame; function ki(y) { if (y) { var k = y._owner, O = Si(y.type, y._source, k ? k.type : null); Ic.setExtraStackFrame(O); } else Ic.setExtraStackFrame(null); } function Um(y, k, O, v, K) { { var U = Function.call.bind(mr); for (var W in y) if (U(y, W)) { var F = void 0; try { if (typeof y[W] != "function") { var Oe = Error((v || "React class") + ": " + O + " type `" + W + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof y[W] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw Oe.name = "Invariant Violation", Oe; } F = y[W](k, W, v, O, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (ne) { F = ne; } F && !(F instanceof Error) && (ki(K), S("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", v || "React class", O, W, typeof F), ki(null)), F instanceof Error && !(F.message in vc) && (vc[F.message] = !0, ki(K), S("Failed %s type: %s", O, F.message), ki(null)); } } } var Gm = Array.isArray; function xo(y) { return Gm(y); } function Ym(y) { { var k = typeof Symbol == "function" && Symbol.toStringTag, O = k && y[Symbol.toStringTag] || y.constructor.name || "Object"; return O; } } function Xm(y) { try { return Pc(y), !1; } catch { return !0; } } function Pc(y) { return "" + y; } function $c(y) { if (Xm(y)) return S("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Ym(y)), Pc(y); } var gr = b.ReactCurrentOwner, Qm = { key: !0, ref: !0, __self: !0, __source: !0 }, Lc, zc, Co; Co = {}; function Zm(y) { if (mr.call(y, "ref")) { var k = Object.getOwnPropertyDescriptor(y, "ref").get; if (k && k.isReactWarning) return !1; } return y.ref !== void 0; } function eg(y) { if (mr.call(y, "key")) { var k = Object.getOwnPropertyDescriptor(y, "key").get; if (k && k.isReactWarning) return !1; } return y.key !== void 0; } function tg(y, k) { if (typeof y.ref == "string" && gr.current && k && gr.current.stateNode !== k) { var O = me(gr.current.type); Co[O] || (S('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', me(gr.current.type), y.ref), Co[O] = !0); } } function ng(y, k) { { var O = function() { Lc || (Lc = !0, S("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", k)); }; O.isReactWarning = !0, Object.defineProperty(y, "key", { get: O, configurable: !0 }); } } function rg(y, k) { { var O = function() { zc || (zc = !0, S("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", k)); }; O.isReactWarning = !0, Object.defineProperty(y, "ref", { get: O, configurable: !0 }); } } var ig = function(y, k, O, v, K, U, W) { var F = { // This tag allows us to uniquely identify this as a React Element $$typeof: e, // Built-in properties that belong on the element type: y, key: k, ref: O, props: W, // Record the component responsible for creating this element. _owner: U }; return F._store = {}, Object.defineProperty(F._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: !1 }), Object.defineProperty(F, "_self", { configurable: !1, enumerable: !1, writable: !1, value: v }), Object.defineProperty(F, "_source", { configurable: !1, enumerable: !1, writable: !1, value: K }), Object.freeze && (Object.freeze(F.props), Object.freeze(F)), F; }; function sg(y, k, O, v, K) { { var U, W = {}, F = null, Oe = null; O !== void 0 && ($c(O), F = "" + O), eg(k) && ($c(k.key), F = "" + k.key), Zm(k) && (Oe = k.ref, tg(k, K)); for (U in k) mr.call(k, U) && !Qm.hasOwnProperty(U) && (W[U] = k[U]); if (y && y.defaultProps) { var ne = y.defaultProps; for (U in ne) W[U] === void 0 && (W[U] = ne[U]); } if (F || Oe) { var se = typeof y == "function" ? y.displayName || y.name || "Unknown" : y; F && ng(W, se), Oe && rg(W, se); } return ig(y, F, Oe, K, v, gr.current, W); } } var To = b.ReactCurrentOwner, Bc = b.ReactDebugCurrentFrame; function zn(y) { if (y) { var k = y._owner, O = Si(y.type, y._source, k ? k.type : null); Bc.setExtraStackFrame(O); } else Bc.setExtraStackFrame(null); } var Eo; Eo = !1; function Mo(y) { return typeof y == "object" && y !== null && y.$$typeof === e; } function Fc() { { if (To.current) { var y = me(To.current.type); if (y) return ` Check the render method of \`` + y + "`."; } return ""; } } function og(y) { { if (y !== void 0) { var k = y.fileName.replace(/^.*[\\\/]/, ""), O = y.lineNumber; return ` Check your code at ` + k + ":" + O + "."; } return ""; } } var Vc = {}; function lg(y) { { var k = Fc(); if (!k) { var O = typeof y == "string" ? y : y.displayName || y.name; O && (k = ` Check the top-level render call using <` + O + ">."); } return k; } } function Hc(y, k) { { if (!y._store || y._store.validated || y.key != null) return; y._store.validated = !0; var O = lg(k); if (Vc[O]) return; Vc[O] = !0; var v = ""; y && y._owner && y._owner !== To.current && (v = " It was passed a child from " + me(y._owner.type) + "."), zn(y), S('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', O, v), zn(null); } } function jc(y, k) { { if (typeof y != "object") return; if (xo(y)) for (var O = 0; O < y.length; O++) { var v = y[O]; Mo(v) && Hc(v, k); } else if (Mo(y)) y._store && (y._store.validated = !0); else if (y) { var K = g(y); if (typeof K == "function" && K !== y.entries) for (var U = K.call(y), W; !(W = U.next()).done; ) Mo(W.value) && Hc(W.value, k); } } } function ag(y) { { var k = y.type; if (k == null || typeof k == "string") return; var O; if (typeof k == "function") O = k.propTypes; else if (typeof k == "object" && (k.$$typeof === a || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. k.$$typeof === f)) O = k.propTypes; else return; if (O) { var v = me(k); Um(O, y.props, "prop", v, y); } else if (k.PropTypes !== void 0 && !Eo) { Eo = !0; var K = me(k); S("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", K || "Unknown"); } typeof k.getDefaultProps == "function" && !k.getDefaultProps.isReactClassApproved && S("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function cg(y) { { for (var k = Object.keys(y.props), O = 0; O < k.length; O++) { var v = k[O]; if (v !== "children" && v !== "key") { zn(y), S("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", v), zn(null); break; } } y.ref !== null && (zn(y), S("Invalid attribute `ref` supplied to `React.Fragment`."), zn(null)); } } var Wc = {}; function _c(y, k, O, v, K, U) { { var W = ie(y); if (!W) { var F = ""; (y === void 0 || typeof y == "object" && y !== null && Object.keys(y).length === 0) && (F += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."); var Oe = og(K); Oe ? F += Oe : F += Fc(); var ne; y === null ? ne = "null" : xo(y) ? ne = "array" : y !== void 0 && y.$$typeof === e ? (ne = "<" + (me(y.type) || "Unknown") + " />", F = " Did you accidentally export a JSX literal instead of a component?") : ne = typeof y, S("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", ne, F); } var se = sg(y, k, O, K, U); if (se == null) return se; if (W) { var Ge = k.children; if (Ge !== void 0) if (v) if (xo(Ge)) { for (var Bn = 0; Bn < Ge.length; Bn++) jc(Ge[Bn], y); Object.freeze && Object.freeze(Ge); } else S("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."); else jc(Ge, y); } if (mr.call(k, "key")) { var rn = me(y), Le = Object.keys(k).filter(function(mg) { return mg !== "key"; }), Oo = Le.length > 0 ? "{key: someKey, " + Le.join(": ..., ") + ": ...}" : "{key: someKey}"; if (!Wc[rn + Oo]) { var pg = Le.length > 0 ? "{" + Le.join(": ..., ") + ": ...}" : "{}"; S(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`, Oo, rn, pg, rn), Wc[rn + Oo] = !0; } } return y === r ? cg(se) : ag(se), se; } } function ug(y, k, O) { return _c(y, k, O, !0); } function fg(y, k, O) { return _c(y, k, O, !1); } var dg = fg, hg = ug; br.Fragment = r, br.jsx = dg, br.jsxs = hg; }()), br; } process.env.NODE_ENV === "production" ? pl.exports = kg() : pl.exports = xg(); var I = pl.exports; function ge(n) { this.content = n; } ge.prototype = { constructor: ge, find: function(n) { for (var e = 0; e < this.content.length; e += 2) if (this.content[e] === n) return e; return -1; }, // :: (string) → ?any // Retrieve the value stored under `key`, or return undefined when // no such key exists. get: function(n) { var e = this.find(n); return e == -1 ? void 0 : this.content[e + 1]; }, // :: (string, any, ?string) → OrderedMap // Create a new map by replacing the value of `key` with a new // value, or adding a binding to the end of the map. If `newKey` is // given, the key of the binding will be replaced with that key. update: function(n, e, t) { var r = t && t != n ? this.remove(t) : this, i = r.find(n), s = r.content.slice(); return i == -1 ? s.push(t || n, e) : (s[i + 1] = e, t && (s[i] = t)), new ge(s); }, // :: (string) → OrderedMap // Return a map with the given key removed, if it existed. remove: function(n) { var e = this.find(n); if (e == -1) return this; var t = this.content.slice(); return t.splice(e, 2), new ge(t); }, // :: (string, any) → OrderedMap // Add a new key to the start of the map. addToStart: function(n, e) { return new ge([n, e].concat(this.remove(n).content)); }, // :: (string, any) → OrderedMap // Add a new key to the end of the map. addToEnd: function(n, e) { var t = this.remove(n).content.slice(); return t.push(n, e), new ge(t); }, // :: (string, string, any) → OrderedMap // Add a key after the given key. If `place` is not found, the new // key is added to the end. addBefore: function(n, e, t) { var r = this.remove(e), i = r.content.slice(), s = r.find(n); return i.splice(s == -1 ? i.length : s, 0, e, t), new ge(i); }, // :: ((key: string, value: any)) // Call the given function for each key/value pair in the map, in // order. forEach: function(n) { for (var e = 0; e < this.content.length; e += 2) n(this.content[e], this.content[e + 1]); }, // :: (union<Object, OrderedMap>) → OrderedMap // Create a new map by prepending the keys in this map that don't // appear in `map` before the keys in `map`. prepend: function(n) { return n = ge.from(n), n.size ? new ge(n.content.concat(this.subtract(n).content)) : this; }, // :: (union<Object, OrderedMap>) → OrderedMap // Create a new map by appending the keys in this map that don't // appear in `map` after the keys in `map`. append: function(n) { return n = ge.from(n), n.size ? new ge(this.subtract(n).content.concat(n.content)) : this; }, // :: (union<Object, OrderedMap>) → OrderedMap // Create a map containing all the keys in this map that don't // appear in `map`. subtract: function(n) { var e = this; n = ge.from(n); for (var t = 0; t < n.content.length; t += 2) e = e.remove(n.content[t]); return e; }, // :: () → Object // Turn ordered map into a plain object. toObject: function() { var n = {}; return this.forEach(function(e, t) { n[e] = t; }), n; }, // :: number // The amount of keys in this map. get size() { return this.content.length >> 1; } }; ge.from = function(n) { if (n instanceof ge) return n; var e = []; if (n) for (var t in n) e.push(t, n[t]); return new ge(e); }; function Cd(n, e, t) { for (let r = 0; ; r++) { if (r == n.childCount || r == e.childCount) return n.childCount == e.childCount ? null : t; let i = n.child(r), s = e.child(r); if (i == s) { t += i.nodeSize; continue; } if (!i.sameMarkup(s)) return t; if (i.isText && i.text != s.text) { for (let o = 0; i.text[o] == s.text[o]; o++) t++; return t; } if (i.content.size || s.content.size) { let o = Cd(i.content, s.content, t + 1); if (o != null) return o; } t += i.nodeSize; } } function Td(n, e, t, r) { for (let i = n.childCount, s = e.childCount; ; ) { if (i == 0 || s == 0) return i == s ? null : { a: t, b: r }; let o = n.child(--i), l = e.child(--s), a = o.nodeSize; if (o == l) { t -= a, r -= a; continue; } if (!o.sameMarkup(l)) return { a: t, b: r }; if (o.isText && o.text != l.text) { let c = 0, u = Math.min(o.text.length, l.text.length); for (; c < u && o.text[o.text.length - c - 1] == l.text[l.text.length - c - 1]; ) c++, t--, r--; return { a: t, b: r }; } if (o.content.size || l.content.size) { let c = Td(o.content, l.content, t - 1, r - 1); if (c) return c; } t -= a, r -= a; } } let $ = class we { /** @internal */ constructor(e, t) { if (this.content = e, this.size = t || 0, t == null) for (let r = 0; r < e.length; r++) this.size += e[r].nodeSize; } /** Invoke a callback for all descendant nodes between the given two positions (relative to start of this fragment). Doesn't descend into a node when the callback returns `false`. */ nodesBetween(e, t, r, i = 0, s) { for (let o = 0, l = 0; l < t; o++) { let a = this.content[o], c = l + a.nodeSize; if (c > e && r(a, i + l, s || null, o) !== !1 && a.content.size) { let u = l + 1; a.nodesBetween(Math.max(0, e - u), Math.min(a.content.size, t - u), r, i + u); } l = c; } } /** Call the given callback for every descendant node. `pos` will be relative to the start of the fragment. The callback may return `false` to prevent traversal of a given node's children. */ descendants(e) { this.nodesBetween(0, this.size, e); } /** Extract the text between `from` and `to`. See the same method on [`Node`](https://prosemirror.net/docs/ref/#model.Node.textBetween). */ textBetween(e, t, r, i) { let s = "", o = !0; return this.nodesBetween(e, t, (l, a) => { l.isText ? (s += l.text.slice(Math.max(e, a) - a, t - a), o = !r) : l.isLeaf ? (i ? s += typeof i == "function" ? i(l) : i : l.type.spec.leafText && (s += l.type.spec.leafText(l)), o = !r) : !o && l.isBlock && (s += r, o = !0); }, 0), s; } /** Create a new fragment containing the combined content of this fragment and the other. */ append(e) { if (!e.size) return this; if (!this.size) return e; let t = this.lastChild, r = e.firstChild, i = this.content.slice(), s = 0; for (t.isText && t.sameMarkup(r) && (i[i.length - 1] = t.withText(t.text + r.text), s = 1); s < e.content.length; s++) i.push(e.content[s]); return new we(i, this.size + e.size); } /** Cut out the sub-fragment between the two given positions. */ cut(e, t = this.size) { if (e == 0 && t == this.size) return this; let r = [], i = 0; if (t > e) for (let s = 0, o = 0; o < t; s++) { let l = this.content[s], a = o + l.nodeSize; a > e && ((o < e || a > t) && (l.isText ? l = l.cut(Math.max(0, e - o), Math.min(l.text.length, t - o)) : l = l.cut(Math.max(0, e - o - 1), Math.min(l.content.size, t - o - 1))), r.push(l), i += l.nodeSize), o = a; } return new we(r, i); } /** @internal */ cutByIndex(e, t) { return e == t ? we.empty : e == 0 && t == this.content.length ? this : new we(this.content.slice(e, t)); } /** Create a new fragment in which the node at the given index is replaced by the given node. */ replaceChild(e, t) { let r = this.content[e]; if (r == t) return this; let i = this.content.slice(), s = this.size + t.nodeSize - r.nodeSize; return i[e] = t, new we(i, s); } /** Create a new fragment by prepending the given node to this fragment. */ addToStart(e) { return new we([e].concat(this.content), this.size + e.nodeSize); } /** Create a new fragment by appending the given node to this fragment. */ addToEnd(e) { return new we(this.content.concat(e), this.size + e.nodeSize); } /** Compare this fragment to another one. */ eq(e) { if (this.content.length != e.content.length) return !1; for (let t = 0; t < this.content.length; t++) if (!this.content[t].eq(e.content[t])) return !1; return !0; } /** The first child of the fragment, or `null` if it is empty. */ get firstChild() { return this.content.length ? this.content[0] : null; } /** The last child of the fragment, or `null` if it is empty. */ get lastChild() { return this.content.length ? this.content[this.content.length - 1] : null; } /** The number of child nodes in this fragment. */ get childCount() { return this.content.length; } /** Get the child node at the given index. Raise an error when the index is out of range. */ child(e) { let t = this.content[e]; if (!t) throw new RangeError("Index " + e + " out of range for " + this); return t; } /** Get the child node at the given index, if it exists. */ maybeChild(e) { return this.content[e] || null; } /** Call `f` for every child node, passing the node, its offset into this parent node, and its index. */ forEach(e) { for (let t = 0, r = 0; t < this.content.length; t++) { let i = this.content[t]; e(i, r, t), r += i.nodeSize; } } /** Find the first position at which this fragment and another fragment differ, or `null` if they are the same. */ findDiffStart(e, t = 0) { return Cd(this, e, t); } /** Find the first position, searching from the end, at which this fragment and the given fragment differ, or `null` if they are the same. Since this position will not be the same in both nodes, an object with two separate positions is returned. */ findDiffEnd(e, t = this.size, r = e.size) { return Td(this, e, t, r); } /** Find the index and inner offset corresponding to a given relative position in this fragment. The result object will be reused (overwritten) the next time the function is called. (Not public.) */ findIndex(e, t = -1) { if (e == 0) return xi(0, e); if (e == this.size) return xi(this.content.length, e); if (e > this.size || e < 0) throw new RangeError(`Position ${e} outside of fragment (${this})`); for (let r = 0, i = 0; ; r++) { let s = this.child(r), o = i + s.nodeSize; if (o >= e) return o == e || t > 0 ? xi(r + 1, o) : xi(r, i); i = o; } } /** Return a debugging string that describes this fragment. */ toString() { return "<" + this.toStringInner() + ">"; } /** @internal */ toStringInner() { return this.content.join(", "); } /** Create a JSON-serializeable representation of this fragment. */ toJSON() { return this.content.length ? this.content.map((e) => e.toJSON()) : null; } /** Deserialize a fragment from its JSON representation. */ static fromJSON(e, t) { if (!t) return we.empty; if (!Array.isArray(t)) throw new RangeError("Invalid input for Fragment.fromJSON"); return new we(t.map(e.nodeFromJSON)); } /** Build a fragment from an array of nodes. Ensures that adjacent text nodes with the same marks are joined together. */ static fromArray(e) { if (!e.length) return we.empty; let t, r = 0; for (let i = 0; i < e.length; i++) { let s = e[i]; r += s.nodeSize, i && s.isText && e[i - 1].sameMarkup(s) ? (t || (t = e.slice(0, i)), t[t.length - 1] = s.withText(t[t.length - 1].text + s.text)) : t && t.push(s); } return new we(t || e, r); } /** Create a fragment from something that can be interpreted as a set of nodes. For `null`, it returns the empty fragment. For a fragment, the fragment itself. For a node or array of nodes, a fragment containing those nodes. */ static from(e) { if (!e) return we.empty; if (e instanceof we) return e; if (Array.isArray(e)) return this.fromArray(e); if (e.attrs) return new we([e], e.nodeSize); throw new RangeError("Can not convert " + e + " to a Fragment" + (e.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : "")); } }; $.empty = new $([], 0); const wo = { index: 0, offset: 0 }; function xi(n, e) { return wo.index = n, wo.offset = e, wo; } function Gi(n, e) { if (n === e) return !0; if (!(n && typeof n == "object") || !(e && typeof e == "object")) return !1; let t = Array.isArray(n); if (Array.isArray(e) != t) return !1; if (t) { if (n.length != e.length) return !1; for (let r = 0; r < n.length; r++) if (!Gi(n[r], e[r])) return !1; } else { for (let r in n) if (!(r in e) || !Gi(n[r], e[r])) return !1; for (let r in e) if (!(r in n)) return !1; } return !0; } let ue = class ml { /** @internal */ constructor(e, t) { this.type = e, this.attrs = t; } /** Given a set of marks, create a new set which contains this one as well, in the right position. If this mark is already in the set, the set itself is returned. If any marks that are set to be [exclusive](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) with this mark are present, those are replaced by this one. */ addToSet(e) { let t, r = !1; for (let i = 0; i < e.length; i++) { let s = e[i]; if (this.eq(s)) return e; if (this.type.excludes(s.type)) t || (t = e.slice(0, i)); else { if (s.type.excludes(this.type)) return e; !r && s.type.rank > this.type.rank && (t || (t = e.slice(0, i)), t.push(this), r = !0), t && t.push(s); } } return t || (t = e.slice()), r || t.push(this), t; } /** Remove this mark from the given set, returning a new set. If this mark is not in the set, the set itself is returned. */ removeFromSet(e) { for (let t = 0; t < e.length; t++) if (this.eq(e[t])) return e.slice(0, t).concat(e.slice(t + 1)); return e; } /** Test whether this mark is in the given set of marks. */ isInSet(e) { for (let t = 0; t < e.length; t++) if (this.eq(e[t])) return !0; return !1; } /** Test whether this mark has the same type and attributes as another mark. */ eq(e) { return this == e || this.type == e.type && Gi(this.attrs, e.attrs); } /** Convert this mark to a JSON-serializeable representation. */ toJSON() { let e = { type: this.type.name }; for (let t in this.attrs) { e.attrs = this.attrs; break; } return e; } /** Deserialize a mark from JSON. */ static fromJSON(e, t) { if (!t) throw new RangeError("Invalid input for Mark.fromJSON"); let r = e.marks[t.type]; if (!r) throw new RangeError(`There is no mark type ${t.type} in this schema`); return r.create(t.attrs); } /** Test whether two sets of marks are identical. */ static sameSet(e, t) { if (e == t) return !0; if (e.length != t.length) return !1; for (let r = 0; r < e.length; r++) if (!e[r].eq(t[r])) return !1; return !0; } /** Create a properly sorted mark set from null, a single mark, or an unsorted array of marks. */ static setFrom(e) { if (!e || Array.isArray(e) && e.length == 0) return ml.none; if (e instanceof ml) return [e]; let t = e.slice(); return t.sort((r, i) => r.type.rank - i.type.rank), t; } }; ue.none = []; let gl = class extends Error { }, q = class Wn { /** Create a slice. When specifying a non-zero open depth, you must make sure that there are nodes of at least that depth at the appropriate side of the fragment—i.e. if the fragment is an empty paragraph node, `openStart` and `openEnd` can't be greater than 1. It is not necessary for the content of open nodes to conform to the schema's content constraints, though it should be a valid start/end/middle for such a node, depending on which sides are open. */ constructor(e, t, r) { this.content = e, this.openStart = t, this.openEnd = r; } /** The size this slice would add when inserted into a document. */ get size() { return this.content.size - this.openStart - this.openEnd; } /** @internal */ insertAt(e, t) { let r = Md(this.content, e + this.openStart, t); return r && new Wn(r, this.openStart, this.openEnd); } /** @internal */ removeBetween(e, t) { return new Wn(Ed(this.content, e + this.openStart, t + this.openStart), this.openStart, this.openEnd); } /** Tests whether this slice is equal to another slice. */ eq(e) { return this.content.eq(e.content) && this.openStart == e.openStart && this.openEnd == e.openEnd; } /** @internal */ toString() { return this.content + "(" + this.openStart + "," + this.openEnd + ")"; } /** Convert a slice to a JSON-serializable representation. */ toJSON() { if (!this.content.size) return null; let e = { content: this.content.toJSON() }; return this.openStart > 0 && (e.openStart = this.openStart), this.openEnd > 0 && (e.openEnd = this.openEnd), e; } /** Deserialize a slice from its JSON representation. */ static fromJSON(e, t) { if (!t) return Wn.empty; let r = t.openStart || 0, i = t.openEnd || 0; if (typeof r != "number" || typeof i != "number") throw new RangeError("Invalid input for Slice.fromJSON"); return new Wn($.fromJSON(e, t.content), r, i); } /** Create a slice from a fragment by taking the maximum possible open value on both side of the fragment. */ static maxOpen(e, t = !0) { let r = 0, i = 0; for (let s = e.firstChild; s && !s.isLeaf && (t || !s.type.spec.isolating); s = s.firstChild) r++; for (let s = e.lastChild; s && !s.isLeaf && (t || !s.type.spec.isolating); s = s.lastChild) i++; return new Wn(e, r, i); } }; q.empty = new q($.empty, 0, 0); function Ed(n, e, t) { let { index: r, offset: i } = n.findIndex(e), s = n.maybeChild(r), { index: o, offset: l } = n.findIndex(t); if (i == e || s.isText) { if (l != t && !n.child(o).isText) throw new RangeError("Removing non-flat range"); return n.cut(0, e).append(n.cut(t)); } if (r != o) throw new RangeError("Removing non-flat range"); return n.replaceChild(r, s.copy(Ed(s.content, e - i - 1, t - i - 1))); } function Md(n, e, t, r) { let { index: i, offset: s } = n.findIndex(e), o = n.maybeChild(i); if (s == e || o.isText) return r && !r.canReplace(i, i, t) ? null : n.cut(0, e).append(t).append(n.cut(e)); let l = Md(o.content, e - s - 1, t); return l && n.replaceChild(i, o.copy(l)); } function Cg(n, e, t) { if (t.openStart > n.depth) throw new gl("Inserted content deeper than insertion position"); if (n.depth - t.openStart != e.depth - t.openEnd) throw new gl("Inconsistent open depths"); return Od(n, e, t, 0); } function Od(n, e, t, r) { let i = n.index(r), s = n.node(r); if (i == e.index(r) && r < n.depth - t.openStart) { let o = Od(n, e, t, r + 1); return s.copy(s.content.replaceChild(i, o)); } else if (t.content.size) if (!t.openStart && !t.openEnd && n.depth == r && e.depth == r) { let o = n.parent, l = o.content; return mn(o, l.cut(0, n.parentOffset).append(t.content).append(l.cut(e.parentOffset))); } else { let { start: o, end: l } = Tg(t, n); return mn(s, Ad(n, o, l, e, r)); } else return mn(s, Yi(n, e, r)); } function wd(n, e) { if (!e.type.compatibleContent(n.type)) throw new gl("Cannot join " + e.type.name + " onto " + n.type.name); } function yl(n, e, t) { let r = n.node(t); return wd(r, e.node(t)), r; } function pn(n, e) { let t = e.length - 1; t >= 0 && n.isText && n.sameMarkup(e[t]) ? e[t] = n.withText(e[t].text + n.text) : e.push(n); } function Ar(n, e, t, r) { let i = (e || n).node(t), s = 0, o = e ? e.index(t) : i.childCount; n && (s = n.index(t), n.depth > t ? s++ : n.textOffset && (pn(n.nodeAfter, r), s++)); for (let l = s; l < o; l++) pn(i.child(l), r); e && e.depth == t && e.textOffset && pn(e.nodeBefore, r); } function mn(n, e) { return n.type.checkContent(e), n.copy(e); } function Ad(n, e, t, r, i) { let s = n.depth > i && yl(n, e, i + 1), o = r.depth > i && yl(t, r, i + 1), l = []; return Ar(null, n, i, l), s && o && e.index(i) == t.index(i) ? (wd(s, o), pn(mn(s, Ad(n, e, t, r, i + 1)), l)) : (s && pn(mn(s, Yi(n, e, i + 1)), l), Ar(e, t, i, l), o && pn(mn(o, Yi(t, r, i + 1)), l)), Ar(r, null, i, l), new $(l); } function Yi(n, e, t) { let r = []; if (Ar(null, n, t, r), n.depth > t) { let i = yl(n, e, t + 1); pn(mn(i, Yi(n, e, t + 1)), r); } return Ar(e, null, t, r), new $(r); } function Tg(n, e) { let t = e.depth - n.openStart, i = e.node(t).copy(n.content); for (let s = t - 1; s >= 0; s--) i = e.node(s).copy($.from(i)); return { start: i.resolveNoCache(n.openStart + t), end: i.resolveNoCache(i.content.size - n.openEnd - t) }; } let Uc = class bl { /** @internal */ constructor(e, t, r) { this.pos = e, this.path = t, this.parentOffset = r, this.depth = t.length / 3 - 1; } /** @internal */ resolveDepth(e) { return e == null ? this.depth : e < 0 ? this.depth + e : e; } /** The parent node that the position points into. Note that even if a position points into a text node, that node is not considered the parent—text nodes are ‘flat’ in this model, and have no content. */ get parent() { return this.node(this.depth); } /** The root node in which the position was resolved. */ get doc() { return this.node(0); } /** The ancestor node at the given level. `p.node(p.depth)` is the same as `p.parent`. */ node(e) { return this.path[this.resolveDepth(e) * 3]; } /** The index into the ancestor at the given level. If this points at the 3rd node in the 2nd paragraph on the top level, for example, `p.index(0)` is 1 and `p.index(1)` is 2. */ index(e) { return this.path[this.resolveDepth(e) * 3 + 1]; } /** The index pointing after this position into the ancestor at the given level. */ indexAfter(e) { return e = this.resolveDepth(e), this.index(e) + (e == this.depth && !this.textOffset ? 0 : 1); } /** The (absolute) position at the start of the node at the given level. */ start(e) { return e = this.resolveDepth(e), e == 0 ? 0 : this.path[e * 3 - 1] + 1; } /** The (absolute) position at the end of the node at the given level. */ end(e) { return e = this.resolveDepth(e), this.start(e) + this.node(e).content.size; } /** The (absolute) position directly before the wrapping node at the given level, or, when `depth` is `this.depth + 1`, the original position. */ before(e) { if (e = this.resolveDepth(e), !e) throw new RangeError("There is no position before the top-level node"); return e == this.depth + 1 ? this.pos : this.path[e * 3 - 1]; } /** The (absolute) position directly after the wrapping node at the given level, or the original position when `depth` is `this.depth + 1`. */ after(e) { if (e = this.resolveDepth(e), !e) throw new RangeError("There is no position after the top-level node"); return e == this.depth + 1 ? this.pos : this.path[e * 3 - 1] + this.path[e * 3].nodeSize; } /** When this position points into a text node, this returns the distance between the position and the start of the text node. Will be zero for positions that point between nodes. */ get textOffset() { return this.pos - this.path[this.path.length - 1]; } /** Get the node directly after the position, if any. If the position points into a text node, only the part of that node after the position is returned. */ get nodeAfter() { let e = this.parent, t = this.index(this.depth); if (t == e.childCount) return null; let r = this.pos - this.path[this.path.length - 1], i = e.child(t); return r ? e.child(t).cut(r) : i; } /** Get the node directly before the position, if any. If the position points into a text node, only the part of that node before the position is returned. */ get nodeBefore() { let e = this.index(this.depth), t = this.pos - this.path[this.path.length - 1]; return t ? this.parent.child(e).cut(0, t) : e == 0 ? null : this.parent.child(e - 1); } /** Get the position at the given index in the parent node at the given depth (which defaults to `this.depth`). */ posAtIndex(e, t) { t = this.resolveDepth(t); let r = this.path[t * 3], i = t == 0 ? 0 : this.path[t * 3 - 1] + 1; for (let s = 0; s < e; s++) i += r.child(s).nodeSize; return i; } /** Get the marks at this position, factoring in the surrounding marks' [`inclusive`](https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive) property. If the position is at the start of a non-empty node, the marks of the node after it (if any) are returned. */ marks() { let e = this.parent, t = this.index(); if (e.content.size == 0) return ue.none; if (this.textOffset) return e.child(t).marks; let r = e.maybeChild(t - 1), i = e.maybeChild(t); if (!r) { let l = r; r = i, i = l; } let s = r.marks; for (var o = 0; o < s.length; o++) s[o].type.spec.inclusive === !1 && (!i || !s[o].isInSet(i.marks)) && (s = s[o--].removeFromSet(s)); return s; } /** Get the marks after the current position, if any, except those that are non-inclusive and not present at position `$end`. This is mostly useful for getting the set of marks to preserve after a deletion. Will return `null` if this position is at the end of its parent node or its parent node isn't a textblock (in which case no marks should be preserved). */ marksAcross(e) { let t = this.parent.maybeChild(this.index()); if (!t || !t.isInline) return null; let r = t.marks, i = e.parent.maybeChild(e.index()); for (var s = 0; s < r.length; s++) r[s].type.spec.inclusive === !1 && (!i || !r[s].isInSet(i.marks)) && (r = r[s--].removeFromSet(r)); return r; } /** The depth up to which this position and the given (non-resolved) position share the same parent nodes. */ sharedDepth(e) { for (let t = this.depth; t > 0; t--) if (this.start(t) <= e && this.end(t) >= e) return t; return 0; } /** Returns a range based on the place where this position and the given position diverge around block content. If both point into the same textblock, for example, a range around that textblock will be returned. If they point into different blocks, the range around those blocks in their shared ancestor is returned. You can pass in an optional predicate that will be called with a parent node to see if a range into that parent is acceptable. */ blockRange(e = this, t) { if (e.pos < this.pos) return e.blockRange(this); for (let r = this.depth - (this.parent.inlineContent || this.pos == e.pos ? 1 : 0); r >= 0; r--) if (e.pos <= this.end(r) && (!t || t(this.node(r)))) return new Xi(this, e, r); return null; } /** Query whether the given position shares the same parent node. */ sameParent(e) { return this.pos - this.parentOffset == e.pos - e.parentOffset; } /** Return the greater of this and the given position. */ max(e) { return e.pos > this.pos ? e : this; } /** Return the smaller of this and the given position. */ min(e) { return e.pos < this.pos ? e : this; } /** @internal */ toString() { let e = ""; for (let t = 1; t <= this.depth; t++) e += (e ? "/" : "") + this.node(t).type.n