@atlaskit/editor-plugin-table 10.8.2 → 10.9.0

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.
@@ -0,0 +1,172 @@
1
+ import React from 'react';
2
+ import { ACTION_SUBJECT } from '@atlaskit/editor-common/analytics';
3
+ import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
4
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
5
+ import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
6
+ import FloatingContextualButton from './FloatingContextualButton';
7
+ import FloatingContextualMenu from './FloatingContextualMenu';
8
+ import FloatingDeleteButton from './FloatingDeleteButton';
9
+ import FloatingDragMenu from './FloatingDragMenu';
10
+ // Ignored via go/ees005
11
+ // eslint-disable-next-line import/no-named-as-default
12
+ import FloatingInsertButton from './FloatingInsertButton';
13
+ import { FloatingToolbarLabel } from './FloatingToolbarLabel/FloatingToolbarLabel';
14
+ import { GlobalStylesWrapper } from './global-styles';
15
+ import { FullWidthDisplay } from './TableFullWidthLabel';
16
+ var useSharedTablePluginStateSelector = function useSharedTablePluginStateSelector(api, key) {
17
+ var value = useSharedPluginStateSelector(api, "table.".concat(key));
18
+ return value;
19
+ };
20
+ var ContentComponentInternal = function ContentComponentInternal(_ref) {
21
+ var _api$analytics, _api$accessibilityUti;
22
+ var api = _ref.api,
23
+ editorView = _ref.editorView,
24
+ dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
25
+ options = _ref.options,
26
+ popupsMountPoint = _ref.popupsMountPoint,
27
+ popupsBoundariesElement = _ref.popupsBoundariesElement,
28
+ popupsScrollableElement = _ref.popupsScrollableElement,
29
+ defaultGetEditorContainerWidth = _ref.defaultGetEditorContainerWidth,
30
+ defaultGetEditorFeatureFlags = _ref.defaultGetEditorFeatureFlags;
31
+ var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
32
+ var ariaNotifyPlugin = api === null || api === void 0 || (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 ? void 0 : _api$accessibilityUti.actions.ariaNotify;
33
+ var resizingTableLocalId = useSharedTablePluginStateSelector(api, 'resizingTableLocalId');
34
+ var resizingTableRef = useSharedTablePluginStateSelector(api, 'resizingTableRef');
35
+ var isTableResizing = useSharedTablePluginStateSelector(api, 'isTableResizing');
36
+ var isResizing = useSharedTablePluginStateSelector(api, 'isResizing');
37
+ var widthToWidest = useSharedTablePluginStateSelector(api, 'widthToWidest');
38
+ var tableNode = useSharedTablePluginStateSelector(api, 'tableNode');
39
+ var targetCellPosition = useSharedTablePluginStateSelector(api, 'targetCellPosition');
40
+ var isContextualMenuOpen = useSharedTablePluginStateSelector(api, 'isContextualMenuOpen');
41
+ var tableRef = useSharedTablePluginStateSelector(api, 'tableRef');
42
+ var pluginConfig = useSharedTablePluginStateSelector(api, 'pluginConfig');
43
+ var insertColumnButtonIndex = useSharedTablePluginStateSelector(api, 'insertColumnButtonIndex');
44
+ var insertRowButtonIndex = useSharedTablePluginStateSelector(api, 'insertRowButtonIndex');
45
+ var isHeaderColumnEnabled = useSharedTablePluginStateSelector(api, 'isHeaderColumnEnabled');
46
+ var isHeaderRowEnabled = useSharedTablePluginStateSelector(api, 'isHeaderRowEnabled');
47
+ var isDragAndDropEnabled = useSharedTablePluginStateSelector(api, 'isDragAndDropEnabled');
48
+ var tableWrapperTarget = useSharedTablePluginStateSelector(api, 'tableWrapperTarget');
49
+ var isCellMenuOpenByKeyboard = useSharedTablePluginStateSelector(api, 'isCellMenuOpenByKeyboard');
50
+ var allowControls = pluginConfig.allowControls;
51
+ var stickyHeader = useSharedTablePluginStateSelector(api, 'stickyHeader');
52
+ var dragMenuDirection = useSharedTablePluginStateSelector(api, 'dragMenuDirection');
53
+ var dragMenuIndex = useSharedTablePluginStateSelector(api, 'dragMenuIndex');
54
+ var isDragMenuOpen = useSharedTablePluginStateSelector(api, 'isDragMenuOpen');
55
+ return /*#__PURE__*/React.createElement(React.Fragment, null, targetCellPosition && (tableRef || isCellMenuOpenByKeyboard) && !isResizing && options && options.allowContextualMenu && /*#__PURE__*/React.createElement(FloatingContextualButton, {
56
+ isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
57
+ editorView: editorView,
58
+ tableNode: tableNode,
59
+ mountPoint: popupsMountPoint,
60
+ targetCellPosition: targetCellPosition,
61
+ scrollableElement: popupsScrollableElement,
62
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
63
+ isContextualMenuOpen: isContextualMenuOpen,
64
+ stickyHeader: stickyHeader,
65
+ tableWrapper: tableWrapperTarget,
66
+ isCellMenuOpenByKeyboard: isCellMenuOpenByKeyboard
67
+ }), allowControls && /*#__PURE__*/React.createElement(FloatingInsertButton, {
68
+ tableNode: tableNode,
69
+ tableRef: tableRef,
70
+ insertColumnButtonIndex: insertColumnButtonIndex,
71
+ insertRowButtonIndex: insertRowButtonIndex,
72
+ isHeaderColumnEnabled: isHeaderColumnEnabled,
73
+ isHeaderRowEnabled: isHeaderRowEnabled,
74
+ isDragAndDropEnabled: isDragAndDropEnabled,
75
+ isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
76
+ editorView: editorView,
77
+ mountPoint: popupsMountPoint,
78
+ boundariesElement: popupsBoundariesElement,
79
+ scrollableElement: popupsScrollableElement,
80
+ hasStickyHeaders: stickyHeader && stickyHeader.sticky,
81
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
82
+ editorAnalyticsAPI: editorAnalyticsAPI,
83
+ getEditorContainerWidth: defaultGetEditorContainerWidth,
84
+ getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags,
85
+ isChromelessEditor: options === null || options === void 0 ? void 0 : options.isChromelessEditor,
86
+ api: api,
87
+ isCommentEditor: options === null || options === void 0 ? void 0 : options.isCommentEditor
88
+ }), (options === null || options === void 0 ? void 0 : options.allowContextualMenu) && /*#__PURE__*/React.createElement(FloatingContextualMenu, {
89
+ editorView: editorView,
90
+ mountPoint: popupsMountPoint,
91
+ boundariesElement: popupsBoundariesElement,
92
+ targetCellPosition: targetCellPosition,
93
+ isOpen: Boolean(isContextualMenuOpen) && !isResizing,
94
+ pluginConfig: pluginConfig,
95
+ editorAnalyticsAPI: editorAnalyticsAPI,
96
+ getEditorContainerWidth: defaultGetEditorContainerWidth,
97
+ getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags,
98
+ isCellMenuOpenByKeyboard: isCellMenuOpenByKeyboard,
99
+ isCommentEditor: options === null || options === void 0 ? void 0 : options.isCommentEditor,
100
+ api: api
101
+ }), isDragAndDropEnabled && /*#__PURE__*/React.createElement(FloatingDragMenu, {
102
+ editorView: editorView,
103
+ mountPoint: popupsMountPoint,
104
+ boundariesElement: popupsBoundariesElement,
105
+ tableRef: tableRef,
106
+ tableNode: tableNode,
107
+ targetCellPosition: targetCellPosition,
108
+ direction: dragMenuDirection,
109
+ index: dragMenuIndex,
110
+ isOpen: !!isDragMenuOpen && !isResizing,
111
+ getEditorContainerWidth: defaultGetEditorContainerWidth,
112
+ editorAnalyticsAPI: editorAnalyticsAPI,
113
+ stickyHeaders: stickyHeader,
114
+ pluginConfig: pluginConfig,
115
+ isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
116
+ getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags,
117
+ ariaNotifyPlugin: ariaNotifyPlugin,
118
+ api: api,
119
+ isCommentEditor: options === null || options === void 0 ? void 0 : options.isCommentEditor
120
+ }), allowControls && !isDragAndDropEnabled && !isResizing && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
121
+ editorView: editorView,
122
+ selection: editorView.state.selection,
123
+ tableRef: tableRef,
124
+ mountPoint: popupsMountPoint,
125
+ boundariesElement: popupsBoundariesElement,
126
+ scrollableElement: popupsScrollableElement,
127
+ stickyHeaders: stickyHeader,
128
+ isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
129
+ editorAnalyticsAPI: editorAnalyticsAPI,
130
+ api: api
131
+ }), ((options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) || (options === null || options === void 0 ? void 0 : options.tableOptions.allowTableResizing) && options.isCommentEditor) && isTableResizing && widthToWidest && resizingTableLocalId && resizingTableRef && widthToWidest[resizingTableLocalId] && /*#__PURE__*/React.createElement(FloatingToolbarLabel, {
132
+ target: resizingTableRef,
133
+ content: /*#__PURE__*/React.createElement(FullWidthDisplay, null),
134
+ alignX: 'center',
135
+ alignY: 'bottom',
136
+ stick: true,
137
+ forcePlacement: true,
138
+ zIndex: akEditorFloatingPanelZIndex,
139
+ offset: [0, 10]
140
+ }));
141
+ };
142
+ export var ContentComponent = function ContentComponent(_ref2) {
143
+ var _api$featureFlags;
144
+ var api = _ref2.api,
145
+ editorView = _ref2.editorView,
146
+ dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent,
147
+ options = _ref2.options,
148
+ popupsMountPoint = _ref2.popupsMountPoint,
149
+ popupsBoundariesElement = _ref2.popupsBoundariesElement,
150
+ popupsScrollableElement = _ref2.popupsScrollableElement,
151
+ defaultGetEditorContainerWidth = _ref2.defaultGetEditorContainerWidth,
152
+ defaultGetEditorFeatureFlags = _ref2.defaultGetEditorFeatureFlags;
153
+ return /*#__PURE__*/React.createElement(ErrorBoundary, {
154
+ component: ACTION_SUBJECT.TABLES_PLUGIN,
155
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
156
+ fallbackComponent: null
157
+ }, /*#__PURE__*/React.createElement(GlobalStylesWrapper, {
158
+ featureFlags: api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState(),
159
+ isDragAndDropEnabledOption: options === null || options === void 0 ? void 0 : options.dragAndDropEnabled,
160
+ api: api
161
+ }), /*#__PURE__*/React.createElement(ContentComponentInternal, {
162
+ api: api,
163
+ editorView: editorView,
164
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
165
+ options: options,
166
+ popupsMountPoint: popupsMountPoint,
167
+ popupsBoundariesElement: popupsBoundariesElement,
168
+ popupsScrollableElement: popupsScrollableElement,
169
+ defaultGetEditorContainerWidth: defaultGetEditorContainerWidth,
170
+ defaultGetEditorFeatureFlags: defaultGetEditorFeatureFlags
171
+ }));
172
+ };
@@ -8,6 +8,7 @@ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
8
8
  import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
9
9
  import type { Rect } from '@atlaskit/editor-tables/table-map';
10
10
  import type { Edge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
11
+ import { RowStickyState } from '../pm-plugins/sticky-headers/types';
11
12
  import type { TablePlugin } from '../tablePluginType';
12
13
  export declare const RESIZE_HANDLE_AREA_DECORATION_GAP = 30;
13
14
  export type RowInsertPosition = 'TOP' | 'BOTTOM';
@@ -33,10 +34,16 @@ export type PluginInjectionAPIWithA11y = ExtractInjectionAPI<TablePlugin> & {
33
34
  };
34
35
  };
35
36
  };
36
- export type TableSharedStateInternal = Pick<TablePluginState, 'isFullWidthModeEnabled' | 'wasFullWidthModeEnabled' | 'isHeaderRowEnabled' | 'isHeaderColumnEnabled' | 'ordering' | 'isInDanger' | 'hoveredRows' | 'hoveredColumns' | 'hoveredCell' | 'isTableHovered' | 'tableNode' | 'widthToWidest'> & {
37
+ export type TableSharedStateInternal = Pick<TablePluginState, 'isFullWidthModeEnabled' | 'wasFullWidthModeEnabled' | 'isHeaderRowEnabled' | 'isHeaderColumnEnabled' | 'ordering' | 'isInDanger' | 'hoveredRows' | 'hoveredColumns' | 'hoveredCell' | 'isTableHovered' | 'tableNode' | 'widthToWidest' | 'tableRef' | 'tablePos' | 'targetCellPosition' | 'isContextualMenuOpen' | 'pluginConfig' | 'insertColumnButtonIndex' | 'insertRowButtonIndex' | 'isDragAndDropEnabled' | 'tableWrapperTarget' | 'isCellMenuOpenByKeyboard'> & {
37
38
  isResizing: boolean;
38
39
  isTableResizing?: boolean;
39
40
  isWholeTableInDanger?: boolean;
41
+ resizingTableRef?: HTMLTableElement;
42
+ resizingTableLocalId?: string;
43
+ stickyHeader?: RowStickyState;
44
+ dragMenuDirection?: TableDirection;
45
+ dragMenuIndex?: number;
46
+ isDragMenuOpen?: boolean;
40
47
  };
41
48
  export type TableSharedState = Pick<TablePluginState, 'isFullWidthModeEnabled' | 'wasFullWidthModeEnabled'>;
42
49
  export type AlignmentOptions = 'center' | 'align-start';
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
3
+ import { ExtractInjectionAPI, GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
4
+ import { EditorView } from '@atlaskit/editor-prosemirror/view';
5
+ import { TablePlugin, TablePluginOptions } from '../tablePluginType';
6
+ export type ContentComponentProps = {
7
+ api: ExtractInjectionAPI<TablePlugin> | undefined;
8
+ editorView: EditorView;
9
+ dispatchAnalyticsEvent: DispatchAnalyticsEvent | undefined;
10
+ options?: TablePluginOptions;
11
+ popupsMountPoint?: HTMLElement;
12
+ popupsBoundariesElement?: HTMLElement;
13
+ popupsScrollableElement?: HTMLElement;
14
+ defaultGetEditorContainerWidth: GetEditorContainerWidth;
15
+ defaultGetEditorFeatureFlags: GetEditorFeatureFlags;
16
+ };
17
+ export declare const ContentComponent: ({ api, editorView, dispatchAnalyticsEvent, options, popupsMountPoint, popupsBoundariesElement, popupsScrollableElement, defaultGetEditorContainerWidth, defaultGetEditorFeatureFlags, }: ContentComponentProps) => React.JSX.Element;
@@ -8,6 +8,7 @@ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
8
8
  import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
9
9
  import type { Rect } from '@atlaskit/editor-tables/table-map';
10
10
  import type { Edge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
11
+ import { RowStickyState } from '../pm-plugins/sticky-headers/types';
11
12
  import type { TablePlugin } from '../tablePluginType';
12
13
  export declare const RESIZE_HANDLE_AREA_DECORATION_GAP = 30;
13
14
  export type RowInsertPosition = 'TOP' | 'BOTTOM';
@@ -33,10 +34,16 @@ export type PluginInjectionAPIWithA11y = ExtractInjectionAPI<TablePlugin> & {
33
34
  };
34
35
  };
35
36
  };
36
- export type TableSharedStateInternal = Pick<TablePluginState, 'isFullWidthModeEnabled' | 'wasFullWidthModeEnabled' | 'isHeaderRowEnabled' | 'isHeaderColumnEnabled' | 'ordering' | 'isInDanger' | 'hoveredRows' | 'hoveredColumns' | 'hoveredCell' | 'isTableHovered' | 'tableNode' | 'widthToWidest'> & {
37
+ export type TableSharedStateInternal = Pick<TablePluginState, 'isFullWidthModeEnabled' | 'wasFullWidthModeEnabled' | 'isHeaderRowEnabled' | 'isHeaderColumnEnabled' | 'ordering' | 'isInDanger' | 'hoveredRows' | 'hoveredColumns' | 'hoveredCell' | 'isTableHovered' | 'tableNode' | 'widthToWidest' | 'tableRef' | 'tablePos' | 'targetCellPosition' | 'isContextualMenuOpen' | 'pluginConfig' | 'insertColumnButtonIndex' | 'insertRowButtonIndex' | 'isDragAndDropEnabled' | 'tableWrapperTarget' | 'isCellMenuOpenByKeyboard'> & {
37
38
  isResizing: boolean;
38
39
  isTableResizing?: boolean;
39
40
  isWholeTableInDanger?: boolean;
41
+ resizingTableRef?: HTMLTableElement;
42
+ resizingTableLocalId?: string;
43
+ stickyHeader?: RowStickyState;
44
+ dragMenuDirection?: TableDirection;
45
+ dragMenuIndex?: number;
46
+ isDragMenuOpen?: boolean;
40
47
  };
41
48
  export type TableSharedState = Pick<TablePluginState, 'isFullWidthModeEnabled' | 'wasFullWidthModeEnabled'>;
42
49
  export type AlignmentOptions = 'center' | 'align-start';
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
3
+ import { ExtractInjectionAPI, GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
4
+ import { EditorView } from '@atlaskit/editor-prosemirror/view';
5
+ import { TablePlugin, TablePluginOptions } from '../tablePluginType';
6
+ export type ContentComponentProps = {
7
+ api: ExtractInjectionAPI<TablePlugin> | undefined;
8
+ editorView: EditorView;
9
+ dispatchAnalyticsEvent: DispatchAnalyticsEvent | undefined;
10
+ options?: TablePluginOptions;
11
+ popupsMountPoint?: HTMLElement;
12
+ popupsBoundariesElement?: HTMLElement;
13
+ popupsScrollableElement?: HTMLElement;
14
+ defaultGetEditorContainerWidth: GetEditorContainerWidth;
15
+ defaultGetEditorFeatureFlags: GetEditorFeatureFlags;
16
+ };
17
+ export declare const ContentComponent: ({ api, editorView, dispatchAnalyticsEvent, options, popupsMountPoint, popupsBoundariesElement, popupsScrollableElement, defaultGetEditorContainerWidth, defaultGetEditorFeatureFlags, }: ContentComponentProps) => React.JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "10.8.2",
3
+ "version": "10.9.0",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -39,7 +39,7 @@
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.2.4",
42
+ "@atlaskit/editor-plugin-extension": "5.2.5",
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",
@@ -54,7 +54,7 @@
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.12.0",
57
+ "@atlaskit/tmp-editor-statsig": "^4.13.0",
58
58
  "@atlaskit/toggle": "^15.0.0",
59
59
  "@atlaskit/tokens": "^4.8.0",
60
60
  "@atlaskit/tooltip": "^20.0.0",
@@ -50,7 +50,6 @@ import { createPlugin as createDragAndDropPlugin } from './pm-plugins/drag-and-d
50
50
  import { pluginKey as dragAndDropPluginKey } from './pm-plugins/drag-and-drop/plugin-key';
51
51
  import { keymapPlugin } from './pm-plugins/keymap';
52
52
  import { createPlugin } from './pm-plugins/main';
53
- import { getPluginState } from './pm-plugins/plugin-factory';
54
53
  import { pluginKey } from './pm-plugins/plugin-key';
55
54
  import { createPlugin as createTableSafariDeleteCompositionTextIssueWorkaroundPlugin } from './pm-plugins/safari-delete-composition-text-issue-workaround';
56
55
  import { createPlugin as createStickyHeadersPlugin } from './pm-plugins/sticky-headers/plugin';
@@ -74,7 +73,8 @@ import { createPlugin as createTableWidthInCommentFixPlugin } from './pm-plugins
74
73
  import { createTableWithWidth } from './pm-plugins/utils/create';
75
74
  import { createPlugin as createViewModeSortPlugin } from './pm-plugins/view-mode-sort';
76
75
  import type { TablePlugin, TablePluginOptions } from './tablePluginType';
77
- import type { ColumnResizingPluginState } from './types';
76
+ import type { ColumnResizingPluginState, TableSharedStateInternal } from './types';
77
+ import { ContentComponent } from './ui/ContentComponent';
78
78
  import FloatingContextualButton from './ui/FloatingContextualButton';
79
79
  import FloatingContextualMenu from './ui/FloatingContextualMenu';
80
80
  import FloatingDeleteButton from './ui/FloatingDeleteButton';
@@ -133,11 +133,19 @@ const tablePlugin: TablePlugin = ({ config: options, api }) => {
133
133
  return undefined;
134
134
  }
135
135
 
136
- const tablePluginState = getPluginState(editorState);
136
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
137
+ const tablePluginState = pluginKey.getState(editorState)!;
137
138
  const tableResizingPluginState = getFlexiResizingPlugin(editorState);
138
139
  const tableWidthResizingPluginState = tableWidthPluginKey.getState(editorState);
139
140
 
140
- return {
141
+ const stickyHeadersState = stickyHeadersPluginKey.getState(editorState);
142
+ const stickyHeader = stickyHeadersState
143
+ ? findStickyHeaderForTable(stickyHeadersState, tablePluginState?.tablePos)
144
+ : undefined;
145
+
146
+ const dragAndDropState = dragAndDropPluginKey.getState(editorState);
147
+
148
+ const sharedStateInternal: TableSharedStateInternal = {
141
149
  isFullWidthModeEnabled: !!options?.fullWidthEnabled,
142
150
  wasFullWidthModeEnabled: !!options?.wasFullWidthEnabled,
143
151
  isHeaderRowEnabled: tablePluginState.isHeaderRowEnabled,
@@ -157,7 +165,25 @@ const tablePlugin: TablePlugin = ({ config: options, api }) => {
157
165
  // TableComponent listens for node attribute changes to update colgroups
158
166
  tableNode: tablePluginState.tableNode,
159
167
  widthToWidest: tablePluginState.widthToWidest,
168
+ resizingTableLocalId: tableWidthResizingPluginState?.tableLocalId,
169
+ tableRef: tablePluginState?.tableRef ?? undefined,
170
+ resizingTableRef: tableWidthResizingPluginState?.tableRef ?? undefined,
171
+ tablePos: tablePluginState.tablePos,
172
+ targetCellPosition: tablePluginState.targetCellPosition,
173
+ isContextualMenuOpen: tablePluginState.isContextualMenuOpen,
174
+ pluginConfig: tablePluginState.pluginConfig,
175
+ insertColumnButtonIndex: tablePluginState.insertColumnButtonIndex,
176
+ insertRowButtonIndex: tablePluginState.insertRowButtonIndex,
177
+ isDragAndDropEnabled: tablePluginState.isDragAndDropEnabled,
178
+ tableWrapperTarget: tablePluginState.tableWrapperTarget,
179
+ isCellMenuOpenByKeyboard: tablePluginState.isCellMenuOpenByKeyboard,
180
+ stickyHeader,
181
+ dragMenuDirection: dragAndDropState?.dragMenuDirection,
182
+ dragMenuIndex: dragAndDropState?.dragMenuIndex,
183
+ isDragMenuOpen: dragAndDropState?.isDragMenuOpen,
160
184
  };
185
+
186
+ return sharedStateInternal;
161
187
  },
162
188
 
163
189
  actions: {
@@ -529,6 +555,22 @@ const tablePlugin: TablePlugin = ({ config: options, api }) => {
529
555
  popupsScrollableElement,
530
556
  dispatchAnalyticsEvent,
531
557
  }) {
558
+ if (editorExperiment('platform_editor_usesharedpluginstateselector', true)) {
559
+ return (
560
+ <ContentComponent
561
+ api={api}
562
+ editorView={editorView}
563
+ dispatchAnalyticsEvent={dispatchAnalyticsEvent}
564
+ options={options}
565
+ popupsMountPoint={popupsMountPoint}
566
+ popupsBoundariesElement={popupsBoundariesElement}
567
+ popupsScrollableElement={popupsScrollableElement}
568
+ defaultGetEditorContainerWidth={defaultGetEditorContainerWidth}
569
+ defaultGetEditorFeatureFlags={defaultGetEditorFeatureFlags}
570
+ />
571
+ );
572
+ }
573
+
532
574
  return (
533
575
  <ErrorBoundary
534
576
  component={ACTION_SUBJECT.TABLES_PLUGIN}
@@ -15,6 +15,7 @@ import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
15
15
  import type { Rect } from '@atlaskit/editor-tables/table-map';
16
16
  import type { Edge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
17
17
 
18
+ import { RowStickyState } from '../pm-plugins/sticky-headers/types';
18
19
  import type { TablePlugin } from '../tablePluginType';
19
20
 
20
21
  export const RESIZE_HANDLE_AREA_DECORATION_GAP = 30;
@@ -58,10 +59,26 @@ export type TableSharedStateInternal = Pick<
58
59
  | 'isTableHovered'
59
60
  | 'tableNode'
60
61
  | 'widthToWidest'
62
+ | 'tableRef'
63
+ | 'tablePos'
64
+ | 'targetCellPosition'
65
+ | 'isContextualMenuOpen'
66
+ | 'pluginConfig'
67
+ | 'insertColumnButtonIndex'
68
+ | 'insertRowButtonIndex'
69
+ | 'isDragAndDropEnabled'
70
+ | 'tableWrapperTarget'
71
+ | 'isCellMenuOpenByKeyboard'
61
72
  > & {
62
73
  isResizing: boolean;
63
74
  isTableResizing?: boolean;
64
75
  isWholeTableInDanger?: boolean;
76
+ resizingTableRef?: HTMLTableElement;
77
+ resizingTableLocalId?: string;
78
+ stickyHeader?: RowStickyState;
79
+ dragMenuDirection?: TableDirection;
80
+ dragMenuIndex?: number;
81
+ isDragMenuOpen?: boolean;
65
82
  };
66
83
 
67
84
  export type TableSharedState = Pick<
@@ -0,0 +1,249 @@
1
+ import React from 'react';
2
+
3
+ import { ACTION_SUBJECT, DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
4
+ import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
5
+ import {
6
+ ExtractInjectionAPI,
7
+ GetEditorContainerWidth,
8
+ GetEditorFeatureFlags,
9
+ } from '@atlaskit/editor-common/types';
10
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
11
+ import { EditorView } from '@atlaskit/editor-prosemirror/view';
12
+ import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
13
+
14
+ import { TablePlugin, TablePluginOptions } from '../tablePluginType';
15
+ import { TableSharedStateInternal } from '../types';
16
+
17
+ import FloatingContextualButton from './FloatingContextualButton';
18
+ import FloatingContextualMenu from './FloatingContextualMenu';
19
+ import FloatingDeleteButton from './FloatingDeleteButton';
20
+ import FloatingDragMenu from './FloatingDragMenu';
21
+ // Ignored via go/ees005
22
+ // eslint-disable-next-line import/no-named-as-default
23
+ import FloatingInsertButton from './FloatingInsertButton';
24
+ import { FloatingToolbarLabel } from './FloatingToolbarLabel/FloatingToolbarLabel';
25
+ import { GlobalStylesWrapper } from './global-styles';
26
+ import { FullWidthDisplay } from './TableFullWidthLabel';
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
+ export type ContentComponentProps = {
40
+ api: ExtractInjectionAPI<TablePlugin> | undefined;
41
+ editorView: EditorView;
42
+ dispatchAnalyticsEvent: DispatchAnalyticsEvent | undefined;
43
+ options?: TablePluginOptions;
44
+ popupsMountPoint?: HTMLElement;
45
+ popupsBoundariesElement?: HTMLElement;
46
+ popupsScrollableElement?: HTMLElement;
47
+ defaultGetEditorContainerWidth: GetEditorContainerWidth;
48
+ defaultGetEditorFeatureFlags: GetEditorFeatureFlags;
49
+ };
50
+
51
+ const ContentComponentInternal = ({
52
+ api,
53
+ editorView,
54
+ dispatchAnalyticsEvent,
55
+ options,
56
+ popupsMountPoint,
57
+ popupsBoundariesElement,
58
+ popupsScrollableElement,
59
+ defaultGetEditorContainerWidth,
60
+ defaultGetEditorFeatureFlags,
61
+ }: ContentComponentProps) => {
62
+ const editorAnalyticsAPI = api?.analytics?.actions;
63
+ const ariaNotifyPlugin = api?.accessibilityUtils?.actions.ariaNotify;
64
+
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');
70
+
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(
83
+ api,
84
+ 'isCellMenuOpenByKeyboard',
85
+ );
86
+
87
+ const { allowControls } = pluginConfig;
88
+
89
+ const stickyHeader = useSharedTablePluginStateSelector(api, 'stickyHeader');
90
+
91
+ const dragMenuDirection = useSharedTablePluginStateSelector(api, 'dragMenuDirection');
92
+ const dragMenuIndex = useSharedTablePluginStateSelector(api, 'dragMenuIndex');
93
+ const isDragMenuOpen = useSharedTablePluginStateSelector(api, 'isDragMenuOpen');
94
+
95
+ return (
96
+ <>
97
+ {targetCellPosition &&
98
+ (tableRef || isCellMenuOpenByKeyboard) &&
99
+ !isResizing &&
100
+ options &&
101
+ options.allowContextualMenu && (
102
+ <FloatingContextualButton
103
+ isNumberColumnEnabled={tableNode && tableNode.attrs.isNumberColumnEnabled}
104
+ editorView={editorView}
105
+ tableNode={tableNode}
106
+ mountPoint={popupsMountPoint}
107
+ targetCellPosition={targetCellPosition}
108
+ scrollableElement={popupsScrollableElement}
109
+ dispatchAnalyticsEvent={dispatchAnalyticsEvent}
110
+ isContextualMenuOpen={isContextualMenuOpen}
111
+ stickyHeader={stickyHeader}
112
+ tableWrapper={tableWrapperTarget}
113
+ isCellMenuOpenByKeyboard={isCellMenuOpenByKeyboard}
114
+ />
115
+ )}
116
+ {allowControls && (
117
+ <FloatingInsertButton
118
+ tableNode={tableNode}
119
+ tableRef={tableRef}
120
+ insertColumnButtonIndex={insertColumnButtonIndex}
121
+ insertRowButtonIndex={insertRowButtonIndex}
122
+ isHeaderColumnEnabled={isHeaderColumnEnabled}
123
+ isHeaderRowEnabled={isHeaderRowEnabled}
124
+ isDragAndDropEnabled={isDragAndDropEnabled}
125
+ isTableScalingEnabled={options?.isTableScalingEnabled}
126
+ editorView={editorView}
127
+ mountPoint={popupsMountPoint}
128
+ boundariesElement={popupsBoundariesElement}
129
+ scrollableElement={popupsScrollableElement}
130
+ hasStickyHeaders={stickyHeader && stickyHeader.sticky}
131
+ dispatchAnalyticsEvent={dispatchAnalyticsEvent}
132
+ editorAnalyticsAPI={editorAnalyticsAPI}
133
+ getEditorContainerWidth={defaultGetEditorContainerWidth}
134
+ getEditorFeatureFlags={options?.getEditorFeatureFlags || defaultGetEditorFeatureFlags}
135
+ isChromelessEditor={options?.isChromelessEditor}
136
+ api={api}
137
+ isCommentEditor={options?.isCommentEditor}
138
+ />
139
+ )}
140
+ {options?.allowContextualMenu && (
141
+ <FloatingContextualMenu
142
+ editorView={editorView}
143
+ mountPoint={popupsMountPoint}
144
+ boundariesElement={popupsBoundariesElement}
145
+ targetCellPosition={targetCellPosition}
146
+ isOpen={Boolean(isContextualMenuOpen) && !isResizing}
147
+ pluginConfig={pluginConfig}
148
+ editorAnalyticsAPI={editorAnalyticsAPI}
149
+ getEditorContainerWidth={defaultGetEditorContainerWidth}
150
+ getEditorFeatureFlags={options?.getEditorFeatureFlags || defaultGetEditorFeatureFlags}
151
+ isCellMenuOpenByKeyboard={isCellMenuOpenByKeyboard}
152
+ isCommentEditor={options?.isCommentEditor}
153
+ api={api}
154
+ />
155
+ )}
156
+ {isDragAndDropEnabled && (
157
+ <FloatingDragMenu
158
+ editorView={editorView}
159
+ mountPoint={popupsMountPoint}
160
+ boundariesElement={popupsBoundariesElement}
161
+ tableRef={tableRef as HTMLTableElement}
162
+ tableNode={tableNode}
163
+ targetCellPosition={targetCellPosition}
164
+ direction={dragMenuDirection}
165
+ index={dragMenuIndex}
166
+ isOpen={!!isDragMenuOpen && !isResizing}
167
+ getEditorContainerWidth={defaultGetEditorContainerWidth}
168
+ editorAnalyticsAPI={editorAnalyticsAPI}
169
+ stickyHeaders={stickyHeader}
170
+ pluginConfig={pluginConfig}
171
+ isTableScalingEnabled={options?.isTableScalingEnabled}
172
+ getEditorFeatureFlags={options?.getEditorFeatureFlags || defaultGetEditorFeatureFlags}
173
+ ariaNotifyPlugin={ariaNotifyPlugin}
174
+ api={api}
175
+ isCommentEditor={options?.isCommentEditor}
176
+ />
177
+ )}
178
+ {allowControls && !isDragAndDropEnabled && !isResizing && (
179
+ <FloatingDeleteButton
180
+ editorView={editorView}
181
+ selection={editorView.state.selection}
182
+ tableRef={tableRef as HTMLTableElement}
183
+ mountPoint={popupsMountPoint}
184
+ boundariesElement={popupsBoundariesElement}
185
+ scrollableElement={popupsScrollableElement}
186
+ stickyHeaders={stickyHeader}
187
+ isNumberColumnEnabled={tableNode && tableNode.attrs.isNumberColumnEnabled}
188
+ editorAnalyticsAPI={editorAnalyticsAPI}
189
+ api={api}
190
+ />
191
+ )}
192
+ {(options?.isTableScalingEnabled ||
193
+ (options?.tableOptions.allowTableResizing && options.isCommentEditor)) &&
194
+ isTableResizing &&
195
+ widthToWidest &&
196
+ resizingTableLocalId &&
197
+ resizingTableRef &&
198
+ widthToWidest[resizingTableLocalId] && (
199
+ <FloatingToolbarLabel
200
+ target={resizingTableRef}
201
+ content={<FullWidthDisplay />}
202
+ alignX={'center'}
203
+ alignY={'bottom'}
204
+ stick={true}
205
+ forcePlacement={true}
206
+ zIndex={akEditorFloatingPanelZIndex}
207
+ offset={[0, 10]}
208
+ />
209
+ )}
210
+ </>
211
+ );
212
+ };
213
+
214
+ export const ContentComponent = ({
215
+ api,
216
+ editorView,
217
+ dispatchAnalyticsEvent,
218
+ options,
219
+ popupsMountPoint,
220
+ popupsBoundariesElement,
221
+ popupsScrollableElement,
222
+ defaultGetEditorContainerWidth,
223
+ defaultGetEditorFeatureFlags,
224
+ }: ContentComponentProps) => {
225
+ return (
226
+ <ErrorBoundary
227
+ component={ACTION_SUBJECT.TABLES_PLUGIN}
228
+ dispatchAnalyticsEvent={dispatchAnalyticsEvent}
229
+ fallbackComponent={null}
230
+ >
231
+ <GlobalStylesWrapper
232
+ featureFlags={api?.featureFlags?.sharedState.currentState()}
233
+ isDragAndDropEnabledOption={options?.dragAndDropEnabled}
234
+ api={api}
235
+ />
236
+ <ContentComponentInternal
237
+ api={api}
238
+ editorView={editorView}
239
+ dispatchAnalyticsEvent={dispatchAnalyticsEvent}
240
+ options={options}
241
+ popupsMountPoint={popupsMountPoint}
242
+ popupsBoundariesElement={popupsBoundariesElement}
243
+ popupsScrollableElement={popupsScrollableElement}
244
+ defaultGetEditorContainerWidth={defaultGetEditorContainerWidth}
245
+ defaultGetEditorFeatureFlags={defaultGetEditorFeatureFlags}
246
+ />
247
+ </ErrorBoundary>
248
+ );
249
+ };