nilfam-editor
Version:
A powerful, customizable rich-text editor built with TipTap, React, and Tailwind CSS. Supports RTL/LTR text, resizable media (images/videos), tables, code blocks, font styling, and more for an enhanced content creation experience.
1,629 lines (1,628 loc) • 880 kB
JavaScript
import Ne, { createContext as gd, useRef as Vn, useState as re, useDebugValue as md, useEffect as ht, forwardRef as wd, useLayoutEffect as bf, useContext as yf, useImperativeHandle as xf } from "react";
import kf, { flushSync as vf } from "react-dom";
function Ef(n) {
return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n;
}
var cs = { exports: {} }, yr = {};
/**
* @license React
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var pa;
function Cf() {
if (pa) return yr;
pa = 1;
var n = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
function t(r, s, i) {
var o = null;
if (i !== void 0 && (o = "" + i), s.key !== void 0 && (o = "" + s.key), "key" in s) {
i = {};
for (var l in s)
l !== "key" && (i[l] = s[l]);
} else i = s;
return s = i.ref, {
$$typeof: n,
type: r,
key: o,
ref: s !== void 0 ? s : null,
props: i
};
}
return yr.Fragment = e, yr.jsx = t, yr.jsxs = t, yr;
}
var xr = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var ga;
function Sf() {
return ga || (ga = 1, process.env.NODE_ENV !== "production" && function() {
function n(v) {
if (v == null) return null;
if (typeof v == "function")
return v.$$typeof === C ? null : v.displayName || v.name || null;
if (typeof v == "string") return v;
switch (v) {
case m:
return "Fragment";
case b:
return "Profiler";
case w:
return "StrictMode";
case E:
return "Suspense";
case T:
return "SuspenseList";
case A:
return "Activity";
}
if (typeof v == "object")
switch (typeof v.tag == "number" && console.error(
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
), v.$$typeof) {
case g:
return "Portal";
case k:
return (v.displayName || "Context") + ".Provider";
case x:
return (v._context.displayName || "Context") + ".Consumer";
case S:
var U = v.render;
return v = v.displayName, v || (v = U.displayName || U.name || "", v = v !== "" ? "ForwardRef(" + v + ")" : "ForwardRef"), v;
case M:
return U = v.displayName || null, U !== null ? U : n(v.type) || "Memo";
case $:
U = v._payload, v = v._init;
try {
return n(v(U));
} catch {
}
}
return null;
}
function e(v) {
return "" + v;
}
function t(v) {
try {
e(v);
var U = !1;
} catch {
U = !0;
}
if (U) {
U = console;
var le = U.error, me = typeof Symbol == "function" && Symbol.toStringTag && v[Symbol.toStringTag] || v.constructor.name || "Object";
return le.call(
U,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
me
), e(v);
}
}
function r(v) {
if (v === m) return "<>";
if (typeof v == "object" && v !== null && v.$$typeof === $)
return "<...>";
try {
var U = n(v);
return U ? "<" + U + ">" : "<...>";
} catch {
return "<...>";
}
}
function s() {
var v = P.A;
return v === null ? null : v.getOwner();
}
function i() {
return Error("react-stack-top-frame");
}
function o(v) {
if (H.call(v, "key")) {
var U = Object.getOwnPropertyDescriptor(v, "key").get;
if (U && U.isReactWarning) return !1;
}
return v.key !== void 0;
}
function l(v, U) {
function le() {
ge || (ge = !0, console.error(
"%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://react.dev/link/special-props)",
U
));
}
le.isReactWarning = !0, Object.defineProperty(v, "key", {
get: le,
configurable: !0
});
}
function a() {
var v = n(this.type);
return xe[v] || (xe[v] = !0, console.error(
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
)), v = this.props.ref, v !== void 0 ? v : null;
}
function c(v, U, le, me, it, ke, Ze, Xt) {
return le = ke.ref, v = {
$$typeof: p,
type: v,
key: U,
props: ke,
_owner: it
}, (le !== void 0 ? le : null) !== null ? Object.defineProperty(v, "ref", {
enumerable: !1,
get: a
}) : Object.defineProperty(v, "ref", { enumerable: !1, value: null }), v._store = {}, Object.defineProperty(v._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: 0
}), Object.defineProperty(v, "_debugInfo", {
configurable: !1,
enumerable: !1,
writable: !0,
value: null
}), Object.defineProperty(v, "_debugStack", {
configurable: !1,
enumerable: !1,
writable: !0,
value: Ze
}), Object.defineProperty(v, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: Xt
}), Object.freeze && (Object.freeze(v.props), Object.freeze(v)), v;
}
function d(v, U, le, me, it, ke, Ze, Xt) {
var Le = U.children;
if (Le !== void 0)
if (me)
if (K(Le)) {
for (me = 0; me < Le.length; me++)
u(Le[me]);
Object.freeze && Object.freeze(Le);
} else
console.error(
"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 u(Le);
if (H.call(U, "key")) {
Le = n(v);
var Tt = Object.keys(U).filter(function(gr) {
return gr !== "key";
});
me = 0 < Tt.length ? "{key: someKey, " + Tt.join(": ..., ") + ": ...}" : "{key: someKey}", ee[Le + me] || (Tt = 0 < Tt.length ? "{" + Tt.join(": ..., ") + ": ...}" : "{}", console.error(
`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} />`,
me,
Le,
Tt,
Le
), ee[Le + me] = !0);
}
if (Le = null, le !== void 0 && (t(le), Le = "" + le), o(U) && (t(U.key), Le = "" + U.key), "key" in U) {
le = {};
for (var Ot in U)
Ot !== "key" && (le[Ot] = U[Ot]);
} else le = U;
return Le && l(
le,
typeof v == "function" ? v.displayName || v.name || "Unknown" : v
), c(
v,
Le,
ke,
it,
s(),
le,
Ze,
Xt
);
}
function u(v) {
typeof v == "object" && v !== null && v.$$typeof === p && v._store && (v._store.validated = 1);
}
var h = Ne, p = Symbol.for("react.transitional.element"), g = Symbol.for("react.portal"), m = Symbol.for("react.fragment"), w = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), k = Symbol.for("react.context"), S = Symbol.for("react.forward_ref"), E = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), M = Symbol.for("react.memo"), $ = Symbol.for("react.lazy"), A = Symbol.for("react.activity"), C = Symbol.for("react.client.reference"), P = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, H = Object.prototype.hasOwnProperty, K = Array.isArray, te = console.createTask ? console.createTask : function() {
return null;
};
h = {
"react-stack-bottom-frame": function(v) {
return v();
}
};
var ge, xe = {}, L = h["react-stack-bottom-frame"].bind(
h,
i
)(), F = te(r(i)), ee = {};
xr.Fragment = m, xr.jsx = function(v, U, le, me, it) {
var ke = 1e4 > P.recentlyCreatedOwnerStacks++;
return d(
v,
U,
le,
!1,
me,
it,
ke ? Error("react-stack-top-frame") : L,
ke ? te(r(v)) : F
);
}, xr.jsxs = function(v, U, le, me, it) {
var ke = 1e4 > P.recentlyCreatedOwnerStacks++;
return d(
v,
U,
le,
!0,
me,
it,
ke ? Error("react-stack-top-frame") : L,
ke ? te(r(v)) : F
);
};
}()), xr;
}
var ma;
function Mf() {
return ma || (ma = 1, process.env.NODE_ENV === "production" ? cs.exports = Cf() : cs.exports = Sf()), cs.exports;
}
var f = Mf();
function qe(n) {
this.content = n;
}
qe.prototype = {
constructor: qe,
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, s = r.find(n), i = r.content.slice();
return s == -1 ? i.push(t || n, e) : (i[s + 1] = e, t && (i[s] = t)), new qe(i);
},
// :: (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 qe(t);
},
// :: (string, any) → OrderedMap
// Add a new key to the start of the map.
addToStart: function(n, e) {
return new qe([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 qe(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), s = r.content.slice(), i = r.find(n);
return s.splice(i == -1 ? s.length : i, 0, e, t), new qe(s);
},
// :: ((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 = qe.from(n), n.size ? new qe(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 = qe.from(n), n.size ? new qe(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 = qe.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;
}
};
qe.from = function(n) {
if (n instanceof qe) return n;
var e = [];
if (n) for (var t in n) e.push(t, n[t]);
return new qe(e);
};
function bd(n, e, t) {
for (let r = 0; ; r++) {
if (r == n.childCount || r == e.childCount)
return n.childCount == e.childCount ? null : t;
let s = n.child(r), i = e.child(r);
if (s == i) {
t += s.nodeSize;
continue;
}
if (!s.sameMarkup(i))
return t;
if (s.isText && s.text != i.text) {
for (let o = 0; s.text[o] == i.text[o]; o++)
t++;
return t;
}
if (s.content.size || i.content.size) {
let o = bd(s.content, i.content, t + 1);
if (o != null)
return o;
}
t += s.nodeSize;
}
}
function yd(n, e, t, r) {
for (let s = n.childCount, i = e.childCount; ; ) {
if (s == 0 || i == 0)
return s == i ? null : { a: t, b: r };
let o = n.child(--s), l = e.child(--i), 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, d = Math.min(o.text.length, l.text.length);
for (; c < d && 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 = yd(o.content, l.content, t - 1, r - 1);
if (c)
return c;
}
t -= a, r -= a;
}
}
class O {
/**
@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, s = 0, i) {
for (let o = 0, l = 0; l < t; o++) {
let a = this.content[o], c = l + a.nodeSize;
if (c > e && r(a, s + l, i || null, o) !== !1 && a.content.size) {
let d = l + 1;
a.nodesBetween(Math.max(0, e - d), Math.min(a.content.size, t - d), r, s + d);
}
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, s) {
let i = "", o = !0;
return this.nodesBetween(e, t, (l, a) => {
let c = l.isText ? l.text.slice(Math.max(e, a) - a, t - a) : l.isLeaf ? s ? typeof s == "function" ? s(l) : s : l.type.spec.leafText ? l.type.spec.leafText(l) : "" : "";
l.isBlock && (l.isLeaf && c || l.isTextblock) && r && (o ? o = !1 : i += r), i += c;
}, 0), i;
}
/**
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, s = this.content.slice(), i = 0;
for (t.isText && t.sameMarkup(r) && (s[s.length - 1] = t.withText(t.text + r.text), i = 1); i < e.content.length; i++)
s.push(e.content[i]);
return new O(s, 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 = [], s = 0;
if (t > e)
for (let i = 0, o = 0; o < t; i++) {
let l = this.content[i], 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), s += l.nodeSize), o = a;
}
return new O(r, s);
}
/**
@internal
*/
cutByIndex(e, t) {
return e == t ? O.empty : e == 0 && t == this.content.length ? this : new O(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 s = this.content.slice(), i = this.size + t.nodeSize - r.nodeSize;
return s[e] = t, new O(s, i);
}
/**
Create a new fragment by prepending the given node to this
fragment.
*/
addToStart(e) {
return new O([e].concat(this.content), this.size + e.nodeSize);
}
/**
Create a new fragment by appending the given node to this
fragment.
*/
addToEnd(e) {
return new O(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 s = this.content[t];
e(s, r, t), r += s.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 bd(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 yd(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. @internal
*/
findIndex(e, t = -1) {
if (e == 0)
return ds(0, e);
if (e == this.size)
return ds(this.content.length, e);
if (e > this.size || e < 0)
throw new RangeError(`Position ${e} outside of fragment (${this})`);
for (let r = 0, s = 0; ; r++) {
let i = this.child(r), o = s + i.nodeSize;
if (o >= e)
return o == e || t > 0 ? ds(r + 1, o) : ds(r, s);
s = 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 O.empty;
if (!Array.isArray(t))
throw new RangeError("Invalid input for Fragment.fromJSON");
return new O(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 O.empty;
let t, r = 0;
for (let s = 0; s < e.length; s++) {
let i = e[s];
r += i.nodeSize, s && i.isText && e[s - 1].sameMarkup(i) ? (t || (t = e.slice(0, s)), t[t.length - 1] = i.withText(t[t.length - 1].text + i.text)) : t && t.push(i);
}
return new O(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 O.empty;
if (e instanceof O)
return e;
if (Array.isArray(e))
return this.fromArray(e);
if (e.attrs)
return new O([e], e.nodeSize);
throw new RangeError("Can not convert " + e + " to a Fragment" + (e.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : ""));
}
}
O.empty = new O([], 0);
const Xi = { index: 0, offset: 0 };
function ds(n, e) {
return Xi.index = n, Xi.offset = e, Xi;
}
function Ds(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 (!Ds(n[r], e[r]))
return !1;
} else {
for (let r in n)
if (!(r in e) || !Ds(n[r], e[r]))
return !1;
for (let r in e)
if (!(r in n))
return !1;
}
return !0;
}
let ye = class Ro {
/**
@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 s = 0; s < e.length; s++) {
let i = e[s];
if (this.eq(i))
return e;
if (this.type.excludes(i.type))
t || (t = e.slice(0, s));
else {
if (i.type.excludes(this.type))
return e;
!r && i.type.rank > this.type.rank && (t || (t = e.slice(0, s)), t.push(this), r = !0), t && t.push(i);
}
}
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 && Ds(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`);
let s = r.create(t.attrs);
return r.checkAttrs(s.attrs), s;
}
/**
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 Ro.none;
if (e instanceof Ro)
return [e];
let t = e.slice();
return t.sort((r, s) => r.type.rank - s.type.rank), t;
}
};
ye.none = [];
class Is extends Error {
}
class _ {
/**
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 = kd(this.content, e + this.openStart, t);
return r && new _(r, this.openStart, this.openEnd);
}
/**
@internal
*/
removeBetween(e, t) {
return new _(xd(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 _.empty;
let r = t.openStart || 0, s = t.openEnd || 0;
if (typeof r != "number" || typeof s != "number")
throw new RangeError("Invalid input for Slice.fromJSON");
return new _(O.fromJSON(e, t.content), r, s);
}
/**
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, s = 0;
for (let i = e.firstChild; i && !i.isLeaf && (t || !i.type.spec.isolating); i = i.firstChild)
r++;
for (let i = e.lastChild; i && !i.isLeaf && (t || !i.type.spec.isolating); i = i.lastChild)
s++;
return new _(e, r, s);
}
}
_.empty = new _(O.empty, 0, 0);
function xd(n, e, t) {
let { index: r, offset: s } = n.findIndex(e), i = n.maybeChild(r), { index: o, offset: l } = n.findIndex(t);
if (s == e || i.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, i.copy(xd(i.content, e - s - 1, t - s - 1)));
}
function kd(n, e, t, r) {
let { index: s, offset: i } = n.findIndex(e), o = n.maybeChild(s);
if (i == e || o.isText)
return n.cut(0, e).append(t).append(n.cut(e));
let l = kd(o.content, e - i - 1, t);
return l && n.replaceChild(s, o.copy(l));
}
function Af(n, e, t) {
if (t.openStart > n.depth)
throw new Is("Inserted content deeper than insertion position");
if (n.depth - t.openStart != e.depth - t.openEnd)
throw new Is("Inconsistent open depths");
return vd(n, e, t, 0);
}
function vd(n, e, t, r) {
let s = n.index(r), i = n.node(r);
if (s == e.index(r) && r < n.depth - t.openStart) {
let o = vd(n, e, t, r + 1);
return i.copy(i.content.replaceChild(s, 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 Dn(o, l.cut(0, n.parentOffset).append(t.content).append(l.cut(e.parentOffset)));
} else {
let { start: o, end: l } = Nf(t, n);
return Dn(i, Cd(n, o, l, e, r));
}
else return Dn(i, _s(n, e, r));
}
function Ed(n, e) {
if (!e.type.compatibleContent(n.type))
throw new Is("Cannot join " + e.type.name + " onto " + n.type.name);
}
function Lo(n, e, t) {
let r = n.node(t);
return Ed(r, e.node(t)), r;
}
function Ln(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 s = (e || n).node(t), i = 0, o = e ? e.index(t) : s.childCount;
n && (i = n.index(t), n.depth > t ? i++ : n.textOffset && (Ln(n.nodeAfter, r), i++));
for (let l = i; l < o; l++)
Ln(s.child(l), r);
e && e.depth == t && e.textOffset && Ln(e.nodeBefore, r);
}
function Dn(n, e) {
return n.type.checkContent(e), n.copy(e);
}
function Cd(n, e, t, r, s) {
let i = n.depth > s && Lo(n, e, s + 1), o = r.depth > s && Lo(t, r, s + 1), l = [];
return Ar(null, n, s, l), i && o && e.index(s) == t.index(s) ? (Ed(i, o), Ln(Dn(i, Cd(n, e, t, r, s + 1)), l)) : (i && Ln(Dn(i, _s(n, e, s + 1)), l), Ar(e, t, s, l), o && Ln(Dn(o, _s(t, r, s + 1)), l)), Ar(r, null, s, l), new O(l);
}
function _s(n, e, t) {
let r = [];
if (Ar(null, n, t, r), n.depth > t) {
let s = Lo(n, e, t + 1);
Ln(Dn(s, _s(n, e, t + 1)), r);
}
return Ar(e, null, t, r), new O(r);
}
function Nf(n, e) {
let t = e.depth - n.openStart, s = e.node(t).copy(n.content);
for (let i = t - 1; i >= 0; i--)
s = e.node(i).copy(O.from(s));
return {
start: s.resolveNoCache(n.openStart + t),
end: s.resolveNoCache(s.content.size - n.openEnd - t)
};
}
class Br {
/**
@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], s = e.child(t);
return r ? e.child(t).cut(r) : s;
}
/**
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], s = t == 0 ? 0 : this.path[t * 3 - 1] + 1;
for (let i = 0; i < e; i++)
s += r.child(i).nodeSize;
return s;
}
/**
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 ye.none;
if (this.textOffset)
return e.child(t).marks;
let r = e.maybeChild(t - 1), s = e.maybeChild(t);
if (!r) {
let l = r;
r = s, s = l;
}
let i = r.marks;
for (var o = 0; o < i.length; o++)
i[o].type.spec.inclusive === !1 && (!s || !i[o].isInSet(s.marks)) && (i = i[o--].removeFromSet(i));
return i;
}
/**
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, s = e.parent.maybeChild(e.index());
for (var i = 0; i < r.length; i++)
r[i].type.spec.inclusive === !1 && (!s || !r[i].isInSet(s.marks)) && (r = r[i--].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 js(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.name + "_" + this.index(t - 1);
return e + ":" + this.parentOffset;
}
/**
@internal
*/
static resolve(e, t) {
if (!(t >= 0 && t <= e.content.size))
throw new RangeError("Position " + t + " out of range");
let r = [], s = 0, i = t;
for (let o = e; ; ) {
let { index: l, offset: a } = o.content.findIndex(i), c = i - a;
if (r.push(o, l, s + a), !c || (o = o.child(l), o.isText))
break;
i = c - 1, s += a + 1;
}
return new Br(t, r, i);
}
/**
@internal
*/
static resolveCached(e, t) {
let r = wa.get(e);
if (r)
for (let i = 0; i < r.elts.length; i++) {
let o = r.elts[i];
if (o.pos == t)
return o;
}
else
wa.set(e, r = new Tf());
let s = r.elts[r.i] = Br.resolve(e, t);
return r.i = (r.i + 1) % Of, s;
}
}
class Tf {
constructor() {
this.elts = [], this.i = 0;
}
}
const Of = 12, wa = /* @__PURE__ */ new WeakMap();
class js {
/**
Construct a node range. `$from` and `$to` should point into the
same node until at least the given `depth`, since a node range
denotes an adjacent set of nodes in a single parent node.
*/
constructor(e, t, r) {
this.$from = e, this.$to = t, this.depth = r;
}
/**
The position at the start of the range.
*/
get start() {
return this.$from.before(this.depth + 1);
}
/**
The position at the end of the range.
*/
get end() {
return this.$to.after(this.depth + 1);
}
/**
The parent node that the range points into.
*/
get parent() {
return this.$from.node(this.depth);
}
/**
The start index of the range in the parent node.
*/
get startIndex() {
return this.$from.index(this.depth);
}
/**
The end index of the range in the parent node.
*/
get endIndex() {
return this.$to.indexAfter(this.depth);
}
}
const Rf = /* @__PURE__ */ Object.create(null);
let fn = class Do {
/**
@internal
*/
constructor(e, t, r, s = ye.none) {
this.type = e, this.attrs = t, this.marks = s, this.content = r || O.empty;
}
/**
The array of this node's child nodes.
*/
get children() {
return this.content.content;
}
/**
The size of this node, as defined by the integer-based [indexing
scheme](https://prosemirror.net/docs/guide/#doc.indexing). For text nodes, this is the
amount of characters. For other leaf nodes, it is one. For
non-leaf nodes, it is the size of the content plus two (the
start and end token).
*/
get nodeSize() {
return this.isLeaf ? 1 : 2 + this.content.size;
}
/**
The number of children that the node has.
*/
get childCount() {
return this.content.childCount;
}
/**
Get the child node at the given index. Raises an error when the
index is out of range.
*/
child(e) {
return this.content.child(e);
}
/**
Get the child node at the given index, if it exists.
*/
maybeChild(e) {
return this.content.maybeChild(e);
}
/**
Call `f` for every child node, passing the node, its offset
into this parent node, and its index.
*/
forEach(e) {
this.content.forEach(e);
}
/**
Invoke a callback for all descendant nodes recursively between
the given two positions that are relative to start of this
node's content. The callback is invoked with the node, its
position relative to the original node (method receiver),
its parent node, and its child index. When the callback returns
false for a given node, that node's children will not be
recursed over. The last parameter can be used to specify a
starting position to count from.
*/
nodesBetween(e, t, r, s = 0) {
this.content.nodesBetween(e, t, r, s, this);
}
/**
Call the given callback for every descendant node. Doesn't
descend into a node when the callback returns `false`.
*/
descendants(e) {
this.nodesBetween(0, this.content.size, e);
}
/**
Concatenates all the text nodes found in this fragment and its
children.
*/
get textContent() {
return this.isLeaf && this.type.spec.leafText ? this.type.spec.leafText(this) : this.textBetween(0, this.content.size, "");
}
/**
Get all text between positions `from` and `to`. When
`blockSeparator` is given, it will be inserted to separate text
from different block nodes. If `leafText` is given, it'll be
inserted for every non-text leaf node encountered, otherwise
[`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec^leafText) will be used.
*/
textBetween(e, t, r, s) {
return this.content.textBetween(e, t, r, s);
}
/**
Returns this node's first child, or `null` if there are no
children.
*/
get firstChild() {
return this.content.firstChild;
}
/**
Returns this node's last child, or `null` if there are no
children.
*/
get lastChild() {
return this.content.lastChild;
}
/**
Test whether two nodes represent the same piece of document.
*/
eq(e) {
return this == e || this.sameMarkup(e) && this.content.eq(e.content);
}
/**
Compare the markup (type, attributes, and marks) of this node to
those of another. Returns `true` if both have the same markup.
*/
sameMarkup(e) {
return this.hasMarkup(e.type, e.attrs, e.marks);
}
/**
Check whether this node's markup correspond to the given type,
attributes, and marks.
*/
hasMarkup(e, t, r) {
return this.type == e && Ds(this.attrs, t || e.defaultAttrs || Rf) && ye.sameSet(this.marks, r || ye.none);
}
/**
Create a new node with the same markup as this node, containing
the given content (or empty, if no content is given).
*/
copy(e = null) {
return e == this.content ? this : new Do(this.type, this.attrs, e, this.marks);
}
/**
Create a copy of this node, with the given set of marks instead
of the node's own marks.
*/
mark(e) {
return e == this.marks ? this : new Do(this.type, this.attrs, this.content, e);
}
/**
Create a copy of this node with only the content between the
given positions. If `to` is not given, it defaults to the end of
the node.
*/
cut(e, t = this.content.size) {
return e == 0 && t == this.content.size ? this : this.copy(this.content.cut(e, t));
}
/**
Cut out the part of the document between the given positions, and
return it as a `Slice` object.
*/
slice(e, t = this.content.size, r = !1) {
if (e == t)
return _.empty;
let s = this.resolve(e), i = this.resolve(t), o = r ? 0 : s.sharedDepth(t), l = s.start(o), c = s.node(o).content.cut(s.pos - l, i.pos - l);
return new _(c, s.depth - o, i.depth - o);
}
/**
Replace the part of the document between the given positions with
the given slice. The slice must 'fit', meaning its open sides
must be able to connect to the surrounding content, and its
content nodes must be valid children for the node they are placed
into. If any of this is violated, an error of type
[`ReplaceError`](https://prosemirror.net/docs/ref/#model.ReplaceError) is thrown.
*/
replace(e, t, r) {
return Af(this.resolve(e), this.resolve(t), r);
}
/**
Find the node directly after the given position.
*/
nodeAt(e) {
for (let t = this; ; ) {
let { index: r, offset: s } = t.content.findIndex(e);
if (t = t.maybeChild(r), !t)
return null;
if (s == e || t.isText)
return t;
e -= s + 1;
}
}
/**
Find the (direct) child node after the given offset, if any,
and return it along with its index and offset relative to this
node.
*/
childAfter(e) {
let { index: t, offset: r } = this.content.findIndex(e);
return { node: this.content.maybeChild(t), index: t, offset: r };
}
/**
Find the (direct) child node before the given offset, if any,
and return it along with its index and offset relative to this
node.
*/
childBefore(e) {
if (e == 0)
return { node: null, index: 0, offset: 0 };
let { index: t, offset: r } = this.content.findIndex(e);
if (r < e)
return { node: this.content.child(t), index: t, offset: r };
let s = this.content.child(t - 1);
return { node: s, index: t - 1, offset: r - s.nodeSize };
}
/**
Resolve the given position in the document, returning an
[object](https://prosemirror.net/docs/ref/#model.ResolvedPos) with information about its context.
*/
resolve(e) {
return Br.resolveCached(this, e);
}
/**
@internal
*/
resolveNoCache(e) {
return Br.resolve(this, e);
}
/**
Test whether a given mark or mark type occurs in this document
between the two given positions.
*/
rangeHasMark(e, t, r) {
let s = !1;
return t > e && this.nodesBetween(e, t, (i) => (r.isInSet(i.marks) && (s = !0), !s)), s;
}
/**
True when this is a block (non-inline node)
*/
get isBlock() {
return this.type.isBlock;
}
/**
True when this is a textblock node, a block node with inline
content.
*/
get isTextblock() {
return this.type.isTextblock;
}
/**
True when this node allows inline content.
*/
get inlineContent() {
return this.type.inlineContent;
}
/**
True when this is an inline node (a text node or a node that can
appear among text).
*/
get isInline() {
return this.type.isInline;
}
/**
True when this is a text node.
*/
get isText() {
return this.type.isText;
}
/**
True when this is a leaf node.
*/
get isLeaf() {
return this.type.isLeaf;
}
/**
True when this is an atom, i.e. when it does not have directly
editable content. This is usually the same as `isLeaf`, but can
be configured with the [`atom` property](https://prosemirror.net/docs/ref/#model.NodeSpec.atom)
on a node's spec (typically used when the node is displayed as
an uneditable [node view](https://prosemirror.net/docs/ref/#view.NodeView)).
*/
get isAtom() {
return this.type.isAtom;
}
/**
Return a string representation of this node for debugging
purposes.
*/
toString() {
if (this.type.spec.toDebugString)
return this.type.spec.toDebugString(this);
let e = this.type.name;
return this.content.size && (e += "(" + this.content.toStringInner() + ")"), Sd(this.marks, e);
}
/**
Get the content match in this node at the given index.
*/
contentMatchAt(e) {
let t = this.type.contentMatch.matchFragment(this.content, 0, e);
if (!t)
throw new Error("Called contentMatchAt on a node with invalid content");
return t;
}
/**
Test whether replacing the range between `from` and `to` (by
child index) with the given replacement fragment (which defaults
to the empty fragment) would leave the node's content valid. You
can optionally pass `start` and `end` indices into the
replacement fragment.
*/
canReplace(e, t, r = O.empty, s = 0, i = r.childCount) {
let o = this.contentMatchAt(e).matchFragment(r, s, i), l = o && o.matchFragment(this.content, t);
if (!l || !l.validEnd)
return !1;
for (let a = s; a < i; a++)
if (!this.type.allowsMarks(r.child(a).marks))
return !1;
return !0;
}
/**
Test whether replacing the range `from` to `to` (by index) with
a node of the given type would leave the node's content valid.
*/
canReplaceWith(e, t, r, s) {
if (s && !this.type.allowsMarks(s))
return !1;
let i = this.contentMatchAt(e).matchType(r), o = i && i.matchFragment(this.content, t);
return o ? o.validEnd : !1;
}
/**
Test whether the given node's content could be appended to this
node. If that node is empty, this will only return true if there
is at least one node type that can appear in both nodes (to avoid
merging completely incompatible nodes).
*/
canAppend(e) {
return e.content.size ? this.canReplace(this.childCount, this.childCount, e.content) : this.type.compatibleContent(e.type);
}
/**
Check whether this node and its descendants conform to the
schema, and raise an exception when they do not.
*/
check() {
this.type.checkContent(this.content), this.type.checkAttrs(this.attrs);
let e = ye.none;
for (let t = 0; t < this.marks.length; t++) {
let r = this.marks[t];
r.type.checkAttrs(r.attrs), e = r.addToSet(e);
}
if (!ye.sameSet(e, this.marks))
throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((t) => t.type.name)}`);
this.content.forEach((t) => t.check());
}
/**
Return a JSON-serializeable representation of this node.
*/
toJSON() {
let e = { type: this.type.name };
for (let t in this.attrs) {
e.attrs = this.attrs;
break;
}
return this.content.size && (e.content = this.content.toJSON()), this.marks.length && (e.marks = this.marks.map((t) => t.toJSON())), e;
}