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

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,23 @@
1
1
  # @atlaskit/editor-plugin-undo-redo
2
2
 
3
+ ## 2.0.11
4
+
5
+ ### Patch Changes
6
+
7
+ - [#149778](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/149778)
8
+ [`de5587be5f109`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/de5587be5f109) -
9
+ Added undo/redo via shortcut analytics
10
+ - Updated dependencies
11
+
12
+ ## 2.0.10
13
+
14
+ ### Patch Changes
15
+
16
+ - [#149192](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/149192)
17
+ [`7dd3315f8b3a2`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7dd3315f8b3a2) -
18
+ Added undo/redo analytics
19
+ - Updated dependencies
20
+
3
21
  ## 2.0.9
4
22
 
5
23
  ### Patch Changes
@@ -3,7 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.attachInputMeta = void 0;
6
+ exports.attachInputMetaWithAnalytics = exports.attachInputMeta = void 0;
7
+ var _analytics = require("@atlaskit/editor-common/analytics");
8
+ var _editorAnalytics = require("@atlaskit/editor-common/editor-analytics");
9
+ var _enums = require("./enums");
7
10
  var _pluginKey = require("./plugin-key");
8
11
  var attachInputMeta = exports.attachInputMeta = function attachInputMeta(inputSource) {
9
12
  return function (command) {
@@ -23,4 +26,30 @@ var attachInputMeta = exports.attachInputMeta = function attachInputMeta(inputSo
23
26
  return true;
24
27
  };
25
28
  };
29
+ };
30
+ var inputSourceToInputMethod = function inputSourceToInputMethod(inputSource) {
31
+ switch (inputSource) {
32
+ case _enums.InputSource.EXTERNAL:
33
+ return _analytics.INPUT_METHOD.EXTERNAL;
34
+ case _enums.InputSource.KEYBOARD:
35
+ return _analytics.INPUT_METHOD.KEYBOARD;
36
+ case _enums.InputSource.TOOLBAR:
37
+ return _analytics.INPUT_METHOD.TOOLBAR;
38
+ default:
39
+ return _analytics.INPUT_METHOD.EXTERNAL;
40
+ }
41
+ };
42
+ var attachInputMetaWithAnalytics = exports.attachInputMetaWithAnalytics = function attachInputMetaWithAnalytics(editorAnalyticsAPI) {
43
+ return function (inputSource, action) {
44
+ return function (command) {
45
+ return attachInputMeta(inputSource)((0, _editorAnalytics.withAnalytics)(editorAnalyticsAPI, {
46
+ eventType: _analytics.EVENT_TYPE.TRACK,
47
+ action: action,
48
+ actionSubject: _analytics.ACTION_SUBJECT.EDITOR,
49
+ attributes: {
50
+ inputMethod: inputSourceToInputMethod(inputSource)
51
+ }
52
+ })(command));
53
+ };
54
+ };
26
55
  };
@@ -3,11 +3,24 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.undoFromToolbar = exports.undoFromKeyboard = exports.redoFromToolbar = exports.redoFromKeyboard = void 0;
6
+ exports.undoFromToolbarWithAnalytics = exports.undoFromToolbar = exports.undoFromKeyboardWithAnalytics = exports.undoFromKeyboard = exports.redoFromToolbarWithAnalytics = exports.redoFromToolbar = exports.redoFromKeyboardWithAnalytics = exports.redoFromKeyboard = void 0;
7
+ var _analytics = require("@atlaskit/editor-common/analytics");
7
8
  var _history = require("@atlaskit/editor-prosemirror/history");
8
9
  var _attachInputMeta = require("./attach-input-meta");
9
10
  var _enums = require("./enums");
10
11
  var undoFromKeyboard = exports.undoFromKeyboard = (0, _attachInputMeta.attachInputMeta)(_enums.InputSource.KEYBOARD)(_history.undo);
11
12
  var redoFromKeyboard = exports.redoFromKeyboard = (0, _attachInputMeta.attachInputMeta)(_enums.InputSource.KEYBOARD)(_history.redo);
12
13
  var undoFromToolbar = exports.undoFromToolbar = (0, _attachInputMeta.attachInputMeta)(_enums.InputSource.TOOLBAR)(_history.undo);
13
- var redoFromToolbar = exports.redoFromToolbar = (0, _attachInputMeta.attachInputMeta)(_enums.InputSource.TOOLBAR)(_history.redo);
14
+ var redoFromToolbar = exports.redoFromToolbar = (0, _attachInputMeta.attachInputMeta)(_enums.InputSource.TOOLBAR)(_history.redo);
15
+ var undoFromKeyboardWithAnalytics = exports.undoFromKeyboardWithAnalytics = function undoFromKeyboardWithAnalytics(editorAnalyticsAPI) {
16
+ return (0, _attachInputMeta.attachInputMetaWithAnalytics)(editorAnalyticsAPI)(_enums.InputSource.KEYBOARD, _analytics.ACTION.UNDO_PERFORMED)(_history.undo);
17
+ };
18
+ var redoFromKeyboardWithAnalytics = exports.redoFromKeyboardWithAnalytics = function redoFromKeyboardWithAnalytics(editorAnalyticsAPI) {
19
+ return (0, _attachInputMeta.attachInputMetaWithAnalytics)(editorAnalyticsAPI)(_enums.InputSource.KEYBOARD, _analytics.ACTION.REDO_PERFORMED)(_history.redo);
20
+ };
21
+ var undoFromToolbarWithAnalytics = exports.undoFromToolbarWithAnalytics = function undoFromToolbarWithAnalytics(editorAnalyticsAPI) {
22
+ return (0, _attachInputMeta.attachInputMetaWithAnalytics)(editorAnalyticsAPI)(_enums.InputSource.TOOLBAR, _analytics.ACTION.UNDO_PERFORMED)(_history.undo);
23
+ };
24
+ var redoFromToolbarWithAnalytics = exports.redoFromToolbarWithAnalytics = function redoFromToolbarWithAnalytics(editorAnalyticsAPI) {
25
+ return (0, _attachInputMeta.attachInputMetaWithAnalytics)(editorAnalyticsAPI)(_enums.InputSource.TOOLBAR, _analytics.ACTION.REDO_PERFORMED)(_history.redo);
26
+ };
@@ -9,20 +9,23 @@ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
9
9
  var _keymap = require("@atlaskit/editor-prosemirror/keymap");
10
10
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
11
  var _commands = require("./commands");
12
- function keymapPlugin() {
12
+ function keymapPlugin(api) {
13
+ var _api$analytics, _api$analytics3;
13
14
  var list = {};
14
-
15
+ (0, _keymaps.bindKeymapWithCommand)(
15
16
  // Ignored via go/ees005
16
17
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17
- (0, _keymaps.bindKeymapWithCommand)((0, _keymaps.findKeyMapForBrowser)(_keymaps.redo), _commands.redoFromKeyboard, list);
18
+ (0, _keymaps.findKeyMapForBrowser)(_keymaps.redo), (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_analytics') ? (0, _commands.redoFromKeyboardWithAnalytics)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions) : _commands.redoFromKeyboard, list);
18
19
  if ((0, _platformFeatureFlags.fg)('platform_editor_cmd_y_mac_redo_shortcut')) {
20
+ var _api$analytics2;
21
+ (0, _keymaps.bindKeymapWithCommand)(
19
22
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20
- (0, _keymaps.bindKeymapWithCommand)((0, _keymaps.findKeyMapForBrowser)(_keymaps.redoAlt), _commands.redoFromKeyboard, list);
23
+ (0, _keymaps.findKeyMapForBrowser)(_keymaps.redoAlt), (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_analytics') ? (0, _commands.redoFromKeyboardWithAnalytics)(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions) : _commands.redoFromKeyboard, list);
21
24
  }
22
-
25
+ (0, _keymaps.bindKeymapWithCommand)(
23
26
  // Ignored via go/ees005
24
27
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
25
- (0, _keymaps.bindKeymapWithCommand)(_keymaps.undo.common, _commands.undoFromKeyboard, list);
28
+ _keymaps.undo.common, (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_analytics') ? (0, _commands.undoFromKeyboardWithAnalytics)(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions) : _commands.undoFromKeyboard, list);
26
29
  return new _safePlugin.SafePlugin({
27
30
  props: {
28
31
  handleKeyDown: function handleKeyDown(view, event) {
@@ -32,10 +32,20 @@ var ToolbarUndoRedo = exports.ToolbarUndoRedo = function ToolbarUndoRedo(_ref) {
32
32
  var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['history']),
33
33
  historyState = _useSharedPluginState.historyState;
34
34
  var handleUndo = function handleUndo() {
35
- (0, _utils.forceFocus)(editorView, api)(_commands.undoFromToolbar);
35
+ if ((0, _platformFeatureFlags.fg)('platform_editor_controls_patch_analytics')) {
36
+ var _api$analytics;
37
+ (0, _utils.forceFocus)(editorView, api)((0, _commands.undoFromToolbarWithAnalytics)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions));
38
+ } else {
39
+ (0, _utils.forceFocus)(editorView, api)(_commands.undoFromToolbar);
40
+ }
36
41
  };
37
42
  var handleRedo = function handleRedo() {
38
- (0, _utils.forceFocus)(editorView, api)(_commands.redoFromToolbar);
43
+ if ((0, _platformFeatureFlags.fg)('platform_editor_controls_patch_analytics')) {
44
+ var _api$analytics2;
45
+ (0, _utils.forceFocus)(editorView, api)((0, _commands.redoFromToolbarWithAnalytics)(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions));
46
+ } else {
47
+ (0, _utils.forceFocus)(editorView, api)(_commands.redoFromToolbar);
48
+ }
39
49
  };
40
50
  var labelUndo = formatMessage(_messages.undoRedoMessages.undo);
41
51
  var labelRedo = formatMessage(_messages.undoRedoMessages.redo);
@@ -6,8 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.undoRedoPlugin = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
+ var _analytics = require("@atlaskit/editor-common/analytics");
9
10
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
11
  var _history = require("@atlaskit/editor-prosemirror/history");
12
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
13
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
12
14
  var _attachInputMeta = require("./pm-plugins/attach-input-meta");
13
15
  var _enums = require("./pm-plugins/enums");
@@ -40,16 +42,18 @@ var undoRedoPlugin = exports.undoRedoPlugin = function undoRedoPlugin(_ref) {
40
42
  component: primaryToolbarComponent
41
43
  });
42
44
  var handleUndo = function handleUndo(inputSource) {
45
+ var _api$analytics;
43
46
  if (!editorViewRef.current) {
44
47
  return false;
45
48
  }
46
- return (0, _utils.forceFocus)(editorViewRef.current, api)((0, _attachInputMeta.attachInputMeta)(inputSource || _enums.InputSource.EXTERNAL)(_history.undo));
49
+ return (0, _utils.forceFocus)(editorViewRef.current, api)((0, _platformFeatureFlags.fg)('platform_editor_controls_patch_analytics') ? (0, _attachInputMeta.attachInputMetaWithAnalytics)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(inputSource || _enums.InputSource.EXTERNAL, _analytics.ACTION.UNDO_PERFORMED)(_history.undo) : (0, _attachInputMeta.attachInputMeta)(inputSource || _enums.InputSource.EXTERNAL)(_history.undo));
47
50
  };
48
51
  var handleRedo = function handleRedo(inputSource) {
52
+ var _api$analytics2;
49
53
  if (!editorViewRef.current) {
50
54
  return false;
51
55
  }
52
- return (0, _utils.forceFocus)(editorViewRef.current, api)((0, _attachInputMeta.attachInputMeta)(inputSource || _enums.InputSource.EXTERNAL)(_history.redo));
56
+ return (0, _utils.forceFocus)(editorViewRef.current, api)((0, _platformFeatureFlags.fg)('platform_editor_controls_patch_analytics') ? (0, _attachInputMeta.attachInputMetaWithAnalytics)(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(inputSource || _enums.InputSource.EXTERNAL, _analytics.ACTION.REDO_PERFORMED)(_history.redo) : (0, _attachInputMeta.attachInputMeta)(inputSource || _enums.InputSource.EXTERNAL)(_history.redo));
53
57
  };
54
58
  return {
55
59
  name: 'undoRedoPlugin',
@@ -61,7 +65,7 @@ var undoRedoPlugin = exports.undoRedoPlugin = function undoRedoPlugin(_ref) {
61
65
  var plugins = [{
62
66
  name: 'undoRedoKeyMap',
63
67
  plugin: function plugin() {
64
- return (0, _keymaps.keymapPlugin)();
68
+ return (0, _keymaps.keymapPlugin)(api);
65
69
  }
66
70
  }, {
67
71
  name: 'undoRedoPlugin',
@@ -1,3 +1,6 @@
1
+ import { ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
3
+ import { InputSource } from './enums';
1
4
  import { pluginKey as undoPluginKey } from './plugin-key';
2
5
  export const attachInputMeta = inputSource => command => (state, dispatch) => {
3
6
  let customTr = state.tr;
@@ -13,4 +16,24 @@ export const attachInputMeta = inputSource => command => (state, dispatch) => {
13
16
  dispatch(customTr);
14
17
  }
15
18
  return true;
16
- };
19
+ };
20
+ const inputSourceToInputMethod = inputSource => {
21
+ switch (inputSource) {
22
+ case InputSource.EXTERNAL:
23
+ return INPUT_METHOD.EXTERNAL;
24
+ case InputSource.KEYBOARD:
25
+ return INPUT_METHOD.KEYBOARD;
26
+ case InputSource.TOOLBAR:
27
+ return INPUT_METHOD.TOOLBAR;
28
+ default:
29
+ return INPUT_METHOD.EXTERNAL;
30
+ }
31
+ };
32
+ export const attachInputMetaWithAnalytics = editorAnalyticsAPI => (inputSource, action) => command => attachInputMeta(inputSource)(withAnalytics(editorAnalyticsAPI, {
33
+ eventType: EVENT_TYPE.TRACK,
34
+ action,
35
+ actionSubject: ACTION_SUBJECT.EDITOR,
36
+ attributes: {
37
+ inputMethod: inputSourceToInputMethod(inputSource)
38
+ }
39
+ })(command));
@@ -1,7 +1,12 @@
1
+ import { ACTION } from '@atlaskit/editor-common/analytics';
1
2
  import { redo, undo } from '@atlaskit/editor-prosemirror/history';
2
- import { attachInputMeta } from './attach-input-meta';
3
+ import { attachInputMeta, attachInputMetaWithAnalytics } from './attach-input-meta';
3
4
  import { InputSource } from './enums';
4
5
  export const undoFromKeyboard = attachInputMeta(InputSource.KEYBOARD)(undo);
5
6
  export const redoFromKeyboard = attachInputMeta(InputSource.KEYBOARD)(redo);
6
7
  export const undoFromToolbar = attachInputMeta(InputSource.TOOLBAR)(undo);
7
- export const redoFromToolbar = attachInputMeta(InputSource.TOOLBAR)(redo);
8
+ export const redoFromToolbar = attachInputMeta(InputSource.TOOLBAR)(redo);
9
+ export const undoFromKeyboardWithAnalytics = editorAnalyticsAPI => attachInputMetaWithAnalytics(editorAnalyticsAPI)(InputSource.KEYBOARD, ACTION.UNDO_PERFORMED)(undo);
10
+ export const redoFromKeyboardWithAnalytics = editorAnalyticsAPI => attachInputMetaWithAnalytics(editorAnalyticsAPI)(InputSource.KEYBOARD, ACTION.REDO_PERFORMED)(redo);
11
+ export const undoFromToolbarWithAnalytics = editorAnalyticsAPI => attachInputMetaWithAnalytics(editorAnalyticsAPI)(InputSource.TOOLBAR, ACTION.UNDO_PERFORMED)(undo);
12
+ export const redoFromToolbarWithAnalytics = editorAnalyticsAPI => attachInputMetaWithAnalytics(editorAnalyticsAPI)(InputSource.TOOLBAR, ACTION.REDO_PERFORMED)(redo);
@@ -2,21 +2,24 @@ import { bindKeymapWithCommand, findKeyMapForBrowser, isCapsLockOnAndModifyKeybo
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
4
4
  import { fg } from '@atlaskit/platform-feature-flags';
5
- import { redoFromKeyboard, undoFromKeyboard } from './commands';
6
- export function keymapPlugin() {
5
+ import { redoFromKeyboard, redoFromKeyboardWithAnalytics, undoFromKeyboard, undoFromKeyboardWithAnalytics } from './commands';
6
+ export function keymapPlugin(api) {
7
+ var _api$analytics, _api$analytics3;
7
8
  const list = {};
8
-
9
+ bindKeymapWithCommand(
9
10
  // Ignored via go/ees005
10
11
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
11
- bindKeymapWithCommand(findKeyMapForBrowser(redo), redoFromKeyboard, list);
12
+ findKeyMapForBrowser(redo), fg('platform_editor_controls_patch_analytics') ? redoFromKeyboardWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions) : redoFromKeyboard, list);
12
13
  if (fg('platform_editor_cmd_y_mac_redo_shortcut')) {
14
+ var _api$analytics2;
15
+ bindKeymapWithCommand(
13
16
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
14
- bindKeymapWithCommand(findKeyMapForBrowser(redoAlt), redoFromKeyboard, list);
17
+ findKeyMapForBrowser(redoAlt), fg('platform_editor_controls_patch_analytics') ? redoFromKeyboardWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions) : redoFromKeyboard, list);
15
18
  }
16
-
19
+ bindKeymapWithCommand(
17
20
  // Ignored via go/ees005
18
21
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
19
- bindKeymapWithCommand(undo.common, undoFromKeyboard, list);
22
+ undo.common, fg('platform_editor_controls_patch_analytics') ? undoFromKeyboardWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions) : undoFromKeyboard, list);
20
23
  return new SafePlugin({
21
24
  props: {
22
25
  handleKeyDown(view, event) {
@@ -13,7 +13,7 @@ import { TOOLBAR_BUTTON, ToolbarButton } from '@atlaskit/editor-common/ui-menu';
13
13
  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
- import { redoFromToolbar, undoFromToolbar } from '../../pm-plugins/commands';
16
+ import { redoFromToolbar, redoFromToolbarWithAnalytics, undoFromToolbar, undoFromToolbarWithAnalytics } from '../../pm-plugins/commands';
17
17
  import { forceFocus } from '../../pm-plugins/utils';
18
18
  export const ToolbarUndoRedo = ({
19
19
  disabled,
@@ -28,10 +28,20 @@ export const ToolbarUndoRedo = ({
28
28
  historyState
29
29
  } = useSharedPluginState(api, ['history']);
30
30
  const handleUndo = () => {
31
- forceFocus(editorView, api)(undoFromToolbar);
31
+ if (fg('platform_editor_controls_patch_analytics')) {
32
+ var _api$analytics;
33
+ forceFocus(editorView, api)(undoFromToolbarWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions));
34
+ } else {
35
+ forceFocus(editorView, api)(undoFromToolbar);
36
+ }
32
37
  };
33
38
  const handleRedo = () => {
34
- forceFocus(editorView, api)(redoFromToolbar);
39
+ if (fg('platform_editor_controls_patch_analytics')) {
40
+ var _api$analytics2;
41
+ forceFocus(editorView, api)(redoFromToolbarWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions));
42
+ } else {
43
+ forceFocus(editorView, api)(redoFromToolbar);
44
+ }
35
45
  };
36
46
  const labelUndo = formatMessage(undoRedoMessages.undo);
37
47
  const labelRedo = formatMessage(undoRedoMessages.redo);
@@ -1,8 +1,10 @@
1
1
  import React from 'react';
2
+ import { ACTION } from '@atlaskit/editor-common/analytics';
2
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
4
  import { redo, undo } from '@atlaskit/editor-prosemirror/history';
5
+ import { fg } from '@atlaskit/platform-feature-flags';
4
6
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
- import { attachInputMeta } from './pm-plugins/attach-input-meta';
7
+ import { attachInputMeta, attachInputMetaWithAnalytics } from './pm-plugins/attach-input-meta';
6
8
  import { InputSource } from './pm-plugins/enums';
7
9
  import { keymapPlugin } from './pm-plugins/keymaps';
8
10
  import { createPlugin } from './pm-plugins/main';
@@ -34,16 +36,18 @@ export const undoRedoPlugin = ({
34
36
  component: primaryToolbarComponent
35
37
  });
36
38
  const handleUndo = inputSource => {
39
+ var _api$analytics;
37
40
  if (!editorViewRef.current) {
38
41
  return false;
39
42
  }
40
- return forceFocus(editorViewRef.current, api)(attachInputMeta(inputSource || InputSource.EXTERNAL)(undo));
43
+ return forceFocus(editorViewRef.current, api)(fg('platform_editor_controls_patch_analytics') ? attachInputMetaWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(inputSource || InputSource.EXTERNAL, ACTION.UNDO_PERFORMED)(undo) : attachInputMeta(inputSource || InputSource.EXTERNAL)(undo));
41
44
  };
42
45
  const handleRedo = inputSource => {
46
+ var _api$analytics2;
43
47
  if (!editorViewRef.current) {
44
48
  return false;
45
49
  }
46
- return forceFocus(editorViewRef.current, api)(attachInputMeta(inputSource || InputSource.EXTERNAL)(redo));
50
+ return forceFocus(editorViewRef.current, api)(fg('platform_editor_controls_patch_analytics') ? attachInputMetaWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(inputSource || InputSource.EXTERNAL, ACTION.REDO_PERFORMED)(redo) : attachInputMeta(inputSource || InputSource.EXTERNAL)(redo));
47
51
  };
48
52
  return {
49
53
  name: 'undoRedoPlugin',
@@ -54,7 +58,7 @@ export const undoRedoPlugin = ({
54
58
  pmPlugins() {
55
59
  const plugins = [{
56
60
  name: 'undoRedoKeyMap',
57
- plugin: () => keymapPlugin()
61
+ plugin: () => keymapPlugin(api)
58
62
  }, {
59
63
  name: 'undoRedoPlugin',
60
64
  plugin: options => createPlugin(options)
@@ -1,3 +1,6 @@
1
+ import { ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
3
+ import { InputSource } from './enums';
1
4
  import { pluginKey as undoPluginKey } from './plugin-key';
2
5
  export var attachInputMeta = function attachInputMeta(inputSource) {
3
6
  return function (command) {
@@ -17,4 +20,30 @@ export var attachInputMeta = function attachInputMeta(inputSource) {
17
20
  return true;
18
21
  };
19
22
  };
23
+ };
24
+ var inputSourceToInputMethod = function inputSourceToInputMethod(inputSource) {
25
+ switch (inputSource) {
26
+ case InputSource.EXTERNAL:
27
+ return INPUT_METHOD.EXTERNAL;
28
+ case InputSource.KEYBOARD:
29
+ return INPUT_METHOD.KEYBOARD;
30
+ case InputSource.TOOLBAR:
31
+ return INPUT_METHOD.TOOLBAR;
32
+ default:
33
+ return INPUT_METHOD.EXTERNAL;
34
+ }
35
+ };
36
+ export var attachInputMetaWithAnalytics = function attachInputMetaWithAnalytics(editorAnalyticsAPI) {
37
+ return function (inputSource, action) {
38
+ return function (command) {
39
+ return attachInputMeta(inputSource)(withAnalytics(editorAnalyticsAPI, {
40
+ eventType: EVENT_TYPE.TRACK,
41
+ action: action,
42
+ actionSubject: ACTION_SUBJECT.EDITOR,
43
+ attributes: {
44
+ inputMethod: inputSourceToInputMethod(inputSource)
45
+ }
46
+ })(command));
47
+ };
48
+ };
20
49
  };
@@ -1,7 +1,20 @@
1
+ import { ACTION } from '@atlaskit/editor-common/analytics';
1
2
  import { redo, undo } from '@atlaskit/editor-prosemirror/history';
2
- import { attachInputMeta } from './attach-input-meta';
3
+ import { attachInputMeta, attachInputMetaWithAnalytics } from './attach-input-meta';
3
4
  import { InputSource } from './enums';
4
5
  export var undoFromKeyboard = attachInputMeta(InputSource.KEYBOARD)(undo);
5
6
  export var redoFromKeyboard = attachInputMeta(InputSource.KEYBOARD)(redo);
6
7
  export var undoFromToolbar = attachInputMeta(InputSource.TOOLBAR)(undo);
7
- export var redoFromToolbar = attachInputMeta(InputSource.TOOLBAR)(redo);
8
+ export var redoFromToolbar = attachInputMeta(InputSource.TOOLBAR)(redo);
9
+ export var undoFromKeyboardWithAnalytics = function undoFromKeyboardWithAnalytics(editorAnalyticsAPI) {
10
+ return attachInputMetaWithAnalytics(editorAnalyticsAPI)(InputSource.KEYBOARD, ACTION.UNDO_PERFORMED)(undo);
11
+ };
12
+ export var redoFromKeyboardWithAnalytics = function redoFromKeyboardWithAnalytics(editorAnalyticsAPI) {
13
+ return attachInputMetaWithAnalytics(editorAnalyticsAPI)(InputSource.KEYBOARD, ACTION.REDO_PERFORMED)(redo);
14
+ };
15
+ export var undoFromToolbarWithAnalytics = function undoFromToolbarWithAnalytics(editorAnalyticsAPI) {
16
+ return attachInputMetaWithAnalytics(editorAnalyticsAPI)(InputSource.TOOLBAR, ACTION.UNDO_PERFORMED)(undo);
17
+ };
18
+ export var redoFromToolbarWithAnalytics = function redoFromToolbarWithAnalytics(editorAnalyticsAPI) {
19
+ return attachInputMetaWithAnalytics(editorAnalyticsAPI)(InputSource.TOOLBAR, ACTION.REDO_PERFORMED)(redo);
20
+ };
@@ -2,21 +2,24 @@ import { bindKeymapWithCommand, findKeyMapForBrowser, isCapsLockOnAndModifyKeybo
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
4
4
  import { fg } from '@atlaskit/platform-feature-flags';
5
- import { redoFromKeyboard, undoFromKeyboard } from './commands';
6
- export function keymapPlugin() {
5
+ import { redoFromKeyboard, redoFromKeyboardWithAnalytics, undoFromKeyboard, undoFromKeyboardWithAnalytics } from './commands';
6
+ export function keymapPlugin(api) {
7
+ var _api$analytics, _api$analytics3;
7
8
  var list = {};
8
-
9
+ bindKeymapWithCommand(
9
10
  // Ignored via go/ees005
10
11
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
11
- bindKeymapWithCommand(findKeyMapForBrowser(redo), redoFromKeyboard, list);
12
+ findKeyMapForBrowser(redo), fg('platform_editor_controls_patch_analytics') ? redoFromKeyboardWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions) : redoFromKeyboard, list);
12
13
  if (fg('platform_editor_cmd_y_mac_redo_shortcut')) {
14
+ var _api$analytics2;
15
+ bindKeymapWithCommand(
13
16
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
14
- bindKeymapWithCommand(findKeyMapForBrowser(redoAlt), redoFromKeyboard, list);
17
+ findKeyMapForBrowser(redoAlt), fg('platform_editor_controls_patch_analytics') ? redoFromKeyboardWithAnalytics(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions) : redoFromKeyboard, list);
15
18
  }
16
-
19
+ bindKeymapWithCommand(
17
20
  // Ignored via go/ees005
18
21
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
19
- bindKeymapWithCommand(undo.common, undoFromKeyboard, list);
22
+ undo.common, fg('platform_editor_controls_patch_analytics') ? undoFromKeyboardWithAnalytics(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions) : undoFromKeyboard, list);
20
23
  return new SafePlugin({
21
24
  props: {
22
25
  handleKeyDown: function handleKeyDown(view, event) {
@@ -13,7 +13,7 @@ import { TOOLBAR_BUTTON, ToolbarButton } from '@atlaskit/editor-common/ui-menu';
13
13
  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
- import { redoFromToolbar, undoFromToolbar } from '../../pm-plugins/commands';
16
+ import { redoFromToolbar, redoFromToolbarWithAnalytics, undoFromToolbar, undoFromToolbarWithAnalytics } from '../../pm-plugins/commands';
17
17
  import { forceFocus } from '../../pm-plugins/utils';
18
18
  export var ToolbarUndoRedo = function ToolbarUndoRedo(_ref) {
19
19
  var disabled = _ref.disabled,
@@ -24,10 +24,20 @@ export var ToolbarUndoRedo = function ToolbarUndoRedo(_ref) {
24
24
  var _useSharedPluginState = useSharedPluginState(api, ['history']),
25
25
  historyState = _useSharedPluginState.historyState;
26
26
  var handleUndo = function handleUndo() {
27
- forceFocus(editorView, api)(undoFromToolbar);
27
+ if (fg('platform_editor_controls_patch_analytics')) {
28
+ var _api$analytics;
29
+ forceFocus(editorView, api)(undoFromToolbarWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions));
30
+ } else {
31
+ forceFocus(editorView, api)(undoFromToolbar);
32
+ }
28
33
  };
29
34
  var handleRedo = function handleRedo() {
30
- forceFocus(editorView, api)(redoFromToolbar);
35
+ if (fg('platform_editor_controls_patch_analytics')) {
36
+ var _api$analytics2;
37
+ forceFocus(editorView, api)(redoFromToolbarWithAnalytics(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions));
38
+ } else {
39
+ forceFocus(editorView, api)(redoFromToolbar);
40
+ }
31
41
  };
32
42
  var labelUndo = formatMessage(undoRedoMessages.undo);
33
43
  var labelRedo = formatMessage(undoRedoMessages.redo);
@@ -1,8 +1,10 @@
1
1
  import React from 'react';
2
+ import { ACTION } from '@atlaskit/editor-common/analytics';
2
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
4
  import { redo, undo } from '@atlaskit/editor-prosemirror/history';
5
+ import { fg } from '@atlaskit/platform-feature-flags';
4
6
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
- import { attachInputMeta } from './pm-plugins/attach-input-meta';
7
+ import { attachInputMeta, attachInputMetaWithAnalytics } from './pm-plugins/attach-input-meta';
6
8
  import { InputSource } from './pm-plugins/enums';
7
9
  import { keymapPlugin } from './pm-plugins/keymaps';
8
10
  import { createPlugin } from './pm-plugins/main';
@@ -32,16 +34,18 @@ export var undoRedoPlugin = function undoRedoPlugin(_ref) {
32
34
  component: primaryToolbarComponent
33
35
  });
34
36
  var handleUndo = function handleUndo(inputSource) {
37
+ var _api$analytics;
35
38
  if (!editorViewRef.current) {
36
39
  return false;
37
40
  }
38
- return forceFocus(editorViewRef.current, api)(attachInputMeta(inputSource || InputSource.EXTERNAL)(undo));
41
+ return forceFocus(editorViewRef.current, api)(fg('platform_editor_controls_patch_analytics') ? attachInputMetaWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(inputSource || InputSource.EXTERNAL, ACTION.UNDO_PERFORMED)(undo) : attachInputMeta(inputSource || InputSource.EXTERNAL)(undo));
39
42
  };
40
43
  var handleRedo = function handleRedo(inputSource) {
44
+ var _api$analytics2;
41
45
  if (!editorViewRef.current) {
42
46
  return false;
43
47
  }
44
- return forceFocus(editorViewRef.current, api)(attachInputMeta(inputSource || InputSource.EXTERNAL)(redo));
48
+ return forceFocus(editorViewRef.current, api)(fg('platform_editor_controls_patch_analytics') ? attachInputMetaWithAnalytics(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(inputSource || InputSource.EXTERNAL, ACTION.REDO_PERFORMED)(redo) : attachInputMeta(inputSource || InputSource.EXTERNAL)(redo));
45
49
  };
46
50
  return {
47
51
  name: 'undoRedoPlugin',
@@ -53,7 +57,7 @@ export var undoRedoPlugin = function undoRedoPlugin(_ref) {
53
57
  var plugins = [{
54
58
  name: 'undoRedoKeyMap',
55
59
  plugin: function plugin() {
56
- return keymapPlugin();
60
+ return keymapPlugin(api);
57
61
  }
58
62
  }, {
59
63
  name: 'undoRedoPlugin',
@@ -1,5 +1,8 @@
1
- import type { HigherOrderCommand } from '@atlaskit/editor-common/types';
2
- import type { InputSource } from './enums';
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import { ACTION } from '@atlaskit/editor-common/analytics';
3
+ import type { HigherOrderCommand, Command } from '@atlaskit/editor-common/types';
4
+ import { InputSource } from './enums';
3
5
  type AttachInputMeta = (inputSource: InputSource) => HigherOrderCommand;
4
6
  export declare const attachInputMeta: AttachInputMeta;
7
+ export declare const attachInputMetaWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputSource: InputSource, action: ACTION.UNDO_PERFORMED | ACTION.REDO_PERFORMED) => (command: Command) => Command;
5
8
  export {};
@@ -1,4 +1,9 @@
1
+ import { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
1
2
  export declare const undoFromKeyboard: import("@atlaskit/editor-common/types").Command;
2
3
  export declare const redoFromKeyboard: import("@atlaskit/editor-common/types").Command;
3
4
  export declare const undoFromToolbar: import("@atlaskit/editor-common/types").Command;
4
5
  export declare const redoFromToolbar: import("@atlaskit/editor-common/types").Command;
6
+ export declare const undoFromKeyboardWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => import("@atlaskit/editor-common/types").Command;
7
+ export declare const redoFromKeyboardWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => import("@atlaskit/editor-common/types").Command;
8
+ export declare const undoFromToolbarWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => import("@atlaskit/editor-common/types").Command;
9
+ export declare const redoFromToolbarWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => import("@atlaskit/editor-common/types").Command;
@@ -1,2 +1,4 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- export declare function keymapPlugin(): SafePlugin;
2
+ import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import { UndoRedoPlugin } from '../undoRedoPluginType';
4
+ export declare function keymapPlugin(api?: ExtractInjectionAPI<UndoRedoPlugin>): SafePlugin;
@@ -1,11 +1,17 @@
1
1
  import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
2
3
  import type { HistoryPlugin } from '@atlaskit/editor-plugin-history';
3
4
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
4
5
  import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
5
6
  import { InputSource } from './pm-plugins/enums';
6
7
  export type UndoRedoAction = (inputSource?: InputSource) => boolean;
7
8
  export type UndoRedoPlugin = NextEditorPlugin<'undoRedoPlugin', {
8
- dependencies: [TypeAheadPlugin, HistoryPlugin, OptionalPlugin<PrimaryToolbarPlugin>];
9
+ dependencies: [
10
+ TypeAheadPlugin,
11
+ HistoryPlugin,
12
+ OptionalPlugin<PrimaryToolbarPlugin>,
13
+ OptionalPlugin<AnalyticsPlugin>
14
+ ];
9
15
  actions: {
10
16
  undo: UndoRedoAction;
11
17
  redo: UndoRedoAction;
@@ -1,5 +1,8 @@
1
- import type { HigherOrderCommand } from '@atlaskit/editor-common/types';
2
- import type { InputSource } from './enums';
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import { ACTION } from '@atlaskit/editor-common/analytics';
3
+ import type { HigherOrderCommand, Command } from '@atlaskit/editor-common/types';
4
+ import { InputSource } from './enums';
3
5
  type AttachInputMeta = (inputSource: InputSource) => HigherOrderCommand;
4
6
  export declare const attachInputMeta: AttachInputMeta;
7
+ export declare const attachInputMetaWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputSource: InputSource, action: ACTION.UNDO_PERFORMED | ACTION.REDO_PERFORMED) => (command: Command) => Command;
5
8
  export {};
@@ -1,4 +1,9 @@
1
+ import { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
1
2
  export declare const undoFromKeyboard: import("@atlaskit/editor-common/types").Command;
2
3
  export declare const redoFromKeyboard: import("@atlaskit/editor-common/types").Command;
3
4
  export declare const undoFromToolbar: import("@atlaskit/editor-common/types").Command;
4
5
  export declare const redoFromToolbar: import("@atlaskit/editor-common/types").Command;
6
+ export declare const undoFromKeyboardWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => import("@atlaskit/editor-common/types").Command;
7
+ export declare const redoFromKeyboardWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => import("@atlaskit/editor-common/types").Command;
8
+ export declare const undoFromToolbarWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => import("@atlaskit/editor-common/types").Command;
9
+ export declare const redoFromToolbarWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => import("@atlaskit/editor-common/types").Command;
@@ -1,2 +1,4 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- export declare function keymapPlugin(): SafePlugin;
2
+ import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import { UndoRedoPlugin } from '../undoRedoPluginType';
4
+ export declare function keymapPlugin(api?: ExtractInjectionAPI<UndoRedoPlugin>): SafePlugin;
@@ -1,4 +1,5 @@
1
1
  import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
2
3
  import type { HistoryPlugin } from '@atlaskit/editor-plugin-history';
3
4
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
4
5
  import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
@@ -8,7 +9,8 @@ export type UndoRedoPlugin = NextEditorPlugin<'undoRedoPlugin', {
8
9
  dependencies: [
9
10
  TypeAheadPlugin,
10
11
  HistoryPlugin,
11
- OptionalPlugin<PrimaryToolbarPlugin>
12
+ OptionalPlugin<PrimaryToolbarPlugin>,
13
+ OptionalPlugin<AnalyticsPlugin>
12
14
  ];
13
15
  actions: {
14
16
  undo: UndoRedoAction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-undo-redo",
3
- "version": "2.0.9",
3
+ "version": "2.0.11",
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": "^103.0.0",
36
+ "@atlaskit/editor-common": "^103.22.0",
37
37
  "@atlaskit/editor-plugin-history": "^2.0.0",
38
- "@atlaskit/editor-plugin-primary-toolbar": "^3.1.0",
39
- "@atlaskit/editor-plugin-type-ahead": "^2.3.0",
38
+ "@atlaskit/editor-plugin-primary-toolbar": "^3.2.0",
39
+ "@atlaskit/editor-plugin-type-ahead": "^2.6.0",
40
40
  "@atlaskit/editor-prosemirror": "7.0.0",
41
- "@atlaskit/icon": "^25.5.0",
41
+ "@atlaskit/icon": "^25.6.0",
42
42
  "@atlaskit/platform-feature-flags": "^1.1.0",
43
- "@atlaskit/tmp-editor-statsig": "^4.6.0",
43
+ "@atlaskit/tmp-editor-statsig": "^4.15.0",
44
44
  "@babel/runtime": "^7.0.0",
45
45
  "@emotion/react": "^11.7.1"
46
46
  },
@@ -95,6 +95,9 @@
95
95
  "platform-feature-flags": {
96
96
  "platform_editor_cmd_y_mac_redo_shortcut": {
97
97
  "type": "boolean"
98
+ },
99
+ "platform_editor_controls_patch_analytics": {
100
+ "type": "boolean"
98
101
  }
99
102
  }
100
103
  }