@blocknote/core 0.24.2 → 0.25.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 (141) hide show
  1. package/dist/blocknote.cjs +12 -0
  2. package/dist/blocknote.cjs.map +1 -0
  3. package/dist/blocknote.js +4754 -3514
  4. package/dist/blocknote.js.map +1 -1
  5. package/dist/comments.cjs +2 -0
  6. package/dist/comments.cjs.map +1 -0
  7. package/dist/comments.js +593 -0
  8. package/dist/comments.js.map +1 -0
  9. package/dist/style.css +1 -1
  10. package/dist/tsconfig.tsbuildinfo +1 -1
  11. package/dist/webpack-stats.json +1 -1
  12. package/package.json +39 -26
  13. package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +1022 -378
  14. package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +730 -270
  15. package/src/api/blockManipulation/commands/moveBlocks/__snapshots__/moveBlocks.test.ts.snap +3100 -1260
  16. package/src/api/blockManipulation/commands/removeBlocks/__snapshots__/removeBlocks.test.ts.snap +438 -162
  17. package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +1168 -432
  18. package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +930 -378
  19. package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +2485 -1015
  20. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +28 -1
  21. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +1 -1
  22. package/src/api/blockManipulation/selections/__snapshots__/selection.test.ts.snap +292 -108
  23. package/src/api/blockManipulation/setupTestEnv.ts +14 -1
  24. package/src/api/blockManipulation/tables/tables.test.ts +1987 -0
  25. package/src/api/blockManipulation/tables/tables.ts +887 -0
  26. package/src/api/clipboard/__snapshots__/external/pasteEndOfParagraph.html +66 -24
  27. package/src/api/clipboard/__snapshots__/external/pasteEndOfParagraphText.html +66 -24
  28. package/src/api/clipboard/__snapshots__/external/pasteImage.html +66 -24
  29. package/src/api/clipboard/__snapshots__/external/pasteParagraphInCustomBlock.html +66 -24
  30. package/src/api/clipboard/__snapshots__/external/pasteTable.html +132 -48
  31. package/src/api/clipboard/__snapshots__/external/pasteTableInExistingTable.html +136 -44
  32. package/src/api/clipboard/toClipboard/copyExtension.ts +2 -3
  33. package/src/api/exporters/html/__snapshots__/table/headerCols/external.html +1 -0
  34. package/src/api/exporters/html/__snapshots__/table/headerCols/internal.html +1 -0
  35. package/src/api/exporters/html/__snapshots__/table/headerRows/external.html +1 -0
  36. package/src/api/exporters/html/__snapshots__/table/headerRows/internal.html +1 -0
  37. package/src/api/exporters/html/__snapshots__/table/headersRows/external.html +1 -0
  38. package/src/api/exporters/html/__snapshots__/table/headersRows/internal.html +1 -0
  39. package/src/api/exporters/html/__snapshots__/table/mixedCellColors/external.html +1 -0
  40. package/src/api/exporters/html/__snapshots__/table/mixedCellColors/internal.html +1 -0
  41. package/src/api/exporters/html/__snapshots__/table/mixedRowspansAndColspans/external.html +1 -0
  42. package/src/api/exporters/html/__snapshots__/table/mixedRowspansAndColspans/internal.html +1 -0
  43. package/src/api/exporters/markdown/__snapshots__/table/headerCols/markdown.md +4 -0
  44. package/src/api/exporters/markdown/__snapshots__/table/headerRows/markdown.md +4 -0
  45. package/src/api/exporters/markdown/__snapshots__/table/mixedCellColors/markdown.md +5 -0
  46. package/src/api/exporters/markdown/__snapshots__/table/mixedRowspansAndColspans/markdown.md +5 -0
  47. package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +985 -20
  48. package/src/api/nodeConversions/blockToNode.ts +63 -20
  49. package/src/api/nodeConversions/nodeToBlock.ts +75 -13
  50. package/src/api/parsers/html/__snapshots__/parse-notion-html.json +145 -54
  51. package/src/api/testUtil/cases/defaultSchema.ts +782 -9
  52. package/src/api/testUtil/partialBlockTestUtil.ts +39 -4
  53. package/src/blocks/TableBlockContent/TableBlockContent.ts +11 -5
  54. package/src/blocks/defaultBlockTypeGuards.ts +8 -0
  55. package/src/comments/index.ts +9 -0
  56. package/src/comments/models/User.ts +8 -0
  57. package/src/comments/threadstore/DefaultThreadStoreAuth.ts +106 -0
  58. package/src/comments/threadstore/ThreadStore.ts +134 -0
  59. package/src/comments/threadstore/ThreadStoreAuth.ts +13 -0
  60. package/src/comments/threadstore/TipTapThreadStore.ts +292 -0
  61. package/src/comments/threadstore/yjs/RESTYjsThreadStore.ts +144 -0
  62. package/src/comments/threadstore/yjs/YjsThreadStore.test.ts +294 -0
  63. package/src/comments/threadstore/yjs/YjsThreadStore.ts +340 -0
  64. package/src/comments/threadstore/yjs/YjsThreadStoreBase.ts +48 -0
  65. package/src/comments/threadstore/yjs/yjsHelpers.ts +121 -0
  66. package/src/comments/types.ts +117 -0
  67. package/src/editor/Block.css +16 -8
  68. package/src/editor/BlockNoteEditor.ts +269 -92
  69. package/src/editor/BlockNoteExtensions.ts +24 -1
  70. package/src/editor/BlockNoteTipTapEditor.ts +5 -1
  71. package/src/editor/editor.css +17 -0
  72. package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +1 -1
  73. package/src/extensions/Comments/CommentMark.ts +61 -0
  74. package/src/extensions/Comments/CommentsPlugin.ts +301 -0
  75. package/src/extensions/Comments/userstore/UserStore.ts +72 -0
  76. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +9 -5
  77. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +3 -3
  78. package/src/extensions/ShowSelection/ShowSelectionPlugin.ts +52 -0
  79. package/src/extensions/TableHandles/TableHandlesPlugin.ts +409 -57
  80. package/src/extensions/TextAlignment/TextAlignmentExtension.ts +2 -0
  81. package/src/extensions/TextColor/TextColorExtension.ts +1 -1
  82. package/src/i18n/locales/ar.ts +23 -0
  83. package/src/i18n/locales/de.ts +15 -0
  84. package/src/i18n/locales/en.ts +25 -1
  85. package/src/i18n/locales/es.ts +16 -1
  86. package/src/i18n/locales/fr.ts +23 -0
  87. package/src/i18n/locales/hr.ts +18 -0
  88. package/src/i18n/locales/is.ts +24 -1
  89. package/src/i18n/locales/it.ts +15 -0
  90. package/src/i18n/locales/ja.ts +23 -0
  91. package/src/i18n/locales/ko.ts +23 -0
  92. package/src/i18n/locales/nl.ts +23 -0
  93. package/src/i18n/locales/no.ts +23 -0
  94. package/src/i18n/locales/pl.ts +23 -0
  95. package/src/i18n/locales/pt.ts +23 -0
  96. package/src/i18n/locales/ru.ts +23 -0
  97. package/src/i18n/locales/uk.ts +23 -0
  98. package/src/i18n/locales/vi.ts +23 -0
  99. package/src/i18n/locales/zh.ts +23 -0
  100. package/src/index.ts +6 -4
  101. package/src/schema/blocks/types.ts +32 -2
  102. package/src/util/browser.ts +1 -1
  103. package/src/util/table.ts +107 -0
  104. package/types/src/api/blockManipulation/tables/tables.d.ts +343 -0
  105. package/types/src/api/blockManipulation/tables/tables.test.d.ts +1 -0
  106. package/types/src/api/clipboard/toClipboard/copyExtension.d.ts +1 -1
  107. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +1 -2
  108. package/types/src/blocks/defaultBlockTypeGuards.d.ts +3 -0
  109. package/types/src/comments/index.d.ts +9 -0
  110. package/types/src/comments/models/User.d.ts +8 -0
  111. package/types/src/comments/threadstore/DefaultThreadStoreAuth.d.ts +47 -0
  112. package/types/src/comments/threadstore/ThreadStore.d.ts +121 -0
  113. package/types/src/comments/threadstore/ThreadStoreAuth.d.ts +12 -0
  114. package/types/src/comments/threadstore/TipTapThreadStore.d.ts +97 -0
  115. package/types/src/comments/threadstore/yjs/RESTYjsThreadStore.d.ts +83 -0
  116. package/types/src/comments/threadstore/yjs/YjsThreadStore.d.ts +79 -0
  117. package/types/src/comments/threadstore/yjs/YjsThreadStore.test.d.ts +1 -0
  118. package/types/src/comments/threadstore/yjs/YjsThreadStoreBase.d.ts +15 -0
  119. package/types/src/comments/threadstore/yjs/yjsHelpers.d.ts +13 -0
  120. package/types/src/comments/types.d.ts +109 -0
  121. package/types/src/editor/BlockNoteEditor.d.ts +146 -66
  122. package/types/src/editor/BlockNoteExtensions.d.ts +4 -0
  123. package/types/src/extensions/Collaboration/createCollaborationExtensions.d.ts +1 -1
  124. package/types/src/extensions/Comments/CommentMark.d.ts +2 -0
  125. package/types/src/extensions/Comments/CommentsPlugin.d.ts +49 -0
  126. package/types/src/extensions/Comments/userstore/UserStore.d.ts +31 -0
  127. package/types/src/extensions/ShowSelection/ShowSelectionPlugin.d.ts +15 -0
  128. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +66 -1
  129. package/types/src/i18n/locales/de.d.ts +15 -0
  130. package/types/src/i18n/locales/en.d.ts +20 -0
  131. package/types/src/i18n/locales/es.d.ts +15 -0
  132. package/types/src/i18n/locales/hr.d.ts +18 -0
  133. package/types/src/i18n/locales/it.d.ts +15 -0
  134. package/types/src/index.d.ts +5 -4
  135. package/types/src/pm-nodes/BlockContainer.d.ts +2 -2
  136. package/types/src/pm-nodes/BlockGroup.d.ts +2 -2
  137. package/types/src/schema/blocks/types.d.ts +23 -2
  138. package/types/src/util/browser.d.ts +1 -1
  139. package/types/src/util/table.d.ts +12 -0
  140. package/dist/blocknote.umd.cjs +0 -11
  141. package/dist/blocknote.umd.cjs.map +0 -1
@@ -157,6 +157,9 @@ export const ru: Dictionary = {
157
157
  bulletListItem: "Список",
158
158
  numberedListItem: "Список",
159
159
  checkListItem: "Список",
160
+ new_comment: "Напишите комментарий...",
161
+ edit_comment: "Редактировать комментарий...",
162
+ comment_reply: "Добавить комментарий...",
160
163
  },
161
164
  file_blocks: {
162
165
  image: {
@@ -180,6 +183,8 @@ export const ru: Dictionary = {
180
183
  drag_handle: {
181
184
  delete_menuitem: "Удалить",
182
185
  colors_menuitem: "Цвета",
186
+ header_row_menuitem: "Заголовок строки",
187
+ header_column_menuitem: "Заголовок столбца",
183
188
  },
184
189
  table_handle: {
185
190
  delete_column_menuitem: "Удалить столбец",
@@ -188,6 +193,9 @@ export const ru: Dictionary = {
188
193
  add_right_menuitem: "Добавить столбец справа",
189
194
  add_above_menuitem: "Добавить строку выше",
190
195
  add_below_menuitem: "Добавить строку ниже",
196
+ split_cell_menuitem: "Разделить ячейку",
197
+ merge_cells_menuitem: "Объединить ячейки",
198
+ background_color_menuitem: "Цвет фона",
191
199
  },
192
200
  suggestion_menu: {
193
201
  no_items_title: "ничего не найдено",
@@ -303,6 +311,9 @@ export const ru: Dictionary = {
303
311
  align_justify: {
304
312
  tooltip: "По середине текст",
305
313
  },
314
+ table_cell_merge: {
315
+ tooltip: "Объединить ячейки",
316
+ },
306
317
  comment: {
307
318
  tooltip: "Добавить комментарий",
308
319
  },
@@ -345,6 +356,18 @@ export const ru: Dictionary = {
345
356
  url_placeholder: "Изменить URL",
346
357
  },
347
358
  },
359
+ comments: {
360
+ actions: {
361
+ add_reaction: "Добавить реакцию",
362
+ resolve: "Решить",
363
+ edit_comment: "Редактировать комментарий",
364
+ delete_comment: "Удалить комментарий",
365
+ more_actions: "Другие действия",
366
+ },
367
+ reactions: {
368
+ reacted_by: "Отреагировал(а)",
369
+ },
370
+ },
348
371
  generic: {
349
372
  ctrl_shortcut: "Ctrl",
350
373
  },
@@ -155,6 +155,9 @@ export const uk: Dictionary = {
155
155
  bulletListItem: "Список",
156
156
  numberedListItem: "Список",
157
157
  checkListItem: "Список",
158
+ new_comment: "Напишіть коментар...",
159
+ edit_comment: "Редагувати коментар...",
160
+ comment_reply: "Додати коментар...",
158
161
  },
159
162
  file_blocks: {
160
163
  image: {
@@ -178,6 +181,8 @@ export const uk: Dictionary = {
178
181
  drag_handle: {
179
182
  delete_menuitem: "Видалити",
180
183
  colors_menuitem: "Кольори",
184
+ header_row_menuitem: "Заголовок рядка",
185
+ header_column_menuitem: "Заголовок стовпця",
181
186
  },
182
187
  table_handle: {
183
188
  delete_column_menuitem: "Видалити стовпець",
@@ -186,6 +191,9 @@ export const uk: Dictionary = {
186
191
  add_right_menuitem: "Додати стовпець справа",
187
192
  add_above_menuitem: "Додати рядок вище",
188
193
  add_below_menuitem: "Додати рядок нижче",
194
+ split_cell_menuitem: "Розділити клітинку",
195
+ merge_cells_menuitem: "Об'єднати клітинки",
196
+ background_color_menuitem: "Змінити колір фону",
189
197
  },
190
198
  suggestion_menu: {
191
199
  no_items_title: "Нічого не знайдено",
@@ -300,6 +308,9 @@ export const uk: Dictionary = {
300
308
  align_justify: {
301
309
  tooltip: "Вирівняти за шириною",
302
310
  },
311
+ table_cell_merge: {
312
+ tooltip: "Об'єднати клітинки",
313
+ },
303
314
  comment: {
304
315
  tooltip: "Додати коментар",
305
316
  },
@@ -342,6 +353,18 @@ export const uk: Dictionary = {
342
353
  url_placeholder: "Редагувати URL",
343
354
  },
344
355
  },
356
+ comments: {
357
+ actions: {
358
+ add_reaction: "Додати реакцію",
359
+ resolve: "Вирішити",
360
+ edit_comment: "Редагувати коментар",
361
+ delete_comment: "Видалити коментар",
362
+ more_actions: "Більше дій",
363
+ },
364
+ reactions: {
365
+ reacted_by: "Відреагував(ла)",
366
+ },
367
+ },
345
368
  generic: {
346
369
  ctrl_shortcut: "Ctrl",
347
370
  },
@@ -129,6 +129,9 @@ export const vi: Dictionary = {
129
129
  bulletListItem: "Danh sách",
130
130
  numberedListItem: "Danh sách",
131
131
  checkListItem: "Danh sách",
132
+ new_comment: "Viết bình luận...",
133
+ edit_comment: "Chỉnh sửa bình luận...",
134
+ comment_reply: "Thêm bình luận...",
132
135
  },
133
136
  file_blocks: {
134
137
  image: {
@@ -152,6 +155,8 @@ export const vi: Dictionary = {
152
155
  drag_handle: {
153
156
  delete_menuitem: "Xóa",
154
157
  colors_menuitem: "Màu sắc",
158
+ header_row_menuitem: "Tiêu đề hàng",
159
+ header_column_menuitem: "Tiêu đề cột",
155
160
  },
156
161
  table_handle: {
157
162
  delete_column_menuitem: "Xóa cột",
@@ -160,6 +165,9 @@ export const vi: Dictionary = {
160
165
  add_right_menuitem: "Thêm cột bên phải",
161
166
  add_above_menuitem: "Thêm hàng phía trên",
162
167
  add_below_menuitem: "Thêm hàng phía dưới",
168
+ split_cell_menuitem: "Chia ô",
169
+ merge_cells_menuitem: "Gộp ô",
170
+ background_color_menuitem: "Màu nền",
163
171
  },
164
172
  suggestion_menu: {
165
173
  no_items_title: "Không tìm thấy mục nào",
@@ -275,6 +283,9 @@ export const vi: Dictionary = {
275
283
  align_justify: {
276
284
  tooltip: "Căn đều văn bản",
277
285
  },
286
+ table_cell_merge: {
287
+ tooltip: "Gộp các ô",
288
+ },
278
289
  comment: {
279
290
  tooltip: "Thêm bình luận",
280
291
  },
@@ -317,6 +328,18 @@ export const vi: Dictionary = {
317
328
  url_placeholder: "Chỉnh sửa URL",
318
329
  },
319
330
  },
331
+ comments: {
332
+ actions: {
333
+ add_reaction: "Thêm phản ứng",
334
+ resolve: "Giải quyết",
335
+ edit_comment: "Chỉnh sửa bình luận",
336
+ delete_comment: "Xóa bình luận",
337
+ more_actions: "Thêm hành động",
338
+ },
339
+ reactions: {
340
+ reacted_by: "Phản ứng bởi",
341
+ },
342
+ },
320
343
  generic: {
321
344
  ctrl_shortcut: "Ctrl",
322
345
  },
@@ -163,6 +163,9 @@ export const zh: Dictionary = {
163
163
  bulletListItem: "列表",
164
164
  numberedListItem: "列表",
165
165
  checkListItem: "列表",
166
+ new_comment: "写评论...",
167
+ edit_comment: "编辑评论...",
168
+ comment_reply: "添加评论...",
166
169
  },
167
170
  file_blocks: {
168
171
  image: {
@@ -186,6 +189,8 @@ export const zh: Dictionary = {
186
189
  drag_handle: {
187
190
  delete_menuitem: "删除",
188
191
  colors_menuitem: "颜色",
192
+ header_row_menuitem: "行标题",
193
+ header_column_menuitem: "列标题",
189
194
  },
190
195
  table_handle: {
191
196
  delete_column_menuitem: "删除列",
@@ -194,6 +199,9 @@ export const zh: Dictionary = {
194
199
  add_right_menuitem: "右侧添加列",
195
200
  add_above_menuitem: "上方添加行",
196
201
  add_below_menuitem: "下方添加行",
202
+ split_cell_menuitem: "拆分单元格",
203
+ merge_cells_menuitem: "合并单元格",
204
+ background_color_menuitem: "背景色",
197
205
  },
198
206
  suggestion_menu: {
199
207
  no_items_title: "无匹配项",
@@ -309,6 +317,9 @@ export const zh: Dictionary = {
309
317
  align_justify: {
310
318
  tooltip: "文本对齐",
311
319
  },
320
+ table_cell_merge: {
321
+ tooltip: "合并单元格",
322
+ },
312
323
  comment: {
313
324
  tooltip: "添加评论",
314
325
  },
@@ -351,6 +362,18 @@ export const zh: Dictionary = {
351
362
  url_placeholder: "编辑链接地址",
352
363
  },
353
364
  },
365
+ comments: {
366
+ actions: {
367
+ add_reaction: "添加反应",
368
+ resolve: "解决",
369
+ edit_comment: "编辑评论",
370
+ delete_comment: "删除评论",
371
+ more_actions: "更多操作",
372
+ },
373
+ reactions: {
374
+ reacted_by: "已回应",
375
+ },
376
+ },
354
377
  generic: {
355
378
  ctrl_shortcut: "Ctrl",
356
379
  },
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as locales from "./i18n/locales/index.js";
2
+ export * from "./api/blockManipulation/commands/updateBlock/updateBlock.js";
2
3
  export * from "./api/exporters/html/externalHTMLExporter.js";
3
4
  export * from "./api/exporters/html/internalHTMLSerializer.js";
4
5
  export * from "./api/getBlockInfoFromPos.js";
@@ -6,9 +7,6 @@ export * from "./api/nodeUtil.js";
6
7
  export * from "./api/testUtil/index.js";
7
8
  export * from "./blocks/AudioBlockContent/AudioBlockContent.js";
8
9
  export * from "./blocks/CodeBlockContent/CodeBlockContent.js";
9
- export * from "./blocks/PageBreakBlockContent/PageBreakBlockContent.js";
10
- export * from "./blocks/PageBreakBlockContent/getPageBreakSlashMenuItems.js";
11
- export * from "./blocks/PageBreakBlockContent/schema.js";
12
10
  export * from "./blocks/FileBlockContent/FileBlockContent.js";
13
11
  export * from "./blocks/FileBlockContent/helpers/parse/parseEmbedElement.js";
14
12
  export * from "./blocks/FileBlockContent/helpers/parse/parseFigureElement.js";
@@ -20,6 +18,9 @@ export * from "./blocks/FileBlockContent/helpers/toExternalHTML/createFigureWith
20
18
  export * from "./blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js";
21
19
  export * from "./blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.js";
22
20
  export * from "./blocks/ImageBlockContent/ImageBlockContent.js";
21
+ export * from "./blocks/PageBreakBlockContent/PageBreakBlockContent.js";
22
+ export * from "./blocks/PageBreakBlockContent/getPageBreakSlashMenuItems.js";
23
+ export * from "./blocks/PageBreakBlockContent/schema.js";
23
24
  export {
24
25
  EMPTY_CELL_HEIGHT,
25
26
  EMPTY_CELL_WIDTH,
@@ -52,11 +53,11 @@ export * from "./schema/index.js";
52
53
  export * from "./util/browser.js";
53
54
  export * from "./util/combineByGroup.js";
54
55
  export * from "./util/esmDependencies.js";
56
+ export * from "./util/table.js";
55
57
  export * from "./util/string.js";
56
58
  export * from "./util/typescript.js";
57
59
  export { UnreachableCaseError, assertEmpty } from "./util/typescript.js";
58
60
  export { locales };
59
- export * from "./api/blockManipulation/commands/updateBlock/updateBlock.js";
60
61
 
61
62
  // for testing from react (TODO: move):
62
63
  export * from "./api/nodeConversions/blockToNode.js";
@@ -68,3 +69,4 @@ export * from "./extensions/UniqueID/UniqueID.js";
68
69
  export * from "./api/exporters/markdown/markdownExporter.js";
69
70
  export * from "./api/parsers/html/parseHTML.js";
70
71
  export * from "./api/parsers/markdown/parseMarkdown.js";
72
+
@@ -144,14 +144,33 @@ export type BlockSchemaWithBlock<
144
144
  [k in BType]: C;
145
145
  };
146
146
 
147
+ export type TableCellProps = {
148
+ backgroundColor: string;
149
+ textColor: string;
150
+ textAlignment: "left" | "center" | "right" | "justify";
151
+ colspan?: number;
152
+ rowspan?: number;
153
+ };
154
+
155
+ export type TableCell<
156
+ I extends InlineContentSchema,
157
+ S extends StyleSchema = StyleSchema
158
+ > = {
159
+ type: "tableCell";
160
+ props: TableCellProps;
161
+ content: InlineContent<I, S>[];
162
+ };
163
+
147
164
  export type TableContent<
148
165
  I extends InlineContentSchema,
149
166
  S extends StyleSchema = StyleSchema
150
167
  > = {
151
168
  type: "tableContent";
152
169
  columnWidths: (number | undefined)[];
170
+ headerRows?: number;
171
+ headerCols?: number;
153
172
  rows: {
154
- cells: InlineContent<I, S>[][];
173
+ cells: InlineContent<I, S>[][] | TableCell<I, S>[];
155
174
  }[];
156
175
  };
157
176
 
@@ -220,14 +239,25 @@ export type SpecificBlock<
220
239
  *
221
240
  */
222
241
 
242
+ export type PartialTableCell<
243
+ I extends InlineContentSchema,
244
+ S extends StyleSchema = StyleSchema
245
+ > = {
246
+ type: "tableCell";
247
+ props?: Partial<TableCellProps>;
248
+ content?: PartialInlineContent<I, S>;
249
+ };
250
+
223
251
  export type PartialTableContent<
224
252
  I extends InlineContentSchema,
225
253
  S extends StyleSchema = StyleSchema
226
254
  > = {
227
255
  type: "tableContent";
228
256
  columnWidths?: (number | undefined)[];
257
+ headerRows?: number;
258
+ headerCols?: number;
229
259
  rows: {
230
- cells: PartialInlineContent<I, S>[];
260
+ cells: PartialInlineContent<I, S>[] | PartialTableCell<I, S>[];
231
261
  }[];
232
262
  };
233
263
 
@@ -12,7 +12,7 @@ export function formatKeyboardShortcut(shortcut: string, ctrlText = "Ctrl") {
12
12
  }
13
13
  }
14
14
 
15
- export function mergeCSSClasses(...classes: (string | undefined)[]) {
15
+ export function mergeCSSClasses(...classes: (string | false | undefined)[]) {
16
16
  return classes.filter((c) => c).join(" ");
17
17
  }
18
18
 
@@ -0,0 +1,107 @@
1
+ import type {
2
+ InlineContentSchema,
3
+ StyleSchema,
4
+ PartialInlineContent,
5
+ InlineContent,
6
+ } from "../schema";
7
+ import { PartialTableCell, TableCell } from "../schema/blocks/types.js";
8
+
9
+ /**
10
+ * This will map a table cell to a TableCell object.
11
+ * This is useful for when we want to get the full table cell object from a partial table cell.
12
+ * It is guaranteed to return a new TableCell object.
13
+ */
14
+ export function mapTableCell<
15
+ T extends InlineContentSchema,
16
+ S extends StyleSchema
17
+ >(
18
+ content: PartialInlineContent<T, S> | PartialTableCell<T, S> | TableCell<T, S>
19
+ ): TableCell<T, S> {
20
+ return isTableCell(content)
21
+ ? { ...content }
22
+ : isPartialTableCell(content)
23
+ ? {
24
+ type: "tableCell",
25
+ content: ([] as InlineContent<T, S>[]).concat(content.content as any),
26
+ props: {
27
+ backgroundColor: content.props?.backgroundColor ?? "default",
28
+ textColor: content.props?.textColor ?? "default",
29
+ textAlignment: content.props?.textAlignment ?? "left",
30
+ colspan: content.props?.colspan ?? 1,
31
+ rowspan: content.props?.rowspan ?? 1,
32
+ },
33
+ }
34
+ : {
35
+ type: "tableCell",
36
+ content: ([] as InlineContent<T, S>[]).concat(content as any),
37
+ props: {
38
+ backgroundColor: "default",
39
+ textColor: "default",
40
+ textAlignment: "left",
41
+ colspan: 1,
42
+ rowspan: 1,
43
+ },
44
+ };
45
+ }
46
+
47
+ export function isPartialTableCell<
48
+ T extends InlineContentSchema,
49
+ S extends StyleSchema
50
+ >(
51
+ content:
52
+ | TableCell<T, S>
53
+ | PartialInlineContent<T, S>
54
+ | PartialTableCell<T, S>
55
+ | undefined
56
+ | null
57
+ ): content is PartialTableCell<T, S> {
58
+ return (
59
+ content !== undefined &&
60
+ content !== null &&
61
+ typeof content !== "string" &&
62
+ !Array.isArray(content) &&
63
+ content.type === "tableCell"
64
+ );
65
+ }
66
+
67
+ export function isTableCell<
68
+ T extends InlineContentSchema,
69
+ S extends StyleSchema
70
+ >(
71
+ content:
72
+ | TableCell<T, S>
73
+ | PartialInlineContent<T, S>
74
+ | PartialTableCell<T, S>
75
+ | undefined
76
+ | null
77
+ ): content is TableCell<T, S> {
78
+ return (
79
+ isPartialTableCell(content) &&
80
+ content.props !== undefined &&
81
+ content.content !== undefined
82
+ );
83
+ }
84
+
85
+ export function getColspan(
86
+ cell:
87
+ | TableCell<any, any>
88
+ | PartialTableCell<any, any>
89
+ | PartialInlineContent<any, any>
90
+ ): number {
91
+ if (isTableCell(cell)) {
92
+ return cell.props.colspan ?? 1;
93
+ }
94
+ return 1;
95
+ }
96
+
97
+ export function getRowspan(
98
+ cell:
99
+ | TableCell<any, any>
100
+ | PartialTableCell<any, any>
101
+ | PartialInlineContent<any, any>
102
+ ): number {
103
+ if (isTableCell(cell)) {
104
+ return cell.props.rowspan ?? 1;
105
+ }
106
+ return 1;
107
+ }