@blocknote/core 0.54.2 → 0.56.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-DjEkXkR5.cjs +2 -0
- package/dist/BlockNoteExtension-DjEkXkR5.cjs.map +1 -0
- package/dist/{BlockNoteExtension-CbvDA0F7.js → BlockNoteExtension-TsTGtIeX.js} +34 -27
- package/dist/BlockNoteExtension-TsTGtIeX.js.map +1 -0
- package/dist/{UserStore-mj3fXW4D.cjs → UserStore-CTVzVGh-.cjs} +2 -2
- package/dist/{UserStore-mj3fXW4D.cjs.map → UserStore-CTVzVGh-.cjs.map} +1 -1
- package/dist/{UserStore-C4TzkGEn.js → UserStore-OZJP3K8T.js} +2 -2
- package/dist/{UserStore-C4TzkGEn.js.map → UserStore-OZJP3K8T.js.map} +1 -1
- package/dist/blocknote.cjs +1 -1
- package/dist/blocknote.js +6 -6
- package/dist/blocks-COVwe5Cf.cjs +12 -0
- package/dist/blocks-COVwe5Cf.cjs.map +1 -0
- package/dist/{blocks-Dol85hpH.js → blocks-COYcDVg7.js} +1577 -1155
- package/dist/blocks-COYcDVg7.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 +69 -43
- package/dist/comments.js.map +1 -1
- package/dist/{en-uzHzj6eH.js → en-Ch-vvt5e.js} +40 -3
- package/dist/en-Ch-vvt5e.js.map +1 -0
- package/dist/en-N5lu0-j8.cjs +2 -0
- package/dist/en-N5lu0-j8.cjs.map +1 -0
- package/dist/extensions-BbM81hHa.js +3069 -0
- package/dist/extensions-BbM81hHa.js.map +1 -0
- package/dist/extensions-D_WkAfSt.cjs +58 -0
- package/dist/extensions-D_WkAfSt.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 +859 -45
- package/dist/locales.js.map +1 -1
- package/dist/src-4OQT3z5S.cjs +23 -0
- package/dist/src-4OQT3z5S.cjs.map +1 -0
- package/dist/src-BmLsLZfE.js +3491 -0
- package/dist/src-BmLsLZfE.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/y.cjs +1 -1
- package/dist/y.cjs.map +1 -1
- package/dist/y.js +1284 -554
- package/dist/y.js.map +1 -1
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.cjs.map +1 -1
- package/dist/yjs.js +189 -148
- package/dist/yjs.js.map +1 -1
- package/package.json +18 -18
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +45 -6
- package/src/api/blockManipulation/commands/insertBlocks/insertPlacement.test.ts +217 -0
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +113 -9
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +151 -163
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +47 -31
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +122 -181
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +256 -0
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +80 -40
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +71 -0
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +39 -31
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +221 -8
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +40 -8
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +272 -40
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +138 -117
- package/src/api/blockManipulation/getBlock/getBlock.ts +4 -11
- package/src/api/blockManipulation/layoutBlocks/fixLayoutBlock.ts +173 -0
- package/src/api/blockManipulation/layoutBlocks/layoutBlocks.browser.test.ts +293 -0
- package/src/api/blockManipulation/layoutBlocks/layoutBlocks.fixture.ts +145 -0
- package/src/api/blockManipulation/layoutBlocks/layoutBlocks.test.ts +783 -0
- package/src/api/blockManipulation/layoutBlocks/plainBlocks.test.ts +180 -0
- package/src/api/blockManipulation/layoutBlocks/titledBlocks.test.ts +365 -0
- package/src/api/blockManipulation/selections/selection.ts +20 -53
- package/src/api/blockManipulation/selections/textCursorPosition.ts +17 -72
- package/src/api/blockManipulation/setupTestEnv.ts +38 -6
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +4 -4
- package/src/api/clipboard/toClipboard/copyExtension.ts +3 -3
- package/src/api/combineTransactionSteps.ts +22 -0
- package/src/api/exporters/html/externalHTMLExporter.ts +1 -1
- package/src/api/exporters/html/internalHTMLSerializer.ts +4 -4
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +111 -36
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +51 -21
- package/src/api/exporters/markdown/htmlToMarkdown.ts +12 -1
- package/src/api/exporters/markdown/markdownExporter.ts +1 -1
- package/src/api/getBlockInfoFromPos.test.ts +428 -3
- package/src/api/getBlockInfoFromPos.ts +531 -129
- package/src/api/getBlocksChangedByTransaction.test.ts +7 -7
- package/src/api/getBlocksChangedByTransaction.ts +3 -3
- package/src/api/{getChangedRange.ts → getChangedRangeWithAttrs.ts} +2 -2
- package/src/api/getChangedRanges.test.ts +391 -0
- package/src/api/getChangedRanges.ts +368 -0
- package/src/api/nodeConversions/blockToNode.ts +44 -16
- package/src/api/nodeConversions/fragmentToBlocks.ts +29 -44
- package/src/api/nodeConversions/nodeToBlock.ts +120 -68
- package/src/api/nodeUtil.ts +1 -1
- package/src/api/parsers/markdown/autolink.ts +23 -0
- package/src/api/parsers/markdown/markdownToHtml.ts +115 -11
- package/src/blocks/Code/block.test.ts +4 -4
- package/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.ts +6 -1
- package/src/blocks/Heading/block.ts +54 -15
- package/src/blocks/ListItem/BulletListItem/block.ts +6 -4
- package/src/blocks/ListItem/CheckListItem/block.test.ts +2 -2
- package/src/blocks/ListItem/CheckListItem/block.ts +6 -4
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +14 -17
- package/src/blocks/ListItem/NumberedListItem/block.ts +6 -4
- package/src/blocks/ListItem/ToggleListItem/block.ts +23 -12
- package/src/blocks/Table/block.ts +2 -10
- package/src/blocks/ToggleWrapper/createToggleFrame.ts +126 -0
- package/src/blocks/ToggleWrapper/toggleBlocks.browser.test.ts +1056 -0
- package/src/blocks/defaultBlockTypeItems.test.ts +70 -0
- package/src/blocks/defaultBlockTypeItems.ts +99 -0
- package/src/blocks/defaultBlocks.test.ts +67 -0
- package/src/blocks/defaultBlocks.ts +7 -1
- package/src/blocks/index.ts +2 -1
- package/src/comments/CommentEditorSubmitExtension.test.ts +141 -0
- package/src/comments/CommentEditorSubmitExtension.ts +56 -0
- package/src/comments/extension.ts +8 -0
- package/src/comments/index.ts +1 -0
- package/src/editor/Block.css +286 -154
- package/src/editor/BlockNoteEditor.node.test.ts +35 -0
- package/src/editor/BlockNoteEditor.test.ts +2 -2
- package/src/editor/BlockNoteEditor.ts +165 -50
- package/src/editor/BlockNoteExtension.ts +11 -6
- package/src/editor/blockColors.browser.test.ts +127 -0
- package/src/editor/editor.css +60 -0
- package/src/editor/managers/BlockManager.ts +4 -3
- package/src/editor/managers/EventManager.browser.test.ts +334 -0
- package/src/editor/managers/EventManager.ts +128 -31
- package/src/editor/managers/ExtensionManager/ExtensionManager.browser.test.ts +45 -0
- package/src/editor/managers/ExtensionManager/ExtensionManager.node.test.ts +209 -0
- package/src/editor/managers/ExtensionManager/ExtensionManager.test.ts +88 -1
- package/src/editor/managers/ExtensionManager/extensions.ts +10 -1
- package/src/editor/managers/ExtensionManager/index.ts +165 -75
- package/src/editor/managers/StateManager.ts +14 -4
- package/src/editor/managers/StyleManager.browser.test.ts +122 -0
- package/src/editor/managers/StyleManager.test.ts +98 -0
- package/src/editor/managers/StyleManager.ts +31 -15
- package/src/editor/managers/index.ts +1 -0
- package/src/editor/transformPasted.ts +14 -13
- package/src/exporter/Exporter.test.ts +70 -1
- package/src/exporter/Exporter.ts +34 -4
- package/src/exporter/mapping.ts +41 -10
- package/src/extensions/DropCursor/DropCursor.ts +119 -6
- package/src/extensions/DropCursor/dropIntoChildren.ts +80 -0
- package/src/extensions/FormattingToolbar/FormattingToolbar.ts +29 -0
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.test.ts +190 -0
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.ts +41 -4
- package/src/extensions/Placeholder/Placeholder.test.ts +23 -0
- package/src/extensions/Placeholder/Placeholder.ts +8 -7
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +36 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +8 -4
- package/src/extensions/ReadOnly/ReadOnly.test.ts +181 -0
- package/src/extensions/ReadOnly/ReadOnly.ts +73 -0
- package/src/extensions/SideMenu/SideMenu.ts +401 -749
- package/src/extensions/SideMenu/blockDropHandling.ts +372 -0
- package/src/extensions/SideMenu/blockGeometry.browser.test.ts +148 -0
- package/src/extensions/SideMenu/blockGeometry.test.ts +46 -0
- package/src/extensions/SideMenu/blockGeometry.ts +53 -0
- package/src/extensions/SideMenu/dragging.ts +19 -32
- package/src/extensions/SideMenu/sideMenuHover.test.ts +36 -0
- package/src/extensions/SideMenu/sideMenuHover.ts +270 -0
- package/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.ts +5 -4
- package/src/extensions/SuggestionMenu/SuggestionMenu.ts +10 -1
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +36 -136
- package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.ts +14 -4
- package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.ts +1 -1
- package/src/extensions/SyntaxHighlighting/shiki.ts +1 -1
- package/src/extensions/TableHandles/TableHandles.browser.test.ts +3 -1
- package/src/extensions/TableHandles/TableHandles.ts +4 -6
- package/src/extensions/Versioning/Versioning.browser.test.ts +151 -0
- package/src/extensions/Versioning/Versioning.node.test.ts +177 -0
- package/src/extensions/Versioning/Versioning.ts +145 -612
- package/src/extensions/Versioning/__test__/result.ts +12 -0
- package/src/extensions/Versioning/comparison.test.ts +40 -0
- package/src/extensions/Versioning/createVersioning.test.ts +867 -0
- package/src/extensions/Versioning/createVersioning.ts +499 -0
- package/src/extensions/Versioning/formatVersionDate.ts +24 -0
- package/src/extensions/Versioning/inMemoryVersioning.test.ts +533 -430
- package/src/extensions/Versioning/inMemoryVersioning.ts +246 -251
- package/src/extensions/Versioning/index.ts +4 -0
- package/src/extensions/Versioning/scrollScheduling.test.ts +51 -0
- package/src/extensions/Versioning/scrollToFirstChange.test.ts +320 -0
- package/src/extensions/Versioning/scrollToFirstChange.ts +139 -0
- package/src/extensions/Versioning/types.ts +219 -0
- package/src/extensions/Versioning/versioningState.ts +154 -0
- package/src/extensions/blockDOM.browser.test.ts +102 -0
- package/src/extensions/blockDOM.test.ts +178 -0
- package/src/extensions/blockDOM.ts +135 -0
- package/src/extensions/index.ts +2 -0
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +1719 -53
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +645 -531
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/blockIdentity.browser.test.ts +152 -0
- package/src/extensions/tiptap-extensions/Link/helpers/autolink.ts +4 -9
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.ts +10 -24
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +22 -19
- package/src/fonts/inter.browser.test.ts +57 -0
- package/src/fonts/inter.css +111 -0
- package/src/i18n/locales/ar.ts +33 -0
- package/src/i18n/locales/de.ts +33 -0
- package/src/i18n/locales/en.ts +33 -0
- package/src/i18n/locales/es.ts +33 -0
- package/src/i18n/locales/fa.ts +33 -0
- package/src/i18n/locales/fr.ts +33 -0
- package/src/i18n/locales/he.ts +33 -0
- package/src/i18n/locales/hr.ts +33 -0
- package/src/i18n/locales/is.ts +33 -0
- package/src/i18n/locales/it.ts +33 -0
- package/src/i18n/locales/ja.ts +33 -0
- package/src/i18n/locales/ko.ts +33 -0
- package/src/i18n/locales/nl.ts +33 -0
- package/src/i18n/locales/no.ts +33 -0
- package/src/i18n/locales/pl.ts +33 -0
- package/src/i18n/locales/pt.ts +33 -0
- package/src/i18n/locales/ru.ts +33 -0
- package/src/i18n/locales/sk.ts +33 -0
- package/src/i18n/locales/uk.ts +33 -0
- package/src/i18n/locales/uz.ts +33 -0
- package/src/i18n/locales/vi.ts +33 -0
- package/src/i18n/locales/zh-tw.ts +33 -0
- package/src/i18n/locales/zh.ts +33 -0
- package/src/index.ts +14 -3
- package/src/pm-nodes/BlockContainer.test.ts +101 -0
- package/src/pm-nodes/BlockContainer.ts +110 -1
- package/src/pm-nodes/BlockGroup.ts +2 -1
- package/src/pm-nodes/README.md +2 -0
- package/src/schema/blocks/children.test.ts +288 -0
- package/src/schema/blocks/children.ts +136 -0
- package/src/schema/blocks/createSpec.browser.test.ts +176 -0
- package/src/schema/blocks/createSpec.test.ts +231 -0
- package/src/schema/blocks/createSpec.ts +493 -267
- package/src/schema/blocks/frame.test.ts +112 -0
- package/src/schema/blocks/frame.ts +337 -0
- package/src/schema/blocks/internal.ts +50 -17
- package/src/schema/blocks/keyboard.ts +154 -0
- package/src/schema/blocks/layoutBlockAttributes.ts +29 -0
- package/src/schema/blocks/meta.test.ts +53 -0
- package/src/schema/blocks/meta.ts +35 -0
- package/src/schema/blocks/renderFrame.test.ts +691 -0
- package/src/schema/blocks/types.ts +285 -21
- package/src/schema/blocks/validateChildren.ts +156 -0
- package/src/schema/dataAttributes.test.ts +72 -0
- package/src/schema/dataAttributes.ts +69 -0
- package/src/schema/index.ts +3 -0
- package/src/schema/inlineContent/internal.ts +7 -12
- package/src/schema/markGroups.ts +34 -2
- package/src/schema/schema.ts +8 -1
- package/src/user/userColors.test.ts +108 -0
- package/src/user/userColors.ts +42 -13
- package/src/util/browser.ts +24 -0
- package/src/y/comments/RESTYjsThreadStore.ts +1 -1
- package/src/y/comments/YjsThreadStore.test.ts +1 -1
- package/src/y/comments/YjsThreadStore.ts +27 -27
- package/src/y/comments/YjsThreadStoreBase.ts +2 -2
- package/src/y/comments/yjsHelpers.ts +11 -11
- package/src/y/extensions/AttributionExtension.test.ts +271 -2
- package/src/y/extensions/AttributionExtension.ts +146 -123
- package/src/y/extensions/DiffVersioningExtension.test.ts +67 -18
- package/src/y/extensions/DiffVersioningExtension.ts +95 -123
- package/src/y/extensions/EmptyDocBinding.test.ts +282 -0
- package/src/y/extensions/ForkYDoc.node.test.ts +77 -0
- package/src/y/extensions/ForkYDoc.test.ts +93 -2
- package/src/y/extensions/ForkYDoc.ts +22 -13
- package/src/y/extensions/History.test.ts +125 -0
- package/src/y/extensions/RelativePositionMapping.test.ts +35 -0
- package/src/y/extensions/RelativePositionMapping.ts +7 -11
- package/src/y/extensions/Versioning.node.test.ts +126 -0
- package/src/y/extensions/Versioning.test.ts +110 -401
- package/src/y/extensions/Versioning.ts +66 -107
- package/src/y/extensions/YAttributionMarks.ts +111 -9
- package/src/y/extensions/YCursorPlugin.ts +3 -0
- package/src/y/extensions/YSync.node.test.ts +75 -0
- package/src/y/extensions/YSync.ts +76 -4
- package/src/y/extensions/YSyncRemount.test.ts +99 -0
- package/src/y/extensions/blockMatchNodes.ts +20 -29
- package/src/y/extensions/index.ts +10 -26
- package/src/y/extensions/legacyYjsDocBinding.test.ts +652 -0
- package/src/y/extensions/nestingChanges.test.ts +326 -0
- package/src/y/extensions/persistentBlockGroups.test.ts +1709 -0
- package/src/y/extensions/persistentBlockGroups.ts +953 -0
- package/src/y/extensions/snapshotCodec.test.ts +105 -0
- package/src/y/extensions/snapshotCodec.ts +39 -0
- package/src/y/extensions/snapshotPreview.test.ts +201 -0
- package/src/y/extensions/snapshotPreview.ts +292 -0
- package/src/y/extensions/tableReshape.test.ts +121 -0
- package/src/y/extensions/v1BindingSnapshotDiff.test.ts +121 -0
- package/src/y/extensions/versionDiffAttribution.test.ts +944 -0
- package/src/y/extensions/versionDiffPerformance.test.ts +101 -0
- package/src/y/index.ts +1 -0
- package/src/y/utils.test.ts +289 -22
- package/src/y/utils.ts +167 -43
- package/src/y/versioning/__test__/fixtures/activity-all-after.json +5 -5
- package/src/y/versioning/__test__/fixtures/activity-all.json +3 -3
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.json +2 -2
- package/src/y/versioning/__test__/yhub.test.ts +902 -721
- package/src/y/versioning/index.ts +6 -1
- package/src/y/versioning/yhub.ts +316 -603
- package/src/y/versioning/yhubClient.ts +345 -0
- package/src/yjs/comments/RESTYjsThreadStore.test.ts +10 -0
- package/src/yjs/extensions/FixUpSchema.ts +11 -0
- package/src/yjs/extensions/ForkYDoc.browser.test.ts +84 -0
- package/src/yjs/extensions/ForkYDoc.node.test.ts +231 -0
- package/src/yjs/extensions/ForkYDoc.test.ts +68 -1
- package/src/yjs/extensions/ForkYDoc.ts +57 -39
- package/src/yjs/extensions/Versioning.test.ts +345 -530
- package/src/yjs/extensions/Versioning.ts +111 -68
- package/src/yjs/extensions/index.ts +1 -1
- package/src/yjs/index.ts +4 -0
- package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +2 -1
- package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.d.ts +24 -24
- package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.d.ts +3 -2
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +1 -1
- package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +2 -2
- package/types/src/api/blockManipulation/layoutBlocks/fixLayoutBlock.d.ts +34 -0
- package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.browser.test.d.ts +1 -0
- package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.fixture.d.ts +460 -0
- package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/layoutBlocks/plainBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/layoutBlocks/titledBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/setupTestEnv.d.ts +15 -69
- package/types/src/api/combineTransactionSteps.d.ts +12 -0
- package/types/src/api/getBlockInfoFromPos.d.ts +218 -44
- package/types/src/api/{getChangedRange.d.ts → getChangedRangeWithAttrs.d.ts} +1 -1
- package/types/src/api/getChangedRanges.d.ts +23 -0
- package/types/src/api/getChangedRanges.test.d.ts +1 -0
- package/types/src/api/nodeConversions/fragmentToBlocks.d.ts +0 -3
- package/types/src/api/parsers/markdown/autolink.d.ts +5 -0
- package/types/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.d.ts +4 -0
- package/types/src/blocks/ToggleWrapper/createToggleFrame.d.ts +29 -0
- package/types/src/blocks/ToggleWrapper/toggleBlocks.browser.test.d.ts +1 -0
- package/types/src/blocks/defaultBlockTypeItems.d.ts +37 -0
- package/types/src/blocks/defaultBlockTypeItems.test.d.ts +1 -0
- package/types/src/blocks/defaultBlocks.test.d.ts +1 -0
- package/types/src/blocks/index.d.ts +2 -1
- package/types/src/comments/CommentEditorSubmitExtension.d.ts +19 -0
- package/types/src/comments/CommentEditorSubmitExtension.test.d.ts +1 -0
- package/types/src/comments/extension.d.ts +7 -0
- package/types/src/comments/index.d.ts +1 -0
- package/types/src/editor/BlockNoteEditor.d.ts +88 -27
- package/types/src/editor/BlockNoteEditor.node.test.d.ts +1 -0
- package/types/src/editor/BlockNoteExtension.d.ts +3 -0
- package/types/src/editor/blockColors.browser.test.d.ts +1 -0
- package/types/src/editor/managers/BlockManager.d.ts +4 -3
- package/types/src/editor/managers/EventManager.browser.test.d.ts +1 -0
- package/types/src/editor/managers/EventManager.d.ts +55 -0
- package/types/src/editor/managers/ExtensionManager/ExtensionManager.browser.test.d.ts +1 -0
- package/types/src/editor/managers/ExtensionManager/ExtensionManager.node.test.d.ts +1 -0
- package/types/src/editor/managers/ExtensionManager/index.d.ts +15 -3
- package/types/src/editor/managers/StateManager.d.ts +1 -1
- package/types/src/editor/managers/StyleManager.browser.test.d.ts +1 -0
- package/types/src/editor/managers/StyleManager.d.ts +4 -2
- package/types/src/editor/managers/StyleManager.test.d.ts +1 -0
- package/types/src/editor/managers/index.d.ts +1 -0
- package/types/src/editor/transformPasted.d.ts +1 -1
- package/types/src/exporter/Exporter.d.ts +11 -4
- package/types/src/exporter/mapping.d.ts +13 -1
- package/types/src/extensions/DropCursor/DropCursor.d.ts +1 -1
- package/types/src/extensions/DropCursor/dropIntoChildren.d.ts +38 -0
- package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.d.ts +1 -1
- package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.test.d.ts +1 -0
- package/types/src/extensions/Placeholder/Placeholder.test.d.ts +1 -0
- package/types/src/extensions/ReadOnly/ReadOnly.d.ts +21 -0
- package/types/src/extensions/ReadOnly/ReadOnly.test.d.ts +1 -0
- package/types/src/extensions/SideMenu/SideMenu.d.ts +49 -88
- package/types/src/extensions/SideMenu/blockDropHandling.d.ts +11 -0
- package/types/src/extensions/SideMenu/blockGeometry.browser.test.d.ts +1 -0
- package/types/src/extensions/SideMenu/blockGeometry.d.ts +22 -0
- package/types/src/extensions/SideMenu/blockGeometry.test.d.ts +1 -0
- package/types/src/extensions/SideMenu/dragging.d.ts +0 -4
- package/types/src/extensions/SideMenu/sideMenuHover.d.ts +58 -0
- package/types/src/extensions/SideMenu/sideMenuHover.test.d.ts +1 -0
- package/types/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.d.ts +3 -0
- package/types/src/extensions/SourceInlineContentWithPreview/SourceInlineContentWithPreview.d.ts +1 -0
- package/types/src/extensions/Versioning/Versioning.browser.test.d.ts +1 -0
- package/types/src/extensions/Versioning/Versioning.d.ts +34 -311
- package/types/src/extensions/Versioning/Versioning.node.test.d.ts +1 -0
- package/types/src/extensions/Versioning/__test__/result.d.ts +3 -0
- package/types/src/extensions/Versioning/comparison.test.d.ts +1 -0
- package/types/src/extensions/Versioning/createVersioning.d.ts +32 -0
- package/types/src/extensions/Versioning/createVersioning.test.d.ts +1 -0
- package/types/src/extensions/Versioning/formatVersionDate.d.ts +7 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.d.ts +64 -36
- package/types/src/extensions/Versioning/index.d.ts +4 -0
- package/types/src/extensions/Versioning/scrollScheduling.test.d.ts +1 -0
- package/types/src/extensions/Versioning/scrollToFirstChange.d.ts +18 -0
- package/types/src/extensions/Versioning/scrollToFirstChange.test.d.ts +1 -0
- package/types/src/extensions/Versioning/types.d.ts +239 -0
- package/types/src/extensions/Versioning/versioningState.d.ts +43 -0
- package/types/src/extensions/blockDOM.browser.test.d.ts +1 -0
- package/types/src/extensions/blockDOM.d.ts +37 -0
- package/types/src/extensions/blockDOM.test.d.ts +1 -0
- package/types/src/extensions/index.d.ts +2 -0
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.d.ts +1 -0
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.d.ts +3 -0
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/blockIdentity.browser.test.d.ts +1 -0
- package/types/src/fonts/inter.browser.test.d.ts +2 -0
- package/types/src/i18n/locales/en.d.ts +33 -0
- package/types/src/i18n/locales/fa.d.ts +33 -0
- package/types/src/i18n/locales/sk.d.ts +33 -0
- package/types/src/index.d.ts +7 -3
- package/types/src/pm-nodes/BlockContainer.d.ts +6 -0
- package/types/src/pm-nodes/BlockContainer.test.d.ts +1 -0
- package/types/src/schema/blocks/children.d.ts +39 -0
- package/types/src/schema/blocks/children.test.d.ts +1 -0
- package/types/src/schema/blocks/createSpec.browser.test.d.ts +1 -0
- package/types/src/schema/blocks/createSpec.d.ts +13 -0
- package/types/src/schema/blocks/frame.d.ts +109 -0
- package/types/src/schema/blocks/frame.test.d.ts +1 -0
- package/types/src/schema/blocks/internal.d.ts +6 -0
- package/types/src/schema/blocks/keyboard.d.ts +111 -0
- package/types/src/schema/blocks/layoutBlockAttributes.d.ts +9 -0
- package/types/src/schema/blocks/meta.d.ts +14 -0
- package/types/src/schema/blocks/meta.test.d.ts +1 -0
- package/types/src/schema/blocks/renderFrame.test.d.ts +1 -0
- package/types/src/schema/blocks/types.d.ts +228 -15
- package/types/src/schema/blocks/validateChildren.d.ts +5 -0
- package/types/src/schema/dataAttributes.d.ts +19 -0
- package/types/src/schema/dataAttributes.test.d.ts +1 -0
- package/types/src/schema/index.d.ts +3 -0
- package/types/src/schema/markGroups.d.ts +8 -0
- package/types/src/user/userColors.d.ts +24 -3
- package/types/src/user/userColors.test.d.ts +1 -0
- package/types/src/util/browser.d.ts +2 -0
- package/types/src/y/comments/RESTYjsThreadStore.d.ts +1 -1
- package/types/src/y/comments/YjsThreadStore.d.ts +1 -1
- package/types/src/y/comments/YjsThreadStoreBase.d.ts +2 -2
- package/types/src/y/comments/yjsHelpers.d.ts +5 -5
- package/types/src/y/extensions/AttributionExtension.d.ts +19 -21
- package/types/src/y/extensions/DiffVersioningExtension.d.ts +9 -4
- package/types/src/y/extensions/EmptyDocBinding.test.d.ts +1 -0
- package/types/src/y/extensions/ForkYDoc.d.ts +3 -1
- package/types/src/y/extensions/ForkYDoc.node.test.d.ts +1 -0
- package/types/src/y/extensions/History.test.d.ts +1 -0
- package/types/src/y/extensions/Versioning.d.ts +4 -15
- package/types/src/y/extensions/Versioning.node.test.d.ts +1 -0
- package/types/src/y/extensions/YAttributionMarks.d.ts +13 -2
- package/types/src/y/extensions/YCursorPlugin.d.ts +1 -0
- package/types/src/y/extensions/YSync.d.ts +4 -18
- package/types/src/y/extensions/YSync.node.test.d.ts +1 -0
- package/types/src/y/extensions/YSyncRemount.test.d.ts +1 -0
- package/types/src/y/extensions/blockMatchNodes.d.ts +0 -22
- package/types/src/y/extensions/index.d.ts +27 -44
- package/types/src/y/extensions/legacyYjsDocBinding.test.d.ts +1 -0
- package/types/src/y/extensions/nestingChanges.test.d.ts +1 -0
- package/types/src/y/extensions/persistentBlockGroups.d.ts +189 -0
- package/types/src/y/extensions/persistentBlockGroups.test.d.ts +1 -0
- package/types/src/y/extensions/snapshotCodec.d.ts +13 -0
- package/types/src/y/extensions/snapshotCodec.test.d.ts +1 -0
- package/types/src/y/extensions/snapshotPreview.d.ts +21 -0
- package/types/src/y/extensions/snapshotPreview.test.d.ts +1 -0
- package/types/src/y/extensions/tableReshape.test.d.ts +1 -0
- package/types/src/y/extensions/v1BindingSnapshotDiff.test.d.ts +1 -0
- package/types/src/y/extensions/versionDiffAttribution.test.d.ts +1 -0
- package/types/src/y/extensions/versionDiffPerformance.test.d.ts +1 -0
- package/types/src/y/index.d.ts +1 -0
- package/types/src/y/utils.d.ts +39 -19
- package/types/src/y/versioning/index.d.ts +1 -1
- package/types/src/y/versioning/yhub.d.ts +69 -86
- package/types/src/y/versioning/yhubClient.d.ts +67 -0
- package/types/src/yjs/extensions/ForkYDoc.browser.test.d.ts +1 -0
- package/types/src/yjs/extensions/ForkYDoc.d.ts +2 -0
- package/types/src/yjs/extensions/ForkYDoc.node.test.d.ts +1 -0
- package/types/src/yjs/extensions/Versioning.d.ts +36 -22
- package/types/src/yjs/extensions/index.d.ts +2 -1
- package/types/src/yjs/index.d.ts +1 -0
- package/dist/BlockNoteExtension-BJCLnwrE.cjs +0 -2
- package/dist/BlockNoteExtension-BJCLnwrE.cjs.map +0 -1
- package/dist/BlockNoteExtension-CbvDA0F7.js.map +0 -1
- package/dist/blocks-CTB_5Vyj.cjs +0 -12
- package/dist/blocks-CTB_5Vyj.cjs.map +0 -1
- package/dist/blocks-Dol85hpH.js.map +0 -1
- package/dist/en-BuzSuuTq.cjs +0 -2
- package/dist/en-BuzSuuTq.cjs.map +0 -1
- package/dist/en-uzHzj6eH.js.map +0 -1
- package/dist/extensions-B7Rsp_Ft.cjs +0 -58
- package/dist/extensions-B7Rsp_Ft.cjs.map +0 -1
- package/dist/extensions-D6JcJCwd.js +0 -2138
- package/dist/extensions-D6JcJCwd.js.map +0 -1
- package/dist/src-Buuo5l7X.js +0 -3317
- package/dist/src-Buuo5l7X.js.map +0 -1
- package/dist/src-C54Ok9E0.cjs +0 -23
- package/dist/src-C54Ok9E0.cjs.map +0 -1
- package/src/api/blockManipulation/commands/replaceBlocks/util/fixColumnList.ts +0 -173
- package/src/blocks/ListItem/ListItemKeyboardShortcuts.ts +0 -63
- package/src/blocks/ToggleWrapper/createToggleWrapper.ts +0 -197
- package/src/blocks/utils/listItemEnterHandler.ts +0 -43
- package/src/extensions/Versioning/Versioning.test.ts +0 -435
- package/src/extensions/getDraggableBlockFromElement.ts +0 -19
- package/types/src/api/blockManipulation/commands/replaceBlocks/util/fixColumnList.d.ts +0 -32
- package/types/src/blocks/ListItem/ListItemKeyboardShortcuts.d.ts +0 -2
- package/types/src/blocks/ToggleWrapper/createToggleWrapper.d.ts +0 -15
- package/types/src/blocks/utils/listItemEnterHandler.d.ts +0 -2
- package/types/src/extensions/getDraggableBlockFromElement.d.ts +0 -5
- /package/types/src/{extensions/Versioning/Versioning.test.d.ts → api/blockManipulation/commands/insertBlocks/insertPlacement.test.d.ts} +0 -0
|
@@ -1,11 +1,8 @@
|
|
|
1
|
+
import type { FrameView } from "./frame.js";
|
|
1
2
|
/** Define the main block types **/
|
|
2
3
|
// import { Extension, Node } from "@tiptap/core";
|
|
3
4
|
import type { Node, NodeViewRendererProps } from "@tiptap/core";
|
|
4
|
-
import type {
|
|
5
|
-
Fragment,
|
|
6
|
-
Node as ProsemirrorNode,
|
|
7
|
-
Schema,
|
|
8
|
-
} from "prosemirror-model";
|
|
5
|
+
import type { Fragment, Node as PMNode, Schema } from "prosemirror-model";
|
|
9
6
|
import type { ViewMutationRecord } from "prosemirror-view";
|
|
10
7
|
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
11
8
|
import type {
|
|
@@ -19,6 +16,7 @@ import type {
|
|
|
19
16
|
StyledText,
|
|
20
17
|
} from "../inlineContent/types.js";
|
|
21
18
|
import type { PropSchema, Props } from "../propTypes.js";
|
|
19
|
+
import type { BlockKeyboard, BlockKeyboardOption } from "./keyboard.js";
|
|
22
20
|
import type { StyleSchema } from "../styles/types.js";
|
|
23
21
|
|
|
24
22
|
export type BlockNoteDOMElement =
|
|
@@ -39,6 +37,10 @@ export interface BlockConfigMeta<
|
|
|
39
37
|
/**
|
|
40
38
|
* Defines which keyboard shortcut should be used to insert a hard break into the block's inline content.
|
|
41
39
|
* @default "shift+enter"
|
|
40
|
+
* @deprecated Use `experimental_keyboard.enter` and
|
|
41
|
+
* `experimental_keyboard.shiftEnter` instead: `"enter"` is
|
|
42
|
+
* `experimental_keyboard: { enter: "line-break" }`, and `"none"` is
|
|
43
|
+
* `experimental_keyboard: { shiftEnter: "same-as-enter" }`.
|
|
42
44
|
*/
|
|
43
45
|
hardBreakShortcut?: "shift+enter" | "enter" | "none";
|
|
44
46
|
|
|
@@ -67,6 +69,25 @@ export interface BlockConfigMeta<
|
|
|
67
69
|
*/
|
|
68
70
|
isolating?: boolean;
|
|
69
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Whether this block type gets a side menu drag handle (and can be dragged
|
|
74
|
+
* by it). Applies to any block type, layout block or not: e.g. a
|
|
75
|
+
* "locked" block can opt out of dragging entirely. A block that opts out is
|
|
76
|
+
* skipped when looking for a drag handle, so the handle falls through to the
|
|
77
|
+
* nearest draggable ancestor.
|
|
78
|
+
* @default `true`, or `false` for a layout block placeable `"namedOnly"`, which
|
|
79
|
+
* can only live in its parent
|
|
80
|
+
*/
|
|
81
|
+
draggable?: boolean;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Whether a block dragged onto this block's content or frame chrome becomes
|
|
85
|
+
* its first child (as in Notion's toggles), instead of going before or after
|
|
86
|
+
* it. A block dragged onto its children still goes between them.
|
|
87
|
+
* @default false
|
|
88
|
+
*/
|
|
89
|
+
dropsIntoChildren?(block: { type: TName; props: Props<TProps> }): boolean;
|
|
90
|
+
|
|
70
91
|
/**
|
|
71
92
|
* Enables syntax highlighting of the contents of the block with the result of this callback
|
|
72
93
|
*/
|
|
@@ -81,9 +102,82 @@ export interface BlockConfigMeta<
|
|
|
81
102
|
}
|
|
82
103
|
|
|
83
104
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
105
|
+
* A block's `meta` with every default applied: what a block spec in a schema
|
|
106
|
+
* holds, so readers never see a missing setting (see `resolveBlockMeta`).
|
|
107
|
+
*/
|
|
108
|
+
export type ResolvedBlockConfigMeta<
|
|
109
|
+
TName extends string = string,
|
|
110
|
+
TProps extends PropSchema = PropSchema,
|
|
111
|
+
> = BlockConfigMeta<TName, TProps> &
|
|
112
|
+
Required<
|
|
113
|
+
Pick<
|
|
114
|
+
BlockConfigMeta<TName, TProps>,
|
|
115
|
+
"selectable" | "code" | "defining" | "isolating" | "draggable"
|
|
116
|
+
>
|
|
117
|
+
>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The type name of a layout block, as used in {@link ChildrenConfig.allow}.
|
|
121
|
+
*/
|
|
122
|
+
export type AllowedChildType = string;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* What may appear as a child of a layout block.
|
|
126
|
+
*
|
|
127
|
+
* - `"blocks"`: any regular block, or any layout block placeable anywhere.
|
|
128
|
+
* This cannot be narrowed to specific regular block types: every regular
|
|
129
|
+
* block is the *same* ProseMirror node (`blockContainer`), so paragraphs,
|
|
130
|
+
* headings and code blocks are indistinguishable at the node level.
|
|
131
|
+
* - `readonly AllowedChildType[]`: only these layout block types, enforced exactly
|
|
132
|
+
* by the schema. Naming a regular block type is a startup error; per-type
|
|
133
|
+
* regular-block filtering can be added to this same form later, with no API
|
|
134
|
+
* change.
|
|
135
|
+
*
|
|
136
|
+
* Neither form includes `placeable: "namedOnly"` types. Those appear only
|
|
137
|
+
* where a parent names them explicitly in an array.
|
|
138
|
+
*/
|
|
139
|
+
export type ChildrenAllow = "blocks" | readonly AllowedChildType[];
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Which child blocks a layout block holds (`layoutOnly: true`), exposed as
|
|
143
|
+
* `block.children` at runtime.
|
|
144
|
+
*
|
|
145
|
+
* The config describes one uniform set of children, semantically a single
|
|
146
|
+
* implicit slot. Ordered multi-slot children (a `sequence` of slots) can be
|
|
147
|
+
* added later as a sibling form.
|
|
86
148
|
*/
|
|
149
|
+
export type ChildrenConfig =
|
|
150
|
+
| {
|
|
151
|
+
/**
|
|
152
|
+
* Any blocks, the default. When its last child is removed, the
|
|
153
|
+
* layout block is removed too.
|
|
154
|
+
*/
|
|
155
|
+
allow?: "blocks";
|
|
156
|
+
/**
|
|
157
|
+
* Layout block types the block does not hold, out of those placeable
|
|
158
|
+
* anywhere: a column holds any block except a column list. Regular
|
|
159
|
+
* block types can't be excluded, as every regular block is the same
|
|
160
|
+
* ProseMirror node.
|
|
161
|
+
*/
|
|
162
|
+
exclude?: readonly AllowedChildType[];
|
|
163
|
+
}
|
|
164
|
+
| {
|
|
165
|
+
/** Which layout block types may appear as a child. */
|
|
166
|
+
allow: readonly AllowedChildType[];
|
|
167
|
+
/**
|
|
168
|
+
* How few children the layout block may hold; `0` lets it be empty.
|
|
169
|
+
* @default 1
|
|
170
|
+
*/
|
|
171
|
+
min?: number;
|
|
172
|
+
/**
|
|
173
|
+
* Whether a layout block with too few children dissolves into what they
|
|
174
|
+
* hold, like a column list with one column left. `false` keeps the
|
|
175
|
+
* layout block and its empty children, like a tab set.
|
|
176
|
+
* @default true
|
|
177
|
+
*/
|
|
178
|
+
dissolve?: boolean;
|
|
179
|
+
};
|
|
180
|
+
|
|
87
181
|
export interface BlockConfig<
|
|
88
182
|
T extends string = string,
|
|
89
183
|
PS extends PropSchema = PropSchema,
|
|
@@ -106,8 +200,55 @@ export interface BlockConfig<
|
|
|
106
200
|
* The content that the block supports
|
|
107
201
|
*/
|
|
108
202
|
content: C;
|
|
109
|
-
|
|
110
|
-
|
|
203
|
+
/**
|
|
204
|
+
* `true` makes the block a layout block: a block without content of its own
|
|
205
|
+
* (`content: "none"`) whose own node holds its child blocks. Its
|
|
206
|
+
* `renderFrame` puts them in its slot (React: `slotRef`). With `false` (the
|
|
207
|
+
* default), the block's child blocks are indented below it. Only a block
|
|
208
|
+
* with `content: "none"` can set `true`.
|
|
209
|
+
*/
|
|
210
|
+
layoutOnly?: C extends "none" ? boolean : false;
|
|
211
|
+
/**
|
|
212
|
+
* Which child blocks the block may have. Every block can have any child
|
|
213
|
+
* blocks (`{ allow: "blocks" }`, the default). Only a layout block
|
|
214
|
+
* (`layoutOnly: true`) can restrict them to certain types or a minimum
|
|
215
|
+
* count, since the child blocks of other blocks all share one untyped
|
|
216
|
+
* group. How the keyboard treats a block's children (e.g. whether Enter in
|
|
217
|
+
* the block's text starts them) is set with its `experimental_keyboard`
|
|
218
|
+
* settings.
|
|
219
|
+
*/
|
|
220
|
+
children?: C extends "none"
|
|
221
|
+
? ChildrenConfig
|
|
222
|
+
: {
|
|
223
|
+
allow?: "blocks";
|
|
224
|
+
exclude?: undefined;
|
|
225
|
+
min?: undefined;
|
|
226
|
+
dissolve?: undefined;
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Where this block may be placed.
|
|
230
|
+
*
|
|
231
|
+
* - `"anywhere"` (default): anywhere a regular block goes, the document
|
|
232
|
+
* root or nested under any other block.
|
|
233
|
+
* - `"namedOnly"`: only inside a layout block that names this type in its
|
|
234
|
+
* `children.allow` array (e.g. a `column` inside a `columnList`).
|
|
235
|
+
*
|
|
236
|
+
* Only meaningful for layout blocks; regular blocks are always placeable
|
|
237
|
+
* anywhere.
|
|
238
|
+
*/
|
|
239
|
+
placeable?: "anywhere" | "namedOnly";
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
declare module "prosemirror-model" {
|
|
243
|
+
interface NodeSpec {
|
|
244
|
+
/**
|
|
245
|
+
* The config of the BlockNote block this node was built from, so code
|
|
246
|
+
* holding a bare `Node` can read block-level facts (like the content
|
|
247
|
+
* kind) without an editor or schema reference. Set on every node built
|
|
248
|
+
* from a block spec.
|
|
249
|
+
*/
|
|
250
|
+
blockConfig?: BlockConfig;
|
|
251
|
+
}
|
|
111
252
|
}
|
|
112
253
|
|
|
113
254
|
/**
|
|
@@ -212,10 +353,19 @@ export type LooseBlockSpec<
|
|
|
212
353
|
config: BlockConfig<T, PS, C>;
|
|
213
354
|
implementation: Omit<
|
|
214
355
|
BlockImplementation<T, PS, C>,
|
|
215
|
-
|
|
356
|
+
| "render"
|
|
357
|
+
| "renderFrame"
|
|
358
|
+
| "toExternalHTML"
|
|
359
|
+
| "experimental_keyboard"
|
|
360
|
+
| "meta"
|
|
216
361
|
> & {
|
|
362
|
+
/** Every keyboard setting of the block, with defaults filled in. */
|
|
363
|
+
keyboard: (block: any) => BlockKeyboard;
|
|
364
|
+
/** The block's `meta`, with defaults filled in. */
|
|
365
|
+
meta: ResolvedBlockConfigMeta<T, PS>;
|
|
217
366
|
// purposefully stub the types for render and toExternalHTML since they reference the block
|
|
218
|
-
render
|
|
367
|
+
// A layout block declares `renderFrame` instead of `render`.
|
|
368
|
+
render?: (
|
|
219
369
|
/**
|
|
220
370
|
* The custom block to render
|
|
221
371
|
*/
|
|
@@ -228,9 +378,21 @@ export type LooseBlockSpec<
|
|
|
228
378
|
dom: HTMLElement | DocumentFragment;
|
|
229
379
|
contentDOM?: HTMLElement;
|
|
230
380
|
ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
|
|
231
|
-
update?: (node: ProsemirrorNode) => boolean;
|
|
232
381
|
destroy?: () => void;
|
|
382
|
+
update?: (node: PMNode) => boolean | void;
|
|
233
383
|
};
|
|
384
|
+
renderFrame?: <I extends InlineContentSchema, S extends StyleSchema>(
|
|
385
|
+
block: any,
|
|
386
|
+
editor: BlockNoteEditor<any, I, S>,
|
|
387
|
+
) =>
|
|
388
|
+
| {
|
|
389
|
+
dom: HTMLElement;
|
|
390
|
+
slot: HTMLElement;
|
|
391
|
+
/** Releases resources when the live frame is replaced or destroyed. */
|
|
392
|
+
destroy?: () => void;
|
|
393
|
+
update?: (block: any) => boolean | void;
|
|
394
|
+
}
|
|
395
|
+
| undefined;
|
|
234
396
|
toExternalHTML?: (
|
|
235
397
|
block: any,
|
|
236
398
|
editor: BlockNoteEditor<any>,
|
|
@@ -271,10 +433,12 @@ export type BlockSpecs = {
|
|
|
271
433
|
config: BlockSpec<k>["config"];
|
|
272
434
|
implementation: Omit<
|
|
273
435
|
BlockSpec<k>["implementation"],
|
|
274
|
-
"render" | "toExternalHTML"
|
|
436
|
+
"render" | "renderFrame" | "toExternalHTML" | "experimental_keyboard"
|
|
275
437
|
> & {
|
|
438
|
+
experimental_keyboard?: BlockKeyboardOption<any>;
|
|
276
439
|
// purposefully stub the types for render and toExternalHTML since they reference the block
|
|
277
|
-
render
|
|
440
|
+
// A layout block declares `renderFrame` instead of `render`.
|
|
441
|
+
render?: (
|
|
278
442
|
/**
|
|
279
443
|
* The custom block to render
|
|
280
444
|
*/
|
|
@@ -287,9 +451,21 @@ export type BlockSpecs = {
|
|
|
287
451
|
dom: HTMLElement | DocumentFragment;
|
|
288
452
|
contentDOM?: HTMLElement;
|
|
289
453
|
ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
|
|
290
|
-
update?: (node: ProsemirrorNode) => boolean;
|
|
291
454
|
destroy?: () => void;
|
|
455
|
+
update?: (node: PMNode) => boolean | void;
|
|
292
456
|
};
|
|
457
|
+
renderFrame?: <I extends InlineContentSchema, S extends StyleSchema>(
|
|
458
|
+
block: any,
|
|
459
|
+
editor: BlockNoteEditor<any, I, S>,
|
|
460
|
+
) =>
|
|
461
|
+
| {
|
|
462
|
+
dom: HTMLElement;
|
|
463
|
+
slot: HTMLElement;
|
|
464
|
+
/** Releases resources when the live frame is replaced or destroyed. */
|
|
465
|
+
destroy?: () => void;
|
|
466
|
+
update?: (block: any) => boolean | void;
|
|
467
|
+
}
|
|
468
|
+
| undefined;
|
|
293
469
|
toExternalHTML?: (
|
|
294
470
|
block: any,
|
|
295
471
|
editor: BlockNoteEditor<any>,
|
|
@@ -554,14 +730,40 @@ export type BlockImplementation<
|
|
|
554
730
|
| "table"
|
|
555
731
|
| "plain",
|
|
556
732
|
> = {
|
|
733
|
+
/**
|
|
734
|
+
* @internal Framework adapter (React): draws the block's frame in the
|
|
735
|
+
* editor, for the node view of a framed block's `blockContainer` or of a
|
|
736
|
+
* layout block. Core uses it instead of the vanilla `renderFrame` when present.
|
|
737
|
+
*
|
|
738
|
+
* TODO: the content node view has no such hook yet: React builds it inside
|
|
739
|
+
* `render` (see the `TODO` there). Add one, so `render` / `renderFrame`
|
|
740
|
+
* only draw.
|
|
741
|
+
*/
|
|
742
|
+
frameView?: (props: NodeViewRendererProps) => FrameView;
|
|
557
743
|
/**
|
|
558
744
|
* Metadata
|
|
559
745
|
*/
|
|
560
746
|
meta?: BlockConfigMeta<TName, TProps>;
|
|
561
747
|
/**
|
|
562
|
-
*
|
|
748
|
+
* Experimental: how the keyboard treats the block and its children (Enter,
|
|
749
|
+
* Shift-Enter, Backspace, and outdenting): the settings that differ from the
|
|
750
|
+
* defaults, or a function of the block that returns them. See
|
|
751
|
+
* {@link BlockKeyboard}. This API may change.
|
|
752
|
+
*/
|
|
753
|
+
experimental_keyboard?: BlockKeyboardOption<
|
|
754
|
+
BlockFromConfig<BlockConfig<TName, TProps, TContent>, any, any>
|
|
755
|
+
>;
|
|
756
|
+
/**
|
|
757
|
+
* A function that converts the block into a DOM element. Every block
|
|
758
|
+
* declares it, except a layout block (`layoutOnly: true`), which has no content
|
|
759
|
+
* to draw and declares only `renderFrame`.
|
|
760
|
+
*
|
|
761
|
+
* FIXME: optional for every block here, checked at runtime
|
|
762
|
+
* (`validateRenderHooks`). The types could require exactly one of `render`
|
|
763
|
+
* and `renderFrame`, but core's first `createBlockSpec` overload can't see
|
|
764
|
+
* `layoutOnly`.
|
|
563
765
|
*/
|
|
564
|
-
render
|
|
766
|
+
render?: (
|
|
565
767
|
this:
|
|
566
768
|
| Record<string, never>
|
|
567
769
|
| ({
|
|
@@ -591,6 +793,7 @@ export type BlockImplementation<
|
|
|
591
793
|
dom: HTMLElement | DocumentFragment;
|
|
592
794
|
contentDOM?: HTMLElement;
|
|
593
795
|
ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
|
|
796
|
+
destroy?: () => void;
|
|
594
797
|
/**
|
|
595
798
|
* Called by ProseMirror when this block's node is updated (e.g. its content
|
|
596
799
|
* or props change). Return `true` to handle the update in place - keeping
|
|
@@ -601,13 +804,74 @@ export type BlockImplementation<
|
|
|
601
804
|
* Useful for blocks whose `render` builds custom DOM that needs to stay in
|
|
602
805
|
* sync with the node (e.g. a code block rendering a preview of its content).
|
|
603
806
|
*/
|
|
604
|
-
update?: (node:
|
|
605
|
-
destroy?: () => void;
|
|
807
|
+
update?: (node: PMNode) => boolean | void;
|
|
606
808
|
};
|
|
607
809
|
|
|
810
|
+
/**
|
|
811
|
+
* Draws the chrome *around* a block's content and children: the author's
|
|
812
|
+
* markup wraps both, and the `slot` is where BlockNote mounts them.
|
|
813
|
+
*
|
|
814
|
+
* The slot holds the content first and the children after it. A layout block
|
|
815
|
+
* (`layoutOnly: true`) has no content, so it draws only its frame, with its
|
|
816
|
+
* child blocks in the slot. The frame's root is then the block's element,
|
|
817
|
+
* and a layout block must always draw it.
|
|
818
|
+
*
|
|
819
|
+
* `render` stays the knob for the block's own content. A block may use
|
|
820
|
+
* both: `render` draws the title, `renderFrame` draws the box around title
|
|
821
|
+
* and body. Returning `undefined` declines — the block renders plain — so
|
|
822
|
+
* a block can decide from its props, content, or children whether it is framed.
|
|
823
|
+
*
|
|
824
|
+
* Chrome outside the slot is the author's: ProseMirror leaves its events
|
|
825
|
+
* alone. An `update` hook receives the current block on updates and patches
|
|
826
|
+
* the frame in place. Return `false` to rebuild (or decline) the frame.
|
|
827
|
+
* Without an update hook, a change to the block's props rebuilds the frame;
|
|
828
|
+
* its content and children are in the slot, so typing doesn't. A frame
|
|
829
|
+
* whose chrome shows the block's content or children needs an `update`
|
|
830
|
+
* hook. Whether a block declines may depend only on its props: a declined
|
|
831
|
+
* frame is asked again when the block's props change.
|
|
832
|
+
*/
|
|
833
|
+
renderFrame?: <I extends InlineContentSchema, S extends StyleSchema>(
|
|
834
|
+
this:
|
|
835
|
+
| Record<string, never>
|
|
836
|
+
| ({
|
|
837
|
+
propSchema?: TProps;
|
|
838
|
+
} & (
|
|
839
|
+
| {
|
|
840
|
+
renderType: "nodeView";
|
|
841
|
+
props: NodeViewRendererProps;
|
|
842
|
+
}
|
|
843
|
+
| {
|
|
844
|
+
renderType: "dom";
|
|
845
|
+
props: undefined;
|
|
846
|
+
}
|
|
847
|
+
)),
|
|
848
|
+
block: BlockFromConfig<BlockConfig<TName, TProps, TContent>, any, any>,
|
|
849
|
+
editor: BlockNoteEditor<
|
|
850
|
+
Record<TName, BlockConfig<TName, TProps, TContent>>,
|
|
851
|
+
I,
|
|
852
|
+
S
|
|
853
|
+
>,
|
|
854
|
+
) =>
|
|
855
|
+
| {
|
|
856
|
+
dom: HTMLElement;
|
|
857
|
+
/** Where BlockNote mounts the block's content and/or children. */
|
|
858
|
+
slot: HTMLElement;
|
|
859
|
+
/** Releases resources when the live frame is replaced or destroyed. */
|
|
860
|
+
destroy?: () => void;
|
|
861
|
+
update?: (
|
|
862
|
+
block: BlockFromConfig<
|
|
863
|
+
BlockConfig<TName, TProps, TContent>,
|
|
864
|
+
any,
|
|
865
|
+
any
|
|
866
|
+
>,
|
|
867
|
+
) => boolean | void;
|
|
868
|
+
}
|
|
869
|
+
| undefined;
|
|
870
|
+
|
|
608
871
|
/**
|
|
609
872
|
* Exports block to external HTML. If not defined, the output will be the same
|
|
610
|
-
* as `render(...).dom
|
|
873
|
+
* as `render(...).dom`, inside the block's frame (`renderFrame`) if it has
|
|
874
|
+
* one. When defined, it replaces both.
|
|
611
875
|
*/
|
|
612
876
|
toExternalHTML?: (
|
|
613
877
|
this: Partial<{
|
|
@@ -699,4 +963,4 @@ export type CustomBlockImplementation<
|
|
|
699
963
|
T extends string = string,
|
|
700
964
|
PS extends PropSchema = PropSchema,
|
|
701
965
|
C extends "inline" | "none" | "plain" = "inline" | "none" | "plain",
|
|
702
|
-
> = BlockImplementation<T, PS, C>;
|
|
966
|
+
> = Omit<BlockImplementation<T, PS, C>, "frameView">;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { BlockConfig, ChildrenAllow } from "./types.js";
|
|
2
|
+
|
|
3
|
+
/** Reject declarations ProseMirror would accept with different semantics. */
|
|
4
|
+
export function validateChildrenConfigs(
|
|
5
|
+
blockSpecs: Record<
|
|
6
|
+
string,
|
|
7
|
+
{
|
|
8
|
+
config: Pick<
|
|
9
|
+
BlockConfig,
|
|
10
|
+
"content" | "placeable" | "layoutOnly" | "children"
|
|
11
|
+
>;
|
|
12
|
+
}
|
|
13
|
+
>,
|
|
14
|
+
) {
|
|
15
|
+
for (const [type, { config }] of Object.entries(blockSpecs)) {
|
|
16
|
+
if (config.layoutOnly === true && config.content !== "none") {
|
|
17
|
+
fail(
|
|
18
|
+
type,
|
|
19
|
+
'`layoutOnly: true` is only for blocks without content (`content: "none"`). A layout block holds only child blocks, no content of its own.',
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
if (config.placeable === "namedOnly" && config.layoutOnly !== true) {
|
|
23
|
+
fail(
|
|
24
|
+
type,
|
|
25
|
+
'`placeable: "namedOnly"` is only for layout blocks (`layoutOnly: true`). Only a layout block can be limited to the blocks that name it in `children.allow`.',
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
if (!config.children) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Typed loosely: a JS caller can put anything here.
|
|
33
|
+
const {
|
|
34
|
+
allow = "blocks",
|
|
35
|
+
min,
|
|
36
|
+
exclude,
|
|
37
|
+
dissolve,
|
|
38
|
+
} = config.children as {
|
|
39
|
+
allow?: ChildrenAllow;
|
|
40
|
+
min?: number;
|
|
41
|
+
exclude?: readonly string[];
|
|
42
|
+
dissolve?: boolean;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// The child blocks of a block that isn't a layout block share one untyped
|
|
46
|
+
// group, which can't enforce types or counts.
|
|
47
|
+
if (config.layoutOnly !== true) {
|
|
48
|
+
if (
|
|
49
|
+
allow !== "blocks" ||
|
|
50
|
+
min !== undefined ||
|
|
51
|
+
exclude !== undefined ||
|
|
52
|
+
dissolve !== undefined
|
|
53
|
+
) {
|
|
54
|
+
fail(
|
|
55
|
+
type,
|
|
56
|
+
'restricting child types, a minimum count or `dissolve` requires `layoutOnly: true`. Other blocks can always have any child blocks (`{ allow: "blocks" }`).',
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// A layout block that accepts any blocks always holds at least one, and
|
|
63
|
+
// dissolves when it loses it. A minimum, and whether the layout block
|
|
64
|
+
// dissolves, only mean something for a set of named layout block types (two
|
|
65
|
+
// columns, one tab). A key can move the last block out of a layout block
|
|
66
|
+
// that accepts any blocks, so one that does not dissolve could never be
|
|
67
|
+
// removed with the keyboard.
|
|
68
|
+
if (allow === "blocks" && (min !== undefined || dissolve !== undefined)) {
|
|
69
|
+
fail(
|
|
70
|
+
type,
|
|
71
|
+
`\`children.${min !== undefined ? "min" : "dissolve"}\` needs an \`allow\` list. A layout block that accepts any blocks always holds at least one child, and dissolves when its last child is removed.`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (min !== undefined && !(Number.isInteger(min) && min >= 0)) {
|
|
76
|
+
fail(
|
|
77
|
+
type,
|
|
78
|
+
`\`children.min\` must be a whole number that is 0 or more, not ${String(min)}.`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (exclude !== undefined) {
|
|
83
|
+
if (allow !== "blocks") {
|
|
84
|
+
fail(
|
|
85
|
+
type,
|
|
86
|
+
"`children.exclude` is only for a layout block that accepts any blocks. An `allow` list already names exactly what the layout block holds.",
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
for (const excluded of exclude) {
|
|
90
|
+
if (!Object.prototype.hasOwnProperty.call(blockSpecs, excluded)) {
|
|
91
|
+
fail(
|
|
92
|
+
type,
|
|
93
|
+
`\`exclude\` contains "${excluded}", which is not a configured block type.`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
const { config: excludedConfig } = blockSpecs[excluded];
|
|
97
|
+
if (excludedConfig.layoutOnly !== true) {
|
|
98
|
+
fail(
|
|
99
|
+
type,
|
|
100
|
+
`\`exclude\` contains "${excluded}", which is not a layout block. ` +
|
|
101
|
+
"Only layout blocks (`layoutOnly: true`) can be excluded.",
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
if (excludedConfig.placeable === "namedOnly") {
|
|
105
|
+
fail(
|
|
106
|
+
type,
|
|
107
|
+
`\`exclude\` contains "${excluded}", which is \`placeable: "namedOnly"\` and never a child of a layout block that accepts any blocks.`,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Every regular block is the same node (`blockContainer`), so naming one
|
|
114
|
+
// here compiles to a valid schema that restricts nothing.
|
|
115
|
+
if (allow !== "blocks") {
|
|
116
|
+
for (const allowed of allow) {
|
|
117
|
+
if (!Object.prototype.hasOwnProperty.call(blockSpecs, allowed)) {
|
|
118
|
+
fail(
|
|
119
|
+
type,
|
|
120
|
+
`\`allow\` contains "${allowed}", which is not a configured block type.`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
if (blockSpecs[allowed].config.layoutOnly !== true) {
|
|
124
|
+
fail(
|
|
125
|
+
type,
|
|
126
|
+
`\`allow\` contains "${allowed}", which is not a layout block. ` +
|
|
127
|
+
"An `allow` list can name only layout blocks (`layoutOnly: true`); naming other blocks is not supported yet. " +
|
|
128
|
+
'Use `allow: "blocks"` to accept all other blocks.',
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// A `namedOnly` block can only be a child of a block that names it in
|
|
136
|
+
// `children.allow`. Without such a block, the editor cannot insert it.
|
|
137
|
+
const named = new Set(
|
|
138
|
+
Object.values(blockSpecs).flatMap(({ config }) =>
|
|
139
|
+
config.children?.allow && config.children.allow !== "blocks"
|
|
140
|
+
? config.children.allow
|
|
141
|
+
: [],
|
|
142
|
+
),
|
|
143
|
+
);
|
|
144
|
+
for (const [type, { config }] of Object.entries(blockSpecs)) {
|
|
145
|
+
if (config.placeable === "namedOnly" && !named.has(type)) {
|
|
146
|
+
fail(
|
|
147
|
+
type,
|
|
148
|
+
'`placeable: "namedOnly"` limits this block to the blocks that name it in `children.allow`, but no block names it. Name it in the `allow` list of a layout block.',
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function fail(type: string, message: string): never {
|
|
155
|
+
throw new Error(`Invalid config for block "${type}": ${message}`);
|
|
156
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { describe, expect, it } from "vite-plus/test";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
applyDataAttributes,
|
|
5
|
+
propsToDataAttributes,
|
|
6
|
+
setDataAttributes,
|
|
7
|
+
} from "./dataAttributes.js";
|
|
8
|
+
|
|
9
|
+
// The one rule props and their `data-*` attributes share: a prop becomes a
|
|
10
|
+
// kebab-case attribute, except at its default, which has none.
|
|
11
|
+
|
|
12
|
+
const propSchema = {
|
|
13
|
+
textAlignment: { default: "left", values: ["left", "center"] },
|
|
14
|
+
previewWidth: { default: undefined, type: "number" },
|
|
15
|
+
checked: { default: false },
|
|
16
|
+
} as const;
|
|
17
|
+
|
|
18
|
+
describe("propsToDataAttributes", () => {
|
|
19
|
+
it("leaves out props at their default or absent, and stringifies the rest", () => {
|
|
20
|
+
expect(
|
|
21
|
+
propsToDataAttributes(
|
|
22
|
+
{ textAlignment: "center", checked: true },
|
|
23
|
+
propSchema,
|
|
24
|
+
),
|
|
25
|
+
).toEqual({ "data-text-alignment": "center", "data-checked": "true" });
|
|
26
|
+
expect(
|
|
27
|
+
propsToDataAttributes(
|
|
28
|
+
{ textAlignment: "left", previewWidth: 256, checked: false },
|
|
29
|
+
propSchema,
|
|
30
|
+
),
|
|
31
|
+
).toEqual({ "data-preview-width": "256" });
|
|
32
|
+
expect(propsToDataAttributes({}, propSchema)).toEqual({});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("keeps the props' own order, and has no attribute for an unknown prop", () => {
|
|
36
|
+
expect(
|
|
37
|
+
Object.keys(
|
|
38
|
+
propsToDataAttributes(
|
|
39
|
+
{ checked: true, unknown: "x", textAlignment: "center" } as any,
|
|
40
|
+
propSchema,
|
|
41
|
+
),
|
|
42
|
+
),
|
|
43
|
+
).toEqual(["data-checked", "data-text-alignment"]);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("setDataAttributes", () => {
|
|
48
|
+
it("sets the attributes and removes nothing", () => {
|
|
49
|
+
const element = document.createElement("div");
|
|
50
|
+
element.setAttribute("data-checked", "author");
|
|
51
|
+
setDataAttributes(
|
|
52
|
+
element,
|
|
53
|
+
propsToDataAttributes({ textAlignment: "center" }, propSchema),
|
|
54
|
+
);
|
|
55
|
+
expect(element.getAttribute("data-text-alignment")).toBe("center");
|
|
56
|
+
expect(element.getAttribute("data-checked")).toBe("author");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("applyDataAttributes", () => {
|
|
61
|
+
it("sets non-default props and removes the attributes of the others", () => {
|
|
62
|
+
const element = document.createElement("div");
|
|
63
|
+
element.setAttribute("data-text-alignment", "center");
|
|
64
|
+
element.setAttribute("data-checked", "author");
|
|
65
|
+
element.setAttribute("data-other", "kept");
|
|
66
|
+
applyDataAttributes(element, { previewWidth: 100 }, propSchema);
|
|
67
|
+
expect(element.getAttribute("data-preview-width")).toBe("100");
|
|
68
|
+
expect(element.hasAttribute("data-text-alignment")).toBe(false);
|
|
69
|
+
expect(element.hasAttribute("data-checked")).toBe(false);
|
|
70
|
+
expect(element.getAttribute("data-other")).toBe("kept");
|
|
71
|
+
});
|
|
72
|
+
});
|