UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

43 lines 1.9 kB
import React from 'react'; import { useIntl } from 'react-intl'; import { INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { tableMessages as messages } from '@atlaskit/editor-common/messages'; import { TableCellMergeIcon, ToolbarDropdownItem } from '@atlaskit/editor-toolbar'; import { closeActiveTableMenu } from '../../../../pm-plugins/commands'; import { mergeCellsWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics'; import { useTableMenuContext } from '../../shared/TableMenuContext'; /** * Merge cells is only visible when the active selection can actually be merged * (multi-cell, non-overlapping). */ const shouldShowMergeCells = tableMenuContext => (tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.canMergeCells) === true; export const MergeCellsItem = ({ api }) => { const tableMenuContext = useTableMenuContext(); const { editorView } = tableMenuContext !== null && tableMenuContext !== void 0 ? tableMenuContext : {}; const { formatMessage } = useIntl(); const handleClick = () => { var _api$analytics; if (!editorView) { return; } mergeCellsWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.CONTEXT_MENU)(editorView.state, editorView.dispatch); api === null || api === void 0 ? void 0 : api.core.actions.execute(closeActiveTableMenu()); api === null || api === void 0 ? void 0 : api.core.actions.focus(); }; if (!shouldShowMergeCells(tableMenuContext)) { return null; } return /*#__PURE__*/React.createElement(ToolbarDropdownItem, { onClick: handleClick, elemBefore: /*#__PURE__*/React.createElement(TableCellMergeIcon, { label: "", size: "small" }) }, formatMessage(messages.mergeCells)); };