@atlaskit/editor-plugin-table 10.9.7 → 10.9.9

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 (36) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/nodeviews/TableComponentWithSharedState.js +33 -19
  3. package/dist/cjs/nodeviews/TableContainer.js +1 -1
  4. package/dist/cjs/nodeviews/TableResizer.js +2 -2
  5. package/dist/cjs/pm-plugins/utils/paste.js +26 -28
  6. package/dist/cjs/tablePlugin.js +1 -1
  7. package/dist/cjs/ui/ContentComponent.js +77 -37
  8. package/dist/cjs/ui/DragHandle/index.js +3 -3
  9. package/dist/cjs/ui/hooks/useInternalTablePluginStateSelector.js +27 -0
  10. package/dist/es2019/nodeviews/TableComponentWithSharedState.js +33 -19
  11. package/dist/es2019/nodeviews/TableContainer.js +1 -1
  12. package/dist/es2019/nodeviews/TableResizer.js +2 -2
  13. package/dist/es2019/pm-plugins/utils/paste.js +26 -28
  14. package/dist/es2019/tablePlugin.js +1 -1
  15. package/dist/es2019/ui/ContentComponent.js +66 -27
  16. package/dist/es2019/ui/DragHandle/index.js +3 -3
  17. package/dist/es2019/ui/hooks/useInternalTablePluginStateSelector.js +21 -0
  18. package/dist/esm/nodeviews/TableComponentWithSharedState.js +33 -19
  19. package/dist/esm/nodeviews/TableContainer.js +1 -1
  20. package/dist/esm/nodeviews/TableResizer.js +2 -2
  21. package/dist/esm/pm-plugins/utils/paste.js +26 -28
  22. package/dist/esm/tablePlugin.js +1 -1
  23. package/dist/esm/ui/ContentComponent.js +77 -37
  24. package/dist/esm/ui/DragHandle/index.js +3 -3
  25. package/dist/esm/ui/hooks/useInternalTablePluginStateSelector.js +21 -0
  26. package/dist/types/ui/hooks/useInternalTablePluginStateSelector.d.ts +20 -0
  27. package/dist/types-ts4.5/ui/hooks/useInternalTablePluginStateSelector.d.ts +20 -0
  28. package/package.json +5 -8
  29. package/src/nodeviews/TableComponentWithSharedState.tsx +40 -28
  30. package/src/nodeviews/TableContainer.tsx +1 -1
  31. package/src/nodeviews/TableResizer.tsx +4 -4
  32. package/src/pm-plugins/utils/paste.ts +31 -33
  33. package/src/tablePlugin.tsx +1 -1
  34. package/src/ui/ContentComponent.tsx +71 -35
  35. package/src/ui/DragHandle/index.tsx +6 -10
  36. package/src/ui/hooks/useInternalTablePluginStateSelector.ts +36 -0
@@ -0,0 +1,20 @@
1
+ import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import { TablePlugin } from '../../tablePluginType';
3
+ import { TableSharedStateInternal } from '../../types';
4
+ type Options = {
5
+ disabled?: boolean;
6
+ };
7
+ /**
8
+ * **This hook is only for internal use and should not be used outside of the table plugin.**
9
+ *
10
+ * Hook to select a value from the internal table plugin state.
11
+ * This is a wrapper around `useSharedPluginStateSelector` to provide access to the entire
12
+ * `TableSharedStateInternal` type. Since tables plugin has a lot of internal state that is not
13
+ * exposed via the `TableSharedState` type, we need to use this hook to access it in a type safe way.
14
+ *
15
+ * @param api The editor API
16
+ * @param key Key of TableSharedStateInternal to select
17
+ * @returns
18
+ */
19
+ export declare const useInternalTablePluginStateSelector: <K extends "isFullWidthModeEnabled" | "wasFullWidthModeEnabled" | "isHeaderRowEnabled" | "isHeaderColumnEnabled" | "ordering" | "isInDanger" | "hoveredRows" | "hoveredColumns" | "hoveredCell" | "isTableHovered" | "tableNode" | "widthToWidest" | "tableRef" | "tablePos" | "targetCellPosition" | "isContextualMenuOpen" | "pluginConfig" | "insertColumnButtonIndex" | "insertRowButtonIndex" | "isDragAndDropEnabled" | "tableWrapperTarget" | "isCellMenuOpenByKeyboard" | "isWholeTableInDanger" | "isDragMenuOpen" | "dragMenuDirection" | "dragMenuIndex" | "isResizing" | "isTableResizing" | "resizingTableRef" | "resizingTableLocalId" | "stickyHeader">(api: ExtractInjectionAPI<TablePlugin> | undefined, key: K, options?: Options) => TableSharedStateInternal[K] | undefined;
20
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "10.9.7",
3
+ "version": "10.9.9",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -32,14 +32,14 @@
32
32
  "@atlaskit/adf-schema": "^47.6.0",
33
33
  "@atlaskit/button": "^23.0.0",
34
34
  "@atlaskit/custom-steps": "^0.11.0",
35
- "@atlaskit/editor-common": "^103.17.0",
35
+ "@atlaskit/editor-common": "^103.19.0",
36
36
  "@atlaskit/editor-palette": "^2.1.0",
37
37
  "@atlaskit/editor-plugin-accessibility-utils": "^2.0.0",
38
38
  "@atlaskit/editor-plugin-analytics": "^2.2.0",
39
39
  "@atlaskit/editor-plugin-batch-attribute-updates": "^2.1.0",
40
40
  "@atlaskit/editor-plugin-content-insertion": "^2.1.0",
41
41
  "@atlaskit/editor-plugin-editor-viewmode": "^3.1.0",
42
- "@atlaskit/editor-plugin-extension": "5.3.0",
42
+ "@atlaskit/editor-plugin-extension": "5.3.1",
43
43
  "@atlaskit/editor-plugin-guideline": "^2.0.0",
44
44
  "@atlaskit/editor-plugin-selection": "^2.1.0",
45
45
  "@atlaskit/editor-plugin-width": "^3.0.0",
@@ -49,12 +49,12 @@
49
49
  "@atlaskit/icon": "^25.6.0",
50
50
  "@atlaskit/menu": "^3.2.0",
51
51
  "@atlaskit/platform-feature-flags": "^1.1.0",
52
- "@atlaskit/pragmatic-drag-and-drop": "^1.5.0",
52
+ "@atlaskit/pragmatic-drag-and-drop": "^1.6.0",
53
53
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^2.1.0",
54
54
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.0",
55
55
  "@atlaskit/primitives": "^14.4.0",
56
56
  "@atlaskit/theme": "^18.0.0",
57
- "@atlaskit/tmp-editor-statsig": "^4.14.0",
57
+ "@atlaskit/tmp-editor-statsig": "^4.15.0",
58
58
  "@atlaskit/toggle": "^15.0.0",
59
59
  "@atlaskit/tokens": "^4.8.0",
60
60
  "@atlaskit/tooltip": "^20.0.0",
@@ -138,9 +138,6 @@
138
138
  "platform_editor_disable_table_lnv": {
139
139
  "type": "boolean"
140
140
  },
141
- "platform_editor_nested_tables_paste_wrap_fix": {
142
- "type": "boolean"
143
- },
144
141
  "nested_table_control_padding_with_css": {
145
142
  "type": "boolean"
146
143
  },
@@ -3,19 +3,15 @@ import React from 'react';
3
3
  import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
4
4
  import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
5
5
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
6
- import type {
7
- ExtractInjectionAPI,
8
- GetEditorFeatureFlags,
9
- getPosHandlerNode,
10
- } from '@atlaskit/editor-common/types';
6
+ import type { GetEditorFeatureFlags, getPosHandlerNode } from '@atlaskit/editor-common/types';
11
7
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
12
8
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
13
9
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
14
10
  import { findTable } from '@atlaskit/editor-tables';
15
11
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
16
12
 
17
- import { TablePlugin } from '../tablePluginType';
18
13
  import type { PluginInjectionAPI, TableSharedStateInternal } from '../types';
14
+ import { useInternalTablePluginStateSelector } from '../ui/hooks/useInternalTablePluginStateSelector';
19
15
 
20
16
  import TableComponent from './TableComponent';
21
17
  import type { TableOptions } from './types';
@@ -40,16 +36,6 @@ type TableComponentWithSharedStateProps = {
40
36
  allowTableResizing?: boolean;
41
37
  };
42
38
 
43
- const useSharedTablePluginStateSelector = <K extends keyof TableSharedStateInternal>(
44
- api: ExtractInjectionAPI<TablePlugin> | undefined,
45
- key: K,
46
- ) => {
47
- const value = useSharedPluginStateSelector(api, `table.${key}` as never, {
48
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
49
- }) as TableSharedStateInternal[K];
50
- return value;
51
- };
52
-
53
39
  /**
54
40
  * Use useSharedPluginState to control re-renders from plugin dependencies
55
41
  */
@@ -73,21 +59,47 @@ export const TableComponentWithSharedState = ({
73
59
  disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
74
60
  });
75
61
 
76
- const isTableResizingSelector = useSharedTablePluginStateSelector(api, 'isTableResizing');
77
- const isHeaderColumnEnabledSelector = useSharedTablePluginStateSelector(
62
+ const isTableResizingSelector = useInternalTablePluginStateSelector(api, 'isTableResizing', {
63
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
64
+ });
65
+ const isHeaderColumnEnabledSelector = useInternalTablePluginStateSelector(
78
66
  api,
79
67
  'isHeaderColumnEnabled',
68
+ {
69
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
70
+ },
80
71
  );
81
- const isHeaderRowEnabledSelector = useSharedTablePluginStateSelector(api, 'isHeaderRowEnabled');
82
- const orderingSelector = useSharedTablePluginStateSelector(api, 'ordering');
83
- const isResizingSelector = useSharedTablePluginStateSelector(api, 'isResizing');
84
- const isInDangerSelector = useSharedTablePluginStateSelector(api, 'isInDanger');
85
- const hoveredCellSelector = useSharedTablePluginStateSelector(api, 'hoveredCell');
86
- const hoveredRowsSelector = useSharedTablePluginStateSelector(api, 'hoveredRows');
87
- const isTableHoveredSelector = useSharedTablePluginStateSelector(api, 'isTableHovered');
88
- const isWholeTableInDangerSelector = useSharedTablePluginStateSelector(
72
+ const isHeaderRowEnabledSelector = useInternalTablePluginStateSelector(
73
+ api,
74
+ 'isHeaderRowEnabled',
75
+ {
76
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
77
+ },
78
+ );
79
+ const orderingSelector = useInternalTablePluginStateSelector(api, 'ordering', {
80
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
81
+ });
82
+ const isResizingSelector = useInternalTablePluginStateSelector(api, 'isResizing', {
83
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
84
+ });
85
+ const isInDangerSelector = useInternalTablePluginStateSelector(api, 'isInDanger', {
86
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
87
+ });
88
+ const hoveredCellSelector = useInternalTablePluginStateSelector(api, 'hoveredCell', {
89
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
90
+ });
91
+ const hoveredRowsSelector = useInternalTablePluginStateSelector(api, 'hoveredRows', {
92
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
93
+ });
94
+ const isTableHoveredSelector = useInternalTablePluginStateSelector(api, 'isTableHovered', {
95
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
96
+ });
97
+ const isWholeTableInDangerSelector = useInternalTablePluginStateSelector(
89
98
  api,
90
99
  'isWholeTableInDanger',
100
+ {
101
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
102
+ },
91
103
  );
92
104
 
93
105
  // mediaState
@@ -203,8 +215,8 @@ export const TableComponentWithSharedState = ({
203
215
  isMediaFullscreen={isFullscreen}
204
216
  options={options}
205
217
  allowControls={allowControls}
206
- isHeaderRowEnabled={isHeaderRowEnabled}
207
- isHeaderColumnEnabled={isHeaderColumnEnabled}
218
+ isHeaderRowEnabled={isHeaderRowEnabled ?? false}
219
+ isHeaderColumnEnabled={isHeaderColumnEnabled ?? false}
208
220
  isDragAndDropEnabled={options?.isDragAndDropEnabled && !isLivePageViewMode}
209
221
  isTableScalingEnabled={options?.isTableScalingEnabled}
210
222
  allowTableAlignment={allowTableAlignment}
@@ -114,7 +114,7 @@ const AlignmentTableContainer = ({
114
114
  : tableState?.wasFullWidthModeEnabled;
115
115
 
116
116
  useEffect(() => {
117
- if (editorExperiment('platform_editor_usesharedpluginstateselector', false) && !tableState) {
117
+ if (!tableState && editorExperiment('platform_editor_usesharedpluginstateselector', false)) {
118
118
  return;
119
119
  }
120
120
 
@@ -19,7 +19,6 @@ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
19
19
  import { logException } from '@atlaskit/editor-common/monitoring';
20
20
  import type { HandleResize, HandleSize } from '@atlaskit/editor-common/resizer';
21
21
  import { ResizerNext } from '@atlaskit/editor-common/resizer';
22
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
23
22
  import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
24
23
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
25
24
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
@@ -70,6 +69,7 @@ import {
70
69
  TABLE_HIGHLIGHT_TOLERANCE,
71
70
  TABLE_SNAP_GAP,
72
71
  } from '../ui/consts';
72
+ import { useInternalTablePluginStateSelector } from '../ui/hooks/useInternalTablePluginStateSelector';
73
73
 
74
74
  interface TableResizerProps {
75
75
  width: number;
@@ -218,13 +218,13 @@ export const TableResizer = ({
218
218
  });
219
219
 
220
220
  // widthToWidest
221
- const widthToWidestSelector = useSharedPluginStateSelector(
221
+ const widthToWidestSelector = useInternalTablePluginStateSelector(
222
222
  pluginInjectionApi,
223
- 'table.widthToWidest' as never,
223
+ 'widthToWidest',
224
224
  {
225
225
  disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
226
226
  },
227
- ) as TableSharedStateInternal['widthToWidest'];
227
+ );
228
228
  const widthToWidest = editorExperiment('platform_editor_usesharedpluginstateselector', true)
229
229
  ? widthToWidestSelector
230
230
  : (tableState as TableSharedStateInternal).widthToWidest;
@@ -260,40 +260,38 @@ const containsNonTableBlockChildren = (fragment: Fragment, schema: Schema): bool
260
260
  };
261
261
 
262
262
  export const transformSliceToRemoveOpenTable = (slice: Slice, schema: Schema): Slice => {
263
- if (fg('platform_editor_nested_tables_paste_wrap_fix')) {
264
- // Case 1: A slice of a block selection inside a nested table
265
- // Prosemirror wraps nested block selections in their respective tables
266
- // We are using `safeInsert` to paste nested tables, so we do not want to preserve this wrapping
267
-
268
- // slice starts and ends inside a nested table at the same depth
269
- if (slice.openStart >= 7 && slice.openEnd >= 7) {
270
- let cleaned = slice;
271
- let descendedDepth = 0;
272
- const tableDepthDecrement = 2;
273
-
274
- // if the slice is a single cell table and contains cells with single cell tables, descend into it until we find textblock children
275
- if (isFragmentSingleCellTable(slice.content, schema)) {
276
- slice.content.firstChild?.descendants((node) => {
277
- if (isNodeSingleCellTable(node, schema)) {
278
- descendedDepth += tableDepthDecrement;
279
- } else if (node.type === schema.nodes.table) {
280
- return false;
281
- } else if (containsNonTableBlockChildren(node.content, schema)) {
282
- descendedDepth += tableDepthDecrement;
283
- // create a new slice with the content of non-table block children and the depth of the nested tables subtracted
284
- cleaned = new Slice(
285
- node.content,
286
- slice.openStart - descendedDepth - tableDepthDecrement,
287
- slice.openEnd - descendedDepth - tableDepthDecrement,
288
- );
289
- return false;
290
- }
291
- });
292
- }
263
+ // Case 1: A slice of a block selection inside a nested table
264
+ // Prosemirror wraps nested block selections in their respective tables
265
+ // We are using `safeInsert` to paste nested tables, so we do not want to preserve this wrapping
293
266
 
294
- if (!cleaned.eq(slice)) {
295
- return cleaned;
296
- }
267
+ // slice starts and ends inside a nested table at the same depth
268
+ if (slice.openStart >= 7 && slice.openEnd >= 7) {
269
+ let cleaned = slice;
270
+ let descendedDepth = 0;
271
+ const tableDepthDecrement = 2;
272
+
273
+ // if the slice is a single cell table and contains cells with single cell tables, descend into it until we find textblock children
274
+ if (isFragmentSingleCellTable(slice.content, schema)) {
275
+ slice.content.firstChild?.descendants((node) => {
276
+ if (isNodeSingleCellTable(node, schema)) {
277
+ descendedDepth += tableDepthDecrement;
278
+ } else if (node.type === schema.nodes.table) {
279
+ return false;
280
+ } else if (containsNonTableBlockChildren(node.content, schema)) {
281
+ descendedDepth += tableDepthDecrement;
282
+ // create a new slice with the content of non-table block children and the depth of the nested tables subtracted
283
+ cleaned = new Slice(
284
+ node.content,
285
+ slice.openStart - descendedDepth - tableDepthDecrement,
286
+ slice.openEnd - descendedDepth - tableDepthDecrement,
287
+ );
288
+ return false;
289
+ }
290
+ });
291
+ }
292
+
293
+ if (!cleaned.eq(slice)) {
294
+ return cleaned;
297
295
  }
298
296
  }
299
297
 
@@ -771,7 +771,7 @@ const tablePlugin: TablePlugin = ({ config: options, api }) => {
771
771
  getDomRefFromSelection(
772
772
  editorView,
773
773
  ACTION_SUBJECT_ID.PICKER_TABLE_SIZE,
774
- api?.analytics?.actions.fireAnalyticsEvent,
774
+ api?.analytics?.actions,
775
775
  )
776
776
  }
777
777
  popupsBoundariesElement={popupsBoundariesElement}
@@ -7,12 +7,11 @@ import {
7
7
  GetEditorContainerWidth,
8
8
  GetEditorFeatureFlags,
9
9
  } from '@atlaskit/editor-common/types';
10
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
11
10
  import { EditorView } from '@atlaskit/editor-prosemirror/view';
12
11
  import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
12
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
13
13
 
14
14
  import { TablePlugin, TablePluginOptions } from '../tablePluginType';
15
- import { TableSharedStateInternal } from '../types';
16
15
 
17
16
  import FloatingContextualButton from './FloatingContextualButton';
18
17
  import FloatingContextualMenu from './FloatingContextualMenu';
@@ -23,19 +22,9 @@ import FloatingDragMenu from './FloatingDragMenu';
23
22
  import FloatingInsertButton from './FloatingInsertButton';
24
23
  import { FloatingToolbarLabel } from './FloatingToolbarLabel/FloatingToolbarLabel';
25
24
  import { GlobalStylesWrapper } from './global-styles';
25
+ import { useInternalTablePluginStateSelector } from './hooks/useInternalTablePluginStateSelector';
26
26
  import { FullWidthDisplay } from './TableFullWidthLabel';
27
27
 
28
- const useSharedTablePluginStateSelector = <K extends keyof TableSharedStateInternal>(
29
- api: ExtractInjectionAPI<TablePlugin> | undefined,
30
- key: K,
31
- ) => {
32
- const value = useSharedPluginStateSelector(
33
- api,
34
- `table.${key}` as never,
35
- ) as TableSharedStateInternal[K];
36
- return value;
37
- };
38
-
39
28
  export type ContentComponentProps = {
40
29
  api: ExtractInjectionAPI<TablePlugin> | undefined;
41
30
  editorView: EditorView;
@@ -62,35 +51,82 @@ const ContentComponentInternal = ({
62
51
  const editorAnalyticsAPI = api?.analytics?.actions;
63
52
  const ariaNotifyPlugin = api?.accessibilityUtils?.actions.ariaNotify;
64
53
 
65
- const resizingTableLocalId = useSharedTablePluginStateSelector(api, 'resizingTableLocalId');
66
- const resizingTableRef = useSharedTablePluginStateSelector(api, 'resizingTableRef');
67
- const isTableResizing = useSharedTablePluginStateSelector(api, 'isTableResizing');
68
- const isResizing = useSharedTablePluginStateSelector(api, 'isResizing');
69
- const widthToWidest = useSharedTablePluginStateSelector(api, 'widthToWidest');
54
+ const resizingTableLocalId = useInternalTablePluginStateSelector(api, 'resizingTableLocalId', {
55
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
56
+ });
57
+ const resizingTableRef = useInternalTablePluginStateSelector(api, 'resizingTableRef', {
58
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
59
+ });
60
+ const isTableResizing = useInternalTablePluginStateSelector(api, 'isTableResizing', {
61
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
62
+ });
63
+ const isResizing = useInternalTablePluginStateSelector(api, 'isResizing', {
64
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
65
+ });
66
+ const widthToWidest = useInternalTablePluginStateSelector(api, 'widthToWidest', {
67
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
68
+ });
70
69
 
71
- const tableNode = useSharedTablePluginStateSelector(api, 'tableNode');
72
- const targetCellPosition = useSharedTablePluginStateSelector(api, 'targetCellPosition');
73
- const isContextualMenuOpen = useSharedTablePluginStateSelector(api, 'isContextualMenuOpen');
74
- const tableRef = useSharedTablePluginStateSelector(api, 'tableRef');
75
- const pluginConfig = useSharedTablePluginStateSelector(api, 'pluginConfig');
76
- const insertColumnButtonIndex = useSharedTablePluginStateSelector(api, 'insertColumnButtonIndex');
77
- const insertRowButtonIndex = useSharedTablePluginStateSelector(api, 'insertRowButtonIndex');
78
- const isHeaderColumnEnabled = useSharedTablePluginStateSelector(api, 'isHeaderColumnEnabled');
79
- const isHeaderRowEnabled = useSharedTablePluginStateSelector(api, 'isHeaderRowEnabled');
80
- const isDragAndDropEnabled = useSharedTablePluginStateSelector(api, 'isDragAndDropEnabled');
81
- const tableWrapperTarget = useSharedTablePluginStateSelector(api, 'tableWrapperTarget');
82
- const isCellMenuOpenByKeyboard = useSharedTablePluginStateSelector(
70
+ const tableNode = useInternalTablePluginStateSelector(api, 'tableNode', {
71
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
72
+ });
73
+ const targetCellPosition = useInternalTablePluginStateSelector(api, 'targetCellPosition', {
74
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
75
+ });
76
+ const isContextualMenuOpen = useInternalTablePluginStateSelector(api, 'isContextualMenuOpen', {
77
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
78
+ });
79
+ const tableRef = useInternalTablePluginStateSelector(api, 'tableRef', {
80
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
81
+ });
82
+ const pluginConfig = useInternalTablePluginStateSelector(api, 'pluginConfig', {
83
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
84
+ });
85
+ const insertColumnButtonIndex = useInternalTablePluginStateSelector(
86
+ api,
87
+ 'insertColumnButtonIndex',
88
+ {
89
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
90
+ },
91
+ );
92
+ const insertRowButtonIndex = useInternalTablePluginStateSelector(api, 'insertRowButtonIndex', {
93
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
94
+ });
95
+ const isHeaderColumnEnabled = useInternalTablePluginStateSelector(api, 'isHeaderColumnEnabled', {
96
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
97
+ });
98
+ const isHeaderRowEnabled = useInternalTablePluginStateSelector(api, 'isHeaderRowEnabled', {
99
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
100
+ });
101
+ const isDragAndDropEnabled = useInternalTablePluginStateSelector(api, 'isDragAndDropEnabled', {
102
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
103
+ });
104
+ const tableWrapperTarget = useInternalTablePluginStateSelector(api, 'tableWrapperTarget', {
105
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
106
+ });
107
+ const isCellMenuOpenByKeyboard = useInternalTablePluginStateSelector(
83
108
  api,
84
109
  'isCellMenuOpenByKeyboard',
110
+ {
111
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
112
+ },
85
113
  );
86
114
 
87
- const { allowControls } = pluginConfig;
115
+ const { allowControls } = pluginConfig ?? {};
88
116
 
89
- const stickyHeader = useSharedTablePluginStateSelector(api, 'stickyHeader');
117
+ const stickyHeader = useInternalTablePluginStateSelector(api, 'stickyHeader', {
118
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
119
+ });
90
120
 
91
- const dragMenuDirection = useSharedTablePluginStateSelector(api, 'dragMenuDirection');
92
- const dragMenuIndex = useSharedTablePluginStateSelector(api, 'dragMenuIndex');
93
- const isDragMenuOpen = useSharedTablePluginStateSelector(api, 'isDragMenuOpen');
121
+ const dragMenuDirection = useInternalTablePluginStateSelector(api, 'dragMenuDirection', {
122
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
123
+ });
124
+ const dragMenuIndex = useInternalTablePluginStateSelector(api, 'dragMenuIndex', {
125
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
126
+ });
127
+ const isDragMenuOpen = useInternalTablePluginStateSelector(api, 'isDragMenuOpen', {
128
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
129
+ });
94
130
 
95
131
  return (
96
132
  <>
@@ -11,7 +11,6 @@ import { browser } from '@atlaskit/editor-common/browser';
11
11
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
12
12
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
13
13
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
14
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
15
14
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
16
15
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
17
16
  import { findTable, TableMap } from '@atlaskit/editor-tables';
@@ -32,6 +31,7 @@ import { TableCssClassName as ClassName } from '../../types';
32
31
  import type { CellHoverMeta, TableDirection, TableSharedStateInternal } from '../../types';
33
32
  import { dragTableInsertColumnButtonSize } from '../consts';
34
33
  import { DragPreview } from '../DragPreview';
34
+ import { useInternalTablePluginStateSelector } from '../hooks/useInternalTablePluginStateSelector';
35
35
 
36
36
  import { HandleIconComponent } from './HandleIconComponent';
37
37
 
@@ -336,21 +336,17 @@ const DragHandleComponentWithSharedState = ({
336
336
  };
337
337
 
338
338
  // hoveredColumns
339
- const hoveredColumnsSelector = useSharedPluginStateSelector(
340
- api,
341
- 'table.hoveredColumns' as never,
342
- {
343
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
344
- },
345
- ) as TableSharedStateInternal['hoveredColumns'];
339
+ const hoveredColumnsSelector = useInternalTablePluginStateSelector(api, 'hoveredColumns', {
340
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
341
+ });
346
342
  const hoveredColumns = editorExperiment('platform_editor_usesharedpluginstateselector', true)
347
343
  ? hoveredColumnsSelector
348
344
  : tableState?.hoveredColumns;
349
345
 
350
346
  // hoveredRows
351
- const hoveredRowsSelector = useSharedPluginStateSelector(api, 'table.hoveredRows' as never, {
347
+ const hoveredRowsSelector = useInternalTablePluginStateSelector(api, 'hoveredRows', {
352
348
  disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
353
- }) as TableSharedStateInternal['hoveredRows'];
349
+ });
354
350
  const hoveredRows = editorExperiment('platform_editor_usesharedpluginstateselector', true)
355
351
  ? hoveredRowsSelector
356
352
  : tableState?.hoveredRows;
@@ -0,0 +1,36 @@
1
+ import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
3
+
4
+ import { TablePlugin } from '../../tablePluginType';
5
+ import { TableSharedStateInternal } from '../../types';
6
+
7
+ type Options = {
8
+ disabled?: boolean;
9
+ };
10
+
11
+ /**
12
+ * **This hook is only for internal use and should not be used outside of the table plugin.**
13
+ *
14
+ * Hook to select a value from the internal table plugin state.
15
+ * This is a wrapper around `useSharedPluginStateSelector` to provide access to the entire
16
+ * `TableSharedStateInternal` type. Since tables plugin has a lot of internal state that is not
17
+ * exposed via the `TableSharedState` type, we need to use this hook to access it in a type safe way.
18
+ *
19
+ * @param api The editor API
20
+ * @param key Key of TableSharedStateInternal to select
21
+ * @returns
22
+ */
23
+ export const useInternalTablePluginStateSelector = <K extends keyof TableSharedStateInternal>(
24
+ api: ExtractInjectionAPI<TablePlugin> | undefined,
25
+ key: K,
26
+ options?: Options,
27
+ ): TableSharedStateInternal[K] | undefined => {
28
+ // Need to disable the eslint rule here because the key is for the TableSharedStateInternal type
29
+ // and we are using it as a string to access the value in the useSharedPluginStateSelector
30
+ // which is typed only for the public TableSharedState type.
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
+ const value = useSharedPluginStateSelector(api, `table.${key}` as any, options) as
33
+ | TableSharedStateInternal[K]
34
+ | undefined;
35
+ return value;
36
+ };