UNPKG

@atlaskit/editor-plugin-insert-block

Version:

Insert block plugin for @atlaskit/editor-core

73 lines • 3.76 kB
import React, { useRef } from 'react'; import { useIntl } from 'react-intl'; import { ToolTipContent, insertEmoji } from '@atlaskit/editor-common/keymaps'; import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages/insert-block'; import { TOOLBAR_BUTTON_TEST_ID } from '@atlaskit/editor-common/toolbar/keys'; import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/useSharedPluginStateWithSelector'; import { EmojiIcon } from '@atlaskit/editor-toolbar/emoji-icon'; import { ToolbarButton } from '@atlaskit/editor-toolbar/toolbar-button'; import { ToolbarTooltip } from '@atlaskit/editor-toolbar/toolbar-tooltip'; import { useToolbarUI } from '@atlaskit/editor-toolbar/ui-context'; import { useEmojiPickerPopup } from './hooks/useEmojiPickerPopup'; import { EmojiPickerPopup } from './popups/EmojiPickerPopup'; export var EmojiButton = function EmojiButton(_ref) { var api = _ref.api; var _useIntl = useIntl(), formatMessage = _useIntl.formatMessage; var emojiButtonRef = useRef(null); var _useToolbarUI = useToolbarUI(), popupsMountPoint = _useToolbarUI.popupsMountPoint, popupsBoundariesElement = _useToolbarUI.popupsBoundariesElement, popupsScrollableElement = _useToolbarUI.popupsScrollableElement; var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['emoji', 'typeAhead'], function (states) { var _states$emojiState, _states$emojiState2, _states$typeAheadStat; return { contentId: (_states$emojiState = states.emojiState) === null || _states$emojiState === void 0 ? void 0 : _states$emojiState.contentId, emojiProviderPromise: (_states$emojiState2 = states.emojiState) === null || _states$emojiState2 === void 0 ? void 0 : _states$emojiState2.emojiProviderPromise, isTypeAheadAllowed: (_states$typeAheadStat = states.typeAheadState) === null || _states$typeAheadStat === void 0 ? void 0 : _states$typeAheadStat.isAllowed }; }), contentId = _useSharedPluginState.contentId, emojiProviderPromise = _useSharedPluginState.emojiProviderPromise, isTypeAheadAllowed = _useSharedPluginState.isTypeAheadAllowed; var emojiPickerPopup = useEmojiPickerPopup({ api: api, buttonRef: emojiButtonRef }); if (!(api !== null && api !== void 0 && api.emoji)) { return null; } return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EmojiPickerPopup, { contentId: contentId, isOpen: emojiPickerPopup.isOpen, targetRef: emojiButtonRef, emojiProvider: emojiProviderPromise, onSelection: emojiPickerPopup.handleSelectedEmoji, onClickOutside: emojiPickerPopup.handleClickOutside, onEscapeKeydown: emojiPickerPopup.handleEscapeKeydown, onUnmount: emojiPickerPopup.onPopupUnmount, popupsMountPoint: popupsMountPoint, popupsBoundariesElement: popupsBoundariesElement, popupsScrollableElement: popupsScrollableElement }), /*#__PURE__*/React.createElement(ToolbarTooltip, { content: /*#__PURE__*/React.createElement(ToolTipContent, { description: formatMessage(messages.emoji), keymap: insertEmoji }) }, /*#__PURE__*/React.createElement(ToolbarButton, { iconBefore: /*#__PURE__*/React.createElement(EmojiIcon, { label: formatMessage(messages.emoji), size: "small" }), ariaKeyshortcuts: "Shift+;", ref: emojiButtonRef // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed) , onClick: function onClick() { return emojiPickerPopup.toggle(); }, isSelected: emojiPickerPopup.isOpen, isDisabled: !isTypeAheadAllowed || !emojiProviderPromise, testId: TOOLBAR_BUTTON_TEST_ID.EMOJI }))); };