@atlaskit/editor-plugin-help-dialog
Version:
Help Dialog plugin for @atlaskit/editor-core
71 lines (70 loc) • 2.69 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';
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
import { helpDialogMessages as messages } from '@atlaskit/editor-common/messages';
import AkModalDialog, { ModalTransition } from '@atlaskit/modal-dialog';
import { closeHelpCommand } from '../pm-plugins/commands';
import { getSupportedFormatting } from './formatting';
import Modal from './Modal';
const selector = states => {
var _states$helpDialogSta, _states$helpDialogSta2, _states$helpDialogSta3;
return {
isVisible: (_states$helpDialogSta = states.helpDialogState) === null || _states$helpDialogSta === void 0 ? void 0 : _states$helpDialogSta.isVisible,
imageEnabled: (_states$helpDialogSta2 = states.helpDialogState) === null || _states$helpDialogSta2 === void 0 ? void 0 : _states$helpDialogSta2.imageEnabled,
aiEnabled: (_states$helpDialogSta3 = states.helpDialogState) === null || _states$helpDialogSta3 === void 0 ? void 0 : _states$helpDialogSta3.aiEnabled
};
};
const HelpDialog = ({
pluginInjectionApi,
editorView,
quickInsertEnabled,
intl
}) => {
const {
isVisible,
imageEnabled,
aiEnabled
} = useSharedPluginStateWithSelector(pluginInjectionApi, ['helpDialog'], selector);
const closeDialog = useCallback(() => {
const {
state: {
tr
},
dispatch
} = editorView;
closeHelpCommand(tr, dispatch);
}, [editorView]);
const handleEsc = useCallback(e => {
if (e.key === 'Escape' && isVisible) {
closeDialog();
}
}, [closeDialog, isVisible]);
useEffect(() => {
// Ignored via go/ees005
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
document.addEventListener('keydown', handleEsc);
return () => {
// Ignored via go/ees005
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
document.removeEventListener('keydown', handleEsc);
};
}, [handleEsc]);
const formatting = getSupportedFormatting(editorView.state.schema, intl, imageEnabled, quickInsertEnabled, aiEnabled);
const label = intl.formatMessage(messages.editorHelp);
return jsx(ModalTransition, null, isVisible ? jsx(AkModalDialog, {
label: label,
width: "large",
onClose: closeDialog,
testId: "help-modal-dialog"
}, jsx(Modal, {
formatting: formatting
})) : null);
};
const _default_1 = injectIntl(HelpDialog);
export default _default_1;