@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.
- package/dist/blocknote.js +1791 -1483
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +6 -6
- 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/clipboard/fromClipboard/handleVSCodePaste.js +3 -3
- package/dist/src/api/clipboard/fromClipboard/handleVSCodePaste.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/CodeBlockContent/CodeBlockContent.js +15 -7
- package/dist/src/blocks/CodeBlockContent/CodeBlockContent.js.map +1 -1
- package/dist/src/blocks/CodeBlockContent/defaultSupportedLanguages.js +38 -18
- package/dist/src/blocks/CodeBlockContent/defaultSupportedLanguages.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 +59 -57
- package/dist/src/editor/BlockNoteEditor.js.map +1 -1
- package/dist/src/editor/BlockNoteExtensions.js +2 -1
- 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/SideMenuPlugin.js +5 -1
- package/dist/src/extensions/SideMenu/SideMenuPlugin.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/SuggestionMenu/getDefaultSlashMenuItems.js +0 -3
- package/dist/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.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/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/style.css +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/clipboard/fromClipboard/handleVSCodePaste.ts +4 -4
- package/src/api/nodeUtil.ts +2 -2
- package/src/blocks/CodeBlockContent/CodeBlockContent.ts +18 -8
- package/src/blocks/CodeBlockContent/defaultSupportedLanguages.ts +38 -18
- package/src/blocks/TableBlockContent/TableExtension.ts +12 -1
- package/src/editor/Block.css +3 -0
- package/src/editor/BlockNoteEditor.ts +93 -85
- package/src/editor/BlockNoteExtensions.ts +3 -1
- 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/SideMenuPlugin.ts +5 -1
- package/src/extensions/SideMenu/dragging.ts +5 -1
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +0 -5
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +34 -9
- package/src/i18n/locales/ru.ts +1 -1
- package/src/index.ts +1 -0
- 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/extensions/SideMenu/SideMenuPlugin.d.ts +1 -1
- package/types/src/index.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
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Block } from "../../../blocks/defaultBlocks.js";
|
|
2
|
+
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
|
|
3
|
+
import {
|
|
4
|
+
BlockIdentifier,
|
|
5
|
+
BlockSchema,
|
|
6
|
+
InlineContentSchema,
|
|
7
|
+
StyleSchema,
|
|
8
|
+
} from "../../../schema/index.js";
|
|
9
|
+
import { nodeToBlock } from "../../nodeConversions/nodeToBlock.js";
|
|
10
|
+
import { getNodeById } from "../../nodeUtil.js";
|
|
11
|
+
|
|
12
|
+
export function getBlock<
|
|
13
|
+
BSchema extends BlockSchema,
|
|
14
|
+
I extends InlineContentSchema,
|
|
15
|
+
S extends StyleSchema
|
|
16
|
+
>(
|
|
17
|
+
editor: BlockNoteEditor<BSchema, I, S>,
|
|
18
|
+
blockIdentifier: BlockIdentifier
|
|
19
|
+
): Block<BSchema, I, S> | undefined {
|
|
20
|
+
const id =
|
|
21
|
+
typeof blockIdentifier === "string" ? blockIdentifier : blockIdentifier.id;
|
|
22
|
+
|
|
23
|
+
const posInfo = getNodeById(id, editor._tiptapEditor.state.doc);
|
|
24
|
+
if (!posInfo) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return nodeToBlock(
|
|
29
|
+
posInfo.node,
|
|
30
|
+
editor.schema.blockSchema,
|
|
31
|
+
editor.schema.inlineContentSchema,
|
|
32
|
+
editor.schema.styleSchema,
|
|
33
|
+
editor.blockCache
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getPrevBlock<
|
|
38
|
+
BSchema extends BlockSchema,
|
|
39
|
+
I extends InlineContentSchema,
|
|
40
|
+
S extends StyleSchema
|
|
41
|
+
>(
|
|
42
|
+
editor: BlockNoteEditor<BSchema, I, S>,
|
|
43
|
+
blockIdentifier: BlockIdentifier
|
|
44
|
+
): Block<BSchema, I, S> | undefined {
|
|
45
|
+
const id =
|
|
46
|
+
typeof blockIdentifier === "string" ? blockIdentifier : blockIdentifier.id;
|
|
47
|
+
|
|
48
|
+
const posInfo = getNodeById(id, editor._tiptapEditor.state.doc);
|
|
49
|
+
if (!posInfo) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const $posBeforeNode = editor._tiptapEditor.state.doc.resolve(
|
|
54
|
+
posInfo.posBeforeNode
|
|
55
|
+
);
|
|
56
|
+
const nodeToConvert = $posBeforeNode.nodeBefore;
|
|
57
|
+
if (!nodeToConvert) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return nodeToBlock(
|
|
62
|
+
nodeToConvert,
|
|
63
|
+
editor.schema.blockSchema,
|
|
64
|
+
editor.schema.inlineContentSchema,
|
|
65
|
+
editor.schema.styleSchema,
|
|
66
|
+
editor.blockCache
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function getNextBlock<
|
|
71
|
+
BSchema extends BlockSchema,
|
|
72
|
+
I extends InlineContentSchema,
|
|
73
|
+
S extends StyleSchema
|
|
74
|
+
>(
|
|
75
|
+
editor: BlockNoteEditor<BSchema, I, S>,
|
|
76
|
+
blockIdentifier: BlockIdentifier
|
|
77
|
+
): Block<BSchema, I, S> | undefined {
|
|
78
|
+
const id =
|
|
79
|
+
typeof blockIdentifier === "string" ? blockIdentifier : blockIdentifier.id;
|
|
80
|
+
|
|
81
|
+
const posInfo = getNodeById(id, editor._tiptapEditor.state.doc);
|
|
82
|
+
if (!posInfo) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const $posAfterNode = editor._tiptapEditor.state.doc.resolve(
|
|
87
|
+
posInfo.posBeforeNode + posInfo.node.nodeSize
|
|
88
|
+
);
|
|
89
|
+
const nodeToConvert = $posAfterNode.nodeAfter;
|
|
90
|
+
if (!nodeToConvert) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return nodeToBlock(
|
|
95
|
+
nodeToConvert,
|
|
96
|
+
editor.schema.blockSchema,
|
|
97
|
+
editor.schema.inlineContentSchema,
|
|
98
|
+
editor.schema.styleSchema,
|
|
99
|
+
editor.blockCache
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function getParentBlock<
|
|
104
|
+
BSchema extends BlockSchema,
|
|
105
|
+
I extends InlineContentSchema,
|
|
106
|
+
S extends StyleSchema
|
|
107
|
+
>(
|
|
108
|
+
editor: BlockNoteEditor<BSchema, I, S>,
|
|
109
|
+
blockIdentifier: BlockIdentifier
|
|
110
|
+
): Block<BSchema, I, S> | undefined {
|
|
111
|
+
const id =
|
|
112
|
+
typeof blockIdentifier === "string" ? blockIdentifier : blockIdentifier.id;
|
|
113
|
+
|
|
114
|
+
const posInfo = getNodeById(id, editor._tiptapEditor.state.doc);
|
|
115
|
+
if (!posInfo) {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const $posBeforeNode = editor._tiptapEditor.state.doc.resolve(
|
|
120
|
+
posInfo.posBeforeNode
|
|
121
|
+
);
|
|
122
|
+
const parentNode = $posBeforeNode.node();
|
|
123
|
+
const grandparentNode = $posBeforeNode.node(-1);
|
|
124
|
+
const nodeToConvert =
|
|
125
|
+
grandparentNode.type.name !== "doc"
|
|
126
|
+
? parentNode.type.name === "blockGroup"
|
|
127
|
+
? grandparentNode
|
|
128
|
+
: parentNode
|
|
129
|
+
: undefined;
|
|
130
|
+
if (!nodeToConvert) {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return nodeToBlock(
|
|
135
|
+
nodeToConvert,
|
|
136
|
+
editor.schema.blockSchema,
|
|
137
|
+
editor.schema.inlineContentSchema,
|
|
138
|
+
editor.schema.styleSchema,
|
|
139
|
+
editor.blockCache
|
|
140
|
+
);
|
|
141
|
+
}
|