@blocknote/core 0.30.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocknote.cjs +9 -9
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +2771 -2245
- package/dist/blocknote.js.map +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js.map +1 -1
- package/dist/{en-D4taoCs4.cjs → en-BXVKCwYt.cjs} +2 -2
- package/dist/en-BXVKCwYt.cjs.map +1 -0
- package/dist/{en-B7ycW7c8.js → en-qGo6sk9V.js} +2 -3
- package/dist/en-qGo6sk9V.js.map +1 -0
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +20 -39
- package/dist/locales.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +8 -7
- package/src/api/README.md +1 -1
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +19 -14
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +7 -8
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +3 -3
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +12 -12
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +14 -14
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +16 -16
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +8 -8
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +12 -12
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +8 -8
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +10 -10
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +2 -2
- package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +2816 -0
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +200 -42
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +104 -34
- package/src/api/blockManipulation/getBlock/getBlock.ts +9 -9
- package/src/api/blockManipulation/insertContentAt.ts +1 -1
- package/src/api/blockManipulation/selections/selection.ts +59 -12
- package/src/api/blockManipulation/selections/{textCursorPosition/textCursorPosition.ts → textCursorPosition.ts} +13 -13
- package/src/api/blockManipulation/tables/tables.test.ts +106 -106
- package/src/api/blockManipulation/tables/tables.ts +35 -35
- package/src/api/clipboard/fromClipboard/fileDropExtension.ts +2 -2
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +9 -9
- package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +3 -3
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +3 -3
- package/src/api/clipboard/toClipboard/copyExtension.ts +22 -22
- package/src/api/exporters/html/externalHTMLExporter.ts +6 -6
- package/src/api/exporters/html/internalHTMLSerializer.ts +3 -3
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +16 -16
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +14 -14
- package/src/api/exporters/markdown/markdownExporter.ts +3 -3
- package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +3 -3
- package/src/api/getBlockInfoFromPos.ts +6 -6
- package/src/api/nodeConversions/blockToNode.ts +31 -28
- package/src/api/nodeConversions/fragmentToBlocks.ts +1 -1
- package/src/api/nodeConversions/nodeToBlock.ts +240 -41
- package/src/api/nodeUtil.test.ts +16 -16
- package/src/api/nodeUtil.ts +10 -10
- package/src/api/parsers/html/parseHTML.ts +1 -1
- package/src/api/parsers/html/util/nestedLists.ts +2 -2
- package/src/api/parsers/markdown/parseMarkdown.ts +1 -1
- package/src/api/pmUtil.ts +7 -7
- package/src/api/positionMapping.test.ts +3 -3
- package/src/api/positionMapping.ts +5 -5
- package/src/blocks/AudioBlockContent/AudioBlockContent.ts +4 -4
- package/src/blocks/CodeBlockContent/CodeBlockContent.ts +18 -18
- package/src/blocks/FileBlockContent/FileBlockContent.ts +2 -2
- package/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.ts +2 -2
- package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +6 -6
- package/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.ts +2 -2
- package/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.ts +1 -1
- package/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.ts +7 -7
- package/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.ts +1 -1
- package/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.ts +1 -1
- package/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts +2 -2
- package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +6 -6
- package/src/blocks/ImageBlockContent/ImageBlockContent.ts +4 -4
- package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +4 -4
- package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +10 -10
- package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +1 -1
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +4 -4
- package/src/blocks/ListItemBlockContent/getListItemContent.ts +5 -5
- package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +1 -1
- package/src/blocks/PageBreakBlockContent/getPageBreakSlashMenuItems.ts +3 -3
- package/src/blocks/PageBreakBlockContent/schema.ts +2 -2
- package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +3 -3
- package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +4 -4
- package/src/blocks/README.md +1 -1
- package/src/blocks/TableBlockContent/TableBlockContent.ts +37 -7
- package/src/blocks/TableBlockContent/TableExtension.ts +3 -3
- package/src/blocks/VideoBlockContent/VideoBlockContent.ts +4 -4
- package/src/blocks/defaultBlockHelpers.ts +8 -8
- package/src/blocks/defaultBlockTypeGuards.ts +16 -16
- package/src/blocks/defaultBlocks.ts +3 -3
- package/src/comments/threadstore/DefaultThreadStoreAuth.ts +3 -3
- package/src/comments/threadstore/ThreadStore.ts +1 -1
- package/src/comments/threadstore/TipTapThreadStore.ts +10 -10
- package/src/comments/threadstore/yjs/RESTYjsThreadStore.ts +4 -4
- package/src/comments/threadstore/yjs/YjsThreadStore.test.ts +2 -2
- package/src/comments/threadstore/yjs/YjsThreadStore.ts +14 -14
- package/src/comments/threadstore/yjs/YjsThreadStoreBase.ts +1 -1
- package/src/comments/threadstore/yjs/yjsHelpers.ts +6 -6
- package/src/editor/Block.css +35 -1
- package/src/editor/BlockNoteEditor.test.ts +10 -3
- package/src/editor/BlockNoteEditor.ts +95 -38
- package/src/editor/BlockNoteExtension.ts +26 -0
- package/src/editor/BlockNoteExtensions.ts +38 -22
- package/src/editor/BlockNoteSchema.ts +4 -4
- package/src/editor/BlockNoteTipTapEditor.ts +33 -12
- package/src/editor/README.md +1 -1
- package/src/editor/cursorPositionTypes.ts +1 -1
- package/src/editor/editor.css +15 -3
- package/src/editor/selectionTypes.ts +1 -1
- package/src/editor/transformPasted.ts +2 -2
- package/src/exporter/Exporter.ts +5 -5
- package/src/exporter/mapping.ts +7 -7
- package/src/extensions/BackgroundColor/BackgroundColorMark.ts +1 -1
- package/src/extensions/Collaboration/CursorPlugin.ts +15 -9
- package/src/extensions/Collaboration/ForkYDocPlugin.test.ts +166 -0
- package/src/extensions/Collaboration/ForkYDocPlugin.ts +174 -0
- package/src/extensions/Collaboration/SyncPlugin.ts +7 -4
- package/src/extensions/Collaboration/UndoPlugin.ts +7 -4
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +30 -0
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +30 -0
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -0
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -0
- package/src/extensions/Comments/CommentsPlugin.ts +80 -75
- package/src/extensions/Comments/userstore/UserStore.ts +2 -2
- package/src/extensions/FilePanel/FilePanelPlugin.ts +56 -55
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +60 -30
- package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +26 -26
- package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +33 -32
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +45 -42
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +113 -110
- package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +179 -170
- package/src/extensions/README.md +1 -1
- package/src/extensions/ShowSelection/ShowSelectionPlugin.ts +22 -19
- package/src/extensions/SideMenu/MultipleNodeSelection.ts +1 -1
- package/src/extensions/SideMenu/SideMenuPlugin.ts +49 -48
- package/src/extensions/SideMenu/dragging.ts +8 -8
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +176 -176
- package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +2 -2
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +16 -16
- package/src/extensions/Suggestions/SuggestionMarks.ts +175 -0
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +199 -195
- package/src/extensions/TrailingNode/TrailingNodeExtension.ts +1 -1
- package/src/extensions/UniqueID/UniqueID.ts +6 -6
- package/src/extensions/getDraggableBlockFromElement.ts +1 -1
- package/src/fonts/inter.css +18 -9
- package/src/i18n/locales/ar.ts +0 -1
- package/src/i18n/locales/de.ts +0 -1
- package/src/i18n/locales/en.ts +0 -1
- package/src/i18n/locales/es.ts +0 -1
- package/src/i18n/locales/fr.ts +0 -1
- package/src/i18n/locales/hr.ts +0 -1
- package/src/i18n/locales/is.ts +0 -1
- package/src/i18n/locales/it.ts +0 -1
- package/src/i18n/locales/ja.ts +0 -1
- package/src/i18n/locales/ko.ts +0 -1
- package/src/i18n/locales/nl.ts +0 -1
- package/src/i18n/locales/no.ts +0 -1
- package/src/i18n/locales/pl.ts +0 -1
- package/src/i18n/locales/pt.ts +0 -1
- package/src/i18n/locales/ru.ts +0 -1
- package/src/i18n/locales/sk.ts +0 -1
- package/src/i18n/locales/uk.ts +0 -1
- package/src/i18n/locales/vi.ts +0 -1
- package/src/i18n/locales/zh-tw.ts +0 -1
- package/src/i18n/locales/zh.ts +0 -1
- package/src/index.ts +18 -8
- package/src/locales.ts +1 -1
- package/src/pm-nodes/BlockContainer.ts +1 -1
- package/src/pm-nodes/BlockGroup.ts +2 -2
- package/src/pm-nodes/Doc.ts +5 -4
- package/src/schema/README.md +1 -1
- package/src/schema/blocks/createSpec.ts +14 -14
- package/src/schema/blocks/internal.ts +17 -17
- package/src/schema/blocks/types.ts +25 -25
- package/src/schema/inlineContent/createSpec.ts +16 -20
- package/src/schema/inlineContent/internal.ts +9 -9
- package/src/schema/inlineContent/types.ts +26 -26
- package/src/schema/propTypes.ts +8 -8
- package/src/schema/styles/createSpec.ts +2 -2
- package/src/schema/styles/internal.ts +7 -7
- package/src/schema/styles/types.ts +2 -2
- package/src/util/EventEmitter.ts +4 -4
- package/src/util/README.md +1 -1
- package/src/util/combineByGroup.ts +1 -1
- package/src/util/table.ts +33 -30
- package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +1 -1
- package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.d.ts +4 -0
- package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.d.ts +3 -1
- package/types/src/api/blockManipulation/selections/selection.d.ts +10 -0
- package/types/src/api/blockManipulation/selections/textCursorPosition.d.ts +5 -0
- package/types/src/api/blockManipulation/transactions.test.d.ts +0 -0
- package/types/src/api/clipboard/clipboardExternal.test.d.ts +1 -0
- package/types/src/api/clipboard/clipboardInternal.test.d.ts +1 -0
- package/types/src/api/clipboard/testUtil.d.ts +541 -0
- package/types/src/api/exporters/html/htmlConversion.test.d.ts +1 -0
- package/types/src/api/exporters/markdown/markdownExporter.test.d.ts +1 -0
- package/types/src/api/nodeConversions/nodeConversions.test.d.ts +1 -0
- package/types/src/api/nodeConversions/nodeToBlock.d.ts +39 -2
- package/types/src/api/parsers/html/parseHTML.test.d.ts +1 -0
- package/types/src/api/parsers/markdown/parseMarkdown.test.d.ts +1 -0
- package/types/src/api/pmUtil.d.ts +3 -3
- package/types/src/api/testUtil/cases/customBlocks.d.ts +670 -0
- package/types/src/api/testUtil/cases/customInlineContent.d.ts +558 -0
- package/types/src/api/testUtil/cases/customStyles.d.ts +552 -0
- package/types/src/api/testUtil/cases/defaultSchema.d.ts +4 -0
- package/types/src/api/testUtil/index.d.ts +14 -0
- package/types/src/api/testUtil/partialBlockTestUtil.d.ts +9 -0
- package/types/src/api/testUtil/paste.d.ts +2 -0
- package/types/src/blocks/CodeBlockContent/defaultSupportedLanguages.d.ts +6 -0
- package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +9 -1
- package/types/src/editor/BlockNoteEditor.d.ts +58 -10
- package/types/src/editor/BlockNoteExtension.d.ts +9 -0
- package/types/src/editor/BlockNoteExtensions.d.ts +2 -2
- package/types/src/editor/BlockNoteTipTapEditor.d.ts +2 -2
- package/types/src/extensions/Collaboration/CursorPlugin.d.ts +3 -3
- package/types/src/extensions/Collaboration/ForkYDocPlugin.d.ts +41 -0
- package/types/src/extensions/Collaboration/ForkYDocPlugin.test.d.ts +1 -0
- package/types/src/extensions/Collaboration/SyncPlugin.d.ts +3 -3
- package/types/src/extensions/Collaboration/UndoPlugin.d.ts +3 -3
- package/types/src/extensions/Collaboration/createCollaborationExtensions.d.ts +17 -0
- package/types/src/extensions/Comments/CommentsPlugin.d.ts +2 -4
- package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +3 -4
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +5 -5
- package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +3 -4
- package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.d.ts +2 -3
- package/types/src/extensions/Placeholder/PlaceholderPlugin.d.ts +2 -3
- package/types/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.d.ts +2 -3
- package/types/src/extensions/ShowSelection/ShowSelectionPlugin.d.ts +2 -3
- package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +3 -4
- package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +2 -4
- package/types/src/extensions/Suggestions/SuggestionMarks.d.ts +4 -0
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +5 -6
- package/types/src/i18n/locales/en.d.ts +0 -1
- package/types/src/i18n/locales/sk.d.ts +0 -1
- package/types/src/index.d.ts +15 -8
- package/dist/en-B7ycW7c8.js.map +0 -1
- package/dist/en-D4taoCs4.cjs.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/api/blockManipulation/selections/__snapshots__/selection.test.ts.snap +0 -844
- package/src/api/blockManipulation/selections/selection.test.ts +0 -72
- package/src/api/blockManipulation/selections/textCursorPosition/__snapshots__/textCursorPosition.test.ts.snap +0 -316
- package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +0 -74
|
@@ -13,10 +13,10 @@ import { getPmSchema } from "../../pmUtil.js";
|
|
|
13
13
|
export function getBlock<
|
|
14
14
|
BSchema extends BlockSchema,
|
|
15
15
|
I extends InlineContentSchema,
|
|
16
|
-
S extends StyleSchema
|
|
16
|
+
S extends StyleSchema,
|
|
17
17
|
>(
|
|
18
18
|
doc: Node,
|
|
19
|
-
blockIdentifier: BlockIdentifier
|
|
19
|
+
blockIdentifier: BlockIdentifier,
|
|
20
20
|
): Block<BSchema, I, S> | undefined {
|
|
21
21
|
const id =
|
|
22
22
|
typeof blockIdentifier === "string" ? blockIdentifier : blockIdentifier.id;
|
|
@@ -33,10 +33,10 @@ export function getBlock<
|
|
|
33
33
|
export function getPrevBlock<
|
|
34
34
|
BSchema extends BlockSchema,
|
|
35
35
|
I extends InlineContentSchema,
|
|
36
|
-
S extends StyleSchema
|
|
36
|
+
S extends StyleSchema,
|
|
37
37
|
>(
|
|
38
38
|
doc: Node,
|
|
39
|
-
blockIdentifier: BlockIdentifier
|
|
39
|
+
blockIdentifier: BlockIdentifier,
|
|
40
40
|
): Block<BSchema, I, S> | undefined {
|
|
41
41
|
const id =
|
|
42
42
|
typeof blockIdentifier === "string" ? blockIdentifier : blockIdentifier.id;
|
|
@@ -59,10 +59,10 @@ export function getPrevBlock<
|
|
|
59
59
|
export function getNextBlock<
|
|
60
60
|
BSchema extends BlockSchema,
|
|
61
61
|
I extends InlineContentSchema,
|
|
62
|
-
S extends StyleSchema
|
|
62
|
+
S extends StyleSchema,
|
|
63
63
|
>(
|
|
64
64
|
doc: Node,
|
|
65
|
-
blockIdentifier: BlockIdentifier
|
|
65
|
+
blockIdentifier: BlockIdentifier,
|
|
66
66
|
): Block<BSchema, I, S> | undefined {
|
|
67
67
|
const id =
|
|
68
68
|
typeof blockIdentifier === "string" ? blockIdentifier : blockIdentifier.id;
|
|
@@ -73,7 +73,7 @@ export function getNextBlock<
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
const $posAfterNode = doc.resolve(
|
|
76
|
-
posInfo.posBeforeNode + posInfo.node.nodeSize
|
|
76
|
+
posInfo.posBeforeNode + posInfo.node.nodeSize,
|
|
77
77
|
);
|
|
78
78
|
const nodeToConvert = $posAfterNode.nodeAfter;
|
|
79
79
|
if (!nodeToConvert) {
|
|
@@ -86,10 +86,10 @@ export function getNextBlock<
|
|
|
86
86
|
export function getParentBlock<
|
|
87
87
|
BSchema extends BlockSchema,
|
|
88
88
|
I extends InlineContentSchema,
|
|
89
|
-
S extends StyleSchema
|
|
89
|
+
S extends StyleSchema,
|
|
90
90
|
>(
|
|
91
91
|
doc: Node,
|
|
92
|
-
blockIdentifier: BlockIdentifier
|
|
92
|
+
blockIdentifier: BlockIdentifier,
|
|
93
93
|
): Block<BSchema, I, S> | undefined {
|
|
94
94
|
const id =
|
|
95
95
|
typeof blockIdentifier === "string" ? blockIdentifier : blockIdentifier.id;
|
|
@@ -10,7 +10,7 @@ export function insertContentAt(
|
|
|
10
10
|
nodes: Node[],
|
|
11
11
|
options: {
|
|
12
12
|
updateSelection: boolean;
|
|
13
|
-
} = { updateSelection: true }
|
|
13
|
+
} = { updateSelection: true },
|
|
14
14
|
) {
|
|
15
15
|
// don’t dispatch an empty fragment because this can lead to strange errors
|
|
16
16
|
// if (content.toString() === "<>") {
|
|
@@ -10,14 +10,17 @@ import {
|
|
|
10
10
|
StyleSchema,
|
|
11
11
|
} from "../../../schema/index.js";
|
|
12
12
|
import { getBlockInfo, getNearestBlockPos } from "../../getBlockInfoFromPos.js";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
nodeToBlock,
|
|
15
|
+
prosemirrorSliceToSlicedBlocks,
|
|
16
|
+
} from "../../nodeConversions/nodeToBlock.js";
|
|
14
17
|
import { getNodeById } from "../../nodeUtil.js";
|
|
15
18
|
import { getBlockNoteSchema, getPmSchema } from "../../pmUtil.js";
|
|
16
19
|
|
|
17
20
|
export function getSelection<
|
|
18
21
|
BSchema extends BlockSchema,
|
|
19
22
|
I extends InlineContentSchema,
|
|
20
|
-
S extends StyleSchema
|
|
23
|
+
S extends StyleSchema,
|
|
21
24
|
>(tr: Transaction): Selection<BSchema, I, S> | undefined {
|
|
22
25
|
const pmSchema = getPmSchema(tr);
|
|
23
26
|
// Return undefined if the selection is collapsed or a node is selected.
|
|
@@ -26,10 +29,10 @@ export function getSelection<
|
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
const $startBlockBeforePos = tr.doc.resolve(
|
|
29
|
-
getNearestBlockPos(tr.doc, tr.selection.from).posBeforeNode
|
|
32
|
+
getNearestBlockPos(tr.doc, tr.selection.from).posBeforeNode,
|
|
30
33
|
);
|
|
31
34
|
const $endBlockBeforePos = tr.doc.resolve(
|
|
32
|
-
getNearestBlockPos(tr.doc, tr.selection.to).posBeforeNode
|
|
35
|
+
getNearestBlockPos(tr.doc, tr.selection.to).posBeforeNode,
|
|
33
36
|
);
|
|
34
37
|
|
|
35
38
|
// Converts the node at the given index and depth around `$startBlockBeforePos`
|
|
@@ -37,14 +40,14 @@ export function getSelection<
|
|
|
37
40
|
// at the depth of `$startBlockBeforePos`.
|
|
38
41
|
const indexToBlock = (
|
|
39
42
|
index: number,
|
|
40
|
-
depth?: number
|
|
43
|
+
depth?: number,
|
|
41
44
|
): Block<BSchema, I, S> => {
|
|
42
45
|
const pos = $startBlockBeforePos.posAtIndex(index, depth);
|
|
43
46
|
const node = tr.doc.resolve(pos).nodeAfter;
|
|
44
47
|
|
|
45
48
|
if (!node) {
|
|
46
49
|
throw new Error(
|
|
47
|
-
`Error getting selection - node not found at position ${pos}
|
|
50
|
+
`Error getting selection - node not found at position ${pos}`,
|
|
48
51
|
);
|
|
49
52
|
}
|
|
50
53
|
|
|
@@ -120,7 +123,7 @@ export function getSelection<
|
|
|
120
123
|
|
|
121
124
|
if (blocks.length === 0) {
|
|
122
125
|
throw new Error(
|
|
123
|
-
`Error getting selection - selection doesn't span any blocks (${tr.selection})
|
|
126
|
+
`Error getting selection - selection doesn't span any blocks (${tr.selection})`,
|
|
124
127
|
);
|
|
125
128
|
}
|
|
126
129
|
|
|
@@ -132,7 +135,7 @@ export function getSelection<
|
|
|
132
135
|
export function setSelection(
|
|
133
136
|
tr: Transaction,
|
|
134
137
|
startBlock: BlockIdentifier,
|
|
135
|
-
endBlock: BlockIdentifier
|
|
138
|
+
endBlock: BlockIdentifier,
|
|
136
139
|
) {
|
|
137
140
|
const startBlockId =
|
|
138
141
|
typeof startBlock === "string" ? startBlock : startBlock.id;
|
|
@@ -142,7 +145,7 @@ export function setSelection(
|
|
|
142
145
|
|
|
143
146
|
if (startBlockId === endBlockId) {
|
|
144
147
|
throw new Error(
|
|
145
|
-
`Attempting to set selection with the same anchor and head blocks (id ${startBlockId})
|
|
148
|
+
`Attempting to set selection with the same anchor and head blocks (id ${startBlockId})`,
|
|
146
149
|
);
|
|
147
150
|
}
|
|
148
151
|
const anchorPosInfo = getNodeById(startBlockId, tr.doc);
|
|
@@ -171,12 +174,12 @@ export function setSelection(
|
|
|
171
174
|
anchorBlockConfig.content === "none"
|
|
172
175
|
) {
|
|
173
176
|
throw new Error(
|
|
174
|
-
`Attempting to set selection anchor in block without content (id ${startBlockId})
|
|
177
|
+
`Attempting to set selection anchor in block without content (id ${startBlockId})`,
|
|
175
178
|
);
|
|
176
179
|
}
|
|
177
180
|
if (!headBlockInfo.isBlockContainer || headBlockConfig.content === "none") {
|
|
178
181
|
throw new Error(
|
|
179
|
-
`Attempting to set selection anchor in block without content (id ${endBlockId})
|
|
182
|
+
`Attempting to set selection anchor in block without content (id ${endBlockId})`,
|
|
180
183
|
);
|
|
181
184
|
}
|
|
182
185
|
|
|
@@ -201,7 +204,7 @@ export function setSelection(
|
|
|
201
204
|
tableMap.positionAt(
|
|
202
205
|
tableMap.height - 1,
|
|
203
206
|
tableMap.width - 1,
|
|
204
|
-
headBlockInfo.blockContent.node
|
|
207
|
+
headBlockInfo.blockContent.node,
|
|
205
208
|
) +
|
|
206
209
|
1;
|
|
207
210
|
const lastCellNodeSize = tr.doc.resolve(lastCellPos).nodeAfter!.nodeSize;
|
|
@@ -216,3 +219,47 @@ export function setSelection(
|
|
|
216
219
|
// restriction that the start/end blocks must have content.
|
|
217
220
|
tr.setSelection(TextSelection.create(tr.doc, startPos, endPos));
|
|
218
221
|
}
|
|
222
|
+
|
|
223
|
+
export function getSelectionCutBlocks(tr: Transaction) {
|
|
224
|
+
// TODO: fix image node selection
|
|
225
|
+
|
|
226
|
+
const pmSchema = getPmSchema(tr);
|
|
227
|
+
let start = tr.selection.$from;
|
|
228
|
+
let end = tr.selection.$to;
|
|
229
|
+
|
|
230
|
+
// the selection moves below are used to make sure `prosemirrorSliceToSlicedBlocks` returns
|
|
231
|
+
// the correct information about whether content is cut at the start or end of a block
|
|
232
|
+
|
|
233
|
+
// if the end is at the end of a node (|</span></p>) move it forward so we include all closing tags (</span></p>|)
|
|
234
|
+
while (end.parentOffset >= end.parent.nodeSize - 2 && end.depth > 0) {
|
|
235
|
+
end = tr.doc.resolve(end.pos + 1);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// if the end is at the start of an empty node (</span></p><p>|) move it backwards so we drop empty start tags (</span></p>|)
|
|
239
|
+
while (end.parentOffset === 0 && end.depth > 0) {
|
|
240
|
+
end = tr.doc.resolve(end.pos - 1);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// if the start is at the start of a node (<p><span>|) move it backwards so we include all open tags (|<p><span>)
|
|
244
|
+
while (start.parentOffset === 0 && start.depth > 0) {
|
|
245
|
+
start = tr.doc.resolve(start.pos - 1);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// if the start is at the end of a node (|</p><p><span>|) move it forwards so we drop all closing tags (|<p><span>)
|
|
249
|
+
while (start.parentOffset >= start.parent.nodeSize - 2 && start.depth > 0) {
|
|
250
|
+
start = tr.doc.resolve(start.pos + 1);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const selectionInfo = prosemirrorSliceToSlicedBlocks(
|
|
254
|
+
tr.doc.slice(start.pos, end.pos, true),
|
|
255
|
+
pmSchema,
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
return {
|
|
259
|
+
_meta: {
|
|
260
|
+
startPos: start.pos,
|
|
261
|
+
endPos: end.pos,
|
|
262
|
+
},
|
|
263
|
+
...selectionInfo,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
@@ -4,26 +4,26 @@ import {
|
|
|
4
4
|
TextSelection,
|
|
5
5
|
type Transaction,
|
|
6
6
|
} from "prosemirror-state";
|
|
7
|
-
import type { TextCursorPosition } from "
|
|
7
|
+
import type { TextCursorPosition } from "../../../editor/cursorPositionTypes.js";
|
|
8
8
|
import type {
|
|
9
9
|
BlockIdentifier,
|
|
10
10
|
BlockSchema,
|
|
11
11
|
InlineContentSchema,
|
|
12
12
|
StyleSchema,
|
|
13
|
-
} from "
|
|
14
|
-
import { UnreachableCaseError } from "
|
|
13
|
+
} from "../../../schema/index.js";
|
|
14
|
+
import { UnreachableCaseError } from "../../../util/typescript.js";
|
|
15
15
|
import {
|
|
16
16
|
getBlockInfo,
|
|
17
17
|
getBlockInfoFromTransaction,
|
|
18
|
-
} from "
|
|
19
|
-
import { nodeToBlock } from "
|
|
20
|
-
import { getNodeById } from "
|
|
21
|
-
import { getBlockNoteSchema, getPmSchema } from "
|
|
18
|
+
} from "../../getBlockInfoFromPos.js";
|
|
19
|
+
import { nodeToBlock } from "../../nodeConversions/nodeToBlock.js";
|
|
20
|
+
import { getNodeById } from "../../nodeUtil.js";
|
|
21
|
+
import { getBlockNoteSchema, getPmSchema } from "../../pmUtil.js";
|
|
22
22
|
|
|
23
23
|
export function getTextCursorPosition<
|
|
24
24
|
BSchema extends BlockSchema,
|
|
25
25
|
I extends InlineContentSchema,
|
|
26
|
-
S extends StyleSchema
|
|
26
|
+
S extends StyleSchema,
|
|
27
27
|
>(tr: Transaction): TextCursorPosition<BSchema, I, S> {
|
|
28
28
|
const { bnBlock } = getBlockInfoFromTransaction(tr);
|
|
29
29
|
const pmSchema = getPmSchema(tr.doc);
|
|
@@ -58,7 +58,7 @@ export function getTextCursorPosition<
|
|
|
58
58
|
export function setTextCursorPosition(
|
|
59
59
|
tr: Transaction,
|
|
60
60
|
targetBlock: BlockIdentifier,
|
|
61
|
-
placement: "start" | "end" = "start"
|
|
61
|
+
placement: "start" | "end" = "start",
|
|
62
62
|
) {
|
|
63
63
|
const id = typeof targetBlock === "string" ? targetBlock : targetBlock.id;
|
|
64
64
|
const pmSchema = getPmSchema(tr.doc);
|
|
@@ -84,11 +84,11 @@ export function setTextCursorPosition(
|
|
|
84
84
|
if (contentType === "inline") {
|
|
85
85
|
if (placement === "start") {
|
|
86
86
|
tr.setSelection(
|
|
87
|
-
TextSelection.create(tr.doc, blockContent.beforePos + 1)
|
|
87
|
+
TextSelection.create(tr.doc, blockContent.beforePos + 1),
|
|
88
88
|
);
|
|
89
89
|
} else {
|
|
90
90
|
tr.setSelection(
|
|
91
|
-
TextSelection.create(tr.doc, blockContent.afterPos - 1)
|
|
91
|
+
TextSelection.create(tr.doc, blockContent.afterPos - 1),
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
94
|
} else if (contentType === "table") {
|
|
@@ -97,11 +97,11 @@ export function setTextCursorPosition(
|
|
|
97
97
|
// and `tableCell` nodes to get to the `tableParagraph` node we want to
|
|
98
98
|
// set the selection in.
|
|
99
99
|
tr.setSelection(
|
|
100
|
-
TextSelection.create(tr.doc, blockContent.beforePos + 4)
|
|
100
|
+
TextSelection.create(tr.doc, blockContent.beforePos + 4),
|
|
101
101
|
);
|
|
102
102
|
} else {
|
|
103
103
|
tr.setSelection(
|
|
104
|
-
TextSelection.create(tr.doc, blockContent.afterPos - 4)
|
|
104
|
+
TextSelection.create(tr.doc, blockContent.afterPos - 4),
|
|
105
105
|
);
|
|
106
106
|
}
|
|
107
107
|
} else {
|