@atlaskit/editor-plugin-help-dialog
Version:
Help Dialog plugin for @atlaskit/editor-core
51 lines (50 loc) • 2.32 kB
JavaScript
/**
* @jsxRuntime classic
* @jsx jsx
*/
import { useCallback, useEffect } from 'react';
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
import { jsx } from '@emotion/react';
import { injectIntl } from 'react-intl-next';
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
import AkModalDialog, { ModalTransition } from '@atlaskit/modal-dialog';
import { closeHelpCommand } from '../pm-plugins/commands';
import { getSupportedFormatting } from './formatting';
import Modal from './Modal';
var HelpDialog = function HelpDialog(_ref) {
var pluginInjectionApi = _ref.pluginInjectionApi,
editorView = _ref.editorView,
quickInsertEnabled = _ref.quickInsertEnabled,
intl = _ref.intl;
var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['helpDialog']),
helpDialogState = _useSharedPluginState.helpDialogState;
var closeDialog = useCallback(function () {
var tr = editorView.state.tr,
dispatch = editorView.dispatch;
closeHelpCommand(tr, dispatch);
}, [editorView]);
var handleEsc = useCallback(function (e) {
if (e.key === 'Escape' && helpDialogState !== null && helpDialogState !== void 0 && helpDialogState.isVisible) {
closeDialog();
}
}, [closeDialog, helpDialogState === null || helpDialogState === void 0 ? void 0 : helpDialogState.isVisible]);
useEffect(function () {
// Ignored via go/ees005
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
document.addEventListener('keydown', handleEsc);
return function () {
// Ignored via go/ees005
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
document.removeEventListener('keydown', handleEsc);
};
}, [handleEsc]);
var formatting = getSupportedFormatting(editorView.state.schema, intl, helpDialogState === null || helpDialogState === void 0 ? void 0 : helpDialogState.imageEnabled, quickInsertEnabled);
return jsx(ModalTransition, null, helpDialogState !== null && helpDialogState !== void 0 && helpDialogState.isVisible ? jsx(AkModalDialog, {
width: "large",
onClose: closeDialog,
testId: "help-modal-dialog"
}, jsx(Modal, {
formatting: formatting
})) : null);
};
export default injectIntl(HelpDialog);