@blocknote/core 0.55.0 → 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-DaEUT0O1.js → blocks-COYcDVg7.js} +1572 -1156
- 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.js +12 -12
- package/dist/{en-BAn9gxr-.js → en-Ch-vvt5e.js} +36 -2
- 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 +771 -23
- 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-D5w0XAHX.js → src-BmLsLZfE.js} +1390 -1278
- 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 +8 -8
- 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/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 +71 -9
- package/src/editor/BlockNoteExtension.ts +5 -5
- 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/ExtensionManager/ExtensionManager.browser.test.ts +45 -0
- package/src/editor/managers/ExtensionManager/ExtensionManager.node.test.ts +209 -0
- package/src/editor/managers/ExtensionManager/extensions.ts +10 -1
- package/src/editor/managers/ExtensionManager/index.ts +135 -68
- package/src/editor/managers/StateManager.ts +14 -4
- 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 +7 -1
- 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 -764
- 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.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 +32 -0
- package/src/i18n/locales/de.ts +32 -0
- package/src/i18n/locales/en.ts +32 -0
- package/src/i18n/locales/es.ts +32 -0
- package/src/i18n/locales/fa.ts +32 -0
- package/src/i18n/locales/fr.ts +32 -0
- package/src/i18n/locales/he.ts +32 -0
- package/src/i18n/locales/hr.ts +32 -0
- package/src/i18n/locales/is.ts +32 -0
- package/src/i18n/locales/it.ts +32 -0
- package/src/i18n/locales/ja.ts +32 -0
- package/src/i18n/locales/ko.ts +32 -0
- package/src/i18n/locales/nl.ts +32 -0
- package/src/i18n/locales/no.ts +32 -0
- package/src/i18n/locales/pl.ts +32 -0
- package/src/i18n/locales/pt.ts +32 -0
- package/src/i18n/locales/ru.ts +32 -0
- package/src/i18n/locales/sk.ts +32 -0
- package/src/i18n/locales/uk.ts +32 -0
- package/src/i18n/locales/uz.ts +32 -0
- package/src/i18n/locales/vi.ts +32 -0
- package/src/i18n/locales/zh-tw.ts +32 -0
- package/src/i18n/locales/zh.ts +32 -0
- package/src/index.ts +13 -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/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/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/editor/BlockNoteEditor.d.ts +36 -8
- package/types/src/editor/BlockNoteEditor.node.test.d.ts +1 -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/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/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/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 +32 -0
- package/types/src/i18n/locales/fa.d.ts +32 -0
- package/types/src/i18n/locales/sk.d.ts +32 -0
- package/types/src/index.d.ts +6 -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/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-DLgTreVu.cjs +0 -12
- package/dist/blocks-DLgTreVu.cjs.map +0 -1
- package/dist/blocks-DaEUT0O1.js.map +0 -1
- package/dist/en-BAn9gxr-.js.map +0 -1
- package/dist/en-CHnrV5l8.cjs +0 -2
- package/dist/en-CHnrV5l8.cjs.map +0 -1
- package/dist/extensions-B1JQURVF.js +0 -2138
- package/dist/extensions-B1JQURVF.js.map +0 -1
- package/dist/extensions-CZkqKzJO.cjs +0 -58
- package/dist/extensions-CZkqKzJO.cjs.map +0 -1
- package/dist/src-D5w0XAHX.js.map +0 -1
- package/dist/src-th5uZEvx.cjs +0 -23
- package/dist/src-th5uZEvx.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,69 @@
|
|
|
1
|
+
import { camelToDataKebab } from "../util/string.js";
|
|
2
|
+
import type { PropSchema, Props } from "./propTypes.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The prop names to visit: the props' own order first, so an element's
|
|
6
|
+
* attributes keep the order its props were given in, then the schema's for
|
|
7
|
+
* the props left out. A prop the schema does not know has no attribute.
|
|
8
|
+
*/
|
|
9
|
+
function propNames<PSchema extends PropSchema>(
|
|
10
|
+
props: Partial<Props<PSchema>>,
|
|
11
|
+
propSchema: PSchema,
|
|
12
|
+
): (keyof PSchema & string)[] {
|
|
13
|
+
const names = new Set([...Object.keys(props), ...Object.keys(propSchema)]);
|
|
14
|
+
return [...names].filter((name) => name in propSchema);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The `data-*` attributes `props` serialize to: a `data-kebab-case` attribute
|
|
19
|
+
* holding each prop's value as a string, except props at their default (or
|
|
20
|
+
* absent), which have none. Parsing (`propsToAttributes`' `parseHTML`) reads
|
|
21
|
+
* these names back, so the rule lives here only. The result is what a new
|
|
22
|
+
* element gets set, what React spreads, and what tiptap merges into a node's
|
|
23
|
+
* HTML attributes.
|
|
24
|
+
*/
|
|
25
|
+
export function propsToDataAttributes<PSchema extends PropSchema>(
|
|
26
|
+
props: Partial<Props<PSchema>>,
|
|
27
|
+
propSchema: PSchema,
|
|
28
|
+
): Record<string, string> {
|
|
29
|
+
const attributes: Record<string, string> = {};
|
|
30
|
+
for (const name of propNames(props, propSchema)) {
|
|
31
|
+
const value = props[name];
|
|
32
|
+
if (value !== undefined && value !== propSchema[name].default) {
|
|
33
|
+
attributes[camelToDataKebab(name)] = String(value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return attributes;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Sets `attributes` on a new element. Nothing is removed. */
|
|
40
|
+
export function setDataAttributes(
|
|
41
|
+
element: HTMLElement,
|
|
42
|
+
attributes: Record<string, string>,
|
|
43
|
+
) {
|
|
44
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
45
|
+
element.setAttribute(name, value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Makes an element's prop attributes follow `props`: sets those of the
|
|
51
|
+
* non-default props and removes those of every other prop in the schema, so
|
|
52
|
+
* an element that lives across updates (a layout block's root, the table view)
|
|
53
|
+
* drops stale attributes, including ones its author set.
|
|
54
|
+
*/
|
|
55
|
+
export function applyDataAttributes<PSchema extends PropSchema>(
|
|
56
|
+
element: HTMLElement,
|
|
57
|
+
props: Partial<Props<PSchema>>,
|
|
58
|
+
propSchema: PSchema,
|
|
59
|
+
) {
|
|
60
|
+
const attributes = propsToDataAttributes(props, propSchema);
|
|
61
|
+
for (const name of propNames(props, propSchema)) {
|
|
62
|
+
const attribute = camelToDataKebab(name);
|
|
63
|
+
if (attribute in attributes) {
|
|
64
|
+
element.setAttribute(attribute, attributes[attribute]);
|
|
65
|
+
} else {
|
|
66
|
+
element.removeAttribute(attribute);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/schema/index.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export * from "./blocks/createSpec.js";
|
|
2
|
+
export * from "./blocks/frame.js";
|
|
2
3
|
export * from "./blocks/internal.js";
|
|
3
4
|
export * from "./blocks/types.js";
|
|
5
|
+
export * from "./dataAttributes.js";
|
|
6
|
+
export type { BlockKeyboard, BlockKeyboardOption } from "./blocks/keyboard.js";
|
|
4
7
|
export * from "./inlineContent/createSpec.js";
|
|
5
8
|
export * from "./inlineContent/internal.js";
|
|
6
9
|
export * from "./inlineContent/types.js";
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
Extension,
|
|
5
5
|
ExtensionFactoryInstance,
|
|
6
6
|
} from "../../editor/BlockNoteExtension.js";
|
|
7
|
-
import {
|
|
7
|
+
import { propsToDataAttributes, setDataAttributes } from "../dataAttributes.js";
|
|
8
8
|
import { PropSchema, Props } from "../propTypes.js";
|
|
9
9
|
import {
|
|
10
10
|
CustomInlineContentConfig,
|
|
@@ -34,17 +34,12 @@ export function addInlineContentAttributes<
|
|
|
34
34
|
} {
|
|
35
35
|
// Sets content type attribute
|
|
36
36
|
element.dom.setAttribute("data-inline-content-type", inlineContentType);
|
|
37
|
-
// Adds props as
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
})
|
|
44
|
-
.map(([prop, value]) => {
|
|
45
|
-
return [camelToDataKebab(prop), value];
|
|
46
|
-
})
|
|
47
|
-
.forEach(([prop, value]) => element.dom.setAttribute(prop, value));
|
|
37
|
+
// Adds the props as `data-*` attributes, leaving out those at their default.
|
|
38
|
+
// Set only: the element is the author's, and their own attributes stay.
|
|
39
|
+
setDataAttributes(
|
|
40
|
+
element.dom,
|
|
41
|
+
propsToDataAttributes(inlineContentProps, propSchema),
|
|
42
|
+
);
|
|
48
43
|
|
|
49
44
|
if (element.contentDOM) {
|
|
50
45
|
element.contentDOM.setAttribute("data-editable", "");
|
package/src/schema/markGroups.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Editor, getExtensionField } from "@tiptap/core";
|
|
1
|
+
import { Editor, flattenExtensions, getExtensionField } from "@tiptap/core";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* ProseMirror mark group for "non-formatting" marks: comments and the
|
|
@@ -36,7 +36,9 @@ export function nonFormattingMarks(editor: Editor | undefined): string {
|
|
|
36
36
|
if (!editor) {
|
|
37
37
|
return "";
|
|
38
38
|
}
|
|
39
|
-
const hasNonFormattingMark =
|
|
39
|
+
const hasNonFormattingMark = flattenExtensions(
|
|
40
|
+
editor.options.extensions,
|
|
41
|
+
).some((extension) => {
|
|
40
42
|
if (extension.type !== "mark") {
|
|
41
43
|
return false;
|
|
42
44
|
}
|
|
@@ -48,3 +50,33 @@ export function nonFormattingMarks(editor: Editor | undefined): string {
|
|
|
48
50
|
});
|
|
49
51
|
return hasNonFormattingMark ? NON_FORMATTING_MARK_GROUP : "";
|
|
50
52
|
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The `excludes` field value for marks which may coexist with annotation marks
|
|
56
|
+
* but should exclude all other marks.
|
|
57
|
+
*
|
|
58
|
+
* Returns `"_"` when no editor is available, preserving ProseMirror's default
|
|
59
|
+
* behavior for schema creation outside an editor.
|
|
60
|
+
*/
|
|
61
|
+
export function marksExcludingNonFormattingMarks(
|
|
62
|
+
editor: Editor | undefined,
|
|
63
|
+
): string {
|
|
64
|
+
if (!editor) {
|
|
65
|
+
return "_";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return flattenExtensions(editor.options.extensions)
|
|
69
|
+
.filter((extension) => {
|
|
70
|
+
if (extension.type !== "mark") {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const group = getExtensionField(extension, "group") as string | undefined;
|
|
75
|
+
return (
|
|
76
|
+
typeof group !== "string" ||
|
|
77
|
+
!group.split(" ").includes(NON_FORMATTING_MARK_GROUP)
|
|
78
|
+
);
|
|
79
|
+
})
|
|
80
|
+
.map((extension) => extension.name)
|
|
81
|
+
.join(" ");
|
|
82
|
+
}
|
package/src/schema/schema.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
getInlineContentSchemaFromSpecs,
|
|
17
17
|
getStyleSchemaFromSpecs,
|
|
18
18
|
} from "./index.js";
|
|
19
|
+
import { validateChildrenConfigs } from "./blocks/validateChildren.js";
|
|
19
20
|
|
|
20
21
|
function removeUndefined<T extends Record<string, any> | undefined>(obj: T): T {
|
|
21
22
|
if (!obj) {
|
|
@@ -91,6 +92,10 @@ export class CustomBlockNoteSchema<
|
|
|
91
92
|
})),
|
|
92
93
|
);
|
|
93
94
|
|
|
95
|
+
// Validation runs before the nodes are built, so the misconfigurations
|
|
96
|
+
// ProseMirror cannot report on its own surface as clear errors.
|
|
97
|
+
validateChildrenConfigs(this.opts.blockSpecs);
|
|
98
|
+
|
|
94
99
|
const blockSpecs = Object.fromEntries(
|
|
95
100
|
Object.entries(this.opts.blockSpecs).map(([key, blockSpec]) => {
|
|
96
101
|
return [
|
|
@@ -193,7 +198,9 @@ export class CustomBlockNoteSchema<
|
|
|
193
198
|
AdditionalInlineContentSpecs extends undefined | Record<string, never>
|
|
194
199
|
? ISchema
|
|
195
200
|
: ISchema & {
|
|
196
|
-
[
|
|
201
|
+
[
|
|
202
|
+
K in keyof AdditionalInlineContentSpecs
|
|
203
|
+
]: AdditionalInlineContentSpecs[K]["config"];
|
|
197
204
|
},
|
|
198
205
|
AdditionalStyleSpecs extends undefined | Record<string, never>
|
|
199
206
|
? SSchema
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { describe, expect, it } from "vite-plus/test";
|
|
2
|
+
|
|
3
|
+
import type { User } from "./UserStore.js";
|
|
4
|
+
import { createUserStore } from "./UserStore.js";
|
|
5
|
+
import {
|
|
6
|
+
colorsForUserIds,
|
|
7
|
+
fallbackColorForUserId,
|
|
8
|
+
userColorPalette,
|
|
9
|
+
userMarkColors,
|
|
10
|
+
} from "./userColors.js";
|
|
11
|
+
|
|
12
|
+
describe("userColorPalette", () => {
|
|
13
|
+
it("contains no red or green", () => {
|
|
14
|
+
// The palette tints insertions as well as deletions, and diffs use red for
|
|
15
|
+
// deleted and green for inserted content. Guard the property rather than
|
|
16
|
+
// the exact hexes: no entry may have a red or a green hue.
|
|
17
|
+
for (const { light, dark } of userColorPalette) {
|
|
18
|
+
for (const color of [light, dark]) {
|
|
19
|
+
const [r, g, b] = [1, 3, 5].map(
|
|
20
|
+
(offset) => parseInt(color.slice(offset, offset + 2), 16) / 255,
|
|
21
|
+
);
|
|
22
|
+
const max = Math.max(r, g, b);
|
|
23
|
+
const delta = max - Math.min(r, g, b);
|
|
24
|
+
if (delta < 0.05) {
|
|
25
|
+
continue; // grey: no hue
|
|
26
|
+
}
|
|
27
|
+
const hue =
|
|
28
|
+
(60 *
|
|
29
|
+
(max === r
|
|
30
|
+
? ((g - b) / delta) % 6
|
|
31
|
+
: max === g
|
|
32
|
+
? (b - r) / delta + 2
|
|
33
|
+
: (r - g) / delta + 4) +
|
|
34
|
+
360) %
|
|
35
|
+
360;
|
|
36
|
+
expect(hue >= 340 || hue <= 20, `${color} reads as red`).toBe(false);
|
|
37
|
+
expect(hue >= 90 && hue <= 160, `${color} reads as green`).toBe(false);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("assigns a stable entry per user id", () => {
|
|
43
|
+
expect(fallbackColorForUserId("alice")).toEqual(
|
|
44
|
+
fallbackColorForUserId("alice"),
|
|
45
|
+
);
|
|
46
|
+
expect(userColorPalette).toContainEqual(fallbackColorForUserId("alice"));
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("userMarkColors", () => {
|
|
51
|
+
it("is undefined for a user with no color", () => {
|
|
52
|
+
expect(userMarkColors(undefined)).toBeUndefined();
|
|
53
|
+
expect(userMarkColors({})).toBeUndefined();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("uses both colors when the app supplies both", () => {
|
|
57
|
+
expect(userMarkColors({ color: "#123456", colorLight: "#abcdef" })).toEqual(
|
|
58
|
+
{
|
|
59
|
+
light: "#abcdef",
|
|
60
|
+
dark: "#123456",
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("derives the light tint when only `color` is set", () => {
|
|
66
|
+
expect(userMarkColors({ color: "#123456" })).toEqual({
|
|
67
|
+
light: "color-mix(in srgb, #123456 30%, white)",
|
|
68
|
+
dark: "#123456",
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("colorsForUserIds", () => {
|
|
74
|
+
it("falls back to the first palette entry with no ids", () => {
|
|
75
|
+
const store = createUserStore<User>(async () => []);
|
|
76
|
+
expect(colorsForUserIds(store, undefined)).toEqual(userColorPalette[0]);
|
|
77
|
+
expect(colorsForUserIds(store, [])).toEqual(userColorPalette[0]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("falls back to the id's palette entry for an unresolved user", () => {
|
|
81
|
+
const store = createUserStore<User>(async () => []);
|
|
82
|
+
expect(colorsForUserIds(store, ["alice"])).toEqual(
|
|
83
|
+
fallbackColorForUserId("alice"),
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("uses the resolved user's own colors, deriving the tint when needed", async () => {
|
|
88
|
+
const store = createUserStore<User>(async (ids: string[]) =>
|
|
89
|
+
ids.map((id) => ({
|
|
90
|
+
id,
|
|
91
|
+
username: id,
|
|
92
|
+
avatarUrl: "",
|
|
93
|
+
color: id === "both" ? "#123456" : "#654321",
|
|
94
|
+
...(id === "both" ? { colorLight: "#abcdef" } : {}),
|
|
95
|
+
})),
|
|
96
|
+
);
|
|
97
|
+
await store.loadUsers(["both", "dark-only"]);
|
|
98
|
+
|
|
99
|
+
expect(colorsForUserIds(store, ["both"])).toEqual({
|
|
100
|
+
light: "#abcdef",
|
|
101
|
+
dark: "#123456",
|
|
102
|
+
});
|
|
103
|
+
expect(colorsForUserIds(store, ["dark-only"])).toEqual({
|
|
104
|
+
light: "color-mix(in srgb, #654321 30%, white)",
|
|
105
|
+
dark: "#654321",
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
package/src/user/userColors.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { digestString } from "lib0/hash/fnv1a";
|
|
2
|
-
import type { UserStore } from "./UserStore.js";
|
|
2
|
+
import type { User, UserStore } from "./UserStore.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Deterministic hash of a string to an unsigned 32-bit integer.
|
|
@@ -12,13 +12,22 @@ const hashStr = (s: string): number => {
|
|
|
12
12
|
return Math.abs(hash);
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Fallback palette used when a user has no resolved color of their own.
|
|
17
|
+
*
|
|
18
|
+
* Deliberately free of red and green: these colors tint *insertions* as well as
|
|
19
|
+
* deletions, and diffs conventionally use red for deleted and green for
|
|
20
|
+
* inserted content. A red insertion would read as a deletion, and a green
|
|
21
|
+
* deletion as an insertion. The hues are spread far enough apart to stay
|
|
22
|
+
* distinguishable for the most common forms of colour-vision deficiency.
|
|
23
|
+
*/
|
|
16
24
|
export const userColorPalette: Array<{ light: string; dark: string }> = [
|
|
17
|
-
{ light: "#fff0c2", dark: "#8a6d1a" },
|
|
18
|
-
{ light: "#
|
|
19
|
-
{ light: "#
|
|
20
|
-
{ light: "#
|
|
21
|
-
{ light: "#
|
|
25
|
+
{ light: "#fff0c2", dark: "#8a6d1a" }, // amber
|
|
26
|
+
{ light: "#cdeffd", dark: "#0b6a8a" }, // sky
|
|
27
|
+
{ light: "#d6defd", dark: "#2948b3" }, // blue
|
|
28
|
+
{ light: "#eadcfb", dark: "#6b2fa3" }, // violet
|
|
29
|
+
{ light: "#f1e2d3", dark: "#7a4a1e" }, // brown
|
|
30
|
+
{ light: "#dfe4ea", dark: "#46525f" }, // slate
|
|
22
31
|
];
|
|
23
32
|
|
|
24
33
|
/** The deterministic {@link userColorPalette} entry for a single user id. */
|
|
@@ -28,7 +37,28 @@ export const fallbackColorForUserId = (
|
|
|
28
37
|
userColorPalette[hashStr(id) % userColorPalette.length];
|
|
29
38
|
|
|
30
39
|
/**
|
|
31
|
-
*
|
|
40
|
+
* A user's own mark colors, or `undefined` when they have none.
|
|
41
|
+
*
|
|
42
|
+
* `color` is the saturated color the app already uses for that user (cursors,
|
|
43
|
+
* avatars); `colorLight` is the pale background a mark is highlighted with. Most
|
|
44
|
+
* applications only set the former, so derive the latter rather than fall back
|
|
45
|
+
* to a palette entry that has nothing to do with the user's actual color — a
|
|
46
|
+
* user whose cursor is green shouldn't have amber marks.
|
|
47
|
+
*/
|
|
48
|
+
export const userMarkColors = (
|
|
49
|
+
user: Pick<User, "color" | "colorLight"> | undefined,
|
|
50
|
+
): { light: string; dark: string } | undefined => {
|
|
51
|
+
if (!user?.color) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
light: user.colorLight ?? `color-mix(in srgb, ${user.color} 30%, white)`,
|
|
56
|
+
dark: user.color,
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The (first) user's {@link userMarkColors}, or their
|
|
32
62
|
* {@link fallbackColorForUserId} palette entry. Used where a concrete color
|
|
33
63
|
* string is needed (the portaled hover tooltip); marks themselves use the
|
|
34
64
|
* cascaded {@link userColorVarNames} properties instead.
|
|
@@ -41,11 +71,10 @@ export const colorsForUserIds = (
|
|
|
41
71
|
return userColorPalette[0];
|
|
42
72
|
}
|
|
43
73
|
const firstId = userIds[0];
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return fallbackColorForUserId(firstId);
|
|
74
|
+
return (
|
|
75
|
+
userMarkColors(userStore.getUser(firstId)) ??
|
|
76
|
+
fallbackColorForUserId(firstId)
|
|
77
|
+
);
|
|
49
78
|
};
|
|
50
79
|
|
|
51
80
|
/**
|
|
@@ -21,7 +21,7 @@ export class RESTYjsThreadStore extends YjsThreadStoreBase {
|
|
|
21
21
|
constructor(
|
|
22
22
|
private readonly BASE_URL: string,
|
|
23
23
|
private readonly headers: Record<string, string>,
|
|
24
|
-
threadsYType: Y.
|
|
24
|
+
threadsYType: Y.Node,
|
|
25
25
|
auth: ThreadStoreAuth,
|
|
26
26
|
) {
|
|
27
27
|
super(threadsYType, auth);
|
|
@@ -14,7 +14,7 @@ vi.mock("lib0/random", async (importOriginal) => ({
|
|
|
14
14
|
describe("YjsThreadStore (@y/y v14)", () => {
|
|
15
15
|
let store: YjsThreadStore;
|
|
16
16
|
let doc: Y.Doc;
|
|
17
|
-
let threadsYType: Y.
|
|
17
|
+
let threadsYType: Y.Node;
|
|
18
18
|
|
|
19
19
|
beforeEach(() => {
|
|
20
20
|
// Reset mocks and create fresh instances
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
export class YjsThreadStore extends YjsThreadStoreBase {
|
|
30
30
|
constructor(
|
|
31
31
|
private readonly userId: string,
|
|
32
|
-
threadsYType: Y.
|
|
32
|
+
threadsYType: Y.Node,
|
|
33
33
|
auth: ThreadStoreAuth,
|
|
34
34
|
) {
|
|
35
35
|
super(threadsYType, auth);
|
|
@@ -98,7 +98,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
|
|
|
98
98
|
threadId: string;
|
|
99
99
|
}) => {
|
|
100
100
|
const yThread = this.threadsYType.getAttr(options.threadId) as
|
|
101
|
-
| Y.
|
|
101
|
+
| Y.Node
|
|
102
102
|
| undefined;
|
|
103
103
|
if (!yThread) {
|
|
104
104
|
throw new Error("Thread not found");
|
|
@@ -121,7 +121,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
|
|
|
121
121
|
body: options.comment.body,
|
|
122
122
|
};
|
|
123
123
|
|
|
124
|
-
(yThread.getAttr("comments") as Y.
|
|
124
|
+
(yThread.getAttr("comments") as Y.Node).push([commentToYType(comment)]);
|
|
125
125
|
|
|
126
126
|
yThread.setAttr("updatedAt", new Date().getTime());
|
|
127
127
|
return comment;
|
|
@@ -138,23 +138,23 @@ export class YjsThreadStore extends YjsThreadStoreBase {
|
|
|
138
138
|
commentId: string;
|
|
139
139
|
}) => {
|
|
140
140
|
const yThread = this.threadsYType.getAttr(options.threadId) as
|
|
141
|
-
| Y.
|
|
141
|
+
| Y.Node
|
|
142
142
|
| undefined;
|
|
143
143
|
if (!yThread) {
|
|
144
144
|
throw new Error("Thread not found");
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
const commentsType = yThread.getAttr("comments") as Y.
|
|
147
|
+
const commentsType = yThread.getAttr("comments") as Y.Node;
|
|
148
148
|
const yCommentIndex = yTypeFindIndex(
|
|
149
149
|
commentsType,
|
|
150
|
-
(comment) => (comment as Y.
|
|
150
|
+
(comment) => (comment as Y.Node).getAttr("id") === options.commentId,
|
|
151
151
|
);
|
|
152
152
|
|
|
153
153
|
if (yCommentIndex === -1) {
|
|
154
154
|
throw new Error("Comment not found");
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
const yComment = commentsType.get(yCommentIndex) as Y.
|
|
157
|
+
const yComment = commentsType.get(yCommentIndex) as Y.Node;
|
|
158
158
|
|
|
159
159
|
if (!this.auth.canUpdateComment(yTypeToComment(yComment))) {
|
|
160
160
|
throw new Error("Not authorized");
|
|
@@ -173,23 +173,23 @@ export class YjsThreadStore extends YjsThreadStoreBase {
|
|
|
173
173
|
softDelete?: boolean;
|
|
174
174
|
}) => {
|
|
175
175
|
const yThread = this.threadsYType.getAttr(options.threadId) as
|
|
176
|
-
| Y.
|
|
176
|
+
| Y.Node
|
|
177
177
|
| undefined;
|
|
178
178
|
if (!yThread) {
|
|
179
179
|
throw new Error("Thread not found");
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
const commentsType = yThread.getAttr("comments") as Y.
|
|
182
|
+
const commentsType = yThread.getAttr("comments") as Y.Node;
|
|
183
183
|
const yCommentIndex = yTypeFindIndex(
|
|
184
184
|
commentsType,
|
|
185
|
-
(comment) => (comment as Y.
|
|
185
|
+
(comment) => (comment as Y.Node).getAttr("id") === options.commentId,
|
|
186
186
|
);
|
|
187
187
|
|
|
188
188
|
if (yCommentIndex === -1) {
|
|
189
189
|
throw new Error("Comment not found");
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
const yComment = commentsType.get(yCommentIndex) as Y.
|
|
192
|
+
const yComment = commentsType.get(yCommentIndex) as Y.Node;
|
|
193
193
|
|
|
194
194
|
if (!this.auth.canDeleteComment(yTypeToComment(yComment))) {
|
|
195
195
|
throw new Error("Not authorized");
|
|
@@ -209,7 +209,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
|
|
|
209
209
|
if (
|
|
210
210
|
commentsType
|
|
211
211
|
.toArray()
|
|
212
|
-
.every((comment) => (comment as Y.
|
|
212
|
+
.every((comment) => (comment as Y.Node).getAttr("deletedAt"))
|
|
213
213
|
) {
|
|
214
214
|
// all comments deleted
|
|
215
215
|
if (options.softDelete) {
|
|
@@ -226,7 +226,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
|
|
|
226
226
|
public deleteThread = this.transact((options: { threadId: string }) => {
|
|
227
227
|
if (
|
|
228
228
|
!this.auth.canDeleteThread(
|
|
229
|
-
yTypeToThread(this.threadsYType.getAttr(options.threadId) as Y.
|
|
229
|
+
yTypeToThread(this.threadsYType.getAttr(options.threadId) as Y.Node),
|
|
230
230
|
)
|
|
231
231
|
) {
|
|
232
232
|
throw new Error("Not authorized");
|
|
@@ -237,7 +237,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
|
|
|
237
237
|
|
|
238
238
|
public resolveThread = this.transact((options: { threadId: string }) => {
|
|
239
239
|
const yThread = this.threadsYType.getAttr(options.threadId) as
|
|
240
|
-
| Y.
|
|
240
|
+
| Y.Node
|
|
241
241
|
| undefined;
|
|
242
242
|
if (!yThread) {
|
|
243
243
|
throw new Error("Thread not found");
|
|
@@ -254,7 +254,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
|
|
|
254
254
|
|
|
255
255
|
public unresolveThread = this.transact((options: { threadId: string }) => {
|
|
256
256
|
const yThread = this.threadsYType.getAttr(options.threadId) as
|
|
257
|
-
| Y.
|
|
257
|
+
| Y.Node
|
|
258
258
|
| undefined;
|
|
259
259
|
if (!yThread) {
|
|
260
260
|
throw new Error("Thread not found");
|
|
@@ -271,23 +271,23 @@ export class YjsThreadStore extends YjsThreadStoreBase {
|
|
|
271
271
|
public addReaction = this.transact(
|
|
272
272
|
(options: { threadId: string; commentId: string; emoji: string }) => {
|
|
273
273
|
const yThread = this.threadsYType.getAttr(options.threadId) as
|
|
274
|
-
| Y.
|
|
274
|
+
| Y.Node
|
|
275
275
|
| undefined;
|
|
276
276
|
if (!yThread) {
|
|
277
277
|
throw new Error("Thread not found");
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
-
const commentsType = yThread.getAttr("comments") as Y.
|
|
280
|
+
const commentsType = yThread.getAttr("comments") as Y.Node;
|
|
281
281
|
const yCommentIndex = yTypeFindIndex(
|
|
282
282
|
commentsType,
|
|
283
|
-
(comment) => (comment as Y.
|
|
283
|
+
(comment) => (comment as Y.Node).getAttr("id") === options.commentId,
|
|
284
284
|
);
|
|
285
285
|
|
|
286
286
|
if (yCommentIndex === -1) {
|
|
287
287
|
throw new Error("Comment not found");
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
const yComment = commentsType.get(yCommentIndex) as Y.
|
|
290
|
+
const yComment = commentsType.get(yCommentIndex) as Y.Node;
|
|
291
291
|
|
|
292
292
|
if (!this.auth.canAddReaction(yTypeToComment(yComment), options.emoji)) {
|
|
293
293
|
throw new Error("Not authorized");
|
|
@@ -297,13 +297,13 @@ export class YjsThreadStore extends YjsThreadStoreBase {
|
|
|
297
297
|
|
|
298
298
|
const key = `${this.userId}-${options.emoji}`;
|
|
299
299
|
|
|
300
|
-
const reactionsByUser = yComment.getAttr("reactionsByUser") as Y.
|
|
300
|
+
const reactionsByUser = yComment.getAttr("reactionsByUser") as Y.Node;
|
|
301
301
|
|
|
302
302
|
if (reactionsByUser.hasAttr(key)) {
|
|
303
303
|
// already exists
|
|
304
304
|
return;
|
|
305
305
|
} else {
|
|
306
|
-
const reaction = new Y.
|
|
306
|
+
const reaction = new Y.Node();
|
|
307
307
|
reaction.setAttr("emoji", options.emoji);
|
|
308
308
|
reaction.setAttr("createdAt", date.getTime());
|
|
309
309
|
reaction.setAttr("userId", this.userId);
|
|
@@ -315,23 +315,23 @@ export class YjsThreadStore extends YjsThreadStoreBase {
|
|
|
315
315
|
public deleteReaction = this.transact(
|
|
316
316
|
(options: { threadId: string; commentId: string; emoji: string }) => {
|
|
317
317
|
const yThread = this.threadsYType.getAttr(options.threadId) as
|
|
318
|
-
| Y.
|
|
318
|
+
| Y.Node
|
|
319
319
|
| undefined;
|
|
320
320
|
if (!yThread) {
|
|
321
321
|
throw new Error("Thread not found");
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
-
const commentsType = yThread.getAttr("comments") as Y.
|
|
324
|
+
const commentsType = yThread.getAttr("comments") as Y.Node;
|
|
325
325
|
const yCommentIndex = yTypeFindIndex(
|
|
326
326
|
commentsType,
|
|
327
|
-
(comment) => (comment as Y.
|
|
327
|
+
(comment) => (comment as Y.Node).getAttr("id") === options.commentId,
|
|
328
328
|
);
|
|
329
329
|
|
|
330
330
|
if (yCommentIndex === -1) {
|
|
331
331
|
throw new Error("Comment not found");
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
-
const yComment = commentsType.get(yCommentIndex) as Y.
|
|
334
|
+
const yComment = commentsType.get(yCommentIndex) as Y.Node;
|
|
335
335
|
|
|
336
336
|
if (
|
|
337
337
|
!this.auth.canDeleteReaction(yTypeToComment(yComment), options.emoji)
|
|
@@ -341,14 +341,14 @@ export class YjsThreadStore extends YjsThreadStoreBase {
|
|
|
341
341
|
|
|
342
342
|
const key = `${this.userId}-${options.emoji}`;
|
|
343
343
|
|
|
344
|
-
const reactionsByUser = yComment.getAttr("reactionsByUser") as Y.
|
|
344
|
+
const reactionsByUser = yComment.getAttr("reactionsByUser") as Y.Node;
|
|
345
345
|
|
|
346
346
|
reactionsByUser.deleteAttr(key);
|
|
347
347
|
},
|
|
348
348
|
);
|
|
349
349
|
}
|
|
350
350
|
|
|
351
|
-
function yTypeFindIndex(yType: Y.
|
|
351
|
+
function yTypeFindIndex(yType: Y.Node, predicate: (item: any) => boolean) {
|
|
352
352
|
for (let i = 0; i < yType.length; i++) {
|
|
353
353
|
if (predicate(yType.get(i))) {
|
|
354
354
|
return i;
|
|
@@ -10,7 +10,7 @@ import { yTypeToThread } from "./yjsHelpers.js";
|
|
|
10
10
|
*/
|
|
11
11
|
export abstract class YjsThreadStoreBase extends ThreadStore {
|
|
12
12
|
constructor(
|
|
13
|
-
protected readonly threadsYType: Y.
|
|
13
|
+
protected readonly threadsYType: Y.Node,
|
|
14
14
|
auth: ThreadStoreAuth,
|
|
15
15
|
) {
|
|
16
16
|
super(auth);
|
|
@@ -29,7 +29,7 @@ export abstract class YjsThreadStoreBase extends ThreadStore {
|
|
|
29
29
|
public getThreads(): Map<string, ThreadData> {
|
|
30
30
|
const threadMap = new Map<string, ThreadData>();
|
|
31
31
|
this.threadsYType.forEachAttr((yThread: any, id: string | number) => {
|
|
32
|
-
if (yThread instanceof Y.
|
|
32
|
+
if (yThread instanceof Y.Node) {
|
|
33
33
|
threadMap.set(String(id), yTypeToThread(yThread));
|
|
34
34
|
}
|
|
35
35
|
});
|