@atlaskit/editor-plugin-table 7.2.2 → 7.3.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 (149) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/commands/column-resize.js +115 -45
  3. package/dist/cjs/commands/go-to-next-cell.js +7 -11
  4. package/dist/cjs/commands/misc.js +3 -2
  5. package/dist/cjs/commands/selection.js +3 -3
  6. package/dist/cjs/event-handlers.js +38 -25
  7. package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +3 -19
  8. package/dist/cjs/pm-plugins/keymap.js +1 -0
  9. package/dist/cjs/pm-plugins/main.js +43 -9
  10. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +37 -7
  11. package/dist/cjs/pm-plugins/table-resizing/plugin.js +20 -6
  12. package/dist/cjs/reducer.js +5 -2
  13. package/dist/cjs/utils/drag-menu.js +37 -23
  14. package/dist/cjs/utils/merged-cells.js +66 -1
  15. package/dist/es2019/commands/column-resize.js +100 -35
  16. package/dist/es2019/commands/go-to-next-cell.js +7 -9
  17. package/dist/es2019/commands/misc.js +3 -2
  18. package/dist/es2019/commands/selection.js +5 -5
  19. package/dist/es2019/event-handlers.js +17 -3
  20. package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  21. package/dist/es2019/pm-plugins/keymap.js +3 -2
  22. package/dist/es2019/pm-plugins/main.js +41 -5
  23. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +37 -4
  24. package/dist/es2019/pm-plugins/table-resizing/plugin.js +16 -1
  25. package/dist/es2019/reducer.js +5 -2
  26. package/dist/es2019/utils/drag-menu.js +38 -14
  27. package/dist/es2019/utils/merged-cells.js +73 -0
  28. package/dist/esm/commands/column-resize.js +105 -35
  29. package/dist/esm/commands/go-to-next-cell.js +7 -11
  30. package/dist/esm/commands/misc.js +3 -2
  31. package/dist/esm/commands/selection.js +5 -5
  32. package/dist/esm/event-handlers.js +38 -25
  33. package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  34. package/dist/esm/pm-plugins/keymap.js +3 -2
  35. package/dist/esm/pm-plugins/main.js +38 -4
  36. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +34 -4
  37. package/dist/esm/pm-plugins/table-resizing/plugin.js +15 -1
  38. package/dist/esm/reducer.js +5 -2
  39. package/dist/esm/utils/drag-menu.js +36 -22
  40. package/dist/esm/utils/merged-cells.js +65 -0
  41. package/dist/types/commands/column-resize.d.ts +2 -0
  42. package/dist/types/commands/misc.d.ts +1 -1
  43. package/dist/types/types.d.ts +16 -0
  44. package/dist/types/utils/drag-menu.d.ts +4 -1
  45. package/dist/types/utils/merged-cells.d.ts +2 -0
  46. package/dist/types-ts4.5/commands/column-resize.d.ts +2 -0
  47. package/dist/types-ts4.5/commands/misc.d.ts +1 -1
  48. package/dist/types-ts4.5/types.d.ts +16 -0
  49. package/dist/types-ts4.5/utils/drag-menu.d.ts +4 -1
  50. package/dist/types-ts4.5/utils/merged-cells.d.ts +2 -0
  51. package/package.json +10 -17
  52. package/src/commands/column-resize.ts +155 -40
  53. package/src/commands/go-to-next-cell.ts +6 -15
  54. package/src/commands/misc.ts +2 -0
  55. package/src/commands/selection.ts +5 -5
  56. package/src/event-handlers.ts +21 -4
  57. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -32
  58. package/src/pm-plugins/keymap.ts +3 -0
  59. package/src/pm-plugins/main.ts +47 -2
  60. package/src/pm-plugins/table-resizing/event-handlers.ts +33 -5
  61. package/src/pm-plugins/table-resizing/plugin.ts +18 -1
  62. package/src/reducer.ts +5 -2
  63. package/src/types.ts +16 -0
  64. package/src/utils/drag-menu.ts +94 -20
  65. package/src/utils/merged-cells.ts +78 -0
  66. package/tsconfig.dev.json +0 -69
  67. package/tsconfig.json +2 -877
  68. package/examples/99-testing.tsx +0 -140
  69. package/examples/config.jsonc +0 -14
  70. package/src/__tests__/unit/analytics.ts +0 -888
  71. package/src/__tests__/unit/collab.ts +0 -93
  72. package/src/__tests__/unit/commands/go-to-next-cell.ts +0 -173
  73. package/src/__tests__/unit/commands/insert.ts +0 -137
  74. package/src/__tests__/unit/commands/misc.ts +0 -185
  75. package/src/__tests__/unit/commands/sort.ts +0 -128
  76. package/src/__tests__/unit/commands.ts +0 -745
  77. package/src/__tests__/unit/copy-button.ts +0 -22
  78. package/src/__tests__/unit/copy-paste.ts +0 -677
  79. package/src/__tests__/unit/event-handlers/index.ts +0 -125
  80. package/src/__tests__/unit/event-handlers.ts +0 -296
  81. package/src/__tests__/unit/fix-tables.ts +0 -164
  82. package/src/__tests__/unit/get-toolbar-config.ts +0 -127
  83. package/src/__tests__/unit/handlers.ts +0 -98
  84. package/src/__tests__/unit/hover-selection.ts +0 -230
  85. package/src/__tests__/unit/index-with-fake-timers.ts +0 -111
  86. package/src/__tests__/unit/index.ts +0 -912
  87. package/src/__tests__/unit/layout.ts +0 -146
  88. package/src/__tests__/unit/nodeviews/OverflowShadowsObserver.ts +0 -162
  89. package/src/__tests__/unit/nodeviews/TableComponent.tsx +0 -280
  90. package/src/__tests__/unit/nodeviews/TableContainer.tsx +0 -525
  91. package/src/__tests__/unit/nodeviews/cell.ts +0 -132
  92. package/src/__tests__/unit/nodeviews/table.ts +0 -129
  93. package/src/__tests__/unit/pm-plugins/analytics.ts +0 -327
  94. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +0 -94
  95. package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +0 -176
  96. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +0 -211
  97. package/src/__tests__/unit/pm-plugins/main.ts +0 -214
  98. package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -101
  99. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +0 -562
  100. package/src/__tests__/unit/pm-plugins/table-local-id.ts +0 -507
  101. package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +0 -269
  102. package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +0 -192
  103. package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +0 -33
  104. package/src/__tests__/unit/pm-plugins/table-width.ts +0 -292
  105. package/src/__tests__/unit/sort-column.ts +0 -399
  106. package/src/__tests__/unit/toolbar.ts +0 -512
  107. package/src/__tests__/unit/transforms/delete-columns.ts +0 -597
  108. package/src/__tests__/unit/transforms/delete-rows.ts +0 -620
  109. package/src/__tests__/unit/transforms/merging.ts +0 -392
  110. package/src/__tests__/unit/ui/ContextualMenu.tsx +0 -71
  111. package/src/__tests__/unit/ui/CornerControls.tsx +0 -99
  112. package/src/__tests__/unit/ui/DeleteButton.tsx +0 -38
  113. package/src/__tests__/unit/ui/FixedButton.tsx +0 -217
  114. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +0 -123
  115. package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +0 -68
  116. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +0 -178
  117. package/src/__tests__/unit/ui/FloatingDragMenu.tsx +0 -511
  118. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +0 -322
  119. package/src/__tests__/unit/ui/NumberColumn.tsx +0 -146
  120. package/src/__tests__/unit/ui/RowControls.tsx +0 -294
  121. package/src/__tests__/unit/ui/RowDragControls.tsx +0 -129
  122. package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +0 -189
  123. package/src/__tests__/unit/ui/TableFloatingControls.tsx +0 -118
  124. package/src/__tests__/unit/undo-redo.ts +0 -220
  125. package/src/__tests__/unit/utils/analytics.ts +0 -98
  126. package/src/__tests__/unit/utils/collapse.ts +0 -57
  127. package/src/__tests__/unit/utils/column-controls.ts +0 -205
  128. package/src/__tests__/unit/utils/dom.ts +0 -180
  129. package/src/__tests__/unit/utils/merged-cells.ts +0 -156
  130. package/src/__tests__/unit/utils/nodes.ts +0 -79
  131. package/src/__tests__/unit/utils/row-controls.ts +0 -195
  132. package/src/__tests__/unit/utils/table.ts +0 -96
  133. package/src/__tests__/unit/utils.ts +0 -670
  134. package/src/__tests__/visual-regression/__fixtures__/sticky-header-with-horizontal-scroll.json +0 -5228
  135. package/src/__tests__/visual-regression/__fixtures__/table-with-100-numbered-list-items.json +0 -20272
  136. package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-column-menu-item-should-remove-the-table-column-on-click-1-snap.png +0 -3
  137. package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-column-menu-item-visual-hints-should-be-added-to-the-table-column-on-hover-1-snap.png +0 -3
  138. package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-row-menu-item-should-remove-the-table-row-on-click-1-snap.png +0 -3
  139. package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-row-menu-item-visual-hints-should-be-added-to-the-table-row-on-hover-1-snap.png +0 -3
  140. package/src/__tests__/visual-regression/__image_snapshots__/copy-button-ts-floating-toolbar-copy-button-table-target-node-displays-blue-border-when-copy-button-is-hovered-1-snap.png +0 -3
  141. package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-1-snap.png +0 -3
  142. package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-2-snap.png +0 -3
  143. package/src/__tests__/visual-regression/__image_snapshots__/index-ts-snapshot-test-table-numbered-list-should-not-overflow-table-cell-when-there-are-more-than-100-ordered-list-items-3-snap.png +0 -3
  144. package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-1-snap.png +0 -3
  145. package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-2-snap.png +0 -3
  146. package/src/__tests__/visual-regression/cell-options-menu.ts +0 -101
  147. package/src/__tests__/visual-regression/copy-button.ts +0 -181
  148. package/src/__tests__/visual-regression/index.ts +0 -62
  149. package/src/__tests__/visual-regression/sticky-header.ts +0 -61
@@ -1,597 +0,0 @@
1
- import { uuid } from '@atlaskit/adf-schema';
2
- import type { DocBuilder } from '@atlaskit/editor-common/types';
3
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
4
- import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
5
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
6
- import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
7
- import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
8
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
9
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
10
- import type { PluginKey } from '@atlaskit/editor-prosemirror/state';
11
- import type { Rect } from '@atlaskit/editor-tables/table-map';
12
- import { getSelectionRect } from '@atlaskit/editor-tables/utils';
13
- // eslint-disable-next-line import/no-extraneous-dependencies
14
- import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
15
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
16
- import {
17
- createProsemirrorEditorFactory,
18
- Preset,
19
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
20
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
21
- import {
22
- doc,
23
- p,
24
- table,
25
- td,
26
- tdCursor,
27
- tdEmpty,
28
- tr,
29
- } from '@atlaskit/editor-test-helpers/doc-builder';
30
-
31
- import tablePlugin from '../../../plugin';
32
- import { pluginKey } from '../../../pm-plugins/plugin-key';
33
- import { deleteColumns } from '../../../transforms';
34
- import type { TablePluginState } from '../../../types';
35
-
36
- const colsToRect = (cols: Array<number>, noOfRows: number): Rect => ({
37
- left: Math.min(...cols),
38
- right: Math.max(...cols) + 1,
39
- top: 0,
40
- bottom: noOfRows,
41
- });
42
-
43
- const TABLE_LOCAL_ID = 'test-table-local-id';
44
-
45
- describe('table plugin -> transforms -> delete columns', () => {
46
- const originalClientWidth = Object.getOwnPropertyDescriptor(
47
- HTMLElement.prototype,
48
- 'clientWidth',
49
- );
50
- beforeAll(() => {
51
- uuid.setStatic(TABLE_LOCAL_ID);
52
-
53
- Object.defineProperty(HTMLElement.prototype, 'clientWidth', {
54
- get() {
55
- return 760;
56
- },
57
- });
58
- });
59
-
60
- afterAll(() => {
61
- uuid.setStatic(false);
62
- Object.defineProperty(HTMLElement.prototype, 'clientWidth', {
63
- get() {
64
- return originalClientWidth;
65
- },
66
- });
67
- });
68
-
69
- const createEditor = createProsemirrorEditorFactory();
70
- const preset = new Preset<LightEditorPlugin>()
71
- .add([featureFlagsPlugin, {}])
72
- .add([analyticsPlugin, {}])
73
- .add(contentInsertionPlugin)
74
- .add(widthPlugin)
75
- .add(guidelinePlugin)
76
- .add(selectionPlugin)
77
- .add(tablePlugin);
78
-
79
- const editor = (doc: DocBuilder) =>
80
- createEditor<TablePluginState, PluginKey, typeof preset>({
81
- doc,
82
- preset,
83
- pluginKey,
84
- attachTo: document.body,
85
- });
86
-
87
- describe('when selection rect is given', () => {
88
- describe('when the first column is deleted', () => {
89
- it('should delete the column and move cursor to the first column', () => {
90
- const {
91
- editorView,
92
- refs: { nextCursorPos },
93
- } = editor(
94
- doc(
95
- p('text'),
96
- table()(
97
- tr(
98
- td({})(p('{nextCursorPos}')),
99
- td({})(p('c2')),
100
- td({})(p('c3')),
101
- ),
102
- ),
103
- ),
104
- );
105
- const { state, dispatch } = editorView;
106
- dispatch(deleteColumns(colsToRect([0], 1), true)(state.tr));
107
- expect(editorView.state.doc).toEqualDocument(
108
- doc(
109
- p('text'),
110
- table({ localId: TABLE_LOCAL_ID })(
111
- tr(td({})(p('c2')), td()(p('c3'))),
112
- ),
113
- ),
114
- );
115
- expect(editorView.state.selection.from).toEqual(nextCursorPos);
116
- });
117
- });
118
-
119
- describe('when middle column is deleted', () => {
120
- it('should delete the column and move cursor to the previous column', () => {
121
- const {
122
- editorView,
123
- refs: { nextCursorPos },
124
- } = editor(
125
- doc(
126
- p('text'),
127
- table()(
128
- tr(
129
- td({})(p('{nextCursorPos}')),
130
- td({})(p('c2')),
131
- td({})(p('c3')),
132
- ),
133
- ),
134
- ),
135
- );
136
- const { state, dispatch } = editorView;
137
- dispatch(deleteColumns(colsToRect([1], 1), true)(state.tr));
138
- expect(editorView.state.doc).toEqualDocument(
139
- doc(
140
- p('text'),
141
- table({ localId: TABLE_LOCAL_ID })(tr(tdEmpty, td()(p('c3')))),
142
- ),
143
- );
144
- expect(editorView.state.selection.from).toEqual(nextCursorPos);
145
- });
146
- });
147
-
148
- describe('when multiple rows are selected', () => {
149
- it('should delete these columns', () => {
150
- const { editorView } = editor(
151
- doc(
152
- p('text'),
153
- table()(tr(tdCursor, td({})(p('c1')), td({})(p('c2')))),
154
- ),
155
- );
156
- const { state, dispatch } = editorView;
157
- dispatch(deleteColumns(colsToRect([0, 1], 1), true)(state.tr));
158
- expect(editorView.state.doc).toEqualDocument(
159
- doc(p('text'), table({ localId: TABLE_LOCAL_ID })(tr(td()(p('c2'))))),
160
- );
161
- });
162
- });
163
- });
164
-
165
- describe('when one column is selected', () => {
166
- it('should delete the column', () => {
167
- const { editorView } = editor(
168
- doc(
169
- p('text'),
170
- table()(
171
- tr(td({})(p('a1')), td({})(p('{<cell}a2')), td({})(p('a3'))),
172
- tr(td({})(p('b1')), td({})(p('{cell>}b2')), td({})(p('b3'))),
173
- ),
174
- ),
175
- );
176
- const { state, dispatch } = editorView;
177
- dispatch(
178
- deleteColumns(getSelectionRect(state.selection)!, true)(state.tr),
179
- );
180
- expect(editorView.state.doc).toEqualDocument(
181
- doc(
182
- p('text'),
183
- table({ localId: TABLE_LOCAL_ID })(
184
- tr(td({})(p('a1')), td({})(p('a3'))),
185
- tr(td({})(p('b1')), td({})(p('b3'))),
186
- ),
187
- ),
188
- );
189
- });
190
-
191
- it('should update each cells colWidth', () => {
192
- const { editorView } = editor(
193
- doc(
194
- table({ localId: TABLE_LOCAL_ID, layout: 'default', width: 760 })(
195
- tr(
196
- td({ colwidth: [401] })(p('{<>}')),
197
- td({ colwidth: [105] })(p('')),
198
- td({ colwidth: [253] })(p('')),
199
- ),
200
- ),
201
- ),
202
- );
203
- const { dispatch, state } = editorView;
204
- dispatch(deleteColumns(colsToRect([1], 1), true, editorView)(state.tr));
205
-
206
- expect(editorView.state.doc).toEqualDocument(
207
- doc(
208
- table({ localId: TABLE_LOCAL_ID, width: 760 })(
209
- tr(td({ colwidth: [460] })(p('')), td({ colwidth: [290] })(p(''))),
210
- ),
211
- ),
212
- );
213
- });
214
- });
215
-
216
- describe('when multiple columns are selected', () => {
217
- it('should delete these column', () => {
218
- const { editorView } = editor(
219
- doc(
220
- p('text'),
221
- table()(
222
- tr(td({})(p('{<cell}a1')), td({})(p('a2')), td({})(p('a3'))),
223
- tr(td({})(p('b1')), td({})(p('{cell>}b2')), td({})(p('b3'))),
224
- ),
225
- ),
226
- );
227
- const { state, dispatch } = editorView;
228
- dispatch(
229
- deleteColumns(getSelectionRect(state.selection)!, true)(state.tr),
230
- );
231
- expect(editorView.state.doc).toEqualDocument(
232
- doc(
233
- p('text'),
234
- table({ localId: TABLE_LOCAL_ID })(
235
- tr(td({})(p('a3'))),
236
- tr(td({})(p('b3'))),
237
- ),
238
- ),
239
- );
240
- });
241
-
242
- it('should update each cells colWidth', () => {
243
- const { editorView } = editor(
244
- doc(
245
- table({ localId: TABLE_LOCAL_ID, layout: 'default', width: 760 })(
246
- tr(
247
- td({ colwidth: [401] })(p('{<cell}')),
248
- td({ colwidth: [105] })(p('{cell>}')),
249
- td({ colwidth: [253] })(p('')),
250
- ),
251
- ),
252
- ),
253
- );
254
- const { dispatch, state } = editorView;
255
- dispatch(
256
- deleteColumns(
257
- getSelectionRect(state.selection)!,
258
- true,
259
- editorView,
260
- )(state.tr),
261
- );
262
-
263
- expect(editorView.state.doc).toEqualDocument(
264
- doc(
265
- table({ localId: TABLE_LOCAL_ID, width: 760 })(
266
- tr(td({ colwidth: [750] })(p(''))),
267
- ),
268
- ),
269
- );
270
- });
271
- });
272
-
273
- describe('when some of the columns are merged', () => {
274
- it('should delete columns and update colspans of cells DOM nodes', () => {
275
- const { editorView } = editor(
276
- doc(
277
- p('text'),
278
- table()(
279
- tr(td({ colspan: 2 })(p('{<cell}c1')), td({})(p('c2'))),
280
- tr(td({})(p('{cell>}c3')), td({})(p('c4')), td({})(p('c5'))),
281
- ),
282
- ),
283
- );
284
- const { state, dispatch } = editorView;
285
- dispatch(
286
- deleteColumns(getSelectionRect(state.selection)!, true)(state.tr),
287
- );
288
- expect(editorView.state.doc).toEqualDocument(
289
- doc(
290
- p('text'),
291
- table({ localId: TABLE_LOCAL_ID })(
292
- tr(td({ colspan: 1 })(p('c2'))),
293
- tr(td({ colspan: 1 })(p('c5'))),
294
- ),
295
- ),
296
- );
297
- const cells = editorView.dom.querySelectorAll('td');
298
- for (let i = 0, count = cells.length; i < count; i++) {
299
- const cell = cells[i] as HTMLElement;
300
- expect(cell.getAttribute('colspan')).not.toEqual('2');
301
- }
302
- });
303
-
304
- describe('when after deleting the last column table has rows where cells have rowspans > 1 in each column', () => {
305
- it('should decrement rowspans of these cells', () => {
306
- const { editorView } = editor(
307
- doc(
308
- p('text'),
309
- table()(
310
- tr(tdEmpty, tdEmpty, td({})(p('{<cell}a3'))),
311
- tr(
312
- td({ rowspan: 2 })(p('b1')),
313
- td({ rowspan: 2 })(p('b2')),
314
- tdEmpty,
315
- ),
316
- tr(td({})(p('{cell>}c3'))),
317
- ),
318
- ),
319
- );
320
- const { state, dispatch } = editorView;
321
- dispatch(
322
- deleteColumns(getSelectionRect(state.selection)!, false)(state.tr),
323
- );
324
- expect(editorView.state.doc).toEqualDocument(
325
- doc(
326
- p('text'),
327
- table({ localId: TABLE_LOCAL_ID })(
328
- tr(tdEmpty, tdEmpty),
329
- tr(td({})(p('b1')), td({})(p('b2'))),
330
- ),
331
- ),
332
- );
333
- });
334
- });
335
-
336
- describe('when after deleting the first column table has rows where cells have rowspans > 1 in each column', () => {
337
- it('should decrement rowspans of these cells', () => {
338
- const { editorView } = editor(
339
- doc(
340
- p('text'),
341
- table()(
342
- tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
343
- tr(
344
- tdEmpty,
345
- td({ rowspan: 2 })(p('b2')),
346
- td({ rowspan: 2 })(p('b3')),
347
- ),
348
- tr(td({})(p('{cell>}c1'))),
349
- ),
350
- ),
351
- );
352
- const { state, dispatch } = editorView;
353
- dispatch(
354
- deleteColumns(getSelectionRect(state.selection)!, false)(state.tr),
355
- );
356
- expect(editorView.state.doc).toEqualDocument(
357
- doc(
358
- p('text'),
359
- table({ localId: TABLE_LOCAL_ID })(
360
- tr(tdEmpty, tdEmpty),
361
- tr(td({})(p('b2')), td({})(p('b3'))),
362
- ),
363
- ),
364
- );
365
- });
366
- });
367
-
368
- describe('when a column-spanning cell is deleted', () => {
369
- describe('when this cell has rowspan = 1', () => {
370
- it('should append missing cells to the column(s) to the right from the deleted column', () => {
371
- const { editorView } = editor(
372
- doc(
373
- table()(
374
- tr(
375
- td({ colwidth: [110] })(p('a1')),
376
- td({ colwidth: [120] })(p('a2')),
377
- td({ colwidth: [130] })(p('a3')),
378
- ),
379
- tr(td({ colwidth: [110, 120, 130], colspan: 3 })(p('b1'))),
380
- tr(
381
- td({ colwidth: [110] })(p('c1')),
382
- td({ colwidth: [120] })(p('c2')),
383
- td({ colwidth: [130] })(p('c3')),
384
- ),
385
- ),
386
- ),
387
- );
388
- const { state, dispatch } = editorView;
389
- dispatch(deleteColumns(colsToRect([0], 3), true)(state.tr));
390
- expect(editorView.state.doc).toEqualDocument(
391
- doc(
392
- table({ localId: TABLE_LOCAL_ID })(
393
- tr(
394
- td({ colwidth: [120] })(p('a2')),
395
- td({ colwidth: [130] })(p('a3')),
396
- ),
397
- tr(
398
- td({ colwidth: [120] })(p('')),
399
- td({ colwidth: [130] })(p('')),
400
- ),
401
- tr(
402
- td({ colwidth: [120] })(p('c2')),
403
- td({ colwidth: [130] })(p('c3')),
404
- ),
405
- ),
406
- ),
407
- );
408
- });
409
- });
410
-
411
- describe('when this cell has rowspan > 1', () => {
412
- it('should append missing cells to the column(s) to the right from the deleted column', () => {
413
- const { editorView } = editor(
414
- doc(
415
- table()(
416
- tr(
417
- td({ colwidth: [110] })(p('a1')),
418
- td({ colwidth: [120] })(p('a2')),
419
- td({ colwidth: [130] })(p('a3')),
420
- td({ colwidth: [140] })(p('a4')),
421
- ),
422
- tr(
423
- td({ colwidth: [110, 120, 130], colspan: 3, rowspan: 2 })(
424
- p('b1'),
425
- ),
426
- td({ colwidth: [140] })(p('b4')),
427
- ),
428
- tr(td({ colwidth: [140] })(p('c4'))),
429
- tr(
430
- td({ colwidth: [110] })(p('d1')),
431
- td({ colwidth: [120] })(p('d2')),
432
- td({ colwidth: [130] })(p('d3')),
433
- td({ colwidth: [140] })(p('d4')),
434
- ),
435
- ),
436
- ),
437
- );
438
- const { state, dispatch } = editorView;
439
- dispatch(deleteColumns(colsToRect([0], 4), true)(state.tr));
440
- expect(editorView.state.doc).toEqualDocument(
441
- doc(
442
- table({ localId: TABLE_LOCAL_ID })(
443
- tr(
444
- td({ colwidth: [120] })(p('a2')),
445
- td({ colwidth: [130] })(p('a3')),
446
- td({ colwidth: [140] })(p('a4')),
447
- ),
448
- tr(
449
- td({ colwidth: [120] })(p('')),
450
- td({ colwidth: [130] })(p('')),
451
- td({ colwidth: [140] })(p('b4')),
452
- ),
453
- tr(
454
- td({ colwidth: [120] })(p('')),
455
- td({ colwidth: [130] })(p('')),
456
- td({ colwidth: [140] })(p('c4')),
457
- ),
458
- tr(
459
- td({ colwidth: [120] })(p('d2')),
460
- td({ colwidth: [130] })(p('d3')),
461
- td({ colwidth: [140] })(p('d4')),
462
- ),
463
- ),
464
- ),
465
- );
466
- });
467
- });
468
- });
469
-
470
- describe('when a column-spanning cell overlaps deleted column from the left', () => {
471
- describe('when this cell has rowspan = 1', () => {
472
- it('should decrement the colspan of that cell', () => {
473
- const { editorView } = editor(
474
- doc(
475
- table()(
476
- tr(
477
- td({ colwidth: [110] })(p('a1')),
478
- td({ colwidth: [120] })(p('a2')),
479
- td({ colwidth: [130] })(p('a3')),
480
- ),
481
- tr(td({ colwidth: [110, 120, 130], colspan: 3 })(p('b1'))),
482
- tr(
483
- td({ colwidth: [110] })(p('c1')),
484
- td({ colwidth: [120] })(p('c2')),
485
- td({ colwidth: [130] })(p('c3')),
486
- ),
487
- ),
488
- ),
489
- );
490
- const { state, dispatch } = editorView;
491
- dispatch(deleteColumns(colsToRect([1], 3), true)(state.tr));
492
- expect(editorView.state.doc).toEqualDocument(
493
- doc(
494
- table({ localId: TABLE_LOCAL_ID })(
495
- tr(
496
- td({ colwidth: [110] })(p('a1')),
497
- td({ colwidth: [130] })(p('a3')),
498
- ),
499
- tr(td({ colwidth: [110, 130], colspan: 2 })(p('b1'))),
500
- tr(
501
- td({ colwidth: [110] })(p('c1')),
502
- td({ colwidth: [130] })(p('c3')),
503
- ),
504
- ),
505
- ),
506
- );
507
- });
508
- });
509
-
510
- describe('when this cell has rowspan > 1', () => {
511
- it('should decrement the colspan of that cell', () => {
512
- const { editorView } = editor(
513
- doc(
514
- table()(
515
- tr(
516
- td({ colwidth: [110] })(p('a1')),
517
- td({ colwidth: [120] })(p('a2')),
518
- td({ colwidth: [130] })(p('a3')),
519
- td({ colwidth: [140] })(p('a4')),
520
- ),
521
- tr(
522
- td({ colwidth: [110, 120, 130], colspan: 3, rowspan: 2 })(
523
- p('b1'),
524
- ),
525
- td({ colwidth: [140] })(p('b4')),
526
- ),
527
- tr(td({ colwidth: [140] })(p('c4'))),
528
- tr(
529
- td({ colwidth: [110] })(p('d1')),
530
- td({ colwidth: [120] })(p('d2')),
531
- td({ colwidth: [130] })(p('d3')),
532
- td({ colwidth: [140] })(p('d4')),
533
- ),
534
- ),
535
- ),
536
- );
537
- const { state, dispatch } = editorView;
538
- dispatch(deleteColumns(colsToRect([1], 4), true)(state.tr));
539
- expect(editorView.state.doc).toEqualDocument(
540
- doc(
541
- table({ localId: TABLE_LOCAL_ID })(
542
- tr(
543
- td({ colwidth: [110] })(p('a1')),
544
- td({ colwidth: [130] })(p('a3')),
545
- td({ colwidth: [140] })(p('a4')),
546
- ),
547
- tr(
548
- td({ colwidth: [110, 130], colspan: 2, rowspan: 2 })(p('b1')),
549
- td({ colwidth: [140] })(p('b4')),
550
- ),
551
- tr(td({ colwidth: [140] })(p('c4'))),
552
- tr(
553
- td({ colwidth: [110] })(p('d1')),
554
- td({ colwidth: [130] })(p('d3')),
555
- td({ colwidth: [140] })(p('d4')),
556
- ),
557
- ),
558
- ),
559
- );
560
- });
561
- });
562
- });
563
-
564
- describe('when a column-spanning cell overlaps two deleted columns from the left', () => {
565
- it('should decrement the colspan of that cell twice', () => {
566
- const { editorView } = editor(
567
- doc(
568
- table()(
569
- tr(
570
- td({ colwidth: [110] })(p('a1')),
571
- td({ colwidth: [120] })(p('a2')),
572
- td({ colwidth: [130] })(p('a3')),
573
- ),
574
- tr(td({ colwidth: [110, 120, 130], colspan: 3 })(p('b1'))),
575
- tr(
576
- td({ colwidth: [110] })(p('c1')),
577
- td({ colwidth: [120] })(p('c2')),
578
- td({ colwidth: [130] })(p('c3')),
579
- ),
580
- ),
581
- ),
582
- );
583
- const { state, dispatch } = editorView;
584
- dispatch(deleteColumns(colsToRect([1, 2], 3), true)(state.tr));
585
- expect(editorView.state.doc).toEqualDocument(
586
- doc(
587
- table({ localId: TABLE_LOCAL_ID })(
588
- tr(td({ colwidth: [110] })(p('a1'))),
589
- tr(td({ colwidth: [110] })(p('b1'))),
590
- tr(td({ colwidth: [110] })(p('c1'))),
591
- ),
592
- ),
593
- );
594
- });
595
- });
596
- });
597
- });