@blocknote/core
Version:
A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.
3,312 lines • 116 kB
JavaScript
import { $n as e, Cn as t, Dn as n, En as r, Et as i, Fn as a, G as o, Hn as s, It as c, Lt as l, Mn as u, Mt as d, Nt as f, Pt as p, Rt as m, Sn as h, Tn as g, Un as _, Xt as ee, _n as te, an as ne, ar as re, er as v, f as ie, in as y, jt as ae, k as b, kn as oe, m as x, nr as S, on as se, or as C, rr as w, t as ce, tr as T, wn as le, wt as ue, xn as de, xt as fe } from "./blocks-CzQLehlc.js";
import { o as pe, r as me, t as he } from "./BlockNoteExtension-CbvDA0F7.js";
import { A as ge, C as _e, F as ve, M as ye, N as be, O as xe, P as Se, S as Ce, T as we, b as Te, c as Ee, g as De, h as Oe, k as ke, m as Ae, s as je, w as Me, x as Ne, y as Pe } from "./extensions-DGuhtOgB.js";
import { r as Fe } from "./UserStore-C4TzkGEn.js";
import { t as Ie } from "./en-uzHzj6eH.js";
import { DOMParser as Le, DOMSerializer as Re, Fragment as E, NodeRange as ze, Slice as D } from "prosemirror-model";
import { ReplaceAroundStep as O, ReplaceStep as Be, canJoin as Ve, liftTarget as He } from "prosemirror-transform";
import { Editor as Ue, Extension as k, Mark as We, Node as A, combineTransactionSteps as Ge, createDocument as Ke, extensions as j, findChildrenInRange as qe, findParentNodeClosestToPos as Je, getAttributes as Ye, getChangedRanges as Xe, getMarkRange as Ze, getMarksBetween as Qe, getSchema as $e, isNodeSelection as et, markPasteRule as tt, mergeAttributes as M, posToDOMRect as nt, selectionToInsertionEnd as rt } from "@tiptap/core";
import { NodeSelection as N, Plugin as P, TextSelection as F } from "prosemirror-state";
import { DOMParser as it, Fragment as I, Slice as L } from "@tiptap/pm/model";
import { CellSelection as at, TableMap as ot } from "prosemirror-tables";
import { Plugin as st, PluginKey as ct } from "@tiptap/pm/state";
import { digestString as lt } from "lib0/hash/fnv1a";
import { InputRule as ut, inputRules as dt } from "@handlewithcare/prosemirror-inputrules";
import { keymap as ft } from "@tiptap/pm/keymap";
import { Text as pt } from "@tiptap/extension-text";
import { Gapcursor as mt } from "@tiptap/extensions/gap-cursor";
//#region src/schema/blocks/types.ts
function ht(e) {
return typeof e == "string" ? e : e.map((e) => typeof e == "string" ? e : e.text).join("");
}
//#endregion
//#region src/schema/inlineContent/createSpec.ts
function gt(e) {
return e.matches("[data-editable]") ? e : e.querySelector("[data-editable]") || e;
}
function _t(e, t) {
return it.fromSchema(t).parse(e, {
topNode: t.nodes.paragraph.create(),
preserveWhitespace: !0
}).content;
}
function vt(e, t) {
let n = [];
return e.forEach((e) => {
if (e.isText) n.push(e);
else {
let r = e.type === t.linebreakReplacement ? "\n" : e.textContent;
r && n.push(t.text(r, e.marks));
}
}), I.fromArray(n);
}
function yt(e, t, n) {
let r = e.content === "plain" || n && e.content === "styled" ? (t) => (r, i) => {
let a = n?.({
el: r,
schema: i
});
if (a !== void 0) return e.content === "plain" ? vt(a, i) : a;
let o = _t(t(r), i);
return e.content === "plain" ? vt(o, i) : o;
} : void 0, i = [{
tag: `[data-inline-content-type="${e.type}"]`,
contentElement: (e) => gt(e),
getContent: r ? (e, t) => r(gt)(e, t) : void 0
}];
return t && i.push({
tag: "*",
getAttrs(e) {
if (typeof e == "string") return !1;
let n = t?.(e);
return n !== void 0 && n;
},
preserveWhitespace: r ? !0 : void 0,
getContent: r ? (e, t) => r((e) => e)(e, t) : void 0
}), i;
}
function bt(e, t) {
let n = A.create({
name: e.type,
inline: !0,
group: "inline",
draggable: t.meta?.draggable,
selectable: e.content !== "none",
atom: e.content === "none",
code: t.meta?.code,
content: e.content === "styled" ? "inline*" : e.content === "plain" ? "text*" : "",
marks() {
return e.content === "plain" ? pe(this.editor) : void 0;
},
addAttributes() {
return te(e.propSchema);
},
addKeyboardShortcuts() {
return ne(e);
},
parseHTML() {
return yt(e, t.parse, t.parseContent);
},
renderHTML({ node: n }) {
let i = this.options.editor, a = t.render.call({
renderType: "dom",
props: void 0
}, r(n, i.schema.inlineContentSchema, i.schema.styleSchema), () => {}, i, n, () => void 0);
return y(a, e.type, n.attrs, e.propSchema);
},
addNodeView() {
return (n) => {
let { node: i, getPos: o } = n, s = this.options.editor, c = t.render.call({
renderType: "nodeView",
props: n
}, r(i, s.schema.inlineContentSchema, s.schema.styleSchema), (e) => {
let t = l([e], s.pmSchema), n = o();
n && s.transact((e) => e.replaceWith(n, n + i.nodeSize, t));
}, s, i, o), u = y(c, e.type, i.attrs, e.propSchema);
return a(u), u;
};
}
});
return se(n, e.propSchema, {
...t,
toExternalHTML: t.toExternalHTML,
render(n, r, i) {
let a = l([n], i.pmSchema)[0], o = t.render(n, r, i, a, () => void 0);
return y(o, e.type, n.props, e.propSchema);
}
});
}
//#endregion
//#region src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts
function xt(e, t, n, r = "before") {
let i = typeof n == "string" ? n : n.id, a = u(e), o = t.map((e) => {
let t = c(e, a);
return t.check(), t;
}), s = p(i, e.doc);
if (!s) throw Error(`Block with ID ${i} not found`);
let l = s.posBeforeNode;
return r === "after" && (l += s.node.nodeSize), e.step(new Be(l, l, new D(E.from(o), 0, 0))), o.map((t) => g(t, e.doc));
}
//#endregion
//#region src/api/blockManipulation/commands/replaceBlocks/util/fixColumnList.ts
function R(e) {
if (!e || e.type.name !== "column") throw Error("Invalid columnPos: does not point to column node.");
let t = e.firstChild;
if (!t) throw Error("Invalid column: does not have child node.");
let n = t.firstChild;
if (!n) throw Error("Invalid blockContainer: does not have child node.");
return e.childCount === 1 && t.childCount === 1 && n.type.name === "paragraph" && n.content.content.length === 0;
}
function St(e, t) {
let n = e.doc.resolve(t), r = n.nodeAfter;
if (!r || r.type.name !== "columnList") throw Error("Invalid columnListPos: does not point to columnList node.");
for (let t = r.childCount - 1; t >= 0; t--) {
let r = e.doc.resolve(n.pos + 1).posAtIndex(t), i = e.doc.resolve(r).nodeAfter;
if (!i || i.type.name !== "column") throw Error("Invalid columnPos: does not point to column node.");
R(i) && e.delete(r, r + i.nodeSize);
}
}
function z(e, t) {
St(e, t);
let n = e.doc.resolve(t).nodeAfter;
if (!n || n.type.name !== "columnList") throw Error("Invalid columnListPos: does not point to columnList node.");
if (n.childCount > 2) return;
if (n.childCount < 2) throw Error("Invalid columnList: contains fewer than two children.");
let r = t + 1, i = e.doc.resolve(r).nodeAfter, a = t + n.nodeSize - 1, o = e.doc.resolve(a).nodeBefore;
if (!i || !o) throw Error("Invalid columnList: does not contain children.");
let s = R(i), c = R(o);
if (s && c) {
e.delete(t, t + n.nodeSize);
return;
}
if (s) {
e.step(new O(t, t + n.nodeSize, a - o.nodeSize + 1, a - 1, D.empty, 0, !1));
return;
}
if (c) {
e.step(new O(t, t + n.nodeSize, r + 1, r + i.nodeSize - 1, D.empty, 0, !1));
return;
}
}
//#endregion
//#region src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts
function B(e, t, n, r = {}) {
let i = u(e), a = n.map((e) => {
let t = c(e, i);
return t.check(), t;
}), o = new Set(t.map((e) => typeof e == "string" ? e : e.id)), s = [], l = /* @__PURE__ */ new Set(), d = typeof t[0] == "string" ? t[0] : t[0].id, f = 0;
if (e.doc.descendants((t, r) => {
if (o.size === 0) return !1;
if (!t.type.isInGroup("bnBlock")) return !0;
let i = C(t, e.doc);
if (!o.has(i)) return !0;
if (s.push(g(t, e.doc)), o.delete(i), n.length > 0 && i === d) {
let t = e.doc.nodeSize;
e.insert(r, a);
let n = e.doc.nodeSize;
f += t - n;
}
let c = e.doc.nodeSize, u = e.doc.resolve(r - f);
u.node().type.name === "column" ? l.add(u.before(-1)) : u.node().type.name === "columnList" && l.add(u.before()), u.node().type.name === "blockGroup" && u.node(u.depth - 1).type.name !== "doc" && u.node().childCount === 1 ? e.delete(u.before(), u.after()) : e.delete(r - f, r - f + t.nodeSize);
let p = e.doc.nodeSize;
return f += c - p, !1;
}), o.size > 0) {
let e = [...o].join("\n");
throw Error("Blocks with the following IDs could not be found in the editor: " + e);
}
return r.fixColumns !== !1 && l.forEach((t) => z(e, t)), {
insertedBlocks: a.map((t) => g(t, e.doc)),
removedBlocks: s
};
}
//#endregion
//#region src/api/exporters/html/util/serializeBlocksInternalHTML.ts
function Ct(e, t, n, i, a) {
let o;
if (!t) throw Error("blockContent is required");
if (typeof t == "string") o = l([t], e.pmSchema, i);
else if (Array.isArray(t)) o = l(t, e.pmSchema, i);
else if (t.type === "tableContent") o = m(t, e.pmSchema);
else throw new _(t.type);
let s = (a?.document ?? document).createDocumentFragment();
for (let t of o) if (t.type.name !== "text" && e.schema.inlineContentSchema[t.type.name]) {
let i = e.schema.inlineContentSpecs[t.type.name].implementation;
if (i) {
let o = r(t, e.schema.inlineContentSchema, e.schema.styleSchema), c = i.render.call({
renderType: "dom",
props: void 0
}, o, () => {}, e);
if (c) {
if (s.appendChild(c.dom), c.contentDOM) {
let e = n.serializeFragment(t.content, a);
c.contentDOM.dataset.editable = "", c.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.render(r.attrs.stringValue, e);
t.contentDOM.appendChild(n), n = t.dom;
} else {
let e = r.type.spec.toDOM(r, !0), t = Re.renderSpec(document, e);
t.contentDOM.appendChild(n), n = t.dom;
}
s.appendChild(n);
} else {
let e = n.serializeFragment(E.from([t]), a);
s.appendChild(e);
}
return s;
}
function wt(e, t, n, r) {
let i = e.pmSchema.nodes.blockContainer, a = t.props || {};
for (let [n, r] of Object.entries(e.schema.blockSchema[t.type].propSchema)) !(n in a) && r.default !== void 0 && (a[n] = r.default);
let o = t.children || [], s = e.blockImplementations[t.type].implementation.render.call({
renderType: "dom",
props: void 0
}, {
...t,
props: a,
children: o
}, e);
if (s.contentDOM && t.content) {
let i = Ct(e, t.content, n, t.type, r);
s.contentDOM.appendChild(i);
}
if (e.pmSchema.nodes[t.type].isInGroup("bnBlock")) {
if (t.children && t.children.length > 0) {
let i = Tt(e, t.children, n, r);
s.contentDOM?.append(i);
}
return s.dom;
}
let c = i.spec?.toDOM?.(i.create({
id: t.id,
...a
}));
return c.contentDOM?.appendChild(s.dom), t.children && t.children.length > 0 && c.contentDOM?.appendChild(Et(e, t.children, n, r)), c.dom;
}
function Tt(e, t, n, r) {
let i = (r?.document ?? document).createDocumentFragment();
for (let a of t) {
let t = wt(e, a, n, r);
i.appendChild(t);
}
return i;
}
var Et = (e, t, n, r) => {
let i = e.pmSchema.nodes.blockGroup, a = i.spec.toDOM(i.create({})), o = Tt(e, t, n, r);
return a.contentDOM?.appendChild(o), a.dom;
}, Dt = (e) => (e.querySelectorAll("[data-content-type=\"numberedListItem\"]").forEach((e) => {
let t = e.closest(".bn-block-outer")?.previousElementSibling?.querySelector("[data-content-type=\"numberedListItem\"]");
if (!t) e.setAttribute("data-index", e.getAttribute("data-start") || "1");
else {
let n = t.getAttribute("data-index");
e.setAttribute("data-index", (parseInt(n || "0") + 1).toString());
}
}), e), Ot = (e) => (e.querySelectorAll("[data-content-type=\"checkListItem\"] input").forEach((e) => {
e.disabled = !0;
}), e), kt = (e) => (e.querySelectorAll(".bn-toggle-wrapper[data-show-children=\"false\"]").forEach((e) => {
e.setAttribute("data-show-children", "true");
}), e), At = (e) => (e.querySelectorAll("[data-content-type=\"table\"] table").forEach((e) => {
e.setAttribute("style", "--default-cell-min-width: 120px;"), e.setAttribute("data-show-children", "true");
}), e), jt = (e) => (e.querySelectorAll("[data-content-type=\"table\"] table").forEach((e) => {
let t = document.createElement("div");
t.className = "tableWrapper";
let n = document.createElement("div");
n.className = "tableWrapper-inner", t.appendChild(n), e.parentElement?.appendChild(t), t.appendChild(e);
}), e), Mt = (e) => (e.querySelectorAll(".bn-inline-content:empty").forEach((e) => {
let t = document.createElement("span");
t.className = "ProseMirror-trailingBreak", t.setAttribute("style", "display: inline-block;"), e.appendChild(t);
}), e), Nt = (e, t) => {
let n = Re.fromSchema(e), r = [
Dt,
Ot,
kt,
At,
jt,
Mt
];
return { serializeBlocks: (e, i) => {
let a = Et(t, e, n, i);
for (let e of r) a = e(a);
return a.outerHTML;
} };
}, Pt = (e) => {
let t = 0;
for (let n = 0; n < e.length; n++) t = Math.imul(31, t) + e.charCodeAt(n);
return Math.abs(t);
}, V = [
{
light: "#fff0c2",
dark: "#8a6d1a"
},
{
light: "#fcc9c3",
dark: "#8a2e24"
},
{
light: "#d4e8eb",
dark: "#4a7178"
},
{
light: "#c2eeff",
dark: "#1a6e8a"
},
{
light: "#bef3ff",
dark: "#0a7a8a"
}
], Ft = (e) => V[Pt(e) % V.length], It = (e, t) => {
if (!t || t.length === 0) return V[0];
let n = t[0], r = e.getUser(n);
return r?.color && r.colorLight ? {
light: r.colorLight,
dark: r.color
} : Ft(n);
}, Lt = (e) => lt(e).toString(16).padStart(8, "0"), Rt = (e) => {
let t = Lt(e);
return {
light: `--user-color-${t}-light`,
dark: `--user-color-${t}-dark`
};
}, H = class {
callbacks = {};
on(e, t) {
return this.callbacks[e] || (this.callbacks[e] = []), this.callbacks[e].push(t), () => this.off(e, t);
}
emit(e, ...t) {
let n = this.callbacks[e];
n && n.forEach((e) => e.apply(this, t));
}
off(e, t) {
let n = this.callbacks[e];
n && (t ? this.callbacks[e] = n.filter((e) => e !== t) : delete this.callbacks[e]);
}
removeAllListeners() {
this.callbacks = {};
}
};
//#endregion
//#region src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts
function zt(e) {
return e.transact((e) => {
let t = T(e, e.selection.anchor), n = C(t.bnBlock.node, e.doc);
if (e.selection instanceof at) return {
type: "cell",
anchorBlockId: n,
anchorCellOffset: e.selection.$anchorCell.pos - t.bnBlock.beforePos,
headCellOffset: e.selection.$headCell.pos - t.bnBlock.beforePos
};
if (e.selection instanceof N) return {
type: "node",
anchorBlockId: n
};
{
let r = T(e, e.selection.head);
return {
type: "text",
anchorBlockId: n,
headBlockId: C(r.bnBlock.node, e.doc),
anchorOffset: e.selection.anchor - t.bnBlock.beforePos,
headOffset: e.selection.head - r.bnBlock.beforePos
};
}
});
}
function Bt(e, t) {
let n = p(t.anchorBlockId, e.doc)?.posBeforeNode;
if (n === void 0) throw Error(`Could not find block with ID ${t.anchorBlockId} to update selection`);
let r;
if (t.type === "cell") r = at.create(e.doc, n + t.anchorCellOffset, n + t.headCellOffset);
else if (t.type === "node") r = N.create(e.doc, n + 1);
else {
let i = p(t.headBlockId, e.doc)?.posBeforeNode;
if (i === void 0) throw Error(`Could not find block with ID ${t.headBlockId} to update selection`);
r = F.create(e.doc, n + t.anchorOffset, i + t.headOffset);
}
e.setSelection(r);
}
function Vt(e) {
return e.flatMap((e) => e.type === "column" ? e.children : [e]);
}
function U(e, t, n, r) {
e.transact((e) => {
B(e, t, [], { fixColumns: !1 }), xt(e, Vt(t), n, r);
});
}
function Ht(e, t, n) {
e.transact((r) => {
let i = e.getSelection()?.blocks || [e.getTextCursorPosition().block], a = zt(e);
U(e, i, t, n), Bt(r, a);
});
}
function Ut(e) {
return !e || e.type !== "columnList";
}
function Wt(e, t, n) {
let r, i;
if (t ? t.children.length > 0 ? (r = t.children[t.children.length - 1], i = "after") : (r = t, i = "before") : n && (r = n, i = "before"), !r || !i) return;
let a = e.getParentBlock(r);
return Ut(a) ? {
referenceBlock: r,
placement: i
} : Wt(e, i === "after" ? r : e.getPrevBlock(r), a);
}
function Gt(e, t, n) {
let r, i;
if (t ? t.children.length > 0 ? (r = t.children[0], i = "before") : (r = t, i = "after") : n && (r = n, i = "after"), !r || !i) return;
let a = e.getParentBlock(r);
return Ut(a) ? {
referenceBlock: r,
placement: i
} : Gt(e, i === "before" ? r : e.getNextBlock(r), a);
}
function Kt(e, t) {
e.transact(() => {
let n;
if (t) {
if (n = e.getBlock(t), !n) return;
} else n = e.getSelection()?.blocks[0] || e.getTextCursorPosition().block;
let r = Wt(e, e.getPrevBlock(n), e.getParentBlock(n));
r && (t ? U(e, [n], r.referenceBlock, r.placement) : Ht(e, r.referenceBlock, r.placement));
});
}
function qt(e, t) {
e.transact(() => {
let n;
if (t) {
if (n = e.getBlock(t), !n) return;
} else {
let t = e.getSelection();
n = t?.blocks[t?.blocks.length - 1] || e.getTextCursorPosition().block;
}
let r = Gt(e, e.getNextBlock(n), e.getParentBlock(n));
r && (t ? U(e, [n], r.referenceBlock, r.placement) : Ht(e, r.referenceBlock, r.placement));
});
}
//#endregion
//#region src/api/blockManipulation/commands/nestBlock/nestBlock.ts
function Jt(e, t, n) {
let { $from: r, $to: i } = e.selection, a = r.blockRange(i, (e) => e.childCount > 0 && (e.type.name === "blockGroup" || e.type.name === "column"));
if (!a) return !1;
let o = a.startIndex;
if (o === 0) return !1;
let s = a.parent.child(o - 1);
if (s.type !== t) return !1;
let c = s.lastChild && s.lastChild.type === n, l = E.from(c ? t.create() : null), u = new D(E.from(t.create(null, E.from(n.create(null, l)))), c ? 3 : 1, 0), d = a.start, f = a.end;
return e.step(new O(d - (c ? 3 : 1), f, d, f, u, 1, !0)).scrollIntoView(), !0;
}
function Yt(e) {
return e.transact((t) => Jt(t, e.pmSchema.nodes.blockContainer, e.pmSchema.nodes.blockGroup));
}
function Xt(e, t, n, r) {
let i = r.end, a = r.$to.end(r.depth);
if (i < a) {
let o = r.parent.child(r.endIndex - 1), s = o.lastChild && o.lastChild.type === n;
e.step(new O(i - (s ? 2 : 1), a, i, a, new D(E.from(t.create(null, n.create())), s ? 2 : 1, 0), +!s, !0)), r = new ze(e.doc.resolve(r.$from.pos), e.doc.resolve(a), r.depth);
}
let o = He(r);
if (o == null) return !1;
e.lift(r, o);
let s = e.doc.resolve(e.mapping.map(i, -1) - 1);
return Ve(e.doc, s.pos) && s.nodeBefore.type === s.nodeAfter.type && e.join(s.pos), e.scrollIntoView(), !0;
}
function W(e, t, n) {
let { $from: r, $to: i } = e.selection, a = r.blockRange(i, (e) => e.childCount > 0 && (e.type.name === "blockGroup" || e.type.name === "column"));
return a ? r.node(a.depth - 1).type === t && Xt(e, t, n, a) : !1;
}
function Zt(e) {
return e.transact((t) => W(t, e.pmSchema.nodes.blockContainer, e.pmSchema.nodes.blockGroup));
}
function Qt(e) {
return e.transact((e) => {
let { bnBlock: t } = w(e);
return e.doc.resolve(t.beforePos).nodeBefore !== null;
});
}
function $t(e) {
return e.transact((e) => {
let { bnBlock: t } = w(e);
return e.doc.resolve(t.beforePos).depth > 1;
});
}
//#endregion
//#region src/api/blockManipulation/getBlock/getBlock.ts
function en(e, t) {
let n = typeof t == "string" ? t : t.id, r = p(n, e);
if (r) return g(r.node, e);
}
function tn(e, t) {
let n = typeof t == "string" ? t : t.id, r = p(n, e);
if (!r) return;
let i = e.resolve(r.posBeforeNode).nodeBefore;
if (i) return g(i, e);
}
function nn(e, t) {
let n = typeof t == "string" ? t : t.id, r = p(n, e);
if (!r) return;
let i = e.resolve(r.posBeforeNode + r.node.nodeSize).nodeAfter;
if (i) return g(i, e);
}
function rn(e, t) {
let n = typeof t == "string" ? t : t.id, r = p(n, e);
if (!r) return;
let i = e.resolve(r.posBeforeNode), a = i.node(), o = i.node(-1), s = o.type.name === "doc" ? void 0 : a.type.name === "blockGroup" ? o : a;
if (s) return g(s, e);
}
//#endregion
//#region src/editor/managers/BlockManager.ts
var an = class {
editor;
constructor(e) {
this.editor = e;
}
get document() {
return this.editor.transact((e) => le(e.doc));
}
getBlock(e) {
return this.editor.transact((t) => en(t.doc, e));
}
getPrevBlock(e) {
return this.editor.transact((t) => tn(t.doc, e));
}
getNextBlock(e) {
return this.editor.transact((t) => nn(t.doc, e));
}
getParentBlock(e) {
return this.editor.transact((t) => rn(t.doc, e));
}
forEachBlock(e, t = !1) {
let n = this.document.slice();
t && n.reverse();
function r(n) {
for (let i of n) if (e(i) === !1 || !r(t ? i.children.slice().reverse() : i.children)) return !1;
return !0;
}
r(n);
}
insertBlocks(e, t, n = "before") {
return this.editor.transact((r) => xt(r, e, t, n));
}
updateBlock(e, t) {
return this.editor.transact((n) => ae(n, e, t));
}
removeBlocks(e) {
return this.editor.transact((t) => B(t, e, []).removedBlocks);
}
replaceBlocks(e, t) {
return this.editor.transact((n) => B(n, e, t));
}
canNestBlock() {
return Qt(this.editor);
}
nestBlock() {
Yt(this.editor);
}
canUnnestBlock() {
return $t(this.editor);
}
unnestBlock() {
Zt(this.editor);
}
moveBlocksUp(e) {
return Kt(this.editor, e);
}
moveBlocksDown(e) {
return qt(this.editor, e);
}
}, on = class extends H {
editor;
constructor(e) {
super(), this.editor = e, e.on("create", () => {
e._tiptapEditor.on("update", ({ transaction: t, appendedTransactions: n }) => {
this.emit("onChange", {
editor: e,
transaction: t,
appendedTransactions: n
});
}), e._tiptapEditor.on("selectionUpdate", ({ transaction: t }) => {
this.emit("onSelectionChange", {
editor: e,
transaction: t
});
}), e._tiptapEditor.on("mount", () => {
this.emit("onMount", { editor: e });
}), e._tiptapEditor.on("unmount", () => {
this.emit("onUnmount", { editor: e });
});
});
}
onChange(e, t = !0) {
let n = ({ transaction: n, appendedTransactions: r }) => {
!t && sn(n) || e(this.editor, { getChanges() {
return Se(n, r);
} });
};
return this.on("onChange", n), () => {
this.off("onChange", n);
};
}
onSelectionChange(e, t = !1) {
let n = (n) => {
!t && sn(n.transaction) || e(this.editor);
};
return this.on("onSelectionChange", n), () => {
this.off("onSelectionChange", n);
};
}
onMount(e) {
return this.on("onMount", e), () => {
this.off("onMount", e);
};
}
onUnmount(e) {
return this.on("onUnmount", e), () => {
this.off("onUnmount", e);
};
}
};
function sn(e) {
return !!e.getMeta("y-sync$");
}
//#endregion
//#region src/api/parsers/html/util/nestedLists.ts
function cn(e) {
return Array.prototype.indexOf.call(e.parentElement.childNodes, e);
}
function ln(e) {
return e.nodeType === 3 && !/\S/.test(e.nodeValue || "");
}
function un(e) {
e.querySelectorAll("li > ul, li > ol").forEach((e) => {
let t = cn(e), n = e.parentElement, r = Array.from(n.childNodes).slice(t + 1);
e.remove(), r.forEach((e) => {
e.remove();
}), n.insertAdjacentElement("afterend", e), r.reverse().forEach((t) => {
if (ln(t)) return;
let n = document.createElement("li");
n.append(t), e.insertAdjacentElement("afterend", n);
}), n.childNodes.length === 0 && n.remove();
});
}
function dn(e) {
e.querySelectorAll("li + ul, li + ol").forEach((e) => {
let t = e.previousElementSibling, n = document.createElement("div");
t.insertAdjacentElement("afterend", n), n.append(t);
let r = document.createElement("div");
for (r.setAttribute("data-node-type", "blockGroup"), n.append(r); n.nextElementSibling?.nodeName === "UL" || n.nextElementSibling?.nodeName === "OL";) r.append(n.nextElementSibling);
});
}
var fn = null;
function pn() {
return fn ||= document.implementation.createHTMLDocument("title");
}
function mn(e) {
if (typeof e == "string") {
let t = pn().createElement("div");
t.innerHTML = e, e = t;
}
return un(e), dn(e), e;
}
//#endregion
//#region src/api/parsers/html/util/normalizeWhitespace.ts
function hn(e) {
let t = e.ownerDocument.createTreeWalker(e, 128), n;
for (; n = t.nextNode();) if (/^\s*notionvc:/.test(n.nodeValue || "")) return !0;
return !1;
}
function gn(e) {
let t = /* @__PURE__ */ new Set(["PRE", "CODE"]), n = e.ownerDocument.createTreeWalker(e, 4, { acceptNode(n) {
let r = n.parentElement;
for (; r && r !== e;) {
if (t.has(r.tagName)) return 2;
r = r.parentElement;
}
return 1;
} }), r = [], i;
for (; i = n.nextNode();) r.push(i);
for (let e of r) e.nodeValue && /[\r\n]/.test(e.nodeValue) && (e.nodeValue = e.nodeValue.replace(/[ \t\r\n\f]+/g, " "));
}
function _n(e) {
hn(e) || gn(e);
}
//#endregion
//#region src/api/parsers/html/parseHTML.ts
function vn(e) {
let t = [];
for (let n of e) if (n.type === "text") {
let e = n.text.split("").join("");
e.length > 0 && t.push({
...n,
text: e
});
} else Array.isArray(n.content) ? t.push({
...n,
content: vn(n.content)
}) : t.push(n);
return t;
}
function yn(e) {
for (let t of e) Array.isArray(t.content) && (t.content = vn(t.content)), t.children.length > 0 && yn(t.children);
}
function G(e, t) {
let n = mn(e);
_n(n);
let r = Le.fromSchema(t).parse(n, { topNode: t.nodes.blockGroup.create() }), i = [];
for (let e = 0; e < r.childCount; e++) i.push(g(r.child(e), r));
return yn(i), i;
}
//#endregion
//#region src/api/parsers/markdown/markdownToHtml.ts
function K(e) {
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
}
function bn(e) {
return e ? /\w/.test(e) : !1;
}
function q(e, t, n) {
let r = t > 0 ? e[t - 1] : void 0, i = t + n < e.length ? e[t + n] : void 0;
return bn(r) && bn(i);
}
function xn(e, t) {
if (e[t] !== "\\" || t + 1 >= e.length) return null;
let n = e[t + 1];
return n === "\n" ? {
html: "<br>\n",
end: t + 2
} : "\\`*_{}[]()#+-.!~|>".includes(n) ? {
html: K(n),
end: t + 2
} : null;
}
function Sn(e, t) {
return e[t] === "`" ? Rn(e, t) : null;
}
function Cn(e, t) {
return e[t] !== "!" || e[t + 1] !== "[" ? null : zn(e, t);
}
function wn(e, t) {
return e[t] === "[" ? Bn(e, t) : null;
}
function Tn(e, t) {
return e[t] !== "~" || e[t + 1] !== "~" ? null : Y(e, t, "~~", "<del>", "</del>");
}
function En(e, t) {
return e[t] === "*" && e[t + 1] === "*" && e[t + 2] === "*" || e[t] === "_" && e[t + 1] === "_" && e[t + 2] === "_" && !q(e, t, 3) ? Y(e, t, e.substring(t, t + 3), "<strong><em>", "</em></strong>") : null;
}
function Dn(e, t) {
return e[t] === "*" && e[t + 1] === "*" || e[t] === "_" && e[t + 1] === "_" && !q(e, t, 2) ? Y(e, t, e.substring(t, t + 2), "<strong>", "</strong>") : null;
}
function On(e, t) {
return e[t] === "*" || e[t] === "_" && !q(e, t, 1) ? Y(e, t, e[t], "<em>", "</em>") : null;
}
function kn(e, t) {
return e[t] === "\n" ? {
html: "<br>\n",
end: t + 1
} : null;
}
var An = /^<\/?[a-zA-Z][a-zA-Z0-9-]*(?:\s+[a-zA-Z_:][a-zA-Z0-9_.:-]*(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)*\s*\/?>/, jn = /^<!--[\s\S]*?-->/, Mn = /^<!\[CDATA\[[\s\S]*?\]\]>/, Nn = /^<\?[\s\S]*?\?>/, Pn = /^<![A-Za-z][\s\S]*?>/;
function Fn(e, t) {
if (e[t] !== "<") return null;
let n = e.substring(t);
for (let e of [
jn,
Mn,
Nn,
Pn,
An
]) {
let r = n.match(e);
if (r) return {
html: r[0],
end: t + r[0].length
};
}
return null;
}
var In = /* @__PURE__ */ new Set("\\`![~*_\n<"), Ln = [
xn,
Sn,
Cn,
wn,
Tn,
En,
Dn,
On,
Fn,
kn
];
function J(e) {
let t = "", n = 0;
for (; n < e.length;) {
if (e[n] === "\n" && n >= 2 && e[n - 1] === " " && e[n - 2] === " ") {
t = t.replace(/ +$/, ""), t += "<br>\n", n++;
continue;
}
let r = !1;
if (In.has(e[n])) for (let i of Ln) {
let a = i(e, n);
if (a) {
t += a.html, n = a.end, r = !0;
break;
}
}
if (!r) {
let r = n;
for (n++; n < e.length && !In.has(e[n]);) n++;
t += K(e.substring(r, n));
}
}
return t;
}
function Rn(e, t) {
let n = 0, r = t;
for (; r < e.length && e[r] === "`";) n++, r++;
let i = r;
for (; i < e.length;) if (e[i] === "`") {
let t = 0, a = i;
for (; i < e.length && e[i] === "`";) t++, i++;
if (t === n) {
let t = e.substring(r, a);
return t = t.replace(/\n/g, " "), t.length >= 2 && t[0] === " " && t[t.length - 1] === " " && /[^ ]/.test(t) && (t = t.substring(1, t.length - 1)), {
html: `<code>${K(t)}</code>`,
end: i
};
}
} else i++;
return null;
}
function zn(e, t) {
let n = Vn(e, t + 1);
if (n === -1) return null;
let r = t + 2;
if (e[n + 1] !== "(") return null;
let i = n + 2, a = Hn(e, i - 1);
if (a === -1) return null;
let o = e.substring(r, n), { url: s, title: c } = Un(e.substring(i, a));
if (de(s)) {
let e = o || c;
return {
html: `<video src="${K(s)}"${e ? ` data-name="${K(e)}"` : ""} data-url="${K(s)}" controls></video>`,
end: a + 1
};
}
let l = c === void 0 ? "" : ` title="${K(c)}"`;
return {
html: `<img src="${K(s)}" alt="${K(o)}"${l}>`,
end: a + 1
};
}
function Bn(e, t) {
let n = t + 1, r = Vn(e, t);
if (r === -1 || e[r + 1] !== "(") return null;
let i = r + 2, a = Hn(e, r + 1);
if (a === -1) return null;
let o = e.substring(n, r), { url: s, title: c } = Un(e.substring(i, a)), l = c === void 0 ? "" : ` title="${K(c)}"`;
return {
html: `<a href="${K(s)}"${l}>${J(o)}</a>`,
end: a + 1
};
}
function Vn(e, t) {
let n = 0;
for (let r = t; r < e.length; r++) {
if (e[r] === "\\" && r + 1 < e.length) {
r++;
continue;
}
if (e[r] === "[" && n++, e[r] === "]" && (n--, n === 0)) return r;
}
return -1;
}
function Hn(e, t) {
let n = 0;
for (let r = t; r < e.length; r++) {
if (e[r] === "\\" && r + 1 < e.length) {
r++;
continue;
}
if (e[r] === "(" && n++, e[r] === ")" && (n--, n === 0)) return r;
}
return -1;
}
function Un(e) {
e = e.trim();
let t, n;
if (e.startsWith("<")) {
let r = e.indexOf(">");
r === -1 ? (t = e.substring(1), n = "") : (t = e.substring(1, r), n = e.substring(r + 1).trim());
} else {
let r = e.length;
for (let t = 0; t < e.length; t++) {
if (e[t] === "\\" && t + 1 < e.length) {
t++;
continue;
}
if (e[t] === " " || e[t] === " " || e[t] === "\n") {
r = t;
break;
}
}
t = e.substring(0, r), n = e.substring(r).trim();
}
let r;
if (n.length > 0) {
let e = n.match(/^"([^"]*)"$|^'([^']*)'$|^\(([^)]*)\)$/);
e && (r = e[1] ?? e[2] ?? e[3]);
}
return {
url: t,
title: r
};
}
function Y(e, t, n, r, i) {
let a = n.length, o = t + a;
if (o >= e.length || e[o] === " " || e[o] === " ") return null;
let s = o;
for (; s < e.length;) {
if (e[s] === "\\" && s + 1 < e.length) {
s += 2;
continue;
}
if (e.substring(s, s + a) === n) {
if (e[s - 1] === " " || e[s - 1] === " ") {
s++;
continue;
}
if (a === 1 && (s > 0 && e[s - 1] === n[0] && !(s >= 2 && e[s - 2] === "\\") || s + a < e.length && e[s + a] === n[0])) {
s++;
continue;
}
let t = e.substring(o, s);
if (t.length === 0) {
s++;
continue;
}
return {
html: r + J(t) + i,
end: s + a
};
}
s++;
}
return null;
}
var Wn = /* @__PURE__ */ new Set(/* @__PURE__ */ "address.article.aside.audio.base.basefont.blockquote.body.caption.center.col.colgroup.dd.details.dialog.dir.div.dl.dt.fieldset.figcaption.figure.footer.form.frame.frameset.h1.h2.h3.h4.h5.h6.head.header.hr.html.iframe.legend.li.link.main.menu.menuitem.nav.noframes.ol.optgroup.option.p.param.section.source.summary.table.tbody.td.tfoot.th.thead.title.tr.track.ul".split("."));
function Gn(e) {
if (/^ {0,3}<(!--|\?|![A-Za-z]|!\[CDATA\[)/.test(e)) return !0;
let t = e.match(/^ {0,3}<\/?([a-zA-Z][a-zA-Z0-9-]*)(?:\s|\/?>|$)/);
return t ? Wn.has(t[1].toLowerCase()) : !1;
}
function Kn(e) {
let t = e.split("\n"), n = [], r = 0, i = !0;
for (; r < t.length;) {
let e = t[r];
if (e.trim() === "") {
i = !0, r++;
continue;
}
let a = e.match(/^ {0,3}(`{3,}|~{3,})(.*)$/);
if (a) {
let e = a[1], o = e[0], s = e.length, c = a[2].trim(), l = [];
for (r++; r < t.length;) {
if (t[r].match(RegExp(`^ {0,3}${o}{${s},}\\s*$`))) {
r++;
break;
}
l.push(t[r]), r++;
}
n.push({
type: "codeBlock",
language: c || "",
code: l.join("\n")
}), i = !1;
continue;
}
let o = e.match(/^(#{1,6})\s+(.+?)(?:\s+#+\s*|\s*)$/);
if (o) {
n.push({
type: "heading",
level: o[1].length,
content: o[2]
}), i = !1, r++;
continue;
}
if (/^(\s{0,3})([-*_])\s*(\2\s*){2,}$/.test(e)) {
let t = n[n.length - 1];
if (!i && e.trim().match(/^-+$/) && t && t.type === "paragraph") {
let e = t;
n[n.length - 1] = {
type: "heading",
level: 2,
content: e.content
}, i = !1, r++;
continue;
}
n.push({ type: "hr" }), i = !1, r++;
continue;
}
if (r + 1 < t.length) {
let a = t[r + 1];
if (/^={1,}\s*$/.test(a) && e.trim().length > 0) {
n.push({
type: "heading",
level: 1,
content: e.trim()
}), i = !1, r += 2;
continue;
}
}
let s = qn(t, r);
if (s) {
n.push(s.token), r = s.nextLine, i = !1;
continue;
}
if (/^\s{0,3}>/.test(e)) {
let e = [];
for (; r < t.length && /^\s{0,3}>/.test(t[r]);) e.push(t[r].replace(/^\s{0,3}>\s?/, "")), r++;
for (; r < t.length;) {
let n = t[r];
if (n.trim() === "" || /^\s{0,3}>/.test(n) || /^(#{1,6})\s/.test(n) || /^(`{3,}|~{3,})/.test(n) || /^(\s{0,3})([-*_])\s*(\2\s*){2,}$/.test(n) || /^\s*([-*+]|\d+[.)])\s+/.test(n) || /^\s*\|(.+\|)+\s*$/.test(n)) break;
e.push(n), r++;
}
n.push({
type: "blockquote",
content: e.join("\n")
}), i = !1;
continue;
}
let c = e.match(/^(\s*)([-*+]|\d+[.)])(\s+)(\[[ xX]\] )?(.*)$/);
if (c) {
let e = c[1].length, a = c[2], o = c[3], s = c[4], l = c[5], u, d, f;
s ? (u = "task", f = s.trim() !== "[ ]") : /^\d+[.)]$/.test(a) ? (u = "ordered", d = parseInt(a, 10)) : u = "bullet";
let p = e + a.length + o.length + (s ? s.length : 0), m = e + 1, h = (e) => {
if (e.trim() === "") return !0;
let t = e.match(/^\s*/)[0].length;
return !!(t >= p || t >= m && e.match(/^\s*([-*+]|\d+[.)])\s+/));
};
r++;
let g = [];
for (; r < t.length;) {
let e = t[r];
if (e.trim() === "") {
let e = r + 1;
for (; e < t.length && t[e].trim() === "";) e++;
if (e < t.length && h(t[e])) {
g.push(""), r++;
continue;
}
break;
}
if (!h(e)) break;
e.match(/^\s*/)[0].length >= p ? g.push(e.substring(p)) : g.push(e.substring(m)), r++;
}
let _ = g.join("\n").replace(/^\n+|\n+$/g, "");
n.push({
type: "listItem",
listType: u,
indent: e,
content: l.trim(),
start: d,
checked: f,
childContent: _ || void 0
}), i = !1;
continue;
}
if (Gn(e)) {
let e = [];
for (; r < t.length && t[r].trim() !== "";) e.push(t[r]), r++;
n.push({
type: "rawHtml",
content: e.join("\n")
}), i = !1;
continue;
}
let l = [e];
for (r++; r < t.length;) {
let e = t[r];
if (e.trim() === "" || /^(#{1,6})\s/.test(e) || /^(`{3,}|~{3,})/.test(e) || /^\s{0,3}>/.test(e) || /^(\s{0,3})([-*_])\s*(\2\s*){2,}$/.test(e) || /^\s*([-*+]|\d+[.)])\s+/.test(e) || /^\s*\|(.+\|)+\s*$/.test(e) || Gn(e) || r + 1 < t.length && /^[=-]+\s*$/.test(t[r + 1]) && e.trim().length > 0) break;
l.push(e), r++;
}
n.push({
type: "paragraph",
content: l.map((e) => e.replace(/^ {1,3}/, "")).join("\n").replace(/[ \t]+$/, "")
}), i = !1;
}
return n;
}
function qn(e, t) {
if (t + 1 >= e.length) return null;
let n = e[t], r = e[t + 1];
if (!r.includes("|") || !/^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/.test(r) || !n.includes("|")) return null;
let i = Jn(n), a = Yn(r), o = [], s = t + 2;
for (; s < e.length;) {
let t = e[s];
if (!t.includes("|")) break;
o.push(Jn(t)), s++;
}
return {
token: {
type: "table",
headers: i,
rows: o,
alignments: a
},
nextLine: s
};
}
function Jn(e) {
let t = e.trim(), n = t.startsWith("|") ? t.substring(1) : t, r = n.endsWith("|") ? n.substring(0, n.length - 1) : n, i = [], a = "";
for (let e = 0; e < r.length; e++) r[e] === "\\" && e + 1 < r.length && r[e + 1] === "|" ? (a += "|", e++) : r[e] === "|" ? (i.push(a.trim()), a = "") : a += r[e];
return i.push(a.trim()), i;
}
function Yn(e) {
return Jn(e).map((e) => {
let t = e.trim(), n = t.startsWith(":"), r = t.endsWith(":");
return n && r ? "center" : r ? "right" : n ? "left" : null;
});
}
function Xn(e) {
let t = "", n = 0;
for (; n < e.length;) {
let r = e[n];
switch (r.type) {
case "heading": {
let e = r;
t += `<h${e.level}>${J(e.content)}</h${e.level}>`, n++;
break;
}
case "paragraph":
t += `<p>${J(r.content)}</p>`, n++;
break;
case "codeBlock": {
let e = r, i = e.language ? ` data-language="${K(e.language)}"` : "";
t += `<pre><code${i}>${K(e.code)}</code></pre>`, n++;
break;
}
case "blockquote": {
let e = Xn(Kn(r.content));
t += `<blockquote>${e}</blockquote>`, n++;
break;
}
case "hr":
t += "<hr>", n++;
break;
case "listItem": {
let r = Zn(e, n);
t += r.html, n = r.nextIndex;
break;
}
case "table":
t += $n(r), n++;
break;
case "rawHtml":
t += r.content, n++;
break;
default: n++;
}
}
return t;
}
function Zn(e, t) {
let n = "", r = t, i = null;
for (; r < e.length && e[r].type === "listItem";) {
let t = e[r], a = Qn(t.listType);
if (i !== null && i !== a && (n += `</${i === "ordered" ? "ol" : "ul"}>`, i = null), i === null) {
if (a === "ordered") {
let e = t.start !== void 0 && t.start !== 1 ? ` start="${t.start}"` : "";
n += `<ol${e}>`;
} else n += "<ul>";
i = a;
}
if (t.listType === "task") {
let e = t.checked ? " checked" : "";
n += `<li><input type="checkbox" disabled${e}><p>${J(t.content)}</p>`;
} else n += `<li><p>${J(t.content)}</p>`;
if (t.childContent) {
let e = Kn(t.childContent);
n += Xn(e);
}
n += "</li>", r++;
}
return i !== null && (n += `</${i === "ordered" ? "ol" : "ul"}>`), {
html: n,
nextIndex: r
};
}
function Qn(e) {
return e === "ordered" ? "ordered" : "bullet";
}
function $n(e) {
let t = "<table>", n = e.headers.every((e) => e.trim() === ""), r = e.headers.length;
if (!n) {
t += "<thead><tr>";
for (let n = 0; n < r; n++) {
let r = e.alignments[n], i = r ? ` align="${r}"` : "";
t += `<th${i}>${J(e.headers[n])}</th>`;
}
t += "</tr></thead>";
}
if (e.rows.length > 0) {
t += "<tbody>";
for (let n of e.rows) {
t += "<tr>";
for (let i = 0; i < r; i++) {
let r = i < n.length ? n[i] : "", a = e.alignments[i], o = a ? ` align="${a}"` : "";
t += `<td${o}>${J(r)}</td>`;
}
t += "</tr>";
}
t += "</tbody>";
}
return t += "</table>", t;
}
function er(e) {
return Xn(Kn(e));
}
//#endregion
//#region src/api/parsers/markdown/parseMarkdown.ts
function tr(e) {
return er(e);
}
function nr(e, t) {
return G(tr(e), t);
}
//#endregion
//#region src/editor/managers/ExportManager.ts
var rr = class {
editor;
constructor(e) {
this.editor = e;
}
blocksToHTMLLossy(e = this.editor.document) {
return ve(this.editor.pmSchema, this.editor).exportBlocks(e, {});
}
blocksToFullHTML(e = this.editor.document) {
return Nt(this.editor.pmSchema, this.editor).serializeBlocks(e, {});
}
tryParseHTMLToBlocks(e) {
return G(e, this.editor.pmSchema);
}
blocksToMarkdownLossy(e = this.editor.document) {
return Te(e, this.editor.pmSchema, this.editor, {});
}
tryParseMarkdownToBlocks(e) {
return nr(e, this.editor.pmSchema);
}
pasteHTML(e, t = !1) {
let n = e;
if (!t) {
let t = this.tryParseHTMLToBlocks(e);
n = this.blocksToFullHTML(t);
}
n && this.editor.prosemirrorView?.pasteHTML(n);
}
pasteText(e) {
return this.editor.prosemirrorView?.pasteText(e);
}
pasteMarkdown(e) {
let t = tr(e);
return this.pasteHTML(t);
}
};
//#endregion
//#region src/api/blockManipulation/selections/textCursorPosition.ts
function ir(e) {
let { bnBlock: t } = w(e), n = e.doc.resolve(t.beforePos), r = n.nodeBefore, i = e.doc.resolve(t.afterPos).nodeAfter, a;
return n.depth > 1 && (a = n.node(), a.type.isInGroup("bnBlock") || (a = n.node(n.depth - 1))), {
block: g(t.node, e.doc),
prevBlock: r === null ? void 0 : g(r, e.doc),
nextBlock: i === null ? void 0 : g(i, e.doc),
parentBlock: a === void 0 ? void 0 : g(a, e.doc)
};
}
function ar(e, t, n = "start") {
let r = typeof t == "string" ? t : t.id, i = u(e.doc), a = oe(i), o = p(r, e.doc);
if (!o) throw Error(`Block with ID ${r} not found`);
let s = v(o), c = a.blockSchema[s.blockNoteType].content;
if (s.isBlockContainer) {
let t = s.blockContent;
if (c === "none") {
e.setSelection(N.create(e.doc, t.beforePos));
return;
}
if (c === "inline" || c === "plain") n === "start" ? e.setSelection(F.create(e.doc, t.beforePos + 1)) : e.setSelection(F.create(e.doc, t.afterPos - 1));
else if (c === "table") n === "start" ? e.setSelection(F.create(e.doc, t.beforePos + 4)) : e.setSelection(F.create(e.doc, t.afterPos - 4));
else throw new _(c);
} else {
let t = n === "start" ? s.childContainer.node.firstChild : s.childContainer.node.lastChild;
ar(e, C(t, e.doc), n);
}
}
//#endregion
//#region src/api/clipboard/fromClipboard/acceptedMIMETypes.ts
var X = [
"vscode-editor-data",
"blocknote/html",
"text/markdown",
"text/html",
"text/plain",
"Files"
];
//#endregion
//#region src/api/clipboard/fromClipboard/handleFileInsertion.ts
function or(e, t) {
if (!e.startsWith(".") || !t.startsWith(".")) throw Error("The strings provided are not valid file extensions.");
return e === t;
}
function sr(e, t) {
let n = e.split("/"), r = t.split("/");
if (n.length !== 2) throw Error(`The string ${e} is not a valid MIME type.`);
if (r.length !== 2) throw Error(`The string ${t} is not a valid MIME type.`);
return n[1] === "*" || r[1] === "*" ? n[0] === r[0] : (n[0] === "*" || r[0] === "*" || n[0] === r[0]) && n[1] === r[1];
}
function cr(e, t, n, r = "after") {
let i;
return i = Array.isArray(t.content) && t.content.length === 0 ? e.updateBlock(t, n).id : e.insertBlocks([n], t, r)[0].id, i;
}
async function lr(e, t) {
if (!t.uploadFile) {
console.warn("Attempted ot insert file, but uploadFile is not set in the BlockNote editor options");
return;
}
let n = "dataTransfer" in e ? e.dataTransfer : e.clipboardData;
if (n === null) return;
let r = null;
for (let e of X) if (n.types.includes(e)) {
r = e;
break;
}
if (r !== "Files") return;
let i = n.items;
if (i) {
e.preventDefault();
for (let n = 0; n < i.length; n++) {
let r = "file";
for (let e of Object.values(t.schema.blockSpecs)) for (let t of e.implementation.meta?.fileBlockAccept || []) {
let a = t.startsWith("."), o = i[n].getAsFile();
if (o && (!a && o.type && sr(i[n].type, t) || a && or("." + o.name.split(".").pop(), t))) {
r = e.config.type;
break;
}
}
let a = i[n].getAsFile();
if (a) {
let n = {
type: r,
props: { name: a.name }
}, i;
if (e.type === "paste") {
let e = t.getTextCursorPosition().block;
i = cr(t, e, n);
} else if (e.type === "drop") {
let r = {
left: e.clientX,
top: e.clientY
}, a = t.prosemirrorView.posAtCoords(r);
if (!a) return;
i = t.transact((e) => {
let i = T(e, a.pos), o = C(i.bnBlock.node, e.doc), s = (t.domElement?.querySelector(`[data-id="${o}"]`))?.getBoundingClientRect(), c = t.getBlock(o);
if (c) return cr(t, c, n, s && (s.top + s.bottom) / 2 > r.top ? "before" : "after");
});
} else return;
if (!i) return;
let o = await t.uploadFile(a, i), s = typeof o == "string" ? { props: { url: o } } : { ...o };
t.updateBlock(i, s);
}
}
}
}
//#endregion
//#region src/api/clipboard/fromClipboard/fileDropExtension.ts
var ur = (e) => k.create({
name: "dropFile",
addProseMirrorPlugins() {
return [new P({ props: { handleDOMEvents: { drop(t, n) {
if (!e.isEditable) return;
let r = null;
for (let e of X) if (n.dataTransfer.types.includes(e)) {
r = e;
break;
}
return r === null || r === "Files" && (lr(n, e), !0);
} } } })];
}
}), dr = /(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/, fr = /(_|__|\*|\*\*|~~|==|\+\+)(?!\s)(?:[^\s](?:.{0,62}[^\s])?|\S)(?=\1)/, pr = /\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/, mr = /(?:\s|^)`(?!\s)(?:[^\s`](?:[^`]{0,46}[^\s`])?|[^\s`])`([^\w]|$)/, hr = /(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/, gr = /(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/, _r = /\n{2} {0,3}-{2,48}\n{2}/, vr = /(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/, yr = /(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/, br = /(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/, xr = /^\s*\|(.+\|)+\s*$/m, Sr = /^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m, Cr = /^\s*\|(.+\|)+\s*$/m, wr = (e) => dr.test(e) || fr.test(e) || pr.test(e) || mr.test(e) || hr.test(e) || gr.test(e) || _r.test(e) || vr.test(e) || yr.test(e) || br.test(e) || xr.test(e) || Sr.test(e) || Cr.test(e);
//#endregion
//#region src/api/clipboard/fromClipboard/handleVSCodePaste.ts
function Tr(e, t) {
let { schema: n } = t.state;
if (!e.clipboardData) return !1;
let r = e.clipboardData.getData("text/plain");
if (!r || !n.nodes.codeBlock) return !1;
let i = e.clipboardData.getData("vscode-editor-data"), a = (i ? JSON.parse(i) : void 0)?.mode;
return a ? (t.pasteHTML(`<pre><code class="language-${a}">${r.replace(/\r\n?/g, "\n")}</code></pre>`), !0) : !1;
}
//#endregion
//#region src/api/clipboard/fromClipboard/pasteExtension.ts
function Er({ event: e, editor: t, prioritizeMarkdownOverHTML: n, plainTextAsMarkdown: r }) {
if (t.transact((e) => e.selection.$from.parent.type.spec.code && e.selection.$to.parent.type.spec.code)) {
let n = e.clipboardData?.getData("text/plain");
if (n) return t.pasteText(n), !0;
}
let i;
for (let t of X) if (e.clipboardData.types.includes(t)) {
i = t;
break;
}
if (!i) return !0;
if (i === "vscode-editor-data") {
if (Tr(e, t.prosemirrorView)) return !0;
i = "text/plain";
}
if (i === "Files") return lr(e, t), !0;
let a = e.clipboardData.getData(i);
if (i === "blocknote/html") return t.pasteHTML(a, !0), !0;
if (i === "text/markdown") return t.pasteMarkdown(a), !0;
if (n) {
let n = e.clipboardData.getData("text/plain");
if (wr(n)) return t.pasteMarkdown(n), !0;
}
return i === "text/html" ? (t.pasteHTML(a), !0) : r ? (t.pasteMarkdown(a), !0) : (t.pasteText(a), !0);
}
var Dr = (e, t) => k.create({
name: "pasteFromClipboard",
addProseMirrorPlugins() {
return [new P({ props: { handleDOMEvents: { paste(n, r) {
if (r.preventDefault(), e.isEditable) return t({
event: r,
editor: e,
defaultPasteHandler: ({ prioritizeMarkdownOverHTML: t = !0, plainTextAsMarkdown: n = !0 } = {}) => Er({
event: r,
editor: e,
prioritizeMarkdownOverHTML: t,
plainTextAsMarkdown: n
})
});
} } } })];
}
});
//#endregion
//#region src/api/clipboard/toClipboard/copyExtension.ts
function Or(e, n, r) {
let i = !1, a = e.state.selection instanceof at;
if (!a) {
let t = e.state.doc.slice(e.state.selection.from, e.state.selection.to, !1).content, r = [];
for (let e = 0; e < t.childCount; e++) r.push(t.child(e));
i = r.find((e) => e.type.isInGroup("bnBlock") || e.type.name === "blockGroup" || e.type.spec.group === "blockContent") === void 0, i && (n = t);
}
let o, s = ve(e.state.schema, r);
if (a) {
n.firstChild?.type.name === "table" && (n = n.firstChild.content);
let e = t(n, r.schema.inlineContentSchema, r.schema.styleSchema);
o = `<table>${s.exportInlineContent(e, {})}</table>`;
} else if (i) {
let e = h(n, r.schema.inlineContentSchema, r.schema.styleSchema);
o = s.exportInlineContent(e, {});
} else {
let e = Pe(n);
o = s.exportBlocks(e, {});
}
return o;
}
function kr(e, t) {
"node" in e.state.selection && e.state.selection.node.type.spec.group === "blockContent" && t.transact((t) => t.setSelection(new N(t.doc.resolve(e.state.selection.from - 1))));
let n = e.serializeForClipboard(e.state.selection.content()).dom.innerHTML, r = e.state.selection.content().content, i = Or(e, r, t), { $from: a, $to: o } = e.state.selection, s = a.parent.type.name, c = t.blockImplementations[s];
return {
clipboardHTML: n,
externalHTML: i,
markdown: a.sameParent(o) && c?.implementation.meta?.code === !0 ? e.state.doc.textBetween(a.pos, o.pos) : Ne(i)
};
}
var Ar = (e) => {
if (e.state.selection.empty) return !0;
let t = window.getSelection();
if (t && !t.isCollapsed) {
let e = t.focusNode;
for (; e;) {
if (e instanceof HTMLElement && e.getAttribute("contenteditable") === "false") return !0;
e = e.parentElement;
}
}
return !1;
}, jr = (e, t, n) => {
n.preventDefault(), n.clipboardData.clearData();
let { clipboardHTML: r, externalHTML: i, markdown: a } = kr(t, e);
n.clipboardData.setData("blocknote/html", r), n.clipboardData.setData("text/html", i), n.clipboardData.setData("text/plain", a);
}, Mr = (e) => k.create({
name: "copyToClipboard",
addProseMirrorPlugins() {
return [new P({ props: { handleDOMEvents: {
copy(t, n) {
return Ar(t) || jr(e, t, n), !0;
},
cut(t, n) {
return Ar(t) ? !0 : (jr(e, t, n), t.editable && t.dispatch(t.state.tr.deleteSelection()), !0);
},
dragstart(t, n) {
if (!("node" in t.state.selection) || t.state.selection.node.type.spec.group !== "blockContent") return;
e.transact((e) => e.setSelection(new N(e.doc.resolve(t.state.selection.from - 1)))), n.preventDefault(), n.dataTransfer.clearData();
let { clipboardHTML: r, externalHTML: i, markdown: a } = kr(t, e);
return n.dataTransfer.setData("blocknote/html", r), n.dataTransfer.setData("text/html", i), n.dataTransfer.setData("text/plain", a), !0;
}
} } })];
}
}), Nr = k.create({
name: "blockBackgroundColor",
addGlobalAttributes() {
return [{
types: ["tableCell", "tableHeader"],
attributes: { backgroundColor: ue() }
}];
}
}), Pr = A.create({
name: "hardBreak",
inline: !0,
group: "inline",
selectable: !1,
linebreakReplacement: !0,
priority: 10,
parseHTML() {
return [{ tag: "br" }];
},
renderHTML({ HTMLAttributes: e }) {
return ["br", M(this.options.HTMLAttributes, e)];
},
renderText() {
return "\n";
}
}), Fr = (e, t) => {
let n = e.resolve(t), r = n.depth - 1;
if (r < 1) return;
let i = n.before(r), a = e.resolve(i).nodeAfter;
if (a) return a.type.spec.group?.includes("bnBlock") ? S(e.resolve(i)) : Fr(e, i);
}, Z = (e, t) => {
let n = e.resolve(t), r = n.index();
if (r === 0) return;
let i = n.posAtIndex(r - 1);
return S(e.resolve(i));
}, Q = (e, t) => {
let n = e.resolve(t), r = n.index();
if (r === n.node().childCount - 1) return;
let i = n.posAtIndex(r + 1);
return S(e.resolve(i));
}, Ir = (e, t) => {
for (; t.childContainer;) {
let n = t.childContainer.node, r = e.resolve(t.childContainer.beforePos + 1).posAtIndex(n.childCount - 1);
t = S(e.resolve(r));
}
return t;
}, Lr = (e, t) => e.isBlockContainer && e.blockContent.node.type.spec.content === "inline*" && e.blockContent.node.childCount > 0 && t.isBlockContainer && t.blockContent.node.type.spec.content === "inline*", Rr = (e, t, n, r) => {
if (!r.isBlockContainer) throw Error(`Attempted to merge block at position ${r.bnBlock.beforePos} into previous block at position ${n.bnBlock.beforePos}, but next block is not a block container`);
if (r.childContainer) {
let n = e.doc.resolve(r.childContainer.beforePos + 1), i = e.doc.resolve(r.childContainer.afterPos - 1), a = n.blockRange(i);
if (t) {
let t = e.doc.resolve(r.bnBlock.beforePos);
e.tr.lift(a, t.depth);
}
}
if (t) {
if (!n.isBlockContainer) throw Error(`Attempted to merge block at position ${r.bnBlock.beforePos} into previous block at position ${n.bnBlock.beforePos}, but previous block is not a block container`);
t(e.tr.delete(n.blockContent.afterPos - 1, r.blockContent.beforePos + 1));
}
return !0;
}, zr = (e) => ({ state: t, dispatch: n }) => {
let r = t.doc.resolve(e), i = S(r), a = Z(t.doc, i.bnBlock.beforePos);
if (!a) return !1;
let o = Ir(t.doc, a);
return Lr(o, i) ? Rr(t, n, o, i) : !1;
}, Br = k.create({
priority: 50,
addKeyboardShortcuts() {
let e = () => this.editor.commands.first(({ chain: e, commands: t }) => [
() => t.deleteSelection(),
() => t.undoInputRule(),
() => t.command(({ state: e }) => {
let n = w(e);
if (!n.isBlockContainer) return !1;
let r = e.selection.from === n.blockContent.beforePos + 1, i = n.blockContent.node.type.name === "paragraph";
return r && !i ? t.command(d(n.bnBlock.beforePos, {
type: "paragraph",
props: {}
})) : !1;
}),
() => t.command(({ state: e, tr: t }) => {
let n = w(e);
if (!n.isBlockContainer) return !1;
let { blockContent: r } = n;
return e.selection.from === r.beforePos + 1 && W(t, t.doc.type.schema.nodes.blockContainer, t.doc.type.schema.nodes.blockGroup);
}),
() => t.command(({ state: t }) => {
let n = w(t);
if (!n.isBlockContainer) return !1;
let { bnBlock: r, blockContent: i } = n, a = Z(t.doc, n.bnBlock.beforePos);
if (!a || !a.isBlockContainer || a.blockContent.node.type.spec.content !== "inline*") return !1;
let o = t.selection.from === i.beforePos + 1, s = t.selection.empty, c = r.beforePos;
return o && s ? e().command(zr(c)).scrollIntoView().run() : !1;
}),
() => t.command(({ state: e, tr: t, dispatch: n }) => {
let r = w(e);
if (!r.isBlockContainer || e.selection.from !== r.blockContent.beforePos + 1) return !1;
let i = Z(e.doc, r.bnBlock.beforePos);
if (!i || i.isBlockContainer) return !1;
if (n) {
let e = i.bnBlock.afterPos - 1, n = t.doc.resolve(e - 1);
return t.delete(r.bnBlock.beforePos, r.bnBlock.afterPos), t.insert(n.pos, r.bnBlock.node), t.setSelection(F.near(t.doc.resolve(n.pos + 1))), !0;
}
return !1;
}),
() => t.command(({ state: e, tr: t, dispatch: n }) => {
let r = w(e);
if (!r.isBlockContainer || t.selection.from !== r.blockContent.beforePos + 1) return !1;
let i = t.doc.resolve(r.bnBlock.beforePos);
if (i.nodeBefore || i.node().type.name !== "column") return !1;
let a = t.doc.resolve(r.bnBlock.beforePos), o = t.doc.resolve(a.before()), s = o.before();
return n && (t.delete(r.bnBlock.beforePos, r.bnBlock.afterPos), z(t, s), o.pos === s + 1 ? (t.insert(s, r.bnBlock.node), t.setSelection(F.near(t.doc.resolve(s)))) : (t.insert(o.pos - 1, r.bnBlock.node), t.setSelection(F.near(t.doc.resolve(o.pos))))), !0;
}),
() => t.command(({ state: t }) => {
let n = w(t);
if (!n.isBlockContainer) return !1;
if (n.blockContent.node.childCount === 0 && n.blockContent.node.type.spec.content === "inline*") {
let r = Z(t.doc, n.bnBlock.beforePos);
if (!r) return !1;
let i = Ir(t.doc, r);
if (!i.isBlockContainer || !i || !i.isBlockContainer) return !1;
let a = e();
if (n.childContainer && a.insertContentAt(n.bnBlock.afterPos, n.childContainer?.node.content), i.blockContent.node.type.spec.content === "tableRow+") {
let e = n.bnBlock.beforePos - 1 - 1 - 1 - 1 - 1;
a = a.setTextSelection(e);
} else if (i.blockContent.node.type.spec.content === "") a = a.setNodeSelection(i.blockContent.beforePos);
else {
let e = i.blockContent.afterPos - 1;
a = a.setTextSelection(e);
}
return a.deleteRange({
from: n.bnBlock.beforePos,
to: n.bnBlock.afterPos
}).scrollIntoView().run();
}
return !1;
}),
() => t.command(({ state: t }) => {
let n = w(t);
if (!n.isBlockContainer) return !1;
let r = t.selection.from === n.blockContent.beforePos + 1, i = t.selection.empty, a = Z(t.doc, n.bnBlock.beforePos);
if (a && r && i) {
let r = Ir(t.doc, a);
if (!r.isBlockContainer) return !1;
if (r.blockContent.node.type.spec.content === "" || r.blockContent.node.type.spec.content === "inline*" && r.blockContent.node.childCount === 0) return e().cut({
from: n.bnBlock.beforePos,
to: n.bnBlock.afterPos
}, r.bnBlock.afterPos).deleteRange({
from: r.bnBlock.beforePos,
to: r.bnBlock.afterPos
}).run();
}
return !1;
})
]), t = () => this.editor.commands.first(({ chain: e, commands: t }) => [
() => t.deleteSelection(),
() => t.command(({ state: t }) => {
let n = w(t);
if (!n.isBlockContainer || !n.childContainer) return !1;
let { blockContent: r, childContainer: i } = n, a = t.selection.from === r.afterPos - 1, o = t.selection.empty, s = S(t.doc.resolve(i.beforePos + 1));
if (!s.isBlockContainer) return !1;
if (a && o) {
let n = s.blockContent.node, a = n.type.spec.content === "inline*", o = r.node.type.spec.content === "inline*";
return e().insertContentAt(s.bnBlock.afterPos, s.childContainer?.node.content || E.empty).deleteRange(i.node.childCount === 1 ? {
from: i.beforePos,
to: i.afterPos
} : {
from: s.bnBlock.beforePos,
to: s.bnBlock.afterPos
}).insertContentAt(t.selection.from, a && o ? n.content : null).setTextSelection(t.selection.from).scrollIntoView().run();
}
return !1;
}),
() => t.command(({ state: t }) => {
let n = w(t);
if (!n.isBlockContainer) return !1;
let { bnBlock: r, blockContent: i } = n, a = Q(t.doc, n.bnBlock.beforePos);
if (!a || !a.isBlockContainer) return !1;
let o = t.selection.from === i.afterPos - 1, s = t.selection.empty, c = r.afterPos;
return o && s ? e().command(zr(c)).scrollIntoView().run() : !1;
}),
() => t.command(({ state: e, tr: t, dispatch: n }) => {
let r = w(e);
if (!r.isBlockContainer || e.selection.from !== r.blockContent.afterPos - 1) return !1;
let i = Q(e.doc, r.bnBlock.beforePos);
if (!i || i.isBlockContainer) return !1;
if (n) {
let e = i.bnBlock.beforePos + 1, n = t.doc.resolve(e + 1);
return t.delete(n.pos, n.pos + n.nodeAfter.nodeSize), z(t, i.bnBlock.beforePos), t.insert(r.bnBlock.afterPos, n.nodeAfter), t.setSelection(F.near(t.doc.resolve(n.pos))), !0;
}
return !1;
}),
() => t.command(({ state: e, tr: t, dispatch: n }) => {
let r = w(e);
if (!r.isBlockContainer || t.selection.from !== r.blockContent.afterPos - 1) return !1;
let i = t.doc.resolve(r.bnBlock.afterPos);
if (i.nodeAfter || i.node().type.name !== "column") return !1;
let a = t.doc.resolve(r.bnBlock.afterPos), o = t.doc.resolve(a.after()), s = o.after();
if (n) {
let e = o.pos === s - 1 ? s : o.pos + 1, n = S(t.doc.resolve(e));
t.delete(n.bnBlock.beforePos, n.bnBlock.afterPos), z(t, s - o.node().nodeSize), t.insert(a.pos, n.bnBlock.node), t.setSelection(F.near(t.doc.resolve(e)));
}
return !0;
}),
() => t.command(({ state: t }) => {
let n = w(t);
if (!n.isBlockContainer) return !1;
let { blockContent: r } = n, i = t.selection.from === r.afterPos - 1, a = t.selection.empty;
if (i && a) {
let i = (e, t) => {
let n = Q(e, t);
if (n) return n;
let r = Fr(e, t);
if (r) return i(e, r.bnBlock.beforePos);
}, a = i(t.doc, n.bnBlock.beforePos);
if (!a || !a.isBlockContainer) return !1;
let o = a.blockContent.node, s = o.type.spec.content === "inline*", c = r.node.type.spec.content === "inline*";
return e().insertContentAt(a.bnBlock.afterPos, a.childContainer?.node.content || E.empty).deleteRange({
from: a.bnBlock.beforePos,
to: a.bnBlock.afterPos
}).insertContentAt(t.selection.from, s && c ? o.content : null).setTextSelection(t.selection.from).scrollIntoView().run();
}
return !1;
}),
() => t.command(({ state: t }) => {
let n = w(t);
if (!n.isBlockContainer) return !1;
if (n.blockContent.node.childCount === 0 && n.blockContent.node.type.spec.content === "inline*") {
let r = Q(t.doc, n.bnBlock.beforePos);
if (!r || !r.isBlockContainer) return !1;
let i = e();
if (r.blockContent.node.type.spec.content === "tableRow+") {
let e = n.bnBlock.afterPos + 1 + 1 + 1 + 1 + 1;
i = i.setTextSelection(e);
} else i = r.blockContent.node.type.spec.content === "" ? i.setNodeSelection(r.blockContent.beforePos) : i.setTextSelection(r.blockContent.beforePos + 1);
return i.deleteRange({
from: n.bnBlock.beforePos,
to: n.bnBlock.afterPos
}).scrollIntoView().run();
}
return !1;
}),
() => t.command(({ state: t }) => {
let n = w(t);
if (!n.isBlockContainer) return !1;
let r = t.selection.from === n.blockContent.afterPos - 1, i = t.selection.empty, a = Q(t.doc, n.bnBlock.beforePos);
if (!a || !a.isBlockContainer) return !1;
if (a && r && i && (a.blockContent.node.type.spec.content === "" || a.blockContent.node.type.spec.content === "inline*" && a.blockContent.node.childCount === 0)) {
let t = a.bnBlock.node.lastChild.content;
return e().deleteRange({
from: a.bnBlock.beforePos,
to: a.bnBlock.afterPos
}).insertContentAt(n.bnBlock.afterPos, a.bnBlock.node.childCount === 2 ? t : null).run();
}
return !1;
})
]), n = (e = !1) => this.editor.commands.first(({ commands: t, tr: n }) => [
() => t.command(({ state: e, tr: t }) => {
let n = w(e);
if (!n.isBlockContainer) return !1;
let { bnBlock: r, blockContent: i } = n, { depth: a } = e.doc.resolve(r.beforePos), o = e.selection.$anchor.parentOffset === 0, s = e.selection.anchor === e.selection.head, c = i.node.childCount === 0;
return o && s && c && a > 1 ? W(t, t.doc.type.schema.nodes.blockContainer, t.doc.type.schema.nodes.blockGroup) : !1;
}),
() => t.command(({ state: t }) => {
let r = w(t), i = this.options.editor.schema.blockSpecs[r.blockNoteType], a = i?.implementation?.meta?.hardBreakShortcut ?? "shift+enter";
if (a === "none") return !1;
if (a === "shift+enter" && e || a === "enter") {
if (i?.config?.content === "plain") return n.insertText("\n", n.selection.head), !0;
let e = n.storedMarks || n.selection.$head.marks().filter((e) => this.editor.extensionManager.splittableMarks.includes(e.type.name));
return n.insert(n.selection.head, n.doc.type.schema.nodes.hardBreak.create()).ensureMarks(e), !0;
}
return !1;
}),
() => t.command(({ state: e, dispatch: t, tr: n }) => {
let r = w(e);
if (!r.isBlockContainer) return !1;
let { bnBlock: i, blockContent: a } = r, o = e.selection.$anchor.parentOffset === 0, s = e.selection.anchor === e.selection.head, c = a.node.childCount === 0;
if (o && s && c) {
let a = i.afterPos, o = a + 2;
if (t) {
let t = e.schema.nodes.blockContainer.createAndFill(void 0, [e.schema.nodes.paragraph.createAndFill() || void 0, r.childContainer?.node].filter((e) => e !== void 0));
n.insert(a, t).setSelection(new F(n.doc.resolve(o))).scrollIntoView(), r.childContainer && n.delete(r.childContainer.beforePos, r.childContainer.afterPos);
}
return !0;
}
return !1;
}),
() => t.command(({ state: e, chain: t }) => {
let n = w(e);
if (!n.isBlockContainer) return !1;
let { blockContent: r } = n, i = e.selection.$anchor.parentOffset === 0;
return r.node.childCount !== 0 && (t().deleteSelection().command(o(e.selection.from, i, i)).scrollIntoView().run(), !0);
})
]);
return {
Backspace: e,
Delete: t,
Enter: () => n(),
"Shift-Enter": () => n(!0),
Tab: () => this.options.tabBehavior !== "prefer-indent" && (this.options.editor.getExtension(x)?.store.state || this.options.editor.getExtension(fe)?.store.state !== void 0) ? !1 : Yt(this.options.editor),
"Shift-Tab": () => this.options.tabBehavior !== "prefer-indent" && (this.options.editor.getExtension(x)?.store.state || this.options.editor.getExtension(fe)?.store.state !== void 0) ? !1 : Zt(this.options.editor),
"Shift-Mod-ArrowUp": () => (this.options.editor.moveBlocksUp(), !0),
"Shift-Mod-ArrowDown": () => (this.options.editor.moveBlocksDown(), !0),
"Mod-z": () => this.options.editor.undo(),
"Mod-y": () => this.options.editor.redo(),
"Shift-Mod-z": () => this.options.editor.redo()
};
}
}), Vr = k.create({
name: "textAlignment",
addGlobalAttributes() {
return [{
types: ["tableCell", "tableHeader"],
attributes: { textAlignment: {
default: "left",
parseHTML: (e) => e.getAttribute("data-text-alignment"),
renderHTML: (e) => e.textAlignment === "left" ? {} : { "data-text-alignment": e.textAlignment }
} }
}];
}
}), Hr = k.create({
name: "blockTextColor",
addGlobalAttributes() {
return [{
types: [
"table",
"tableCell",
"tableHeader"
],
attributes: { textColor: i() }
}];
}
}), Ur = "aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2odyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rck0msd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2oodside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2";
//#endregion
//#region src/extensions/tiptap-extensions/Link/helpers/linkDetector.ts
function Wr(e) {
let t = [], n = [], r = 0;
for (; r < e.length;) {
let i = 0;
for (; r + i < e.length && e.charCodeAt(r + i) >= 48 && e.charCodeAt(r + i) <= 57;) i++;
if (i > 0) {
t.push(n.join(""));
let a = parseInt(e.substring(r, r + i), 10);
for (; a-- > 0;) n.pop();
r += i;
} else n.push(e[r]), r++;
}
return t;
}
var Gr = new Set(Wr(Ur)), Kr = /* @__PURE__ */ new Set(["localhost"]), qr = /[.,;:!?"']+$/, Jr = /(?:https?|ftp|ftps):\/\/[^\s]+/g, Yr = /mailto:[^\s]+/g, Xr = /[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}/g, Zr = /(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(?::\d{1,5})?(?:[/?#][^\s]*)?/g;
function Qr(e) {
let t = e, n = !0;
for (; n;) {
n = !1;
let e = t;
t = t.replace(qr, ""), t !== e && (n = !0);
for (let [e, r] of [["(", ")"], ["[", "]"]]) for (; t.endsWith(r);) {
let i = $r(t, e);
if ($r(t, r) > i) t = t.slice(0, -1), n = !0;
else break;
}
}
return t;
}
function $r(e, t) {
let n = 0;
for (let r = 0; r < e.length; r++) e[r] === t && n++;
return n;
}
function ei(e) {
let t = e.split(".");
return t[t.length - 1].toLowerCase();
}
function ti(e) {
let t = ei(e);
return Gr.has(t);
}
function ni(e, t, n) {
return t === "email" ? "mailto:" + e : /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(e) || /^mailto:/i.test(e) ? e : n + "://" + e;
}
function ri(e, t) {
if (!e) return [];
let n = t?.defaultProtocol || "http", r = [];
for (let t of e.matchAll(Jr)) r.push({
type: "url",
value: t[0],
start: t.index,
end: t.index + t[0].length
});
for (let t of e.matchAll(Yr)) r.push({
type: "url",
value: t[0],
start: t.index,
end: t.index + t[0].length
});
for (let t of e.matchAll(Xr)) r.push({
type: "email",
value: t[0],
start: t.index,
end: t.index + t[0].length
});
for (let t of e.matchAll(Zr)) r.push({
type: "url",
value: t[0],
start: t.index,
end: t.index + t[0].length
});
r.sort((e, t) => e.start - t.start || t.end - e.end);
let i = [], a = -1;
for (let e of r) e.start >= a && (i.push(e), a = e.end);
let o = [];
for (let e of i) {
let t = Qr(e.value);
if (!t) continue;
let r = e.start, i = r + t.length;
if (e.type === "url" && !/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(t)) {
let e = new URL("http://" + t).hostname;
if (!ti(e)) continue;
}
if (e.type === "email") {
let e = t.split("@")[1];
if (!ti(e)) continue;
}
let a = ni(t, e.type, n);
o.push({
type: e.type,
value: t,
isLink: !0,
href: a,
start: r,
end: i
});
}
return o;
}
function ii(e, t = "http") {
if (!e) return [$(e, 0, 0)];
for (let [n, r] of [
["(", ")"],
["[", "]"],
["{", "}"]
]) if (e.startsWith(n) && e.endsWith(r) && e.length > 2) {
let i = e.slice(1, -1);
if (ai(i)) return [
$(n, 0, 1),
oi(i, 1, 1 + i.length, t),
$(r, 1 + i.length, e.length)
];
}
if (e.endsWith(".") && e.length > 1) {
let n = e.slice(0, -1);
if (ai(n)) return [oi(n, 0, n.length, t), $(".", n.length, e.length)];
}
return ai(e) ? [oi(e, 0, e.length, t)] : [$(e, 0, e.length)];
}
function ai(e) {
if (/^(?:https?|ftp|ftps):\/\/[^\s]+$/.test(e) || /^mailto:[^\s]+$/.test(e) || Kr.has(e.toLowerCase())) return !0;
let t = e.match(/^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+([a-zA-Z]{2,})(?::\d{1,5})?(?:[/?#][^\s]*)?$/);
if (t) {
let e = t[1].toLowerCase();
if (Gr.has(e)) return !0;
}
return !1;
}
function oi(e, t, n, r) {
let i = e.includes("@") && !e.includes("://") && !e.startsWith("mailto:") ? "email" : "url";
return {
type: i,
value: e,
isLink: !0,
href: ni(e, i, r),
start: t,
end: n
};
}
function $(e, t, n) {
return {
type: "text",
value: e,
isLink: !1,
href: e,
start: t,
end: n
};
}
//#endregion
//#region src/extensions/tiptap-extensions/Link/helpers/whitespace.ts
var si = "[\0- \xA0 -\u2029 ]", ci = new RegExp(si), li = RegExp(`${si}$`), ui = new RegExp(si, "g");
//#endregion
//#region src/extensions/tiptap-extensions/Link/helpers/autolink.ts
function di(e) {
return e.length === 1 ? e[0].isLink : e.length === 3 && e[1].isLink ? ["()", "[]"].includes(e[0].value + e[2].value) : !1;
}
function fi(e) {
return new st({
key: new ct("autolink"),
appendTransaction: (t, n, r) => {
let i = t.some((e) => e.docChanged) && !n.doc.eq(r.doc), a = t.some((e) => e.getMeta("preventAutolink"));
if (!i || a) return;
let { tr: o } = r, s = Ge(n.doc, [...t]);
if (Xe(s).forEach(({ newRange: t }) => {
let n = qe(r.doc, t, (e) => e.isTextblock), i, a;
if (n.length > 1) i = n[0], a = r.doc.textBetween(i.pos, i.pos + i.node.nodeSize, void 0, " ");
else if (n.length) {
let e = r.doc.textBetween(t.from, t.to, " ", " ");
if (!li.test(e)) return;
i = n[0], a = r.doc.textBetween(i.pos, t.to, void 0, " ");
}
if (i && a) {
let t = a.split(ci).filter(Boolean);
if (t.length <= 0) return;
let n = t[t.length - 1], s = i.pos + a.lastIndexOf(n);
if (!n) return;
let c = ii(n, e.defaultProtocol);
if (!di(c)) return;
c.filter((e) => e.isLink).map((e) => ({
...e,
from: s + e.start + 1,
to: s + e.end + 1
})).filter((e) => !r.schema.marks.code || !r.doc.rangeHasMark(e.from, e.to, r.schema.marks.code)).filter((t) => e.validate(t.value)).filter((t) => e.shouldAutoLink(t.value)).forEach((t) => {
Qe(t.from, t.to, r.doc).some((t) => t.mark.type === e.type) || o.addMark(t.from, t.to, e.type.create({ href: t.href }));
});
}
}), o.steps.length) return o;
}
});
}
//#endregion
//#region src/extensions/tiptap-extensions/Link/helpers/clickHandler.ts
function pi(e) {
return new st({
key: new ct("handleClickLink"),
props: { handleClick: (t, n, r) => {
if (r.button !== 0 || !t.editable) return !1;
let i = null;
if (r.target instanceof HTMLAnchorElement && r.target.getAttribute("data-inline-content-type") === "link") i = r.target;
else {
let t = r.target;
if (!t) return !1;
let n = e.tiptapEditor.view.dom;
i = t.closest("a[data-inline-content-type=\"link\"]"), i && !n.contains(i) && (i = null);
}
if (!i) return !1;
if (e.onClick) {
if (!e.editor) throw Error("BlockNoteEditor not found in Link click handler");
return e.onClick(r, e.editor) ?? !0;
}
let a = Ye(t.state, e.type.name), o = i.href ?? a.href, s = i.target ?? a.target;
return o ? (window.open(o, s), !0) : !1;
} }
});
}
//#endregion
//#region src/extensions/tiptap-extensions/Link/helpers/pasteHandler.ts
function mi(e) {
return new st({
key: new ct("handlePasteLink"),
props: { handlePaste: (t, n, r) => {
let { shouldAutoLink: i, isValidLink: a } = e, { state: o } = t, { selection: s } = o, { empty: c } = s;
if (c) return !1;
let l = "";
r.content.forEach((e) => {
l += e.textContent;
});
let u = ri(l, { defaultProtocol: e.defaultProtocol }).find((e) => e.isLink && e.value === l);
return !l || !u || !a(u.value) || i !== void 0 && !i(u.value) ? !1 : e.editor.commands.setMark(e.type, { href: u.href });
} }
});
}
//#endregion
//#region src/extensions/tiptap-extensions/Link/link.ts
var hi = "https", gi = /^(?:(?:http|https|ftp|ftps|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z0-9+.\-]+(?:[^a-z+.\-:]|$))/i;
function _i(e) {
if (!e) return !0;
let t = e.replace(ui, "");
return gi.test(t);
}
function vi(e) {
let t = /^[a-z][a-z0-9+.-]*:\/\//i.test(e), n = /^[a-z][a-z0-9+.-]*:/i.test(e);
if (t || n && !e.includes("@")) return !0;
let r = (e.includes("@") ? e.split("@").pop() : e).split(/[/?#:]/)[0];
return !(/^\d{1,3}(\.\d{1,3}){3}$/.test(r) || !/\./.test(r));
}
var yi = We.create({
name: "link",
keepOnSplit: !1,
exitable: !0,
inclusive: !1,
addOptions() {
return {
HTMLAttributes: {
target: "_blank",
rel: "noopener noreferrer nofollow",
className: "bn-inline-content-section",
"data-inline-content-type": "link"
},
editor: void 0,
onClick: void 0,
isValidLink: _i
};
},
addAttributes() {
return { href: {
default: null,
parseHTML(e) {
return e.getAttribute("href");
}
} };
},
parseHTML() {
let e = this.options.isValidLink;
return [{
tag: "a[href]",
getAttrs: (t) => {
let n = t.getAttribute("href");
return !n || !e(n) ? !1 : null;
}
}];
},
renderHTML({ HTMLAttributes: e }) {
return this.options.isValidLink(e.href) ? [
"a",
M(e, this.options.HTMLAttributes),
0
] : [
"a",
M({
...e,
href: ""
}, this.options.HTMLAttributes),
0
];
},
addPasteRules() {
let e = this.options.isValidLink;
return [tt({
find: (t) => {
let n = [];
if (t) {
let r = ri(t, { defaultProtocol: hi }).filter((t) => t.isLink && e(t.value));
for (let e of r) vi(e.value) && n.push({
text: e.value,
data: { href: e.href },
index: e.start
});
}
return n;
},
type: this.type,
getAttributes: (e) => ({ href: e.data?.href })
})];
},
addProseMirrorPlugins() {
let e = [];
return e.push(fi({
type: this.type,
defaultProtocol: hi,
validate: this.options.isValidLink,
shouldAutoLink: vi
})), e.push(pi({
type: this.type,
tiptapEditor: this.editor,
editor: this.options.editor,
onClick: this.options.onClick
})), e.push(mi({
editor: this.editor,
defaultProtocol: hi,
type: this.type,
shouldAutoLink: vi,
isValidLink: this.options.isValidLink
})), e;
}
}), bi = he(({ editor: e, options: t }) => ({
key: "link",
tiptapExtensions: [yi.configure({
HTMLAttributes: t.HTMLAttributes ?? {},
editor: e,
onClick: t.onClick,
...t.isValidLink ? { isValidLink: t.isValidLink } : {}
})]
})), xi = {
blockColor: "data-block-color",
blockStyle: "data-block-style",
id: "data-id",
depth: "data-depth",
depthChange: "data-depth-change"
}, Si = A.create({
name: "blockContainer",
group: "blockGroupChild bnBlock",
content: "blockContent blockGroup?",
priority: 50,
defining: !0,
marks() {
return b(this.editor);
},
parseHTML() {
return [{
tag: "div[data-node-type=" + this.name + "]",
getAttrs: (e) => {
if (typeof e == "string") return !1;
let t = {};
for (let [n, r] of Object.entries(xi)) e.getAttribute(r) && (t[n] = e.getAttribute(r));
return t;
}
}, {
tag: "div[data-node-type=\"blockOuter\"]",
skip: !0
}];
},
renderHTML({ HTMLAttributes: e }) {
let t = document.createElement("div");
t.className = "bn-block-outer", t.setAttribute("data-node-type", "blockOuter");
for (let [n, r] of Object.entries(e)) n !== "class" && t.setAttribute(n, r);
let n = {
...this.options.domAttributes?.block || {},
...e
}, r = document.createElement("div");
r.className = s("bn-block", n.class), r.setAttribute("data-node-type", this.name);
for (let [e, t] of Object.entries(n)) e !== "class" && r.setAttribute(e, t);
return t.appendChild(r), {
dom: t,
contentDOM: r
};
}
}), Ci = A.create({
name: "blockGroup",
group: "childContainer",
content: "blockGroupChild+",
marks() {
return b(this.editor);
},
parseHTML() {
return [{
tag: "div",
getAttrs: (e) => typeof e != "string" && e.getAttribute("data-node-type") === "blockGroup" && null
}];
},
renderHTML({ HTMLAttributes: e }) {
let t = {
...this.options.domAttributes?.blockGroup || {},
...e
}, n = document.createElement("div");
n.className = s("bn-block-group", t.class), n.setAttribute("data-node-type", "blockGroup");
for (let [e, r] of Object.entries(t)) e !== "class" && n.setAttribute(e, r);
return {
dom: n,
contentDOM: n
};
}
}), wi = A.create({
name: "doc",
topNode: !0,
content: "blockGroup",
marks() {
return b(this.editor);
}
});
//#endregion
//#region src/editor/managers/ExtensionManager/extensions.ts
function Ti(t, n) {
return [
j.ClipboardTextSerializer,
j.Commands,
j.Editable,
j.FocusEvents,
j.Tabindex,
mt,
e.configure({
types: [
"blockContainer",
"columnList",
"column"
],
setIdAttribute: n.setIdAttribute,
isWithinEditor: t.isWithinEditor
}),
Pr,
pt,
...Object.values(t.schema.styleSpecs).map((e) => e.implementation.mark.configure({ editor: t })),
Hr,
Nr,
Vr,
k.create({
name: "OverrideEscape",
addKeyboardShortcuts: () => ({ Escape: () => !t.getExtension(ie)?.shown() && (t.blur(), !0) })
}),
wi,
Si.configure({
editor: t,
domAttributes: n.domAttributes
}),
Br.configure({
editor: t,
tabBehavior: n.tabBehavior
}),
Ci.configure({ domAttributes: n.domAttributes }),
...Object.values(t.schema.inlineContentSpecs).filter((e) => e.config !== "link" && e.config !== "text").map((e) => e.implementation.node.configure({ editor: t })),
...Object.values(t.schema.blockSpecs).flatMap((e) => [..."node" in e.implementation ? [e.implementation.node.configure({
editor: t,
domAttributes: n.domAttributes
})] : []]),
Mr(t),
Dr(t, n.pasteHandler || ((e) => e.defaultPasteHandler())),
ur(t)
];
}
function Ei(e, t) {
let n = [
be(),
ye(t),
fe(t),
x(t),
bi({
HTMLAttributes: t.links?.HTMLAttributes ?? {},
onClick: t.links?.onClick,
...t.links?.isValidLink ? { isValidLink: t.links.isValidLink } : {}
}),
xe(t),
we(),
Me(t),
Fe(t),
De(t),
Oe(),
Ae(),
ie(t),
ge(),
ke(),
_e(),
...t.trailingBlock === !1 ? [] : [je()]
];
return "table" in e.schema.blockSpecs && n.push(Ee(t)), t.animations !== !1 && n.push(Ce()), n;
}
//#endregion
//#region src/editor/managers/ExtensionManager/index.ts
var Di = class {
editor;
options;
disabledExtensions = /* @__PURE__ */ new Set();
extensions = [];
abortMap = /* @__PURE__ */ new Map();
extensionFactories = /* @__PURE__ */ new Map();
extensionPlugins = /* @__PURE__ */ new Map();
blockNoteExtensionDependents = /* @__PURE__ */ new Map();
constructor(e, t) {
this.editor = e, this.options = t, e.onMount(() => {
for (let t of this.extensions) if (t.mount) {
let n = new window.AbortController(), r = t.mount({
dom: e.prosemirrorView.dom,
root: e.prosemirrorView.root,
signal: n.signal
});
r && n.signal.addEventListener("abort", () => {
r();
}), this.abortMap.set(t, n);
}
}), e.onUnmount(() => {
for (let [e, t] of this.abortMap.entries()) this.abortMap.delete(e), t.abort();
}), this.disabledExtensions = new Set(t.disableExtensions || []);
for (let e of Ei(this.editor, this.options)) this.addExtension(e);
for (let e of this.options.extensions ?? []) this.addExtension(e);
for (let e of Object.values(this.editor.schema.blockSpecs)) for (let t of e.extensions ?? []) this.addExtension(t);
}
registerExtension(e) {
this.replaceExtension(void 0, e);
}
addExtension(e, t) {
let n;
if (n = typeof e == "function" ? e({ editor: this.editor }) : e, !(!n || this.disabledExtensions.has(n.key))) {
if (t) {
let e = this.blockNoteExtensionDependents.get(n.key);
e || (e = /* @__PURE__ */ new Set(), this.blockNoteExtensionDependents.set(n.key, e)), e.add(t);
}
if (!this.extensions.some((e) => e.key === n.key)) {
if (typeof e == "function") {
let e = n[me];
typeof e == "function" && this.extensionFactories.set(e, n);
}
if (this.extensions.push(n), n.blockNoteExtensions) for (let e of n.blockNoteExtensions) this.addExtension(e, n.key);
return n;
}
}
}
resolveExtensions(e) {
let t = [];
if (typeof e == "function") {
let n = this.extensionFactories.get(e);
n && t.push(n);
} else if (Array.isArray(e)) for (let n of e) t.push(...this.resolveExtensions(n));
else if (typeof e == "object" && "key" in e) t.push(e);
else if (typeof e == "string") {
let n = this.extensions.find((t) => t.key === e);
n && t.push(n);
}
return t;
}
unregisterExtension(e) {
this.replaceExtension(e, []);
}
replaceExtension(e, t) {
let n = this.resolveExtensions(e);
e && !n.length && console.warn("No extensions found to unregister", e);
let r = !1, i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
for (let t of n) this.extensions = this.extensions.filter((e) => e !== t), this.extensionFactories.forEach((e, n) => {
e === t && this.extensionFactories.delete(n);
}), this.abortMap.get(t)?.abort(), this.abortMap.delete(t), this.extensionPlugins.get(t)?.forEach((e) => {
i.add(e);
let t = e.spec?.key, n = typeof t == "object" && t ? t.key : t;
typeof n == "string" && a.add(n);
}), this.extensionPlugins.delete(t), t.tiptapExtensions && !r && (r = !0, console.warn(`Extension ${t.key} has tiptap extensions, but they will not be removed. Please separate the extension into multiple extensions if you want to remove them, or re-initialize the editor.`, e));
let o = [].concat(t).filter(Boolean).map((e) => this.addExtension(e)).filter(Boolean), s = [];
for (let e of o) e?.tiptapExtensions && console.warn(`Extension ${e.key} has tiptap extensions, but these cannot be changed after initializing the editor. Please separate the extension into multiple extensions if you want to add them, or re-initialize the editor.`, e), e?.inputRules?.length && console.warn(`Extension ${e.key} has input rules, but these cannot be changed after initializing the editor. Please separate the extension into multiple extensions if you want to add them, or re-initialize the editor.`, e), this.getProsemirrorPluginsFromExtension(e).plugins.forEach((e) => {
s.push(e);
});
!i.size && !a.size && !s.length || this.updatePlugins((e) => [...e.filter((e) => {
if (i.has(e)) return !1;
if (a.size) {
let t = e.spec?.key, n = typeof t == "object" && t ? t.key : t;
if (typeof n == "string" && a.has(n)) return !1;
}
return !0;
}), ...s]);
}
updatePlugins(e) {
let t = this.editor.prosemirrorState, n = t.reconfigure({ plugins: e(t.plugins.slice()) });
this.editor.prosemirrorView.updateState(n);
}
getTiptapExtensions() {
let e = Ti(this.editor, this.options).filter((e) => !this.disabledExtensions.has(e.name)), t = ee(this.extensions.map((e) => {
let t = this.blockNoteExtensionDependents.get(e.key);
return t?.size ? {
key: e.key,
runsBefore: [...e.runsBefore ?? [], ...t]
} : e;
})), n = /* @__PURE__ */ new Map();
for (let r of this.extensions) {
r.tiptapExtensions && e.push(...r.tiptapExtensions);
let i = t(r.key), { plugins: a, inputRules: o } = this.getProsemirrorPluginsFromExtension(r);
a.length && e.push(k.create({
name: r.key,
priority: i,
addProseMirrorPlugins: () => a
})), o.length && (n.has(i) || n.set(i, []), n.get(i).push(...o));
}
e.push(k.create({
name: "blocknote-input-rules",
addProseMirrorPlugins() {
let e = [];
Array.from(n.keys()).sort((e, t) => e - t).reverse().forEach((t) => {
e.push(...n.get(t));
});
let t = dt({ rules: e });
return [t, new P({ props: { handleKeyDown(e, n) {
if (n.key !== "Enter" || n.shiftKey || n.ctrlKey || n.metaKey || n.altKey) return !1;
let { $cursor: r } = e.state.selection;
return r ? !!t.props.handleTextInput?.call(t, e, r.pos, r.pos, "\n", () => e.state.tr.insertText("\n", r.pos, r.pos)) : !1;
} } })];
}
}));
for (let t of this.options._tiptapOptions?.extensions ?? []) e.push(t);
return e;
}
getProsemirrorPluginsFromExtension(e) {
let t = [...e.prosemirrorPlugins ?? []], n = [];
return !e.prosemirrorPlugins?.length && !Object.keys(e.keyboardShortcuts || {}).length && !e.inputRules?.length ? {
plugins: t,
inputRules: n
} : (this.extensionPlugins.set(e, t), e.inputRules?.length && n.push(...e.inputRules.map((e) => new ut(e.find, (t, n, r, i) => {
let a = e.replace({
match: n,
range: {
from: r,
to: i
},
editor: this.editor
});
if (a) {
let e = t.tr, n = w(e);
return !n.isBlockContainer || this.editor.schema.blockSchema[n.blockNoteType]?.content !== "inline" ? null : (e.deleteRange(r, i), f(e, n.bnBlock.beforePos, a), ar(e, C(n.bnBlock.node, e.doc), "start"), e);
}
return null;
}, { undoable: !0 }))), Object.keys(e.keyboardShortcuts || {}).length && t.push(ft(Object.fromEntries(Object.entries(e.keyboardShortcuts).map(([e, t]) => [e, () => t({ editor: this.editor })])))), {
plugins: t,
inputRules: n
});
}
getExtensions() {
return new Map(this.extensions.map((e) => [e.key, e]));
}
getExtension(e) {
if (typeof e == "string") return this.extensions.find((t) => t.key === e) || void 0;
if (typeof e == "function") return this.extensionFactories.get(e) || void 0;
throw Error(`Invalid extension type: ${typeof e}`);
}
hasExtension(e) {
return typeof e == "string" ? this.extensions.some((t) => t.key === e) : typeof e == "object" && "key" in e ? this.extensions.some((t) => t.key === e.key) : typeof e == "function" && this.extensionFactories.has(e);
}
};
//#endregion
//#region src/util/expandToWords.ts
function Oi(e, t) {
let { $from: n, $to: r } = t;
if (n.pos > n.start() && n.pos < e.content.size) {
let t = e.textBetween(n.pos, n.pos + 1);
if (/^[\w\p{P}]$/u.test(t)) {
let t = e.textBetween(n.start(), n.pos).match(/[\w\p{P}]+$/u);
t && (n = e.resolve(n.pos - t[0].length));
}
}
if (r.pos < r.end() && r.pos > 0) {
let t = e.textBetween(r.pos - 1, r.pos);
if (/^[\w\p{P}]$/u.test(t)) {
let t = e.textBetween(r.pos, r.end()).match(/^[\w\p{P}]+/u);
t && (r = e.resolve(r.pos + t[0].length));
}
}
return {
$from: n,
$to: r,
from: n.pos,
to: r.pos
};
}
//#endregion
//#region src/api/blockManipulation/selections/selection.ts
function ki(e) {
if (e.selection.empty || "node" in e.selection) return;
let t = e.doc.resolve(re(e.doc, e.selection.from).posBeforeNode), n = e.doc.resolve(re(e.doc, e.selection.to).posBeforeNode), r = (n, r) => {
let i = t.posAtIndex(n, r), a = e.doc.resolve(i).nodeAfter;
if (!a) throw Error(`Error getting selection - node not found at position ${i}`);
return g(a, e.doc);
}, i = [], a = t.sharedDepth(n.pos), o = t.index(a), s = n.index(a);
if (t.depth > a) {
i.push(g(t.nodeAfter, e.doc));
for (let e = t.depth; e > a; e--) if (t.node(e).type.isInGroup("childContainer")) {
let n = t.index(e) + 1, a = t.node(e).childCount;
for (let t = n; t < a; t++) i.push(r(t, e));
}
} else i.push(r(o, a));
for (let e = o + 1; e <= s; e++) i.push(r(e, a));
if (i.length === 0) throw Error(`Error getting selection - selection doesn't span any blocks (${e.selection})`);
return { blocks: i };
}
function Ai(e, t, n) {
let r = typeof t == "string" ? t : t.id, i = typeof n == "string" ? n : n.id, a = u(e), o = oe(a);
if (r === i) throw Error(`Attempting to set selection with the same anchor and head blocks (id ${r})`);
let s = p(r, e.doc);
if (!s) throw Error(`Block with ID ${r} not found`);
let c = p(i, e.doc);
if (!c) throw Error(`Block with ID ${i} not found`);
let l = v(s), d = v(c), f = o.blockSchema[l.blockNoteType], m = o.blockSchema[d.blockNoteType];
if (!l.isBlockContainer || f.content === "none") throw Error(`Attempting to set selection anchor in block without content (id ${r})`);
if (!d.isBlockContainer || m.content === "none") throw Error(`Attempting to set selection anchor in block without content (id ${i})`);
let h, g;
if (f.content === "table") {
let e = ot.get(l.blockContent.node);
h = l.blockContent.beforePos + e.positionAt(0, 0, l.blockContent.node) + 1 + 2;
} else h = l.blockContent.beforePos + 1;
if (m.content === "table") {
let t = ot.get(d.blockContent.node), n = d.blockContent.beforePos + t.positionAt(t.height - 1, t.width - 1, d.blockContent.node) + 1;
g = n + e.doc.resolve(n).nodeAfter.nodeSize - 2;
} else g = d.blockContent.afterPos - 1;
e.setSelection(F.create(e.doc, h, g));
}
function ji(e, t = !1) {
let r = t ? Oi(e.doc, e.selection) : e.selection, i = r.$from, a = r.$to;
for (; a.parentOffset >= a.parent.nodeSize - 2 && a.depth > 0;) a = e.doc.resolve(a.pos + 1);
for (; a.parentOffset === 0 && a.depth > 0;) a = e.doc.resolve(a.pos - 1);
for (; i.parentOffset === 0 && i.depth > 0;) i = e.doc.resolve(i.pos - 1);
for (; i.parentOffset >= i.parent.nodeSize - 2 && i.depth > 0;) i = e.doc.resolve(i.pos + 1);
let o = n(e.doc.slice(i.pos, a.pos, !0));
return {
_meta: {
startPos: i.pos,
endPos: a.pos
},
...o
};
}
//#endregion
//#region src/editor/managers/SelectionManager.ts
var Mi = class {
editor;
constructor(e) {
this.editor = e;
}
getSelection() {
return this.editor.transact((e) => ki(e));
}
getSelectionCutBlocks(e = !1) {
return this.editor.transact((t) => ji(t, e));
}
setSelection(e, t) {
return this.editor.transact((n) => Ai(n, e, t));
}
getTextCursorPosition() {
return this.editor.transact((e) => ir(e));
}
setTextCursorPosition(e, t = "start") {
return this.editor.transact((n) => ar(n, e, t));
}
getSelectionBoundingBox() {
if (!this.editor.prosemirrorView) return;
let { selection: e } = this.editor.prosemirrorState, { ranges: t } = e, n = Math.min(...t.map((e) => e.$from.pos)), r = Math.max(...t.map((e) => e.$to.pos));
if (et(e)) {
let e = this.editor.prosemirrorView.nodeDOM(n);
if (e) return e.getBoundingClientRect();
}
return nt(this.editor.prosemirrorView, n, r).toJSON();
}
}, Ni = class {
editor;
constructor(e) {
this.editor = e;
}
activeTransaction = null;
can(e) {
try {
return this.isInCan = !0, e();
} finally {
this.isInCan = !1;
}
}
isInCan = !1;
exec(e) {
if (this.activeTransaction) throw Error("`exec` should not be called within a `transact` call, move the `exec` call outside of the `transact` call");
if (this.isInCan) return this.canExec(e);
let t = this.prosemirrorState, n = this.prosemirrorView;
return e(t, (e) => this.prosemirrorView.dispatch(e), n);
}
canExec(e) {
if (this.activeTransaction) throw Error("`canExec` should not be called within a `transact` call, move the `canExec` call outside of the `transact` call");
let t = this.prosemirrorState, n = this.prosemirrorView;
return e(t, void 0, n);
}
transact(e) {
if (this.activeTransaction) return e(this.activeTransaction);
try {
this.activeTransaction = this.editor._tiptapEditor.state.tr;
let t = e(this.activeTransaction), n = this.activeTransaction;
return this.activeTransaction = null, n && (n.docChanged || n.selectionSet || n.scrolledIntoView || n.storedMarksSet || !n.isGeneric) && this.prosemirrorView.dispatch(n), t;
} finally {
this.activeTransaction = null;
}
}
get prosemirrorState() {
if (this.activeTransaction) throw Error("`prosemirrorState` should not be called within a `transact` call, move the `prosemirrorState` call outside of the `transact` call or use `editor.transact` to read the current editor state");
return this.editor._tiptapEditor.state;
}
get prosemirrorView() {
return this.editor._tiptapEditor.view;
}
isFocused() {
return this.prosemirrorView?.hasFocus() || !1;
}
focus() {
this.prosemirrorView?.focus();
}
get isEditable() {
if (!this.editor._tiptapEditor) {
if (!this.editor.headless) throw Error("no editor, but also not headless?");
return !1;
}
return this.editor._tiptapEditor.isEditable === void 0 || this.editor._tiptapEditor.isEditable;
}
set isEditable(e) {
if (!this.editor._tiptapEditor) {
if (!this.editor.headless) throw Error("no editor, but also not headless?");
return;
}
this.editor._tiptapEditor.options.editable !== e && this.editor._tiptapEditor.setEditable(e);
}
undo() {
let e = this.editor.getExtension("yUndo");
if (e) return this.exec(e.undoCommand);
let t = this.editor.getExtension("history");
if (t) return this.exec(t.undoCommand);
throw Error("No undo plugin found");
}
redo() {
let e = this.editor.getExtension("yUndo");
if (e) return this.exec(e.redoCommand);
let t = this.editor.getExtension("history");
if (t) return this.exec(t.redoCommand);
throw Error("No redo plugin found");
}
};
//#endregion
//#region src/api/blockManipulation/insertContentAt.ts
function Pi(e, t, n, r = { updateSelection: !0 }) {
let { from: i, to: a } = typeof t == "number" ? {
from: t,
to: t
} : {
from: t.from,
to: t.to
}, o = !0, s = !0, c = "";
if (n.forEach((e) => {
e.check(), o && e.isText && e.marks.length === 0 ? c += e.text : o = !1, s = s ? e.isBlock : !1;
}), i === a && s) {
let { parent: t } = e.doc.resolve(i);
t.isTextblock && !t.type.spec.code && !t.childCount && (--i, a += 1);
}
return o ? e.insertText(c, i, a) : e.replaceWith(i, a, n), r.updateSelection && rt(e, e.steps.length - 1, -1), !0;
}
//#endregion
//#region src/editor/managers/StyleManager.ts
var Fi = class {
editor;
constructor(e) {
this.editor = e;
}
insertInlineContent(e, { updateSelection: t = !1 } = {}) {
let n = l(e, this.editor.pmSchema);
this.editor.transact((e) => {
Pi(e, {
from: e.selection.from,
to: e.selection.to
}, n, { updateSelection: t });
});
}
getActiveStyles() {
return this.editor.transact((e) => {
let t = {}, n = e.selection.$to.marks();
for (let e of n) {
let n = this.editor.schema.styleSchema[e.type.name];
if (!n) {
e.type.name !== "link" && !e.type.spec.blocknoteIgnore && console.warn("mark not found in styleschema", e.type.name);
continue;
}
n.propSchema === "boolean" ? t[n.type] = !0 : t[n.type] = e.attrs.stringValue;
}
return t;
});
}
addStyles(e) {
for (let [t, n] of Object.entries(e)) {
let e = this.editor.schema.styleSchema[t];
if (!e) throw Error(`style ${t} not found in styleSchema`);
if (e.propSchema === "boolean") this.editor._tiptapEditor.commands.setMark(t);
else if (e.propSchema === "string") this.editor._tiptapEditor.commands.setMark(t, { stringValue: n });
else throw new _(e.propSchema);
}
}
removeStyles(e) {
for (let t of Object.keys(e)) this.editor._tiptapEditor.commands.unsetMark(t);
}
toggleStyles(e) {
for (let [t, n] of Object.entries(e)) {
let e = this.editor.schema.styleSchema[t];
if (!e) throw Error(`style ${t} not found in styleSchema`);
if (e.propSchema === "boolean") this.editor._tiptapEditor.commands.toggleMark(t);
else if (e.propSchema === "string") this.editor._tiptapEditor.commands.toggleMark(t, { stringValue: n });
else throw new _(e.propSchema);
}
}
getSelectedText() {
return this.editor.transact((e) => e.doc.textBetween(e.selection.from, e.selection.to));
}
getLinkMarkAtPos(e) {
return this.editor.transact((t) => {
let n = t.doc.resolve(e), r = n.marks().find((e) => e.type.name === "link");
if (!r) return;
let i = Ze(n, r.type);
if (i) return {
href: r.attrs.href,
from: i.from,
to: i.to,
text: t.doc.textBetween(i.from, i.to)
};
});
}
getSelectedLinkUrl() {
return this.editor.transact((e) => this.getLinkMarkAtPos(e.selection.from)?.href);
}
createLink(e, t) {
e !== "" && this.editor.transact((n) => {
let { from: r, to: i } = n.selection, a = this.editor.pmSchema.mark("link", { href: e });
t ? n.insertText(t, r, i).addMark(r, r + t.length, a) : n.addMark(r, i, a);
});
}
editLink(e, t, n = this.editor.transact((e) => e.selection.anchor)) {
this.editor.transact((r) => {
let { from: i, to: a } = this.getLinkMarkAtPos(n + 1) || {
from: r.selection.from,
to: r.selection.to
}, o = this.editor.pmSchema.mark("link", { href: e });
t !== r.doc.textBetween(i, a) && r.insertText(t, i, a), r.addMark(i, i + t.length, o);
}), this.editor.prosemirrorView.focus();
}
deleteLink(e = this.editor.transact((e) => e.selection.anchor)) {
this.editor.transact((t) => {
let { from: n, to: r } = this.getLinkMarkAtPos(e + 1) || {
from: t.selection.from,
to: t.selection.to
};
t.removeMark(n, r, this.editor.pmSchema.marks.link).setMeta("preventAutolink", !0);
}), this.editor.prosemirrorView.focus();
}
};
//#endregion
//#region src/editor/transformPasted.ts
function Ii(e) {
return Je(e.state.selection.$from, (e) => e.type.name === "tableCell" || e.type.name === "tableHeader") !== void 0;
}
function Li(e, t) {
let n = t.nodes.hardBreak, r = I.empty;
return e.forEach((e) => {
e.isTextblock && e.childCount > 0 ? (r = r.append(e.content), r = r.addToEnd(n.create())) : e.isText ? r = r.addToEnd(e) : e.isBlock && e.childCount > 0 && (r = r.append(Li(e.content, t)), r = r.addToEnd(n.create()));
}), r.lastChild?.type === n && (r = r.cut(0, r.size - 1)), r;
}
function Ri(e, t) {
let n = [];
return e.forEach((e, r, i) => {
i !== t && n.push(e);
}), I.from(n);
}
function zi(e, t) {
let n = [];
for (let r = 0; r < e.childCount; r++) if (e.child(r).type.name === "tableRow") {
if (n.length > 0 && n[n.length - 1].type.name === "table") {
let t = n[n.length - 1], i = t.copy(t.content.addToEnd(e.child(r)));
n[n.length - 1] = i;
} else {
let i = t.nodes.table.createChecked(void 0, e.child(r));
n.push(i);
}
} else n.push(e.child(r));
return e = I.from(n), e;
}
function Bi(e, t) {
let n = I.from(e.content);
n = zi(n, t.state.schema);
let r = Vi(n, t, e);
if (r) return r;
if (Ii(t)) {
let e = !1;
if (n.descendants((t) => {
t.type.isInGroup("tableContent") && (e = !0);
}), !e && !t.state.schema.nodes.tableParagraph.validContent(n)) return new L(Li(n, t.state.schema), 0, 0);
}
if (!Hi(n, t)) return new L(n, e.openStart, e.openEnd);
for (let e = 0; e < n.childCount; e++) if (n.child(e).type.spec.group === "blockContent") {
let r = [n.child(e)];
if (e + 1 < n.childCount && n.child(e + 1).type.name === "blockGroup") {
let t = n.child(e + 1).child(0).child(0);
(t.type.name === "bulletListItem" || t.type.name === "numberedListItem" || t.type.name === "checkListItem") && (r.push(n.child(e + 1)), n = Ri(n, e + 1));
}
let i = t.state.schema.nodes.blockContainer.createChecked(void 0, r);
n = n.replaceChild(e, i);
}
return new L(n, e.openStart, e.openEnd);
}
function Vi(e, t, n) {
if (Ii(t) || t.dragging) return null;
let r = w(t.state), i = r.isBlockContainer ? r.blockContent.node : null;
if (!i || i.type.name === "paragraph" || i.type.spec.content !== "inline*" || i.childCount > 0) return null;
let a = e.firstChild, o = a?.firstChild, s = o?.firstChild;
if (a?.type.name !== "blockGroup" || o?.type.name !== "blockContainer" || s?.type.name !== "paragraph") return null;
let c = i.type.create(i.attrs, s.content), l = o.copy(o.content.replaceChild(0, c)), u = a.copy(a.content.replaceChild(0, l));
return new L(e.replaceChild(0, u), n.openStart, n.openEnd);
}
function Hi(e, t) {
let n = e.childCount === 1, r = e.firstChild?.type.spec.content === "inline*", i = e.firstChild?.type.spec.content === "tableRow+";
if (n) {
if (r) return !1;
if (i) {
let e = w(t.state);
if (e.isBlockContainer) return e.blockContent.node.type.spec.content !== "tableRow+";
}
}
return !0;
}
//#endregion
//#region src/editor/BlockNoteEditor.ts
var Ui = {
enableInputRules: !0,
enablePasteRules: !0,
enableCoreExtensions: !1
}, Wi = class t extends H {
options;
pmSchema;
_tiptapEditor;
elementRenderer = null;
blockCache = /* @__PURE__ */ new WeakMap();
dictionary;
schema;
blockImplementations;
inlineContentImplementations;
styleImplementations;
uploadFile;
onUploadStartCallbacks = [];
onUploadEndCallbacks = [];
resolveFileUrl;
settings;
static create(e) {
return new t(e ?? {});
}
constructor(t) {
super(), this.options = t, this.dictionary = t.dictionary || Ie, this.settings = { tables: {
splitCells: t?.tables?.splitCells ?? !1,
cellBackgroundColor: t?.tables?.cellBackgroundColor ?? !1,
cellTextColor: t?.tables?.cellTextColor ?? !1,
headers: t?.tables?.headers ?? !1
} };
let n = {
defaultStyles: !0,
schema: t.schema || ce.create(),
...t,
placeholders: {
...this.dictionary.placeholders,
...t.placeholders
}
};
if (this.schema = n.schema, this.blockImplementations = n.schema.blockSpecs, this.inlineContentImplementations = n.schema.inlineContentSpecs, this.styleImplementations = n.schema.styleSpecs, n.uploadFile) {
let e = n.uploadFile;
this.uploadFile = async (t, n) => {
this.onUploadStartCallbacks.forEach((e) => e.apply(this, [n]));
try {
return await e(t, n);
} finally {
this.onUploadEndCallbacks.forEach((e) => e.apply(this, [n]));
}
};
}
this.resolveFileUrl = n.resolveFileUrl, this._eventManager = new on(this), this._extensionManager = new Di(this, n);
let r = this._extensionManager.getTiptapExtensions(), i = {
...Ui,
...n._tiptapOptions,
element: null,
autofocus: n.autofocus ?? !1,
extensions: r,
editorProps: {
scrollMargin: {
top: 72,
bottom: 72,
left: 0,
right: 0
},
...n._tiptapOptions?.editorProps,
attributes: {
tabIndex: "0",
...n._tiptapOptions?.editorProps?.attributes,
...n.domAttributes?.editor,
class: s("bn-editor", n.defaultStyles ? "bn-default-styles" : "", n.domAttributes?.editor?.class || "")
},
transformPasted: Bi
}
};
try {
let t = n.initialContent || [{
type: "paragraph",
id: e.options.generateID()
}];
if (!Array.isArray(t) || t.length === 0) throw Error("initialContent must be a non-empty array of blocks, received: " + JSON.stringify(t));
let r = $e(i.extensions);
r.cached.blockNoteEditor = this;
let a = t.map((e) => c(e, r, this.schema.styleSchema).toJSON()), o = Ke({
type: "doc",
content: [{
type: "blockGroup",
content: a
}]
}, r, i.parseOptions);
this._tiptapEditor = new Ue({
...i,
content: o.toJSON()
}), this.pmSchema = this._tiptapEditor.schema;
} catch (e) {
throw Error("Error creating document from blocks passed as `initialContent`", { cause: e });
}
this.pmSchema.cached.blockNoteEditor = this, this._tiptapEditor.on("mount", () => {
this.headless = !1;
}), this._tiptapEditor.on("unmount", () => {
this.headless = !0;
}), this._blockManager = new an(this), this._exportManager = new rr(this), this._selectionManager = new Mi(this), this._stateManager = new Ni(this), this._styleManager = new Fi(this), this.emit("create");
}
_blockManager;
_eventManager;
_exportManager;
_extensionManager;
_selectionManager;
_stateManager;
_styleManager;
get extensions() {
return this._extensionManager.getExtensions();
}
exec(e) {
return this._stateManager.exec(e);
}
canExec(e) {
return this._stateManager.canExec(e);
}
transact(e) {
return this._stateManager.transact(e);
}
unregisterExtension = (...e) => this._extensionManager.unregisterExtension(...e);
registerExtension = (...e) => this._extensionManager.registerExtension(...e);
replaceExtension = (...e) => this._extensionManager.replaceExtension(...e);
getExtension = ((e) => this._extensionManager.getExtension(e));
mount = (e, t) => {
let n = e.getRootNode(), r = typeof ShadowRoot < "u" && n instanceof ShadowRoot;
(t?.portalTarget ?? e.parentElement ?? (r ? n : document.body)).appendChild(this.portalElement), this._tiptapEditor.mount({ mount: e });
};
unmount = () => {
this.portalElement?.remove(), this._tiptapEditor.unmount();
};
get prosemirrorState() {
return this._stateManager.prosemirrorState;
}
get prosemirrorView() {
return this._stateManager.prosemirrorView;
}
get domElement() {
if (!this.headless) return this.prosemirrorView?.dom;
}
_portalElement;
get portalElement() {
if (typeof document > "u") throw Error("Portal element accessed, but not available in headless mode");
return this._portalElement ||= document.createElement("div"), this._portalElement;
}
isWithinEditor = (e) => !!(this.domElement?.parentElement?.contains(e) || this.portalElement?.contains(e));
isFocused() {
return this.headless ? !1 : this.prosemirrorView?.hasFocus() || !1;
}
headless = !0;
focus() {
this.headless || this.prosemirrorView.focus();
}
blur() {
this.headless || this.domElement?.blur();
}
onUploadStart(e) {
return this.onUploadStartCallbacks.push(e), () => {
let t = this.onUploadStartCallbacks.indexOf(e);
t > -1 && this.onUploadStartCallbacks.splice(t, 1);
};
}
onUploadEnd(e) {
return this.onUploadEndCallbacks.push(e), () => {
let t = this.onUploadEndCallbacks.indexOf(e);
t > -1 && this.onUploadEndCallbacks.splice(t, 1);
};
}
get topLevelBlocks() {
return this.document;
}
get document() {
return this._blockManager.document;
}
getBlock(e) {
return this._blockManager.getBlock(e);
}
getPrevBlock(e) {
return this._blockManager.getPrevBlock(e);
}
getNextBlock(e) {
return this._blockManager.getNextBlock(e);
}
getParentBlock(e) {
return this._blockManager.getParentBlock(e);
}
forEachBlock(e, t = !1) {
this._blockManager.forEachBlock(e, t);
}
onEditorContentChange(e) {
this._tiptapEditor.on("update", e);
}
onEditorSelectionChange(e) {
this._tiptapEditor.on("selectionUpdate", e);
}
onBeforeChange(e) {
return this._extensionManager.getExtension(be).subscribe(e);
}
getTextCursorPosition() {
return this._selectionManager.getTextCursorPosition();
}
setTextCursorPosition(e, t = "start") {
return this._selectionManager.setTextCursorPosition(e, t);
}
getSelection() {
return this._selectionManager.getSelection();
}
getSelectionCutBlocks(e = !1) {
return this._selectionManager.getSelectionCutBlocks(e);
}
setSelection(e, t) {
return this._selectionManager.setSelection(e, t);
}
get isEditable() {
return this._stateManager.isEditable;
}
set isEditable(e) {
this._stateManager.isEditable = e;
}
insertBlocks(e, t, n = "before") {
return this._blockManager.insertBlocks(e, t, n);
}
updateBlock(e, t) {
return this._blockManager.updateBlock(e, t);
}
removeBlocks(e) {
return this._blockManager.removeBlocks(e);
}
replaceBlocks(e, t) {
return this._blockManager.replaceBlocks(e, t);
}
undo() {
return this._stateManager.undo();
}
redo() {
return this._stateManager.redo();
}
insertInlineContent(e, { updateSelection: t = !1 } = {}) {
this._styleManager.insertInlineContent(e, { updateSelection: t });
}
getActiveStyles() {
return this._styleManager.getActiveStyles();
}
addStyles(e) {
this._styleManager.addStyles(e);
}
removeStyles(e) {
this._styleManager.removeStyles(e);
}
toggleStyles(e) {
this._styleManager.toggleStyles(e);
}
getSelectedText() {
return this._styleManager.getSelectedText();
}
getSelectedLinkUrl() {
return this._styleManager.getSelectedLinkUrl();
}
createLink(e, t) {
this._styleManager.createLink(e, t);
}
getLinkMarkAtPos(e) {
return this._styleManager.getLinkMarkAtPos(e);
}
editLink(e, t, n) {
this._styleManager.editLink(e, t, n);
}
deleteLink(e) {
this._styleManager.deleteLink(e);
}
canNestBlock() {
return this._blockManager.canNestBlock();
}
nestBlock() {
this._blockManager.nestBlock();
}
canUnnestBlock() {
return this._blockManager.canUnnestBlock();
}
unnestBlock() {
this._blockManager.unnestBlock();
}
moveBlocksUp(e) {
return this._blockManager.moveBlocksUp(e);
}
moveBlocksDown(e) {
return this._blockManager.moveBlocksDown(e);
}
blocksToHTMLLossy(e = this.document) {
return this._exportManager.blocksToHTMLLossy(e);
}
blocksToFullHTML(e = this.document) {
return this._exportManager.blocksToFullHTML(e);
}
tryParseHTMLToBlocks(e) {
return this._exportManager.tryParseHTMLToBlocks(e);
}
blocksToMarkdownLossy(e = this.document) {
return this._exportManager.blocksToMarkdownLossy(e);
}
tryParseMarkdownToBlocks(e) {
return this._exportManager.tryParseMarkdownToBlocks(e);
}
onChange(e, t) {
return this._eventManager.onChange(e, t);
}
onSelectionChange(e, t) {
return this._eventManager.onSelectionChange(e, t);
}
onMount(e) {
return this._eventManager.onMount(e);
}
onUnmount(e) {
return this._eventManager.onUnmount(e);
}
getSelectionBoundingBox() {
return this._selectionManager.getSelectionBoundingBox();
}
get isEmpty() {
let e = this.document;
return e.length === 0 || e.length === 1 && e[0].type === "paragraph" && e[0].content.length === 0;
}
pasteHTML(e, t = !1) {
this._exportManager.pasteHTML(e, t);
}
pasteText(e) {
return this._exportManager.pasteText(e);
}
pasteMarkdown(e) {
return this._exportManager.pasteMarkdown(e);
}
}, Gi = class {
mappings;
options;
constructor(e, t, n) {
this.mappings = t, this.options = n;
}
get dictionary() {
return this.options.dictionary?.exporter ?? Ie.exporter;
}
async resolveFile(e) {
if (!this.options?.resolveFileUrl) return (await fetch(e)).blob();
let t = await this.options.resolveFileUrl(e);
return t instanceof Blob ? t : (await fetch(t)).blob();
}
mapStyles(e) {
return Object.entries(e).map(([e, t]) => {
let n = this.mappings.styleMapping[e];
if (!n) throw Error(`Exporter is missing a style mapping for style "${e}". If this style comes from a separate package, spread that package's exporter mappings into your styleMapping.`);
return n(t, this);
});
}
mapInlineContent(e) {
let t = this.mappings.inlineContentMapping[e.type];
if (!t) throw Error(`Exporter is missing an inline content mapping for inline content type "${e.type}". If this inline content comes from a separate package, spread that package's exporter mappings into your inlineContentMapping.`);
return t(e, this);
}
transformInlineContent(e) {
return e.map((e) => this.mapInlineContent(e));
}
async mapBlock(e, t, n, r) {
let i = this.mappings.blockMapping[e.type];
if (!i) throw Error(`Exporter is missing a block mapping for block type "${e.type}". If this block comes from a separate package, spread that package's exporter mappings into your blockMapping.`);
return i(e, this, t, n, r);
}
};
//#endregion
//#region src/exporter/ExportImage.ts
function Ki(e) {
if ("toBase64" in e && typeof e.toBase64 == "function") return e.toBase64();
let t = "";
for (let n of e) t += String.fromCharCode(n);
return btoa(t);
}
function qi(e) {
return `data:${e.mimeType};base64,${Ki(e.data)}`;
}
//#endregion
//#region src/exporter/mapping.ts
function Ji(e) {
return {
createBlockMapping: (e) => e,
createInlineContentMapping: (e) => e,
createStyleMapping: (e) => e
};
}
//#endregion
//#region src/util/combineByGroup.ts
function Yi(e, ...t) {
let n = [...e];
for (let e of t) for (let t of e) {
let e = n.findLastIndex((e) => e.group === t.group);
e === -1 ? n.push(t) : n.splice(e + 1, 0, t);
}
return n;
}
//#endregion
export { ht as A, B as C, xt as D, St as E, bt as O, Nt as S, R as T, It as _, Gi as a, V as b, kr as c, G as d, en as f, H as g, tn as h, qi as i, yt as k, nr as l, rn as m, Ji as n, Wi as o, nn as p, Ki as r, Oi as s, Yi as t, tr as u, Lt as v, z as w, Rt as x, Ft as y };
//# sourceMappingURL=src-BkfZVfaO.js.map