UNPKG

@atlaskit/editor-plugin-insert-block

Version:

Insert block plugin for @atlaskit/editor-core

39 lines 1.51 kB
import React from 'react'; import { useIntl } from 'react-intl'; import { INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { ToolTipContent, getAriaKeyshortcuts, toggleCodeBlock } from '@atlaskit/editor-common/keymaps'; import { blockTypeMessages } from '@atlaskit/editor-common/messages'; import { useEditorToolbar } from '@atlaskit/editor-common/toolbar'; import { ToolbarButton, ToolbarTooltip, CodeIcon } from '@atlaskit/editor-toolbar'; export const CodeBlockButton = ({ api }) => { const { formatMessage } = useIntl(); const { editorView } = useEditorToolbar(); if (!(api !== null && api !== void 0 && api.codeBlock)) { return null; } const onClick = () => { if (editorView) { var _api$codeBlock; api === null || api === void 0 ? void 0 : (_api$codeBlock = api.codeBlock) === null || _api$codeBlock === void 0 ? void 0 : _api$codeBlock.actions.insertCodeBlock(INPUT_METHOD.TOOLBAR)(editorView.state, editorView.dispatch); } }; return /*#__PURE__*/React.createElement(ToolbarTooltip, { content: /*#__PURE__*/React.createElement(ToolTipContent, { description: formatMessage(blockTypeMessages.codeblock), keymap: toggleCodeBlock }) }, /*#__PURE__*/React.createElement(ToolbarButton, { iconBefore: /*#__PURE__*/React.createElement(CodeIcon, { label: formatMessage(blockTypeMessages.codeblock), size: "small" }), onClick: onClick, ariaKeyshortcuts: getAriaKeyshortcuts(toggleCodeBlock) })); };