@blocknote/core 0.41.1 → 0.42.1

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
@@ -1,4375 +0,0 @@
1
- var mt = Object.defineProperty;
2
- var gt = (e, t, n) => t in e ? mt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var x = (e, t, n) => gt(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { TableMap as We, goToNextCell as Se, columnResizing as bt, tableEditing as kt, CellSelection as Fe, TableView as Ct } from "prosemirror-tables";
5
- import yt from "@tiptap/extension-bold";
6
- import wt from "@tiptap/extension-code";
7
- import vt from "@tiptap/extension-italic";
8
- import Et from "@tiptap/extension-strike";
9
- import xt from "@tiptap/extension-underline";
10
- import { Extension as $e, combineTransactionSteps as St, getChangedRanges as Bt, findChildrenInRange as Mt, Node as D, Mark as Lt, callOrReturn as Tt, getExtensionField as At, mergeAttributes as ue } from "@tiptap/core";
11
- import { Slice as de, Fragment as _, DOMParser as Q, DOMSerializer as Be } from "prosemirror-model";
12
- import { Plugin as je, PluginKey as Ue, TextSelection as ze } from "prosemirror-state";
13
- import { v4 as Nt } from "uuid";
14
- import { createHighlightPlugin as It } from "prosemirror-highlight";
15
- import { createParser as Pt } from "prosemirror-highlight/shiki";
16
- import { ReplaceStep as Ht } from "prosemirror-transform";
17
- import { DecorationSet as Me, Decoration as Ot } from "prosemirror-view";
18
- function Dt(e, t = JSON.stringify) {
19
- const n = {};
20
- return e.filter((o) => {
21
- const r = t(o);
22
- return Object.prototype.hasOwnProperty.call(n, r) ? !1 : n[r] = !0;
23
- });
24
- }
25
- function _t(e) {
26
- const t = e.filter(
27
- (o, r) => e.indexOf(o) !== r
28
- );
29
- return Dt(t);
30
- }
31
- const qe = $e.create({
32
- name: "uniqueID",
33
- // we’ll set a very high priority to make sure this runs first
34
- // and is compatible with `appendTransaction` hooks of other extensions
35
- priority: 1e4,
36
- addOptions() {
37
- return {
38
- attributeName: "id",
39
- types: [],
40
- setIdAttribute: !1,
41
- generateID: () => {
42
- if (typeof window < "u" && window.__TEST_OPTIONS) {
43
- const e = window.__TEST_OPTIONS;
44
- return e.mockID === void 0 ? e.mockID = 0 : e.mockID++, e.mockID.toString();
45
- }
46
- return Nt();
47
- },
48
- filterTransaction: null
49
- };
50
- },
51
- addGlobalAttributes() {
52
- return [
53
- {
54
- types: this.options.types,
55
- attributes: {
56
- [this.options.attributeName]: {
57
- default: null,
58
- parseHTML: (e) => e.getAttribute(`data-${this.options.attributeName}`),
59
- renderHTML: (e) => {
60
- const t = {
61
- [`data-${this.options.attributeName}`]: e[this.options.attributeName]
62
- };
63
- return this.options.setIdAttribute ? {
64
- ...t,
65
- id: e[this.options.attributeName]
66
- } : t;
67
- }
68
- }
69
- }
70
- }
71
- ];
72
- },
73
- // check initial content for missing ids
74
- // onCreate() {
75
- // // Don’t do this when the collaboration extension is active
76
- // // because this may update the content, so Y.js tries to merge these changes.
77
- // // This leads to empty block nodes.
78
- // // See: https://github.com/ueberdosis/tiptap/issues/2400
79
- // if (
80
- // this.editor.extensionManager.extensions.find(
81
- // (extension) => extension.name === "collaboration"
82
- // )
83
- // ) {
84
- // return;
85
- // }
86
- // const { view, state } = this.editor;
87
- // const { tr, doc } = state;
88
- // const { types, attributeName, generateID } = this.options;
89
- // const nodesWithoutId = findChildren(doc, (node) => {
90
- // return (
91
- // types.includes(node.type.name) && node.attrs[attributeName] === null
92
- // );
93
- // });
94
- // nodesWithoutId.forEach(({ node, pos }) => {
95
- // tr.setNodeMarkup(pos, undefined, {
96
- // ...node.attrs,
97
- // [attributeName]: generateID(),
98
- // });
99
- // });
100
- // tr.setMeta("addToHistory", false);
101
- // view.dispatch(tr);
102
- // },
103
- addProseMirrorPlugins() {
104
- let e = null, t = !1;
105
- return [
106
- new je({
107
- key: new Ue("uniqueID"),
108
- appendTransaction: (n, o, r) => {
109
- const s = n.some((h) => h.docChanged) && !o.doc.eq(r.doc), a = this.options.filterTransaction && n.some((h) => {
110
- var k, m;
111
- return !((m = (k = this.options).filterTransaction) != null && m.call(k, h));
112
- });
113
- if (!s || a)
114
- return;
115
- const { tr: i } = r, { types: c, attributeName: l, generateID: d } = this.options, u = St(
116
- o.doc,
117
- n
118
- ), { mapping: p } = u;
119
- if (Bt(u).forEach(({ newRange: h }) => {
120
- const k = Mt(
121
- r.doc,
122
- h,
123
- (y) => c.includes(y.type.name)
124
- ), m = k.map(({ node: y }) => y.attrs[l]).filter((y) => y !== null), b = _t(m);
125
- k.forEach(({ node: y, pos: g }) => {
126
- var V;
127
- const v = (V = i.doc.nodeAt(g)) == null ? void 0 : V.attrs[l];
128
- if (v === null) {
129
- const W = o.doc.type.createAndFill().content;
130
- if (o.doc.content.findDiffStart(W) === null) {
131
- const xe = JSON.parse(
132
- JSON.stringify(r.doc.toJSON())
133
- );
134
- if (xe.content[0].content[0].attrs.id = "initialBlockId", JSON.stringify(xe.content) === JSON.stringify(W.toJSON())) {
135
- i.setNodeMarkup(g, void 0, {
136
- ...y.attrs,
137
- [l]: "initialBlockId"
138
- });
139
- return;
140
- }
141
- }
142
- i.setNodeMarkup(g, void 0, {
143
- ...y.attrs,
144
- [l]: d()
145
- });
146
- return;
147
- }
148
- const { deleted: S } = p.invert().mapResult(g);
149
- S && b.includes(v) && i.setNodeMarkup(g, void 0, {
150
- ...y.attrs,
151
- [l]: d()
152
- });
153
- });
154
- }), !!i.steps.length)
155
- return i.setMeta("uniqueID", !0), i;
156
- },
157
- // we register a global drag handler to track the current drag source element
158
- view(n) {
159
- const o = (r) => {
160
- let s;
161
- e = !((s = n.dom.parentElement) === null || s === void 0) && s.contains(r.target) ? n.dom.parentElement : null;
162
- };
163
- return window.addEventListener("dragstart", o), {
164
- destroy() {
165
- window.removeEventListener("dragstart", o);
166
- }
167
- };
168
- },
169
- props: {
170
- // `handleDOMEvents` is called before `transformPasted` so we can do
171
- // some checks before. However, `transformPasted` only runs when
172
- // editor content is pasted - not external content.
173
- handleDOMEvents: {
174
- // only create new ids for dropped content while holding `alt`
175
- // or content is dragged from another editor
176
- drop: (n, o) => {
177
- let r;
178
- return e !== n.dom.parentElement || ((r = o.dataTransfer) === null || r === void 0 ? void 0 : r.effectAllowed) === "copy" ? t = !0 : t = !1, e = null, !1;
179
- },
180
- // always create new ids on pasted content
181
- paste: () => (t = !0, !1)
182
- },
183
- // we’ll remove ids for every pasted node
184
- // so we can create a new one within `appendTransaction`
185
- transformPasted: (n) => {
186
- if (!t)
187
- return n;
188
- const { types: o, attributeName: r } = this.options, s = (a) => {
189
- const i = [];
190
- return a.forEach((c) => {
191
- if (c.isText) {
192
- i.push(c);
193
- return;
194
- }
195
- if (!o.includes(c.type.name)) {
196
- i.push(c.copy(s(c.content)));
197
- return;
198
- }
199
- const l = c.type.create(
200
- {
201
- ...c.attrs,
202
- [r]: null
203
- },
204
- s(c.content),
205
- c.marks
206
- );
207
- i.push(l);
208
- }), _.from(i);
209
- };
210
- return t = !1, new de(
211
- s(n.content),
212
- n.openStart,
213
- n.openEnd
214
- );
215
- }
216
- }
217
- })
218
- ];
219
- }
220
- });
221
- function Le(e) {
222
- return e.type === "link";
223
- }
224
- function Ze(e) {
225
- return typeof e != "string" && e.type === "link";
226
- }
227
- function I(e) {
228
- return typeof e != "string" && e.type === "text";
229
- }
230
- function se(e) {
231
- var t, n, o, r, s;
232
- return pe(e) ? { ...e } : $(e) ? {
233
- type: "tableCell",
234
- content: [].concat(e.content),
235
- props: {
236
- backgroundColor: ((t = e.props) == null ? void 0 : t.backgroundColor) ?? "default",
237
- textColor: ((n = e.props) == null ? void 0 : n.textColor) ?? "default",
238
- textAlignment: ((o = e.props) == null ? void 0 : o.textAlignment) ?? "left",
239
- colspan: ((r = e.props) == null ? void 0 : r.colspan) ?? 1,
240
- rowspan: ((s = e.props) == null ? void 0 : s.rowspan) ?? 1
241
- }
242
- } : {
243
- type: "tableCell",
244
- content: [].concat(e),
245
- props: {
246
- backgroundColor: "default",
247
- textColor: "default",
248
- textAlignment: "left",
249
- colspan: 1,
250
- rowspan: 1
251
- }
252
- };
253
- }
254
- function $(e) {
255
- return e != null && typeof e != "string" && !Array.isArray(e) && e.type === "tableCell";
256
- }
257
- function pe(e) {
258
- return $(e) && e.props !== void 0 && e.content !== void 0;
259
- }
260
- function j(e) {
261
- return pe(e) ? e.props.colspan ?? 1 : 1;
262
- }
263
- function ae(e) {
264
- return pe(e) ? e.props.rowspan ?? 1 : 1;
265
- }
266
- class Z extends Error {
267
- constructor(t) {
268
- super(`Unreachable case: ${t}`);
269
- }
270
- }
271
- function Vo(e, t = !0) {
272
- const { "data-test": n, ...o } = e;
273
- if (Object.keys(o).length > 0 && t)
274
- throw new Error("Object must be empty " + JSON.stringify(e));
275
- }
276
- const Rt = () => typeof navigator < "u" && (/Mac/.test(navigator.platform) || /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent));
277
- function T(e, t = "Ctrl") {
278
- return Rt() ? e.replace("Mod", "⌘") : e.replace("Mod", t);
279
- }
280
- function U(...e) {
281
- return [
282
- // Converts to & from set to remove duplicates.
283
- ...new Set(
284
- e.filter((t) => t).join(" ").split(" ")
285
- )
286
- ].join(" ");
287
- }
288
- const Wo = () => /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
289
- function Vt(e, t, n, o) {
290
- const r = document.createElement("div");
291
- r.className = U(
292
- "bn-block-content",
293
- n.class
294
- ), r.setAttribute("data-content-type", e);
295
- for (const [a, i] of Object.entries(n))
296
- a !== "class" && r.setAttribute(a, i);
297
- const s = document.createElement(t);
298
- s.className = U(
299
- "bn-inline-content",
300
- o.class
301
- );
302
- for (const [a, i] of Object.entries(
303
- o
304
- ))
305
- a !== "class" && s.setAttribute(a, i);
306
- return r.appendChild(s), {
307
- dom: r,
308
- contentDOM: s
309
- };
310
- }
311
- const Te = (e, t) => {
312
- let n = Y(e, t.pmSchema);
313
- n.type.name === "blockContainer" && (n = n.firstChild);
314
- const o = t.pmSchema.nodes[n.type.name].spec.toDOM;
315
- if (o === void 0)
316
- throw new Error(
317
- "This block has no default HTML serialization as its corresponding TipTap node doesn't implement `renderHTML`."
318
- );
319
- const r = o(n);
320
- if (typeof r != "object" || !("dom" in r))
321
- throw new Error(
322
- "Cannot use this block's default HTML serialization as its corresponding TipTap node's `renderHTML` function does not return an object with the `dom` property."
323
- );
324
- return r;
325
- };
326
- function Wt(e, t = "<br>") {
327
- const n = e.querySelectorAll("p");
328
- if (n.length > 1) {
329
- const o = n[0];
330
- for (let r = 1; r < n.length; r++) {
331
- const s = n[r];
332
- o.innerHTML += t + s.innerHTML, s.remove();
333
- }
334
- }
335
- }
336
- function K(e) {
337
- return "data-" + e.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
338
- }
339
- function Fo(e) {
340
- const t = e.split("/");
341
- return !t.length || // invalid?
342
- t[t.length - 1] === "" ? e : t[t.length - 1];
343
- }
344
- function $o(e) {
345
- var n;
346
- const t = [
347
- "mp4",
348
- "webm",
349
- "ogg",
350
- "mov",
351
- "mkv",
352
- "flv",
353
- "avi",
354
- "wmv",
355
- "m4v"
356
- ];
357
- try {
358
- const r = ((n = new URL(e).pathname.split(".").pop()) == null ? void 0 : n.toLowerCase()) || "";
359
- return t.includes(r);
360
- } catch {
361
- return !1;
362
- }
363
- }
364
- function Ft(e) {
365
- const t = {};
366
- return Object.entries(e).forEach(([n, o]) => {
367
- t[n] = {
368
- default: o.default,
369
- keepOnSplit: !0,
370
- // Props are displayed in kebab-case as HTML attributes. If a prop's
371
- // value is the same as its default, we don't display an HTML
372
- // attribute for it.
373
- parseHTML: (r) => {
374
- const s = r.getAttribute(K(n));
375
- if (s === null)
376
- return null;
377
- if (o.default === void 0 && o.type === "boolean" || o.default !== void 0 && typeof o.default == "boolean")
378
- return s === "true" ? !0 : s === "false" ? !1 : null;
379
- if (o.default === void 0 && o.type === "number" || o.default !== void 0 && typeof o.default == "number") {
380
- const a = parseFloat(s);
381
- return !Number.isNaN(a) && Number.isFinite(a) ? a : null;
382
- }
383
- return s;
384
- },
385
- renderHTML: (r) => r[n] !== o.default ? {
386
- [K(n)]: r[n]
387
- } : {}
388
- };
389
- }), t;
390
- }
391
- function $t(e, t, n, o) {
392
- const r = e();
393
- if (r === void 0)
394
- throw new Error("Cannot find node position");
395
- const a = n.state.doc.resolve(r).node().attrs.id;
396
- if (!a)
397
- throw new Error("Block doesn't have id");
398
- const i = t.getBlock(a);
399
- if (i.type !== o)
400
- throw new Error("Block type does not match");
401
- return i;
402
- }
403
- function ie(e, t, n, o, r = !1, s) {
404
- const a = document.createElement("div");
405
- if (s !== void 0)
406
- for (const [i, c] of Object.entries(s))
407
- i !== "class" && a.setAttribute(i, c);
408
- a.className = U(
409
- "bn-block-content",
410
- (s == null ? void 0 : s.class) || ""
411
- ), a.setAttribute("data-content-type", t);
412
- for (const [i, c] of Object.entries(n)) {
413
- const d = o[i].default;
414
- c !== d && a.setAttribute(K(i), c);
415
- }
416
- return r && a.setAttribute("data-file-block", ""), a.appendChild(e.dom), e.contentDOM && (e.contentDOM.className = U(
417
- "bn-inline-content",
418
- e.contentDOM.className
419
- )), {
420
- ...e,
421
- dom: a
422
- };
423
- }
424
- function jt(e, t, n) {
425
- return {
426
- config: {
427
- type: e.type,
428
- content: e.content,
429
- propSchema: t
430
- },
431
- implementation: {
432
- node: e.node,
433
- render: Te,
434
- toExternalHTML: Te
435
- },
436
- extensions: n
437
- };
438
- }
439
- function Ut(e, t) {
440
- e.stopEvent = (n) => (n.type === "mousedown" && setTimeout(() => {
441
- t.view.dom.blur();
442
- }, 10), !0);
443
- }
444
- function zt(e, t) {
445
- const n = [
446
- {
447
- tag: "[data-content-type=" + e.type + "]",
448
- contentElement: ".bn-inline-content"
449
- }
450
- ];
451
- return t.parse && n.push({
452
- tag: "*",
453
- getAttrs(o) {
454
- var s;
455
- if (typeof o == "string")
456
- return !1;
457
- const r = (s = t.parse) == null ? void 0 : s.call(t, o);
458
- return r === void 0 ? !1 : r;
459
- },
460
- getContent: e.content === "inline" || e.content === "none" ? (o, r) => {
461
- var s;
462
- if (t.parseContent)
463
- return t.parseContent({
464
- el: o,
465
- schema: r
466
- });
467
- if (e.content === "inline") {
468
- const i = o.cloneNode(!0);
469
- return Wt(
470
- i,
471
- (s = t.meta) != null && s.code ? `
472
- ` : "<br>"
473
- ), Q.fromSchema(r).parse(i, {
474
- topNode: r.nodes.paragraph.create()
475
- }).content;
476
- }
477
- return _.empty;
478
- } : void 0
479
- }), n;
480
- }
481
- function qt(e, t, n, o) {
482
- var s, a, i, c;
483
- const r = t.node || D.create({
484
- name: e.type,
485
- content: e.content === "inline" ? "inline*" : e.content === "none" ? "" : e.content,
486
- group: "blockContent",
487
- selectable: ((s = t.meta) == null ? void 0 : s.selectable) ?? !0,
488
- isolating: ((a = t.meta) == null ? void 0 : a.isolating) ?? !0,
489
- code: ((i = t.meta) == null ? void 0 : i.code) ?? !1,
490
- defining: ((c = t.meta) == null ? void 0 : c.defining) ?? !0,
491
- priority: o,
492
- addAttributes() {
493
- return Ft(e.propSchema);
494
- },
495
- parseHTML() {
496
- return zt(e, t);
497
- },
498
- renderHTML({ HTMLAttributes: l }) {
499
- var u;
500
- const d = document.createElement("div");
501
- return ie(
502
- {
503
- dom: d,
504
- contentDOM: e.content === "inline" ? d : void 0
505
- },
506
- e.type,
507
- {},
508
- e.propSchema,
509
- ((u = t.meta) == null ? void 0 : u.fileBlockAccept) !== void 0,
510
- l
511
- );
512
- },
513
- addNodeView() {
514
- return (l) => {
515
- var h, k;
516
- const d = this.options.editor, u = $t(
517
- l.getPos,
518
- d,
519
- this.editor,
520
- e.type
521
- ), p = ((h = this.options.domAttributes) == null ? void 0 : h.blockContent) || {}, f = t.render.call(
522
- { blockContentDOMAttributes: p, props: l, renderType: "nodeView" },
523
- u,
524
- d
525
- );
526
- return ((k = t.meta) == null ? void 0 : k.selectable) === !1 && Ut(f, this.editor), f;
527
- };
528
- }
529
- });
530
- if (r.name !== e.type)
531
- throw new Error(
532
- "Node name does not match block type. This is a bug in BlockNote."
533
- );
534
- return {
535
- config: e,
536
- implementation: {
537
- ...t,
538
- node: r,
539
- render(l, d) {
540
- var p;
541
- const u = ((p = r.options.domAttributes) == null ? void 0 : p.blockContent) || {};
542
- return t.render.call(
543
- {
544
- blockContentDOMAttributes: u,
545
- props: void 0,
546
- renderType: "dom"
547
- },
548
- l,
549
- d
550
- );
551
- },
552
- // TODO: this should not have wrapInBlockStructure and generally be a lot simpler
553
- // post-processing in externalHTMLExporter should not be necessary
554
- toExternalHTML: (l, d) => {
555
- var p, f;
556
- const u = ((p = r.options.domAttributes) == null ? void 0 : p.blockContent) || {};
557
- return ((f = t.toExternalHTML) == null ? void 0 : f.call(
558
- { blockContentDOMAttributes: u },
559
- l,
560
- d
561
- )) ?? t.render.call(
562
- { blockContentDOMAttributes: u, renderType: "dom", props: void 0 },
563
- l,
564
- d
565
- );
566
- }
567
- },
568
- extensions: n
569
- };
570
- }
571
- function jo(e) {
572
- return e;
573
- }
574
- function M(e, t, n) {
575
- return (o = {}) => {
576
- const r = typeof e == "function" ? e(o) : e, s = typeof t == "function" ? t(o) : t, a = n ? typeof n == "function" ? n(o) : n : void 0;
577
- return {
578
- config: r,
579
- implementation: {
580
- ...s,
581
- // TODO: this should not have wrapInBlockStructure and generally be a lot simpler
582
- // post-processing in externalHTMLExporter should not be necessary
583
- toExternalHTML(i, c) {
584
- var d, u;
585
- const l = (d = s.toExternalHTML) == null ? void 0 : d.call(
586
- { blockContentDOMAttributes: this.blockContentDOMAttributes },
587
- i,
588
- c
589
- );
590
- if (l !== void 0)
591
- return ie(
592
- l,
593
- i.type,
594
- i.props,
595
- r.propSchema,
596
- ((u = s.meta) == null ? void 0 : u.fileBlockAccept) !== void 0
597
- );
598
- },
599
- render(i, c) {
600
- var u;
601
- const l = s.render.call(
602
- {
603
- blockContentDOMAttributes: this.blockContentDOMAttributes,
604
- renderType: this.renderType,
605
- props: this.props
606
- },
607
- i,
608
- c
609
- );
610
- return ie(
611
- l,
612
- i.type,
613
- i.props,
614
- r.propSchema,
615
- ((u = s.meta) == null ? void 0 : u.fileBlockAccept) !== void 0,
616
- this.blockContentDOMAttributes
617
- );
618
- }
619
- },
620
- extensions: a
621
- };
622
- };
623
- }
624
- function fe(e, t) {
625
- const n = e.resolve(t);
626
- if (n.nodeAfter && n.nodeAfter.type.isInGroup("bnBlock"))
627
- return {
628
- posBeforeNode: n.pos,
629
- node: n.nodeAfter
630
- };
631
- let o = n.depth, r = n.node(o);
632
- for (; o > 0; ) {
633
- if (r.type.isInGroup("bnBlock"))
634
- return {
635
- posBeforeNode: n.before(o),
636
- node: r
637
- };
638
- o--, r = n.node(o);
639
- }
640
- const s = [];
641
- e.descendants((i, c) => {
642
- i.type.isInGroup("bnBlock") && s.push(c);
643
- }), console.warn(`Position ${t} is not within a blockContainer node.`);
644
- const a = e.resolve(
645
- s.find((i) => i >= t) || s[s.length - 1]
646
- );
647
- return {
648
- posBeforeNode: a.pos,
649
- node: a.nodeAfter
650
- };
651
- }
652
- function he(e, t) {
653
- if (!e.type.isInGroup("bnBlock"))
654
- throw new Error(
655
- `Attempted to get bnBlock node at position but found node of different type ${e.type.name}`
656
- );
657
- const n = e, o = t, r = o + n.nodeSize, s = {
658
- node: n,
659
- beforePos: o,
660
- afterPos: r
661
- };
662
- if (n.type.name === "blockContainer") {
663
- let a, i;
664
- if (n.forEach((c, l) => {
665
- if (c.type.spec.group === "blockContent") {
666
- const d = c, u = o + l + 1, p = u + c.nodeSize;
667
- a = {
668
- node: d,
669
- beforePos: u,
670
- afterPos: p
671
- };
672
- } else if (c.type.name === "blockGroup") {
673
- const d = c, u = o + l + 1, p = u + c.nodeSize;
674
- i = {
675
- node: d,
676
- beforePos: u,
677
- afterPos: p
678
- };
679
- }
680
- }), !a)
681
- throw new Error(
682
- `blockContainer node does not contain a blockContent node in its children: ${n}`
683
- );
684
- return {
685
- isBlockContainer: !0,
686
- bnBlock: s,
687
- blockContent: a,
688
- childContainer: i,
689
- blockNoteType: a.node.type.name
690
- };
691
- } else {
692
- if (!s.node.type.isInGroup("childContainer"))
693
- throw new Error(
694
- `bnBlock node is not in the childContainer group: ${s.node}`
695
- );
696
- return {
697
- isBlockContainer: !1,
698
- bnBlock: s,
699
- childContainer: s,
700
- blockNoteType: s.node.type.name
701
- };
702
- }
703
- }
704
- function z(e) {
705
- return he(e.node, e.posBeforeNode);
706
- }
707
- function Zt(e) {
708
- if (!e.nodeAfter)
709
- throw new Error(
710
- `Attempted to get blockContainer node at position ${e.pos} but a node at this position does not exist`
711
- );
712
- return he(e.nodeAfter, e.pos);
713
- }
714
- function Ge(e) {
715
- const t = fe(e.doc, e.selection.anchor);
716
- return z(t);
717
- }
718
- function Gt(e) {
719
- const t = fe(e.doc, e.selection.anchor);
720
- return z(t);
721
- }
722
- function G(e) {
723
- return "doc" in e ? e.doc.type.schema : e.type.schema;
724
- }
725
- function Xe(e) {
726
- return e.cached.blockNoteEditor;
727
- }
728
- function me(e) {
729
- return Xe(e).schema;
730
- }
731
- function ge(e) {
732
- return me(e).blockSchema;
733
- }
734
- function be(e) {
735
- return me(e).inlineContentSchema;
736
- }
737
- function R(e) {
738
- return me(e).styleSchema;
739
- }
740
- function ke(e) {
741
- return Xe(e).blockCache;
742
- }
743
- function Xt(e, t, n) {
744
- var s, a;
745
- const o = {
746
- type: "tableContent",
747
- columnWidths: [],
748
- headerRows: void 0,
749
- headerCols: void 0,
750
- rows: []
751
- }, r = [];
752
- e.content.forEach((i, c, l) => {
753
- const d = {
754
- cells: []
755
- };
756
- l === 0 && i.content.forEach((u) => {
757
- let p = u.attrs.colwidth;
758
- p == null && (p = new Array(u.attrs.colspan ?? 1).fill(void 0)), o.columnWidths.push(...p);
759
- }), d.cells = i.content.content.map((u, p) => (r[l] || (r[l] = []), r[l][p] = u.type.name === "tableHeader", {
760
- type: "tableCell",
761
- content: u.content.content.map(
762
- (h) => Ce(h, t, n)
763
- ).reduce(
764
- (h, k) => {
765
- if (!h.length)
766
- return k;
767
- const m = h[h.length - 1], b = k[0];
768
- return b && I(m) && I(b) && JSON.stringify(m.styles) === JSON.stringify(b.styles) ? (m.text += `
769
- ` + b.text, h.push(...k.slice(1)), h) : (h.push(...k), h);
770
- },
771
- []
772
- ),
773
- props: {
774
- colspan: u.attrs.colspan,
775
- rowspan: u.attrs.rowspan,
776
- backgroundColor: u.attrs.backgroundColor,
777
- textColor: u.attrs.textColor,
778
- textAlignment: u.attrs.textAlignment
779
- }
780
- })), o.rows.push(d);
781
- });
782
- for (let i = 0; i < r.length; i++)
783
- (s = r[i]) != null && s.every((c) => c) && (o.headerRows = (o.headerRows ?? 0) + 1);
784
- for (let i = 0; i < ((a = r[0]) == null ? void 0 : a.length); i++)
785
- r != null && r.every((c) => c[i]) && (o.headerCols = (o.headerCols ?? 0) + 1);
786
- return o;
787
- }
788
- function Ce(e, t, n) {
789
- const o = [];
790
- let r;
791
- return e.content.forEach((s) => {
792
- if (s.type.name === "hardBreak") {
793
- if (r)
794
- if (I(r))
795
- r.text += `
796
- `;
797
- else if (Le(r))
798
- r.content[r.content.length - 1].text += `
799
- `;
800
- else
801
- throw new Error("unexpected");
802
- else
803
- r = {
804
- type: "text",
805
- text: `
806
- `,
807
- styles: {}
808
- };
809
- return;
810
- }
811
- if (s.type.name !== "link" && s.type.name !== "text") {
812
- if (!t[s.type.name]) {
813
- console.warn("unrecognized inline content type", s.type.name);
814
- return;
815
- }
816
- r && (o.push(r), r = void 0), o.push(
817
- Jt(s, t, n)
818
- );
819
- return;
820
- }
821
- const a = {};
822
- let i;
823
- for (const c of s.marks)
824
- if (c.type.name === "link")
825
- i = c;
826
- else {
827
- const l = n[c.type.name];
828
- if (!l) {
829
- if (c.type.spec.blocknoteIgnore)
830
- continue;
831
- throw new Error(`style ${c.type.name} not found in styleSchema`);
832
- }
833
- if (l.propSchema === "boolean")
834
- a[l.type] = !0;
835
- else if (l.propSchema === "string")
836
- a[l.type] = c.attrs.stringValue;
837
- else
838
- throw new Z(l.propSchema);
839
- }
840
- r ? I(r) ? i ? (o.push(r), r = {
841
- type: "link",
842
- href: i.attrs.href,
843
- content: [
844
- {
845
- type: "text",
846
- text: s.textContent,
847
- styles: a
848
- }
849
- ]
850
- }) : JSON.stringify(r.styles) === JSON.stringify(a) ? r.text += s.textContent : (o.push(r), r = {
851
- type: "text",
852
- text: s.textContent,
853
- styles: a
854
- }) : Le(r) && (i ? r.href === i.attrs.href ? JSON.stringify(
855
- r.content[r.content.length - 1].styles
856
- ) === JSON.stringify(a) ? r.content[r.content.length - 1].text += s.textContent : r.content.push({
857
- type: "text",
858
- text: s.textContent,
859
- styles: a
860
- }) : (o.push(r), r = {
861
- type: "link",
862
- href: i.attrs.href,
863
- content: [
864
- {
865
- type: "text",
866
- text: s.textContent,
867
- styles: a
868
- }
869
- ]
870
- }) : (o.push(r), r = {
871
- type: "text",
872
- text: s.textContent,
873
- styles: a
874
- })) : i ? r = {
875
- type: "link",
876
- href: i.attrs.href,
877
- content: [
878
- {
879
- type: "text",
880
- text: s.textContent,
881
- styles: a
882
- }
883
- ]
884
- } : r = {
885
- type: "text",
886
- text: s.textContent,
887
- styles: a
888
- };
889
- }), r && o.push(r), o;
890
- }
891
- function Jt(e, t, n) {
892
- if (e.type.name === "text" || e.type.name === "link")
893
- throw new Error("unexpected");
894
- const o = {}, r = t[e.type.name];
895
- for (const [i, c] of Object.entries(e.attrs)) {
896
- if (!r)
897
- throw Error("ic node is of an unrecognized type: " + e.type.name);
898
- const l = r.propSchema;
899
- i in l && (o[i] = c);
900
- }
901
- let s;
902
- return r.content === "styled" ? s = Ce(
903
- e,
904
- t,
905
- n
906
- ) : s = void 0, {
907
- type: e.type.name,
908
- props: o,
909
- content: s
910
- };
911
- }
912
- function X(e, t, n = ge(t), o = be(t), r = R(t), s = ke(t)) {
913
- var k;
914
- if (!e.type.isInGroup("bnBlock"))
915
- throw Error("Node should be a bnBlock, but is instead: " + e.type.name);
916
- const a = s == null ? void 0 : s.get(e);
917
- if (a)
918
- return a;
919
- const i = he(e, 0);
920
- let c = i.bnBlock.node.attrs.id;
921
- c === null && (c = qe.options.generateID());
922
- const l = n[i.blockNoteType];
923
- if (!l)
924
- throw Error("Block is of an unrecognized type: " + i.blockNoteType);
925
- const d = {};
926
- for (const [m, b] of Object.entries({
927
- ...e.attrs,
928
- ...i.isBlockContainer ? i.blockContent.node.attrs : {}
929
- })) {
930
- const y = l.propSchema;
931
- m in y && !(y[m].default === void 0 && b === void 0) && (d[m] = b);
932
- }
933
- const u = n[i.blockNoteType], p = [];
934
- (k = i.childContainer) == null || k.node.forEach((m) => {
935
- p.push(
936
- X(
937
- m,
938
- t,
939
- n,
940
- o,
941
- r,
942
- s
943
- )
944
- );
945
- });
946
- let f;
947
- if (u.content === "inline") {
948
- if (!i.isBlockContainer)
949
- throw new Error("impossible");
950
- f = Ce(
951
- i.blockContent.node,
952
- o,
953
- r
954
- );
955
- } else if (u.content === "table") {
956
- if (!i.isBlockContainer)
957
- throw new Error("impossible");
958
- f = Xt(
959
- i.blockContent.node,
960
- o,
961
- r
962
- );
963
- } else if (u.content === "none")
964
- f = void 0;
965
- else
966
- throw new Z(u.content);
967
- const h = {
968
- id: c,
969
- type: u.type,
970
- props: d,
971
- content: f,
972
- children: p
973
- };
974
- return s == null || s.set(e, h), h;
975
- }
976
- function Uo(e, t, n = ge(t), o = be(t), r = R(t), s = ke(t)) {
977
- const a = [];
978
- return e.firstChild.descendants((i) => (a.push(
979
- X(
980
- i,
981
- t,
982
- n,
983
- o,
984
- r,
985
- s
986
- )
987
- ), !1)), a;
988
- }
989
- function zo(e, t, n = ge(t), o = be(t), r = R(t), s = ke(t)) {
990
- function a(i, c, l) {
991
- if (i.type.name !== "blockGroup")
992
- throw new Error("unexpected");
993
- const d = [];
994
- let u, p;
995
- return i.forEach((f, h, k) => {
996
- if (f.type.name !== "blockContainer")
997
- throw new Error("unexpected");
998
- if (f.childCount === 0)
999
- return;
1000
- if (f.childCount === 0 || f.childCount > 2)
1001
- throw new Error(
1002
- "unexpected, blockContainer.childCount: " + f.childCount
1003
- );
1004
- const m = k === 0, b = k === i.childCount - 1;
1005
- if (f.firstChild.type.name === "blockGroup") {
1006
- if (!m)
1007
- throw new Error("unexpected");
1008
- const S = a(
1009
- f.firstChild,
1010
- Math.max(0, c - 1),
1011
- b ? Math.max(0, l - 1) : 0
1012
- );
1013
- u = S.blockCutAtStart, b && (p = S.blockCutAtEnd), d.push(...S.blocks);
1014
- return;
1015
- }
1016
- const y = X(
1017
- f,
1018
- t,
1019
- n,
1020
- o,
1021
- r,
1022
- s
1023
- ), g = f.childCount > 1 ? f.child(1) : void 0;
1024
- let v = [];
1025
- if (g) {
1026
- const S = a(
1027
- g,
1028
- 0,
1029
- // TODO: can this be anything other than 0?
1030
- b ? Math.max(0, l - 1) : 0
1031
- );
1032
- v = S.blocks, b && (p = S.blockCutAtEnd);
1033
- }
1034
- b && !g && l > 1 && (p = y.id), m && c > 1 && (u = y.id), d.push({
1035
- ...y,
1036
- children: v
1037
- });
1038
- }), { blocks: d, blockCutAtStart: u, blockCutAtEnd: p };
1039
- }
1040
- if (e.content.childCount === 0)
1041
- return {
1042
- blocks: [],
1043
- blockCutAtStart: void 0,
1044
- blockCutAtEnd: void 0
1045
- };
1046
- if (e.content.childCount !== 1)
1047
- throw new Error(
1048
- "slice must be a single block, did you forget includeParents=true?"
1049
- );
1050
- return a(
1051
- e.content.firstChild,
1052
- Math.max(e.openStart - 1, 0),
1053
- Math.max(e.openEnd - 1, 0)
1054
- );
1055
- }
1056
- function qo(e, t, n, o) {
1057
- return e.dom.setAttribute("data-inline-content-type", t), Object.entries(n).filter(([r, s]) => {
1058
- const a = o[r];
1059
- return s !== a.default;
1060
- }).map(([r, s]) => [K(r), s]).forEach(([r, s]) => e.dom.setAttribute(r, s)), e.contentDOM && e.contentDOM.setAttribute("data-editable", ""), e;
1061
- }
1062
- function Zo(e) {
1063
- return {
1064
- Backspace: ({ editor: t }) => {
1065
- const n = t.state.selection.$from;
1066
- return t.state.selection.empty && n.node().type.name === e.type && n.parentOffset === 0;
1067
- }
1068
- };
1069
- }
1070
- function Kt(e, t) {
1071
- return {
1072
- config: e,
1073
- implementation: t
1074
- };
1075
- }
1076
- function Go(e, t, n) {
1077
- return Kt(
1078
- {
1079
- type: e.name,
1080
- propSchema: t,
1081
- content: e.config.content === "inline*" ? "styled" : "none"
1082
- },
1083
- {
1084
- ...n,
1085
- node: e
1086
- }
1087
- );
1088
- }
1089
- function Je(e) {
1090
- return Object.fromEntries(
1091
- Object.entries(e).map(([t, n]) => [t, n.config])
1092
- );
1093
- }
1094
- function Qt(e) {
1095
- return e === "boolean" ? {} : {
1096
- stringValue: {
1097
- default: void 0,
1098
- keepOnSplit: !0,
1099
- parseHTML: (t) => t.getAttribute("data-value"),
1100
- renderHTML: (t) => t.stringValue !== void 0 ? {
1101
- "data-value": t.stringValue
1102
- } : {}
1103
- }
1104
- };
1105
- }
1106
- function J(e, t, n, o) {
1107
- return e.dom.setAttribute("data-style-type", t), o === "string" && e.dom.setAttribute("data-value", n), e.contentDOM && e.contentDOM.setAttribute("data-editable", ""), e;
1108
- }
1109
- function Ke(e, t) {
1110
- return {
1111
- config: e,
1112
- implementation: t
1113
- };
1114
- }
1115
- function F(e, t) {
1116
- return Ke(
1117
- {
1118
- type: e.name,
1119
- propSchema: t
1120
- },
1121
- {
1122
- mark: e,
1123
- render(n, o) {
1124
- const r = o.pmSchema.marks[e.name].spec.toDOM;
1125
- if (r === void 0)
1126
- throw new Error(
1127
- "This block has no default HTML serialization as its corresponding TipTap node doesn't implement `renderHTML`."
1128
- );
1129
- const s = o.pmSchema.mark(e.name, {
1130
- stringValue: n
1131
- }), a = Be.renderSpec(
1132
- document,
1133
- r(s, !0)
1134
- );
1135
- if (typeof a != "object" || !("dom" in a))
1136
- throw new Error(
1137
- "Cannot use this block's default HTML serialization as its corresponding TipTap mark's `renderHTML` function does not return an object with the `dom` property."
1138
- );
1139
- return a;
1140
- },
1141
- toExternalHTML(n, o) {
1142
- const r = o.pmSchema.marks[e.name].spec.toDOM;
1143
- if (r === void 0)
1144
- throw new Error(
1145
- "This block has no default HTML serialization as its corresponding TipTap node doesn't implement `renderHTML`."
1146
- );
1147
- const s = o.pmSchema.mark(e.name, {
1148
- stringValue: n
1149
- }), a = Be.renderSpec(
1150
- document,
1151
- r(s, !0)
1152
- );
1153
- if (typeof a != "object" || !("dom" in a))
1154
- throw new Error(
1155
- "Cannot use this block's default HTML serialization as its corresponding TipTap mark's `renderHTML` function does not return an object with the `dom` property."
1156
- );
1157
- return a;
1158
- }
1159
- }
1160
- );
1161
- }
1162
- function Qe(e) {
1163
- return Object.fromEntries(
1164
- Object.entries(e).map(([t, n]) => [t, n.config])
1165
- );
1166
- }
1167
- function Yt(e, t) {
1168
- const n = [
1169
- {
1170
- tag: `[data-style-type="${e.type}"]`,
1171
- contentElement: (o) => {
1172
- const r = o;
1173
- return r.matches("[data-editable]") ? r : r.querySelector("[data-editable]") || r;
1174
- }
1175
- }
1176
- ];
1177
- return t && n.push({
1178
- tag: "*",
1179
- getAttrs(o) {
1180
- if (typeof o == "string")
1181
- return !1;
1182
- const r = t == null ? void 0 : t(o);
1183
- return r === void 0 ? !1 : { stringValue: r };
1184
- }
1185
- }), n;
1186
- }
1187
- function Ye(e, t) {
1188
- const n = Lt.create({
1189
- name: e.type,
1190
- addAttributes() {
1191
- return Qt(e.propSchema);
1192
- },
1193
- parseHTML() {
1194
- return Yt(e, t.parse);
1195
- },
1196
- renderHTML({ mark: o }) {
1197
- const r = (t.toExternalHTML || t.render)(o.attrs.stringValue);
1198
- return J(
1199
- r,
1200
- e.type,
1201
- o.attrs.stringValue,
1202
- e.propSchema
1203
- );
1204
- },
1205
- addMarkView() {
1206
- return ({ mark: o }) => {
1207
- const r = t.render(o.attrs.stringValue);
1208
- return J(
1209
- r,
1210
- e.type,
1211
- o.attrs.stringValue,
1212
- e.propSchema
1213
- );
1214
- };
1215
- }
1216
- });
1217
- return Ke(e, {
1218
- mark: n,
1219
- render: (o) => {
1220
- const r = t.render(o);
1221
- return J(
1222
- r,
1223
- e.type,
1224
- o,
1225
- e.propSchema
1226
- );
1227
- },
1228
- toExternalHTML: (o) => {
1229
- const r = (t.toExternalHTML || t.render)(o);
1230
- return J(
1231
- r,
1232
- e.type,
1233
- o,
1234
- e.propSchema
1235
- );
1236
- }
1237
- });
1238
- }
1239
- function en(e) {
1240
- const t = nn(e);
1241
- let { roots: n, nonRoots: o } = Ae(t);
1242
- const r = [];
1243
- for (; n.size; ) {
1244
- r.push(n);
1245
- const s = /* @__PURE__ */ new Set();
1246
- for (const a of n) {
1247
- const i = e.get(a);
1248
- if (i)
1249
- for (const c of i) {
1250
- const l = t.get(c);
1251
- if (l === void 0)
1252
- continue;
1253
- const d = l - 1;
1254
- t.set(c, d), d === 0 && s.add(c);
1255
- }
1256
- }
1257
- n = s;
1258
- }
1259
- if (o = Ae(t).nonRoots, o.size)
1260
- throw new Error(
1261
- `Cycle(s) detected; toposort only works on acyclic graphs. Cyclic nodes: ${Array.from(o).join(", ")}`
1262
- );
1263
- return r;
1264
- }
1265
- function tn(e) {
1266
- const t = on(e);
1267
- return en(t);
1268
- }
1269
- function nn(e) {
1270
- const t = /* @__PURE__ */ new Map();
1271
- for (const [n, o] of e.entries()) {
1272
- t.has(n) || t.set(n, 0);
1273
- for (const r of o) {
1274
- const s = t.get(r) ?? 0;
1275
- t.set(r, s + 1);
1276
- }
1277
- }
1278
- return t;
1279
- }
1280
- function Ae(e) {
1281
- const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
1282
- for (const [o, r] of e.entries())
1283
- r === 0 ? t.add(o) : n.add(o);
1284
- return { roots: t, nonRoots: n };
1285
- }
1286
- function on(e) {
1287
- const t = /* @__PURE__ */ new Map();
1288
- for (const [n, o] of e.entries()) {
1289
- t.has(n) || t.set(n, /* @__PURE__ */ new Set());
1290
- for (const r of o)
1291
- t.has(r) || t.set(r, /* @__PURE__ */ new Set()), t.get(r).add(n);
1292
- }
1293
- return t;
1294
- }
1295
- function rn() {
1296
- return /* @__PURE__ */ new Map();
1297
- }
1298
- function Ne(e) {
1299
- return e && Object.fromEntries(
1300
- Object.entries(e).filter(([, t]) => t !== void 0)
1301
- );
1302
- }
1303
- class sn {
1304
- constructor(t) {
1305
- // Helper so that you can use typeof schema.BlockNoteEditor
1306
- x(this, "BlockNoteEditor", "only for types");
1307
- x(this, "Block", "only for types");
1308
- x(this, "PartialBlock", "only for types");
1309
- x(this, "inlineContentSpecs");
1310
- x(this, "styleSpecs");
1311
- x(this, "blockSpecs");
1312
- x(this, "blockSchema");
1313
- x(this, "inlineContentSchema");
1314
- x(this, "styleSchema");
1315
- this.opts = t;
1316
- const {
1317
- blockSpecs: n,
1318
- inlineContentSpecs: o,
1319
- styleSpecs: r,
1320
- blockSchema: s,
1321
- inlineContentSchema: a,
1322
- styleSchema: i
1323
- } = this.init();
1324
- this.blockSpecs = n, this.styleSpecs = r, this.styleSchema = i, this.inlineContentSpecs = o, this.blockSchema = s, this.inlineContentSchema = a;
1325
- }
1326
- init() {
1327
- const t = rn(), n = /* @__PURE__ */ new Set();
1328
- t.set("default", n);
1329
- for (const [i, c] of Object.entries(this.opts.blockSpecs))
1330
- c.implementation.runsBefore ? t.set(i, new Set(c.implementation.runsBefore)) : n.add(i);
1331
- const o = tn(t), r = o.findIndex((i) => i.has("default")), s = (i) => 91 + (o.findIndex((l) => l.has(i)) + r) * 10, a = Object.fromEntries(
1332
- Object.entries(this.opts.blockSpecs).map(([i, c]) => [
1333
- i,
1334
- qt(
1335
- c.config,
1336
- c.implementation,
1337
- c.extensions,
1338
- s(i)
1339
- )
1340
- ])
1341
- );
1342
- return {
1343
- blockSpecs: a,
1344
- blockSchema: Object.fromEntries(
1345
- Object.entries(a).map(([i, c]) => [i, c.config])
1346
- ),
1347
- inlineContentSpecs: Ne(this.opts.inlineContentSpecs),
1348
- styleSpecs: Ne(this.opts.styleSpecs),
1349
- inlineContentSchema: Je(
1350
- this.opts.inlineContentSpecs
1351
- ),
1352
- styleSchema: Qe(this.opts.styleSpecs)
1353
- };
1354
- }
1355
- /**
1356
- * Adds additional block specs to the current schema in a builder pattern.
1357
- * This method allows extending the schema after it has been created.
1358
- *
1359
- * @param additionalBlockSpecs - Additional block specs to add to the schema
1360
- * @returns The current schema instance for chaining
1361
- */
1362
- extend(t) {
1363
- Object.assign(this.opts.blockSpecs, t.blockSpecs), Object.assign(this.opts.inlineContentSpecs, t.inlineContentSpecs), Object.assign(this.opts.styleSpecs, t.styleSpecs);
1364
- const {
1365
- blockSpecs: n,
1366
- inlineContentSpecs: o,
1367
- styleSpecs: r,
1368
- blockSchema: s,
1369
- inlineContentSchema: a,
1370
- styleSchema: i
1371
- } = this.init();
1372
- return this.blockSpecs = n, this.styleSpecs = r, this.styleSchema = i, this.inlineContentSpecs = o, this.blockSchema = s, this.inlineContentSchema = a, this;
1373
- }
1374
- }
1375
- function N(e) {
1376
- const { height: t, width: n } = et(e), o = new Array(t).fill(!1).map(() => new Array(n).fill(null)), r = (s, a) => {
1377
- for (let i = s; i < t; i++)
1378
- for (let c = a; c < n; c++)
1379
- if (!o[i][c])
1380
- return { row: i, col: c };
1381
- throw new Error(
1382
- "Unable to create occupancy grid for table, no more available cells"
1383
- );
1384
- };
1385
- for (let s = 0; s < e.content.rows.length; s++)
1386
- for (let a = 0; a < e.content.rows[s].cells.length; a++) {
1387
- const i = se(e.content.rows[s].cells[a]), c = ae(i), l = j(i), { row: d, col: u } = r(s, a);
1388
- for (let p = d; p < d + c; p++)
1389
- for (let f = u; f < u + l; f++) {
1390
- if (o[p][f])
1391
- throw new Error(
1392
- `Unable to create occupancy grid for table, cell at ${p},${f} is already occupied`
1393
- );
1394
- o[p][f] = {
1395
- row: s,
1396
- col: a,
1397
- rowspan: c,
1398
- colspan: l,
1399
- cell: i
1400
- };
1401
- }
1402
- }
1403
- return o;
1404
- }
1405
- function q(e) {
1406
- const t = /* @__PURE__ */ new Set();
1407
- return e.map((n) => ({
1408
- cells: n.map((o) => t.has(o.row + ":" + o.col) ? !1 : (t.add(o.row + ":" + o.col), o.cell)).filter((o) => o !== !1)
1409
- }));
1410
- }
1411
- function P(e, t, n = N(t)) {
1412
- for (let o = 0; o < n.length; o++)
1413
- for (let r = 0; r < n[o].length; r++) {
1414
- const s = n[o][r];
1415
- if (s.row === e.row && s.col === e.col)
1416
- return { row: o, col: r, cell: s.cell };
1417
- }
1418
- throw new Error(
1419
- `Unable to resolve relative table cell indices for table, cell at ${e.row},${e.col} is not occupied`
1420
- );
1421
- }
1422
- function et(e) {
1423
- const t = e.content.rows.length;
1424
- let n = 0;
1425
- return e.content.rows.forEach((o) => {
1426
- let r = 0;
1427
- o.cells.forEach((s) => {
1428
- r += j(s);
1429
- }), n = Math.max(n, r);
1430
- }), { height: t, width: n };
1431
- }
1432
- function tt(e, t, n = N(t)) {
1433
- var r;
1434
- const o = (r = n[e.row]) == null ? void 0 : r[e.col];
1435
- if (o)
1436
- return {
1437
- row: o.row,
1438
- col: o.col,
1439
- cell: o.cell
1440
- };
1441
- }
1442
- function an(e, t) {
1443
- var s;
1444
- const n = N(e);
1445
- if (t < 0 || t >= n.length)
1446
- return [];
1447
- let o = 0;
1448
- for (let a = 0; a < t; a++) {
1449
- const i = (s = n[o]) == null ? void 0 : s[0];
1450
- if (!i)
1451
- return [];
1452
- o += i.rowspan;
1453
- }
1454
- const r = new Array(n[0].length).fill(!1).map((a, i) => tt(
1455
- { row: o, col: i },
1456
- e,
1457
- n
1458
- )).filter(
1459
- (a) => a !== void 0
1460
- );
1461
- return r.filter((a, i) => r.findIndex((c) => c.row === a.row && c.col === a.col) === i);
1462
- }
1463
- function cn(e, t) {
1464
- var s;
1465
- const n = N(e);
1466
- if (t < 0 || t >= n[0].length)
1467
- return [];
1468
- let o = 0;
1469
- for (let a = 0; a < t; a++) {
1470
- const i = (s = n[0]) == null ? void 0 : s[o];
1471
- if (!i)
1472
- return [];
1473
- o += i.colspan;
1474
- }
1475
- const r = new Array(n.length).fill(!1).map((a, i) => tt(
1476
- { row: i, col: o },
1477
- e,
1478
- n
1479
- )).filter(
1480
- (a) => a !== void 0
1481
- );
1482
- return r.filter((a, i) => r.findIndex((c) => c.row === a.row && c.col === a.col) === i);
1483
- }
1484
- function Xo(e, t, n, o = N(e)) {
1485
- const { col: r } = P(
1486
- {
1487
- row: 0,
1488
- col: t
1489
- },
1490
- e,
1491
- o
1492
- ), { col: s } = P(
1493
- {
1494
- row: 0,
1495
- col: n
1496
- },
1497
- e,
1498
- o
1499
- );
1500
- return o.forEach((a) => {
1501
- const [i] = a.splice(r, 1);
1502
- a.splice(s, 0, i);
1503
- }), q(o);
1504
- }
1505
- function Jo(e, t, n, o = N(e)) {
1506
- const { row: r } = P(
1507
- {
1508
- row: t,
1509
- col: 0
1510
- },
1511
- e,
1512
- o
1513
- ), { row: s } = P(
1514
- {
1515
- row: n,
1516
- col: 0
1517
- },
1518
- e,
1519
- o
1520
- ), [a] = o.splice(r, 1);
1521
- return o.splice(s, 0, a), q(o);
1522
- }
1523
- function ce(e) {
1524
- return e ? $(e) ? ce(e.content) : typeof e == "string" ? e.length === 0 : Array.isArray(e) ? e.every(
1525
- (t) => typeof t == "string" ? t.length === 0 : I(t) ? t.text.length === 0 : Ze(t) ? typeof t.content == "string" ? t.content.length === 0 : t.content.every((n) => n.text.length === 0) : !1
1526
- ) : !1 : !0;
1527
- }
1528
- function Ko(e, t, n = N(e)) {
1529
- if (t === "columns") {
1530
- let s = 0;
1531
- for (let a = n[0].length - 1; a >= 0 && n.every(
1532
- (c) => ce(c[a].cell) && c[a].colspan === 1
1533
- ); a--)
1534
- s++;
1535
- for (let a = n.length - 1; a >= 0; a--) {
1536
- const i = Math.max(
1537
- n[a].length - s,
1538
- 1
1539
- );
1540
- n[a] = n[a].slice(0, i);
1541
- }
1542
- return q(n);
1543
- }
1544
- let o = 0;
1545
- for (let s = n.length - 1; s >= 0 && n[s].every(
1546
- (i) => ce(i.cell) && i.rowspan === 1
1547
- ); s--)
1548
- o++;
1549
- const r = Math.min(o, n.length - 1);
1550
- return n.splice(n.length - r, r), q(n);
1551
- }
1552
- function Qo(e, t, n, o = N(e)) {
1553
- const { width: r, height: s } = et(e);
1554
- if (t === "columns")
1555
- o.forEach((a, i) => {
1556
- if (n >= 0)
1557
- for (let c = 0; c < n; c++)
1558
- a.push({
1559
- row: i,
1560
- col: Math.max(...a.map((l) => l.col)) + 1,
1561
- rowspan: 1,
1562
- colspan: 1,
1563
- cell: se("")
1564
- });
1565
- else
1566
- a.splice(r + n, -1 * n);
1567
- });
1568
- else if (n > 0)
1569
- for (let a = 0; a < n; a++) {
1570
- const i = new Array(r).fill(null).map((c, l) => ({
1571
- row: s + a,
1572
- col: l,
1573
- rowspan: 1,
1574
- colspan: 1,
1575
- cell: se("")
1576
- }));
1577
- o.push(i);
1578
- }
1579
- else n < 0 && o.splice(s + n, -1 * n);
1580
- return q(o);
1581
- }
1582
- function Yo(e, t, n) {
1583
- const o = an(e, n);
1584
- if (!o.some((c) => ae(c.cell) > 1))
1585
- return !0;
1586
- let s = n, a = n;
1587
- return o.forEach((c) => {
1588
- const l = ae(c.cell);
1589
- s = Math.max(s, c.row + l - 1), a = Math.min(a, c.row);
1590
- }), t < n ? n === s : n === a;
1591
- }
1592
- function er(e, t, n) {
1593
- const o = cn(e, n);
1594
- if (!o.some((c) => j(c.cell) > 1))
1595
- return !0;
1596
- let s = n, a = n;
1597
- return o.forEach((c) => {
1598
- const l = j(c.cell);
1599
- s = Math.max(s, c.col + l - 1), a = Math.min(a, c.col);
1600
- }), t < n ? n === s : n === a;
1601
- }
1602
- function tr(e, t, n) {
1603
- const o = P(e, n), r = P(t, n);
1604
- return o.col === r.col;
1605
- }
1606
- function Ie(e, t, n, o) {
1607
- const r = [];
1608
- for (const [a, i] of Object.entries(e.styles || {})) {
1609
- const c = n[a];
1610
- if (!c)
1611
- throw new Error(`style ${a} not found in styleSchema`);
1612
- if (c.propSchema === "boolean")
1613
- i && r.push(t.mark(a));
1614
- else if (c.propSchema === "string")
1615
- i && r.push(t.mark(a, { stringValue: i }));
1616
- else
1617
- throw new Z(c.propSchema);
1618
- }
1619
- return !o || !t.nodes[o].spec.code ? e.text.split(/(\n)/g).filter((a) => a.length > 0).map((a) => a === `
1620
- ` ? t.nodes.hardBreak.createChecked() : t.text(a, r)) : e.text.length > 0 ? [t.text(e.text, r)] : [];
1621
- }
1622
- function ln(e, t, n) {
1623
- const o = t.marks.link.create({
1624
- href: e.href
1625
- });
1626
- return le(e.content, t, n).map(
1627
- (r) => {
1628
- if (r.type.name === "text")
1629
- return r.mark([...r.marks, o]);
1630
- if (r.type.name === "hardBreak")
1631
- return r;
1632
- throw new Error("unexpected node type");
1633
- }
1634
- );
1635
- }
1636
- function le(e, t, n, o) {
1637
- const r = [];
1638
- if (typeof e == "string")
1639
- return r.push(
1640
- ...Ie(
1641
- { text: e, styles: {} },
1642
- t,
1643
- n,
1644
- o
1645
- )
1646
- ), r;
1647
- for (const s of e)
1648
- r.push(
1649
- ...Ie(s, t, n, o)
1650
- );
1651
- return r;
1652
- }
1653
- function O(e, t, n, o = R(t)) {
1654
- const r = [];
1655
- for (const s of e)
1656
- typeof s == "string" ? r.push(
1657
- ...le(s, t, o, n)
1658
- ) : Ze(s) ? r.push(...ln(s, t, o)) : I(s) ? r.push(
1659
- ...le([s], t, o, n)
1660
- ) : r.push(
1661
- ot(s, t, o)
1662
- );
1663
- return r;
1664
- }
1665
- function nt(e, t, n = R(t)) {
1666
- const o = [], r = new Array(e.headerRows ?? 0).fill(!0), s = new Array(e.headerCols ?? 0).fill(!0), a = e.columnWidths ?? [];
1667
- for (let i = 0; i < e.rows.length; i++) {
1668
- const c = e.rows[i], l = [], d = r[i];
1669
- for (let p = 0; p < c.cells.length; p++) {
1670
- const f = c.cells[p], h = s[p], k = void 0;
1671
- let m = null;
1672
- const b = P(
1673
- {
1674
- row: i,
1675
- col: p
1676
- },
1677
- { content: e }
1678
- );
1679
- let y = a[b.col] ? [a[b.col]] : null;
1680
- if (f) if (typeof f == "string")
1681
- m = t.text(f);
1682
- else if ($(f)) {
1683
- f.content && (m = O(
1684
- f.content,
1685
- t,
1686
- "tableParagraph",
1687
- n
1688
- ));
1689
- const v = j(f);
1690
- v > 1 && (y = new Array(v).fill(!1).map((S, oe) => a[b.col + oe] ?? void 0));
1691
- } else
1692
- m = O(
1693
- f,
1694
- t,
1695
- "tableParagraph",
1696
- n
1697
- );
1698
- const g = t.nodes[h || d ? "tableHeader" : "tableCell"].createChecked(
1699
- {
1700
- ...$(f) ? f.props : {},
1701
- colwidth: y
1702
- },
1703
- t.nodes.tableParagraph.createChecked(k, m)
1704
- );
1705
- l.push(g);
1706
- }
1707
- const u = t.nodes.tableRow.createChecked({}, l);
1708
- o.push(u);
1709
- }
1710
- return o;
1711
- }
1712
- function ot(e, t, n) {
1713
- let o, r = e.type;
1714
- if (r === void 0 && (r = "paragraph"), !t.nodes[r])
1715
- throw new Error(`node type ${r} not found in schema`);
1716
- if (!e.content)
1717
- o = t.nodes[r].createChecked(e.props);
1718
- else if (typeof e.content == "string") {
1719
- const s = O(
1720
- [e.content],
1721
- t,
1722
- r,
1723
- n
1724
- );
1725
- o = t.nodes[r].createChecked(e.props, s);
1726
- } else if (Array.isArray(e.content)) {
1727
- const s = O(
1728
- e.content,
1729
- t,
1730
- r,
1731
- n
1732
- );
1733
- o = t.nodes[r].createChecked(e.props, s);
1734
- } else if (e.content.type === "tableContent") {
1735
- const s = nt(e.content, t, n);
1736
- o = t.nodes[r].createChecked(e.props, s);
1737
- } else
1738
- throw new Z(e.content.type);
1739
- return o;
1740
- }
1741
- function Y(e, t, n = R(t)) {
1742
- let o = e.id;
1743
- o === void 0 && (o = qe.options.generateID());
1744
- const r = [];
1745
- if (e.children)
1746
- for (const a of e.children)
1747
- r.push(Y(a, t, n));
1748
- if (!e.type || // can happen if block.type is not defined (this should create the default node)
1749
- t.nodes[e.type].isInGroup("blockContent")) {
1750
- const a = ot(
1751
- e,
1752
- t,
1753
- n
1754
- ), i = r.length > 0 ? t.nodes.blockGroup.createChecked({}, r) : void 0;
1755
- return t.nodes.blockContainer.createChecked(
1756
- {
1757
- id: o,
1758
- ...e.props
1759
- },
1760
- i ? [a, i] : a
1761
- );
1762
- } else {
1763
- if (t.nodes[e.type].isInGroup("bnBlock"))
1764
- return t.nodes[e.type].createChecked(
1765
- {
1766
- id: o,
1767
- ...e.props
1768
- },
1769
- r
1770
- );
1771
- throw new Error(
1772
- `block type ${e.type} doesn't match blockContent or bnBlock group`
1773
- );
1774
- }
1775
- }
1776
- function un(e, t) {
1777
- let n, o;
1778
- if (t.firstChild.descendants((r, s) => n ? !1 : !dn(r) || r.attrs.id !== e ? !0 : (n = r, o = s + 1, !1)), !(n === void 0 || o === void 0))
1779
- return {
1780
- node: n,
1781
- posBeforeNode: o
1782
- };
1783
- }
1784
- function dn(e) {
1785
- return e.type.isInGroup("bnBlock");
1786
- }
1787
- const nr = (e, t) => ({
1788
- tr: n,
1789
- dispatch: o
1790
- }) => (o && ye(n, e, t), !0);
1791
- function ye(e, t, n, o, r) {
1792
- const s = Zt(e.doc.resolve(t));
1793
- let a = null;
1794
- s.blockNoteType === "table" && (a = fn(e));
1795
- const i = G(e);
1796
- if (o !== void 0 && r !== void 0 && o > r)
1797
- throw new Error("Invalid replaceFromPos or replaceToPos");
1798
- const c = i.nodes[s.blockNoteType], l = i.nodes[n.type || s.blockNoteType], d = l.isInGroup("bnBlock") ? l : i.nodes.blockContainer;
1799
- if (s.isBlockContainer && l.isInGroup("blockContent")) {
1800
- const u = o !== void 0 && o > s.blockContent.beforePos && o < s.blockContent.afterPos ? o - s.blockContent.beforePos - 1 : void 0, p = r !== void 0 && r > s.blockContent.beforePos && r < s.blockContent.afterPos ? r - s.blockContent.beforePos - 1 : void 0;
1801
- Pe(n, e, s), pn(
1802
- n,
1803
- e,
1804
- c,
1805
- l,
1806
- s,
1807
- u,
1808
- p
1809
- );
1810
- } else if (!s.isBlockContainer && l.isInGroup("bnBlock"))
1811
- Pe(n, e, s);
1812
- else {
1813
- const u = X(s.bnBlock.node, i);
1814
- e.replaceWith(
1815
- s.bnBlock.beforePos,
1816
- s.bnBlock.afterPos,
1817
- Y(
1818
- {
1819
- children: u.children,
1820
- // if no children are passed in, use existing children
1821
- ...n
1822
- },
1823
- i
1824
- )
1825
- );
1826
- return;
1827
- }
1828
- e.setNodeMarkup(s.bnBlock.beforePos, d, {
1829
- ...s.bnBlock.node.attrs,
1830
- ...n.props
1831
- }), a && hn(e, s, a);
1832
- }
1833
- function pn(e, t, n, o, r, s, a) {
1834
- const i = G(t);
1835
- let c = "keep";
1836
- if (e.content)
1837
- if (typeof e.content == "string")
1838
- c = O(
1839
- [e.content],
1840
- i,
1841
- o.name
1842
- );
1843
- else if (Array.isArray(e.content))
1844
- c = O(e.content, i, o.name);
1845
- else if (e.content.type === "tableContent")
1846
- c = nt(e.content, i);
1847
- else
1848
- throw new Z(e.content.type);
1849
- else
1850
- n.spec.content === "" || o.spec.content !== n.spec.content && (c = []);
1851
- if (c === "keep")
1852
- t.setNodeMarkup(r.blockContent.beforePos, o, {
1853
- ...r.blockContent.node.attrs,
1854
- ...e.props
1855
- });
1856
- else if (s !== void 0 || a !== void 0) {
1857
- t.setNodeMarkup(r.blockContent.beforePos, o, {
1858
- ...r.blockContent.node.attrs,
1859
- ...e.props
1860
- });
1861
- const l = r.blockContent.beforePos + 1 + (s ?? 0), d = r.blockContent.beforePos + 1 + (a ?? r.blockContent.node.content.size), u = t.doc.resolve(r.blockContent.beforePos).depth, p = t.doc.resolve(l).depth, f = t.doc.resolve(d).depth;
1862
- t.replace(
1863
- l,
1864
- d,
1865
- new de(
1866
- _.from(c),
1867
- p - u - 1,
1868
- f - u - 1
1869
- )
1870
- );
1871
- } else
1872
- t.replaceWith(
1873
- r.blockContent.beforePos,
1874
- r.blockContent.afterPos,
1875
- o.createChecked(
1876
- {
1877
- ...r.blockContent.node.attrs,
1878
- ...e.props
1879
- },
1880
- c
1881
- )
1882
- );
1883
- }
1884
- function Pe(e, t, n) {
1885
- const o = G(t);
1886
- if (e.children !== void 0 && e.children.length > 0) {
1887
- const r = e.children.map((s) => Y(s, o));
1888
- if (n.childContainer)
1889
- t.step(
1890
- new Ht(
1891
- n.childContainer.beforePos + 1,
1892
- n.childContainer.afterPos - 1,
1893
- new de(_.from(r), 0, 0)
1894
- )
1895
- );
1896
- else {
1897
- if (!n.isBlockContainer)
1898
- throw new Error("impossible");
1899
- t.insert(
1900
- n.blockContent.afterPos,
1901
- o.nodes.blockGroup.createChecked({}, r)
1902
- );
1903
- }
1904
- }
1905
- }
1906
- function or(e, t, n, o, r) {
1907
- const s = typeof t == "string" ? t : t.id, a = un(s, e.doc);
1908
- if (!a)
1909
- throw new Error(`Block with ID ${s} not found`);
1910
- ye(
1911
- e,
1912
- a.posBeforeNode,
1913
- n,
1914
- o,
1915
- r
1916
- );
1917
- const i = e.doc.resolve(a.posBeforeNode + 1).node(), c = G(e);
1918
- return X(i, c);
1919
- }
1920
- function fn(e) {
1921
- const t = "selection" in e ? e.selection : null;
1922
- if (!(t instanceof ze))
1923
- return null;
1924
- const n = e.doc.resolve(t.head);
1925
- let o = -1, r = -1;
1926
- for (let m = n.depth; m >= 0; m--) {
1927
- const b = n.node(m).type.name;
1928
- if (o < 0 && (b === "tableCell" || b === "tableHeader") && (o = m), b === "table") {
1929
- r = m;
1930
- break;
1931
- }
1932
- }
1933
- if (o < 0 || r < 0)
1934
- return null;
1935
- const s = n.before(o), a = n.before(r), i = e.doc.nodeAt(a);
1936
- if (!i || i.type.name !== "table")
1937
- return null;
1938
- const c = We.get(i), l = s - (a + 1), d = c.map.indexOf(l);
1939
- if (d < 0)
1940
- return null;
1941
- const u = Math.floor(d / c.width), p = d % c.width, h = s + 1 + 1, k = Math.max(0, t.head - h);
1942
- return { row: u, col: p, offset: k };
1943
- }
1944
- function hn(e, t, n) {
1945
- var m;
1946
- if (t.blockNoteType !== "table")
1947
- return !1;
1948
- let o = -1;
1949
- if (t.isBlockContainer)
1950
- o = e.mapping.map(t.blockContent.beforePos);
1951
- else {
1952
- const b = e.mapping.map(t.bnBlock.beforePos), y = b + (((m = e.doc.nodeAt(b)) == null ? void 0 : m.nodeSize) || 0);
1953
- e.doc.nodesBetween(b, y, (g, v) => g.type.name === "table" ? (o = v, !1) : !0);
1954
- }
1955
- const r = o >= 0 ? e.doc.nodeAt(o) : null;
1956
- if (!r || r.type.name !== "table")
1957
- return !1;
1958
- const s = We.get(r), a = Math.max(0, Math.min(n.row, s.height - 1)), i = Math.max(0, Math.min(n.col, s.width - 1)), c = a * s.width + i, l = s.map[c];
1959
- if (l == null)
1960
- return !1;
1961
- const u = o + 1 + l + 1, p = e.doc.nodeAt(u), f = u + 1, h = p ? p.content.size : 0, k = f + Math.max(0, Math.min(n.offset, h));
1962
- return "selection" in e && e.setSelection(ze.create(e.doc, k)), !0;
1963
- }
1964
- const A = {
1965
- gray: {
1966
- text: "#9b9a97",
1967
- background: "#ebeced"
1968
- },
1969
- brown: {
1970
- text: "#64473a",
1971
- background: "#e9e5e3"
1972
- },
1973
- red: {
1974
- text: "#e03e3e",
1975
- background: "#fbe4e4"
1976
- },
1977
- orange: {
1978
- text: "#d9730d",
1979
- background: "#f6e9d9"
1980
- },
1981
- yellow: {
1982
- text: "#dfab01",
1983
- background: "#fbf3db"
1984
- },
1985
- green: {
1986
- text: "#4d6461",
1987
- background: "#ddedea"
1988
- },
1989
- blue: {
1990
- text: "#0b6e99",
1991
- background: "#ddebf1"
1992
- },
1993
- purple: {
1994
- text: "#6940a5",
1995
- background: "#eae4f2"
1996
- },
1997
- pink: {
1998
- text: "#ad1a72",
1999
- background: "#f4dfeb"
2000
- }
2001
- }, rr = {
2002
- gray: {
2003
- text: "#bebdb8",
2004
- background: "#9b9a97"
2005
- },
2006
- brown: {
2007
- text: "#8e6552",
2008
- background: "#64473a"
2009
- },
2010
- red: {
2011
- text: "#ec4040",
2012
- background: "#be3434"
2013
- },
2014
- orange: {
2015
- text: "#e3790d",
2016
- background: "#b7600a"
2017
- },
2018
- yellow: {
2019
- text: "#dfab01",
2020
- background: "#b58b00"
2021
- },
2022
- green: {
2023
- text: "#6b8b87",
2024
- background: "#4d6461"
2025
- },
2026
- blue: {
2027
- text: "#0e87bc",
2028
- background: "#0b6e99"
2029
- },
2030
- purple: {
2031
- text: "#8552d7",
2032
- background: "#6940a5"
2033
- },
2034
- pink: {
2035
- text: "#da208f",
2036
- background: "#ad1a72"
2037
- }
2038
- }, C = {
2039
- backgroundColor: {
2040
- default: "default"
2041
- },
2042
- textColor: {
2043
- default: "default"
2044
- },
2045
- textAlignment: {
2046
- default: "left",
2047
- values: ["left", "center", "right", "justify"]
2048
- }
2049
- }, B = (e) => {
2050
- const t = {};
2051
- return e.hasAttribute("data-background-color") ? t.backgroundColor = e.getAttribute("data-background-color") : e.style.backgroundColor && (t.backgroundColor = e.style.backgroundColor), e.hasAttribute("data-text-color") ? t.textColor = e.getAttribute("data-text-color") : e.style.color && (t.textColor = e.style.color), t.textAlignment = C.textAlignment.values.includes(
2052
- e.style.textAlign
2053
- ) ? e.style.textAlign : void 0, t;
2054
- }, H = (e, t) => {
2055
- e.backgroundColor && e.backgroundColor !== C.backgroundColor.default && (t.style.backgroundColor = e.backgroundColor in A ? A[e.backgroundColor].background : e.backgroundColor), e.textColor && e.textColor !== C.textColor.default && (t.style.color = e.textColor in A ? A[e.textColor].text : e.textColor), e.textAlignment && e.textAlignment !== C.textAlignment.default && (t.style.textAlign = e.textAlignment);
2056
- }, sr = (e = "backgroundColor") => ({
2057
- default: C.backgroundColor.default,
2058
- parseHTML: (t) => t.hasAttribute("data-background-color") ? t.getAttribute("data-background-color") : t.style.backgroundColor ? t.style.backgroundColor : C.backgroundColor.default,
2059
- renderHTML: (t) => t[e] === C.backgroundColor.default ? {} : {
2060
- "data-background-color": t[e]
2061
- }
2062
- }), ar = (e = "textColor") => ({
2063
- default: C.textColor.default,
2064
- parseHTML: (t) => t.hasAttribute("data-text-color") ? t.getAttribute("data-text-color") : t.style.color ? t.style.color : C.textColor.default,
2065
- renderHTML: (t) => t[e] === C.textColor.default ? {} : {
2066
- "data-text-color": t[e]
2067
- }
2068
- }), ir = (e = "textAlignment") => ({
2069
- default: C.textAlignment.default,
2070
- parseHTML: (t) => t.hasAttribute("data-text-alignment") ? t.getAttribute("data-text-alignment") : t.style.textAlign ? t.style.textAlign : C.textAlignment.default,
2071
- renderHTML: (t) => t[e] === C.textAlignment.default ? {} : {
2072
- "data-text-alignment": t[e]
2073
- }
2074
- }), ee = (e, t) => {
2075
- const n = e.querySelector(
2076
- t
2077
- );
2078
- if (!n)
2079
- return;
2080
- const o = e.querySelector("figcaption"), r = (o == null ? void 0 : o.textContent) ?? void 0;
2081
- return { targetElement: n, caption: r };
2082
- }, mn = (e, t, n) => {
2083
- const o = document.createElement("div");
2084
- o.className = "bn-add-file-button";
2085
- const r = document.createElement("div");
2086
- r.className = "bn-add-file-button-icon", n ? r.appendChild(n) : r.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>', o.appendChild(r);
2087
- const s = document.createElement("p");
2088
- s.className = "bn-add-file-button-text", s.innerHTML = e.type in t.dictionary.file_blocks.add_button_text ? t.dictionary.file_blocks.add_button_text[e.type] : t.dictionary.file_blocks.add_button_text.file, o.appendChild(s);
2089
- const a = (c) => {
2090
- c.preventDefault();
2091
- }, i = () => {
2092
- t.transact(
2093
- (c) => c.setMeta(t.filePanel.plugins[0], {
2094
- block: e
2095
- })
2096
- );
2097
- };
2098
- return o.addEventListener(
2099
- "mousedown",
2100
- a,
2101
- !0
2102
- ), o.addEventListener("click", i, !0), {
2103
- dom: o,
2104
- destroy: () => {
2105
- o.removeEventListener(
2106
- "mousedown",
2107
- a,
2108
- !0
2109
- ), o.removeEventListener(
2110
- "click",
2111
- i,
2112
- !0
2113
- );
2114
- }
2115
- };
2116
- }, gn = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>', bn = (e) => {
2117
- const t = document.createElement("div");
2118
- t.className = "bn-file-name-with-icon";
2119
- const n = document.createElement("div");
2120
- n.className = "bn-file-icon", n.innerHTML = gn, t.appendChild(n);
2121
- const o = document.createElement("p");
2122
- return o.className = "bn-file-name", o.textContent = e.props.name, t.appendChild(o), {
2123
- dom: t
2124
- };
2125
- }, we = (e, t, n, o) => {
2126
- const r = document.createElement("div");
2127
- if (r.className = "bn-file-block-content-wrapper", e.props.url === "") {
2128
- const a = mn(e, t, o);
2129
- r.appendChild(a.dom);
2130
- const i = t.onUploadStart((c) => {
2131
- if (c === e.id) {
2132
- r.removeChild(a.dom);
2133
- const l = document.createElement("div");
2134
- l.className = "bn-file-loading-preview", l.textContent = "Loading...", r.appendChild(l);
2135
- }
2136
- });
2137
- return {
2138
- dom: r,
2139
- destroy: () => {
2140
- i(), a.destroy();
2141
- }
2142
- };
2143
- }
2144
- const s = { dom: r };
2145
- if (e.props.showPreview === !1 || !n) {
2146
- const a = bn(e);
2147
- r.appendChild(a.dom), s.destroy = () => {
2148
- var i;
2149
- (i = a.destroy) == null || i.call(a);
2150
- };
2151
- } else
2152
- r.appendChild(n.dom);
2153
- if (e.props.caption) {
2154
- const a = document.createElement("p");
2155
- a.className = "bn-file-caption", a.textContent = e.props.caption, r.appendChild(a);
2156
- }
2157
- return s;
2158
- }, ve = (e, t) => {
2159
- const n = document.createElement("figure"), o = document.createElement("figcaption");
2160
- return o.textContent = t, n.appendChild(e), n.appendChild(o), { dom: n };
2161
- }, te = (e, t) => {
2162
- const n = document.createElement("div"), o = document.createElement("p");
2163
- return o.textContent = t, n.appendChild(e), n.appendChild(o), {
2164
- dom: n
2165
- };
2166
- }, He = (e) => ({ url: e.src || void 0 }), kn = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 16.0001H5.88889L11.1834 20.3319C11.2727 20.405 11.3846 20.4449 11.5 20.4449C11.7761 20.4449 12 20.2211 12 19.9449V4.05519C12 3.93977 11.9601 3.8279 11.887 3.73857C11.7121 3.52485 11.3971 3.49335 11.1834 3.66821L5.88889 8.00007H2C1.44772 8.00007 1 8.44778 1 9.00007V15.0001C1 15.5524 1.44772 16.0001 2 16.0001ZM23 12C23 15.292 21.5539 18.2463 19.2622 20.2622L17.8445 18.8444C19.7758 17.1937 21 14.7398 21 12C21 9.26016 19.7758 6.80629 17.8445 5.15557L19.2622 3.73779C21.5539 5.75368 23 8.70795 23 12ZM18 12C18 10.0883 17.106 8.38548 15.7133 7.28673L14.2842 8.71584C15.3213 9.43855 16 10.64 16 12C16 13.36 15.3213 14.5614 14.2842 15.2841L15.7133 16.7132C17.106 15.6145 18 13.9116 18 12Z"></path></svg>', Cn = (e) => ({
2167
- type: "audio",
2168
- propSchema: {
2169
- backgroundColor: C.backgroundColor,
2170
- // File name.
2171
- name: {
2172
- default: ""
2173
- },
2174
- // File url.
2175
- url: {
2176
- default: ""
2177
- },
2178
- // File caption.
2179
- caption: {
2180
- default: ""
2181
- },
2182
- showPreview: {
2183
- default: !0
2184
- }
2185
- },
2186
- content: "none"
2187
- }), yn = (e = {}) => (t) => {
2188
- if (t.tagName === "AUDIO") {
2189
- if (t.closest("figure"))
2190
- return;
2191
- const { backgroundColor: n } = B(t);
2192
- return {
2193
- ...He(t),
2194
- backgroundColor: n
2195
- };
2196
- }
2197
- if (t.tagName === "FIGURE") {
2198
- const n = ee(t, "audio");
2199
- if (!n)
2200
- return;
2201
- const { targetElement: o, caption: r } = n, { backgroundColor: s } = B(t);
2202
- return {
2203
- ...He(o),
2204
- backgroundColor: s,
2205
- caption: r
2206
- };
2207
- }
2208
- }, wn = (e = {}) => (t, n) => {
2209
- const o = document.createElement("div");
2210
- o.innerHTML = e.icon ?? kn;
2211
- const r = document.createElement("audio");
2212
- return r.className = "bn-audio", n.resolveFileUrl ? n.resolveFileUrl(t.props.url).then((s) => {
2213
- r.src = s;
2214
- }) : r.src = t.props.url, r.controls = !0, r.contentEditable = "false", r.draggable = !1, we(
2215
- t,
2216
- n,
2217
- { dom: r },
2218
- o.firstElementChild
2219
- );
2220
- }, vn = (e = {}) => (t, n) => {
2221
- if (!t.props.url) {
2222
- const r = document.createElement("p");
2223
- return r.textContent = "Add audio", {
2224
- dom: r
2225
- };
2226
- }
2227
- let o;
2228
- return t.props.showPreview ? (o = document.createElement("audio"), o.src = t.props.url) : (o = document.createElement("a"), o.href = t.props.url, o.textContent = t.props.name || t.props.url), t.props.caption ? t.props.showPreview ? ve(o, t.props.caption) : te(o, t.props.caption) : {
2229
- dom: o
2230
- };
2231
- }, En = M(
2232
- Cn,
2233
- (e) => ({
2234
- meta: {
2235
- fileBlockAccept: ["audio/*"]
2236
- },
2237
- parse: yn(e),
2238
- render: wn(e),
2239
- toExternalHTML: vn(e),
2240
- runsBefore: ["file"]
2241
- })
2242
- );
2243
- class xn {
2244
- constructor() {
2245
- // eslint-disable-next-line @typescript-eslint/ban-types
2246
- x(this, "callbacks", {});
2247
- }
2248
- on(t, n) {
2249
- return this.callbacks[t] || (this.callbacks[t] = []), this.callbacks[t].push(n), () => this.off(t, n);
2250
- }
2251
- emit(t, ...n) {
2252
- const o = this.callbacks[t];
2253
- o && o.forEach((r) => r.apply(this, n));
2254
- }
2255
- off(t, n) {
2256
- const o = this.callbacks[t];
2257
- o && (n ? this.callbacks[t] = o.filter((r) => r !== n) : delete this.callbacks[t]);
2258
- }
2259
- removeAllListeners() {
2260
- this.callbacks = {};
2261
- }
2262
- }
2263
- class Sn extends xn {
2264
- // eslint-disable-next-line
2265
- constructor(...n) {
2266
- super();
2267
- x(this, "plugins", []);
2268
- /**
2269
- * Input rules for the block
2270
- */
2271
- x(this, "inputRules");
2272
- /**
2273
- * A mapping of a keyboard shortcut to a function that will be called when the shortcut is pressed
2274
- *
2275
- * The keys are in the format:
2276
- * - Key names may be strings like `Shift-Ctrl-Enter`—a key identifier prefixed with zero or more modifiers
2277
- * - Key identifiers are based on the strings that can appear in KeyEvent.key
2278
- * - Use lowercase letters to refer to letter keys (or uppercase letters if you want shift to be held)
2279
- * - You may use `Space` as an alias for the " " name
2280
- * - Modifiers can be given in any order: `Shift-` (or `s-`), `Alt-` (or `a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or `Meta-`)
2281
- * - For characters that are created by holding shift, the Shift- prefix is implied, and should not be added explicitly
2282
- * - You can use Mod- as a shorthand for Cmd- on Mac and Ctrl- on other platforms
2283
- *
2284
- * @example
2285
- * ```typescript
2286
- * keyboardShortcuts: {
2287
- * "Mod-Enter": (ctx) => { return true; },
2288
- * "Shift-Ctrl-Space": (ctx) => { return true; },
2289
- * "a": (ctx) => { return true; },
2290
- * "Space": (ctx) => { return true; }
2291
- * }
2292
- * ```
2293
- */
2294
- x(this, "keyboardShortcuts");
2295
- x(this, "tiptapExtensions");
2296
- }
2297
- static key() {
2298
- throw new Error("You must implement the key method in your extension");
2299
- }
2300
- addProsemirrorPlugin(n) {
2301
- this.plugins.push(n);
2302
- }
2303
- get priority() {
2304
- }
2305
- }
2306
- function L(e) {
2307
- const t = Object.create(Sn.prototype);
2308
- return t.key = e.key, t.inputRules = e.inputRules, t.keyboardShortcuts = e.keyboardShortcuts, t.plugins = e.plugins ?? [], t.tiptapExtensions = e.tiptapExtensions, t;
2309
- }
2310
- const Oe = Symbol.for("blocknote.shikiParser"), re = Symbol.for(
2311
- "blocknote.shikiHighlighterPromise"
2312
- );
2313
- function Bn(e) {
2314
- const t = globalThis;
2315
- let n, o, r = !1;
2316
- return It({
2317
- parser: (a) => {
2318
- if (!e.createHighlighter)
2319
- return process.env.NODE_ENV === "development" && !r && (console.log(
2320
- "For syntax highlighting of code blocks, you must provide a `createCodeBlockSpec({ createHighlighter: () => ... })` function"
2321
- ), r = !0), [];
2322
- if (!n)
2323
- return t[re] = t[re] || e.createHighlighter(), t[re].then(
2324
- (c) => {
2325
- n = c;
2326
- }
2327
- );
2328
- const i = rt(e, a.language);
2329
- return !i || i === "text" || i === "none" || i === "plaintext" || i === "txt" ? [] : n.getLoadedLanguages().includes(i) ? (o || (o = t[Oe] || Pt(n), t[Oe] = o), o(a)) : n.loadLanguage(i);
2330
- },
2331
- languageExtractor: (a) => a.attrs.language,
2332
- nodeTypes: ["codeBlock"]
2333
- });
2334
- }
2335
- const Mn = ({ defaultLanguage: e = "text" }) => ({
2336
- type: "codeBlock",
2337
- propSchema: {
2338
- language: {
2339
- default: e
2340
- }
2341
- },
2342
- content: "inline"
2343
- }), Ln = M(
2344
- Mn,
2345
- (e) => ({
2346
- meta: {
2347
- code: !0,
2348
- defining: !0,
2349
- isolating: !1
2350
- },
2351
- parse: (t) => {
2352
- var r, s;
2353
- if (t.tagName !== "PRE" || t.childElementCount !== 1 || ((r = t.firstElementChild) == null ? void 0 : r.tagName) !== "CODE")
2354
- return;
2355
- const n = t.firstElementChild;
2356
- return { language: n.getAttribute("data-language") || ((s = n.className.split(" ").find((a) => a.includes("language-"))) == null ? void 0 : s.replace("language-", "")) };
2357
- },
2358
- parseContent: ({ el: t, schema: n }) => {
2359
- const o = Q.fromSchema(n), r = t.firstElementChild;
2360
- return o.parse(r, {
2361
- topNode: n.nodes.codeBlock.create()
2362
- }).content;
2363
- },
2364
- render(t, n) {
2365
- const o = document.createDocumentFragment(), r = document.createElement("pre"), s = document.createElement("code");
2366
- r.appendChild(s);
2367
- let a;
2368
- if (e.supportedLanguages) {
2369
- const i = document.createElement("select");
2370
- Object.entries(e.supportedLanguages ?? {}).forEach(
2371
- ([d, { name: u }]) => {
2372
- const p = document.createElement("option");
2373
- p.value = d, p.text = u, i.appendChild(p);
2374
- }
2375
- ), i.value = t.props.language || e.defaultLanguage || "text";
2376
- const c = (d) => {
2377
- const u = d.target.value;
2378
- n.updateBlock(t.id, { props: { language: u } });
2379
- };
2380
- i.addEventListener("change", c), a = () => i.removeEventListener("change", c);
2381
- const l = document.createElement("div");
2382
- l.contentEditable = "false", l.appendChild(i), o.appendChild(l);
2383
- }
2384
- return o.appendChild(r), {
2385
- dom: o,
2386
- contentDOM: s,
2387
- destroy: () => {
2388
- a == null || a();
2389
- }
2390
- };
2391
- },
2392
- toExternalHTML(t) {
2393
- const n = document.createElement("pre"), o = document.createElement("code");
2394
- return o.className = `language-${t.props.language}`, o.dataset.language = t.props.language, n.appendChild(o), {
2395
- dom: n,
2396
- contentDOM: o
2397
- };
2398
- }
2399
- }),
2400
- (e) => [
2401
- L({
2402
- key: "code-block-highlighter",
2403
- plugins: [Bn(e)]
2404
- }),
2405
- L({
2406
- key: "code-block-keyboard-shortcuts",
2407
- keyboardShortcuts: {
2408
- Delete: ({ editor: t }) => t.transact((n) => {
2409
- const { block: o } = t.getTextCursorPosition();
2410
- if (o.type !== "codeBlock")
2411
- return !1;
2412
- const { $from: r } = n.selection;
2413
- return r.parent.textContent ? !1 : (t.removeBlocks([o]), !0);
2414
- }),
2415
- Tab: ({ editor: t }) => e.indentLineWithTab === !1 ? !1 : t.transact((n) => {
2416
- const { block: o } = t.getTextCursorPosition();
2417
- return o.type === "codeBlock" ? (n.insertText(" "), !0) : !1;
2418
- }),
2419
- Enter: ({ editor: t }) => t.transact((n) => {
2420
- const { block: o, nextBlock: r } = t.getTextCursorPosition();
2421
- if (o.type !== "codeBlock")
2422
- return !1;
2423
- const { $from: s } = n.selection, a = s.parentOffset === s.parent.nodeSize - 2, i = s.parent.textContent.endsWith(`
2424
-
2425
- `);
2426
- if (a && i) {
2427
- if (n.delete(s.pos - 2, s.pos), r)
2428
- return t.setTextCursorPosition(r, "start"), !0;
2429
- const [c] = t.insertBlocks(
2430
- [{ type: "paragraph" }],
2431
- o,
2432
- "after"
2433
- );
2434
- return t.setTextCursorPosition(c, "start"), !0;
2435
- }
2436
- return n.insertText(`
2437
- `), !0;
2438
- }),
2439
- "Shift-Enter": ({ editor: t }) => t.transact(() => {
2440
- const { block: n } = t.getTextCursorPosition();
2441
- if (n.type !== "codeBlock")
2442
- return !1;
2443
- const [o] = t.insertBlocks(
2444
- // insert a new paragraph
2445
- [{ type: "paragraph" }],
2446
- n,
2447
- "after"
2448
- );
2449
- return t.setTextCursorPosition(o, "start"), !0;
2450
- })
2451
- },
2452
- inputRules: [
2453
- {
2454
- find: /^```(.*?)\s$/,
2455
- replace: ({ match: t }) => {
2456
- const n = t[1].trim();
2457
- return {
2458
- type: "codeBlock",
2459
- props: {
2460
- language: {
2461
- language: rt(e, n) ?? n
2462
- }.language
2463
- },
2464
- content: []
2465
- };
2466
- }
2467
- }
2468
- ]
2469
- })
2470
- ]
2471
- );
2472
- function rt(e, t) {
2473
- var n;
2474
- return (n = Object.entries(e.supportedLanguages ?? {}).find(
2475
- ([o, { aliases: r }]) => (r == null ? void 0 : r.includes(t)) || o === t
2476
- )) == null ? void 0 : n[0];
2477
- }
2478
- const Tn = () => ({
2479
- type: "divider",
2480
- propSchema: {},
2481
- content: "none"
2482
- }), An = M(
2483
- Tn,
2484
- {
2485
- meta: {
2486
- isolating: !1
2487
- },
2488
- parse(e) {
2489
- if (e.tagName === "HR")
2490
- return {};
2491
- },
2492
- render() {
2493
- return {
2494
- dom: document.createElement("hr")
2495
- };
2496
- }
2497
- },
2498
- [
2499
- L({
2500
- key: "divider-block-shortcuts",
2501
- inputRules: [
2502
- {
2503
- find: new RegExp("^---$"),
2504
- replace() {
2505
- return { type: "divider", props: {}, content: [] };
2506
- }
2507
- }
2508
- ]
2509
- })
2510
- ]
2511
- ), De = (e) => ({ url: e.src || void 0 }), Nn = () => ({
2512
- type: "file",
2513
- propSchema: {
2514
- backgroundColor: C.backgroundColor,
2515
- // File name.
2516
- name: {
2517
- default: ""
2518
- },
2519
- // File url.
2520
- url: {
2521
- default: ""
2522
- },
2523
- // File caption.
2524
- caption: {
2525
- default: ""
2526
- }
2527
- },
2528
- content: "none"
2529
- }), In = () => (e) => {
2530
- if (e.tagName === "EMBED") {
2531
- if (e.closest("figure"))
2532
- return;
2533
- const { backgroundColor: t } = B(e);
2534
- return {
2535
- ...De(e),
2536
- backgroundColor: t
2537
- };
2538
- }
2539
- if (e.tagName === "FIGURE") {
2540
- const t = ee(e, "embed");
2541
- if (!t)
2542
- return;
2543
- const { targetElement: n, caption: o } = t, { backgroundColor: r } = B(e);
2544
- return {
2545
- ...De(n),
2546
- backgroundColor: r,
2547
- caption: o
2548
- };
2549
- }
2550
- }, Pn = M(Nn, {
2551
- meta: {
2552
- fileBlockAccept: ["*/*"]
2553
- },
2554
- parse: In(),
2555
- render(e, t) {
2556
- return we(e, t);
2557
- },
2558
- toExternalHTML(e) {
2559
- if (!e.props.url) {
2560
- const n = document.createElement("p");
2561
- return n.textContent = "Add file", {
2562
- dom: n
2563
- };
2564
- }
2565
- const t = document.createElement("a");
2566
- return t.href = e.props.url, t.textContent = e.props.name || e.props.url, e.props.caption ? te(t, e.props.caption) : {
2567
- dom: t
2568
- };
2569
- }
2570
- }), Hn = {
2571
- set: (e, t) => window.localStorage.setItem(
2572
- `toggle-${e.id}`,
2573
- t ? "true" : "false"
2574
- ),
2575
- get: (e) => window.localStorage.getItem(`toggle-${e.id}`) === "true"
2576
- }, st = (e, t, n, o = Hn) => {
2577
- if ("isToggleable" in e.props && !e.props.isToggleable)
2578
- return {
2579
- dom: n
2580
- };
2581
- const r = document.createElement("div"), s = document.createElement("div");
2582
- s.className = "bn-toggle-wrapper";
2583
- const a = document.createElement("button");
2584
- a.className = "bn-toggle-button", a.type = "button", a.innerHTML = // https://fonts.google.com/icons?selected=Material+Symbols+Rounded:chevron_right:FILL@0;wght@700;GRAD@0;opsz@24&icon.query=chevron&icon.style=Rounded&icon.size=24&icon.color=%23e8eaed
2585
- '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="CURRENTCOLOR"><path d="M320-200v-560l440 280-440 280Z"/></svg>';
2586
- const i = (h) => h.preventDefault();
2587
- a.addEventListener("mousedown", i);
2588
- const c = () => {
2589
- var h;
2590
- s.getAttribute("data-show-children") === "true" ? (s.setAttribute("data-show-children", "false"), o.set(t.getBlock(e), !1), r.contains(l) && r.removeChild(l)) : (s.setAttribute("data-show-children", "true"), o.set(t.getBlock(e), !0), ((h = t.getBlock(e)) == null ? void 0 : h.children.length) === 0 && !r.contains(l) && r.appendChild(l));
2591
- };
2592
- a.addEventListener("click", c), s.appendChild(a), s.appendChild(n);
2593
- const l = document.createElement("button");
2594
- l.className = "bn-toggle-add-block-button", l.type = "button", l.textContent = t.dictionary.toggle_blocks.add_block_button;
2595
- const d = (h) => h.preventDefault();
2596
- l.addEventListener(
2597
- "mousedown",
2598
- d
2599
- );
2600
- const u = () => {
2601
- t.transact(() => {
2602
- const h = t.updateBlock(e, {
2603
- // Single empty block with default type.
2604
- children: [{}]
2605
- });
2606
- t.setTextCursorPosition(h.children[0].id, "end"), t.focus();
2607
- });
2608
- };
2609
- l.addEventListener("click", u), r.appendChild(s);
2610
- let p = e.children.length;
2611
- const f = t.onChange(() => {
2612
- var k;
2613
- const h = ((k = t.getBlock(e)) == null ? void 0 : k.children.length) ?? 0;
2614
- h > p ? (s.getAttribute("data-show-children") === "false" && (s.setAttribute("data-show-children", "true"), o.set(t.getBlock(e), !0)), r.contains(l) && r.removeChild(l)) : h === 0 && h < p && (s.getAttribute("data-show-children") === "true" && (s.setAttribute("data-show-children", "false"), o.set(t.getBlock(e), !1)), r.contains(l) && r.removeChild(l)), p = h;
2615
- });
2616
- return o.get(e) ? (s.setAttribute("data-show-children", "true"), e.children.length === 0 && r.appendChild(l)) : s.setAttribute("data-show-children", "false"), {
2617
- dom: r,
2618
- // Prevents re-renders when the toggle button is clicked.
2619
- ignoreMutation: (h) => h instanceof MutationRecord && // We want to prevent re-renders when the view changes, so we ignore
2620
- // all mutations where the `data-show-children` attribute is changed
2621
- // or the "add block" button is added/removed.
2622
- (h.type === "attributes" && h.target === s && h.attributeName === "data-show-children" || h.type === "childList" && (h.addedNodes[0] === l || h.removedNodes[0] === l)),
2623
- destroy: () => {
2624
- a.removeEventListener("mousedown", i), a.removeEventListener("click", c), l.removeEventListener(
2625
- "mousedown",
2626
- d
2627
- ), l.removeEventListener(
2628
- "click",
2629
- u
2630
- ), f == null || f();
2631
- }
2632
- };
2633
- }, at = [1, 2, 3, 4, 5, 6], On = ({
2634
- defaultLevel: e = 1,
2635
- levels: t = at,
2636
- allowToggleHeadings: n = !0
2637
- } = {}) => ({
2638
- type: "heading",
2639
- propSchema: {
2640
- ...C,
2641
- level: { default: e, values: t },
2642
- ...n ? { isToggleable: { default: !1, optional: !0 } } : {}
2643
- },
2644
- content: "inline"
2645
- }), Dn = M(
2646
- On,
2647
- ({ allowToggleHeadings: e = !0 } = {}) => ({
2648
- meta: {
2649
- isolating: !1
2650
- },
2651
- parse(t) {
2652
- let n;
2653
- switch (t.tagName) {
2654
- case "H1":
2655
- n = 1;
2656
- break;
2657
- case "H2":
2658
- n = 2;
2659
- break;
2660
- case "H3":
2661
- n = 3;
2662
- break;
2663
- case "H4":
2664
- n = 4;
2665
- break;
2666
- case "H5":
2667
- n = 5;
2668
- break;
2669
- case "H6":
2670
- n = 6;
2671
- break;
2672
- default:
2673
- return;
2674
- }
2675
- return {
2676
- ...B(t),
2677
- level: n
2678
- };
2679
- },
2680
- render(t, n) {
2681
- const o = document.createElement(`h${t.props.level}`);
2682
- return e ? { ...st(t, n, o), contentDOM: o } : {
2683
- dom: o,
2684
- contentDOM: o
2685
- };
2686
- },
2687
- toExternalHTML(t) {
2688
- const n = document.createElement(`h${t.props.level}`);
2689
- return H(t.props, n), {
2690
- dom: n,
2691
- contentDOM: n
2692
- };
2693
- }
2694
- }),
2695
- ({ levels: e = at } = {}) => [
2696
- L({
2697
- key: "heading-shortcuts",
2698
- keyboardShortcuts: Object.fromEntries(
2699
- e.map((t) => [
2700
- `Mod-Alt-${t}`,
2701
- ({ editor: n }) => {
2702
- const o = n.getTextCursorPosition();
2703
- return n.schema.blockSchema[o.block.type].content !== "inline" ? !1 : (n.updateBlock(o.block, {
2704
- type: "heading",
2705
- props: {
2706
- level: t
2707
- }
2708
- }), !0);
2709
- }
2710
- ]) ?? []
2711
- ),
2712
- inputRules: e.map((t) => ({
2713
- find: new RegExp(`^(#{${t}})\\s$`),
2714
- replace({ match: n }) {
2715
- return {
2716
- type: "heading",
2717
- props: {
2718
- level: n[1].length
2719
- }
2720
- };
2721
- }
2722
- }))
2723
- })
2724
- ]
2725
- ), it = (e, t, n, o, r) => {
2726
- const { dom: s, destroy: a } = we(
2727
- e,
2728
- t,
2729
- n,
2730
- r
2731
- ), i = s;
2732
- i.style.position = "relative", e.props.url && e.props.showPreview && (e.props.previewWidth ? i.style.width = `${e.props.previewWidth}px` : i.style.width = "fit-content");
2733
- const c = document.createElement("div");
2734
- c.className = "bn-resize-handle", c.style.left = "4px";
2735
- const l = document.createElement("div");
2736
- l.className = "bn-resize-handle", l.style.right = "4px";
2737
- const d = document.createElement("div");
2738
- d.style.position = "absolute", d.style.height = "100%", d.style.width = "100%";
2739
- let u, p = e.props.previewWidth;
2740
- const f = (g) => {
2741
- var V, W;
2742
- if (!u) {
2743
- !t.isEditable && o.contains(c) && o.contains(l) && (o.removeChild(c), o.removeChild(l));
2744
- return;
2745
- }
2746
- let v;
2747
- const S = "touches" in g ? g.touches[0].clientX : g.clientX;
2748
- e.props.textAlignment === "center" ? u.handleUsed === "left" ? v = u.initialWidth + (u.initialClientX - S) * 2 : v = u.initialWidth + (S - u.initialClientX) * 2 : u.handleUsed === "left" ? v = u.initialWidth + u.initialClientX - S : v = u.initialWidth + S - u.initialClientX, p = Math.min(
2749
- Math.max(v, 64),
2750
- ((W = (V = t.domElement) == null ? void 0 : V.firstElementChild) == null ? void 0 : W.clientWidth) || Number.MAX_VALUE
2751
- ), i.style.width = `${p}px`;
2752
- }, h = (g) => {
2753
- (!g.target || !i.contains(g.target) || !t.isEditable) && o.contains(c) && o.contains(l) && (o.removeChild(c), o.removeChild(l)), u && (u = void 0, i.contains(d) && i.removeChild(d), t.updateBlock(e, {
2754
- props: {
2755
- previewWidth: p
2756
- }
2757
- }));
2758
- }, k = () => {
2759
- t.isEditable && (o.appendChild(c), o.appendChild(l));
2760
- }, m = (g) => {
2761
- g.relatedTarget === c || g.relatedTarget === l || u || t.isEditable && o.contains(c) && o.contains(l) && (o.removeChild(c), o.removeChild(l));
2762
- }, b = (g) => {
2763
- g.preventDefault(), i.contains(d) || i.appendChild(d);
2764
- const v = "touches" in g ? g.touches[0].clientX : g.clientX;
2765
- u = {
2766
- handleUsed: "left",
2767
- initialWidth: i.clientWidth,
2768
- initialClientX: v
2769
- };
2770
- }, y = (g) => {
2771
- g.preventDefault(), i.contains(d) || i.appendChild(d);
2772
- const v = "touches" in g ? g.touches[0].clientX : g.clientX;
2773
- u = {
2774
- handleUsed: "right",
2775
- initialWidth: i.clientWidth,
2776
- initialClientX: v
2777
- };
2778
- };
2779
- return window.addEventListener("mousemove", f), window.addEventListener("touchmove", f), window.addEventListener("mouseup", h), window.addEventListener("touchend", h), i.addEventListener("mouseenter", k), i.addEventListener("mouseleave", m), c.addEventListener(
2780
- "mousedown",
2781
- b
2782
- ), c.addEventListener(
2783
- "touchstart",
2784
- b
2785
- ), l.addEventListener(
2786
- "mousedown",
2787
- y
2788
- ), l.addEventListener(
2789
- "touchstart",
2790
- y
2791
- ), {
2792
- dom: i,
2793
- destroy: () => {
2794
- a == null || a(), window.removeEventListener("mousemove", f), window.removeEventListener("touchmove", f), window.removeEventListener("mouseup", h), window.removeEventListener("touchend", h), i.removeEventListener("mouseenter", k), i.removeEventListener("mouseleave", m), c.removeEventListener(
2795
- "mousedown",
2796
- b
2797
- ), c.removeEventListener(
2798
- "touchstart",
2799
- b
2800
- ), l.removeEventListener(
2801
- "mousedown",
2802
- y
2803
- ), l.removeEventListener(
2804
- "touchstart",
2805
- y
2806
- );
2807
- }
2808
- };
2809
- }, _e = (e) => {
2810
- const t = e.src || void 0, n = e.width || void 0, o = e.alt || void 0;
2811
- return { url: t, previewWidth: n, name: o };
2812
- }, _n = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M5 11.1005L7 9.1005L12.5 14.6005L16 11.1005L19 14.1005V5H5V11.1005ZM4 3H20C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3ZM15.5 10C14.6716 10 14 9.32843 14 8.5C14 7.67157 14.6716 7 15.5 7C16.3284 7 17 7.67157 17 8.5C17 9.32843 16.3284 10 15.5 10Z"></path></svg>', Rn = (e = {}) => ({
2813
- type: "image",
2814
- propSchema: {
2815
- textAlignment: C.textAlignment,
2816
- backgroundColor: C.backgroundColor,
2817
- // File name.
2818
- name: {
2819
- default: ""
2820
- },
2821
- // File url.
2822
- url: {
2823
- default: ""
2824
- },
2825
- // File caption.
2826
- caption: {
2827
- default: ""
2828
- },
2829
- showPreview: {
2830
- default: !0
2831
- },
2832
- // File preview width in px.
2833
- previewWidth: {
2834
- default: void 0,
2835
- type: "number"
2836
- }
2837
- },
2838
- content: "none"
2839
- }), Vn = (e = {}) => (t) => {
2840
- if (t.tagName === "IMG") {
2841
- if (t.closest("figure"))
2842
- return;
2843
- const { backgroundColor: n } = B(t);
2844
- return {
2845
- ..._e(t),
2846
- backgroundColor: n
2847
- };
2848
- }
2849
- if (t.tagName === "FIGURE") {
2850
- const n = ee(t, "img");
2851
- if (!n)
2852
- return;
2853
- const { targetElement: o, caption: r } = n, { backgroundColor: s } = B(t);
2854
- return {
2855
- ..._e(o),
2856
- backgroundColor: s,
2857
- caption: r
2858
- };
2859
- }
2860
- }, Wn = (e = {}) => (t, n) => {
2861
- const o = document.createElement("div");
2862
- o.innerHTML = e.icon ?? _n;
2863
- const r = document.createElement("div");
2864
- r.className = "bn-visual-media-wrapper";
2865
- const s = document.createElement("img");
2866
- return s.className = "bn-visual-media", n.resolveFileUrl ? n.resolveFileUrl(t.props.url).then((a) => {
2867
- s.src = a;
2868
- }) : s.src = t.props.url, s.alt = t.props.name || t.props.caption || "BlockNote image", s.contentEditable = "false", s.draggable = !1, r.appendChild(s), it(
2869
- t,
2870
- n,
2871
- { dom: r },
2872
- r,
2873
- o.firstElementChild
2874
- );
2875
- }, Fn = (e = {}) => (t, n) => {
2876
- if (!t.props.url) {
2877
- const r = document.createElement("p");
2878
- return r.textContent = "Add image", {
2879
- dom: r
2880
- };
2881
- }
2882
- let o;
2883
- return t.props.showPreview ? (o = document.createElement("img"), o.src = t.props.url, o.alt = t.props.name || t.props.caption || "BlockNote image", t.props.previewWidth && (o.width = t.props.previewWidth)) : (o = document.createElement("a"), o.href = t.props.url, o.textContent = t.props.name || t.props.url), t.props.caption ? t.props.showPreview ? ve(o, t.props.caption) : te(o, t.props.caption) : {
2884
- dom: o
2885
- };
2886
- }, $n = M(
2887
- Rn,
2888
- (e) => ({
2889
- meta: {
2890
- fileBlockAccept: ["image/*"]
2891
- },
2892
- parse: Vn(e),
2893
- render: Wn(e),
2894
- toExternalHTML: Fn(e),
2895
- runsBefore: ["file"]
2896
- })
2897
- ), cr = (e, t, n) => ({
2898
- state: o,
2899
- dispatch: r
2900
- }) => r ? ct(o.tr, e, t, n) : !0, ct = (e, t, n, o) => {
2901
- const r = fe(e.doc, t), s = z(r);
2902
- if (!s.isBlockContainer)
2903
- return !1;
2904
- const a = G(e), i = [
2905
- {
2906
- type: s.bnBlock.node.type,
2907
- // always keep blockcontainer type
2908
- attrs: o ? { ...s.bnBlock.node.attrs, id: void 0 } : {}
2909
- },
2910
- {
2911
- type: n ? s.blockContent.node.type : a.nodes.paragraph,
2912
- attrs: o ? { ...s.blockContent.node.attrs } : {}
2913
- }
2914
- ];
2915
- return e.split(t, 2, i), !0;
2916
- }, ne = (e, t) => {
2917
- const { blockInfo: n, selectionEmpty: o } = e.transact((a) => ({
2918
- blockInfo: Gt(a),
2919
- selectionEmpty: a.selection.anchor === a.selection.head
2920
- }));
2921
- if (!n.isBlockContainer)
2922
- return !1;
2923
- const { bnBlock: r, blockContent: s } = n;
2924
- return s.node.type.name !== t || !o ? !1 : s.node.childCount === 0 ? (e.transact((a) => {
2925
- ye(a, r.beforePos, {
2926
- type: "paragraph",
2927
- props: {}
2928
- });
2929
- }), !0) : s.node.childCount > 0 ? e.transact((a) => (a.deleteSelection(), ct(a, a.selection.from, !0))) : !1;
2930
- };
2931
- function Ee(e, t, n) {
2932
- var u, p, f;
2933
- const o = Q.fromSchema(t), r = e, s = document.createElement("div");
2934
- s.setAttribute("data-node-type", "blockGroup");
2935
- for (const h of Array.from(r.childNodes))
2936
- s.appendChild(h.cloneNode(!0));
2937
- let a = o.parse(s, {
2938
- topNode: t.nodes.blockGroup.create()
2939
- });
2940
- ((p = (u = a.firstChild) == null ? void 0 : u.firstChild) == null ? void 0 : p.type.name) === "checkListItem" && (a = a.copy(
2941
- a.content.cut(
2942
- a.firstChild.firstChild.nodeSize + 2
2943
- )
2944
- ));
2945
- const i = (f = a.firstChild) == null ? void 0 : f.firstChild;
2946
- if (!(i != null && i.isTextblock))
2947
- return _.from(a);
2948
- const c = t.nodes[n].create(
2949
- {},
2950
- i.content
2951
- ), l = a.content.cut(
2952
- // +2 for the `blockGroup` node's start and end markers
2953
- i.nodeSize + 2
2954
- );
2955
- if (l.size > 0) {
2956
- const h = a.copy(l);
2957
- return c.content.addToEnd(h);
2958
- }
2959
- return c.content;
2960
- }
2961
- const jn = () => ({
2962
- type: "bulletListItem",
2963
- propSchema: {
2964
- ...C
2965
- },
2966
- content: "inline"
2967
- }), Un = M(
2968
- jn,
2969
- {
2970
- meta: {
2971
- isolating: !1
2972
- },
2973
- parse(e) {
2974
- var n;
2975
- if (e.tagName !== "LI")
2976
- return;
2977
- const t = e.parentElement;
2978
- if (t !== null && (t.tagName === "UL" || t.tagName === "DIV" && ((n = t.parentElement) == null ? void 0 : n.tagName) === "UL"))
2979
- return B(e);
2980
- },
2981
- // As `li` elements can contain multiple paragraphs, we need to merge their contents
2982
- // into a single one so that ProseMirror can parse everything correctly.
2983
- parseContent: ({ el: e, schema: t }) => Ee(e, t, "bulletListItem"),
2984
- render() {
2985
- const e = document.createElement("p");
2986
- return {
2987
- dom: e,
2988
- contentDOM: e
2989
- };
2990
- },
2991
- toExternalHTML(e) {
2992
- const t = document.createElement("li"), n = document.createElement("p");
2993
- return H(e.props, t), t.appendChild(n), {
2994
- dom: t,
2995
- contentDOM: n
2996
- };
2997
- }
2998
- },
2999
- [
3000
- L({
3001
- key: "bullet-list-item-shortcuts",
3002
- keyboardShortcuts: {
3003
- Enter: ({ editor: e }) => ne(e, "bulletListItem"),
3004
- "Mod-Shift-8": ({ editor: e }) => {
3005
- const t = e.getTextCursorPosition();
3006
- return e.schema.blockSchema[t.block.type].content !== "inline" ? !1 : (e.updateBlock(t.block, {
3007
- type: "bulletListItem",
3008
- props: {}
3009
- }), !0);
3010
- }
3011
- },
3012
- inputRules: [
3013
- {
3014
- find: new RegExp("^[-+*]\\s$"),
3015
- replace({ editor: e }) {
3016
- if (Ge(
3017
- e.prosemirrorState
3018
- ).blockNoteType !== "heading")
3019
- return {
3020
- type: "bulletListItem",
3021
- props: {}
3022
- };
3023
- }
3024
- }
3025
- ]
3026
- })
3027
- ]
3028
- ), zn = () => ({
3029
- type: "checkListItem",
3030
- propSchema: {
3031
- ...C,
3032
- checked: { default: !1, type: "boolean" }
3033
- },
3034
- content: "inline"
3035
- }), qn = M(
3036
- zn,
3037
- {
3038
- meta: {
3039
- isolating: !1
3040
- },
3041
- parse(e) {
3042
- var n;
3043
- if (e.tagName === "input")
3044
- return e.closest("[data-content-type]") || e.closest("li") ? void 0 : e.type === "checkbox" ? { checked: e.checked } : void 0;
3045
- if (e.tagName !== "LI")
3046
- return;
3047
- const t = e.parentElement;
3048
- if (t !== null && (t.tagName === "UL" || t.tagName === "DIV" && ((n = t.parentElement) == null ? void 0 : n.tagName) === "UL")) {
3049
- const o = e.querySelector("input[type=checkbox]") || null;
3050
- return o === null ? void 0 : { ...B(e), checked: o.checked };
3051
- }
3052
- },
3053
- // As `li` elements can contain multiple paragraphs, we need to merge their contents
3054
- // into a single one so that ProseMirror can parse everything correctly.
3055
- parseContent: ({ el: e, schema: t }) => Ee(e, t, "checkListItem"),
3056
- render(e, t) {
3057
- const n = document.createDocumentFragment(), o = document.createElement("input");
3058
- o.type = "checkbox", o.checked = e.props.checked, e.props.checked && o.setAttribute("checked", ""), o.addEventListener("change", () => {
3059
- t.updateBlock(e, { props: { checked: !e.props.checked } });
3060
- });
3061
- const r = document.createElement("p");
3062
- return n.appendChild(o), n.appendChild(r), {
3063
- dom: n,
3064
- contentDOM: r
3065
- };
3066
- },
3067
- toExternalHTML(e) {
3068
- const t = document.createElement("li"), n = document.createElement("input");
3069
- n.type = "checkbox", n.checked = e.props.checked, e.props.checked && n.setAttribute("checked", "");
3070
- const o = document.createElement("p");
3071
- return H(e.props, t), t.appendChild(n), t.appendChild(o), {
3072
- dom: t,
3073
- contentDOM: o
3074
- };
3075
- },
3076
- runsBefore: ["bulletListItem"]
3077
- },
3078
- [
3079
- L({
3080
- key: "check-list-item-shortcuts",
3081
- keyboardShortcuts: {
3082
- Enter: ({ editor: e }) => ne(e, "checkListItem"),
3083
- "Mod-Shift-9": ({ editor: e }) => {
3084
- const t = e.getTextCursorPosition();
3085
- return e.schema.blockSchema[t.block.type].content !== "inline" ? !1 : (e.updateBlock(t.block, {
3086
- type: "checkListItem",
3087
- props: {}
3088
- }), !0);
3089
- }
3090
- },
3091
- inputRules: [
3092
- {
3093
- find: new RegExp("\\[\\s*\\]\\s$"),
3094
- replace() {
3095
- return {
3096
- type: "checkListItem",
3097
- props: {
3098
- checked: !1
3099
- },
3100
- content: []
3101
- };
3102
- }
3103
- },
3104
- {
3105
- find: new RegExp("\\[[Xx]\\]\\s$"),
3106
- replace() {
3107
- return {
3108
- type: "checkListItem",
3109
- props: {
3110
- checked: !0
3111
- }
3112
- };
3113
- }
3114
- }
3115
- ]
3116
- })
3117
- ]
3118
- );
3119
- function lt(e, t, n, o) {
3120
- let r = e.firstChild.attrs.start || 1, s = !0;
3121
- const a = !!e.firstChild.attrs.start, i = z({
3122
- posBeforeNode: t,
3123
- node: e
3124
- });
3125
- if (!i.isBlockContainer)
3126
- throw new Error("impossible");
3127
- const c = n.doc.resolve(i.bnBlock.beforePos).nodeBefore, l = c ? o.get(c) : void 0;
3128
- return l !== void 0 ? (r = l + 1, s = !1) : c && z({
3129
- posBeforeNode: i.bnBlock.beforePos - c.nodeSize,
3130
- node: c
3131
- }).blockNoteType === "numberedListItem" && (r = lt(
3132
- c,
3133
- i.bnBlock.beforePos - c.nodeSize,
3134
- n,
3135
- o
3136
- ).index + 1, s = !1), o.set(e, r), { index: r, isFirst: s, hasStart: a };
3137
- }
3138
- function Re(e, t) {
3139
- const n = /* @__PURE__ */ new Map(), o = t.decorations.map(
3140
- e.mapping,
3141
- e.doc
3142
- ), r = [];
3143
- e.doc.nodesBetween(0, e.doc.nodeSize - 2, (a, i) => {
3144
- if (a.type.name === "blockContainer" && a.firstChild.type.name === "numberedListItem") {
3145
- const { index: c, isFirst: l, hasStart: d } = lt(
3146
- a,
3147
- i,
3148
- e,
3149
- n
3150
- );
3151
- o.find(
3152
- i,
3153
- i + a.nodeSize,
3154
- (p) => p.index === c && p.isFirst === l && p.hasStart === d
3155
- ).length === 0 && r.push(
3156
- // move in by 1 to account for the block container
3157
- Ot.node(i + 1, i + a.nodeSize - 1, {
3158
- "data-index": c.toString()
3159
- })
3160
- );
3161
- }
3162
- });
3163
- const s = r.flatMap(
3164
- (a) => o.find(a.from, a.to)
3165
- );
3166
- return {
3167
- decorations: o.remove(s).add(e.doc, r)
3168
- };
3169
- }
3170
- const Zn = () => new je({
3171
- key: new Ue("numbered-list-indexing-decorations"),
3172
- state: {
3173
- init(e, t) {
3174
- return Re(t.tr, {
3175
- decorations: Me.empty
3176
- });
3177
- },
3178
- apply(e, t) {
3179
- return !e.docChanged && !e.selectionSet && t.decorations ? t : Re(e, t);
3180
- }
3181
- },
3182
- props: {
3183
- decorations(e) {
3184
- var t;
3185
- return ((t = this.getState(e)) == null ? void 0 : t.decorations) ?? Me.empty;
3186
- }
3187
- }
3188
- }), Gn = () => ({
3189
- type: "numberedListItem",
3190
- propSchema: {
3191
- ...C,
3192
- start: { default: void 0, type: "number" }
3193
- },
3194
- content: "inline"
3195
- }), Xn = M(
3196
- Gn,
3197
- {
3198
- meta: {
3199
- isolating: !1
3200
- },
3201
- parse(e) {
3202
- var n;
3203
- if (e.tagName !== "LI")
3204
- return;
3205
- const t = e.parentElement;
3206
- if (t !== null && (t.tagName === "OL" || t.tagName === "DIV" && ((n = t.parentElement) == null ? void 0 : n.tagName) === "OL")) {
3207
- const o = parseInt(t.getAttribute("start") || "1"), r = B(e);
3208
- return e.previousElementSibling || o === 1 ? r : {
3209
- ...r,
3210
- start: o
3211
- };
3212
- }
3213
- },
3214
- // As `li` elements can contain multiple paragraphs, we need to merge their contents
3215
- // into a single one so that ProseMirror can parse everything correctly.
3216
- parseContent: ({ el: e, schema: t }) => Ee(e, t, "numberedListItem"),
3217
- render() {
3218
- const e = document.createElement("p");
3219
- return {
3220
- dom: e,
3221
- contentDOM: e
3222
- };
3223
- },
3224
- toExternalHTML(e) {
3225
- const t = document.createElement("li"), n = document.createElement("p");
3226
- return H(e.props, t), t.appendChild(n), {
3227
- dom: t,
3228
- contentDOM: n
3229
- };
3230
- }
3231
- },
3232
- [
3233
- L({
3234
- key: "numbered-list-item-shortcuts",
3235
- inputRules: [
3236
- {
3237
- find: new RegExp("^(\\d+)\\.\\s$"),
3238
- replace({ match: e, editor: t }) {
3239
- if (Ge(
3240
- t.prosemirrorState
3241
- ).blockNoteType === "heading")
3242
- return;
3243
- const o = parseInt(e[1]);
3244
- return {
3245
- type: "numberedListItem",
3246
- props: {
3247
- start: o !== 1 ? o : void 0
3248
- }
3249
- };
3250
- }
3251
- }
3252
- ],
3253
- keyboardShortcuts: {
3254
- Enter: ({ editor: e }) => ne(e, "numberedListItem"),
3255
- "Mod-Shift-7": ({ editor: e }) => {
3256
- const t = e.getTextCursorPosition();
3257
- return e.schema.blockSchema[t.block.type].content !== "inline" ? !1 : (e.updateBlock(t.block, {
3258
- type: "numberedListItem",
3259
- props: {}
3260
- }), !0);
3261
- }
3262
- },
3263
- plugins: [Zn()]
3264
- })
3265
- ]
3266
- ), Jn = () => ({
3267
- type: "toggleListItem",
3268
- propSchema: {
3269
- ...C
3270
- },
3271
- content: "inline"
3272
- }), Kn = M(
3273
- Jn,
3274
- {
3275
- meta: {
3276
- isolating: !1
3277
- },
3278
- render(e, t) {
3279
- const n = document.createElement("p");
3280
- return { ...st(
3281
- e,
3282
- t,
3283
- n
3284
- ), contentDOM: n };
3285
- },
3286
- toExternalHTML(e) {
3287
- const t = document.createElement("li"), n = document.createElement("p");
3288
- return H(e.props, t), t.appendChild(n), {
3289
- dom: t,
3290
- contentDOM: n
3291
- };
3292
- }
3293
- },
3294
- [
3295
- L({
3296
- key: "toggle-list-item-shortcuts",
3297
- keyboardShortcuts: {
3298
- Enter: ({ editor: e }) => ne(e, "toggleListItem"),
3299
- "Mod-Shift-6": ({ editor: e }) => {
3300
- const t = e.getTextCursorPosition();
3301
- return e.schema.blockSchema[t.block.type].content !== "inline" ? !1 : (e.updateBlock(t.block, {
3302
- type: "toggleListItem",
3303
- props: {}
3304
- }), !0);
3305
- }
3306
- }
3307
- })
3308
- ]
3309
- ), Qn = () => ({
3310
- type: "pageBreak",
3311
- propSchema: {},
3312
- content: "none"
3313
- }), Yn = M(
3314
- Qn,
3315
- {
3316
- parse(e) {
3317
- if (e.tagName === "DIV" && e.hasAttribute("data-page-break"))
3318
- return {};
3319
- },
3320
- render() {
3321
- const e = document.createElement("div");
3322
- return e.setAttribute("data-page-break", ""), {
3323
- dom: e
3324
- };
3325
- },
3326
- toExternalHTML() {
3327
- const e = document.createElement("div");
3328
- return e.setAttribute("data-page-break", ""), {
3329
- dom: e
3330
- };
3331
- }
3332
- }
3333
- ), lr = (e) => e.extend({
3334
- blockSpecs: {
3335
- pageBreak: Yn()
3336
- }
3337
- }), eo = () => ({
3338
- type: "paragraph",
3339
- propSchema: C,
3340
- content: "inline"
3341
- }), to = M(
3342
- eo,
3343
- {
3344
- meta: {
3345
- isolating: !1
3346
- },
3347
- parse: (e) => {
3348
- var t;
3349
- if (e.tagName === "P" && (t = e.textContent) != null && t.trim())
3350
- return B(e);
3351
- },
3352
- render: () => {
3353
- const e = document.createElement("p");
3354
- return {
3355
- dom: e,
3356
- contentDOM: e
3357
- };
3358
- },
3359
- toExternalHTML: (e) => {
3360
- const t = document.createElement("p");
3361
- return H(e.props, t), {
3362
- dom: t,
3363
- contentDOM: t
3364
- };
3365
- },
3366
- runsBefore: ["default"]
3367
- },
3368
- [
3369
- L({
3370
- key: "paragraph-shortcuts",
3371
- keyboardShortcuts: {
3372
- "Mod-Alt-0": ({ editor: e }) => {
3373
- const t = e.getTextCursorPosition();
3374
- return e.schema.blockSchema[t.block.type].content !== "inline" ? !1 : (e.updateBlock(t.block, {
3375
- type: "paragraph",
3376
- props: {}
3377
- }), !0);
3378
- }
3379
- }
3380
- })
3381
- ]
3382
- ), no = () => ({
3383
- type: "quote",
3384
- propSchema: {
3385
- backgroundColor: C.backgroundColor,
3386
- textColor: C.textColor
3387
- },
3388
- content: "inline"
3389
- }), oo = M(
3390
- no,
3391
- {
3392
- meta: {
3393
- isolating: !1
3394
- },
3395
- parse(e) {
3396
- if (e.tagName === "BLOCKQUOTE") {
3397
- const { backgroundColor: t, textColor: n } = B(e);
3398
- return { backgroundColor: t, textColor: n };
3399
- }
3400
- },
3401
- render() {
3402
- const e = document.createElement("blockquote");
3403
- return {
3404
- dom: e,
3405
- contentDOM: e
3406
- };
3407
- },
3408
- toExternalHTML(e) {
3409
- const t = document.createElement("blockquote");
3410
- return H(e.props, t), {
3411
- dom: t,
3412
- contentDOM: t
3413
- };
3414
- }
3415
- },
3416
- [
3417
- L({
3418
- key: "quote-block-shortcuts",
3419
- keyboardShortcuts: {
3420
- "Mod-Alt-q": ({ editor: e }) => {
3421
- const t = e.getTextCursorPosition();
3422
- return e.schema.blockSchema[t.block.type].content !== "inline" ? !1 : (e.updateBlock(t.block, {
3423
- type: "quote",
3424
- props: {}
3425
- }), !0);
3426
- }
3427
- },
3428
- inputRules: [
3429
- {
3430
- find: new RegExp("^>\\s$"),
3431
- replace() {
3432
- return {
3433
- type: "quote",
3434
- props: {}
3435
- };
3436
- }
3437
- }
3438
- ]
3439
- })
3440
- ]
3441
- ), ro = 35, ut = 120, ur = 31, so = $e.create({
3442
- name: "BlockNoteTableExtension",
3443
- addProseMirrorPlugins: () => [
3444
- bt({
3445
- cellMinWidth: ro,
3446
- defaultCellMinWidth: ut,
3447
- // We set this to null as we implement our own node view in the table
3448
- // block content. This node view is the same as what's used by default,
3449
- // but is wrapped in a `blockContent` HTML element.
3450
- View: null
3451
- }),
3452
- kt()
3453
- ],
3454
- addKeyboardShortcuts() {
3455
- return {
3456
- // Makes enter create a new line within the cell.
3457
- Enter: () => this.editor.state.selection.empty && this.editor.state.selection.$head.parent.type.name === "tableParagraph" ? (this.editor.commands.insertContent({ type: "hardBreak" }), !0) : !1,
3458
- // Ensures that backspace won't delete the table if the text cursor is at
3459
- // the start of a cell and the selection is empty.
3460
- Backspace: () => {
3461
- const e = this.editor.state.selection, t = e.empty, n = e.$head.parentOffset === 0, o = e.$head.node().type.name === "tableParagraph";
3462
- return t && n && o;
3463
- },
3464
- // Enables navigating cells using the tab key.
3465
- Tab: () => this.editor.commands.command(
3466
- ({ state: e, dispatch: t, view: n }) => Se(1)(e, t, n)
3467
- ),
3468
- "Shift-Tab": () => this.editor.commands.command(
3469
- ({ state: e, dispatch: t, view: n }) => Se(-1)(e, t, n)
3470
- )
3471
- };
3472
- },
3473
- extendNodeSchema(e) {
3474
- const t = {
3475
- name: e.name,
3476
- options: e.options,
3477
- storage: e.storage
3478
- };
3479
- return {
3480
- tableRole: Tt(
3481
- At(e, "tableRole", t)
3482
- )
3483
- };
3484
- }
3485
- }), ao = {
3486
- textColor: C.textColor
3487
- }, io = D.create({
3488
- name: "tableHeader",
3489
- addOptions() {
3490
- return {
3491
- HTMLAttributes: {}
3492
- };
3493
- },
3494
- /**
3495
- * We allow table headers and cells to have multiple tableContent nodes because
3496
- * when merging cells, prosemirror-tables will concat the contents of the cells naively.
3497
- * This would cause that content to overflow into other cells when prosemirror tries to enforce the cell structure.
3498
- *
3499
- * So, we manually fix this up when reading back in the `nodeToBlock` and only ever place a single tableContent back into the cell.
3500
- */
3501
- content: "tableContent+",
3502
- addAttributes() {
3503
- return {
3504
- colspan: {
3505
- default: 1
3506
- },
3507
- rowspan: {
3508
- default: 1
3509
- },
3510
- colwidth: {
3511
- default: null,
3512
- parseHTML: (e) => {
3513
- const t = e.getAttribute("colwidth");
3514
- return t ? t.split(",").map((o) => parseInt(o, 10)) : null;
3515
- }
3516
- }
3517
- };
3518
- },
3519
- tableRole: "header_cell",
3520
- isolating: !0,
3521
- parseHTML() {
3522
- return [
3523
- {
3524
- tag: "th",
3525
- // As `th` elements can contain multiple paragraphs, we need to merge their contents
3526
- // into a single one so that ProseMirror can parse everything correctly.
3527
- getContent: (e, t) => dt(e, t)
3528
- }
3529
- ];
3530
- },
3531
- renderHTML({ HTMLAttributes: e }) {
3532
- return [
3533
- "th",
3534
- ue(this.options.HTMLAttributes, e),
3535
- 0
3536
- ];
3537
- }
3538
- }), co = D.create({
3539
- name: "tableCell",
3540
- addOptions() {
3541
- return {
3542
- HTMLAttributes: {}
3543
- };
3544
- },
3545
- content: "tableContent+",
3546
- addAttributes() {
3547
- return {
3548
- colspan: {
3549
- default: 1
3550
- },
3551
- rowspan: {
3552
- default: 1
3553
- },
3554
- colwidth: {
3555
- default: null,
3556
- parseHTML: (e) => {
3557
- const t = e.getAttribute("colwidth");
3558
- return t ? t.split(",").map((o) => parseInt(o, 10)) : null;
3559
- }
3560
- }
3561
- };
3562
- },
3563
- tableRole: "cell",
3564
- isolating: !0,
3565
- parseHTML() {
3566
- return [
3567
- {
3568
- tag: "td",
3569
- // As `td` elements can contain multiple paragraphs, we need to merge their contents
3570
- // into a single one so that ProseMirror can parse everything correctly.
3571
- getContent: (e, t) => dt(e, t)
3572
- }
3573
- ];
3574
- },
3575
- renderHTML({ HTMLAttributes: e }) {
3576
- return [
3577
- "td",
3578
- ue(this.options.HTMLAttributes, e),
3579
- 0
3580
- ];
3581
- }
3582
- }), lo = D.create({
3583
- name: "table",
3584
- content: "tableRow+",
3585
- group: "blockContent",
3586
- tableRole: "table",
3587
- marks: "deletion insertion modification",
3588
- isolating: !0,
3589
- parseHTML() {
3590
- return [
3591
- {
3592
- tag: "table"
3593
- }
3594
- ];
3595
- },
3596
- renderHTML({ node: e, HTMLAttributes: t }) {
3597
- var r, s, a;
3598
- const n = Vt(
3599
- this.name,
3600
- "table",
3601
- {
3602
- ...((r = this.options.domAttributes) == null ? void 0 : r.blockContent) || {},
3603
- ...t
3604
- },
3605
- ((s = this.options.domAttributes) == null ? void 0 : s.inlineContent) || {}
3606
- ), o = document.createElement("colgroup");
3607
- for (const i of e.children[0].children)
3608
- if (i.attrs.colwidth)
3609
- for (const l of i.attrs.colwidth) {
3610
- const d = document.createElement("col");
3611
- l && (d.style = `width: ${l}px`), o.appendChild(d);
3612
- }
3613
- else
3614
- o.appendChild(document.createElement("col"));
3615
- return (a = n.dom.firstChild) == null || a.appendChild(o), n;
3616
- },
3617
- // This node view is needed for the `columnResizing` plugin. By default, the
3618
- // plugin adds its own node view, which overrides how the node is rendered vs
3619
- // `renderHTML`. This means that the wrapping `blockContent` HTML element is
3620
- // no longer rendered. The `columnResizing` plugin uses the `TableView` as its
3621
- // default node view. `BlockNoteTableView` extends it by wrapping it in a
3622
- // `blockContent` element, so the DOM structure is consistent with other block
3623
- // types.
3624
- addNodeView() {
3625
- return ({ node: e, HTMLAttributes: t }) => {
3626
- var o;
3627
- class n extends Ct {
3628
- constructor(s, a, i) {
3629
- super(s, a), this.node = s, this.cellMinWidth = a, this.blockContentHTMLAttributes = i;
3630
- const c = document.createElement("div");
3631
- c.className = U(
3632
- "bn-block-content",
3633
- i.class
3634
- ), c.setAttribute("data-content-type", "table");
3635
- for (const [p, f] of Object.entries(
3636
- i
3637
- ))
3638
- p !== "class" && c.setAttribute(p, f);
3639
- const l = this.dom, d = document.createElement("div");
3640
- d.className = "tableWrapper-inner", d.appendChild(l.firstChild), l.appendChild(d), c.appendChild(l);
3641
- const u = document.createElement("div");
3642
- u.className = "table-widgets-container", u.style.position = "relative", l.appendChild(u), this.dom = c;
3643
- }
3644
- ignoreMutation(s) {
3645
- return !s.target.closest(".tableWrapper-inner") || super.ignoreMutation(s);
3646
- }
3647
- }
3648
- return new n(e, ut, {
3649
- ...((o = this.options.domAttributes) == null ? void 0 : o.blockContent) || {},
3650
- ...t
3651
- });
3652
- };
3653
- }
3654
- }), uo = D.create({
3655
- name: "tableParagraph",
3656
- group: "tableContent",
3657
- content: "inline*",
3658
- parseHTML() {
3659
- return [
3660
- {
3661
- tag: "p",
3662
- getAttrs: (e) => {
3663
- if (typeof e == "string" || !e.textContent || !e.closest("[data-content-type]"))
3664
- return !1;
3665
- const t = e.parentElement;
3666
- return t === null ? !1 : t.tagName === "TD" || t.tagName === "TH" ? {} : !1;
3667
- },
3668
- node: "tableParagraph"
3669
- }
3670
- ];
3671
- },
3672
- renderHTML({ HTMLAttributes: e }) {
3673
- return ["p", e, 0];
3674
- }
3675
- }), po = D.create({
3676
- name: "tableRow",
3677
- addOptions() {
3678
- return {
3679
- HTMLAttributes: {}
3680
- };
3681
- },
3682
- content: "(tableCell | tableHeader)+",
3683
- tableRole: "row",
3684
- marks: "deletion insertion modification",
3685
- parseHTML() {
3686
- return [{ tag: "tr" }];
3687
- },
3688
- renderHTML({ HTMLAttributes: e }) {
3689
- return [
3690
- "tr",
3691
- ue(this.options.HTMLAttributes, e),
3692
- 0
3693
- ];
3694
- }
3695
- });
3696
- function dt(e, t) {
3697
- const o = Q.fromSchema(t).parse(e, {
3698
- topNode: t.nodes.blockGroup.create()
3699
- }), r = [];
3700
- return o.content.descendants((s) => {
3701
- if (s.isInline)
3702
- return r.push(s), !1;
3703
- }), _.fromArray(r);
3704
- }
3705
- const fo = () => jt(
3706
- { node: lo, type: "table", content: "table" },
3707
- ao,
3708
- [
3709
- L({
3710
- key: "table-extensions",
3711
- tiptapExtensions: [
3712
- so,
3713
- uo,
3714
- io,
3715
- co,
3716
- po
3717
- ]
3718
- }),
3719
- // Extension for keyboard shortcut which deletes the table if it's empty
3720
- // and all cells are selected. Uses a separate extension as it needs
3721
- // priority over keyboard handlers in the `TableExtension`'s
3722
- // `tableEditing` plugin.
3723
- L({
3724
- key: "table-keyboard-delete",
3725
- keyboardShortcuts: {
3726
- Backspace: ({ editor: e }) => {
3727
- if (!(e.prosemirrorState.selection instanceof Fe))
3728
- return !1;
3729
- const t = e.getTextCursorPosition().block, n = t.content;
3730
- let o = 0;
3731
- for (const s of n.rows)
3732
- for (const a of s.cells) {
3733
- if ("type" in a && a.content.length > 0 || !("type" in a) && a.length > 0)
3734
- return !1;
3735
- o++;
3736
- }
3737
- let r = 0;
3738
- return e.prosemirrorState.selection.forEachCell(() => {
3739
- r++;
3740
- }), r < o ? !1 : (e.transact(() => {
3741
- (e.getPrevBlock(t) || e.getNextBlock(t)) && e.setTextCursorPosition(t), e.removeBlocks([t]);
3742
- }), !0);
3743
- }
3744
- }
3745
- })
3746
- ]
3747
- ), Ve = (e) => {
3748
- const t = e.src || void 0, n = e.width || void 0;
3749
- return { url: t, previewWidth: n };
3750
- }, ho = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 3.9934C2 3.44476 2.45531 3 2.9918 3H21.0082C21.556 3 22 3.44495 22 3.9934V20.0066C22 20.5552 21.5447 21 21.0082 21H2.9918C2.44405 21 2 20.5551 2 20.0066V3.9934ZM8 5V19H16V5H8ZM4 5V7H6V5H4ZM18 5V7H20V5H18ZM4 9V11H6V9H4ZM18 9V11H20V9H18ZM4 13V15H6V13H4ZM18 13V15H20V13H18ZM4 17V19H6V17H4ZM18 17V19H20V17H18Z"></path></svg>', mo = (e) => ({
3751
- type: "video",
3752
- propSchema: {
3753
- textAlignment: C.textAlignment,
3754
- backgroundColor: C.backgroundColor,
3755
- name: { default: "" },
3756
- url: { default: "" },
3757
- caption: { default: "" },
3758
- showPreview: { default: !0 },
3759
- previewWidth: { default: void 0, type: "number" }
3760
- },
3761
- content: "none"
3762
- }), go = (e) => (t) => {
3763
- if (t.tagName === "VIDEO") {
3764
- if (t.closest("figure"))
3765
- return;
3766
- const { backgroundColor: n } = B(t);
3767
- return {
3768
- ...Ve(t),
3769
- backgroundColor: n
3770
- };
3771
- }
3772
- if (t.tagName === "FIGURE") {
3773
- const n = ee(t, "video");
3774
- if (!n)
3775
- return;
3776
- const { targetElement: o, caption: r } = n, { backgroundColor: s } = B(t);
3777
- return {
3778
- ...Ve(o),
3779
- backgroundColor: s,
3780
- caption: r
3781
- };
3782
- }
3783
- }, bo = M(
3784
- mo,
3785
- (e) => ({
3786
- meta: {
3787
- fileBlockAccept: ["video/*"]
3788
- },
3789
- parse: go(),
3790
- render(t, n) {
3791
- const o = document.createElement("div");
3792
- o.innerHTML = e.icon ?? ho;
3793
- const r = document.createElement("div");
3794
- r.className = "bn-visual-media-wrapper";
3795
- const s = document.createElement("video");
3796
- return s.className = "bn-visual-media", n.resolveFileUrl ? n.resolveFileUrl(t.props.url).then((a) => {
3797
- s.src = a;
3798
- }) : s.src = t.props.url, s.controls = !0, s.contentEditable = "false", s.draggable = !1, s.width = t.props.previewWidth, r.appendChild(s), it(
3799
- t,
3800
- n,
3801
- { dom: r },
3802
- r,
3803
- o.firstElementChild
3804
- );
3805
- },
3806
- toExternalHTML(t) {
3807
- if (!t.props.url) {
3808
- const o = document.createElement("p");
3809
- return o.textContent = "Add video", {
3810
- dom: o
3811
- };
3812
- }
3813
- let n;
3814
- return t.props.showPreview ? (n = document.createElement("video"), n.src = t.props.url, t.props.previewWidth && (n.width = t.props.previewWidth)) : (n = document.createElement("a"), n.href = t.props.url, n.textContent = t.props.name || t.props.url), t.props.caption ? t.props.showPreview ? ve(n, t.props.caption) : te(n, t.props.caption) : {
3815
- dom: n
3816
- };
3817
- },
3818
- runsBefore: ["file"]
3819
- })
3820
- ), dr = async (e) => {
3821
- const t = new FormData();
3822
- return t.append("file", e), (await (await fetch("https://tmpfiles.org/api/v1/upload", {
3823
- method: "POST",
3824
- body: t
3825
- })).json()).data.url.replace(
3826
- "tmpfiles.org/",
3827
- "tmpfiles.org/dl/"
3828
- );
3829
- };
3830
- function E(e, t, n) {
3831
- if (!(t in e.schema.blockSpecs))
3832
- return !1;
3833
- if (!n)
3834
- return !0;
3835
- for (const [o, r] of Object.entries(n)) {
3836
- if (!(o in e.schema.blockSpecs[t].config.propSchema))
3837
- return !1;
3838
- if (typeof r == "string") {
3839
- if (e.schema.blockSpecs[t].config.propSchema[o].default && typeof e.schema.blockSpecs[t].config.propSchema[o].default !== r || e.schema.blockSpecs[t].config.propSchema[o].type && e.schema.blockSpecs[t].config.propSchema[o].type !== r)
3840
- return !1;
3841
- } else {
3842
- if (e.schema.blockSpecs[t].config.propSchema[o].default !== r.default || e.schema.blockSpecs[t].config.propSchema[o].default === void 0 && r.default === void 0 && e.schema.blockSpecs[t].config.propSchema[o].type !== r.type || typeof e.schema.blockSpecs[t].config.propSchema[o].values != typeof r.values)
3843
- return !1;
3844
- if (typeof e.schema.blockSpecs[t].config.propSchema[o].values == "object" && typeof r.values == "object") {
3845
- if (e.schema.blockSpecs[t].config.propSchema[o].values.length !== r.values.length)
3846
- return !1;
3847
- for (let s = 0; s < e.schema.blockSpecs[t].config.propSchema[o].values.length; s++)
3848
- if (e.schema.blockSpecs[t].config.propSchema[o].values[s] !== r.values[s])
3849
- return !1;
3850
- }
3851
- }
3852
- }
3853
- return !0;
3854
- }
3855
- function pr(e, t, n, o) {
3856
- return E(t, n, o) && e.type === n;
3857
- }
3858
- function fr(e) {
3859
- return e instanceof Fe;
3860
- }
3861
- function ko(e) {
3862
- let t = e.getTextCursorPosition().block, n = e.schema.blockSchema[t.type].content;
3863
- for (; n === "none"; ) {
3864
- if (t = e.getTextCursorPosition().nextBlock, t === void 0)
3865
- return;
3866
- n = e.schema.blockSchema[t.type].content, e.setTextCursorPosition(t, "end");
3867
- }
3868
- }
3869
- function w(e, t) {
3870
- const n = e.getTextCursorPosition().block;
3871
- if (n.content === void 0)
3872
- throw new Error("Slash Menu open in a block that doesn't contain content.");
3873
- let o;
3874
- return Array.isArray(n.content) && (n.content.length === 1 && I(n.content[0]) && n.content[0].type === "text" && n.content[0].text === "/" || n.content.length === 0) ? (o = e.updateBlock(n, t), e.setTextCursorPosition(o)) : (o = e.insertBlocks([t], n, "after")[0], e.setTextCursorPosition(e.getTextCursorPosition().nextBlock)), ko(e), o;
3875
- }
3876
- function hr(e) {
3877
- const t = [];
3878
- return E(e, "heading", { level: "number" }) && t.push(
3879
- {
3880
- onItemClick: () => {
3881
- w(e, {
3882
- type: "heading",
3883
- props: { level: 1 }
3884
- });
3885
- },
3886
- badge: T("Mod-Alt-1"),
3887
- key: "heading",
3888
- ...e.dictionary.slash_menu.heading
3889
- },
3890
- {
3891
- onItemClick: () => {
3892
- w(e, {
3893
- type: "heading",
3894
- props: { level: 2 }
3895
- });
3896
- },
3897
- badge: T("Mod-Alt-2"),
3898
- key: "heading_2",
3899
- ...e.dictionary.slash_menu.heading_2
3900
- },
3901
- {
3902
- onItemClick: () => {
3903
- w(e, {
3904
- type: "heading",
3905
- props: { level: 3 }
3906
- });
3907
- },
3908
- badge: T("Mod-Alt-3"),
3909
- key: "heading_3",
3910
- ...e.dictionary.slash_menu.heading_3
3911
- }
3912
- ), E(e, "quote") && t.push({
3913
- onItemClick: () => {
3914
- w(e, {
3915
- type: "quote"
3916
- });
3917
- },
3918
- key: "quote",
3919
- ...e.dictionary.slash_menu.quote
3920
- }), E(e, "toggleListItem") && t.push({
3921
- onItemClick: () => {
3922
- w(e, {
3923
- type: "toggleListItem"
3924
- });
3925
- },
3926
- badge: T("Mod-Shift-6"),
3927
- key: "toggle_list",
3928
- ...e.dictionary.slash_menu.toggle_list
3929
- }), E(e, "numberedListItem") && t.push({
3930
- onItemClick: () => {
3931
- w(e, {
3932
- type: "numberedListItem"
3933
- });
3934
- },
3935
- badge: T("Mod-Shift-7"),
3936
- key: "numbered_list",
3937
- ...e.dictionary.slash_menu.numbered_list
3938
- }), E(e, "bulletListItem") && t.push({
3939
- onItemClick: () => {
3940
- w(e, {
3941
- type: "bulletListItem"
3942
- });
3943
- },
3944
- badge: T("Mod-Shift-8"),
3945
- key: "bullet_list",
3946
- ...e.dictionary.slash_menu.bullet_list
3947
- }), E(e, "checkListItem") && t.push({
3948
- onItemClick: () => {
3949
- w(e, {
3950
- type: "checkListItem"
3951
- });
3952
- },
3953
- badge: T("Mod-Shift-9"),
3954
- key: "check_list",
3955
- ...e.dictionary.slash_menu.check_list
3956
- }), E(e, "paragraph") && t.push({
3957
- onItemClick: () => {
3958
- w(e, {
3959
- type: "paragraph"
3960
- });
3961
- },
3962
- badge: T("Mod-Alt-0"),
3963
- key: "paragraph",
3964
- ...e.dictionary.slash_menu.paragraph
3965
- }), E(e, "codeBlock") && t.push({
3966
- onItemClick: () => {
3967
- w(e, {
3968
- type: "codeBlock"
3969
- });
3970
- },
3971
- badge: T("Mod-Alt-c"),
3972
- key: "code_block",
3973
- ...e.dictionary.slash_menu.code_block
3974
- }), E(e, "divider") && t.push({
3975
- onItemClick: () => {
3976
- w(e, { type: "divider" });
3977
- },
3978
- key: "divider",
3979
- ...e.dictionary.slash_menu.divider
3980
- }), E(e, "table") && t.push({
3981
- onItemClick: () => {
3982
- w(e, {
3983
- type: "table",
3984
- content: {
3985
- type: "tableContent",
3986
- rows: [
3987
- {
3988
- cells: ["", "", ""]
3989
- },
3990
- {
3991
- cells: ["", "", ""]
3992
- }
3993
- ]
3994
- }
3995
- });
3996
- },
3997
- badge: void 0,
3998
- key: "table",
3999
- ...e.dictionary.slash_menu.table
4000
- }), E(e, "image", { url: "string" }) && t.push({
4001
- onItemClick: () => {
4002
- const n = w(e, {
4003
- type: "image"
4004
- });
4005
- e.transact(
4006
- (o) => o.setMeta(e.filePanel.plugins[0], {
4007
- block: n
4008
- })
4009
- );
4010
- },
4011
- key: "image",
4012
- ...e.dictionary.slash_menu.image
4013
- }), E(e, "video", { url: "string" }) && t.push({
4014
- onItemClick: () => {
4015
- const n = w(e, {
4016
- type: "video"
4017
- });
4018
- e.transact(
4019
- (o) => o.setMeta(e.filePanel.plugins[0], {
4020
- block: n
4021
- })
4022
- );
4023
- },
4024
- key: "video",
4025
- ...e.dictionary.slash_menu.video
4026
- }), E(e, "audio", { url: "string" }) && t.push({
4027
- onItemClick: () => {
4028
- const n = w(e, {
4029
- type: "audio"
4030
- });
4031
- e.transact(
4032
- (o) => o.setMeta(e.filePanel.plugins[0], {
4033
- block: n
4034
- })
4035
- );
4036
- },
4037
- key: "audio",
4038
- ...e.dictionary.slash_menu.audio
4039
- }), E(e, "file", { url: "string" }) && t.push({
4040
- onItemClick: () => {
4041
- const n = w(e, {
4042
- type: "file"
4043
- });
4044
- e.transact(
4045
- (o) => o.setMeta(e.filePanel.plugins[0], {
4046
- block: n
4047
- })
4048
- );
4049
- },
4050
- key: "file",
4051
- ...e.dictionary.slash_menu.file
4052
- }), E(e, "heading", {
4053
- level: "number",
4054
- isToggleable: "boolean"
4055
- }) && t.push(
4056
- {
4057
- onItemClick: () => {
4058
- w(e, {
4059
- type: "heading",
4060
- props: { level: 1, isToggleable: !0 }
4061
- });
4062
- },
4063
- key: "toggle_heading",
4064
- ...e.dictionary.slash_menu.toggle_heading
4065
- },
4066
- {
4067
- onItemClick: () => {
4068
- w(e, {
4069
- type: "heading",
4070
- props: { level: 2, isToggleable: !0 }
4071
- });
4072
- },
4073
- key: "toggle_heading_2",
4074
- ...e.dictionary.slash_menu.toggle_heading_2
4075
- },
4076
- {
4077
- onItemClick: () => {
4078
- w(e, {
4079
- type: "heading",
4080
- props: { level: 3, isToggleable: !0 }
4081
- });
4082
- },
4083
- key: "toggle_heading_3",
4084
- ...e.dictionary.slash_menu.toggle_heading_3
4085
- }
4086
- ), E(e, "heading", { level: "number" }) && (e.schema.blockSchema.heading.propSchema.level.values || []).filter((n) => n > 3).forEach((n) => {
4087
- t.push({
4088
- onItemClick: () => {
4089
- w(e, {
4090
- type: "heading",
4091
- props: { level: n }
4092
- });
4093
- },
4094
- key: `heading_${n}`,
4095
- ...e.dictionary.slash_menu[`heading_${n}`]
4096
- });
4097
- }), t.push({
4098
- onItemClick: () => {
4099
- e.openSuggestionMenu(":", {
4100
- deleteTriggerCharacter: !0,
4101
- ignoreQueryLength: !0
4102
- });
4103
- },
4104
- key: "emoji",
4105
- ...e.dictionary.slash_menu.emoji
4106
- }), t;
4107
- }
4108
- function mr(e, t) {
4109
- return e.filter(
4110
- ({ title: n, aliases: o }) => n.toLowerCase().includes(t.toLowerCase()) || o && o.filter(
4111
- (r) => r.toLowerCase().includes(t.toLowerCase())
4112
- ).length !== 0
4113
- );
4114
- }
4115
- function Co(e) {
4116
- return "pageBreak" in e.schema.blockSchema;
4117
- }
4118
- function gr(e) {
4119
- const t = [];
4120
- return Co(e) && t.push({
4121
- ...e.dictionary.slash_menu.page_break,
4122
- onItemClick: () => {
4123
- w(e, {
4124
- type: "pageBreak"
4125
- });
4126
- },
4127
- key: "page_break"
4128
- }), t;
4129
- }
4130
- const yo = {
4131
- audio: En(),
4132
- bulletListItem: Un(),
4133
- checkListItem: qn(),
4134
- codeBlock: Ln(),
4135
- divider: An(),
4136
- file: Pn(),
4137
- heading: Dn(),
4138
- image: $n(),
4139
- numberedListItem: Xn(),
4140
- paragraph: to(),
4141
- quote: oo(),
4142
- table: fo(),
4143
- toggleListItem: Kn(),
4144
- video: bo()
4145
- }, wo = Ye(
4146
- {
4147
- type: "textColor",
4148
- propSchema: "string"
4149
- },
4150
- {
4151
- render: () => {
4152
- const e = document.createElement("span");
4153
- return {
4154
- dom: e,
4155
- contentDOM: e
4156
- };
4157
- },
4158
- toExternalHTML: (e) => {
4159
- const t = document.createElement("span");
4160
- return e !== C.textColor.default && (t.style.color = e in A ? A[e].text : e), {
4161
- dom: t,
4162
- contentDOM: t
4163
- };
4164
- },
4165
- parse: (e) => {
4166
- if (e.tagName === "SPAN" && e.style.color)
4167
- return e.style.color;
4168
- }
4169
- }
4170
- ), vo = Ye(
4171
- {
4172
- type: "backgroundColor",
4173
- propSchema: "string"
4174
- },
4175
- {
4176
- render: () => {
4177
- const e = document.createElement("span");
4178
- return {
4179
- dom: e,
4180
- contentDOM: e
4181
- };
4182
- },
4183
- toExternalHTML: (e) => {
4184
- const t = document.createElement("span");
4185
- return e !== C.backgroundColor.default && (t.style.backgroundColor = e in A ? A[e].background : e), {
4186
- dom: t,
4187
- contentDOM: t
4188
- };
4189
- },
4190
- parse: (e) => {
4191
- if (e.tagName === "SPAN" && e.style.backgroundColor)
4192
- return e.style.backgroundColor;
4193
- }
4194
- }
4195
- ), pt = {
4196
- bold: F(yt, "boolean"),
4197
- italic: F(vt, "boolean"),
4198
- underline: F(xt, "boolean"),
4199
- strike: F(Et, "boolean"),
4200
- code: F(wt, "boolean"),
4201
- textColor: wo,
4202
- backgroundColor: vo
4203
- }, br = Qe(pt), ft = {
4204
- text: { config: "text", implementation: {} },
4205
- link: { config: "link", implementation: {} }
4206
- }, kr = Je(
4207
- ft
4208
- );
4209
- class ht extends sn {
4210
- static create(t) {
4211
- return new ht({
4212
- blockSpecs: (t == null ? void 0 : t.blockSpecs) ?? yo,
4213
- inlineContentSpecs: (t == null ? void 0 : t.inlineContentSpecs) ?? ft,
4214
- styleSpecs: (t == null ? void 0 : t.styleSpecs) ?? pt
4215
- });
4216
- }
4217
- }
4218
- export {
4219
- Te as $,
4220
- qn as A,
4221
- Gn as B,
4222
- Xn as C,
4223
- Jn as D,
4224
- ur as E,
4225
- kn as F,
4226
- Kn as G,
4227
- Qn as H,
4228
- Yn as I,
4229
- lr as J,
4230
- eo as K,
4231
- to as L,
4232
- no as M,
4233
- oo as N,
4234
- ao as O,
4235
- fo as P,
4236
- ho as Q,
4237
- mo as R,
4238
- go as S,
4239
- bo as T,
4240
- Hn as U,
4241
- st as V,
4242
- dr as W,
4243
- Co as X,
4244
- gr as Y,
4245
- ht as Z,
4246
- Vt as _,
4247
- ut as a,
4248
- ke as a$,
4249
- Wt as a0,
4250
- yo as a1,
4251
- pt as a2,
4252
- br as a3,
4253
- ft as a4,
4254
- kr as a5,
4255
- E as a6,
4256
- pr as a7,
4257
- fr as a8,
4258
- C as a9,
4259
- cr as aA,
4260
- nr as aB,
4261
- Yo as aC,
4262
- Jo as aD,
4263
- er as aE,
4264
- Xo as aF,
4265
- et as aG,
4266
- an as aH,
4267
- cn as aI,
4268
- tr as aJ,
4269
- Ko as aK,
4270
- Qo as aL,
4271
- U as aM,
4272
- qe as aN,
4273
- Uo as aO,
4274
- or as aP,
4275
- $o as aQ,
4276
- zo as aR,
4277
- me as aS,
4278
- z as aT,
4279
- ye as aU,
4280
- Vo as aV,
4281
- fn as aW,
4282
- he as aX,
4283
- ge as aY,
4284
- be as aZ,
4285
- R as a_,
4286
- B as aa,
4287
- H as ab,
4288
- sr as ac,
4289
- ar as ad,
4290
- ir as ae,
4291
- Jt as af,
4292
- O as ag,
4293
- qo as ah,
4294
- Zo as ai,
4295
- Ft as aj,
4296
- Go as ak,
4297
- G as al,
4298
- Y as am,
4299
- un as an,
4300
- X as ao,
4301
- nt as ap,
4302
- Z as aq,
4303
- dn as ar,
4304
- fe as as,
4305
- Xt as at,
4306
- Ce as au,
4307
- Sn as av,
4308
- xn as aw,
4309
- Zt as ax,
4310
- Gt as ay,
4311
- Ge as az,
4312
- yn as b,
4313
- L as b0,
4314
- A as b1,
4315
- rr as b2,
4316
- w as b3,
4317
- hr as b4,
4318
- mr as b5,
4319
- Ut as b6,
4320
- zt as b7,
4321
- qt as b8,
4322
- jo as b9,
4323
- ae as bA,
4324
- M as ba,
4325
- $t as bb,
4326
- ie as bc,
4327
- jt as bd,
4328
- Kt as be,
4329
- Je as bf,
4330
- Le as bg,
4331
- Ze as bh,
4332
- I as bi,
4333
- Yt as bj,
4334
- Ye as bk,
4335
- Qt as bl,
4336
- J as bm,
4337
- Ke as bn,
4338
- F as bo,
4339
- Qe as bp,
4340
- sn as bq,
4341
- Rt as br,
4342
- T as bs,
4343
- Wo as bt,
4344
- K as bu,
4345
- Fo as bv,
4346
- se as bw,
4347
- $ as bx,
4348
- pe as by,
4349
- j as bz,
4350
- Cn as c,
4351
- wn as d,
4352
- vn as e,
4353
- En as f,
4354
- Mn as g,
4355
- Ln as h,
4356
- rt as i,
4357
- Tn as j,
4358
- An as k,
4359
- Nn as l,
4360
- In as m,
4361
- Pn as n,
4362
- On as o,
4363
- He as p,
4364
- Dn as q,
4365
- _n as r,
4366
- Rn as s,
4367
- Vn as t,
4368
- Wn as u,
4369
- Fn as v,
4370
- $n as w,
4371
- jn as x,
4372
- Un as y,
4373
- zn as z
4374
- };
4375
- //# sourceMappingURL=BlockNoteSchema-CYRHak18.js.map