@blocknote/core 0.17.1 → 0.19.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 +2774 -1804
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +9 -6
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.js +27 -0
- package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.js.map +1 -0
- package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.js +99 -0
- package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.js.map +1 -0
- package/dist/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.js +97 -0
- package/dist/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.js.map +1 -0
- package/dist/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.js +88 -0
- package/dist/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.js.map +1 -0
- package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.js +116 -0
- package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.js.map +1 -0
- package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.test.js +106 -0
- package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.test.js.map +1 -0
- package/dist/src/api/blockManipulation/commands/nestBlock/nestBlock.js +57 -0
- package/dist/src/api/blockManipulation/commands/nestBlock/nestBlock.js.map +1 -0
- package/dist/src/api/blockManipulation/commands/removeBlocks/removeBlocks.js +43 -0
- package/dist/src/api/blockManipulation/commands/removeBlocks/removeBlocks.js.map +1 -0
- package/dist/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.js +27 -0
- package/dist/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.js.map +1 -0
- package/dist/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.js +29 -0
- package/dist/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.js.map +1 -0
- package/dist/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.js +157 -0
- package/dist/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.js.map +1 -0
- package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.js +27 -0
- package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.js.map +1 -0
- package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.test.js +64 -0
- package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.test.js.map +1 -0
- package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.js +145 -0
- package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.js.map +1 -0
- package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.test.js +252 -0
- package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.test.js.map +1 -0
- package/dist/src/api/blockManipulation/insertContentAt.js +64 -0
- package/dist/src/api/blockManipulation/insertContentAt.js.map +1 -0
- package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.js +76 -0
- package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.js.map +1 -0
- package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.js +33 -0
- package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.js.map +1 -0
- package/dist/src/api/blockManipulation/setupTestEnv.js +172 -0
- package/dist/src/api/blockManipulation/setupTestEnv.js.map +1 -0
- package/dist/src/api/clipboard/clipboard.test.js +246 -0
- package/dist/src/api/clipboard/clipboard.test.js.map +1 -0
- package/dist/src/api/clipboard/fromClipboard/acceptedMIMETypes.js +8 -0
- package/dist/src/api/clipboard/fromClipboard/acceptedMIMETypes.js.map +1 -0
- package/dist/src/api/clipboard/fromClipboard/fileDropExtension.js +38 -0
- package/dist/src/api/clipboard/fromClipboard/fileDropExtension.js.map +1 -0
- package/dist/src/api/clipboard/fromClipboard/handleFileInsertion.js +109 -0
- package/dist/src/api/clipboard/fromClipboard/handleFileInsertion.js.map +1 -0
- package/dist/src/api/clipboard/fromClipboard/handleVSCodePaste.js +26 -0
- package/dist/src/api/clipboard/fromClipboard/handleVSCodePaste.js.map +1 -0
- package/dist/src/api/clipboard/fromClipboard/pasteExtension.js +57 -0
- package/dist/src/api/clipboard/fromClipboard/pasteExtension.js.map +1 -0
- package/dist/src/api/clipboard/toClipboard/copyExtension.js +132 -0
- package/dist/src/api/clipboard/toClipboard/copyExtension.js.map +1 -0
- package/dist/src/api/exporters/html/externalHTMLExporter.js +35 -0
- package/dist/src/api/exporters/html/externalHTMLExporter.js.map +1 -0
- package/dist/src/api/exporters/html/htmlConversion.test.js +72 -0
- package/dist/src/api/exporters/html/htmlConversion.test.js.map +1 -0
- package/dist/src/api/exporters/html/internalHTMLSerializer.js +21 -0
- package/dist/src/api/exporters/html/internalHTMLSerializer.js.map +1 -0
- package/dist/src/api/exporters/html/util/serializeBlocksExternalHTML.js +141 -0
- package/dist/src/api/exporters/html/util/serializeBlocksExternalHTML.js.map +1 -0
- package/dist/src/api/exporters/html/util/serializeBlocksInternalHTML.js +96 -0
- package/dist/src/api/exporters/html/util/serializeBlocksInternalHTML.js.map +1 -0
- package/dist/src/api/exporters/markdown/markdownExporter.js +31 -0
- package/dist/src/api/exporters/markdown/markdownExporter.js.map +1 -0
- package/dist/src/api/exporters/markdown/markdownExporter.test.js +57 -0
- package/dist/src/api/exporters/markdown/markdownExporter.test.js.map +1 -0
- package/dist/src/api/exporters/markdown/removeUnderlinesRehypePlugin.js +33 -0
- package/dist/src/api/exporters/markdown/removeUnderlinesRehypePlugin.js.map +1 -0
- package/dist/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.js +37 -0
- package/dist/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.js.map +1 -0
- package/dist/src/api/getBlockInfoFromPos.js +171 -0
- package/dist/src/api/getBlockInfoFromPos.js.map +1 -0
- package/dist/src/api/nodeConversions/blockToNode.js +197 -0
- package/dist/src/api/nodeConversions/blockToNode.js.map +1 -0
- package/dist/src/api/nodeConversions/fragmentToBlocks.js +50 -0
- package/dist/src/api/nodeConversions/fragmentToBlocks.js.map +1 -0
- package/dist/src/api/nodeConversions/nodeConversions.test.js +54 -0
- package/dist/src/api/nodeConversions/nodeConversions.test.js.map +1 -0
- package/dist/src/api/nodeConversions/nodeToBlock.js +316 -0
- package/dist/src/api/nodeConversions/nodeToBlock.js.map +1 -0
- package/dist/src/api/nodeUtil.js +28 -0
- package/dist/src/api/nodeUtil.js.map +1 -0
- package/dist/src/api/parsers/html/parseHTML.js +19 -0
- package/dist/src/api/parsers/html/parseHTML.js.map +1 -0
- package/dist/src/api/parsers/html/parseHTML.test.js +470 -0
- package/dist/src/api/parsers/html/parseHTML.test.js.map +1 -0
- package/dist/src/api/parsers/html/util/nestedLists.js +106 -0
- package/dist/src/api/parsers/html/util/nestedLists.js.map +1 -0
- package/dist/src/api/parsers/html/util/nestedLists.test.js +166 -0
- package/dist/src/api/parsers/html/util/nestedLists.test.js.map +1 -0
- package/dist/src/api/parsers/markdown/parseMarkdown.js +52 -0
- package/dist/src/api/parsers/markdown/parseMarkdown.js.map +1 -0
- package/dist/src/api/parsers/markdown/parseMarkdown.test.js +109 -0
- package/dist/src/api/parsers/markdown/parseMarkdown.test.js.map +1 -0
- package/dist/src/api/testUtil/cases/customBlocks.js +313 -0
- package/dist/src/api/testUtil/cases/customBlocks.js.map +1 -0
- package/dist/src/api/testUtil/cases/customInlineContent.js +91 -0
- package/dist/src/api/testUtil/cases/customInlineContent.js.map +1 -0
- package/dist/src/api/testUtil/cases/customStyles.js +83 -0
- package/dist/src/api/testUtil/cases/customStyles.js.map +1 -0
- package/dist/src/api/testUtil/cases/defaultSchema.js +673 -0
- package/dist/src/api/testUtil/cases/defaultSchema.js.map +1 -0
- package/dist/src/api/testUtil/index.js +2 -0
- package/dist/src/api/testUtil/index.js.map +1 -0
- package/dist/src/api/testUtil/partialBlockTestUtil.js +114 -0
- package/dist/src/api/testUtil/partialBlockTestUtil.js.map +1 -0
- package/dist/src/api/testUtil/paste.js +29 -0
- package/dist/src/api/testUtil/paste.js.map +1 -0
- package/dist/src/blocks/AudioBlockContent/AudioBlockContent.js +97 -0
- package/dist/src/blocks/AudioBlockContent/AudioBlockContent.js.map +1 -0
- package/dist/src/blocks/AudioBlockContent/audioBlockHelpers.js +5 -0
- package/dist/src/blocks/AudioBlockContent/audioBlockHelpers.js.map +1 -0
- package/dist/src/blocks/CodeBlockContent/CodeBlockContent.js +273 -0
- package/dist/src/blocks/CodeBlockContent/CodeBlockContent.js.map +1 -0
- package/dist/src/blocks/CodeBlockContent/defaultSupportedLanguages.js +90 -0
- package/dist/src/blocks/CodeBlockContent/defaultSupportedLanguages.js.map +1 -0
- package/dist/src/blocks/FileBlockContent/FileBlockContent.js +70 -0
- package/dist/src/blocks/FileBlockContent/FileBlockContent.js.map +1 -0
- package/dist/src/blocks/FileBlockContent/fileBlockHelpers.js +317 -0
- package/dist/src/blocks/FileBlockContent/fileBlockHelpers.js.map +1 -0
- package/dist/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.js +15 -0
- package/dist/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.js.map +1 -0
- package/dist/src/blocks/HeadingBlockContent/HeadingBlockContent.js +141 -0
- package/dist/src/blocks/HeadingBlockContent/HeadingBlockContent.js.map +1 -0
- package/dist/src/blocks/ImageBlockContent/ImageBlockContent.js +106 -0
- package/dist/src/blocks/ImageBlockContent/ImageBlockContent.js.map +1 -0
- package/dist/src/blocks/ImageBlockContent/imageBlockHelpers.js +6 -0
- package/dist/src/blocks/ImageBlockContent/imageBlockHelpers.js.map +1 -0
- package/dist/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.js +111 -0
- package/dist/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.js.map +1 -0
- package/dist/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.js +218 -0
- package/dist/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.js.map +1 -0
- package/dist/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.js +41 -0
- package/dist/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.js.map +1 -0
- package/dist/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.js +58 -0
- package/dist/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.js.map +1 -0
- package/dist/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.js +128 -0
- package/dist/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.js.map +1 -0
- package/dist/src/blocks/ParagraphBlockContent/ParagraphBlockContent.js +51 -0
- package/dist/src/blocks/ParagraphBlockContent/ParagraphBlockContent.js.map +1 -0
- package/dist/src/blocks/TableBlockContent/TableBlockContent.js +130 -0
- package/dist/src/blocks/TableBlockContent/TableBlockContent.js.map +1 -0
- package/dist/src/blocks/TableBlockContent/TableExtension.js +57 -0
- package/dist/src/blocks/TableBlockContent/TableExtension.js.map +1 -0
- package/dist/src/blocks/VideoBlockContent/VideoBlockContent.js +103 -0
- package/dist/src/blocks/VideoBlockContent/VideoBlockContent.js.map +1 -0
- package/dist/src/blocks/VideoBlockContent/videoBlockHelpers.js +6 -0
- package/dist/src/blocks/VideoBlockContent/videoBlockHelpers.js.map +1 -0
- package/dist/src/blocks/defaultBlockHelpers.js +50 -0
- package/dist/src/blocks/defaultBlockHelpers.js.map +1 -0
- package/dist/src/blocks/defaultBlockTypeGuards.js +40 -0
- package/dist/src/blocks/defaultBlockTypeGuards.js.map +1 -0
- package/dist/src/blocks/defaultBlocks.js +50 -0
- package/dist/src/blocks/defaultBlocks.js.map +1 -0
- package/dist/src/blocks/defaultProps.js +19 -0
- package/dist/src/blocks/defaultProps.js.map +1 -0
- package/dist/src/editor/BlockNoteEditor.js +750 -0
- package/dist/src/editor/BlockNoteEditor.js.map +1 -0
- package/dist/src/editor/BlockNoteEditor.test.js +65 -0
- package/dist/src/editor/BlockNoteEditor.test.js.map +1 -0
- package/dist/src/editor/BlockNoteExtensions.js +149 -0
- package/dist/src/editor/BlockNoteExtensions.js.map +1 -0
- package/dist/src/editor/BlockNoteSchema.js +38 -0
- package/dist/src/editor/BlockNoteSchema.js.map +1 -0
- package/dist/src/editor/BlockNoteTipTapEditor.js +169 -0
- package/dist/src/editor/BlockNoteTipTapEditor.js.map +1 -0
- package/dist/src/editor/cursorPositionTypes.js +2 -0
- package/dist/src/editor/cursorPositionTypes.js.map +1 -0
- package/dist/src/editor/defaultColors.js +77 -0
- package/dist/src/editor/defaultColors.js.map +1 -0
- package/dist/src/editor/selectionTypes.js +2 -0
- package/dist/src/editor/selectionTypes.js.map +1 -0
- package/dist/src/editor/transformPasted.js +79 -0
- package/dist/src/editor/transformPasted.js.map +1 -0
- package/dist/src/exporter/Exporter.js +36 -0
- package/dist/src/exporter/Exporter.js.map +1 -0
- package/dist/src/exporter/index.js +3 -0
- package/dist/src/exporter/index.js.map +1 -0
- package/dist/src/exporter/mapping.js +12 -0
- package/dist/src/exporter/mapping.js.map +1 -0
- package/dist/src/extensions/BackgroundColor/BackgroundColorExtension.js +30 -0
- package/dist/src/extensions/BackgroundColor/BackgroundColorExtension.js.map +1 -0
- package/dist/src/extensions/BackgroundColor/BackgroundColorMark.js +39 -0
- package/dist/src/extensions/BackgroundColor/BackgroundColorMark.js.map +1 -0
- package/dist/src/extensions/FilePanel/FilePanelPlugin.js +131 -0
- package/dist/src/extensions/FilePanel/FilePanelPlugin.js.map +1 -0
- package/dist/src/extensions/FormattingToolbar/FormattingToolbarPlugin.js +195 -0
- package/dist/src/extensions/FormattingToolbar/FormattingToolbarPlugin.js.map +1 -0
- package/dist/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js +309 -0
- package/dist/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js.map +1 -0
- package/dist/src/extensions/LinkToolbar/LinkToolbarPlugin.js +247 -0
- package/dist/src/extensions/LinkToolbar/LinkToolbarPlugin.js.map +1 -0
- package/dist/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.js +51 -0
- package/dist/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.js.map +1 -0
- package/dist/src/extensions/Placeholder/PlaceholderPlugin.js +81 -0
- package/dist/src/extensions/Placeholder/PlaceholderPlugin.js.map +1 -0
- package/dist/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.js +183 -0
- package/dist/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.js.map +1 -0
- package/dist/src/extensions/SideMenu/MultipleNodeSelection.js +68 -0
- package/dist/src/extensions/SideMenu/MultipleNodeSelection.js.map +1 -0
- package/dist/src/extensions/SideMenu/SideMenuPlugin.js +339 -0
- package/dist/src/extensions/SideMenu/SideMenuPlugin.js.map +1 -0
- package/dist/src/extensions/SideMenu/dragging.js +128 -0
- package/dist/src/extensions/SideMenu/dragging.js.map +1 -0
- package/dist/src/extensions/SuggestionMenu/DefaultGridSuggestionItem.js +2 -0
- package/dist/src/extensions/SuggestionMenu/DefaultGridSuggestionItem.js.map +1 -0
- package/dist/src/extensions/SuggestionMenu/DefaultSuggestionItem.js +2 -0
- package/dist/src/extensions/SuggestionMenu/DefaultSuggestionItem.js.map +1 -0
- package/dist/src/extensions/SuggestionMenu/SuggestionPlugin.js +245 -0
- package/dist/src/extensions/SuggestionMenu/SuggestionPlugin.js.map +1 -0
- package/dist/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.js +26 -0
- package/dist/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.js.map +1 -0
- package/dist/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.js +244 -0
- package/dist/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.js.map +1 -0
- package/dist/src/extensions/TableHandles/TableHandlesPlugin.js +553 -0
- package/dist/src/extensions/TableHandles/TableHandlesPlugin.js.map +1 -0
- package/dist/src/extensions/TextAlignment/TextAlignmentExtension.js +36 -0
- package/dist/src/extensions/TextAlignment/TextAlignmentExtension.js.map +1 -0
- package/dist/src/extensions/TextColor/TextColorExtension.js +29 -0
- package/dist/src/extensions/TextColor/TextColorExtension.js.map +1 -0
- package/dist/src/extensions/TextColor/TextColorMark.js +37 -0
- package/dist/src/extensions/TextColor/TextColorMark.js.map +1 -0
- package/dist/src/extensions/TrailingNode/TrailingNodeExtension.js +58 -0
- package/dist/src/extensions/TrailingNode/TrailingNodeExtension.js.map +1 -0
- package/dist/src/extensions/UniqueID/UniqueID.js +283 -0
- package/dist/src/extensions/UniqueID/UniqueID.js.map +1 -0
- package/dist/src/extensions/getDraggableBlockFromElement.js +13 -0
- package/dist/src/extensions/getDraggableBlockFromElement.js.map +1 -0
- package/dist/src/extensions-shared/UiElementPosition.js +2 -0
- package/dist/src/extensions-shared/UiElementPosition.js.map +1 -0
- package/dist/src/i18n/dictionary.js +4 -0
- package/dist/src/i18n/dictionary.js.map +1 -0
- package/dist/src/i18n/locales/ar.js +298 -0
- package/dist/src/i18n/locales/ar.js.map +1 -0
- package/dist/src/i18n/locales/de.js +313 -0
- package/dist/src/i18n/locales/de.js.map +1 -0
- package/dist/src/i18n/locales/en.js +314 -0
- package/dist/src/i18n/locales/en.js.map +1 -0
- package/dist/src/i18n/locales/es.js +312 -0
- package/dist/src/i18n/locales/es.js.map +1 -0
- package/dist/src/i18n/locales/fr.js +313 -0
- package/dist/src/i18n/locales/fr.js.map +1 -0
- package/dist/src/i18n/locales/hr.js +308 -0
- package/dist/src/i18n/locales/hr.js.map +1 -0
- package/dist/src/i18n/locales/index.js +16 -0
- package/dist/src/i18n/locales/index.js.map +1 -0
- package/dist/src/i18n/locales/is.js +305 -0
- package/dist/src/i18n/locales/is.js.map +1 -0
- package/dist/src/i18n/locales/ja.js +333 -0
- package/dist/src/i18n/locales/ja.js.map +1 -0
- package/dist/src/i18n/locales/ko.js +326 -0
- package/dist/src/i18n/locales/ko.js.map +1 -0
- package/dist/src/i18n/locales/nl.js +313 -0
- package/dist/src/i18n/locales/nl.js.map +1 -0
- package/dist/src/i18n/locales/pl.js +297 -0
- package/dist/src/i18n/locales/pl.js.map +1 -0
- package/dist/src/i18n/locales/pt.js +305 -0
- package/dist/src/i18n/locales/pt.js.map +1 -0
- package/dist/src/i18n/locales/ru.js +340 -0
- package/dist/src/i18n/locales/ru.js.map +1 -0
- package/dist/src/i18n/locales/vi.js +312 -0
- package/dist/src/i18n/locales/vi.js.map +1 -0
- package/dist/src/i18n/locales/zh.js +346 -0
- package/dist/src/i18n/locales/zh.js.map +1 -0
- package/dist/src/index.js +55 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/pm-nodes/BlockContainer.js +72 -0
- package/dist/src/pm-nodes/BlockContainer.js.map +1 -0
- package/dist/src/pm-nodes/BlockGroup.js +43 -0
- package/dist/src/pm-nodes/BlockGroup.js.map +1 -0
- package/dist/src/pm-nodes/Doc.js +7 -0
- package/dist/src/pm-nodes/Doc.js.map +1 -0
- package/dist/src/pm-nodes/index.js +4 -0
- package/dist/src/pm-nodes/index.js.map +1 -0
- package/dist/src/schema/blocks/createSpec.js +126 -0
- package/dist/src/schema/blocks/createSpec.js.map +1 -0
- package/dist/src/schema/blocks/internal.js +147 -0
- package/dist/src/schema/blocks/internal.js.map +1 -0
- package/dist/src/schema/blocks/types.js +2 -0
- package/dist/src/schema/blocks/types.js.map +1 -0
- package/dist/src/schema/index.js +11 -0
- package/dist/src/schema/index.js.map +1 -0
- package/dist/src/schema/inlineContent/createSpec.js +64 -0
- package/dist/src/schema/inlineContent/createSpec.js.map +1 -0
- package/dist/src/schema/inlineContent/internal.js +52 -0
- package/dist/src/schema/inlineContent/internal.js.map +1 -0
- package/dist/src/schema/inlineContent/types.js +10 -0
- package/dist/src/schema/inlineContent/types.js.map +1 -0
- package/dist/src/schema/propTypes.js +2 -0
- package/dist/src/schema/propTypes.js.map +1 -0
- package/dist/src/schema/styles/createSpec.js +48 -0
- package/dist/src/schema/styles/createSpec.js.map +1 -0
- package/dist/src/schema/styles/internal.js +53 -0
- package/dist/src/schema/styles/internal.js.map +1 -0
- package/dist/src/schema/styles/types.js +2 -0
- package/dist/src/schema/styles/types.js.map +1 -0
- package/dist/src/util/EventEmitter.js +33 -0
- package/dist/src/util/EventEmitter.js.map +1 -0
- package/dist/src/util/browser.js +17 -0
- package/dist/src/util/browser.js.map +1 -0
- package/dist/src/util/combineByGroup.js +20 -0
- package/dist/src/util/combineByGroup.js.map +1 -0
- package/dist/src/util/esmDependencies.js +35 -0
- package/dist/src/util/esmDependencies.js.map +1 -0
- package/dist/src/util/string.js +14 -0
- package/dist/src/util/string.js.map +1 -0
- package/dist/src/util/typescript.js +12 -0
- package/dist/src/util/typescript.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/webpack-stats.json +1 -1
- package/package.json +9 -7
- package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +30 -0
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +2 -0
- package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +25 -0
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +2 -2
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +104 -39
- package/src/api/blockManipulation/commands/moveBlock/__snapshots__/moveBlock.test.ts.snap +40 -0
- package/src/api/blockManipulation/commands/moveBlock/moveBlock.ts +3 -5
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +100 -0
- package/src/api/blockManipulation/commands/removeBlocks/__snapshots__/removeBlocks.test.ts.snap +10 -0
- package/src/api/blockManipulation/commands/removeBlocks/removeBlocks.ts +1 -1
- package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +40 -0
- package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +30 -0
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +8 -4
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +11 -7
- package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +87 -0
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +5 -5
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +192 -107
- package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +48 -33
- package/src/api/clipboard/clipboard.test.ts +1 -1
- package/src/api/clipboard/fromClipboard/acceptedMIMETypes.ts +1 -0
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +1 -1
- package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +49 -0
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +6 -0
- package/src/api/clipboard/toClipboard/copyExtension.ts +1 -1
- package/src/api/exporters/html/__snapshots__/codeBlock/defaultLanguage/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/codeBlock/defaultLanguage/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/codeBlock/empty/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/codeBlock/empty/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/codeBlock/python/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/codeBlock/python/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/image/basic/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/image/nested/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/image/noName/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/image/noPreview/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/lists/basic/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/lists/nested/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/basic/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/nested/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noCaption/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noName/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noName/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/internal.html +1 -1
- package/src/api/exporters/html/__snapshots__/table/allColWidths/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/allColWidths/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/mixedColWidths/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/table/mixedColWidths/internal.html +1 -0
- package/src/api/exporters/html/htmlConversion.test.ts +1 -4
- package/src/api/exporters/html/internalHTMLSerializer.ts +2 -7
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +7 -1
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +75 -33
- package/src/api/exporters/markdown/__snapshots__/codeBlock/defaultLanguage/markdown.md +3 -0
- package/src/api/exporters/markdown/__snapshots__/codeBlock/empty/markdown.md +2 -0
- package/src/api/exporters/markdown/__snapshots__/codeBlock/python/markdown.md +3 -0
- package/src/api/exporters/markdown/__snapshots__/table/allColWidths/markdown.md +5 -0
- package/src/api/exporters/markdown/__snapshots__/table/basic/markdown.md +5 -0
- package/src/api/exporters/markdown/__snapshots__/table/mixedColWidths/markdown.md +5 -0
- package/src/api/exporters/markdown/markdownExporter.test.ts +1 -4
- package/src/api/getBlockInfoFromPos.ts +113 -58
- package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +711 -0
- package/src/api/nodeConversions/blockToNode.ts +62 -26
- package/src/api/nodeConversions/fragmentToBlocks.ts +18 -0
- package/src/api/nodeConversions/nodeToBlock.ts +35 -22
- package/src/api/nodeUtil.ts +1 -1
- package/src/api/parsers/html/__snapshots__/parse-notion-html.json +5 -0
- package/src/api/parsers/markdown/parseMarkdown.ts +1 -1
- package/src/api/testUtil/cases/defaultSchema.ts +95 -0
- package/src/api/testUtil/partialBlockTestUtil.ts +41 -4
- package/src/blocks/AudioBlockContent/AudioBlockContent.ts +4 -2
- package/src/blocks/CodeBlockContent/CodeBlockContent.ts +369 -0
- package/src/blocks/CodeBlockContent/defaultSupportedLanguages.ts +96 -0
- package/src/blocks/FileBlockContent/fileBlockHelpers.ts +10 -2
- package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +19 -31
- package/src/blocks/ImageBlockContent/ImageBlockContent.ts +4 -2
- package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +5 -9
- package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +6 -10
- package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +11 -4
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +5 -9
- package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +4 -8
- package/src/blocks/TableBlockContent/TableBlockContent.ts +83 -8
- package/src/blocks/TableBlockContent/TableExtension.ts +10 -1
- package/src/blocks/VideoBlockContent/VideoBlockContent.ts +4 -2
- package/src/blocks/defaultBlockHelpers.ts +7 -2
- package/src/blocks/defaultBlocks.ts +4 -0
- package/src/editor/Block.css +71 -3
- package/src/editor/BlockNoteEditor.test.ts +2 -2
- package/src/editor/BlockNoteEditor.ts +18 -21
- package/src/editor/BlockNoteExtensions.ts +2 -3
- package/src/editor/BlockNoteTipTapEditor.ts +8 -1
- package/src/editor/defaultColors.ts +77 -0
- package/src/editor/editor.css +43 -5
- package/src/editor/transformPasted.ts +6 -3
- package/src/exporter/Exporter.ts +101 -0
- package/src/exporter/index.ts +2 -0
- package/src/exporter/mapping.ts +75 -0
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +8 -0
- package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +201 -48
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +1 -1
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +5 -0
- package/src/extensions/SideMenu/SideMenuPlugin.ts +141 -52
- package/src/extensions/SideMenu/dragging.ts +3 -54
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +5 -0
- package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +2 -1
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +22 -6
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +225 -120
- package/src/extensions/TrailingNode/TrailingNodeExtension.ts +1 -1
- package/src/extensions/getDraggableBlockFromElement.ts +19 -0
- package/src/i18n/locales/ar.ts +6 -0
- package/src/i18n/locales/de.ts +299 -294
- package/src/i18n/locales/en.ts +6 -0
- package/src/i18n/locales/es.ts +310 -274
- package/src/i18n/locales/fr.ts +6 -0
- package/src/i18n/locales/is.ts +6 -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 +10 -4
- 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 +9 -0
- package/src/pm-nodes/BlockContainer.ts +1 -1
- package/src/pm-nodes/BlockGroup.ts +2 -2
- package/src/pm-nodes/README.md +127 -28
- package/src/schema/blocks/createSpec.ts +4 -1
- package/src/schema/blocks/internal.ts +12 -2
- package/src/schema/blocks/types.ts +3 -1
- package/src/util/combineByGroup.ts +25 -0
- package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.d.ts +22 -2
- package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.d.ts +5 -0
- package/types/src/api/blockManipulation/setupTestEnv.d.ts +22 -8
- package/types/src/api/clipboard/fromClipboard/acceptedMIMETypes.d.ts +1 -1
- package/types/src/api/clipboard/fromClipboard/handleVSCodePaste.d.ts +3 -0
- package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +2 -3
- package/types/src/api/getBlockInfoFromPos.d.ts +55 -5
- package/types/src/api/nodeConversions/blockToNode.d.ts +1 -1
- package/types/src/api/nodeConversions/nodeToBlock.d.ts +3 -1
- package/types/src/api/testUtil/cases/customBlocks.d.ts +22 -8
- package/types/src/api/testUtil/cases/customInlineContent.d.ts +22 -8
- package/types/src/api/testUtil/cases/customStyles.d.ts +22 -8
- package/types/src/api/testUtil/partialBlockTestUtil.d.ts +2 -1
- package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +1 -0
- package/types/src/blocks/CodeBlockContent/CodeBlockContent.d.ts +57 -0
- package/types/src/blocks/CodeBlockContent/defaultSupportedLanguages.d.ts +6 -0
- package/types/src/blocks/FileBlockContent/fileBlockHelpers.d.ts +1 -0
- package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +1 -0
- package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +0 -12
- package/types/src/blocks/TableBlockContent/TableExtension.d.ts +3 -0
- package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +1 -0
- package/types/src/blocks/defaultBlocks.d.ts +45 -16
- package/types/src/editor/BlockNoteEditor.d.ts +4 -3
- package/types/src/editor/BlockNoteTipTapEditor.d.ts +1 -0
- package/types/src/editor/defaultColors.d.ts +76 -0
- package/types/src/exporter/Exporter.d.ts +43 -0
- package/types/src/exporter/index.d.ts +2 -0
- package/types/src/exporter/mapping.d.ts +30 -0
- package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +2 -1
- package/types/src/extensions/SideMenu/dragging.d.ts +1 -6
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +9 -5
- package/types/src/extensions/getDraggableBlockFromElement.d.ts +5 -0
- 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/index.d.ts +6 -0
- package/types/src/schema/blocks/createSpec.d.ts +1 -1
- package/types/src/schema/blocks/internal.d.ts +2 -2
- package/types/src/schema/blocks/types.d.ts +3 -1
- package/types/src/util/combineByGroup.d.ts +9 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Plugin, PluginKey } from "prosemirror-state";
|
|
2
|
+
import { Decoration, DecorationSet } from "prosemirror-view";
|
|
3
|
+
const PLUGIN_KEY = new PluginKey(`blocknote-placeholder`);
|
|
4
|
+
export const PlaceholderPlugin = (editor, placeholders) => {
|
|
5
|
+
return new Plugin({
|
|
6
|
+
key: PLUGIN_KEY,
|
|
7
|
+
view: () => {
|
|
8
|
+
const styleEl = document.createElement("style");
|
|
9
|
+
const nonce = editor._tiptapEditor.options.injectNonce;
|
|
10
|
+
if (nonce) {
|
|
11
|
+
styleEl.setAttribute("nonce", nonce);
|
|
12
|
+
}
|
|
13
|
+
if (editor._tiptapEditor.view.root instanceof ShadowRoot) {
|
|
14
|
+
editor._tiptapEditor.view.root.append(styleEl);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
editor._tiptapEditor.view.root.head.appendChild(styleEl);
|
|
18
|
+
}
|
|
19
|
+
const styleSheet = styleEl.sheet;
|
|
20
|
+
const getBaseSelector = (additionalSelectors = "") => `.bn-block-content${additionalSelectors} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`;
|
|
21
|
+
const getSelector = (blockType, mustBeFocused = true) => {
|
|
22
|
+
const mustBeFocusedSelector = mustBeFocused
|
|
23
|
+
? `[data-is-empty-and-focused]`
|
|
24
|
+
: ``;
|
|
25
|
+
if (blockType === "default") {
|
|
26
|
+
return getBaseSelector(mustBeFocusedSelector);
|
|
27
|
+
}
|
|
28
|
+
const blockTypeSelector = `[data-content-type="${blockType}"]`;
|
|
29
|
+
return getBaseSelector(mustBeFocusedSelector + blockTypeSelector);
|
|
30
|
+
};
|
|
31
|
+
for (const [blockType, placeholder] of Object.entries(placeholders)) {
|
|
32
|
+
const mustBeFocused = blockType === "default";
|
|
33
|
+
styleSheet.insertRule(`${getSelector(blockType, mustBeFocused)}{ content: ${JSON.stringify(placeholder)}; }`);
|
|
34
|
+
// For some reason, the placeholders which show when the block is focused
|
|
35
|
+
// take priority over ones which show depending on block type, so we need
|
|
36
|
+
// to make sure the block specific ones are also used when the block is
|
|
37
|
+
// focused.
|
|
38
|
+
if (!mustBeFocused) {
|
|
39
|
+
styleSheet.insertRule(`${getSelector(blockType, true)}{ content: ${JSON.stringify(placeholder)}; }`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
destroy: () => {
|
|
44
|
+
if (editor._tiptapEditor.view.root instanceof ShadowRoot) {
|
|
45
|
+
editor._tiptapEditor.view.root.removeChild(styleEl);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
editor._tiptapEditor.view.root.head.removeChild(styleEl);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
props: {
|
|
54
|
+
// TODO: maybe also add placeholder for empty document ("e.g.: start writing..")
|
|
55
|
+
decorations: (state) => {
|
|
56
|
+
const { doc, selection } = state;
|
|
57
|
+
if (!editor.isEditable) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (!selection.empty) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
// Don't show placeholder when the cursor is inside a code block
|
|
64
|
+
if (selection.$from.parent.type.spec.code) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const $pos = selection.$anchor;
|
|
68
|
+
const node = $pos.parent;
|
|
69
|
+
if (node.content.size > 0) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const before = $pos.before();
|
|
73
|
+
const dec = Decoration.node(before, before + node.nodeSize, {
|
|
74
|
+
"data-is-empty-and-focused": "true",
|
|
75
|
+
});
|
|
76
|
+
return DecorationSet.create(doc, [dec]);
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=PlaceholderPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlaceholderPlugin.js","sourceRoot":"","sources":["../../../../src/extensions/Placeholder/PlaceholderPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAG7D,MAAM,UAAU,GAAG,IAAI,SAAS,CAAC,uBAAuB,CAAC,CAAC;AAE1D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,MAAsC,EACtC,YAAgD,EAChD,EAAE;IACF,OAAO,IAAI,MAAM,CAAC;QAChB,GAAG,EAAE,UAAU;QACf,IAAI,EAAE,GAAG,EAAE;YACT,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YAChD,MAAM,KAAK,GAAG,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,WAAW,CAAC;YACvD,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YACvC,CAAC;YACD,IAAI,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,YAAY,UAAU,EAAE,CAAC;gBACzD,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACjD,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC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"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { findChildren } from "@tiptap/core";
|
|
2
|
+
import { Plugin, PluginKey } from "prosemirror-state";
|
|
3
|
+
import { Decoration, DecorationSet } from "prosemirror-view";
|
|
4
|
+
const PLUGIN_KEY = new PluginKey(`previous-blocks`);
|
|
5
|
+
const nodeAttributes = {
|
|
6
|
+
// Numbered List Items
|
|
7
|
+
index: "index",
|
|
8
|
+
// Headings
|
|
9
|
+
level: "level",
|
|
10
|
+
// All Blocks
|
|
11
|
+
type: "type",
|
|
12
|
+
depth: "depth",
|
|
13
|
+
"depth-change": "depth-change",
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* This plugin tracks transformation of Block node attributes, so we can support CSS transitions.
|
|
17
|
+
*
|
|
18
|
+
* Problem it solves: ProseMirror recreates the DOM when transactions happen. So when a transaction changes a Node attribute,
|
|
19
|
+
* it results in a completely new DOM element. This means CSS transitions don't work.
|
|
20
|
+
*
|
|
21
|
+
* Solution: When attributes change on a node, this plugin sets a data-* attribute with the "previous" value. This way we can still use CSS transitions. (See block.module.css)
|
|
22
|
+
*/
|
|
23
|
+
export const PreviousBlockTypePlugin = () => {
|
|
24
|
+
let timeout;
|
|
25
|
+
return new Plugin({
|
|
26
|
+
key: PLUGIN_KEY,
|
|
27
|
+
view(_editorView) {
|
|
28
|
+
return {
|
|
29
|
+
update: async (view, _prevState) => {
|
|
30
|
+
if (this.key?.getState(view.state).updatedBlocks.size > 0) {
|
|
31
|
+
// use setTimeout 0 to clear the decorations so that at least
|
|
32
|
+
// for one DOM-render the decorations have been applied
|
|
33
|
+
timeout = setTimeout(() => {
|
|
34
|
+
view.dispatch(view.state.tr.setMeta(PLUGIN_KEY, { clearUpdate: true }));
|
|
35
|
+
}, 0);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
destroy: () => {
|
|
39
|
+
if (timeout) {
|
|
40
|
+
clearTimeout(timeout);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
state: {
|
|
46
|
+
init() {
|
|
47
|
+
return {
|
|
48
|
+
// Block attributes, by block ID, from just before the previous transaction.
|
|
49
|
+
prevTransactionOldBlockAttrs: {},
|
|
50
|
+
// Block attributes, by block ID, from just before the current transaction.
|
|
51
|
+
currentTransactionOldBlockAttrs: {},
|
|
52
|
+
// Set of IDs of blocks whose attributes changed from the current transaction.
|
|
53
|
+
updatedBlocks: new Set(),
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
apply(transaction, prev, oldState, newState) {
|
|
57
|
+
prev.currentTransactionOldBlockAttrs = {};
|
|
58
|
+
prev.updatedBlocks.clear();
|
|
59
|
+
if (!transaction.docChanged || oldState.doc.eq(newState.doc)) {
|
|
60
|
+
return prev;
|
|
61
|
+
}
|
|
62
|
+
// TODO: Instead of iterating through the entire document, only check nodes affected by the transactions. Will
|
|
63
|
+
// also probably require checking nodes affected by the previous transaction too.
|
|
64
|
+
// We didn't get this to work yet:
|
|
65
|
+
// const transform = combineTransactionSteps(oldState.doc, [transaction]);
|
|
66
|
+
// // const { mapping } = transform;
|
|
67
|
+
// const changes = getChangedRanges(transform);
|
|
68
|
+
//
|
|
69
|
+
// changes.forEach(({ oldRange, newRange }) => {
|
|
70
|
+
// const oldNodes = findChildrenInRange(
|
|
71
|
+
// oldState.doc,
|
|
72
|
+
// oldRange,
|
|
73
|
+
// (node) => node.attrs.id
|
|
74
|
+
// );
|
|
75
|
+
//
|
|
76
|
+
// const newNodes = findChildrenInRange(
|
|
77
|
+
// newState.doc,
|
|
78
|
+
// newRange,
|
|
79
|
+
// (node) => node.attrs.id
|
|
80
|
+
// );
|
|
81
|
+
const currentTransactionOriginalOldBlockAttrs = {};
|
|
82
|
+
const oldNodes = findChildren(oldState.doc, (node) => node.attrs.id);
|
|
83
|
+
const oldNodesById = new Map(oldNodes.map((node) => [node.node.attrs.id, node]));
|
|
84
|
+
const newNodes = findChildren(newState.doc, (node) => node.attrs.id);
|
|
85
|
+
// Traverses all block containers in the new editor state.
|
|
86
|
+
for (const node of newNodes) {
|
|
87
|
+
const oldNode = oldNodesById.get(node.node.attrs.id);
|
|
88
|
+
const oldContentNode = oldNode?.node.firstChild;
|
|
89
|
+
const newContentNode = node.node.firstChild;
|
|
90
|
+
if (oldNode && oldContentNode && newContentNode) {
|
|
91
|
+
const newAttrs = {
|
|
92
|
+
index: newContentNode.attrs.index,
|
|
93
|
+
level: newContentNode.attrs.level,
|
|
94
|
+
type: newContentNode.type.name,
|
|
95
|
+
depth: newState.doc.resolve(node.pos).depth,
|
|
96
|
+
};
|
|
97
|
+
let oldAttrs = {
|
|
98
|
+
index: oldContentNode.attrs.index,
|
|
99
|
+
level: oldContentNode.attrs.level,
|
|
100
|
+
type: oldContentNode.type.name,
|
|
101
|
+
depth: oldState.doc.resolve(oldNode.pos).depth,
|
|
102
|
+
};
|
|
103
|
+
currentTransactionOriginalOldBlockAttrs[node.node.attrs.id] =
|
|
104
|
+
oldAttrs;
|
|
105
|
+
// Whenever a transaction is appended by the OrderedListItemIndexPlugin, it's given the metadata:
|
|
106
|
+
// { "orderedListIndexing": true }
|
|
107
|
+
// These appended transactions happen immediately after any transaction which causes ordered list item
|
|
108
|
+
// indices to require updating, including those which trigger animations. Therefore, these animations are
|
|
109
|
+
// immediately overridden when the PreviousBlockTypePlugin processes the appended transaction, despite only
|
|
110
|
+
// the listItemIndex attribute changing. To solve this, oldAttrs must be edited for transactions with the
|
|
111
|
+
// "orderedListIndexing" metadata, so the correct animation can be re-triggered.
|
|
112
|
+
if (transaction.getMeta("numberedListIndexing")) {
|
|
113
|
+
// If the block existed before the transaction, gets the attributes from before the previous transaction
|
|
114
|
+
// (i.e. the transaction that caused list item indices to need updating).
|
|
115
|
+
if (node.node.attrs.id in prev.prevTransactionOldBlockAttrs) {
|
|
116
|
+
oldAttrs =
|
|
117
|
+
prev.prevTransactionOldBlockAttrs[node.node.attrs.id];
|
|
118
|
+
}
|
|
119
|
+
// Stops list item indices themselves being animated (looks smoother), unless the block's content type is
|
|
120
|
+
// changing from a numbered list item to something else.
|
|
121
|
+
if (newAttrs.type === "numberedListItem") {
|
|
122
|
+
oldAttrs.index = newAttrs.index;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
prev.currentTransactionOldBlockAttrs[node.node.attrs.id] = oldAttrs;
|
|
126
|
+
// TODO: faster deep equal?
|
|
127
|
+
if (JSON.stringify(oldAttrs) !== JSON.stringify(newAttrs)) {
|
|
128
|
+
oldAttrs["depth-change"] =
|
|
129
|
+
oldAttrs.depth - newAttrs.depth;
|
|
130
|
+
// for debugging:
|
|
131
|
+
// console.log(
|
|
132
|
+
// "id:",
|
|
133
|
+
// node.node.attrs.id,
|
|
134
|
+
// "previousBlockTypePlugin changes detected, oldAttrs",
|
|
135
|
+
// oldAttrs,
|
|
136
|
+
// "new",
|
|
137
|
+
// newAttrs
|
|
138
|
+
// );
|
|
139
|
+
prev.updatedBlocks.add(node.node.attrs.id);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
prev.prevTransactionOldBlockAttrs =
|
|
144
|
+
currentTransactionOriginalOldBlockAttrs;
|
|
145
|
+
return prev;
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
props: {
|
|
149
|
+
decorations(state) {
|
|
150
|
+
const pluginState = this.getState(state);
|
|
151
|
+
if (pluginState.updatedBlocks.size === 0) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
const decorations = [];
|
|
155
|
+
state.doc.descendants((node, pos) => {
|
|
156
|
+
if (!node.attrs.id) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (!pluginState.updatedBlocks.has(node.attrs.id)) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const prevAttrs = pluginState.currentTransactionOldBlockAttrs[node.attrs.id];
|
|
163
|
+
const decorationAttrs = {};
|
|
164
|
+
for (const [nodeAttr, val] of Object.entries(prevAttrs)) {
|
|
165
|
+
decorationAttrs["data-prev-" + nodeAttributes[nodeAttr]] =
|
|
166
|
+
val || "none";
|
|
167
|
+
}
|
|
168
|
+
// for debugging:
|
|
169
|
+
// console.log(
|
|
170
|
+
// "previousBlockTypePlugin committing decorations",
|
|
171
|
+
// decorationAttrs
|
|
172
|
+
// );
|
|
173
|
+
const decoration = Decoration.node(pos, pos + node.nodeSize, {
|
|
174
|
+
...decorationAttrs,
|
|
175
|
+
});
|
|
176
|
+
decorations.push(decoration);
|
|
177
|
+
});
|
|
178
|
+
return DecorationSet.create(state.doc, decorations);
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
//# sourceMappingURL=PreviousBlockTypePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PreviousBlockTypePlugin.js","sourceRoot":"","sources":["../../../../src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE7D,MAAM,UAAU,GAAG,IAAI,SAAS,CAAC,iBAAiB,CAAC,CAAC;AAEpD,MAAM,cAAc,GAA2B;IAC7C,sBAAsB;IACtB,KAAK,EAAE,OAAO;IACd,WAAW;IACX,KAAK,EAAE,OAAO;IACd,aAAa;IACb,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,cAAc,EAAE,cAAc;CAC/B,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,EAAE;IAC1C,IAAI,OAAY,CAAC;IACjB,OAAO,IAAI,MAAM,CAAC;QAChB,GAAG,EAAE,UAAU;QACf,IAAI,CAAC,WAAW;YACd,OAAO;g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AAC,EAAE,CAAC;wBACxD,eAAe,CAAC,YAAY,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;4BACtD,GAAG,IAAI,MAAM,CAAC;oBAClB,CAAC;oBAED,iBAAiB;oBACjB,eAAe;oBACf,sDAAsD;oBACtD,oBAAoB;oBACpB,KAAK;oBAEL,MAAM,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;wBAC3D,GAAG,eAAe;qBACnB,CAAC,CAAC;oBAEH,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBAC/B,CAAC,CAAC,CAAC;gBAEH,OAAO,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;YACtD,CAAC;SACF;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Fragment, Slice } from "prosemirror-model";
|
|
2
|
+
import { Selection } from "prosemirror-state";
|
|
3
|
+
/**
|
|
4
|
+
* This class represents an editor selection which spans multiple nodes/blocks. It's currently only used to allow users
|
|
5
|
+
* to drag multiple blocks at the same time. Expects the selection anchor and head to be between nodes, i.e. just before
|
|
6
|
+
* the first target node and just after the last, and that anchor and head are at the same nesting level.
|
|
7
|
+
*
|
|
8
|
+
* Partially based on ProseMirror's NodeSelection implementation:
|
|
9
|
+
* (https://github.com/ProseMirror/prosemirror-state/blob/master/src/selection.ts)
|
|
10
|
+
* MultipleNodeSelection differs from NodeSelection in the following ways:
|
|
11
|
+
* 1. Stores which nodes are included in the selection instead of just a single node.
|
|
12
|
+
* 2. Already expects the selection to start just before the first target node and ends just after the last, while a
|
|
13
|
+
* NodeSelection automatically sets both anchor and head to just before the single target node.
|
|
14
|
+
*/
|
|
15
|
+
export class MultipleNodeSelection extends Selection {
|
|
16
|
+
nodes;
|
|
17
|
+
constructor($anchor, $head) {
|
|
18
|
+
super($anchor, $head);
|
|
19
|
+
// Parent is at the same nesting level as anchor/head since they are just before/ just after target nodes.
|
|
20
|
+
const parentNode = $anchor.node();
|
|
21
|
+
this.nodes = [];
|
|
22
|
+
$anchor.doc.nodesBetween($anchor.pos, $head.pos, (node, _pos, parent) => {
|
|
23
|
+
if (parent !== null && parent.eq(parentNode)) {
|
|
24
|
+
this.nodes.push(node);
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
static create(doc, from, to = from) {
|
|
31
|
+
return new MultipleNodeSelection(doc.resolve(from), doc.resolve(to));
|
|
32
|
+
}
|
|
33
|
+
content() {
|
|
34
|
+
return new Slice(Fragment.from(this.nodes), 0, 0);
|
|
35
|
+
}
|
|
36
|
+
eq(selection) {
|
|
37
|
+
if (!(selection instanceof MultipleNodeSelection)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (this.nodes.length !== selection.nodes.length) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (this.from !== selection.from || this.to !== selection.to) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
for (let i = 0; i < this.nodes.length; i++) {
|
|
47
|
+
if (!this.nodes[i].eq(selection.nodes[i])) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
map(doc, mapping) {
|
|
54
|
+
const fromResult = mapping.mapResult(this.from);
|
|
55
|
+
const toResult = mapping.mapResult(this.to);
|
|
56
|
+
if (toResult.deleted) {
|
|
57
|
+
return Selection.near(doc.resolve(fromResult.pos));
|
|
58
|
+
}
|
|
59
|
+
if (fromResult.deleted) {
|
|
60
|
+
return Selection.near(doc.resolve(toResult.pos));
|
|
61
|
+
}
|
|
62
|
+
return new MultipleNodeSelection(doc.resolve(fromResult.pos), doc.resolve(toResult.pos));
|
|
63
|
+
}
|
|
64
|
+
toJSON() {
|
|
65
|
+
return { type: "node", anchor: this.anchor, head: this.head };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=MultipleNodeSelection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultipleNodeSelection.js","sourceRoot":"","sources":["../../../../src/extensions/SideMenu/MultipleNodeSelection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAqB,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IAClD,KAAK,CAAc;IAEnB,YAAY,OAAoB,EAAE,KAAkB;QAClD,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAEtB,0GAA0G;QAC1G,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAElC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;YACtE,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC7C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACtB,OAAO,KAAK,CAAC;YACf,CAAC;YACD,OAAO;QACT,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,GAAS,EAAE,IAAY,EAAE,EAAE,GAAG,IAAI;QAC9C,OAAO,IAAI,qBAAqB,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IACvE,CAAC;IAED,OAAO;QACL,OAAO,IAAI,KAAK,CA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