UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

50 lines (49 loc) • 2.46 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.MergeCellsItem = void 0; var _react = _interopRequireDefault(require("react")); var _reactIntl = require("react-intl"); var _enums = require("@atlaskit/editor-common/analytics/types/enums"); var _table = require("@atlaskit/editor-common/messages/table"); var _cellMergeIcon = require("@atlaskit/editor-toolbar/cell-merge-icon"); var _toolbarDropdownItem = require("@atlaskit/editor-toolbar/toolbar-dropdown-item"); var _commands = require("../../../../pm-plugins/commands"); var _commandsWithAnalytics = require("../../../../pm-plugins/commands/commands-with-analytics"); var _TableMenuContext = require("../../shared/TableMenuContext"); /** * Merge cells is only visible when the active selection can actually be merged * (multi-cell, non-overlapping). */ var shouldShowMergeCells = function shouldShowMergeCells(tableMenuContext) { return (tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.canMergeCells) === true; }; var MergeCellsItem = exports.MergeCellsItem = function MergeCellsItem(_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; } (0, _commandsWithAnalytics.mergeCellsWithAnalytics)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(_enums.INPUT_METHOD.CONTEXT_MENU)(editorView.state, editorView.dispatch); api === null || api === void 0 || api.core.actions.execute((0, _commands.closeActiveTableMenu)(api)); api === null || api === void 0 || api.core.actions.focus(); }; if (!shouldShowMergeCells(tableMenuContext)) { return null; } return /*#__PURE__*/_react.default.createElement(_toolbarDropdownItem.ToolbarDropdownItem, { onClick: handleClick, elemBefore: /*#__PURE__*/_react.default.createElement(_cellMergeIcon.TableCellMergeIcon, { label: "", size: "small" }) }, formatMessage(_table.messages.mergeCells)); };