@atlaskit/editor-plugin-table 11.0.3 → 11.1.1

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 (56) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/afm-jira/tsconfig.json +3 -0
  4. package/afm-post-office/tsconfig.json +3 -0
  5. package/dist/cjs/nodeviews/TableComponent.js +59 -2
  6. package/dist/cjs/nodeviews/TableComponentWithSharedState.js +52 -38
  7. package/dist/cjs/nodeviews/TableContainer.js +39 -24
  8. package/dist/cjs/nodeviews/TableResizer.js +13 -8
  9. package/dist/cjs/tablePlugin.js +9 -4
  10. package/dist/cjs/ui/DragHandle/index.js +11 -5
  11. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +9 -4
  12. package/dist/cjs/ui/TableFloatingControls/CornerControls/DragCornerControls.js +10 -5
  13. package/dist/cjs/ui/TableFloatingControls/FloatingControlsWithSelection.js +10 -5
  14. package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +10 -5
  15. package/dist/cjs/ui/global-styles.js +9 -4
  16. package/dist/cjs/ui/icons/SortingIconWrapper.js +9 -4
  17. package/dist/es2019/nodeviews/TableComponent.js +57 -2
  18. package/dist/es2019/nodeviews/TableComponentWithSharedState.js +47 -32
  19. package/dist/es2019/nodeviews/TableContainer.js +33 -18
  20. package/dist/es2019/nodeviews/TableResizer.js +14 -8
  21. package/dist/es2019/tablePlugin.js +9 -3
  22. package/dist/es2019/ui/DragHandle/index.js +11 -4
  23. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +9 -3
  24. package/dist/es2019/ui/TableFloatingControls/CornerControls/DragCornerControls.js +10 -4
  25. package/dist/es2019/ui/TableFloatingControls/FloatingControlsWithSelection.js +10 -4
  26. package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +10 -4
  27. package/dist/es2019/ui/global-styles.js +9 -3
  28. package/dist/es2019/ui/icons/SortingIconWrapper.js +9 -3
  29. package/dist/esm/nodeviews/TableComponent.js +60 -2
  30. package/dist/esm/nodeviews/TableComponentWithSharedState.js +53 -39
  31. package/dist/esm/nodeviews/TableContainer.js +40 -25
  32. package/dist/esm/nodeviews/TableResizer.js +14 -9
  33. package/dist/esm/tablePlugin.js +10 -5
  34. package/dist/esm/ui/DragHandle/index.js +12 -6
  35. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +10 -5
  36. package/dist/esm/ui/TableFloatingControls/CornerControls/DragCornerControls.js +11 -6
  37. package/dist/esm/ui/TableFloatingControls/FloatingControlsWithSelection.js +11 -6
  38. package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +11 -6
  39. package/dist/esm/ui/global-styles.js +10 -5
  40. package/dist/esm/ui/icons/SortingIconWrapper.js +10 -5
  41. package/dist/types/ui/hooks/useInternalTablePluginStateSelector.d.ts +1 -1
  42. package/dist/types-ts4.5/ui/hooks/useInternalTablePluginStateSelector.d.ts +1 -1
  43. package/package.json +5 -4
  44. package/src/nodeviews/TableComponent.tsx +62 -0
  45. package/src/nodeviews/TableComponentWithSharedState.tsx +62 -32
  46. package/src/nodeviews/TableContainer.tsx +40 -25
  47. package/src/nodeviews/TableResizer.tsx +10 -7
  48. package/src/tablePlugin.tsx +4 -2
  49. package/src/ui/DragHandle/index.tsx +9 -3
  50. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +4 -2
  51. package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +5 -3
  52. package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +5 -3
  53. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +5 -3
  54. package/src/ui/global-styles.tsx +4 -2
  55. package/src/ui/icons/SortingIconWrapper.tsx +4 -2
  56. package/tsconfig.app.json +3 -0
@@ -1,15 +1,20 @@
1
1
  import React from 'react';
2
- import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
2
+ import { sharedPluginStateHookMigratorFactory, useSharedPluginState, useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
3
3
  import { SortingIcon } from '@atlaskit/editor-common/table';
4
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
5
4
  var useSharedState = sharedPluginStateHookMigratorFactory(function (api) {
6
- var mode = useSharedPluginStateSelector(api, 'editorViewMode.mode');
5
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['editorViewMode'], function (states) {
6
+ var _states$editorViewMod;
7
+ return {
8
+ mode: (_states$editorViewMod = states.editorViewModeState) === null || _states$editorViewMod === void 0 ? void 0 : _states$editorViewMod.mode
9
+ };
10
+ }),
11
+ mode = _useSharedPluginState.mode;
7
12
  return {
8
13
  mode: mode
9
14
  };
10
15
  }, function (api) {
11
- var _useSharedPluginState = useSharedPluginState(api, ['editorViewMode']),
12
- editorViewModeState = _useSharedPluginState.editorViewModeState;
16
+ var _useSharedPluginState2 = useSharedPluginState(api, ['editorViewMode']),
17
+ editorViewModeState = _useSharedPluginState2.editorViewModeState;
13
18
  return {
14
19
  mode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode
15
20
  };
@@ -18,5 +18,5 @@ type Options = {
18
18
  * @returns
19
19
  * @example
20
20
  */
21
- 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" | "isSizeSelectorOpen" | "sizeSelectorTargetRef">(api: ExtractInjectionAPI<TablePlugin> | undefined, key: K, options?: Options) => TableSharedStateInternal[K] | undefined;
21
+ 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" | "stickyHeader" | "isTableResizing" | "resizingTableRef" | "resizingTableLocalId" | "isSizeSelectorOpen" | "sizeSelectorTargetRef">(api: ExtractInjectionAPI<TablePlugin> | undefined, key: K, options?: Options) => TableSharedStateInternal[K] | undefined;
22
22
  export {};
@@ -18,5 +18,5 @@ type Options = {
18
18
  * @returns
19
19
  * @example
20
20
  */
21
- 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" | "isSizeSelectorOpen" | "sizeSelectorTargetRef">(api: ExtractInjectionAPI<TablePlugin> | undefined, key: K, options?: Options) => TableSharedStateInternal[K] | undefined;
21
+ 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" | "stickyHeader" | "isTableResizing" | "resizingTableRef" | "resizingTableLocalId" | "isSizeSelectorOpen" | "sizeSelectorTargetRef">(api: ExtractInjectionAPI<TablePlugin> | undefined, key: K, options?: Options) => TableSharedStateInternal[K] | undefined;
22
22
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "11.0.3",
3
+ "version": "11.1.1",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -28,7 +28,7 @@
28
28
  "singleton": true
29
29
  },
30
30
  "dependencies": {
31
- "@atlaskit/adf-schema": "^47.6.0",
31
+ "@atlaskit/adf-schema": "^49.0.5",
32
32
  "@atlaskit/button": "^23.2.0",
33
33
  "@atlaskit/custom-steps": "^0.11.0",
34
34
  "@atlaskit/editor-palette": "^2.1.0",
@@ -52,10 +52,11 @@
52
52
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^2.1.0",
53
53
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.1.0",
54
54
  "@atlaskit/primitives": "^14.10.0",
55
+ "@atlaskit/react-ufo": "^3.14.0",
55
56
  "@atlaskit/theme": "^19.0.0",
56
- "@atlaskit/tmp-editor-statsig": "^9.1.0",
57
+ "@atlaskit/tmp-editor-statsig": "^9.5.0",
57
58
  "@atlaskit/toggle": "^15.0.0",
58
- "@atlaskit/tokens": "^5.4.0",
59
+ "@atlaskit/tokens": "^5.5.0",
59
60
  "@atlaskit/tooltip": "^20.3.0",
60
61
  "@babel/runtime": "^7.0.0",
61
62
  "@emotion/react": "^11.7.1",
@@ -29,6 +29,8 @@ import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
29
29
  import { fg } from '@atlaskit/platform-feature-flags';
30
30
  import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
31
31
  import type { CleanupFn } from '@atlaskit/pragmatic-drag-and-drop/types';
32
+ import UFOLoadHold from '@atlaskit/react-ufo/load-hold';
33
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
32
34
  import { token } from '@atlaskit/tokens';
33
35
 
34
36
  import { autoSizeTable, clearHoverSelection } from '../pm-plugins/commands';
@@ -146,6 +148,17 @@ interface TableState {
146
148
  tableWrapperHeight?: number;
147
149
  }
148
150
 
151
+ // Generate a unique ID to prevent collisions when multiple plugin versions exist on the same page
152
+ const generateUniqueTableId = () => {
153
+ // Use crypto.randomUUID() if available, fallback to Math.random() based approach
154
+ if (!globalThis.crypto || typeof globalThis.crypto.randomUUID !== 'function') {
155
+ // Fallback: for older environments (IE).
156
+ // Not the best fallback, but the crypto.randomUUID is widely available
157
+ return (Math.random() + 1).toString(36).substring(20);
158
+ }
159
+ return crypto.randomUUID();
160
+ };
161
+
149
162
  // Ignored via go/ees005
150
163
  // eslint-disable-next-line @repo/internal/react/no-class-components
151
164
  class TableComponent extends React.Component<ComponentProps, TableState> {
@@ -182,6 +195,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
182
195
 
183
196
  private dragAndDropCleanupFn?: CleanupFn;
184
197
  private nodeVisibilityObserverCleanupFn?: CleanupFn;
198
+ private holdCompleted = false;
199
+ private dispatchEventName = `tableResized-${generateUniqueTableId()}`;
185
200
 
186
201
  constructor(props: ComponentProps) {
187
202
  super(props);
@@ -606,6 +621,16 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
606
621
  shouldScaleOnColgroupUpdate,
607
622
  scalePercent,
608
623
  );
624
+
625
+ if (expValEquals('cc_editor_ufo_hold_table_till_resize_complete', 'isEnabled', true)) {
626
+ // Mark table as updated for TableHold component (if no table exists yet, the colgroup update will not have done anything)
627
+ if (this.table && !this.holdCompleted) {
628
+ const customTableResizedEvent = new CustomEvent(this.dispatchEventName);
629
+
630
+ document.dispatchEvent(customTableResizedEvent);
631
+ this.holdCompleted = true;
632
+ }
633
+ }
609
634
  });
610
635
  }
611
636
  }
@@ -989,6 +1014,9 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
989
1014
  isCommentEditor={options?.isCommentEditor}
990
1015
  isChromelessEditor={options?.isChromelessEditor}
991
1016
  >
1017
+ {expValEquals('cc_editor_ufo_hold_table_till_resize_complete', 'isEnabled', true) ? (
1018
+ <TableHold dispatchEventName={this.dispatchEventName} />
1019
+ ) : null}
992
1020
  <div
993
1021
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
994
1022
  className={ClassName.TABLE_STICKY_SENTINEL_TOP}
@@ -1431,3 +1459,37 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
1431
1459
  }
1432
1460
 
1433
1461
  export default injectIntl(TableComponent);
1462
+
1463
+ /**
1464
+ * This is needed because of how currently the table is resized post client boot up with code that exists outside react
1465
+ *
1466
+ * This can be deleted once https://home.atlassian.com/o/2346a038-3c8c-498b-a79b-e7847859868d/s/a436116f-02ce-4520-8fbb-7301462a1674/project/ATLAS-97756/updates
1467
+ * is rolled out (and doesn't need to be used in the test arm of that change).
1468
+ */
1469
+ const TableHold = React.memo(function TableHold({
1470
+ dispatchEventName,
1471
+ }: {
1472
+ dispatchEventName: string;
1473
+ }) {
1474
+ const [tableUpdateConfirmed, setTableUpdateConfirmed] = React.useState(false);
1475
+
1476
+ React.useEffect(() => {
1477
+ const customEventListener = () => {
1478
+ setTableUpdateConfirmed(true);
1479
+ };
1480
+
1481
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
1482
+ document.addEventListener(dispatchEventName, customEventListener);
1483
+
1484
+ return () => {
1485
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
1486
+ document.removeEventListener(dispatchEventName, customEventListener);
1487
+ };
1488
+ }, [dispatchEventName]);
1489
+
1490
+ if (tableUpdateConfirmed === false) {
1491
+ return <UFOLoadHold name="editor_table_resize" />;
1492
+ }
1493
+
1494
+ return null;
1495
+ });
@@ -3,18 +3,23 @@ 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 {
6
+ type NamedPluginStatesFromInjectionAPI,
6
7
  sharedPluginStateHookMigratorFactory,
7
8
  useSharedPluginState,
9
+ useSharedPluginStateWithSelector,
8
10
  } from '@atlaskit/editor-common/hooks';
9
- import type { GetEditorFeatureFlags, getPosHandlerNode } from '@atlaskit/editor-common/types';
10
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
11
+ import type {
12
+ ExtractInjectionAPI,
13
+ GetEditorFeatureFlags,
14
+ getPosHandlerNode,
15
+ } from '@atlaskit/editor-common/types';
11
16
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
12
17
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
13
18
  import { findTable } from '@atlaskit/editor-tables';
14
19
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
15
20
 
21
+ import type tablePlugin from '../tablePlugin';
16
22
  import type { PluginInjectionAPI, TableSharedStateInternal } from '../types';
17
- import { useInternalTablePluginStateSelector } from '../ui/hooks/useInternalTablePluginStateSelector';
18
23
 
19
24
  import TableComponent from './TableComponent';
20
25
  import type { TableOptions } from './types';
@@ -41,35 +46,60 @@ type TableComponentWithSharedStateProps = {
41
46
 
42
47
  const useSharedState = sharedPluginStateHookMigratorFactory(
43
48
  (api: PluginInjectionAPI | undefined) => {
44
- // tableState
45
- const isTableResizing = useInternalTablePluginStateSelector(api, 'isTableResizing');
46
- const isHeaderColumnEnabled = useInternalTablePluginStateSelector(api, 'isHeaderColumnEnabled');
47
- const isHeaderRowEnabled = useInternalTablePluginStateSelector(api, 'isHeaderRowEnabled');
48
- const ordering = useInternalTablePluginStateSelector(api, 'ordering');
49
- const isResizing = useInternalTablePluginStateSelector(api, 'isResizing');
50
- const isInDanger = useInternalTablePluginStateSelector(api, 'isInDanger');
51
- const hoveredCell = useInternalTablePluginStateSelector(api, 'hoveredCell');
52
- const hoveredRows = useInternalTablePluginStateSelector(api, 'hoveredRows');
53
- const isTableHovered = useInternalTablePluginStateSelector(api, 'isTableHovered');
54
- const isWholeTableInDanger = useInternalTablePluginStateSelector(api, 'isWholeTableInDanger');
55
- // Required so that table controls re-renders
56
- useInternalTablePluginStateSelector(api, 'targetCellPosition');
57
-
58
- // mediaState
59
- const isFullscreen = useSharedPluginStateSelector(api, 'media.isFullscreen');
60
-
61
- // selectionState
62
- const selection = useSharedPluginStateSelector(api, 'selection.selection');
63
-
64
- // editorViewModeState
65
- const mode = useSharedPluginStateSelector(api, 'editorViewMode.mode');
66
-
67
- // widthState
68
- const width = useSharedPluginStateSelector(api, 'width.width');
69
- const lineLength = useSharedPluginStateSelector(api, 'width.lineLength');
70
-
71
- // interactionState
72
- const interaction = useSharedPluginStateSelector(api, 'interaction.interactionState');
49
+ const {
50
+ isTableResizing,
51
+ isHeaderColumnEnabled,
52
+ isHeaderRowEnabled,
53
+ ordering,
54
+ isResizing,
55
+ isInDanger,
56
+ hoveredCell,
57
+ hoveredRows,
58
+ isTableHovered,
59
+ isWholeTableInDanger,
60
+ interaction,
61
+ isFullscreen,
62
+ lineLength,
63
+ mode,
64
+ selection,
65
+ width,
66
+ } = useSharedPluginStateWithSelector(
67
+ api,
68
+ ['table', 'width', 'media', 'selection', 'editorViewMode', 'interaction'],
69
+ (
70
+ states: NamedPluginStatesFromInjectionAPI<
71
+ ExtractInjectionAPI<typeof tablePlugin>,
72
+ 'width' | 'media' | 'selection' | 'editorViewMode' | 'interaction'
73
+ > & {
74
+ tableState: TableSharedStateInternal | undefined;
75
+ },
76
+ ) => ({
77
+ // tableState
78
+ isTableResizing: states.tableState?.isTableResizing,
79
+ isHeaderColumnEnabled: states.tableState?.isHeaderColumnEnabled,
80
+ isHeaderRowEnabled: states.tableState?.isHeaderRowEnabled,
81
+ ordering: states.tableState?.ordering,
82
+ isResizing: states.tableState?.isResizing,
83
+ isInDanger: states.tableState?.isInDanger,
84
+ hoveredCell: states.tableState?.hoveredCell,
85
+ hoveredRows: states.tableState?.hoveredRows,
86
+ isTableHovered: states.tableState?.isTableHovered,
87
+ isWholeTableInDanger: states.tableState?.isWholeTableInDanger,
88
+ // Required so that table control re-renders
89
+ targetCellPosition: states.tableState?.targetCellPosition,
90
+ // mediaState
91
+ isFullscreen: states.mediaState?.isFullscreen,
92
+ // selectionState
93
+ selection: states.selectionState?.selection,
94
+ // editorViewModeState
95
+ mode: states.editorViewModeState?.mode,
96
+ // widthState
97
+ width: states.widthState?.width,
98
+ lineLength: states.widthState?.lineLength,
99
+ // interactionState
100
+ interaction: states.interactionState?.interactionState,
101
+ }),
102
+ );
73
103
 
74
104
  return {
75
105
  tableState: undefined,
@@ -10,12 +10,13 @@ import {
10
10
  } from '@atlaskit/editor-common/analytics';
11
11
  import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
12
12
  import {
13
+ type NamedPluginStatesFromInjectionAPI,
13
14
  sharedPluginStateHookMigratorFactory,
14
15
  useSharedPluginState,
16
+ useSharedPluginStateWithSelector,
15
17
  } from '@atlaskit/editor-common/hooks';
16
18
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
17
- import type { EditorContainerWidth } from '@atlaskit/editor-common/types';
18
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
19
+ import type { EditorContainerWidth, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
19
20
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
20
21
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
21
22
  import {
@@ -33,7 +34,8 @@ import {
33
34
  TABLE_OFFSET_IN_COMMENT_EDITOR,
34
35
  } from '../pm-plugins/table-resizing/utils/consts';
35
36
  import { ALIGN_CENTER, ALIGN_START } from '../pm-plugins/utils/alignment';
36
- import type { PluginInjectionAPI } from '../types';
37
+ import type tablePlugin from '../tablePlugin';
38
+ import type { PluginInjectionAPI, TableSharedStateInternal } from '../types';
37
39
  import { TableCssClassName as ClassName } from '../types';
38
40
 
39
41
  import { getAlignmentStyle } from './table-container-styles';
@@ -74,15 +76,15 @@ type AlignmentTableContainerProps = {
74
76
  editorView?: EditorView;
75
77
  };
76
78
 
77
- const useAlignmentStableContainerSharedState = sharedPluginStateHookMigratorFactory(
79
+ const useAlignmentTableContainerSharedState = sharedPluginStateHookMigratorFactory(
78
80
  (pluginInjectionApi: PluginInjectionAPI | undefined) => {
79
- const isFullWidthModeEnabled = useSharedPluginStateSelector(
81
+ const { isFullWidthModeEnabled, wasFullWidthModeEnabled } = useSharedPluginStateWithSelector(
80
82
  pluginInjectionApi,
81
- 'table.isFullWidthModeEnabled',
82
- );
83
- const wasFullWidthModeEnabled = useSharedPluginStateSelector(
84
- pluginInjectionApi,
85
- 'table.wasFullWidthModeEnabled',
83
+ ['table'],
84
+ (states) => ({
85
+ isFullWidthModeEnabled: states.tableState?.isFullWidthModeEnabled,
86
+ wasFullWidthModeEnabled: states.tableState?.wasFullWidthModeEnabled,
87
+ }),
86
88
  );
87
89
  return {
88
90
  tableState: undefined,
@@ -109,7 +111,7 @@ const AlignmentTableContainer = ({
109
111
  }: PropsWithChildren<AlignmentTableContainerProps>) => {
110
112
  const alignment = node.attrs.layout !== ALIGN_START ? ALIGN_CENTER : ALIGN_START;
111
113
  const { tableState, isFullWidthModeEnabled, wasFullWidthModeEnabled } =
112
- useAlignmentStableContainerSharedState(pluginInjectionApi);
114
+ useAlignmentTableContainerSharedState(pluginInjectionApi);
113
115
 
114
116
  useEffect(() => {
115
117
  if (!tableState && editorExperiment('platform_editor_usesharedpluginstateselector', false)) {
@@ -214,26 +216,38 @@ type ResizableTableContainerProps = {
214
216
  isCommentEditor?: boolean;
215
217
  };
216
218
 
217
- const useResizeableTableContainerSharedState = sharedPluginStateHookMigratorFactory(
218
- (pluginInjectionApi: PluginInjectionAPI | undefined) => {
219
- const isFullWidthModeEnabled = useSharedPluginStateSelector(
220
- pluginInjectionApi,
221
- 'table.isFullWidthModeEnabled',
219
+ const selector = (
220
+ states: NamedPluginStatesFromInjectionAPI<
221
+ ExtractInjectionAPI<typeof tablePlugin>,
222
+ 'editorViewMode'
223
+ > & {
224
+ tableState: TableSharedStateInternal | undefined;
225
+ },
226
+ ) => ({
227
+ tableState: states.tableState,
228
+ editorViewModeState: states.editorViewModeState,
229
+ });
230
+
231
+ const useSharedState = sharedPluginStateHookMigratorFactory(
232
+ (api: PluginInjectionAPI | undefined) => {
233
+ const { tableState, editorViewModeState } = useSharedPluginStateWithSelector(
234
+ api,
235
+ ['table', 'editorViewMode'],
236
+ selector,
222
237
  );
223
- const mode = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.mode');
224
238
  return {
225
- isFullWidthModeEnabled,
226
- mode,
239
+ tableState,
240
+ editorViewModeState,
227
241
  };
228
242
  },
229
- (pluginInjectionApi: PluginInjectionAPI | undefined) => {
230
- const { tableState, editorViewModeState } = useSharedPluginState(pluginInjectionApi, [
243
+ (api: PluginInjectionAPI | undefined) => {
244
+ const { tableState, editorViewModeState } = useSharedPluginState(api, [
231
245
  'table',
232
246
  'editorViewMode',
233
247
  ]);
234
248
  return {
235
- isFullWidthModeEnabled: tableState?.isFullWidthModeEnabled,
236
- mode: editorViewModeState?.mode,
249
+ tableState,
250
+ editorViewModeState,
237
251
  };
238
252
  },
239
253
  );
@@ -262,8 +276,9 @@ export const ResizableTableContainer = React.memo(
262
276
  const tableWidthRef = useRef<number>(akEditorDefaultLayoutWidth);
263
277
  const [resizing, setIsResizing] = useState(false);
264
278
 
265
- const { isFullWidthModeEnabled, mode } =
266
- useResizeableTableContainerSharedState(pluginInjectionApi);
279
+ const { tableState, editorViewModeState } = useSharedState(pluginInjectionApi);
280
+ const isFullWidthModeEnabled = tableState?.isFullWidthModeEnabled;
281
+ const mode = editorViewModeState?.mode;
267
282
 
268
283
  const updateContainerHeight = useCallback((height: number | 'auto') => {
269
284
  // current StickyHeader State is not stable to be fetch.
@@ -16,6 +16,7 @@ import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
16
16
  import {
17
17
  sharedPluginStateHookMigratorFactory,
18
18
  useSharedPluginState,
19
+ useSharedPluginStateWithSelector,
19
20
  } from '@atlaskit/editor-common/hooks';
20
21
  import { focusTableResizer, ToolTipContent } from '@atlaskit/editor-common/keymaps';
21
22
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
@@ -72,7 +73,6 @@ import {
72
73
  TABLE_HIGHLIGHT_TOLERANCE,
73
74
  TABLE_SNAP_GAP,
74
75
  } from '../ui/consts';
75
- import { useInternalTablePluginStateSelector } from '../ui/hooks/useInternalTablePluginStateSelector';
76
76
 
77
77
  interface TableResizerProps {
78
78
  width: number;
@@ -185,18 +185,21 @@ const getVisibleGuidelines = (
185
185
  });
186
186
  };
187
187
 
188
+ const selector = (states: { tableState: TableSharedStateInternal | undefined }) => ({
189
+ widthToWidest: (states.tableState as TableSharedStateInternal | undefined)?.widthToWidest,
190
+ });
191
+
188
192
  const useSharedState = sharedPluginStateHookMigratorFactory(
189
- (pluginInjectionApi: PluginInjectionAPI | undefined) => {
190
- const widthToWidest = useInternalTablePluginStateSelector(pluginInjectionApi, 'widthToWidest');
193
+ (api: PluginInjectionAPI | undefined) => {
194
+ const { widthToWidest } = useSharedPluginStateWithSelector(api, ['table'], selector);
191
195
  return {
192
196
  widthToWidest,
193
197
  };
194
198
  },
195
- (pluginInjectionApi: PluginInjectionAPI | undefined) => {
196
- const { tableState } = useSharedPluginState(pluginInjectionApi, ['table']);
197
- const tableStateInternal = tableState as TableSharedStateInternal;
199
+ (api: PluginInjectionAPI | undefined) => {
200
+ const { tableState } = useSharedPluginState(api, ['table']);
198
201
  return {
199
- widthToWidest: tableStateInternal.widthToWidest,
202
+ widthToWidest: (tableState as TableSharedStateInternal | undefined)?.widthToWidest,
200
203
  };
201
204
  },
202
205
  );
@@ -22,6 +22,7 @@ import { getDomRefFromSelection } from '@atlaskit/editor-common/get-dom-ref-from
22
22
  import {
23
23
  sharedPluginStateHookMigratorFactory,
24
24
  useSharedPluginState,
25
+ useSharedPluginStateWithSelector,
25
26
  } from '@atlaskit/editor-common/hooks';
26
27
  import { IconTable } from '@atlaskit/editor-common/icons';
27
28
  import { toggleTable, tooltip } from '@atlaskit/editor-common/keymaps';
@@ -39,7 +40,6 @@ import type {
39
40
  ExtractInjectionAPI,
40
41
  GetEditorContainerWidth,
41
42
  } from '@atlaskit/editor-common/types';
42
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
43
43
  import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
44
44
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
45
45
  import { hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
@@ -102,7 +102,9 @@ const defaultGetEditorFeatureFlags = () => ({});
102
102
 
103
103
  const useTableSharedState = sharedPluginStateHookMigratorFactory(
104
104
  (api: ExtractInjectionAPI<TablePlugin> | undefined) => {
105
- const mode = useSharedPluginStateSelector(api, 'editorViewMode.mode');
105
+ const { mode } = useSharedPluginStateWithSelector(api, ['editorViewMode'], (states) => ({
106
+ mode: states.editorViewModeState?.mode,
107
+ }));
106
108
  return { mode };
107
109
  },
108
110
  (api: ExtractInjectionAPI<TablePlugin> | undefined) => {
@@ -11,6 +11,7 @@ import { browser } from '@atlaskit/editor-common/browser';
11
11
  import {
12
12
  sharedPluginStateHookMigratorFactory,
13
13
  useSharedPluginState,
14
+ useSharedPluginStateWithSelector,
14
15
  } from '@atlaskit/editor-common/hooks';
15
16
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
16
17
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
@@ -33,7 +34,6 @@ import { TableCssClassName as ClassName } from '../../types';
33
34
  import type { CellHoverMeta, TableDirection, TableSharedStateInternal } from '../../types';
34
35
  import { dragTableInsertColumnButtonSize } from '../consts';
35
36
  import { DragPreview } from '../DragPreview';
36
- import { useInternalTablePluginStateSelector } from '../hooks/useInternalTablePluginStateSelector';
37
37
 
38
38
  import { HandleIconComponent } from './HandleIconComponent';
39
39
 
@@ -315,8 +315,14 @@ const DragHandleComponent = ({
315
315
 
316
316
  const useSharedState = sharedPluginStateHookMigratorFactory(
317
317
  (api: ExtractInjectionAPI<TablePlugin> | undefined) => {
318
- const hoveredColumns = useInternalTablePluginStateSelector(api, 'hoveredColumns');
319
- const hoveredRows = useInternalTablePluginStateSelector(api, 'hoveredRows');
318
+ const { hoveredColumns, hoveredRows } = useSharedPluginStateWithSelector(
319
+ api,
320
+ ['table'],
321
+ (states) => ({
322
+ hoveredColumns: (states.tableState as TableSharedStateInternal)?.hoveredColumns,
323
+ hoveredRows: (states.tableState as TableSharedStateInternal)?.hoveredRows,
324
+ }),
325
+ );
320
326
  return {
321
327
  hoveredColumns,
322
328
  hoveredRows,
@@ -5,10 +5,10 @@ import React, { useCallback, useMemo, useRef } from 'react';
5
5
  import {
6
6
  sharedPluginStateHookMigratorFactory,
7
7
  useSharedPluginState,
8
+ useSharedPluginStateWithSelector,
8
9
  } from '@atlaskit/editor-common/hooks';
9
10
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
10
11
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
11
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
12
12
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
13
13
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
14
14
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
@@ -64,7 +64,9 @@ const getSelectedColumns = (selection: Selection) => {
64
64
 
65
65
  const useSharedState = sharedPluginStateHookMigratorFactory(
66
66
  (api: ExtractInjectionAPI<TablePlugin> | undefined) => {
67
- const selection = useSharedPluginStateSelector(api, 'selection.selection');
67
+ const { selection } = useSharedPluginStateWithSelector(api, ['selection'], (states) => ({
68
+ selection: states.selectionState?.selection,
69
+ }));
68
70
  return {
69
71
  selection,
70
72
  };
@@ -7,10 +7,10 @@ import { injectIntl } from 'react-intl-next';
7
7
  import {
8
8
  sharedPluginStateHookMigratorFactory,
9
9
  useSharedPluginState,
10
+ useSharedPluginStateWithSelector,
10
11
  } from '@atlaskit/editor-common/hooks';
11
12
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
12
13
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
13
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
14
14
  import { findTable, isTableSelected, selectTable } from '@atlaskit/editor-tables/utils';
15
15
 
16
16
  import { clearHoverSelection } from '../../../pm-plugins/commands';
@@ -70,9 +70,11 @@ const DragCornerControlsComponent = ({
70
70
 
71
71
  const useSharedState = sharedPluginStateHookMigratorFactory(
72
72
  (api: ExtractInjectionAPI<TablePlugin> | undefined) => {
73
- const selectionsSelector = useSharedPluginStateSelector(api, 'selection.selection');
73
+ const { selection } = useSharedPluginStateWithSelector(api, ['selection'], (states) => ({
74
+ selection: states.selectionState?.selection,
75
+ }));
74
76
  return {
75
- selection: selectionsSelector,
77
+ selection,
76
78
  };
77
79
  },
78
80
  (api: ExtractInjectionAPI<TablePlugin> | undefined) => {
@@ -3,9 +3,9 @@ import React from 'react';
3
3
  import {
4
4
  sharedPluginStateHookMigratorFactory,
5
5
  useSharedPluginState,
6
+ useSharedPluginStateWithSelector,
6
7
  } from '@atlaskit/editor-common/hooks';
7
8
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
8
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
9
9
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
10
10
 
11
11
  import type { TablePlugin } from '../../tablePluginType';
@@ -30,9 +30,11 @@ type FloatingControlsWithSelectionProps = {
30
30
 
31
31
  const useSharedState = sharedPluginStateHookMigratorFactory(
32
32
  (api: ExtractInjectionAPI<TablePlugin> | undefined) => {
33
- const selectionsSelector = useSharedPluginStateSelector(api, 'selection.selection');
33
+ const { selection } = useSharedPluginStateWithSelector(api, ['selection'], (states) => ({
34
+ selection: states.selectionState?.selection,
35
+ }));
34
36
  return {
35
- selection: selectionsSelector,
37
+ selection,
36
38
  };
37
39
  },
38
40
  (api: ExtractInjectionAPI<TablePlugin> | undefined) => {
@@ -5,9 +5,9 @@ import React, { Fragment, useCallback, useEffect, useMemo, useState } from 'reac
5
5
  import {
6
6
  sharedPluginStateHookMigratorFactory,
7
7
  useSharedPluginState,
8
+ useSharedPluginStateWithSelector,
8
9
  } from '@atlaskit/editor-common/hooks';
9
10
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
10
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
11
11
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
12
12
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
13
13
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
@@ -375,9 +375,11 @@ export const DragControls = ({
375
375
 
376
376
  const useSharedState = sharedPluginStateHookMigratorFactory(
377
377
  (api: ExtractInjectionAPI<TablePlugin> | undefined) => {
378
- const selectionsSelector = useSharedPluginStateSelector(api, 'selection.selection');
378
+ const { selection } = useSharedPluginStateWithSelector(api, ['selection'], (states) => ({
379
+ selection: states.selectionState?.selection,
380
+ }));
379
381
  return {
380
- selection: selectionsSelector,
382
+ selection,
381
383
  };
382
384
  },
383
385
  (api: ExtractInjectionAPI<TablePlugin> | undefined) => {
@@ -8,9 +8,9 @@ import { Global, jsx } from '@emotion/react';
8
8
  import {
9
9
  sharedPluginStateHookMigratorFactory,
10
10
  useSharedPluginState,
11
+ useSharedPluginStateWithSelector,
11
12
  } from '@atlaskit/editor-common/hooks';
12
13
  import type { FeatureFlags } from '@atlaskit/editor-common/types';
13
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
14
14
 
15
15
  import type { PluginInjectionAPI } from '../types';
16
16
 
@@ -18,7 +18,9 @@ import { tableStyles } from './common-styles';
18
18
 
19
19
  const useSharedState = sharedPluginStateHookMigratorFactory(
20
20
  (api: PluginInjectionAPI | undefined) => {
21
- const mode = useSharedPluginStateSelector(api, 'editorViewMode.mode');
21
+ const { mode } = useSharedPluginStateWithSelector(api, ['editorViewMode'], (states) => ({
22
+ mode: states.editorViewModeState?.mode,
23
+ }));
22
24
  return {
23
25
  mode,
24
26
  };