@atlaskit/editor-plugin-show-diff 0.1.0 → 0.1.2
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 +18 -0
- package/afm-passionfruit/tsconfig.json +27 -0
- package/afm-volt/tsconfig.json +27 -0
- package/dist/cjs/pm-plugins/main.js +28 -18
- package/dist/cjs/pm-plugins/markDecorations.js +21 -0
- package/dist/es2019/pm-plugins/main.js +26 -16
- package/dist/es2019/pm-plugins/markDecorations.js +13 -0
- package/dist/esm/pm-plugins/main.js +28 -18
- package/dist/esm/pm-plugins/markDecorations.js +15 -0
- package/dist/types/pm-plugins/decorations.d.ts +4 -1
- package/dist/types/pm-plugins/main.d.ts +1 -0
- package/dist/types/pm-plugins/markDecorations.d.ts +7 -0
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +4 -1
- package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/markDecorations.d.ts +7 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-show-diff
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`7fe4c9e51271d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7fe4c9e51271d) -
|
|
8
|
+
Fix initial show diff after performance fix.
|
|
9
|
+
- [`b2d53a70dbaa5`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b2d53a70dbaa5) -
|
|
10
|
+
Improve show diff performance by storing decorations in state.
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 0.1.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [`941fdc429d140`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/941fdc429d140) -
|
|
18
|
+
Show formatting changes in the diff
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
3
21
|
## 0.1.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../../tsconfig.entry-points.passionfruit.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"outDir": "../../../../../passionfruit/tsDist/@atlaskit__editor-plugin-show-diff/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/tokens/afm-passionfruit/tsconfig.json"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "../../editor-common/afm-passionfruit/tsconfig.json"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../../tsconfig.entry-points.volt.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"outDir": "../../../../../volt/tsDist/@atlaskit__editor-plugin-show-diff/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/tokens/afm-volt/tsconfig.json"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "../../editor-common/afm-volt/tsconfig.json"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -13,6 +13,7 @@ var _state = require("@atlaskit/editor-prosemirror/state");
|
|
|
13
13
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
14
14
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
15
15
|
var _decorations = require("./decorations");
|
|
16
|
+
var _markDecorations = require("./markDecorations");
|
|
16
17
|
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
18
|
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
19
|
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; } } }; }
|
|
@@ -23,7 +24,7 @@ var calculateDecorations = function calculateDecorations(_ref) {
|
|
|
23
24
|
pluginState = _ref.pluginState;
|
|
24
25
|
var originalDoc = pluginState.originalDoc,
|
|
25
26
|
steps = pluginState.steps;
|
|
26
|
-
if (!originalDoc) {
|
|
27
|
+
if (!originalDoc || !pluginState.isDisplayingChanges) {
|
|
27
28
|
return _view.DecorationSet.empty;
|
|
28
29
|
}
|
|
29
30
|
var tr = state.tr;
|
|
@@ -62,6 +63,9 @@ var calculateDecorations = function calculateDecorations(_ref) {
|
|
|
62
63
|
}));
|
|
63
64
|
}
|
|
64
65
|
});
|
|
66
|
+
(0, _markDecorations.getMarkChangeRanges)(steps).forEach(function (change) {
|
|
67
|
+
decorations.push((0, _decorations.createInlineChangedDecoration)(change));
|
|
68
|
+
});
|
|
65
69
|
return _view.DecorationSet.empty.add(tr.doc, decorations);
|
|
66
70
|
};
|
|
67
71
|
var showDiffPluginKey = exports.showDiffPluginKey = new _state.PluginKey('showDiffPlugin');
|
|
@@ -70,20 +74,24 @@ var createPlugin = exports.createPlugin = function createPlugin(config) {
|
|
|
70
74
|
key: showDiffPluginKey,
|
|
71
75
|
state: {
|
|
72
76
|
init: function init(_, state) {
|
|
73
|
-
var _config$steps;
|
|
77
|
+
var _config$steps, _config$steps2;
|
|
74
78
|
var schema = state.schema;
|
|
79
|
+
var isDisplayingChanges = ((_config$steps = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps !== void 0 ? _config$steps : []).length > 0;
|
|
80
|
+
var steps = ((_config$steps2 = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps2 !== void 0 ? _config$steps2 : []).map(function (step) {
|
|
81
|
+
return _transform.Step.fromJSON(schema, step);
|
|
82
|
+
});
|
|
75
83
|
return {
|
|
76
|
-
steps:
|
|
77
|
-
return _transform.Step.fromJSON(schema, step);
|
|
78
|
-
}),
|
|
84
|
+
steps: steps,
|
|
79
85
|
originalDoc: config !== null && config !== void 0 && config.originalDoc ? (0, _processRawValue.processRawValue)(state.schema, config.originalDoc) : undefined,
|
|
80
86
|
decorations: calculateDecorations({
|
|
81
87
|
state: state,
|
|
82
88
|
pluginState: {
|
|
83
|
-
steps:
|
|
84
|
-
originalDoc: config !== null && config !== void 0 && config.originalDoc ? (0, _processRawValue.processRawValue)(state.schema, config.originalDoc) : undefined
|
|
89
|
+
steps: steps,
|
|
90
|
+
originalDoc: config !== null && config !== void 0 && config.originalDoc ? (0, _processRawValue.processRawValue)(state.schema, config.originalDoc) : undefined,
|
|
91
|
+
isDisplayingChanges: isDisplayingChanges
|
|
85
92
|
}
|
|
86
|
-
})
|
|
93
|
+
}),
|
|
94
|
+
isDisplayingChanges: isDisplayingChanges
|
|
87
95
|
};
|
|
88
96
|
},
|
|
89
97
|
apply: function apply(tr, currentPluginState, oldState, newState) {
|
|
@@ -91,28 +99,30 @@ var createPlugin = exports.createPlugin = function createPlugin(config) {
|
|
|
91
99
|
var newPluginState = currentPluginState;
|
|
92
100
|
if (meta) {
|
|
93
101
|
if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'SHOW_DIFF') {
|
|
102
|
+
// Calculate and store decorations in state
|
|
103
|
+
var decorations = calculateDecorations({
|
|
104
|
+
state: newState,
|
|
105
|
+
pluginState: {
|
|
106
|
+
steps: meta.steps,
|
|
107
|
+
originalDoc: meta.originalDoc,
|
|
108
|
+
isDisplayingChanges: true
|
|
109
|
+
}
|
|
110
|
+
});
|
|
94
111
|
newPluginState = _objectSpread(_objectSpread(_objectSpread({}, currentPluginState), meta), {}, {
|
|
112
|
+
decorations: decorations,
|
|
95
113
|
isDisplayingChanges: true
|
|
96
114
|
});
|
|
97
115
|
} else if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'HIDE_DIFF') {
|
|
98
116
|
newPluginState = _objectSpread(_objectSpread(_objectSpread({}, currentPluginState), meta), {}, {
|
|
117
|
+
decorations: _view.DecorationSet.empty,
|
|
99
118
|
isDisplayingChanges: false
|
|
100
119
|
});
|
|
101
120
|
} else {
|
|
102
121
|
newPluginState = _objectSpread(_objectSpread({}, currentPluginState), meta);
|
|
103
122
|
}
|
|
104
123
|
}
|
|
105
|
-
|
|
106
|
-
// Calculate and store decorations in state
|
|
107
|
-
var decorations = calculateDecorations({
|
|
108
|
-
state: newState,
|
|
109
|
-
pluginState: {
|
|
110
|
-
steps: newPluginState.steps,
|
|
111
|
-
originalDoc: newPluginState.originalDoc
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
124
|
return _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
115
|
-
decorations: decorations
|
|
125
|
+
decorations: newPluginState.decorations.map(tr.mapping, tr.doc)
|
|
116
126
|
});
|
|
117
127
|
}
|
|
118
128
|
},
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getMarkChangeRanges = void 0;
|
|
7
|
+
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
8
|
+
var filterUndefined = function filterUndefined(x) {
|
|
9
|
+
return !!x;
|
|
10
|
+
};
|
|
11
|
+
var getMarkChangeRanges = exports.getMarkChangeRanges = function getMarkChangeRanges(steps) {
|
|
12
|
+
return steps.map(function (step) {
|
|
13
|
+
if (step instanceof _transform.AddMarkStep || step instanceof _transform.RemoveMarkStep) {
|
|
14
|
+
return {
|
|
15
|
+
fromB: step.from,
|
|
16
|
+
toB: step.to
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}).filter(filterUndefined);
|
|
21
|
+
};
|
|
@@ -6,6 +6,7 @@ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
|
6
6
|
import { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
|
|
7
7
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
8
8
|
import { createInlineChangedDecoration, createDeletedContentDecoration } from './decorations';
|
|
9
|
+
import { getMarkChangeRanges } from './markDecorations';
|
|
9
10
|
const calculateDecorations = ({
|
|
10
11
|
state,
|
|
11
12
|
pluginState
|
|
@@ -14,7 +15,7 @@ const calculateDecorations = ({
|
|
|
14
15
|
originalDoc,
|
|
15
16
|
steps
|
|
16
17
|
} = pluginState;
|
|
17
|
-
if (!originalDoc) {
|
|
18
|
+
if (!originalDoc || !pluginState.isDisplayingChanges) {
|
|
18
19
|
return DecorationSet.empty;
|
|
19
20
|
}
|
|
20
21
|
const {
|
|
@@ -46,6 +47,9 @@ const calculateDecorations = ({
|
|
|
46
47
|
}));
|
|
47
48
|
}
|
|
48
49
|
});
|
|
50
|
+
getMarkChangeRanges(steps).forEach(change => {
|
|
51
|
+
decorations.push(createInlineChangedDecoration(change));
|
|
52
|
+
});
|
|
49
53
|
return DecorationSet.empty.add(tr.doc, decorations);
|
|
50
54
|
};
|
|
51
55
|
export const showDiffPluginKey = new PluginKey('showDiffPlugin');
|
|
@@ -54,18 +58,22 @@ export const createPlugin = config => {
|
|
|
54
58
|
key: showDiffPluginKey,
|
|
55
59
|
state: {
|
|
56
60
|
init(_, state) {
|
|
57
|
-
var _config$steps;
|
|
61
|
+
var _config$steps, _config$steps2;
|
|
58
62
|
const schema = state.schema;
|
|
63
|
+
const isDisplayingChanges = ((_config$steps = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps !== void 0 ? _config$steps : []).length > 0;
|
|
64
|
+
const steps = ((_config$steps2 = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps2 !== void 0 ? _config$steps2 : []).map(step => ProseMirrorStep.fromJSON(schema, step));
|
|
59
65
|
return {
|
|
60
|
-
steps
|
|
66
|
+
steps,
|
|
61
67
|
originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined,
|
|
62
68
|
decorations: calculateDecorations({
|
|
63
69
|
state,
|
|
64
70
|
pluginState: {
|
|
65
|
-
steps
|
|
66
|
-
originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined
|
|
71
|
+
steps,
|
|
72
|
+
originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined,
|
|
73
|
+
isDisplayingChanges
|
|
67
74
|
}
|
|
68
|
-
})
|
|
75
|
+
}),
|
|
76
|
+
isDisplayingChanges
|
|
69
77
|
};
|
|
70
78
|
},
|
|
71
79
|
apply: (tr, currentPluginState, oldState, newState) => {
|
|
@@ -73,15 +81,26 @@ export const createPlugin = config => {
|
|
|
73
81
|
let newPluginState = currentPluginState;
|
|
74
82
|
if (meta) {
|
|
75
83
|
if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'SHOW_DIFF') {
|
|
84
|
+
// Calculate and store decorations in state
|
|
85
|
+
const decorations = calculateDecorations({
|
|
86
|
+
state: newState,
|
|
87
|
+
pluginState: {
|
|
88
|
+
steps: meta.steps,
|
|
89
|
+
originalDoc: meta.originalDoc,
|
|
90
|
+
isDisplayingChanges: true
|
|
91
|
+
}
|
|
92
|
+
});
|
|
76
93
|
newPluginState = {
|
|
77
94
|
...currentPluginState,
|
|
78
95
|
...meta,
|
|
96
|
+
decorations,
|
|
79
97
|
isDisplayingChanges: true
|
|
80
98
|
};
|
|
81
99
|
} else if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'HIDE_DIFF') {
|
|
82
100
|
newPluginState = {
|
|
83
101
|
...currentPluginState,
|
|
84
102
|
...meta,
|
|
103
|
+
decorations: DecorationSet.empty,
|
|
85
104
|
isDisplayingChanges: false
|
|
86
105
|
};
|
|
87
106
|
} else {
|
|
@@ -91,18 +110,9 @@ export const createPlugin = config => {
|
|
|
91
110
|
};
|
|
92
111
|
}
|
|
93
112
|
}
|
|
94
|
-
|
|
95
|
-
// Calculate and store decorations in state
|
|
96
|
-
const decorations = calculateDecorations({
|
|
97
|
-
state: newState,
|
|
98
|
-
pluginState: {
|
|
99
|
-
steps: newPluginState.steps,
|
|
100
|
-
originalDoc: newPluginState.originalDoc
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
113
|
return {
|
|
104
114
|
...newPluginState,
|
|
105
|
-
decorations
|
|
115
|
+
decorations: newPluginState.decorations.map(tr.mapping, tr.doc)
|
|
106
116
|
};
|
|
107
117
|
}
|
|
108
118
|
},
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AddMarkStep, RemoveMarkStep } from '@atlaskit/editor-prosemirror/transform';
|
|
2
|
+
const filterUndefined = x => !!x;
|
|
3
|
+
export const getMarkChangeRanges = steps => {
|
|
4
|
+
return steps.map(step => {
|
|
5
|
+
if (step instanceof AddMarkStep || step instanceof RemoveMarkStep) {
|
|
6
|
+
return {
|
|
7
|
+
fromB: step.from,
|
|
8
|
+
toB: step.to
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
}).filter(filterUndefined);
|
|
13
|
+
};
|
|
@@ -12,12 +12,13 @@ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
|
12
12
|
import { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
|
|
13
13
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
14
14
|
import { createInlineChangedDecoration, createDeletedContentDecoration } from './decorations';
|
|
15
|
+
import { getMarkChangeRanges } from './markDecorations';
|
|
15
16
|
var calculateDecorations = function calculateDecorations(_ref) {
|
|
16
17
|
var state = _ref.state,
|
|
17
18
|
pluginState = _ref.pluginState;
|
|
18
19
|
var originalDoc = pluginState.originalDoc,
|
|
19
20
|
steps = pluginState.steps;
|
|
20
|
-
if (!originalDoc) {
|
|
21
|
+
if (!originalDoc || !pluginState.isDisplayingChanges) {
|
|
21
22
|
return DecorationSet.empty;
|
|
22
23
|
}
|
|
23
24
|
var tr = state.tr;
|
|
@@ -56,6 +57,9 @@ var calculateDecorations = function calculateDecorations(_ref) {
|
|
|
56
57
|
}));
|
|
57
58
|
}
|
|
58
59
|
});
|
|
60
|
+
getMarkChangeRanges(steps).forEach(function (change) {
|
|
61
|
+
decorations.push(createInlineChangedDecoration(change));
|
|
62
|
+
});
|
|
59
63
|
return DecorationSet.empty.add(tr.doc, decorations);
|
|
60
64
|
};
|
|
61
65
|
export var showDiffPluginKey = new PluginKey('showDiffPlugin');
|
|
@@ -64,20 +68,24 @@ export var createPlugin = function createPlugin(config) {
|
|
|
64
68
|
key: showDiffPluginKey,
|
|
65
69
|
state: {
|
|
66
70
|
init: function init(_, state) {
|
|
67
|
-
var _config$steps;
|
|
71
|
+
var _config$steps, _config$steps2;
|
|
68
72
|
var schema = state.schema;
|
|
73
|
+
var isDisplayingChanges = ((_config$steps = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps !== void 0 ? _config$steps : []).length > 0;
|
|
74
|
+
var steps = ((_config$steps2 = config === null || config === void 0 ? void 0 : config.steps) !== null && _config$steps2 !== void 0 ? _config$steps2 : []).map(function (step) {
|
|
75
|
+
return ProseMirrorStep.fromJSON(schema, step);
|
|
76
|
+
});
|
|
69
77
|
return {
|
|
70
|
-
steps:
|
|
71
|
-
return ProseMirrorStep.fromJSON(schema, step);
|
|
72
|
-
}),
|
|
78
|
+
steps: steps,
|
|
73
79
|
originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined,
|
|
74
80
|
decorations: calculateDecorations({
|
|
75
81
|
state: state,
|
|
76
82
|
pluginState: {
|
|
77
|
-
steps:
|
|
78
|
-
originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined
|
|
83
|
+
steps: steps,
|
|
84
|
+
originalDoc: config !== null && config !== void 0 && config.originalDoc ? processRawValue(state.schema, config.originalDoc) : undefined,
|
|
85
|
+
isDisplayingChanges: isDisplayingChanges
|
|
79
86
|
}
|
|
80
|
-
})
|
|
87
|
+
}),
|
|
88
|
+
isDisplayingChanges: isDisplayingChanges
|
|
81
89
|
};
|
|
82
90
|
},
|
|
83
91
|
apply: function apply(tr, currentPluginState, oldState, newState) {
|
|
@@ -85,28 +93,30 @@ export var createPlugin = function createPlugin(config) {
|
|
|
85
93
|
var newPluginState = currentPluginState;
|
|
86
94
|
if (meta) {
|
|
87
95
|
if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'SHOW_DIFF') {
|
|
96
|
+
// Calculate and store decorations in state
|
|
97
|
+
var decorations = calculateDecorations({
|
|
98
|
+
state: newState,
|
|
99
|
+
pluginState: {
|
|
100
|
+
steps: meta.steps,
|
|
101
|
+
originalDoc: meta.originalDoc,
|
|
102
|
+
isDisplayingChanges: true
|
|
103
|
+
}
|
|
104
|
+
});
|
|
88
105
|
newPluginState = _objectSpread(_objectSpread(_objectSpread({}, currentPluginState), meta), {}, {
|
|
106
|
+
decorations: decorations,
|
|
89
107
|
isDisplayingChanges: true
|
|
90
108
|
});
|
|
91
109
|
} else if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'HIDE_DIFF') {
|
|
92
110
|
newPluginState = _objectSpread(_objectSpread(_objectSpread({}, currentPluginState), meta), {}, {
|
|
111
|
+
decorations: DecorationSet.empty,
|
|
93
112
|
isDisplayingChanges: false
|
|
94
113
|
});
|
|
95
114
|
} else {
|
|
96
115
|
newPluginState = _objectSpread(_objectSpread({}, currentPluginState), meta);
|
|
97
116
|
}
|
|
98
117
|
}
|
|
99
|
-
|
|
100
|
-
// Calculate and store decorations in state
|
|
101
|
-
var decorations = calculateDecorations({
|
|
102
|
-
state: newState,
|
|
103
|
-
pluginState: {
|
|
104
|
-
steps: newPluginState.steps,
|
|
105
|
-
originalDoc: newPluginState.originalDoc
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
118
|
return _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
109
|
-
decorations: decorations
|
|
119
|
+
decorations: newPluginState.decorations.map(tr.mapping, tr.doc)
|
|
110
120
|
});
|
|
111
121
|
}
|
|
112
122
|
},
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AddMarkStep, RemoveMarkStep } from '@atlaskit/editor-prosemirror/transform';
|
|
2
|
+
var filterUndefined = function filterUndefined(x) {
|
|
3
|
+
return !!x;
|
|
4
|
+
};
|
|
5
|
+
export var getMarkChangeRanges = function getMarkChangeRanges(steps) {
|
|
6
|
+
return steps.map(function (step) {
|
|
7
|
+
if (step instanceof AddMarkStep || step instanceof RemoveMarkStep) {
|
|
8
|
+
return {
|
|
9
|
+
fromB: step.from,
|
|
10
|
+
toB: step.to
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}).filter(filterUndefined);
|
|
15
|
+
};
|
|
@@ -8,7 +8,10 @@ import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
|
8
8
|
* @param change Changeset "change" containing information about the change content + range
|
|
9
9
|
* @returns Prosemirror inline decoration
|
|
10
10
|
*/
|
|
11
|
-
export declare const createInlineChangedDecoration: (change:
|
|
11
|
+
export declare const createInlineChangedDecoration: (change: {
|
|
12
|
+
fromB: number;
|
|
13
|
+
toB: number;
|
|
14
|
+
}) => Decoration;
|
|
12
15
|
interface DeletedContentDecorationProps {
|
|
13
16
|
change: Change;
|
|
14
17
|
doc: PMNode;
|
|
@@ -9,6 +9,7 @@ type ShowDiffPluginState = {
|
|
|
9
9
|
steps: ProseMirrorStep[];
|
|
10
10
|
originalDoc: PMNode | undefined;
|
|
11
11
|
decorations: DecorationSet;
|
|
12
|
+
isDisplayingChanges: boolean;
|
|
12
13
|
};
|
|
13
14
|
export declare const createPlugin: (config: DiffParams | undefined) => SafePlugin<ShowDiffPluginState>;
|
|
14
15
|
export {};
|
|
@@ -8,7 +8,10 @@ import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
|
8
8
|
* @param change Changeset "change" containing information about the change content + range
|
|
9
9
|
* @returns Prosemirror inline decoration
|
|
10
10
|
*/
|
|
11
|
-
export declare const createInlineChangedDecoration: (change:
|
|
11
|
+
export declare const createInlineChangedDecoration: (change: {
|
|
12
|
+
fromB: number;
|
|
13
|
+
toB: number;
|
|
14
|
+
}) => Decoration;
|
|
12
15
|
interface DeletedContentDecorationProps {
|
|
13
16
|
change: Change;
|
|
14
17
|
doc: PMNode;
|
|
@@ -9,6 +9,7 @@ type ShowDiffPluginState = {
|
|
|
9
9
|
steps: ProseMirrorStep[];
|
|
10
10
|
originalDoc: PMNode | undefined;
|
|
11
11
|
decorations: DecorationSet;
|
|
12
|
+
isDisplayingChanges: boolean;
|
|
12
13
|
};
|
|
13
14
|
export declare const createPlugin: (config: DiffParams | undefined) => SafePlugin<ShowDiffPluginState>;
|
|
14
15
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-show-diff",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "ShowDiff plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"prosemirror-changeset": "^2.2.1"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@atlaskit/editor-common": "^107.
|
|
40
|
+
"@atlaskit/editor-common": "^107.23.0",
|
|
41
41
|
"react": "^18.2.0"
|
|
42
42
|
},
|
|
43
43
|
"techstack": {
|