@blocknote/core 0.47.2 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist/BlockNoteExtension-B6RhuQ3V.js +27 -0
  2. package/dist/BlockNoteExtension-B6RhuQ3V.js.map +1 -0
  3. package/dist/BlockNoteExtension-ab0REuob.cjs +2 -0
  4. package/dist/BlockNoteExtension-ab0REuob.cjs.map +1 -0
  5. package/dist/EventEmitter-CuPnGDYt.js +22 -0
  6. package/dist/EventEmitter-CuPnGDYt.js.map +1 -0
  7. package/dist/EventEmitter-DHdSnYCD.cjs +2 -0
  8. package/dist/EventEmitter-DHdSnYCD.cjs.map +1 -0
  9. package/dist/ShowSelection-BsHFfdMi.js +29 -0
  10. package/dist/ShowSelection-BsHFfdMi.js.map +1 -0
  11. package/dist/ShowSelection-DhXglbt8.cjs +2 -0
  12. package/dist/ShowSelection-DhXglbt8.cjs.map +1 -0
  13. package/dist/blocknote.cjs +1 -5
  14. package/dist/blocknote.js +7 -4216
  15. package/dist/blocks-BEvIOzln.cjs +11 -0
  16. package/dist/blocks-BEvIOzln.cjs.map +1 -0
  17. package/dist/blocks-DYl7UTS4.js +3313 -0
  18. package/dist/blocks-DYl7UTS4.js.map +1 -0
  19. package/dist/blocks.cjs +1 -2
  20. package/dist/blocks.js +2 -74
  21. package/dist/comments.cjs +2 -2
  22. package/dist/comments.cjs.map +1 -1
  23. package/dist/comments.js +604 -900
  24. package/dist/comments.js.map +1 -1
  25. package/dist/en-C4ykW581.cjs +2 -0
  26. package/dist/en-C4ykW581.cjs.map +1 -0
  27. package/dist/en-QsSI16s5.js +453 -0
  28. package/dist/en-QsSI16s5.js.map +1 -0
  29. package/dist/extensions-3nf9PPhA.js +1495 -0
  30. package/dist/extensions-3nf9PPhA.js.map +1 -0
  31. package/dist/extensions-D9y6evn6.cjs +2 -0
  32. package/dist/extensions-D9y6evn6.cjs.map +1 -0
  33. package/dist/extensions.cjs +1 -2
  34. package/dist/extensions.js +4 -36
  35. package/dist/locales.cjs +2 -2
  36. package/dist/locales.cjs.map +1 -1
  37. package/dist/locales.js +10049 -9111
  38. package/dist/locales.js.map +1 -1
  39. package/dist/src-BKJH7Jla.cjs +5 -0
  40. package/dist/src-BKJH7Jla.cjs.map +1 -0
  41. package/dist/src-Hjv1f5lc.js +2386 -0
  42. package/dist/src-Hjv1f5lc.js.map +1 -0
  43. package/dist/style.css +2 -1
  44. package/dist/webpack-stats.json +1 -1
  45. package/dist/yjs.cjs +2 -2
  46. package/dist/yjs.cjs.map +1 -1
  47. package/dist/yjs.js +20 -38
  48. package/dist/yjs.js.map +1 -1
  49. package/package.json +8 -8
  50. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +15 -1
  51. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +5 -0
  52. package/src/api/blockManipulation/commands/nestBlock/__snapshots__/nestBlock.test.ts.snap +1095 -0
  53. package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +661 -0
  54. package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +128 -11
  55. package/src/api/parsers/html/parseHTML.ts +2 -0
  56. package/src/api/parsers/html/util/normalizeWhitespace.ts +87 -0
  57. package/src/blocks/File/helpers/render/createResizableFileBlockWrapper.ts +17 -23
  58. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +346 -0
  59. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +143 -71
  60. package/src/editor/Block.css +5 -8
  61. package/src/editor/BlockNoteEditor.ts +38 -1
  62. package/src/editor/editor.css +0 -20
  63. package/src/editor/managers/ExtensionManager/extensions.ts +12 -1
  64. package/src/editor/performance.test.ts +134 -0
  65. package/src/extensions/Collaboration/ForkYDoc.test.ts +115 -103
  66. package/src/extensions/Placeholder/Placeholder.ts +1 -1
  67. package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +86 -0
  68. package/src/extensions/PreviousBlockType/PreviousBlockType.ts +33 -49
  69. package/src/extensions/SideMenu/SideMenu.ts +14 -8
  70. package/src/extensions/TableHandles/TableHandles.ts +14 -0
  71. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +57 -17
  72. package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +9 -8
  73. package/src/index.ts +1 -1
  74. package/src/schema/blocks/createSpec.ts +6 -2
  75. package/src/schema/inlineContent/types.ts +0 -1
  76. package/src/vite-env.d.ts +6 -0
  77. package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.d.ts +14 -1
  78. package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.test.d.ts +1 -0
  79. package/types/src/api/parsers/html/util/normalizeWhitespace.d.ts +6 -0
  80. package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.d.ts +1 -0
  81. package/types/src/editor/BlockNoteEditor.d.ts +13 -0
  82. package/types/src/editor/performance.test.d.ts +1 -0
  83. package/types/src/extensions/PreviousBlockType/PreviousBlockType.test.d.ts +1 -0
  84. package/types/src/extensions/SideMenu/SideMenu.d.ts +6 -0
  85. package/types/src/extensions/TableHandles/TableHandles.d.ts +6 -0
  86. package/dist/BlockNoteExtension-BWw0r8Gy.cjs +0 -2
  87. package/dist/BlockNoteExtension-BWw0r8Gy.cjs.map +0 -1
  88. package/dist/BlockNoteExtension-C2X7LW-V.js +0 -25
  89. package/dist/BlockNoteExtension-C2X7LW-V.js.map +0 -1
  90. package/dist/BlockNoteSchema-CCs_V3lo.cjs +0 -2
  91. package/dist/BlockNoteSchema-CCs_V3lo.cjs.map +0 -1
  92. package/dist/BlockNoteSchema-ooiKsd5B.js +0 -270
  93. package/dist/BlockNoteSchema-ooiKsd5B.js.map +0 -1
  94. package/dist/EventEmitter-CLwfmbqG.cjs +0 -2
  95. package/dist/EventEmitter-CLwfmbqG.cjs.map +0 -1
  96. package/dist/EventEmitter-CjSwpTbz.js +0 -27
  97. package/dist/EventEmitter-CjSwpTbz.js.map +0 -1
  98. package/dist/ShowSelection-B0ch3unP.js +0 -51
  99. package/dist/ShowSelection-B0ch3unP.js.map +0 -1
  100. package/dist/ShowSelection-BxnbRvy4.cjs +0 -2
  101. package/dist/ShowSelection-BxnbRvy4.cjs.map +0 -1
  102. package/dist/TrailingNode-GzE59m_7.js +0 -2288
  103. package/dist/TrailingNode-GzE59m_7.js.map +0 -1
  104. package/dist/TrailingNode-n0WdMPUl.cjs +0 -2
  105. package/dist/TrailingNode-n0WdMPUl.cjs.map +0 -1
  106. package/dist/blockToNode-BNoNIXU7.js +0 -1140
  107. package/dist/blockToNode-BNoNIXU7.js.map +0 -1
  108. package/dist/blockToNode-CumVjgem.cjs +0 -7
  109. package/dist/blockToNode-CumVjgem.cjs.map +0 -1
  110. package/dist/blocknote.cjs.map +0 -1
  111. package/dist/blocknote.js.map +0 -1
  112. package/dist/blocks.cjs.map +0 -1
  113. package/dist/blocks.js.map +0 -1
  114. package/dist/defaultBlocks-Dg9kQWXm.cjs +0 -6
  115. package/dist/defaultBlocks-Dg9kQWXm.cjs.map +0 -1
  116. package/dist/defaultBlocks-ZzGbYgQn.js +0 -3284
  117. package/dist/defaultBlocks-ZzGbYgQn.js.map +0 -1
  118. package/dist/en-Cl87Uuyf.cjs +0 -2
  119. package/dist/en-Cl87Uuyf.cjs.map +0 -1
  120. package/dist/en-njEqD7AG.js +0 -408
  121. package/dist/en-njEqD7AG.js.map +0 -1
  122. package/dist/extensions.cjs.map +0 -1
  123. package/dist/extensions.js.map +0 -1
  124. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -1,4 +1,4 @@
1
- import { findChildren } from "@tiptap/core";
1
+ import { findChildrenInRange } from "@tiptap/core";
2
2
  import { Plugin, PluginKey } from "prosemirror-state";
3
3
  import { Decoration, DecorationSet } from "prosemirror-view";
4
4
  import { createExtension } from "../../editor/BlockNoteExtension.js";
@@ -67,45 +67,40 @@ export const PreviousBlockTypeExtension = createExtension(() => {
67
67
  prev.currentTransactionOldBlockAttrs = {};
68
68
  prev.updatedBlocks.clear();
69
69
 
70
- if (!transaction.docChanged || oldState.doc.eq(newState.doc)) {
70
+ if (!transaction.docChanged) {
71
71
  return prev;
72
72
  }
73
73
 
74
- // TODO: Instead of iterating through the entire document, only check nodes affected by the transactions. Will
75
- // also probably require checking nodes affected by the previous transaction too.
76
- // We didn't get this to work yet:
77
- // const transform = combineTransactionSteps(oldState.doc, [transaction]);
78
- // // const { mapping } = transform;
79
- // const changes = getChangedRanges(transform);
80
- //
81
- // changes.forEach(({ oldRange, newRange }) => {
82
- // const oldNodes = findChildrenInRange(
83
- // oldState.doc,
84
- // oldRange,
85
- // (node) => node.attrs.id
86
- // );
87
- //
88
- // const newNodes = findChildrenInRange(
89
- // newState.doc,
90
- // newRange,
91
- // (node) => node.attrs.id
92
- // );
74
+ // Only check nodes affected by the transaction, not the entire document.
75
+ // changedRange() is O(steps) unlike tiptap's getChangedRanges which is O(steps²).
76
+ const newRange = transaction.changedRange();
77
+ if (!newRange) {
78
+ return prev;
79
+ }
80
+
81
+ // Map the new-doc range back to old-doc coordinates
82
+ const invertedMapping = transaction.mapping.invert();
83
+ const oldRange = {
84
+ from: invertedMapping.map(newRange.from, -1),
85
+ to: invertedMapping.map(newRange.to, 1),
86
+ };
93
87
 
94
88
  const currentTransactionOriginalOldBlockAttrs = {} as any;
95
89
 
96
- const oldNodes = findChildren(
90
+ const oldNodes = findChildrenInRange(
97
91
  oldState.doc,
92
+ oldRange,
98
93
  (node) => node.attrs.id,
99
94
  );
100
95
  const oldNodesById = new Map(
101
96
  oldNodes.map((node) => [node.node.attrs.id, node]),
102
97
  );
103
- const newNodes = findChildren(
98
+ const newNodes = findChildrenInRange(
104
99
  newState.doc,
100
+ newRange,
105
101
  (node) => node.attrs.id,
106
102
  );
107
103
 
108
- // Traverses all block containers in the new editor state.
109
104
  for (const node of newNodes) {
110
105
  const oldNode = oldNodesById.get(node.node.attrs.id);
111
106
 
@@ -127,27 +122,22 @@ export const PreviousBlockTypeExtension = createExtension(() => {
127
122
  depth: oldState.doc.resolve(oldNode.pos).depth,
128
123
  };
129
124
 
130
- currentTransactionOriginalOldBlockAttrs[node.node.attrs.id] =
131
- oldAttrs;
125
+ currentTransactionOriginalOldBlockAttrs[
126
+ node.node.attrs.id
127
+ ] = oldAttrs;
132
128
 
133
129
  prev.currentTransactionOldBlockAttrs[node.node.attrs.id] =
134
130
  oldAttrs;
135
131
 
136
- // TODO: faster deep equal?
137
- if (JSON.stringify(oldAttrs) !== JSON.stringify(newAttrs)) {
132
+ if (
133
+ oldAttrs.index !== newAttrs.index ||
134
+ oldAttrs.level !== newAttrs.level ||
135
+ oldAttrs.type !== newAttrs.type ||
136
+ oldAttrs.depth !== newAttrs.depth
137
+ ) {
138
138
  (oldAttrs as any)["depth-change"] =
139
139
  oldAttrs.depth - newAttrs.depth;
140
140
 
141
- // for debugging:
142
- // console.log(
143
- // "id:",
144
- // node.node.attrs.id,
145
- // "previousBlockTypePlugin changes detected, oldAttrs",
146
- // oldAttrs,
147
- // "new",
148
- // newAttrs
149
- // );
150
-
151
141
  prev.updatedBlocks.add(node.node.attrs.id);
152
142
  }
153
143
  }
@@ -186,17 +176,11 @@ export const PreviousBlockTypeExtension = createExtension(() => {
186
176
  val || "none";
187
177
  }
188
178
 
189
- // for debugging:
190
- // console.log(
191
- // "previousBlockTypePlugin committing decorations",
192
- // decorationAttrs
193
- // );
194
-
195
- const decoration = Decoration.node(pos, pos + node.nodeSize, {
196
- ...decorationAttrs,
197
- });
198
-
199
- decorations.push(decoration);
179
+ decorations.push(
180
+ Decoration.node(pos, pos + node.nodeSize, {
181
+ ...decorationAttrs,
182
+ }),
183
+ );
200
184
  });
201
185
 
202
186
  return DecorationSet.create(state.doc, decorations);
@@ -612,9 +612,6 @@ export class SideMenuView<
612
612
  this.mousePos.y > editorOuterBoundingBox.top &&
613
613
  this.mousePos.y < editorOuterBoundingBox.bottom;
614
614
 
615
- // TODO: remove parentElement, but then we need to remove padding from boundingbox or find a different solution
616
- const editorWrapper = this.pmView.dom!.parentElement!;
617
-
618
615
  // Doesn't update if the mouse hovers an element that's over the editor but
619
616
  // isn't a part of it or the side menu.
620
617
  if (
@@ -623,11 +620,8 @@ export class SideMenuView<
623
620
  // An element is hovered
624
621
  event &&
625
622
  event.target &&
626
- // Element is outside the editor
627
- !(
628
- editorWrapper === event.target ||
629
- editorWrapper.contains(event.target as HTMLElement)
630
- )
623
+ // Element is outside this editor and its portaled UI
624
+ !this.editor.isWithinEditor(event.target as HTMLElement)
631
625
  ) {
632
626
  if (this.state?.show) {
633
627
  this.state.show = false;
@@ -784,5 +778,17 @@ export const SideMenuExtension = createExtension(({ editor }) => {
784
778
  view!.state!.show = false;
785
779
  view!.emitUpdate(view!.state!);
786
780
  },
781
+
782
+ /**
783
+ * Hides the side menu unless it is currently frozen (e.g. the drag
784
+ * handle menu is open). Used to dismiss the menu on scroll without
785
+ * interfering with open submenus.
786
+ */
787
+ hideMenuIfNotFrozen() {
788
+ if (!view!.menuFrozen && view!.state!.show) {
789
+ view!.state!.show = false;
790
+ view!.emitUpdate(view!.state!);
791
+ }
792
+ },
787
793
  } as const;
788
794
  });
@@ -908,6 +908,20 @@ export const TableHandlesExtension = createExtension(({ editor }) => {
908
908
  view!.menuFrozen = false;
909
909
  },
910
910
 
911
+ /**
912
+ * Hides the table handles unless they are currently frozen (e.g. a
913
+ * handle menu is open). Used to dismiss the handles on scroll without
914
+ * interfering with open submenus.
915
+ */
916
+ hideHandlesIfNotFrozen() {
917
+ if (!view!.menuFrozen && view!.state?.show) {
918
+ view!.state.show = false;
919
+ view!.state.showAddOrRemoveRowsButton = false;
920
+ view!.state.showAddOrRemoveColumnsButton = false;
921
+ view!.emitUpdate();
922
+ }
923
+ },
924
+
911
925
  getCellsAtRowHandle(
912
926
  block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>,
913
927
  relativeRowIndex: RelativeCellIndices["row"],
@@ -9,7 +9,11 @@ import {
9
9
  getPrevBlockInfo,
10
10
  mergeBlocksCommand,
11
11
  } from "../../../api/blockManipulation/commands/mergeBlocks/mergeBlocks.js";
12
- import { nestBlock } from "../../../api/blockManipulation/commands/nestBlock/nestBlock.js";
12
+ import {
13
+ liftItem,
14
+ nestBlock,
15
+ unnestBlock,
16
+ } from "../../../api/blockManipulation/commands/nestBlock/nestBlock.js";
13
17
  import { fixColumnList } from "../../../api/blockManipulation/commands/replaceBlocks/util/fixColumnList.js";
14
18
  import { splitBlockCommand } from "../../../api/blockManipulation/commands/splitBlock/splitBlock.js";
15
19
  import { updateBlockCommand } from "../../../api/blockManipulation/commands/updateBlock/updateBlock.js";
@@ -63,7 +67,7 @@ export const KeyboardShortcutsExtension = Extension.create<{
63
67
  }),
64
68
  // Removes a level of nesting if the block is indented if the selection is at the start of the block.
65
69
  () =>
66
- commands.command(({ state }) => {
70
+ commands.command(({ state, tr }) => {
67
71
  const blockInfo = getBlockInfoFromSelection(state);
68
72
  if (!blockInfo.isBlockContainer) {
69
73
  return false;
@@ -74,7 +78,11 @@ export const KeyboardShortcutsExtension = Extension.create<{
74
78
  state.selection.from === blockContent.beforePos + 1;
75
79
 
76
80
  if (selectionAtBlockStart) {
77
- return commands.liftListItem("blockContainer");
81
+ return liftItem(
82
+ tr,
83
+ tr.doc.type.schema.nodes["blockContainer"],
84
+ tr.doc.type.schema.nodes["blockGroup"],
85
+ );
78
86
  }
79
87
 
80
88
  return false;
@@ -128,6 +136,13 @@ export const KeyboardShortcutsExtension = Extension.create<{
128
136
  return false;
129
137
  }
130
138
 
139
+ const selectionAtBlockStart =
140
+ state.selection.from ===
141
+ blockInfo.blockContent.beforePos + 1;
142
+ if (!selectionAtBlockStart) {
143
+ return false;
144
+ }
145
+
131
146
  const prevBlockInfo = getPrevBlockInfo(
132
147
  state.doc,
133
148
  blockInfo.bnBlock.beforePos,
@@ -226,13 +241,26 @@ export const KeyboardShortcutsExtension = Extension.create<{
226
241
  state.doc,
227
242
  blockInfo.bnBlock.beforePos,
228
243
  );
229
- if (!prevBlockInfo || !prevBlockInfo.isBlockContainer) {
244
+ if (!prevBlockInfo) {
245
+ return false;
246
+ }
247
+ const bottomNestedPrevBlockInfo = getBottomNestedBlockInfo(
248
+ state.doc,
249
+ prevBlockInfo,
250
+ );
251
+ if (!bottomNestedPrevBlockInfo.isBlockContainer) {
252
+ return false;
253
+ }
254
+ if (
255
+ !bottomNestedPrevBlockInfo ||
256
+ !bottomNestedPrevBlockInfo.isBlockContainer
257
+ ) {
230
258
  return false;
231
259
  }
232
260
 
233
261
  let chainedCommands = chain();
234
262
 
235
- // Moves the children of the current block to the previous one.
263
+ // Moves the children the current block.
236
264
  if (blockInfo.childContainer) {
237
265
  chainedCommands.insertContentAt(
238
266
  blockInfo.bnBlock.afterPos,
@@ -241,8 +269,8 @@ export const KeyboardShortcutsExtension = Extension.create<{
241
269
  }
242
270
 
243
271
  if (
244
- prevBlockInfo.blockContent.node.type.spec.content ===
245
- "tableRow+"
272
+ bottomNestedPrevBlockInfo.blockContent.node.type.spec
273
+ .content === "tableRow+"
246
274
  ) {
247
275
  const tableBlockEndPos = blockInfo.bnBlock.beforePos - 1;
248
276
  const tableBlockContentEndPos = tableBlockEndPos - 1;
@@ -254,17 +282,18 @@ export const KeyboardShortcutsExtension = Extension.create<{
254
282
  lastCellParagraphEndPos,
255
283
  );
256
284
  } else if (
257
- prevBlockInfo.blockContent.node.type.spec.content === ""
285
+ bottomNestedPrevBlockInfo.blockContent.node.type.spec
286
+ .content === ""
258
287
  ) {
259
288
  chainedCommands = chainedCommands.setNodeSelection(
260
- prevBlockInfo.blockContent.beforePos,
289
+ bottomNestedPrevBlockInfo.blockContent.beforePos,
261
290
  );
262
291
  } else {
263
- const blockContentStartPos =
264
- prevBlockInfo.blockContent.afterPos - 1;
292
+ const blockContentEndPos =
293
+ bottomNestedPrevBlockInfo.blockContent.afterPos - 1;
265
294
 
266
295
  chainedCommands =
267
- chainedCommands.setTextSelection(blockContentStartPos);
296
+ chainedCommands.setTextSelection(blockContentEndPos);
268
297
  }
269
298
 
270
299
  return chainedCommands
@@ -440,8 +469,8 @@ export const KeyboardShortcutsExtension = Extension.create<{
440
469
 
441
470
  return false;
442
471
  }),
443
- // If the previous block is a columnList, moves the current block to
444
- // the end of the last column in it.
472
+ // If the next block is a columnList, moves the first block from its
473
+ // first column to after the current block.
445
474
  () =>
446
475
  commands.command(({ state, tr, dispatch }) => {
447
476
  const blockInfo = getBlockInfoFromSelection(state);
@@ -449,6 +478,13 @@ export const KeyboardShortcutsExtension = Extension.create<{
449
478
  return false;
450
479
  }
451
480
 
481
+ const selectionAtBlockEnd =
482
+ state.selection.from ===
483
+ blockInfo.blockContent.afterPos - 1;
484
+ if (!selectionAtBlockEnd) {
485
+ return false;
486
+ }
487
+
452
488
  const nextBlockInfo = getNextBlockInfo(
453
489
  state.doc,
454
490
  blockInfo.bnBlock.beforePos,
@@ -734,7 +770,7 @@ export const KeyboardShortcutsExtension = Extension.create<{
734
770
  // Removes a level of nesting if the block is empty & indented, while the selection is also empty & at the start
735
771
  // of the block.
736
772
  () =>
737
- commands.command(({ state }) => {
773
+ commands.command(({ state, tr }) => {
738
774
  const blockInfo = getBlockInfoFromSelection(state);
739
775
  if (!blockInfo.isBlockContainer) {
740
776
  return false;
@@ -756,7 +792,11 @@ export const KeyboardShortcutsExtension = Extension.create<{
756
792
  blockEmpty &&
757
793
  blockIndented
758
794
  ) {
759
- return commands.liftListItem("blockContainer");
795
+ return liftItem(
796
+ tr,
797
+ tr.doc.type.schema.nodes["blockContainer"],
798
+ tr.doc.type.schema.nodes["blockGroup"],
799
+ );
760
800
  }
761
801
 
762
802
  return false;
@@ -926,7 +966,7 @@ export const KeyboardShortcutsExtension = Extension.create<{
926
966
  // don't handle tabs if a toolbar is shown, so we can tab into / out of it
927
967
  return false;
928
968
  }
929
- return this.editor.commands.liftListItem("blockContainer");
969
+ return unnestBlock(this.options.editor);
930
970
  },
931
971
  "Shift-Mod-ArrowUp": () => {
932
972
  this.options.editor.moveBlocksUp();
@@ -51,6 +51,9 @@ const UniqueID = Extension.create({
51
51
  attributeName: "id",
52
52
  types: [],
53
53
  setIdAttribute: false,
54
+ isWithinEditor: undefined as
55
+ | ((element: Element) => boolean)
56
+ | undefined,
54
57
  generateID: () => {
55
58
  // Use mock ID if tests are running.
56
59
  if (typeof window !== "undefined" && (window as any).__TEST_OPTIONS) {
@@ -128,6 +131,7 @@ const UniqueID = Extension.create({
128
131
  // view.dispatch(tr);
129
132
  // },
130
133
  addProseMirrorPlugins() {
134
+ const { isWithinEditor } = this.options;
131
135
  let dragSourceElement: any = null;
132
136
  let transformPasted = false;
133
137
  return [
@@ -228,14 +232,11 @@ const UniqueID = Extension.create({
228
232
  // we register a global drag handler to track the current drag source element
229
233
  view(view) {
230
234
  const handleDragstart = (event: any) => {
231
- let _a;
232
- dragSourceElement = (
233
- (_a = view.dom.parentElement) === null || _a === void 0
234
- ? void 0
235
- : _a.contains(event.target)
236
- )
237
- ? view.dom.parentElement
238
- : null;
235
+ const editorParent = view.dom.parentElement;
236
+ const isFromEditor =
237
+ editorParent?.contains(event.target) ||
238
+ isWithinEditor?.(event.target);
239
+ dragSourceElement = isFromEditor ? editorParent : null;
239
240
  };
240
241
  window.addEventListener("dragstart", handleDragstart);
241
242
  return {
package/src/index.ts CHANGED
@@ -29,7 +29,7 @@ export type { CodeBlockOptions } from "./blocks/Code/block.js";
29
29
  export { assertEmpty, UnreachableCaseError } from "./util/typescript.js";
30
30
 
31
31
  export * from "./util/EventEmitter.js";
32
- // for testing from react (TODO: move):
32
+ // for testing from react (TODO: move)
33
33
  // Unit testing
34
34
  export { selectedFragmentToHTML } from "./api/clipboard/toClipboard/copyExtension.js";
35
35
 
@@ -211,15 +211,19 @@ export function addNodeAndExtensionsToSpec<
211
211
  editor as any,
212
212
  );
213
213
 
214
+ // Cast needed because render returns `dom: HTMLElement | DocumentFragment`
215
+ // but tiptap's NodeView expects `dom: HTMLElement`
216
+ const typedNodeView = nodeView as unknown as NodeView;
217
+
214
218
  if (blockImplementation.meta?.selectable === false) {
215
- applyNonSelectableBlockFix(nodeView, this.editor);
219
+ applyNonSelectableBlockFix(typedNodeView, this.editor);
216
220
  }
217
221
 
218
222
  // See explanation for why `update` is not implemented for NodeViews
219
223
  // https://github.com/TypeCellOS/BlockNote/pull/1904#discussion_r2313461464
220
224
  // TODO: in a future version, we might want to implement updates so that
221
225
  // vanilla blocks don't always re-render entirely (https://github.com/TypeCellOS/BlockNote/issues/220)
222
- return nodeView;
226
+ return typedNodeView;
223
227
  };
224
228
  },
225
229
  });
@@ -15,7 +15,6 @@ export type InlineContentConfig = CustomInlineContentConfig | "text" | "link";
15
15
 
16
16
  // InlineContentImplementation contains the "implementation" info about an InlineContent element
17
17
  // such as the functions / Nodes required to render and / or serialize it
18
- // @ts-ignore
19
18
  export type InlineContentImplementation<T extends InlineContentConfig> =
20
19
  T extends "link" | "text"
21
20
  ? undefined
package/src/vite-env.d.ts CHANGED
@@ -1 +1,7 @@
1
1
  /// <reference types="vite/client" />
2
+
3
+ declare const process: {
4
+ env: {
5
+ NODE_ENV: string;
6
+ };
7
+ };
@@ -1,5 +1,18 @@
1
+ import { NodeType } from "prosemirror-model";
2
+ import { Transaction } from "prosemirror-state";
1
3
  import { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
2
4
  export declare function nestBlock(editor: BlockNoteEditor<any, any, any>): boolean;
3
- export declare function unnestBlock(editor: BlockNoteEditor<any, any, any>): void;
5
+ /**
6
+ * Modified version of prosemirror-schema-list's liftListItem.
7
+ * https://github.com/ProseMirror/prosemirror-schema-list/blob/master/src/schema-list.ts
8
+ *
9
+ * Changes from the original:
10
+ * 1. Range predicate checks node.type instead of firstChild.type (same as sinkItem)
11
+ * 2. Passes groupType to liftToOuterList
12
+ * 3. Operates on Transaction directly instead of state+dispatch
13
+ * 4. Skips liftOutOfList (root-level blocks can't be unnested in BlockNote)
14
+ */
15
+ export declare function liftItem(tr: Transaction, itemType: NodeType, groupType: NodeType): boolean;
16
+ export declare function unnestBlock(editor: BlockNoteEditor<any, any, any>): boolean;
4
17
  export declare function canNestBlock(editor: BlockNoteEditor<any, any, any>): boolean;
5
18
  export declare function canUnnestBlock(editor: BlockNoteEditor<any, any, any>): boolean;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Normalizes whitespace in HTML text nodes to match standard CSS
3
+ * white-space:normal behavior. Skipped for Notion HTML which intentionally
4
+ * uses `\n` for hard breaks.
5
+ */
6
+ export declare function preprocessHTMLWhitespace(element: HTMLElement): void;
@@ -367,6 +367,19 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
367
367
  */
368
368
  get prosemirrorView(): import("prosemirror-view").EditorView;
369
369
  get domElement(): HTMLDivElement | undefined;
370
+ private _portalElement;
371
+ /**
372
+ * The portal container element at `document.body` used by floating UI
373
+ * elements (menus, toolbars) to escape overflow:hidden ancestors.
374
+ * Set by BlockNoteView; undefined in headless mode.
375
+ */
376
+ get portalElement(): HTMLElement;
377
+ /**
378
+ * Checks whether a DOM element belongs to this editor — either inside the
379
+ * editor's DOM tree or inside its portal container (used for floating UI
380
+ * elements like menus and toolbars).
381
+ */
382
+ isWithinEditor: (element: Element) => boolean;
370
383
  isFocused(): boolean;
371
384
  get headless(): boolean;
372
385
  /**
@@ -0,0 +1 @@
1
+ export {};
@@ -125,4 +125,10 @@ export declare const SideMenuExtension: (options?: any) => import("../../index.j
125
125
  * mouse cursor.
126
126
  */
127
127
  readonly unfreezeMenu: () => void;
128
+ /**
129
+ * Hides the side menu unless it is currently frozen (e.g. the drag
130
+ * handle menu is open). Used to dismiss the menu on scroll without
131
+ * interfering with open submenus.
132
+ */
133
+ readonly hideMenuIfNotFrozen: () => void;
128
134
  }>;
@@ -76,6 +76,12 @@ export declare const TableHandlesExtension: (options?: any) => import("../../ind
76
76
  * same cell regardless of which cell is hovered by the mouse cursor.
77
77
  */
78
78
  readonly unfreezeHandles: () => void;
79
+ /**
80
+ * Hides the table handles unless they are currently frozen (e.g. a
81
+ * handle menu is open). Used to dismiss the handles on scroll without
82
+ * interfering with open submenus.
83
+ */
84
+ readonly hideHandlesIfNotFrozen: () => void;
79
85
  readonly getCellsAtRowHandle: (block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>, relativeRowIndex: RelativeCellIndices["row"]) => (RelativeCellIndices & {
80
86
  cell: import("../../index.js").TableCell<any, any>;
81
87
  })[];
@@ -1,2 +0,0 @@
1
- "use strict";const c=require("@tanstack/store"),e=Symbol("originalFactory");function u(t){if(typeof t=="object"&&"key"in t)return function n(){return t[e]=n,t};if(typeof t!="function")throw new Error("factory must be a function");return function n(o){return i=>{const r=t({editor:i.editor,options:o});return r[e]=n,r}}}function s(t,n){return new c.Store(t,n)}exports.createExtension=u;exports.createStore=s;exports.originalFactorySymbol=e;
2
- //# sourceMappingURL=BlockNoteExtension-BWw0r8Gy.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BlockNoteExtension-BWw0r8Gy.cjs","sources":["../src/editor/managers/ExtensionManager/symbol.ts","../src/editor/BlockNoteExtension.ts"],"sourcesContent":["/**\n * Symbol used to track the original factory function for extensions.\n * This allows us to retrieve the original factory for comparison and other operations.\n */\nexport const originalFactorySymbol = Symbol(\"originalFactory\");\n","import { Store, StoreOptions } from \"@tanstack/store\";\nimport { type AnyExtension } from \"@tiptap/core\";\nimport type { Plugin as ProsemirrorPlugin } from \"prosemirror-state\";\nimport type { PartialBlockNoDefaults } from \"../schema/index.js\";\nimport type { BlockNoteEditor } from \"./BlockNoteEditor.js\";\nimport { originalFactorySymbol } from \"./managers/ExtensionManager/symbol.js\";\n\n/**\n * This function is called when the extension is destroyed.\n */\ntype OnDestroy = () => void;\n\n/**\n * Describes a BlockNote extension.\n */\nexport interface Extension<State = any, Key extends string = string> {\n /**\n * The unique identifier for the extension.\n */\n readonly key: Key;\n\n /**\n * Triggered when the extension is mounted to the editor.\n */\n readonly mount?: (ctx: {\n /**\n * The DOM element that the editor is mounted to.\n */\n dom: HTMLElement;\n /**\n * The root document of the {@link document} that the editor is mounted to.\n */\n root: Document | ShadowRoot;\n /**\n * An {@link AbortSignal} that will be aborted when the extension is destroyed.\n */\n signal: AbortSignal;\n }) => void | OnDestroy;\n\n /**\n * The store for the extension.\n */\n readonly store?: Store<State>;\n\n /**\n * Declares what {@link Extension}s that this extension depends on.\n */\n readonly runsBefore?: ReadonlyArray<string>;\n\n /**\n * Input rules for a block: An input rule is what is used to replace text in a block when a regular expression match is found.\n * As an example, typing `#` in a paragraph block will trigger an input rule to replace the text with a heading block.\n */\n readonly inputRules?: ReadonlyArray<InputRule>;\n\n /**\n * A mapping of a keyboard shortcut to a function that will be called when the shortcut is pressed\n *\n * The keys are in the format:\n * - Key names may be strings like `Shift-Ctrl-Enter`—a key identifier prefixed with zero or more modifiers\n * - Key identifiers are based on the strings that can appear in KeyEvent.key\n * - Use lowercase letters to refer to letter keys (or uppercase letters if you want shift to be held)\n * - You may use `Space` as an alias for the \" \" name\n * - Modifiers can be given in any order: `Shift-` (or `s-`), `Alt-` (or `a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or `Meta-`)\n * - For characters that are created by holding shift, the Shift- prefix is implied, and should not be added explicitly\n * - You can use Mod- as a shorthand for Cmd- on Mac and Ctrl- on other platforms\n *\n * @example\n * ```typescript\n * keyboardShortcuts: {\n * \"Mod-Enter\": (ctx) => { return true; },\n * \"Shift-Ctrl-Space\": (ctx) => { return true; },\n * \"a\": (ctx) => { return true; },\n * \"Space\": (ctx) => { return true; }\n * }\n * ```\n */\n readonly keyboardShortcuts?: Record<\n string,\n (ctx: { editor: BlockNoteEditor<any, any, any> }) => boolean\n >;\n\n /**\n * Add additional prosemirror plugins to the editor.\n */\n readonly prosemirrorPlugins?: ReadonlyArray<ProsemirrorPlugin>;\n\n /**\n * Add additional tiptap extensions to the editor.\n */\n readonly tiptapExtensions?: ReadonlyArray<AnyExtension>;\n\n /**\n * Add additional BlockNote extensions to the editor.\n */\n readonly blockNoteExtensions?: ReadonlyArray<ExtensionFactoryInstance>;\n}\n\n/**\n * An input rule is what is used to replace text in a block when a regular expression match is found.\n * As an example, typing `#` in a paragraph block will trigger an input rule to replace the text with a heading block.\n */\ntype InputRule = {\n /**\n * The regex to match when to trigger the input rule\n */\n find: RegExp;\n /**\n * The function to call when the input rule is matched\n * @returns undefined if the input rule should not be triggered, or an object with the type and props to update the block\n */\n replace: (props: {\n /**\n * The result of the regex match\n */\n match: RegExpMatchArray;\n // TODO this will be a Point, when we have the Location API\n /**\n * The range of the text that was matched\n */\n range: { from: number; to: number };\n /**\n * The editor instance\n */\n editor: BlockNoteEditor<any, any, any>;\n }) => undefined | PartialBlockNoDefaults<any, any, any>;\n};\n\n/**\n * These are the arguments that are passed to an {@link ExtensionFactoryInstance}.\n */\nexport interface ExtensionOptions<\n Options extends Record<string, any> | undefined =\n | Record<string, any>\n | undefined,\n> {\n options: Options;\n editor: BlockNoteEditor<any, any, any>;\n}\n\n// a type that maps the extension key to the return type of the extension factory\nexport type ExtensionMap<T extends ReadonlyArray<ExtensionFactoryInstance>> = {\n [K in T[number] extends ExtensionFactoryInstance<infer Ext>\n ? Ext[\"key\"]\n : never]: T[number] extends ExtensionFactoryInstance<infer Ext>\n ? Ext\n : never;\n};\n\n/**\n * This is a type that represents the function which will actually create the extension.\n * It requires the editor instance to be passed in, but will already have the options applied automatically.\n *\n * @note Only the BlockNoteEditor should instantiate this function, not the user. Look at {@link createExtension} for user-facing functions.\n */\nexport type ExtensionFactoryInstance<\n Ext extends Extension<any, any> = Extension<any, any>,\n> = (ctx: Omit<ExtensionOptions<any>, \"options\">) => Ext;\n\n/**\n * This is the return type of the {@link createExtension} function.\n * It is a function that can be invoked with the extension's options to create a new extension factory.\n */\nexport type ExtensionFactory<\n State = any,\n Key extends string = string,\n Factory extends (ctx: any) => Extension<State, Key> = (\n ctx: ExtensionOptions<any>,\n ) => Extension<State, Key>,\n> =\n Parameters<Factory>[0] extends ExtensionOptions<infer Options>\n ? undefined extends Options\n ? (\n options?: Exclude<Options, undefined>,\n ) => ExtensionFactoryInstance<ReturnType<Factory>>\n : (options: Options) => ExtensionFactoryInstance<ReturnType<Factory>>\n : () => ExtensionFactoryInstance<ReturnType<Factory>>;\n\n/**\n * Constructs a BlockNote {@link ExtensionFactory} from a factory function or object\n */\n// This overload is for `createExtension({ key: \"test\", ... })`\nexport function createExtension<\n const State = any,\n const Key extends string = string,\n const Ext extends Extension<State, Key> = Extension<State, Key>,\n>(factory: Ext): ExtensionFactoryInstance<Ext>;\n// This overload is for `createExtension(({editor, options}) => ({ key: \"test\", ... }))`\nexport function createExtension<\n const State = any,\n const Options extends Record<string, any> | undefined = any,\n const Key extends string = string,\n const Factory extends (ctx: any) => Extension<State, Key> = (\n ctx: ExtensionOptions<Options>,\n ) => Extension<State, Key>,\n>(factory: Factory): ExtensionFactory<State, Key, Factory>;\n// This overload is for both of the above overloads as it is the implementation of the function\nexport function createExtension<\n const State = any,\n const Options extends Record<string, any> | undefined = any,\n const Key extends string = string,\n const Factory extends\n | Extension<State, Key>\n | ((ctx: any) => Extension<State, Key>) = (\n ctx: ExtensionOptions<Options>,\n ) => Extension<State, Key>,\n>(\n factory: Factory,\n): Factory extends Extension<State, Key>\n ? ExtensionFactoryInstance<Factory>\n : Factory extends (ctx: any) => Extension<State, Key>\n ? ExtensionFactory<State, Key, Factory>\n : never {\n if (typeof factory === \"object\" && \"key\" in factory) {\n return function factoryFn() {\n (factory as any)[originalFactorySymbol] = factoryFn;\n return factory;\n } as any;\n }\n\n if (typeof factory !== \"function\") {\n throw new Error(\"factory must be a function\");\n }\n\n return function factoryFn(options: Options) {\n return (ctx: { editor: BlockNoteEditor<any, any, any> }) => {\n const extension = factory({ editor: ctx.editor, options });\n // We stick a symbol onto the extension to allow us to retrieve the original factory for comparison later.\n // This enables us to do things like: `editor.getExtension(YSync).prosemirrorPlugins`\n (extension as any)[originalFactorySymbol] = factoryFn;\n return extension;\n };\n } as any;\n}\n\nexport function createStore<T = any>(\n initialState: T,\n options?: StoreOptions<T>,\n): Store<T> {\n return new Store(initialState, options);\n}\n"],"names":["originalFactorySymbol","createExtension","factory","factoryFn","options","ctx","extension","createStore","initialState","Store"],"mappings":"gDAIaA,EAAwB,OAAO,iBAAiB,ECiMtD,SAASC,EAUdC,EAKU,CACV,GAAI,OAAOA,GAAY,UAAY,QAASA,EAC1C,OAAO,SAASC,GAAY,CACzB,OAAAD,EAAgBF,CAAqB,EAAIG,EACnCD,CACT,EAGF,GAAI,OAAOA,GAAY,WACrB,MAAM,IAAI,MAAM,4BAA4B,EAG9C,OAAO,SAASC,EAAUC,EAAkB,CAC1C,OAAQC,GAAoD,CAC1D,MAAMC,EAAYJ,EAAQ,CAAE,OAAQG,EAAI,OAAQ,QAAAD,EAAS,EAGxD,OAAAE,EAAkBN,CAAqB,EAAIG,EACrCG,CACT,CACF,CACF,CAEO,SAASC,EACdC,EACAJ,EACU,CACV,OAAO,IAAIK,EAAAA,MAAMD,EAAcJ,CAAO,CACxC"}
@@ -1,25 +0,0 @@
1
- import { Store as u } from "@tanstack/store";
2
- const r = Symbol("originalFactory");
3
- function a(n) {
4
- if (typeof n == "object" && "key" in n)
5
- return function t() {
6
- return n[r] = t, n;
7
- };
8
- if (typeof n != "function")
9
- throw new Error("factory must be a function");
10
- return function t(e) {
11
- return (i) => {
12
- const o = n({ editor: i.editor, options: e });
13
- return o[r] = t, o;
14
- };
15
- };
16
- }
17
- function f(n, t) {
18
- return new u(n, t);
19
- }
20
- export {
21
- f as a,
22
- a as c,
23
- r as o
24
- };
25
- //# sourceMappingURL=BlockNoteExtension-C2X7LW-V.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BlockNoteExtension-C2X7LW-V.js","sources":["../src/editor/managers/ExtensionManager/symbol.ts","../src/editor/BlockNoteExtension.ts"],"sourcesContent":["/**\n * Symbol used to track the original factory function for extensions.\n * This allows us to retrieve the original factory for comparison and other operations.\n */\nexport const originalFactorySymbol = Symbol(\"originalFactory\");\n","import { Store, StoreOptions } from \"@tanstack/store\";\nimport { type AnyExtension } from \"@tiptap/core\";\nimport type { Plugin as ProsemirrorPlugin } from \"prosemirror-state\";\nimport type { PartialBlockNoDefaults } from \"../schema/index.js\";\nimport type { BlockNoteEditor } from \"./BlockNoteEditor.js\";\nimport { originalFactorySymbol } from \"./managers/ExtensionManager/symbol.js\";\n\n/**\n * This function is called when the extension is destroyed.\n */\ntype OnDestroy = () => void;\n\n/**\n * Describes a BlockNote extension.\n */\nexport interface Extension<State = any, Key extends string = string> {\n /**\n * The unique identifier for the extension.\n */\n readonly key: Key;\n\n /**\n * Triggered when the extension is mounted to the editor.\n */\n readonly mount?: (ctx: {\n /**\n * The DOM element that the editor is mounted to.\n */\n dom: HTMLElement;\n /**\n * The root document of the {@link document} that the editor is mounted to.\n */\n root: Document | ShadowRoot;\n /**\n * An {@link AbortSignal} that will be aborted when the extension is destroyed.\n */\n signal: AbortSignal;\n }) => void | OnDestroy;\n\n /**\n * The store for the extension.\n */\n readonly store?: Store<State>;\n\n /**\n * Declares what {@link Extension}s that this extension depends on.\n */\n readonly runsBefore?: ReadonlyArray<string>;\n\n /**\n * Input rules for a block: An input rule is what is used to replace text in a block when a regular expression match is found.\n * As an example, typing `#` in a paragraph block will trigger an input rule to replace the text with a heading block.\n */\n readonly inputRules?: ReadonlyArray<InputRule>;\n\n /**\n * A mapping of a keyboard shortcut to a function that will be called when the shortcut is pressed\n *\n * The keys are in the format:\n * - Key names may be strings like `Shift-Ctrl-Enter`—a key identifier prefixed with zero or more modifiers\n * - Key identifiers are based on the strings that can appear in KeyEvent.key\n * - Use lowercase letters to refer to letter keys (or uppercase letters if you want shift to be held)\n * - You may use `Space` as an alias for the \" \" name\n * - Modifiers can be given in any order: `Shift-` (or `s-`), `Alt-` (or `a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or `Meta-`)\n * - For characters that are created by holding shift, the Shift- prefix is implied, and should not be added explicitly\n * - You can use Mod- as a shorthand for Cmd- on Mac and Ctrl- on other platforms\n *\n * @example\n * ```typescript\n * keyboardShortcuts: {\n * \"Mod-Enter\": (ctx) => { return true; },\n * \"Shift-Ctrl-Space\": (ctx) => { return true; },\n * \"a\": (ctx) => { return true; },\n * \"Space\": (ctx) => { return true; }\n * }\n * ```\n */\n readonly keyboardShortcuts?: Record<\n string,\n (ctx: { editor: BlockNoteEditor<any, any, any> }) => boolean\n >;\n\n /**\n * Add additional prosemirror plugins to the editor.\n */\n readonly prosemirrorPlugins?: ReadonlyArray<ProsemirrorPlugin>;\n\n /**\n * Add additional tiptap extensions to the editor.\n */\n readonly tiptapExtensions?: ReadonlyArray<AnyExtension>;\n\n /**\n * Add additional BlockNote extensions to the editor.\n */\n readonly blockNoteExtensions?: ReadonlyArray<ExtensionFactoryInstance>;\n}\n\n/**\n * An input rule is what is used to replace text in a block when a regular expression match is found.\n * As an example, typing `#` in a paragraph block will trigger an input rule to replace the text with a heading block.\n */\ntype InputRule = {\n /**\n * The regex to match when to trigger the input rule\n */\n find: RegExp;\n /**\n * The function to call when the input rule is matched\n * @returns undefined if the input rule should not be triggered, or an object with the type and props to update the block\n */\n replace: (props: {\n /**\n * The result of the regex match\n */\n match: RegExpMatchArray;\n // TODO this will be a Point, when we have the Location API\n /**\n * The range of the text that was matched\n */\n range: { from: number; to: number };\n /**\n * The editor instance\n */\n editor: BlockNoteEditor<any, any, any>;\n }) => undefined | PartialBlockNoDefaults<any, any, any>;\n};\n\n/**\n * These are the arguments that are passed to an {@link ExtensionFactoryInstance}.\n */\nexport interface ExtensionOptions<\n Options extends Record<string, any> | undefined =\n | Record<string, any>\n | undefined,\n> {\n options: Options;\n editor: BlockNoteEditor<any, any, any>;\n}\n\n// a type that maps the extension key to the return type of the extension factory\nexport type ExtensionMap<T extends ReadonlyArray<ExtensionFactoryInstance>> = {\n [K in T[number] extends ExtensionFactoryInstance<infer Ext>\n ? Ext[\"key\"]\n : never]: T[number] extends ExtensionFactoryInstance<infer Ext>\n ? Ext\n : never;\n};\n\n/**\n * This is a type that represents the function which will actually create the extension.\n * It requires the editor instance to be passed in, but will already have the options applied automatically.\n *\n * @note Only the BlockNoteEditor should instantiate this function, not the user. Look at {@link createExtension} for user-facing functions.\n */\nexport type ExtensionFactoryInstance<\n Ext extends Extension<any, any> = Extension<any, any>,\n> = (ctx: Omit<ExtensionOptions<any>, \"options\">) => Ext;\n\n/**\n * This is the return type of the {@link createExtension} function.\n * It is a function that can be invoked with the extension's options to create a new extension factory.\n */\nexport type ExtensionFactory<\n State = any,\n Key extends string = string,\n Factory extends (ctx: any) => Extension<State, Key> = (\n ctx: ExtensionOptions<any>,\n ) => Extension<State, Key>,\n> =\n Parameters<Factory>[0] extends ExtensionOptions<infer Options>\n ? undefined extends Options\n ? (\n options?: Exclude<Options, undefined>,\n ) => ExtensionFactoryInstance<ReturnType<Factory>>\n : (options: Options) => ExtensionFactoryInstance<ReturnType<Factory>>\n : () => ExtensionFactoryInstance<ReturnType<Factory>>;\n\n/**\n * Constructs a BlockNote {@link ExtensionFactory} from a factory function or object\n */\n// This overload is for `createExtension({ key: \"test\", ... })`\nexport function createExtension<\n const State = any,\n const Key extends string = string,\n const Ext extends Extension<State, Key> = Extension<State, Key>,\n>(factory: Ext): ExtensionFactoryInstance<Ext>;\n// This overload is for `createExtension(({editor, options}) => ({ key: \"test\", ... }))`\nexport function createExtension<\n const State = any,\n const Options extends Record<string, any> | undefined = any,\n const Key extends string = string,\n const Factory extends (ctx: any) => Extension<State, Key> = (\n ctx: ExtensionOptions<Options>,\n ) => Extension<State, Key>,\n>(factory: Factory): ExtensionFactory<State, Key, Factory>;\n// This overload is for both of the above overloads as it is the implementation of the function\nexport function createExtension<\n const State = any,\n const Options extends Record<string, any> | undefined = any,\n const Key extends string = string,\n const Factory extends\n | Extension<State, Key>\n | ((ctx: any) => Extension<State, Key>) = (\n ctx: ExtensionOptions<Options>,\n ) => Extension<State, Key>,\n>(\n factory: Factory,\n): Factory extends Extension<State, Key>\n ? ExtensionFactoryInstance<Factory>\n : Factory extends (ctx: any) => Extension<State, Key>\n ? ExtensionFactory<State, Key, Factory>\n : never {\n if (typeof factory === \"object\" && \"key\" in factory) {\n return function factoryFn() {\n (factory as any)[originalFactorySymbol] = factoryFn;\n return factory;\n } as any;\n }\n\n if (typeof factory !== \"function\") {\n throw new Error(\"factory must be a function\");\n }\n\n return function factoryFn(options: Options) {\n return (ctx: { editor: BlockNoteEditor<any, any, any> }) => {\n const extension = factory({ editor: ctx.editor, options });\n // We stick a symbol onto the extension to allow us to retrieve the original factory for comparison later.\n // This enables us to do things like: `editor.getExtension(YSync).prosemirrorPlugins`\n (extension as any)[originalFactorySymbol] = factoryFn;\n return extension;\n };\n } as any;\n}\n\nexport function createStore<T = any>(\n initialState: T,\n options?: StoreOptions<T>,\n): Store<T> {\n return new Store(initialState, options);\n}\n"],"names":["originalFactorySymbol","createExtension","factory","factoryFn","options","ctx","extension","createStore","initialState","Store"],"mappings":";AAIO,MAAMA,IAAwB,OAAO,iBAAiB;ACiMtD,SAASC,EAUdC,GAKU;AACV,MAAI,OAAOA,KAAY,YAAY,SAASA;AAC1C,WAAO,SAASC,IAAY;AACzB,aAAAD,EAAgBF,CAAqB,IAAIG,GACnCD;AAAA,IACT;AAGF,MAAI,OAAOA,KAAY;AACrB,UAAM,IAAI,MAAM,4BAA4B;AAG9C,SAAO,SAASC,EAAUC,GAAkB;AAC1C,WAAO,CAACC,MAAoD;AAC1D,YAAMC,IAAYJ,EAAQ,EAAE,QAAQG,EAAI,QAAQ,SAAAD,GAAS;AAGxD,aAAAE,EAAkBN,CAAqB,IAAIG,GACrCG;AAAA,IACT;AAAA,EACF;AACF;AAEO,SAASC,EACdC,GACAJ,GACU;AACV,SAAO,IAAIK,EAAMD,GAAcJ,CAAO;AACxC;"}
@@ -1,2 +0,0 @@
1
- "use strict";var C=Object.defineProperty;var O=(t,e,n)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var a=(t,e,n)=>O(t,typeof e!="symbol"?e+"":e,n);const l=require("./defaultBlocks-Dg9kQWXm.cjs");function w(t){const e=D(t);let{roots:n,nonRoots:r}=f(e);const s=[];for(;n.size;){s.push(n);const o=new Set;for(const c of n){const i=t.get(c);if(i)for(const p of i){const m=e.get(p);if(m===void 0)continue;const S=m-1;e.set(p,S),S===0&&o.add(p)}}n=o}if(r=f(e).nonRoots,r.size)throw new Error(`Cycle(s) detected; toposort only works on acyclic graphs. Cyclic nodes: ${Array.from(r).join(", ")}`);return s}function j(t){const e=x(t);return w(e)}function D(t){const e=new Map;for(const[n,r]of t.entries()){e.has(n)||e.set(n,0);for(const s of r){const o=e.get(s)??0;e.set(s,o+1)}}return e}function f(t){const e=new Set,n=new Set;for(const[r,s]of t.entries())s===0?e.add(r):n.add(r);return{roots:e,nonRoots:n}}function x(t){const e=new Map;for(const[n,r]of t.entries()){e.has(n)||e.set(n,new Set);for(const s of r)e.has(s)||e.set(s,new Set),e.get(s).add(n)}return e}function E(){return new Map}function h(t,e,n){return t.has(e)||t.set(e,new Set),t.get(e).add(n),t}function k(t){const e=E();for(const s of t)Array.isArray(s.runsBefore)&&s.runsBefore.length>0?s.runsBefore.forEach(o=>{h(e,s.key,o)}):h(e,"default",s.key);const n=j(e),r=n.findIndex(s=>s.has("default"));return s=>91+(n.findIndex(c=>c.has(s))+r)*10}function u(t){return t&&Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0))}class g{constructor(e){a(this,"BlockNoteEditor","only for types");a(this,"Block","only for types");a(this,"PartialBlock","only for types");a(this,"inlineContentSpecs");a(this,"styleSpecs");a(this,"blockSpecs");a(this,"blockSchema");a(this,"inlineContentSchema");a(this,"styleSchema");this.opts=e;const{blockSpecs:n,inlineContentSpecs:r,styleSpecs:s,blockSchema:o,inlineContentSchema:c,styleSchema:i}=this.init();this.blockSpecs=n,this.styleSpecs=s,this.styleSchema=i,this.inlineContentSpecs=r,this.blockSchema=o,this.inlineContentSchema=c}init(){const e=k(Object.entries({...this.opts.blockSpecs,...this.opts.inlineContentSpecs,...this.opts.styleSpecs}).map(([o,c])=>{var i;return{key:o,runsBefore:((i=c.implementation)==null?void 0:i.runsBefore)??[]}})),n=Object.fromEntries(Object.entries(this.opts.blockSpecs).map(([o,c])=>[o,l.addNodeAndExtensionsToSpec(c.config,c.implementation,c.extensions,e(o))])),r=Object.fromEntries(Object.entries(this.opts.inlineContentSpecs).map(([o,c])=>{var i;return typeof c.config!="object"?[o,c]:[o,{...c,implementation:{...c.implementation,node:(i=c.implementation)==null?void 0:i.node.extend({priority:e(o)})}}]})),s=Object.fromEntries(Object.entries(this.opts.styleSpecs).map(([o,c])=>{var i;return[o,{...c,implementation:{...c.implementation,mark:(i=c.implementation)==null?void 0:i.mark.extend({priority:e(o)})}}]}));return{blockSpecs:n,blockSchema:Object.fromEntries(Object.entries(n).map(([o,c])=>[o,c.config])),inlineContentSpecs:u(r),styleSpecs:u(s),inlineContentSchema:l.getInlineContentSchemaFromSpecs(r),styleSchema:l.getStyleSchemaFromSpecs(s)}}extend(e){Object.assign(this.opts.blockSpecs,e.blockSpecs),Object.assign(this.opts.inlineContentSpecs,e.inlineContentSpecs),Object.assign(this.opts.styleSpecs,e.styleSpecs);const{blockSpecs:n,inlineContentSpecs:r,styleSpecs:s,blockSchema:o,inlineContentSchema:c,styleSchema:i}=this.init();return this.blockSpecs=n,this.styleSpecs=s,this.styleSchema=i,this.inlineContentSpecs=r,this.blockSchema=o,this.inlineContentSchema=c,this}}const y=l.createBlockConfig(()=>({type:"pageBreak",propSchema:{},content:"none"})),b=l.createBlockSpec(y,{parse(t){if(t.tagName==="DIV"&&t.hasAttribute("data-page-break"))return{}},render(){const t=document.createElement("div");return t.setAttribute("data-page-break",""),{dom:t}},toExternalHTML(){const t=document.createElement("div");return t.setAttribute("data-page-break",""),{dom:t}}}),P=t=>t.extend({blockSpecs:{pageBreak:b()}}),I=async t=>{const e=new FormData;return e.append("file",t),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:e})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")};function B(t){return"pageBreak"in t.schema.blockSchema}function v(t){const e=[];return B(t)&&e.push({...t.dictionary.slash_menu.page_break,onItemClick:()=>{l.insertOrUpdateBlockForSlashMenu(t,{type:"pageBreak"})},key:"page_break"}),e}class d extends g{static create(e){return new d({blockSpecs:(e==null?void 0:e.blockSpecs)??l.defaultBlockSpecs,inlineContentSpecs:(e==null?void 0:e.inlineContentSpecs)??l.defaultInlineContentSpecs,styleSpecs:(e==null?void 0:e.styleSpecs)??l.defaultStyleSpecs})}}exports.BlockNoteSchema=d;exports.CustomBlockNoteSchema=g;exports.checkPageBreakBlocksInSchema=B;exports.createPageBreakBlockConfig=y;exports.createPageBreakBlockSpec=b;exports.getPageBreakSlashMenuItems=v;exports.sortByDependencies=k;exports.uploadToTmpFilesDotOrg_DEV_ONLY=I;exports.withPageBreak=P;
2
- //# sourceMappingURL=BlockNoteSchema-CCs_V3lo.cjs.map