UNPKG

@atlaskit/editor-plugin-insert-block

Version:

Insert block plugin for @atlaskit/editor-core

57 lines (56 loc) 2.64 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.TableButton = void 0; var _react = _interopRequireDefault(require("react")); var _reactIntl = require("react-intl"); var _analytics = require("@atlaskit/editor-common/analytics"); var _keymaps = require("@atlaskit/editor-common/keymaps"); var _messages = require("@atlaskit/editor-common/messages"); var _toolbar = require("@atlaskit/editor-common/toolbar"); var _editorToolbar = require("@atlaskit/editor-toolbar"); var TableButton = exports.TableButton = function TableButton(_ref) { var api = _ref.api; var _useIntl = (0, _reactIntl.useIntl)(), formatMessage = _useIntl.formatMessage; var _useEditorToolbar = (0, _toolbar.useEditorToolbar)(), editorView = _useEditorToolbar.editorView; if (!(api !== null && api !== void 0 && api.table)) { return null; } var onClick = function onClick() { if (editorView) { var state = editorView.state, dispatch = editorView.dispatch; // workaround to solve race condition where cursor is not placed correctly inside table queueMicrotask(function () { var _api$table, _api$table$actions$in, _api$table$actions; api === null || api === void 0 || (_api$table = api.table) === null || _api$table === void 0 || (_api$table$actions$in = (_api$table$actions = _api$table.actions).insertTable) === null || _api$table$actions$in === void 0 || _api$table$actions$in.call(_api$table$actions, { action: _analytics.ACTION.INSERTED, actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT, actionSubjectId: _analytics.ACTION_SUBJECT_ID.TABLE, attributes: { inputMethod: _analytics.INPUT_METHOD.TOOLBAR }, eventType: _analytics.EVENT_TYPE.TRACK })(state, dispatch); }); } }; return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarTooltip, { content: /*#__PURE__*/_react.default.createElement(_keymaps.ToolTipContent, { description: formatMessage(_messages.toolbarInsertBlockMessages.table), keymap: _keymaps.toggleTable }) }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarButton, { iconBefore: /*#__PURE__*/_react.default.createElement(_editorToolbar.TableIcon, { label: formatMessage(_messages.toolbarInsertBlockMessages.table), size: "small" }), onClick: onClick, ariaKeyshortcuts: (0, _keymaps.getAriaKeyshortcuts)(_keymaps.toggleTable), testId: _toolbar.TOOLBAR_BUTTON_TEST_ID.TABLE })); };