@atlaskit/editor-plugin-table 22.4.11 → 22.4.13
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 +17 -0
- package/dist/cjs/tablePlugin.js +7 -1
- package/dist/cjs/ui/TableMenu/column/getColumnMenuComponents.js +46 -11
- package/dist/cjs/ui/TableMenu/column/items/AddColumnLeftItem.js +34 -1
- package/dist/cjs/ui/TableMenu/column/items/AddColumnRightItem.js +34 -1
- package/dist/cjs/ui/TableMenu/column/items/ColumnBackgroundSection.js +15 -2
- package/dist/cjs/ui/TableMenu/column/items/ColumnToggleSection.js +15 -2
- package/dist/cjs/ui/TableMenu/column/items/DeleteColumnItem.js +60 -3
- package/dist/cjs/ui/TableMenu/column/items/DistributeColumnsItem.js +43 -5
- package/dist/cjs/ui/TableMenu/column/items/HeaderColumnToggleItem.js +36 -5
- package/dist/cjs/ui/TableMenu/column/items/MoveColumnLeftItem.js +69 -0
- package/dist/cjs/ui/TableMenu/column/items/MoveColumnRightItem.js +42 -3
- package/dist/cjs/ui/TableMenu/column/items/SortDecreasingItem.js +22 -1
- package/dist/cjs/ui/TableMenu/column/items/SortIncreasingItem.js +22 -1
- package/dist/cjs/ui/TableMenu/column/keys.js +6 -2
- package/dist/cjs/ui/TableMenu/row/getRowMenuComponents.js +23 -8
- package/dist/cjs/ui/TableMenu/row/items/AddRowAboveItem.js +24 -1
- package/dist/cjs/ui/TableMenu/row/items/AddRowBelowItem.js +24 -1
- package/dist/cjs/ui/TableMenu/row/items/DeleteRowItem.js +55 -3
- package/dist/cjs/ui/TableMenu/row/items/HeaderRowToggleItem.js +38 -5
- package/dist/cjs/ui/TableMenu/row/items/MoveRowDownItem.js +38 -13
- package/dist/cjs/ui/TableMenu/row/items/MoveRowUpItem.js +38 -13
- package/dist/cjs/ui/TableMenu/row/items/NumberedRowsToggleItem.js +29 -2
- package/dist/cjs/ui/TableMenu/shared/consts.js +4 -2
- package/dist/cjs/ui/TableMenu/shared/getSharedItems.js +5 -2
- package/dist/cjs/ui/TableMenu/shared/getTableMenuComponents.js +2 -2
- package/dist/cjs/ui/TableMenu/shared/items/ClearCellsItem.js +23 -3
- package/dist/cjs/ui/TableMenu/shared/types.js +5 -0
- package/dist/es2019/tablePlugin.js +7 -1
- package/dist/es2019/ui/TableMenu/column/getColumnMenuComponents.js +46 -12
- package/dist/es2019/ui/TableMenu/column/items/AddColumnLeftItem.js +37 -1
- package/dist/es2019/ui/TableMenu/column/items/AddColumnRightItem.js +37 -1
- package/dist/es2019/ui/TableMenu/column/items/ColumnBackgroundSection.js +15 -1
- package/dist/es2019/ui/TableMenu/column/items/ColumnToggleSection.js +15 -1
- package/dist/es2019/ui/TableMenu/column/items/DeleteColumnItem.js +63 -3
- package/dist/es2019/ui/TableMenu/column/items/DistributeColumnsItem.js +43 -7
- package/dist/es2019/ui/TableMenu/column/items/HeaderColumnToggleItem.js +40 -5
- package/dist/es2019/ui/TableMenu/column/items/MoveColumnLeftItem.js +65 -0
- package/dist/es2019/ui/TableMenu/column/items/MoveColumnRightItem.js +44 -3
- package/dist/es2019/ui/TableMenu/column/items/SortDecreasingItem.js +24 -1
- package/dist/es2019/ui/TableMenu/column/items/SortIncreasingItem.js +24 -1
- package/dist/es2019/ui/TableMenu/column/keys.js +7 -2
- package/dist/es2019/ui/TableMenu/row/getRowMenuComponents.js +24 -8
- package/dist/es2019/ui/TableMenu/row/items/AddRowAboveItem.js +27 -1
- package/dist/es2019/ui/TableMenu/row/items/AddRowBelowItem.js +27 -1
- package/dist/es2019/ui/TableMenu/row/items/DeleteRowItem.js +59 -3
- package/dist/es2019/ui/TableMenu/row/items/HeaderRowToggleItem.js +42 -5
- package/dist/es2019/ui/TableMenu/row/items/MoveRowDownItem.js +42 -11
- package/dist/es2019/ui/TableMenu/row/items/MoveRowUpItem.js +42 -11
- package/dist/es2019/ui/TableMenu/row/items/NumberedRowsToggleItem.js +33 -2
- package/dist/es2019/ui/TableMenu/shared/consts.js +3 -1
- package/dist/es2019/ui/TableMenu/shared/getSharedItems.js +6 -2
- package/dist/es2019/ui/TableMenu/shared/getTableMenuComponents.js +1 -1
- package/dist/es2019/ui/TableMenu/shared/items/ClearCellsItem.js +26 -3
- package/dist/es2019/ui/TableMenu/shared/types.js +1 -0
- package/dist/esm/tablePlugin.js +7 -1
- package/dist/esm/ui/TableMenu/column/getColumnMenuComponents.js +47 -12
- package/dist/esm/ui/TableMenu/column/items/AddColumnLeftItem.js +34 -1
- package/dist/esm/ui/TableMenu/column/items/AddColumnRightItem.js +34 -1
- package/dist/esm/ui/TableMenu/column/items/ColumnBackgroundSection.js +15 -2
- package/dist/esm/ui/TableMenu/column/items/ColumnToggleSection.js +15 -2
- package/dist/esm/ui/TableMenu/column/items/DeleteColumnItem.js +60 -3
- package/dist/esm/ui/TableMenu/column/items/DistributeColumnsItem.js +43 -6
- package/dist/esm/ui/TableMenu/column/items/HeaderColumnToggleItem.js +36 -6
- package/dist/esm/ui/TableMenu/column/items/MoveColumnLeftItem.js +62 -0
- package/dist/esm/ui/TableMenu/column/items/MoveColumnRightItem.js +42 -3
- package/dist/esm/ui/TableMenu/column/items/SortDecreasingItem.js +22 -1
- package/dist/esm/ui/TableMenu/column/items/SortIncreasingItem.js +22 -1
- package/dist/esm/ui/TableMenu/column/keys.js +5 -1
- package/dist/esm/ui/TableMenu/row/getRowMenuComponents.js +23 -8
- package/dist/esm/ui/TableMenu/row/items/AddRowAboveItem.js +24 -1
- package/dist/esm/ui/TableMenu/row/items/AddRowBelowItem.js +24 -1
- package/dist/esm/ui/TableMenu/row/items/DeleteRowItem.js +55 -3
- package/dist/esm/ui/TableMenu/row/items/HeaderRowToggleItem.js +38 -6
- package/dist/esm/ui/TableMenu/row/items/MoveRowDownItem.js +39 -14
- package/dist/esm/ui/TableMenu/row/items/MoveRowUpItem.js +39 -14
- package/dist/esm/ui/TableMenu/row/items/NumberedRowsToggleItem.js +29 -2
- package/dist/esm/ui/TableMenu/shared/consts.js +3 -1
- package/dist/esm/ui/TableMenu/shared/getSharedItems.js +5 -2
- package/dist/esm/ui/TableMenu/shared/getTableMenuComponents.js +2 -2
- package/dist/esm/ui/TableMenu/shared/items/ClearCellsItem.js +23 -3
- package/dist/esm/ui/TableMenu/shared/types.js +1 -0
- package/dist/types/types/index.d.ts +2 -1
- package/dist/types/ui/TableMenu/column/getColumnMenuComponents.d.ts +2 -1
- package/dist/types/ui/TableMenu/column/items/AddColumnLeftItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/column/items/AddColumnRightItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/column/items/ColumnBackgroundSection.d.ts +2 -1
- package/dist/types/ui/TableMenu/column/items/ColumnToggleSection.d.ts +2 -1
- package/dist/types/ui/TableMenu/column/items/DeleteColumnItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/column/items/DistributeColumnsItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/column/items/HeaderColumnToggleItem.d.ts +7 -3
- package/dist/types/ui/TableMenu/column/items/MoveColumnLeftItem.d.ts +3 -0
- package/dist/types/ui/TableMenu/column/items/MoveColumnRightItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/column/items/SortDecreasingItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/column/items/SortIncreasingItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/column/keys.d.ts +1 -0
- package/dist/types/ui/TableMenu/row/getRowMenuComponents.d.ts +2 -1
- package/dist/types/ui/TableMenu/row/items/AddRowAboveItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/row/items/AddRowBelowItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/row/items/DeleteRowItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/row/items/HeaderRowToggleItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/row/items/MoveRowDownItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/row/items/MoveRowUpItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/row/items/NumberedRowsToggleItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/shared/consts.d.ts +2 -0
- package/dist/types/ui/TableMenu/shared/getSharedItems.d.ts +2 -1
- package/dist/types/ui/TableMenu/shared/getTableMenuComponents.d.ts +2 -1
- package/dist/types/ui/TableMenu/shared/items/ClearCellsItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/shared/types.d.ts +4 -0
- package/dist/types-ts4.5/types/index.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/column/getColumnMenuComponents.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/column/items/AddColumnLeftItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/column/items/AddColumnRightItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/column/items/ColumnBackgroundSection.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/column/items/ColumnToggleSection.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/column/items/DeleteColumnItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/column/items/DistributeColumnsItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/column/items/HeaderColumnToggleItem.d.ts +7 -3
- package/dist/types-ts4.5/ui/TableMenu/column/items/MoveColumnLeftItem.d.ts +3 -0
- package/dist/types-ts4.5/ui/TableMenu/column/items/MoveColumnRightItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/column/items/SortDecreasingItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/column/items/SortIncreasingItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/column/keys.d.ts +1 -0
- package/dist/types-ts4.5/ui/TableMenu/row/getRowMenuComponents.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/row/items/AddRowAboveItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/row/items/AddRowBelowItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/row/items/DeleteRowItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/row/items/HeaderRowToggleItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/row/items/MoveRowDownItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/row/items/MoveRowUpItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/row/items/NumberedRowsToggleItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/shared/consts.d.ts +2 -0
- package/dist/types-ts4.5/ui/TableMenu/shared/getSharedItems.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/shared/getTableMenuComponents.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/shared/items/ClearCellsItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/shared/types.d.ts +4 -0
- package/package.json +4 -4
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
3
4
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
5
|
+
import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
4
6
|
import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
5
7
|
import Toggle from '@atlaskit/toggle';
|
|
8
|
+
import { toggleHeaderColumnWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
|
|
6
9
|
import { useTableMenuContext } from '../../shared/TableMenuContext';
|
|
7
|
-
|
|
8
10
|
/**
|
|
9
11
|
* Header column toggle is only visible when the first column is the entire
|
|
10
12
|
* selection.
|
|
@@ -13,20 +15,53 @@ import { useTableMenuContext } from '../../shared/TableMenuContext';
|
|
|
13
15
|
* `ColumnBackgroundSection` (which drops its leading separator alongside)
|
|
14
16
|
* can stay in lockstep with this rule without redefining it.
|
|
15
17
|
*/
|
|
16
|
-
export const shouldShowHeaderColumnToggle =
|
|
17
|
-
|
|
18
|
+
export const shouldShowHeaderColumnToggle = ({
|
|
19
|
+
isFirstColumn,
|
|
20
|
+
isHeaderColumnAllowed,
|
|
21
|
+
selectedColumnCount
|
|
22
|
+
}) => isHeaderColumnAllowed === true && isFirstColumn === true && selectedColumnCount === 1;
|
|
23
|
+
export const HeaderColumnToggleItem = props => {
|
|
24
|
+
const {
|
|
25
|
+
api
|
|
26
|
+
} = props;
|
|
27
|
+
const {
|
|
28
|
+
editorView
|
|
29
|
+
} = useEditorToolbar();
|
|
18
30
|
const tableMenuContext = useTableMenuContext();
|
|
31
|
+
const {
|
|
32
|
+
isHeaderColumnAllowed,
|
|
33
|
+
isHeaderColumnEnabled
|
|
34
|
+
} = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], states => {
|
|
35
|
+
var _states$tableState, _states$tableState$pl, _states$tableState2;
|
|
36
|
+
return {
|
|
37
|
+
isHeaderColumnAllowed: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : (_states$tableState$pl = _states$tableState.pluginConfig) === null || _states$tableState$pl === void 0 ? void 0 : _states$tableState$pl.allowHeaderColumn,
|
|
38
|
+
isHeaderColumnEnabled: (_states$tableState2 = states.tableState) === null || _states$tableState2 === void 0 ? void 0 : _states$tableState2.isHeaderColumnEnabled
|
|
39
|
+
};
|
|
40
|
+
});
|
|
19
41
|
const {
|
|
20
42
|
formatMessage
|
|
21
43
|
} = useIntl();
|
|
22
44
|
const label = formatMessage(messages.headerColumn);
|
|
23
|
-
|
|
45
|
+
const handleClick = () => {
|
|
46
|
+
var _api$analytics;
|
|
47
|
+
if (!editorView) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
toggleHeaderColumnWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(editorView.state, editorView.dispatch);
|
|
51
|
+
};
|
|
52
|
+
if (!shouldShowHeaderColumnToggle({
|
|
53
|
+
isFirstColumn: tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstColumn,
|
|
54
|
+
isHeaderColumnAllowed,
|
|
55
|
+
selectedColumnCount: tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount
|
|
56
|
+
})) {
|
|
24
57
|
return null;
|
|
25
58
|
}
|
|
26
59
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
60
|
+
onClick: handleClick,
|
|
27
61
|
elemAfter: /*#__PURE__*/React.createElement(Toggle, {
|
|
28
62
|
label: label,
|
|
29
|
-
isChecked:
|
|
63
|
+
isChecked: !!isHeaderColumnEnabled,
|
|
64
|
+
onChange: handleClick
|
|
30
65
|
})
|
|
31
66
|
}, label);
|
|
32
67
|
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
5
|
+
import { moveColumnLeft, tooltip } from '@atlaskit/editor-common/keymaps';
|
|
6
|
+
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
7
|
+
import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
8
|
+
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
9
|
+
import { ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
|
|
10
|
+
import TableColumnMoveLeftIcon from '@atlaskit/icon/core/table-column-move-left';
|
|
11
|
+
import { moveSourceWithAnalytics } from '../../../../pm-plugins/drag-and-drop/commands-with-analytics';
|
|
12
|
+
import { getPluginState } from '../../../../pm-plugins/plugin-factory';
|
|
13
|
+
import { getSelectedColumnIndexes } from '../../../../pm-plugins/utils/selection';
|
|
14
|
+
import { TABLE_COLUMN } from '../../shared/consts';
|
|
15
|
+
import { useTableMenuContext } from '../../shared/TableMenuContext';
|
|
16
|
+
const shouldShowMoveColumnLeft = isFirstColumn => !isFirstColumn;
|
|
17
|
+
export const MoveColumnLeftItem = props => {
|
|
18
|
+
var _tableMenuContext$sel, _tooltip;
|
|
19
|
+
const {
|
|
20
|
+
api
|
|
21
|
+
} = props;
|
|
22
|
+
const {
|
|
23
|
+
editorView
|
|
24
|
+
} = useEditorToolbar();
|
|
25
|
+
const tableMenuContext = useTableMenuContext();
|
|
26
|
+
const {
|
|
27
|
+
tableNode
|
|
28
|
+
} = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], states => {
|
|
29
|
+
var _states$tableState;
|
|
30
|
+
return {
|
|
31
|
+
tableNode: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : _states$tableState.tableNode
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
const selectedColumnCount = (_tableMenuContext$sel = tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount) !== null && _tableMenuContext$sel !== void 0 ? _tableMenuContext$sel : 1;
|
|
35
|
+
const {
|
|
36
|
+
formatMessage
|
|
37
|
+
} = useIntl();
|
|
38
|
+
const handleClick = () => {
|
|
39
|
+
var _api$analytics, _api$accessibilityUti;
|
|
40
|
+
if (!editorView) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const selectionRect = getSelectionRect(editorView.state.selection);
|
|
44
|
+
if (!selectionRect) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
moveSourceWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api === null || api === void 0 ? void 0 : (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 ? void 0 : _api$accessibilityUti.actions.ariaNotify, getPluginState(editorView.state).getIntl)(INPUT_METHOD.TABLE_CONTEXT_MENU, TABLE_COLUMN, getSelectedColumnIndexes(selectionRect), selectionRect.left - 1)(editorView.state, editorView.dispatch);
|
|
48
|
+
};
|
|
49
|
+
if (!tableNode || !shouldShowMoveColumnLeft(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstColumn)) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
53
|
+
onClick: handleClick,
|
|
54
|
+
elemBefore: /*#__PURE__*/React.createElement(TableColumnMoveLeftIcon, {
|
|
55
|
+
color: "currentColor",
|
|
56
|
+
label: "",
|
|
57
|
+
size: "small"
|
|
58
|
+
}),
|
|
59
|
+
elemAfter: /*#__PURE__*/React.createElement(ToolbarKeyboardShortcutHint, {
|
|
60
|
+
shortcut: (_tooltip = tooltip(moveColumnLeft)) !== null && _tooltip !== void 0 ? _tooltip : ''
|
|
61
|
+
})
|
|
62
|
+
}, formatMessage(messages.moveColumnLeft, {
|
|
63
|
+
0: selectedColumnCount
|
|
64
|
+
}));
|
|
65
|
+
};
|
|
@@ -1,14 +1,55 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
3
5
|
import { moveColumnRight, tooltip } from '@atlaskit/editor-common/keymaps';
|
|
4
6
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
7
|
+
import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
8
|
+
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
5
9
|
import { TableColumnMoveRightIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
import { moveSourceWithAnalytics } from '../../../../pm-plugins/drag-and-drop/commands-with-analytics';
|
|
11
|
+
import { getPluginState } from '../../../../pm-plugins/plugin-factory';
|
|
12
|
+
import { getSelectedColumnIndexes } from '../../../../pm-plugins/utils/selection';
|
|
13
|
+
import { TABLE_COLUMN } from '../../shared/consts';
|
|
14
|
+
import { useTableMenuContext } from '../../shared/TableMenuContext';
|
|
15
|
+
const shouldShowMoveColumnRight = isLastColumn => !isLastColumn;
|
|
16
|
+
export const MoveColumnRightItem = props => {
|
|
17
|
+
var _tableMenuContext$sel, _tooltip;
|
|
18
|
+
const {
|
|
19
|
+
api
|
|
20
|
+
} = props;
|
|
21
|
+
const {
|
|
22
|
+
editorView
|
|
23
|
+
} = useEditorToolbar();
|
|
24
|
+
const tableMenuContext = useTableMenuContext();
|
|
25
|
+
const {
|
|
26
|
+
tableNode
|
|
27
|
+
} = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], states => {
|
|
28
|
+
var _states$tableState;
|
|
29
|
+
return {
|
|
30
|
+
tableNode: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : _states$tableState.tableNode
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
const selectedColumnCount = (_tableMenuContext$sel = tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount) !== null && _tableMenuContext$sel !== void 0 ? _tableMenuContext$sel : 1;
|
|
8
34
|
const {
|
|
9
35
|
formatMessage
|
|
10
36
|
} = useIntl();
|
|
37
|
+
const handleClick = () => {
|
|
38
|
+
var _api$analytics, _api$accessibilityUti;
|
|
39
|
+
if (!editorView) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const selectionRect = getSelectionRect(editorView.state.selection);
|
|
43
|
+
if (!selectionRect) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
moveSourceWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api === null || api === void 0 ? void 0 : (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 ? void 0 : _api$accessibilityUti.actions.ariaNotify, getPluginState(editorView.state).getIntl)(INPUT_METHOD.TABLE_CONTEXT_MENU, TABLE_COLUMN, getSelectedColumnIndexes(selectionRect), selectionRect.right)(editorView.state, editorView.dispatch);
|
|
47
|
+
};
|
|
48
|
+
if (!tableNode || !shouldShowMoveColumnRight(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isLastColumn)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
11
51
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
52
|
+
onClick: handleClick,
|
|
12
53
|
elemBefore: /*#__PURE__*/React.createElement(TableColumnMoveRightIcon, {
|
|
13
54
|
color: "currentColor",
|
|
14
55
|
label: "",
|
|
@@ -18,6 +59,6 @@ export const MoveColumnRightItem = () => {
|
|
|
18
59
|
shortcut: (_tooltip = tooltip(moveColumnRight)) !== null && _tooltip !== void 0 ? _tooltip : ''
|
|
19
60
|
})
|
|
20
61
|
}, formatMessage(messages.moveColumnRight, {
|
|
21
|
-
0:
|
|
62
|
+
0: selectedColumnCount
|
|
22
63
|
}));
|
|
23
64
|
};
|
|
@@ -1,14 +1,37 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
|
+
import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
|
|
4
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
5
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
6
|
+
import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
7
|
+
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
4
8
|
import { ArrowDownIcon, ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
9
|
+
import { sortColumnWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
|
|
5
10
|
import { useTableMenuContext } from '../../shared/TableMenuContext';
|
|
6
|
-
export const SortDecreasingItem = (
|
|
11
|
+
export const SortDecreasingItem = ({
|
|
12
|
+
api
|
|
13
|
+
}) => {
|
|
14
|
+
const {
|
|
15
|
+
editorView
|
|
16
|
+
} = useEditorToolbar();
|
|
7
17
|
const tableMenuContext = useTableMenuContext();
|
|
8
18
|
const {
|
|
9
19
|
formatMessage
|
|
10
20
|
} = useIntl();
|
|
21
|
+
const handleClick = () => {
|
|
22
|
+
var _api$analytics;
|
|
23
|
+
if (!editorView) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const selectionRect = getSelectionRect(editorView.state.selection);
|
|
27
|
+
const columnIndex = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.left;
|
|
28
|
+
if (columnIndex === undefined) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
sortColumnWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, columnIndex, SortOrder.DESC)(editorView.state, editorView.dispatch);
|
|
32
|
+
};
|
|
11
33
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
34
|
+
onClick: handleClick,
|
|
12
35
|
isDisabled: Boolean(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.hasMergedCellsInTable),
|
|
13
36
|
elemBefore: /*#__PURE__*/React.createElement(ArrowDownIcon, {
|
|
14
37
|
color: "currentColor",
|
|
@@ -1,14 +1,37 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
|
+
import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
|
|
4
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
5
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
6
|
+
import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
7
|
+
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
4
8
|
import { ArrowUpIcon, ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
9
|
+
import { sortColumnWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
|
|
5
10
|
import { useTableMenuContext } from '../../shared/TableMenuContext';
|
|
6
|
-
export const SortIncreasingItem = (
|
|
11
|
+
export const SortIncreasingItem = ({
|
|
12
|
+
api
|
|
13
|
+
}) => {
|
|
14
|
+
const {
|
|
15
|
+
editorView
|
|
16
|
+
} = useEditorToolbar();
|
|
7
17
|
const tableMenuContext = useTableMenuContext();
|
|
8
18
|
const {
|
|
9
19
|
formatMessage
|
|
10
20
|
} = useIntl();
|
|
21
|
+
const handleClick = () => {
|
|
22
|
+
var _api$analytics;
|
|
23
|
+
if (!editorView) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const selectionRect = getSelectionRect(editorView.state.selection);
|
|
27
|
+
const columnIndex = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.left;
|
|
28
|
+
if (columnIndex === undefined) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
sortColumnWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, columnIndex, SortOrder.ASC)(editorView.state, editorView.dispatch);
|
|
32
|
+
};
|
|
11
33
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
34
|
+
onClick: handleClick,
|
|
12
35
|
isDisabled: Boolean(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.hasMergedCellsInTable),
|
|
13
36
|
elemBefore: /*#__PURE__*/React.createElement(ArrowUpIcon, {
|
|
14
37
|
color: "currentColor",
|
|
@@ -56,6 +56,10 @@ export const ADD_COLUMN_RIGHT_ITEM = {
|
|
|
56
56
|
type: 'menu-item',
|
|
57
57
|
key: 'add-column-right'
|
|
58
58
|
};
|
|
59
|
+
export const MOVE_COLUMN_LEFT_ITEM = {
|
|
60
|
+
type: 'menu-item',
|
|
61
|
+
key: 'move-column-left'
|
|
62
|
+
};
|
|
59
63
|
export const MOVE_COLUMN_RIGHT_ITEM = {
|
|
60
64
|
type: 'menu-item',
|
|
61
65
|
key: 'move-column-right'
|
|
@@ -84,8 +88,9 @@ export const COLUMN_SORT_SECTION_RANK = {
|
|
|
84
88
|
export const COLUMN_ADD_SECTION_RANK = {
|
|
85
89
|
[ADD_COLUMN_LEFT_ITEM.key]: 100,
|
|
86
90
|
[ADD_COLUMN_RIGHT_ITEM.key]: 200,
|
|
87
|
-
[
|
|
88
|
-
[
|
|
91
|
+
[MOVE_COLUMN_LEFT_ITEM.key]: 300,
|
|
92
|
+
[MOVE_COLUMN_RIGHT_ITEM.key]: 400,
|
|
93
|
+
[DISTRIBUTE_COLUMNS_ITEM.key]: 500
|
|
89
94
|
};
|
|
90
95
|
export const COLUMN_DANGER_SECTION_RANK = {
|
|
91
96
|
[CLEAR_CELLS_ITEM.key]: 100,
|
|
@@ -8,7 +8,9 @@ import { MoveRowDownItem } from './items/MoveRowDownItem';
|
|
|
8
8
|
import { MoveRowUpItem } from './items/MoveRowUpItem';
|
|
9
9
|
import { NumberedRowsToggleItem } from './items/NumberedRowsToggleItem';
|
|
10
10
|
import { ROW_MENU, ROW_TOGGLE_SECTION, ROW_BACKGROUND_SECTION, ROW_ADD_SECTION, ROW_DANGER_SECTION, ROW_MENU_SECTION_RANK, HEADER_ROW_TOGGLE_ITEM, NUMBERED_ROWS_TOGGLE_ITEM, ADD_ROW_ABOVE_ITEM, ADD_ROW_BELOW_ITEM, MOVE_ROW_UP_ITEM, MOVE_ROW_DOWN_ITEM, DELETE_ROW_ITEM, ROW_TOGGLE_SECTION_RANK, ROW_ADD_SECTION_RANK, ROW_DANGER_SECTION_RANK } from './keys';
|
|
11
|
-
export const getRowMenuComponents = (
|
|
11
|
+
export const getRowMenuComponents = ({
|
|
12
|
+
api
|
|
13
|
+
}) => [
|
|
12
14
|
// --- Menu surface ---
|
|
13
15
|
{
|
|
14
16
|
type: ROW_MENU.type,
|
|
@@ -32,7 +34,9 @@ export const getRowMenuComponents = () => [
|
|
|
32
34
|
key: ROW_TOGGLE_SECTION.key,
|
|
33
35
|
rank: ROW_TOGGLE_SECTION_RANK[HEADER_ROW_TOGGLE_ITEM.key]
|
|
34
36
|
}],
|
|
35
|
-
component: () => /*#__PURE__*/React.createElement(HeaderRowToggleItem,
|
|
37
|
+
component: () => /*#__PURE__*/React.createElement(HeaderRowToggleItem, {
|
|
38
|
+
api: api
|
|
39
|
+
})
|
|
36
40
|
}, {
|
|
37
41
|
type: NUMBERED_ROWS_TOGGLE_ITEM.type,
|
|
38
42
|
key: NUMBERED_ROWS_TOGGLE_ITEM.key,
|
|
@@ -41,7 +45,9 @@ export const getRowMenuComponents = () => [
|
|
|
41
45
|
key: ROW_TOGGLE_SECTION.key,
|
|
42
46
|
rank: ROW_TOGGLE_SECTION_RANK[NUMBERED_ROWS_TOGGLE_ITEM.key]
|
|
43
47
|
}],
|
|
44
|
-
component: () => /*#__PURE__*/React.createElement(NumberedRowsToggleItem,
|
|
48
|
+
component: () => /*#__PURE__*/React.createElement(NumberedRowsToggleItem, {
|
|
49
|
+
api: api
|
|
50
|
+
})
|
|
45
51
|
},
|
|
46
52
|
// --- Background color section ---
|
|
47
53
|
{
|
|
@@ -76,7 +82,9 @@ export const getRowMenuComponents = () => [
|
|
|
76
82
|
key: ROW_ADD_SECTION.key,
|
|
77
83
|
rank: ROW_ADD_SECTION_RANK[ADD_ROW_ABOVE_ITEM.key]
|
|
78
84
|
}],
|
|
79
|
-
component: () => /*#__PURE__*/React.createElement(AddRowAboveItem,
|
|
85
|
+
component: () => /*#__PURE__*/React.createElement(AddRowAboveItem, {
|
|
86
|
+
api: api
|
|
87
|
+
})
|
|
80
88
|
}, {
|
|
81
89
|
type: ADD_ROW_BELOW_ITEM.type,
|
|
82
90
|
key: ADD_ROW_BELOW_ITEM.key,
|
|
@@ -85,7 +93,9 @@ export const getRowMenuComponents = () => [
|
|
|
85
93
|
key: ROW_ADD_SECTION.key,
|
|
86
94
|
rank: ROW_ADD_SECTION_RANK[ADD_ROW_BELOW_ITEM.key]
|
|
87
95
|
}],
|
|
88
|
-
component: () => /*#__PURE__*/React.createElement(AddRowBelowItem,
|
|
96
|
+
component: () => /*#__PURE__*/React.createElement(AddRowBelowItem, {
|
|
97
|
+
api: api
|
|
98
|
+
})
|
|
89
99
|
}, {
|
|
90
100
|
type: MOVE_ROW_UP_ITEM.type,
|
|
91
101
|
key: MOVE_ROW_UP_ITEM.key,
|
|
@@ -94,7 +104,9 @@ export const getRowMenuComponents = () => [
|
|
|
94
104
|
key: ROW_ADD_SECTION.key,
|
|
95
105
|
rank: ROW_ADD_SECTION_RANK[MOVE_ROW_UP_ITEM.key]
|
|
96
106
|
}],
|
|
97
|
-
component: () => /*#__PURE__*/React.createElement(MoveRowUpItem,
|
|
107
|
+
component: () => /*#__PURE__*/React.createElement(MoveRowUpItem, {
|
|
108
|
+
api: api
|
|
109
|
+
})
|
|
98
110
|
}, {
|
|
99
111
|
type: MOVE_ROW_DOWN_ITEM.type,
|
|
100
112
|
key: MOVE_ROW_DOWN_ITEM.key,
|
|
@@ -103,7 +115,9 @@ export const getRowMenuComponents = () => [
|
|
|
103
115
|
key: ROW_ADD_SECTION.key,
|
|
104
116
|
rank: ROW_ADD_SECTION_RANK[MOVE_ROW_DOWN_ITEM.key]
|
|
105
117
|
}],
|
|
106
|
-
component: () => /*#__PURE__*/React.createElement(MoveRowDownItem,
|
|
118
|
+
component: () => /*#__PURE__*/React.createElement(MoveRowDownItem, {
|
|
119
|
+
api: api
|
|
120
|
+
})
|
|
107
121
|
},
|
|
108
122
|
// --- Danger section (Clear cells, Delete row) ---
|
|
109
123
|
{
|
|
@@ -125,5 +139,7 @@ export const getRowMenuComponents = () => [
|
|
|
125
139
|
key: ROW_DANGER_SECTION.key,
|
|
126
140
|
rank: ROW_DANGER_SECTION_RANK[DELETE_ROW_ITEM.key]
|
|
127
141
|
}],
|
|
128
|
-
component: () => /*#__PURE__*/React.createElement(DeleteRowItem,
|
|
142
|
+
component: () => /*#__PURE__*/React.createElement(DeleteRowItem, {
|
|
143
|
+
api: api
|
|
144
|
+
})
|
|
129
145
|
}];
|
|
@@ -1,14 +1,40 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
4
|
import { addRowBefore, tooltip } from '@atlaskit/editor-common/keymaps';
|
|
4
5
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
6
|
+
import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
7
|
+
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
5
8
|
import { TableRowAddAboveIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
|
|
6
|
-
|
|
9
|
+
import { insertRowWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
|
|
10
|
+
export const AddRowAboveItem = props => {
|
|
7
11
|
var _tooltip;
|
|
12
|
+
const {
|
|
13
|
+
api
|
|
14
|
+
} = props;
|
|
15
|
+
const {
|
|
16
|
+
editorView
|
|
17
|
+
} = useEditorToolbar();
|
|
8
18
|
const {
|
|
9
19
|
formatMessage
|
|
10
20
|
} = useIntl();
|
|
21
|
+
const handleClick = () => {
|
|
22
|
+
var _api$analytics;
|
|
23
|
+
if (!editorView) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const selectionRect = getSelectionRect(editorView.state.selection);
|
|
27
|
+
const index = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.top;
|
|
28
|
+
if (index === undefined) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
insertRowWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, {
|
|
32
|
+
index,
|
|
33
|
+
moveCursorToInsertedRow: true
|
|
34
|
+
})(editorView.state, editorView.dispatch);
|
|
35
|
+
};
|
|
11
36
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
37
|
+
onClick: handleClick,
|
|
12
38
|
elemBefore: /*#__PURE__*/React.createElement(TableRowAddAboveIcon, {
|
|
13
39
|
color: "currentColor",
|
|
14
40
|
label: "",
|
|
@@ -1,14 +1,40 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
4
|
import { addRowAfter, tooltip } from '@atlaskit/editor-common/keymaps';
|
|
4
5
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
6
|
+
import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
7
|
+
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
5
8
|
import { TableRowAddBelowIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
|
|
6
|
-
|
|
9
|
+
import { insertRowWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
|
|
10
|
+
export const AddRowBelowItem = props => {
|
|
7
11
|
var _tooltip;
|
|
12
|
+
const {
|
|
13
|
+
api
|
|
14
|
+
} = props;
|
|
15
|
+
const {
|
|
16
|
+
editorView
|
|
17
|
+
} = useEditorToolbar();
|
|
8
18
|
const {
|
|
9
19
|
formatMessage
|
|
10
20
|
} = useIntl();
|
|
21
|
+
const handleClick = () => {
|
|
22
|
+
var _api$analytics;
|
|
23
|
+
if (!editorView) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const selectionRect = getSelectionRect(editorView.state.selection);
|
|
27
|
+
const index = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.bottom;
|
|
28
|
+
if (index === undefined) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
insertRowWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, {
|
|
32
|
+
index,
|
|
33
|
+
moveCursorToInsertedRow: true
|
|
34
|
+
})(editorView.state, editorView.dispatch);
|
|
35
|
+
};
|
|
11
36
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
37
|
+
onClick: handleClick,
|
|
12
38
|
elemBefore: /*#__PURE__*/React.createElement(TableRowAddBelowIcon, {
|
|
13
39
|
color: "currentColor",
|
|
14
40
|
label: "",
|
|
@@ -1,14 +1,70 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
3
5
|
import { deleteRow, tooltip } from '@atlaskit/editor-common/keymaps';
|
|
4
6
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
7
|
+
import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
8
|
+
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
5
9
|
import { DeleteIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
import { clearHoverSelection, hoverRows } from '../../../../pm-plugins/commands';
|
|
11
|
+
import { deleteRowsWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
|
|
12
|
+
import { getSelectedRowIndexes } from '../../../../pm-plugins/utils/selection';
|
|
13
|
+
import { useTableMenuContext } from '../../shared/TableMenuContext';
|
|
14
|
+
export const DeleteRowItem = props => {
|
|
15
|
+
var _tableMenuContext$sel, _tooltip;
|
|
16
|
+
const {
|
|
17
|
+
api
|
|
18
|
+
} = props;
|
|
19
|
+
const {
|
|
20
|
+
editorView
|
|
21
|
+
} = useEditorToolbar();
|
|
22
|
+
const tableMenuContext = useTableMenuContext();
|
|
23
|
+
const {
|
|
24
|
+
isHeaderRowRequired
|
|
25
|
+
} = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], states => {
|
|
26
|
+
var _states$tableState, _states$tableState$pl;
|
|
27
|
+
return {
|
|
28
|
+
isHeaderRowRequired: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : (_states$tableState$pl = _states$tableState.pluginConfig) === null || _states$tableState$pl === void 0 ? void 0 : _states$tableState$pl.isHeaderRowRequired
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
const selectedRowCount = (_tableMenuContext$sel = tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedRowCount) !== null && _tableMenuContext$sel !== void 0 ? _tableMenuContext$sel : 1;
|
|
8
32
|
const {
|
|
9
33
|
formatMessage
|
|
10
34
|
} = useIntl();
|
|
35
|
+
const handleMouseEnter = () => {
|
|
36
|
+
if (!editorView) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const selectionRect = getSelectionRect(editorView.state.selection);
|
|
40
|
+
if (!selectionRect) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
hoverRows(getSelectedRowIndexes(selectionRect), true)(editorView.state, editorView.dispatch);
|
|
44
|
+
};
|
|
45
|
+
const handleMouseLeave = () => {
|
|
46
|
+
if (!editorView) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
clearHoverSelection()(editorView.state, editorView.dispatch);
|
|
50
|
+
};
|
|
51
|
+
const handleClick = () => {
|
|
52
|
+
var _api$analytics;
|
|
53
|
+
if (!editorView) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const selectionRect = getSelectionRect(editorView.state.selection);
|
|
57
|
+
if (!selectionRect) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
deleteRowsWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, selectionRect, !!isHeaderRowRequired)(editorView.state, editorView.dispatch);
|
|
61
|
+
};
|
|
11
62
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
63
|
+
onClick: handleClick,
|
|
64
|
+
onFocus: handleMouseEnter,
|
|
65
|
+
onMouseEnter: handleMouseEnter,
|
|
66
|
+
onBlur: handleMouseLeave,
|
|
67
|
+
onMouseLeave: handleMouseLeave,
|
|
12
68
|
elemBefore: /*#__PURE__*/React.createElement(DeleteIcon, {
|
|
13
69
|
color: "currentColor",
|
|
14
70
|
label: "",
|
|
@@ -18,6 +74,6 @@ export const DeleteRowItem = () => {
|
|
|
18
74
|
shortcut: (_tooltip = tooltip(deleteRow)) !== null && _tooltip !== void 0 ? _tooltip : ''
|
|
19
75
|
})
|
|
20
76
|
}, formatMessage(messages.removeRows, {
|
|
21
|
-
0:
|
|
77
|
+
0: selectedRowCount
|
|
22
78
|
}));
|
|
23
79
|
};
|
|
@@ -1,25 +1,62 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
3
4
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
5
|
+
import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
4
6
|
import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
5
7
|
import Toggle from '@atlaskit/toggle';
|
|
8
|
+
import { toggleHeaderRowWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
|
|
6
9
|
import { useTableMenuContext } from '../../shared/TableMenuContext';
|
|
7
|
-
|
|
8
10
|
/** Header row toggle is only visible when the first row is the entire selection. */
|
|
9
|
-
const shouldShowHeaderRowToggle =
|
|
10
|
-
|
|
11
|
+
const shouldShowHeaderRowToggle = ({
|
|
12
|
+
isFirstRow,
|
|
13
|
+
isHeaderRowAllowed,
|
|
14
|
+
selectedRowCount
|
|
15
|
+
}) => isHeaderRowAllowed === true && isFirstRow && selectedRowCount === 1;
|
|
16
|
+
export const HeaderRowToggleItem = props => {
|
|
17
|
+
var _tableMenuContext$sel;
|
|
18
|
+
const {
|
|
19
|
+
api
|
|
20
|
+
} = props;
|
|
21
|
+
const {
|
|
22
|
+
editorView
|
|
23
|
+
} = useEditorToolbar();
|
|
11
24
|
const tableMenuContext = useTableMenuContext();
|
|
25
|
+
const {
|
|
26
|
+
isHeaderRowAllowed,
|
|
27
|
+
isHeaderRowEnabled
|
|
28
|
+
} = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], states => {
|
|
29
|
+
var _states$tableState, _states$tableState$pl, _states$tableState2;
|
|
30
|
+
return {
|
|
31
|
+
isHeaderRowAllowed: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : (_states$tableState$pl = _states$tableState.pluginConfig) === null || _states$tableState$pl === void 0 ? void 0 : _states$tableState$pl.allowHeaderRow,
|
|
32
|
+
isHeaderRowEnabled: (_states$tableState2 = states.tableState) === null || _states$tableState2 === void 0 ? void 0 : _states$tableState2.isHeaderRowEnabled
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
const selectedRowCount = (_tableMenuContext$sel = tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedRowCount) !== null && _tableMenuContext$sel !== void 0 ? _tableMenuContext$sel : 0;
|
|
12
36
|
const {
|
|
13
37
|
formatMessage
|
|
14
38
|
} = useIntl();
|
|
15
39
|
const label = formatMessage(messages.headerRow);
|
|
16
|
-
|
|
40
|
+
const handleClick = () => {
|
|
41
|
+
var _api$analytics;
|
|
42
|
+
if (!editorView) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
toggleHeaderRowWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(editorView.state, editorView.dispatch);
|
|
46
|
+
};
|
|
47
|
+
if (!shouldShowHeaderRowToggle({
|
|
48
|
+
isFirstRow: (tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstRow) === true,
|
|
49
|
+
isHeaderRowAllowed,
|
|
50
|
+
selectedRowCount
|
|
51
|
+
})) {
|
|
17
52
|
return null;
|
|
18
53
|
}
|
|
19
54
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
55
|
+
onClick: handleClick,
|
|
20
56
|
elemAfter: /*#__PURE__*/React.createElement(Toggle, {
|
|
21
57
|
label: label,
|
|
22
|
-
isChecked:
|
|
58
|
+
isChecked: !!isHeaderRowEnabled,
|
|
59
|
+
onChange: handleClick
|
|
23
60
|
})
|
|
24
61
|
}, label);
|
|
25
62
|
};
|