UNPKG

@atlaskit/editor-plugin-mentions

Version:

Mentions plugin for @atlaskit/editor-core

43 lines 1.6 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, previewImageUrls, 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); const didOpen = 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); if (didOpen === false) { return false; } return tr; }, [api, typeAhead]); return /*#__PURE__*/React.createElement(QuickInsertMenuItem, { iconBefore: /*#__PURE__*/React.createElement(MentionIcon, { label: "" }), onSelect: onSelect, previewImageUrls: previewImageUrls, shortcut: "@", title: formatMessage(messages.mention) }); };