UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

41 lines 2.19 kB
import React from 'react'; import { useIntl } from 'react-intl'; import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps'; import { INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { tableMessages as messages } from '@atlaskit/editor-common/messages'; import { getSelectionRect } from '@atlaskit/editor-tables/utils'; import { ArrowUpIcon, ToolbarDropdownItem } from '@atlaskit/editor-toolbar'; import { closeActiveTableMenu } from '../../../../pm-plugins/commands'; import { sortColumnWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics'; import { useTableMenuContext } from '../../shared/TableMenuContext'; export var SortIncreasingItem = function SortIncreasingItem(_ref) { var api = _ref.api; var tableMenuContext = useTableMenuContext(); var _ref2 = tableMenuContext !== null && tableMenuContext !== void 0 ? tableMenuContext : {}, editorView = _ref2.editorView; var _useIntl = useIntl(), formatMessage = _useIntl.formatMessage; var handleClick = function handleClick() { var _api$analytics; if (!editorView) { return; } var selectionRect = getSelectionRect(editorView.state.selection); var columnIndex = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.left; if (columnIndex === undefined) { return; } sortColumnWithAnalytics(api === null || api === 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); api === null || api === void 0 || api.core.actions.execute(closeActiveTableMenu()); api === null || api === void 0 || api.core.actions.focus(); }; return /*#__PURE__*/React.createElement(ToolbarDropdownItem, { onClick: handleClick, isDisabled: Boolean(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.hasMergedCellsInTable), elemBefore: /*#__PURE__*/React.createElement(ArrowUpIcon, { color: "currentColor", label: "", size: "small" }) }, formatMessage(messages.sortColumnIncreasing)); };