@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,670 +0,0 @@
1
- import type { DocBuilder } from '@atlaskit/editor-common/types';
2
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
3
- import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
5
- import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
6
- import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
7
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
8
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
9
- import type { PluginKey } from '@atlaskit/editor-prosemirror/state';
10
- // eslint-disable-next-line import/no-extraneous-dependencies
11
- import type { LightEditorPlugin } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
12
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
13
- import {
14
- createProsemirrorEditorFactory,
15
- Preset,
16
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
17
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
18
- import {
19
- doc,
20
- p,
21
- table,
22
- td,
23
- tdCursor,
24
- tdEmpty,
25
- tr,
26
- } from '@atlaskit/editor-test-helpers/doc-builder';
27
-
28
- import tablePlugin from '../../plugin';
29
- import { pluginKey } from '../../pm-plugins/plugin-key';
30
- import type { TablePluginState } from '../../types';
31
- import {
32
- getColumnClassNames,
33
- getColumnDeleteButtonParams,
34
- getRowClassNames,
35
- getRowDeleteButtonParams,
36
- getRowHeights,
37
- getRowsParams,
38
- isColumnDeleteButtonVisible,
39
- isRowDeleteButtonVisible,
40
- } from '../../utils';
41
- import { getColumnsWidths } from '../../utils/column-controls';
42
-
43
- describe('table plugin: utils', () => {
44
- const createEditor = createProsemirrorEditorFactory();
45
- const preset = new Preset<LightEditorPlugin>()
46
- .add([featureFlagsPlugin, {}])
47
- .add([analyticsPlugin, {}])
48
- .add(contentInsertionPlugin)
49
- .add(widthPlugin)
50
- .add(guidelinePlugin)
51
- .add(selectionPlugin)
52
- .add(tablePlugin);
53
-
54
- const editor = (doc: DocBuilder) =>
55
- createEditor<TablePluginState, PluginKey, typeof preset>({
56
- doc,
57
- preset,
58
- pluginKey,
59
- });
60
-
61
- describe('#getColumnsWidths', () => {
62
- describe('when columns are not merged', () => {
63
- it('should return an array of widths of all columns', () => {
64
- const { editorView } = editor(
65
- doc(
66
- p('text'),
67
- table()(
68
- tr(td({})(p('a1')), td({})(p('a2'))),
69
- tr(td({})(p('b1')), td({})(p('b2'))),
70
- ),
71
- ),
72
- );
73
- const columnsWidths = getColumnsWidths(editorView);
74
- columnsWidths.forEach((width) => {
75
- expect(typeof width).toEqual('number');
76
- expect(width && width > 0).toBe(true);
77
- });
78
- });
79
- });
80
-
81
- describe('when columns are merged', () => {
82
- describe('when merged column has cells', () => {
83
- it('should return an array of widths of all columns', () => {
84
- const { editorView } = editor(
85
- doc(
86
- p('text'),
87
- table()(
88
- tr(td({ colspan: 2 })(p('a1')), td({})(p('a3'))),
89
- tr(td({})(p('b1')), td({})(p('b2')), td({})(p('b3'))),
90
- ),
91
- ),
92
- );
93
- const columnsWidths = getColumnsWidths(editorView);
94
- expect(columnsWidths).toEqual([1, undefined, 1]);
95
- });
96
- });
97
- });
98
- });
99
-
100
- describe('#getRowHeights', () => {
101
- describe('when rows are not merged', () => {
102
- it('should return an array of heights of all rows', () => {
103
- const { editorView } = editor(
104
- doc(
105
- p('text'),
106
- table()(
107
- tr(td({})(p('a1')), td({})(p('a2'))),
108
- tr(td({})(p('b1')), td({})(p('b2'))),
109
- ),
110
- ),
111
- );
112
- const tableRef = editorView.dom.querySelector('table')!;
113
- const rowHeights = getRowHeights(tableRef);
114
- rowHeights.forEach((height) => {
115
- expect(typeof height).toEqual('number');
116
- expect(height > 0).toBe(true);
117
- });
118
- });
119
- });
120
-
121
- describe('when rows are merged', () => {
122
- describe('when merged row has cells', () => {
123
- it('should return an array of heights of all rows', () => {
124
- const { editorView } = editor(
125
- doc(
126
- p('text'),
127
- table()(
128
- tr(td({ rowspan: 2 })(p('a1')), td({})(p('a2'))),
129
- tr(td({})(p('b2'))),
130
- ),
131
- ),
132
- );
133
- const tableRef = editorView.dom.querySelector('table')!;
134
- const rowHeights = getRowHeights(tableRef);
135
-
136
- rowHeights.forEach((height) => {
137
- expect(typeof height).toEqual('number');
138
- expect(height > 0).toBe(true);
139
- });
140
- });
141
- });
142
- });
143
- });
144
-
145
- describe('#isColumnDeleteButtonVisible', () => {
146
- describe('when selection is a TextSelection', () => {
147
- it('should return false', () => {
148
- const { editorView } = editor(
149
- doc(p('text'), table()(tr(tdCursor, tdEmpty, tdEmpty))),
150
- );
151
- expect(isColumnDeleteButtonVisible(editorView.state.selection)).toBe(
152
- false,
153
- );
154
- });
155
- });
156
- describe('when selection is a CellSelection', () => {
157
- describe('when no columns are fully selected', () => {
158
- it('should return false', () => {
159
- const { editorView } = editor(
160
- doc(
161
- p('text'),
162
- table()(
163
- tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
164
- tr(tdEmpty, tdEmpty, td({})(p('{cell>}b3'))),
165
- tr(tdEmpty, tdEmpty, tdEmpty),
166
- ),
167
- ),
168
- );
169
-
170
- expect(isColumnDeleteButtonVisible(editorView.state.selection)).toBe(
171
- false,
172
- );
173
- });
174
- });
175
- describe('when a column is selected', () => {
176
- it('should return true', () => {
177
- const { editorView } = editor(
178
- doc(
179
- p('text'),
180
- table()(
181
- tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
182
- tr(tdEmpty, tdEmpty, tdEmpty),
183
- tr(td({})(p('{cell>}c1')), tdEmpty, tdEmpty),
184
- ),
185
- ),
186
- );
187
-
188
- expect(isColumnDeleteButtonVisible(editorView.state.selection)).toBe(
189
- true,
190
- );
191
- });
192
- });
193
- describe('when table is selected', () => {
194
- it('should return false', () => {
195
- const { editorView } = editor(
196
- doc(
197
- p('text'),
198
- table()(
199
- tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
200
- tr(tdEmpty, tdEmpty, tdEmpty),
201
- tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
202
- ),
203
- ),
204
- );
205
-
206
- expect(isColumnDeleteButtonVisible(editorView.state.selection)).toBe(
207
- false,
208
- );
209
- });
210
- });
211
- });
212
- });
213
-
214
- describe('#isRowDeleteButtonVisible', () => {
215
- describe('when selection is a TextSelection', () => {
216
- it('should return false', () => {
217
- const { editorView } = editor(
218
- doc(p('text'), table()(tr(tdCursor, tdEmpty, tdEmpty))),
219
- );
220
- expect(isRowDeleteButtonVisible(editorView.state.selection)).toBe(
221
- false,
222
- );
223
- });
224
- });
225
- describe('when selection is a CellSelection', () => {
226
- describe('when no rows are fully selected', () => {
227
- it('should return false', () => {
228
- const { editorView } = editor(
229
- doc(
230
- p('text'),
231
- table()(
232
- tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
233
- tr(tdEmpty, td({})(p('{cell>}b3')), tdEmpty),
234
- tr(tdEmpty, tdEmpty, tdEmpty),
235
- ),
236
- ),
237
- );
238
-
239
- expect(isRowDeleteButtonVisible(editorView.state.selection)).toBe(
240
- false,
241
- );
242
- });
243
- });
244
- describe('when a row is selected', () => {
245
- it('should return true', () => {
246
- const { editorView } = editor(
247
- doc(
248
- p('text'),
249
- table()(
250
- tr(td({})(p('{<cell}a1')), tdEmpty, td({})(p('{cell>}a1'))),
251
- tr(tdEmpty, tdEmpty, tdEmpty),
252
- tr(tdEmpty, tdEmpty, tdEmpty),
253
- ),
254
- ),
255
- );
256
-
257
- expect(isRowDeleteButtonVisible(editorView.state.selection)).toBe(
258
- true,
259
- );
260
- });
261
- });
262
- describe('when table is selected', () => {
263
- it('should return false', () => {
264
- const { editorView } = editor(
265
- doc(
266
- p('text'),
267
- table()(
268
- tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
269
- tr(tdEmpty, tdEmpty, tdEmpty),
270
- tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
271
- ),
272
- ),
273
- );
274
-
275
- expect(isRowDeleteButtonVisible(editorView.state.selection)).toBe(
276
- false,
277
- );
278
- });
279
- });
280
- });
281
- });
282
-
283
- describe('#getColumnDeleteButtonParams', () => {
284
- describe('when selection is a TextSelection', () => {
285
- it('should return null', () => {
286
- const { editorView } = editor(
287
- doc(p('text'), table()(tr(tdCursor, tdEmpty, tdEmpty))),
288
- );
289
- const columnsWidths = [100, 150, 200];
290
- expect(
291
- getColumnDeleteButtonParams(
292
- columnsWidths,
293
- editorView.state.selection,
294
- ),
295
- ).toBe(null);
296
- });
297
- });
298
- describe('when selection is a CellSelection and 3 columns are selected', () => {
299
- describe('columnsWidths = [100, 150, 200]', () => {
300
- it('should return indexes = [0, 1, 2]', () => {
301
- const { editorView } = editor(
302
- doc(
303
- p('text'),
304
- table()(
305
- tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty, tdEmpty),
306
- tr(tdEmpty, tdEmpty, tdEmpty, tdEmpty),
307
- tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3')), tdEmpty),
308
- ),
309
- ),
310
- );
311
-
312
- const columnsWidths = [100, 150, 200];
313
- const { indexes, left } = getColumnDeleteButtonParams(
314
- columnsWidths,
315
- editorView.state.selection,
316
- )!;
317
- expect(indexes).toEqual([0, 1, 2]);
318
- expect(left > 0).toBe(true);
319
- });
320
- });
321
- });
322
- });
323
-
324
- describe('#getRowDeleteButtonParams', () => {
325
- describe('when selection is a TextSelection', () => {
326
- it('should return null', () => {
327
- const { editorView } = editor(
328
- doc(
329
- p('text'),
330
- table()(
331
- tr(tdCursor, tdEmpty, tdEmpty),
332
- tr(tdEmpty, tdEmpty, tdEmpty),
333
- tr(tdEmpty, tdEmpty, tdEmpty),
334
- ),
335
- ),
336
- );
337
- const rowsHeights = [100, 150, 200];
338
- expect(
339
- getRowDeleteButtonParams(rowsHeights, editorView.state.selection),
340
- ).toBe(null);
341
- });
342
- });
343
- describe('when selection is a CellSelection and 3 rows are selected', () => {
344
- describe('rowsHeights = [100, 150, 200]', () => {
345
- it('should return indexes = [0, 1, 2]', () => {
346
- const { editorView } = editor(
347
- doc(
348
- p('text'),
349
- table()(
350
- tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
351
- tr(tdEmpty, tdEmpty, tdEmpty),
352
- tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
353
- tr(tdEmpty, tdEmpty, tdEmpty),
354
- ),
355
- ),
356
- );
357
-
358
- const rowsHeights = [100, 150, 200];
359
- const { indexes, top } = getRowDeleteButtonParams(
360
- rowsHeights,
361
- editorView.state.selection,
362
- )!;
363
- expect(indexes).toEqual([0, 1, 2]);
364
- expect(top > 0).toBe(true);
365
- });
366
- });
367
- describe('rowsHeights = [100, ,150, ,200]', () => {
368
- it('should return indexes = [0, 1, 2]', () => {
369
- const { editorView } = editor(
370
- doc(
371
- p('text'),
372
- table()(
373
- tr(
374
- td({ rowspan: 2 })(p('{<cell}a1')),
375
- td({ rowspan: 2 })(p('a2')),
376
- td({ rowspan: 2 })(p('a3')),
377
- ),
378
- tr(
379
- td({ rowspan: 2 })(p('c1')),
380
- td({ rowspan: 2 })(p('c2')),
381
- td({ rowspan: 2 })(p('{cell>}c3')),
382
- ),
383
- tr(tdEmpty, tdEmpty, tdEmpty),
384
- ),
385
- ),
386
- );
387
-
388
- const rowsHeights = [100, , 150, , 200];
389
- const { indexes, top } = getRowDeleteButtonParams(
390
- rowsHeights,
391
- editorView.state.selection,
392
- )!;
393
- expect(indexes).toEqual([0, 2]);
394
- expect(top > 0).toBe(true);
395
- });
396
- });
397
- });
398
- });
399
-
400
- describe('#getRowsParams', () => {
401
- describe('rowHeights = [100, 150, 200]', () => {
402
- it('should return consecutive indexes', () => {
403
- const rowHeights = [100, 150, 200];
404
- const rows = getRowsParams(rowHeights);
405
- rows.forEach((row, index) => {
406
- expect(row.startIndex).toEqual(index);
407
- expect(row.endIndex).toEqual(index + 1);
408
- expect(row.height).toEqual(rowHeights[index]);
409
- });
410
- });
411
- });
412
- describe('rowHeights = [100, ,150, ,200]', () => {
413
- it('should return correct indexes', () => {
414
- const rowHeights = [100, , 150, , 200];
415
- const rows = getRowsParams(rowHeights);
416
- const expectedIndexes = [0, 2, 4, 5];
417
- for (let i = 0, count = rows.length; i < count; i++) {
418
- const row = rows[i];
419
- expect(row.startIndex).toEqual(expectedIndexes[i]);
420
- expect(row.endIndex).toEqual(expectedIndexes[i + 1]);
421
- expect(row.height).toEqual(rowHeights[expectedIndexes[i]]);
422
- }
423
- });
424
- });
425
- });
426
-
427
- describe('#getColumnClassNames', () => {
428
- describe('when selection is a TextSelection', () => {
429
- [[0], [1], [2], [0, 1], [1, 2], [0, 2]].forEach((hoveredColumns) => {
430
- describe(`when hoveredColumns = ${hoveredColumns}`, () => {
431
- it('return a string containing "active" substring', () => {
432
- const { editorView } = editor(
433
- doc(
434
- p('text'),
435
- table()(
436
- tr(tdCursor, tdEmpty, tdEmpty),
437
- tr(tdEmpty, tdEmpty, tdEmpty),
438
- tr(tdEmpty, tdEmpty, tdEmpty),
439
- ),
440
- ),
441
- );
442
- const isInDanger = false;
443
- const classNames = getColumnClassNames(
444
- hoveredColumns[0],
445
- editorView.state.selection,
446
- hoveredColumns,
447
- isInDanger,
448
- );
449
- expect(classNames.indexOf('active') > -1).toBe(true);
450
- });
451
- describe('when isInDanger = true', () => {
452
- it('return a string containing "danger" substring', () => {
453
- const { editorView } = editor(
454
- doc(
455
- p('text'),
456
- table()(
457
- tr(tdCursor, tdEmpty, tdEmpty),
458
- tr(tdEmpty, tdEmpty, tdEmpty),
459
- tr(tdEmpty, tdEmpty, tdEmpty),
460
- ),
461
- ),
462
- );
463
- const isInDanger = true;
464
- const classNames = getColumnClassNames(
465
- hoveredColumns[0],
466
- editorView.state.selection,
467
- hoveredColumns,
468
- isInDanger,
469
- );
470
- expect(classNames.indexOf('danger') > -1).toBe(true);
471
- });
472
- });
473
- });
474
- });
475
- });
476
- describe('when selection is a CellSelection', () => {
477
- describe('when no columns are fully selected', () => {
478
- it('should return an empty string', () => {
479
- const { editorView } = editor(
480
- doc(
481
- p('text'),
482
- table()(
483
- tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
484
- tr(tdEmpty, tdEmpty, td({})(p('{cell>}b3'))),
485
- tr(tdEmpty, tdEmpty, tdEmpty),
486
- ),
487
- ),
488
- );
489
-
490
- const classNames = getColumnClassNames(
491
- 0,
492
- editorView.state.selection,
493
- [],
494
- false,
495
- );
496
- expect(classNames).toBe('');
497
- });
498
- });
499
- describe('when a column is selected', () => {
500
- it('return a string containing "active" substring', () => {
501
- const { editorView } = editor(
502
- doc(
503
- p('text'),
504
- table()(
505
- tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
506
- tr(tdEmpty, tdEmpty, tdEmpty),
507
- tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
508
- ),
509
- ),
510
- );
511
-
512
- [0, 1, 2].forEach((index) => {
513
- const classNames = getColumnClassNames(
514
- index,
515
- editorView.state.selection,
516
- [],
517
- false,
518
- );
519
- expect(classNames.indexOf('active') > -1).toBe(true);
520
- });
521
- });
522
- describe('when isInDanger = true', () => {
523
- it('return a string containing "danger" substring', () => {
524
- const { editorView } = editor(
525
- doc(
526
- p('text'),
527
- table()(
528
- tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
529
- tr(tdEmpty, tdEmpty, tdEmpty),
530
- tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
531
- ),
532
- ),
533
- );
534
- [0, 1, 2].forEach((index) => {
535
- const classNames = getColumnClassNames(
536
- index,
537
- editorView.state.selection,
538
- [],
539
- true,
540
- );
541
- expect(classNames.indexOf('danger') > -1).toBe(true);
542
- });
543
- });
544
- });
545
- });
546
- });
547
- });
548
-
549
- describe('#getRowClassNames', () => {
550
- describe('when selection is a TextSelection', () => {
551
- [[0], [1], [2], [0, 1], [1, 2], [0, 2]].forEach((hoveredRows) => {
552
- describe(`when hoveredRows = ${hoveredRows}`, () => {
553
- it('return a string containing "active" substring', () => {
554
- const { editorView } = editor(
555
- doc(
556
- p('text'),
557
- table()(
558
- tr(tdCursor, tdEmpty, tdEmpty),
559
- tr(tdEmpty, tdEmpty, tdEmpty),
560
- tr(tdEmpty, tdEmpty, tdEmpty),
561
- ),
562
- ),
563
- );
564
- const isInDanger = false;
565
- const classNames = getRowClassNames(
566
- hoveredRows[0],
567
- editorView.state.selection,
568
- hoveredRows,
569
- isInDanger,
570
- );
571
- expect(classNames.indexOf('active') > -1).toBe(true);
572
- });
573
- describe('when isInDanger = true', () => {
574
- it('return a string containing "danger" substring', () => {
575
- const { editorView } = editor(
576
- doc(
577
- p('text'),
578
- table()(
579
- tr(tdCursor, tdEmpty, tdEmpty),
580
- tr(tdEmpty, tdEmpty, tdEmpty),
581
- tr(tdEmpty, tdEmpty, tdEmpty),
582
- ),
583
- ),
584
- );
585
- const isInDanger = true;
586
- const classNames = getRowClassNames(
587
- hoveredRows[0],
588
- editorView.state.selection,
589
- hoveredRows,
590
- isInDanger,
591
- );
592
- expect(classNames.indexOf('danger') > -1).toBe(true);
593
- });
594
- });
595
- });
596
- });
597
- });
598
- describe('when selection is a CellSelection', () => {
599
- describe('when no rows are fully selected', () => {
600
- it('should return an empty string', () => {
601
- const { editorView } = editor(
602
- doc(
603
- p('text'),
604
- table()(
605
- tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
606
- tr(tdEmpty, tdEmpty, tdEmpty),
607
- tr(tdEmpty, td({})(p('{cell>}c3')), tdEmpty),
608
- ),
609
- ),
610
- );
611
-
612
- const classNames = getRowClassNames(
613
- 0,
614
- editorView.state.selection,
615
- [],
616
- false,
617
- );
618
- expect(classNames).toBe('');
619
- });
620
- });
621
- describe('when a row is selected', () => {
622
- it('return a string containing "active" substring', () => {
623
- const { editorView } = editor(
624
- doc(
625
- p('text'),
626
- table()(
627
- tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
628
- tr(tdEmpty, tdEmpty, tdEmpty),
629
- tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
630
- ),
631
- ),
632
- );
633
-
634
- [0, 1, 2].forEach((index) => {
635
- const classNames = getRowClassNames(
636
- index,
637
- editorView.state.selection,
638
- [],
639
- false,
640
- );
641
- expect(classNames.indexOf('active') > -1).toBe(true);
642
- });
643
- });
644
- describe('when isInDanger = true', () => {
645
- it('return a string containing "danger" substring', () => {
646
- const { editorView } = editor(
647
- doc(
648
- p('text'),
649
- table()(
650
- tr(td({})(p('{<cell}a1')), tdEmpty, tdEmpty),
651
- tr(tdEmpty, tdEmpty, tdEmpty),
652
- tr(tdEmpty, tdEmpty, td({})(p('{cell>}c3'))),
653
- ),
654
- ),
655
- );
656
- [0, 1, 2].forEach((index) => {
657
- const classNames = getRowClassNames(
658
- index,
659
- editorView.state.selection,
660
- [],
661
- true,
662
- );
663
- expect(classNames.indexOf('danger') > -1).toBe(true);
664
- });
665
- });
666
- });
667
- });
668
- });
669
- });
670
- });