@atlaskit/editor-plugin-track-changes 2.1.1 → 2.2.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,17 @@
1
1
  # @atlaskit/editor-plugin-track-changes
2
2
 
3
+ ## 2.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#193685](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/193685)
8
+ [`ee3ba46cb3d0a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ee3ba46cb3d0a) -
9
+ [EDITOR-1073] Add undo/ redo & show diff to comment toolbar
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 2.1.1
4
16
 
5
17
  ### Patch Changes
@@ -18,7 +18,16 @@
18
18
  ],
19
19
  "references": [
20
20
  {
21
- "path": "../../../design-system/tokens/afm-cc/tsconfig.json"
21
+ "path": "../../../design-system/button/afm-cc/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../editor-plugin-primary-toolbar/afm-cc/tsconfig.json"
25
+ },
26
+ {
27
+ "path": "../../editor-plugin-show-diff/afm-cc/tsconfig.json"
28
+ },
29
+ {
30
+ "path": "../../../design-system/icon-lab/afm-cc/tsconfig.json"
22
31
  },
23
32
  {
24
33
  "path": "../../editor-common/afm-cc/tsconfig.json"
@@ -18,7 +18,16 @@
18
18
  ],
19
19
  "references": [
20
20
  {
21
- "path": "../../../design-system/tokens/afm-jira/tsconfig.json"
21
+ "path": "../../../design-system/button/afm-jira/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../editor-plugin-primary-toolbar/afm-jira/tsconfig.json"
25
+ },
26
+ {
27
+ "path": "../../editor-plugin-show-diff/afm-jira/tsconfig.json"
28
+ },
29
+ {
30
+ "path": "../../../design-system/icon-lab/afm-jira/tsconfig.json"
22
31
  },
23
32
  {
24
33
  "path": "../../editor-common/afm-jira/tsconfig.json"
@@ -0,0 +1,36 @@
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
+ ],
19
+ "references": [
20
+ {
21
+ "path": "../../../design-system/button/afm-post-office/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../editor-plugin-primary-toolbar/afm-post-office/tsconfig.json"
25
+ },
26
+ {
27
+ "path": "../../editor-plugin-show-diff/afm-post-office/tsconfig.json"
28
+ },
29
+ {
30
+ "path": "../../../design-system/icon-lab/afm-post-office/tsconfig.json"
31
+ },
32
+ {
33
+ "path": "../../editor-common/afm-post-office/tsconfig.json"
34
+ }
35
+ ]
36
+ }
@@ -0,0 +1,36 @@
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
+ ],
19
+ "references": [
20
+ {
21
+ "path": "../../../design-system/button/afm-rovo-extension/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../editor-plugin-primary-toolbar/afm-rovo-extension/tsconfig.json"
25
+ },
26
+ {
27
+ "path": "../../editor-plugin-show-diff/afm-rovo-extension/tsconfig.json"
28
+ },
29
+ {
30
+ "path": "../../../design-system/icon-lab/afm-rovo-extension/tsconfig.json"
31
+ },
32
+ {
33
+ "path": "../../editor-common/afm-rovo-extension/tsconfig.json"
34
+ }
35
+ ]
36
+ }
@@ -0,0 +1,36 @@
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
+ ],
19
+ "references": [
20
+ {
21
+ "path": "../../../design-system/button/afm-townsquare/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../editor-plugin-primary-toolbar/afm-townsquare/tsconfig.json"
25
+ },
26
+ {
27
+ "path": "../../editor-plugin-show-diff/afm-townsquare/tsconfig.json"
28
+ },
29
+ {
30
+ "path": "../../../design-system/icon-lab/afm-townsquare/tsconfig.json"
31
+ },
32
+ {
33
+ "path": "../../editor-common/afm-townsquare/tsconfig.json"
34
+ }
35
+ ]
36
+ }
@@ -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,39 @@
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$primaryToolbar;
14
+ var api = _ref.api;
15
+ var primaryToolbarComponent = function primaryToolbarComponent() {
16
+ return /*#__PURE__*/_react.default.createElement(_TrackChangesToolbarButton.TrackChangesToolbarButton, {
17
+ api: api
18
+ });
19
+ };
20
+ 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({
21
+ name: 'trackChanges',
22
+ component: primaryToolbarComponent
23
+ });
10
24
  return {
11
25
  name: 'trackChanges',
12
26
  pmPlugins: function pmPlugins() {
13
27
  return [{
14
28
  name: 'trackChangesPlugin',
15
- plugin: _main.createTrackChangesPlugin
29
+ plugin: function plugin() {
30
+ return (0, _main.createTrackChangesPlugin)(api);
31
+ }
16
32
  }];
17
33
  },
18
34
  commands: {
19
- toggleChanges: function toggleChanges(_ref) {
20
- var tr = _ref.tr;
35
+ toggleChanges: function toggleChanges(_ref2) {
36
+ var tr = _ref2.tr;
21
37
  return tr.setMeta(_main.trackChangesPluginKey, {
22
38
  action: _types.TOGGLE_TRACK_CHANGES_ACTION.TOGGLE_TRACK_CHANGES
23
39
  });
@@ -0,0 +1,35 @@
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 _new = require("@atlaskit/button/new");
10
+ var _hooks = require("@atlaskit/editor-common/hooks");
11
+ var _history = _interopRequireDefault(require("@atlaskit/icon-lab/core/history"));
12
+ var TrackChangesToolbarButton = exports.TrackChangesToolbarButton = function TrackChangesToolbarButton(_ref) {
13
+ var _api$trackChanges;
14
+ var api = _ref.api;
15
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['trackChanges'], function (states) {
16
+ var _states$trackChangesS, _states$trackChangesS2;
17
+ return {
18
+ isDisplayingChanges: (_states$trackChangesS = states.trackChangesState) === null || _states$trackChangesS === void 0 ? void 0 : _states$trackChangesS.isDisplayingChanges,
19
+ isShowDiffAvailable: (_states$trackChangesS2 = states.trackChangesState) === null || _states$trackChangesS2 === void 0 ? void 0 : _states$trackChangesS2.isShowDiffAvailable
20
+ };
21
+ }),
22
+ isDisplayingChanges = _useSharedPluginState.isDisplayingChanges,
23
+ isShowDiffAvailable = _useSharedPluginState.isShowDiffAvailable;
24
+ var handleClick = _react.default.useCallback(function () {
25
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.trackChanges.commands.toggleChanges);
26
+ }, [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]);
27
+ return /*#__PURE__*/_react.default.createElement(_new.IconButton, {
28
+ icon: _history.default,
29
+ label: "Track Changes",
30
+ appearance: "subtle",
31
+ isDisabled: !isShowDiffAvailable,
32
+ isSelected: isDisplayingChanges,
33
+ onClick: handleClick
34
+ });
35
+ };
@@ -1,29 +1,37 @@
1
- import { ChangeSet, simplifyChanges } from 'prosemirror-changeset';
2
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
3
  import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
5
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
- import { createInlineChangedDecoration, createDeletedContentDecoration } from './decorations';
7
4
  import { TOGGLE_TRACK_CHANGES_ACTION as ACTION } from './types';
8
5
  export const trackChangesPluginKey = new PluginKey('trackChangesPlugin');
9
- export const createTrackChangesPlugin = () => {
6
+ export class InvertableStep {
7
+ constructor(step, inverted) {
8
+ this.step = step;
9
+ this.inverted = inverted;
10
+ }
11
+ }
12
+ const getBaselineFromSteps = (doc, steps) => {
13
+ for (const step of steps.slice().reverse()) {
14
+ const result = step.inverted.apply(doc);
15
+ if (result.failed === null && result.doc) {
16
+ doc = result.doc;
17
+ }
18
+ }
19
+ return doc;
20
+ };
21
+ export const createTrackChangesPlugin = api => {
10
22
  // Mark the state to be reset on next time the document has a meaningful change
11
23
  let resetBaseline = false;
12
24
  return new SafePlugin({
13
25
  key: trackChangesPluginKey,
14
26
  state: {
15
- init(_, {
16
- doc
17
- }) {
27
+ init() {
18
28
  return {
19
- changes: ChangeSet.create(doc),
29
+ steps: [],
20
30
  shouldChangesBeDisplayed: false,
21
- isShowDiffAvailable: false,
22
- baselineDoc: doc,
23
- numOfChanges: 0
31
+ isShowDiffAvailable: false
24
32
  };
25
33
  },
26
- apply(tr, state, oldState, newState) {
34
+ apply(tr, state) {
27
35
  const metadata = tr.getMeta(trackChangesPluginKey);
28
36
  if (metadata && metadata.action === ACTION.TOGGLE_TRACK_CHANGES) {
29
37
  resetBaseline = true;
@@ -37,54 +45,39 @@ export const createTrackChangesPlugin = () => {
37
45
  // If no document changes, return the old changeSet
38
46
  return state;
39
47
  }
40
- const changes = resetBaseline ? ChangeSet.create(tr.docs[0]).addSteps(tr.doc,
41
- // The new document
42
- tr.mapping.maps,
43
- // The set of changes
44
- tr.docs[0].content // The old document
45
- ) : state.changes.addSteps(tr.doc,
46
- // The new document
47
- tr.mapping.maps,
48
- // The set of changes
49
- tr.docs[0].content // The old document
50
- );
51
- const baselineDoc = resetBaseline ? tr.docs[0] : state.baselineDoc;
48
+ const newSteps = tr.steps.map((step, idx) => new InvertableStep(step, step.invert(tr.docs[idx])));
49
+ const steps = resetBaseline ? newSteps : [...state.steps, ...newSteps];
52
50
  resetBaseline = false;
53
51
 
54
52
  // Create a new ChangeSet based on document changes
55
53
  return {
56
54
  ...state,
57
- baselineDoc,
55
+ steps,
58
56
  shouldChangesBeDisplayed: false,
59
- changes,
60
57
  isShowDiffAvailable: true
61
58
  };
62
59
  }
63
60
  },
64
- props: {
65
- decorations: state => {
66
- const pluginState = trackChangesPluginKey.getState(state);
67
- if (!(pluginState !== null && pluginState !== void 0 && pluginState.shouldChangesBeDisplayed) || !pluginState.changes) {
68
- return undefined;
69
- }
70
- const decoration = DecorationSet.empty;
71
- const decorations = [];
72
- const changes = simplifyChanges(pluginState.changes.changes, state.doc);
73
- const tr = state.tr;
74
- changes.forEach(change => {
75
- if (change.inserted.length > 0) {
76
- decorations.push(createInlineChangedDecoration(change));
77
- }
78
- if (change.deleted.length > 0) {
79
- decorations.push(createDeletedContentDecoration({
80
- change,
81
- doc: pluginState === null || pluginState === void 0 ? void 0 : pluginState.baselineDoc,
82
- tr
61
+ view() {
62
+ return {
63
+ update(view, prevState) {
64
+ var _trackChangesPluginKe;
65
+ const prevShouldChangesBeDisplayed = (_trackChangesPluginKe = trackChangesPluginKey.getState(prevState)) === null || _trackChangesPluginKe === void 0 ? void 0 : _trackChangesPluginKe.shouldChangesBeDisplayed;
66
+ const currentPluginState = trackChangesPluginKey.getState(view.state);
67
+ const currentShouldChangesBeDisplayed = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.shouldChangesBeDisplayed;
68
+ if (prevShouldChangesBeDisplayed === false && currentShouldChangesBeDisplayed === true) {
69
+ var _currentPluginState$s, _api$core, _api$showDiff, _api$showDiff$command;
70
+ const steps = (_currentPluginState$s = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.steps) !== null && _currentPluginState$s !== void 0 ? _currentPluginState$s : [];
71
+ api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api === null || api === void 0 ? void 0 : (_api$showDiff = api.showDiff) === null || _api$showDiff === void 0 ? void 0 : (_api$showDiff$command = _api$showDiff.commands) === null || _api$showDiff$command === void 0 ? void 0 : _api$showDiff$command.showDiff({
72
+ originalDoc: getBaselineFromSteps(view.state.doc, steps),
73
+ steps: steps.map(s => s.step)
83
74
  }));
75
+ } else if (currentShouldChangesBeDisplayed === false && prevShouldChangesBeDisplayed === true) {
76
+ var _api$core2, _api$showDiff2, _api$showDiff2$comman;
77
+ api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(api === null || api === void 0 ? void 0 : (_api$showDiff2 = api.showDiff) === null || _api$showDiff2 === void 0 ? void 0 : (_api$showDiff2$comman = _api$showDiff2.commands) === null || _api$showDiff2$comman === void 0 ? void 0 : _api$showDiff2$comman.hideDiff);
84
78
  }
85
- });
86
- return decoration.add(tr.doc, decorations);
87
- }
79
+ }
80
+ };
88
81
  }
89
82
  });
90
83
  };
@@ -1,33 +1,49 @@
1
+ import React from 'react';
1
2
  import { createTrackChangesPlugin, trackChangesPluginKey } from './pm-plugins/main';
2
3
  import { TOGGLE_TRACK_CHANGES_ACTION as ACTION } from './pm-plugins/types';
3
- export const trackChangesPlugin = () => ({
4
- name: 'trackChanges',
5
- pmPlugins() {
6
- return [{
7
- name: 'trackChangesPlugin',
8
- plugin: createTrackChangesPlugin
9
- }];
10
- },
11
- commands: {
12
- toggleChanges: ({
13
- tr
14
- }) => {
15
- return tr.setMeta(trackChangesPluginKey, {
16
- action: ACTION.TOGGLE_TRACK_CHANGES
17
- });
18
- }
19
- },
20
- getSharedState: editorState => {
21
- var _trackChangesPluginKe, _trackChangesPluginKe2;
22
- if (!editorState) {
4
+ import { TrackChangesToolbarButton } from './ui/TrackChangesToolbarButton';
5
+ export const trackChangesPlugin = ({
6
+ api
7
+ }) => {
8
+ var _api$primaryToolbar, _api$primaryToolbar$a;
9
+ const primaryToolbarComponent = () => {
10
+ return /*#__PURE__*/React.createElement(TrackChangesToolbarButton, {
11
+ api: api
12
+ });
13
+ };
14
+ api === null || api === void 0 ? void 0 : (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 ? void 0 : (_api$primaryToolbar$a = _api$primaryToolbar.actions) === null || _api$primaryToolbar$a === void 0 ? void 0 : _api$primaryToolbar$a.registerComponent({
15
+ name: 'trackChanges',
16
+ component: primaryToolbarComponent
17
+ });
18
+ return {
19
+ name: 'trackChanges',
20
+ pmPlugins() {
21
+ return [{
22
+ name: 'trackChangesPlugin',
23
+ plugin: () => createTrackChangesPlugin(api)
24
+ }];
25
+ },
26
+ commands: {
27
+ toggleChanges: ({
28
+ tr
29
+ }) => {
30
+ return tr.setMeta(trackChangesPluginKey, {
31
+ action: ACTION.TOGGLE_TRACK_CHANGES
32
+ });
33
+ }
34
+ },
35
+ getSharedState: editorState => {
36
+ var _trackChangesPluginKe, _trackChangesPluginKe2;
37
+ if (!editorState) {
38
+ return {
39
+ isDisplayingChanges: false,
40
+ isShowDiffAvailable: false
41
+ };
42
+ }
23
43
  return {
24
- isDisplayingChanges: false,
25
- isShowDiffAvailable: false
44
+ isDisplayingChanges: Boolean((_trackChangesPluginKe = trackChangesPluginKey.getState(editorState)) === null || _trackChangesPluginKe === void 0 ? void 0 : _trackChangesPluginKe.shouldChangesBeDisplayed),
45
+ isShowDiffAvailable: Boolean((_trackChangesPluginKe2 = trackChangesPluginKey.getState(editorState)) === null || _trackChangesPluginKe2 === void 0 ? void 0 : _trackChangesPluginKe2.isShowDiffAvailable)
26
46
  };
27
47
  }
28
- return {
29
- isDisplayingChanges: Boolean((_trackChangesPluginKe = trackChangesPluginKey.getState(editorState)) === null || _trackChangesPluginKe === void 0 ? void 0 : _trackChangesPluginKe.shouldChangesBeDisplayed),
30
- isShowDiffAvailable: Boolean((_trackChangesPluginKe2 = trackChangesPluginKey.getState(editorState)) === null || _trackChangesPluginKe2 === void 0 ? void 0 : _trackChangesPluginKe2.isShowDiffAvailable)
31
- };
32
- }
33
- });
48
+ };
49
+ };
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import { IconButton } from '@atlaskit/button/new';
3
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
4
+ import HistoryIcon from '@atlaskit/icon-lab/core/history';
5
+ export const TrackChangesToolbarButton = ({
6
+ api
7
+ }) => {
8
+ var _api$trackChanges;
9
+ const {
10
+ isDisplayingChanges,
11
+ isShowDiffAvailable
12
+ } = useSharedPluginStateWithSelector(api, ['trackChanges'], states => {
13
+ var _states$trackChangesS, _states$trackChangesS2;
14
+ return {
15
+ isDisplayingChanges: (_states$trackChangesS = states.trackChangesState) === null || _states$trackChangesS === void 0 ? void 0 : _states$trackChangesS.isDisplayingChanges,
16
+ isShowDiffAvailable: (_states$trackChangesS2 = states.trackChangesState) === null || _states$trackChangesS2 === void 0 ? void 0 : _states$trackChangesS2.isShowDiffAvailable
17
+ };
18
+ });
19
+ const handleClick = React.useCallback(() => {
20
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.trackChanges.commands.toggleChanges);
21
+ }, [api === null || api === void 0 ? 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]);
22
+ return /*#__PURE__*/React.createElement(IconButton, {
23
+ icon: HistoryIcon,
24
+ label: "Track Changes",
25
+ appearance: "subtle",
26
+ isDisabled: !isShowDiffAvailable,
27
+ isSelected: isDisplayingChanges,
28
+ onClick: handleClick
29
+ });
30
+ };
@@ -1,31 +1,54 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _createClass from "@babel/runtime/helpers/createClass";
4
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
5
  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; }
3
6
  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) { _defineProperty(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; }
4
- import { ChangeSet, simplifyChanges } from 'prosemirror-changeset';
7
+ 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; } } }; }
8
+ 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; } }
9
+ 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; }
5
10
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
11
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
7
12
  import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
8
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
9
- import { createInlineChangedDecoration, createDeletedContentDecoration } from './decorations';
10
13
  import { TOGGLE_TRACK_CHANGES_ACTION as ACTION } from './types';
11
14
  export var trackChangesPluginKey = new PluginKey('trackChangesPlugin');
12
- export var createTrackChangesPlugin = function createTrackChangesPlugin() {
15
+ export var InvertableStep = /*#__PURE__*/_createClass(function InvertableStep(step, inverted) {
16
+ _classCallCheck(this, InvertableStep);
17
+ this.step = step;
18
+ this.inverted = inverted;
19
+ });
20
+ var getBaselineFromSteps = function getBaselineFromSteps(doc, steps) {
21
+ var _iterator = _createForOfIteratorHelper(steps.slice().reverse()),
22
+ _step;
23
+ try {
24
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
25
+ var _step2 = _step.value;
26
+ var result = _step2.inverted.apply(doc);
27
+ if (result.failed === null && result.doc) {
28
+ doc = result.doc;
29
+ }
30
+ }
31
+ } catch (err) {
32
+ _iterator.e(err);
33
+ } finally {
34
+ _iterator.f();
35
+ }
36
+ return doc;
37
+ };
38
+ export var createTrackChangesPlugin = function createTrackChangesPlugin(api) {
13
39
  // Mark the state to be reset on next time the document has a meaningful change
14
40
  var resetBaseline = false;
15
41
  return new SafePlugin({
16
42
  key: trackChangesPluginKey,
17
43
  state: {
18
- init: function init(_, _ref) {
19
- var doc = _ref.doc;
44
+ init: function init() {
20
45
  return {
21
- changes: ChangeSet.create(doc),
46
+ steps: [],
22
47
  shouldChangesBeDisplayed: false,
23
- isShowDiffAvailable: false,
24
- baselineDoc: doc,
25
- numOfChanges: 0
48
+ isShowDiffAvailable: false
26
49
  };
27
50
  },
28
- apply: function apply(tr, state, oldState, newState) {
51
+ apply: function apply(tr, state) {
29
52
  var metadata = tr.getMeta(trackChangesPluginKey);
30
53
  if (metadata && metadata.action === ACTION.TOGGLE_TRACK_CHANGES) {
31
54
  resetBaseline = true;
@@ -40,53 +63,42 @@ export var createTrackChangesPlugin = function createTrackChangesPlugin() {
40
63
  // If no document changes, return the old changeSet
41
64
  return state;
42
65
  }
43
- var changes = resetBaseline ? ChangeSet.create(tr.docs[0]).addSteps(tr.doc,
44
- // The new document
45
- tr.mapping.maps,
46
- // The set of changes
47
- tr.docs[0].content // The old document
48
- ) : state.changes.addSteps(tr.doc,
49
- // The new document
50
- tr.mapping.maps,
51
- // The set of changes
52
- tr.docs[0].content // The old document
53
- );
54
- var baselineDoc = resetBaseline ? tr.docs[0] : state.baselineDoc;
66
+ var newSteps = tr.steps.map(function (step, idx) {
67
+ return new InvertableStep(step, step.invert(tr.docs[idx]));
68
+ });
69
+ var steps = resetBaseline ? newSteps : [].concat(_toConsumableArray(state.steps), _toConsumableArray(newSteps));
55
70
  resetBaseline = false;
56
71
 
57
72
  // Create a new ChangeSet based on document changes
58
73
  return _objectSpread(_objectSpread({}, state), {}, {
59
- baselineDoc: baselineDoc,
74
+ steps: steps,
60
75
  shouldChangesBeDisplayed: false,
61
- changes: changes,
62
76
  isShowDiffAvailable: true
63
77
  });
64
78
  }
65
79
  },
66
- props: {
67
- decorations: function decorations(state) {
68
- var pluginState = trackChangesPluginKey.getState(state);
69
- if (!(pluginState !== null && pluginState !== void 0 && pluginState.shouldChangesBeDisplayed) || !pluginState.changes) {
70
- return undefined;
71
- }
72
- var decoration = DecorationSet.empty;
73
- var decorations = [];
74
- var changes = simplifyChanges(pluginState.changes.changes, state.doc);
75
- var tr = state.tr;
76
- changes.forEach(function (change) {
77
- if (change.inserted.length > 0) {
78
- decorations.push(createInlineChangedDecoration(change));
79
- }
80
- if (change.deleted.length > 0) {
81
- decorations.push(createDeletedContentDecoration({
82
- change: change,
83
- doc: pluginState === null || pluginState === void 0 ? void 0 : pluginState.baselineDoc,
84
- tr: tr
80
+ view: function view() {
81
+ return {
82
+ update: function update(view, prevState) {
83
+ var _trackChangesPluginKe;
84
+ var prevShouldChangesBeDisplayed = (_trackChangesPluginKe = trackChangesPluginKey.getState(prevState)) === null || _trackChangesPluginKe === void 0 ? void 0 : _trackChangesPluginKe.shouldChangesBeDisplayed;
85
+ var currentPluginState = trackChangesPluginKey.getState(view.state);
86
+ var currentShouldChangesBeDisplayed = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.shouldChangesBeDisplayed;
87
+ if (prevShouldChangesBeDisplayed === false && currentShouldChangesBeDisplayed === true) {
88
+ var _currentPluginState$s, _api$core, _api$showDiff;
89
+ var steps = (_currentPluginState$s = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.steps) !== null && _currentPluginState$s !== void 0 ? _currentPluginState$s : [];
90
+ 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({
91
+ originalDoc: getBaselineFromSteps(view.state.doc, steps),
92
+ steps: steps.map(function (s) {
93
+ return s.step;
94
+ })
85
95
  }));
96
+ } else if (currentShouldChangesBeDisplayed === false && prevShouldChangesBeDisplayed === true) {
97
+ var _api$core2, _api$showDiff2;
98
+ 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);
86
99
  }
87
- });
88
- return decoration.add(tr.doc, decorations);
89
- }
100
+ }
101
+ };
90
102
  }
91
103
  });
92
104
  };
@@ -1,17 +1,32 @@
1
+ import React from 'react';
1
2
  import { createTrackChangesPlugin, trackChangesPluginKey } from './pm-plugins/main';
2
3
  import { TOGGLE_TRACK_CHANGES_ACTION as ACTION } from './pm-plugins/types';
3
- export var trackChangesPlugin = function trackChangesPlugin() {
4
+ import { TrackChangesToolbarButton } from './ui/TrackChangesToolbarButton';
5
+ export var trackChangesPlugin = function trackChangesPlugin(_ref) {
6
+ var _api$primaryToolbar;
7
+ var api = _ref.api;
8
+ var primaryToolbarComponent = function primaryToolbarComponent() {
9
+ return /*#__PURE__*/React.createElement(TrackChangesToolbarButton, {
10
+ api: api
11
+ });
12
+ };
13
+ 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({
14
+ name: 'trackChanges',
15
+ component: primaryToolbarComponent
16
+ });
4
17
  return {
5
18
  name: 'trackChanges',
6
19
  pmPlugins: function pmPlugins() {
7
20
  return [{
8
21
  name: 'trackChangesPlugin',
9
- plugin: createTrackChangesPlugin
22
+ plugin: function plugin() {
23
+ return createTrackChangesPlugin(api);
24
+ }
10
25
  }];
11
26
  },
12
27
  commands: {
13
- toggleChanges: function toggleChanges(_ref) {
14
- var tr = _ref.tr;
28
+ toggleChanges: function toggleChanges(_ref2) {
29
+ var tr = _ref2.tr;
15
30
  return tr.setMeta(trackChangesPluginKey, {
16
31
  action: ACTION.TOGGLE_TRACK_CHANGES
17
32
  });
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { IconButton } from '@atlaskit/button/new';
3
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
4
+ import HistoryIcon from '@atlaskit/icon-lab/core/history';
5
+ export var TrackChangesToolbarButton = function TrackChangesToolbarButton(_ref) {
6
+ var _api$trackChanges;
7
+ var api = _ref.api;
8
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['trackChanges'], function (states) {
9
+ var _states$trackChangesS, _states$trackChangesS2;
10
+ return {
11
+ isDisplayingChanges: (_states$trackChangesS = states.trackChangesState) === null || _states$trackChangesS === void 0 ? void 0 : _states$trackChangesS.isDisplayingChanges,
12
+ isShowDiffAvailable: (_states$trackChangesS2 = states.trackChangesState) === null || _states$trackChangesS2 === void 0 ? void 0 : _states$trackChangesS2.isShowDiffAvailable
13
+ };
14
+ }),
15
+ isDisplayingChanges = _useSharedPluginState.isDisplayingChanges,
16
+ isShowDiffAvailable = _useSharedPluginState.isShowDiffAvailable;
17
+ var handleClick = React.useCallback(function () {
18
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.trackChanges.commands.toggleChanges);
19
+ }, [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]);
20
+ return /*#__PURE__*/React.createElement(IconButton, {
21
+ icon: HistoryIcon,
22
+ label: "Track Changes",
23
+ appearance: "subtle",
24
+ isDisabled: !isShowDiffAvailable,
25
+ isSelected: isDisplayingChanges,
26
+ onClick: handleClick
27
+ });
28
+ };
@@ -1,13 +1,18 @@
1
- import { ChangeSet } from 'prosemirror-changeset';
2
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
+ import { type Step } from '@atlaskit/editor-prosemirror/transform';
5
+ import type { TrackChangesPlugin } from '../trackChangesPluginType';
5
6
  export declare const trackChangesPluginKey: PluginKey<TrackChangesPluginState>;
6
7
  type TrackChangesPluginState = {
7
8
  shouldChangesBeDisplayed: boolean;
8
9
  isShowDiffAvailable: boolean;
9
- baselineDoc: PMNode;
10
- changes: ChangeSet;
10
+ steps: InvertableStep[];
11
11
  };
12
- export declare const createTrackChangesPlugin: () => SafePlugin<TrackChangesPluginState>;
12
+ export declare class InvertableStep {
13
+ readonly step: Step;
14
+ readonly inverted: Step;
15
+ constructor(step: Step, inverted: Step);
16
+ }
17
+ export declare const createTrackChangesPlugin: (api: ExtractInjectionAPI<TrackChangesPlugin> | undefined) => SafePlugin<TrackChangesPluginState>;
13
18
  export {};
@@ -1,4 +1,6 @@
1
- import type { EditorCommand, NextEditorPlugin } from '@atlaskit/editor-common/types';
1
+ import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import { type PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
3
+ import type { ShowDiffPlugin } from '@atlaskit/editor-plugin-show-diff';
2
4
  export type TrackChangesPlugin = NextEditorPlugin<'trackChanges', {
3
5
  commands: {
4
6
  /**
@@ -6,6 +8,7 @@ export type TrackChangesPlugin = NextEditorPlugin<'trackChanges', {
6
8
  */
7
9
  toggleChanges: EditorCommand;
8
10
  };
11
+ dependencies: [OptionalPlugin<PrimaryToolbarPlugin>, ShowDiffPlugin];
9
12
  sharedState: {
10
13
  /**
11
14
  * Whether the track changes feature is currently displaying changes.
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import { type TrackChangesPlugin } from '../trackChangesPluginType';
4
+ type TrackChangesToolbarButtonProps = {
5
+ api: ExtractInjectionAPI<TrackChangesPlugin> | undefined;
6
+ };
7
+ export declare const TrackChangesToolbarButton: ({ api }: TrackChangesToolbarButtonProps) => React.JSX.Element;
8
+ export {};
@@ -1,13 +1,18 @@
1
- import { ChangeSet } from 'prosemirror-changeset';
2
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
+ import { type Step } from '@atlaskit/editor-prosemirror/transform';
5
+ import type { TrackChangesPlugin } from '../trackChangesPluginType';
5
6
  export declare const trackChangesPluginKey: PluginKey<TrackChangesPluginState>;
6
7
  type TrackChangesPluginState = {
7
8
  shouldChangesBeDisplayed: boolean;
8
9
  isShowDiffAvailable: boolean;
9
- baselineDoc: PMNode;
10
- changes: ChangeSet;
10
+ steps: InvertableStep[];
11
11
  };
12
- export declare const createTrackChangesPlugin: () => SafePlugin<TrackChangesPluginState>;
12
+ export declare class InvertableStep {
13
+ readonly step: Step;
14
+ readonly inverted: Step;
15
+ constructor(step: Step, inverted: Step);
16
+ }
17
+ export declare const createTrackChangesPlugin: (api: ExtractInjectionAPI<TrackChangesPlugin> | undefined) => SafePlugin<TrackChangesPluginState>;
13
18
  export {};
@@ -1,4 +1,6 @@
1
- import type { EditorCommand, NextEditorPlugin } from '@atlaskit/editor-common/types';
1
+ import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import { type PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
3
+ import type { ShowDiffPlugin } from '@atlaskit/editor-plugin-show-diff';
2
4
  export type TrackChangesPlugin = NextEditorPlugin<'trackChanges', {
3
5
  commands: {
4
6
  /**
@@ -6,6 +8,10 @@ export type TrackChangesPlugin = NextEditorPlugin<'trackChanges', {
6
8
  */
7
9
  toggleChanges: EditorCommand;
8
10
  };
11
+ dependencies: [
12
+ OptionalPlugin<PrimaryToolbarPlugin>,
13
+ ShowDiffPlugin
14
+ ];
9
15
  sharedState: {
10
16
  /**
11
17
  * Whether the track changes feature is currently displaying changes.
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import { type TrackChangesPlugin } from '../trackChangesPluginType';
4
+ type TrackChangesToolbarButtonProps = {
5
+ api: ExtractInjectionAPI<TrackChangesPlugin> | undefined;
6
+ };
7
+ export declare const TrackChangesToolbarButton: ({ api }: TrackChangesToolbarButtonProps) => React.JSX.Element;
8
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-track-changes",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "ShowDiff plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,13 +31,15 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
+ "@atlaskit/button": "^23.3.0",
35
+ "@atlaskit/editor-plugin-primary-toolbar": "^4.1.0",
36
+ "@atlaskit/editor-plugin-show-diff": "0.0.0",
34
37
  "@atlaskit/editor-prosemirror": "7.0.0",
35
- "@atlaskit/tokens": "^5.6.0",
36
- "@babel/runtime": "^7.0.0",
37
- "prosemirror-changeset": "^2.2.1"
38
+ "@atlaskit/icon-lab": "^5.2.0",
39
+ "@babel/runtime": "^7.0.0"
38
40
  },
39
41
  "peerDependencies": {
40
- "@atlaskit/editor-common": "^107.12.0",
42
+ "@atlaskit/editor-common": "^107.13.0",
41
43
  "react": "^18.2.0"
42
44
  },
43
45
  "devDependencies": {
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createInlineChangedDecoration = exports.createDeletedContentDecoration = void 0;
7
- var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
8
- var _model = require("@atlaskit/editor-prosemirror/model");
9
- var _view = require("@atlaskit/editor-prosemirror/view");
10
- var style = (0, _lazyNodeView.convertToInlineCss)({
11
- background: "var(--ds-background-accent-purple-subtlest, #F3F0FF)",
12
- textDecoration: 'underline',
13
- textDecorationStyle: 'dotted',
14
- textDecorationThickness: "var(--ds-space-025, 2px)",
15
- textDecorationColor: "var(--ds-border-accent-purple, #8270DB)"
16
- });
17
-
18
- /**
19
- * Inline decoration used for insertions as the content already exists in the document
20
- *
21
- * @param change Changeset "change" containing information about the change content + range
22
- * @returns Prosemirror inline decoration
23
- */
24
- var createInlineChangedDecoration = exports.createInlineChangedDecoration = function createInlineChangedDecoration(change) {
25
- return _view.Decoration.inline(change.fromB, change.toB, {
26
- style: style
27
- }, {});
28
- };
29
- var deletedContentStyle = (0, _lazyNodeView.convertToInlineCss)({
30
- color: "var(--ds-text-accent-gray, #44546F)",
31
- textDecoration: 'line-through'
32
- });
33
-
34
- /**
35
- * Creates a widget to represent the deleted content in the editor
36
- *
37
- * @param props.change Changeset "change" containing information about the change content + range
38
- * @param props.doc Baseline doc to compare against
39
- * @param props.tr The relevant transaction this decoration is being created against
40
- * @returns Prosemirror widget decoration
41
- */
42
- var createDeletedContentDecoration = exports.createDeletedContentDecoration = function createDeletedContentDecoration(_ref) {
43
- var change = _ref.change,
44
- doc = _ref.doc,
45
- tr = _ref.tr;
46
- var dom = document.createElement('span');
47
- dom.setAttribute('style', deletedContentStyle);
48
- dom.appendChild(_model.DOMSerializer.fromSchema(tr.doc.type.schema).serializeFragment(doc.slice(change.fromA, change.toA).content));
49
-
50
- // Widget decoration used for deletions as the content is not in the document
51
- // and we want to display the deleted content with a style.
52
- return _view.Decoration.widget(change.fromB, dom, {
53
- marks: []
54
- });
55
- };
@@ -1,48 +0,0 @@
1
- import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
2
- import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
3
- import { Decoration } from '@atlaskit/editor-prosemirror/view';
4
- const style = convertToInlineCss({
5
- background: "var(--ds-background-accent-purple-subtlest, #F3F0FF)",
6
- textDecoration: 'underline',
7
- textDecorationStyle: 'dotted',
8
- textDecorationThickness: "var(--ds-space-025, 2px)",
9
- textDecorationColor: "var(--ds-border-accent-purple, #8270DB)"
10
- });
11
-
12
- /**
13
- * Inline decoration used for insertions as the content already exists in the document
14
- *
15
- * @param change Changeset "change" containing information about the change content + range
16
- * @returns Prosemirror inline decoration
17
- */
18
- export const createInlineChangedDecoration = change => Decoration.inline(change.fromB, change.toB, {
19
- style
20
- }, {});
21
- const deletedContentStyle = convertToInlineCss({
22
- color: "var(--ds-text-accent-gray, #44546F)",
23
- textDecoration: 'line-through'
24
- });
25
-
26
- /**
27
- * Creates a widget to represent the deleted content in the editor
28
- *
29
- * @param props.change Changeset "change" containing information about the change content + range
30
- * @param props.doc Baseline doc to compare against
31
- * @param props.tr The relevant transaction this decoration is being created against
32
- * @returns Prosemirror widget decoration
33
- */
34
- export const createDeletedContentDecoration = ({
35
- change,
36
- doc,
37
- tr
38
- }) => {
39
- const dom = document.createElement('span');
40
- dom.setAttribute('style', deletedContentStyle);
41
- dom.appendChild(DOMSerializer.fromSchema(tr.doc.type.schema).serializeFragment(doc.slice(change.fromA, change.toA).content));
42
-
43
- // Widget decoration used for deletions as the content is not in the document
44
- // and we want to display the deleted content with a style.
45
- return Decoration.widget(change.fromB, dom, {
46
- marks: []
47
- });
48
- };
@@ -1,49 +0,0 @@
1
- import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
2
- import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
3
- import { Decoration } from '@atlaskit/editor-prosemirror/view';
4
- var style = convertToInlineCss({
5
- background: "var(--ds-background-accent-purple-subtlest, #F3F0FF)",
6
- textDecoration: 'underline',
7
- textDecorationStyle: 'dotted',
8
- textDecorationThickness: "var(--ds-space-025, 2px)",
9
- textDecorationColor: "var(--ds-border-accent-purple, #8270DB)"
10
- });
11
-
12
- /**
13
- * Inline decoration used for insertions as the content already exists in the document
14
- *
15
- * @param change Changeset "change" containing information about the change content + range
16
- * @returns Prosemirror inline decoration
17
- */
18
- export var createInlineChangedDecoration = function createInlineChangedDecoration(change) {
19
- return Decoration.inline(change.fromB, change.toB, {
20
- style: style
21
- }, {});
22
- };
23
- var deletedContentStyle = convertToInlineCss({
24
- color: "var(--ds-text-accent-gray, #44546F)",
25
- textDecoration: 'line-through'
26
- });
27
-
28
- /**
29
- * Creates a widget to represent the deleted content in the editor
30
- *
31
- * @param props.change Changeset "change" containing information about the change content + range
32
- * @param props.doc Baseline doc to compare against
33
- * @param props.tr The relevant transaction this decoration is being created against
34
- * @returns Prosemirror widget decoration
35
- */
36
- export var createDeletedContentDecoration = function createDeletedContentDecoration(_ref) {
37
- var change = _ref.change,
38
- doc = _ref.doc,
39
- tr = _ref.tr;
40
- var dom = document.createElement('span');
41
- dom.setAttribute('style', deletedContentStyle);
42
- dom.appendChild(DOMSerializer.fromSchema(tr.doc.type.schema).serializeFragment(doc.slice(change.fromA, change.toA).content));
43
-
44
- // Widget decoration used for deletions as the content is not in the document
45
- // and we want to display the deleted content with a style.
46
- return Decoration.widget(change.fromB, dom, {
47
- marks: []
48
- });
49
- };
@@ -1,26 +0,0 @@
1
- import type { Change } from 'prosemirror-changeset';
2
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
4
- import { Decoration } from '@atlaskit/editor-prosemirror/view';
5
- /**
6
- * Inline decoration used for insertions as the content already exists in the document
7
- *
8
- * @param change Changeset "change" containing information about the change content + range
9
- * @returns Prosemirror inline decoration
10
- */
11
- export declare const createInlineChangedDecoration: (change: Change) => Decoration;
12
- interface DeletedContentDecorationProps {
13
- change: Change;
14
- doc: PMNode;
15
- tr: Transaction;
16
- }
17
- /**
18
- * Creates a widget to represent the deleted content in the editor
19
- *
20
- * @param props.change Changeset "change" containing information about the change content + range
21
- * @param props.doc Baseline doc to compare against
22
- * @param props.tr The relevant transaction this decoration is being created against
23
- * @returns Prosemirror widget decoration
24
- */
25
- export declare const createDeletedContentDecoration: ({ change, doc, tr, }: DeletedContentDecorationProps) => Decoration;
26
- export {};
@@ -1,26 +0,0 @@
1
- import type { Change } from 'prosemirror-changeset';
2
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
4
- import { Decoration } from '@atlaskit/editor-prosemirror/view';
5
- /**
6
- * Inline decoration used for insertions as the content already exists in the document
7
- *
8
- * @param change Changeset "change" containing information about the change content + range
9
- * @returns Prosemirror inline decoration
10
- */
11
- export declare const createInlineChangedDecoration: (change: Change) => Decoration;
12
- interface DeletedContentDecorationProps {
13
- change: Change;
14
- doc: PMNode;
15
- tr: Transaction;
16
- }
17
- /**
18
- * Creates a widget to represent the deleted content in the editor
19
- *
20
- * @param props.change Changeset "change" containing information about the change content + range
21
- * @param props.doc Baseline doc to compare against
22
- * @param props.tr The relevant transaction this decoration is being created against
23
- * @returns Prosemirror widget decoration
24
- */
25
- export declare const createDeletedContentDecoration: ({ change, doc, tr, }: DeletedContentDecorationProps) => Decoration;
26
- export {};