@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
@@ -0,0 +1,316 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`Test getTextCursorPosition & setTextCursorPosition > Basic 1`] = `
4
+ {
5
+ "block": {
6
+ "children": [],
7
+ "content": [
8
+ {
9
+ "styles": {},
10
+ "text": "Paragraph 1",
11
+ "type": "text",
12
+ },
13
+ ],
14
+ "id": "paragraph-1",
15
+ "props": {
16
+ "backgroundColor": "default",
17
+ "textAlignment": "left",
18
+ "textColor": "default",
19
+ },
20
+ "type": "paragraph",
21
+ },
22
+ "nextBlock": {
23
+ "children": [
24
+ {
25
+ "children": [
26
+ {
27
+ "children": [],
28
+ "content": [
29
+ {
30
+ "styles": {},
31
+ "text": "Double Nested Paragraph 0",
32
+ "type": "text",
33
+ },
34
+ ],
35
+ "id": "double-nested-paragraph-0",
36
+ "props": {
37
+ "backgroundColor": "default",
38
+ "textAlignment": "left",
39
+ "textColor": "default",
40
+ },
41
+ "type": "paragraph",
42
+ },
43
+ ],
44
+ "content": [
45
+ {
46
+ "styles": {},
47
+ "text": "Nested Paragraph 0",
48
+ "type": "text",
49
+ },
50
+ ],
51
+ "id": "nested-paragraph-0",
52
+ "props": {
53
+ "backgroundColor": "default",
54
+ "textAlignment": "left",
55
+ "textColor": "default",
56
+ },
57
+ "type": "paragraph",
58
+ },
59
+ ],
60
+ "content": [
61
+ {
62
+ "styles": {},
63
+ "text": "Paragraph with children",
64
+ "type": "text",
65
+ },
66
+ ],
67
+ "id": "paragraph-with-children",
68
+ "props": {
69
+ "backgroundColor": "default",
70
+ "textAlignment": "left",
71
+ "textColor": "default",
72
+ },
73
+ "type": "paragraph",
74
+ },
75
+ "parentBlock": undefined,
76
+ "prevBlock": {
77
+ "children": [],
78
+ "content": [
79
+ {
80
+ "styles": {},
81
+ "text": "Paragraph 0",
82
+ "type": "text",
83
+ },
84
+ ],
85
+ "id": "paragraph-0",
86
+ "props": {
87
+ "backgroundColor": "default",
88
+ "textAlignment": "left",
89
+ "textColor": "default",
90
+ },
91
+ "type": "paragraph",
92
+ },
93
+ }
94
+ `;
95
+
96
+ exports[`Test getTextCursorPosition & setTextCursorPosition > First block 1`] = `
97
+ {
98
+ "block": {
99
+ "children": [],
100
+ "content": [
101
+ {
102
+ "styles": {},
103
+ "text": "Paragraph 0",
104
+ "type": "text",
105
+ },
106
+ ],
107
+ "id": "paragraph-0",
108
+ "props": {
109
+ "backgroundColor": "default",
110
+ "textAlignment": "left",
111
+ "textColor": "default",
112
+ },
113
+ "type": "paragraph",
114
+ },
115
+ "nextBlock": {
116
+ "children": [],
117
+ "content": [
118
+ {
119
+ "styles": {},
120
+ "text": "Paragraph 1",
121
+ "type": "text",
122
+ },
123
+ ],
124
+ "id": "paragraph-1",
125
+ "props": {
126
+ "backgroundColor": "default",
127
+ "textAlignment": "left",
128
+ "textColor": "default",
129
+ },
130
+ "type": "paragraph",
131
+ },
132
+ "parentBlock": undefined,
133
+ "prevBlock": undefined,
134
+ }
135
+ `;
136
+
137
+ exports[`Test getTextCursorPosition & setTextCursorPosition > Last block 1`] = `
138
+ {
139
+ "block": {
140
+ "children": [],
141
+ "content": [],
142
+ "id": "trailing-paragraph",
143
+ "props": {
144
+ "backgroundColor": "default",
145
+ "textAlignment": "left",
146
+ "textColor": "default",
147
+ },
148
+ "type": "paragraph",
149
+ },
150
+ "nextBlock": undefined,
151
+ "parentBlock": undefined,
152
+ "prevBlock": {
153
+ "children": [
154
+ {
155
+ "children": [
156
+ {
157
+ "children": [],
158
+ "content": [
159
+ {
160
+ "styles": {},
161
+ "text": "Double Nested Paragraph 1",
162
+ "type": "text",
163
+ },
164
+ ],
165
+ "id": "double-nested-paragraph-1",
166
+ "props": {
167
+ "backgroundColor": "default",
168
+ "textAlignment": "left",
169
+ "textColor": "default",
170
+ },
171
+ "type": "paragraph",
172
+ },
173
+ ],
174
+ "content": [
175
+ {
176
+ "styles": {},
177
+ "text": "Nested Paragraph 1",
178
+ "type": "text",
179
+ },
180
+ ],
181
+ "id": "nested-paragraph-1",
182
+ "props": {
183
+ "backgroundColor": "default",
184
+ "textAlignment": "left",
185
+ "textColor": "default",
186
+ },
187
+ "type": "paragraph",
188
+ },
189
+ ],
190
+ "content": [
191
+ {
192
+ "styles": {
193
+ "bold": true,
194
+ },
195
+ "text": "Heading",
196
+ "type": "text",
197
+ },
198
+ {
199
+ "styles": {},
200
+ "text": " with styled ",
201
+ "type": "text",
202
+ },
203
+ {
204
+ "styles": {
205
+ "italic": true,
206
+ },
207
+ "text": "content",
208
+ "type": "text",
209
+ },
210
+ ],
211
+ "id": "heading-with-everything",
212
+ "props": {
213
+ "backgroundColor": "red",
214
+ "level": 2,
215
+ "textAlignment": "center",
216
+ "textColor": "red",
217
+ },
218
+ "type": "heading",
219
+ },
220
+ }
221
+ `;
222
+
223
+ exports[`Test getTextCursorPosition & setTextCursorPosition > Nested block 1`] = `
224
+ {
225
+ "block": {
226
+ "children": [
227
+ {
228
+ "children": [],
229
+ "content": [
230
+ {
231
+ "styles": {},
232
+ "text": "Double Nested Paragraph 0",
233
+ "type": "text",
234
+ },
235
+ ],
236
+ "id": "double-nested-paragraph-0",
237
+ "props": {
238
+ "backgroundColor": "default",
239
+ "textAlignment": "left",
240
+ "textColor": "default",
241
+ },
242
+ "type": "paragraph",
243
+ },
244
+ ],
245
+ "content": [
246
+ {
247
+ "styles": {},
248
+ "text": "Nested Paragraph 0",
249
+ "type": "text",
250
+ },
251
+ ],
252
+ "id": "nested-paragraph-0",
253
+ "props": {
254
+ "backgroundColor": "default",
255
+ "textAlignment": "left",
256
+ "textColor": "default",
257
+ },
258
+ "type": "paragraph",
259
+ },
260
+ "nextBlock": undefined,
261
+ "parentBlock": {
262
+ "children": [
263
+ {
264
+ "children": [
265
+ {
266
+ "children": [],
267
+ "content": [
268
+ {
269
+ "styles": {},
270
+ "text": "Double Nested Paragraph 0",
271
+ "type": "text",
272
+ },
273
+ ],
274
+ "id": "double-nested-paragraph-0",
275
+ "props": {
276
+ "backgroundColor": "default",
277
+ "textAlignment": "left",
278
+ "textColor": "default",
279
+ },
280
+ "type": "paragraph",
281
+ },
282
+ ],
283
+ "content": [
284
+ {
285
+ "styles": {},
286
+ "text": "Nested Paragraph 0",
287
+ "type": "text",
288
+ },
289
+ ],
290
+ "id": "nested-paragraph-0",
291
+ "props": {
292
+ "backgroundColor": "default",
293
+ "textAlignment": "left",
294
+ "textColor": "default",
295
+ },
296
+ "type": "paragraph",
297
+ },
298
+ ],
299
+ "content": [
300
+ {
301
+ "styles": {},
302
+ "text": "Paragraph with children",
303
+ "type": "text",
304
+ },
305
+ ],
306
+ "id": "paragraph-with-children",
307
+ "props": {
308
+ "backgroundColor": "default",
309
+ "textAlignment": "left",
310
+ "textColor": "default",
311
+ },
312
+ "type": "paragraph",
313
+ },
314
+ "prevBlock": undefined,
315
+ }
316
+ `;
@@ -0,0 +1,53 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import { setupTestEnv } from "../../setupTestEnv.js";
4
+ import {
5
+ getTextCursorPosition,
6
+ setTextCursorPosition,
7
+ } from "./textCursorPosition.js";
8
+
9
+ const getEditor = setupTestEnv();
10
+
11
+ describe("Test getTextCursorPosition & setTextCursorPosition", () => {
12
+ it("Basic", () => {
13
+ setTextCursorPosition(getEditor(), "paragraph-1");
14
+
15
+ expect(getTextCursorPosition(getEditor())).toMatchSnapshot();
16
+ });
17
+
18
+ it("First block", () => {
19
+ setTextCursorPosition(getEditor(), "paragraph-0");
20
+
21
+ expect(getTextCursorPosition(getEditor())).toMatchSnapshot();
22
+ });
23
+
24
+ it("Last block", () => {
25
+ setTextCursorPosition(getEditor(), "trailing-paragraph");
26
+
27
+ expect(getTextCursorPosition(getEditor())).toMatchSnapshot();
28
+ });
29
+
30
+ it("Nested block", () => {
31
+ setTextCursorPosition(getEditor(), "nested-paragraph-0");
32
+
33
+ expect(getTextCursorPosition(getEditor())).toMatchSnapshot();
34
+ });
35
+
36
+ it("Set to start", () => {
37
+ setTextCursorPosition(getEditor(), "paragraph-1", "start");
38
+
39
+ expect(
40
+ getEditor()._tiptapEditor.state.selection.$from.parentOffset === 0
41
+ ).toBeTruthy();
42
+ });
43
+
44
+ it("Set to end", () => {
45
+ setTextCursorPosition(getEditor(), "paragraph-1", "end");
46
+
47
+ expect(
48
+ getEditor()._tiptapEditor.state.selection.$from.parentOffset ===
49
+ getEditor()._tiptapEditor.state.selection.$from.node().firstChild!
50
+ .nodeSize
51
+ ).toBeTruthy();
52
+ });
53
+ });
@@ -0,0 +1,130 @@
1
+ import { Node } from "prosemirror-model";
2
+
3
+ import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
4
+ import { TextCursorPosition } from "../../../../editor/cursorPositionTypes.js";
5
+ import {
6
+ BlockIdentifier,
7
+ BlockSchema,
8
+ InlineContentSchema,
9
+ StyleSchema,
10
+ } from "../../../../schema/index.js";
11
+ import { UnreachableCaseError } from "../../../../util/typescript.js";
12
+ import {
13
+ getBlockInfo,
14
+ getBlockInfoFromSelection,
15
+ } from "../../../getBlockInfoFromPos.js";
16
+ import { nodeToBlock } from "../../../nodeConversions/nodeToBlock.js";
17
+ import { getNodeById } from "../../../nodeUtil.js";
18
+
19
+ export function getTextCursorPosition<
20
+ BSchema extends BlockSchema,
21
+ I extends InlineContentSchema,
22
+ S extends StyleSchema
23
+ >(editor: BlockNoteEditor<BSchema, I, S>): TextCursorPosition<BSchema, I, S> {
24
+ const { blockContainer } = getBlockInfoFromSelection(
25
+ editor._tiptapEditor.state
26
+ );
27
+
28
+ const resolvedPos = editor._tiptapEditor.state.doc.resolve(
29
+ blockContainer.beforePos
30
+ );
31
+ // Gets previous blockContainer node at the same nesting level, if the current node isn't the first child.
32
+ const prevNode = resolvedPos.nodeBefore;
33
+
34
+ // Gets next blockContainer node at the same nesting level, if the current node isn't the last child.
35
+ const nextNode = editor._tiptapEditor.state.doc.resolve(
36
+ blockContainer.afterPos
37
+ ).nodeAfter;
38
+
39
+ // Gets parent blockContainer node, if the current node is nested.
40
+ let parentNode: Node | undefined = undefined;
41
+ if (resolvedPos.depth > 1) {
42
+ parentNode = resolvedPos.node(resolvedPos.depth - 1);
43
+ }
44
+
45
+ return {
46
+ block: nodeToBlock(
47
+ blockContainer.node,
48
+ editor.schema.blockSchema,
49
+ editor.schema.inlineContentSchema,
50
+ editor.schema.styleSchema,
51
+ editor.blockCache
52
+ ),
53
+ prevBlock:
54
+ prevNode === null
55
+ ? undefined
56
+ : nodeToBlock(
57
+ prevNode,
58
+ editor.schema.blockSchema,
59
+ editor.schema.inlineContentSchema,
60
+ editor.schema.styleSchema,
61
+ editor.blockCache
62
+ ),
63
+ nextBlock:
64
+ nextNode === null
65
+ ? undefined
66
+ : nodeToBlock(
67
+ nextNode,
68
+ editor.schema.blockSchema,
69
+ editor.schema.inlineContentSchema,
70
+ editor.schema.styleSchema,
71
+ editor.blockCache
72
+ ),
73
+ parentBlock:
74
+ parentNode === undefined
75
+ ? undefined
76
+ : nodeToBlock(
77
+ parentNode,
78
+ editor.schema.blockSchema,
79
+ editor.schema.inlineContentSchema,
80
+ editor.schema.styleSchema,
81
+ editor.blockCache
82
+ ),
83
+ };
84
+ }
85
+
86
+ export function setTextCursorPosition<
87
+ BSchema extends BlockSchema,
88
+ I extends InlineContentSchema,
89
+ S extends StyleSchema
90
+ >(
91
+ editor: BlockNoteEditor<BSchema, I, S>,
92
+ targetBlock: BlockIdentifier,
93
+ placement: "start" | "end" = "start"
94
+ ) {
95
+ const id = typeof targetBlock === "string" ? targetBlock : targetBlock.id;
96
+
97
+ const posInfo = getNodeById(id, editor._tiptapEditor.state.doc);
98
+ const { blockContent } = getBlockInfo(posInfo);
99
+
100
+ const contentType: "none" | "inline" | "table" =
101
+ editor.schema.blockSchema[blockContent.node.type.name]!.content;
102
+
103
+ if (contentType === "none") {
104
+ editor._tiptapEditor.commands.setNodeSelection(blockContent.beforePos);
105
+ return;
106
+ }
107
+
108
+ if (contentType === "inline") {
109
+ if (placement === "start") {
110
+ editor._tiptapEditor.commands.setTextSelection(
111
+ blockContent.beforePos + 1
112
+ );
113
+ } else {
114
+ editor._tiptapEditor.commands.setTextSelection(blockContent.afterPos - 1);
115
+ }
116
+ } else if (contentType === "table") {
117
+ if (placement === "start") {
118
+ // Need to offset the position as we have to get through the `tableRow`
119
+ // and `tableCell` nodes to get to the `tableParagraph` node we want to
120
+ // set the selection in.
121
+ editor._tiptapEditor.commands.setTextSelection(
122
+ blockContent.beforePos + 4
123
+ );
124
+ } else {
125
+ editor._tiptapEditor.commands.setTextSelection(blockContent.afterPos - 4);
126
+ }
127
+ } else {
128
+ throw new UnreachableCaseError(contentType);
129
+ }
130
+ }
@@ -0,0 +1,179 @@
1
+ import { afterAll, beforeAll, beforeEach } from "vitest";
2
+
3
+ import { PartialBlock } from "../../blocks/defaultBlocks.js";
4
+ import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
5
+
6
+ export function setupTestEnv() {
7
+ let editor: BlockNoteEditor;
8
+ const div = document.createElement("div");
9
+
10
+ beforeAll(() => {
11
+ editor = BlockNoteEditor.create();
12
+ editor.mount(div);
13
+ });
14
+
15
+ afterAll(() => {
16
+ editor.mount(undefined);
17
+ editor._tiptapEditor.destroy();
18
+ editor = undefined as any;
19
+ });
20
+
21
+ beforeEach(() => {
22
+ editor.replaceBlocks(editor.document, testDocument);
23
+ });
24
+
25
+ return () => editor;
26
+ }
27
+
28
+ const testDocument: PartialBlock[] = [
29
+ {
30
+ id: "paragraph-0",
31
+ type: "paragraph",
32
+ content: "Paragraph 0",
33
+ },
34
+ {
35
+ id: "paragraph-1",
36
+ type: "paragraph",
37
+ content: "Paragraph 1",
38
+ },
39
+ {
40
+ id: "paragraph-with-children",
41
+ type: "paragraph",
42
+ content: "Paragraph with children",
43
+ children: [
44
+ {
45
+ id: "nested-paragraph-0",
46
+ type: "paragraph",
47
+ content: "Nested Paragraph 0",
48
+ children: [
49
+ {
50
+ id: "double-nested-paragraph-0",
51
+ type: "paragraph",
52
+ content: "Double Nested Paragraph 0",
53
+ },
54
+ ],
55
+ },
56
+ ],
57
+ },
58
+ {
59
+ id: "paragraph-2",
60
+ type: "paragraph",
61
+ content: "Paragraph 2",
62
+ },
63
+ {
64
+ id: "paragraph-with-props",
65
+ type: "paragraph",
66
+ props: {
67
+ textAlignment: "center",
68
+ textColor: "red",
69
+ },
70
+ content: "Paragraph with props",
71
+ },
72
+ {
73
+ id: "paragraph-3",
74
+ type: "paragraph",
75
+ content: "Paragraph 3",
76
+ },
77
+ {
78
+ id: "paragraph-with-styled-content",
79
+ type: "paragraph",
80
+ content: [
81
+ { type: "text", text: "Paragraph", styles: { bold: true } },
82
+ { type: "text", text: " with styled ", styles: {} },
83
+ { type: "text", text: "content", styles: { italic: true } },
84
+ ],
85
+ },
86
+ {
87
+ id: "paragraph-4",
88
+ type: "paragraph",
89
+ content: "Paragraph 4",
90
+ },
91
+ {
92
+ id: "heading-0",
93
+ type: "heading",
94
+ content: "Heading 1",
95
+ },
96
+ {
97
+ id: "paragraph-5",
98
+ type: "paragraph",
99
+ content: "Paragraph 5",
100
+ },
101
+ {
102
+ id: "image-0",
103
+ type: "image",
104
+ props: {
105
+ url: "https://via.placeholder.com/150",
106
+ },
107
+ },
108
+ {
109
+ id: "paragraph-6",
110
+ type: "paragraph",
111
+ content: "Paragraph 6",
112
+ },
113
+ {
114
+ id: "table-0",
115
+ type: "table",
116
+ content: {
117
+ type: "tableContent",
118
+ rows: [
119
+ {
120
+ cells: ["Cell 1", "Cell 2", "Cell 3"],
121
+ },
122
+ {
123
+ cells: ["Cell 4", "Cell 5", "Cell 6"],
124
+ },
125
+ {
126
+ cells: ["Cell 7", "Cell 8", "Cell 9"],
127
+ },
128
+ ],
129
+ },
130
+ },
131
+ {
132
+ id: "paragraph-7",
133
+ type: "paragraph",
134
+ content: "Paragraph 7",
135
+ },
136
+ {
137
+ id: "empty-paragraph",
138
+ type: "paragraph",
139
+ content: "",
140
+ },
141
+ {
142
+ id: "paragraph-8",
143
+ type: "paragraph",
144
+ content: "Paragraph 8",
145
+ },
146
+ {
147
+ id: "heading-with-everything",
148
+ type: "heading",
149
+ props: {
150
+ backgroundColor: "red",
151
+ level: 2,
152
+ textAlignment: "center",
153
+ textColor: "red",
154
+ },
155
+ content: [
156
+ { type: "text", text: "Heading", styles: { bold: true } },
157
+ { type: "text", text: " with styled ", styles: {} },
158
+ { type: "text", text: "content", styles: { italic: true } },
159
+ ],
160
+ children: [
161
+ {
162
+ id: "nested-paragraph-1",
163
+ type: "paragraph",
164
+ content: "Nested Paragraph 1",
165
+ children: [
166
+ {
167
+ id: "double-nested-paragraph-1",
168
+ type: "paragraph",
169
+ content: "Double Nested Paragraph 1",
170
+ },
171
+ ],
172
+ },
173
+ ],
174
+ },
175
+ {
176
+ id: "trailing-paragraph",
177
+ type: "paragraph",
178
+ },
179
+ ];
@@ -1 +1 @@
1
- <div class="bn-block-content" data-content-type="table"><table class="bn-inline-content"><tbody><tr><td colspan="1" rowspan="1"><p>Table Cell</p></td><td colspan="1" rowspan="1"><p>Table Cell</p></td></tr><tr><td colspan="1" rowspan="1"><p>Table Cell</p></td><td colspan="1" rowspan="1"><p>Table Cell</p></td></tr></tbody></table></div>
1
+ <tr><td colspan="1" rowspan="1"><p>Table Cell</p></td><td colspan="1" rowspan="1"><p>Table Cell</p></td></tr><tr><td colspan="1" rowspan="1"><p>Table Cell</p></td><td colspan="1" rowspan="1"><p>Table Cell</p></td></tr>
@@ -3,11 +3,11 @@ import { NodeSelection, Selection, TextSelection } from "prosemirror-state";
3
3
  import { CellSelection } from "prosemirror-tables";
4
4
  import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
5
5
 
6
- import { PartialBlock } from "../../blocks/defaultBlocks";
7
- import { BlockNoteEditor } from "../../editor/BlockNoteEditor";
8
- import { doPaste } from "../testUtil/paste";
9
- import { initializeESMDependencies } from "../../util/esmDependencies";
10
- import { selectedFragmentToHTML } from "./toClipboard/copyExtension";
6
+ import { PartialBlock } from "../../blocks/defaultBlocks.js";
7
+ import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
8
+ import { initializeESMDependencies } from "../../util/esmDependencies.js";
9
+ import { doPaste } from "../testUtil/paste.js";
10
+ import { selectedFragmentToHTML } from "./toClipboard/copyExtension.js";
11
11
 
12
12
  type SelectionTestCase = {
13
13
  testName: string;
@@ -269,7 +269,6 @@ describe("Test ProseMirror selection clipboard HTML", () => {
269
269
  createSelection: (doc) => CellSelection.create(doc, 214, 228),
270
270
  },
271
271
  // Selection spans all cells of the table.
272
- // TODO: External HTML is wrapped in unnecessary `blockContent` element.
273
272
  {
274
273
  testName: "tableAllCells",
275
274
  createSelection: (doc) => CellSelection.create(doc, 214, 258),