@atlaskit/editor-plugin-show-diff 17.0.1 → 17.1.0

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 (75) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/cjs/entry-points/show-diff-plugin-type.js +12 -1
  3. package/dist/cjs/pm-plugins/NodeViewSerializer.js +1 -1
  4. package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +128 -51
  5. package/dist/cjs/pm-plugins/calculateDiff/groupDeletedColumnChanges.js +265 -0
  6. package/dist/cjs/pm-plugins/decorations/colorSchemes/attributions.js +14 -3
  7. package/dist/cjs/pm-plugins/decorations/createBlockChangedDecoration.js +1 -1
  8. package/dist/cjs/pm-plugins/decorations/createChangedRowDecorationWidgets.js +100 -34
  9. package/dist/cjs/pm-plugins/decorations/createContributorTagWidget.js +18 -13
  10. package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +82 -20
  11. package/dist/cjs/pm-plugins/decorations/utils/createDeletedLineBreakWidget.js +106 -0
  12. package/dist/cjs/pm-plugins/decorations/utils/tableDiffMode.js +36 -0
  13. package/dist/cjs/pm-plugins/decorations/utils/wrapBlockNodeView.js +19 -8
  14. package/dist/cjs/pm-plugins/resolveDiffContributors.js +4 -3
  15. package/dist/cjs/pm-plugins/utils/emptyTextBlocks.js +66 -0
  16. package/dist/cjs/showDiffPluginType.js +87 -1
  17. package/dist/cjs/ui/ContributorTag/contributorAvatarRenderer.js +22 -14
  18. package/dist/cjs/ui/ContributorTag/contributorTagIcons.js +4 -0
  19. package/dist/es2019/entry-points/calculate-diff.js +1 -0
  20. package/dist/es2019/entry-points/show-diff-plugin-type.js +3 -0
  21. package/dist/es2019/entry-points/show-diff-plugin.js +1 -0
  22. package/dist/es2019/pm-plugins/NodeViewSerializer.js +1 -1
  23. package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +63 -3
  24. package/dist/es2019/pm-plugins/calculateDiff/groupDeletedColumnChanges.js +210 -0
  25. package/dist/es2019/pm-plugins/decorations/colorSchemes/attributions.js +12 -3
  26. package/dist/es2019/pm-plugins/decorations/colorSchemes/factory.js +0 -1
  27. package/dist/es2019/pm-plugins/decorations/createBlockChangedDecoration.js +1 -1
  28. package/dist/es2019/pm-plugins/decorations/createChangedRowDecorationWidgets.js +79 -13
  29. package/dist/es2019/pm-plugins/decorations/createContributorTagWidget.js +8 -2
  30. package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +85 -15
  31. package/dist/es2019/pm-plugins/decorations/utils/createDeletedLineBreakWidget.js +100 -0
  32. package/dist/es2019/pm-plugins/decorations/utils/tableDiffMode.js +27 -0
  33. package/dist/es2019/pm-plugins/decorations/utils/wrapBlockNodeView.js +17 -7
  34. package/dist/es2019/pm-plugins/resolveDiffContributors.js +3 -1
  35. package/dist/es2019/pm-plugins/scrollToDiff.js +1 -0
  36. package/dist/es2019/pm-plugins/utils/emptyTextBlocks.js +58 -0
  37. package/dist/es2019/showDiffPluginType.js +85 -1
  38. package/dist/es2019/ui/ContributorTag/contributorAvatarRenderer.js +22 -14
  39. package/dist/es2019/ui/ContributorTag/contributorTagIcons.js +4 -0
  40. package/dist/esm/entry-points/calculate-diff.js +1 -0
  41. package/dist/esm/entry-points/show-diff-plugin-type.js +3 -0
  42. package/dist/esm/entry-points/show-diff-plugin.js +1 -0
  43. package/dist/esm/pm-plugins/NodeViewSerializer.js +1 -1
  44. package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +129 -52
  45. package/dist/esm/pm-plugins/calculateDiff/groupDeletedColumnChanges.js +258 -0
  46. package/dist/esm/pm-plugins/decorations/colorSchemes/attributions.js +14 -3
  47. package/dist/esm/pm-plugins/decorations/colorSchemes/factory.js +0 -1
  48. package/dist/esm/pm-plugins/decorations/createBlockChangedDecoration.js +1 -1
  49. package/dist/esm/pm-plugins/decorations/createChangedRowDecorationWidgets.js +100 -34
  50. package/dist/esm/pm-plugins/decorations/createContributorTagWidget.js +18 -13
  51. package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +84 -22
  52. package/dist/esm/pm-plugins/decorations/utils/createDeletedLineBreakWidget.js +100 -0
  53. package/dist/esm/pm-plugins/decorations/utils/tableDiffMode.js +30 -0
  54. package/dist/esm/pm-plugins/decorations/utils/wrapBlockNodeView.js +18 -7
  55. package/dist/esm/pm-plugins/resolveDiffContributors.js +4 -3
  56. package/dist/esm/pm-plugins/scrollToDiff.js +1 -0
  57. package/dist/esm/pm-plugins/utils/emptyTextBlocks.js +60 -0
  58. package/dist/esm/showDiffPluginType.js +85 -1
  59. package/dist/esm/ui/ContributorTag/contributorAvatarRenderer.js +22 -14
  60. package/dist/esm/ui/ContributorTag/contributorTagIcons.js +4 -0
  61. package/dist/types/entry-points/show-diff-plugin-type.d.ts +2 -1
  62. package/dist/types/pm-plugins/calculateDiff/groupDeletedColumnChanges.d.ts +9 -0
  63. package/dist/types/pm-plugins/decorations/colorSchemes/attributions.d.ts +2 -2
  64. package/dist/types/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +3 -1
  65. package/dist/types/pm-plugins/decorations/createContributorTagWidget.d.ts +5 -1
  66. package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +3 -2
  67. package/dist/types/pm-plugins/decorations/utils/createDeletedLineBreakWidget.d.ts +50 -0
  68. package/dist/types/pm-plugins/decorations/utils/getAttrChangeRanges.d.ts +1 -1
  69. package/dist/types/pm-plugins/decorations/utils/getMarkChangeRanges.d.ts +1 -1
  70. package/dist/types/pm-plugins/decorations/utils/tableDiffMode.d.ts +26 -0
  71. package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +4 -0
  72. package/dist/types/pm-plugins/utils/emptyTextBlocks.d.ts +16 -0
  73. package/dist/types/showDiffPluginType.d.ts +6 -1
  74. package/dist/types/ui/ContributorTag/contributorTagIcons.d.ts +1 -1
  75. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @atlaskit/editor-plugin-show-diff
2
2
 
3
+ ## 17.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`1351b0fb49e7d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1351b0fb49e7d) -
8
+ Support branded Claude and ChatGPT contributor tags, use the ChatGPT Presence artwork, and assign
9
+ Claude and ChatGPT their fixed orange and gray diff colours.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
15
+ ## 17.0.2
16
+
17
+ ### Patch Changes
18
+
19
+ - [`df446e0eda630`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/df446e0eda630) -
20
+ The extended diff view now compares whole tables after a column deletion. Reliably tracked deleted
21
+ columns use strikethrough text and a Removed lozenge, with contributor tags aligned directly above
22
+ the table. Deleted table rows also carry a Removed lozenge in their top-right corner.
23
+ - [`885418b21ca4d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/885418b21ca4d) -
24
+ Show a struck-through return glyph (⤶) where a removed blank line was — an empty paragraph or an
25
+ empty heading — instead of rendering nothing. One glyph per removed line, including runs of
26
+ adjacent ones. Covers both diff directions: the deleted side of a forward diff, and the inserted
27
+ side of an inverted diff (AI suggested edits). Behind `platform_editor_ai_show_diff_patch_2`.
28
+ - Updated dependencies
29
+
3
30
  ## 17.0.1
4
31
 
5
32
  ### Patch Changes
@@ -1 +1,12 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "DIFF_AGENT_BRANDS", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _showDiffPluginType.DIFF_AGENT_BRANDS;
10
+ }
11
+ });
12
+ var _showDiffPluginType = require("../showDiffPluginType");
@@ -8,8 +8,8 @@ exports.NodeViewSerializer = void 0;
8
8
  exports.isEditorViewWithNodeViews = isEditorViewWithNodeViews;
9
9
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
10
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
12
11
  var _model = require("@atlaskit/editor-prosemirror/model");
12
+ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
13
13
  /**
14
14
  * Utilities for working with ProseMirror node views and DOM serialization within the
15
15
  * Show Diff editor plugin.
@@ -15,22 +15,27 @@ var _areDocsEqualByBlockStructureAndText = require("@atlaskit/editor-common/util
15
15
  var _document = require("@atlaskit/editor-common/utils/document");
16
16
  var _transform = require("@atlaskit/editor-prosemirror/transform");
17
17
  var _view = require("@atlaskit/editor-prosemirror/view");
18
+ var _tableMap = require("@atlaskit/editor-tables/table-map");
18
19
  var _unsafeExpValNoExposure = require("@atlaskit/platform-feature-experiments/unsafe-exp-val-no-exposure");
19
20
  var _fg = require("@atlaskit/platform-feature-flags/fg");
20
21
  var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
22
+ var _attributions = require("../decorations/colorSchemes/attributions");
21
23
  var _createAnchorDecorationWidgets = require("../decorations/createAnchorDecorationWidgets");
22
24
  var _createBlockChangedDecoration = require("../decorations/createBlockChangedDecoration");
23
25
  var _createInlineChangedDecoration = require("../decorations/createInlineChangedDecoration");
24
26
  var _createNodeChangedDecorationWidget = require("../decorations/createNodeChangedDecorationWidget");
25
- var _attributions = require("../decorations/colorSchemes/attributions");
26
27
  var _decorationKeys = require("../decorations/decorationKeys");
27
28
  var _extractContributorTags = require("../decorations/extractContributorTags");
29
+ var _createDeletedLineBreakWidget = require("../decorations/utils/createDeletedLineBreakWidget");
28
30
  var _getAttrChangeRanges = require("../decorations/utils/getAttrChangeRanges");
29
31
  var _getMarkChangeRanges = require("../decorations/utils/getMarkChangeRanges");
32
+ var _wrapBlockNodeView = require("../decorations/utils/wrapBlockNodeView");
30
33
  var _getScrollableDecorations = require("../getScrollableDecorations");
31
34
  var _isExtendedEnabled = require("../isExtendedEnabled");
35
+ var _emptyTextBlocks = require("../utils/emptyTextBlocks");
32
36
  var _diffBySteps = require("./diffBySteps");
33
37
  var _groupChangesByBlock = require("./groupChangesByBlock");
38
+ var _groupDeletedColumnChanges = require("./groupDeletedColumnChanges");
34
39
  var _isMarkOnlyChange = require("./isMarkOnlyChange");
35
40
  var _isOpenTokenOnlyChange = require("./isOpenTokenOnlyChange");
36
41
  var _optimizeChanges = require("./optimizeChanges");
@@ -508,7 +513,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
508
513
 
509
514
  // Still colours-only: a tags-only diff keeps the plain colour scheme.
510
515
  if (attributionColoringEnabled) {
511
- attributionColors = (0, _attributions.createAttributionColorMap)(simplifiedStepAttributions);
516
+ attributionColors = (0, _attributions.createAttributionColorMap)(simplifiedStepAttributions, contributors);
512
517
  }
513
518
  } else {
514
519
  var _changeset = _prosemirrorChangeset.ChangeSet.create(originalDoc, undefined, tokenEncoder).addSteps(steppedDoc, stepMaps, tr.doc);
@@ -534,10 +539,38 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
534
539
 
535
540
  // Our default operations are insertions, so it should match the opposite of isInverted.
536
541
  var isInserted = !isInverted;
542
+ if ((0, _isExtendedEnabled.isExtendedEnabled)(diffType)) {
543
+ changes = (0, _groupDeletedColumnChanges.groupDeletedColumnChanges)(changes, originalDoc, tr.doc, new _transform.Mapping(stepMaps), isInverted);
544
+ }
545
+ // A whole-table change owns every mark and attribute range inside its bounds, so those ranges
546
+ // do not also get their own decoration.
547
+ var tableChanges = changes.filter(function (change) {
548
+ return change.deletedColumns !== undefined;
549
+ });
550
+ var isHandledByTable = function isHandledByTable(from, to) {
551
+ return tableChanges.some(function (change) {
552
+ return from >= change.fromB && to <= change.toB;
553
+ });
554
+ };
537
555
  var createDecorationsForChange = function createDecorationsForChange(change) {
538
556
  var changeColorScheme = attributionColors ? (0, _attributions.getColorSchemeForChange)(change, attributedChanges, attributionColors, colorScheme) : colorScheme;
539
557
  var attributionKey = showContributorTags ? (0, _attributions.getAttributionKeyForChange)(change, attributedChanges) : undefined;
540
558
  var isActive = isRangeActive(activeIndexPos, change.fromB, change.toB);
559
+ var deletedColumns = change.deletedColumns;
560
+ // On an inverted diff the table that lost columns is the one in `tr.doc`, so the column
561
+ // indices address it directly and each label anchors inside its own cell.
562
+ var table = tr.doc.nodeAt(change.fromB);
563
+ if (isInverted && !hideDeletedDiffs && deletedColumns !== null && deletedColumns !== void 0 && deletedColumns.length && (table === null || table === void 0 ? void 0 : table.type.name) === 'table') {
564
+ var tableMap = _tableMap.TableMap.get(table);
565
+ deletedColumns.forEach(function (column) {
566
+ var offset = tableMap.positionAt(0, column, table);
567
+ decorations.push(_view.Decoration.widget(change.fromB + _groupDeletedColumnChanges.CELL_CONTENT_OFFSET + offset, function () {
568
+ return (0, _wrapBlockNodeView.createRemovedLozenge)(intl, isActive, changeColorScheme, true);
569
+ }, {
570
+ side: -1
571
+ }));
572
+ });
573
+ }
541
574
 
542
575
  // The deleted side of a mark-only change is a byte-identical copy of the new text, so it is
543
576
  // suppressed in the clean view. `hideDeletedDiffs` is load-bearing: when false the reviewer
@@ -571,6 +604,41 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
571
604
  // On an inverted diff the inserted side is visually the deleted side.
572
605
  var shouldHideDeleted = (0, _isExtendedEnabled.isExtendedEnabled)(diffType) ? isInverted && hideDeletedDiffs : false;
573
606
 
607
+ // A removed blank line — an empty paragraph or heading — has nothing to mark up. On an
608
+ // inverted diff, the shape AI suggested edits renders, the block is still in the displayed
609
+ // document, so the removal lands here on the inserted side rather than on the deleted side,
610
+ // and both the inline and the block decoration paint nothing: an empty textblock has no
611
+ // inline content to cover, and block decorations return no style for a paragraph or heading.
612
+ // The reviewer sees an unmarked blank line. Stand the struck-through return glyph in for each
613
+ // one, anchored inside the block so it renders on the blank line itself.
614
+ //
615
+ // One decoration per blank line rather than one per change: a run of adjacent blank lines is
616
+ // reported as a single change spanning all of them.
617
+ //
618
+ // Withheld in the clean view, where removals are hidden rather than struck through.
619
+ if ((0, _fg.fg)('platform_editor_ai_show_diff_patch_2') && !isInserted && !shouldHideDeleted) {
620
+ var _iterator3 = _createForOfIteratorHelper((0, _emptyTextBlocks.emptyTextBlockContentPositions)(tr.doc, change.fromB, change.toB)),
621
+ _step3;
622
+ try {
623
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
624
+ var pos = _step3.value;
625
+ decorations.push((0, _createDeletedLineBreakWidget.createDeletedLineBreakDecoration)({
626
+ attributionKey: attributionKey,
627
+ colorScheme: changeColorScheme,
628
+ diffType: diffType,
629
+ isActive: isActive,
630
+ pos: pos,
631
+ reveal: reveal,
632
+ side: -1
633
+ }));
634
+ }
635
+ } catch (err) {
636
+ _iterator3.e(err);
637
+ } finally {
638
+ _iterator3.f();
639
+ }
640
+ }
641
+
574
642
  // For `smart` NODE-level promotions the change range spans a whole container
575
643
  // (e.g. an entire list/table/layout, using outer node bounds). Applying a SINGLE
576
644
  // inline decoration across that whole range would paint the inserted style across
@@ -601,13 +669,13 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
601
669
  // table (the cell overlays added below provide the highlight without the
602
670
  // expensive content re-render); leaf blocks outside the table still get theirs.
603
671
  var coarseTables = useCoarseTableDecoration ? tableRanges(tr.doc, change.fromB, change.toB) : [];
604
- var _iterator3 = _createForOfIteratorHelper(leafTextblockRanges(tr.doc, change.fromB, change.toB)),
605
- _step3;
672
+ var _iterator4 = _createForOfIteratorHelper(leafTextblockRanges(tr.doc, change.fromB, change.toB)),
673
+ _step4;
606
674
  try {
607
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
608
- var _step3$value = (0, _slicedToArray2.default)(_step3.value, 2),
609
- from = _step3$value[0],
610
- to = _step3$value[1];
675
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
676
+ var _step4$value = (0, _slicedToArray2.default)(_step4.value, 2),
677
+ from = _step4$value[0],
678
+ to = _step4$value[1];
611
679
  if (useCoarseTableDecoration && isInsideTable(coarseTables, from)) {
612
680
  continue;
613
681
  }
@@ -634,9 +702,9 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
634
702
  }))));
635
703
  }
636
704
  } catch (err) {
637
- _iterator3.e(err);
705
+ _iterator4.e(err);
638
706
  } finally {
639
- _iterator3.f();
707
+ _iterator4.f();
640
708
  }
641
709
  } else {
642
710
  decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createInlineChangedDecoration.createInlineChangedDecoration)(_objectSpread({
@@ -688,6 +756,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
688
756
  });
689
757
  if (!_shouldHideDeleted) {
690
758
  decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createNodeChangedDecorationWidget.createNodeChangedDecorationWidget)(_objectSpread(_objectSpread({
759
+ deletedColumns: deletedColumns,
691
760
  // The deleted side has no inline decoration, so the widget carries the actor.
692
761
  attributionKey: attributionKey,
693
762
  // Extended pipeline only, matching the inline path: the non-extended styles have no
@@ -723,6 +792,10 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
723
792
  (0, _getMarkChangeRanges.getMarkChangeRanges)(simplifiedSteps, simplifiedStepAttributions, (0, _fg.fg)('confluence_ncs_step_diffing_version_history') ? stepMaps : undefined).filter(function (_ref11) {
724
793
  var fromB = _ref11.fromB,
725
794
  toB = _ref11.toB;
795
+ return !isHandledByTable(fromB, toB);
796
+ }).filter(function (_ref12) {
797
+ var fromB = _ref12.fromB,
798
+ toB = _ref12.toB;
726
799
  return !(0, _fg.fg)('confluence_ncs_step_diffing_version_history') || !changes.some(function (change) {
727
800
  return change.fromB === fromB && change.toB === toB;
728
801
  });
@@ -744,9 +817,13 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
744
817
  tagMountContext: tagMountContext
745
818
  })));
746
819
  });
747
- (0, _getAttrChangeRanges.getAttrChangeRanges)(tr.doc, attrStepContexts, originalDoc).filter(function (_ref12) {
748
- var fromB = _ref12.fromB,
749
- toB = _ref12.toB;
820
+ (0, _getAttrChangeRanges.getAttrChangeRanges)(tr.doc, attrStepContexts, originalDoc).filter(function (_ref13) {
821
+ var fromB = _ref13.fromB,
822
+ toB = _ref13.toB;
823
+ return !isHandledByTable(fromB, toB);
824
+ }).filter(function (_ref14) {
825
+ var fromB = _ref14.fromB,
826
+ toB = _ref14.toB;
750
827
  return !(0, _fg.fg)('confluence_ncs_step_diffing_version_history') || !changes.some(function (change) {
751
828
  return change.fromB === fromB && change.toB === toB;
752
829
  });
@@ -856,49 +933,49 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
856
933
  var calculateDiffDecorations = exports.calculateDiffDecorations = (0, _memoizeOne.default)(calculateDiffDecorationsInner,
857
934
  // Cache results unless relevant inputs change. `tagMountContext` is deliberately absent: it is
858
935
  // built once per plugin instance, so it can never be the reason a diff needs recalculating.
859
- function (_ref13, _ref14) {
860
- var _ref18;
861
- var _ref15 = (0, _slicedToArray2.default)(_ref13, 1),
862
- _ref15$ = _ref15[0],
863
- pluginState = _ref15$.pluginState,
864
- state = _ref15$.state,
865
- colorScheme = _ref15$.colorScheme,
866
- intl = _ref15$.intl,
867
- activeIndexPos = _ref15$.activeIndexPos,
868
- isInverted = _ref15$.isInverted,
869
- diffType = _ref15$.diffType,
870
- hideDeletedDiffs = _ref15$.hideDeletedDiffs,
871
- hideAddedDiffsUnderline = _ref15$.hideAddedDiffsUnderline,
872
- showIndicators = _ref15$.showIndicators,
873
- smartThresholds = _ref15$.smartThresholds,
874
- deletedDiffPlacement = _ref15$.deletedDiffPlacement,
875
- inlineDeletedDiffPlacement = _ref15$.inlineDeletedDiffPlacement,
876
- reveal = _ref15$.reveal;
877
- var _ref16 = (0, _slicedToArray2.default)(_ref14, 1),
878
- _ref16$ = _ref16[0],
879
- lastPluginState = _ref16$.pluginState,
880
- lastState = _ref16$.state,
881
- lastColorScheme = _ref16$.colorScheme,
882
- lastIntl = _ref16$.intl,
883
- lastActiveIndexPos = _ref16$.activeIndexPos,
884
- lastIsInverted = _ref16$.isInverted,
885
- lastDiffType = _ref16$.diffType,
886
- lastHideDeletedDiffs = _ref16$.hideDeletedDiffs,
887
- lastHideAddedDiffsUnderline = _ref16$.hideAddedDiffsUnderline,
888
- lastShowIndicators = _ref16$.showIndicators,
889
- lastSmartThresholds = _ref16$.smartThresholds,
890
- lastDeletedDiffPlacement = _ref16$.deletedDiffPlacement,
891
- lastInlineDeletedDiffPlacement = _ref16$.inlineDeletedDiffPlacement,
892
- lastReveal = _ref16$.reveal;
936
+ function (_ref15, _ref16) {
937
+ var _ref20;
938
+ var _ref17 = (0, _slicedToArray2.default)(_ref15, 1),
939
+ _ref17$ = _ref17[0],
940
+ pluginState = _ref17$.pluginState,
941
+ state = _ref17$.state,
942
+ colorScheme = _ref17$.colorScheme,
943
+ intl = _ref17$.intl,
944
+ activeIndexPos = _ref17$.activeIndexPos,
945
+ isInverted = _ref17$.isInverted,
946
+ diffType = _ref17$.diffType,
947
+ hideDeletedDiffs = _ref17$.hideDeletedDiffs,
948
+ hideAddedDiffsUnderline = _ref17$.hideAddedDiffsUnderline,
949
+ showIndicators = _ref17$.showIndicators,
950
+ smartThresholds = _ref17$.smartThresholds,
951
+ deletedDiffPlacement = _ref17$.deletedDiffPlacement,
952
+ inlineDeletedDiffPlacement = _ref17$.inlineDeletedDiffPlacement,
953
+ reveal = _ref17$.reveal;
954
+ var _ref18 = (0, _slicedToArray2.default)(_ref16, 1),
955
+ _ref18$ = _ref18[0],
956
+ lastPluginState = _ref18$.pluginState,
957
+ lastState = _ref18$.state,
958
+ lastColorScheme = _ref18$.colorScheme,
959
+ lastIntl = _ref18$.intl,
960
+ lastActiveIndexPos = _ref18$.activeIndexPos,
961
+ lastIsInverted = _ref18$.isInverted,
962
+ lastDiffType = _ref18$.diffType,
963
+ lastHideDeletedDiffs = _ref18$.hideDeletedDiffs,
964
+ lastHideAddedDiffsUnderline = _ref18$.hideAddedDiffsUnderline,
965
+ lastShowIndicators = _ref18$.showIndicators,
966
+ lastSmartThresholds = _ref18$.smartThresholds,
967
+ lastDeletedDiffPlacement = _ref18$.deletedDiffPlacement,
968
+ lastInlineDeletedDiffPlacement = _ref18$.inlineDeletedDiffPlacement,
969
+ lastReveal = _ref18$.reveal;
893
970
  var originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
894
971
  if ((0, _isExtendedEnabled.isExtendedEnabled)(diffType)) {
895
- var _ref17;
896
- return (_ref17 = 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) &&
972
+ var _ref19;
973
+ return (_ref19 = 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) &&
897
974
  // Contributors can arrive after the first calculation; without this, tags never appear.
898
975
  (0, _isEqual.default)(pluginState.contributors, lastPluginState.contributors) && state.doc.eq(lastState.doc) && hideDeletedDiffs === lastHideDeletedDiffs && hideAddedDiffsUnderline === lastHideAddedDiffsUnderline && showIndicators === lastShowIndicators && (0, _isEqual.default)(smartThresholds, lastSmartThresholds) && deletedDiffPlacement === lastDeletedDiffPlacement && inlineDeletedDiffPlacement === lastInlineDeletedDiffPlacement &&
899
976
  // Turning the reveal on or off changes the emitted styles, so a cached result from the
900
977
  // other setting would leave the diff painted in the wrong resting state.
901
- (0, _isEqual.default)(reveal, lastReveal)) !== null && _ref17 !== void 0 ? _ref17 : false;
978
+ (0, _isEqual.default)(reveal, lastReveal)) !== null && _ref19 !== void 0 ? _ref19 : false;
902
979
  }
903
- return (_ref18 = originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && (0, _isEqual.default)(pluginState.stepAttributions, lastPluginState.stepAttributions) && (0, _isEqual.default)(pluginState.contributors, lastPluginState.contributors) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && (0, _isEqual.default)(activeIndexPos, lastActiveIndexPos) && hideDeletedDiffs === lastHideDeletedDiffs) !== null && _ref18 !== void 0 ? _ref18 : false;
980
+ return (_ref20 = originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && (0, _isEqual.default)(pluginState.stepAttributions, lastPluginState.stepAttributions) && (0, _isEqual.default)(pluginState.contributors, lastPluginState.contributors) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && (0, _isEqual.default)(activeIndexPos, lastActiveIndexPos) && hideDeletedDiffs === lastHideDeletedDiffs) !== null && _ref20 !== void 0 ? _ref20 : false;
904
981
  });
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.groupDeletedColumnChanges = exports.CELL_CONTENT_OFFSET = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _document = require("@atlaskit/editor-common/utils/document");
10
+ var _model = require("@atlaskit/editor-prosemirror/model");
11
+ var _tableMap = require("@atlaskit/editor-tables/table-map");
12
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
13
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
14
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
15
+ var CELL_CONTENT_OFFSET = exports.CELL_CONTENT_OFFSET = 2;
16
+ var IGNORED_CELL_ATTRS = ['localId', 'colwidth'];
17
+ var tablesIn = function tablesIn(doc) {
18
+ var tables = [];
19
+ doc.descendants(function (node, pos) {
20
+ if (node.type.name === 'table') {
21
+ tables.push({
22
+ node: node,
23
+ pos: pos
24
+ });
25
+ return false;
26
+ }
27
+ return true;
28
+ });
29
+ return tables;
30
+ };
31
+ var tableEnd = function tableEnd(table) {
32
+ return table.pos + table.node.nodeSize;
33
+ };
34
+ var documentsDifferOnlyByTable = function documentsDifferOnlyByTable(originalDoc, newDoc, before, after) {
35
+ try {
36
+ return originalDoc.replace(before.pos, tableEnd(before), new _model.Slice(_model.Fragment.from(after.node), 0, 0)).eq(newDoc);
37
+ } catch (_unused) {
38
+ return false;
39
+ }
40
+ };
41
+ var columnOffsets = function columnOffsets(map, table) {
42
+ return Array.from({
43
+ length: map.width
44
+ }, function (_, column) {
45
+ return map.positionAt(0, column, table);
46
+ });
47
+ };
48
+ var positionMatchedColumns = function positionMatchedColumns(_ref) {
49
+ var before = _ref.before,
50
+ after = _ref.after,
51
+ afterToBefore = _ref.afterToBefore,
52
+ beforeOffsets = _ref.beforeOffsets;
53
+ var afterMap = _tableMap.TableMap.get(after.node);
54
+ var surviving = new Set();
55
+ for (var column = 0; column < afterMap.width; column++) {
56
+ var offset = afterMap.positionAt(0, column, after.node);
57
+ var mapped = afterToBefore.mapResult(after.pos + CELL_CONTENT_OFFSET + offset);
58
+ var beforeColumn = beforeOffsets.indexOf(mapped.pos - before.pos - CELL_CONTENT_OFFSET);
59
+ if (mapped.deleted || beforeColumn === -1) {
60
+ return new Set();
61
+ }
62
+ surviving.add(beforeColumn);
63
+ }
64
+ return surviving;
65
+ };
66
+ var addContentMatchedColumns = function addContentMatchedColumns(surviving, before, after) {
67
+ var _before$node$firstChi, _before$node$firstChi2, _after$node$firstChil, _after$node$firstChil2;
68
+ var beforeCells = (_before$node$firstChi = (_before$node$firstChi2 = before.node.firstChild) === null || _before$node$firstChi2 === void 0 ? void 0 : _before$node$firstChi2.children) !== null && _before$node$firstChi !== void 0 ? _before$node$firstChi : [];
69
+ var afterCells = (_after$node$firstChil = (_after$node$firstChil2 = after.node.firstChild) === null || _after$node$firstChil2 === void 0 ? void 0 : _after$node$firstChil2.children) !== null && _after$node$firstChil !== void 0 ? _after$node$firstChil : [];
70
+ var _iterator = _createForOfIteratorHelper(afterCells),
71
+ _step;
72
+ try {
73
+ var _loop = function _loop() {
74
+ var afterCell = _step.value;
75
+ var matches = beforeCells.flatMap(function (beforeCell, column) {
76
+ return (0, _document.areNodesEqualIgnoreAttrs)(beforeCell, afterCell, IGNORED_CELL_ATTRS) ? [column] : [];
77
+ });
78
+ if (matches.length !== 1) {
79
+ return {
80
+ v: false
81
+ };
82
+ }
83
+ surviving.add(matches[0]);
84
+ },
85
+ _ret;
86
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
87
+ _ret = _loop();
88
+ if (_ret) return _ret.v;
89
+ }
90
+ } catch (err) {
91
+ _iterator.e(err);
92
+ } finally {
93
+ _iterator.f();
94
+ }
95
+ var ordered = (0, _toConsumableArray2.default)(surviving);
96
+ return !ordered.some(function (column, index) {
97
+ return index > 0 && column <= ordered[index - 1];
98
+ });
99
+ };
100
+ var findDeletedColumns = function findDeletedColumns(before, after, afterToBefore) {
101
+ var beforeMap = _tableMap.TableMap.get(before.node);
102
+ var afterMap = _tableMap.TableMap.get(after.node);
103
+ // Merged or malformed tables do not have reliable column indices.
104
+ if (beforeMap.hasMergedCells() || afterMap.hasMergedCells() || beforeMap.problems || afterMap.problems) {
105
+ return [];
106
+ }
107
+ var beforeOffsets = columnOffsets(beforeMap, before.node);
108
+ var surviving = positionMatchedColumns({
109
+ before: before,
110
+ after: after,
111
+ afterToBefore: afterToBefore,
112
+ beforeOffsets: beforeOffsets
113
+ });
114
+ if (surviving.size !== afterMap.width && !addContentMatchedColumns(surviving, before, after)) {
115
+ return [];
116
+ }
117
+ return beforeOffsets.flatMap(function (_, column) {
118
+ return surviving.has(column) ? [] : [column];
119
+ });
120
+ };
121
+ var findCounterpart = function findCounterpart(_ref2) {
122
+ var table = _ref2.table,
123
+ index = _ref2.index,
124
+ originalTables = _ref2.originalTables,
125
+ newTables = _ref2.newTables,
126
+ mapping = _ref2.mapping;
127
+ var from = mapping.map(table.pos, -1);
128
+ var to = mapping.map(tableEnd(table), 1);
129
+ var inside = mapping.mapResult(table.pos + 1);
130
+ var candidates = newTables.filter(function (candidate) {
131
+ return inside.deleted ? candidate.pos >= from && tableEnd(candidate) <= to : candidate.pos < inside.pos && inside.pos < tableEnd(candidate);
132
+ });
133
+ if (candidates.length === 1) {
134
+ return candidates[0];
135
+ }
136
+ return originalTables.length === newTables.length ? newTables[index] : undefined;
137
+ };
138
+ var orient = function orient(_ref3) {
139
+ var table = _ref3.table,
140
+ counterpart = _ref3.counterpart,
141
+ mapping = _ref3.mapping,
142
+ isInverted = _ref3.isInverted;
143
+ return {
144
+ before: isInverted ? counterpart : table,
145
+ after: isInverted ? table : counterpart,
146
+ afterToBefore: (isInverted ? mapping.invert() : mapping).invert()
147
+ };
148
+ };
149
+ var changesInTable = function changesInTable(changes, table) {
150
+ return changes.filter(function (change) {
151
+ return change.fromA < tableEnd(table) && change.toA > table.pos;
152
+ });
153
+ };
154
+ var isNarrowingSafe = function isNarrowingSafe(_ref4) {
155
+ var replacedChanges = _ref4.replacedChanges,
156
+ table = _ref4.table,
157
+ counterpart = _ref4.counterpart,
158
+ originalDoc = _ref4.originalDoc,
159
+ newDoc = _ref4.newDoc;
160
+ var staysInside = replacedChanges.every(function (change) {
161
+ return change.fromA >= table.pos && change.toA <= tableEnd(table) && change.fromB >= counterpart.pos && change.toB <= tableEnd(counterpart);
162
+ });
163
+ return staysInside || documentsDifferOnlyByTable(originalDoc, newDoc, table, counterpart);
164
+ };
165
+ var planTableChange = function planTableChange(_ref5) {
166
+ var table = _ref5.table,
167
+ index = _ref5.index,
168
+ originalTables = _ref5.originalTables,
169
+ newTables = _ref5.newTables,
170
+ changes = _ref5.changes,
171
+ originalDoc = _ref5.originalDoc,
172
+ newDoc = _ref5.newDoc,
173
+ mapping = _ref5.mapping,
174
+ isInverted = _ref5.isInverted;
175
+ var counterpart = findCounterpart({
176
+ table: table,
177
+ index: index,
178
+ originalTables: originalTables,
179
+ newTables: newTables,
180
+ mapping: mapping
181
+ });
182
+ if (!counterpart) {
183
+ return undefined;
184
+ }
185
+ var _orient = orient({
186
+ table: table,
187
+ counterpart: counterpart,
188
+ mapping: mapping,
189
+ isInverted: isInverted
190
+ }),
191
+ before = _orient.before,
192
+ after = _orient.after,
193
+ afterToBefore = _orient.afterToBefore;
194
+ if (_tableMap.TableMap.get(before.node).width <= _tableMap.TableMap.get(after.node).width) {
195
+ return undefined;
196
+ }
197
+ var replacedChanges = changesInTable(changes, table);
198
+ if (!replacedChanges.length) {
199
+ return undefined;
200
+ }
201
+ if (!isNarrowingSafe({
202
+ replacedChanges: replacedChanges,
203
+ table: table,
204
+ counterpart: counterpart,
205
+ originalDoc: originalDoc,
206
+ newDoc: newDoc
207
+ })) {
208
+ return undefined;
209
+ }
210
+ var spans = replacedChanges.flatMap(function (change) {
211
+ return [].concat((0, _toConsumableArray2.default)(change.deleted), (0, _toConsumableArray2.default)(change.inserted));
212
+ });
213
+ return {
214
+ replacedChanges: replacedChanges,
215
+ tableChange: {
216
+ deletedColumns: findDeletedColumns(before, after, afterToBefore),
217
+ fromA: table.pos,
218
+ toA: tableEnd(table),
219
+ fromB: counterpart.pos,
220
+ toB: tableEnd(counterpart),
221
+ deleted: spans,
222
+ inserted: spans
223
+ }
224
+ };
225
+ };
226
+
227
+ /** Groups a deleted column's cell changes into one whole-table change. */
228
+ var groupDeletedColumnChanges = exports.groupDeletedColumnChanges = function groupDeletedColumnChanges(changes, originalDoc, newDoc, mapping, isInverted) {
229
+ var originalTables = tablesIn(originalDoc);
230
+ var newTables = tablesIn(newDoc);
231
+ var plans = [];
232
+ var replaced = new Set();
233
+ originalTables.forEach(function (table, index) {
234
+ var plan = planTableChange({
235
+ table: table,
236
+ index: index,
237
+ originalTables: originalTables,
238
+ newTables: newTables,
239
+ changes: changes.filter(function (change) {
240
+ return !replaced.has(change);
241
+ }),
242
+ originalDoc: originalDoc,
243
+ newDoc: newDoc,
244
+ mapping: mapping,
245
+ isInverted: isInverted
246
+ });
247
+ if (!plan) {
248
+ return;
249
+ }
250
+ plans.push(plan);
251
+ plan.replacedChanges.forEach(function (change) {
252
+ return replaced.add(change);
253
+ });
254
+ });
255
+ if (!plans.length) {
256
+ return (0, _toConsumableArray2.default)(changes);
257
+ }
258
+ return [].concat((0, _toConsumableArray2.default)(changes.filter(function (change) {
259
+ return !replaced.has(change);
260
+ })), (0, _toConsumableArray2.default)(plans.map(function (plan) {
261
+ return plan.tableChange;
262
+ }))).sort(function (left, right) {
263
+ return left.fromB - right.fromB;
264
+ });
265
+ };
@@ -12,6 +12,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
12
12
  var _utils = require("@atlaskit/editor-shared-styles/utils");
13
13
  var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
14
14
  var _fg = require("@atlaskit/platform-feature-flags/fg");
15
+ var _showDiffPluginType = require("../../../showDiffPluginType");
15
16
  var _types = require("./types");
16
17
  var _excluded = ["attribution", "connectedTo"];
17
18
  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; }
@@ -95,6 +96,16 @@ var getAttributionKey = exports.getAttributionKey = function getAttributionKey(a
95
96
  var _getAttributionIdenti;
96
97
  return (_getAttributionIdenti = getAttributionIdentity(attribution)) === null || _getAttributionIdenti === void 0 ? void 0 : _getAttributionIdenti.key;
97
98
  };
99
+ var isDiffAgentBrand = function isDiffAgentBrand(agentBrand) {
100
+ return agentBrand !== undefined && _showDiffPluginType.DIFF_AGENT_BRANDS.has(agentBrand);
101
+ };
102
+
103
+ /** Prefers the resolved branded profile over the raw attribution agent type. */
104
+ var getAgentBrandForColor = function getAgentBrandForColor(attribution, contributors) {
105
+ var _contributors, _getAttributionKey;
106
+ var agentBrand = contributors === null || contributors === void 0 || (_contributors = contributors[(_getAttributionKey = getAttributionKey(attribution)) !== null && _getAttributionKey !== void 0 ? _getAttributionKey : '']) === null || _contributors === void 0 ? void 0 : _contributors.agentKind;
107
+ return isDiffAgentBrand(agentBrand) ? agentBrand : attribution === null || attribution === void 0 ? void 0 : attribution.agentType;
108
+ };
98
109
 
99
110
  /**
100
111
  * Public contributor list to internal key-addressed record. A contributor whose attribution carries
@@ -154,7 +165,7 @@ var isContributorTagsEnabled = exports.isContributorTagsEnabled = function isCon
154
165
  return getAttributionKey(attribution) !== undefined;
155
166
  })) && contributors !== undefined && Object.keys(contributors).length > 0;
156
167
  };
157
- var createAttributionColorMap = exports.createAttributionColorMap = function createAttributionColorMap(stepAttributions) {
168
+ var createAttributionColorMap = exports.createAttributionColorMap = function createAttributionColorMap(stepAttributions, contributors) {
158
169
  var colors = new Map();
159
170
  var allocatedColors = new Set();
160
171
 
@@ -169,7 +180,7 @@ var createAttributionColorMap = exports.createAttributionColorMap = function cre
169
180
  if (!identity) {
170
181
  continue;
171
182
  }
172
- var _getParticipantColor = (0, _utils.getParticipantColor)(identity.colorSeed, attribution === null || attribution === void 0 ? void 0 : attribution.agentType),
183
+ var _getParticipantColor = (0, _utils.getParticipantColor)(identity.colorSeed, getAgentBrandForColor(attribution, contributors)),
173
184
  index = _getParticipantColor.index,
174
185
  isFixed = _getParticipantColor.isFixed;
175
186
  var color = HASHED_PARTICIPANT_COLOR_SCHEMES[index];
@@ -192,7 +203,7 @@ var createAttributionColorMap = exports.createAttributionColorMap = function cre
192
203
  if (!_identity || colors.has(_identity.key)) {
193
204
  continue;
194
205
  }
195
- var _getParticipantColor2 = (0, _utils.getParticipantColor)(_identity.colorSeed, _attribution === null || _attribution === void 0 ? void 0 : _attribution.agentType),
206
+ var _getParticipantColor2 = (0, _utils.getParticipantColor)(_identity.colorSeed, getAgentBrandForColor(_attribution, contributors)),
196
207
  _index = _getParticipantColor2.index;
197
208
  var hashedColor = getSlotColor(_index);
198
209
  if (!hashedColor) {