@atlaskit/editor-plugin-show-diff 14.0.4 → 14.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 +18 -0
- package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +215 -103
- package/dist/cjs/pm-plugins/calculateDiff/diffBySteps.js +20 -9
- package/dist/cjs/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +89 -0
- package/dist/cjs/pm-plugins/calculateDiff/simplifySteps.js +81 -4
- package/dist/cjs/pm-plugins/decorations/colorSchemes/attributions.js +68 -0
- package/dist/cjs/pm-plugins/decorations/colorSchemes/schemes.js +26 -2
- package/dist/cjs/pm-plugins/decorations/colorSchemes/types.js +5 -1
- package/dist/cjs/pm-plugins/decorations/createBlockChangedDecoration.js +7 -2
- package/dist/cjs/pm-plugins/decorations/createChangedRowDecorationWidgets.js +2 -2
- package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +4 -2
- package/dist/cjs/pm-plugins/decorations/utils/getAttrChangeRanges.js +59 -30
- package/dist/cjs/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +14 -10
- package/dist/cjs/pm-plugins/main.js +1 -0
- package/dist/cjs/showDiffPlugin.js +36 -14
- package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +130 -22
- package/dist/es2019/pm-plugins/calculateDiff/diffBySteps.js +17 -9
- package/dist/es2019/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +64 -0
- package/dist/es2019/pm-plugins/calculateDiff/simplifySteps.js +64 -1
- package/dist/es2019/pm-plugins/decorations/colorSchemes/attributions.js +37 -0
- package/dist/es2019/pm-plugins/decorations/colorSchemes/schemes.js +19 -2
- package/dist/es2019/pm-plugins/decorations/colorSchemes/types.js +1 -0
- package/dist/es2019/pm-plugins/decorations/createBlockChangedDecoration.js +6 -3
- package/dist/es2019/pm-plugins/decorations/createChangedRowDecorationWidgets.js +3 -3
- package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +6 -3
- package/dist/es2019/pm-plugins/decorations/utils/getAttrChangeRanges.js +55 -30
- package/dist/es2019/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +12 -9
- package/dist/es2019/pm-plugins/main.js +1 -0
- package/dist/es2019/showDiffPlugin.js +23 -1
- package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +216 -104
- package/dist/esm/pm-plugins/calculateDiff/diffBySteps.js +20 -9
- package/dist/esm/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +82 -0
- package/dist/esm/pm-plugins/calculateDiff/simplifySteps.js +79 -5
- package/dist/esm/pm-plugins/decorations/colorSchemes/attributions.js +61 -0
- package/dist/esm/pm-plugins/decorations/colorSchemes/schemes.js +24 -1
- package/dist/esm/pm-plugins/decorations/colorSchemes/types.js +1 -0
- package/dist/esm/pm-plugins/decorations/createBlockChangedDecoration.js +8 -3
- package/dist/esm/pm-plugins/decorations/createChangedRowDecorationWidgets.js +3 -3
- package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +5 -3
- package/dist/esm/pm-plugins/decorations/utils/getAttrChangeRanges.js +59 -30
- package/dist/esm/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +14 -9
- package/dist/esm/pm-plugins/main.js +1 -0
- package/dist/esm/showDiffPlugin.js +36 -14
- package/dist/types/entry-points/show-diff-plugin-type.d.ts +1 -1
- package/dist/types/pm-plugins/calculateDiff/diffBySteps.d.ts +2 -1
- package/dist/types/pm-plugins/calculateDiff/simplifyChangesWithAttribution.d.ts +7 -0
- package/dist/types/pm-plugins/calculateDiff/simplifySteps.d.ts +10 -0
- package/dist/types/pm-plugins/decorations/colorSchemes/attributions.d.ts +12 -0
- package/dist/types/pm-plugins/decorations/colorSchemes/schemes.d.ts +5 -3
- package/dist/types/pm-plugins/decorations/colorSchemes/types.d.ts +6 -1
- package/dist/types/pm-plugins/decorations/createBlockChangedDecoration.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/createInlineChangedDecoration.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/utils/getAttrChangeRanges.d.ts +12 -2
- package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.d.ts +2 -1
- package/dist/types/pm-plugins/main.d.ts +3 -1
- package/dist/types/showDiffPluginType.d.ts +29 -1
- package/package.json +10 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-show-diff
|
|
2
2
|
|
|
3
|
+
## 14.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`b1510eccd9729`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b1510eccd9729) -
|
|
8
|
+
Reduce false-positive attribute diff decorations behind
|
|
9
|
+
`platform_editor_reduce_diff_attr_sensitivity`.
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 14.1.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [`69574af99ed9e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/69574af99ed9e) -
|
|
17
|
+
[ux] Add attributed-step inputs and internally selected, gated agent colours behind
|
|
18
|
+
`confluence_ncs_step_diffing_version_history` and
|
|
19
|
+
`platform_editor_show_diff_color_scheme_refactor`.
|
|
20
|
+
|
|
3
21
|
## 14.0.4
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -13,6 +13,7 @@ var _memoizeOne = _interopRequireDefault(require("memoize-one"));
|
|
|
13
13
|
var _prosemirrorChangeset = require("prosemirror-changeset");
|
|
14
14
|
var _deprecatedPlatformFeatureExperiments = require("@atlaskit/editor-common/deprecated-platform-feature-experiments");
|
|
15
15
|
var _document = require("@atlaskit/editor-common/utils/document");
|
|
16
|
+
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
16
17
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
17
18
|
var _fg = require("@atlaskit/platform-feature-flags/fg");
|
|
18
19
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
@@ -21,6 +22,7 @@ var _createAnchorDecorationWidgets = require("../decorations/createAnchorDecorat
|
|
|
21
22
|
var _createBlockChangedDecoration = require("../decorations/createBlockChangedDecoration");
|
|
22
23
|
var _createInlineChangedDecoration = require("../decorations/createInlineChangedDecoration");
|
|
23
24
|
var _createNodeChangedDecorationWidget = require("../decorations/createNodeChangedDecorationWidget");
|
|
25
|
+
var _attributions = require("../decorations/colorSchemes/attributions");
|
|
24
26
|
var _decorationKeys = require("../decorations/decorationKeys");
|
|
25
27
|
var _getAttrChangeRanges = require("../decorations/utils/getAttrChangeRanges");
|
|
26
28
|
var _getMarkChangeRanges = require("../decorations/utils/getMarkChangeRanges");
|
|
@@ -29,6 +31,7 @@ var _attrAwareTokenEncoder = require("./attrAwareTokenEncoder");
|
|
|
29
31
|
var _diffBySteps = require("./diffBySteps");
|
|
30
32
|
var _groupChangesByBlock = require("./groupChangesByBlock");
|
|
31
33
|
var _optimizeChanges = require("./optimizeChanges");
|
|
34
|
+
var _simplifyChangesWithAttribution = require("./simplifyChangesWithAttribution");
|
|
32
35
|
var _simplifySteps = require("./simplifySteps");
|
|
33
36
|
var _classifySmartChanges = require("./smart/classifySmartChanges");
|
|
34
37
|
var _helpers = require("./smart/helpers");
|
|
@@ -72,6 +75,34 @@ var getChanges = function getChanges(_ref) {
|
|
|
72
75
|
var changes = (0, _prosemirrorChangeset.simplifyChanges)(changeset.changes, tr.doc);
|
|
73
76
|
return (0, _optimizeChanges.optimizeChanges)(changes);
|
|
74
77
|
};
|
|
78
|
+
var getAttributedChanges = function getAttributedChanges(_ref2) {
|
|
79
|
+
var attributedChanges = _ref2.attributedChanges,
|
|
80
|
+
changeset = _ref2.changeset,
|
|
81
|
+
originalDoc = _ref2.originalDoc,
|
|
82
|
+
steppedDoc = _ref2.steppedDoc,
|
|
83
|
+
diffType = _ref2.diffType,
|
|
84
|
+
tr = _ref2.tr,
|
|
85
|
+
intl = _ref2.intl,
|
|
86
|
+
smartThresholds = _ref2.smartThresholds;
|
|
87
|
+
if ((0, _isExtendedEnabled.isExtendedEnabled)(diffType)) {
|
|
88
|
+
if (diffType === 'smart' && (0, _fg.fg)('platform_editor_ai_smart_diff')) {
|
|
89
|
+
return (0, _classifySmartChanges.classifySmartChanges)({
|
|
90
|
+
changes: (0, _simplifyChangesWithAttribution.simplifyChangesWithAttribution)(attributedChanges, tr.doc),
|
|
91
|
+
originalDoc: originalDoc,
|
|
92
|
+
newDoc: tr.doc,
|
|
93
|
+
locale: intl.locale,
|
|
94
|
+
thresholds: smartThresholds
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (diffType === 'step') {
|
|
98
|
+
return attributedChanges;
|
|
99
|
+
}
|
|
100
|
+
if (diffType === 'block') {
|
|
101
|
+
return (0, _groupChangesByBlock.groupChangesByBlock)(changeset.changes, originalDoc, steppedDoc);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return (0, _simplifyChangesWithAttribution.simplifyChangesWithAttribution)(attributedChanges, tr.doc);
|
|
105
|
+
};
|
|
75
106
|
|
|
76
107
|
/**
|
|
77
108
|
* Collect the inline-content ranges of every leaf text-bearing block (paragraph, heading, …)
|
|
@@ -130,28 +161,28 @@ var tableRanges = function tableRanges(doc, from, to) {
|
|
|
130
161
|
return ranges;
|
|
131
162
|
};
|
|
132
163
|
var isInsideTable = function isInsideTable(tables, pos) {
|
|
133
|
-
return tables.some(function (
|
|
134
|
-
var
|
|
135
|
-
tFrom =
|
|
136
|
-
tTo =
|
|
164
|
+
return tables.some(function (_ref3) {
|
|
165
|
+
var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
|
|
166
|
+
tFrom = _ref4[0],
|
|
167
|
+
tTo = _ref4[1];
|
|
137
168
|
return pos >= tFrom && pos < tTo;
|
|
138
169
|
});
|
|
139
170
|
};
|
|
140
|
-
var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration(
|
|
141
|
-
var doc =
|
|
142
|
-
from =
|
|
143
|
-
to =
|
|
144
|
-
colorScheme =
|
|
145
|
-
|
|
146
|
-
isInserted =
|
|
147
|
-
activeIndexPos =
|
|
148
|
-
|
|
149
|
-
shouldHideDeleted =
|
|
150
|
-
|
|
151
|
-
showIndicators =
|
|
152
|
-
diffType =
|
|
153
|
-
|
|
154
|
-
coarseTableCellsOnly =
|
|
171
|
+
var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration(_ref5) {
|
|
172
|
+
var doc = _ref5.doc,
|
|
173
|
+
from = _ref5.from,
|
|
174
|
+
to = _ref5.to,
|
|
175
|
+
colorScheme = _ref5.colorScheme,
|
|
176
|
+
_ref5$isInserted = _ref5.isInserted,
|
|
177
|
+
isInserted = _ref5$isInserted === void 0 ? true : _ref5$isInserted,
|
|
178
|
+
activeIndexPos = _ref5.activeIndexPos,
|
|
179
|
+
_ref5$shouldHideDelet = _ref5.shouldHideDeleted,
|
|
180
|
+
shouldHideDeleted = _ref5$shouldHideDelet === void 0 ? false : _ref5$shouldHideDelet,
|
|
181
|
+
_ref5$showIndicators = _ref5.showIndicators,
|
|
182
|
+
showIndicators = _ref5$showIndicators === void 0 ? false : _ref5$showIndicators,
|
|
183
|
+
diffType = _ref5.diffType,
|
|
184
|
+
_ref5$coarseTableCell = _ref5.coarseTableCellsOnly,
|
|
185
|
+
coarseTableCellsOnly = _ref5$coarseTableCell === void 0 ? false : _ref5$coarseTableCell;
|
|
155
186
|
var decorations = [];
|
|
156
187
|
// Coarse path: inside the large table, only cell/header overlays are kept — the
|
|
157
188
|
// table/row/paragraph decorations there are redundant and cause expensive per-cell
|
|
@@ -197,10 +228,10 @@ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration
|
|
|
197
228
|
*
|
|
198
229
|
* Callers are responsible for the `smart` diffType and gate checks.
|
|
199
230
|
*/
|
|
200
|
-
var isDeletedContentPlacedBelow = exports.isDeletedContentPlacedBelow = function isDeletedContentPlacedBelow(
|
|
201
|
-
var change =
|
|
202
|
-
deletedDiffPlacement =
|
|
203
|
-
inlineDeletedDiffPlacement =
|
|
231
|
+
var isDeletedContentPlacedBelow = exports.isDeletedContentPlacedBelow = function isDeletedContentPlacedBelow(_ref6) {
|
|
232
|
+
var change = _ref6.change,
|
|
233
|
+
deletedDiffPlacement = _ref6.deletedDiffPlacement,
|
|
234
|
+
inlineDeletedDiffPlacement = _ref6.inlineDeletedDiffPlacement;
|
|
204
235
|
var level = (0, _helpers.smartChangeLevel)(change);
|
|
205
236
|
if (level === 'node' || level === 'paragraph') {
|
|
206
237
|
return deletedDiffPlacement === 'bottom';
|
|
@@ -209,31 +240,32 @@ var isDeletedContentPlacedBelow = exports.isDeletedContentPlacedBelow = function
|
|
|
209
240
|
// Inline-level (undefined) and sentence-level changes.
|
|
210
241
|
return inlineDeletedDiffPlacement === 'after';
|
|
211
242
|
};
|
|
212
|
-
var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(
|
|
213
|
-
var state =
|
|
214
|
-
pluginState =
|
|
215
|
-
nodeViewSerializer =
|
|
216
|
-
colorScheme =
|
|
217
|
-
intl =
|
|
218
|
-
activeIndexPos =
|
|
219
|
-
api =
|
|
220
|
-
|
|
221
|
-
isInverted =
|
|
222
|
-
|
|
223
|
-
diffType =
|
|
224
|
-
|
|
225
|
-
hideDeletedDiffs =
|
|
226
|
-
|
|
227
|
-
hideAddedDiffsUnderlineParam =
|
|
228
|
-
|
|
229
|
-
showIndicators =
|
|
230
|
-
smartThresholds =
|
|
231
|
-
|
|
232
|
-
deletedDiffPlacement =
|
|
233
|
-
|
|
234
|
-
inlineDeletedDiffPlacement =
|
|
243
|
+
var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref7) {
|
|
244
|
+
var state = _ref7.state,
|
|
245
|
+
pluginState = _ref7.pluginState,
|
|
246
|
+
nodeViewSerializer = _ref7.nodeViewSerializer,
|
|
247
|
+
colorScheme = _ref7.colorScheme,
|
|
248
|
+
intl = _ref7.intl,
|
|
249
|
+
activeIndexPos = _ref7.activeIndexPos,
|
|
250
|
+
api = _ref7.api,
|
|
251
|
+
_ref7$isInverted = _ref7.isInverted,
|
|
252
|
+
isInverted = _ref7$isInverted === void 0 ? false : _ref7$isInverted,
|
|
253
|
+
_ref7$diffType = _ref7.diffType,
|
|
254
|
+
diffType = _ref7$diffType === void 0 ? (0, _isExtendedEnabled.getDefaultDiffType)() : _ref7$diffType,
|
|
255
|
+
_ref7$hideDeletedDiff = _ref7.hideDeletedDiffs,
|
|
256
|
+
hideDeletedDiffs = _ref7$hideDeletedDiff === void 0 ? false : _ref7$hideDeletedDiff,
|
|
257
|
+
_ref7$hideAddedDiffsU = _ref7.hideAddedDiffsUnderline,
|
|
258
|
+
hideAddedDiffsUnderlineParam = _ref7$hideAddedDiffsU === void 0 ? false : _ref7$hideAddedDiffsU,
|
|
259
|
+
_ref7$showIndicators = _ref7.showIndicators,
|
|
260
|
+
showIndicators = _ref7$showIndicators === void 0 ? false : _ref7$showIndicators,
|
|
261
|
+
smartThresholds = _ref7.smartThresholds,
|
|
262
|
+
_ref7$deletedDiffPlac = _ref7.deletedDiffPlacement,
|
|
263
|
+
deletedDiffPlacement = _ref7$deletedDiffPlac === void 0 ? 'top' : _ref7$deletedDiffPlac,
|
|
264
|
+
_ref7$inlineDeletedDi = _ref7.inlineDeletedDiffPlacement,
|
|
265
|
+
inlineDeletedDiffPlacement = _ref7$inlineDeletedDi === void 0 ? 'before' : _ref7$inlineDeletedDi;
|
|
235
266
|
var originalDoc = pluginState.originalDoc,
|
|
236
267
|
steps = pluginState.steps,
|
|
268
|
+
stepAttributions = pluginState.stepAttributions,
|
|
237
269
|
isDisplayingChanges = pluginState.isDisplayingChanges;
|
|
238
270
|
if (!originalDoc || !isDisplayingChanges) {
|
|
239
271
|
return {
|
|
@@ -247,8 +279,23 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
|
|
|
247
279
|
var hideAddedDiffsUnderline = hideAddedDiffsUnderlineParam && (0, _fg.fg)('platform_editor_ai_smart_diff');
|
|
248
280
|
var tr = state.tr;
|
|
249
281
|
var steppedDoc = originalDoc;
|
|
250
|
-
var
|
|
251
|
-
var simplifiedSteps
|
|
282
|
+
var attributionColoringEnabled = (0, _attributions.isAttributionColoringEnabled)(stepAttributions);
|
|
283
|
+
var simplifiedSteps;
|
|
284
|
+
var simplifiedStepAttributions = [];
|
|
285
|
+
if (attributionColoringEnabled) {
|
|
286
|
+
var simplifiedStepsWithAttribution = (0, _simplifySteps.simplifyStepsWithAttribution)(steps, stepAttributions !== null && stepAttributions !== void 0 ? stepAttributions : [], originalDoc);
|
|
287
|
+
simplifiedSteps = simplifiedStepsWithAttribution.map(function (_ref8) {
|
|
288
|
+
var step = _ref8.step;
|
|
289
|
+
return step;
|
|
290
|
+
});
|
|
291
|
+
simplifiedStepAttributions = simplifiedStepsWithAttribution.map(function (_ref9) {
|
|
292
|
+
var stepAttribution = _ref9.stepAttribution;
|
|
293
|
+
return stepAttribution;
|
|
294
|
+
});
|
|
295
|
+
} else {
|
|
296
|
+
simplifiedSteps = (0, _simplifySteps.simplifySteps)(steps, originalDoc);
|
|
297
|
+
}
|
|
298
|
+
var pendingAttrSteps = [];
|
|
252
299
|
var stepMaps = [];
|
|
253
300
|
var _iterator = _createForOfIteratorHelper(simplifiedSteps),
|
|
254
301
|
_step;
|
|
@@ -258,20 +305,56 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
|
|
|
258
305
|
var result = step.apply(steppedDoc);
|
|
259
306
|
if (result.failed === null && result.doc) {
|
|
260
307
|
if ((0, _getAttrChangeRanges.stepIsValidAttrChange)(step, steppedDoc, result.doc)) {
|
|
261
|
-
|
|
308
|
+
pendingAttrSteps.push({
|
|
309
|
+
afterNode: result.doc.nodeAt(step.pos),
|
|
310
|
+
beforeNode: steppedDoc.nodeAt(step.pos),
|
|
311
|
+
mapIndex: stepMaps.length,
|
|
312
|
+
step: step
|
|
313
|
+
});
|
|
262
314
|
}
|
|
263
315
|
stepMaps.push(step.getMap());
|
|
264
316
|
steppedDoc = result.doc;
|
|
265
317
|
}
|
|
266
318
|
}
|
|
267
|
-
|
|
268
|
-
//
|
|
269
|
-
// changes and ignores differences in attributes which don't affect decoration positions
|
|
319
|
+
// Gate the complete attribution fix: mapped positions and step-time nodes are used together.
|
|
320
|
+
// The fallback deliberately preserves the legacy raw-position lookups for rollout safety.
|
|
270
321
|
} catch (err) {
|
|
271
322
|
_iterator.e(err);
|
|
272
323
|
} finally {
|
|
273
324
|
_iterator.f();
|
|
274
325
|
}
|
|
326
|
+
var attrStepContexts = (0, _fg.fg)('platform_editor_reduce_diff_attr_sensitivity') ? pendingAttrSteps.flatMap(function (_ref0) {
|
|
327
|
+
var afterNode = _ref0.afterNode,
|
|
328
|
+
beforeNode = _ref0.beforeNode,
|
|
329
|
+
mapIndex = _ref0.mapIndex,
|
|
330
|
+
step = _ref0.step;
|
|
331
|
+
var finalPosition = new _transform.Mapping(stepMaps.slice(mapIndex + 1)).mapResult(step.pos);
|
|
332
|
+
if (finalPosition.deleted) {
|
|
333
|
+
return [];
|
|
334
|
+
}
|
|
335
|
+
var originalPosition = new _transform.Mapping(stepMaps.slice(0, mapIndex)).invert().mapResult(step.pos);
|
|
336
|
+
return [_objectSpread(_objectSpread({
|
|
337
|
+
afterNode: afterNode,
|
|
338
|
+
beforeNode: beforeNode,
|
|
339
|
+
finalPos: finalPosition.pos
|
|
340
|
+
}, originalPosition.deleted ? {} : {
|
|
341
|
+
originalPos: originalPosition.pos
|
|
342
|
+
}), {}, {
|
|
343
|
+
step: step
|
|
344
|
+
})];
|
|
345
|
+
}) : pendingAttrSteps.map(function (_ref1) {
|
|
346
|
+
var step = _ref1.step;
|
|
347
|
+
return {
|
|
348
|
+
afterNode: tr.doc.nodeAt(step.pos),
|
|
349
|
+
beforeNode: originalDoc.nodeAt(step.pos),
|
|
350
|
+
finalPos: step.pos,
|
|
351
|
+
originalPos: step.pos,
|
|
352
|
+
step: step
|
|
353
|
+
};
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
// Rather than using .eq() we use a custom function that only checks for structural
|
|
357
|
+
// changes and ignores differences in attributes which don't affect decoration positions
|
|
275
358
|
if (!(0, _document.areNodesEqualIgnoreAttrs)(steppedDoc, tr.doc)) {
|
|
276
359
|
var _api$analytics;
|
|
277
360
|
var recoveredViaContentEquality = (0, _areDocsEqualByBlockStructureAndText.areDocsEqualByBlockStructureAndText)(steppedDoc, tr.doc);
|
|
@@ -296,17 +379,45 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
|
|
|
296
379
|
// gated with it; other diff types keep the library default so their output is
|
|
297
380
|
// unchanged.
|
|
298
381
|
var tokenEncoder = diffType === 'smart' && (0, _fg.fg)('platform_editor_ai_smart_diff') ? _attrAwareTokenEncoder.attrAwareTokenEncoder : undefined;
|
|
299
|
-
var
|
|
300
|
-
var
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
382
|
+
var changes;
|
|
383
|
+
var attributedChanges = [];
|
|
384
|
+
var attributionColors;
|
|
385
|
+
if (attributionColoringEnabled) {
|
|
386
|
+
var changeset = _prosemirrorChangeset.ChangeSet.create(originalDoc, function (left, right) {
|
|
387
|
+
return (0, _attributions.getAttributionKey)(left) === (0, _attributions.getAttributionKey)(right) ? left.stepIndex > right.stepIndex ? left : right :
|
|
388
|
+
// `prosemirror-changeset` uses null as its incompatible-data sentinel even
|
|
389
|
+
// though its public combine callback is typed as returning Data.
|
|
390
|
+
null;
|
|
391
|
+
}, tokenEncoder).addSteps(steppedDoc, stepMaps, simplifiedStepAttributions.map(function (attribution, stepIndex) {
|
|
392
|
+
return _objectSpread(_objectSpread({}, attribution), {}, {
|
|
393
|
+
stepIndex: stepIndex
|
|
394
|
+
});
|
|
395
|
+
}));
|
|
396
|
+
attributedChanges = (0, _diffBySteps.diffBySteps)(originalDoc, simplifiedSteps, simplifiedStepAttributions);
|
|
397
|
+
changes = getAttributedChanges({
|
|
398
|
+
changeset: changeset,
|
|
399
|
+
originalDoc: originalDoc,
|
|
400
|
+
steppedDoc: steppedDoc,
|
|
401
|
+
diffType: diffType,
|
|
402
|
+
tr: tr,
|
|
403
|
+
attributedChanges: attributedChanges,
|
|
404
|
+
intl: intl,
|
|
405
|
+
smartThresholds: smartThresholds
|
|
406
|
+
});
|
|
407
|
+
attributionColors = (0, _attributions.createAttributionColorMap)(simplifiedStepAttributions);
|
|
408
|
+
} else {
|
|
409
|
+
var _changeset = _prosemirrorChangeset.ChangeSet.create(originalDoc, undefined, tokenEncoder).addSteps(steppedDoc, stepMaps, tr.doc);
|
|
410
|
+
changes = getChanges({
|
|
411
|
+
changeset: _changeset,
|
|
412
|
+
originalDoc: originalDoc,
|
|
413
|
+
steppedDoc: steppedDoc,
|
|
414
|
+
diffType: diffType,
|
|
415
|
+
tr: tr,
|
|
416
|
+
steps: simplifiedSteps,
|
|
417
|
+
intl: intl,
|
|
418
|
+
smartThresholds: smartThresholds
|
|
419
|
+
});
|
|
420
|
+
}
|
|
310
421
|
var decorations = [];
|
|
311
422
|
|
|
312
423
|
/**
|
|
@@ -319,6 +430,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
|
|
|
319
430
|
// Our default operations are insertions, so it should match the opposite of isInverted.
|
|
320
431
|
var isInserted = !isInverted;
|
|
321
432
|
var createDecorationsForChange = function createDecorationsForChange(change) {
|
|
433
|
+
var changeColorScheme = attributionColors ? (0, _attributions.getColorSchemeForChange)(change, attributedChanges, attributionColors, colorScheme) : colorScheme;
|
|
322
434
|
var isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
|
|
323
435
|
|
|
324
436
|
// Hoisted because it decides BOTH where the deleted widget is anchored and — since the
|
|
@@ -373,7 +485,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
|
|
|
373
485
|
toB: to
|
|
374
486
|
},
|
|
375
487
|
doc: tr.doc,
|
|
376
|
-
colorScheme:
|
|
488
|
+
colorScheme: changeColorScheme,
|
|
377
489
|
isActive: isActive,
|
|
378
490
|
diffType: diffType
|
|
379
491
|
}, (0, _isExtendedEnabled.isExtendedEnabled)(diffType) && {
|
|
@@ -394,7 +506,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
|
|
|
394
506
|
decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createInlineChangedDecoration.createInlineChangedDecoration)(_objectSpread({
|
|
395
507
|
change: change,
|
|
396
508
|
doc: tr.doc,
|
|
397
|
-
colorScheme:
|
|
509
|
+
colorScheme: changeColorScheme,
|
|
398
510
|
isActive: isActive,
|
|
399
511
|
diffType: diffType
|
|
400
512
|
}, (0, _isExtendedEnabled.isExtendedEnabled)(diffType) && {
|
|
@@ -410,7 +522,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
|
|
|
410
522
|
doc: tr.doc,
|
|
411
523
|
from: change.fromB,
|
|
412
524
|
to: change.toB,
|
|
413
|
-
colorScheme:
|
|
525
|
+
colorScheme: changeColorScheme
|
|
414
526
|
}, (0, _isExtendedEnabled.isExtendedEnabled)(diffType) && {
|
|
415
527
|
isInserted: isInserted,
|
|
416
528
|
shouldHideDeleted: shouldHideDeleted,
|
|
@@ -429,7 +541,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
|
|
|
429
541
|
change: change,
|
|
430
542
|
doc: originalDoc,
|
|
431
543
|
nodeViewSerializer: nodeViewSerializer,
|
|
432
|
-
colorScheme:
|
|
544
|
+
colorScheme: changeColorScheme,
|
|
433
545
|
newDoc: tr.doc,
|
|
434
546
|
intl: intl,
|
|
435
547
|
activeIndexPos: activeIndexPos
|
|
@@ -456,7 +568,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
|
|
|
456
568
|
isInserted: true
|
|
457
569
|
})));
|
|
458
570
|
});
|
|
459
|
-
(0, _getAttrChangeRanges.getAttrChangeRanges)(tr.doc,
|
|
571
|
+
(0, _getAttrChangeRanges.getAttrChangeRanges)(tr.doc, attrStepContexts, originalDoc).forEach(function (change) {
|
|
460
572
|
if (change.isInline) {
|
|
461
573
|
// Inline nodes (e.g. date, emoji, mention, status) need an inline decoration rather than a block decoration
|
|
462
574
|
var isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
|
|
@@ -546,42 +658,42 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
|
|
|
546
658
|
};
|
|
547
659
|
var calculateDiffDecorations = exports.calculateDiffDecorations = (0, _memoizeOne.default)(calculateDiffDecorationsInner,
|
|
548
660
|
// Cache results unless relevant inputs change
|
|
549
|
-
function (
|
|
550
|
-
var
|
|
551
|
-
var
|
|
552
|
-
|
|
553
|
-
pluginState =
|
|
554
|
-
state =
|
|
555
|
-
colorScheme =
|
|
556
|
-
intl =
|
|
557
|
-
activeIndexPos =
|
|
558
|
-
isInverted =
|
|
559
|
-
diffType =
|
|
560
|
-
hideDeletedDiffs =
|
|
561
|
-
hideAddedDiffsUnderline =
|
|
562
|
-
showIndicators =
|
|
563
|
-
smartThresholds =
|
|
564
|
-
deletedDiffPlacement =
|
|
565
|
-
inlineDeletedDiffPlacement =
|
|
566
|
-
var
|
|
567
|
-
|
|
568
|
-
lastPluginState =
|
|
569
|
-
lastState =
|
|
570
|
-
lastColorScheme =
|
|
571
|
-
lastIntl =
|
|
572
|
-
lastActiveIndexPos =
|
|
573
|
-
lastIsInverted =
|
|
574
|
-
lastDiffType =
|
|
575
|
-
lastHideDeletedDiffs =
|
|
576
|
-
lastHideAddedDiffsUnderline =
|
|
577
|
-
lastShowIndicators =
|
|
578
|
-
lastSmartThresholds =
|
|
579
|
-
lastDeletedDiffPlacement =
|
|
580
|
-
lastInlineDeletedDiffPlacement =
|
|
661
|
+
function (_ref10, _ref11) {
|
|
662
|
+
var _ref15;
|
|
663
|
+
var _ref12 = (0, _slicedToArray2.default)(_ref10, 1),
|
|
664
|
+
_ref12$ = _ref12[0],
|
|
665
|
+
pluginState = _ref12$.pluginState,
|
|
666
|
+
state = _ref12$.state,
|
|
667
|
+
colorScheme = _ref12$.colorScheme,
|
|
668
|
+
intl = _ref12$.intl,
|
|
669
|
+
activeIndexPos = _ref12$.activeIndexPos,
|
|
670
|
+
isInverted = _ref12$.isInverted,
|
|
671
|
+
diffType = _ref12$.diffType,
|
|
672
|
+
hideDeletedDiffs = _ref12$.hideDeletedDiffs,
|
|
673
|
+
hideAddedDiffsUnderline = _ref12$.hideAddedDiffsUnderline,
|
|
674
|
+
showIndicators = _ref12$.showIndicators,
|
|
675
|
+
smartThresholds = _ref12$.smartThresholds,
|
|
676
|
+
deletedDiffPlacement = _ref12$.deletedDiffPlacement,
|
|
677
|
+
inlineDeletedDiffPlacement = _ref12$.inlineDeletedDiffPlacement;
|
|
678
|
+
var _ref13 = (0, _slicedToArray2.default)(_ref11, 1),
|
|
679
|
+
_ref13$ = _ref13[0],
|
|
680
|
+
lastPluginState = _ref13$.pluginState,
|
|
681
|
+
lastState = _ref13$.state,
|
|
682
|
+
lastColorScheme = _ref13$.colorScheme,
|
|
683
|
+
lastIntl = _ref13$.intl,
|
|
684
|
+
lastActiveIndexPos = _ref13$.activeIndexPos,
|
|
685
|
+
lastIsInverted = _ref13$.isInverted,
|
|
686
|
+
lastDiffType = _ref13$.diffType,
|
|
687
|
+
lastHideDeletedDiffs = _ref13$.hideDeletedDiffs,
|
|
688
|
+
lastHideAddedDiffsUnderline = _ref13$.hideAddedDiffsUnderline,
|
|
689
|
+
lastShowIndicators = _ref13$.showIndicators,
|
|
690
|
+
lastSmartThresholds = _ref13$.smartThresholds,
|
|
691
|
+
lastDeletedDiffPlacement = _ref13$.deletedDiffPlacement,
|
|
692
|
+
lastInlineDeletedDiffPlacement = _ref13$.inlineDeletedDiffPlacement;
|
|
581
693
|
var originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
|
|
582
694
|
if ((0, _isExtendedEnabled.isExtendedEnabled)(diffType)) {
|
|
583
|
-
var
|
|
584
|
-
return (
|
|
695
|
+
var _ref14;
|
|
696
|
+
return (_ref14 = colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isInverted === lastIsInverted && diffType === lastDiffType && (0, _isEqual.default)(activeIndexPos, lastActiveIndexPos) && originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && (0, _isEqual.default)(pluginState.stepAttributions, lastPluginState.stepAttributions) && state.doc.eq(lastState.doc) && hideDeletedDiffs === lastHideDeletedDiffs && hideAddedDiffsUnderline === lastHideAddedDiffsUnderline && showIndicators === lastShowIndicators && (0, _isEqual.default)(smartThresholds, lastSmartThresholds) && deletedDiffPlacement === lastDeletedDiffPlacement && inlineDeletedDiffPlacement === lastInlineDeletedDiffPlacement) !== null && _ref14 !== void 0 ? _ref14 : false;
|
|
585
697
|
}
|
|
586
|
-
return (
|
|
698
|
+
return (_ref15 = originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && (0, _isEqual.default)(pluginState.stepAttributions, lastPluginState.stepAttributions) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && (0, _isEqual.default)(activeIndexPos, lastActiveIndexPos) && hideDeletedDiffs === lastHideDeletedDiffs) !== null && _ref15 !== void 0 ? _ref15 : false;
|
|
587
699
|
});
|
|
@@ -5,11 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.diffBySteps = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
8
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
11
|
var _prosemirrorChangeset = require("prosemirror-changeset");
|
|
11
12
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
12
13
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
14
|
+
var _attributions = require("../decorations/colorSchemes/attributions");
|
|
13
15
|
var _attrAwareTokenEncoder = require("./attrAwareTokenEncoder");
|
|
14
16
|
var _optimizeChanges = require("./optimizeChanges");
|
|
15
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; }
|
|
@@ -205,9 +207,10 @@ var createMapping = function createMapping(maps) {
|
|
|
205
207
|
return mapping;
|
|
206
208
|
};
|
|
207
209
|
var createSpans = function createSpans(length) {
|
|
210
|
+
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
208
211
|
return length > 0 ? [{
|
|
209
212
|
length: length,
|
|
210
|
-
data:
|
|
213
|
+
data: data
|
|
211
214
|
}] : [];
|
|
212
215
|
};
|
|
213
216
|
var mergeOverlappingByNewDocRange = function mergeOverlappingByNewDocRange(changes) {
|
|
@@ -220,8 +223,11 @@ var mergeOverlappingByNewDocRange = function mergeOverlappingByNewDocRange(chang
|
|
|
220
223
|
var merged = [];
|
|
221
224
|
var current = _objectSpread({}, sortedChanges[0]);
|
|
222
225
|
for (var i = 1; i < sortedChanges.length; i++) {
|
|
226
|
+
var _, _2;
|
|
223
227
|
var next = sortedChanges[i];
|
|
224
|
-
var
|
|
228
|
+
var currentIdentity = (0, _attributions.getAttributionKey)((_ = [].concat((0, _toConsumableArray2.default)(current.deleted), (0, _toConsumableArray2.default)(current.inserted))[0]) === null || _ === void 0 ? void 0 : _.data);
|
|
229
|
+
var nextIdentity = (0, _attributions.getAttributionKey)((_2 = [].concat((0, _toConsumableArray2.default)(next.deleted), (0, _toConsumableArray2.default)(next.inserted))[0]) === null || _2 === void 0 ? void 0 : _2.data);
|
|
230
|
+
var isOverlapping = next.fromB <= current.toB && currentIdentity === nextIdentity;
|
|
225
231
|
if (isOverlapping) {
|
|
226
232
|
current = {
|
|
227
233
|
fromA: Math.min(current.fromA, next.fromA),
|
|
@@ -275,16 +281,18 @@ var shouldCheckGranularDiff = function shouldCheckGranularDiff(step, before, fro
|
|
|
275
281
|
var isTextContentEqual = (replacedNode === null || replacedNode === void 0 ? void 0 : replacedNode.textContent) === (replacingNode === null || replacingNode === void 0 ? void 0 : replacingNode.textContent);
|
|
276
282
|
return !isTextContentEqual || isTextContentEqual && hasSameChildMarks(replacedNode, replacingNode);
|
|
277
283
|
};
|
|
278
|
-
var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps) {
|
|
284
|
+
var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps, stepAttributions) {
|
|
279
285
|
var changes = [];
|
|
280
286
|
var currentDoc = originalDoc;
|
|
281
287
|
var successfulStepMaps = [];
|
|
282
288
|
var rangedSteps = [];
|
|
283
|
-
var _iterator2 = _createForOfIteratorHelper(steps),
|
|
289
|
+
var _iterator2 = _createForOfIteratorHelper(steps.entries()),
|
|
284
290
|
_step2;
|
|
285
291
|
try {
|
|
286
292
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
287
|
-
var
|
|
293
|
+
var _step2$value = (0, _slicedToArray2.default)(_step2.value, 2),
|
|
294
|
+
stepIndex = _step2$value[0],
|
|
295
|
+
step = _step2$value[1];
|
|
288
296
|
var before = currentDoc;
|
|
289
297
|
var result = step.apply(currentDoc);
|
|
290
298
|
if (result.failed !== null || !result.doc) {
|
|
@@ -299,6 +307,9 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
|
|
|
299
307
|
from: rangeStep.from,
|
|
300
308
|
to: rangeStep.to,
|
|
301
309
|
mapIndex: successfulStepMaps.length,
|
|
310
|
+
stepAttribution: stepAttributions !== null && stepAttributions !== void 0 && stepAttributions[stepIndex] ? _objectSpread(_objectSpread({}, stepAttributions[stepIndex]), {}, {
|
|
311
|
+
stepIndex: stepIndex
|
|
312
|
+
}) : null,
|
|
302
313
|
step: step,
|
|
303
314
|
stepMap: stepMap
|
|
304
315
|
});
|
|
@@ -384,8 +395,8 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
|
|
|
384
395
|
toA: granularToA,
|
|
385
396
|
fromB: granularFromB,
|
|
386
397
|
toB: granularToB,
|
|
387
|
-
deleted: createSpans(Math.max(0, granularToA - granularFromA)),
|
|
388
|
-
inserted: createSpans(Math.max(0, granularToB - granularFromB))
|
|
398
|
+
deleted: createSpans(Math.max(0, granularToA - granularFromA), rangedStep.stepAttribution),
|
|
399
|
+
inserted: createSpans(Math.max(0, granularToB - granularFromB), rangedStep.stepAttribution)
|
|
389
400
|
});
|
|
390
401
|
}
|
|
391
402
|
} catch (err) {
|
|
@@ -400,8 +411,8 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
|
|
|
400
411
|
toA: toA,
|
|
401
412
|
fromB: fromB,
|
|
402
413
|
toB: toB,
|
|
403
|
-
deleted: createSpans(Math.max(0, toA - fromA)),
|
|
404
|
-
inserted: createSpans(Math.max(0, toB - fromB))
|
|
414
|
+
deleted: createSpans(Math.max(0, toA - fromA), rangedStep.stepAttribution),
|
|
415
|
+
inserted: createSpans(Math.max(0, toB - fromB), rangedStep.stepAttribution)
|
|
405
416
|
});
|
|
406
417
|
}
|
|
407
418
|
return mergeOverlappingByNewDocRange(changes);
|