@blocknote/core 0.19.2 → 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.
- package/dist/blocknote.js +1721 -1453
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +7 -7
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.js +6 -3
- package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.js.map +1 -1
- package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.js +219 -0
- package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.js.map +1 -0
- package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.js +175 -0
- package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.js.map +1 -0
- package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.test.js +3 -0
- package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.test.js.map +1 -1
- package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.js +6 -3
- package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.js.map +1 -1
- package/dist/src/api/blockManipulation/getBlock/getBlock.js +56 -0
- package/dist/src/api/blockManipulation/getBlock/getBlock.js.map +1 -0
- package/dist/src/api/blockManipulation/selections/selection.js +149 -0
- package/dist/src/api/blockManipulation/selections/selection.js.map +1 -0
- package/dist/src/api/blockManipulation/selections/selection.test.js +39 -0
- package/dist/src/api/blockManipulation/selections/selection.test.js.map +1 -0
- package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.js +3 -0
- package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.js.map +1 -1
- package/dist/src/api/nodeUtil.js +1 -1
- package/dist/src/api/nodeUtil.js.map +1 -1
- package/dist/src/blocks/TableBlockContent/TableExtension.js +8 -1
- package/dist/src/blocks/TableBlockContent/TableExtension.js.map +1 -1
- package/dist/src/editor/BlockNoteEditor.js +56 -57
- package/dist/src/editor/BlockNoteEditor.js.map +1 -1
- package/dist/src/editor/BlockNoteExtensions.js +1 -0
- package/dist/src/editor/BlockNoteExtensions.js.map +1 -1
- package/dist/src/extensions/FormattingToolbar/FormattingToolbarPlugin.js +4 -2
- package/dist/src/extensions/FormattingToolbar/FormattingToolbarPlugin.js.map +1 -1
- package/dist/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js +10 -8
- package/dist/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js.map +1 -1
- package/dist/src/extensions/LinkToolbar/LinkToolbarPlugin.js +7 -3
- package/dist/src/extensions/LinkToolbar/LinkToolbarPlugin.js.map +1 -1
- package/dist/src/extensions/Placeholder/PlaceholderPlugin.js +13 -7
- package/dist/src/extensions/Placeholder/PlaceholderPlugin.js.map +1 -1
- package/dist/src/extensions/SideMenu/dragging.js +5 -1
- package/dist/src/extensions/SideMenu/dragging.js.map +1 -1
- package/dist/src/extensions/TableHandles/TableHandlesPlugin.js +25 -8
- package/dist/src/extensions/TableHandles/TableHandlesPlugin.js.map +1 -1
- package/dist/src/i18n/locales/ru.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +3 -3
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +6 -6
- package/src/api/blockManipulation/commands/moveBlocks/__snapshots__/moveBlocks.test.ts.snap +9506 -0
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +295 -0
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +338 -0
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +4 -0
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +11 -3
- package/src/api/blockManipulation/getBlock/getBlock.ts +141 -0
- package/src/api/blockManipulation/selections/__snapshots__/selection.test.ts.snap +660 -0
- package/src/api/blockManipulation/selections/selection.test.ts +56 -0
- package/src/api/blockManipulation/selections/selection.ts +244 -0
- package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +4 -0
- package/src/api/nodeUtil.ts +2 -2
- package/src/blocks/TableBlockContent/TableExtension.ts +12 -1
- package/src/editor/BlockNoteEditor.ts +87 -85
- package/src/editor/BlockNoteExtensions.ts +2 -0
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +4 -2
- package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +11 -8
- package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +11 -4
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +23 -15
- package/src/extensions/SideMenu/dragging.ts +5 -1
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +34 -9
- package/src/i18n/locales/ru.ts +1 -1
- package/types/src/api/blockManipulation/commands/moveBlocks/moveBlocks.d.ts +15 -0
- package/types/src/api/blockManipulation/getBlock/getBlock.d.ts +7 -0
- package/types/src/api/blockManipulation/selections/selection.d.ts +5 -0
- package/types/src/api/blockManipulation/selections/selection.test.d.ts +1 -0
- package/types/src/api/nodeUtil.d.ts +1 -1
- package/types/src/editor/BlockNoteEditor.d.ts +54 -10
- package/types/src/editor/BlockNoteExtensions.d.ts +1 -0
- package/types/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.d.ts +1 -0
- package/types/src/pm-nodes/BlockContainer.d.ts +2 -2
- package/types/src/pm-nodes/BlockGroup.d.ts +2 -2
- package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.js +0 -116
- package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.js.map +0 -1
- package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.test.js +0 -110
- package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.test.js.map +0 -1
- package/src/api/blockManipulation/commands/moveBlock/__snapshots__/moveBlock.test.ts.snap +0 -3799
- package/src/api/blockManipulation/commands/moveBlock/moveBlock.test.ts +0 -196
- package/src/api/blockManipulation/commands/moveBlock/moveBlock.ts +0 -176
- package/types/src/api/blockManipulation/commands/moveBlock/moveBlock.d.ts +0 -5
- /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;
|
|
File without changes
|