UNPKG

@atlaskit/editor-plugin-help-dialog

Version:

Help Dialog plugin for @atlaskit/editor-core

75 lines (72 loc) 3.98 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); 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 _hooks = require("@atlaskit/editor-common/hooks"); var _messages = require("@atlaskit/editor-common/messages"); var _modalDialog = _interopRequireWildcard(require("@atlaskit/modal-dialog")); var _commands = require("../pm-plugins/commands"); var _formatting = require("./formatting"); var _Modal = _interopRequireDefault(require("./Modal")); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } /** * @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, _hooks.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(_messages.helpDialogMessages.editorHelp); return (0, _react2.jsx)(_modalDialog.ModalTransition, null, isVisible ? (0, _react2.jsx)(_modalDialog.default, { label: 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;