UNPKG

@atlaskit/editor-plugin-insert-block

Version:

Insert block plugin for @atlaskit/editor-core

55 lines 2.21 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 const TableButton = ({ api }) => { const { formatMessage } = useIntl(); const { editorView } = useEditorToolbar(); if (!(api !== null && api !== void 0 && api.table)) { return null; } const onClick = () => { if (editorView) { const { state, dispatch } = editorView; // workaround to solve race condition where cursor is not placed correctly inside table queueMicrotask(() => { var _api$table, _api$table$actions$in, _api$table$actions; api === null || api === void 0 ? void 0 : (_api$table = api.table) === null || _api$table === void 0 ? void 0 : (_api$table$actions$in = (_api$table$actions = _api$table.actions).insertTable) === null || _api$table$actions$in === void 0 ? 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 })); };