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

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.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [#130044](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/130044)
8
+ [`cad348d512cdf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/cad348d512cdf) -
9
+ [ux] ED-26802 contextual formatting configuration
10
+ - Updated dependencies
11
+
12
+ ## 2.0.6
13
+
14
+ ### Patch Changes
15
+
16
+ - [#127269](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/127269)
17
+ [`a8235a7de7cd0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a8235a7de7cd0) -
18
+ Added undo & redo actions to undoRedoPlugin
19
+ - Updated dependencies
20
+
3
21
  ## 2.0.5
4
22
 
5
23
  ### Patch Changes
@@ -8,5 +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
12
  return InputSource;
12
13
  }({});
@@ -6,7 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.undoRedoPlugin = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
+ var _history = require("@atlaskit/editor-prosemirror/history");
9
11
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
12
+ var _attachInputMeta = require("./pm-plugins/attach-input-meta");
10
13
  var _keymaps = require("./pm-plugins/keymaps");
11
14
  var _main = require("./pm-plugins/main");
12
15
  var _ToolbarUndoRedo = _interopRequireDefault(require("./ui/ToolbarUndoRedo"));
@@ -15,7 +18,11 @@ var _ToolbarUndoRedo = _interopRequireDefault(require("./ui/ToolbarUndoRedo"));
15
18
  // eslint-disable-next-line import/no-named-as-default
16
19
 
17
20
  var undoRedoPlugin = exports.undoRedoPlugin = function undoRedoPlugin(_ref) {
21
+ var _api$primaryToolbar;
18
22
  var api = _ref.api;
23
+ var editorViewRef = {
24
+ current: null
25
+ };
19
26
  var primaryToolbarComponent = function primaryToolbarComponent(_ref2) {
20
27
  var editorView = _ref2.editorView,
21
28
  disabled = _ref2.disabled,
@@ -27,19 +34,40 @@ var undoRedoPlugin = exports.undoRedoPlugin = function undoRedoPlugin(_ref) {
27
34
  api: api
28
35
  });
29
36
  };
30
- if ((0, _experiments.editorExperiment)('platform_editor_controls', 'control', {
31
- exposure: true
32
- })) {
33
- var _api$primaryToolbar;
34
- api === null || api === void 0 || (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 || _api$primaryToolbar.actions.registerComponent({
35
- name: 'undoRedoPlugin',
36
- component: primaryToolbarComponent
37
- });
38
- }
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
+ });
39
41
  return {
40
42
  name: 'undoRedoPlugin',
43
+ 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
+ }
68
+ },
41
69
  pmPlugins: function pmPlugins() {
42
- return [{
70
+ var plugins = [{
43
71
  name: 'undoRedoKeyMap',
44
72
  plugin: function plugin() {
45
73
  return (0, _keymaps.keymapPlugin)();
@@ -50,9 +78,27 @@ var undoRedoPlugin = exports.undoRedoPlugin = function undoRedoPlugin(_ref) {
50
78
  return (0, _main.createPlugin)(options);
51
79
  }
52
80
  }];
81
+ if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1', {
82
+ exposure: false
83
+ })) {
84
+ plugins.push({
85
+ name: 'undoRedoGetEditorViewReferencePlugin',
86
+ plugin: function plugin() {
87
+ return new _safePlugin.SafePlugin({
88
+ view: function view(editorView) {
89
+ editorViewRef.current = editorView;
90
+ return {
91
+ destroy: function destroy() {
92
+ editorViewRef.current = null;
93
+ }
94
+ };
95
+ }
96
+ });
97
+ }
98
+ });
99
+ }
100
+ return plugins;
53
101
  },
54
- primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && (0, _experiments.editorExperiment)('platform_editor_controls', 'control', {
55
- exposure: true
56
- }) ? primaryToolbarComponent : undefined
102
+ primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined
57
103
  };
58
104
  };
@@ -2,5 +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
6
  return InputSource;
6
7
  }({});
@@ -1,5 +1,8 @@
1
1
  import React from 'react';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { redo, undo } from '@atlaskit/editor-prosemirror/history';
2
4
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
+ import { attachInputMeta } from './pm-plugins/attach-input-meta';
3
6
  import { keymapPlugin } from './pm-plugins/keymaps';
4
7
  import { createPlugin } from './pm-plugins/main';
5
8
  // eslint-disable-next-line @atlassian/tangerine/import/entry-points
@@ -9,6 +12,10 @@ import ToolbarUndoRedo from './ui/ToolbarUndoRedo';
9
12
  export const undoRedoPlugin = ({
10
13
  api
11
14
  }) => {
15
+ var _api$primaryToolbar;
16
+ const editorViewRef = {
17
+ current: null
18
+ };
12
19
  const primaryToolbarComponent = ({
13
20
  editorView,
14
21
  disabled,
@@ -21,28 +28,69 @@ export const undoRedoPlugin = ({
21
28
  api: api
22
29
  });
23
30
  };
24
- if (editorExperiment('platform_editor_controls', 'control', {
25
- exposure: true
26
- })) {
27
- var _api$primaryToolbar;
28
- api === null || api === void 0 ? void 0 : (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 ? void 0 : _api$primaryToolbar.actions.registerComponent({
29
- name: 'undoRedoPlugin',
30
- component: primaryToolbarComponent
31
- });
32
- }
31
+ api === null || api === void 0 ? void 0 : (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 ? void 0 : _api$primaryToolbar.actions.registerComponent({
32
+ name: 'undoRedoPlugin',
33
+ component: primaryToolbarComponent
34
+ });
33
35
  return {
34
36
  name: 'undoRedoPlugin',
37
+ 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
+ }
64
+ },
35
65
  pmPlugins() {
36
- return [{
66
+ const plugins = [{
37
67
  name: 'undoRedoKeyMap',
38
68
  plugin: () => keymapPlugin()
39
69
  }, {
40
70
  name: 'undoRedoPlugin',
41
71
  plugin: options => createPlugin(options)
42
72
  }];
73
+ if (editorExperiment('platform_editor_controls', 'variant1', {
74
+ exposure: false
75
+ })) {
76
+ plugins.push({
77
+ name: 'undoRedoGetEditorViewReferencePlugin',
78
+ plugin: () => {
79
+ return new SafePlugin({
80
+ view: editorView => {
81
+ editorViewRef.current = editorView;
82
+ return {
83
+ destroy: () => {
84
+ editorViewRef.current = null;
85
+ }
86
+ };
87
+ }
88
+ });
89
+ }
90
+ });
91
+ }
92
+ return plugins;
43
93
  },
44
- primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && editorExperiment('platform_editor_controls', 'control', {
45
- exposure: true
46
- }) ? primaryToolbarComponent : undefined
94
+ primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined
47
95
  };
48
96
  };
@@ -2,5 +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
6
  return InputSource;
6
7
  }({});
@@ -1,5 +1,8 @@
1
1
  import React from 'react';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { redo as _redo, undo as _undo } from '@atlaskit/editor-prosemirror/history';
2
4
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
+ import { attachInputMeta } from './pm-plugins/attach-input-meta';
3
6
  import { keymapPlugin } from './pm-plugins/keymaps';
4
7
  import { createPlugin } from './pm-plugins/main';
5
8
  // eslint-disable-next-line @atlassian/tangerine/import/entry-points
@@ -7,7 +10,11 @@ import { createPlugin } from './pm-plugins/main';
7
10
  // eslint-disable-next-line import/no-named-as-default
8
11
  import ToolbarUndoRedo from './ui/ToolbarUndoRedo';
9
12
  export var undoRedoPlugin = function undoRedoPlugin(_ref) {
13
+ var _api$primaryToolbar;
10
14
  var api = _ref.api;
15
+ var editorViewRef = {
16
+ current: null
17
+ };
11
18
  var primaryToolbarComponent = function primaryToolbarComponent(_ref2) {
12
19
  var editorView = _ref2.editorView,
13
20
  disabled = _ref2.disabled,
@@ -19,19 +26,40 @@ export var undoRedoPlugin = function undoRedoPlugin(_ref) {
19
26
  api: api
20
27
  });
21
28
  };
22
- if (editorExperiment('platform_editor_controls', 'control', {
23
- exposure: true
24
- })) {
25
- var _api$primaryToolbar;
26
- api === null || api === void 0 || (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 || _api$primaryToolbar.actions.registerComponent({
27
- name: 'undoRedoPlugin',
28
- component: primaryToolbarComponent
29
- });
30
- }
29
+ api === null || api === void 0 || (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 || _api$primaryToolbar.actions.registerComponent({
30
+ name: 'undoRedoPlugin',
31
+ component: primaryToolbarComponent
32
+ });
31
33
  return {
32
34
  name: 'undoRedoPlugin',
35
+ 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
+ }
60
+ },
33
61
  pmPlugins: function pmPlugins() {
34
- return [{
62
+ var plugins = [{
35
63
  name: 'undoRedoKeyMap',
36
64
  plugin: function plugin() {
37
65
  return keymapPlugin();
@@ -42,9 +70,27 @@ export var undoRedoPlugin = function undoRedoPlugin(_ref) {
42
70
  return createPlugin(options);
43
71
  }
44
72
  }];
73
+ if (editorExperiment('platform_editor_controls', 'variant1', {
74
+ exposure: false
75
+ })) {
76
+ plugins.push({
77
+ name: 'undoRedoGetEditorViewReferencePlugin',
78
+ plugin: function plugin() {
79
+ return new SafePlugin({
80
+ view: function view(editorView) {
81
+ editorViewRef.current = editorView;
82
+ return {
83
+ destroy: function destroy() {
84
+ editorViewRef.current = null;
85
+ }
86
+ };
87
+ }
88
+ });
89
+ }
90
+ });
91
+ }
92
+ return plugins;
45
93
  },
46
- primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && editorExperiment('platform_editor_controls', 'control', {
47
- exposure: true
48
- }) ? primaryToolbarComponent : undefined
94
+ primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined
49
95
  };
50
96
  };
@@ -1,4 +1,5 @@
1
1
  export declare enum InputSource {
2
2
  TOOLBAR = "toolbar",
3
- KEYBOARD = "keyboard"
3
+ KEYBOARD = "keyboard",
4
+ PAGE_OVERFLOW_MENU = "confluencePageOverflowMenu"
4
5
  }
@@ -2,6 +2,12 @@ import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/t
2
2
  import type { HistoryPlugin } from '@atlaskit/editor-plugin-history';
3
3
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
4
4
  import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
5
+ import { InputSource } from './pm-plugins/enums';
6
+ export type UndoRedoAction = (inputSource?: InputSource) => boolean;
5
7
  export type UndoRedoPlugin = NextEditorPlugin<'undoRedoPlugin', {
6
8
  dependencies: [TypeAheadPlugin, HistoryPlugin, OptionalPlugin<PrimaryToolbarPlugin>];
9
+ actions: {
10
+ undo: UndoRedoAction;
11
+ redo: UndoRedoAction;
12
+ };
7
13
  }>;
@@ -1,4 +1,5 @@
1
1
  export declare enum InputSource {
2
2
  TOOLBAR = "toolbar",
3
- KEYBOARD = "keyboard"
3
+ KEYBOARD = "keyboard",
4
+ PAGE_OVERFLOW_MENU = "confluencePageOverflowMenu"
4
5
  }
@@ -2,10 +2,16 @@ import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/t
2
2
  import type { HistoryPlugin } from '@atlaskit/editor-plugin-history';
3
3
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
4
4
  import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
5
+ import { InputSource } from './pm-plugins/enums';
6
+ export type UndoRedoAction = (inputSource?: InputSource) => boolean;
5
7
  export type UndoRedoPlugin = NextEditorPlugin<'undoRedoPlugin', {
6
8
  dependencies: [
7
9
  TypeAheadPlugin,
8
10
  HistoryPlugin,
9
11
  OptionalPlugin<PrimaryToolbarPlugin>
10
12
  ];
13
+ actions: {
14
+ undo: UndoRedoAction;
15
+ redo: UndoRedoAction;
16
+ };
11
17
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-undo-redo",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
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.4.0",
36
+ "@atlaskit/editor-common": "^102.12.0",
37
37
  "@atlaskit/editor-plugin-history": "^2.0.0",
38
- "@atlaskit/editor-plugin-primary-toolbar": "^3.0.0",
38
+ "@atlaskit/editor-plugin-primary-toolbar": "^3.1.0",
39
39
  "@atlaskit/editor-plugin-type-ahead": "^2.1.0",
40
40
  "@atlaskit/editor-prosemirror": "7.0.0",
41
41
  "@atlaskit/icon": "^25.0.0",
42
42
  "@atlaskit/platform-feature-flags": "^1.1.0",
43
- "@atlaskit/tmp-editor-statsig": "^3.6.0",
43
+ "@atlaskit/tmp-editor-statsig": "^4.1.0",
44
44
  "@babel/runtime": "^7.0.0",
45
45
  "@emotion/react": "^11.7.1"
46
46
  },