@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
|
@@ -7,12 +7,11 @@ import {
|
|
|
7
7
|
GetEditorContainerWidth,
|
|
8
8
|
GetEditorFeatureFlags,
|
|
9
9
|
} from '@atlaskit/editor-common/types';
|
|
10
|
-
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
11
10
|
import { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
12
11
|
import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
12
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
13
13
|
|
|
14
14
|
import { TablePlugin, TablePluginOptions } from '../tablePluginType';
|
|
15
|
-
import { TableSharedStateInternal } from '../types';
|
|
16
15
|
|
|
17
16
|
import FloatingContextualButton from './FloatingContextualButton';
|
|
18
17
|
import FloatingContextualMenu from './FloatingContextualMenu';
|
|
@@ -23,19 +22,9 @@ import FloatingDragMenu from './FloatingDragMenu';
|
|
|
23
22
|
import FloatingInsertButton from './FloatingInsertButton';
|
|
24
23
|
import { FloatingToolbarLabel } from './FloatingToolbarLabel/FloatingToolbarLabel';
|
|
25
24
|
import { GlobalStylesWrapper } from './global-styles';
|
|
25
|
+
import { useInternalTablePluginStateSelector } from './hooks/useInternalTablePluginStateSelector';
|
|
26
26
|
import { FullWidthDisplay } from './TableFullWidthLabel';
|
|
27
27
|
|
|
28
|
-
const useSharedTablePluginStateSelector = <K extends keyof TableSharedStateInternal>(
|
|
29
|
-
api: ExtractInjectionAPI<TablePlugin> | undefined,
|
|
30
|
-
key: K,
|
|
31
|
-
) => {
|
|
32
|
-
const value = useSharedPluginStateSelector(
|
|
33
|
-
api,
|
|
34
|
-
`table.${key}` as never,
|
|
35
|
-
) as TableSharedStateInternal[K];
|
|
36
|
-
return value;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
28
|
export type ContentComponentProps = {
|
|
40
29
|
api: ExtractInjectionAPI<TablePlugin> | undefined;
|
|
41
30
|
editorView: EditorView;
|
|
@@ -62,35 +51,82 @@ const ContentComponentInternal = ({
|
|
|
62
51
|
const editorAnalyticsAPI = api?.analytics?.actions;
|
|
63
52
|
const ariaNotifyPlugin = api?.accessibilityUtils?.actions.ariaNotify;
|
|
64
53
|
|
|
65
|
-
const resizingTableLocalId =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
54
|
+
const resizingTableLocalId = useInternalTablePluginStateSelector(api, 'resizingTableLocalId', {
|
|
55
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
56
|
+
});
|
|
57
|
+
const resizingTableRef = useInternalTablePluginStateSelector(api, 'resizingTableRef', {
|
|
58
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
59
|
+
});
|
|
60
|
+
const isTableResizing = useInternalTablePluginStateSelector(api, 'isTableResizing', {
|
|
61
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
62
|
+
});
|
|
63
|
+
const isResizing = useInternalTablePluginStateSelector(api, 'isResizing', {
|
|
64
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
65
|
+
});
|
|
66
|
+
const widthToWidest = useInternalTablePluginStateSelector(api, 'widthToWidest', {
|
|
67
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
68
|
+
});
|
|
70
69
|
|
|
71
|
-
const tableNode =
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
70
|
+
const tableNode = useInternalTablePluginStateSelector(api, 'tableNode', {
|
|
71
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
72
|
+
});
|
|
73
|
+
const targetCellPosition = useInternalTablePluginStateSelector(api, 'targetCellPosition', {
|
|
74
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
75
|
+
});
|
|
76
|
+
const isContextualMenuOpen = useInternalTablePluginStateSelector(api, 'isContextualMenuOpen', {
|
|
77
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
78
|
+
});
|
|
79
|
+
const tableRef = useInternalTablePluginStateSelector(api, 'tableRef', {
|
|
80
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
81
|
+
});
|
|
82
|
+
const pluginConfig = useInternalTablePluginStateSelector(api, 'pluginConfig', {
|
|
83
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
84
|
+
});
|
|
85
|
+
const insertColumnButtonIndex = useInternalTablePluginStateSelector(
|
|
86
|
+
api,
|
|
87
|
+
'insertColumnButtonIndex',
|
|
88
|
+
{
|
|
89
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
90
|
+
},
|
|
91
|
+
);
|
|
92
|
+
const insertRowButtonIndex = useInternalTablePluginStateSelector(api, 'insertRowButtonIndex', {
|
|
93
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
94
|
+
});
|
|
95
|
+
const isHeaderColumnEnabled = useInternalTablePluginStateSelector(api, 'isHeaderColumnEnabled', {
|
|
96
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
97
|
+
});
|
|
98
|
+
const isHeaderRowEnabled = useInternalTablePluginStateSelector(api, 'isHeaderRowEnabled', {
|
|
99
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
100
|
+
});
|
|
101
|
+
const isDragAndDropEnabled = useInternalTablePluginStateSelector(api, 'isDragAndDropEnabled', {
|
|
102
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
103
|
+
});
|
|
104
|
+
const tableWrapperTarget = useInternalTablePluginStateSelector(api, 'tableWrapperTarget', {
|
|
105
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
106
|
+
});
|
|
107
|
+
const isCellMenuOpenByKeyboard = useInternalTablePluginStateSelector(
|
|
83
108
|
api,
|
|
84
109
|
'isCellMenuOpenByKeyboard',
|
|
110
|
+
{
|
|
111
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
112
|
+
},
|
|
85
113
|
);
|
|
86
114
|
|
|
87
|
-
const { allowControls } = pluginConfig;
|
|
115
|
+
const { allowControls } = pluginConfig ?? {};
|
|
88
116
|
|
|
89
|
-
const stickyHeader =
|
|
117
|
+
const stickyHeader = useInternalTablePluginStateSelector(api, 'stickyHeader', {
|
|
118
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
119
|
+
});
|
|
90
120
|
|
|
91
|
-
const dragMenuDirection =
|
|
92
|
-
|
|
93
|
-
|
|
121
|
+
const dragMenuDirection = useInternalTablePluginStateSelector(api, 'dragMenuDirection', {
|
|
122
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
123
|
+
});
|
|
124
|
+
const dragMenuIndex = useInternalTablePluginStateSelector(api, 'dragMenuIndex', {
|
|
125
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
126
|
+
});
|
|
127
|
+
const isDragMenuOpen = useInternalTablePluginStateSelector(api, 'isDragMenuOpen', {
|
|
128
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
129
|
+
});
|
|
94
130
|
|
|
95
131
|
return (
|
|
96
132
|
<>
|
|
@@ -11,7 +11,6 @@ import { browser } from '@atlaskit/editor-common/browser';
|
|
|
11
11
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
12
12
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
13
13
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
14
|
-
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
15
14
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
16
15
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
17
16
|
import { findTable, TableMap } from '@atlaskit/editor-tables';
|
|
@@ -32,6 +31,7 @@ import { TableCssClassName as ClassName } from '../../types';
|
|
|
32
31
|
import type { CellHoverMeta, TableDirection, TableSharedStateInternal } from '../../types';
|
|
33
32
|
import { dragTableInsertColumnButtonSize } from '../consts';
|
|
34
33
|
import { DragPreview } from '../DragPreview';
|
|
34
|
+
import { useInternalTablePluginStateSelector } from '../hooks/useInternalTablePluginStateSelector';
|
|
35
35
|
|
|
36
36
|
import { HandleIconComponent } from './HandleIconComponent';
|
|
37
37
|
|
|
@@ -336,21 +336,17 @@ const DragHandleComponentWithSharedState = ({
|
|
|
336
336
|
};
|
|
337
337
|
|
|
338
338
|
// hoveredColumns
|
|
339
|
-
const hoveredColumnsSelector =
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
{
|
|
343
|
-
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
344
|
-
},
|
|
345
|
-
) as TableSharedStateInternal['hoveredColumns'];
|
|
339
|
+
const hoveredColumnsSelector = useInternalTablePluginStateSelector(api, 'hoveredColumns', {
|
|
340
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
341
|
+
});
|
|
346
342
|
const hoveredColumns = editorExperiment('platform_editor_usesharedpluginstateselector', true)
|
|
347
343
|
? hoveredColumnsSelector
|
|
348
344
|
: tableState?.hoveredColumns;
|
|
349
345
|
|
|
350
346
|
// hoveredRows
|
|
351
|
-
const hoveredRowsSelector =
|
|
347
|
+
const hoveredRowsSelector = useInternalTablePluginStateSelector(api, 'hoveredRows', {
|
|
352
348
|
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
353
|
-
})
|
|
349
|
+
});
|
|
354
350
|
const hoveredRows = editorExperiment('platform_editor_usesharedpluginstateselector', true)
|
|
355
351
|
? hoveredRowsSelector
|
|
356
352
|
: tableState?.hoveredRows;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
3
|
+
|
|
4
|
+
import { TablePlugin } from '../../tablePluginType';
|
|
5
|
+
import { TableSharedStateInternal } from '../../types';
|
|
6
|
+
|
|
7
|
+
type Options = {
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* **This hook is only for internal use and should not be used outside of the table plugin.**
|
|
13
|
+
*
|
|
14
|
+
* Hook to select a value from the internal table plugin state.
|
|
15
|
+
* This is a wrapper around `useSharedPluginStateSelector` to provide access to the entire
|
|
16
|
+
* `TableSharedStateInternal` type. Since tables plugin has a lot of internal state that is not
|
|
17
|
+
* exposed via the `TableSharedState` type, we need to use this hook to access it in a type safe way.
|
|
18
|
+
*
|
|
19
|
+
* @param api The editor API
|
|
20
|
+
* @param key Key of TableSharedStateInternal to select
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export const useInternalTablePluginStateSelector = <K extends keyof TableSharedStateInternal>(
|
|
24
|
+
api: ExtractInjectionAPI<TablePlugin> | undefined,
|
|
25
|
+
key: K,
|
|
26
|
+
options?: Options,
|
|
27
|
+
): TableSharedStateInternal[K] | undefined => {
|
|
28
|
+
// Need to disable the eslint rule here because the key is for the TableSharedStateInternal type
|
|
29
|
+
// and we are using it as a string to access the value in the useSharedPluginStateSelector
|
|
30
|
+
// which is typed only for the public TableSharedState type.
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
const value = useSharedPluginStateSelector(api, `table.${key}` as any, options) as
|
|
33
|
+
| TableSharedStateInternal[K]
|
|
34
|
+
| undefined;
|
|
35
|
+
return value;
|
|
36
|
+
};
|