@blocknote/core 0.53.0 → 0.54.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/dist/BlockNoteExtension-BJCLnwrE.cjs +2 -0
- package/dist/BlockNoteExtension-BJCLnwrE.cjs.map +1 -0
- package/dist/BlockNoteExtension-CbvDA0F7.js +80 -0
- package/dist/BlockNoteExtension-CbvDA0F7.js.map +1 -0
- package/dist/{UserStore-QbbPFj0z.js → UserStore-C4TzkGEn.js} +3 -3
- package/dist/{UserStore-DCG6lsla.cjs.map → UserStore-C4TzkGEn.js.map} +1 -1
- package/dist/{UserStore-DCG6lsla.cjs → UserStore-mj3fXW4D.cjs} +2 -2
- package/dist/UserStore-mj3fXW4D.cjs.map +1 -0
- package/dist/blocknote.cjs +1 -1
- package/dist/blocknote.js +6 -6
- package/dist/blocks-CTB_5Vyj.cjs +12 -0
- package/dist/blocks-CTB_5Vyj.cjs.map +1 -0
- package/dist/{blocks-BEJW9OM_.js → blocks-Dol85hpH.js} +680 -670
- package/dist/blocks-Dol85hpH.js.map +1 -0
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +2 -2
- package/dist/comments.cjs +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +7 -7
- package/dist/comments.js.map +1 -1
- package/dist/en-BuzSuuTq.cjs +2 -0
- package/dist/en-BuzSuuTq.cjs.map +1 -0
- package/dist/{en-CGKXfWma.js → en-uzHzj6eH.js} +10 -1
- package/dist/en-uzHzj6eH.js.map +1 -0
- package/dist/extensions-B7Rsp_Ft.cjs +58 -0
- package/dist/extensions-B7Rsp_Ft.cjs.map +1 -0
- package/dist/{extensions-BR5hkAio.js → extensions-D6JcJCwd.js} +735 -457
- package/dist/extensions-D6JcJCwd.js.map +1 -0
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +4 -4
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +199 -1
- package/dist/locales.js.map +1 -1
- package/dist/{src-BUXut68d.js → src-Buuo5l7X.js} +924 -851
- package/dist/src-Buuo5l7X.js.map +1 -0
- package/dist/src-C54Ok9E0.cjs +23 -0
- package/dist/src-C54Ok9E0.cjs.map +1 -0
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/y.cjs +1 -1
- package/dist/y.cjs.map +1 -1
- package/dist/y.js +245 -242
- package/dist/y.js.map +1 -1
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.cjs.map +1 -1
- package/dist/yjs.js +79 -67
- package/dist/yjs.js.map +1 -1
- package/package.json +17 -18
- package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +2505 -763
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +42 -0
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +16 -4
- package/src/api/exporters/markdown/htmlToMarkdown.ts +45 -10
- package/src/api/getBlocksChangedByTransaction.test.ts +211 -0
- package/src/api/getBlocksChangedByTransaction.ts +48 -12
- package/src/api/getChangedRange.ts +54 -0
- package/src/api/nodeConversions/blockToNode.ts +5 -1
- package/src/api/nodeConversions/nodeToBlock.ts +3 -0
- package/src/api/pmUtil.ts +16 -8
- package/src/blocks/Code/CodeBlockOptions.ts +83 -0
- package/src/blocks/Code/block.test.ts +1 -1
- package/src/blocks/Code/block.ts +29 -281
- package/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.ts +120 -0
- package/src/blocks/Code/helpers/parse/parsePreCode.ts +45 -0
- package/src/blocks/Code/helpers/render/createCodeBlock.ts +98 -0
- package/src/blocks/Code/helpers/toExternalHTML/createPreCode.ts +14 -0
- package/src/blocks/index.ts +3 -1
- package/src/comments/extension.ts +2 -4
- package/src/editor/Block.css +273 -2
- package/src/editor/BlockNoteEditor.ts +25 -4
- package/src/editor/BlockNoteExtension.ts +1 -1
- package/src/editor/managers/ExtensionManager/extensions.ts +6 -0
- package/src/editor/performance.test.ts +45 -0
- package/src/exporter/ExportImage.ts +50 -0
- package/src/exporter/Exporter.test.ts +186 -0
- package/src/exporter/Exporter.ts +66 -14
- package/src/exporter/index.ts +1 -0
- package/src/exporter/mapping.ts +4 -1
- package/src/extensions/FormattingToolbar/FormattingToolbar.ts +10 -8
- package/src/extensions/InlineContentBoundaryEdit/InlineContentBoundaryEdit.ts +109 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +21 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +5 -3
- package/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.ts +192 -0
- package/src/extensions/SourceInlineContentWithPreview/SourceInlineContentWithPreview.ts +142 -0
- package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.ts +120 -0
- package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.ts +89 -0
- package/src/extensions/SyntaxHighlighting/inlineHighlight.test.ts +135 -0
- package/src/extensions/SyntaxHighlighting/shiki.ts +116 -0
- package/src/extensions/TableHandles/TableHandles.browser.test.ts +305 -0
- package/src/extensions/TableHandles/TableHandles.ts +82 -41
- package/src/extensions/Versioning/inMemoryVersioning.ts +13 -3
- package/src/extensions/index.ts +4 -0
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +51 -2
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +22 -2
- package/src/fonts/inter.css +9 -9
- package/src/i18n/locales/ar.ts +9 -0
- package/src/i18n/locales/de.ts +9 -0
- package/src/i18n/locales/en.ts +9 -0
- package/src/i18n/locales/es.ts +9 -0
- package/src/i18n/locales/fa.ts +9 -0
- package/src/i18n/locales/fr.ts +9 -0
- package/src/i18n/locales/he.ts +9 -0
- package/src/i18n/locales/hr.ts +9 -0
- package/src/i18n/locales/is.ts +9 -0
- package/src/i18n/locales/it.ts +9 -0
- package/src/i18n/locales/ja.ts +9 -0
- package/src/i18n/locales/ko.ts +9 -0
- package/src/i18n/locales/nl.ts +9 -0
- package/src/i18n/locales/no.ts +9 -0
- package/src/i18n/locales/pl.ts +9 -0
- package/src/i18n/locales/pt.ts +9 -0
- package/src/i18n/locales/ru.ts +9 -0
- package/src/i18n/locales/sk.ts +9 -0
- package/src/i18n/locales/uk.ts +9 -0
- package/src/i18n/locales/uz.ts +9 -0
- package/src/i18n/locales/vi.ts +9 -0
- package/src/i18n/locales/zh-tw.ts +9 -0
- package/src/i18n/locales/zh.ts +9 -0
- package/src/index.ts +5 -1
- package/src/schema/blocks/createSpec.ts +5 -7
- package/src/schema/blocks/types.ts +53 -3
- package/src/schema/contentTypePropagation.test.ts +1 -1
- package/src/schema/inlineContent/createSpec.test.ts +161 -0
- package/src/schema/inlineContent/createSpec.ts +175 -17
- package/src/schema/inlineContent/internal.ts +21 -2
- package/src/schema/inlineContent/types.ts +35 -5
- package/src/schema/nodeViewMutations.test.ts +81 -56
- package/src/schema/nodeViewMutations.ts +30 -27
- package/src/schema/schema.test.ts +110 -0
- package/src/schema/schema.ts +13 -4
- package/src/user/UserStore.ts +1 -1
- package/src/util/Store.test.ts +132 -0
- package/src/util/Store.ts +135 -0
- package/src/y/extensions/AttributionExtension.test.ts +18 -9
- package/src/y/extensions/Versioning.test.ts +20 -7
- package/src/y/versioning/__test__/yhub.test.ts +92 -59
- package/src/y/versioning/yhub.ts +35 -29
- package/src/yjs/comments/RESTYjsThreadStore.test.ts +85 -0
- package/src/yjs/comments/RESTYjsThreadStore.ts +7 -1
- package/src/yjs/extensions/ForkYDoc.test.ts +37 -0
- package/src/yjs/extensions/ForkYDoc.ts +26 -1
- package/src/yjs/extensions/RelativePositionMapping.ts +8 -2
- package/src/yjs/extensions/Versioning.test.ts +17 -5
- package/types/src/api/getChangedRange.d.ts +14 -0
- package/types/src/api/pmUtil.d.ts +7 -7
- package/types/src/blocks/Code/CodeBlockOptions.d.ts +61 -0
- package/types/src/blocks/Code/block.d.ts +3 -53
- package/types/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.d.ts +35 -0
- package/types/src/blocks/Code/helpers/parse/parsePreCode.d.ts +8 -0
- package/types/src/blocks/Code/helpers/render/createCodeBlock.d.ts +18 -0
- package/types/src/blocks/Code/helpers/toExternalHTML/createPreCode.d.ts +5 -0
- package/types/src/blocks/index.d.ts +3 -1
- package/types/src/comments/extension.d.ts +1 -15
- package/types/src/editor/BlockNoteEditor.d.ts +3 -3
- package/types/src/editor/BlockNoteExtension.d.ts +1 -1
- package/types/src/exporter/ExportImage.d.ts +36 -0
- package/types/src/exporter/Exporter.d.ts +30 -0
- package/types/src/exporter/Exporter.test.d.ts +1 -0
- package/types/src/exporter/index.d.ts +1 -0
- package/types/src/exporter/mapping.d.ts +1 -1
- package/types/src/extensions/FilePanel/FilePanel.d.ts +1 -1
- package/types/src/extensions/FormattingToolbar/FormattingToolbar.d.ts +1 -1
- package/types/src/extensions/InlineContentBoundaryEdit/InlineContentBoundaryEdit.d.ts +5 -0
- package/types/src/extensions/ShowSelection/ShowSelection.d.ts +1 -5
- package/types/src/extensions/SideMenu/SideMenu.d.ts +1 -1
- package/types/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.d.ts +45 -0
- package/types/src/extensions/SourceInlineContentWithPreview/SourceInlineContentWithPreview.d.ts +49 -0
- package/types/src/extensions/SuggestionMenu/SuggestionMenu.d.ts +1 -11
- package/types/src/extensions/SyntaxHighlighting/SyntaxHighlighting.d.ts +44 -0
- package/types/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.d.ts +1 -0
- package/types/src/extensions/SyntaxHighlighting/inlineHighlight.test.d.ts +1 -0
- package/types/src/extensions/SyntaxHighlighting/shiki.d.ts +13 -0
- package/types/src/extensions/TableHandles/TableHandles.browser.test.d.ts +1 -0
- package/types/src/extensions/TableHandles/TableHandles.d.ts +4 -1
- package/types/src/extensions/Versioning/Versioning.d.ts +1 -35
- package/types/src/extensions/index.d.ts +4 -0
- package/types/src/i18n/locales/en.d.ts +9 -0
- package/types/src/i18n/locales/fa.d.ts +9 -0
- package/types/src/i18n/locales/sk.d.ts +9 -0
- package/types/src/index.d.ts +2 -1
- package/types/src/schema/blocks/types.d.ts +36 -3
- package/types/src/schema/inlineContent/createSpec.d.ts +35 -3
- package/types/src/schema/inlineContent/createSpec.test.d.ts +1 -0
- package/types/src/schema/inlineContent/internal.d.ts +3 -2
- package/types/src/schema/inlineContent/types.d.ts +22 -3
- package/types/src/schema/nodeViewMutations.d.ts +2 -2
- package/types/src/schema/schema.test.d.ts +1 -0
- package/types/src/user/UserStore.d.ts +1 -1
- package/types/src/util/Store.d.ts +45 -0
- package/types/src/util/Store.test.d.ts +1 -0
- package/types/src/y/extensions/AttributionExtension.d.ts +1 -1
- package/types/src/y/extensions/DiffVersioningExtension.d.ts +1 -1
- package/types/src/y/extensions/ForkYDoc.d.ts +1 -5
- package/types/src/y/extensions/index.d.ts +2 -10
- package/types/src/y/versioning/yhub.d.ts +3 -2
- package/types/src/yjs/comments/RESTYjsThreadStore.test.d.ts +1 -0
- package/types/src/yjs/extensions/ForkYDoc.d.ts +1 -5
- package/types/src/yjs/extensions/index.d.ts +1 -5
- package/dist/BlockNoteExtension-B_IEJHS8.js +0 -38
- package/dist/BlockNoteExtension-B_IEJHS8.js.map +0 -1
- package/dist/BlockNoteExtension-M0znTzxP.cjs +0 -2
- package/dist/BlockNoteExtension-M0znTzxP.cjs.map +0 -1
- package/dist/UserStore-QbbPFj0z.js.map +0 -1
- package/dist/blocks-BEJW9OM_.js.map +0 -1
- package/dist/blocks-BPmJglFo.cjs +0 -12
- package/dist/blocks-BPmJglFo.cjs.map +0 -1
- package/dist/en-C5Z4Ag9_.cjs +0 -2
- package/dist/en-C5Z4Ag9_.cjs.map +0 -1
- package/dist/en-CGKXfWma.js.map +0 -1
- package/dist/extensions-AitWbYdJ.cjs +0 -52
- package/dist/extensions-AitWbYdJ.cjs.map +0 -1
- package/dist/extensions-BR5hkAio.js.map +0 -1
- package/dist/src-BHPuOo7W.cjs +0 -21
- package/dist/src-BHPuOo7W.cjs.map +0 -1
- package/dist/src-BUXut68d.js.map +0 -1
- package/src/blocks/Code/shiki.ts +0 -73
- package/src/blocks/File/helpers/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -20
- package/types/src/blocks/Code/shiki.d.ts +0 -4
- package/types/src/blocks/File/helpers/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +0 -6
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { Node } from "@tiptap/core";
|
|
2
2
|
import { ViewMutationRecord } from "prosemirror-view";
|
|
3
|
-
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
4
3
|
import { PropSchema, Props } from "../propTypes.js";
|
|
5
4
|
import { StyleSchema, Styles } from "../styles/types.js";
|
|
5
|
+
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
6
|
+
import {
|
|
7
|
+
Extension,
|
|
8
|
+
ExtensionFactoryInstance,
|
|
9
|
+
} from "../../editor/BlockNoteExtension.js";
|
|
6
10
|
|
|
7
11
|
export type CustomInlineContentConfig = {
|
|
8
12
|
type: string;
|
|
@@ -16,11 +20,35 @@ export type InlineContentConfig = CustomInlineContentConfig | "text" | "link";
|
|
|
16
20
|
// InlineContentImplementation contains the "implementation" info about an InlineContent element
|
|
17
21
|
// such as the functions / Nodes required to render and / or serialize it
|
|
18
22
|
export type InlineContentImplementation<T extends InlineContentConfig> =
|
|
19
|
-
T extends
|
|
20
|
-
?
|
|
21
|
-
: {
|
|
23
|
+
T extends CustomInlineContentConfig
|
|
24
|
+
? {
|
|
22
25
|
meta?: {
|
|
26
|
+
/**
|
|
27
|
+
* Whether the inline content is a {@link https://prosemirror.net/docs/ref/#model.NodeSpec.code} block
|
|
28
|
+
*/
|
|
29
|
+
code?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* When {@link code} is `true`, this can syntax highlight the contents of the block with the result of this callback
|
|
32
|
+
*/
|
|
33
|
+
// Method syntax (rather than an arrow-function property) so its
|
|
34
|
+
// parameter is checked bivariantly, keeping a specific
|
|
35
|
+
// implementation assignable to the generic spec record type.
|
|
36
|
+
highlight?(
|
|
37
|
+
inlineContent: Pick<
|
|
38
|
+
CustomInlineContentFromConfig<T, any>,
|
|
39
|
+
"type" | "props"
|
|
40
|
+
>,
|
|
41
|
+
): string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the inline content is draggable
|
|
44
|
+
*/
|
|
23
45
|
draggable?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Marks the inline content as rendering a preview with an editable
|
|
48
|
+
* source popup, driven by the editor-wide
|
|
49
|
+
* `SourceInlineContentWithPreviewExtension`.
|
|
50
|
+
*/
|
|
51
|
+
hasPreview?: boolean;
|
|
24
52
|
};
|
|
25
53
|
node: Node;
|
|
26
54
|
toExternalHTML?: (
|
|
@@ -43,7 +71,8 @@ export type InlineContentImplementation<T extends InlineContentConfig> =
|
|
|
43
71
|
destroy?: () => void;
|
|
44
72
|
};
|
|
45
73
|
runsBefore?: string[];
|
|
46
|
-
}
|
|
74
|
+
}
|
|
75
|
+
: undefined;
|
|
47
76
|
|
|
48
77
|
export type InlineContentSchemaWithInlineContent<
|
|
49
78
|
IType extends string,
|
|
@@ -57,6 +86,7 @@ export type InlineContentSchemaWithInlineContent<
|
|
|
57
86
|
export type InlineContentSpec<T extends InlineContentConfig> = {
|
|
58
87
|
config: T;
|
|
59
88
|
implementation: InlineContentImplementation<T>;
|
|
89
|
+
extensions?: (Extension | ExtensionFactoryInstance)[];
|
|
60
90
|
};
|
|
61
91
|
|
|
62
92
|
// A Schema contains all the types (Configs) supported in an editor
|
|
@@ -2,15 +2,20 @@ import { NodeView, ViewMutationRecord } from "@tiptap/pm/view";
|
|
|
2
2
|
import { describe, expect, it } from "vite-plus/test";
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
ignoreDarkReaderMutations,
|
|
6
|
+
isDarkReaderMutation,
|
|
7
7
|
} from "./nodeViewMutations.js";
|
|
8
8
|
|
|
9
|
-
function attributeMutation(
|
|
9
|
+
function attributeMutation(
|
|
10
|
+
target: Element,
|
|
11
|
+
attributeName: string,
|
|
12
|
+
oldValue: string | null = null,
|
|
13
|
+
): ViewMutationRecord {
|
|
10
14
|
return {
|
|
11
15
|
type: "attributes",
|
|
12
16
|
target,
|
|
13
|
-
attributeName
|
|
17
|
+
attributeName,
|
|
18
|
+
oldValue,
|
|
14
19
|
} as unknown as ViewMutationRecord;
|
|
15
20
|
}
|
|
16
21
|
|
|
@@ -25,97 +30,117 @@ function childListMutation(target: Node): ViewMutationRecord {
|
|
|
25
30
|
|
|
26
31
|
const selectionMutation = { type: "selection" } as ViewMutationRecord;
|
|
27
32
|
|
|
28
|
-
describe("
|
|
33
|
+
describe("isDarkReaderMutation", () => {
|
|
29
34
|
it("never ignores selection mutations", () => {
|
|
30
|
-
expect(
|
|
31
|
-
expect(
|
|
32
|
-
isNonContentMutation(selectionMutation, document.createElement("div")),
|
|
33
|
-
).toBe(false);
|
|
35
|
+
expect(isDarkReaderMutation(selectionMutation)).toBe(false);
|
|
34
36
|
});
|
|
35
37
|
|
|
36
|
-
it("ignores
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
expect(
|
|
38
|
+
it("ignores the attributes Dark Reader stamps on recoloured elements", () => {
|
|
39
|
+
const span = document.createElement("span");
|
|
40
|
+
span.setAttribute("data-darkreader-inline-bgcolor", "");
|
|
41
|
+
expect(
|
|
42
|
+
isDarkReaderMutation(
|
|
43
|
+
attributeMutation(span, "data-darkreader-inline-bgcolor"),
|
|
44
|
+
),
|
|
45
|
+
).toBe(true);
|
|
40
46
|
});
|
|
41
47
|
|
|
42
|
-
it("ignores
|
|
43
|
-
const contentDOM = document.createElement("div");
|
|
48
|
+
it("ignores inline style writes that add or remove Dark Reader declarations", () => {
|
|
44
49
|
const span = document.createElement("span");
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
expect(isNonContentMutation(attributeMutation(span), contentDOM)).toBe(
|
|
49
|
-
true,
|
|
50
|
+
span.setAttribute(
|
|
51
|
+
"style",
|
|
52
|
+
"color: #f00; --darkreader-inline-color: #ff8080;",
|
|
50
53
|
);
|
|
54
|
+
// Added: the old value had none.
|
|
51
55
|
expect(
|
|
52
|
-
|
|
56
|
+
isDarkReaderMutation(attributeMutation(span, "style", "color: #f00;")),
|
|
53
57
|
).toBe(true);
|
|
54
|
-
});
|
|
55
58
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const textNode = document.createTextNode("hello");
|
|
59
|
-
contentDOM.appendChild(textNode);
|
|
60
|
-
|
|
61
|
-
// childList directly on the content DOM (e.g. a node inserted while typing).
|
|
59
|
+
// Removed (the extension toggled off): only the old value had them.
|
|
60
|
+
span.setAttribute("style", "color: #f00;");
|
|
62
61
|
expect(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
isDarkReaderMutation(
|
|
63
|
+
attributeMutation(
|
|
64
|
+
span,
|
|
65
|
+
"style",
|
|
66
|
+
"color: #f00; --darkreader-inline-color: #ff8080;",
|
|
67
|
+
),
|
|
68
|
+
),
|
|
69
|
+
).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("reads every other attribute mutation", () => {
|
|
73
|
+
const span = document.createElement("span");
|
|
74
|
+
span.setAttribute("style", "color: #f00;");
|
|
75
|
+
expect(isDarkReaderMutation(attributeMutation(span, "style", null))).toBe(
|
|
76
|
+
false,
|
|
77
|
+
);
|
|
78
|
+
expect(isDarkReaderMutation(attributeMutation(span, "class", null))).toBe(
|
|
79
|
+
false,
|
|
80
|
+
);
|
|
81
|
+
expect(isDarkReaderMutation(attributeMutation(span, "data-id", null))).toBe(
|
|
67
82
|
false,
|
|
68
83
|
);
|
|
69
84
|
});
|
|
70
85
|
|
|
71
|
-
it("
|
|
86
|
+
it("reads child list mutations anywhere in the node view", () => {
|
|
72
87
|
const dom = document.createElement("div");
|
|
73
|
-
const contentDOM = document.createElement("
|
|
74
|
-
|
|
75
|
-
dom.append(chrome, contentDOM);
|
|
88
|
+
const contentDOM = document.createElement("p");
|
|
89
|
+
dom.append(document.createElement("button"), contentDOM);
|
|
76
90
|
|
|
77
|
-
expect(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
);
|
|
91
|
+
expect(isDarkReaderMutation(childListMutation(contentDOM))).toBe(false);
|
|
92
|
+
// A browser's native paragraph split on Android and iOS inserts the new
|
|
93
|
+
// paragraph next to the content DOM, not inside it.
|
|
94
|
+
expect(isDarkReaderMutation(childListMutation(dom))).toBe(false);
|
|
81
95
|
});
|
|
82
96
|
});
|
|
83
97
|
|
|
84
|
-
describe("
|
|
85
|
-
it("ignores
|
|
86
|
-
const contentDOM = document.createElement("
|
|
98
|
+
describe("ignoreDarkReaderMutations", () => {
|
|
99
|
+
it("ignores Dark Reader writes while reading everything else", () => {
|
|
100
|
+
const contentDOM = document.createElement("p");
|
|
87
101
|
const span = document.createElement("span");
|
|
102
|
+
span.setAttribute("style", "--darkreader-inline-color: #ff8080;");
|
|
88
103
|
contentDOM.appendChild(span);
|
|
89
104
|
const nodeView: NodeView = {
|
|
90
105
|
dom: document.createElement("div"),
|
|
91
106
|
contentDOM,
|
|
92
107
|
};
|
|
93
108
|
|
|
94
|
-
|
|
109
|
+
ignoreDarkReaderMutations(nodeView);
|
|
95
110
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
111
|
+
expect(nodeView.ignoreMutation!(attributeMutation(span, "style"))).toBe(
|
|
112
|
+
true,
|
|
113
|
+
);
|
|
99
114
|
expect(nodeView.ignoreMutation!(childListMutation(contentDOM))).toBe(false);
|
|
100
|
-
// ...and selection is read.
|
|
101
115
|
expect(nodeView.ignoreMutation!(selectionMutation)).toBe(false);
|
|
102
116
|
});
|
|
103
117
|
|
|
104
|
-
it("
|
|
105
|
-
const
|
|
118
|
+
it("keeps prosemirror-view's default for a node view without a content DOM", () => {
|
|
119
|
+
const dom = document.createElement("div");
|
|
120
|
+
const nodeView: NodeView = { dom };
|
|
121
|
+
|
|
122
|
+
ignoreDarkReaderMutations(nodeView);
|
|
123
|
+
|
|
124
|
+
// Nothing to read back: every mutation but the selection is ignored, as
|
|
125
|
+
// prosemirror-view does when a node view defines no `ignoreMutation`.
|
|
126
|
+
expect(nodeView.ignoreMutation!(attributeMutation(dom, "class"))).toBe(
|
|
127
|
+
true,
|
|
128
|
+
);
|
|
129
|
+
expect(nodeView.ignoreMutation!(childListMutation(dom))).toBe(true);
|
|
130
|
+
expect(nodeView.ignoreMutation!(selectionMutation)).toBe(false);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("still defers to an existing ignoreMutation", () => {
|
|
134
|
+
const contentDOM = document.createElement("p");
|
|
106
135
|
const nodeView: NodeView = {
|
|
107
136
|
dom: document.createElement("div"),
|
|
108
137
|
contentDOM,
|
|
109
|
-
// Pretend this node view wants to ignore all of its
|
|
138
|
+
// Pretend this node view wants to ignore all of its mutations.
|
|
110
139
|
ignoreMutation: () => true,
|
|
111
140
|
};
|
|
112
141
|
|
|
113
|
-
|
|
142
|
+
ignoreDarkReaderMutations(nodeView);
|
|
114
143
|
|
|
115
|
-
// A content mutation the filter would read is still ignored by the
|
|
116
|
-
// original `ignoreMutation`.
|
|
117
144
|
expect(nodeView.ignoreMutation!(childListMutation(contentDOM))).toBe(true);
|
|
118
|
-
// Non-content mutations are ignored by the filter regardless.
|
|
119
|
-
expect(nodeView.ignoreMutation!(attributeMutation(contentDOM))).toBe(true);
|
|
120
145
|
});
|
|
121
146
|
});
|
|
@@ -1,46 +1,49 @@
|
|
|
1
1
|
import { NodeView, ViewMutationRecord } from "@tiptap/pm/view";
|
|
2
2
|
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// the
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (mutation.type
|
|
3
|
+
// Dark Reader recolours a page by rewriting inline styles (every declaration
|
|
4
|
+
// it adds starts with `--darkreader`) and stamping `data-darkreader-*`
|
|
5
|
+
// attributes on the elements it touched. ProseMirror re-reads a node view on
|
|
6
|
+
// any DOM mutation inside it and re-renders it, after which the extension
|
|
7
|
+
// rewrites it again: an endless loop that froze the tab on code blocks and
|
|
8
|
+
// toggles (#2818). Only those writes are ignored. Every other mutation must
|
|
9
|
+
// reach ProseMirror, including a browser's native paragraph split, which lands
|
|
10
|
+
// next to the content DOM on Android and iOS: ignoring it left the split
|
|
11
|
+
// unread and a stray paragraph in the block (#3001).
|
|
12
|
+
export function isDarkReaderMutation(mutation: ViewMutationRecord): boolean {
|
|
13
|
+
if (mutation.type !== "attributes" || !mutation.attributeName) {
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
// Ignore all mutations for nodes without content.
|
|
18
|
-
if (!contentDOM) {
|
|
16
|
+
if (mutation.attributeName.startsWith("data-darkreader")) {
|
|
19
17
|
return true;
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// ProseMirror node's attribute, the change should be made to the ProseMirror node directly,
|
|
24
|
-
// which will trigger a re-render. We don't propagate changes to the DOM back to the node.
|
|
25
|
-
if (mutation.type === "attributes") {
|
|
26
|
-
return true;
|
|
19
|
+
if (mutation.attributeName !== "style") {
|
|
20
|
+
return false;
|
|
27
21
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
const style = (mutation.target as Element).getAttribute("style") ?? "";
|
|
23
|
+
return (
|
|
24
|
+
style.includes("--darkreader") ||
|
|
25
|
+
(mutation.oldValue ?? "").includes("--darkreader")
|
|
26
|
+
);
|
|
32
27
|
}
|
|
33
28
|
|
|
34
|
-
export function
|
|
29
|
+
export function ignoreDarkReaderMutations(nodeView: NodeView): void {
|
|
35
30
|
const originalIgnoreMutation = nodeView.ignoreMutation?.bind(nodeView);
|
|
36
31
|
const contentDOM = nodeView.contentDOM;
|
|
37
32
|
|
|
38
33
|
nodeView.ignoreMutation = (mutation: ViewMutationRecord) => {
|
|
39
|
-
if (
|
|
34
|
+
if (isDarkReaderMutation(mutation)) {
|
|
40
35
|
return true;
|
|
41
36
|
}
|
|
42
37
|
|
|
43
38
|
// Defer to the node view's own `ignoreMutation` for additional filtering.
|
|
44
|
-
|
|
39
|
+
if (originalIgnoreMutation) {
|
|
40
|
+
return originalIgnoreMutation(mutation);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Defining `ignoreMutation` replaces prosemirror-view's default, so keep
|
|
44
|
+
// it: a node view without a content DOM (an image block, say) has nothing
|
|
45
|
+
// to read back, and reading its own DOM changes (the selected-node class,
|
|
46
|
+
// for one) resets a node selection, which broke copying an image.
|
|
47
|
+
return !contentDOM && mutation.type !== "selection";
|
|
45
48
|
};
|
|
46
49
|
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import { afterEach, describe, expect, it } from "vite-plus/test";
|
|
5
|
+
|
|
6
|
+
import { BlockNoteSchema } from "../blocks/BlockNoteSchema.js";
|
|
7
|
+
import {
|
|
8
|
+
defaultBlockSpecs,
|
|
9
|
+
defaultInlineContentSpecs,
|
|
10
|
+
defaultStyleSpecs,
|
|
11
|
+
} from "../blocks/defaultBlocks.js";
|
|
12
|
+
import { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
13
|
+
import { createExtension } from "../editor/BlockNoteExtension.js";
|
|
14
|
+
import { createBlockSpec } from "./blocks/createSpec.js";
|
|
15
|
+
import { createInlineContentSpec } from "./inlineContent/createSpec.js";
|
|
16
|
+
import { createStyleSpec } from "./styles/createSpec.js";
|
|
17
|
+
|
|
18
|
+
const editorsToCleanup: BlockNoteEditor<any, any, any>[] = [];
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
for (const editor of editorsToCleanup) {
|
|
22
|
+
editor.unmount();
|
|
23
|
+
}
|
|
24
|
+
editorsToCleanup.length = 0;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function createMountedEditor(
|
|
28
|
+
options: Parameters<typeof BlockNoteEditor.create>[0],
|
|
29
|
+
) {
|
|
30
|
+
const editor = BlockNoteEditor.create(options);
|
|
31
|
+
editor.mount(document.createElement("div"));
|
|
32
|
+
editorsToCleanup.push(editor);
|
|
33
|
+
return editor;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// A block spec that registers an editor extension, like
|
|
37
|
+
// `@blocknote/xl-multi-column`'s `ColumnBlock` does with its drop handler.
|
|
38
|
+
const CustomBlockExtension = createExtension(() => ({
|
|
39
|
+
key: "customBlockExtension",
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
const createCustomBlockSpec = createBlockSpec(
|
|
43
|
+
{ type: "customBlock", propSchema: {}, content: "none" },
|
|
44
|
+
{ render: () => ({ dom: document.createElement("div") }) },
|
|
45
|
+
[CustomBlockExtension()],
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const customInlineContent = createInlineContentSpec(
|
|
49
|
+
{ type: "customInlineContent", propSchema: {}, content: "none" },
|
|
50
|
+
{ render: () => ({ dom: document.createElement("span") }) },
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const customStyle = createStyleSpec(
|
|
54
|
+
{ type: "customStyle", propSchema: "boolean" },
|
|
55
|
+
{ render: () => ({ dom: document.createElement("span") }) },
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
describe("CustomBlockNoteSchema.extend", () => {
|
|
59
|
+
it("does not mutate the default specs shared by every default schema", () => {
|
|
60
|
+
const extended = BlockNoteSchema.create().extend({
|
|
61
|
+
blockSpecs: { customBlock: createCustomBlockSpec() },
|
|
62
|
+
inlineContentSpecs: { customInlineContent },
|
|
63
|
+
styleSpecs: { customStyle },
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// The extended schema has the added specs...
|
|
67
|
+
expect(extended.blockSchema).toHaveProperty("customBlock");
|
|
68
|
+
expect(extended.inlineContentSchema).toHaveProperty("customInlineContent");
|
|
69
|
+
expect(extended.styleSchema).toHaveProperty("customStyle");
|
|
70
|
+
|
|
71
|
+
// ...the module-level defaults it was created from are untouched...
|
|
72
|
+
expect(defaultBlockSpecs).not.toHaveProperty("customBlock");
|
|
73
|
+
expect(defaultInlineContentSpecs).not.toHaveProperty("customInlineContent");
|
|
74
|
+
expect(defaultStyleSpecs).not.toHaveProperty("customStyle");
|
|
75
|
+
|
|
76
|
+
// ...so a default schema created afterwards doesn't inherit them.
|
|
77
|
+
const fresh = BlockNoteSchema.create();
|
|
78
|
+
expect(fresh.blockSchema).not.toHaveProperty("customBlock");
|
|
79
|
+
expect(fresh.inlineContentSchema).not.toHaveProperty("customInlineContent");
|
|
80
|
+
expect(fresh.styleSchema).not.toHaveProperty("customStyle");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("does not mutate the spec objects passed to `create`", () => {
|
|
84
|
+
const blockSpecs = { paragraph: defaultBlockSpecs.paragraph };
|
|
85
|
+
|
|
86
|
+
BlockNoteSchema.create({ blockSpecs }).extend({
|
|
87
|
+
blockSpecs: { customBlock: createCustomBlockSpec() },
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(Object.keys(blockSpecs)).toEqual(["paragraph"]);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("keeps an extended schema's blocks and their extensions out of later default-schema editors", () => {
|
|
94
|
+
// Regression: extending a default schema used to write the added block
|
|
95
|
+
// specs into the shared default specs, so every editor created afterwards
|
|
96
|
+
// without an explicit schema silently got the extra block types - and the
|
|
97
|
+
// editor extensions they register (e.g. multi-column's drop handler).
|
|
98
|
+
const extendedEditor = createMountedEditor({
|
|
99
|
+
schema: BlockNoteSchema.create().extend({
|
|
100
|
+
blockSpecs: { customBlock: createCustomBlockSpec() },
|
|
101
|
+
}),
|
|
102
|
+
});
|
|
103
|
+
expect(extendedEditor.getExtension(CustomBlockExtension)).toBeDefined();
|
|
104
|
+
|
|
105
|
+
const defaultEditor = createMountedEditor({});
|
|
106
|
+
expect(defaultEditor.schema.blockSchema).not.toHaveProperty("customBlock");
|
|
107
|
+
expect(defaultEditor.pmSchema.nodes).not.toHaveProperty("customBlock");
|
|
108
|
+
expect(defaultEditor.getExtension(CustomBlockExtension)).toBeUndefined();
|
|
109
|
+
});
|
|
110
|
+
});
|
package/src/schema/schema.ts
CHANGED
|
@@ -201,10 +201,19 @@ export class CustomBlockNoteSchema<
|
|
|
201
201
|
[K in keyof AdditionalStyleSpecs]: AdditionalStyleSpecs[K]["config"];
|
|
202
202
|
}
|
|
203
203
|
> {
|
|
204
|
-
// Merge the new specs with existing ones
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
204
|
+
// Merge the new specs with the existing ones into fresh objects. The
|
|
205
|
+
// existing spec objects must not be written to: `BlockNoteSchema.create()`
|
|
206
|
+
// passes the module-level default specs by reference, so mutating them
|
|
207
|
+
// would leak the added specs (and the editor extensions they register) into
|
|
208
|
+
// every default-schema editor created afterwards.
|
|
209
|
+
this.opts = {
|
|
210
|
+
blockSpecs: { ...this.opts.blockSpecs, ...opts.blockSpecs },
|
|
211
|
+
inlineContentSpecs: {
|
|
212
|
+
...this.opts.inlineContentSpecs,
|
|
213
|
+
...opts.inlineContentSpecs,
|
|
214
|
+
},
|
|
215
|
+
styleSpecs: { ...this.opts.styleSpecs, ...opts.styleSpecs },
|
|
216
|
+
};
|
|
208
217
|
|
|
209
218
|
// Reinitialize the block specs with the merged specs
|
|
210
219
|
const {
|
package/src/user/UserStore.ts
CHANGED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vite-plus/test";
|
|
2
|
+
import { Store } from "./Store.js";
|
|
3
|
+
|
|
4
|
+
describe("Store", () => {
|
|
5
|
+
it("updates state from a value", () => {
|
|
6
|
+
const store = new Store({ count: 0 });
|
|
7
|
+
|
|
8
|
+
store.setState({ count: 1 });
|
|
9
|
+
|
|
10
|
+
expect(store.state).toEqual({ count: 1 });
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("updates state from an updater function", () => {
|
|
14
|
+
const store = new Store({ count: 0 });
|
|
15
|
+
|
|
16
|
+
store.setState((prev) => ({ count: prev.count + 1 }));
|
|
17
|
+
|
|
18
|
+
expect(store.state).toEqual({ count: 1 });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("exposes the previous state after an update", () => {
|
|
22
|
+
const store = new Store({ count: 0 });
|
|
23
|
+
|
|
24
|
+
store.setState({ count: 1 });
|
|
25
|
+
expect(store.prevState).toEqual({ count: 0 });
|
|
26
|
+
|
|
27
|
+
store.setState({ count: 2 });
|
|
28
|
+
expect(store.prevState).toEqual({ count: 1 });
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("notifies listeners with the previous and current state", () => {
|
|
32
|
+
const store = new Store({ count: 0 });
|
|
33
|
+
const listener = vi.fn();
|
|
34
|
+
store.subscribe(listener);
|
|
35
|
+
|
|
36
|
+
store.setState({ count: 1 });
|
|
37
|
+
|
|
38
|
+
expect(listener).toHaveBeenCalledTimes(1);
|
|
39
|
+
expect(listener).toHaveBeenCalledWith({
|
|
40
|
+
prevVal: { count: 0 },
|
|
41
|
+
currentVal: { count: 1 },
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("stops notifying after unsubscribing", () => {
|
|
46
|
+
const store = new Store({ count: 0 });
|
|
47
|
+
const listener = vi.fn();
|
|
48
|
+
const unsubscribe = store.subscribe(listener);
|
|
49
|
+
|
|
50
|
+
store.setState({ count: 1 });
|
|
51
|
+
unsubscribe();
|
|
52
|
+
store.setState({ count: 2 });
|
|
53
|
+
|
|
54
|
+
expect(listener).toHaveBeenCalledTimes(1);
|
|
55
|
+
expect(store.state).toEqual({ count: 2 });
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("calls `onUpdate` after the write but before listeners", () => {
|
|
59
|
+
const calls: string[] = [];
|
|
60
|
+
const store: Store<{ count: number }> = new Store(
|
|
61
|
+
{ count: 0 },
|
|
62
|
+
{
|
|
63
|
+
onUpdate() {
|
|
64
|
+
// The new state is already committed by the time `onUpdate` runs, which is
|
|
65
|
+
// what the comments & ShowSelection extensions rely on to dispatch a
|
|
66
|
+
// transaction reflecting it.
|
|
67
|
+
calls.push(`onUpdate:${store.state.count}`);
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
);
|
|
71
|
+
store.subscribe(() => calls.push("listener"));
|
|
72
|
+
|
|
73
|
+
store.setState({ count: 1 });
|
|
74
|
+
|
|
75
|
+
expect(calls).toEqual(["onUpdate:1", "listener"]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("passes the new and previous state to `onUpdate`", () => {
|
|
79
|
+
const onUpdate = vi.fn();
|
|
80
|
+
const store = new Store({ count: 0 }, { onUpdate });
|
|
81
|
+
|
|
82
|
+
store.setState({ count: 1 });
|
|
83
|
+
|
|
84
|
+
expect(onUpdate).toHaveBeenCalledWith({ count: 1 }, { count: 0 });
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("notifies once with the settled state when `onUpdate` writes back", () => {
|
|
88
|
+
const seen: Array<{ prev: number; curr: number }> = [];
|
|
89
|
+
let nested = false;
|
|
90
|
+
const store: Store<{ count: number }> = new Store(
|
|
91
|
+
{ count: 0 },
|
|
92
|
+
{
|
|
93
|
+
onUpdate(state) {
|
|
94
|
+
// A callback that writes back to its own store — e.g. one dispatching a
|
|
95
|
+
// transaction that settles the state. The nested write must be coalesced
|
|
96
|
+
// into the in-progress flush rather than draining on its own.
|
|
97
|
+
if (!nested && state.count === 1) {
|
|
98
|
+
nested = true;
|
|
99
|
+
store.setState({ count: 2 });
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
);
|
|
104
|
+
store.subscribe(({ prevVal, currentVal }) =>
|
|
105
|
+
seen.push({ prev: prevVal.count, curr: currentVal.count }),
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
store.setState({ count: 1 });
|
|
109
|
+
|
|
110
|
+
expect(seen).toEqual([{ prev: 1, curr: 2 }]);
|
|
111
|
+
expect(store.state).toEqual({ count: 2 });
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("flattens re-entrant updates instead of recursing", () => {
|
|
115
|
+
const store = new Store({ count: 0 });
|
|
116
|
+
const seen: number[] = [];
|
|
117
|
+
|
|
118
|
+
store.subscribe(({ currentVal }) => {
|
|
119
|
+
seen.push(currentVal.count);
|
|
120
|
+
// A listener writing back to the store — e.g. one that dispatches a transaction
|
|
121
|
+
// which in turn updates state. This must terminate rather than recurse.
|
|
122
|
+
if (currentVal.count < 3) {
|
|
123
|
+
store.setState({ count: currentVal.count + 1 });
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
store.setState({ count: 1 });
|
|
128
|
+
|
|
129
|
+
expect(seen).toEqual([1, 2, 3]);
|
|
130
|
+
expect(store.state).toEqual({ count: 3 });
|
|
131
|
+
});
|
|
132
|
+
});
|