UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

48 lines (47 loc) 2.55 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.SortDecreasingItem = void 0; var _react = _interopRequireDefault(require("react")); var _reactIntl = require("react-intl"); var _customSteps = require("@atlaskit/custom-steps"); var _analytics = require("@atlaskit/editor-common/analytics"); var _messages = require("@atlaskit/editor-common/messages"); var _utils = require("@atlaskit/editor-tables/utils"); var _editorToolbar = require("@atlaskit/editor-toolbar"); var _commands = require("../../../../pm-plugins/commands"); var _commandsWithAnalytics = require("../../../../pm-plugins/commands/commands-with-analytics"); var _TableMenuContext = require("../../shared/TableMenuContext"); var SortDecreasingItem = exports.SortDecreasingItem = function SortDecreasingItem(_ref) { var api = _ref.api; var tableMenuContext = (0, _TableMenuContext.useTableMenuContext)(); var _ref2 = tableMenuContext !== null && tableMenuContext !== void 0 ? tableMenuContext : {}, editorView = _ref2.editorView; var _useIntl = (0, _reactIntl.useIntl)(), formatMessage = _useIntl.formatMessage; var handleClick = function handleClick() { var _api$analytics; if (!editorView) { return; } var selectionRect = (0, _utils.getSelectionRect)(editorView.state.selection); var columnIndex = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.left; if (columnIndex === undefined) { return; } (0, _commandsWithAnalytics.sortColumnWithAnalytics)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(_analytics.INPUT_METHOD.TABLE_CONTEXT_MENU, columnIndex, _customSteps.TableSortOrder.DESC)(editorView.state, editorView.dispatch); api === null || api === void 0 || api.core.actions.execute((0, _commands.closeActiveTableMenu)()); api === null || api === void 0 || api.core.actions.focus(); }; return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, { onClick: handleClick, isDisabled: Boolean(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.hasMergedCellsInTable), elemBefore: /*#__PURE__*/_react.default.createElement(_editorToolbar.ArrowDownIcon, { color: "currentColor", label: "", size: "small" }) }, formatMessage(_messages.tableMessages.sortColumnDecreasing)); };