@atlaskit/editor-plugin-table 10.9.7 → 10.9.8
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.
- package/CHANGELOG.md +9 -0
- package/dist/cjs/nodeviews/TableComponentWithSharedState.js +33 -19
- package/dist/cjs/nodeviews/TableContainer.js +1 -1
- package/dist/cjs/nodeviews/TableResizer.js +2 -2
- package/dist/cjs/ui/ContentComponent.js +77 -37
- package/dist/cjs/ui/DragHandle/index.js +3 -3
- package/dist/cjs/ui/hooks/useInternalTablePluginStateSelector.js +27 -0
- package/dist/es2019/nodeviews/TableComponentWithSharedState.js +33 -19
- package/dist/es2019/nodeviews/TableContainer.js +1 -1
- package/dist/es2019/nodeviews/TableResizer.js +2 -2
- package/dist/es2019/ui/ContentComponent.js +66 -27
- package/dist/es2019/ui/DragHandle/index.js +3 -3
- package/dist/es2019/ui/hooks/useInternalTablePluginStateSelector.js +21 -0
- package/dist/esm/nodeviews/TableComponentWithSharedState.js +33 -19
- package/dist/esm/nodeviews/TableContainer.js +1 -1
- package/dist/esm/nodeviews/TableResizer.js +2 -2
- package/dist/esm/ui/ContentComponent.js +77 -37
- package/dist/esm/ui/DragHandle/index.js +3 -3
- package/dist/esm/ui/hooks/useInternalTablePluginStateSelector.js +21 -0
- package/dist/types/ui/hooks/useInternalTablePluginStateSelector.d.ts +20 -0
- package/dist/types-ts4.5/ui/hooks/useInternalTablePluginStateSelector.d.ts +20 -0
- package/package.json +3 -3
- package/src/nodeviews/TableComponentWithSharedState.tsx +40 -28
- package/src/nodeviews/TableContainer.tsx +1 -1
- package/src/nodeviews/TableResizer.tsx +4 -4
- package/src/ui/ContentComponent.tsx +71 -35
- package/src/ui/DragHandle/index.tsx +6 -10
- package/src/ui/hooks/useInternalTablePluginStateSelector.ts +36 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
2
|
+
/**
|
|
3
|
+
* **This hook is only for internal use and should not be used outside of the table plugin.**
|
|
4
|
+
*
|
|
5
|
+
* Hook to select a value from the internal table plugin state.
|
|
6
|
+
* This is a wrapper around `useSharedPluginStateSelector` to provide access to the entire
|
|
7
|
+
* `TableSharedStateInternal` type. Since tables plugin has a lot of internal state that is not
|
|
8
|
+
* exposed via the `TableSharedState` type, we need to use this hook to access it in a type safe way.
|
|
9
|
+
*
|
|
10
|
+
* @param api The editor API
|
|
11
|
+
* @param key Key of TableSharedStateInternal to select
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export const useInternalTablePluginStateSelector = (api, key, options) => {
|
|
15
|
+
// Need to disable the eslint rule here because the key is for the TableSharedStateInternal type
|
|
16
|
+
// and we are using it as a string to access the value in the useSharedPluginStateSelector
|
|
17
|
+
// which is typed only for the public TableSharedState type.
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
const value = useSharedPluginStateSelector(api, `table.${key}`, options);
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
@@ -3,18 +3,12 @@ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
|
3
3
|
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
4
4
|
import { findTable } from '@atlaskit/editor-tables';
|
|
5
5
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
6
|
+
import { useInternalTablePluginStateSelector } from '../ui/hooks/useInternalTablePluginStateSelector';
|
|
6
7
|
import TableComponent from './TableComponent';
|
|
7
8
|
|
|
8
9
|
// Ignored via go/ees005
|
|
9
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
11
|
|
|
11
|
-
var useSharedTablePluginStateSelector = function useSharedTablePluginStateSelector(api, key) {
|
|
12
|
-
var value = useSharedPluginStateSelector(api, "table.".concat(key), {
|
|
13
|
-
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
14
|
-
});
|
|
15
|
-
return value;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
12
|
/**
|
|
19
13
|
* Use useSharedPluginState to control re-renders from plugin dependencies
|
|
20
14
|
*/
|
|
@@ -40,16 +34,36 @@ export var TableComponentWithSharedState = function TableComponentWithSharedStat
|
|
|
40
34
|
mediaState = _useSharedPluginState.mediaState,
|
|
41
35
|
selectionState = _useSharedPluginState.selectionState,
|
|
42
36
|
editorViewModeState = _useSharedPluginState.editorViewModeState;
|
|
43
|
-
var isTableResizingSelector =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
var
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var
|
|
37
|
+
var isTableResizingSelector = useInternalTablePluginStateSelector(api, 'isTableResizing', {
|
|
38
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
39
|
+
});
|
|
40
|
+
var isHeaderColumnEnabledSelector = useInternalTablePluginStateSelector(api, 'isHeaderColumnEnabled', {
|
|
41
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
42
|
+
});
|
|
43
|
+
var isHeaderRowEnabledSelector = useInternalTablePluginStateSelector(api, 'isHeaderRowEnabled', {
|
|
44
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
45
|
+
});
|
|
46
|
+
var orderingSelector = useInternalTablePluginStateSelector(api, 'ordering', {
|
|
47
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
48
|
+
});
|
|
49
|
+
var isResizingSelector = useInternalTablePluginStateSelector(api, 'isResizing', {
|
|
50
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
51
|
+
});
|
|
52
|
+
var isInDangerSelector = useInternalTablePluginStateSelector(api, 'isInDanger', {
|
|
53
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
54
|
+
});
|
|
55
|
+
var hoveredCellSelector = useInternalTablePluginStateSelector(api, 'hoveredCell', {
|
|
56
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
57
|
+
});
|
|
58
|
+
var hoveredRowsSelector = useInternalTablePluginStateSelector(api, 'hoveredRows', {
|
|
59
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
60
|
+
});
|
|
61
|
+
var isTableHoveredSelector = useInternalTablePluginStateSelector(api, 'isTableHovered', {
|
|
62
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
63
|
+
});
|
|
64
|
+
var isWholeTableInDangerSelector = useInternalTablePluginStateSelector(api, 'isWholeTableInDanger', {
|
|
65
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
66
|
+
});
|
|
53
67
|
|
|
54
68
|
// mediaState
|
|
55
69
|
var isFullscreenSelector = useSharedPluginStateSelector(api, 'media.isFullscreen', {
|
|
@@ -117,8 +131,8 @@ export var TableComponentWithSharedState = function TableComponentWithSharedStat
|
|
|
117
131
|
isMediaFullscreen: isFullscreen,
|
|
118
132
|
options: options,
|
|
119
133
|
allowControls: allowControls,
|
|
120
|
-
isHeaderRowEnabled: isHeaderRowEnabled,
|
|
121
|
-
isHeaderColumnEnabled: isHeaderColumnEnabled,
|
|
134
|
+
isHeaderRowEnabled: isHeaderRowEnabled !== null && isHeaderRowEnabled !== void 0 ? isHeaderRowEnabled : false,
|
|
135
|
+
isHeaderColumnEnabled: isHeaderColumnEnabled !== null && isHeaderColumnEnabled !== void 0 ? isHeaderColumnEnabled : false,
|
|
122
136
|
isDragAndDropEnabled: (options === null || options === void 0 ? void 0 : options.isDragAndDropEnabled) && !isLivePageViewMode,
|
|
123
137
|
isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
|
|
124
138
|
allowTableAlignment: allowTableAlignment,
|
|
@@ -58,7 +58,7 @@ var AlignmentTableContainer = function AlignmentTableContainer(_ref2) {
|
|
|
58
58
|
});
|
|
59
59
|
var wasFullWidthModeEnabled = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? wasFullWidthModeEnabledSelector : tableState === null || tableState === void 0 ? void 0 : tableState.wasFullWidthModeEnabled;
|
|
60
60
|
useEffect(function () {
|
|
61
|
-
if (editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
61
|
+
if (!tableState && editorExperiment('platform_editor_usesharedpluginstateselector', false)) {
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
if (editorView && getPos) {
|
|
@@ -13,7 +13,6 @@ import { focusTableResizer, ToolTipContent } from '@atlaskit/editor-common/keyma
|
|
|
13
13
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
14
14
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
15
15
|
import { ResizerNext } from '@atlaskit/editor-common/resizer';
|
|
16
|
-
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
17
16
|
import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
|
|
18
17
|
import { akEditorGutterPaddingDynamic } from '@atlaskit/editor-shared-styles';
|
|
19
18
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
@@ -31,6 +30,7 @@ import { generateResizedPayload, generateResizeFrameRatePayloads, useMeasureFram
|
|
|
31
30
|
import { defaultGuidelines, defaultGuidelinesForPreserveTable, PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET } from '../pm-plugins/utils/guidelines';
|
|
32
31
|
import { defaultSnappingWidths, defaultTablePreserveSnappingWidths, findClosestSnap, PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET } from '../pm-plugins/utils/snapping';
|
|
33
32
|
import { TABLE_GUIDELINE_VISIBLE_ADJUSTMENT, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE, TABLE_SNAP_GAP } from '../ui/consts';
|
|
33
|
+
import { useInternalTablePluginStateSelector } from '../ui/hooks/useInternalTablePluginStateSelector';
|
|
34
34
|
var RESIZE_STEP_VALUE = 10;
|
|
35
35
|
var handles = {
|
|
36
36
|
right: true
|
|
@@ -133,7 +133,7 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
133
133
|
tableState = _useSharedPluginState.tableState;
|
|
134
134
|
|
|
135
135
|
// widthToWidest
|
|
136
|
-
var widthToWidestSelector =
|
|
136
|
+
var widthToWidestSelector = useInternalTablePluginStateSelector(pluginInjectionApi, 'widthToWidest', {
|
|
137
137
|
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
138
138
|
});
|
|
139
139
|
var widthToWidest = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? widthToWidestSelector : tableState.widthToWidest;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ACTION_SUBJECT } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
|
|
4
|
-
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
5
4
|
import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
5
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
6
6
|
import FloatingContextualButton from './FloatingContextualButton';
|
|
7
7
|
import FloatingContextualMenu from './FloatingContextualMenu';
|
|
8
8
|
import FloatingDeleteButton from './FloatingDeleteButton';
|
|
@@ -12,11 +12,8 @@ import FloatingDragMenu from './FloatingDragMenu';
|
|
|
12
12
|
import FloatingInsertButton from './FloatingInsertButton';
|
|
13
13
|
import { FloatingToolbarLabel } from './FloatingToolbarLabel/FloatingToolbarLabel';
|
|
14
14
|
import { GlobalStylesWrapper } from './global-styles';
|
|
15
|
+
import { useInternalTablePluginStateSelector } from './hooks/useInternalTablePluginStateSelector';
|
|
15
16
|
import { FullWidthDisplay } from './TableFullWidthLabel';
|
|
16
|
-
var useSharedTablePluginStateSelector = function useSharedTablePluginStateSelector(api, key) {
|
|
17
|
-
var value = useSharedPluginStateSelector(api, "table.".concat(key));
|
|
18
|
-
return value;
|
|
19
|
-
};
|
|
20
17
|
var ContentComponentInternal = function ContentComponentInternal(_ref) {
|
|
21
18
|
var _api$analytics, _api$accessibilityUti;
|
|
22
19
|
var api = _ref.api,
|
|
@@ -30,28 +27,71 @@ var ContentComponentInternal = function ContentComponentInternal(_ref) {
|
|
|
30
27
|
defaultGetEditorFeatureFlags = _ref.defaultGetEditorFeatureFlags;
|
|
31
28
|
var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
|
|
32
29
|
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 =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
var
|
|
30
|
+
var resizingTableLocalId = useInternalTablePluginStateSelector(api, 'resizingTableLocalId', {
|
|
31
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
32
|
+
});
|
|
33
|
+
var resizingTableRef = useInternalTablePluginStateSelector(api, 'resizingTableRef', {
|
|
34
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
35
|
+
});
|
|
36
|
+
var isTableResizing = useInternalTablePluginStateSelector(api, 'isTableResizing', {
|
|
37
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
38
|
+
});
|
|
39
|
+
var isResizing = useInternalTablePluginStateSelector(api, 'isResizing', {
|
|
40
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
41
|
+
});
|
|
42
|
+
var widthToWidest = useInternalTablePluginStateSelector(api, 'widthToWidest', {
|
|
43
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
44
|
+
});
|
|
45
|
+
var tableNode = useInternalTablePluginStateSelector(api, 'tableNode', {
|
|
46
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
47
|
+
});
|
|
48
|
+
var targetCellPosition = useInternalTablePluginStateSelector(api, 'targetCellPosition', {
|
|
49
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
50
|
+
});
|
|
51
|
+
var isContextualMenuOpen = useInternalTablePluginStateSelector(api, 'isContextualMenuOpen', {
|
|
52
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
53
|
+
});
|
|
54
|
+
var tableRef = useInternalTablePluginStateSelector(api, 'tableRef', {
|
|
55
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
56
|
+
});
|
|
57
|
+
var pluginConfig = useInternalTablePluginStateSelector(api, 'pluginConfig', {
|
|
58
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
59
|
+
});
|
|
60
|
+
var insertColumnButtonIndex = useInternalTablePluginStateSelector(api, 'insertColumnButtonIndex', {
|
|
61
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
62
|
+
});
|
|
63
|
+
var insertRowButtonIndex = useInternalTablePluginStateSelector(api, 'insertRowButtonIndex', {
|
|
64
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
65
|
+
});
|
|
66
|
+
var isHeaderColumnEnabled = useInternalTablePluginStateSelector(api, 'isHeaderColumnEnabled', {
|
|
67
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
68
|
+
});
|
|
69
|
+
var isHeaderRowEnabled = useInternalTablePluginStateSelector(api, 'isHeaderRowEnabled', {
|
|
70
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
71
|
+
});
|
|
72
|
+
var isDragAndDropEnabled = useInternalTablePluginStateSelector(api, 'isDragAndDropEnabled', {
|
|
73
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
74
|
+
});
|
|
75
|
+
var tableWrapperTarget = useInternalTablePluginStateSelector(api, 'tableWrapperTarget', {
|
|
76
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
77
|
+
});
|
|
78
|
+
var isCellMenuOpenByKeyboard = useInternalTablePluginStateSelector(api, 'isCellMenuOpenByKeyboard', {
|
|
79
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
80
|
+
});
|
|
81
|
+
var _ref2 = pluginConfig !== null && pluginConfig !== void 0 ? pluginConfig : {},
|
|
82
|
+
allowControls = _ref2.allowControls;
|
|
83
|
+
var stickyHeader = useInternalTablePluginStateSelector(api, 'stickyHeader', {
|
|
84
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
85
|
+
});
|
|
86
|
+
var dragMenuDirection = useInternalTablePluginStateSelector(api, 'dragMenuDirection', {
|
|
87
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
88
|
+
});
|
|
89
|
+
var dragMenuIndex = useInternalTablePluginStateSelector(api, 'dragMenuIndex', {
|
|
90
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
91
|
+
});
|
|
92
|
+
var isDragMenuOpen = useInternalTablePluginStateSelector(api, 'isDragMenuOpen', {
|
|
93
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
94
|
+
});
|
|
55
95
|
return /*#__PURE__*/React.createElement(React.Fragment, null, targetCellPosition && (tableRef || isCellMenuOpenByKeyboard) && !isResizing && options && options.allowContextualMenu && /*#__PURE__*/React.createElement(FloatingContextualButton, {
|
|
56
96
|
isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
|
|
57
97
|
editorView: editorView,
|
|
@@ -139,17 +179,17 @@ var ContentComponentInternal = function ContentComponentInternal(_ref) {
|
|
|
139
179
|
offset: [0, 10]
|
|
140
180
|
}));
|
|
141
181
|
};
|
|
142
|
-
export var ContentComponent = function ContentComponent(
|
|
182
|
+
export var ContentComponent = function ContentComponent(_ref3) {
|
|
143
183
|
var _api$featureFlags;
|
|
144
|
-
var api =
|
|
145
|
-
editorView =
|
|
146
|
-
dispatchAnalyticsEvent =
|
|
147
|
-
options =
|
|
148
|
-
popupsMountPoint =
|
|
149
|
-
popupsBoundariesElement =
|
|
150
|
-
popupsScrollableElement =
|
|
151
|
-
defaultGetEditorContainerWidth =
|
|
152
|
-
defaultGetEditorFeatureFlags =
|
|
184
|
+
var api = _ref3.api,
|
|
185
|
+
editorView = _ref3.editorView,
|
|
186
|
+
dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent,
|
|
187
|
+
options = _ref3.options,
|
|
188
|
+
popupsMountPoint = _ref3.popupsMountPoint,
|
|
189
|
+
popupsBoundariesElement = _ref3.popupsBoundariesElement,
|
|
190
|
+
popupsScrollableElement = _ref3.popupsScrollableElement,
|
|
191
|
+
defaultGetEditorContainerWidth = _ref3.defaultGetEditorContainerWidth,
|
|
192
|
+
defaultGetEditorFeatureFlags = _ref3.defaultGetEditorFeatureFlags;
|
|
153
193
|
return /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
154
194
|
component: ACTION_SUBJECT.TABLES_PLUGIN,
|
|
155
195
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
@@ -9,7 +9,6 @@ import { injectIntl } from 'react-intl-next';
|
|
|
9
9
|
import { browser } from '@atlaskit/editor-common/browser';
|
|
10
10
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
11
11
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
12
|
-
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
13
12
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
14
13
|
import { findTable, TableMap } from '@atlaskit/editor-tables';
|
|
15
14
|
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
@@ -21,6 +20,7 @@ import { findDuplicatePosition, hasMergedCellsInSelection } from '../../pm-plugi
|
|
|
21
20
|
import { TableCssClassName as ClassName } from '../../types';
|
|
22
21
|
import { dragTableInsertColumnButtonSize } from '../consts';
|
|
23
22
|
import { DragPreview } from '../DragPreview';
|
|
23
|
+
import { useInternalTablePluginStateSelector } from '../hooks/useInternalTablePluginStateSelector';
|
|
24
24
|
import { HandleIconComponent } from './HandleIconComponent';
|
|
25
25
|
var DragHandleComponent = function DragHandleComponent(_ref) {
|
|
26
26
|
var isDragMenuTarget = _ref.isDragMenuTarget,
|
|
@@ -268,13 +268,13 @@ var DragHandleComponentWithSharedState = function DragHandleComponentWithSharedS
|
|
|
268
268
|
tableState = _ref6.tableState;
|
|
269
269
|
|
|
270
270
|
// hoveredColumns
|
|
271
|
-
var hoveredColumnsSelector =
|
|
271
|
+
var hoveredColumnsSelector = useInternalTablePluginStateSelector(api, 'hoveredColumns', {
|
|
272
272
|
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
273
273
|
});
|
|
274
274
|
var hoveredColumns = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? hoveredColumnsSelector : tableState === null || tableState === void 0 ? void 0 : tableState.hoveredColumns;
|
|
275
275
|
|
|
276
276
|
// hoveredRows
|
|
277
|
-
var hoveredRowsSelector =
|
|
277
|
+
var hoveredRowsSelector = useInternalTablePluginStateSelector(api, 'hoveredRows', {
|
|
278
278
|
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
279
279
|
});
|
|
280
280
|
var hoveredRows = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? hoveredRowsSelector : tableState === null || tableState === void 0 ? void 0 : tableState.hoveredRows;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
2
|
+
/**
|
|
3
|
+
* **This hook is only for internal use and should not be used outside of the table plugin.**
|
|
4
|
+
*
|
|
5
|
+
* Hook to select a value from the internal table plugin state.
|
|
6
|
+
* This is a wrapper around `useSharedPluginStateSelector` to provide access to the entire
|
|
7
|
+
* `TableSharedStateInternal` type. Since tables plugin has a lot of internal state that is not
|
|
8
|
+
* exposed via the `TableSharedState` type, we need to use this hook to access it in a type safe way.
|
|
9
|
+
*
|
|
10
|
+
* @param api The editor API
|
|
11
|
+
* @param key Key of TableSharedStateInternal to select
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export var useInternalTablePluginStateSelector = function useInternalTablePluginStateSelector(api, key, options) {
|
|
15
|
+
// Need to disable the eslint rule here because the key is for the TableSharedStateInternal type
|
|
16
|
+
// and we are using it as a string to access the value in the useSharedPluginStateSelector
|
|
17
|
+
// which is typed only for the public TableSharedState type.
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
var value = useSharedPluginStateSelector(api, "table.".concat(key), options);
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
@@ -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 {};
|
|
@@ -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.
|
|
3
|
+
"version": "10.9.8",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -32,7 +32,7 @@
|
|
|
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.
|
|
35
|
+
"@atlaskit/editor-common": "^103.18.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",
|
|
@@ -49,7 +49,7 @@
|
|
|
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.
|
|
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",
|
|
@@ -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 =
|
|
77
|
-
|
|
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 =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
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)
|
|
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 =
|
|
221
|
+
const widthToWidestSelector = useInternalTablePluginStateSelector(
|
|
222
222
|
pluginInjectionApi,
|
|
223
|
-
'
|
|
223
|
+
'widthToWidest',
|
|
224
224
|
{
|
|
225
225
|
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
226
226
|
},
|
|
227
|
-
)
|
|
227
|
+
);
|
|
228
228
|
const widthToWidest = editorExperiment('platform_editor_usesharedpluginstateselector', true)
|
|
229
229
|
? widthToWidestSelector
|
|
230
230
|
: (tableState as TableSharedStateInternal).widthToWidest;
|