UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

62 lines (60 loc) 2.24 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 const fakePluginKey = { key: 'helpDialog$', getState: state => { // eslint-disable-next-line @typescript-eslint/no-explicit-any return state['helpDialog$']; } }; const openHelpCommand = (tr, dispatch) => { tr = tr.setMeta(fakePluginKey, true); if (dispatch) { dispatch(tr); return true; } return false; }; const TooltipHelpTrigger = ({ title = 'Open help dialog', titlePosition = 'left', intl, editorApi }) => { const editorContext = useEditorContext(); // to have translation for the default tooltip helper let displayTitle = title; if (title === 'Open help dialog') { displayTitle = intl.formatMessage(messages.toolbarHelpTitle); } const showHelp = () => { if (editorApi) { var _editorApi$helpDialog; editorApi === null || editorApi === void 0 ? void 0 : (_editorApi$helpDialog = editorApi.helpDialog) === null || _editorApi$helpDialog === void 0 ? void 0 : _editorApi$helpDialog.actions.openHelp(); } else { var _editorContext$editor; const editorView = editorContext === null || editorContext === void 0 ? 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 const _default_1 = injectIntl(TooltipHelpTrigger); export default _default_1;