UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

44 lines 2.68 kB
import React from 'react'; import { useIntl } from 'react-intl'; import { INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { backspace, tooltip } from '@atlaskit/editor-common/keymaps'; import { tableMessages as messages } from '@atlaskit/editor-common/messages'; import { CrossIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar'; import { closeActiveTableMenu } from '../../../../pm-plugins/commands'; import { emptyMultipleCellsWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics'; import { getPluginState } from '../../../../pm-plugins/plugin-factory'; import { useTableMenuContext } from '../TableMenuContext'; export var ClearCellsItem = function ClearCellsItem(_ref) { var _tableMenuContext$sel, _tableMenuContext$sel2, _tooltip; 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 selectedCellCount = Math.max((_tableMenuContext$sel = tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount) !== null && _tableMenuContext$sel !== void 0 ? _tableMenuContext$sel : 1, (_tableMenuContext$sel2 = tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedRowCount) !== null && _tableMenuContext$sel2 !== void 0 ? _tableMenuContext$sel2 : 1); var handleClick = function handleClick() { var _api$analytics; if (!editorView) { return; } var _getPluginState = getPluginState(editorView.state), targetCellPosition = _getPluginState.targetCellPosition; emptyMultipleCellsWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, targetCellPosition)(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, elemBefore: /*#__PURE__*/React.createElement(CrossIcon, { color: "currentColor", label: "", size: "small" }), elemAfter: /*#__PURE__*/React.createElement(ToolbarKeyboardShortcutHint, { shortcut: (_tooltip = tooltip(backspace)) !== null && _tooltip !== void 0 ? _tooltip : '' }) }, formatMessage(messages.clearCells, { 0: selectedCellCount })); };