@blocknote/core 0.16.0 → 0.17.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 (248) hide show
  1. package/dist/blocknote.js +3292 -2755
  2. package/dist/blocknote.js.map +1 -1
  3. package/dist/blocknote.umd.cjs +6 -6
  4. package/dist/blocknote.umd.cjs.map +1 -1
  5. package/dist/webpack-stats.json +1 -1
  6. package/package.json +5 -2
  7. package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +3087 -0
  8. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +132 -0
  9. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +71 -0
  10. package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +2276 -0
  11. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +131 -0
  12. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +103 -0
  13. package/src/api/blockManipulation/commands/moveBlock/__snapshots__/moveBlock.test.ts.snap +3767 -0
  14. package/src/api/blockManipulation/commands/moveBlock/moveBlock.test.ts +192 -0
  15. package/src/api/blockManipulation/commands/moveBlock/moveBlock.ts +178 -0
  16. package/src/api/blockManipulation/commands/removeBlocks/__snapshots__/removeBlocks.test.ts.snap +1136 -0
  17. package/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.ts +34 -0
  18. package/src/api/blockManipulation/commands/removeBlocks/removeBlocks.ts +100 -0
  19. package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +4931 -0
  20. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +222 -0
  21. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +70 -0
  22. package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +2924 -0
  23. package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +136 -0
  24. package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +48 -0
  25. package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +8376 -0
  26. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +300 -0
  27. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +199 -0
  28. package/src/api/blockManipulation/insertContentAt.ts +96 -0
  29. package/src/api/blockManipulation/selections/textCursorPosition/__snapshots__/textCursorPosition.test.ts.snap +316 -0
  30. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +53 -0
  31. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +130 -0
  32. package/src/api/blockManipulation/setupTestEnv.ts +179 -0
  33. package/src/api/clipboard/__snapshots__/tableAllCells.html +1 -1
  34. package/src/api/clipboard/clipboard.test.ts +5 -6
  35. package/src/api/clipboard/fromClipboard/fileDropExtension.ts +8 -4
  36. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +11 -6
  37. package/src/api/clipboard/fromClipboard/pasteExtension.ts +8 -4
  38. package/src/api/clipboard/toClipboard/copyExtension.ts +113 -61
  39. package/src/api/exporters/html/__snapshots__/complex/misc/external.html +1 -1
  40. package/src/api/exporters/html/__snapshots__/lists/basic/external.html +1 -1
  41. package/src/api/exporters/html/__snapshots__/lists/nested/external.html +1 -1
  42. package/src/api/exporters/html/externalHTMLExporter.ts +42 -94
  43. package/src/api/exporters/html/htmlConversion.test.ts +19 -13
  44. package/src/api/exporters/html/internalHTMLSerializer.ts +21 -72
  45. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +263 -0
  46. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +158 -0
  47. package/src/api/exporters/markdown/markdownExporter.test.ts +10 -10
  48. package/src/api/exporters/markdown/markdownExporter.ts +11 -7
  49. package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +2 -2
  50. package/src/api/getBlockInfoFromPos.ts +172 -90
  51. package/src/api/nodeConversions/blockToNode.ts +257 -0
  52. package/src/api/nodeConversions/fragmentToBlocks.ts +60 -0
  53. package/src/api/nodeConversions/nodeConversions.test.ts +9 -8
  54. package/src/api/nodeConversions/{nodeConversions.ts → nodeToBlock.ts} +20 -262
  55. package/src/api/parsers/html/parseHTML.test.ts +2 -2
  56. package/src/api/parsers/html/parseHTML.ts +8 -4
  57. package/src/api/parsers/html/util/nestedLists.test.ts +2 -2
  58. package/src/api/parsers/markdown/parseMarkdown.test.ts +2 -2
  59. package/src/api/parsers/markdown/parseMarkdown.ts +8 -4
  60. package/src/api/testUtil/cases/customBlocks.ts +11 -11
  61. package/src/api/testUtil/cases/customInlineContent.ts +6 -6
  62. package/src/api/testUtil/cases/customStyles.ts +6 -6
  63. package/src/api/testUtil/cases/defaultSchema.ts +4 -4
  64. package/src/api/testUtil/index.ts +6 -6
  65. package/src/api/testUtil/partialBlockTestUtil.ts +5 -5
  66. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +5 -5
  67. package/src/blocks/FileBlockContent/FileBlockContent.ts +4 -4
  68. package/src/blocks/FileBlockContent/fileBlockHelpers.ts +2 -2
  69. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +61 -39
  70. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +5 -5
  71. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +30 -18
  72. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +67 -33
  73. package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +23 -19
  74. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +22 -24
  75. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +31 -19
  76. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +16 -11
  77. package/src/blocks/TableBlockContent/TableBlockContent.ts +4 -4
  78. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +5 -5
  79. package/src/blocks/defaultBlockHelpers.ts +4 -4
  80. package/src/blocks/defaultBlockTypeGuards.ts +5 -5
  81. package/src/blocks/defaultBlocks.ts +13 -13
  82. package/src/blocks/defaultProps.ts +1 -1
  83. package/src/editor/BlockNoteEditor.test.ts +14 -7
  84. package/src/editor/BlockNoteEditor.ts +82 -149
  85. package/src/editor/BlockNoteExtensions.ts +15 -11
  86. package/src/editor/BlockNoteSchema.ts +7 -7
  87. package/src/editor/BlockNoteTipTapEditor.ts +5 -3
  88. package/src/editor/cursorPositionTypes.ts +7 -2
  89. package/src/editor/selectionTypes.ts +6 -2
  90. package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +1 -1
  91. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +1 -1
  92. package/src/extensions/FilePanel/FilePanelPlugin.ts +4 -4
  93. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +8 -4
  94. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +334 -0
  95. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +9 -4
  96. package/src/extensions/{NonEditableBlocks/NonEditableBlockPlugin.ts → NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts} +2 -2
  97. package/src/extensions/Placeholder/PlaceholderPlugin.ts +1 -1
  98. package/src/extensions/SideMenu/SideMenuPlugin.ts +72 -401
  99. package/src/extensions/SideMenu/dragging.ts +251 -0
  100. package/src/extensions/SuggestionMenu/DefaultSuggestionItem.ts +1 -1
  101. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +8 -4
  102. package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +8 -4
  103. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +19 -15
  104. package/src/extensions/TableHandles/TableHandlesPlugin.ts +11 -7
  105. package/src/extensions/TextColor/TextColorExtension.ts +1 -1
  106. package/src/extensions/TextColor/TextColorMark.ts +1 -1
  107. package/src/i18n/dictionary.ts +1 -1
  108. package/src/i18n/locales/ar.ts +1 -1
  109. package/src/i18n/locales/fr.ts +1 -1
  110. package/src/i18n/locales/hr.ts +308 -0
  111. package/src/i18n/locales/index.ts +15 -14
  112. package/src/i18n/locales/is.ts +1 -1
  113. package/src/i18n/locales/ja.ts +1 -1
  114. package/src/i18n/locales/ko.ts +1 -1
  115. package/src/i18n/locales/nl.ts +1 -1
  116. package/src/i18n/locales/pl.ts +1 -1
  117. package/src/i18n/locales/pt.ts +1 -1
  118. package/src/i18n/locales/ru.ts +1 -1
  119. package/src/i18n/locales/vi.ts +1 -1
  120. package/src/i18n/locales/zh.ts +1 -1
  121. package/src/index.ts +45 -44
  122. package/src/pm-nodes/BlockContainer.ts +3 -647
  123. package/src/pm-nodes/BlockGroup.ts +2 -2
  124. package/src/pm-nodes/index.ts +3 -3
  125. package/src/schema/blocks/createSpec.ts +8 -7
  126. package/src/schema/blocks/internal.ts +9 -9
  127. package/src/schema/blocks/types.ts +4 -4
  128. package/src/schema/index.ts +10 -10
  129. package/src/schema/inlineContent/createSpec.ts +9 -10
  130. package/src/schema/inlineContent/internal.ts +3 -3
  131. package/src/schema/inlineContent/types.ts +2 -2
  132. package/src/schema/styles/createSpec.ts +4 -3
  133. package/src/schema/styles/internal.ts +1 -1
  134. package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +4 -0
  135. package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.d.ts +7 -0
  136. package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.d.ts +1 -0
  137. package/types/src/api/blockManipulation/commands/moveBlock/moveBlock.d.ts +5 -0
  138. package/types/src/api/blockManipulation/commands/moveBlock/moveBlock.test.d.ts +1 -0
  139. package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.d.ts +7 -0
  140. package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.d.ts +1 -0
  141. package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +7 -0
  142. package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.d.ts +1 -0
  143. package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +5 -0
  144. package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.test.d.ts +1 -0
  145. package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.d.ts +11 -0
  146. package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.test.d.ts +1 -0
  147. package/types/src/api/blockManipulation/insertContentAt.d.ts +6 -0
  148. package/types/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.d.ts +5 -0
  149. package/types/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.d.ts +1 -0
  150. package/types/src/api/blockManipulation/setupTestEnv.d.ts +492 -0
  151. package/types/src/api/clipboard/fromClipboard/fileDropExtension.d.ts +3 -3
  152. package/types/src/api/clipboard/fromClipboard/handleFileInsertion.d.ts +1 -1
  153. package/types/src/api/clipboard/fromClipboard/pasteExtension.d.ts +2 -2
  154. package/types/src/api/clipboard/toClipboard/copyExtension.d.ts +5 -5
  155. package/types/src/api/exporters/html/externalHTMLExporter.d.ts +7 -9
  156. package/types/src/api/exporters/html/internalHTMLSerializer.d.ts +6 -10
  157. package/types/src/api/exporters/html/util/serializeBlocksExternalHTML.d.ts +10 -0
  158. package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +11 -0
  159. package/types/src/api/exporters/markdown/markdownExporter.d.ts +3 -3
  160. package/types/src/api/getBlockInfoFromPos.d.ts +63 -20
  161. package/types/src/api/nodeConversions/blockToNode.d.ts +15 -0
  162. package/types/src/api/nodeConversions/fragmentToBlocks.d.ts +7 -0
  163. package/types/src/api/nodeConversions/nodeToBlock.d.ts +16 -0
  164. package/types/src/api/parsers/html/parseHTML.d.ts +2 -2
  165. package/types/src/api/parsers/markdown/parseMarkdown.d.ts +2 -2
  166. package/types/src/api/testUtil/cases/customBlocks.d.ts +39 -39
  167. package/types/src/api/testUtil/cases/customInlineContent.d.ts +35 -35
  168. package/types/src/api/testUtil/cases/customStyles.d.ts +35 -35
  169. package/types/src/api/testUtil/cases/defaultSchema.d.ts +2 -2
  170. package/types/src/api/testUtil/index.d.ts +6 -6
  171. package/types/src/api/testUtil/partialBlockTestUtil.d.ts +4 -4
  172. package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +4 -4
  173. package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +4 -4
  174. package/types/src/blocks/FileBlockContent/fileBlockHelpers.d.ts +2 -2
  175. package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +2 -2
  176. package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +4 -4
  177. package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +2 -2
  178. package/types/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.d.ts +2 -2
  179. package/types/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.d.ts +2 -2
  180. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +2 -2
  181. package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +2 -2
  182. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +2 -2
  183. package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +4 -4
  184. package/types/src/blocks/defaultBlockHelpers.d.ts +3 -3
  185. package/types/src/blocks/defaultBlockTypeGuards.d.ts +4 -4
  186. package/types/src/blocks/defaultBlocks.d.ts +38 -38
  187. package/types/src/blocks/defaultProps.d.ts +1 -1
  188. package/types/src/editor/BlockNoteEditor.d.ts +28 -16
  189. package/types/src/editor/BlockNoteExtensions.d.ts +3 -3
  190. package/types/src/editor/BlockNoteSchema.d.ts +4 -4
  191. package/types/src/editor/BlockNoteTipTapEditor.d.ts +2 -2
  192. package/types/src/editor/cursorPositionTypes.d.ts +3 -2
  193. package/types/src/editor/selectionTypes.d.ts +2 -2
  194. package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +1 -1
  195. package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +4 -4
  196. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +4 -4
  197. package/types/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.d.ts +5 -0
  198. package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +4 -4
  199. package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.d.ts +2 -0
  200. package/types/src/extensions/Placeholder/PlaceholderPlugin.d.ts +1 -1
  201. package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +12 -28
  202. package/types/src/extensions/SideMenu/dragging.d.ts +17 -0
  203. package/types/src/extensions/SuggestionMenu/DefaultSuggestionItem.d.ts +1 -1
  204. package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +4 -4
  205. package/types/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.d.ts +3 -3
  206. package/types/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.d.ts +4 -4
  207. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +4 -4
  208. package/types/src/extensions/TextColor/TextColorMark.d.ts +1 -1
  209. package/types/src/i18n/dictionary.d.ts +1 -1
  210. package/types/src/i18n/locales/ar.d.ts +1 -1
  211. package/types/src/i18n/locales/fr.d.ts +1 -1
  212. package/types/src/i18n/locales/hr.d.ts +239 -0
  213. package/types/src/i18n/locales/index.d.ts +15 -14
  214. package/types/src/i18n/locales/is.d.ts +1 -1
  215. package/types/src/i18n/locales/ja.d.ts +1 -1
  216. package/types/src/i18n/locales/ko.d.ts +1 -1
  217. package/types/src/i18n/locales/nl.d.ts +1 -1
  218. package/types/src/i18n/locales/pl.d.ts +1 -1
  219. package/types/src/i18n/locales/pt.d.ts +1 -1
  220. package/types/src/i18n/locales/ru.d.ts +1 -1
  221. package/types/src/i18n/locales/vi.d.ts +1 -1
  222. package/types/src/i18n/locales/zh.d.ts +1 -1
  223. package/types/src/index.d.ts +45 -44
  224. package/types/src/pm-nodes/BlockContainer.d.ts +2 -16
  225. package/types/src/pm-nodes/BlockGroup.d.ts +1 -1
  226. package/types/src/pm-nodes/index.d.ts +3 -3
  227. package/types/src/schema/blocks/createSpec.d.ts +5 -5
  228. package/types/src/schema/blocks/internal.d.ts +5 -5
  229. package/types/src/schema/blocks/types.d.ts +4 -4
  230. package/types/src/schema/index.d.ts +10 -10
  231. package/types/src/schema/inlineContent/createSpec.d.ts +3 -3
  232. package/types/src/schema/inlineContent/internal.d.ts +2 -2
  233. package/types/src/schema/inlineContent/types.d.ts +2 -2
  234. package/types/src/schema/styles/createSpec.d.ts +1 -1
  235. package/types/src/schema/styles/internal.d.ts +1 -1
  236. package/src/api/blockManipulation/__snapshots__/blockManipulation.test.ts.snap +0 -714
  237. package/src/api/blockManipulation/blockManipulation.test.ts +0 -292
  238. package/src/api/blockManipulation/blockManipulation.ts +0 -350
  239. package/src/api/exporters/html/util/sharedHTMLConversion.ts +0 -130
  240. package/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts +0 -218
  241. package/src/api/getCurrentBlockContentType.ts +0 -14
  242. package/types/src/api/blockManipulation/blockManipulation.d.ts +0 -14
  243. package/types/src/api/exporters/html/util/sharedHTMLConversion.d.ts +0 -9
  244. package/types/src/api/exporters/html/util/simplifyBlocksRehypePlugin.d.ts +0 -16
  245. package/types/src/api/getCurrentBlockContentType.d.ts +0 -2
  246. package/types/src/api/nodeConversions/nodeConversions.d.ts +0 -24
  247. package/types/src/extensions/NonEditableBlocks/NonEditableBlockPlugin.d.ts +0 -2
  248. /package/types/src/api/blockManipulation/{blockManipulation.test.d.ts → commands/insertBlocks/insertBlocks.test.d.ts} +0 -0
@@ -1,12 +1,13 @@
1
1
  import { InputRule } from "@tiptap/core";
2
+ import { updateBlockCommand } from "../../api/blockManipulation/commands/updateBlock/updateBlock.js";
3
+ import { getBlockInfoFromSelection } from "../../api/getBlockInfoFromPos.js";
2
4
  import {
3
5
  PropSchema,
4
6
  createBlockSpecFromStronglyTypedTiptapNode,
5
7
  createStronglyTypedTiptapNode,
6
- } from "../../schema";
7
- import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers";
8
- import { defaultProps } from "../defaultProps";
9
- import { getCurrentBlockContentType } from "../../api/getCurrentBlockContentType";
8
+ } from "../../schema/index.js";
9
+ import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers.js";
10
+ import { defaultProps } from "../defaultProps.js";
10
11
 
11
12
  export const headingPropSchema = {
12
13
  ...defaultProps,
@@ -46,19 +47,27 @@ const HeadingBlockContent = createStronglyTypedTiptapNode({
46
47
  return new InputRule({
47
48
  find: new RegExp(`^(#{${level}})\\s$`),
48
49
  handler: ({ state, chain, range }) => {
49
- if (getCurrentBlockContentType(this.editor) !== "inline*") {
50
+ const blockInfo = getBlockInfoFromSelection(state);
51
+ if (blockInfo.blockContent.node.type.spec.content !== "inline*") {
50
52
  return;
51
53
  }
52
54
 
53
55
  chain()
54
- .BNUpdateBlock(state.selection.from, {
55
- type: "heading",
56
- props: {
57
- level: level as any,
58
- },
59
- })
56
+ .command(
57
+ updateBlockCommand(
58
+ this.options.editor,
59
+ blockInfo.blockContainer.beforePos,
60
+ {
61
+ type: "heading",
62
+ props: {
63
+ level: level as any,
64
+ },
65
+ }
66
+ )
67
+ )
60
68
  // Removes the "#" character(s) used to set the heading.
61
- .deleteRange({ from: range.from, to: range.to });
69
+ .deleteRange({ from: range.from, to: range.to })
70
+ .run();
62
71
  },
63
72
  });
64
73
  }),
@@ -68,48 +77,61 @@ const HeadingBlockContent = createStronglyTypedTiptapNode({
68
77
  addKeyboardShortcuts() {
69
78
  return {
70
79
  "Mod-Alt-1": () => {
71
- if (getCurrentBlockContentType(this.editor) !== "inline*") {
80
+ const blockInfo = getBlockInfoFromSelection(this.editor.state);
81
+ if (blockInfo.blockContent.node.type.spec.content !== "inline*") {
72
82
  return true;
73
83
  }
74
84
 
75
- return this.editor.commands.BNUpdateBlock(
76
- this.editor.state.selection.anchor,
77
- {
78
- type: "heading",
79
- props: {
80
- level: 1 as any,
81
- },
82
- }
85
+ // call updateBlockCommand
86
+ return this.editor.commands.command(
87
+ updateBlockCommand(
88
+ this.options.editor,
89
+ blockInfo.blockContainer.beforePos,
90
+ {
91
+ type: "heading",
92
+ props: {
93
+ level: 1 as any,
94
+ },
95
+ }
96
+ )
83
97
  );
84
98
  },
85
99
  "Mod-Alt-2": () => {
86
- if (getCurrentBlockContentType(this.editor) !== "inline*") {
100
+ const blockInfo = getBlockInfoFromSelection(this.editor.state);
101
+ if (blockInfo.blockContent.node.type.spec.content !== "inline*") {
87
102
  return true;
88
103
  }
89
104
 
90
- return this.editor.commands.BNUpdateBlock(
91
- this.editor.state.selection.anchor,
92
- {
93
- type: "heading",
94
- props: {
95
- level: 2 as any,
96
- },
97
- }
105
+ return this.editor.commands.command(
106
+ updateBlockCommand(
107
+ this.options.editor,
108
+ blockInfo.blockContainer.beforePos,
109
+ {
110
+ type: "heading",
111
+ props: {
112
+ level: 2 as any,
113
+ },
114
+ }
115
+ )
98
116
  );
99
117
  },
100
118
  "Mod-Alt-3": () => {
101
- if (getCurrentBlockContentType(this.editor) !== "inline*") {
119
+ const blockInfo = getBlockInfoFromSelection(this.editor.state);
120
+ if (blockInfo.blockContent.node.type.spec.content !== "inline*") {
102
121
  return true;
103
122
  }
104
123
 
105
- return this.editor.commands.BNUpdateBlock(
106
- this.editor.state.selection.anchor,
107
- {
108
- type: "heading",
109
- props: {
110
- level: 3 as any,
111
- },
112
- }
124
+ return this.editor.commands.command(
125
+ updateBlockCommand(
126
+ this.options.editor,
127
+ blockInfo.blockContainer.beforePos,
128
+ {
129
+ type: "heading",
130
+ props: {
131
+ level: 3 as any,
132
+ },
133
+ }
134
+ )
113
135
  );
114
136
  },
115
137
  };
@@ -1,12 +1,12 @@
1
- import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
1
+ import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
2
2
  import {
3
3
  BlockFromConfig,
4
4
  createBlockSpec,
5
5
  FileBlockConfig,
6
6
  Props,
7
7
  PropSchema,
8
- } from "../../schema";
9
- import { defaultProps } from "../defaultProps";
8
+ } from "../../schema/index.js";
9
+ import { defaultProps } from "../defaultProps.js";
10
10
  import {
11
11
  createFigureWithCaption,
12
12
  createFileAndCaptionWrapper,
@@ -14,8 +14,8 @@ import {
14
14
  createLinkWithCaption,
15
15
  createResizeHandlesWrapper,
16
16
  parseFigureElement,
17
- } from "../FileBlockContent/fileBlockHelpers";
18
- import { parseImageElement } from "./imageBlockHelpers";
17
+ } from "../FileBlockContent/fileBlockHelpers.js";
18
+ import { parseImageElement } from "./imageBlockHelpers.js";
19
19
 
20
20
  export const imagePropSchema = {
21
21
  textAlignment: defaultProps.textAlignment,
@@ -1,13 +1,14 @@
1
1
  import { InputRule } from "@tiptap/core";
2
+ import { updateBlockCommand } from "../../../api/blockManipulation/commands/updateBlock/updateBlock.js";
3
+ import { getBlockInfoFromSelection } from "../../../api/getBlockInfoFromPos.js";
2
4
  import {
3
5
  PropSchema,
4
6
  createBlockSpecFromStronglyTypedTiptapNode,
5
7
  createStronglyTypedTiptapNode,
6
- } from "../../../schema";
7
- import { createDefaultBlockDOMOutputSpec } from "../../defaultBlockHelpers";
8
- import { defaultProps } from "../../defaultProps";
9
- import { handleEnter } from "../ListItemKeyboardShortcuts";
10
- import { getCurrentBlockContentType } from "../../../api/getCurrentBlockContentType";
8
+ } from "../../../schema/index.js";
9
+ import { createDefaultBlockDOMOutputSpec } from "../../defaultBlockHelpers.js";
10
+ import { defaultProps } from "../../defaultProps.js";
11
+ import { handleEnter } from "../ListItemKeyboardShortcuts.js";
11
12
 
12
13
  export const bulletListItemPropSchema = {
13
14
  ...defaultProps,
@@ -26,15 +27,22 @@ const BulletListItemBlockContent = createStronglyTypedTiptapNode({
26
27
  new InputRule({
27
28
  find: new RegExp(`^[-+*]\\s$`),
28
29
  handler: ({ state, chain, range }) => {
29
- if (getCurrentBlockContentType(this.editor) !== "inline*") {
30
+ const blockInfo = getBlockInfoFromSelection(state);
31
+ if (blockInfo.blockContent.node.type.spec.content !== "inline*") {
30
32
  return;
31
33
  }
32
34
 
33
35
  chain()
34
- .BNUpdateBlock(state.selection.from, {
35
- type: "bulletListItem",
36
- props: {},
37
- })
36
+ .command(
37
+ updateBlockCommand(
38
+ this.options.editor,
39
+ blockInfo.blockContainer.beforePos,
40
+ {
41
+ type: "bulletListItem",
42
+ props: {},
43
+ }
44
+ )
45
+ )
38
46
  // Removes the "-", "+", or "*" character used to set the list.
39
47
  .deleteRange({ from: range.from, to: range.to });
40
48
  },
@@ -44,18 +52,22 @@ const BulletListItemBlockContent = createStronglyTypedTiptapNode({
44
52
 
45
53
  addKeyboardShortcuts() {
46
54
  return {
47
- Enter: () => handleEnter(this.editor),
55
+ Enter: () => handleEnter(this.options.editor),
48
56
  "Mod-Shift-8": () => {
49
- if (getCurrentBlockContentType(this.editor) !== "inline*") {
57
+ const blockInfo = getBlockInfoFromSelection(this.editor.state);
58
+ if (blockInfo.blockContent.node.type.spec.content !== "inline*") {
50
59
  return true;
51
60
  }
52
61
 
53
- return this.editor.commands.BNUpdateBlock(
54
- this.editor.state.selection.anchor,
55
- {
56
- type: "bulletListItem",
57
- props: {},
58
- }
62
+ return this.options.editor.commands.command(
63
+ updateBlockCommand(
64
+ this.options.editor,
65
+ blockInfo.blockContainer.beforePos,
66
+ {
67
+ type: "bulletListItem",
68
+ props: {},
69
+ }
70
+ )
59
71
  );
60
72
  },
61
73
  };
@@ -1,13 +1,17 @@
1
1
  import { InputRule } from "@tiptap/core";
2
+ import { updateBlockCommand } from "../../../api/blockManipulation/commands/updateBlock/updateBlock.js";
3
+ import {
4
+ getBlockInfoFromSelection,
5
+ getNearestBlockContainerPos,
6
+ } from "../../../api/getBlockInfoFromPos.js";
2
7
  import {
3
8
  PropSchema,
4
9
  createBlockSpecFromStronglyTypedTiptapNode,
5
10
  createStronglyTypedTiptapNode,
6
- } from "../../../schema";
7
- import { createDefaultBlockDOMOutputSpec } from "../../defaultBlockHelpers";
8
- import { defaultProps } from "../../defaultProps";
9
- import { handleEnter } from "../ListItemKeyboardShortcuts";
10
- import { getCurrentBlockContentType } from "../../../api/getCurrentBlockContentType";
11
+ } from "../../../schema/index.js";
12
+ import { createDefaultBlockDOMOutputSpec } from "../../defaultBlockHelpers.js";
13
+ import { defaultProps } from "../../defaultProps.js";
14
+ import { handleEnter } from "../ListItemKeyboardShortcuts.js";
11
15
 
12
16
  export const checkListItemPropSchema = {
13
17
  ...defaultProps,
@@ -44,17 +48,24 @@ const checkListItemBlockContent = createStronglyTypedTiptapNode({
44
48
  new InputRule({
45
49
  find: new RegExp(`\\[\\s*\\]\\s$`),
46
50
  handler: ({ state, chain, range }) => {
47
- if (getCurrentBlockContentType(this.editor) !== "inline*") {
51
+ const blockInfo = getBlockInfoFromSelection(state);
52
+ if (blockInfo.blockContent.node.type.spec.content !== "inline*") {
48
53
  return;
49
54
  }
50
55
 
51
56
  chain()
52
- .BNUpdateBlock(state.selection.from, {
53
- type: "checkListItem",
54
- props: {
55
- checked: false as any,
56
- },
57
- })
57
+ .command(
58
+ updateBlockCommand(
59
+ this.options.editor,
60
+ blockInfo.blockContainer.beforePos,
61
+ {
62
+ type: "checkListItem",
63
+ props: {
64
+ checked: false as any,
65
+ },
66
+ }
67
+ )
68
+ )
58
69
  // Removes the characters used to set the list.
59
70
  .deleteRange({ from: range.from, to: range.to });
60
71
  },
@@ -62,17 +73,25 @@ const checkListItemBlockContent = createStronglyTypedTiptapNode({
62
73
  new InputRule({
63
74
  find: new RegExp(`\\[[Xx]\\]\\s$`),
64
75
  handler: ({ state, chain, range }) => {
65
- if (getCurrentBlockContentType(this.editor) !== "inline*") {
76
+ const blockInfo = getBlockInfoFromSelection(state);
77
+
78
+ if (blockInfo.blockContent.node.type.spec.content !== "inline*") {
66
79
  return;
67
80
  }
68
81
 
69
82
  chain()
70
- .BNUpdateBlock(state.selection.from, {
71
- type: "checkListItem",
72
- props: {
73
- checked: true as any,
74
- },
75
- })
83
+ .command(
84
+ updateBlockCommand(
85
+ this.options.editor,
86
+ blockInfo.blockContainer.beforePos,
87
+ {
88
+ type: "checkListItem",
89
+ props: {
90
+ checked: true as any,
91
+ },
92
+ }
93
+ )
94
+ )
76
95
  // Removes the characters used to set the list.
77
96
  .deleteRange({ from: range.from, to: range.to });
78
97
  },
@@ -82,18 +101,22 @@ const checkListItemBlockContent = createStronglyTypedTiptapNode({
82
101
 
83
102
  addKeyboardShortcuts() {
84
103
  return {
85
- Enter: () => handleEnter(this.editor),
104
+ Enter: () => handleEnter(this.options.editor),
86
105
  "Mod-Shift-9": () => {
87
- if (getCurrentBlockContentType(this.editor) !== "inline*") {
106
+ const blockInfo = getBlockInfoFromSelection(this.options.editor.state);
107
+ if (blockInfo.blockContent.node.type.spec.content !== "inline*") {
88
108
  return true;
89
109
  }
90
110
 
91
- return this.editor.commands.BNUpdateBlock(
92
- this.editor.state.selection.anchor,
93
- {
94
- type: "checkListItem",
95
- props: {},
96
- }
111
+ return this.editor.commands.command(
112
+ updateBlockCommand(
113
+ this.options.editor,
114
+ blockInfo.blockContainer.beforePos,
115
+ {
116
+ type: "checkListItem",
117
+ props: {},
118
+ }
119
+ )
97
120
  );
98
121
  },
99
122
  };
@@ -211,13 +234,24 @@ const checkListItemBlockContent = createStronglyTypedTiptapNode({
211
234
  return;
212
235
  }
213
236
 
237
+ // TODO: test
214
238
  if (typeof getPos !== "boolean") {
215
- this.editor.commands.BNUpdateBlock(getPos(), {
216
- type: "checkListItem",
217
- props: {
218
- checked: checkbox.checked as any,
219
- },
220
- });
239
+ const beforeBlockContainerPos = getNearestBlockContainerPos(
240
+ editor.state.doc,
241
+ getPos()
242
+ );
243
+ this.editor.commands.command(
244
+ updateBlockCommand(
245
+ this.options.editor,
246
+ beforeBlockContainerPos.posBeforeNode,
247
+ {
248
+ type: "checkListItem",
249
+ props: {
250
+ checked: checkbox.checked as any,
251
+ },
252
+ }
253
+ )
254
+ );
221
255
  }
222
256
  };
223
257
  checkbox.addEventListener("change", changeHandler);
@@ -1,35 +1,39 @@
1
- import { Editor } from "@tiptap/core";
2
- import { getBlockInfoFromPos } from "../../api/getBlockInfoFromPos";
1
+ import { splitBlockCommand } from "../../api/blockManipulation/commands/splitBlock/splitBlock.js";
2
+ import { updateBlockCommand } from "../../api/blockManipulation/commands/updateBlock/updateBlock.js";
3
+ import { getBlockInfoFromSelection } from "../../api/getBlockInfoFromPos.js";
4
+ import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
3
5
 
4
- export const handleEnter = (editor: Editor) => {
5
- const { contentNode, contentType } = getBlockInfoFromPos(
6
- editor.state.doc,
7
- editor.state.selection.from
8
- )!;
6
+ export const handleEnter = (editor: BlockNoteEditor<any, any, any>) => {
7
+ const ttEditor = editor._tiptapEditor;
8
+ const { blockContent, blockContainer } = getBlockInfoFromSelection(
9
+ ttEditor.state
10
+ );
9
11
 
10
12
  const selectionEmpty =
11
- editor.state.selection.anchor === editor.state.selection.head;
13
+ ttEditor.state.selection.anchor === ttEditor.state.selection.head;
12
14
 
13
15
  if (
14
16
  !(
15
- contentType.name === "bulletListItem" ||
16
- contentType.name === "numberedListItem" ||
17
- contentType.name === "checkListItem"
17
+ blockContent.node.type.name === "bulletListItem" ||
18
+ blockContent.node.type.name === "numberedListItem" ||
19
+ blockContent.node.type.name === "checkListItem"
18
20
  ) ||
19
21
  !selectionEmpty
20
22
  ) {
21
23
  return false;
22
24
  }
23
25
 
24
- return editor.commands.first(({ state, chain, commands }) => [
26
+ return ttEditor.commands.first(({ state, chain, commands }) => [
25
27
  () =>
26
28
  // Changes list item block to a paragraph block if the content is empty.
27
29
  commands.command(() => {
28
- if (contentNode.childCount === 0) {
29
- return commands.BNUpdateBlock(state.selection.from, {
30
- type: "paragraph",
31
- props: {},
32
- });
30
+ if (blockContent.node.childCount === 0) {
31
+ return commands.command(
32
+ updateBlockCommand(editor, blockContainer.beforePos, {
33
+ type: "paragraph",
34
+ props: {},
35
+ })
36
+ );
33
37
  }
34
38
 
35
39
  return false;
@@ -39,10 +43,10 @@ export const handleEnter = (editor: Editor) => {
39
43
  // Splits the current block, moving content inside that's after the cursor
40
44
  // to a new block of the same type below.
41
45
  commands.command(() => {
42
- if (contentNode.childCount > 0) {
46
+ if (blockContent.node.childCount > 0) {
43
47
  chain()
44
48
  .deleteSelection()
45
- .BNSplitBlock(state.selection.from, true)
49
+ .command(splitBlockCommand(state.selection.from, true))
46
50
  .run();
47
51
 
48
52
  return true;
@@ -1,5 +1,5 @@
1
1
  import { Plugin, PluginKey } from "prosemirror-state";
2
- import { getBlockInfoFromPos } from "../../../api/getBlockInfoFromPos";
2
+ import { getBlockInfo } from "../../../api/getBlockInfoFromPos.js";
3
3
 
4
4
  // ProseMirror Plugin which automatically assigns indices to ordered list items per nesting level.
5
5
  const PLUGIN_KEY = new PluginKey(`numbered-list-indexing`);
@@ -21,46 +21,44 @@ export const NumberedListIndexingPlugin = () => {
21
21
  node.firstChild!.type.name === "numberedListItem"
22
22
  ) {
23
23
  let newIndex = "1";
24
- const isFirstBlockInDoc = pos === 1;
25
24
 
26
- const blockInfo = getBlockInfoFromPos(tr.doc, pos + 1)!;
27
- if (blockInfo === undefined) {
28
- return;
29
- }
25
+ const blockInfo = getBlockInfo({
26
+ posBeforeNode: pos,
27
+ node,
28
+ });
30
29
 
31
30
  // Checks if this block is the start of a new ordered list, i.e. if it's the first block in the document, the
32
31
  // first block in its nesting level, or the previous block is not an ordered list item.
33
- if (!isFirstBlockInDoc) {
34
- const prevBlockInfo = getBlockInfoFromPos(tr.doc, pos - 2)!;
35
- if (prevBlockInfo === undefined) {
36
- return;
37
- }
38
32
 
39
- const isFirstBlockInNestingLevel =
40
- blockInfo.depth !== prevBlockInfo.depth;
33
+ const prevBlock = tr.doc.resolve(
34
+ blockInfo.blockContainer.beforePos
35
+ ).nodeBefore;
41
36
 
42
- if (!isFirstBlockInNestingLevel) {
43
- const prevBlockContentNode = prevBlockInfo.contentNode;
44
- const prevBlockContentType = prevBlockInfo.contentType;
37
+ if (prevBlock) {
38
+ const prevBlockInfo = getBlockInfo({
39
+ posBeforeNode:
40
+ blockInfo.blockContainer.beforePos - prevBlock.nodeSize,
41
+ node: prevBlock,
42
+ });
45
43
 
46
- const isPrevBlockOrderedListItem =
47
- prevBlockContentType.name === "numberedListItem";
44
+ const isPrevBlockOrderedListItem =
45
+ prevBlockInfo.blockContent.node.type.name === "numberedListItem";
48
46
 
49
- if (isPrevBlockOrderedListItem) {
50
- const prevBlockIndex = prevBlockContentNode.attrs["index"];
47
+ if (isPrevBlockOrderedListItem) {
48
+ const prevBlockIndex =
49
+ prevBlockInfo.blockContent.node.attrs["index"];
51
50
 
52
- newIndex = (parseInt(prevBlockIndex) + 1).toString();
53
- }
51
+ newIndex = (parseInt(prevBlockIndex) + 1).toString();
54
52
  }
55
53
  }
56
54
 
57
- const contentNode = blockInfo.contentNode;
55
+ const contentNode = blockInfo.blockContent.node;
58
56
  const index = contentNode.attrs["index"];
59
57
 
60
58
  if (index !== newIndex) {
61
59
  modified = true;
62
60
 
63
- tr.setNodeMarkup(pos + 1, undefined, {
61
+ tr.setNodeMarkup(blockInfo.blockContent.beforePos, undefined, {
64
62
  index: newIndex,
65
63
  });
66
64
  }
@@ -1,14 +1,15 @@
1
1
  import { InputRule } from "@tiptap/core";
2
+ import { updateBlockCommand } from "../../../api/blockManipulation/commands/updateBlock/updateBlock.js";
3
+ import { getBlockInfoFromSelection } from "../../../api/getBlockInfoFromPos.js";
2
4
  import {
3
5
  PropSchema,
4
6
  createBlockSpecFromStronglyTypedTiptapNode,
5
7
  createStronglyTypedTiptapNode,
6
- } from "../../../schema";
7
- import { createDefaultBlockDOMOutputSpec } from "../../defaultBlockHelpers";
8
- import { defaultProps } from "../../defaultProps";
9
- import { handleEnter } from "../ListItemKeyboardShortcuts";
10
- import { NumberedListIndexingPlugin } from "./NumberedListIndexingPlugin";
11
- import { getCurrentBlockContentType } from "../../../api/getCurrentBlockContentType";
8
+ } from "../../../schema/index.js";
9
+ import { createDefaultBlockDOMOutputSpec } from "../../defaultBlockHelpers.js";
10
+ import { defaultProps } from "../../defaultProps.js";
11
+ import { handleEnter } from "../ListItemKeyboardShortcuts.js";
12
+ import { NumberedListIndexingPlugin } from "./NumberedListIndexingPlugin.js";
12
13
 
13
14
  export const numberedListItemPropSchema = {
14
15
  ...defaultProps,
@@ -39,15 +40,22 @@ const NumberedListItemBlockContent = createStronglyTypedTiptapNode({
39
40
  new InputRule({
40
41
  find: new RegExp(`^1\\.\\s$`),
41
42
  handler: ({ state, chain, range }) => {
42
- if (getCurrentBlockContentType(this.editor) !== "inline*") {
43
+ const blockInfo = getBlockInfoFromSelection(state);
44
+ if (blockInfo.blockContent.node.type.spec.content !== "inline*") {
43
45
  return;
44
46
  }
45
47
 
46
48
  chain()
47
- .BNUpdateBlock(state.selection.from, {
48
- type: "numberedListItem",
49
- props: {},
50
- })
49
+ .command(
50
+ updateBlockCommand(
51
+ this.options.editor,
52
+ blockInfo.blockContainer.beforePos,
53
+ {
54
+ type: "numberedListItem",
55
+ props: {},
56
+ }
57
+ )
58
+ )
51
59
  // Removes the "1." characters used to set the list.
52
60
  .deleteRange({ from: range.from, to: range.to });
53
61
  },
@@ -57,18 +65,22 @@ const NumberedListItemBlockContent = createStronglyTypedTiptapNode({
57
65
 
58
66
  addKeyboardShortcuts() {
59
67
  return {
60
- Enter: () => handleEnter(this.editor),
68
+ Enter: () => handleEnter(this.options.editor),
61
69
  "Mod-Shift-7": () => {
62
- if (getCurrentBlockContentType(this.editor) !== "inline*") {
70
+ const blockInfo = getBlockInfoFromSelection(this.editor.state);
71
+ if (blockInfo.blockContent.node.type.spec.content !== "inline*") {
63
72
  return true;
64
73
  }
65
74
 
66
- return this.editor.commands.BNUpdateBlock(
67
- this.editor.state.selection.anchor,
68
- {
69
- type: "numberedListItem",
70
- props: {},
71
- }
75
+ return this.editor.commands.command(
76
+ updateBlockCommand(
77
+ this.options.editor,
78
+ blockInfo.blockContainer.beforePos,
79
+ {
80
+ type: "numberedListItem",
81
+ props: {},
82
+ }
83
+ )
72
84
  );
73
85
  },
74
86
  };