@blocknote/core 0.56.0 → 0.57.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/NOTICE.txt +101 -0
- package/dist/BlockNoteExtension-U58cXw1g.js +64 -0
- package/dist/ThreadStore-CSEwCO0O.js +8 -0
- package/dist/{UserStore-OZJP3K8T.js → UserStore-BFv6NXA-.js} +3 -7
- package/dist/ar-DPJDxCQI.js +3 -0
- package/dist/blocknote.js +8 -6
- package/dist/blocks-BUX9dXi9.js +2063 -0
- package/dist/blocks.js +3 -2
- package/dist/comments.js +8 -9
- package/dist/de-CakHBokE.js +3 -0
- package/dist/emoji-data.js +102 -0
- package/dist/en-BGdzE27X.js +3 -0
- package/dist/{en-Ch-vvt5e.js → en-Ne9rlj9Y.js} +9 -6
- package/dist/es-VeBX6MEG.js +3 -0
- package/dist/{extensions-BbM81hHa.js → extensions-CEgexSyF.js} +846 -824
- package/dist/extensions.js +4 -4
- package/dist/fa-Dt7EYtKf.js +3 -0
- package/dist/fr-DUhhjxrJ.js +3 -0
- package/dist/getDefaultSlashMenuItems-DfDOr807.js +1939 -0
- package/dist/he-BShJg1dK.js +3 -0
- package/dist/hr-BXtyqmwg.js +3 -0
- package/dist/is-2Fb-0w_j.js +3 -0
- package/dist/it-CiZtVb3Y.js +3 -0
- package/dist/ja-CsxD3kEL.js +3 -0
- package/dist/ko-It6g03Cy.js +3 -0
- package/dist/locales.js +692 -54
- package/dist/markGroups-BszXCkX8.js +18 -0
- package/dist/nb-CLao87La.js +3 -0
- package/dist/nl-JQSo8dht.js +3 -0
- package/dist/pl-DEMBgHEP.js +3 -0
- package/dist/pt-CBCdYAax.js +3 -0
- package/dist/ru-BQk_9Q-L.js +3 -0
- package/dist/sk-kgB2DtDL.js +3 -0
- package/dist/{src-BmLsLZfE.js → src-DksfoQmN.js} +1173 -1090
- package/dist/style.css +1 -1
- package/dist/tr-DkcSXX8f.js +3 -0
- package/dist/uk-Bib-e6bV.js +3 -0
- package/dist/uz-B2jaKhJb.js +3 -0
- package/dist/vi-V_GFRxE8.js +3 -0
- package/dist/y.js +356 -361
- package/dist/yjs.js +134 -135
- package/dist/zh-hant-2ZrAkFnC.js +3 -0
- package/dist/zh-jglyCmjs.js +3 -0
- package/package.json +45 -21
- package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.fixture.d.ts +5 -0
- package/types/src/api/blockManipulation/tables/tables.d.ts +9 -4
- package/types/src/api/clipboard/fromClipboard/normalizeOfficeHTML.d.ts +5 -0
- package/types/src/api/exporters/markdown/wrapWithDelimiter.d.ts +6 -0
- package/types/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.d.ts +4 -0
- package/types/src/blocks/defaultBlocks.d.ts +10 -0
- package/types/src/editor/BlockNoteEditor.d.ts +2 -1
- package/types/src/editor/managers/ExtensionManager/index.d.ts +4 -4
- package/types/src/editor/managers/StyleManager.d.ts +2 -1
- package/types/src/emoji-data/frimousse/ar.d.ts +2 -0
- package/types/src/emoji-data/frimousse/common.d.ts +3 -0
- package/types/src/emoji-data/frimousse/de.d.ts +2 -0
- package/types/src/emoji-data/frimousse/en.d.ts +2 -0
- package/types/src/emoji-data/frimousse/es.d.ts +2 -0
- package/types/src/emoji-data/frimousse/fa.d.ts +2 -0
- package/types/src/emoji-data/frimousse/fr.d.ts +2 -0
- package/types/src/emoji-data/frimousse/he.d.ts +2 -0
- package/types/src/emoji-data/frimousse/hr.d.ts +2 -0
- package/types/src/emoji-data/frimousse/is.d.ts +2 -0
- package/types/src/emoji-data/frimousse/it.d.ts +2 -0
- package/types/src/emoji-data/frimousse/ja.d.ts +2 -0
- package/types/src/emoji-data/frimousse/ko.d.ts +2 -0
- package/types/src/emoji-data/frimousse/loadFrimousseData.d.ts +2 -0
- package/types/src/emoji-data/frimousse/nb.d.ts +2 -0
- package/types/src/emoji-data/frimousse/nl.d.ts +2 -0
- package/types/src/emoji-data/frimousse/pl.d.ts +2 -0
- package/types/src/emoji-data/frimousse/pt.d.ts +2 -0
- package/types/src/emoji-data/frimousse/ru.d.ts +2 -0
- package/types/src/emoji-data/frimousse/sk.d.ts +2 -0
- package/types/src/emoji-data/frimousse/tr.d.ts +2 -0
- package/types/src/emoji-data/frimousse/types.d.ts +21 -0
- package/types/src/emoji-data/frimousse/uk.d.ts +2 -0
- package/types/src/emoji-data/frimousse/uz.d.ts +2 -0
- package/types/src/emoji-data/frimousse/vi.d.ts +2 -0
- package/types/src/emoji-data/frimousse/zh-hant.d.ts +2 -0
- package/types/src/emoji-data/frimousse/zh.d.ts +2 -0
- package/types/src/emoji-data/index.d.ts +3 -0
- package/types/src/emoji-data/searchEmojis.d.ts +5 -0
- package/types/src/extensions/Loading/Loading.d.ts +11 -0
- package/types/src/extensions/SideMenu/MultipleNodeSelection.d.ts +13 -4
- package/types/src/extensions/SideMenu/SideMenu.d.ts +2 -1
- package/types/src/extensions/Versioning/Versioning.d.ts +2 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.d.ts +1 -0
- package/types/src/extensions/Versioning/types.d.ts +12 -6
- package/types/src/extensions/Versioning/versioningState.d.ts +6 -0
- package/types/src/extensions/index.d.ts +1 -2
- package/types/src/i18n/dictionary.d.ts +4 -1
- package/types/src/i18n/locales/en.d.ts +6 -0
- package/types/src/i18n/locales/fa.d.ts +6 -0
- package/types/src/i18n/locales/index.d.ts +1 -0
- package/types/src/i18n/locales/sk.d.ts +6 -0
- package/types/src/i18n/locales/tr.d.ts +378 -0
- package/types/src/index.d.ts +0 -1
- package/types/src/schema/inlineContent/createSpec.d.ts +2 -1
- package/types/src/schema/inlineContent/internal.d.ts +1 -1
- package/types/src/schema/inlineContent/types.d.ts +2 -4
- package/types/src/schema/styles/createSpec.d.ts +2 -1
- package/types/src/schema/styles/internal.d.ts +4 -1
- package/types/src/schema/styles/types.d.ts +2 -0
- package/types/src/y/extensions/YSync.d.ts +1 -1
- package/types/src/y/extensions/index.d.ts +1 -1
- package/types/src/y/versioning/yhub.d.ts +2 -0
- package/types/src/yjs/extensions/Versioning.d.ts +1 -0
- package/types/src/yjs/extensions/YUndo.d.ts +3 -2
- package/types/src/yjs/extensions/index.d.ts +1 -1
- package/dist/BlockNoteExtension-DjEkXkR5.cjs +0 -2
- package/dist/BlockNoteExtension-DjEkXkR5.cjs.map +0 -1
- package/dist/BlockNoteExtension-TsTGtIeX.js +0 -87
- package/dist/BlockNoteExtension-TsTGtIeX.js.map +0 -1
- package/dist/ThreadStore-Bx-gSEh1.cjs +0 -2
- package/dist/ThreadStore-Bx-gSEh1.cjs.map +0 -1
- package/dist/ThreadStore-et9wB5Xt.js +0 -11
- package/dist/ThreadStore-et9wB5Xt.js.map +0 -1
- package/dist/UserStore-CTVzVGh-.cjs +0 -2
- package/dist/UserStore-CTVzVGh-.cjs.map +0 -1
- package/dist/UserStore-OZJP3K8T.js.map +0 -1
- package/dist/blocknote.cjs +0 -1
- package/dist/blocks-COVwe5Cf.cjs +0 -12
- package/dist/blocks-COVwe5Cf.cjs.map +0 -1
- package/dist/blocks-COYcDVg7.js +0 -3943
- package/dist/blocks-COYcDVg7.js.map +0 -1
- package/dist/blocks.cjs +0 -1
- package/dist/comments.cjs +0 -2
- package/dist/comments.cjs.map +0 -1
- package/dist/comments.js.map +0 -1
- package/dist/en-Ch-vvt5e.js.map +0 -1
- package/dist/en-N5lu0-j8.cjs +0 -2
- package/dist/en-N5lu0-j8.cjs.map +0 -1
- package/dist/extensions-BbM81hHa.js.map +0 -1
- package/dist/extensions-D_WkAfSt.cjs +0 -58
- package/dist/extensions-D_WkAfSt.cjs.map +0 -1
- package/dist/extensions.cjs +0 -1
- package/dist/locales.cjs +0 -2
- package/dist/locales.cjs.map +0 -1
- package/dist/locales.js.map +0 -1
- package/dist/src-4OQT3z5S.cjs +0 -23
- package/dist/src-4OQT3z5S.cjs.map +0 -1
- package/dist/src-BmLsLZfE.js.map +0 -1
- package/dist/webpack-stats.json +0 -1
- package/dist/y.cjs +0 -2
- package/dist/y.cjs.map +0 -1
- package/dist/y.js.map +0 -1
- package/dist/yjs.cjs +0 -2
- package/dist/yjs.cjs.map +0 -1
- package/dist/yjs.js.map +0 -1
- package/src/api/README.md +0 -8
- package/src/api/__snapshots__/blocks-deleted-nested-deep.json +0 -26
- package/src/api/__snapshots__/blocks-deleted-nested.json +0 -68
- package/src/api/__snapshots__/blocks-deleted.json +0 -26
- package/src/api/__snapshots__/blocks-indented-changed.json +0 -129
- package/src/api/__snapshots__/blocks-inserted-nested.json +0 -62
- package/src/api/__snapshots__/blocks-inserted.json +0 -20
- package/src/api/__snapshots__/blocks-moved-deeper-into-nesting.json +0 -164
- package/src/api/__snapshots__/blocks-moved-down-twice-in-same-parent.json +0 -44
- package/src/api/__snapshots__/blocks-moved-insert-changes-sibling-order.json +0 -26
- package/src/api/__snapshots__/blocks-moved-multiple-in-same-transaction.json +0 -188
- package/src/api/__snapshots__/blocks-moved-nested-sibling-reorder.json +0 -180
- package/src/api/__snapshots__/blocks-moved-to-different-parent.json +0 -78
- package/src/api/__snapshots__/blocks-moved-to-root-level.json +0 -78
- package/src/api/__snapshots__/blocks-moved-up-down-in-same-parent.json +0 -44
- package/src/api/__snapshots__/blocks-moved-up-down-in-same-transaction.json +0 -44
- package/src/api/__snapshots__/blocks-outdented-changed.json +0 -129
- package/src/api/__snapshots__/blocks-updated-content-inserted.json +0 -42
- package/src/api/__snapshots__/blocks-updated-multiple-insert.json +0 -50
- package/src/api/__snapshots__/blocks-updated-multiple.json +0 -82
- package/src/api/__snapshots__/blocks-updated-nested-deep.json +0 -42
- package/src/api/__snapshots__/blocks-updated-nested-multiple.json +0 -118
- package/src/api/__snapshots__/blocks-updated-nested.json +0 -78
- package/src/api/__snapshots__/blocks-updated-single.json +0 -42
- package/src/api/__snapshots__/blocks-updated.json +0 -42
- package/src/api/blockManipulation/__snapshots__/transactions.test.ts.snap +0 -34
- package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +0 -4570
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +0 -176
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +0 -95
- package/src/api/blockManipulation/commands/insertBlocks/insertPlacement.test.ts +0 -217
- package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +0 -2761
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +0 -251
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +0 -187
- package/src/api/blockManipulation/commands/moveBlocks/__snapshots__/moveBlocks.test.ts.snap +0 -13625
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +0 -391
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +0 -350
- package/src/api/blockManipulation/commands/nestBlock/__snapshots__/nestBlock.test.ts.snap +0 -952
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +0 -917
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +0 -248
- package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +0 -5710
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +0 -306
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +0 -143
- package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +0 -3507
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +0 -364
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +0 -90
- package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +0 -15085
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +0 -1210
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +0 -706
- package/src/api/blockManipulation/getBlock/getBlock.ts +0 -104
- package/src/api/blockManipulation/insertContentAt.ts +0 -83
- package/src/api/blockManipulation/layoutBlocks/fixLayoutBlock.ts +0 -173
- package/src/api/blockManipulation/layoutBlocks/layoutBlocks.browser.test.ts +0 -293
- package/src/api/blockManipulation/layoutBlocks/layoutBlocks.fixture.ts +0 -145
- package/src/api/blockManipulation/layoutBlocks/layoutBlocks.test.ts +0 -783
- package/src/api/blockManipulation/layoutBlocks/plainBlocks.test.ts +0 -180
- package/src/api/blockManipulation/layoutBlocks/titledBlocks.test.ts +0 -365
- package/src/api/blockManipulation/selections/selection.ts +0 -234
- package/src/api/blockManipulation/selections/textCursorPosition.ts +0 -63
- package/src/api/blockManipulation/setupTestEnv.ts +0 -223
- package/src/api/blockManipulation/tables/tables.test.ts +0 -2127
- package/src/api/blockManipulation/tables/tables.ts +0 -887
- package/src/api/clipboard/fromClipboard/acceptedMIMETypes.ts +0 -8
- package/src/api/clipboard/fromClipboard/fileDropExtension.ts +0 -55
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +0 -209
- package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +0 -38
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +0 -157
- package/src/api/clipboard/toClipboard/copyExtension.ts +0 -299
- package/src/api/combineTransactionSteps.ts +0 -22
- package/src/api/exporters/html/externalHTMLExporter.ts +0 -76
- package/src/api/exporters/html/internalHTMLSerializer.ts +0 -182
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +0 -510
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +0 -283
- package/src/api/exporters/markdown/htmlToMarkdown.ts +0 -895
- package/src/api/exporters/markdown/markdownExporter.ts +0 -41
- package/src/api/getBlockInfoFromPos.test.ts +0 -681
- package/src/api/getBlockInfoFromPos.ts +0 -693
- package/src/api/getBlocksChangedByTransaction.test.ts +0 -783
- package/src/api/getBlocksChangedByTransaction.ts +0 -458
- package/src/api/getChangedRangeWithAttrs.ts +0 -54
- package/src/api/getChangedRanges.test.ts +0 -391
- package/src/api/getChangedRanges.ts +0 -368
- package/src/api/nodeConversions/blockToNode.test.ts +0 -113
- package/src/api/nodeConversions/blockToNode.ts +0 -427
- package/src/api/nodeConversions/fragmentToBlocks.ts +0 -48
- package/src/api/nodeConversions/nodeToBlock.ts +0 -717
- package/src/api/nodeUtil.ts +0 -46
- package/src/api/parsers/html/parseHTML.ts +0 -80
- package/src/api/parsers/html/util/__snapshots__/nestedLists.test.ts.snap +0 -144
- package/src/api/parsers/html/util/nestedLists.test.ts +0 -165
- package/src/api/parsers/html/util/nestedLists.ts +0 -123
- package/src/api/parsers/html/util/normalizeWhitespace.ts +0 -87
- package/src/api/parsers/markdown/autolink.ts +0 -23
- package/src/api/parsers/markdown/detectMarkdown.test.ts +0 -211
- package/src/api/parsers/markdown/detectMarkdown.ts +0 -61
- package/src/api/parsers/markdown/markdownToHtml.ts +0 -1444
- package/src/api/parsers/markdown/parseMarkdown.ts +0 -24
- package/src/api/pmUtil.ts +0 -79
- package/src/api/positionMapping.test.ts +0 -209
- package/src/api/positionMapping.ts +0 -42
- package/src/blocks/Audio/block.ts +0 -171
- package/src/blocks/Audio/parseAudioElement.ts +0 -5
- package/src/blocks/BlockNoteSchema.ts +0 -59
- package/src/blocks/Code/CodeBlockOptions.ts +0 -83
- package/src/blocks/Code/block.test.ts +0 -265
- package/src/blocks/Code/block.ts +0 -56
- package/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.ts +0 -125
- package/src/blocks/Code/helpers/parse/parsePreCode.ts +0 -45
- package/src/blocks/Code/helpers/render/createCodeBlock.ts +0 -98
- package/src/blocks/Code/helpers/toExternalHTML/createPreCode.ts +0 -14
- package/src/blocks/Divider/block.ts +0 -49
- package/src/blocks/File/block.ts +0 -95
- package/src/blocks/File/helpers/parse/parseEmbedElement.ts +0 -5
- package/src/blocks/File/helpers/parse/parseFigureElement.ts +0 -16
- package/src/blocks/File/helpers/render/createAddFileButton.ts +0 -69
- package/src/blocks/File/helpers/render/createFileBlockWrapper.ts +0 -88
- package/src/blocks/File/helpers/render/createFileNameWithIcon.ts +0 -37
- package/src/blocks/File/helpers/render/createResizableFileBlockWrapper.ts +0 -271
- package/src/blocks/File/helpers/toExternalHTML/createFigureWithCaption.ts +0 -13
- package/src/blocks/File/helpers/toExternalHTML/createLinkWithCaption.ts +0 -15
- package/src/blocks/Heading/block.ts +0 -227
- package/src/blocks/Image/block.ts +0 -193
- package/src/blocks/Image/parseImageElement.ts +0 -7
- package/src/blocks/ListItem/BulletListItem/block.ts +0 -129
- package/src/blocks/ListItem/CheckListItem/block.test.ts +0 -61
- package/src/blocks/ListItem/CheckListItem/block.ts +0 -184
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +0 -352
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +0 -239
- package/src/blocks/ListItem/NumberedListItem/block.ts +0 -143
- package/src/blocks/ListItem/ToggleListItem/block.ts +0 -139
- package/src/blocks/ListItem/getListItemContent.ts +0 -115
- package/src/blocks/PageBreak/block.ts +0 -72
- package/src/blocks/PageBreak/getPageBreakSlashMenuItems.ts +0 -47
- package/src/blocks/Paragraph/block.ts +0 -80
- package/src/blocks/Quote/block.ts +0 -99
- package/src/blocks/README.md +0 -3
- package/src/blocks/Table/TableExtension.test.ts +0 -231
- package/src/blocks/Table/TableExtension.ts +0 -115
- package/src/blocks/Table/block.ts +0 -492
- package/src/blocks/ToggleWrapper/createToggleFrame.ts +0 -126
- package/src/blocks/ToggleWrapper/toggleBlocks.browser.test.ts +0 -1056
- package/src/blocks/Video/block.ts +0 -142
- package/src/blocks/Video/parseVideoElement.ts +0 -7
- package/src/blocks/defaultBlockHelpers.ts +0 -113
- package/src/blocks/defaultBlockTypeGuards.ts +0 -167
- package/src/blocks/defaultBlockTypeItems.test.ts +0 -70
- package/src/blocks/defaultBlockTypeItems.ts +0 -99
- package/src/blocks/defaultBlocks.test.ts +0 -67
- package/src/blocks/defaultBlocks.ts +0 -214
- package/src/blocks/defaultProps.ts +0 -165
- package/src/blocks/getDetailsContent.ts +0 -77
- package/src/blocks/index.ts +0 -30
- package/src/comments/CommentEditorSubmitExtension.test.ts +0 -141
- package/src/comments/CommentEditorSubmitExtension.ts +0 -56
- package/src/comments/extension.ts +0 -396
- package/src/comments/index.ts +0 -8
- package/src/comments/mark.ts +0 -64
- package/src/comments/threadstore/DefaultThreadStoreAuth.ts +0 -106
- package/src/comments/threadstore/ThreadStore.ts +0 -130
- package/src/comments/threadstore/ThreadStoreAuth.ts +0 -13
- package/src/comments/threadstore/TipTapThreadStore.ts +0 -292
- package/src/comments/threadstore/tiptap/types.ts +0 -131
- package/src/comments/types.ts +0 -121
- package/src/editor/Block.css +0 -1498
- package/src/editor/BlockNoteEditor.node.test.ts +0 -35
- package/src/editor/BlockNoteEditor.test.ts +0 -278
- package/src/editor/BlockNoteEditor.ts +0 -1559
- package/src/editor/BlockNoteExtension.test.ts +0 -103
- package/src/editor/BlockNoteExtension.ts +0 -246
- package/src/editor/README.md +0 -3
- package/src/editor/blockColors.browser.test.ts +0 -127
- package/src/editor/cursorPositionTypes.ts +0 -17
- package/src/editor/defaultColors.ts +0 -77
- package/src/editor/editor.css +0 -257
- package/src/editor/managers/BlockManager.ts +0 -256
- package/src/editor/managers/EventManager.browser.test.ts +0 -334
- package/src/editor/managers/EventManager.ts +0 -260
- package/src/editor/managers/ExportManager.ts +0 -137
- package/src/editor/managers/ExtensionManager/ExtensionManager.browser.test.ts +0 -45
- package/src/editor/managers/ExtensionManager/ExtensionManager.node.test.ts +0 -209
- package/src/editor/managers/ExtensionManager/ExtensionManager.test.ts +0 -336
- package/src/editor/managers/ExtensionManager/extensions.ts +0 -200
- package/src/editor/managers/ExtensionManager/index.ts +0 -764
- package/src/editor/managers/ExtensionManager/symbol.ts +0 -5
- package/src/editor/managers/SelectionManager.ts +0 -120
- package/src/editor/managers/StateManager.ts +0 -261
- package/src/editor/managers/StyleManager.browser.test.ts +0 -122
- package/src/editor/managers/StyleManager.test.ts +0 -98
- package/src/editor/managers/StyleManager.ts +0 -278
- package/src/editor/managers/index.ts +0 -8
- package/src/editor/performance.test.ts +0 -192
- package/src/editor/selectionTypes.ts +0 -14
- package/src/editor/transformPasted.test.ts +0 -295
- package/src/editor/transformPasted.ts +0 -294
- package/src/exporter/ExportImage.ts +0 -50
- package/src/exporter/Exporter.test.ts +0 -255
- package/src/exporter/Exporter.ts +0 -185
- package/src/exporter/index.ts +0 -3
- package/src/exporter/mapping.ts +0 -110
- package/src/extensions/BlockChange/BlockChange.ts +0 -67
- package/src/extensions/DropCursor/DropCursor.ts +0 -376
- package/src/extensions/DropCursor/dropIntoChildren.ts +0 -80
- package/src/extensions/DropCursor/utils.ts +0 -195
- package/src/extensions/FilePanel/FilePanel.ts +0 -41
- package/src/extensions/FormattingToolbar/FormattingToolbar.ts +0 -157
- package/src/extensions/History/History.ts +0 -11
- package/src/extensions/InlineContentBoundaryEdit/InlineContentBoundaryEdit.ts +0 -109
- package/src/extensions/LinkToolbar/LinkToolbar.ts +0 -76
- package/src/extensions/LinkToolbar/protocols.ts +0 -13
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.test.ts +0 -190
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.ts +0 -112
- package/src/extensions/Placeholder/Placeholder.test.ts +0 -23
- package/src/extensions/Placeholder/Placeholder.ts +0 -150
- package/src/extensions/PositionMapping/PositionMapping.ts +0 -68
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +0 -156
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +0 -201
- package/src/extensions/README.md +0 -3
- package/src/extensions/ReadOnly/ReadOnly.test.ts +0 -181
- package/src/extensions/ReadOnly/ReadOnly.ts +0 -73
- package/src/extensions/ShowSelection/ShowSelection.ts +0 -61
- package/src/extensions/SideMenu/MultipleNodeSelection.ts +0 -89
- package/src/extensions/SideMenu/SideMenu.ts +0 -470
- package/src/extensions/SideMenu/blockDropHandling.ts +0 -372
- package/src/extensions/SideMenu/blockGeometry.browser.test.ts +0 -148
- package/src/extensions/SideMenu/blockGeometry.test.ts +0 -46
- package/src/extensions/SideMenu/blockGeometry.ts +0 -53
- package/src/extensions/SideMenu/dragging.ts +0 -200
- package/src/extensions/SideMenu/sideMenuHover.test.ts +0 -36
- package/src/extensions/SideMenu/sideMenuHover.ts +0 -270
- package/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.ts +0 -193
- package/src/extensions/SourceInlineContentWithPreview/SourceInlineContentWithPreview.ts +0 -142
- package/src/extensions/SuggestionMenu/DefaultGridSuggestionItem.ts +0 -4
- package/src/extensions/SuggestionMenu/DefaultSuggestionItem.ts +0 -11
- package/src/extensions/SuggestionMenu/SuggestionMenu.test.ts +0 -309
- package/src/extensions/SuggestionMenu/SuggestionMenu.ts +0 -436
- package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +0 -76
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +0 -299
- package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.ts +0 -130
- package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.ts +0 -89
- package/src/extensions/SyntaxHighlighting/inlineHighlight.test.ts +0 -135
- package/src/extensions/SyntaxHighlighting/shiki.ts +0 -116
- package/src/extensions/TableHandles/TableHandles.browser.test.ts +0 -307
- package/src/extensions/TableHandles/TableHandles.ts +0 -1263
- package/src/extensions/TrailingNode/TrailingNode.ts +0 -233
- package/src/extensions/Versioning/Versioning.browser.test.ts +0 -151
- package/src/extensions/Versioning/Versioning.node.test.ts +0 -177
- package/src/extensions/Versioning/Versioning.ts +0 -161
- package/src/extensions/Versioning/__test__/result.ts +0 -12
- package/src/extensions/Versioning/comparison.test.ts +0 -40
- package/src/extensions/Versioning/createVersioning.test.ts +0 -867
- package/src/extensions/Versioning/createVersioning.ts +0 -499
- package/src/extensions/Versioning/formatVersionDate.ts +0 -24
- package/src/extensions/Versioning/inMemoryVersioning.test.ts +0 -572
- package/src/extensions/Versioning/inMemoryVersioning.ts +0 -268
- package/src/extensions/Versioning/index.ts +0 -6
- package/src/extensions/Versioning/scrollScheduling.test.ts +0 -51
- package/src/extensions/Versioning/scrollToFirstChange.test.ts +0 -320
- package/src/extensions/Versioning/scrollToFirstChange.ts +0 -139
- package/src/extensions/Versioning/types.ts +0 -219
- package/src/extensions/Versioning/versioningState.ts +0 -154
- package/src/extensions/blockDOM.browser.test.ts +0 -102
- package/src/extensions/blockDOM.test.ts +0 -178
- package/src/extensions/blockDOM.ts +0 -135
- package/src/extensions/index.ts +0 -27
- package/src/extensions/tiptap-extensions/BackgroundColor/BackgroundColorExtension.ts +0 -17
- package/src/extensions/tiptap-extensions/HardBreak/HardBreak.ts +0 -35
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +0 -1870
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +0 -1116
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/blockIdentity.browser.test.ts +0 -152
- package/src/extensions/tiptap-extensions/Link/helpers/autolink.ts +0 -174
- package/src/extensions/tiptap-extensions/Link/helpers/clickHandler.ts +0 -82
- package/src/extensions/tiptap-extensions/Link/helpers/linkDetector.ts +0 -412
- package/src/extensions/tiptap-extensions/Link/helpers/pasteHandler.ts +0 -53
- package/src/extensions/tiptap-extensions/Link/helpers/tlds.ts +0 -7
- package/src/extensions/tiptap-extensions/Link/helpers/whitespace.ts +0 -13
- package/src/extensions/tiptap-extensions/Link/index.ts +0 -2
- package/src/extensions/tiptap-extensions/Link/link.test.ts +0 -945
- package/src/extensions/tiptap-extensions/Link/link.ts +0 -238
- package/src/extensions/tiptap-extensions/TextAlignment/TextAlignmentExtension.ts +0 -33
- package/src/extensions/tiptap-extensions/TextColor/TextColorExtension.ts +0 -17
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.ts +0 -173
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +0 -339
- package/src/extensions/tiptap-extensions/index.ts +0 -7
- package/src/extensions-shared/UiElementPosition.ts +0 -4
- package/src/fonts/inter.browser.test.ts +0 -57
- package/src/i18n/dictionary.ts +0 -17
- package/src/i18n/index.ts +0 -2
- package/src/i18n/locales/ar.ts +0 -443
- package/src/i18n/locales/de.ts +0 -477
- package/src/i18n/locales/en.ts +0 -458
- package/src/i18n/locales/es.ts +0 -456
- package/src/i18n/locales/fa.ts +0 -427
- package/src/i18n/locales/fr.ts +0 -504
- package/src/i18n/locales/he.ts +0 -458
- package/src/i18n/locales/hr.ts +0 -472
- package/src/i18n/locales/index.ts +0 -23
- package/src/i18n/locales/is.ts +0 -472
- package/src/i18n/locales/it.ts +0 -480
- package/src/i18n/locales/ja.ts +0 -498
- package/src/i18n/locales/ko.ts +0 -471
- package/src/i18n/locales/nl.ts +0 -459
- package/src/i18n/locales/no.ts +0 -476
- package/src/i18n/locales/pl.ts +0 -449
- package/src/i18n/locales/pt.ts +0 -451
- package/src/i18n/locales/ru.ts +0 -502
- package/src/i18n/locales/sk.ts +0 -456
- package/src/i18n/locales/uk.ts +0 -482
- package/src/i18n/locales/uz.ts +0 -492
- package/src/i18n/locales/vi.ts +0 -457
- package/src/i18n/locales/zh-tw.ts +0 -499
- package/src/i18n/locales/zh.ts +0 -499
- package/src/index.ts +0 -66
- package/src/locales.ts +0 -1
- package/src/pm-nodes/BlockContainer.test.ts +0 -101
- package/src/pm-nodes/BlockContainer.ts +0 -200
- package/src/pm-nodes/BlockGroup.ts +0 -58
- package/src/pm-nodes/Doc.ts +0 -11
- package/src/pm-nodes/README.md +0 -143
- package/src/pm-nodes/index.ts +0 -3
- package/src/pm-nodes/suggestionMarks.ts +0 -43
- package/src/schema/README.md +0 -3
- package/src/schema/blocks/children.test.ts +0 -288
- package/src/schema/blocks/children.ts +0 -136
- package/src/schema/blocks/createSpec.browser.test.ts +0 -176
- package/src/schema/blocks/createSpec.test.ts +0 -354
- package/src/schema/blocks/createSpec.ts +0 -732
- package/src/schema/blocks/extendBlockSpec.test.ts +0 -188
- package/src/schema/blocks/frame.test.ts +0 -112
- package/src/schema/blocks/frame.ts +0 -337
- package/src/schema/blocks/internal.test.ts +0 -86
- package/src/schema/blocks/internal.ts +0 -288
- package/src/schema/blocks/keyboard.ts +0 -154
- package/src/schema/blocks/layoutBlockAttributes.ts +0 -29
- package/src/schema/blocks/meta.test.ts +0 -53
- package/src/schema/blocks/meta.ts +0 -35
- package/src/schema/blocks/renderFrame.test.ts +0 -691
- package/src/schema/blocks/types.ts +0 -966
- package/src/schema/blocks/validateChildren.ts +0 -156
- package/src/schema/contentTypePropagation.test.ts +0 -182
- package/src/schema/dataAttributes.test.ts +0 -72
- package/src/schema/dataAttributes.ts +0 -69
- package/src/schema/index.ts +0 -15
- package/src/schema/inlineContent/createSpec.test.ts +0 -161
- package/src/schema/inlineContent/createSpec.ts +0 -409
- package/src/schema/inlineContent/internal.ts +0 -131
- package/src/schema/inlineContent/types.ts +0 -204
- package/src/schema/markGroups.ts +0 -82
- package/src/schema/nodeViewMutations.test.ts +0 -146
- package/src/schema/nodeViewMutations.ts +0 -49
- package/src/schema/propTypes.ts +0 -61
- package/src/schema/schema.test.ts +0 -110
- package/src/schema/schema.ts +0 -243
- package/src/schema/styles/createSpec.ts +0 -140
- package/src/schema/styles/internal.ts +0 -155
- package/src/schema/styles/types.ts +0 -57
- package/src/style.css +0 -2
- package/src/user/UserStore.ts +0 -199
- package/src/user/createUserStore.test.ts +0 -126
- package/src/user/index.ts +0 -2
- package/src/user/userColors.test.ts +0 -108
- package/src/user/userColors.ts +0 -101
- package/src/util/EventEmitter.ts +0 -59
- package/src/util/README.md +0 -3
- package/src/util/Store.test.ts +0 -132
- package/src/util/Store.ts +0 -135
- package/src/util/browser.ts +0 -54
- package/src/util/combineByGroup.ts +0 -25
- package/src/util/expandToWords.ts +0 -38
- package/src/util/string.ts +0 -36
- package/src/util/table.ts +0 -110
- package/src/util/topo-sort.test.ts +0 -125
- package/src/util/topo-sort.ts +0 -206
- package/src/util/typescript.ts +0 -17
- package/src/vite-env.d.ts +0 -7
- package/src/y/README.md +0 -5
- package/src/y/comments/RESTYjsThreadStore.ts +0 -138
- package/src/y/comments/YjsThreadStore.test.ts +0 -295
- package/src/y/comments/YjsThreadStore.ts +0 -358
- package/src/y/comments/YjsThreadStoreBase.ts +0 -50
- package/src/y/comments/index.ts +0 -3
- package/src/y/comments/yjsHelpers.ts +0 -125
- package/src/y/extensions/AttributionExtension.test.ts +0 -364
- package/src/y/extensions/AttributionExtension.ts +0 -401
- package/src/y/extensions/DiffVersioningExtension.test.ts +0 -242
- package/src/y/extensions/DiffVersioningExtension.ts +0 -200
- package/src/y/extensions/EmptyDocBinding.test.ts +0 -282
- package/src/y/extensions/ForkYDoc.node.test.ts +0 -77
- package/src/y/extensions/ForkYDoc.test.ts +0 -344
- package/src/y/extensions/ForkYDoc.ts +0 -117
- package/src/y/extensions/History.test.ts +0 -125
- package/src/y/extensions/RelativePositionMapping.test.ts +0 -453
- package/src/y/extensions/RelativePositionMapping.ts +0 -45
- package/src/y/extensions/Suggestions.ts +0 -174
- package/src/y/extensions/Versioning.node.test.ts +0 -126
- package/src/y/extensions/Versioning.test.ts +0 -117
- package/src/y/extensions/Versioning.ts +0 -74
- package/src/y/extensions/YAttributionMarks.ts +0 -422
- package/src/y/extensions/YCursorPlugin.ts +0 -192
- package/src/y/extensions/YSync.node.test.ts +0 -75
- package/src/y/extensions/YSync.ts +0 -197
- package/src/y/extensions/YSyncRemount.test.ts +0 -99
- package/src/y/extensions/blockMatchNodes.ts +0 -173
- package/src/y/extensions/index.ts +0 -140
- package/src/y/extensions/legacyYjsDocBinding.test.ts +0 -652
- package/src/y/extensions/nestingChanges.test.ts +0 -326
- package/src/y/extensions/persistentBlockGroups.test.ts +0 -1709
- package/src/y/extensions/persistentBlockGroups.ts +0 -953
- package/src/y/extensions/snapshotCodec.test.ts +0 -105
- package/src/y/extensions/snapshotCodec.ts +0 -39
- package/src/y/extensions/snapshotPreview.test.ts +0 -201
- package/src/y/extensions/snapshotPreview.ts +0 -292
- package/src/y/extensions/tableReshape.test.ts +0 -121
- package/src/y/extensions/v1BindingSnapshotDiff.test.ts +0 -121
- package/src/y/extensions/versionDiffAttribution.test.ts +0 -944
- package/src/y/extensions/versionDiffPerformance.test.ts +0 -101
- package/src/y/index.ts +0 -5
- package/src/y/utils.test.ts +0 -1309
- package/src/y/utils.ts +0 -366
- package/src/y/versioning/__test__/fixtures/activity-all-after.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-all-after.json +0 -50
- package/src/y/versioning/__test__/fixtures/activity-all.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-all.json +0 -20
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.json +0 -32
- package/src/y/versioning/__test__/fixtures/activity-filtered-before.json +0 -1
- package/src/y/versioning/__test__/fixtures/changeset.bin +0 -0
- package/src/y/versioning/__test__/fixtures/patch-response.json +0 -4
- package/src/y/versioning/__test__/yhub.test.ts +0 -966
- package/src/y/versioning/index.ts +0 -6
- package/src/y/versioning/yhub.ts +0 -350
- package/src/y/versioning/yhubClient.ts +0 -345
- package/src/yjs/README.md +0 -5
- package/src/yjs/comments/RESTYjsThreadStore.test.ts +0 -95
- package/src/yjs/comments/RESTYjsThreadStore.ts +0 -172
- package/src/yjs/comments/YjsThreadStore.test.ts +0 -295
- package/src/yjs/comments/YjsThreadStore.ts +0 -345
- package/src/yjs/comments/YjsThreadStoreBase.ts +0 -50
- package/src/yjs/comments/index.ts +0 -3
- package/src/yjs/comments/yjsHelpers.ts +0 -127
- package/src/yjs/extensions/FixUpSchema.test.ts +0 -421
- package/src/yjs/extensions/FixUpSchema.ts +0 -99
- package/src/yjs/extensions/ForkYDoc.browser.test.ts +0 -84
- package/src/yjs/extensions/ForkYDoc.node.test.ts +0 -231
- package/src/yjs/extensions/ForkYDoc.test.ts +0 -320
- package/src/yjs/extensions/ForkYDoc.ts +0 -177
- package/src/yjs/extensions/RelativePositionMapping.test.ts +0 -418
- package/src/yjs/extensions/RelativePositionMapping.ts +0 -77
- package/src/yjs/extensions/Versioning.test.ts +0 -376
- package/src/yjs/extensions/Versioning.ts +0 -126
- package/src/yjs/extensions/YCursorPlugin.ts +0 -201
- package/src/yjs/extensions/YSync.ts +0 -16
- package/src/yjs/extensions/YUndo.ts +0 -12
- package/src/yjs/extensions/__snapshots__/fork-yjs-snap-editor-forked.json +0 -19
- package/src/yjs/extensions/__snapshots__/fork-yjs-snap-editor.json +0 -19
- package/src/yjs/extensions/__snapshots__/fork-yjs-snap-forked.html +0 -1
- package/src/yjs/extensions/__snapshots__/fork-yjs-snap.html +0 -1
- package/src/yjs/extensions/index.ts +0 -89
- package/src/yjs/extensions/schemaMigration/SchemaMigration.ts +0 -59
- package/src/yjs/extensions/schemaMigration/migrationRules/index.ts +0 -4
- package/src/yjs/extensions/schemaMigration/migrationRules/migrationRule.ts +0 -4
- package/src/yjs/extensions/schemaMigration/migrationRules/moveColorAttributes.test.ts +0 -130
- package/src/yjs/extensions/schemaMigration/migrationRules/moveColorAttributes.ts +0 -91
- package/src/yjs/index.ts +0 -7
- package/src/yjs/utils.test.ts +0 -1013
- package/src/yjs/utils.ts +0 -186
- package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.d.ts +0 -1
- package/types/src/api/blockManipulation/commands/insertBlocks/insertPlacement.test.d.ts +0 -1
- package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.d.ts +0 -1
- package/types/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.d.ts +0 -1
- package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.test.d.ts +0 -1
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.d.ts +0 -1
- package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.test.d.ts +0 -1
- package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.test.d.ts +0 -1
- package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.browser.test.d.ts +0 -1
- package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.test.d.ts +0 -1
- package/types/src/api/blockManipulation/layoutBlocks/plainBlocks.test.d.ts +0 -1
- package/types/src/api/blockManipulation/layoutBlocks/titledBlocks.test.d.ts +0 -1
- package/types/src/api/blockManipulation/tables/tables.test.d.ts +0 -1
- package/types/src/api/getBlockInfoFromPos.test.d.ts +0 -1
- package/types/src/api/getBlocksChangedByTransaction.test.d.ts +0 -1
- package/types/src/api/getChangedRanges.test.d.ts +0 -1
- package/types/src/api/nodeConversions/blockToNode.test.d.ts +0 -1
- package/types/src/api/parsers/html/util/nestedLists.test.d.ts +0 -1
- package/types/src/api/parsers/markdown/detectMarkdown.test.d.ts +0 -1
- package/types/src/api/positionMapping.test.d.ts +0 -1
- package/types/src/blocks/Code/block.test.d.ts +0 -1
- package/types/src/blocks/ListItem/CheckListItem/block.test.d.ts +0 -1
- package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.d.ts +0 -1
- package/types/src/blocks/Table/TableExtension.test.d.ts +0 -1
- package/types/src/blocks/ToggleWrapper/toggleBlocks.browser.test.d.ts +0 -1
- package/types/src/blocks/defaultBlockTypeItems.test.d.ts +0 -1
- package/types/src/blocks/defaultBlocks.test.d.ts +0 -1
- package/types/src/comments/CommentEditorSubmitExtension.test.d.ts +0 -1
- package/types/src/editor/BlockNoteEditor.node.test.d.ts +0 -1
- package/types/src/editor/BlockNoteEditor.test.d.ts +0 -1
- package/types/src/editor/BlockNoteExtension.test.d.ts +0 -1
- package/types/src/editor/blockColors.browser.test.d.ts +0 -1
- package/types/src/editor/managers/EventManager.browser.test.d.ts +0 -1
- package/types/src/editor/managers/ExtensionManager/ExtensionManager.browser.test.d.ts +0 -1
- package/types/src/editor/managers/ExtensionManager/ExtensionManager.node.test.d.ts +0 -1
- package/types/src/editor/managers/ExtensionManager/ExtensionManager.test.d.ts +0 -1
- package/types/src/editor/managers/StyleManager.browser.test.d.ts +0 -1
- package/types/src/editor/managers/StyleManager.test.d.ts +0 -1
- package/types/src/editor/performance.test.d.ts +0 -1
- package/types/src/editor/transformPasted.test.d.ts +0 -1
- package/types/src/exporter/Exporter.test.d.ts +0 -1
- package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.test.d.ts +0 -1
- package/types/src/extensions/Placeholder/Placeholder.test.d.ts +0 -1
- package/types/src/extensions/PreviousBlockType/PreviousBlockType.test.d.ts +0 -1
- package/types/src/extensions/ReadOnly/ReadOnly.test.d.ts +0 -1
- package/types/src/extensions/SideMenu/blockGeometry.browser.test.d.ts +0 -1
- package/types/src/extensions/SideMenu/blockGeometry.test.d.ts +0 -1
- package/types/src/extensions/SideMenu/sideMenuHover.test.d.ts +0 -1
- package/types/src/extensions/SuggestionMenu/DefaultGridSuggestionItem.d.ts +0 -4
- package/types/src/extensions/SuggestionMenu/SuggestionMenu.test.d.ts +0 -1
- package/types/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.d.ts +0 -4
- package/types/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.d.ts +0 -1
- package/types/src/extensions/SyntaxHighlighting/inlineHighlight.test.d.ts +0 -1
- package/types/src/extensions/TableHandles/TableHandles.browser.test.d.ts +0 -1
- package/types/src/extensions/Versioning/Versioning.browser.test.d.ts +0 -1
- package/types/src/extensions/Versioning/Versioning.node.test.d.ts +0 -1
- package/types/src/extensions/Versioning/__test__/result.d.ts +0 -3
- package/types/src/extensions/Versioning/comparison.test.d.ts +0 -1
- package/types/src/extensions/Versioning/createVersioning.test.d.ts +0 -1
- package/types/src/extensions/Versioning/inMemoryVersioning.test.d.ts +0 -1
- package/types/src/extensions/Versioning/scrollScheduling.test.d.ts +0 -1
- package/types/src/extensions/Versioning/scrollToFirstChange.test.d.ts +0 -1
- package/types/src/extensions/blockDOM.browser.test.d.ts +0 -1
- package/types/src/extensions/blockDOM.test.d.ts +0 -1
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.d.ts +0 -4
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/blockIdentity.browser.test.d.ts +0 -1
- package/types/src/extensions/tiptap-extensions/Link/link.test.d.ts +0 -1
- package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.d.ts +0 -4
- package/types/src/fonts/inter.browser.test.d.ts +0 -2
- package/types/src/pm-nodes/BlockContainer.test.d.ts +0 -1
- package/types/src/schema/blocks/children.test.d.ts +0 -1
- package/types/src/schema/blocks/createSpec.browser.test.d.ts +0 -1
- package/types/src/schema/blocks/createSpec.test.d.ts +0 -1
- package/types/src/schema/blocks/extendBlockSpec.test.d.ts +0 -1
- package/types/src/schema/blocks/frame.test.d.ts +0 -1
- package/types/src/schema/blocks/internal.test.d.ts +0 -1
- package/types/src/schema/blocks/meta.test.d.ts +0 -1
- package/types/src/schema/blocks/renderFrame.test.d.ts +0 -1
- package/types/src/schema/contentTypePropagation.test.d.ts +0 -1
- package/types/src/schema/dataAttributes.test.d.ts +0 -1
- package/types/src/schema/inlineContent/createSpec.test.d.ts +0 -1
- package/types/src/schema/nodeViewMutations.test.d.ts +0 -1
- package/types/src/schema/schema.test.d.ts +0 -1
- package/types/src/user/createUserStore.test.d.ts +0 -1
- package/types/src/user/userColors.test.d.ts +0 -1
- package/types/src/util/Store.test.d.ts +0 -1
- package/types/src/util/topo-sort.test.d.ts +0 -1
- package/types/src/y/comments/YjsThreadStore.test.d.ts +0 -1
- package/types/src/y/extensions/AttributionExtension.test.d.ts +0 -1
- package/types/src/y/extensions/DiffVersioningExtension.test.d.ts +0 -1
- package/types/src/y/extensions/EmptyDocBinding.test.d.ts +0 -1
- package/types/src/y/extensions/ForkYDoc.node.test.d.ts +0 -1
- package/types/src/y/extensions/ForkYDoc.test.d.ts +0 -1
- package/types/src/y/extensions/History.test.d.ts +0 -1
- package/types/src/y/extensions/RelativePositionMapping.test.d.ts +0 -1
- package/types/src/y/extensions/Versioning.node.test.d.ts +0 -1
- package/types/src/y/extensions/Versioning.test.d.ts +0 -1
- package/types/src/y/extensions/YSync.node.test.d.ts +0 -1
- package/types/src/y/extensions/YSyncRemount.test.d.ts +0 -1
- package/types/src/y/extensions/legacyYjsDocBinding.test.d.ts +0 -1
- package/types/src/y/extensions/nestingChanges.test.d.ts +0 -1
- package/types/src/y/extensions/persistentBlockGroups.test.d.ts +0 -1
- package/types/src/y/extensions/snapshotCodec.test.d.ts +0 -1
- package/types/src/y/extensions/snapshotPreview.test.d.ts +0 -1
- package/types/src/y/extensions/tableReshape.test.d.ts +0 -1
- package/types/src/y/extensions/v1BindingSnapshotDiff.test.d.ts +0 -1
- package/types/src/y/extensions/versionDiffAttribution.test.d.ts +0 -1
- package/types/src/y/extensions/versionDiffPerformance.test.d.ts +0 -1
- package/types/src/y/utils.test.d.ts +0 -1
- package/types/src/y/versioning/__test__/yhub.test.d.ts +0 -1
- package/types/src/yjs/comments/RESTYjsThreadStore.test.d.ts +0 -1
- package/types/src/yjs/comments/YjsThreadStore.test.d.ts +0 -1
- package/types/src/yjs/extensions/FixUpSchema.test.d.ts +0 -1
- package/types/src/yjs/extensions/ForkYDoc.browser.test.d.ts +0 -1
- package/types/src/yjs/extensions/ForkYDoc.node.test.d.ts +0 -1
- package/types/src/yjs/extensions/ForkYDoc.test.d.ts +0 -1
- package/types/src/yjs/extensions/RelativePositionMapping.test.d.ts +0 -1
- package/types/src/yjs/extensions/Versioning.test.d.ts +0 -1
- package/types/src/yjs/extensions/schemaMigration/migrationRules/moveColorAttributes.test.d.ts +0 -1
- package/types/src/yjs/utils.test.d.ts +0 -1
|
@@ -1,1709 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @vitest-environment jsdom
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Tests for persistentBlockGroups.ts, in three layers:
|
|
6
|
-
*
|
|
7
|
-
* 1. the per-container stage on hand-built deltas (what every change maps to)
|
|
8
|
-
* 2. the binding: BlockNote-shaped ProseMirror views on synced Y docs, the
|
|
9
|
-
* concurrency scenarios the transformer exists for, legacy documents,
|
|
10
|
-
* suggestion mode, cursor mapping, the standalone conversions and a client
|
|
11
|
-
* without the transformer
|
|
12
|
-
* 3. a fuzz: random nesting / un-nesting / inserting / deleting / typing on
|
|
13
|
-
* two peers with random sync points, asserting convergence and the Y
|
|
14
|
-
* invariants
|
|
15
|
-
*
|
|
16
|
-
* The views are plain ProseMirror views on BlockNote's schema, bound through
|
|
17
|
-
* `@y/prosemirror` exactly as `YSyncExtension` binds the editor (same
|
|
18
|
-
* transformer, same node pairing). nestingChanges.test.ts covers the same
|
|
19
|
-
* scenarios through the BlockNote editor API.
|
|
20
|
-
*/
|
|
21
|
-
import * as YPM from "@y/prosemirror";
|
|
22
|
-
import * as Y from "@y/y";
|
|
23
|
-
import * as delta from "lib0/delta";
|
|
24
|
-
import * as dpos from "lib0/delta/position";
|
|
25
|
-
import * as prng from "lib0/prng";
|
|
26
|
-
import type { Node } from "prosemirror-model";
|
|
27
|
-
import { EditorState } from "prosemirror-state";
|
|
28
|
-
import { EditorView } from "prosemirror-view";
|
|
29
|
-
import { describe, expect, it } from "vite-plus/test";
|
|
30
|
-
|
|
31
|
-
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
32
|
-
import { blockMatchNodes } from "./blockMatchNodes.js";
|
|
33
|
-
import { withCollaboration } from "./index.js";
|
|
34
|
-
import { persistentBlockGroups } from "./persistentBlockGroups.js";
|
|
35
|
-
|
|
36
|
-
// lib0's delta builders are untyped at this level of genericity.
|
|
37
|
-
type AnyBuilder = delta.DeltaBuilderAny;
|
|
38
|
-
type AnyDelta = delta.DeltaAny;
|
|
39
|
-
|
|
40
|
-
// --- schema -----------------------------------------------------------------
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* BlockNote's ProseMirror schema with the `y-attributed-*` marks (which the
|
|
44
|
-
* collaboration extension registers).
|
|
45
|
-
*/
|
|
46
|
-
const schema = BlockNoteEditor.create(
|
|
47
|
-
withCollaboration({
|
|
48
|
-
collaboration: {
|
|
49
|
-
fragment: new Y.Doc().get("schema"),
|
|
50
|
-
user: { name: "schema", color: "#000000" },
|
|
51
|
-
},
|
|
52
|
-
}),
|
|
53
|
-
).pmSchema;
|
|
54
|
-
|
|
55
|
-
const N = schema.nodes;
|
|
56
|
-
|
|
57
|
-
/** A block with optional nested children. */
|
|
58
|
-
function block(
|
|
59
|
-
id: string,
|
|
60
|
-
text: string,
|
|
61
|
-
children: Node[] = [],
|
|
62
|
-
type: "paragraph" | "heading" = "paragraph",
|
|
63
|
-
): Node {
|
|
64
|
-
return N.blockContainer.create({ id }, [
|
|
65
|
-
N[type].create(null, text ? schema.text(text) : null),
|
|
66
|
-
...(children.length > 0 ? [N.blockGroup.create(null, children)] : []),
|
|
67
|
-
]);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function docOf(blocks: Node[]): Node {
|
|
71
|
-
return N.doc.create(null, N.blockGroup.create(null, blocks));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** The nested blocks of a container. */
|
|
75
|
-
function childrenOf(container: Node): Node[] {
|
|
76
|
-
const out: Node[] = [];
|
|
77
|
-
if (container.childCount > 1) {
|
|
78
|
-
container.child(1).forEach((c) => out.push(c));
|
|
79
|
-
}
|
|
80
|
-
return out;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** The container with `children` as its nested blocks (no group when empty). */
|
|
84
|
-
function withChildren(container: Node, children: Node[]): Node {
|
|
85
|
-
return N.blockContainer.create(container.attrs, [
|
|
86
|
-
container.child(0),
|
|
87
|
-
...(children.length > 0 ? [N.blockGroup.create(null, children)] : []),
|
|
88
|
-
]);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function withText(container: Node, text: string): Node {
|
|
92
|
-
return N.blockContainer.create(container.attrs, [
|
|
93
|
-
container
|
|
94
|
-
.child(0)
|
|
95
|
-
.type.create(container.child(0).attrs, text ? schema.text(text) : null),
|
|
96
|
-
...(container.childCount > 1 ? [container.child(1)] : []),
|
|
97
|
-
]);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** The top-level blocks of a doc. */
|
|
101
|
-
function topBlocks(doc: Node): Node[] {
|
|
102
|
-
const out: Node[] = [];
|
|
103
|
-
doc.child(0).forEach((c) => out.push(c));
|
|
104
|
-
return out;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* A path addresses a block by child indexes: `[i]` is the i-th top-level
|
|
109
|
-
* block, `[i, j]` its j-th nested block, and so on.
|
|
110
|
-
*/
|
|
111
|
-
type Path = number[];
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Rebuild the doc with the sibling list at `parentPath` (`[]` = top level)
|
|
115
|
-
* replaced by what `fn` returns for it.
|
|
116
|
-
*/
|
|
117
|
-
function updateSiblings(
|
|
118
|
-
doc: Node,
|
|
119
|
-
parentPath: Path,
|
|
120
|
-
fn: (siblings: Node[]) => Node[],
|
|
121
|
-
): Node {
|
|
122
|
-
function rec(siblings: Node[], depth: number): Node[] {
|
|
123
|
-
if (depth === parentPath.length) {
|
|
124
|
-
return fn(siblings);
|
|
125
|
-
}
|
|
126
|
-
const i = parentPath[depth];
|
|
127
|
-
return siblings.map((s, j) =>
|
|
128
|
-
j === i ? withChildren(s, rec(childrenOf(s), depth + 1)) : s,
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
return docOf(rec(topBlocks(doc), 0));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function blockAt(doc: Node, path: Path): Node {
|
|
135
|
-
let siblings = topBlocks(doc);
|
|
136
|
-
let node = siblings[path[0]];
|
|
137
|
-
for (let i = 1; i < path.length; i++) {
|
|
138
|
-
siblings = childrenOf(node);
|
|
139
|
-
node = siblings[path[i]];
|
|
140
|
-
}
|
|
141
|
-
return node;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/** Every block path in document order. */
|
|
145
|
-
function allPaths(doc: Node): Path[] {
|
|
146
|
-
const out: Path[] = [];
|
|
147
|
-
function rec(siblings: Node[], prefix: Path) {
|
|
148
|
-
siblings.forEach((s, i) => {
|
|
149
|
-
out.push([...prefix, i]);
|
|
150
|
-
rec(childrenOf(s), [...prefix, i]);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
rec(topBlocks(doc), []);
|
|
154
|
-
return out;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// --- the editing operations BlockNote performs, as doc -> doc functions ------
|
|
158
|
-
|
|
159
|
-
/** Insert `b` after the block at `path`. */
|
|
160
|
-
function insertAfter(doc: Node, path: Path, b: Node): Node {
|
|
161
|
-
return updateSiblings(doc, path.slice(0, -1), (sibs) => {
|
|
162
|
-
const i = path[path.length - 1];
|
|
163
|
-
return [...sibs.slice(0, i + 1), b, ...sibs.slice(i + 1)];
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Remove the block at `path` (its nested blocks go with it). Removing the last
|
|
169
|
-
* nested block of a parent removes the parent's group, as BlockNote does.
|
|
170
|
-
*/
|
|
171
|
-
function remove(doc: Node, path: Path): Node {
|
|
172
|
-
return updateSiblings(doc, path.slice(0, -1), (sibs) =>
|
|
173
|
-
sibs.filter((_, j) => j !== path[path.length - 1]),
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* BlockNote's "nest" (Tab): the block becomes the last nested block of its
|
|
179
|
-
* previous sibling. Requires a previous sibling.
|
|
180
|
-
*/
|
|
181
|
-
function nest(doc: Node, path: Path): Node {
|
|
182
|
-
return updateSiblings(doc, path.slice(0, -1), (sibs) => {
|
|
183
|
-
const i = path[path.length - 1];
|
|
184
|
-
const prev = sibs[i - 1];
|
|
185
|
-
return [
|
|
186
|
-
...sibs.slice(0, i - 1),
|
|
187
|
-
withChildren(prev, [...childrenOf(prev), sibs[i]]),
|
|
188
|
-
...sibs.slice(i + 1),
|
|
189
|
-
];
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* BlockNote's "unnest" (Shift-Tab): the block moves after its parent, and its
|
|
195
|
-
* following siblings become its own nested blocks. Requires depth >= 2.
|
|
196
|
-
*/
|
|
197
|
-
function unnest(doc: Node, path: Path): Node {
|
|
198
|
-
const parentPath = path.slice(0, -1);
|
|
199
|
-
const i = path[path.length - 1];
|
|
200
|
-
const parent = blockAt(doc, parentPath);
|
|
201
|
-
const sibs = childrenOf(parent);
|
|
202
|
-
const lifted = withChildren(sibs[i], [
|
|
203
|
-
...childrenOf(sibs[i]),
|
|
204
|
-
...sibs.slice(i + 1),
|
|
205
|
-
]);
|
|
206
|
-
const newParent = withChildren(parent, sibs.slice(0, i));
|
|
207
|
-
return updateSiblings(doc, parentPath.slice(0, -1), (psibs) => {
|
|
208
|
-
const pi = parentPath[parentPath.length - 1];
|
|
209
|
-
return [...psibs.slice(0, pi), newParent, lifted, ...psibs.slice(pi + 1)];
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/** Append `text` to the block's content. */
|
|
214
|
-
function typeText(doc: Node, path: Path, text: string): Node {
|
|
215
|
-
return updateSiblings(doc, path.slice(0, -1), (sibs) =>
|
|
216
|
-
sibs.map((s, j) =>
|
|
217
|
-
j === path[path.length - 1]
|
|
218
|
-
? withText(s, s.child(0).textContent + text)
|
|
219
|
-
: s,
|
|
220
|
-
),
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Replace the view's document. Untouched subtrees keep their node identity,
|
|
226
|
-
* so the binding's incremental pull sees only the changed window. Nothing
|
|
227
|
-
* here depends on how the transaction is expressed: the binding diffs
|
|
228
|
-
* documents, not steps.
|
|
229
|
-
*/
|
|
230
|
-
function setDoc(view: EditorView, doc: Node) {
|
|
231
|
-
view.dispatch(
|
|
232
|
-
view.state.tr.replaceWith(0, view.state.doc.content.size, doc.content),
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// --- peers ------------------------------------------------------------------
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* BlockNote renders the marks that have no `toDOM` (its attribution marks)
|
|
240
|
-
* through the editor; a plain ProseMirror view needs a stand-in for them.
|
|
241
|
-
*/
|
|
242
|
-
const markViews = Object.fromEntries(
|
|
243
|
-
Object.values(schema.marks)
|
|
244
|
-
.filter((mark) => mark.spec.toDOM === undefined)
|
|
245
|
-
.map((mark) => [
|
|
246
|
-
mark.name,
|
|
247
|
-
() => {
|
|
248
|
-
const dom = document.createElement("span");
|
|
249
|
-
return { dom, contentDOM: dom };
|
|
250
|
-
},
|
|
251
|
-
]),
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
/** The transformer under test, in the shape `syncPlugin` takes. */
|
|
255
|
-
const transformers = [persistentBlockGroups];
|
|
256
|
-
|
|
257
|
-
const pipeline = YPM.defaultTransformer({ transformers });
|
|
258
|
-
|
|
259
|
-
type Peer = {
|
|
260
|
-
view: EditorView;
|
|
261
|
-
ydoc: Y.Doc;
|
|
262
|
-
errors: Error[];
|
|
263
|
-
destroy: () => void;
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
/** A BlockNote-shaped editor bound to `ytype` through the transformer. */
|
|
267
|
-
function createPeer(
|
|
268
|
-
ydoc: Y.Doc,
|
|
269
|
-
{
|
|
270
|
-
ytype = ydoc.get("bn"),
|
|
271
|
-
renderer = null,
|
|
272
|
-
withTransformer = true,
|
|
273
|
-
}: {
|
|
274
|
-
ytype?: Y.Node;
|
|
275
|
-
renderer?: Y.AbstractRenderer | null;
|
|
276
|
-
withTransformer?: boolean;
|
|
277
|
-
} = {},
|
|
278
|
-
): Peer {
|
|
279
|
-
const errors: Error[] = [];
|
|
280
|
-
const plugin = YPM.syncPlugin({
|
|
281
|
-
transformers: withTransformer ? transformers : [],
|
|
282
|
-
customCompare: blockMatchNodes,
|
|
283
|
-
onInternalError: (err) => {
|
|
284
|
-
errors.push(err);
|
|
285
|
-
},
|
|
286
|
-
});
|
|
287
|
-
const view = new EditorView(
|
|
288
|
-
{ mount: document.createElement("div") },
|
|
289
|
-
{ state: EditorState.create({ schema, plugins: [plugin] }), markViews },
|
|
290
|
-
);
|
|
291
|
-
YPM.configureYProsemirror({ ytype, renderer })(view.state, view.dispatch);
|
|
292
|
-
return { view, ydoc, errors, destroy: () => view.destroy() };
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* A network between Y docs that can hold updates back. Idempotent under the
|
|
297
|
-
* state vector, so flushing after every change is as good as live sync.
|
|
298
|
-
*/
|
|
299
|
-
function createNetwork(docs: Y.Doc[]) {
|
|
300
|
-
let queue: Array<{ from: Y.Doc; update: Uint8Array }> = [];
|
|
301
|
-
let live = true;
|
|
302
|
-
const flush = () => {
|
|
303
|
-
const q = queue;
|
|
304
|
-
queue = [];
|
|
305
|
-
for (const { from, update } of q) {
|
|
306
|
-
for (const to of docs) {
|
|
307
|
-
if (to !== from) {
|
|
308
|
-
Y.applyUpdate(to, update, "network");
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
for (const from of docs) {
|
|
314
|
-
from.on("update", (update: Uint8Array, origin: unknown) => {
|
|
315
|
-
if (origin === "network") {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
queue.push({ from, update });
|
|
319
|
-
if (live) {
|
|
320
|
-
flush();
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
// initial exchange
|
|
325
|
-
for (const a of docs) {
|
|
326
|
-
for (const b of docs) {
|
|
327
|
-
if (a !== b) {
|
|
328
|
-
Y.applyUpdate(b, Y.encodeStateAsUpdate(a), "network");
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
return {
|
|
333
|
-
pause: () => {
|
|
334
|
-
live = false;
|
|
335
|
-
},
|
|
336
|
-
resume: () => {
|
|
337
|
-
live = true;
|
|
338
|
-
flush();
|
|
339
|
-
},
|
|
340
|
-
flush,
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
function json(doc: Node): unknown {
|
|
345
|
-
return JSON.parse(JSON.stringify(doc.toJSON()));
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/** The doc JSON with attribution marks stripped (content only). */
|
|
349
|
-
function stripMarks(node: unknown): unknown {
|
|
350
|
-
if (node === null || typeof node !== "object") {
|
|
351
|
-
return node;
|
|
352
|
-
}
|
|
353
|
-
const out = { ...(node as Record<string, unknown>) };
|
|
354
|
-
if (Array.isArray(out.marks)) {
|
|
355
|
-
const marks = out.marks.filter(
|
|
356
|
-
(m: { type: string }) => !String(m.type).startsWith("y-attributed"),
|
|
357
|
-
);
|
|
358
|
-
if (marks.length > 0) {
|
|
359
|
-
out.marks = marks;
|
|
360
|
-
} else {
|
|
361
|
-
delete out.marks;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
if (Array.isArray(out.content)) {
|
|
365
|
-
out.content = out.content.map(stripMarks);
|
|
366
|
-
}
|
|
367
|
-
return out;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/** The value of a delta node's attribute (`d.attrs[key]` is the attr *op*). */
|
|
371
|
-
function attrValue(d: AnyDelta, key: string): unknown {
|
|
372
|
-
const op: unknown = (d.attrs as Record<string, unknown>)[key];
|
|
373
|
-
return op !== undefined && delta.$setAttrOp.check(op) ? op.value : undefined;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* The Y layout of every container: its id and the child counts of its
|
|
378
|
-
* `blockGroup` children, in document order.
|
|
379
|
-
*/
|
|
380
|
-
function yContainers(ytype: Y.Node): Array<{ id: string; groups: number[] }> {
|
|
381
|
-
const out: Array<{ id: string; groups: number[] }> = [];
|
|
382
|
-
function rec(node: AnyDelta) {
|
|
383
|
-
for (const op of node.children) {
|
|
384
|
-
if (!delta.$insertOp.check(op)) {
|
|
385
|
-
continue;
|
|
386
|
-
}
|
|
387
|
-
for (const el of op.insert) {
|
|
388
|
-
if (!delta.$deltaAny.check(el)) {
|
|
389
|
-
continue;
|
|
390
|
-
}
|
|
391
|
-
if (el.name === "blockContainer") {
|
|
392
|
-
const groups: number[] = [];
|
|
393
|
-
for (const cop of el.children) {
|
|
394
|
-
if (!delta.$insertOp.check(cop)) {
|
|
395
|
-
continue;
|
|
396
|
-
}
|
|
397
|
-
for (const c of cop.insert) {
|
|
398
|
-
if (delta.$deltaAny.check(c) && c.name === "blockGroup") {
|
|
399
|
-
groups.push(c.childCnt);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
out.push({ id: String(attrValue(el, "id")), groups });
|
|
404
|
-
}
|
|
405
|
-
rec(el);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
rec(ytype.toDeltaDeep() as AnyDelta);
|
|
410
|
-
return out;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
function yContainer(ytype: Y.Node, id: string) {
|
|
414
|
-
const c = yContainers(ytype).find((c) => c.id === id);
|
|
415
|
-
if (c === undefined) {
|
|
416
|
-
throw new Error(`no container ${id}`);
|
|
417
|
-
}
|
|
418
|
-
return c;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/** Render the ytype through the pipeline (what a freshly bound view shows). */
|
|
422
|
-
function render(ytype: Y.Node, renderer: Y.AbstractRenderer | null = null) {
|
|
423
|
-
return YPM.ynodeToPmnode(ytype, schema, { renderer, transformer: pipeline });
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
/**
|
|
427
|
-
* Assert that every peer shows the same document, that it equals the
|
|
428
|
-
* pipeline's rendering of the Y document, and that no peer reported an
|
|
429
|
-
* internal error.
|
|
430
|
-
*/
|
|
431
|
-
function assertConverged(peers: Peer[], msg: string) {
|
|
432
|
-
for (const p of peers) {
|
|
433
|
-
expect(
|
|
434
|
-
p.errors.map((e) => e.message),
|
|
435
|
-
`${msg}: no internal errors`,
|
|
436
|
-
).toEqual([]);
|
|
437
|
-
}
|
|
438
|
-
const first = json(peers[0].view.state.doc);
|
|
439
|
-
for (const p of peers.slice(1)) {
|
|
440
|
-
expect(json(p.view.state.doc), `${msg}: peers agree`).toEqual(first);
|
|
441
|
-
}
|
|
442
|
-
expect(
|
|
443
|
-
json(render(peers[0].ydoc.get("bn"))),
|
|
444
|
-
`${msg}: the view equals the rendering of the Y document`,
|
|
445
|
-
).toEqual(first);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// --- 1. the per-container stage on hand-built deltas -------------------------
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
* A container delta.
|
|
452
|
-
*
|
|
453
|
-
* @param children `null` = no group, `[]` = an empty group
|
|
454
|
-
*/
|
|
455
|
-
function yblock(
|
|
456
|
-
id: string,
|
|
457
|
-
text: string,
|
|
458
|
-
children: AnyBuilder[] | null = null,
|
|
459
|
-
): AnyBuilder {
|
|
460
|
-
const b: AnyBuilder = delta
|
|
461
|
-
.create("blockContainer", { id })
|
|
462
|
-
.insert([delta.create("paragraph", {}, text)]);
|
|
463
|
-
if (children !== null) {
|
|
464
|
-
b.insert([delta.create("blockGroup", {}).insert(children)]);
|
|
465
|
-
}
|
|
466
|
-
return b;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
function ydocOf(blocks: AnyBuilder[]): AnyBuilder {
|
|
470
|
-
return delta.create().insert([delta.create("blockGroup", {}).insert(blocks)]);
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/** A fresh pipeline stage over `$prosemirrorDelta`. */
|
|
474
|
-
function stage() {
|
|
475
|
-
return persistentBlockGroups(YPM.$prosemirrorDelta).init();
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
/** A change on the top-level group's i-th container. */
|
|
479
|
-
function onBlock(i: number, containerChange: AnyBuilder): AnyBuilder {
|
|
480
|
-
return delta
|
|
481
|
-
.create()
|
|
482
|
-
.modify(delta.create().retain(i).modify(containerChange));
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
function expectDelta(
|
|
486
|
-
actual: { toJSON(): unknown },
|
|
487
|
-
expected: { toJSON(): unknown },
|
|
488
|
-
msg: string,
|
|
489
|
-
) {
|
|
490
|
-
expect(actual.toJSON(), msg).toEqual(expected.toJSON());
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
describe("persistent block groups: the per-container stage", () => {
|
|
494
|
-
it("hides empty groups at every depth", () => {
|
|
495
|
-
const s = stage();
|
|
496
|
-
const d = ydocOf([
|
|
497
|
-
yblock("a", "A", []),
|
|
498
|
-
yblock("b", "B"),
|
|
499
|
-
yblock("c", "C", [yblock("c1", "C1", [])]),
|
|
500
|
-
]);
|
|
501
|
-
const b = s.applyA(delta.cloneDeep(d.done(false))).b!;
|
|
502
|
-
expectDelta(
|
|
503
|
-
b,
|
|
504
|
-
ydocOf([
|
|
505
|
-
yblock("a", "A"),
|
|
506
|
-
yblock("b", "B"),
|
|
507
|
-
yblock("c", "C", [yblock("c1", "C1")]),
|
|
508
|
-
]),
|
|
509
|
-
"a legacy container and a hidden-group container render the same",
|
|
510
|
-
);
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
it("shows the view group while it has children and hides it again", () => {
|
|
514
|
-
const s = stage();
|
|
515
|
-
s.applyA(delta.cloneDeep(ydocOf([yblock("a", "A", [])]).done(false)));
|
|
516
|
-
// Y inserts a child into the hidden group
|
|
517
|
-
const appear = s.applyA(
|
|
518
|
-
onBlock(
|
|
519
|
-
0,
|
|
520
|
-
delta
|
|
521
|
-
.create()
|
|
522
|
-
.retain(1)
|
|
523
|
-
.modify(delta.create().insert([yblock("x", "X", [])])),
|
|
524
|
-
),
|
|
525
|
-
).b!;
|
|
526
|
-
expectDelta(
|
|
527
|
-
appear,
|
|
528
|
-
onBlock(
|
|
529
|
-
0,
|
|
530
|
-
delta
|
|
531
|
-
.create()
|
|
532
|
-
.retain(1)
|
|
533
|
-
.insert([delta.create("blockGroup", {}).insert([yblock("x", "X")])]),
|
|
534
|
-
),
|
|
535
|
-
"the view group appears with its children",
|
|
536
|
-
);
|
|
537
|
-
// a second child: the group is modified
|
|
538
|
-
const grow = s.applyA(
|
|
539
|
-
onBlock(
|
|
540
|
-
0,
|
|
541
|
-
delta
|
|
542
|
-
.create()
|
|
543
|
-
.retain(1)
|
|
544
|
-
.modify(
|
|
545
|
-
delta
|
|
546
|
-
.create()
|
|
547
|
-
.retain(1)
|
|
548
|
-
.insert([yblock("y", "Y", [])]),
|
|
549
|
-
),
|
|
550
|
-
),
|
|
551
|
-
).b!;
|
|
552
|
-
expectDelta(
|
|
553
|
-
grow,
|
|
554
|
-
onBlock(
|
|
555
|
-
0,
|
|
556
|
-
delta
|
|
557
|
-
.create()
|
|
558
|
-
.retain(1)
|
|
559
|
-
.modify(
|
|
560
|
-
delta
|
|
561
|
-
.create()
|
|
562
|
-
.retain(1)
|
|
563
|
-
.insert([yblock("y", "Y")]),
|
|
564
|
-
),
|
|
565
|
-
),
|
|
566
|
-
"a visible group is modified in place",
|
|
567
|
-
);
|
|
568
|
-
// text typed into the nested child: a plain modify chain
|
|
569
|
-
const typed = s.applyA(
|
|
570
|
-
onBlock(
|
|
571
|
-
0,
|
|
572
|
-
delta
|
|
573
|
-
.create()
|
|
574
|
-
.retain(1)
|
|
575
|
-
.modify(
|
|
576
|
-
delta
|
|
577
|
-
.create()
|
|
578
|
-
.retain(1)
|
|
579
|
-
.modify(
|
|
580
|
-
delta.create().modify(delta.create().retain(1).insert("!")),
|
|
581
|
-
),
|
|
582
|
-
),
|
|
583
|
-
),
|
|
584
|
-
).b!;
|
|
585
|
-
expectDelta(
|
|
586
|
-
typed,
|
|
587
|
-
onBlock(
|
|
588
|
-
0,
|
|
589
|
-
delta
|
|
590
|
-
.create()
|
|
591
|
-
.retain(1)
|
|
592
|
-
.modify(
|
|
593
|
-
delta
|
|
594
|
-
.create()
|
|
595
|
-
.retain(1)
|
|
596
|
-
.modify(
|
|
597
|
-
delta.create().modify(delta.create().retain(1).insert("!")),
|
|
598
|
-
),
|
|
599
|
-
),
|
|
600
|
-
),
|
|
601
|
-
"a modify chain passes through",
|
|
602
|
-
);
|
|
603
|
-
// delete both children: the view group disappears
|
|
604
|
-
const vanish = s.applyA(
|
|
605
|
-
onBlock(0, delta.create().retain(1).modify(delta.create().delete(2))),
|
|
606
|
-
).b!;
|
|
607
|
-
expectDelta(
|
|
608
|
-
vanish,
|
|
609
|
-
onBlock(0, delta.create().retain(1).delete(1)),
|
|
610
|
-
"the view group disappears when the last child goes",
|
|
611
|
-
);
|
|
612
|
-
// the group still exists for the transformer: a later insert shows it again
|
|
613
|
-
const again = s.applyA(
|
|
614
|
-
onBlock(
|
|
615
|
-
0,
|
|
616
|
-
delta
|
|
617
|
-
.create()
|
|
618
|
-
.retain(1)
|
|
619
|
-
.modify(delta.create().insert([yblock("z", "Z", [])])),
|
|
620
|
-
),
|
|
621
|
-
).b!;
|
|
622
|
-
expectDelta(
|
|
623
|
-
again,
|
|
624
|
-
onBlock(
|
|
625
|
-
0,
|
|
626
|
-
delta
|
|
627
|
-
.create()
|
|
628
|
-
.retain(1)
|
|
629
|
-
.insert([delta.create("blockGroup", {}).insert([yblock("z", "Z")])]),
|
|
630
|
-
),
|
|
631
|
-
"the kept group reappears",
|
|
632
|
-
);
|
|
633
|
-
});
|
|
634
|
-
|
|
635
|
-
/** A container with two groups, as a legacy document has after concurrent first nesting. */
|
|
636
|
-
function twoGroups(): AnyBuilder {
|
|
637
|
-
return delta
|
|
638
|
-
.create("blockContainer", { id: "p" })
|
|
639
|
-
.insert([
|
|
640
|
-
delta.create("paragraph", {}, "P"),
|
|
641
|
-
delta
|
|
642
|
-
.create("blockGroup", {})
|
|
643
|
-
.insert([yblock("a", "A"), yblock("b", "B")]),
|
|
644
|
-
delta.create("blockGroup", {}).insert([yblock("c", "C")]),
|
|
645
|
-
]);
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
it("merges several groups of a container into one", () => {
|
|
649
|
-
const s = stage();
|
|
650
|
-
const b = s.applyA(
|
|
651
|
-
delta.cloneDeep(
|
|
652
|
-
delta
|
|
653
|
-
.create()
|
|
654
|
-
.insert([delta.create("blockGroup", {}).insert([twoGroups()])])
|
|
655
|
-
.done(false),
|
|
656
|
-
),
|
|
657
|
-
).b!;
|
|
658
|
-
expectDelta(
|
|
659
|
-
b,
|
|
660
|
-
ydocOf([
|
|
661
|
-
yblock("p", "P", [
|
|
662
|
-
yblock("a", "A"),
|
|
663
|
-
yblock("b", "B"),
|
|
664
|
-
yblock("c", "C"),
|
|
665
|
-
]),
|
|
666
|
-
]),
|
|
667
|
-
"groups merge in order",
|
|
668
|
-
);
|
|
669
|
-
// an insert at the start of the second group lands at merged offset 2
|
|
670
|
-
const ins = s.applyA(
|
|
671
|
-
onBlock(
|
|
672
|
-
0,
|
|
673
|
-
delta
|
|
674
|
-
.create()
|
|
675
|
-
.retain(2)
|
|
676
|
-
.modify(delta.create().insert([yblock("d", "D")])),
|
|
677
|
-
),
|
|
678
|
-
).b!;
|
|
679
|
-
expectDelta(
|
|
680
|
-
ins,
|
|
681
|
-
onBlock(
|
|
682
|
-
0,
|
|
683
|
-
delta
|
|
684
|
-
.create()
|
|
685
|
-
.retain(1)
|
|
686
|
-
.modify(
|
|
687
|
-
delta
|
|
688
|
-
.create()
|
|
689
|
-
.retain(2)
|
|
690
|
-
.insert([yblock("d", "D")]),
|
|
691
|
-
),
|
|
692
|
-
),
|
|
693
|
-
"a second-group insert is offset by the first group",
|
|
694
|
-
);
|
|
695
|
-
// deleting the whole first group deletes its two children from the merged group
|
|
696
|
-
const del = s.applyA(onBlock(0, delta.create().retain(1).delete(1))).b!;
|
|
697
|
-
expectDelta(
|
|
698
|
-
del,
|
|
699
|
-
onBlock(0, delta.create().retain(1).modify(delta.create().delete(2))),
|
|
700
|
-
"deleting a group deletes its children from the view",
|
|
701
|
-
);
|
|
702
|
-
// changes to both groups in one change merge into one modify
|
|
703
|
-
const s2 = stage();
|
|
704
|
-
s2.applyA(
|
|
705
|
-
delta.cloneDeep(
|
|
706
|
-
delta
|
|
707
|
-
.create()
|
|
708
|
-
.insert([delta.create("blockGroup", {}).insert([twoGroups()])])
|
|
709
|
-
.done(false),
|
|
710
|
-
),
|
|
711
|
-
);
|
|
712
|
-
const both = s2.applyA(
|
|
713
|
-
onBlock(
|
|
714
|
-
0,
|
|
715
|
-
delta
|
|
716
|
-
.create()
|
|
717
|
-
.retain(1)
|
|
718
|
-
.modify(delta.create().retain(1).delete(1))
|
|
719
|
-
.modify(
|
|
720
|
-
delta
|
|
721
|
-
.create()
|
|
722
|
-
.retain(1)
|
|
723
|
-
.insert([yblock("e", "E")]),
|
|
724
|
-
),
|
|
725
|
-
),
|
|
726
|
-
).b!;
|
|
727
|
-
expectDelta(
|
|
728
|
-
both,
|
|
729
|
-
onBlock(
|
|
730
|
-
0,
|
|
731
|
-
delta
|
|
732
|
-
.create()
|
|
733
|
-
.retain(1)
|
|
734
|
-
.modify(
|
|
735
|
-
delta
|
|
736
|
-
.create()
|
|
737
|
-
.retain(1)
|
|
738
|
-
.delete(1)
|
|
739
|
-
.retain(1)
|
|
740
|
-
.insert([yblock("e", "E")]),
|
|
741
|
-
),
|
|
742
|
-
),
|
|
743
|
-
"ops on several groups form one merged change",
|
|
744
|
-
);
|
|
745
|
-
});
|
|
746
|
-
|
|
747
|
-
it("creates a group for every container the view inserts, never for a legacy one", () => {
|
|
748
|
-
const s = stage();
|
|
749
|
-
const a = s.applyB(
|
|
750
|
-
delta.cloneDeep(
|
|
751
|
-
ydocOf([yblock("a", "A"), yblock("b", "B", [yblock("b1", "B1")])]).done(
|
|
752
|
-
false,
|
|
753
|
-
),
|
|
754
|
-
),
|
|
755
|
-
).a!;
|
|
756
|
-
expectDelta(
|
|
757
|
-
a,
|
|
758
|
-
ydocOf([
|
|
759
|
-
yblock("a", "A", []),
|
|
760
|
-
yblock("b", "B", [yblock("b1", "B1", [])]),
|
|
761
|
-
]),
|
|
762
|
-
"every view-created container gets a group, at every depth",
|
|
763
|
-
);
|
|
764
|
-
// a container inserted later from the view
|
|
765
|
-
const ins = s.applyB(
|
|
766
|
-
delta.create().modify(
|
|
767
|
-
delta
|
|
768
|
-
.create()
|
|
769
|
-
.retain(2)
|
|
770
|
-
.insert([yblock("c", "C")]),
|
|
771
|
-
),
|
|
772
|
-
).a!;
|
|
773
|
-
expectDelta(
|
|
774
|
-
ins,
|
|
775
|
-
delta.create().modify(
|
|
776
|
-
delta
|
|
777
|
-
.create()
|
|
778
|
-
.retain(2)
|
|
779
|
-
.insert([yblock("c", "C", [])]),
|
|
780
|
-
),
|
|
781
|
-
"a later view insert gets its group too",
|
|
782
|
-
);
|
|
783
|
-
// a legacy container from Y stays without a group until the view nests something
|
|
784
|
-
const s2 = stage();
|
|
785
|
-
s2.applyA(delta.cloneDeep(ydocOf([yblock("l", "L")]).done(false)));
|
|
786
|
-
const typed = s2.applyB(
|
|
787
|
-
onBlock(0, delta.create().modify(delta.create().retain(1).insert("!"))),
|
|
788
|
-
).a!;
|
|
789
|
-
expectDelta(
|
|
790
|
-
typed,
|
|
791
|
-
onBlock(0, delta.create().modify(delta.create().retain(1).insert("!"))),
|
|
792
|
-
"typing into a legacy container creates no group",
|
|
793
|
-
);
|
|
794
|
-
const nested = s2.applyB(
|
|
795
|
-
onBlock(
|
|
796
|
-
0,
|
|
797
|
-
delta
|
|
798
|
-
.create()
|
|
799
|
-
.retain(1)
|
|
800
|
-
.insert([delta.create("blockGroup", {}).insert([yblock("n", "N")])]),
|
|
801
|
-
),
|
|
802
|
-
).a!;
|
|
803
|
-
expectDelta(
|
|
804
|
-
nested,
|
|
805
|
-
onBlock(
|
|
806
|
-
0,
|
|
807
|
-
delta
|
|
808
|
-
.create()
|
|
809
|
-
.retain(1)
|
|
810
|
-
.insert([
|
|
811
|
-
delta.create("blockGroup", {}).insert([yblock("n", "N", [])]),
|
|
812
|
-
]),
|
|
813
|
-
),
|
|
814
|
-
"the first nesting creates the group as the view built it; the nested container gets its own",
|
|
815
|
-
);
|
|
816
|
-
});
|
|
817
|
-
|
|
818
|
-
it("can be configured without implicit groups", () => {
|
|
819
|
-
const s = persistentBlockGroups(YPM.$prosemirrorDelta, {
|
|
820
|
-
implicitGroups: false,
|
|
821
|
-
}).init();
|
|
822
|
-
const a = s.applyB(
|
|
823
|
-
delta.cloneDeep(
|
|
824
|
-
ydocOf([yblock("a", "A"), yblock("b", "B", [yblock("b1", "B1")])]).done(
|
|
825
|
-
false,
|
|
826
|
-
),
|
|
827
|
-
),
|
|
828
|
-
).a!;
|
|
829
|
-
expectDelta(
|
|
830
|
-
a,
|
|
831
|
-
ydocOf([yblock("a", "A"), yblock("b", "B", [yblock("b1", "B1")])]),
|
|
832
|
-
"no group is added",
|
|
833
|
-
);
|
|
834
|
-
const del = s.applyB(onBlock(1, delta.create().retain(1).delete(1))).a!;
|
|
835
|
-
expectDelta(
|
|
836
|
-
del,
|
|
837
|
-
onBlock(1, delta.create().retain(1).modify(delta.create().delete(1))),
|
|
838
|
-
"but an existing group is still kept when emptied",
|
|
839
|
-
);
|
|
840
|
-
});
|
|
841
|
-
|
|
842
|
-
it("routes view changes into the kept groups", () => {
|
|
843
|
-
const s = stage();
|
|
844
|
-
s.applyA(delta.cloneDeep(ydocOf([yblock("a", "A", [])]).done(false)));
|
|
845
|
-
const ins = s.applyB(
|
|
846
|
-
onBlock(
|
|
847
|
-
0,
|
|
848
|
-
delta
|
|
849
|
-
.create()
|
|
850
|
-
.retain(1)
|
|
851
|
-
.insert([delta.create("blockGroup", {}).insert([yblock("x", "X")])]),
|
|
852
|
-
),
|
|
853
|
-
).a!;
|
|
854
|
-
expectDelta(
|
|
855
|
-
ins,
|
|
856
|
-
onBlock(
|
|
857
|
-
0,
|
|
858
|
-
delta
|
|
859
|
-
.create()
|
|
860
|
-
.retain(1)
|
|
861
|
-
.modify(delta.create().insert([yblock("x", "X", [])])),
|
|
862
|
-
),
|
|
863
|
-
"a view group insert routes into the hidden group",
|
|
864
|
-
);
|
|
865
|
-
const del = s.applyB(onBlock(0, delta.create().retain(1).delete(1))).a!;
|
|
866
|
-
expectDelta(
|
|
867
|
-
del,
|
|
868
|
-
onBlock(0, delta.create().retain(1).modify(delta.create().delete(1))),
|
|
869
|
-
"removing the view group empties the group and keeps it",
|
|
870
|
-
);
|
|
871
|
-
const ins2 = s.applyB(
|
|
872
|
-
onBlock(
|
|
873
|
-
0,
|
|
874
|
-
delta
|
|
875
|
-
.create()
|
|
876
|
-
.retain(1)
|
|
877
|
-
.insert([delta.create("blockGroup", {}).insert([yblock("y", "Y")])]),
|
|
878
|
-
),
|
|
879
|
-
).a!;
|
|
880
|
-
expectDelta(
|
|
881
|
-
ins2,
|
|
882
|
-
onBlock(
|
|
883
|
-
0,
|
|
884
|
-
delta
|
|
885
|
-
.create()
|
|
886
|
-
.retain(1)
|
|
887
|
-
.modify(delta.create().insert([yblock("y", "Y", [])])),
|
|
888
|
-
),
|
|
889
|
-
"the kept group is reused",
|
|
890
|
-
);
|
|
891
|
-
// two groups: [a, b] + [c]
|
|
892
|
-
const s2 = stage();
|
|
893
|
-
s2.applyA(
|
|
894
|
-
delta.cloneDeep(
|
|
895
|
-
delta
|
|
896
|
-
.create()
|
|
897
|
-
.insert([delta.create("blockGroup", {}).insert([twoGroups()])])
|
|
898
|
-
.done(false),
|
|
899
|
-
),
|
|
900
|
-
);
|
|
901
|
-
// insert at the boundary (merged offset 2): the earlier group wins
|
|
902
|
-
const boundary = s2.applyB(
|
|
903
|
-
onBlock(
|
|
904
|
-
0,
|
|
905
|
-
delta
|
|
906
|
-
.create()
|
|
907
|
-
.retain(1)
|
|
908
|
-
.modify(
|
|
909
|
-
delta
|
|
910
|
-
.create()
|
|
911
|
-
.retain(2)
|
|
912
|
-
.insert([yblock("d", "D")]),
|
|
913
|
-
),
|
|
914
|
-
),
|
|
915
|
-
).a!;
|
|
916
|
-
expectDelta(
|
|
917
|
-
boundary,
|
|
918
|
-
onBlock(
|
|
919
|
-
0,
|
|
920
|
-
delta
|
|
921
|
-
.create()
|
|
922
|
-
.retain(1)
|
|
923
|
-
.modify(
|
|
924
|
-
delta
|
|
925
|
-
.create()
|
|
926
|
-
.retain(2)
|
|
927
|
-
.insert([yblock("d", "D", [])]),
|
|
928
|
-
),
|
|
929
|
-
),
|
|
930
|
-
"a boundary insert goes to the earlier group",
|
|
931
|
-
);
|
|
932
|
-
// merged layout is now [a, b, d] + [c]; delete offsets 1..3 spans both groups
|
|
933
|
-
const span = s2.applyB(
|
|
934
|
-
onBlock(
|
|
935
|
-
0,
|
|
936
|
-
delta.create().retain(1).modify(delta.create().retain(1).delete(3)),
|
|
937
|
-
),
|
|
938
|
-
).a!;
|
|
939
|
-
expectDelta(
|
|
940
|
-
span,
|
|
941
|
-
onBlock(
|
|
942
|
-
0,
|
|
943
|
-
delta
|
|
944
|
-
.create()
|
|
945
|
-
.retain(1)
|
|
946
|
-
.modify(delta.create().retain(1).delete(2))
|
|
947
|
-
.modify(delta.create().delete(1)),
|
|
948
|
-
),
|
|
949
|
-
"a delete spanning groups is split, groups are kept",
|
|
950
|
-
);
|
|
951
|
-
// merged layout is [a] + []; the view group still exists; modify its only child
|
|
952
|
-
const mod = s2.applyB(
|
|
953
|
-
onBlock(
|
|
954
|
-
0,
|
|
955
|
-
delta
|
|
956
|
-
.create()
|
|
957
|
-
.retain(1)
|
|
958
|
-
.modify(
|
|
959
|
-
delta
|
|
960
|
-
.create()
|
|
961
|
-
.modify(
|
|
962
|
-
delta.create().modify(delta.create().retain(1).insert("!")),
|
|
963
|
-
),
|
|
964
|
-
),
|
|
965
|
-
),
|
|
966
|
-
).a!;
|
|
967
|
-
expectDelta(
|
|
968
|
-
mod,
|
|
969
|
-
onBlock(
|
|
970
|
-
0,
|
|
971
|
-
delta
|
|
972
|
-
.create()
|
|
973
|
-
.retain(1)
|
|
974
|
-
.modify(
|
|
975
|
-
delta
|
|
976
|
-
.create()
|
|
977
|
-
.modify(
|
|
978
|
-
delta.create().modify(delta.create().retain(1).insert("!")),
|
|
979
|
-
),
|
|
980
|
-
),
|
|
981
|
-
),
|
|
982
|
-
"a modify reaches the group holding the position",
|
|
983
|
-
);
|
|
984
|
-
// remove the view group: only the non-empty group gets a delete
|
|
985
|
-
const del2 = s2.applyB(onBlock(0, delta.create().retain(1).delete(1))).a!;
|
|
986
|
-
expectDelta(
|
|
987
|
-
del2,
|
|
988
|
-
onBlock(0, delta.create().retain(1).modify(delta.create().delete(1))),
|
|
989
|
-
"emptying touches only the non-empty groups",
|
|
990
|
-
);
|
|
991
|
-
// now both are empty; a new view group routes into the first
|
|
992
|
-
const ins3 = s2.applyB(
|
|
993
|
-
onBlock(
|
|
994
|
-
0,
|
|
995
|
-
delta
|
|
996
|
-
.create()
|
|
997
|
-
.retain(1)
|
|
998
|
-
.insert([delta.create("blockGroup", {}).insert([yblock("e", "E")])]),
|
|
999
|
-
),
|
|
1000
|
-
).a!;
|
|
1001
|
-
expectDelta(
|
|
1002
|
-
ins3,
|
|
1003
|
-
onBlock(
|
|
1004
|
-
0,
|
|
1005
|
-
delta
|
|
1006
|
-
.create()
|
|
1007
|
-
.retain(1)
|
|
1008
|
-
.modify(delta.create().insert([yblock("e", "E", [])])),
|
|
1009
|
-
),
|
|
1010
|
-
"the first empty group takes a new view group",
|
|
1011
|
-
);
|
|
1012
|
-
});
|
|
1013
|
-
|
|
1014
|
-
it("maps positions through the layout in both directions", () => {
|
|
1015
|
-
const s = stage();
|
|
1016
|
-
s.applyA(
|
|
1017
|
-
delta.cloneDeep(
|
|
1018
|
-
delta
|
|
1019
|
-
.create()
|
|
1020
|
-
.insert([
|
|
1021
|
-
delta
|
|
1022
|
-
.create("blockGroup", {})
|
|
1023
|
-
.insert([twoGroups(), yblock("q", "Q", [])]),
|
|
1024
|
-
])
|
|
1025
|
-
.done(false),
|
|
1026
|
-
),
|
|
1027
|
-
);
|
|
1028
|
-
// Y: doc > group > p > [paragraph, g1[a, b], g2[c]] > paragraph of c > offset 1
|
|
1029
|
-
const inC = dpos.create([0, 0, 2, 0, 0, 1]);
|
|
1030
|
-
const mappedC = dpos.mapPositionsA(s, [inC])[0];
|
|
1031
|
-
expect(
|
|
1032
|
-
mappedC?.path,
|
|
1033
|
-
"a position in the second group maps to the merged offset",
|
|
1034
|
-
).toEqual([0, 0, 1, 2, 0, 1]);
|
|
1035
|
-
const back = dpos.mapPositionsB(s, [mappedC!])[0];
|
|
1036
|
-
expect(back?.path, "and maps back into the second group").toEqual([
|
|
1037
|
-
0, 0, 2, 0, 0, 1,
|
|
1038
|
-
]);
|
|
1039
|
-
const inA = dpos.create([0, 0, 1, 0, 0, 1]);
|
|
1040
|
-
expect(
|
|
1041
|
-
dpos.mapPositionsA(s, [inA])[0]?.path,
|
|
1042
|
-
"a position in the first group keeps its path",
|
|
1043
|
-
).toEqual([0, 0, 1, 0, 0, 1]);
|
|
1044
|
-
// a gap in the container's child list after the hidden group of q: Y [paragraph, g[]] gap 2 -> view gap 1
|
|
1045
|
-
const gapQ = dpos.create([0, 1, 2]);
|
|
1046
|
-
expect(
|
|
1047
|
-
dpos.mapPositionsA(s, [gapQ])[0]?.path,
|
|
1048
|
-
"a gap behind a hidden group maps before it",
|
|
1049
|
-
).toEqual([0, 1, 1]);
|
|
1050
|
-
expect(
|
|
1051
|
-
dpos.mapPositionsB(s, [dpos.create([0, 1, 1])])[0]?.path,
|
|
1052
|
-
"a view gap at the end of a container maps to the end of the Y child list",
|
|
1053
|
-
).toEqual([0, 1, 2]);
|
|
1054
|
-
});
|
|
1055
|
-
});
|
|
1056
|
-
|
|
1057
|
-
// --- 2. the binding -----------------------------------------------------------
|
|
1058
|
-
|
|
1059
|
-
describe("persistent block groups: the binding", () => {
|
|
1060
|
-
it("keeps groups across nesting and un-nesting", () => {
|
|
1061
|
-
const ydoc = new Y.Doc({ gc: false });
|
|
1062
|
-
const a = createPeer(ydoc);
|
|
1063
|
-
try {
|
|
1064
|
-
setDoc(a.view, docOf([block("p", "P"), block("q", "Q")]));
|
|
1065
|
-
expect(
|
|
1066
|
-
yContainers(ydoc.get("bn")).map((c) => c.groups),
|
|
1067
|
-
"every block the view creates has an empty group in Y",
|
|
1068
|
-
).toEqual([[0], [0]]);
|
|
1069
|
-
setDoc(a.view, nest(a.view.state.doc, [1]));
|
|
1070
|
-
expect(
|
|
1071
|
-
yContainer(ydoc.get("bn"), "p").groups,
|
|
1072
|
-
"nesting the first child fills the existing group",
|
|
1073
|
-
).toEqual([1]);
|
|
1074
|
-
expect(
|
|
1075
|
-
yContainer(ydoc.get("bn"), "q").groups,
|
|
1076
|
-
"the moved block keeps a group",
|
|
1077
|
-
).toEqual([0]);
|
|
1078
|
-
setDoc(a.view, typeText(a.view.state.doc, [0, 0], "!"));
|
|
1079
|
-
expect(
|
|
1080
|
-
blockAt(render(ydoc.get("bn")), [0, 0]).textContent,
|
|
1081
|
-
"typing into a nested block syncs",
|
|
1082
|
-
).toBe("Q!");
|
|
1083
|
-
setDoc(a.view, unnest(a.view.state.doc, [0, 0]));
|
|
1084
|
-
expect(
|
|
1085
|
-
yContainer(ydoc.get("bn"), "p").groups,
|
|
1086
|
-
"un-nesting the last child keeps the group, empty",
|
|
1087
|
-
).toEqual([0]);
|
|
1088
|
-
expect(a.view.state.doc.child(0).childCount).toBe(2);
|
|
1089
|
-
expect(
|
|
1090
|
-
blockAt(a.view.state.doc, [0]).childCount,
|
|
1091
|
-
"the view shows no group on the emptied parent",
|
|
1092
|
-
).toBe(1);
|
|
1093
|
-
const b = createPeer(ydoc);
|
|
1094
|
-
try {
|
|
1095
|
-
assertConverged([a, b], "a later peer");
|
|
1096
|
-
} finally {
|
|
1097
|
-
b.destroy();
|
|
1098
|
-
}
|
|
1099
|
-
} finally {
|
|
1100
|
-
a.destroy();
|
|
1101
|
-
}
|
|
1102
|
-
});
|
|
1103
|
-
|
|
1104
|
-
it("merges two users nesting a first child under the same block", () => {
|
|
1105
|
-
const da = new Y.Doc({ gc: false });
|
|
1106
|
-
const db = new Y.Doc({ gc: false });
|
|
1107
|
-
const net = createNetwork([da, db]);
|
|
1108
|
-
const a = createPeer(da);
|
|
1109
|
-
const b = createPeer(db);
|
|
1110
|
-
try {
|
|
1111
|
-
setDoc(
|
|
1112
|
-
a.view,
|
|
1113
|
-
docOf([block("p", "P"), block("x", "X"), block("y", "Y")]),
|
|
1114
|
-
);
|
|
1115
|
-
assertConverged([a, b], "seed");
|
|
1116
|
-
net.pause();
|
|
1117
|
-
// peer a nests x under p; peer b removes x and nests y under p
|
|
1118
|
-
setDoc(a.view, nest(a.view.state.doc, [1])); // p[x], y
|
|
1119
|
-
setDoc(b.view, nest(remove(b.view.state.doc, [1]), [1])); // p[y]
|
|
1120
|
-
expect(yContainer(da.get("bn"), "p").groups).toEqual([1]);
|
|
1121
|
-
expect(yContainer(db.get("bn"), "p").groups).toEqual([1]);
|
|
1122
|
-
net.resume();
|
|
1123
|
-
assertConverged([a, b], "after merge");
|
|
1124
|
-
expect(
|
|
1125
|
-
yContainer(da.get("bn"), "p").groups,
|
|
1126
|
-
"p has exactly one group in Y, holding both moved blocks",
|
|
1127
|
-
).toEqual([2]);
|
|
1128
|
-
expect(
|
|
1129
|
-
a.view.state.doc.child(0).childCount,
|
|
1130
|
-
"the view has a single top-level block",
|
|
1131
|
-
).toBe(1);
|
|
1132
|
-
expect(
|
|
1133
|
-
childrenOf(blockAt(a.view.state.doc, [0]))
|
|
1134
|
-
.map((c) => String(c.attrs.id))
|
|
1135
|
-
.sort((x, y) => x.localeCompare(y)),
|
|
1136
|
-
"with both nested blocks, no duplicates",
|
|
1137
|
-
).toEqual(["x", "y"]);
|
|
1138
|
-
expect(yContainers(da.get("bn")).length, "three containers in Y").toBe(3);
|
|
1139
|
-
} finally {
|
|
1140
|
-
a.destroy();
|
|
1141
|
-
b.destroy();
|
|
1142
|
-
da.destroy();
|
|
1143
|
-
db.destroy();
|
|
1144
|
-
}
|
|
1145
|
-
});
|
|
1146
|
-
|
|
1147
|
-
it("merges two users adding a new nested block under the same parent", () => {
|
|
1148
|
-
const da = new Y.Doc({ gc: false });
|
|
1149
|
-
const db = new Y.Doc({ gc: false });
|
|
1150
|
-
const net = createNetwork([da, db]);
|
|
1151
|
-
const a = createPeer(da);
|
|
1152
|
-
const b = createPeer(db);
|
|
1153
|
-
try {
|
|
1154
|
-
setDoc(a.view, docOf([block("p", "P")]));
|
|
1155
|
-
assertConverged([a, b], "seed");
|
|
1156
|
-
net.pause();
|
|
1157
|
-
setDoc(
|
|
1158
|
-
a.view,
|
|
1159
|
-
updateSiblings(a.view.state.doc, [0], () => [block("a1", "A1")]),
|
|
1160
|
-
);
|
|
1161
|
-
setDoc(
|
|
1162
|
-
b.view,
|
|
1163
|
-
updateSiblings(b.view.state.doc, [0], () => [block("b1", "B1")]),
|
|
1164
|
-
);
|
|
1165
|
-
expect(yContainer(da.get("bn"), "p").groups).toEqual([1]);
|
|
1166
|
-
expect(yContainer(db.get("bn"), "p").groups).toEqual([1]);
|
|
1167
|
-
net.resume();
|
|
1168
|
-
assertConverged([a, b], "after merge");
|
|
1169
|
-
expect(
|
|
1170
|
-
yContainer(da.get("bn"), "p").groups,
|
|
1171
|
-
"one group with both children",
|
|
1172
|
-
).toEqual([2]);
|
|
1173
|
-
expect(
|
|
1174
|
-
childrenOf(blockAt(a.view.state.doc, [0]))
|
|
1175
|
-
.map((c) => String(c.attrs.id))
|
|
1176
|
-
.sort((x, y) => x.localeCompare(y)),
|
|
1177
|
-
).toEqual(["a1", "b1"]);
|
|
1178
|
-
expect(
|
|
1179
|
-
yContainers(da.get("bn")).length,
|
|
1180
|
-
"no container was duplicated",
|
|
1181
|
-
).toBe(3);
|
|
1182
|
-
// and the group survives both children being removed, on either peer
|
|
1183
|
-
setDoc(a.view, remove(a.view.state.doc, [0, 0]));
|
|
1184
|
-
setDoc(b.view, remove(b.view.state.doc, [0, 0]));
|
|
1185
|
-
assertConverged([a, b], "after emptying");
|
|
1186
|
-
expect(
|
|
1187
|
-
yContainer(da.get("bn"), "p").groups,
|
|
1188
|
-
"the group is kept, empty",
|
|
1189
|
-
).toEqual([0]);
|
|
1190
|
-
expect(
|
|
1191
|
-
blockAt(a.view.state.doc, [0]).childCount,
|
|
1192
|
-
"the view hides it",
|
|
1193
|
-
).toBe(1);
|
|
1194
|
-
} finally {
|
|
1195
|
-
a.destroy();
|
|
1196
|
-
b.destroy();
|
|
1197
|
-
da.destroy();
|
|
1198
|
-
db.destroy();
|
|
1199
|
-
}
|
|
1200
|
-
});
|
|
1201
|
-
|
|
1202
|
-
it("merges the groups of a legacy document and routes later edits into them", () => {
|
|
1203
|
-
const da = new Y.Doc({ gc: false });
|
|
1204
|
-
// a legacy document: written without groups
|
|
1205
|
-
da.get("bn").applyDelta(
|
|
1206
|
-
ydocOf([yblock("p", "P"), yblock("q", "Q")]).done(),
|
|
1207
|
-
);
|
|
1208
|
-
const db = new Y.Doc({ gc: false });
|
|
1209
|
-
const net = createNetwork([da, db]);
|
|
1210
|
-
const a = createPeer(da);
|
|
1211
|
-
const b = createPeer(db);
|
|
1212
|
-
try {
|
|
1213
|
-
assertConverged([a, b], "legacy seed");
|
|
1214
|
-
expect(
|
|
1215
|
-
yContainers(da.get("bn")).map((c) => c.groups),
|
|
1216
|
-
"legacy containers have no group and get none implicitly",
|
|
1217
|
-
).toEqual([[], []]);
|
|
1218
|
-
setDoc(a.view, typeText(a.view.state.doc, [0], "!"));
|
|
1219
|
-
expect(
|
|
1220
|
-
yContainer(da.get("bn"), "p").groups,
|
|
1221
|
-
"editing a legacy container creates no group",
|
|
1222
|
-
).toEqual([]);
|
|
1223
|
-
net.pause();
|
|
1224
|
-
setDoc(
|
|
1225
|
-
a.view,
|
|
1226
|
-
updateSiblings(a.view.state.doc, [0], () => [block("a1", "A1")]),
|
|
1227
|
-
);
|
|
1228
|
-
setDoc(
|
|
1229
|
-
b.view,
|
|
1230
|
-
updateSiblings(b.view.state.doc, [0], () => [block("b1", "B1")]),
|
|
1231
|
-
);
|
|
1232
|
-
net.resume();
|
|
1233
|
-
assertConverged([a, b], "after merge");
|
|
1234
|
-
expect(yContainer(da.get("bn"), "p").groups, "two groups in Y").toEqual([
|
|
1235
|
-
1, 1,
|
|
1236
|
-
]);
|
|
1237
|
-
expect(
|
|
1238
|
-
childrenOf(blockAt(a.view.state.doc, [0])).length,
|
|
1239
|
-
"the view merges them",
|
|
1240
|
-
).toBe(2);
|
|
1241
|
-
// type into both nested blocks and nest a third; everything stays in sync
|
|
1242
|
-
setDoc(a.view, typeText(a.view.state.doc, [0, 0], "?"));
|
|
1243
|
-
setDoc(b.view, typeText(b.view.state.doc, [0, 1], "?"));
|
|
1244
|
-
setDoc(
|
|
1245
|
-
a.view,
|
|
1246
|
-
updateSiblings(a.view.state.doc, [0], (sibs) => [
|
|
1247
|
-
...sibs,
|
|
1248
|
-
block("c1", "C1"),
|
|
1249
|
-
]),
|
|
1250
|
-
);
|
|
1251
|
-
assertConverged([a, b], "after edits in a merged group");
|
|
1252
|
-
expect(
|
|
1253
|
-
yContainer(da.get("bn"), "p").groups.reduce((s, n) => s + n, 0),
|
|
1254
|
-
"three nested blocks across the two groups",
|
|
1255
|
-
).toBe(3);
|
|
1256
|
-
// removing all nested blocks keeps both groups
|
|
1257
|
-
setDoc(
|
|
1258
|
-
b.view,
|
|
1259
|
-
updateSiblings(b.view.state.doc, [0], () => []),
|
|
1260
|
-
);
|
|
1261
|
-
assertConverged([a, b], "after emptying");
|
|
1262
|
-
expect(
|
|
1263
|
-
yContainer(da.get("bn"), "p").groups,
|
|
1264
|
-
"both groups are kept",
|
|
1265
|
-
).toEqual([0, 0]);
|
|
1266
|
-
} finally {
|
|
1267
|
-
a.destroy();
|
|
1268
|
-
b.destroy();
|
|
1269
|
-
da.destroy();
|
|
1270
|
-
db.destroy();
|
|
1271
|
-
}
|
|
1272
|
-
});
|
|
1273
|
-
|
|
1274
|
-
it("syncs moves: nest under a parent with children, un-nest, delete a parent", () => {
|
|
1275
|
-
const da = new Y.Doc({ gc: false });
|
|
1276
|
-
const db = new Y.Doc({ gc: false });
|
|
1277
|
-
createNetwork([da, db]);
|
|
1278
|
-
const a = createPeer(da);
|
|
1279
|
-
const b = createPeer(db);
|
|
1280
|
-
try {
|
|
1281
|
-
setDoc(
|
|
1282
|
-
a.view,
|
|
1283
|
-
docOf([
|
|
1284
|
-
block("p", "P", [block("a", "A"), block("b", "B"), block("c", "C")]),
|
|
1285
|
-
block("q", "Q"),
|
|
1286
|
-
]),
|
|
1287
|
-
);
|
|
1288
|
-
assertConverged([a, b], "seed");
|
|
1289
|
-
setDoc(b.view, nest(b.view.state.doc, [1])); // q under p: p[a, b, c, q]
|
|
1290
|
-
assertConverged([a, b], "nest under a parent with children");
|
|
1291
|
-
expect(
|
|
1292
|
-
yContainer(da.get("bn"), "p").groups,
|
|
1293
|
-
"routed into the existing group",
|
|
1294
|
-
).toEqual([4]);
|
|
1295
|
-
setDoc(a.view, unnest(a.view.state.doc, [0, 1])); // b out: p[a], b[c, q]
|
|
1296
|
-
assertConverged([a, b], "un-nest a middle child");
|
|
1297
|
-
expect(
|
|
1298
|
-
yContainer(da.get("bn"), "p").groups,
|
|
1299
|
-
"the parent keeps a one-child group",
|
|
1300
|
-
).toEqual([1]);
|
|
1301
|
-
expect(
|
|
1302
|
-
yContainer(da.get("bn"), "b").groups,
|
|
1303
|
-
"the lifted block holds its followers",
|
|
1304
|
-
).toEqual([2]);
|
|
1305
|
-
setDoc(b.view, remove(b.view.state.doc, [1])); // delete b with its children
|
|
1306
|
-
assertConverged([a, b], "delete a parent");
|
|
1307
|
-
expect(
|
|
1308
|
-
yContainers(da.get("bn")).map((c) => c.id),
|
|
1309
|
-
"the subtree is gone",
|
|
1310
|
-
).toEqual(["p", "a"]);
|
|
1311
|
-
setDoc(
|
|
1312
|
-
a.view,
|
|
1313
|
-
updateSiblings(a.view.state.doc, [0], () => []),
|
|
1314
|
-
);
|
|
1315
|
-
setDoc(
|
|
1316
|
-
b.view,
|
|
1317
|
-
updateSiblings(b.view.state.doc, [], (sibs) => [
|
|
1318
|
-
...sibs,
|
|
1319
|
-
block("r", "R"),
|
|
1320
|
-
]),
|
|
1321
|
-
);
|
|
1322
|
-
assertConverged([a, b], "empty a group while another peer appends");
|
|
1323
|
-
} finally {
|
|
1324
|
-
a.destroy();
|
|
1325
|
-
b.destroy();
|
|
1326
|
-
da.destroy();
|
|
1327
|
-
db.destroy();
|
|
1328
|
-
}
|
|
1329
|
-
});
|
|
1330
|
-
|
|
1331
|
-
it("still replaces the container on a block type change, with its group", () => {
|
|
1332
|
-
const ydoc = new Y.Doc({ gc: false });
|
|
1333
|
-
const a = createPeer(ydoc);
|
|
1334
|
-
try {
|
|
1335
|
-
setDoc(a.view, docOf([block("p", "P", [block("a", "A")])]));
|
|
1336
|
-
const asHeading = docOf([
|
|
1337
|
-
N.blockContainer.create({ id: "p" }, [
|
|
1338
|
-
N.heading.create(null, schema.text("P")),
|
|
1339
|
-
N.blockGroup.create(null, [block("a", "A")]),
|
|
1340
|
-
]),
|
|
1341
|
-
]);
|
|
1342
|
-
setDoc(a.view, asHeading);
|
|
1343
|
-
expect(
|
|
1344
|
-
yContainer(ydoc.get("bn"), "p").groups,
|
|
1345
|
-
"the replaced container has one group with the child",
|
|
1346
|
-
).toEqual([1]);
|
|
1347
|
-
expect(json(render(ydoc.get("bn"))), "the rendering agrees").toEqual(
|
|
1348
|
-
json(a.view.state.doc),
|
|
1349
|
-
);
|
|
1350
|
-
} finally {
|
|
1351
|
-
a.destroy();
|
|
1352
|
-
}
|
|
1353
|
-
});
|
|
1354
|
-
|
|
1355
|
-
/**
|
|
1356
|
-
* The suggestion setup of BlockNote's demo: a base doc, a suggestion doc
|
|
1357
|
-
* with a diff renderer in view mode and one in suggestion mode.
|
|
1358
|
-
*/
|
|
1359
|
-
function createSuggestionSetup() {
|
|
1360
|
-
const base = new Y.Doc({ gc: false, guid: "base" });
|
|
1361
|
-
const viewDoc = new Y.Doc({
|
|
1362
|
-
isSuggestionDoc: true,
|
|
1363
|
-
gc: false,
|
|
1364
|
-
guid: "view",
|
|
1365
|
-
});
|
|
1366
|
-
const editDoc = new Y.Doc({
|
|
1367
|
-
isSuggestionDoc: true,
|
|
1368
|
-
gc: false,
|
|
1369
|
-
guid: "edit",
|
|
1370
|
-
});
|
|
1371
|
-
const attributions = Y.createContentMap();
|
|
1372
|
-
const viewRenderer = Y.createDiffRenderer(base, viewDoc, { attributions });
|
|
1373
|
-
viewRenderer.suggestionMode = false;
|
|
1374
|
-
const editRenderer = Y.createDiffRenderer(base, editDoc, { attributions });
|
|
1375
|
-
editRenderer.suggestionMode = true;
|
|
1376
|
-
createNetwork([viewDoc, editDoc]);
|
|
1377
|
-
const baseView = createPeer(base);
|
|
1378
|
-
const viewing = createPeer(viewDoc, { renderer: viewRenderer });
|
|
1379
|
-
const editing = createPeer(editDoc, { renderer: editRenderer });
|
|
1380
|
-
return {
|
|
1381
|
-
base,
|
|
1382
|
-
baseView,
|
|
1383
|
-
viewing,
|
|
1384
|
-
editing,
|
|
1385
|
-
destroy: () => {
|
|
1386
|
-
baseView.destroy();
|
|
1387
|
-
viewing.destroy();
|
|
1388
|
-
editing.destroy();
|
|
1389
|
-
},
|
|
1390
|
-
};
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
function hasDeleteMark(n: Node): boolean {
|
|
1394
|
-
let found = n.marks.some((m) => m.type.name === "y-attributed-delete");
|
|
1395
|
-
n.descendants((d) => {
|
|
1396
|
-
if (d.marks.some((m) => m.type.name === "y-attributed-delete")) {
|
|
1397
|
-
found = true;
|
|
1398
|
-
}
|
|
1399
|
-
});
|
|
1400
|
-
return found;
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
it("works in suggestion mode: suggest, reject, accept, suggest a deletion", () => {
|
|
1404
|
-
const s = createSuggestionSetup();
|
|
1405
|
-
try {
|
|
1406
|
-
setDoc(s.baseView.view, docOf([block("p", "P"), block("q", "Q")]));
|
|
1407
|
-
expect(
|
|
1408
|
-
stripMarks(json(s.editing.view.state.doc)),
|
|
1409
|
-
"the suggesting peer sees the base",
|
|
1410
|
-
).toEqual(json(s.baseView.view.state.doc));
|
|
1411
|
-
// suggest a nested block under p
|
|
1412
|
-
setDoc(
|
|
1413
|
-
s.editing.view,
|
|
1414
|
-
updateSiblings(s.editing.view.state.doc, [0], () => [block("n", "N")]),
|
|
1415
|
-
);
|
|
1416
|
-
expect(
|
|
1417
|
-
yContainer(s.base.get("bn"), "p").groups,
|
|
1418
|
-
"the base doc is untouched (the insert is a suggestion)",
|
|
1419
|
-
).toEqual([0]);
|
|
1420
|
-
const shown = blockAt(s.viewing.view.state.doc, [0, 0]);
|
|
1421
|
-
expect(
|
|
1422
|
-
shown?.attrs.id,
|
|
1423
|
-
"the viewing peer renders the suggested nested block",
|
|
1424
|
-
).toBe("n");
|
|
1425
|
-
expect(s.viewing.errors).toEqual([]);
|
|
1426
|
-
expect(s.editing.errors).toEqual([]);
|
|
1427
|
-
// reject: the child goes, the group hides
|
|
1428
|
-
YPM.rejectAllChanges()(s.viewing.view.state, s.viewing.view.dispatch);
|
|
1429
|
-
expect(
|
|
1430
|
-
stripMarks(json(s.viewing.view.state.doc)),
|
|
1431
|
-
"rejecting removes the nested block",
|
|
1432
|
-
).toEqual(json(docOf([block("p", "P"), block("q", "Q")])));
|
|
1433
|
-
expect(
|
|
1434
|
-
stripMarks(json(s.editing.view.state.doc)),
|
|
1435
|
-
"the suggesting peer agrees",
|
|
1436
|
-
).toEqual(json(docOf([block("p", "P"), block("q", "Q")])));
|
|
1437
|
-
expect(
|
|
1438
|
-
blockAt(s.viewing.view.state.doc, [0]).childCount,
|
|
1439
|
-
"the group is hidden again",
|
|
1440
|
-
).toBe(1);
|
|
1441
|
-
// suggest again and accept
|
|
1442
|
-
setDoc(
|
|
1443
|
-
s.editing.view,
|
|
1444
|
-
updateSiblings(s.editing.view.state.doc, [0], () => [block("m", "M")]),
|
|
1445
|
-
);
|
|
1446
|
-
YPM.acceptAllChanges()(s.viewing.view.state, s.viewing.view.dispatch);
|
|
1447
|
-
expect(
|
|
1448
|
-
json(s.baseView.view.state.doc),
|
|
1449
|
-
"accepting lands the nested block in the base",
|
|
1450
|
-
).toEqual(
|
|
1451
|
-
json(docOf([block("p", "P", [block("m", "M")]), block("q", "Q")])),
|
|
1452
|
-
);
|
|
1453
|
-
expect(
|
|
1454
|
-
yContainer(s.base.get("bn"), "p").groups,
|
|
1455
|
-
"in the one group",
|
|
1456
|
-
).toEqual([1]);
|
|
1457
|
-
// delete the only nested block as a suggestion: it stays visible as a pending deletion
|
|
1458
|
-
setDoc(
|
|
1459
|
-
s.editing.view,
|
|
1460
|
-
updateSiblings(s.editing.view.state.doc, [0], () => []),
|
|
1461
|
-
);
|
|
1462
|
-
const pending = blockAt(s.viewing.view.state.doc, [0, 0]);
|
|
1463
|
-
expect(
|
|
1464
|
-
pending?.attrs.id,
|
|
1465
|
-
"the deleted nested block is still rendered",
|
|
1466
|
-
).toBe("m");
|
|
1467
|
-
expect(hasDeleteMark(pending), "as a pending deletion").toBe(true);
|
|
1468
|
-
expect(
|
|
1469
|
-
stripMarks(json(s.editing.view.state.doc)),
|
|
1470
|
-
"both suggestion peers agree",
|
|
1471
|
-
).toEqual(stripMarks(json(s.viewing.view.state.doc)));
|
|
1472
|
-
expect(s.viewing.errors).toEqual([]);
|
|
1473
|
-
expect(s.editing.errors).toEqual([]);
|
|
1474
|
-
expect(s.baseView.errors).toEqual([]);
|
|
1475
|
-
YPM.acceptAllChanges()(s.viewing.view.state, s.viewing.view.dispatch);
|
|
1476
|
-
expect(
|
|
1477
|
-
json(s.baseView.view.state.doc),
|
|
1478
|
-
"accepting the deletion removes it from the base",
|
|
1479
|
-
).toEqual(json(docOf([block("p", "P"), block("q", "Q")])));
|
|
1480
|
-
expect(
|
|
1481
|
-
yContainer(s.base.get("bn"), "p").groups,
|
|
1482
|
-
"and keeps the group",
|
|
1483
|
-
).toEqual([0]);
|
|
1484
|
-
expect(
|
|
1485
|
-
blockAt(s.viewing.view.state.doc, [0]).childCount,
|
|
1486
|
-
"which the viewing peer hides",
|
|
1487
|
-
).toBe(1);
|
|
1488
|
-
} finally {
|
|
1489
|
-
s.destroy();
|
|
1490
|
-
}
|
|
1491
|
-
});
|
|
1492
|
-
|
|
1493
|
-
it("round-trips relative positions across peers", () => {
|
|
1494
|
-
const da = new Y.Doc({ gc: false });
|
|
1495
|
-
const db = new Y.Doc({ gc: false });
|
|
1496
|
-
createNetwork([da, db]);
|
|
1497
|
-
const a = createPeer(da);
|
|
1498
|
-
const b = createPeer(db);
|
|
1499
|
-
try {
|
|
1500
|
-
setDoc(
|
|
1501
|
-
a.view,
|
|
1502
|
-
docOf([
|
|
1503
|
-
block("p", "P", [block("a", "Alpha"), block("b", "Beta")]),
|
|
1504
|
-
block("q", "Q"),
|
|
1505
|
-
]),
|
|
1506
|
-
);
|
|
1507
|
-
assertConverged([a, b], "seed");
|
|
1508
|
-
// the position after "Al" in the nested block a
|
|
1509
|
-
let posA = -1;
|
|
1510
|
-
a.view.state.doc.descendants((n, pos) => {
|
|
1511
|
-
if (n.isText && n.text === "Alpha") {
|
|
1512
|
-
posA = pos + 2;
|
|
1513
|
-
}
|
|
1514
|
-
return posA === -1;
|
|
1515
|
-
});
|
|
1516
|
-
expect(posA, "found the text").toBeGreaterThan(0);
|
|
1517
|
-
const rpos = YPM.resolvedPositionToRelativePosition(
|
|
1518
|
-
a.view,
|
|
1519
|
-
a.view.state.doc.resolve(posA),
|
|
1520
|
-
);
|
|
1521
|
-
expect(rpos, "maps into Y through the transformer").not.toBeNull();
|
|
1522
|
-
const onB = YPM.relativePositionToResolvedPosition(b.view, rpos!);
|
|
1523
|
-
expect(onB?.pos, "resolves to the same position on the other peer").toBe(
|
|
1524
|
-
posA,
|
|
1525
|
-
);
|
|
1526
|
-
// still valid after the other peer adds a nested block before it (one group, no replacement)
|
|
1527
|
-
setDoc(
|
|
1528
|
-
b.view,
|
|
1529
|
-
updateSiblings(b.view.state.doc, [0], (sibs) => [
|
|
1530
|
-
block("z", "Zed"),
|
|
1531
|
-
...sibs,
|
|
1532
|
-
]),
|
|
1533
|
-
);
|
|
1534
|
-
assertConverged([a, b], "after an insert before the position");
|
|
1535
|
-
const after = YPM.relativePositionToResolvedPosition(a.view, rpos!);
|
|
1536
|
-
expect(after).not.toBeNull();
|
|
1537
|
-
expect(
|
|
1538
|
-
a.view.state.doc.textBetween(after!.pos - 2, after!.pos),
|
|
1539
|
-
"the relative position follows its text",
|
|
1540
|
-
).toBe("Al");
|
|
1541
|
-
} finally {
|
|
1542
|
-
a.destroy();
|
|
1543
|
-
b.destroy();
|
|
1544
|
-
da.destroy();
|
|
1545
|
-
db.destroy();
|
|
1546
|
-
}
|
|
1547
|
-
});
|
|
1548
|
-
|
|
1549
|
-
it("applies to the standalone conversions", () => {
|
|
1550
|
-
const pm = docOf([block("p", "P", [block("a", "A")]), block("q", "Q")]);
|
|
1551
|
-
const d = YPM.pmnodeToDelta(pm, { transformer: pipeline });
|
|
1552
|
-
const ydoc = new Y.Doc({ gc: false });
|
|
1553
|
-
ydoc.get("bn").applyDelta(d);
|
|
1554
|
-
expect(
|
|
1555
|
-
yContainers(ydoc.get("bn")).map((c) => c.groups),
|
|
1556
|
-
"pmnodeToDelta writes a group into every container",
|
|
1557
|
-
).toEqual([[1], [0], [0]]);
|
|
1558
|
-
expect(
|
|
1559
|
-
json(render(ydoc.get("bn"))),
|
|
1560
|
-
"ynodeToPmnode renders it back",
|
|
1561
|
-
).toEqual(json(pm));
|
|
1562
|
-
const a = createPeer(ydoc);
|
|
1563
|
-
try {
|
|
1564
|
-
expect(json(a.view.state.doc), "a bound view shows the same").toEqual(
|
|
1565
|
-
json(pm),
|
|
1566
|
-
);
|
|
1567
|
-
expect(
|
|
1568
|
-
yContainers(ydoc.get("bn")).map((c) => c.groups),
|
|
1569
|
-
"binding wrote nothing back",
|
|
1570
|
-
).toEqual([[1], [0], [0]]);
|
|
1571
|
-
// without the transformer the empty groups are schema-invalid and get dropped: the compat path
|
|
1572
|
-
const plain = YPM.ynodeToPmnode(ydoc.get("bn"), schema);
|
|
1573
|
-
expect(
|
|
1574
|
-
json(plain),
|
|
1575
|
-
"without the transformer, ynodeToPmnode drops the empty groups",
|
|
1576
|
-
).toEqual(json(pm));
|
|
1577
|
-
} finally {
|
|
1578
|
-
a.destroy();
|
|
1579
|
-
}
|
|
1580
|
-
});
|
|
1581
|
-
|
|
1582
|
-
it("keeps syncing with a client that has no transformer", () => {
|
|
1583
|
-
const da = new Y.Doc({ gc: false });
|
|
1584
|
-
const db = new Y.Doc({ gc: false });
|
|
1585
|
-
createNetwork([da, db]);
|
|
1586
|
-
const a = createPeer(da);
|
|
1587
|
-
try {
|
|
1588
|
-
setDoc(
|
|
1589
|
-
a.view,
|
|
1590
|
-
docOf([block("p", "P", [block("a", "A")]), block("q", "Q")]),
|
|
1591
|
-
);
|
|
1592
|
-
const old = createPeer(db, { withTransformer: false });
|
|
1593
|
-
try {
|
|
1594
|
-
expect(
|
|
1595
|
-
json(old.view.state.doc),
|
|
1596
|
-
"the old client shows the document",
|
|
1597
|
-
).toEqual(json(a.view.state.doc));
|
|
1598
|
-
expect(
|
|
1599
|
-
yContainers(da.get("bn")).map((c) => c.groups),
|
|
1600
|
-
"the old client deleted the empty groups from Y",
|
|
1601
|
-
).toEqual([[1], [], []]);
|
|
1602
|
-
setDoc(old.view, typeText(old.view.state.doc, [1], "!"));
|
|
1603
|
-
setDoc(
|
|
1604
|
-
a.view,
|
|
1605
|
-
updateSiblings(a.view.state.doc, [1], () => [block("n", "N")]),
|
|
1606
|
-
);
|
|
1607
|
-
expect(json(old.view.state.doc), "both keep syncing").toEqual(
|
|
1608
|
-
json(a.view.state.doc),
|
|
1609
|
-
);
|
|
1610
|
-
expect(
|
|
1611
|
-
yContainer(da.get("bn"), "q").groups,
|
|
1612
|
-
"the first nesting under a stripped container creates its group",
|
|
1613
|
-
).toEqual([1]);
|
|
1614
|
-
expect(a.errors).toEqual([]);
|
|
1615
|
-
expect(old.errors).toEqual([]);
|
|
1616
|
-
} finally {
|
|
1617
|
-
old.destroy();
|
|
1618
|
-
}
|
|
1619
|
-
} finally {
|
|
1620
|
-
a.destroy();
|
|
1621
|
-
da.destroy();
|
|
1622
|
-
db.destroy();
|
|
1623
|
-
}
|
|
1624
|
-
});
|
|
1625
|
-
});
|
|
1626
|
-
|
|
1627
|
-
// --- 3. fuzz ----------------------------------------------------------------
|
|
1628
|
-
|
|
1629
|
-
describe("persistent block groups: random nesting on two peers", () => {
|
|
1630
|
-
/**
|
|
1631
|
-
* Random editing on two peers with random sync points. After every full
|
|
1632
|
-
* sync both peers show the same document, which equals the pipeline's
|
|
1633
|
-
* rendering of the Y document, every container the view created holds a
|
|
1634
|
-
* group, and no container ever holds more than one (the whole point: the
|
|
1635
|
-
* view only ever writes into existing groups).
|
|
1636
|
-
*/
|
|
1637
|
-
function run(seed: number) {
|
|
1638
|
-
const gen = prng.create(seed);
|
|
1639
|
-
const da = new Y.Doc({ gc: false });
|
|
1640
|
-
const db = new Y.Doc({ gc: false });
|
|
1641
|
-
const net = createNetwork([da, db]);
|
|
1642
|
-
const peers = [createPeer(da), createPeer(db)];
|
|
1643
|
-
let nextId = 0;
|
|
1644
|
-
const newBlock = () => block(`b${nextId++}`, prng.word(gen, 1, 4));
|
|
1645
|
-
try {
|
|
1646
|
-
setDoc(peers[0].view, docOf([newBlock(), newBlock(), newBlock()]));
|
|
1647
|
-
assertConverged(peers, `seed ${seed}`);
|
|
1648
|
-
const rounds = prng.uint32(gen, 1, 6);
|
|
1649
|
-
for (let r = 0; r < rounds; r++) {
|
|
1650
|
-
net.pause();
|
|
1651
|
-
const ops = prng.uint32(gen, 1, 8);
|
|
1652
|
-
for (let i = 0; i < ops; i++) {
|
|
1653
|
-
const peer = prng.oneOf(gen, peers);
|
|
1654
|
-
const doc = peer.view.state.doc;
|
|
1655
|
-
const paths = allPaths(doc);
|
|
1656
|
-
const path = prng.oneOf(gen, paths);
|
|
1657
|
-
const choice = prng.uint32(gen, 0, 5);
|
|
1658
|
-
let next = doc;
|
|
1659
|
-
if (choice === 0) {
|
|
1660
|
-
next = insertAfter(doc, path, newBlock());
|
|
1661
|
-
} else if (choice === 1) {
|
|
1662
|
-
if (
|
|
1663
|
-
paths.length > 1 &&
|
|
1664
|
-
!(path.length === 1 && topBlocks(doc).length === 1)
|
|
1665
|
-
) {
|
|
1666
|
-
next = remove(doc, path);
|
|
1667
|
-
}
|
|
1668
|
-
} else if (choice === 2) {
|
|
1669
|
-
if (path[path.length - 1] > 0) {
|
|
1670
|
-
next = nest(doc, path);
|
|
1671
|
-
}
|
|
1672
|
-
} else if (choice === 3) {
|
|
1673
|
-
if (path.length > 1) {
|
|
1674
|
-
next = unnest(doc, path);
|
|
1675
|
-
}
|
|
1676
|
-
} else {
|
|
1677
|
-
next = typeText(doc, path, prng.word(gen, 1, 3));
|
|
1678
|
-
}
|
|
1679
|
-
if (next !== doc) {
|
|
1680
|
-
setDoc(peer.view, next);
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
|
-
net.resume();
|
|
1684
|
-
assertConverged(peers, `seed ${seed}, round ${r}`);
|
|
1685
|
-
for (const c of yContainers(da.get("bn"))) {
|
|
1686
|
-
expect(
|
|
1687
|
-
c.groups.length,
|
|
1688
|
-
`seed ${seed}: container ${c.id} holds exactly one group`,
|
|
1689
|
-
).toBe(1);
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
} finally {
|
|
1693
|
-
peers.forEach((p) => p.destroy());
|
|
1694
|
-
da.destroy();
|
|
1695
|
-
db.destroy();
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
|
|
1699
|
-
const seeds = Array.from({ length: 150 }, (_, i) => i);
|
|
1700
|
-
it(
|
|
1701
|
-
"converges and keeps one group per container",
|
|
1702
|
-
{ timeout: 120_000 },
|
|
1703
|
-
() => {
|
|
1704
|
-
for (const seed of seeds) {
|
|
1705
|
-
run(seed);
|
|
1706
|
-
}
|
|
1707
|
-
},
|
|
1708
|
-
);
|
|
1709
|
-
});
|