UNPKG

@blocknote/core

Version:

A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.

1,830 lines 66.5 kB
import { $n as e, At as t, Bt as n, Ft as r, Ht as i, In as a, It as o, Lt as s, Mt as c, Nt as l, Pt as u, Rt as d, Ut as f, Vt as p, _ as m, bn as h, g, kt as ee, r as te, yn as _, zt as v } from "./blocks-CiuUGa1E.js";
import { n as y, t as b } from "./BlockNoteExtension-B_IEJHS8.js";
import { n as ne } from "./UserStore-QbbPFj0z.js";
import { DOMSerializer as x, Fragment as S, Slice as re } from "prosemirror-model";
import { Mapping as ie, dropPoint as ae } from "prosemirror-transform";
import { combineTransactionSteps as oe, findChildrenInRange as se, posToDOMRect as ce } from "@tiptap/core";
import { uuidv4 as le } from "lib0/random";
import { NodeSelection as ue, Plugin as C, PluginKey as w, Selection as T, TextSelection as de } from "prosemirror-state";
import { DOMParser as fe, Slice as pe } from "@tiptap/pm/model";
import { CellSelection as me, addColumnAfter as he, addColumnBefore as ge, addRowAfter as _e, addRowBefore as ve, deleteColumn as ye, deleteRow as be, mergeCells as xe, splitCell as Se } from "prosemirror-tables";
import { Plugin as Ce, PluginKey as we, TextSelection as Te } from "@tiptap/pm/state";
import { Decoration as E, DecorationSet as D } from "prosemirror-view";
import Ee from "fast-deep-equal";
import { history as De, redo as Oe, undo as ke } from "@tiptap/pm/history";
//#region src/api/exporters/html/util/serializeBlocksExternalHTML.ts
function Ae(e) {
	let t = Array.from(e.classList).filter((e) => !e.startsWith("bn-")) || [];
	t.length > 0 ? e.className = t.join(" ") : e.removeAttribute("class");
}
function O(e, t, n, r) {
	let i;
	if (!t) throw Error("blockContent is required");
	if (typeof t == "string") i = c([t], e.pmSchema, r?.blockType);
	else if (Array.isArray(t)) i = c(t, e.pmSchema, r?.blockType);
	else if (t.type === "tableContent") i = l(t, e.pmSchema);
	else throw new a(t.type);
	let o = (r?.document ?? document).createDocumentFragment();
	for (let t of i) if (t.type.name !== "text" && e.schema.inlineContentSchema[t.type.name]) {
		let i = e.schema.inlineContentSpecs[t.type.name].implementation;
		if (i) {
			let a = h(t, e.schema.inlineContentSchema, e.schema.styleSchema), s = i.toExternalHTML ? i.toExternalHTML(a, e) : i.render.call({
				renderType: "dom",
				props: void 0
			}, a, () => {}, e);
			if (s) {
				if (o.appendChild(s.dom), s.contentDOM) {
					let e = n.serializeFragment(t.content, r);
					s.contentDOM.dataset.editable = "", s.contentDOM.appendChild(e);
				}
				continue;
			}
		}
	} else if (t.type.name === "text") {
		let n = document.createTextNode(t.textContent);
		for (let r of t.marks.toReversed()) if (r.type.name in e.schema.styleSpecs) {
			let t = (e.schema.styleSpecs[r.type.name].implementation.toExternalHTML ?? e.schema.styleSpecs[r.type.name].implementation.render)(r.attrs.stringValue, e);
			t.contentDOM.appendChild(n), n = t.dom;
		} else {
			let e = r.type.spec.toDOM(r, !0), t = x.renderSpec(document, e);
			t.contentDOM.appendChild(n), n = t.dom;
		}
		o.appendChild(n);
	} else {
		let e = n.serializeFragment(S.from([t]), r);
		o.appendChild(e);
	}
	return o.childNodes.length === 1 && o.firstChild?.nodeType === 1 && Ae(o.firstChild), o;
}
function je(e, t, n, r, i, a, o, s) {
	let c = s?.document ?? document, l = t.pmSchema.nodes.blockContainer, u = n.props || {};
	for (let [e, r] of Object.entries(t.schema.blockSchema[n.type].propSchema)) !(e in u) && r.default !== void 0 && (u[e] = r.default);
	let d = l.spec?.toDOM?.(l.create({
		id: n.id,
		...u
	})), f = Array.from(d.dom.attributes), p = t.blockImplementations[n.type].implementation, m = p.toExternalHTML?.call({}, {
		...n,
		props: u
	}, t, { nestingLevel: o }) || p.render.call({}, {
		...n,
		props: u
	}, t), h = c.createDocumentFragment();
	if (m.dom.classList.contains("bn-block-content")) {
		let e = [...f, ...Array.from(m.dom.attributes)].filter((e) => e.name.startsWith("data") && e.name !== "data-content-type" && e.name !== "data-file-block" && e.name !== "data-node-view-wrapper" && e.name !== "data-node-type" && e.name !== "data-id" && e.name !== "data-editable");
		for (let t of e) m.dom.firstChild.setAttribute(t.name, t.value);
		Ae(m.dom.firstChild), o > 0 && m.dom.firstChild.setAttribute("data-nesting-level", o.toString()), h.append(...Array.from(m.dom.childNodes));
	} else h.append(m.dom), o > 0 && m.dom.setAttribute("data-nesting-level", o.toString());
	if (m.contentDOM && n.content) {
		let e = O(t, n.content, r, {
			...s,
			blockType: n.type
		});
		m.contentDOM.appendChild(e);
	}
	let g;
	if (i.has(n.type) ? g = "OL" : a.has(n.type) && (g = "UL"), g) {
		if (e.lastChild?.nodeName !== g) {
			let t = c.createElement(g);
			g === "OL" && "start" in u && u.start && u?.start !== 1 && t.setAttribute("start", String(u.start)), e.append(t);
		}
		e.lastChild.appendChild(h);
	} else e.append(h);
	if (n.children && n.children.length > 0) {
		let l = c.createDocumentFragment();
		if (Me(l, t, n.children, r, i, a, o + 1, s), e.lastChild?.nodeName === "UL" || e.lastChild?.nodeName === "OL") for (; l.firstChild?.nodeName === "UL" || l.firstChild?.nodeName === "OL";) e.lastChild.lastChild.appendChild(l.firstChild);
		"childrenDOM" in m && m.childrenDOM ? m.childrenDOM.append(l) : t.pmSchema.nodes[n.type].isInGroup("blockContent") ? e.append(l) : m.contentDOM?.append(l);
	}
}
var Me = (e, t, n, r, i, a, o = 0, s) => {
	for (let c of n) je(e, t, c, r, i, a, o, s);
}, Ne = (e, t, n, r, i, a) => {
	let o = (a?.document ?? document).createDocumentFragment();
	return Me(o, e, t, n, r, i, 0, a), o;
}, k = (e, t) => {
	let n = x.fromSchema(e);
	return {
		exportBlocks: (e, r) => {
			let i = Ne(t, e, n, new Set(["numberedListItem"]), new Set([
				"bulletListItem",
				"checkListItem",
				"toggleListItem"
			]), r), a = document.createElement("div");
			return a.append(i), a.innerHTML;
		},
		exportInlineContent: (e, r) => {
			let i = O(t, e, n, r), a = document.createElement("div");
			return a.append(i.cloneNode(!0)), a.innerHTML;
		}
	};
};
//#endregion
//#region src/api/getBlocksChangedByTransaction.ts
function Pe(n, r) {
	if (r === 0) return;
	let i = n.resolve(r);
	for (let r = i.depth; r > 0; r--) {
		let a = i.node(r);
		if (t(a)) return e(a, n);
	}
}
function Fe(e) {
	return e.getMeta("paste") ? { type: "paste" } : e.getMeta("uiEvent") === "drop" ? { type: "drop" } : e.getMeta("history$") ? { type: e.getMeta("history$").redo ? "redo" : "undo" } : e.getMeta("y-sync$") ? e.getMeta("y-sync$").isUndoRedoOperation ? { type: "undo-redo" } : { type: "yjs-remote" } : { type: "local" };
}
function Ie(n) {
	let r = {}, i = {};
	return n.descendants((a, o) => {
		if (!t(a)) return !0;
		let s = Pe(n, o), c = s ?? "__root__";
		i[c] || (i[c] = []);
		let l = _(a, n), u = e(a, n);
		return r[u] = {
			block: l,
			parentId: s
		}, i[c].push(u), !0;
	}), {
		byId: r,
		childrenByParent: i
	};
}
function Le(e, t) {
	let n = /* @__PURE__ */ new Set();
	if (!e || !t) return n;
	let r = new Set(e), i = t.filter((e) => r.has(e)), a = e.filter((e) => i.includes(e));
	if (a.length <= 1 || i.length <= 1) return n;
	let o = {};
	for (let e = 0; e < a.length; e++) o[a[e]] = e;
	let s = i.map((e) => o[e]), c = s.length, l = [], u = [], d = Array(c).fill(-1), f = (e, t) => {
		let n = 0, r = e.length;
		for (; n < r;) {
			let i = n + r >>> 1;
			e[i] < t ? n = i + 1 : r = i;
		}
		return n;
	};
	for (let e = 0; e < c; e++) {
		let t = s[e], n = f(l, t);
		n > 0 && (d[e] = u[n - 1]), n === l.length ? (l.push(t), u.push(e)) : (l[n] = t, u[n] = e);
	}
	let p = /* @__PURE__ */ new Set(), m = u[u.length - 1] ?? -1;
	for (; m !== -1;) p.add(m), m = d[m];
	for (let e = 0; e < i.length; e++) p.has(e) || n.add(i[e]);
	return n;
}
function Re(e, t = []) {
	let n = Fe(e), r = oe(e.before, [e, ...t]), i = Ie(r.before), a = Ie(r.doc), o = [], s = /* @__PURE__ */ new Set();
	Object.keys(a.byId).filter((e) => !(e in i.byId)).forEach((e) => {
		o.push({
			type: "insert",
			block: a.byId[e].block,
			source: n,
			prevBlock: void 0
		}), s.add(e);
	}), Object.keys(i.byId).filter((e) => !(e in a.byId)).forEach((e) => {
		o.push({
			type: "delete",
			block: i.byId[e].block,
			source: n,
			prevBlock: void 0
		}), s.add(e);
	}), Object.keys(a.byId).filter((e) => e in i.byId).forEach((e) => {
		let t = i.byId[e], r = a.byId[e];
		t.parentId === r.parentId ? Ee({
			...t.block,
			children: void 0
		}, {
			...r.block,
			children: void 0
		}) || (o.push({
			type: "update",
			block: r.block,
			prevBlock: t.block,
			source: n
		}), s.add(e)) : (o.push({
			type: "move",
			block: r.block,
			prevBlock: t.block,
			source: n,
			prevParent: t.parentId ? i.byId[t.parentId]?.block : void 0,
			currentParent: r.parentId ? a.byId[r.parentId]?.block : void 0
		}), s.add(e));
	});
	let c = i.childrenByParent, l = a.childrenByParent, u = new Set([...Object.keys(c), ...Object.keys(l)]), d = /* @__PURE__ */ new Set();
	return u.forEach((e) => {
		let t = Le(c[e], l[e]);
		t.size !== 0 && t.forEach((t) => {
			let r = i.byId[t], c = a.byId[t];
			!r || !c || r.parentId === c.parentId && (s.has(t) || (r.parentId ?? "__root__") === e && (d.has(t) || (d.add(t), o.push({
				type: "move",
				block: c.block,
				prevBlock: r.block,
				source: n,
				prevParent: r.parentId ? i.byId[r.parentId]?.block : void 0,
				currentParent: c.parentId ? a.byId[c.parentId]?.block : void 0
			}), s.add(t))));
		});
	}), o;
}
//#endregion
//#region src/extensions/BlockChange/BlockChange.ts
var ze = b(() => {
	let e = [];
	return {
		key: "blockChange",
		prosemirrorPlugins: [new C({
			key: new w("blockChange"),
			filterTransaction: (t) => {
				let n;
				return e.reduce((e, r) => e === !1 ? e : r({
					getChanges() {
						return n || (n = Re(t), n);
					},
					tr: t
				}) !== !1, !0);
			}
		})],
		subscribe(t) {
			return e.push(t), () => {
				e.splice(e.indexOf(t), 1);
			};
		}
	};
});
//#endregion
//#region src/extensions/DropCursor/utils.ts
function Be(e, t) {
	return !e || !t ? !1 : !!e.closest(`.${t}`);
}
function Ve(e, t, n, r, i) {
	let a = e.state.doc.resolve(t.pos);
	if (a.parent.inlineContent || t.orientation === "inline") return null;
	let o = a.nodeBefore, s = a.nodeAfter;
	if (!o && !s) return null;
	let c = t.orientation === "block-vertical-left" || t.orientation === "block-vertical-right", l = c ? t.pos : t.pos - (o ? o.nodeSize : 0), u = e.nodeDOM(l);
	if (!u) return null;
	let d = u.getBoundingClientRect();
	if (c) {
		let e = n / 2 * r, i = t.orientation === "block-vertical-left" ? d.left : d.right;
		return {
			left: i - e,
			right: i + e,
			top: d.top,
			bottom: d.bottom
		};
	}
	let f = o ? d.bottom : d.top;
	o && s && (f = (f + e.nodeDOM(t.pos).getBoundingClientRect().top) / 2);
	let p = n / 2 * i;
	return {
		left: d.left,
		right: d.right,
		top: f - p,
		bottom: f + p
	};
}
function He(e, t, n, r) {
	let i = e.coordsAtPos(t.pos), a = n / 2 * r;
	return {
		left: i.left - a,
		right: i.left + a,
		top: i.top,
		bottom: i.bottom
	};
}
function Ue(e, t) {
	e.classList.toggle("prosemirror-dropcursor-inline", t === "inline"), e.classList.toggle("prosemirror-dropcursor-block-horizontal", t === "block-horizontal"), e.classList.toggle("prosemirror-dropcursor-block-vertical-left", t === "block-vertical-left"), e.classList.toggle("prosemirror-dropcursor-block-vertical-right", t === "block-vertical-right"), e.classList.toggle("prosemirror-dropcursor-block", t === "block-horizontal"), e.classList.toggle("prosemirror-dropcursor-vertical", t === "block-vertical-left" || t === "block-vertical-right");
}
function We(e) {
	if (!e || e === document.body && getComputedStyle(e).position === "static") return {
		parentLeft: -window.pageXOffset,
		parentTop: -window.pageYOffset
	};
	let t = e.getBoundingClientRect(), n = t.width / e.offsetWidth, r = t.height / e.offsetHeight;
	return {
		parentLeft: t.left - e.scrollLeft * n,
		parentTop: t.top - e.scrollTop * r
	};
}
//#endregion
//#region src/extensions/DropCursor/DropCursor.ts
var Ge = "bn-drag-exclude", Ke = b(({ editor: e, options: t }) => {
	let n = null, r = null, i = -1, a = null, o = {
		width: t.dropCursor?.width ?? 5,
		color: t.dropCursor?.color ?? "#ddeeff",
		exclude: t.dropCursor?.exclude ?? "bn-drag-exclude",
		hooks: t.dropCursor?.hooks
	}, s = (e) => {
		e?.pos === n?.pos && e?.orientation === n?.orientation || (n = e, e == null ? (r && r.parentNode && r.parentNode.removeChild(r), r = null) : c());
	}, c = () => {
		if (!n) return;
		let t = e.prosemirrorView, i = t.dom, a = i.getBoundingClientRect(), s = a.width / i.offsetWidth, c = a.height / i.offsetHeight, l = Ve(t, n, o.width, s, c) ?? He(t, n, o.width, s), u = t.dom.offsetParent;
		r || (r = u.appendChild(document.createElement("div")), r.style.cssText = "position: absolute; z-index: 50; pointer-events: none;", o.color && (r.style.backgroundColor = o.color)), Ue(r, n.orientation);
		let { parentLeft: d, parentTop: f } = We(u);
		r.style.left = (l.left - d) / s + "px", r.style.top = (l.top - f) / c + "px", r.style.width = (l.right - l.left) / s + "px", r.style.height = (l.bottom - l.top) / c + "px";
	}, l = (e) => {
		clearTimeout(i), i = window.setTimeout(() => s(null), e);
	}, u = (e) => {
		let t = e;
		a = t.target instanceof Element ? t.target : null;
	}, d = (t) => {
		let n = t;
		if (a && Be(a, o.exclude) || n.target instanceof Element && Be(n.target, o.exclude)) return;
		let r = e.prosemirrorView;
		if (!r.editable) return;
		let i = r.posAtCoords({
			left: n.clientX,
			top: n.clientY
		}), c = i && i.inside >= 0 && r.state.doc.nodeAt(i.inside), u = c && c.type.spec.disableDropCursor, d = typeof u == "function" ? u(r, i, n) : u;
		if (i && !d) {
			let t = i.pos;
			if (r.dragging && r.dragging.slice) {
				let e = ae(r.state.doc, t, r.dragging.slice);
				e != null && (t = e);
			}
			let a = !r.state.doc.resolve(t).parent.inlineContent, c = {
				pos: t,
				orientation: a ? "block-horizontal" : "inline"
			}, u = c;
			if (o.hooks?.computeDropPosition) {
				let t = o.hooks.computeDropPosition({
					editor: e,
					event: n,
					view: r,
					defaultPosition: c
				});
				if (t === null) {
					s(null);
					return;
				}
				u = t;
			}
			s(u), l(5e3);
		}
	}, f = (t) => {
		let n = t;
		(!(n.relatedTarget instanceof Node) || !e.prosemirrorView.dom.contains(n.relatedTarget)) && s(null);
	}, p = () => {
		l(20);
	}, m = () => {
		l(20), a = null;
	};
	return {
		key: "dropCursor",
		mount({ signal: e, dom: t, root: n }) {
			n.addEventListener("dragstart", u, {
				capture: !0,
				signal: e
			}), t.addEventListener("dragover", d, { signal: e }), t.addEventListener("dragleave", f, { signal: e }), t.addEventListener("drop", p, { signal: e }), t.addEventListener("dragend", m, { signal: e }), e.addEventListener("abort", () => {
				clearTimeout(i), s(null);
			});
		}
	};
}), qe = b(() => ({
	key: "history",
	prosemirrorPlugins: [De()],
	undoCommand: ke,
	redoCommand: Oe
})), Je = b(({ editor: e }) => {
	function t(t) {
		let n = e.prosemirrorView.nodeDOM(t);
		for (; n && n.parentElement;) {
			if (n.nodeName === "A") return n;
			n = n.parentElement;
		}
		return null;
	}
	function n(t) {
		let n = e.getLinkMarkAtPos(t);
		if (n) return {
			range: {
				from: n.from,
				to: n.to
			},
			mark: { attrs: { href: n.href } },
			get text() {
				return n.text;
			},
			get position() {
				return ce(e.prosemirrorView, n.from, n.to).toJSON();
			}
		};
	}
	function r() {
		return e.transact((e) => {
			if (e.selection.empty) return n(e.selection.anchor);
		});
	}
	return {
		key: "linkToolbar",
		getLinkAtSelection: r,
		getLinkElementAtPos: t,
		getMarkAtPos(e, t) {
			return n(e);
		},
		getLinkAtElement(t) {
			return e.transact(() => n(e.prosemirrorView.posAtDOM(t, 0) + 1));
		},
		editLink(t, n, r = e.transact((e) => e.selection.anchor)) {
			e.editLink(t, n, r);
		},
		deleteLink(t = e.transact((e) => e.selection.anchor)) {
			e.deleteLink(t);
		}
	};
}), Ye = [
	"http",
	"https",
	"ftp",
	"ftps",
	"mailto",
	"tel",
	"callto",
	"sms",
	"cid",
	"xmpp"
], Xe = "https", Ze = new w("node-selection-keyboard"), Qe = b(() => ({
	key: "nodeSelectionKeyboard",
	prosemirrorPlugins: [new C({
		key: Ze,
		props: { handleKeyDown: (e, t) => {
			if ("node" in e.state.selection) {
				if (t.ctrlKey || t.metaKey) return !1;
				if (t.key.length === 1) return t.preventDefault(), !0;
				if (t.key === "Enter" && !t.isComposing && !t.shiftKey && !t.altKey && !t.ctrlKey && !t.metaKey) {
					let t = e.state.tr;
					return e.dispatch(t.insert(e.state.tr.selection.$to.after(), e.state.schema.nodes.paragraph.createChecked()).setSelection(new de(t.doc.resolve(e.state.tr.selection.$to.after() + 1)))), !0;
				}
			}
			return !1;
		} }
	})]
})), $e = new w("blocknote-placeholder"), et = b(({ editor: e, options: t }) => {
	let n = t.placeholders;
	return {
		key: "placeholder",
		prosemirrorPlugins: [new C({
			key: $e,
			view: (t) => {
				let r = `placeholder-selector-${le()}`;
				t.dom.classList.add(r);
				let i = document.createElement("style"), a = e._tiptapEditor.options.injectNonce;
				a && i.setAttribute("nonce", a), t.root instanceof window.ShadowRoot ? t.root.append(i) : t.root.head.appendChild(i);
				let o = i.sheet, s = (e = "") => `.${r} .bn-block-content${e}:has(.ProseMirror-trailingBreak:only-child):after`;
				try {
					let { default: e, emptyDocument: t, ...r } = n || {};
					for (let [e, t] of Object.entries(r)) {
						let n = `[data-content-type="${e}"]`;
						o.insertRule(`${s(n)} { content: ${JSON.stringify(t)}; }`);
					}
					o.insertRule(`${s("[data-is-only-empty-block]")} { content: ${JSON.stringify(t)}; }`), o.insertRule(`${s("[data-is-empty-and-focused]")} { content: ${JSON.stringify(e)}; }`);
				} catch (e) {
					console.warn("Failed to insert placeholder CSS rule - this is likely due to the browser not supporting certain CSS pseudo-element selectors (:has, :only-child:, or :before)", e);
				}
				return { destroy: () => {
					t.root instanceof window.ShadowRoot ? t.root.removeChild(i) : t.root.head.removeChild(i);
				} };
			},
			props: { decorations: (t) => {
				let { doc: n, selection: r } = t;
				if (!e.isEditable || !r.empty || r.$from.parent.type.spec.code) return;
				let i = [];
				t.doc.content.size === 6 && i.push(E.node(2, 4, { "data-is-only-empty-block": "true" }));
				let a = r.$anchor, o = a.parent;
				if (o.content.size === 0) {
					let e = a.before();
					i.push(E.node(e, e + o.nodeSize, { "data-is-empty-and-focused": "true" }));
				}
				return D.create(n, i);
			} }
		})]
	};
}), tt = b(({ editor: e }) => {
	let t = new ie(), n = 0;
	function r() {
		t = new ie(), n = 0;
	}
	let i = typeof FinalizationRegistry < "u" ? new FinalizationRegistry(() => {
		n--, n === 0 && r();
	}) : null;
	return e.on("create", () => {
		e._tiptapEditor.on("transaction", ({ transaction: e }) => {
			n !== 0 && t.appendMapping(e.mapping);
		}), e._tiptapEditor.on("destroy", () => {
			r();
		});
	}), {
		key: "positionMapping",
		mapPosition: (e, r = "left") => {
			n++;
			let a = t.maps.length, o = () => t.slice(a).map(e, r === "left" ? -1 : 1);
			return i && i.register(o, void 0), o;
		}
	};
}), nt = new w("previous-blocks"), rt = {
	index: "index",
	level: "level",
	type: "type",
	depth: "depth",
	"depth-change": "depth-change"
}, it = b(() => {
	let t;
	return {
		key: "previousBlockType",
		prosemirrorPlugins: [new C({
			key: nt,
			view(e) {
				return {
					update: async (e, n) => {
						this.key?.getState(e.state).updatedBlocks.size > 0 && (t = setTimeout(() => {
							e.dispatch(e.state.tr.setMeta(nt, { clearUpdate: !0 }));
						}, 0));
					},
					destroy: () => {
						t && clearTimeout(t);
					}
				};
			},
			state: {
				init() {
					return {
						prevTransactionOldBlockAttrs: {},
						currentTransactionOldBlockAttrs: {},
						updatedBlocks: /* @__PURE__ */ new Set()
					};
				},
				apply(t, n, r, i) {
					if (n.currentTransactionOldBlockAttrs = {}, n.updatedBlocks.clear(), !t.docChanged) return n;
					let a = t.changedRange();
					if (!a) return n;
					let o = t.mapping.invert(), s = {
						from: o.map(a.from, -1),
						to: o.map(a.to, 1)
					}, c = {}, l = se(r.doc, s, (e) => e.attrs.id), u = new Map(l.map((t) => [e(t.node, r.doc), t])), d = se(i.doc, a, (e) => e.attrs.id);
					for (let t of d) {
						let a = e(t.node, i.doc), o = u.get(a), s = o?.node.firstChild, l = t.node.firstChild;
						if (o && s && l) {
							let e = {
								index: l.attrs.index,
								level: l.attrs.level,
								type: l.type.name,
								depth: i.doc.resolve(t.pos).depth
							}, u = {
								index: s.attrs.index,
								level: s.attrs.level,
								type: s.type.name,
								depth: r.doc.resolve(o.pos).depth
							};
							c[a] = u, n.currentTransactionOldBlockAttrs[a] = u, (u.index !== e.index || u.level !== e.level || u.type !== e.type || u.depth !== e.depth) && (u["depth-change"] = u.depth - e.depth, n.updatedBlocks.add(a));
						}
					}
					return n.prevTransactionOldBlockAttrs = c, n;
				}
			},
			props: { decorations(t) {
				let n = this.getState(t);
				if (n.updatedBlocks.size === 0) return;
				let r = [];
				return t.doc.descendants((i, a) => {
					if (!i.attrs.id) return;
					let o = e(i, t.doc);
					if (!n.updatedBlocks.has(o)) return;
					let s = n.currentTransactionOldBlockAttrs[o], c = {};
					for (let [e, t] of Object.entries(s)) c["data-prev-" + rt[e]] = t || "none";
					r.push(E.node(a, a + i.nodeSize, { ...c }));
				}), D.create(t.doc, r);
			} }
		})]
	};
});
//#endregion
//#region src/extensions/getDraggableBlockFromElement.ts
function A(e, t) {
	for (; e && e.parentElement && e.parentElement !== t.dom && e.getAttribute?.("data-node-type") !== "blockContainer";) e = e.parentElement;
	if (e.getAttribute?.("data-node-type") === "blockContainer") return {
		node: e,
		id: e.getAttribute("data-id")
	};
}
//#endregion
//#region src/api/exporters/markdown/htmlToMarkdown.ts
function at(e) {
	let t = document.createElement("div");
	return t.innerHTML = e, j(t, {
		indent: "",
		inListItem: !1
	}).trim() + "\n";
}
function j(e, t) {
	let n = "", r = Array.from(e.childNodes);
	for (let e = 0; e < r.length; e++) {
		let i = r[e];
		n += M(i, t);
	}
	return n;
}
function M(e, t) {
	if (e.nodeType === 3) return e.textContent || "";
	if (e.nodeType !== 1) return "";
	let n = e;
	switch (n.tagName.toLowerCase()) {
		case "p": return ot(n, t);
		case "h1":
		case "h2":
		case "h3":
		case "h4":
		case "h5":
		case "h6": return N(n, t);
		case "blockquote": return st(n, t);
		case "pre": return ct(n, t);
		case "ul": return ut(n, t);
		case "ol": return dt(n, t);
		case "table": return pt(n, t);
		case "hr": return t.indent + "***\n\n";
		case "img": return ht(n, t);
		case "video": return gt(n, t);
		case "audio": return _t(n, t);
		case "embed": return vt(n, t);
		case "figure": return yt(n, t);
		case "a": return xt(n, t);
		case "details": return wt(n, t);
		case "div": return j(n, t);
		case "br": return "";
		default: return j(n, t);
	}
}
function ot(e, t) {
	let n = Et(B(e));
	return t.inListItem ? n : t.indent + n + "\n\n";
}
function N(e, t) {
	let n = parseInt(e.tagName[1], 10), r = "#".repeat(n) + " ", i = B(e);
	return t.indent + r + i + "\n\n";
}
function st(e, t) {
	let n = Array.from(e.children).filter((e) => {
		let t = e.tagName.toLowerCase();
		return [
			"p",
			"ul",
			"ol",
			"pre",
			"blockquote",
			"table",
			"hr"
		].includes(t);
	}), r;
	if (n.length > 0) {
		let e = [];
		for (let t of n) t.tagName.toLowerCase() === "p" ? e.push(B(t)) : e.push(M(t, {
			indent: "",
			inListItem: !1
		}).trim());
		r = e.join("\n\n");
	} else r = B(e);
	return r.split("\n").map((e) => t.indent + "> " + e).join("\n") + "\n\n";
}
function ct(e, t) {
	let n = e.querySelector("code");
	if (!n) return "";
	let r = n.getAttribute("data-language") || lt(n.className) || "", i = P(n), a = Math.max(0, ...(i.match(/`+/g) ?? []).map((e) => e.length)), o = "`".repeat(Math.max(3, a + 1));
	return i ? t.indent + o + r + "\n" + i + (i.endsWith("\n") ? "" : "\n") + o + "\n\n" : t.indent + o + r + "\n" + o + "\n\n";
}
function P(e) {
	let t = "";
	for (let n of Array.from(e.childNodes)) n.nodeType === 3 ? t += n.textContent || "" : n.nodeType === 1 && (n.tagName.toLowerCase() === "br" ? t += "\n" : t += P(n));
	return t;
}
function lt(e) {
	let t = e.match(/language-(\S+)/);
	return t ? t[1] : "";
}
function ut(e, t) {
	let n = "", r = Array.from(e.children).filter((e) => e.tagName.toLowerCase() === "li");
	for (let e of r) n += F(e, "bullet", t);
	return t.inListItem || (n += "\n"), n;
}
function dt(e, t) {
	let n = "", r = Array.from(e.children).filter((e) => e.tagName.toLowerCase() === "li"), i = parseInt(e.getAttribute("start") || "1", 10);
	for (let e = 0; e < r.length; e++) {
		let a = i + e;
		n += F(r[e], "ordered", t, a);
	}
	return t.inListItem || (n += "\n"), n;
}
function F(e, t, n, r) {
	let i = null, a = null;
	for (let t of Array.from(e.children)) {
		let e = t.tagName.toLowerCase();
		e === "input" && t.type === "checkbox" && (i = t), e === "details" && (a = t);
	}
	let o, s;
	i ? (o = `* ${i.checked ? "[x]" : "[ ]"} `, s = 2) : t === "ordered" ? (o = `${r}. `, s = o.length) : (o = "* ", s = 2);
	let c, l;
	if (a) {
		let e = a.querySelector("summary")?.querySelector("p");
		l = a, c = e ? B(e) : "";
	} else l = ft(e, i), c = l ? B(l) : "";
	let u = n.indent + o + c + "\n", d = n.indent + " ".repeat(s), f = {
		indent: d,
		inListItem: !0
	};
	if (a) {
		let e = a.querySelector("summary");
		for (let t of Array.from(a.children)) if (t !== e) if (t.tagName.toLowerCase() === "p") {
			let e = B(t);
			u += "\n" + d + e + "\n";
		} else u += M(t, f);
	}
	let p = Array.from(e.children);
	for (let e of p) {
		let t = e.tagName.toLowerCase();
		if (!(e === l || e === i) && t !== "input") if (t === "ul" || t === "ol") u += M(e, f);
		else if (t === "p") {
			let t = B(e);
			u += "\n" + d + t + "\n";
		} else u += "\n" + M(e, f);
	}
	return u;
}
function ft(e, t) {
	for (let n of Array.from(e.children)) {
		if (n === t || n.tagName.toLowerCase() === "input") continue;
		let e = n.tagName.toLowerCase();
		if (e === "p" || e === "span") return n;
	}
	return null;
}
function pt(e, t) {
	let n = e.querySelector("colgroup"), r = 0;
	n && (r = n.querySelectorAll("col").length);
	let i = [], a = !1, o = e.querySelectorAll("tr"), s = [];
	o.forEach((e, t) => {
		s[t] || (s[t] = []);
		let n = e.querySelectorAll("th, td"), i = 0;
		n.forEach((e) => {
			for (; s[t][i] !== void 0;) i++;
			t === 0 && e.tagName.toLowerCase() === "th" && (a = !0);
			let n = mt(B(e).trim()), r = parseInt(e.getAttribute("colspan") || "1", 10), o = parseInt(e.getAttribute("rowspan") || "1", 10);
			for (let e = 0; e < o; e++) for (let a = 0; a < r; a++) {
				let r = t + e;
				s[r] || (s[r] = []), s[r][i + a] = e === 0 && a === 0 ? n : "";
			}
			i += r;
		}), s[t] && (r = Math.max(r, s[t].length));
	});
	for (let e of s) {
		let t = [];
		for (let n = 0; n < r; n++) t.push(e && e[n] !== void 0 ? e[n] ?? "" : "");
		i.push(t);
	}
	if (i.length === 0) return "";
	let c = [];
	for (let e = 0; e < r; e++) {
		let t = 3;
		for (let n of i) {
			let r = e < n.length ? n[e].length : 0;
			t = Math.max(t, r);
		}
		c.push(Math.max(t, 10));
	}
	let l = "";
	if (a) {
		l += t.indent + I(i[0], c, r) + "\n", l += t.indent + L(c, r) + "\n";
		for (let e = 1; e < i.length; e++) l += t.indent + I(i[e], c, r) + "\n";
	} else {
		let e = Array(r).fill("");
		l += t.indent + I(e, c, r) + "\n", l += t.indent + L(c, r) + "\n";
		for (let e of i) l += t.indent + I(e, c, r) + "\n";
	}
	return l += "\n", l;
}
function mt(e) {
	return e.replace(/\|/g, "\\|");
}
function I(e, t, n) {
	let r = [];
	for (let i = 0; i < n; i++) {
		let n = i < e.length ? e[i] : "";
		r.push(" " + n.padEnd(t[i]) + " ");
	}
	return "|" + r.join("|") + "|";
}
function L(e, t) {
	let n = [];
	for (let r = 0; r < t; r++) n.push(" " + "-".repeat(e[r]) + " ");
	return "|" + n.join("|") + "|";
}
function ht(e, t) {
	let n = e.getAttribute("src") || "", r = e.getAttribute("alt") || "";
	return n ? t.indent + `![${r}](${n})\n\n` : "\n\n";
}
function gt(e, t) {
	let n = e.getAttribute("src") || e.getAttribute("data-url") || "", r = e.getAttribute("data-name") || e.getAttribute("title") || "";
	return n ? t.indent + `![${r}](${n})\n\n` : "\n\n";
}
function _t(e, t) {
	let n = e.getAttribute("src") || "";
	return n ? t.indent + `<audio src="${z(n)}" controls></audio>\n\n` : "\n\n";
}
function vt(e, t) {
	let n = e.getAttribute("src") || "";
	return n ? t.indent + `[](${n})\n\n` : "\n\n";
}
function yt(e, t) {
	let n = e.querySelector("img"), r = e.querySelector("video"), i = e.querySelector("audio"), a = e.querySelector("a"), o = e.querySelector("figcaption")?.textContent?.trim() || "";
	return n ? R("img", n.getAttribute("src") || "", n.getAttribute("alt") || "", o, t) : r ? R("video", r.getAttribute("src") || r.getAttribute("data-url") || "", r.getAttribute("data-name") || r.getAttribute("title") || "", o, t) : i ? R("audio", i.getAttribute("src") || "", "", o, t) : a ? xt(a, t) : "";
}
function R(e, t, n, r, i) {
	if (!t) return "";
	if (!r && e !== "audio") return i.indent + `![${n}](${t})\n\n`;
	let a = n && n !== r ? e === "img" ? ` alt="${z(n)}"` : e === "video" ? ` data-name="${z(n)}"` : "" : "", o = e === "img" ? `<img${a} src="${z(t)}">` : `<${e} src="${z(t)}"${a} controls></${e}>`, s = r ? `<figcaption>${bt(r)}</figcaption>` : "";
	return i.indent + `<figure>${o}${s}</figure>\n\n`;
}
function z(e) {
	return e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}
function bt(e) {
	return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}
function xt(e, t) {
	let n = e.getAttribute("href") || "", r = e.textContent?.trim() || "";
	return n ? t.indent + St(r, n) + "\n\n" : t.indent + r + "\n\n";
}
function St(e, t) {
	return !e || e === t ? t : `[${e}](${Ct(t)})`;
}
function Ct(e) {
	return e.replace(/[\\()]/g, "\\$&");
}
function wt(e, t) {
	let n = e.querySelector("summary");
	if (!n) return j(e, t);
	let r = n.querySelector("h1, h2, h3, h4, h5, h6");
	if (r) {
		let i = N(r, t);
		for (let r of Array.from(e.children)) r !== n && (i += M(r, t));
		return i;
	}
	return j(n, t);
}
function B(e) {
	let t = "";
	for (let n of Array.from(e.childNodes)) if (n.nodeType === 3) t += n.textContent || "";
	else if (n.nodeType === 1) {
		let e = n;
		switch (e.tagName.toLowerCase()) {
			case "strong":
			case "b": {
				let { content: n, trailing: r } = Tt(B(e));
				n ? t += `**${n}**${r}` : t += r;
				break;
			}
			case "em":
			case "i": {
				let { content: n, trailing: r } = Tt(B(e));
				n ? t += `*${n}*${r}` : t += r;
				break;
			}
			case "s":
			case "del":
				t += `~~${B(e)}~~`;
				break;
			case "code": {
				let n = e.textContent || "", r = Math.max(0, ...(n.match(/`+/g) ?? []).map((e) => e.length)), i = "`".repeat(r + 1), a = n.startsWith("`") || n.endsWith("`");
				t += i + (a ? ` ${n} ` : n) + i;
				break;
			}
			case "u":
				t += B(e);
				break;
			case "a": {
				let n = e.getAttribute("href") || "", r = B(e);
				t += St(r, n);
				break;
			}
			case "br":
				t += "\\\n";
				break;
			case "span":
				t += B(e);
				break;
			case "img": {
				let n = e.getAttribute("src") || "", r = e.getAttribute("alt") || "";
				t += `![${r}](${n})`;
				break;
			}
			case "video": {
				let n = e.getAttribute("src") || e.getAttribute("data-url") || "", r = e.getAttribute("data-name") || e.getAttribute("title") || "";
				t += `![${r}](${n})`;
				break;
			}
			case "p":
				t += B(e);
				break;
			case "input": break;
			default:
				t += B(e);
				break;
		}
	}
	return t;
}
function Tt(e) {
	let t = e.match(/^(.*?)(\s*)$/);
	return t ? {
		content: t[1],
		trailing: t[2]
	} : {
		content: e,
		trailing: ""
	};
}
function Et(e) {
	let t = e.replace(/^(\\\n)+/, "");
	return t = t.replace(/(\\\n)+$/, ""), t;
}
//#endregion
//#region src/api/exporters/markdown/markdownExporter.ts
function V(e) {
	return at(e);
}
function Dt(e, t, n, r) {
	return V(k(t, n).exportBlocks(e, r));
}
//#endregion
//#region src/api/nodeConversions/fragmentToBlocks.ts
function Ot(e) {
	let t = [];
	return e.descendants((e) => e.type.name === "blockContainer" && e.firstChild?.type.name === "blockGroup" ? !0 : e.type.name === "columnList" && e.childCount === 1 ? (e.firstChild?.forEach((n) => {
		t.push(_(n, e));
	}), !1) : e.type.isInGroup("bnBlock") ? (t.push(_(e, e)), !1) : !0), t;
}
//#endregion
//#region src/extensions/SideMenu/MultipleNodeSelection.ts
var H = class e extends T {
	nodes;
	constructor(e, t) {
		super(e, t);
		let n = e.node();
		this.nodes = [], e.doc.nodesBetween(e.pos, t.pos, (e, t, r) => {
			if (r !== null && r.eq(n)) return this.nodes.push(e), !1;
		});
	}
	static create(t, n, r = n) {
		return new e(t.resolve(n), t.resolve(r));
	}
	content() {
		return new re(S.from(this.nodes), 0, 0);
	}
	eq(t) {
		if (!(t instanceof e) || this.nodes.length !== t.nodes.length || this.from !== t.from || this.to !== t.to) return !1;
		for (let e = 0; e < this.nodes.length; e++) if (!this.nodes[e].eq(t.nodes[e])) return !1;
		return !0;
	}
	map(t, n) {
		let r = n.mapResult(this.from), i = n.mapResult(this.to);
		return i.deleted ? T.near(t.resolve(r.pos)) : r.deleted ? T.near(t.resolve(i.pos)) : new e(t.resolve(r.pos), t.resolve(i.pos));
	}
	toJSON() {
		return {
			type: "multiple-node",
			anchor: this.anchor,
			head: this.head
		};
	}
};
T.jsonID("multiple-node", H);
//#endregion
//#region src/extensions/SideMenu/dragging.ts
var U;
function kt(e, t) {
	let n, r, i = t.resolve(e.from).node().type.spec.group === "blockContent", a = t.resolve(e.to).node().type.spec.group === "blockContent", o = Math.min(e.$anchor.depth, e.$head.depth);
	if (i && a) {
		let i = e.$from.start(o - 1), a = e.$to.end(o - 1);
		n = t.resolve(i - 1).pos, r = t.resolve(a + 1).pos;
	} else n = e.from, r = e.to;
	return {
		from: n,
		to: r
	};
}
function At(e, t, n = t) {
	t === n && (n += e.state.doc.resolve(t + 1).node().nodeSize);
	let r = e.domAtPos(t).node.cloneNode(!0), i = e.domAtPos(t).node, a = (e, t) => Array.prototype.indexOf.call(e.children, t), o = a(i, e.domAtPos(t + 1).node.parentElement), s = a(i, e.domAtPos(n - 1).node.parentElement);
	for (let e = i.childElementCount - 1; e >= 0; e--) (e > s || e < o) && r.removeChild(r.children[e]);
	jt(e.root), U = r, U.querySelectorAll("iframe, embed, object").forEach((e) => e.parentElement?.removeChild(e));
	let c = e.dom.className.split(" ").filter((e) => e !== "ProseMirror" && e !== "bn-root" && e !== "bn-editor").join(" ");
	U.className = U.className + " bn-drag-preview " + c, e.root instanceof ShadowRoot ? e.root.appendChild(U) : e.root.body.appendChild(U);
}
function jt(e) {
	U !== void 0 && (e instanceof ShadowRoot ? e.removeChild(U) : e.body.removeChild(U), U = void 0);
}
function Mt(e, t, n) {
	if (!e.dataTransfer || n.headless) return;
	let r = n.prosemirrorView, i = ee(t.id, r.state.doc);
	if (!i) throw Error(`Block with ID ${t.id} not found`);
	let a = i.posBeforeNode;
	if (a != null) {
		let t = r.state.selection, i = r.state.doc, { from: o, to: s } = kt(t, i), c = o <= a && a < s, l = t.$anchor.node() !== t.$head.node() || t instanceof H;
		c && l ? (r.dispatch(r.state.tr.setSelection(H.create(i, o, s))), At(r, o, s)) : (r.dispatch(r.state.tr.setSelection(ue.create(r.state.doc, a))), At(r, a));
		let u = r.state.selection.content(), d = n.pmSchema, f = r.serializeForClipboard(u).dom.innerHTML, p = k(d, n), m = Ot(u.content), h = p.exportBlocks(m, {}), g = V(h);
		e.dataTransfer.clearData(), e.dataTransfer.setData("blocknote/html", f), e.dataTransfer.setData("text/html", h), e.dataTransfer.setData("text/plain", g), e.dataTransfer.effectAllowed = "move", e.dataTransfer.setDragImage(U, 0, 0);
	}
}
//#endregion
//#region src/extensions/SideMenu/SideMenu.ts
var Nt = 250;
function W(e, t, n = !0) {
	let r = e.root.elementsFromPoint(t.left, t.top);
	for (let i of r) if (e.dom.contains(i)) return n && i.closest("[data-node-type=columnList]") ? W(e, {
		left: t.left + 50,
		top: t.top
	}, !1) : A(i, e);
}
function Pt(e, t) {
	if (!t.dom.firstChild) return;
	let n = t.dom.firstChild.getBoundingClientRect(), r = W(t, {
		left: Math.min(Math.max(n.left + 10, e.x), n.right - 10),
		top: e.y
	});
	if (r) return W(t, {
		left: r.node.getBoundingClientRect().right - 10,
		top: e.y
	}, !1);
}
var Ft = class {
	editor;
	pmView;
	state;
	emitUpdate;
	mousePos;
	hoveredBlock;
	menuFrozen = !1;
	isDragOrigin = !1;
	constructor(e, t, n) {
		this.editor = e, this.pmView = t, this.emitUpdate = () => {
			if (!this.state) throw Error("Attempting to update uninitialized side menu");
			n(this.state);
		}, this.pmView.root.addEventListener("dragstart", this.onDragStart), this.pmView.root.addEventListener("dragover", this.onDragOver), this.pmView.root.addEventListener("drop", this.onDrop, !0), this.pmView.root.addEventListener("dragend", this.onDragEnd, !0), this.pmView.root.addEventListener("mousemove", this.onMouseMove, !0), this.pmView.root.addEventListener("keydown", this.onKeyDown, !0);
	}
	updateState = (e) => {
		this.state = e, this.emitUpdate(this.state);
	};
	updateStateFromMousePos = () => {
		if (this.menuFrozen || !this.mousePos) return;
		let e = this.findClosestEditorElement({
			clientX: this.mousePos.x,
			clientY: this.mousePos.y
		});
		if (e?.element !== this.pmView.dom || e.distance > Nt) {
			this.state?.show && (this.state.show = !1, this.updateState(this.state));
			return;
		}
		let t = Pt(this.mousePos, this.pmView);
		if (!t || !this.editor.isEditable) {
			this.state?.show && (this.state.show = !1, this.updateState(this.state));
			return;
		}
		if (!(this.state?.show && this.hoveredBlock?.hasAttribute("data-id") && this.hoveredBlock?.getAttribute("data-id") === t.id) && (this.hoveredBlock = t.node, this.editor.isEditable)) {
			let e = t.node.getBoundingClientRect(), n = t.node.closest("[data-node-type=column]");
			this.state = {
				show: !0,
				referencePos: new DOMRect(n ? n.firstElementChild.getBoundingClientRect().x : this.pmView.dom.firstChild.getBoundingClientRect().x, e.y, e.width, e.height),
				block: this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))
			}, this.updateState(this.state);
		}
	};
	onDragStart = (e) => {
		let t = e.dataTransfer?.getData("blocknote/html");
		if (!t || this.pmView.dragging) return;
		let n = document.createElement("div");
		n.innerHTML = t;
		let r = fe.fromSchema(this.pmView.state.schema).parse(n, { topNode: this.pmView.state.schema.nodes.blockGroup.create() });
		this.pmView.dragging = {
			slice: new pe(r.content, 0, 0),
			move: !0
		};
	};
	findClosestEditorElement = (e) => {
		let t = Array.from(this.pmView.root.querySelectorAll(".bn-editor"));
		if (t.length === 0) return null;
		let n = t[0], r = Number.MAX_VALUE;
		return t.forEach((t) => {
			let i = t.querySelector(".bn-block-group").getBoundingClientRect(), a = e.clientX < i.left ? i.left - e.clientX : e.clientX > i.right ? e.clientX - i.right : 0, o = e.clientY < i.top ? i.top - e.clientY : e.clientY > i.bottom ? e.clientY - i.bottom : 0, s = Math.sqrt(a ** 2 + o ** 2);
			s < r && (r = s, n = t);
		}), {
			element: n,
			distance: r
		};
	};
	onDragOver = (e) => {
		if (e.synthetic || !(this.pmView.dragging !== null || this.isDragOrigin || e.dataTransfer?.types.includes("blocknote/html") || e.target instanceof Node && this.pmView.dom.contains(e.target))) return;
		let t = this.getDragEventContext(e);
		if (!t || !t.isDropPoint) {
			this.closeDropCursor();
			return;
		}
		t.isDropPoint && !t.isDropWithinEditorBounds && this.dispatchSyntheticEvent(e);
	};
	closeDropCursor = () => {
		let e = new Event("dragleave", { bubbles: !1 });
		e.synthetic = !0, this.pmView.dom.dispatchEvent(e);
	};
	getDragEventContext = (e) => {
		if (!(this.pmView.dragging !== null || this.isDragOrigin || e.dataTransfer?.types.includes("blocknote/html") || e.target instanceof Node && this.pmView.dom.contains(e.target))) return;
		let t = !e.dataTransfer?.types.includes("blocknote/html") && !!this.pmView.dragging, n = !!this.isDragOrigin, r = t || n, i = this.findClosestEditorElement(e);
		if (!i || i.distance > Nt) return;
		let a = i.element === this.pmView.dom, o = a && i.distance === 0;
		if (!(!a && !r)) return {
			isDropPoint: a,
			isDropWithinEditorBounds: o,
			isDragOrigin: r
		};
	};
	onDrop = (e) => {
		if (e.synthetic || !(this.pmView.dragging !== null || this.isDragOrigin || e.dataTransfer?.types.includes("blocknote/html") || e.target instanceof Node && this.pmView.dom.contains(e.target))) return;
		let t = this.getDragEventContext(e);
		if (!t) {
			this.closeDropCursor();
			return;
		}
		let { isDropPoint: n, isDropWithinEditorBounds: r, isDragOrigin: i } = t;
		if (!r && n && this.dispatchSyntheticEvent(e), n) {
			if (this.pmView.dragging) return;
			this.pmView.dispatch(this.pmView.state.tr.setSelection(Te.create(this.pmView.state.tr.doc, this.pmView.state.tr.selection.anchor)));
			return;
		} else if (i) {
			setTimeout(() => this.pmView.dispatch(this.pmView.state.tr.deleteSelection()), 0);
			return;
		}
	};
	onDragEnd = (e) => {
		e.synthetic || (this.pmView.dragging = null);
	};
	onKeyDown = (e) => {
		this.state?.show && this.editor.isFocused() && (this.state.show = !1, this.emitUpdate(this.state));
	};
	onMouseMove = (e) => {
		if (this.menuFrozen || !Number.isFinite(e.clientX) || !Number.isFinite(e.clientY)) return;
		this.mousePos = {
			x: e.clientX,
			y: e.clientY
		};
		let t = this.pmView.dom.getBoundingClientRect();
		if (this.mousePos.x > t.left && this.mousePos.x < t.right && this.mousePos.y > t.top && this.mousePos.y < t.bottom && e && e.target && !this.editor.isWithinEditor(e.target)) {
			this.state?.show && (this.state.show = !1, this.emitUpdate(this.state));
			return;
		}
		this.updateStateFromMousePos();
	};
	dispatchSyntheticEvent(e) {
		let t = new Event(e.type, e), n = this.pmView.dom.firstChild.getBoundingClientRect();
		t.clientX = e.clientX, t.clientY = e.clientY, t.clientX = Math.min(Math.max(e.clientX, n.left), n.left + n.width), t.clientY = Math.min(Math.max(e.clientY, n.top), n.top + n.height), t.dataTransfer = e.dataTransfer, t.preventDefault = () => e.preventDefault(), t.synthetic = !0, this.pmView.dom.dispatchEvent(t);
	}
	update(e, t) {
		!t.doc.eq(this.pmView.state.doc) && this.state?.show && this.updateStateFromMousePos();
	}
	destroy() {
		this.state?.show && (this.state.show = !1, this.emitUpdate(this.state)), this.pmView.root.removeEventListener("mousemove", this.onMouseMove, !0), this.pmView.root.removeEventListener("dragstart", this.onDragStart), this.pmView.root.removeEventListener("dragover", this.onDragOver), this.pmView.root.removeEventListener("drop", this.onDrop, !0), this.pmView.root.removeEventListener("dragend", this.onDragEnd, !0), this.pmView.root.removeEventListener("keydown", this.onKeyDown, !0);
	}
}, It = new we("SideMenuPlugin"), Lt = b(({ editor: e }) => {
	let t, n = y(void 0);
	return {
		key: "sideMenu",
		store: n,
		prosemirrorPlugins: [new Ce({
			key: It,
			view: (r) => (t = new Ft(e, r, (e) => {
				n.setState({ ...e });
			}), t)
		})],
		blockDragStart(n, r) {
			t && (t.isDragOrigin = !0), Mt(n, r, e);
		},
		blockDragEnd() {
			jt(e.prosemirrorView.root), t && (t.isDragOrigin = !1), e.blur();
		},
		freezeMenu() {
			t.menuFrozen = !0, t.state.show = !0, t.emitUpdate(t.state);
		},
		unfreezeMenu() {
			t.menuFrozen = !1, t.state.show = !1, t.emitUpdate(t.state);
		},
		hideMenuIfNotFrozen() {
			!t.menuFrozen && t.state?.show && (t.state.show = !1, t.emitUpdate(t.state));
		}
	};
}), G;
async function Rt() {
	return G || (G = (async () => {
		let [e, t] = await Promise.all([import("emoji-mart"), import("@emoji-mart/data")]), n = "default" in e ? e.default : e, r = "default" in t ? t.default : t;
		return await n.init({ data: r }), {
			emojiMart: n,
			emojiData: r
		};
	})(), G);
}
async function zt(e, t) {
	if (!("text" in e.schema.inlineContentSchema) || e.schema.inlineContentSchema.text !== te.text) return [];
	let { emojiData: n, emojiMart: r } = await Rt();
	return (t.trim() === "" ? Object.values(n.emojis) : await r.SearchIndex.search(t)).map((t) => ({
		id: t.skins[0].native,
		onItemClick: () => e.insertInlineContent(t.skins[0].native + " ")
	}));
}
//#endregion
//#region src/extensions/TableHandles/TableHandles.ts
var K;
function Bt(e) {
	K || (K = document.createElement("div"), K.innerHTML = "_", K.style.opacity = "0", K.style.height = "1px", K.style.width = "1px", e instanceof Document ? e.body.appendChild(K) : e.appendChild(K));
}
function Vt(e) {
	K &&= (e instanceof Document ? e.body.removeChild(K) : e.removeChild(K), void 0);
}
function q(e) {
	return Array.prototype.indexOf.call(e.parentElement.childNodes, e);
}
function Ht(e) {
	let t = e;
	for (; t && t.nodeName !== "TD" && t.nodeName !== "TH" && !t.classList.contains("tableWrapper");) {
		if (t.classList.contains("ProseMirror")) return;
		let e = t.parentNode;
		if (!e || !(e instanceof Element)) return;
		t = e;
	}
	return t.nodeName === "TD" || t.nodeName === "TH" ? {
		type: "cell",
		domNode: t,
		tbodyNode: t.closest("tbody")
	} : {
		type: "wrapper",
		domNode: t,
		tbodyNode: t.querySelector("tbody")
	};
}
function Ut(e, t) {
	let n = t.querySelectorAll(e);
	for (let e = 0; e < n.length; e++) n[e].style.visibility = "hidden";
}
var Wt = class {
	editor;
	pmView;
	state;
	emitUpdate;
	tableId;
	tablePos;
	tableElement;
	menuFrozen = !1;
	mouseState = "up";
	prevWasEditable = null;
	constructor(e, t, n) {
		this.editor = e, this.pmView = t, this.emitUpdate = () => {
			n(this.state);
		}, t.dom.addEventListener("mousemove", this.mouseMoveHandler), t.dom.addEventListener("mousedown", this.viewMousedownHandler), window.addEventListener("mouseup", this.mouseUpHandler), t.root.addEventListener("dragover", this.dragOverHandler), t.root.addEventListener("drop", this.dropHandler);
	}
	viewMousedownHandler = () => {
		this.mouseState = "down";
	};
	mouseUpHandler = (e) => {
		this.mouseState = "up", this.mouseMoveHandler(e);
	};
	mouseMoveHandler = (e) => {
		if (this.menuFrozen || this.mouseState === "selecting" || !(e.target instanceof Element) || !this.pmView.dom.contains(e.target)) return;
		let t = Ht(e.target);
		if (t?.type === "cell" && this.mouseState === "down" && !this.state?.draggingState) {
			this.mouseState = "selecting", this.state?.show && (this.state.show = !1, this.state.showAddOrRemoveRowsButton = !1, this.state.showAddOrRemoveColumnsButton = !1, this.emitUpdate());
			return;
		}
		if (!t || !this.editor.isEditable) {
			this.state?.show && (this.state.show = !1, this.state.showAddOrRemoveRowsButton = !1, this.state.showAddOrRemoveColumnsButton = !1, this.emitUpdate());
			return;
		}
		if (!t.tbodyNode) return;
		let n = t.tbodyNode.getBoundingClientRect(), r = A(t.domNode, this.pmView);
		if (!r) return;
		this.tableElement = r.node;
		let i, { pmNodeInfo: a, doc: o } = this.editor.transact((e) => ({
			pmNodeInfo: ee(r.id, e.doc),
			doc: e.doc
		}));
		if (!a) throw Error(`Block with ID ${r.id} not found`);
		let s = _(a.node, o);
		if (g(this.editor, "table") && (this.tablePos = a.posBeforeNode + 1, i = s), !i) return;
		this.tableId = r.id;
		let c = t.domNode.closest(".tableWrapper")?.querySelector(".table-widgets-container");
		if (t?.type === "wrapper") {
			let t = e.clientY >= n.bottom - 1 && e.clientY < n.bottom + 20, r = e.clientX >= n.right - 1 && e.clientX < n.right + 20, a = this.state?.block?.id !== i.id || e.clientX > n.right || e.clientY > n.bottom;
			this.state = {
				...this.state,
				show: !0,
				showAddOrRemoveRowsButton: t,
				showAddOrRemoveColumnsButton: r,
				referencePosTable: n,
				block: i,
				widgetContainer: c,
				colIndex: a ? void 0 : this.state?.colIndex,
				rowIndex: a ? void 0 : this.state?.rowIndex,
				referencePosCell: a ? void 0 : this.state?.referencePosCell
			};
		} else {
			let e = q(t.domNode), a = q(t.domNode.parentElement), o = t.domNode.getBoundingClientRect();
			if (this.state !== void 0 && this.state.show && this.tableId === r.id && this.state.rowIndex === a && this.state.colIndex === e) return;
			this.state = {
				show: !0,
				showAddOrRemoveColumnsButton: e === i.content.rows[0].cells.length - 1,
				showAddOrRemoveRowsButton: a === i.content.rows.length - 1,
				referencePosTable: n,
				block: i,
				draggingState: void 0,
				referencePosCell: o,
				colIndex: e,
				rowIndex: a,
				widgetContainer: c
			};
		}
		return this.emitUpdate(), !1;
	};
	dragOverHandler = (e) => {
		if (this.state?.draggingState === void 0) return;
		e.preventDefault(), e.dataTransfer.dropEffect = "move", Ut(".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline", this.pmView.root);
		let t = {
			left: Math.min(Math.max(e.clientX, this.state.referencePosTable.left + 1), this.state.referencePosTable.right - 1),
			top: Math.min(Math.max(e.clientY, this.state.referencePosTable.top + 1), this.state.referencePosTable.bottom - 1)
		}, n = this.pmView.root.elementsFromPoint(t.left, t.top).filter((e) => e.tagName === "TD" || e.tagName === "TH");
		if (n.length === 0) return;
		let r = n[0], i = !1, a = q(r.parentElement), o = q(r), s = this.state.draggingState.draggedCellOrientation === "row" ? this.state.rowIndex : this.state.colIndex, c = (this.state.draggingState.draggedCellOrientation === "row" ? a : o) !== s;
		(this.state.rowIndex !== a || this.state.colIndex !== o) && (this.state.rowIndex = a, this.state.colIndex = o, this.state.referencePosCell = r.getBoundingClientRect(), i = !0);
		let l = this.state.draggingState.draggedCellOrientation === "row" ? t.top : t.left;
		this.state.draggingState.mousePos !== l && (this.state.draggingState.mousePos = l, i = !0), i && this.emitUpdate(), c && this.editor.transact((e) => e.setMeta(J, !0));
	};
	dropHandler = (e) => {
		if (this.mouseState = "up", this.state === void 0 || this.state.draggingState === void 0) return !1;
		if (this.state.rowIndex === void 0 || this.state.colIndex === void 0) throw Error("Attempted to drop table row or column, but no table block was hovered prior.");
		e.preventDefault();
		let { draggingState: t, colIndex: n, rowIndex: r } = this.state;
		this.state.draggingState = void 0;
		let a = this.state.block.content.columnWidths;
		if (t.draggedCellOrientation === "row") {
			if (!s(this.state.block, t.originalIndex, r)) return !1;
			let e = f(this.state.block, t.originalIndex, r);
			this.editor.updateBlock(this.state.block, {
				type: "table",
				content: {
					...this.state.block.content,
					rows: e
				}
			});
		} else {
			if (!o(this.state.block, t.originalIndex, n)) return !1;
			let e = i(this.state.block, t.originalIndex, n), [r] = a.splice(t.originalIndex, 1);
			a.splice(n, 0, r), this.editor.updateBlock(this.state.block, {
				type: "table",
				content: {
					...this.state.block.content,
					columnWidths: a,
					rows: e
				}
			});
		}
		return this.editor.setTextCursorPosition(this.state.block.id), !0;
	};
	update() {
		if (!this.state || !this.state.show) return;
		if (this.state.block = this.editor.getBlock(this.state.block.id), !this.state.block || this.state.block.type !== "table" || !this.tableElement?.isConnected) {
			this.state = void 0, this.tableId = void 0, this.tableElement = void 0, this.emitUpdate();
			return;
		}
		let { height: e, width: t } = p(this.state.block);
		this.state.rowIndex !== void 0 && this.state.colIndex !== void 0 && (this.state.rowIndex >= e && (this.state.rowIndex = e - 1), this.state.colIndex >= t && (this.state.colIndex = t - 1));
		let n = this.tableElement.querySelector("tbody");
		if (!n) throw Error("Table block does not contain a 'tbody' HTML element. This should never happen.");
		if (this.state.rowIndex !== void 0 && this.state.colIndex !== void 0) {
			let e = n.children[this.state.rowIndex].children[this.state.colIndex];
			e ? this.state.referencePosCell = e.getBoundingClientRect() : (this.state.rowIndex = void 0, this.state.colIndex = void 0);
		}
		this.state.referencePosTable = n.getBoundingClientRect(), this.emitUpdate();
	}
	destroy() {
		this.pmView.dom.removeEventListener("mousemove", this.mouseMoveHandler), window.removeEventListener("mouseup", this.mouseUpHandler), this.pmView.dom.removeEventListener("mousedown", this.viewMousedownHandler), this.pmView.root.removeEventListener("dragover", this.dragOverHandler), this.pmView.root.removeEventListener("drop", this.dropHandler);
	}
}, J = new w("TableHandlesPlugin"), Gt = b(({ editor: e }) => {
	let t, i = y(void 0);
	return {
		key: "tableHandles",
		store: i,
		prosemirrorPlugins: [new C({
			key: J,
			view: (n) => (t = new Wt(e, n, (e) => {
				i.setState(e?.block ? {
					...e,
					draggingState: e.draggingState ? { ...e.draggingState } : void 0
				} : void 0);
			}), t),
			props: { decorations: (e) => {
				if (t === void 0 || t.state === void 0 || t.state.draggingState === void 0 || t.tablePos === void 0) return;
				let r = t.state.draggingState.draggedCellOrientation === "row" ? t.state.rowIndex : t.state.colIndex;
				if (r === void 0) return;
				let i = [], { block: a, draggingState: c } = t.state, { originalIndex: l, draggedCellOrientation: u } = c;
				if (r === l || !a || u === "row" && !s(a, l, r) || u === "col" && !o(a, l, r)) return D.create(e.doc, i);
				let d = e.doc.resolve(t.tablePos + 1);
				return t.state.draggingState.draggedCellOrientation === "row" ? n(t.state.block, r).forEach(({ row: t, col: n }) => {
					let a = e.doc.resolve(d.posAtIndex(t) + 1), o = e.doc.resolve(a.posAtIndex(n) + 1), s = o.node(), c = o.pos + (r > l ? s.nodeSize - 2 : 0);
					i.push(E.widget(c, () => {
						let e = document.createElement("div");
						return e.className = "bn-table-drop-cursor", e.style.left = "0", e.style.right = "0", r > l ? e.style.bottom = "-2px" : e.style.top = "-3px", e.style.height = "4px", e;
					}));
				}) : v(t.state.block, r).forEach(({ row: t, col: n }) => {
					let a = e.doc.resolve(d.posAtIndex(t) + 1), o = e.doc.resolve(a.posAtIndex(n) + 1), s = o.node(), c = o.pos + (r > l ? s.nodeSize - 2 : 0);
					i.push(E.widget(c, () => {
						let e = document.createElement("div");
						return e.className = "bn-table-drop-cursor", e.style.top = "0", e.style.bottom = "0", r > l ? e.style.right = "-2px" : e.style.left = "-3px", e.style.width = "4px", e;
					}));
				}), D.create(e.doc, i);
			} }
		})],
		colDragStart(n) {
			if (t === void 0 || t.state === void 0 || t.state.colIndex === void 0) throw Error("Attempted to drag table column, but no table block was hovered prior.");
			t.state.draggingState = {
				draggedCellOrientation: "col",
				originalIndex: t.state.colIndex,
				mousePos: n.clientX
			}, t.emitUpdate(), e.transact((e) => e.setMeta(J, {
				draggedCellOrientation: t.state.draggingState.draggedCellOrientation,
				originalIndex: t.state.colIndex,
				newIndex: t.state.colIndex,
				tablePos: t.tablePos
			})), !e.headless && (Bt(e.prosemirrorView.root), n.dataTransfer.setDragImage(K, 0, 0), n.dataTransfer.effectAllowed = "move");
		},
		rowDragStart(n) {
			if (t.state === void 0 || t.state.rowIndex === void 0) throw Error("Attempted to drag table row, but no table block was hovered prior.");
			t.state.draggingState = {
				draggedCellOrientation: "row",
				originalIndex: t.state.rowIndex,
				mousePos: n.clientY
			}, t.emitUpdate(), e.transact((e) => e.setMeta(J, {
				draggedCellOrientation: t.state.draggingState.draggedCellOrientation,
				originalIndex: t.state.rowIndex,
				newIndex: t.state.rowIndex,
				tablePos: t.tablePos
			})), !e.headless && (Bt(e.prosemirrorView.root), n.dataTransfer.setDragImage(K, 0, 0), n.dataTransfer.effectAllowed = "copyMove");
		},
		dragEnd() {
			if (t.state === void 0) throw Error("Attempted to drag table row, but no table block was hovered prior.");
			t.state.draggingState = void 0, t.emitUpdate(), e.transact((e) => e.setMeta(J, null)), !e.headless && Vt(e.prosemirrorView.root);
		},
		freezeHandles() {
			t.menuFrozen = !0;
		},
		unfreezeHandles() {
			t.menuFrozen = !1;
		},
		hideHandlesIfNotFrozen() {
			!t.menuFrozen && t.state?.show && (t.state.show = !1, t.state.showAddOrRemoveRowsButton = !1, t.state.showAddOrRemoveColumnsButton = !1, t.emitUpdate());
		},
		getCellsAtRowHandle(e, t) {
			return n(e, t);
		},
		getCellsAtColumnHandle(e, t) {
			return v(e, t);
		},
		setCellSelection(e, n, r = n) {
			if (!t) throw Error("Table handles view not initialized");
			let i = e.doc.resolve(t.tablePos + 1), a = e.doc.resolve(i.posAtIndex(n.row) + 1), o = e.doc.resolve(a.posAtIndex(n.col)), s = e.doc.resolve(i.posAtIndex(r.row) + 1), c = e.doc.resolve(s.posAtIndex(r.col)), l = e.tr;
			return l.setSelection(new me(o, c)), e.apply(l);
		},
		addRowOrColumn(t, n) {
			e.exec((e, r) => {
				let i = this.setCellSelection(e, n.orientation === "row" ? {
					row: t,
					col: 0
				} : {
					row: 0,
					col: t
				});
				return n.orientation === "row" ? n.side === "above" ? ve(i, r) : _e(i, r) : n.side === "left" ? ge(i, r) : he(i, r);
			});
		},
		removeRowOrColumn(t, n) {
			return n === "row" ? e.exec((e, n) => be(this.setCellSelection(e, {
				row: t,
				col: 0
			}), n)) : e.exec((e, n) => ye(this.setCellSelection(e, {
				row: 0,
				col: t
			}), n));
		},
		mergeCells(t) {
			return e.exec((e, n) => xe(t ? this.setCellSelection(e, t.relativeStartCell, t.relativeEndCell) : e, n));
		},
		splitCell(t) {
			return e.exec((e, n) => Se(t ? this.setCellSelection(e, t) : e, n));
		},
		getCellSelection() {
			return e.transact((e) => {
				let t = e.selection, n = t.$from, r = t.$to;
				if (m(t)) {
					let { ranges: e } = t;
					e.forEach((e) => {
						n = e.$from.min(n ?? e.$from), r = e.$to.max(r ?? e.$to);
					});
				} else if (n = e.doc.resolve(t.$from.pos - t.$from.parentOffset - 1), r = e.doc.resolve(t.$to.pos - t.$to.parentOffset - 1), n.pos === 0 || r.pos === 0) return;
				let i = e.doc.resolve(n.pos - n.parentOffset - 1), a = e.doc.resolve(r.pos - r.parentOffset - 1), o = e.doc.resolve(i.pos - i.parentOffset - 1), s = n.index(i.depth), c = i.index(o.depth), l = r.index(a.depth), u = a.index(o.depth), d = [];
				for (let e = c; e <= u; e++) for (let t = s; t <= l; t++) d.push({
					row: e,
					col: t
				});
				return {
					from: {
						row: c,
						col: s
					},
					to: {
						row: u,
						col: l
					},
					cells: d
				};
			});
		},
		getMergeDirection(t) {
			return e.transact((e) => {
				let n = m(e.selection) ? e.selection : void 0;
				if (!n || !t || n.ranges.length <= 1) return;
				let i = this.getCellSelection();
				if (i) return r(i.from, i.to, t) ? "vertical" : "horizontal";
			});
		},
		cropEmptyRowsOrColumns(e, t) {
			return d(e, t);
		},
		addRowsOrColumns(e, t, n) {
			return u(e, t, n);
		}
	};
}), Y = new w("trailingNode");
function Kt(e, t) {
	if (!t) return !1;
	let n = e.lastChild?.lastChild, r = n?.firstChild;
	return !(n?.type.name === "blockContainer" && r?.type.name === "paragraph" && r.content.size === 0);
}
var qt = b(({ editor: e }) => {
	function t(t) {
		return E.widget(t, () => {
			let t = document.createElement("div");
			return t.className = "bn-trailing-block", t.contentEditable = "false", t.addEventListener("mousedown", (t) => {
				t.preventDefault(), e.transact((t) => {
					let [n] = e.insertBlocks([{ type: "paragraph" }], e.document[e.document.length - 1], "after");
					e.setTextCursorPosition(n, "start"), t.scrollIntoView();
				}), e.prosemirrorView?.focus();
			}), t;
		}, { side: 1 });
	}
	function n(e, n, r) {
		let i = n.map(e.mapping, e.doc), a = i.find(), o = a.length > 0;
		return o === Kt(e.doc, r) ? i : o ? i.remove(a) : i.add(e.doc, [t(e.doc.content.size - 1)]);
	}
	return {
		key: "trailingNode",
		prosemirrorPlugins: [new C({
			key: Y,
			state: {
				init: (t, r) => n(r.tr, D.empty, e.isEditable),
				apply: (t, r) => !t.docChanged && !t.getMeta(Y) ? r : n(t, r, e.isEditable)
			},
			view(e) {
				let t = e.editable;
				return { update(e) {
					e.editable !== t && (t = e.editable, e.dispatch(e.state.tr.setMeta(Y, !0)));
				} };
			},
			props: {
				decorations: (e) => Y.getState(e),
				handleKeyDown: (t, n) => {
					if (n.key !== "ArrowRight" && n.key !== "ArrowDown") return !1;
					let { selection: r } = t.state;
					if (!r.empty) return !1;
					let i = T.atEnd(t.state.doc);
					return r.$head.pos !== i.$head.pos || !Kt(t.state.doc, e.isEditable) ? !1 : (n.preventDefault(), !0);
				}
			}
		})]
	};
}), X = Symbol("bn-current-version");
function Z(e) {
	return [...e].sort((e, t) => t.createdAt - e.createdAt);
}
function Q(e) {
	let t = typeof e == "object" ? e.id : e;
	throw Error(`Snapshot not found: ${String(t)}`);
}
var Jt = b(({ options: e, editor: t }) => {
	let { endpoints: n, preview: r, getCurrentDocument: i, serializeCurrentContent: a, resolveUsers: o } = typeof e == "function" ? e(t) : e, s = typeof n == "function" ? n(t) : n, c = ne(o), l = y({
		snapshots: [],
		previewedSnapshotId: void 0,
		compareToSnapshotId: void 0
	}), u = (e) => {
		let t = typeof e == "object" ? e.id : e;
		return l.state.snapshots.find((e) => e.id === t);
	}, d = async () => {
		let e = Z(await s.list());
		return l.setState((t) => ({
			...t,
			snapshots: e
		})), e;
	}, f = async (e, t) => {
		let n = u(e);
		n || Q(e);
		let i = t?.compareTo ? u(t.compareTo) : void 0;
		l.setState((e) => ({
			...e,
			previewedSnapshotId: n.id,
			compareToSnapshotId: i?.id
		}));
		let a, o;
		i && (a = await s.getContent(i), s.getAttributions && (o = await s.getAttributions(n, i)));
		let c = await s.getContent(n);
		r.enterPreview(c, a, o, {
			snapshot: n,
			compareTo: i
		});
	}, p = async (e) => {
		if (!a) throw Error("previewCurrentVersion requires `serializeCurrentContent` to be provided to the VersioningExtension options.");
		let t = e?.compareTo ? u(e.compareTo) : void 0;
		l.setState((e) => ({
			...e,
			previewedSnapshotId: X,
			compareToSnapshotId: t?.id
		}));
		let n = {
			id: X,
			createdAt: Date.now(),
			updatedAt: Date.now()
		}, i, o;
		t && (i = await s.getContent(t), s.getAttributions && (o = await s.getAttributions(n, t)));
		let c = await a();
		r.enterPreview(c, i, o, {
			snapshot: n,
			compareTo: t
		});
	}, m = () => {
		l.setState((e) => ({
			...e,
			previewedSnapshotId: void 0,
			compareToSnapshotId: void 0
		})), r.exitPreview();
	};
	return {
		key: "versioning",
		store: l,
		userStore: c,
		list: async () => await d(),
		get canCompare() {
			return r.supportsComparison !== !1;
		},
		canCreate: s.create !== void 0,
		create: s.create ? async (e) => {
			let t = await s.create(i(), {
				name: e?.name,
				restoredFromSnapshot: u(e?.restoredFromSnapshot)
			});
			l.setState((e) => ({
				...e,
				snapshots: Z([...e.snapshots, t])
			}));
			let n = await s.list();
			return l.setState((e) => ({
				...e,
				snapshots: Z(n.some((e) => e.id === t.id) ? n : [...n, t])
			})), t;
		} : void 0,
		canRestore: s.restore !== void 0,
		restore: s.restore ? async (e) => {
			m();
			let t = u(e);
			t || Q(e);
			let n = await s.restore(i(), t);
			return r.applyRestore(n), await d(), n;
		} : void 0,
		canRename: s.rename !== void 0,
		rename: s.rename ? async (e, t) => {
			let n = u(e);
			n || Q(e), await s.rename(n, t), l.setState((n) => ({
				...n,
				snapshots: n.snapshots.map((n) => n.id === e ? {
					...n,
					name: t,
					updatedAt: Date.now()
				} : n)
			}));
		} : void 0,
		canRemove: s.remove !== void 0,
		remove: s.remove ? async (e) => {
			let t = u(e);
			t || Q(e), (l.state.previewedSnapshotId === t.id || l.state.compareToSnapshotId === t.id) && m(), await s.remove(t), l.setState((e) => ({
				...e,
				snapshots: e.snapshots.filter((e) => e.id !== t.id)
			})), await d();
		} : void 0,
		previewSnapshot: f,
		canPreviewCurrent: a !== void 0,
		previewCurrentVersion: a ? p : void 0,
		exitPreview: m
	};
});
//#endregion
//#region src/extensions/Versioning/inMemoryVersioning.ts
function Yt(e) {
	return e.id === X ? "Current version" : e.name ?? "Unnamed version";
}
function Xt(e) {
	let t, n = !1, r = (t) => {
		e.replaceBlocks(e.document, t);
	}, i = () => e.getExtension("diffVersioning");
	return {
		get supportsComparison() {
			return i() !== void 0;
		},
		enterPreview(a, o, s, c) {
			t === void 0 && (t = e.document);
			let l = i();
			if (o && l) {
				l.renderDiff(a, o, c && Yt(c.snapshot)), n = !0;
				return;
			}
			n = !1, r(a);
		},
		exitPreview() {
			if (t !== void 0) {
				let e = i();
				n && e ? e.clearDiff(t) : r(t), t = void 0, n = !1;
			}
		},
		applyRestore(e) {
			let a = i();
			n && a ? a.clearDiff(e) : r(e), t = void 0, n = !1;
		}
	};
}
function $() {
	let e = [], t = /* @__PURE__ */ new Map(), n = 1;
	return {
		async list() {
			return Z([...e]);
		},
		async create(r, i) {
			let a = Date.now(), o = String(n++), s = {
				id: o,
				name: i?.name,
				createdAt: a,
				updatedAt: a
			};
			return e.push(s), t.set(o, structuredClone(r)), s;
		},
		async restore(r, i) {
			let a = String(i.id), o = t.get(a);
			if (!o) throw Error(`Snapshot ${a} not found`);
			let s = Date.now(), c = String(n++), l = {
				id: c,
				name: "Before restore",
				createdAt: s,
				updatedAt: s,
				restoredFromSnapshotId: a
			};
			return e.push(l), t.set(c, structuredClone(r)), structuredClone(o);
		},
		async getContent(e) {
			let n = String(e.id), r = t.get(n);
			if (!r) throw Error(`Snapshot ${n} not found`);
			return structuredClone(r);
		},
		async rename(t, n) {
			let r = e.find((e) => e.id === t.id);
			if (!r) throw Error(`Snapshot ${String(t.id)} not found`);
			r.name = n, r.updatedAt = Date.now();
		},
		async remove(n) {
			let r = e.findIndex((e) => e.id === n.id);
			if (r === -1) throw Error(`Snapshot ${String(n.id)} not found`);
			e.splice(r, 1), t.delete(String(n.id));
		}
	};
}
function Zt(e) {
	let t = $();
	return {
		endpoints: {
			...t,
			list: async () => [{
				id: X,
				createdAt: Date.now(),
				updatedAt: Date.now()
			}, ...await t.list()]
		},
		preview: Xt(e),
		getCurrentDocument: () => e.document,
		serializeCurrentContent: () => e.document
	};
}
//#endregion
export { k as A, Ye as C, Ke as D, Ge as E, ze as O, Xe as S, qe as T, V as _, Jt as a, et as b, Gt as c, zt as d, Lt as f, Dt as g, Ot as h, X as i, Re as k, Wt as l, It as m, Zt as n, Z as o, Ft as p, $ as r, qt as s, Xt as t, J as u, it as v, Je as w, Qe as x, tt as y };

//# sourceMappingURL=extensions-CrUGDOks.js.map