@atlaskit/editor-plugin-undo-redo 2.0.7 → 2.0.8
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 +9 -0
- package/dist/cjs/pm-plugins/enums.js +1 -1
- package/dist/cjs/pm-plugins/utils.js +33 -0
- package/dist/cjs/ui/ToolbarUndoRedo/index.js +3 -27
- package/dist/cjs/undoRedoPlugin.js +16 -25
- package/dist/es2019/pm-plugins/enums.js +1 -1
- package/dist/es2019/pm-plugins/utils.js +23 -0
- package/dist/es2019/ui/ToolbarUndoRedo/index.js +1 -21
- package/dist/es2019/undoRedoPlugin.js +16 -27
- package/dist/esm/pm-plugins/enums.js +1 -1
- package/dist/esm/pm-plugins/utils.js +27 -0
- package/dist/esm/ui/ToolbarUndoRedo/index.js +1 -25
- package/dist/esm/undoRedoPlugin.js +17 -26
- package/dist/types/pm-plugins/enums.d.ts +1 -1
- package/dist/types/pm-plugins/utils.d.ts +5 -0
- package/dist/types-ts4.5/pm-plugins/enums.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/utils.d.ts +5 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-undo-redo
|
|
2
2
|
|
|
3
|
+
## 2.0.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#130818](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/130818)
|
|
8
|
+
[`0e42cb4df2b7f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0e42cb4df2b7f) -
|
|
9
|
+
Changed undo/redo commands to use EXTRENAL input type when no inputSource is provided. Ensure type
|
|
10
|
+
ahead is closed before undo/redo and that editor is re-focused after undo/redo.
|
|
11
|
+
|
|
3
12
|
## 2.0.7
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -8,6 +8,6 @@ var _analytics = require("@atlaskit/editor-common/analytics");
|
|
|
8
8
|
var InputSource = exports.InputSource = function (InputSource) {
|
|
9
9
|
InputSource[InputSource["TOOLBAR"] = _analytics.INPUT_METHOD.TOOLBAR] = "TOOLBAR";
|
|
10
10
|
InputSource[InputSource["KEYBOARD"] = _analytics.INPUT_METHOD.KEYBOARD] = "KEYBOARD";
|
|
11
|
-
InputSource[InputSource["
|
|
11
|
+
InputSource[InputSource["EXTERNAL"] = _analytics.INPUT_METHOD.EXTERNAL] = "EXTERNAL";
|
|
12
12
|
return InputSource;
|
|
13
13
|
}({});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.forceFocus = exports.closeTypeAheadAndRunCommand = void 0;
|
|
7
|
+
var closeTypeAheadAndRunCommand = exports.closeTypeAheadAndRunCommand = function closeTypeAheadAndRunCommand(editorView, api) {
|
|
8
|
+
return function (command) {
|
|
9
|
+
var _api$typeAhead;
|
|
10
|
+
if (!editorView) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
if (api !== null && api !== void 0 && (_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && (_api$typeAhead = _api$typeAhead.actions) !== null && _api$typeAhead !== void 0 && _api$typeAhead.isOpen(editorView.state)) {
|
|
14
|
+
var _api$typeAhead2;
|
|
15
|
+
api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 || (_api$typeAhead2 = _api$typeAhead2.actions) === null || _api$typeAhead2 === void 0 || _api$typeAhead2.close({
|
|
16
|
+
attachCommand: command,
|
|
17
|
+
insertCurrentQueryAsRawText: false
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
command(editorView.state, editorView.dispatch);
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
var forceFocus = exports.forceFocus = function forceFocus(editorView, api) {
|
|
26
|
+
return function (command) {
|
|
27
|
+
var result = closeTypeAheadAndRunCommand(editorView, api)(command);
|
|
28
|
+
if (result && !editorView.hasFocus()) {
|
|
29
|
+
editorView.focus();
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -16,37 +16,13 @@ var _redo = _interopRequireDefault(require("@atlaskit/icon/core/migration/redo")
|
|
|
16
16
|
var _undo = _interopRequireDefault(require("@atlaskit/icon/core/migration/undo"));
|
|
17
17
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
18
18
|
var _commands = require("../../pm-plugins/commands");
|
|
19
|
+
var _utils = require("../../pm-plugins/utils");
|
|
19
20
|
/**
|
|
20
21
|
* @jsxRuntime classic
|
|
21
22
|
* @jsx jsx
|
|
22
23
|
*/
|
|
23
24
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
24
25
|
|
|
25
|
-
var closeTypeAheadAndRunCommand = function closeTypeAheadAndRunCommand(editorView, api) {
|
|
26
|
-
return function (command) {
|
|
27
|
-
var _api$typeAhead;
|
|
28
|
-
if (!editorView) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (api !== null && api !== void 0 && (_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && (_api$typeAhead = _api$typeAhead.actions) !== null && _api$typeAhead !== void 0 && _api$typeAhead.isOpen(editorView.state)) {
|
|
32
|
-
var _api$typeAhead2;
|
|
33
|
-
api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 || (_api$typeAhead2 = _api$typeAhead2.actions) === null || _api$typeAhead2 === void 0 || _api$typeAhead2.close({
|
|
34
|
-
attachCommand: command,
|
|
35
|
-
insertCurrentQueryAsRawText: false
|
|
36
|
-
});
|
|
37
|
-
} else {
|
|
38
|
-
command(editorView.state, editorView.dispatch);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
var forceFocus = function forceFocus(editorView, api) {
|
|
43
|
-
return function (command) {
|
|
44
|
-
closeTypeAheadAndRunCommand(editorView, api)(command);
|
|
45
|
-
if (!editorView.hasFocus()) {
|
|
46
|
-
editorView.focus();
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
26
|
var ToolbarUndoRedo = exports.ToolbarUndoRedo = function ToolbarUndoRedo(_ref) {
|
|
51
27
|
var disabled = _ref.disabled,
|
|
52
28
|
isReducedSpacing = _ref.isReducedSpacing,
|
|
@@ -56,10 +32,10 @@ var ToolbarUndoRedo = exports.ToolbarUndoRedo = function ToolbarUndoRedo(_ref) {
|
|
|
56
32
|
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['history']),
|
|
57
33
|
historyState = _useSharedPluginState.historyState;
|
|
58
34
|
var handleUndo = function handleUndo() {
|
|
59
|
-
forceFocus(editorView, api)(_commands.undoFromToolbar);
|
|
35
|
+
(0, _utils.forceFocus)(editorView, api)(_commands.undoFromToolbar);
|
|
60
36
|
};
|
|
61
37
|
var handleRedo = function handleRedo() {
|
|
62
|
-
forceFocus(editorView, api)(_commands.redoFromToolbar);
|
|
38
|
+
(0, _utils.forceFocus)(editorView, api)(_commands.redoFromToolbar);
|
|
63
39
|
};
|
|
64
40
|
var labelUndo = formatMessage(_messages.undoRedoMessages.undo);
|
|
65
41
|
var labelRedo = formatMessage(_messages.undoRedoMessages.redo);
|
|
@@ -10,10 +10,11 @@ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
|
10
10
|
var _history = require("@atlaskit/editor-prosemirror/history");
|
|
11
11
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
12
12
|
var _attachInputMeta = require("./pm-plugins/attach-input-meta");
|
|
13
|
+
var _enums = require("./pm-plugins/enums");
|
|
13
14
|
var _keymaps = require("./pm-plugins/keymaps");
|
|
14
15
|
var _main = require("./pm-plugins/main");
|
|
16
|
+
var _utils = require("./pm-plugins/utils");
|
|
15
17
|
var _ToolbarUndoRedo = _interopRequireDefault(require("./ui/ToolbarUndoRedo"));
|
|
16
|
-
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
17
18
|
// Ignored via go/ees005
|
|
18
19
|
// eslint-disable-next-line import/no-named-as-default
|
|
19
20
|
|
|
@@ -38,33 +39,23 @@ var undoRedoPlugin = exports.undoRedoPlugin = function undoRedoPlugin(_ref) {
|
|
|
38
39
|
name: 'undoRedoPlugin',
|
|
39
40
|
component: primaryToolbarComponent
|
|
40
41
|
});
|
|
42
|
+
var handleUndo = function handleUndo(inputSource) {
|
|
43
|
+
if (!editorViewRef.current) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return (0, _utils.forceFocus)(editorViewRef.current, api)((0, _attachInputMeta.attachInputMeta)(inputSource || _enums.InputSource.EXTERNAL)(_history.undo));
|
|
47
|
+
};
|
|
48
|
+
var handleRedo = function handleRedo(inputSource) {
|
|
49
|
+
if (!editorViewRef.current) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return (0, _utils.forceFocus)(editorViewRef.current, api)((0, _attachInputMeta.attachInputMeta)(inputSource || _enums.InputSource.EXTERNAL)(_history.redo));
|
|
53
|
+
};
|
|
41
54
|
return {
|
|
42
55
|
name: 'undoRedoPlugin',
|
|
43
56
|
actions: {
|
|
44
|
-
undo:
|
|
45
|
-
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
var _editorViewRef$curren = editorViewRef.current,
|
|
49
|
-
state = _editorViewRef$curren.state,
|
|
50
|
-
dispatch = _editorViewRef$curren.dispatch;
|
|
51
|
-
if (!inputSource) {
|
|
52
|
-
return (0, _history.undo)(state, dispatch);
|
|
53
|
-
}
|
|
54
|
-
return (0, _attachInputMeta.attachInputMeta)(inputSource)(_history.undo)(state, dispatch);
|
|
55
|
-
},
|
|
56
|
-
redo: function redo(inputSource) {
|
|
57
|
-
if (!editorViewRef.current) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
var _editorViewRef$curren2 = editorViewRef.current,
|
|
61
|
-
state = _editorViewRef$curren2.state,
|
|
62
|
-
dispatch = _editorViewRef$curren2.dispatch;
|
|
63
|
-
if (!inputSource) {
|
|
64
|
-
return (0, _history.redo)(state, dispatch);
|
|
65
|
-
}
|
|
66
|
-
return (0, _attachInputMeta.attachInputMeta)(inputSource)(_history.redo)(state, dispatch);
|
|
67
|
-
}
|
|
57
|
+
undo: handleUndo,
|
|
58
|
+
redo: handleRedo
|
|
68
59
|
},
|
|
69
60
|
pmPlugins: function pmPlugins() {
|
|
70
61
|
var plugins = [{
|
|
@@ -2,6 +2,6 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
|
2
2
|
export let InputSource = function (InputSource) {
|
|
3
3
|
InputSource[InputSource["TOOLBAR"] = INPUT_METHOD.TOOLBAR] = "TOOLBAR";
|
|
4
4
|
InputSource[InputSource["KEYBOARD"] = INPUT_METHOD.KEYBOARD] = "KEYBOARD";
|
|
5
|
-
InputSource[InputSource["
|
|
5
|
+
InputSource[InputSource["EXTERNAL"] = INPUT_METHOD.EXTERNAL] = "EXTERNAL";
|
|
6
6
|
return InputSource;
|
|
7
7
|
}({});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const closeTypeAheadAndRunCommand = (editorView, api) => command => {
|
|
2
|
+
var _api$typeAhead, _api$typeAhead$action;
|
|
3
|
+
if (!editorView) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
if (api !== null && api !== void 0 && (_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && (_api$typeAhead$action = _api$typeAhead.actions) !== null && _api$typeAhead$action !== void 0 && _api$typeAhead$action.isOpen(editorView.state)) {
|
|
7
|
+
var _api$typeAhead2, _api$typeAhead2$actio;
|
|
8
|
+
api === null || api === void 0 ? void 0 : (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : (_api$typeAhead2$actio = _api$typeAhead2.actions) === null || _api$typeAhead2$actio === void 0 ? void 0 : _api$typeAhead2$actio.close({
|
|
9
|
+
attachCommand: command,
|
|
10
|
+
insertCurrentQueryAsRawText: false
|
|
11
|
+
});
|
|
12
|
+
} else {
|
|
13
|
+
command(editorView.state, editorView.dispatch);
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
};
|
|
17
|
+
export const forceFocus = (editorView, api) => command => {
|
|
18
|
+
const result = closeTypeAheadAndRunCommand(editorView, api)(command);
|
|
19
|
+
if (result && !editorView.hasFocus()) {
|
|
20
|
+
editorView.focus();
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
@@ -14,27 +14,7 @@ import RedoIcon from '@atlaskit/icon/core/migration/redo';
|
|
|
14
14
|
import UndoIcon from '@atlaskit/icon/core/migration/undo';
|
|
15
15
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
16
16
|
import { redoFromToolbar, undoFromToolbar } from '../../pm-plugins/commands';
|
|
17
|
-
|
|
18
|
-
var _api$typeAhead, _api$typeAhead$action;
|
|
19
|
-
if (!editorView) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (api !== null && api !== void 0 && (_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && (_api$typeAhead$action = _api$typeAhead.actions) !== null && _api$typeAhead$action !== void 0 && _api$typeAhead$action.isOpen(editorView.state)) {
|
|
23
|
-
var _api$typeAhead2, _api$typeAhead2$actio;
|
|
24
|
-
api === null || api === void 0 ? void 0 : (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : (_api$typeAhead2$actio = _api$typeAhead2.actions) === null || _api$typeAhead2$actio === void 0 ? void 0 : _api$typeAhead2$actio.close({
|
|
25
|
-
attachCommand: command,
|
|
26
|
-
insertCurrentQueryAsRawText: false
|
|
27
|
-
});
|
|
28
|
-
} else {
|
|
29
|
-
command(editorView.state, editorView.dispatch);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const forceFocus = (editorView, api) => command => {
|
|
33
|
-
closeTypeAheadAndRunCommand(editorView, api)(command);
|
|
34
|
-
if (!editorView.hasFocus()) {
|
|
35
|
-
editorView.focus();
|
|
36
|
-
}
|
|
37
|
-
};
|
|
17
|
+
import { forceFocus } from '../../pm-plugins/utils';
|
|
38
18
|
export const ToolbarUndoRedo = ({
|
|
39
19
|
disabled,
|
|
40
20
|
isReducedSpacing,
|
|
@@ -3,9 +3,10 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
3
3
|
import { redo, undo } from '@atlaskit/editor-prosemirror/history';
|
|
4
4
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
5
5
|
import { attachInputMeta } from './pm-plugins/attach-input-meta';
|
|
6
|
+
import { InputSource } from './pm-plugins/enums';
|
|
6
7
|
import { keymapPlugin } from './pm-plugins/keymaps';
|
|
7
8
|
import { createPlugin } from './pm-plugins/main';
|
|
8
|
-
|
|
9
|
+
import { forceFocus } from './pm-plugins/utils';
|
|
9
10
|
// Ignored via go/ees005
|
|
10
11
|
// eslint-disable-next-line import/no-named-as-default
|
|
11
12
|
import ToolbarUndoRedo from './ui/ToolbarUndoRedo';
|
|
@@ -32,35 +33,23 @@ export const undoRedoPlugin = ({
|
|
|
32
33
|
name: 'undoRedoPlugin',
|
|
33
34
|
component: primaryToolbarComponent
|
|
34
35
|
});
|
|
36
|
+
const handleUndo = inputSource => {
|
|
37
|
+
if (!editorViewRef.current) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return forceFocus(editorViewRef.current, api)(attachInputMeta(inputSource || InputSource.EXTERNAL)(undo));
|
|
41
|
+
};
|
|
42
|
+
const handleRedo = inputSource => {
|
|
43
|
+
if (!editorViewRef.current) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return forceFocus(editorViewRef.current, api)(attachInputMeta(inputSource || InputSource.EXTERNAL)(redo));
|
|
47
|
+
};
|
|
35
48
|
return {
|
|
36
49
|
name: 'undoRedoPlugin',
|
|
37
50
|
actions: {
|
|
38
|
-
undo:
|
|
39
|
-
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
const {
|
|
43
|
-
state,
|
|
44
|
-
dispatch
|
|
45
|
-
} = editorViewRef.current;
|
|
46
|
-
if (!inputSource) {
|
|
47
|
-
return undo(state, dispatch);
|
|
48
|
-
}
|
|
49
|
-
return attachInputMeta(inputSource)(undo)(state, dispatch);
|
|
50
|
-
},
|
|
51
|
-
redo: inputSource => {
|
|
52
|
-
if (!editorViewRef.current) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
const {
|
|
56
|
-
state,
|
|
57
|
-
dispatch
|
|
58
|
-
} = editorViewRef.current;
|
|
59
|
-
if (!inputSource) {
|
|
60
|
-
return redo(state, dispatch);
|
|
61
|
-
}
|
|
62
|
-
return attachInputMeta(inputSource)(redo)(state, dispatch);
|
|
63
|
-
}
|
|
51
|
+
undo: handleUndo,
|
|
52
|
+
redo: handleRedo
|
|
64
53
|
},
|
|
65
54
|
pmPlugins() {
|
|
66
55
|
const plugins = [{
|
|
@@ -2,6 +2,6 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
|
2
2
|
export var InputSource = function (InputSource) {
|
|
3
3
|
InputSource[InputSource["TOOLBAR"] = INPUT_METHOD.TOOLBAR] = "TOOLBAR";
|
|
4
4
|
InputSource[InputSource["KEYBOARD"] = INPUT_METHOD.KEYBOARD] = "KEYBOARD";
|
|
5
|
-
InputSource[InputSource["
|
|
5
|
+
InputSource[InputSource["EXTERNAL"] = INPUT_METHOD.EXTERNAL] = "EXTERNAL";
|
|
6
6
|
return InputSource;
|
|
7
7
|
}({});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export var closeTypeAheadAndRunCommand = function closeTypeAheadAndRunCommand(editorView, api) {
|
|
2
|
+
return function (command) {
|
|
3
|
+
var _api$typeAhead;
|
|
4
|
+
if (!editorView) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
if (api !== null && api !== void 0 && (_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && (_api$typeAhead = _api$typeAhead.actions) !== null && _api$typeAhead !== void 0 && _api$typeAhead.isOpen(editorView.state)) {
|
|
8
|
+
var _api$typeAhead2;
|
|
9
|
+
api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 || (_api$typeAhead2 = _api$typeAhead2.actions) === null || _api$typeAhead2 === void 0 || _api$typeAhead2.close({
|
|
10
|
+
attachCommand: command,
|
|
11
|
+
insertCurrentQueryAsRawText: false
|
|
12
|
+
});
|
|
13
|
+
} else {
|
|
14
|
+
command(editorView.state, editorView.dispatch);
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export var forceFocus = function forceFocus(editorView, api) {
|
|
20
|
+
return function (command) {
|
|
21
|
+
var result = closeTypeAheadAndRunCommand(editorView, api)(command);
|
|
22
|
+
if (result && !editorView.hasFocus()) {
|
|
23
|
+
editorView.focus();
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -14,31 +14,7 @@ import RedoIcon from '@atlaskit/icon/core/migration/redo';
|
|
|
14
14
|
import UndoIcon from '@atlaskit/icon/core/migration/undo';
|
|
15
15
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
16
16
|
import { redoFromToolbar, undoFromToolbar } from '../../pm-plugins/commands';
|
|
17
|
-
|
|
18
|
-
return function (command) {
|
|
19
|
-
var _api$typeAhead;
|
|
20
|
-
if (!editorView) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
if (api !== null && api !== void 0 && (_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && (_api$typeAhead = _api$typeAhead.actions) !== null && _api$typeAhead !== void 0 && _api$typeAhead.isOpen(editorView.state)) {
|
|
24
|
-
var _api$typeAhead2;
|
|
25
|
-
api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 || (_api$typeAhead2 = _api$typeAhead2.actions) === null || _api$typeAhead2 === void 0 || _api$typeAhead2.close({
|
|
26
|
-
attachCommand: command,
|
|
27
|
-
insertCurrentQueryAsRawText: false
|
|
28
|
-
});
|
|
29
|
-
} else {
|
|
30
|
-
command(editorView.state, editorView.dispatch);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
var forceFocus = function forceFocus(editorView, api) {
|
|
35
|
-
return function (command) {
|
|
36
|
-
closeTypeAheadAndRunCommand(editorView, api)(command);
|
|
37
|
-
if (!editorView.hasFocus()) {
|
|
38
|
-
editorView.focus();
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
};
|
|
17
|
+
import { forceFocus } from '../../pm-plugins/utils';
|
|
42
18
|
export var ToolbarUndoRedo = function ToolbarUndoRedo(_ref) {
|
|
43
19
|
var disabled = _ref.disabled,
|
|
44
20
|
isReducedSpacing = _ref.isReducedSpacing,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
-
import { redo
|
|
3
|
+
import { redo, undo } from '@atlaskit/editor-prosemirror/history';
|
|
4
4
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
5
5
|
import { attachInputMeta } from './pm-plugins/attach-input-meta';
|
|
6
|
+
import { InputSource } from './pm-plugins/enums';
|
|
6
7
|
import { keymapPlugin } from './pm-plugins/keymaps';
|
|
7
8
|
import { createPlugin } from './pm-plugins/main';
|
|
8
|
-
|
|
9
|
+
import { forceFocus } from './pm-plugins/utils';
|
|
9
10
|
// Ignored via go/ees005
|
|
10
11
|
// eslint-disable-next-line import/no-named-as-default
|
|
11
12
|
import ToolbarUndoRedo from './ui/ToolbarUndoRedo';
|
|
@@ -30,33 +31,23 @@ export var undoRedoPlugin = function undoRedoPlugin(_ref) {
|
|
|
30
31
|
name: 'undoRedoPlugin',
|
|
31
32
|
component: primaryToolbarComponent
|
|
32
33
|
});
|
|
34
|
+
var handleUndo = function handleUndo(inputSource) {
|
|
35
|
+
if (!editorViewRef.current) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return forceFocus(editorViewRef.current, api)(attachInputMeta(inputSource || InputSource.EXTERNAL)(undo));
|
|
39
|
+
};
|
|
40
|
+
var handleRedo = function handleRedo(inputSource) {
|
|
41
|
+
if (!editorViewRef.current) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return forceFocus(editorViewRef.current, api)(attachInputMeta(inputSource || InputSource.EXTERNAL)(redo));
|
|
45
|
+
};
|
|
33
46
|
return {
|
|
34
47
|
name: 'undoRedoPlugin',
|
|
35
48
|
actions: {
|
|
36
|
-
undo:
|
|
37
|
-
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
var _editorViewRef$curren = editorViewRef.current,
|
|
41
|
-
state = _editorViewRef$curren.state,
|
|
42
|
-
dispatch = _editorViewRef$curren.dispatch;
|
|
43
|
-
if (!inputSource) {
|
|
44
|
-
return _undo(state, dispatch);
|
|
45
|
-
}
|
|
46
|
-
return attachInputMeta(inputSource)(_undo)(state, dispatch);
|
|
47
|
-
},
|
|
48
|
-
redo: function redo(inputSource) {
|
|
49
|
-
if (!editorViewRef.current) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
var _editorViewRef$curren2 = editorViewRef.current,
|
|
53
|
-
state = _editorViewRef$curren2.state,
|
|
54
|
-
dispatch = _editorViewRef$curren2.dispatch;
|
|
55
|
-
if (!inputSource) {
|
|
56
|
-
return _redo(state, dispatch);
|
|
57
|
-
}
|
|
58
|
-
return attachInputMeta(inputSource)(_redo)(state, dispatch);
|
|
59
|
-
}
|
|
49
|
+
undo: handleUndo,
|
|
50
|
+
redo: handleRedo
|
|
60
51
|
},
|
|
61
52
|
pmPlugins: function pmPlugins() {
|
|
62
53
|
var plugins = [{
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Command, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
import { UndoRedoPlugin } from '../undoRedoPluginType';
|
|
4
|
+
export declare const closeTypeAheadAndRunCommand: (editorView: EditorView, api: ExtractInjectionAPI<UndoRedoPlugin> | undefined) => (command: Command) => boolean;
|
|
5
|
+
export declare const forceFocus: (editorView: EditorView, api: ExtractInjectionAPI<UndoRedoPlugin> | undefined) => (command: Command) => boolean;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Command, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
import { UndoRedoPlugin } from '../undoRedoPluginType';
|
|
4
|
+
export declare const closeTypeAheadAndRunCommand: (editorView: EditorView, api: ExtractInjectionAPI<UndoRedoPlugin> | undefined) => (command: Command) => boolean;
|
|
5
|
+
export declare const forceFocus: (editorView: EditorView, api: ExtractInjectionAPI<UndoRedoPlugin> | undefined) => (command: Command) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-undo-redo",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
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.
|
|
36
|
+
"@atlaskit/editor-common": "^102.13.0",
|
|
37
37
|
"@atlaskit/editor-plugin-history": "^2.0.0",
|
|
38
38
|
"@atlaskit/editor-plugin-primary-toolbar": "^3.1.0",
|
|
39
|
-
"@atlaskit/editor-plugin-type-ahead": "^2.
|
|
39
|
+
"@atlaskit/editor-plugin-type-ahead": "^2.2.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": "^4.
|
|
43
|
+
"@atlaskit/tmp-editor-statsig": "^4.2.0",
|
|
44
44
|
"@babel/runtime": "^7.0.0",
|
|
45
45
|
"@emotion/react": "^11.7.1"
|
|
46
46
|
},
|