UNPKG

@atlaskit/editor-plugin-help-dialog

Version:

Help Dialog plugin for @atlaskit/editor-core

77 lines (74 loc) • 3.67 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = require("react"); var _react2 = require("@emotion/react"); var _reactIntl = require("react-intl"); var _helpDialog = require("@atlaskit/editor-common/messages/help-dialog"); var _useSharedPluginStateWithSelector = require("@atlaskit/editor-common/useSharedPluginStateWithSelector"); var _modalDialog = _interopRequireDefault(require("@atlaskit/modal-dialog/modal-dialog")); var _modalTransition = _interopRequireDefault(require("@atlaskit/modal-dialog/modal-transition")); var _fg = require("@atlaskit/platform-feature-flags/fg"); var _commands = require("../pm-plugins/commands"); var _formatting = require("./formatting"); var _Modal = _interopRequireDefault(require("./Modal")); /** * @jsxRuntime classic * @jsx jsx */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766 var selector = function 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 }; }; var HelpDialog = function HelpDialog(_ref) { var pluginInjectionApi = _ref.pluginInjectionApi, editorView = _ref.editorView, quickInsertEnabled = _ref.quickInsertEnabled, intl = _ref.intl; var _useSharedPluginState = (0, _useSharedPluginStateWithSelector.useSharedPluginStateWithSelector)(pluginInjectionApi, ['helpDialog'], selector), isVisible = _useSharedPluginState.isVisible, imageEnabled = _useSharedPluginState.imageEnabled, aiEnabled = _useSharedPluginState.aiEnabled; var closeDialog = (0, _react.useCallback)(function () { var tr = editorView.state.tr, dispatch = editorView.dispatch; (0, _commands.closeHelpCommand)(tr, dispatch); }, [editorView]); var handleEsc = (0, _react.useCallback)(function (e) { if (e.key === 'Escape' && isVisible) { closeDialog(); } }, [closeDialog, isVisible]); (0, _react.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 = (0, _formatting.getSupportedFormatting)(editorView.state.schema, intl, imageEnabled, quickInsertEnabled, aiEnabled); var label = intl.formatMessage(_helpDialog.helpDialogMessages.editorHelp); return (0, _react2.jsx)(_modalTransition.default, null, isVisible ? // eslint-disable-next-line @atlaskit/design-system/no-modal-label (0, _react2.jsx)(_modalDialog.default, { label: (0, _fg.fg)('platform_dst-modal_title') ? undefined : label, width: "large", onClose: closeDialog, testId: "help-modal-dialog" }, (0, _react2.jsx)(_Modal.default, { formatting: formatting })) : null); }; var _default_1 = (0, _reactIntl.injectIntl)(HelpDialog); var _default = exports.default = _default_1;