@atlaskit/editor-plugin-expand
Version:
Expand plugin for @atlaskit/editor-core
43 lines • 1.61 kB
JavaScript
import React from 'react';
import { useIntl } from 'react-intl-next';
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
import { toolbarInsertBlockMessages } from '@atlaskit/editor-common/messages';
import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
import ExpandElementIcon from '@atlaskit/icon-lab/core/expand-element';
const NODE_NAME = 'expand';
const ExpandBlockMenuItem = ({
api
}) => {
const {
formatMessage
} = useIntl();
const handleClick = event => {
const triggeredFrom = event.nativeEvent instanceof KeyboardEvent || event.nativeEvent.detail === 0 ? INPUT_METHOD.KEYBOARD : INPUT_METHOD.MOUSE;
const inputMethod = INPUT_METHOD.BLOCK_MENU;
api === null || api === void 0 ? void 0 : api.core.actions.execute(({
tr
}) => {
var _api$blockMenu;
const command = api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.commands.transformNode(tr.doc.type.schema.nodes.expand, {
inputMethod,
triggeredFrom,
targetTypeName: NODE_NAME
});
return command ? command({
tr
}) : null;
});
};
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
onClick: handleClick,
elemBefore: /*#__PURE__*/React.createElement(ExpandElementIcon, {
label: "",
size: "small"
})
}, formatMessage(toolbarInsertBlockMessages.expand));
};
export const createExpandBlockMenuItem = api => {
return () => /*#__PURE__*/React.createElement(ExpandBlockMenuItem, {
api: api
});
};