@blocknote/core 0.29.1 → 0.30.1
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/README.md +125 -0
- package/dist/blocknote.cjs +9 -9
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +1501 -1359
- package/dist/blocknote.js.map +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js.map +1 -1
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +751 -9
- package/dist/locales.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +7 -8
- package/src/api/README.md +1 -1
- package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +0 -7
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +19 -14
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +5 -5
- package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +0 -5
- 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/__snapshots__/moveBlocks.test.ts.snap +0 -20
- 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/__snapshots__/replaceBlocks.test.ts.snap +0 -12
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +12 -12
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +7 -7
- package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +0 -6
- 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 +0 -17
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +42 -42
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +18 -18
- package/src/api/blockManipulation/getBlock/getBlock.ts +9 -9
- package/src/api/blockManipulation/insertContentAt.ts +1 -1
- package/src/api/blockManipulation/selections/selection.ts +11 -11
- package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +7 -7
- package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +6 -6
- 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 +21 -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 +26 -26
- package/src/api/nodeConversions/fragmentToBlocks.ts +1 -1
- package/src/api/nodeConversions/nodeToBlock.ts +37 -33
- 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 +4 -4
- package/src/api/positionMapping.test.ts +3 -3
- package/src/api/positionMapping.ts +5 -5
- package/src/blocks/AudioBlockContent/AudioBlockContent.ts +9 -4
- package/src/blocks/CodeBlockContent/CodeBlockContent.ts +40 -26
- package/src/blocks/FileBlockContent/FileBlockContent.ts +7 -2
- package/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.ts +2 -2
- package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +5 -5
- 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 +15 -8
- 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 +9 -6
- package/src/blocks/ImageBlockContent/ImageBlockContent.ts +14 -6
- package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +13 -29
- package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +24 -13
- package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +1 -1
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +13 -30
- package/src/blocks/ListItemBlockContent/getListItemContent.ts +115 -0
- 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 +9 -5
- package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +10 -5
- package/src/blocks/README.md +1 -1
- package/src/blocks/TableBlockContent/TableBlockContent.ts +76 -19
- package/src/blocks/TableBlockContent/TableExtension.ts +3 -3
- package/src/blocks/VideoBlockContent/VideoBlockContent.ts +14 -6
- package/src/blocks/defaultBlockHelpers.ts +24 -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 +10 -1
- package/src/editor/BlockNoteEditor.test.ts +3 -3
- package/src/editor/BlockNoteEditor.ts +110 -61
- package/src/editor/BlockNoteExtensions.ts +24 -15
- package/src/editor/BlockNoteSchema.ts +4 -4
- package/src/editor/BlockNoteTipTapEditor.ts +10 -10
- 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 +152 -0
- package/src/extensions/Collaboration/SyncPlugin.ts +15 -0
- package/src/extensions/Collaboration/UndoPlugin.ts +14 -0
- package/src/extensions/Comments/CommentsPlugin.ts +9 -9
- package/src/extensions/Comments/userstore/UserStore.ts +2 -2
- package/src/extensions/FilePanel/FilePanelPlugin.ts +37 -28
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +6 -8
- package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +29 -26
- package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +11 -11
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +4 -4
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +10 -10
- package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +2 -2
- package/src/extensions/README.md +1 -1
- package/src/extensions/SideMenu/MultipleNodeSelection.ts +1 -1
- package/src/extensions/SideMenu/SideMenuPlugin.ts +31 -31
- package/src/extensions/SideMenu/dragging.ts +8 -8
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +17 -17
- package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +2 -2
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +12 -12
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +54 -53
- 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/index.ts +2 -0
- package/src/i18n/locales/ru.ts +2 -2
- package/src/i18n/locales/sk.ts +355 -0
- package/src/i18n/locales/zh-tw.ts +390 -0
- package/src/locales.ts +1 -1
- package/src/pm-nodes/BlockContainer.ts +7 -6
- package/src/pm-nodes/BlockGroup.ts +1 -1
- package/src/pm-nodes/Doc.ts +4 -4
- package/src/schema/README.md +1 -1
- package/src/schema/blocks/createSpec.ts +15 -15
- package/src/schema/blocks/internal.ts +17 -18
- package/src/schema/blocks/types.ts +27 -26
- 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/setupTestEnv.d.ts +8 -4
- package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +8 -4
- package/types/src/blocks/ListItemBlockContent/getListItemContent.d.ts +28 -0
- package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +8 -4
- package/types/src/blocks/defaultBlockHelpers.d.ts +1 -0
- package/types/src/blocks/defaultBlocks.d.ts +16 -8
- package/types/src/editor/BlockNoteEditor.d.ts +21 -2
- package/types/src/extensions/Collaboration/CursorPlugin.d.ts +31 -0
- package/types/src/extensions/Collaboration/SyncPlugin.d.ts +7 -0
- package/types/src/extensions/Collaboration/UndoPlugin.d.ts +6 -0
- package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +1 -1
- package/types/src/i18n/locales/index.d.ts +2 -0
- package/types/src/i18n/locales/sk.d.ts +313 -0
- package/types/src/i18n/locales/zh-tw.d.ts +2 -0
- package/types/src/schema/blocks/types.d.ts +2 -1
- package/src/extensions/Collaboration/createCollaborationExtensions.ts +0 -147
- package/types/src/extensions/Collaboration/createCollaborationExtensions.d.ts +0 -17
|
@@ -30,7 +30,7 @@ import { getBlockSchema } from "../pmUtil.js";
|
|
|
30
30
|
*/
|
|
31
31
|
export function contentNodeToTableContent<
|
|
32
32
|
I extends InlineContentSchema,
|
|
33
|
-
S extends StyleSchema
|
|
33
|
+
S extends StyleSchema,
|
|
34
34
|
>(contentNode: Node, inlineContentSchema: I, styleSchema: S) {
|
|
35
35
|
const ret: TableContent<I, S> = {
|
|
36
36
|
type: "tableContent",
|
|
@@ -70,34 +70,37 @@ export function contentNodeToTableContent<
|
|
|
70
70
|
// Convert cell content to inline content and merge adjacent styled text nodes
|
|
71
71
|
const content = cellNode.content.content
|
|
72
72
|
.map((child) =>
|
|
73
|
-
contentNodeToInlineContent(child, inlineContentSchema, styleSchema)
|
|
73
|
+
contentNodeToInlineContent(child, inlineContentSchema, styleSchema),
|
|
74
74
|
)
|
|
75
75
|
// The reason that we merge this content is that we allow table cells to contain multiple tableParagraph nodes
|
|
76
76
|
// So that we can leverage prosemirror-tables native merging
|
|
77
77
|
// If the schema only allowed a single tableParagraph node, then the merging would not work and cause prosemirror to fit the content into a new cell
|
|
78
|
-
.reduce(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
.reduce(
|
|
79
|
+
(acc, contentPartial) => {
|
|
80
|
+
if (!acc.length) {
|
|
81
|
+
return contentPartial;
|
|
82
|
+
}
|
|
82
83
|
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
const last = acc[acc.length - 1];
|
|
85
|
+
const first = contentPartial[0];
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
87
|
+
// Only merge if the last and first content are both styled text nodes and have the same styles
|
|
88
|
+
if (
|
|
89
|
+
first &&
|
|
90
|
+
isStyledTextInlineContent(last) &&
|
|
91
|
+
isStyledTextInlineContent(first) &&
|
|
92
|
+
JSON.stringify(last.styles) === JSON.stringify(first.styles)
|
|
93
|
+
) {
|
|
94
|
+
// Join them together if they have the same styles
|
|
95
|
+
last.text += "\n" + first.text;
|
|
96
|
+
acc.push(...contentPartial.slice(1));
|
|
97
|
+
return acc;
|
|
98
|
+
}
|
|
99
|
+
acc.push(...contentPartial);
|
|
96
100
|
return acc;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}, [] as InlineContent<I, S>[]);
|
|
101
|
+
},
|
|
102
|
+
[] as InlineContent<I, S>[],
|
|
103
|
+
);
|
|
101
104
|
|
|
102
105
|
return {
|
|
103
106
|
type: "tableCell",
|
|
@@ -135,7 +138,7 @@ export function contentNodeToTableContent<
|
|
|
135
138
|
*/
|
|
136
139
|
export function contentNodeToInlineContent<
|
|
137
140
|
I extends InlineContentSchema,
|
|
138
|
-
S extends StyleSchema
|
|
141
|
+
S extends StyleSchema,
|
|
139
142
|
>(contentNode: Node, inlineContentSchema: I, styleSchema: S) {
|
|
140
143
|
const content: InlineContent<any, S>[] = [];
|
|
141
144
|
let currentContent: InlineContent<any, S> | undefined = undefined;
|
|
@@ -182,7 +185,7 @@ export function contentNodeToInlineContent<
|
|
|
182
185
|
}
|
|
183
186
|
|
|
184
187
|
content.push(
|
|
185
|
-
nodeToCustomInlineContent(node, inlineContentSchema, styleSchema)
|
|
188
|
+
nodeToCustomInlineContent(node, inlineContentSchema, styleSchema),
|
|
186
189
|
);
|
|
187
190
|
|
|
188
191
|
return;
|
|
@@ -259,7 +262,8 @@ export function contentNodeToInlineContent<
|
|
|
259
262
|
// Styles are the same.
|
|
260
263
|
if (
|
|
261
264
|
JSON.stringify(
|
|
262
|
-
currentContent.content[currentContent.content.length - 1]
|
|
265
|
+
currentContent.content[currentContent.content.length - 1]
|
|
266
|
+
.styles,
|
|
263
267
|
) === JSON.stringify(styles)
|
|
264
268
|
) {
|
|
265
269
|
currentContent.content[currentContent.content.length - 1].text +=
|
|
@@ -336,7 +340,7 @@ export function contentNodeToInlineContent<
|
|
|
336
340
|
|
|
337
341
|
export function nodeToCustomInlineContent<
|
|
338
342
|
I extends InlineContentSchema,
|
|
339
|
-
S extends StyleSchema
|
|
343
|
+
S extends StyleSchema,
|
|
340
344
|
>(node: Node, inlineContentSchema: I, styleSchema: S): InlineContent<I, S> {
|
|
341
345
|
if (node.type.name === "text" || node.type.name === "link") {
|
|
342
346
|
throw new Error("unexpected");
|
|
@@ -363,7 +367,7 @@ export function nodeToCustomInlineContent<
|
|
|
363
367
|
content = contentNodeToInlineContent(
|
|
364
368
|
node,
|
|
365
369
|
inlineContentSchema,
|
|
366
|
-
styleSchema
|
|
370
|
+
styleSchema,
|
|
367
371
|
) as any; // TODO: is this safe? could we have Links here that are undesired?
|
|
368
372
|
} else {
|
|
369
373
|
content = undefined;
|
|
@@ -385,14 +389,14 @@ export function nodeToCustomInlineContent<
|
|
|
385
389
|
export function nodeToBlock<
|
|
386
390
|
BSchema extends BlockSchema,
|
|
387
391
|
I extends InlineContentSchema,
|
|
388
|
-
S extends StyleSchema
|
|
392
|
+
S extends StyleSchema,
|
|
389
393
|
>(
|
|
390
394
|
node: Node,
|
|
391
395
|
schema: Schema,
|
|
392
396
|
blockSchema: BSchema = getBlockSchema(schema) as BSchema,
|
|
393
397
|
inlineContentSchema: I = getInlineContentSchema(schema) as I,
|
|
394
398
|
styleSchema: S = getStyleSchema(schema) as S,
|
|
395
|
-
blockCache = getBlockCache(schema)
|
|
399
|
+
blockCache = getBlockCache(schema),
|
|
396
400
|
): Block<BSchema, I, S> {
|
|
397
401
|
if (!node.type.isInGroup("bnBlock")) {
|
|
398
402
|
throw Error("Node should be a bnBlock, but is instead: " + node.type.name);
|
|
@@ -445,8 +449,8 @@ export function nodeToBlock<
|
|
|
445
449
|
blockSchema,
|
|
446
450
|
inlineContentSchema,
|
|
447
451
|
styleSchema,
|
|
448
|
-
blockCache
|
|
449
|
-
)
|
|
452
|
+
blockCache,
|
|
453
|
+
),
|
|
450
454
|
);
|
|
451
455
|
});
|
|
452
456
|
|
|
@@ -459,7 +463,7 @@ export function nodeToBlock<
|
|
|
459
463
|
content = contentNodeToInlineContent(
|
|
460
464
|
blockInfo.blockContent.node,
|
|
461
465
|
inlineContentSchema,
|
|
462
|
-
styleSchema
|
|
466
|
+
styleSchema,
|
|
463
467
|
);
|
|
464
468
|
} else if (blockConfig.content === "table") {
|
|
465
469
|
if (!blockInfo.isBlockContainer) {
|
|
@@ -468,7 +472,7 @@ export function nodeToBlock<
|
|
|
468
472
|
content = contentNodeToTableContent(
|
|
469
473
|
blockInfo.blockContent.node,
|
|
470
474
|
inlineContentSchema,
|
|
471
|
-
styleSchema
|
|
475
|
+
styleSchema,
|
|
472
476
|
);
|
|
473
477
|
} else if (blockConfig.content === "none") {
|
|
474
478
|
content = undefined;
|
package/src/api/nodeUtil.test.ts
CHANGED
|
@@ -27,7 +27,7 @@ describe("Test getBlocksChangedByTransaction", () => {
|
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
await expect(blocksChanged).toMatchFileSnapshot(
|
|
30
|
-
"__snapshots__/blocks-inserted.json"
|
|
30
|
+
"__snapshots__/blocks-inserted.json",
|
|
31
31
|
);
|
|
32
32
|
});
|
|
33
33
|
|
|
@@ -41,14 +41,14 @@ describe("Test getBlocksChangedByTransaction", () => {
|
|
|
41
41
|
},
|
|
42
42
|
],
|
|
43
43
|
"paragraph-0",
|
|
44
|
-
"after"
|
|
44
|
+
"after",
|
|
45
45
|
);
|
|
46
46
|
|
|
47
47
|
return getBlocksChangedByTransaction(tr);
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
await expect(blocksChanged).toMatchFileSnapshot(
|
|
51
|
-
"__snapshots__/blocks-inserted-nested.json"
|
|
51
|
+
"__snapshots__/blocks-inserted-nested.json",
|
|
52
52
|
);
|
|
53
53
|
});
|
|
54
54
|
|
|
@@ -59,7 +59,7 @@ describe("Test getBlocksChangedByTransaction", () => {
|
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
await expect(blocksChanged).toMatchFileSnapshot(
|
|
62
|
-
"__snapshots__/blocks-deleted.json"
|
|
62
|
+
"__snapshots__/blocks-deleted.json",
|
|
63
63
|
);
|
|
64
64
|
});
|
|
65
65
|
|
|
@@ -70,7 +70,7 @@ describe("Test getBlocksChangedByTransaction", () => {
|
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
await expect(blocksChanged).toMatchFileSnapshot(
|
|
73
|
-
"__snapshots__/blocks-deleted-nested-deep.json"
|
|
73
|
+
"__snapshots__/blocks-deleted-nested-deep.json",
|
|
74
74
|
);
|
|
75
75
|
});
|
|
76
76
|
|
|
@@ -81,7 +81,7 @@ describe("Test getBlocksChangedByTransaction", () => {
|
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
await expect(blocksChanged).toMatchFileSnapshot(
|
|
84
|
-
"__snapshots__/blocks-deleted-nested.json"
|
|
84
|
+
"__snapshots__/blocks-deleted-nested.json",
|
|
85
85
|
);
|
|
86
86
|
});
|
|
87
87
|
|
|
@@ -97,7 +97,7 @@ describe("Test getBlocksChangedByTransaction", () => {
|
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
await expect(blocksChanged).toMatchFileSnapshot(
|
|
100
|
-
"__snapshots__/blocks-updated.json"
|
|
100
|
+
"__snapshots__/blocks-updated.json",
|
|
101
101
|
);
|
|
102
102
|
});
|
|
103
103
|
|
|
@@ -113,7 +113,7 @@ describe("Test getBlocksChangedByTransaction", () => {
|
|
|
113
113
|
});
|
|
114
114
|
|
|
115
115
|
await expect(blocksChanged).toMatchFileSnapshot(
|
|
116
|
-
"__snapshots__/blocks-updated-nested.json"
|
|
116
|
+
"__snapshots__/blocks-updated-nested.json",
|
|
117
117
|
);
|
|
118
118
|
});
|
|
119
119
|
|
|
@@ -127,7 +127,7 @@ describe("Test getBlocksChangedByTransaction", () => {
|
|
|
127
127
|
});
|
|
128
128
|
|
|
129
129
|
await expect(blocksChanged).toMatchFileSnapshot(
|
|
130
|
-
"__snapshots__/blocks-updated-nested-deep.json"
|
|
130
|
+
"__snapshots__/blocks-updated-nested-deep.json",
|
|
131
131
|
);
|
|
132
132
|
});
|
|
133
133
|
|
|
@@ -146,7 +146,7 @@ describe("Test getBlocksChangedByTransaction", () => {
|
|
|
146
146
|
});
|
|
147
147
|
|
|
148
148
|
await expect(blocksChanged).toMatchFileSnapshot(
|
|
149
|
-
"__snapshots__/blocks-updated-nested-multiple.json"
|
|
149
|
+
"__snapshots__/blocks-updated-nested-multiple.json",
|
|
150
150
|
);
|
|
151
151
|
});
|
|
152
152
|
|
|
@@ -167,7 +167,7 @@ describe("Test getBlocksChangedByTransaction", () => {
|
|
|
167
167
|
});
|
|
168
168
|
|
|
169
169
|
await expect(blocksChanged).toMatchFileSnapshot(
|
|
170
|
-
"__snapshots__/blocks-updated-single.json"
|
|
170
|
+
"__snapshots__/blocks-updated-single.json",
|
|
171
171
|
);
|
|
172
172
|
});
|
|
173
173
|
|
|
@@ -188,7 +188,7 @@ describe("Test getBlocksChangedByTransaction", () => {
|
|
|
188
188
|
});
|
|
189
189
|
|
|
190
190
|
await expect(blocksChanged).toMatchFileSnapshot(
|
|
191
|
-
"__snapshots__/blocks-updated-multiple.json"
|
|
191
|
+
"__snapshots__/blocks-updated-multiple.json",
|
|
192
192
|
);
|
|
193
193
|
});
|
|
194
194
|
|
|
@@ -197,19 +197,19 @@ describe("Test getBlocksChangedByTransaction", () => {
|
|
|
197
197
|
editor.insertBlocks(
|
|
198
198
|
[{ type: "paragraph", content: "ABC" }],
|
|
199
199
|
"paragraph-0",
|
|
200
|
-
"after"
|
|
200
|
+
"after",
|
|
201
201
|
);
|
|
202
202
|
editor.insertBlocks(
|
|
203
203
|
[{ type: "paragraph", content: "DEF" }],
|
|
204
204
|
"paragraph-1",
|
|
205
|
-
"after"
|
|
205
|
+
"after",
|
|
206
206
|
);
|
|
207
207
|
|
|
208
208
|
return getBlocksChangedByTransaction(tr);
|
|
209
209
|
});
|
|
210
210
|
|
|
211
211
|
await expect(blocksChanged).toMatchFileSnapshot(
|
|
212
|
-
"__snapshots__/blocks-updated-multiple-insert.json"
|
|
212
|
+
"__snapshots__/blocks-updated-multiple-insert.json",
|
|
213
213
|
);
|
|
214
214
|
});
|
|
215
215
|
|
|
@@ -222,7 +222,7 @@ describe("Test getBlocksChangedByTransaction", () => {
|
|
|
222
222
|
});
|
|
223
223
|
|
|
224
224
|
await expect(blocksChanged).toMatchFileSnapshot(
|
|
225
|
-
"__snapshots__/blocks-updated-content-inserted.json"
|
|
225
|
+
"__snapshots__/blocks-updated-content-inserted.json",
|
|
226
226
|
);
|
|
227
227
|
});
|
|
228
228
|
});
|
package/src/api/nodeUtil.ts
CHANGED
|
@@ -22,7 +22,7 @@ import { getPmSchema } from "./pmUtil.js";
|
|
|
22
22
|
*/
|
|
23
23
|
export function getNodeById(
|
|
24
24
|
id: string,
|
|
25
|
-
doc: Node
|
|
25
|
+
doc: Node,
|
|
26
26
|
): { node: Node; posBeforeNode: number } | undefined {
|
|
27
27
|
let targetNode: Node | undefined = undefined;
|
|
28
28
|
let posBeforeNode: number | undefined = undefined;
|
|
@@ -98,7 +98,7 @@ export type BlockChangeSource =
|
|
|
98
98
|
export type BlocksChanged<
|
|
99
99
|
BSchema extends BlockSchema = DefaultBlockSchema,
|
|
100
100
|
ISchema extends InlineContentSchema = DefaultInlineContentSchema,
|
|
101
|
-
SSchema extends StyleSchema = DefaultStyleSchema
|
|
101
|
+
SSchema extends StyleSchema = DefaultStyleSchema,
|
|
102
102
|
> = Array<
|
|
103
103
|
{
|
|
104
104
|
/**
|
|
@@ -134,10 +134,10 @@ export type BlocksChanged<
|
|
|
134
134
|
function areBlocksDifferentExcludingChildren<
|
|
135
135
|
BSchema extends BlockSchema,
|
|
136
136
|
ISchema extends InlineContentSchema,
|
|
137
|
-
SSchema extends StyleSchema
|
|
137
|
+
SSchema extends StyleSchema,
|
|
138
138
|
>(
|
|
139
139
|
block1: Block<BSchema, ISchema, SSchema>,
|
|
140
|
-
block2: Block<BSchema, ISchema, SSchema
|
|
140
|
+
block2: Block<BSchema, ISchema, SSchema>,
|
|
141
141
|
): boolean {
|
|
142
142
|
// TODO use an actual diff algorithm
|
|
143
143
|
// Compare all properties except children
|
|
@@ -158,10 +158,10 @@ function areBlocksDifferentExcludingChildren<
|
|
|
158
158
|
export function getBlocksChangedByTransaction<
|
|
159
159
|
BSchema extends BlockSchema = DefaultBlockSchema,
|
|
160
160
|
ISchema extends InlineContentSchema = DefaultInlineContentSchema,
|
|
161
|
-
SSchema extends StyleSchema = DefaultStyleSchema
|
|
161
|
+
SSchema extends StyleSchema = DefaultStyleSchema,
|
|
162
162
|
>(
|
|
163
163
|
transaction: Transaction,
|
|
164
|
-
appendedTransactions: Transaction[] = []
|
|
164
|
+
appendedTransactions: Transaction[] = [],
|
|
165
165
|
): BlocksChanged<BSchema, ISchema, SSchema> {
|
|
166
166
|
let source: BlockChangeSource = { type: "local" };
|
|
167
167
|
|
|
@@ -198,7 +198,7 @@ export function getBlocksChangedByTransaction<
|
|
|
198
198
|
return findChildrenInRange(
|
|
199
199
|
combinedTransaction.before,
|
|
200
200
|
range.oldRange,
|
|
201
|
-
isNodeBlock
|
|
201
|
+
isNodeBlock,
|
|
202
202
|
);
|
|
203
203
|
})
|
|
204
204
|
.map(({ node }) => nodeToBlock(node, pmSchema));
|
|
@@ -208,7 +208,7 @@ export function getBlocksChangedByTransaction<
|
|
|
208
208
|
return findChildrenInRange(
|
|
209
209
|
combinedTransaction.doc,
|
|
210
210
|
range.newRange,
|
|
211
|
-
isNodeBlock
|
|
211
|
+
isNodeBlock,
|
|
212
212
|
);
|
|
213
213
|
})
|
|
214
214
|
.map(({ node }) => nodeToBlock(node, pmSchema));
|
|
@@ -216,12 +216,12 @@ export function getBlocksChangedByTransaction<
|
|
|
216
216
|
const nextBlocks = new Map(
|
|
217
217
|
nextAffectedBlocks.map((block) => {
|
|
218
218
|
return [block.id, block];
|
|
219
|
-
})
|
|
219
|
+
}),
|
|
220
220
|
);
|
|
221
221
|
const prevBlocks = new Map(
|
|
222
222
|
prevAffectedBlocks.map((block) => {
|
|
223
223
|
return [block.id, block];
|
|
224
|
-
})
|
|
224
|
+
}),
|
|
225
225
|
);
|
|
226
226
|
|
|
227
227
|
const changes: BlocksChanged<BSchema, ISchema, SSchema> = [];
|
|
@@ -11,7 +11,7 @@ import { nestedListsToBlockNoteStructure } from "./util/nestedLists.js";
|
|
|
11
11
|
export async function HTMLToBlocks<
|
|
12
12
|
BSchema extends BlockSchema,
|
|
13
13
|
I extends InlineContentSchema,
|
|
14
|
-
S extends StyleSchema
|
|
14
|
+
S extends StyleSchema,
|
|
15
15
|
>(html: string, pmSchema: Schema): Promise<Block<BSchema, I, S>[]> {
|
|
16
16
|
const htmlNode = nestedListsToBlockNoteStructure(html);
|
|
17
17
|
const parser = DOMParser.fromSchema(pmSchema);
|
|
@@ -33,7 +33,7 @@ function liftNestedListsToParent(element: HTMLElement) {
|
|
|
33
33
|
const index = getChildIndex(list);
|
|
34
34
|
const parentListItem = list.parentElement!;
|
|
35
35
|
const siblingsAfter = Array.from(parentListItem.childNodes).slice(
|
|
36
|
-
index + 1
|
|
36
|
+
index + 1,
|
|
37
37
|
);
|
|
38
38
|
list.remove();
|
|
39
39
|
siblingsAfter.forEach((sibling) => {
|
|
@@ -110,7 +110,7 @@ function detachedDoc() {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
export function nestedListsToBlockNoteStructure(
|
|
113
|
-
elementOrHTML: HTMLElement | string
|
|
113
|
+
elementOrHTML: HTMLElement | string,
|
|
114
114
|
) {
|
|
115
115
|
if (typeof elementOrHTML === "string") {
|
|
116
116
|
const element = detachedDoc().createElement("div");
|
|
@@ -70,7 +70,7 @@ export async function markdownToHTML(markdown: string): Promise<string> {
|
|
|
70
70
|
export async function markdownToBlocks<
|
|
71
71
|
BSchema extends BlockSchema,
|
|
72
72
|
I extends InlineContentSchema,
|
|
73
|
-
S extends StyleSchema
|
|
73
|
+
S extends StyleSchema,
|
|
74
74
|
>(markdown: string, pmSchema: Schema): Promise<Block<BSchema, I, S>[]> {
|
|
75
75
|
const htmlString = await markdownToHTML(markdown);
|
|
76
76
|
|
package/src/api/pmUtil.ts
CHANGED
|
@@ -16,7 +16,7 @@ export function getPmSchema(trOrNode: Transaction | Node) {
|
|
|
16
16
|
function getBlockNoteEditor<
|
|
17
17
|
BSchema extends BlockSchema,
|
|
18
18
|
I extends InlineContentSchema,
|
|
19
|
-
S extends StyleSchema
|
|
19
|
+
S extends StyleSchema,
|
|
20
20
|
>(schema: Schema): BlockNoteEditor<BSchema, I, S> {
|
|
21
21
|
return schema.cached.blockNoteEditor as BlockNoteEditor<BSchema, I, S>;
|
|
22
22
|
}
|
|
@@ -24,7 +24,7 @@ function getBlockNoteEditor<
|
|
|
24
24
|
export function getBlockNoteSchema<
|
|
25
25
|
BSchema extends BlockSchema,
|
|
26
26
|
I extends InlineContentSchema,
|
|
27
|
-
S extends StyleSchema
|
|
27
|
+
S extends StyleSchema,
|
|
28
28
|
>(schema: Schema): BlockNoteSchema<BSchema, I, S> {
|
|
29
29
|
return getBlockNoteEditor(schema).schema as unknown as BlockNoteSchema<
|
|
30
30
|
BSchema,
|
|
@@ -34,13 +34,13 @@ export function getBlockNoteSchema<
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export function getBlockSchema<BSchema extends BlockSchema>(
|
|
37
|
-
schema: Schema
|
|
37
|
+
schema: Schema,
|
|
38
38
|
): BSchema {
|
|
39
39
|
return getBlockNoteSchema(schema).blockSchema as BSchema;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export function getInlineContentSchema<I extends InlineContentSchema>(
|
|
43
|
-
schema: Schema
|
|
43
|
+
schema: Schema,
|
|
44
44
|
): I {
|
|
45
45
|
return getBlockNoteSchema(schema).inlineContentSchema as I;
|
|
46
46
|
}
|
|
@@ -23,7 +23,7 @@ describe("PositionStorage with local editor", () => {
|
|
|
23
23
|
|
|
24
24
|
expect(editor._tiptapEditor.on).toHaveBeenCalledWith(
|
|
25
25
|
"transaction",
|
|
26
|
-
expect.any(Function)
|
|
26
|
+
expect.any(Function),
|
|
27
27
|
);
|
|
28
28
|
});
|
|
29
29
|
});
|
|
@@ -59,7 +59,7 @@ describe("PositionStorage with local editor", () => {
|
|
|
59
59
|
},
|
|
60
60
|
],
|
|
61
61
|
editor.document[0],
|
|
62
|
-
"before"
|
|
62
|
+
"before",
|
|
63
63
|
);
|
|
64
64
|
|
|
65
65
|
// Start tracking
|
|
@@ -98,7 +98,7 @@ describe("PositionStorage with local editor", () => {
|
|
|
98
98
|
},
|
|
99
99
|
],
|
|
100
100
|
editor.document[0],
|
|
101
|
-
"before"
|
|
101
|
+
"before",
|
|
102
102
|
);
|
|
103
103
|
// Start tracking
|
|
104
104
|
const getPos = trackPosition(editor, 10);
|
|
@@ -59,10 +59,10 @@ export function trackPosition(
|
|
|
59
59
|
/**
|
|
60
60
|
* This is the side of the position to track. "left" is the default. "right" would move with the change if the change is in the right direction.
|
|
61
61
|
*/
|
|
62
|
-
side: "left" | "right" = "left"
|
|
62
|
+
side: "left" | "right" = "left",
|
|
63
63
|
): () => number {
|
|
64
64
|
const ySyncPluginState = ySyncPluginKey.getState(
|
|
65
|
-
editor._tiptapEditor.state
|
|
65
|
+
editor._tiptapEditor.state,
|
|
66
66
|
) as {
|
|
67
67
|
doc: Y.Doc;
|
|
68
68
|
binding: ProsemirrorBinding;
|
|
@@ -90,18 +90,18 @@ export function trackPosition(
|
|
|
90
90
|
// Track the position after the position if we are on the right side
|
|
91
91
|
position + (side === "right" ? 1 : 0),
|
|
92
92
|
ySyncPluginState.binding.type,
|
|
93
|
-
ySyncPluginState.binding.mapping
|
|
93
|
+
ySyncPluginState.binding.mapping,
|
|
94
94
|
);
|
|
95
95
|
|
|
96
96
|
return () => {
|
|
97
97
|
const curYSyncPluginState = ySyncPluginKey.getState(
|
|
98
|
-
editor._tiptapEditor.state
|
|
98
|
+
editor._tiptapEditor.state,
|
|
99
99
|
) as typeof ySyncPluginState;
|
|
100
100
|
const pos = relativePositionToAbsolutePosition(
|
|
101
101
|
curYSyncPluginState.doc,
|
|
102
102
|
curYSyncPluginState.binding.type,
|
|
103
103
|
relativePosition,
|
|
104
|
-
curYSyncPluginState.binding.mapping
|
|
104
|
+
curYSyncPluginState.binding.mapping,
|
|
105
105
|
);
|
|
106
106
|
|
|
107
107
|
// This can happen if the element is garbage collected
|
|
@@ -47,7 +47,7 @@ export const audioBlockConfig = {
|
|
|
47
47
|
|
|
48
48
|
export const audioRender = (
|
|
49
49
|
block: BlockFromConfig<typeof audioBlockConfig, any, any>,
|
|
50
|
-
editor: BlockNoteEditor<any, any, any
|
|
50
|
+
editor: BlockNoteEditor<any, any, any>,
|
|
51
51
|
) => {
|
|
52
52
|
const icon = document.createElement("div");
|
|
53
53
|
icon.innerHTML = FILE_AUDIO_ICON_SVG;
|
|
@@ -70,14 +70,19 @@ export const audioRender = (
|
|
|
70
70
|
editor,
|
|
71
71
|
{ dom: audio },
|
|
72
72
|
editor.dictionary.file_blocks.audio.add_button_text,
|
|
73
|
-
icon.firstElementChild as HTMLElement
|
|
73
|
+
icon.firstElementChild as HTMLElement,
|
|
74
74
|
);
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
export const audioParse = (
|
|
78
|
-
element: HTMLElement
|
|
78
|
+
element: HTMLElement,
|
|
79
79
|
): Partial<Props<typeof audioBlockConfig.propSchema>> | undefined => {
|
|
80
80
|
if (element.tagName === "AUDIO") {
|
|
81
|
+
// Ignore if parent figure has already been parsed.
|
|
82
|
+
if (element.closest("figure")) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
|
|
81
86
|
return parseAudioElement(element as HTMLAudioElement);
|
|
82
87
|
}
|
|
83
88
|
|
|
@@ -99,7 +104,7 @@ export const audioParse = (
|
|
|
99
104
|
};
|
|
100
105
|
|
|
101
106
|
export const audioToExternalHTML = (
|
|
102
|
-
block: BlockFromConfig<typeof audioBlockConfig, any, any
|
|
107
|
+
block: BlockFromConfig<typeof audioBlockConfig, any, any>,
|
|
103
108
|
) => {
|
|
104
109
|
if (!block.props.url) {
|
|
105
110
|
const div = document.createElement("p");
|