@blocknote/core 0.37.0 → 0.39.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/BlockNoteSchema-DmZ6UQfY.cjs +11 -0
- package/dist/BlockNoteSchema-DmZ6UQfY.cjs.map +1 -0
- package/dist/BlockNoteSchema-oR047ACf.js +4275 -0
- package/dist/BlockNoteSchema-oR047ACf.js.map +1 -0
- package/dist/blocknote.cjs +4 -12
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +3311 -7230
- package/dist/blocknote.js.map +1 -1
- package/dist/blocks.cjs +2 -0
- package/dist/blocks.cjs.map +1 -0
- package/dist/blocks.js +71 -0
- package/dist/blocks.js.map +1 -0
- package/dist/{en-CvDoFvhc.js → en-Bq3Es3Np.js} +6 -12
- package/dist/en-Bq3Es3Np.js.map +1 -0
- package/dist/en-D3B48eJ7.cjs +2 -0
- package/dist/en-D3B48eJ7.cjs.map +1 -0
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +109 -229
- package/dist/locales.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/webpack-stats.json +1 -1
- package/package.json +25 -22
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +1 -1
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +2 -2
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +34 -25
- package/src/api/blockManipulation/setupTestEnv.ts +0 -1
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +4 -8
- package/src/api/clipboard/toClipboard/copyExtension.ts +1 -3
- package/src/api/exporters/html/externalHTMLExporter.ts +0 -1
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +128 -28
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +101 -41
- package/src/api/exporters/markdown/markdownExporter.ts +13 -22
- package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +2 -12
- package/src/api/parsers/html/parseHTML.ts +3 -2
- package/src/api/parsers/html/util/nestedLists.test.ts +8 -8
- package/src/api/parsers/markdown/parseMarkdown.ts +17 -14
- package/src/api/pmUtil.ts +1 -1
- package/src/api/positionMapping.test.ts +197 -33
- package/src/api/positionMapping.ts +4 -6
- package/src/blocks/Audio/block.ts +174 -0
- package/src/blocks/BlockNoteSchema.ts +59 -0
- package/src/blocks/Code/block.ts +303 -0
- package/src/blocks/Code/shiki.ts +73 -0
- package/src/blocks/File/block.ts +98 -0
- package/src/blocks/{FileBlockContent → File}/helpers/render/createAddFileButton.ts +8 -4
- package/src/blocks/{FileBlockContent → File}/helpers/render/createFileBlockWrapper.ts +16 -13
- package/src/blocks/{FileBlockContent → File}/helpers/render/createFileNameWithIcon.ts +15 -2
- package/src/blocks/{FileBlockContent → File}/helpers/render/createResizableFileBlockWrapper.ts +63 -19
- package/src/blocks/Heading/block.ts +138 -0
- package/src/blocks/Image/block.ts +190 -0
- package/src/blocks/ListItem/BulletListItem/block.ts +116 -0
- package/src/blocks/ListItem/CheckListItem/block.ts +175 -0
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +173 -0
- package/src/blocks/ListItem/NumberedListItem/block.ts +133 -0
- package/src/blocks/ListItem/ToggleListItem/block.ts +78 -0
- package/src/blocks/PageBreak/block.ts +72 -0
- package/src/blocks/{PageBreakBlockContent → PageBreak}/getPageBreakSlashMenuItems.ts +9 -7
- package/src/blocks/Paragraph/block.ts +80 -0
- package/src/blocks/Quote/block.ts +90 -0
- package/src/blocks/{TableBlockContent/TableBlockContent.ts → Table/block.ts} +169 -51
- package/src/blocks/ToggleWrapper/createToggleWrapper.ts +1 -1
- package/src/blocks/Video/block.ts +143 -0
- package/src/blocks/defaultBlockHelpers.ts +2 -2
- package/src/blocks/defaultBlockTypeGuards.ts +143 -174
- package/src/blocks/defaultBlocks.ts +107 -35
- package/src/blocks/defaultProps.ts +145 -4
- package/src/blocks/index.ts +26 -0
- package/src/blocks/utils/listItemEnterHandler.ts +42 -0
- package/src/editor/Block.css +54 -18
- package/src/editor/BlockNoteEditor.ts +265 -230
- package/src/editor/BlockNoteExtension.ts +92 -0
- package/src/editor/BlockNoteExtensions.ts +20 -16
- package/src/editor/defaultColors.ts +2 -2
- package/src/exporter/Exporter.ts +1 -1
- package/src/exporter/mapping.ts +1 -1
- package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +3 -20
- package/src/extensions/BackgroundColor/BackgroundColorMark.ts +6 -8
- package/src/extensions/BlockChange/BlockChangePlugin.ts +2 -1
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +2 -2
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +2 -2
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -1
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -1
- package/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.ts +52 -0
- package/src/extensions/Collaboration/schemaMigration/migrationRules/index.ts +4 -0
- package/src/extensions/Collaboration/schemaMigration/migrationRules/migrationRule.ts +4 -0
- package/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.ts +78 -0
- package/src/extensions/Comments/CommentsPlugin.ts +2 -0
- package/src/extensions/FilePanel/FilePanelPlugin.ts +5 -10
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +1 -1
- package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +4 -3
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +2 -2
- package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +1 -23
- package/src/extensions/SideMenu/SideMenuPlugin.ts +0 -2
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +0 -5
- package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +6 -2
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +24 -17
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +2 -2
- package/src/extensions/TextAlignment/TextAlignmentExtension.ts +5 -11
- package/src/extensions/TextColor/TextColorExtension.ts +3 -17
- package/src/extensions/TextColor/TextColorMark.ts +4 -9
- package/src/extensions/UniqueID/UniqueID.ts +6 -13
- package/src/i18n/locales/ar.ts +6 -12
- package/src/i18n/locales/de.ts +6 -12
- package/src/i18n/locales/en.ts +6 -12
- package/src/i18n/locales/es.ts +6 -12
- package/src/i18n/locales/fr.ts +6 -12
- package/src/i18n/locales/he.ts +6 -12
- package/src/i18n/locales/hr.ts +6 -12
- package/src/i18n/locales/is.ts +6 -12
- package/src/i18n/locales/it.ts +6 -12
- package/src/i18n/locales/ja.ts +6 -12
- package/src/i18n/locales/ko.ts +6 -12
- package/src/i18n/locales/nl.ts +6 -12
- package/src/i18n/locales/no.ts +6 -12
- package/src/i18n/locales/pl.ts +6 -12
- package/src/i18n/locales/pt.ts +6 -12
- package/src/i18n/locales/ru.ts +6 -12
- package/src/i18n/locales/sk.ts +6 -12
- package/src/i18n/locales/uk.ts +6 -12
- package/src/i18n/locales/vi.ts +6 -12
- package/src/i18n/locales/zh-tw.ts +6 -12
- package/src/i18n/locales/zh.ts +6 -12
- package/src/index.ts +2 -29
- package/src/schema/blocks/createSpec.ts +342 -169
- package/src/schema/blocks/internal.ts +77 -138
- package/src/schema/blocks/types.ts +264 -94
- package/src/schema/index.ts +1 -0
- package/src/schema/inlineContent/createSpec.ts +99 -21
- package/src/schema/inlineContent/internal.ts +16 -7
- package/src/schema/inlineContent/types.ts +24 -2
- package/src/schema/propTypes.ts +15 -9
- package/src/schema/schema.ts +209 -0
- package/src/schema/styles/createSpec.ts +79 -31
- package/src/schema/styles/internal.ts +61 -2
- package/src/schema/styles/types.ts +17 -3
- package/src/util/topo-sort.test.ts +125 -0
- package/src/util/topo-sort.ts +160 -0
- package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +2 -1
- package/types/src/api/blockManipulation/selections/selection.d.ts +1 -1
- package/types/src/api/blockManipulation/setupTestEnv.d.ts +29 -543
- package/types/src/api/exporters/html/util/serializeBlocksExternalHTML.d.ts +1 -1
- package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +1 -1
- package/types/src/api/exporters/markdown/markdownExporter.d.ts +1 -1
- package/types/src/api/parsers/html/parseHTML.d.ts +1 -1
- package/types/src/api/parsers/markdown/parseMarkdown.d.ts +2 -2
- package/types/src/api/pmUtil.d.ts +1 -1
- package/types/src/blocks/Audio/block.d.ts +58 -0
- package/types/src/blocks/BlockNoteSchema.d.ts +18 -0
- package/types/src/blocks/{CodeBlockContent/CodeBlockContent.d.ts → Code/block.d.ts} +25 -26
- package/types/src/blocks/Code/shiki.d.ts +4 -0
- package/types/src/blocks/File/block.d.ts +37 -0
- package/types/src/blocks/File/helpers/render/createAddFileButton.d.ts +6 -0
- package/types/src/blocks/File/helpers/render/createFileBlockWrapper.d.ts +25 -0
- package/types/src/blocks/{FileBlockContent → File}/helpers/render/createFileNameWithIcon.d.ts +6 -2
- package/types/src/blocks/File/helpers/render/createResizableFileBlockWrapper.d.ts +31 -0
- package/types/src/blocks/Heading/block.d.ts +71 -0
- package/types/src/blocks/Image/block.d.ts +102 -0
- package/types/src/blocks/ListItem/BulletListItem/block.d.ts +25 -0
- package/types/src/blocks/ListItem/CheckListItem/block.d.ts +33 -0
- package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.d.ts +8 -0
- package/types/src/blocks/ListItem/NumberedListItem/block.d.ts +33 -0
- package/types/src/blocks/ListItem/ToggleListItem/block.d.ts +25 -0
- package/types/src/blocks/PageBreak/block.d.ts +11 -0
- package/types/src/blocks/{PageBreakBlockContent → PageBreak}/getPageBreakSlashMenuItems.d.ts +4 -2
- package/types/src/blocks/Paragraph/block.d.ts +25 -0
- package/types/src/blocks/Quote/block.d.ts +17 -0
- package/types/src/blocks/Table/block.d.ts +21 -0
- package/types/src/blocks/Video/block.d.ts +67 -0
- package/types/src/blocks/defaultBlockHelpers.d.ts +1 -1
- package/types/src/blocks/defaultBlockTypeGuards.d.ts +15 -36
- package/types/src/blocks/defaultBlocks.d.ts +221 -1060
- package/types/src/blocks/defaultProps.d.ts +17 -1
- package/types/src/blocks/index.d.ts +24 -0
- package/types/src/blocks/utils/listItemEnterHandler.d.ts +2 -0
- package/types/src/editor/BlockNoteEditor.d.ts +39 -75
- package/types/src/editor/BlockNoteExtension.d.ts +67 -0
- package/types/src/editor/BlockNoteExtensions.d.ts +2 -0
- package/types/src/editor/defaultColors.d.ts +8 -76
- package/types/src/exporter/Exporter.d.ts +1 -1
- package/types/src/exporter/mapping.d.ts +1 -1
- package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +4 -1
- package/types/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.d.ts +7 -0
- package/types/src/extensions/Collaboration/schemaMigration/migrationRules/index.d.ts +3 -0
- package/types/src/extensions/Collaboration/schemaMigration/migrationRules/migrationRule.d.ts +3 -0
- package/types/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.d.ts +2 -0
- package/types/src/extensions/Comments/CommentsPlugin.d.ts +3 -1
- package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +4 -4
- package/types/src/extensions/TextColor/TextColorMark.d.ts +4 -1
- package/types/src/i18n/locales/en.d.ts +1 -12
- package/types/src/i18n/locales/sk.d.ts +1 -12
- package/types/src/index.d.ts +2 -26
- package/types/src/schema/blocks/createSpec.d.ts +16 -36
- package/types/src/schema/blocks/internal.d.ts +11 -33
- package/types/src/schema/blocks/types.d.ts +181 -57
- package/types/src/schema/index.d.ts +1 -0
- package/types/src/schema/inlineContent/createSpec.d.ts +36 -2
- package/types/src/schema/inlineContent/internal.d.ts +7 -15
- package/types/src/schema/inlineContent/types.d.ts +15 -1
- package/types/src/schema/propTypes.d.ts +4 -4
- package/types/src/schema/schema.d.ts +40 -0
- package/types/src/schema/styles/createSpec.d.ts +6 -4
- package/types/src/schema/styles/internal.d.ts +6 -3
- package/types/src/schema/styles/types.d.ts +11 -2
- package/types/src/util/topo-sort.d.ts +18 -0
- package/types/src/util/topo-sort.test.d.ts +1 -0
- package/dist/en-CvDoFvhc.js.map +0 -1
- package/dist/en-ub2yVBX0.cjs +0 -2
- package/dist/en-ub2yVBX0.cjs.map +0 -1
- package/src/blocks/AudioBlockContent/AudioBlockContent.ts +0 -145
- package/src/blocks/CodeBlockContent/CodeBlockContent.ts +0 -445
- package/src/blocks/FileBlockContent/FileBlockContent.ts +0 -100
- package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +0 -159
- package/src/blocks/ImageBlockContent/ImageBlockContent.ts +0 -160
- package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +0 -134
- package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +0 -299
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +0 -86
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +0 -172
- package/src/blocks/ListItemBlockContent/ToggleListItemBlockContent/ToggleListItemBlockContent.ts +0 -104
- package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +0 -49
- package/src/blocks/PageBreakBlockContent/schema.ts +0 -40
- package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +0 -78
- package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +0 -121
- package/src/blocks/VideoBlockContent/VideoBlockContent.ts +0 -159
- package/src/editor/BlockNoteSchema.ts +0 -107
- package/src/editor/BlockNoteTipTapEditor.ts +0 -335
- package/src/util/esmDependencies.ts +0 -51
- package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +0 -99
- package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +0 -90
- package/types/src/blocks/FileBlockContent/helpers/render/createAddFileButton.d.ts +0 -6
- package/types/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.d.ts +0 -9
- package/types/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.d.ts +0 -9
- package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +0 -67
- package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +0 -131
- package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +0 -46
- package/types/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.d.ts +0 -55
- package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.d.ts +0 -2
- package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +0 -58
- package/types/src/blocks/ListItemBlockContent/ToggleListItemBlockContent/ToggleListItemBlockContent.d.ts +0 -46
- package/types/src/blocks/PageBreakBlockContent/PageBreakBlockContent.d.ts +0 -31
- package/types/src/blocks/PageBreakBlockContent/schema.d.ts +0 -86
- package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +0 -52
- package/types/src/blocks/QuoteBlockContent/QuoteBlockContent.d.ts +0 -52
- package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +0 -39
- package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +0 -131
- package/types/src/editor/BlockNoteSchema.d.ts +0 -34
- package/types/src/editor/BlockNoteTipTapEditor.d.ts +0 -43
- package/types/src/util/esmDependencies.d.ts +0 -24
- /package/src/blocks/{AudioBlockContent → Audio}/parseAudioElement.ts +0 -0
- /package/src/blocks/{FileBlockContent → File}/helpers/parse/parseEmbedElement.ts +0 -0
- /package/src/blocks/{FileBlockContent → File}/helpers/parse/parseFigureElement.ts +0 -0
- /package/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createFigureWithCaption.ts +0 -0
- /package/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createLinkWithCaption.ts +0 -0
- /package/src/blocks/{FileBlockContent → File/helpers}/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -0
- /package/src/blocks/{ImageBlockContent → Image}/parseImageElement.ts +0 -0
- /package/src/blocks/{ListItemBlockContent → ListItem}/ListItemKeyboardShortcuts.ts +0 -0
- /package/src/blocks/{ListItemBlockContent → ListItem}/getListItemContent.ts +0 -0
- /package/src/blocks/{TableBlockContent → Table}/TableExtension.ts +0 -0
- /package/src/blocks/{VideoBlockContent → Video}/parseVideoElement.ts +0 -0
- /package/types/src/blocks/{AudioBlockContent → Audio}/parseAudioElement.d.ts +0 -0
- /package/types/src/blocks/{FileBlockContent → File}/helpers/parse/parseEmbedElement.d.ts +0 -0
- /package/types/src/blocks/{FileBlockContent → File}/helpers/parse/parseFigureElement.d.ts +0 -0
- /package/types/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createFigureWithCaption.d.ts +0 -0
- /package/types/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createLinkWithCaption.d.ts +0 -0
- /package/types/src/blocks/{FileBlockContent → File/helpers}/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +0 -0
- /package/types/src/blocks/{ImageBlockContent → Image}/parseImageElement.d.ts +0 -0
- /package/types/src/blocks/{ListItemBlockContent → ListItem}/ListItemKeyboardShortcuts.d.ts +0 -0
- /package/types/src/blocks/{ListItemBlockContent → ListItem}/getListItemContent.d.ts +0 -0
- /package/types/src/blocks/{TableBlockContent → Table}/TableExtension.d.ts +0 -0
- /package/types/src/blocks/{VideoBlockContent → Video}/parseVideoElement.d.ts +0 -0
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
2
|
-
import {
|
|
3
|
-
BlockFromConfig,
|
|
4
|
-
createBlockSpec,
|
|
5
|
-
FileBlockConfig,
|
|
6
|
-
Props,
|
|
7
|
-
PropSchema,
|
|
8
|
-
} from "../../schema/index.js";
|
|
9
|
-
import { defaultProps } from "../defaultProps.js";
|
|
10
|
-
import { parseFigureElement } from "../FileBlockContent/helpers/parse/parseFigureElement.js";
|
|
11
|
-
import { createFigureWithCaption } from "../FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.js";
|
|
12
|
-
import { createLinkWithCaption } from "../FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js";
|
|
13
|
-
import { createResizableFileBlockWrapper } from "../FileBlockContent/helpers/render/createResizableFileBlockWrapper.js";
|
|
14
|
-
import { parseVideoElement } from "./parseVideoElement.js";
|
|
15
|
-
|
|
16
|
-
export const FILE_VIDEO_ICON_SVG =
|
|
17
|
-
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 3.9934C2 3.44476 2.45531 3 2.9918 3H21.0082C21.556 3 22 3.44495 22 3.9934V20.0066C22 20.5552 21.5447 21 21.0082 21H2.9918C2.44405 21 2 20.5551 2 20.0066V3.9934ZM8 5V19H16V5H8ZM4 5V7H6V5H4ZM18 5V7H20V5H18ZM4 9V11H6V9H4ZM18 9V11H20V9H18ZM4 13V15H6V13H4ZM18 13V15H20V13H18ZM4 17V19H6V17H4ZM18 17V19H20V17H18Z"></path></svg>';
|
|
18
|
-
|
|
19
|
-
export const videoPropSchema = {
|
|
20
|
-
textAlignment: defaultProps.textAlignment,
|
|
21
|
-
backgroundColor: defaultProps.backgroundColor,
|
|
22
|
-
// File name.
|
|
23
|
-
name: {
|
|
24
|
-
default: "" as const,
|
|
25
|
-
},
|
|
26
|
-
// File url.
|
|
27
|
-
url: {
|
|
28
|
-
default: "" as const,
|
|
29
|
-
},
|
|
30
|
-
// File caption.
|
|
31
|
-
caption: {
|
|
32
|
-
default: "" as const,
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
showPreview: {
|
|
36
|
-
default: true,
|
|
37
|
-
},
|
|
38
|
-
// File preview width in px.
|
|
39
|
-
previewWidth: {
|
|
40
|
-
default: undefined,
|
|
41
|
-
type: "number",
|
|
42
|
-
},
|
|
43
|
-
} satisfies PropSchema;
|
|
44
|
-
|
|
45
|
-
export const videoBlockConfig = {
|
|
46
|
-
type: "video" as const,
|
|
47
|
-
propSchema: videoPropSchema,
|
|
48
|
-
content: "none",
|
|
49
|
-
isFileBlock: true,
|
|
50
|
-
fileBlockAccept: ["video/*"],
|
|
51
|
-
} satisfies FileBlockConfig;
|
|
52
|
-
|
|
53
|
-
export const videoRender = (
|
|
54
|
-
block: BlockFromConfig<typeof videoBlockConfig, any, any>,
|
|
55
|
-
editor: BlockNoteEditor<any, any, any>,
|
|
56
|
-
) => {
|
|
57
|
-
const icon = document.createElement("div");
|
|
58
|
-
icon.innerHTML = FILE_VIDEO_ICON_SVG;
|
|
59
|
-
|
|
60
|
-
const videoWrapper = document.createElement("div");
|
|
61
|
-
videoWrapper.className = "bn-visual-media-wrapper";
|
|
62
|
-
|
|
63
|
-
const video = document.createElement("video");
|
|
64
|
-
video.className = "bn-visual-media";
|
|
65
|
-
if (editor.resolveFileUrl) {
|
|
66
|
-
editor.resolveFileUrl(block.props.url).then((downloadUrl) => {
|
|
67
|
-
video.src = downloadUrl;
|
|
68
|
-
});
|
|
69
|
-
} else {
|
|
70
|
-
video.src = block.props.url;
|
|
71
|
-
}
|
|
72
|
-
video.controls = true;
|
|
73
|
-
video.contentEditable = "false";
|
|
74
|
-
video.draggable = false;
|
|
75
|
-
video.width = block.props.previewWidth;
|
|
76
|
-
videoWrapper.appendChild(video);
|
|
77
|
-
|
|
78
|
-
return createResizableFileBlockWrapper(
|
|
79
|
-
block,
|
|
80
|
-
editor,
|
|
81
|
-
{ dom: videoWrapper },
|
|
82
|
-
videoWrapper,
|
|
83
|
-
editor.dictionary.file_blocks.video.add_button_text,
|
|
84
|
-
icon.firstElementChild as HTMLElement,
|
|
85
|
-
);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export const videoParse = (
|
|
89
|
-
element: HTMLElement,
|
|
90
|
-
): Partial<Props<typeof videoBlockConfig.propSchema>> | undefined => {
|
|
91
|
-
if (element.tagName === "VIDEO") {
|
|
92
|
-
// Ignore if parent figure has already been parsed.
|
|
93
|
-
if (element.closest("figure")) {
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return parseVideoElement(element as HTMLVideoElement);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (element.tagName === "FIGURE") {
|
|
101
|
-
const parsedFigure = parseFigureElement(element, "video");
|
|
102
|
-
if (!parsedFigure) {
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const { targetElement, caption } = parsedFigure;
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
...parseVideoElement(targetElement as HTMLVideoElement),
|
|
110
|
-
caption,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return undefined;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export const videoToExternalHTML = (
|
|
118
|
-
block: BlockFromConfig<typeof videoBlockConfig, any, any>,
|
|
119
|
-
) => {
|
|
120
|
-
if (!block.props.url) {
|
|
121
|
-
const div = document.createElement("p");
|
|
122
|
-
div.textContent = "Add video";
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
dom: div,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
let video;
|
|
130
|
-
if (block.props.showPreview) {
|
|
131
|
-
video = document.createElement("video");
|
|
132
|
-
video.src = block.props.url;
|
|
133
|
-
if (block.props.previewWidth) {
|
|
134
|
-
video.width = block.props.previewWidth;
|
|
135
|
-
}
|
|
136
|
-
} else {
|
|
137
|
-
video = document.createElement("a");
|
|
138
|
-
video.href = block.props.url;
|
|
139
|
-
video.textContent = block.props.name || block.props.url;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (block.props.caption) {
|
|
143
|
-
if (block.props.showPreview) {
|
|
144
|
-
return createFigureWithCaption(video, block.props.caption);
|
|
145
|
-
} else {
|
|
146
|
-
return createLinkWithCaption(video, block.props.caption);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return {
|
|
151
|
-
dom: video,
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
export const VideoBlock = createBlockSpec(videoBlockConfig, {
|
|
156
|
-
render: videoRender,
|
|
157
|
-
parse: videoParse,
|
|
158
|
-
toExternalHTML: videoToExternalHTML,
|
|
159
|
-
});
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defaultBlockSpecs,
|
|
3
|
-
defaultInlineContentSpecs,
|
|
4
|
-
defaultStyleSpecs,
|
|
5
|
-
} from "../blocks/defaultBlocks.js";
|
|
6
|
-
import type {
|
|
7
|
-
BlockNoDefaults,
|
|
8
|
-
PartialBlockNoDefaults,
|
|
9
|
-
} from "../schema/blocks/types.js";
|
|
10
|
-
import {
|
|
11
|
-
BlockSchema,
|
|
12
|
-
BlockSchemaFromSpecs,
|
|
13
|
-
BlockSpecs,
|
|
14
|
-
InlineContentSchema,
|
|
15
|
-
InlineContentSchemaFromSpecs,
|
|
16
|
-
InlineContentSpecs,
|
|
17
|
-
StyleSchema,
|
|
18
|
-
StyleSchemaFromSpecs,
|
|
19
|
-
StyleSpecs,
|
|
20
|
-
getBlockSchemaFromSpecs,
|
|
21
|
-
getInlineContentSchemaFromSpecs,
|
|
22
|
-
getStyleSchemaFromSpecs,
|
|
23
|
-
} from "../schema/index.js";
|
|
24
|
-
import type { BlockNoteEditor } from "./BlockNoteEditor.js";
|
|
25
|
-
|
|
26
|
-
function removeUndefined<T extends Record<string, any> | undefined>(obj: T): T {
|
|
27
|
-
if (!obj) {
|
|
28
|
-
return obj;
|
|
29
|
-
}
|
|
30
|
-
return Object.fromEntries(
|
|
31
|
-
Object.entries(obj).filter(([, value]) => value !== undefined),
|
|
32
|
-
) as T;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export class BlockNoteSchema<
|
|
36
|
-
BSchema extends BlockSchema,
|
|
37
|
-
ISchema extends InlineContentSchema,
|
|
38
|
-
SSchema extends StyleSchema,
|
|
39
|
-
> {
|
|
40
|
-
public readonly blockSpecs: BlockSpecs;
|
|
41
|
-
public readonly inlineContentSpecs: InlineContentSpecs;
|
|
42
|
-
public readonly styleSpecs: StyleSpecs;
|
|
43
|
-
|
|
44
|
-
public readonly blockSchema: BSchema;
|
|
45
|
-
public readonly inlineContentSchema: ISchema;
|
|
46
|
-
public readonly styleSchema: SSchema;
|
|
47
|
-
|
|
48
|
-
// Helper so that you can use typeof schema.BlockNoteEditor
|
|
49
|
-
public readonly BlockNoteEditor: BlockNoteEditor<BSchema, ISchema, SSchema> =
|
|
50
|
-
"only for types" as any;
|
|
51
|
-
|
|
52
|
-
public readonly Block: BlockNoDefaults<BSchema, ISchema, SSchema> =
|
|
53
|
-
"only for types" as any;
|
|
54
|
-
|
|
55
|
-
public readonly PartialBlock: PartialBlockNoDefaults<
|
|
56
|
-
BSchema,
|
|
57
|
-
ISchema,
|
|
58
|
-
SSchema
|
|
59
|
-
> = "only for types" as any;
|
|
60
|
-
|
|
61
|
-
public static create<
|
|
62
|
-
BSpecs extends BlockSpecs = typeof defaultBlockSpecs,
|
|
63
|
-
ISpecs extends InlineContentSpecs = typeof defaultInlineContentSpecs,
|
|
64
|
-
SSpecs extends StyleSpecs = typeof defaultStyleSpecs,
|
|
65
|
-
>(options?: {
|
|
66
|
-
/**
|
|
67
|
-
* A list of custom block types that should be available in the editor.
|
|
68
|
-
*/
|
|
69
|
-
blockSpecs?: BSpecs;
|
|
70
|
-
/**
|
|
71
|
-
* A list of custom InlineContent types that should be available in the editor.
|
|
72
|
-
*/
|
|
73
|
-
inlineContentSpecs?: ISpecs;
|
|
74
|
-
/**
|
|
75
|
-
* A list of custom Styles that should be available in the editor.
|
|
76
|
-
*/
|
|
77
|
-
styleSpecs?: SSpecs;
|
|
78
|
-
}) {
|
|
79
|
-
return new BlockNoteSchema<
|
|
80
|
-
BlockSchemaFromSpecs<BSpecs>,
|
|
81
|
-
InlineContentSchemaFromSpecs<ISpecs>,
|
|
82
|
-
StyleSchemaFromSpecs<SSpecs>
|
|
83
|
-
>(options);
|
|
84
|
-
// as BlockNoteSchema<
|
|
85
|
-
// BlockSchemaFromSpecs<BSpecs>,
|
|
86
|
-
// InlineContentSchemaFromSpecs<ISpecs>,
|
|
87
|
-
// StyleSchemaFromSpecs<SSpecs>
|
|
88
|
-
// >;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
constructor(opts?: {
|
|
92
|
-
blockSpecs?: BlockSpecs;
|
|
93
|
-
inlineContentSpecs?: InlineContentSpecs;
|
|
94
|
-
styleSpecs?: StyleSpecs;
|
|
95
|
-
}) {
|
|
96
|
-
this.blockSpecs = removeUndefined(opts?.blockSpecs) || defaultBlockSpecs;
|
|
97
|
-
this.inlineContentSpecs =
|
|
98
|
-
removeUndefined(opts?.inlineContentSpecs) || defaultInlineContentSpecs;
|
|
99
|
-
this.styleSpecs = removeUndefined(opts?.styleSpecs) || defaultStyleSpecs;
|
|
100
|
-
|
|
101
|
-
this.blockSchema = getBlockSchemaFromSpecs(this.blockSpecs) as any;
|
|
102
|
-
this.inlineContentSchema = getInlineContentSchemaFromSpecs(
|
|
103
|
-
this.inlineContentSpecs,
|
|
104
|
-
) as any;
|
|
105
|
-
this.styleSchema = getStyleSchemaFromSpecs(this.styleSpecs) as any;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Editor,
|
|
3
|
-
EditorOptions,
|
|
4
|
-
Editor as TiptapEditor,
|
|
5
|
-
createDocument,
|
|
6
|
-
} from "@tiptap/core";
|
|
7
|
-
|
|
8
|
-
import { Node } from "@tiptap/pm/model";
|
|
9
|
-
|
|
10
|
-
import { EditorView } from "@tiptap/pm/view";
|
|
11
|
-
|
|
12
|
-
import { EditorState, Transaction } from "@tiptap/pm/state";
|
|
13
|
-
import { blockToNode } from "../api/nodeConversions/blockToNode.js";
|
|
14
|
-
import { PartialBlock } from "../blocks/defaultBlocks.js";
|
|
15
|
-
import { StyleSchema } from "../schema/index.js";
|
|
16
|
-
import type { BlockNoteEditor } from "./BlockNoteEditor.js";
|
|
17
|
-
|
|
18
|
-
export type BlockNoteTipTapEditorOptions = Partial<
|
|
19
|
-
Omit<EditorOptions, "content">
|
|
20
|
-
> & {
|
|
21
|
-
content: PartialBlock<any, any, any>[];
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Custom Editor class that extends TiptapEditor and separates
|
|
26
|
-
* the creation of the view from the constructor.
|
|
27
|
-
*/
|
|
28
|
-
export class BlockNoteTipTapEditor extends TiptapEditor {
|
|
29
|
-
private _state: EditorState;
|
|
30
|
-
|
|
31
|
-
public static create = (
|
|
32
|
-
options: BlockNoteTipTapEditorOptions,
|
|
33
|
-
styleSchema: StyleSchema,
|
|
34
|
-
) => {
|
|
35
|
-
// because we separate the constructor from the creation of the view,
|
|
36
|
-
// we need to patch setTimeout to prevent this code from having any effect:
|
|
37
|
-
// https://github.com/ueberdosis/tiptap/blob/45bac803283446795ad1b03f43d3746fa54a68ff/packages/core/src/Editor.ts#L117
|
|
38
|
-
const oldSetTimeout = globalThis?.window?.setTimeout;
|
|
39
|
-
if (typeof globalThis?.window?.setTimeout !== "undefined") {
|
|
40
|
-
globalThis.window.setTimeout = (() => {
|
|
41
|
-
return 0;
|
|
42
|
-
}) as any;
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
return new BlockNoteTipTapEditor(options, styleSchema);
|
|
46
|
-
} finally {
|
|
47
|
-
if (oldSetTimeout) {
|
|
48
|
-
globalThis.window.setTimeout = oldSetTimeout;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
protected constructor(
|
|
54
|
-
options: BlockNoteTipTapEditorOptions,
|
|
55
|
-
styleSchema: StyleSchema,
|
|
56
|
-
) {
|
|
57
|
-
// possible fix for next.js server side rendering
|
|
58
|
-
// const d = globalThis.document;
|
|
59
|
-
// const w = globalThis.window;
|
|
60
|
-
// if (!globalThis.document) {
|
|
61
|
-
// globalThis.document = {
|
|
62
|
-
// createElement: () => {},
|
|
63
|
-
// };
|
|
64
|
-
// }
|
|
65
|
-
|
|
66
|
-
// options.injectCSS = false
|
|
67
|
-
|
|
68
|
-
super({ ...options, content: undefined });
|
|
69
|
-
// try {
|
|
70
|
-
// globalThis.window = w;
|
|
71
|
-
// } catch(e) {}
|
|
72
|
-
// try {
|
|
73
|
-
// globalThis.document = d;
|
|
74
|
-
// } catch(e) {}
|
|
75
|
-
|
|
76
|
-
// This is a hack to make "initial content detection" by y-prosemirror (and also tiptap isEmpty)
|
|
77
|
-
// properly detect whether or not the document has changed.
|
|
78
|
-
// We change the doc.createAndFill function to make sure the initial block id is set, instead of null
|
|
79
|
-
const schema = this.schema;
|
|
80
|
-
let cache: any;
|
|
81
|
-
const oldCreateAndFill = schema.nodes.doc.createAndFill;
|
|
82
|
-
(schema.nodes.doc as any).createAndFill = (...args: any) => {
|
|
83
|
-
if (cache) {
|
|
84
|
-
return cache;
|
|
85
|
-
}
|
|
86
|
-
const ret = oldCreateAndFill.apply(schema.nodes.doc, args);
|
|
87
|
-
|
|
88
|
-
// create a copy that we can mutate (otherwise, assigning attrs is not safe and corrupts the pm state)
|
|
89
|
-
const jsonNode = JSON.parse(JSON.stringify(ret!.toJSON()));
|
|
90
|
-
jsonNode.content[0].content[0].attrs.id = "initialBlockId";
|
|
91
|
-
|
|
92
|
-
cache = Node.fromJSON(schema, jsonNode);
|
|
93
|
-
return cache;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
let doc: Node;
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
const pmNodes = options?.content.map((b) =>
|
|
100
|
-
blockToNode(b, this.schema, styleSchema).toJSON(),
|
|
101
|
-
);
|
|
102
|
-
doc = createDocument(
|
|
103
|
-
{
|
|
104
|
-
type: "doc",
|
|
105
|
-
content: [
|
|
106
|
-
{
|
|
107
|
-
type: "blockGroup",
|
|
108
|
-
content: pmNodes,
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
},
|
|
112
|
-
this.schema,
|
|
113
|
-
this.options.parseOptions,
|
|
114
|
-
);
|
|
115
|
-
} catch (e) {
|
|
116
|
-
// eslint-disable-next-line no-console
|
|
117
|
-
console.error(
|
|
118
|
-
"Error creating document from blocks passed as `initialContent`. Caused by exception: ",
|
|
119
|
-
e,
|
|
120
|
-
);
|
|
121
|
-
throw new Error(
|
|
122
|
-
"Error creating document from blocks passed as `initialContent`:\n" +
|
|
123
|
-
+JSON.stringify(options.content),
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Create state immediately, so that it's available independently from the View,
|
|
128
|
-
// the way Prosemirror "intends it to be". This also makes sure that we can access
|
|
129
|
-
// the state before the view is created / mounted.
|
|
130
|
-
this._state = EditorState.create({
|
|
131
|
-
doc,
|
|
132
|
-
schema: this.schema,
|
|
133
|
-
// selection: selection || undefined,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
get state() {
|
|
138
|
-
if (this.view) {
|
|
139
|
-
this._state = this.view.state;
|
|
140
|
-
}
|
|
141
|
-
return this._state;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
dispatch(transaction: Transaction) {
|
|
145
|
-
if (!this.view) {
|
|
146
|
-
// before view has been initialized
|
|
147
|
-
this._state = this.state.apply(transaction);
|
|
148
|
-
this.emit("transaction", {
|
|
149
|
-
editor: this,
|
|
150
|
-
transaction,
|
|
151
|
-
});
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
// This is a verbatim copy of the default dispatch method, but with the following changes:
|
|
155
|
-
// - We provide the appendedTransactions to a new `v3-update` event
|
|
156
|
-
// In the future, we can remove this dispatch method entirely and rely on the new `update` event signature which does what we want by providing the appendedTransactions
|
|
157
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
158
|
-
// if the editor / the view of the editor was destroyed
|
|
159
|
-
// the transaction should not be dispatched as there is no view anymore.
|
|
160
|
-
if (this.view.isDestroyed) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (this.isCapturingTransaction) {
|
|
165
|
-
// Do the default capture behavior
|
|
166
|
-
(this as any).dispatchTransaction(transaction);
|
|
167
|
-
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const { state, transactions: appendedTransactions } =
|
|
172
|
-
this.state.applyTransaction(transaction);
|
|
173
|
-
const selectionHasChanged = !this.state.selection.eq(state.selection);
|
|
174
|
-
|
|
175
|
-
this.emit("beforeTransaction", {
|
|
176
|
-
editor: this,
|
|
177
|
-
transaction,
|
|
178
|
-
nextState: state,
|
|
179
|
-
});
|
|
180
|
-
this.view.updateState(state);
|
|
181
|
-
this.emit("transaction", {
|
|
182
|
-
editor: this,
|
|
183
|
-
transaction,
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
if (selectionHasChanged) {
|
|
187
|
-
this.emit("selectionUpdate", {
|
|
188
|
-
editor: this,
|
|
189
|
-
transaction,
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const focus = transaction.getMeta("focus");
|
|
194
|
-
const blur = transaction.getMeta("blur");
|
|
195
|
-
|
|
196
|
-
if (focus) {
|
|
197
|
-
this.emit("focus", {
|
|
198
|
-
editor: this,
|
|
199
|
-
event: focus.event,
|
|
200
|
-
transaction,
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (blur) {
|
|
205
|
-
this.emit("blur", {
|
|
206
|
-
editor: this,
|
|
207
|
-
event: blur.event,
|
|
208
|
-
transaction,
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (!transaction.docChanged || transaction.getMeta("preventUpdate")) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
this.emit("update", {
|
|
217
|
-
editor: this,
|
|
218
|
-
transaction,
|
|
219
|
-
});
|
|
220
|
-
this.emit("v3-update", {
|
|
221
|
-
editor: this,
|
|
222
|
-
transaction,
|
|
223
|
-
appendedTransactions: appendedTransactions.slice(1),
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// a helper method that can enable plugins before the view has been initialized
|
|
228
|
-
// currently only used for testing
|
|
229
|
-
forceEnablePlugins() {
|
|
230
|
-
if (this.view) {
|
|
231
|
-
throw new Error(
|
|
232
|
-
"forcePluginsEnabled called after view has been initialized",
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
this._state = this.state.reconfigure({
|
|
236
|
-
plugins: this.extensionManager.plugins,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Replace the default `createView` method with a custom one - which we call on mount
|
|
242
|
-
*/
|
|
243
|
-
private createViewAlternative(
|
|
244
|
-
blockNoteEditor: BlockNoteEditor<any, any, any>,
|
|
245
|
-
contentComponent?: any,
|
|
246
|
-
) {
|
|
247
|
-
(this as any).contentComponent = contentComponent;
|
|
248
|
-
|
|
249
|
-
const markViews: any = {};
|
|
250
|
-
this.extensionManager.extensions.forEach((extension) => {
|
|
251
|
-
if (extension.type === "mark" && extension.config.addMarkView) {
|
|
252
|
-
// Note: migrate to using `addMarkView` from tiptap as soon as this lands
|
|
253
|
-
// (currently tiptap doesn't support markviews)
|
|
254
|
-
markViews[extension.name] =
|
|
255
|
-
extension.config.addMarkView(blockNoteEditor);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
this.view = new EditorView(
|
|
260
|
-
{ mount: this.options.element as any }, // use mount option so that we reuse the existing element instead of creating a new one
|
|
261
|
-
{
|
|
262
|
-
...this.options.editorProps,
|
|
263
|
-
// @ts-ignore
|
|
264
|
-
dispatchTransaction: this.dispatch.bind(this),
|
|
265
|
-
state: this.state,
|
|
266
|
-
markViews,
|
|
267
|
-
nodeViews: this.extensionManager.nodeViews,
|
|
268
|
-
},
|
|
269
|
-
);
|
|
270
|
-
|
|
271
|
-
// `editor.view` is not yet available at this time.
|
|
272
|
-
// Therefore we will add all plugins directly afterwards.
|
|
273
|
-
//
|
|
274
|
-
// To research: this is the default tiptap behavior, but might actually not be necessary
|
|
275
|
-
// it feels like it's a workaround for plugins that don't account for the view not being available yet
|
|
276
|
-
const newState = this.state.reconfigure({
|
|
277
|
-
plugins: this.extensionManager.plugins,
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
this.view.updateState(newState);
|
|
281
|
-
|
|
282
|
-
// emit the created event, call here manually because we blocked the default call in the constructor
|
|
283
|
-
// (https://github.com/ueberdosis/tiptap/blob/45bac803283446795ad1b03f43d3746fa54a68ff/packages/core/src/Editor.ts#L117)
|
|
284
|
-
this.commands.focus(
|
|
285
|
-
this.options.autofocus ||
|
|
286
|
-
this.options.element.getAttribute("data-bn-autofocus") === "true",
|
|
287
|
-
{ scrollIntoView: false },
|
|
288
|
-
);
|
|
289
|
-
this.emit("create", { editor: this });
|
|
290
|
-
this.isInitialized = true;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Mounts / unmounts the editor to a dom element
|
|
295
|
-
*
|
|
296
|
-
* @param element DOM element to mount to, ur null / undefined to destroy
|
|
297
|
-
*/
|
|
298
|
-
public mount = (
|
|
299
|
-
blockNoteEditor: BlockNoteEditor<any, any, any>,
|
|
300
|
-
element?: HTMLElement | null,
|
|
301
|
-
contentComponent?: any,
|
|
302
|
-
) => {
|
|
303
|
-
if (!element) {
|
|
304
|
-
this.destroy();
|
|
305
|
-
this.isInitialized = false;
|
|
306
|
-
} else {
|
|
307
|
-
this.options.element = element;
|
|
308
|
-
this.createViewAlternative(blockNoteEditor, contentComponent);
|
|
309
|
-
}
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
(BlockNoteTipTapEditor.prototype as any).createView = function () {
|
|
314
|
-
// no-op
|
|
315
|
-
// Disable default call to `createView` in the Editor constructor.
|
|
316
|
-
// We should call `createView` manually only when a DOM element is available
|
|
317
|
-
|
|
318
|
-
// additional fix because onPaste and onDrop depend on installing plugins in constructor which we don't support
|
|
319
|
-
// (note: can probably be removed after tiptap upgrade fixed in 2.8.0)
|
|
320
|
-
this.options.onPaste = this.options.onDrop = undefined;
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
declare module "@tiptap/core" {
|
|
324
|
-
interface EditorEvents {
|
|
325
|
-
/**
|
|
326
|
-
* This is a custom event that will be emitted in Tiptap V3.
|
|
327
|
-
* We use it to provide the appendedTransactions, until Tiptap V3 is released.
|
|
328
|
-
*/
|
|
329
|
-
"v3-update": {
|
|
330
|
-
editor: Editor;
|
|
331
|
-
transaction: Transaction;
|
|
332
|
-
appendedTransactions: Transaction[];
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// some dependencies only export as ESM modules. This makes them incompatible with Node CJS.
|
|
2
|
-
// To work around this, we load these dependencies as dynamic imports in a function that initializes them.
|
|
3
|
-
|
|
4
|
-
// (to reproduce this issue, run ts-node on a file that users server-util)
|
|
5
|
-
export let esmDependencies:
|
|
6
|
-
| undefined
|
|
7
|
-
| {
|
|
8
|
-
rehypeParse: typeof import("rehype-parse");
|
|
9
|
-
rehypeStringify: typeof import("rehype-stringify");
|
|
10
|
-
unified: typeof import("unified");
|
|
11
|
-
hastUtilFromDom: typeof import("hast-util-from-dom");
|
|
12
|
-
rehypeRemark: typeof import("rehype-remark");
|
|
13
|
-
remarkGfm: typeof import("remark-gfm");
|
|
14
|
-
remarkStringify: typeof import("remark-stringify");
|
|
15
|
-
remarkParse: typeof import("remark-parse");
|
|
16
|
-
remarkRehype: typeof import("remark-rehype");
|
|
17
|
-
rehypeFormat: typeof import("rehype-format");
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export async function initializeESMDependencies() {
|
|
21
|
-
if (esmDependencies) {
|
|
22
|
-
return esmDependencies;
|
|
23
|
-
}
|
|
24
|
-
const vals = await Promise.all([
|
|
25
|
-
import("rehype-parse"),
|
|
26
|
-
import("rehype-stringify"),
|
|
27
|
-
import("unified"),
|
|
28
|
-
import("hast-util-from-dom"),
|
|
29
|
-
import("rehype-remark"),
|
|
30
|
-
import("remark-gfm"),
|
|
31
|
-
import("remark-stringify"),
|
|
32
|
-
import("remark-parse"),
|
|
33
|
-
import("remark-rehype"),
|
|
34
|
-
import("rehype-format"),
|
|
35
|
-
]);
|
|
36
|
-
|
|
37
|
-
esmDependencies = {
|
|
38
|
-
rehypeParse: vals[0],
|
|
39
|
-
rehypeStringify: vals[1],
|
|
40
|
-
unified: vals[2],
|
|
41
|
-
hastUtilFromDom: vals[3],
|
|
42
|
-
rehypeRemark: vals[4],
|
|
43
|
-
remarkGfm: vals[5],
|
|
44
|
-
remarkStringify: vals[6],
|
|
45
|
-
remarkParse: vals[7],
|
|
46
|
-
remarkRehype: vals[8],
|
|
47
|
-
rehypeFormat: vals[9],
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
return esmDependencies;
|
|
51
|
-
}
|