@atlaskit/editor-plugin-track-changes 1.0.0 → 2.0.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,13 @@
1
1
  # @atlaskit/editor-plugin-track-changes
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#185139](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/185139)
8
+ [`710f9b65a743a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/710f9b65a743a) -
9
+ [EDITOR-1014] Setup basic plugin diffing functionality and documentation
10
+
3
11
  ## 1.0.0
4
12
 
5
13
  ### Major Changes
@@ -1,28 +1,107 @@
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.trackChangesPluginKey = exports.createTrackChangesPlugin = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _prosemirrorChangeset = require("prosemirror-changeset");
10
+ var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
7
11
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
12
+ var _model = require("@atlaskit/editor-prosemirror/model");
8
13
  var _state = require("@atlaskit/editor-prosemirror/state");
9
- var trackChangesPluginKey = exports.trackChangesPluginKey = new _state.PluginKey('showDiffPlugin');
10
-
11
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
12
-
14
+ var _view = require("@atlaskit/editor-prosemirror/view");
15
+ var _types = require("./types");
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
+ 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
+ var trackChangesPluginKey = exports.trackChangesPluginKey = new _state.PluginKey('trackChangesPlugin');
13
19
  var createTrackChangesPlugin = exports.createTrackChangesPlugin = function createTrackChangesPlugin() {
14
20
  return new _safePlugin.SafePlugin({
15
21
  key: trackChangesPluginKey,
16
22
  state: {
17
- init: function init() {
18
- return {};
23
+ init: function init(_, _ref) {
24
+ var doc = _ref.doc;
25
+ return {
26
+ changes: _prosemirrorChangeset.ChangeSet.create(doc),
27
+ shouldChangesBeDispalyed: false,
28
+ baselineDoc: doc,
29
+ numOfChanges: 0
30
+ };
19
31
  },
20
- apply: function apply(tr, currentPluginState) {
21
- var meta = tr.getMeta(trackChangesPluginKey);
22
- if (meta) {
23
- return meta;
32
+ apply: function apply(tr, state, oldState, newState) {
33
+ var metadata = tr.getMeta(trackChangesPluginKey);
34
+ if (metadata) {
35
+ if (metadata.action === _types.TOGGLE_TRACK_CHANGES_ACTION.TOGGLE_TRACK_CHANGES) {
36
+ return _objectSpread(_objectSpread({}, state), {}, {
37
+ baselineDoc: state.shouldChangesBeDispalyed ? tr.doc : state.baselineDoc,
38
+ shouldChangesBeDispalyed: !state.shouldChangesBeDispalyed,
39
+ changes: state.shouldChangesBeDispalyed ? _prosemirrorChangeset.ChangeSet.create(tr.doc) : state.changes
40
+ });
41
+ }
42
+ }
43
+ if (!tr.docChanged || tr.getMeta('isRemote')) {
44
+ // If no document changes, return the old changeSet
45
+ return state;
46
+ }
47
+
48
+ // Create a new ChangeSet based on document changes
49
+ return _objectSpread(_objectSpread({}, state), {}, {
50
+ shouldChangesBeDispalyed: false,
51
+ changes: state.changes.addSteps(tr.doc,
52
+ // The new document
53
+ tr.mapping.maps,
54
+ // The set of changes
55
+ tr.docs[0].content // The old document
56
+ )
57
+ });
58
+ }
59
+ },
60
+ props: {
61
+ decorations: function decorations(state) {
62
+ var pluginState = trackChangesPluginKey.getState(state);
63
+ if (pluginState && pluginState.shouldChangesBeDispalyed && pluginState.changes) {
64
+ var decoration = _view.DecorationSet.empty;
65
+ var decorations = [];
66
+ var changes = (0, _prosemirrorChangeset.simplifyChanges)(pluginState.changes.changes, state.doc);
67
+ var tr = state.tr;
68
+ changes.forEach(function (change) {
69
+ if (change.inserted.length > 0) {
70
+ var style = (0, _lazyNodeView.convertToInlineCss)({
71
+ background: "var(--ds-background-accent-purple-subtlest, #F3F0FF)",
72
+ textDecoration: 'underline',
73
+ textDecorationStyle: 'dotted',
74
+ textDecorationThickness: "var(--ds-space-025, 2px)",
75
+ textDecorationColor: "var(--ds-border-accent-purple, #8270DB)"
76
+ });
77
+
78
+ // Inline decoration used for insertions as the content already exists in the document
79
+ // and we just want to style it.
80
+ var insertionInlineDecoration = _view.Decoration.inline(change.fromB, change.toB, {
81
+ style: style
82
+ }, {});
83
+ decorations.push(insertionInlineDecoration);
84
+ }
85
+ if (change.deleted.length > 0) {
86
+ var dom = document.createElement('span');
87
+ var _style = (0, _lazyNodeView.convertToInlineCss)({
88
+ color: "var(--ds-text-accent-gray, #44546F)",
89
+ textDecoration: 'line-through'
90
+ });
91
+ dom.setAttribute('style', _style);
92
+ dom.appendChild(_model.DOMSerializer.fromSchema(tr.doc.type.schema).serializeFragment(pluginState === null || pluginState === void 0 ? void 0 : pluginState.baselineDoc.slice(change.fromA, change.toA).content));
93
+
94
+ // Widget decoration used for deletions as the content is not in the document
95
+ // and we want to display the deleted content with a style.
96
+ var deletionWidgetDecoration = _view.Decoration.widget(change.fromB, dom, {
97
+ marks: []
98
+ });
99
+ decorations.push(deletionWidgetDecoration);
100
+ }
101
+ });
102
+ return decoration.add(tr.doc, decorations);
24
103
  }
25
- return currentPluginState;
104
+ return undefined;
26
105
  }
27
106
  }
28
107
  });
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TOGGLE_TRACK_CHANGES_ACTION = void 0;
7
+ var TOGGLE_TRACK_CHANGES_ACTION = exports.TOGGLE_TRACK_CHANGES_ACTION = /*#__PURE__*/function (TOGGLE_TRACK_CHANGES_ACTION) {
8
+ TOGGLE_TRACK_CHANGES_ACTION["TOGGLE_TRACK_CHANGES"] = "TOGGLE_TRACK_CHANGES";
9
+ return TOGGLE_TRACK_CHANGES_ACTION;
10
+ }({});
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.trackChangesPlugin = void 0;
7
7
  var _main = require("./pm-plugins/main");
8
+ var _types = require("./pm-plugins/types");
8
9
  var trackChangesPlugin = exports.trackChangesPlugin = function trackChangesPlugin() {
9
10
  return {
10
11
  name: 'trackChanges',
@@ -15,10 +16,23 @@ var trackChangesPlugin = exports.trackChangesPlugin = function trackChangesPlugi
15
16
  }];
16
17
  },
17
18
  commands: {
18
- setBaseline: function setBaseline(_ref) {
19
+ toggleChanges: function toggleChanges(_ref) {
19
20
  var tr = _ref.tr;
20
- return tr.setMeta('setBaseline', true);
21
+ return tr.setMeta(_main.trackChangesPluginKey, {
22
+ action: _types.TOGGLE_TRACK_CHANGES_ACTION.TOGGLE_TRACK_CHANGES
23
+ });
21
24
  }
25
+ },
26
+ getSharedState: function getSharedState(editorState) {
27
+ var _trackChangesPluginKe;
28
+ if (!editorState) {
29
+ return {
30
+ isDisplayingChanges: false
31
+ };
32
+ }
33
+ return {
34
+ isDisplayingChanges: Boolean((_trackChangesPluginKe = _main.trackChangesPluginKey.getState(editorState)) === null || _trackChangesPluginKe === void 0 ? void 0 : _trackChangesPluginKe.enable)
35
+ };
22
36
  }
23
37
  };
24
38
  };
@@ -1,22 +1,100 @@
1
+ import { ChangeSet, simplifyChanges } from 'prosemirror-changeset';
2
+ import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
1
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
+ import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
2
5
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- export const trackChangesPluginKey = new PluginKey('showDiffPlugin');
4
-
5
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
6
-
6
+ import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
+ import { TOGGLE_TRACK_CHANGES_ACTION as ACTION } from './types';
8
+ export const trackChangesPluginKey = new PluginKey('trackChangesPlugin');
7
9
  export const createTrackChangesPlugin = () => {
8
10
  return new SafePlugin({
9
11
  key: trackChangesPluginKey,
10
12
  state: {
11
- init() {
12
- return {};
13
+ init(_, {
14
+ doc
15
+ }) {
16
+ return {
17
+ changes: ChangeSet.create(doc),
18
+ shouldChangesBeDispalyed: false,
19
+ baselineDoc: doc,
20
+ numOfChanges: 0
21
+ };
13
22
  },
14
- apply: (tr, currentPluginState) => {
15
- const meta = tr.getMeta(trackChangesPluginKey);
16
- if (meta) {
17
- return meta;
23
+ apply(tr, state, oldState, newState) {
24
+ const metadata = tr.getMeta(trackChangesPluginKey);
25
+ if (metadata) {
26
+ if (metadata.action === ACTION.TOGGLE_TRACK_CHANGES) {
27
+ return {
28
+ ...state,
29
+ baselineDoc: state.shouldChangesBeDispalyed ? tr.doc : state.baselineDoc,
30
+ shouldChangesBeDispalyed: !state.shouldChangesBeDispalyed,
31
+ changes: state.shouldChangesBeDispalyed ? ChangeSet.create(tr.doc) : state.changes
32
+ };
33
+ }
34
+ }
35
+ if (!tr.docChanged || tr.getMeta('isRemote')) {
36
+ // If no document changes, return the old changeSet
37
+ return state;
38
+ }
39
+
40
+ // Create a new ChangeSet based on document changes
41
+ return {
42
+ ...state,
43
+ shouldChangesBeDispalyed: false,
44
+ changes: state.changes.addSteps(tr.doc,
45
+ // The new document
46
+ tr.mapping.maps,
47
+ // The set of changes
48
+ tr.docs[0].content // The old document
49
+ )
50
+ };
51
+ }
52
+ },
53
+ props: {
54
+ decorations: state => {
55
+ const pluginState = trackChangesPluginKey.getState(state);
56
+ if (pluginState && pluginState.shouldChangesBeDispalyed && pluginState.changes) {
57
+ const decoration = DecorationSet.empty;
58
+ const decorations = [];
59
+ const changes = simplifyChanges(pluginState.changes.changes, state.doc);
60
+ const tr = state.tr;
61
+ changes.forEach(change => {
62
+ if (change.inserted.length > 0) {
63
+ const style = convertToInlineCss({
64
+ background: "var(--ds-background-accent-purple-subtlest, #F3F0FF)",
65
+ textDecoration: 'underline',
66
+ textDecorationStyle: 'dotted',
67
+ textDecorationThickness: "var(--ds-space-025, 2px)",
68
+ textDecorationColor: "var(--ds-border-accent-purple, #8270DB)"
69
+ });
70
+
71
+ // Inline decoration used for insertions as the content already exists in the document
72
+ // and we just want to style it.
73
+ const insertionInlineDecoration = Decoration.inline(change.fromB, change.toB, {
74
+ style
75
+ }, {});
76
+ decorations.push(insertionInlineDecoration);
77
+ }
78
+ if (change.deleted.length > 0) {
79
+ const dom = document.createElement('span');
80
+ const style = convertToInlineCss({
81
+ color: "var(--ds-text-accent-gray, #44546F)",
82
+ textDecoration: 'line-through'
83
+ });
84
+ dom.setAttribute('style', style);
85
+ dom.appendChild(DOMSerializer.fromSchema(tr.doc.type.schema).serializeFragment(pluginState === null || pluginState === void 0 ? void 0 : pluginState.baselineDoc.slice(change.fromA, change.toA).content));
86
+
87
+ // Widget decoration used for deletions as the content is not in the document
88
+ // and we want to display the deleted content with a style.
89
+ const deletionWidgetDecoration = Decoration.widget(change.fromB, dom, {
90
+ marks: []
91
+ });
92
+ decorations.push(deletionWidgetDecoration);
93
+ }
94
+ });
95
+ return decoration.add(tr.doc, decorations);
18
96
  }
19
- return currentPluginState;
97
+ return undefined;
20
98
  }
21
99
  }
22
100
  });
@@ -0,0 +1,4 @@
1
+ export let TOGGLE_TRACK_CHANGES_ACTION = /*#__PURE__*/function (TOGGLE_TRACK_CHANGES_ACTION) {
2
+ TOGGLE_TRACK_CHANGES_ACTION["TOGGLE_TRACK_CHANGES"] = "TOGGLE_TRACK_CHANGES";
3
+ return TOGGLE_TRACK_CHANGES_ACTION;
4
+ }({});
@@ -1,4 +1,5 @@
1
- import { createTrackChangesPlugin } from './pm-plugins/main';
1
+ import { createTrackChangesPlugin, trackChangesPluginKey } from './pm-plugins/main';
2
+ import { TOGGLE_TRACK_CHANGES_ACTION as ACTION } from './pm-plugins/types';
2
3
  export const trackChangesPlugin = () => ({
3
4
  name: 'trackChanges',
4
5
  pmPlugins() {
@@ -8,10 +9,23 @@ export const trackChangesPlugin = () => ({
8
9
  }];
9
10
  },
10
11
  commands: {
11
- setBaseline: ({
12
+ toggleChanges: ({
12
13
  tr
13
14
  }) => {
14
- return tr.setMeta('setBaseline', true);
15
+ return tr.setMeta(trackChangesPluginKey, {
16
+ action: ACTION.TOGGLE_TRACK_CHANGES
17
+ });
15
18
  }
19
+ },
20
+ getSharedState: editorState => {
21
+ var _trackChangesPluginKe;
22
+ if (!editorState) {
23
+ return {
24
+ isDisplayingChanges: false
25
+ };
26
+ }
27
+ return {
28
+ isDisplayingChanges: Boolean((_trackChangesPluginKe = trackChangesPluginKey.getState(editorState)) === null || _trackChangesPluginKe === void 0 ? void 0 : _trackChangesPluginKe.enable)
29
+ };
16
30
  }
17
31
  });
@@ -1,22 +1,100 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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
+ 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';
5
+ import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
1
6
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
+ import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
2
8
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- export var trackChangesPluginKey = new PluginKey('showDiffPlugin');
4
-
5
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
6
-
9
+ import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
10
+ import { TOGGLE_TRACK_CHANGES_ACTION as ACTION } from './types';
11
+ export var trackChangesPluginKey = new PluginKey('trackChangesPlugin');
7
12
  export var createTrackChangesPlugin = function createTrackChangesPlugin() {
8
13
  return new SafePlugin({
9
14
  key: trackChangesPluginKey,
10
15
  state: {
11
- init: function init() {
12
- return {};
16
+ init: function init(_, _ref) {
17
+ var doc = _ref.doc;
18
+ return {
19
+ changes: ChangeSet.create(doc),
20
+ shouldChangesBeDispalyed: false,
21
+ baselineDoc: doc,
22
+ numOfChanges: 0
23
+ };
13
24
  },
14
- apply: function apply(tr, currentPluginState) {
15
- var meta = tr.getMeta(trackChangesPluginKey);
16
- if (meta) {
17
- return meta;
25
+ apply: function apply(tr, state, oldState, newState) {
26
+ var metadata = tr.getMeta(trackChangesPluginKey);
27
+ if (metadata) {
28
+ if (metadata.action === ACTION.TOGGLE_TRACK_CHANGES) {
29
+ return _objectSpread(_objectSpread({}, state), {}, {
30
+ baselineDoc: state.shouldChangesBeDispalyed ? tr.doc : state.baselineDoc,
31
+ shouldChangesBeDispalyed: !state.shouldChangesBeDispalyed,
32
+ changes: state.shouldChangesBeDispalyed ? ChangeSet.create(tr.doc) : state.changes
33
+ });
34
+ }
35
+ }
36
+ if (!tr.docChanged || tr.getMeta('isRemote')) {
37
+ // If no document changes, return the old changeSet
38
+ return state;
39
+ }
40
+
41
+ // Create a new ChangeSet based on document changes
42
+ return _objectSpread(_objectSpread({}, state), {}, {
43
+ shouldChangesBeDispalyed: false,
44
+ changes: state.changes.addSteps(tr.doc,
45
+ // The new document
46
+ tr.mapping.maps,
47
+ // The set of changes
48
+ tr.docs[0].content // The old document
49
+ )
50
+ });
51
+ }
52
+ },
53
+ props: {
54
+ decorations: function decorations(state) {
55
+ var pluginState = trackChangesPluginKey.getState(state);
56
+ if (pluginState && pluginState.shouldChangesBeDispalyed && pluginState.changes) {
57
+ var decoration = DecorationSet.empty;
58
+ var decorations = [];
59
+ var changes = simplifyChanges(pluginState.changes.changes, state.doc);
60
+ var tr = state.tr;
61
+ changes.forEach(function (change) {
62
+ if (change.inserted.length > 0) {
63
+ var style = convertToInlineCss({
64
+ background: "var(--ds-background-accent-purple-subtlest, #F3F0FF)",
65
+ textDecoration: 'underline',
66
+ textDecorationStyle: 'dotted',
67
+ textDecorationThickness: "var(--ds-space-025, 2px)",
68
+ textDecorationColor: "var(--ds-border-accent-purple, #8270DB)"
69
+ });
70
+
71
+ // Inline decoration used for insertions as the content already exists in the document
72
+ // and we just want to style it.
73
+ var insertionInlineDecoration = Decoration.inline(change.fromB, change.toB, {
74
+ style: style
75
+ }, {});
76
+ decorations.push(insertionInlineDecoration);
77
+ }
78
+ if (change.deleted.length > 0) {
79
+ var dom = document.createElement('span');
80
+ var _style = convertToInlineCss({
81
+ color: "var(--ds-text-accent-gray, #44546F)",
82
+ textDecoration: 'line-through'
83
+ });
84
+ dom.setAttribute('style', _style);
85
+ dom.appendChild(DOMSerializer.fromSchema(tr.doc.type.schema).serializeFragment(pluginState === null || pluginState === void 0 ? void 0 : pluginState.baselineDoc.slice(change.fromA, change.toA).content));
86
+
87
+ // Widget decoration used for deletions as the content is not in the document
88
+ // and we want to display the deleted content with a style.
89
+ var deletionWidgetDecoration = Decoration.widget(change.fromB, dom, {
90
+ marks: []
91
+ });
92
+ decorations.push(deletionWidgetDecoration);
93
+ }
94
+ });
95
+ return decoration.add(tr.doc, decorations);
18
96
  }
19
- return currentPluginState;
97
+ return undefined;
20
98
  }
21
99
  }
22
100
  });
@@ -0,0 +1,4 @@
1
+ export var TOGGLE_TRACK_CHANGES_ACTION = /*#__PURE__*/function (TOGGLE_TRACK_CHANGES_ACTION) {
2
+ TOGGLE_TRACK_CHANGES_ACTION["TOGGLE_TRACK_CHANGES"] = "TOGGLE_TRACK_CHANGES";
3
+ return TOGGLE_TRACK_CHANGES_ACTION;
4
+ }({});
@@ -1,4 +1,5 @@
1
- import { createTrackChangesPlugin } from './pm-plugins/main';
1
+ import { createTrackChangesPlugin, trackChangesPluginKey } from './pm-plugins/main';
2
+ import { TOGGLE_TRACK_CHANGES_ACTION as ACTION } from './pm-plugins/types';
2
3
  export var trackChangesPlugin = function trackChangesPlugin() {
3
4
  return {
4
5
  name: 'trackChanges',
@@ -9,10 +10,23 @@ export var trackChangesPlugin = function trackChangesPlugin() {
9
10
  }];
10
11
  },
11
12
  commands: {
12
- setBaseline: function setBaseline(_ref) {
13
+ toggleChanges: function toggleChanges(_ref) {
13
14
  var tr = _ref.tr;
14
- return tr.setMeta('setBaseline', true);
15
+ return tr.setMeta(trackChangesPluginKey, {
16
+ action: ACTION.TOGGLE_TRACK_CHANGES
17
+ });
15
18
  }
19
+ },
20
+ getSharedState: function getSharedState(editorState) {
21
+ var _trackChangesPluginKe;
22
+ if (!editorState) {
23
+ return {
24
+ isDisplayingChanges: false
25
+ };
26
+ }
27
+ return {
28
+ isDisplayingChanges: Boolean((_trackChangesPluginKe = trackChangesPluginKey.getState(editorState)) === null || _trackChangesPluginKe === void 0 ? void 0 : _trackChangesPluginKe.enable)
29
+ };
16
30
  }
17
31
  };
18
32
  };
@@ -1,6 +1,12 @@
1
+ import { ChangeSet } from 'prosemirror-changeset';
1
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
4
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
5
  export declare const trackChangesPluginKey: PluginKey<any>;
4
- type TrackChangesPluginState = {};
6
+ type TrackChangesPluginState = {
7
+ shouldChangesBeDispalyed: boolean;
8
+ baselineDoc: PMNode;
9
+ changes: ChangeSet;
10
+ };
5
11
  export declare const createTrackChangesPlugin: () => SafePlugin<TrackChangesPluginState>;
6
12
  export {};
@@ -0,0 +1,3 @@
1
+ export declare enum TOGGLE_TRACK_CHANGES_ACTION {
2
+ TOGGLE_TRACK_CHANGES = "TOGGLE_TRACK_CHANGES"
3
+ }
@@ -1,2 +1,16 @@
1
- import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
2
- export type TrackChangesPlugin = NextEditorPlugin<'trackChanges'>;
1
+ import type { EditorCommand, NextEditorPlugin } from '@atlaskit/editor-common/types';
2
+ export type TrackChangesPlugin = NextEditorPlugin<'trackChanges', {
3
+ commands: {
4
+ /**
5
+ * Toggles the displaying of changes in the editor.
6
+ */
7
+ toggleChanges: EditorCommand;
8
+ };
9
+ sharedState: {
10
+ /**
11
+ * Whether the track changes feature is currently displaying changes.
12
+ * Defaults to false.
13
+ */
14
+ isDisplayingChanges: boolean;
15
+ };
16
+ }>;
@@ -1,6 +1,12 @@
1
+ import { ChangeSet } from 'prosemirror-changeset';
1
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
4
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
5
  export declare const trackChangesPluginKey: PluginKey<any>;
4
- type TrackChangesPluginState = {};
6
+ type TrackChangesPluginState = {
7
+ shouldChangesBeDispalyed: boolean;
8
+ baselineDoc: PMNode;
9
+ changes: ChangeSet;
10
+ };
5
11
  export declare const createTrackChangesPlugin: () => SafePlugin<TrackChangesPluginState>;
6
12
  export {};
@@ -0,0 +1,3 @@
1
+ export declare enum TOGGLE_TRACK_CHANGES_ACTION {
2
+ TOGGLE_TRACK_CHANGES = "TOGGLE_TRACK_CHANGES"
3
+ }
@@ -1,2 +1,16 @@
1
- import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
2
- export type TrackChangesPlugin = NextEditorPlugin<'trackChanges'>;
1
+ import type { EditorCommand, NextEditorPlugin } from '@atlaskit/editor-common/types';
2
+ export type TrackChangesPlugin = NextEditorPlugin<'trackChanges', {
3
+ commands: {
4
+ /**
5
+ * Toggles the displaying of changes in the editor.
6
+ */
7
+ toggleChanges: EditorCommand;
8
+ };
9
+ sharedState: {
10
+ /**
11
+ * Whether the track changes feature is currently displaying changes.
12
+ * Defaults to false.
13
+ */
14
+ isDisplayingChanges: boolean;
15
+ };
16
+ }>;
package/docs/0-intro.tsx CHANGED
@@ -30,7 +30,72 @@ The \`dependencies\`, \`configuration\`, \`state\`, \`actions\`, and \`commands\
30
30
  below:
31
31
 
32
32
  ${code`
33
- type TrackChangesPlugin = NextEditorPlugin<'trackChanges'>;
33
+ type TrackChangesPlugin = NextEditorPlugin<'trackChanges', {
34
+ commands: {
35
+ toggleChanges: EditorCommand
36
+ }
37
+ }>;
38
+ `}
39
+
40
+ ### Example Usage
41
+ ---
42
+ ${code`
43
+ import React from 'react';
44
+
45
+ import Button from '@atlaskit/button/new';
46
+ import { cssMap } from '@atlaskit/css';
47
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
48
+ import { ComposableEditor } from '@atlaskit/editor-core/composable-editor';
49
+ import { usePreset } from '@atlaskit/editor-core/use-preset';
50
+ import { basePlugin } from '@atlaskit/editor-plugins/base';
51
+ import { Box } from '@atlaskit/primitives/compiled';
52
+ import { token } from '@atlaskit/tokens';
53
+
54
+ import { trackChangesPlugin } from '../src/trackChangesPlugin';
55
+
56
+ const styles = cssMap({
57
+ aboveEditor: {
58
+ paddingTop: token('space.100'),
59
+ paddingBottom: token('space.100'),
60
+ },
61
+ everythingContainer: {
62
+ paddingTop: token('space.200'),
63
+ paddingBottom: token('space.200'),
64
+ paddingLeft: token('space.200'),
65
+ paddingRight: token('space.200'),
66
+ },
67
+ });
68
+
69
+ function Editor() {
70
+ const { preset, editorApi } = usePreset(
71
+ (builder) =>
72
+ builder.add(basePlugin).add(trackChangesPlugin),
73
+ [],
74
+ );
75
+
76
+ const isSelected = useSharedPluginStateSelector(editorApi, 'trackChanges.isDisplayingChanges');
77
+
78
+ return (
79
+ <Box xcss={styles.everythingContainer}>
80
+ <Box xcss={styles.aboveEditor}>
81
+ <Button
82
+ appearance="primary"
83
+ onClick={() => {
84
+ editorApi?.core.actions.execute(
85
+ editorApi?.trackChanges.commands.toggleChanges,
86
+ );
87
+ }}
88
+ isSelected={isSelected}
89
+ >
90
+ Show Diff
91
+ </Button>
92
+ </Box>
93
+ <ComposableEditor preset={preset} />
94
+ </Box>
95
+ );
96
+ }
97
+
98
+ export default Editor;
34
99
  `}
35
100
 
36
101
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-track-changes",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "ShowDiff plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -32,7 +32,9 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@atlaskit/editor-prosemirror": "7.0.0",
35
- "@babel/runtime": "^7.0.0"
35
+ "@atlaskit/tokens": "^5.5.0",
36
+ "@babel/runtime": "^7.0.0",
37
+ "prosemirror-changeset": "^2.2.1"
36
38
  },
37
39
  "peerDependencies": {
38
40
  "@atlaskit/editor-common": "^107.7.0",