@atlaskit/editor-plugin-undo-redo 2.0.4 → 2.0.6

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.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#127269](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/127269)
8
+ [`a8235a7de7cd0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a8235a7de7cd0) -
9
+ Added undo & redo actions to undoRedoPlugin
10
+ - Updated dependencies
11
+
12
+ ## 2.0.5
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies
17
+
3
18
  ## 2.0.4
4
19
 
5
20
  ### 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"));
@@ -16,6 +19,9 @@ var _ToolbarUndoRedo = _interopRequireDefault(require("./ui/ToolbarUndoRedo"));
16
19
 
17
20
  var undoRedoPlugin = exports.undoRedoPlugin = function undoRedoPlugin(_ref) {
18
21
  var api = _ref.api;
22
+ var editorViewRef = {
23
+ current: null
24
+ };
19
25
  var primaryToolbarComponent = function primaryToolbarComponent(_ref2) {
20
26
  var editorView = _ref2.editorView,
21
27
  disabled = _ref2.disabled,
@@ -38,8 +44,34 @@ var undoRedoPlugin = exports.undoRedoPlugin = function undoRedoPlugin(_ref) {
38
44
  }
39
45
  return {
40
46
  name: 'undoRedoPlugin',
47
+ actions: {
48
+ undo: function undo(inputSource) {
49
+ if (!editorViewRef.current) {
50
+ return false;
51
+ }
52
+ var _editorViewRef$curren = editorViewRef.current,
53
+ state = _editorViewRef$curren.state,
54
+ dispatch = _editorViewRef$curren.dispatch;
55
+ if (!inputSource) {
56
+ return (0, _history.undo)(state, dispatch);
57
+ }
58
+ return (0, _attachInputMeta.attachInputMeta)(inputSource)(_history.undo)(state, dispatch);
59
+ },
60
+ redo: function redo(inputSource) {
61
+ if (!editorViewRef.current) {
62
+ return false;
63
+ }
64
+ var _editorViewRef$curren2 = editorViewRef.current,
65
+ state = _editorViewRef$curren2.state,
66
+ dispatch = _editorViewRef$curren2.dispatch;
67
+ if (!inputSource) {
68
+ return (0, _history.redo)(state, dispatch);
69
+ }
70
+ return (0, _attachInputMeta.attachInputMeta)(inputSource)(_history.redo)(state, dispatch);
71
+ }
72
+ },
41
73
  pmPlugins: function pmPlugins() {
42
- return [{
74
+ var plugins = [{
43
75
  name: 'undoRedoKeyMap',
44
76
  plugin: function plugin() {
45
77
  return (0, _keymaps.keymapPlugin)();
@@ -50,6 +82,26 @@ var undoRedoPlugin = exports.undoRedoPlugin = function undoRedoPlugin(_ref) {
50
82
  return (0, _main.createPlugin)(options);
51
83
  }
52
84
  }];
85
+ if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1', {
86
+ exposure: false
87
+ })) {
88
+ plugins.push({
89
+ name: 'undoRedoGetEditorViewReferencePlugin',
90
+ plugin: function plugin() {
91
+ return new _safePlugin.SafePlugin({
92
+ view: function view(editorView) {
93
+ editorViewRef.current = editorView;
94
+ return {
95
+ destroy: function destroy() {
96
+ editorViewRef.current = null;
97
+ }
98
+ };
99
+ }
100
+ });
101
+ }
102
+ });
103
+ }
104
+ return plugins;
53
105
  },
54
106
  primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && (0, _experiments.editorExperiment)('platform_editor_controls', 'control', {
55
107
  exposure: true
@@ -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,9 @@ import ToolbarUndoRedo from './ui/ToolbarUndoRedo';
9
12
  export const undoRedoPlugin = ({
10
13
  api
11
14
  }) => {
15
+ const editorViewRef = {
16
+ current: null
17
+ };
12
18
  const primaryToolbarComponent = ({
13
19
  editorView,
14
20
  disabled,
@@ -32,14 +38,62 @@ export const undoRedoPlugin = ({
32
38
  }
33
39
  return {
34
40
  name: 'undoRedoPlugin',
41
+ actions: {
42
+ undo: inputSource => {
43
+ if (!editorViewRef.current) {
44
+ return false;
45
+ }
46
+ const {
47
+ state,
48
+ dispatch
49
+ } = editorViewRef.current;
50
+ if (!inputSource) {
51
+ return undo(state, dispatch);
52
+ }
53
+ return attachInputMeta(inputSource)(undo)(state, dispatch);
54
+ },
55
+ redo: inputSource => {
56
+ if (!editorViewRef.current) {
57
+ return false;
58
+ }
59
+ const {
60
+ state,
61
+ dispatch
62
+ } = editorViewRef.current;
63
+ if (!inputSource) {
64
+ return redo(state, dispatch);
65
+ }
66
+ return attachInputMeta(inputSource)(redo)(state, dispatch);
67
+ }
68
+ },
35
69
  pmPlugins() {
36
- return [{
70
+ const plugins = [{
37
71
  name: 'undoRedoKeyMap',
38
72
  plugin: () => keymapPlugin()
39
73
  }, {
40
74
  name: 'undoRedoPlugin',
41
75
  plugin: options => createPlugin(options)
42
76
  }];
77
+ if (editorExperiment('platform_editor_controls', 'variant1', {
78
+ exposure: false
79
+ })) {
80
+ plugins.push({
81
+ name: 'undoRedoGetEditorViewReferencePlugin',
82
+ plugin: () => {
83
+ return new SafePlugin({
84
+ view: editorView => {
85
+ editorViewRef.current = editorView;
86
+ return {
87
+ destroy: () => {
88
+ editorViewRef.current = null;
89
+ }
90
+ };
91
+ }
92
+ });
93
+ }
94
+ });
95
+ }
96
+ return plugins;
43
97
  },
44
98
  primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && editorExperiment('platform_editor_controls', 'control', {
45
99
  exposure: true
@@ -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
@@ -8,6 +11,9 @@ import { createPlugin } from './pm-plugins/main';
8
11
  import ToolbarUndoRedo from './ui/ToolbarUndoRedo';
9
12
  export var undoRedoPlugin = function undoRedoPlugin(_ref) {
10
13
  var api = _ref.api;
14
+ var editorViewRef = {
15
+ current: null
16
+ };
11
17
  var primaryToolbarComponent = function primaryToolbarComponent(_ref2) {
12
18
  var editorView = _ref2.editorView,
13
19
  disabled = _ref2.disabled,
@@ -30,8 +36,34 @@ export var undoRedoPlugin = function undoRedoPlugin(_ref) {
30
36
  }
31
37
  return {
32
38
  name: 'undoRedoPlugin',
39
+ actions: {
40
+ undo: function undo(inputSource) {
41
+ if (!editorViewRef.current) {
42
+ return false;
43
+ }
44
+ var _editorViewRef$curren = editorViewRef.current,
45
+ state = _editorViewRef$curren.state,
46
+ dispatch = _editorViewRef$curren.dispatch;
47
+ if (!inputSource) {
48
+ return _undo(state, dispatch);
49
+ }
50
+ return attachInputMeta(inputSource)(_undo)(state, dispatch);
51
+ },
52
+ redo: function redo(inputSource) {
53
+ if (!editorViewRef.current) {
54
+ return false;
55
+ }
56
+ var _editorViewRef$curren2 = editorViewRef.current,
57
+ state = _editorViewRef$curren2.state,
58
+ dispatch = _editorViewRef$curren2.dispatch;
59
+ if (!inputSource) {
60
+ return _redo(state, dispatch);
61
+ }
62
+ return attachInputMeta(inputSource)(_redo)(state, dispatch);
63
+ }
64
+ },
33
65
  pmPlugins: function pmPlugins() {
34
- return [{
66
+ var plugins = [{
35
67
  name: 'undoRedoKeyMap',
36
68
  plugin: function plugin() {
37
69
  return keymapPlugin();
@@ -42,6 +74,26 @@ export var undoRedoPlugin = function undoRedoPlugin(_ref) {
42
74
  return createPlugin(options);
43
75
  }
44
76
  }];
77
+ if (editorExperiment('platform_editor_controls', 'variant1', {
78
+ exposure: false
79
+ })) {
80
+ plugins.push({
81
+ name: 'undoRedoGetEditorViewReferencePlugin',
82
+ plugin: function plugin() {
83
+ return new SafePlugin({
84
+ view: function view(editorView) {
85
+ editorViewRef.current = editorView;
86
+ return {
87
+ destroy: function destroy() {
88
+ editorViewRef.current = null;
89
+ }
90
+ };
91
+ }
92
+ });
93
+ }
94
+ });
95
+ }
96
+ return plugins;
45
97
  },
46
98
  primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && editorExperiment('platform_editor_controls', 'control', {
47
99
  exposure: true
@@ -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.4",
3
+ "version": "2.0.6",
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.0.0",
36
+ "@atlaskit/editor-common": "^102.8.0",
37
37
  "@atlaskit/editor-plugin-history": "^2.0.0",
38
38
  "@atlaskit/editor-plugin-primary-toolbar": "^3.0.0",
39
39
  "@atlaskit/editor-plugin-type-ahead": "^2.1.0",
40
40
  "@atlaskit/editor-prosemirror": "7.0.0",
41
- "@atlaskit/icon": "^24.1.0",
41
+ "@atlaskit/icon": "^25.0.0",
42
42
  "@atlaskit/platform-feature-flags": "^1.1.0",
43
- "@atlaskit/tmp-editor-statsig": "^3.4.0",
43
+ "@atlaskit/tmp-editor-statsig": "^4.0.0",
44
44
  "@babel/runtime": "^7.0.0",
45
45
  "@emotion/react": "^11.7.1"
46
46
  },