@atlaskit/editor-plugin-table 10.9.3 → 10.9.5
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 +16 -0
- package/dist/cjs/nodeviews/TableComponentWithSharedState.js +72 -19
- package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +12 -2
- package/dist/cjs/ui/TableFloatingControls/CornerControls/DragCornerControls.js +14 -5
- package/dist/cjs/ui/TableFloatingControls/FloatingControlsWithSelection.js +11 -2
- package/dist/cjs/ui/TableFloatingControls/NumberColumn/index.js +1 -1
- package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +11 -2
- package/dist/cjs/ui/icons/SortingIconWrapper.js +12 -2
- package/dist/es2019/nodeviews/TableComponentWithSharedState.js +72 -20
- package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +12 -2
- package/dist/es2019/ui/TableFloatingControls/CornerControls/DragCornerControls.js +14 -5
- package/dist/es2019/ui/TableFloatingControls/FloatingControlsWithSelection.js +11 -2
- package/dist/es2019/ui/TableFloatingControls/NumberColumn/index.js +1 -1
- package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +11 -2
- package/dist/es2019/ui/icons/SortingIconWrapper.js +12 -2
- package/dist/esm/nodeviews/TableComponentWithSharedState.js +72 -19
- package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +12 -2
- package/dist/esm/ui/TableFloatingControls/CornerControls/DragCornerControls.js +14 -5
- package/dist/esm/ui/TableFloatingControls/FloatingControlsWithSelection.js +11 -2
- package/dist/esm/ui/TableFloatingControls/NumberColumn/index.js +1 -1
- package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +11 -2
- package/dist/esm/ui/icons/SortingIconWrapper.js +12 -2
- package/package.json +1 -1
- package/src/nodeviews/TableComponentWithSharedState.tsx +127 -21
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +15 -5
- package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +16 -5
- package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +13 -2
- package/src/ui/TableFloatingControls/NumberColumn/index.tsx +4 -4
- package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +13 -2
- package/src/ui/icons/SortingIconWrapper.tsx +15 -2
|
@@ -5,12 +5,14 @@ import React, { useCallback, useMemo, useRef } from 'react';
|
|
|
5
5
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
6
6
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
7
7
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
8
|
+
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
8
9
|
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
9
10
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
10
11
|
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
11
12
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
12
13
|
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
13
14
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
15
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
14
16
|
|
|
15
17
|
import {
|
|
16
18
|
clearHoverSelection,
|
|
@@ -76,7 +78,17 @@ export const ColumnControls = ({
|
|
|
76
78
|
api,
|
|
77
79
|
}: ColumnControlsProps & { api?: ExtractInjectionAPI<TablePlugin> }) => {
|
|
78
80
|
const columnControlsRef = useRef<HTMLDivElement>(null);
|
|
79
|
-
|
|
81
|
+
|
|
82
|
+
// selection
|
|
83
|
+
const { selectionState } = useSharedPluginState(api, ['selection'], {
|
|
84
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
|
|
85
|
+
});
|
|
86
|
+
const selectionsSelector = useSharedPluginStateSelector(api, 'selection.selection', {
|
|
87
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
88
|
+
});
|
|
89
|
+
const selection = editorExperiment('platform_editor_usesharedpluginstateselector', true)
|
|
90
|
+
? selectionsSelector
|
|
91
|
+
: selectionState?.selection;
|
|
80
92
|
|
|
81
93
|
const widths =
|
|
82
94
|
colWidths
|
|
@@ -89,15 +101,13 @@ export const ColumnControls = ({
|
|
|
89
101
|
// TODO: ED-26961 - reusing getRowsParams here because it's generic enough to work for columns -> rename
|
|
90
102
|
const columnParams = getRowsParams(colWidths ?? []);
|
|
91
103
|
const colIndex = hoveredCell?.colIndex;
|
|
92
|
-
const selectedColIndexes = getSelectedColumns(
|
|
93
|
-
selectionState?.selection || editorView.state.selection,
|
|
94
|
-
);
|
|
104
|
+
const selectedColIndexes = getSelectedColumns(selection || editorView.state.selection);
|
|
95
105
|
|
|
96
106
|
const firstRow = tableRef.querySelector('tr');
|
|
97
107
|
const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
|
|
98
108
|
|
|
99
109
|
const rowControlStickyTop = 45;
|
|
100
|
-
const marginTop = hasHeaderRow && stickyTop !== undefined ? rowControlStickyTop ?? 0 : 0;
|
|
110
|
+
const marginTop = hasHeaderRow && stickyTop !== undefined ? (rowControlStickyTop ?? 0) : 0;
|
|
101
111
|
|
|
102
112
|
const handleClick = useCallback(
|
|
103
113
|
(event: MouseEvent) => {
|
|
@@ -7,7 +7,9 @@ import { injectIntl } from 'react-intl-next';
|
|
|
7
7
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
8
8
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
9
9
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
10
|
+
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
10
11
|
import { findTable, isTableSelected, selectTable } from '@atlaskit/editor-tables/utils';
|
|
12
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
11
13
|
|
|
12
14
|
import { clearHoverSelection } from '../../../pm-plugins/commands';
|
|
13
15
|
import type { TablePlugin } from '../../../tablePluginType';
|
|
@@ -71,7 +73,16 @@ const DragCornerControlsComponentWithSelection = ({
|
|
|
71
73
|
intl: { formatMessage },
|
|
72
74
|
api,
|
|
73
75
|
}: CornerControlProps & WrappedComponentProps & { api?: ExtractInjectionAPI<TablePlugin> }) => {
|
|
74
|
-
|
|
76
|
+
// selection
|
|
77
|
+
const { selectionState } = useSharedPluginState(api, ['selection'], {
|
|
78
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
|
|
79
|
+
});
|
|
80
|
+
const selectionsSelector = useSharedPluginStateSelector(api, 'selection.selection', {
|
|
81
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
82
|
+
});
|
|
83
|
+
const selection = editorExperiment('platform_editor_usesharedpluginstateselector', true)
|
|
84
|
+
? selectionsSelector
|
|
85
|
+
: selectionState?.selection;
|
|
75
86
|
|
|
76
87
|
const handleOnClick = () => {
|
|
77
88
|
const { state, dispatch } = editorView;
|
|
@@ -83,15 +94,15 @@ const DragCornerControlsComponentWithSelection = ({
|
|
|
83
94
|
clearHoverSelection()(state, dispatch);
|
|
84
95
|
};
|
|
85
96
|
const isActive = useMemo(() => {
|
|
86
|
-
if (!
|
|
97
|
+
if (!selection) {
|
|
87
98
|
return;
|
|
88
99
|
}
|
|
89
|
-
const table = findTable(
|
|
100
|
+
const table = findTable(selection);
|
|
90
101
|
if (!table) {
|
|
91
102
|
return false;
|
|
92
103
|
}
|
|
93
|
-
return isTableSelected(
|
|
94
|
-
}, [
|
|
104
|
+
return isTableSelected(selection);
|
|
105
|
+
}, [selection]);
|
|
95
106
|
|
|
96
107
|
if (isResizing) {
|
|
97
108
|
return null;
|
|
@@ -2,7 +2,9 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
4
4
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
5
|
+
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
5
6
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
7
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
6
8
|
|
|
7
9
|
import type { TablePlugin } from '../../tablePluginType';
|
|
8
10
|
|
|
@@ -38,7 +40,16 @@ export const FloatingControlsWithSelection = ({
|
|
|
38
40
|
tableActive,
|
|
39
41
|
api,
|
|
40
42
|
}: FloatingControlsWithSelectionProps) => {
|
|
41
|
-
|
|
43
|
+
// selection
|
|
44
|
+
const { selectionState } = useSharedPluginState(api, ['selection'], {
|
|
45
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
|
|
46
|
+
});
|
|
47
|
+
const selectionsSelector = useSharedPluginStateSelector(api, 'selection.selection', {
|
|
48
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
49
|
+
});
|
|
50
|
+
const selection = editorExperiment('platform_editor_usesharedpluginstateselector', true)
|
|
51
|
+
? selectionsSelector
|
|
52
|
+
: selectionState?.selection;
|
|
42
53
|
|
|
43
54
|
return (
|
|
44
55
|
<>
|
|
@@ -53,7 +64,7 @@ export const FloatingControlsWithSelection = ({
|
|
|
53
64
|
stickyTop={tableActive ? stickyTop : undefined}
|
|
54
65
|
/>
|
|
55
66
|
<RowControls
|
|
56
|
-
selection={
|
|
67
|
+
selection={selection}
|
|
57
68
|
editorView={editorView}
|
|
58
69
|
tableRef={tableRef}
|
|
59
70
|
hoverRows={hoverRows}
|
|
@@ -66,7 +66,7 @@ export default class NumberColumn extends Component<Props, any> {
|
|
|
66
66
|
{hasHeaderRow ? (index > 0 ? index : null) : index + 1}
|
|
67
67
|
</div>
|
|
68
68
|
) : (
|
|
69
|
-
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
|
|
69
|
+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions, @atlassian/a11y/interactive-element-not-keyboard-focusable
|
|
70
70
|
<div
|
|
71
71
|
// Ignored via go/ees005
|
|
72
72
|
// eslint-disable-next-line react/no-array-index-key
|
|
@@ -103,10 +103,10 @@ export default class NumberColumn extends Component<Props, any> {
|
|
|
103
103
|
const newPos =
|
|
104
104
|
selection.head > pos
|
|
105
105
|
? // Selection is after table
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
// nodeSize - 3 will move the position inside last table cell
|
|
107
|
+
Selection.near(doc.resolve(pos + ($pos.parent.nodeSize - 3)), -1)
|
|
108
108
|
: // Selection is before table
|
|
109
|
-
|
|
109
|
+
Selection.near($pos);
|
|
110
110
|
editorView.dispatch(tr.setSelection(newPos));
|
|
111
111
|
}
|
|
112
112
|
selectRow(index, event.shiftKey);
|
|
@@ -4,6 +4,7 @@ import React, { Fragment, useCallback, useEffect, useMemo, useState } from 'reac
|
|
|
4
4
|
|
|
5
5
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
6
6
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
7
|
+
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
7
8
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
8
9
|
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
9
10
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
@@ -11,6 +12,7 @@ import { CellSelection } from '@atlaskit/editor-tables';
|
|
|
11
12
|
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
12
13
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
13
14
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
15
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
14
16
|
import { token } from '@atlaskit/tokens';
|
|
15
17
|
|
|
16
18
|
import { clearHoverSelection } from '../../../pm-plugins/commands';
|
|
@@ -385,7 +387,16 @@ export const DragControlsWithSelection = ({
|
|
|
385
387
|
updateCellHoverLocation,
|
|
386
388
|
api,
|
|
387
389
|
}: Exclude<DragControlsProps, 'selection'>) => {
|
|
388
|
-
|
|
390
|
+
// selection
|
|
391
|
+
const { selectionState } = useSharedPluginState(api, ['selection'], {
|
|
392
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
|
|
393
|
+
});
|
|
394
|
+
const selectionsSelector = useSharedPluginStateSelector(api, 'selection.selection', {
|
|
395
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
396
|
+
});
|
|
397
|
+
const selection = editorExperiment('platform_editor_usesharedpluginstateselector', true)
|
|
398
|
+
? selectionsSelector
|
|
399
|
+
: selectionState?.selection;
|
|
389
400
|
|
|
390
401
|
return (
|
|
391
402
|
<DragControls
|
|
@@ -403,7 +414,7 @@ export const DragControlsWithSelection = ({
|
|
|
403
414
|
selectRows={selectRows}
|
|
404
415
|
updateCellHoverLocation={updateCellHoverLocation}
|
|
405
416
|
api={api}
|
|
406
|
-
selection={
|
|
417
|
+
selection={selection}
|
|
407
418
|
/>
|
|
408
419
|
);
|
|
409
420
|
};
|
|
@@ -3,6 +3,8 @@ import React from 'react';
|
|
|
3
3
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
4
4
|
import { SortingIcon } from '@atlaskit/editor-common/table';
|
|
5
5
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
6
|
+
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
7
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
6
8
|
|
|
7
9
|
import type { TablePlugin } from '../../tablePluginType';
|
|
8
10
|
|
|
@@ -12,8 +14,19 @@ type SortingIconWrapperProps = SortingIconProps & {
|
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
export const SortingIconWrapper = (props: SortingIconWrapperProps) => {
|
|
15
|
-
const { editorViewModeState } = useSharedPluginState(props.api, ['editorViewMode']
|
|
16
|
-
|
|
17
|
+
const { editorViewModeState } = useSharedPluginState(props.api, ['editorViewMode'], {
|
|
18
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// mode
|
|
22
|
+
const modeSelector = useSharedPluginStateSelector(props.api, 'editorViewMode.mode', {
|
|
23
|
+
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
|
|
24
|
+
});
|
|
25
|
+
const mode = editorExperiment('platform_editor_usesharedpluginstateselector', true)
|
|
26
|
+
? modeSelector
|
|
27
|
+
: editorViewModeState?.mode;
|
|
28
|
+
|
|
29
|
+
if (mode === 'edit') {
|
|
17
30
|
return null;
|
|
18
31
|
}
|
|
19
32
|
// Ignored via go/ees005
|