UNPKG

@atlaskit/editor-plugin-help-dialog

Version:

Help Dialog plugin for @atlaskit/editor-core

96 lines 3.76 kB
import React from 'react'; import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { openHelp, tooltip } from '@atlaskit/editor-common/keymaps'; import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages'; import QuestionCircleIcon from '@atlaskit/icon/core/migration/question-circle'; import { closeHelpAction, openHelpAction } from './pm-plugins/actions'; import { openHelpCommand } from './pm-plugins/commands'; import { keymapPlugin } from './pm-plugins/keymap'; import { createPlugin } from './pm-plugins/main'; import { pluginKey } from './pm-plugins/plugin-key'; import { HelpDialogLoader } from './ui/HelpDialogLoader'; export var helpDialogPlugin = function helpDialogPlugin(_ref) { var _ref$config = _ref.config, imageUploadProviderExists = _ref$config === void 0 ? false : _ref$config, api = _ref.api; return { name: 'helpDialog', pmPlugins: function pmPlugins() { return [{ name: 'helpDialog', plugin: function plugin(_ref2) { var dispatch = _ref2.dispatch; return createPlugin(dispatch, imageUploadProviderExists); } }, { name: 'helpDialogKeymap', plugin: function plugin() { var _api$analytics; return keymapPlugin(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions); } }]; }, pluginsOptions: { quickInsert: function quickInsert(_ref3) { var formatMessage = _ref3.formatMessage; return [{ id: 'helpdialog', title: formatMessage(messages.help), description: formatMessage(messages.helpDescription), keywords: ['?'], priority: 4000, keyshortcut: tooltip(openHelp), icon: function icon() { return /*#__PURE__*/React.createElement(QuestionCircleIcon, { label: "", color: "currentColor" }); }, action: function action(insert) { var _api$analytics2; var tr = insert(''); openHelpCommand(tr); api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || _api$analytics2.actions.attachAnalyticsEvent({ action: ACTION.HELP_OPENED, actionSubject: ACTION_SUBJECT.HELP, actionSubjectId: ACTION_SUBJECT_ID.HELP_QUICK_INSERT, attributes: { inputMethod: INPUT_METHOD.QUICK_INSERT }, eventType: EVENT_TYPE.UI })(tr); return tr; } }]; } }, contentComponent: function contentComponent(_ref4) { var editorView = _ref4.editorView; return /*#__PURE__*/React.createElement(HelpDialogLoader, { pluginInjectionApi: api, editorView: editorView, quickInsertEnabled: !!(api !== null && api !== void 0 && api.quickInsert) }); }, getSharedState: function getSharedState(editorState) { if (!editorState) { return null; } return pluginKey.getState(editorState) || null; }, actions: { openHelp: function openHelp() { return api === null || api === void 0 ? void 0 : api.core.actions.execute(function (_ref5) { var tr = _ref5.tr; return openHelpAction(tr); }); }, closeHelp: function closeHelp() { return api === null || api === void 0 ? void 0 : api.core.actions.execute(function (_ref6) { var tr = _ref6.tr; return closeHelpAction(tr); }); } } }; };