@atlaskit/editor-plugin-undo-redo 3.1.2 → 3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-undo-redo
2
2
 
3
+ ## 3.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`f78a34afab8d4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f78a34afab8d4) -
8
+ [ux] ED-28961 register undo redo and track changes buttons to new toolbar behind
9
+ platform_editor_toolbar_aifc. adds ai buttons into comment toolbar.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 3.1.2
4
16
 
5
17
  ### Patch Changes
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.RedoButton = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _hooks = require("@atlaskit/editor-common/hooks");
11
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
12
+ var _messages = require("@atlaskit/editor-common/messages");
13
+ var _toolbar = require("@atlaskit/editor-common/toolbar");
14
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
15
+ var _commands = require("../../pm-plugins/commands");
16
+ var _utils = require("../../pm-plugins/utils");
17
+ var RedoButton = exports.RedoButton = function RedoButton(_ref) {
18
+ var api = _ref.api;
19
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
20
+ formatMessage = _useIntl.formatMessage;
21
+ var _useEditorToolbar = (0, _toolbar.useEditorToolbar)(),
22
+ editorView = _useEditorToolbar.editorView;
23
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['history'], function (states) {
24
+ var _states$historyState;
25
+ return {
26
+ canRedo: (_states$historyState = states.historyState) === null || _states$historyState === void 0 ? void 0 : _states$historyState.canRedo
27
+ };
28
+ }),
29
+ canRedo = _useSharedPluginState.canRedo;
30
+ var handleRedo = function handleRedo() {
31
+ if (editorView) {
32
+ var _api$analytics;
33
+ (0, _utils.forceFocus)(editorView, api)((0, _commands.redoFromToolbarWithAnalytics)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions));
34
+ }
35
+ };
36
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarTooltip, {
37
+ content: /*#__PURE__*/_react.default.createElement(_keymaps.ToolTipContent, {
38
+ description: formatMessage(_messages.undoRedoMessages.redo),
39
+ keymap: _keymaps.redo
40
+ })
41
+ }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarButton, {
42
+ iconBefore: /*#__PURE__*/_react.default.createElement(_editorToolbar.RedoIcon, {
43
+ label: formatMessage(_messages.undoRedoMessages.redo)
44
+ }),
45
+ onClick: handleRedo,
46
+ isDisabled: !canRedo,
47
+ ariaKeyshortcuts: (0, _keymaps.getAriaKeyshortcuts)(_keymaps.redo),
48
+ testId: "ak-editor-toolbar-button-redo"
49
+ }));
50
+ };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.UndoButton = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _hooks = require("@atlaskit/editor-common/hooks");
11
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
12
+ var _messages = require("@atlaskit/editor-common/messages");
13
+ var _toolbar = require("@atlaskit/editor-common/toolbar");
14
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
15
+ var _commands = require("../../pm-plugins/commands");
16
+ var _utils = require("../../pm-plugins/utils");
17
+ var UndoButton = exports.UndoButton = function UndoButton(_ref) {
18
+ var api = _ref.api;
19
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
20
+ formatMessage = _useIntl.formatMessage;
21
+ var _useEditorToolbar = (0, _toolbar.useEditorToolbar)(),
22
+ editorView = _useEditorToolbar.editorView;
23
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['history'], function (states) {
24
+ var _states$historyState;
25
+ return {
26
+ canUndo: (_states$historyState = states.historyState) === null || _states$historyState === void 0 ? void 0 : _states$historyState.canUndo
27
+ };
28
+ }),
29
+ canUndo = _useSharedPluginState.canUndo;
30
+ var handleUndo = function handleUndo() {
31
+ if (editorView) {
32
+ var _api$analytics;
33
+ (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));
34
+ }
35
+ };
36
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarTooltip, {
37
+ content: /*#__PURE__*/_react.default.createElement(_keymaps.ToolTipContent, {
38
+ description: formatMessage(_messages.undoRedoMessages.undo),
39
+ keymap: _keymaps.undo
40
+ })
41
+ }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarButton, {
42
+ iconBefore: /*#__PURE__*/_react.default.createElement(_editorToolbar.UndoIcon, {
43
+ label: formatMessage(_messages.undoRedoMessages.undo)
44
+ }),
45
+ onClick: handleUndo,
46
+ isDisabled: !canUndo,
47
+ ariaKeyshortcuts: (0, _keymaps.getAriaKeyshortcuts)(_keymaps.undo),
48
+ testId: "ak-editor-toolbar-button-undo"
49
+ }));
50
+ };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getToolbarComponents = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _toolbar = require("@atlaskit/editor-common/toolbar");
10
+ var _RedoButton = require("./RedoButton");
11
+ var _UndoButton = require("./UndoButton");
12
+ var getToolbarComponents = exports.getToolbarComponents = function getToolbarComponents(api) {
13
+ return [{
14
+ type: _toolbar.UNDO_BUTTON.type,
15
+ key: _toolbar.UNDO_BUTTON.key,
16
+ parents: [{
17
+ type: _toolbar.TRACK_CHANGES_GROUP.type,
18
+ key: _toolbar.TRACK_CHANGES_GROUP.key,
19
+ rank: _toolbar.TRACK_CHANGES_GROUP_RANK[_toolbar.UNDO_BUTTON.key]
20
+ }],
21
+ component: function component() {
22
+ return /*#__PURE__*/_react.default.createElement(_UndoButton.UndoButton, {
23
+ api: api
24
+ });
25
+ }
26
+ }, {
27
+ type: _toolbar.REDO_BUTTON.type,
28
+ key: _toolbar.REDO_BUTTON.key,
29
+ parents: [{
30
+ type: _toolbar.TRACK_CHANGES_GROUP.type,
31
+ key: _toolbar.TRACK_CHANGES_GROUP.key,
32
+ rank: _toolbar.TRACK_CHANGES_GROUP_RANK[_toolbar.REDO_BUTTON.key]
33
+ }],
34
+ component: function component() {
35
+ return /*#__PURE__*/_react.default.createElement(_RedoButton.RedoButton, {
36
+ api: api
37
+ });
38
+ }
39
+ }];
40
+ };
@@ -9,6 +9,7 @@ var _react = _interopRequireDefault(require("react"));
9
9
  var _analytics = require("@atlaskit/editor-common/analytics");
10
10
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
11
  var _history = require("@atlaskit/editor-prosemirror/history");
12
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
12
13
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
13
14
  var _attachInputMeta = require("./pm-plugins/attach-input-meta");
14
15
  var _enums = require("./pm-plugins/enums");
@@ -16,11 +17,11 @@ var _keymaps = require("./pm-plugins/keymaps");
16
17
  var _main = require("./pm-plugins/main");
17
18
  var _utils = require("./pm-plugins/utils");
18
19
  var _ToolbarUndoRedo = _interopRequireDefault(require("./ui/ToolbarUndoRedo"));
20
+ var _toolbarComponents = require("./ui/ToolbarUndoRedo/toolbar-components");
19
21
  // Ignored via go/ees005
20
22
  // eslint-disable-next-line import/no-named-as-default
21
23
 
22
24
  var undoRedoPlugin = exports.undoRedoPlugin = function undoRedoPlugin(_ref) {
23
- var _api$primaryToolbar;
24
25
  var api = _ref.api;
25
26
  var editorViewRef = {
26
27
  current: null
@@ -36,10 +37,16 @@ var undoRedoPlugin = exports.undoRedoPlugin = function undoRedoPlugin(_ref) {
36
37
  api: api
37
38
  });
38
39
  };
39
- api === null || api === void 0 || (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 || _api$primaryToolbar.actions.registerComponent({
40
- name: 'undoRedoPlugin',
41
- component: primaryToolbarComponent
42
- });
40
+ if ((0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc', 'isEnabled', true)) {
41
+ var _api$toolbar;
42
+ api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || _api$toolbar.actions.registerComponents((0, _toolbarComponents.getToolbarComponents)(api));
43
+ } else {
44
+ var _api$primaryToolbar;
45
+ api === null || api === void 0 || (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 || _api$primaryToolbar.actions.registerComponent({
46
+ name: 'undoRedoPlugin',
47
+ component: primaryToolbarComponent
48
+ });
49
+ }
43
50
  var handleUndo = function handleUndo(inputSource) {
44
51
  var _api$analytics;
45
52
  if (!editorViewRef.current) {
@@ -93,6 +100,6 @@ var undoRedoPlugin = exports.undoRedoPlugin = function undoRedoPlugin(_ref) {
93
100
  }
94
101
  return plugins;
95
102
  },
96
- primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined
103
+ primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && !(0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc', 'isEnabled', true) ? primaryToolbarComponent : undefined
97
104
  };
98
105
  };
@@ -0,0 +1,47 @@
1
+ import React from "react";
2
+ import { useIntl } from "react-intl-next";
3
+ import { useSharedPluginStateWithSelector } from "@atlaskit/editor-common/hooks";
4
+ import { getAriaKeyshortcuts, redo as redoKeymap, ToolTipContent } from '@atlaskit/editor-common/keymaps';
5
+ import { undoRedoMessages } from '@atlaskit/editor-common/messages';
6
+ import { useEditorToolbar } from "@atlaskit/editor-common/toolbar";
7
+ import { ToolbarButton, RedoIcon, ToolbarTooltip } from "@atlaskit/editor-toolbar";
8
+ import { redoFromToolbarWithAnalytics } from "../../pm-plugins/commands";
9
+ import { forceFocus } from "../../pm-plugins/utils";
10
+ export const RedoButton = ({
11
+ api
12
+ }) => {
13
+ const {
14
+ formatMessage
15
+ } = useIntl();
16
+ const {
17
+ editorView
18
+ } = useEditorToolbar();
19
+ const {
20
+ canRedo
21
+ } = useSharedPluginStateWithSelector(api, ['history'], states => {
22
+ var _states$historyState;
23
+ return {
24
+ canRedo: (_states$historyState = states.historyState) === null || _states$historyState === void 0 ? void 0 : _states$historyState.canRedo
25
+ };
26
+ });
27
+ const handleRedo = () => {
28
+ if (editorView) {
29
+ var _api$analytics;
30
+ forceFocus(editorView, api)(redoFromToolbarWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions));
31
+ }
32
+ };
33
+ return /*#__PURE__*/React.createElement(ToolbarTooltip, {
34
+ content: /*#__PURE__*/React.createElement(ToolTipContent, {
35
+ description: formatMessage(undoRedoMessages.redo),
36
+ keymap: redoKeymap
37
+ })
38
+ }, /*#__PURE__*/React.createElement(ToolbarButton, {
39
+ iconBefore: /*#__PURE__*/React.createElement(RedoIcon, {
40
+ label: formatMessage(undoRedoMessages.redo)
41
+ }),
42
+ onClick: handleRedo,
43
+ isDisabled: !canRedo,
44
+ ariaKeyshortcuts: getAriaKeyshortcuts(redoKeymap),
45
+ testId: "ak-editor-toolbar-button-redo"
46
+ }));
47
+ };
@@ -0,0 +1,47 @@
1
+ import React from "react";
2
+ import { useIntl } from "react-intl-next";
3
+ import { useSharedPluginStateWithSelector } from "@atlaskit/editor-common/hooks";
4
+ import { getAriaKeyshortcuts, ToolTipContent, undo as undoKeymap } from '@atlaskit/editor-common/keymaps';
5
+ import { undoRedoMessages } from '@atlaskit/editor-common/messages';
6
+ import { useEditorToolbar } from "@atlaskit/editor-common/toolbar";
7
+ import { ToolbarButton, ToolbarTooltip, UndoIcon } from "@atlaskit/editor-toolbar";
8
+ import { undoFromToolbarWithAnalytics } from "../../pm-plugins/commands";
9
+ import { forceFocus } from "../../pm-plugins/utils";
10
+ export const UndoButton = ({
11
+ api
12
+ }) => {
13
+ const {
14
+ formatMessage
15
+ } = useIntl();
16
+ const {
17
+ editorView
18
+ } = useEditorToolbar();
19
+ const {
20
+ canUndo
21
+ } = useSharedPluginStateWithSelector(api, ['history'], states => {
22
+ var _states$historyState;
23
+ return {
24
+ canUndo: (_states$historyState = states.historyState) === null || _states$historyState === void 0 ? void 0 : _states$historyState.canUndo
25
+ };
26
+ });
27
+ const handleUndo = () => {
28
+ if (editorView) {
29
+ var _api$analytics;
30
+ 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));
31
+ }
32
+ };
33
+ return /*#__PURE__*/React.createElement(ToolbarTooltip, {
34
+ content: /*#__PURE__*/React.createElement(ToolTipContent, {
35
+ description: formatMessage(undoRedoMessages.undo),
36
+ keymap: undoKeymap
37
+ })
38
+ }, /*#__PURE__*/React.createElement(ToolbarButton, {
39
+ iconBefore: /*#__PURE__*/React.createElement(UndoIcon, {
40
+ label: formatMessage(undoRedoMessages.undo)
41
+ }),
42
+ onClick: handleUndo,
43
+ isDisabled: !canUndo,
44
+ ariaKeyshortcuts: getAriaKeyshortcuts(undoKeymap),
45
+ testId: "ak-editor-toolbar-button-undo"
46
+ }));
47
+ };
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import { UNDO_BUTTON, REDO_BUTTON, TRACK_CHANGES_GROUP_RANK, TRACK_CHANGES_GROUP } from "@atlaskit/editor-common/toolbar";
3
+ import { RedoButton } from './RedoButton';
4
+ import { UndoButton } from "./UndoButton";
5
+ export const getToolbarComponents = api => {
6
+ return [{
7
+ type: UNDO_BUTTON.type,
8
+ key: UNDO_BUTTON.key,
9
+ parents: [{
10
+ type: TRACK_CHANGES_GROUP.type,
11
+ key: TRACK_CHANGES_GROUP.key,
12
+ rank: TRACK_CHANGES_GROUP_RANK[UNDO_BUTTON.key]
13
+ }],
14
+ component: () => /*#__PURE__*/React.createElement(UndoButton, {
15
+ api: api
16
+ })
17
+ }, {
18
+ type: REDO_BUTTON.type,
19
+ key: REDO_BUTTON.key,
20
+ parents: [{
21
+ type: TRACK_CHANGES_GROUP.type,
22
+ key: TRACK_CHANGES_GROUP.key,
23
+ rank: TRACK_CHANGES_GROUP_RANK[REDO_BUTTON.key]
24
+ }],
25
+ component: () => /*#__PURE__*/React.createElement(RedoButton, {
26
+ api: api
27
+ })
28
+ }];
29
+ };
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { ACTION } from '@atlaskit/editor-common/analytics';
3
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import { redo, undo } from '@atlaskit/editor-prosemirror/history';
5
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
5
6
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
6
7
  import { attachInputMetaWithAnalytics } from './pm-plugins/attach-input-meta';
7
8
  import { InputSource } from './pm-plugins/enums';
@@ -11,10 +12,10 @@ import { forceFocus } from './pm-plugins/utils';
11
12
  // Ignored via go/ees005
12
13
  // eslint-disable-next-line import/no-named-as-default
13
14
  import ToolbarUndoRedo from './ui/ToolbarUndoRedo';
15
+ import { getToolbarComponents } from './ui/ToolbarUndoRedo/toolbar-components';
14
16
  export const undoRedoPlugin = ({
15
17
  api
16
18
  }) => {
17
- var _api$primaryToolbar;
18
19
  const editorViewRef = {
19
20
  current: null
20
21
  };
@@ -30,10 +31,16 @@ export const undoRedoPlugin = ({
30
31
  api: api
31
32
  });
32
33
  };
33
- api === null || api === void 0 ? void 0 : (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 ? void 0 : _api$primaryToolbar.actions.registerComponent({
34
- name: 'undoRedoPlugin',
35
- component: primaryToolbarComponent
36
- });
34
+ if (expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true)) {
35
+ var _api$toolbar;
36
+ api === null || api === void 0 ? void 0 : (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : _api$toolbar.actions.registerComponents(getToolbarComponents(api));
37
+ } else {
38
+ var _api$primaryToolbar;
39
+ api === null || api === void 0 ? void 0 : (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 ? void 0 : _api$primaryToolbar.actions.registerComponent({
40
+ name: 'undoRedoPlugin',
41
+ component: primaryToolbarComponent
42
+ });
43
+ }
37
44
  const handleUndo = inputSource => {
38
45
  var _api$analytics;
39
46
  if (!editorViewRef.current) {
@@ -83,6 +90,6 @@ export const undoRedoPlugin = ({
83
90
  }
84
91
  return plugins;
85
92
  },
86
- primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined
93
+ primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && !expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true) ? primaryToolbarComponent : undefined
87
94
  };
88
95
  };
@@ -0,0 +1,43 @@
1
+ import React from "react";
2
+ import { useIntl } from "react-intl-next";
3
+ import { useSharedPluginStateWithSelector } from "@atlaskit/editor-common/hooks";
4
+ import { getAriaKeyshortcuts, redo as redoKeymap, ToolTipContent } from '@atlaskit/editor-common/keymaps';
5
+ import { undoRedoMessages } from '@atlaskit/editor-common/messages';
6
+ import { useEditorToolbar } from "@atlaskit/editor-common/toolbar";
7
+ import { ToolbarButton, RedoIcon, ToolbarTooltip } from "@atlaskit/editor-toolbar";
8
+ import { redoFromToolbarWithAnalytics } from "../../pm-plugins/commands";
9
+ import { forceFocus } from "../../pm-plugins/utils";
10
+ export var RedoButton = function RedoButton(_ref) {
11
+ var api = _ref.api;
12
+ var _useIntl = useIntl(),
13
+ formatMessage = _useIntl.formatMessage;
14
+ var _useEditorToolbar = useEditorToolbar(),
15
+ editorView = _useEditorToolbar.editorView;
16
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['history'], function (states) {
17
+ var _states$historyState;
18
+ return {
19
+ canRedo: (_states$historyState = states.historyState) === null || _states$historyState === void 0 ? void 0 : _states$historyState.canRedo
20
+ };
21
+ }),
22
+ canRedo = _useSharedPluginState.canRedo;
23
+ var handleRedo = function handleRedo() {
24
+ if (editorView) {
25
+ var _api$analytics;
26
+ forceFocus(editorView, api)(redoFromToolbarWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions));
27
+ }
28
+ };
29
+ return /*#__PURE__*/React.createElement(ToolbarTooltip, {
30
+ content: /*#__PURE__*/React.createElement(ToolTipContent, {
31
+ description: formatMessage(undoRedoMessages.redo),
32
+ keymap: redoKeymap
33
+ })
34
+ }, /*#__PURE__*/React.createElement(ToolbarButton, {
35
+ iconBefore: /*#__PURE__*/React.createElement(RedoIcon, {
36
+ label: formatMessage(undoRedoMessages.redo)
37
+ }),
38
+ onClick: handleRedo,
39
+ isDisabled: !canRedo,
40
+ ariaKeyshortcuts: getAriaKeyshortcuts(redoKeymap),
41
+ testId: "ak-editor-toolbar-button-redo"
42
+ }));
43
+ };
@@ -0,0 +1,43 @@
1
+ import React from "react";
2
+ import { useIntl } from "react-intl-next";
3
+ import { useSharedPluginStateWithSelector } from "@atlaskit/editor-common/hooks";
4
+ import { getAriaKeyshortcuts, ToolTipContent, undo as undoKeymap } from '@atlaskit/editor-common/keymaps';
5
+ import { undoRedoMessages } from '@atlaskit/editor-common/messages';
6
+ import { useEditorToolbar } from "@atlaskit/editor-common/toolbar";
7
+ import { ToolbarButton, ToolbarTooltip, UndoIcon } from "@atlaskit/editor-toolbar";
8
+ import { undoFromToolbarWithAnalytics } from "../../pm-plugins/commands";
9
+ import { forceFocus } from "../../pm-plugins/utils";
10
+ export var UndoButton = function UndoButton(_ref) {
11
+ var api = _ref.api;
12
+ var _useIntl = useIntl(),
13
+ formatMessage = _useIntl.formatMessage;
14
+ var _useEditorToolbar = useEditorToolbar(),
15
+ editorView = _useEditorToolbar.editorView;
16
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['history'], function (states) {
17
+ var _states$historyState;
18
+ return {
19
+ canUndo: (_states$historyState = states.historyState) === null || _states$historyState === void 0 ? void 0 : _states$historyState.canUndo
20
+ };
21
+ }),
22
+ canUndo = _useSharedPluginState.canUndo;
23
+ var handleUndo = function handleUndo() {
24
+ if (editorView) {
25
+ var _api$analytics;
26
+ forceFocus(editorView, api)(undoFromToolbarWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions));
27
+ }
28
+ };
29
+ return /*#__PURE__*/React.createElement(ToolbarTooltip, {
30
+ content: /*#__PURE__*/React.createElement(ToolTipContent, {
31
+ description: formatMessage(undoRedoMessages.undo),
32
+ keymap: undoKeymap
33
+ })
34
+ }, /*#__PURE__*/React.createElement(ToolbarButton, {
35
+ iconBefore: /*#__PURE__*/React.createElement(UndoIcon, {
36
+ label: formatMessage(undoRedoMessages.undo)
37
+ }),
38
+ onClick: handleUndo,
39
+ isDisabled: !canUndo,
40
+ ariaKeyshortcuts: getAriaKeyshortcuts(undoKeymap),
41
+ testId: "ak-editor-toolbar-button-undo"
42
+ }));
43
+ };
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import { UNDO_BUTTON, REDO_BUTTON, TRACK_CHANGES_GROUP_RANK, TRACK_CHANGES_GROUP } from "@atlaskit/editor-common/toolbar";
3
+ import { RedoButton } from './RedoButton';
4
+ import { UndoButton } from "./UndoButton";
5
+ export var getToolbarComponents = function getToolbarComponents(api) {
6
+ return [{
7
+ type: UNDO_BUTTON.type,
8
+ key: UNDO_BUTTON.key,
9
+ parents: [{
10
+ type: TRACK_CHANGES_GROUP.type,
11
+ key: TRACK_CHANGES_GROUP.key,
12
+ rank: TRACK_CHANGES_GROUP_RANK[UNDO_BUTTON.key]
13
+ }],
14
+ component: function component() {
15
+ return /*#__PURE__*/React.createElement(UndoButton, {
16
+ api: api
17
+ });
18
+ }
19
+ }, {
20
+ type: REDO_BUTTON.type,
21
+ key: REDO_BUTTON.key,
22
+ parents: [{
23
+ type: TRACK_CHANGES_GROUP.type,
24
+ key: TRACK_CHANGES_GROUP.key,
25
+ rank: TRACK_CHANGES_GROUP_RANK[REDO_BUTTON.key]
26
+ }],
27
+ component: function component() {
28
+ return /*#__PURE__*/React.createElement(RedoButton, {
29
+ api: api
30
+ });
31
+ }
32
+ }];
33
+ };
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { ACTION } from '@atlaskit/editor-common/analytics';
3
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import { redo, undo } from '@atlaskit/editor-prosemirror/history';
5
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
5
6
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
6
7
  import { attachInputMetaWithAnalytics } from './pm-plugins/attach-input-meta';
7
8
  import { InputSource } from './pm-plugins/enums';
@@ -11,8 +12,8 @@ import { forceFocus } from './pm-plugins/utils';
11
12
  // Ignored via go/ees005
12
13
  // eslint-disable-next-line import/no-named-as-default
13
14
  import ToolbarUndoRedo from './ui/ToolbarUndoRedo';
15
+ import { getToolbarComponents } from './ui/ToolbarUndoRedo/toolbar-components';
14
16
  export var undoRedoPlugin = function undoRedoPlugin(_ref) {
15
- var _api$primaryToolbar;
16
17
  var api = _ref.api;
17
18
  var editorViewRef = {
18
19
  current: null
@@ -28,10 +29,16 @@ export var undoRedoPlugin = function undoRedoPlugin(_ref) {
28
29
  api: api
29
30
  });
30
31
  };
31
- api === null || api === void 0 || (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 || _api$primaryToolbar.actions.registerComponent({
32
- name: 'undoRedoPlugin',
33
- component: primaryToolbarComponent
34
- });
32
+ if (expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true)) {
33
+ var _api$toolbar;
34
+ api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || _api$toolbar.actions.registerComponents(getToolbarComponents(api));
35
+ } else {
36
+ var _api$primaryToolbar;
37
+ api === null || api === void 0 || (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 || _api$primaryToolbar.actions.registerComponent({
38
+ name: 'undoRedoPlugin',
39
+ component: primaryToolbarComponent
40
+ });
41
+ }
35
42
  var handleUndo = function handleUndo(inputSource) {
36
43
  var _api$analytics;
37
44
  if (!editorViewRef.current) {
@@ -85,6 +92,6 @@ export var undoRedoPlugin = function undoRedoPlugin(_ref) {
85
92
  }
86
93
  return plugins;
87
94
  },
88
- primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined
95
+ primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && !expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true) ? primaryToolbarComponent : undefined
89
96
  };
90
97
  };
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ import type { ExtractInjectionAPI } from "@atlaskit/editor-common/types";
3
+ import type { UndoRedoPlugin } from "../../undoRedoPluginType";
4
+ type RedoButtonProps = {
5
+ api?: ExtractInjectionAPI<UndoRedoPlugin>;
6
+ };
7
+ export declare const RedoButton: ({ api }: RedoButtonProps) => React.JSX.Element;
8
+ export {};
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ import type { ExtractInjectionAPI } from "@atlaskit/editor-common/types";
3
+ import type { UndoRedoPlugin } from "../../undoRedoPluginType";
4
+ type UndoButtonProps = {
5
+ api?: ExtractInjectionAPI<UndoRedoPlugin>;
6
+ };
7
+ export declare const UndoButton: ({ api }: UndoButtonProps) => React.JSX.Element;
8
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { ExtractInjectionAPI } from "@atlaskit/editor-common/types";
2
+ import type { RegisterComponent } from "@atlaskit/editor-toolbar-model";
3
+ import type { UndoRedoPlugin } from "../../undoRedoPluginType";
4
+ export declare const getToolbarComponents: (api?: ExtractInjectionAPI<UndoRedoPlugin>) => RegisterComponent[];
@@ -2,6 +2,7 @@ import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/t
2
2
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
3
3
  import type { HistoryPlugin } from '@atlaskit/editor-plugin-history';
4
4
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
5
+ import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
5
6
  import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
6
7
  import { type InputSource } from './pm-plugins/enums';
7
8
  export type UndoRedoAction = (inputSource?: InputSource) => boolean;
@@ -10,7 +11,8 @@ export type UndoRedoPlugin = NextEditorPlugin<'undoRedoPlugin', {
10
11
  TypeAheadPlugin,
11
12
  HistoryPlugin,
12
13
  OptionalPlugin<PrimaryToolbarPlugin>,
13
- OptionalPlugin<AnalyticsPlugin>
14
+ OptionalPlugin<AnalyticsPlugin>,
15
+ OptionalPlugin<ToolbarPlugin>
14
16
  ];
15
17
  actions: {
16
18
  undo: UndoRedoAction;
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ import type { ExtractInjectionAPI } from "@atlaskit/editor-common/types";
3
+ import type { UndoRedoPlugin } from "../../undoRedoPluginType";
4
+ type RedoButtonProps = {
5
+ api?: ExtractInjectionAPI<UndoRedoPlugin>;
6
+ };
7
+ export declare const RedoButton: ({ api }: RedoButtonProps) => React.JSX.Element;
8
+ export {};
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ import type { ExtractInjectionAPI } from "@atlaskit/editor-common/types";
3
+ import type { UndoRedoPlugin } from "../../undoRedoPluginType";
4
+ type UndoButtonProps = {
5
+ api?: ExtractInjectionAPI<UndoRedoPlugin>;
6
+ };
7
+ export declare const UndoButton: ({ api }: UndoButtonProps) => React.JSX.Element;
8
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { ExtractInjectionAPI } from "@atlaskit/editor-common/types";
2
+ import type { RegisterComponent } from "@atlaskit/editor-toolbar-model";
3
+ import type { UndoRedoPlugin } from "../../undoRedoPluginType";
4
+ export declare const getToolbarComponents: (api?: ExtractInjectionAPI<UndoRedoPlugin>) => RegisterComponent[];
@@ -2,6 +2,7 @@ import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/t
2
2
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
3
3
  import type { HistoryPlugin } from '@atlaskit/editor-plugin-history';
4
4
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
5
+ import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
5
6
  import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
6
7
  import { type InputSource } from './pm-plugins/enums';
7
8
  export type UndoRedoAction = (inputSource?: InputSource) => boolean;
@@ -10,7 +11,8 @@ export type UndoRedoPlugin = NextEditorPlugin<'undoRedoPlugin', {
10
11
  TypeAheadPlugin,
11
12
  HistoryPlugin,
12
13
  OptionalPlugin<PrimaryToolbarPlugin>,
13
- OptionalPlugin<AnalyticsPlugin>
14
+ OptionalPlugin<AnalyticsPlugin>,
15
+ OptionalPlugin<ToolbarPlugin>
14
16
  ];
15
17
  actions: {
16
18
  undo: UndoRedoAction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-undo-redo",
3
- "version": "3.1.2",
3
+ "version": "3.2.0",
4
4
  "description": "Undo redo plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,16 +34,19 @@
34
34
  "dependencies": {
35
35
  "@atlaskit/editor-plugin-history": "^3.1.0",
36
36
  "@atlaskit/editor-plugin-primary-toolbar": "^4.1.0",
37
+ "@atlaskit/editor-plugin-toolbar": "^0.2.0",
37
38
  "@atlaskit/editor-plugin-type-ahead": "^3.1.0",
38
39
  "@atlaskit/editor-prosemirror": "7.0.0",
40
+ "@atlaskit/editor-toolbar": "^0.3.0",
41
+ "@atlaskit/editor-toolbar-model": "^0.1.0",
39
42
  "@atlaskit/icon": "^27.12.0",
40
43
  "@atlaskit/platform-feature-flags": "^1.1.0",
41
- "@atlaskit/tmp-editor-statsig": "^11.0.0",
44
+ "@atlaskit/tmp-editor-statsig": "^11.3.0",
42
45
  "@babel/runtime": "^7.0.0",
43
46
  "@emotion/react": "^11.7.1"
44
47
  },
45
48
  "peerDependencies": {
46
- "@atlaskit/editor-common": "^107.25.0",
49
+ "@atlaskit/editor-common": "^107.26.0",
47
50
  "react": "^18.2.0",
48
51
  "react-intl-next": "npm:react-intl@^5.18.1"
49
52
  },