UNPKG

@atlaskit/editor-plugin-code-block

Version:

Code block plugin for @atlaskit/editor-core

42 lines 1.75 kB
import React from 'react'; import { useIntl } from 'react-intl'; import { INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { blockMenuMessages } from '@atlaskit/editor-common/messages'; import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar'; import AngleBracketsIcon from '@atlaskit/icon/core/angle-brackets'; var NODE_NAME = 'codeBlock'; var CodeBlockMenuItem = function CodeBlockMenuItem(_ref) { var api = _ref.api; var _useIntl = useIntl(), formatMessage = _useIntl.formatMessage; var handleClick = function handleClick(event) { var triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE; var inputMethod = INPUT_METHOD.BLOCK_MENU; api === null || api === void 0 || api.core.actions.execute(function (_ref2) { var _api$blockMenu; var tr = _ref2.tr; var command = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.codeBlock, { inputMethod: inputMethod, triggeredFrom: triggeredFrom, targetTypeName: NODE_NAME }); return command ? command({ tr: tr }) : null; }); }; return /*#__PURE__*/React.createElement(ToolbarDropdownItem, { onClick: handleClick, elemBefore: /*#__PURE__*/React.createElement(AngleBracketsIcon, { label: "", size: "small" }) }, formatMessage(blockMenuMessages.codeBlock)); }; export var createCodeBlockMenuItem = function createCodeBlockMenuItem(api) { return function () { return /*#__PURE__*/React.createElement(CodeBlockMenuItem, { api: api }); }; };