UNPKG

@atlaskit/editor-plugin-insert-block

Version:

Insert block plugin for @atlaskit/editor-core

46 lines 2.58 kB
import React from 'react'; import { useIntl } from 'react-intl'; import { INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'; import { ToolTipContent, insertMention } from '@atlaskit/editor-common/keymaps'; import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages'; import { TOOLBAR_BUTTON_TEST_ID } from '@atlaskit/editor-common/toolbar'; import { ToolbarButton, ToolbarTooltip, MentionIcon } from '@atlaskit/editor-toolbar'; export var MentionButton = function MentionButton(_ref) { var api = _ref.api; var _useIntl = useIntl(), formatMessage = _useIntl.formatMessage; var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['mention', 'typeAhead'], function (states) { var _states$mentionState, _states$mentionState2, _states$typeAheadStat; return { canInsertMention: (_states$mentionState = states.mentionState) === null || _states$mentionState === void 0 ? void 0 : _states$mentionState.canInsertMention, mentionProvider: (_states$mentionState2 = states.mentionState) === null || _states$mentionState2 === void 0 ? void 0 : _states$mentionState2.mentionProvider, isTypeAheadAllowed: (_states$typeAheadStat = states.typeAheadState) === null || _states$typeAheadStat === void 0 ? void 0 : _states$typeAheadStat.isAllowed }; }), canInsertMention = _useSharedPluginState.canInsertMention, mentionProvider = _useSharedPluginState.mentionProvider, isTypeAheadAllowed = _useSharedPluginState.isTypeAheadAllowed; if (!(api !== null && api !== void 0 && api.mention)) { return null; } var onClick = function onClick() { var _api$mention; api === null || api === void 0 || (_api$mention = api.mention) === null || _api$mention === void 0 || (_api$mention = _api$mention.actions) === null || _api$mention === void 0 || _api$mention.openTypeAhead(INPUT_METHOD.TOOLBAR); }; return /*#__PURE__*/React.createElement(ToolbarTooltip, { content: /*#__PURE__*/React.createElement(ToolTipContent, { description: formatMessage(messages.mention), keymap: insertMention }) }, /*#__PURE__*/React.createElement(ToolbarButton, { iconBefore: /*#__PURE__*/React.createElement(MentionIcon, { label: formatMessage(messages.mention), size: "small" }), onClick: onClick, ariaKeyshortcuts: "Shift+2 Space", isDisabled: !canInsertMention || !mentionProvider || !isTypeAheadAllowed, testId: TOOLBAR_BUTTON_TEST_ID.MENTION })); };