@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,620 +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
- tdEmpty,
27
- th,
28
- thEmpty,
29
- tr,
30
- } from '@atlaskit/editor-test-helpers/doc-builder';
31
-
32
- import tablePlugin from '../../../plugin';
33
- import { pluginKey } from '../../../pm-plugins/plugin-key';
34
- import { deleteRows } from '../../../transforms';
35
- import type { TablePluginState } from '../../../types';
36
-
37
- const rowsToRect = (rows: Array<number>, noOfColumns: number): Rect => ({
38
- left: 0,
39
- right: noOfColumns,
40
- top: Math.min(...rows),
41
- bottom: Math.max(...rows) + 1,
42
- });
43
-
44
- const TABLE_LOCAL_ID = 'test-table-local-id';
45
-
46
- describe('table plugin -> transforms -> delete rows', () => {
47
- beforeAll(() => {
48
- uuid.setStatic(TABLE_LOCAL_ID);
49
- });
50
-
51
- afterAll(() => {
52
- uuid.setStatic(false);
53
- });
54
- const createEditor = createProsemirrorEditorFactory();
55
- const preset = new Preset<LightEditorPlugin>()
56
- .add([featureFlagsPlugin, {}])
57
- .add([analyticsPlugin, {}])
58
- .add(contentInsertionPlugin)
59
- .add(widthPlugin)
60
- .add(guidelinePlugin)
61
- .add(selectionPlugin)
62
- .add(tablePlugin);
63
-
64
- const editor = (doc: DocBuilder) =>
65
- createEditor<TablePluginState, PluginKey, typeof preset>({
66
- doc,
67
- preset,
68
- pluginKey,
69
- });
70
-
71
- describe('when selection rect is given', () => {
72
- describe('when the first row is deleted', () => {
73
- it('should delete the row and move cursor to the first row', () => {
74
- const {
75
- editorView,
76
- refs: { nextCursorPos },
77
- } = editor(
78
- doc(
79
- p('text'),
80
- table()(
81
- tr(td({})(p('{nextCursorPos}a1')), tdEmpty),
82
- tr(td({})(p('b1')), tdEmpty),
83
- tr(td({})(p('c1')), tdEmpty),
84
- ),
85
- ),
86
- );
87
- const { state, dispatch } = editorView;
88
- dispatch(deleteRows(rowsToRect([0], 3))(state.tr));
89
- expect(editorView.state.doc).toEqualDocument(
90
- doc(
91
- p('text'),
92
- table({ localId: TABLE_LOCAL_ID })(
93
- tr(td({})(p('b1')), tdEmpty),
94
- tr(td({})(p('c1')), tdEmpty),
95
- ),
96
- ),
97
- );
98
- expect(editorView.state.selection.from).toEqual(nextCursorPos);
99
- });
100
- });
101
-
102
- describe('when the middle row is deleted', () => {
103
- it('should delete the row and move cursor to the first row', () => {
104
- const {
105
- editorView,
106
- refs: { nextCursorPos },
107
- } = editor(
108
- doc(
109
- p('text'),
110
- table()(
111
- tr(td({})(p('{nextCursorPos}a1')), tdEmpty),
112
- tr(td({})(p('b1')), tdEmpty),
113
- tr(td({})(p('c1')), tdEmpty),
114
- ),
115
- ),
116
- );
117
- const { state, dispatch } = editorView;
118
- dispatch(deleteRows(rowsToRect([1], 3))(state.tr));
119
- expect(editorView.state.doc).toEqualDocument(
120
- doc(
121
- p('text'),
122
- table({ localId: TABLE_LOCAL_ID })(
123
- tr(td({})(p('a1')), tdEmpty),
124
- tr(td({})(p('c1')), tdEmpty),
125
- ),
126
- ),
127
- );
128
- expect(editorView.state.selection.from).toEqual(nextCursorPos);
129
- });
130
- });
131
-
132
- describe('when multiple rows are selected', () => {
133
- it('should delete those rows', () => {
134
- const { editorView } = editor(
135
- doc(
136
- p('text'),
137
- table()(
138
- tr(td()(p('a1')), td()(p('a2'))),
139
- tr(td()(p('b1')), td()(p('b2'))),
140
- tr(td()(p('c1')), td()(p('c2'))),
141
- ),
142
- ),
143
- );
144
- const { state, dispatch } = editorView;
145
- dispatch(deleteRows(rowsToRect([0, 1], 3))(state.tr));
146
- expect(editorView.state.doc).toEqualDocument(
147
- doc(
148
- p('text'),
149
- table({ localId: TABLE_LOCAL_ID })(
150
- tr(td()(p('c1')), td()(p('c2'))),
151
- ),
152
- ),
153
- );
154
- });
155
- });
156
- });
157
-
158
- describe('when one row is selected', () => {
159
- it('should delete the row', () => {
160
- const { editorView } = editor(
161
- doc(
162
- p('text'),
163
- table()(
164
- tr(td({})(p('a1{<cell}')), tdEmpty, td({})(p('{cell>}a3'))),
165
- tr(td({})(p('b1')), td({})(p('b2')), td({})(p('b3'))),
166
- ),
167
- ),
168
- );
169
- const { state, dispatch } = editorView;
170
- dispatch(deleteRows(getSelectionRect(state.selection)!)(state.tr));
171
- expect(editorView.state.doc).toEqualDocument(
172
- doc(
173
- p('text'),
174
- table({ localId: TABLE_LOCAL_ID })(
175
- tr(td({})(p('b1')), td({})(p('b2')), td({})(p('b3'))),
176
- ),
177
- ),
178
- );
179
- });
180
- });
181
-
182
- describe('when multiple rows are selected', () => {
183
- it('should delete these rows', () => {
184
- const { editorView } = editor(
185
- doc(
186
- p('text'),
187
- table()(
188
- tr(td({})(p('{<cell}a1')), td({})(p('a2'))),
189
- tr(td({})(p('b1')), td({})(p('{cell>}b2'))),
190
- tr(td({})(p('c1')), td({})(p('c2'))),
191
- ),
192
- ),
193
- );
194
- const { state, dispatch } = editorView;
195
- dispatch(deleteRows(getSelectionRect(state.selection)!)(state.tr));
196
- expect(editorView.state.doc).toEqualDocument(
197
- doc(
198
- p('text'),
199
- table({ localId: TABLE_LOCAL_ID })(
200
- tr(td({})(p('c1')), td({})(p('c2'))),
201
- ),
202
- ),
203
- );
204
- });
205
- });
206
-
207
- describe('when some of the rows are merged', () => {
208
- it('should delete rows and update rowspans of cells DOM nodes', () => {
209
- const { editorView } = editor(
210
- doc(
211
- p('text'),
212
- table()(
213
- tr(td({ rowspan: 2 })(p('{<cell}c1')), td({})(p('c2'))),
214
- tr(td({})(p('{cell>}c3'))),
215
- tr(td({})(p('c4')), td({})(p('c5'))),
216
- ),
217
- ),
218
- );
219
- const { state, dispatch } = editorView;
220
- dispatch(deleteRows(getSelectionRect(state.selection)!)(state.tr));
221
- expect(editorView.state.doc).toEqualDocument(
222
- doc(
223
- p('text'),
224
- table({ localId: TABLE_LOCAL_ID })(
225
- tr(td({})(p('c4')), td({})(p('c5'))),
226
- ),
227
- ),
228
- );
229
- const cells = editorView.dom.querySelectorAll('td');
230
- for (let i = 0, count = cells.length; i < count; i++) {
231
- const cell = cells[i] as HTMLElement;
232
- expect(cell.getAttribute('rowspan')).not.toEqual('2');
233
- }
234
- });
235
-
236
- describe('when after deleting the last row table has columns where all cells have colspan > 1', () => {
237
- it('should decrement colspan of these cells', () => {
238
- const { editorView } = editor(
239
- doc(
240
- p('text'),
241
- table()(
242
- tr(td({ colspan: 2 })(p('a1')), td({})(p('a3'))),
243
- tr(td({ colspan: 2 })(p('b1')), tdEmpty),
244
- tr(td({})(p('c1{cell>}')), tdEmpty, td({})(p('{<cell}c3'))),
245
- ),
246
- ),
247
- );
248
- const { state, dispatch } = editorView;
249
- dispatch(deleteRows(getSelectionRect(state.selection)!)(state.tr));
250
- expect(editorView.state.doc).toEqualDocument(
251
- doc(
252
- p('text'),
253
- table({ localId: TABLE_LOCAL_ID })(
254
- tr(td({})(p('a1')), td({})(p('a3'))),
255
- tr(td({})(p('b1')), tdEmpty),
256
- ),
257
- ),
258
- );
259
- });
260
- });
261
-
262
- describe('when delete the row in between rows that have merged cells with an extra row underneath', () => {
263
- it('should decrement colspan of these cells', () => {
264
- const { editorView } = editor(
265
- doc(
266
- p('text'),
267
- table()(
268
- tr(td({ colspan: 5 })(p('a1')), td({})(p('a6'))),
269
- tr(
270
- td({})(p('b1{<cell}')),
271
- td({})(p('b2')),
272
- td({})(p('b3')),
273
- td({})(p('b4')),
274
- td({})(p('b5')),
275
- td({})(p('b6{cell>}')),
276
- ),
277
- tr(td({})(p('c1')), td({ colspan: 5 })(p('c6'))),
278
- tr(
279
- td({ colspan: 3 })(p('d1')),
280
- td({})(p('d4')),
281
- td({})(p('d5')),
282
- td({})(p('d6')),
283
- ),
284
- ),
285
- ),
286
- );
287
- const { state, dispatch } = editorView;
288
- dispatch(deleteRows(getSelectionRect(state.selection)!)(state.tr));
289
- expect(editorView.state.doc).toEqualDocument(
290
- doc(
291
- p('text'),
292
- table({ localId: TABLE_LOCAL_ID })(
293
- tr(td({ colspan: 4 })(p('a1')), td({})(p('a6'))),
294
- tr(td({})(p('c1')), td({ colspan: 4 })(p('c6'))),
295
- tr(
296
- td({ colspan: 2 })(p('d1')),
297
- td({})(p('d4')),
298
- td({})(p('d5')),
299
- td({})(p('d6')),
300
- ),
301
- ),
302
- ),
303
- );
304
- });
305
- });
306
-
307
- describe('when after deleting the first row table has columns where all cells have colspan > 1', () => {
308
- it('should decrement colspan of these cells', () => {
309
- const { editorView } = editor(
310
- doc(
311
- p('text'),
312
- table()(
313
- tr(td({})(p('a1{<cell}')), tdEmpty, td({})(p('{cell>}a2'))),
314
- tr(td({ colspan: 2 })(p('b1')), td({})(p('b3'))),
315
- tr(td({ colspan: 2 })(p('c1')), td({})(p('c3'))),
316
- ),
317
- ),
318
- );
319
- const { state, dispatch } = editorView;
320
- dispatch(deleteRows(getSelectionRect(state.selection)!)(state.tr));
321
- expect(editorView.state.doc).toEqualDocument(
322
- doc(
323
- p('text'),
324
- table({ localId: TABLE_LOCAL_ID })(
325
- tr(td({})(p('b1')), td({})(p('b3'))),
326
- tr(td({})(p('c1')), td({})(p('c3'))),
327
- ),
328
- ),
329
- );
330
- });
331
- });
332
-
333
- describe('when isHeaderRowRequired = true (Bitbucket)', () => {
334
- const isHeaderRowRequired = true;
335
-
336
- describe('when only header row is selected', () => {
337
- it('should do nothing', () => {
338
- const { editorView } = editor(
339
- doc(table()(tr(thEmpty), tr(tdEmpty), tr(tdEmpty))),
340
- );
341
- const { state, dispatch } = editorView;
342
- dispatch(
343
- deleteRows(rowsToRect([0], 3), isHeaderRowRequired)(state.tr),
344
- );
345
- expect(editorView.state.doc).toEqualDocument(
346
- doc(
347
- table({ localId: TABLE_LOCAL_ID })(
348
- tr(thEmpty),
349
- tr(tdEmpty),
350
- tr(tdEmpty),
351
- ),
352
- ),
353
- );
354
- });
355
- });
356
-
357
- describe('when header row and other rows are selected', () => {
358
- it('should remove selected rows except the header row', () => {
359
- const { editorView } = editor(
360
- doc(
361
- table()(
362
- tr(th({})(p('header{<cell}')), thEmpty),
363
- tr(td({})(p('b1{cell>}')), tdEmpty),
364
- tr(td({})(p('c1')), tdEmpty),
365
- ),
366
- ),
367
- );
368
- const { state, dispatch } = editorView;
369
- dispatch(
370
- deleteRows(
371
- getSelectionRect(state.selection)!,
372
- isHeaderRowRequired,
373
- )(state.tr),
374
- );
375
- expect(editorView.state.doc).toEqualDocument(
376
- doc(
377
- table({ localId: TABLE_LOCAL_ID })(
378
- tr(th({})(p('header')), thEmpty),
379
- tr(td({})(p('c1')), tdEmpty),
380
- ),
381
- ),
382
- );
383
- });
384
- });
385
- });
386
-
387
- describe('when a row-spanning cell is deleted', () => {
388
- describe('when this cell has colspan = 1', () => {
389
- it('should append missing cells to the rows below deleted row', () => {
390
- const { editorView } = editor(
391
- doc(
392
- table()(
393
- tr(
394
- td({ colwidth: [110] })(p('a1')),
395
- td({ colwidth: [120], rowspan: 3 })(p('a2')),
396
- td({ colwidth: [130] })(p('a3')),
397
- ),
398
- tr(
399
- td({ colwidth: [110] })(p('b1')),
400
- td({ colwidth: [130] })(p('b3')),
401
- ),
402
- tr(
403
- td({ colwidth: [110] })(p('c1')),
404
- td({ colwidth: [130] })(p('c3')),
405
- ),
406
- ),
407
- ),
408
- );
409
- const { state, dispatch } = editorView;
410
- dispatch(deleteRows(rowsToRect([0], 3))(state.tr));
411
- expect(editorView.state.doc).toEqualDocument(
412
- doc(
413
- table({ localId: TABLE_LOCAL_ID })(
414
- tr(
415
- td({ colwidth: [110] })(p('b1')),
416
- td({ colwidth: [120] })(p('')),
417
- td({ colwidth: [130] })(p('b3')),
418
- ),
419
- tr(
420
- td({ colwidth: [110] })(p('c1')),
421
- td({ colwidth: [120] })(p('')),
422
- td({ colwidth: [130] })(p('c3')),
423
- ),
424
- ),
425
- ),
426
- );
427
- });
428
- });
429
-
430
- describe('when this cell has colspan > 1', () => {
431
- it('should append missing cells to the rows below deleted row', () => {
432
- const { editorView } = editor(
433
- doc(
434
- table()(
435
- tr(
436
- td({ colwidth: [110] })(p('a1')),
437
- td({ colwidth: [120, 130], rowspan: 3, colspan: 2 })(p('a2')),
438
- td({ colwidth: [140] })(p('a4')),
439
- ),
440
- tr(
441
- td({ colwidth: [110] })(p('b1')),
442
- td({ colwidth: [140] })(p('b4')),
443
- ),
444
- tr(
445
- td({ colwidth: [110] })(p('c1')),
446
- td({ colwidth: [140] })(p('c4')),
447
- ),
448
- tr(
449
- td({ colwidth: [110] })(p('d1')),
450
- td({ colwidth: [120] })(p('d2')),
451
- td({ colwidth: [130] })(p('d3')),
452
- td({ colwidth: [140] })(p('d4')),
453
- ),
454
- ),
455
- ),
456
- );
457
- const { state, dispatch } = editorView;
458
- dispatch(deleteRows(rowsToRect([0], 3))(state.tr));
459
- expect(editorView.state.doc).toEqualDocument(
460
- doc(
461
- table({ localId: TABLE_LOCAL_ID })(
462
- tr(
463
- td({ colwidth: [110] })(p('b1')),
464
- td({ colwidth: [120] })(p('')),
465
- td({ colwidth: [130] })(p('')),
466
- td({ colwidth: [140] })(p('b4')),
467
- ),
468
- tr(
469
- td({ colwidth: [110] })(p('c1')),
470
- td({ colwidth: [120] })(p('')),
471
- td({ colwidth: [130] })(p('')),
472
- td({ colwidth: [140] })(p('c4')),
473
- ),
474
- tr(
475
- td({ colwidth: [110] })(p('d1')),
476
- td({ colwidth: [120] })(p('d2')),
477
- td({ colwidth: [130] })(p('d3')),
478
- td({ colwidth: [140] })(p('d4')),
479
- ),
480
- ),
481
- ),
482
- );
483
- });
484
- });
485
- });
486
-
487
- describe('when a row-spanning cell overlaps deleted row from the row above', () => {
488
- describe('when this cell has colspan = 1', () => {
489
- it('should decrement the rowspan of that cell', () => {
490
- const { editorView } = editor(
491
- doc(
492
- table()(
493
- tr(
494
- td({ colwidth: [110] })(p('a1')),
495
- td({ colwidth: [120, 130], rowspan: 3, colspan: 2 })(p('a2')),
496
- td({ colwidth: [140] })(p('a4')),
497
- ),
498
- tr(
499
- td({ colwidth: [110] })(p('b1')),
500
- td({ colwidth: [140] })(p('b4')),
501
- ),
502
- tr(
503
- td({ colwidth: [110] })(p('c1')),
504
- td({ colwidth: [140] })(p('c4')),
505
- ),
506
- tr(
507
- td({ colwidth: [110] })(p('d1')),
508
- td({ colwidth: [120] })(p('d2')),
509
- td({ colwidth: [130] })(p('d3')),
510
- td({ colwidth: [140] })(p('d4')),
511
- ),
512
- ),
513
- ),
514
- );
515
- const { state, dispatch } = editorView;
516
- dispatch(deleteRows(rowsToRect([1], 3))(state.tr));
517
- expect(editorView.state.doc).toEqualDocument(
518
- doc(
519
- table({ localId: TABLE_LOCAL_ID })(
520
- tr(
521
- td({ colwidth: [110] })(p('a1')),
522
- td({ colwidth: [120, 130], rowspan: 2, colspan: 2 })(p('a2')),
523
- td({ colwidth: [140] })(p('a4')),
524
- ),
525
- tr(
526
- td({ colwidth: [110] })(p('c1')),
527
- td({ colwidth: [140] })(p('c4')),
528
- ),
529
- tr(
530
- td({ colwidth: [110] })(p('d1')),
531
- td({ colwidth: [120] })(p('d2')),
532
- td({ colwidth: [130] })(p('d3')),
533
- td({ colwidth: [140] })(p('d4')),
534
- ),
535
- ),
536
- ),
537
- );
538
- });
539
- });
540
-
541
- describe('when this cell has colspan > 1', () => {
542
- it('should decrement the rowspan of that cell', () => {
543
- const { editorView } = editor(
544
- doc(
545
- table()(
546
- tr(
547
- td({ colwidth: [110] })(p('a1')),
548
- td({ colwidth: [120], rowspan: 3 })(p('a2')),
549
- td({ colwidth: [130] })(p('a3')),
550
- ),
551
- tr(
552
- td({ colwidth: [110] })(p('b1')),
553
- td({ colwidth: [130] })(p('b3')),
554
- ),
555
- tr(
556
- td({ colwidth: [110] })(p('c1')),
557
- td({ colwidth: [130] })(p('c3')),
558
- ),
559
- ),
560
- ),
561
- );
562
- const { state, dispatch } = editorView;
563
- dispatch(deleteRows(rowsToRect([1], 3))(state.tr));
564
- expect(editorView.state.doc).toEqualDocument(
565
- doc(
566
- table({ localId: TABLE_LOCAL_ID })(
567
- tr(
568
- td({ colwidth: [110] })(p('a1')),
569
- td({ colwidth: [120], rowspan: 2 })(p('a2')),
570
- td({ colwidth: [130] })(p('a3')),
571
- ),
572
- tr(
573
- td({ colwidth: [110] })(p('c1')),
574
- td({ colwidth: [130] })(p('c3')),
575
- ),
576
- ),
577
- ),
578
- );
579
- });
580
- });
581
- });
582
-
583
- describe('when a row-spanning cell overlaps two deleted rows from the row above', () => {
584
- it('should decrement the rowspan of that cell twice', () => {
585
- const { editorView } = editor(
586
- doc(
587
- table()(
588
- tr(
589
- td({ colwidth: [110] })(p('a1')),
590
- td({ colwidth: [120], rowspan: 3 })(p('a2')),
591
- td({ colwidth: [130] })(p('a3')),
592
- ),
593
- tr(
594
- td({ colwidth: [110] })(p('b1')),
595
- td({ colwidth: [130] })(p('b3')),
596
- ),
597
- tr(
598
- td({ colwidth: [110] })(p('c1')),
599
- td({ colwidth: [130] })(p('c3')),
600
- ),
601
- ),
602
- ),
603
- );
604
- const { state, dispatch } = editorView;
605
- dispatch(deleteRows(rowsToRect([1, 2], 3))(state.tr));
606
- expect(editorView.state.doc).toEqualDocument(
607
- doc(
608
- table({ localId: TABLE_LOCAL_ID })(
609
- tr(
610
- td({ colwidth: [110] })(p('a1')),
611
- td({ colwidth: [120] })(p('a2')),
612
- td({ colwidth: [130] })(p('a3')),
613
- ),
614
- ),
615
- ),
616
- );
617
- });
618
- });
619
- });
620
- });