@blocknote/core 0.19.2 → 0.21.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 (220) hide show
  1. package/dist/blocknote.js +2035 -1758
  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/src/api/blockManipulation/commands/insertBlocks/insertBlocks.js +6 -3
  6. package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.js.map +1 -1
  7. package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.js +219 -0
  8. package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.js.map +1 -0
  9. package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.js +175 -0
  10. package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.js.map +1 -0
  11. package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.test.js +4 -1
  12. package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.test.js.map +1 -1
  13. package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.js +6 -3
  14. package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.js.map +1 -1
  15. package/dist/src/api/blockManipulation/getBlock/getBlock.js +56 -0
  16. package/dist/src/api/blockManipulation/getBlock/getBlock.js.map +1 -0
  17. package/dist/src/api/blockManipulation/selections/selection.js +149 -0
  18. package/dist/src/api/blockManipulation/selections/selection.js.map +1 -0
  19. package/dist/src/api/blockManipulation/selections/selection.test.js +39 -0
  20. package/dist/src/api/blockManipulation/selections/selection.test.js.map +1 -0
  21. package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.js +3 -0
  22. package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.js.map +1 -1
  23. package/dist/src/api/clipboard/clipboard.test.js +6 -3
  24. package/dist/src/api/clipboard/clipboard.test.js.map +1 -1
  25. package/dist/src/api/clipboard/fromClipboard/handleFileInsertion.js +1 -1
  26. package/dist/src/api/clipboard/fromClipboard/handleFileInsertion.js.map +1 -1
  27. package/dist/src/api/clipboard/fromClipboard/handleVSCodePaste.js +2 -3
  28. package/dist/src/api/clipboard/fromClipboard/handleVSCodePaste.js.map +1 -1
  29. package/dist/src/api/clipboard/fromClipboard/pasteExtension.js +5 -5
  30. package/dist/src/api/clipboard/fromClipboard/pasteExtension.js.map +1 -1
  31. package/dist/src/api/clipboard/toClipboard/copyExtension.js +4 -2
  32. package/dist/src/api/clipboard/toClipboard/copyExtension.js.map +1 -1
  33. package/dist/src/api/nodeUtil.js +1 -1
  34. package/dist/src/api/nodeUtil.js.map +1 -1
  35. package/dist/src/api/parsers/markdown/parseMarkdown.test.js +4 -1
  36. package/dist/src/api/parsers/markdown/parseMarkdown.test.js.map +1 -1
  37. package/dist/src/blocks/AudioBlockContent/AudioBlockContent.js +14 -7
  38. package/dist/src/blocks/AudioBlockContent/AudioBlockContent.js.map +1 -1
  39. package/dist/src/blocks/AudioBlockContent/{audioBlockHelpers.js → parseAudioElement.js} +1 -1
  40. package/dist/src/blocks/AudioBlockContent/parseAudioElement.js.map +1 -0
  41. package/dist/src/blocks/FileBlockContent/FileBlockContent.js +5 -4
  42. package/dist/src/blocks/FileBlockContent/FileBlockContent.js.map +1 -1
  43. package/dist/src/blocks/FileBlockContent/helpers/parse/parseEmbedElement.js +5 -0
  44. package/dist/src/blocks/FileBlockContent/helpers/parse/parseEmbedElement.js.map +1 -0
  45. package/dist/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.js +10 -0
  46. package/dist/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.js.map +1 -0
  47. package/dist/src/blocks/FileBlockContent/helpers/render/createAddFileButton.js +39 -0
  48. package/dist/src/blocks/FileBlockContent/helpers/render/createAddFileButton.js.map +1 -0
  49. package/dist/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.js +51 -0
  50. package/dist/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.js.map +1 -0
  51. package/dist/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.js +17 -0
  52. package/dist/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.js.map +1 -0
  53. package/dist/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.js +147 -0
  54. package/dist/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.js.map +1 -0
  55. package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.js +9 -0
  56. package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.js.map +1 -0
  57. package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js +11 -0
  58. package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js.map +1 -0
  59. package/dist/src/blocks/ImageBlockContent/ImageBlockContent.js +17 -9
  60. package/dist/src/blocks/ImageBlockContent/ImageBlockContent.js.map +1 -1
  61. package/dist/src/blocks/ImageBlockContent/{imageBlockHelpers.js → parseImageElement.js} +1 -1
  62. package/dist/src/blocks/ImageBlockContent/parseImageElement.js.map +1 -0
  63. package/dist/src/blocks/TableBlockContent/TableExtension.js +8 -1
  64. package/dist/src/blocks/TableBlockContent/TableExtension.js.map +1 -1
  65. package/dist/src/blocks/VideoBlockContent/VideoBlockContent.js +18 -7
  66. package/dist/src/blocks/VideoBlockContent/VideoBlockContent.js.map +1 -1
  67. package/dist/src/blocks/VideoBlockContent/{videoBlockHelpers.js → parseVideoElement.js} +1 -1
  68. package/dist/src/blocks/VideoBlockContent/parseVideoElement.js.map +1 -0
  69. package/dist/src/editor/BlockNoteEditor.js +64 -62
  70. package/dist/src/editor/BlockNoteEditor.js.map +1 -1
  71. package/dist/src/editor/BlockNoteExtensions.js +5 -8
  72. package/dist/src/editor/BlockNoteExtensions.js.map +1 -1
  73. package/dist/src/extensions/FormattingToolbar/FormattingToolbarPlugin.js +4 -2
  74. package/dist/src/extensions/FormattingToolbar/FormattingToolbarPlugin.js.map +1 -1
  75. package/dist/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js +10 -8
  76. package/dist/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js.map +1 -1
  77. package/dist/src/extensions/LinkToolbar/LinkToolbarPlugin.js +7 -3
  78. package/dist/src/extensions/LinkToolbar/LinkToolbarPlugin.js.map +1 -1
  79. package/dist/src/extensions/LinkToolbar/protocols.js +14 -0
  80. package/dist/src/extensions/LinkToolbar/protocols.js.map +1 -0
  81. package/dist/src/extensions/Placeholder/PlaceholderPlugin.js +19 -13
  82. package/dist/src/extensions/Placeholder/PlaceholderPlugin.js.map +1 -1
  83. package/dist/src/extensions/SideMenu/SideMenuPlugin.js +5 -1
  84. package/dist/src/extensions/SideMenu/SideMenuPlugin.js.map +1 -1
  85. package/dist/src/extensions/SideMenu/dragging.js +8 -1
  86. package/dist/src/extensions/SideMenu/dragging.js.map +1 -1
  87. package/dist/src/extensions/SuggestionMenu/SuggestionPlugin.js +3 -3
  88. package/dist/src/extensions/SuggestionMenu/SuggestionPlugin.js.map +1 -1
  89. package/dist/src/extensions/TableHandles/TableHandlesPlugin.js +37 -11
  90. package/dist/src/extensions/TableHandles/TableHandlesPlugin.js.map +1 -1
  91. package/dist/src/i18n/locales/ru.js +1 -1
  92. package/dist/src/index.js +9 -2
  93. package/dist/src/index.js.map +1 -1
  94. package/dist/src/schema/inlineContent/createSpec.js +1 -1
  95. package/dist/src/schema/inlineContent/createSpec.js.map +1 -1
  96. package/dist/style.css +1 -1
  97. package/dist/tsconfig.tsbuildinfo +1 -1
  98. package/dist/webpack-stats.json +1 -1
  99. package/package.json +3 -3
  100. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +6 -6
  101. package/src/api/blockManipulation/commands/moveBlocks/__snapshots__/moveBlocks.test.ts.snap +9506 -0
  102. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +295 -0
  103. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +336 -0
  104. package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +5 -1
  105. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +11 -3
  106. package/src/api/blockManipulation/getBlock/getBlock.ts +141 -0
  107. package/src/api/blockManipulation/selections/__snapshots__/selection.test.ts.snap +660 -0
  108. package/src/api/blockManipulation/selections/selection.test.ts +56 -0
  109. package/src/api/blockManipulation/selections/selection.ts +244 -0
  110. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +4 -0
  111. package/src/api/clipboard/__snapshots__/tableAllCells.html +1 -1
  112. package/src/api/clipboard/__snapshots__/tableCell.html +1 -1
  113. package/src/api/clipboard/__snapshots__/tableRow.html +1 -1
  114. package/src/api/clipboard/clipboard.test.ts +7 -3
  115. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +1 -1
  116. package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +7 -14
  117. package/src/api/clipboard/fromClipboard/pasteExtension.ts +6 -6
  118. package/src/api/clipboard/toClipboard/copyExtension.ts +7 -2
  119. package/src/api/exporters/html/__snapshots__/file/basic/internal.html +1 -1
  120. package/src/api/exporters/html/__snapshots__/file/nested/internal.html +1 -1
  121. package/src/api/exporters/html/__snapshots__/file/noCaption/internal.html +1 -1
  122. package/src/api/exporters/html/__snapshots__/file/noName/internal.html +1 -1
  123. package/src/api/exporters/html/__snapshots__/image/basic/internal.html +1 -1
  124. package/src/api/exporters/html/__snapshots__/image/nested/internal.html +1 -1
  125. package/src/api/exporters/html/__snapshots__/image/noCaption/internal.html +1 -1
  126. package/src/api/exporters/html/__snapshots__/image/noName/internal.html +1 -1
  127. package/src/api/exporters/html/__snapshots__/image/noPreview/internal.html +1 -1
  128. package/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html +1 -1
  129. package/src/api/exporters/html/__snapshots__/simpleImage/basic/internal.html +1 -1
  130. package/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html +1 -1
  131. package/src/api/exporters/html/__snapshots__/simpleImage/nested/internal.html +1 -1
  132. package/src/api/exporters/html/__snapshots__/simpleImage/noCaption/external.html +1 -1
  133. package/src/api/exporters/html/__snapshots__/simpleImage/noCaption/internal.html +1 -1
  134. package/src/api/exporters/html/__snapshots__/simpleImage/noName/external.html +1 -1
  135. package/src/api/exporters/html/__snapshots__/simpleImage/noName/internal.html +1 -1
  136. package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/external.html +1 -1
  137. package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/internal.html +1 -1
  138. package/src/api/exporters/markdown/__snapshots__/simpleImage/basic/markdown.md +1 -1
  139. package/src/api/exporters/markdown/__snapshots__/simpleImage/nested/markdown.md +2 -2
  140. package/src/api/exporters/markdown/__snapshots__/simpleImage/noCaption/markdown.md +1 -1
  141. package/src/api/exporters/markdown/__snapshots__/simpleImage/noName/markdown.md +1 -1
  142. package/src/api/nodeUtil.ts +2 -2
  143. package/src/api/parsers/markdown/parseMarkdown.test.ts +5 -7
  144. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +13 -14
  145. package/src/blocks/FileBlockContent/FileBlockContent.ts +5 -12
  146. package/src/blocks/FileBlockContent/helpers/parse/parseEmbedElement.ts +5 -0
  147. package/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.ts +16 -0
  148. package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +63 -0
  149. package/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.ts +80 -0
  150. package/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.ts +24 -0
  151. package/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.ts +204 -0
  152. package/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.ts +13 -0
  153. package/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.ts +15 -0
  154. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +20 -28
  155. package/src/blocks/TableBlockContent/TableExtension.ts +12 -1
  156. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +20 -27
  157. package/src/editor/Block.css +35 -51
  158. package/src/editor/BlockNoteEditor.ts +101 -92
  159. package/src/editor/BlockNoteExtensions.ts +9 -8
  160. package/src/editor/editor.css +1 -0
  161. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +4 -2
  162. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +11 -8
  163. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +11 -4
  164. package/src/extensions/LinkToolbar/protocols.ts +13 -0
  165. package/src/extensions/Placeholder/PlaceholderPlugin.ts +29 -21
  166. package/src/extensions/SideMenu/SideMenuPlugin.ts +5 -1
  167. package/src/extensions/SideMenu/dragging.ts +8 -1
  168. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +3 -6
  169. package/src/extensions/TableHandles/TableHandlesPlugin.ts +49 -12
  170. package/src/i18n/locales/ru.ts +1 -1
  171. package/src/index.ts +9 -2
  172. package/src/schema/inlineContent/createSpec.ts +2 -2
  173. package/types/src/api/blockManipulation/commands/moveBlocks/moveBlocks.d.ts +15 -0
  174. package/types/src/api/blockManipulation/getBlock/getBlock.d.ts +7 -0
  175. package/types/src/api/blockManipulation/selections/selection.d.ts +5 -0
  176. package/types/src/api/blockManipulation/selections/selection.test.d.ts +1 -0
  177. package/types/src/api/clipboard/fromClipboard/handleVSCodePaste.d.ts +2 -3
  178. package/types/src/api/clipboard/fromClipboard/pasteExtension.d.ts +1 -3
  179. package/types/src/api/nodeUtil.d.ts +1 -1
  180. package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +2 -5
  181. package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +2 -5
  182. package/types/src/blocks/FileBlockContent/helpers/parse/parseEmbedElement.d.ts +3 -0
  183. package/types/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.d.ts +4 -0
  184. package/types/src/blocks/FileBlockContent/helpers/render/createAddFileButton.d.ts +6 -0
  185. package/types/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.d.ts +9 -0
  186. package/types/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.d.ts +6 -0
  187. package/types/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.d.ts +9 -0
  188. package/types/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.d.ts +3 -0
  189. package/types/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.d.ts +3 -0
  190. package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +2 -5
  191. package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +2 -5
  192. package/types/src/editor/BlockNoteEditor.d.ts +60 -14
  193. package/types/src/editor/BlockNoteExtensions.d.ts +1 -0
  194. package/types/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.d.ts +1 -0
  195. package/types/src/extensions/LinkToolbar/protocols.d.ts +2 -0
  196. package/types/src/index.d.ts +9 -2
  197. package/types/src/pm-nodes/BlockContainer.d.ts +2 -2
  198. package/types/src/pm-nodes/BlockGroup.d.ts +2 -2
  199. package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.js +0 -116
  200. package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.js.map +0 -1
  201. package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.test.js +0 -110
  202. package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.test.js.map +0 -1
  203. package/dist/src/blocks/AudioBlockContent/audioBlockHelpers.js.map +0 -1
  204. package/dist/src/blocks/FileBlockContent/fileBlockHelpers.js +0 -317
  205. package/dist/src/blocks/FileBlockContent/fileBlockHelpers.js.map +0 -1
  206. package/dist/src/blocks/ImageBlockContent/imageBlockHelpers.js.map +0 -1
  207. package/dist/src/blocks/VideoBlockContent/videoBlockHelpers.js.map +0 -1
  208. package/src/api/blockManipulation/commands/moveBlock/__snapshots__/moveBlock.test.ts.snap +0 -3799
  209. package/src/api/blockManipulation/commands/moveBlock/moveBlock.test.ts +0 -196
  210. package/src/api/blockManipulation/commands/moveBlock/moveBlock.ts +0 -176
  211. package/src/blocks/FileBlockContent/fileBlockHelpers.ts +0 -456
  212. package/types/src/api/blockManipulation/commands/moveBlock/moveBlock.d.ts +0 -5
  213. package/types/src/blocks/FileBlockContent/fileBlockHelpers.d.ts +0 -41
  214. /package/src/blocks/AudioBlockContent/{audioBlockHelpers.ts → parseAudioElement.ts} +0 -0
  215. /package/src/blocks/ImageBlockContent/{imageBlockHelpers.ts → parseImageElement.ts} +0 -0
  216. /package/src/blocks/VideoBlockContent/{videoBlockHelpers.ts → parseVideoElement.ts} +0 -0
  217. /package/types/src/api/blockManipulation/commands/{moveBlock/moveBlock.test.d.ts → moveBlocks/moveBlocks.test.d.ts} +0 -0
  218. /package/types/src/blocks/AudioBlockContent/{audioBlockHelpers.d.ts → parseAudioElement.d.ts} +0 -0
  219. /package/types/src/blocks/ImageBlockContent/{imageBlockHelpers.d.ts → parseImageElement.d.ts} +0 -0
  220. /package/types/src/blocks/VideoBlockContent/{videoBlockHelpers.d.ts → parseVideoElement.d.ts} +0 -0
@@ -1,196 +0,0 @@
1
- import { NodeSelection, TextSelection } from "prosemirror-state";
2
- import { CellSelection } from "prosemirror-tables";
3
- import { describe, expect, it } from "vitest";
4
-
5
- import { getBlockInfoFromSelection } from "../../../getBlockInfoFromPos.js";
6
- import { setupTestEnv } from "../../setupTestEnv.js";
7
- import {
8
- moveBlockDown,
9
- moveBlockUp,
10
- moveSelectedBlockAndSelection,
11
- } from "./moveBlock.js";
12
-
13
- const getEditor = setupTestEnv();
14
-
15
- function makeSelectionSpanContent(selectionType: "text" | "node" | "cell") {
16
- const blockInfo = getBlockInfoFromSelection(getEditor()._tiptapEditor.state);
17
- if (!blockInfo.isBlockContainer) {
18
- throw new Error(
19
- `Selection points to a ${blockInfo.blockNoteType} node, not a blockContainer node`
20
- );
21
- }
22
- const { blockContent } = blockInfo;
23
-
24
- if (selectionType === "cell") {
25
- getEditor()._tiptapEditor.view.dispatch(
26
- getEditor()._tiptapEditor.state.tr.setSelection(
27
- CellSelection.create(
28
- getEditor()._tiptapEditor.state.doc,
29
- getEditor()
30
- ._tiptapEditor.state.doc.resolve(blockContent.beforePos + 3)
31
- .before(),
32
- getEditor()
33
- ._tiptapEditor.state.doc.resolve(blockContent.afterPos - 3)
34
- .before()
35
- )
36
- )
37
- );
38
- } else if (selectionType === "node") {
39
- const resolvedContentStartPos = getEditor()._tiptapEditor.state.doc.resolve(
40
- blockContent.beforePos
41
- );
42
-
43
- getEditor()._tiptapEditor.view.dispatch(
44
- getEditor()._tiptapEditor.state.tr.setSelection(
45
- NodeSelection.create(
46
- getEditor()._tiptapEditor.state.doc,
47
- getEditor()
48
- ._tiptapEditor.state.doc.resolve(
49
- resolvedContentStartPos.after(resolvedContentStartPos.depth + 1)
50
- )
51
- .start()
52
- )
53
- )
54
- );
55
- } else {
56
- const resolvedContentStartPos = getEditor()._tiptapEditor.state.doc.resolve(
57
- blockContent.beforePos
58
- );
59
- const resolvedContentEndPos = getEditor()._tiptapEditor.state.doc.resolve(
60
- blockContent.afterPos
61
- );
62
-
63
- getEditor()._tiptapEditor.view.dispatch(
64
- getEditor()._tiptapEditor.state.tr.setSelection(
65
- TextSelection.create(
66
- getEditor()._tiptapEditor.state.doc,
67
- getEditor()
68
- ._tiptapEditor.state.doc.resolve(
69
- resolvedContentStartPos.after(resolvedContentStartPos.depth + 1)
70
- )
71
- .start(),
72
- getEditor()
73
- ._tiptapEditor.state.doc.resolve(
74
- resolvedContentEndPos.before(resolvedContentEndPos.depth + 1)
75
- )
76
- .end()
77
- )
78
- )
79
- );
80
- }
81
- }
82
-
83
- describe("Test moveSelectedBlockAndSelection", () => {
84
- it("Text selection", () => {
85
- getEditor().setTextCursorPosition("paragraph-1");
86
- makeSelectionSpanContent("text");
87
-
88
- moveSelectedBlockAndSelection(getEditor(), "paragraph-0", "before");
89
-
90
- const selection = getEditor()._tiptapEditor.state.selection;
91
- getEditor().setTextCursorPosition("paragraph-1");
92
- makeSelectionSpanContent("text");
93
-
94
- expect(
95
- selection.eq(getEditor()._tiptapEditor.state.selection)
96
- ).toBeTruthy();
97
- });
98
-
99
- it("Node selection", () => {
100
- getEditor().setTextCursorPosition("image-0");
101
- makeSelectionSpanContent("node");
102
-
103
- moveSelectedBlockAndSelection(getEditor(), "paragraph-0", "before");
104
-
105
- const selection = getEditor()._tiptapEditor.state.selection;
106
- getEditor().setTextCursorPosition("image-0");
107
- makeSelectionSpanContent("node");
108
-
109
- expect(
110
- selection.eq(getEditor()._tiptapEditor.state.selection)
111
- ).toBeTruthy();
112
- });
113
-
114
- it("Cell selection", () => {
115
- getEditor().setTextCursorPosition("table-0");
116
- makeSelectionSpanContent("cell");
117
-
118
- moveSelectedBlockAndSelection(getEditor(), "paragraph-0", "before");
119
-
120
- const selection = getEditor()._tiptapEditor.state.selection;
121
- getEditor().setTextCursorPosition("table-0");
122
- makeSelectionSpanContent("cell");
123
-
124
- expect(
125
- selection.eq(getEditor()._tiptapEditor.state.selection)
126
- ).toBeTruthy();
127
- });
128
- });
129
-
130
- describe("Test moveBlockUp", () => {
131
- it("Basic", () => {
132
- getEditor().setTextCursorPosition("paragraph-1");
133
-
134
- moveBlockUp(getEditor());
135
-
136
- expect(getEditor().document).toMatchSnapshot();
137
- });
138
-
139
- it("Into children", () => {
140
- getEditor().setTextCursorPosition("paragraph-2");
141
-
142
- moveBlockUp(getEditor());
143
-
144
- expect(getEditor().document).toMatchSnapshot();
145
- });
146
-
147
- it("Out of children", () => {
148
- getEditor().setTextCursorPosition("nested-paragraph-1");
149
-
150
- moveBlockUp(getEditor());
151
-
152
- expect(getEditor().document).toMatchSnapshot();
153
- });
154
-
155
- it("First block", () => {
156
- getEditor().setTextCursorPosition("paragraph-0");
157
-
158
- moveBlockUp(getEditor());
159
-
160
- expect(getEditor().document).toMatchSnapshot();
161
- });
162
- });
163
-
164
- describe("Test moveBlockDown", () => {
165
- it("Basic", () => {
166
- getEditor().setTextCursorPosition("paragraph-0");
167
-
168
- moveBlockDown(getEditor());
169
-
170
- expect(getEditor().document).toMatchSnapshot();
171
- });
172
-
173
- it("Into children", () => {
174
- getEditor().setTextCursorPosition("paragraph-1");
175
-
176
- moveBlockDown(getEditor());
177
-
178
- expect(getEditor().document).toMatchSnapshot();
179
- });
180
-
181
- it("Out of children", () => {
182
- getEditor().setTextCursorPosition("nested-paragraph-1");
183
-
184
- moveBlockDown(getEditor());
185
-
186
- expect(getEditor().document).toMatchSnapshot();
187
- });
188
-
189
- it("Last block", () => {
190
- getEditor().setTextCursorPosition("trailing-paragraph");
191
-
192
- moveBlockDown(getEditor());
193
-
194
- expect(getEditor().document).toMatchSnapshot();
195
- });
196
- });
@@ -1,176 +0,0 @@
1
- import { NodeSelection, Selection, TextSelection } from "prosemirror-state";
2
- import { CellSelection } from "prosemirror-tables";
3
-
4
- import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor";
5
- import { BlockIdentifier } from "../../../../schema/index.js";
6
- import { getBlockInfoFromSelection } from "../../../getBlockInfoFromPos.js";
7
- import { getNodeById } from "../../../nodeUtil.js";
8
-
9
- type BlockSelectionData = (
10
- | {
11
- type: "text";
12
- anchor: number;
13
- head: number;
14
- }
15
- | {
16
- type: "node";
17
- from: number;
18
- }
19
- | {
20
- type: "cell";
21
- anchorCell: number;
22
- headCell: number;
23
- }
24
- ) & {
25
- blockId: string;
26
- blockPos: number;
27
- };
28
-
29
- // `getBlockSelectionData` and `updateBlockSelectionFromData` are used to save
30
- // and restore the selection within a block, when the block is moved.
31
- function getBlockSelectionData(
32
- editor: BlockNoteEditor<any, any, any>
33
- ): BlockSelectionData {
34
- const { bnBlock } = getBlockInfoFromSelection(editor._tiptapEditor.state);
35
-
36
- const selectionData = {
37
- blockId: bnBlock.node.attrs.id,
38
- blockPos: bnBlock.beforePos,
39
- };
40
-
41
- if (editor._tiptapEditor.state.selection instanceof CellSelection) {
42
- return {
43
- ...selectionData,
44
- type: "cell" as const,
45
- anchorCell: (editor._tiptapEditor.state.selection as CellSelection)
46
- .$anchorCell.pos,
47
- headCell: (editor._tiptapEditor.state.selection as CellSelection)
48
- .$headCell.pos,
49
- };
50
- } else if (editor._tiptapEditor.state.selection instanceof NodeSelection) {
51
- return {
52
- ...selectionData,
53
- type: "node" as const,
54
- from: editor._tiptapEditor.state.selection.from,
55
- };
56
- } else {
57
- return {
58
- ...selectionData,
59
- type: "text" as const,
60
- anchor: editor._tiptapEditor.state.selection.anchor,
61
- head: editor._tiptapEditor.state.selection.head,
62
- };
63
- }
64
- }
65
-
66
- function updateBlockSelectionFromData(
67
- editor: BlockNoteEditor<any, any, any>,
68
- data: BlockSelectionData
69
- ) {
70
- const blockPos = getNodeById(
71
- data.blockId,
72
- editor._tiptapEditor.state.doc
73
- ).posBeforeNode;
74
-
75
- let selection: Selection;
76
- if (data.type === "cell") {
77
- selection = CellSelection.create(
78
- editor._tiptapEditor.state.doc,
79
- data.anchorCell + (blockPos - data.blockPos),
80
- data.headCell + (blockPos - data.blockPos)
81
- );
82
- } else if (data.type === "node") {
83
- selection = NodeSelection.create(
84
- editor._tiptapEditor.state.doc,
85
- data.from + (blockPos - data.blockPos)
86
- );
87
- } else {
88
- selection = TextSelection.create(
89
- editor._tiptapEditor.state.doc,
90
- data.anchor + (blockPos - data.blockPos),
91
- data.head + (blockPos - data.blockPos)
92
- );
93
- }
94
-
95
- editor._tiptapEditor.view.dispatch(
96
- editor._tiptapEditor.state.tr.setSelection(selection)
97
- );
98
- }
99
-
100
- export function moveSelectedBlockAndSelection(
101
- editor: BlockNoteEditor<any, any, any>,
102
- referenceBlock: BlockIdentifier,
103
- placement: "before" | "after"
104
- ) {
105
- const { block } = editor.getTextCursorPosition();
106
- const selectionData = getBlockSelectionData(editor);
107
-
108
- editor.removeBlocks([block]);
109
- editor.insertBlocks([block], referenceBlock, placement);
110
-
111
- updateBlockSelectionFromData(editor, selectionData);
112
- }
113
-
114
- export function moveBlockUp(editor: BlockNoteEditor<any, any, any>) {
115
- // This function currently only supports moving a single block.
116
- const editorSelection = editor.getSelection();
117
- if (editorSelection && editorSelection.blocks.length > 1) {
118
- return;
119
- }
120
-
121
- const { prevBlock, parentBlock } = editor.getTextCursorPosition();
122
-
123
- let referenceBlockId: string | undefined;
124
- let placement: "before" | "after" | undefined;
125
-
126
- if (!prevBlock) {
127
- if (parentBlock) {
128
- referenceBlockId = parentBlock.id;
129
- placement = "before";
130
- }
131
- } else if (prevBlock.children.length > 0) {
132
- referenceBlockId = prevBlock.children[prevBlock.children.length - 1].id;
133
- placement = "after";
134
- } else {
135
- referenceBlockId = prevBlock.id;
136
- placement = "before";
137
- }
138
-
139
- if (!referenceBlockId || !placement) {
140
- return;
141
- }
142
-
143
- moveSelectedBlockAndSelection(editor, referenceBlockId, placement);
144
- }
145
-
146
- export function moveBlockDown(editor: BlockNoteEditor<any, any, any>) {
147
- // This function currently only supports moving a single block.
148
- const editorSelection = editor.getSelection();
149
- if (editorSelection && editorSelection.blocks.length > 1) {
150
- return;
151
- }
152
-
153
- const { nextBlock, parentBlock } = editor.getTextCursorPosition();
154
-
155
- let referenceBlockId: string | undefined;
156
- let placement: "before" | "after" | undefined;
157
-
158
- if (!nextBlock) {
159
- if (parentBlock) {
160
- referenceBlockId = parentBlock.id;
161
- placement = "after";
162
- }
163
- } else if (nextBlock.children.length > 0) {
164
- referenceBlockId = nextBlock.children[0].id;
165
- placement = "before";
166
- } else {
167
- referenceBlockId = nextBlock.id;
168
- placement = "after";
169
- }
170
-
171
- if (!referenceBlockId || !placement) {
172
- return;
173
- }
174
-
175
- moveSelectedBlockAndSelection(editor, referenceBlockId, placement);
176
- }