@blocknote/core 0.55.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-C4TzkGEn.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 +18 -19
- package/dist/de-CakHBokE.js +3 -0
- package/dist/emoji-data.js +102 -0
- package/dist/en-BGdzE27X.js +3 -0
- package/dist/{en-BAn9gxr-.js → en-Ne9rlj9Y.js} +42 -5
- package/dist/es-VeBX6MEG.js +3 -0
- package/dist/extensions-CEgexSyF.js +3091 -0
- 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 +1418 -32
- 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-DksfoQmN.js +3574 -0
- 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 +1284 -559
- package/dist/yjs.js +211 -171
- package/dist/zh-hant-2ZrAkFnC.js +3 -0
- package/dist/zh-jglyCmjs.js +3 -0
- package/package.json +51 -27
- package/src/fonts/inter.css +111 -0
- package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +2 -1
- package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.d.ts +24 -24
- package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.d.ts +3 -2
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +1 -1
- package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +2 -2
- package/types/src/api/blockManipulation/layoutBlocks/fixLayoutBlock.d.ts +34 -0
- package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.fixture.d.ts +465 -0
- package/types/src/api/blockManipulation/setupTestEnv.d.ts +15 -69
- 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/combineTransactionSteps.d.ts +12 -0
- package/types/src/api/exporters/markdown/wrapWithDelimiter.d.ts +6 -0
- package/types/src/api/getBlockInfoFromPos.d.ts +218 -44
- package/types/src/api/{getChangedRange.d.ts → getChangedRangeWithAttrs.d.ts} +1 -1
- package/types/src/api/getChangedRanges.d.ts +23 -0
- package/types/src/api/nodeConversions/fragmentToBlocks.d.ts +0 -3
- package/types/src/api/parsers/markdown/autolink.d.ts +5 -0
- package/types/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.d.ts +4 -0
- package/types/src/blocks/ToggleWrapper/createToggleFrame.d.ts +29 -0
- package/types/src/blocks/defaultBlockTypeItems.d.ts +37 -0
- package/types/src/blocks/defaultBlocks.d.ts +10 -0
- package/types/src/blocks/index.d.ts +2 -1
- package/types/src/editor/BlockNoteEditor.d.ts +38 -9
- package/types/src/editor/managers/BlockManager.d.ts +4 -3
- package/types/src/editor/managers/ExtensionManager/index.d.ts +19 -7
- package/types/src/editor/managers/StateManager.d.ts +1 -1
- package/types/src/editor/managers/StyleManager.d.ts +2 -1
- package/types/src/editor/transformPasted.d.ts +1 -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/exporter/Exporter.d.ts +11 -4
- package/types/src/exporter/mapping.d.ts +13 -1
- package/types/src/extensions/DropCursor/DropCursor.d.ts +1 -1
- package/types/src/extensions/DropCursor/dropIntoChildren.d.ts +38 -0
- package/types/src/extensions/Loading/Loading.d.ts +11 -0
- package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.d.ts +1 -1
- package/types/src/extensions/ReadOnly/ReadOnly.d.ts +21 -0
- package/types/src/extensions/SideMenu/MultipleNodeSelection.d.ts +13 -4
- package/types/src/extensions/SideMenu/SideMenu.d.ts +51 -89
- package/types/src/extensions/SideMenu/blockDropHandling.d.ts +11 -0
- package/types/src/extensions/SideMenu/blockGeometry.d.ts +22 -0
- package/types/src/extensions/SideMenu/dragging.d.ts +0 -4
- package/types/src/extensions/SideMenu/sideMenuHover.d.ts +58 -0
- package/types/src/extensions/Versioning/Versioning.d.ts +36 -311
- package/types/src/extensions/Versioning/createVersioning.d.ts +32 -0
- package/types/src/extensions/Versioning/formatVersionDate.d.ts +7 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.d.ts +65 -36
- package/types/src/extensions/Versioning/index.d.ts +4 -0
- package/types/src/extensions/Versioning/scrollToFirstChange.d.ts +18 -0
- package/types/src/extensions/Versioning/types.d.ts +245 -0
- package/types/src/extensions/Versioning/versioningState.d.ts +49 -0
- package/types/src/extensions/blockDOM.d.ts +37 -0
- package/types/src/extensions/index.d.ts +3 -2
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.d.ts +1 -0
- package/types/src/i18n/dictionary.d.ts +4 -1
- package/types/src/i18n/locales/en.d.ts +38 -0
- package/types/src/i18n/locales/fa.d.ts +38 -0
- package/types/src/i18n/locales/index.d.ts +1 -0
- package/types/src/i18n/locales/sk.d.ts +38 -0
- package/types/src/i18n/locales/tr.d.ts +378 -0
- package/types/src/index.d.ts +5 -3
- package/types/src/pm-nodes/BlockContainer.d.ts +6 -0
- package/types/src/schema/blocks/children.d.ts +39 -0
- package/types/src/schema/blocks/createSpec.d.ts +13 -0
- package/types/src/schema/blocks/frame.d.ts +109 -0
- package/types/src/schema/blocks/internal.d.ts +6 -0
- package/types/src/schema/blocks/keyboard.d.ts +111 -0
- package/types/src/schema/blocks/layoutBlockAttributes.d.ts +9 -0
- package/types/src/schema/blocks/meta.d.ts +14 -0
- package/types/src/schema/blocks/types.d.ts +228 -15
- package/types/src/schema/blocks/validateChildren.d.ts +5 -0
- package/types/src/schema/dataAttributes.d.ts +19 -0
- package/types/src/schema/index.d.ts +3 -0
- 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/markGroups.d.ts +8 -0
- 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/user/userColors.d.ts +24 -3
- package/types/src/y/comments/RESTYjsThreadStore.d.ts +1 -1
- package/types/src/y/comments/YjsThreadStore.d.ts +1 -1
- package/types/src/y/comments/YjsThreadStoreBase.d.ts +2 -2
- package/types/src/y/comments/yjsHelpers.d.ts +5 -5
- package/types/src/y/extensions/AttributionExtension.d.ts +19 -21
- package/types/src/y/extensions/DiffVersioningExtension.d.ts +9 -4
- package/types/src/y/extensions/ForkYDoc.d.ts +3 -1
- package/types/src/y/extensions/Versioning.d.ts +4 -15
- package/types/src/y/extensions/YAttributionMarks.d.ts +13 -2
- package/types/src/y/extensions/YCursorPlugin.d.ts +1 -0
- package/types/src/y/extensions/YSync.d.ts +4 -18
- package/types/src/y/extensions/blockMatchNodes.d.ts +0 -22
- package/types/src/y/extensions/index.d.ts +27 -44
- package/types/src/y/extensions/persistentBlockGroups.d.ts +189 -0
- package/types/src/y/extensions/snapshotCodec.d.ts +13 -0
- package/types/src/y/extensions/snapshotPreview.d.ts +21 -0
- package/types/src/y/index.d.ts +1 -0
- package/types/src/y/utils.d.ts +39 -19
- package/types/src/y/versioning/index.d.ts +1 -1
- package/types/src/y/versioning/yhub.d.ts +71 -86
- package/types/src/y/versioning/yhubClient.d.ts +67 -0
- package/types/src/yjs/extensions/ForkYDoc.d.ts +2 -0
- package/types/src/yjs/extensions/Versioning.d.ts +37 -22
- package/types/src/yjs/extensions/YUndo.d.ts +3 -2
- package/types/src/yjs/extensions/index.d.ts +3 -2
- package/types/src/yjs/index.d.ts +1 -0
- package/dist/BlockNoteExtension-BJCLnwrE.cjs +0 -2
- package/dist/BlockNoteExtension-BJCLnwrE.cjs.map +0 -1
- package/dist/BlockNoteExtension-CbvDA0F7.js +0 -80
- package/dist/BlockNoteExtension-CbvDA0F7.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-C4TzkGEn.js.map +0 -1
- package/dist/UserStore-mj3fXW4D.cjs +0 -2
- package/dist/UserStore-mj3fXW4D.cjs.map +0 -1
- package/dist/blocknote.cjs +0 -1
- package/dist/blocks-DLgTreVu.cjs +0 -12
- package/dist/blocks-DLgTreVu.cjs.map +0 -1
- package/dist/blocks-DaEUT0O1.js +0 -3527
- package/dist/blocks-DaEUT0O1.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-BAn9gxr-.js.map +0 -1
- package/dist/en-CHnrV5l8.cjs +0 -2
- package/dist/en-CHnrV5l8.cjs.map +0 -1
- package/dist/extensions-B1JQURVF.js +0 -2138
- package/dist/extensions-B1JQURVF.js.map +0 -1
- package/dist/extensions-CZkqKzJO.cjs +0 -58
- package/dist/extensions-CZkqKzJO.cjs.map +0 -1
- package/dist/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-D5w0XAHX.js +0 -3379
- package/dist/src-D5w0XAHX.js.map +0 -1
- package/dist/src-th5uZEvx.cjs +0 -23
- package/dist/src-th5uZEvx.cjs.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 -56
- package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +0 -2761
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +0 -147
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +0 -199
- package/src/api/blockManipulation/commands/moveBlocks/__snapshots__/moveBlocks.test.ts.snap +0 -13625
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +0 -375
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +0 -409
- package/src/api/blockManipulation/commands/nestBlock/__snapshots__/nestBlock.test.ts.snap +0 -952
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +0 -661
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +0 -208
- package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +0 -5710
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +0 -235
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +0 -135
- package/src/api/blockManipulation/commands/replaceBlocks/util/fixColumnList.ts +0 -173
- package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +0 -3507
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +0 -151
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +0 -58
- package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +0 -15085
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +0 -978
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +0 -685
- package/src/api/blockManipulation/getBlock/getBlock.ts +0 -111
- package/src/api/blockManipulation/insertContentAt.ts +0 -83
- package/src/api/blockManipulation/selections/selection.ts +0 -267
- package/src/api/blockManipulation/selections/textCursorPosition.ts +0 -118
- package/src/api/blockManipulation/setupTestEnv.ts +0 -191
- 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/exporters/html/externalHTMLExporter.ts +0 -76
- package/src/api/exporters/html/internalHTMLSerializer.ts +0 -182
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +0 -435
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +0 -253
- package/src/api/exporters/markdown/htmlToMarkdown.ts +0 -884
- package/src/api/exporters/markdown/markdownExporter.ts +0 -41
- package/src/api/getBlockInfoFromPos.test.ts +0 -256
- package/src/api/getBlockInfoFromPos.ts +0 -291
- package/src/api/getBlocksChangedByTransaction.test.ts +0 -783
- package/src/api/getBlocksChangedByTransaction.ts +0 -458
- package/src/api/getChangedRange.ts +0 -54
- package/src/api/nodeConversions/blockToNode.test.ts +0 -113
- package/src/api/nodeConversions/blockToNode.ts +0 -399
- package/src/api/nodeConversions/fragmentToBlocks.ts +0 -63
- package/src/api/nodeConversions/nodeToBlock.ts +0 -665
- 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/detectMarkdown.test.ts +0 -211
- package/src/api/parsers/markdown/detectMarkdown.ts +0 -61
- package/src/api/parsers/markdown/markdownToHtml.ts +0 -1340
- 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 -120
- 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 -188
- package/src/blocks/Image/block.ts +0 -193
- package/src/blocks/Image/parseImageElement.ts +0 -7
- package/src/blocks/ListItem/BulletListItem/block.ts +0 -127
- package/src/blocks/ListItem/CheckListItem/block.test.ts +0 -61
- package/src/blocks/ListItem/CheckListItem/block.ts +0 -182
- package/src/blocks/ListItem/ListItemKeyboardShortcuts.ts +0 -63
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +0 -352
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +0 -242
- package/src/blocks/ListItem/NumberedListItem/block.ts +0 -141
- package/src/blocks/ListItem/ToggleListItem/block.ts +0 -128
- 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 -500
- package/src/blocks/ToggleWrapper/createToggleWrapper.ts +0 -197
- 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/defaultBlocks.ts +0 -208
- package/src/blocks/defaultProps.ts +0 -165
- package/src/blocks/getDetailsContent.ts +0 -77
- package/src/blocks/index.ts +0 -29
- package/src/blocks/utils/listItemEnterHandler.ts +0 -43
- 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 -1366
- package/src/editor/BlockNoteEditor.test.ts +0 -278
- package/src/editor/BlockNoteEditor.ts +0 -1497
- 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/cursorPositionTypes.ts +0 -17
- package/src/editor/defaultColors.ts +0 -77
- package/src/editor/editor.css +0 -197
- package/src/editor/managers/BlockManager.ts +0 -255
- 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.test.ts +0 -336
- package/src/editor/managers/ExtensionManager/extensions.ts +0 -191
- package/src/editor/managers/ExtensionManager/index.ts +0 -697
- package/src/editor/managers/ExtensionManager/symbol.ts +0 -5
- package/src/editor/managers/SelectionManager.ts +0 -120
- package/src/editor/managers/StateManager.ts +0 -251
- 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 -293
- package/src/exporter/ExportImage.ts +0 -50
- package/src/exporter/Exporter.test.ts +0 -186
- package/src/exporter/Exporter.ts +0 -155
- package/src/exporter/index.ts +0 -3
- package/src/exporter/mapping.ts +0 -79
- package/src/extensions/BlockChange/BlockChange.ts +0 -67
- package/src/extensions/DropCursor/DropCursor.ts +0 -263
- package/src/extensions/DropCursor/utils.ts +0 -195
- package/src/extensions/FilePanel/FilePanel.ts +0 -41
- package/src/extensions/FormattingToolbar/FormattingToolbar.ts +0 -151
- 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.ts +0 -75
- package/src/extensions/Placeholder/Placeholder.ts +0 -149
- package/src/extensions/PositionMapping/PositionMapping.ts +0 -68
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +0 -120
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +0 -197
- package/src/extensions/README.md +0 -3
- package/src/extensions/ShowSelection/ShowSelection.ts +0 -61
- package/src/extensions/SideMenu/MultipleNodeSelection.ts +0 -89
- package/src/extensions/SideMenu/SideMenu.ts +0 -833
- package/src/extensions/SideMenu/dragging.ts +0 -213
- package/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.ts +0 -192
- 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 -427
- package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +0 -76
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +0 -399
- package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.ts +0 -120
- 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 -1265
- package/src/extensions/TrailingNode/TrailingNode.ts +0 -233
- package/src/extensions/Versioning/Versioning.test.ts +0 -435
- package/src/extensions/Versioning/Versioning.ts +0 -628
- package/src/extensions/Versioning/inMemoryVersioning.test.ts +0 -469
- package/src/extensions/Versioning/inMemoryVersioning.ts +0 -273
- package/src/extensions/Versioning/index.ts +0 -2
- package/src/extensions/getDraggableBlockFromElement.ts +0 -19
- package/src/extensions/index.ts +0 -25
- 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 -204
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +0 -1002
- package/src/extensions/tiptap-extensions/Link/helpers/autolink.ts +0 -179
- 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 -187
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +0 -336
- package/src/extensions/tiptap-extensions/index.ts +0 -7
- package/src/extensions-shared/UiElementPosition.ts +0 -4
- package/src/i18n/dictionary.ts +0 -17
- package/src/i18n/index.ts +0 -2
- package/src/i18n/locales/ar.ts +0 -411
- package/src/i18n/locales/de.ts +0 -445
- package/src/i18n/locales/en.ts +0 -426
- package/src/i18n/locales/es.ts +0 -424
- package/src/i18n/locales/fa.ts +0 -395
- package/src/i18n/locales/fr.ts +0 -472
- package/src/i18n/locales/he.ts +0 -426
- package/src/i18n/locales/hr.ts +0 -440
- package/src/i18n/locales/index.ts +0 -23
- package/src/i18n/locales/is.ts +0 -440
- package/src/i18n/locales/it.ts +0 -448
- package/src/i18n/locales/ja.ts +0 -466
- package/src/i18n/locales/ko.ts +0 -439
- package/src/i18n/locales/nl.ts +0 -427
- package/src/i18n/locales/no.ts +0 -444
- package/src/i18n/locales/pl.ts +0 -417
- package/src/i18n/locales/pt.ts +0 -419
- package/src/i18n/locales/ru.ts +0 -470
- package/src/i18n/locales/sk.ts +0 -424
- package/src/i18n/locales/uk.ts +0 -450
- package/src/i18n/locales/uz.ts +0 -460
- package/src/i18n/locales/vi.ts +0 -425
- package/src/i18n/locales/zh-tw.ts +0 -467
- package/src/i18n/locales/zh.ts +0 -467
- package/src/index.ts +0 -56
- package/src/locales.ts +0 -1
- package/src/pm-nodes/BlockContainer.ts +0 -91
- package/src/pm-nodes/BlockGroup.ts +0 -57
- package/src/pm-nodes/Doc.ts +0 -11
- package/src/pm-nodes/README.md +0 -141
- 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/createSpec.test.ts +0 -123
- package/src/schema/blocks/createSpec.ts +0 -506
- package/src/schema/blocks/extendBlockSpec.test.ts +0 -188
- package/src/schema/blocks/internal.test.ts +0 -86
- package/src/schema/blocks/internal.ts +0 -255
- package/src/schema/blocks/types.ts +0 -702
- package/src/schema/contentTypePropagation.test.ts +0 -182
- package/src/schema/index.ts +0 -12
- package/src/schema/inlineContent/createSpec.test.ts +0 -161
- package/src/schema/inlineContent/createSpec.ts +0 -409
- package/src/schema/inlineContent/internal.ts +0 -136
- package/src/schema/inlineContent/types.ts +0 -204
- package/src/schema/markGroups.ts +0 -50
- 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 -236
- 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.ts +0 -72
- 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 -95
- package/src/y/extensions/AttributionExtension.ts +0 -378
- package/src/y/extensions/DiffVersioningExtension.test.ts +0 -193
- package/src/y/extensions/DiffVersioningExtension.ts +0 -228
- package/src/y/extensions/ForkYDoc.test.ts +0 -253
- package/src/y/extensions/ForkYDoc.ts +0 -108
- package/src/y/extensions/RelativePositionMapping.test.ts +0 -418
- package/src/y/extensions/RelativePositionMapping.ts +0 -49
- package/src/y/extensions/Suggestions.ts +0 -174
- package/src/y/extensions/Versioning.test.ts +0 -408
- package/src/y/extensions/Versioning.ts +0 -115
- package/src/y/extensions/YAttributionMarks.ts +0 -320
- package/src/y/extensions/YCursorPlugin.ts +0 -189
- package/src/y/extensions/YSync.ts +0 -125
- package/src/y/extensions/blockMatchNodes.ts +0 -182
- package/src/y/extensions/index.ts +0 -156
- package/src/y/index.ts +0 -4
- package/src/y/utils.test.ts +0 -1042
- package/src/y/utils.ts +0 -242
- 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 -785
- package/src/y/versioning/index.ts +0 -1
- package/src/y/versioning/yhub.ts +0 -637
- package/src/yjs/README.md +0 -5
- package/src/yjs/comments/RESTYjsThreadStore.test.ts +0 -85
- 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 -88
- package/src/yjs/extensions/ForkYDoc.test.ts +0 -253
- package/src/yjs/extensions/ForkYDoc.ts +0 -159
- 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 -561
- package/src/yjs/extensions/Versioning.ts +0 -83
- 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 -3
- 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/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/replaceBlocks/util/fixColumnList.d.ts +0 -32
- 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/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/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/ListItemKeyboardShortcuts.d.ts +0 -2
- 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/createToggleWrapper.d.ts +0 -15
- package/types/src/blocks/utils/listItemEnterHandler.d.ts +0 -2
- package/types/src/comments/CommentEditorSubmitExtension.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/managers/EventManager.browser.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/PreviousBlockType/PreviousBlockType.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.test.d.ts +0 -1
- package/types/src/extensions/Versioning/inMemoryVersioning.test.d.ts +0 -1
- package/types/src/extensions/getDraggableBlockFromElement.d.ts +0 -5
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.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/schema/blocks/createSpec.test.d.ts +0 -1
- package/types/src/schema/blocks/extendBlockSpec.test.d.ts +0 -1
- package/types/src/schema/blocks/internal.test.d.ts +0 -1
- package/types/src/schema/contentTypePropagation.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/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/ForkYDoc.test.d.ts +0 -1
- package/types/src/y/extensions/RelativePositionMapping.test.d.ts +0 -1
- package/types/src/y/extensions/Versioning.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.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,1497 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createDocument,
|
|
3
|
-
EditorOptions,
|
|
4
|
-
FocusPosition,
|
|
5
|
-
getSchema,
|
|
6
|
-
Editor as TiptapEditor,
|
|
7
|
-
} from "@tiptap/core";
|
|
8
|
-
import { type Command, type Transaction } from "@tiptap/pm/state";
|
|
9
|
-
import { Node, Schema } from "prosemirror-model";
|
|
10
|
-
import type { BlocksChanged } from "../api/getBlocksChangedByTransaction.js";
|
|
11
|
-
import { blockToNode } from "../api/nodeConversions/blockToNode.js";
|
|
12
|
-
import {
|
|
13
|
-
Block,
|
|
14
|
-
BlockNoteSchema,
|
|
15
|
-
DefaultBlockSchema,
|
|
16
|
-
DefaultInlineContentSchema,
|
|
17
|
-
DefaultStyleSchema,
|
|
18
|
-
PartialBlock,
|
|
19
|
-
} from "../blocks/index.js";
|
|
20
|
-
import {
|
|
21
|
-
BlockChangeExtension,
|
|
22
|
-
DropCursorOptions,
|
|
23
|
-
} from "../extensions/index.js";
|
|
24
|
-
import { UniqueID } from "../extensions/tiptap-extensions/UniqueID/UniqueID.js";
|
|
25
|
-
import type { Dictionary } from "../i18n/dictionary.js";
|
|
26
|
-
import { en } from "../i18n/locales/index.js";
|
|
27
|
-
import type {
|
|
28
|
-
BlockIdentifier,
|
|
29
|
-
BlockNoteDOMAttributes,
|
|
30
|
-
BlockSchema,
|
|
31
|
-
BlockSpecs,
|
|
32
|
-
CustomBlockNoteSchema,
|
|
33
|
-
InlineContentSchema,
|
|
34
|
-
InlineContentSpecs,
|
|
35
|
-
PartialInlineContent,
|
|
36
|
-
Styles,
|
|
37
|
-
StyleSchema,
|
|
38
|
-
StyleSpecs,
|
|
39
|
-
} from "../schema/index.js";
|
|
40
|
-
import "../style.css";
|
|
41
|
-
import { mergeCSSClasses } from "../util/browser.js";
|
|
42
|
-
import { EventEmitter } from "../util/EventEmitter.js";
|
|
43
|
-
import type { NoInfer } from "../util/typescript.js";
|
|
44
|
-
import {
|
|
45
|
-
Extension,
|
|
46
|
-
ExtensionFactory,
|
|
47
|
-
ExtensionFactoryInstance,
|
|
48
|
-
} from "./BlockNoteExtension.js";
|
|
49
|
-
import type { TextCursorPosition } from "./cursorPositionTypes.js";
|
|
50
|
-
import {
|
|
51
|
-
BlockManager,
|
|
52
|
-
EditorFocusOptions,
|
|
53
|
-
EventManager,
|
|
54
|
-
ExportManager,
|
|
55
|
-
ExtensionManager,
|
|
56
|
-
SelectionManager,
|
|
57
|
-
StateManager,
|
|
58
|
-
StyleManager,
|
|
59
|
-
} from "./managers/index.js";
|
|
60
|
-
import type { Selection } from "./selectionTypes.js";
|
|
61
|
-
import { transformPasted } from "./transformPasted.js";
|
|
62
|
-
|
|
63
|
-
export type BlockCache<
|
|
64
|
-
BSchema extends BlockSchema = any,
|
|
65
|
-
ISchema extends InlineContentSchema = any,
|
|
66
|
-
SSchema extends StyleSchema = any,
|
|
67
|
-
> = WeakMap<Node, Block<BSchema, ISchema, SSchema>>;
|
|
68
|
-
|
|
69
|
-
export interface BlockNoteEditorOptions<
|
|
70
|
-
BSchema extends BlockSchema,
|
|
71
|
-
ISchema extends InlineContentSchema,
|
|
72
|
-
SSchema extends StyleSchema,
|
|
73
|
-
> {
|
|
74
|
-
/**
|
|
75
|
-
* Whether changes to blocks (like indentation, creating lists, changing headings) should be animated or not. Defaults to `true`.
|
|
76
|
-
*
|
|
77
|
-
* @default true
|
|
78
|
-
*/
|
|
79
|
-
animations?: boolean;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Whether the editor should be focused automatically when it's created.
|
|
83
|
-
*
|
|
84
|
-
* @default false
|
|
85
|
-
*/
|
|
86
|
-
autofocus?: FocusPosition;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Use default BlockNote font and reset the styles of <p> <li> <h1> elements etc., that are used in BlockNote.
|
|
90
|
-
*
|
|
91
|
-
* @default true
|
|
92
|
-
*/
|
|
93
|
-
defaultStyles?: boolean;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* A dictionary object containing translations for the editor.
|
|
97
|
-
*
|
|
98
|
-
* See [Localization / i18n](https://www.blocknotejs.org/docs/advanced/localization) for more info.
|
|
99
|
-
*
|
|
100
|
-
* @remarks `Dictionary` is a type that contains all the translations for the editor.
|
|
101
|
-
*/
|
|
102
|
-
dictionary?: Dictionary & Record<string, any>;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Disable internal extensions (based on keys / extension name)
|
|
106
|
-
*
|
|
107
|
-
* @note Advanced
|
|
108
|
-
*/
|
|
109
|
-
disableExtensions?: string[];
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* An object containing attributes that should be added to HTML elements of the editor.
|
|
113
|
-
*
|
|
114
|
-
* See [Adding DOM Attributes](https://www.blocknotejs.org/docs/theming#adding-dom-attributes) for more info.
|
|
115
|
-
*
|
|
116
|
-
* @example { editor: { class: "my-editor-class" } }
|
|
117
|
-
* @remarks `Record<string, Record<string, string>>`
|
|
118
|
-
*/
|
|
119
|
-
domAttributes?: Partial<BlockNoteDOMAttributes>;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Options for configuring the drop cursor behavior when dragging and dropping blocks.
|
|
123
|
-
* Allows customization of cursor appearance and drop position computation through hooks.
|
|
124
|
-
* @remarks `DropCursorOptions`
|
|
125
|
-
*/
|
|
126
|
-
dropCursor?: DropCursorOptions;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* The content that should be in the editor when it's created, represented as an array of {@link PartialBlock} objects.
|
|
130
|
-
*
|
|
131
|
-
* See [Partial Blocks](https://www.blocknotejs.org/docs/editor-api/manipulating-blocks#partial-blocks) for more info.
|
|
132
|
-
*
|
|
133
|
-
* @remarks `PartialBlock[]`
|
|
134
|
-
*/
|
|
135
|
-
initialContent?: PartialBlock<
|
|
136
|
-
NoInfer<BSchema>,
|
|
137
|
-
NoInfer<ISchema>,
|
|
138
|
-
NoInfer<SSchema>
|
|
139
|
-
>[];
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Options for configuring how links behave in the editor.
|
|
143
|
-
*/
|
|
144
|
-
links?: {
|
|
145
|
-
/**
|
|
146
|
-
* HTML attributes to add to rendered link elements.
|
|
147
|
-
*
|
|
148
|
-
* @default {}
|
|
149
|
-
* @example { class: "my-link-class", target: "_blank" }
|
|
150
|
-
*/
|
|
151
|
-
HTMLAttributes?: Record<string, any>;
|
|
152
|
-
/**
|
|
153
|
-
* Custom handler invoked when a link is clicked. If left `undefined`,
|
|
154
|
-
* links are opened in a new window on click. If provided, the default
|
|
155
|
-
* open-on-click behavior is disabled and this function is called instead.
|
|
156
|
-
*
|
|
157
|
-
* Return `false` to let ProseMirror continue handling the click event.
|
|
158
|
-
* Returning `true` or nothing (the default) marks the event as handled.
|
|
159
|
-
*/
|
|
160
|
-
onClick?: (
|
|
161
|
-
event: MouseEvent,
|
|
162
|
-
editor: BlockNoteEditor<any, any, any>,
|
|
163
|
-
) => boolean | void;
|
|
164
|
-
/**
|
|
165
|
-
* Callback that decides whether a given `href` is a valid link. Applied at
|
|
166
|
-
* every gate where a link enters the document: HTML import, HTML export,
|
|
167
|
-
* paste, and autolink. Useful for supporting additional URI schemes (e.g.
|
|
168
|
-
* `vscode:`, `myapp:`) or tightening the default allowlist.
|
|
169
|
-
*
|
|
170
|
-
* Defaults to `isAllowedUri`, which allows
|
|
171
|
-
* `http|https|ftp|ftps|mailto|tel|callto|sms|cid|xmpp`. Import
|
|
172
|
-
* `isAllowedUri` from `@blocknote/core` to layer on top of the default.
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* ```ts
|
|
176
|
-
* import { isAllowedUri } from "@blocknote/core";
|
|
177
|
-
*
|
|
178
|
-
* BlockNoteEditor.create({
|
|
179
|
-
* links: {
|
|
180
|
-
* isValidLink: (href) =>
|
|
181
|
-
* isAllowedUri(href) || href.startsWith("myapp:"),
|
|
182
|
-
* },
|
|
183
|
-
* });
|
|
184
|
-
* ```
|
|
185
|
-
*/
|
|
186
|
-
isValidLink?: (href: string) => boolean;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* @deprecated, provide placeholders via dictionary instead
|
|
191
|
-
* @internal
|
|
192
|
-
*/
|
|
193
|
-
placeholders?: Record<string, string | undefined>;
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Custom paste handler that can be used to override the default paste behavior.
|
|
197
|
-
*
|
|
198
|
-
* See [Paste Handling](https://www.blocknotejs.org/docs/advanced/paste-handling) for more info.
|
|
199
|
-
*
|
|
200
|
-
* @remarks `PasteHandler`
|
|
201
|
-
* @returns The function should return `true` if the paste event was handled, otherwise it should return `false` if it should be canceled or `undefined` if it should be handled by another handler.
|
|
202
|
-
*
|
|
203
|
-
* @example
|
|
204
|
-
* ```ts
|
|
205
|
-
* pasteHandler: ({ defaultPasteHandler }) => {
|
|
206
|
-
* return defaultPasteHandler({ pasteBehavior: "prefer-html" });
|
|
207
|
-
* }
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
pasteHandler?: (context: {
|
|
211
|
-
event: ClipboardEvent;
|
|
212
|
-
editor: BlockNoteEditor<
|
|
213
|
-
NoInfer<BSchema>,
|
|
214
|
-
NoInfer<ISchema>,
|
|
215
|
-
NoInfer<SSchema>
|
|
216
|
-
>;
|
|
217
|
-
/**
|
|
218
|
-
* The default paste handler
|
|
219
|
-
* @param context The context object
|
|
220
|
-
* @returns Whether the paste event was handled or not
|
|
221
|
-
*/
|
|
222
|
-
defaultPasteHandler: (context?: {
|
|
223
|
-
/**
|
|
224
|
-
* Whether to prioritize Markdown content in `text/plain` over `text/html` when pasting from the clipboard.
|
|
225
|
-
* @default true
|
|
226
|
-
*/
|
|
227
|
-
prioritizeMarkdownOverHTML?: boolean;
|
|
228
|
-
/**
|
|
229
|
-
* Whether to parse `text/plain` content from the clipboard as Markdown content.
|
|
230
|
-
* @default true
|
|
231
|
-
*/
|
|
232
|
-
plainTextAsMarkdown?: boolean;
|
|
233
|
-
}) => boolean | undefined;
|
|
234
|
-
}) => boolean | undefined;
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Resolve a URL of a file block to one that can be displayed or downloaded. This can be used for creating authenticated URL or
|
|
238
|
-
* implementing custom protocols / schemes
|
|
239
|
-
* @returns The URL that's
|
|
240
|
-
*/
|
|
241
|
-
resolveFileUrl?: (url: string) => Promise<string>;
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* The schema of the editor. The schema defines which Blocks, InlineContent, and Styles are available in the editor.
|
|
245
|
-
*
|
|
246
|
-
* See [Custom Schemas](https://www.blocknotejs.org/docs/custom-schemas) for more info.
|
|
247
|
-
* @remarks `BlockNoteSchema`
|
|
248
|
-
*/
|
|
249
|
-
schema: CustomBlockNoteSchema<BSchema, ISchema, SSchema>;
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* A flag indicating whether to set an HTML ID for every block
|
|
253
|
-
*
|
|
254
|
-
* When set to `true`, on each block an id attribute will be set with the block id
|
|
255
|
-
* Otherwise, the HTML ID attribute will not be set.
|
|
256
|
-
*
|
|
257
|
-
* (note that the id is always set on the `data-id` attribute)
|
|
258
|
-
*/
|
|
259
|
-
setIdAttribute?: boolean;
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Determines behavior when pressing Tab (or Shift-Tab) while multiple blocks are selected and a toolbar is open.
|
|
263
|
-
* - `"prefer-navigate-ui"`: Changes focus to the toolbar. User must press Escape to close toolbar before indenting blocks. Better for keyboard accessibility.
|
|
264
|
-
* - `"prefer-indent"`: Always indents selected blocks, regardless of toolbar state. Keyboard navigation of toolbars not possible.
|
|
265
|
-
* @default "prefer-navigate-ui"
|
|
266
|
-
*/
|
|
267
|
-
tabBehavior?: "prefer-navigate-ui" | "prefer-indent";
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Allows enabling / disabling features of tables.
|
|
271
|
-
*
|
|
272
|
-
* See [Tables](https://www.blocknotejs.org/docs/editor-basics/document-structure#tables) for more info.
|
|
273
|
-
*
|
|
274
|
-
* @remarks `TableConfig`
|
|
275
|
-
*/
|
|
276
|
-
tables?: {
|
|
277
|
-
/**
|
|
278
|
-
* Whether to allow splitting and merging cells within a table.
|
|
279
|
-
*
|
|
280
|
-
* @default false
|
|
281
|
-
*/
|
|
282
|
-
splitCells?: boolean;
|
|
283
|
-
/**
|
|
284
|
-
* Whether to allow changing the background color of cells.
|
|
285
|
-
*
|
|
286
|
-
* @default false
|
|
287
|
-
*/
|
|
288
|
-
cellBackgroundColor?: boolean;
|
|
289
|
-
/**
|
|
290
|
-
* Whether to allow changing the text color of cells.
|
|
291
|
-
*
|
|
292
|
-
* @default false
|
|
293
|
-
*/
|
|
294
|
-
cellTextColor?: boolean;
|
|
295
|
-
/**
|
|
296
|
-
* Whether to allow changing cells into headers.
|
|
297
|
-
*
|
|
298
|
-
* @default false
|
|
299
|
-
*/
|
|
300
|
-
headers?: boolean;
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* When the editor document doesn't end in an empty paragraph block, this option causes the editor to render an element simulating one.
|
|
305
|
-
* When clicked by the user, it gets turned into an actual block at the end of the document. This element is not shown when the option is `false`.
|
|
306
|
-
*
|
|
307
|
-
* @default true
|
|
308
|
-
*/
|
|
309
|
-
trailingBlock?: boolean;
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* The `uploadFile` method is what the editor uses when files need to be uploaded (for example when selecting an image to upload).
|
|
313
|
-
* This method should set when creating the editor as this is application-specific.
|
|
314
|
-
*
|
|
315
|
-
* `undefined` means the application doesn't support file uploads.
|
|
316
|
-
*
|
|
317
|
-
* @param file The file that should be uploaded.
|
|
318
|
-
* @returns The URL of the uploaded file OR an object containing props that should be set on the file block (such as an id)
|
|
319
|
-
* @remarks `(file: File) => Promise<UploadFileResult>`
|
|
320
|
-
*/
|
|
321
|
-
uploadFile?: (
|
|
322
|
-
file: File,
|
|
323
|
-
blockId?: string,
|
|
324
|
-
) => Promise<string | Record<string, any>>;
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* additional tiptap options, undocumented
|
|
328
|
-
* @internal
|
|
329
|
-
*/
|
|
330
|
-
_tiptapOptions?: Partial<EditorOptions>;
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Register extensions to the editor.
|
|
334
|
-
*
|
|
335
|
-
* See [Extensions](/docs/features/extensions) for more info.
|
|
336
|
-
*
|
|
337
|
-
* @remarks `ExtensionFactory[]`
|
|
338
|
-
*/
|
|
339
|
-
extensions?: Array<ExtensionFactoryInstance>;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
const blockNoteTipTapOptions = {
|
|
343
|
-
enableInputRules: true,
|
|
344
|
-
enablePasteRules: true,
|
|
345
|
-
enableCoreExtensions: false,
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
export class BlockNoteEditor<
|
|
349
|
-
BSchema extends BlockSchema = DefaultBlockSchema,
|
|
350
|
-
ISchema extends InlineContentSchema = DefaultInlineContentSchema,
|
|
351
|
-
SSchema extends StyleSchema = DefaultStyleSchema,
|
|
352
|
-
> extends EventEmitter<{
|
|
353
|
-
create: void;
|
|
354
|
-
}> {
|
|
355
|
-
/**
|
|
356
|
-
* The underlying prosemirror schema
|
|
357
|
-
*/
|
|
358
|
-
public readonly pmSchema: Schema;
|
|
359
|
-
|
|
360
|
-
public readonly _tiptapEditor: TiptapEditor & {
|
|
361
|
-
contentComponent: any;
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Used by React to store a reference to an `ElementRenderer` helper utility to make sure we can render React elements
|
|
366
|
-
* in the correct context (used by `ReactRenderUtil`)
|
|
367
|
-
*/
|
|
368
|
-
public elementRenderer: ((node: any, container: HTMLElement) => void) | null =
|
|
369
|
-
null;
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Cache of all blocks. This makes sure we don't have to "recompute" blocks if underlying Prosemirror Nodes haven't changed.
|
|
373
|
-
* This is especially useful when we want to keep track of the same block across multiple operations,
|
|
374
|
-
* with this cache, blocks stay the same object reference (referential equality with ===).
|
|
375
|
-
*/
|
|
376
|
-
public blockCache: BlockCache = new WeakMap();
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* The dictionary contains translations for the editor.
|
|
380
|
-
*/
|
|
381
|
-
public readonly dictionary: Dictionary & Record<string, any>;
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* The schema of the editor. The schema defines which Blocks, InlineContent, and Styles are available in the editor.
|
|
385
|
-
*/
|
|
386
|
-
public readonly schema: BlockNoteSchema<BSchema, ISchema, SSchema>;
|
|
387
|
-
|
|
388
|
-
public readonly blockImplementations: BlockSpecs;
|
|
389
|
-
public readonly inlineContentImplementations: InlineContentSpecs;
|
|
390
|
-
public readonly styleImplementations: StyleSpecs;
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* The `uploadFile` method is what the editor uses when files need to be uploaded (for example when selecting an image to upload).
|
|
394
|
-
* This method should set when creating the editor as this is application-specific.
|
|
395
|
-
*
|
|
396
|
-
* `undefined` means the application doesn't support file uploads.
|
|
397
|
-
*
|
|
398
|
-
* @param file The file that should be uploaded.
|
|
399
|
-
* @returns The URL of the uploaded file OR an object containing props that should be set on the file block (such as an id)
|
|
400
|
-
*/
|
|
401
|
-
public readonly uploadFile:
|
|
402
|
-
| ((file: File, blockId?: string) => Promise<string | Record<string, any>>)
|
|
403
|
-
| undefined;
|
|
404
|
-
|
|
405
|
-
private onUploadStartCallbacks: ((blockId?: string) => void)[] = [];
|
|
406
|
-
private onUploadEndCallbacks: ((blockId?: string) => void)[] = [];
|
|
407
|
-
|
|
408
|
-
public readonly resolveFileUrl?: (url: string) => Promise<string>;
|
|
409
|
-
/**
|
|
410
|
-
* Editor settings
|
|
411
|
-
*/
|
|
412
|
-
public readonly settings: {
|
|
413
|
-
tables: {
|
|
414
|
-
splitCells: boolean;
|
|
415
|
-
cellBackgroundColor: boolean;
|
|
416
|
-
cellTextColor: boolean;
|
|
417
|
-
headers: boolean;
|
|
418
|
-
};
|
|
419
|
-
};
|
|
420
|
-
public static create<
|
|
421
|
-
Options extends Partial<BlockNoteEditorOptions<any, any, any>> | undefined,
|
|
422
|
-
>(
|
|
423
|
-
options?: Options,
|
|
424
|
-
): Options extends {
|
|
425
|
-
schema: CustomBlockNoteSchema<infer BSchema, infer ISchema, infer SSchema>;
|
|
426
|
-
}
|
|
427
|
-
? BlockNoteEditor<BSchema, ISchema, SSchema>
|
|
428
|
-
: BlockNoteEditor<
|
|
429
|
-
DefaultBlockSchema,
|
|
430
|
-
DefaultInlineContentSchema,
|
|
431
|
-
DefaultStyleSchema
|
|
432
|
-
> {
|
|
433
|
-
return new BlockNoteEditor(options ?? {}) as any;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
protected constructor(
|
|
437
|
-
protected readonly options: Partial<
|
|
438
|
-
BlockNoteEditorOptions<BSchema, ISchema, SSchema>
|
|
439
|
-
>,
|
|
440
|
-
) {
|
|
441
|
-
super();
|
|
442
|
-
|
|
443
|
-
this.dictionary = options.dictionary || en;
|
|
444
|
-
this.settings = {
|
|
445
|
-
tables: {
|
|
446
|
-
splitCells: options?.tables?.splitCells ?? false,
|
|
447
|
-
cellBackgroundColor: options?.tables?.cellBackgroundColor ?? false,
|
|
448
|
-
cellTextColor: options?.tables?.cellTextColor ?? false,
|
|
449
|
-
headers: options?.tables?.headers ?? false,
|
|
450
|
-
},
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
// apply defaults
|
|
454
|
-
const newOptions = {
|
|
455
|
-
defaultStyles: true,
|
|
456
|
-
schema:
|
|
457
|
-
options.schema ||
|
|
458
|
-
(BlockNoteSchema.create() as unknown as CustomBlockNoteSchema<
|
|
459
|
-
BSchema,
|
|
460
|
-
ISchema,
|
|
461
|
-
SSchema
|
|
462
|
-
>),
|
|
463
|
-
...options,
|
|
464
|
-
placeholders: {
|
|
465
|
-
...this.dictionary.placeholders,
|
|
466
|
-
...options.placeholders,
|
|
467
|
-
},
|
|
468
|
-
};
|
|
469
|
-
|
|
470
|
-
this.schema = newOptions.schema;
|
|
471
|
-
this.blockImplementations = newOptions.schema.blockSpecs;
|
|
472
|
-
this.inlineContentImplementations = newOptions.schema.inlineContentSpecs;
|
|
473
|
-
this.styleImplementations = newOptions.schema.styleSpecs;
|
|
474
|
-
|
|
475
|
-
// TODO this should just be an extension
|
|
476
|
-
if (newOptions.uploadFile) {
|
|
477
|
-
const uploadFile = newOptions.uploadFile;
|
|
478
|
-
this.uploadFile = async (file, blockId) => {
|
|
479
|
-
this.onUploadStartCallbacks.forEach((callback) =>
|
|
480
|
-
callback.apply(this, [blockId]),
|
|
481
|
-
);
|
|
482
|
-
try {
|
|
483
|
-
return await uploadFile(file, blockId);
|
|
484
|
-
} finally {
|
|
485
|
-
this.onUploadEndCallbacks.forEach((callback) =>
|
|
486
|
-
callback.apply(this, [blockId]),
|
|
487
|
-
);
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
this.resolveFileUrl = newOptions.resolveFileUrl;
|
|
493
|
-
|
|
494
|
-
this._eventManager = new EventManager(this as any);
|
|
495
|
-
this._extensionManager = new ExtensionManager(this, newOptions);
|
|
496
|
-
|
|
497
|
-
const tiptapExtensions = this._extensionManager.getTiptapExtensions();
|
|
498
|
-
|
|
499
|
-
const tiptapOptions: EditorOptions = {
|
|
500
|
-
...blockNoteTipTapOptions,
|
|
501
|
-
...newOptions._tiptapOptions,
|
|
502
|
-
element: null,
|
|
503
|
-
autofocus: newOptions.autofocus ?? false,
|
|
504
|
-
extensions: tiptapExtensions,
|
|
505
|
-
editorProps: {
|
|
506
|
-
scrollMargin: { top: 72, bottom: 72, left: 0, right: 0 },
|
|
507
|
-
...newOptions._tiptapOptions?.editorProps,
|
|
508
|
-
attributes: {
|
|
509
|
-
// As of TipTap v2.5.0 the tabIndex is removed when the editor is not
|
|
510
|
-
// editable, so you can't focus it. We want to revert this as we have
|
|
511
|
-
// UI behaviour that relies on it.
|
|
512
|
-
tabIndex: "0",
|
|
513
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-spread
|
|
514
|
-
...newOptions._tiptapOptions?.editorProps?.attributes,
|
|
515
|
-
...newOptions.domAttributes?.editor,
|
|
516
|
-
class: mergeCSSClasses(
|
|
517
|
-
"bn-editor",
|
|
518
|
-
newOptions.defaultStyles ? "bn-default-styles" : "",
|
|
519
|
-
newOptions.domAttributes?.editor?.class || "",
|
|
520
|
-
),
|
|
521
|
-
},
|
|
522
|
-
transformPasted,
|
|
523
|
-
},
|
|
524
|
-
} as any;
|
|
525
|
-
|
|
526
|
-
try {
|
|
527
|
-
const initialContent = newOptions.initialContent || [
|
|
528
|
-
{
|
|
529
|
-
type: "paragraph",
|
|
530
|
-
id: UniqueID.options.generateID(),
|
|
531
|
-
},
|
|
532
|
-
];
|
|
533
|
-
|
|
534
|
-
if (!Array.isArray(initialContent) || initialContent.length === 0) {
|
|
535
|
-
throw new Error(
|
|
536
|
-
"initialContent must be a non-empty array of blocks, received: " +
|
|
537
|
-
JSON.stringify(initialContent),
|
|
538
|
-
);
|
|
539
|
-
}
|
|
540
|
-
const schema = getSchema(tiptapOptions.extensions!);
|
|
541
|
-
// `blockToNode` (via `isPlainContentNodeType`) resolves the block schema
|
|
542
|
-
// through `schema.cached.blockNoteEditor`, so stamp it on this throwaway
|
|
543
|
-
// schema now — the real `pmSchema` is stamped separately below.
|
|
544
|
-
schema.cached.blockNoteEditor = this;
|
|
545
|
-
const pmNodes = initialContent.map((b) =>
|
|
546
|
-
blockToNode(b, schema, this.schema.styleSchema).toJSON(),
|
|
547
|
-
);
|
|
548
|
-
const doc = createDocument(
|
|
549
|
-
{
|
|
550
|
-
type: "doc",
|
|
551
|
-
content: [
|
|
552
|
-
{
|
|
553
|
-
type: "blockGroup",
|
|
554
|
-
content: pmNodes,
|
|
555
|
-
},
|
|
556
|
-
],
|
|
557
|
-
},
|
|
558
|
-
schema,
|
|
559
|
-
tiptapOptions.parseOptions,
|
|
560
|
-
);
|
|
561
|
-
|
|
562
|
-
this._tiptapEditor = new TiptapEditor({
|
|
563
|
-
...tiptapOptions,
|
|
564
|
-
content: doc.toJSON(),
|
|
565
|
-
}) as any;
|
|
566
|
-
this.pmSchema = this._tiptapEditor.schema;
|
|
567
|
-
} catch (e) {
|
|
568
|
-
throw new Error(
|
|
569
|
-
"Error creating document from blocks passed as `initialContent`",
|
|
570
|
-
{ cause: e },
|
|
571
|
-
);
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
this.pmSchema.cached.blockNoteEditor = this;
|
|
575
|
-
|
|
576
|
-
this._tiptapEditor.on("mount", () => {
|
|
577
|
-
this.headless = false;
|
|
578
|
-
});
|
|
579
|
-
this._tiptapEditor.on("unmount", () => {
|
|
580
|
-
this.headless = true;
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
// Initialize managers
|
|
584
|
-
this._blockManager = new BlockManager(this as any);
|
|
585
|
-
|
|
586
|
-
this._exportManager = new ExportManager(this as any);
|
|
587
|
-
this._selectionManager = new SelectionManager(this as any);
|
|
588
|
-
this._stateManager = new StateManager(this as any);
|
|
589
|
-
this._styleManager = new StyleManager(this as any);
|
|
590
|
-
|
|
591
|
-
this.emit("create");
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
// Manager instances
|
|
595
|
-
private readonly _blockManager: BlockManager<any, any, any>;
|
|
596
|
-
private readonly _eventManager: EventManager<any, any, any>;
|
|
597
|
-
private readonly _exportManager: ExportManager<any, any, any>;
|
|
598
|
-
private readonly _extensionManager: ExtensionManager;
|
|
599
|
-
private readonly _selectionManager: SelectionManager<any, any, any>;
|
|
600
|
-
private readonly _stateManager: StateManager;
|
|
601
|
-
private readonly _styleManager: StyleManager<any, any, any>;
|
|
602
|
-
|
|
603
|
-
/**
|
|
604
|
-
* BlockNote extensions that are added to the editor, keyed by the extension key
|
|
605
|
-
*/
|
|
606
|
-
public get extensions() {
|
|
607
|
-
return this._extensionManager.getExtensions();
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
/**
|
|
611
|
-
* Execute a prosemirror command. This is mostly for backwards compatibility with older code.
|
|
612
|
-
*
|
|
613
|
-
* @note You should prefer the {@link transact} method when possible, as it will automatically handle the dispatching of the transaction and work across blocknote transactions.
|
|
614
|
-
*
|
|
615
|
-
* @example
|
|
616
|
-
* ```ts
|
|
617
|
-
* editor.exec((state, dispatch, view) => {
|
|
618
|
-
* dispatch(state.tr.insertText("Hello, world!"));
|
|
619
|
-
* });
|
|
620
|
-
* ```
|
|
621
|
-
*/
|
|
622
|
-
public exec(command: Command) {
|
|
623
|
-
return this._stateManager.exec(command);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
/**
|
|
627
|
-
* Check if a command can be executed. A command should return `false` if it is not valid in the current state.
|
|
628
|
-
*
|
|
629
|
-
* @example
|
|
630
|
-
* ```ts
|
|
631
|
-
* if (editor.canExec(command)) {
|
|
632
|
-
* // show button
|
|
633
|
-
* } else {
|
|
634
|
-
* // hide button
|
|
635
|
-
* }
|
|
636
|
-
* ```
|
|
637
|
-
*/
|
|
638
|
-
public canExec(command: Command): boolean {
|
|
639
|
-
return this._stateManager.canExec(command);
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
/**
|
|
643
|
-
* Execute a function within a "blocknote transaction".
|
|
644
|
-
* All changes to the editor within the transaction will be grouped together, so that
|
|
645
|
-
* we can dispatch them as a single operation (thus creating only a single undo step)
|
|
646
|
-
*
|
|
647
|
-
* @note There is no need to dispatch the transaction, as it will be automatically dispatched when the callback is complete.
|
|
648
|
-
*
|
|
649
|
-
* @example
|
|
650
|
-
* ```ts
|
|
651
|
-
* // All changes to the editor will be grouped together
|
|
652
|
-
* editor.transact((tr) => {
|
|
653
|
-
* tr.insertText("Hello, world!");
|
|
654
|
-
* // These two operations will be grouped together in a single undo step
|
|
655
|
-
* editor.transact((tr) => {
|
|
656
|
-
* tr.insertText("Hello, world!");
|
|
657
|
-
* });
|
|
658
|
-
* });
|
|
659
|
-
* ```
|
|
660
|
-
*/
|
|
661
|
-
public transact<T>(
|
|
662
|
-
callback: (
|
|
663
|
-
/**
|
|
664
|
-
* The current active transaction, this will automatically be dispatched to the editor when the callback is complete
|
|
665
|
-
* If another `transact` call is made within the callback, it will be passed the same transaction as the parent call.
|
|
666
|
-
*/
|
|
667
|
-
tr: Transaction,
|
|
668
|
-
) => T,
|
|
669
|
-
): T {
|
|
670
|
-
return this._stateManager.transact(callback);
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
/**
|
|
674
|
-
* Remove extension(s) from the editor
|
|
675
|
-
*/
|
|
676
|
-
public unregisterExtension: ExtensionManager["unregisterExtension"] = (
|
|
677
|
-
...args: Parameters<ExtensionManager["unregisterExtension"]>
|
|
678
|
-
) => this._extensionManager.unregisterExtension(...args);
|
|
679
|
-
|
|
680
|
-
/**
|
|
681
|
-
* Register extension(s) to the editor
|
|
682
|
-
*/
|
|
683
|
-
public registerExtension: ExtensionManager["registerExtension"] = (
|
|
684
|
-
...args: Parameters<ExtensionManager["registerExtension"]>
|
|
685
|
-
) => this._extensionManager.registerExtension(...args) as any;
|
|
686
|
-
|
|
687
|
-
/**
|
|
688
|
-
* Atomically unregister old extensions and register new ones in a single
|
|
689
|
-
* plugin update, avoiding re-entrant dispatch issues.
|
|
690
|
-
*/
|
|
691
|
-
public replaceExtension: ExtensionManager["replaceExtension"] = (
|
|
692
|
-
...args: Parameters<ExtensionManager["replaceExtension"]>
|
|
693
|
-
) => this._extensionManager.replaceExtension(...args);
|
|
694
|
-
|
|
695
|
-
/**
|
|
696
|
-
* Get an extension from the editor
|
|
697
|
-
*/
|
|
698
|
-
// Declared as an explicit intersection of the two `ExtensionManager`
|
|
699
|
-
// overloads rather than `ExtensionManager["getExtension"]`: indexed access on
|
|
700
|
-
// an overloaded method collapses the signatures, which widened the factory
|
|
701
|
-
// overload's `ReturnType<ReturnType<T>>` result to `any` (losing e.g. a
|
|
702
|
-
// returned extension's `store` type).
|
|
703
|
-
public getExtension: (<
|
|
704
|
-
const Ext extends Extension | ExtensionFactory = Extension,
|
|
705
|
-
>(
|
|
706
|
-
extension: string,
|
|
707
|
-
) =>
|
|
708
|
-
| (Ext extends Extension
|
|
709
|
-
? Ext
|
|
710
|
-
: Ext extends ExtensionFactory
|
|
711
|
-
? ReturnType<ReturnType<Ext>>
|
|
712
|
-
: never)
|
|
713
|
-
| undefined) &
|
|
714
|
-
(<const T extends ExtensionFactory>(
|
|
715
|
-
extension: T,
|
|
716
|
-
) => ReturnType<ReturnType<T>> | undefined) = ((extension: any) =>
|
|
717
|
-
this._extensionManager.getExtension(extension)) as any;
|
|
718
|
-
|
|
719
|
-
/**
|
|
720
|
-
* Mount the editor to a DOM element.
|
|
721
|
-
*
|
|
722
|
-
* @param element The DOM element to mount the editor's contenteditable into.
|
|
723
|
-
*
|
|
724
|
-
* Floating UI rendered next to the contenteditable counts as within the
|
|
725
|
-
* editor already; UI rendered outside its DOM tree has to be registered with
|
|
726
|
-
* {@link registerPortalElement} so {@link isWithinEditor} recognizes it.
|
|
727
|
-
*
|
|
728
|
-
* @warning Not needed to call manually when using React, use BlockNoteView to take care of mounting
|
|
729
|
-
*/
|
|
730
|
-
public mount = (element: HTMLElement) => {
|
|
731
|
-
this._tiptapEditor.mount({ mount: element });
|
|
732
|
-
};
|
|
733
|
-
|
|
734
|
-
/**
|
|
735
|
-
* Unmount the editor from the DOM element it is bound to
|
|
736
|
-
*/
|
|
737
|
-
public unmount = () => {
|
|
738
|
-
this._tiptapEditor.unmount();
|
|
739
|
-
};
|
|
740
|
-
|
|
741
|
-
/**
|
|
742
|
-
* Get the underlying prosemirror state
|
|
743
|
-
* @note Prefer using `editor.transact` to read the current editor state, as that will ensure the state is up to date
|
|
744
|
-
* @see https://prosemirror.net/docs/ref/#state.EditorState
|
|
745
|
-
*/
|
|
746
|
-
public get prosemirrorState() {
|
|
747
|
-
return this._stateManager.prosemirrorState;
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
/**
|
|
751
|
-
* Get the underlying prosemirror view
|
|
752
|
-
* @see https://prosemirror.net/docs/ref/#view.EditorView
|
|
753
|
-
*/
|
|
754
|
-
public get prosemirrorView() {
|
|
755
|
-
return this._stateManager.prosemirrorView;
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
public get domElement() {
|
|
759
|
-
if (this.headless) {
|
|
760
|
-
return undefined;
|
|
761
|
-
}
|
|
762
|
-
return this.prosemirrorView?.dom as HTMLDivElement | undefined;
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
// Portal elements registered by the view layer, with reference counts so
|
|
766
|
-
// several UI elements can share one (e.g. multiple popovers portalling into
|
|
767
|
-
// the same custom element).
|
|
768
|
-
private _portalElements = new Map<HTMLElement, number>();
|
|
769
|
-
|
|
770
|
-
/**
|
|
771
|
-
* Registers an element as a portal element for this editor's floating UI, so
|
|
772
|
-
* {@link isWithinEditor} treats its contents as part of the editor. The view
|
|
773
|
-
* layer calls this for each portal element it designates (see
|
|
774
|
-
* `PortalElementOverride` in `@blocknote/react`) — without it, UI portalled outside
|
|
775
|
-
* the editor's DOM tree would be considered outside the editor.
|
|
776
|
-
* Registrations are reference-counted; release with
|
|
777
|
-
* {@link unregisterPortalElement}.
|
|
778
|
-
*/
|
|
779
|
-
public registerPortalElement = (element: HTMLElement) => {
|
|
780
|
-
this._portalElements.set(
|
|
781
|
-
element,
|
|
782
|
-
(this._portalElements.get(element) ?? 0) + 1,
|
|
783
|
-
);
|
|
784
|
-
};
|
|
785
|
-
|
|
786
|
-
/**
|
|
787
|
-
* Releases a registration made with {@link registerPortalElement}. The element
|
|
788
|
-
* stops counting as part of the editor once every registration for it has
|
|
789
|
-
* been released.
|
|
790
|
-
*/
|
|
791
|
-
public unregisterPortalElement = (element: HTMLElement) => {
|
|
792
|
-
const count = this._portalElements.get(element);
|
|
793
|
-
if (count === undefined) {
|
|
794
|
-
return;
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
if (count <= 1) {
|
|
798
|
-
this._portalElements.delete(element);
|
|
799
|
-
} else {
|
|
800
|
-
this._portalElements.set(element, count - 1);
|
|
801
|
-
}
|
|
802
|
-
};
|
|
803
|
-
|
|
804
|
-
/**
|
|
805
|
-
* Checks whether a DOM element belongs to this editor — inside the editor's
|
|
806
|
-
* DOM tree, or inside any portal element registered via
|
|
807
|
-
* {@link registerPortalElement} (used for floating UI elements like menus and
|
|
808
|
-
* toolbars, which may portal outside the editor's DOM tree).
|
|
809
|
-
*
|
|
810
|
-
* The DOM-tree check starts at the content area's *parent*, so that UI the
|
|
811
|
-
* host app renders as `BlockNoteView` children counts too — React places
|
|
812
|
-
* those beside the content (see the "Static Formatting Toolbar" example).
|
|
813
|
-
* The boundary is whatever the element passed to `editor.mount()` has as
|
|
814
|
-
* its parent: `BlockNoteView` always provides a wrapper; mounting bare into
|
|
815
|
-
* `<body>`, as the vanilla-JS docs do, makes the whole page count as within
|
|
816
|
-
* the editor.
|
|
817
|
-
*/
|
|
818
|
-
public isWithinEditor = (element: Element): boolean => {
|
|
819
|
-
if (this.domElement?.parentElement?.contains(element)) {
|
|
820
|
-
return true;
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
for (const portalElement of this._portalElements.keys()) {
|
|
824
|
-
if (portalElement.contains(element)) {
|
|
825
|
-
return true;
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
return false;
|
|
830
|
-
};
|
|
831
|
-
|
|
832
|
-
public isFocused(options?: EditorFocusOptions) {
|
|
833
|
-
if (this.headless) {
|
|
834
|
-
return false;
|
|
835
|
-
}
|
|
836
|
-
const contentFocused = this.prosemirrorView?.hasFocus() || false;
|
|
837
|
-
if (!options?.includeEditorUI) {
|
|
838
|
-
return contentFocused;
|
|
839
|
-
}
|
|
840
|
-
const active =
|
|
841
|
-
typeof document !== "undefined" ? document.activeElement : null;
|
|
842
|
-
return contentFocused || (!!active && this.isWithinEditor(active));
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
public headless = true;
|
|
846
|
-
|
|
847
|
-
/**
|
|
848
|
-
* Focus on the editor
|
|
849
|
-
*/
|
|
850
|
-
public focus() {
|
|
851
|
-
if (this.headless) {
|
|
852
|
-
return;
|
|
853
|
-
}
|
|
854
|
-
this.prosemirrorView.focus();
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
/**
|
|
858
|
-
* Blur the editor
|
|
859
|
-
*/
|
|
860
|
-
public blur() {
|
|
861
|
-
if (this.headless) {
|
|
862
|
-
return;
|
|
863
|
-
}
|
|
864
|
-
this.domElement?.blur();
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
// TODO move to extension
|
|
868
|
-
public onUploadStart(callback: (blockId?: string) => void) {
|
|
869
|
-
this.onUploadStartCallbacks.push(callback);
|
|
870
|
-
|
|
871
|
-
return () => {
|
|
872
|
-
const index = this.onUploadStartCallbacks.indexOf(callback);
|
|
873
|
-
if (index > -1) {
|
|
874
|
-
this.onUploadStartCallbacks.splice(index, 1);
|
|
875
|
-
}
|
|
876
|
-
};
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
public onUploadEnd(callback: (blockId?: string) => void) {
|
|
880
|
-
this.onUploadEndCallbacks.push(callback);
|
|
881
|
-
|
|
882
|
-
return () => {
|
|
883
|
-
const index = this.onUploadEndCallbacks.indexOf(callback);
|
|
884
|
-
if (index > -1) {
|
|
885
|
-
this.onUploadEndCallbacks.splice(index, 1);
|
|
886
|
-
}
|
|
887
|
-
};
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
/**
|
|
891
|
-
* @deprecated, use `editor.document` instead
|
|
892
|
-
*/
|
|
893
|
-
public get topLevelBlocks(): Block<BSchema, ISchema, SSchema>[] {
|
|
894
|
-
return this.document;
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
/**
|
|
898
|
-
* Gets a snapshot of all top-level (non-nested) blocks in the editor.
|
|
899
|
-
* @returns A snapshot of all top-level (non-nested) blocks in the editor.
|
|
900
|
-
*/
|
|
901
|
-
public get document(): Block<BSchema, ISchema, SSchema>[] {
|
|
902
|
-
return this._blockManager.document;
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
/**
|
|
906
|
-
* Gets a snapshot of an existing block from the editor.
|
|
907
|
-
* @param blockIdentifier The identifier of an existing block that should be
|
|
908
|
-
* retrieved.
|
|
909
|
-
* @returns The block that matches the identifier, or `undefined` if no
|
|
910
|
-
* matching block was found.
|
|
911
|
-
*/
|
|
912
|
-
public getBlock(
|
|
913
|
-
blockIdentifier: BlockIdentifier,
|
|
914
|
-
): Block<BSchema, ISchema, SSchema> | undefined {
|
|
915
|
-
return this._blockManager.getBlock(blockIdentifier);
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
/**
|
|
919
|
-
* Gets a snapshot of the previous sibling of an existing block from the
|
|
920
|
-
* editor.
|
|
921
|
-
* @param blockIdentifier The identifier of an existing block for which the
|
|
922
|
-
* previous sibling should be retrieved.
|
|
923
|
-
* @returns The previous sibling of the block that matches the identifier.
|
|
924
|
-
* `undefined` if no matching block was found, or it's the first child/block
|
|
925
|
-
* in the document.
|
|
926
|
-
*/
|
|
927
|
-
public getPrevBlock(
|
|
928
|
-
blockIdentifier: BlockIdentifier,
|
|
929
|
-
): Block<BSchema, ISchema, SSchema> | undefined {
|
|
930
|
-
return this._blockManager.getPrevBlock(blockIdentifier);
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
/**
|
|
934
|
-
* Gets a snapshot of the next sibling of an existing block from the editor.
|
|
935
|
-
* @param blockIdentifier The identifier of an existing block for which the
|
|
936
|
-
* next sibling should be retrieved.
|
|
937
|
-
* @returns The next sibling of the block that matches the identifier.
|
|
938
|
-
* `undefined` if no matching block was found, or it's the last child/block in
|
|
939
|
-
* the document.
|
|
940
|
-
*/
|
|
941
|
-
public getNextBlock(
|
|
942
|
-
blockIdentifier: BlockIdentifier,
|
|
943
|
-
): Block<BSchema, ISchema, SSchema> | undefined {
|
|
944
|
-
return this._blockManager.getNextBlock(blockIdentifier);
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
/**
|
|
948
|
-
* Gets a snapshot of the parent of an existing block from the editor.
|
|
949
|
-
* @param blockIdentifier The identifier of an existing block for which the
|
|
950
|
-
* parent should be retrieved.
|
|
951
|
-
* @returns The parent of the block that matches the identifier. `undefined`
|
|
952
|
-
* if no matching block was found, or the block isn't nested.
|
|
953
|
-
*/
|
|
954
|
-
public getParentBlock(
|
|
955
|
-
blockIdentifier: BlockIdentifier,
|
|
956
|
-
): Block<BSchema, ISchema, SSchema> | undefined {
|
|
957
|
-
return this._blockManager.getParentBlock(blockIdentifier);
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
/**
|
|
961
|
-
* Traverses all blocks in the editor depth-first, and executes a callback for each.
|
|
962
|
-
* @param callback The callback to execute for each block. Returning `false` stops the traversal.
|
|
963
|
-
* @param reverse Whether the blocks should be traversed in reverse order.
|
|
964
|
-
*/
|
|
965
|
-
public forEachBlock(
|
|
966
|
-
callback: (block: Block<BSchema, ISchema, SSchema>) => boolean,
|
|
967
|
-
reverse = false,
|
|
968
|
-
): void {
|
|
969
|
-
this._blockManager.forEachBlock(callback, reverse);
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
/**
|
|
973
|
-
* Executes a callback whenever the editor's contents change.
|
|
974
|
-
* @param callback The callback to execute.
|
|
975
|
-
*
|
|
976
|
-
* @deprecated use {@link BlockNoteEditor.onChange} instead
|
|
977
|
-
*/
|
|
978
|
-
public onEditorContentChange(callback: () => void) {
|
|
979
|
-
this._tiptapEditor.on("update", callback);
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
/**
|
|
983
|
-
* Executes a callback whenever the editor's selection changes.
|
|
984
|
-
* @param callback The callback to execute.
|
|
985
|
-
*
|
|
986
|
-
* @deprecated use `onSelectionChange` instead
|
|
987
|
-
*/
|
|
988
|
-
public onEditorSelectionChange(callback: () => void) {
|
|
989
|
-
this._tiptapEditor.on("selectionUpdate", callback);
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
/**
|
|
993
|
-
* Executes a callback before any change is applied to the editor, allowing you to cancel the change.
|
|
994
|
-
* @param callback The callback to execute.
|
|
995
|
-
* @returns A function to remove the callback.
|
|
996
|
-
*/
|
|
997
|
-
public onBeforeChange(
|
|
998
|
-
callback: (context: {
|
|
999
|
-
getChanges: () => BlocksChanged<BSchema, ISchema, SSchema>;
|
|
1000
|
-
tr: Transaction;
|
|
1001
|
-
}) => boolean | void,
|
|
1002
|
-
): () => void {
|
|
1003
|
-
return this._extensionManager
|
|
1004
|
-
.getExtension(BlockChangeExtension)!
|
|
1005
|
-
.subscribe(callback);
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
/**
|
|
1009
|
-
* Gets a snapshot of the current text cursor position.
|
|
1010
|
-
* @returns A snapshot of the current text cursor position.
|
|
1011
|
-
*/
|
|
1012
|
-
public getTextCursorPosition(): TextCursorPosition<
|
|
1013
|
-
BSchema,
|
|
1014
|
-
ISchema,
|
|
1015
|
-
SSchema
|
|
1016
|
-
> {
|
|
1017
|
-
return this._selectionManager.getTextCursorPosition();
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
/**
|
|
1021
|
-
* Sets the text cursor position to the start or end of an existing block. Throws an error if the target block could
|
|
1022
|
-
* not be found.
|
|
1023
|
-
* @param targetBlock The identifier of an existing block that the text cursor should be moved to.
|
|
1024
|
-
* @param placement Whether the text cursor should be placed at the start or end of the block.
|
|
1025
|
-
*/
|
|
1026
|
-
public setTextCursorPosition(
|
|
1027
|
-
targetBlock: BlockIdentifier,
|
|
1028
|
-
placement: "start" | "end" = "start",
|
|
1029
|
-
) {
|
|
1030
|
-
return this._selectionManager.setTextCursorPosition(targetBlock, placement);
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
/**
|
|
1034
|
-
* Gets a snapshot of the current selection. This contains all blocks (included nested blocks)
|
|
1035
|
-
* that the selection spans across.
|
|
1036
|
-
*
|
|
1037
|
-
* If the selection starts / ends halfway through a block, the returned data will contain the entire block.
|
|
1038
|
-
*/
|
|
1039
|
-
public getSelection(): Selection<BSchema, ISchema, SSchema> | undefined {
|
|
1040
|
-
return this._selectionManager.getSelection();
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
/**
|
|
1044
|
-
* Gets a snapshot of the current selection. This contains all blocks (included nested blocks)
|
|
1045
|
-
* that the selection spans across.
|
|
1046
|
-
*
|
|
1047
|
-
* If the selection starts / ends halfway through a block, the returned block will be
|
|
1048
|
-
* only the part of the block that is included in the selection.
|
|
1049
|
-
*/
|
|
1050
|
-
public getSelectionCutBlocks(expandToWords = false) {
|
|
1051
|
-
return this._selectionManager.getSelectionCutBlocks(expandToWords);
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
/**
|
|
1055
|
-
* Sets the selection to a range of blocks.
|
|
1056
|
-
* @param startBlock The identifier of the block that should be the start of the selection.
|
|
1057
|
-
* @param endBlock The identifier of the block that should be the end of the selection.
|
|
1058
|
-
*/
|
|
1059
|
-
public setSelection(startBlock: BlockIdentifier, endBlock: BlockIdentifier) {
|
|
1060
|
-
return this._selectionManager.setSelection(startBlock, endBlock);
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
/**
|
|
1064
|
-
* Checks if the editor is currently editable, or if it's locked.
|
|
1065
|
-
* @returns True if the editor is editable, false otherwise.
|
|
1066
|
-
*/
|
|
1067
|
-
public get isEditable(): boolean {
|
|
1068
|
-
return this._stateManager.isEditable;
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
/**
|
|
1072
|
-
* Makes the editor editable or locks it, depending on the argument passed.
|
|
1073
|
-
* @param editable True to make the editor editable, or false to lock it.
|
|
1074
|
-
*/
|
|
1075
|
-
public set isEditable(editable: boolean) {
|
|
1076
|
-
this._stateManager.isEditable = editable;
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
/**
|
|
1080
|
-
* Inserts new blocks into the editor. If a block's `id` is undefined, BlockNote generates one automatically. Throws an
|
|
1081
|
-
* error if the reference block could not be found.
|
|
1082
|
-
* @param blocksToInsert An array of partial blocks that should be inserted.
|
|
1083
|
-
* @param referenceBlock An identifier for an existing block, at which the new blocks should be inserted.
|
|
1084
|
-
* @param placement Whether the blocks should be inserted just before, just after, or nested inside the
|
|
1085
|
-
* `referenceBlock`.
|
|
1086
|
-
*/
|
|
1087
|
-
public insertBlocks(
|
|
1088
|
-
blocksToInsert: PartialBlock<BSchema, ISchema, SSchema>[],
|
|
1089
|
-
referenceBlock: BlockIdentifier,
|
|
1090
|
-
placement: "before" | "after" = "before",
|
|
1091
|
-
) {
|
|
1092
|
-
return this._blockManager.insertBlocks(
|
|
1093
|
-
blocksToInsert,
|
|
1094
|
-
referenceBlock,
|
|
1095
|
-
placement,
|
|
1096
|
-
);
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
/**
|
|
1100
|
-
* Updates an existing block in the editor. Since updatedBlock is a PartialBlock object, some fields might not be
|
|
1101
|
-
* defined. These undefined fields are kept as-is from the existing block. Throws an error if the block to update could
|
|
1102
|
-
* not be found.
|
|
1103
|
-
* @param blockToUpdate The block that should be updated.
|
|
1104
|
-
* @param update A partial block which defines how the existing block should be changed.
|
|
1105
|
-
*/
|
|
1106
|
-
public updateBlock(
|
|
1107
|
-
blockToUpdate: BlockIdentifier,
|
|
1108
|
-
update: PartialBlock<BSchema, ISchema, SSchema>,
|
|
1109
|
-
) {
|
|
1110
|
-
return this._blockManager.updateBlock(blockToUpdate, update);
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1113
|
-
/**
|
|
1114
|
-
* Removes existing blocks from the editor. Throws an error if any of the blocks could not be found.
|
|
1115
|
-
* @param blocksToRemove An array of identifiers for existing blocks that should be removed.
|
|
1116
|
-
*/
|
|
1117
|
-
public removeBlocks(blocksToRemove: BlockIdentifier[]) {
|
|
1118
|
-
return this._blockManager.removeBlocks(blocksToRemove);
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
/**
|
|
1122
|
-
* Replaces existing blocks in the editor with new blocks. If the blocks that should be removed are not adjacent or
|
|
1123
|
-
* are at different nesting levels, `blocksToInsert` will be inserted at the position of the first block in
|
|
1124
|
-
* `blocksToRemove`. Throws an error if any of the blocks to remove could not be found.
|
|
1125
|
-
* @param blocksToRemove An array of blocks that should be replaced.
|
|
1126
|
-
* @param blocksToInsert An array of partial blocks to replace the old ones with.
|
|
1127
|
-
*/
|
|
1128
|
-
public replaceBlocks(
|
|
1129
|
-
blocksToRemove: BlockIdentifier[],
|
|
1130
|
-
blocksToInsert: PartialBlock<BSchema, ISchema, SSchema>[],
|
|
1131
|
-
) {
|
|
1132
|
-
return this._blockManager.replaceBlocks(blocksToRemove, blocksToInsert);
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
/**
|
|
1136
|
-
* Undo the last action.
|
|
1137
|
-
*/
|
|
1138
|
-
public undo(): boolean {
|
|
1139
|
-
return this._stateManager.undo();
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
/**
|
|
1143
|
-
* Redo the last action.
|
|
1144
|
-
*/
|
|
1145
|
-
public redo(): boolean {
|
|
1146
|
-
return this._stateManager.redo();
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
/**
|
|
1150
|
-
* Insert a piece of content at the current cursor position.
|
|
1151
|
-
*
|
|
1152
|
-
* @param content can be a string, or array of partial inline content elements
|
|
1153
|
-
*/
|
|
1154
|
-
public insertInlineContent(
|
|
1155
|
-
content: PartialInlineContent<ISchema, SSchema>,
|
|
1156
|
-
{ updateSelection = false }: { updateSelection?: boolean } = {},
|
|
1157
|
-
) {
|
|
1158
|
-
this._styleManager.insertInlineContent(content, { updateSelection });
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
/**
|
|
1162
|
-
* Gets the active text styles at the text cursor position or at the end of the current selection if it's active.
|
|
1163
|
-
*/
|
|
1164
|
-
public getActiveStyles(): Styles<SSchema> {
|
|
1165
|
-
return this._styleManager.getActiveStyles();
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
/**
|
|
1169
|
-
* Adds styles to the currently selected content.
|
|
1170
|
-
* @param styles The styles to add.
|
|
1171
|
-
*/
|
|
1172
|
-
public addStyles(styles: Styles<SSchema>) {
|
|
1173
|
-
this._styleManager.addStyles(styles);
|
|
1174
|
-
}
|
|
1175
|
-
|
|
1176
|
-
/**
|
|
1177
|
-
* Removes styles from the currently selected content.
|
|
1178
|
-
* @param styles The styles to remove.
|
|
1179
|
-
*/
|
|
1180
|
-
public removeStyles(styles: Styles<SSchema>) {
|
|
1181
|
-
this._styleManager.removeStyles(styles);
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
/**
|
|
1185
|
-
* Toggles styles on the currently selected content.
|
|
1186
|
-
* @param styles The styles to toggle.
|
|
1187
|
-
*/
|
|
1188
|
-
public toggleStyles(styles: Styles<SSchema>) {
|
|
1189
|
-
this._styleManager.toggleStyles(styles);
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
/**
|
|
1193
|
-
* Gets the currently selected text.
|
|
1194
|
-
*/
|
|
1195
|
-
public getSelectedText() {
|
|
1196
|
-
return this._styleManager.getSelectedText();
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
/**
|
|
1200
|
-
* Gets the URL of the link the current selection starts in, or `undefined`
|
|
1201
|
-
* if it does not start in one.
|
|
1202
|
-
*/
|
|
1203
|
-
public getSelectedLinkUrl() {
|
|
1204
|
-
return this._styleManager.getSelectedLinkUrl();
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
/**
|
|
1208
|
-
* Creates a new link to replace the selected content.
|
|
1209
|
-
* @param url The link URL.
|
|
1210
|
-
* @param text The text to display the link with.
|
|
1211
|
-
*/
|
|
1212
|
-
public createLink(url: string, text?: string) {
|
|
1213
|
-
this._styleManager.createLink(url, text);
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
/**
|
|
1217
|
-
* Find the link mark and its range at the given position.
|
|
1218
|
-
* Returns undefined if there is no link at that position.
|
|
1219
|
-
*/
|
|
1220
|
-
public getLinkMarkAtPos(pos: number) {
|
|
1221
|
-
return this._styleManager.getLinkMarkAtPos(pos);
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
/**
|
|
1225
|
-
* Updates the link at the given position with a new URL and text.
|
|
1226
|
-
* @param url The new link URL.
|
|
1227
|
-
* @param text The new text to display.
|
|
1228
|
-
* @param position The position inside the link to edit. Defaults to the current selection anchor.
|
|
1229
|
-
*/
|
|
1230
|
-
public editLink(url: string, text: string, position?: number) {
|
|
1231
|
-
this._styleManager.editLink(url, text, position);
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
/**
|
|
1235
|
-
* Removes the link at the given position, keeping the text.
|
|
1236
|
-
* @param position The position inside the link to remove. Defaults to the current selection anchor.
|
|
1237
|
-
*/
|
|
1238
|
-
public deleteLink(position?: number) {
|
|
1239
|
-
this._styleManager.deleteLink(position);
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
/**
|
|
1243
|
-
* Checks if the block containing the text cursor can be nested.
|
|
1244
|
-
*/
|
|
1245
|
-
public canNestBlock() {
|
|
1246
|
-
return this._blockManager.canNestBlock();
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
/**
|
|
1250
|
-
* Nests the block containing the text cursor into the block above it.
|
|
1251
|
-
*/
|
|
1252
|
-
public nestBlock() {
|
|
1253
|
-
this._blockManager.nestBlock();
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
/**
|
|
1257
|
-
* Checks if the block containing the text cursor is nested.
|
|
1258
|
-
*/
|
|
1259
|
-
public canUnnestBlock() {
|
|
1260
|
-
return this._blockManager.canUnnestBlock();
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
/**
|
|
1264
|
-
* Lifts the block containing the text cursor out of its parent.
|
|
1265
|
-
*/
|
|
1266
|
-
public unnestBlock() {
|
|
1267
|
-
this._blockManager.unnestBlock();
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
/**
|
|
1271
|
-
* Moves the selected blocks up. If the previous block has children, moves
|
|
1272
|
-
* them to the end of its children. If there is no previous block, but the
|
|
1273
|
-
* current blocks share a common parent, moves them out of & before it. If a
|
|
1274
|
-
* `blockIdentifier` is provided, that block is moved instead of the
|
|
1275
|
-
* selection, and the selection is left unchanged.
|
|
1276
|
-
*/
|
|
1277
|
-
public moveBlocksUp(blockIdentifier?: BlockIdentifier) {
|
|
1278
|
-
return this._blockManager.moveBlocksUp(blockIdentifier);
|
|
1279
|
-
}
|
|
1280
|
-
|
|
1281
|
-
/**
|
|
1282
|
-
* Moves the selected blocks down. If the next block has children, moves
|
|
1283
|
-
* them to the start of its children. If there is no next block, but the
|
|
1284
|
-
* current blocks share a common parent, moves them out of & after it. If a
|
|
1285
|
-
* `blockIdentifier` is provided, that block is moved instead of the
|
|
1286
|
-
* selection, and the selection is left unchanged.
|
|
1287
|
-
*/
|
|
1288
|
-
public moveBlocksDown(blockIdentifier?: BlockIdentifier) {
|
|
1289
|
-
return this._blockManager.moveBlocksDown(blockIdentifier);
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
/**
|
|
1293
|
-
* Exports blocks into a simplified HTML string. To better conform to HTML standards, children of blocks which aren't list
|
|
1294
|
-
* items are un-nested in the output HTML.
|
|
1295
|
-
*
|
|
1296
|
-
* @param blocks An array of blocks that should be serialized into HTML.
|
|
1297
|
-
* @returns The blocks, serialized as an HTML string.
|
|
1298
|
-
*/
|
|
1299
|
-
public blocksToHTMLLossy(
|
|
1300
|
-
blocks: PartialBlock<BSchema, ISchema, SSchema>[] = this.document,
|
|
1301
|
-
): string {
|
|
1302
|
-
return this._exportManager.blocksToHTMLLossy(blocks);
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
|
-
/**
|
|
1306
|
-
* Serializes blocks into an HTML string in the format that would normally be rendered by the editor.
|
|
1307
|
-
*
|
|
1308
|
-
* Use this method if you want to server-side render HTML (for example, a blog post that has been edited in BlockNote)
|
|
1309
|
-
* and serve it to users without loading the editor on the client (i.e.: displaying the blog post)
|
|
1310
|
-
*
|
|
1311
|
-
* @param blocks An array of blocks that should be serialized into HTML.
|
|
1312
|
-
* @returns The blocks, serialized as an HTML string.
|
|
1313
|
-
*/
|
|
1314
|
-
public blocksToFullHTML(
|
|
1315
|
-
blocks: PartialBlock<BSchema, ISchema, SSchema>[] = this.document,
|
|
1316
|
-
): string {
|
|
1317
|
-
return this._exportManager.blocksToFullHTML(blocks);
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
/**
|
|
1321
|
-
* Parses blocks from an HTML string. Tries to create `Block` objects out of any HTML block-level elements, and
|
|
1322
|
-
* `InlineNode` objects from any HTML inline elements, though not all element types are recognized. If BlockNote
|
|
1323
|
-
* doesn't recognize an HTML element's tag, it will parse it as a paragraph or plain text.
|
|
1324
|
-
* @param html The HTML string to parse blocks from.
|
|
1325
|
-
* @returns The blocks parsed from the HTML string.
|
|
1326
|
-
*/
|
|
1327
|
-
public tryParseHTMLToBlocks(
|
|
1328
|
-
html: string,
|
|
1329
|
-
): Block<BSchema, ISchema, SSchema>[] {
|
|
1330
|
-
return this._exportManager.tryParseHTMLToBlocks(html);
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
/**
|
|
1334
|
-
* Serializes blocks into a Markdown string. The output is simplified as Markdown does not support all features of
|
|
1335
|
-
* BlockNote - children of blocks which aren't list items are un-nested and certain styles are removed.
|
|
1336
|
-
* @param blocks An array of blocks that should be serialized into Markdown.
|
|
1337
|
-
* @returns The blocks, serialized as a Markdown string.
|
|
1338
|
-
*/
|
|
1339
|
-
public blocksToMarkdownLossy(
|
|
1340
|
-
blocks: PartialBlock<BSchema, ISchema, SSchema>[] = this.document,
|
|
1341
|
-
): string {
|
|
1342
|
-
return this._exportManager.blocksToMarkdownLossy(blocks);
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1345
|
-
/**
|
|
1346
|
-
* Creates a list of blocks from a Markdown string. Tries to create `Block` and `InlineNode` objects based on
|
|
1347
|
-
* Markdown syntax, though not all symbols are recognized. If BlockNote doesn't recognize a symbol, it will parse it
|
|
1348
|
-
* as text.
|
|
1349
|
-
* @param markdown The Markdown string to parse blocks from.
|
|
1350
|
-
* @returns The blocks parsed from the Markdown string.
|
|
1351
|
-
*/
|
|
1352
|
-
public tryParseMarkdownToBlocks(
|
|
1353
|
-
markdown: string,
|
|
1354
|
-
): Block<BSchema, ISchema, SSchema>[] {
|
|
1355
|
-
return this._exportManager.tryParseMarkdownToBlocks(markdown);
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
/**
|
|
1359
|
-
* A callback function that runs whenever the editor's contents change.
|
|
1360
|
-
*
|
|
1361
|
-
* @param callback The callback to execute.
|
|
1362
|
-
* @returns A function to remove the callback.
|
|
1363
|
-
*/
|
|
1364
|
-
public onChange(
|
|
1365
|
-
callback: (
|
|
1366
|
-
editor: BlockNoteEditor<BSchema, ISchema, SSchema>,
|
|
1367
|
-
context: {
|
|
1368
|
-
/**
|
|
1369
|
-
* Returns the blocks that were inserted, updated, or deleted by the change that occurred.
|
|
1370
|
-
*/
|
|
1371
|
-
getChanges(): BlocksChanged<BSchema, ISchema, SSchema>;
|
|
1372
|
-
},
|
|
1373
|
-
) => void,
|
|
1374
|
-
/**
|
|
1375
|
-
* If true, the callback will be triggered when the changes are caused by a remote user
|
|
1376
|
-
* @default true
|
|
1377
|
-
*/
|
|
1378
|
-
includeUpdatesFromRemote?: boolean,
|
|
1379
|
-
) {
|
|
1380
|
-
return this._eventManager.onChange(callback, includeUpdatesFromRemote);
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
/**
|
|
1384
|
-
* A callback function that runs whenever the text cursor position or selection changes.
|
|
1385
|
-
*
|
|
1386
|
-
* @param callback The callback to execute.
|
|
1387
|
-
* @returns A function to remove the callback.
|
|
1388
|
-
*/
|
|
1389
|
-
public onSelectionChange(
|
|
1390
|
-
callback: (editor: BlockNoteEditor<BSchema, ISchema, SSchema>) => void,
|
|
1391
|
-
includeSelectionChangedByRemote?: boolean,
|
|
1392
|
-
) {
|
|
1393
|
-
return this._eventManager.onSelectionChange(
|
|
1394
|
-
callback,
|
|
1395
|
-
includeSelectionChangedByRemote,
|
|
1396
|
-
);
|
|
1397
|
-
}
|
|
1398
|
-
|
|
1399
|
-
/**
|
|
1400
|
-
* A callback function that runs when focus changes. By default, this reports
|
|
1401
|
-
* when the editor's content area gains or loses DOM focus.
|
|
1402
|
-
*
|
|
1403
|
-
* Note that `focused: false` only means the content area itself blurred —
|
|
1404
|
-
* focus may have moved into the editor's own UI (e.g. a toolbar
|
|
1405
|
-
* popover's input). Pass `includeEditorUI: true` to report changes to
|
|
1406
|
-
* combined content and UI focus, allowing focus handoffs to settle.
|
|
1407
|
-
*
|
|
1408
|
-
* @param callback The callback to execute.
|
|
1409
|
-
* @returns A function to remove the callback.
|
|
1410
|
-
*/
|
|
1411
|
-
public onFocusChange(
|
|
1412
|
-
callback: (
|
|
1413
|
-
editor: BlockNoteEditor<BSchema, ISchema, SSchema>,
|
|
1414
|
-
context: { focused: boolean; event: FocusEvent },
|
|
1415
|
-
) => void,
|
|
1416
|
-
options?: EditorFocusOptions,
|
|
1417
|
-
) {
|
|
1418
|
-
return this._eventManager.onFocusChange(callback, options);
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
/**
|
|
1422
|
-
* A callback function that runs when the editor has been mounted.
|
|
1423
|
-
*
|
|
1424
|
-
* This can be useful for plugins to initialize themselves after the editor has been mounted.
|
|
1425
|
-
*
|
|
1426
|
-
* @param callback The callback to execute.
|
|
1427
|
-
* @returns A function to remove the callback.
|
|
1428
|
-
*/
|
|
1429
|
-
public onMount(
|
|
1430
|
-
callback: (ctx: {
|
|
1431
|
-
editor: BlockNoteEditor<BSchema, ISchema, SSchema>;
|
|
1432
|
-
}) => void,
|
|
1433
|
-
) {
|
|
1434
|
-
return this._eventManager.onMount(callback);
|
|
1435
|
-
}
|
|
1436
|
-
|
|
1437
|
-
/**
|
|
1438
|
-
* A callback function that runs when the editor has been unmounted.
|
|
1439
|
-
*
|
|
1440
|
-
* This can be useful for plugins to clean up themselves after the editor has been unmounted.
|
|
1441
|
-
*
|
|
1442
|
-
* @param callback The callback to execute.
|
|
1443
|
-
* @returns A function to remove the callback.
|
|
1444
|
-
*/
|
|
1445
|
-
public onUnmount(
|
|
1446
|
-
callback: (ctx: {
|
|
1447
|
-
editor: BlockNoteEditor<BSchema, ISchema, SSchema>;
|
|
1448
|
-
}) => void,
|
|
1449
|
-
) {
|
|
1450
|
-
return this._eventManager.onUnmount(callback);
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
/**
|
|
1454
|
-
* Gets the bounding box of the current selection.
|
|
1455
|
-
* @returns The bounding box of the current selection.
|
|
1456
|
-
*/
|
|
1457
|
-
public getSelectionBoundingBox() {
|
|
1458
|
-
return this._selectionManager.getSelectionBoundingBox();
|
|
1459
|
-
}
|
|
1460
|
-
|
|
1461
|
-
public get isEmpty() {
|
|
1462
|
-
const doc = this.document;
|
|
1463
|
-
// Note: only works for paragraphs as default blocks (but for now this is default in blocknote)
|
|
1464
|
-
// checking prosemirror directly might be faster
|
|
1465
|
-
return (
|
|
1466
|
-
doc.length === 0 ||
|
|
1467
|
-
(doc.length === 1 &&
|
|
1468
|
-
doc[0].type === "paragraph" &&
|
|
1469
|
-
(doc[0].content as any).length === 0)
|
|
1470
|
-
);
|
|
1471
|
-
}
|
|
1472
|
-
|
|
1473
|
-
/**
|
|
1474
|
-
* Paste HTML into the editor. Defaults to converting HTML to BlockNote HTML.
|
|
1475
|
-
* @param html The HTML to paste.
|
|
1476
|
-
* @param raw Whether to paste the HTML as is, or to convert it to BlockNote HTML.
|
|
1477
|
-
*/
|
|
1478
|
-
public pasteHTML(html: string, raw = false) {
|
|
1479
|
-
this._exportManager.pasteHTML(html, raw);
|
|
1480
|
-
}
|
|
1481
|
-
|
|
1482
|
-
/**
|
|
1483
|
-
* Paste text into the editor. Defaults to interpreting text as markdown.
|
|
1484
|
-
* @param text The text to paste.
|
|
1485
|
-
*/
|
|
1486
|
-
public pasteText(text: string) {
|
|
1487
|
-
return this._exportManager.pasteText(text);
|
|
1488
|
-
}
|
|
1489
|
-
|
|
1490
|
-
/**
|
|
1491
|
-
* Paste markdown into the editor.
|
|
1492
|
-
* @param markdown The markdown to paste.
|
|
1493
|
-
*/
|
|
1494
|
-
public pasteMarkdown(markdown: string) {
|
|
1495
|
-
return this._exportManager.pasteMarkdown(markdown);
|
|
1496
|
-
}
|
|
1497
|
-
}
|