@atlaskit/editor-plugin-table 7.6.2 → 7.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/nodeviews/TableComponent.js +25 -11
  3. package/dist/cjs/nodeviews/TableComponentWithSharedState.js +87 -0
  4. package/dist/cjs/nodeviews/TableContainer.js +8 -4
  5. package/dist/cjs/nodeviews/TableResizer.js +4 -5
  6. package/dist/cjs/nodeviews/table.js +21 -1
  7. package/dist/cjs/plugin.js +24 -2
  8. package/dist/cjs/types.js +3 -0
  9. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +6 -2
  10. package/dist/cjs/ui/TableFloatingColumnControls/index.js +5 -2
  11. package/dist/cjs/ui/TableFloatingControls/CornerControls/DragCornerControls.js +48 -1
  12. package/dist/cjs/ui/TableFloatingControls/CornerControls/index.js +6 -0
  13. package/dist/cjs/ui/TableFloatingControls/FloatingControlsWithSelection.js +47 -0
  14. package/dist/cjs/ui/TableFloatingControls/RowControls/ClassicControls.js +3 -2
  15. package/dist/cjs/ui/TableFloatingControls/index.js +25 -3
  16. package/dist/cjs/ui/common-styles.js +11 -6
  17. package/dist/es2019/nodeviews/TableComponent.js +27 -12
  18. package/dist/es2019/nodeviews/TableComponentWithSharedState.js +83 -0
  19. package/dist/es2019/nodeviews/TableContainer.js +8 -4
  20. package/dist/es2019/nodeviews/TableResizer.js +2 -4
  21. package/dist/es2019/nodeviews/table.js +21 -1
  22. package/dist/es2019/plugin.js +25 -3
  23. package/dist/es2019/types.js +3 -0
  24. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -2
  25. package/dist/es2019/ui/TableFloatingColumnControls/index.js +5 -2
  26. package/dist/es2019/ui/TableFloatingControls/CornerControls/DragCornerControls.js +55 -0
  27. package/dist/es2019/ui/TableFloatingControls/CornerControls/index.js +1 -1
  28. package/dist/es2019/ui/TableFloatingControls/FloatingControlsWithSelection.js +42 -0
  29. package/dist/es2019/ui/TableFloatingControls/RowControls/ClassicControls.js +3 -2
  30. package/dist/es2019/ui/TableFloatingControls/index.js +26 -4
  31. package/dist/es2019/ui/common-styles.js +589 -588
  32. package/dist/esm/nodeviews/TableComponent.js +25 -11
  33. package/dist/esm/nodeviews/TableComponentWithSharedState.js +80 -0
  34. package/dist/esm/nodeviews/TableContainer.js +8 -4
  35. package/dist/esm/nodeviews/TableResizer.js +4 -5
  36. package/dist/esm/nodeviews/table.js +21 -1
  37. package/dist/esm/plugin.js +25 -3
  38. package/dist/esm/types.js +3 -0
  39. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +6 -2
  40. package/dist/esm/ui/TableFloatingColumnControls/index.js +5 -2
  41. package/dist/esm/ui/TableFloatingControls/CornerControls/DragCornerControls.js +47 -0
  42. package/dist/esm/ui/TableFloatingControls/CornerControls/index.js +1 -1
  43. package/dist/esm/ui/TableFloatingControls/FloatingControlsWithSelection.js +40 -0
  44. package/dist/esm/ui/TableFloatingControls/RowControls/ClassicControls.js +3 -2
  45. package/dist/esm/ui/TableFloatingControls/index.js +26 -4
  46. package/dist/esm/ui/common-styles.js +10 -5
  47. package/dist/types/nodeviews/TableComponent.d.ts +7 -2
  48. package/dist/types/nodeviews/TableComponentWithSharedState.d.ts +27 -0
  49. package/dist/types/nodeviews/TableContainer.d.ts +4 -2
  50. package/dist/types/nodeviews/TableResizer.d.ts +2 -1
  51. package/dist/types/nodeviews/types.d.ts +1 -0
  52. package/dist/types/plugin.d.ts +11 -7
  53. package/dist/types/types.d.ts +8 -2
  54. package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +113 -1
  55. package/dist/types/ui/TableFloatingColumnControls/index.d.ts +3 -2
  56. package/dist/types/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +223 -0
  57. package/dist/types/ui/TableFloatingControls/CornerControls/index.d.ts +1 -1
  58. package/dist/types/ui/TableFloatingControls/FloatingControlsWithSelection.d.ts +20 -0
  59. package/dist/types/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +2 -0
  60. package/dist/types/ui/TableFloatingControls/index.d.ts +113 -1
  61. package/dist/types/ui/common-styles.d.ts +3 -0
  62. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +7 -2
  63. package/dist/types-ts4.5/nodeviews/TableComponentWithSharedState.d.ts +27 -0
  64. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -2
  65. package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
  66. package/dist/types-ts4.5/nodeviews/types.d.ts +1 -0
  67. package/dist/types-ts4.5/plugin.d.ts +11 -7
  68. package/dist/types-ts4.5/types.d.ts +8 -2
  69. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +144 -1
  70. package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +3 -2
  71. package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +285 -0
  72. package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/index.d.ts +1 -1
  73. package/dist/types-ts4.5/ui/TableFloatingControls/FloatingControlsWithSelection.d.ts +20 -0
  74. package/dist/types-ts4.5/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +2 -0
  75. package/dist/types-ts4.5/ui/TableFloatingControls/index.d.ts +144 -1
  76. package/dist/types-ts4.5/ui/common-styles.d.ts +3 -0
  77. package/package.json +6 -3
  78. package/src/nodeviews/TableComponent.tsx +36 -7
  79. package/src/nodeviews/TableComponentWithSharedState.tsx +125 -0
  80. package/src/nodeviews/TableContainer.tsx +6 -0
  81. package/src/nodeviews/TableResizer.tsx +2 -1
  82. package/src/nodeviews/table.tsx +22 -1
  83. package/src/nodeviews/types.ts +1 -0
  84. package/src/plugin.tsx +46 -6
  85. package/src/types.ts +27 -2
  86. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +10 -2
  87. package/src/ui/TableFloatingColumnControls/index.tsx +13 -1
  88. package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +58 -0
  89. package/src/ui/TableFloatingControls/CornerControls/index.tsx +4 -1
  90. package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +68 -0
  91. package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +4 -1
  92. package/src/ui/TableFloatingControls/index.tsx +42 -8
  93. package/src/ui/common-styles.ts +611 -610
package/src/plugin.tsx CHANGED
@@ -28,6 +28,7 @@ import type {
28
28
  GetEditorContainerWidth,
29
29
  GetEditorFeatureFlags,
30
30
  NextEditorPlugin,
31
+ OptionalPlugin,
31
32
  } from '@atlaskit/editor-common/types';
32
33
  import { browser } from '@atlaskit/editor-common/utils';
33
34
  import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
@@ -64,6 +65,7 @@ import { createPlugin as createTableOverflowAnalyticsPlugin } from './pm-plugins
64
65
  import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-local-id';
65
66
  import {
66
67
  createPlugin as createFlexiResizingPlugin,
68
+ getPluginState as getFlexiResizingPlugin,
67
69
  pluginKey as tableResizingPluginKey,
68
70
  } from './pm-plugins/table-resizing';
69
71
  import { tableSelectionKeymapPlugin } from './pm-plugins/table-selection-keymap';
@@ -72,7 +74,11 @@ import {
72
74
  pluginKey as tableWidthPluginKey,
73
75
  } from './pm-plugins/table-width';
74
76
  import { getToolbarConfig } from './toolbar';
75
- import type { ColumnResizingPluginState, PluginConfig } from './types';
77
+ import type {
78
+ ColumnResizingPluginState,
79
+ PluginConfig,
80
+ TableSharedState,
81
+ } from './types';
76
82
  import FloatingContextualButton from './ui/FloatingContextualButton';
77
83
  import FloatingContextualMenu from './ui/FloatingContextualMenu';
78
84
  import FloatingDeleteButton from './ui/FloatingDeleteButton';
@@ -100,6 +106,17 @@ type InsertTableAction = (analyticsPayload: AnalyticsEventPayload) => Command;
100
106
 
101
107
  const defaultGetEditorFeatureFlags = () => ({});
102
108
 
109
+ // TODO: duplicating type instead of importing media plugin causing a circular dependency
110
+ type MediaPlugin = NextEditorPlugin<
111
+ 'media',
112
+ {
113
+ pluginConfiguration: any;
114
+ dependencies: any;
115
+ sharedState: any;
116
+ actions: any;
117
+ }
118
+ >;
119
+
103
120
  export type TablePlugin = NextEditorPlugin<
104
121
  'table',
105
122
  {
@@ -107,10 +124,7 @@ export type TablePlugin = NextEditorPlugin<
107
124
  actions: {
108
125
  insertTable: InsertTableAction;
109
126
  };
110
- sharedState: {
111
- isFullWidthModeEnabled: boolean;
112
- wasFullWidthModeEnabled: boolean;
113
- };
127
+ sharedState?: TableSharedState;
114
128
  commands: {
115
129
  insertTableWithSize: (
116
130
  rowsCount: number,
@@ -124,6 +138,7 @@ export type TablePlugin = NextEditorPlugin<
124
138
  WidthPlugin,
125
139
  GuidelinePlugin,
126
140
  SelectionPlugin,
141
+ OptionalPlugin<MediaPlugin>,
127
142
  ];
128
143
  }
129
144
  >;
@@ -148,10 +163,35 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
148
163
 
149
164
  // Use getSharedState to store fullWidthEnabled and wasFullWidthModeEnabled to guarantee access
150
165
  // to most up to date values - passing to createPluginState will not re-initialise the state
151
- getSharedState: () => {
166
+ getSharedState: (editorState) => {
167
+ if (!editorState) {
168
+ return undefined;
169
+ }
170
+
171
+ const tablePluginState = getPluginState(editorState);
172
+ const tableResizingPluginState = getFlexiResizingPlugin(editorState);
173
+ const tableWidthResizingPluginState =
174
+ tableWidthPluginKey.getState(editorState);
175
+
152
176
  return {
153
177
  isFullWidthModeEnabled: !!options?.fullWidthEnabled,
154
178
  wasFullWidthModeEnabled: !!options?.wasFullWidthEnabled,
179
+ isHeaderRowEnabled: tablePluginState.isHeaderRowEnabled,
180
+ isHeaderColumnEnabled: tablePluginState.isHeaderColumnEnabled,
181
+ ordering: tablePluginState.ordering,
182
+ isResizing: !!(
183
+ tableResizingPluginState?.dragging ||
184
+ tableWidthResizingPluginState?.resizing
185
+ ),
186
+ isTableResizing: tableWidthResizingPluginState?.resizing,
187
+ isInDanger: tablePluginState.isInDanger,
188
+ hoveredRows: tablePluginState.hoveredRows,
189
+ hoveredCell: tablePluginState.hoveredCell,
190
+ isTableHovered: tablePluginState.isTableHovered,
191
+ isWholeTableInDanger: tablePluginState.isWholeTableInDanger,
192
+ // IMPORTANT: Need to continue to pass tableNode to control re-renders
193
+ // TableComponent listens for node attribute changes to update colgroups
194
+ tableNode: tablePluginState.tableNode,
155
195
  };
156
196
  },
157
197
 
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,32 @@ 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
+ > & {
53
+ isResizing: boolean;
54
+ isTableResizing?: boolean;
55
+ isWholeTableInDanger?: boolean;
56
+ };
57
+
58
+ export type TableSharedState = Pick<
59
+ TablePluginState,
60
+ 'isFullWidthModeEnabled' | 'wasFullWidthModeEnabled'
61
+ >;
37
62
 
38
63
  export type InsertRowMethods =
39
64
  | INPUT_METHOD.CONTEXT_MENU
@@ -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';
@@ -0,0 +1,68 @@
1
+ import React from 'react';
2
+
3
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
5
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
+
7
+ import type { TablePlugin } from '../../plugin';
8
+
9
+ import { CornerControls } from './CornerControls';
10
+ import { RowControls } from './RowControls';
11
+
12
+ type FloatingControlsWithSelectionProps = {
13
+ editorView: EditorView;
14
+ tableRef: HTMLTableElement;
15
+ isInDanger?: boolean;
16
+ isResizing?: boolean;
17
+ isHeaderRowEnabled?: boolean;
18
+ isHeaderColumnEnabled?: boolean;
19
+ hoveredRows?: number[];
20
+ stickyTop?: number;
21
+ hoverRows: (rows: number[]) => void;
22
+ selectRow: (row: number, expand: boolean) => void;
23
+ tableActive: boolean;
24
+ api?: ExtractInjectionAPI<TablePlugin>;
25
+ };
26
+
27
+ export const FloatingControlsWithSelection = ({
28
+ editorView,
29
+ tableRef,
30
+ isInDanger,
31
+ isResizing,
32
+ isHeaderRowEnabled,
33
+ isHeaderColumnEnabled,
34
+ hoveredRows,
35
+ stickyTop,
36
+ hoverRows,
37
+ selectRow,
38
+ tableActive,
39
+ api,
40
+ }: FloatingControlsWithSelectionProps) => {
41
+ const { selectionState } = useSharedPluginState(api, ['selection']);
42
+
43
+ return (
44
+ <>
45
+ <CornerControls
46
+ editorView={editorView}
47
+ tableRef={tableRef}
48
+ isInDanger={isInDanger}
49
+ isResizing={isResizing}
50
+ isHeaderRowEnabled={isHeaderRowEnabled}
51
+ isHeaderColumnEnabled={isHeaderColumnEnabled}
52
+ hoveredRows={hoveredRows}
53
+ stickyTop={tableActive ? stickyTop : undefined}
54
+ />
55
+ <RowControls
56
+ selection={selectionState?.selection}
57
+ editorView={editorView}
58
+ tableRef={tableRef}
59
+ hoverRows={hoverRows}
60
+ hoveredRows={hoveredRows}
61
+ isInDanger={isInDanger}
62
+ isResizing={isResizing}
63
+ selectRow={selectRow}
64
+ stickyTop={tableActive ? stickyTop : undefined}
65
+ />
66
+ </>
67
+ );
68
+ };
@@ -4,6 +4,7 @@ import type { WrappedComponentProps } from 'react-intl-next';
4
4
  import { injectIntl } from 'react-intl-next';
5
5
 
6
6
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
7
+ import type { Selection } from '@atlaskit/editor-prosemirror/state';
7
8
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
9
 
9
10
  import { clearHoverSelection } from '../../../commands';
@@ -22,6 +23,7 @@ export interface Props {
22
23
  isResizing?: boolean;
23
24
  insertRowButtonIndex?: number;
24
25
  stickyTop?: number;
26
+ selection?: Selection;
25
27
  }
26
28
 
27
29
  class RowControlsComponent extends Component<Props & WrappedComponentProps> {
@@ -33,6 +35,7 @@ class RowControlsComponent extends Component<Props & WrappedComponentProps> {
33
35
  isInDanger,
34
36
  isResizing,
35
37
  intl: { formatMessage },
38
+ selection: selectionState,
36
39
  } = this.props;
37
40
  if (!tableRef) {
38
41
  return null;
@@ -72,7 +75,7 @@ class RowControlsComponent extends Component<Props & WrappedComponentProps> {
72
75
  ClassName.ROW_CONTROLS_BUTTON_WRAP
73
76
  } ${getRowClassNames(
74
77
  startIndex,
75
- selection,
78
+ selectionState || selection,
76
79
  hoveredRows,
77
80
  isInDanger,
78
81
  isResizing,
@@ -1,17 +1,25 @@
1
1
  import React, { useCallback } from 'react';
2
2
 
3
3
  import type { TableColumnOrdering } from '@atlaskit/custom-steps';
4
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
5
  import { browser } from '@atlaskit/editor-common/utils';
5
6
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
6
7
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
7
8
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
9
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
8
10
 
9
11
  import { hoverCell, hoverRows, selectRow, selectRows } from '../../commands';
12
+ import type { TablePlugin } from '../../plugin';
10
13
  import type { RowStickyState } from '../../pm-plugins/sticky-headers';
11
14
  import { TableCssClassName as ClassName } from '../../types';
12
15
  import type { CellHoverMeta } from '../../types';
13
16
 
14
- import { CornerControls, DragCornerControls } from './CornerControls';
17
+ import {
18
+ CornerControls,
19
+ DragCornerControls,
20
+ DragCornerControlsWithSelection,
21
+ } from './CornerControls';
22
+ import { FloatingControlsWithSelection } from './FloatingControlsWithSelection';
15
23
  import NumberColumn from './NumberColumn';
16
24
  import { DragControls, RowControls } from './RowControls';
17
25
 
@@ -55,7 +63,8 @@ export const TableFloatingControls = ({
55
63
  hoveredCell,
56
64
  isTableHovered,
57
65
  tableWrapperWidth,
58
- }: TableFloatingControlsProps) => {
66
+ api,
67
+ }: TableFloatingControlsProps & { api?: ExtractInjectionAPI<TablePlugin> }) => {
59
68
  const _selectRow = useCallback(
60
69
  (row: number, expand: boolean) => {
61
70
  const { state, dispatch } = editorView;
@@ -141,12 +150,22 @@ export const TableFloatingControls = ({
141
150
  <>
142
151
  {isDragAndDropEnabled ? (
143
152
  <>
144
- <DragCornerControls
145
- editorView={editorView}
146
- tableRef={tableRef}
147
- isInDanger={isInDanger}
148
- isResizing={isResizing}
149
- />
153
+ {getBooleanFF('platform.editor.table.use-shared-state-hook') ? (
154
+ <DragCornerControlsWithSelection
155
+ editorView={editorView}
156
+ tableRef={tableRef}
157
+ isInDanger={isInDanger}
158
+ isResizing={isResizing}
159
+ api={api}
160
+ />
161
+ ) : (
162
+ <DragCornerControls
163
+ editorView={editorView}
164
+ tableRef={tableRef}
165
+ isInDanger={isInDanger}
166
+ isResizing={isResizing}
167
+ />
168
+ )}
150
169
  <DragControls
151
170
  tableRef={tableRef}
152
171
  tableNode={tableNode}
@@ -163,6 +182,21 @@ export const TableFloatingControls = ({
163
182
  updateCellHoverLocation={updateCellHoverLocation}
164
183
  />
165
184
  </>
185
+ ) : getBooleanFF('platform.editor.table.use-shared-state-hook') ? (
186
+ <FloatingControlsWithSelection
187
+ editorView={editorView}
188
+ tableRef={tableRef}
189
+ isInDanger={isInDanger}
190
+ isResizing={isResizing}
191
+ isHeaderRowEnabled={isHeaderRowEnabled}
192
+ isHeaderColumnEnabled={isHeaderColumnEnabled}
193
+ hoveredRows={hoveredRows}
194
+ stickyTop={tableActive ? stickyTop : undefined}
195
+ tableActive={tableActive}
196
+ hoverRows={_hoverRows}
197
+ selectRow={_selectRow}
198
+ api={api}
199
+ />
166
200
  ) : (
167
201
  <>
168
202
  <CornerControls