@atlaskit/editor-plugin-table 7.2.1 → 7.2.3

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 (124) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/nodeviews/TableComponent.js +11 -7
  3. package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +3 -19
  4. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +11 -25
  5. package/dist/cjs/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +13 -3
  6. package/dist/cjs/ui/TableFloatingColumnControls/index.js +7 -3
  7. package/dist/cjs/utils/drag-menu.js +37 -23
  8. package/dist/cjs/utils/merged-cells.js +66 -1
  9. package/dist/es2019/nodeviews/TableComponent.js +9 -5
  10. package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  11. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -21
  12. package/dist/es2019/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +10 -2
  13. package/dist/es2019/ui/TableFloatingColumnControls/index.js +7 -3
  14. package/dist/es2019/utils/drag-menu.js +38 -14
  15. package/dist/es2019/utils/merged-cells.js +73 -0
  16. package/dist/esm/nodeviews/TableComponent.js +11 -7
  17. package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +4 -20
  18. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -21
  19. package/dist/esm/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +10 -2
  20. package/dist/esm/ui/TableFloatingColumnControls/index.js +7 -3
  21. package/dist/esm/utils/drag-menu.js +36 -22
  22. package/dist/esm/utils/merged-cells.js +65 -0
  23. package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  24. package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -0
  25. package/dist/types/ui/TableFloatingColumnControls/index.d.ts +1 -0
  26. package/dist/types/utils/drag-menu.d.ts +4 -1
  27. package/dist/types/utils/merged-cells.d.ts +2 -0
  28. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -1
  29. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -0
  30. package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +1 -0
  31. package/dist/types-ts4.5/utils/drag-menu.d.ts +4 -1
  32. package/dist/types-ts4.5/utils/merged-cells.d.ts +2 -0
  33. package/package.json +9 -16
  34. package/src/nodeviews/TableComponent.tsx +1 -0
  35. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +11 -32
  36. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +6 -27
  37. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +12 -1
  38. package/src/ui/TableFloatingColumnControls/index.tsx +5 -0
  39. package/src/utils/drag-menu.ts +94 -20
  40. package/src/utils/merged-cells.ts +78 -0
  41. package/tsconfig.dev.json +0 -69
  42. package/tsconfig.json +2 -871
  43. package/examples/99-testing.tsx +0 -140
  44. package/examples/config.jsonc +0 -14
  45. package/src/__tests__/unit/analytics.ts +0 -888
  46. package/src/__tests__/unit/collab.ts +0 -93
  47. package/src/__tests__/unit/commands/go-to-next-cell.ts +0 -173
  48. package/src/__tests__/unit/commands/insert.ts +0 -137
  49. package/src/__tests__/unit/commands/misc.ts +0 -185
  50. package/src/__tests__/unit/commands/sort.ts +0 -128
  51. package/src/__tests__/unit/commands.ts +0 -745
  52. package/src/__tests__/unit/copy-button.ts +0 -22
  53. package/src/__tests__/unit/copy-paste.ts +0 -677
  54. package/src/__tests__/unit/event-handlers/index.ts +0 -125
  55. package/src/__tests__/unit/event-handlers.ts +0 -296
  56. package/src/__tests__/unit/fix-tables.ts +0 -164
  57. package/src/__tests__/unit/get-toolbar-config.ts +0 -127
  58. package/src/__tests__/unit/handlers.ts +0 -98
  59. package/src/__tests__/unit/hover-selection.ts +0 -230
  60. package/src/__tests__/unit/index-with-fake-timers.ts +0 -111
  61. package/src/__tests__/unit/index.ts +0 -912
  62. package/src/__tests__/unit/layout.ts +0 -146
  63. package/src/__tests__/unit/nodeviews/OverflowShadowsObserver.ts +0 -162
  64. package/src/__tests__/unit/nodeviews/TableComponent.tsx +0 -280
  65. package/src/__tests__/unit/nodeviews/TableContainer.tsx +0 -525
  66. package/src/__tests__/unit/nodeviews/cell.ts +0 -132
  67. package/src/__tests__/unit/nodeviews/table.ts +0 -129
  68. package/src/__tests__/unit/pm-plugins/analytics.ts +0 -327
  69. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +0 -94
  70. package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +0 -176
  71. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +0 -211
  72. package/src/__tests__/unit/pm-plugins/main.ts +0 -214
  73. package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -101
  74. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +0 -562
  75. package/src/__tests__/unit/pm-plugins/table-local-id.ts +0 -507
  76. package/src/__tests__/unit/pm-plugins/table-resizing/colgroup.ts +0 -269
  77. package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +0 -192
  78. package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +0 -33
  79. package/src/__tests__/unit/pm-plugins/table-width.ts +0 -292
  80. package/src/__tests__/unit/sort-column.ts +0 -399
  81. package/src/__tests__/unit/toolbar.ts +0 -512
  82. package/src/__tests__/unit/transforms/delete-columns.ts +0 -597
  83. package/src/__tests__/unit/transforms/delete-rows.ts +0 -620
  84. package/src/__tests__/unit/transforms/merging.ts +0 -392
  85. package/src/__tests__/unit/ui/ContextualMenu.tsx +0 -71
  86. package/src/__tests__/unit/ui/CornerControls.tsx +0 -99
  87. package/src/__tests__/unit/ui/DeleteButton.tsx +0 -38
  88. package/src/__tests__/unit/ui/FixedButton.tsx +0 -217
  89. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +0 -123
  90. package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +0 -68
  91. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +0 -178
  92. package/src/__tests__/unit/ui/FloatingDragMenu.tsx +0 -511
  93. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +0 -322
  94. package/src/__tests__/unit/ui/NumberColumn.tsx +0 -146
  95. package/src/__tests__/unit/ui/RowControls.tsx +0 -294
  96. package/src/__tests__/unit/ui/RowDragControls.tsx +0 -129
  97. package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +0 -189
  98. package/src/__tests__/unit/ui/TableFloatingControls.tsx +0 -118
  99. package/src/__tests__/unit/undo-redo.ts +0 -220
  100. package/src/__tests__/unit/utils/analytics.ts +0 -98
  101. package/src/__tests__/unit/utils/collapse.ts +0 -57
  102. package/src/__tests__/unit/utils/column-controls.ts +0 -205
  103. package/src/__tests__/unit/utils/dom.ts +0 -180
  104. package/src/__tests__/unit/utils/merged-cells.ts +0 -156
  105. package/src/__tests__/unit/utils/nodes.ts +0 -79
  106. package/src/__tests__/unit/utils/row-controls.ts +0 -195
  107. package/src/__tests__/unit/utils/table.ts +0 -96
  108. package/src/__tests__/unit/utils.ts +0 -670
  109. package/src/__tests__/visual-regression/__fixtures__/sticky-header-with-horizontal-scroll.json +0 -5228
  110. package/src/__tests__/visual-regression/__fixtures__/table-with-100-numbered-list-items.json +0 -20272
  111. 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
  112. 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
  113. 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
  114. 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
  115. 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
  116. 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
  117. 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
  118. 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
  119. 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
  120. 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
  121. package/src/__tests__/visual-regression/cell-options-menu.ts +0 -101
  122. package/src/__tests__/visual-regression/copy-button.ts +0 -181
  123. package/src/__tests__/visual-regression/index.ts +0 -62
  124. 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
- });