@atlaskit/editor-plugin-help-dialog 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/.eslintrc.js +2 -0
  2. package/CHANGELOG.md +6 -0
  3. package/dist/cjs/commands.js +19 -0
  4. package/dist/cjs/index.js +15 -1
  5. package/dist/cjs/plugin-key.js +8 -0
  6. package/dist/cjs/plugin.js +137 -0
  7. package/dist/cjs/ui/HelpDialogLoader.js +24 -0
  8. package/dist/cjs/ui/index.js +563 -0
  9. package/dist/cjs/ui/styles.js +50 -0
  10. package/dist/es2019/commands.js +13 -0
  11. package/dist/es2019/index.js +6 -1
  12. package/dist/es2019/plugin-key.js +2 -0
  13. package/dist/es2019/plugin.js +124 -0
  14. package/dist/es2019/ui/HelpDialogLoader.js +6 -0
  15. package/dist/es2019/ui/index.js +441 -0
  16. package/dist/es2019/ui/styles.js +110 -0
  17. package/dist/esm/commands.js +13 -0
  18. package/dist/esm/index.js +6 -1
  19. package/dist/esm/plugin-key.js +2 -0
  20. package/dist/esm/plugin.js +129 -0
  21. package/dist/esm/ui/HelpDialogLoader.js +12 -0
  22. package/dist/esm/ui/index.js +552 -0
  23. package/dist/esm/ui/styles.js +40 -0
  24. package/dist/types/commands.d.ts +3 -0
  25. package/dist/types/index.d.ts +6 -0
  26. package/dist/types/plugin-key.d.ts +2 -0
  27. package/dist/types/plugin.d.ts +4 -0
  28. package/dist/types/ui/HelpDialogLoader.d.ts +4 -0
  29. package/dist/types/ui/index.d.ts +27 -0
  30. package/dist/types/ui/styles.d.ts +33 -0
  31. package/dist/types-ts4.5/commands.d.ts +3 -0
  32. package/dist/types-ts4.5/index.d.ts +6 -0
  33. package/dist/types-ts4.5/plugin-key.d.ts +2 -0
  34. package/dist/types-ts4.5/plugin.d.ts +4 -0
  35. package/dist/types-ts4.5/ui/HelpDialogLoader.d.ts +4 -0
  36. package/dist/types-ts4.5/ui/index.d.ts +27 -0
  37. package/dist/types-ts4.5/ui/styles.d.ts +33 -0
  38. package/package.json +12 -3
  39. package/report.api.md +10 -0
  40. package/tmp/api-report-tmp.d.ts +7 -0
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export var pluginKey = new PluginKey('helpDialogPlugin');
@@ -0,0 +1,129 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ import React from 'react';
5
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
6
+ import { bindKeymapWithCommand, openHelp, tooltip } from '@atlaskit/editor-common/keymaps';
7
+ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
8
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
9
+ import { keymap } from '@atlaskit/editor-prosemirror/keymap';
10
+ import QuestionCircleIcon from '@atlaskit/icon/glyph/question-circle';
11
+ import { openHelpCommand } from './commands';
12
+ import { pluginKey } from './plugin-key';
13
+ import { HelpDialogLoader } from './ui/HelpDialogLoader';
14
+ export function createPlugin(dispatch, imageEnabled) {
15
+ return new SafePlugin({
16
+ key: pluginKey,
17
+ state: {
18
+ init: function init() {
19
+ return {
20
+ isVisible: false,
21
+ imageEnabled: imageEnabled
22
+ };
23
+ },
24
+ apply: function apply(tr, _value, state) {
25
+ var isVisible = tr.getMeta(pluginKey);
26
+ var currentState = pluginKey.getState(state);
27
+ if (isVisible !== undefined && isVisible !== currentState.isVisible) {
28
+ var newState = _objectSpread(_objectSpread({}, currentState), {}, {
29
+ isVisible: isVisible
30
+ });
31
+ dispatch(pluginKey, newState);
32
+ return newState;
33
+ }
34
+ return currentState;
35
+ }
36
+ }
37
+ });
38
+ }
39
+ export var helpDialogPlugin = function helpDialogPlugin(_ref) {
40
+ var _ref$config = _ref.config,
41
+ imageUploadProviderExists = _ref$config === void 0 ? false : _ref$config,
42
+ api = _ref.api;
43
+ return {
44
+ name: 'helpDialog',
45
+ pmPlugins: function pmPlugins() {
46
+ return [{
47
+ name: 'helpDialog',
48
+ plugin: function plugin(_ref2) {
49
+ var dispatch = _ref2.dispatch;
50
+ return createPlugin(dispatch, imageUploadProviderExists);
51
+ }
52
+ }, {
53
+ name: 'helpDialogKeymap',
54
+ plugin: function plugin() {
55
+ var _api$analytics;
56
+ return keymapPlugin(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
57
+ }
58
+ }];
59
+ },
60
+ pluginsOptions: {
61
+ quickInsert: function quickInsert(_ref3) {
62
+ var formatMessage = _ref3.formatMessage;
63
+ return [{
64
+ id: 'helpdialog',
65
+ title: formatMessage(messages.help),
66
+ description: formatMessage(messages.helpDescription),
67
+ keywords: ['?'],
68
+ priority: 4000,
69
+ keyshortcut: tooltip(openHelp),
70
+ icon: function icon() {
71
+ return /*#__PURE__*/React.createElement(QuestionCircleIcon, {
72
+ label: ""
73
+ });
74
+ },
75
+ action: function action(insert) {
76
+ var _api$analytics2;
77
+ var tr = insert('');
78
+ openHelpCommand(tr);
79
+ api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || _api$analytics2.actions.attachAnalyticsEvent({
80
+ action: ACTION.HELP_OPENED,
81
+ actionSubject: ACTION_SUBJECT.HELP,
82
+ actionSubjectId: ACTION_SUBJECT_ID.HELP_QUICK_INSERT,
83
+ attributes: {
84
+ inputMethod: INPUT_METHOD.QUICK_INSERT
85
+ },
86
+ eventType: EVENT_TYPE.UI
87
+ })(tr);
88
+ return tr;
89
+ }
90
+ }];
91
+ }
92
+ },
93
+ contentComponent: function contentComponent(_ref4) {
94
+ var editorView = _ref4.editorView;
95
+ return /*#__PURE__*/React.createElement(HelpDialogLoader, {
96
+ pluginInjectionApi: api,
97
+ editorView: editorView,
98
+ quickInsertEnabled: !!(api !== null && api !== void 0 && api.quickInsert)
99
+ });
100
+ },
101
+ getSharedState: function getSharedState(editorState) {
102
+ if (!editorState) {
103
+ return null;
104
+ }
105
+ return pluginKey.getState(editorState) || null;
106
+ }
107
+ };
108
+ };
109
+ var keymapPlugin = function keymapPlugin(editorAnalyticsAPI) {
110
+ var list = {};
111
+ bindKeymapWithCommand(openHelp.common, function (state, dispatch) {
112
+ var tr = state.tr;
113
+ var isVisible = tr.getMeta(pluginKey);
114
+ if (!isVisible) {
115
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
116
+ action: ACTION.CLICKED,
117
+ actionSubject: ACTION_SUBJECT.BUTTON,
118
+ actionSubjectId: ACTION_SUBJECT_ID.BUTTON_HELP,
119
+ attributes: {
120
+ inputMethod: INPUT_METHOD.SHORTCUT
121
+ },
122
+ eventType: EVENT_TYPE.UI
123
+ })(tr);
124
+ openHelpCommand(tr, dispatch);
125
+ }
126
+ return true;
127
+ }, list);
128
+ return keymap(list);
129
+ };
@@ -0,0 +1,12 @@
1
+ import Loadable from 'react-loadable';
2
+ export var HelpDialogLoader = Loadable({
3
+ loader: function loader() {
4
+ return import( /* webpackChunkName: "@atlaskit-internal_editor-core-helpdialog" */
5
+ './index').then(function (mod) {
6
+ return mod.default;
7
+ });
8
+ },
9
+ loading: function loading() {
10
+ return null;
11
+ }
12
+ });
@@ -0,0 +1,552 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
+ /** @jsx jsx */
4
+ import { useCallback, useEffect } from 'react';
5
+ import { jsx } from '@emotion/react';
6
+ import { defineMessages, FormattedMessage, injectIntl } from 'react-intl-next';
7
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
8
+ import { addInlineComment, addLink, alignLeft, clearFormatting, insertRule, navToEditorToolbar, navToFloatingToolbar, openHelp, pastePlainText, redo, setNormalText, toggleBlockQuote, toggleBold, toggleBulletList, toggleCode, toggleHeading1, toggleHeading2, toggleHeading3, toggleHeading4, toggleHeading5, toggleHeading6, toggleItalic, toggleOrderedList, toggleStrikethrough, toggleSubscript, toggleSuperscript, toggleTaskItemCheckbox, toggleUnderline, undo } from '@atlaskit/editor-common/keymaps';
9
+ import { alignmentMessages, annotationMessages, blockTypeMessages, listMessages, toolbarInsertBlockMessages, toolbarMessages, undoRedoMessages } from '@atlaskit/editor-common/messages';
10
+ import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
11
+ import { browser } from '@atlaskit/editor-common/utils';
12
+ import CrossIcon from '@atlaskit/icon/glyph/cross';
13
+ import AkModalDialog, { ModalTransition, useModal } from '@atlaskit/modal-dialog';
14
+ import { closeHelpCommand } from '../commands';
15
+ import { codeLg, codeMd, codeSm, column, content, contentWrapper, dialogHeader, footer, header, line, row, title } from './styles';
16
+ var messages = defineMessages({
17
+ editorHelp: {
18
+ id: 'fabric.editor.editorHelp',
19
+ defaultMessage: 'Editor help',
20
+ description: 'Title of editor help dialog.'
21
+ },
22
+ helpDialogTips: {
23
+ id: 'fabric.editor.helpDialogTips',
24
+ defaultMessage: 'Press {keyMap} to quickly open this dialog at any time',
25
+ description: 'Hint about how to open a dialog quickly using a shortcut.'
26
+ },
27
+ keyboardShortcuts: {
28
+ id: 'fabric.editor.keyboardShortcuts',
29
+ defaultMessage: 'Keyboard shortcuts',
30
+ description: ''
31
+ },
32
+ markdown: {
33
+ id: 'fabric.editor.markdown',
34
+ defaultMessage: 'Markdown',
35
+ description: 'It is a name of popular markup language.'
36
+ },
37
+ pastePlainText: {
38
+ id: 'fabric.editor.pastePlainText',
39
+ defaultMessage: 'Paste plain text',
40
+ description: ''
41
+ },
42
+ CheckUncheckActionItem: {
43
+ id: 'fabric.editor.checkUncheckActionItem',
44
+ defaultMessage: 'Toggle action item',
45
+ description: 'For Check/Uncheck Action item use shortcut'
46
+ },
47
+ altText: {
48
+ id: 'fabric.editor.altText',
49
+ defaultMessage: 'Alt text',
50
+ description: 'Alternative text for image.'
51
+ },
52
+ closeHelpDialog: {
53
+ id: 'fabric.editor.closeHelpDialog',
54
+ defaultMessage: 'Close help dialog',
55
+ description: ''
56
+ },
57
+ // TODO: Move it inside quick insert plugin
58
+ quickInsert: {
59
+ id: 'fabric.editor.quickInsert',
60
+ defaultMessage: 'Quick insert',
61
+ description: 'Name of a feature, which let you insert items quickly.'
62
+ }
63
+ });
64
+ var navigationKeymaps = function navigationKeymaps(_ref) {
65
+ var formatMessage = _ref.formatMessage;
66
+ return [{
67
+ name: formatMessage(toolbarMessages.navigateToEditorToolbar),
68
+ type: 'navigation',
69
+ keymap: function keymap() {
70
+ return navToEditorToolbar;
71
+ }
72
+ }, {
73
+ name: formatMessage(toolbarMessages.navigateToFloatingToolbar),
74
+ type: 'navigation',
75
+ keymap: function keymap() {
76
+ return navToFloatingToolbar;
77
+ }
78
+ }];
79
+ };
80
+ export var formatting = function formatting(_ref2) {
81
+ var formatMessage = _ref2.formatMessage;
82
+ return [{
83
+ name: formatMessage(toolbarMessages.bold),
84
+ type: 'strong',
85
+ keymap: function keymap() {
86
+ return toggleBold;
87
+ },
88
+ autoFormatting: function autoFormatting() {
89
+ return jsx("span", null, jsx("span", {
90
+ css: codeLg
91
+ }, "**", jsx(FormattedMessage, toolbarMessages.bold), "**"));
92
+ }
93
+ }, {
94
+ name: formatMessage(toolbarMessages.italic),
95
+ type: 'em',
96
+ keymap: function keymap() {
97
+ return toggleItalic;
98
+ },
99
+ autoFormatting: function autoFormatting() {
100
+ return jsx("span", null, jsx("span", {
101
+ css: codeLg
102
+ }, "*", jsx(FormattedMessage, toolbarMessages.italic), "*"));
103
+ }
104
+ }, {
105
+ name: formatMessage(toolbarMessages.underline),
106
+ type: 'underline',
107
+ keymap: function keymap() {
108
+ return toggleUnderline;
109
+ }
110
+ }, {
111
+ name: formatMessage(toolbarMessages.strike),
112
+ type: 'strike',
113
+ keymap: function keymap() {
114
+ return toggleStrikethrough;
115
+ },
116
+ autoFormatting: function autoFormatting() {
117
+ return jsx("span", null, jsx("span", {
118
+ css: codeLg
119
+ }, "~~", jsx(FormattedMessage, toolbarMessages.strike), "~~"));
120
+ }
121
+ }, {
122
+ name: formatMessage(toolbarMessages.subscript),
123
+ type: 'subsup',
124
+ keymap: function keymap() {
125
+ return toggleSubscript;
126
+ }
127
+ }, {
128
+ name: formatMessage(toolbarMessages.superscript),
129
+ type: 'subsup',
130
+ keymap: function keymap() {
131
+ return toggleSuperscript;
132
+ }
133
+ }, {
134
+ name: formatMessage(blockTypeMessages.heading1),
135
+ type: 'heading',
136
+ keymap: function keymap() {
137
+ return toggleHeading1;
138
+ },
139
+ autoFormatting: function autoFormatting() {
140
+ return jsx("span", null, jsx("span", {
141
+ css: codeSm
142
+ }, "#"), " ", jsx("span", {
143
+ css: codeLg
144
+ }, "Space"));
145
+ }
146
+ }, {
147
+ name: formatMessage(blockTypeMessages.heading2),
148
+ type: 'heading',
149
+ keymap: function keymap() {
150
+ return toggleHeading2;
151
+ },
152
+ autoFormatting: function autoFormatting() {
153
+ return jsx("span", null, jsx("span", {
154
+ css: codeLg
155
+ }, "##"), " ", jsx("span", {
156
+ css: codeLg
157
+ }, "Space"));
158
+ }
159
+ }, {
160
+ name: formatMessage(blockTypeMessages.heading3),
161
+ type: 'heading',
162
+ keymap: function keymap() {
163
+ return toggleHeading3;
164
+ },
165
+ autoFormatting: function autoFormatting() {
166
+ return jsx("span", null, jsx("span", {
167
+ css: codeLg
168
+ }, "###"), " ", jsx("span", {
169
+ css: codeLg
170
+ }, "Space"));
171
+ }
172
+ }, {
173
+ name: formatMessage(blockTypeMessages.heading4),
174
+ type: 'heading',
175
+ keymap: function keymap() {
176
+ return toggleHeading4;
177
+ },
178
+ autoFormatting: function autoFormatting() {
179
+ return jsx("span", null, jsx("span", {
180
+ css: codeLg
181
+ }, "####"), " ", jsx("span", {
182
+ css: codeLg
183
+ }, "Space"));
184
+ }
185
+ }, {
186
+ name: formatMessage(blockTypeMessages.heading5),
187
+ type: 'heading',
188
+ keymap: function keymap() {
189
+ return toggleHeading5;
190
+ },
191
+ autoFormatting: function autoFormatting() {
192
+ return jsx("span", null, jsx("span", {
193
+ css: codeLg
194
+ }, "#####"), " ", jsx("span", {
195
+ css: codeLg
196
+ }, "Space"));
197
+ }
198
+ }, {
199
+ name: formatMessage(blockTypeMessages.heading6),
200
+ type: 'heading',
201
+ keymap: function keymap() {
202
+ return toggleHeading6;
203
+ },
204
+ autoFormatting: function autoFormatting() {
205
+ return jsx("span", null, jsx("span", {
206
+ css: codeLg
207
+ }, "######"), " ", jsx("span", {
208
+ css: codeLg
209
+ }, "Space"));
210
+ }
211
+ }, {
212
+ name: formatMessage(blockTypeMessages.normal),
213
+ type: 'paragraph',
214
+ keymap: function keymap() {
215
+ return setNormalText;
216
+ }
217
+ }, {
218
+ name: formatMessage(listMessages.orderedList),
219
+ type: 'orderedList',
220
+ keymap: function keymap() {
221
+ return toggleOrderedList;
222
+ },
223
+ autoFormatting: function autoFormatting() {
224
+ return jsx("span", null, jsx("span", {
225
+ css: codeSm
226
+ }, "1."), " ", jsx("span", {
227
+ css: codeLg
228
+ }, "Space"));
229
+ }
230
+ }, {
231
+ name: formatMessage(listMessages.unorderedList),
232
+ type: 'bulletList',
233
+ keymap: function keymap() {
234
+ return toggleBulletList;
235
+ },
236
+ autoFormatting: function autoFormatting() {
237
+ return jsx("span", null, jsx("span", {
238
+ css: codeSm
239
+ }, "*"), " ", jsx("span", {
240
+ css: codeLg
241
+ }, "Space"));
242
+ }
243
+ }, {
244
+ name: formatMessage(blockTypeMessages.blockquote),
245
+ type: 'blockquote',
246
+ keymap: function keymap() {
247
+ return toggleBlockQuote;
248
+ },
249
+ autoFormatting: function autoFormatting() {
250
+ return jsx("span", null, jsx("span", {
251
+ css: codeLg
252
+ }, '>'), " ", jsx("span", {
253
+ css: codeLg
254
+ }, "Space"));
255
+ }
256
+ }, {
257
+ name: formatMessage(blockTypeMessages.codeblock),
258
+ type: 'codeBlock',
259
+ autoFormatting: function autoFormatting() {
260
+ return jsx("span", null, jsx("span", {
261
+ css: codeLg
262
+ }, "```"));
263
+ }
264
+ }, {
265
+ name: formatMessage(toolbarInsertBlockMessages.horizontalRule),
266
+ type: 'rule',
267
+ keymap: function keymap() {
268
+ return insertRule;
269
+ },
270
+ autoFormatting: function autoFormatting() {
271
+ return jsx("span", null, jsx("span", {
272
+ css: codeLg
273
+ }, "---"));
274
+ }
275
+ }, {
276
+ name: formatMessage(toolbarInsertBlockMessages.link),
277
+ type: 'link',
278
+ keymap: function keymap() {
279
+ return addLink;
280
+ },
281
+ autoFormatting: function autoFormatting() {
282
+ return jsx("span", null, jsx("span", {
283
+ css: codeLg
284
+ }, "[", jsx(FormattedMessage, toolbarInsertBlockMessages.link), "](http://a.com)"));
285
+ }
286
+ }, {
287
+ name: formatMessage(toolbarMessages.code),
288
+ type: 'code',
289
+ keymap: function keymap() {
290
+ return toggleCode;
291
+ },
292
+ autoFormatting: function autoFormatting() {
293
+ return jsx("span", null, jsx("span", {
294
+ css: codeLg
295
+ }, "`", jsx(FormattedMessage, toolbarMessages.code), "`"));
296
+ }
297
+ }, {
298
+ name: formatMessage(toolbarInsertBlockMessages.action),
299
+ type: 'taskItem',
300
+ autoFormatting: function autoFormatting() {
301
+ return jsx("span", null, jsx("span", {
302
+ css: codeSm
303
+ }, "[]"), " ", jsx("span", {
304
+ css: codeLg
305
+ }, "Space"));
306
+ }
307
+ }, {
308
+ name: formatMessage(toolbarInsertBlockMessages.decision),
309
+ type: 'decisionItem',
310
+ autoFormatting: function autoFormatting() {
311
+ return jsx("span", null, jsx("span", {
312
+ css: codeSm
313
+ }, "<>"), " ", jsx("span", {
314
+ css: codeLg
315
+ }, "Space"));
316
+ }
317
+ }, {
318
+ name: formatMessage(toolbarInsertBlockMessages.emoji),
319
+ type: 'emoji',
320
+ autoFormatting: function autoFormatting() {
321
+ return jsx("span", null, jsx("span", {
322
+ css: codeLg
323
+ }, ":"));
324
+ }
325
+ }, {
326
+ name: formatMessage(toolbarInsertBlockMessages.mention),
327
+ type: 'mention',
328
+ autoFormatting: function autoFormatting() {
329
+ return jsx("span", null, jsx("span", {
330
+ css: codeLg
331
+ }, "@"));
332
+ }
333
+ }, {
334
+ name: formatMessage(alignmentMessages.alignLeft),
335
+ type: 'alignment',
336
+ keymap: function keymap() {
337
+ return alignLeft;
338
+ }
339
+ }, {
340
+ name: formatMessage(alignmentMessages.alignRight),
341
+ type: 'alignment'
342
+ }];
343
+ };
344
+ var shortcutNamesWithoutKeymap = ['emoji', 'mention', 'quickInsert'];
345
+ var otherFormatting = function otherFormatting(_ref3) {
346
+ var formatMessage = _ref3.formatMessage;
347
+ return [{
348
+ name: formatMessage(toolbarMessages.clearFormatting),
349
+ type: 'clearFormatting',
350
+ keymap: function keymap() {
351
+ return clearFormatting;
352
+ }
353
+ }, {
354
+ name: formatMessage(undoRedoMessages.undo),
355
+ type: 'undo',
356
+ keymap: function keymap() {
357
+ return undo;
358
+ }
359
+ }, {
360
+ name: formatMessage(undoRedoMessages.redo),
361
+ type: 'redo',
362
+ keymap: function keymap() {
363
+ return redo;
364
+ }
365
+ }, {
366
+ name: formatMessage(messages.pastePlainText),
367
+ type: 'paste',
368
+ keymap: function keymap() {
369
+ return pastePlainText;
370
+ }
371
+ }, {
372
+ name: formatMessage(annotationMessages.createComment),
373
+ type: 'annotation',
374
+ keymap: function keymap() {
375
+ return addInlineComment;
376
+ }
377
+ }, {
378
+ name: formatMessage(messages.CheckUncheckActionItem),
379
+ type: 'checkbox',
380
+ keymap: function keymap() {
381
+ return toggleTaskItemCheckbox;
382
+ }
383
+ }];
384
+ };
385
+ var imageAutoFormat = {
386
+ name: 'Image',
387
+ type: 'image',
388
+ autoFormatting: function autoFormatting() {
389
+ return jsx("span", null, jsx("span", {
390
+ css: codeLg
391
+ }, "![", jsx(FormattedMessage, messages.altText), "](http://www.image.com)"));
392
+ }
393
+ };
394
+ var quickInsertAutoFormat = function quickInsertAutoFormat(_ref4) {
395
+ var formatMessage = _ref4.formatMessage;
396
+ return {
397
+ name: formatMessage(messages.quickInsert),
398
+ type: 'quickInsert',
399
+ autoFormatting: function autoFormatting() {
400
+ return jsx("span", null, jsx("span", {
401
+ css: codeLg
402
+ }, "/"));
403
+ }
404
+ };
405
+ };
406
+ var getKeyParts = function getKeyParts(keymap) {
407
+ var shortcut = keymap[browser.mac ? 'mac' : 'windows'];
408
+ if (browser.mac) {
409
+ shortcut = shortcut.replace('Alt', 'Opt');
410
+ }
411
+ return shortcut.replace(/\-(?=.)/g, ' + ').split(' ');
412
+ };
413
+ export var getSupportedFormatting = function getSupportedFormatting(schema, intl, imageEnabled, quickInsertEnabled) {
414
+ var supportedBySchema = formatting(intl).filter(function (format) {
415
+ return schema.nodes[format.type] || schema.marks[format.type];
416
+ });
417
+ return [].concat(_toConsumableArray(navigationKeymaps(intl)), _toConsumableArray(supportedBySchema), _toConsumableArray(imageEnabled ? [imageAutoFormat] : []), _toConsumableArray(quickInsertEnabled ? [quickInsertAutoFormat(intl)] : []), _toConsumableArray(otherFormatting(intl)));
418
+ };
419
+ export var getComponentFromKeymap = function getComponentFromKeymap(keymap) {
420
+ var keyParts = getKeyParts(keymap);
421
+ return jsx("span", null, keyParts.map(function (part, index) {
422
+ if (part === '+') {
423
+ return jsx("span", {
424
+ key: "".concat(keyParts, "-").concat(index)
425
+ }, ' + ');
426
+ } else if (part === 'Cmd') {
427
+ return jsx("span", {
428
+ css: codeSm,
429
+ key: "".concat(keyParts, "-").concat(index)
430
+ }, "\u2318");
431
+ } else if (['ctrl', 'alt', 'opt', 'shift'].indexOf(part.toLowerCase()) >= 0) {
432
+ return jsx("span", {
433
+ css: codeMd,
434
+ key: "".concat(keyParts, "-").concat(index)
435
+ }, part);
436
+ } else if (['f9', 'f10'].indexOf(part.toLowerCase()) >= 0) {
437
+ return jsx("span", {
438
+ css: codeLg,
439
+ key: "".concat(keyParts, "-").concat(index)
440
+ }, part);
441
+ } else if (part.toLowerCase() === 'enter') {
442
+ return jsx("span", {
443
+ css: codeSm,
444
+ key: "".concat(keyParts, "-").concat(index)
445
+ }, '⏎');
446
+ }
447
+ return jsx("span", {
448
+ css: codeSm,
449
+ key: "".concat(keyParts, "-").concat(index)
450
+ }, part.toUpperCase());
451
+ }));
452
+ };
453
+ var ModalHeader = injectIntl(function (_ref5) {
454
+ var formatMessage = _ref5.intl.formatMessage;
455
+ var _useModal = useModal(),
456
+ onClose = _useModal.onClose;
457
+ return jsx("div", {
458
+ css: header
459
+ }, jsx("h1", {
460
+ css: dialogHeader
461
+ }, jsx(FormattedMessage, messages.editorHelp)), jsx("div", null, jsx(ToolbarButton
462
+ // @ts-ignore
463
+ , {
464
+ onClick: onClose,
465
+ title: formatMessage(messages.closeHelpDialog),
466
+ spacing: "compact",
467
+ iconBefore: jsx(CrossIcon, {
468
+ label: formatMessage(messages.closeHelpDialog),
469
+ size: "medium"
470
+ })
471
+ })));
472
+ });
473
+ var ModalFooter = function ModalFooter() {
474
+ return jsx("div", {
475
+ css: footer
476
+ }, jsx(FormattedMessage, _extends({}, messages.helpDialogTips, {
477
+ values: {
478
+ keyMap: getComponentFromKeymap(openHelp)
479
+ }
480
+ })));
481
+ };
482
+ var HelpDialog = function HelpDialog(_ref6) {
483
+ var pluginInjectionApi = _ref6.pluginInjectionApi,
484
+ editorView = _ref6.editorView,
485
+ quickInsertEnabled = _ref6.quickInsertEnabled,
486
+ intl = _ref6.intl;
487
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['helpDialog']),
488
+ helpDialogState = _useSharedPluginState.helpDialogState;
489
+ var closeDialog = useCallback(function () {
490
+ var tr = editorView.state.tr,
491
+ dispatch = editorView.dispatch;
492
+ closeHelpCommand(tr, dispatch);
493
+ }, [editorView]);
494
+ var handleEsc = useCallback(function (e) {
495
+ if (e.key === 'Escape' && helpDialogState !== null && helpDialogState !== void 0 && helpDialogState.isVisible) {
496
+ closeDialog();
497
+ }
498
+ }, [closeDialog, helpDialogState === null || helpDialogState === void 0 ? void 0 : helpDialogState.isVisible]);
499
+ useEffect(function () {
500
+ document.addEventListener('keydown', handleEsc);
501
+ return function () {
502
+ document.removeEventListener('keydown', handleEsc);
503
+ };
504
+ }, [handleEsc]);
505
+ var formatting = getSupportedFormatting(editorView.state.schema, intl, helpDialogState === null || helpDialogState === void 0 ? void 0 : helpDialogState.imageEnabled, quickInsertEnabled);
506
+ return jsx(ModalTransition, null, helpDialogState !== null && helpDialogState !== void 0 && helpDialogState.isVisible ? jsx(AkModalDialog, {
507
+ width: "large",
508
+ onClose: closeDialog,
509
+ testId: "help-modal-dialog"
510
+ }, jsx(ModalHeader, null), jsx("div", {
511
+ css: contentWrapper
512
+ }, jsx("div", {
513
+ css: line
514
+ }), jsx("div", {
515
+ css: content
516
+ }, jsx("div", {
517
+ css: column
518
+ }, jsx("h2", {
519
+ css: title
520
+ }, jsx(FormattedMessage, messages.keyboardShortcuts)), jsx("ul", null, formatting.filter(function (form) {
521
+ var keymap = form.keymap && form.keymap();
522
+ return keymap && keymap[browser.mac ? 'mac' : 'windows'];
523
+ }).map(function (form) {
524
+ return jsx("li", {
525
+ css: row,
526
+ key: "textFormatting-".concat(form.name)
527
+ }, jsx("span", null, form.name), getComponentFromKeymap(form.keymap()));
528
+ }), formatting.filter(function (form) {
529
+ return shortcutNamesWithoutKeymap.indexOf(form.type) !== -1;
530
+ }).filter(function (form) {
531
+ return form.autoFormatting;
532
+ }).map(function (form) {
533
+ return jsx("li", {
534
+ css: row,
535
+ key: "autoFormatting-".concat(form.name)
536
+ }, jsx("span", null, form.name), form.autoFormatting());
537
+ }))), jsx("div", {
538
+ css: line
539
+ }), jsx("div", {
540
+ css: column
541
+ }, jsx("h2", {
542
+ css: title
543
+ }, jsx(FormattedMessage, messages.markdown)), jsx("ul", null, formatting.filter(function (form) {
544
+ return shortcutNamesWithoutKeymap.indexOf(form.type) === -1;
545
+ }).map(function (form) {
546
+ return form.autoFormatting && jsx("li", {
547
+ key: "autoFormatting-".concat(form.name),
548
+ css: row
549
+ }, jsx("span", null, form.name), form.autoFormatting());
550
+ }))))), jsx(ModalFooter, null)) : null);
551
+ };
552
+ export default injectIntl(HelpDialog);