@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,512 +0,0 @@
1
- import type {
2
- Command,
3
- DropdownOptionT,
4
- FloatingToolbarDropdown,
5
- } from '@atlaskit/editor-common/types';
6
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
7
- import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
8
- import { contentInsertionPlugin } from '@atlaskit/editor-plugin-content-insertion';
9
- import { featureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
10
- import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
11
- import { selectionPlugin } from '@atlaskit/editor-plugin-selection';
12
- import { widthPlugin } from '@atlaskit/editor-plugin-width';
13
- import { Rect } from '@atlaskit/editor-tables/table-map';
14
- import { splitCell } from '@atlaskit/editor-tables/utils';
15
- // eslint-disable-next-line import/no-extraneous-dependencies
16
- import type { LightEditorPlugin } 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
- createProsemirrorEditorFactory,
20
- Preset,
21
- } from '@atlaskit/editor-test-helpers/create-prosemirror-editor';
22
- // eslint-disable-next-line import/no-extraneous-dependencies -- Removed import for fixing circular dependencies
23
- import {
24
- doc,
25
- p,
26
- tr as row,
27
- table,
28
- td,
29
- tdEmpty,
30
- th,
31
- thEmpty,
32
- tr,
33
- } from '@atlaskit/editor-test-helpers/doc-builder';
34
-
35
- import tablePlugin from '../../plugin';
36
- import { pluginKey } from '../../pm-plugins/plugin-key';
37
- import { getNewResizeStateFromSelectedColumns } from '../../pm-plugins/table-resizing/utils/resize-state';
38
- import {
39
- getToolbarCellOptionsConfig,
40
- getToolbarMenuConfig,
41
- } from '../../toolbar';
42
- import { canMergeCells } from '../../transforms';
43
- import type { ToolbarMenuConfig, ToolbarMenuState } from '../../types';
44
- import { getMergedCellsPositions } from '../../utils';
45
-
46
- jest.mock('@atlaskit/editor-tables/utils');
47
- jest.mock('../../transforms');
48
- jest.mock('../../utils');
49
- jest.mock('../../pm-plugins/table-resizing/utils/resize-state');
50
-
51
- (getMergedCellsPositions as Function as jest.Mock<{}>).mockImplementation(
52
- () => () => [],
53
- );
54
-
55
- const formatMessage: (t: unknown) => string = (id) => 'Lorem ipsum';
56
- const ctx = { formatMessage };
57
-
58
- describe('getToolbarMenuConfig', () => {
59
- it('hidden by default', () => {
60
- const menu = getToolbarMenuConfig({}, {}, ctx, undefined);
61
- expect(menu.hidden).toBe(true);
62
- });
63
-
64
- it('visible for allowHeaderRow', () => {
65
- const menu = getToolbarMenuConfig(
66
- { allowHeaderRow: true },
67
- {},
68
- ctx,
69
- undefined,
70
- );
71
- expect(menu.hidden).toBe(false);
72
- });
73
-
74
- it('visible for allowHeaderColumn', () => {
75
- const menu = getToolbarMenuConfig(
76
- { allowHeaderColumn: true },
77
- {},
78
- ctx,
79
- undefined,
80
- );
81
- expect(menu.hidden).toBe(false);
82
- });
83
-
84
- it('visible for allowNumberColumn', () => {
85
- const menu = getToolbarMenuConfig(
86
- { allowNumberColumn: true },
87
- {},
88
- ctx,
89
- undefined,
90
- );
91
- expect(menu.hidden).toBe(false);
92
- });
93
-
94
- it('visible for allowCollapse', () => {
95
- const menu = getToolbarMenuConfig(
96
- { allowCollapse: true },
97
- {},
98
- ctx,
99
- undefined,
100
- );
101
- expect(menu.hidden).toBe(false);
102
- });
103
-
104
- describe('collapse button states', () => {
105
- const getCollapseItem = (
106
- config: ToolbarMenuConfig,
107
- state: ToolbarMenuState,
108
- ) => {
109
- const menu = getToolbarMenuConfig(config, state, ctx, undefined);
110
- const options = (menu as FloatingToolbarDropdown<Command>).options;
111
-
112
- if (Array.isArray(options)) {
113
- return options.find(
114
- (option) => option.id === 'editor.table.collapseTable',
115
- );
116
- }
117
- };
118
-
119
- it('should show tick if table is collapsed', () => {
120
- const item = getCollapseItem(
121
- { allowCollapse: true },
122
- { isTableCollapsed: true },
123
- )!;
124
-
125
- expect(item.selected).toBe(true);
126
- });
127
- it('should not show tick if table is not collapsed', () => {
128
- const item = getCollapseItem(
129
- { allowCollapse: true },
130
- { isTableCollapsed: false },
131
- )!;
132
-
133
- expect(item.selected).toBe(false);
134
- });
135
-
136
- it('should be enabled if table can be collapsed', () => {
137
- const item = getCollapseItem(
138
- { allowCollapse: true },
139
- { canCollapseTable: true },
140
- )!;
141
-
142
- expect(item.disabled).toBe(false);
143
- });
144
-
145
- it('should be disabled if table cannot be collapsed', () => {
146
- const item = getCollapseItem(
147
- { allowCollapse: true },
148
- { canCollapseTable: false },
149
- )!;
150
-
151
- expect(item.disabled).toBe(true);
152
- });
153
-
154
- it('should be hidden if collapse feature flag is disabled', () => {
155
- const item = getCollapseItem({ allowCollapse: false }, {})!;
156
-
157
- expect(item.hidden).toBe(true);
158
- });
159
- });
160
- });
161
-
162
- describe('getToolbarCellOptionsConfig', () => {
163
- const createEditor = createProsemirrorEditorFactory();
164
- const props = {
165
- preset: new Preset<LightEditorPlugin>()
166
- .add([featureFlagsPlugin, {}])
167
- .add([analyticsPlugin, {}])
168
- .add(contentInsertionPlugin)
169
- .add(widthPlugin)
170
- .add(guidelinePlugin)
171
- .add(selectionPlugin)
172
- .add([
173
- tablePlugin,
174
- {
175
- tableOptions: {
176
- allowDistributeColumns: true,
177
- allowColumnResizing: true,
178
- allowColumnSorting: true,
179
- },
180
- },
181
- ]),
182
- pluginKey,
183
- };
184
- const { editorView } = createEditor({
185
- doc: doc(table()(row(td()(p('1{cursor}'))))),
186
- ...props,
187
- });
188
- const { state } = editorView;
189
- const getEditorContainerWidth = () => ({ width: 500 });
190
-
191
- const formatMessage: (t: { id: string }) => string = (message) =>
192
- `${message.id}`;
193
- const rect = new Rect(1, 1, 1, 1);
194
- const cellOptionsMenu = getToolbarCellOptionsConfig(
195
- state,
196
- editorView,
197
- rect,
198
- {
199
- formatMessage,
200
- },
201
- getEditorContainerWidth,
202
- undefined,
203
- );
204
-
205
- beforeEach(() => {
206
- jest.resetAllMocks();
207
- (getMergedCellsPositions as Function as jest.Mock<{}>).mockImplementation(
208
- () => () => [],
209
- );
210
- });
211
-
212
- it('is a dropdown with the following dropdown items with the given order', () => {
213
- const items = cellOptionsMenu.options as Array<DropdownOptionT<Command>>;
214
- expect(items[0]).toMatchObject({
215
- title: 'fabric.editor.insertColumn',
216
- selected: false,
217
- disabled: false,
218
- });
219
- expect(items[1]).toMatchObject({
220
- title: 'fabric.editor.insertRow',
221
- selected: false,
222
- disabled: false,
223
- });
224
- expect(items[2]).toMatchObject({
225
- title: 'fabric.editor.removeColumns',
226
- selected: false,
227
- disabled: false,
228
- });
229
- expect(items[3]).toMatchObject({
230
- title: 'fabric.editor.removeRows',
231
- selected: false,
232
- disabled: false,
233
- });
234
- expect(items[4]).toMatchObject({
235
- title: 'fabric.editor.mergeCells',
236
- selected: false,
237
- disabled: true,
238
- });
239
- expect(items[5]).toMatchObject({
240
- title: 'fabric.editor.splitCell',
241
- selected: false,
242
- disabled: true,
243
- });
244
- expect(items[6]).toMatchObject({
245
- title: 'fabric.editor.distributeColumns',
246
- selected: false,
247
- disabled: true,
248
- });
249
- expect(items[7]).toMatchObject({
250
- title: 'fabric.editor.sortColumnASC',
251
- selected: false,
252
- disabled: false,
253
- });
254
- expect(items[8]).toMatchObject({
255
- title: 'fabric.editor.sortColumnDESC',
256
- selected: false,
257
- disabled: false,
258
- });
259
- expect(items[9]).toMatchObject({
260
- title: 'fabric.editor.clearCells',
261
- selected: false,
262
- disabled: false,
263
- });
264
- });
265
-
266
- it('should have enabled merge cells when multiple cells are selected', () => {
267
- (canMergeCells as Function as jest.Mock<{}>).mockImplementation(
268
- () => () => true,
269
- );
270
- //
271
- const cellOptionsMenu = getToolbarCellOptionsConfig(
272
- state,
273
- editorView,
274
- rect,
275
- {
276
- formatMessage,
277
- },
278
- getEditorContainerWidth,
279
- undefined,
280
- );
281
- const items = cellOptionsMenu.options as Array<DropdownOptionT<Command>>;
282
- const item = items.find(
283
- (item) => item.title === 'fabric.editor.mergeCells',
284
- );
285
-
286
- expect(item).toMatchObject({
287
- disabled: false,
288
- });
289
- });
290
-
291
- it('should have enabled split cell when cell can be splitted', () => {
292
- (splitCell as Function as jest.Mock<{}>).mockImplementation(
293
- () => () => true,
294
- );
295
- //
296
- const cellOptionsMenu = getToolbarCellOptionsConfig(
297
- state,
298
- editorView,
299
- rect,
300
- {
301
- formatMessage,
302
- },
303
- getEditorContainerWidth,
304
- undefined,
305
- );
306
- const items = cellOptionsMenu.options as Array<DropdownOptionT<Command>>;
307
- const splitCellItem = items.find(
308
- (item) => item.title === 'fabric.editor.splitCell',
309
- );
310
-
311
- expect(splitCellItem).toMatchObject({
312
- disabled: false,
313
- });
314
- });
315
-
316
- it('should disable sorting when merged cells are detected', () => {
317
- (getMergedCellsPositions as Function as jest.Mock<{}>).mockImplementation(
318
- () => [1, 2, 3],
319
- );
320
-
321
- const cellOptionsMenu = getToolbarCellOptionsConfig(
322
- state,
323
- editorView,
324
- rect,
325
- {
326
- formatMessage,
327
- },
328
- getEditorContainerWidth,
329
- undefined,
330
- );
331
-
332
- const items = cellOptionsMenu.options as Array<DropdownOptionT<Command>>;
333
- const sortItems = items.filter((item) =>
334
- item.id?.startsWith('editor.table.sortColumn'),
335
- );
336
-
337
- const isDisabled = sortItems.every((item) => item.disabled);
338
- const hasTooltip = sortItems.every((item) => item.tooltip);
339
-
340
- expect(isDisabled).toBeTruthy();
341
- expect(hasTooltip).toBeTruthy();
342
- });
343
-
344
- it('should allow sorting when there are no merged cells detected', () => {
345
- (getMergedCellsPositions as Function as jest.Mock<{}>).mockImplementation(
346
- () => [],
347
- );
348
-
349
- const cellOptionsMenu = getToolbarCellOptionsConfig(
350
- state,
351
- editorView,
352
- rect,
353
- {
354
- formatMessage,
355
- },
356
- getEditorContainerWidth,
357
- undefined,
358
- );
359
-
360
- const items = cellOptionsMenu.options as Array<DropdownOptionT<Command>>;
361
- const sortItems = items.filter((item) =>
362
- item.id?.startsWith('editor.table.sortColumn'),
363
- );
364
-
365
- const isDisabled = sortItems.every((item) => item.disabled);
366
- const hasTooltip = sortItems.every((item) => item.tooltip);
367
-
368
- expect(isDisabled).toBeFalsy();
369
- expect(hasTooltip).toBeFalsy();
370
- });
371
-
372
- it('should disable distribute columns when no resize detected', () => {
373
- (
374
- getNewResizeStateFromSelectedColumns as Function as jest.Mock<{}>
375
- ).mockImplementation(() => ({ changed: false }));
376
-
377
- const cellOptionsMenu = getToolbarCellOptionsConfig(
378
- state,
379
- editorView,
380
- rect,
381
- {
382
- formatMessage,
383
- },
384
- getEditorContainerWidth,
385
- undefined,
386
- );
387
-
388
- const items = cellOptionsMenu.options as Array<DropdownOptionT<Command>>;
389
- const distributeColumns = items.filter((item) =>
390
- item.id?.startsWith('editor.table.distributeColumns'),
391
- );
392
-
393
- const isDisabled = distributeColumns.every((item) => item.disabled);
394
- expect(isDisabled).toBeTruthy();
395
- });
396
-
397
- it('should allow distribute columns when resize detected', () => {
398
- (
399
- getNewResizeStateFromSelectedColumns as Function as jest.Mock<{}>
400
- ).mockImplementation(() => ({ changed: true }));
401
-
402
- const cellOptionsMenu = getToolbarCellOptionsConfig(
403
- state,
404
- editorView,
405
- rect,
406
- {
407
- formatMessage,
408
- },
409
- getEditorContainerWidth,
410
- undefined,
411
- );
412
-
413
- const items = cellOptionsMenu.options as Array<DropdownOptionT<Command>>;
414
- const distributeColumns = items.filter((item) =>
415
- item.id?.startsWith('editor.table.distributeColumns'),
416
- );
417
-
418
- const isDisabled = distributeColumns.every((item) => item.disabled);
419
- expect(isDisabled).toBeFalsy();
420
- });
421
-
422
- it('should disable distribute columns when editorView is undefined', () => {
423
- const cellOptionsMenu = getToolbarCellOptionsConfig(
424
- state,
425
- undefined,
426
- rect,
427
- {
428
- formatMessage,
429
- },
430
- getEditorContainerWidth,
431
- undefined,
432
- );
433
-
434
- const items = cellOptionsMenu.options as Array<DropdownOptionT<Command>>;
435
- const distributeColumns = items.filter((item) =>
436
- item.id?.startsWith('editor.table.distributeColumns'),
437
- );
438
-
439
- const isDisabled = distributeColumns.every((item) => item.disabled);
440
- expect(isDisabled).toBeTruthy();
441
- });
442
-
443
- it('should disable distribute columns if selected cells are without colwidths', () => {
444
- const { editorView } = createEditor({
445
- doc: doc(
446
- table()(
447
- tr(th({})(p('{<cell}')), thEmpty, thEmpty),
448
- tr(tdEmpty, td({})(p('{cell>}')), tdEmpty),
449
- tr(tdEmpty, tdEmpty, tdEmpty),
450
- ),
451
- ),
452
- ...props,
453
- });
454
-
455
- const { state } = editorView;
456
- const rect = new Rect(1, 1, 2, 2);
457
-
458
- const cellOptionsMenu = getToolbarCellOptionsConfig(
459
- state,
460
- editorView,
461
- rect,
462
- {
463
- formatMessage,
464
- },
465
- getEditorContainerWidth,
466
- undefined,
467
- );
468
-
469
- const items = cellOptionsMenu.options as Array<DropdownOptionT<Command>>;
470
- const distributeColumns = items.filter((item) =>
471
- item.id?.startsWith('editor.table.distributeColumns'),
472
- );
473
-
474
- const isDisabled = distributeColumns.every((item) => item.disabled);
475
- expect(isDisabled).toBeTruthy();
476
- });
477
-
478
- it('should disable distribute columns if selection is on a single column', () => {
479
- const { editorView } = createEditor({
480
- doc: doc(
481
- table()(
482
- tr(th({})(p('{<cell}')), thEmpty, thEmpty),
483
- tr(td({})(p('{cell>}')), tdEmpty, tdEmpty),
484
- tr(tdEmpty, tdEmpty, tdEmpty),
485
- ),
486
- ),
487
- ...props,
488
- });
489
-
490
- const { state } = editorView;
491
- const rect = new Rect(1, 1, 1, 2);
492
-
493
- const cellOptionsMenu = getToolbarCellOptionsConfig(
494
- state,
495
- editorView,
496
- rect,
497
- {
498
- formatMessage,
499
- },
500
- getEditorContainerWidth,
501
- undefined,
502
- );
503
-
504
- const items = cellOptionsMenu.options as Array<DropdownOptionT<Command>>;
505
- const distributeColumns = items.filter((item) =>
506
- item.id?.startsWith('editor.table.distributeColumns'),
507
- );
508
-
509
- const isDisabled = distributeColumns.every((item) => item.disabled);
510
- expect(isDisabled).toBeTruthy();
511
- });
512
- });