UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

87 lines (86 loc) 4.71 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.DeleteColumnItem = void 0; var _react = _interopRequireDefault(require("react")); var _reactIntl = require("react-intl"); var _analytics = require("@atlaskit/editor-common/analytics"); var _hooks = require("@atlaskit/editor-common/hooks"); var _keymaps = require("@atlaskit/editor-common/keymaps"); 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 _selection = require("../../../../pm-plugins/utils/selection"); var _TableMenuContext = require("../../shared/TableMenuContext"); var DeleteColumnItem = exports.DeleteColumnItem = function DeleteColumnItem(_ref) { var _tableMenuContext$sel, _tooltip; var api = _ref.api; var tableMenuContext = (0, _TableMenuContext.useTableMenuContext)(); var _ref2 = tableMenuContext !== null && tableMenuContext !== void 0 ? tableMenuContext : {}, editorView = _ref2.editorView; var selectedColumnCount = (_tableMenuContext$sel = tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount) !== null && _tableMenuContext$sel !== void 0 ? _tableMenuContext$sel : 1; var _useIntl = (0, _reactIntl.useIntl)(), formatMessage = _useIntl.formatMessage; var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api !== null && api !== void 0 ? api : undefined, ['table'], function (states) { var tableState = states.tableState; return { isCommentEditor: tableState === null || tableState === void 0 ? void 0 : tableState.isCommentEditor, isTableFixedColumnWidthsOptionEnabled: tableState === null || tableState === void 0 ? void 0 : tableState.isTableFixedColumnWidthsOptionEnabled, isTableScalingEnabled: tableState === null || tableState === void 0 ? void 0 : tableState.isTableScalingEnabled }; }), isCommentEditor = _useSharedPluginState.isCommentEditor, isTableFixedColumnWidthsOptionEnabled = _useSharedPluginState.isTableFixedColumnWidthsOptionEnabled, isTableScalingEnabled = _useSharedPluginState.isTableScalingEnabled; var handleMouseEnter = function handleMouseEnter() { if (!editorView) { return; } var selectionRect = (0, _utils.getSelectionRect)(editorView.state.selection); if (!selectionRect) { return; } (0, _commands.hoverColumns)((0, _selection.getSelectedColumnIndexes)(selectionRect), true)(editorView.state, editorView.dispatch); }; var handleMouseLeave = function handleMouseLeave() { if (!editorView) { return; } (0, _commands.clearHoverSelection)()(editorView.state, editorView.dispatch); }; var handleClick = function handleClick() { var _api$analytics; if (!editorView) { return; } var selectionRect = (0, _utils.getSelectionRect)(editorView.state.selection); if (!selectionRect) { return; } var shouldUseIncreasedScalingPercent = isTableScalingEnabled && (isTableFixedColumnWidthsOptionEnabled || isCommentEditor); (0, _commandsWithAnalytics.deleteColumnsWithAnalytics)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent, isCommentEditor)(_analytics.INPUT_METHOD.TABLE_CONTEXT_MENU, selectionRect)(editorView.state, editorView.dispatch, editorView); 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, onFocus: handleMouseEnter, onMouseEnter: handleMouseEnter, onBlur: handleMouseLeave, onMouseLeave: handleMouseLeave, elemBefore: /*#__PURE__*/_react.default.createElement(_editorToolbar.DeleteIcon, { color: "currentColor", label: "", size: "small" }), elemAfter: /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarKeyboardShortcutHint, { shortcut: (_tooltip = (0, _keymaps.tooltip)(_keymaps.deleteColumn)) !== null && _tooltip !== void 0 ? _tooltip : '' }) }, formatMessage(_messages.tableMessages.removeColumns, { 0: selectedColumnCount })); };