@atlaskit/editor-plugin-table
Version:
Table plugin for the @atlaskit/editor
46 lines • 2.33 kB
JavaScript
import React from 'react';
import { useIntl } from 'react-intl';
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
import { addRowAfter, tooltip } from '@atlaskit/editor-common/keymaps';
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
import { TableRowAddBelowIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
import { closeActiveTableMenu } from '../../../../pm-plugins/commands';
import { insertRowWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
import { useTableMenuContext } from '../../shared/TableMenuContext';
export var AddRowBelowItem = function AddRowBelowItem(props) {
var _useTableMenuContext, _tooltip;
var api = props.api;
var _ref = (_useTableMenuContext = useTableMenuContext()) !== null && _useTableMenuContext !== void 0 ? _useTableMenuContext : {},
editorView = _ref.editorView;
var _useIntl = useIntl(),
formatMessage = _useIntl.formatMessage;
var handleClick = function handleClick() {
var _api$analytics;
if (!editorView) {
return;
}
var selectionRect = getSelectionRect(editorView.state.selection);
var index = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.bottom;
if (index === undefined) {
return;
}
insertRowWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, {
index: index,
moveCursorToInsertedRow: true
})(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(TableRowAddBelowIcon, {
color: "currentColor",
label: "",
size: "small"
}),
elemAfter: /*#__PURE__*/React.createElement(ToolbarKeyboardShortcutHint, {
shortcut: (_tooltip = tooltip(addRowAfter)) !== null && _tooltip !== void 0 ? _tooltip : ''
})
}, formatMessage(messages.addRowBelow));
};