@atlaskit/editor-plugin-table 7.6.2 → 7.6.4

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 (119) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/commands/misc.js +3 -2
  3. package/dist/cjs/nodeviews/TableComponent.js +25 -11
  4. package/dist/cjs/nodeviews/TableComponentWithSharedState.js +87 -0
  5. package/dist/cjs/nodeviews/TableContainer.js +37 -21
  6. package/dist/cjs/nodeviews/TableResizer.js +40 -29
  7. package/dist/cjs/nodeviews/table.js +21 -1
  8. package/dist/cjs/plugin.js +25 -2
  9. package/dist/cjs/toolbar.js +5 -4
  10. package/dist/cjs/types.js +3 -0
  11. package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +16 -16
  12. package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +3 -3
  13. package/dist/cjs/ui/FloatingDragMenu/DropdownMenu.js +21 -28
  14. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +6 -2
  15. package/dist/cjs/ui/TableFloatingColumnControls/index.js +5 -2
  16. package/dist/cjs/ui/TableFloatingControls/CornerControls/DragCornerControls.js +48 -1
  17. package/dist/cjs/ui/TableFloatingControls/CornerControls/index.js +6 -0
  18. package/dist/cjs/ui/TableFloatingControls/FloatingControlsWithSelection.js +47 -0
  19. package/dist/cjs/ui/TableFloatingControls/RowControls/ClassicControls.js +3 -2
  20. package/dist/cjs/ui/TableFloatingControls/index.js +25 -3
  21. package/dist/cjs/ui/common-styles.js +11 -6
  22. package/dist/cjs/utils/guidelines.js +1 -1
  23. package/dist/es2019/commands/misc.js +6 -2
  24. package/dist/es2019/nodeviews/TableComponent.js +27 -12
  25. package/dist/es2019/nodeviews/TableComponentWithSharedState.js +83 -0
  26. package/dist/es2019/nodeviews/TableContainer.js +24 -6
  27. package/dist/es2019/nodeviews/TableResizer.js +27 -19
  28. package/dist/es2019/nodeviews/table.js +21 -1
  29. package/dist/es2019/plugin.js +26 -3
  30. package/dist/es2019/toolbar.js +5 -4
  31. package/dist/es2019/types.js +3 -0
  32. package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +16 -16
  33. package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +3 -3
  34. package/dist/es2019/ui/FloatingDragMenu/DropdownMenu.js +20 -27
  35. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -2
  36. package/dist/es2019/ui/TableFloatingColumnControls/index.js +5 -2
  37. package/dist/es2019/ui/TableFloatingControls/CornerControls/DragCornerControls.js +55 -0
  38. package/dist/es2019/ui/TableFloatingControls/CornerControls/index.js +1 -1
  39. package/dist/es2019/ui/TableFloatingControls/FloatingControlsWithSelection.js +42 -0
  40. package/dist/es2019/ui/TableFloatingControls/RowControls/ClassicControls.js +3 -2
  41. package/dist/es2019/ui/TableFloatingControls/index.js +26 -4
  42. package/dist/es2019/ui/common-styles.js +589 -588
  43. package/dist/es2019/utils/guidelines.js +1 -1
  44. package/dist/esm/commands/misc.js +3 -2
  45. package/dist/esm/nodeviews/TableComponent.js +25 -11
  46. package/dist/esm/nodeviews/TableComponentWithSharedState.js +80 -0
  47. package/dist/esm/nodeviews/TableContainer.js +37 -21
  48. package/dist/esm/nodeviews/TableResizer.js +41 -30
  49. package/dist/esm/nodeviews/table.js +21 -1
  50. package/dist/esm/plugin.js +26 -3
  51. package/dist/esm/toolbar.js +5 -4
  52. package/dist/esm/types.js +3 -0
  53. package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +16 -16
  54. package/dist/esm/ui/FloatingDragMenu/DragMenu.js +3 -3
  55. package/dist/esm/ui/FloatingDragMenu/DropdownMenu.js +21 -28
  56. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +6 -2
  57. package/dist/esm/ui/TableFloatingColumnControls/index.js +5 -2
  58. package/dist/esm/ui/TableFloatingControls/CornerControls/DragCornerControls.js +47 -0
  59. package/dist/esm/ui/TableFloatingControls/CornerControls/index.js +1 -1
  60. package/dist/esm/ui/TableFloatingControls/FloatingControlsWithSelection.js +40 -0
  61. package/dist/esm/ui/TableFloatingControls/RowControls/ClassicControls.js +3 -2
  62. package/dist/esm/ui/TableFloatingControls/index.js +26 -4
  63. package/dist/esm/ui/common-styles.js +10 -5
  64. package/dist/esm/utils/guidelines.js +1 -1
  65. package/dist/types/commands/misc.d.ts +2 -1
  66. package/dist/types/nodeviews/TableComponent.d.ts +7 -2
  67. package/dist/types/nodeviews/TableComponentWithSharedState.d.ts +27 -0
  68. package/dist/types/nodeviews/TableContainer.d.ts +4 -2
  69. package/dist/types/nodeviews/TableResizer.d.ts +4 -1
  70. package/dist/types/nodeviews/types.d.ts +1 -0
  71. package/dist/types/plugin.d.ts +11 -7
  72. package/dist/types/types.d.ts +13 -4
  73. package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +113 -1
  74. package/dist/types/ui/TableFloatingColumnControls/index.d.ts +3 -2
  75. package/dist/types/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +223 -0
  76. package/dist/types/ui/TableFloatingControls/CornerControls/index.d.ts +1 -1
  77. package/dist/types/ui/TableFloatingControls/FloatingControlsWithSelection.d.ts +20 -0
  78. package/dist/types/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +2 -0
  79. package/dist/types/ui/TableFloatingControls/index.d.ts +113 -1
  80. package/dist/types/ui/common-styles.d.ts +3 -0
  81. package/dist/types-ts4.5/commands/misc.d.ts +2 -1
  82. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +7 -2
  83. package/dist/types-ts4.5/nodeviews/TableComponentWithSharedState.d.ts +27 -0
  84. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -2
  85. package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +4 -1
  86. package/dist/types-ts4.5/nodeviews/types.d.ts +1 -0
  87. package/dist/types-ts4.5/plugin.d.ts +11 -7
  88. package/dist/types-ts4.5/types.d.ts +13 -4
  89. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +144 -1
  90. package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +3 -2
  91. package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +285 -0
  92. package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/index.d.ts +1 -1
  93. package/dist/types-ts4.5/ui/TableFloatingControls/FloatingControlsWithSelection.d.ts +20 -0
  94. package/dist/types-ts4.5/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +2 -0
  95. package/dist/types-ts4.5/ui/TableFloatingControls/index.d.ts +144 -1
  96. package/dist/types-ts4.5/ui/common-styles.d.ts +3 -0
  97. package/package.json +6 -6
  98. package/src/commands/misc.ts +6 -3
  99. package/src/nodeviews/TableComponent.tsx +36 -7
  100. package/src/nodeviews/TableComponentWithSharedState.tsx +125 -0
  101. package/src/nodeviews/TableContainer.tsx +24 -3
  102. package/src/nodeviews/TableResizer.tsx +36 -21
  103. package/src/nodeviews/table.tsx +22 -1
  104. package/src/nodeviews/types.ts +1 -0
  105. package/src/plugin.tsx +47 -6
  106. package/src/toolbar.tsx +20 -19
  107. package/src/types.ts +33 -4
  108. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +66 -112
  109. package/src/ui/FloatingDragMenu/DragMenu.tsx +3 -12
  110. package/src/ui/FloatingDragMenu/DropdownMenu.tsx +19 -28
  111. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +10 -2
  112. package/src/ui/TableFloatingColumnControls/index.tsx +13 -1
  113. package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +58 -0
  114. package/src/ui/TableFloatingControls/CornerControls/index.tsx +4 -1
  115. package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +68 -0
  116. package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +4 -1
  117. package/src/ui/TableFloatingControls/index.tsx +42 -8
  118. package/src/ui/common-styles.ts +611 -610
  119. package/src/utils/guidelines.ts +5 -4
package/src/toolbar.tsx CHANGED
@@ -51,7 +51,6 @@ import {
51
51
  import DistributeColumnIcon from '@atlaskit/icon/glyph/editor/layout-three-equal';
52
52
  import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
53
53
  import TableOptionsIcon from '@atlaskit/icon/glyph/preferences';
54
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
55
54
 
56
55
  import {
57
56
  clearHoverSelection,
@@ -135,10 +134,7 @@ export const getToolbarMenuConfig = (
135
134
  },
136
135
  ];
137
136
 
138
- if (
139
- state.isDragAndDropEnabled &&
140
- getBooleanFF('platform.editor.table.new-cell-context-menu-styling')
141
- ) {
137
+ if (state.isDragAndDropEnabled) {
142
138
  return {
143
139
  id: 'editor.table.tableOptions',
144
140
  type: 'dropdown',
@@ -454,8 +450,15 @@ export const getToolbarConfig =
454
450
  const isWidthResizing = tableWidthState?.resizing;
455
451
 
456
452
  const { isTableScalingEnabled, widthToWidest } = pluginState;
457
-
458
- if (isTableScalingEnabled && isWidthResizing && widthToWidest) {
453
+ const currentTableNodeLocalId = tableObject?.node?.attrs?.localId ?? '';
454
+
455
+ if (
456
+ isTableScalingEnabled &&
457
+ isWidthResizing &&
458
+ widthToWidest &&
459
+ currentTableNodeLocalId &&
460
+ widthToWidest[currentTableNodeLocalId]
461
+ ) {
459
462
  const { stickyScrollbar } = getEditorFeatureFlags();
460
463
 
461
464
  const nodeType = state.schema.nodes.table;
@@ -526,18 +529,16 @@ export const getToolbarConfig =
526
529
  );
527
530
 
528
531
  let columnSettingsItems;
529
- columnSettingsItems =
530
- pluginState.isDragAndDropEnabled &&
531
- getBooleanFF('platform.editor.table.new-cell-context-menu-styling')
532
- ? getColumnSettingItems(
533
- state,
534
- getEditorView(),
535
- intl,
536
- getEditorContainerWidth,
537
- editorAnalyticsAPI,
538
- isTableScalingEnabled,
539
- )
540
- : [];
532
+ columnSettingsItems = pluginState.isDragAndDropEnabled
533
+ ? getColumnSettingItems(
534
+ state,
535
+ getEditorView(),
536
+ intl,
537
+ getEditorContainerWidth,
538
+ editorAnalyticsAPI,
539
+ isTableScalingEnabled,
540
+ )
541
+ : [];
541
542
  const colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
542
543
 
543
544
  // Check if we need to show confirm dialog for delete button
package/src/types.ts CHANGED
@@ -16,7 +16,7 @@ import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
16
16
  import type { Rect } from '@atlaskit/editor-tables/table-map';
17
17
  import type { Edge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
18
18
 
19
- import type tablePlugin from './plugin';
19
+ import type { TablePlugin } from './plugin';
20
20
 
21
21
  export const RESIZE_HANDLE_AREA_DECORATION_GAP = 30;
22
22
  export type RowInsertPosition = 'TOP' | 'BOTTOM';
@@ -33,7 +33,33 @@ export interface InsertRowOptions {
33
33
  moveCursorToInsertedRow: boolean;
34
34
  }
35
35
 
36
- export type PluginInjectionAPI = ExtractInjectionAPI<typeof tablePlugin>;
36
+ export type PluginInjectionAPI = ExtractInjectionAPI<TablePlugin>;
37
+
38
+ // override getPluginState but do not expose publicly as this type is experimental and will change
39
+ // in the future
40
+ export type TableSharedStateInternal = Pick<
41
+ TablePluginState,
42
+ | 'isFullWidthModeEnabled'
43
+ | 'wasFullWidthModeEnabled'
44
+ | 'isHeaderRowEnabled'
45
+ | 'isHeaderColumnEnabled'
46
+ | 'ordering'
47
+ | 'isInDanger'
48
+ | 'hoveredRows'
49
+ | 'hoveredCell'
50
+ | 'isTableHovered'
51
+ | 'tableNode'
52
+ | 'widthToWidest'
53
+ > & {
54
+ isResizing: boolean;
55
+ isTableResizing?: boolean;
56
+ isWholeTableInDanger?: boolean;
57
+ };
58
+
59
+ export type TableSharedState = Pick<
60
+ TablePluginState,
61
+ 'isFullWidthModeEnabled' | 'wasFullWidthModeEnabled'
62
+ >;
37
63
 
38
64
  export type InsertRowMethods =
39
65
  | INPUT_METHOD.CONTEXT_MENU
@@ -96,6 +122,9 @@ export interface CellHoverMeta {
96
122
  colIndex?: number;
97
123
  rowIndex?: number;
98
124
  }
125
+ export interface WidthToWidest {
126
+ [tableLocalId: string]: boolean;
127
+ }
99
128
 
100
129
  export interface TablePluginState {
101
130
  editorHasFocus?: boolean;
@@ -130,7 +159,7 @@ export interface TablePluginState {
130
159
  // for table wrap/collapse
131
160
  isTableCollapsed?: boolean; // is the current table already in an expand?
132
161
  canCollapseTable?: boolean; // enabled/disabled state of collapse option
133
- widthToWidest?: boolean; // is the current table set to the widest width regarding view port
162
+ widthToWidest?: WidthToWidest; // is the current table set to the widest width regarding view port
134
163
 
135
164
  getIntl: () => IntlShape;
136
165
 
@@ -221,7 +250,7 @@ export type TablePluginAction =
221
250
  | {
222
251
  type: 'UPDATE_TABLE_WIDTH_TO_WIDEST';
223
252
  data: {
224
- widthToWidest: boolean | undefined;
253
+ widthToWidest: WidthToWidest | undefined;
225
254
  };
226
255
  }
227
256
  | {
@@ -126,11 +126,9 @@ export class ContextualMenu extends Component<
126
126
  const { isOpen, mountPoint, offset, boundariesElement, editorView } =
127
127
  this.props;
128
128
  const { isDragAndDropEnabled } = getPluginState(editorView.state);
129
- const items =
130
- isDragAndDropEnabled &&
131
- getBooleanFF('platform.editor.table.new-cell-context-menu-styling')
132
- ? this.createNewContextMenuItems()
133
- : this.createOriginalContextMenuItems();
129
+ const items = isDragAndDropEnabled
130
+ ? this.createNewContextMenuItems()
131
+ : this.createOriginalContextMenuItems();
134
132
 
135
133
  return (
136
134
  <div
@@ -161,9 +159,6 @@ export class ContextualMenu extends Component<
161
159
  offset={offset}
162
160
  section={
163
161
  isDragAndDropEnabled &&
164
- getBooleanFF(
165
- 'platform.editor.table.new-cell-context-menu-styling',
166
- ) &&
167
162
  getBooleanFF('platform.editor.menu.group-items')
168
163
  ? { hasSeparator: true }
169
164
  : undefined
@@ -210,33 +205,24 @@ export class ContextualMenu extends Component<
210
205
  node?.attrs?.background || '#ffffff',
211
206
  );
212
207
  return {
213
- content:
214
- isDragAndDropEnabled &&
215
- getBooleanFF('platform.editor.table.new-cell-context-menu-styling')
216
- ? formatMessage(messages.backgroundColor)
217
- : formatMessage(messages.cellBackground),
208
+ content: isDragAndDropEnabled
209
+ ? formatMessage(messages.backgroundColor)
210
+ : formatMessage(messages.cellBackground),
218
211
  value: { name: 'background' },
219
- elemBefore:
220
- isDragAndDropEnabled &&
221
- getBooleanFF(
222
- 'platform.editor.table.new-cell-context-menu-styling',
223
- ) ? (
224
- <span css={elementBeforeIconStyles}>
225
- <EditorBackgroundColorIcon
226
- label={formatMessage(messages.backgroundColor)}
227
- size="medium"
228
- />
229
- </span>
230
- ) : undefined,
212
+ elemBefore: isDragAndDropEnabled ? (
213
+ <span css={elementBeforeIconStyles}>
214
+ <EditorBackgroundColorIcon
215
+ label={formatMessage(messages.backgroundColor)}
216
+ size="medium"
217
+ />
218
+ </span>
219
+ ) : undefined,
231
220
  elemAfter: (
232
221
  <div className={DropdownMenuSharedCssClassName.SUBMENU}>
233
222
  <div
234
223
  css={cellColourPreviewStyles(background)}
235
224
  className={
236
- isDragAndDropEnabled &&
237
- getBooleanFF(
238
- 'platform.editor.table.new-cell-context-menu-styling',
239
- )
225
+ isDragAndDropEnabled
240
226
  ? ClassName.CONTEXTUAL_MENU_ICON_SMALL
241
227
  : ClassName.CONTEXTUAL_MENU_ICON
242
228
  }
@@ -280,29 +266,21 @@ export class ContextualMenu extends Component<
280
266
  content: formatMessage(messages.mergeCells),
281
267
  value: { name: 'merge' },
282
268
  isDisabled: !canMergeCells(state.tr),
283
- elemBefore:
284
- isDragAndDropEnabled &&
285
- getBooleanFF(
286
- 'platform.editor.table.new-cell-context-menu-styling',
287
- ) ? (
288
- <span css={elementBeforeIconStyles}>
289
- <MergeCellsIcon />
290
- </span>
291
- ) : undefined,
269
+ elemBefore: isDragAndDropEnabled ? (
270
+ <span css={elementBeforeIconStyles}>
271
+ <MergeCellsIcon />
272
+ </span>
273
+ ) : undefined,
292
274
  },
293
275
  {
294
276
  content: formatMessage(messages.splitCell),
295
277
  value: { name: 'split' },
296
278
  isDisabled: !splitCell(state),
297
- elemBefore:
298
- isDragAndDropEnabled &&
299
- getBooleanFF(
300
- 'platform.editor.table.new-cell-context-menu-styling',
301
- ) ? (
302
- <span css={elementBeforeIconStyles}>
303
- <SplitCellIcon />
304
- </span>
305
- ) : undefined,
279
+ elemBefore: isDragAndDropEnabled ? (
280
+ <span css={elementBeforeIconStyles}>
281
+ <SplitCellIcon />
282
+ </span>
283
+ ) : undefined,
306
284
  },
307
285
  ] as MenuItem[];
308
286
  }
@@ -318,20 +296,15 @@ export class ContextualMenu extends Component<
318
296
 
319
297
  return {
320
298
  content: formatMessage(
321
- isDragAndDropEnabled &&
322
- getBooleanFF('platform.editor.table.new-cell-context-menu-styling')
323
- ? messages.addColumnRight
324
- : messages.insertColumn,
299
+ isDragAndDropEnabled ? messages.addColumnRight : messages.insertColumn,
325
300
  ),
326
301
  value: { name: 'insert_column' },
327
302
  elemAfter: <div css={shortcutStyle}>{tooltip(addColumnAfter)}</div>,
328
- elemBefore:
329
- isDragAndDropEnabled &&
330
- getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? (
331
- <span css={elementBeforeIconStyles}>
332
- <AddColRightIcon />
333
- </span>
334
- ) : undefined,
303
+ elemBefore: isDragAndDropEnabled ? (
304
+ <span css={elementBeforeIconStyles}>
305
+ <AddColRightIcon />
306
+ </span>
307
+ ) : undefined,
335
308
  } as MenuItem;
336
309
  };
337
310
 
@@ -344,20 +317,15 @@ export class ContextualMenu extends Component<
344
317
 
345
318
  return {
346
319
  content: formatMessage(
347
- isDragAndDropEnabled &&
348
- getBooleanFF('platform.editor.table.new-cell-context-menu-styling')
349
- ? messages.addRowBelow
350
- : messages.insertRow,
320
+ isDragAndDropEnabled ? messages.addRowBelow : messages.insertRow,
351
321
  ),
352
322
  value: { name: 'insert_row' },
353
323
  elemAfter: <div css={shortcutStyle}>{tooltip(addRowAfter)}</div>,
354
- elemBefore:
355
- isDragAndDropEnabled &&
356
- getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? (
357
- <span css={elementBeforeIconStyles}>
358
- <AddRowBelowIcon />
359
- </span>
360
- ) : undefined,
324
+ elemBefore: isDragAndDropEnabled ? (
325
+ <span css={elementBeforeIconStyles}>
326
+ <AddRowBelowIcon />
327
+ </span>
328
+ ) : undefined,
361
329
  } as MenuItem;
362
330
  };
363
331
 
@@ -378,17 +346,15 @@ export class ContextualMenu extends Component<
378
346
  }),
379
347
  value: { name: 'clear' },
380
348
  elemAfter: <div css={shortcutStyle}>{tooltip(backspace)}</div>,
381
- elemBefore:
382
- isDragAndDropEnabled &&
383
- getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? (
384
- <span css={elementBeforeIconStyles}>
385
- <CrossCircleIcon
386
- label={formatMessage(messages.clearCells, {
387
- 0: Math.max(noOfColumns, noOfRows),
388
- })}
389
- />
390
- </span>
391
- ) : undefined,
349
+ elemBefore: isDragAndDropEnabled ? (
350
+ <span css={elementBeforeIconStyles}>
351
+ <CrossCircleIcon
352
+ label={formatMessage(messages.clearCells, {
353
+ 0: Math.max(noOfColumns, noOfRows),
354
+ })}
355
+ />
356
+ </span>
357
+ ) : undefined,
392
358
  } as MenuItem;
393
359
  };
394
360
 
@@ -408,17 +374,15 @@ export class ContextualMenu extends Component<
408
374
  0: noOfColumns,
409
375
  }),
410
376
  value: { name: 'delete_column' },
411
- elemBefore:
412
- isDragAndDropEnabled &&
413
- getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? (
414
- <span css={elementBeforeIconStyles}>
415
- <RemoveIcon
416
- label={formatMessage(messages.removeColumns, {
417
- 0: noOfColumns,
418
- })}
419
- />
420
- </span>
421
- ) : undefined,
377
+ elemBefore: isDragAndDropEnabled ? (
378
+ <span css={elementBeforeIconStyles}>
379
+ <RemoveIcon
380
+ label={formatMessage(messages.removeColumns, {
381
+ 0: noOfColumns,
382
+ })}
383
+ />
384
+ </span>
385
+ ) : undefined,
422
386
  } as MenuItem;
423
387
  };
424
388
 
@@ -438,17 +402,15 @@ export class ContextualMenu extends Component<
438
402
  0: noOfRows,
439
403
  }),
440
404
  value: { name: 'delete_row' },
441
- elemBefore:
442
- isDragAndDropEnabled &&
443
- getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? (
444
- <span css={elementBeforeIconStyles}>
445
- <RemoveIcon
446
- label={formatMessage(messages.removeRows, {
447
- 0: noOfRows,
448
- })}
449
- />
450
- </span>
451
- ) : undefined,
405
+ elemBefore: isDragAndDropEnabled ? (
406
+ <span css={elementBeforeIconStyles}>
407
+ <RemoveIcon
408
+ label={formatMessage(messages.removeRows, {
409
+ 0: noOfRows,
410
+ })}
411
+ />
412
+ </span>
413
+ ) : undefined,
452
414
  } as MenuItem;
453
415
  };
454
416
 
@@ -463,11 +425,7 @@ export class ContextualMenu extends Component<
463
425
  isDragAndDropEnabled,
464
426
  pluginConfig: { allowDistributeColumns },
465
427
  } = getPluginState(editorView.state);
466
- if (
467
- allowDistributeColumns &&
468
- (!isDragAndDropEnabled ||
469
- !getBooleanFF('platform.editor.table.new-cell-context-menu-styling'))
470
- ) {
428
+ if (allowDistributeColumns && !isDragAndDropEnabled) {
471
429
  const { isTableScalingEnabled = false } = getPluginState(
472
430
  editorView.state,
473
431
  );
@@ -498,11 +456,7 @@ export class ContextualMenu extends Component<
498
456
  } = this.props;
499
457
  const { isDragAndDropEnabled } = getPluginState(editorView.state);
500
458
 
501
- if (
502
- allowColumnSorting &&
503
- (!isDragAndDropEnabled ||
504
- !getBooleanFF('platform.editor.table.new-cell-context-menu-styling'))
505
- ) {
459
+ if (allowColumnSorting && !isDragAndDropEnabled) {
506
460
  const hasMergedCellsInTable =
507
461
  getMergedCellsPositions(editorView.state.tr).length > 0;
508
462
  const warning = hasMergedCellsInTable
@@ -620,27 +620,18 @@ export const DragMenu = React.memo(
620
620
  return null;
621
621
  }
622
622
 
623
- if (
624
- allowBackgroundColor &&
625
- getBooleanFF('platform.editor.table.new-cell-context-menu-styling')
626
- ) {
623
+ if (allowBackgroundColor) {
627
624
  menuItems[0].items.unshift(createBackgroundColorMenuItem());
628
625
  }
629
626
 
630
627
  // If first row, add toggle for Header row, default is true
631
628
  // If first column, add toggle for Header column, default is false
632
- if (
633
- getBooleanFF('platform.editor.table.new-cell-context-menu-styling') &&
634
- index === 0
635
- ) {
629
+ if (index === 0) {
636
630
  menuItems.push({ items: [createHeaderRowColumnMenuItem(direction)] });
637
631
  }
638
632
 
639
633
  // All rows, add toggle for numbered rows, default is false
640
- if (
641
- getBooleanFF('platform.editor.table.new-cell-context-menu-styling') &&
642
- direction === 'row'
643
- ) {
634
+ if (direction === 'row') {
644
635
  index === 0
645
636
  ? menuItems[menuItems.length - 1].items.push(createRowNumbersMenuItem())
646
637
  : menuItems.push({ items: [createRowNumbersMenuItem()] });
@@ -11,7 +11,6 @@ import {
11
11
  import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
12
12
  import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
13
13
  import { MenuGroup, Section } from '@atlaskit/menu';
14
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
15
14
 
16
15
  import { dragMenuDropdownWidth } from '../consts';
17
16
 
@@ -150,39 +149,31 @@ export const DropdownMenu = ({
150
149
  // The logic below normalises the index value based on the number
151
150
  // of menu items with 2 focusable elements, and adjusts the index to ensure
152
151
  // the correct menu item is sent in onItemActivated callback
153
- if (
154
- getBooleanFF(
155
- 'platform.editor.table.new-cell-context-menu-styling',
156
- )
157
- ) {
158
- const keys = ['row_numbers', 'header_row', 'header_column'];
159
- let doubleItemCount = 0;
152
+ const keys = ['row_numbers', 'header_row', 'header_column'];
153
+ let doubleItemCount = 0;
160
154
 
161
- const firstIndex = results.findIndex((value) =>
162
- keys.includes(value.key!),
163
- );
155
+ const firstIndex = results.findIndex((value) =>
156
+ keys.includes(value.key!),
157
+ );
158
+
159
+ if (firstIndex === -1 || index <= firstIndex) {
160
+ onItemActivated && onItemActivated({ item: results[index] });
161
+ return;
162
+ }
164
163
 
165
- if (firstIndex === -1 || index <= firstIndex) {
166
- onItemActivated && onItemActivated({ item: results[index] });
164
+ for (let i = firstIndex; i < results.length; i += 1) {
165
+ if (keys.includes(results[i].key!)) {
166
+ doubleItemCount += 1;
167
+ }
168
+ if (firstIndex % 2 === 0 && index - doubleItemCount === i) {
169
+ onItemActivated && onItemActivated({ item: results[i] });
167
170
  return;
168
171
  }
169
172
 
170
- for (let i = firstIndex; i < results.length; i += 1) {
171
- if (keys.includes(results[i].key!)) {
172
- doubleItemCount += 1;
173
- }
174
- if (firstIndex % 2 === 0 && index - doubleItemCount === i) {
175
- onItemActivated && onItemActivated({ item: results[i] });
176
- return;
177
- }
178
-
179
- if (firstIndex % 2 === 1 && index - doubleItemCount === i) {
180
- onItemActivated && onItemActivated({ item: results[i] });
181
- return;
182
- }
173
+ if (firstIndex % 2 === 1 && index - doubleItemCount === i) {
174
+ onItemActivated && onItemActivated({ item: results[i] });
175
+ return;
183
176
  }
184
- } else {
185
- onItemActivated && onItemActivated({ item: results[index] });
186
177
  }
187
178
  }}
188
179
  >
@@ -2,7 +2,9 @@
2
2
  import type { MouseEvent } from 'react';
3
3
  import React, { useCallback, useMemo, useRef } from 'react';
4
4
 
5
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
5
6
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
7
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
6
8
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
7
9
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
10
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
@@ -16,6 +18,7 @@ import {
16
18
  selectColumn,
17
19
  selectColumns,
18
20
  } from '../../../commands';
21
+ import type { TablePlugin } from '../../../plugin';
19
22
  import { toggleDragMenu } from '../../../pm-plugins/drag-and-drop/commands';
20
23
  import type { TriggerType } from '../../../pm-plugins/drag-and-drop/types';
21
24
  import type { CellHoverMeta, HandleTypes } from '../../../types';
@@ -69,8 +72,11 @@ export const ColumnControls = ({
69
72
  isNumberColumnEnabled,
70
73
  isDragging,
71
74
  getScrollOffset,
72
- }: ColumnControlsProps) => {
75
+ api,
76
+ }: ColumnControlsProps & { api?: ExtractInjectionAPI<TablePlugin> }) => {
73
77
  const columnControlsRef = useRef<HTMLDivElement>(null);
78
+ const { selectionState } = useSharedPluginState(api, ['selection']);
79
+
74
80
  const widths =
75
81
  colWidths
76
82
  ?.map((width) =>
@@ -82,7 +88,9 @@ export const ColumnControls = ({
82
88
  // TODO: reusing getRowsParams here because it's generic enough to work for columns -> rename
83
89
  const columnParams = getRowsParams(colWidths ?? []);
84
90
  const colIndex = hoveredCell?.colIndex;
85
- const selectedColIndexes = getSelectedColumns(editorView.state.selection);
91
+ const selectedColIndexes = getSelectedColumns(
92
+ selectionState?.selection || editorView.state.selection,
93
+ );
86
94
 
87
95
  const firstRow = tableRef.querySelector('tr');
88
96
  const hasHeaderRow = firstRow
@@ -5,10 +5,15 @@ import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
5
5
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
6
6
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
7
7
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
8
9
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
9
10
 
10
11
  import type { RowStickyState } from '../../pm-plugins/sticky-headers';
11
- import type { CellHoverMeta, DraggableSourceData } from '../../types';
12
+ import type {
13
+ CellHoverMeta,
14
+ DraggableSourceData,
15
+ PluginInjectionAPI,
16
+ } from '../../types';
12
17
  import { TableCssClassName as ClassName } from '../../types';
13
18
  import {
14
19
  containsHeaderColumn,
@@ -39,6 +44,7 @@ export interface Props {
39
44
  isNumberColumnEnabled?: boolean;
40
45
  getScrollOffset?: () => number;
41
46
  tableWrapperHeight?: number;
47
+ api?: PluginInjectionAPI;
42
48
  }
43
49
 
44
50
  export const TableFloatingColumnControls = ({
@@ -57,6 +63,7 @@ export const TableFloatingColumnControls = ({
57
63
  isNumberColumnEnabled,
58
64
  getScrollOffset,
59
65
  tableWrapperHeight,
66
+ api,
60
67
  }: Props) => {
61
68
  const [isDragging, setIsDragging] = useState(false);
62
69
  const containerRef = useRef<HTMLDivElement>(null);
@@ -136,6 +143,11 @@ export const TableFloatingColumnControls = ({
136
143
  isNumberColumnEnabled={isNumberColumnEnabled}
137
144
  isDragging={isDragging}
138
145
  getScrollOffset={getScrollOffset}
146
+ api={
147
+ getBooleanFF('platform.editor.table.use-shared-state-hook')
148
+ ? api
149
+ : undefined
150
+ }
139
151
  />
140
152
  {isDragging && (
141
153
  <ColumnDropTargets
@@ -4,7 +4,9 @@ import classnames from 'classnames';
4
4
  import type { WrappedComponentProps } from 'react-intl-next';
5
5
  import { injectIntl } from 'react-intl-next';
6
6
 
7
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
7
8
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
9
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
8
10
  import {
9
11
  findTable,
10
12
  isTableSelected,
@@ -12,6 +14,7 @@ import {
12
14
  } from '@atlaskit/editor-tables/utils';
13
15
 
14
16
  import { clearHoverSelection } from '../../../commands';
17
+ import type { TablePlugin } from '../../../plugin';
15
18
  import { TableCssClassName as ClassName } from '../../../types';
16
19
 
17
20
  import type { CornerControlProps } from './types';
@@ -62,4 +65,59 @@ const DragCornerControlsComponent = ({
62
65
  );
63
66
  };
64
67
 
68
+ const DragCornerControlsComponentWithSelection = ({
69
+ editorView,
70
+ isInDanger,
71
+ isResizing,
72
+ intl: { formatMessage },
73
+ api,
74
+ }: CornerControlProps &
75
+ WrappedComponentProps & { api?: ExtractInjectionAPI<TablePlugin> }) => {
76
+ const { selectionState } = useSharedPluginState(api, ['selection']);
77
+
78
+ const handleOnClick = () => {
79
+ const { state, dispatch } = editorView;
80
+ dispatch(selectTable(state.tr).setMeta('addToHistory', false));
81
+ };
82
+
83
+ const handleMouseOut = () => {
84
+ const { state, dispatch } = editorView;
85
+ clearHoverSelection()(state, dispatch);
86
+ };
87
+ const isActive = useMemo(() => {
88
+ if (!selectionState?.selection) {
89
+ return;
90
+ }
91
+ const table = findTable(selectionState.selection);
92
+ if (!table) {
93
+ return false;
94
+ }
95
+ return isTableSelected(selectionState.selection);
96
+ }, [selectionState]);
97
+
98
+ if (isResizing) {
99
+ return null;
100
+ }
101
+
102
+ return (
103
+ <button
104
+ className={classnames(ClassName.DRAG_CORNER_BUTTON, {
105
+ active: isActive,
106
+ danger: isActive && isInDanger,
107
+ })}
108
+ aria-label={formatMessage(messages.cornerControl)}
109
+ type="button"
110
+ onClick={handleOnClick}
111
+ onMouseOut={handleMouseOut}
112
+ contentEditable={false}
113
+ >
114
+ <div className={ClassName.DRAG_CORNER_BUTTON_INNER} />
115
+ </button>
116
+ );
117
+ };
118
+
119
+ export const DragCornerControlsWithSelection = injectIntl(
120
+ DragCornerControlsComponentWithSelection,
121
+ );
122
+
65
123
  export const DragCornerControls = injectIntl(DragCornerControlsComponent);
@@ -1,2 +1,5 @@
1
1
  export { CornerControls } from './ClassicCornerControls';
2
- export { DragCornerControls } from './DragCornerControls';
2
+ export {
3
+ DragCornerControls,
4
+ DragCornerControlsWithSelection,
5
+ } from './DragCornerControls';