@blocknote/core 0.19.1 → 0.20.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 (109) hide show
  1. package/dist/blocknote.js +1791 -1483
  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 +3 -0
  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/fromClipboard/handleVSCodePaste.js +3 -3
  24. package/dist/src/api/clipboard/fromClipboard/handleVSCodePaste.js.map +1 -1
  25. package/dist/src/api/nodeUtil.js +1 -1
  26. package/dist/src/api/nodeUtil.js.map +1 -1
  27. package/dist/src/blocks/CodeBlockContent/CodeBlockContent.js +15 -7
  28. package/dist/src/blocks/CodeBlockContent/CodeBlockContent.js.map +1 -1
  29. package/dist/src/blocks/CodeBlockContent/defaultSupportedLanguages.js +38 -18
  30. package/dist/src/blocks/CodeBlockContent/defaultSupportedLanguages.js.map +1 -1
  31. package/dist/src/blocks/TableBlockContent/TableExtension.js +8 -1
  32. package/dist/src/blocks/TableBlockContent/TableExtension.js.map +1 -1
  33. package/dist/src/editor/BlockNoteEditor.js +59 -57
  34. package/dist/src/editor/BlockNoteEditor.js.map +1 -1
  35. package/dist/src/editor/BlockNoteExtensions.js +2 -1
  36. package/dist/src/editor/BlockNoteExtensions.js.map +1 -1
  37. package/dist/src/extensions/FormattingToolbar/FormattingToolbarPlugin.js +4 -2
  38. package/dist/src/extensions/FormattingToolbar/FormattingToolbarPlugin.js.map +1 -1
  39. package/dist/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js +10 -8
  40. package/dist/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js.map +1 -1
  41. package/dist/src/extensions/LinkToolbar/LinkToolbarPlugin.js +7 -3
  42. package/dist/src/extensions/LinkToolbar/LinkToolbarPlugin.js.map +1 -1
  43. package/dist/src/extensions/Placeholder/PlaceholderPlugin.js +13 -7
  44. package/dist/src/extensions/Placeholder/PlaceholderPlugin.js.map +1 -1
  45. package/dist/src/extensions/SideMenu/SideMenuPlugin.js +5 -1
  46. package/dist/src/extensions/SideMenu/SideMenuPlugin.js.map +1 -1
  47. package/dist/src/extensions/SideMenu/dragging.js +5 -1
  48. package/dist/src/extensions/SideMenu/dragging.js.map +1 -1
  49. package/dist/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.js +0 -3
  50. package/dist/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.js.map +1 -1
  51. package/dist/src/extensions/TableHandles/TableHandlesPlugin.js +25 -8
  52. package/dist/src/extensions/TableHandles/TableHandlesPlugin.js.map +1 -1
  53. package/dist/src/i18n/locales/ru.js +1 -1
  54. package/dist/src/index.js +1 -0
  55. package/dist/src/index.js.map +1 -1
  56. package/dist/style.css +1 -1
  57. package/dist/tsconfig.tsbuildinfo +1 -1
  58. package/dist/webpack-stats.json +1 -1
  59. package/package.json +3 -3
  60. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +6 -6
  61. package/src/api/blockManipulation/commands/moveBlocks/__snapshots__/moveBlocks.test.ts.snap +9506 -0
  62. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +295 -0
  63. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +338 -0
  64. package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +4 -0
  65. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +11 -3
  66. package/src/api/blockManipulation/getBlock/getBlock.ts +141 -0
  67. package/src/api/blockManipulation/selections/__snapshots__/selection.test.ts.snap +660 -0
  68. package/src/api/blockManipulation/selections/selection.test.ts +56 -0
  69. package/src/api/blockManipulation/selections/selection.ts +244 -0
  70. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +4 -0
  71. package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +4 -4
  72. package/src/api/nodeUtil.ts +2 -2
  73. package/src/blocks/CodeBlockContent/CodeBlockContent.ts +18 -8
  74. package/src/blocks/CodeBlockContent/defaultSupportedLanguages.ts +38 -18
  75. package/src/blocks/TableBlockContent/TableExtension.ts +12 -1
  76. package/src/editor/Block.css +3 -0
  77. package/src/editor/BlockNoteEditor.ts +93 -85
  78. package/src/editor/BlockNoteExtensions.ts +3 -1
  79. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +4 -2
  80. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +11 -8
  81. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +11 -4
  82. package/src/extensions/Placeholder/PlaceholderPlugin.ts +23 -15
  83. package/src/extensions/SideMenu/SideMenuPlugin.ts +5 -1
  84. package/src/extensions/SideMenu/dragging.ts +5 -1
  85. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +0 -5
  86. package/src/extensions/TableHandles/TableHandlesPlugin.ts +34 -9
  87. package/src/i18n/locales/ru.ts +1 -1
  88. package/src/index.ts +1 -0
  89. package/types/src/api/blockManipulation/commands/moveBlocks/moveBlocks.d.ts +15 -0
  90. package/types/src/api/blockManipulation/getBlock/getBlock.d.ts +7 -0
  91. package/types/src/api/blockManipulation/selections/selection.d.ts +5 -0
  92. package/types/src/api/blockManipulation/selections/selection.test.d.ts +1 -0
  93. package/types/src/api/nodeUtil.d.ts +1 -1
  94. package/types/src/editor/BlockNoteEditor.d.ts +54 -10
  95. package/types/src/editor/BlockNoteExtensions.d.ts +1 -0
  96. package/types/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.d.ts +1 -0
  97. package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +1 -1
  98. package/types/src/index.d.ts +1 -0
  99. package/types/src/pm-nodes/BlockContainer.d.ts +2 -2
  100. package/types/src/pm-nodes/BlockGroup.d.ts +2 -2
  101. package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.js +0 -116
  102. package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.js.map +0 -1
  103. package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.test.js +0 -110
  104. package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.test.js.map +0 -1
  105. package/src/api/blockManipulation/commands/moveBlock/__snapshots__/moveBlock.test.ts.snap +0 -3799
  106. package/src/api/blockManipulation/commands/moveBlock/moveBlock.test.ts +0 -196
  107. package/src/api/blockManipulation/commands/moveBlock/moveBlock.ts +0 -176
  108. package/types/src/api/blockManipulation/commands/moveBlock/moveBlock.d.ts +0 -5
  109. /package/types/src/api/blockManipulation/commands/{moveBlock/moveBlock.test.d.ts → moveBlocks/moveBlocks.test.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
- }
@@ -1,5 +0,0 @@
1
- import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor";
2
- import { BlockIdentifier } from "../../../../schema/index.js";
3
- export declare function moveSelectedBlockAndSelection(editor: BlockNoteEditor<any, any, any>, referenceBlock: BlockIdentifier, placement: "before" | "after"): void;
4
- export declare function moveBlockUp(editor: BlockNoteEditor<any, any, any>): void;
5
- export declare function moveBlockDown(editor: BlockNoteEditor<any, any, any>): void;