@atlaskit/editor-plugin-show-diff 8.0.0 → 8.1.1
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 +21 -0
- package/afm-cc/tsconfig.json +3 -0
- package/afm-products/tsconfig.json +3 -0
- package/dist/cjs/pm-plugins/calculateDiff/diffBySteps.js +46 -0
- package/dist/cjs/pm-plugins/main.js +7 -2
- package/dist/es2019/pm-plugins/calculateDiff/diffBySteps.js +38 -1
- package/dist/es2019/pm-plugins/main.js +7 -2
- package/dist/esm/pm-plugins/calculateDiff/diffBySteps.js +47 -1
- package/dist/esm/pm-plugins/main.js +7 -2
- package/dist/types/pm-plugins/calculateDiff/diffBySteps.d.ts +1 -1
- package/dist/types/showDiffPluginType.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/calculateDiff/diffBySteps.d.ts +1 -1
- package/dist/types-ts4.5/showDiffPluginType.d.ts +3 -1
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-show-diff
|
|
2
2
|
|
|
3
|
+
## 8.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`b26874dcf4a79`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b26874dcf4a79) -
|
|
8
|
+
Show granular inline diffs when the replace step is for a paragraph.
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 8.1.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [`c50b6810de5a3`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c50b6810de5a3) -
|
|
16
|
+
Open expand nodes before scrolling to diff changes within them using `toggleExpandRange` from the
|
|
17
|
+
expand plugin. This is gated behind the `platform_editor_show_diff_open_expands_on_scroll` feature
|
|
18
|
+
flag.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
|
|
3
24
|
## 8.0.0
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/afm-cc/tsconfig.json
CHANGED
|
@@ -7,7 +7,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.diffBySteps = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
+
var _prosemirrorChangeset = require("prosemirror-changeset");
|
|
10
11
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
12
|
+
var _optimizeChanges = require("./optimizeChanges");
|
|
11
13
|
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; }
|
|
12
14
|
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; }
|
|
13
15
|
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; } } }; }
|
|
@@ -67,6 +69,18 @@ var mergeOverlappingByNewDocRange = function mergeOverlappingByNewDocRange(chang
|
|
|
67
69
|
merged.push(current);
|
|
68
70
|
return merged;
|
|
69
71
|
};
|
|
72
|
+
var isReplaceStepForTextBlockNode = function isReplaceStepForTextBlockNode(step, before, from, to) {
|
|
73
|
+
var _replacedSlice$conten, _replacingSlice$conte, _replacedSlice$conten2;
|
|
74
|
+
if (!(step instanceof _transform.ReplaceStep)) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
if (step.slice.openStart !== 0 || step.slice.openEnd !== 0) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
var replacedSlice = before.slice(from, to);
|
|
81
|
+
var replacingSlice = step.slice;
|
|
82
|
+
return Boolean(replacedSlice.openStart === 0 && replacedSlice.openEnd === 0 && replacedSlice.content.childCount === 1 && replacingSlice.content.childCount === 1 && ((_replacedSlice$conten = replacedSlice.content.firstChild) === null || _replacedSlice$conten === void 0 ? void 0 : _replacedSlice$conten.type.name) === ((_replacingSlice$conte = replacingSlice.content.firstChild) === null || _replacingSlice$conte === void 0 ? void 0 : _replacingSlice$conte.type.name) && ((_replacedSlice$conten2 = replacedSlice.content.firstChild) === null || _replacedSlice$conten2 === void 0 ? void 0 : _replacedSlice$conten2.type.isTextblock));
|
|
83
|
+
};
|
|
70
84
|
var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps) {
|
|
71
85
|
var changes = [];
|
|
72
86
|
var currentDoc = originalDoc;
|
|
@@ -77,6 +91,7 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
|
|
|
77
91
|
try {
|
|
78
92
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
79
93
|
var step = _step2.value;
|
|
94
|
+
var before = currentDoc;
|
|
80
95
|
var result = step.apply(currentDoc);
|
|
81
96
|
if (result.failed !== null || !result.doc) {
|
|
82
97
|
continue;
|
|
@@ -85,9 +100,12 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
|
|
|
85
100
|
var rangeStep = step;
|
|
86
101
|
if (typeof rangeStep.from === 'number' && typeof rangeStep.to === 'number') {
|
|
87
102
|
rangedSteps.push({
|
|
103
|
+
before: before,
|
|
104
|
+
doc: result.doc,
|
|
88
105
|
from: rangeStep.from,
|
|
89
106
|
to: rangeStep.to,
|
|
90
107
|
mapIndex: successfulStepMaps.length,
|
|
108
|
+
step: step,
|
|
91
109
|
stepMap: stepMap
|
|
92
110
|
});
|
|
93
111
|
}
|
|
@@ -113,6 +131,34 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
|
|
|
113
131
|
var afterStepToFinal = createMapping(successfulStepMaps.slice(rangedStep.mapIndex + 1));
|
|
114
132
|
var fromB = mapPosition(afterStepToFinal, fromAfterStep);
|
|
115
133
|
var toB = mapPosition(afterStepToFinal, toAfterStep);
|
|
134
|
+
if (isReplaceStepForTextBlockNode(rangedStep.step, rangedStep.before, rangedStep.from, rangedStep.to)) {
|
|
135
|
+
var granularStepChanges = _prosemirrorChangeset.ChangeSet.create(rangedStep.before).addSteps(rangedStep.doc, [rangedStep.stepMap], null);
|
|
136
|
+
var optimizedGranularStepChanges = (0, _optimizeChanges.optimizeChanges)((0, _prosemirrorChangeset.simplifyChanges)(granularStepChanges.changes, granularStepChanges.startDoc));
|
|
137
|
+
var _iterator3 = _createForOfIteratorHelper(optimizedGranularStepChanges),
|
|
138
|
+
_step3;
|
|
139
|
+
try {
|
|
140
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
141
|
+
var granularChange = _step3.value;
|
|
142
|
+
var granularFromA = mapPosition(beforeStepToOriginal, granularChange.fromA);
|
|
143
|
+
var granularToA = mapPosition(beforeStepToOriginal, granularChange.toA);
|
|
144
|
+
var granularFromB = mapPosition(afterStepToFinal, granularChange.fromB);
|
|
145
|
+
var granularToB = mapPosition(afterStepToFinal, granularChange.toB);
|
|
146
|
+
changes.push({
|
|
147
|
+
fromA: granularFromA,
|
|
148
|
+
toA: granularToA,
|
|
149
|
+
fromB: granularFromB,
|
|
150
|
+
toB: granularToB,
|
|
151
|
+
deleted: createSpans(Math.max(0, granularToA - granularFromA)),
|
|
152
|
+
inserted: createSpans(Math.max(0, granularToB - granularFromB))
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
} catch (err) {
|
|
156
|
+
_iterator3.e(err);
|
|
157
|
+
} finally {
|
|
158
|
+
_iterator3.f();
|
|
159
|
+
}
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
116
162
|
changes.push({
|
|
117
163
|
fromA: fromA,
|
|
118
164
|
toA: toA,
|
|
@@ -161,9 +161,14 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
|
|
|
161
161
|
var activeIndexChanged = (pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex) !== undefined && pluginState.activeIndex !== previousActiveIndex;
|
|
162
162
|
previousActiveIndex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex;
|
|
163
163
|
if ((pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex) !== undefined && activeIndexChanged) {
|
|
164
|
-
var _cancelPendingScrollT;
|
|
164
|
+
var _cancelPendingScrollT, _api$expand;
|
|
165
165
|
(_cancelPendingScrollT = cancelPendingScrollToDecoration) === null || _cancelPendingScrollT === void 0 || _cancelPendingScrollT();
|
|
166
|
-
|
|
166
|
+
var scrollableDecorations = (0, _getScrollableDecorations.getScrollableDecorations)(pluginState.decorations, view.state.doc);
|
|
167
|
+
var activeDecoration = scrollableDecorations[pluginState.activeIndex];
|
|
168
|
+
if (activeDecoration && api !== null && api !== void 0 && (_api$expand = api.expand) !== null && _api$expand !== void 0 && (_api$expand = _api$expand.commands) !== null && _api$expand !== void 0 && _api$expand.toggleExpandRange && (0, _platformFeatureFlags.fg)('platform_editor_show_diff_scroll_navigation')) {
|
|
169
|
+
api === null || api === void 0 || api.core.actions.execute(api.expand.commands.toggleExpandRange(activeDecoration.from, activeDecoration.to, true));
|
|
170
|
+
}
|
|
171
|
+
cancelPendingScrollToDecoration = (0, _scrollToActiveDecoration.scrollToActiveDecoration)(view, scrollableDecorations, pluginState.activeIndex);
|
|
167
172
|
}
|
|
168
173
|
}
|
|
169
174
|
},
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { simplifyChanges, ChangeSet } from 'prosemirror-changeset';
|
|
2
|
+
import { Mapping, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
3
|
+
import { optimizeChanges } from './optimizeChanges';
|
|
2
4
|
const mapPosition = (mapping, pos) => mapping.map(pos);
|
|
3
5
|
const createMapping = maps => {
|
|
4
6
|
const mapping = new Mapping();
|
|
@@ -42,12 +44,25 @@ const mergeOverlappingByNewDocRange = changes => {
|
|
|
42
44
|
merged.push(current);
|
|
43
45
|
return merged;
|
|
44
46
|
};
|
|
47
|
+
const isReplaceStepForTextBlockNode = (step, before, from, to) => {
|
|
48
|
+
var _replacedSlice$conten, _replacingSlice$conte, _replacedSlice$conten2;
|
|
49
|
+
if (!(step instanceof ReplaceStep)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (step.slice.openStart !== 0 || step.slice.openEnd !== 0) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
const replacedSlice = before.slice(from, to);
|
|
56
|
+
const replacingSlice = step.slice;
|
|
57
|
+
return Boolean(replacedSlice.openStart === 0 && replacedSlice.openEnd === 0 && replacedSlice.content.childCount === 1 && replacingSlice.content.childCount === 1 && ((_replacedSlice$conten = replacedSlice.content.firstChild) === null || _replacedSlice$conten === void 0 ? void 0 : _replacedSlice$conten.type.name) === ((_replacingSlice$conte = replacingSlice.content.firstChild) === null || _replacingSlice$conte === void 0 ? void 0 : _replacingSlice$conte.type.name) && ((_replacedSlice$conten2 = replacedSlice.content.firstChild) === null || _replacedSlice$conten2 === void 0 ? void 0 : _replacedSlice$conten2.type.isTextblock));
|
|
58
|
+
};
|
|
45
59
|
export const diffBySteps = (originalDoc, steps) => {
|
|
46
60
|
const changes = [];
|
|
47
61
|
let currentDoc = originalDoc;
|
|
48
62
|
const successfulStepMaps = [];
|
|
49
63
|
const rangedSteps = [];
|
|
50
64
|
for (const step of steps) {
|
|
65
|
+
const before = currentDoc;
|
|
51
66
|
const result = step.apply(currentDoc);
|
|
52
67
|
if (result.failed !== null || !result.doc) {
|
|
53
68
|
continue;
|
|
@@ -56,9 +71,12 @@ export const diffBySteps = (originalDoc, steps) => {
|
|
|
56
71
|
const rangeStep = step;
|
|
57
72
|
if (typeof rangeStep.from === 'number' && typeof rangeStep.to === 'number') {
|
|
58
73
|
rangedSteps.push({
|
|
74
|
+
before,
|
|
75
|
+
doc: result.doc,
|
|
59
76
|
from: rangeStep.from,
|
|
60
77
|
to: rangeStep.to,
|
|
61
78
|
mapIndex: successfulStepMaps.length,
|
|
79
|
+
step,
|
|
62
80
|
stepMap
|
|
63
81
|
});
|
|
64
82
|
}
|
|
@@ -78,6 +96,25 @@ export const diffBySteps = (originalDoc, steps) => {
|
|
|
78
96
|
const afterStepToFinal = createMapping(successfulStepMaps.slice(rangedStep.mapIndex + 1));
|
|
79
97
|
const fromB = mapPosition(afterStepToFinal, fromAfterStep);
|
|
80
98
|
const toB = mapPosition(afterStepToFinal, toAfterStep);
|
|
99
|
+
if (isReplaceStepForTextBlockNode(rangedStep.step, rangedStep.before, rangedStep.from, rangedStep.to)) {
|
|
100
|
+
const granularStepChanges = ChangeSet.create(rangedStep.before).addSteps(rangedStep.doc, [rangedStep.stepMap], null);
|
|
101
|
+
const optimizedGranularStepChanges = optimizeChanges(simplifyChanges(granularStepChanges.changes, granularStepChanges.startDoc));
|
|
102
|
+
for (const granularChange of optimizedGranularStepChanges) {
|
|
103
|
+
const granularFromA = mapPosition(beforeStepToOriginal, granularChange.fromA);
|
|
104
|
+
const granularToA = mapPosition(beforeStepToOriginal, granularChange.toA);
|
|
105
|
+
const granularFromB = mapPosition(afterStepToFinal, granularChange.fromB);
|
|
106
|
+
const granularToB = mapPosition(afterStepToFinal, granularChange.toB);
|
|
107
|
+
changes.push({
|
|
108
|
+
fromA: granularFromA,
|
|
109
|
+
toA: granularToA,
|
|
110
|
+
fromB: granularFromB,
|
|
111
|
+
toB: granularToB,
|
|
112
|
+
deleted: createSpans(Math.max(0, granularToA - granularFromA)),
|
|
113
|
+
inserted: createSpans(Math.max(0, granularToB - granularFromB))
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
81
118
|
changes.push({
|
|
82
119
|
fromA,
|
|
83
120
|
toA,
|
|
@@ -166,9 +166,14 @@ export const createPlugin = (config, getIntl, api) => {
|
|
|
166
166
|
const activeIndexChanged = (pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex) !== undefined && pluginState.activeIndex !== previousActiveIndex;
|
|
167
167
|
previousActiveIndex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex;
|
|
168
168
|
if ((pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex) !== undefined && activeIndexChanged) {
|
|
169
|
-
var _cancelPendingScrollT;
|
|
169
|
+
var _cancelPendingScrollT, _api$expand, _api$expand$commands;
|
|
170
170
|
(_cancelPendingScrollT = cancelPendingScrollToDecoration) === null || _cancelPendingScrollT === void 0 ? void 0 : _cancelPendingScrollT();
|
|
171
|
-
|
|
171
|
+
const scrollableDecorations = getScrollableDecorations(pluginState.decorations, view.state.doc);
|
|
172
|
+
const activeDecoration = scrollableDecorations[pluginState.activeIndex];
|
|
173
|
+
if (activeDecoration && api !== null && api !== void 0 && (_api$expand = api.expand) !== null && _api$expand !== void 0 && (_api$expand$commands = _api$expand.commands) !== null && _api$expand$commands !== void 0 && _api$expand$commands.toggleExpandRange && fg('platform_editor_show_diff_scroll_navigation')) {
|
|
174
|
+
api === null || api === void 0 ? void 0 : api.core.actions.execute(api.expand.commands.toggleExpandRange(activeDecoration.from, activeDecoration.to, true));
|
|
175
|
+
}
|
|
176
|
+
cancelPendingScrollToDecoration = scrollToActiveDecoration(view, scrollableDecorations, pluginState.activeIndex);
|
|
172
177
|
}
|
|
173
178
|
}
|
|
174
179
|
},
|
|
@@ -5,7 +5,9 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
5
5
|
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; } } }; }
|
|
6
6
|
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; } }
|
|
7
7
|
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; }
|
|
8
|
-
import {
|
|
8
|
+
import { simplifyChanges, ChangeSet } from 'prosemirror-changeset';
|
|
9
|
+
import { Mapping, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
10
|
+
import { optimizeChanges } from './optimizeChanges';
|
|
9
11
|
var mapPosition = function mapPosition(mapping, pos) {
|
|
10
12
|
return mapping.map(pos);
|
|
11
13
|
};
|
|
@@ -60,6 +62,18 @@ var mergeOverlappingByNewDocRange = function mergeOverlappingByNewDocRange(chang
|
|
|
60
62
|
merged.push(current);
|
|
61
63
|
return merged;
|
|
62
64
|
};
|
|
65
|
+
var isReplaceStepForTextBlockNode = function isReplaceStepForTextBlockNode(step, before, from, to) {
|
|
66
|
+
var _replacedSlice$conten, _replacingSlice$conte, _replacedSlice$conten2;
|
|
67
|
+
if (!(step instanceof ReplaceStep)) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
if (step.slice.openStart !== 0 || step.slice.openEnd !== 0) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
var replacedSlice = before.slice(from, to);
|
|
74
|
+
var replacingSlice = step.slice;
|
|
75
|
+
return Boolean(replacedSlice.openStart === 0 && replacedSlice.openEnd === 0 && replacedSlice.content.childCount === 1 && replacingSlice.content.childCount === 1 && ((_replacedSlice$conten = replacedSlice.content.firstChild) === null || _replacedSlice$conten === void 0 ? void 0 : _replacedSlice$conten.type.name) === ((_replacingSlice$conte = replacingSlice.content.firstChild) === null || _replacingSlice$conte === void 0 ? void 0 : _replacingSlice$conte.type.name) && ((_replacedSlice$conten2 = replacedSlice.content.firstChild) === null || _replacedSlice$conten2 === void 0 ? void 0 : _replacedSlice$conten2.type.isTextblock));
|
|
76
|
+
};
|
|
63
77
|
export var diffBySteps = function diffBySteps(originalDoc, steps) {
|
|
64
78
|
var changes = [];
|
|
65
79
|
var currentDoc = originalDoc;
|
|
@@ -70,6 +84,7 @@ export var diffBySteps = function diffBySteps(originalDoc, steps) {
|
|
|
70
84
|
try {
|
|
71
85
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
72
86
|
var step = _step2.value;
|
|
87
|
+
var before = currentDoc;
|
|
73
88
|
var result = step.apply(currentDoc);
|
|
74
89
|
if (result.failed !== null || !result.doc) {
|
|
75
90
|
continue;
|
|
@@ -78,9 +93,12 @@ export var diffBySteps = function diffBySteps(originalDoc, steps) {
|
|
|
78
93
|
var rangeStep = step;
|
|
79
94
|
if (typeof rangeStep.from === 'number' && typeof rangeStep.to === 'number') {
|
|
80
95
|
rangedSteps.push({
|
|
96
|
+
before: before,
|
|
97
|
+
doc: result.doc,
|
|
81
98
|
from: rangeStep.from,
|
|
82
99
|
to: rangeStep.to,
|
|
83
100
|
mapIndex: successfulStepMaps.length,
|
|
101
|
+
step: step,
|
|
84
102
|
stepMap: stepMap
|
|
85
103
|
});
|
|
86
104
|
}
|
|
@@ -106,6 +124,34 @@ export var diffBySteps = function diffBySteps(originalDoc, steps) {
|
|
|
106
124
|
var afterStepToFinal = createMapping(successfulStepMaps.slice(rangedStep.mapIndex + 1));
|
|
107
125
|
var fromB = mapPosition(afterStepToFinal, fromAfterStep);
|
|
108
126
|
var toB = mapPosition(afterStepToFinal, toAfterStep);
|
|
127
|
+
if (isReplaceStepForTextBlockNode(rangedStep.step, rangedStep.before, rangedStep.from, rangedStep.to)) {
|
|
128
|
+
var granularStepChanges = ChangeSet.create(rangedStep.before).addSteps(rangedStep.doc, [rangedStep.stepMap], null);
|
|
129
|
+
var optimizedGranularStepChanges = optimizeChanges(simplifyChanges(granularStepChanges.changes, granularStepChanges.startDoc));
|
|
130
|
+
var _iterator3 = _createForOfIteratorHelper(optimizedGranularStepChanges),
|
|
131
|
+
_step3;
|
|
132
|
+
try {
|
|
133
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
134
|
+
var granularChange = _step3.value;
|
|
135
|
+
var granularFromA = mapPosition(beforeStepToOriginal, granularChange.fromA);
|
|
136
|
+
var granularToA = mapPosition(beforeStepToOriginal, granularChange.toA);
|
|
137
|
+
var granularFromB = mapPosition(afterStepToFinal, granularChange.fromB);
|
|
138
|
+
var granularToB = mapPosition(afterStepToFinal, granularChange.toB);
|
|
139
|
+
changes.push({
|
|
140
|
+
fromA: granularFromA,
|
|
141
|
+
toA: granularToA,
|
|
142
|
+
fromB: granularFromB,
|
|
143
|
+
toB: granularToB,
|
|
144
|
+
deleted: createSpans(Math.max(0, granularToA - granularFromA)),
|
|
145
|
+
inserted: createSpans(Math.max(0, granularToB - granularFromB))
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
} catch (err) {
|
|
149
|
+
_iterator3.e(err);
|
|
150
|
+
} finally {
|
|
151
|
+
_iterator3.f();
|
|
152
|
+
}
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
109
155
|
changes.push({
|
|
110
156
|
fromA: fromA,
|
|
111
157
|
toA: toA,
|
|
@@ -154,9 +154,14 @@ export var createPlugin = function createPlugin(config, getIntl, api) {
|
|
|
154
154
|
var activeIndexChanged = (pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex) !== undefined && pluginState.activeIndex !== previousActiveIndex;
|
|
155
155
|
previousActiveIndex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex;
|
|
156
156
|
if ((pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex) !== undefined && activeIndexChanged) {
|
|
157
|
-
var _cancelPendingScrollT;
|
|
157
|
+
var _cancelPendingScrollT, _api$expand;
|
|
158
158
|
(_cancelPendingScrollT = cancelPendingScrollToDecoration) === null || _cancelPendingScrollT === void 0 || _cancelPendingScrollT();
|
|
159
|
-
|
|
159
|
+
var scrollableDecorations = getScrollableDecorations(pluginState.decorations, view.state.doc);
|
|
160
|
+
var activeDecoration = scrollableDecorations[pluginState.activeIndex];
|
|
161
|
+
if (activeDecoration && api !== null && api !== void 0 && (_api$expand = api.expand) !== null && _api$expand !== void 0 && (_api$expand = _api$expand.commands) !== null && _api$expand !== void 0 && _api$expand.toggleExpandRange && fg('platform_editor_show_diff_scroll_navigation')) {
|
|
162
|
+
api === null || api === void 0 || api.core.actions.execute(api.expand.commands.toggleExpandRange(activeDecoration.from, activeDecoration.to, true));
|
|
163
|
+
}
|
|
164
|
+
cancelPendingScrollToDecoration = scrollToActiveDecoration(view, scrollableDecorations, pluginState.activeIndex);
|
|
160
165
|
}
|
|
161
166
|
}
|
|
162
167
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Change } from 'prosemirror-changeset';
|
|
2
2
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import type { Step } from '@atlaskit/editor-prosemirror/transform';
|
|
4
4
|
export declare const diffBySteps: (originalDoc: PMNode, steps: Step[]) => Change[];
|
|
@@ -2,6 +2,7 @@ import type { StepJson } from '@atlaskit/editor-common/collab';
|
|
|
2
2
|
import type { NextEditorPlugin, EditorCommand, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
|
|
4
4
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
5
|
+
import type { ExpandPlugin } from '@atlaskit/editor-plugin-expand';
|
|
5
6
|
import type { Node } from '@atlaskit/editor-prosemirror/model';
|
|
6
7
|
import type { Step } from '@atlaskit/editor-prosemirror/transform';
|
|
7
8
|
export type ColorScheme = 'standard' | 'traditional';
|
|
@@ -37,7 +38,7 @@ export type ShowDiffPlugin = NextEditorPlugin<'showDiff', {
|
|
|
37
38
|
scrollToPrevious: EditorCommand;
|
|
38
39
|
showDiff: (config: PMDiffParams) => EditorCommand;
|
|
39
40
|
};
|
|
40
|
-
dependencies: [OptionalPlugin<AnalyticsPlugin>];
|
|
41
|
+
dependencies: [OptionalPlugin<AnalyticsPlugin>, OptionalPlugin<ExpandPlugin>];
|
|
41
42
|
pluginConfiguration: DiffParams | undefined;
|
|
42
43
|
sharedState: {
|
|
43
44
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Change } from 'prosemirror-changeset';
|
|
2
2
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import type { Step } from '@atlaskit/editor-prosemirror/transform';
|
|
4
4
|
export declare const diffBySteps: (originalDoc: PMNode, steps: Step[]) => Change[];
|
|
@@ -2,6 +2,7 @@ import type { StepJson } from '@atlaskit/editor-common/collab';
|
|
|
2
2
|
import type { NextEditorPlugin, EditorCommand, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
|
|
4
4
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
5
|
+
import type { ExpandPlugin } from '@atlaskit/editor-plugin-expand';
|
|
5
6
|
import type { Node } from '@atlaskit/editor-prosemirror/model';
|
|
6
7
|
import type { Step } from '@atlaskit/editor-prosemirror/transform';
|
|
7
8
|
export type ColorScheme = 'standard' | 'traditional';
|
|
@@ -38,7 +39,8 @@ export type ShowDiffPlugin = NextEditorPlugin<'showDiff', {
|
|
|
38
39
|
showDiff: (config: PMDiffParams) => EditorCommand;
|
|
39
40
|
};
|
|
40
41
|
dependencies: [
|
|
41
|
-
OptionalPlugin<AnalyticsPlugin
|
|
42
|
+
OptionalPlugin<AnalyticsPlugin>,
|
|
43
|
+
OptionalPlugin<ExpandPlugin>
|
|
42
44
|
];
|
|
43
45
|
pluginConfiguration: DiffParams | undefined;
|
|
44
46
|
sharedState: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-show-diff",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.1.1",
|
|
4
4
|
"description": "ShowDiff plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,10 +31,11 @@
|
|
|
31
31
|
"@atlaskit/adf-schema": "^52.5.0",
|
|
32
32
|
"@atlaskit/custom-steps": "^0.16.0",
|
|
33
33
|
"@atlaskit/editor-plugin-analytics": "^10.0.0",
|
|
34
|
+
"@atlaskit/editor-plugin-expand": "^11.0.0",
|
|
34
35
|
"@atlaskit/editor-prosemirror": "^7.3.0",
|
|
35
36
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
36
37
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
37
|
-
"@atlaskit/tmp-editor-statsig": "^62.
|
|
38
|
+
"@atlaskit/tmp-editor-statsig": "^62.8.0",
|
|
38
39
|
"@atlaskit/tokens": "^13.0.0",
|
|
39
40
|
"@babel/runtime": "^7.0.0",
|
|
40
41
|
"lodash": "^4.17.21",
|
|
@@ -56,7 +57,7 @@
|
|
|
56
57
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
57
58
|
},
|
|
58
59
|
"peerDependencies": {
|
|
59
|
-
"@atlaskit/editor-common": "^114.
|
|
60
|
+
"@atlaskit/editor-common": "^114.1.0",
|
|
60
61
|
"react": "^18.2.0"
|
|
61
62
|
},
|
|
62
63
|
"techstack": {
|