@blocknote/core 0.49.0 → 0.51.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.
Files changed (147) hide show
  1. package/dist/blocknote.cjs +1 -1
  2. package/dist/blocknote.js +4 -4
  3. package/dist/{blocks-CSfJen16.js → blocks-D0lMxErU.js} +612 -568
  4. package/dist/blocks-D0lMxErU.js.map +1 -0
  5. package/dist/blocks-KyMOxPT3.cjs +11 -0
  6. package/dist/blocks-KyMOxPT3.cjs.map +1 -0
  7. package/dist/blocks.cjs +1 -1
  8. package/dist/blocks.js +2 -2
  9. package/dist/comments.cjs +1 -1
  10. package/dist/comments.cjs.map +1 -1
  11. package/dist/comments.js +17 -14
  12. package/dist/comments.js.map +1 -1
  13. package/dist/{en-QsSI16s5.js → en-B9hMApn4.js} +4 -2
  14. package/dist/en-B9hMApn4.js.map +1 -0
  15. package/dist/{en-C4ykW581.cjs → en-Cj5r8sW_.cjs} +2 -2
  16. package/dist/en-Cj5r8sW_.cjs.map +1 -0
  17. package/dist/{extensions-C3nguvVr.js → extensions-CQFfm5f5.js} +621 -353
  18. package/dist/extensions-CQFfm5f5.js.map +1 -0
  19. package/dist/extensions-Cuw3zOdC.cjs +52 -0
  20. package/dist/extensions-Cuw3zOdC.cjs.map +1 -0
  21. package/dist/extensions.cjs +1 -1
  22. package/dist/extensions.js +3 -3
  23. package/dist/locales.cjs +1 -1
  24. package/dist/locales.cjs.map +1 -1
  25. package/dist/locales.js +68 -24
  26. package/dist/locales.js.map +1 -1
  27. package/dist/{src-DQfz4zLM.js → src-DK_8q1j5.js} +1135 -625
  28. package/dist/src-DK_8q1j5.js.map +1 -0
  29. package/dist/src-_83jmA7A.cjs +21 -0
  30. package/dist/src-_83jmA7A.cjs.map +1 -0
  31. package/dist/style.css +1 -1
  32. package/dist/webpack-stats.json +1 -1
  33. package/dist/yjs.cjs +1 -1
  34. package/dist/yjs.js +8 -8
  35. package/package.json +1 -13
  36. package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +7 -7
  37. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +5 -3
  38. package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +5 -5
  39. package/src/api/blockManipulation/commands/moveBlocks/__snapshots__/moveBlocks.test.ts.snap +2550 -291
  40. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +83 -2
  41. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +103 -42
  42. package/src/api/blockManipulation/commands/nestBlock/__snapshots__/nestBlock.test.ts.snap +0 -143
  43. package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +12 -12
  44. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +5 -3
  45. package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +6 -6
  46. package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +22 -22
  47. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +12 -8
  48. package/src/api/blockManipulation/setupTestEnv.ts +1 -1
  49. package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +2 -6
  50. package/src/api/clipboard/fromClipboard/pasteExtension.ts +7 -2
  51. package/src/api/clipboard/toClipboard/copyExtension.ts +21 -16
  52. package/src/api/exporters/markdown/htmlToMarkdown.ts +813 -0
  53. package/src/api/exporters/markdown/markdownExporter.ts +2 -21
  54. package/src/api/nodeConversions/blockToNode.ts +3 -2
  55. package/src/api/parsers/html/util/__snapshots__/nestedLists.test.ts.snap +122 -107
  56. package/src/api/parsers/html/util/nestedLists.test.ts +1 -12
  57. package/src/api/parsers/markdown/markdownToHtml.ts +1194 -0
  58. package/src/api/parsers/markdown/parseMarkdown.ts +2 -101
  59. package/src/blocks/Audio/block.ts +1 -4
  60. package/src/blocks/Code/block.test.ts +258 -0
  61. package/src/blocks/File/block.ts +1 -4
  62. package/src/blocks/File/helpers/render/createFileBlockWrapper.ts +7 -2
  63. package/src/blocks/Image/block.ts +9 -6
  64. package/src/blocks/ListItem/BulletListItem/block.ts +7 -4
  65. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +3 -4
  66. package/src/blocks/Table/TableExtension.ts +38 -9
  67. package/src/blocks/Video/block.ts +4 -5
  68. package/src/blocks/Video/parseVideoElement.ts +2 -1
  69. package/src/blocks/defaultBlocks.ts +34 -1
  70. package/src/comments/extension.ts +30 -11
  71. package/src/editor/Block.css +22 -18
  72. package/src/editor/BlockNoteEditor.test.ts +10 -4
  73. package/src/editor/BlockNoteEditor.ts +30 -13
  74. package/src/editor/managers/BlockManager.ts +10 -6
  75. package/src/editor/managers/ExtensionManager/extensions.ts +8 -9
  76. package/src/editor/managers/ExtensionManager/index.ts +80 -25
  77. package/src/editor/performance.test.ts +2 -2
  78. package/src/editor/transformPasted.test.ts +295 -0
  79. package/src/editor/transformPasted.ts +77 -0
  80. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +1 -12
  81. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +0 -11
  82. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -1
  83. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -1
  84. package/src/extensions/SideMenu/SideMenu.ts +2 -2
  85. package/src/extensions/SideMenu/dragging.ts +7 -10
  86. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +21 -0
  87. package/src/extensions/TableHandles/TableHandles.ts +2 -0
  88. package/src/extensions/TrailingNode/TrailingNode.ts +124 -65
  89. package/src/extensions/tiptap-extensions/Link/index.ts +1 -1
  90. package/src/extensions/tiptap-extensions/Link/link.ts +49 -18
  91. package/src/i18n/locales/ar.ts +3 -1
  92. package/src/i18n/locales/de.ts +3 -1
  93. package/src/i18n/locales/en.ts +3 -1
  94. package/src/i18n/locales/es.ts +3 -1
  95. package/src/i18n/locales/fa.ts +3 -1
  96. package/src/i18n/locales/fr.ts +4 -2
  97. package/src/i18n/locales/he.ts +3 -1
  98. package/src/i18n/locales/hr.ts +3 -1
  99. package/src/i18n/locales/is.ts +3 -1
  100. package/src/i18n/locales/it.ts +3 -1
  101. package/src/i18n/locales/ja.ts +3 -1
  102. package/src/i18n/locales/ko.ts +3 -1
  103. package/src/i18n/locales/nl.ts +3 -1
  104. package/src/i18n/locales/no.ts +3 -1
  105. package/src/i18n/locales/pl.ts +3 -1
  106. package/src/i18n/locales/pt.ts +3 -1
  107. package/src/i18n/locales/ru.ts +3 -1
  108. package/src/i18n/locales/sk.ts +3 -1
  109. package/src/i18n/locales/uk.ts +3 -1
  110. package/src/i18n/locales/uz.ts +3 -1
  111. package/src/i18n/locales/vi.ts +3 -1
  112. package/src/i18n/locales/zh-tw.ts +3 -1
  113. package/src/i18n/locales/zh.ts +3 -1
  114. package/types/src/api/blockManipulation/commands/moveBlocks/moveBlocks.d.ts +13 -2
  115. package/types/src/api/clipboard/fromClipboard/handleVSCodePaste.d.ts +1 -1
  116. package/types/src/api/exporters/markdown/htmlToMarkdown.d.ts +11 -0
  117. package/types/src/api/parsers/markdown/markdownToHtml.d.ts +5 -0
  118. package/types/src/blocks/Code/block.test.d.ts +1 -0
  119. package/types/src/blocks/Video/block.d.ts +2 -0
  120. package/types/src/blocks/Video/parseVideoElement.d.ts +1 -0
  121. package/types/src/comments/extension.d.ts +2 -1
  122. package/types/src/editor/BlockNoteEditor.d.ts +20 -6
  123. package/types/src/editor/managers/BlockManager.d.ts +8 -4
  124. package/types/src/editor/transformPasted.test.d.ts +1 -0
  125. package/types/src/extensions/TrailingNode/TrailingNode.d.ts +8 -3
  126. package/types/src/extensions/tiptap-extensions/Link/index.d.ts +1 -1
  127. package/types/src/extensions/tiptap-extensions/Link/link.d.ts +12 -0
  128. package/types/src/i18n/locales/en.d.ts +2 -0
  129. package/types/src/i18n/locales/fa.d.ts +2 -0
  130. package/types/src/i18n/locales/sk.d.ts +2 -0
  131. package/dist/blocks-CSfJen16.js.map +0 -1
  132. package/dist/blocks-_lpGWKOa.cjs +0 -11
  133. package/dist/blocks-_lpGWKOa.cjs.map +0 -1
  134. package/dist/en-C4ykW581.cjs.map +0 -1
  135. package/dist/en-QsSI16s5.js.map +0 -1
  136. package/dist/extensions-BfYaEv6F.cjs +0 -2
  137. package/dist/extensions-BfYaEv6F.cjs.map +0 -1
  138. package/dist/extensions-C3nguvVr.js.map +0 -1
  139. package/dist/src-ChTwrMcE.cjs +0 -5
  140. package/dist/src-ChTwrMcE.cjs.map +0 -1
  141. package/dist/src-DQfz4zLM.js.map +0 -1
  142. package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +0 -42
  143. package/src/api/exporters/markdown/util/convertVideoToMarkdownRehypePlugin.ts +0 -19
  144. package/src/api/exporters/markdown/util/removeUnderlinesRehypePlugin.ts +0 -39
  145. package/types/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.d.ts +0 -7
  146. package/types/src/api/exporters/markdown/util/convertVideoToMarkdownRehypePlugin.d.ts +0 -2
  147. package/types/src/api/exporters/markdown/util/removeUnderlinesRehypePlugin.d.ts +0 -6
@@ -1,11 +1,4 @@
1
1
  import { Schema } from "prosemirror-model";
2
- import remarkGfm from "remark-gfm";
3
- import remarkParse from "remark-parse";
4
- import remarkRehype, {
5
- defaultHandlers as remarkRehypeDefaultHandlers,
6
- } from "remark-rehype";
7
- import rehypeStringify from "rehype-stringify";
8
- import { unified } from "unified";
9
2
 
10
3
  import { Block } from "../../../blocks/defaultBlocks.js";
11
4
  import {
@@ -14,102 +7,10 @@ import {
14
7
  StyleSchema,
15
8
  } from "../../../schema/index.js";
16
9
  import { HTMLToBlocks } from "../html/parseHTML.js";
17
- import { isVideoUrl } from "../../../util/string.js";
18
-
19
- // modified version of https://github.com/syntax-tree/mdast-util-to-hast/blob/main/lib/handlers/code.js
20
- // that outputs a data-language attribute instead of a CSS class (e.g.: language-typescript)
21
- function code(state: any, node: any) {
22
- const value = node.value ? node.value : "";
23
- /** @type {Properties} */
24
- const properties: any = {};
25
-
26
- if (node.lang) {
27
- // changed line
28
- properties["data-language"] = node.lang;
29
- }
30
-
31
- // Create `<code>`.
32
- /** @type {Element} */
33
- let result: any = {
34
- type: "element",
35
- tagName: "code",
36
- properties,
37
- children: [{ type: "text", value }],
38
- };
39
-
40
- if (node.meta) {
41
- result.data = { meta: node.meta };
42
- }
43
-
44
- state.patch(node, result);
45
- result = state.applyData(node, result);
46
-
47
- // Create `<pre>`.
48
- result = {
49
- type: "element",
50
- tagName: "pre",
51
- properties: {},
52
- children: [result],
53
- };
54
- state.patch(node, result);
55
- return result;
56
- }
57
-
58
- function video(state: any, node: any) {
59
- const url = String(node?.url || "");
60
- const title = node?.title ? String(node.title) : undefined;
61
-
62
- let result: any = {
63
- type: "element",
64
- tagName: "video",
65
- properties: {
66
- src: url,
67
- "data-name": title,
68
- "data-url": url,
69
- controls: true,
70
- },
71
- children: [],
72
- };
73
- state.patch?.(node, result);
74
- result = state.applyData ? state.applyData(node, result) : result;
75
-
76
- return result;
77
- }
10
+ import { markdownToHtml } from "./markdownToHtml.js";
78
11
 
79
12
  export function markdownToHTML(markdown: string): string {
80
- const htmlString = unified()
81
- .use(remarkParse)
82
- .use(remarkGfm)
83
- .use(remarkRehype, {
84
- handlers: {
85
- ...(remarkRehypeDefaultHandlers as any),
86
- image: (state: any, node: any) => {
87
- const url = String(node?.url || "");
88
-
89
- if (isVideoUrl(url)) {
90
- return video(state, node);
91
- } else {
92
- return remarkRehypeDefaultHandlers.image(state, node);
93
- }
94
- },
95
- code,
96
- blockquote: (state: any, node: any) => {
97
- const result = {
98
- type: "element",
99
- tagName: "blockquote",
100
- properties: {},
101
- // The only difference from the original is that we don't wrap the children with line endings
102
- children: state.wrap(state.all(node), false),
103
- };
104
- state.patch(node, result);
105
- return state.applyData(node, result);
106
- },
107
- },
108
- })
109
- .use(rehypeStringify)
110
- .processSync(markdown);
111
-
112
- return htmlString.value as string;
13
+ return markdownToHtml(markdown);
113
14
  }
114
15
 
115
16
  export function markdownToBlocks<
@@ -129,11 +129,8 @@ export const audioToExternalHTML =
129
129
  >,
130
130
  ) => {
131
131
  if (!block.props.url) {
132
- const div = document.createElement("p");
133
- div.textContent = "Add audio";
134
-
135
132
  return {
136
- dom: div,
133
+ dom: document.createElement("audio"),
137
134
  };
138
135
  }
139
136
 
@@ -0,0 +1,258 @@
1
+ import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
2
+ import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
3
+ import type { PartialBlock } from "../defaultBlocks.js";
4
+ import { getLanguageId, type CodeBlockOptions } from "./block.js";
5
+
6
+ /**
7
+ * @vitest-environment jsdom
8
+ */
9
+
10
+ /**
11
+ * Simulate typing text into the editor at the current cursor position.
12
+ * This triggers input rules by calling the view's handleTextInput prop,
13
+ * which is how ProseMirror processes keyboard text input.
14
+ */
15
+ function simulateTextInput(editor: BlockNoteEditor, text: string) {
16
+ const view = editor.prosemirrorView;
17
+ const { from, to } = view.state.selection;
18
+ const deflt = () => view.state.tr.insertText(text, from, to);
19
+ const handled = view.someProp("handleTextInput", (f) =>
20
+ f(view, from, to, text, deflt),
21
+ );
22
+ if (!handled) {
23
+ view.dispatch(deflt());
24
+ }
25
+ }
26
+
27
+ function typeString(editor: BlockNoteEditor, str: string) {
28
+ for (const char of str) {
29
+ simulateTextInput(editor, char);
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Simulate a keyboard shortcut by invoking the view's handleKeyDown prop,
35
+ * which is how ProseMirror routes keymap-based handlers like Enter.
36
+ */
37
+ function pressKey(editor: BlockNoteEditor, key: string) {
38
+ const view = editor.prosemirrorView;
39
+ const event = new KeyboardEvent("keydown", { key });
40
+ view.someProp("handleKeyDown", (f) => f(view, event));
41
+ }
42
+
43
+ describe("Code block input rule", () => {
44
+ let editor: BlockNoteEditor;
45
+ const div = document.createElement("div");
46
+
47
+ beforeAll(() => {
48
+ editor = BlockNoteEditor.create();
49
+ editor.mount(div);
50
+ });
51
+
52
+ afterAll(() => {
53
+ editor._tiptapEditor.destroy();
54
+ editor = undefined as any;
55
+ });
56
+
57
+ beforeEach(() => {
58
+ const testDoc: PartialBlock[] = [
59
+ {
60
+ id: "test-paragraph",
61
+ type: "paragraph",
62
+ content: "",
63
+ },
64
+ ];
65
+ editor.replaceBlocks(editor.document, testDoc);
66
+ editor.setTextCursorPosition("test-paragraph", "start");
67
+ });
68
+
69
+ it("converts ```ts + space into a codeBlock", () => {
70
+ typeString(editor, "```ts ");
71
+
72
+ const block = editor.document[0];
73
+ expect(block.type).toBe("codeBlock");
74
+ // Without supportedLanguages configured, the raw alias is used
75
+ expect((block.props as any).language).toBe("ts");
76
+ });
77
+
78
+ it("converts ``` + space into a codeBlock with empty language", () => {
79
+ typeString(editor, "``` ");
80
+
81
+ const block = editor.document[0];
82
+ expect(block.type).toBe("codeBlock");
83
+ expect((block.props as any).language).toBe("");
84
+ });
85
+
86
+ it("converts ```javascript + space into a codeBlock", () => {
87
+ typeString(editor, "```javascript ");
88
+
89
+ const block = editor.document[0];
90
+ expect(block.type).toBe("codeBlock");
91
+ expect((block.props as any).language).toBe("javascript");
92
+ });
93
+
94
+ it("does not trigger input rule without trailing space", () => {
95
+ typeString(editor, "```ts");
96
+
97
+ const block = editor.document[0];
98
+ expect(block.type).toBe("paragraph");
99
+ });
100
+
101
+ it("does not trigger with only two backticks", () => {
102
+ typeString(editor, "``ts ");
103
+
104
+ const block = editor.document[0];
105
+ expect(block.type).toBe("paragraph");
106
+ });
107
+
108
+ it("does not trigger in non-empty paragraph with preceding text", () => {
109
+ typeString(editor, "some text ```ts ");
110
+
111
+ const block = editor.document[0];
112
+ // The ^ anchor in the regex means it only triggers at the start of a block
113
+ expect(block.type).toBe("paragraph");
114
+ });
115
+
116
+ it("code block content is empty after conversion", () => {
117
+ typeString(editor, "```ts ");
118
+
119
+ const block = editor.document[0];
120
+ expect(block.type).toBe("codeBlock");
121
+ expect(block.content).toEqual([]);
122
+ });
123
+
124
+ it("converts ```ts + Enter into a codeBlock", () => {
125
+ typeString(editor, "```ts");
126
+ pressKey(editor, "Enter");
127
+
128
+ const block = editor.document[0];
129
+ expect(block.type).toBe("codeBlock");
130
+ expect((block.props as any).language).toBe("ts");
131
+ expect(block.content).toEqual([]);
132
+ });
133
+
134
+ it("converts ``` + Enter into a codeBlock with empty language", () => {
135
+ typeString(editor, "```");
136
+ pressKey(editor, "Enter");
137
+
138
+ const block = editor.document[0];
139
+ expect(block.type).toBe("codeBlock");
140
+ expect((block.props as any).language).toBe("");
141
+ });
142
+
143
+ it("converts ```javascript + Enter into a codeBlock", () => {
144
+ typeString(editor, "```javascript");
145
+ pressKey(editor, "Enter");
146
+
147
+ const block = editor.document[0];
148
+ expect(block.type).toBe("codeBlock");
149
+ expect((block.props as any).language).toBe("javascript");
150
+ });
151
+
152
+ it("does not trigger Enter conversion in non-empty paragraph with preceding text", () => {
153
+ typeString(editor, "some text ```ts");
154
+ pressKey(editor, "Enter");
155
+
156
+ const block = editor.document[0];
157
+ expect(block.type).toBe("paragraph");
158
+ });
159
+
160
+ it("does not trigger Enter conversion with only two backticks", () => {
161
+ typeString(editor, "``ts");
162
+ pressKey(editor, "Enter");
163
+
164
+ const block = editor.document[0];
165
+ expect(block.type).toBe("paragraph");
166
+ });
167
+
168
+ it("places cursor inside the new code block after space conversion", () => {
169
+ typeString(editor, "```ts ");
170
+
171
+ const block = editor.document[0];
172
+ expect(block.type).toBe("codeBlock");
173
+
174
+ const { block: cursorBlock } = editor.getTextCursorPosition();
175
+ expect(cursorBlock.id).toBe(block.id);
176
+
177
+ // Typing should now go into the code block, not after it.
178
+ typeString(editor, "hello");
179
+ const after = editor.document[0];
180
+ expect(after.type).toBe("codeBlock");
181
+ expect(after.id).toBe(block.id);
182
+ expect((after.content as Array<{ type: string; text: string }>)[0].text).toBe(
183
+ "hello",
184
+ );
185
+ });
186
+
187
+ it("places cursor inside the new code block after Enter conversion", () => {
188
+ typeString(editor, "```ts");
189
+ pressKey(editor, "Enter");
190
+
191
+ const block = editor.document[0];
192
+ expect(block.type).toBe("codeBlock");
193
+
194
+ const { block: cursorBlock } = editor.getTextCursorPosition();
195
+ expect(cursorBlock.id).toBe(block.id);
196
+
197
+ typeString(editor, "world");
198
+ const after = editor.document[0];
199
+ expect(after.type).toBe("codeBlock");
200
+ expect(after.id).toBe(block.id);
201
+ expect((after.content as Array<{ type: string; text: string }>)[0].text).toBe(
202
+ "world",
203
+ );
204
+ });
205
+
206
+ it("Enter inside an existing code block does not retrigger conversion", () => {
207
+ typeString(editor, "```ts ");
208
+
209
+ const block = editor.document[0];
210
+ expect(block.type).toBe("codeBlock");
211
+
212
+ typeString(editor, "```js");
213
+ pressKey(editor, "Enter");
214
+
215
+ // Enter inside a code block should insert a newline, not convert again.
216
+ const after = editor.document[0];
217
+ expect(after.type).toBe("codeBlock");
218
+ expect((after.props as any).language).toBe("ts");
219
+ });
220
+ });
221
+
222
+ describe("getLanguageId", () => {
223
+ const options: CodeBlockOptions = {
224
+ supportedLanguages: {
225
+ typescript: {
226
+ name: "TypeScript",
227
+ aliases: ["ts", "typescript"],
228
+ },
229
+ javascript: {
230
+ name: "JavaScript",
231
+ aliases: ["js", "javascript"],
232
+ },
233
+ python: {
234
+ name: "Python",
235
+ aliases: ["py", "python"],
236
+ },
237
+ },
238
+ };
239
+
240
+ it("resolves alias to language id", () => {
241
+ expect(getLanguageId(options, "ts")).toBe("typescript");
242
+ expect(getLanguageId(options, "js")).toBe("javascript");
243
+ expect(getLanguageId(options, "py")).toBe("python");
244
+ });
245
+
246
+ it("resolves language id directly", () => {
247
+ expect(getLanguageId(options, "typescript")).toBe("typescript");
248
+ expect(getLanguageId(options, "javascript")).toBe("javascript");
249
+ });
250
+
251
+ it("returns undefined for unknown language", () => {
252
+ expect(getLanguageId(options, "unknown")).toBeUndefined();
253
+ });
254
+
255
+ it("returns undefined with no supportedLanguages", () => {
256
+ expect(getLanguageId({}, "ts")).toBeUndefined();
257
+ });
258
+ });
@@ -75,11 +75,8 @@ export const createFileBlockSpec = createBlockSpec(createFileBlockConfig, {
75
75
  },
76
76
  toExternalHTML(block) {
77
77
  if (!block.props.url) {
78
- const div = document.createElement("p");
79
- div.textContent = "Add file";
80
-
81
78
  return {
82
- dom: div,
79
+ dom: document.createElement("embed"),
83
80
  };
84
81
  }
85
82
 
@@ -26,7 +26,12 @@ export const createFileBlockWrapper = (
26
26
  element?: { dom: HTMLElement; destroy?: () => void },
27
27
  buttonIcon?: HTMLElement,
28
28
  ) => {
29
- const wrapper = document.createElement("div");
29
+ // Use a <figure>/<figcaption> when the block has a caption, so the caption
30
+ // is semantically associated with its content for assistive tech. Falls back
31
+ // to a plain <div> when there is no caption (or the file has not been
32
+ // uploaded yet, since the upload UI never shows the caption).
33
+ const useFigure = block.props.url !== "" && !!block.props.caption;
34
+ const wrapper = document.createElement(useFigure ? "figure" : "div");
30
35
  wrapper.className = "bn-file-block-content-wrapper";
31
36
 
32
37
  // Show the add file button if the file has not been uploaded yet. Change to
@@ -73,7 +78,7 @@ export const createFileBlockWrapper = (
73
78
 
74
79
  // Show the caption if there is one.
75
80
  if (block.props.caption) {
76
- const caption = document.createElement("p");
81
+ const caption = document.createElement("figcaption");
77
82
  caption.className = "bn-file-caption";
78
83
  caption.textContent = block.props.caption;
79
84
  wrapper.appendChild(caption);
@@ -116,9 +116,15 @@ export const imageRender =
116
116
  image.src = block.props.url;
117
117
  }
118
118
 
119
- image.alt = block.props.name || block.props.caption || "BlockNote image";
119
+ // alt describes image content (per WCAG H86); figcaption (when present)
120
+ // is the contextual caption. Fall back to "" so unlabelled images are
121
+ // marked decorative rather than getting a noisy generic fallback.
122
+ image.alt = block.props.name || "";
120
123
  image.contentEditable = "false";
121
124
  image.draggable = false;
125
+ if (block.props.previewWidth) {
126
+ image.width = block.props.previewWidth;
127
+ }
122
128
  imageWrapper.appendChild(image);
123
129
 
124
130
  return createResizableFileBlockWrapper(
@@ -141,11 +147,8 @@ export const imageToExternalHTML =
141
147
  >,
142
148
  ) => {
143
149
  if (!block.props.url) {
144
- const div = document.createElement("p");
145
- div.textContent = "Add image";
146
-
147
150
  return {
148
- dom: div,
151
+ dom: document.createElement("img"),
149
152
  };
150
153
  }
151
154
 
@@ -153,7 +156,7 @@ export const imageToExternalHTML =
153
156
  if (block.props.showPreview) {
154
157
  image = document.createElement("img");
155
158
  image.src = block.props.url;
156
- image.alt = block.props.name || block.props.caption || "BlockNote image";
159
+ image.alt = block.props.name || "";
157
160
  if (block.props.previewWidth) {
158
161
  image.width = block.props.previewWidth;
159
162
  }
@@ -37,17 +37,20 @@ export const createBulletListItemBlockSpec = createBlockSpec(
37
37
 
38
38
  const parent = element.parentElement;
39
39
 
40
- if (parent === null) {
41
- return undefined;
42
- }
43
-
44
40
  if (
41
+ parent === null ||
45
42
  parent.tagName === "UL" ||
46
43
  (parent.tagName === "DIV" && parent.parentElement?.tagName === "UL")
47
44
  ) {
48
45
  return parseDefaultProps(element);
49
46
  }
50
47
 
48
+ // Orphan `<li>` (no <ul>/<ol> ancestor) — match as bulletListItem so
49
+ // pasting bare `<li>` HTML doesn't fall back to a paragraph.
50
+ if (!element.closest("ul, ol")) {
51
+ return parseDefaultProps(element);
52
+ }
53
+
51
54
  return undefined;
52
55
  },
53
56
  // As `li` elements can contain multiple paragraphs, we need to merge their contents
@@ -135,10 +135,9 @@ function getDecorations(
135
135
  // Find the start of the first change to limit traversal scope.
136
136
  // We only need to check from the change point forward, since earlier
137
137
  // blocks are unaffected and their mapped decorations remain correct.
138
- const range = tr.changedRange();
139
- if (!range) {
140
- return { decorations: nextDecorationSet };
141
- }
138
+ // On init (no steps), changedRange() returns null — fall back to a
139
+ // full scan so initial content gets indexed.
140
+ const range = tr.changedRange() ?? { from: 0, to: tr.doc.nodeSize - 2 };
142
141
  const decorationsToAdd = [] as Deco[];
143
142
 
144
143
  // Track blockGroups where we've verified a decoration match past the
@@ -1,5 +1,14 @@
1
1
  import { callOrReturn, Extension, getExtensionField } from "@tiptap/core";
2
- import { columnResizing, goToNextCell, tableEditing } from "prosemirror-tables";
2
+ import { TextSelection } from "prosemirror-state";
3
+ import {
4
+ columnResizing,
5
+ goToNextCell,
6
+ isInTable,
7
+ moveCellForward,
8
+ nextCell,
9
+ selectionCell,
10
+ tableEditing,
11
+ } from "prosemirror-tables";
3
12
 
4
13
  export const RESIZE_MIN_WIDTH = 35;
5
14
  export const EMPTY_CELL_WIDTH = 120;
@@ -24,19 +33,39 @@ export const TableExtension = Extension.create({
24
33
 
25
34
  addKeyboardShortcuts() {
26
35
  return {
27
- // Makes enter create a new line within the cell.
36
+ // Moves the selection to the cell below.
28
37
  Enter: () => {
29
38
  if (
30
- this.editor.state.selection.empty &&
31
- this.editor.state.selection.$head.parent.type.name ===
32
- "tableParagraph"
39
+ this.editor.state.selection.$head.parent.type.name !==
40
+ "tableParagraph"
33
41
  ) {
34
- this.editor.commands.insertContent({ type: "hardBreak" });
35
-
36
- return true;
42
+ return false;
37
43
  }
38
44
 
39
- return false;
45
+ return this.editor.commands.command(({ state, dispatch }) => {
46
+ if (!isInTable(state)) {
47
+ return false;
48
+ }
49
+
50
+ const $cell = selectionCell(state);
51
+ const $nextCell = nextCell($cell, "vert", 1);
52
+
53
+ if (!$nextCell) {
54
+ return false;
55
+ }
56
+
57
+ if (dispatch) {
58
+ dispatch(
59
+ state.tr
60
+ .setSelection(
61
+ TextSelection.between($nextCell, moveCellForward($nextCell)),
62
+ )
63
+ .scrollIntoView(),
64
+ );
65
+ }
66
+
67
+ return true;
68
+ });
40
69
  },
41
70
  // Ensures that backspace won't delete the table if the text cursor is at
42
71
  // the start of a cell and the selection is empty.
@@ -92,7 +92,9 @@ export const createVideoBlockSpec = createBlockSpec(
92
92
  video.controls = true;
93
93
  video.contentEditable = "false";
94
94
  video.draggable = false;
95
- video.width = block.props.previewWidth;
95
+ if (block.props.previewWidth) {
96
+ video.width = block.props.previewWidth;
97
+ }
96
98
  videoWrapper.appendChild(video);
97
99
 
98
100
  return createResizableFileBlockWrapper(
@@ -105,11 +107,8 @@ export const createVideoBlockSpec = createBlockSpec(
105
107
  },
106
108
  toExternalHTML(block) {
107
109
  if (!block.props.url) {
108
- const div = document.createElement("p");
109
- div.textContent = "Add video";
110
-
111
110
  return {
112
- dom: div,
111
+ dom: document.createElement("video"),
113
112
  };
114
113
  }
115
114
 
@@ -1,6 +1,7 @@
1
1
  export const parseVideoElement = (videoElement: HTMLVideoElement) => {
2
2
  const url = videoElement.src || undefined;
3
3
  const previewWidth = videoElement.width || undefined;
4
+ const name = videoElement.getAttribute("data-name") || undefined;
4
5
 
5
- return { url, previewWidth };
6
+ return { url, previewWidth, name };
6
7
  };
@@ -1,3 +1,4 @@
1
+ import { InputRule, markInputRule } from "@tiptap/core";
1
2
  import Bold from "@tiptap/extension-bold";
2
3
  import Code from "@tiptap/extension-code";
3
4
  import Italic from "@tiptap/extension-italic";
@@ -136,7 +137,39 @@ export const defaultStyleSpecs = {
136
137
  italic: createStyleSpecFromTipTapMark(Italic, "boolean"),
137
138
  underline: createStyleSpecFromTipTapMark(Underline, "boolean"),
138
139
  strike: createStyleSpecFromTipTapMark(Strike, "boolean"),
139
- code: createStyleSpecFromTipTapMark(Code, "boolean"),
140
+ code: createStyleSpecFromTipTapMark(
141
+ Code.extend({
142
+ addInputRules() {
143
+ return [
144
+ // Matches any string that starts with a backtick, ends with a
145
+ // backtick, and has any non-backtick characters in between. Copied
146
+ // from original input rule:
147
+ // https://github.com/ueberdosis/tiptap/blob/c27661c148cdbea9e1c80107e10d0a9d1775c4ec/packages/extension-code/src/code.ts#L116
148
+ markInputRule({
149
+ find: /(^|[^`])`([^`]+)`(?!`)$/,
150
+ type: this.type,
151
+ }),
152
+ // Extends the Code mark with an extra input rule that fires when a space is
153
+ // typed after the closing backtick. The default rule only fires when typing
154
+ // the closing backtick itself, so it misses the case where the user adds
155
+ // both backticks first, then writes content between them.
156
+ new InputRule({
157
+ find: /(^|[^`])`([^`]+)`(?!`) $/,
158
+ handler: ({ state, range, match }) => {
159
+ const { tr, schema } = state;
160
+ const leadingChar = match[1];
161
+ const content = match[2];
162
+ tr.replaceWith(range.from + leadingChar.length, range.to, [
163
+ schema.text(content, [this.type.create()]),
164
+ schema.text(" "),
165
+ ]);
166
+ },
167
+ }),
168
+ ];
169
+ },
170
+ }),
171
+ "boolean",
172
+ ),
140
173
  textColor: TextColor,
141
174
  backgroundColor: BackgroundColor,
142
175
  } satisfies StyleSpecs;