@blocknote/core 0.13.2 → 0.13.4

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 (163) hide show
  1. package/dist/blocknote.js +5730 -2891
  2. package/dist/blocknote.js.map +1 -1
  3. package/dist/blocknote.umd.cjs +7 -7
  4. package/dist/blocknote.umd.cjs.map +1 -1
  5. package/dist/style.css +1 -1
  6. package/dist/webpack-stats.json +1 -1
  7. package/package.json +2 -2
  8. package/src/api/exporters/html/__snapshots__/file/basic/external.html +1 -0
  9. package/src/api/exporters/html/__snapshots__/file/basic/internal.html +1 -0
  10. package/src/api/exporters/html/__snapshots__/file/button/external.html +1 -0
  11. package/src/api/exporters/html/__snapshots__/file/button/internal.html +1 -0
  12. package/src/api/exporters/html/__snapshots__/file/nested/external.html +1 -0
  13. package/src/api/exporters/html/__snapshots__/file/nested/internal.html +1 -0
  14. package/src/api/exporters/html/__snapshots__/file/noCaption/external.html +1 -0
  15. package/src/api/exporters/html/__snapshots__/file/noCaption/internal.html +1 -0
  16. package/src/api/exporters/html/__snapshots__/file/noName/external.html +1 -0
  17. package/src/api/exporters/html/__snapshots__/file/noName/internal.html +1 -0
  18. package/src/api/exporters/html/__snapshots__/image/basic/external.html +1 -1
  19. package/src/api/exporters/html/__snapshots__/image/basic/internal.html +1 -1
  20. package/src/api/exporters/html/__snapshots__/image/button/external.html +1 -1
  21. package/src/api/exporters/html/__snapshots__/image/button/internal.html +1 -1
  22. package/src/api/exporters/html/__snapshots__/image/nested/external.html +1 -1
  23. package/src/api/exporters/html/__snapshots__/image/nested/internal.html +1 -1
  24. package/src/api/exporters/html/__snapshots__/image/noCaption/external.html +1 -0
  25. package/src/api/exporters/html/__snapshots__/image/noCaption/internal.html +1 -0
  26. package/src/api/exporters/html/__snapshots__/image/noName/external.html +1 -0
  27. package/src/api/exporters/html/__snapshots__/image/noName/internal.html +1 -0
  28. package/src/api/exporters/html/__snapshots__/image/noPreview/external.html +1 -0
  29. package/src/api/exporters/html/__snapshots__/image/noPreview/internal.html +1 -0
  30. package/src/api/exporters/html/__snapshots__/lists/basic/external.html +1 -0
  31. package/src/api/exporters/html/__snapshots__/lists/basic/internal.html +1 -0
  32. package/src/api/exporters/html/__snapshots__/lists/nested/external.html +1 -0
  33. package/src/api/exporters/html/__snapshots__/lists/nested/internal.html +1 -0
  34. package/src/api/exporters/html/__snapshots__/simpleFile/basic/external.html +1 -0
  35. package/src/api/exporters/html/__snapshots__/simpleFile/basic/internal.html +1 -0
  36. package/src/api/exporters/html/__snapshots__/simpleFile/button/external.html +1 -0
  37. package/src/api/exporters/html/__snapshots__/simpleFile/button/internal.html +1 -0
  38. package/src/api/exporters/html/__snapshots__/simpleFile/nested/external.html +1 -0
  39. package/src/api/exporters/html/__snapshots__/simpleFile/nested/internal.html +1 -0
  40. package/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html +1 -1
  41. package/src/api/exporters/html/__snapshots__/simpleImage/basic/internal.html +1 -1
  42. package/src/api/exporters/html/__snapshots__/simpleImage/button/external.html +1 -1
  43. package/src/api/exporters/html/__snapshots__/simpleImage/button/internal.html +1 -1
  44. package/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html +1 -1
  45. package/src/api/exporters/html/__snapshots__/simpleImage/nested/internal.html +1 -1
  46. package/src/api/exporters/html/__snapshots__/simpleImage/noCaption/external.html +1 -0
  47. package/src/api/exporters/html/__snapshots__/simpleImage/noCaption/internal.html +1 -0
  48. package/src/api/exporters/html/__snapshots__/simpleImage/noName/external.html +1 -0
  49. package/src/api/exporters/html/__snapshots__/simpleImage/noName/internal.html +1 -0
  50. package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/external.html +1 -0
  51. package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/internal.html +1 -0
  52. package/src/api/exporters/html/externalHTMLExporter.ts +4 -3
  53. package/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts +1 -1
  54. package/src/api/exporters/markdown/__snapshots__/file/basic/markdown.md +3 -0
  55. package/src/api/exporters/markdown/__snapshots__/file/button/markdown.md +1 -0
  56. package/src/api/exporters/markdown/__snapshots__/file/nested/markdown.md +7 -0
  57. package/src/api/exporters/markdown/__snapshots__/file/noCaption/markdown.md +1 -0
  58. package/src/api/exporters/markdown/__snapshots__/file/noName/markdown.md +3 -0
  59. package/src/api/exporters/markdown/__snapshots__/image/basic/markdown.md +1 -1
  60. package/src/api/exporters/markdown/__snapshots__/image/button/markdown.md +1 -1
  61. package/src/api/exporters/markdown/__snapshots__/image/nested/markdown.md +2 -2
  62. package/src/api/exporters/markdown/__snapshots__/image/noCaption/markdown.md +1 -0
  63. package/src/api/exporters/markdown/__snapshots__/image/noName/markdown.md +3 -0
  64. package/src/api/exporters/markdown/__snapshots__/image/noPreview/markdown.md +3 -0
  65. package/src/api/exporters/markdown/__snapshots__/lists/basic/markdown.md +8 -0
  66. package/src/api/exporters/markdown/__snapshots__/lists/nested/markdown.md +10 -0
  67. package/src/api/exporters/markdown/__snapshots__/simpleFile/basic/markdown.md +3 -0
  68. package/src/api/exporters/markdown/__snapshots__/simpleFile/button/markdown.md +1 -0
  69. package/src/api/exporters/markdown/__snapshots__/simpleFile/nested/markdown.md +7 -0
  70. package/src/api/exporters/markdown/__snapshots__/simpleImage/basic/markdown.md +3 -1
  71. package/src/api/exporters/markdown/__snapshots__/simpleImage/button/markdown.md +1 -0
  72. package/src/api/exporters/markdown/__snapshots__/simpleImage/nested/markdown.md +6 -2
  73. package/src/api/exporters/markdown/__snapshots__/simpleImage/noCaption/markdown.md +1 -0
  74. package/src/api/exporters/markdown/__snapshots__/simpleImage/noName/markdown.md +3 -0
  75. package/src/api/exporters/markdown/__snapshots__/simpleImage/noPreview/markdown.md +3 -0
  76. package/src/api/exporters/markdown/markdownExporter.ts +2 -0
  77. package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +42 -0
  78. package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +262 -4
  79. package/src/api/parsers/html/__snapshots__/paste/list-test.json +74 -2
  80. package/src/api/parsers/html/__snapshots__/paste/parse-basic-block-types.json +3 -1
  81. package/src/api/parsers/html/__snapshots__/paste/parse-fake-image-caption.json +3 -1
  82. package/src/api/parsers/html/__snapshots__/paste/parse-mixed-nested-lists.json +135 -10
  83. package/src/api/parsers/html/__snapshots__/paste/parse-nested-lists-with-paragraphs.json +132 -7
  84. package/src/api/parsers/html/__snapshots__/paste/parse-nested-lists.json +111 -3
  85. package/src/api/parsers/html/parseHTML.test.ts +166 -95
  86. package/src/api/testUtil/cases/customBlocks.ts +82 -33
  87. package/src/api/testUtil/cases/customInlineContent.ts +1 -1
  88. package/src/api/testUtil/cases/customStyles.ts +1 -1
  89. package/src/api/testUtil/cases/defaultSchema.ts +185 -4
  90. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +163 -0
  91. package/src/blocks/AudioBlockContent/audioBlockHelpers.ts +5 -0
  92. package/src/blocks/FileBlockContent/FileBlockContent.ts +120 -0
  93. package/src/blocks/FileBlockContent/fileBlockHelpers.ts +377 -0
  94. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +134 -354
  95. package/src/blocks/ImageBlockContent/imageBlockHelpers.ts +6 -0
  96. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +3 -0
  97. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +266 -0
  98. package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +2 -1
  99. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +1 -0
  100. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +181 -0
  101. package/src/blocks/VideoBlockContent/videoBlockHelpers.ts +6 -0
  102. package/src/blocks/defaultBlockTypeGuards.ts +53 -1
  103. package/src/blocks/defaultBlocks.ts +11 -2
  104. package/src/editor/Block.css +89 -27
  105. package/src/editor/BlockNoteEditor.ts +24 -10
  106. package/src/editor/BlockNoteSchema.ts +12 -3
  107. package/src/editor/transformPasted.ts +2 -1
  108. package/src/extensions/{ImagePanel/ImageToolbarPlugin.ts → FilePanel/FilePanelPlugin.ts} +22 -25
  109. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +14 -2
  110. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +72 -2
  111. package/src/extensions/TableHandles/TableHandlesPlugin.ts +27 -27
  112. package/src/extensions/TextAlignment/TextAlignmentExtension.ts +7 -1
  113. package/src/i18n/locales/en.ts +117 -11
  114. package/src/i18n/locales/fr.ts +118 -11
  115. package/src/i18n/locales/index.ts +8 -2
  116. package/src/i18n/locales/is.ts +295 -0
  117. package/src/i18n/locales/ja.ts +323 -0
  118. package/src/i18n/locales/ko.ts +307 -0
  119. package/src/i18n/locales/nl.ts +108 -8
  120. package/src/i18n/locales/pl.ts +287 -0
  121. package/src/i18n/locales/pt.ts +295 -0
  122. package/src/i18n/locales/vi.ts +295 -0
  123. package/src/i18n/locales/zh.ts +123 -8
  124. package/src/index.ts +9 -2
  125. package/src/pm-nodes/BlockContainer.ts +18 -6
  126. package/src/schema/blocks/createSpec.ts +1 -0
  127. package/src/schema/blocks/internal.ts +10 -0
  128. package/src/schema/blocks/types.ts +40 -5
  129. package/src/util/string.ts +12 -0
  130. package/types/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.d.ts +7 -0
  131. package/types/src/api/testUtil/cases/customBlocks.d.ts +272 -54
  132. package/types/src/api/testUtil/cases/customInlineContent.d.ts +222 -16
  133. package/types/src/api/testUtil/cases/customStyles.d.ts +222 -16
  134. package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +101 -0
  135. package/types/src/blocks/AudioBlockContent/audioBlockHelpers.d.ts +3 -0
  136. package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +93 -0
  137. package/types/src/blocks/FileBlockContent/fileBlockHelpers.d.ts +30 -0
  138. package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +50 -14
  139. package/types/src/blocks/ImageBlockContent/imageBlockHelpers.d.ts +4 -0
  140. package/types/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.d.ts +55 -0
  141. package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +129 -0
  142. package/types/src/blocks/VideoBlockContent/videoBlockHelpers.d.ts +4 -0
  143. package/types/src/blocks/defaultBlockTypeGuards.d.ts +6 -1
  144. package/types/src/blocks/defaultBlocks.d.ts +444 -32
  145. package/types/src/editor/BlockNoteEditor.d.ts +12 -5
  146. package/types/src/extensions/{ImagePanel/ImageToolbarPlugin.d.ts → FilePanel/FilePanelPlugin.d.ts} +9 -12
  147. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +1 -1
  148. package/types/src/i18n/locales/en.d.ts +56 -7
  149. package/types/src/i18n/locales/fr.d.ts +2 -184
  150. package/types/src/i18n/locales/index.d.ts +7 -1
  151. package/types/src/i18n/locales/is.d.ts +2 -0
  152. package/types/src/i18n/locales/ja.d.ts +2 -0
  153. package/types/src/i18n/locales/ko.d.ts +2 -0
  154. package/types/src/i18n/locales/pl.d.ts +2 -0
  155. package/types/src/i18n/locales/pt.d.ts +2 -0
  156. package/types/src/i18n/locales/vi.d.ts +2 -0
  157. package/types/src/index.d.ts +8 -2
  158. package/types/src/pm-nodes/BlockContainer.d.ts +1 -1
  159. package/types/src/schema/blocks/internal.d.ts +1 -1
  160. package/types/src/schema/blocks/types.d.ts +25 -1
  161. package/types/src/util/string.d.ts +1 -0
  162. /package/src/blocks/{ImageBlockContent → FileBlockContent}/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -0
  163. /package/types/src/blocks/{ImageBlockContent → FileBlockContent}/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +0 -0
@@ -48,6 +48,21 @@ export const zh: Dictionary = {
48
48
  ],
49
49
  group: "基础",
50
50
  },
51
+ check_list: {
52
+ title: "检查清单",
53
+ subtext: "用于显示带有复选框的列表",
54
+ aliases: [
55
+ "ul",
56
+ "li",
57
+ "checklist",
58
+ "checked list",
59
+ "列表",
60
+ "检查清单",
61
+ "勾选列表",
62
+ "复选框",
63
+ ],
64
+ group: "基本块",
65
+ },
51
66
  paragraph: {
52
67
  title: "段落",
53
68
  subtext: "用于文档正文",
@@ -75,15 +90,67 @@ export const zh: Dictionary = {
75
90
  ],
76
91
  group: "媒体",
77
92
  },
93
+ video: {
94
+ title: "视频",
95
+ subtext: "插入视频",
96
+ aliases: [
97
+ "视频",
98
+ "视频上传",
99
+ "上传",
100
+ "video",
101
+ "mp4",
102
+ "电影",
103
+ "媒体",
104
+ "url",
105
+ "驱动",
106
+ "dropbox",
107
+ ],
108
+ group: "媒体",
109
+ },
110
+ audio: {
111
+ title: "音频",
112
+ subtext: "插入音频",
113
+ aliases: [
114
+ "音频",
115
+ "音频上传",
116
+ "上传",
117
+ "audio",
118
+ "mp3",
119
+ "声音",
120
+ "媒体",
121
+ "url",
122
+ "驱动",
123
+ "dropbox",
124
+ ],
125
+ group: "媒体",
126
+ },
127
+ file: {
128
+ title: "文件",
129
+ subtext: "插入文件",
130
+ aliases: ["文件", "上传", "file", "嵌入", "媒体", "url"],
131
+ group: "媒体",
132
+ },
78
133
  },
79
134
  placeholders: {
80
135
  default: "输入 '/' 以使用命令",
81
136
  heading: "标题",
82
137
  bulletListItem: "列表",
83
138
  numberedListItem: "列表",
139
+ checkListItem: "列表",
84
140
  },
85
- image: {
86
- add_button: "添加图片",
141
+ file_blocks: {
142
+ image: {
143
+ add_button_text: "添加图片",
144
+ },
145
+ video: {
146
+ add_button_text: "添加视频",
147
+ },
148
+ audio: {
149
+ add_button_text: "添加音频",
150
+ },
151
+ file: {
152
+ add_button_text: "添加文件",
153
+ },
87
154
  },
88
155
  // from react package:
89
156
  side_menu: {
@@ -151,12 +218,50 @@ export const zh: Dictionary = {
151
218
  tooltip: "添加链接",
152
219
  secondary_tooltip: "Mod+K",
153
220
  },
154
- image_caption: {
221
+ file_caption: {
155
222
  tooltip: "编辑标题",
156
223
  input_placeholder: "编辑标题",
157
224
  },
158
- image_replace: {
159
- tooltip: "替换图片",
225
+ file_replace: {
226
+ tooltip: {
227
+ image: "替换图片",
228
+ video: "替换视频",
229
+ audio: "替换音频",
230
+ file: "替换文件",
231
+ },
232
+ },
233
+ file_rename: {
234
+ tooltip: {
235
+ image: "重命名图片",
236
+ video: "重命名视频",
237
+ audio: "重命名音频",
238
+ file: "重命名文件",
239
+ },
240
+ input_placeholder: {
241
+ image: "重命名图片",
242
+ video: "重命名视频",
243
+ audio: "重命名音频",
244
+ file: "重命名文件",
245
+ },
246
+ },
247
+ file_download: {
248
+ tooltip: {
249
+ image: "下载图片",
250
+ video: "下载视频",
251
+ audio: "下载音频",
252
+ file: "下载文件",
253
+ },
254
+ },
255
+ file_delete: {
256
+ tooltip: {
257
+ image: "删除图片",
258
+ video: "删除视频",
259
+ audio: "删除音频",
260
+ file: "删除文件",
261
+ },
262
+ },
263
+ file_preview_toggle: {
264
+ tooltip: "切换预览",
160
265
  },
161
266
  nest: {
162
267
  tooltip: "嵌套",
@@ -179,15 +284,25 @@ export const zh: Dictionary = {
179
284
  tooltip: "文本对齐",
180
285
  },
181
286
  },
182
- image_panel: {
287
+ file_panel: {
183
288
  upload: {
184
289
  title: "上传",
185
- file_placeholder: "上传图片",
290
+ file_placeholder: {
291
+ image: "上传图片",
292
+ video: "上传视频",
293
+ audio: "上传音频",
294
+ file: "上传文件",
295
+ },
186
296
  upload_error: "Error:上传失败",
187
297
  },
188
298
  embed: {
189
299
  title: "嵌入",
190
- embed_button: "嵌入图片",
300
+ embed_button: {
301
+ image: "嵌入图片",
302
+ video: "嵌入视频",
303
+ audio: "嵌入音频",
304
+ file: "嵌入文件",
305
+ },
191
306
  url_placeholder: "输入图片地址",
192
307
  },
193
308
  },
package/src/index.ts CHANGED
@@ -2,7 +2,13 @@ import * as locales from "./i18n/locales";
2
2
  export * from "./api/exporters/html/externalHTMLExporter";
3
3
  export * from "./api/exporters/html/internalHTMLSerializer";
4
4
  export * from "./api/testUtil";
5
- export * from "./blocks/ImageBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY";
5
+ export * from "./blocks/FileBlockContent/FileBlockContent";
6
+ export * from "./blocks/ImageBlockContent/ImageBlockContent";
7
+ export * from "./blocks/VideoBlockContent/VideoBlockContent";
8
+ export * from "./blocks/AudioBlockContent/AudioBlockContent";
9
+
10
+ export * from "./blocks/FileBlockContent/fileBlockHelpers";
11
+ export * from "./blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY";
6
12
  export * from "./blocks/defaultBlockTypeGuards";
7
13
  export * from "./blocks/defaultBlocks";
8
14
  export * from "./blocks/defaultProps";
@@ -11,8 +17,8 @@ export * from "./editor/BlockNoteExtensions";
11
17
  export * from "./editor/BlockNoteSchema";
12
18
  export * from "./editor/selectionTypes";
13
19
  export * from "./extensions-shared/UiElementPosition";
20
+ export * from "./extensions/FilePanel/FilePanelPlugin";
14
21
  export * from "./extensions/FormattingToolbar/FormattingToolbarPlugin";
15
- export * from "./extensions/ImagePanel/ImageToolbarPlugin";
16
22
  export * from "./extensions/LinkToolbar/LinkToolbarPlugin";
17
23
  export * from "./extensions/SideMenu/SideMenuPlugin";
18
24
  export * from "./extensions/SuggestionMenu/DefaultSuggestionItem";
@@ -29,3 +35,4 @@ export * from "./extensions/UniqueID/UniqueID";
29
35
  export * from "./i18n/dictionary";
30
36
  export { UnreachableCaseError, assertEmpty } from "./util/typescript";
31
37
  export { locales };
38
+ export { parseImageElement } from "./blocks/ImageBlockContent/imageBlockHelpers";
@@ -36,7 +36,11 @@ declare module "@tiptap/core" {
36
36
  BNCreateBlock: (pos: number) => ReturnType;
37
37
  BNDeleteBlock: (posInBlock: number) => ReturnType;
38
38
  BNMergeBlocks: (posBetweenBlocks: number) => ReturnType;
39
- BNSplitBlock: (posInBlock: number, keepType: boolean) => ReturnType;
39
+ BNSplitBlock: (
40
+ posInBlock: number,
41
+ keepType?: boolean,
42
+ keepProps?: boolean
43
+ ) => ReturnType;
40
44
  BNUpdateBlock: <
41
45
  BSchema extends BlockSchema,
42
46
  I extends InlineContentSchema,
@@ -402,8 +406,12 @@ export const BlockContainer = Node.create<{
402
406
  },
403
407
  // Splits a block at a given position. Content after the position is moved to a new block below, at the same
404
408
  // nesting level.
409
+ // - `keepType` is usually false, unless the selection is at the start of
410
+ // a block.
411
+ // - `keepProps` is usually true when `keepType` is true, except for when
412
+ // creating new list item blocks with Enter.
405
413
  BNSplitBlock:
406
- (posInBlock, keepType) =>
414
+ (posInBlock, keepType, keepProps) =>
407
415
  ({ state, dispatch }) => {
408
416
  const blockInfo = getBlockInfoFromPos(state.doc, posInBlock);
409
417
  if (blockInfo === undefined) {
@@ -448,7 +456,7 @@ export const BlockContainer = Node.create<{
448
456
  newBlockContentPos,
449
457
  newBlockContentPos,
450
458
  state.schema.node(contentType).type,
451
- contentNode.attrs
459
+ keepProps ? contentNode.attrs : undefined
452
460
  );
453
461
  }
454
462
 
@@ -671,7 +679,11 @@ export const BlockContainer = Node.create<{
671
679
  if (!blockEmpty) {
672
680
  chain()
673
681
  .deleteSelection()
674
- .BNSplitBlock(state.selection.from, selectionAtBlockStart)
682
+ .BNSplitBlock(
683
+ state.selection.from,
684
+ selectionAtBlockStart,
685
+ selectionAtBlockStart
686
+ )
675
687
  .run();
676
688
 
677
689
  return true;
@@ -691,7 +703,7 @@ export const BlockContainer = Node.create<{
691
703
  if (
692
704
  this.options.editor.formattingToolbar?.shown ||
693
705
  this.options.editor.linkToolbar?.shown ||
694
- this.options.editor.imagePanel?.shown
706
+ this.options.editor.filePanel?.shown
695
707
  ) {
696
708
  // don't handle tabs if a toolbar is shown, so we can tab into / out of it
697
709
  return false;
@@ -703,7 +715,7 @@ export const BlockContainer = Node.create<{
703
715
  if (
704
716
  this.options.editor.formattingToolbar?.shown ||
705
717
  this.options.editor.linkToolbar?.shown ||
706
- this.options.editor.imagePanel?.shown
718
+ this.options.editor.filePanel?.shown
707
719
  ) {
708
720
  // don't handle tabs if a toolbar is shown, so we can tab into / out of it
709
721
  return false;
@@ -193,6 +193,7 @@ export function createBlockSpec<
193
193
  block.type,
194
194
  block.props,
195
195
  blockConfig.propSchema,
196
+ blockConfig.isFileBlock,
196
197
  blockContentDOMAttributes
197
198
  );
198
199
  },
@@ -109,6 +109,11 @@ export function getBlockFromPos<
109
109
  const blockContainer = tipTapEditor.state.doc.resolve(pos!).node();
110
110
  // Gets block identifier
111
111
  const blockIdentifier = blockContainer.attrs.id;
112
+
113
+ if (!blockIdentifier) {
114
+ throw new Error("Block doesn't have id");
115
+ }
116
+
112
117
  // Gets the block
113
118
  const block = editor.getBlock(blockIdentifier)! as SpecificBlock<
114
119
  BSchema,
@@ -139,6 +144,7 @@ export function wrapInBlockStructure<
139
144
  blockType: BType,
140
145
  blockProps: Props<PSchema>,
141
146
  propSchema: PSchema,
147
+ isFileBlock = false,
142
148
  domAttributes?: Record<string, string>
143
149
  ): {
144
150
  dom: HTMLElement;
@@ -171,6 +177,10 @@ export function wrapInBlockStructure<
171
177
  blockContent.setAttribute(camelToDataKebab(prop), value);
172
178
  }
173
179
  }
180
+ // Adds file block attribute
181
+ if (isFileBlock) {
182
+ blockContent.setAttribute("data-file-block", "");
183
+ }
174
184
 
175
185
  blockContent.appendChild(element.dom);
176
186
 
@@ -21,14 +21,49 @@ export type BlockNoteDOMAttributes = Partial<{
21
21
  [DOMElement in BlockNoteDOMElement]: Record<string, string>;
22
22
  }>;
23
23
 
24
- // BlockConfig contains the "schema" info about a Block type
25
- // i.e. what props it supports, what content it supports, etc.
26
- export type BlockConfig = {
24
+ export type FileBlockConfig = {
27
25
  type: string;
28
- readonly propSchema: PropSchema;
29
- content: "inline" | "none" | "table";
26
+ readonly propSchema: PropSchema & {
27
+ caption: {
28
+ default: "";
29
+ };
30
+ name: {
31
+ default: "";
32
+ };
33
+
34
+ // URL is optional, as we also want to accept files with no URL, but for example ids
35
+ // (ids can be used for files that are resolved on the backend)
36
+ url?: {
37
+ default: "";
38
+ };
39
+
40
+ // Whether to show the file preview or the name only.
41
+ // This is useful for some file blocks, but not all
42
+ // (e.g.: not relevant for default "file" block which doesn;'t show previews)
43
+ showPreview?: {
44
+ default: boolean;
45
+ };
46
+ // File preview width in px.
47
+ previewWidth?: {
48
+ default: number;
49
+ };
50
+ };
51
+ content: "none";
52
+ isFileBlock: true;
53
+ fileBlockAcceptMimeTypes?: string[];
30
54
  };
31
55
 
56
+ // BlockConfig contains the "schema" info about a Block type
57
+ // i.e. what props it supports, what content it supports, etc.
58
+ export type BlockConfig =
59
+ | {
60
+ type: string;
61
+ readonly propSchema: PropSchema;
62
+ content: "inline" | "none" | "table";
63
+ isFileBlock?: false;
64
+ }
65
+ | FileBlockConfig;
66
+
32
67
  // Block implementation contains the "implementation" info about a Block
33
68
  // such as the functions / Nodes required to render and / or serialize it
34
69
  export type TiptapBlockImplementation<
@@ -1,3 +1,15 @@
1
1
  export function camelToDataKebab(str: string): string {
2
2
  return "data-" + str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
3
3
  }
4
+
5
+ export function filenameFromURL(url: string): string {
6
+ const parts = url.split("/");
7
+ if (
8
+ !parts.length || // invalid?
9
+ parts[parts.length - 1] === "" // for example, URL ends in a directory-like trailing slash
10
+ ) {
11
+ // in this case just return the original url
12
+ return url;
13
+ }
14
+ return parts[parts.length - 1];
15
+ }
@@ -0,0 +1,7 @@
1
+ import { Parent as HASTParent } from "hast";
2
+ /**
3
+ * Rehype plugin which adds a space after each checkbox input element. This is
4
+ * because remark doesn't add any spaces between the checkbox input and the text
5
+ * itself, but these are needed for correct Markdown syntax.
6
+ */
7
+ export declare function addSpacesToCheckboxes(): (tree: HASTParent) => void;