@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
@@ -0,0 +1,1987 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import { Block, DefaultBlockSchema } from "../../../blocks/defaultBlocks.js";
4
+ import {
5
+ getCellsAtColumnHandle,
6
+ getCellsAtRowHandle,
7
+ getRelativeTableCells,
8
+ getAbsoluteTableCells,
9
+ moveColumn,
10
+ moveRow,
11
+ cropEmptyRowsOrColumns,
12
+ } from "./tables.js";
13
+
14
+ /**
15
+ * Simple table
16
+ * | 1-1 | 1-2 | 1-3 |
17
+ * | 2-1 | 2-2 | 2-3 |
18
+ */
19
+ const simpleTable = {
20
+ type: "table",
21
+ id: "table-0",
22
+ props: {
23
+ textColor: "default",
24
+ },
25
+ content: {
26
+ type: "tableContent",
27
+ columnWidths: [100, 100],
28
+ rows: [
29
+ {
30
+ cells: [
31
+ {
32
+ type: "tableCell",
33
+ props: {
34
+ backgroundColor: "default",
35
+ textColor: "default",
36
+ textAlignment: "left",
37
+ colspan: 1,
38
+ rowspan: 1,
39
+ },
40
+ content: [{ type: "text", text: "1-1", styles: {} }],
41
+ },
42
+ {
43
+ type: "tableCell",
44
+ props: {
45
+ backgroundColor: "default",
46
+ textColor: "default",
47
+ textAlignment: "left",
48
+ colspan: 1,
49
+ rowspan: 1,
50
+ },
51
+ content: [{ type: "text", text: "1-2", styles: {} }],
52
+ },
53
+ ],
54
+ },
55
+ {
56
+ cells: [
57
+ {
58
+ type: "tableCell",
59
+ props: {
60
+ backgroundColor: "default",
61
+ textColor: "default",
62
+ textAlignment: "left",
63
+ colspan: 1,
64
+ rowspan: 1,
65
+ },
66
+ content: [{ type: "text", text: "2-1", styles: {} }],
67
+ },
68
+ {
69
+ type: "tableCell",
70
+ props: {
71
+ backgroundColor: "default",
72
+ textColor: "default",
73
+ textAlignment: "left",
74
+ colspan: 1,
75
+ rowspan: 1,
76
+ },
77
+ content: [{ type: "text", text: "2-2", styles: {} }],
78
+ },
79
+ ],
80
+ },
81
+ ],
82
+ },
83
+ children: [],
84
+ } satisfies Block<
85
+ {
86
+ table: DefaultBlockSchema["table"];
87
+ },
88
+ any,
89
+ any
90
+ >;
91
+
92
+ /**
93
+ * Normal table
94
+ * | 1-1 | 1-2 | 1-3 |
95
+ * | 2-1 | 2-2 | 2-3 |
96
+ *
97
+ * Table with colspan
98
+ * | 1-1 | 1-1 | 1-2 |
99
+ * | 2-1 | 2-2 | 2-3 |
100
+ */
101
+ const tableWithColspan = {
102
+ type: "table",
103
+ id: "table-0",
104
+ props: {
105
+ textColor: "default",
106
+ },
107
+ content: {
108
+ type: "tableContent",
109
+ columnWidths: [100, 100],
110
+ rows: [
111
+ {
112
+ cells: [
113
+ {
114
+ type: "tableCell",
115
+ props: {
116
+ backgroundColor: "default",
117
+ textColor: "default",
118
+ textAlignment: "left",
119
+ colspan: 2,
120
+ rowspan: 1,
121
+ },
122
+ content: [
123
+ { type: "text", text: "1-1", styles: {} },
124
+ { type: "text", text: "1-2", styles: {} },
125
+ ],
126
+ },
127
+ {
128
+ type: "tableCell",
129
+ props: {
130
+ backgroundColor: "default",
131
+ textColor: "default",
132
+ textAlignment: "left",
133
+ colspan: 1,
134
+ rowspan: 1,
135
+ },
136
+ content: [{ type: "text", text: "1-3", styles: {} }],
137
+ },
138
+ ],
139
+ },
140
+ {
141
+ cells: [
142
+ {
143
+ type: "tableCell",
144
+ props: {
145
+ backgroundColor: "default",
146
+ textColor: "default",
147
+ textAlignment: "left",
148
+ colspan: 1,
149
+ rowspan: 1,
150
+ },
151
+ content: [{ type: "text", text: "2-1", styles: {} }],
152
+ },
153
+ {
154
+ type: "tableCell",
155
+ props: {
156
+ backgroundColor: "default",
157
+ textColor: "default",
158
+ textAlignment: "left",
159
+ colspan: 1,
160
+ rowspan: 1,
161
+ },
162
+ content: [{ type: "text", text: "2-2", styles: {} }],
163
+ },
164
+ {
165
+ type: "tableCell",
166
+ props: {
167
+ backgroundColor: "default",
168
+ textColor: "default",
169
+ textAlignment: "left",
170
+ colspan: 1,
171
+ rowspan: 1,
172
+ },
173
+ content: [{ type: "text", text: "2-3", styles: {} }],
174
+ },
175
+ ],
176
+ },
177
+ ],
178
+ },
179
+ children: [],
180
+ } satisfies Block<
181
+ {
182
+ table: DefaultBlockSchema["table"];
183
+ },
184
+ any,
185
+ any
186
+ >;
187
+
188
+ /**
189
+ * Normal table
190
+ * | 1-1 | 1-2 | 1-3 |
191
+ * | 2-1 | 2-2 | 2-3 |
192
+ * | 3-1 | 3-2 | 3-3 |
193
+ *
194
+ * Table with rowspan
195
+ * | 1-1 | 1-2 | 1-3 |
196
+ * | 1-1 | 2-1 | 2-2 |
197
+ * | 3-1 | 3-2 | 3-3 |
198
+ */
199
+ const tableWithRowspan = {
200
+ type: "table",
201
+ id: "table-0",
202
+ props: {
203
+ textColor: "default",
204
+ },
205
+ content: {
206
+ type: "tableContent",
207
+ columnWidths: [100, 100],
208
+ rows: [
209
+ {
210
+ cells: [
211
+ {
212
+ type: "tableCell",
213
+ props: {
214
+ backgroundColor: "default",
215
+ textColor: "default",
216
+ textAlignment: "left",
217
+ colspan: 1,
218
+ rowspan: 2,
219
+ },
220
+ content: [
221
+ { type: "text", text: "1-1", styles: {} },
222
+ { type: "text", text: "2-1", styles: {} },
223
+ ],
224
+ },
225
+ {
226
+ type: "tableCell",
227
+ props: {
228
+ backgroundColor: "default",
229
+ textColor: "default",
230
+ textAlignment: "left",
231
+ colspan: 1,
232
+ rowspan: 1,
233
+ },
234
+ content: [{ type: "text", text: "1-2", styles: {} }],
235
+ },
236
+ {
237
+ type: "tableCell",
238
+ props: {
239
+ backgroundColor: "default",
240
+ textColor: "default",
241
+ textAlignment: "left",
242
+ colspan: 1,
243
+ rowspan: 1,
244
+ },
245
+ content: [{ type: "text", text: "1-3", styles: {} }],
246
+ },
247
+ ],
248
+ },
249
+ {
250
+ cells: [
251
+ {
252
+ type: "tableCell",
253
+ props: {
254
+ backgroundColor: "default",
255
+ textColor: "default",
256
+ textAlignment: "left",
257
+ colspan: 1,
258
+ rowspan: 1,
259
+ },
260
+ content: [{ type: "text", text: "2-2", styles: {} }],
261
+ },
262
+ {
263
+ type: "tableCell",
264
+ props: {
265
+ backgroundColor: "default",
266
+ textColor: "default",
267
+ textAlignment: "left",
268
+ colspan: 1,
269
+ rowspan: 1,
270
+ },
271
+ content: [{ type: "text", text: "2-3", styles: {} }],
272
+ },
273
+ ],
274
+ },
275
+ {
276
+ cells: [
277
+ {
278
+ type: "tableCell",
279
+ props: {
280
+ backgroundColor: "default",
281
+ textColor: "default",
282
+ textAlignment: "left",
283
+ colspan: 1,
284
+ rowspan: 1,
285
+ },
286
+ content: [{ type: "text", text: "3-1", styles: {} }],
287
+ },
288
+ {
289
+ type: "tableCell",
290
+ props: {
291
+ backgroundColor: "default",
292
+ textColor: "default",
293
+ textAlignment: "left",
294
+ colspan: 1,
295
+ rowspan: 1,
296
+ },
297
+ content: [{ type: "text", text: "3-2", styles: {} }],
298
+ },
299
+ {
300
+ type: "tableCell",
301
+ props: {
302
+ backgroundColor: "default",
303
+ textColor: "default",
304
+ textAlignment: "left",
305
+ colspan: 1,
306
+ rowspan: 1,
307
+ },
308
+ content: [{ type: "text", text: "3-3", styles: {} }],
309
+ },
310
+ ],
311
+ },
312
+ ],
313
+ },
314
+ children: [],
315
+ } satisfies Block<
316
+ {
317
+ table: DefaultBlockSchema["table"];
318
+ },
319
+ any,
320
+ any
321
+ >;
322
+
323
+ /**
324
+ * Normal table
325
+ * | 1-1 | 1-2 | 1-3 |
326
+ * | 2-1 | 2-2 | 2-3 |
327
+ * | 3-1 | 3-2 | 3-3 |
328
+ *
329
+ * Table with colspan and rowspan
330
+ * | 1-1 | 1-2 | 1-3 |
331
+ * | 1-1 | 2-1 | 2-1 |
332
+ * | 3-1 | 3-2 | 3-3 |
333
+ */
334
+ const tableWithColspanAndRowspan = {
335
+ type: "table",
336
+ id: "table-0",
337
+ props: {
338
+ textColor: "default",
339
+ },
340
+ content: {
341
+ type: "tableContent",
342
+ columnWidths: [100, 100],
343
+ rows: [
344
+ {
345
+ cells: [
346
+ {
347
+ type: "tableCell",
348
+ props: {
349
+ backgroundColor: "default",
350
+ textColor: "default",
351
+ textAlignment: "left",
352
+ colspan: 1,
353
+ rowspan: 2,
354
+ },
355
+ content: [
356
+ { type: "text", text: "1-1", styles: {} },
357
+ { type: "text", text: "2-1", styles: {} },
358
+ ],
359
+ },
360
+ {
361
+ type: "tableCell",
362
+ props: {
363
+ backgroundColor: "default",
364
+ textColor: "default",
365
+ textAlignment: "left",
366
+ colspan: 1,
367
+ rowspan: 1,
368
+ },
369
+ content: [{ type: "text", text: "1-2", styles: {} }],
370
+ },
371
+ {
372
+ type: "tableCell",
373
+ props: {
374
+ backgroundColor: "default",
375
+ textColor: "default",
376
+ textAlignment: "left",
377
+ colspan: 1,
378
+ rowspan: 1,
379
+ },
380
+ content: [{ type: "text", text: "1-3", styles: {} }],
381
+ },
382
+ ],
383
+ },
384
+ {
385
+ cells: [
386
+ {
387
+ type: "tableCell",
388
+ props: {
389
+ backgroundColor: "default",
390
+ textColor: "default",
391
+ textAlignment: "left",
392
+ colspan: 2,
393
+ rowspan: 1,
394
+ },
395
+ content: [
396
+ { type: "text", text: "2-2", styles: {} },
397
+ { type: "text", text: "2-3", styles: {} },
398
+ ],
399
+ },
400
+ ],
401
+ },
402
+ {
403
+ cells: [
404
+ {
405
+ type: "tableCell",
406
+ props: {
407
+ backgroundColor: "default",
408
+ textColor: "default",
409
+ textAlignment: "left",
410
+ colspan: 1,
411
+ rowspan: 1,
412
+ },
413
+ content: [{ type: "text", text: "3-1", styles: {} }],
414
+ },
415
+ {
416
+ type: "tableCell",
417
+ props: {
418
+ backgroundColor: "default",
419
+ textColor: "default",
420
+ textAlignment: "left",
421
+ colspan: 1,
422
+ rowspan: 1,
423
+ },
424
+ content: [{ type: "text", text: "3-2", styles: {} }],
425
+ },
426
+ {
427
+ type: "tableCell",
428
+ props: {
429
+ backgroundColor: "default",
430
+ textColor: "default",
431
+ textAlignment: "left",
432
+ colspan: 1,
433
+ rowspan: 1,
434
+ },
435
+ content: [{ type: "text", text: "3-3", styles: {} }],
436
+ },
437
+ ],
438
+ },
439
+ ],
440
+ },
441
+ children: [],
442
+ } satisfies Block<
443
+ {
444
+ table: DefaultBlockSchema["table"];
445
+ },
446
+ any,
447
+ any
448
+ >;
449
+
450
+ /**
451
+ * Normal table
452
+ * | 1-1 | 1-2 | 1-3 |
453
+ * | 2-1 | 2-2 | 2-3 |
454
+ * | 3-1 | 3-2 | 3-3 |
455
+ *
456
+ * Table with colspans and rowspans
457
+ * | 1-1 | 1-2 | 1-2 |
458
+ * | 1-1 | 2-1 | 2-1 |
459
+ * | 3-1 | 2-1 | 2-1 |
460
+ */
461
+ const tableWithColspansAndRowspans = {
462
+ type: "table",
463
+ id: "table-0",
464
+ props: {
465
+ textColor: "default",
466
+ },
467
+ content: {
468
+ type: "tableContent",
469
+ columnWidths: [100, 100],
470
+ rows: [
471
+ {
472
+ cells: [
473
+ {
474
+ type: "tableCell",
475
+ props: {
476
+ backgroundColor: "default",
477
+ textColor: "default",
478
+ textAlignment: "left",
479
+ colspan: 1,
480
+ rowspan: 2,
481
+ },
482
+ content: [
483
+ { type: "text", text: "1-1", styles: {} },
484
+ { type: "text", text: "2-1", styles: {} },
485
+ ],
486
+ },
487
+ {
488
+ type: "tableCell",
489
+ props: {
490
+ backgroundColor: "default",
491
+ textColor: "default",
492
+ textAlignment: "left",
493
+ colspan: 2,
494
+ rowspan: 1,
495
+ },
496
+ content: [
497
+ { type: "text", text: "1-2", styles: {} },
498
+ { type: "text", text: "1-3", styles: {} },
499
+ ],
500
+ },
501
+ ],
502
+ },
503
+ {
504
+ cells: [
505
+ {
506
+ type: "tableCell",
507
+ props: {
508
+ backgroundColor: "default",
509
+ textColor: "default",
510
+ textAlignment: "left",
511
+ colspan: 2,
512
+ rowspan: 2,
513
+ },
514
+ content: [
515
+ { type: "text", text: "2-2", styles: {} },
516
+ { type: "text", text: "2-3", styles: {} },
517
+ { type: "text", text: "3-2", styles: {} },
518
+ { type: "text", text: "3-3", styles: {} },
519
+ ],
520
+ },
521
+ ],
522
+ },
523
+ {
524
+ cells: [
525
+ {
526
+ type: "tableCell",
527
+ props: {
528
+ backgroundColor: "default",
529
+ textColor: "default",
530
+ textAlignment: "left",
531
+ colspan: 1,
532
+ rowspan: 1,
533
+ },
534
+ content: [{ type: "text", text: "3-1", styles: {} }],
535
+ },
536
+ ],
537
+ },
538
+ ],
539
+ },
540
+ children: [],
541
+ } satisfies Block<
542
+ {
543
+ table: DefaultBlockSchema["table"];
544
+ },
545
+ any,
546
+ any
547
+ >;
548
+
549
+ /**
550
+ * Normal table
551
+ * | 1-1 | 1-2 | 1-3 | 1-4 |
552
+ * | 2-1 | 2-2 | 2-3 | 2-4 |
553
+ * | 3-1 | 3-2 | 3-3 | 3-4 |
554
+ *
555
+ * Table with complex rowspans and colspans
556
+ * | 1-1 | 1-1 | 1-2 | 1-3 |
557
+ * | 1-1 | 1-1 | 2-1 | 2-2 |
558
+ * | 3-1 | 3-2 | 2-1 | 3-3 |
559
+ */
560
+ const tableWithComplexRowspansAndColspans = {
561
+ type: "table",
562
+ id: "table-0",
563
+ props: {
564
+ textColor: "default",
565
+ },
566
+ content: {
567
+ type: "tableContent",
568
+ columnWidths: [100, 100],
569
+ rows: [
570
+ {
571
+ cells: [
572
+ {
573
+ type: "tableCell",
574
+ props: {
575
+ backgroundColor: "default",
576
+ textColor: "default",
577
+ textAlignment: "left",
578
+ colspan: 2,
579
+ rowspan: 2,
580
+ },
581
+ content: [
582
+ { type: "text", text: "1-1", styles: {} },
583
+ { type: "text", text: "1-2", styles: {} },
584
+ { type: "text", text: "2-1", styles: {} },
585
+ { type: "text", text: "2-2", styles: {} },
586
+ ],
587
+ },
588
+ {
589
+ type: "tableCell",
590
+ props: {
591
+ backgroundColor: "default",
592
+ textColor: "default",
593
+ textAlignment: "left",
594
+ colspan: 1,
595
+ rowspan: 1,
596
+ },
597
+ content: [{ type: "text", text: "1-3", styles: {} }],
598
+ },
599
+ {
600
+ type: "tableCell",
601
+ props: {
602
+ backgroundColor: "default",
603
+ textColor: "default",
604
+ textAlignment: "left",
605
+ colspan: 1,
606
+ rowspan: 1,
607
+ },
608
+ content: [{ type: "text", text: "1-4", styles: {} }],
609
+ },
610
+ ],
611
+ },
612
+ {
613
+ cells: [
614
+ {
615
+ type: "tableCell",
616
+ props: {
617
+ backgroundColor: "default",
618
+ textColor: "default",
619
+ textAlignment: "left",
620
+ colspan: 1,
621
+ rowspan: 2,
622
+ },
623
+ content: [
624
+ { type: "text", text: "2-3", styles: {} },
625
+ { type: "text", text: "3-3", styles: {} },
626
+ ],
627
+ },
628
+ {
629
+ type: "tableCell",
630
+ props: {
631
+ backgroundColor: "default",
632
+ textColor: "default",
633
+ textAlignment: "left",
634
+ colspan: 1,
635
+ rowspan: 1,
636
+ },
637
+ content: [{ type: "text", text: "2-4", styles: {} }],
638
+ },
639
+ ],
640
+ },
641
+ {
642
+ cells: [
643
+ {
644
+ type: "tableCell",
645
+ props: {
646
+ backgroundColor: "default",
647
+ textColor: "default",
648
+ textAlignment: "left",
649
+ colspan: 1,
650
+ rowspan: 1,
651
+ },
652
+ content: [{ type: "text", text: "3-1", styles: {} }],
653
+ },
654
+ {
655
+ type: "tableCell",
656
+ props: {
657
+ backgroundColor: "default",
658
+ textColor: "default",
659
+ textAlignment: "left",
660
+ colspan: 1,
661
+ rowspan: 1,
662
+ },
663
+ content: [{ type: "text", text: "3-2", styles: {} }],
664
+ },
665
+ {
666
+ type: "tableCell",
667
+ props: {
668
+ backgroundColor: "default",
669
+ textColor: "default",
670
+ textAlignment: "left",
671
+ colspan: 1,
672
+ rowspan: 1,
673
+ },
674
+ content: [{ type: "text", text: "3-3", styles: {} }],
675
+ },
676
+ ],
677
+ },
678
+ ],
679
+ },
680
+ children: [],
681
+ } satisfies Block<
682
+ {
683
+ table: DefaultBlockSchema["table"];
684
+ },
685
+ any,
686
+ any
687
+ >;
688
+
689
+ describe("Test getAbsoluteTableCellIndices", () => {
690
+ it("should resolve relative table cell indices to absolute table cell indices", () => {
691
+ expect(getAbsoluteTableCells({ row: 0, col: 0 }, simpleTable)).toEqual({
692
+ row: 0,
693
+ col: 0,
694
+ cell: simpleTable.content.rows[0].cells[0],
695
+ });
696
+ expect(getAbsoluteTableCells({ row: 0, col: 1 }, simpleTable)).toEqual({
697
+ row: 0,
698
+ col: 1,
699
+ cell: simpleTable.content.rows[0].cells[1],
700
+ });
701
+ expect(getAbsoluteTableCells({ row: 1, col: 0 }, simpleTable)).toEqual({
702
+ row: 1,
703
+ col: 0,
704
+ cell: simpleTable.content.rows[1].cells[0],
705
+ });
706
+ expect(getAbsoluteTableCells({ row: 1, col: 1 }, simpleTable)).toEqual({
707
+ row: 1,
708
+ col: 1,
709
+ cell: simpleTable.content.rows[1].cells[1],
710
+ });
711
+ });
712
+
713
+ it("should resolve relative table cell indices to absolute table cell indices with colspan", () => {
714
+ expect(getAbsoluteTableCells({ row: 0, col: 0 }, tableWithColspan)).toEqual(
715
+ {
716
+ row: 0,
717
+ col: 0,
718
+ cell: tableWithColspan.content.rows[0].cells[0],
719
+ }
720
+ );
721
+ expect(getAbsoluteTableCells({ row: 0, col: 1 }, tableWithColspan)).toEqual(
722
+ {
723
+ row: 0,
724
+ col: 2,
725
+ cell: tableWithColspan.content.rows[0].cells[1],
726
+ }
727
+ );
728
+ expect(getAbsoluteTableCells({ row: 1, col: 0 }, tableWithColspan)).toEqual(
729
+ {
730
+ row: 1,
731
+ col: 0,
732
+ cell: tableWithColspan.content.rows[1].cells[0],
733
+ }
734
+ );
735
+ expect(getAbsoluteTableCells({ row: 1, col: 1 }, tableWithColspan)).toEqual(
736
+ {
737
+ row: 1,
738
+ col: 1,
739
+ cell: tableWithColspan.content.rows[1].cells[1],
740
+ }
741
+ );
742
+ expect(getAbsoluteTableCells({ row: 1, col: 2 }, tableWithColspan)).toEqual(
743
+ {
744
+ row: 1,
745
+ col: 2,
746
+ cell: tableWithColspan.content.rows[1].cells[2],
747
+ }
748
+ );
749
+ });
750
+
751
+ it("should resolve relative table cell indices to absolute table cell indices with rowspan", () => {
752
+ expect(getAbsoluteTableCells({ row: 0, col: 0 }, tableWithRowspan)).toEqual(
753
+ {
754
+ row: 0,
755
+ col: 0,
756
+ cell: tableWithRowspan.content.rows[0].cells[0],
757
+ }
758
+ );
759
+ expect(getAbsoluteTableCells({ row: 0, col: 1 }, tableWithRowspan)).toEqual(
760
+ {
761
+ row: 0,
762
+ col: 1,
763
+ cell: tableWithRowspan.content.rows[0].cells[1],
764
+ }
765
+ );
766
+ expect(getAbsoluteTableCells({ row: 0, col: 2 }, tableWithRowspan)).toEqual(
767
+ {
768
+ row: 0,
769
+ col: 2,
770
+ cell: tableWithRowspan.content.rows[0].cells[2],
771
+ }
772
+ );
773
+ expect(getAbsoluteTableCells({ row: 1, col: 0 }, tableWithRowspan)).toEqual(
774
+ {
775
+ row: 1,
776
+ col: 1,
777
+ cell: tableWithRowspan.content.rows[1].cells[0],
778
+ }
779
+ );
780
+ expect(getAbsoluteTableCells({ row: 1, col: 1 }, tableWithRowspan)).toEqual(
781
+ {
782
+ row: 1,
783
+ col: 2,
784
+ cell: tableWithRowspan.content.rows[1].cells[1],
785
+ }
786
+ );
787
+ expect(getAbsoluteTableCells({ row: 2, col: 0 }, tableWithRowspan)).toEqual(
788
+ {
789
+ row: 2,
790
+ col: 0,
791
+ cell: tableWithRowspan.content.rows[2].cells[0],
792
+ }
793
+ );
794
+ expect(getAbsoluteTableCells({ row: 2, col: 1 }, tableWithRowspan)).toEqual(
795
+ {
796
+ row: 2,
797
+ col: 1,
798
+ cell: tableWithRowspan.content.rows[2].cells[1],
799
+ }
800
+ );
801
+ });
802
+
803
+ it("should resolve complex rowspans and colspans", () => {
804
+ expect(
805
+ getAbsoluteTableCells(
806
+ { row: 0, col: 0 },
807
+ tableWithComplexRowspansAndColspans
808
+ )
809
+ ).toEqual({
810
+ row: 0,
811
+ col: 0,
812
+ cell: tableWithComplexRowspansAndColspans.content.rows[0].cells[0],
813
+ });
814
+ expect(
815
+ getAbsoluteTableCells(
816
+ { row: 0, col: 1 },
817
+ tableWithComplexRowspansAndColspans
818
+ )
819
+ ).toEqual({
820
+ row: 0,
821
+ col: 2,
822
+ cell: tableWithComplexRowspansAndColspans.content.rows[0].cells[1],
823
+ });
824
+ expect(
825
+ getAbsoluteTableCells(
826
+ { row: 0, col: 2 },
827
+ tableWithComplexRowspansAndColspans
828
+ )
829
+ ).toEqual({
830
+ row: 0,
831
+ col: 3,
832
+ cell: tableWithComplexRowspansAndColspans.content.rows[0].cells[2],
833
+ });
834
+ expect(
835
+ getAbsoluteTableCells(
836
+ { row: 1, col: 0 },
837
+ tableWithComplexRowspansAndColspans
838
+ )
839
+ ).toEqual({
840
+ row: 1,
841
+ col: 2,
842
+ cell: tableWithComplexRowspansAndColspans.content.rows[1].cells[0],
843
+ });
844
+ expect(
845
+ getAbsoluteTableCells(
846
+ { row: 1, col: 1 },
847
+ tableWithComplexRowspansAndColspans
848
+ )
849
+ ).toEqual({
850
+ row: 1,
851
+ col: 3,
852
+ cell: tableWithComplexRowspansAndColspans.content.rows[1].cells[1],
853
+ });
854
+ expect(
855
+ getAbsoluteTableCells(
856
+ { row: 2, col: 0 },
857
+ tableWithComplexRowspansAndColspans
858
+ )
859
+ ).toEqual({
860
+ row: 2,
861
+ col: 0,
862
+ cell: tableWithComplexRowspansAndColspans.content.rows[2].cells[0],
863
+ });
864
+ expect(
865
+ getAbsoluteTableCells(
866
+ { row: 2, col: 1 },
867
+ tableWithComplexRowspansAndColspans
868
+ )
869
+ ).toEqual({
870
+ row: 2,
871
+ col: 1,
872
+ cell: tableWithComplexRowspansAndColspans.content.rows[2].cells[1],
873
+ });
874
+ expect(
875
+ getAbsoluteTableCells(
876
+ { row: 2, col: 2 },
877
+ tableWithComplexRowspansAndColspans
878
+ )
879
+ ).toEqual({
880
+ row: 2,
881
+ col: 3,
882
+ cell: tableWithComplexRowspansAndColspans.content.rows[2].cells[2],
883
+ });
884
+ });
885
+ });
886
+
887
+ describe("Test getRelativeTableCellIndices", () => {
888
+ it("should resolve absolute table cell indices to relative table cell indices", () => {
889
+ expect(getRelativeTableCells({ row: 0, col: 0 }, simpleTable)).toEqual({
890
+ row: 0,
891
+ col: 0,
892
+ cell: simpleTable.content.rows[0].cells[0],
893
+ });
894
+ expect(getRelativeTableCells({ row: 0, col: 1 }, simpleTable)).toEqual({
895
+ row: 0,
896
+ col: 1,
897
+ cell: simpleTable.content.rows[0].cells[1],
898
+ });
899
+ expect(getRelativeTableCells({ row: 1, col: 0 }, simpleTable)).toEqual({
900
+ row: 1,
901
+ col: 0,
902
+ cell: simpleTable.content.rows[1].cells[0],
903
+ });
904
+ expect(getRelativeTableCells({ row: 1, col: 1 }, simpleTable)).toEqual({
905
+ row: 1,
906
+ col: 1,
907
+ cell: simpleTable.content.rows[1].cells[1],
908
+ });
909
+ });
910
+
911
+ it("should resolve absolute table cell indices to relative table cell indices with colspan", () => {
912
+ expect(getRelativeTableCells({ row: 0, col: 0 }, tableWithColspan)).toEqual(
913
+ {
914
+ row: 0,
915
+ col: 0,
916
+ cell: tableWithColspan.content.rows[0].cells[0],
917
+ }
918
+ );
919
+ expect(getRelativeTableCells({ row: 0, col: 1 }, tableWithColspan)).toEqual(
920
+ {
921
+ row: 0,
922
+ col: 0,
923
+ cell: tableWithColspan.content.rows[0].cells[0],
924
+ }
925
+ );
926
+ expect(getRelativeTableCells({ row: 0, col: 2 }, tableWithColspan)).toEqual(
927
+ {
928
+ row: 0,
929
+ col: 1,
930
+ cell: tableWithColspan.content.rows[0].cells[1],
931
+ }
932
+ );
933
+ expect(getRelativeTableCells({ row: 1, col: 0 }, tableWithColspan)).toEqual(
934
+ {
935
+ row: 1,
936
+ col: 0,
937
+ cell: tableWithColspan.content.rows[1].cells[0],
938
+ }
939
+ );
940
+ expect(getRelativeTableCells({ row: 1, col: 1 }, tableWithColspan)).toEqual(
941
+ {
942
+ row: 1,
943
+ col: 1,
944
+ cell: tableWithColspan.content.rows[1].cells[1],
945
+ }
946
+ );
947
+ expect(getRelativeTableCells({ row: 1, col: 2 }, tableWithColspan)).toEqual(
948
+ {
949
+ row: 1,
950
+ col: 2,
951
+ cell: tableWithColspan.content.rows[1].cells[2],
952
+ }
953
+ );
954
+ });
955
+
956
+ it("should resolve absolute table cell indices to relative table cell indices with rowspan", () => {
957
+ expect(getRelativeTableCells({ row: 0, col: 0 }, tableWithRowspan)).toEqual(
958
+ {
959
+ row: 0,
960
+ col: 0,
961
+ cell: tableWithRowspan.content.rows[0].cells[0],
962
+ }
963
+ );
964
+ expect(getRelativeTableCells({ row: 0, col: 1 }, tableWithRowspan)).toEqual(
965
+ {
966
+ row: 0,
967
+ col: 1,
968
+ cell: tableWithRowspan.content.rows[0].cells[1],
969
+ }
970
+ );
971
+ expect(getRelativeTableCells({ row: 0, col: 2 }, tableWithRowspan)).toEqual(
972
+ {
973
+ row: 0,
974
+ col: 2,
975
+ cell: tableWithRowspan.content.rows[0].cells[2],
976
+ }
977
+ );
978
+ expect(getRelativeTableCells({ row: 1, col: 0 }, tableWithRowspan)).toEqual(
979
+ {
980
+ row: 0,
981
+ col: 0,
982
+ cell: tableWithRowspan.content.rows[0].cells[0],
983
+ }
984
+ );
985
+ expect(getRelativeTableCells({ row: 1, col: 1 }, tableWithRowspan)).toEqual(
986
+ {
987
+ row: 1,
988
+ col: 0,
989
+ cell: tableWithRowspan.content.rows[1].cells[0],
990
+ }
991
+ );
992
+ expect(getRelativeTableCells({ row: 1, col: 2 }, tableWithRowspan)).toEqual(
993
+ {
994
+ row: 1,
995
+ col: 1,
996
+ cell: tableWithRowspan.content.rows[1].cells[1],
997
+ }
998
+ );
999
+ expect(getRelativeTableCells({ row: 2, col: 0 }, tableWithRowspan)).toEqual(
1000
+ {
1001
+ row: 2,
1002
+ col: 0,
1003
+ cell: tableWithRowspan.content.rows[2].cells[0],
1004
+ }
1005
+ );
1006
+ expect(getRelativeTableCells({ row: 2, col: 1 }, tableWithRowspan)).toEqual(
1007
+ {
1008
+ row: 2,
1009
+ col: 1,
1010
+ cell: tableWithRowspan.content.rows[2].cells[1],
1011
+ }
1012
+ );
1013
+ expect(getRelativeTableCells({ row: 2, col: 2 }, tableWithRowspan)).toEqual(
1014
+ {
1015
+ row: 2,
1016
+ col: 2,
1017
+ cell: tableWithRowspan.content.rows[2].cells[2],
1018
+ }
1019
+ );
1020
+ });
1021
+
1022
+ it("should resolve absolute table cell indices to relative table cell indices with colspan and rowspan", () => {
1023
+ expect(
1024
+ getRelativeTableCells({ row: 0, col: 0 }, tableWithColspanAndRowspan)
1025
+ ).toEqual({
1026
+ row: 0,
1027
+ col: 0,
1028
+ cell: tableWithColspanAndRowspan.content.rows[0].cells[0],
1029
+ });
1030
+ expect(
1031
+ getRelativeTableCells({ row: 0, col: 1 }, tableWithColspanAndRowspan)
1032
+ ).toEqual({
1033
+ row: 0,
1034
+ col: 1,
1035
+ cell: tableWithColspanAndRowspan.content.rows[0].cells[1],
1036
+ });
1037
+ expect(
1038
+ getRelativeTableCells({ row: 0, col: 2 }, tableWithColspanAndRowspan)
1039
+ ).toEqual({
1040
+ row: 0,
1041
+ col: 2,
1042
+ cell: tableWithColspanAndRowspan.content.rows[0].cells[2],
1043
+ });
1044
+ expect(
1045
+ getRelativeTableCells({ row: 1, col: 0 }, tableWithColspanAndRowspan)
1046
+ ).toEqual({
1047
+ row: 0,
1048
+ col: 0,
1049
+ cell: tableWithColspanAndRowspan.content.rows[0].cells[0],
1050
+ });
1051
+ expect(
1052
+ getRelativeTableCells({ row: 1, col: 1 }, tableWithColspanAndRowspan)
1053
+ ).toEqual({
1054
+ row: 1,
1055
+ col: 0,
1056
+ cell: tableWithColspanAndRowspan.content.rows[1].cells[0],
1057
+ });
1058
+ expect(
1059
+ getRelativeTableCells({ row: 1, col: 2 }, tableWithColspanAndRowspan)
1060
+ ).toEqual({
1061
+ row: 1,
1062
+ col: 0,
1063
+ cell: tableWithColspanAndRowspan.content.rows[1].cells[0],
1064
+ });
1065
+ expect(
1066
+ getRelativeTableCells({ row: 2, col: 0 }, tableWithColspanAndRowspan)
1067
+ ).toEqual({
1068
+ row: 2,
1069
+ col: 0,
1070
+ cell: tableWithColspanAndRowspan.content.rows[2].cells[0],
1071
+ });
1072
+ expect(
1073
+ getRelativeTableCells({ row: 2, col: 1 }, tableWithColspanAndRowspan)
1074
+ ).toEqual({
1075
+ row: 2,
1076
+ col: 1,
1077
+ cell: tableWithColspanAndRowspan.content.rows[2].cells[1],
1078
+ });
1079
+ expect(
1080
+ getRelativeTableCells({ row: 2, col: 2 }, tableWithColspanAndRowspan)
1081
+ ).toEqual({
1082
+ row: 2,
1083
+ col: 2,
1084
+ cell: tableWithColspanAndRowspan.content.rows[2].cells[2],
1085
+ });
1086
+ });
1087
+
1088
+ it("should resolve absolute table cell indices to relative table cell indices with colspans and rowspans", () => {
1089
+ expect(
1090
+ getRelativeTableCells({ row: 0, col: 0 }, tableWithColspansAndRowspans)
1091
+ ).toEqual({
1092
+ row: 0,
1093
+ col: 0,
1094
+ cell: tableWithColspansAndRowspans.content.rows[0].cells[0],
1095
+ });
1096
+ expect(
1097
+ getRelativeTableCells({ row: 0, col: 1 }, tableWithColspansAndRowspans)
1098
+ ).toEqual({
1099
+ row: 0,
1100
+ col: 1,
1101
+ cell: tableWithColspansAndRowspans.content.rows[0].cells[1],
1102
+ });
1103
+ expect(
1104
+ getRelativeTableCells({ row: 0, col: 2 }, tableWithColspansAndRowspans)
1105
+ ).toEqual({
1106
+ row: 0,
1107
+ col: 1,
1108
+ cell: tableWithColspansAndRowspans.content.rows[0].cells[1],
1109
+ });
1110
+ expect(
1111
+ getRelativeTableCells({ row: 1, col: 0 }, tableWithColspansAndRowspans)
1112
+ ).toEqual({
1113
+ row: 0,
1114
+ col: 0,
1115
+ cell: tableWithColspansAndRowspans.content.rows[0].cells[0],
1116
+ });
1117
+ expect(
1118
+ getRelativeTableCells({ row: 1, col: 1 }, tableWithColspansAndRowspans)
1119
+ ).toEqual({
1120
+ row: 1,
1121
+ col: 0,
1122
+ cell: tableWithColspansAndRowspans.content.rows[1].cells[0],
1123
+ });
1124
+ expect(
1125
+ getRelativeTableCells({ row: 1, col: 2 }, tableWithColspansAndRowspans)
1126
+ ).toEqual({
1127
+ row: 1,
1128
+ col: 0,
1129
+ cell: tableWithColspansAndRowspans.content.rows[1].cells[0],
1130
+ });
1131
+ expect(
1132
+ getRelativeTableCells({ row: 2, col: 0 }, tableWithColspansAndRowspans)
1133
+ ).toEqual({
1134
+ row: 2,
1135
+ col: 0,
1136
+ cell: tableWithColspansAndRowspans.content.rows[2].cells[0],
1137
+ });
1138
+ expect(
1139
+ getRelativeTableCells({ row: 2, col: 1 }, tableWithColspansAndRowspans)
1140
+ ).toEqual({
1141
+ row: 1,
1142
+ col: 0,
1143
+ cell: tableWithColspansAndRowspans.content.rows[1].cells[0],
1144
+ });
1145
+ expect(
1146
+ getRelativeTableCells({ row: 2, col: 2 }, tableWithColspansAndRowspans)
1147
+ ).toEqual({
1148
+ row: 1,
1149
+ col: 0,
1150
+ cell: tableWithColspansAndRowspans.content.rows[1].cells[0],
1151
+ });
1152
+ });
1153
+ });
1154
+
1155
+ describe("resolveAbsoluteTableCellIndices and resolveRelativeTableCellIndices should be inverse functions", () => {
1156
+ it("should work for simple tables", () => {
1157
+ for (let row = 0; row < simpleTable.content.rows.length; row++) {
1158
+ for (
1159
+ let col = 0;
1160
+ col < simpleTable.content.rows[row].cells.length;
1161
+ col++
1162
+ ) {
1163
+ expect(
1164
+ getRelativeTableCells(
1165
+ getAbsoluteTableCells({ row, col }, simpleTable),
1166
+ simpleTable
1167
+ )
1168
+ ).toEqual({ row, col, cell: simpleTable.content.rows[row].cells[col] });
1169
+ }
1170
+ }
1171
+ });
1172
+ it("should work for tables with colspans", () => {
1173
+ for (let row = 0; row < tableWithColspan.content.rows.length; row++) {
1174
+ for (
1175
+ let col = 0;
1176
+ col < tableWithColspan.content.rows[row].cells.length;
1177
+ col++
1178
+ ) {
1179
+ expect(
1180
+ getRelativeTableCells(
1181
+ getAbsoluteTableCells({ row, col }, tableWithColspan),
1182
+ tableWithColspan
1183
+ )
1184
+ ).toEqual({
1185
+ row,
1186
+ col,
1187
+ cell: tableWithColspan.content.rows[row].cells[col],
1188
+ });
1189
+ }
1190
+ }
1191
+ });
1192
+
1193
+ it("should work for tables with rowspans", () => {
1194
+ for (let row = 0; row < tableWithRowspan.content.rows.length; row++) {
1195
+ for (
1196
+ let col = 0;
1197
+ col < tableWithRowspan.content.rows[row].cells.length;
1198
+ col++
1199
+ ) {
1200
+ expect(
1201
+ getRelativeTableCells(
1202
+ getAbsoluteTableCells({ row, col }, tableWithRowspan),
1203
+ tableWithRowspan
1204
+ )
1205
+ ).toEqual({
1206
+ row,
1207
+ col,
1208
+ cell: tableWithRowspan.content.rows[row].cells[col],
1209
+ });
1210
+ }
1211
+ }
1212
+ });
1213
+
1214
+ it("should work for tables with colspans and rowspans", () => {
1215
+ for (
1216
+ let row = 0;
1217
+ row < tableWithColspanAndRowspan.content.rows.length;
1218
+ row++
1219
+ ) {
1220
+ for (
1221
+ let col = 0;
1222
+ col < tableWithColspanAndRowspan.content.rows[row].cells.length;
1223
+ col++
1224
+ ) {
1225
+ expect(
1226
+ getRelativeTableCells(
1227
+ getAbsoluteTableCells({ row, col }, tableWithColspanAndRowspan),
1228
+ tableWithColspanAndRowspan
1229
+ )
1230
+ ).toEqual({
1231
+ row,
1232
+ col,
1233
+ cell: tableWithColspanAndRowspan.content.rows[row].cells[col],
1234
+ });
1235
+ }
1236
+ }
1237
+ });
1238
+
1239
+ it("should work for tables with complex rowspans and colspans", () => {
1240
+ for (
1241
+ let row = 0;
1242
+ row < tableWithComplexRowspansAndColspans.content.rows.length;
1243
+ row++
1244
+ ) {
1245
+ for (
1246
+ let col = 0;
1247
+ col <
1248
+ tableWithComplexRowspansAndColspans.content.rows[row].cells.length;
1249
+ col++
1250
+ ) {
1251
+ expect(
1252
+ getRelativeTableCells(
1253
+ getAbsoluteTableCells(
1254
+ { row, col },
1255
+ tableWithComplexRowspansAndColspans
1256
+ ),
1257
+ tableWithComplexRowspansAndColspans
1258
+ )
1259
+ ).toEqual({
1260
+ row,
1261
+ col,
1262
+ cell: tableWithComplexRowspansAndColspans.content.rows[row].cells[
1263
+ col
1264
+ ],
1265
+ });
1266
+ }
1267
+ }
1268
+ });
1269
+ });
1270
+
1271
+ describe("Test getRow", () => {
1272
+ it("should get the row of the table", () => {
1273
+ expect(getCellsAtRowHandle(simpleTable, 0)).toEqual(
1274
+ simpleTable.content.rows[0].cells.map((cell, col) => ({
1275
+ row: 0,
1276
+ col,
1277
+ cell,
1278
+ }))
1279
+ );
1280
+ });
1281
+
1282
+ it("should get the row of the table with colspan", () => {
1283
+ expect(getCellsAtRowHandle(tableWithColspan, 0)).toEqual([
1284
+ {
1285
+ row: 0,
1286
+ col: 0,
1287
+ cell: tableWithColspan.content.rows[0].cells[0],
1288
+ },
1289
+ {
1290
+ row: 0,
1291
+ col: 1,
1292
+ cell: tableWithColspan.content.rows[0].cells[1],
1293
+ },
1294
+ ]);
1295
+
1296
+ expect(getCellsAtRowHandle(tableWithColspan, 1)).toEqual([
1297
+ {
1298
+ row: 1,
1299
+ col: 0,
1300
+ cell: tableWithColspan.content.rows[1].cells[0],
1301
+ },
1302
+ {
1303
+ row: 1,
1304
+ col: 1,
1305
+ cell: tableWithColspan.content.rows[1].cells[1],
1306
+ },
1307
+ {
1308
+ row: 1,
1309
+ col: 2,
1310
+ cell: tableWithColspan.content.rows[1].cells[2],
1311
+ },
1312
+ ]);
1313
+ });
1314
+
1315
+ it("should get the row of the table with rowspan", () => {
1316
+ expect(getCellsAtRowHandle(tableWithRowspan, 0)).toEqual([
1317
+ {
1318
+ row: 0,
1319
+ col: 0,
1320
+ cell: tableWithRowspan.content.rows[0].cells[0],
1321
+ },
1322
+ {
1323
+ row: 0,
1324
+ col: 1,
1325
+ cell: tableWithRowspan.content.rows[0].cells[1],
1326
+ },
1327
+ {
1328
+ row: 0,
1329
+ col: 2,
1330
+ cell: tableWithRowspan.content.rows[0].cells[2],
1331
+ },
1332
+ ]);
1333
+
1334
+ expect(getCellsAtRowHandle(tableWithRowspan, 1)).toEqual([
1335
+ {
1336
+ row: 2,
1337
+ col: 0,
1338
+ cell: tableWithRowspan.content.rows[2].cells[0],
1339
+ },
1340
+ {
1341
+ row: 2,
1342
+ col: 1,
1343
+ cell: tableWithRowspan.content.rows[2].cells[1],
1344
+ },
1345
+ {
1346
+ row: 2,
1347
+ col: 2,
1348
+ cell: tableWithRowspan.content.rows[2].cells[2],
1349
+ },
1350
+ ]);
1351
+ });
1352
+
1353
+ it("should get the row of the table with complex rowspans and colspans", () => {
1354
+ expect(getCellsAtRowHandle(tableWithComplexRowspansAndColspans, 0)).toEqual(
1355
+ [
1356
+ {
1357
+ row: 0,
1358
+ col: 0,
1359
+ cell: tableWithComplexRowspansAndColspans.content.rows[0].cells[0],
1360
+ },
1361
+ {
1362
+ row: 0,
1363
+ col: 1,
1364
+ cell: tableWithComplexRowspansAndColspans.content.rows[0].cells[1],
1365
+ },
1366
+ {
1367
+ row: 0,
1368
+ col: 2,
1369
+ cell: tableWithComplexRowspansAndColspans.content.rows[0].cells[2],
1370
+ },
1371
+ ]
1372
+ );
1373
+ expect(getCellsAtRowHandle(tableWithComplexRowspansAndColspans, 1)).toEqual(
1374
+ [
1375
+ {
1376
+ row: 2,
1377
+ col: 0,
1378
+ cell: tableWithComplexRowspansAndColspans.content.rows[2].cells[0],
1379
+ },
1380
+ {
1381
+ row: 2,
1382
+ col: 1,
1383
+ cell: tableWithComplexRowspansAndColspans.content.rows[2].cells[1],
1384
+ },
1385
+ {
1386
+ row: 1,
1387
+ col: 0,
1388
+ cell: tableWithComplexRowspansAndColspans.content.rows[1].cells[0],
1389
+ },
1390
+ {
1391
+ row: 2,
1392
+ col: 2,
1393
+ cell: tableWithComplexRowspansAndColspans.content.rows[2].cells[2],
1394
+ },
1395
+ ]
1396
+ );
1397
+ expect(getCellsAtRowHandle(tableWithComplexRowspansAndColspans, 2)).toEqual(
1398
+ []
1399
+ );
1400
+ });
1401
+ });
1402
+
1403
+ describe("Test getColumn", () => {
1404
+ it("should get the column of the table", () => {
1405
+ expect(getCellsAtColumnHandle(simpleTable, 0)).toEqual([
1406
+ {
1407
+ row: 0,
1408
+ col: 0,
1409
+ cell: simpleTable.content.rows[0].cells[0],
1410
+ },
1411
+ {
1412
+ row: 1,
1413
+ col: 0,
1414
+ cell: simpleTable.content.rows[1].cells[0],
1415
+ },
1416
+ ]);
1417
+
1418
+ expect(getCellsAtColumnHandle(simpleTable, 1)).toEqual([
1419
+ {
1420
+ row: 0,
1421
+ col: 1,
1422
+ cell: simpleTable.content.rows[0].cells[1],
1423
+ },
1424
+ {
1425
+ row: 1,
1426
+ col: 1,
1427
+ cell: simpleTable.content.rows[1].cells[1],
1428
+ },
1429
+ ]);
1430
+ expect(getCellsAtColumnHandle(simpleTable, 2)).toEqual([]);
1431
+ });
1432
+
1433
+ it("should get the column of the table with colspan", () => {
1434
+ expect(getCellsAtColumnHandle(tableWithColspan, 0)).toEqual([
1435
+ {
1436
+ row: 0,
1437
+ col: 0,
1438
+ cell: tableWithColspan.content.rows[0].cells[0],
1439
+ },
1440
+ {
1441
+ row: 1,
1442
+ col: 0,
1443
+ cell: tableWithColspan.content.rows[1].cells[0],
1444
+ },
1445
+ ]);
1446
+
1447
+ expect(getCellsAtColumnHandle(tableWithColspan, 1)).toEqual([
1448
+ {
1449
+ row: 0,
1450
+ col: 1,
1451
+ cell: tableWithColspan.content.rows[0].cells[1],
1452
+ },
1453
+ {
1454
+ row: 1,
1455
+ col: 2,
1456
+ cell: tableWithColspan.content.rows[1].cells[2],
1457
+ },
1458
+ ]);
1459
+ expect(getCellsAtColumnHandle(tableWithColspan, 2)).toEqual([]);
1460
+ });
1461
+
1462
+ it("should get the column of the table with rowspan", () => {
1463
+ expect(getCellsAtColumnHandle(tableWithRowspan, 0)).toEqual([
1464
+ {
1465
+ row: 0,
1466
+ col: 0,
1467
+ cell: tableWithRowspan.content.rows[0].cells[0],
1468
+ },
1469
+ {
1470
+ row: 2,
1471
+ col: 0,
1472
+ cell: tableWithRowspan.content.rows[2].cells[0],
1473
+ },
1474
+ ]);
1475
+
1476
+ expect(getCellsAtColumnHandle(tableWithRowspan, 1)).toEqual([
1477
+ {
1478
+ row: 0,
1479
+ col: 1,
1480
+ cell: tableWithRowspan.content.rows[0].cells[1],
1481
+ },
1482
+ {
1483
+ row: 1,
1484
+ col: 0,
1485
+ cell: tableWithRowspan.content.rows[1].cells[0],
1486
+ },
1487
+ {
1488
+ row: 2,
1489
+ col: 1,
1490
+ cell: tableWithRowspan.content.rows[2].cells[1],
1491
+ },
1492
+ ]);
1493
+
1494
+ expect(getCellsAtColumnHandle(tableWithRowspan, 2)).toEqual([
1495
+ {
1496
+ row: 0,
1497
+ col: 2,
1498
+ cell: tableWithRowspan.content.rows[0].cells[2],
1499
+ },
1500
+ {
1501
+ row: 1,
1502
+ col: 1,
1503
+ cell: tableWithRowspan.content.rows[1].cells[1],
1504
+ },
1505
+ {
1506
+ row: 2,
1507
+ col: 2,
1508
+ cell: tableWithRowspan.content.rows[2].cells[2],
1509
+ },
1510
+ ]);
1511
+ expect(getCellsAtColumnHandle(tableWithRowspan, 3)).toEqual([]);
1512
+ });
1513
+
1514
+ it("should get the column of the table with complex rowspans and colspans", () => {
1515
+ expect(
1516
+ getCellsAtColumnHandle(tableWithComplexRowspansAndColspans, 0)
1517
+ ).toEqual([
1518
+ {
1519
+ row: 0,
1520
+ col: 0,
1521
+ cell: tableWithComplexRowspansAndColspans.content.rows[0].cells[0],
1522
+ },
1523
+ {
1524
+ row: 2,
1525
+ col: 0,
1526
+ cell: tableWithComplexRowspansAndColspans.content.rows[2].cells[0],
1527
+ },
1528
+ ]);
1529
+ expect(
1530
+ getCellsAtColumnHandle(tableWithComplexRowspansAndColspans, 1)
1531
+ ).toEqual([
1532
+ {
1533
+ row: 0,
1534
+ col: 1,
1535
+ cell: tableWithComplexRowspansAndColspans.content.rows[0].cells[1],
1536
+ },
1537
+ {
1538
+ row: 1,
1539
+ col: 0,
1540
+ cell: tableWithComplexRowspansAndColspans.content.rows[1].cells[0],
1541
+ },
1542
+ ]);
1543
+ expect(
1544
+ getCellsAtColumnHandle(tableWithComplexRowspansAndColspans, 2)
1545
+ ).toEqual([
1546
+ {
1547
+ row: 0,
1548
+ col: 2,
1549
+ cell: tableWithComplexRowspansAndColspans.content.rows[0].cells[2],
1550
+ },
1551
+ {
1552
+ row: 1,
1553
+ col: 1,
1554
+ cell: tableWithComplexRowspansAndColspans.content.rows[1].cells[1],
1555
+ },
1556
+ {
1557
+ row: 2,
1558
+ col: 2,
1559
+ cell: tableWithComplexRowspansAndColspans.content.rows[2].cells[2],
1560
+ },
1561
+ ]);
1562
+ expect(
1563
+ getCellsAtColumnHandle(tableWithComplexRowspansAndColspans, 3)
1564
+ ).toEqual([]);
1565
+ });
1566
+ });
1567
+
1568
+ describe("Test moveColumn", () => {
1569
+ it("should move the column of the table", () => {
1570
+ expect(moveColumn(simpleTable, 0, 1)).toEqual([
1571
+ {
1572
+ cells: [
1573
+ simpleTable.content.rows[0].cells[1],
1574
+ simpleTable.content.rows[0].cells[0],
1575
+ ],
1576
+ },
1577
+ {
1578
+ cells: [
1579
+ simpleTable.content.rows[1].cells[1],
1580
+ simpleTable.content.rows[1].cells[0],
1581
+ ],
1582
+ },
1583
+ ]);
1584
+ });
1585
+ });
1586
+
1587
+ describe("Test moveRow", () => {
1588
+ it("should move the row of the table", () => {
1589
+ expect(moveRow(simpleTable, 0, 1)).toEqual([
1590
+ {
1591
+ cells: [
1592
+ simpleTable.content.rows[1].cells[0],
1593
+ simpleTable.content.rows[1].cells[1],
1594
+ ],
1595
+ },
1596
+ {
1597
+ cells: [
1598
+ simpleTable.content.rows[0].cells[0],
1599
+ simpleTable.content.rows[0].cells[1],
1600
+ ],
1601
+ },
1602
+ ]);
1603
+ });
1604
+ });
1605
+
1606
+ describe("Test cropEmptyRowsOrColumns", () => {
1607
+ const emptyCell = {
1608
+ type: "tableCell" as const,
1609
+ props: {
1610
+ backgroundColor: "red",
1611
+ textColor: "blue",
1612
+ textAlignment: "left" as const,
1613
+ colspan: 1,
1614
+ rowspan: 1,
1615
+ },
1616
+ content: [{ type: "text" as const, text: "", styles: {} }],
1617
+ };
1618
+ it("should crop the empty rows of the table", () => {
1619
+ expect(
1620
+ cropEmptyRowsOrColumns(
1621
+ {
1622
+ ...simpleTable,
1623
+ content: {
1624
+ ...simpleTable.content,
1625
+ rows: simpleTable.content.rows.concat([
1626
+ {
1627
+ cells: [emptyCell, emptyCell],
1628
+ },
1629
+ ]),
1630
+ },
1631
+ },
1632
+ "rows"
1633
+ )
1634
+ ).toEqual([
1635
+ {
1636
+ cells: [
1637
+ simpleTable.content.rows[0].cells[0],
1638
+ simpleTable.content.rows[0].cells[1],
1639
+ ],
1640
+ },
1641
+ {
1642
+ cells: [
1643
+ simpleTable.content.rows[1].cells[0],
1644
+ simpleTable.content.rows[1].cells[1],
1645
+ ],
1646
+ },
1647
+ ]);
1648
+ });
1649
+
1650
+ it("should crop the empty rows of a table with colspan", () => {
1651
+ expect(
1652
+ cropEmptyRowsOrColumns(
1653
+ {
1654
+ ...tableWithColspan,
1655
+ content: {
1656
+ ...tableWithColspan.content,
1657
+ rows: tableWithColspan.content.rows.concat([
1658
+ {
1659
+ cells: [emptyCell, emptyCell, emptyCell],
1660
+ },
1661
+ ]),
1662
+ },
1663
+ },
1664
+ "rows"
1665
+ )
1666
+ ).toEqual(tableWithColspan.content.rows);
1667
+ });
1668
+
1669
+ it("should crop the empty columns of a table with colspan", () => {
1670
+ expect(
1671
+ cropEmptyRowsOrColumns(
1672
+ {
1673
+ ...tableWithColspan,
1674
+ content: {
1675
+ ...tableWithColspan.content,
1676
+ rows: [
1677
+ {
1678
+ cells: [...tableWithColspan.content.rows[0].cells, emptyCell],
1679
+ },
1680
+ {
1681
+ cells: [...tableWithColspan.content.rows[1].cells, emptyCell],
1682
+ },
1683
+ ],
1684
+ },
1685
+ },
1686
+ "columns"
1687
+ )
1688
+ ).toEqual(tableWithColspan.content.rows);
1689
+ });
1690
+
1691
+ it("should crop the empty rows of a table with rowspan", () => {
1692
+ expect(
1693
+ cropEmptyRowsOrColumns(
1694
+ {
1695
+ ...tableWithRowspan,
1696
+ content: {
1697
+ ...tableWithRowspan.content,
1698
+ rows: tableWithRowspan.content.rows.concat([
1699
+ {
1700
+ cells: [emptyCell, emptyCell, emptyCell],
1701
+ },
1702
+ ]),
1703
+ },
1704
+ },
1705
+ "rows"
1706
+ )
1707
+ ).toEqual(tableWithRowspan.content.rows);
1708
+ });
1709
+
1710
+ it("should crop the empty columns of a table with rowspan", () => {
1711
+ expect(
1712
+ cropEmptyRowsOrColumns(
1713
+ {
1714
+ ...tableWithRowspan,
1715
+ content: {
1716
+ ...tableWithRowspan.content,
1717
+ rows: [
1718
+ {
1719
+ cells: [...tableWithRowspan.content.rows[0].cells, emptyCell],
1720
+ },
1721
+ {
1722
+ cells: [...tableWithRowspan.content.rows[1].cells, emptyCell],
1723
+ },
1724
+ {
1725
+ cells: [...tableWithRowspan.content.rows[2].cells, emptyCell],
1726
+ },
1727
+ ],
1728
+ },
1729
+ },
1730
+ "columns"
1731
+ )
1732
+ ).toEqual(tableWithRowspan.content.rows);
1733
+ });
1734
+
1735
+ it("should crop the empty rows of a table with colspan and rowspan", () => {
1736
+ expect(
1737
+ cropEmptyRowsOrColumns(
1738
+ {
1739
+ ...tableWithColspanAndRowspan,
1740
+ content: {
1741
+ ...tableWithColspanAndRowspan.content,
1742
+ rows: tableWithColspanAndRowspan.content.rows.concat([
1743
+ {
1744
+ cells: [emptyCell, emptyCell, emptyCell],
1745
+ },
1746
+ ]),
1747
+ },
1748
+ },
1749
+ "rows"
1750
+ )
1751
+ ).toEqual(tableWithColspanAndRowspan.content.rows);
1752
+ });
1753
+
1754
+ it("should crop the empty columns of a table with colspan and rowspan", () => {
1755
+ expect(
1756
+ cropEmptyRowsOrColumns(
1757
+ {
1758
+ ...tableWithColspanAndRowspan,
1759
+ content: {
1760
+ ...tableWithColspanAndRowspan.content,
1761
+ rows: [
1762
+ {
1763
+ cells: [
1764
+ ...tableWithColspanAndRowspan.content.rows[0].cells,
1765
+ emptyCell,
1766
+ ],
1767
+ },
1768
+ {
1769
+ cells: [
1770
+ ...tableWithColspanAndRowspan.content.rows[1].cells,
1771
+ emptyCell,
1772
+ ],
1773
+ },
1774
+ {
1775
+ cells: [
1776
+ ...tableWithColspanAndRowspan.content.rows[2].cells,
1777
+ emptyCell,
1778
+ ],
1779
+ },
1780
+ ],
1781
+ },
1782
+ },
1783
+ "columns"
1784
+ )
1785
+ ).toEqual(tableWithColspanAndRowspan.content.rows);
1786
+ });
1787
+
1788
+ it("should crop the empty rows of a table with complex rowspans and colspans", () => {
1789
+ expect(
1790
+ cropEmptyRowsOrColumns(
1791
+ {
1792
+ ...tableWithComplexRowspansAndColspans,
1793
+ content: {
1794
+ ...tableWithComplexRowspansAndColspans.content,
1795
+ rows: tableWithComplexRowspansAndColspans.content.rows.concat([
1796
+ {
1797
+ cells: [emptyCell, emptyCell, emptyCell, emptyCell],
1798
+ },
1799
+ ]),
1800
+ },
1801
+ },
1802
+ "rows"
1803
+ )
1804
+ ).toEqual(tableWithComplexRowspansAndColspans.content.rows);
1805
+ });
1806
+
1807
+ it("should crop the empty columns of a table with complex rowspans and colspans", () => {
1808
+ expect(
1809
+ cropEmptyRowsOrColumns(
1810
+ {
1811
+ ...tableWithComplexRowspansAndColspans,
1812
+ content: {
1813
+ ...tableWithComplexRowspansAndColspans.content,
1814
+ rows: [
1815
+ {
1816
+ cells: [
1817
+ ...tableWithComplexRowspansAndColspans.content.rows[0].cells,
1818
+ emptyCell,
1819
+ ],
1820
+ },
1821
+ {
1822
+ cells: [
1823
+ ...tableWithComplexRowspansAndColspans.content.rows[1].cells,
1824
+ emptyCell,
1825
+ ],
1826
+ },
1827
+ {
1828
+ cells: [
1829
+ ...tableWithComplexRowspansAndColspans.content.rows[2].cells,
1830
+ emptyCell,
1831
+ ],
1832
+ },
1833
+ ],
1834
+ },
1835
+ },
1836
+ "columns"
1837
+ )
1838
+ ).toEqual(tableWithComplexRowspansAndColspans.content.rows);
1839
+ });
1840
+
1841
+ it("should not crop out the last row of a table", () => {
1842
+ expect(
1843
+ cropEmptyRowsOrColumns(
1844
+ {
1845
+ ...simpleTable,
1846
+ content: {
1847
+ ...simpleTable.content,
1848
+ rows: [
1849
+ {
1850
+ cells: [emptyCell, emptyCell],
1851
+ },
1852
+ {
1853
+ cells: [emptyCell, emptyCell],
1854
+ },
1855
+ ],
1856
+ },
1857
+ },
1858
+ "rows"
1859
+ )
1860
+ ).toEqual([
1861
+ {
1862
+ cells: [emptyCell, emptyCell],
1863
+ },
1864
+ ]);
1865
+ });
1866
+
1867
+ it("should not crop out the last column of a table", () => {
1868
+ expect(
1869
+ cropEmptyRowsOrColumns(
1870
+ {
1871
+ ...simpleTable,
1872
+ content: {
1873
+ ...simpleTable.content,
1874
+ rows: [
1875
+ {
1876
+ cells: [emptyCell, emptyCell],
1877
+ },
1878
+ {
1879
+ cells: [emptyCell, emptyCell],
1880
+ },
1881
+ ],
1882
+ },
1883
+ },
1884
+ "columns"
1885
+ )
1886
+ ).toEqual([
1887
+ {
1888
+ cells: [emptyCell],
1889
+ },
1890
+ {
1891
+ cells: [emptyCell],
1892
+ },
1893
+ ]);
1894
+ });
1895
+
1896
+ it("should preserve any colspan or rowspan on that last row", () => {
1897
+ expect(
1898
+ cropEmptyRowsOrColumns(
1899
+ {
1900
+ ...simpleTable,
1901
+ content: {
1902
+ ...simpleTable.content,
1903
+ rows: [
1904
+ {
1905
+ cells: [
1906
+ {
1907
+ ...emptyCell,
1908
+ props: {
1909
+ ...emptyCell.props,
1910
+ rowspan: 2,
1911
+ },
1912
+ },
1913
+ emptyCell,
1914
+ ],
1915
+ },
1916
+ {
1917
+ cells: [emptyCell],
1918
+ },
1919
+ ],
1920
+ },
1921
+ },
1922
+ "rows"
1923
+ )
1924
+ ).toEqual([
1925
+ {
1926
+ cells: [
1927
+ {
1928
+ ...emptyCell,
1929
+ props: {
1930
+ ...emptyCell.props,
1931
+ rowspan: 2,
1932
+ },
1933
+ },
1934
+ emptyCell,
1935
+ ],
1936
+ },
1937
+ {
1938
+ cells: [emptyCell],
1939
+ },
1940
+ ]);
1941
+ });
1942
+
1943
+ it("should preserve any colspan or rowspan on that last column", () => {
1944
+ expect(
1945
+ cropEmptyRowsOrColumns(
1946
+ {
1947
+ ...simpleTable,
1948
+ content: {
1949
+ ...simpleTable.content,
1950
+ rows: [
1951
+ {
1952
+ cells: [
1953
+ {
1954
+ ...emptyCell,
1955
+ props: {
1956
+ ...emptyCell.props,
1957
+ colspan: 2,
1958
+ },
1959
+ },
1960
+ ],
1961
+ },
1962
+ {
1963
+ cells: [emptyCell, emptyCell],
1964
+ },
1965
+ ],
1966
+ },
1967
+ },
1968
+ "columns"
1969
+ )
1970
+ ).toEqual([
1971
+ {
1972
+ cells: [
1973
+ {
1974
+ ...emptyCell,
1975
+ props: {
1976
+ ...emptyCell.props,
1977
+ colspan: 2,
1978
+ },
1979
+ },
1980
+ ],
1981
+ },
1982
+ {
1983
+ cells: [emptyCell, emptyCell],
1984
+ },
1985
+ ]);
1986
+ });
1987
+ });