@atlaskit/editor-plugin-undo-redo 2.0.7 → 2.0.9

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/editor-plugin-undo-redo
2
2
 
3
+ ## 2.0.9
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 2.0.8
10
+
11
+ ### Patch Changes
12
+
13
+ - [#130818](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/130818)
14
+ [`0e42cb4df2b7f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0e42cb4df2b7f) -
15
+ Changed undo/redo commands to use EXTRENAL input type when no inputSource is provided. Ensure type
16
+ ahead is closed before undo/redo and that editor is re-focused after undo/redo.
17
+
3
18
  ## 2.0.7
4
19
 
5
20
  ### Patch Changes
@@ -8,6 +8,6 @@ var _analytics = require("@atlaskit/editor-common/analytics");
8
8
  var InputSource = exports.InputSource = function (InputSource) {
9
9
  InputSource[InputSource["TOOLBAR"] = _analytics.INPUT_METHOD.TOOLBAR] = "TOOLBAR";
10
10
  InputSource[InputSource["KEYBOARD"] = _analytics.INPUT_METHOD.KEYBOARD] = "KEYBOARD";
11
- InputSource[InputSource["PAGE_OVERFLOW_MENU"] = _analytics.INPUT_METHOD.PAGE_OVERFLOW_MENU] = "PAGE_OVERFLOW_MENU";
11
+ InputSource[InputSource["EXTERNAL"] = _analytics.INPUT_METHOD.EXTERNAL] = "EXTERNAL";
12
12
  return InputSource;
13
13
  }({});
@@ -7,6 +7,7 @@ exports.keymapPlugin = keymapPlugin;
7
7
  var _keymaps = require("@atlaskit/editor-common/keymaps");
8
8
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
9
9
  var _keymap = require("@atlaskit/editor-prosemirror/keymap");
10
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
11
  var _commands = require("./commands");
11
12
  function keymapPlugin() {
12
13
  var list = {};
@@ -14,6 +15,10 @@ function keymapPlugin() {
14
15
  // Ignored via go/ees005
15
16
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
16
17
  (0, _keymaps.bindKeymapWithCommand)((0, _keymaps.findKeyMapForBrowser)(_keymaps.redo), _commands.redoFromKeyboard, list);
18
+ if ((0, _platformFeatureFlags.fg)('platform_editor_cmd_y_mac_redo_shortcut')) {
19
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20
+ (0, _keymaps.bindKeymapWithCommand)((0, _keymaps.findKeyMapForBrowser)(_keymaps.redoAlt), _commands.redoFromKeyboard, list);
21
+ }
17
22
 
18
23
  // Ignored via go/ees005
19
24
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.forceFocus = exports.closeTypeAheadAndRunCommand = void 0;
7
+ var closeTypeAheadAndRunCommand = exports.closeTypeAheadAndRunCommand = function closeTypeAheadAndRunCommand(editorView, api) {
8
+ return function (command) {
9
+ var _api$typeAhead;
10
+ if (!editorView) {
11
+ return false;
12
+ }
13
+ if (api !== null && api !== void 0 && (_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && (_api$typeAhead = _api$typeAhead.actions) !== null && _api$typeAhead !== void 0 && _api$typeAhead.isOpen(editorView.state)) {
14
+ var _api$typeAhead2;
15
+ api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 || (_api$typeAhead2 = _api$typeAhead2.actions) === null || _api$typeAhead2 === void 0 || _api$typeAhead2.close({
16
+ attachCommand: command,
17
+ insertCurrentQueryAsRawText: false
18
+ });
19
+ } else {
20
+ command(editorView.state, editorView.dispatch);
21
+ }
22
+ return true;
23
+ };
24
+ };
25
+ var forceFocus = exports.forceFocus = function forceFocus(editorView, api) {
26
+ return function (command) {
27
+ var result = closeTypeAheadAndRunCommand(editorView, api)(command);
28
+ if (result && !editorView.hasFocus()) {
29
+ editorView.focus();
30
+ }
31
+ return result;
32
+ };
33
+ };
@@ -16,37 +16,13 @@ var _redo = _interopRequireDefault(require("@atlaskit/icon/core/migration/redo")
16
16
  var _undo = _interopRequireDefault(require("@atlaskit/icon/core/migration/undo"));
17
17
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
18
18
  var _commands = require("../../pm-plugins/commands");
19
+ var _utils = require("../../pm-plugins/utils");
19
20
  /**
20
21
  * @jsxRuntime classic
21
22
  * @jsx jsx
22
23
  */
23
24
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
24
25
 
25
- var closeTypeAheadAndRunCommand = function closeTypeAheadAndRunCommand(editorView, api) {
26
- return function (command) {
27
- var _api$typeAhead;
28
- if (!editorView) {
29
- return;
30
- }
31
- if (api !== null && api !== void 0 && (_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && (_api$typeAhead = _api$typeAhead.actions) !== null && _api$typeAhead !== void 0 && _api$typeAhead.isOpen(editorView.state)) {
32
- var _api$typeAhead2;
33
- api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 || (_api$typeAhead2 = _api$typeAhead2.actions) === null || _api$typeAhead2 === void 0 || _api$typeAhead2.close({
34
- attachCommand: command,
35
- insertCurrentQueryAsRawText: false
36
- });
37
- } else {
38
- command(editorView.state, editorView.dispatch);
39
- }
40
- };
41
- };
42
- var forceFocus = function forceFocus(editorView, api) {
43
- return function (command) {
44
- closeTypeAheadAndRunCommand(editorView, api)(command);
45
- if (!editorView.hasFocus()) {
46
- editorView.focus();
47
- }
48
- };
49
- };
50
26
  var ToolbarUndoRedo = exports.ToolbarUndoRedo = function ToolbarUndoRedo(_ref) {
51
27
  var disabled = _ref.disabled,
52
28
  isReducedSpacing = _ref.isReducedSpacing,
@@ -56,16 +32,17 @@ var ToolbarUndoRedo = exports.ToolbarUndoRedo = function ToolbarUndoRedo(_ref) {
56
32
  var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['history']),
57
33
  historyState = _useSharedPluginState.historyState;
58
34
  var handleUndo = function handleUndo() {
59
- forceFocus(editorView, api)(_commands.undoFromToolbar);
35
+ (0, _utils.forceFocus)(editorView, api)(_commands.undoFromToolbar);
60
36
  };
61
37
  var handleRedo = function handleRedo() {
62
- forceFocus(editorView, api)(_commands.redoFromToolbar);
38
+ (0, _utils.forceFocus)(editorView, api)(_commands.redoFromToolbar);
63
39
  };
64
40
  var labelUndo = formatMessage(_messages.undoRedoMessages.undo);
65
41
  var labelRedo = formatMessage(_messages.undoRedoMessages.redo);
66
42
  var _ref2 = historyState !== null && historyState !== void 0 ? historyState : {},
67
43
  canUndo = _ref2.canUndo,
68
44
  canRedo = _ref2.canRedo;
45
+ var redoKeymap = (0, _platformFeatureFlags.fg)('platform_editor_cmd_y_mac_redo_shortcut') ? _keymaps.redoAlt : _keymaps.redo;
69
46
  return (
70
47
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
71
48
  (0, _react.jsx)("span", {
@@ -100,7 +77,7 @@ var ToolbarUndoRedo = exports.ToolbarUndoRedo = function ToolbarUndoRedo(_ref) {
100
77
  disabled: !canRedo || disabled,
101
78
  title: (0, _react.jsx)(_keymaps.ToolTipContent, {
102
79
  description: labelRedo,
103
- keymap: _keymaps.redo
80
+ keymap: redoKeymap
104
81
  }),
105
82
  iconBefore: (0, _react.jsx)(_redo.default, {
106
83
  label: "",
@@ -108,8 +85,8 @@ var ToolbarUndoRedo = exports.ToolbarUndoRedo = function ToolbarUndoRedo(_ref) {
108
85
  spacing: "spacious"
109
86
  }),
110
87
  testId: "ak-editor-toolbar-button-redo",
111
- "aria-label": (0, _keymaps.tooltip)(_keymaps.redo, labelRedo),
112
- "aria-keyshortcuts": (0, _keymaps.getAriaKeyshortcuts)(_keymaps.redo)
88
+ "aria-label": (0, _keymaps.tooltip)(redoKeymap, labelRedo),
89
+ "aria-keyshortcuts": (0, _keymaps.getAriaKeyshortcuts)(redoKeymap)
113
90
  }), !(api !== null && api !== void 0 && api.primaryToolbar) && /* eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage */
114
91
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
115
92
  (0, _react.jsx)("span", {
@@ -10,10 +10,11 @@ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
10
  var _history = require("@atlaskit/editor-prosemirror/history");
11
11
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
12
12
  var _attachInputMeta = require("./pm-plugins/attach-input-meta");
13
+ var _enums = require("./pm-plugins/enums");
13
14
  var _keymaps = require("./pm-plugins/keymaps");
14
15
  var _main = require("./pm-plugins/main");
16
+ var _utils = require("./pm-plugins/utils");
15
17
  var _ToolbarUndoRedo = _interopRequireDefault(require("./ui/ToolbarUndoRedo"));
16
- // eslint-disable-next-line @atlassian/tangerine/import/entry-points
17
18
  // Ignored via go/ees005
18
19
  // eslint-disable-next-line import/no-named-as-default
19
20
 
@@ -38,33 +39,23 @@ var undoRedoPlugin = exports.undoRedoPlugin = function undoRedoPlugin(_ref) {
38
39
  name: 'undoRedoPlugin',
39
40
  component: primaryToolbarComponent
40
41
  });
42
+ var handleUndo = function handleUndo(inputSource) {
43
+ if (!editorViewRef.current) {
44
+ return false;
45
+ }
46
+ return (0, _utils.forceFocus)(editorViewRef.current, api)((0, _attachInputMeta.attachInputMeta)(inputSource || _enums.InputSource.EXTERNAL)(_history.undo));
47
+ };
48
+ var handleRedo = function handleRedo(inputSource) {
49
+ if (!editorViewRef.current) {
50
+ return false;
51
+ }
52
+ return (0, _utils.forceFocus)(editorViewRef.current, api)((0, _attachInputMeta.attachInputMeta)(inputSource || _enums.InputSource.EXTERNAL)(_history.redo));
53
+ };
41
54
  return {
42
55
  name: 'undoRedoPlugin',
43
56
  actions: {
44
- undo: function undo(inputSource) {
45
- if (!editorViewRef.current) {
46
- return false;
47
- }
48
- var _editorViewRef$curren = editorViewRef.current,
49
- state = _editorViewRef$curren.state,
50
- dispatch = _editorViewRef$curren.dispatch;
51
- if (!inputSource) {
52
- return (0, _history.undo)(state, dispatch);
53
- }
54
- return (0, _attachInputMeta.attachInputMeta)(inputSource)(_history.undo)(state, dispatch);
55
- },
56
- redo: function redo(inputSource) {
57
- if (!editorViewRef.current) {
58
- return false;
59
- }
60
- var _editorViewRef$curren2 = editorViewRef.current,
61
- state = _editorViewRef$curren2.state,
62
- dispatch = _editorViewRef$curren2.dispatch;
63
- if (!inputSource) {
64
- return (0, _history.redo)(state, dispatch);
65
- }
66
- return (0, _attachInputMeta.attachInputMeta)(inputSource)(_history.redo)(state, dispatch);
67
- }
57
+ undo: handleUndo,
58
+ redo: handleRedo
68
59
  },
69
60
  pmPlugins: function pmPlugins() {
70
61
  var plugins = [{
@@ -2,6 +2,6 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  export let InputSource = function (InputSource) {
3
3
  InputSource[InputSource["TOOLBAR"] = INPUT_METHOD.TOOLBAR] = "TOOLBAR";
4
4
  InputSource[InputSource["KEYBOARD"] = INPUT_METHOD.KEYBOARD] = "KEYBOARD";
5
- InputSource[InputSource["PAGE_OVERFLOW_MENU"] = INPUT_METHOD.PAGE_OVERFLOW_MENU] = "PAGE_OVERFLOW_MENU";
5
+ InputSource[InputSource["EXTERNAL"] = INPUT_METHOD.EXTERNAL] = "EXTERNAL";
6
6
  return InputSource;
7
7
  }({});
@@ -1,6 +1,7 @@
1
- import { bindKeymapWithCommand, findKeyMapForBrowser, isCapsLockOnAndModifyKeyboardEvent, redo, undo } from '@atlaskit/editor-common/keymaps';
1
+ import { bindKeymapWithCommand, findKeyMapForBrowser, isCapsLockOnAndModifyKeyboardEvent, redo, redoAlt, undo } from '@atlaskit/editor-common/keymaps';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
4
5
  import { redoFromKeyboard, undoFromKeyboard } from './commands';
5
6
  export function keymapPlugin() {
6
7
  const list = {};
@@ -8,6 +9,10 @@ export function keymapPlugin() {
8
9
  // Ignored via go/ees005
9
10
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
10
11
  bindKeymapWithCommand(findKeyMapForBrowser(redo), redoFromKeyboard, list);
12
+ if (fg('platform_editor_cmd_y_mac_redo_shortcut')) {
13
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
14
+ bindKeymapWithCommand(findKeyMapForBrowser(redoAlt), redoFromKeyboard, list);
15
+ }
11
16
 
12
17
  // Ignored via go/ees005
13
18
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -0,0 +1,23 @@
1
+ export const closeTypeAheadAndRunCommand = (editorView, api) => command => {
2
+ var _api$typeAhead, _api$typeAhead$action;
3
+ if (!editorView) {
4
+ return false;
5
+ }
6
+ if (api !== null && api !== void 0 && (_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && (_api$typeAhead$action = _api$typeAhead.actions) !== null && _api$typeAhead$action !== void 0 && _api$typeAhead$action.isOpen(editorView.state)) {
7
+ var _api$typeAhead2, _api$typeAhead2$actio;
8
+ api === null || api === void 0 ? void 0 : (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : (_api$typeAhead2$actio = _api$typeAhead2.actions) === null || _api$typeAhead2$actio === void 0 ? void 0 : _api$typeAhead2$actio.close({
9
+ attachCommand: command,
10
+ insertCurrentQueryAsRawText: false
11
+ });
12
+ } else {
13
+ command(editorView.state, editorView.dispatch);
14
+ }
15
+ return true;
16
+ };
17
+ export const forceFocus = (editorView, api) => command => {
18
+ const result = closeTypeAheadAndRunCommand(editorView, api)(command);
19
+ if (result && !editorView.hasFocus()) {
20
+ editorView.focus();
21
+ }
22
+ return result;
23
+ };
@@ -6,7 +6,7 @@
6
6
  import { jsx } from '@emotion/react';
7
7
  import { injectIntl } from 'react-intl-next';
8
8
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
9
- import { getAriaKeyshortcuts, redo as redoKeymap, tooltip, ToolTipContent, undo as undoKeymap } from '@atlaskit/editor-common/keymaps';
9
+ import { getAriaKeyshortcuts, redo, redoAlt, tooltip, ToolTipContent, undo as undoKeymap } from '@atlaskit/editor-common/keymaps';
10
10
  import { undoRedoMessages } from '@atlaskit/editor-common/messages';
11
11
  import { buttonGroupStyle, buttonGroupStyleBeforeVisualRefresh, separatorStyles } from '@atlaskit/editor-common/styles';
12
12
  import { TOOLBAR_BUTTON, ToolbarButton } from '@atlaskit/editor-common/ui-menu';
@@ -14,27 +14,7 @@ import RedoIcon from '@atlaskit/icon/core/migration/redo';
14
14
  import UndoIcon from '@atlaskit/icon/core/migration/undo';
15
15
  import { fg } from '@atlaskit/platform-feature-flags';
16
16
  import { redoFromToolbar, undoFromToolbar } from '../../pm-plugins/commands';
17
- const closeTypeAheadAndRunCommand = (editorView, api) => command => {
18
- var _api$typeAhead, _api$typeAhead$action;
19
- if (!editorView) {
20
- return;
21
- }
22
- if (api !== null && api !== void 0 && (_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && (_api$typeAhead$action = _api$typeAhead.actions) !== null && _api$typeAhead$action !== void 0 && _api$typeAhead$action.isOpen(editorView.state)) {
23
- var _api$typeAhead2, _api$typeAhead2$actio;
24
- api === null || api === void 0 ? void 0 : (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : (_api$typeAhead2$actio = _api$typeAhead2.actions) === null || _api$typeAhead2$actio === void 0 ? void 0 : _api$typeAhead2$actio.close({
25
- attachCommand: command,
26
- insertCurrentQueryAsRawText: false
27
- });
28
- } else {
29
- command(editorView.state, editorView.dispatch);
30
- }
31
- };
32
- const forceFocus = (editorView, api) => command => {
33
- closeTypeAheadAndRunCommand(editorView, api)(command);
34
- if (!editorView.hasFocus()) {
35
- editorView.focus();
36
- }
37
- };
17
+ import { forceFocus } from '../../pm-plugins/utils';
38
18
  export const ToolbarUndoRedo = ({
39
19
  disabled,
40
20
  isReducedSpacing,
@@ -59,6 +39,7 @@ export const ToolbarUndoRedo = ({
59
39
  canUndo,
60
40
  canRedo
61
41
  } = historyState !== null && historyState !== void 0 ? historyState : {};
42
+ const redoKeymap = fg('platform_editor_cmd_y_mac_redo_shortcut') ? redoAlt : redo;
62
43
  return (
63
44
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
64
45
  jsx("span", {
@@ -3,9 +3,10 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import { redo, undo } from '@atlaskit/editor-prosemirror/history';
4
4
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
5
  import { attachInputMeta } from './pm-plugins/attach-input-meta';
6
+ import { InputSource } from './pm-plugins/enums';
6
7
  import { keymapPlugin } from './pm-plugins/keymaps';
7
8
  import { createPlugin } from './pm-plugins/main';
8
- // eslint-disable-next-line @atlassian/tangerine/import/entry-points
9
+ import { forceFocus } from './pm-plugins/utils';
9
10
  // Ignored via go/ees005
10
11
  // eslint-disable-next-line import/no-named-as-default
11
12
  import ToolbarUndoRedo from './ui/ToolbarUndoRedo';
@@ -32,35 +33,23 @@ export const undoRedoPlugin = ({
32
33
  name: 'undoRedoPlugin',
33
34
  component: primaryToolbarComponent
34
35
  });
36
+ const handleUndo = inputSource => {
37
+ if (!editorViewRef.current) {
38
+ return false;
39
+ }
40
+ return forceFocus(editorViewRef.current, api)(attachInputMeta(inputSource || InputSource.EXTERNAL)(undo));
41
+ };
42
+ const handleRedo = inputSource => {
43
+ if (!editorViewRef.current) {
44
+ return false;
45
+ }
46
+ return forceFocus(editorViewRef.current, api)(attachInputMeta(inputSource || InputSource.EXTERNAL)(redo));
47
+ };
35
48
  return {
36
49
  name: 'undoRedoPlugin',
37
50
  actions: {
38
- undo: inputSource => {
39
- if (!editorViewRef.current) {
40
- return false;
41
- }
42
- const {
43
- state,
44
- dispatch
45
- } = editorViewRef.current;
46
- if (!inputSource) {
47
- return undo(state, dispatch);
48
- }
49
- return attachInputMeta(inputSource)(undo)(state, dispatch);
50
- },
51
- redo: inputSource => {
52
- if (!editorViewRef.current) {
53
- return false;
54
- }
55
- const {
56
- state,
57
- dispatch
58
- } = editorViewRef.current;
59
- if (!inputSource) {
60
- return redo(state, dispatch);
61
- }
62
- return attachInputMeta(inputSource)(redo)(state, dispatch);
63
- }
51
+ undo: handleUndo,
52
+ redo: handleRedo
64
53
  },
65
54
  pmPlugins() {
66
55
  const plugins = [{
@@ -2,6 +2,6 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  export var InputSource = function (InputSource) {
3
3
  InputSource[InputSource["TOOLBAR"] = INPUT_METHOD.TOOLBAR] = "TOOLBAR";
4
4
  InputSource[InputSource["KEYBOARD"] = INPUT_METHOD.KEYBOARD] = "KEYBOARD";
5
- InputSource[InputSource["PAGE_OVERFLOW_MENU"] = INPUT_METHOD.PAGE_OVERFLOW_MENU] = "PAGE_OVERFLOW_MENU";
5
+ InputSource[InputSource["EXTERNAL"] = INPUT_METHOD.EXTERNAL] = "EXTERNAL";
6
6
  return InputSource;
7
7
  }({});
@@ -1,6 +1,7 @@
1
- import { bindKeymapWithCommand, findKeyMapForBrowser, isCapsLockOnAndModifyKeyboardEvent, redo, undo } from '@atlaskit/editor-common/keymaps';
1
+ import { bindKeymapWithCommand, findKeyMapForBrowser, isCapsLockOnAndModifyKeyboardEvent, redo, redoAlt, undo } from '@atlaskit/editor-common/keymaps';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
4
5
  import { redoFromKeyboard, undoFromKeyboard } from './commands';
5
6
  export function keymapPlugin() {
6
7
  var list = {};
@@ -8,6 +9,10 @@ export function keymapPlugin() {
8
9
  // Ignored via go/ees005
9
10
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
10
11
  bindKeymapWithCommand(findKeyMapForBrowser(redo), redoFromKeyboard, list);
12
+ if (fg('platform_editor_cmd_y_mac_redo_shortcut')) {
13
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
14
+ bindKeymapWithCommand(findKeyMapForBrowser(redoAlt), redoFromKeyboard, list);
15
+ }
11
16
 
12
17
  // Ignored via go/ees005
13
18
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -0,0 +1,27 @@
1
+ export var closeTypeAheadAndRunCommand = function closeTypeAheadAndRunCommand(editorView, api) {
2
+ return function (command) {
3
+ var _api$typeAhead;
4
+ if (!editorView) {
5
+ return false;
6
+ }
7
+ if (api !== null && api !== void 0 && (_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && (_api$typeAhead = _api$typeAhead.actions) !== null && _api$typeAhead !== void 0 && _api$typeAhead.isOpen(editorView.state)) {
8
+ var _api$typeAhead2;
9
+ api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 || (_api$typeAhead2 = _api$typeAhead2.actions) === null || _api$typeAhead2 === void 0 || _api$typeAhead2.close({
10
+ attachCommand: command,
11
+ insertCurrentQueryAsRawText: false
12
+ });
13
+ } else {
14
+ command(editorView.state, editorView.dispatch);
15
+ }
16
+ return true;
17
+ };
18
+ };
19
+ export var forceFocus = function forceFocus(editorView, api) {
20
+ return function (command) {
21
+ var result = closeTypeAheadAndRunCommand(editorView, api)(command);
22
+ if (result && !editorView.hasFocus()) {
23
+ editorView.focus();
24
+ }
25
+ return result;
26
+ };
27
+ };
@@ -6,7 +6,7 @@
6
6
  import { jsx } from '@emotion/react';
7
7
  import { injectIntl } from 'react-intl-next';
8
8
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
9
- import { getAriaKeyshortcuts, redo as redoKeymap, tooltip, ToolTipContent, undo as undoKeymap } from '@atlaskit/editor-common/keymaps';
9
+ import { getAriaKeyshortcuts, redo, redoAlt, tooltip, ToolTipContent, undo as undoKeymap } from '@atlaskit/editor-common/keymaps';
10
10
  import { undoRedoMessages } from '@atlaskit/editor-common/messages';
11
11
  import { buttonGroupStyle, buttonGroupStyleBeforeVisualRefresh, separatorStyles } from '@atlaskit/editor-common/styles';
12
12
  import { TOOLBAR_BUTTON, ToolbarButton } from '@atlaskit/editor-common/ui-menu';
@@ -14,31 +14,7 @@ import RedoIcon from '@atlaskit/icon/core/migration/redo';
14
14
  import UndoIcon from '@atlaskit/icon/core/migration/undo';
15
15
  import { fg } from '@atlaskit/platform-feature-flags';
16
16
  import { redoFromToolbar, undoFromToolbar } from '../../pm-plugins/commands';
17
- var closeTypeAheadAndRunCommand = function closeTypeAheadAndRunCommand(editorView, api) {
18
- return function (command) {
19
- var _api$typeAhead;
20
- if (!editorView) {
21
- return;
22
- }
23
- if (api !== null && api !== void 0 && (_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && (_api$typeAhead = _api$typeAhead.actions) !== null && _api$typeAhead !== void 0 && _api$typeAhead.isOpen(editorView.state)) {
24
- var _api$typeAhead2;
25
- api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 || (_api$typeAhead2 = _api$typeAhead2.actions) === null || _api$typeAhead2 === void 0 || _api$typeAhead2.close({
26
- attachCommand: command,
27
- insertCurrentQueryAsRawText: false
28
- });
29
- } else {
30
- command(editorView.state, editorView.dispatch);
31
- }
32
- };
33
- };
34
- var forceFocus = function forceFocus(editorView, api) {
35
- return function (command) {
36
- closeTypeAheadAndRunCommand(editorView, api)(command);
37
- if (!editorView.hasFocus()) {
38
- editorView.focus();
39
- }
40
- };
41
- };
17
+ import { forceFocus } from '../../pm-plugins/utils';
42
18
  export var ToolbarUndoRedo = function ToolbarUndoRedo(_ref) {
43
19
  var disabled = _ref.disabled,
44
20
  isReducedSpacing = _ref.isReducedSpacing,
@@ -58,6 +34,7 @@ export var ToolbarUndoRedo = function ToolbarUndoRedo(_ref) {
58
34
  var _ref2 = historyState !== null && historyState !== void 0 ? historyState : {},
59
35
  canUndo = _ref2.canUndo,
60
36
  canRedo = _ref2.canRedo;
37
+ var redoKeymap = fg('platform_editor_cmd_y_mac_redo_shortcut') ? redoAlt : redo;
61
38
  return (
62
39
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
63
40
  jsx("span", {
@@ -1,11 +1,12 @@
1
1
  import React from 'react';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import { redo as _redo, undo as _undo } from '@atlaskit/editor-prosemirror/history';
3
+ import { redo, undo } from '@atlaskit/editor-prosemirror/history';
4
4
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
5
  import { attachInputMeta } from './pm-plugins/attach-input-meta';
6
+ import { InputSource } from './pm-plugins/enums';
6
7
  import { keymapPlugin } from './pm-plugins/keymaps';
7
8
  import { createPlugin } from './pm-plugins/main';
8
- // eslint-disable-next-line @atlassian/tangerine/import/entry-points
9
+ import { forceFocus } from './pm-plugins/utils';
9
10
  // Ignored via go/ees005
10
11
  // eslint-disable-next-line import/no-named-as-default
11
12
  import ToolbarUndoRedo from './ui/ToolbarUndoRedo';
@@ -30,33 +31,23 @@ export var undoRedoPlugin = function undoRedoPlugin(_ref) {
30
31
  name: 'undoRedoPlugin',
31
32
  component: primaryToolbarComponent
32
33
  });
34
+ var handleUndo = function handleUndo(inputSource) {
35
+ if (!editorViewRef.current) {
36
+ return false;
37
+ }
38
+ return forceFocus(editorViewRef.current, api)(attachInputMeta(inputSource || InputSource.EXTERNAL)(undo));
39
+ };
40
+ var handleRedo = function handleRedo(inputSource) {
41
+ if (!editorViewRef.current) {
42
+ return false;
43
+ }
44
+ return forceFocus(editorViewRef.current, api)(attachInputMeta(inputSource || InputSource.EXTERNAL)(redo));
45
+ };
33
46
  return {
34
47
  name: 'undoRedoPlugin',
35
48
  actions: {
36
- undo: function undo(inputSource) {
37
- if (!editorViewRef.current) {
38
- return false;
39
- }
40
- var _editorViewRef$curren = editorViewRef.current,
41
- state = _editorViewRef$curren.state,
42
- dispatch = _editorViewRef$curren.dispatch;
43
- if (!inputSource) {
44
- return _undo(state, dispatch);
45
- }
46
- return attachInputMeta(inputSource)(_undo)(state, dispatch);
47
- },
48
- redo: function redo(inputSource) {
49
- if (!editorViewRef.current) {
50
- return false;
51
- }
52
- var _editorViewRef$curren2 = editorViewRef.current,
53
- state = _editorViewRef$curren2.state,
54
- dispatch = _editorViewRef$curren2.dispatch;
55
- if (!inputSource) {
56
- return _redo(state, dispatch);
57
- }
58
- return attachInputMeta(inputSource)(_redo)(state, dispatch);
59
- }
49
+ undo: handleUndo,
50
+ redo: handleRedo
60
51
  },
61
52
  pmPlugins: function pmPlugins() {
62
53
  var plugins = [{
@@ -1,5 +1,5 @@
1
1
  export declare enum InputSource {
2
2
  TOOLBAR = "toolbar",
3
3
  KEYBOARD = "keyboard",
4
- PAGE_OVERFLOW_MENU = "confluencePageOverflowMenu"
4
+ EXTERNAL = "external"
5
5
  }
@@ -0,0 +1,5 @@
1
+ import type { Command, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
+ import { UndoRedoPlugin } from '../undoRedoPluginType';
4
+ export declare const closeTypeAheadAndRunCommand: (editorView: EditorView, api: ExtractInjectionAPI<UndoRedoPlugin> | undefined) => (command: Command) => boolean;
5
+ export declare const forceFocus: (editorView: EditorView, api: ExtractInjectionAPI<UndoRedoPlugin> | undefined) => (command: Command) => boolean;
@@ -1,5 +1,5 @@
1
1
  export declare enum InputSource {
2
2
  TOOLBAR = "toolbar",
3
3
  KEYBOARD = "keyboard",
4
- PAGE_OVERFLOW_MENU = "confluencePageOverflowMenu"
4
+ EXTERNAL = "external"
5
5
  }
@@ -0,0 +1,5 @@
1
+ import type { Command, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
+ import { UndoRedoPlugin } from '../undoRedoPluginType';
4
+ export declare const closeTypeAheadAndRunCommand: (editorView: EditorView, api: ExtractInjectionAPI<UndoRedoPlugin> | undefined) => (command: Command) => boolean;
5
+ export declare const forceFocus: (editorView: EditorView, api: ExtractInjectionAPI<UndoRedoPlugin> | undefined) => (command: Command) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-undo-redo",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
4
4
  "description": "Undo redo plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,14 +33,14 @@
33
33
  ".": "./src/index.ts"
34
34
  },
35
35
  "dependencies": {
36
- "@atlaskit/editor-common": "^102.12.0",
36
+ "@atlaskit/editor-common": "^103.0.0",
37
37
  "@atlaskit/editor-plugin-history": "^2.0.0",
38
38
  "@atlaskit/editor-plugin-primary-toolbar": "^3.1.0",
39
- "@atlaskit/editor-plugin-type-ahead": "^2.1.0",
39
+ "@atlaskit/editor-plugin-type-ahead": "^2.3.0",
40
40
  "@atlaskit/editor-prosemirror": "7.0.0",
41
- "@atlaskit/icon": "^25.0.0",
41
+ "@atlaskit/icon": "^25.5.0",
42
42
  "@atlaskit/platform-feature-flags": "^1.1.0",
43
- "@atlaskit/tmp-editor-statsig": "^4.1.0",
43
+ "@atlaskit/tmp-editor-statsig": "^4.6.0",
44
44
  "@babel/runtime": "^7.0.0",
45
45
  "@emotion/react": "^11.7.1"
46
46
  },
@@ -91,5 +91,10 @@
91
91
  "no-unused-dependencies": {
92
92
  "checkDevDependencies": true
93
93
  }
94
+ },
95
+ "platform-feature-flags": {
96
+ "platform_editor_cmd_y_mac_redo_shortcut": {
97
+ "type": "boolean"
98
+ }
94
99
  }
95
100
  }