@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
@@ -6,6 +6,7 @@ import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
6
6
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
7
7
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
8
8
  import { TableMap } from '@atlaskit/editor-tables/table-map';
9
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
10
  import { pluginConfig as getPluginConfig } from '../create-plugin-config';
10
11
  import { pluginKey as tableDragAndDropPluginKey } from '../pm-plugins/drag-and-drop';
11
12
  import { getPluginState } from '../pm-plugins/plugin-factory';
@@ -15,6 +16,7 @@ import { generateColgroup } from '../pm-plugins/table-resizing/utils';
15
16
  import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
16
17
  import { isTableNested } from '../utils';
17
18
  import TableComponent from './TableComponent';
19
+ import { TableComponentWithSharedState } from './TableComponentWithSharedState';
18
20
  const tableAttributes = node => {
19
21
  return {
20
22
  'data-number-column': node.attrs.isNumberColumnEnabled,
@@ -92,6 +94,22 @@ export default class TableView extends ReactNodeView {
92
94
  }
93
95
  }
94
96
  render(props, forwardRef) {
97
+ if (getBooleanFF('platform.editor.table.use-shared-state-hook')) {
98
+ return /*#__PURE__*/React.createElement(TableComponentWithSharedState, {
99
+ forwardRef: forwardRef,
100
+ getNode: this.getNode,
101
+ view: props.view,
102
+ options: props.options,
103
+ eventDispatcher: props.eventDispatcher,
104
+ api: props.pluginInjectionApi,
105
+ allowColumnResizing: props.allowColumnResizing,
106
+ allowControls: props.allowControls,
107
+ getPos: props.getPos,
108
+ getEditorFeatureFlags: props.getEditorFeatureFlags,
109
+ dispatchAnalyticsEvent: props.dispatchAnalyticsEvent
110
+ });
111
+ }
112
+
95
113
  // TODO: ED-15663
96
114
  // Please, do not copy or use this kind of code below
97
115
  // @ts-ignore
@@ -236,13 +254,15 @@ export const createTableView = (node, view, getPos, portalProviderAPI, eventDisp
236
254
  isTableScalingEnabled
237
255
  } = getPluginState(view.state);
238
256
  const {
239
- allowColumnResizing
257
+ allowColumnResizing,
258
+ allowControls
240
259
  } = getPluginConfig(pluginConfig);
241
260
  const hasIntlContext = true;
242
261
  return new TableView({
243
262
  node,
244
263
  view,
245
264
  allowColumnResizing,
265
+ allowControls,
246
266
  portalProviderAPI,
247
267
  eventDispatcher,
248
268
  getPos: getPos,
@@ -24,7 +24,7 @@ import { createPlugin as createTableSafariDeleteCompositionTextIssueWorkaroundPl
24
24
  import { createPlugin as createStickyHeadersPlugin, findStickyHeaderForTable, pluginKey as stickyHeadersPluginKey } from './pm-plugins/sticky-headers';
25
25
  import { createPlugin as createTableOverflowAnalyticsPlugin } from './pm-plugins/table-analytics';
26
26
  import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-local-id';
27
- import { createPlugin as createFlexiResizingPlugin, pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing';
27
+ import { createPlugin as createFlexiResizingPlugin, getPluginState as getFlexiResizingPlugin, pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing';
28
28
  import { tableSelectionKeymapPlugin } from './pm-plugins/table-selection-keymap';
29
29
  import { createPlugin as createTableWidthPlugin, pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
30
30
  import { getToolbarConfig } from './toolbar';
@@ -36,6 +36,9 @@ import FloatingInsertButton from './ui/FloatingInsertButton';
36
36
  import LayoutButton from './ui/LayoutButton';
37
37
  import { createTableWithWidth, isLayoutSupported } from './utils';
38
38
  const defaultGetEditorFeatureFlags = () => ({});
39
+
40
+ // TODO: duplicating type instead of importing media plugin causing a circular dependency
41
+
39
42
  /**
40
43
  * Table plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
41
44
  * from `@atlaskit/editor-core`.
@@ -59,10 +62,30 @@ const tablesPlugin = ({
59
62
  name: 'table',
60
63
  // Use getSharedState to store fullWidthEnabled and wasFullWidthModeEnabled to guarantee access
61
64
  // to most up to date values - passing to createPluginState will not re-initialise the state
62
- getSharedState: () => {
65
+ getSharedState: editorState => {
66
+ if (!editorState) {
67
+ return undefined;
68
+ }
69
+ const tablePluginState = getPluginState(editorState);
70
+ const tableResizingPluginState = getFlexiResizingPlugin(editorState);
71
+ const tableWidthResizingPluginState = tableWidthPluginKey.getState(editorState);
63
72
  return {
64
73
  isFullWidthModeEnabled: !!(options !== null && options !== void 0 && options.fullWidthEnabled),
65
- wasFullWidthModeEnabled: !!(options !== null && options !== void 0 && options.wasFullWidthEnabled)
74
+ wasFullWidthModeEnabled: !!(options !== null && options !== void 0 && options.wasFullWidthEnabled),
75
+ isHeaderRowEnabled: tablePluginState.isHeaderRowEnabled,
76
+ isHeaderColumnEnabled: tablePluginState.isHeaderColumnEnabled,
77
+ ordering: tablePluginState.ordering,
78
+ isResizing: !!(tableResizingPluginState !== null && tableResizingPluginState !== void 0 && tableResizingPluginState.dragging || tableWidthResizingPluginState !== null && tableWidthResizingPluginState !== void 0 && tableWidthResizingPluginState.resizing),
79
+ isTableResizing: tableWidthResizingPluginState === null || tableWidthResizingPluginState === void 0 ? void 0 : tableWidthResizingPluginState.resizing,
80
+ isInDanger: tablePluginState.isInDanger,
81
+ hoveredRows: tablePluginState.hoveredRows,
82
+ hoveredCell: tablePluginState.hoveredCell,
83
+ isTableHovered: tablePluginState.isTableHovered,
84
+ isWholeTableInDanger: tablePluginState.isWholeTableInDanger,
85
+ // IMPORTANT: Need to continue to pass tableNode to control re-renders
86
+ // TableComponent listens for node attribute changes to update colgroups
87
+ tableNode: tablePluginState.tableNode,
88
+ widthToWidest: tablePluginState.widthToWidest
66
89
  };
67
90
  },
68
91
  actions: {
@@ -14,7 +14,6 @@ import { findCellRectClosestToPos, findTable, getSelectionRect, isSelectionType,
14
14
  import DistributeColumnIcon from '@atlaskit/icon/glyph/editor/layout-three-equal';
15
15
  import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
16
16
  import TableOptionsIcon from '@atlaskit/icon/glyph/preferences';
17
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
18
17
  import { clearHoverSelection, hoverColumns, hoverMergedCells, hoverRows, hoverTable, removeDescendantNodes } from './commands';
19
18
  import { deleteColumnsWithAnalytics, deleteRowsWithAnalytics, deleteTableWithAnalytics, distributeColumnsWidthsWithAnalytics, emptyMultipleCellsWithAnalytics, insertColumnWithAnalytics, insertRowWithAnalytics, mergeCellsWithAnalytics, setColorWithAnalytics, sortColumnWithAnalytics, splitCellWithAnalytics, toggleHeaderColumnWithAnalytics, toggleHeaderRowWithAnalytics, toggleNumberColumnWithAnalytics, wrapTableInExpandWithAnalytics } from './commands-with-analytics';
20
19
  import { getPluginState } from './pm-plugins/plugin-factory';
@@ -54,7 +53,7 @@ export const getToolbarMenuConfig = (config, state, {
54
53
  disabled: !state.canCollapseTable,
55
54
  hidden: !config.allowCollapse
56
55
  }];
57
- if (state.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling')) {
56
+ if (state.isDragAndDropEnabled) {
58
57
  return {
59
58
  id: 'editor.table.tableOptions',
60
59
  type: 'dropdown',
@@ -287,6 +286,7 @@ export const getClosestSelectionOrTableRect = state => {
287
286
  return isSelectionType(selection, 'cell') ? getSelectionRect(selection) : tableRect;
288
287
  };
289
288
  export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, getEditorFeatureFlags, getEditorView) => config => (state, intl) => {
289
+ var _tableObject$node$att, _tableObject$node, _tableObject$node$att2;
290
290
  const tableObject = findTable(state.selection);
291
291
  const pluginState = getPluginState(state);
292
292
  const resizeState = tableResizingPluginKey.getState(state);
@@ -298,7 +298,8 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
298
298
  isTableScalingEnabled,
299
299
  widthToWidest
300
300
  } = pluginState;
301
- if (isTableScalingEnabled && isWidthResizing && widthToWidest) {
301
+ const currentTableNodeLocalId = (_tableObject$node$att = tableObject === null || tableObject === void 0 ? void 0 : (_tableObject$node = tableObject.node) === null || _tableObject$node === void 0 ? void 0 : (_tableObject$node$att2 = _tableObject$node.attrs) === null || _tableObject$node$att2 === void 0 ? void 0 : _tableObject$node$att2.localId) !== null && _tableObject$node$att !== void 0 ? _tableObject$node$att : '';
302
+ if (isTableScalingEnabled && isWidthResizing && widthToWidest && currentTableNodeLocalId && widthToWidest[currentTableNodeLocalId]) {
302
303
  const {
303
304
  stickyScrollbar
304
305
  } = getEditorFeatureFlags();
@@ -351,7 +352,7 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
351
352
  let cellItems;
352
353
  cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled);
353
354
  let columnSettingsItems;
354
- columnSettingsItems = pluginState.isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled) : [];
355
+ columnSettingsItems = pluginState.isDragAndDropEnabled ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled) : [];
355
356
  const colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI);
356
357
 
357
358
  // Check if we need to show confirm dialog for delete button
@@ -6,6 +6,9 @@ export const RESIZE_HANDLE_AREA_DECORATION_GAP = 30;
6
6
  * @deprecated {@link https://hello.atlassian.net/browse/ENGHEALTH-6877 Internal documentation for deprecation (no external access)}
7
7
  **/
8
8
 
9
+ // override getPluginState but do not expose publicly as this type is experimental and will change
10
+ // in the future
11
+
9
12
  /*
10
13
  * This type represents the start and end from a cell in a column,
11
14
  * for example, on this table the cell C1 will have
@@ -70,11 +70,11 @@ export class ContextualMenu extends Component {
70
70
  const node = isOpen && targetCellPosition ? state.doc.nodeAt(targetCellPosition) : null;
71
71
  const background = hexToEditorBackgroundPaletteColor((node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.background) || '#ffffff');
72
72
  return {
73
- content: isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? formatMessage(messages.backgroundColor) : formatMessage(messages.cellBackground),
73
+ content: isDragAndDropEnabled ? formatMessage(messages.backgroundColor) : formatMessage(messages.cellBackground),
74
74
  value: {
75
75
  name: 'background'
76
76
  },
77
- elemBefore: isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? jsx("span", {
77
+ elemBefore: isDragAndDropEnabled ? jsx("span", {
78
78
  css: elementBeforeIconStyles
79
79
  }, jsx(EditorBackgroundColorIcon, {
80
80
  label: formatMessage(messages.backgroundColor),
@@ -84,7 +84,7 @@ export class ContextualMenu extends Component {
84
84
  className: DropdownMenuSharedCssClassName.SUBMENU
85
85
  }, jsx("div", {
86
86
  css: cellColourPreviewStyles(background),
87
- className: isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? ClassName.CONTEXTUAL_MENU_ICON_SMALL : ClassName.CONTEXTUAL_MENU_ICON
87
+ className: isDragAndDropEnabled ? ClassName.CONTEXTUAL_MENU_ICON_SMALL : ClassName.CONTEXTUAL_MENU_ICON
88
88
  }), isSubmenuOpen && jsx("div", {
89
89
  className: ClassName.CONTEXTUAL_SUBMENU,
90
90
  ref: this.handleSubMenuRef
@@ -122,7 +122,7 @@ export class ContextualMenu extends Component {
122
122
  name: 'merge'
123
123
  },
124
124
  isDisabled: !canMergeCells(state.tr),
125
- elemBefore: isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? jsx("span", {
125
+ elemBefore: isDragAndDropEnabled ? jsx("span", {
126
126
  css: elementBeforeIconStyles
127
127
  }, jsx(MergeCellsIcon, null)) : undefined
128
128
  }, {
@@ -131,7 +131,7 @@ export class ContextualMenu extends Component {
131
131
  name: 'split'
132
132
  },
133
133
  isDisabled: !splitCell(state),
134
- elemBefore: isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? jsx("span", {
134
+ elemBefore: isDragAndDropEnabled ? jsx("span", {
135
135
  css: elementBeforeIconStyles
136
136
  }, jsx(SplitCellIcon, null)) : undefined
137
137
  }];
@@ -149,14 +149,14 @@ export class ContextualMenu extends Component {
149
149
  isDragAndDropEnabled
150
150
  } = getPluginState(editorView.state);
151
151
  return {
152
- content: formatMessage(isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? messages.addColumnRight : messages.insertColumn),
152
+ content: formatMessage(isDragAndDropEnabled ? messages.addColumnRight : messages.insertColumn),
153
153
  value: {
154
154
  name: 'insert_column'
155
155
  },
156
156
  elemAfter: jsx("div", {
157
157
  css: shortcutStyle
158
158
  }, tooltip(addColumnAfter)),
159
- elemBefore: isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? jsx("span", {
159
+ elemBefore: isDragAndDropEnabled ? jsx("span", {
160
160
  css: elementBeforeIconStyles
161
161
  }, jsx(AddColRightIcon, null)) : undefined
162
162
  };
@@ -172,14 +172,14 @@ export class ContextualMenu extends Component {
172
172
  isDragAndDropEnabled
173
173
  } = getPluginState(editorView.state);
174
174
  return {
175
- content: formatMessage(isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? messages.addRowBelow : messages.insertRow),
175
+ content: formatMessage(isDragAndDropEnabled ? messages.addRowBelow : messages.insertRow),
176
176
  value: {
177
177
  name: 'insert_row'
178
178
  },
179
179
  elemAfter: jsx("div", {
180
180
  css: shortcutStyle
181
181
  }, tooltip(addRowAfter)),
182
- elemBefore: isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? jsx("span", {
182
+ elemBefore: isDragAndDropEnabled ? jsx("span", {
183
183
  css: elementBeforeIconStyles
184
184
  }, jsx(AddRowBelowIcon, null)) : undefined
185
185
  };
@@ -213,7 +213,7 @@ export class ContextualMenu extends Component {
213
213
  elemAfter: jsx("div", {
214
214
  css: shortcutStyle
215
215
  }, tooltip(backspace)),
216
- elemBefore: isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? jsx("span", {
216
+ elemBefore: isDragAndDropEnabled ? jsx("span", {
217
217
  css: elementBeforeIconStyles
218
218
  }, jsx(CrossCircleIcon, {
219
219
  label: formatMessage(messages.clearCells, {
@@ -245,7 +245,7 @@ export class ContextualMenu extends Component {
245
245
  value: {
246
246
  name: 'delete_column'
247
247
  },
248
- elemBefore: isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? jsx("span", {
248
+ elemBefore: isDragAndDropEnabled ? jsx("span", {
249
249
  css: elementBeforeIconStyles
250
250
  }, jsx(RemoveIcon, {
251
251
  label: formatMessage(messages.removeColumns, {
@@ -277,7 +277,7 @@ export class ContextualMenu extends Component {
277
277
  value: {
278
278
  name: 'delete_row'
279
279
  },
280
- elemBefore: isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? jsx("span", {
280
+ elemBefore: isDragAndDropEnabled ? jsx("span", {
281
281
  css: elementBeforeIconStyles
282
282
  }, jsx(RemoveIcon, {
283
283
  label: formatMessage(messages.removeRows, {
@@ -301,7 +301,7 @@ export class ContextualMenu extends Component {
301
301
  allowDistributeColumns
302
302
  }
303
303
  } = getPluginState(editorView.state);
304
- if (allowDistributeColumns && (!isDragAndDropEnabled || !getBooleanFF('platform.editor.table.new-cell-context-menu-styling'))) {
304
+ if (allowDistributeColumns && !isDragAndDropEnabled) {
305
305
  var _newResizeState$chang;
306
306
  const {
307
307
  isTableScalingEnabled = false
@@ -329,7 +329,7 @@ export class ContextualMenu extends Component {
329
329
  const {
330
330
  isDragAndDropEnabled
331
331
  } = getPluginState(editorView.state);
332
- if (allowColumnSorting && (!isDragAndDropEnabled || !getBooleanFF('platform.editor.table.new-cell-context-menu-styling'))) {
332
+ if (allowColumnSorting && !isDragAndDropEnabled) {
333
333
  const hasMergedCellsInTable = getMergedCellsPositions(editorView.state.tr).length > 0;
334
334
  const warning = hasMergedCellsInTable ? {
335
335
  tooltipDescription: formatMessage(messages.canNotSortTable),
@@ -568,7 +568,7 @@ export class ContextualMenu extends Component {
568
568
  const {
569
569
  isDragAndDropEnabled
570
570
  } = getPluginState(editorView.state);
571
- const items = isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') ? this.createNewContextMenuItems() : this.createOriginalContextMenuItems();
571
+ const items = isDragAndDropEnabled ? this.createNewContextMenuItems() : this.createOriginalContextMenuItems();
572
572
  return jsx("div", {
573
573
  "data-testid": "table-cell-contextual-menu",
574
574
  onMouseLeave: this.closeSubmenu
@@ -591,7 +591,7 @@ export class ContextualMenu extends Component {
591
591
  fitWidth: isDragAndDropEnabled ? contextualMenuDropdownWidthDnD : contextualMenuDropdownWidth,
592
592
  boundariesElement: boundariesElement,
593
593
  offset: offset,
594
- section: isDragAndDropEnabled && getBooleanFF('platform.editor.table.new-cell-context-menu-styling') && getBooleanFF('platform.editor.menu.group-items') ? {
594
+ section: isDragAndDropEnabled && getBooleanFF('platform.editor.menu.group-items') ? {
595
595
  hasSeparator: true
596
596
  } : undefined
597
597
  }));
@@ -448,20 +448,20 @@ export const DragMenu = /*#__PURE__*/React.memo(({
448
448
  if (!menuItems) {
449
449
  return null;
450
450
  }
451
- if (allowBackgroundColor && getBooleanFF('platform.editor.table.new-cell-context-menu-styling')) {
451
+ if (allowBackgroundColor) {
452
452
  menuItems[0].items.unshift(createBackgroundColorMenuItem());
453
453
  }
454
454
 
455
455
  // If first row, add toggle for Header row, default is true
456
456
  // If first column, add toggle for Header column, default is false
457
- if (getBooleanFF('platform.editor.table.new-cell-context-menu-styling') && index === 0) {
457
+ if (index === 0) {
458
458
  menuItems.push({
459
459
  items: [createHeaderRowColumnMenuItem(direction)]
460
460
  });
461
461
  }
462
462
 
463
463
  // All rows, add toggle for numbered rows, default is false
464
- if (getBooleanFF('platform.editor.table.new-cell-context-menu-styling') && direction === 'row') {
464
+ if (direction === 'row') {
465
465
  index === 0 ? menuItems[menuItems.length - 1].items.push(createRowNumbersMenuItem()) : menuItems.push({
466
466
  items: [createRowNumbersMenuItem()]
467
467
  });
@@ -5,7 +5,6 @@ import { ArrowKeyNavigationProvider, ArrowKeyNavigationType, DropdownMenuItem }
5
5
  import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
6
6
  import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
7
7
  import { MenuGroup, Section } from '@atlaskit/menu';
8
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
8
  import { dragMenuDropdownWidth } from '../consts';
10
9
  const DropListWithOutsideListeners = withReactEditorViewOuterListeners(DropList);
11
10
  export const DropdownMenu = ({
@@ -106,37 +105,31 @@ export const DropdownMenu = ({
106
105
  // The logic below normalises the index value based on the number
107
106
  // of menu items with 2 focusable elements, and adjusts the index to ensure
108
107
  // the correct menu item is sent in onItemActivated callback
109
- if (getBooleanFF('platform.editor.table.new-cell-context-menu-styling')) {
110
- const keys = ['row_numbers', 'header_row', 'header_column'];
111
- let doubleItemCount = 0;
112
- const firstIndex = results.findIndex(value => keys.includes(value.key));
113
- if (firstIndex === -1 || index <= firstIndex) {
108
+ const keys = ['row_numbers', 'header_row', 'header_column'];
109
+ let doubleItemCount = 0;
110
+ const firstIndex = results.findIndex(value => keys.includes(value.key));
111
+ if (firstIndex === -1 || index <= firstIndex) {
112
+ onItemActivated && onItemActivated({
113
+ item: results[index]
114
+ });
115
+ return;
116
+ }
117
+ for (let i = firstIndex; i < results.length; i += 1) {
118
+ if (keys.includes(results[i].key)) {
119
+ doubleItemCount += 1;
120
+ }
121
+ if (firstIndex % 2 === 0 && index - doubleItemCount === i) {
114
122
  onItemActivated && onItemActivated({
115
- item: results[index]
123
+ item: results[i]
116
124
  });
117
125
  return;
118
126
  }
119
- for (let i = firstIndex; i < results.length; i += 1) {
120
- if (keys.includes(results[i].key)) {
121
- doubleItemCount += 1;
122
- }
123
- if (firstIndex % 2 === 0 && index - doubleItemCount === i) {
124
- onItemActivated && onItemActivated({
125
- item: results[i]
126
- });
127
- return;
128
- }
129
- if (firstIndex % 2 === 1 && index - doubleItemCount === i) {
130
- onItemActivated && onItemActivated({
131
- item: results[i]
132
- });
133
- return;
134
- }
127
+ if (firstIndex % 2 === 1 && index - doubleItemCount === i) {
128
+ onItemActivated && onItemActivated({
129
+ item: results[i]
130
+ });
131
+ return;
135
132
  }
136
- } else {
137
- onItemActivated && onItemActivated({
138
- item: results[index]
139
- });
140
133
  }
141
134
  }
142
135
  }, innerMenu())));
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable @atlaskit/design-system/prefer-primitives */
2
2
 
3
3
  import React, { useCallback, useMemo, useRef } from 'react';
4
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
5
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
5
6
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
6
7
  import { CellSelection } from '@atlaskit/editor-tables';
@@ -35,10 +36,14 @@ export const ColumnControls = ({
35
36
  tableContainerWidth,
36
37
  isNumberColumnEnabled,
37
38
  isDragging,
38
- getScrollOffset
39
+ getScrollOffset,
40
+ api
39
41
  }) => {
40
42
  var _colWidths$map$join, _rowHeights$;
41
43
  const columnControlsRef = useRef(null);
44
+ const {
45
+ selectionState
46
+ } = useSharedPluginState(api, ['selection']);
42
47
  const widths = (_colWidths$map$join = colWidths === null || colWidths === void 0 ? void 0 : colWidths.map(width =>
43
48
  // when there is sticky header, a `margin-right: -1px` applied to `tr.sticky th` so it causes colWidths to be 1px wider
44
49
  // we need to reduce the width by 1px to avoid misalignment of column controls.
@@ -46,7 +51,7 @@ export const ColumnControls = ({
46
51
  // TODO: reusing getRowsParams here because it's generic enough to work for columns -> rename
47
52
  const columnParams = getRowsParams(colWidths !== null && colWidths !== void 0 ? colWidths : []);
48
53
  const colIndex = hoveredCell === null || hoveredCell === void 0 ? void 0 : hoveredCell.colIndex;
49
- const selectedColIndexes = getSelectedColumns(editorView.state.selection);
54
+ const selectedColIndexes = getSelectedColumns((selectionState === null || selectionState === void 0 ? void 0 : selectionState.selection) || editorView.state.selection);
50
55
  const firstRow = tableRef.querySelector('tr');
51
56
  const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
52
57
  const marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
@@ -1,4 +1,5 @@
1
1
  import React, { useEffect, useMemo, useRef, useState } from 'react';
2
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
2
3
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
3
4
  import { TableCssClassName as ClassName } from '../../types';
4
5
  import { containsHeaderColumn, getColumnsWidths, getRowHeights } from '../../utils';
@@ -19,7 +20,8 @@ export const TableFloatingColumnControls = ({
19
20
  tableContainerWidth,
20
21
  isNumberColumnEnabled,
21
22
  getScrollOffset,
22
- tableWrapperHeight
23
+ tableWrapperHeight,
24
+ api
23
25
  }) => {
24
26
  const [isDragging, setIsDragging] = useState(false);
25
27
  const containerRef = useRef(null);
@@ -86,7 +88,8 @@ export const TableFloatingColumnControls = ({
86
88
  tableContainerWidth: tableContainerWidth,
87
89
  isNumberColumnEnabled: isNumberColumnEnabled,
88
90
  isDragging: isDragging,
89
- getScrollOffset: getScrollOffset
91
+ getScrollOffset: getScrollOffset,
92
+ api: getBooleanFF('platform.editor.table.use-shared-state-hook') ? api : undefined
90
93
  }), isDragging && /*#__PURE__*/React.createElement(ColumnDropTargets, {
91
94
  tableRef: tableRef,
92
95
  isHeaderSticky: (stickyHeader === null || stickyHeader === void 0 ? void 0 : stickyHeader.sticky) && hasHeaderRow,
@@ -1,6 +1,7 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import classnames from 'classnames';
3
3
  import { injectIntl } from 'react-intl-next';
4
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
5
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
5
6
  import { findTable, isTableSelected, selectTable } from '@atlaskit/editor-tables/utils';
6
7
  import { clearHoverSelection } from '../../../commands';
@@ -54,4 +55,58 @@ const DragCornerControlsComponent = ({
54
55
  className: ClassName.DRAG_CORNER_BUTTON_INNER
55
56
  }));
56
57
  };
58
+ const DragCornerControlsComponentWithSelection = ({
59
+ editorView,
60
+ isInDanger,
61
+ isResizing,
62
+ intl: {
63
+ formatMessage
64
+ },
65
+ api
66
+ }) => {
67
+ const {
68
+ selectionState
69
+ } = useSharedPluginState(api, ['selection']);
70
+ const handleOnClick = () => {
71
+ const {
72
+ state,
73
+ dispatch
74
+ } = editorView;
75
+ dispatch(selectTable(state.tr).setMeta('addToHistory', false));
76
+ };
77
+ const handleMouseOut = () => {
78
+ const {
79
+ state,
80
+ dispatch
81
+ } = editorView;
82
+ clearHoverSelection()(state, dispatch);
83
+ };
84
+ const isActive = useMemo(() => {
85
+ if (!(selectionState !== null && selectionState !== void 0 && selectionState.selection)) {
86
+ return;
87
+ }
88
+ const table = findTable(selectionState.selection);
89
+ if (!table) {
90
+ return false;
91
+ }
92
+ return isTableSelected(selectionState.selection);
93
+ }, [selectionState]);
94
+ if (isResizing) {
95
+ return null;
96
+ }
97
+ return /*#__PURE__*/React.createElement("button", {
98
+ className: classnames(ClassName.DRAG_CORNER_BUTTON, {
99
+ active: isActive,
100
+ danger: isActive && isInDanger
101
+ }),
102
+ "aria-label": formatMessage(messages.cornerControl),
103
+ type: "button",
104
+ onClick: handleOnClick,
105
+ onMouseOut: handleMouseOut,
106
+ contentEditable: false
107
+ }, /*#__PURE__*/React.createElement("div", {
108
+ className: ClassName.DRAG_CORNER_BUTTON_INNER
109
+ }));
110
+ };
111
+ export const DragCornerControlsWithSelection = injectIntl(DragCornerControlsComponentWithSelection);
57
112
  export const DragCornerControls = injectIntl(DragCornerControlsComponent);
@@ -1,2 +1,2 @@
1
1
  export { CornerControls } from './ClassicCornerControls';
2
- export { DragCornerControls } from './DragCornerControls';
2
+ export { DragCornerControls, DragCornerControlsWithSelection } from './DragCornerControls';
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
+ import { CornerControls } from './CornerControls';
4
+ import { RowControls } from './RowControls';
5
+ export const FloatingControlsWithSelection = ({
6
+ editorView,
7
+ tableRef,
8
+ isInDanger,
9
+ isResizing,
10
+ isHeaderRowEnabled,
11
+ isHeaderColumnEnabled,
12
+ hoveredRows,
13
+ stickyTop,
14
+ hoverRows,
15
+ selectRow,
16
+ tableActive,
17
+ api
18
+ }) => {
19
+ const {
20
+ selectionState
21
+ } = useSharedPluginState(api, ['selection']);
22
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CornerControls, {
23
+ editorView: editorView,
24
+ tableRef: tableRef,
25
+ isInDanger: isInDanger,
26
+ isResizing: isResizing,
27
+ isHeaderRowEnabled: isHeaderRowEnabled,
28
+ isHeaderColumnEnabled: isHeaderColumnEnabled,
29
+ hoveredRows: hoveredRows,
30
+ stickyTop: tableActive ? stickyTop : undefined
31
+ }), /*#__PURE__*/React.createElement(RowControls, {
32
+ selection: selectionState === null || selectionState === void 0 ? void 0 : selectionState.selection,
33
+ editorView: editorView,
34
+ tableRef: tableRef,
35
+ hoverRows: hoverRows,
36
+ hoveredRows: hoveredRows,
37
+ isInDanger: isInDanger,
38
+ isResizing: isResizing,
39
+ selectRow: selectRow,
40
+ stickyTop: tableActive ? stickyTop : undefined
41
+ }));
42
+ };
@@ -26,7 +26,8 @@ class RowControlsComponent extends Component {
26
26
  isResizing,
27
27
  intl: {
28
28
  formatMessage
29
- }
29
+ },
30
+ selection: selectionState
30
31
  } = this.props;
31
32
  if (!tableRef) {
32
33
  return null;
@@ -54,7 +55,7 @@ class RowControlsComponent extends Component {
54
55
  }
55
56
  const thisRowSticky = this.props.stickyTop !== undefined && index === 0 && hasHeaderRow;
56
57
  return /*#__PURE__*/React.createElement("div", {
57
- className: `${ClassName.ROW_CONTROLS_BUTTON_WRAP} ${getRowClassNames(startIndex, selection, hoveredRows, isInDanger, isResizing)} ${thisRowSticky ? 'sticky' : ''}`,
58
+ className: `${ClassName.ROW_CONTROLS_BUTTON_WRAP} ${getRowClassNames(startIndex, selectionState || selection, hoveredRows, isInDanger, isResizing)} ${thisRowSticky ? 'sticky' : ''}`,
58
59
  key: startIndex,
59
60
  style: {
60
61
  height: height,
@@ -1,8 +1,10 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { browser } from '@atlaskit/editor-common/utils';
3
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
3
4
  import { hoverCell, hoverRows, selectRow, selectRows } from '../../commands';
4
5
  import { TableCssClassName as ClassName } from '../../types';
5
- import { CornerControls, DragCornerControls } from './CornerControls';
6
+ import { CornerControls, DragCornerControls, DragCornerControlsWithSelection } from './CornerControls';
7
+ import { FloatingControlsWithSelection } from './FloatingControlsWithSelection';
6
8
  import NumberColumn from './NumberColumn';
7
9
  import { DragControls, RowControls } from './RowControls';
8
10
  export const TableFloatingControls = ({
@@ -21,7 +23,8 @@ export const TableFloatingControls = ({
21
23
  isDragAndDropEnabled,
22
24
  hoveredCell,
23
25
  isTableHovered,
24
- tableWrapperWidth
26
+ tableWrapperWidth,
27
+ api
25
28
  }) => {
26
29
  const _selectRow = useCallback((row, expand) => {
27
30
  const {
@@ -89,7 +92,13 @@ export const TableFloatingControls = ({
89
92
  updateCellHoverLocation: updateCellHoverLocation,
90
93
  stickyTop: stickyTop,
91
94
  isDragAndDropEnabled: isDragAndDropEnabled
92
- }) : null, tableActive && /*#__PURE__*/React.createElement(React.Fragment, null, isDragAndDropEnabled ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DragCornerControls, {
95
+ }) : null, tableActive && /*#__PURE__*/React.createElement(React.Fragment, null, isDragAndDropEnabled ? /*#__PURE__*/React.createElement(React.Fragment, null, getBooleanFF('platform.editor.table.use-shared-state-hook') ? /*#__PURE__*/React.createElement(DragCornerControlsWithSelection, {
96
+ editorView: editorView,
97
+ tableRef: tableRef,
98
+ isInDanger: isInDanger,
99
+ isResizing: isResizing,
100
+ api: api
101
+ }) : /*#__PURE__*/React.createElement(DragCornerControls, {
93
102
  editorView: editorView,
94
103
  tableRef: tableRef,
95
104
  isInDanger: isInDanger,
@@ -108,7 +117,20 @@ export const TableFloatingControls = ({
108
117
  selectRow: _selectRow,
109
118
  selectRows: _selectRows,
110
119
  updateCellHoverLocation: updateCellHoverLocation
111
- })) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CornerControls, {
120
+ })) : getBooleanFF('platform.editor.table.use-shared-state-hook') ? /*#__PURE__*/React.createElement(FloatingControlsWithSelection, {
121
+ editorView: editorView,
122
+ tableRef: tableRef,
123
+ isInDanger: isInDanger,
124
+ isResizing: isResizing,
125
+ isHeaderRowEnabled: isHeaderRowEnabled,
126
+ isHeaderColumnEnabled: isHeaderColumnEnabled,
127
+ hoveredRows: hoveredRows,
128
+ stickyTop: tableActive ? stickyTop : undefined,
129
+ tableActive: tableActive,
130
+ hoverRows: _hoverRows,
131
+ selectRow: _selectRow,
132
+ api: api
133
+ }) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CornerControls, {
112
134
  editorView: editorView,
113
135
  tableRef: tableRef,
114
136
  isInDanger: isInDanger,