@atlaskit/editor-plugin-help-dialog
Version:
Help Dialog plugin for @atlaskit/editor-core
89 lines • 3.05 kB
JavaScript
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 const helpDialogPlugin = ({
config: imageUploadProviderExists = false,
api
}) => ({
name: 'helpDialog',
pmPlugins() {
return [{
name: 'helpDialog',
plugin: ({
dispatch
}) => createPlugin(dispatch, imageUploadProviderExists)
}, {
name: 'helpDialogKeymap',
plugin: () => {
var _api$analytics;
return keymapPlugin(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
}
}];
},
pluginsOptions: {
quickInsert: ({
formatMessage
}) => [{
id: 'helpdialog',
title: formatMessage(messages.help),
description: formatMessage(messages.helpDescription),
keywords: ['?'],
priority: 4000,
keyshortcut: tooltip(openHelp),
icon: () => /*#__PURE__*/React.createElement(QuestionCircleIcon, {
label: "",
color: "currentColor"
}),
action(insert) {
var _api$analytics2;
const tr = insert('');
openHelpCommand(tr);
api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? 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({
editorView
}) {
return /*#__PURE__*/React.createElement(HelpDialogLoader, {
pluginInjectionApi: api,
editorView: editorView,
quickInsertEnabled: !!(api !== null && api !== void 0 && api.quickInsert)
});
},
getSharedState(editorState) {
if (!editorState) {
return null;
}
return pluginKey.getState(editorState) || null;
},
actions: {
openHelp: () => {
return api === null || api === void 0 ? void 0 : api.core.actions.execute(({
tr
}) => openHelpAction(tr));
},
closeHelp: () => {
return api === null || api === void 0 ? void 0 : api.core.actions.execute(({
tr
}) => closeHelpAction(tr));
}
}
});