@atlaskit/editor-plugin-table 5.6.6 → 5.7.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 (68) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/types.js +1 -0
  3. package/dist/cjs/ui/FloatingContextualButton/index.js +1 -7
  4. package/dist/cjs/ui/FloatingContextualButton/styles.js +5 -25
  5. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +238 -99
  6. package/dist/cjs/ui/FloatingContextualMenu/styles.js +1 -2
  7. package/dist/cjs/ui/TableFloatingControls/NumberColumn/index.js +1 -1
  8. package/dist/cjs/ui/common-styles.js +7 -7
  9. package/dist/cjs/ui/consts.js +16 -63
  10. package/dist/cjs/ui/icons/MergeCellsIcon.js +34 -0
  11. package/dist/cjs/ui/icons/SplitCellIcon.js +41 -0
  12. package/dist/cjs/ui/icons/index.js +14 -0
  13. package/dist/cjs/ui/ui-styles.js +47 -48
  14. package/dist/es2019/types.js +1 -0
  15. package/dist/es2019/ui/FloatingContextualButton/index.js +1 -5
  16. package/dist/es2019/ui/FloatingContextualButton/styles.js +10 -31
  17. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +248 -71
  18. package/dist/es2019/ui/FloatingContextualMenu/styles.js +22 -3
  19. package/dist/es2019/ui/TableFloatingControls/NumberColumn/index.js +1 -1
  20. package/dist/es2019/ui/common-styles.js +59 -59
  21. package/dist/es2019/ui/consts.js +18 -64
  22. package/dist/es2019/ui/icons/MergeCellsIcon.js +25 -0
  23. package/dist/es2019/ui/icons/SplitCellIcon.js +32 -0
  24. package/dist/es2019/ui/icons/index.js +2 -0
  25. package/dist/es2019/ui/ui-styles.js +98 -99
  26. package/dist/esm/types.js +1 -0
  27. package/dist/esm/ui/FloatingContextualButton/index.js +1 -7
  28. package/dist/esm/ui/FloatingContextualButton/styles.js +5 -26
  29. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +238 -98
  30. package/dist/esm/ui/FloatingContextualMenu/styles.js +1 -2
  31. package/dist/esm/ui/TableFloatingControls/NumberColumn/index.js +1 -1
  32. package/dist/esm/ui/common-styles.js +7 -7
  33. package/dist/esm/ui/consts.js +18 -64
  34. package/dist/esm/ui/icons/MergeCellsIcon.js +27 -0
  35. package/dist/esm/ui/icons/SplitCellIcon.js +34 -0
  36. package/dist/esm/ui/icons/index.js +2 -0
  37. package/dist/esm/ui/ui-styles.js +47 -48
  38. package/dist/types/types.d.ts +1 -0
  39. package/dist/types/ui/FloatingContextualButton/styles.d.ts +2 -3
  40. package/dist/types/ui/FloatingContextualMenu/ContextualMenu.d.ts +12 -2
  41. package/dist/types/ui/common-styles.d.ts +1 -2
  42. package/dist/types/ui/consts.d.ts +15 -15
  43. package/dist/types/ui/icons/MergeCellsIcon.d.ts +2 -0
  44. package/dist/types/ui/icons/SplitCellIcon.d.ts +2 -0
  45. package/dist/types/ui/icons/index.d.ts +2 -0
  46. package/dist/types/ui/ui-styles.d.ts +17 -18
  47. package/dist/types-ts4.5/types.d.ts +1 -0
  48. package/dist/types-ts4.5/ui/FloatingContextualButton/styles.d.ts +2 -3
  49. package/dist/types-ts4.5/ui/FloatingContextualMenu/ContextualMenu.d.ts +12 -2
  50. package/dist/types-ts4.5/ui/common-styles.d.ts +1 -2
  51. package/dist/types-ts4.5/ui/consts.d.ts +15 -15
  52. package/dist/types-ts4.5/ui/icons/MergeCellsIcon.d.ts +2 -0
  53. package/dist/types-ts4.5/ui/icons/SplitCellIcon.d.ts +2 -0
  54. package/dist/types-ts4.5/ui/icons/index.d.ts +2 -0
  55. package/dist/types-ts4.5/ui/ui-styles.d.ts +17 -18
  56. package/package.json +12 -5
  57. package/src/types.ts +1 -0
  58. package/src/ui/FloatingContextualButton/index.tsx +3 -5
  59. package/src/ui/FloatingContextualButton/styles.ts +13 -35
  60. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +316 -68
  61. package/src/ui/FloatingContextualMenu/styles.ts +22 -3
  62. package/src/ui/TableFloatingControls/NumberColumn/index.tsx +1 -1
  63. package/src/ui/common-styles.ts +57 -69
  64. package/src/ui/consts.ts +52 -73
  65. package/src/ui/icons/MergeCellsIcon.tsx +32 -0
  66. package/src/ui/icons/SplitCellIcon.tsx +40 -0
  67. package/src/ui/icons/index.ts +2 -0
  68. package/src/ui/ui-styles.ts +94 -106
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.6.6",
3
+ "version": "5.7.0",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -24,12 +24,13 @@
24
24
  "atlassian": {
25
25
  "team": "Editor: Jenga",
26
26
  "singleton": true,
27
- "releaseModel": "continuous"
27
+ "releaseModel": "continuous",
28
+ "runReact18": false
28
29
  },
29
30
  "dependencies": {
30
31
  "@atlaskit/adf-schema": "^35.2.0",
31
32
  "@atlaskit/custom-steps": "^0.0.10",
32
- "@atlaskit/editor-common": "^76.27.0",
33
+ "@atlaskit/editor-common": "^76.29.0",
33
34
  "@atlaskit/editor-palette": "1.5.2",
34
35
  "@atlaskit/editor-plugin-analytics": "^0.4.0",
35
36
  "@atlaskit/editor-plugin-content-insertion": "^0.1.0",
@@ -46,8 +47,8 @@
46
47
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^0.12.0",
47
48
  "@atlaskit/primitives": "^1.15.0",
48
49
  "@atlaskit/theme": "^12.6.0",
49
- "@atlaskit/tokens": "^1.30.0",
50
- "@atlaskit/tooltip": "^18.0.0",
50
+ "@atlaskit/tokens": "^1.31.0",
51
+ "@atlaskit/tooltip": "^18.1.0",
51
52
  "@babel/runtime": "^7.0.0",
52
53
  "@emotion/react": "^11.7.1",
53
54
  "classnames": "^2.2.5",
@@ -141,6 +142,12 @@
141
142
  },
142
143
  "platform.editor.a11y.table-selection_9uv33": {
143
144
  "type": "boolean"
145
+ },
146
+ "platform.editor.table.new-cell-context-menu-styling": {
147
+ "type": "boolean"
148
+ },
149
+ "platform.editor.menu.group-items": {
150
+ "type": "boolean"
144
151
  }
145
152
  }
146
153
  }
package/src/types.ts CHANGED
@@ -368,6 +368,7 @@ export const TableCssClassName = {
368
368
  CONTEXTUAL_MENU_BUTTON: `${tablePrefixSelector}-contextual-menu-button`,
369
369
  CONTEXTUAL_MENU_BUTTON_FIXED: `${tablePrefixSelector}-contextual-menu-button-fixed`,
370
370
  CONTEXTUAL_MENU_ICON: `${tablePrefixSelector}-contextual-submenu-icon`,
371
+ CONTEXTUAL_MENU_ICON_SMALL: `${tablePrefixSelector}-contextual-submenu-icon-small`,
371
372
 
372
373
  // come from prosemirror-table
373
374
  SELECTED_CELL: 'selectedCell',
@@ -17,7 +17,6 @@ import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
17
17
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
18
18
  import { akEditorSmallZIndex } from '@atlaskit/editor-shared-styles';
19
19
  import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
20
- import type { ThemeProps } from '@atlaskit/theme/types';
21
20
 
22
21
  import { toggleContextualMenu } from '../../commands';
23
22
  import type { RowStickyState } from '../../pm-plugins/sticky-headers';
@@ -83,10 +82,9 @@ const FloatingContextualButtonInner = React.memo(
83
82
 
84
83
  const button = (
85
84
  <div
86
- css={(theme: ThemeProps) => [
87
- tableFloatingCellButtonStyles({ theme }),
88
- isContextualMenuOpen &&
89
- tableFloatingCellButtonSelectedStyles({ theme }),
85
+ css={[
86
+ tableFloatingCellButtonStyles(),
87
+ isContextualMenuOpen && tableFloatingCellButtonSelectedStyles(),
90
88
  ]}
91
89
  >
92
90
  <ToolbarButton
@@ -1,28 +1,21 @@
1
1
  import { css } from '@emotion/react';
2
2
 
3
- import { B75, DN0, DN60, N0, N20, N30A, N700 } from '@atlaskit/theme/colors';
4
- // eslint-disable-next-line @atlaskit/design-system/no-deprecated-imports
5
- import { themed } from '@atlaskit/theme/components';
6
- import { borderRadius } from '@atlaskit/theme/constants';
7
- import type { ThemeProps } from '@atlaskit/theme/types';
3
+ import { N0, N20, N30A, N700 } from '@atlaskit/theme/colors';
8
4
  import { token } from '@atlaskit/tokens';
9
5
 
10
6
  import { contextualMenuTriggerSize } from '../consts';
11
7
 
12
- export const tableFloatingCellButtonStyles = (props: ThemeProps) => css`
8
+ export const tableFloatingCellButtonStyles = () => css`
13
9
  > div {
14
10
  // Sits behind button to provide surface-color background
15
11
  background: ${token('elevation.surface', N20)};
16
- border-radius: ${borderRadius()}px;
12
+ border-radius: ${token('border.radius', '3px')};
17
13
  display: flex;
18
14
  height: ${contextualMenuTriggerSize + 2}px;
19
15
  flex-direction: column;
20
16
  }
21
17
  && button {
22
- background: ${themed({
23
- light: token('color.background.neutral', 'none'),
24
- dark: token('color.background.neutral', 'none'),
25
- })(props)};
18
+ background: ${token('color.background.neutral', 'none')};
26
19
  flex-direction: column;
27
20
  margin: ${token('space.025', '2px')};
28
21
  outline: 2px solid ${token('elevation.surface', N0)};
@@ -32,19 +25,13 @@ export const tableFloatingCellButtonStyles = (props: ThemeProps) => css`
32
25
  display: flex;
33
26
  }
34
27
  && button:hover {
35
- background: ${themed({
36
- light: token('color.background.neutral.hovered', N30A),
37
- dark: token('color.background.neutral.hovered', DN60),
38
- })(props)};
28
+ background: ${token('color.background.neutral.hovered', N30A)};
39
29
  }
40
30
  && button:active {
41
- background: ${themed({
42
- light: token(
43
- 'color.background.neutral.pressed',
44
- 'rgba(179, 212, 255, 0.6)',
45
- ),
46
- dark: token('color.background.neutral.pressed', B75),
47
- })(props)};
31
+ background: ${token(
32
+ 'color.background.neutral.pressed',
33
+ 'rgba(179, 212, 255, 0.6)',
34
+ )};
48
35
  }
49
36
  && button > span {
50
37
  margin: 0px ${token('space.negative.050', '-4px')};
@@ -54,23 +41,14 @@ export const tableFloatingCellButtonStyles = (props: ThemeProps) => css`
54
41
  }
55
42
  `;
56
43
 
57
- export const tableFloatingCellButtonSelectedStyles = (props: ThemeProps) => css`
44
+ export const tableFloatingCellButtonSelectedStyles = () => css`
58
45
  && button {
59
- background: ${themed({
60
- light: token('color.background.selected', N700),
61
- dark: token('color.background.selected', DN0),
62
- })(props)};
46
+ background: ${token('color.background.selected', N700)};
63
47
  }
64
48
  && button:hover {
65
- background: ${themed({
66
- light: token('color.background.selected.hovered', N700),
67
- dark: token('color.background.selected.hovered', DN0),
68
- })(props)};
49
+ background: ${token('color.background.selected.hovered', N700)};
69
50
  }
70
51
  && button:active {
71
- background: ${themed({
72
- light: token('color.background.selected.pressed', N700),
73
- dark: token('color.background.selected.pressed', DN0),
74
- })(props)};
52
+ background: ${token('color.background.selected.pressed', N700)};
75
53
  }
76
54
  `;
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @atlaskit/design-system/prefer-primitives */
1
2
  /** @jsx jsx */
2
3
  import { Component } from 'react';
3
4
 
@@ -39,6 +40,10 @@ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
39
40
  import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
40
41
  import type { Rect } from '@atlaskit/editor-tables/table-map';
41
42
  import { splitCell } from '@atlaskit/editor-tables/utils';
43
+ import CrossCircleIcon from '@atlaskit/icon/glyph/cross-circle';
44
+ import EditorBackgroundColorIcon from '@atlaskit/icon/glyph/editor/background-color';
45
+ import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
46
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
42
47
 
43
48
  import {
44
49
  clearHoverSelection,
@@ -69,6 +74,12 @@ import {
69
74
  getSelectedRowIndexes,
70
75
  } from '../../utils';
71
76
  import { contextualMenuDropdownWidth } from '../consts';
77
+ import {
78
+ AddColRightIcon,
79
+ AddRowBelowIcon,
80
+ MergeCellsIcon,
81
+ SplitCellIcon,
82
+ } from '../icons';
72
83
 
73
84
  import { cellColourPreviewStyles } from './styles';
74
85
 
@@ -105,11 +116,14 @@ export class ContextualMenu extends Component<
105
116
  };
106
117
 
107
118
  render() {
108
- const { isOpen, mountPoint, offset, boundariesElement } = this.props;
109
- const items = this.createItems();
110
- if (!items) {
111
- return null;
112
- }
119
+ const { isOpen, mountPoint, offset, boundariesElement, editorView } =
120
+ this.props;
121
+ const { isDragAndDropEnabled } = getPluginState(editorView.state);
122
+ const items =
123
+ isDragAndDropEnabled &&
124
+ getBooleanFF('platform.editor.table.new-cell-context-menu-styling')
125
+ ? this.createNewContextMenuItems()
126
+ : this.createOriginalContextMenuItems();
113
127
 
114
128
  return (
115
129
  <div
@@ -134,6 +148,15 @@ export class ContextualMenu extends Component<
134
148
  fitWidth={contextualMenuDropdownWidth}
135
149
  boundariesElement={boundariesElement}
136
150
  offset={offset}
151
+ section={
152
+ isDragAndDropEnabled &&
153
+ getBooleanFF(
154
+ 'platform.editor.table.new-cell-context-menu-styling',
155
+ ) &&
156
+ getBooleanFF('platform.editor.menu.group-items')
157
+ ? { hasSeparator: true }
158
+ : undefined
159
+ }
137
160
  />
138
161
  </div>
139
162
  );
@@ -154,24 +177,19 @@ export class ContextualMenu extends Component<
154
177
  }
155
178
  };
156
179
 
157
- private createItems = () => {
180
+ private createBackgroundColorItem = () => {
158
181
  const {
159
- allowMergeCells,
160
- allowColumnSorting,
161
182
  allowBackgroundColor,
162
183
  editorView: { state },
163
184
  isOpen,
164
- selectionRect,
165
185
  intl: { formatMessage },
166
186
  editorView,
167
187
  } = this.props;
168
- const items: any[] = [];
169
188
  const { isSubmenuOpen } = this.state;
170
- // TargetCellPosition could be outdated: https://product-fabric.atlassian.net/browse/ED-8129
171
- const {
172
- targetCellPosition,
173
- pluginConfig: { allowDistributeColumns },
174
- } = getPluginState(editorView.state);
189
+ const { targetCellPosition, isDragAndDropEnabled } = getPluginState(
190
+ editorView.state,
191
+ );
192
+
175
193
  if (allowBackgroundColor) {
176
194
  const node =
177
195
  isOpen && targetCellPosition
@@ -180,14 +198,35 @@ export class ContextualMenu extends Component<
180
198
  const background = hexToEditorBackgroundPaletteColor(
181
199
  node?.attrs?.background || '#ffffff',
182
200
  );
183
- items.push({
184
- content: formatMessage(messages.cellBackground),
201
+ return {
202
+ content:
203
+ isDragAndDropEnabled &&
204
+ getBooleanFF('platform.editor.table.new-cell-context-menu-styling')
205
+ ? formatMessage(messages.backgroundColor)
206
+ : formatMessage(messages.cellBackground),
185
207
  value: { name: 'background' },
208
+ elemBefore:
209
+ isDragAndDropEnabled &&
210
+ getBooleanFF(
211
+ 'platform.editor.table.new-cell-context-menu-styling',
212
+ ) ? (
213
+ <EditorBackgroundColorIcon
214
+ label={formatMessage(messages.backgroundColor)}
215
+ size="medium"
216
+ />
217
+ ) : undefined,
186
218
  elemAfter: (
187
219
  <div className={DropdownMenuSharedCssClassName.SUBMENU}>
188
220
  <div
189
221
  css={cellColourPreviewStyles(background)}
190
- className={ClassName.CONTEXTUAL_MENU_ICON}
222
+ className={
223
+ isDragAndDropEnabled &&
224
+ getBooleanFF(
225
+ 'platform.editor.table.new-cell-context-menu-styling',
226
+ )
227
+ ? ClassName.CONTEXTUAL_MENU_ICON_SMALL
228
+ : ClassName.CONTEXTUAL_MENU_ICON
229
+ }
191
230
  />
192
231
  {isSubmenuOpen && (
193
232
  <div
@@ -209,72 +248,232 @@ export class ContextualMenu extends Component<
209
248
  )}
210
249
  </div>
211
250
  ),
212
- });
251
+ } as MenuItem;
213
252
  }
253
+ };
254
+
255
+ private createMergeSplitCellItems = () => {
256
+ const {
257
+ allowMergeCells,
258
+ editorView: { state },
259
+ intl: { formatMessage },
260
+ editorView,
261
+ } = this.props;
262
+ const { isDragAndDropEnabled } = getPluginState(editorView.state);
214
263
 
215
- items.push({
216
- content: formatMessage(messages.insertColumn),
264
+ if (allowMergeCells) {
265
+ return [
266
+ {
267
+ content: formatMessage(messages.mergeCells),
268
+ value: { name: 'merge' },
269
+ isDisabled: !canMergeCells(state.tr),
270
+ elemBefore:
271
+ isDragAndDropEnabled &&
272
+ getBooleanFF(
273
+ 'platform.editor.table.new-cell-context-menu-styling',
274
+ ) ? (
275
+ <MergeCellsIcon />
276
+ ) : undefined,
277
+ },
278
+ {
279
+ content: formatMessage(messages.splitCell),
280
+ value: { name: 'split' },
281
+ isDisabled: !splitCell(state),
282
+ elemBefore:
283
+ isDragAndDropEnabled &&
284
+ getBooleanFF(
285
+ 'platform.editor.table.new-cell-context-menu-styling',
286
+ ) ? (
287
+ <SplitCellIcon />
288
+ ) : undefined,
289
+ },
290
+ ] as MenuItem[];
291
+ }
292
+ return [];
293
+ };
294
+
295
+ private createInsertColumnItem = () => {
296
+ const {
297
+ intl: { formatMessage },
298
+ editorView,
299
+ } = this.props;
300
+ const { isDragAndDropEnabled } = getPluginState(editorView.state);
301
+
302
+ return {
303
+ content: formatMessage(
304
+ isDragAndDropEnabled &&
305
+ getBooleanFF('platform.editor.table.new-cell-context-menu-styling')
306
+ ? messages.addColumn
307
+ : messages.insertColumn,
308
+ ),
217
309
  value: { name: 'insert_column' },
218
310
  elemAfter: <div css={shortcutStyle}>{tooltip(addColumnAfter)}</div>,
219
- });
311
+ elemBefore:
312
+ isDragAndDropEnabled &&
313
+ getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? (
314
+ <AddColRightIcon />
315
+ ) : undefined,
316
+ } as MenuItem;
317
+ };
220
318
 
221
- items.push({
222
- content: formatMessage(messages.insertRow),
319
+ private createInsertRowItem = () => {
320
+ const {
321
+ intl: { formatMessage },
322
+ editorView,
323
+ } = this.props;
324
+ const { isDragAndDropEnabled } = getPluginState(editorView.state);
325
+
326
+ return {
327
+ content: formatMessage(
328
+ isDragAndDropEnabled &&
329
+ getBooleanFF('platform.editor.table.new-cell-context-menu-styling')
330
+ ? messages.addRow
331
+ : messages.insertRow,
332
+ ),
223
333
  value: { name: 'insert_row' },
224
334
  elemAfter: <div css={shortcutStyle}>{tooltip(addRowAfter)}</div>,
225
- });
335
+ elemBefore:
336
+ isDragAndDropEnabled &&
337
+ getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? (
338
+ <AddRowBelowIcon />
339
+ ) : undefined,
340
+ } as MenuItem;
341
+ };
226
342
 
343
+ private createClearCellsItem = () => {
344
+ const {
345
+ selectionRect,
346
+ intl: { formatMessage },
347
+ editorView,
348
+ } = this.props;
349
+ const { isDragAndDropEnabled } = getPluginState(editorView.state);
227
350
  const { top, bottom, right, left } = selectionRect;
228
351
  const noOfColumns = right - left;
229
352
  const noOfRows = bottom - top;
230
353
 
231
- items.push({
354
+ return {
355
+ content: formatMessage(messages.clearCells, {
356
+ 0: Math.max(noOfColumns, noOfRows),
357
+ }),
358
+ value: { name: 'clear' },
359
+ elemAfter: <div css={shortcutStyle}>{tooltip(backspace)}</div>,
360
+ elemBefore:
361
+ isDragAndDropEnabled &&
362
+ getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? (
363
+ <CrossCircleIcon
364
+ label={formatMessage(messages.clearCells, {
365
+ 0: Math.max(noOfColumns, noOfRows),
366
+ })}
367
+ />
368
+ ) : undefined,
369
+ } as MenuItem;
370
+ };
371
+
372
+ private createDeleteColumnItem = () => {
373
+ const {
374
+ selectionRect,
375
+ intl: { formatMessage },
376
+ editorView,
377
+ } = this.props;
378
+ const { isDragAndDropEnabled } = getPluginState(editorView.state);
379
+
380
+ const { right, left } = selectionRect;
381
+ const noOfColumns = right - left;
382
+
383
+ return {
232
384
  content: formatMessage(messages.removeColumns, {
233
385
  0: noOfColumns,
234
386
  }),
235
387
  value: { name: 'delete_column' },
236
- });
388
+ elemBefore:
389
+ isDragAndDropEnabled &&
390
+ getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? (
391
+ <RemoveIcon
392
+ label={formatMessage(messages.removeColumns, {
393
+ 0: noOfColumns,
394
+ })}
395
+ />
396
+ ) : undefined,
397
+ } as MenuItem;
398
+ };
399
+
400
+ private createDeleteRowItem = () => {
401
+ const {
402
+ selectionRect,
403
+ intl: { formatMessage },
404
+ editorView,
405
+ } = this.props;
406
+ const { isDragAndDropEnabled } = getPluginState(editorView.state);
237
407
 
238
- items.push({
408
+ const { bottom, top } = selectionRect;
409
+ const noOfRows = bottom - top;
410
+
411
+ return {
239
412
  content: formatMessage(messages.removeRows, {
240
413
  0: noOfRows,
241
414
  }),
242
415
  value: { name: 'delete_row' },
243
- });
244
-
245
- if (allowMergeCells) {
246
- items.push({
247
- content: formatMessage(messages.mergeCells),
248
- value: { name: 'merge' },
249
- isDisabled: !canMergeCells(state.tr),
250
- });
251
- items.push({
252
- content: formatMessage(messages.splitCell),
253
- value: { name: 'split' },
254
- isDisabled: !splitCell(state),
255
- });
256
- }
416
+ elemBefore:
417
+ isDragAndDropEnabled &&
418
+ getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? (
419
+ <RemoveIcon
420
+ label={formatMessage(messages.removeRows, {
421
+ 0: noOfRows,
422
+ })}
423
+ />
424
+ ) : undefined,
425
+ } as MenuItem;
426
+ };
257
427
 
258
- if (allowDistributeColumns) {
428
+ private createDistributeColumnsItem = () => {
429
+ const {
430
+ selectionRect,
431
+ intl: { formatMessage },
432
+ editorView,
433
+ getEditorContainerWidth,
434
+ } = this.props;
435
+ const {
436
+ isDragAndDropEnabled,
437
+ pluginConfig: { allowDistributeColumns },
438
+ } = getPluginState(editorView.state);
439
+ if (
440
+ allowDistributeColumns &&
441
+ (!isDragAndDropEnabled ||
442
+ !getBooleanFF('platform.editor.table.new-cell-context-menu-styling'))
443
+ ) {
259
444
  const newResizeState = getNewResizeStateFromSelectedColumns(
260
445
  selectionRect,
261
- state,
446
+ editorView.state,
262
447
  editorView.domAtPos.bind(editorView),
263
- this.props.getEditorContainerWidth,
448
+ getEditorContainerWidth,
264
449
  );
265
450
 
266
451
  const wouldChange = newResizeState?.changed ?? false;
267
452
 
268
- items.push({
453
+ return {
269
454
  content: formatMessage(messages.distributeColumns),
270
455
  value: { name: 'distribute_columns' },
271
456
  isDisabled: !wouldChange,
272
- });
457
+ } as MenuItem;
273
458
  }
459
+ return null;
460
+ };
274
461
 
275
- if (allowColumnSorting) {
462
+ private createSortColumnItems = () => {
463
+ const {
464
+ intl: { formatMessage },
465
+ editorView,
466
+ allowColumnSorting,
467
+ } = this.props;
468
+ const { isDragAndDropEnabled } = getPluginState(editorView.state);
469
+
470
+ if (
471
+ allowColumnSorting &&
472
+ (!isDragAndDropEnabled ||
473
+ !getBooleanFF('platform.editor.table.new-cell-context-menu-styling'))
474
+ ) {
276
475
  const hasMergedCellsInTable =
277
- getMergedCellsPositions(state.tr).length > 0;
476
+ getMergedCellsPositions(editorView.state.tr).length > 0;
278
477
  const warning = hasMergedCellsInTable
279
478
  ? {
280
479
  tooltipDescription: formatMessage(messages.canNotSortTable),
@@ -282,28 +481,77 @@ export class ContextualMenu extends Component<
282
481
  }
283
482
  : {};
284
483
 
285
- items.push({
286
- content: formatMessage(messages.sortColumnASC),
287
- value: { name: 'sort_column_asc' },
288
- ...warning,
289
- });
290
-
291
- items.push({
292
- content: formatMessage(messages.sortColumnDESC),
293
- value: { name: 'sort_column_desc' },
294
- ...warning,
295
- });
484
+ return [
485
+ {
486
+ content: formatMessage(messages.sortColumnASC),
487
+ value: { name: 'sort_column_asc' },
488
+ ...warning,
489
+ },
490
+ {
491
+ content: formatMessage(messages.sortColumnDESC),
492
+ value: { name: 'sort_column_desc' },
493
+ ...warning,
494
+ },
495
+ ] as MenuItem[];
296
496
  }
297
497
 
298
- items.push({
299
- content: formatMessage(messages.clearCells, {
300
- 0: Math.max(noOfColumns, noOfRows),
301
- }),
302
- value: { name: 'clear' },
303
- elemAfter: <div css={shortcutStyle}>{tooltip(backspace)}</div>,
304
- });
498
+ return null;
499
+ };
500
+
501
+ private createOriginalContextMenuItems = () => {
502
+ let items: MenuItem[] = [];
503
+ const backgroundColorItem = this.createBackgroundColorItem();
504
+ backgroundColorItem && items.push(backgroundColorItem);
505
+
506
+ items.push(this.createInsertColumnItem());
507
+
508
+ items.push(this.createInsertRowItem());
509
+
510
+ items.push(this.createDeleteColumnItem());
511
+
512
+ items.push(this.createDeleteRowItem());
513
+
514
+ items.push(...this.createMergeSplitCellItems());
515
+
516
+ const distributeColumnsItem = this.createDistributeColumnsItem();
517
+ distributeColumnsItem && items.push(distributeColumnsItem);
518
+
519
+ const sortColumnItems = this.createSortColumnItems();
520
+ sortColumnItems && items.push(...sortColumnItems);
521
+
522
+ items.push(this.createClearCellsItem());
523
+
524
+ return [{ items }];
525
+ };
305
526
 
306
- return items.length ? [{ items }] : null;
527
+ private createNewContextMenuItems = () => {
528
+ const backgroundColorItem = this.createBackgroundColorItem();
529
+ const mergeSplitCellItems = this.createMergeSplitCellItems();
530
+ const insertColumnItem = this.createInsertColumnItem();
531
+ const insertRowItem = this.createInsertRowItem();
532
+ const clearCellsItem = this.createClearCellsItem();
533
+ const deleteColumnItem = this.createDeleteColumnItem();
534
+ const deleteRowItem = this.createDeleteRowItem();
535
+
536
+ // Group items so when table.menu.group-items FF is enabled, a divider shows under split cell, above add column
537
+ let items: { items: MenuItem[] }[] = [
538
+ {
539
+ items: [],
540
+ },
541
+ {
542
+ items: [],
543
+ },
544
+ ];
545
+
546
+ backgroundColorItem && items[0].items.push(backgroundColorItem);
547
+ items[0].items.push(...mergeSplitCellItems);
548
+ items[1].items.push(insertColumnItem);
549
+ items[1].items.push(insertRowItem);
550
+ items[1].items.push(clearCellsItem);
551
+ items[1].items.push(deleteColumnItem);
552
+ items[1].items.push(deleteRowItem);
553
+
554
+ return items;
307
555
  };
308
556
 
309
557
  private onMenuItemActivated = ({ item }: { item: DropdownItem }) => {