UNPKG

@atlaskit/editor-plugin-mentions

Version:

Mentions plugin for @atlaskit/editor-core

38 lines 1.47 kB
import React, { useCallback } from 'react'; import { useIntl } from 'react-intl'; import { INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages'; import { QuickInsertMenuItem } from '@atlaskit/editor-common/quick-insert/menu-item'; import MentionIcon from '@atlaskit/icon/core/mention'; import { mentionPluginKey } from '../../pm-plugins/key'; export const MentionQuickInsertMenuItem = ({ api, typeAhead }) => { const { formatMessage } = useIntl(); const onSelect = useCallback(({ editorView, insert }) => { var _mentionPluginKey$get, _api$typeAhead; if (((_mentionPluginKey$get = mentionPluginKey.getState(editorView.state)) === null || _mentionPluginKey$get === void 0 ? void 0 : _mentionPluginKey$get.canInsertMention) === false) { return false; } const tr = insert(undefined); api === null || api === void 0 ? void 0 : (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : _api$typeAhead.actions.openAtTransaction({ triggerHandler: typeAhead, inputMethod: INPUT_METHOD.QUICK_INSERT })(tr); return tr; }, [api, typeAhead]); return /*#__PURE__*/React.createElement(QuickInsertMenuItem, { iconBefore: /*#__PURE__*/React.createElement(MentionIcon, { label: "" }), onSelect: onSelect, shortcut: "@", title: formatMessage(messages.mention) }); };