@atlaskit/editor-plugin-table 11.0.2 → 11.1.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.
- package/CHANGELOG.md +21 -0
- package/afm-cc/tsconfig.json +3 -0
- package/afm-jira/tsconfig.json +3 -0
- package/afm-post-office/tsconfig.json +3 -0
- package/dist/cjs/nodeviews/TableComponent.js +57 -3
- package/dist/cjs/nodeviews/TableComponentWithSharedState.js +52 -38
- package/dist/cjs/nodeviews/TableContainer.js +39 -24
- package/dist/cjs/nodeviews/TableResizer.js +13 -8
- package/dist/cjs/tablePlugin.js +9 -4
- package/dist/cjs/ui/DragHandle/index.js +11 -5
- package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +9 -4
- package/dist/cjs/ui/TableFloatingControls/CornerControls/DragCornerControls.js +10 -5
- package/dist/cjs/ui/TableFloatingControls/FloatingControlsWithSelection.js +10 -5
- package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +10 -5
- package/dist/cjs/ui/global-styles.js +9 -4
- package/dist/cjs/ui/icons/SortingIconWrapper.js +9 -4
- package/dist/es2019/nodeviews/TableComponent.js +52 -2
- package/dist/es2019/nodeviews/TableComponentWithSharedState.js +47 -32
- package/dist/es2019/nodeviews/TableContainer.js +33 -18
- package/dist/es2019/nodeviews/TableResizer.js +14 -8
- package/dist/es2019/tablePlugin.js +9 -3
- package/dist/es2019/ui/DragHandle/index.js +11 -4
- package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +9 -3
- package/dist/es2019/ui/TableFloatingControls/CornerControls/DragCornerControls.js +10 -4
- package/dist/es2019/ui/TableFloatingControls/FloatingControlsWithSelection.js +10 -4
- package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +10 -4
- package/dist/es2019/ui/global-styles.js +9 -3
- package/dist/es2019/ui/icons/SortingIconWrapper.js +9 -3
- package/dist/esm/nodeviews/TableComponent.js +57 -2
- package/dist/esm/nodeviews/TableComponentWithSharedState.js +53 -39
- package/dist/esm/nodeviews/TableContainer.js +40 -25
- package/dist/esm/nodeviews/TableResizer.js +14 -9
- package/dist/esm/tablePlugin.js +10 -5
- package/dist/esm/ui/DragHandle/index.js +12 -6
- package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +10 -5
- package/dist/esm/ui/TableFloatingControls/CornerControls/DragCornerControls.js +11 -6
- package/dist/esm/ui/TableFloatingControls/FloatingControlsWithSelection.js +11 -6
- package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +11 -6
- package/dist/esm/ui/global-styles.js +10 -5
- package/dist/esm/ui/icons/SortingIconWrapper.js +10 -5
- package/dist/types/nodeviews/TableComponent.d.ts +4 -0
- package/dist/types/ui/hooks/useInternalTablePluginStateSelector.d.ts +1 -1
- package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +4 -0
- package/dist/types-ts4.5/ui/hooks/useInternalTablePluginStateSelector.d.ts +1 -1
- package/package.json +6 -5
- package/src/nodeviews/TableComponent.tsx +57 -0
- package/src/nodeviews/TableComponentWithSharedState.tsx +62 -32
- package/src/nodeviews/TableContainer.tsx +40 -25
- package/src/nodeviews/TableResizer.tsx +10 -7
- package/src/tablePlugin.tsx +4 -2
- package/src/ui/DragHandle/index.tsx +9 -3
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +5 -3
- package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +5 -3
- package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +5 -3
- package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +5 -3
- package/src/ui/global-styles.tsx +4 -2
- package/src/ui/icons/SortingIconWrapper.tsx +4 -2
- 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
|
|
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
|
|
12
|
-
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
|
};
|
|
@@ -40,6 +40,10 @@ interface ComponentProps {
|
|
|
40
40
|
isWholeTableInDanger?: boolean;
|
|
41
41
|
selection?: Selection;
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Exported for test purposes only
|
|
45
|
+
*/
|
|
46
|
+
export declare const _reset_tableComponentCount: () => number;
|
|
43
47
|
declare const _default: React.FC<import("react-intl-next").WithIntlProps<ComponentProps>> & {
|
|
44
48
|
WrappedComponent: React.ComponentType<ComponentProps>;
|
|
45
49
|
};
|
|
@@ -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" | "
|
|
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 {};
|
|
@@ -40,6 +40,10 @@ interface ComponentProps {
|
|
|
40
40
|
isWholeTableInDanger?: boolean;
|
|
41
41
|
selection?: Selection;
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Exported for test purposes only
|
|
45
|
+
*/
|
|
46
|
+
export declare const _reset_tableComponentCount: () => number;
|
|
43
47
|
declare const _default: React.FC<import("react-intl-next").WithIntlProps<ComponentProps>> & {
|
|
44
48
|
WrappedComponent: React.ComponentType<ComponentProps>;
|
|
45
49
|
};
|
|
@@ -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" | "
|
|
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
|
+
"version": "11.1.0",
|
|
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": "^
|
|
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",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@atlaskit/editor-plugin-batch-attribute-updates": "^3.0.0",
|
|
38
38
|
"@atlaskit/editor-plugin-content-insertion": "^3.0.0",
|
|
39
39
|
"@atlaskit/editor-plugin-editor-viewmode": "^5.0.0",
|
|
40
|
-
"@atlaskit/editor-plugin-extension": "6.0.
|
|
40
|
+
"@atlaskit/editor-plugin-extension": "6.0.3",
|
|
41
41
|
"@atlaskit/editor-plugin-guideline": "^3.0.0",
|
|
42
42
|
"@atlaskit/editor-plugin-interaction": "^4.0.0",
|
|
43
43
|
"@atlaskit/editor-plugin-selection": "^3.0.0",
|
|
@@ -52,8 +52,9 @@
|
|
|
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/
|
|
56
|
-
"@atlaskit/
|
|
55
|
+
"@atlaskit/react-ufo": "^3.14.0",
|
|
56
|
+
"@atlaskit/theme": "^19.0.0",
|
|
57
|
+
"@atlaskit/tmp-editor-statsig": "^9.4.0",
|
|
57
58
|
"@atlaskit/toggle": "^15.0.0",
|
|
58
59
|
"@atlaskit/tokens": "^5.4.0",
|
|
59
60
|
"@atlaskit/tooltip": "^20.3.0",
|
|
@@ -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,12 @@ interface TableState {
|
|
|
146
148
|
tableWrapperHeight?: number;
|
|
147
149
|
}
|
|
148
150
|
|
|
151
|
+
let _tableComponentCount = 1;
|
|
152
|
+
/**
|
|
153
|
+
* Exported for test purposes only
|
|
154
|
+
*/
|
|
155
|
+
export const _reset_tableComponentCount = () => (_tableComponentCount = 0);
|
|
156
|
+
|
|
149
157
|
// Ignored via go/ees005
|
|
150
158
|
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
151
159
|
class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
@@ -182,6 +190,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
182
190
|
|
|
183
191
|
private dragAndDropCleanupFn?: CleanupFn;
|
|
184
192
|
private nodeVisibilityObserverCleanupFn?: CleanupFn;
|
|
193
|
+
private holdCompleted = false;
|
|
194
|
+
private dispatchEventName = `tableResized-${_tableComponentCount++}`;
|
|
185
195
|
|
|
186
196
|
constructor(props: ComponentProps) {
|
|
187
197
|
super(props);
|
|
@@ -606,6 +616,16 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
606
616
|
shouldScaleOnColgroupUpdate,
|
|
607
617
|
scalePercent,
|
|
608
618
|
);
|
|
619
|
+
|
|
620
|
+
if (expValEquals('cc_editor_ufo_hold_table_till_resize_complete', 'isEnabled', true)) {
|
|
621
|
+
// Mark table as updated for TableHold component (if no table exists yet, the colgroup update will not have done anything)
|
|
622
|
+
if (this.table && !this.holdCompleted) {
|
|
623
|
+
const customTableResizedEvent = new CustomEvent(this.dispatchEventName);
|
|
624
|
+
|
|
625
|
+
document.dispatchEvent(customTableResizedEvent);
|
|
626
|
+
this.holdCompleted = true;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
609
629
|
});
|
|
610
630
|
}
|
|
611
631
|
}
|
|
@@ -989,6 +1009,9 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
989
1009
|
isCommentEditor={options?.isCommentEditor}
|
|
990
1010
|
isChromelessEditor={options?.isChromelessEditor}
|
|
991
1011
|
>
|
|
1012
|
+
{expValEquals('cc_editor_ufo_hold_table_till_resize_complete', 'isEnabled', true) ? (
|
|
1013
|
+
<TableHold dispatchEventName={this.dispatchEventName} />
|
|
1014
|
+
) : null}
|
|
992
1015
|
<div
|
|
993
1016
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
994
1017
|
className={ClassName.TABLE_STICKY_SENTINEL_TOP}
|
|
@@ -1431,3 +1454,37 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
1431
1454
|
}
|
|
1432
1455
|
|
|
1433
1456
|
export default injectIntl(TableComponent);
|
|
1457
|
+
|
|
1458
|
+
/**
|
|
1459
|
+
* This is needed because of how currently the table is resized post client boot up with code that exists outside react
|
|
1460
|
+
*
|
|
1461
|
+
* 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
|
|
1462
|
+
* is rolled out (and doesn't need to be used in the test arm of that change).
|
|
1463
|
+
*/
|
|
1464
|
+
const TableHold = React.memo(function TableHold({
|
|
1465
|
+
dispatchEventName,
|
|
1466
|
+
}: {
|
|
1467
|
+
dispatchEventName: string;
|
|
1468
|
+
}) {
|
|
1469
|
+
const [tableUpdateConfirmed, setTableUpdateConfirmed] = React.useState(false);
|
|
1470
|
+
|
|
1471
|
+
React.useEffect(() => {
|
|
1472
|
+
const customEventListener = () => {
|
|
1473
|
+
setTableUpdateConfirmed(true);
|
|
1474
|
+
};
|
|
1475
|
+
|
|
1476
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
1477
|
+
document.addEventListener(dispatchEventName, customEventListener);
|
|
1478
|
+
|
|
1479
|
+
return () => {
|
|
1480
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
1481
|
+
document.removeEventListener(dispatchEventName, customEventListener);
|
|
1482
|
+
};
|
|
1483
|
+
}, [dispatchEventName]);
|
|
1484
|
+
|
|
1485
|
+
if (tableUpdateConfirmed === false) {
|
|
1486
|
+
return <UFOLoadHold name="editor_table_resize" />;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
return null;
|
|
1490
|
+
});
|
|
@@ -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 {
|
|
10
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
|
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
|
|
79
|
+
const useAlignmentTableContainerSharedState = sharedPluginStateHookMigratorFactory(
|
|
78
80
|
(pluginInjectionApi: PluginInjectionAPI | undefined) => {
|
|
79
|
-
const isFullWidthModeEnabled =
|
|
81
|
+
const { isFullWidthModeEnabled, wasFullWidthModeEnabled } = useSharedPluginStateWithSelector(
|
|
80
82
|
pluginInjectionApi,
|
|
81
|
-
'table
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
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
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
|
|
226
|
-
|
|
239
|
+
tableState,
|
|
240
|
+
editorViewModeState,
|
|
227
241
|
};
|
|
228
242
|
},
|
|
229
|
-
(
|
|
230
|
-
const { tableState, editorViewModeState } = useSharedPluginState(
|
|
243
|
+
(api: PluginInjectionAPI | undefined) => {
|
|
244
|
+
const { tableState, editorViewModeState } = useSharedPluginState(api, [
|
|
231
245
|
'table',
|
|
232
246
|
'editorViewMode',
|
|
233
247
|
]);
|
|
234
248
|
return {
|
|
235
|
-
|
|
236
|
-
|
|
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 {
|
|
266
|
-
|
|
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
|
-
(
|
|
190
|
-
const widthToWidest =
|
|
193
|
+
(api: PluginInjectionAPI | undefined) => {
|
|
194
|
+
const { widthToWidest } = useSharedPluginStateWithSelector(api, ['table'], selector);
|
|
191
195
|
return {
|
|
192
196
|
widthToWidest,
|
|
193
197
|
};
|
|
194
198
|
},
|
|
195
|
-
(
|
|
196
|
-
const { tableState } = useSharedPluginState(
|
|
197
|
-
const tableStateInternal = tableState as TableSharedStateInternal;
|
|
199
|
+
(api: PluginInjectionAPI | undefined) => {
|
|
200
|
+
const { tableState } = useSharedPluginState(api, ['table']);
|
|
198
201
|
return {
|
|
199
|
-
widthToWidest:
|
|
202
|
+
widthToWidest: (tableState as TableSharedStateInternal | undefined)?.widthToWidest,
|
|
200
203
|
};
|
|
201
204
|
},
|
|
202
205
|
);
|
package/src/tablePlugin.tsx
CHANGED
|
@@ -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 =
|
|
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 =
|
|
319
|
-
|
|
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 =
|
|
67
|
+
const { selection } = useSharedPluginStateWithSelector(api, ['selection'], (states) => ({
|
|
68
|
+
selection: states.selectionState?.selection,
|
|
69
|
+
}));
|
|
68
70
|
return {
|
|
69
71
|
selection,
|
|
70
72
|
};
|
|
@@ -114,7 +116,7 @@ export const ColumnControls = ({
|
|
|
114
116
|
const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
|
|
115
117
|
|
|
116
118
|
const rowControlStickyTop = 45;
|
|
117
|
-
const marginTop = hasHeaderRow && stickyTop !== undefined ? rowControlStickyTop ?? 0 : 0;
|
|
119
|
+
const marginTop = hasHeaderRow && stickyTop !== undefined ? (rowControlStickyTop ?? 0) : 0;
|
|
118
120
|
|
|
119
121
|
const handleClick = useCallback(
|
|
120
122
|
(event: MouseEvent) => {
|
|
@@ -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
|
|
73
|
+
const { selection } = useSharedPluginStateWithSelector(api, ['selection'], (states) => ({
|
|
74
|
+
selection: states.selectionState?.selection,
|
|
75
|
+
}));
|
|
74
76
|
return {
|
|
75
|
-
selection
|
|
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
|
|
33
|
+
const { selection } = useSharedPluginStateWithSelector(api, ['selection'], (states) => ({
|
|
34
|
+
selection: states.selectionState?.selection,
|
|
35
|
+
}));
|
|
34
36
|
return {
|
|
35
|
-
selection
|
|
37
|
+
selection,
|
|
36
38
|
};
|
|
37
39
|
},
|
|
38
40
|
(api: ExtractInjectionAPI<TablePlugin> | undefined) => {
|