@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 +24 -0
- package/README.md +88 -0
- package/afm-cc/tsconfig.json +16 -2
- package/afm-jira/tsconfig.json +16 -2
- package/afm-post-office/tsconfig.json +41 -0
- package/afm-rovo-extension/tsconfig.json +41 -0
- package/afm-townsquare/tsconfig.json +41 -0
- package/build/tsconfig.json +20 -15
- package/dist/cjs/pm-plugins/main.js +60 -48
- package/dist/cjs/trackChangesPlugin.js +23 -4
- package/dist/cjs/ui/TrackChangesToolbarButton.js +39 -0
- package/dist/es2019/pm-plugins/main.js +41 -48
- package/dist/es2019/trackChangesPlugin.js +47 -28
- package/dist/es2019/ui/TrackChangesToolbarButton.js +35 -0
- package/dist/esm/pm-plugins/main.js +59 -47
- package/dist/esm/trackChangesPlugin.js +22 -4
- package/dist/esm/ui/TrackChangesToolbarButton.js +32 -0
- package/dist/types/pm-plugins/main.d.ts +10 -5
- package/dist/types/trackChangesPluginType.d.ts +20 -1
- package/dist/types/ui/TrackChangesToolbarButton.d.ts +8 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +10 -5
- package/dist/types-ts4.5/trackChangesPluginType.d.ts +20 -1
- package/dist/types-ts4.5/ui/TrackChangesToolbarButton.d.ts +8 -0
- package/docs/0-intro.tsx +44 -7
- package/package.json +7 -4
- package/tsconfig.json +16 -10
- package/dist/cjs/pm-plugins/decorations.js +0 -55
- package/dist/es2019/pm-plugins/decorations.js +0 -48
- package/dist/esm/pm-plugins/decorations.js +0 -49
- package/dist/types/pm-plugins/decorations.d.ts +0 -26
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +0 -26
|
@@ -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
|
|
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
|
-
|
|
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
|
|
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
|
|
41
|
-
|
|
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
|
-
|
|
55
|
+
steps,
|
|
58
56
|
shouldChangesBeDisplayed: false,
|
|
59
|
-
changes,
|
|
60
57
|
isShowDiffAvailable: true
|
|
61
58
|
};
|
|
62
59
|
}
|
|
63
60
|
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
87
|
-
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
88
81
|
}
|
|
89
82
|
});
|
|
90
83
|
};
|
|
@@ -1,33 +1,52 @@
|
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
import { TrackChangesToolbarButton } from './ui/TrackChangesToolbarButton';
|
|
5
|
+
export const trackChangesPlugin = ({
|
|
6
|
+
api,
|
|
7
|
+
config: options
|
|
8
|
+
}) => {
|
|
9
|
+
const primaryToolbarComponent = () => {
|
|
10
|
+
return /*#__PURE__*/React.createElement(TrackChangesToolbarButton, {
|
|
11
|
+
api: api
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
if ((options === null || options === void 0 ? void 0 : options.showOnToolbar) === true) {
|
|
15
|
+
var _api$primaryToolbar, _api$primaryToolbar$a;
|
|
16
|
+
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({
|
|
17
|
+
name: 'trackChanges',
|
|
18
|
+
component: primaryToolbarComponent
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
name: 'trackChanges',
|
|
23
|
+
pmPlugins() {
|
|
24
|
+
return [{
|
|
25
|
+
name: 'trackChangesPlugin',
|
|
26
|
+
plugin: () => createTrackChangesPlugin(api)
|
|
27
|
+
}];
|
|
28
|
+
},
|
|
29
|
+
commands: {
|
|
30
|
+
toggleChanges: ({
|
|
31
|
+
tr
|
|
32
|
+
}) => {
|
|
33
|
+
return tr.setMeta(trackChangesPluginKey, {
|
|
34
|
+
action: ACTION.TOGGLE_TRACK_CHANGES
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
getSharedState: editorState => {
|
|
39
|
+
var _trackChangesPluginKe, _trackChangesPluginKe2;
|
|
40
|
+
if (!editorState) {
|
|
41
|
+
return {
|
|
42
|
+
isDisplayingChanges: false,
|
|
43
|
+
isShowDiffAvailable: false
|
|
44
|
+
};
|
|
45
|
+
}
|
|
23
46
|
return {
|
|
24
|
-
isDisplayingChanges:
|
|
25
|
-
isShowDiffAvailable:
|
|
47
|
+
isDisplayingChanges: Boolean((_trackChangesPluginKe = trackChangesPluginKey.getState(editorState)) === null || _trackChangesPluginKe === void 0 ? void 0 : _trackChangesPluginKe.shouldChangesBeDisplayed),
|
|
48
|
+
isShowDiffAvailable: Boolean((_trackChangesPluginKe2 = trackChangesPluginKey.getState(editorState)) === null || _trackChangesPluginKe2 === void 0 ? void 0 : _trackChangesPluginKe2.isShowDiffAvailable)
|
|
26
49
|
};
|
|
27
50
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
isShowDiffAvailable: Boolean((_trackChangesPluginKe2 = trackChangesPluginKey.getState(editorState)) === null || _trackChangesPluginKe2 === void 0 ? void 0 : _trackChangesPluginKe2.isShowDiffAvailable)
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
});
|
|
51
|
+
};
|
|
52
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl-next';
|
|
3
|
+
import { IconButton } from '@atlaskit/button/new';
|
|
4
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
5
|
+
import { trackChangesMessages } from '@atlaskit/editor-common/messages';
|
|
6
|
+
import HistoryIcon from '@atlaskit/icon-lab/core/history';
|
|
7
|
+
export const TrackChangesToolbarButton = ({
|
|
8
|
+
api
|
|
9
|
+
}) => {
|
|
10
|
+
var _api$trackChanges;
|
|
11
|
+
const {
|
|
12
|
+
isDisplayingChanges,
|
|
13
|
+
isShowDiffAvailable
|
|
14
|
+
} = useSharedPluginStateWithSelector(api, ['trackChanges'], states => {
|
|
15
|
+
var _states$trackChangesS, _states$trackChangesS2;
|
|
16
|
+
return {
|
|
17
|
+
isDisplayingChanges: (_states$trackChangesS = states.trackChangesState) === null || _states$trackChangesS === void 0 ? void 0 : _states$trackChangesS.isDisplayingChanges,
|
|
18
|
+
isShowDiffAvailable: (_states$trackChangesS2 = states.trackChangesState) === null || _states$trackChangesS2 === void 0 ? void 0 : _states$trackChangesS2.isShowDiffAvailable
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
const {
|
|
22
|
+
formatMessage
|
|
23
|
+
} = useIntl();
|
|
24
|
+
const handleClick = React.useCallback(() => {
|
|
25
|
+
api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.trackChanges.commands.toggleChanges);
|
|
26
|
+
}, [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]);
|
|
27
|
+
return /*#__PURE__*/React.createElement(IconButton, {
|
|
28
|
+
icon: HistoryIcon,
|
|
29
|
+
label: formatMessage(trackChangesMessages.toolbarIconLabel),
|
|
30
|
+
appearance: "subtle",
|
|
31
|
+
isDisabled: !isShowDiffAvailable,
|
|
32
|
+
isSelected: isDisplayingChanges,
|
|
33
|
+
onClick: handleClick
|
|
34
|
+
});
|
|
35
|
+
};
|
|
@@ -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
|
-
|
|
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
|
|
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(
|
|
19
|
-
var doc = _ref.doc;
|
|
44
|
+
init: function init() {
|
|
20
45
|
return {
|
|
21
|
-
|
|
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
|
|
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
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
74
|
+
steps: steps,
|
|
60
75
|
shouldChangesBeDisplayed: false,
|
|
61
|
-
changes: changes,
|
|
62
76
|
isShowDiffAvailable: true
|
|
63
77
|
});
|
|
64
78
|
}
|
|
65
79
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
89
|
-
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
90
102
|
}
|
|
91
103
|
});
|
|
92
104
|
};
|
|
@@ -1,17 +1,35 @@
|
|
|
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
|
-
|
|
4
|
+
import { TrackChangesToolbarButton } from './ui/TrackChangesToolbarButton';
|
|
5
|
+
export var trackChangesPlugin = function trackChangesPlugin(_ref) {
|
|
6
|
+
var api = _ref.api,
|
|
7
|
+
options = _ref.config;
|
|
8
|
+
var primaryToolbarComponent = function primaryToolbarComponent() {
|
|
9
|
+
return /*#__PURE__*/React.createElement(TrackChangesToolbarButton, {
|
|
10
|
+
api: api
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
if ((options === null || options === void 0 ? void 0 : options.showOnToolbar) === true) {
|
|
14
|
+
var _api$primaryToolbar;
|
|
15
|
+
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({
|
|
16
|
+
name: 'trackChanges',
|
|
17
|
+
component: primaryToolbarComponent
|
|
18
|
+
});
|
|
19
|
+
}
|
|
4
20
|
return {
|
|
5
21
|
name: 'trackChanges',
|
|
6
22
|
pmPlugins: function pmPlugins() {
|
|
7
23
|
return [{
|
|
8
24
|
name: 'trackChangesPlugin',
|
|
9
|
-
plugin:
|
|
25
|
+
plugin: function plugin() {
|
|
26
|
+
return createTrackChangesPlugin(api);
|
|
27
|
+
}
|
|
10
28
|
}];
|
|
11
29
|
},
|
|
12
30
|
commands: {
|
|
13
|
-
toggleChanges: function toggleChanges(
|
|
14
|
-
var tr =
|
|
31
|
+
toggleChanges: function toggleChanges(_ref2) {
|
|
32
|
+
var tr = _ref2.tr;
|
|
15
33
|
return tr.setMeta(trackChangesPluginKey, {
|
|
16
34
|
action: ACTION.TOGGLE_TRACK_CHANGES
|
|
17
35
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl-next';
|
|
3
|
+
import { IconButton } from '@atlaskit/button/new';
|
|
4
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
5
|
+
import { trackChangesMessages } from '@atlaskit/editor-common/messages';
|
|
6
|
+
import HistoryIcon from '@atlaskit/icon-lab/core/history';
|
|
7
|
+
export var TrackChangesToolbarButton = function TrackChangesToolbarButton(_ref) {
|
|
8
|
+
var _api$trackChanges;
|
|
9
|
+
var api = _ref.api;
|
|
10
|
+
var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['trackChanges'], function (states) {
|
|
11
|
+
var _states$trackChangesS, _states$trackChangesS2;
|
|
12
|
+
return {
|
|
13
|
+
isDisplayingChanges: (_states$trackChangesS = states.trackChangesState) === null || _states$trackChangesS === void 0 ? void 0 : _states$trackChangesS.isDisplayingChanges,
|
|
14
|
+
isShowDiffAvailable: (_states$trackChangesS2 = states.trackChangesState) === null || _states$trackChangesS2 === void 0 ? void 0 : _states$trackChangesS2.isShowDiffAvailable
|
|
15
|
+
};
|
|
16
|
+
}),
|
|
17
|
+
isDisplayingChanges = _useSharedPluginState.isDisplayingChanges,
|
|
18
|
+
isShowDiffAvailable = _useSharedPluginState.isShowDiffAvailable;
|
|
19
|
+
var _useIntl = useIntl(),
|
|
20
|
+
formatMessage = _useIntl.formatMessage;
|
|
21
|
+
var handleClick = React.useCallback(function () {
|
|
22
|
+
api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.trackChanges.commands.toggleChanges);
|
|
23
|
+
}, [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]);
|
|
24
|
+
return /*#__PURE__*/React.createElement(IconButton, {
|
|
25
|
+
icon: HistoryIcon,
|
|
26
|
+
label: formatMessage(trackChangesMessages.toolbarIconLabel),
|
|
27
|
+
appearance: "subtle",
|
|
28
|
+
isDisabled: !isShowDiffAvailable,
|
|
29
|
+
isSelected: isDisplayingChanges,
|
|
30
|
+
onClick: handleClick
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import { ChangeSet } from 'prosemirror-changeset';
|
|
2
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
-
import
|
|
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
|
-
|
|
10
|
-
changes: ChangeSet;
|
|
10
|
+
steps: InvertableStep[];
|
|
11
11
|
};
|
|
12
|
-
export declare
|
|
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,23 @@ export type TrackChangesPlugin = NextEditorPlugin<'trackChanges', {
|
|
|
6
8
|
*/
|
|
7
9
|
toggleChanges: EditorCommand;
|
|
8
10
|
};
|
|
11
|
+
dependencies: [
|
|
12
|
+
/**
|
|
13
|
+
* Primary toolbar plugin for registering the track changes button.
|
|
14
|
+
*/
|
|
15
|
+
OptionalPlugin<PrimaryToolbarPlugin>,
|
|
16
|
+
/**
|
|
17
|
+
* Show diff plugin for showing the changes in a diff view.
|
|
18
|
+
*/
|
|
19
|
+
ShowDiffPlugin
|
|
20
|
+
];
|
|
21
|
+
pluginConfiguration?: {
|
|
22
|
+
/**
|
|
23
|
+
* Whether the track changes button should be shown on the toolbar.
|
|
24
|
+
* Defaults to false.
|
|
25
|
+
*/
|
|
26
|
+
showOnToolbar?: boolean;
|
|
27
|
+
};
|
|
9
28
|
sharedState: {
|
|
10
29
|
/**
|
|
11
30
|
* 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
|
|
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
|
-
|
|
10
|
-
changes: ChangeSet;
|
|
10
|
+
steps: InvertableStep[];
|
|
11
11
|
};
|
|
12
|
-
export declare
|
|
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,23 @@ export type TrackChangesPlugin = NextEditorPlugin<'trackChanges', {
|
|
|
6
8
|
*/
|
|
7
9
|
toggleChanges: EditorCommand;
|
|
8
10
|
};
|
|
11
|
+
dependencies: [
|
|
12
|
+
/**
|
|
13
|
+
* Primary toolbar plugin for registering the track changes button.
|
|
14
|
+
*/
|
|
15
|
+
OptionalPlugin<PrimaryToolbarPlugin>,
|
|
16
|
+
/**
|
|
17
|
+
* Show diff plugin for showing the changes in a diff view.
|
|
18
|
+
*/
|
|
19
|
+
ShowDiffPlugin
|
|
20
|
+
];
|
|
21
|
+
pluginConfiguration?: {
|
|
22
|
+
/**
|
|
23
|
+
* Whether the track changes button should be shown on the toolbar.
|
|
24
|
+
* Defaults to false.
|
|
25
|
+
*/
|
|
26
|
+
showOnToolbar?: boolean;
|
|
27
|
+
};
|
|
9
28
|
sharedState: {
|
|
10
29
|
/**
|
|
11
30
|
* 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 {};
|