@blocknote/core 0.21.0 → 0.23.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 +2320 -1692
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +7 -7
- package/dist/blocknote.umd.cjs.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/clipboard/__snapshots__/external/pasteEndOfParagraph.html +96 -0
- package/src/api/clipboard/__snapshots__/external/pasteEndOfParagraphText.html +96 -0
- package/src/api/clipboard/__snapshots__/external/pasteImage.html +111 -0
- package/src/api/clipboard/__snapshots__/external/pasteParagraphInCustomBlock.html +96 -0
- package/src/api/clipboard/__snapshots__/external/pasteTable.html +149 -0
- package/src/api/clipboard/__snapshots__/external/pasteTableInExistingTable.html +124 -0
- package/src/api/clipboard/__snapshots__/internal/basicBlocks.html +1 -0
- package/src/api/clipboard/__snapshots__/internal/basicBlocksWithProps.html +1 -0
- package/src/api/clipboard/__snapshots__/internal/paragraphInCustomBlock.html +1 -0
- package/src/api/clipboard/clipboardExternal.test.ts +161 -0
- package/src/api/clipboard/{clipboard.test.ts → clipboardInternal.test.ts} +186 -38
- package/src/api/clipboard/testUtil.ts +27 -0
- package/src/api/clipboard/toClipboard/copyExtension.ts +1 -0
- package/src/api/exporters/html/__snapshots__/pageBreak/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/pageBreak/basic/internal.html +1 -0
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +7 -1
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +3 -1
- package/src/api/exporters/markdown/__snapshots__/pageBreak/basic/markdown.md +0 -0
- package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +16 -0
- package/src/api/nodeConversions/nodeToBlock.ts +4 -1
- package/src/api/parsers/html/__snapshots__/parse-codeblocks.json +62 -0
- package/src/api/parsers/html/parseHTML.test.ts +9 -0
- package/src/api/parsers/markdown/__snapshots__/pasted/styled.json +2 -2
- package/src/api/testUtil/cases/defaultSchema.ts +15 -1
- package/src/api/testUtil/partialBlockTestUtil.ts +4 -1
- package/src/blocks/CodeBlockContent/CodeBlockContent.ts +32 -11
- package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +3 -28
- package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +1 -1
- package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +4 -16
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +11 -3
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +26 -6
- package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +49 -0
- package/src/blocks/PageBreakBlockContent/getPageBreakSlashMenuItems.ts +45 -0
- package/src/blocks/PageBreakBlockContent/schema.ts +40 -0
- package/src/editor/Block.css +18 -4
- package/src/editor/BlockNoteEditor.test.ts +21 -1
- package/src/editor/BlockNoteEditor.ts +17 -0
- package/src/editor/BlockNoteExtensions.ts +111 -16
- package/src/editor/editor.css +28 -13
- package/src/editor/transformPasted.ts +57 -4
- package/src/extensions/SideMenu/SideMenuPlugin.ts +115 -23
- package/src/extensions/SideMenu/dragging.ts +0 -1
- package/src/extensions/SuggestionMenu/DefaultSuggestionItem.ts +1 -1
- package/src/i18n/locales/ar.ts +6 -0
- package/src/i18n/locales/de.ts +6 -0
- package/src/i18n/locales/en.ts +6 -0
- package/src/i18n/locales/es.ts +6 -0
- package/src/i18n/locales/fr.ts +47 -17
- package/src/i18n/locales/hr.ts +72 -54
- package/src/i18n/locales/index.ts +1 -0
- package/src/i18n/locales/is.ts +6 -0
- package/src/i18n/locales/it.ts +315 -0
- package/src/i18n/locales/ja.ts +6 -0
- package/src/i18n/locales/ko.ts +6 -0
- package/src/i18n/locales/nl.ts +6 -0
- package/src/i18n/locales/pl.ts +6 -0
- package/src/i18n/locales/pt.ts +6 -0
- package/src/i18n/locales/ru.ts +6 -0
- package/src/i18n/locales/vi.ts +6 -0
- package/src/i18n/locales/zh.ts +6 -0
- package/src/index.ts +3 -0
- package/src/schema/blocks/createSpec.ts +1 -1
- package/src/schema/blocks/internal.ts +16 -6
- package/src/schema/inlineContent/internal.ts +4 -1
- package/src/schema/propTypes.ts +41 -18
- package/types/src/api/blockManipulation/setupTestEnv.d.ts +8 -0
- package/types/src/api/clipboard/clipboardInternal.test.d.ts +1 -0
- package/types/src/api/clipboard/testUtil.d.ts +509 -0
- package/types/src/api/testUtil/cases/customBlocks.d.ts +8 -0
- package/types/src/api/testUtil/cases/customInlineContent.d.ts +8 -0
- package/types/src/api/testUtil/cases/customStyles.d.ts +8 -0
- package/types/src/api/testUtil/cases/defaultSchema.d.ts +2 -1
- package/types/src/blocks/CodeBlockContent/CodeBlockContent.d.ts +2 -0
- package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +12 -0
- package/types/src/blocks/PageBreakBlockContent/PageBreakBlockContent.d.ts +31 -0
- package/types/src/blocks/PageBreakBlockContent/getPageBreakSlashMenuItems.d.ts +8 -0
- package/types/src/blocks/PageBreakBlockContent/schema.d.ts +86 -0
- package/types/src/blocks/defaultBlocks.d.ts +16 -0
- package/types/src/editor/BlockNoteEditor.d.ts +15 -0
- package/types/src/editor/BlockNoteExtensions.d.ts +2 -0
- package/types/src/editor/transformPasted.d.ts +8 -4
- package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +25 -5
- package/types/src/extensions/SuggestionMenu/DefaultSuggestionItem.d.ts +1 -1
- package/types/src/i18n/locales/de.d.ts +6 -0
- package/types/src/i18n/locales/en.d.ts +6 -0
- package/types/src/i18n/locales/es.d.ts +6 -0
- package/types/src/i18n/locales/hr.d.ts +6 -0
- package/types/src/i18n/locales/index.d.ts +1 -0
- package/types/src/i18n/locales/it.d.ts +245 -0
- package/types/src/index.d.ts +3 -0
- package/types/src/schema/propTypes.d.ts +20 -2
- package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.js +0 -30
- package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.js.map +0 -1
- package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.js +0 -99
- package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.js.map +0 -1
- package/dist/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.js +0 -97
- package/dist/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.js.map +0 -1
- package/dist/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.js +0 -88
- package/dist/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.js.map +0 -1
- package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.js +0 -219
- package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.js.map +0 -1
- package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.js +0 -175
- package/dist/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.js.map +0 -1
- package/dist/src/api/blockManipulation/commands/nestBlock/nestBlock.js +0 -57
- package/dist/src/api/blockManipulation/commands/nestBlock/nestBlock.js.map +0 -1
- package/dist/src/api/blockManipulation/commands/removeBlocks/removeBlocks.js +0 -5
- package/dist/src/api/blockManipulation/commands/removeBlocks/removeBlocks.js.map +0 -1
- package/dist/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.js +0 -31
- package/dist/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.js.map +0 -1
- package/dist/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.js +0 -71
- package/dist/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.js.map +0 -1
- package/dist/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.js +0 -157
- package/dist/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.js.map +0 -1
- package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.js +0 -27
- package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.js.map +0 -1
- package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.test.js +0 -67
- package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.test.js.map +0 -1
- package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.js +0 -148
- package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.js.map +0 -1
- package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.test.js +0 -252
- package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.test.js.map +0 -1
- package/dist/src/api/blockManipulation/getBlock/getBlock.js +0 -56
- package/dist/src/api/blockManipulation/getBlock/getBlock.js.map +0 -1
- package/dist/src/api/blockManipulation/insertContentAt.js +0 -64
- package/dist/src/api/blockManipulation/insertContentAt.js.map +0 -1
- package/dist/src/api/blockManipulation/selections/selection.js +0 -149
- package/dist/src/api/blockManipulation/selections/selection.js.map +0 -1
- package/dist/src/api/blockManipulation/selections/selection.test.js +0 -39
- package/dist/src/api/blockManipulation/selections/selection.test.js.map +0 -1
- package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.js +0 -79
- package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.js.map +0 -1
- package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.js +0 -33
- package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.js.map +0 -1
- package/dist/src/api/blockManipulation/setupTestEnv.js +0 -172
- package/dist/src/api/blockManipulation/setupTestEnv.js.map +0 -1
- package/dist/src/api/clipboard/clipboard.test.js +0 -249
- package/dist/src/api/clipboard/clipboard.test.js.map +0 -1
- package/dist/src/api/clipboard/fromClipboard/acceptedMIMETypes.js +0 -8
- package/dist/src/api/clipboard/fromClipboard/acceptedMIMETypes.js.map +0 -1
- package/dist/src/api/clipboard/fromClipboard/fileDropExtension.js +0 -38
- package/dist/src/api/clipboard/fromClipboard/fileDropExtension.js.map +0 -1
- package/dist/src/api/clipboard/fromClipboard/handleFileInsertion.js +0 -111
- package/dist/src/api/clipboard/fromClipboard/handleFileInsertion.js.map +0 -1
- package/dist/src/api/clipboard/fromClipboard/handleVSCodePaste.js +0 -25
- package/dist/src/api/clipboard/fromClipboard/handleVSCodePaste.js.map +0 -1
- package/dist/src/api/clipboard/fromClipboard/pasteExtension.js +0 -57
- package/dist/src/api/clipboard/fromClipboard/pasteExtension.js.map +0 -1
- package/dist/src/api/clipboard/toClipboard/copyExtension.js +0 -134
- package/dist/src/api/clipboard/toClipboard/copyExtension.js.map +0 -1
- package/dist/src/api/exporters/html/externalHTMLExporter.js +0 -35
- package/dist/src/api/exporters/html/externalHTMLExporter.js.map +0 -1
- package/dist/src/api/exporters/html/htmlConversion.test.js +0 -72
- package/dist/src/api/exporters/html/htmlConversion.test.js.map +0 -1
- package/dist/src/api/exporters/html/internalHTMLSerializer.js +0 -21
- package/dist/src/api/exporters/html/internalHTMLSerializer.js.map +0 -1
- package/dist/src/api/exporters/html/util/serializeBlocksExternalHTML.js +0 -141
- package/dist/src/api/exporters/html/util/serializeBlocksExternalHTML.js.map +0 -1
- package/dist/src/api/exporters/html/util/serializeBlocksInternalHTML.js +0 -96
- package/dist/src/api/exporters/html/util/serializeBlocksInternalHTML.js.map +0 -1
- package/dist/src/api/exporters/markdown/markdownExporter.js +0 -31
- package/dist/src/api/exporters/markdown/markdownExporter.js.map +0 -1
- package/dist/src/api/exporters/markdown/markdownExporter.test.js +0 -57
- package/dist/src/api/exporters/markdown/markdownExporter.test.js.map +0 -1
- package/dist/src/api/exporters/markdown/removeUnderlinesRehypePlugin.js +0 -33
- package/dist/src/api/exporters/markdown/removeUnderlinesRehypePlugin.js.map +0 -1
- package/dist/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.js +0 -37
- package/dist/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.js.map +0 -1
- package/dist/src/api/getBlockInfoFromPos.js +0 -165
- package/dist/src/api/getBlockInfoFromPos.js.map +0 -1
- package/dist/src/api/nodeConversions/blockToNode.js +0 -197
- package/dist/src/api/nodeConversions/blockToNode.js.map +0 -1
- package/dist/src/api/nodeConversions/fragmentToBlocks.js +0 -50
- package/dist/src/api/nodeConversions/fragmentToBlocks.js.map +0 -1
- package/dist/src/api/nodeConversions/nodeConversions.test.js +0 -54
- package/dist/src/api/nodeConversions/nodeConversions.test.js.map +0 -1
- package/dist/src/api/nodeConversions/nodeToBlock.js +0 -316
- package/dist/src/api/nodeConversions/nodeToBlock.js.map +0 -1
- package/dist/src/api/nodeUtil.js +0 -28
- package/dist/src/api/nodeUtil.js.map +0 -1
- package/dist/src/api/parsers/html/parseHTML.js +0 -19
- package/dist/src/api/parsers/html/parseHTML.js.map +0 -1
- package/dist/src/api/parsers/html/parseHTML.test.js +0 -470
- package/dist/src/api/parsers/html/parseHTML.test.js.map +0 -1
- package/dist/src/api/parsers/html/util/nestedLists.js +0 -106
- package/dist/src/api/parsers/html/util/nestedLists.js.map +0 -1
- package/dist/src/api/parsers/html/util/nestedLists.test.js +0 -166
- package/dist/src/api/parsers/html/util/nestedLists.test.js.map +0 -1
- package/dist/src/api/parsers/markdown/parseMarkdown.js +0 -52
- package/dist/src/api/parsers/markdown/parseMarkdown.js.map +0 -1
- package/dist/src/api/parsers/markdown/parseMarkdown.test.js +0 -112
- package/dist/src/api/parsers/markdown/parseMarkdown.test.js.map +0 -1
- package/dist/src/api/testUtil/cases/customBlocks.js +0 -313
- package/dist/src/api/testUtil/cases/customBlocks.js.map +0 -1
- package/dist/src/api/testUtil/cases/customInlineContent.js +0 -91
- package/dist/src/api/testUtil/cases/customInlineContent.js.map +0 -1
- package/dist/src/api/testUtil/cases/customStyles.js +0 -83
- package/dist/src/api/testUtil/cases/customStyles.js.map +0 -1
- package/dist/src/api/testUtil/cases/defaultSchema.js +0 -673
- package/dist/src/api/testUtil/cases/defaultSchema.js.map +0 -1
- package/dist/src/api/testUtil/index.js +0 -2
- package/dist/src/api/testUtil/index.js.map +0 -1
- package/dist/src/api/testUtil/partialBlockTestUtil.js +0 -114
- package/dist/src/api/testUtil/partialBlockTestUtil.js.map +0 -1
- package/dist/src/api/testUtil/paste.js +0 -29
- package/dist/src/api/testUtil/paste.js.map +0 -1
- package/dist/src/blocks/AudioBlockContent/AudioBlockContent.js +0 -104
- package/dist/src/blocks/AudioBlockContent/AudioBlockContent.js.map +0 -1
- package/dist/src/blocks/AudioBlockContent/parseAudioElement.js +0 -5
- package/dist/src/blocks/AudioBlockContent/parseAudioElement.js.map +0 -1
- package/dist/src/blocks/CodeBlockContent/CodeBlockContent.js +0 -281
- package/dist/src/blocks/CodeBlockContent/CodeBlockContent.js.map +0 -1
- package/dist/src/blocks/CodeBlockContent/defaultSupportedLanguages.js +0 -110
- package/dist/src/blocks/CodeBlockContent/defaultSupportedLanguages.js.map +0 -1
- package/dist/src/blocks/FileBlockContent/FileBlockContent.js +0 -71
- package/dist/src/blocks/FileBlockContent/FileBlockContent.js.map +0 -1
- package/dist/src/blocks/FileBlockContent/helpers/parse/parseEmbedElement.js +0 -5
- package/dist/src/blocks/FileBlockContent/helpers/parse/parseEmbedElement.js.map +0 -1
- package/dist/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.js +0 -10
- package/dist/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.js.map +0 -1
- package/dist/src/blocks/FileBlockContent/helpers/render/createAddFileButton.js +0 -39
- package/dist/src/blocks/FileBlockContent/helpers/render/createAddFileButton.js.map +0 -1
- package/dist/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.js +0 -51
- package/dist/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.js.map +0 -1
- package/dist/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.js +0 -17
- package/dist/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.js.map +0 -1
- package/dist/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.js +0 -147
- package/dist/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.js.map +0 -1
- package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.js +0 -9
- package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.js.map +0 -1
- package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js +0 -11
- package/dist/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js.map +0 -1
- package/dist/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.js +0 -15
- package/dist/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.js.map +0 -1
- package/dist/src/blocks/HeadingBlockContent/HeadingBlockContent.js +0 -145
- package/dist/src/blocks/HeadingBlockContent/HeadingBlockContent.js.map +0 -1
- package/dist/src/blocks/ImageBlockContent/ImageBlockContent.js +0 -114
- package/dist/src/blocks/ImageBlockContent/ImageBlockContent.js.map +0 -1
- package/dist/src/blocks/ImageBlockContent/parseImageElement.js +0 -6
- package/dist/src/blocks/ImageBlockContent/parseImageElement.js.map +0 -1
- package/dist/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.js +0 -113
- package/dist/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.js.map +0 -1
- package/dist/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.js +0 -224
- package/dist/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.js.map +0 -1
- package/dist/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.js +0 -45
- package/dist/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.js.map +0 -1
- package/dist/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.js +0 -58
- package/dist/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.js.map +0 -1
- package/dist/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.js +0 -130
- package/dist/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.js.map +0 -1
- package/dist/src/blocks/ParagraphBlockContent/ParagraphBlockContent.js +0 -52
- package/dist/src/blocks/ParagraphBlockContent/ParagraphBlockContent.js.map +0 -1
- package/dist/src/blocks/TableBlockContent/TableBlockContent.js +0 -129
- package/dist/src/blocks/TableBlockContent/TableBlockContent.js.map +0 -1
- package/dist/src/blocks/TableBlockContent/TableExtension.js +0 -64
- package/dist/src/blocks/TableBlockContent/TableExtension.js.map +0 -1
- package/dist/src/blocks/VideoBlockContent/VideoBlockContent.js +0 -114
- package/dist/src/blocks/VideoBlockContent/VideoBlockContent.js.map +0 -1
- package/dist/src/blocks/VideoBlockContent/parseVideoElement.js +0 -6
- package/dist/src/blocks/VideoBlockContent/parseVideoElement.js.map +0 -1
- package/dist/src/blocks/defaultBlockHelpers.js +0 -50
- package/dist/src/blocks/defaultBlockHelpers.js.map +0 -1
- package/dist/src/blocks/defaultBlockTypeGuards.js +0 -40
- package/dist/src/blocks/defaultBlockTypeGuards.js.map +0 -1
- package/dist/src/blocks/defaultBlocks.js +0 -50
- package/dist/src/blocks/defaultBlocks.js.map +0 -1
- package/dist/src/blocks/defaultProps.js +0 -19
- package/dist/src/blocks/defaultProps.js.map +0 -1
- package/dist/src/editor/BlockNoteEditor.js +0 -751
- package/dist/src/editor/BlockNoteEditor.js.map +0 -1
- package/dist/src/editor/BlockNoteEditor.test.js +0 -65
- package/dist/src/editor/BlockNoteEditor.test.js.map +0 -1
- package/dist/src/editor/BlockNoteExtensions.js +0 -192
- package/dist/src/editor/BlockNoteExtensions.js.map +0 -1
- package/dist/src/editor/BlockNoteSchema.js +0 -38
- package/dist/src/editor/BlockNoteSchema.js.map +0 -1
- package/dist/src/editor/BlockNoteTipTapEditor.js +0 -169
- package/dist/src/editor/BlockNoteTipTapEditor.js.map +0 -1
- package/dist/src/editor/cursorPositionTypes.js +0 -2
- package/dist/src/editor/cursorPositionTypes.js.map +0 -1
- package/dist/src/editor/defaultColors.js +0 -77
- package/dist/src/editor/defaultColors.js.map +0 -1
- package/dist/src/editor/selectionTypes.js +0 -2
- package/dist/src/editor/selectionTypes.js.map +0 -1
- package/dist/src/editor/transformPasted.js +0 -79
- package/dist/src/editor/transformPasted.js.map +0 -1
- package/dist/src/exporter/Exporter.js +0 -36
- package/dist/src/exporter/Exporter.js.map +0 -1
- package/dist/src/exporter/index.js +0 -3
- package/dist/src/exporter/index.js.map +0 -1
- package/dist/src/exporter/mapping.js +0 -12
- package/dist/src/exporter/mapping.js.map +0 -1
- package/dist/src/extensions/BackgroundColor/BackgroundColorExtension.js +0 -30
- package/dist/src/extensions/BackgroundColor/BackgroundColorExtension.js.map +0 -1
- package/dist/src/extensions/BackgroundColor/BackgroundColorMark.js +0 -39
- package/dist/src/extensions/BackgroundColor/BackgroundColorMark.js.map +0 -1
- package/dist/src/extensions/FilePanel/FilePanelPlugin.js +0 -131
- package/dist/src/extensions/FilePanel/FilePanelPlugin.js.map +0 -1
- package/dist/src/extensions/FormattingToolbar/FormattingToolbarPlugin.js +0 -197
- package/dist/src/extensions/FormattingToolbar/FormattingToolbarPlugin.js.map +0 -1
- package/dist/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js +0 -341
- package/dist/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js.map +0 -1
- package/dist/src/extensions/LinkToolbar/LinkToolbarPlugin.js +0 -251
- package/dist/src/extensions/LinkToolbar/LinkToolbarPlugin.js.map +0 -1
- package/dist/src/extensions/LinkToolbar/protocols.js +0 -14
- package/dist/src/extensions/LinkToolbar/protocols.js.map +0 -1
- package/dist/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.js +0 -54
- package/dist/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.js.map +0 -1
- package/dist/src/extensions/Placeholder/PlaceholderPlugin.js +0 -90
- package/dist/src/extensions/Placeholder/PlaceholderPlugin.js.map +0 -1
- package/dist/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.js +0 -187
- package/dist/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.js.map +0 -1
- package/dist/src/extensions/SideMenu/MultipleNodeSelection.js +0 -68
- package/dist/src/extensions/SideMenu/MultipleNodeSelection.js.map +0 -1
- package/dist/src/extensions/SideMenu/SideMenuPlugin.js +0 -347
- package/dist/src/extensions/SideMenu/SideMenuPlugin.js.map +0 -1
- package/dist/src/extensions/SideMenu/dragging.js +0 -135
- package/dist/src/extensions/SideMenu/dragging.js.map +0 -1
- package/dist/src/extensions/SuggestionMenu/DefaultGridSuggestionItem.js +0 -2
- package/dist/src/extensions/SuggestionMenu/DefaultGridSuggestionItem.js.map +0 -1
- package/dist/src/extensions/SuggestionMenu/DefaultSuggestionItem.js +0 -2
- package/dist/src/extensions/SuggestionMenu/DefaultSuggestionItem.js.map +0 -1
- package/dist/src/extensions/SuggestionMenu/SuggestionPlugin.js +0 -245
- package/dist/src/extensions/SuggestionMenu/SuggestionPlugin.js.map +0 -1
- package/dist/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.js +0 -26
- package/dist/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.js.map +0 -1
- package/dist/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.js +0 -241
- package/dist/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.js.map +0 -1
- package/dist/src/extensions/TableHandles/TableHandlesPlugin.js +0 -579
- package/dist/src/extensions/TableHandles/TableHandlesPlugin.js.map +0 -1
- package/dist/src/extensions/TextAlignment/TextAlignmentExtension.js +0 -36
- package/dist/src/extensions/TextAlignment/TextAlignmentExtension.js.map +0 -1
- package/dist/src/extensions/TextColor/TextColorExtension.js +0 -29
- package/dist/src/extensions/TextColor/TextColorExtension.js.map +0 -1
- package/dist/src/extensions/TextColor/TextColorMark.js +0 -37
- package/dist/src/extensions/TextColor/TextColorMark.js.map +0 -1
- package/dist/src/extensions/TrailingNode/TrailingNodeExtension.js +0 -58
- package/dist/src/extensions/TrailingNode/TrailingNodeExtension.js.map +0 -1
- package/dist/src/extensions/UniqueID/UniqueID.js +0 -283
- package/dist/src/extensions/UniqueID/UniqueID.js.map +0 -1
- package/dist/src/extensions/getDraggableBlockFromElement.js +0 -13
- package/dist/src/extensions/getDraggableBlockFromElement.js.map +0 -1
- package/dist/src/extensions-shared/UiElementPosition.js +0 -2
- package/dist/src/extensions-shared/UiElementPosition.js.map +0 -1
- package/dist/src/i18n/dictionary.js +0 -4
- package/dist/src/i18n/dictionary.js.map +0 -1
- package/dist/src/i18n/locales/ar.js +0 -298
- package/dist/src/i18n/locales/ar.js.map +0 -1
- package/dist/src/i18n/locales/de.js +0 -313
- package/dist/src/i18n/locales/de.js.map +0 -1
- package/dist/src/i18n/locales/en.js +0 -314
- package/dist/src/i18n/locales/en.js.map +0 -1
- package/dist/src/i18n/locales/es.js +0 -312
- package/dist/src/i18n/locales/es.js.map +0 -1
- package/dist/src/i18n/locales/fr.js +0 -313
- package/dist/src/i18n/locales/fr.js.map +0 -1
- package/dist/src/i18n/locales/hr.js +0 -308
- package/dist/src/i18n/locales/hr.js.map +0 -1
- package/dist/src/i18n/locales/index.js +0 -16
- package/dist/src/i18n/locales/index.js.map +0 -1
- package/dist/src/i18n/locales/is.js +0 -305
- package/dist/src/i18n/locales/is.js.map +0 -1
- package/dist/src/i18n/locales/ja.js +0 -333
- package/dist/src/i18n/locales/ja.js.map +0 -1
- package/dist/src/i18n/locales/ko.js +0 -326
- package/dist/src/i18n/locales/ko.js.map +0 -1
- package/dist/src/i18n/locales/nl.js +0 -313
- package/dist/src/i18n/locales/nl.js.map +0 -1
- package/dist/src/i18n/locales/pl.js +0 -297
- package/dist/src/i18n/locales/pl.js.map +0 -1
- package/dist/src/i18n/locales/pt.js +0 -305
- package/dist/src/i18n/locales/pt.js.map +0 -1
- package/dist/src/i18n/locales/ru.js +0 -340
- package/dist/src/i18n/locales/ru.js.map +0 -1
- package/dist/src/i18n/locales/vi.js +0 -312
- package/dist/src/i18n/locales/vi.js.map +0 -1
- package/dist/src/i18n/locales/zh.js +0 -346
- package/dist/src/i18n/locales/zh.js.map +0 -1
- package/dist/src/index.js +0 -63
- package/dist/src/index.js.map +0 -1
- package/dist/src/pm-nodes/BlockContainer.js +0 -72
- package/dist/src/pm-nodes/BlockContainer.js.map +0 -1
- package/dist/src/pm-nodes/BlockGroup.js +0 -43
- package/dist/src/pm-nodes/BlockGroup.js.map +0 -1
- package/dist/src/pm-nodes/Doc.js +0 -7
- package/dist/src/pm-nodes/Doc.js.map +0 -1
- package/dist/src/pm-nodes/index.js +0 -4
- package/dist/src/pm-nodes/index.js.map +0 -1
- package/dist/src/schema/blocks/createSpec.js +0 -126
- package/dist/src/schema/blocks/createSpec.js.map +0 -1
- package/dist/src/schema/blocks/internal.js +0 -147
- package/dist/src/schema/blocks/internal.js.map +0 -1
- package/dist/src/schema/blocks/types.js +0 -2
- package/dist/src/schema/blocks/types.js.map +0 -1
- package/dist/src/schema/index.js +0 -11
- package/dist/src/schema/index.js.map +0 -1
- package/dist/src/schema/inlineContent/createSpec.js +0 -64
- package/dist/src/schema/inlineContent/createSpec.js.map +0 -1
- package/dist/src/schema/inlineContent/internal.js +0 -52
- package/dist/src/schema/inlineContent/internal.js.map +0 -1
- package/dist/src/schema/inlineContent/types.js +0 -10
- package/dist/src/schema/inlineContent/types.js.map +0 -1
- package/dist/src/schema/propTypes.js +0 -2
- package/dist/src/schema/propTypes.js.map +0 -1
- package/dist/src/schema/styles/createSpec.js +0 -48
- package/dist/src/schema/styles/createSpec.js.map +0 -1
- package/dist/src/schema/styles/internal.js +0 -53
- package/dist/src/schema/styles/internal.js.map +0 -1
- package/dist/src/schema/styles/types.js +0 -2
- package/dist/src/schema/styles/types.js.map +0 -1
- package/dist/src/util/EventEmitter.js +0 -33
- package/dist/src/util/EventEmitter.js.map +0 -1
- package/dist/src/util/browser.js +0 -17
- package/dist/src/util/browser.js.map +0 -1
- package/dist/src/util/combineByGroup.js +0 -20
- package/dist/src/util/combineByGroup.js.map +0 -1
- package/dist/src/util/esmDependencies.js +0 -35
- package/dist/src/util/esmDependencies.js.map +0 -1
- package/dist/src/util/string.js +0 -14
- package/dist/src/util/string.js.map +0 -1
- package/dist/src/util/typescript.js +0 -12
- package/dist/src/util/typescript.js.map +0 -1
- /package/src/api/clipboard/__snapshots__/{childToParent.html → internal/childToParent.html} +0 -0
- /package/src/api/clipboard/__snapshots__/{childrenToNextParent.html → internal/childrenToNextParent.html} +0 -0
- /package/src/api/clipboard/__snapshots__/{childrenToNextParentsChildren.html → internal/childrenToNextParentsChildren.html} +0 -0
- /package/src/api/clipboard/__snapshots__/{image.html → internal/image.html} +0 -0
- /package/src/api/clipboard/__snapshots__/{multipleChildren.html → internal/multipleChildren.html} +0 -0
- /package/src/api/clipboard/__snapshots__/{multipleStyledText.html → internal/multipleStyledText.html} +0 -0
- /package/src/api/clipboard/__snapshots__/{nestedImage.html → internal/nestedImage.html} +0 -0
- /package/src/api/clipboard/__snapshots__/{partialChildToParent.html → internal/partialChildToParent.html} +0 -0
- /package/src/api/clipboard/__snapshots__/{styledText.html → internal/styledText.html} +0 -0
- /package/src/api/clipboard/__snapshots__/{tableAllCells.html → internal/tableAllCells.html} +0 -0
- /package/src/api/clipboard/__snapshots__/{tableCell.html → internal/tableCell.html} +0 -0
- /package/src/api/clipboard/__snapshots__/{tableCellText.html → internal/tableCellText.html} +0 -0
- /package/src/api/clipboard/__snapshots__/{tableRow.html → internal/tableRow.html} +0 -0
- /package/src/api/clipboard/__snapshots__/{unstyledText.html → internal/unstyledText.html} +0 -0
- /package/types/src/api/clipboard/{clipboard.test.d.ts → clipboardExternal.test.d.ts} +0 -0
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { Fragment } from "prosemirror-model";
|
|
2
|
-
import { UnreachableCaseError } from "../../../../util/typescript.js";
|
|
3
|
-
import { inlineContentToNodes, tableContentToNodes, } from "../../../nodeConversions/blockToNode.js";
|
|
4
|
-
function addAttributesAndRemoveClasses(element) {
|
|
5
|
-
// Removes all BlockNote specific class names.
|
|
6
|
-
const className = [...element.classList].filter((className) => !className.startsWith("bn-")) || [];
|
|
7
|
-
if (className.length > 0) {
|
|
8
|
-
element.className = className.join(" ");
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
element.removeAttribute("class");
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export function serializeInlineContentExternalHTML(editor, blockContent, serializer, options) {
|
|
15
|
-
let nodes;
|
|
16
|
-
// TODO: reuse function from nodeconversions?
|
|
17
|
-
if (!blockContent) {
|
|
18
|
-
throw new Error("blockContent is required");
|
|
19
|
-
}
|
|
20
|
-
else if (typeof blockContent === "string") {
|
|
21
|
-
nodes = inlineContentToNodes([blockContent], editor.pmSchema, editor.schema.styleSchema);
|
|
22
|
-
}
|
|
23
|
-
else if (Array.isArray(blockContent)) {
|
|
24
|
-
nodes = inlineContentToNodes(blockContent, editor.pmSchema, editor.schema.styleSchema);
|
|
25
|
-
}
|
|
26
|
-
else if (blockContent.type === "tableContent") {
|
|
27
|
-
nodes = tableContentToNodes(blockContent, editor.pmSchema, editor.schema.styleSchema);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
throw new UnreachableCaseError(blockContent.type);
|
|
31
|
-
}
|
|
32
|
-
// We call the prosemirror serializer here because it handles Marks and Inline Content nodes nicely.
|
|
33
|
-
// If we'd want to support custom serialization or externalHTML for Inline Content, we'd have to implement
|
|
34
|
-
// a custom serializer here.
|
|
35
|
-
const dom = serializer.serializeFragment(Fragment.from(nodes), options);
|
|
36
|
-
if (dom.nodeType === 1 /* Node.ELEMENT_NODE */) {
|
|
37
|
-
addAttributesAndRemoveClasses(dom);
|
|
38
|
-
}
|
|
39
|
-
return dom;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* TODO: there's still quite some logic that handles getting and filtering properties,
|
|
43
|
-
* we should make sure the `toExternalHTML` methods of default blocks actually handle this,
|
|
44
|
-
* instead of the serializer.
|
|
45
|
-
*/
|
|
46
|
-
function serializeBlock(fragment, editor, block, serializer, orderedListItemBlockTypes, unorderedListItemBlockTypes, options) {
|
|
47
|
-
const doc = options?.document ?? document;
|
|
48
|
-
const BC_NODE = editor.pmSchema.nodes["blockContainer"];
|
|
49
|
-
let props = block.props;
|
|
50
|
-
// set default props in case we were passed a partial block
|
|
51
|
-
if (!block.props) {
|
|
52
|
-
props = {};
|
|
53
|
-
for (const [name, spec] of Object.entries(editor.schema.blockSchema[block.type].propSchema)) {
|
|
54
|
-
props[name] = spec.default;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const bc = BC_NODE.spec?.toDOM?.(BC_NODE.create({
|
|
58
|
-
id: block.id,
|
|
59
|
-
...props,
|
|
60
|
-
}));
|
|
61
|
-
// the container node is just used as a workaround to get some block-level attributes.
|
|
62
|
-
// we should change toExternalHTML so that this is not necessary
|
|
63
|
-
const attrs = [...bc.dom.attributes];
|
|
64
|
-
const ret = editor.blockImplementations[block.type].implementation.toExternalHTML({ ...block, props }, editor);
|
|
65
|
-
const elementFragment = doc.createDocumentFragment();
|
|
66
|
-
if (ret.dom.classList.contains("bn-block-content")) {
|
|
67
|
-
const blockContentDataAttributes = [...attrs, ...ret.dom.attributes].filter((attr) => attr.name.startsWith("data") &&
|
|
68
|
-
attr.name !== "data-content-type" &&
|
|
69
|
-
attr.name !== "data-file-block" &&
|
|
70
|
-
attr.name !== "data-node-view-wrapper" &&
|
|
71
|
-
attr.name !== "data-node-type" &&
|
|
72
|
-
attr.name !== "data-id" &&
|
|
73
|
-
attr.name !== "data-index" &&
|
|
74
|
-
attr.name !== "data-editable");
|
|
75
|
-
// ret.dom = ret.dom.firstChild! as any;
|
|
76
|
-
for (const attr of blockContentDataAttributes) {
|
|
77
|
-
ret.dom.firstChild.setAttribute(attr.name, attr.value);
|
|
78
|
-
}
|
|
79
|
-
addAttributesAndRemoveClasses(ret.dom.firstChild);
|
|
80
|
-
elementFragment.append(...ret.dom.childNodes);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
elementFragment.append(ret.dom);
|
|
84
|
-
}
|
|
85
|
-
if (ret.contentDOM && block.content) {
|
|
86
|
-
const ic = serializeInlineContentExternalHTML(editor, block.content, // TODO
|
|
87
|
-
serializer, options);
|
|
88
|
-
ret.contentDOM.appendChild(ic);
|
|
89
|
-
}
|
|
90
|
-
let listType = undefined;
|
|
91
|
-
if (orderedListItemBlockTypes.has(block.type)) {
|
|
92
|
-
listType = "OL";
|
|
93
|
-
}
|
|
94
|
-
else if (unorderedListItemBlockTypes.has(block.type)) {
|
|
95
|
-
listType = "UL";
|
|
96
|
-
}
|
|
97
|
-
if (listType) {
|
|
98
|
-
if (fragment.lastChild?.nodeName !== listType) {
|
|
99
|
-
const list = doc.createElement(listType);
|
|
100
|
-
fragment.append(list);
|
|
101
|
-
}
|
|
102
|
-
const li = doc.createElement("li");
|
|
103
|
-
li.append(elementFragment);
|
|
104
|
-
fragment.lastChild.appendChild(li);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
fragment.append(elementFragment);
|
|
108
|
-
}
|
|
109
|
-
if (block.children && block.children.length > 0) {
|
|
110
|
-
const childFragment = doc.createDocumentFragment();
|
|
111
|
-
serializeBlocksToFragment(childFragment, editor, block.children, serializer, orderedListItemBlockTypes, unorderedListItemBlockTypes, options);
|
|
112
|
-
if (fragment.lastChild?.nodeName === "UL" ||
|
|
113
|
-
fragment.lastChild?.nodeName === "OL") {
|
|
114
|
-
// add nested lists to the last list item
|
|
115
|
-
while (childFragment.firstChild?.nodeName === "UL" ||
|
|
116
|
-
childFragment.firstChild?.nodeName === "OL") {
|
|
117
|
-
fragment.lastChild.lastChild.appendChild(childFragment.firstChild);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (editor.pmSchema.nodes[block.type].isInGroup("blockContent")) {
|
|
121
|
-
// default "blockContainer" style blocks are flattened (no "nested block" support) for externalHTML, so append the child fragment to the outer fragment
|
|
122
|
-
fragment.append(childFragment);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
// for columns / column lists, do use nesting
|
|
126
|
-
ret.contentDOM?.append(childFragment);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
const serializeBlocksToFragment = (fragment, editor, blocks, serializer, orderedListItemBlockTypes, unorderedListItemBlockTypes, options) => {
|
|
131
|
-
for (const block of blocks) {
|
|
132
|
-
serializeBlock(fragment, editor, block, serializer, orderedListItemBlockTypes, unorderedListItemBlockTypes, options);
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
export const serializeBlocksExternalHTML = (editor, blocks, serializer, orderedListItemBlockTypes, unorderedListItemBlockTypes, options) => {
|
|
136
|
-
const doc = options?.document ?? document;
|
|
137
|
-
const fragment = doc.createDocumentFragment();
|
|
138
|
-
serializeBlocksToFragment(fragment, editor, blocks, serializer, orderedListItemBlockTypes, unorderedListItemBlockTypes, options);
|
|
139
|
-
return fragment;
|
|
140
|
-
};
|
|
141
|
-
//# sourceMappingURL=serializeBlocksExternalHTML.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serializeBlocksExternalHTML.js","sourceRoot":"","sources":["../../../../../../src/api/exporters/html/util/serializeBlocksExternalHTML.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAS5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EACL,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,yCAAyC,CAAC;AAEjD,SAAS,6BAA6B,CAAC,OAAoB;IACzD,8CAA8C;IAC9C,MAAM,SAAS,GACb,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAC3B,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAC5C,I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2BAA2B,EAC3B,OAAO,CACR,CAAC;IACF,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC"}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Fragment } from "prosemirror-model";
|
|
2
|
-
import { UnreachableCaseError } from "../../../../util/typescript.js";
|
|
3
|
-
import { inlineContentToNodes, tableContentToNodes, } from "../../../nodeConversions/blockToNode.js";
|
|
4
|
-
export function serializeInlineContentInternalHTML(editor, blockContent, serializer, options) {
|
|
5
|
-
let nodes;
|
|
6
|
-
// TODO: reuse function from nodeconversions?
|
|
7
|
-
if (!blockContent) {
|
|
8
|
-
throw new Error("blockContent is required");
|
|
9
|
-
}
|
|
10
|
-
else if (typeof blockContent === "string") {
|
|
11
|
-
nodes = inlineContentToNodes([blockContent], editor.pmSchema, editor.schema.styleSchema);
|
|
12
|
-
}
|
|
13
|
-
else if (Array.isArray(blockContent)) {
|
|
14
|
-
nodes = inlineContentToNodes(blockContent, editor.pmSchema, editor.schema.styleSchema);
|
|
15
|
-
}
|
|
16
|
-
else if (blockContent.type === "tableContent") {
|
|
17
|
-
nodes = tableContentToNodes(blockContent, editor.pmSchema, editor.schema.styleSchema);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
throw new UnreachableCaseError(blockContent.type);
|
|
21
|
-
}
|
|
22
|
-
// We call the prosemirror serializer here because it handles Marks and Inline Content nodes nicely.
|
|
23
|
-
// If we'd want to support custom serialization or externalHTML for Inline Content, we'd have to implement
|
|
24
|
-
// a custom serializer here.
|
|
25
|
-
const dom = serializer.serializeFragment(Fragment.from(nodes), options);
|
|
26
|
-
return dom;
|
|
27
|
-
}
|
|
28
|
-
function serializeBlock(editor, block, serializer, listIndex, options) {
|
|
29
|
-
const BC_NODE = editor.pmSchema.nodes["blockContainer"];
|
|
30
|
-
let props = block.props;
|
|
31
|
-
// set default props in case we were passed a partial block
|
|
32
|
-
if (!block.props) {
|
|
33
|
-
props = {};
|
|
34
|
-
for (const [name, spec] of Object.entries(editor.schema.blockSchema[block.type].propSchema)) {
|
|
35
|
-
props[name] = spec.default;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const impl = editor.blockImplementations[block.type].implementation;
|
|
39
|
-
const ret = impl.toInternalHTML({ ...block, props }, editor);
|
|
40
|
-
if (block.type === "numberedListItem") {
|
|
41
|
-
// This is a workaround to make sure there's a list index set.
|
|
42
|
-
// Normally, this is set on the internal prosemirror nodes by the NumberedListIndexingPlugin,
|
|
43
|
-
// but:
|
|
44
|
-
// - (a) this information is not available on the Blocks passed to the serializer. (we only have access to BlockNote Blocks)
|
|
45
|
-
// - (b) the NumberedListIndexingPlugin might not even have run, because we can manually call blocksToFullHTML
|
|
46
|
-
// with blocks that are not part of the active document
|
|
47
|
-
ret.dom.setAttribute("data-index", listIndex.toString());
|
|
48
|
-
}
|
|
49
|
-
if (ret.contentDOM && block.content) {
|
|
50
|
-
const ic = serializeInlineContentInternalHTML(editor, block.content, // TODO
|
|
51
|
-
serializer, options);
|
|
52
|
-
ret.contentDOM.appendChild(ic);
|
|
53
|
-
}
|
|
54
|
-
const pmType = editor.pmSchema.nodes[block.type];
|
|
55
|
-
if (pmType.isInGroup("bnBlock")) {
|
|
56
|
-
if (block.children && block.children.length > 0) {
|
|
57
|
-
const fragment = serializeBlocks(editor, block.children, serializer, options);
|
|
58
|
-
ret.contentDOM?.append(fragment);
|
|
59
|
-
}
|
|
60
|
-
return ret.dom;
|
|
61
|
-
}
|
|
62
|
-
// wrap the block in a blockContainer
|
|
63
|
-
const bc = BC_NODE.spec?.toDOM?.(BC_NODE.create({
|
|
64
|
-
id: block.id,
|
|
65
|
-
...props,
|
|
66
|
-
}));
|
|
67
|
-
bc.contentDOM?.appendChild(ret.dom);
|
|
68
|
-
if (block.children && block.children.length > 0) {
|
|
69
|
-
bc.contentDOM?.appendChild(serializeBlocksInternalHTML(editor, block.children, serializer, options));
|
|
70
|
-
}
|
|
71
|
-
return bc.dom;
|
|
72
|
-
}
|
|
73
|
-
function serializeBlocks(editor, blocks, serializer, options) {
|
|
74
|
-
const doc = options?.document ?? document;
|
|
75
|
-
const fragment = doc.createDocumentFragment();
|
|
76
|
-
let listIndex = 0;
|
|
77
|
-
for (const block of blocks) {
|
|
78
|
-
if (block.type === "numberedListItem") {
|
|
79
|
-
listIndex++;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
listIndex = 0;
|
|
83
|
-
}
|
|
84
|
-
const blockDOM = serializeBlock(editor, block, serializer, listIndex, options);
|
|
85
|
-
fragment.appendChild(blockDOM);
|
|
86
|
-
}
|
|
87
|
-
return fragment;
|
|
88
|
-
}
|
|
89
|
-
export const serializeBlocksInternalHTML = (editor, blocks, serializer, options) => {
|
|
90
|
-
const BG_NODE = editor.pmSchema.nodes["blockGroup"];
|
|
91
|
-
const bg = BG_NODE.spec.toDOM(BG_NODE.create({}));
|
|
92
|
-
const fragment = serializeBlocks(editor, blocks, serializer, options);
|
|
93
|
-
bg.contentDOM?.appendChild(fragment);
|
|
94
|
-
return bg.dom;
|
|
95
|
-
};
|
|
96
|
-
//# sourceMappingURL=serializeBlocksInternalHTML.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serializeBlocksInternalHTML.js","sourceRoot":"","sources":["../../../../../../src/api/exporters/html/util/serializeBlocksInternalHTML.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAS5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EACL,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,yCAAyC,CAAC;AAEjD,MAAM,UAAU,kCAAkC,CAKhD,MAAkC,EAClC,YAAoD,EACpD,UAAyB,EACzB,OAAiC;IAEjC,IAAI,KAAU,CAAC;IAEf,6CAA6C;IAC7C,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAC9C,C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AAC;AAClB,CAAC;AAED,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAKzC,MAAsC,EACtC,MAAqC,EACrC,UAAyB,EACzB,OAAiC,EACjC,EAAE;IACF,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAEpD,MAAM,EAAE,GAAG,OAAO,CAAC,IAAK,CAAC,KAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAGjD,CAAC;IAEF,MAAM,QAAQ,GAAG,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAEtE,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAErC,OAAO,EAAE,CAAC,GAAG,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { esmDependencies, initializeESMDependencies, } from "../../../util/esmDependencies.js";
|
|
2
|
-
import { createExternalHTMLExporter } from "../html/externalHTMLExporter.js";
|
|
3
|
-
import { removeUnderlines } from "./removeUnderlinesRehypePlugin.js";
|
|
4
|
-
import { addSpacesToCheckboxes } from "./util/addSpacesToCheckboxesRehypePlugin.js";
|
|
5
|
-
// Needs to be sync because it's used in drag handler event (SideMenuPlugin)
|
|
6
|
-
// Ideally, call `await initializeESMDependencies()` before calling this function
|
|
7
|
-
export function cleanHTMLToMarkdown(cleanHTMLString) {
|
|
8
|
-
const deps = esmDependencies;
|
|
9
|
-
if (!deps) {
|
|
10
|
-
throw new Error("cleanHTMLToMarkdown requires ESM dependencies to be initialized");
|
|
11
|
-
}
|
|
12
|
-
const markdownString = deps.unified
|
|
13
|
-
.unified()
|
|
14
|
-
.use(deps.rehypeParse.default, { fragment: true })
|
|
15
|
-
.use(removeUnderlines)
|
|
16
|
-
.use(addSpacesToCheckboxes)
|
|
17
|
-
.use(deps.rehypeRemark.default)
|
|
18
|
-
.use(deps.remarkGfm.default)
|
|
19
|
-
.use(deps.remarkStringify.default, {
|
|
20
|
-
handlers: { text: (node) => node.value },
|
|
21
|
-
})
|
|
22
|
-
.processSync(cleanHTMLString);
|
|
23
|
-
return markdownString.value;
|
|
24
|
-
}
|
|
25
|
-
export async function blocksToMarkdown(blocks, schema, editor, options) {
|
|
26
|
-
await initializeESMDependencies();
|
|
27
|
-
const exporter = createExternalHTMLExporter(schema, editor);
|
|
28
|
-
const externalHTML = exporter.exportBlocks(blocks, options);
|
|
29
|
-
return cleanHTMLToMarkdown(externalHTML);
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=markdownExporter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"markdownExporter.js","sourceRoot":"","sources":["../../../../../src/api/exporters/markdown/markdownExporter.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,eAAe,EACf,yBAAyB,GAC1B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AAEpF,4EAA4E;AAC5E,iFAAiF;AACjF,MAAM,UAAU,mBAAmB,CAAC,eAAuB;IACzD,MAAM,IAAI,GAAG,eAAe,CAAC;IAE7B,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CACb,iEAAiE,CAClE,CAAC;IACJ,CAAC;IAED,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO;SAChC,OAAO,EAAE;SACT,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;SACjD,GAAG,CAAC,gBAAgB,CAAC;SACrB,GAAG,CAAC,qBAAqB,CAAC;SAC1B,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC;SAC9B,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;SAC3B,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE;QACjC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE;KACzC,CAAC;SACD,WAAW,CAAC,eAAe,CAAC,CAAC;IAEhC,OAAO,cAAc,CAAC,KAAe,CAAC;AACxC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAKpC,MAAqC,EACrC,MAAc,EACd,MAAsC,EACtC,OAAgC;IAEhC,MAAM,yBAAyB,EAAE,CAAC;IAClC,MAAM,QAAQ,GAAG,0BAA0B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5D,MAAM,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE5D,OAAO,mBAAmB,CAAC,YAAY,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
4
|
-
import { customBlocksTestCases } from "../../testUtil/cases/customBlocks.js";
|
|
5
|
-
import { customInlineContentTestCases } from "../../testUtil/cases/customInlineContent.js";
|
|
6
|
-
import { customStylesTestCases } from "../../testUtil/cases/customStyles.js";
|
|
7
|
-
import { defaultSchemaTestCases } from "../../testUtil/cases/defaultSchema.js";
|
|
8
|
-
import { partialBlocksToBlocksForTesting } from "../../testUtil/partialBlockTestUtil.js";
|
|
9
|
-
async function convertToMarkdownAndCompareSnapshots(editor, blocks, snapshotDirectory, snapshotName) {
|
|
10
|
-
const fullBlocks = partialBlocksToBlocksForTesting(editor.schema, blocks);
|
|
11
|
-
const md = await editor.blocksToMarkdownLossy(fullBlocks);
|
|
12
|
-
const snapshotPath = "./__snapshots__/" +
|
|
13
|
-
snapshotDirectory +
|
|
14
|
-
"/" +
|
|
15
|
-
snapshotName +
|
|
16
|
-
"/markdown.md";
|
|
17
|
-
// vitest empty snapshots are broken on CI. might be fixed on next vitest, use workaround for now
|
|
18
|
-
if (!md.length && process.env.CI) {
|
|
19
|
-
if (fs.readFileSync(path.join(__dirname, snapshotPath), "utf8").length === 0) {
|
|
20
|
-
// both are empty, so it's fine
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
expect(md).toMatchFileSnapshot(snapshotPath);
|
|
25
|
-
}
|
|
26
|
-
const testCases = [
|
|
27
|
-
defaultSchemaTestCases,
|
|
28
|
-
customBlocksTestCases,
|
|
29
|
-
customStylesTestCases,
|
|
30
|
-
customInlineContentTestCases,
|
|
31
|
-
];
|
|
32
|
-
describe("markdownExporter", () => {
|
|
33
|
-
for (const testCase of testCases) {
|
|
34
|
-
describe("Case: " + testCase.name, () => {
|
|
35
|
-
let editor;
|
|
36
|
-
const div = document.createElement("div");
|
|
37
|
-
beforeEach(() => {
|
|
38
|
-
editor = testCase.createEditor();
|
|
39
|
-
editor.mount(div);
|
|
40
|
-
});
|
|
41
|
-
afterEach(() => {
|
|
42
|
-
editor.mount(undefined);
|
|
43
|
-
editor._tiptapEditor.destroy();
|
|
44
|
-
editor = undefined;
|
|
45
|
-
delete window.__TEST_OPTIONS;
|
|
46
|
-
});
|
|
47
|
-
for (const document of testCase.documents) {
|
|
48
|
-
// eslint-disable-next-line no-loop-func
|
|
49
|
-
it("Convert " + document.name + " to HTML", async () => {
|
|
50
|
-
const nameSplit = document.name.split("/");
|
|
51
|
-
await convertToMarkdownAndCompareSnapshots(editor, document.blocks, nameSplit[0], nameSplit[1]);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
//# sourceMappingURL=markdownExporter.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"markdownExporter.test.js","sourceRoot":"","sources":["../../../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used to remove underlines before converting HTML to markdown, as Markdown
|
|
3
|
-
* doesn't support underlines.
|
|
4
|
-
*/
|
|
5
|
-
export function removeUnderlines() {
|
|
6
|
-
const removeUnderlinesHelper = (tree) => {
|
|
7
|
-
let numChildElements = tree.children.length;
|
|
8
|
-
for (let i = 0; i < numChildElements; i++) {
|
|
9
|
-
const node = tree.children[i];
|
|
10
|
-
if (node.type === "element") {
|
|
11
|
-
// Recursively removes underlines from child elements.
|
|
12
|
-
removeUnderlinesHelper(node);
|
|
13
|
-
if (node.tagName === "u") {
|
|
14
|
-
// Lifts child nodes outside underline element, deletes the underline element, and updates current index &
|
|
15
|
-
// the number of child elements.
|
|
16
|
-
if (node.children.length > 0) {
|
|
17
|
-
tree.children.splice(i, 1, ...node.children);
|
|
18
|
-
const numElementsAdded = node.children.length - 1;
|
|
19
|
-
numChildElements += numElementsAdded;
|
|
20
|
-
i += numElementsAdded;
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
tree.children.splice(i, 1);
|
|
24
|
-
numChildElements--;
|
|
25
|
-
i--;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
return removeUnderlinesHelper;
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=removeUnderlinesRehypePlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"removeUnderlinesRehypePlugin.js","sourceRoot":"","sources":["../../../../../src/api/exporters/markdown/removeUnderlinesRehypePlugin.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,sBAAsB,GAAG,CAAC,IAAgB,EAAE,EAAE;QAClD,IAAI,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAE5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,gBAAgB,EAAE,CAAC,EAAE,EAAE,CAAC;YAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;YAE9B,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBAC5B,sDAAsD;gBACtD,sBAAsB,CAAC,IAAI,CAAC,CAAC;gBAE7B,IAAK,IAAoB,CAAC,OAAO,KAAK,GAAG,EAAE,CAAC;oBAC1C,0GAA0G;oBAC1G,gCAAgC;oBAChC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBAC7B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;wBAE7C,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;wBAClD,gBAAgB,IAAI,gBAAgB,CAAC;wBACrC,CAAC,IAAI,gBAAgB,CAAC;oBACxB,CAAC;yBAAM,CAAC;wBACN,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;wBAE3B,gBAAgB,EAAE,CAAC;wBACnB,CAAC,EAAE,CAAC;oBACN,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,sBAAsB,CAAC;AAChC,CAAC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { esmDependencies } from "../../../../util/esmDependencies.js";
|
|
2
|
-
/**
|
|
3
|
-
* Rehype plugin which adds a space after each checkbox input element. This is
|
|
4
|
-
* because remark doesn't add any spaces between the checkbox input and the text
|
|
5
|
-
* itself, but these are needed for correct Markdown syntax.
|
|
6
|
-
*/
|
|
7
|
-
export function addSpacesToCheckboxes() {
|
|
8
|
-
const deps = esmDependencies;
|
|
9
|
-
if (!deps) {
|
|
10
|
-
throw new Error("addSpacesToCheckboxes requires ESM dependencies to be initialized");
|
|
11
|
-
}
|
|
12
|
-
const helper = (tree) => {
|
|
13
|
-
if (tree.children && "length" in tree.children && tree.children.length) {
|
|
14
|
-
for (let i = tree.children.length - 1; i >= 0; i--) {
|
|
15
|
-
const child = tree.children[i];
|
|
16
|
-
const nextChild = i + 1 < tree.children.length ? tree.children[i + 1] : undefined;
|
|
17
|
-
// Checks for paragraph element after checkbox input element.
|
|
18
|
-
if (child.type === "element" &&
|
|
19
|
-
child.tagName === "input" &&
|
|
20
|
-
child.properties?.type === "checkbox" &&
|
|
21
|
-
nextChild?.type === "element" &&
|
|
22
|
-
nextChild.tagName === "p") {
|
|
23
|
-
// Converts paragraph to span, otherwise remark will think it needs to
|
|
24
|
-
// be on a new line.
|
|
25
|
-
nextChild.tagName = "span";
|
|
26
|
-
// Adds a space after the checkbox input element.
|
|
27
|
-
nextChild.children.splice(0, 0, deps.hastUtilFromDom.fromDom(document.createTextNode(" ")));
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
helper(child);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
return helper;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=addSpacesToCheckboxesRehypePlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addSpacesToCheckboxesRehypePlugin.js","sourceRoot":"","sources":["../../../../../../src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAEtE;;;;GAIG;AACH,MAAM,UAAU,qBAAqB;IACnC,MAAM,IAAI,GAAG,eAAe,CAAC;IAE7B,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,CAAC,IAAgB,EAAE,EAAE;QAClC,IAAI,IAAI,CAAC,QAAQ,IAAI,QAAQ,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;YACvE,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBACnD,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;gBAC/B,MAAM,SAAS,GACb,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;gBAElE,6DAA6D;gBAC7D,IACE,KAAK,CAAC,IAAI,KAAK,SAAS;oBACxB,KAAK,CAAC,OAAO,KAAK,OAAO;oBACzB,KAAK,CAAC,UAAU,EAAE,IAAI,KAAK,UAAU;oBACrC,SAAS,EAAE,IAAI,KAAK,SAAS;oBAC7B,SAAS,CAAC,OAAO,KAAK,GAAG,EACzB,CAAC;oBACD,sEAAsE;oBACtE,oBAAoB;oBACpB,SAAS,CAAC,OAAO,GAAG,MAAM,CAAC;oBAC3B,iDAAiD;oBACjD,SAAS,CAAC,QAAQ,CAAC,MAAM,CACvB,CAAC,EACD,CAAC,EACD,IAAI,CAAC,eAAe,CAAC,OAAO,CAC1B,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CACd,CACjB,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,KAAmB,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retrieves the position just before the nearest block node in a ProseMirror
|
|
3
|
-
* doc, relative to a position. If the position is within a block node or its
|
|
4
|
-
* descendants, the position just before it is returned. If the position is not
|
|
5
|
-
* within a block node or its descendants, the position just before the next
|
|
6
|
-
* closest block node is returned. If the position is beyond the last block, the
|
|
7
|
-
* position just before the last block is returned.
|
|
8
|
-
* @param doc The ProseMirror doc.
|
|
9
|
-
* @param pos An integer position in the document.
|
|
10
|
-
* @returns The position just before the nearest blockContainer node.
|
|
11
|
-
*/
|
|
12
|
-
export function getNearestBlockPos(doc, pos) {
|
|
13
|
-
const $pos = doc.resolve(pos);
|
|
14
|
-
// Checks if the position provided is already just before a block node, in
|
|
15
|
-
// which case we return the position.
|
|
16
|
-
if ($pos.nodeAfter && $pos.nodeAfter.type.isInGroup("bnBlock")) {
|
|
17
|
-
return {
|
|
18
|
-
posBeforeNode: $pos.pos,
|
|
19
|
-
node: $pos.nodeAfter,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
// Checks the node containing the position and its ancestors until a
|
|
23
|
-
// block node is found and returned.
|
|
24
|
-
let depth = $pos.depth;
|
|
25
|
-
let node = $pos.node(depth);
|
|
26
|
-
while (depth > 0) {
|
|
27
|
-
if (node.type.isInGroup("bnBlock")) {
|
|
28
|
-
return {
|
|
29
|
-
posBeforeNode: $pos.before(depth),
|
|
30
|
-
node: node,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
depth--;
|
|
34
|
-
node = $pos.node(depth);
|
|
35
|
-
}
|
|
36
|
-
// If the position doesn't lie within a block node, we instead find the
|
|
37
|
-
// position of the next closest one. If the position is beyond the last block,
|
|
38
|
-
// we return the position of the last block. While running `doc.descendants`
|
|
39
|
-
// is expensive, this case should be very rarely triggered. However, it's
|
|
40
|
-
// possible for the position to sometimes be beyond the last block node. This
|
|
41
|
-
// is a problem specifically when using the collaboration plugin.
|
|
42
|
-
const allBlockContainerPositions = [];
|
|
43
|
-
doc.descendants((node, pos) => {
|
|
44
|
-
if (node.type.isInGroup("bnBlock")) {
|
|
45
|
-
allBlockContainerPositions.push(pos);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
// eslint-disable-next-line no-console
|
|
49
|
-
console.warn(`Position ${pos} is not within a blockContainer node.`);
|
|
50
|
-
const resolvedPos = doc.resolve(allBlockContainerPositions.find((position) => position >= pos) ||
|
|
51
|
-
allBlockContainerPositions[allBlockContainerPositions.length - 1]);
|
|
52
|
-
return {
|
|
53
|
-
posBeforeNode: resolvedPos.pos,
|
|
54
|
-
node: resolvedPos.nodeAfter,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Gets information regarding the ProseMirror nodes that make up a block in a
|
|
59
|
-
* BlockNote document. This includes the main `blockContainer` node, the
|
|
60
|
-
* `blockContent` node with the block's main body, and the optional `blockGroup`
|
|
61
|
-
* node which contains the block's children. As well as the nodes, also returns
|
|
62
|
-
* the ProseMirror positions just before & after each node.
|
|
63
|
-
* @param node The main `blockContainer` node that the block information should
|
|
64
|
-
* be retrieved from,
|
|
65
|
-
* @param bnBlockBeforePosOffset the position just before the
|
|
66
|
-
* `blockContainer` node in the document.
|
|
67
|
-
*/
|
|
68
|
-
export function getBlockInfoWithManualOffset(node, bnBlockBeforePosOffset) {
|
|
69
|
-
if (!node.type.isInGroup("bnBlock")) {
|
|
70
|
-
throw new Error(`Attempted to get bnBlock node at position but found node of different type ${node.type}`);
|
|
71
|
-
}
|
|
72
|
-
const bnBlockNode = node;
|
|
73
|
-
const bnBlockBeforePos = bnBlockBeforePosOffset;
|
|
74
|
-
const bnBlockAfterPos = bnBlockBeforePos + bnBlockNode.nodeSize;
|
|
75
|
-
const bnBlock = {
|
|
76
|
-
node: bnBlockNode,
|
|
77
|
-
beforePos: bnBlockBeforePos,
|
|
78
|
-
afterPos: bnBlockAfterPos,
|
|
79
|
-
};
|
|
80
|
-
if (bnBlockNode.type.name === "blockContainer") {
|
|
81
|
-
let blockContent;
|
|
82
|
-
let blockGroup;
|
|
83
|
-
bnBlockNode.forEach((node, offset) => {
|
|
84
|
-
if (node.type.spec.group === "blockContent") {
|
|
85
|
-
// console.log(beforePos, offset);
|
|
86
|
-
const blockContentNode = node;
|
|
87
|
-
const blockContentBeforePos = bnBlockBeforePos + offset + 1;
|
|
88
|
-
const blockContentAfterPos = blockContentBeforePos + node.nodeSize;
|
|
89
|
-
blockContent = {
|
|
90
|
-
node: blockContentNode,
|
|
91
|
-
beforePos: blockContentBeforePos,
|
|
92
|
-
afterPos: blockContentAfterPos,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
else if (node.type.name === "blockGroup") {
|
|
96
|
-
const blockGroupNode = node;
|
|
97
|
-
const blockGroupBeforePos = bnBlockBeforePos + offset + 1;
|
|
98
|
-
const blockGroupAfterPos = blockGroupBeforePos + node.nodeSize;
|
|
99
|
-
blockGroup = {
|
|
100
|
-
node: blockGroupNode,
|
|
101
|
-
beforePos: blockGroupBeforePos,
|
|
102
|
-
afterPos: blockGroupAfterPos,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
if (!blockContent) {
|
|
107
|
-
throw new Error(`blockContainer node does not contain a blockContent node in its children: ${bnBlockNode}`);
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
isBlockContainer: true,
|
|
111
|
-
bnBlock,
|
|
112
|
-
blockContent,
|
|
113
|
-
childContainer: blockGroup,
|
|
114
|
-
blockNoteType: blockContent.node.type.name,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
if (!bnBlock.node.type.isInGroup("childContainer")) {
|
|
119
|
-
throw new Error(`bnBlock node is not in the childContainer group: ${bnBlock.node}`);
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
isBlockContainer: false,
|
|
123
|
-
bnBlock: bnBlock,
|
|
124
|
-
childContainer: bnBlock,
|
|
125
|
-
blockNoteType: bnBlock.node.type.name,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Gets information regarding the ProseMirror nodes that make up a block in a
|
|
131
|
-
* BlockNote document. This includes the main `blockContainer` node, the
|
|
132
|
-
* `blockContent` node with the block's main body, and the optional `blockGroup`
|
|
133
|
-
* node which contains the block's children. As well as the nodes, also returns
|
|
134
|
-
* the ProseMirror positions just before & after each node.
|
|
135
|
-
* @param posInfo An object with the main `blockContainer` node that the block
|
|
136
|
-
* information should be retrieved from, and the position just before it in the
|
|
137
|
-
* document.
|
|
138
|
-
*/
|
|
139
|
-
export function getBlockInfo(posInfo) {
|
|
140
|
-
return getBlockInfoWithManualOffset(posInfo.node, posInfo.posBeforeNode);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Gets information regarding the ProseMirror nodes that make up a block from a
|
|
144
|
-
* resolved position just before the `blockContainer` node in the document that
|
|
145
|
-
* corresponds to it.
|
|
146
|
-
* @param resolvedPos The resolved position just before the `blockContainer`
|
|
147
|
-
* node.
|
|
148
|
-
*/
|
|
149
|
-
export function getBlockInfoFromResolvedPos(resolvedPos) {
|
|
150
|
-
if (!resolvedPos.nodeAfter) {
|
|
151
|
-
throw new Error(`Attempted to get blockContainer node at position ${resolvedPos.pos} but a node at this position does not exist`);
|
|
152
|
-
}
|
|
153
|
-
return getBlockInfoWithManualOffset(resolvedPos.nodeAfter, resolvedPos.pos);
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Gets information regarding the ProseMirror nodes that make up a block. The
|
|
157
|
-
* block chosen is the one currently containing the current ProseMirror
|
|
158
|
-
* selection.
|
|
159
|
-
* @param state The ProseMirror editor state.
|
|
160
|
-
*/
|
|
161
|
-
export function getBlockInfoFromSelection(state) {
|
|
162
|
-
const posInfo = getNearestBlockPos(state.doc, state.selection.anchor);
|
|
163
|
-
return getBlockInfo(posInfo);
|
|
164
|
-
}
|
|
165
|
-
//# sourceMappingURL=getBlockInfoFromPos.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getBlockInfoFromPos.js","sourceRoot":"","sources":["../../../src/api/getBlockInfoFromPos.ts"],"names":[],"mappings":"AA8CA;;;;;;;;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