@blocknote/core 0.47.2 → 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 (124) 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 -4216
  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/api/parsers/html/parseHTML.ts +2 -0
  56. package/src/api/parsers/html/util/normalizeWhitespace.ts +87 -0
  57. package/src/blocks/File/helpers/render/createResizableFileBlockWrapper.ts +17 -23
  58. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +346 -0
  59. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +143 -71
  60. package/src/editor/Block.css +5 -8
  61. package/src/editor/BlockNoteEditor.ts +38 -1
  62. package/src/editor/editor.css +0 -20
  63. package/src/editor/managers/ExtensionManager/extensions.ts +12 -1
  64. package/src/editor/performance.test.ts +134 -0
  65. package/src/extensions/Collaboration/ForkYDoc.test.ts +115 -103
  66. package/src/extensions/Placeholder/Placeholder.ts +1 -1
  67. package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +86 -0
  68. package/src/extensions/PreviousBlockType/PreviousBlockType.ts +33 -49
  69. package/src/extensions/SideMenu/SideMenu.ts +14 -8
  70. package/src/extensions/TableHandles/TableHandles.ts +14 -0
  71. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +57 -17
  72. package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +9 -8
  73. package/src/index.ts +1 -1
  74. package/src/schema/blocks/createSpec.ts +6 -2
  75. package/src/schema/inlineContent/types.ts +0 -1
  76. package/src/vite-env.d.ts +6 -0
  77. package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.d.ts +14 -1
  78. package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.test.d.ts +1 -0
  79. package/types/src/api/parsers/html/util/normalizeWhitespace.d.ts +6 -0
  80. package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.d.ts +1 -0
  81. package/types/src/editor/BlockNoteEditor.d.ts +13 -0
  82. package/types/src/editor/performance.test.d.ts +1 -0
  83. package/types/src/extensions/PreviousBlockType/PreviousBlockType.test.d.ts +1 -0
  84. package/types/src/extensions/SideMenu/SideMenu.d.ts +6 -0
  85. package/types/src/extensions/TableHandles/TableHandles.d.ts +6 -0
  86. package/dist/BlockNoteExtension-BWw0r8Gy.cjs +0 -2
  87. package/dist/BlockNoteExtension-BWw0r8Gy.cjs.map +0 -1
  88. package/dist/BlockNoteExtension-C2X7LW-V.js +0 -25
  89. package/dist/BlockNoteExtension-C2X7LW-V.js.map +0 -1
  90. package/dist/BlockNoteSchema-CCs_V3lo.cjs +0 -2
  91. package/dist/BlockNoteSchema-CCs_V3lo.cjs.map +0 -1
  92. package/dist/BlockNoteSchema-ooiKsd5B.js +0 -270
  93. package/dist/BlockNoteSchema-ooiKsd5B.js.map +0 -1
  94. package/dist/EventEmitter-CLwfmbqG.cjs +0 -2
  95. package/dist/EventEmitter-CLwfmbqG.cjs.map +0 -1
  96. package/dist/EventEmitter-CjSwpTbz.js +0 -27
  97. package/dist/EventEmitter-CjSwpTbz.js.map +0 -1
  98. package/dist/ShowSelection-B0ch3unP.js +0 -51
  99. package/dist/ShowSelection-B0ch3unP.js.map +0 -1
  100. package/dist/ShowSelection-BxnbRvy4.cjs +0 -2
  101. package/dist/ShowSelection-BxnbRvy4.cjs.map +0 -1
  102. package/dist/TrailingNode-GzE59m_7.js +0 -2288
  103. package/dist/TrailingNode-GzE59m_7.js.map +0 -1
  104. package/dist/TrailingNode-n0WdMPUl.cjs +0 -2
  105. package/dist/TrailingNode-n0WdMPUl.cjs.map +0 -1
  106. package/dist/blockToNode-BNoNIXU7.js +0 -1140
  107. package/dist/blockToNode-BNoNIXU7.js.map +0 -1
  108. package/dist/blockToNode-CumVjgem.cjs +0 -7
  109. package/dist/blockToNode-CumVjgem.cjs.map +0 -1
  110. package/dist/blocknote.cjs.map +0 -1
  111. package/dist/blocknote.js.map +0 -1
  112. package/dist/blocks.cjs.map +0 -1
  113. package/dist/blocks.js.map +0 -1
  114. package/dist/defaultBlocks-Dg9kQWXm.cjs +0 -6
  115. package/dist/defaultBlocks-Dg9kQWXm.cjs.map +0 -1
  116. package/dist/defaultBlocks-ZzGbYgQn.js +0 -3284
  117. package/dist/defaultBlocks-ZzGbYgQn.js.map +0 -1
  118. package/dist/en-Cl87Uuyf.cjs +0 -2
  119. package/dist/en-Cl87Uuyf.cjs.map +0 -1
  120. package/dist/en-njEqD7AG.js +0 -408
  121. package/dist/en-njEqD7AG.js.map +0 -1
  122. package/dist/extensions.cjs.map +0 -1
  123. package/dist/extensions.js.map +0 -1
  124. package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/blocknote.js CHANGED
@@ -1,4216 +1,7 @@
1
- var Fe = Object.defineProperty;
2
- var Ve = (n, e, t) => e in n ? Fe(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var k = (n, e, t) => Ve(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { Slice as F, Fragment as w, DOMSerializer as me, DOMParser as Ue, Node as ze } from "prosemirror-model";
5
- import { ReplaceStep as Re, ReplaceAroundStep as W } from "prosemirror-transform";
6
- import { n as q, i as V, g as E, b as Z, a as C, t as Ge, U, q as D, r as z, d as je, s as We, u as qe, v, w as B, x as ke, y as Ke, z as be, A as K } from "./blockToNode-BNoNIXU7.js";
7
- import { B as ms, G as ks, C as bs, D as gs, N as Bs, E as ys, O as Cs, F as Ss, H as xs, I as Es, L as Ps, J as Ts, M as Ms, K as ws } from "./blockToNode-BNoNIXU7.js";
8
- import { ak as G, al as Je, am as Ye, an as Qe, aj as P, a as Xe, ao as Ze, ap as et, a5 as tt, a8 as J, aq as ot, ar as nt, a6 as st, as as ee, a9 as ge, at as rt } from "./defaultBlocks-ZzGbYgQn.js";
9
- import { aw as Is, av as As, E as Ns, F as _s, r as Ls, N as Ds, a4 as Os, ad as $s, aG as Hs, ax as Fs, b as Vs, d as Us, e as zs, a0 as Rs, aM as Gs, au as js, c as Ws, f as qs, ag as Ks, ah as Js, aB as Ys, x as Qs, y as Xs, A as Zs, z as er, g as tr, h as or, T as nr, j as sr, k as rr, l as ir, n as ar, o as cr, q as lr, s as dr, w as ur, aC as pr, aH as fr, B as hr, C as mr, H as kr, I as br, J as gr, K as Br, aE as yr, aI as Cr, M as Sr, D as xr, G as Er, S as Pr, O as Tr, Q as Mr, W as wr, U as vr, _ as Ir, Z as Ar, a2 as Nr, Y as _r, X as Lr, R as Dr, $ as Or, m as $r, aN as Hr, ac as Fr, aK as Vr, az as Ur, ab as zr, af as Rr, i as Gr, ay as jr, aD as Wr, ae as qr, a7 as Kr, t as Jr, u as Yr, v as Qr, aa as Xr, aJ as Zr, ai as ei, aL as ti, a1 as oi, V as ni, p as si, a3 as ri, aF as ii, L as ai, aO as ci, P as li, aA as di } from "./defaultBlocks-ZzGbYgQn.js";
10
- import { l as it, m as Be, n as at, o as ct, p as lt, d as Y, F as dt, Y as ut, a as pt, b as ft, S as ht, B as ye, c as mt, L as kt, N as bt, P as gt, h as Bt, k as yt, H as Ct, j as St, f as xt, V as Et, e as Pt } from "./TrailingNode-GzE59m_7.js";
11
- import { D as pi, g as fi, T as hi, i as mi, s as ki, t as bi } from "./TrailingNode-GzE59m_7.js";
12
- import { s as Tt, B as Mt } from "./BlockNoteSchema-ooiKsd5B.js";
13
- import { C as Bi, b as yi, c as Ci, a as Si, g as xi, u as Ei, w as Pi } from "./BlockNoteSchema-ooiKsd5B.js";
14
- import { Node as O, Extension as T, mergeAttributes as wt, Mark as te, extensions as N, isNodeSelection as vt, posToDOMRect as It, selectionToInsertionEnd as At, findParentNodeClosestToPos as Nt, getSchema as _t, createDocument as Lt, Editor as Dt } from "@tiptap/core";
15
- import { E as Ce } from "./EventEmitter-CjSwpTbz.js";
16
- import { Fragment as R, Slice as j } from "@tiptap/pm/model";
17
- import { e as Ot } from "./en-njEqD7AG.js";
18
- import { inputRules as $t, InputRule as Ht } from "@handlewithcare/prosemirror-inputrules";
19
- import { keymap as Ft } from "@tiptap/pm/keymap";
20
- import { c as Vt, o as Ut } from "./BlockNoteExtension-C2X7LW-V.js";
21
- import { a as Mi } from "./BlockNoteExtension-C2X7LW-V.js";
22
- import { Gapcursor as zt } from "@tiptap/extensions/gap-cursor";
23
- import { Link as Rt } from "@tiptap/extension-link";
24
- import { Text as Gt } from "@tiptap/extension-text";
25
- import { NodeSelection as $, TextSelection as S, Plugin as oe } from "prosemirror-state";
26
- import { CellSelection as ne, TableMap as re } from "prosemirror-tables";
27
- import { S as jt } from "./ShowSelection-B0ch3unP.js";
28
- import Wt from "remark-gfm";
29
- import qt from "remark-parse";
30
- import Kt, { defaultHandlers as ie } from "remark-rehype";
31
- import Jt from "rehype-stringify";
32
- import { unified as Yt } from "unified";
33
- import { TextSelection as Qt } from "@tiptap/pm/state";
34
- function Xt(n, e) {
35
- const t = [
36
- {
37
- tag: `[data-inline-content-type="${n.type}"]`,
38
- contentElement: (o) => {
39
- const s = o;
40
- return s.matches("[data-editable]") ? s : s.querySelector("[data-editable]") || s;
41
- }
42
- }
43
- ];
44
- return e && t.push({
45
- tag: "*",
46
- getAttrs(o) {
47
- if (typeof o == "string")
48
- return !1;
49
- const s = e == null ? void 0 : e(o);
50
- return s === void 0 ? !1 : s;
51
- }
52
- }), t;
53
- }
54
- function ls(n, e) {
55
- var o;
56
- const t = O.create({
57
- name: n.type,
58
- inline: !0,
59
- group: "inline",
60
- draggable: (o = e.meta) == null ? void 0 : o.draggable,
61
- selectable: n.content === "styled",
62
- atom: n.content === "none",
63
- content: n.content === "styled" ? "inline*" : "",
64
- addAttributes() {
65
- return Ye(n.propSchema);
66
- },
67
- addKeyboardShortcuts() {
68
- return Je(n);
69
- },
70
- parseHTML() {
71
- return Xt(
72
- n,
73
- e.parse
74
- );
75
- },
76
- renderHTML({ node: s }) {
77
- const r = this.options.editor, i = e.render.call(
78
- { renderType: "dom", props: void 0 },
79
- q(
80
- s,
81
- r.schema.inlineContentSchema,
82
- r.schema.styleSchema
83
- ),
84
- // TODO: fix cast
85
- () => {
86
- },
87
- r
88
- );
89
- return G(
90
- i,
91
- n.type,
92
- s.attrs,
93
- n.propSchema
94
- );
95
- },
96
- addNodeView() {
97
- return (s) => {
98
- const { node: r, getPos: i } = s, l = this.options.editor, a = e.render.call(
99
- { renderType: "nodeView", props: s },
100
- q(
101
- r,
102
- l.schema.inlineContentSchema,
103
- l.schema.styleSchema
104
- ),
105
- // TODO: fix cast
106
- (c) => {
107
- const d = V([c], l.pmSchema), u = i();
108
- u && l.transact(
109
- (p) => p.replaceWith(u, u + r.nodeSize, d)
110
- );
111
- },
112
- l
113
- );
114
- return G(
115
- a,
116
- n.type,
117
- r.attrs,
118
- n.propSchema
119
- );
120
- };
121
- }
122
- });
123
- return Qe(
124
- t,
125
- n.propSchema,
126
- {
127
- ...e,
128
- toExternalHTML: e.toExternalHTML,
129
- render(s, r, i) {
130
- const l = e.render(
131
- s,
132
- r,
133
- i
134
- );
135
- return G(
136
- l,
137
- n.type,
138
- s.props,
139
- n.propSchema
140
- );
141
- }
142
- }
143
- );
144
- }
145
- function Zt(n, e, t, o = "before") {
146
- const s = typeof t == "string" ? t : t.id, r = E(n), i = e.map(
147
- (d) => Z(d, r)
148
- ), l = P(s, n.doc);
149
- if (!l)
150
- throw new Error(`Block with ID ${s} not found`);
151
- let a = l.posBeforeNode;
152
- return o === "after" && (a += l.node.nodeSize), n.step(
153
- new Re(a, a, new F(w.from(i), 0, 0))
154
- ), i.map(
155
- (d) => C(d, r)
156
- );
157
- }
158
- function Q(n) {
159
- if (!n || n.type.name !== "column")
160
- throw new Error("Invalid columnPos: does not point to column node.");
161
- const e = n.firstChild;
162
- if (!e)
163
- throw new Error("Invalid column: does not have child node.");
164
- const t = e.firstChild;
165
- if (!t)
166
- throw new Error("Invalid blockContainer: does not have child node.");
167
- return n.childCount === 1 && e.childCount === 1 && t.type.name === "paragraph" && t.content.content.length === 0;
168
- }
169
- function eo(n, e) {
170
- const t = n.doc.resolve(e), o = t.nodeAfter;
171
- if (!o || o.type.name !== "columnList")
172
- throw new Error(
173
- "Invalid columnListPos: does not point to columnList node."
174
- );
175
- for (let s = o.childCount - 1; s >= 0; s--) {
176
- const r = n.doc.resolve(t.pos + 1).posAtIndex(s), l = n.doc.resolve(r).nodeAfter;
177
- if (!l || l.type.name !== "column")
178
- throw new Error("Invalid columnPos: does not point to column node.");
179
- Q(l) && n.delete(r, r + l.nodeSize);
180
- }
181
- }
182
- function H(n, e) {
183
- eo(n, e);
184
- const o = n.doc.resolve(e).nodeAfter;
185
- if (!o || o.type.name !== "columnList")
186
- throw new Error(
187
- "Invalid columnListPos: does not point to columnList node."
188
- );
189
- if (o.childCount > 2)
190
- return;
191
- if (o.childCount < 2)
192
- throw new Error("Invalid columnList: contains fewer than two children.");
193
- const s = e + 1, i = n.doc.resolve(s).nodeAfter, l = e + o.nodeSize - 1, c = n.doc.resolve(l).nodeBefore;
194
- if (!i || !c)
195
- throw new Error("Invalid columnList: does not contain children.");
196
- const d = Q(i), u = Q(c);
197
- if (d && u) {
198
- n.delete(e, e + o.nodeSize);
199
- return;
200
- }
201
- if (d) {
202
- n.step(
203
- new W(
204
- // Replaces `columnList`.
205
- e,
206
- e + o.nodeSize,
207
- // Replaces with content of last `column`.
208
- l - c.nodeSize + 1,
209
- l - 1,
210
- // Doesn't append anything.
211
- F.empty,
212
- 0,
213
- !1
214
- )
215
- );
216
- return;
217
- }
218
- if (u) {
219
- n.step(
220
- new W(
221
- // Replaces `columnList`.
222
- e,
223
- e + o.nodeSize,
224
- // Replaces with content of first `column`.
225
- s + 1,
226
- s + i.nodeSize - 1,
227
- // Doesn't append anything.
228
- F.empty,
229
- 0,
230
- !1
231
- )
232
- );
233
- return;
234
- }
235
- }
236
- function ae(n, e, t) {
237
- const o = E(n), s = t.map(
238
- (u) => Z(u, o)
239
- ), r = new Set(
240
- e.map(
241
- (u) => typeof u == "string" ? u : u.id
242
- )
243
- ), i = [], l = /* @__PURE__ */ new Set(), a = typeof e[0] == "string" ? e[0] : e[0].id;
244
- let c = 0;
245
- if (n.doc.descendants((u, p) => {
246
- if (r.size === 0)
247
- return !1;
248
- if (!u.type.isInGroup("bnBlock") || !r.has(u.attrs.id))
249
- return !0;
250
- if (i.push(C(u, o)), r.delete(u.attrs.id), t.length > 0 && u.attrs.id === a) {
251
- const b = n.doc.nodeSize;
252
- n.insert(p, s);
253
- const g = n.doc.nodeSize;
254
- c += b - g;
255
- }
256
- const h = n.doc.nodeSize, f = n.doc.resolve(p - c);
257
- f.node().type.name === "column" ? l.add(f.before(-1)) : f.node().type.name === "columnList" && l.add(f.before()), f.node().type.name === "blockGroup" && f.node(f.depth - 1).type.name !== "doc" && f.node().childCount === 1 ? n.delete(f.before(), f.after()) : n.delete(p - c, p - c + u.nodeSize);
258
- const m = n.doc.nodeSize;
259
- return c += h - m, !1;
260
- }), r.size > 0) {
261
- const u = [...r].join(`
262
- `);
263
- throw Error(
264
- "Blocks with the following IDs could not be found in the editor: " + u
265
- );
266
- }
267
- return l.forEach((u) => H(n, u)), { insertedBlocks: s.map(
268
- (u) => C(u, o)
269
- ), removedBlocks: i };
270
- }
271
- function to(n, e, t, o, s) {
272
- let r;
273
- if (e)
274
- if (typeof e == "string")
275
- r = V([e], n.pmSchema, o);
276
- else if (Array.isArray(e))
277
- r = V(e, n.pmSchema, o);
278
- else if (e.type === "tableContent")
279
- r = Ge(e, n.pmSchema);
280
- else
281
- throw new U(e.type);
282
- else throw new Error("blockContent is required");
283
- const l = ((s == null ? void 0 : s.document) ?? document).createDocumentFragment();
284
- for (const a of r)
285
- if (a.type.name !== "text" && n.schema.inlineContentSchema[a.type.name]) {
286
- const c = n.schema.inlineContentSpecs[a.type.name].implementation;
287
- if (c) {
288
- const d = q(
289
- a,
290
- n.schema.inlineContentSchema,
291
- n.schema.styleSchema
292
- ), u = c.render.call(
293
- {
294
- renderType: "dom",
295
- props: void 0
296
- },
297
- d,
298
- () => {
299
- },
300
- n
301
- );
302
- if (u) {
303
- if (l.appendChild(u.dom), u.contentDOM) {
304
- const p = t.serializeFragment(
305
- a.content,
306
- s
307
- );
308
- u.contentDOM.dataset.editable = "", u.contentDOM.appendChild(p);
309
- }
310
- continue;
311
- }
312
- }
313
- } else if (a.type.name === "text") {
314
- let c = document.createTextNode(
315
- a.textContent
316
- );
317
- for (const d of a.marks.toReversed())
318
- if (d.type.name in n.schema.styleSpecs) {
319
- const u = n.schema.styleSpecs[d.type.name].implementation.render(d.attrs.stringValue, n);
320
- u.contentDOM.appendChild(c), c = u.dom;
321
- } else {
322
- const u = d.type.spec.toDOM(d, !0), p = me.renderSpec(document, u);
323
- p.contentDOM.appendChild(c), c = p.dom;
324
- }
325
- l.appendChild(c);
326
- } else {
327
- const c = t.serializeFragment(
328
- w.from([a]),
329
- s
330
- );
331
- l.appendChild(c);
332
- }
333
- return l;
334
- }
335
- function oo(n, e, t, o) {
336
- var u, p, h, f, m;
337
- const s = n.pmSchema.nodes.blockContainer, r = e.props || {};
338
- for (const [b, g] of Object.entries(
339
- n.schema.blockSchema[e.type].propSchema
340
- ))
341
- !(b in r) && g.default !== void 0 && (r[b] = g.default);
342
- const i = e.children || [], a = n.blockImplementations[e.type].implementation.render.call(
343
- {
344
- renderType: "dom",
345
- props: void 0
346
- },
347
- { ...e, props: r, children: i },
348
- n
349
- );
350
- if (a.contentDOM && e.content) {
351
- const b = to(
352
- n,
353
- e.content,
354
- // TODO
355
- t,
356
- e.type,
357
- o
358
- );
359
- a.contentDOM.appendChild(b);
360
- }
361
- if (n.pmSchema.nodes[e.type].isInGroup("bnBlock")) {
362
- if (e.children && e.children.length > 0) {
363
- const b = Se(
364
- n,
365
- e.children,
366
- t,
367
- o
368
- );
369
- (u = a.contentDOM) == null || u.append(b);
370
- }
371
- return a.dom;
372
- }
373
- const d = (h = (p = s.spec) == null ? void 0 : p.toDOM) == null ? void 0 : h.call(
374
- p,
375
- s.create({
376
- id: e.id,
377
- ...r
378
- })
379
- );
380
- return (f = d.contentDOM) == null || f.appendChild(a.dom), e.children && e.children.length > 0 && ((m = d.contentDOM) == null || m.appendChild(
381
- xe(n, e.children, t, o)
382
- )), d.dom;
383
- }
384
- function Se(n, e, t, o) {
385
- const r = ((o == null ? void 0 : o.document) ?? document).createDocumentFragment();
386
- for (const i of e) {
387
- const l = oo(n, i, t, o);
388
- r.appendChild(l);
389
- }
390
- return r;
391
- }
392
- const xe = (n, e, t, o) => {
393
- var l;
394
- const s = n.pmSchema.nodes.blockGroup, r = s.spec.toDOM(s.create({})), i = Se(n, e, t, o);
395
- return (l = r.contentDOM) == null || l.appendChild(i), r.dom;
396
- }, no = (n) => (n.querySelectorAll(
397
- '[data-content-type="numberedListItem"]'
398
- ).forEach((t) => {
399
- var s, r;
400
- const o = (r = (s = t.closest(".bn-block-outer")) == null ? void 0 : s.previousElementSibling) == null ? void 0 : r.querySelector(
401
- '[data-content-type="numberedListItem"]'
402
- );
403
- if (!o)
404
- t.setAttribute(
405
- "data-index",
406
- t.getAttribute("data-start") || "1"
407
- );
408
- else {
409
- const i = o.getAttribute("data-index");
410
- t.setAttribute(
411
- "data-index",
412
- (parseInt(i || "0") + 1).toString()
413
- );
414
- }
415
- }), n), so = (n) => (n.querySelectorAll(
416
- '[data-content-type="checkListItem"] input'
417
- ).forEach((t) => {
418
- t.disabled = !0;
419
- }), n), ro = (n) => (n.querySelectorAll(
420
- '.bn-toggle-wrapper[data-show-children="false"]'
421
- ).forEach((t) => {
422
- t.setAttribute("data-show-children", "true");
423
- }), n), io = (n) => (n.querySelectorAll('[data-content-type="table"] table').forEach((t) => {
424
- t.setAttribute(
425
- "style",
426
- `--default-cell-min-width: ${Xe}px;`
427
- ), t.setAttribute("data-show-children", "true");
428
- }), n), ao = (n) => (n.querySelectorAll('[data-content-type="table"] table').forEach((t) => {
429
- var r;
430
- const o = document.createElement("div");
431
- o.className = "tableWrapper";
432
- const s = document.createElement("div");
433
- s.className = "tableWrapper-inner", o.appendChild(s), (r = t.parentElement) == null || r.appendChild(o), o.appendChild(t);
434
- }), n), co = (n) => (n.querySelectorAll(
435
- ".bn-inline-content:empty"
436
- ).forEach((t) => {
437
- const o = document.createElement("span");
438
- o.className = "ProseMirror-trailingBreak", o.setAttribute("style", "display: inline-block;"), t.appendChild(o);
439
- }), n), lo = (n, e) => {
440
- const t = me.fromSchema(n), o = [
441
- no,
442
- so,
443
- ro,
444
- io,
445
- ao,
446
- co
447
- ];
448
- return {
449
- serializeBlocks: (s, r) => {
450
- let i = xe(
451
- e,
452
- s,
453
- t,
454
- r
455
- );
456
- for (const l of o)
457
- i = l(i);
458
- return i.outerHTML;
459
- }
460
- };
461
- };
462
- function uo(n) {
463
- return n.transact((e) => {
464
- const t = D(e.doc, e.selection.anchor);
465
- if (e.selection instanceof ne)
466
- return {
467
- type: "cell",
468
- anchorBlockId: t.node.attrs.id,
469
- anchorCellOffset: e.selection.$anchorCell.pos - t.posBeforeNode,
470
- headCellOffset: e.selection.$headCell.pos - t.posBeforeNode
471
- };
472
- if (e.selection instanceof $)
473
- return {
474
- type: "node",
475
- anchorBlockId: t.node.attrs.id
476
- };
477
- {
478
- const o = D(e.doc, e.selection.head);
479
- return {
480
- type: "text",
481
- anchorBlockId: t.node.attrs.id,
482
- headBlockId: o.node.attrs.id,
483
- anchorOffset: e.selection.anchor - t.posBeforeNode,
484
- headOffset: e.selection.head - o.posBeforeNode
485
- };
486
- }
487
- });
488
- }
489
- function po(n, e) {
490
- var s, r;
491
- const t = (s = P(e.anchorBlockId, n.doc)) == null ? void 0 : s.posBeforeNode;
492
- if (t === void 0)
493
- throw new Error(
494
- `Could not find block with ID ${e.anchorBlockId} to update selection`
495
- );
496
- let o;
497
- if (e.type === "cell")
498
- o = ne.create(
499
- n.doc,
500
- t + e.anchorCellOffset,
501
- t + e.headCellOffset
502
- );
503
- else if (e.type === "node")
504
- o = $.create(n.doc, t + 1);
505
- else {
506
- const i = (r = P(e.headBlockId, n.doc)) == null ? void 0 : r.posBeforeNode;
507
- if (i === void 0)
508
- throw new Error(
509
- `Could not find block with ID ${e.headBlockId} to update selection`
510
- );
511
- o = S.create(
512
- n.doc,
513
- t + e.anchorOffset,
514
- i + e.headOffset
515
- );
516
- }
517
- n.setSelection(o);
518
- }
519
- function X(n) {
520
- return n.map((e) => e.type === "columnList" ? e.children.map((t) => X(t.children)).flat() : {
521
- ...e,
522
- children: X(e.children)
523
- }).flat();
524
- }
525
- function Ee(n, e, t) {
526
- n.transact((o) => {
527
- var i;
528
- const s = ((i = n.getSelection()) == null ? void 0 : i.blocks) || [
529
- n.getTextCursorPosition().block
530
- ], r = uo(n);
531
- n.removeBlocks(s), n.insertBlocks(X(s), e, t), po(o, r);
532
- });
533
- }
534
- function Pe(n) {
535
- return !n || n.type !== "columnList";
536
- }
537
- function Te(n, e, t) {
538
- let o, s;
539
- if (e ? e.children.length > 0 ? (o = e.children[e.children.length - 1], s = "after") : (o = e, s = "before") : t && (o = t, s = "before"), !o || !s)
540
- return;
541
- const r = n.getParentBlock(o);
542
- return Pe(r) ? { referenceBlock: o, placement: s } : Te(
543
- n,
544
- s === "after" ? o : n.getPrevBlock(o),
545
- r
546
- );
547
- }
548
- function Me(n, e, t) {
549
- let o, s;
550
- if (e ? e.children.length > 0 ? (o = e.children[0], s = "before") : (o = e, s = "after") : t && (o = t, s = "after"), !o || !s)
551
- return;
552
- const r = n.getParentBlock(o);
553
- return Pe(r) ? { referenceBlock: o, placement: s } : Me(
554
- n,
555
- s === "before" ? o : n.getNextBlock(o),
556
- r
557
- );
558
- }
559
- function fo(n) {
560
- n.transact(() => {
561
- const e = n.getSelection(), t = (e == null ? void 0 : e.blocks[0]) || n.getTextCursorPosition().block, o = Te(
562
- n,
563
- n.getPrevBlock(t),
564
- n.getParentBlock(t)
565
- );
566
- o && Ee(
567
- n,
568
- o.referenceBlock,
569
- o.placement
570
- );
571
- });
572
- }
573
- function ho(n) {
574
- n.transact(() => {
575
- const e = n.getSelection(), t = (e == null ? void 0 : e.blocks[(e == null ? void 0 : e.blocks.length) - 1]) || n.getTextCursorPosition().block, o = Me(
576
- n,
577
- n.getNextBlock(t),
578
- n.getParentBlock(t)
579
- );
580
- o && Ee(
581
- n,
582
- o.referenceBlock,
583
- o.placement
584
- );
585
- });
586
- }
587
- function mo(n, e, t) {
588
- const { $from: o, $to: s } = n.selection, r = o.blockRange(
589
- s,
590
- (f) => f.childCount > 0 && (f.type.name === "blockGroup" || f.type.name === "column")
591
- // change necessary to not look at first item child type
592
- );
593
- if (!r)
594
- return !1;
595
- const i = r.startIndex;
596
- if (i === 0)
597
- return !1;
598
- const a = r.parent.child(i - 1);
599
- if (a.type !== e)
600
- return !1;
601
- const c = a.lastChild && a.lastChild.type === t, d = w.from(c ? e.create() : null), u = new F(
602
- w.from(
603
- e.create(null, w.from(t.create(null, d)))
604
- // change necessary to create "groupType" instead of parent.type
605
- ),
606
- c ? 3 : 1,
607
- 0
608
- ), p = r.start, h = r.end;
609
- return n.step(
610
- new W(
611
- p - (c ? 3 : 1),
612
- h,
613
- p,
614
- h,
615
- u,
616
- 1,
617
- !0
618
- )
619
- ).scrollIntoView(), !0;
620
- }
621
- function we(n) {
622
- return n.transact((e) => mo(
623
- e,
624
- n.pmSchema.nodes.blockContainer,
625
- n.pmSchema.nodes.blockGroup
626
- ));
627
- }
628
- function ko(n) {
629
- n._tiptapEditor.commands.liftListItem("blockContainer");
630
- }
631
- function bo(n) {
632
- return n.transact((e) => {
633
- const { bnBlock: t } = z(e);
634
- return e.doc.resolve(t.beforePos).nodeBefore !== null;
635
- });
636
- }
637
- function go(n) {
638
- return n.transact((e) => {
639
- const { bnBlock: t } = z(e);
640
- return e.doc.resolve(t.beforePos).depth > 1;
641
- });
642
- }
643
- function Bo(n, e) {
644
- const t = typeof e == "string" ? e : e.id, o = E(n), s = P(t, n);
645
- if (s)
646
- return C(s.node, o);
647
- }
648
- function yo(n, e) {
649
- const t = typeof e == "string" ? e : e.id, o = P(t, n), s = E(n);
650
- if (!o)
651
- return;
652
- const i = n.resolve(o.posBeforeNode).nodeBefore;
653
- if (i)
654
- return C(i, s);
655
- }
656
- function Co(n, e) {
657
- const t = typeof e == "string" ? e : e.id, o = P(t, n), s = E(n);
658
- if (!o)
659
- return;
660
- const i = n.resolve(
661
- o.posBeforeNode + o.node.nodeSize
662
- ).nodeAfter;
663
- if (i)
664
- return C(i, s);
665
- }
666
- function So(n, e) {
667
- const t = typeof e == "string" ? e : e.id, o = E(n), s = P(t, n);
668
- if (!s)
669
- return;
670
- const r = n.resolve(s.posBeforeNode), i = r.node(), l = r.node(-1), a = l.type.name !== "doc" ? i.type.name === "blockGroup" ? l : i : void 0;
671
- if (a)
672
- return C(a, o);
673
- }
674
- class xo {
675
- constructor(e) {
676
- this.editor = e;
677
- }
678
- /**
679
- * Gets a snapshot of all top-level (non-nested) blocks in the editor.
680
- * @returns A snapshot of all top-level (non-nested) blocks in the editor.
681
- */
682
- get document() {
683
- return this.editor.transact((e) => je(e.doc, this.editor.pmSchema));
684
- }
685
- /**
686
- * Gets a snapshot of an existing block from the editor.
687
- * @param blockIdentifier The identifier of an existing block that should be
688
- * retrieved.
689
- * @returns The block that matches the identifier, or `undefined` if no
690
- * matching block was found.
691
- */
692
- getBlock(e) {
693
- return this.editor.transact((t) => Bo(t.doc, e));
694
- }
695
- /**
696
- * Gets a snapshot of the previous sibling of an existing block from the
697
- * editor.
698
- * @param blockIdentifier The identifier of an existing block for which the
699
- * previous sibling should be retrieved.
700
- * @returns The previous sibling of the block that matches the identifier.
701
- * `undefined` if no matching block was found, or it's the first child/block
702
- * in the document.
703
- */
704
- getPrevBlock(e) {
705
- return this.editor.transact((t) => yo(t.doc, e));
706
- }
707
- /**
708
- * Gets a snapshot of the next sibling of an existing block from the editor.
709
- * @param blockIdentifier The identifier of an existing block for which the
710
- * next sibling should be retrieved.
711
- * @returns The next sibling of the block that matches the identifier.
712
- * `undefined` if no matching block was found, or it's the last child/block in
713
- * the document.
714
- */
715
- getNextBlock(e) {
716
- return this.editor.transact((t) => Co(t.doc, e));
717
- }
718
- /**
719
- * Gets a snapshot of the parent of an existing block from the editor.
720
- * @param blockIdentifier The identifier of an existing block for which the
721
- * parent should be retrieved.
722
- * @returns The parent of the block that matches the identifier. `undefined`
723
- * if no matching block was found, or the block isn't nested.
724
- */
725
- getParentBlock(e) {
726
- return this.editor.transact(
727
- (t) => So(t.doc, e)
728
- );
729
- }
730
- /**
731
- * Traverses all blocks in the editor depth-first, and executes a callback for each.
732
- * @param callback The callback to execute for each block. Returning `false` stops the traversal.
733
- * @param reverse Whether the blocks should be traversed in reverse order.
734
- */
735
- forEachBlock(e, t = !1) {
736
- const o = this.document.slice();
737
- t && o.reverse();
738
- function s(r) {
739
- for (const i of r) {
740
- if (e(i) === !1)
741
- return !1;
742
- const l = t ? i.children.slice().reverse() : i.children;
743
- if (!s(l))
744
- return !1;
745
- }
746
- return !0;
747
- }
748
- s(o);
749
- }
750
- /**
751
- * Inserts new blocks into the editor. If a block's `id` is undefined, BlockNote generates one automatically. Throws an
752
- * error if the reference block could not be found.
753
- * @param blocksToInsert An array of partial blocks that should be inserted.
754
- * @param referenceBlock An identifier for an existing block, at which the new blocks should be inserted.
755
- * @param placement Whether the blocks should be inserted just before, just after, or nested inside the
756
- * `referenceBlock`.
757
- */
758
- insertBlocks(e, t, o = "before") {
759
- return this.editor.transact(
760
- (s) => Zt(s, e, t, o)
761
- );
762
- }
763
- /**
764
- * Updates an existing block in the editor. Since updatedBlock is a PartialBlock object, some fields might not be
765
- * defined. These undefined fields are kept as-is from the existing block. Throws an error if the block to update could
766
- * not be found.
767
- * @param blockToUpdate The block that should be updated.
768
- * @param update A partial block which defines how the existing block should be changed.
769
- */
770
- updateBlock(e, t) {
771
- return this.editor.transact((o) => Ze(o, e, t));
772
- }
773
- /**
774
- * Removes existing blocks from the editor. Throws an error if any of the blocks could not be found.
775
- * @param blocksToRemove An array of identifiers for existing blocks that should be removed.
776
- */
777
- removeBlocks(e) {
778
- return this.editor.transact(
779
- (t) => ae(t, e, []).removedBlocks
780
- );
781
- }
782
- /**
783
- * Replaces existing blocks in the editor with new blocks. If the blocks that should be removed are not adjacent or
784
- * are at different nesting levels, `blocksToInsert` will be inserted at the position of the first block in
785
- * `blocksToRemove`. Throws an error if any of the blocks to remove could not be found.
786
- * @param blocksToRemove An array of blocks that should be replaced.
787
- * @param blocksToInsert An array of partial blocks to replace the old ones with.
788
- */
789
- replaceBlocks(e, t) {
790
- return this.editor.transact(
791
- (o) => ae(o, e, t)
792
- );
793
- }
794
- /**
795
- * Checks if the block containing the text cursor can be nested.
796
- */
797
- canNestBlock() {
798
- return bo(this.editor);
799
- }
800
- /**
801
- * Nests the block containing the text cursor into the block above it.
802
- */
803
- nestBlock() {
804
- we(this.editor);
805
- }
806
- /**
807
- * Checks if the block containing the text cursor is nested.
808
- */
809
- canUnnestBlock() {
810
- return go(this.editor);
811
- }
812
- /**
813
- * Lifts the block containing the text cursor out of its parent.
814
- */
815
- unnestBlock() {
816
- ko(this.editor);
817
- }
818
- /**
819
- * Moves the selected blocks up. If the previous block has children, moves
820
- * them to the end of its children. If there is no previous block, but the
821
- * current blocks share a common parent, moves them out of & before it.
822
- */
823
- moveBlocksUp() {
824
- return fo(this.editor);
825
- }
826
- /**
827
- * Moves the selected blocks down. If the next block has children, moves
828
- * them to the start of its children. If there is no next block, but the
829
- * current blocks share a common parent, moves them out of & after it.
830
- */
831
- moveBlocksDown() {
832
- return ho(this.editor);
833
- }
834
- }
835
- class Eo extends Ce {
836
- constructor(e) {
837
- super(), this.editor = e, e.on("create", () => {
838
- e._tiptapEditor.on(
839
- "update",
840
- ({ transaction: t, appendedTransactions: o }) => {
841
- this.emit("onChange", { editor: e, transaction: t, appendedTransactions: o });
842
- }
843
- ), e._tiptapEditor.on("selectionUpdate", ({ transaction: t }) => {
844
- this.emit("onSelectionChange", { editor: e, transaction: t });
845
- }), e._tiptapEditor.on("mount", () => {
846
- this.emit("onMount", { editor: e });
847
- }), e._tiptapEditor.on("unmount", () => {
848
- this.emit("onUnmount", { editor: e });
849
- });
850
- });
851
- }
852
- /**
853
- * Register a callback that will be called when the editor changes.
854
- */
855
- onChange(e, t = !0) {
856
- const o = ({
857
- transaction: s,
858
- appendedTransactions: r
859
- }) => {
860
- !t && ce(s) || e(this.editor, {
861
- getChanges() {
862
- return it(
863
- s,
864
- r
865
- );
866
- }
867
- });
868
- };
869
- return this.on("onChange", o), () => {
870
- this.off("onChange", o);
871
- };
872
- }
873
- /**
874
- * Register a callback that will be called when the selection changes.
875
- */
876
- onSelectionChange(e, t = !1) {
877
- const o = (s) => {
878
- !t && ce(s.transaction) || e(this.editor);
879
- };
880
- return this.on("onSelectionChange", o), () => {
881
- this.off("onSelectionChange", o);
882
- };
883
- }
884
- /**
885
- * Register a callback that will be called when the editor is mounted.
886
- */
887
- onMount(e) {
888
- return this.on("onMount", e), () => {
889
- this.off("onMount", e);
890
- };
891
- }
892
- /**
893
- * Register a callback that will be called when the editor is unmounted.
894
- */
895
- onUnmount(e) {
896
- return this.on("onUnmount", e), () => {
897
- this.off("onUnmount", e);
898
- };
899
- }
900
- }
901
- function ce(n) {
902
- return !!n.getMeta("y-sync$");
903
- }
904
- function Po(n) {
905
- return Array.prototype.indexOf.call(n.parentElement.childNodes, n);
906
- }
907
- function To(n) {
908
- return n.nodeType === 3 && !/\S/.test(n.nodeValue || "");
909
- }
910
- function Mo(n) {
911
- n.querySelectorAll("li > ul, li > ol").forEach((e) => {
912
- const t = Po(e), o = e.parentElement, s = Array.from(o.childNodes).slice(
913
- t + 1
914
- );
915
- e.remove(), s.forEach((r) => {
916
- r.remove();
917
- }), o.insertAdjacentElement("afterend", e), s.reverse().forEach((r) => {
918
- if (To(r))
919
- return;
920
- const i = document.createElement("li");
921
- i.append(r), e.insertAdjacentElement("afterend", i);
922
- }), o.childNodes.length === 0 && o.remove();
923
- });
924
- }
925
- function wo(n) {
926
- n.querySelectorAll("li + ul, li + ol").forEach((e) => {
927
- var r, i;
928
- const t = e.previousElementSibling, o = document.createElement("div");
929
- t.insertAdjacentElement("afterend", o), o.append(t);
930
- const s = document.createElement("div");
931
- for (s.setAttribute("data-node-type", "blockGroup"), o.append(s); ((r = o.nextElementSibling) == null ? void 0 : r.nodeName) === "UL" || ((i = o.nextElementSibling) == null ? void 0 : i.nodeName) === "OL"; )
932
- s.append(o.nextElementSibling);
933
- });
934
- }
935
- let le = null;
936
- function vo() {
937
- return le || (le = document.implementation.createHTMLDocument("title"));
938
- }
939
- function Io(n) {
940
- if (typeof n == "string") {
941
- const e = vo().createElement("div");
942
- e.innerHTML = n, n = e;
943
- }
944
- return Mo(n), wo(n), n;
945
- }
946
- function ve(n, e) {
947
- const t = Io(n), s = Ue.fromSchema(e).parse(t, {
948
- topNode: e.nodes.blockGroup.create()
949
- }), r = [];
950
- for (let i = 0; i < s.childCount; i++)
951
- r.push(C(s.child(i), e));
952
- return r;
953
- }
954
- function Ao(n, e) {
955
- const t = e.value ? e.value : "", o = {};
956
- e.lang && (o["data-language"] = e.lang);
957
- let s = {
958
- type: "element",
959
- tagName: "code",
960
- properties: o,
961
- children: [{ type: "text", value: t }]
962
- };
963
- return e.meta && (s.data = { meta: e.meta }), n.patch(e, s), s = n.applyData(e, s), s = {
964
- type: "element",
965
- tagName: "pre",
966
- properties: {},
967
- children: [s]
968
- }, n.patch(e, s), s;
969
- }
970
- function No(n, e) {
971
- var r;
972
- const t = String((e == null ? void 0 : e.url) || ""), o = e != null && e.title ? String(e.title) : void 0;
973
- let s = {
974
- type: "element",
975
- tagName: "video",
976
- properties: {
977
- src: t,
978
- "data-name": o,
979
- "data-url": t,
980
- controls: !0
981
- },
982
- children: []
983
- };
984
- return (r = n.patch) == null || r.call(n, e, s), s = n.applyData ? n.applyData(e, s) : s, s;
985
- }
986
- function Ie(n) {
987
- return Yt().use(qt).use(Wt).use(Kt, {
988
- handlers: {
989
- ...ie,
990
- image: (t, o) => {
991
- const s = String((o == null ? void 0 : o.url) || "");
992
- return et(s) ? No(t, o) : ie.image(t, o);
993
- },
994
- code: Ao,
995
- blockquote: (t, o) => {
996
- const s = {
997
- type: "element",
998
- tagName: "blockquote",
999
- properties: {},
1000
- // The only difference from the original is that we don't wrap the children with line endings
1001
- children: t.wrap(t.all(o), !1)
1002
- };
1003
- return t.patch(o, s), t.applyData(o, s);
1004
- }
1005
- }
1006
- }).use(Jt).processSync(n).value;
1007
- }
1008
- function _o(n, e) {
1009
- const t = Ie(n);
1010
- return ve(t, e);
1011
- }
1012
- class Lo {
1013
- constructor(e) {
1014
- this.editor = e;
1015
- }
1016
- /**
1017
- * Exports blocks into a simplified HTML string. To better conform to HTML standards, children of blocks which aren't list
1018
- * items are un-nested in the output HTML.
1019
- *
1020
- * @param blocks An array of blocks that should be serialized into HTML.
1021
- * @returns The blocks, serialized as an HTML string.
1022
- */
1023
- blocksToHTMLLossy(e = this.editor.document) {
1024
- return Be(
1025
- this.editor.pmSchema,
1026
- this.editor
1027
- ).exportBlocks(e, {});
1028
- }
1029
- /**
1030
- * Serializes blocks into an HTML string in the format that would normally be rendered by the editor.
1031
- *
1032
- * Use this method if you want to server-side render HTML (for example, a blog post that has been edited in BlockNote)
1033
- * and serve it to users without loading the editor on the client (i.e.: displaying the blog post)
1034
- *
1035
- * @param blocks An array of blocks that should be serialized into HTML.
1036
- * @returns The blocks, serialized as an HTML string.
1037
- */
1038
- blocksToFullHTML(e = this.editor.document) {
1039
- return lo(
1040
- this.editor.pmSchema,
1041
- this.editor
1042
- ).serializeBlocks(e, {});
1043
- }
1044
- /**
1045
- * Parses blocks from an HTML string. Tries to create `Block` objects out of any HTML block-level elements, and
1046
- * `InlineNode` objects from any HTML inline elements, though not all element types are recognized. If BlockNote
1047
- * doesn't recognize an HTML element's tag, it will parse it as a paragraph or plain text.
1048
- * @param html The HTML string to parse blocks from.
1049
- * @returns The blocks parsed from the HTML string.
1050
- */
1051
- tryParseHTMLToBlocks(e) {
1052
- return ve(e, this.editor.pmSchema);
1053
- }
1054
- /**
1055
- * Serializes blocks into a Markdown string. The output is simplified as Markdown does not support all features of
1056
- * BlockNote - children of blocks which aren't list items are un-nested and certain styles are removed.
1057
- * @param blocks An array of blocks that should be serialized into Markdown.
1058
- * @returns The blocks, serialized as a Markdown string.
1059
- */
1060
- blocksToMarkdownLossy(e = this.editor.document) {
1061
- return at(e, this.editor.pmSchema, this.editor, {});
1062
- }
1063
- /**
1064
- * Creates a list of blocks from a Markdown string. Tries to create `Block` and `InlineNode` objects based on
1065
- * Markdown syntax, though not all symbols are recognized. If BlockNote doesn't recognize a symbol, it will parse it
1066
- * as text.
1067
- * @param markdown The Markdown string to parse blocks from.
1068
- * @returns The blocks parsed from the Markdown string.
1069
- */
1070
- tryParseMarkdownToBlocks(e) {
1071
- return _o(e, this.editor.pmSchema);
1072
- }
1073
- /**
1074
- * Paste HTML into the editor. Defaults to converting HTML to BlockNote HTML.
1075
- * @param html The HTML to paste.
1076
- * @param raw Whether to paste the HTML as is, or to convert it to BlockNote HTML.
1077
- */
1078
- pasteHTML(e, t = !1) {
1079
- var s;
1080
- let o = e;
1081
- if (!t) {
1082
- const r = this.tryParseHTMLToBlocks(e);
1083
- o = this.blocksToFullHTML(r);
1084
- }
1085
- o && ((s = this.editor.prosemirrorView) == null || s.pasteHTML(o));
1086
- }
1087
- /**
1088
- * Paste text into the editor. Defaults to interpreting text as markdown.
1089
- * @param text The text to paste.
1090
- */
1091
- pasteText(e) {
1092
- var t;
1093
- return (t = this.editor.prosemirrorView) == null ? void 0 : t.pasteText(e);
1094
- }
1095
- /**
1096
- * Paste markdown into the editor.
1097
- * @param markdown The markdown to paste.
1098
- */
1099
- pasteMarkdown(e) {
1100
- const t = Ie(e);
1101
- return this.pasteHTML(t);
1102
- }
1103
- }
1104
- const se = [
1105
- "vscode-editor-data",
1106
- "blocknote/html",
1107
- "text/markdown",
1108
- "text/html",
1109
- "text/plain",
1110
- "Files"
1111
- ];
1112
- function Do(n, e) {
1113
- if (!n.startsWith(".") || !e.startsWith("."))
1114
- throw new Error("The strings provided are not valid file extensions.");
1115
- return n === e;
1116
- }
1117
- function Oo(n, e) {
1118
- const t = n.split("/"), o = e.split("/");
1119
- if (t.length !== 2)
1120
- throw new Error(`The string ${n} is not a valid MIME type.`);
1121
- if (o.length !== 2)
1122
- throw new Error(`The string ${e} is not a valid MIME type.`);
1123
- return t[1] === "*" || o[1] === "*" ? t[0] === o[0] : (t[0] === "*" || o[0] === "*" || t[0] === o[0]) && t[1] === o[1];
1124
- }
1125
- function de(n, e, t, o = "after") {
1126
- let s;
1127
- return Array.isArray(e.content) && e.content.length === 0 ? s = n.updateBlock(e, t).id : s = n.insertBlocks(
1128
- [t],
1129
- e,
1130
- o
1131
- )[0].id, s;
1132
- }
1133
- async function Ae(n, e) {
1134
- var r;
1135
- if (!e.uploadFile) {
1136
- console.warn(
1137
- "Attempted ot insert file, but uploadFile is not set in the BlockNote editor options"
1138
- );
1139
- return;
1140
- }
1141
- const t = "dataTransfer" in n ? n.dataTransfer : n.clipboardData;
1142
- if (t === null)
1143
- return;
1144
- let o = null;
1145
- for (const i of se)
1146
- if (t.types.includes(i)) {
1147
- o = i;
1148
- break;
1149
- }
1150
- if (o !== "Files")
1151
- return;
1152
- const s = t.items;
1153
- if (s) {
1154
- n.preventDefault();
1155
- for (let i = 0; i < s.length; i++) {
1156
- let l = "file";
1157
- for (const c of Object.values(e.schema.blockSpecs))
1158
- for (const d of ((r = c.implementation.meta) == null ? void 0 : r.fileBlockAccept) || []) {
1159
- const u = d.startsWith("."), p = s[i].getAsFile();
1160
- if (p && (!u && p.type && Oo(s[i].type, d) || u && Do(
1161
- "." + p.name.split(".").pop(),
1162
- d
1163
- ))) {
1164
- l = c.config.type;
1165
- break;
1166
- }
1167
- }
1168
- const a = s[i].getAsFile();
1169
- if (a) {
1170
- const c = {
1171
- type: l,
1172
- props: {
1173
- name: a.name
1174
- }
1175
- };
1176
- let d;
1177
- if (n.type === "paste") {
1178
- const h = e.getTextCursorPosition().block;
1179
- d = de(e, h, c);
1180
- } else if (n.type === "drop") {
1181
- const h = {
1182
- left: n.clientX,
1183
- top: n.clientY
1184
- }, f = e.prosemirrorView.posAtCoords(h);
1185
- if (!f)
1186
- return;
1187
- d = e.transact((m) => {
1188
- var y;
1189
- const b = D(m.doc, f.pos), g = (y = e.domElement) == null ? void 0 : y.querySelector(
1190
- `[data-id="${b.node.attrs.id}"]`
1191
- ), x = g == null ? void 0 : g.getBoundingClientRect();
1192
- return de(
1193
- e,
1194
- e.getBlock(b.node.attrs.id),
1195
- c,
1196
- x && (x.top + x.bottom) / 2 > h.top ? "before" : "after"
1197
- );
1198
- });
1199
- } else
1200
- return;
1201
- const u = await e.uploadFile(a, d), p = typeof u == "string" ? {
1202
- props: {
1203
- url: u
1204
- }
1205
- } : { ...u };
1206
- e.updateBlock(d, p);
1207
- }
1208
- }
1209
- }
1210
- }
1211
- const $o = (n) => T.create({
1212
- name: "dropFile",
1213
- addProseMirrorPlugins() {
1214
- return [
1215
- new oe({
1216
- props: {
1217
- handleDOMEvents: {
1218
- drop(e, t) {
1219
- if (!n.isEditable)
1220
- return;
1221
- let o = null;
1222
- for (const s of se)
1223
- if (t.dataTransfer.types.includes(s)) {
1224
- o = s;
1225
- break;
1226
- }
1227
- return o === null ? !0 : o === "Files" ? (Ae(t, n), !0) : !1;
1228
- }
1229
- }
1230
- }
1231
- })
1232
- ];
1233
- }
1234
- }), Ho = /(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/, Fo = /(_|__|\*|\*\*|~~|==|\+\+)(?!\s)(?:[^\s](?:.{0,62}[^\s])?|\S)(?=\1)/, Vo = /\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/, Uo = /(?:\s|^)`(?!\s)(?:[^\s`](?:[^`]{0,46}[^\s`])?|[^\s`])`([^\w]|$)/, zo = /(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/, Ro = /(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/, Go = /\n{2} {0,3}-{2,48}\n{2}/, jo = /(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/, Wo = /(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/, qo = /(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/, Ko = /^\s*\|(.+\|)+\s*$/m, Jo = /^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m, Yo = /^\s*\|(.+\|)+\s*$/m, Qo = (n) => Ho.test(n) || Fo.test(n) || Vo.test(n) || Uo.test(n) || zo.test(n) || Ro.test(n) || Go.test(n) || jo.test(n) || Wo.test(n) || qo.test(n) || Ko.test(n) || Jo.test(n) || Yo.test(n);
1235
- async function Xo(n, e) {
1236
- const { schema: t } = e.state;
1237
- if (!n.clipboardData)
1238
- return !1;
1239
- const o = n.clipboardData.getData("text/plain");
1240
- if (!o)
1241
- return !1;
1242
- if (!t.nodes.codeBlock)
1243
- return e.pasteText(o), !0;
1244
- const s = n.clipboardData.getData("vscode-editor-data"), r = s ? JSON.parse(s) : void 0, i = r == null ? void 0 : r.mode;
1245
- return i ? (e.pasteHTML(
1246
- `<pre><code class="language-${i}">${o.replace(
1247
- /\r\n?/g,
1248
- `
1249
- `
1250
- )}</code></pre>`
1251
- ), !0) : !1;
1252
- }
1253
- function Zo({
1254
- event: n,
1255
- editor: e,
1256
- prioritizeMarkdownOverHTML: t,
1257
- plainTextAsMarkdown: o
1258
- }) {
1259
- var l;
1260
- if (e.transact(
1261
- (a) => a.selection.$from.parent.type.spec.code && a.selection.$to.parent.type.spec.code
1262
- )) {
1263
- const a = (l = n.clipboardData) == null ? void 0 : l.getData("text/plain");
1264
- if (a)
1265
- return e.pasteText(a), !0;
1266
- }
1267
- let r;
1268
- for (const a of se)
1269
- if (n.clipboardData.types.includes(a)) {
1270
- r = a;
1271
- break;
1272
- }
1273
- if (!r)
1274
- return !0;
1275
- if (r === "vscode-editor-data")
1276
- return Xo(n, e.prosemirrorView), !0;
1277
- if (r === "Files")
1278
- return Ae(n, e), !0;
1279
- const i = n.clipboardData.getData(r);
1280
- if (r === "blocknote/html")
1281
- return e.pasteHTML(i, !0), !0;
1282
- if (r === "text/markdown")
1283
- return e.pasteMarkdown(i), !0;
1284
- if (t) {
1285
- const a = n.clipboardData.getData("text/plain");
1286
- if (Qo(a))
1287
- return e.pasteMarkdown(a), !0;
1288
- }
1289
- return r === "text/html" ? (e.pasteHTML(i), !0) : o ? (e.pasteMarkdown(i), !0) : (e.pasteText(i), !0);
1290
- }
1291
- const en = (n, e) => T.create({
1292
- name: "pasteFromClipboard",
1293
- addProseMirrorPlugins() {
1294
- return [
1295
- new oe({
1296
- props: {
1297
- handleDOMEvents: {
1298
- paste(t, o) {
1299
- if (o.preventDefault(), !!n.isEditable)
1300
- return e({
1301
- event: o,
1302
- editor: n,
1303
- defaultPasteHandler: ({
1304
- prioritizeMarkdownOverHTML: s = !0,
1305
- plainTextAsMarkdown: r = !0
1306
- } = {}) => Zo({
1307
- event: o,
1308
- editor: n,
1309
- prioritizeMarkdownOverHTML: s,
1310
- plainTextAsMarkdown: r
1311
- })
1312
- });
1313
- }
1314
- }
1315
- }
1316
- })
1317
- ];
1318
- }
1319
- });
1320
- function tn(n, e, t) {
1321
- var l;
1322
- let o = !1;
1323
- const s = n.state.selection instanceof ne;
1324
- if (!s) {
1325
- const a = n.state.doc.slice(
1326
- n.state.selection.from,
1327
- n.state.selection.to,
1328
- !1
1329
- ).content, c = [];
1330
- for (let d = 0; d < a.childCount; d++)
1331
- c.push(a.child(d));
1332
- o = c.find(
1333
- (d) => d.type.isInGroup("bnBlock") || d.type.name === "blockGroup" || d.type.spec.group === "blockContent"
1334
- ) === void 0, o && (e = a);
1335
- }
1336
- let r;
1337
- const i = Be(
1338
- n.state.schema,
1339
- t
1340
- );
1341
- if (s) {
1342
- ((l = e.firstChild) == null ? void 0 : l.type.name) === "table" && (e = e.firstChild.content);
1343
- const a = We(
1344
- e,
1345
- t.schema.inlineContentSchema,
1346
- t.schema.styleSchema
1347
- );
1348
- r = `<table>${i.exportInlineContent(
1349
- a,
1350
- {}
1351
- )}</table>`;
1352
- } else if (o) {
1353
- const a = qe(
1354
- e,
1355
- t.schema.inlineContentSchema,
1356
- t.schema.styleSchema
1357
- );
1358
- r = i.exportInlineContent(a, {});
1359
- } else {
1360
- const a = lt(e);
1361
- r = i.exportBlocks(a, {});
1362
- }
1363
- return r;
1364
- }
1365
- function Ne(n, e) {
1366
- "node" in n.state.selection && n.state.selection.node.type.spec.group === "blockContent" && e.transact(
1367
- (i) => i.setSelection(
1368
- new $(i.doc.resolve(n.state.selection.from - 1))
1369
- )
1370
- );
1371
- const t = n.serializeForClipboard(
1372
- n.state.selection.content()
1373
- ).dom.innerHTML, o = n.state.selection.content().content, s = tn(
1374
- n,
1375
- o,
1376
- e
1377
- ), r = ct(s);
1378
- return { clipboardHTML: t, externalHTML: s, markdown: r };
1379
- }
1380
- const ue = () => {
1381
- const n = window.getSelection();
1382
- if (!n || n.isCollapsed)
1383
- return !0;
1384
- let e = n.focusNode;
1385
- for (; e; ) {
1386
- if (e instanceof HTMLElement && e.getAttribute("contenteditable") === "false")
1387
- return !0;
1388
- e = e.parentElement;
1389
- }
1390
- return !1;
1391
- }, pe = (n, e, t) => {
1392
- t.preventDefault(), t.clipboardData.clearData();
1393
- const { clipboardHTML: o, externalHTML: s, markdown: r } = Ne(
1394
- e,
1395
- n
1396
- );
1397
- t.clipboardData.setData("blocknote/html", o), t.clipboardData.setData("text/html", s), t.clipboardData.setData("text/plain", r);
1398
- }, on = (n) => T.create({
1399
- name: "copyToClipboard",
1400
- addProseMirrorPlugins() {
1401
- return [
1402
- new oe({
1403
- props: {
1404
- handleDOMEvents: {
1405
- copy(e, t) {
1406
- return ue() || pe(n, e, t), !0;
1407
- },
1408
- cut(e, t) {
1409
- return ue() || (pe(n, e, t), e.editable && e.dispatch(e.state.tr.deleteSelection())), !0;
1410
- },
1411
- // This is for the use-case in which only a block without content
1412
- // is selected, e.g. an image block, and dragged (not using the
1413
- // drag handle).
1414
- dragstart(e, t) {
1415
- if (!("node" in e.state.selection) || e.state.selection.node.type.spec.group !== "blockContent")
1416
- return;
1417
- n.transact(
1418
- (i) => i.setSelection(
1419
- new $(
1420
- i.doc.resolve(e.state.selection.from - 1)
1421
- )
1422
- )
1423
- ), t.preventDefault(), t.dataTransfer.clearData();
1424
- const { clipboardHTML: o, externalHTML: s, markdown: r } = Ne(e, n);
1425
- return t.dataTransfer.setData("blocknote/html", o), t.dataTransfer.setData("text/html", s), t.dataTransfer.setData("text/plain", r), !0;
1426
- }
1427
- }
1428
- }
1429
- })
1430
- ];
1431
- }
1432
- }), nn = T.create({
1433
- name: "blockBackgroundColor",
1434
- addGlobalAttributes() {
1435
- return [
1436
- {
1437
- types: ["tableCell", "tableHeader"],
1438
- attributes: {
1439
- backgroundColor: tt()
1440
- }
1441
- }
1442
- ];
1443
- }
1444
- }), sn = O.create({
1445
- name: "hardBreak",
1446
- inline: !0,
1447
- group: "inline",
1448
- selectable: !1,
1449
- linebreakReplacement: !0,
1450
- priority: 10,
1451
- parseHTML() {
1452
- return [{ tag: "br" }];
1453
- },
1454
- renderHTML({ HTMLAttributes: n }) {
1455
- return ["br", wt(this.options.HTMLAttributes, n)];
1456
- },
1457
- renderText() {
1458
- return `
1459
- `;
1460
- }
1461
- }), _e = (n, e) => {
1462
- var l;
1463
- const t = n.resolve(e), o = t.depth - 1, s = t.before(o), r = n.resolve(s).nodeAfter;
1464
- return r ? (l = r.type.spec.group) != null && l.includes("bnBlock") ? v(
1465
- n.resolve(s)
1466
- ) : _e(n, s) : void 0;
1467
- }, L = (n, e) => {
1468
- const t = n.resolve(e), o = t.index();
1469
- if (o === 0)
1470
- return;
1471
- const s = t.posAtIndex(o - 1);
1472
- return v(
1473
- n.resolve(s)
1474
- );
1475
- }, _ = (n, e) => {
1476
- const t = n.resolve(e), o = t.index();
1477
- if (o === t.node().childCount - 1)
1478
- return;
1479
- const s = t.posAtIndex(o + 1);
1480
- return v(
1481
- n.resolve(s)
1482
- );
1483
- }, Le = (n, e) => {
1484
- for (; e.childContainer; ) {
1485
- const t = e.childContainer.node, o = n.resolve(e.childContainer.beforePos + 1).posAtIndex(t.childCount - 1);
1486
- e = v(n.resolve(o));
1487
- }
1488
- return e;
1489
- }, rn = (n, e) => n.isBlockContainer && n.blockContent.node.type.spec.content === "inline*" && n.blockContent.node.childCount > 0 && e.isBlockContainer && e.blockContent.node.type.spec.content === "inline*", an = (n, e, t, o) => {
1490
- if (!o.isBlockContainer)
1491
- throw new Error(
1492
- `Attempted to merge block at position ${o.bnBlock.beforePos} into previous block at position ${t.bnBlock.beforePos}, but next block is not a block container`
1493
- );
1494
- if (o.childContainer) {
1495
- const s = n.doc.resolve(
1496
- o.childContainer.beforePos + 1
1497
- ), r = n.doc.resolve(
1498
- o.childContainer.afterPos - 1
1499
- ), i = s.blockRange(r);
1500
- if (e) {
1501
- const l = n.doc.resolve(o.bnBlock.beforePos);
1502
- n.tr.lift(i, l.depth);
1503
- }
1504
- }
1505
- if (e) {
1506
- if (!t.isBlockContainer)
1507
- throw new Error(
1508
- `Attempted to merge block at position ${o.bnBlock.beforePos} into previous block at position ${t.bnBlock.beforePos}, but previous block is not a block container`
1509
- );
1510
- e(
1511
- n.tr.delete(
1512
- t.blockContent.afterPos - 1,
1513
- o.blockContent.beforePos + 1
1514
- )
1515
- );
1516
- }
1517
- return !0;
1518
- }, fe = (n) => ({
1519
- state: e,
1520
- dispatch: t
1521
- }) => {
1522
- const o = e.doc.resolve(n), s = v(o), r = L(
1523
- e.doc,
1524
- s.bnBlock.beforePos
1525
- );
1526
- if (!r)
1527
- return !1;
1528
- const i = Le(
1529
- e.doc,
1530
- r
1531
- );
1532
- return rn(i, s) ? an(e, t, i, s) : !1;
1533
- }, cn = T.create({
1534
- priority: 50,
1535
- // TODO: The shortcuts need a refactor. Do we want to use a command priority
1536
- // design as there is now, or clump the logic into a single function?
1537
- addKeyboardShortcuts() {
1538
- const n = () => this.editor.commands.first(({ chain: o, commands: s }) => [
1539
- // Deletes the selection if it's not empty.
1540
- () => s.deleteSelection(),
1541
- // Undoes an input rule if one was triggered in the last editor state change.
1542
- () => s.undoInputRule(),
1543
- // Reverts block content type to a paragraph if the selection is at the start of the block.
1544
- () => s.command(({ state: r }) => {
1545
- const i = B(r);
1546
- if (!i.isBlockContainer)
1547
- return !1;
1548
- const l = r.selection.from === i.blockContent.beforePos + 1, a = i.blockContent.node.type.name === "paragraph";
1549
- return l && !a ? s.command(
1550
- nt(i.bnBlock.beforePos, {
1551
- type: "paragraph",
1552
- props: {}
1553
- })
1554
- ) : !1;
1555
- }),
1556
- // Removes a level of nesting if the block is indented if the selection is at the start of the block.
1557
- () => s.command(({ state: r }) => {
1558
- const i = B(r);
1559
- if (!i.isBlockContainer)
1560
- return !1;
1561
- const { blockContent: l } = i;
1562
- return r.selection.from === l.beforePos + 1 ? s.liftListItem("blockContainer") : !1;
1563
- }),
1564
- // Merges block with the previous one if it isn't indented, and the selection is at the start of the
1565
- // block. The target block for merging must contain inline content.
1566
- () => s.command(({ state: r }) => {
1567
- const i = B(r);
1568
- if (!i.isBlockContainer)
1569
- return !1;
1570
- const { bnBlock: l, blockContent: a } = i, c = L(
1571
- r.doc,
1572
- i.bnBlock.beforePos
1573
- );
1574
- if (!c || !c.isBlockContainer || c.blockContent.node.type.spec.content !== "inline*")
1575
- return !1;
1576
- const d = r.selection.from === a.beforePos + 1, u = r.selection.empty, p = l.beforePos;
1577
- return d && u ? o().command(fe(p)).scrollIntoView().run() : !1;
1578
- }),
1579
- // If the previous block is a columnList, moves the current block to
1580
- // the end of the last column in it.
1581
- () => s.command(({ state: r, tr: i, dispatch: l }) => {
1582
- const a = B(r);
1583
- if (!a.isBlockContainer)
1584
- return !1;
1585
- const c = L(
1586
- r.doc,
1587
- a.bnBlock.beforePos
1588
- );
1589
- if (!c || c.isBlockContainer)
1590
- return !1;
1591
- if (l) {
1592
- const d = c.bnBlock.afterPos - 1, u = i.doc.resolve(d - 1);
1593
- return i.delete(
1594
- a.bnBlock.beforePos,
1595
- a.bnBlock.afterPos
1596
- ), i.insert(u.pos, a.bnBlock.node), i.setSelection(
1597
- S.near(i.doc.resolve(u.pos + 1))
1598
- ), !0;
1599
- }
1600
- return !1;
1601
- }),
1602
- // If the block is the first in a column, moves it to the end of the
1603
- // previous column. If there is no previous column, moves it above the
1604
- // columnList.
1605
- () => s.command(({ state: r, tr: i, dispatch: l }) => {
1606
- const a = B(r);
1607
- if (!a.isBlockContainer || !(i.selection.from === a.blockContent.beforePos + 1))
1608
- return !1;
1609
- const d = i.doc.resolve(a.bnBlock.beforePos);
1610
- if (d.nodeBefore || d.node().type.name !== "column")
1611
- return !1;
1612
- const h = i.doc.resolve(a.bnBlock.beforePos), f = i.doc.resolve(h.before()), m = f.before();
1613
- return l && (i.delete(
1614
- a.bnBlock.beforePos,
1615
- a.bnBlock.afterPos
1616
- ), H(i, m), f.pos === m + 1 ? (i.insert(m, a.bnBlock.node), i.setSelection(
1617
- S.near(i.doc.resolve(m))
1618
- )) : (i.insert(f.pos - 1, a.bnBlock.node), i.setSelection(
1619
- S.near(i.doc.resolve(f.pos))
1620
- ))), !0;
1621
- }),
1622
- // Deletes the current block if it's an empty block with inline content,
1623
- // and moves the selection to the previous block.
1624
- () => s.command(({ state: r }) => {
1625
- var a;
1626
- const i = B(r);
1627
- if (!i.isBlockContainer)
1628
- return !1;
1629
- if (i.blockContent.node.childCount === 0 && i.blockContent.node.type.spec.content === "inline*") {
1630
- const c = L(
1631
- r.doc,
1632
- i.bnBlock.beforePos
1633
- );
1634
- if (!c || !c.isBlockContainer)
1635
- return !1;
1636
- let d = o();
1637
- if (i.childContainer && d.insertContentAt(
1638
- i.bnBlock.afterPos,
1639
- (a = i.childContainer) == null ? void 0 : a.node.content
1640
- ), c.blockContent.node.type.spec.content === "tableRow+") {
1641
- const m = i.bnBlock.beforePos - 1 - 1 - 1 - 1 - 1;
1642
- d = d.setTextSelection(
1643
- m
1644
- );
1645
- } else if (c.blockContent.node.type.spec.content === "")
1646
- d = d.setNodeSelection(
1647
- c.blockContent.beforePos
1648
- );
1649
- else {
1650
- const u = c.blockContent.afterPos - 1;
1651
- d = d.setTextSelection(u);
1652
- }
1653
- return d.deleteRange({
1654
- from: i.bnBlock.beforePos,
1655
- to: i.bnBlock.afterPos
1656
- }).scrollIntoView().run();
1657
- }
1658
- return !1;
1659
- }),
1660
- // Deletes previous block if it contains no content and isn't a table,
1661
- // when the selection is empty and at the start of the block. Moves the
1662
- // current block into the deleted block's place.
1663
- () => s.command(({ state: r }) => {
1664
- const i = B(r);
1665
- if (!i.isBlockContainer)
1666
- return !1;
1667
- const l = r.selection.from === i.blockContent.beforePos + 1, a = r.selection.empty, c = L(
1668
- r.doc,
1669
- i.bnBlock.beforePos
1670
- );
1671
- if (c && l && a) {
1672
- const d = Le(
1673
- r.doc,
1674
- c
1675
- );
1676
- if (!d.isBlockContainer)
1677
- return !1;
1678
- if (d.blockContent.node.type.spec.content === "" || d.blockContent.node.type.spec.content === "inline*" && d.blockContent.node.childCount === 0)
1679
- return o().cut(
1680
- {
1681
- from: i.bnBlock.beforePos,
1682
- to: i.bnBlock.afterPos
1683
- },
1684
- d.bnBlock.afterPos
1685
- ).deleteRange({
1686
- from: d.bnBlock.beforePos,
1687
- to: d.bnBlock.afterPos
1688
- }).run();
1689
- }
1690
- return !1;
1691
- })
1692
- ]), e = () => this.editor.commands.first(({ chain: o, commands: s }) => [
1693
- // Deletes the selection if it's not empty.
1694
- () => s.deleteSelection(),
1695
- // Deletes the first child block and un-nests its children, if the
1696
- // selection is empty and at the end of the current block. If both the
1697
- // parent and child blocks have inline content, the child block's
1698
- // content is appended to the parent's. The child block's own children
1699
- // are unindented before it's deleted.
1700
- () => s.command(({ state: r }) => {
1701
- var p;
1702
- const i = B(r);
1703
- if (!i.isBlockContainer || !i.childContainer)
1704
- return !1;
1705
- const { blockContent: l, childContainer: a } = i, c = r.selection.from === l.afterPos - 1, d = r.selection.empty, u = v(
1706
- r.doc.resolve(a.beforePos + 1)
1707
- );
1708
- if (!u.isBlockContainer)
1709
- return !1;
1710
- if (c && d) {
1711
- const h = u.blockContent.node, f = h.type.spec.content === "inline*", m = l.node.type.spec.content === "inline*";
1712
- return o().insertContentAt(
1713
- u.bnBlock.afterPos,
1714
- ((p = u.childContainer) == null ? void 0 : p.node.content) || w.empty
1715
- ).deleteRange(
1716
- // Deletes whole child container if there's only one child.
1717
- a.node.childCount === 1 ? {
1718
- from: a.beforePos,
1719
- to: a.afterPos
1720
- } : {
1721
- from: u.bnBlock.beforePos,
1722
- to: u.bnBlock.afterPos
1723
- }
1724
- ).insertContentAt(
1725
- r.selection.from,
1726
- f && m ? h.content : null
1727
- ).setTextSelection(r.selection.from).scrollIntoView().run();
1728
- }
1729
- return !1;
1730
- }),
1731
- // Merges block with the next one (at the same nesting level or lower),
1732
- // if one exists, the block has no children, and the selection is at the
1733
- // end of the block.
1734
- () => s.command(({ state: r }) => {
1735
- const i = B(r);
1736
- if (!i.isBlockContainer)
1737
- return !1;
1738
- const { bnBlock: l, blockContent: a } = i, c = _(
1739
- r.doc,
1740
- i.bnBlock.beforePos
1741
- );
1742
- if (!c || !c.isBlockContainer)
1743
- return !1;
1744
- const d = r.selection.from === a.afterPos - 1, u = r.selection.empty, p = l.afterPos;
1745
- return d && u ? o().command(fe(p)).scrollIntoView().run() : !1;
1746
- }),
1747
- // If the previous block is a columnList, moves the current block to
1748
- // the end of the last column in it.
1749
- () => s.command(({ state: r, tr: i, dispatch: l }) => {
1750
- const a = B(r);
1751
- if (!a.isBlockContainer)
1752
- return !1;
1753
- const c = _(
1754
- r.doc,
1755
- a.bnBlock.beforePos
1756
- );
1757
- if (!c || c.isBlockContainer)
1758
- return !1;
1759
- if (l) {
1760
- const d = c.bnBlock.beforePos + 1, u = i.doc.resolve(d + 1);
1761
- return i.delete(
1762
- u.pos,
1763
- u.pos + u.nodeAfter.nodeSize
1764
- ), H(i, c.bnBlock.beforePos), i.insert(a.bnBlock.afterPos, u.nodeAfter), i.setSelection(
1765
- S.near(i.doc.resolve(u.pos))
1766
- ), !0;
1767
- }
1768
- return !1;
1769
- }),
1770
- // If the block is the last in a column, moves it to the start of the
1771
- // next column. If there is no next column, moves it below the
1772
- // columnList.
1773
- () => s.command(({ state: r, tr: i, dispatch: l }) => {
1774
- const a = B(r);
1775
- if (!a.isBlockContainer || !(i.selection.from === a.blockContent.afterPos - 1))
1776
- return !1;
1777
- const d = i.doc.resolve(a.bnBlock.afterPos);
1778
- if (d.nodeAfter || d.node().type.name !== "column")
1779
- return !1;
1780
- const h = i.doc.resolve(a.bnBlock.afterPos), f = i.doc.resolve(h.after()), m = f.after();
1781
- if (l) {
1782
- const b = f.pos === m - 1 ? m : f.pos + 1, g = v(
1783
- i.doc.resolve(b)
1784
- );
1785
- i.delete(
1786
- g.bnBlock.beforePos,
1787
- g.bnBlock.afterPos
1788
- ), H(
1789
- i,
1790
- m - f.node().nodeSize
1791
- ), i.insert(h.pos, g.bnBlock.node), i.setSelection(
1792
- S.near(i.doc.resolve(b))
1793
- );
1794
- }
1795
- return !0;
1796
- }),
1797
- // Deletes the next block at either the same or lower nesting level, if
1798
- // the selection is empty and at the end of the block. If both the
1799
- // current and next blocks have inline content, the next block's
1800
- // content is appended to the current block's. The next block's own
1801
- // children are unindented before it's deleted.
1802
- () => s.command(({ state: r }) => {
1803
- var d;
1804
- const i = B(r);
1805
- if (!i.isBlockContainer)
1806
- return !1;
1807
- const { blockContent: l } = i, a = r.selection.from === l.afterPos - 1, c = r.selection.empty;
1808
- if (a && c) {
1809
- const u = (b, g) => {
1810
- const x = _(b, g);
1811
- if (x)
1812
- return x;
1813
- const y = _e(b, g);
1814
- if (y)
1815
- return u(
1816
- b,
1817
- y.bnBlock.beforePos
1818
- );
1819
- }, p = u(
1820
- r.doc,
1821
- i.bnBlock.beforePos
1822
- );
1823
- if (!p || !p.isBlockContainer)
1824
- return !1;
1825
- const h = p.blockContent.node, f = h.type.spec.content === "inline*", m = l.node.type.spec.content === "inline*";
1826
- return o().insertContentAt(
1827
- p.bnBlock.afterPos,
1828
- ((d = p.childContainer) == null ? void 0 : d.node.content) || w.empty
1829
- ).deleteRange({
1830
- from: p.bnBlock.beforePos,
1831
- to: p.bnBlock.afterPos
1832
- }).insertContentAt(
1833
- r.selection.from,
1834
- f && m ? h.content : null
1835
- ).setTextSelection(r.selection.from).scrollIntoView().run();
1836
- }
1837
- return !1;
1838
- }),
1839
- // Deletes the current block if it's an empty block with inline content,
1840
- // and moves the selection to the next block.
1841
- () => s.command(({ state: r }) => {
1842
- const i = B(r);
1843
- if (!i.isBlockContainer)
1844
- return !1;
1845
- if (i.blockContent.node.childCount === 0 && i.blockContent.node.type.spec.content === "inline*") {
1846
- const a = _(
1847
- r.doc,
1848
- i.bnBlock.beforePos
1849
- );
1850
- if (!a || !a.isBlockContainer)
1851
- return !1;
1852
- let c = o();
1853
- if (a.blockContent.node.type.spec.content === "tableRow+") {
1854
- const f = i.bnBlock.afterPos + 1 + 1 + 1 + 1 + 1;
1855
- c = c.setTextSelection(
1856
- f
1857
- );
1858
- } else a.blockContent.node.type.spec.content === "" ? c = c.setNodeSelection(
1859
- a.blockContent.beforePos
1860
- ) : c = c.setTextSelection(
1861
- a.blockContent.beforePos + 1
1862
- );
1863
- return c.deleteRange({
1864
- from: i.bnBlock.beforePos,
1865
- to: i.bnBlock.afterPos
1866
- }).scrollIntoView().run();
1867
- }
1868
- return !1;
1869
- }),
1870
- // Deletes next block if it contains no content and isn't a table,
1871
- // when the selection is empty and at the end of the block. Moves the
1872
- // current block into the deleted block's place.
1873
- () => s.command(({ state: r }) => {
1874
- const i = B(r);
1875
- if (!i.isBlockContainer)
1876
- return !1;
1877
- const l = r.selection.from === i.blockContent.afterPos - 1, a = r.selection.empty, c = _(
1878
- r.doc,
1879
- i.bnBlock.beforePos
1880
- );
1881
- if (!c || !c.isBlockContainer)
1882
- return !1;
1883
- if (c && l && a && (c.blockContent.node.type.spec.content === "" || c.blockContent.node.type.spec.content === "inline*" && c.blockContent.node.childCount === 0)) {
1884
- const u = c.bnBlock.node.lastChild.content;
1885
- return o().deleteRange({
1886
- from: c.bnBlock.beforePos,
1887
- to: c.bnBlock.afterPos
1888
- }).insertContentAt(
1889
- i.bnBlock.afterPos,
1890
- c.bnBlock.node.childCount === 2 ? u : null
1891
- ).run();
1892
- }
1893
- return !1;
1894
- })
1895
- ]), t = (o = !1) => this.editor.commands.first(({ commands: s, tr: r }) => [
1896
- // Removes a level of nesting if the block is empty & indented, while the selection is also empty & at the start
1897
- // of the block.
1898
- () => s.command(({ state: i }) => {
1899
- const l = B(i);
1900
- if (!l.isBlockContainer)
1901
- return !1;
1902
- const { bnBlock: a, blockContent: c } = l, { depth: d } = i.doc.resolve(a.beforePos), u = i.selection.$anchor.parentOffset === 0, p = i.selection.anchor === i.selection.head, h = c.node.childCount === 0, f = d > 1;
1903
- return u && p && h && f ? s.liftListItem("blockContainer") : !1;
1904
- }),
1905
- // Creates a hard break if block is configured to do so.
1906
- () => s.command(({ state: i }) => {
1907
- var c;
1908
- const l = B(i), a = ((c = this.options.editor.schema.blockSchema[l.blockNoteType].meta) == null ? void 0 : c.hardBreakShortcut) ?? "shift+enter";
1909
- if (a === "none")
1910
- return !1;
1911
- if (
1912
- // If shortcut is not configured, or is configured as "shift+enter",
1913
- // create a hard break for shift+enter, but not for enter.
1914
- a === "shift+enter" && o || // If shortcut is configured as "enter", create a hard break for
1915
- // both enter and shift+enter.
1916
- a === "enter"
1917
- ) {
1918
- const d = r.storedMarks || r.selection.$head.marks().filter(
1919
- (u) => this.editor.extensionManager.splittableMarks.includes(
1920
- u.type.name
1921
- )
1922
- );
1923
- return r.insert(
1924
- r.selection.head,
1925
- r.doc.type.schema.nodes.hardBreak.create()
1926
- ).ensureMarks(d), !0;
1927
- }
1928
- return !1;
1929
- }),
1930
- // Creates a new block and moves the selection to it if the current one is empty, while the selection is also
1931
- // empty & at the start of the block.
1932
- () => s.command(({ state: i, dispatch: l, tr: a }) => {
1933
- var m;
1934
- const c = B(i);
1935
- if (!c.isBlockContainer)
1936
- return !1;
1937
- const { bnBlock: d, blockContent: u } = c, p = i.selection.$anchor.parentOffset === 0, h = i.selection.anchor === i.selection.head, f = u.node.childCount === 0;
1938
- if (p && h && f) {
1939
- const b = d.afterPos, g = b + 2;
1940
- if (l) {
1941
- const x = i.schema.nodes.blockContainer.createAndFill(
1942
- void 0,
1943
- [
1944
- i.schema.nodes.paragraph.createAndFill() || void 0,
1945
- (m = c.childContainer) == null ? void 0 : m.node
1946
- ].filter((y) => y !== void 0)
1947
- );
1948
- a.insert(b, x).setSelection(
1949
- new S(a.doc.resolve(g))
1950
- ).scrollIntoView(), c.childContainer && a.delete(
1951
- c.childContainer.beforePos,
1952
- c.childContainer.afterPos
1953
- );
1954
- }
1955
- return !0;
1956
- }
1957
- return !1;
1958
- }),
1959
- // Splits the current block, moving content inside that's after the cursor to a new text block below. Also
1960
- // deletes the selection beforehand, if it's not empty.
1961
- () => s.command(({ state: i, chain: l }) => {
1962
- const a = B(i);
1963
- if (!a.isBlockContainer)
1964
- return !1;
1965
- const { blockContent: c } = a, d = i.selection.$anchor.parentOffset === 0;
1966
- return c.node.childCount === 0 ? !1 : (l().deleteSelection().command(
1967
- ot(
1968
- i.selection.from,
1969
- d,
1970
- d
1971
- )
1972
- ).run(), !0);
1973
- })
1974
- ]);
1975
- return {
1976
- Backspace: n,
1977
- Delete: e,
1978
- Enter: () => t(),
1979
- "Shift-Enter": () => t(!0),
1980
- // Always returning true for tab key presses ensures they're not captured by the browser. Otherwise, they blur the
1981
- // editor since the browser will try to use tab for keyboard navigation.
1982
- Tab: () => {
1983
- var o, s;
1984
- return this.options.tabBehavior !== "prefer-indent" && ((o = this.options.editor.getExtension(Y)) != null && o.store.state || ((s = this.options.editor.getExtension(J)) == null ? void 0 : s.store.state) !== void 0) ? !1 : we(this.options.editor);
1985
- },
1986
- "Shift-Tab": () => {
1987
- var o, s;
1988
- return this.options.tabBehavior !== "prefer-indent" && ((o = this.options.editor.getExtension(Y)) != null && o.store.state || ((s = this.options.editor.getExtension(J)) == null ? void 0 : s.store.state) !== void 0) ? !1 : this.editor.commands.liftListItem("blockContainer");
1989
- },
1990
- "Shift-Mod-ArrowUp": () => (this.options.editor.moveBlocksUp(), !0),
1991
- "Shift-Mod-ArrowDown": () => (this.options.editor.moveBlocksDown(), !0),
1992
- "Mod-z": () => this.options.editor.undo(),
1993
- "Mod-y": () => this.options.editor.redo(),
1994
- "Shift-Mod-z": () => this.options.editor.redo()
1995
- };
1996
- }
1997
- }), ln = te.create({
1998
- name: "insertion",
1999
- inclusive: !1,
2000
- excludes: "deletion modification insertion",
2001
- addAttributes() {
2002
- return {
2003
- id: { default: null, validate: "number" }
2004
- // note: validate is supported in prosemirror but not in tiptap, so this doesn't actually work (considered not critical)
2005
- };
2006
- },
2007
- extendMarkSchema(n) {
2008
- return n.name !== "insertion" ? {} : {
2009
- blocknoteIgnore: !0,
2010
- inclusive: !1,
2011
- toDOM(e, t) {
2012
- return [
2013
- "ins",
2014
- {
2015
- "data-id": String(e.attrs.id),
2016
- "data-inline": String(t),
2017
- ...!t && { style: "display: contents" }
2018
- // changed to "contents" to make this work for table rows
2019
- },
2020
- 0
2021
- ];
2022
- },
2023
- parseDOM: [
2024
- {
2025
- tag: "ins",
2026
- getAttrs(e) {
2027
- return e.dataset.id ? {
2028
- id: parseInt(e.dataset.id, 10)
2029
- } : !1;
2030
- }
2031
- }
2032
- ]
2033
- };
2034
- }
2035
- }), dn = te.create({
2036
- name: "deletion",
2037
- inclusive: !1,
2038
- excludes: "insertion modification deletion",
2039
- addAttributes() {
2040
- return {
2041
- id: { default: null, validate: "number" }
2042
- // note: validate is supported in prosemirror but not in tiptap
2043
- };
2044
- },
2045
- extendMarkSchema(n) {
2046
- return n.name !== "deletion" ? {} : {
2047
- blocknoteIgnore: !0,
2048
- inclusive: !1,
2049
- // attrs: {
2050
- // id: { validate: "number" },
2051
- // },
2052
- toDOM(e, t) {
2053
- return [
2054
- "del",
2055
- {
2056
- "data-id": String(e.attrs.id),
2057
- "data-inline": String(t),
2058
- ...!t && { style: "display: contents" }
2059
- // changed to "contents" to make this work for table rows
2060
- },
2061
- 0
2062
- ];
2063
- },
2064
- parseDOM: [
2065
- {
2066
- tag: "del",
2067
- getAttrs(e) {
2068
- return e.dataset.id ? {
2069
- id: parseInt(e.dataset.id, 10)
2070
- } : !1;
2071
- }
2072
- }
2073
- ]
2074
- };
2075
- }
2076
- }), un = te.create({
2077
- name: "modification",
2078
- inclusive: !1,
2079
- excludes: "deletion insertion",
2080
- addAttributes() {
2081
- return {
2082
- id: { default: null, validate: "number" },
2083
- type: { validate: "string" },
2084
- attrName: { default: null, validate: "string|null" },
2085
- previousValue: { default: null },
2086
- newValue: { default: null }
2087
- };
2088
- },
2089
- extendMarkSchema(n) {
2090
- return n.name !== "modification" ? {} : {
2091
- blocknoteIgnore: !0,
2092
- inclusive: !1,
2093
- // attrs: {
2094
- // id: { validate: "number" },
2095
- // type: { validate: "string" },
2096
- // attrName: { default: null, validate: "string|null" },
2097
- // previousValue: { default: null },
2098
- // newValue: { default: null },
2099
- // },
2100
- toDOM(e, t) {
2101
- return [
2102
- t ? "span" : "div",
2103
- {
2104
- "data-type": "modification",
2105
- "data-id": String(e.attrs.id),
2106
- "data-mod-type": e.attrs.type,
2107
- "data-mod-prev-val": JSON.stringify(e.attrs.previousValue),
2108
- // TODO: Try to serialize marks with toJSON?
2109
- "data-mod-new-val": JSON.stringify(e.attrs.newValue)
2110
- },
2111
- 0
2112
- ];
2113
- },
2114
- parseDOM: [
2115
- {
2116
- tag: "span[data-type='modification']",
2117
- getAttrs(e) {
2118
- return e.dataset.id ? {
2119
- id: parseInt(e.dataset.id, 10),
2120
- type: e.dataset.modType,
2121
- previousValue: e.dataset.modPrevVal,
2122
- newValue: e.dataset.modNewVal
2123
- } : !1;
2124
- }
2125
- },
2126
- {
2127
- tag: "div[data-type='modification']",
2128
- getAttrs(e) {
2129
- return e.dataset.id ? {
2130
- id: parseInt(e.dataset.id, 10),
2131
- type: e.dataset.modType,
2132
- previousValue: e.dataset.modPrevVal
2133
- } : !1;
2134
- }
2135
- }
2136
- ]
2137
- };
2138
- }
2139
- }), pn = T.create({
2140
- name: "textAlignment",
2141
- addGlobalAttributes() {
2142
- return [
2143
- {
2144
- // Generally text alignment is handled through props using the custom
2145
- // blocks API. Tables are the only blocks that are created as TipTap
2146
- // nodes and ported to blocks, so we need to add text alignment in a
2147
- // separate extension.
2148
- types: ["tableCell", "tableHeader"],
2149
- attributes: {
2150
- textAlignment: {
2151
- default: "left",
2152
- parseHTML: (n) => n.getAttribute("data-text-alignment"),
2153
- renderHTML: (n) => n.textAlignment === "left" ? {} : {
2154
- "data-text-alignment": n.textAlignment
2155
- }
2156
- }
2157
- }
2158
- }
2159
- ];
2160
- }
2161
- }), fn = T.create({
2162
- name: "blockTextColor",
2163
- addGlobalAttributes() {
2164
- return [
2165
- {
2166
- types: ["table", "tableCell", "tableHeader"],
2167
- attributes: {
2168
- textColor: st()
2169
- }
2170
- }
2171
- ];
2172
- }
2173
- }), hn = {
2174
- blockColor: "data-block-color",
2175
- blockStyle: "data-block-style",
2176
- id: "data-id",
2177
- depth: "data-depth",
2178
- depthChange: "data-depth-change"
2179
- }, mn = O.create({
2180
- name: "blockContainer",
2181
- group: "blockGroupChild bnBlock",
2182
- // A block always contains content, and optionally a blockGroup which contains nested blocks
2183
- content: "blockContent blockGroup?",
2184
- // Ensures content-specific keyboard handlers trigger first.
2185
- priority: 50,
2186
- defining: !0,
2187
- marks: "insertion modification deletion",
2188
- parseHTML() {
2189
- return [
2190
- {
2191
- tag: "div[data-node-type=" + this.name + "]",
2192
- getAttrs: (n) => {
2193
- if (typeof n == "string")
2194
- return !1;
2195
- const e = {};
2196
- for (const [t, o] of Object.entries(hn))
2197
- n.getAttribute(o) && (e[t] = n.getAttribute(o));
2198
- return e;
2199
- }
2200
- },
2201
- // Ignore `blockOuter` divs, but parse the `blockContainer` divs inside them.
2202
- {
2203
- tag: 'div[data-node-type="blockOuter"]',
2204
- skip: !0
2205
- }
2206
- ];
2207
- },
2208
- renderHTML({ HTMLAttributes: n }) {
2209
- var s;
2210
- const e = document.createElement("div");
2211
- e.className = "bn-block-outer", e.setAttribute("data-node-type", "blockOuter");
2212
- for (const [r, i] of Object.entries(n))
2213
- r !== "class" && e.setAttribute(r, i);
2214
- const t = {
2215
- ...((s = this.options.domAttributes) == null ? void 0 : s.block) || {},
2216
- ...n
2217
- }, o = document.createElement("div");
2218
- o.className = ee("bn-block", t.class), o.setAttribute("data-node-type", this.name);
2219
- for (const [r, i] of Object.entries(t))
2220
- r !== "class" && o.setAttribute(r, i);
2221
- return e.appendChild(o), {
2222
- dom: e,
2223
- contentDOM: o
2224
- };
2225
- }
2226
- }), kn = O.create({
2227
- name: "blockGroup",
2228
- group: "childContainer",
2229
- content: "blockGroupChild+",
2230
- marks: "deletion insertion modification",
2231
- parseHTML() {
2232
- return [
2233
- {
2234
- tag: "div",
2235
- getAttrs: (n) => typeof n == "string" ? !1 : n.getAttribute("data-node-type") === "blockGroup" ? null : !1
2236
- }
2237
- ];
2238
- },
2239
- renderHTML({ HTMLAttributes: n }) {
2240
- var o;
2241
- const e = {
2242
- ...((o = this.options.domAttributes) == null ? void 0 : o.blockGroup) || {},
2243
- ...n
2244
- }, t = document.createElement("div");
2245
- t.className = ee(
2246
- "bn-block-group",
2247
- e.class
2248
- ), t.setAttribute("data-node-type", "blockGroup");
2249
- for (const [s, r] of Object.entries(e))
2250
- s !== "class" && t.setAttribute(s, r);
2251
- return {
2252
- dom: t,
2253
- contentDOM: t
2254
- };
2255
- }
2256
- }), bn = O.create({
2257
- name: "doc",
2258
- topNode: !0,
2259
- content: "blockGroup",
2260
- marks: "insertion modification deletion"
2261
- }), gn = Vt(
2262
- ({ options: n }) => ({
2263
- key: "collaboration",
2264
- blockNoteExtensions: [
2265
- dt(n),
2266
- ut(n),
2267
- pt(n),
2268
- ft(),
2269
- ht(n)
2270
- ]
2271
- })
2272
- );
2273
- let he = !1;
2274
- function Bn(n, e) {
2275
- const t = [
2276
- N.ClipboardTextSerializer,
2277
- N.Commands,
2278
- N.Editable,
2279
- N.FocusEvents,
2280
- N.Tabindex,
2281
- zt,
2282
- ke.configure({
2283
- // everything from bnBlock group (nodes that represent a BlockNote block should have an id)
2284
- types: ["blockContainer", "columnList", "column"],
2285
- setIdAttribute: e.setIdAttribute
2286
- }),
2287
- sn,
2288
- Gt,
2289
- // marks:
2290
- ln,
2291
- dn,
2292
- un,
2293
- Rt.extend({
2294
- inclusive: !1
2295
- }).configure({
2296
- defaultProtocol: Pt,
2297
- // only call this once if we have multiple editors installed. Or fix https://github.com/ueberdosis/tiptap/issues/5450
2298
- protocols: he ? [] : Et
2299
- }),
2300
- ...Object.values(n.schema.styleSpecs).map((o) => o.implementation.mark.configure({
2301
- editor: n
2302
- })),
2303
- fn,
2304
- nn,
2305
- pn,
2306
- // make sure escape blurs editor, so that we can tab to other elements in the host page (accessibility)
2307
- T.create({
2308
- name: "OverrideEscape",
2309
- addKeyboardShortcuts: () => ({
2310
- Escape: () => {
2311
- var o;
2312
- return (o = n.getExtension(ge)) != null && o.shown() ? !1 : (n.blur(), !0);
2313
- }
2314
- })
2315
- }),
2316
- // nodes
2317
- bn,
2318
- mn.configure({
2319
- editor: n,
2320
- domAttributes: e.domAttributes
2321
- }),
2322
- cn.configure({
2323
- editor: n,
2324
- tabBehavior: e.tabBehavior
2325
- }),
2326
- kn.configure({
2327
- domAttributes: e.domAttributes
2328
- }),
2329
- ...Object.values(n.schema.inlineContentSpecs).filter((o) => o.config !== "link" && o.config !== "text").map((o) => o.implementation.node.configure({
2330
- editor: n
2331
- })),
2332
- ...Object.values(n.schema.blockSpecs).flatMap((o) => [
2333
- // the node extension implementations
2334
- ..."node" in o.implementation ? [
2335
- o.implementation.node.configure({
2336
- editor: n,
2337
- domAttributes: e.domAttributes
2338
- })
2339
- ] : []
2340
- ]),
2341
- on(n),
2342
- en(
2343
- n,
2344
- e.pasteHandler || ((o) => o.defaultPasteHandler())
2345
- ),
2346
- $o(n)
2347
- ];
2348
- return he = !0, t;
2349
- }
2350
- function yn(n, e) {
2351
- const t = [
2352
- ye(),
2353
- mt(e),
2354
- J(e),
2355
- Y(e),
2356
- kt(e),
2357
- bt(),
2358
- gt(e),
2359
- jt(e),
2360
- Bt(e),
2361
- ge(e),
2362
- ...e.trailingBlock !== !1 ? [yt()] : []
2363
- ];
2364
- return e.collaboration ? t.push(gn(e.collaboration)) : t.push(Ct()), "table" in n.schema.blockSpecs && t.push(St(e)), e.animations !== !1 && t.push(xt()), t;
2365
- }
2366
- class Cn {
2367
- constructor(e, t) {
2368
- /**
2369
- * A set of extension keys which are disabled by the options
2370
- */
2371
- k(this, "disabledExtensions", /* @__PURE__ */ new Set());
2372
- /**
2373
- * A list of all the extensions that are registered to the editor
2374
- */
2375
- k(this, "extensions", []);
2376
- /**
2377
- * A map of all the abort controllers for each extension that has an init method defined
2378
- */
2379
- k(this, "abortMap", /* @__PURE__ */ new Map());
2380
- /**
2381
- * A map of all the extension factories that are registered to the editor
2382
- */
2383
- k(this, "extensionFactories", /* @__PURE__ */ new Map());
2384
- /**
2385
- * Because a single blocknote extension can both have it's own prosemirror plugins & additional generated ones (e.g. keymap & input rules plugins)
2386
- * We need to keep track of all the plugins for each extension, so that we can remove them when the extension is unregistered
2387
- */
2388
- k(this, "extensionPlugins", /* @__PURE__ */ new Map());
2389
- this.editor = e, this.options = t, e.onMount(() => {
2390
- for (const o of this.extensions)
2391
- if (o.mount) {
2392
- const s = new window.AbortController(), r = o.mount({
2393
- dom: e.prosemirrorView.dom,
2394
- root: e.prosemirrorView.root,
2395
- signal: s.signal
2396
- });
2397
- r && s.signal.addEventListener("abort", () => {
2398
- r();
2399
- }), this.abortMap.set(o, s);
2400
- }
2401
- }), e.onUnmount(() => {
2402
- for (const [o, s] of this.abortMap.entries())
2403
- this.abortMap.delete(o), s.abort();
2404
- }), this.disabledExtensions = new Set(t.disableExtensions || []);
2405
- for (const o of yn(this.editor, this.options))
2406
- this.addExtension(o);
2407
- for (const o of this.options.extensions ?? [])
2408
- this.addExtension(o);
2409
- for (const o of Object.values(this.editor.schema.blockSpecs))
2410
- for (const s of o.extensions ?? [])
2411
- this.addExtension(s);
2412
- }
2413
- /**
2414
- * Register one or more extensions to the editor after the editor is initialized.
2415
- *
2416
- * This allows users to switch on & off extensions "at runtime".
2417
- */
2418
- registerExtension(e) {
2419
- var r;
2420
- const t = [].concat(e).filter(Boolean);
2421
- if (!t.length) {
2422
- console.warn("No extensions found to register", e);
2423
- return;
2424
- }
2425
- const o = t.map((i) => this.addExtension(i)).filter(Boolean), s = /* @__PURE__ */ new Set();
2426
- for (const i of o)
2427
- i != null && i.tiptapExtensions && console.warn(
2428
- `Extension ${i.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.`,
2429
- i
2430
- ), (r = i == null ? void 0 : i.inputRules) != null && r.length && console.warn(
2431
- `Extension ${i.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.`,
2432
- i
2433
- ), this.getProsemirrorPluginsFromExtension(i).plugins.forEach(
2434
- (l) => {
2435
- s.add(l);
2436
- }
2437
- );
2438
- this.updatePlugins((i) => [...i, ...s]);
2439
- }
2440
- /**
2441
- * Register an extension to the editor
2442
- * @param extension - The extension to register
2443
- * @returns The extension instance
2444
- */
2445
- addExtension(e) {
2446
- let t;
2447
- if (typeof e == "function" ? t = e({ editor: this.editor }) : t = e, !(!t || this.disabledExtensions.has(t.key))) {
2448
- if (typeof e == "function") {
2449
- const o = t[Ut];
2450
- typeof o == "function" && this.extensionFactories.set(o, t);
2451
- }
2452
- if (this.extensions.push(t), t.blockNoteExtensions)
2453
- for (const o of t.blockNoteExtensions)
2454
- this.addExtension(o);
2455
- return t;
2456
- }
2457
- }
2458
- /**
2459
- * Resolve an extension or a list of extensions into a list of extension instances
2460
- * @param toResolve - The extension or list of extensions to resolve
2461
- * @returns A list of extension instances
2462
- */
2463
- resolveExtensions(e) {
2464
- const t = [];
2465
- if (typeof e == "function") {
2466
- const o = this.extensionFactories.get(e);
2467
- o && t.push(o);
2468
- } else if (Array.isArray(e))
2469
- for (const o of e)
2470
- t.push(...this.resolveExtensions(o));
2471
- else if (typeof e == "object" && "key" in e)
2472
- t.push(e);
2473
- else if (typeof e == "string") {
2474
- const o = this.extensions.find((s) => s.key === e);
2475
- o && t.push(o);
2476
- }
2477
- return t;
2478
- }
2479
- /**
2480
- * Unregister an extension from the editor
2481
- * @param toUnregister - The extension to unregister
2482
- * @returns void
2483
- */
2484
- unregisterExtension(e) {
2485
- var r;
2486
- const t = this.resolveExtensions(e);
2487
- if (!t.length) {
2488
- console.warn("No extensions found to unregister", e);
2489
- return;
2490
- }
2491
- let o = !1;
2492
- const s = /* @__PURE__ */ new Set();
2493
- for (const i of t) {
2494
- this.extensions = this.extensions.filter((a) => a !== i), this.extensionFactories.forEach((a, c) => {
2495
- a === i && this.extensionFactories.delete(c);
2496
- }), (r = this.abortMap.get(i)) == null || r.abort(), this.abortMap.delete(i);
2497
- const l = this.extensionPlugins.get(i);
2498
- l == null || l.forEach((a) => {
2499
- s.add(a);
2500
- }), this.extensionPlugins.delete(i), i.tiptapExtensions && !o && (o = !0, console.warn(
2501
- `Extension ${i.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.`,
2502
- e
2503
- ));
2504
- }
2505
- this.updatePlugins(
2506
- (i) => i.filter((l) => !s.has(l))
2507
- );
2508
- }
2509
- /**
2510
- * Allows resetting the current prosemirror state's plugins
2511
- * @param update - A function that takes the current plugins and returns the new plugins
2512
- * @returns void
2513
- */
2514
- updatePlugins(e) {
2515
- const t = this.editor.prosemirrorState, o = t.reconfigure({
2516
- plugins: e(t.plugins.slice())
2517
- });
2518
- this.editor.prosemirrorView.updateState(o);
2519
- }
2520
- /**
2521
- * Get all the extensions that are registered to the editor
2522
- */
2523
- getTiptapExtensions() {
2524
- var s;
2525
- const e = Bn(
2526
- this.editor,
2527
- this.options
2528
- ).filter((r) => !this.disabledExtensions.has(r.name)), t = Tt(this.extensions), o = /* @__PURE__ */ new Map();
2529
- for (const r of this.extensions) {
2530
- r.tiptapExtensions && e.push(...r.tiptapExtensions);
2531
- const i = t(r.key), { plugins: l, inputRules: a } = this.getProsemirrorPluginsFromExtension(r);
2532
- l.length && e.push(
2533
- T.create({
2534
- name: r.key,
2535
- priority: i,
2536
- addProseMirrorPlugins: () => l
2537
- })
2538
- ), a.length && (o.has(i) || o.set(i, []), o.get(i).push(...a));
2539
- }
2540
- e.push(
2541
- T.create({
2542
- name: "blocknote-input-rules",
2543
- addProseMirrorPlugins() {
2544
- const r = [];
2545
- return Array.from(o.keys()).sort().reverse().forEach((i) => {
2546
- r.push(...o.get(i));
2547
- }), [$t({ rules: r })];
2548
- }
2549
- })
2550
- );
2551
- for (const r of ((s = this.options._tiptapOptions) == null ? void 0 : s.extensions) ?? [])
2552
- e.push(r);
2553
- return e;
2554
- }
2555
- /**
2556
- * This maps a blocknote extension into an array of Prosemirror plugins if it has any of the following:
2557
- * - plugins
2558
- * - keyboard shortcuts
2559
- * - input rules
2560
- */
2561
- getProsemirrorPluginsFromExtension(e) {
2562
- var s, r, i;
2563
- const t = [...e.prosemirrorPlugins ?? []], o = [];
2564
- return !((s = e.prosemirrorPlugins) != null && s.length) && !Object.keys(e.keyboardShortcuts || {}).length && !((r = e.inputRules) != null && r.length) ? { plugins: t, inputRules: o } : (this.extensionPlugins.set(e, t), (i = e.inputRules) != null && i.length && o.push(
2565
- ...e.inputRules.map((l) => new Ht(l.find, (a, c, d, u) => {
2566
- const p = l.replace({
2567
- match: c,
2568
- range: { from: d, to: u },
2569
- editor: this.editor
2570
- });
2571
- if (p) {
2572
- const h = this.editor.getTextCursorPosition();
2573
- if (this.editor.schema.blockSchema[h.block.type].content !== "inline")
2574
- return null;
2575
- const f = z(a.tr), m = a.tr.deleteRange(d, u);
2576
- return rt(m, f.bnBlock.beforePos, p), m;
2577
- }
2578
- return null;
2579
- }))
2580
- ), Object.keys(e.keyboardShortcuts || {}).length && t.push(
2581
- Ft(
2582
- Object.fromEntries(
2583
- Object.entries(e.keyboardShortcuts).map(([l, a]) => [
2584
- l,
2585
- () => a({ editor: this.editor })
2586
- ])
2587
- )
2588
- )
2589
- ), { plugins: t, inputRules: o });
2590
- }
2591
- /**
2592
- * Get all extensions
2593
- */
2594
- getExtensions() {
2595
- return new Map(
2596
- this.extensions.map((e) => [e.key, e])
2597
- );
2598
- }
2599
- getExtension(e) {
2600
- if (typeof e == "string") {
2601
- const t = this.extensions.find((o) => o.key === e);
2602
- return t || void 0;
2603
- } else if (typeof e == "function") {
2604
- const t = this.extensionFactories.get(e);
2605
- return t || void 0;
2606
- }
2607
- throw new Error(`Invalid extension type: ${typeof e}`);
2608
- }
2609
- /**
2610
- * Check if an extension exists
2611
- */
2612
- hasExtension(e) {
2613
- 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) : !1;
2614
- }
2615
- }
2616
- function Sn(n, e) {
2617
- let { $from: t, $to: o } = e;
2618
- if (t.pos > t.start() && t.pos < n.content.size) {
2619
- const s = n.textBetween(t.pos, t.pos + 1);
2620
- if (/^[\w\p{P}]$/u.test(s)) {
2621
- const i = n.textBetween(t.start(), t.pos).match(/[\w\p{P}]+$/u);
2622
- i && (t = n.resolve(t.pos - i[0].length));
2623
- }
2624
- }
2625
- if (o.pos < o.end() && o.pos > 0) {
2626
- const s = n.textBetween(o.pos - 1, o.pos);
2627
- if (/^[\w\p{P}]$/u.test(s)) {
2628
- const i = n.textBetween(o.pos, o.end()).match(/^[\w\p{P}]+/u);
2629
- i && (o = n.resolve(o.pos + i[0].length));
2630
- }
2631
- }
2632
- return { $from: t, $to: o, from: t.pos, to: o.pos };
2633
- }
2634
- function xn(n) {
2635
- const e = E(n);
2636
- if (n.selection.empty || "node" in n.selection)
2637
- return;
2638
- const t = n.doc.resolve(
2639
- D(n.doc, n.selection.from).posBeforeNode
2640
- ), o = n.doc.resolve(
2641
- D(n.doc, n.selection.to).posBeforeNode
2642
- ), s = (c, d) => {
2643
- const u = t.posAtIndex(c, d), p = n.doc.resolve(u).nodeAfter;
2644
- if (!p)
2645
- throw new Error(
2646
- `Error getting selection - node not found at position ${u}`
2647
- );
2648
- return C(p, e);
2649
- }, r = [], i = t.sharedDepth(o.pos), l = t.index(i), a = o.index(i);
2650
- if (t.depth > i) {
2651
- r.push(C(t.nodeAfter, e));
2652
- for (let c = t.depth; c > i; c--)
2653
- if (t.node(c).type.isInGroup("childContainer")) {
2654
- const u = t.index(c) + 1, p = t.node(c).childCount;
2655
- for (let h = u; h < p; h++)
2656
- r.push(s(h, c));
2657
- }
2658
- } else
2659
- r.push(s(l, i));
2660
- for (let c = l + 1; c <= a; c++)
2661
- r.push(s(c, i));
2662
- if (r.length === 0)
2663
- throw new Error(
2664
- `Error getting selection - selection doesn't span any blocks (${n.selection})`
2665
- );
2666
- return {
2667
- blocks: r
2668
- };
2669
- }
2670
- function En(n, e, t) {
2671
- const o = typeof e == "string" ? e : e.id, s = typeof t == "string" ? t : t.id, r = E(n), i = be(r);
2672
- if (o === s)
2673
- throw new Error(
2674
- `Attempting to set selection with the same anchor and head blocks (id ${o})`
2675
- );
2676
- const l = P(o, n.doc);
2677
- if (!l)
2678
- throw new Error(`Block with ID ${o} not found`);
2679
- const a = P(s, n.doc);
2680
- if (!a)
2681
- throw new Error(`Block with ID ${s} not found`);
2682
- const c = K(l), d = K(a), u = i.blockSchema[c.blockNoteType], p = i.blockSchema[d.blockNoteType];
2683
- if (!c.isBlockContainer || u.content === "none")
2684
- throw new Error(
2685
- `Attempting to set selection anchor in block without content (id ${o})`
2686
- );
2687
- if (!d.isBlockContainer || p.content === "none")
2688
- throw new Error(
2689
- `Attempting to set selection anchor in block without content (id ${s})`
2690
- );
2691
- let h, f;
2692
- if (u.content === "table") {
2693
- const m = re.get(c.blockContent.node);
2694
- h = c.blockContent.beforePos + m.positionAt(0, 0, c.blockContent.node) + 1 + 2;
2695
- } else
2696
- h = c.blockContent.beforePos + 1;
2697
- if (p.content === "table") {
2698
- const m = re.get(d.blockContent.node), b = d.blockContent.beforePos + m.positionAt(
2699
- m.height - 1,
2700
- m.width - 1,
2701
- d.blockContent.node
2702
- ) + 1, g = n.doc.resolve(b).nodeAfter.nodeSize;
2703
- f = b + g - 2;
2704
- } else
2705
- f = d.blockContent.afterPos - 1;
2706
- n.setSelection(S.create(n.doc, h, f));
2707
- }
2708
- function Pn(n, e = !1) {
2709
- const t = E(n), o = e ? Sn(n.doc, n.selection) : n.selection;
2710
- let s = o.$from, r = o.$to;
2711
- for (; r.parentOffset >= r.parent.nodeSize - 2 && r.depth > 0; )
2712
- r = n.doc.resolve(r.pos + 1);
2713
- for (; r.parentOffset === 0 && r.depth > 0; )
2714
- r = n.doc.resolve(r.pos - 1);
2715
- for (; s.parentOffset === 0 && s.depth > 0; )
2716
- s = n.doc.resolve(s.pos - 1);
2717
- for (; s.parentOffset >= s.parent.nodeSize - 2 && s.depth > 0; )
2718
- s = n.doc.resolve(s.pos + 1);
2719
- const i = Ke(
2720
- n.doc.slice(s.pos, r.pos, !0),
2721
- t
2722
- );
2723
- return {
2724
- _meta: {
2725
- startPos: s.pos,
2726
- endPos: r.pos
2727
- },
2728
- ...i
2729
- };
2730
- }
2731
- function Tn(n) {
2732
- const { bnBlock: e } = z(n), t = E(n.doc), o = n.doc.resolve(e.beforePos), s = o.nodeBefore, r = n.doc.resolve(e.afterPos).nodeAfter;
2733
- let i;
2734
- return o.depth > 1 && (i = o.node(), i.type.isInGroup("bnBlock") || (i = o.node(o.depth - 1))), {
2735
- block: C(e.node, t),
2736
- prevBlock: s === null ? void 0 : C(s, t),
2737
- nextBlock: r === null ? void 0 : C(r, t),
2738
- parentBlock: i === void 0 ? void 0 : C(i, t)
2739
- };
2740
- }
2741
- function De(n, e, t = "start") {
2742
- const o = typeof e == "string" ? e : e.id, s = E(n.doc), r = be(s), i = P(o, n.doc);
2743
- if (!i)
2744
- throw new Error(`Block with ID ${o} not found`);
2745
- const l = K(i), a = r.blockSchema[l.blockNoteType].content;
2746
- if (l.isBlockContainer) {
2747
- const c = l.blockContent;
2748
- if (a === "none") {
2749
- n.setSelection($.create(n.doc, c.beforePos));
2750
- return;
2751
- }
2752
- if (a === "inline")
2753
- t === "start" ? n.setSelection(
2754
- S.create(n.doc, c.beforePos + 1)
2755
- ) : n.setSelection(
2756
- S.create(n.doc, c.afterPos - 1)
2757
- );
2758
- else if (a === "table")
2759
- t === "start" ? n.setSelection(
2760
- S.create(n.doc, c.beforePos + 4)
2761
- ) : n.setSelection(
2762
- S.create(n.doc, c.afterPos - 4)
2763
- );
2764
- else
2765
- throw new U(a);
2766
- } else {
2767
- const c = t === "start" ? l.childContainer.node.firstChild : l.childContainer.node.lastChild;
2768
- De(n, c.attrs.id, t);
2769
- }
2770
- }
2771
- class Mn {
2772
- constructor(e) {
2773
- this.editor = e;
2774
- }
2775
- /**
2776
- * Gets a snapshot of the current selection. This contains all blocks (included nested blocks)
2777
- * that the selection spans across.
2778
- *
2779
- * If the selection starts / ends halfway through a block, the returned data will contain the entire block.
2780
- */
2781
- getSelection() {
2782
- return this.editor.transact((e) => xn(e));
2783
- }
2784
- /**
2785
- * Gets a snapshot of the current selection. This contains all blocks (included nested blocks)
2786
- * that the selection spans across.
2787
- *
2788
- * If the selection starts / ends halfway through a block, the returned block will be
2789
- * only the part of the block that is included in the selection.
2790
- */
2791
- getSelectionCutBlocks(e = !1) {
2792
- return this.editor.transact(
2793
- (t) => Pn(t, e)
2794
- );
2795
- }
2796
- /**
2797
- * Sets the selection to a range of blocks.
2798
- * @param startBlock The identifier of the block that should be the start of the selection.
2799
- * @param endBlock The identifier of the block that should be the end of the selection.
2800
- */
2801
- setSelection(e, t) {
2802
- return this.editor.transact((o) => En(o, e, t));
2803
- }
2804
- /**
2805
- * Gets a snapshot of the current text cursor position.
2806
- * @returns A snapshot of the current text cursor position.
2807
- */
2808
- getTextCursorPosition() {
2809
- return this.editor.transact((e) => Tn(e));
2810
- }
2811
- /**
2812
- * Sets the text cursor position to the start or end of an existing block. Throws an error if the target block could
2813
- * not be found.
2814
- * @param targetBlock The identifier of an existing block that the text cursor should be moved to.
2815
- * @param placement Whether the text cursor should be placed at the start or end of the block.
2816
- */
2817
- setTextCursorPosition(e, t = "start") {
2818
- return this.editor.transact(
2819
- (o) => De(o, e, t)
2820
- );
2821
- }
2822
- /**
2823
- * Gets the bounding box of the current selection.
2824
- */
2825
- getSelectionBoundingBox() {
2826
- if (!this.editor.prosemirrorView)
2827
- return;
2828
- const { selection: e } = this.editor.prosemirrorState, { ranges: t } = e, o = Math.min(...t.map((r) => r.$from.pos)), s = Math.max(...t.map((r) => r.$to.pos));
2829
- if (vt(e)) {
2830
- const r = this.editor.prosemirrorView.nodeDOM(o);
2831
- if (r)
2832
- return r.getBoundingClientRect();
2833
- }
2834
- return It(
2835
- this.editor.prosemirrorView,
2836
- o,
2837
- s
2838
- ).toJSON();
2839
- }
2840
- }
2841
- class wn {
2842
- constructor(e) {
2843
- /**
2844
- * Stores the currently active transaction, which is the accumulated transaction from all {@link dispatch} calls during a {@link transact} calls
2845
- */
2846
- k(this, "activeTransaction", null);
2847
- // Flag to indicate if we're in a `can` call
2848
- k(this, "isInCan", !1);
2849
- this.editor = e;
2850
- }
2851
- /**
2852
- * For any command that can be executed, you can check if it can be executed by calling `editor.can(command)`.
2853
- * @example
2854
- * ```ts
2855
- * if (editor.can(editor.undo)) {
2856
- * // show button
2857
- * } else {
2858
- * // hide button
2859
- * }
2860
- */
2861
- can(e) {
2862
- try {
2863
- return this.isInCan = !0, e();
2864
- } finally {
2865
- this.isInCan = !1;
2866
- }
2867
- }
2868
- /**
2869
- * Execute a prosemirror command. This is mostly for backwards compatibility with older code.
2870
- *
2871
- * @note You should prefer the {@link transact} method when possible, as it will automatically handle the dispatching of the transaction and work across blocknote transactions.
2872
- *
2873
- * @example
2874
- * ```ts
2875
- * editor.exec((state, dispatch, view) => {
2876
- * dispatch(state.tr.insertText("Hello, world!"));
2877
- * });
2878
- * ```
2879
- */
2880
- exec(e) {
2881
- if (this.activeTransaction)
2882
- throw new Error(
2883
- "`exec` should not be called within a `transact` call, move the `exec` call outside of the `transact` call"
2884
- );
2885
- if (this.isInCan)
2886
- return this.canExec(e);
2887
- const t = this.prosemirrorState, o = this.prosemirrorView;
2888
- return e(t, (r) => this.prosemirrorView.dispatch(r), o);
2889
- }
2890
- /**
2891
- * Check if a command can be executed. A command should return `false` if it is not valid in the current state.
2892
- *
2893
- * @example
2894
- * ```ts
2895
- * if (editor.canExec(command)) {
2896
- * // show button
2897
- * } else {
2898
- * // hide button
2899
- * }
2900
- * ```
2901
- */
2902
- canExec(e) {
2903
- if (this.activeTransaction)
2904
- throw new Error(
2905
- "`canExec` should not be called within a `transact` call, move the `canExec` call outside of the `transact` call"
2906
- );
2907
- const t = this.prosemirrorState, o = this.prosemirrorView;
2908
- return e(t, void 0, o);
2909
- }
2910
- /**
2911
- * Execute a function within a "blocknote transaction".
2912
- * All changes to the editor within the transaction will be grouped together, so that
2913
- * we can dispatch them as a single operation (thus creating only a single undo step)
2914
- *
2915
- * @note There is no need to dispatch the transaction, as it will be automatically dispatched when the callback is complete.
2916
- *
2917
- * @example
2918
- * ```ts
2919
- * // All changes to the editor will be grouped together
2920
- * editor.transact((tr) => {
2921
- * tr.insertText("Hello, world!");
2922
- * // These two operations will be grouped together in a single undo step
2923
- * editor.transact((tr) => {
2924
- * tr.insertText("Hello, world!");
2925
- * });
2926
- * });
2927
- * ```
2928
- */
2929
- transact(e) {
2930
- if (this.activeTransaction)
2931
- return e(this.activeTransaction);
2932
- try {
2933
- this.activeTransaction = this.editor._tiptapEditor.state.tr;
2934
- const t = e(this.activeTransaction), o = this.activeTransaction;
2935
- return this.activeTransaction = null, o && // Only dispatch if the transaction was actually modified in some way
2936
- (o.docChanged || o.selectionSet || o.scrolledIntoView || o.storedMarksSet || !o.isGeneric) && this.prosemirrorView.dispatch(o), t;
2937
- } finally {
2938
- this.activeTransaction = null;
2939
- }
2940
- }
2941
- /**
2942
- * Get the underlying prosemirror state
2943
- * @note Prefer using `editor.transact` to read the current editor state, as that will ensure the state is up to date
2944
- * @see https://prosemirror.net/docs/ref/#state.EditorState
2945
- */
2946
- get prosemirrorState() {
2947
- if (this.activeTransaction)
2948
- throw new Error(
2949
- "`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"
2950
- );
2951
- return this.editor._tiptapEditor.state;
2952
- }
2953
- /**
2954
- * Get the underlying prosemirror view
2955
- * @see https://prosemirror.net/docs/ref/#view.EditorView
2956
- */
2957
- get prosemirrorView() {
2958
- return this.editor._tiptapEditor.view;
2959
- }
2960
- isFocused() {
2961
- var e;
2962
- return ((e = this.prosemirrorView) == null ? void 0 : e.hasFocus()) || !1;
2963
- }
2964
- focus() {
2965
- var e;
2966
- (e = this.prosemirrorView) == null || e.focus();
2967
- }
2968
- /**
2969
- * Checks if the editor is currently editable, or if it's locked.
2970
- * @returns True if the editor is editable, false otherwise.
2971
- */
2972
- get isEditable() {
2973
- if (!this.editor._tiptapEditor) {
2974
- if (!this.editor.headless)
2975
- throw new Error("no editor, but also not headless?");
2976
- return !1;
2977
- }
2978
- return this.editor._tiptapEditor.isEditable === void 0 ? !0 : this.editor._tiptapEditor.isEditable;
2979
- }
2980
- /**
2981
- * Makes the editor editable or locks it, depending on the argument passed.
2982
- * @param editable True to make the editor editable, or false to lock it.
2983
- */
2984
- set isEditable(e) {
2985
- if (!this.editor._tiptapEditor) {
2986
- if (!this.editor.headless)
2987
- throw new Error("no editor, but also not headless?");
2988
- return;
2989
- }
2990
- this.editor._tiptapEditor.options.editable !== e && this.editor._tiptapEditor.setEditable(e);
2991
- }
2992
- /**
2993
- * Undo the last action.
2994
- */
2995
- undo() {
2996
- const e = this.editor.getExtension("yUndo");
2997
- if (e)
2998
- return this.exec(e.undoCommand);
2999
- const t = this.editor.getExtension("history");
3000
- if (t)
3001
- return this.exec(t.undoCommand);
3002
- throw new Error("No undo plugin found");
3003
- }
3004
- /**
3005
- * Redo the last action.
3006
- */
3007
- redo() {
3008
- const e = this.editor.getExtension("yUndo");
3009
- if (e)
3010
- return this.exec(e.redoCommand);
3011
- const t = this.editor.getExtension("history");
3012
- if (t)
3013
- return this.exec(t.redoCommand);
3014
- throw new Error("No redo plugin found");
3015
- }
3016
- }
3017
- function vn(n, e, t, o = { updateSelection: !0 }) {
3018
- let { from: s, to: r } = typeof e == "number" ? { from: e, to: e } : { from: e.from, to: e.to }, i = !0, l = !0, a = "";
3019
- if (t.forEach((c) => {
3020
- c.check(), i && c.isText && c.marks.length === 0 ? a += c.text : i = !1, l = l ? c.isBlock : !1;
3021
- }), s === r && l) {
3022
- const { parent: c } = n.doc.resolve(s);
3023
- c.isTextblock && !c.type.spec.code && !c.childCount && (s -= 1, r += 1);
3024
- }
3025
- return i ? n.insertText(a, s, r) : n.replaceWith(s, r, t), o.updateSelection && At(n, n.steps.length - 1, -1), !0;
3026
- }
3027
- class In {
3028
- constructor(e) {
3029
- this.editor = e;
3030
- }
3031
- /**
3032
- * Insert a piece of content at the current cursor position.
3033
- *
3034
- * @param content can be a string, or array of partial inline content elements
3035
- */
3036
- insertInlineContent(e, { updateSelection: t = !1 } = {}) {
3037
- const o = V(e, this.editor.pmSchema);
3038
- this.editor.transact((s) => {
3039
- vn(
3040
- s,
3041
- {
3042
- from: s.selection.from,
3043
- to: s.selection.to
3044
- },
3045
- o,
3046
- {
3047
- updateSelection: t
3048
- }
3049
- );
3050
- });
3051
- }
3052
- /**
3053
- * Gets the active text styles at the text cursor position or at the end of the current selection if it's active.
3054
- */
3055
- getActiveStyles() {
3056
- return this.editor.transact((e) => {
3057
- const t = {}, o = e.selection.$to.marks();
3058
- for (const s of o) {
3059
- const r = this.editor.schema.styleSchema[s.type.name];
3060
- if (!r) {
3061
- // Links are not considered styles in blocknote
3062
- s.type.name !== "link" && // "blocknoteIgnore" tagged marks (such as comments) are also not considered BlockNote "styles"
3063
- !s.type.spec.blocknoteIgnore && console.warn("mark not found in styleschema", s.type.name);
3064
- continue;
3065
- }
3066
- r.propSchema === "boolean" ? t[r.type] = !0 : t[r.type] = s.attrs.stringValue;
3067
- }
3068
- return t;
3069
- });
3070
- }
3071
- /**
3072
- * Adds styles to the currently selected content.
3073
- * @param styles The styles to add.
3074
- */
3075
- addStyles(e) {
3076
- for (const [t, o] of Object.entries(e)) {
3077
- const s = this.editor.schema.styleSchema[t];
3078
- if (!s)
3079
- throw new Error(`style ${t} not found in styleSchema`);
3080
- if (s.propSchema === "boolean")
3081
- this.editor._tiptapEditor.commands.setMark(t);
3082
- else if (s.propSchema === "string")
3083
- this.editor._tiptapEditor.commands.setMark(t, {
3084
- stringValue: o
3085
- });
3086
- else
3087
- throw new U(s.propSchema);
3088
- }
3089
- }
3090
- /**
3091
- * Removes styles from the currently selected content.
3092
- * @param styles The styles to remove.
3093
- */
3094
- removeStyles(e) {
3095
- for (const t of Object.keys(e))
3096
- this.editor._tiptapEditor.commands.unsetMark(t);
3097
- }
3098
- /**
3099
- * Toggles styles on the currently selected content.
3100
- * @param styles The styles to toggle.
3101
- */
3102
- toggleStyles(e) {
3103
- for (const [t, o] of Object.entries(e)) {
3104
- const s = this.editor.schema.styleSchema[t];
3105
- if (!s)
3106
- throw new Error(`style ${t} not found in styleSchema`);
3107
- if (s.propSchema === "boolean")
3108
- this.editor._tiptapEditor.commands.toggleMark(t);
3109
- else if (s.propSchema === "string")
3110
- this.editor._tiptapEditor.commands.toggleMark(t, {
3111
- stringValue: o
3112
- });
3113
- else
3114
- throw new U(s.propSchema);
3115
- }
3116
- }
3117
- /**
3118
- * Gets the currently selected text.
3119
- */
3120
- getSelectedText() {
3121
- return this.editor.transact((e) => e.doc.textBetween(e.selection.from, e.selection.to));
3122
- }
3123
- /**
3124
- * Gets the URL of the last link in the current selection, or `undefined` if there are no links in the selection.
3125
- */
3126
- getSelectedLinkUrl() {
3127
- return this.editor._tiptapEditor.getAttributes("link").href;
3128
- }
3129
- /**
3130
- * Creates a new link to replace the selected content.
3131
- * @param url The link URL.
3132
- * @param text The text to display the link with.
3133
- */
3134
- createLink(e, t) {
3135
- if (e === "")
3136
- return;
3137
- const o = this.editor.pmSchema.mark("link", { href: e });
3138
- this.editor.transact((s) => {
3139
- const { from: r, to: i } = s.selection;
3140
- t ? s.insertText(t, r, i).addMark(r, r + t.length, o) : s.setSelection(Qt.create(s.doc, i)).addMark(
3141
- r,
3142
- i,
3143
- o
3144
- );
3145
- });
3146
- }
3147
- }
3148
- function An(n) {
3149
- return Nt(n.state.selection.$from, (e) => e.type.name === "tableCell" || e.type.name === "tableHeader") !== void 0;
3150
- }
3151
- function Oe(n, e) {
3152
- var s;
3153
- const t = e.nodes.hardBreak;
3154
- let o = R.empty;
3155
- return n.forEach((r) => {
3156
- r.isTextblock && r.childCount > 0 ? (o = o.append(r.content), o = o.addToEnd(t.create())) : r.isText ? o = o.addToEnd(r) : r.isBlock && r.childCount > 0 && (o = o.append(
3157
- Oe(r.content, e)
3158
- ), o = o.addToEnd(t.create()));
3159
- }), ((s = o.lastChild) == null ? void 0 : s.type) === t && (o = o.cut(0, o.size - 1)), o;
3160
- }
3161
- function Nn(n, e) {
3162
- const t = [];
3163
- return n.forEach((o, s, r) => {
3164
- r !== e && t.push(o);
3165
- }), R.from(t);
3166
- }
3167
- function _n(n, e) {
3168
- const t = [];
3169
- for (let o = 0; o < n.childCount; o++)
3170
- if (n.child(o).type.name === "tableRow")
3171
- if (t.length > 0 && t[t.length - 1].type.name === "table") {
3172
- const s = t[t.length - 1], r = s.copy(s.content.addToEnd(n.child(o)));
3173
- t[t.length - 1] = r;
3174
- } else {
3175
- const s = e.nodes.table.createChecked(
3176
- void 0,
3177
- n.child(o)
3178
- );
3179
- t.push(s);
3180
- }
3181
- else
3182
- t.push(n.child(o));
3183
- return n = R.from(t), n;
3184
- }
3185
- function Ln(n, e) {
3186
- let t = R.from(n.content);
3187
- if (t = _n(t, e.state.schema), An(e)) {
3188
- let o = !1;
3189
- if (t.descendants((s) => {
3190
- s.type.isInGroup("tableContent") && (o = !0);
3191
- }), !o && // is the content valid for a table paragraph?
3192
- !e.state.schema.nodes.tableParagraph.validContent(t))
3193
- return new j(
3194
- Oe(t, e.state.schema),
3195
- 0,
3196
- 0
3197
- );
3198
- }
3199
- if (!Dn(t, e))
3200
- return new j(t, n.openStart, n.openEnd);
3201
- for (let o = 0; o < t.childCount; o++)
3202
- if (t.child(o).type.spec.group === "blockContent") {
3203
- const s = [t.child(o)];
3204
- if (o + 1 < t.childCount && t.child(o + 1).type.name === "blockGroup") {
3205
- const i = t.child(o + 1).child(0).child(0);
3206
- (i.type.name === "bulletListItem" || i.type.name === "numberedListItem" || i.type.name === "checkListItem") && (s.push(t.child(o + 1)), t = Nn(t, o + 1));
3207
- }
3208
- const r = e.state.schema.nodes.blockContainer.createChecked(
3209
- void 0,
3210
- s
3211
- );
3212
- t = t.replaceChild(o, r);
3213
- }
3214
- return new j(t, n.openStart, n.openEnd);
3215
- }
3216
- function Dn(n, e) {
3217
- var r, i;
3218
- const t = n.childCount === 1, o = ((r = n.firstChild) == null ? void 0 : r.type.spec.content) === "inline*", s = ((i = n.firstChild) == null ? void 0 : i.type.spec.content) === "tableRow+";
3219
- if (t) {
3220
- if (o)
3221
- return !1;
3222
- if (s) {
3223
- const l = B(e.state);
3224
- if (l.isBlockContainer)
3225
- return !(l.blockContent.node.type.spec.content === "tableRow+");
3226
- }
3227
- }
3228
- return !0;
3229
- }
3230
- const On = {
3231
- enableInputRules: !0,
3232
- enablePasteRules: !0,
3233
- enableCoreExtensions: !1
3234
- };
3235
- class $e extends Ce {
3236
- constructor(t) {
3237
- var c, d, u, p, h, f, m, b, g, x;
3238
- super();
3239
- /**
3240
- * The underlying prosemirror schema
3241
- */
3242
- k(this, "pmSchema");
3243
- k(this, "_tiptapEditor");
3244
- /**
3245
- * Used by React to store a reference to an `ElementRenderer` helper utility to make sure we can render React elements
3246
- * in the correct context (used by `ReactRenderUtil`)
3247
- */
3248
- k(this, "elementRenderer", null);
3249
- /**
3250
- * Cache of all blocks. This makes sure we don't have to "recompute" blocks if underlying Prosemirror Nodes haven't changed.
3251
- * This is especially useful when we want to keep track of the same block across multiple operations,
3252
- * with this cache, blocks stay the same object reference (referential equality with ===).
3253
- */
3254
- k(this, "blockCache", /* @__PURE__ */ new WeakMap());
3255
- /**
3256
- * The dictionary contains translations for the editor.
3257
- */
3258
- k(this, "dictionary");
3259
- /**
3260
- * The schema of the editor. The schema defines which Blocks, InlineContent, and Styles are available in the editor.
3261
- */
3262
- k(this, "schema");
3263
- k(this, "blockImplementations");
3264
- k(this, "inlineContentImplementations");
3265
- k(this, "styleImplementations");
3266
- /**
3267
- * The `uploadFile` method is what the editor uses when files need to be uploaded (for example when selecting an image to upload).
3268
- * This method should set when creating the editor as this is application-specific.
3269
- *
3270
- * `undefined` means the application doesn't support file uploads.
3271
- *
3272
- * @param file The file that should be uploaded.
3273
- * @returns The URL of the uploaded file OR an object containing props that should be set on the file block (such as an id)
3274
- */
3275
- k(this, "uploadFile");
3276
- k(this, "onUploadStartCallbacks", []);
3277
- k(this, "onUploadEndCallbacks", []);
3278
- k(this, "resolveFileUrl");
3279
- /**
3280
- * Editor settings
3281
- */
3282
- k(this, "settings");
3283
- // Manager instances
3284
- k(this, "_blockManager");
3285
- k(this, "_eventManager");
3286
- k(this, "_exportManager");
3287
- k(this, "_extensionManager");
3288
- k(this, "_selectionManager");
3289
- k(this, "_stateManager");
3290
- k(this, "_styleManager");
3291
- /**
3292
- * Remove extension(s) from the editor
3293
- */
3294
- k(this, "unregisterExtension", (...t) => this._extensionManager.unregisterExtension(...t));
3295
- /**
3296
- * Register extension(s) to the editor
3297
- */
3298
- k(this, "registerExtension", (...t) => this._extensionManager.registerExtension(...t));
3299
- /**
3300
- * Get an extension from the editor
3301
- */
3302
- k(this, "getExtension", (...t) => this._extensionManager.getExtension(...t));
3303
- /**
3304
- * Mount the editor to a DOM element.
3305
- *
3306
- * @warning Not needed to call manually when using React, use BlockNoteView to take care of mounting
3307
- */
3308
- k(this, "mount", (t) => {
3309
- this._tiptapEditor.mount({ mount: t });
3310
- });
3311
- /**
3312
- * Unmount the editor from the DOM element it is bound to
3313
- */
3314
- k(this, "unmount", () => {
3315
- this._tiptapEditor.unmount();
3316
- });
3317
- this.options = t, this.dictionary = t.dictionary || Ot, this.settings = {
3318
- tables: {
3319
- splitCells: ((c = t == null ? void 0 : t.tables) == null ? void 0 : c.splitCells) ?? !1,
3320
- cellBackgroundColor: ((d = t == null ? void 0 : t.tables) == null ? void 0 : d.cellBackgroundColor) ?? !1,
3321
- cellTextColor: ((u = t == null ? void 0 : t.tables) == null ? void 0 : u.cellTextColor) ?? !1,
3322
- headers: ((p = t == null ? void 0 : t.tables) == null ? void 0 : p.headers) ?? !1
3323
- }
3324
- };
3325
- const o = {
3326
- defaultStyles: !0,
3327
- schema: t.schema || Mt.create(),
3328
- ...t,
3329
- placeholders: {
3330
- ...this.dictionary.placeholders,
3331
- ...t.placeholders
3332
- }
3333
- };
3334
- if (this.schema = o.schema, this.blockImplementations = o.schema.blockSpecs, this.inlineContentImplementations = o.schema.inlineContentSpecs, this.styleImplementations = o.schema.styleSpecs, o.uploadFile) {
3335
- const y = o.uploadFile;
3336
- this.uploadFile = async (I, M) => {
3337
- this.onUploadStartCallbacks.forEach(
3338
- (A) => A.apply(this, [M])
3339
- );
3340
- try {
3341
- return await y(I, M);
3342
- } finally {
3343
- this.onUploadEndCallbacks.forEach(
3344
- (A) => A.apply(this, [M])
3345
- );
3346
- }
3347
- };
3348
- }
3349
- this.resolveFileUrl = o.resolveFileUrl, this._eventManager = new Eo(this), this._extensionManager = new Cn(this, o);
3350
- const s = this._extensionManager.getTiptapExtensions(), r = this._extensionManager.hasExtension("ySync") || this._extensionManager.hasExtension("liveblocksExtension");
3351
- r && o.initialContent && console.warn(
3352
- "When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider"
3353
- );
3354
- const i = {
3355
- ...On,
3356
- ...o._tiptapOptions,
3357
- element: null,
3358
- autofocus: o.autofocus ?? !1,
3359
- extensions: s,
3360
- editorProps: {
3361
- ...(h = o._tiptapOptions) == null ? void 0 : h.editorProps,
3362
- attributes: {
3363
- // As of TipTap v2.5.0 the tabIndex is removed when the editor is not
3364
- // editable, so you can't focus it. We want to revert this as we have
3365
- // UI behaviour that relies on it.
3366
- tabIndex: "0",
3367
- ...(m = (f = o._tiptapOptions) == null ? void 0 : f.editorProps) == null ? void 0 : m.attributes,
3368
- ...(b = o.domAttributes) == null ? void 0 : b.editor,
3369
- class: ee(
3370
- "bn-editor",
3371
- o.defaultStyles ? "bn-default-styles" : "",
3372
- ((x = (g = o.domAttributes) == null ? void 0 : g.editor) == null ? void 0 : x.class) || ""
3373
- )
3374
- },
3375
- transformPasted: Ln
3376
- }
3377
- };
3378
- try {
3379
- const y = o.initialContent || (r ? [
3380
- {
3381
- type: "paragraph",
3382
- id: "initialBlockId"
3383
- }
3384
- ] : [
3385
- {
3386
- type: "paragraph",
3387
- id: ke.options.generateID()
3388
- }
3389
- ]);
3390
- if (!Array.isArray(y) || y.length === 0)
3391
- throw new Error(
3392
- "initialContent must be a non-empty array of blocks, received: " + y
3393
- );
3394
- const I = _t(i.extensions), M = y.map(
3395
- (He) => Z(He, I, this.schema.styleSchema).toJSON()
3396
- ), A = Lt(
3397
- {
3398
- type: "doc",
3399
- content: [
3400
- {
3401
- type: "blockGroup",
3402
- content: M
3403
- }
3404
- ]
3405
- },
3406
- I,
3407
- i.parseOptions
3408
- );
3409
- this._tiptapEditor = new Dt({
3410
- ...i,
3411
- content: A.toJSON()
3412
- }), this.pmSchema = this._tiptapEditor.schema;
3413
- } catch (y) {
3414
- throw new Error(
3415
- "Error creating document from blocks passed as `initialContent`",
3416
- { cause: y }
3417
- );
3418
- }
3419
- let l;
3420
- const a = this.pmSchema.nodes.doc.createAndFill;
3421
- this.pmSchema.nodes.doc.createAndFill = (...y) => {
3422
- if (l)
3423
- return l;
3424
- const I = a.apply(this.pmSchema.nodes.doc, y), M = JSON.parse(JSON.stringify(I.toJSON()));
3425
- return M.content[0].content[0].attrs.id = "initialBlockId", l = ze.fromJSON(this.pmSchema, M), l;
3426
- }, this.pmSchema.cached.blockNoteEditor = this, this._blockManager = new xo(this), this._exportManager = new Lo(this), this._selectionManager = new Mn(this), this._stateManager = new wn(this), this._styleManager = new In(this), this.emit("create");
3427
- }
3428
- static create(t) {
3429
- return new $e(t ?? {});
3430
- }
3431
- /**
3432
- * BlockNote extensions that are added to the editor, keyed by the extension key
3433
- */
3434
- get extensions() {
3435
- return this._extensionManager.getExtensions();
3436
- }
3437
- /**
3438
- * Execute a prosemirror command. This is mostly for backwards compatibility with older code.
3439
- *
3440
- * @note You should prefer the {@link transact} method when possible, as it will automatically handle the dispatching of the transaction and work across blocknote transactions.
3441
- *
3442
- * @example
3443
- * ```ts
3444
- * editor.exec((state, dispatch, view) => {
3445
- * dispatch(state.tr.insertText("Hello, world!"));
3446
- * });
3447
- * ```
3448
- */
3449
- exec(t) {
3450
- return this._stateManager.exec(t);
3451
- }
3452
- /**
3453
- * Check if a command can be executed. A command should return `false` if it is not valid in the current state.
3454
- *
3455
- * @example
3456
- * ```ts
3457
- * if (editor.canExec(command)) {
3458
- * // show button
3459
- * } else {
3460
- * // hide button
3461
- * }
3462
- * ```
3463
- */
3464
- canExec(t) {
3465
- return this._stateManager.canExec(t);
3466
- }
3467
- /**
3468
- * Execute a function within a "blocknote transaction".
3469
- * All changes to the editor within the transaction will be grouped together, so that
3470
- * we can dispatch them as a single operation (thus creating only a single undo step)
3471
- *
3472
- * @note There is no need to dispatch the transaction, as it will be automatically dispatched when the callback is complete.
3473
- *
3474
- * @example
3475
- * ```ts
3476
- * // All changes to the editor will be grouped together
3477
- * editor.transact((tr) => {
3478
- * tr.insertText("Hello, world!");
3479
- * // These two operations will be grouped together in a single undo step
3480
- * editor.transact((tr) => {
3481
- * tr.insertText("Hello, world!");
3482
- * });
3483
- * });
3484
- * ```
3485
- */
3486
- transact(t) {
3487
- return this._stateManager.transact(t);
3488
- }
3489
- /**
3490
- * Get the underlying prosemirror state
3491
- * @note Prefer using `editor.transact` to read the current editor state, as that will ensure the state is up to date
3492
- * @see https://prosemirror.net/docs/ref/#state.EditorState
3493
- */
3494
- get prosemirrorState() {
3495
- return this._stateManager.prosemirrorState;
3496
- }
3497
- /**
3498
- * Get the underlying prosemirror view
3499
- * @see https://prosemirror.net/docs/ref/#view.EditorView
3500
- */
3501
- get prosemirrorView() {
3502
- return this._stateManager.prosemirrorView;
3503
- }
3504
- get domElement() {
3505
- var t;
3506
- if (!this.headless)
3507
- return (t = this.prosemirrorView) == null ? void 0 : t.dom;
3508
- }
3509
- isFocused() {
3510
- var t;
3511
- return this.headless ? !1 : ((t = this.prosemirrorView) == null ? void 0 : t.hasFocus()) || !1;
3512
- }
3513
- get headless() {
3514
- return !this._tiptapEditor.isInitialized;
3515
- }
3516
- /**
3517
- * Focus on the editor
3518
- */
3519
- focus() {
3520
- this.headless || this.prosemirrorView.focus();
3521
- }
3522
- /**
3523
- * Blur the editor
3524
- */
3525
- blur() {
3526
- var t;
3527
- this.headless || (t = this.domElement) == null || t.blur();
3528
- }
3529
- // TODO move to extension
3530
- onUploadStart(t) {
3531
- return this.onUploadStartCallbacks.push(t), () => {
3532
- const o = this.onUploadStartCallbacks.indexOf(t);
3533
- o > -1 && this.onUploadStartCallbacks.splice(o, 1);
3534
- };
3535
- }
3536
- onUploadEnd(t) {
3537
- return this.onUploadEndCallbacks.push(t), () => {
3538
- const o = this.onUploadEndCallbacks.indexOf(t);
3539
- o > -1 && this.onUploadEndCallbacks.splice(o, 1);
3540
- };
3541
- }
3542
- /**
3543
- * @deprecated, use `editor.document` instead
3544
- */
3545
- get topLevelBlocks() {
3546
- return this.document;
3547
- }
3548
- /**
3549
- * Gets a snapshot of all top-level (non-nested) blocks in the editor.
3550
- * @returns A snapshot of all top-level (non-nested) blocks in the editor.
3551
- */
3552
- get document() {
3553
- return this._blockManager.document;
3554
- }
3555
- /**
3556
- * Gets a snapshot of an existing block from the editor.
3557
- * @param blockIdentifier The identifier of an existing block that should be
3558
- * retrieved.
3559
- * @returns The block that matches the identifier, or `undefined` if no
3560
- * matching block was found.
3561
- */
3562
- getBlock(t) {
3563
- return this._blockManager.getBlock(t);
3564
- }
3565
- /**
3566
- * Gets a snapshot of the previous sibling of an existing block from the
3567
- * editor.
3568
- * @param blockIdentifier The identifier of an existing block for which the
3569
- * previous sibling should be retrieved.
3570
- * @returns The previous sibling of the block that matches the identifier.
3571
- * `undefined` if no matching block was found, or it's the first child/block
3572
- * in the document.
3573
- */
3574
- getPrevBlock(t) {
3575
- return this._blockManager.getPrevBlock(t);
3576
- }
3577
- /**
3578
- * Gets a snapshot of the next sibling of an existing block from the editor.
3579
- * @param blockIdentifier The identifier of an existing block for which the
3580
- * next sibling should be retrieved.
3581
- * @returns The next sibling of the block that matches the identifier.
3582
- * `undefined` if no matching block was found, or it's the last child/block in
3583
- * the document.
3584
- */
3585
- getNextBlock(t) {
3586
- return this._blockManager.getNextBlock(t);
3587
- }
3588
- /**
3589
- * Gets a snapshot of the parent of an existing block from the editor.
3590
- * @param blockIdentifier The identifier of an existing block for which the
3591
- * parent should be retrieved.
3592
- * @returns The parent of the block that matches the identifier. `undefined`
3593
- * if no matching block was found, or the block isn't nested.
3594
- */
3595
- getParentBlock(t) {
3596
- return this._blockManager.getParentBlock(t);
3597
- }
3598
- /**
3599
- * Traverses all blocks in the editor depth-first, and executes a callback for each.
3600
- * @param callback The callback to execute for each block. Returning `false` stops the traversal.
3601
- * @param reverse Whether the blocks should be traversed in reverse order.
3602
- */
3603
- forEachBlock(t, o = !1) {
3604
- this._blockManager.forEachBlock(t, o);
3605
- }
3606
- /**
3607
- * Executes a callback whenever the editor's contents change.
3608
- * @param callback The callback to execute.
3609
- *
3610
- * @deprecated use {@link BlockNoteEditor.onChange} instead
3611
- */
3612
- onEditorContentChange(t) {
3613
- this._tiptapEditor.on("update", t);
3614
- }
3615
- /**
3616
- * Executes a callback whenever the editor's selection changes.
3617
- * @param callback The callback to execute.
3618
- *
3619
- * @deprecated use `onSelectionChange` instead
3620
- */
3621
- onEditorSelectionChange(t) {
3622
- this._tiptapEditor.on("selectionUpdate", t);
3623
- }
3624
- /**
3625
- * Executes a callback before any change is applied to the editor, allowing you to cancel the change.
3626
- * @param callback The callback to execute.
3627
- * @returns A function to remove the callback.
3628
- */
3629
- onBeforeChange(t) {
3630
- return this._extensionManager.getExtension(ye).subscribe(t);
3631
- }
3632
- /**
3633
- * Gets a snapshot of the current text cursor position.
3634
- * @returns A snapshot of the current text cursor position.
3635
- */
3636
- getTextCursorPosition() {
3637
- return this._selectionManager.getTextCursorPosition();
3638
- }
3639
- /**
3640
- * Sets the text cursor position to the start or end of an existing block. Throws an error if the target block could
3641
- * not be found.
3642
- * @param targetBlock The identifier of an existing block that the text cursor should be moved to.
3643
- * @param placement Whether the text cursor should be placed at the start or end of the block.
3644
- */
3645
- setTextCursorPosition(t, o = "start") {
3646
- return this._selectionManager.setTextCursorPosition(t, o);
3647
- }
3648
- /**
3649
- * Gets a snapshot of the current selection. This contains all blocks (included nested blocks)
3650
- * that the selection spans across.
3651
- *
3652
- * If the selection starts / ends halfway through a block, the returned data will contain the entire block.
3653
- */
3654
- getSelection() {
3655
- return this._selectionManager.getSelection();
3656
- }
3657
- /**
3658
- * Gets a snapshot of the current selection. This contains all blocks (included nested blocks)
3659
- * that the selection spans across.
3660
- *
3661
- * If the selection starts / ends halfway through a block, the returned block will be
3662
- * only the part of the block that is included in the selection.
3663
- */
3664
- getSelectionCutBlocks(t = !1) {
3665
- return this._selectionManager.getSelectionCutBlocks(t);
3666
- }
3667
- /**
3668
- * Sets the selection to a range of blocks.
3669
- * @param startBlock The identifier of the block that should be the start of the selection.
3670
- * @param endBlock The identifier of the block that should be the end of the selection.
3671
- */
3672
- setSelection(t, o) {
3673
- return this._selectionManager.setSelection(t, o);
3674
- }
3675
- /**
3676
- * Checks if the editor is currently editable, or if it's locked.
3677
- * @returns True if the editor is editable, false otherwise.
3678
- */
3679
- get isEditable() {
3680
- return this._stateManager.isEditable;
3681
- }
3682
- /**
3683
- * Makes the editor editable or locks it, depending on the argument passed.
3684
- * @param editable True to make the editor editable, or false to lock it.
3685
- */
3686
- set isEditable(t) {
3687
- this._stateManager.isEditable = t;
3688
- }
3689
- /**
3690
- * Inserts new blocks into the editor. If a block's `id` is undefined, BlockNote generates one automatically. Throws an
3691
- * error if the reference block could not be found.
3692
- * @param blocksToInsert An array of partial blocks that should be inserted.
3693
- * @param referenceBlock An identifier for an existing block, at which the new blocks should be inserted.
3694
- * @param placement Whether the blocks should be inserted just before, just after, or nested inside the
3695
- * `referenceBlock`.
3696
- */
3697
- insertBlocks(t, o, s = "before") {
3698
- return this._blockManager.insertBlocks(
3699
- t,
3700
- o,
3701
- s
3702
- );
3703
- }
3704
- /**
3705
- * Updates an existing block in the editor. Since updatedBlock is a PartialBlock object, some fields might not be
3706
- * defined. These undefined fields are kept as-is from the existing block. Throws an error if the block to update could
3707
- * not be found.
3708
- * @param blockToUpdate The block that should be updated.
3709
- * @param update A partial block which defines how the existing block should be changed.
3710
- */
3711
- updateBlock(t, o) {
3712
- return this._blockManager.updateBlock(t, o);
3713
- }
3714
- /**
3715
- * Removes existing blocks from the editor. Throws an error if any of the blocks could not be found.
3716
- * @param blocksToRemove An array of identifiers for existing blocks that should be removed.
3717
- */
3718
- removeBlocks(t) {
3719
- return this._blockManager.removeBlocks(t);
3720
- }
3721
- /**
3722
- * Replaces existing blocks in the editor with new blocks. If the blocks that should be removed are not adjacent or
3723
- * are at different nesting levels, `blocksToInsert` will be inserted at the position of the first block in
3724
- * `blocksToRemove`. Throws an error if any of the blocks to remove could not be found.
3725
- * @param blocksToRemove An array of blocks that should be replaced.
3726
- * @param blocksToInsert An array of partial blocks to replace the old ones with.
3727
- */
3728
- replaceBlocks(t, o) {
3729
- return this._blockManager.replaceBlocks(t, o);
3730
- }
3731
- /**
3732
- * Undo the last action.
3733
- */
3734
- undo() {
3735
- return this._stateManager.undo();
3736
- }
3737
- /**
3738
- * Redo the last action.
3739
- */
3740
- redo() {
3741
- return this._stateManager.redo();
3742
- }
3743
- /**
3744
- * Insert a piece of content at the current cursor position.
3745
- *
3746
- * @param content can be a string, or array of partial inline content elements
3747
- */
3748
- insertInlineContent(t, { updateSelection: o = !1 } = {}) {
3749
- this._styleManager.insertInlineContent(t, { updateSelection: o });
3750
- }
3751
- /**
3752
- * Gets the active text styles at the text cursor position or at the end of the current selection if it's active.
3753
- */
3754
- getActiveStyles() {
3755
- return this._styleManager.getActiveStyles();
3756
- }
3757
- /**
3758
- * Adds styles to the currently selected content.
3759
- * @param styles The styles to add.
3760
- */
3761
- addStyles(t) {
3762
- this._styleManager.addStyles(t);
3763
- }
3764
- /**
3765
- * Removes styles from the currently selected content.
3766
- * @param styles The styles to remove.
3767
- */
3768
- removeStyles(t) {
3769
- this._styleManager.removeStyles(t);
3770
- }
3771
- /**
3772
- * Toggles styles on the currently selected content.
3773
- * @param styles The styles to toggle.
3774
- */
3775
- toggleStyles(t) {
3776
- this._styleManager.toggleStyles(t);
3777
- }
3778
- /**
3779
- * Gets the currently selected text.
3780
- */
3781
- getSelectedText() {
3782
- return this._styleManager.getSelectedText();
3783
- }
3784
- /**
3785
- * Gets the URL of the last link in the current selection, or `undefined` if there are no links in the selection.
3786
- */
3787
- getSelectedLinkUrl() {
3788
- return this._styleManager.getSelectedLinkUrl();
3789
- }
3790
- /**
3791
- * Creates a new link to replace the selected content.
3792
- * @param url The link URL.
3793
- * @param text The text to display the link with.
3794
- */
3795
- createLink(t, o) {
3796
- this._styleManager.createLink(t, o);
3797
- }
3798
- /**
3799
- * Checks if the block containing the text cursor can be nested.
3800
- */
3801
- canNestBlock() {
3802
- return this._blockManager.canNestBlock();
3803
- }
3804
- /**
3805
- * Nests the block containing the text cursor into the block above it.
3806
- */
3807
- nestBlock() {
3808
- this._blockManager.nestBlock();
3809
- }
3810
- /**
3811
- * Checks if the block containing the text cursor is nested.
3812
- */
3813
- canUnnestBlock() {
3814
- return this._blockManager.canUnnestBlock();
3815
- }
3816
- /**
3817
- * Lifts the block containing the text cursor out of its parent.
3818
- */
3819
- unnestBlock() {
3820
- this._blockManager.unnestBlock();
3821
- }
3822
- /**
3823
- * Moves the selected blocks up. If the previous block has children, moves
3824
- * them to the end of its children. If there is no previous block, but the
3825
- * current blocks share a common parent, moves them out of & before it.
3826
- */
3827
- moveBlocksUp() {
3828
- return this._blockManager.moveBlocksUp();
3829
- }
3830
- /**
3831
- * Moves the selected blocks down. If the next block has children, moves
3832
- * them to the start of its children. If there is no next block, but the
3833
- * current blocks share a common parent, moves them out of & after it.
3834
- */
3835
- moveBlocksDown() {
3836
- return this._blockManager.moveBlocksDown();
3837
- }
3838
- /**
3839
- * Exports blocks into a simplified HTML string. To better conform to HTML standards, children of blocks which aren't list
3840
- * items are un-nested in the output HTML.
3841
- *
3842
- * @param blocks An array of blocks that should be serialized into HTML.
3843
- * @returns The blocks, serialized as an HTML string.
3844
- */
3845
- blocksToHTMLLossy(t = this.document) {
3846
- return this._exportManager.blocksToHTMLLossy(t);
3847
- }
3848
- /**
3849
- * Serializes blocks into an HTML string in the format that would normally be rendered by the editor.
3850
- *
3851
- * Use this method if you want to server-side render HTML (for example, a blog post that has been edited in BlockNote)
3852
- * and serve it to users without loading the editor on the client (i.e.: displaying the blog post)
3853
- *
3854
- * @param blocks An array of blocks that should be serialized into HTML.
3855
- * @returns The blocks, serialized as an HTML string.
3856
- */
3857
- blocksToFullHTML(t = this.document) {
3858
- return this._exportManager.blocksToFullHTML(t);
3859
- }
3860
- /**
3861
- * Parses blocks from an HTML string. Tries to create `Block` objects out of any HTML block-level elements, and
3862
- * `InlineNode` objects from any HTML inline elements, though not all element types are recognized. If BlockNote
3863
- * doesn't recognize an HTML element's tag, it will parse it as a paragraph or plain text.
3864
- * @param html The HTML string to parse blocks from.
3865
- * @returns The blocks parsed from the HTML string.
3866
- */
3867
- tryParseHTMLToBlocks(t) {
3868
- return this._exportManager.tryParseHTMLToBlocks(t);
3869
- }
3870
- /**
3871
- * Serializes blocks into a Markdown string. The output is simplified as Markdown does not support all features of
3872
- * BlockNote - children of blocks which aren't list items are un-nested and certain styles are removed.
3873
- * @param blocks An array of blocks that should be serialized into Markdown.
3874
- * @returns The blocks, serialized as a Markdown string.
3875
- */
3876
- blocksToMarkdownLossy(t = this.document) {
3877
- return this._exportManager.blocksToMarkdownLossy(t);
3878
- }
3879
- /**
3880
- * Creates a list of blocks from a Markdown string. Tries to create `Block` and `InlineNode` objects based on
3881
- * Markdown syntax, though not all symbols are recognized. If BlockNote doesn't recognize a symbol, it will parse it
3882
- * as text.
3883
- * @param markdown The Markdown string to parse blocks from.
3884
- * @returns The blocks parsed from the Markdown string.
3885
- */
3886
- tryParseMarkdownToBlocks(t) {
3887
- return this._exportManager.tryParseMarkdownToBlocks(t);
3888
- }
3889
- /**
3890
- * A callback function that runs whenever the editor's contents change.
3891
- *
3892
- * @param callback The callback to execute.
3893
- * @returns A function to remove the callback.
3894
- */
3895
- onChange(t, o) {
3896
- return this._eventManager.onChange(t, o);
3897
- }
3898
- /**
3899
- * A callback function that runs whenever the text cursor position or selection changes.
3900
- *
3901
- * @param callback The callback to execute.
3902
- * @returns A function to remove the callback.
3903
- */
3904
- onSelectionChange(t, o) {
3905
- return this._eventManager.onSelectionChange(
3906
- t,
3907
- o
3908
- );
3909
- }
3910
- /**
3911
- * A callback function that runs when the editor has been mounted.
3912
- *
3913
- * This can be useful for plugins to initialize themselves after the editor has been mounted.
3914
- *
3915
- * @param callback The callback to execute.
3916
- * @returns A function to remove the callback.
3917
- */
3918
- onMount(t) {
3919
- this._eventManager.onMount(t);
3920
- }
3921
- /**
3922
- * A callback function that runs when the editor has been unmounted.
3923
- *
3924
- * This can be useful for plugins to clean up themselves after the editor has been unmounted.
3925
- *
3926
- * @param callback The callback to execute.
3927
- * @returns A function to remove the callback.
3928
- */
3929
- onUnmount(t) {
3930
- this._eventManager.onUnmount(t);
3931
- }
3932
- /**
3933
- * Gets the bounding box of the current selection.
3934
- * @returns The bounding box of the current selection.
3935
- */
3936
- getSelectionBoundingBox() {
3937
- return this._selectionManager.getSelectionBoundingBox();
3938
- }
3939
- get isEmpty() {
3940
- const t = this.document;
3941
- return t.length === 0 || t.length === 1 && t[0].type === "paragraph" && t[0].content.length === 0;
3942
- }
3943
- /**
3944
- * Paste HTML into the editor. Defaults to converting HTML to BlockNote HTML.
3945
- * @param html The HTML to paste.
3946
- * @param raw Whether to paste the HTML as is, or to convert it to BlockNote HTML.
3947
- */
3948
- pasteHTML(t, o = !1) {
3949
- this._exportManager.pasteHTML(t, o);
3950
- }
3951
- /**
3952
- * Paste text into the editor. Defaults to interpreting text as markdown.
3953
- * @param text The text to paste.
3954
- */
3955
- pasteText(t) {
3956
- return this._exportManager.pasteText(t);
3957
- }
3958
- /**
3959
- * Paste markdown into the editor.
3960
- * @param markdown The markdown to paste.
3961
- */
3962
- pasteMarkdown(t) {
3963
- return this._exportManager.pasteMarkdown(t);
3964
- }
3965
- }
3966
- class ds {
3967
- constructor(e, t, o) {
3968
- this.mappings = t, this.options = o;
3969
- }
3970
- async resolveFile(e) {
3971
- var o;
3972
- if (!((o = this.options) != null && o.resolveFileUrl))
3973
- return (await fetch(e)).blob();
3974
- const t = await this.options.resolveFileUrl(e);
3975
- return t instanceof Blob ? t : (await fetch(t)).blob();
3976
- }
3977
- mapStyles(e) {
3978
- return Object.entries(e).map(([o, s]) => this.mappings.styleMapping[o](s, this));
3979
- }
3980
- mapInlineContent(e) {
3981
- return this.mappings.inlineContentMapping[e.type](
3982
- e,
3983
- this
3984
- );
3985
- }
3986
- transformInlineContent(e) {
3987
- return e.map((t) => this.mapInlineContent(t));
3988
- }
3989
- async mapBlock(e, t, o, s) {
3990
- return this.mappings.blockMapping[e.type](
3991
- e,
3992
- this,
3993
- t,
3994
- o,
3995
- s
3996
- );
3997
- }
3998
- }
3999
- function us(n) {
4000
- return {
4001
- createBlockMapping: (e) => e,
4002
- createInlineContentMapping: (e) => e,
4003
- createStyleMapping: (e) => e
4004
- };
4005
- }
4006
- function ps(n, ...e) {
4007
- const t = [...n];
4008
- for (const o of e)
4009
- for (const s of o) {
4010
- const r = t.findLastIndex(
4011
- (i) => i.group === s.group
4012
- );
4013
- r === -1 ? t.push(s) : t.splice(r + 1, 0, s);
4014
- }
4015
- return t;
4016
- }
4017
- export {
4018
- ye as BlockChangeExtension,
4019
- $e as BlockNoteEditor,
4020
- Mt as BlockNoteSchema,
4021
- Is as COLORS_DARK_MODE_DEFAULT,
4022
- As as COLORS_DEFAULT,
4023
- Bi as CustomBlockNoteSchema,
4024
- Pt as DEFAULT_LINK_PROTOCOL,
4025
- pi as DRAG_EXCLUSION_CLASSNAME,
4026
- mt as DropCursorExtension,
4027
- Ns as EMPTY_CELL_HEIGHT,
4028
- Xe as EMPTY_CELL_WIDTH,
4029
- Ce as EventEmitter,
4030
- ds as Exporter,
4031
- _s as FILE_AUDIO_ICON_SVG,
4032
- Ls as FILE_IMAGE_ICON_SVG,
4033
- Ds as FILE_VIDEO_ICON_SVG,
4034
- J as FilePanelExtension,
4035
- dt as ForkYDocExtension,
4036
- Y as FormattingToolbarExtension,
4037
- ve as HTMLToBlocks,
4038
- Ct as HistoryExtension,
4039
- kt as LinkToolbarExtension,
4040
- bt as NodeSelectionKeyboardExtension,
4041
- gt as PlaceholderExtension,
4042
- xt as PreviousBlockTypeExtension,
4043
- ht as SchemaMigration,
4044
- jt as ShowSelectionExtension,
4045
- Bt as SideMenuExtension,
4046
- fi as SideMenuView,
4047
- ge as SuggestionMenu,
4048
- St as TableHandlesExtension,
4049
- hi as TableHandlesView,
4050
- yt as TrailingNodeExtension,
4051
- ke as UniqueID,
4052
- U as UnreachableCaseError,
4053
- Et as VALID_LINK_PROTOCOLS,
4054
- ut as YCursorExtension,
4055
- pt as YSyncExtension,
4056
- ft as YUndoExtension,
4057
- Os as addDefaultPropsExternalHTML,
4058
- G as addInlineContentAttributes,
4059
- Je as addInlineContentKeyboardShortcuts,
4060
- $s as addNodeAndExtensionsToSpec,
4061
- Hs as addStyleAttributes,
4062
- Fs as applyNonSelectableBlockFix,
4063
- ms as assertEmpty,
4064
- Vs as audioParse,
4065
- Us as audioRender,
4066
- zs as audioToExternalHTML,
4067
- Rs as blockHasType,
4068
- Z as blockToNode,
4069
- at as blocksToMarkdown,
4070
- Gs as camelToDataKebab,
4071
- js as captureCellAnchor,
4072
- yi as checkPageBreakBlocksInSchema,
4073
- ct as cleanHTMLToMarkdown,
4074
- ps as combineByGroup,
4075
- qe as contentNodeToInlineContent,
4076
- We as contentNodeToTableContent,
4077
- Ws as createAudioBlockConfig,
4078
- qs as createAudioBlockSpec,
4079
- Ks as createBlockConfig,
4080
- Js as createBlockSpec,
4081
- Ys as createBlockSpecFromTiptapNode,
4082
- Qs as createBulletListItemBlockConfig,
4083
- Xs as createBulletListItemBlockSpec,
4084
- Zs as createCheckListItemBlockSpec,
4085
- er as createCheckListItemConfig,
4086
- tr as createCodeBlockConfig,
4087
- or as createCodeBlockSpec,
4088
- nr as createDefaultBlockDOMOutputSpec,
4089
- sr as createDividerBlockConfig,
4090
- rr as createDividerBlockSpec,
4091
- Vt as createExtension,
4092
- Be as createExternalHTMLExporter,
4093
- ir as createFileBlockConfig,
4094
- ar as createFileBlockSpec,
4095
- cr as createHeadingBlockConfig,
4096
- lr as createHeadingBlockSpec,
4097
- dr as createImageBlockConfig,
4098
- ur as createImageBlockSpec,
4099
- ls as createInlineContentSpec,
4100
- Qe as createInlineContentSpecFromTipTapNode,
4101
- lo as createInternalHTMLSerializer,
4102
- pr as createInternalInlineContentSpec,
4103
- fr as createInternalStyleSpec,
4104
- hr as createNumberedListItemBlockConfig,
4105
- mr as createNumberedListItemBlockSpec,
4106
- Ci as createPageBreakBlockConfig,
4107
- Si as createPageBreakBlockSpec,
4108
- kr as createParagraphBlockConfig,
4109
- br as createParagraphBlockSpec,
4110
- gr as createQuoteBlockConfig,
4111
- Br as createQuoteBlockSpec,
4112
- Mi as createStore,
4113
- yr as createStyleSpec,
4114
- Cr as createStyleSpecFromTipTapMark,
4115
- Sr as createTableBlockSpec,
4116
- xr as createToggleListItemBlockConfig,
4117
- Er as createToggleListItemBlockSpec,
4118
- Pr as createToggleWrapper,
4119
- Tr as createVideoBlockConfig,
4120
- Mr as createVideoBlockSpec,
4121
- wr as defaultBlockSpecs,
4122
- vr as defaultBlockToHTML,
4123
- Ir as defaultInlineContentSchema,
4124
- Ar as defaultInlineContentSpecs,
4125
- Nr as defaultProps,
4126
- _r as defaultStyleSchema,
4127
- Lr as defaultStyleSpecs,
4128
- Dr as defaultToggledState,
4129
- je as docToBlocks,
4130
- Or as editorHasBlockWithType,
4131
- Sn as expandPMRangeToWords,
4132
- $r as fileParse,
4133
- Hr as filenameFromURL,
4134
- Fr as filterSuggestionItems,
4135
- H as fixColumnList,
4136
- Vr as formatKeyboardShortcut,
4137
- tt as getBackgroundColorAttribute,
4138
- Bo as getBlock,
4139
- ks as getBlockCache,
4140
- Ur as getBlockFromPos,
4141
- K as getBlockInfo,
4142
- v as getBlockInfoFromResolvedPos,
4143
- B as getBlockInfoFromSelection,
4144
- z as getBlockInfoFromTransaction,
4145
- bs as getBlockInfoWithManualOffset,
4146
- be as getBlockNoteSchema,
4147
- gs as getBlockSchema,
4148
- it as getBlocksChangedByTransaction,
4149
- Bs as getColspan,
4150
- mi as getDefaultEmojiPickerItems,
4151
- zr as getDefaultSlashMenuItems,
4152
- Xt as getInlineContentParseRules,
4153
- ys as getInlineContentSchema,
4154
- Rr as getInlineContentSchemaFromSpecs,
4155
- Gr as getLanguageId,
4156
- D as getNearestBlockPos,
4157
- Co as getNextBlock,
4158
- P as getNodeById,
4159
- xi as getPageBreakSlashMenuItems,
4160
- So as getParentBlock,
4161
- jr as getParseRules,
4162
- E as getPmSchema,
4163
- yo as getPrevBlock,
4164
- Cs as getRowspan,
4165
- Wr as getStyleParseRules,
4166
- Ss as getStyleSchema,
4167
- qr as getStyleSchemaFromSpecs,
4168
- Kr as getTextAlignmentAttribute,
4169
- st as getTextColorAttribute,
4170
- Jr as imageParse,
4171
- Yr as imageRender,
4172
- Qr as imageToExternalHTML,
4173
- V as inlineContentToNodes,
4174
- Zt as insertBlocks,
4175
- Xr as insertOrUpdateBlockForSlashMenu,
4176
- Zr as isAppleOS,
4177
- Q as isEmptyColumn,
4178
- xs as isLinkInlineContent,
4179
- ei as isNodeBlock,
4180
- Es as isPartialLinkInlineContent,
4181
- Ps as isPartialTableCell,
4182
- ti as isSafari,
4183
- Ts as isStyledTextInlineContent,
4184
- Ms as isTableCell,
4185
- oi as isTableCellSelection,
4186
- et as isVideoUrl,
4187
- ws as mapTableCell,
4188
- us as mappingFactory,
4189
- _o as markdownToBlocks,
4190
- Ie as markdownToHTML,
4191
- ee as mergeCSSClasses,
4192
- ni as mergeParagraphs,
4193
- C as nodeToBlock,
4194
- q as nodeToCustomInlineContent,
4195
- si as parseAudioElement,
4196
- ri as parseDefaultProps,
4197
- Ye as propsToAttributes,
4198
- Ke as prosemirrorSliceToSlicedBlocks,
4199
- ae as removeAndInsertBlocks,
4200
- eo as removeEmptyColumns,
4201
- Ne as selectedFragmentToHTML,
4202
- ki as sideMenuPluginKey,
4203
- ii as stylePropsToAttributes,
4204
- Ge as tableContentToNodes,
4205
- bi as tableHandlesPluginKey,
4206
- ai as tablePropSchema,
4207
- ci as trackPosition,
4208
- Ze as updateBlock,
4209
- nt as updateBlockCommand,
4210
- rt as updateBlockTr,
4211
- Ei as uploadToTmpFilesDotOrg_DEV_ONLY,
4212
- li as videoParse,
4213
- Pi as withPageBreak,
4214
- di as wrapInBlockStructure
4215
- };
4216
- //# sourceMappingURL=blocknote.js.map
1
+ import { $ as e, $t as t, A as n, An as r, At as i, B as a, Bn as o, C as s, Cn as c, Ct as l, D as u, Dn as d, Dt as f, E as p, En as m, Et as h, F as g, Fn as _, G as v, Gn as y, Gt as b, H as x, Hn as S, I as C, In as w, J as T, Jn as E, Jt as D, K as O, Kn as k, Kt as A, L as j, Ln as M, M as N, Mn as P, N as F, Nn as I, O as L, On as R, Ot as z, P as B, Pn as V, Q as H, Qt as U, R as W, Rn as G, S as K, Sn as q, St as J, T as Y, Tn as X, Tt as Z, U as Q, Un as $, Ut as ee, Vn as te, Vt as ne, W as re, Wn as ie, Wt as ae, X as oe, Xt as se, Y as ce, Yt as le, Z as ue, Zt as de, _ as fe, _n as pe, _t as me, a as he, an as ge, at as _e, b as ve, bn as ye, bt as be, c as xe, cn as Se, ct as Ce, d as we, dn as Te, dt as Ee, en as De, et as Oe, f as ke, fn as Ae, ft as je, g as Me, gn as Ne, gt as Pe, h as Fe, hn as Ie, ht as Le, i as Re, in as ze, it as Be, j as Ve, jn as He, k as Ue, kn as We, kt as Ge, l as Ke, ln as qe, lt as Je, m as Ye, mn as Xe, mt as Ze, n as Qe, nn as $e, nt as et, o as tt, on as nt, ot as rt, p as it, pn as at, pt as ot, q as st, qn as ct, qt as lt, r as ut, rn as dt, rt as ft, s as pt, sn as mt, st as ht, t as gt, tn as _t, tt as vt, u as yt, un as bt, ut as xt, v as St, vn as Ct, vt as wt, w as Tt, wn as Et, wt as Dt, x as Ot, xn as kt, xt as At, y as jt, yn as Mt, yt as Nt, z as Pt, zn as Ft } from "./blocks-DYl7UTS4.js";
2
+ import { _ as It, a as Lt, b as Rt, c as zt, d as Bt, f as Vt, g as Ht, h as Ut, i as Wt, l as Gt, m as Kt, n as qt, o as Jt, p as Yt, r as Xt, s as Zt, t as Qt, u as $t, v as en, x as tn, y as nn } from "./src-Hjv1f5lc.js";
3
+ import { C as rn, D as an, E as on, O as sn, S as cn, T as ln, _ as un, a as dn, b as fn, c as pn, d as mn, f as hn, g as gn, h as _n, i as vn, k as yn, m as bn, n as xn, o as Sn, p as Cn, r as wn, s as Tn, t as En, u as Dn, v as On, w as kn, x as An, y as jn } from "./extensions-3nf9PPhA.js";
4
+ import { n as Mn, t as Nn } from "./BlockNoteExtension-B6RhuQ3V.js";
5
+ import { t as Pn } from "./ShowSelection-BsHFfdMi.js";
6
+ import { t as Fn } from "./EventEmitter-CuPnGDYt.js";
7
+ export { an as BlockChangeExtension, Wt as BlockNoteEditor, gt as BlockNoteSchema, be as COLORS_DARK_MODE_DEFAULT, At as COLORS_DEFAULT, ne as CustomBlockNoteSchema, _n as DEFAULT_LINK_PROTOCOL, fn as DRAG_EXCLUSION_CLASSNAME, An as DropCursorExtension, Tt as EMPTY_CELL_HEIGHT, Y as EMPTY_CELL_WIDTH, Fn as EventEmitter, Xt as Exporter, rt as FILE_AUDIO_ICON_SVG, x as FILE_IMAGE_ICON_SVG, St as FILE_VIDEO_ICON_SVG, ot as FilePanelExtension, rn as ForkYDocExtension, jn as FormattingToolbarExtension, Gt as HTMLToBlocks, On as HistoryExtension, un as LinkToolbarExtension, bn as NodeSelectionKeyboardExtension, Cn as PlaceholderExtension, hn as PreviousBlockTypeExtension, cn as SchemaMigration, Pn as ShowSelectionExtension, Sn as SideMenuExtension, Tn as SideMenuView, ke as SuggestionMenu, xn as TableHandlesExtension, wn as TableHandlesView, En as TrailingNodeExtension, E as UniqueID, G as UnreachableCaseError, gn as VALID_LINK_PROTOCOLS, on as YCursorExtension, ln as YSyncExtension, kn as YUndoExtension, Ze as addDefaultPropsExternalHTML, se as addInlineContentAttributes, de as addInlineContentKeyboardShortcuts, Mt as addNodeAndExtensionsToSpec, b as addStyleAttributes, ye as applyNonSelectableBlockFix, Ft as assertEmpty, ht as audioParse, Ce as audioRender, Je as audioToExternalHTML, Ye as blockHasType, z as blockToNode, Dn as blocksToMarkdown, R as camelToDataKebab, J as captureCellAnchor, pt as checkPageBreakBlocksInSchema, mn as cleanHTMLToMarkdown, Qt as combineByGroup, _t as contentNodeToInlineContent, $e as contentNodeToTableContent, xt as createAudioBlockConfig, Ee as createAudioBlockSpec, kt as createBlockConfig, q as createBlockSpec, Et as createBlockSpecFromTiptapNode, Pt as createBulletListItemBlockConfig, a as createBulletListItemBlockSpec, j as createCheckListItemBlockSpec, W as createCheckListItemConfig, ft as createCodeBlockConfig, Be as createCodeBlockSpec, He as createDefaultBlockDOMOutputSpec, vt as createDividerBlockConfig, et as createDividerBlockSpec, Nn as createExtension, yn as createExternalHTMLExporter, H as createFileBlockConfig, e as createFileBlockSpec, T as createHeadingBlockConfig, ce as createHeadingBlockSpec, Q as createImageBlockConfig, re as createImageBlockSpec, Rt as createInlineContentSpec, U as createInlineContentSpecFromTipTapNode, Kt as createInternalHTMLSerializer, t as createInternalInlineContentSpec, A as createInternalStyleSpec, g as createNumberedListItemBlockConfig, C as createNumberedListItemBlockSpec, n as createPageBreakBlockConfig, Ve as createPageBreakBlockSpec, L as createParagraphBlockConfig, Ue as createParagraphBlockSpec, p as createQuoteBlockConfig, u as createQuoteBlockSpec, Mn as createStore, ee as createStyleSpec, lt as createStyleSpecFromTipTapMark, K as createTableBlockSpec, F as createToggleListItemBlockConfig, B as createToggleListItemBlockSpec, oe as createToggleWrapper, jt as createVideoBlockConfig, ve as createVideoBlockSpec, Qe as defaultBlockSpecs, P as defaultBlockToHTML, ut as defaultInlineContentSchema, Re as defaultInlineContentSpecs, Le as defaultProps, he as defaultStyleSchema, tt as defaultStyleSpecs, ue as defaultToggledState, dt as docToBlocks, Fe as editorHasBlockWithType, Lt as expandPMRangeToWords, Oe as fileParse, We as filenameFromURL, Ke as filterSuggestionItems, Ht as fixColumnList, V as formatKeyboardShortcut, Pe as getBackgroundColorAttribute, $t as getBlock, mt as getBlockCache, X as getBlockFromPos, at as getBlockInfo, Xe as getBlockInfoFromResolvedPos, Ie as getBlockInfoFromSelection, Ne as getBlockInfoFromTransaction, pe as getBlockInfoWithManualOffset, Se as getBlockNoteSchema, qe as getBlockSchema, sn as getBlocksChangedByTransaction, o as getColspan, dn as getDefaultEmojiPickerItems, yt as getDefaultSlashMenuItems, tn as getInlineContentParseRules, bt as getInlineContentSchema, De as getInlineContentSchemaFromSpecs, _e as getLanguageId, Ct as getNearestBlockPos, Bt as getNextBlock, h as getNodeById, xe as getPageBreakSlashMenuItems, Vt as getParentBlock, c as getParseRules, Te as getPmSchema, Yt as getPrevBlock, te as getRowspan, ae as getStyleParseRules, Ae as getStyleSchema, D as getStyleSchemaFromSpecs, me as getTextAlignmentAttribute, wt as getTextColorAttribute, v as imageParse, O as imageRender, st as imageToExternalHTML, Ge as inlineContentToNodes, nn as insertBlocks, we as insertOrUpdateBlockForSlashMenu, _ as isAppleOS, It as isEmptyColumn, y as isLinkInlineContent, f as isNodeBlock, k as isPartialLinkInlineContent, S as isPartialTableCell, w as isSafari, ct as isStyledTextInlineContent, $ as isTableCell, Me as isTableCellSelection, r as isVideoUrl, ie as mapTableCell, qt as mappingFactory, Zt as markdownToBlocks, zt as markdownToHTML, M as mergeCSSClasses, I as mergeParagraphs, ze as nodeToBlock, ge as nodeToCustomInlineContent, je as parseAudioElement, Nt as parseDefaultProps, m as propsToAttributes, nt as prosemirrorSliceToSlicedBlocks, Ut as removeAndInsertBlocks, en as removeEmptyColumns, Jt as selectedFragmentToHTML, pn as sideMenuPluginKey, le as stylePropsToAttributes, i as tableContentToNodes, vn as tableHandlesPluginKey, s as tablePropSchema, it as trackPosition, l as updateBlock, Dt as updateBlockCommand, Z as updateBlockTr, fe as uploadToTmpFilesDotOrg_DEV_ONLY, Ot as videoParse, N as withPageBreak, d as wrapInBlockStructure };