@atlaskit/editor-plugin-insert-block
Version:
Insert block plugin for @atlaskit/editor-core
36 lines • 1.61 kB
JavaScript
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 var CodeBlockButton = function CodeBlockButton(_ref) {
var api = _ref.api;
var _useIntl = useIntl(),
formatMessage = _useIntl.formatMessage;
var _useEditorToolbar = useEditorToolbar(),
editorView = _useEditorToolbar.editorView;
if (!(api !== null && api !== void 0 && api.codeBlock)) {
return null;
}
var onClick = function onClick() {
if (editorView) {
var _api$codeBlock;
api === null || api === void 0 || (_api$codeBlock = api.codeBlock) === null || _api$codeBlock === 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)
}));
};