@atlaskit/editor-core 188.11.4 → 188.12.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/labs/next/presets/universal.js +3 -2
  3. package/dist/cjs/plugins/index.js +0 -7
  4. package/dist/cjs/plugins/undo-redo/index.js +7 -16
  5. package/dist/cjs/plugins/undo-redo/ui/ToolbarUndoRedo/index.js +59 -75
  6. package/dist/cjs/version-wrapper.js +1 -1
  7. package/dist/es2019/labs/next/presets/universal.js +2 -1
  8. package/dist/es2019/plugins/index.js +0 -1
  9. package/dist/es2019/plugins/undo-redo/index.js +6 -17
  10. package/dist/es2019/plugins/undo-redo/ui/ToolbarUndoRedo/index.js +60 -61
  11. package/dist/es2019/version-wrapper.js +1 -1
  12. package/dist/esm/labs/next/presets/universal.js +2 -1
  13. package/dist/esm/plugins/index.js +0 -1
  14. package/dist/esm/plugins/undo-redo/index.js +6 -16
  15. package/dist/esm/plugins/undo-redo/ui/ToolbarUndoRedo/index.js +56 -74
  16. package/dist/esm/version-wrapper.js +1 -1
  17. package/dist/types/plugins/index.d.ts +0 -1
  18. package/dist/types/plugins/undo-redo/types.d.ts +2 -1
  19. package/dist/types/plugins/undo-redo/ui/ToolbarUndoRedo/index.d.ts +2 -6
  20. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  21. package/dist/types-ts4.5/plugins/undo-redo/types.d.ts +3 -1
  22. package/dist/types-ts4.5/plugins/undo-redo/ui/ToolbarUndoRedo/index.d.ts +2 -6
  23. package/package.json +4 -3
  24. package/dist/cjs/plugins/history/actions.js +0 -10
  25. package/dist/cjs/plugins/history/index.js +0 -75
  26. package/dist/cjs/plugins/history/pm-history-types.js +0 -5
  27. package/dist/cjs/plugins/history/reducer.js +0 -18
  28. package/dist/cjs/plugins/history/types.js +0 -5
  29. package/dist/cjs/plugins/history/utils.js +0 -19
  30. package/dist/es2019/plugins/history/actions.js +0 -4
  31. package/dist/es2019/plugins/history/index.js +0 -61
  32. package/dist/es2019/plugins/history/pm-history-types.js +0 -1
  33. package/dist/es2019/plugins/history/reducer.js +0 -12
  34. package/dist/es2019/plugins/history/types.js +0 -1
  35. package/dist/es2019/plugins/history/utils.js +0 -11
  36. package/dist/esm/plugins/history/actions.js +0 -4
  37. package/dist/esm/plugins/history/index.js +0 -68
  38. package/dist/esm/plugins/history/pm-history-types.js +0 -1
  39. package/dist/esm/plugins/history/reducer.js +0 -12
  40. package/dist/esm/plugins/history/types.js +0 -1
  41. package/dist/esm/plugins/history/utils.js +0 -13
  42. package/dist/types/plugins/history/actions.d.ts +0 -8
  43. package/dist/types/plugins/history/index.d.ts +0 -13
  44. package/dist/types/plugins/history/pm-history-types.d.ts +0 -17
  45. package/dist/types/plugins/history/reducer.d.ts +0 -4
  46. package/dist/types/plugins/history/types.d.ts +0 -4
  47. package/dist/types/plugins/history/utils.d.ts +0 -4
  48. package/dist/types-ts4.5/plugins/history/actions.d.ts +0 -8
  49. package/dist/types-ts4.5/plugins/history/index.d.ts +0 -13
  50. package/dist/types-ts4.5/plugins/history/pm-history-types.d.ts +0 -17
  51. package/dist/types-ts4.5/plugins/history/reducer.d.ts +0 -4
  52. package/dist/types-ts4.5/plugins/history/types.d.ts +0 -4
  53. package/dist/types-ts4.5/plugins/history/utils.d.ts +0 -4
@@ -1,16 +1,9 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
7
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
8
1
  /** @jsx jsx */
9
- import { PureComponent } from 'react';
10
2
  import { jsx } from '@emotion/react';
11
3
  import { injectIntl } from 'react-intl-next';
12
4
  import UndoIcon from '@atlaskit/icon/glyph/undo';
13
5
  import RedoIcon from '@atlaskit/icon/glyph/redo';
6
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
14
7
  import { undo as undoKeymap, redo as redoKeymap, ToolTipContent, tooltip } from '../../../../keymaps';
15
8
  import { separatorStyles, buttonGroupStyle } from '@atlaskit/editor-common/styles';
16
9
  import ToolbarButton, { TOOLBAR_BUTTON } from '../../../../ui/ToolbarButton';
@@ -42,70 +35,59 @@ var forceFocus = function forceFocus(editorView, api) {
42
35
  }
43
36
  };
44
37
  };
45
- export var ToolbarUndoRedo = /*#__PURE__*/function (_PureComponent) {
46
- _inherits(ToolbarUndoRedo, _PureComponent);
47
- var _super = _createSuper(ToolbarUndoRedo);
48
- function ToolbarUndoRedo() {
49
- _classCallCheck(this, ToolbarUndoRedo);
50
- return _super.apply(this, arguments);
51
- }
52
- _createClass(ToolbarUndoRedo, [{
53
- key: "render",
54
- value: function render() {
55
- var _this$props = this.props,
56
- disabled = _this$props.disabled,
57
- isReducedSpacing = _this$props.isReducedSpacing,
58
- historyState = _this$props.historyState,
59
- editorView = _this$props.editorView,
60
- api = _this$props.api,
61
- formatMessage = _this$props.intl.formatMessage;
62
- var handleUndo = function handleUndo() {
63
- forceFocus(editorView, api)(undoFromToolbar);
64
- };
65
- var handleRedo = function handleRedo() {
66
- forceFocus(editorView, api)(redoFromToolbar);
67
- };
68
- var labelUndo = formatMessage(undoRedoMessages.undo);
69
- var labelRedo = formatMessage(undoRedoMessages.redo);
70
- var canUndo = historyState.canUndo,
71
- canRedo = historyState.canRedo;
72
- return jsx("span", {
73
- css: buttonGroupStyle
74
- }, jsx(ToolbarButton, {
75
- buttonId: TOOLBAR_BUTTON.UNDO,
76
- spacing: isReducedSpacing ? 'none' : 'default',
77
- onClick: handleUndo,
78
- disabled: !canUndo || disabled,
79
- "aria-label": tooltip(undoKeymap, labelUndo),
80
- "aria-keyshortcuts": getAriaKeyshortcuts(undoKeymap),
81
- title: jsx(ToolTipContent, {
82
- description: labelUndo,
83
- keymap: undoKeymap
84
- }),
85
- iconBefore: jsx(UndoIcon, {
86
- label: ""
87
- }),
88
- testId: "ak-editor-toolbar-button-undo"
89
- }), jsx(ToolbarButton, {
90
- spacing: isReducedSpacing ? 'none' : 'default',
91
- buttonId: TOOLBAR_BUTTON.REDO,
92
- onClick: handleRedo,
93
- disabled: !canRedo || disabled,
94
- title: jsx(ToolTipContent, {
95
- description: labelRedo,
96
- keymap: redoKeymap
97
- }),
98
- iconBefore: jsx(RedoIcon, {
99
- label: ""
100
- }),
101
- testId: "ak-editor-toolbar-button-redo",
102
- "aria-label": tooltip(redoKeymap, labelRedo),
103
- "aria-keyshortcuts": getAriaKeyshortcuts(redoKeymap)
104
- }), jsx("span", {
105
- css: separatorStyles
106
- }));
107
- }
108
- }]);
109
- return ToolbarUndoRedo;
110
- }(PureComponent);
38
+ export var ToolbarUndoRedo = function ToolbarUndoRedo(_ref) {
39
+ var disabled = _ref.disabled,
40
+ isReducedSpacing = _ref.isReducedSpacing,
41
+ editorView = _ref.editorView,
42
+ api = _ref.api,
43
+ formatMessage = _ref.intl.formatMessage;
44
+ var _useSharedPluginState = useSharedPluginState(api, ['history']),
45
+ historyState = _useSharedPluginState.historyState;
46
+ var handleUndo = function handleUndo() {
47
+ forceFocus(editorView, api)(undoFromToolbar);
48
+ };
49
+ var handleRedo = function handleRedo() {
50
+ forceFocus(editorView, api)(redoFromToolbar);
51
+ };
52
+ var labelUndo = formatMessage(undoRedoMessages.undo);
53
+ var labelRedo = formatMessage(undoRedoMessages.redo);
54
+ var _ref2 = historyState !== null && historyState !== void 0 ? historyState : {},
55
+ canUndo = _ref2.canUndo,
56
+ canRedo = _ref2.canRedo;
57
+ return jsx("span", {
58
+ css: buttonGroupStyle
59
+ }, jsx(ToolbarButton, {
60
+ buttonId: TOOLBAR_BUTTON.UNDO,
61
+ spacing: isReducedSpacing ? 'none' : 'default',
62
+ onClick: handleUndo,
63
+ disabled: !canUndo || disabled,
64
+ "aria-label": tooltip(undoKeymap, labelUndo),
65
+ "aria-keyshortcuts": getAriaKeyshortcuts(undoKeymap),
66
+ title: jsx(ToolTipContent, {
67
+ description: labelUndo,
68
+ keymap: undoKeymap
69
+ }),
70
+ iconBefore: jsx(UndoIcon, {
71
+ label: ""
72
+ }),
73
+ testId: "ak-editor-toolbar-button-undo"
74
+ }), jsx(ToolbarButton, {
75
+ spacing: isReducedSpacing ? 'none' : 'default',
76
+ buttonId: TOOLBAR_BUTTON.REDO,
77
+ onClick: handleRedo,
78
+ disabled: !canRedo || disabled,
79
+ title: jsx(ToolTipContent, {
80
+ description: labelRedo,
81
+ keymap: redoKeymap
82
+ }),
83
+ iconBefore: jsx(RedoIcon, {
84
+ label: ""
85
+ }),
86
+ testId: "ak-editor-toolbar-button-redo",
87
+ "aria-label": tooltip(redoKeymap, labelRedo),
88
+ "aria-keyshortcuts": getAriaKeyshortcuts(redoKeymap)
89
+ }), jsx("span", {
90
+ css: separatorStyles
91
+ }));
92
+ };
111
93
  export default injectIntl(ToolbarUndoRedo);
@@ -1,5 +1,5 @@
1
1
  export var name = "@atlaskit/editor-core";
2
- export var version = "188.11.4";
2
+ export var version = "188.12.0";
3
3
  export var nextMajorVersion = function nextMajorVersion() {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -24,7 +24,6 @@ export { default as annotationPlugin } from './annotation';
24
24
  export { default as analyticsPlugin } from './analytics';
25
25
  export { default as customAutoformatPlugin } from './custom-autoformat';
26
26
  export { default as feedbackDialogPlugin } from './feedback-dialog';
27
- export { default as historyPlugin } from './history';
28
27
  export { default as expandPlugin, isExpandInsertionEnabled } from './expand';
29
28
  export { default as mobileDimensionsPlugin } from './mobile-dimensions';
30
29
  export { default as findReplacePlugin } from './find-replace';
@@ -1,5 +1,6 @@
1
1
  import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
2
2
  import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
3
+ import type { HistoryPlugin } from '@atlaskit/editor-plugin-history';
3
4
  export type UndoRedoPlugin = NextEditorPlugin<'undoRedoPlugin', {
4
- dependencies: [TypeAheadPlugin];
5
+ dependencies: [TypeAheadPlugin, HistoryPlugin];
5
6
  }>;
@@ -1,9 +1,8 @@
1
+ /// <reference types="react" />
1
2
  /** @jsx jsx */
2
- import { PureComponent } from 'react';
3
3
  import { jsx } from '@emotion/react';
4
4
  import type { WrappedComponentProps } from 'react-intl-next';
5
5
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
- import type { HistoryPluginState } from '../../../history/types';
7
6
  import type { UndoRedoPlugin } from '../../types';
8
7
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
9
8
  export interface Props {
@@ -11,13 +10,10 @@ export interface Props {
11
10
  redoDisabled?: boolean;
12
11
  disabled?: boolean;
13
12
  isReducedSpacing?: boolean;
14
- historyState: HistoryPluginState;
15
13
  editorView: EditorView;
16
14
  api: ExtractInjectionAPI<UndoRedoPlugin> | undefined;
17
15
  }
18
- export declare class ToolbarUndoRedo extends PureComponent<Props & WrappedComponentProps> {
19
- render(): jsx.JSX.Element;
20
- }
16
+ export declare const ToolbarUndoRedo: ({ disabled, isReducedSpacing, editorView, api, intl: { formatMessage }, }: Props & WrappedComponentProps) => jsx.JSX.Element;
21
17
  declare const _default: import("react").FC<import("react-intl-next").WithIntlProps<Props & WrappedComponentProps<"intl">>> & {
22
18
  WrappedComponent: import("react").ComponentType<Props & WrappedComponentProps<"intl">>;
23
19
  };
@@ -24,7 +24,6 @@ export { default as annotationPlugin } from './annotation';
24
24
  export { default as analyticsPlugin } from './analytics';
25
25
  export { default as customAutoformatPlugin } from './custom-autoformat';
26
26
  export { default as feedbackDialogPlugin } from './feedback-dialog';
27
- export { default as historyPlugin } from './history';
28
27
  export { default as expandPlugin, isExpandInsertionEnabled } from './expand';
29
28
  export { default as mobileDimensionsPlugin } from './mobile-dimensions';
30
29
  export { default as findReplacePlugin } from './find-replace';
@@ -1,7 +1,9 @@
1
1
  import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
2
2
  import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
3
+ import type { HistoryPlugin } from '@atlaskit/editor-plugin-history';
3
4
  export type UndoRedoPlugin = NextEditorPlugin<'undoRedoPlugin', {
4
5
  dependencies: [
5
- TypeAheadPlugin
6
+ TypeAheadPlugin,
7
+ HistoryPlugin
6
8
  ];
7
9
  }>;
@@ -1,9 +1,8 @@
1
+ /// <reference types="react" />
1
2
  /** @jsx jsx */
2
- import { PureComponent } from 'react';
3
3
  import { jsx } from '@emotion/react';
4
4
  import type { WrappedComponentProps } from 'react-intl-next';
5
5
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
- import type { HistoryPluginState } from '../../../history/types';
7
6
  import type { UndoRedoPlugin } from '../../types';
8
7
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
9
8
  export interface Props {
@@ -11,13 +10,10 @@ export interface Props {
11
10
  redoDisabled?: boolean;
12
11
  disabled?: boolean;
13
12
  isReducedSpacing?: boolean;
14
- historyState: HistoryPluginState;
15
13
  editorView: EditorView;
16
14
  api: ExtractInjectionAPI<UndoRedoPlugin> | undefined;
17
15
  }
18
- export declare class ToolbarUndoRedo extends PureComponent<Props & WrappedComponentProps> {
19
- render(): jsx.JSX.Element;
20
- }
16
+ export declare const ToolbarUndoRedo: ({ disabled, isReducedSpacing, editorView, api, intl: { formatMessage }, }: Props & WrappedComponentProps) => jsx.JSX.Element;
21
17
  declare const _default: import("react").FC<import("react-intl-next").WithIntlProps<Props & WrappedComponentProps<"intl">>> & {
22
18
  WrappedComponent: import("react").ComponentType<Props & WrappedComponentProps<"intl">>;
23
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "188.11.4",
3
+ "version": "188.12.0",
4
4
  "description": "A package contains Atlassian editor core functionality",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -80,6 +80,7 @@
80
80
  "@atlaskit/editor-plugin-grid": "^0.3.0",
81
81
  "@atlaskit/editor-plugin-guideline": "^0.5.0",
82
82
  "@atlaskit/editor-plugin-help-dialog": "^0.2.0",
83
+ "@atlaskit/editor-plugin-history": "^0.1.0",
83
84
  "@atlaskit/editor-plugin-hyperlink": "^0.5.0",
84
85
  "@atlaskit/editor-plugin-image-upload": "^0.2.0",
85
86
  "@atlaskit/editor-plugin-list": "^1.3.0",
@@ -106,7 +107,7 @@
106
107
  "@atlaskit/form": "^8.11.0",
107
108
  "@atlaskit/icon": "^21.12.0",
108
109
  "@atlaskit/logo": "^13.14.0",
109
- "@atlaskit/media-card": "^77.1.0",
110
+ "@atlaskit/media-card": "^77.2.0",
110
111
  "@atlaskit/media-client": "^24.0.0",
111
112
  "@atlaskit/media-common": "^9.0.0",
112
113
  "@atlaskit/mention": "^22.1.0",
@@ -116,7 +117,7 @@
116
117
  "@atlaskit/radio": "^5.6.0",
117
118
  "@atlaskit/section-message": "^6.4.0",
118
119
  "@atlaskit/select": "^16.7.0",
119
- "@atlaskit/smart-card": "^26.35.0",
120
+ "@atlaskit/smart-card": "^26.36.0",
120
121
  "@atlaskit/smart-user-picker": "^6.3.0",
121
122
  "@atlaskit/spinner": "^15.6.0",
122
123
  "@atlaskit/tabs": "^13.4.0",
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.HistoryActionTypes = void 0;
7
- var HistoryActionTypes = exports.HistoryActionTypes = /*#__PURE__*/function (HistoryActionTypes) {
8
- HistoryActionTypes["UPDATE"] = "UPDATE";
9
- return HistoryActionTypes;
10
- }({});
@@ -1,75 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.historyPluginKey = exports.default = void 0;
8
- var _pluginStateFactory = require("../../utils/plugin-state-factory");
9
- var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
- var _state = require("@atlaskit/editor-prosemirror/state");
11
- var _reducer = _interopRequireDefault(require("./reducer"));
12
- var _actions = require("./actions");
13
- var _utils = require("./utils");
14
- /**
15
- * Plugin that keeps track of whether undo and redo are currently available
16
- * This is needed so we can enable/disable controls appropriately
17
- *
18
- * Actual undo/redo functionality is handled by prosemirror-history:
19
- * https://github.com/ProseMirror/prosemirror-history
20
- */
21
-
22
- var historyPluginKey = exports.historyPluginKey = new _state.PluginKey('historyPlugin');
23
- var getInitialState = function getInitialState() {
24
- return {
25
- canUndo: false,
26
- canRedo: false
27
- };
28
- };
29
- var _pluginFactory = (0, _pluginStateFactory.pluginFactory)(historyPluginKey, _reducer.default),
30
- createPluginState = _pluginFactory.createPluginState,
31
- getPluginState = _pluginFactory.getPluginState;
32
- var createPlugin = function createPlugin(dispatch) {
33
- return new _safePlugin.SafePlugin({
34
- state: createPluginState(dispatch, getInitialState),
35
- key: historyPluginKey,
36
- appendTransaction: function appendTransaction(transactions, oldState, newState) {
37
- if (transactions.find(function (tr) {
38
- return tr.docChanged && tr.getMeta('addToHistory') !== false;
39
- })) {
40
- var pmHistoryPluginState = (0, _utils.getPmHistoryPluginState)(newState);
41
- if (!pmHistoryPluginState) {
42
- return;
43
- }
44
- var canUndo = pmHistoryPluginState.done.eventCount > 0;
45
- var canRedo = pmHistoryPluginState.undone.eventCount > 0;
46
- var _getPluginState = getPluginState(newState),
47
- prevCanUndo = _getPluginState.canUndo,
48
- prevCanRedo = _getPluginState.canRedo;
49
- if (canUndo !== prevCanUndo || canRedo !== prevCanRedo) {
50
- var action = {
51
- type: _actions.HistoryActionTypes.UPDATE,
52
- canUndo: canUndo,
53
- canRedo: canRedo
54
- };
55
- return newState.tr.setMeta(historyPluginKey, action);
56
- }
57
- }
58
- }
59
- });
60
- };
61
- var historyPlugin = function historyPlugin() {
62
- return {
63
- name: 'history',
64
- pmPlugins: function pmPlugins() {
65
- return [{
66
- name: 'history',
67
- plugin: function plugin(_ref) {
68
- var dispatch = _ref.dispatch;
69
- return createPlugin(dispatch);
70
- }
71
- }];
72
- }
73
- };
74
- };
75
- var _default = exports.default = historyPlugin;
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _actions = require("./actions");
8
- var reducer = function reducer(state, action) {
9
- switch (action.type) {
10
- case _actions.HistoryActionTypes.UPDATE:
11
- return {
12
- canUndo: action.canUndo,
13
- canRedo: action.canRedo
14
- };
15
- }
16
- return state;
17
- };
18
- var _default = exports.default = reducer;
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getPmHistoryPluginState = exports.getPmHistoryPlugin = void 0;
7
- var _utils = require("@atlaskit/editor-common/utils");
8
- var getPmHistoryPlugin = exports.getPmHistoryPlugin = function getPmHistoryPlugin(state) {
9
- return state.plugins.find(function (plugin) {
10
- return plugin.key === _utils.pmHistoryPluginKey;
11
- });
12
- };
13
- var getPmHistoryPluginState = exports.getPmHistoryPluginState = function getPmHistoryPluginState(state) {
14
- var pmHistoryPlugin = getPmHistoryPlugin(state);
15
- if (!pmHistoryPlugin) {
16
- return;
17
- }
18
- return pmHistoryPlugin.getState(state);
19
- };
@@ -1,4 +0,0 @@
1
- export let HistoryActionTypes = /*#__PURE__*/function (HistoryActionTypes) {
2
- HistoryActionTypes["UPDATE"] = "UPDATE";
3
- return HistoryActionTypes;
4
- }({});
@@ -1,61 +0,0 @@
1
- import { pluginFactory } from '../../utils/plugin-state-factory';
2
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
- import reducer from './reducer';
5
- import { HistoryActionTypes } from './actions';
6
- import { getPmHistoryPluginState } from './utils';
7
- /**
8
- * Plugin that keeps track of whether undo and redo are currently available
9
- * This is needed so we can enable/disable controls appropriately
10
- *
11
- * Actual undo/redo functionality is handled by prosemirror-history:
12
- * https://github.com/ProseMirror/prosemirror-history
13
- */
14
-
15
- export const historyPluginKey = new PluginKey('historyPlugin');
16
- const getInitialState = () => ({
17
- canUndo: false,
18
- canRedo: false
19
- });
20
- const {
21
- createPluginState,
22
- getPluginState
23
- } = pluginFactory(historyPluginKey, reducer);
24
- const createPlugin = dispatch => new SafePlugin({
25
- state: createPluginState(dispatch, getInitialState),
26
- key: historyPluginKey,
27
- appendTransaction: (transactions, oldState, newState) => {
28
- if (transactions.find(tr => tr.docChanged && tr.getMeta('addToHistory') !== false)) {
29
- const pmHistoryPluginState = getPmHistoryPluginState(newState);
30
- if (!pmHistoryPluginState) {
31
- return;
32
- }
33
- const canUndo = pmHistoryPluginState.done.eventCount > 0;
34
- const canRedo = pmHistoryPluginState.undone.eventCount > 0;
35
- const {
36
- canUndo: prevCanUndo,
37
- canRedo: prevCanRedo
38
- } = getPluginState(newState);
39
- if (canUndo !== prevCanUndo || canRedo !== prevCanRedo) {
40
- const action = {
41
- type: HistoryActionTypes.UPDATE,
42
- canUndo,
43
- canRedo
44
- };
45
- return newState.tr.setMeta(historyPluginKey, action);
46
- }
47
- }
48
- }
49
- });
50
- const historyPlugin = () => ({
51
- name: 'history',
52
- pmPlugins() {
53
- return [{
54
- name: 'history',
55
- plugin: ({
56
- dispatch
57
- }) => createPlugin(dispatch)
58
- }];
59
- }
60
- });
61
- export default historyPlugin;
@@ -1 +0,0 @@
1
- export {};
@@ -1,12 +0,0 @@
1
- import { HistoryActionTypes } from './actions';
2
- const reducer = (state, action) => {
3
- switch (action.type) {
4
- case HistoryActionTypes.UPDATE:
5
- return {
6
- canUndo: action.canUndo,
7
- canRedo: action.canRedo
8
- };
9
- }
10
- return state;
11
- };
12
- export default reducer;
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
1
- import { pmHistoryPluginKey } from '@atlaskit/editor-common/utils';
2
- export const getPmHistoryPlugin = state => {
3
- return state.plugins.find(plugin => plugin.key === pmHistoryPluginKey);
4
- };
5
- export const getPmHistoryPluginState = state => {
6
- const pmHistoryPlugin = getPmHistoryPlugin(state);
7
- if (!pmHistoryPlugin) {
8
- return;
9
- }
10
- return pmHistoryPlugin.getState(state);
11
- };
@@ -1,4 +0,0 @@
1
- export var HistoryActionTypes = /*#__PURE__*/function (HistoryActionTypes) {
2
- HistoryActionTypes["UPDATE"] = "UPDATE";
3
- return HistoryActionTypes;
4
- }({});
@@ -1,68 +0,0 @@
1
- import { pluginFactory } from '../../utils/plugin-state-factory';
2
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
- import reducer from './reducer';
5
- import { HistoryActionTypes } from './actions';
6
- import { getPmHistoryPluginState } from './utils';
7
- /**
8
- * Plugin that keeps track of whether undo and redo are currently available
9
- * This is needed so we can enable/disable controls appropriately
10
- *
11
- * Actual undo/redo functionality is handled by prosemirror-history:
12
- * https://github.com/ProseMirror/prosemirror-history
13
- */
14
-
15
- export var historyPluginKey = new PluginKey('historyPlugin');
16
- var getInitialState = function getInitialState() {
17
- return {
18
- canUndo: false,
19
- canRedo: false
20
- };
21
- };
22
- var _pluginFactory = pluginFactory(historyPluginKey, reducer),
23
- createPluginState = _pluginFactory.createPluginState,
24
- getPluginState = _pluginFactory.getPluginState;
25
- var createPlugin = function createPlugin(dispatch) {
26
- return new SafePlugin({
27
- state: createPluginState(dispatch, getInitialState),
28
- key: historyPluginKey,
29
- appendTransaction: function appendTransaction(transactions, oldState, newState) {
30
- if (transactions.find(function (tr) {
31
- return tr.docChanged && tr.getMeta('addToHistory') !== false;
32
- })) {
33
- var pmHistoryPluginState = getPmHistoryPluginState(newState);
34
- if (!pmHistoryPluginState) {
35
- return;
36
- }
37
- var canUndo = pmHistoryPluginState.done.eventCount > 0;
38
- var canRedo = pmHistoryPluginState.undone.eventCount > 0;
39
- var _getPluginState = getPluginState(newState),
40
- prevCanUndo = _getPluginState.canUndo,
41
- prevCanRedo = _getPluginState.canRedo;
42
- if (canUndo !== prevCanUndo || canRedo !== prevCanRedo) {
43
- var action = {
44
- type: HistoryActionTypes.UPDATE,
45
- canUndo: canUndo,
46
- canRedo: canRedo
47
- };
48
- return newState.tr.setMeta(historyPluginKey, action);
49
- }
50
- }
51
- }
52
- });
53
- };
54
- var historyPlugin = function historyPlugin() {
55
- return {
56
- name: 'history',
57
- pmPlugins: function pmPlugins() {
58
- return [{
59
- name: 'history',
60
- plugin: function plugin(_ref) {
61
- var dispatch = _ref.dispatch;
62
- return createPlugin(dispatch);
63
- }
64
- }];
65
- }
66
- };
67
- };
68
- export default historyPlugin;
@@ -1 +0,0 @@
1
- export {};
@@ -1,12 +0,0 @@
1
- import { HistoryActionTypes } from './actions';
2
- var reducer = function reducer(state, action) {
3
- switch (action.type) {
4
- case HistoryActionTypes.UPDATE:
5
- return {
6
- canUndo: action.canUndo,
7
- canRedo: action.canRedo
8
- };
9
- }
10
- return state;
11
- };
12
- export default reducer;
@@ -1 +0,0 @@
1
- export {};
@@ -1,13 +0,0 @@
1
- import { pmHistoryPluginKey } from '@atlaskit/editor-common/utils';
2
- export var getPmHistoryPlugin = function getPmHistoryPlugin(state) {
3
- return state.plugins.find(function (plugin) {
4
- return plugin.key === pmHistoryPluginKey;
5
- });
6
- };
7
- export var getPmHistoryPluginState = function getPmHistoryPluginState(state) {
8
- var pmHistoryPlugin = getPmHistoryPlugin(state);
9
- if (!pmHistoryPlugin) {
10
- return;
11
- }
12
- return pmHistoryPlugin.getState(state);
13
- };
@@ -1,8 +0,0 @@
1
- export declare enum HistoryActionTypes {
2
- UPDATE = "UPDATE"
3
- }
4
- export interface HistoryAction {
5
- type: HistoryActionTypes.UPDATE;
6
- canUndo: boolean;
7
- canRedo: boolean;
8
- }