@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
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { describe, expect, it } from "vite-plus/test";
|
|
2
|
+
|
|
3
|
+
import { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
4
|
+
|
|
5
|
+
// `Block.css` applies a block's colors to its children from the block's own
|
|
6
|
+
// element, so the node view keeps them on `.bn-block`, framed or not.
|
|
7
|
+
describe("block colors on the block's element", () => {
|
|
8
|
+
const blockElement = (editor: BlockNoteEditor<any, any, any>, id: string) =>
|
|
9
|
+
editor.domElement!.querySelector(
|
|
10
|
+
`[data-node-type="blockContainer"][data-id="${id}"]`,
|
|
11
|
+
)!;
|
|
12
|
+
|
|
13
|
+
for (const [type, props] of [
|
|
14
|
+
["paragraph", {}],
|
|
15
|
+
["heading", {}],
|
|
16
|
+
["toggleListItem", {}],
|
|
17
|
+
["heading", { isToggleable: true }],
|
|
18
|
+
] as const) {
|
|
19
|
+
it(`puts them on a ${type} ${JSON.stringify(props)} and follows changes`, () => {
|
|
20
|
+
const editor = BlockNoteEditor.create({
|
|
21
|
+
initialContent: [
|
|
22
|
+
{
|
|
23
|
+
id: "parent",
|
|
24
|
+
type,
|
|
25
|
+
props: { ...props, textColor: "red" },
|
|
26
|
+
content: "Parent",
|
|
27
|
+
children: [{ id: "child", type: "paragraph", content: "Child" }],
|
|
28
|
+
} as any,
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
editor.mount(document.createElement("div"));
|
|
32
|
+
try {
|
|
33
|
+
const element = () => blockElement(editor, "parent");
|
|
34
|
+
expect(element().getAttribute("data-text-color")).toBe("red");
|
|
35
|
+
expect(element().hasAttribute("data-background-color")).toBe(false);
|
|
36
|
+
|
|
37
|
+
editor.updateBlock("parent", {
|
|
38
|
+
props: { textColor: "default", backgroundColor: "blue" },
|
|
39
|
+
} as any);
|
|
40
|
+
expect(element().hasAttribute("data-text-color")).toBe(false);
|
|
41
|
+
expect(element().getAttribute("data-background-color")).toBe("blue");
|
|
42
|
+
} finally {
|
|
43
|
+
editor._tiptapEditor.destroy();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// As with ProseMirror's default, a change of the block's type keeps its view
|
|
50
|
+
// (and its children's), unless the new type draws a frame or the old one did.
|
|
51
|
+
describe("block type changes", () => {
|
|
52
|
+
function editorWithParent() {
|
|
53
|
+
const editor = BlockNoteEditor.create({
|
|
54
|
+
initialContent: [
|
|
55
|
+
{
|
|
56
|
+
id: "parent",
|
|
57
|
+
type: "paragraph",
|
|
58
|
+
content: "Parent",
|
|
59
|
+
children: [{ id: "child", type: "paragraph", content: "Child" }],
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
editor.mount(document.createElement("div"));
|
|
64
|
+
const element = (id: string) =>
|
|
65
|
+
editor.domElement!.querySelector(
|
|
66
|
+
`[data-node-type="blockContainer"][data-id="${id}"]`,
|
|
67
|
+
);
|
|
68
|
+
return { editor, element };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
it("keeps the block and its children between types without a frame", () => {
|
|
72
|
+
const { editor, element } = editorWithParent();
|
|
73
|
+
try {
|
|
74
|
+
const [parent, child] = [element("parent"), element("child")];
|
|
75
|
+
editor.updateBlock("parent", { type: "heading" });
|
|
76
|
+
editor.updateBlock("parent", { type: "bulletListItem" });
|
|
77
|
+
expect(element("parent")).toBe(parent);
|
|
78
|
+
expect(element("child")).toBe(child);
|
|
79
|
+
} finally {
|
|
80
|
+
editor._tiptapEditor.destroy();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("draws the block again when the frame comes or goes", () => {
|
|
85
|
+
const { editor, element } = editorWithParent();
|
|
86
|
+
try {
|
|
87
|
+
const parent = element("parent");
|
|
88
|
+
editor.updateBlock("parent", { type: "toggleListItem" });
|
|
89
|
+
const toggled = element("parent")!;
|
|
90
|
+
expect(toggled).not.toBe(parent);
|
|
91
|
+
expect(toggled.querySelector(".bn-toggle-frame")).not.toBeNull();
|
|
92
|
+
|
|
93
|
+
editor.updateBlock("parent", { type: "paragraph" });
|
|
94
|
+
expect(element("parent")).not.toBe(toggled);
|
|
95
|
+
expect(element("parent")!.querySelector(".bn-toggle-frame")).toBeNull();
|
|
96
|
+
expect(element("parent")!.textContent).toContain("Child");
|
|
97
|
+
} finally {
|
|
98
|
+
editor._tiptapEditor.destroy();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -1,10 +1,54 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Node,
|
|
3
|
+
type NodeViewRenderer,
|
|
4
|
+
type NodeViewRendererProps,
|
|
5
|
+
} from "@tiptap/core";
|
|
6
|
+
import type { NodeView } from "@tiptap/pm/view";
|
|
2
7
|
|
|
3
8
|
import type { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
9
|
+
import {
|
|
10
|
+
blockFrameView,
|
|
11
|
+
findFrameSlot,
|
|
12
|
+
frameNodeViewHooks,
|
|
13
|
+
} from "../schema/blocks/frame.js";
|
|
4
14
|
import { BlockNoteDOMAttributes } from "../schema/index.js";
|
|
5
15
|
import { mergeCSSClasses } from "../util/browser.js";
|
|
6
16
|
import { suggestionMarks } from "./suggestionMarks.js";
|
|
7
17
|
|
|
18
|
+
/** The block props whose colors `Block.css` applies to a block's children. */
|
|
19
|
+
const BLOCK_COLORS = [
|
|
20
|
+
["textColor", "data-text-color"],
|
|
21
|
+
["backgroundColor", "data-background-color"],
|
|
22
|
+
] as const;
|
|
23
|
+
|
|
24
|
+
function isColorSet(value: unknown): value is string {
|
|
25
|
+
return typeof value === "string" && value !== "default";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Whether a block has a text or background color other than the default. */
|
|
29
|
+
function hasBlockColors(props: Record<string, unknown>) {
|
|
30
|
+
return BLOCK_COLORS.some(([prop]) => isColorSet(props[prop]));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Puts a block's text and background color on its own element (`.bn-block`),
|
|
35
|
+
* so they also apply to its children however deep a frame puts its content.
|
|
36
|
+
* Only these two props, which `Block.css` applies to a block's children.
|
|
37
|
+
*/
|
|
38
|
+
export function setBlockColorAttributes(
|
|
39
|
+
element: HTMLElement,
|
|
40
|
+
props: Record<string, unknown> | undefined,
|
|
41
|
+
) {
|
|
42
|
+
for (const [prop, attribute] of BLOCK_COLORS) {
|
|
43
|
+
const value = props?.[prop];
|
|
44
|
+
if (isColorSet(value)) {
|
|
45
|
+
element.setAttribute(attribute, value);
|
|
46
|
+
} else {
|
|
47
|
+
element.removeAttribute(attribute);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
8
52
|
// Object containing all possible block attributes.
|
|
9
53
|
const BlockAttributes: Record<string, string> = {
|
|
10
54
|
blockColor: "data-block-color",
|
|
@@ -49,6 +93,10 @@ export const BlockContainer = Node.create<{
|
|
|
49
93
|
|
|
50
94
|
return attrs;
|
|
51
95
|
},
|
|
96
|
+
// The frame's slot: the rest of a frame is chrome, not document
|
|
97
|
+
// content.
|
|
98
|
+
contentElement: (element) =>
|
|
99
|
+
findFrameSlot(element as HTMLElement) ?? (element as HTMLElement),
|
|
52
100
|
},
|
|
53
101
|
// Ignore `blockOuter` divs, but parse the `blockContainer` divs inside them.
|
|
54
102
|
{
|
|
@@ -88,4 +136,65 @@ export const BlockContainer = Node.create<{
|
|
|
88
136
|
contentDOM: block,
|
|
89
137
|
};
|
|
90
138
|
},
|
|
139
|
+
|
|
140
|
+
addNodeView() {
|
|
141
|
+
// Every block gets this node view: it draws the block's frame (or none),
|
|
142
|
+
// keeps it current, and keeps the block's colors on `.bn-block`. Without
|
|
143
|
+
// a frame, it is as fast as ProseMirror's default (`performance.test.ts`).
|
|
144
|
+
// Cast: this returns a plain ProseMirror node view, which tiptap's
|
|
145
|
+
// `NodeViewRenderer` type doesn't model.
|
|
146
|
+
return ((props: NodeViewRendererProps) => {
|
|
147
|
+
const { dom, contentDOM: block } = this.type.spec.toDOM!(props.node) as {
|
|
148
|
+
dom: HTMLElement;
|
|
149
|
+
contentDOM: HTMLElement;
|
|
150
|
+
};
|
|
151
|
+
const editor = this.options.editor;
|
|
152
|
+
// The block's frame: React draws its own, otherwise the block's
|
|
153
|
+
// vanilla `renderFrame`. A drawn frame goes inside `.bn-block`; a block
|
|
154
|
+
// without one keeps its content and children in `.bn-block` itself.
|
|
155
|
+
const frame = blockFrameView({
|
|
156
|
+
props,
|
|
157
|
+
editor,
|
|
158
|
+
blockNode: (node) => node.firstChild!,
|
|
159
|
+
unframed: block,
|
|
160
|
+
});
|
|
161
|
+
if (frame.dom !== block) {
|
|
162
|
+
block.appendChild(frame.dom);
|
|
163
|
+
}
|
|
164
|
+
// A new `.bn-block` has no color attributes, so a block with the default
|
|
165
|
+
// colors needs no DOM calls. Skipping them keeps typing in large
|
|
166
|
+
// documents fast (`performance.test.ts`).
|
|
167
|
+
const attrs = props.node.firstChild!.attrs;
|
|
168
|
+
if (hasBlockColors(attrs)) {
|
|
169
|
+
setBlockColorAttributes(block, attrs);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const nodeView: NodeView = {
|
|
173
|
+
dom,
|
|
174
|
+
contentDOM: frame.slot,
|
|
175
|
+
update(node, decorations, innerDecorations) {
|
|
176
|
+
const before = frame.node;
|
|
177
|
+
// Like ProseMirror's default, the view is rebuilt when the block's
|
|
178
|
+
// own attributes change (another block), and otherwise kept while
|
|
179
|
+
// ProseMirror updates the content and children. It is also rebuilt
|
|
180
|
+
// when the frame no longer fits, for example after a change of the
|
|
181
|
+
// block's type or props.
|
|
182
|
+
if (
|
|
183
|
+
!node.sameMarkup(before) ||
|
|
184
|
+
!frame.update(node, decorations, innerDecorations)
|
|
185
|
+
) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
// `Block.css` applies a block's colors to its children too, from
|
|
189
|
+
// its element. They are props, so only a prop change moves them.
|
|
190
|
+
if (!node.firstChild!.sameMarkup(before.firstChild!)) {
|
|
191
|
+
setBlockColorAttributes(block, node.firstChild!.attrs);
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
},
|
|
195
|
+
...frameNodeViewHooks(frame),
|
|
196
|
+
};
|
|
197
|
+
return nodeView;
|
|
198
|
+
}) as unknown as NodeViewRenderer;
|
|
199
|
+
},
|
|
91
200
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Node } from "@tiptap/core";
|
|
2
|
+
import { CHILD_CONTAINER_GROUP } from "../schema/blocks/children.js";
|
|
2
3
|
import { BlockNoteDOMAttributes } from "../schema/index.js";
|
|
3
4
|
import { mergeCSSClasses } from "../util/browser.js";
|
|
4
5
|
import { suggestionMarks } from "./suggestionMarks.js";
|
|
@@ -7,7 +8,7 @@ export const BlockGroup = Node.create<{
|
|
|
7
8
|
domAttributes?: BlockNoteDOMAttributes;
|
|
8
9
|
}>({
|
|
9
10
|
name: "blockGroup",
|
|
10
|
-
group:
|
|
11
|
+
group: CHILD_CONTAINER_GROUP,
|
|
11
12
|
content: "blockGroupChild+",
|
|
12
13
|
marks() {
|
|
13
14
|
return suggestionMarks(this.editor);
|
package/src/pm-nodes/README.md
CHANGED
|
@@ -48,6 +48,8 @@ content: "blockContent blockGroup?",
|
|
|
48
48
|
|
|
49
49
|
A `blockContainer` is a container node that always contains a `blockContent` node, and optionally a `blockGroup` node (for nested children). It is used as the wrapper for most blocks. This structure makes it possible to nest blocks within blocks.
|
|
50
50
|
|
|
51
|
+
In a collaborative (Yjs) document the `blockGroup` of a block is persistent: it is created together with the block, stays in the Y document when its last child is removed, and is hidden from the ProseMirror document while it is empty. The `blockContainer` in Y therefore holds `blockContent blockGroup` (or, in documents written before this, `blockContent` until the first nesting), and a container may even hold several `blockGroup`s after two users nested a first child concurrently; the editor shows them as one. See `y/extensions/persistentBlockGroups.ts`.
|
|
52
|
+
|
|
51
53
|
### BlockContent (group)
|
|
52
54
|
|
|
53
55
|
Example:
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { describe, expect, it } from "vite-plus/test";
|
|
3
|
+
|
|
4
|
+
import { anyBlocksExpression, childrenContentExpression } from "./children.js";
|
|
5
|
+
import type { ChildrenAllow, ChildrenConfig } from "./types.js";
|
|
6
|
+
import { validateChildrenConfigs } from "./validateChildren.js";
|
|
7
|
+
|
|
8
|
+
// All enforcement happens through the content expression. If this table is
|
|
9
|
+
// right, `allow`/`min` are enforced by ProseMirror itself.
|
|
10
|
+
const CASES: [string, ChildrenConfig, string][] = [
|
|
11
|
+
[
|
|
12
|
+
"any block or placeable layout block, at least one (the minimal config)",
|
|
13
|
+
{ allow: "blocks" },
|
|
14
|
+
"blockGroupChild+",
|
|
15
|
+
],
|
|
16
|
+
["one layout block type only", { allow: ["column"], min: 2 }, "column{2,}"],
|
|
17
|
+
[
|
|
18
|
+
"one layout block type, possibly none",
|
|
19
|
+
{ allow: ["column"], min: 0 },
|
|
20
|
+
"column*",
|
|
21
|
+
],
|
|
22
|
+
[
|
|
23
|
+
"several layout block types",
|
|
24
|
+
{ allow: ["column", "card"] },
|
|
25
|
+
"(column | card)+",
|
|
26
|
+
],
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
describe("childrenContentExpression", () => {
|
|
30
|
+
it.each(CASES)("%s", (_name, config, expected) => {
|
|
31
|
+
expect(childrenContentExpression(config)).toBe(expected);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// `validateChildrenConfigs` never builds the content expression — it only
|
|
35
|
+
// resolves `allow`/`min` — so an `allow` that permits nothing is caught
|
|
36
|
+
// here, at expression build, rather than by `validate` below.
|
|
37
|
+
it("accepts any blocks when `children` or `allow` is left out", () => {
|
|
38
|
+
expect(childrenContentExpression()).toBe("blockGroupChild+");
|
|
39
|
+
expect(childrenContentExpression({ allow: "blocks" })).toBe(
|
|
40
|
+
"blockGroupChild+",
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("throws for an allow array that permits nothing", () => {
|
|
45
|
+
expect(() => childrenContentExpression({ allow: [] })).toThrow(
|
|
46
|
+
/permits nothing/,
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
type BlockFixture = {
|
|
52
|
+
content?: "none" | "inline" | "plain" | "table";
|
|
53
|
+
layoutOnly?: true;
|
|
54
|
+
// Loose on purpose: the validator tests pass shapes the type rejects.
|
|
55
|
+
children?: {
|
|
56
|
+
allow?: ChildrenAllow;
|
|
57
|
+
min?: number;
|
|
58
|
+
exclude?: string[];
|
|
59
|
+
dissolve?: boolean;
|
|
60
|
+
};
|
|
61
|
+
placeable?: "anywhere" | "namedOnly";
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
function specsWith(blocks: Record<string, BlockFixture>) {
|
|
65
|
+
return {
|
|
66
|
+
paragraph: { config: { content: "inline" as const } },
|
|
67
|
+
heading: { config: { content: "inline" as const } },
|
|
68
|
+
...Object.fromEntries(
|
|
69
|
+
Object.entries(blocks).map(([type, config]) => [
|
|
70
|
+
type,
|
|
71
|
+
{ config: { ...config, content: config.content ?? ("none" as const) } },
|
|
72
|
+
]),
|
|
73
|
+
),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Typed loosely on purpose: the validator is what catches the combinations the
|
|
78
|
+
// types reject, for JS callers.
|
|
79
|
+
const validate = (blocks: Record<string, BlockFixture>) => () =>
|
|
80
|
+
validateChildrenConfigs(specsWith(blocks) as any);
|
|
81
|
+
|
|
82
|
+
// `exclude` is resolved against the schema: the "any blocks" group is replaced
|
|
83
|
+
// by its other members, and `childrenContentExpression` takes the result.
|
|
84
|
+
describe("anyBlocksExpression", () => {
|
|
85
|
+
const specs = specsWith({
|
|
86
|
+
callout: { layoutOnly: true },
|
|
87
|
+
columnList: { layoutOnly: true, children: { allow: ["column"], min: 2 } },
|
|
88
|
+
column: { layoutOnly: true, placeable: "namedOnly" },
|
|
89
|
+
}) as any;
|
|
90
|
+
|
|
91
|
+
it("is the group when nothing is excluded", () => {
|
|
92
|
+
expect(anyBlocksExpression([], specs)).toBe("blockGroupChild");
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("spells out the other members otherwise", () => {
|
|
96
|
+
expect(anyBlocksExpression(["columnList"], specs)).toBe(
|
|
97
|
+
"(blockContainer | callout)",
|
|
98
|
+
);
|
|
99
|
+
expect(anyBlocksExpression(["columnList", "callout"], specs)).toBe(
|
|
100
|
+
"blockContainer",
|
|
101
|
+
);
|
|
102
|
+
expect(
|
|
103
|
+
childrenContentExpression(
|
|
104
|
+
{ allow: "blocks", exclude: ["columnList"] },
|
|
105
|
+
anyBlocksExpression(["columnList"], specs),
|
|
106
|
+
),
|
|
107
|
+
).toBe("(blockContainer | callout)+");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("rejects `exclude` on an allow list at the type level", () => {
|
|
111
|
+
const config: ChildrenConfig = {
|
|
112
|
+
allow: ["column"],
|
|
113
|
+
// @ts-expect-error `exclude` is only for a layout block of any blocks
|
|
114
|
+
exclude: ["callout"],
|
|
115
|
+
};
|
|
116
|
+
expect(config.allow).toEqual(["column"]);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe("validateChildrenConfigs", () => {
|
|
121
|
+
it("accepts `exclude` of a layout block that can stand anywhere", () => {
|
|
122
|
+
expect(
|
|
123
|
+
validate({
|
|
124
|
+
box: { layoutOnly: true, children: { exclude: ["callout"] } },
|
|
125
|
+
callout: { layoutOnly: true },
|
|
126
|
+
}),
|
|
127
|
+
).not.toThrow();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("rejects `exclude` where it can't apply", () => {
|
|
131
|
+
expect(
|
|
132
|
+
validate({
|
|
133
|
+
box: {
|
|
134
|
+
layoutOnly: true,
|
|
135
|
+
children: { allow: ["callout"], exclude: ["callout"] },
|
|
136
|
+
},
|
|
137
|
+
callout: { layoutOnly: true },
|
|
138
|
+
}),
|
|
139
|
+
).toThrow(/only for a layout block that accepts any blocks/);
|
|
140
|
+
expect(
|
|
141
|
+
validate({
|
|
142
|
+
box: { content: "inline", children: { exclude: ["callout"] } },
|
|
143
|
+
callout: { layoutOnly: true },
|
|
144
|
+
}),
|
|
145
|
+
).toThrow(/requires `layoutOnly: true`/);
|
|
146
|
+
expect(
|
|
147
|
+
validate({ box: { layoutOnly: true, children: { exclude: ["typo"] } } }),
|
|
148
|
+
).toThrow(/not a configured block type/);
|
|
149
|
+
expect(
|
|
150
|
+
validate({
|
|
151
|
+
box: { layoutOnly: true, children: { exclude: ["paragraph"] } },
|
|
152
|
+
}),
|
|
153
|
+
).toThrow(/is not a layout block/);
|
|
154
|
+
expect(
|
|
155
|
+
validate({
|
|
156
|
+
box: { layoutOnly: true, children: { exclude: ["column"] } },
|
|
157
|
+
column: { layoutOnly: true, placeable: "namedOnly" },
|
|
158
|
+
}),
|
|
159
|
+
).toThrow(/namedOnly/);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("accepts recursive layout blocks and named-only children", () => {
|
|
163
|
+
expect(validate({ callout: { layoutOnly: true } })).not.toThrow();
|
|
164
|
+
expect(
|
|
165
|
+
validate({
|
|
166
|
+
// gridCell is a terminating alternative to the recursive grid.
|
|
167
|
+
grid: {
|
|
168
|
+
layoutOnly: true,
|
|
169
|
+
children: { allow: ["gridCell", "grid"], min: 2 },
|
|
170
|
+
},
|
|
171
|
+
gridCell: { layoutOnly: true, placeable: "namedOnly" },
|
|
172
|
+
}),
|
|
173
|
+
).not.toThrow();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// `min` only means something for a set of named layout block types. A
|
|
177
|
+
// layout block that accepts any blocks always holds at least one, and
|
|
178
|
+
// dissolves when it loses it.
|
|
179
|
+
it("rejects `min` on a layout block that accepts any blocks", () => {
|
|
180
|
+
for (const children of [{ allow: "blocks", min: 2 }, { min: 2 }] as const) {
|
|
181
|
+
expect(validate({ panel: { layoutOnly: true, children } })).toThrow(
|
|
182
|
+
/`children.min` needs an `allow` list/,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
// The type rejects it too.
|
|
186
|
+
// @ts-expect-error
|
|
187
|
+
const invalid: ChildrenConfig = { allow: "blocks", min: 2 };
|
|
188
|
+
expect(invalid).toBeDefined();
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it.each(["inline", "plain", "table"] as const)(
|
|
192
|
+
"rejects `layoutOnly` on a block with %s content",
|
|
193
|
+
(content) => {
|
|
194
|
+
expect(validate({ alert: { content, layoutOnly: true } })).toThrow(
|
|
195
|
+
/only for blocks without content/,
|
|
196
|
+
);
|
|
197
|
+
},
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
// Any block can have any child blocks, so writing out the default is fine
|
|
201
|
+
// everywhere. Restricting them needs the block's own node.
|
|
202
|
+
it.each(["inline", "plain", "table", "none"] as const)(
|
|
203
|
+
"only accepts the default children on a %s block that isn't a layout block",
|
|
204
|
+
(content) => {
|
|
205
|
+
expect(
|
|
206
|
+
validate({ alert: { content, children: { allow: "blocks" } } }),
|
|
207
|
+
).not.toThrow();
|
|
208
|
+
for (const children of [
|
|
209
|
+
{ allow: "blocks", min: 2 },
|
|
210
|
+
{ allow: ["cell"] },
|
|
211
|
+
] as const) {
|
|
212
|
+
expect(
|
|
213
|
+
validate({
|
|
214
|
+
alert: { content, children },
|
|
215
|
+
cell: { layoutOnly: true },
|
|
216
|
+
}),
|
|
217
|
+
).toThrow(/requires `layoutOnly: true`/);
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
it("does not treat a block with content as an allowed layout block", () => {
|
|
223
|
+
expect(
|
|
224
|
+
validate({
|
|
225
|
+
box: { layoutOnly: true, children: { allow: ["alert"] } },
|
|
226
|
+
alert: { content: "inline" },
|
|
227
|
+
}),
|
|
228
|
+
).toThrow(/is not a layout block/);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("rejects `dissolve` without an allow list", () => {
|
|
232
|
+
expect(
|
|
233
|
+
validate({ box: { layoutOnly: true, children: { dissolve: false } } }),
|
|
234
|
+
).toThrow(/`children.dissolve` needs an `allow` list/);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it.each([-1, 1.5, Number.NaN])("rejects `min: %s`", (min) => {
|
|
238
|
+
expect(
|
|
239
|
+
validate({
|
|
240
|
+
columnList: {
|
|
241
|
+
layoutOnly: true,
|
|
242
|
+
children: { allow: ["column"], min },
|
|
243
|
+
},
|
|
244
|
+
column: { layoutOnly: true, placeable: "namedOnly" },
|
|
245
|
+
}),
|
|
246
|
+
).toThrow(/`children.min` must be a whole number that is 0 or more/);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("rejects `dissolve` on a block that is not a layout block", () => {
|
|
250
|
+
expect(
|
|
251
|
+
validate({ alert: { content: "inline", children: { dissolve: false } } }),
|
|
252
|
+
).toThrow(/requires `layoutOnly: true`/);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("rejects named-only placement on a block that is not a layout block", () => {
|
|
256
|
+
expect(
|
|
257
|
+
validate({ alert: { content: "inline", placeable: "namedOnly" } }),
|
|
258
|
+
).toThrow(/only for layout blocks/);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("rejects a named-only block that no allow list names", () => {
|
|
262
|
+
// The editor could not insert it anywhere.
|
|
263
|
+
expect(
|
|
264
|
+
validate({ step: { layoutOnly: true, placeable: "namedOnly" } }),
|
|
265
|
+
).toThrow(/no block names it/);
|
|
266
|
+
expect(
|
|
267
|
+
validate({
|
|
268
|
+
stepper: { layoutOnly: true, children: { allow: ["step"] } },
|
|
269
|
+
step: { layoutOnly: true, placeable: "namedOnly" },
|
|
270
|
+
}),
|
|
271
|
+
).not.toThrow();
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it.each(["typo", "blockGroupChild", "toString"])(
|
|
275
|
+
"rejects an allow entry that is not a configured block: %s",
|
|
276
|
+
(allowed) => {
|
|
277
|
+
expect(
|
|
278
|
+
validate({ box: { layoutOnly: true, children: { allow: [allowed] } } }),
|
|
279
|
+
).toThrow(/not a configured block type/);
|
|
280
|
+
},
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
it("rejects a regular block type in the allow array", () => {
|
|
284
|
+
expect(
|
|
285
|
+
validate({ box: { layoutOnly: true, children: { allow: ["heading"] } } }),
|
|
286
|
+
).toThrow(/not supported yet/);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { Node, NodeType, Schema } from "prosemirror-model";
|
|
2
|
+
|
|
3
|
+
import type { BlockConfig, ChildrenConfig } from "./types.js";
|
|
4
|
+
|
|
5
|
+
export const CHILD_CONTAINER_GROUP = "childContainer";
|
|
6
|
+
|
|
7
|
+
export const BLOCK_GROUP_CHILD_GROUP = "blockGroupChild";
|
|
8
|
+
|
|
9
|
+
// Naming: a "layout block" is a block declared `layoutOnly: true`, whose own
|
|
10
|
+
// node holds its child blocks. Two older names with "container" mean
|
|
11
|
+
// something else:
|
|
12
|
+
// - `blockContainer` is the node around every other block (its content node
|
|
13
|
+
// plus an optional `blockGroup` of children). Its name is kept because it
|
|
14
|
+
// is stored in documents.
|
|
15
|
+
// - `childContainer` (`CHILD_CONTAINER_GROUP`) is the node group of every
|
|
16
|
+
// node that holds a block's children: `blockGroup` and the nodes of layout
|
|
17
|
+
// blocks.
|
|
18
|
+
//
|
|
19
|
+
// Whether `type` is the node of a layout block: a node that holds child
|
|
20
|
+
// blocks directly and is itself a block. `blockGroup` also holds children but
|
|
21
|
+
// is not a block (it's regular blocks' nesting machinery), so the `bnBlock`
|
|
22
|
+
// check excludes it.
|
|
23
|
+
export function isLayoutNode(type: NodeType): boolean {
|
|
24
|
+
return type.isInGroup(CHILD_CONTAINER_GROUP) && type.isInGroup("bnBlock");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Builds the `blockGroup` node that holds a block's children when converting
|
|
28
|
+
// blocks to nodes. Transaction-level nesting (`sinkItem`, `findWrapping` in the
|
|
29
|
+
// keyboard shortcuts) wraps existing nodes in a `blockGroup` instead, and the
|
|
30
|
+
// document's root `blockGroup` is created by the parsers and `y`/`yjs` utils.
|
|
31
|
+
export function createBlockGroup(
|
|
32
|
+
schema: Schema,
|
|
33
|
+
children: readonly Node[],
|
|
34
|
+
): Node {
|
|
35
|
+
return schema.nodes["blockGroup"].createChecked({}, children as Node[]);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Whether `type` is a layout block declared `placeable: "namedOnly"`: one
|
|
40
|
+
* defined only in terms of the layout block that holds it (a `column`), so it can
|
|
41
|
+
* never stand where a regular block goes.
|
|
42
|
+
*
|
|
43
|
+
* The schema encodes this by keeping such types out of
|
|
44
|
+
* `BLOCK_GROUP_CHILD_GROUP`, which is how ProseMirror enforces it while
|
|
45
|
+
* matching content. This answers the same question from the declaration
|
|
46
|
+
* itself, for code reasoning about the block rather than about what PM will
|
|
47
|
+
* match.
|
|
48
|
+
*/
|
|
49
|
+
export function isNamedOnly(type: NodeType): boolean {
|
|
50
|
+
return isLayoutNode(type) && type.spec.blockConfig?.placeable === "namedOnly";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Below `blockContainer`'s priority (50) so PM's `fillBefore` picks
|
|
54
|
+
// `blockContainer` first, avoiding recursion through nested layout blocks.
|
|
55
|
+
export const LAYOUT_NODE_PRIORITY = 40;
|
|
56
|
+
|
|
57
|
+
const LAYOUT_PRIORITY_BAND = { min: 30, max: 49 };
|
|
58
|
+
const DEFAULT_SPEC_PRIORITY = 101;
|
|
59
|
+
|
|
60
|
+
// Maps `sortByDependencies` priority into the layout block band (30–49).
|
|
61
|
+
// Preserves relative order but keeps all layout blocks below regular blocks.
|
|
62
|
+
export function layoutNodePriority(priority: number | undefined): number {
|
|
63
|
+
if (priority === undefined) {
|
|
64
|
+
return LAYOUT_NODE_PRIORITY;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const steps = Math.round((priority - DEFAULT_SPEC_PRIORITY) / 10);
|
|
68
|
+
|
|
69
|
+
return Math.min(
|
|
70
|
+
LAYOUT_PRIORITY_BAND.max,
|
|
71
|
+
Math.max(LAYOUT_PRIORITY_BAND.min, LAYOUT_NODE_PRIORITY + steps),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** How few children a layout block must hold: its `min` (an `allow` list only), else 1. */
|
|
76
|
+
export function minChildren(children: ChildrenConfig | undefined): number {
|
|
77
|
+
return children !== undefined && "min" in children ? (children.min ?? 1) : 1;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The content expression for "any blocks": the `BLOCK_GROUP_CHILD_GROUP` group
|
|
82
|
+
* itself, or, for a layout block that excludes some layout block types, the group's
|
|
83
|
+
* other members spelled out: `blockContainer` (the node every regular block
|
|
84
|
+
* shares) and the layout block types placeable anywhere. That takes the whole
|
|
85
|
+
* schema, which is why only a layout block with `exclude` needs it.
|
|
86
|
+
*/
|
|
87
|
+
export function anyBlocksExpression(
|
|
88
|
+
exclude: readonly string[],
|
|
89
|
+
blockSpecs: Record<
|
|
90
|
+
string,
|
|
91
|
+
{ config: Pick<BlockConfig, "layoutOnly" | "placeable"> }
|
|
92
|
+
>,
|
|
93
|
+
): string {
|
|
94
|
+
if (exclude.length === 0) {
|
|
95
|
+
return BLOCK_GROUP_CHILD_GROUP;
|
|
96
|
+
}
|
|
97
|
+
const layoutBlocks = Object.entries(blockSpecs)
|
|
98
|
+
.filter(
|
|
99
|
+
([type, { config }]) =>
|
|
100
|
+
config.layoutOnly === true &&
|
|
101
|
+
config.placeable !== "namedOnly" &&
|
|
102
|
+
!exclude.includes(type),
|
|
103
|
+
)
|
|
104
|
+
.map(([type]) => type);
|
|
105
|
+
const members = ["blockContainer", ...layoutBlocks];
|
|
106
|
+
return members.length === 1 ? members[0] : `(${members.join(" | ")})`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Compiles a layout block's `children` config into its node's ProseMirror content
|
|
111
|
+
* expression: which types may be its children (`allow`), followed by how few
|
|
112
|
+
* of them it takes (`min`). `anyBlocks` is what `allow: "blocks"` stands for:
|
|
113
|
+
* the group, unless the layout block excludes types (see `anyBlocksExpression`).
|
|
114
|
+
*/
|
|
115
|
+
export function childrenContentExpression(
|
|
116
|
+
children: ChildrenConfig = {},
|
|
117
|
+
anyBlocks: string = BLOCK_GROUP_CHILD_GROUP,
|
|
118
|
+
): string {
|
|
119
|
+
const { allow = "blocks" } = children;
|
|
120
|
+
const min = minChildren(children);
|
|
121
|
+
|
|
122
|
+
let allowed: string;
|
|
123
|
+
if (allow === "blocks") {
|
|
124
|
+
allowed = anyBlocks;
|
|
125
|
+
} else {
|
|
126
|
+
if (allow.length === 0) {
|
|
127
|
+
throw new Error(
|
|
128
|
+
"Layout block `allow` permits nothing. A layout block must accept at least one block or layout block type; drop `children` entirely for a block that holds none.",
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
allowed = allow.length === 1 ? allow[0] : `(${allow.join(" | ")})`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return allowed + (min === 0 ? "*" : min === 1 ? "+" : `{${min},}`);
|
|
136
|
+
}
|