@atlaskit/editor-plugin-block-type
Version:
BlockType plugin for @atlaskit/editor-core
52 lines • 2.07 kB
JavaScript
import React from 'react';
import { useIntl } from 'react-intl';
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
import { blockTypeMessages } from '@atlaskit/editor-common/messages';
import { TextSmallIcon, ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
var NODE_NAME = 'smallText';
var SmallTextBlockMenuItem = function SmallTextBlockMenuItem(_ref) {
var api = _ref.api,
isSuggested = _ref.isSuggested;
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.paragraph, {
inputMethod: inputMethod,
isSuggested: isSuggested,
marksToAdd: {
fontSize: {
fontSize: 'small'
}
},
triggeredFrom: triggeredFrom,
targetTypeName: NODE_NAME
});
return command ? command({
tr: tr
}) : null;
});
};
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
onClick: handleClick,
elemBefore: /*#__PURE__*/React.createElement(TextSmallIcon, {
label: "",
size: "small"
})
}, formatMessage(blockTypeMessages.smallText));
};
export var createSmallTextBlockMenuItem = function createSmallTextBlockMenuItem(_ref3) {
var api = _ref3.api;
return function () {
var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
isSuggested = _ref4.isSuggested;
return /*#__PURE__*/React.createElement(SmallTextBlockMenuItem, {
api: api,
isSuggested: isSuggested
});
};
};