UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

49 lines (48 loc) 2.35 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.SplitCellItem = void 0; var _react = _interopRequireDefault(require("react")); var _reactIntl = require("react-intl"); var _analytics = require("@atlaskit/editor-common/analytics"); var _messages = require("@atlaskit/editor-common/messages"); 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"); /** * Split cell is only visible when the active selection sits in a cell whose * `rowspan` or `colspan` is greater than one. */ var shouldShowSplitCell = function shouldShowSplitCell(tableMenuContext) { return (tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.canSplitCell) === true; }; var SplitCellItem = exports.SplitCellItem = function SplitCellItem(_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.splitCellWithAnalytics)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(_analytics.INPUT_METHOD.CONTEXT_MENU)(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(); }; if (!shouldShowSplitCell(tableMenuContext)) { return null; } return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, { onClick: handleClick, elemBefore: /*#__PURE__*/_react.default.createElement(_editorToolbar.TableCellSplitIcon, { label: "", size: "small" }) }, formatMessage(_messages.tableMessages.splitCell)); };