@atlaskit/editor-plugin-show-diff 17.0.1 → 17.0.2
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 +15 -0
- package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +126 -49
- package/dist/cjs/pm-plugins/calculateDiff/groupDeletedColumnChanges.js +265 -0
- package/dist/cjs/pm-plugins/decorations/createChangedRowDecorationWidgets.js +100 -34
- package/dist/cjs/pm-plugins/decorations/createContributorTagWidget.js +18 -13
- package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +82 -20
- package/dist/cjs/pm-plugins/decorations/utils/createDeletedLineBreakWidget.js +106 -0
- package/dist/cjs/pm-plugins/decorations/utils/tableDiffMode.js +36 -0
- package/dist/cjs/pm-plugins/decorations/utils/wrapBlockNodeView.js +17 -6
- package/dist/cjs/pm-plugins/utils/emptyTextBlocks.js +66 -0
- package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +61 -1
- package/dist/es2019/pm-plugins/calculateDiff/groupDeletedColumnChanges.js +210 -0
- package/dist/es2019/pm-plugins/decorations/createChangedRowDecorationWidgets.js +79 -13
- package/dist/es2019/pm-plugins/decorations/createContributorTagWidget.js +8 -2
- package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +85 -15
- package/dist/es2019/pm-plugins/decorations/utils/createDeletedLineBreakWidget.js +100 -0
- package/dist/es2019/pm-plugins/decorations/utils/tableDiffMode.js +27 -0
- package/dist/es2019/pm-plugins/decorations/utils/wrapBlockNodeView.js +15 -5
- package/dist/es2019/pm-plugins/utils/emptyTextBlocks.js +58 -0
- package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +127 -50
- package/dist/esm/pm-plugins/calculateDiff/groupDeletedColumnChanges.js +258 -0
- package/dist/esm/pm-plugins/decorations/createChangedRowDecorationWidgets.js +100 -34
- package/dist/esm/pm-plugins/decorations/createContributorTagWidget.js +18 -13
- package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +84 -22
- package/dist/esm/pm-plugins/decorations/utils/createDeletedLineBreakWidget.js +100 -0
- package/dist/esm/pm-plugins/decorations/utils/tableDiffMode.js +30 -0
- package/dist/esm/pm-plugins/decorations/utils/wrapBlockNodeView.js +16 -5
- package/dist/esm/pm-plugins/utils/emptyTextBlocks.js +60 -0
- package/dist/types/pm-plugins/calculateDiff/groupDeletedColumnChanges.d.ts +9 -0
- package/dist/types/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +3 -1
- package/dist/types/pm-plugins/decorations/createContributorTagWidget.d.ts +5 -1
- package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/utils/createDeletedLineBreakWidget.d.ts +50 -0
- package/dist/types/pm-plugins/decorations/utils/tableDiffMode.d.ts +26 -0
- package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +4 -0
- package/dist/types/pm-plugins/utils/emptyTextBlocks.d.ts +16 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-show-diff
|
|
2
2
|
|
|
3
|
+
## 17.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`df446e0eda630`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/df446e0eda630) -
|
|
8
|
+
The extended diff view now compares whole tables after a column deletion. Reliably tracked deleted
|
|
9
|
+
columns use strikethrough text and a Removed lozenge, with contributor tags aligned directly above
|
|
10
|
+
the table. Deleted table rows also carry a Removed lozenge in their top-right corner.
|
|
11
|
+
- [`885418b21ca4d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/885418b21ca4d) -
|
|
12
|
+
Show a struck-through return glyph (⤶) where a removed blank line was — an empty paragraph or an
|
|
13
|
+
empty heading — instead of rendering nothing. One glyph per removed line, including runs of
|
|
14
|
+
adjacent ones. Covers both diff directions: the deleted side of a forward diff, and the inserted
|
|
15
|
+
side of an inverted diff (AI suggested edits). Behind `platform_editor_ai_show_diff_patch_2`.
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
|
|
3
18
|
## 17.0.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -15,6 +15,7 @@ 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");
|
|
@@ -25,15 +26,19 @@ var _createNodeChangedDecorationWidget = require("../decorations/createNodeChang
|
|
|
25
26
|
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");
|
|
31
|
+
var _wrapBlockNodeView = require("../decorations/utils/wrapBlockNodeView");
|
|
29
32
|
var _getMarkChangeRanges = require("../decorations/utils/getMarkChangeRanges");
|
|
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");
|
|
34
38
|
var _isMarkOnlyChange = require("./isMarkOnlyChange");
|
|
35
39
|
var _isOpenTokenOnlyChange = require("./isOpenTokenOnlyChange");
|
|
36
40
|
var _optimizeChanges = require("./optimizeChanges");
|
|
41
|
+
var _groupDeletedColumnChanges = require("./groupDeletedColumnChanges");
|
|
37
42
|
var _selectTokenEncoder2 = require("./selectTokenEncoder");
|
|
38
43
|
var _simplifyChangesWithAttribution = require("./simplifyChangesWithAttribution");
|
|
39
44
|
var _simplifySteps = require("./simplifySteps");
|
|
@@ -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
|
|
605
|
-
|
|
672
|
+
var _iterator4 = _createForOfIteratorHelper(leafTextblockRanges(tr.doc, change.fromB, change.toB)),
|
|
673
|
+
_step4;
|
|
606
674
|
try {
|
|
607
|
-
for (
|
|
608
|
-
var
|
|
609
|
-
from =
|
|
610
|
-
to =
|
|
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
|
-
|
|
705
|
+
_iterator4.e(err);
|
|
638
706
|
} finally {
|
|
639
|
-
|
|
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 (
|
|
748
|
-
var fromB =
|
|
749
|
-
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 (
|
|
860
|
-
var
|
|
861
|
-
var
|
|
862
|
-
|
|
863
|
-
pluginState =
|
|
864
|
-
state =
|
|
865
|
-
colorScheme =
|
|
866
|
-
intl =
|
|
867
|
-
activeIndexPos =
|
|
868
|
-
isInverted =
|
|
869
|
-
diffType =
|
|
870
|
-
hideDeletedDiffs =
|
|
871
|
-
hideAddedDiffsUnderline =
|
|
872
|
-
showIndicators =
|
|
873
|
-
smartThresholds =
|
|
874
|
-
deletedDiffPlacement =
|
|
875
|
-
inlineDeletedDiffPlacement =
|
|
876
|
-
reveal =
|
|
877
|
-
var
|
|
878
|
-
|
|
879
|
-
lastPluginState =
|
|
880
|
-
lastState =
|
|
881
|
-
lastColorScheme =
|
|
882
|
-
lastIntl =
|
|
883
|
-
lastActiveIndexPos =
|
|
884
|
-
lastIsInverted =
|
|
885
|
-
lastDiffType =
|
|
886
|
-
lastHideDeletedDiffs =
|
|
887
|
-
lastHideAddedDiffsUnderline =
|
|
888
|
-
lastShowIndicators =
|
|
889
|
-
lastSmartThresholds =
|
|
890
|
-
lastDeletedDiffPlacement =
|
|
891
|
-
lastInlineDeletedDiffPlacement =
|
|
892
|
-
lastReveal =
|
|
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
|
|
896
|
-
return (
|
|
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 &&
|
|
978
|
+
(0, _isEqual.default)(reveal, lastReveal)) !== null && _ref19 !== void 0 ? _ref19 : false;
|
|
902
979
|
}
|
|
903
|
-
return (
|
|
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
|
+
};
|