@atlaskit/editor-plugin-show-diff 10.1.10 → 10.1.12

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.
Files changed (27) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +118 -31
  3. package/dist/cjs/pm-plugins/calculateDiff/diffBySteps.js +124 -1
  4. package/dist/cjs/pm-plugins/decorations/colorSchemes/standard.js +6 -1
  5. package/dist/cjs/pm-plugins/decorations/createBlockChangedDecoration.js +17 -0
  6. package/dist/cjs/pm-plugins/decorations/createGranularBlockReferenceWidget.js +125 -0
  7. package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +50 -105
  8. package/dist/cjs/pm-plugins/decorations/utils/wrapBlockNodeView.js +79 -1
  9. package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +91 -7
  10. package/dist/es2019/pm-plugins/calculateDiff/diffBySteps.js +104 -0
  11. package/dist/es2019/pm-plugins/decorations/colorSchemes/standard.js +5 -0
  12. package/dist/es2019/pm-plugins/decorations/createBlockChangedDecoration.js +18 -1
  13. package/dist/es2019/pm-plugins/decorations/createGranularBlockReferenceWidget.js +120 -0
  14. package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +41 -89
  15. package/dist/es2019/pm-plugins/decorations/utils/wrapBlockNodeView.js +74 -2
  16. package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +119 -32
  17. package/dist/esm/pm-plugins/calculateDiff/diffBySteps.js +123 -0
  18. package/dist/esm/pm-plugins/decorations/colorSchemes/standard.js +5 -0
  19. package/dist/esm/pm-plugins/decorations/createBlockChangedDecoration.js +18 -1
  20. package/dist/esm/pm-plugins/decorations/createGranularBlockReferenceWidget.js +120 -0
  21. package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +46 -100
  22. package/dist/esm/pm-plugins/decorations/utils/wrapBlockNodeView.js +79 -2
  23. package/dist/types/pm-plugins/calculateDiff/diffBySteps.d.ts +20 -0
  24. package/dist/types/pm-plugins/decorations/colorSchemes/standard.d.ts +1 -0
  25. package/dist/types/pm-plugins/decorations/createGranularBlockReferenceWidget.d.ts +36 -0
  26. package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +15 -0
  27. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/editor-plugin-show-diff
2
2
 
3
+ ## 10.1.12
4
+
5
+ ### Patch Changes
6
+
7
+ - [`3d9bf2e6f248a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3d9bf2e6f248a) -
8
+ Fix nested image in panel shifting left when showing suggestion diff
9
+ - Updated dependencies
10
+
11
+ ## 10.1.11
12
+
13
+ ### Patch Changes
14
+
15
+ - [`0096393101f67`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0096393101f67) -
16
+ Render inverted granular step diffs as a hybrid (based on threshold): granular changed inline plus
17
+ a 'reference' block crossed out underneath
18
+ - Updated dependencies
19
+
3
20
  ## 10.1.10
4
21
 
5
22
  ### 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
- changes.forEach(function (change) {
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
- var shouldHideDeleted = (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? isInverted && hideDeletedDiffs : false;
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 (_ref4, _ref5) {
263
- var _ref9;
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
- lastPluginState = _ref7$.pluginState,
278
- lastState = _ref7$.state,
279
- lastColorScheme = _ref7$.colorScheme,
280
- lastIntl = _ref7$.intl,
281
- lastActiveIndexPos = _ref7$.activeIndexPos,
282
- lastIsInverted = _ref7$.isInverted,
283
- lastDiffType = _ref7$.diffType,
284
- lastHideDeletedDiffs = _ref7$.hideDeletedDiffs,
285
- lastShowIndicators = _ref7$.showIndicators;
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 _ref8;
289
- return (_ref8 = 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 && _ref8 !== void 0 ? _ref8 : false;
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 (_ref9 = 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 && _ref9 !== void 0 ? _ref9 : false;
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
  };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.standardDecorationMarkerVariable = exports.editingStyleRuleNode = exports.editingStyleQuoteNode = exports.editingStyleNode = exports.editingStyleExtended = exports.editingStyleCardBlockNode = exports.editingStyleActiveExtended = exports.editingStyleActive = exports.editingStyle = exports.editingContentStyleInBlockExtended = exports.editingContentStyleInBlock = exports.deletedStyleQuoteNodeWithLozengeActive = exports.deletedStyleQuoteNodeWithLozenge = exports.deletedStyleQuoteNode = exports.deletedRowStyle = exports.deletedInlineContentStyleExtended = exports.deletedContentStyleUnbounded = exports.deletedContentStyleNew = exports.deletedContentStyleActive = exports.deletedContentStyle = exports.deletedCellOverlayStyle = exports.deletedBlockOutlineRoundedActive = exports.deletedBlockOutlineRounded = exports.deletedBlockOutlineActive = exports.deletedBlockOutline = exports.addedCellOverlayStyle = void 0;
6
+ exports.standardDecorationMarkerVariable = exports.editingStyleRuleNode = exports.editingStyleQuoteNode = exports.editingStyleNode = exports.editingStyleExtended = exports.editingStyleCardBlockNode = exports.editingStyleActiveExtended = exports.editingStyleActive = exports.editingStyle = exports.editingContentStyleInBlockExtended = exports.editingContentStyleInBlock = exports.deletedStyleQuoteNodeWithLozengeActive = exports.deletedStyleQuoteNodeWithLozenge = exports.deletedStyleQuoteNode = exports.deletedRowStyle = exports.deletedInlineContentStyleExtended = exports.deletedDecorationMarkerVariable = exports.deletedContentStyleUnbounded = exports.deletedContentStyleNew = exports.deletedContentStyleActive = exports.deletedContentStyle = exports.deletedCellOverlayStyle = exports.deletedBlockOutlineRoundedActive = exports.deletedBlockOutlineRounded = exports.deletedBlockOutlineActive = exports.deletedBlockOutline = exports.addedCellOverlayStyle = void 0;
7
7
  var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
8
8
  // delete on platform_editor_diff_plugin_extended cleanup
9
9
  var editingStyle = exports.editingStyle = (0, _lazyNodeView.convertToInlineCss)({
@@ -142,6 +142,11 @@ var standardDecorationMarkerVariable = exports.standardDecorationMarkerVariable
142
142
  '--diff-decoration-marker-color': "var(--ds-border-accent-purple, #AF59E1)",
143
143
  '--diff-decoration-marker-ring-width': '1px'
144
144
  });
145
+ var deletedDecorationMarkerVariable = exports.deletedDecorationMarkerVariable = (0, _lazyNodeView.convertToInlineCss)({
146
+ '--diff-decoration-marker-color': "var(--ds-border-accent-gray, #7D818A)",
147
+ '--diff-decoration-marker-ring-width': '1px',
148
+ opacity: 0.8
149
+ });
145
150
  var addedCellOverlayStyle = exports.addedCellOverlayStyle = (0, _lazyNodeView.convertToInlineCss)({
146
151
  position: 'absolute',
147
152
  top: 0,
@@ -37,6 +37,14 @@ var getBlockNodeStyle = function getBlockNodeStyle(_ref) {
37
37
  // Layout nodes do not need special styling
38
38
  return undefined;
39
39
  }
40
+ // Media nodes inside mediaSingle should not get position:relative
41
+ // as it shifts the image outside its parent container (e.g. panel)
42
+ if (nodeName === 'media') {
43
+ if (!isInserted && (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
44
+ return isTraditional ? (0, _traditional.getDeletedTraditionalInlineStyle)(false) : _standard.deletedDecorationMarkerVariable;
45
+ }
46
+ return isTraditional ? isActive ? _traditional.traditionalStyleNodeActive : _traditional.traditionalStyleNodeNew : _standard.editingStyleNode;
47
+ }
40
48
  if (['tableCell', 'tableHeader'].includes(nodeName)) {
41
49
  if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
42
50
  // This is used for positioning the cell overlay widget decorations
@@ -47,11 +55,20 @@ var getBlockNodeStyle = function getBlockNodeStyle(_ref) {
47
55
  // When gate is off, it should return undefined as above
48
56
  return undefined;
49
57
  }
58
+ if (nodeName === 'panel') {
59
+ if (!isInserted && (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
60
+ return isTraditional ? (0, _traditional.getDeletedTraditionalInlineStyle)(false) : _standard.deletedDecorationMarkerVariable;
61
+ }
62
+ return isTraditional ? isActive ? _traditional.traditionalStyleNodeActive : _traditional.traditionalStyleNodeNew : _standard.editingStyleNode;
63
+ }
50
64
  if (['extension', 'embedCard', 'listItem'].includes(nodeName)) {
51
65
  if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
52
66
  if (isInserted) {
53
67
  return isTraditional && isActive ? _traditional.traditionalDecorationMarkerVariableActive : isTraditional ? _traditional.traditionalDecorationMarkerVariableNew : _standard.standardDecorationMarkerVariable;
54
68
  } else {
69
+ if (nodeName === 'listItem') {
70
+ return isTraditional && isActive ? _traditional.traditionalDeletedDecorationMarkerVariableActive : isTraditional ? _traditional.traditionalDeletedDecorationMarkerVariableNew : _standard.deletedDecorationMarkerVariable;
71
+ }
55
72
  return isTraditional && isActive ? _traditional.traditionalDeletedDecorationMarkerVariableActive : isTraditional ? _traditional.traditionalDeletedDecorationMarkerVariableNew : _standard.deletedContentStyleNew;
56
73
  }
57
74
  }
@@ -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
+ };