@atlaskit/editor-plugin-track-changes 2.1.1 → 2.3.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,29 @@
1
1
  # @atlaskit/editor-plugin-track-changes
2
2
 
3
+ ## 2.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#193889](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/193889)
8
+ [`6d4374ce318fd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6d4374ce318fd) -
9
+ [EDITOR-1073] Add i18n for Track Changes button & toggle button on toolbar with plugin option
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
15
+ ## 2.2.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [#193685](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/193685)
20
+ [`ee3ba46cb3d0a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ee3ba46cb3d0a) -
21
+ [EDITOR-1073] Add undo/ redo & show diff to comment toolbar
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies
26
+
3
27
  ## 2.1.1
4
28
 
5
29
  ### Patch Changes
package/README.md CHANGED
@@ -1 +1,89 @@
1
1
  # Editor plugin track changes
2
+
3
+ Track changes plugin for @atlaskit/editor-core
4
+
5
+ ## Usage
6
+
7
+ `import { trackChangesPlugin } from '@atlaskit/editor-plugin-track-changes';`
8
+
9
+ ### Dependencies
10
+
11
+ **Required:**
12
+ - `ShowDiffPlugin` - Required for displaying track changes diff view
13
+
14
+ **Optional:**
15
+ - `PrimaryToolbarPlugin` - Required if using `showOnToolbar: true`
16
+
17
+ ### Configuration
18
+
19
+ The plugin accepts an optional configuration object:
20
+
21
+ ```typescript
22
+ trackChangesPlugin({
23
+ showOnToolbar: true // Shows track changes button in the toolbar (default: false)
24
+ })
25
+ ```
26
+
27
+ ### Example
28
+
29
+ ```typescript
30
+ import React from 'react';
31
+
32
+ import Button from '@atlaskit/button/new';
33
+ import { cssMap } from '@atlaskit/css';
34
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
35
+ import { ComposableEditor } from '@atlaskit/editor-core/composable-editor';
36
+ import { usePreset } from '@atlaskit/editor-core/use-preset';
37
+ import { basePlugin } from '@atlaskit/editor-plugins/base';
38
+ import { Box } from '@atlaskit/primitives/compiled';
39
+ import { token } from '@atlaskit/tokens';
40
+
41
+ import { showDiffPlugin } from '@atlaskit/editor-plugin-show-diff';
42
+ import { trackChangesPlugin } from '@atlaskit/editor-plugin-track-changes';
43
+
44
+ const styles = cssMap({
45
+ aboveEditor: {
46
+ paddingTop: token('space.100'),
47
+ paddingBottom: token('space.100'),
48
+ },
49
+ everythingContainer: {
50
+ paddingTop: token('space.200'),
51
+ paddingBottom: token('space.200'),
52
+ paddingLeft: token('space.200'),
53
+ paddingRight: token('space.200'),
54
+ },
55
+ });
56
+
57
+ function Editor() {
58
+ const { preset, editorApi } = usePreset(
59
+ (builder) =>
60
+ builder.add(basePlugin).add(showDiffPlugin).add(trackChangesPlugin),
61
+ [],
62
+ );
63
+
64
+ const isSelected = useSharedPluginStateSelector(editorApi, 'trackChanges.isDisplayingChanges');
65
+
66
+ return (
67
+ <Box xcss={styles.everythingContainer}>
68
+ <Box xcss={styles.aboveEditor}>
69
+ <Button
70
+ appearance="primary"
71
+ onClick={() => {
72
+ editorApi?.core.actions.execute(
73
+ editorApi?.trackChanges.commands.toggleChanges,
74
+ );
75
+ }}
76
+ isSelected={isSelected}
77
+ >
78
+ Show Diff
79
+ </Button>
80
+ </Box>
81
+ <ComposableEditor preset={preset} />
82
+ </Box>
83
+ );
84
+ }
85
+
86
+ export default Editor;
87
+ ```
88
+
89
+ Detailed docs and example usage can be found [here](https://atlaskit.atlassian.com/packages/editor/editor-plugin-track-changes).
@@ -14,11 +14,25 @@
14
14
  "../src/**/__tests__/*",
15
15
  "../src/**/*.test.*",
16
16
  "../src/**/test.*",
17
- "../src/**/examples.*"
17
+ "../src/**/examples.*",
18
+ "../src/**/examples/*",
19
+ "../src/**/examples/**/*",
20
+ "../src/**/*.stories.*",
21
+ "../src/**/stories/*",
22
+ "../src/**/stories/**/*"
18
23
  ],
19
24
  "references": [
20
25
  {
21
- "path": "../../../design-system/tokens/afm-cc/tsconfig.json"
26
+ "path": "../../../design-system/button/afm-cc/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-plugin-primary-toolbar/afm-cc/tsconfig.json"
30
+ },
31
+ {
32
+ "path": "../../editor-plugin-show-diff/afm-cc/tsconfig.json"
33
+ },
34
+ {
35
+ "path": "../../../design-system/icon-lab/afm-cc/tsconfig.json"
22
36
  },
23
37
  {
24
38
  "path": "../../editor-common/afm-cc/tsconfig.json"
@@ -14,11 +14,25 @@
14
14
  "../src/**/__tests__/*",
15
15
  "../src/**/*.test.*",
16
16
  "../src/**/test.*",
17
- "../src/**/examples.*"
17
+ "../src/**/examples.*",
18
+ "../src/**/examples/*",
19
+ "../src/**/examples/**/*",
20
+ "../src/**/*.stories.*",
21
+ "../src/**/stories/*",
22
+ "../src/**/stories/**/*"
18
23
  ],
19
24
  "references": [
20
25
  {
21
- "path": "../../../design-system/tokens/afm-jira/tsconfig.json"
26
+ "path": "../../../design-system/button/afm-jira/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-plugin-primary-toolbar/afm-jira/tsconfig.json"
30
+ },
31
+ {
32
+ "path": "../../editor-plugin-show-diff/afm-jira/tsconfig.json"
33
+ },
34
+ {
35
+ "path": "../../../design-system/icon-lab/afm-jira/tsconfig.json"
22
36
  },
23
37
  {
24
38
  "path": "../../editor-common/afm-jira/tsconfig.json"
@@ -0,0 +1,41 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.post-office.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../post-office/tsDist/@atlaskit__editor-plugin-track-changes/app",
6
+ "rootDir": "../",
7
+ "composite": true
8
+ },
9
+ "include": [
10
+ "../src/**/*.ts",
11
+ "../src/**/*.tsx"
12
+ ],
13
+ "exclude": [
14
+ "../src/**/__tests__/*",
15
+ "../src/**/*.test.*",
16
+ "../src/**/test.*",
17
+ "../src/**/examples.*",
18
+ "../src/**/examples/*",
19
+ "../src/**/examples/**/*",
20
+ "../src/**/*.stories.*",
21
+ "../src/**/stories/*",
22
+ "../src/**/stories/**/*"
23
+ ],
24
+ "references": [
25
+ {
26
+ "path": "../../../design-system/button/afm-post-office/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-plugin-primary-toolbar/afm-post-office/tsconfig.json"
30
+ },
31
+ {
32
+ "path": "../../editor-plugin-show-diff/afm-post-office/tsconfig.json"
33
+ },
34
+ {
35
+ "path": "../../../design-system/icon-lab/afm-post-office/tsconfig.json"
36
+ },
37
+ {
38
+ "path": "../../editor-common/afm-post-office/tsconfig.json"
39
+ }
40
+ ]
41
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.rovo-extension.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../rovo-extension/tsDist/@atlaskit__editor-plugin-track-changes/app",
6
+ "rootDir": "../",
7
+ "composite": true
8
+ },
9
+ "include": [
10
+ "../src/**/*.ts",
11
+ "../src/**/*.tsx"
12
+ ],
13
+ "exclude": [
14
+ "../src/**/__tests__/*",
15
+ "../src/**/*.test.*",
16
+ "../src/**/test.*",
17
+ "../src/**/examples.*",
18
+ "../src/**/examples/*",
19
+ "../src/**/examples/**/*",
20
+ "../src/**/*.stories.*",
21
+ "../src/**/stories/*",
22
+ "../src/**/stories/**/*"
23
+ ],
24
+ "references": [
25
+ {
26
+ "path": "../../../design-system/button/afm-rovo-extension/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-plugin-primary-toolbar/afm-rovo-extension/tsconfig.json"
30
+ },
31
+ {
32
+ "path": "../../editor-plugin-show-diff/afm-rovo-extension/tsconfig.json"
33
+ },
34
+ {
35
+ "path": "../../../design-system/icon-lab/afm-rovo-extension/tsconfig.json"
36
+ },
37
+ {
38
+ "path": "../../editor-common/afm-rovo-extension/tsconfig.json"
39
+ }
40
+ ]
41
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.townsquare.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../townsquare/tsDist/@atlaskit__editor-plugin-track-changes/app",
6
+ "rootDir": "../",
7
+ "composite": true
8
+ },
9
+ "include": [
10
+ "../src/**/*.ts",
11
+ "../src/**/*.tsx"
12
+ ],
13
+ "exclude": [
14
+ "../src/**/__tests__/*",
15
+ "../src/**/*.test.*",
16
+ "../src/**/test.*",
17
+ "../src/**/examples.*",
18
+ "../src/**/examples/*",
19
+ "../src/**/examples/**/*",
20
+ "../src/**/*.stories.*",
21
+ "../src/**/stories/*",
22
+ "../src/**/stories/**/*"
23
+ ],
24
+ "references": [
25
+ {
26
+ "path": "../../../design-system/button/afm-townsquare/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-plugin-primary-toolbar/afm-townsquare/tsconfig.json"
30
+ },
31
+ {
32
+ "path": "../../editor-plugin-show-diff/afm-townsquare/tsconfig.json"
33
+ },
34
+ {
35
+ "path": "../../../design-system/icon-lab/afm-townsquare/tsconfig.json"
36
+ },
37
+ {
38
+ "path": "../../editor-common/afm-townsquare/tsconfig.json"
39
+ }
40
+ ]
41
+ }
@@ -1,17 +1,22 @@
1
1
  {
2
- "extends": "../tsconfig",
3
- "compilerOptions": {
4
- "target": "es5",
5
- "paths": {}
6
- },
7
- "include": [
8
- "../src/**/*.ts",
9
- "../src/**/*.tsx"
10
- ],
11
- "exclude": [
12
- "../src/**/__tests__/*",
13
- "../src/**/*.test.*",
14
- "../src/**/test.*",
15
- "../src/**/examples.*"
16
- ]
2
+ "extends": "../tsconfig",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "paths": {}
6
+ },
7
+ "include": [
8
+ "../src/**/*.ts",
9
+ "../src/**/*.tsx"
10
+ ],
11
+ "exclude": [
12
+ "../src/**/__tests__/*",
13
+ "../src/**/*.test.*",
14
+ "../src/**/test.*",
15
+ "../src/**/examples.*",
16
+ "../src/**/examples/*",
17
+ "../src/**/examples/**/*",
18
+ "../src/**/*.stories.*",
19
+ "../src/**/stories/*",
20
+ "../src/**/stories/**/*"
21
+ ]
17
22
  }
@@ -4,35 +4,58 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.trackChangesPluginKey = exports.createTrackChangesPlugin = void 0;
7
+ exports.trackChangesPluginKey = exports.createTrackChangesPlugin = exports.InvertableStep = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
8
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _prosemirrorChangeset = require("prosemirror-changeset");
10
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
12
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
13
  var _state = require("@atlaskit/editor-prosemirror/state");
12
14
  var _transform = require("@atlaskit/editor-prosemirror/transform");
13
- var _view = require("@atlaskit/editor-prosemirror/view");
14
- var _decorations = require("./decorations");
15
15
  var _types = require("./types");
16
16
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
17
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
19
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
20
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
18
21
  var trackChangesPluginKey = exports.trackChangesPluginKey = new _state.PluginKey('trackChangesPlugin');
19
- var createTrackChangesPlugin = exports.createTrackChangesPlugin = function createTrackChangesPlugin() {
22
+ var InvertableStep = exports.InvertableStep = /*#__PURE__*/(0, _createClass2.default)(function InvertableStep(step, inverted) {
23
+ (0, _classCallCheck2.default)(this, InvertableStep);
24
+ this.step = step;
25
+ this.inverted = inverted;
26
+ });
27
+ var getBaselineFromSteps = function getBaselineFromSteps(doc, steps) {
28
+ var _iterator = _createForOfIteratorHelper(steps.slice().reverse()),
29
+ _step;
30
+ try {
31
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
32
+ var _step2 = _step.value;
33
+ var result = _step2.inverted.apply(doc);
34
+ if (result.failed === null && result.doc) {
35
+ doc = result.doc;
36
+ }
37
+ }
38
+ } catch (err) {
39
+ _iterator.e(err);
40
+ } finally {
41
+ _iterator.f();
42
+ }
43
+ return doc;
44
+ };
45
+ var createTrackChangesPlugin = exports.createTrackChangesPlugin = function createTrackChangesPlugin(api) {
20
46
  // Mark the state to be reset on next time the document has a meaningful change
21
47
  var resetBaseline = false;
22
48
  return new _safePlugin.SafePlugin({
23
49
  key: trackChangesPluginKey,
24
50
  state: {
25
- init: function init(_, _ref) {
26
- var doc = _ref.doc;
51
+ init: function init() {
27
52
  return {
28
- changes: _prosemirrorChangeset.ChangeSet.create(doc),
53
+ steps: [],
29
54
  shouldChangesBeDisplayed: false,
30
- isShowDiffAvailable: false,
31
- baselineDoc: doc,
32
- numOfChanges: 0
55
+ isShowDiffAvailable: false
33
56
  };
34
57
  },
35
- apply: function apply(tr, state, oldState, newState) {
58
+ apply: function apply(tr, state) {
36
59
  var metadata = tr.getMeta(trackChangesPluginKey);
37
60
  if (metadata && metadata.action === _types.TOGGLE_TRACK_CHANGES_ACTION.TOGGLE_TRACK_CHANGES) {
38
61
  resetBaseline = true;
@@ -47,53 +70,42 @@ var createTrackChangesPlugin = exports.createTrackChangesPlugin = function creat
47
70
  // If no document changes, return the old changeSet
48
71
  return state;
49
72
  }
50
- var changes = resetBaseline ? _prosemirrorChangeset.ChangeSet.create(tr.docs[0]).addSteps(tr.doc,
51
- // The new document
52
- tr.mapping.maps,
53
- // The set of changes
54
- tr.docs[0].content // The old document
55
- ) : state.changes.addSteps(tr.doc,
56
- // The new document
57
- tr.mapping.maps,
58
- // The set of changes
59
- tr.docs[0].content // The old document
60
- );
61
- var baselineDoc = resetBaseline ? tr.docs[0] : state.baselineDoc;
73
+ var newSteps = tr.steps.map(function (step, idx) {
74
+ return new InvertableStep(step, step.invert(tr.docs[idx]));
75
+ });
76
+ var steps = resetBaseline ? newSteps : [].concat((0, _toConsumableArray2.default)(state.steps), (0, _toConsumableArray2.default)(newSteps));
62
77
  resetBaseline = false;
63
78
 
64
79
  // Create a new ChangeSet based on document changes
65
80
  return _objectSpread(_objectSpread({}, state), {}, {
66
- baselineDoc: baselineDoc,
81
+ steps: steps,
67
82
  shouldChangesBeDisplayed: false,
68
- changes: changes,
69
83
  isShowDiffAvailable: true
70
84
  });
71
85
  }
72
86
  },
73
- props: {
74
- decorations: function decorations(state) {
75
- var pluginState = trackChangesPluginKey.getState(state);
76
- if (!(pluginState !== null && pluginState !== void 0 && pluginState.shouldChangesBeDisplayed) || !pluginState.changes) {
77
- return undefined;
78
- }
79
- var decoration = _view.DecorationSet.empty;
80
- var decorations = [];
81
- var changes = (0, _prosemirrorChangeset.simplifyChanges)(pluginState.changes.changes, state.doc);
82
- var tr = state.tr;
83
- changes.forEach(function (change) {
84
- if (change.inserted.length > 0) {
85
- decorations.push((0, _decorations.createInlineChangedDecoration)(change));
86
- }
87
- if (change.deleted.length > 0) {
88
- decorations.push((0, _decorations.createDeletedContentDecoration)({
89
- change: change,
90
- doc: pluginState === null || pluginState === void 0 ? void 0 : pluginState.baselineDoc,
91
- tr: tr
87
+ view: function view() {
88
+ return {
89
+ update: function update(view, prevState) {
90
+ var _trackChangesPluginKe;
91
+ var prevShouldChangesBeDisplayed = (_trackChangesPluginKe = trackChangesPluginKey.getState(prevState)) === null || _trackChangesPluginKe === void 0 ? void 0 : _trackChangesPluginKe.shouldChangesBeDisplayed;
92
+ var currentPluginState = trackChangesPluginKey.getState(view.state);
93
+ var currentShouldChangesBeDisplayed = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.shouldChangesBeDisplayed;
94
+ if (prevShouldChangesBeDisplayed === false && currentShouldChangesBeDisplayed === true) {
95
+ var _currentPluginState$s, _api$core, _api$showDiff;
96
+ var steps = (_currentPluginState$s = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.steps) !== null && _currentPluginState$s !== void 0 ? _currentPluginState$s : [];
97
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$showDiff = api.showDiff) === null || _api$showDiff === void 0 || (_api$showDiff = _api$showDiff.commands) === null || _api$showDiff === void 0 ? void 0 : _api$showDiff.showDiff({
98
+ originalDoc: getBaselineFromSteps(view.state.doc, steps),
99
+ steps: steps.map(function (s) {
100
+ return s.step;
101
+ })
92
102
  }));
103
+ } else if (currentShouldChangesBeDisplayed === false && prevShouldChangesBeDisplayed === true) {
104
+ var _api$core2, _api$showDiff2;
105
+ api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(api === null || api === void 0 || (_api$showDiff2 = api.showDiff) === null || _api$showDiff2 === void 0 || (_api$showDiff2 = _api$showDiff2.commands) === null || _api$showDiff2 === void 0 ? void 0 : _api$showDiff2.hideDiff);
93
106
  }
94
- });
95
- return decoration.add(tr.doc, decorations);
96
- }
107
+ }
108
+ };
97
109
  }
98
110
  });
99
111
  };
@@ -1,23 +1,42 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.trackChangesPlugin = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
7
9
  var _main = require("./pm-plugins/main");
8
10
  var _types = require("./pm-plugins/types");
9
- var trackChangesPlugin = exports.trackChangesPlugin = function trackChangesPlugin() {
11
+ var _TrackChangesToolbarButton = require("./ui/TrackChangesToolbarButton");
12
+ var trackChangesPlugin = exports.trackChangesPlugin = function trackChangesPlugin(_ref) {
13
+ var api = _ref.api,
14
+ options = _ref.config;
15
+ var primaryToolbarComponent = function primaryToolbarComponent() {
16
+ return /*#__PURE__*/_react.default.createElement(_TrackChangesToolbarButton.TrackChangesToolbarButton, {
17
+ api: api
18
+ });
19
+ };
20
+ if ((options === null || options === void 0 ? void 0 : options.showOnToolbar) === true) {
21
+ var _api$primaryToolbar;
22
+ api === null || api === void 0 || (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 || (_api$primaryToolbar = _api$primaryToolbar.actions) === null || _api$primaryToolbar === void 0 || _api$primaryToolbar.registerComponent({
23
+ name: 'trackChanges',
24
+ component: primaryToolbarComponent
25
+ });
26
+ }
10
27
  return {
11
28
  name: 'trackChanges',
12
29
  pmPlugins: function pmPlugins() {
13
30
  return [{
14
31
  name: 'trackChangesPlugin',
15
- plugin: _main.createTrackChangesPlugin
32
+ plugin: function plugin() {
33
+ return (0, _main.createTrackChangesPlugin)(api);
34
+ }
16
35
  }];
17
36
  },
18
37
  commands: {
19
- toggleChanges: function toggleChanges(_ref) {
20
- var tr = _ref.tr;
38
+ toggleChanges: function toggleChanges(_ref2) {
39
+ var tr = _ref2.tr;
21
40
  return tr.setMeta(_main.trackChangesPluginKey, {
22
41
  action: _types.TOGGLE_TRACK_CHANGES_ACTION.TOGGLE_TRACK_CHANGES
23
42
  });
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.TrackChangesToolbarButton = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _new = require("@atlaskit/button/new");
11
+ var _hooks = require("@atlaskit/editor-common/hooks");
12
+ var _messages = require("@atlaskit/editor-common/messages");
13
+ var _history = _interopRequireDefault(require("@atlaskit/icon-lab/core/history"));
14
+ var TrackChangesToolbarButton = exports.TrackChangesToolbarButton = function TrackChangesToolbarButton(_ref) {
15
+ var _api$trackChanges;
16
+ var api = _ref.api;
17
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['trackChanges'], function (states) {
18
+ var _states$trackChangesS, _states$trackChangesS2;
19
+ return {
20
+ isDisplayingChanges: (_states$trackChangesS = states.trackChangesState) === null || _states$trackChangesS === void 0 ? void 0 : _states$trackChangesS.isDisplayingChanges,
21
+ isShowDiffAvailable: (_states$trackChangesS2 = states.trackChangesState) === null || _states$trackChangesS2 === void 0 ? void 0 : _states$trackChangesS2.isShowDiffAvailable
22
+ };
23
+ }),
24
+ isDisplayingChanges = _useSharedPluginState.isDisplayingChanges,
25
+ isShowDiffAvailable = _useSharedPluginState.isShowDiffAvailable;
26
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
27
+ formatMessage = _useIntl.formatMessage;
28
+ var handleClick = _react.default.useCallback(function () {
29
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.trackChanges.commands.toggleChanges);
30
+ }, [api === null || api === void 0 || (_api$trackChanges = api.trackChanges) === null || _api$trackChanges === void 0 ? void 0 : _api$trackChanges.commands, api === null || api === void 0 ? void 0 : api.core.actions]);
31
+ return /*#__PURE__*/_react.default.createElement(_new.IconButton, {
32
+ icon: _history.default,
33
+ label: formatMessage(_messages.trackChangesMessages.toolbarIconLabel),
34
+ appearance: "subtle",
35
+ isDisabled: !isShowDiffAvailable,
36
+ isSelected: isDisplayingChanges,
37
+ onClick: handleClick
38
+ });
39
+ };