@blocknote/core 0.41.1 → 0.42.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 (81) hide show
  1. package/dist/BlockNoteSchema-Bi-eeHal.js +3288 -0
  2. package/dist/BlockNoteSchema-Bi-eeHal.js.map +1 -0
  3. package/dist/BlockNoteSchema-DjDaA2C3.cjs +6 -0
  4. package/dist/BlockNoteSchema-DjDaA2C3.cjs.map +1 -0
  5. package/dist/blockToNode-DIfPWLH8.js +1140 -0
  6. package/dist/blockToNode-DIfPWLH8.js.map +1 -0
  7. package/dist/blockToNode-w7H99R6p.cjs +7 -0
  8. package/dist/blockToNode-w7H99R6p.cjs.map +1 -0
  9. package/dist/blocknote.cjs +4 -4
  10. package/dist/blocknote.cjs.map +1 -1
  11. package/dist/blocknote.js +1413 -1366
  12. package/dist/blocknote.js.map +1 -1
  13. package/dist/blocks.cjs +1 -1
  14. package/dist/blocks.js +1 -1
  15. package/dist/comments.cjs +1 -1
  16. package/dist/comments.cjs.map +1 -1
  17. package/dist/comments.js +49 -49
  18. package/dist/comments.js.map +1 -1
  19. package/dist/en-Cl87Uuyf.cjs.map +1 -1
  20. package/dist/en-njEqD7AG.js.map +1 -1
  21. package/dist/locales.cjs.map +1 -1
  22. package/dist/locales.js.map +1 -1
  23. package/dist/tsconfig.tsbuildinfo +1 -0
  24. package/dist/webpack-stats.json +1 -1
  25. package/dist/yjs.cjs +2 -0
  26. package/dist/yjs.cjs.map +1 -0
  27. package/dist/yjs.js +44 -0
  28. package/dist/yjs.js.map +1 -0
  29. package/package.json +30 -25
  30. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +19 -6
  31. package/src/api/blockManipulation/commands/replaceBlocks/util/fixColumnList.ts +173 -0
  32. package/src/api/nodeConversions/nodeToBlock.ts +17 -14
  33. package/src/blocks/Code/block.ts +1 -0
  34. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +2 -1
  35. package/src/blocks/defaultBlockTypeGuards.ts +7 -18
  36. package/src/comments/threadstore/yjs/YjsThreadStoreBase.ts +3 -1
  37. package/src/editor/BlockNoteEditor.test.ts +70 -1
  38. package/src/editor/BlockNoteEditor.ts +55 -4
  39. package/src/editor/managers/ExportManager.ts +1 -1
  40. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +2 -2
  41. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +2 -2
  42. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -1
  43. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -1
  44. package/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.ts +10 -3
  45. package/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.test.ts +130 -0
  46. package/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.ts +34 -21
  47. package/src/extensions/Comments/CommentsPlugin.ts +37 -7
  48. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +30 -128
  49. package/src/extensions/SideMenu/SideMenuPlugin.ts +2 -0
  50. package/src/index.ts +1 -0
  51. package/src/schema/inlineContent/createSpec.ts +3 -0
  52. package/src/schema/inlineContent/types.ts +1 -0
  53. package/src/schema/schema.ts +49 -6
  54. package/src/schema/styles/createSpec.ts +6 -0
  55. package/src/schema/styles/types.ts +1 -0
  56. package/src/yjs/index.ts +1 -0
  57. package/src/yjs/utils.test.ts +1023 -0
  58. package/src/yjs/utils.ts +150 -0
  59. package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +1 -1
  60. package/types/src/api/blockManipulation/commands/replaceBlocks/util/fixColumnList.d.ts +32 -0
  61. package/types/src/api/nodeConversions/nodeToBlock.d.ts +1 -1
  62. package/types/src/editor/BlockNoteEditor.d.ts +6 -1
  63. package/types/src/editor/managers/ExportManager.d.ts +1 -1
  64. package/types/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.test.d.ts +1 -0
  65. package/types/src/extensions/Comments/CommentsPlugin.d.ts +1 -1
  66. package/types/src/index.d.ts +1 -0
  67. package/types/src/schema/inlineContent/createSpec.d.ts +1 -0
  68. package/types/src/schema/inlineContent/types.d.ts +1 -0
  69. package/types/src/schema/styles/createSpec.d.ts +1 -0
  70. package/types/src/schema/styles/types.d.ts +1 -0
  71. package/types/src/yjs/index.d.ts +1 -0
  72. package/types/src/yjs/utils.d.ts +55 -0
  73. package/types/src/yjs/utils.test.d.ts +1 -0
  74. package/dist/BlockNoteSchema-COA0fsXW.cjs +0 -11
  75. package/dist/BlockNoteSchema-COA0fsXW.cjs.map +0 -1
  76. package/dist/BlockNoteSchema-CYRHak18.js +0 -4375
  77. package/dist/BlockNoteSchema-CYRHak18.js.map +0 -1
  78. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +0 -46
  79. package/src/extensions/TextColor/TextColorMark.ts +0 -38
  80. package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +0 -10
  81. package/types/src/extensions/TextColor/TextColorMark.d.ts +0 -10
@@ -0,0 +1,1140 @@
1
+ import { Extension as ot, combineTransactionSteps as rt, getChangedRanges as st, findChildrenInRange as it } from "@tiptap/core";
2
+ import { Slice as lt, Fragment as at } from "prosemirror-model";
3
+ import { Plugin as ct, PluginKey as ft } from "prosemirror-state";
4
+ import { v4 as ut } from "uuid";
5
+ function pt(t, o = JSON.stringify) {
6
+ const r = {};
7
+ return t.filter((n) => {
8
+ const e = o(n);
9
+ return Object.prototype.hasOwnProperty.call(r, e) ? !1 : r[e] = !0;
10
+ });
11
+ }
12
+ function dt(t) {
13
+ const o = t.filter(
14
+ (n, e) => t.indexOf(n) !== e
15
+ );
16
+ return pt(o);
17
+ }
18
+ const Q = ot.create({
19
+ name: "uniqueID",
20
+ // we’ll set a very high priority to make sure this runs first
21
+ // and is compatible with `appendTransaction` hooks of other extensions
22
+ priority: 1e4,
23
+ addOptions() {
24
+ return {
25
+ attributeName: "id",
26
+ types: [],
27
+ setIdAttribute: !1,
28
+ generateID: () => {
29
+ if (typeof window < "u" && window.__TEST_OPTIONS) {
30
+ const t = window.__TEST_OPTIONS;
31
+ return t.mockID === void 0 ? t.mockID = 0 : t.mockID++, t.mockID.toString();
32
+ }
33
+ return ut();
34
+ },
35
+ filterTransaction: null
36
+ };
37
+ },
38
+ addGlobalAttributes() {
39
+ return [
40
+ {
41
+ types: this.options.types,
42
+ attributes: {
43
+ [this.options.attributeName]: {
44
+ default: null,
45
+ parseHTML: (t) => t.getAttribute(`data-${this.options.attributeName}`),
46
+ renderHTML: (t) => {
47
+ const o = {
48
+ [`data-${this.options.attributeName}`]: t[this.options.attributeName]
49
+ };
50
+ return this.options.setIdAttribute ? {
51
+ ...o,
52
+ id: t[this.options.attributeName]
53
+ } : o;
54
+ }
55
+ }
56
+ }
57
+ }
58
+ ];
59
+ },
60
+ // check initial content for missing ids
61
+ // onCreate() {
62
+ // // Don’t do this when the collaboration extension is active
63
+ // // because this may update the content, so Y.js tries to merge these changes.
64
+ // // This leads to empty block nodes.
65
+ // // See: https://github.com/ueberdosis/tiptap/issues/2400
66
+ // if (
67
+ // this.editor.extensionManager.extensions.find(
68
+ // (extension) => extension.name === "collaboration"
69
+ // )
70
+ // ) {
71
+ // return;
72
+ // }
73
+ // const { view, state } = this.editor;
74
+ // const { tr, doc } = state;
75
+ // const { types, attributeName, generateID } = this.options;
76
+ // const nodesWithoutId = findChildren(doc, (node) => {
77
+ // return (
78
+ // types.includes(node.type.name) && node.attrs[attributeName] === null
79
+ // );
80
+ // });
81
+ // nodesWithoutId.forEach(({ node, pos }) => {
82
+ // tr.setNodeMarkup(pos, undefined, {
83
+ // ...node.attrs,
84
+ // [attributeName]: generateID(),
85
+ // });
86
+ // });
87
+ // tr.setMeta("addToHistory", false);
88
+ // view.dispatch(tr);
89
+ // },
90
+ addProseMirrorPlugins() {
91
+ let t = null, o = !1;
92
+ return [
93
+ new ct({
94
+ key: new ft("uniqueID"),
95
+ appendTransaction: (r, n, e) => {
96
+ const s = r.some((g) => g.docChanged) && !n.doc.eq(e.doc), i = this.options.filterTransaction && r.some((g) => {
97
+ var C, d;
98
+ return !((d = (C = this.options).filterTransaction) != null && d.call(C, g));
99
+ });
100
+ if (!s || i)
101
+ return;
102
+ const { tr: l } = e, { types: a, attributeName: c, generateID: h } = this.options, f = rt(
103
+ n.doc,
104
+ r
105
+ ), { mapping: p } = f;
106
+ if (st(f).forEach(({ newRange: g }) => {
107
+ const C = it(
108
+ e.doc,
109
+ g,
110
+ (y) => a.includes(y.type.name)
111
+ ), d = C.map(({ node: y }) => y.attrs[c]).filter((y) => y !== null), w = dt(d);
112
+ C.forEach(({ node: y, pos: m }) => {
113
+ var z;
114
+ const b = (z = l.doc.nodeAt(m)) == null ? void 0 : z.attrs[c];
115
+ if (b === null) {
116
+ const U = n.doc.type.createAndFill().content;
117
+ if (n.doc.content.findDiffStart(U) === null) {
118
+ const q = JSON.parse(
119
+ JSON.stringify(e.doc.toJSON())
120
+ );
121
+ if (q.content[0].content[0].attrs.id = "initialBlockId", JSON.stringify(q.content) === JSON.stringify(U.toJSON())) {
122
+ l.setNodeMarkup(m, void 0, {
123
+ ...y.attrs,
124
+ [c]: "initialBlockId"
125
+ });
126
+ return;
127
+ }
128
+ }
129
+ l.setNodeMarkup(m, void 0, {
130
+ ...y.attrs,
131
+ [c]: h()
132
+ });
133
+ return;
134
+ }
135
+ const { deleted: k } = p.invert().mapResult(m);
136
+ k && w.includes(b) && l.setNodeMarkup(m, void 0, {
137
+ ...y.attrs,
138
+ [c]: h()
139
+ });
140
+ });
141
+ }), !!l.steps.length)
142
+ return l.setMeta("uniqueID", !0), l;
143
+ },
144
+ // we register a global drag handler to track the current drag source element
145
+ view(r) {
146
+ const n = (e) => {
147
+ let s;
148
+ t = !((s = r.dom.parentElement) === null || s === void 0) && s.contains(e.target) ? r.dom.parentElement : null;
149
+ };
150
+ return window.addEventListener("dragstart", n), {
151
+ destroy() {
152
+ window.removeEventListener("dragstart", n);
153
+ }
154
+ };
155
+ },
156
+ props: {
157
+ // `handleDOMEvents` is called before `transformPasted` so we can do
158
+ // some checks before. However, `transformPasted` only runs when
159
+ // editor content is pasted - not external content.
160
+ handleDOMEvents: {
161
+ // only create new ids for dropped content while holding `alt`
162
+ // or content is dragged from another editor
163
+ drop: (r, n) => {
164
+ let e;
165
+ return t !== r.dom.parentElement || ((e = n.dataTransfer) === null || e === void 0 ? void 0 : e.effectAllowed) === "copy" ? o = !0 : o = !1, t = null, !1;
166
+ },
167
+ // always create new ids on pasted content
168
+ paste: () => (o = !0, !1)
169
+ },
170
+ // we’ll remove ids for every pasted node
171
+ // so we can create a new one within `appendTransaction`
172
+ transformPasted: (r) => {
173
+ if (!o)
174
+ return r;
175
+ const { types: n, attributeName: e } = this.options, s = (i) => {
176
+ const l = [];
177
+ return i.forEach((a) => {
178
+ if (a.isText) {
179
+ l.push(a);
180
+ return;
181
+ }
182
+ if (!n.includes(a.type.name)) {
183
+ l.push(a.copy(s(a.content)));
184
+ return;
185
+ }
186
+ const c = a.type.create(
187
+ {
188
+ ...a.attrs,
189
+ [e]: null
190
+ },
191
+ s(a.content),
192
+ a.marks
193
+ );
194
+ l.push(c);
195
+ }), at.from(l);
196
+ };
197
+ return o = !1, new lt(
198
+ s(r.content),
199
+ r.openStart,
200
+ r.openEnd
201
+ );
202
+ }
203
+ }
204
+ })
205
+ ];
206
+ }
207
+ });
208
+ function K(t) {
209
+ return t.type === "link";
210
+ }
211
+ function X(t) {
212
+ return typeof t != "string" && t.type === "link";
213
+ }
214
+ function B(t) {
215
+ return typeof t != "string" && t.type === "text";
216
+ }
217
+ function S(t) {
218
+ var o, r, n, e, s;
219
+ return R(t) ? { ...t } : v(t) ? {
220
+ type: "tableCell",
221
+ content: [].concat(t.content),
222
+ props: {
223
+ backgroundColor: ((o = t.props) == null ? void 0 : o.backgroundColor) ?? "default",
224
+ textColor: ((r = t.props) == null ? void 0 : r.textColor) ?? "default",
225
+ textAlignment: ((n = t.props) == null ? void 0 : n.textAlignment) ?? "left",
226
+ colspan: ((e = t.props) == null ? void 0 : e.colspan) ?? 1,
227
+ rowspan: ((s = t.props) == null ? void 0 : s.rowspan) ?? 1
228
+ }
229
+ } : {
230
+ type: "tableCell",
231
+ content: [].concat(t),
232
+ props: {
233
+ backgroundColor: "default",
234
+ textColor: "default",
235
+ textAlignment: "left",
236
+ colspan: 1,
237
+ rowspan: 1
238
+ }
239
+ };
240
+ }
241
+ function v(t) {
242
+ return t != null && typeof t != "string" && !Array.isArray(t) && t.type === "tableCell";
243
+ }
244
+ function R(t) {
245
+ return v(t) && t.props !== void 0 && t.content !== void 0;
246
+ }
247
+ function A(t) {
248
+ return R(t) ? t.props.colspan ?? 1 : 1;
249
+ }
250
+ function D(t) {
251
+ return R(t) ? t.props.rowspan ?? 1 : 1;
252
+ }
253
+ class O extends Error {
254
+ constructor(o) {
255
+ super(`Unreachable case: ${o}`);
256
+ }
257
+ }
258
+ function At(t, o = !0) {
259
+ const { "data-test": r, ...n } = t;
260
+ if (Object.keys(n).length > 0 && o)
261
+ throw new Error("Object must be empty " + JSON.stringify(t));
262
+ }
263
+ function Y(t, o) {
264
+ const r = t.resolve(o);
265
+ if (r.nodeAfter && r.nodeAfter.type.isInGroup("bnBlock"))
266
+ return {
267
+ posBeforeNode: r.pos,
268
+ node: r.nodeAfter
269
+ };
270
+ let n = r.depth, e = r.node(n);
271
+ for (; n > 0; ) {
272
+ if (e.type.isInGroup("bnBlock"))
273
+ return {
274
+ posBeforeNode: r.before(n),
275
+ node: e
276
+ };
277
+ n--, e = r.node(n);
278
+ }
279
+ const s = [];
280
+ t.descendants((l, a) => {
281
+ l.type.isInGroup("bnBlock") && s.push(a);
282
+ }), console.warn(`Position ${o} is not within a blockContainer node.`);
283
+ const i = t.resolve(
284
+ s.find((l) => l >= o) || s[s.length - 1]
285
+ );
286
+ return {
287
+ posBeforeNode: i.pos,
288
+ node: i.nodeAfter
289
+ };
290
+ }
291
+ function $(t, o) {
292
+ if (!t.type.isInGroup("bnBlock"))
293
+ throw new Error(
294
+ `Attempted to get bnBlock node at position but found node of different type ${t.type.name}`
295
+ );
296
+ const r = t, n = o, e = n + r.nodeSize, s = {
297
+ node: r,
298
+ beforePos: n,
299
+ afterPos: e
300
+ };
301
+ if (r.type.name === "blockContainer") {
302
+ let i, l;
303
+ if (r.forEach((a, c) => {
304
+ if (a.type.spec.group === "blockContent") {
305
+ const h = a, f = n + c + 1, p = f + a.nodeSize;
306
+ i = {
307
+ node: h,
308
+ beforePos: f,
309
+ afterPos: p
310
+ };
311
+ } else if (a.type.name === "blockGroup") {
312
+ const h = a, f = n + c + 1, p = f + a.nodeSize;
313
+ l = {
314
+ node: h,
315
+ beforePos: f,
316
+ afterPos: p
317
+ };
318
+ }
319
+ }), !i)
320
+ throw new Error(
321
+ `blockContainer node does not contain a blockContent node in its children: ${r}`
322
+ );
323
+ return {
324
+ isBlockContainer: !0,
325
+ bnBlock: s,
326
+ blockContent: i,
327
+ childContainer: l,
328
+ blockNoteType: i.node.type.name
329
+ };
330
+ } else {
331
+ if (!s.node.type.isInGroup("childContainer"))
332
+ throw new Error(
333
+ `bnBlock node is not in the childContainer group: ${s.node}`
334
+ );
335
+ return {
336
+ isBlockContainer: !1,
337
+ bnBlock: s,
338
+ childContainer: s,
339
+ blockNoteType: s.node.type.name
340
+ };
341
+ }
342
+ }
343
+ function Z(t) {
344
+ return $(t.node, t.posBeforeNode);
345
+ }
346
+ function It(t) {
347
+ if (!t.nodeAfter)
348
+ throw new Error(
349
+ `Attempted to get blockContainer node at position ${t.pos} but a node at this position does not exist`
350
+ );
351
+ return $(t.nodeAfter, t.pos);
352
+ }
353
+ function Tt(t) {
354
+ const o = Y(t.doc, t.selection.anchor);
355
+ return Z(o);
356
+ }
357
+ function Ot(t) {
358
+ const o = Y(t.doc, t.selection.anchor);
359
+ return Z(o);
360
+ }
361
+ function ht(t) {
362
+ return "doc" in t ? t.doc.type.schema : t.type.schema;
363
+ }
364
+ function G(t) {
365
+ return t.cached.blockNoteEditor;
366
+ }
367
+ function J(t) {
368
+ return G(t).schema;
369
+ }
370
+ function _(t) {
371
+ return J(t).blockSchema;
372
+ }
373
+ function H(t) {
374
+ return J(t).inlineContentSchema;
375
+ }
376
+ function N(t) {
377
+ return J(t).styleSchema;
378
+ }
379
+ function j(t) {
380
+ return G(t).blockCache;
381
+ }
382
+ function gt(t, o, r) {
383
+ var s, i;
384
+ const n = {
385
+ type: "tableContent",
386
+ columnWidths: [],
387
+ headerRows: void 0,
388
+ headerCols: void 0,
389
+ rows: []
390
+ }, e = [];
391
+ t.content.forEach((l, a, c) => {
392
+ const h = {
393
+ cells: []
394
+ };
395
+ c === 0 && l.content.forEach((f) => {
396
+ let p = f.attrs.colwidth;
397
+ p == null && (p = new Array(f.attrs.colspan ?? 1).fill(void 0)), n.columnWidths.push(...p);
398
+ }), h.cells = l.content.content.map((f, p) => (e[c] || (e[c] = []), e[c][p] = f.type.name === "tableHeader", {
399
+ type: "tableCell",
400
+ content: f.content.content.map(
401
+ (g) => F(g, o, r)
402
+ ).reduce(
403
+ (g, C) => {
404
+ if (!g.length)
405
+ return C;
406
+ const d = g[g.length - 1], w = C[0];
407
+ return w && B(d) && B(w) && JSON.stringify(d.styles) === JSON.stringify(w.styles) ? (d.text += `
408
+ ` + w.text, g.push(...C.slice(1)), g) : (g.push(...C), g);
409
+ },
410
+ []
411
+ ),
412
+ props: {
413
+ colspan: f.attrs.colspan,
414
+ rowspan: f.attrs.rowspan,
415
+ backgroundColor: f.attrs.backgroundColor,
416
+ textColor: f.attrs.textColor,
417
+ textAlignment: f.attrs.textAlignment
418
+ }
419
+ })), n.rows.push(h);
420
+ });
421
+ for (let l = 0; l < e.length; l++)
422
+ (s = e[l]) != null && s.every((a) => a) && (n.headerRows = (n.headerRows ?? 0) + 1);
423
+ for (let l = 0; l < ((i = e[0]) == null ? void 0 : i.length); l++)
424
+ e != null && e.every((a) => a[l]) && (n.headerCols = (n.headerCols ?? 0) + 1);
425
+ return n;
426
+ }
427
+ function F(t, o, r) {
428
+ const n = [];
429
+ let e;
430
+ return t.content.forEach((s) => {
431
+ if (s.type.name === "hardBreak") {
432
+ if (e)
433
+ if (B(e))
434
+ e.text += `
435
+ `;
436
+ else if (K(e))
437
+ e.content[e.content.length - 1].text += `
438
+ `;
439
+ else
440
+ throw new Error("unexpected");
441
+ else
442
+ e = {
443
+ type: "text",
444
+ text: `
445
+ `,
446
+ styles: {}
447
+ };
448
+ return;
449
+ }
450
+ if (s.type.name !== "link" && s.type.name !== "text") {
451
+ if (!o[s.type.name]) {
452
+ console.warn("unrecognized inline content type", s.type.name);
453
+ return;
454
+ }
455
+ e && (n.push(e), e = void 0), n.push(
456
+ wt(s, o, r)
457
+ );
458
+ return;
459
+ }
460
+ const i = {};
461
+ let l;
462
+ for (const a of s.marks)
463
+ if (a.type.name === "link")
464
+ l = a;
465
+ else {
466
+ const c = r[a.type.name];
467
+ if (!c) {
468
+ if (a.type.spec.blocknoteIgnore)
469
+ continue;
470
+ throw new Error(`style ${a.type.name} not found in styleSchema`);
471
+ }
472
+ if (c.propSchema === "boolean")
473
+ i[c.type] = !0;
474
+ else if (c.propSchema === "string")
475
+ i[c.type] = a.attrs.stringValue;
476
+ else
477
+ throw new O(c.propSchema);
478
+ }
479
+ e ? B(e) ? l ? (n.push(e), e = {
480
+ type: "link",
481
+ href: l.attrs.href,
482
+ content: [
483
+ {
484
+ type: "text",
485
+ text: s.textContent,
486
+ styles: i
487
+ }
488
+ ]
489
+ }) : JSON.stringify(e.styles) === JSON.stringify(i) ? e.text += s.textContent : (n.push(e), e = {
490
+ type: "text",
491
+ text: s.textContent,
492
+ styles: i
493
+ }) : K(e) && (l ? e.href === l.attrs.href ? JSON.stringify(
494
+ e.content[e.content.length - 1].styles
495
+ ) === JSON.stringify(i) ? e.content[e.content.length - 1].text += s.textContent : e.content.push({
496
+ type: "text",
497
+ text: s.textContent,
498
+ styles: i
499
+ }) : (n.push(e), e = {
500
+ type: "link",
501
+ href: l.attrs.href,
502
+ content: [
503
+ {
504
+ type: "text",
505
+ text: s.textContent,
506
+ styles: i
507
+ }
508
+ ]
509
+ }) : (n.push(e), e = {
510
+ type: "text",
511
+ text: s.textContent,
512
+ styles: i
513
+ })) : l ? e = {
514
+ type: "link",
515
+ href: l.attrs.href,
516
+ content: [
517
+ {
518
+ type: "text",
519
+ text: s.textContent,
520
+ styles: i
521
+ }
522
+ ]
523
+ } : e = {
524
+ type: "text",
525
+ text: s.textContent,
526
+ styles: i
527
+ };
528
+ }), e && n.push(e), n;
529
+ }
530
+ function wt(t, o, r) {
531
+ if (t.type.name === "text" || t.type.name === "link")
532
+ throw new Error("unexpected");
533
+ const n = {}, e = o[t.type.name];
534
+ for (const [l, a] of Object.entries(t.attrs)) {
535
+ if (!e)
536
+ throw Error("ic node is of an unrecognized type: " + t.type.name);
537
+ const c = e.propSchema;
538
+ l in c && (n[l] = a);
539
+ }
540
+ let s;
541
+ return e.content === "styled" ? s = F(
542
+ t,
543
+ o,
544
+ r
545
+ ) : s = void 0, {
546
+ type: t.type.name,
547
+ props: n,
548
+ content: s
549
+ };
550
+ }
551
+ function L(t, o, r = _(o), n = H(o), e = N(o), s = j(o)) {
552
+ var C;
553
+ if (!t.type.isInGroup("bnBlock"))
554
+ throw Error("Node should be a bnBlock, but is instead: " + t.type.name);
555
+ const i = s == null ? void 0 : s.get(t);
556
+ if (i)
557
+ return i;
558
+ const l = $(t, 0);
559
+ let a = l.bnBlock.node.attrs.id;
560
+ a === null && (a = Q.options.generateID());
561
+ const c = r[l.blockNoteType];
562
+ if (!c)
563
+ throw Error("Block is of an unrecognized type: " + l.blockNoteType);
564
+ const h = {};
565
+ for (const [d, w] of Object.entries({
566
+ ...t.attrs,
567
+ ...l.isBlockContainer ? l.blockContent.node.attrs : {}
568
+ })) {
569
+ const y = c.propSchema;
570
+ d in y && !(y[d].default === void 0 && w === void 0) && (h[d] = w);
571
+ }
572
+ const f = r[l.blockNoteType], p = [];
573
+ (C = l.childContainer) == null || C.node.forEach((d) => {
574
+ p.push(
575
+ L(
576
+ d,
577
+ o,
578
+ r,
579
+ n,
580
+ e,
581
+ s
582
+ )
583
+ );
584
+ });
585
+ let u;
586
+ if (f.content === "inline") {
587
+ if (!l.isBlockContainer)
588
+ throw new Error("impossible");
589
+ u = F(
590
+ l.blockContent.node,
591
+ n,
592
+ e
593
+ );
594
+ } else if (f.content === "table") {
595
+ if (!l.isBlockContainer)
596
+ throw new Error("impossible");
597
+ u = gt(
598
+ l.blockContent.node,
599
+ n,
600
+ e
601
+ );
602
+ } else if (f.content === "none")
603
+ u = void 0;
604
+ else
605
+ throw new O(f.content);
606
+ const g = {
607
+ id: a,
608
+ type: f.type,
609
+ props: h,
610
+ content: u,
611
+ children: p
612
+ };
613
+ return s == null || s.set(t, g), g;
614
+ }
615
+ function St(t, o = ht(t), r = _(o), n = H(o), e = N(o), s = j(o)) {
616
+ const i = [];
617
+ return t.firstChild && t.firstChild.descendants((l) => (i.push(
618
+ L(
619
+ l,
620
+ o,
621
+ r,
622
+ n,
623
+ e,
624
+ s
625
+ )
626
+ ), !1)), i;
627
+ }
628
+ function Dt(t, o, r = _(o), n = H(o), e = N(o), s = j(o)) {
629
+ function i(l, a, c) {
630
+ if (l.type.name !== "blockGroup")
631
+ throw new Error("unexpected");
632
+ const h = [];
633
+ let f, p;
634
+ return l.forEach((u, g, C) => {
635
+ if (u.type.name !== "blockContainer")
636
+ throw new Error("unexpected");
637
+ if (u.childCount === 0)
638
+ return;
639
+ if (u.childCount === 0 || u.childCount > 2)
640
+ throw new Error(
641
+ "unexpected, blockContainer.childCount: " + u.childCount
642
+ );
643
+ const d = C === 0, w = C === l.childCount - 1;
644
+ if (u.firstChild.type.name === "blockGroup") {
645
+ if (!d)
646
+ throw new Error("unexpected");
647
+ const k = i(
648
+ u.firstChild,
649
+ Math.max(0, a - 1),
650
+ w ? Math.max(0, c - 1) : 0
651
+ );
652
+ f = k.blockCutAtStart, w && (p = k.blockCutAtEnd), h.push(...k.blocks);
653
+ return;
654
+ }
655
+ const y = L(
656
+ u,
657
+ o,
658
+ r,
659
+ n,
660
+ e,
661
+ s
662
+ ), m = u.childCount > 1 ? u.child(1) : void 0;
663
+ let b = [];
664
+ if (m) {
665
+ const k = i(
666
+ m,
667
+ 0,
668
+ // TODO: can this be anything other than 0?
669
+ w ? Math.max(0, c - 1) : 0
670
+ );
671
+ b = k.blocks, w && (p = k.blockCutAtEnd);
672
+ }
673
+ w && !m && c > 1 && (p = y.id), d && a > 1 && (f = y.id), h.push({
674
+ ...y,
675
+ children: b
676
+ });
677
+ }), { blocks: h, blockCutAtStart: f, blockCutAtEnd: p };
678
+ }
679
+ if (t.content.childCount === 0)
680
+ return {
681
+ blocks: [],
682
+ blockCutAtStart: void 0,
683
+ blockCutAtEnd: void 0
684
+ };
685
+ if (t.content.childCount !== 1)
686
+ throw new Error(
687
+ "slice must be a single block, did you forget includeParents=true?"
688
+ );
689
+ return i(
690
+ t.content.firstChild,
691
+ Math.max(t.openStart - 1, 0),
692
+ Math.max(t.openEnd - 1, 0)
693
+ );
694
+ }
695
+ function x(t) {
696
+ const { height: o, width: r } = tt(t), n = new Array(o).fill(!1).map(() => new Array(r).fill(null)), e = (s, i) => {
697
+ for (let l = s; l < o; l++)
698
+ for (let a = i; a < r; a++)
699
+ if (!n[l][a])
700
+ return { row: l, col: a };
701
+ throw new Error(
702
+ "Unable to create occupancy grid for table, no more available cells"
703
+ );
704
+ };
705
+ for (let s = 0; s < t.content.rows.length; s++)
706
+ for (let i = 0; i < t.content.rows[s].cells.length; i++) {
707
+ const l = S(t.content.rows[s].cells[i]), a = D(l), c = A(l), { row: h, col: f } = e(s, i);
708
+ for (let p = h; p < h + a; p++)
709
+ for (let u = f; u < f + c; u++) {
710
+ if (n[p][u])
711
+ throw new Error(
712
+ `Unable to create occupancy grid for table, cell at ${p},${u} is already occupied`
713
+ );
714
+ n[p][u] = {
715
+ row: s,
716
+ col: i,
717
+ rowspan: a,
718
+ colspan: c,
719
+ cell: l
720
+ };
721
+ }
722
+ }
723
+ return n;
724
+ }
725
+ function I(t) {
726
+ const o = /* @__PURE__ */ new Set();
727
+ return t.map((r) => ({
728
+ cells: r.map((n) => o.has(n.row + ":" + n.col) ? !1 : (o.add(n.row + ":" + n.col), n.cell)).filter((n) => n !== !1)
729
+ }));
730
+ }
731
+ function E(t, o, r = x(o)) {
732
+ for (let n = 0; n < r.length; n++)
733
+ for (let e = 0; e < r[n].length; e++) {
734
+ const s = r[n][e];
735
+ if (s.row === t.row && s.col === t.col)
736
+ return { row: n, col: e, cell: s.cell };
737
+ }
738
+ throw new Error(
739
+ `Unable to resolve relative table cell indices for table, cell at ${t.row},${t.col} is not occupied`
740
+ );
741
+ }
742
+ function tt(t) {
743
+ const o = t.content.rows.length;
744
+ let r = 0;
745
+ return t.content.rows.forEach((n) => {
746
+ let e = 0;
747
+ n.cells.forEach((s) => {
748
+ e += A(s);
749
+ }), r = Math.max(r, e);
750
+ }), { height: o, width: r };
751
+ }
752
+ function et(t, o, r = x(o)) {
753
+ var e;
754
+ const n = (e = r[t.row]) == null ? void 0 : e[t.col];
755
+ if (n)
756
+ return {
757
+ row: n.row,
758
+ col: n.col,
759
+ cell: n.cell
760
+ };
761
+ }
762
+ function yt(t, o) {
763
+ var s;
764
+ const r = x(t);
765
+ if (o < 0 || o >= r.length)
766
+ return [];
767
+ let n = 0;
768
+ for (let i = 0; i < o; i++) {
769
+ const l = (s = r[n]) == null ? void 0 : s[0];
770
+ if (!l)
771
+ return [];
772
+ n += l.rowspan;
773
+ }
774
+ const e = new Array(r[0].length).fill(!1).map((i, l) => et(
775
+ { row: n, col: l },
776
+ t,
777
+ r
778
+ )).filter(
779
+ (i) => i !== void 0
780
+ );
781
+ return e.filter((i, l) => e.findIndex((a) => a.row === i.row && a.col === i.col) === l);
782
+ }
783
+ function Ct(t, o) {
784
+ var s;
785
+ const r = x(t);
786
+ if (o < 0 || o >= r[0].length)
787
+ return [];
788
+ let n = 0;
789
+ for (let i = 0; i < o; i++) {
790
+ const l = (s = r[0]) == null ? void 0 : s[n];
791
+ if (!l)
792
+ return [];
793
+ n += l.colspan;
794
+ }
795
+ const e = new Array(r.length).fill(!1).map((i, l) => et(
796
+ { row: l, col: n },
797
+ t,
798
+ r
799
+ )).filter(
800
+ (i) => i !== void 0
801
+ );
802
+ return e.filter((i, l) => e.findIndex((a) => a.row === i.row && a.col === i.col) === l);
803
+ }
804
+ function Mt(t, o, r, n = x(t)) {
805
+ const { col: e } = E(
806
+ {
807
+ row: 0,
808
+ col: o
809
+ },
810
+ t,
811
+ n
812
+ ), { col: s } = E(
813
+ {
814
+ row: 0,
815
+ col: r
816
+ },
817
+ t,
818
+ n
819
+ );
820
+ return n.forEach((i) => {
821
+ const [l] = i.splice(e, 1);
822
+ i.splice(s, 0, l);
823
+ }), I(n);
824
+ }
825
+ function Pt(t, o, r, n = x(t)) {
826
+ const { row: e } = E(
827
+ {
828
+ row: o,
829
+ col: 0
830
+ },
831
+ t,
832
+ n
833
+ ), { row: s } = E(
834
+ {
835
+ row: r,
836
+ col: 0
837
+ },
838
+ t,
839
+ n
840
+ ), [i] = n.splice(e, 1);
841
+ return n.splice(s, 0, i), I(n);
842
+ }
843
+ function M(t) {
844
+ return t ? v(t) ? M(t.content) : typeof t == "string" ? t.length === 0 : Array.isArray(t) ? t.every(
845
+ (o) => typeof o == "string" ? o.length === 0 : B(o) ? o.text.length === 0 : X(o) ? typeof o.content == "string" ? o.content.length === 0 : o.content.every((r) => r.text.length === 0) : !1
846
+ ) : !1 : !0;
847
+ }
848
+ function Rt(t, o, r = x(t)) {
849
+ if (o === "columns") {
850
+ let s = 0;
851
+ for (let i = r[0].length - 1; i >= 0 && r.every(
852
+ (a) => M(a[i].cell) && a[i].colspan === 1
853
+ ); i--)
854
+ s++;
855
+ for (let i = r.length - 1; i >= 0; i--) {
856
+ const l = Math.max(
857
+ r[i].length - s,
858
+ 1
859
+ );
860
+ r[i] = r[i].slice(0, l);
861
+ }
862
+ return I(r);
863
+ }
864
+ let n = 0;
865
+ for (let s = r.length - 1; s >= 0 && r[s].every(
866
+ (l) => M(l.cell) && l.rowspan === 1
867
+ ); s--)
868
+ n++;
869
+ const e = Math.min(n, r.length - 1);
870
+ return r.splice(r.length - e, e), I(r);
871
+ }
872
+ function $t(t, o, r, n = x(t)) {
873
+ const { width: e, height: s } = tt(t);
874
+ if (o === "columns")
875
+ n.forEach((i, l) => {
876
+ if (r >= 0)
877
+ for (let a = 0; a < r; a++)
878
+ i.push({
879
+ row: l,
880
+ col: Math.max(...i.map((c) => c.col)) + 1,
881
+ rowspan: 1,
882
+ colspan: 1,
883
+ cell: S("")
884
+ });
885
+ else
886
+ i.splice(e + r, -1 * r);
887
+ });
888
+ else if (r > 0)
889
+ for (let i = 0; i < r; i++) {
890
+ const l = new Array(e).fill(null).map((a, c) => ({
891
+ row: s + i,
892
+ col: c,
893
+ rowspan: 1,
894
+ colspan: 1,
895
+ cell: S("")
896
+ }));
897
+ n.push(l);
898
+ }
899
+ else r < 0 && n.splice(s + r, -1 * r);
900
+ return I(n);
901
+ }
902
+ function Jt(t, o, r) {
903
+ const n = yt(t, r);
904
+ if (!n.some((a) => D(a.cell) > 1))
905
+ return !0;
906
+ let s = r, i = r;
907
+ return n.forEach((a) => {
908
+ const c = D(a.cell);
909
+ s = Math.max(s, a.row + c - 1), i = Math.min(i, a.row);
910
+ }), o < r ? r === s : r === i;
911
+ }
912
+ function _t(t, o, r) {
913
+ const n = Ct(t, r);
914
+ if (!n.some((a) => A(a.cell) > 1))
915
+ return !0;
916
+ let s = r, i = r;
917
+ return n.forEach((a) => {
918
+ const c = A(a.cell);
919
+ s = Math.max(s, a.col + c - 1), i = Math.min(i, a.col);
920
+ }), o < r ? r === s : r === i;
921
+ }
922
+ function Ht(t, o, r) {
923
+ const n = E(t, r), e = E(o, r);
924
+ return n.col === e.col;
925
+ }
926
+ function V(t, o, r, n) {
927
+ const e = [];
928
+ for (const [i, l] of Object.entries(t.styles || {})) {
929
+ const a = r[i];
930
+ if (!a)
931
+ throw new Error(`style ${i} not found in styleSchema`);
932
+ if (a.propSchema === "boolean")
933
+ l && e.push(o.mark(i));
934
+ else if (a.propSchema === "string")
935
+ l && e.push(o.mark(i, { stringValue: l }));
936
+ else
937
+ throw new O(a.propSchema);
938
+ }
939
+ return !n || !o.nodes[n].spec.code ? t.text.split(/(\n)/g).filter((i) => i.length > 0).map((i) => i === `
940
+ ` ? o.nodes.hardBreak.createChecked() : o.text(i, e)) : t.text.length > 0 ? [o.text(t.text, e)] : [];
941
+ }
942
+ function mt(t, o, r) {
943
+ const n = o.marks.link.create({
944
+ href: t.href
945
+ });
946
+ return P(t.content, o, r).map(
947
+ (e) => {
948
+ if (e.type.name === "text")
949
+ return e.mark([...e.marks, n]);
950
+ if (e.type.name === "hardBreak")
951
+ return e;
952
+ throw new Error("unexpected node type");
953
+ }
954
+ );
955
+ }
956
+ function P(t, o, r, n) {
957
+ const e = [];
958
+ if (typeof t == "string")
959
+ return e.push(
960
+ ...V(
961
+ { text: t, styles: {} },
962
+ o,
963
+ r,
964
+ n
965
+ )
966
+ ), e;
967
+ for (const s of t)
968
+ e.push(
969
+ ...V(s, o, r, n)
970
+ );
971
+ return e;
972
+ }
973
+ function T(t, o, r, n = N(o)) {
974
+ const e = [];
975
+ for (const s of t)
976
+ typeof s == "string" ? e.push(
977
+ ...P(s, o, n, r)
978
+ ) : X(s) ? e.push(...mt(s, o, n)) : B(s) ? e.push(
979
+ ...P([s], o, n, r)
980
+ ) : e.push(
981
+ nt(s, o, n)
982
+ );
983
+ return e;
984
+ }
985
+ function kt(t, o, r = N(o)) {
986
+ const n = [], e = new Array(t.headerRows ?? 0).fill(!0), s = new Array(t.headerCols ?? 0).fill(!0), i = t.columnWidths ?? [];
987
+ for (let l = 0; l < t.rows.length; l++) {
988
+ const a = t.rows[l], c = [], h = e[l];
989
+ for (let p = 0; p < a.cells.length; p++) {
990
+ const u = a.cells[p], g = s[p], C = void 0;
991
+ let d = null;
992
+ const w = E(
993
+ {
994
+ row: l,
995
+ col: p
996
+ },
997
+ { content: t }
998
+ );
999
+ let y = i[w.col] ? [i[w.col]] : null;
1000
+ if (u) if (typeof u == "string")
1001
+ d = o.text(u);
1002
+ else if (v(u)) {
1003
+ u.content && (d = T(
1004
+ u.content,
1005
+ o,
1006
+ "tableParagraph",
1007
+ r
1008
+ ));
1009
+ const b = A(u);
1010
+ b > 1 && (y = new Array(b).fill(!1).map((k, W) => i[w.col + W] ?? void 0));
1011
+ } else
1012
+ d = T(
1013
+ u,
1014
+ o,
1015
+ "tableParagraph",
1016
+ r
1017
+ );
1018
+ const m = o.nodes[g || h ? "tableHeader" : "tableCell"].createChecked(
1019
+ {
1020
+ ...v(u) ? u.props : {},
1021
+ colwidth: y
1022
+ },
1023
+ o.nodes.tableParagraph.createChecked(C, d)
1024
+ );
1025
+ c.push(m);
1026
+ }
1027
+ const f = o.nodes.tableRow.createChecked({}, c);
1028
+ n.push(f);
1029
+ }
1030
+ return n;
1031
+ }
1032
+ function nt(t, o, r) {
1033
+ let n, e = t.type;
1034
+ if (e === void 0 && (e = "paragraph"), !o.nodes[e])
1035
+ throw new Error(`node type ${e} not found in schema`);
1036
+ if (!t.content)
1037
+ n = o.nodes[e].createChecked(t.props);
1038
+ else if (typeof t.content == "string") {
1039
+ const s = T(
1040
+ [t.content],
1041
+ o,
1042
+ e,
1043
+ r
1044
+ );
1045
+ n = o.nodes[e].createChecked(t.props, s);
1046
+ } else if (Array.isArray(t.content)) {
1047
+ const s = T(
1048
+ t.content,
1049
+ o,
1050
+ e,
1051
+ r
1052
+ );
1053
+ n = o.nodes[e].createChecked(t.props, s);
1054
+ } else if (t.content.type === "tableContent") {
1055
+ const s = kt(t.content, o, r);
1056
+ n = o.nodes[e].createChecked(t.props, s);
1057
+ } else
1058
+ throw new O(t.content.type);
1059
+ return n;
1060
+ }
1061
+ function bt(t, o, r = N(o)) {
1062
+ let n = t.id;
1063
+ n === void 0 && (n = Q.options.generateID());
1064
+ const e = [];
1065
+ if (t.children)
1066
+ for (const i of t.children)
1067
+ e.push(bt(i, o, r));
1068
+ if (!t.type || // can happen if block.type is not defined (this should create the default node)
1069
+ o.nodes[t.type].isInGroup("blockContent")) {
1070
+ const i = nt(
1071
+ t,
1072
+ o,
1073
+ r
1074
+ ), l = e.length > 0 ? o.nodes.blockGroup.createChecked({}, e) : void 0;
1075
+ return o.nodes.blockContainer.createChecked(
1076
+ {
1077
+ id: n,
1078
+ ...t.props
1079
+ },
1080
+ l ? [i, l] : i
1081
+ );
1082
+ } else {
1083
+ if (o.nodes[t.type].isInGroup("bnBlock"))
1084
+ return o.nodes[t.type].createChecked(
1085
+ {
1086
+ id: n,
1087
+ ...t.props
1088
+ },
1089
+ e
1090
+ );
1091
+ throw new Error(
1092
+ `block type ${t.type} doesn't match blockContent or bnBlock group`
1093
+ );
1094
+ }
1095
+ }
1096
+ export {
1097
+ Dt as A,
1098
+ J as B,
1099
+ At as C,
1100
+ $ as D,
1101
+ _ as E,
1102
+ H as F,
1103
+ N as G,
1104
+ j as H,
1105
+ K as I,
1106
+ X as J,
1107
+ S as K,
1108
+ v as L,
1109
+ R as M,
1110
+ A as N,
1111
+ D as O,
1112
+ O as U,
1113
+ ht as a,
1114
+ bt as b,
1115
+ Y as c,
1116
+ St as d,
1117
+ Z as e,
1118
+ Ot as f,
1119
+ It as g,
1120
+ Tt as h,
1121
+ T as i,
1122
+ B as j,
1123
+ wt as k,
1124
+ gt as l,
1125
+ F as m,
1126
+ L as n,
1127
+ Jt as o,
1128
+ Pt as p,
1129
+ _t as q,
1130
+ Mt as r,
1131
+ tt as s,
1132
+ kt as t,
1133
+ yt as u,
1134
+ Ct as v,
1135
+ Ht as w,
1136
+ Rt as x,
1137
+ $t as y,
1138
+ Q as z
1139
+ };
1140
+ //# sourceMappingURL=blockToNode-DIfPWLH8.js.map