@blocknote/core 0.51.4 → 0.52.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/BlockNoteExtension-B_IEJHS8.js +38 -0
- package/dist/BlockNoteExtension-B_IEJHS8.js.map +1 -0
- package/dist/BlockNoteExtension-M0znTzxP.cjs +2 -0
- package/dist/BlockNoteExtension-M0znTzxP.cjs.map +1 -0
- package/dist/ThreadStore-Bx-gSEh1.cjs +2 -0
- package/dist/ThreadStore-Bx-gSEh1.cjs.map +1 -0
- package/dist/ThreadStore-et9wB5Xt.js +11 -0
- package/dist/ThreadStore-et9wB5Xt.js.map +1 -0
- package/dist/UserStore-DCG6lsla.cjs +2 -0
- package/dist/UserStore-DCG6lsla.cjs.map +1 -0
- package/dist/UserStore-QbbPFj0z.js +73 -0
- package/dist/UserStore-QbbPFj0z.js.map +1 -0
- package/dist/blocknote.cjs +1 -1
- package/dist/blocknote.js +6 -7
- package/dist/blocks-BqHv0xhc.cjs +12 -0
- package/dist/blocks-BqHv0xhc.cjs.map +1 -0
- package/dist/{blocks-DGsP5WKr.js → blocks-CiuUGa1E.js} +1093 -994
- package/dist/blocks-CiuUGa1E.js.map +1 -0
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +2 -2
- package/dist/comments.cjs +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +75 -340
- package/dist/comments.js.map +1 -1
- package/dist/{en-Cj5r8sW_.cjs → en-C5Z4Ag9_.cjs} +2 -2
- package/dist/en-C5Z4Ag9_.cjs.map +1 -0
- package/dist/{en-B9hMApn4.js → en-CGKXfWma.js} +9 -1
- package/dist/en-CGKXfWma.js.map +1 -0
- package/dist/{extensions-Co4y7P63.js → extensions-CrUGDOks.js} +655 -583
- package/dist/extensions-CrUGDOks.js.map +1 -0
- package/dist/extensions-Ghr9QqqR.cjs +52 -0
- package/dist/extensions-Ghr9QqqR.cjs.map +1 -0
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +4 -4
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +177 -1
- package/dist/locales.js.map +1 -1
- package/dist/{src-Bcud0PIg.js → src-DTF83Cl9.js} +1243 -1297
- package/dist/src-DTF83Cl9.js.map +1 -0
- package/dist/src-OfbaVbMw.cjs +21 -0
- package/dist/src-OfbaVbMw.cjs.map +1 -0
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/y.cjs +2 -0
- package/dist/y.cjs.map +1 -0
- package/dist/y.js +989 -0
- package/dist/y.js.map +1 -0
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.cjs.map +1 -1
- package/dist/yjs.js +535 -14
- package/dist/yjs.js.map +1 -1
- package/package.json +46 -19
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +1 -1
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +1 -1
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +3 -3
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +25 -20
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +39 -29
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +2 -2
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +4 -8
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +1 -1
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +21 -9
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +6 -5
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +362 -4
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +240 -30
- package/src/api/blockManipulation/getBlock/getBlock.ts +4 -9
- package/src/api/blockManipulation/selections/selection.ts +3 -6
- package/src/api/blockManipulation/selections/textCursorPosition.ts +10 -10
- package/src/api/blockManipulation/setupTestEnv.ts +1 -1
- package/src/api/blockManipulation/tables/tables.test.ts +1 -1
- package/src/api/clipboard/fromClipboard/fileDropExtension.ts +1 -1
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +8 -4
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +1 -1
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +2 -1
- package/src/api/exporters/markdown/htmlToMarkdown.ts +79 -43
- package/src/api/getBlockInfoFromPos.test.ts +256 -0
- package/src/api/getBlockInfoFromPos.ts +53 -15
- package/src/api/getBlocksChangedByTransaction.test.ts +2 -1
- package/src/api/getBlocksChangedByTransaction.ts +6 -6
- package/src/api/nodeConversions/blockToNode.test.ts +113 -0
- package/src/api/nodeConversions/blockToNode.ts +15 -3
- package/src/api/nodeConversions/fragmentToBlocks.ts +2 -4
- package/src/api/nodeConversions/nodeToBlock.ts +28 -58
- package/src/api/nodeUtil.ts +6 -2
- package/src/api/parsers/html/parseHTML.ts +1 -1
- package/src/api/parsers/html/util/nestedLists.test.ts +1 -1
- package/src/api/parsers/markdown/detectMarkdown.test.ts +1 -1
- package/src/api/parsers/markdown/markdownToHtml.ts +228 -82
- package/src/api/pmUtil.ts +18 -1
- package/src/api/positionMapping.test.ts +20 -345
- package/src/api/positionMapping.ts +13 -83
- package/src/blocks/Audio/block.ts +1 -1
- package/src/blocks/Code/block.test.ts +14 -7
- package/src/blocks/Code/block.ts +2 -2
- package/src/blocks/Image/block.ts +1 -1
- package/src/blocks/ListItem/CheckListItem/block.test.ts +1 -1
- package/src/blocks/ListItem/ListItemKeyboardShortcuts.ts +2 -2
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +4 -11
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +47 -50
- package/src/blocks/Table/TableExtension.test.ts +9 -6
- package/src/blocks/Table/TableExtension.ts +20 -6
- package/src/blocks/Table/block.ts +18 -5
- package/src/blocks/Video/block.ts +1 -1
- package/src/blocks/utils/listItemEnterHandler.ts +3 -2
- package/src/comments/extension.ts +30 -21
- package/src/comments/index.ts +0 -3
- package/src/comments/mark.ts +4 -0
- package/src/comments/threadstore/ThreadStore.ts +4 -8
- package/src/comments/types.ts +0 -8
- package/src/editor/Block.css +307 -3
- package/src/editor/BlockNoteEditor.test.ts +21 -18
- package/src/editor/BlockNoteEditor.ts +22 -57
- package/src/editor/BlockNoteExtension.test.ts +1 -1
- package/src/editor/managers/BlockManager.ts +1 -1
- package/src/editor/managers/ExtensionManager/ExtensionManager.test.ts +249 -0
- package/src/editor/managers/ExtensionManager/extensions.ts +7 -18
- package/src/editor/managers/ExtensionManager/index.ts +168 -68
- package/src/editor/managers/StateManager.ts +4 -3
- package/src/editor/performance.test.ts +14 -1
- package/src/editor/transformPasted.test.ts +1 -1
- package/src/extensions/Placeholder/Placeholder.ts +1 -0
- package/src/extensions/PositionMapping/PositionMapping.ts +68 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +14 -1
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +14 -11
- package/src/extensions/SideMenu/SideMenu.ts +9 -2
- package/src/extensions/SuggestionMenu/SuggestionMenu.test.ts +1 -1
- package/src/extensions/TableHandles/TableHandles.ts +18 -20
- package/src/extensions/TrailingNode/TrailingNode.ts +33 -1
- package/src/extensions/Versioning/Versioning.test.ts +435 -0
- package/src/extensions/Versioning/Versioning.ts +628 -0
- package/src/extensions/Versioning/inMemoryVersioning.test.ts +469 -0
- package/src/extensions/Versioning/inMemoryVersioning.ts +263 -0
- package/src/extensions/Versioning/index.ts +2 -0
- package/src/extensions/index.ts +6 -9
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +155 -0
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +6 -8
- package/src/extensions/tiptap-extensions/Link/helpers/autolink.ts +9 -9
- package/src/extensions/tiptap-extensions/Link/helpers/linkDetector.ts +8 -10
- package/src/extensions/tiptap-extensions/Link/helpers/whitespace.ts +2 -2
- package/src/extensions/tiptap-extensions/Link/link.test.ts +26 -22
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.ts +187 -0
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +37 -24
- package/src/extensions/tiptap-extensions/index.ts +1 -25
- package/src/i18n/locales/ar.ts +9 -0
- package/src/i18n/locales/de.ts +9 -0
- package/src/i18n/locales/en.ts +10 -1
- package/src/i18n/locales/es.ts +9 -0
- package/src/i18n/locales/fa.ts +11 -1
- package/src/i18n/locales/fr.ts +9 -0
- package/src/i18n/locales/he.ts +10 -1
- package/src/i18n/locales/hr.ts +10 -0
- package/src/i18n/locales/is.ts +10 -0
- package/src/i18n/locales/it.ts +9 -0
- package/src/i18n/locales/ja.ts +9 -0
- package/src/i18n/locales/ko.ts +9 -0
- package/src/i18n/locales/nl.ts +10 -0
- package/src/i18n/locales/no.ts +10 -0
- package/src/i18n/locales/pl.ts +9 -0
- package/src/i18n/locales/pt.ts +10 -0
- package/src/i18n/locales/ru.ts +10 -0
- package/src/i18n/locales/sk.ts +10 -1
- package/src/i18n/locales/uk.ts +9 -0
- package/src/i18n/locales/uz.ts +9 -0
- package/src/i18n/locales/vi.ts +9 -0
- package/src/i18n/locales/zh-tw.ts +9 -0
- package/src/i18n/locales/zh.ts +9 -0
- package/src/index.ts +2 -0
- package/src/pm-nodes/BlockContainer.ts +4 -1
- package/src/pm-nodes/BlockGroup.ts +4 -1
- package/src/pm-nodes/Doc.ts +4 -1
- package/src/pm-nodes/suggestionMarks.ts +43 -0
- package/src/schema/blocks/createSpec.test.ts +123 -0
- package/src/schema/blocks/createSpec.ts +82 -24
- package/src/schema/blocks/extendBlockSpec.test.ts +188 -0
- package/src/schema/blocks/internal.ts +13 -43
- package/src/schema/blocks/types.ts +69 -22
- package/src/schema/contentTypePropagation.test.ts +182 -0
- package/src/schema/index.ts +1 -0
- package/src/schema/inlineContent/internal.ts +1 -1
- package/src/schema/inlineContent/types.ts +3 -3
- package/src/schema/markGroups.ts +50 -0
- package/src/user/UserStore.ts +199 -0
- package/src/user/createUserStore.test.ts +126 -0
- package/src/user/index.ts +2 -0
- package/src/user/userColors.ts +72 -0
- package/src/util/string.ts +1 -1
- package/src/util/topo-sort.test.ts +1 -1
- package/src/util/typescript.ts +2 -1
- package/src/vite-env.d.ts +1 -1
- package/src/y/README.md +5 -0
- package/src/{comments/threadstore/yjs → y/comments}/RESTYjsThreadStore.ts +8 -14
- package/src/y/comments/YjsThreadStore.test.ts +295 -0
- package/src/y/comments/YjsThreadStore.ts +358 -0
- package/src/y/comments/YjsThreadStoreBase.ts +50 -0
- package/src/y/comments/index.ts +3 -0
- package/src/y/comments/yjsHelpers.ts +125 -0
- package/src/y/extensions/AttributionExtension.test.ts +86 -0
- package/src/y/extensions/AttributionExtension.ts +378 -0
- package/src/y/extensions/DiffVersioningExtension.test.ts +193 -0
- package/src/y/extensions/DiffVersioningExtension.ts +228 -0
- package/src/y/extensions/ForkYDoc.test.ts +253 -0
- package/src/y/extensions/ForkYDoc.ts +108 -0
- package/src/y/extensions/RelativePositionMapping.test.ts +418 -0
- package/src/y/extensions/RelativePositionMapping.ts +49 -0
- package/src/y/extensions/Suggestions.ts +174 -0
- package/src/y/extensions/Versioning.test.ts +395 -0
- package/src/y/extensions/Versioning.ts +115 -0
- package/src/y/extensions/YAttributionMarks.ts +320 -0
- package/src/{extensions/Collaboration → y/extensions}/YCursorPlugin.ts +15 -7
- package/src/y/extensions/YSync.ts +125 -0
- package/src/y/extensions/blockMatchNodes.ts +182 -0
- package/src/y/extensions/index.ts +156 -0
- package/src/y/index.ts +4 -0
- package/src/y/utils.test.ts +1042 -0
- package/src/y/utils.ts +242 -0
- package/src/y/versioning/__test__/fixtures/activity-all-after.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-all-after.json +50 -0
- package/src/y/versioning/__test__/fixtures/activity-all.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-all.json +20 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.json +32 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-before.json +1 -0
- package/src/y/versioning/__test__/fixtures/changeset.bin +0 -0
- package/src/y/versioning/__test__/fixtures/patch-response.json +4 -0
- package/src/y/versioning/__test__/yhub.test.ts +752 -0
- package/src/y/versioning/index.ts +1 -0
- package/src/y/versioning/yhub.ts +631 -0
- package/src/yjs/README.md +5 -0
- package/src/yjs/comments/RESTYjsThreadStore.ts +166 -0
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.test.ts +3 -3
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.ts +7 -3
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStoreBase.ts +3 -3
- package/src/yjs/comments/index.ts +3 -0
- package/src/{comments/threadstore/yjs → yjs/comments}/yjsHelpers.ts +5 -1
- package/src/yjs/extensions/FixUpSchema.test.ts +421 -0
- package/src/yjs/extensions/FixUpSchema.ts +88 -0
- package/src/yjs/extensions/ForkYDoc.test.ts +216 -0
- package/src/{extensions/Collaboration → yjs/extensions}/ForkYDoc.ts +38 -57
- package/src/yjs/extensions/RelativePositionMapping.test.ts +418 -0
- package/src/yjs/extensions/RelativePositionMapping.ts +71 -0
- package/src/yjs/extensions/Versioning.test.ts +549 -0
- package/src/yjs/extensions/Versioning.ts +83 -0
- package/src/yjs/extensions/YCursorPlugin.ts +201 -0
- package/src/{extensions/Collaboration → yjs/extensions}/YSync.ts +1 -1
- package/src/yjs/extensions/index.ts +89 -0
- package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.test.ts +1 -1
- package/src/yjs/index.ts +2 -0
- package/src/yjs/utils.test.ts +5 -15
- package/src/yjs/utils.ts +36 -0
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +3 -1
- package/types/src/api/blockManipulation/selections/selection.d.ts +1 -1
- package/types/src/api/getBlockInfoFromPos.d.ts +5 -9
- package/types/src/api/nodeConversions/nodeToBlock.d.ts +4 -6
- package/types/src/api/pmUtil.d.ts +12 -1
- package/types/src/blocks/Audio/block.d.ts +2 -2
- package/types/src/blocks/Code/block.d.ts +2 -2
- package/types/src/blocks/File/block.d.ts +2 -2
- package/types/src/blocks/Heading/block.d.ts +21 -21
- package/types/src/blocks/Image/block.d.ts +3 -3
- package/types/src/blocks/ListItem/CheckListItem/block.d.ts +6 -6
- package/types/src/blocks/ListItem/NumberedListItem/block.d.ts +6 -6
- package/types/src/blocks/Video/block.d.ts +3 -3
- package/types/src/blocks/defaultBlocks.d.ts +17 -17
- package/types/src/comments/extension.d.ts +18 -5
- package/types/src/comments/index.d.ts +0 -3
- package/types/src/comments/threadstore/ThreadStore.d.ts +4 -8
- package/types/src/comments/types.d.ts +0 -8
- package/types/src/editor/BlockNoteEditor.d.ts +8 -9
- package/types/src/editor/managers/BlockManager.d.ts +1 -1
- package/types/src/editor/managers/ExtensionManager/extensions.d.ts +2 -2
- package/types/src/editor/managers/ExtensionManager/index.d.ts +13 -0
- package/types/src/editor/managers/SelectionManager.d.ts +1 -1
- package/types/src/extensions/PositionMapping/PositionMapping.d.ts +4 -0
- package/types/src/extensions/TableHandles/TableHandles.d.ts +6 -6
- package/types/src/extensions/Versioning/Versioning.d.ts +352 -0
- package/types/src/extensions/Versioning/Versioning.test.d.ts +1 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.d.ts +37 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.test.d.ts +1 -0
- package/types/src/extensions/Versioning/index.d.ts +2 -0
- package/types/src/extensions/index.d.ts +6 -9
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.d.ts +1 -0
- package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.d.ts +6 -1
- package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.d.ts +4 -0
- package/types/src/extensions/tiptap-extensions/index.d.ts +1 -5
- package/types/src/i18n/locales/en.d.ts +9 -1
- package/types/src/i18n/locales/fa.d.ts +9 -1
- package/types/src/i18n/locales/sk.d.ts +9 -1
- package/types/src/index.d.ts +2 -0
- package/types/src/pm-nodes/suggestionMarks.d.ts +26 -0
- package/types/src/schema/blocks/createSpec.d.ts +4 -4
- package/types/src/schema/blocks/createSpec.test.d.ts +1 -0
- package/types/src/schema/blocks/extendBlockSpec.test.d.ts +1 -0
- package/types/src/schema/blocks/internal.d.ts +5 -7
- package/types/src/schema/blocks/types.d.ts +22 -14
- package/types/src/schema/contentTypePropagation.test.d.ts +1 -0
- package/types/src/schema/index.d.ts +1 -0
- package/types/src/schema/inlineContent/types.d.ts +3 -3
- package/types/src/schema/markGroups.d.ts +33 -0
- package/types/src/user/UserStore.d.ts +105 -0
- package/types/src/user/createUserStore.test.d.ts +1 -0
- package/types/src/user/index.d.ts +2 -0
- package/types/src/user/userColors.d.ts +36 -0
- package/types/src/y/comments/RESTYjsThreadStore.d.ts +77 -0
- package/types/src/y/comments/YjsThreadStore.d.ts +79 -0
- package/types/src/y/comments/YjsThreadStore.test.d.ts +1 -0
- package/types/src/y/comments/YjsThreadStoreBase.d.ts +15 -0
- package/types/src/y/comments/index.d.ts +3 -0
- package/types/src/y/comments/yjsHelpers.d.ts +13 -0
- package/types/src/y/extensions/AttributionExtension.d.ts +74 -0
- package/types/src/y/extensions/AttributionExtension.test.d.ts +1 -0
- package/types/src/y/extensions/DiffVersioningExtension.d.ts +69 -0
- package/types/src/y/extensions/DiffVersioningExtension.test.d.ts +1 -0
- package/types/src/{extensions/Collaboration → y/extensions}/ForkYDoc.d.ts +4 -2
- package/types/src/y/extensions/ForkYDoc.test.d.ts +1 -0
- package/types/src/y/extensions/RelativePositionMapping.d.ts +4 -0
- package/types/src/y/extensions/RelativePositionMapping.test.d.ts +1 -0
- package/types/src/y/extensions/Suggestions.d.ts +36 -0
- package/types/src/y/extensions/Versioning.d.ts +17 -0
- package/types/src/y/extensions/Versioning.test.d.ts +1 -0
- package/types/src/y/extensions/YAttributionMarks.d.ts +67 -0
- package/types/src/y/extensions/YCursorPlugin.d.ts +14 -0
- package/types/src/y/extensions/YSync.d.ts +32 -0
- package/types/src/y/extensions/blockMatchNodes.d.ts +25 -0
- package/types/src/y/extensions/index.d.ts +189 -0
- package/types/src/y/index.d.ts +4 -0
- package/types/src/y/utils.d.ts +82 -0
- package/types/src/y/utils.test.d.ts +1 -0
- package/types/src/y/versioning/__test__/yhub.test.d.ts +1 -0
- package/types/src/y/versioning/index.d.ts +1 -0
- package/types/src/y/versioning/yhub.d.ts +87 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/RESTYjsThreadStore.d.ts +6 -10
- package/types/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.d.ts +3 -3
- package/types/src/yjs/comments/YjsThreadStore.test.d.ts +1 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStoreBase.d.ts +3 -3
- package/types/src/yjs/comments/index.d.ts +3 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/yjsHelpers.d.ts +1 -1
- package/types/src/yjs/extensions/FixUpSchema.d.ts +3 -0
- package/types/src/yjs/extensions/FixUpSchema.test.d.ts +1 -0
- package/types/src/yjs/extensions/ForkYDoc.d.ts +27 -0
- package/types/src/yjs/extensions/ForkYDoc.test.d.ts +1 -0
- package/types/src/yjs/extensions/RelativePositionMapping.d.ts +4 -0
- package/types/src/yjs/extensions/RelativePositionMapping.test.d.ts +1 -0
- package/types/src/yjs/extensions/Versioning.d.ts +26 -0
- package/types/src/yjs/extensions/Versioning.test.d.ts +1 -0
- package/types/src/{extensions/Collaboration → yjs/extensions}/YCursorPlugin.d.ts +5 -2
- package/types/src/{extensions/Collaboration → yjs/extensions}/YSync.d.ts +1 -1
- package/types/src/{extensions/Collaboration/Collaboration.d.ts → yjs/extensions/index.d.ts} +36 -15
- package/types/src/yjs/extensions/schemaMigration/migrationRules/moveColorAttributes.test.d.ts +1 -0
- package/types/src/yjs/index.d.ts +2 -0
- package/types/src/yjs/utils.d.ts +5 -0
- package/dist/BlockNoteExtension-B6RhuQ3V.js +0 -27
- package/dist/BlockNoteExtension-B6RhuQ3V.js.map +0 -1
- package/dist/BlockNoteExtension-ab0REuob.cjs +0 -2
- package/dist/BlockNoteExtension-ab0REuob.cjs.map +0 -1
- package/dist/EventEmitter-CuPnGDYt.js +0 -22
- package/dist/EventEmitter-CuPnGDYt.js.map +0 -1
- package/dist/EventEmitter-DHdSnYCD.cjs +0 -2
- package/dist/EventEmitter-DHdSnYCD.cjs.map +0 -1
- package/dist/ShowSelection-BsHFfdMi.js +0 -29
- package/dist/ShowSelection-BsHFfdMi.js.map +0 -1
- package/dist/ShowSelection-DhXglbt8.cjs +0 -2
- package/dist/ShowSelection-DhXglbt8.cjs.map +0 -1
- package/dist/blocks-Bm6IfL1R.cjs +0 -11
- package/dist/blocks-Bm6IfL1R.cjs.map +0 -1
- package/dist/blocks-DGsP5WKr.js.map +0 -1
- package/dist/en-B9hMApn4.js.map +0 -1
- package/dist/en-Cj5r8sW_.cjs.map +0 -1
- package/dist/extensions-Co4y7P63.js.map +0 -1
- package/dist/extensions-IJK3t0sz.cjs +0 -52
- package/dist/extensions-IJK3t0sz.cjs.map +0 -1
- package/dist/src-B6rlChSc.cjs +0 -21
- package/dist/src-B6rlChSc.cjs.map +0 -1
- package/dist/src-Bcud0PIg.js.map +0 -1
- package/src/comments/userstore/UserStore.ts +0 -72
- package/src/extensions/Collaboration/Collaboration.ts +0 -55
- package/src/extensions/Collaboration/ForkYDoc.test.ts +0 -179
- package/src/extensions/tiptap-extensions/Suggestions/SuggestionMarks.ts +0 -175
- package/types/src/comments/userstore/UserStore.d.ts +0 -31
- package/types/src/extensions/tiptap-extensions/Suggestions/SuggestionMarks.d.ts +0 -4
- /package/src/{extensions/Collaboration → yjs/extensions}/YUndo.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-editor-forked.json +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-editor.json +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-forked.html +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap.html +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/SchemaMigration.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/index.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/migrationRule.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.ts +0 -0
- /package/types/src/{comments/threadstore/yjs/YjsThreadStore.test.d.ts → api/getBlockInfoFromPos.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration/ForkYDoc.test.d.ts → api/nodeConversions/blockToNode.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.test.d.ts → editor/managers/ExtensionManager/ExtensionManager.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/YUndo.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/SchemaMigration.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/index.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/migrationRule.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.d.ts +0 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { describe, expect, it } from "vite-plus/test";
|
|
2
|
+
|
|
3
|
+
import { BlockNoteSchema } from "../../blocks/BlockNoteSchema.js";
|
|
4
|
+
import { defaultBlockSpecs } from "../../blocks/defaultBlocks.js";
|
|
5
|
+
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
6
|
+
import { YAttributionMarksExtension } from "../../y/extensions/YAttributionMarks.js";
|
|
7
|
+
import { createBlockConfig, createBlockSpec } from "../index.js";
|
|
8
|
+
|
|
9
|
+
// A minimal "plain" content block WITHOUT a custom `parseContent`, so parsing
|
|
10
|
+
// its HTML exercises the generic plain branch in `getParseRules`' `getContent`.
|
|
11
|
+
const customPlain = createBlockSpec(
|
|
12
|
+
createBlockConfig(() => ({
|
|
13
|
+
type: "customPlain" as const,
|
|
14
|
+
propSchema: {},
|
|
15
|
+
content: "plain" as const,
|
|
16
|
+
})),
|
|
17
|
+
{
|
|
18
|
+
parse: (el) => (el.classList?.contains("custom-plain") ? {} : undefined),
|
|
19
|
+
render: () => {
|
|
20
|
+
const dom = document.createElement("div");
|
|
21
|
+
return { dom, contentDOM: dom };
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
)();
|
|
25
|
+
|
|
26
|
+
const createEditor = () =>
|
|
27
|
+
BlockNoteEditor.create({
|
|
28
|
+
schema: BlockNoteSchema.create({
|
|
29
|
+
blockSpecs: { ...defaultBlockSpecs, customPlain },
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("plain content parsing", () => {
|
|
34
|
+
it("keeps text and drops formatting marks", () => {
|
|
35
|
+
const editor = createEditor();
|
|
36
|
+
|
|
37
|
+
const blocks = editor.tryParseHTMLToBlocks(
|
|
38
|
+
`<div class="custom-plain">hello <b>world</b></div>`,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
expect(blocks[0].type).toBe("customPlain");
|
|
42
|
+
expect(blocks[0].content).toEqual([
|
|
43
|
+
{
|
|
44
|
+
styles: {},
|
|
45
|
+
text: "hello world",
|
|
46
|
+
type: "text",
|
|
47
|
+
},
|
|
48
|
+
]);
|
|
49
|
+
editor._tiptapEditor.destroy();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("merges multiple paragraphs with newlines", () => {
|
|
53
|
+
const editor = createEditor();
|
|
54
|
+
|
|
55
|
+
const blocks = editor.tryParseHTMLToBlocks(
|
|
56
|
+
`<div class="custom-plain"><p>first</p><p>second</p></div>`,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
expect(blocks[0].type).toBe("customPlain");
|
|
60
|
+
expect(blocks[0].content).toEqual([
|
|
61
|
+
{
|
|
62
|
+
styles: {},
|
|
63
|
+
text: "first\nsecond",
|
|
64
|
+
type: "text",
|
|
65
|
+
},
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
editor._tiptapEditor.destroy();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("converts line breaks to newline characters", () => {
|
|
72
|
+
const editor = createEditor();
|
|
73
|
+
|
|
74
|
+
const blocks = editor.tryParseHTMLToBlocks(
|
|
75
|
+
`<div class="custom-plain">first<br>second</div>`,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
expect(blocks[0].type).toBe("customPlain");
|
|
79
|
+
expect(blocks[0].content).toEqual([
|
|
80
|
+
{
|
|
81
|
+
styles: {},
|
|
82
|
+
text: "first\nsecond",
|
|
83
|
+
type: "text",
|
|
84
|
+
},
|
|
85
|
+
]);
|
|
86
|
+
|
|
87
|
+
editor._tiptapEditor.destroy();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("keeps allowed (non-formatting) marks while dropping formatting", () => {
|
|
91
|
+
// Every non-formatting mark comes from an optional extension. The Yjs
|
|
92
|
+
// attribution marks are the ones reachable from core, so they stand in for
|
|
93
|
+
// the `"annotation"` group here; register them so the group is non-empty.
|
|
94
|
+
const editor = BlockNoteEditor.create({
|
|
95
|
+
schema: BlockNoteSchema.create({
|
|
96
|
+
blockSpecs: { ...defaultBlockSpecs, customPlain },
|
|
97
|
+
}),
|
|
98
|
+
extensions: [YAttributionMarksExtension()],
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const plainType = editor.pmSchema.nodes["customPlain"];
|
|
102
|
+
const insertMark = editor.pmSchema.marks["y-attributed-insert"];
|
|
103
|
+
const boldMark = editor.pmSchema.marks["bold"];
|
|
104
|
+
|
|
105
|
+
// The plain block allows the non-formatting mark but not the formatting one.
|
|
106
|
+
expect(plainType.allowsMarkType(insertMark)).toBe(true);
|
|
107
|
+
expect(plainType.allowsMarkType(boldMark)).toBe(false);
|
|
108
|
+
|
|
109
|
+
// ...and so `allowedMarks` keeps the former while dropping the latter.
|
|
110
|
+
const markNames = new Set(
|
|
111
|
+
plainType
|
|
112
|
+
.allowedMarks([
|
|
113
|
+
insertMark.create({ userIds: ["test-user"] }),
|
|
114
|
+
boldMark.create(),
|
|
115
|
+
])
|
|
116
|
+
.map((m) => m.type.name),
|
|
117
|
+
);
|
|
118
|
+
expect(markNames.has("y-attributed-insert")).toBe(true);
|
|
119
|
+
expect(markNames.has("bold")).toBe(false);
|
|
120
|
+
|
|
121
|
+
editor._tiptapEditor.destroy();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { Editor, Node } from "@tiptap/core";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
DOMParser,
|
|
4
|
+
Fragment,
|
|
5
|
+
Node as PMNode,
|
|
6
|
+
TagParseRule,
|
|
7
|
+
} from "@tiptap/pm/model";
|
|
3
8
|
import { NodeView } from "@tiptap/pm/view";
|
|
4
9
|
import { mergeParagraphs } from "../../blocks/defaultBlockHelpers.js";
|
|
5
10
|
import {
|
|
6
11
|
Extension,
|
|
7
12
|
ExtensionFactoryInstance,
|
|
8
13
|
} from "../../editor/BlockNoteExtension.js";
|
|
14
|
+
import { nonFormattingMarks } from "../markGroups.js";
|
|
9
15
|
import { PropSchema } from "../propTypes.js";
|
|
10
16
|
import {
|
|
11
17
|
getBlockFromPos,
|
|
@@ -44,7 +50,7 @@ export function applyNonSelectableBlockFix(nodeView: NodeView, editor: Editor) {
|
|
|
44
50
|
export function getParseRules<
|
|
45
51
|
TName extends string,
|
|
46
52
|
TProps extends PropSchema,
|
|
47
|
-
TContent extends "inline" | "none" | "table",
|
|
53
|
+
TContent extends "inline" | "none" | "table" | "plain",
|
|
48
54
|
>(
|
|
49
55
|
config: BlockConfig<TName, TProps, TContent>,
|
|
50
56
|
implementation: BlockImplementation<TName, TProps, TContent>,
|
|
@@ -75,7 +81,9 @@ export function getParseRules<
|
|
|
75
81
|
// Because we do the parsing ourselves, we want to preserve whitespace for content we've parsed
|
|
76
82
|
preserveWhitespace: true,
|
|
77
83
|
getContent:
|
|
78
|
-
config.content === "inline" ||
|
|
84
|
+
config.content === "inline" ||
|
|
85
|
+
config.content === "none" ||
|
|
86
|
+
config.content === "plain"
|
|
79
87
|
? (node, schema) => {
|
|
80
88
|
if (implementation.parseContent) {
|
|
81
89
|
const result = implementation.parseContent({
|
|
@@ -89,7 +97,7 @@ export function getParseRules<
|
|
|
89
97
|
}
|
|
90
98
|
}
|
|
91
99
|
|
|
92
|
-
if (config.content === "inline") {
|
|
100
|
+
if (config.content === "inline" || config.content === "plain") {
|
|
93
101
|
// Parse the inline content if it exists
|
|
94
102
|
const element = node as HTMLElement;
|
|
95
103
|
|
|
@@ -99,7 +107,9 @@ export function getParseRules<
|
|
|
99
107
|
// Merge multiple paragraphs into one with line breaks
|
|
100
108
|
mergeParagraphs(
|
|
101
109
|
clone,
|
|
102
|
-
|
|
110
|
+
config.content === "plain" || implementation.meta?.code
|
|
111
|
+
? "\n"
|
|
112
|
+
: "<br>",
|
|
103
113
|
);
|
|
104
114
|
|
|
105
115
|
// Parse the content directly as a paragraph to extract inline content
|
|
@@ -109,6 +119,27 @@ export function getParseRules<
|
|
|
109
119
|
preserveWhitespace: true,
|
|
110
120
|
});
|
|
111
121
|
|
|
122
|
+
if (config.content === "plain") {
|
|
123
|
+
// Plain blocks hold text only, so non-text inline nodes are
|
|
124
|
+
// flattened: line breaks become newline characters and other
|
|
125
|
+
// nodes (e.g. mentions) are kept as their text.
|
|
126
|
+
const textNodes: PMNode[] = [];
|
|
127
|
+
parsed.content.forEach((child) => {
|
|
128
|
+
if (child.isText) {
|
|
129
|
+
textNodes.push(child);
|
|
130
|
+
} else {
|
|
131
|
+
const text =
|
|
132
|
+
child.type === schema.linebreakReplacement
|
|
133
|
+
? "\n"
|
|
134
|
+
: child.textContent;
|
|
135
|
+
if (text) {
|
|
136
|
+
textNodes.push(schema.text(text, child.marks));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
return Fragment.fromArray(textNodes);
|
|
142
|
+
}
|
|
112
143
|
return parsed.content;
|
|
113
144
|
}
|
|
114
145
|
return Fragment.empty;
|
|
@@ -140,7 +171,7 @@ export function getParseRules<
|
|
|
140
171
|
export function addNodeAndExtensionsToSpec<
|
|
141
172
|
TName extends string,
|
|
142
173
|
TProps extends PropSchema,
|
|
143
|
-
TContent extends "inline" | "none" | "table",
|
|
174
|
+
TContent extends "inline" | "none" | "table" | "plain",
|
|
144
175
|
>(
|
|
145
176
|
blockConfig: BlockConfig<TName, TProps, TContent>,
|
|
146
177
|
blockImplementation: BlockImplementation<TName, TProps, TContent>,
|
|
@@ -153,9 +184,26 @@ export function addNodeAndExtensionsToSpec<
|
|
|
153
184
|
name: blockConfig.type,
|
|
154
185
|
content: (blockConfig.content === "inline"
|
|
155
186
|
? "inline*"
|
|
156
|
-
: blockConfig.content === "
|
|
157
|
-
? ""
|
|
158
|
-
: blockConfig.content
|
|
187
|
+
: blockConfig.content === "plain"
|
|
188
|
+
? "text*"
|
|
189
|
+
: blockConfig.content === "none"
|
|
190
|
+
? ""
|
|
191
|
+
: blockConfig.content) as TContent extends "inline"
|
|
192
|
+
? "inline*"
|
|
193
|
+
: TContent extends "plain"
|
|
194
|
+
? "text*"
|
|
195
|
+
: "",
|
|
196
|
+
// "plain" blocks hold unstyled text, so they disallow formatting marks.
|
|
197
|
+
// They still allow the non-formatting marks (comments and
|
|
198
|
+
// suggestions/diffs) — those annotate content without changing it and are
|
|
199
|
+
// ignored by the block model. `nonFormattingMarks` resolves the group only
|
|
200
|
+
// when at least one such mark is registered, so a plain block in an editor
|
|
201
|
+
// without any of them doesn't reference an empty (unknown) mark group.
|
|
202
|
+
marks() {
|
|
203
|
+
return blockConfig.content === "plain"
|
|
204
|
+
? nonFormattingMarks(this.editor)
|
|
205
|
+
: undefined;
|
|
206
|
+
},
|
|
159
207
|
group: "blockContent",
|
|
160
208
|
selectable: blockImplementation.meta?.selectable ?? true,
|
|
161
209
|
isolating: blockImplementation.meta?.isolating ?? true,
|
|
@@ -180,7 +228,11 @@ export function addNodeAndExtensionsToSpec<
|
|
|
180
228
|
return wrapInBlockStructure(
|
|
181
229
|
{
|
|
182
230
|
dom: div,
|
|
183
|
-
contentDOM:
|
|
231
|
+
contentDOM:
|
|
232
|
+
blockConfig.content === "inline" ||
|
|
233
|
+
blockConfig.content === "plain"
|
|
234
|
+
? div
|
|
235
|
+
: undefined,
|
|
184
236
|
},
|
|
185
237
|
blockConfig.type,
|
|
186
238
|
{},
|
|
@@ -195,18 +247,18 @@ export function addNodeAndExtensionsToSpec<
|
|
|
195
247
|
// Gets the BlockNote editor instance
|
|
196
248
|
const editor = this.options.editor;
|
|
197
249
|
// Gets the block
|
|
198
|
-
const block = getBlockFromPos(
|
|
199
|
-
props.getPos,
|
|
200
|
-
editor,
|
|
201
|
-
this.editor,
|
|
202
|
-
blockConfig.type,
|
|
203
|
-
);
|
|
250
|
+
const block = getBlockFromPos(props.getPos, props.view.state.doc);
|
|
204
251
|
// Gets the custom HTML attributes for `blockContent` nodes
|
|
205
252
|
const blockContentDOMAttributes =
|
|
206
253
|
this.options.domAttributes?.blockContent || {};
|
|
207
254
|
|
|
208
255
|
const nodeView = blockImplementation.render.call(
|
|
209
|
-
{
|
|
256
|
+
{
|
|
257
|
+
blockContentDOMAttributes,
|
|
258
|
+
props,
|
|
259
|
+
renderType: "nodeView",
|
|
260
|
+
propSchema: blockConfig.propSchema,
|
|
261
|
+
},
|
|
210
262
|
block as any,
|
|
211
263
|
editor as any,
|
|
212
264
|
);
|
|
@@ -248,6 +300,7 @@ export function addNodeAndExtensionsToSpec<
|
|
|
248
300
|
blockContentDOMAttributes,
|
|
249
301
|
props: undefined,
|
|
250
302
|
renderType: "dom",
|
|
303
|
+
propSchema: blockConfig.propSchema,
|
|
251
304
|
},
|
|
252
305
|
block as any,
|
|
253
306
|
editor as any,
|
|
@@ -261,13 +314,18 @@ export function addNodeAndExtensionsToSpec<
|
|
|
261
314
|
|
|
262
315
|
return (
|
|
263
316
|
blockImplementation.toExternalHTML?.call(
|
|
264
|
-
{ blockContentDOMAttributes },
|
|
317
|
+
{ blockContentDOMAttributes, propSchema: blockConfig.propSchema },
|
|
265
318
|
block as any,
|
|
266
319
|
editor as any,
|
|
267
320
|
context,
|
|
268
321
|
) ??
|
|
269
322
|
blockImplementation.render.call(
|
|
270
|
-
{
|
|
323
|
+
{
|
|
324
|
+
blockContentDOMAttributes,
|
|
325
|
+
renderType: "dom",
|
|
326
|
+
props: undefined,
|
|
327
|
+
propSchema: blockConfig.propSchema,
|
|
328
|
+
},
|
|
271
329
|
block as any,
|
|
272
330
|
editor as any,
|
|
273
331
|
)
|
|
@@ -304,7 +362,7 @@ export function createBlockConfig<
|
|
|
304
362
|
export function createBlockSpec<
|
|
305
363
|
const TName extends string,
|
|
306
364
|
const TProps extends PropSchema,
|
|
307
|
-
const TContent extends "inline" | "none",
|
|
365
|
+
const TContent extends "inline" | "none" | "plain",
|
|
308
366
|
const TOptions extends Partial<Record<string, any>> | undefined = undefined,
|
|
309
367
|
>(
|
|
310
368
|
blockConfigOrCreator: BlockConfig<TName, TProps, TContent>,
|
|
@@ -323,7 +381,7 @@ export function createBlockSpec<
|
|
|
323
381
|
export function createBlockSpec<
|
|
324
382
|
const TName extends string,
|
|
325
383
|
const TProps extends PropSchema,
|
|
326
|
-
const TContent extends "inline" | "none",
|
|
384
|
+
const TContent extends "inline" | "none" | "plain",
|
|
327
385
|
const BlockConf extends BlockConfig<TName, TProps, TContent>,
|
|
328
386
|
const TOptions extends Partial<Record<string, any>>,
|
|
329
387
|
>(
|
|
@@ -349,7 +407,7 @@ export function createBlockSpec<
|
|
|
349
407
|
export function createBlockSpec<
|
|
350
408
|
const TName extends string,
|
|
351
409
|
const TProps extends PropSchema,
|
|
352
|
-
const TContent extends "inline" | "none",
|
|
410
|
+
const TContent extends "inline" | "none" | "plain",
|
|
353
411
|
const TOptions extends Partial<Record<string, any>> | undefined = undefined,
|
|
354
412
|
>(
|
|
355
413
|
blockConfigOrCreator: BlockConfigOrCreator<TName, TProps, TContent, TOptions>,
|
|
@@ -404,7 +462,7 @@ export function createBlockSpec<
|
|
|
404
462
|
output,
|
|
405
463
|
block.type,
|
|
406
464
|
block.props,
|
|
407
|
-
blockConfig.propSchema,
|
|
465
|
+
this.propSchema ?? blockConfig.propSchema,
|
|
408
466
|
blockImplementation.meta?.fileBlockAccept !== undefined,
|
|
409
467
|
);
|
|
410
468
|
},
|
|
@@ -423,7 +481,7 @@ export function createBlockSpec<
|
|
|
423
481
|
output,
|
|
424
482
|
block.type,
|
|
425
483
|
block.props,
|
|
426
|
-
blockConfig.propSchema,
|
|
484
|
+
this.propSchema ?? blockConfig.propSchema,
|
|
427
485
|
blockImplementation.meta?.fileBlockAccept !== undefined,
|
|
428
486
|
this.blockContentDOMAttributes,
|
|
429
487
|
) satisfies NodeView;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from "vite-plus/test";
|
|
2
|
+
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
3
|
+
import { BlockNoteSchema } from "../../blocks/BlockNoteSchema.js";
|
|
4
|
+
import { defaultBlockSpecs } from "../../blocks/defaultBlocks.js";
|
|
5
|
+
import { createParagraphBlockSpec } from "../../blocks/Paragraph/block.js";
|
|
6
|
+
import { createHeadingBlockSpec } from "../../blocks/Heading/block.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @vitest-environment jsdom
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const editorsToCleanup: BlockNoteEditor<any, any, any>[] = [];
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
for (const editor of editorsToCleanup) {
|
|
16
|
+
editor.unmount();
|
|
17
|
+
}
|
|
18
|
+
editorsToCleanup.length = 0;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
function withMetadata<
|
|
22
|
+
T extends { config: { propSchema: Record<string, unknown> } },
|
|
23
|
+
>(spec: T): T {
|
|
24
|
+
return {
|
|
25
|
+
...spec,
|
|
26
|
+
config: {
|
|
27
|
+
...spec.config,
|
|
28
|
+
propSchema: {
|
|
29
|
+
...spec.config.propSchema,
|
|
30
|
+
metadata: { default: "" },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
} as T;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function createExtendedSchema() {
|
|
37
|
+
return BlockNoteSchema.create({
|
|
38
|
+
blockSpecs: Object.fromEntries(
|
|
39
|
+
Object.entries(defaultBlockSpecs).map(([key, spec]) => [
|
|
40
|
+
key,
|
|
41
|
+
withMetadata(spec),
|
|
42
|
+
]),
|
|
43
|
+
) as typeof defaultBlockSpecs,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function createExtendedEditor() {
|
|
48
|
+
const editor = BlockNoteEditor.create({ schema: createExtendedSchema() });
|
|
49
|
+
editorsToCleanup.push(editor);
|
|
50
|
+
return editor;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe("extending default block specs with additional props", () => {
|
|
54
|
+
it("creates an editor with an extended paragraph prop without crashing", () => {
|
|
55
|
+
const paragraph = createParagraphBlockSpec();
|
|
56
|
+
const schema = BlockNoteSchema.create({
|
|
57
|
+
blockSpecs: {
|
|
58
|
+
...defaultBlockSpecs,
|
|
59
|
+
paragraph: {
|
|
60
|
+
...paragraph,
|
|
61
|
+
config: {
|
|
62
|
+
...paragraph.config,
|
|
63
|
+
propSchema: {
|
|
64
|
+
...paragraph.config.propSchema,
|
|
65
|
+
metadata: { default: "" },
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const editor = BlockNoteEditor.create({ schema });
|
|
73
|
+
editorsToCleanup.push(editor);
|
|
74
|
+
|
|
75
|
+
expect(editor.document[0].type).toBe("paragraph");
|
|
76
|
+
expect((editor.document[0].props as any).metadata).toBe("");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("creates an editor using a helper that extends all block specs", () => {
|
|
80
|
+
const editor = createExtendedEditor();
|
|
81
|
+
|
|
82
|
+
expect(editor.document[0].type).toBe("paragraph");
|
|
83
|
+
expect((editor.document[0].props as any).metadata).toBe("");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("can update the extended prop on a block", () => {
|
|
87
|
+
const editor = createExtendedEditor();
|
|
88
|
+
|
|
89
|
+
editor.updateBlock(editor.document[0], {
|
|
90
|
+
props: { metadata: '{"source":"xwiki"}' } as any,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
expect((editor.document[0].props as any).metadata).toBe(
|
|
94
|
+
'{"source":"xwiki"}',
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("renders the extended prop in full HTML export", () => {
|
|
99
|
+
const editor = createExtendedEditor();
|
|
100
|
+
|
|
101
|
+
editor.updateBlock(editor.document[0], {
|
|
102
|
+
props: { metadata: "test-value" } as any,
|
|
103
|
+
content: "Hello",
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const html = editor.blocksToFullHTML(editor.document);
|
|
107
|
+
expect(html).toContain('data-metadata="test-value"');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("does not render the extended prop when it equals the default", () => {
|
|
111
|
+
const editor = createExtendedEditor();
|
|
112
|
+
|
|
113
|
+
editor.updateBlock(editor.document[0], {
|
|
114
|
+
content: "Hello",
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const html = editor.blocksToFullHTML(editor.document);
|
|
118
|
+
expect(html).not.toContain("data-metadata");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("works when extending only specific block types", () => {
|
|
122
|
+
const paragraph = createParagraphBlockSpec();
|
|
123
|
+
const heading = createHeadingBlockSpec();
|
|
124
|
+
|
|
125
|
+
const schema = BlockNoteSchema.create({
|
|
126
|
+
blockSpecs: {
|
|
127
|
+
...defaultBlockSpecs,
|
|
128
|
+
paragraph: withMetadata(paragraph),
|
|
129
|
+
heading: withMetadata(heading),
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const editor = BlockNoteEditor.create({ schema });
|
|
134
|
+
editorsToCleanup.push(editor);
|
|
135
|
+
|
|
136
|
+
editor.replaceBlocks(editor.document, [
|
|
137
|
+
{
|
|
138
|
+
type: "paragraph",
|
|
139
|
+
content: "Text",
|
|
140
|
+
props: { metadata: "p-meta" } as any,
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
type: "heading",
|
|
144
|
+
content: "Title",
|
|
145
|
+
props: { metadata: "h-meta", level: 1 } as any,
|
|
146
|
+
},
|
|
147
|
+
{ type: "bulletListItem", content: "Item" },
|
|
148
|
+
]);
|
|
149
|
+
|
|
150
|
+
expect((editor.document[0].props as any).metadata).toBe("p-meta");
|
|
151
|
+
expect((editor.document[1].props as any).metadata).toBe("h-meta");
|
|
152
|
+
expect(editor.document[2].props).not.toHaveProperty("metadata");
|
|
153
|
+
|
|
154
|
+
const html = editor.blocksToFullHTML(editor.document);
|
|
155
|
+
expect(html).toContain('data-metadata="p-meta"');
|
|
156
|
+
expect(html).toContain('data-metadata="h-meta"');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("round-trips extended props through full HTML export and parse", () => {
|
|
160
|
+
const editor = createExtendedEditor();
|
|
161
|
+
|
|
162
|
+
editor.updateBlock(editor.document[0], {
|
|
163
|
+
props: { metadata: '{"key":"value"}' } as any,
|
|
164
|
+
content: "Round trip test",
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const html = editor.blocksToFullHTML(editor.document);
|
|
168
|
+
const parsed = editor.tryParseHTMLToBlocks(html);
|
|
169
|
+
|
|
170
|
+
expect((parsed[0].props as any).metadata).toBe('{"key":"value"}');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("mounts the editor to a DOM element without crashing", () => {
|
|
174
|
+
const editor = createExtendedEditor();
|
|
175
|
+
|
|
176
|
+
const container = document.createElement("div");
|
|
177
|
+
editor.mount(container);
|
|
178
|
+
|
|
179
|
+
expect(container.innerHTML).toContain("bn-block-content");
|
|
180
|
+
|
|
181
|
+
editor.updateBlock(editor.document[0], {
|
|
182
|
+
props: { metadata: "mounted-test" } as any,
|
|
183
|
+
content: "Mounted",
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
expect((editor.document[0].props as any).metadata).toBe("mounted-test");
|
|
187
|
+
});
|
|
188
|
+
});
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import { Attribute, Attributes,
|
|
1
|
+
import { Attribute, Attributes, Node } from "@tiptap/core";
|
|
2
|
+
import type { Node as PMNode } from "prosemirror-model";
|
|
3
|
+
import { nodeToBlock } from "../../api/nodeConversions/nodeToBlock.js";
|
|
2
4
|
import { defaultBlockToHTML } from "../../blocks/defaultBlockHelpers.js";
|
|
3
|
-
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
4
5
|
import type { ExtensionFactoryInstance } from "../../editor/BlockNoteExtension.js";
|
|
5
6
|
import { mergeCSSClasses } from "../../util/browser.js";
|
|
6
7
|
import { camelToDataKebab } from "../../util/string.js";
|
|
7
|
-
import { InlineContentSchema } from "../inlineContent/types.js";
|
|
8
8
|
import { PropSchema, Props } from "../propTypes.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
BlockConfig,
|
|
12
|
-
BlockSchemaWithBlock,
|
|
13
|
-
LooseBlockSpec,
|
|
14
|
-
SpecificBlock,
|
|
15
|
-
} from "./types.js";
|
|
9
|
+
import { LooseBlockSpec } from "./types.js";
|
|
16
10
|
|
|
17
11
|
// Function that uses the 'propSchema' of a blockConfig to create a TipTap
|
|
18
12
|
// node's `addAttributes` property.
|
|
@@ -82,43 +76,20 @@ export function propsToAttributes(propSchema: PropSchema): Attributes {
|
|
|
82
76
|
|
|
83
77
|
// Used to figure out which block should be rendered. This block is then used to
|
|
84
78
|
// create the node view.
|
|
85
|
-
export function getBlockFromPos
|
|
86
|
-
|
|
87
|
-
Config extends BlockConfig,
|
|
88
|
-
BSchema extends BlockSchemaWithBlock<BType, Config>,
|
|
89
|
-
I extends InlineContentSchema,
|
|
90
|
-
S extends StyleSchema,
|
|
91
|
-
>(
|
|
92
|
-
getPos: () => number | undefined,
|
|
93
|
-
editor: BlockNoteEditor<BSchema, I, S>,
|
|
94
|
-
tipTapEditor: Editor,
|
|
95
|
-
type: BType,
|
|
96
|
-
) {
|
|
79
|
+
export function getBlockFromPos(getPos: () => number | undefined, doc: PMNode) {
|
|
80
|
+
// TODO is there a cleaner implementation of this? Probably...
|
|
97
81
|
const pos = getPos();
|
|
98
82
|
// Gets position of the node
|
|
99
83
|
if (pos === undefined) {
|
|
100
84
|
throw new Error("Cannot find node position");
|
|
101
85
|
}
|
|
102
|
-
// Gets parent blockContainer node
|
|
103
|
-
const blockContainer = tipTapEditor.state.doc.resolve(pos!).node();
|
|
104
|
-
// Gets block identifier
|
|
105
|
-
const blockIdentifier = blockContainer.attrs.id;
|
|
106
86
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// Gets the block
|
|
112
|
-
const block = editor.getBlock(blockIdentifier)! as SpecificBlock<
|
|
113
|
-
BSchema,
|
|
114
|
-
BType,
|
|
115
|
-
I,
|
|
116
|
-
S
|
|
117
|
-
>;
|
|
118
|
-
if (block.type !== type) {
|
|
119
|
-
throw new Error("Block type does not match");
|
|
87
|
+
// Gets parent blockContainer node
|
|
88
|
+
const blockContainer = doc.resolve(pos).node();
|
|
89
|
+
if (!blockContainer) {
|
|
90
|
+
throw new Error("Cannot find block container");
|
|
120
91
|
}
|
|
121
|
-
|
|
92
|
+
const block = nodeToBlock(blockContainer, doc);
|
|
122
93
|
return block;
|
|
123
94
|
}
|
|
124
95
|
|
|
@@ -168,8 +139,7 @@ export function wrapInBlockStructure<
|
|
|
168
139
|
// element (inheritedProps) and props set to their default values.
|
|
169
140
|
for (const [prop, value] of Object.entries(blockProps)) {
|
|
170
141
|
const spec = propSchema[prop];
|
|
171
|
-
|
|
172
|
-
if (value !== defaultValue) {
|
|
142
|
+
if (value !== spec?.default) {
|
|
173
143
|
blockContent.setAttribute(camelToDataKebab(prop), value);
|
|
174
144
|
}
|
|
175
145
|
}
|
|
@@ -197,7 +167,7 @@ export function createBlockSpecFromTiptapNode<
|
|
|
197
167
|
const T extends {
|
|
198
168
|
node: Node;
|
|
199
169
|
type: string;
|
|
200
|
-
content: "inline" | "table" | "none";
|
|
170
|
+
content: "inline" | "table" | "none" | "plain";
|
|
201
171
|
},
|
|
202
172
|
P extends PropSchema,
|
|
203
173
|
>(
|