UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

63 lines (61 loc) 2.48 kB
import React from 'react'; import { injectIntl } from 'react-intl'; import { ToolbarButton } from '@atlaskit/editor-common/ui-menu'; import QuestionIcon from '@atlaskit/icon/core/question-circle'; import { useEditorContext } from '../EditorContext'; import { messages } from './messages'; // Please, do not copy or use this kind of code below // This is just a temporary solution to keep the tooltip trigger working for Trello since it's not using the composable editor // @ts-ignore var fakePluginKey = { key: 'helpDialog$', getState: function getState(state) { // eslint-disable-next-line @typescript-eslint/no-explicit-any return state['helpDialog$']; } }; var openHelpCommand = function openHelpCommand(tr, dispatch) { tr = tr.setMeta(fakePluginKey, true); if (dispatch) { dispatch(tr); return true; } return false; }; var TooltipHelpTrigger = function TooltipHelpTrigger(_ref) { var _ref$title = _ref.title, title = _ref$title === void 0 ? 'Open help dialog' : _ref$title, _ref$titlePosition = _ref.titlePosition, titlePosition = _ref$titlePosition === void 0 ? 'left' : _ref$titlePosition, intl = _ref.intl, editorApi = _ref.editorApi; var editorContext = useEditorContext(); // to have translation for the default tooltip helper var displayTitle = title; if (title === 'Open help dialog') { displayTitle = intl.formatMessage(messages.toolbarHelpTitle); } var showHelp = function showHelp() { if (editorApi) { var _editorApi$helpDialog; editorApi === null || editorApi === void 0 || (_editorApi$helpDialog = editorApi.helpDialog) === null || _editorApi$helpDialog === void 0 || _editorApi$helpDialog.actions.openHelp(); } else { var _editorContext$editor; var editorView = editorContext === null || editorContext === void 0 || (_editorContext$editor = editorContext.editorActions) === null || _editorContext$editor === void 0 ? void 0 : _editorContext$editor._privateGetEditorView(); if (editorView) { openHelpCommand(editorView.state.tr, editorView.dispatch); } } }; return /*#__PURE__*/React.createElement(ToolbarButton, { onClick: showHelp, title: displayTitle, titlePosition: titlePosition, iconBefore: /*#__PURE__*/React.createElement(QuestionIcon, { label: displayTitle }) }); }; // eslint-disable-next-line @typescript-eslint/ban-types var _default_1 = injectIntl(TooltipHelpTrigger); export default _default_1;