UNPKG

@atlaskit/editor-plugin-mentions

Version:

Mentions plugin for @atlaskit/editor-core

33 lines 1.53 kB
import React, { useCallback } from 'react'; import { INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'; import ToolbarMention from './ToolbarMention'; const selector = states => { var _states$mentionState; return { mentionProvider: (_states$mentionState = states.mentionState) === null || _states$mentionState === void 0 ? void 0 : _states$mentionState.mentionProvider }; }; export function SecondaryToolbarComponent({ editorView, api, typeAhead, disabled }) { var _api$typeAhead2; const { mentionProvider } = useSharedPluginStateWithSelector(api, ['mention'], selector); const openMentionTypeAhead = useCallback(() => { var _api$typeAhead, _api$typeAhead$action; api === null || api === void 0 ? void 0 : (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : (_api$typeAhead$action = _api$typeAhead.actions) === null || _api$typeAhead$action === void 0 ? void 0 : _api$typeAhead$action.open({ triggerHandler: typeAhead, inputMethod: INPUT_METHOD.INSERT_MENU }); }, [api, typeAhead]); return !mentionProvider ? null : /*#__PURE__*/React.createElement(ToolbarMention, { editorView: editorView, onInsertMention: openMentionTypeAhead, isDisabled: disabled || (api === null || api === void 0 ? void 0 : (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.isAllowed(editorView.state)) }); }