@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.
- package/dist/blocknote.js +2035 -1758
- 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 +4 -1
- 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/clipboard.test.js +6 -3
- package/dist/src/api/clipboard/clipboard.test.js.map +1 -1
- package/dist/src/api/clipboard/fromClipboard/handleFileInsertion.js +1 -1
- package/dist/src/api/clipboard/fromClipboard/handleFileInsertion.js.map +1 -1
- package/dist/src/api/clipboard/fromClipboard/handleVSCodePaste.js +2 -3
- package/dist/src/api/clipboard/fromClipboard/handleVSCodePaste.js.map +1 -1
- package/dist/src/api/clipboard/fromClipboard/pasteExtension.js +5 -5
- package/dist/src/api/clipboard/fromClipboard/pasteExtension.js.map +1 -1
- package/dist/src/api/clipboard/toClipboard/copyExtension.js +4 -2
- package/dist/src/api/clipboard/toClipboard/copyExtension.js.map +1 -1
- package/dist/src/api/nodeUtil.js +1 -1
- package/dist/src/api/nodeUtil.js.map +1 -1
- package/dist/src/api/parsers/markdown/parseMarkdown.test.js +4 -1
- package/dist/src/api/parsers/markdown/parseMarkdown.test.js.map +1 -1
- package/dist/src/blocks/AudioBlockContent/AudioBlockContent.js +14 -7
- package/dist/src/blocks/AudioBlockContent/AudioBlockContent.js.map +1 -1
- package/dist/src/blocks/AudioBlockContent/{audioBlockHelpers.js → parseAudioElement.js} +1 -1
- package/dist/src/blocks/AudioBlockContent/parseAudioElement.js.map +1 -0
- package/dist/src/blocks/FileBlockContent/FileBlockContent.js +5 -4
- package/dist/src/blocks/FileBlockContent/FileBlockContent.js.map +1 -1
- package/dist/src/blocks/FileBlockContent/helpers/parse/parseEmbedElement.js +5 -0
- package/dist/src/blocks/FileBlockContent/helpers/parse/parseEmbedElement.js.map +1 -0
- package/dist/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.js +10 -0
- package/dist/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.js.map +1 -0
- package/dist/src/blocks/FileBlockContent/helpers/render/createAddFileButton.js +39 -0
- package/dist/src/blocks/FileBlockContent/helpers/render/createAddFileButton.js.map +1 -0
- package/dist/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.js +51 -0
- package/dist/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.js.map +1 -0
- package/dist/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.js +17 -0
- package/dist/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.js.map +1 -0
- package/dist/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.js +147 -0
- package/dist/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.js.map +1 -0
- package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.js +9 -0
- package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.js.map +1 -0
- package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js +11 -0
- package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js.map +1 -0
- package/dist/src/blocks/ImageBlockContent/ImageBlockContent.js +17 -9
- package/dist/src/blocks/ImageBlockContent/ImageBlockContent.js.map +1 -1
- package/dist/src/blocks/ImageBlockContent/{imageBlockHelpers.js → parseImageElement.js} +1 -1
- package/dist/src/blocks/ImageBlockContent/parseImageElement.js.map +1 -0
- package/dist/src/blocks/TableBlockContent/TableExtension.js +8 -1
- package/dist/src/blocks/TableBlockContent/TableExtension.js.map +1 -1
- package/dist/src/blocks/VideoBlockContent/VideoBlockContent.js +18 -7
- package/dist/src/blocks/VideoBlockContent/VideoBlockContent.js.map +1 -1
- package/dist/src/blocks/VideoBlockContent/{videoBlockHelpers.js → parseVideoElement.js} +1 -1
- package/dist/src/blocks/VideoBlockContent/parseVideoElement.js.map +1 -0
- package/dist/src/editor/BlockNoteEditor.js +64 -62
- package/dist/src/editor/BlockNoteEditor.js.map +1 -1
- package/dist/src/editor/BlockNoteExtensions.js +5 -8
- 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/LinkToolbar/protocols.js +14 -0
- package/dist/src/extensions/LinkToolbar/protocols.js.map +1 -0
- package/dist/src/extensions/Placeholder/PlaceholderPlugin.js +19 -13
- 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 +8 -1
- package/dist/src/extensions/SideMenu/dragging.js.map +1 -1
- package/dist/src/extensions/SuggestionMenu/SuggestionPlugin.js +3 -3
- package/dist/src/extensions/SuggestionMenu/SuggestionPlugin.js.map +1 -1
- package/dist/src/extensions/TableHandles/TableHandlesPlugin.js +37 -11
- package/dist/src/extensions/TableHandles/TableHandlesPlugin.js.map +1 -1
- package/dist/src/i18n/locales/ru.js +1 -1
- package/dist/src/index.js +9 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/schema/inlineContent/createSpec.js +1 -1
- package/dist/src/schema/inlineContent/createSpec.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 +336 -0
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +5 -1
- 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/__snapshots__/tableAllCells.html +1 -1
- package/src/api/clipboard/__snapshots__/tableCell.html +1 -1
- package/src/api/clipboard/__snapshots__/tableRow.html +1 -1
- package/src/api/clipboard/clipboard.test.ts +7 -3
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +1 -1
- package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +7 -14
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +6 -6
- package/src/api/clipboard/toClipboard/copyExtension.ts +7 -2
- package/src/api/exporters/html/__snapshots__/file/basic/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/file/nested/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/file/noCaption/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/file/noName/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/image/basic/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/image/nested/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/image/noCaption/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/image/noName/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/image/noPreview/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/basic/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/nested/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noCaption/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noCaption/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noName/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noName/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/internal.html +1 -1
- package/src/api/exporters/markdown/__snapshots__/simpleImage/basic/markdown.md +1 -1
- package/src/api/exporters/markdown/__snapshots__/simpleImage/nested/markdown.md +2 -2
- package/src/api/exporters/markdown/__snapshots__/simpleImage/noCaption/markdown.md +1 -1
- package/src/api/exporters/markdown/__snapshots__/simpleImage/noName/markdown.md +1 -1
- package/src/api/nodeUtil.ts +2 -2
- package/src/api/parsers/markdown/parseMarkdown.test.ts +5 -7
- package/src/blocks/AudioBlockContent/AudioBlockContent.ts +13 -14
- package/src/blocks/FileBlockContent/FileBlockContent.ts +5 -12
- package/src/blocks/FileBlockContent/helpers/parse/parseEmbedElement.ts +5 -0
- package/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.ts +16 -0
- package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +63 -0
- package/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.ts +80 -0
- package/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.ts +24 -0
- package/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.ts +204 -0
- package/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.ts +13 -0
- package/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.ts +15 -0
- package/src/blocks/ImageBlockContent/ImageBlockContent.ts +20 -28
- package/src/blocks/TableBlockContent/TableExtension.ts +12 -1
- package/src/blocks/VideoBlockContent/VideoBlockContent.ts +20 -27
- package/src/editor/Block.css +35 -51
- package/src/editor/BlockNoteEditor.ts +101 -92
- package/src/editor/BlockNoteExtensions.ts +9 -8
- package/src/editor/editor.css +1 -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/LinkToolbar/protocols.ts +13 -0
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +29 -21
- package/src/extensions/SideMenu/SideMenuPlugin.ts +5 -1
- package/src/extensions/SideMenu/dragging.ts +8 -1
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +3 -6
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +49 -12
- package/src/i18n/locales/ru.ts +1 -1
- package/src/index.ts +9 -2
- package/src/schema/inlineContent/createSpec.ts +2 -2
- 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/clipboard/fromClipboard/handleVSCodePaste.d.ts +2 -3
- package/types/src/api/clipboard/fromClipboard/pasteExtension.d.ts +1 -3
- package/types/src/api/nodeUtil.d.ts +1 -1
- package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +2 -5
- package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +2 -5
- package/types/src/blocks/FileBlockContent/helpers/parse/parseEmbedElement.d.ts +3 -0
- package/types/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.d.ts +4 -0
- package/types/src/blocks/FileBlockContent/helpers/render/createAddFileButton.d.ts +6 -0
- package/types/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.d.ts +9 -0
- package/types/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.d.ts +6 -0
- package/types/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.d.ts +9 -0
- package/types/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.d.ts +3 -0
- package/types/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.d.ts +3 -0
- package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +2 -5
- package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +2 -5
- package/types/src/editor/BlockNoteEditor.d.ts +60 -14
- package/types/src/editor/BlockNoteExtensions.d.ts +1 -0
- package/types/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.d.ts +1 -0
- package/types/src/extensions/LinkToolbar/protocols.d.ts +2 -0
- package/types/src/index.d.ts +9 -2
- 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/dist/src/blocks/AudioBlockContent/audioBlockHelpers.js.map +0 -1
- package/dist/src/blocks/FileBlockContent/fileBlockHelpers.js +0 -317
- package/dist/src/blocks/FileBlockContent/fileBlockHelpers.js.map +0 -1
- package/dist/src/blocks/ImageBlockContent/imageBlockHelpers.js.map +0 -1
- package/dist/src/blocks/VideoBlockContent/videoBlockHelpers.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/src/blocks/FileBlockContent/fileBlockHelpers.ts +0 -456
- package/types/src/api/blockManipulation/commands/moveBlock/moveBlock.d.ts +0 -5
- package/types/src/blocks/FileBlockContent/fileBlockHelpers.d.ts +0 -41
- /package/src/blocks/AudioBlockContent/{audioBlockHelpers.ts → parseAudioElement.ts} +0 -0
- /package/src/blocks/ImageBlockContent/{imageBlockHelpers.ts → parseImageElement.ts} +0 -0
- /package/src/blocks/VideoBlockContent/{videoBlockHelpers.ts → parseVideoElement.ts} +0 -0
- /package/types/src/api/blockManipulation/commands/{moveBlock/moveBlock.test.d.ts → moveBlocks/moveBlocks.test.d.ts} +0 -0
- /package/types/src/blocks/AudioBlockContent/{audioBlockHelpers.d.ts → parseAudioElement.d.ts} +0 -0
- /package/types/src/blocks/ImageBlockContent/{imageBlockHelpers.d.ts → parseImageElement.d.ts} +0 -0
- /package/types/src/blocks/VideoBlockContent/{videoBlockHelpers.d.ts → parseVideoElement.d.ts} +0 -0
|
@@ -1,456 +0,0 @@
|
|
|
1
|
-
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
2
|
-
import {
|
|
3
|
-
BlockFromConfig,
|
|
4
|
-
BlockSchemaWithBlock,
|
|
5
|
-
FileBlockConfig,
|
|
6
|
-
} from "../../schema/index.js";
|
|
7
|
-
|
|
8
|
-
export const FILE_ICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>`;
|
|
9
|
-
export const createFileBlockWrapper = (
|
|
10
|
-
block: BlockFromConfig<FileBlockConfig, any, any>,
|
|
11
|
-
editor: BlockNoteEditor<
|
|
12
|
-
BlockSchemaWithBlock<FileBlockConfig["type"], FileBlockConfig>,
|
|
13
|
-
any,
|
|
14
|
-
any
|
|
15
|
-
>,
|
|
16
|
-
// TODO: Maybe make optional for default preview
|
|
17
|
-
element: { dom: HTMLElement; destroy?: () => void },
|
|
18
|
-
buttonText?: string,
|
|
19
|
-
buttonIcon?: HTMLElement
|
|
20
|
-
) => {
|
|
21
|
-
const wrapper = document.createElement("div");
|
|
22
|
-
wrapper.className = "bn-file-block-content-wrapper";
|
|
23
|
-
|
|
24
|
-
if (block.props.url === "") {
|
|
25
|
-
const addFileButton = createAddFileButton(
|
|
26
|
-
block,
|
|
27
|
-
editor,
|
|
28
|
-
buttonText,
|
|
29
|
-
buttonIcon
|
|
30
|
-
);
|
|
31
|
-
wrapper.appendChild(addFileButton.dom);
|
|
32
|
-
|
|
33
|
-
const loading = document.createElement("div");
|
|
34
|
-
loading.className = "bn-file-loading-preview";
|
|
35
|
-
loading.textContent = "Loading...";
|
|
36
|
-
|
|
37
|
-
const destroyUploadStartHandler = editor.onUploadStart((blockId) => {
|
|
38
|
-
if (blockId === block.id) {
|
|
39
|
-
wrapper.removeChild(addFileButton.dom);
|
|
40
|
-
wrapper.appendChild(loading);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
const destroyUploadEndHandler = editor.onUploadEnd((blockId) => {
|
|
44
|
-
if (blockId === block.id) {
|
|
45
|
-
wrapper.removeChild(loading);
|
|
46
|
-
wrapper.appendChild(addFileButton.dom);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
dom: wrapper,
|
|
52
|
-
destroy: () => {
|
|
53
|
-
addFileButton.destroy?.();
|
|
54
|
-
destroyUploadStartHandler();
|
|
55
|
-
destroyUploadEndHandler();
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
} else if (block.props.showPreview === false) {
|
|
59
|
-
// TODO: Not using the wrapper element here?
|
|
60
|
-
const file = createDefaultFilePreview(block).dom;
|
|
61
|
-
const element = createFileAndCaptionWrapper(block, file);
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
dom: element.dom,
|
|
65
|
-
};
|
|
66
|
-
} else {
|
|
67
|
-
wrapper.appendChild(element.dom);
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
dom: wrapper,
|
|
71
|
-
destroy: element.destroy,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
// Default file preview, displaying a file icon and file name.
|
|
77
|
-
export const createDefaultFilePreview = (
|
|
78
|
-
block: BlockFromConfig<FileBlockConfig, any, any>
|
|
79
|
-
): { dom: HTMLElement; destroy?: () => void } => {
|
|
80
|
-
const file = document.createElement("div");
|
|
81
|
-
file.className = "bn-file-default-preview";
|
|
82
|
-
|
|
83
|
-
const icon = document.createElement("div");
|
|
84
|
-
icon.className = "bn-file-default-preview-icon";
|
|
85
|
-
icon.innerHTML = FILE_ICON_SVG;
|
|
86
|
-
|
|
87
|
-
const fileName = document.createElement("p");
|
|
88
|
-
fileName.className = "bn-file-default-preview-name";
|
|
89
|
-
fileName.textContent = block.props.name || "";
|
|
90
|
-
|
|
91
|
-
file.appendChild(icon);
|
|
92
|
-
file.appendChild(fileName);
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
dom: file,
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
// Wrapper element containing file preview and caption.
|
|
100
|
-
export const createFileAndCaptionWrapper = (
|
|
101
|
-
block: BlockFromConfig<FileBlockConfig, any, any>,
|
|
102
|
-
file: HTMLElement
|
|
103
|
-
) => {
|
|
104
|
-
const fileAndCaptionWrapper = document.createElement("div");
|
|
105
|
-
fileAndCaptionWrapper.className = "bn-file-and-caption-wrapper";
|
|
106
|
-
|
|
107
|
-
const caption = document.createElement("p");
|
|
108
|
-
caption.className = "bn-file-caption";
|
|
109
|
-
caption.textContent = block.props.caption;
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
typeof block.props.previewWidth === "number" &&
|
|
113
|
-
block.props.previewWidth > 0 &&
|
|
114
|
-
block.props.caption !== undefined
|
|
115
|
-
) {
|
|
116
|
-
caption.style.width = `${block.props.previewWidth}px`;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
fileAndCaptionWrapper.appendChild(file);
|
|
120
|
-
fileAndCaptionWrapper.appendChild(caption);
|
|
121
|
-
|
|
122
|
-
return {
|
|
123
|
-
dom: fileAndCaptionWrapper,
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
// Button element that acts as a placeholder for files with no src.
|
|
128
|
-
export const createAddFileButton = (
|
|
129
|
-
block: BlockFromConfig<FileBlockConfig, any, any>,
|
|
130
|
-
editor: BlockNoteEditor<any, any, any>,
|
|
131
|
-
buttonText?: string,
|
|
132
|
-
buttonIcon?: HTMLElement
|
|
133
|
-
) => {
|
|
134
|
-
const addFileButton = document.createElement("div");
|
|
135
|
-
addFileButton.className = "bn-add-file-button";
|
|
136
|
-
|
|
137
|
-
const addFileButtonIcon = document.createElement("div");
|
|
138
|
-
addFileButtonIcon.className = "bn-add-file-button-icon";
|
|
139
|
-
if (buttonIcon) {
|
|
140
|
-
addFileButtonIcon.appendChild(buttonIcon);
|
|
141
|
-
} else {
|
|
142
|
-
addFileButtonIcon.innerHTML =
|
|
143
|
-
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>';
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const addFileButtonText = document.createElement("p");
|
|
147
|
-
addFileButtonText.className = "bn-add-file-button-text";
|
|
148
|
-
addFileButtonText.innerHTML =
|
|
149
|
-
buttonText || editor.dictionary.file_blocks.file.add_button_text;
|
|
150
|
-
|
|
151
|
-
// Prevents focus from moving to the button.
|
|
152
|
-
const addFileButtonMouseDownHandler = (event: MouseEvent) => {
|
|
153
|
-
event.preventDefault();
|
|
154
|
-
};
|
|
155
|
-
// Opens the file toolbar.
|
|
156
|
-
const addFileButtonClickHandler = () => {
|
|
157
|
-
editor.dispatch(
|
|
158
|
-
editor._tiptapEditor.state.tr.setMeta(editor.filePanel!.plugin, {
|
|
159
|
-
block: block,
|
|
160
|
-
})
|
|
161
|
-
);
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
addFileButton.appendChild(addFileButtonIcon);
|
|
165
|
-
addFileButton.appendChild(addFileButtonText);
|
|
166
|
-
|
|
167
|
-
addFileButton.addEventListener(
|
|
168
|
-
"mousedown",
|
|
169
|
-
addFileButtonMouseDownHandler,
|
|
170
|
-
true
|
|
171
|
-
);
|
|
172
|
-
addFileButton.addEventListener("click", addFileButtonClickHandler, true);
|
|
173
|
-
|
|
174
|
-
return {
|
|
175
|
-
dom: addFileButton,
|
|
176
|
-
destroy: () => {
|
|
177
|
-
addFileButton.removeEventListener(
|
|
178
|
-
"mousedown",
|
|
179
|
-
addFileButtonMouseDownHandler,
|
|
180
|
-
true
|
|
181
|
-
);
|
|
182
|
-
addFileButton.removeEventListener(
|
|
183
|
-
"click",
|
|
184
|
-
addFileButtonClickHandler,
|
|
185
|
-
true
|
|
186
|
-
);
|
|
187
|
-
},
|
|
188
|
-
};
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
export const parseEmbedElement = (embedElement: HTMLEmbedElement) => {
|
|
192
|
-
const url = embedElement.src || undefined;
|
|
193
|
-
|
|
194
|
-
return { url };
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
export const parseFigureElement = (
|
|
198
|
-
figureElement: HTMLElement,
|
|
199
|
-
targetTag: string
|
|
200
|
-
) => {
|
|
201
|
-
const targetElement = figureElement.querySelector(
|
|
202
|
-
targetTag
|
|
203
|
-
) as HTMLElement | null;
|
|
204
|
-
if (!targetElement) {
|
|
205
|
-
return undefined;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const captionElement = figureElement.querySelector("figcaption");
|
|
209
|
-
const caption = captionElement?.textContent ?? undefined;
|
|
210
|
-
|
|
211
|
-
return { targetElement, caption };
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
// Wrapper figure element to display file link with caption. Used for external
|
|
215
|
-
// HTML
|
|
216
|
-
export const createLinkWithCaption = (
|
|
217
|
-
element: HTMLElement,
|
|
218
|
-
caption: string
|
|
219
|
-
) => {
|
|
220
|
-
const wrapper = document.createElement("div");
|
|
221
|
-
const fileCaption = document.createElement("p");
|
|
222
|
-
fileCaption.textContent = caption;
|
|
223
|
-
|
|
224
|
-
wrapper.appendChild(element);
|
|
225
|
-
wrapper.appendChild(fileCaption);
|
|
226
|
-
|
|
227
|
-
return {
|
|
228
|
-
dom: wrapper,
|
|
229
|
-
};
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
// Wrapper figure element to display file preview with caption. Used for
|
|
233
|
-
// external HTML.
|
|
234
|
-
export const createFigureWithCaption = (
|
|
235
|
-
element: HTMLElement,
|
|
236
|
-
caption: string
|
|
237
|
-
) => {
|
|
238
|
-
const figure = document.createElement("figure");
|
|
239
|
-
const captionElement = document.createElement("figcaption");
|
|
240
|
-
captionElement.textContent = caption;
|
|
241
|
-
|
|
242
|
-
figure.appendChild(element);
|
|
243
|
-
figure.appendChild(captionElement);
|
|
244
|
-
|
|
245
|
-
return { dom: figure };
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
// Wrapper element which adds resize handles & logic for visual media file
|
|
249
|
-
// previews.
|
|
250
|
-
export const createResizeHandlesWrapper = (
|
|
251
|
-
block: BlockFromConfig<FileBlockConfig, any, any>,
|
|
252
|
-
editor: BlockNoteEditor<any, any, any>,
|
|
253
|
-
element: HTMLElement,
|
|
254
|
-
getWidth: () => number,
|
|
255
|
-
setWidth: (width: number) => void
|
|
256
|
-
): { dom: HTMLElement; destroy: () => void } => {
|
|
257
|
-
if (!block.props.previewWidth) {
|
|
258
|
-
throw new Error("Block must have a `previewWidth` prop.");
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// Wrapper element for rendered element and resize handles.
|
|
262
|
-
const wrapper = document.createElement("div");
|
|
263
|
-
wrapper.className = "bn-visual-media-wrapper";
|
|
264
|
-
|
|
265
|
-
// Resize handle elements.
|
|
266
|
-
const leftResizeHandle = document.createElement("div");
|
|
267
|
-
leftResizeHandle.className = "bn-visual-media-resize-handle";
|
|
268
|
-
leftResizeHandle.style.left = "4px";
|
|
269
|
-
const rightResizeHandle = document.createElement("div");
|
|
270
|
-
rightResizeHandle.className = "bn-visual-media-resize-handle";
|
|
271
|
-
rightResizeHandle.style.right = "4px";
|
|
272
|
-
|
|
273
|
-
// Temporary parameters set when the user begins resizing the element, used to
|
|
274
|
-
// calculate the new width of the element.
|
|
275
|
-
let resizeParams:
|
|
276
|
-
| {
|
|
277
|
-
handleUsed: "left" | "right";
|
|
278
|
-
initialWidth: number;
|
|
279
|
-
initialClientX: number;
|
|
280
|
-
}
|
|
281
|
-
| undefined;
|
|
282
|
-
|
|
283
|
-
// Updates the element width with an updated width depending on the cursor X
|
|
284
|
-
// offset from when the resize began, and which resize handle is being used.
|
|
285
|
-
const windowMouseMoveHandler = (event: MouseEvent) => {
|
|
286
|
-
if (!resizeParams) {
|
|
287
|
-
if (
|
|
288
|
-
!editor.isEditable &&
|
|
289
|
-
wrapper.contains(leftResizeHandle) &&
|
|
290
|
-
wrapper.contains(rightResizeHandle)
|
|
291
|
-
) {
|
|
292
|
-
wrapper.removeChild(leftResizeHandle);
|
|
293
|
-
wrapper.removeChild(rightResizeHandle);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
let newWidth: number;
|
|
300
|
-
|
|
301
|
-
if (block.props.textAlignment === "center") {
|
|
302
|
-
if (resizeParams.handleUsed === "left") {
|
|
303
|
-
newWidth =
|
|
304
|
-
resizeParams.initialWidth +
|
|
305
|
-
(resizeParams.initialClientX - event.clientX) * 2;
|
|
306
|
-
} else {
|
|
307
|
-
newWidth =
|
|
308
|
-
resizeParams.initialWidth +
|
|
309
|
-
(event.clientX - resizeParams.initialClientX) * 2;
|
|
310
|
-
}
|
|
311
|
-
} else {
|
|
312
|
-
if (resizeParams.handleUsed === "left") {
|
|
313
|
-
newWidth =
|
|
314
|
-
resizeParams.initialWidth +
|
|
315
|
-
resizeParams.initialClientX -
|
|
316
|
-
event.clientX;
|
|
317
|
-
} else {
|
|
318
|
-
newWidth =
|
|
319
|
-
resizeParams.initialWidth +
|
|
320
|
-
event.clientX -
|
|
321
|
-
resizeParams.initialClientX;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// Min element width in px.
|
|
326
|
-
const minWidth = 64;
|
|
327
|
-
|
|
328
|
-
// Ensures the element is not wider than the editor and not smaller than a
|
|
329
|
-
// predetermined minimum width.
|
|
330
|
-
if (newWidth < minWidth) {
|
|
331
|
-
setWidth(minWidth);
|
|
332
|
-
} else if (newWidth > editor.domElement.firstElementChild!.clientWidth) {
|
|
333
|
-
setWidth(editor.domElement.firstElementChild!.clientWidth);
|
|
334
|
-
} else {
|
|
335
|
-
setWidth(newWidth);
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
// Stops mouse movements from resizing the element and updates the block's
|
|
339
|
-
// `width` prop to the new value.
|
|
340
|
-
const windowMouseUpHandler = (event: MouseEvent) => {
|
|
341
|
-
// Hides the drag handles if the cursor is no longer over the element.
|
|
342
|
-
if (
|
|
343
|
-
(!event.target ||
|
|
344
|
-
!wrapper.contains(event.target as Node) ||
|
|
345
|
-
!editor.isEditable) &&
|
|
346
|
-
wrapper.contains(leftResizeHandle) &&
|
|
347
|
-
wrapper.contains(rightResizeHandle)
|
|
348
|
-
) {
|
|
349
|
-
wrapper.removeChild(leftResizeHandle);
|
|
350
|
-
wrapper.removeChild(rightResizeHandle);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
if (!resizeParams) {
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
resizeParams = undefined;
|
|
358
|
-
|
|
359
|
-
editor.updateBlock(block, {
|
|
360
|
-
props: {
|
|
361
|
-
previewWidth: getWidth(),
|
|
362
|
-
},
|
|
363
|
-
});
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
// Shows the resize handles when hovering over the element with the cursor.
|
|
367
|
-
const elementMouseEnterHandler = () => {
|
|
368
|
-
if (editor.isEditable) {
|
|
369
|
-
wrapper.appendChild(leftResizeHandle);
|
|
370
|
-
wrapper.appendChild(rightResizeHandle);
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
// Hides the resize handles when the cursor leaves the element, unless the
|
|
374
|
-
// cursor moves to one of the resize handles.
|
|
375
|
-
const elementMouseLeaveHandler = (event: MouseEvent) => {
|
|
376
|
-
if (
|
|
377
|
-
event.relatedTarget === leftResizeHandle ||
|
|
378
|
-
event.relatedTarget === rightResizeHandle
|
|
379
|
-
) {
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (resizeParams) {
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
if (
|
|
388
|
-
editor.isEditable &&
|
|
389
|
-
wrapper.contains(leftResizeHandle) &&
|
|
390
|
-
wrapper.contains(rightResizeHandle)
|
|
391
|
-
) {
|
|
392
|
-
wrapper.removeChild(leftResizeHandle);
|
|
393
|
-
wrapper.removeChild(rightResizeHandle);
|
|
394
|
-
}
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
// Sets the resize params, allowing the user to begin resizing the element by
|
|
398
|
-
// moving the cursor left or right.
|
|
399
|
-
const leftResizeHandleMouseDownHandler = (event: MouseEvent) => {
|
|
400
|
-
event.preventDefault();
|
|
401
|
-
|
|
402
|
-
wrapper.appendChild(leftResizeHandle);
|
|
403
|
-
wrapper.appendChild(rightResizeHandle);
|
|
404
|
-
|
|
405
|
-
resizeParams = {
|
|
406
|
-
handleUsed: "left",
|
|
407
|
-
initialWidth: block.props.previewWidth!,
|
|
408
|
-
initialClientX: event.clientX,
|
|
409
|
-
};
|
|
410
|
-
};
|
|
411
|
-
const rightResizeHandleMouseDownHandler = (event: MouseEvent) => {
|
|
412
|
-
event.preventDefault();
|
|
413
|
-
|
|
414
|
-
wrapper.appendChild(leftResizeHandle);
|
|
415
|
-
wrapper.appendChild(rightResizeHandle);
|
|
416
|
-
|
|
417
|
-
resizeParams = {
|
|
418
|
-
handleUsed: "right",
|
|
419
|
-
initialWidth: block.props.previewWidth!,
|
|
420
|
-
initialClientX: event.clientX,
|
|
421
|
-
};
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
wrapper.appendChild(element);
|
|
425
|
-
|
|
426
|
-
window.addEventListener("mousemove", windowMouseMoveHandler);
|
|
427
|
-
window.addEventListener("mouseup", windowMouseUpHandler);
|
|
428
|
-
element.addEventListener("mouseenter", elementMouseEnterHandler);
|
|
429
|
-
element.addEventListener("mouseleave", elementMouseLeaveHandler);
|
|
430
|
-
leftResizeHandle.addEventListener(
|
|
431
|
-
"mousedown",
|
|
432
|
-
leftResizeHandleMouseDownHandler
|
|
433
|
-
);
|
|
434
|
-
rightResizeHandle.addEventListener(
|
|
435
|
-
"mousedown",
|
|
436
|
-
rightResizeHandleMouseDownHandler
|
|
437
|
-
);
|
|
438
|
-
|
|
439
|
-
return {
|
|
440
|
-
dom: wrapper,
|
|
441
|
-
destroy: () => {
|
|
442
|
-
window.removeEventListener("mousemove", windowMouseMoveHandler);
|
|
443
|
-
window.removeEventListener("mouseup", windowMouseUpHandler);
|
|
444
|
-
element.removeEventListener("mouseenter", elementMouseEnterHandler);
|
|
445
|
-
element.removeEventListener("mouseleave", elementMouseLeaveHandler);
|
|
446
|
-
leftResizeHandle.removeEventListener(
|
|
447
|
-
"mousedown",
|
|
448
|
-
leftResizeHandleMouseDownHandler
|
|
449
|
-
);
|
|
450
|
-
rightResizeHandle.removeEventListener(
|
|
451
|
-
"mousedown",
|
|
452
|
-
rightResizeHandleMouseDownHandler
|
|
453
|
-
);
|
|
454
|
-
},
|
|
455
|
-
};
|
|
456
|
-
};
|
|
@@ -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;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
2
|
-
import { BlockFromConfig, BlockSchemaWithBlock, FileBlockConfig } from "../../schema/index.js";
|
|
3
|
-
export declare const FILE_ICON_SVG = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z\"></path></svg>";
|
|
4
|
-
export declare const createFileBlockWrapper: (block: BlockFromConfig<FileBlockConfig, any, any>, editor: BlockNoteEditor<BlockSchemaWithBlock<FileBlockConfig["type"], FileBlockConfig>, any, any>, element: {
|
|
5
|
-
dom: HTMLElement;
|
|
6
|
-
destroy?: () => void;
|
|
7
|
-
}, buttonText?: string, buttonIcon?: HTMLElement) => {
|
|
8
|
-
dom: HTMLDivElement;
|
|
9
|
-
destroy?: undefined;
|
|
10
|
-
} | {
|
|
11
|
-
dom: HTMLDivElement;
|
|
12
|
-
destroy: (() => void) | undefined;
|
|
13
|
-
};
|
|
14
|
-
export declare const createDefaultFilePreview: (block: BlockFromConfig<FileBlockConfig, any, any>) => {
|
|
15
|
-
dom: HTMLElement;
|
|
16
|
-
destroy?: () => void;
|
|
17
|
-
};
|
|
18
|
-
export declare const createFileAndCaptionWrapper: (block: BlockFromConfig<FileBlockConfig, any, any>, file: HTMLElement) => {
|
|
19
|
-
dom: HTMLDivElement;
|
|
20
|
-
};
|
|
21
|
-
export declare const createAddFileButton: (block: BlockFromConfig<FileBlockConfig, any, any>, editor: BlockNoteEditor<any, any, any>, buttonText?: string, buttonIcon?: HTMLElement) => {
|
|
22
|
-
dom: HTMLDivElement;
|
|
23
|
-
destroy: () => void;
|
|
24
|
-
};
|
|
25
|
-
export declare const parseEmbedElement: (embedElement: HTMLEmbedElement) => {
|
|
26
|
-
url: string | undefined;
|
|
27
|
-
};
|
|
28
|
-
export declare const parseFigureElement: (figureElement: HTMLElement, targetTag: string) => {
|
|
29
|
-
targetElement: HTMLElement;
|
|
30
|
-
caption: string | undefined;
|
|
31
|
-
} | undefined;
|
|
32
|
-
export declare const createLinkWithCaption: (element: HTMLElement, caption: string) => {
|
|
33
|
-
dom: HTMLDivElement;
|
|
34
|
-
};
|
|
35
|
-
export declare const createFigureWithCaption: (element: HTMLElement, caption: string) => {
|
|
36
|
-
dom: HTMLElement;
|
|
37
|
-
};
|
|
38
|
-
export declare const createResizeHandlesWrapper: (block: BlockFromConfig<FileBlockConfig, any, any>, editor: BlockNoteEditor<any, any, any>, element: HTMLElement, getWidth: () => number, setWidth: (width: number) => void) => {
|
|
39
|
-
dom: HTMLElement;
|
|
40
|
-
destroy: () => void;
|
|
41
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/types/src/blocks/AudioBlockContent/{audioBlockHelpers.d.ts → parseAudioElement.d.ts}
RENAMED
|
File without changes
|
/package/types/src/blocks/ImageBlockContent/{imageBlockHelpers.d.ts → parseImageElement.d.ts}
RENAMED
|
File without changes
|
/package/types/src/blocks/VideoBlockContent/{videoBlockHelpers.d.ts → parseVideoElement.d.ts}
RENAMED
|
File without changes
|