@blocknote/core 0.47.3 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/dist/BlockNoteExtension-B6RhuQ3V.js +27 -0
  2. package/dist/BlockNoteExtension-B6RhuQ3V.js.map +1 -0
  3. package/dist/BlockNoteExtension-ab0REuob.cjs +2 -0
  4. package/dist/BlockNoteExtension-ab0REuob.cjs.map +1 -0
  5. package/dist/EventEmitter-CuPnGDYt.js +22 -0
  6. package/dist/EventEmitter-CuPnGDYt.js.map +1 -0
  7. package/dist/EventEmitter-DHdSnYCD.cjs +2 -0
  8. package/dist/EventEmitter-DHdSnYCD.cjs.map +1 -0
  9. package/dist/ShowSelection-BsHFfdMi.js +29 -0
  10. package/dist/ShowSelection-BsHFfdMi.js.map +1 -0
  11. package/dist/ShowSelection-DhXglbt8.cjs +2 -0
  12. package/dist/ShowSelection-DhXglbt8.cjs.map +1 -0
  13. package/dist/blocknote.cjs +1 -5
  14. package/dist/blocknote.js +7 -4256
  15. package/dist/blocks-BEvIOzln.cjs +11 -0
  16. package/dist/blocks-BEvIOzln.cjs.map +1 -0
  17. package/dist/blocks-DYl7UTS4.js +3313 -0
  18. package/dist/blocks-DYl7UTS4.js.map +1 -0
  19. package/dist/blocks.cjs +1 -2
  20. package/dist/blocks.js +2 -74
  21. package/dist/comments.cjs +2 -2
  22. package/dist/comments.cjs.map +1 -1
  23. package/dist/comments.js +604 -900
  24. package/dist/comments.js.map +1 -1
  25. package/dist/en-C4ykW581.cjs +2 -0
  26. package/dist/en-C4ykW581.cjs.map +1 -0
  27. package/dist/en-QsSI16s5.js +453 -0
  28. package/dist/en-QsSI16s5.js.map +1 -0
  29. package/dist/extensions-3nf9PPhA.js +1495 -0
  30. package/dist/extensions-3nf9PPhA.js.map +1 -0
  31. package/dist/extensions-D9y6evn6.cjs +2 -0
  32. package/dist/extensions-D9y6evn6.cjs.map +1 -0
  33. package/dist/extensions.cjs +1 -2
  34. package/dist/extensions.js +4 -36
  35. package/dist/locales.cjs +2 -2
  36. package/dist/locales.cjs.map +1 -1
  37. package/dist/locales.js +10049 -9111
  38. package/dist/locales.js.map +1 -1
  39. package/dist/src-BKJH7Jla.cjs +5 -0
  40. package/dist/src-BKJH7Jla.cjs.map +1 -0
  41. package/dist/src-Hjv1f5lc.js +2386 -0
  42. package/dist/src-Hjv1f5lc.js.map +1 -0
  43. package/dist/style.css +2 -1
  44. package/dist/webpack-stats.json +1 -1
  45. package/dist/yjs.cjs +2 -2
  46. package/dist/yjs.cjs.map +1 -1
  47. package/dist/yjs.js +20 -38
  48. package/dist/yjs.js.map +1 -1
  49. package/package.json +8 -8
  50. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +15 -1
  51. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +5 -0
  52. package/src/api/blockManipulation/commands/nestBlock/__snapshots__/nestBlock.test.ts.snap +1095 -0
  53. package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +661 -0
  54. package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +128 -11
  55. package/src/blocks/File/helpers/render/createResizableFileBlockWrapper.ts +17 -23
  56. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +346 -0
  57. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +143 -71
  58. package/src/editor/Block.css +5 -8
  59. package/src/editor/BlockNoteEditor.ts +38 -1
  60. package/src/editor/editor.css +0 -20
  61. package/src/editor/managers/ExtensionManager/extensions.ts +12 -1
  62. package/src/editor/performance.test.ts +134 -0
  63. package/src/extensions/Collaboration/ForkYDoc.test.ts +115 -103
  64. package/src/extensions/Placeholder/Placeholder.ts +1 -1
  65. package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +86 -0
  66. package/src/extensions/PreviousBlockType/PreviousBlockType.ts +33 -49
  67. package/src/extensions/SideMenu/SideMenu.ts +14 -8
  68. package/src/extensions/TableHandles/TableHandles.ts +14 -0
  69. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +57 -17
  70. package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +9 -8
  71. package/src/index.ts +1 -1
  72. package/src/schema/blocks/createSpec.ts +6 -2
  73. package/src/schema/inlineContent/types.ts +0 -1
  74. package/src/vite-env.d.ts +6 -0
  75. package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.d.ts +14 -1
  76. package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.test.d.ts +1 -0
  77. package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.d.ts +1 -0
  78. package/types/src/editor/BlockNoteEditor.d.ts +13 -0
  79. package/types/src/editor/performance.test.d.ts +1 -0
  80. package/types/src/extensions/PreviousBlockType/PreviousBlockType.test.d.ts +1 -0
  81. package/types/src/extensions/SideMenu/SideMenu.d.ts +6 -0
  82. package/types/src/extensions/TableHandles/TableHandles.d.ts +6 -0
  83. package/dist/BlockNoteExtension-BWw0r8Gy.cjs +0 -2
  84. package/dist/BlockNoteExtension-BWw0r8Gy.cjs.map +0 -1
  85. package/dist/BlockNoteExtension-C2X7LW-V.js +0 -25
  86. package/dist/BlockNoteExtension-C2X7LW-V.js.map +0 -1
  87. package/dist/BlockNoteSchema-CCs_V3lo.cjs +0 -2
  88. package/dist/BlockNoteSchema-CCs_V3lo.cjs.map +0 -1
  89. package/dist/BlockNoteSchema-ooiKsd5B.js +0 -270
  90. package/dist/BlockNoteSchema-ooiKsd5B.js.map +0 -1
  91. package/dist/EventEmitter-CLwfmbqG.cjs +0 -2
  92. package/dist/EventEmitter-CLwfmbqG.cjs.map +0 -1
  93. package/dist/EventEmitter-CjSwpTbz.js +0 -27
  94. package/dist/EventEmitter-CjSwpTbz.js.map +0 -1
  95. package/dist/ShowSelection-B0ch3unP.js +0 -51
  96. package/dist/ShowSelection-B0ch3unP.js.map +0 -1
  97. package/dist/ShowSelection-BxnbRvy4.cjs +0 -2
  98. package/dist/ShowSelection-BxnbRvy4.cjs.map +0 -1
  99. package/dist/TrailingNode-GzE59m_7.js +0 -2288
  100. package/dist/TrailingNode-GzE59m_7.js.map +0 -1
  101. package/dist/TrailingNode-n0WdMPUl.cjs +0 -2
  102. package/dist/TrailingNode-n0WdMPUl.cjs.map +0 -1
  103. package/dist/blockToNode-BNoNIXU7.js +0 -1140
  104. package/dist/blockToNode-BNoNIXU7.js.map +0 -1
  105. package/dist/blockToNode-CumVjgem.cjs +0 -7
  106. package/dist/blockToNode-CumVjgem.cjs.map +0 -1
  107. package/dist/blocknote.cjs.map +0 -1
  108. package/dist/blocknote.js.map +0 -1
  109. package/dist/blocks.cjs.map +0 -1
  110. package/dist/blocks.js.map +0 -1
  111. package/dist/defaultBlocks-Dg9kQWXm.cjs +0 -6
  112. package/dist/defaultBlocks-Dg9kQWXm.cjs.map +0 -1
  113. package/dist/defaultBlocks-ZzGbYgQn.js +0 -3284
  114. package/dist/defaultBlocks-ZzGbYgQn.js.map +0 -1
  115. package/dist/en-Cl87Uuyf.cjs +0 -2
  116. package/dist/en-Cl87Uuyf.cjs.map +0 -1
  117. package/dist/en-njEqD7AG.js +0 -408
  118. package/dist/en-njEqD7AG.js.map +0 -1
  119. package/dist/extensions.cjs.map +0 -1
  120. package/dist/extensions.js.map +0 -1
  121. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,1495 @@
1
+ import { At as e, Bt as t, Dt as n, Et as r, Ft as i, It as a, Lt as o, Mt as s, Nt as c, Pt as l, Rn as u, Rt as d, an as f, dn as p, g as m, h, ht as g, in as _, jt as ee, kt as te, r as ne, zt as re } from "./blocks-DYl7UTS4.js";
2
+ import { n as v, t as y } from "./BlockNoteExtension-B6RhuQ3V.js";
3
+ import { DOMSerializer as ie, Fragment as b, Slice as ae } from "prosemirror-model";
4
+ import { dropPoint as oe } from "prosemirror-transform";
5
+ import { combineTransactionSteps as se, findChildrenInRange as x, getMarkRange as ce, posToDOMRect as le } from "@tiptap/core";
6
+ import { NodeSelection as S, Plugin as C, PluginKey as w, Selection as T, TextSelection as E } from "prosemirror-state";
7
+ import { v4 as ue } from "uuid";
8
+ import { DOMParser as de, Slice as fe } from "@tiptap/pm/model";
9
+ import { CellSelection as pe, addColumnAfter as me, addColumnBefore as he, addRowAfter as ge, addRowBefore as _e, deleteColumn as ve, deleteRow as ye, mergeCells as be, splitCell as xe } from "prosemirror-tables";
10
+ import { Plugin as D, PluginKey as O, TextSelection as Se } from "@tiptap/pm/state";
11
+ import { Decoration as k, DecorationSet as A } from "prosemirror-view";
12
+ import { defaultSelectionBuilder as Ce, redoCommand as we, undoCommand as Te, yCursorPlugin as Ee, ySyncPlugin as De, yUndoPlugin as Oe, yUndoPluginKey as ke } from "y-prosemirror";
13
+ import Ae from "fast-deep-equal";
14
+ import * as j from "yjs";
15
+ import { history as je, redo as Me, undo as Ne } from "@tiptap/pm/history";
16
+ import Pe from "rehype-parse";
17
+ import Fe from "rehype-remark";
18
+ import Ie from "remark-gfm";
19
+ import Le from "remark-stringify";
20
+ import { unified as Re } from "unified";
21
+ import { fromDom as ze } from "hast-util-from-dom";
22
+ import { visit as Be } from "unist-util-visit";
23
+ //#region src/api/exporters/html/util/serializeBlocksExternalHTML.ts
24
+ function Ve(e) {
25
+ let t = Array.from(e.classList).filter((e) => !e.startsWith("bn-")) || [];
26
+ t.length > 0 ? e.className = t.join(" ") : e.removeAttribute("class");
27
+ }
28
+ function He(t, n, r, i) {
29
+ let a;
30
+ if (!n) throw Error("blockContent is required");
31
+ if (typeof n == "string") a = te([n], t.pmSchema);
32
+ else if (Array.isArray(n)) a = te(n, t.pmSchema);
33
+ else if (n.type === "tableContent") a = e(n, t.pmSchema);
34
+ else throw new u(n.type);
35
+ let o = (i?.document ?? document).createDocumentFragment();
36
+ for (let e of a) if (e.type.name !== "text" && t.schema.inlineContentSchema[e.type.name]) {
37
+ let n = t.schema.inlineContentSpecs[e.type.name].implementation;
38
+ if (n) {
39
+ let a = f(e, t.schema.inlineContentSchema, t.schema.styleSchema), s = n.toExternalHTML ? n.toExternalHTML(a, t) : n.render.call({
40
+ renderType: "dom",
41
+ props: void 0
42
+ }, a, () => {}, t);
43
+ if (s) {
44
+ if (o.appendChild(s.dom), s.contentDOM) {
45
+ let t = r.serializeFragment(e.content, i);
46
+ s.contentDOM.dataset.editable = "", s.contentDOM.appendChild(t);
47
+ }
48
+ continue;
49
+ }
50
+ }
51
+ } else if (e.type.name === "text") {
52
+ let n = document.createTextNode(e.textContent);
53
+ for (let r of e.marks.toReversed()) if (r.type.name in t.schema.styleSpecs) {
54
+ let e = (t.schema.styleSpecs[r.type.name].implementation.toExternalHTML ?? t.schema.styleSpecs[r.type.name].implementation.render)(r.attrs.stringValue, t);
55
+ e.contentDOM.appendChild(n), n = e.dom;
56
+ } else {
57
+ let e = r.type.spec.toDOM(r, !0), t = ie.renderSpec(document, e);
58
+ t.contentDOM.appendChild(n), n = t.dom;
59
+ }
60
+ o.appendChild(n);
61
+ } else {
62
+ let t = r.serializeFragment(b.from([e]), i);
63
+ o.appendChild(t);
64
+ }
65
+ return o.childNodes.length === 1 && o.firstChild?.nodeType === 1 && Ve(o.firstChild), o;
66
+ }
67
+ function Ue(e, t, n, r, i, a, o, s) {
68
+ let c = s?.document ?? document, l = t.pmSchema.nodes.blockContainer, u = n.props || {};
69
+ for (let [e, r] of Object.entries(t.schema.blockSchema[n.type].propSchema)) !(e in u) && r.default !== void 0 && (u[e] = r.default);
70
+ let d = l.spec?.toDOM?.(l.create({
71
+ id: n.id,
72
+ ...u
73
+ })), f = Array.from(d.dom.attributes), p = t.blockImplementations[n.type].implementation, m = p.toExternalHTML?.call({}, {
74
+ ...n,
75
+ props: u
76
+ }, t, { nestingLevel: o }) || p.render.call({}, {
77
+ ...n,
78
+ props: u
79
+ }, t), h = c.createDocumentFragment();
80
+ if (m.dom.classList.contains("bn-block-content")) {
81
+ let e = [...f, ...Array.from(m.dom.attributes)].filter((e) => e.name.startsWith("data") && e.name !== "data-content-type" && e.name !== "data-file-block" && e.name !== "data-node-view-wrapper" && e.name !== "data-node-type" && e.name !== "data-id" && e.name !== "data-editable");
82
+ for (let t of e) m.dom.firstChild.setAttribute(t.name, t.value);
83
+ Ve(m.dom.firstChild), o > 0 && m.dom.firstChild.setAttribute("data-nesting-level", o.toString()), h.append(...Array.from(m.dom.childNodes));
84
+ } else h.append(m.dom), o > 0 && m.dom.setAttribute("data-nesting-level", o.toString());
85
+ if (m.contentDOM && n.content) {
86
+ let e = He(t, n.content, r, s);
87
+ m.contentDOM.appendChild(e);
88
+ }
89
+ let g;
90
+ if (i.has(n.type) ? g = "OL" : a.has(n.type) && (g = "UL"), g) {
91
+ if (e.lastChild?.nodeName !== g) {
92
+ let t = c.createElement(g);
93
+ g === "OL" && "start" in u && u.start && u?.start !== 1 && t.setAttribute("start", u.start + ""), e.append(t);
94
+ }
95
+ e.lastChild.appendChild(h);
96
+ } else e.append(h);
97
+ if (n.children && n.children.length > 0) {
98
+ let l = c.createDocumentFragment();
99
+ if (We(l, t, n.children, r, i, a, o + 1, s), e.lastChild?.nodeName === "UL" || e.lastChild?.nodeName === "OL") for (; l.firstChild?.nodeName === "UL" || l.firstChild?.nodeName === "OL";) e.lastChild.lastChild.appendChild(l.firstChild);
100
+ "childrenDOM" in m && m.childrenDOM ? m.childrenDOM.append(l) : t.pmSchema.nodes[n.type].isInGroup("blockContent") ? e.append(l) : m.contentDOM?.append(l);
101
+ }
102
+ }
103
+ var We = (e, t, n, r, i, a, o = 0, s) => {
104
+ for (let c of n) Ue(e, t, c, r, i, a, o, s);
105
+ }, Ge = (e, t, n, r, i, a) => {
106
+ let o = (a?.document ?? document).createDocumentFragment();
107
+ return We(o, e, t, n, r, i, 0, a), o;
108
+ }, M = (e, t) => {
109
+ let n = ie.fromSchema(e);
110
+ return {
111
+ exportBlocks: (e, r) => {
112
+ let i = Ge(t, e, n, new Set(["numberedListItem"]), new Set([
113
+ "bulletListItem",
114
+ "checkListItem",
115
+ "toggleListItem"
116
+ ]), r), a = document.createElement("div");
117
+ return a.append(i), a.innerHTML;
118
+ },
119
+ exportInlineContent: (e, r) => {
120
+ let i = He(t, e, n, r), a = document.createElement("div");
121
+ return a.append(i.cloneNode(!0)), a.innerHTML;
122
+ }
123
+ };
124
+ };
125
+ //#endregion
126
+ //#region src/api/getBlocksChangedByTransaction.ts
127
+ function Ke(e, t) {
128
+ if (t === 0) return;
129
+ let r = e.resolve(t);
130
+ for (let e = r.depth; e > 0; e--) {
131
+ let t = r.node(e);
132
+ if (n(t)) return t.attrs.id;
133
+ }
134
+ }
135
+ function qe(e) {
136
+ return e.getMeta("paste") ? { type: "paste" } : e.getMeta("uiEvent") === "drop" ? { type: "drop" } : e.getMeta("history$") ? { type: e.getMeta("history$").redo ? "redo" : "undo" } : e.getMeta("y-sync$") ? e.getMeta("y-sync$").isUndoRedoOperation ? { type: "undo-redo" } : { type: "yjs-remote" } : { type: "local" };
137
+ }
138
+ function Je(e) {
139
+ let t = {}, r = {}, i = p(e);
140
+ return e.descendants((a, o) => {
141
+ if (!n(a)) return !0;
142
+ let s = Ke(e, o), c = s ?? "__root__";
143
+ r[c] || (r[c] = []);
144
+ let l = _(a, i);
145
+ return t[a.attrs.id] = {
146
+ block: l,
147
+ parentId: s
148
+ }, r[c].push(a.attrs.id), !0;
149
+ }), {
150
+ byId: t,
151
+ childrenByParent: r
152
+ };
153
+ }
154
+ function Ye(e, t) {
155
+ let n = /* @__PURE__ */ new Set();
156
+ if (!e || !t) return n;
157
+ let r = new Set(e), i = t.filter((e) => r.has(e)), a = e.filter((e) => i.includes(e));
158
+ if (a.length <= 1 || i.length <= 1) return n;
159
+ let o = {};
160
+ for (let e = 0; e < a.length; e++) o[a[e]] = e;
161
+ let s = i.map((e) => o[e]), c = s.length, l = [], u = [], d = Array(c).fill(-1), f = (e, t) => {
162
+ let n = 0, r = e.length;
163
+ for (; n < r;) {
164
+ let i = n + r >>> 1;
165
+ e[i] < t ? n = i + 1 : r = i;
166
+ }
167
+ return n;
168
+ };
169
+ for (let e = 0; e < c; e++) {
170
+ let t = s[e], n = f(l, t);
171
+ n > 0 && (d[e] = u[n - 1]), n === l.length ? (l.push(t), u.push(e)) : (l[n] = t, u[n] = e);
172
+ }
173
+ let p = /* @__PURE__ */ new Set(), m = u[u.length - 1] ?? -1;
174
+ for (; m !== -1;) p.add(m), m = d[m];
175
+ for (let e = 0; e < i.length; e++) p.has(e) || n.add(i[e]);
176
+ return n;
177
+ }
178
+ function N(e, t = []) {
179
+ let n = qe(e), r = se(e.before, [e, ...t]), i = Je(r.before), a = Je(r.doc), o = [], s = /* @__PURE__ */ new Set();
180
+ Object.keys(a.byId).filter((e) => !(e in i.byId)).forEach((e) => {
181
+ o.push({
182
+ type: "insert",
183
+ block: a.byId[e].block,
184
+ source: n,
185
+ prevBlock: void 0
186
+ }), s.add(e);
187
+ }), Object.keys(i.byId).filter((e) => !(e in a.byId)).forEach((e) => {
188
+ o.push({
189
+ type: "delete",
190
+ block: i.byId[e].block,
191
+ source: n,
192
+ prevBlock: void 0
193
+ }), s.add(e);
194
+ }), Object.keys(a.byId).filter((e) => e in i.byId).forEach((e) => {
195
+ let t = i.byId[e], r = a.byId[e];
196
+ t.parentId === r.parentId ? Ae({
197
+ ...t.block,
198
+ children: void 0
199
+ }, {
200
+ ...r.block,
201
+ children: void 0
202
+ }) || (o.push({
203
+ type: "update",
204
+ block: r.block,
205
+ prevBlock: t.block,
206
+ source: n
207
+ }), s.add(e)) : (o.push({
208
+ type: "move",
209
+ block: r.block,
210
+ prevBlock: t.block,
211
+ source: n,
212
+ prevParent: t.parentId ? i.byId[t.parentId]?.block : void 0,
213
+ currentParent: r.parentId ? a.byId[r.parentId]?.block : void 0
214
+ }), s.add(e));
215
+ });
216
+ let c = i.childrenByParent, l = a.childrenByParent, u = new Set([...Object.keys(c), ...Object.keys(l)]), d = /* @__PURE__ */ new Set();
217
+ return u.forEach((e) => {
218
+ let t = Ye(c[e], l[e]);
219
+ t.size !== 0 && t.forEach((t) => {
220
+ let r = i.byId[t], c = a.byId[t];
221
+ !r || !c || r.parentId === c.parentId && (s.has(t) || (r.parentId ?? "__root__") === e && (d.has(t) || (d.add(t), o.push({
222
+ type: "move",
223
+ block: c.block,
224
+ prevBlock: r.block,
225
+ source: n,
226
+ prevParent: r.parentId ? i.byId[r.parentId]?.block : void 0,
227
+ currentParent: c.parentId ? a.byId[c.parentId]?.block : void 0
228
+ }), s.add(t))));
229
+ });
230
+ }), o;
231
+ }
232
+ //#endregion
233
+ //#region src/extensions/BlockChange/BlockChange.ts
234
+ var Xe = y(() => {
235
+ let e = [];
236
+ return {
237
+ key: "blockChange",
238
+ prosemirrorPlugins: [new C({
239
+ key: new w("blockChange"),
240
+ filterTransaction: (t) => {
241
+ let n;
242
+ return e.reduce((e, r) => e === !1 ? e : r({
243
+ getChanges() {
244
+ return n || (n = N(t), n);
245
+ },
246
+ tr: t
247
+ }) !== !1, !0);
248
+ }
249
+ })],
250
+ subscribe(t) {
251
+ return e.push(t), () => {
252
+ e.splice(e.indexOf(t), 1);
253
+ };
254
+ }
255
+ };
256
+ });
257
+ //#endregion
258
+ //#region src/extensions/Collaboration/YCursorPlugin.ts
259
+ function P(e) {
260
+ let t = e.charAt(0) === "#" ? e.substring(1, 7) : e, n = parseInt(t.substring(0, 2), 16), r = parseInt(t.substring(2, 4), 16), i = parseInt(t.substring(4, 6), 16), a = [
261
+ n / 255,
262
+ r / 255,
263
+ i / 255
264
+ ].map((e) => e <= .03928 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4);
265
+ return .2126 * a[0] + .7152 * a[1] + .0722 * a[2] <= .179;
266
+ }
267
+ function Ze(e) {
268
+ let t = document.createElement("span");
269
+ t.classList.add("bn-collaboration-cursor__base");
270
+ let n = document.createElement("span");
271
+ n.setAttribute("contentedEditable", "false"), n.classList.add("bn-collaboration-cursor__caret"), n.setAttribute("style", `background-color: ${e.color}; color: ${P(e.color) ? "white" : "black"}`);
272
+ let r = document.createElement("span");
273
+ return r.classList.add("bn-collaboration-cursor__label"), r.setAttribute("style", `background-color: ${e.color}; color: ${P(e.color) ? "white" : "black"}`), r.insertBefore(document.createTextNode(e.name), null), n.insertBefore(r, null), t.insertBefore(document.createTextNode("⁠"), null), t.insertBefore(n, null), t.insertBefore(document.createTextNode("⁠"), null), t;
274
+ }
275
+ var F = y(({ options: e }) => {
276
+ let t = /* @__PURE__ */ new Map(), n = e.provider && "awareness" in e.provider && typeof e.provider.awareness == "object" ? e.provider.awareness : void 0;
277
+ return n && ("setLocalStateField" in n && typeof n.setLocalStateField == "function" && n.setLocalStateField("user", e.user), "on" in n && typeof n.on == "function" && e.showCursorLabels !== "always" && n.on("change", ({ updated: e }) => {
278
+ for (let n of e) {
279
+ let e = t.get(n);
280
+ e && (setTimeout(() => {
281
+ e.element.setAttribute("data-active", "");
282
+ }, 10), e.hideTimeout && clearTimeout(e.hideTimeout), t.set(n, {
283
+ element: e.element,
284
+ hideTimeout: setTimeout(() => {
285
+ e.element.removeAttribute("data-active");
286
+ }, 2e3)
287
+ }));
288
+ }
289
+ })), {
290
+ key: "yCursor",
291
+ prosemirrorPlugins: [n ? Ee(n, {
292
+ selectionBuilder: Ce,
293
+ cursorBuilder(n, r) {
294
+ let i = t.get(r);
295
+ if (!i) {
296
+ let a = (e.renderCursor ?? Ze)(n);
297
+ e.showCursorLabels !== "always" && (a.addEventListener("mouseenter", () => {
298
+ let e = t.get(r);
299
+ e.element.setAttribute("data-active", ""), e.hideTimeout && (clearTimeout(e.hideTimeout), t.set(r, {
300
+ element: e.element,
301
+ hideTimeout: void 0
302
+ }));
303
+ }), a.addEventListener("mouseleave", () => {
304
+ let e = t.get(r);
305
+ t.set(r, {
306
+ element: e.element,
307
+ hideTimeout: setTimeout(() => {
308
+ e.element.removeAttribute("data-active");
309
+ }, 2e3)
310
+ });
311
+ })), i = {
312
+ element: a,
313
+ hideTimeout: void 0
314
+ }, t.set(r, i);
315
+ }
316
+ return i.element;
317
+ }
318
+ }) : void 0].filter(Boolean),
319
+ dependsOn: ["ySync"],
320
+ updateUser(e) {
321
+ n?.setLocalStateField("user", e);
322
+ }
323
+ };
324
+ }), I = y(({ options: e }) => ({
325
+ key: "ySync",
326
+ prosemirrorPlugins: [De(e.fragment)],
327
+ runsBefore: ["default"]
328
+ })), L = y(() => ({
329
+ key: "yUndo",
330
+ prosemirrorPlugins: [Oe()],
331
+ dependsOn: ["yCursor", "ySync"],
332
+ undoCommand: Te,
333
+ redoCommand: we
334
+ }));
335
+ //#endregion
336
+ //#region src/extensions/Collaboration/ForkYDoc.ts
337
+ function Qe(e, t) {
338
+ let n = e.doc;
339
+ if (e._item === null) {
340
+ let r = Array.from(n.share.keys()).find((t) => n.share.get(t) === e);
341
+ if (r == null) throw Error("type does not exist in other ydoc");
342
+ return t.get(r, e.constructor);
343
+ } else {
344
+ let n = e._item, r = t.store.clients.get(n.id.client) ?? [];
345
+ return r[j.findIndexSS(r, n.id.clock)].content.type;
346
+ }
347
+ }
348
+ var $e = y(({ editor: e, options: t }) => {
349
+ let n, r = v({ isForked: !1 });
350
+ return {
351
+ key: "yForkDoc",
352
+ store: r,
353
+ fork() {
354
+ if (n) return;
355
+ let i = t.fragment;
356
+ if (!i) throw Error("No fragment to fork from");
357
+ let a = new j.Doc();
358
+ j.applyUpdate(a, j.encodeStateAsUpdate(i.doc));
359
+ let o = Qe(i, a);
360
+ n = {
361
+ undoStack: ke.getState(e.prosemirrorState).undoManager.undoStack,
362
+ originalFragment: i,
363
+ forkedFragment: o
364
+ }, e.unregisterExtension([
365
+ L,
366
+ F,
367
+ I
368
+ ]);
369
+ let s = {
370
+ ...t,
371
+ fragment: o
372
+ };
373
+ e.registerExtension([I(s), L()]), r.setState({ isForked: !0 });
374
+ },
375
+ merge({ keepChanges: i }) {
376
+ if (!n) return;
377
+ e.unregisterExtension([
378
+ "ySync",
379
+ "yCursor",
380
+ "yUndo"
381
+ ]);
382
+ let { originalFragment: a, forkedFragment: o, undoStack: s } = n;
383
+ if (e.registerExtension([
384
+ I(t),
385
+ F(t),
386
+ L()
387
+ ]), ke.getState(e.prosemirrorState).undoManager.undoStack = s, i) {
388
+ let t = j.encodeStateAsUpdate(o.doc, j.encodeStateVector(a.doc));
389
+ j.applyUpdate(a.doc, t, e);
390
+ }
391
+ n = void 0, r.setState({ isForked: !1 });
392
+ }
393
+ };
394
+ }), R = (e, t) => {
395
+ t(e), e.forEach((e) => {
396
+ e instanceof j.XmlElement && R(e, t);
397
+ });
398
+ }, et = [(e, t) => {
399
+ let n = /* @__PURE__ */ new Map();
400
+ return e.forEach((e) => {
401
+ e instanceof j.XmlElement && R(e, (e) => {
402
+ if (e.nodeName === "blockContainer" && e.hasAttribute("id")) {
403
+ let t = e.getAttribute("textColor"), r = e.getAttribute("backgroundColor"), i = {
404
+ textColor: t === g.textColor.default ? void 0 : t,
405
+ backgroundColor: r === g.backgroundColor.default ? void 0 : r
406
+ };
407
+ (i.textColor || i.backgroundColor) && n.set(e.getAttribute("id"), i);
408
+ }
409
+ });
410
+ }), n.size === 0 ? !1 : (t.doc.descendants((e, r) => {
411
+ if (e.type.name === "blockContainer" && n.has(e.attrs.id)) {
412
+ let i = t.doc.nodeAt(r + 1);
413
+ if (!i) throw Error("No element found");
414
+ t.setNodeMarkup(r + 1, void 0, {
415
+ ...i.attrs,
416
+ ...n.get(e.attrs.id)
417
+ });
418
+ }
419
+ }), !0);
420
+ }], tt = y(({ options: e }) => {
421
+ let t = !1;
422
+ return {
423
+ key: "schemaMigration",
424
+ prosemirrorPlugins: [new D({
425
+ key: new O("schemaMigration"),
426
+ appendTransaction: (n, r, i) => {
427
+ if (t || !n.some((e) => e.getMeta("y-sync$")) || n.every((e) => !e.docChanged) || !e.fragment.firstChild) return;
428
+ let a = i.tr;
429
+ for (let t of et) t(e.fragment, a);
430
+ if (t = !0, a.docChanged) return a;
431
+ }
432
+ })]
433
+ };
434
+ });
435
+ //#endregion
436
+ //#region src/extensions/DropCursor/utils.ts
437
+ function z(e, t) {
438
+ return !e || !t ? !1 : !!e.closest(`.${t}`);
439
+ }
440
+ function nt(e, t, n, r, i) {
441
+ let a = e.state.doc.resolve(t.pos);
442
+ if (a.parent.inlineContent || t.orientation === "inline") return null;
443
+ let o = a.nodeBefore, s = a.nodeAfter;
444
+ if (!o && !s) return null;
445
+ let c = t.orientation === "block-vertical-left" || t.orientation === "block-vertical-right", l = c ? t.pos : t.pos - (o ? o.nodeSize : 0), u = e.nodeDOM(l);
446
+ if (!u) return null;
447
+ let d = u.getBoundingClientRect();
448
+ if (c) {
449
+ let e = n / 2 * r, i = t.orientation === "block-vertical-left" ? d.left : d.right;
450
+ return {
451
+ left: i - e,
452
+ right: i + e,
453
+ top: d.top,
454
+ bottom: d.bottom
455
+ };
456
+ }
457
+ let f = o ? d.bottom : d.top;
458
+ o && s && (f = (f + e.nodeDOM(t.pos).getBoundingClientRect().top) / 2);
459
+ let p = n / 2 * i;
460
+ return {
461
+ left: d.left,
462
+ right: d.right,
463
+ top: f - p,
464
+ bottom: f + p
465
+ };
466
+ }
467
+ function rt(e, t, n, r) {
468
+ let i = e.coordsAtPos(t.pos), a = n / 2 * r;
469
+ return {
470
+ left: i.left - a,
471
+ right: i.left + a,
472
+ top: i.top,
473
+ bottom: i.bottom
474
+ };
475
+ }
476
+ function it(e, t) {
477
+ e.classList.toggle("prosemirror-dropcursor-inline", t === "inline"), e.classList.toggle("prosemirror-dropcursor-block-horizontal", t === "block-horizontal"), e.classList.toggle("prosemirror-dropcursor-block-vertical-left", t === "block-vertical-left"), e.classList.toggle("prosemirror-dropcursor-block-vertical-right", t === "block-vertical-right"), e.classList.toggle("prosemirror-dropcursor-block", t === "block-horizontal"), e.classList.toggle("prosemirror-dropcursor-vertical", t === "block-vertical-left" || t === "block-vertical-right");
478
+ }
479
+ function at(e) {
480
+ if (!e || e === document.body && getComputedStyle(e).position === "static") return {
481
+ parentLeft: -window.pageXOffset,
482
+ parentTop: -window.pageYOffset
483
+ };
484
+ let t = e.getBoundingClientRect(), n = t.width / e.offsetWidth, r = t.height / e.offsetHeight;
485
+ return {
486
+ parentLeft: t.left - e.scrollLeft * n,
487
+ parentTop: t.top - e.scrollTop * r
488
+ };
489
+ }
490
+ //#endregion
491
+ //#region src/extensions/DropCursor/DropCursor.ts
492
+ var ot = "bn-drag-exclude", st = y(({ editor: e, options: t }) => {
493
+ let n = null, r = null, i = -1, a = null, o = {
494
+ width: t.dropCursor?.width ?? 5,
495
+ color: t.dropCursor?.color ?? "#ddeeff",
496
+ exclude: t.dropCursor?.exclude ?? "bn-drag-exclude",
497
+ hooks: t.dropCursor?.hooks
498
+ }, s = (e) => {
499
+ e?.pos === n?.pos && e?.orientation === n?.orientation || (n = e, e == null ? (r && r.parentNode && r.parentNode.removeChild(r), r = null) : c());
500
+ }, c = () => {
501
+ if (!n) return;
502
+ let t = e.prosemirrorView, i = t.dom, a = i.getBoundingClientRect(), s = a.width / i.offsetWidth, c = a.height / i.offsetHeight, l = nt(t, n, o.width, s, c) ?? rt(t, n, o.width, s), u = t.dom.offsetParent;
503
+ r || (r = u.appendChild(document.createElement("div")), r.style.cssText = "position: absolute; z-index: 50; pointer-events: none;", o.color && (r.style.backgroundColor = o.color)), it(r, n.orientation);
504
+ let { parentLeft: d, parentTop: f } = at(u);
505
+ r.style.left = (l.left - d) / s + "px", r.style.top = (l.top - f) / c + "px", r.style.width = (l.right - l.left) / s + "px", r.style.height = (l.bottom - l.top) / c + "px";
506
+ }, l = (e) => {
507
+ clearTimeout(i), i = window.setTimeout(() => s(null), e);
508
+ }, u = (e) => {
509
+ let t = e;
510
+ a = t.target instanceof Element ? t.target : null;
511
+ }, d = (t) => {
512
+ let n = t;
513
+ if (a && z(a, o.exclude) || n.target instanceof Element && z(n.target, o.exclude)) return;
514
+ let r = e.prosemirrorView;
515
+ if (!r.editable) return;
516
+ let i = r.posAtCoords({
517
+ left: n.clientX,
518
+ top: n.clientY
519
+ }), c = i && i.inside >= 0 && r.state.doc.nodeAt(i.inside), u = c && c.type.spec.disableDropCursor, d = typeof u == "function" ? u(r, i, n) : u;
520
+ if (i && !d) {
521
+ let t = i.pos;
522
+ if (r.dragging && r.dragging.slice) {
523
+ let e = oe(r.state.doc, t, r.dragging.slice);
524
+ e != null && (t = e);
525
+ }
526
+ let a = !r.state.doc.resolve(t).parent.inlineContent, c = {
527
+ pos: t,
528
+ orientation: a ? "block-horizontal" : "inline"
529
+ }, u = c;
530
+ if (o.hooks?.computeDropPosition) {
531
+ let t = o.hooks.computeDropPosition({
532
+ editor: e,
533
+ event: n,
534
+ view: r,
535
+ defaultPosition: c
536
+ });
537
+ if (t === null) {
538
+ s(null);
539
+ return;
540
+ }
541
+ u = t;
542
+ }
543
+ s(u), l(5e3);
544
+ }
545
+ }, f = (t) => {
546
+ let n = t;
547
+ (!(n.relatedTarget instanceof Node) || !e.prosemirrorView.dom.contains(n.relatedTarget)) && s(null);
548
+ }, p = () => {
549
+ l(20);
550
+ }, m = () => {
551
+ l(20), a = null;
552
+ };
553
+ return {
554
+ key: "dropCursor",
555
+ mount({ signal: e, dom: t, root: n }) {
556
+ n.addEventListener("dragstart", u, {
557
+ capture: !0,
558
+ signal: e
559
+ }), t.addEventListener("dragover", d, { signal: e }), t.addEventListener("dragleave", f, { signal: e }), t.addEventListener("drop", p, { signal: e }), t.addEventListener("dragend", m, { signal: e }), e.addEventListener("abort", () => {
560
+ clearTimeout(i), s(null);
561
+ });
562
+ }
563
+ };
564
+ }), ct = y(({ editor: e }) => {
565
+ let t = v(!1), n = () => e.transact((e) => {
566
+ if (e.selection.empty || e.selection instanceof S && (e.selection.node.type.spec.content === "inline*" || e.selection.node.firstChild?.type.spec.content === "inline*") || e.selection instanceof E && e.doc.textBetween(e.selection.from, e.selection.to).length === 0) return !1;
567
+ let t = !1;
568
+ return e.selection.content().content.descendants((e) => (e.type.spec.code && (t = !0), !t)), !t;
569
+ });
570
+ return {
571
+ key: "formattingToolbar",
572
+ store: t,
573
+ mount({ dom: r, signal: i }) {
574
+ let a = !1, o = e.onChange(() => {
575
+ a || t.setState(n());
576
+ }), s = e.onSelectionChange(() => {
577
+ a || t.setState(n());
578
+ });
579
+ r.addEventListener("pointerdown", () => {
580
+ a = !0, t.setState(!1);
581
+ }, { signal: i }), e.prosemirrorView.root.addEventListener("pointerup", () => {
582
+ a = !1, e.isFocused() && t.setState(n());
583
+ }, {
584
+ signal: i,
585
+ capture: !0
586
+ }), r.addEventListener("pointercancel", () => {
587
+ a = !1;
588
+ }, {
589
+ signal: i,
590
+ capture: !0
591
+ }), i.addEventListener("abort", () => {
592
+ o(), s();
593
+ });
594
+ }
595
+ };
596
+ }), lt = y(() => ({
597
+ key: "history",
598
+ prosemirrorPlugins: [je()],
599
+ undoCommand: Ne,
600
+ redoCommand: Me
601
+ })), ut = y(({ editor: e }) => {
602
+ function t(t) {
603
+ let n = e.prosemirrorView.nodeDOM(t);
604
+ for (; n && n.parentElement;) {
605
+ if (n.nodeName === "A") return n;
606
+ n = n.parentElement;
607
+ }
608
+ return null;
609
+ }
610
+ function n(t, n) {
611
+ return e.transact((r) => {
612
+ let i = r.doc.resolve(t), a = i.marks().find((e) => e.type.name === n);
613
+ if (!a) return;
614
+ let o = ce(i, a.type);
615
+ if (o) return {
616
+ range: o,
617
+ mark: a,
618
+ get text() {
619
+ return r.doc.textBetween(o.from, o.to);
620
+ },
621
+ get position() {
622
+ return le(e.prosemirrorView, o.from, o.to).toJSON();
623
+ }
624
+ };
625
+ });
626
+ }
627
+ function r() {
628
+ return e.transact((e) => {
629
+ let t = e.selection;
630
+ if (t.empty) return n(t.anchor, "link");
631
+ });
632
+ }
633
+ return {
634
+ key: "linkToolbar",
635
+ getLinkAtSelection: r,
636
+ getLinkElementAtPos: t,
637
+ getMarkAtPos: n,
638
+ getLinkAtElement(t) {
639
+ return e.transact(() => n(e.prosemirrorView.posAtDOM(t, 0) + 1, "link"));
640
+ },
641
+ editLink(t, r, i = e.transact((e) => e.selection.anchor)) {
642
+ e.transact((e) => {
643
+ let a = p(e), { range: o } = n(i + 1, "link") || { range: {
644
+ from: e.selection.from,
645
+ to: e.selection.to
646
+ } };
647
+ o && (e.insertText(r, o.from, o.to), e.addMark(o.from, o.from + r.length, a.mark("link", { href: t })));
648
+ }), e.prosemirrorView.focus();
649
+ },
650
+ deleteLink(t = e.transact((e) => e.selection.anchor)) {
651
+ e.transact((e) => {
652
+ let r = p(e), { range: i } = n(t + 1, "link") || { range: {
653
+ from: e.selection.from,
654
+ to: e.selection.to
655
+ } };
656
+ i && e.removeMark(i.from, i.to, r.marks.link).setMeta("preventAutolink", !0);
657
+ }), e.prosemirrorView.focus();
658
+ }
659
+ };
660
+ }), dt = [
661
+ "http",
662
+ "https",
663
+ "ftp",
664
+ "ftps",
665
+ "mailto",
666
+ "tel",
667
+ "callto",
668
+ "sms",
669
+ "cid",
670
+ "xmpp"
671
+ ], ft = "https", pt = new w("node-selection-keyboard"), mt = y(() => ({
672
+ key: "nodeSelectionKeyboard",
673
+ prosemirrorPlugins: [new C({
674
+ key: pt,
675
+ props: { handleKeyDown: (e, t) => {
676
+ if ("node" in e.state.selection) {
677
+ if (t.ctrlKey || t.metaKey) return !1;
678
+ if (t.key.length === 1) return t.preventDefault(), !0;
679
+ if (t.key === "Enter" && !t.isComposing && !t.shiftKey && !t.altKey && !t.ctrlKey && !t.metaKey) {
680
+ let t = e.state.tr;
681
+ return e.dispatch(t.insert(e.state.tr.selection.$to.after(), e.state.schema.nodes.paragraph.createChecked()).setSelection(new E(t.doc.resolve(e.state.tr.selection.$to.after() + 1)))), !0;
682
+ }
683
+ }
684
+ return !1;
685
+ } }
686
+ })]
687
+ })), ht = new w("blocknote-placeholder"), gt = y(({ editor: e, options: t }) => {
688
+ let n = t.placeholders;
689
+ return {
690
+ key: "placeholder",
691
+ prosemirrorPlugins: [new C({
692
+ key: ht,
693
+ view: (t) => {
694
+ let r = `placeholder-selector-${ue()}`;
695
+ t.dom.classList.add(r);
696
+ let i = document.createElement("style"), a = e._tiptapEditor.options.injectNonce;
697
+ a && i.setAttribute("nonce", a), t.root instanceof window.ShadowRoot ? t.root.append(i) : t.root.head.appendChild(i);
698
+ let o = i.sheet, s = (e = "") => `.${r} .bn-block-content${e}:has(.ProseMirror-trailingBreak:only-child):after`;
699
+ try {
700
+ let { default: e, emptyDocument: t, ...r } = n || {};
701
+ for (let [e, t] of Object.entries(r)) {
702
+ let n = `[data-content-type="${e}"]`;
703
+ o.insertRule(`${s(n)} { content: ${JSON.stringify(t)}; }`);
704
+ }
705
+ o.insertRule(`${s("[data-is-only-empty-block]")} { content: ${JSON.stringify(t)}; }`), o.insertRule(`${s("[data-is-empty-and-focused]")} { content: ${JSON.stringify(e)}; }`);
706
+ } catch (e) {
707
+ console.warn("Failed to insert placeholder CSS rule - this is likely due to the browser not supporting certain CSS pseudo-element selectors (:has, :only-child:, or :before)", e);
708
+ }
709
+ return { destroy: () => {
710
+ t.root instanceof window.ShadowRoot ? t.root.removeChild(i) : t.root.head.removeChild(i);
711
+ } };
712
+ },
713
+ props: { decorations: (t) => {
714
+ let { doc: n, selection: r } = t;
715
+ if (!e.isEditable || !r.empty || r.$from.parent.type.spec.code) return;
716
+ let i = [];
717
+ t.doc.content.size === 6 && i.push(k.node(2, 4, { "data-is-only-empty-block": "true" }));
718
+ let a = r.$anchor, o = a.parent;
719
+ if (o.content.size === 0) {
720
+ let e = a.before();
721
+ i.push(k.node(e, e + o.nodeSize, { "data-is-empty-and-focused": "true" }));
722
+ }
723
+ return A.create(n, i);
724
+ } }
725
+ })]
726
+ };
727
+ }), B = new w("previous-blocks"), _t = {
728
+ index: "index",
729
+ level: "level",
730
+ type: "type",
731
+ depth: "depth",
732
+ "depth-change": "depth-change"
733
+ }, vt = y(() => {
734
+ let e;
735
+ return {
736
+ key: "previousBlockType",
737
+ prosemirrorPlugins: [new C({
738
+ key: B,
739
+ view(t) {
740
+ return {
741
+ update: async (t, n) => {
742
+ this.key?.getState(t.state).updatedBlocks.size > 0 && (e = setTimeout(() => {
743
+ t.dispatch(t.state.tr.setMeta(B, { clearUpdate: !0 }));
744
+ }, 0));
745
+ },
746
+ destroy: () => {
747
+ e && clearTimeout(e);
748
+ }
749
+ };
750
+ },
751
+ state: {
752
+ init() {
753
+ return {
754
+ prevTransactionOldBlockAttrs: {},
755
+ currentTransactionOldBlockAttrs: {},
756
+ updatedBlocks: /* @__PURE__ */ new Set()
757
+ };
758
+ },
759
+ apply(e, t, n, r) {
760
+ if (t.currentTransactionOldBlockAttrs = {}, t.updatedBlocks.clear(), !e.docChanged) return t;
761
+ let i = e.changedRange();
762
+ if (!i) return t;
763
+ let a = e.mapping.invert(), o = {
764
+ from: a.map(i.from, -1),
765
+ to: a.map(i.to, 1)
766
+ }, s = {}, c = x(n.doc, o, (e) => e.attrs.id), l = new Map(c.map((e) => [e.node.attrs.id, e])), u = x(r.doc, i, (e) => e.attrs.id);
767
+ for (let e of u) {
768
+ let i = l.get(e.node.attrs.id), a = i?.node.firstChild, o = e.node.firstChild;
769
+ if (i && a && o) {
770
+ let c = {
771
+ index: o.attrs.index,
772
+ level: o.attrs.level,
773
+ type: o.type.name,
774
+ depth: r.doc.resolve(e.pos).depth
775
+ }, l = {
776
+ index: a.attrs.index,
777
+ level: a.attrs.level,
778
+ type: a.type.name,
779
+ depth: n.doc.resolve(i.pos).depth
780
+ };
781
+ s[e.node.attrs.id] = l, t.currentTransactionOldBlockAttrs[e.node.attrs.id] = l, (l.index !== c.index || l.level !== c.level || l.type !== c.type || l.depth !== c.depth) && (l["depth-change"] = l.depth - c.depth, t.updatedBlocks.add(e.node.attrs.id));
782
+ }
783
+ }
784
+ return t.prevTransactionOldBlockAttrs = s, t;
785
+ }
786
+ },
787
+ props: { decorations(e) {
788
+ let t = this.getState(e);
789
+ if (t.updatedBlocks.size === 0) return;
790
+ let n = [];
791
+ return e.doc.descendants((e, r) => {
792
+ if (!e.attrs.id || !t.updatedBlocks.has(e.attrs.id)) return;
793
+ let i = t.currentTransactionOldBlockAttrs[e.attrs.id], a = {};
794
+ for (let [e, t] of Object.entries(i)) a["data-prev-" + _t[e]] = t || "none";
795
+ n.push(k.node(r, r + e.nodeSize, { ...a }));
796
+ }), A.create(e.doc, n);
797
+ } }
798
+ })]
799
+ };
800
+ });
801
+ //#endregion
802
+ //#region src/extensions/getDraggableBlockFromElement.ts
803
+ function V(e, t) {
804
+ for (; e && e.parentElement && e.parentElement !== t.dom && e.getAttribute?.("data-node-type") !== "blockContainer";) e = e.parentElement;
805
+ if (e.getAttribute?.("data-node-type") === "blockContainer") return {
806
+ node: e,
807
+ id: e.getAttribute("data-id")
808
+ };
809
+ }
810
+ //#endregion
811
+ //#region src/api/exporters/markdown/util/removeUnderlinesRehypePlugin.ts
812
+ function yt() {
813
+ let e = (t) => {
814
+ let n = t.children.length;
815
+ for (let r = 0; r < n; r++) {
816
+ let i = t.children[r];
817
+ if (i.type === "element" && (e(i), i.tagName === "u")) if (i.children.length > 0) {
818
+ t.children.splice(r, 1, ...i.children);
819
+ let e = i.children.length - 1;
820
+ n += e, r += e;
821
+ } else t.children.splice(r, 1), n--, r--;
822
+ }
823
+ };
824
+ return e;
825
+ }
826
+ //#endregion
827
+ //#region src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts
828
+ function bt() {
829
+ let e = (t) => {
830
+ if (t.children && "length" in t.children && t.children.length) for (let n = t.children.length - 1; n >= 0; n--) {
831
+ let r = t.children[n], i = n + 1 < t.children.length ? t.children[n + 1] : void 0;
832
+ r.type === "element" && r.tagName === "input" && r.properties?.type === "checkbox" && i?.type === "element" && i.tagName === "p" ? (i.tagName = "span", i.children.splice(0, 0, ze(document.createTextNode(" ")))) : e(r);
833
+ }
834
+ };
835
+ return e;
836
+ }
837
+ //#endregion
838
+ //#region src/api/exporters/markdown/util/convertVideoToMarkdownRehypePlugin.ts
839
+ function xt() {
840
+ return (e) => {
841
+ Be(e, "element", (e, t, n) => {
842
+ if (n && e.tagName === "video") {
843
+ let r = e.properties?.src || e.properties?.["data-url"] || "", i = e.properties?.title || e.properties?.["data-name"] || "";
844
+ n.children[t] = {
845
+ type: "text",
846
+ value: `![${i}](${r})`
847
+ };
848
+ }
849
+ });
850
+ };
851
+ }
852
+ //#endregion
853
+ //#region src/api/exporters/markdown/markdownExporter.ts
854
+ function H(e) {
855
+ return Re().use(Pe, { fragment: !0 }).use(xt).use(yt).use(bt).use(Fe).use(Ie).use(Le, { handlers: { text: (e) => e.value } }).processSync(e).value;
856
+ }
857
+ function St(e, t, n, r) {
858
+ return H(M(t, n).exportBlocks(e, r));
859
+ }
860
+ //#endregion
861
+ //#region src/api/nodeConversions/fragmentToBlocks.ts
862
+ function U(e) {
863
+ let t = [];
864
+ return e.descendants((e) => {
865
+ let n = p(e);
866
+ return e.type.name === "blockContainer" && e.firstChild?.type.name === "blockGroup" ? !0 : e.type.name === "columnList" && e.childCount === 1 ? (e.firstChild?.forEach((e) => {
867
+ t.push(_(e, n));
868
+ }), !1) : e.type.isInGroup("bnBlock") ? (t.push(_(e, n)), !1) : !0;
869
+ }), t;
870
+ }
871
+ //#endregion
872
+ //#region src/extensions/SideMenu/MultipleNodeSelection.ts
873
+ var W = class e extends T {
874
+ nodes;
875
+ constructor(e, t) {
876
+ super(e, t);
877
+ let n = e.node();
878
+ this.nodes = [], e.doc.nodesBetween(e.pos, t.pos, (e, t, r) => {
879
+ if (r !== null && r.eq(n)) return this.nodes.push(e), !1;
880
+ });
881
+ }
882
+ static create(t, n, r = n) {
883
+ return new e(t.resolve(n), t.resolve(r));
884
+ }
885
+ content() {
886
+ return new ae(b.from(this.nodes), 0, 0);
887
+ }
888
+ eq(t) {
889
+ if (!(t instanceof e) || this.nodes.length !== t.nodes.length || this.from !== t.from || this.to !== t.to) return !1;
890
+ for (let e = 0; e < this.nodes.length; e++) if (!this.nodes[e].eq(t.nodes[e])) return !1;
891
+ return !0;
892
+ }
893
+ map(t, n) {
894
+ let r = n.mapResult(this.from), i = n.mapResult(this.to);
895
+ return i.deleted ? T.near(t.resolve(r.pos)) : r.deleted ? T.near(t.resolve(i.pos)) : new e(t.resolve(r.pos), t.resolve(i.pos));
896
+ }
897
+ toJSON() {
898
+ return {
899
+ type: "multiple-node",
900
+ anchor: this.anchor,
901
+ head: this.head
902
+ };
903
+ }
904
+ };
905
+ T.jsonID("multiple-node", W);
906
+ //#endregion
907
+ //#region src/extensions/SideMenu/dragging.ts
908
+ var G;
909
+ function Ct(e, t) {
910
+ let n, r, i = t.resolve(e.from).node().type.spec.group === "blockContent", a = t.resolve(e.to).node().type.spec.group === "blockContent", o = Math.min(e.$anchor.depth, e.$head.depth);
911
+ if (i && a) {
912
+ let i = e.$from.start(o - 1), a = e.$to.end(o - 1);
913
+ n = t.resolve(i - 1).pos, r = t.resolve(a + 1).pos;
914
+ } else n = e.from, r = e.to;
915
+ return {
916
+ from: n,
917
+ to: r
918
+ };
919
+ }
920
+ function K(e, t, n = t) {
921
+ t === n && (n += e.state.doc.resolve(t + 1).node().nodeSize);
922
+ let r = e.domAtPos(t).node.cloneNode(!0), i = e.domAtPos(t).node, a = (e, t) => Array.prototype.indexOf.call(e.children, t), o = a(i, e.domAtPos(t + 1).node.parentElement), s = a(i, e.domAtPos(n - 1).node.parentElement);
923
+ for (let e = i.childElementCount - 1; e >= 0; e--) (e > s || e < o) && r.removeChild(r.children[e]);
924
+ q(e.root), G = r;
925
+ let c = G.getElementsByTagName("iframe");
926
+ for (let e = 0; e < c.length; e++) {
927
+ let t = c[e], n = t.parentElement;
928
+ n && n.removeChild(t);
929
+ }
930
+ let l = e.dom.className.split(" ").filter((e) => e !== "ProseMirror" && e !== "bn-root" && e !== "bn-editor").join(" ");
931
+ G.className = G.className + " bn-drag-preview " + l, e.root instanceof ShadowRoot ? e.root.appendChild(G) : e.root.body.appendChild(G);
932
+ }
933
+ function q(e) {
934
+ G !== void 0 && (e instanceof ShadowRoot ? e.removeChild(G) : e.body.removeChild(G), G = void 0);
935
+ }
936
+ function wt(e, t, n) {
937
+ if (!e.dataTransfer || n.headless) return;
938
+ let i = n.prosemirrorView, a = r(t.id, i.state.doc);
939
+ if (!a) throw Error(`Block with ID ${t.id} not found`);
940
+ let o = a.posBeforeNode;
941
+ if (o != null) {
942
+ let t = i.state.selection, r = i.state.doc, { from: a, to: s } = Ct(t, r), c = a <= o && o < s, l = t.$anchor.node() !== t.$head.node() || t instanceof W;
943
+ c && l ? (i.dispatch(i.state.tr.setSelection(W.create(r, a, s))), K(i, a, s)) : (i.dispatch(i.state.tr.setSelection(S.create(i.state.doc, o))), K(i, o));
944
+ let u = i.state.selection.content(), d = n.pmSchema, f = i.serializeForClipboard(u).dom.innerHTML, p = M(d, n), m = U(u.content), h = p.exportBlocks(m, {}), g = H(h);
945
+ e.dataTransfer.clearData(), e.dataTransfer.setData("blocknote/html", f), e.dataTransfer.setData("text/html", h), e.dataTransfer.setData("text/plain", g), e.dataTransfer.effectAllowed = "move", e.dataTransfer.setDragImage(G, 0, 0);
946
+ }
947
+ }
948
+ //#endregion
949
+ //#region src/extensions/SideMenu/SideMenu.ts
950
+ var Tt = 250;
951
+ function J(e, t, n = !0) {
952
+ let r = e.root.elementsFromPoint(t.left, t.top);
953
+ for (let i of r) if (e.dom.contains(i)) return n && i.closest("[data-node-type=columnList]") ? J(e, {
954
+ left: t.left + 50,
955
+ top: t.top
956
+ }, !1) : V(i, e);
957
+ }
958
+ function Et(e, t) {
959
+ if (!t.dom.firstChild) return;
960
+ let n = t.dom.firstChild.getBoundingClientRect(), r = J(t, {
961
+ left: Math.min(Math.max(n.left + 10, e.x), n.right - 10),
962
+ top: e.y
963
+ });
964
+ if (r) return J(t, {
965
+ left: r.node.getBoundingClientRect().right - 10,
966
+ top: e.y
967
+ }, !1);
968
+ }
969
+ var Dt = class {
970
+ state;
971
+ emitUpdate;
972
+ mousePos;
973
+ hoveredBlock;
974
+ menuFrozen = !1;
975
+ isDragOrigin = !1;
976
+ constructor(e, t, n) {
977
+ this.editor = e, this.pmView = t, this.emitUpdate = () => {
978
+ if (!this.state) throw Error("Attempting to update uninitialized side menu");
979
+ n(this.state);
980
+ }, this.pmView.root.addEventListener("dragstart", this.onDragStart), this.pmView.root.addEventListener("dragover", this.onDragOver), this.pmView.root.addEventListener("drop", this.onDrop, !0), this.pmView.root.addEventListener("dragend", this.onDragEnd, !0), this.pmView.root.addEventListener("mousemove", this.onMouseMove, !0), this.pmView.root.addEventListener("keydown", this.onKeyDown, !0);
981
+ }
982
+ updateState = (e) => {
983
+ this.state = e, this.emitUpdate(this.state);
984
+ };
985
+ updateStateFromMousePos = () => {
986
+ if (this.menuFrozen || !this.mousePos) return;
987
+ let e = this.findClosestEditorElement({
988
+ clientX: this.mousePos.x,
989
+ clientY: this.mousePos.y
990
+ });
991
+ if (e?.element !== this.pmView.dom || e.distance > Tt) {
992
+ this.state?.show && (this.state.show = !1, this.updateState(this.state));
993
+ return;
994
+ }
995
+ let t = Et(this.mousePos, this.pmView);
996
+ if (!t || !this.editor.isEditable) {
997
+ this.state?.show && (this.state.show = !1, this.updateState(this.state));
998
+ return;
999
+ }
1000
+ if (!(this.state?.show && this.hoveredBlock?.hasAttribute("data-id") && this.hoveredBlock?.getAttribute("data-id") === t.id) && (this.hoveredBlock = t.node, this.editor.isEditable)) {
1001
+ let e = t.node.getBoundingClientRect(), n = t.node.closest("[data-node-type=column]");
1002
+ this.state = {
1003
+ show: !0,
1004
+ referencePos: new DOMRect(n ? n.firstElementChild.getBoundingClientRect().x : this.pmView.dom.firstChild.getBoundingClientRect().x, e.y, e.width, e.height),
1005
+ block: this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))
1006
+ }, this.updateState(this.state);
1007
+ }
1008
+ };
1009
+ onDragStart = (e) => {
1010
+ let t = e.dataTransfer?.getData("blocknote/html");
1011
+ if (!t || this.pmView.dragging) return;
1012
+ let n = document.createElement("div");
1013
+ n.innerHTML = t;
1014
+ let r = de.fromSchema(this.pmView.state.schema).parse(n, { topNode: this.pmView.state.schema.nodes.blockGroup.create() });
1015
+ this.pmView.dragging = {
1016
+ slice: new fe(r.content, 0, 0),
1017
+ move: !0
1018
+ };
1019
+ };
1020
+ findClosestEditorElement = (e) => {
1021
+ let t = Array.from(this.pmView.root.querySelectorAll(".bn-editor"));
1022
+ if (t.length === 0) return null;
1023
+ let n = t[0], r = Number.MAX_VALUE;
1024
+ return t.forEach((t) => {
1025
+ let i = t.querySelector(".bn-block-group").getBoundingClientRect(), a = e.clientX < i.left ? i.left - e.clientX : e.clientX > i.right ? e.clientX - i.right : 0, o = e.clientY < i.top ? i.top - e.clientY : e.clientY > i.bottom ? e.clientY - i.bottom : 0, s = Math.sqrt(a ** 2 + o ** 2);
1026
+ s < r && (r = s, n = t);
1027
+ }), {
1028
+ element: n,
1029
+ distance: r
1030
+ };
1031
+ };
1032
+ onDragOver = (e) => {
1033
+ if (e.synthetic || !(this.pmView.dragging !== null || this.isDragOrigin || e.dataTransfer?.types.includes("blocknote/html") || e.target instanceof Node && this.pmView.dom.contains(e.target))) return;
1034
+ let t = this.getDragEventContext(e);
1035
+ if (!t || !t.isDropPoint) {
1036
+ this.closeDropCursor();
1037
+ return;
1038
+ }
1039
+ t.isDropPoint && !t.isDropWithinEditorBounds && this.dispatchSyntheticEvent(e);
1040
+ };
1041
+ closeDropCursor = () => {
1042
+ let e = new Event("dragleave", { bubbles: !1 });
1043
+ e.synthetic = !0, this.pmView.dom.dispatchEvent(e);
1044
+ };
1045
+ getDragEventContext = (e) => {
1046
+ if (!(this.pmView.dragging !== null || this.isDragOrigin || e.dataTransfer?.types.includes("blocknote/html") || e.target instanceof Node && this.pmView.dom.contains(e.target))) return;
1047
+ let t = !e.dataTransfer?.types.includes("blocknote/html") && !!this.pmView.dragging, n = !!this.isDragOrigin, r = t || n, i = this.findClosestEditorElement(e);
1048
+ if (!i || i.distance > Tt) return;
1049
+ let a = i.element === this.pmView.dom, o = a && i.distance === 0;
1050
+ if (!(!a && !r)) return {
1051
+ isDropPoint: a,
1052
+ isDropWithinEditorBounds: o,
1053
+ isDragOrigin: r
1054
+ };
1055
+ };
1056
+ onDrop = (e) => {
1057
+ if (e.synthetic || !(this.pmView.dragging !== null || this.isDragOrigin || e.dataTransfer?.types.includes("blocknote/html") || e.target instanceof Node && this.pmView.dom.contains(e.target))) return;
1058
+ let t = this.getDragEventContext(e);
1059
+ if (!t) {
1060
+ this.closeDropCursor();
1061
+ return;
1062
+ }
1063
+ let { isDropPoint: n, isDropWithinEditorBounds: r, isDragOrigin: i } = t;
1064
+ if (!r && n && this.dispatchSyntheticEvent(e), n) {
1065
+ if (this.pmView.dragging) return;
1066
+ this.pmView.dispatch(this.pmView.state.tr.setSelection(Se.create(this.pmView.state.tr.doc, this.pmView.state.tr.selection.anchor)));
1067
+ return;
1068
+ } else if (i) {
1069
+ setTimeout(() => this.pmView.dispatch(this.pmView.state.tr.deleteSelection()), 0);
1070
+ return;
1071
+ }
1072
+ };
1073
+ onDragEnd = (e) => {
1074
+ e.synthetic || (this.pmView.dragging = null);
1075
+ };
1076
+ onKeyDown = (e) => {
1077
+ this.state?.show && this.editor.isFocused() && (this.state.show = !1, this.emitUpdate(this.state));
1078
+ };
1079
+ onMouseMove = (e) => {
1080
+ if (this.menuFrozen) return;
1081
+ this.mousePos = {
1082
+ x: e.clientX,
1083
+ y: e.clientY
1084
+ };
1085
+ let t = this.pmView.dom.getBoundingClientRect();
1086
+ if (this.mousePos.x > t.left && this.mousePos.x < t.right && this.mousePos.y > t.top && this.mousePos.y < t.bottom && e && e.target && !this.editor.isWithinEditor(e.target)) {
1087
+ this.state?.show && (this.state.show = !1, this.emitUpdate(this.state));
1088
+ return;
1089
+ }
1090
+ this.updateStateFromMousePos();
1091
+ };
1092
+ dispatchSyntheticEvent(e) {
1093
+ let t = new Event(e.type, e), n = this.pmView.dom.firstChild.getBoundingClientRect();
1094
+ t.clientX = e.clientX, t.clientY = e.clientY, t.clientX = Math.min(Math.max(e.clientX, n.left), n.left + n.width), t.clientY = Math.min(Math.max(e.clientY, n.top), n.top + n.height), t.dataTransfer = e.dataTransfer, t.preventDefault = () => e.preventDefault(), t.synthetic = !0, this.pmView.dom.dispatchEvent(t);
1095
+ }
1096
+ update(e, t) {
1097
+ !t.doc.eq(this.pmView.state.doc) && this.state?.show && this.updateStateFromMousePos();
1098
+ }
1099
+ destroy() {
1100
+ this.state?.show && (this.state.show = !1, this.emitUpdate(this.state)), this.pmView.root.removeEventListener("mousemove", this.onMouseMove, !0), this.pmView.root.removeEventListener("dragstart", this.onDragStart), this.pmView.root.removeEventListener("dragover", this.onDragOver), this.pmView.root.removeEventListener("drop", this.onDrop, !0), this.pmView.root.removeEventListener("dragend", this.onDragEnd, !0), this.pmView.root.removeEventListener("keydown", this.onKeyDown, !0);
1101
+ }
1102
+ }, Ot = new O("SideMenuPlugin"), kt = y(({ editor: e }) => {
1103
+ let t, n = v(void 0);
1104
+ return {
1105
+ key: "sideMenu",
1106
+ store: n,
1107
+ prosemirrorPlugins: [new D({
1108
+ key: Ot,
1109
+ view: (r) => (t = new Dt(e, r, (e) => {
1110
+ n.setState({ ...e });
1111
+ }), t)
1112
+ })],
1113
+ blockDragStart(n, r) {
1114
+ t && (t.isDragOrigin = !0), wt(n, r, e);
1115
+ },
1116
+ blockDragEnd() {
1117
+ q(e.prosemirrorView.root), t && (t.isDragOrigin = !1), e.blur();
1118
+ },
1119
+ freezeMenu() {
1120
+ t.menuFrozen = !0, t.state.show = !0, t.emitUpdate(t.state);
1121
+ },
1122
+ unfreezeMenu() {
1123
+ t.menuFrozen = !1, t.state.show = !1, t.emitUpdate(t.state);
1124
+ },
1125
+ hideMenuIfNotFrozen() {
1126
+ !t.menuFrozen && t.state.show && (t.state.show = !1, t.emitUpdate(t.state));
1127
+ }
1128
+ };
1129
+ }), Y;
1130
+ async function At() {
1131
+ return Y || (Y = (async () => {
1132
+ let [e, t] = await Promise.all([import("emoji-mart"), import("@emoji-mart/data")]), n = "default" in e ? e.default : e, r = "default" in t ? t.default : t;
1133
+ return await n.init({ data: r }), {
1134
+ emojiMart: n,
1135
+ emojiData: r
1136
+ };
1137
+ })(), Y);
1138
+ }
1139
+ async function jt(e, t) {
1140
+ if (!("text" in e.schema.inlineContentSchema) || e.schema.inlineContentSchema.text !== ne.text) return [];
1141
+ let { emojiData: n, emojiMart: r } = await At();
1142
+ return (t.trim() === "" ? Object.values(n.emojis) : await r.SearchIndex.search(t)).map((t) => ({
1143
+ id: t.skins[0].native,
1144
+ onItemClick: () => e.insertInlineContent(t.skins[0].native + " ")
1145
+ }));
1146
+ }
1147
+ //#endregion
1148
+ //#region src/extensions/TableHandles/TableHandles.ts
1149
+ var X;
1150
+ function Mt(e) {
1151
+ X || (X = document.createElement("div"), X.innerHTML = "_", X.style.opacity = "0", X.style.height = "1px", X.style.width = "1px", e instanceof Document ? e.body.appendChild(X) : e.appendChild(X));
1152
+ }
1153
+ function Nt(e) {
1154
+ X &&= (e instanceof Document ? e.body.removeChild(X) : e.removeChild(X), void 0);
1155
+ }
1156
+ function Z(e) {
1157
+ return Array.prototype.indexOf.call(e.parentElement.childNodes, e);
1158
+ }
1159
+ function Pt(e) {
1160
+ let t = e;
1161
+ for (; t && t.nodeName !== "TD" && t.nodeName !== "TH" && !t.classList.contains("tableWrapper");) {
1162
+ if (t.classList.contains("ProseMirror")) return;
1163
+ let e = t.parentNode;
1164
+ if (!e || !(e instanceof Element)) return;
1165
+ t = e;
1166
+ }
1167
+ return t.nodeName === "TD" || t.nodeName === "TH" ? {
1168
+ type: "cell",
1169
+ domNode: t,
1170
+ tbodyNode: t.closest("tbody")
1171
+ } : {
1172
+ type: "wrapper",
1173
+ domNode: t,
1174
+ tbodyNode: t.querySelector("tbody")
1175
+ };
1176
+ }
1177
+ function Ft(e, t) {
1178
+ let n = t.querySelectorAll(e);
1179
+ for (let e = 0; e < n.length; e++) n[e].style.visibility = "hidden";
1180
+ }
1181
+ var Q = class {
1182
+ state;
1183
+ emitUpdate;
1184
+ tableId;
1185
+ tablePos;
1186
+ tableElement;
1187
+ menuFrozen = !1;
1188
+ mouseState = "up";
1189
+ prevWasEditable = null;
1190
+ constructor(e, t, n) {
1191
+ this.editor = e, this.pmView = t, this.emitUpdate = () => {
1192
+ if (!this.state) throw Error("Attempting to update uninitialized image toolbar");
1193
+ n(this.state);
1194
+ }, t.dom.addEventListener("mousemove", this.mouseMoveHandler), t.dom.addEventListener("mousedown", this.viewMousedownHandler), window.addEventListener("mouseup", this.mouseUpHandler), t.root.addEventListener("dragover", this.dragOverHandler), t.root.addEventListener("drop", this.dropHandler);
1195
+ }
1196
+ viewMousedownHandler = () => {
1197
+ this.mouseState = "down";
1198
+ };
1199
+ mouseUpHandler = (e) => {
1200
+ this.mouseState = "up", this.mouseMoveHandler(e);
1201
+ };
1202
+ mouseMoveHandler = (e) => {
1203
+ if (this.menuFrozen || this.mouseState === "selecting" || !(e.target instanceof Element) || !this.pmView.dom.contains(e.target)) return;
1204
+ let t = Pt(e.target);
1205
+ if (t?.type === "cell" && this.mouseState === "down" && !this.state?.draggingState) {
1206
+ this.mouseState = "selecting", this.state?.show && (this.state.show = !1, this.state.showAddOrRemoveRowsButton = !1, this.state.showAddOrRemoveColumnsButton = !1, this.emitUpdate());
1207
+ return;
1208
+ }
1209
+ if (!t || !this.editor.isEditable) {
1210
+ this.state?.show && (this.state.show = !1, this.state.showAddOrRemoveRowsButton = !1, this.state.showAddOrRemoveColumnsButton = !1, this.emitUpdate());
1211
+ return;
1212
+ }
1213
+ if (!t.tbodyNode) return;
1214
+ let n = t.tbodyNode.getBoundingClientRect(), i = V(t.domNode, this.pmView);
1215
+ if (!i) return;
1216
+ this.tableElement = i.node;
1217
+ let a, o = this.editor.transact((e) => r(i.id, e.doc));
1218
+ if (!o) throw Error(`Block with ID ${i.id} not found`);
1219
+ let s = _(o.node, this.editor.pmSchema, this.editor.schema.blockSchema, this.editor.schema.inlineContentSchema, this.editor.schema.styleSchema);
1220
+ if (h(this.editor, "table") && (this.tablePos = o.posBeforeNode + 1, a = s), !a) return;
1221
+ this.tableId = i.id;
1222
+ let c = t.domNode.closest(".tableWrapper")?.querySelector(".table-widgets-container");
1223
+ if (t?.type === "wrapper") {
1224
+ let t = e.clientY >= n.bottom - 1 && e.clientY < n.bottom + 20, r = e.clientX >= n.right - 1 && e.clientX < n.right + 20, i = this.state?.block.id !== a.id || e.clientX > n.right || e.clientY > n.bottom;
1225
+ this.state = {
1226
+ ...this.state,
1227
+ show: !0,
1228
+ showAddOrRemoveRowsButton: t,
1229
+ showAddOrRemoveColumnsButton: r,
1230
+ referencePosTable: n,
1231
+ block: a,
1232
+ widgetContainer: c,
1233
+ colIndex: i ? void 0 : this.state?.colIndex,
1234
+ rowIndex: i ? void 0 : this.state?.rowIndex,
1235
+ referencePosCell: i ? void 0 : this.state?.referencePosCell
1236
+ };
1237
+ } else {
1238
+ let e = Z(t.domNode), r = Z(t.domNode.parentElement), o = t.domNode.getBoundingClientRect();
1239
+ if (this.state !== void 0 && this.state.show && this.tableId === i.id && this.state.rowIndex === r && this.state.colIndex === e) return;
1240
+ this.state = {
1241
+ show: !0,
1242
+ showAddOrRemoveColumnsButton: e === a.content.rows[0].cells.length - 1,
1243
+ showAddOrRemoveRowsButton: r === a.content.rows.length - 1,
1244
+ referencePosTable: n,
1245
+ block: a,
1246
+ draggingState: void 0,
1247
+ referencePosCell: o,
1248
+ colIndex: e,
1249
+ rowIndex: r,
1250
+ widgetContainer: c
1251
+ };
1252
+ }
1253
+ return this.emitUpdate(), !1;
1254
+ };
1255
+ dragOverHandler = (e) => {
1256
+ if (this.state?.draggingState === void 0) return;
1257
+ e.preventDefault(), e.dataTransfer.dropEffect = "move", Ft(".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline", this.pmView.root);
1258
+ let t = {
1259
+ left: Math.min(Math.max(e.clientX, this.state.referencePosTable.left + 1), this.state.referencePosTable.right - 1),
1260
+ top: Math.min(Math.max(e.clientY, this.state.referencePosTable.top + 1), this.state.referencePosTable.bottom - 1)
1261
+ }, n = this.pmView.root.elementsFromPoint(t.left, t.top).filter((e) => e.tagName === "TD" || e.tagName === "TH");
1262
+ if (n.length === 0) return;
1263
+ let r = n[0], i = !1, a = Z(r.parentElement), o = Z(r), s = this.state.draggingState.draggedCellOrientation === "row" ? this.state.rowIndex : this.state.colIndex, c = (this.state.draggingState.draggedCellOrientation === "row" ? a : o) !== s;
1264
+ (this.state.rowIndex !== a || this.state.colIndex !== o) && (this.state.rowIndex = a, this.state.colIndex = o, this.state.referencePosCell = r.getBoundingClientRect(), i = !0);
1265
+ let l = this.state.draggingState.draggedCellOrientation === "row" ? t.top : t.left;
1266
+ this.state.draggingState.mousePos !== l && (this.state.draggingState.mousePos = l, i = !0), i && this.emitUpdate(), c && this.editor.transact((e) => e.setMeta($, !0));
1267
+ };
1268
+ dropHandler = (e) => {
1269
+ if (this.mouseState = "up", this.state === void 0 || this.state.draggingState === void 0) return !1;
1270
+ if (this.state.rowIndex === void 0 || this.state.colIndex === void 0) throw Error("Attempted to drop table row or column, but no table block was hovered prior.");
1271
+ e.preventDefault();
1272
+ let { draggingState: n, colIndex: r, rowIndex: i } = this.state, a = this.state.block.content.columnWidths;
1273
+ if (n.draggedCellOrientation === "row") {
1274
+ if (!l(this.state.block, n.originalIndex, i)) return !1;
1275
+ let e = t(this.state.block, n.originalIndex, i);
1276
+ this.editor.updateBlock(this.state.block, {
1277
+ type: "table",
1278
+ content: {
1279
+ ...this.state.block.content,
1280
+ rows: e
1281
+ }
1282
+ });
1283
+ } else {
1284
+ if (!c(this.state.block, n.originalIndex, r)) return !1;
1285
+ let e = re(this.state.block, n.originalIndex, r), [t] = a.splice(n.originalIndex, 1);
1286
+ a.splice(r, 0, t), this.editor.updateBlock(this.state.block, {
1287
+ type: "table",
1288
+ content: {
1289
+ ...this.state.block.content,
1290
+ columnWidths: a,
1291
+ rows: e
1292
+ }
1293
+ });
1294
+ }
1295
+ return this.editor.setTextCursorPosition(this.state.block.id), !0;
1296
+ };
1297
+ update() {
1298
+ if (!this.state || !this.state.show) return;
1299
+ if (this.state.block = this.editor.getBlock(this.state.block.id), !this.state.block || this.state.block.type !== "table" || !this.tableElement?.isConnected) {
1300
+ this.state.show = !1, this.state.showAddOrRemoveRowsButton = !1, this.state.showAddOrRemoveColumnsButton = !1, this.emitUpdate();
1301
+ return;
1302
+ }
1303
+ let { height: e, width: t } = d(this.state.block);
1304
+ this.state.rowIndex !== void 0 && this.state.colIndex !== void 0 && (this.state.rowIndex >= e && (this.state.rowIndex = e - 1), this.state.colIndex >= t && (this.state.colIndex = t - 1));
1305
+ let n = this.tableElement.querySelector("tbody");
1306
+ if (!n) throw Error("Table block does not contain a 'tbody' HTML element. This should never happen.");
1307
+ if (this.state.rowIndex !== void 0 && this.state.colIndex !== void 0) {
1308
+ let e = n.children[this.state.rowIndex].children[this.state.colIndex];
1309
+ e ? this.state.referencePosCell = e.getBoundingClientRect() : (this.state.rowIndex = void 0, this.state.colIndex = void 0);
1310
+ }
1311
+ this.state.referencePosTable = n.getBoundingClientRect(), this.emitUpdate();
1312
+ }
1313
+ destroy() {
1314
+ this.pmView.dom.removeEventListener("mousemove", this.mouseMoveHandler), window.removeEventListener("mouseup", this.mouseUpHandler), this.pmView.dom.removeEventListener("mousedown", this.viewMousedownHandler), this.pmView.root.removeEventListener("dragover", this.dragOverHandler), this.pmView.root.removeEventListener("drop", this.dropHandler);
1315
+ }
1316
+ }, $ = new w("TableHandlesPlugin"), It = y(({ editor: e }) => {
1317
+ let t, n = v(void 0);
1318
+ return {
1319
+ key: "tableHandles",
1320
+ store: n,
1321
+ prosemirrorPlugins: [new C({
1322
+ key: $,
1323
+ view: (r) => (t = new Q(e, r, (e) => {
1324
+ n.setState(e.block ? {
1325
+ ...e,
1326
+ draggingState: e.draggingState ? { ...e.draggingState } : void 0
1327
+ } : void 0);
1328
+ }), t),
1329
+ props: { decorations: (e) => {
1330
+ if (t === void 0 || t.state === void 0 || t.state.draggingState === void 0 || t.tablePos === void 0) return;
1331
+ let n = t.state.draggingState.draggedCellOrientation === "row" ? t.state.rowIndex : t.state.colIndex;
1332
+ if (n === void 0) return;
1333
+ let r = [], { block: i, draggingState: s } = t.state, { originalIndex: u, draggedCellOrientation: d } = s;
1334
+ if (n === u || !i || d === "row" && !l(i, u, n) || d === "col" && !c(i, u, n)) return A.create(e.doc, r);
1335
+ let f = e.doc.resolve(t.tablePos + 1);
1336
+ return t.state.draggingState.draggedCellOrientation === "row" ? o(t.state.block, n).forEach(({ row: t, col: i }) => {
1337
+ let a = e.doc.resolve(f.posAtIndex(t) + 1), o = e.doc.resolve(a.posAtIndex(i) + 1), s = o.node(), c = o.pos + (n > u ? s.nodeSize - 2 : 0);
1338
+ r.push(k.widget(c, () => {
1339
+ let e = document.createElement("div");
1340
+ return e.className = "bn-table-drop-cursor", e.style.left = "0", e.style.right = "0", n > u ? e.style.bottom = "-2px" : e.style.top = "-3px", e.style.height = "4px", e;
1341
+ }));
1342
+ }) : a(t.state.block, n).forEach(({ row: t, col: i }) => {
1343
+ let a = e.doc.resolve(f.posAtIndex(t) + 1), o = e.doc.resolve(a.posAtIndex(i) + 1), s = o.node(), c = o.pos + (n > u ? s.nodeSize - 2 : 0);
1344
+ r.push(k.widget(c, () => {
1345
+ let e = document.createElement("div");
1346
+ return e.className = "bn-table-drop-cursor", e.style.top = "0", e.style.bottom = "0", n > u ? e.style.right = "-2px" : e.style.left = "-3px", e.style.width = "4px", e;
1347
+ }));
1348
+ }), A.create(e.doc, r);
1349
+ } }
1350
+ })],
1351
+ colDragStart(n) {
1352
+ if (t === void 0 || t.state === void 0 || t.state.colIndex === void 0) throw Error("Attempted to drag table column, but no table block was hovered prior.");
1353
+ t.state.draggingState = {
1354
+ draggedCellOrientation: "col",
1355
+ originalIndex: t.state.colIndex,
1356
+ mousePos: n.clientX
1357
+ }, t.emitUpdate(), e.transact((e) => e.setMeta($, {
1358
+ draggedCellOrientation: t.state.draggingState.draggedCellOrientation,
1359
+ originalIndex: t.state.colIndex,
1360
+ newIndex: t.state.colIndex,
1361
+ tablePos: t.tablePos
1362
+ })), !e.headless && (Mt(e.prosemirrorView.root), n.dataTransfer.setDragImage(X, 0, 0), n.dataTransfer.effectAllowed = "move");
1363
+ },
1364
+ rowDragStart(n) {
1365
+ if (t.state === void 0 || t.state.rowIndex === void 0) throw Error("Attempted to drag table row, but no table block was hovered prior.");
1366
+ t.state.draggingState = {
1367
+ draggedCellOrientation: "row",
1368
+ originalIndex: t.state.rowIndex,
1369
+ mousePos: n.clientY
1370
+ }, t.emitUpdate(), e.transact((e) => e.setMeta($, {
1371
+ draggedCellOrientation: t.state.draggingState.draggedCellOrientation,
1372
+ originalIndex: t.state.rowIndex,
1373
+ newIndex: t.state.rowIndex,
1374
+ tablePos: t.tablePos
1375
+ })), !e.headless && (Mt(e.prosemirrorView.root), n.dataTransfer.setDragImage(X, 0, 0), n.dataTransfer.effectAllowed = "copyMove");
1376
+ },
1377
+ dragEnd() {
1378
+ if (t.state === void 0) throw Error("Attempted to drag table row, but no table block was hovered prior.");
1379
+ t.state.draggingState = void 0, t.emitUpdate(), e.transact((e) => e.setMeta($, null)), !e.headless && Nt(e.prosemirrorView.root);
1380
+ },
1381
+ freezeHandles() {
1382
+ t.menuFrozen = !0;
1383
+ },
1384
+ unfreezeHandles() {
1385
+ t.menuFrozen = !1;
1386
+ },
1387
+ hideHandlesIfNotFrozen() {
1388
+ !t.menuFrozen && t.state?.show && (t.state.show = !1, t.state.showAddOrRemoveRowsButton = !1, t.state.showAddOrRemoveColumnsButton = !1, t.emitUpdate());
1389
+ },
1390
+ getCellsAtRowHandle(e, t) {
1391
+ return o(e, t);
1392
+ },
1393
+ getCellsAtColumnHandle(e, t) {
1394
+ return a(e, t);
1395
+ },
1396
+ setCellSelection(e, n, r = n) {
1397
+ if (!t) throw Error("Table handles view not initialized");
1398
+ let i = e.doc.resolve(t.tablePos + 1), a = e.doc.resolve(i.posAtIndex(n.row) + 1), o = e.doc.resolve(a.posAtIndex(n.col)), s = e.doc.resolve(i.posAtIndex(r.row) + 1), c = e.doc.resolve(s.posAtIndex(r.col)), l = e.tr;
1399
+ return l.setSelection(new pe(o, c)), e.apply(l);
1400
+ },
1401
+ addRowOrColumn(t, n) {
1402
+ e.exec((e, r) => {
1403
+ let i = this.setCellSelection(e, n.orientation === "row" ? {
1404
+ row: t,
1405
+ col: 0
1406
+ } : {
1407
+ row: 0,
1408
+ col: t
1409
+ });
1410
+ return n.orientation === "row" ? n.side === "above" ? _e(i, r) : ge(i, r) : n.side === "left" ? he(i, r) : me(i, r);
1411
+ });
1412
+ },
1413
+ removeRowOrColumn(t, n) {
1414
+ return n === "row" ? e.exec((e, n) => ye(this.setCellSelection(e, {
1415
+ row: t,
1416
+ col: 0
1417
+ }), n)) : e.exec((e, n) => ve(this.setCellSelection(e, {
1418
+ row: 0,
1419
+ col: t
1420
+ }), n));
1421
+ },
1422
+ mergeCells(t) {
1423
+ return e.exec((e, n) => be(t ? this.setCellSelection(e, t.relativeStartCell, t.relativeEndCell) : e, n));
1424
+ },
1425
+ splitCell(t) {
1426
+ return e.exec((e, n) => xe(t ? this.setCellSelection(e, t) : e, n));
1427
+ },
1428
+ getCellSelection() {
1429
+ return e.transact((e) => {
1430
+ let t = e.selection, n = t.$from, r = t.$to;
1431
+ if (m(t)) {
1432
+ let { ranges: e } = t;
1433
+ e.forEach((e) => {
1434
+ n = e.$from.min(n ?? e.$from), r = e.$to.max(r ?? e.$to);
1435
+ });
1436
+ } else if (n = e.doc.resolve(t.$from.pos - t.$from.parentOffset - 1), r = e.doc.resolve(t.$to.pos - t.$to.parentOffset - 1), n.pos === 0 || r.pos === 0) return;
1437
+ let i = e.doc.resolve(n.pos - n.parentOffset - 1), a = e.doc.resolve(r.pos - r.parentOffset - 1), o = e.doc.resolve(i.pos - i.parentOffset - 1), s = n.index(i.depth), c = i.index(o.depth), l = r.index(a.depth), u = a.index(o.depth), d = [];
1438
+ for (let e = c; e <= u; e++) for (let t = s; t <= l; t++) d.push({
1439
+ row: e,
1440
+ col: t
1441
+ });
1442
+ return {
1443
+ from: {
1444
+ row: c,
1445
+ col: s
1446
+ },
1447
+ to: {
1448
+ row: u,
1449
+ col: l
1450
+ },
1451
+ cells: d
1452
+ };
1453
+ });
1454
+ },
1455
+ getMergeDirection(t) {
1456
+ return e.transact((e) => {
1457
+ let n = m(e.selection) ? e.selection : void 0;
1458
+ if (!n || !t || n.ranges.length <= 1) return;
1459
+ let r = this.getCellSelection();
1460
+ if (r) return s(r.from, r.to, t) ? "vertical" : "horizontal";
1461
+ });
1462
+ },
1463
+ cropEmptyRowsOrColumns(e, t) {
1464
+ return i(e, t);
1465
+ },
1466
+ addRowsOrColumns(e, t, n) {
1467
+ return ee(e, t, n);
1468
+ }
1469
+ };
1470
+ }), Lt = new w("trailingNode"), Rt = y(() => ({
1471
+ key: "trailingNode",
1472
+ prosemirrorPlugins: [new C({
1473
+ key: Lt,
1474
+ appendTransaction: (e, t, n) => {
1475
+ let { doc: r, tr: i, schema: a } = n, o = Lt.getState(n), s = r.content.size - 2, c = a.nodes.blockContainer, l = a.nodes.paragraph;
1476
+ if (o) return i.insert(s, c.create(void 0, l.create()));
1477
+ },
1478
+ state: {
1479
+ init: (e, t) => {},
1480
+ apply: (e, t) => {
1481
+ if (!e.docChanged) return t;
1482
+ let n = e.doc.lastChild;
1483
+ if (!n || n.type.name !== "blockGroup") throw Error("Expected blockGroup");
1484
+ if (n = n.lastChild, !n || n.type.name !== "blockContainer") return !0;
1485
+ let r = n.firstChild;
1486
+ if (!r) throw Error("Expected blockContent");
1487
+ return n.nodeSize > 4 || r.type.spec.content !== "inline*";
1488
+ }
1489
+ }
1490
+ })]
1491
+ }));
1492
+ //#endregion
1493
+ export { $e as C, Xe as D, F as E, N as O, tt as S, I as T, ut as _, jt as a, ot as b, Ot as c, H as d, vt as f, dt as g, ft as h, $ as i, M as k, U as l, mt as m, It as n, kt as o, gt as p, Q as r, Dt as s, Rt as t, St as u, lt as v, L as w, st as x, ct as y };
1494
+
1495
+ //# sourceMappingURL=extensions-3nf9PPhA.js.map