UNPKG

@atlaskit/editor-plugin-insert-block

Version:

Insert block plugin for @atlaskit/editor-core

50 lines 2.32 kB
import React from 'react'; import { useIntl } from 'react-intl'; import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { ToolTipContent, getAriaKeyshortcuts, toggleTable } from '@atlaskit/editor-common/keymaps'; import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages'; import { useEditorToolbar, TOOLBAR_BUTTON_TEST_ID } from '@atlaskit/editor-common/toolbar'; import { ToolbarButton, ToolbarTooltip, TableIcon } from '@atlaskit/editor-toolbar'; export var TableButton = function TableButton(_ref) { var api = _ref.api; var _useIntl = useIntl(), formatMessage = _useIntl.formatMessage; var _useEditorToolbar = 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: ACTION.INSERTED, actionSubject: ACTION_SUBJECT.DOCUMENT, actionSubjectId: ACTION_SUBJECT_ID.TABLE, attributes: { inputMethod: INPUT_METHOD.TOOLBAR }, eventType: EVENT_TYPE.TRACK })(state, dispatch); }); } }; return /*#__PURE__*/React.createElement(ToolbarTooltip, { content: /*#__PURE__*/React.createElement(ToolTipContent, { description: formatMessage(messages.table), keymap: toggleTable }) }, /*#__PURE__*/React.createElement(ToolbarButton, { iconBefore: /*#__PURE__*/React.createElement(TableIcon, { label: formatMessage(messages.table), size: "small" }), onClick: onClick, ariaKeyshortcuts: getAriaKeyshortcuts(toggleTable), testId: TOOLBAR_BUTTON_TEST_ID.TABLE })); };