@blocknote/core 0.53.0 → 0.54.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/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-BEJW9OM_.js → blocks-CzQLehlc.js} +571 -568
- package/dist/blocks-CzQLehlc.js.map +1 -0
- package/dist/blocks-CzkqclGj.cjs +12 -0
- package/dist/blocks-CzkqclGj.cjs.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-CSB9ZvuL.cjs +58 -0
- package/dist/extensions-CSB9ZvuL.cjs.map +1 -0
- package/dist/{extensions-BR5hkAio.js → extensions-DGuhtOgB.js} +662 -427
- package/dist/extensions-DGuhtOgB.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-BkfZVfaO.js} +967 -899
- package/dist/src-BkfZVfaO.js.map +1 -0
- package/dist/src-DM3syMdf.cjs +23 -0
- package/dist/src-DM3syMdf.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 +59 -56
- package/dist/y.js.map +1 -1
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.cjs.map +1 -1
- package/dist/yjs.js +88 -76
- 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/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 -0
- 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/exporter/ExportImage.ts +50 -0
- package/src/exporter/Exporter.test.ts +48 -0
- package/src/exporter/Exporter.ts +46 -12
- 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/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/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/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 +2 -3
- 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 +171 -12
- package/src/schema/inlineContent/internal.ts +21 -2
- package/src/schema/inlineContent/types.ts +35 -5
- 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 +10 -0
- package/src/y/extensions/Versioning.test.ts +20 -7
- 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/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 -0
- 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 +21 -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.d.ts +1 -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/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/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/types/src/blocks/Code/shiki.d.ts +0 -4
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { createExtension } from "../../../../editor/BlockNoteExtension.js";
|
|
2
|
+
import { CodeBlockOptions, getLanguageId } from "../../CodeBlockOptions.js";
|
|
3
|
+
|
|
4
|
+
export const CodeKeyboardShortcutsExtension =
|
|
5
|
+
(options: CodeBlockOptions) => (key: string, blockType: string) =>
|
|
6
|
+
createExtension({
|
|
7
|
+
key,
|
|
8
|
+
keyboardShortcuts: {
|
|
9
|
+
Delete: ({ editor }) => {
|
|
10
|
+
return editor.transact((tr) => {
|
|
11
|
+
const { block } = editor.getTextCursorPosition();
|
|
12
|
+
if (block.type !== blockType) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const { $from } = tr.selection;
|
|
16
|
+
|
|
17
|
+
// When inside empty codeblock, on `DELETE` key press, delete the codeblock
|
|
18
|
+
if (!$from.parent.textContent) {
|
|
19
|
+
editor.removeBlocks([block]);
|
|
20
|
+
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return false;
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
Tab: ({ editor }) => {
|
|
28
|
+
if (options.indentLineWithTab === false) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return editor.transact((tr) => {
|
|
33
|
+
const { block } = editor.getTextCursorPosition();
|
|
34
|
+
if (block.type === blockType) {
|
|
35
|
+
// TODO should probably only tab when at a line start or already tabbed in
|
|
36
|
+
tr.insertText(" ");
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return false;
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
Enter: ({ editor }) => {
|
|
44
|
+
return editor.transact((tr) => {
|
|
45
|
+
const { block, nextBlock } = editor.getTextCursorPosition();
|
|
46
|
+
if (block.type !== blockType) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const { $from } = tr.selection;
|
|
50
|
+
|
|
51
|
+
const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
|
|
52
|
+
const endsWithDoubleNewline =
|
|
53
|
+
$from.parent.textContent.endsWith("\n\n");
|
|
54
|
+
|
|
55
|
+
// The user is trying to exit the code block by pressing enter at the end of the code block
|
|
56
|
+
if (isAtEnd && endsWithDoubleNewline) {
|
|
57
|
+
// Remove the double newline
|
|
58
|
+
tr.delete($from.pos - 2, $from.pos);
|
|
59
|
+
|
|
60
|
+
// If there is a next block, move the cursor to it
|
|
61
|
+
if (nextBlock) {
|
|
62
|
+
editor.setTextCursorPosition(nextBlock, "start");
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// If there is no next block, insert a new paragraph
|
|
67
|
+
const [newBlock] = editor.insertBlocks(
|
|
68
|
+
[{ type: "paragraph" }],
|
|
69
|
+
block,
|
|
70
|
+
"after",
|
|
71
|
+
);
|
|
72
|
+
// Move the cursor to the new block
|
|
73
|
+
editor.setTextCursorPosition(newBlock, "start");
|
|
74
|
+
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
tr.insertText("\n");
|
|
79
|
+
return true;
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
"Shift-Enter": ({ editor }) => {
|
|
83
|
+
return editor.transact(() => {
|
|
84
|
+
const { block } = editor.getTextCursorPosition();
|
|
85
|
+
if (block.type !== blockType) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const [newBlock] = editor.insertBlocks(
|
|
90
|
+
// insert a new paragraph
|
|
91
|
+
[{ type: "paragraph" }],
|
|
92
|
+
block,
|
|
93
|
+
"after",
|
|
94
|
+
);
|
|
95
|
+
// move the cursor to the new block
|
|
96
|
+
editor.setTextCursorPosition(newBlock, "start");
|
|
97
|
+
return true;
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
inputRules: [
|
|
102
|
+
{
|
|
103
|
+
find: /^```(.*?)\s$/,
|
|
104
|
+
replace: ({ match }) => {
|
|
105
|
+
const languageName = match[1].trim();
|
|
106
|
+
const attributes = {
|
|
107
|
+
language: getLanguageId(options, languageName) ?? languageName,
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
type: blockType,
|
|
112
|
+
props: {
|
|
113
|
+
language: attributes.language,
|
|
114
|
+
},
|
|
115
|
+
content: [],
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { DOMParser, Schema } from "@tiptap/pm/model";
|
|
2
|
+
|
|
3
|
+
export const parsePreCode = (el: HTMLElement) => {
|
|
4
|
+
{
|
|
5
|
+
if (el.tagName !== "PRE") {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (
|
|
10
|
+
el.childElementCount !== 1 ||
|
|
11
|
+
el.firstElementChild?.tagName !== "CODE"
|
|
12
|
+
) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const code = el.firstElementChild!;
|
|
17
|
+
const language =
|
|
18
|
+
code.getAttribute("data-language") ||
|
|
19
|
+
code.className
|
|
20
|
+
.split(" ")
|
|
21
|
+
.find((name) => name.startsWith("language-"))
|
|
22
|
+
?.replace("language-", "");
|
|
23
|
+
|
|
24
|
+
return { language };
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const parsePreCodeContent = (
|
|
29
|
+
{
|
|
30
|
+
el,
|
|
31
|
+
schema,
|
|
32
|
+
}: {
|
|
33
|
+
el: HTMLElement;
|
|
34
|
+
schema: Schema;
|
|
35
|
+
},
|
|
36
|
+
blockType: string,
|
|
37
|
+
) => {
|
|
38
|
+
const parser = DOMParser.fromSchema(schema);
|
|
39
|
+
const code = el.firstElementChild!;
|
|
40
|
+
|
|
41
|
+
return parser.parse(code, {
|
|
42
|
+
preserveWhitespace: "full",
|
|
43
|
+
topNode: schema.nodes[blockType].create(),
|
|
44
|
+
}).content;
|
|
45
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
|
|
2
|
+
import type { BlockFromConfig } from "../../../../schema/index.js";
|
|
3
|
+
|
|
4
|
+
// Select dropdown to change the block's language. Assumes `block` has a `language` prop.
|
|
5
|
+
export const createLanguageSelect = (
|
|
6
|
+
block: BlockFromConfig<any, any, any>,
|
|
7
|
+
editor: BlockNoteEditor<any>,
|
|
8
|
+
selectedLanguage: string,
|
|
9
|
+
supportedLanguages: Record<
|
|
10
|
+
string,
|
|
11
|
+
{
|
|
12
|
+
name: string;
|
|
13
|
+
}
|
|
14
|
+
>,
|
|
15
|
+
) => {
|
|
16
|
+
if (!(selectedLanguage in supportedLanguages)) {
|
|
17
|
+
throw new Error(`Language ${selectedLanguage} is not supported.`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const select = document.createElement("select");
|
|
21
|
+
Object.entries(supportedLanguages).forEach(([id, { name }]) => {
|
|
22
|
+
const option = document.createElement("option");
|
|
23
|
+
option.value = id;
|
|
24
|
+
option.text = name;
|
|
25
|
+
select.appendChild(option);
|
|
26
|
+
});
|
|
27
|
+
select.value = selectedLanguage;
|
|
28
|
+
|
|
29
|
+
const handleLanguageChange = (event: Event) => {
|
|
30
|
+
if (!editor.isEditable) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
editor.updateBlock(block.id, {
|
|
35
|
+
props: { language: (event.target as HTMLSelectElement).value },
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
if (editor.isEditable) {
|
|
40
|
+
select.addEventListener("change", handleLanguageChange);
|
|
41
|
+
} else {
|
|
42
|
+
select.disabled = true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const selectWrapper = document.createElement("div");
|
|
46
|
+
selectWrapper.contentEditable = "false";
|
|
47
|
+
selectWrapper.appendChild(select);
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
dom: selectWrapper,
|
|
51
|
+
destroy: () => select.removeEventListener("change", handleLanguageChange),
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Renders the block's inline content as code, alongside a language picker, if multiple languages
|
|
56
|
+
// are supported.
|
|
57
|
+
export const createCodeBlock = (
|
|
58
|
+
block: BlockFromConfig<any, any, any>,
|
|
59
|
+
editor: BlockNoteEditor<any>,
|
|
60
|
+
options?: {
|
|
61
|
+
selectedLanguage: string;
|
|
62
|
+
supportedLanguages: Record<
|
|
63
|
+
string,
|
|
64
|
+
{
|
|
65
|
+
name: string;
|
|
66
|
+
}
|
|
67
|
+
>;
|
|
68
|
+
},
|
|
69
|
+
) => {
|
|
70
|
+
const pre = document.createElement("pre");
|
|
71
|
+
const code = document.createElement("code");
|
|
72
|
+
pre.appendChild(code);
|
|
73
|
+
|
|
74
|
+
const sourceBlock = document.createDocumentFragment();
|
|
75
|
+
|
|
76
|
+
let languageSelect: ReturnType<typeof createLanguageSelect> | undefined =
|
|
77
|
+
undefined;
|
|
78
|
+
if (options && Object.keys(options.supportedLanguages).length > 1) {
|
|
79
|
+
languageSelect = createLanguageSelect(
|
|
80
|
+
block,
|
|
81
|
+
editor,
|
|
82
|
+
options.selectedLanguage,
|
|
83
|
+
options.supportedLanguages,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
sourceBlock.appendChild(languageSelect.dom);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
sourceBlock.appendChild(pre);
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
dom: sourceBlock,
|
|
93
|
+
contentDOM: code,
|
|
94
|
+
destroy: () => {
|
|
95
|
+
languageSelect?.destroy();
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BlockFromConfig } from "../../../../schema/index.js";
|
|
2
|
+
|
|
3
|
+
export const createPreCode = (block: BlockFromConfig<any, any, any>) => {
|
|
4
|
+
const pre = document.createElement("pre");
|
|
5
|
+
const code = document.createElement("code");
|
|
6
|
+
code.className = `language-${block.props.language}`;
|
|
7
|
+
code.dataset.language = block.props.language;
|
|
8
|
+
pre.appendChild(code);
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
dom: pre,
|
|
12
|
+
contentDOM: code,
|
|
13
|
+
};
|
|
14
|
+
};
|
package/src/blocks/index.ts
CHANGED
|
@@ -16,6 +16,9 @@ export * from "./Table/block.js";
|
|
|
16
16
|
export * from "./Video/block.js";
|
|
17
17
|
|
|
18
18
|
export { EMPTY_CELL_HEIGHT, EMPTY_CELL_WIDTH } from "./Table/TableExtension.js";
|
|
19
|
+
export * from "./Code/helpers/parse/parsePreCode.js";
|
|
20
|
+
export * from "./Code/helpers/render/createCodeBlock.js";
|
|
21
|
+
export * from "./Code/helpers/toExternalHTML/createPreCode.js";
|
|
19
22
|
export * from "./ToggleWrapper/createToggleWrapper.js";
|
|
20
23
|
export * from "./File/helpers/uploadToTmpFilesDotOrg_DEV_ONLY.js";
|
|
21
24
|
export * from "./PageBreak/getPageBreakSlashMenuItems.js";
|
|
@@ -117,11 +117,9 @@ export const CommentsExtension = createExtension(
|
|
|
117
117
|
threadPositions: new Map<string, { from: number; to: number }>(),
|
|
118
118
|
},
|
|
119
119
|
{
|
|
120
|
-
onUpdate() {
|
|
120
|
+
onUpdate(state, prevState) {
|
|
121
121
|
// If the selected thread id changed, we need to update the decorations
|
|
122
|
-
if (
|
|
123
|
-
store.state.selectedThreadId !== store.prevState.selectedThreadId
|
|
124
|
-
) {
|
|
122
|
+
if (state.selectedThreadId !== prevState.selectedThreadId) {
|
|
125
123
|
// So, we issue a transaction to update the decorations
|
|
126
124
|
editor.transact((tr) => tr.setMeta(PLUGIN_KEY, true));
|
|
127
125
|
}
|
package/src/editor/Block.css
CHANGED
|
@@ -22,9 +22,27 @@ BASIC STYLES
|
|
|
22
22
|
|
|
23
23
|
.bn-block-content.ProseMirror-selectednode > *,
|
|
24
24
|
/* Case for node view renderers */
|
|
25
|
-
.ProseMirror-selectednode > .bn-block-content >
|
|
25
|
+
.ProseMirror-selectednode > .bn-block-content > *,
|
|
26
|
+
/* Case for blocks/inline content where class is set manually */
|
|
27
|
+
.bn-block-content .ProseMirror-selectednode,
|
|
28
|
+
.bn-inline-content .ProseMirror-selectednode {
|
|
29
|
+
/* Anchor for the `::after` highlight overlay below. */
|
|
30
|
+
position: relative;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* Draws the selection highlight (border + translucent fill) as an overlay on
|
|
34
|
+
top of the element's content */
|
|
35
|
+
.bn-block-content.ProseMirror-selectednode > *::after,
|
|
36
|
+
.ProseMirror-selectednode > .bn-block-content > *::after,
|
|
37
|
+
.bn-block-content .ProseMirror-selectednode::after,
|
|
38
|
+
.bn-inline-content .ProseMirror-selectednode::after {
|
|
39
|
+
content: "";
|
|
40
|
+
position: absolute;
|
|
41
|
+
inset: 0;
|
|
26
42
|
border-radius: 4px;
|
|
27
|
-
|
|
43
|
+
background-color: rgba(100, 160, 255, 0.08);
|
|
44
|
+
box-shadow: inset 0 0 0 4px rgba(100, 160, 255, 0.3);
|
|
45
|
+
pointer-events: none;
|
|
28
46
|
}
|
|
29
47
|
|
|
30
48
|
.bn-block-content::before {
|
|
@@ -468,6 +486,259 @@ NESTED BLOCKS
|
|
|
468
486
|
transition-delay: 0.1s;
|
|
469
487
|
}
|
|
470
488
|
|
|
489
|
+
/* CODE BLOCK PREVIEW */
|
|
490
|
+
.bn-block-content[data-content-type="codeBlock"]:has(
|
|
491
|
+
.bn-preview-with-source-popup
|
|
492
|
+
) {
|
|
493
|
+
background-color: transparent;
|
|
494
|
+
color: inherit;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/* Default to dark theme as the code block has a dark background regardless of theme. */
|
|
498
|
+
.shiki {
|
|
499
|
+
color: var(--shiki-dark);
|
|
500
|
+
}
|
|
501
|
+
.bn-source-block-popup .shiki {
|
|
502
|
+
color: var(--shiki-light);
|
|
503
|
+
}
|
|
504
|
+
.bn-root[data-color-scheme="dark"] .bn-source-block-popup .shiki {
|
|
505
|
+
color: var(--shiki-dark);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
.bn-preview-with-source-popup {
|
|
509
|
+
position: relative;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
.bn-block-content .bn-preview-with-source-popup {
|
|
513
|
+
display: flex;
|
|
514
|
+
padding: 12px;
|
|
515
|
+
width: 100%;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
.bn-inline-content-section .bn-preview-with-source-popup {
|
|
519
|
+
display: inline-block;
|
|
520
|
+
padding: 0;
|
|
521
|
+
width: fit-content;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
.bn-preview-container {
|
|
525
|
+
anchor-name: --bn-source-popup-anchor;
|
|
526
|
+
cursor: pointer;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
.bn-block-content .bn-preview-container {
|
|
530
|
+
overflow: auto;
|
|
531
|
+
width: 100%;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
.bn-inline-content-section .bn-preview-container {
|
|
535
|
+
overflow: visible;
|
|
536
|
+
width: fit-content;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/* Additional right padding for equation numbers. */
|
|
540
|
+
.bn-block-content .bn-preview-container .katex-html:has(> .tag) {
|
|
541
|
+
box-sizing: border-box;
|
|
542
|
+
width: max-content;
|
|
543
|
+
min-width: 100%;
|
|
544
|
+
padding-right: 2.5em;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
.bn-source-block-popup {
|
|
548
|
+
background-color: transparent;
|
|
549
|
+
border: none;
|
|
550
|
+
border-radius: 0;
|
|
551
|
+
box-shadow: none;
|
|
552
|
+
color: transparent;
|
|
553
|
+
height: 0;
|
|
554
|
+
left: 0;
|
|
555
|
+
margin-top: 4px;
|
|
556
|
+
overflow: clip;
|
|
557
|
+
position: absolute;
|
|
558
|
+
top: 100%;
|
|
559
|
+
width: 0;
|
|
560
|
+
z-index: 0;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
.bn-preview-with-source-popup[data-open="true"] .bn-source-block-popup {
|
|
564
|
+
background-color: var(--bn-colors-menu-background);
|
|
565
|
+
border: var(--bn-border);
|
|
566
|
+
border-radius: var(--bn-border-radius-medium);
|
|
567
|
+
box-shadow: var(--bn-shadow-medium);
|
|
568
|
+
color: var(--bn-colors-menu-text);
|
|
569
|
+
height: unset;
|
|
570
|
+
z-index: 1;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
.bn-block-content
|
|
574
|
+
.bn-preview-with-source-popup[data-open="true"]
|
|
575
|
+
.bn-source-block-popup {
|
|
576
|
+
width: 100%;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
.bn-inline-content-section
|
|
580
|
+
.bn-preview-with-source-popup[data-open="true"]
|
|
581
|
+
.bn-source-block-popup {
|
|
582
|
+
width: 300px;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
.bn-code-block-source-popup-body {
|
|
586
|
+
align-items: flex-end;
|
|
587
|
+
display: flex;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
.bn-code-block-source-popup-body > pre {
|
|
591
|
+
align-self: center;
|
|
592
|
+
flex: 1;
|
|
593
|
+
margin: 0;
|
|
594
|
+
max-height: 200px;
|
|
595
|
+
overflow: auto;
|
|
596
|
+
padding: 16px;
|
|
597
|
+
position: relative;
|
|
598
|
+
tab-size: 2;
|
|
599
|
+
white-space: pre;
|
|
600
|
+
width: 0;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
.bn-code-block-source-popup-input-empty::before {
|
|
604
|
+
color: currentColor;
|
|
605
|
+
content: attr(data-placeholder);
|
|
606
|
+
left: 16px;
|
|
607
|
+
opacity: 0.5;
|
|
608
|
+
overflow: hidden;
|
|
609
|
+
pointer-events: none;
|
|
610
|
+
position: absolute;
|
|
611
|
+
right: 16px;
|
|
612
|
+
text-overflow: ellipsis;
|
|
613
|
+
top: 16px;
|
|
614
|
+
white-space: nowrap;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
.bn-code-block-source-error {
|
|
618
|
+
border-top: var(--bn-border);
|
|
619
|
+
color: var(--bn-colors-highlights-red-text);
|
|
620
|
+
font-size: 0.8em;
|
|
621
|
+
padding: 8px 16px;
|
|
622
|
+
white-space: pre-wrap !important;
|
|
623
|
+
font-family: monospace;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
.bn-code-block-source-popup-ok-button-wrapper {
|
|
627
|
+
align-items: flex-end;
|
|
628
|
+
justify-content: flex-end;
|
|
629
|
+
padding: 14px 16px;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
.bn-code-block-source-popup-ok-button {
|
|
633
|
+
align-items: center;
|
|
634
|
+
appearance: none;
|
|
635
|
+
background-color: rgb(37, 99, 235);
|
|
636
|
+
border: none;
|
|
637
|
+
border-radius: var(--bn-border-radius-small);
|
|
638
|
+
color: white;
|
|
639
|
+
cursor: pointer;
|
|
640
|
+
display: flex;
|
|
641
|
+
font-size: 0.8em;
|
|
642
|
+
font-weight: 500;
|
|
643
|
+
gap: 4px;
|
|
644
|
+
padding: 4px 8px;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
.bn-code-block-source-popup-ok-button-icon {
|
|
648
|
+
height: 1.2em;
|
|
649
|
+
width: 1.2em;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
.bn-code-block-source-popup-ok-button:hover {
|
|
653
|
+
background-color: rgb(29, 78, 216);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
.bn-preview-with-source-popup:has(.bn-preview-placeholder) {
|
|
657
|
+
padding: 0;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
.bn-preview-placeholder {
|
|
661
|
+
align-items: center;
|
|
662
|
+
background-color: rgb(242, 241, 238);
|
|
663
|
+
border-radius: 4px;
|
|
664
|
+
color: rgb(95, 91, 92);
|
|
665
|
+
display: flex;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
.bn-block-content .bn-preview-placeholder {
|
|
669
|
+
gap: 10px;
|
|
670
|
+
padding: 12px;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
.bn-inline-content-section .bn-preview-placeholder {
|
|
674
|
+
gap: 4px;
|
|
675
|
+
padding: 0 4px;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
.bn-preview-placeholder:where(.dark, .dark *) {
|
|
679
|
+
background-color: rgb(70, 70, 70);
|
|
680
|
+
color: rgb(190, 190, 190);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
.bn-editor[contenteditable="true"]
|
|
684
|
+
.bn-preview-placeholder:not(.bn-preview-placeholder-error):hover {
|
|
685
|
+
background-color: rgb(225, 225, 225);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
.bn-editor[contenteditable="true"]
|
|
689
|
+
.bn-preview-placeholder:not(.bn-preview-placeholder-error):hover:where(
|
|
690
|
+
.dark,
|
|
691
|
+
.dark *
|
|
692
|
+
) {
|
|
693
|
+
background-color: rgb(90, 90, 90);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
.bn-preview-placeholder-error {
|
|
697
|
+
background-color: var(--bn-colors-highlights-red-background);
|
|
698
|
+
color: var(--bn-colors-highlights-red-text);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
.bn-preview-placeholder-icon {
|
|
702
|
+
align-items: center;
|
|
703
|
+
display: flex;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
.bn-block-content .bn-preview-placeholder-icon {
|
|
707
|
+
height: 24px;
|
|
708
|
+
width: 24px;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
.bn-inline-content-section .bn-preview-placeholder-icon {
|
|
712
|
+
height: 14px;
|
|
713
|
+
width: 14px;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
.bn-preview-placeholder-icon > svg {
|
|
717
|
+
height: 100%;
|
|
718
|
+
width: 100%;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
.bn-preview-placeholder-text {
|
|
722
|
+
margin: 0;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
.bn-block-content .bn-preview-placeholder-text {
|
|
726
|
+
font-size: 0.9rem;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
.bn-inline-content-section .bn-preview-placeholder-text {
|
|
730
|
+
font-size: 0.7rem;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/* Toggled for a single frame while an up/down arrow press is handled, so the
|
|
734
|
+
browser's geometry-based vertical caret movement skips the popup. */
|
|
735
|
+
.bn-suppress-source-popup-caret
|
|
736
|
+
.bn-inline-content-section
|
|
737
|
+
.bn-preview-with-source-popup:not([data-open="true"])
|
|
738
|
+
.bn-source-block-popup {
|
|
739
|
+
visibility: hidden;
|
|
740
|
+
}
|
|
741
|
+
|
|
471
742
|
/* PAGE BREAK */
|
|
472
743
|
.bn-block-content[data-content-type="pageBreak"] > div {
|
|
473
744
|
width: 100%;
|
|
@@ -41,7 +41,11 @@ import "../style.css";
|
|
|
41
41
|
import { mergeCSSClasses } from "../util/browser.js";
|
|
42
42
|
import { EventEmitter } from "../util/EventEmitter.js";
|
|
43
43
|
import type { NoInfer } from "../util/typescript.js";
|
|
44
|
-
import {
|
|
44
|
+
import {
|
|
45
|
+
Extension,
|
|
46
|
+
ExtensionFactory,
|
|
47
|
+
ExtensionFactoryInstance,
|
|
48
|
+
} from "./BlockNoteExtension.js";
|
|
45
49
|
import type { TextCursorPosition } from "./cursorPositionTypes.js";
|
|
46
50
|
import {
|
|
47
51
|
BlockManager,
|
|
@@ -690,9 +694,26 @@ export class BlockNoteEditor<
|
|
|
690
694
|
/**
|
|
691
695
|
* Get an extension from the editor
|
|
692
696
|
*/
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
697
|
+
// Declared as an explicit intersection of the two `ExtensionManager`
|
|
698
|
+
// overloads rather than `ExtensionManager["getExtension"]`: indexed access on
|
|
699
|
+
// an overloaded method collapses the signatures, which widened the factory
|
|
700
|
+
// overload's `ReturnType<ReturnType<T>>` result to `any` (losing e.g. a
|
|
701
|
+
// returned extension's `store` type).
|
|
702
|
+
public getExtension: (<
|
|
703
|
+
const Ext extends Extension | ExtensionFactory = Extension,
|
|
704
|
+
>(
|
|
705
|
+
extension: string,
|
|
706
|
+
) =>
|
|
707
|
+
| (Ext extends Extension
|
|
708
|
+
? Ext
|
|
709
|
+
: Ext extends ExtensionFactory
|
|
710
|
+
? ReturnType<ReturnType<Ext>>
|
|
711
|
+
: never)
|
|
712
|
+
| undefined) &
|
|
713
|
+
(<const T extends ExtensionFactory>(
|
|
714
|
+
extension: T,
|
|
715
|
+
) => ReturnType<ReturnType<T>> | undefined) = ((extension: any) =>
|
|
716
|
+
this._extensionManager.getExtension(extension)) as any;
|
|
696
717
|
|
|
697
718
|
/**
|
|
698
719
|
* Mount the editor to a DOM element.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Store, StoreOptions } from "@tanstack/store";
|
|
2
1
|
import { type AnyExtension } from "@tiptap/core";
|
|
3
2
|
import type { Plugin as ProsemirrorPlugin } from "prosemirror-state";
|
|
4
3
|
import type { PartialBlockNoDefaults } from "../schema/index.js";
|
|
4
|
+
import { Store, StoreOptions } from "../util/Store.js";
|
|
5
5
|
import type { BlockNoteEditor } from "./BlockNoteEditor.js";
|
|
6
6
|
import { originalFactorySymbol } from "./managers/ExtensionManager/symbol.js";
|
|
7
7
|
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
FilePanelExtension,
|
|
16
16
|
FormattingToolbarExtension,
|
|
17
17
|
HistoryExtension,
|
|
18
|
+
InlineContentBoundaryEditExtension,
|
|
18
19
|
LinkToolbarExtension,
|
|
19
20
|
NodeSelectionKeyboardExtension,
|
|
20
21
|
PlaceholderExtension,
|
|
@@ -22,6 +23,8 @@ import {
|
|
|
22
23
|
PreviousBlockTypeExtension,
|
|
23
24
|
ShowSelectionExtension,
|
|
24
25
|
SideMenuExtension,
|
|
26
|
+
SourceBlockWithPreviewExtension,
|
|
27
|
+
SourceInlineContentWithPreviewExtension,
|
|
25
28
|
SuggestionMenu,
|
|
26
29
|
TableHandlesExtension,
|
|
27
30
|
TrailingNodeExtension,
|
|
@@ -167,8 +170,11 @@ export function getDefaultExtensions(
|
|
|
167
170
|
PlaceholderExtension(options),
|
|
168
171
|
ShowSelectionExtension(options),
|
|
169
172
|
SideMenuExtension(options),
|
|
173
|
+
SourceBlockWithPreviewExtension(),
|
|
174
|
+
SourceInlineContentWithPreviewExtension(),
|
|
170
175
|
SuggestionMenu(options),
|
|
171
176
|
HistoryExtension(),
|
|
177
|
+
InlineContentBoundaryEditExtension(),
|
|
172
178
|
PositionMappingExtension(),
|
|
173
179
|
...(options.trailingBlock !== false ? [TrailingNodeExtension()] : []),
|
|
174
180
|
] as ExtensionFactoryInstance[];
|