@atlaskit/editor-plugin-mentions
Version:
Mentions plugin for @atlaskit/editor-core
31 lines • 1.6 kB
JavaScript
import React, { useCallback } from 'react';
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
import ToolbarMention from './ToolbarMention';
var selector = function selector(states) {
var _states$mentionState;
return {
mentionProvider: (_states$mentionState = states.mentionState) === null || _states$mentionState === void 0 ? void 0 : _states$mentionState.mentionProvider
};
};
export function SecondaryToolbarComponent(_ref) {
var _api$typeAhead2;
var editorView = _ref.editorView,
api = _ref.api,
typeAhead = _ref.typeAhead,
disabled = _ref.disabled;
var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['mention'], selector),
mentionProvider = _useSharedPluginState.mentionProvider;
var openMentionTypeAhead = useCallback(function () {
var _api$typeAhead;
api === null || api === void 0 || (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 || (_api$typeAhead = _api$typeAhead.actions) === null || _api$typeAhead === void 0 || _api$typeAhead.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 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.actions.isAllowed(editorView.state))
});
}