@atlaskit/editor-plugin-show-diff 21.0.1 → 21.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 +7 -0
- package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +51 -13
- package/dist/cjs/pm-plugins/calculateDiff/markAwareTokenEncoder.js +2 -1
- package/dist/cjs/pm-plugins/calculateDiff/selectTokenEncoder.js +1 -1
- package/dist/cjs/pm-plugins/decorations/utils/diffableAttrs.js +5 -1
- package/dist/cjs/pm-plugins/decorations/utils/getAttrChangeRanges.js +10 -7
- package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +38 -11
- package/dist/es2019/pm-plugins/calculateDiff/markAwareTokenEncoder.js +2 -1
- package/dist/es2019/pm-plugins/calculateDiff/selectTokenEncoder.js +1 -1
- package/dist/es2019/pm-plugins/decorations/utils/diffableAttrs.js +6 -1
- package/dist/es2019/pm-plugins/decorations/utils/getAttrChangeRanges.js +4 -3
- package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +51 -13
- package/dist/esm/pm-plugins/calculateDiff/markAwareTokenEncoder.js +2 -1
- package/dist/esm/pm-plugins/calculateDiff/selectTokenEncoder.js +1 -1
- package/dist/esm/pm-plugins/decorations/utils/diffableAttrs.js +6 -1
- package/dist/esm/pm-plugins/decorations/utils/getAttrChangeRanges.js +10 -7
- package/dist/types/pm-plugins/calculateDiff/markAwareTokenEncoder.d.ts +2 -1
- package/dist/types/pm-plugins/calculateDiff/selectTokenEncoder.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-show-diff
|
|
2
2
|
|
|
3
|
+
## 21.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`1647c1098fca5`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1647c1098fca5) -
|
|
8
|
+
Highlight changed inline nodes and the edited portion of link display text
|
|
9
|
+
|
|
3
10
|
## 21.0.1
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -464,11 +464,14 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
|
|
|
464
464
|
};
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
|
-
// The attribute-aware encoder is
|
|
468
|
-
|
|
467
|
+
// The attribute-aware encoder is needed by the smart classifier and is gated with it.
|
|
468
|
+
// The NCS version-history path also uses it so the main diff calculation detects attribute-only
|
|
469
|
+
// node replacements, e.g. changing an emoji or mention without changing the node type.
|
|
470
|
+
var _selectTokenEncoder = (0, _selectTokenEncoder2.selectTokenEncoder)(diffType === 'smart' && (0, _fg.fg)('platform_editor_ai_smart_diff') || (0, _fg.fg)('confluence_ncs_step_diffing_version_history')),
|
|
469
471
|
tokenEncoder = _selectTokenEncoder.tokenEncoder,
|
|
470
472
|
shouldHideMarkOnlyDeletions = _selectTokenEncoder.shouldHideMarkOnlyDeletions;
|
|
471
473
|
var changes;
|
|
474
|
+
var contentChanges;
|
|
472
475
|
var attributedChanges = [];
|
|
473
476
|
var attributionColors;
|
|
474
477
|
if (attributedChangesetEnabled) {
|
|
@@ -482,6 +485,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
|
|
|
482
485
|
stepIndex: stepIndex
|
|
483
486
|
});
|
|
484
487
|
}));
|
|
488
|
+
contentChanges = changeset.changes;
|
|
485
489
|
attributedChanges = diffType === 'step' ? (0, _diffBySteps.diffBySteps)(originalDoc, simplifiedSteps, simplifiedStepAttributions) : (0, _toConsumableArray2.default)(changeset.changes);
|
|
486
490
|
// The attributed pipeline gives no guarantee that its output ranges are disjoint — see
|
|
487
491
|
// `collapseOverlappingChanges`.
|
|
@@ -501,6 +505,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
|
|
|
501
505
|
}
|
|
502
506
|
} else {
|
|
503
507
|
var _changeset = _prosemirrorChangeset.ChangeSet.create(originalDoc, undefined, tokenEncoder).addSteps(steppedDoc, stepMaps, tr.doc);
|
|
508
|
+
contentChanges = _changeset.changes;
|
|
504
509
|
changes = getChanges({
|
|
505
510
|
changeset: _changeset,
|
|
506
511
|
originalDoc: originalDoc,
|
|
@@ -760,20 +765,52 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
|
|
|
760
765
|
changes.forEach(function (change) {
|
|
761
766
|
createDecorationsForChange(change);
|
|
762
767
|
});
|
|
763
|
-
//
|
|
764
|
-
//
|
|
765
|
-
//
|
|
766
|
-
|
|
767
|
-
(0, _getMarkChangeRanges.getMarkChangeRanges)(simplifiedSteps, simplifiedStepAttributions, (0, _fg.fg)('confluence_ncs_step_diffing_version_history') ? stepMaps : undefined).filter(function (_ref10) {
|
|
768
|
+
// Compare the content outside replacement ranges at matching positions in both documents.
|
|
769
|
+
// This preserves real formatting edits without highlighting an unchanged link mark reapplied
|
|
770
|
+
// while editing its display text.
|
|
771
|
+
var hasUnhighlightedMarkChanges = function hasUnhighlightedMarkChanges(_ref10) {
|
|
768
772
|
var fromB = _ref10.fromB,
|
|
769
773
|
toB = _ref10.toB;
|
|
770
|
-
|
|
771
|
-
|
|
774
|
+
var from = fromB;
|
|
775
|
+
var offset = 0;
|
|
776
|
+
var differs = function differs(to) {
|
|
777
|
+
return from < to && !originalDoc.slice(from + offset, to + offset).content.eq(tr.doc.slice(from, to).content);
|
|
778
|
+
};
|
|
779
|
+
var _iterator5 = _createForOfIteratorHelper(contentChanges),
|
|
780
|
+
_step5;
|
|
781
|
+
try {
|
|
782
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
783
|
+
var change = _step5.value;
|
|
784
|
+
if (change.fromB >= toB) {
|
|
785
|
+
break;
|
|
786
|
+
}
|
|
787
|
+
if (change.toB > from) {
|
|
788
|
+
if (differs(change.fromB)) {
|
|
789
|
+
return true;
|
|
790
|
+
}
|
|
791
|
+
from = change.toB;
|
|
792
|
+
}
|
|
793
|
+
offset = change.toA - change.toB;
|
|
794
|
+
}
|
|
795
|
+
} catch (err) {
|
|
796
|
+
_iterator5.e(err);
|
|
797
|
+
} finally {
|
|
798
|
+
_iterator5.f();
|
|
799
|
+
}
|
|
800
|
+
return differs(toB);
|
|
801
|
+
};
|
|
802
|
+
|
|
803
|
+
// The attribute-aware token encoder already reports mark-only changes as regular changes in the
|
|
804
|
+
// smart path and the NCS version-history path. For NCS version history, only skip the step-range
|
|
805
|
+
// highlight if the main diff covers it or the remaining content has unchanged formatting.
|
|
806
|
+
(0, _getMarkChangeRanges.getMarkChangeRanges)(simplifiedSteps, simplifiedStepAttributions, (0, _fg.fg)('confluence_ncs_step_diffing_version_history') ? stepMaps : undefined).filter(function (_ref11) {
|
|
772
807
|
var fromB = _ref11.fromB,
|
|
773
808
|
toB = _ref11.toB;
|
|
809
|
+
return !isHandledByTable(fromB, toB);
|
|
810
|
+
}).filter(function (range) {
|
|
774
811
|
return !(0, _fg.fg)('confluence_ncs_step_diffing_version_history') || !changes.some(function (change) {
|
|
775
|
-
return change.fromB
|
|
776
|
-
});
|
|
812
|
+
return change.fromB <= range.fromB && change.toB >= range.toB;
|
|
813
|
+
}) && hasUnhighlightedMarkChanges(range);
|
|
777
814
|
}).forEach(function (change) {
|
|
778
815
|
var _attributionColors$ge, _attributionColors;
|
|
779
816
|
var changeColorScheme = change.attributionKey ? (_attributionColors$ge = (_attributionColors = attributionColors) === null || _attributionColors === void 0 ? void 0 : _attributionColors.get(change.attributionKey)) !== null && _attributionColors$ge !== void 0 ? _attributionColors$ge : colorScheme : colorScheme;
|
|
@@ -797,8 +834,9 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
|
|
|
797
834
|
return !isHandledByTable(fromB, toB);
|
|
798
835
|
}).filter(function (_ref13) {
|
|
799
836
|
var fromB = _ref13.fromB,
|
|
800
|
-
toB = _ref13.toB
|
|
801
|
-
|
|
837
|
+
toB = _ref13.toB,
|
|
838
|
+
isInline = _ref13.isInline;
|
|
839
|
+
return !(0, _fg.fg)('confluence_ncs_step_diffing_version_history') || !isInline || !changes.some(function (change) {
|
|
802
840
|
return change.fromB === fromB && change.toB === toB;
|
|
803
841
|
});
|
|
804
842
|
}).forEach(function (change) {
|
|
@@ -20,7 +20,8 @@ var typeID = function typeID(type) {
|
|
|
20
20
|
*
|
|
21
21
|
* Deliberately narrower than `attrAwareTokenEncoder`: node-start tokens keep the library default
|
|
22
22
|
* and do not fold in diffable attributes, which `getAttrChangeRanges` already reports for every
|
|
23
|
-
* diff type.
|
|
23
|
+
* diff type. The NCS version-history path also uses `attrAwareTokenEncoder` so main diff calculation
|
|
24
|
+
* detects attribute-only node replacements.
|
|
24
25
|
*/
|
|
25
26
|
var markAwareTokenEncoder = exports.markAwareTokenEncoder = {
|
|
26
27
|
encodeCharacter: function encodeCharacter(char, marks) {
|
|
@@ -11,7 +11,7 @@ var _markAwareTokenEncoder = require("./markAwareTokenEncoder");
|
|
|
11
11
|
* `computeDiffChanges` so the two cannot drift.
|
|
12
12
|
*
|
|
13
13
|
* @param useAttrAwareEncoder Caller is running the smart classifier, which needs node attrs folded
|
|
14
|
-
* into the token.
|
|
14
|
+
* into the token. Also used by the NCS version-history path to detect attribute-only node changes.
|
|
15
15
|
*/
|
|
16
16
|
var selectTokenEncoder = exports.selectTokenEncoder = function selectTokenEncoder(useAttrAwareEncoder) {
|
|
17
17
|
if (useAttrAwareEncoder) {
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.isDiffableAttr = exports.getRequiredIncludedDiffableAttrs = exports.getIncludedDiffableAttrs = exports.getDiffableAttrNames = exports.DIFFABLE_ATTRS_BY_NODE_TYPE = void 0;
|
|
7
|
+
var _fg = require("@atlaskit/platform-feature-flags/fg");
|
|
7
8
|
/**
|
|
8
9
|
* Single source of truth for which attributes of a node type represent a
|
|
9
10
|
* meaningful change. Shared by `attrAwareTokenEncoder` (changeset detection)
|
|
@@ -94,10 +95,13 @@ var getRequiredIncludedDiffableAttrs = exports.getRequiredIncludedDiffableAttrs
|
|
|
94
95
|
* order is not stable across the two diffed documents.
|
|
95
96
|
*/
|
|
96
97
|
var getDiffableAttrNames = exports.getDiffableAttrNames = function getDiffableAttrNames(nodeTypeName, attrs) {
|
|
98
|
+
// Adding a column updates existing widths, ignore this attribute change. Move this into
|
|
99
|
+
// DIFFABLE_ATTRS_BY_NODE_TYPE when cleaning up confluence_ncs_step_diffing_version_history
|
|
100
|
+
var ignoreColumnWidth = nodeTypeName === 'layoutColumn' && (0, _fg.fg)('confluence_ncs_step_diffing_version_history');
|
|
97
101
|
var rule = DIFFABLE_ATTRS_BY_NODE_TYPE[nodeTypeName];
|
|
98
102
|
if (!rule) {
|
|
99
103
|
return Object.keys(attrs).filter(function (name) {
|
|
100
|
-
return !DEFAULT_EXCLUDED_ATTRS.includes(name);
|
|
104
|
+
return !DEFAULT_EXCLUDED_ATTRS.includes(name) && !(ignoreColumnWidth && name === 'width');
|
|
101
105
|
}).sort();
|
|
102
106
|
}
|
|
103
107
|
if ('include' in rule) {
|
|
@@ -90,6 +90,11 @@ var getAttrChangeRanges = exports.getAttrChangeRanges = function getAttrChangeRa
|
|
|
90
90
|
var $pos = doc.resolve(finalPos);
|
|
91
91
|
var nodeAtPos = doc.nodeAt(finalPos);
|
|
92
92
|
var originalNodeAtPos = originalPos === undefined ? null : originalDoc.nodeAt(originalPos);
|
|
93
|
+
var hasChangedAttr = function hasChangedAttr(watchedAttrs) {
|
|
94
|
+
return attrsToCheck.some(function (attr) {
|
|
95
|
+
return watchedAttrs.includes(attr) && (!(0, _fg.fg)('confluence_ncs_step_diffing_version_history') || !originalNodeAtPos || originalNodeAtPos.type !== (nodeAtPos === null || nodeAtPos === void 0 ? void 0 : nodeAtPos.type) || !(0, _isEqual.default)(originalNodeAtPos.attrs[attr], nodeAtPos === null || nodeAtPos === void 0 ? void 0 : nodeAtPos.attrs[attr]));
|
|
96
|
+
});
|
|
97
|
+
};
|
|
93
98
|
|
|
94
99
|
// The changeset path (createDecorationsForChange) handles the deletion widget via
|
|
95
100
|
// prosemirror-changeset; we only need to add the inline insertion highlight here.
|
|
@@ -97,9 +102,7 @@ var getAttrChangeRanges = exports.getAttrChangeRanges = function getAttrChangeRa
|
|
|
97
102
|
var nodeName = nodeAtPos.type.name;
|
|
98
103
|
if (isInlineAttrChangeNodeName(nodeName)) {
|
|
99
104
|
var watchedAttrs = inlineNodeAttrMap[nodeName];
|
|
100
|
-
if (
|
|
101
|
-
return watchedAttrs.includes(v);
|
|
102
|
-
})) {
|
|
105
|
+
if (hasChangedAttr(watchedAttrs)) {
|
|
103
106
|
return _objectSpread(_objectSpread({}, attributionKey ? {
|
|
104
107
|
attributionKey: attributionKey
|
|
105
108
|
} : {}), {}, {
|
|
@@ -131,9 +134,7 @@ var getAttrChangeRanges = exports.getAttrChangeRanges = function getAttrChangeRa
|
|
|
131
134
|
// (e.g. note -> warning) — highlight the new panel and, when the original node
|
|
132
135
|
// is resolvable, expose its range (fromA/toA) so the caller can render the old
|
|
133
136
|
// panel as a "deleted" widget for a before/after comparison.
|
|
134
|
-
if (
|
|
135
|
-
return panelAttrs.includes(v);
|
|
136
|
-
}) && nodeAtPos && (0, _nodeTypeUtils.getBaseNodeTypeName)(nodeAtPos.type) === 'panel') {
|
|
137
|
+
if (hasChangedAttr(panelAttrs) && nodeAtPos && (0, _nodeTypeUtils.getBaseNodeTypeName)(nodeAtPos.type) === 'panel') {
|
|
137
138
|
return _objectSpread(_objectSpread({}, attributionKey ? {
|
|
138
139
|
attributionKey: attributionKey
|
|
139
140
|
} : {}), {}, {
|
|
@@ -181,7 +182,9 @@ var getAttrChangeRanges = exports.getAttrChangeRanges = function getAttrChangeRa
|
|
|
181
182
|
// (e.g. setNodeAttribute(pos, 'text', ...) + setNodeAttribute(pos, 'color', ...))
|
|
182
183
|
// should produce only one decoration, not one per step.
|
|
183
184
|
.filter(function (range, i, arr) {
|
|
184
|
-
return arr.
|
|
185
|
+
return (0, _fg.fg)('confluence_ncs_step_diffing_version_history') ? !arr.some(function (r, nextIndex) {
|
|
186
|
+
return nextIndex > i && r.fromB === range.fromB;
|
|
187
|
+
}) : arr.findIndex(function (r) {
|
|
185
188
|
return r.fromB === range.fromB;
|
|
186
189
|
}) === i;
|
|
187
190
|
});
|
|
@@ -418,12 +418,15 @@ const calculateDiffDecorationsInner = ({
|
|
|
418
418
|
};
|
|
419
419
|
}
|
|
420
420
|
}
|
|
421
|
-
// The attribute-aware encoder is
|
|
421
|
+
// The attribute-aware encoder is needed by the smart classifier and is gated with it.
|
|
422
|
+
// The NCS version-history path also uses it so the main diff calculation detects attribute-only
|
|
423
|
+
// node replacements, e.g. changing an emoji or mention without changing the node type.
|
|
422
424
|
const {
|
|
423
425
|
tokenEncoder,
|
|
424
426
|
shouldHideMarkOnlyDeletions
|
|
425
|
-
} = selectTokenEncoder(diffType === 'smart' && fg('platform_editor_ai_smart_diff'));
|
|
427
|
+
} = selectTokenEncoder(diffType === 'smart' && fg('platform_editor_ai_smart_diff') || fg('confluence_ncs_step_diffing_version_history'));
|
|
426
428
|
let changes;
|
|
429
|
+
let contentChanges;
|
|
427
430
|
let attributedChanges = [];
|
|
428
431
|
let attributionColors;
|
|
429
432
|
if (attributedChangesetEnabled) {
|
|
@@ -434,6 +437,7 @@ const calculateDiffDecorationsInner = ({
|
|
|
434
437
|
...attribution,
|
|
435
438
|
stepIndex
|
|
436
439
|
})));
|
|
440
|
+
contentChanges = changeset.changes;
|
|
437
441
|
attributedChanges = diffType === 'step' ? diffBySteps(originalDoc, simplifiedSteps, simplifiedStepAttributions) : [...changeset.changes];
|
|
438
442
|
// The attributed pipeline gives no guarantee that its output ranges are disjoint — see
|
|
439
443
|
// `collapseOverlappingChanges`.
|
|
@@ -453,6 +457,7 @@ const calculateDiffDecorationsInner = ({
|
|
|
453
457
|
}
|
|
454
458
|
} else {
|
|
455
459
|
const changeset = ChangeSet.create(originalDoc, undefined, tokenEncoder).addSteps(steppedDoc, stepMaps, tr.doc);
|
|
460
|
+
contentChanges = changeset.changes;
|
|
456
461
|
changes = getChanges({
|
|
457
462
|
changeset,
|
|
458
463
|
originalDoc,
|
|
@@ -686,17 +691,38 @@ const calculateDiffDecorationsInner = ({
|
|
|
686
691
|
changes.forEach(change => {
|
|
687
692
|
createDecorationsForChange(change);
|
|
688
693
|
});
|
|
689
|
-
//
|
|
690
|
-
//
|
|
691
|
-
//
|
|
692
|
-
|
|
693
|
-
getMarkChangeRanges(simplifiedSteps, simplifiedStepAttributions, fg('confluence_ncs_step_diffing_version_history') ? stepMaps : undefined).filter(({
|
|
694
|
+
// Compare the content outside replacement ranges at matching positions in both documents.
|
|
695
|
+
// This preserves real formatting edits without highlighting an unchanged link mark reapplied
|
|
696
|
+
// while editing its display text.
|
|
697
|
+
const hasUnhighlightedMarkChanges = ({
|
|
694
698
|
fromB,
|
|
695
699
|
toB
|
|
696
|
-
}) =>
|
|
700
|
+
}) => {
|
|
701
|
+
let from = fromB;
|
|
702
|
+
let offset = 0;
|
|
703
|
+
const differs = to => from < to && !originalDoc.slice(from + offset, to + offset).content.eq(tr.doc.slice(from, to).content);
|
|
704
|
+
for (const change of contentChanges) {
|
|
705
|
+
if (change.fromB >= toB) {
|
|
706
|
+
break;
|
|
707
|
+
}
|
|
708
|
+
if (change.toB > from) {
|
|
709
|
+
if (differs(change.fromB)) {
|
|
710
|
+
return true;
|
|
711
|
+
}
|
|
712
|
+
from = change.toB;
|
|
713
|
+
}
|
|
714
|
+
offset = change.toA - change.toB;
|
|
715
|
+
}
|
|
716
|
+
return differs(toB);
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
// The attribute-aware token encoder already reports mark-only changes as regular changes in the
|
|
720
|
+
// smart path and the NCS version-history path. For NCS version history, only skip the step-range
|
|
721
|
+
// highlight if the main diff covers it or the remaining content has unchanged formatting.
|
|
722
|
+
getMarkChangeRanges(simplifiedSteps, simplifiedStepAttributions, fg('confluence_ncs_step_diffing_version_history') ? stepMaps : undefined).filter(({
|
|
697
723
|
fromB,
|
|
698
724
|
toB
|
|
699
|
-
}) => !fg('confluence_ncs_step_diffing_version_history') || !changes.some(change => change.fromB
|
|
725
|
+
}) => !isHandledByTable(fromB, toB)).filter(range => !fg('confluence_ncs_step_diffing_version_history') || !changes.some(change => change.fromB <= range.fromB && change.toB >= range.toB) && hasUnhighlightedMarkChanges(range)).forEach(change => {
|
|
700
726
|
var _attributionColors$ge, _attributionColors;
|
|
701
727
|
const changeColorScheme = change.attributionKey ? (_attributionColors$ge = (_attributionColors = attributionColors) === null || _attributionColors === void 0 ? void 0 : _attributionColors.get(change.attributionKey)) !== null && _attributionColors$ge !== void 0 ? _attributionColors$ge : colorScheme : colorScheme;
|
|
702
728
|
const attributionKey = showContributorTags ? change.attributionKey : undefined;
|
|
@@ -718,8 +744,9 @@ const calculateDiffDecorationsInner = ({
|
|
|
718
744
|
toB
|
|
719
745
|
}) => !isHandledByTable(fromB, toB)).filter(({
|
|
720
746
|
fromB,
|
|
721
|
-
toB
|
|
722
|
-
|
|
747
|
+
toB,
|
|
748
|
+
isInline
|
|
749
|
+
}) => !fg('confluence_ncs_step_diffing_version_history') || !isInline || !changes.some(change => change.fromB === fromB && change.toB === toB)).forEach(change => {
|
|
723
750
|
var _attributionColors$ge2, _attributionColors2;
|
|
724
751
|
const changeColorScheme = change.attributionKey ? (_attributionColors$ge2 = (_attributionColors2 = attributionColors) === null || _attributionColors2 === void 0 ? void 0 : _attributionColors2.get(change.attributionKey)) !== null && _attributionColors$ge2 !== void 0 ? _attributionColors$ge2 : colorScheme : colorScheme;
|
|
725
752
|
const attributionKey = showContributorTags ? change.attributionKey : undefined;
|
|
@@ -15,7 +15,8 @@ const typeID = type => {
|
|
|
15
15
|
*
|
|
16
16
|
* Deliberately narrower than `attrAwareTokenEncoder`: node-start tokens keep the library default
|
|
17
17
|
* and do not fold in diffable attributes, which `getAttrChangeRanges` already reports for every
|
|
18
|
-
* diff type.
|
|
18
|
+
* diff type. The NCS version-history path also uses `attrAwareTokenEncoder` so main diff calculation
|
|
19
|
+
* detects attribute-only node replacements.
|
|
19
20
|
*/
|
|
20
21
|
export const markAwareTokenEncoder = {
|
|
21
22
|
encodeCharacter: (char, marks) => encodeCharacterWithMarks(char, marks),
|
|
@@ -5,7 +5,7 @@ import { markAwareTokenEncoder } from './markAwareTokenEncoder';
|
|
|
5
5
|
* `computeDiffChanges` so the two cannot drift.
|
|
6
6
|
*
|
|
7
7
|
* @param useAttrAwareEncoder Caller is running the smart classifier, which needs node attrs folded
|
|
8
|
-
* into the token.
|
|
8
|
+
* into the token. Also used by the NCS version-history path to detect attribute-only node changes.
|
|
9
9
|
*/
|
|
10
10
|
export const selectTokenEncoder = useAttrAwareEncoder => {
|
|
11
11
|
if (useAttrAwareEncoder) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Single source of truth for which attributes of a node type represent a
|
|
3
5
|
* meaningful change. Shared by `attrAwareTokenEncoder` (changeset detection)
|
|
@@ -88,9 +90,12 @@ export const getRequiredIncludedDiffableAttrs = nodeTypeName => {
|
|
|
88
90
|
* order is not stable across the two diffed documents.
|
|
89
91
|
*/
|
|
90
92
|
export const getDiffableAttrNames = (nodeTypeName, attrs) => {
|
|
93
|
+
// Adding a column updates existing widths, ignore this attribute change. Move this into
|
|
94
|
+
// DIFFABLE_ATTRS_BY_NODE_TYPE when cleaning up confluence_ncs_step_diffing_version_history
|
|
95
|
+
const ignoreColumnWidth = nodeTypeName === 'layoutColumn' && fg('confluence_ncs_step_diffing_version_history');
|
|
91
96
|
const rule = DIFFABLE_ATTRS_BY_NODE_TYPE[nodeTypeName];
|
|
92
97
|
if (!rule) {
|
|
93
|
-
return Object.keys(attrs).filter(name => !DEFAULT_EXCLUDED_ATTRS.includes(name)).sort();
|
|
98
|
+
return Object.keys(attrs).filter(name => !DEFAULT_EXCLUDED_ATTRS.includes(name) && !(ignoreColumnWidth && name === 'width')).sort();
|
|
94
99
|
}
|
|
95
100
|
if ('include' in rule) {
|
|
96
101
|
return rule.include;
|
|
@@ -74,6 +74,7 @@ export const getAttrChangeRanges = (doc, attrStepContexts, originalDoc) => {
|
|
|
74
74
|
const $pos = doc.resolve(finalPos);
|
|
75
75
|
const nodeAtPos = doc.nodeAt(finalPos);
|
|
76
76
|
const originalNodeAtPos = originalPos === undefined ? null : originalDoc.nodeAt(originalPos);
|
|
77
|
+
const hasChangedAttr = watchedAttrs => attrsToCheck.some(attr => watchedAttrs.includes(attr) && (!fg('confluence_ncs_step_diffing_version_history') || !originalNodeAtPos || originalNodeAtPos.type !== (nodeAtPos === null || nodeAtPos === void 0 ? void 0 : nodeAtPos.type) || !isEqual(originalNodeAtPos.attrs[attr], nodeAtPos === null || nodeAtPos === void 0 ? void 0 : nodeAtPos.attrs[attr])));
|
|
77
78
|
|
|
78
79
|
// The changeset path (createDecorationsForChange) handles the deletion widget via
|
|
79
80
|
// prosemirror-changeset; we only need to add the inline insertion highlight here.
|
|
@@ -81,7 +82,7 @@ export const getAttrChangeRanges = (doc, attrStepContexts, originalDoc) => {
|
|
|
81
82
|
const nodeName = nodeAtPos.type.name;
|
|
82
83
|
if (isInlineAttrChangeNodeName(nodeName)) {
|
|
83
84
|
const watchedAttrs = inlineNodeAttrMap[nodeName];
|
|
84
|
-
if (
|
|
85
|
+
if (hasChangedAttr(watchedAttrs)) {
|
|
85
86
|
return {
|
|
86
87
|
...(attributionKey ? {
|
|
87
88
|
attributionKey
|
|
@@ -114,7 +115,7 @@ export const getAttrChangeRanges = (doc, attrStepContexts, originalDoc) => {
|
|
|
114
115
|
// (e.g. note -> warning) — highlight the new panel and, when the original node
|
|
115
116
|
// is resolvable, expose its range (fromA/toA) so the caller can render the old
|
|
116
117
|
// panel as a "deleted" widget for a before/after comparison.
|
|
117
|
-
if (
|
|
118
|
+
if (hasChangedAttr(panelAttrs) && nodeAtPos && getBaseNodeTypeName(nodeAtPos.type) === 'panel') {
|
|
118
119
|
return {
|
|
119
120
|
...(attributionKey ? {
|
|
120
121
|
attributionKey
|
|
@@ -161,7 +162,7 @@ export const getAttrChangeRanges = (doc, attrStepContexts, originalDoc) => {
|
|
|
161
162
|
// Deduplicate by node position: multiple AttrSteps on the same node
|
|
162
163
|
// (e.g. setNodeAttribute(pos, 'text', ...) + setNodeAttribute(pos, 'color', ...))
|
|
163
164
|
// should produce only one decoration, not one per step.
|
|
164
|
-
.filter((range, i, arr) => arr.findIndex(r => r.fromB === range.fromB) === i);
|
|
165
|
+
.filter((range, i, arr) => fg('confluence_ncs_step_diffing_version_history') ? !arr.some((r, nextIndex) => nextIndex > i && r.fromB === range.fromB) : arr.findIndex(r => r.fromB === range.fromB) === i);
|
|
165
166
|
};
|
|
166
167
|
|
|
167
168
|
/**
|
|
@@ -457,11 +457,14 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
|
|
|
457
457
|
};
|
|
458
458
|
}
|
|
459
459
|
}
|
|
460
|
-
// The attribute-aware encoder is
|
|
461
|
-
|
|
460
|
+
// The attribute-aware encoder is needed by the smart classifier and is gated with it.
|
|
461
|
+
// The NCS version-history path also uses it so the main diff calculation detects attribute-only
|
|
462
|
+
// node replacements, e.g. changing an emoji or mention without changing the node type.
|
|
463
|
+
var _selectTokenEncoder = selectTokenEncoder(diffType === 'smart' && fg('platform_editor_ai_smart_diff') || fg('confluence_ncs_step_diffing_version_history')),
|
|
462
464
|
tokenEncoder = _selectTokenEncoder.tokenEncoder,
|
|
463
465
|
shouldHideMarkOnlyDeletions = _selectTokenEncoder.shouldHideMarkOnlyDeletions;
|
|
464
466
|
var changes;
|
|
467
|
+
var contentChanges;
|
|
465
468
|
var attributedChanges = [];
|
|
466
469
|
var attributionColors;
|
|
467
470
|
if (attributedChangesetEnabled) {
|
|
@@ -475,6 +478,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
|
|
|
475
478
|
stepIndex: stepIndex
|
|
476
479
|
});
|
|
477
480
|
}));
|
|
481
|
+
contentChanges = changeset.changes;
|
|
478
482
|
attributedChanges = diffType === 'step' ? diffBySteps(originalDoc, simplifiedSteps, simplifiedStepAttributions) : _toConsumableArray(changeset.changes);
|
|
479
483
|
// The attributed pipeline gives no guarantee that its output ranges are disjoint — see
|
|
480
484
|
// `collapseOverlappingChanges`.
|
|
@@ -494,6 +498,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
|
|
|
494
498
|
}
|
|
495
499
|
} else {
|
|
496
500
|
var _changeset = ChangeSet.create(originalDoc, undefined, tokenEncoder).addSteps(steppedDoc, stepMaps, tr.doc);
|
|
501
|
+
contentChanges = _changeset.changes;
|
|
497
502
|
changes = getChanges({
|
|
498
503
|
changeset: _changeset,
|
|
499
504
|
originalDoc: originalDoc,
|
|
@@ -753,20 +758,52 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
|
|
|
753
758
|
changes.forEach(function (change) {
|
|
754
759
|
createDecorationsForChange(change);
|
|
755
760
|
});
|
|
756
|
-
//
|
|
757
|
-
//
|
|
758
|
-
//
|
|
759
|
-
|
|
760
|
-
getMarkChangeRanges(simplifiedSteps, simplifiedStepAttributions, fg('confluence_ncs_step_diffing_version_history') ? stepMaps : undefined).filter(function (_ref10) {
|
|
761
|
+
// Compare the content outside replacement ranges at matching positions in both documents.
|
|
762
|
+
// This preserves real formatting edits without highlighting an unchanged link mark reapplied
|
|
763
|
+
// while editing its display text.
|
|
764
|
+
var hasUnhighlightedMarkChanges = function hasUnhighlightedMarkChanges(_ref10) {
|
|
761
765
|
var fromB = _ref10.fromB,
|
|
762
766
|
toB = _ref10.toB;
|
|
763
|
-
|
|
764
|
-
|
|
767
|
+
var from = fromB;
|
|
768
|
+
var offset = 0;
|
|
769
|
+
var differs = function differs(to) {
|
|
770
|
+
return from < to && !originalDoc.slice(from + offset, to + offset).content.eq(tr.doc.slice(from, to).content);
|
|
771
|
+
};
|
|
772
|
+
var _iterator5 = _createForOfIteratorHelper(contentChanges),
|
|
773
|
+
_step5;
|
|
774
|
+
try {
|
|
775
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
776
|
+
var change = _step5.value;
|
|
777
|
+
if (change.fromB >= toB) {
|
|
778
|
+
break;
|
|
779
|
+
}
|
|
780
|
+
if (change.toB > from) {
|
|
781
|
+
if (differs(change.fromB)) {
|
|
782
|
+
return true;
|
|
783
|
+
}
|
|
784
|
+
from = change.toB;
|
|
785
|
+
}
|
|
786
|
+
offset = change.toA - change.toB;
|
|
787
|
+
}
|
|
788
|
+
} catch (err) {
|
|
789
|
+
_iterator5.e(err);
|
|
790
|
+
} finally {
|
|
791
|
+
_iterator5.f();
|
|
792
|
+
}
|
|
793
|
+
return differs(toB);
|
|
794
|
+
};
|
|
795
|
+
|
|
796
|
+
// The attribute-aware token encoder already reports mark-only changes as regular changes in the
|
|
797
|
+
// smart path and the NCS version-history path. For NCS version history, only skip the step-range
|
|
798
|
+
// highlight if the main diff covers it or the remaining content has unchanged formatting.
|
|
799
|
+
getMarkChangeRanges(simplifiedSteps, simplifiedStepAttributions, fg('confluence_ncs_step_diffing_version_history') ? stepMaps : undefined).filter(function (_ref11) {
|
|
765
800
|
var fromB = _ref11.fromB,
|
|
766
801
|
toB = _ref11.toB;
|
|
802
|
+
return !isHandledByTable(fromB, toB);
|
|
803
|
+
}).filter(function (range) {
|
|
767
804
|
return !fg('confluence_ncs_step_diffing_version_history') || !changes.some(function (change) {
|
|
768
|
-
return change.fromB
|
|
769
|
-
});
|
|
805
|
+
return change.fromB <= range.fromB && change.toB >= range.toB;
|
|
806
|
+
}) && hasUnhighlightedMarkChanges(range);
|
|
770
807
|
}).forEach(function (change) {
|
|
771
808
|
var _attributionColors$ge, _attributionColors;
|
|
772
809
|
var changeColorScheme = change.attributionKey ? (_attributionColors$ge = (_attributionColors = attributionColors) === null || _attributionColors === void 0 ? void 0 : _attributionColors.get(change.attributionKey)) !== null && _attributionColors$ge !== void 0 ? _attributionColors$ge : colorScheme : colorScheme;
|
|
@@ -790,8 +827,9 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
|
|
|
790
827
|
return !isHandledByTable(fromB, toB);
|
|
791
828
|
}).filter(function (_ref13) {
|
|
792
829
|
var fromB = _ref13.fromB,
|
|
793
|
-
toB = _ref13.toB
|
|
794
|
-
|
|
830
|
+
toB = _ref13.toB,
|
|
831
|
+
isInline = _ref13.isInline;
|
|
832
|
+
return !fg('confluence_ncs_step_diffing_version_history') || !isInline || !changes.some(function (change) {
|
|
795
833
|
return change.fromB === fromB && change.toB === toB;
|
|
796
834
|
});
|
|
797
835
|
}).forEach(function (change) {
|
|
@@ -15,7 +15,8 @@ var typeID = function typeID(type) {
|
|
|
15
15
|
*
|
|
16
16
|
* Deliberately narrower than `attrAwareTokenEncoder`: node-start tokens keep the library default
|
|
17
17
|
* and do not fold in diffable attributes, which `getAttrChangeRanges` already reports for every
|
|
18
|
-
* diff type.
|
|
18
|
+
* diff type. The NCS version-history path also uses `attrAwareTokenEncoder` so main diff calculation
|
|
19
|
+
* detects attribute-only node replacements.
|
|
19
20
|
*/
|
|
20
21
|
export var markAwareTokenEncoder = {
|
|
21
22
|
encodeCharacter: function encodeCharacter(char, marks) {
|
|
@@ -5,7 +5,7 @@ import { markAwareTokenEncoder } from './markAwareTokenEncoder';
|
|
|
5
5
|
* `computeDiffChanges` so the two cannot drift.
|
|
6
6
|
*
|
|
7
7
|
* @param useAttrAwareEncoder Caller is running the smart classifier, which needs node attrs folded
|
|
8
|
-
* into the token.
|
|
8
|
+
* into the token. Also used by the NCS version-history path to detect attribute-only node changes.
|
|
9
9
|
*/
|
|
10
10
|
export var selectTokenEncoder = function selectTokenEncoder(useAttrAwareEncoder) {
|
|
11
11
|
if (useAttrAwareEncoder) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Single source of truth for which attributes of a node type represent a
|
|
3
5
|
* meaningful change. Shared by `attrAwareTokenEncoder` (changeset detection)
|
|
@@ -88,10 +90,13 @@ export var getRequiredIncludedDiffableAttrs = function getRequiredIncludedDiffab
|
|
|
88
90
|
* order is not stable across the two diffed documents.
|
|
89
91
|
*/
|
|
90
92
|
export var getDiffableAttrNames = function getDiffableAttrNames(nodeTypeName, attrs) {
|
|
93
|
+
// Adding a column updates existing widths, ignore this attribute change. Move this into
|
|
94
|
+
// DIFFABLE_ATTRS_BY_NODE_TYPE when cleaning up confluence_ncs_step_diffing_version_history
|
|
95
|
+
var ignoreColumnWidth = nodeTypeName === 'layoutColumn' && fg('confluence_ncs_step_diffing_version_history');
|
|
91
96
|
var rule = DIFFABLE_ATTRS_BY_NODE_TYPE[nodeTypeName];
|
|
92
97
|
if (!rule) {
|
|
93
98
|
return Object.keys(attrs).filter(function (name) {
|
|
94
|
-
return !DEFAULT_EXCLUDED_ATTRS.includes(name);
|
|
99
|
+
return !DEFAULT_EXCLUDED_ATTRS.includes(name) && !(ignoreColumnWidth && name === 'width');
|
|
95
100
|
}).sort();
|
|
96
101
|
}
|
|
97
102
|
if ('include' in rule) {
|
|
@@ -83,6 +83,11 @@ export var getAttrChangeRanges = function getAttrChangeRanges(doc, attrStepConte
|
|
|
83
83
|
var $pos = doc.resolve(finalPos);
|
|
84
84
|
var nodeAtPos = doc.nodeAt(finalPos);
|
|
85
85
|
var originalNodeAtPos = originalPos === undefined ? null : originalDoc.nodeAt(originalPos);
|
|
86
|
+
var hasChangedAttr = function hasChangedAttr(watchedAttrs) {
|
|
87
|
+
return attrsToCheck.some(function (attr) {
|
|
88
|
+
return watchedAttrs.includes(attr) && (!fg('confluence_ncs_step_diffing_version_history') || !originalNodeAtPos || originalNodeAtPos.type !== (nodeAtPos === null || nodeAtPos === void 0 ? void 0 : nodeAtPos.type) || !isEqual(originalNodeAtPos.attrs[attr], nodeAtPos === null || nodeAtPos === void 0 ? void 0 : nodeAtPos.attrs[attr]));
|
|
89
|
+
});
|
|
90
|
+
};
|
|
86
91
|
|
|
87
92
|
// The changeset path (createDecorationsForChange) handles the deletion widget via
|
|
88
93
|
// prosemirror-changeset; we only need to add the inline insertion highlight here.
|
|
@@ -90,9 +95,7 @@ export var getAttrChangeRanges = function getAttrChangeRanges(doc, attrStepConte
|
|
|
90
95
|
var nodeName = nodeAtPos.type.name;
|
|
91
96
|
if (isInlineAttrChangeNodeName(nodeName)) {
|
|
92
97
|
var watchedAttrs = inlineNodeAttrMap[nodeName];
|
|
93
|
-
if (
|
|
94
|
-
return watchedAttrs.includes(v);
|
|
95
|
-
})) {
|
|
98
|
+
if (hasChangedAttr(watchedAttrs)) {
|
|
96
99
|
return _objectSpread(_objectSpread({}, attributionKey ? {
|
|
97
100
|
attributionKey: attributionKey
|
|
98
101
|
} : {}), {}, {
|
|
@@ -124,9 +127,7 @@ export var getAttrChangeRanges = function getAttrChangeRanges(doc, attrStepConte
|
|
|
124
127
|
// (e.g. note -> warning) — highlight the new panel and, when the original node
|
|
125
128
|
// is resolvable, expose its range (fromA/toA) so the caller can render the old
|
|
126
129
|
// panel as a "deleted" widget for a before/after comparison.
|
|
127
|
-
if (
|
|
128
|
-
return panelAttrs.includes(v);
|
|
129
|
-
}) && nodeAtPos && getBaseNodeTypeName(nodeAtPos.type) === 'panel') {
|
|
130
|
+
if (hasChangedAttr(panelAttrs) && nodeAtPos && getBaseNodeTypeName(nodeAtPos.type) === 'panel') {
|
|
130
131
|
return _objectSpread(_objectSpread({}, attributionKey ? {
|
|
131
132
|
attributionKey: attributionKey
|
|
132
133
|
} : {}), {}, {
|
|
@@ -174,7 +175,9 @@ export var getAttrChangeRanges = function getAttrChangeRanges(doc, attrStepConte
|
|
|
174
175
|
// (e.g. setNodeAttribute(pos, 'text', ...) + setNodeAttribute(pos, 'color', ...))
|
|
175
176
|
// should produce only one decoration, not one per step.
|
|
176
177
|
.filter(function (range, i, arr) {
|
|
177
|
-
return arr.
|
|
178
|
+
return fg('confluence_ncs_step_diffing_version_history') ? !arr.some(function (r, nextIndex) {
|
|
179
|
+
return nextIndex > i && r.fromB === range.fromB;
|
|
180
|
+
}) : arr.findIndex(function (r) {
|
|
178
181
|
return r.fromB === range.fromB;
|
|
179
182
|
}) === i;
|
|
180
183
|
});
|
|
@@ -4,6 +4,7 @@ import type { TokenEncoder } from 'prosemirror-changeset';
|
|
|
4
4
|
*
|
|
5
5
|
* Deliberately narrower than `attrAwareTokenEncoder`: node-start tokens keep the library default
|
|
6
6
|
* and do not fold in diffable attributes, which `getAttrChangeRanges` already reports for every
|
|
7
|
-
* diff type.
|
|
7
|
+
* diff type. The NCS version-history path also uses `attrAwareTokenEncoder` so main diff calculation
|
|
8
|
+
* detects attribute-only node replacements.
|
|
8
9
|
*/
|
|
9
10
|
export declare const markAwareTokenEncoder: TokenEncoder<string | number>;
|
|
@@ -10,6 +10,6 @@ export type TokenEncoderSelection = {
|
|
|
10
10
|
* `computeDiffChanges` so the two cannot drift.
|
|
11
11
|
*
|
|
12
12
|
* @param useAttrAwareEncoder Caller is running the smart classifier, which needs node attrs folded
|
|
13
|
-
* into the token.
|
|
13
|
+
* into the token. Also used by the NCS version-history path to detect attribute-only node changes.
|
|
14
14
|
*/
|
|
15
15
|
export declare const selectTokenEncoder: (useAttrAwareEncoder: boolean) => TokenEncoderSelection;
|