@atlaskit/editor-plugin-show-diff 10.1.10 → 10.1.11
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 +9 -0
- package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +118 -31
- package/dist/cjs/pm-plugins/calculateDiff/diffBySteps.js +124 -1
- package/dist/cjs/pm-plugins/decorations/createGranularBlockReferenceWidget.js +125 -0
- package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +17 -103
- package/dist/cjs/pm-plugins/decorations/utils/wrapBlockNodeView.js +79 -1
- package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +91 -7
- package/dist/es2019/pm-plugins/calculateDiff/diffBySteps.js +104 -0
- package/dist/es2019/pm-plugins/decorations/createGranularBlockReferenceWidget.js +120 -0
- package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +1 -81
- package/dist/es2019/pm-plugins/decorations/utils/wrapBlockNodeView.js +74 -2
- package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +119 -32
- package/dist/esm/pm-plugins/calculateDiff/diffBySteps.js +123 -0
- package/dist/esm/pm-plugins/decorations/createGranularBlockReferenceWidget.js +120 -0
- package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +13 -98
- package/dist/esm/pm-plugins/decorations/utils/wrapBlockNodeView.js +79 -2
- package/dist/types/pm-plugins/calculateDiff/diffBySteps.d.ts +20 -0
- package/dist/types/pm-plugins/decorations/createGranularBlockReferenceWidget.d.ts +36 -0
- package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +15 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-show-diff
|
|
2
2
|
|
|
3
|
+
## 10.1.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`0096393101f67`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0096393101f67) -
|
|
8
|
+
Render inverted granular step diffs as a hybrid (based on threshold): granular changed inline plus
|
|
9
|
+
a 'reference' block crossed out underneath
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
3
12
|
## 10.1.10
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -17,6 +17,7 @@ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
|
17
17
|
var _areDocsEqualByBlockStructureAndText = require("../areDocsEqualByBlockStructureAndText");
|
|
18
18
|
var _createAnchorDecorationWidgets = require("../decorations/createAnchorDecorationWidgets");
|
|
19
19
|
var _createBlockChangedDecoration = require("../decorations/createBlockChangedDecoration");
|
|
20
|
+
var _createGranularBlockReferenceWidget = require("../decorations/createGranularBlockReferenceWidget");
|
|
20
21
|
var _createInlineChangedDecoration = require("../decorations/createInlineChangedDecoration");
|
|
21
22
|
var _createNodeChangedDecorationWidget = require("../decorations/createNodeChangedDecorationWidget");
|
|
22
23
|
var _decorationKeys = require("../decorations/decorationKeys");
|
|
@@ -171,12 +172,16 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
|
|
|
171
172
|
if (showIndicators && (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
172
173
|
decorations.push((0, _createAnchorDecorationWidgets.createDocMarginAnchorWidget)());
|
|
173
174
|
}
|
|
174
|
-
|
|
175
|
+
|
|
176
|
+
// Our default operations are insertions, so it should match the opposite of isInverted.
|
|
177
|
+
var isInserted = !isInverted;
|
|
178
|
+
var createDecorationsForChange = function createDecorationsForChange(change, showGranularWithBlock) {
|
|
175
179
|
var isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
|
|
176
|
-
// Our default operations are insertions, so it should match the opposite of isInverted.
|
|
177
|
-
var isInserted = !isInverted;
|
|
178
180
|
if (change.inserted.length > 0) {
|
|
179
|
-
|
|
181
|
+
// shouldHideDeleted for block/node decorations: suppressed when isInverted + hideDeletedDiffs,
|
|
182
|
+
// or when showGranularWithBlock (block reference widget is shown instead).
|
|
183
|
+
// isInverted gates both — on an inverted diff the inserted side is visually the deleted side.
|
|
184
|
+
var shouldHideDeleted = (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? isInverted && (hideDeletedDiffs || showGranularWithBlock) && change.deleted.length > 0 : false;
|
|
180
185
|
decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createInlineChangedDecoration.createInlineChangedDecoration)(_objectSpread({
|
|
181
186
|
change: change,
|
|
182
187
|
doc: tr.doc,
|
|
@@ -201,7 +206,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
|
|
|
201
206
|
}))));
|
|
202
207
|
}
|
|
203
208
|
if (change.deleted.length > 0) {
|
|
204
|
-
var _shouldHideDeleted = (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? !isInverted && hideDeletedDiffs : false;
|
|
209
|
+
var _shouldHideDeleted = (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? !isInverted && (hideDeletedDiffs || showGranularWithBlock) && change.inserted.length > 0 : false;
|
|
205
210
|
if (!_shouldHideDeleted) {
|
|
206
211
|
decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createNodeChangedDecorationWidget.createNodeChangedDecorationWidget)(_objectSpread(_objectSpread({
|
|
207
212
|
change: change,
|
|
@@ -219,7 +224,89 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
|
|
|
219
224
|
}))));
|
|
220
225
|
}
|
|
221
226
|
}
|
|
222
|
-
}
|
|
227
|
+
};
|
|
228
|
+
if (diffType === 'step' && (0, _expValEquals.expValEquals)('platform_editor_diff_granular_extended', 'isEnabled', true)) {
|
|
229
|
+
// Uses getStepChanges instead of getChanges so that we have per-step granularity metadata.
|
|
230
|
+
// Specifically, we need to know how many granular changes each step produced in order to
|
|
231
|
+
// apply the shouldHideDeleted suppression threshold (> 3 granular changes per step).
|
|
232
|
+
// getChanges returns a flat Change[] with no per-step grouping, making this count impossible
|
|
233
|
+
// to derive after the fact without re-introducing per-change metadata.
|
|
234
|
+
var stepChanges = (0, _diffBySteps.getStepChanges)(originalDoc, steps);
|
|
235
|
+
stepChanges.forEach(function (_ref4) {
|
|
236
|
+
var isGranular = _ref4.isGranular,
|
|
237
|
+
stepChangeList = _ref4.changes;
|
|
238
|
+
var granularCount = isGranular ? stepChangeList.length : 0;
|
|
239
|
+
|
|
240
|
+
// Calculate the average ratio of changed content on both A (original) and B (new)
|
|
241
|
+
// sides of the diff. If 30% or more of the block has changed on average, we show
|
|
242
|
+
// the block reference widget even if the granular change count is below the threshold.
|
|
243
|
+
// Block length is derived from the enclosing text block boundaries rather than the
|
|
244
|
+
// first/last change positions, so unchanged words at the start/end are accounted for.
|
|
245
|
+
var avgChangedRatio = 0;
|
|
246
|
+
if (isGranular && stepChangeList.length > 0) {
|
|
247
|
+
var first = stepChangeList[0];
|
|
248
|
+
var last = stepChangeList[stepChangeList.length - 1];
|
|
249
|
+
var resolvedA = originalDoc.resolve(first.fromA);
|
|
250
|
+
var resolvedB = tr.doc.resolve(first.fromB);
|
|
251
|
+
var blockStartA = first.fromA;
|
|
252
|
+
var blockEndA = last.toA;
|
|
253
|
+
var blockStartB = first.fromB;
|
|
254
|
+
var blockEndB = last.toB;
|
|
255
|
+
for (var depth = resolvedA.depth; depth >= 0; depth--) {
|
|
256
|
+
var node = resolvedA.node(depth);
|
|
257
|
+
if (node.isTextblock) {
|
|
258
|
+
blockStartA = resolvedA.start(depth);
|
|
259
|
+
blockEndA = blockStartA + node.nodeSize - 2; // exclude open/close tokens
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
for (var _depth = resolvedB.depth; _depth >= 0; _depth--) {
|
|
264
|
+
var _node = resolvedB.node(_depth);
|
|
265
|
+
if (_node.isTextblock) {
|
|
266
|
+
blockStartB = resolvedB.start(_depth);
|
|
267
|
+
blockEndB = blockStartB + _node.nodeSize - 2; // exclude open/close tokens
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
var blockLengthA = blockEndA - blockStartA;
|
|
272
|
+
var blockLengthB = blockEndB - blockStartB;
|
|
273
|
+
var totalChangedA = stepChangeList.reduce(function (sum, c) {
|
|
274
|
+
return sum + (c.toA - c.fromA);
|
|
275
|
+
}, 0);
|
|
276
|
+
var totalChangedB = stepChangeList.reduce(function (sum, c) {
|
|
277
|
+
return sum + (c.toB - c.fromB);
|
|
278
|
+
}, 0);
|
|
279
|
+
var ratioA = blockLengthA > 0 ? totalChangedA / blockLengthA : 0;
|
|
280
|
+
var ratioB = blockLengthB > 0 ? totalChangedB / blockLengthB : 0;
|
|
281
|
+
avgChangedRatio = (ratioA + ratioB) / 2;
|
|
282
|
+
}
|
|
283
|
+
var showGranularWithBlock = isGranular && granularCount !== 1 && (granularCount > 3 || avgChangedRatio >= 0.3);
|
|
284
|
+
stepChangeList.forEach(function (change) {
|
|
285
|
+
createDecorationsForChange(change, showGranularWithBlock);
|
|
286
|
+
});
|
|
287
|
+
if (showGranularWithBlock && stepChangeList.length > 0) {
|
|
288
|
+
var lastChange = stepChangeList[stepChangeList.length - 1];
|
|
289
|
+
var granularBlockDiffId = crypto.randomUUID();
|
|
290
|
+
var blockWidgets = (0, _createGranularBlockReferenceWidget.createGranularBlockReferenceWidget)({
|
|
291
|
+
change: lastChange,
|
|
292
|
+
originalDoc: originalDoc,
|
|
293
|
+
newDoc: tr.doc,
|
|
294
|
+
isInverted: isInverted,
|
|
295
|
+
nodeViewSerializer: nodeViewSerializer,
|
|
296
|
+
colorScheme: colorScheme,
|
|
297
|
+
intl: intl,
|
|
298
|
+
activeIndexPos: activeIndexPos,
|
|
299
|
+
diffId: granularBlockDiffId,
|
|
300
|
+
showIndicators: showIndicators
|
|
301
|
+
});
|
|
302
|
+
decorations.push.apply(decorations, (0, _toConsumableArray2.default)(blockWidgets));
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
} else {
|
|
306
|
+
changes.forEach(function (change) {
|
|
307
|
+
createDecorationsForChange(change, /* showGranularWithBlock */false);
|
|
308
|
+
});
|
|
309
|
+
}
|
|
223
310
|
(0, _getMarkChangeRanges.getMarkChangeRanges)(steps).forEach(function (change) {
|
|
224
311
|
var isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
|
|
225
312
|
decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createInlineChangedDecoration.createInlineChangedDecoration)({
|
|
@@ -259,34 +346,34 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
|
|
|
259
346
|
};
|
|
260
347
|
var calculateDiffDecorations = exports.calculateDiffDecorations = (0, _memoizeOne.default)(calculateDiffDecorationsInner,
|
|
261
348
|
// Cache results unless relevant inputs change
|
|
262
|
-
function (
|
|
263
|
-
var
|
|
264
|
-
var _ref6 = (0, _slicedToArray2.default)(_ref4, 1),
|
|
265
|
-
_ref6$ = _ref6[0],
|
|
266
|
-
pluginState = _ref6$.pluginState,
|
|
267
|
-
state = _ref6$.state,
|
|
268
|
-
colorScheme = _ref6$.colorScheme,
|
|
269
|
-
intl = _ref6$.intl,
|
|
270
|
-
activeIndexPos = _ref6$.activeIndexPos,
|
|
271
|
-
isInverted = _ref6$.isInverted,
|
|
272
|
-
diffType = _ref6$.diffType,
|
|
273
|
-
hideDeletedDiffs = _ref6$.hideDeletedDiffs,
|
|
274
|
-
showIndicators = _ref6$.showIndicators;
|
|
349
|
+
function (_ref5, _ref6) {
|
|
350
|
+
var _ref0;
|
|
275
351
|
var _ref7 = (0, _slicedToArray2.default)(_ref5, 1),
|
|
276
352
|
_ref7$ = _ref7[0],
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
353
|
+
pluginState = _ref7$.pluginState,
|
|
354
|
+
state = _ref7$.state,
|
|
355
|
+
colorScheme = _ref7$.colorScheme,
|
|
356
|
+
intl = _ref7$.intl,
|
|
357
|
+
activeIndexPos = _ref7$.activeIndexPos,
|
|
358
|
+
isInverted = _ref7$.isInverted,
|
|
359
|
+
diffType = _ref7$.diffType,
|
|
360
|
+
hideDeletedDiffs = _ref7$.hideDeletedDiffs,
|
|
361
|
+
showIndicators = _ref7$.showIndicators;
|
|
362
|
+
var _ref8 = (0, _slicedToArray2.default)(_ref6, 1),
|
|
363
|
+
_ref8$ = _ref8[0],
|
|
364
|
+
lastPluginState = _ref8$.pluginState,
|
|
365
|
+
lastState = _ref8$.state,
|
|
366
|
+
lastColorScheme = _ref8$.colorScheme,
|
|
367
|
+
lastIntl = _ref8$.intl,
|
|
368
|
+
lastActiveIndexPos = _ref8$.activeIndexPos,
|
|
369
|
+
lastIsInverted = _ref8$.isInverted,
|
|
370
|
+
lastDiffType = _ref8$.diffType,
|
|
371
|
+
lastHideDeletedDiffs = _ref8$.hideDeletedDiffs,
|
|
372
|
+
lastShowIndicators = _ref8$.showIndicators;
|
|
286
373
|
var originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
|
|
287
374
|
if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
288
|
-
var
|
|
289
|
-
return (
|
|
375
|
+
var _ref9;
|
|
376
|
+
return (_ref9 = colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isInverted === lastIsInverted && diffType === lastDiffType && (0, _isEqual.default)(activeIndexPos, lastActiveIndexPos) && originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && hideDeletedDiffs === lastHideDeletedDiffs && showIndicators === lastShowIndicators) !== null && _ref9 !== void 0 ? _ref9 : false;
|
|
290
377
|
}
|
|
291
|
-
return (
|
|
378
|
+
return (_ref0 = originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && (0, _isEqual.default)(activeIndexPos, lastActiveIndexPos) && hideDeletedDiffs === lastHideDeletedDiffs) !== null && _ref0 !== void 0 ? _ref0 : false;
|
|
292
379
|
});
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.diffBySteps = void 0;
|
|
7
|
+
exports.getStepChanges = 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
10
|
var _prosemirrorChangeset = require("prosemirror-changeset");
|
|
@@ -407,4 +407,127 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
|
|
|
407
407
|
});
|
|
408
408
|
}
|
|
409
409
|
return mergeOverlappingByNewDocRange(changes);
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* A fork of `diffBySteps` that returns changes grouped per step, rather than as a flat list.
|
|
414
|
+
*
|
|
415
|
+
* Why forked rather than refactoring `diffBySteps`:
|
|
416
|
+
* - `diffBySteps` returns a flat `Change[]` and is consumed by the existing decoration path.
|
|
417
|
+
* Changing its return shape would require threading per-step metadata through all callers,
|
|
418
|
+
* adding complexity to a stable code path.
|
|
419
|
+
* - The per-step grouping is only needed for the `platform_editor_diff_granular_extended` gate,
|
|
420
|
+
* where we need to know how many granular changes a single step produced in order to decide
|
|
421
|
+
* whether to suppress deleted decorations (threshold: > 3 granular changes per step).
|
|
422
|
+
* - Keeping the two functions separate means each has a clear, focused contract and neither
|
|
423
|
+
* accumulates the other's concerns. Shared logic (mapping helpers, `mergeOverlappingByNewDocRange`,
|
|
424
|
+
* `shouldCheckGranularDiff`, etc.) is already extracted and reused by both.
|
|
425
|
+
*/
|
|
426
|
+
var getStepChanges = exports.getStepChanges = function getStepChanges(originalDoc, steps) {
|
|
427
|
+
var result = [];
|
|
428
|
+
var currentDoc = originalDoc;
|
|
429
|
+
var successfulStepMaps = [];
|
|
430
|
+
var rangedSteps = [];
|
|
431
|
+
var _iterator4 = _createForOfIteratorHelper(steps),
|
|
432
|
+
_step4;
|
|
433
|
+
try {
|
|
434
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
435
|
+
var step = _step4.value;
|
|
436
|
+
var before = currentDoc;
|
|
437
|
+
var stepResult = step.apply(currentDoc);
|
|
438
|
+
if (stepResult.failed !== null || !stepResult.doc) {
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
var stepMap = step.getMap();
|
|
442
|
+
var rangeStep = step;
|
|
443
|
+
if (typeof rangeStep.from === 'number' && typeof rangeStep.to === 'number') {
|
|
444
|
+
rangedSteps.push({
|
|
445
|
+
before: before,
|
|
446
|
+
doc: stepResult.doc,
|
|
447
|
+
from: rangeStep.from,
|
|
448
|
+
to: rangeStep.to,
|
|
449
|
+
mapIndex: successfulStepMaps.length,
|
|
450
|
+
step: step,
|
|
451
|
+
stepMap: stepMap
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
successfulStepMaps.push(stepMap);
|
|
455
|
+
currentDoc = stepResult.doc;
|
|
456
|
+
}
|
|
457
|
+
} catch (err) {
|
|
458
|
+
_iterator4.e(err);
|
|
459
|
+
} finally {
|
|
460
|
+
_iterator4.f();
|
|
461
|
+
}
|
|
462
|
+
for (var _i2 = 0, _rangedSteps2 = rangedSteps; _i2 < _rangedSteps2.length; _i2++) {
|
|
463
|
+
var rangedStep = _rangedSteps2[_i2];
|
|
464
|
+
var originalToBeforeStep = createMapping(successfulStepMaps.slice(0, rangedStep.mapIndex));
|
|
465
|
+
var beforeStepToOriginal = originalToBeforeStep.invert();
|
|
466
|
+
var fromA = mapPosition(beforeStepToOriginal, rangedStep.from);
|
|
467
|
+
var toA = mapPosition(beforeStepToOriginal, rangedStep.to);
|
|
468
|
+
var fromAfterStep = rangedStep.stepMap.map(rangedStep.from, -1);
|
|
469
|
+
var toAfterStep = rangedStep.stepMap.map(rangedStep.to, 1);
|
|
470
|
+
var afterStepToFinal = createMapping(successfulStepMaps.slice(rangedStep.mapIndex + 1));
|
|
471
|
+
var fromB = mapPosition(afterStepToFinal, fromAfterStep);
|
|
472
|
+
var toB = mapPosition(afterStepToFinal, toAfterStep);
|
|
473
|
+
if (shouldCheckGranularDiff(rangedStep.step, rangedStep.before, rangedStep.from, rangedStep.to)) {
|
|
474
|
+
var granularStepChanges = _prosemirrorChangeset.ChangeSet.create(rangedStep.before).addSteps(rangedStep.doc, [rangedStep.stepMap], null);
|
|
475
|
+
var optimizedGranularStepChanges = (0, _optimizeChanges.optimizeChanges)((0, _prosemirrorChangeset.simplifyChanges)(granularStepChanges.changes, rangedStep.doc));
|
|
476
|
+
var stepChanges = [];
|
|
477
|
+
var _iterator5 = _createForOfIteratorHelper(optimizedGranularStepChanges),
|
|
478
|
+
_step5;
|
|
479
|
+
try {
|
|
480
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
481
|
+
var granularChange = _step5.value;
|
|
482
|
+
var expandedA = expandToWordBoundaries(rangedStep.before, granularChange.fromA, granularChange.toA);
|
|
483
|
+
var expandedB = expandToWordBoundaries(rangedStep.doc, granularChange.fromB, granularChange.toB);
|
|
484
|
+
var aLeftDelta = granularChange.fromA - expandedA.from;
|
|
485
|
+
var aRightDelta = expandedA.to - granularChange.toA;
|
|
486
|
+
var bLeftDelta = granularChange.fromB - expandedB.from;
|
|
487
|
+
var bRightDelta = expandedB.to - granularChange.toB;
|
|
488
|
+
var finalA = expandedA;
|
|
489
|
+
var finalB = expandedB;
|
|
490
|
+
if (aLeftDelta > bLeftDelta || aRightDelta > bRightDelta) {
|
|
491
|
+
var extraLeft = Math.max(0, aLeftDelta - bLeftDelta);
|
|
492
|
+
var extraRight = Math.max(0, aRightDelta - bRightDelta);
|
|
493
|
+
finalB = expandToWordBoundaries(rangedStep.doc, Math.max(expandedB.from - extraLeft, 0), expandedB.to + extraRight);
|
|
494
|
+
}
|
|
495
|
+
if (bLeftDelta > aLeftDelta || bRightDelta > aRightDelta) {
|
|
496
|
+
var _extraLeft2 = Math.max(0, bLeftDelta - aLeftDelta);
|
|
497
|
+
var _extraRight2 = Math.max(0, bRightDelta - aRightDelta);
|
|
498
|
+
finalA = expandToWordBoundaries(rangedStep.before, Math.max(expandedA.from - _extraLeft2, 0), expandedA.to + _extraRight2);
|
|
499
|
+
}
|
|
500
|
+
stepChanges.push({
|
|
501
|
+
fromA: mapPosition(beforeStepToOriginal, finalA.from),
|
|
502
|
+
toA: mapPosition(beforeStepToOriginal, finalA.to),
|
|
503
|
+
fromB: mapPosition(afterStepToFinal, finalB.from),
|
|
504
|
+
toB: mapPosition(afterStepToFinal, finalB.to),
|
|
505
|
+
deleted: createSpans(Math.max(0, finalA.to - finalA.from)),
|
|
506
|
+
inserted: createSpans(Math.max(0, finalB.to - finalB.from))
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
} catch (err) {
|
|
510
|
+
_iterator5.e(err);
|
|
511
|
+
} finally {
|
|
512
|
+
_iterator5.f();
|
|
513
|
+
}
|
|
514
|
+
result.push({
|
|
515
|
+
isGranular: true,
|
|
516
|
+
changes: mergeOverlappingByNewDocRange(stepChanges)
|
|
517
|
+
});
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
result.push({
|
|
521
|
+
isGranular: false,
|
|
522
|
+
changes: [{
|
|
523
|
+
fromA: fromA,
|
|
524
|
+
toA: toA,
|
|
525
|
+
fromB: fromB,
|
|
526
|
+
toB: toB,
|
|
527
|
+
deleted: createSpans(Math.max(0, toA - fromA)),
|
|
528
|
+
inserted: createSpans(Math.max(0, toB - fromB))
|
|
529
|
+
}]
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
return result;
|
|
410
533
|
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createGranularBlockReferenceWidget = void 0;
|
|
7
|
+
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
8
|
+
var _createAnchorDecorationWidgets = require("./createAnchorDecorationWidgets");
|
|
9
|
+
var _decorationKeys = require("./decorationKeys");
|
|
10
|
+
var _wrapBlockNodeView = require("./utils/wrapBlockNodeView");
|
|
11
|
+
/**
|
|
12
|
+
* Creates a single block widget that renders a reference text block content
|
|
13
|
+
* beneath a granular diff set, for reference when deleted content is hidden.
|
|
14
|
+
*
|
|
15
|
+
* Since granular diffing only applies to singular isTextBlock=true nodes, this
|
|
16
|
+
* widget always renders exactly one block node and does not need the slice/fragment
|
|
17
|
+
* complexity of createNodeChangedDecorationWidget.
|
|
18
|
+
*
|
|
19
|
+
* Resolves which doc and positions to render based on isInverted:
|
|
20
|
+
* - !isInverted: renders originalDoc at A-side positions (what was there before)
|
|
21
|
+
* - isInverted: renders newDoc at B-side positions (the current/new content)
|
|
22
|
+
*
|
|
23
|
+
* The widget is always inserted at the B-side block boundary in newDoc since
|
|
24
|
+
* ProseMirror decorations are always anchored against the live (new) document.
|
|
25
|
+
*/
|
|
26
|
+
var createGranularBlockReferenceWidget = exports.createGranularBlockReferenceWidget = function createGranularBlockReferenceWidget(_ref) {
|
|
27
|
+
var change = _ref.change,
|
|
28
|
+
originalDoc = _ref.originalDoc,
|
|
29
|
+
newDoc = _ref.newDoc,
|
|
30
|
+
isInverted = _ref.isInverted,
|
|
31
|
+
nodeViewSerializer = _ref.nodeViewSerializer,
|
|
32
|
+
colorScheme = _ref.colorScheme,
|
|
33
|
+
intl = _ref.intl,
|
|
34
|
+
activeIndexPos = _ref.activeIndexPos,
|
|
35
|
+
diffId = _ref.diffId,
|
|
36
|
+
_ref$showIndicators = _ref.showIndicators,
|
|
37
|
+
showIndicators = _ref$showIndicators === void 0 ? false : _ref$showIndicators;
|
|
38
|
+
// Determine which doc and positions to use for rendering the reference block.
|
|
39
|
+
var renderDoc = isInverted ? newDoc : originalDoc;
|
|
40
|
+
var renderTo = isInverted ? change.toB : change.toA;
|
|
41
|
+
|
|
42
|
+
// The insertion point is always in newDoc — ProseMirror decorates against the live document.
|
|
43
|
+
// Walk up from toB to find the enclosing text block boundary for widget placement.
|
|
44
|
+
var insertResolvedPos = newDoc.resolve(change.toB);
|
|
45
|
+
var blockEnd = change.toB;
|
|
46
|
+
for (var depth = insertResolvedPos.depth; depth >= 0; depth--) {
|
|
47
|
+
var node = insertResolvedPos.node(depth);
|
|
48
|
+
if (node.isTextblock) {
|
|
49
|
+
blockEnd = insertResolvedPos.start(depth) + node.nodeSize - 1;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Find the block node to render from the render doc at the render positions.
|
|
55
|
+
var renderResolvedPos = renderDoc.resolve(renderTo);
|
|
56
|
+
var renderBlockNode = null;
|
|
57
|
+
for (var _depth = renderResolvedPos.depth; _depth >= 0; _depth--) {
|
|
58
|
+
var _node = renderResolvedPos.node(_depth);
|
|
59
|
+
if (_node.isTextblock) {
|
|
60
|
+
renderBlockNode = _node;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!renderBlockNode) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
var isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* This will always be a block node as it's a textBlock-like node.
|
|
71
|
+
* We use div instead of span so we can add margins.
|
|
72
|
+
*/
|
|
73
|
+
var dom = document.createElement('div');
|
|
74
|
+
dom.setAttribute('data-testid', 'show-diff-granular-block-reference');
|
|
75
|
+
dom.style.setProperty('margin-top', "var(--ds-space-200, 16px)");
|
|
76
|
+
var nodeView = nodeViewSerializer.tryCreateNodeView(renderBlockNode);
|
|
77
|
+
if (nodeView) {
|
|
78
|
+
(0, _wrapBlockNodeView.wrapBlockNodeView)({
|
|
79
|
+
dom: dom,
|
|
80
|
+
nodeView: nodeView,
|
|
81
|
+
targetNode: renderBlockNode,
|
|
82
|
+
colorScheme: colorScheme,
|
|
83
|
+
intl: intl,
|
|
84
|
+
isActive: !!isActive,
|
|
85
|
+
isInserted: false
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
var serialized = nodeViewSerializer.serializeNode(renderBlockNode);
|
|
89
|
+
if (serialized && serialized instanceof HTMLElement) {
|
|
90
|
+
(0, _wrapBlockNodeView.injectInnerWrapper)({
|
|
91
|
+
node: serialized,
|
|
92
|
+
colorScheme: colorScheme,
|
|
93
|
+
isActive: !!isActive,
|
|
94
|
+
isInserted: false
|
|
95
|
+
});
|
|
96
|
+
dom.append(serialized);
|
|
97
|
+
} else if (serialized) {
|
|
98
|
+
dom.append(serialized);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (dom.childNodes.length === 0) {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
var decorations = [];
|
|
105
|
+
if (showIndicators) {
|
|
106
|
+
var leftAnchor = (0, _createAnchorDecorationWidgets.createLeftAnchorWidget)({
|
|
107
|
+
doc: newDoc,
|
|
108
|
+
from: blockEnd,
|
|
109
|
+
diffId: diffId
|
|
110
|
+
});
|
|
111
|
+
dom.style.setProperty('anchor-name', "--".concat((0, _decorationKeys.buildAnchorDecorationKey)({
|
|
112
|
+
diffId: diffId
|
|
113
|
+
})));
|
|
114
|
+
if (leftAnchor) {
|
|
115
|
+
decorations.push(leftAnchor);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
decorations.push(_view.Decoration.widget(blockEnd, dom, (0, _decorationKeys.buildDiffDecorationSpec)({
|
|
119
|
+
decorationType: 'widget',
|
|
120
|
+
diffId: diffId,
|
|
121
|
+
// We want it to be as close to the granular diff as possible
|
|
122
|
+
side: -999
|
|
123
|
+
})));
|
|
124
|
+
return decorations;
|
|
125
|
+
};
|
|
@@ -6,12 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.createNodeChangedDecorationWidget = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
-
var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
|
|
11
9
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
12
10
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
13
|
-
var _standard = require("./colorSchemes/standard");
|
|
14
|
-
var _traditional = require("./colorSchemes/traditional");
|
|
15
11
|
var _createAnchorDecorationWidgets = require("./createAnchorDecorationWidgets");
|
|
16
12
|
var _createChangedRowDecorationWidgets = require("./createChangedRowDecorationWidgets");
|
|
17
13
|
var _decorationKeys = require("./decorationKeys");
|
|
@@ -19,105 +15,23 @@ var _findSafeInsertPos = require("./utils/findSafeInsertPos");
|
|
|
19
15
|
var _wrapBlockNodeView = require("./utils/wrapBlockNodeView");
|
|
20
16
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
21
17
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
22
|
-
var getDeletedContentStyleUnbounded = function getDeletedContentStyleUnbounded(colorScheme) {
|
|
23
|
-
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
24
|
-
if (colorScheme === 'traditional' && isActive) {
|
|
25
|
-
return _traditional.deletedTraditionalContentStyleUnboundedActive;
|
|
26
|
-
}
|
|
27
|
-
return colorScheme === 'traditional' ? _traditional.deletedTraditionalContentStyleUnbounded : _standard.deletedContentStyleUnbounded;
|
|
28
|
-
};
|
|
29
|
-
var getInsertedContentStyle = function getInsertedContentStyle(colorScheme) {
|
|
30
|
-
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
31
|
-
if (colorScheme === 'traditional') {
|
|
32
|
-
if (isActive) {
|
|
33
|
-
return _traditional.traditionalInsertStyleActive;
|
|
34
|
-
}
|
|
35
|
-
return _traditional.traditionalInsertStyle;
|
|
36
|
-
}
|
|
37
|
-
if (isActive) {
|
|
38
|
-
return (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? _standard.editingStyleActiveExtended : _standard.editingStyleActive;
|
|
39
|
-
}
|
|
40
|
-
return (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? _standard.editingStyleExtended : _standard.editingStyle;
|
|
41
|
-
};
|
|
42
|
-
var getDeletedContentStyle = function getDeletedContentStyle(colorScheme) {
|
|
43
|
-
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
44
|
-
if (colorScheme === 'traditional') {
|
|
45
|
-
return (0, _traditional.getDeletedTraditionalInlineStyle)(isActive);
|
|
46
|
-
}
|
|
47
|
-
// Merge into existing styles when cleaning up
|
|
48
|
-
if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
49
|
-
if (isActive) {
|
|
50
|
-
return _standard.deletedContentStyleActive + _standard.deletedInlineContentStyleExtended;
|
|
51
|
-
}
|
|
52
|
-
return _standard.deletedContentStyleNew + _standard.deletedInlineContentStyleExtended;
|
|
53
|
-
}
|
|
54
|
-
if (isActive) {
|
|
55
|
-
return _standard.deletedContentStyleActive;
|
|
56
|
-
}
|
|
57
|
-
return (0, _expValEquals.expValEquals)('platform_editor_enghealth_a11y_jan_fixes', 'isEnabled', true) ? _standard.deletedContentStyleNew : _standard.deletedContentStyle;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* CSS backgrounds don't work when applied to a wrapper around a paragraph, so
|
|
62
|
-
* the wrapper needs to be injected inside the node around the child content
|
|
63
|
-
*/
|
|
64
|
-
var injectInnerWrapper = function injectInnerWrapper(_ref) {
|
|
65
|
-
var node = _ref.node,
|
|
66
|
-
colorScheme = _ref.colorScheme,
|
|
67
|
-
isActive = _ref.isActive,
|
|
68
|
-
isInserted = _ref.isInserted;
|
|
69
|
-
var wrapper = document.createElement('span');
|
|
70
|
-
wrapper.setAttribute('style', isInserted ? getInsertedContentStyle(colorScheme, isActive) : getDeletedContentStyle(colorScheme, isActive));
|
|
71
|
-
(0, _toConsumableArray2.default)(node.childNodes).forEach(function (child) {
|
|
72
|
-
var removedChild = node.removeChild(child);
|
|
73
|
-
wrapper.append(removedChild);
|
|
74
|
-
});
|
|
75
|
-
node.appendChild(wrapper);
|
|
76
|
-
return node;
|
|
77
|
-
};
|
|
78
|
-
var createContentWrapper = function createContentWrapper(colorScheme) {
|
|
79
|
-
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
80
|
-
var isInserted = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
81
|
-
var wrapper = document.createElement('span');
|
|
82
|
-
var baseStyle = (0, _lazyNodeView.convertToInlineCss)({
|
|
83
|
-
position: 'relative',
|
|
84
|
-
width: 'fit-content'
|
|
85
|
-
});
|
|
86
|
-
if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
87
|
-
if (isInserted) {
|
|
88
|
-
wrapper.setAttribute('style', "".concat(baseStyle).concat(getInsertedContentStyle(colorScheme, isActive)));
|
|
89
|
-
} else {
|
|
90
|
-
wrapper.setAttribute('style', "".concat(baseStyle).concat(getDeletedContentStyle(colorScheme, isActive)));
|
|
91
|
-
var strikethrough = document.createElement('span');
|
|
92
|
-
strikethrough.setAttribute('style', getDeletedContentStyleUnbounded(colorScheme, isActive));
|
|
93
|
-
wrapper.append(strikethrough);
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
wrapper.setAttribute('style', "".concat(baseStyle).concat(getDeletedContentStyle(colorScheme, isActive)));
|
|
97
|
-
var _strikethrough = document.createElement('span');
|
|
98
|
-
_strikethrough.setAttribute('style', getDeletedContentStyleUnbounded(colorScheme, isActive));
|
|
99
|
-
wrapper.append(_strikethrough);
|
|
100
|
-
}
|
|
101
|
-
return wrapper;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
18
|
/**
|
|
105
19
|
* This function is used to create a decoration widget to show content
|
|
106
20
|
* that is not in the current document.
|
|
107
21
|
*/
|
|
108
|
-
var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidget = function createNodeChangedDecorationWidget(
|
|
22
|
+
var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidget = function createNodeChangedDecorationWidget(_ref) {
|
|
109
23
|
var _slice$content, _slice$content2, _slice$content3, _slice$content$firstC;
|
|
110
|
-
var change =
|
|
111
|
-
doc =
|
|
112
|
-
nodeViewSerializer =
|
|
113
|
-
colorScheme =
|
|
114
|
-
newDoc =
|
|
115
|
-
intl =
|
|
116
|
-
activeIndexPos =
|
|
117
|
-
|
|
118
|
-
isInserted =
|
|
119
|
-
|
|
120
|
-
showIndicators =
|
|
24
|
+
var change = _ref.change,
|
|
25
|
+
doc = _ref.doc,
|
|
26
|
+
nodeViewSerializer = _ref.nodeViewSerializer,
|
|
27
|
+
colorScheme = _ref.colorScheme,
|
|
28
|
+
newDoc = _ref.newDoc,
|
|
29
|
+
intl = _ref.intl,
|
|
30
|
+
activeIndexPos = _ref.activeIndexPos,
|
|
31
|
+
_ref$isInserted = _ref.isInserted,
|
|
32
|
+
isInserted = _ref$isInserted === void 0 ? false : _ref$isInserted,
|
|
33
|
+
_ref$showIndicators = _ref.showIndicators,
|
|
34
|
+
showIndicators = _ref$showIndicators === void 0 ? false : _ref$showIndicators;
|
|
121
35
|
var slice = doc.slice(change.fromA, change.toA);
|
|
122
36
|
var shouldSkipDeletedEmptyParagraphDecoration = !isInserted && (slice === null || slice === void 0 || (_slice$content = slice.content) === null || _slice$content === void 0 ? void 0 : _slice$content.childCount) === 1 && (slice === null || slice === void 0 || (_slice$content2 = slice.content) === null || _slice$content2 === void 0 || (_slice$content2 = _slice$content2.firstChild) === null || _slice$content2 === void 0 ? void 0 : _slice$content2.type.name) === 'paragraph' && (slice === null || slice === void 0 || (_slice$content3 = slice.content) === null || _slice$content3 === void 0 || (_slice$content3 = _slice$content3.firstChild) === null || _slice$content3 === void 0 ? void 0 : _slice$content3.content.size) === 0;
|
|
123
37
|
// Widget decoration used for deletions as the content is not in the document
|
|
@@ -171,14 +85,14 @@ var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidge
|
|
|
171
85
|
if (childNodeView) {
|
|
172
86
|
var lineBreak = document.createElement('br');
|
|
173
87
|
dom.append(lineBreak);
|
|
174
|
-
var wrapper = createContentWrapper(colorScheme, isActive, isInserted);
|
|
88
|
+
var wrapper = (0, _wrapBlockNodeView.createContentWrapper)(colorScheme, isActive, isInserted);
|
|
175
89
|
wrapper.append(childNodeView);
|
|
176
90
|
dom.append(wrapper);
|
|
177
91
|
} else {
|
|
178
92
|
// Fallback to serializing the individual child node
|
|
179
93
|
var serializedChild = serializer.serializeNode(childNode);
|
|
180
94
|
if (serializedChild) {
|
|
181
|
-
var _wrapper = createContentWrapper(colorScheme, isActive, isInserted);
|
|
95
|
+
var _wrapper = (0, _wrapBlockNodeView.createContentWrapper)(colorScheme, isActive, isInserted);
|
|
182
96
|
_wrapper.append(serializedChild);
|
|
183
97
|
dom.append(_wrapper);
|
|
184
98
|
}
|
|
@@ -223,7 +137,7 @@ var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidge
|
|
|
223
137
|
var nodeView = serializer.tryCreateNodeView(node);
|
|
224
138
|
if (nodeView) {
|
|
225
139
|
if (node.isInline) {
|
|
226
|
-
var wrapper = createContentWrapper(colorScheme, isActive, isInserted);
|
|
140
|
+
var wrapper = (0, _wrapBlockNodeView.createContentWrapper)(colorScheme, isActive, isInserted);
|
|
227
141
|
wrapper.append(nodeView);
|
|
228
142
|
dom.append(wrapper);
|
|
229
143
|
} else {
|
|
@@ -245,7 +159,7 @@ var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidge
|
|
|
245
159
|
var fallbackNode = fallbackSerialization();
|
|
246
160
|
if (fallbackNode) {
|
|
247
161
|
if (fallbackNode instanceof HTMLElement) {
|
|
248
|
-
var injectedNode = injectInnerWrapper({
|
|
162
|
+
var injectedNode = (0, _wrapBlockNodeView.injectInnerWrapper)({
|
|
249
163
|
node: fallbackNode,
|
|
250
164
|
colorScheme: colorScheme,
|
|
251
165
|
isActive: isActive,
|
|
@@ -253,7 +167,7 @@ var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidge
|
|
|
253
167
|
});
|
|
254
168
|
dom.append(injectedNode);
|
|
255
169
|
} else {
|
|
256
|
-
var _wrapper2 = createContentWrapper(colorScheme, isActive, isInserted);
|
|
170
|
+
var _wrapper2 = (0, _wrapBlockNodeView.createContentWrapper)(colorScheme, isActive, isInserted);
|
|
257
171
|
_wrapper2.append(fallbackNode);
|
|
258
172
|
dom.append(_wrapper2);
|
|
259
173
|
}
|