@atlaskit/editor-plugin-show-diff 14.0.4 → 14.1.1

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 (60) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +215 -103
  3. package/dist/cjs/pm-plugins/calculateDiff/diffBySteps.js +20 -9
  4. package/dist/cjs/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +89 -0
  5. package/dist/cjs/pm-plugins/calculateDiff/simplifySteps.js +81 -4
  6. package/dist/cjs/pm-plugins/decorations/colorSchemes/attributions.js +68 -0
  7. package/dist/cjs/pm-plugins/decorations/colorSchemes/schemes.js +26 -2
  8. package/dist/cjs/pm-plugins/decorations/colorSchemes/types.js +5 -1
  9. package/dist/cjs/pm-plugins/decorations/createBlockChangedDecoration.js +7 -2
  10. package/dist/cjs/pm-plugins/decorations/createChangedRowDecorationWidgets.js +2 -2
  11. package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +4 -2
  12. package/dist/cjs/pm-plugins/decorations/utils/getAttrChangeRanges.js +59 -30
  13. package/dist/cjs/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +14 -10
  14. package/dist/cjs/pm-plugins/main.js +1 -0
  15. package/dist/cjs/showDiffPlugin.js +36 -14
  16. package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +130 -22
  17. package/dist/es2019/pm-plugins/calculateDiff/diffBySteps.js +17 -9
  18. package/dist/es2019/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +64 -0
  19. package/dist/es2019/pm-plugins/calculateDiff/simplifySteps.js +64 -1
  20. package/dist/es2019/pm-plugins/decorations/colorSchemes/attributions.js +37 -0
  21. package/dist/es2019/pm-plugins/decorations/colorSchemes/schemes.js +19 -2
  22. package/dist/es2019/pm-plugins/decorations/colorSchemes/types.js +1 -0
  23. package/dist/es2019/pm-plugins/decorations/createBlockChangedDecoration.js +6 -3
  24. package/dist/es2019/pm-plugins/decorations/createChangedRowDecorationWidgets.js +3 -3
  25. package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +6 -3
  26. package/dist/es2019/pm-plugins/decorations/utils/getAttrChangeRanges.js +55 -30
  27. package/dist/es2019/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +12 -9
  28. package/dist/es2019/pm-plugins/main.js +1 -0
  29. package/dist/es2019/showDiffPlugin.js +23 -1
  30. package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +216 -104
  31. package/dist/esm/pm-plugins/calculateDiff/diffBySteps.js +20 -9
  32. package/dist/esm/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +82 -0
  33. package/dist/esm/pm-plugins/calculateDiff/simplifySteps.js +79 -5
  34. package/dist/esm/pm-plugins/decorations/colorSchemes/attributions.js +61 -0
  35. package/dist/esm/pm-plugins/decorations/colorSchemes/schemes.js +24 -1
  36. package/dist/esm/pm-plugins/decorations/colorSchemes/types.js +1 -0
  37. package/dist/esm/pm-plugins/decorations/createBlockChangedDecoration.js +8 -3
  38. package/dist/esm/pm-plugins/decorations/createChangedRowDecorationWidgets.js +3 -3
  39. package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +5 -3
  40. package/dist/esm/pm-plugins/decorations/utils/getAttrChangeRanges.js +59 -30
  41. package/dist/esm/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +14 -9
  42. package/dist/esm/pm-plugins/main.js +1 -0
  43. package/dist/esm/showDiffPlugin.js +36 -14
  44. package/dist/types/entry-points/show-diff-plugin-type.d.ts +1 -1
  45. package/dist/types/pm-plugins/calculateDiff/diffBySteps.d.ts +2 -1
  46. package/dist/types/pm-plugins/calculateDiff/simplifyChangesWithAttribution.d.ts +7 -0
  47. package/dist/types/pm-plugins/calculateDiff/simplifySteps.d.ts +10 -0
  48. package/dist/types/pm-plugins/decorations/colorSchemes/attributions.d.ts +12 -0
  49. package/dist/types/pm-plugins/decorations/colorSchemes/schemes.d.ts +5 -3
  50. package/dist/types/pm-plugins/decorations/colorSchemes/types.d.ts +6 -1
  51. package/dist/types/pm-plugins/decorations/createBlockChangedDecoration.d.ts +2 -1
  52. package/dist/types/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +2 -1
  53. package/dist/types/pm-plugins/decorations/createInlineChangedDecoration.d.ts +2 -1
  54. package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +2 -1
  55. package/dist/types/pm-plugins/decorations/utils/getAttrChangeRanges.d.ts +12 -2
  56. package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +2 -1
  57. package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.d.ts +2 -1
  58. package/dist/types/pm-plugins/main.d.ts +3 -1
  59. package/dist/types/showDiffPluginType.d.ts +29 -1
  60. package/package.json +10 -7
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.simplifyChangesWithAttribution = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _prosemirrorChangeset = require("prosemirror-changeset");
11
+ var _attributions = require("../decorations/colorSchemes/attributions");
12
+ var _optimizeChanges = require("./optimizeChanges");
13
+ 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; } } }; }
14
+ 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; } }
15
+ 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; }
16
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
+ var getAttributionIdentity = function getAttributionIdentity(change) {
19
+ var identities = new Set();
20
+ for (var _i = 0, _arr = [].concat((0, _toConsumableArray2.default)(change.deleted), (0, _toConsumableArray2.default)(change.inserted)); _i < _arr.length; _i++) {
21
+ var span = _arr[_i];
22
+ identities.add((0, _attributions.getAttributionKey)(span.data));
23
+ }
24
+ if (identities.size > 1) {
25
+ return {
26
+ key: undefined,
27
+ mergeable: false
28
+ };
29
+ }
30
+ return {
31
+ key: identities.values().next().value,
32
+ mergeable: true
33
+ };
34
+ };
35
+
36
+ /**
37
+ * Simplifies and optimizes consecutive changes without crossing an attribution boundary.
38
+ * A change which already contains more than one identity is deliberately kept isolated.
39
+ */
40
+ var simplifyChangesWithAttribution = exports.simplifyChangesWithAttribution = function simplifyChangesWithAttribution(changes, doc) {
41
+ var result = [];
42
+ var run = [];
43
+ var runIdentity;
44
+ var flush = function flush() {
45
+ if (run.length > 0) {
46
+ // Some show-diff producers use structurally compatible Change objects rather than the
47
+ // library class. `simplifyChanges` reads runtime `lenA`/`lenB` getters even though they
48
+ // are intentionally omitted from its public declarations, so add equivalent getters
49
+ // without calling the library's internal constructor.
50
+ var normalizedRun = run.map(function (change) {
51
+ return _objectSpread(_objectSpread({}, change), {}, {
52
+ get lenA() {
53
+ return change.toA - change.fromA;
54
+ },
55
+ get lenB() {
56
+ return change.toB - change.fromB;
57
+ }
58
+ });
59
+ });
60
+ result.push.apply(result, (0, _toConsumableArray2.default)((0, _optimizeChanges.optimizeChanges)((0, _prosemirrorChangeset.simplifyChanges)(normalizedRun, doc))));
61
+ }
62
+ run = [];
63
+ runIdentity = undefined;
64
+ };
65
+ var _iterator = _createForOfIteratorHelper(changes),
66
+ _step;
67
+ try {
68
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
69
+ var _runIdentity;
70
+ var change = _step.value;
71
+ var identity = getAttributionIdentity(change);
72
+ var canJoinRun = ((_runIdentity = runIdentity) === null || _runIdentity === void 0 ? void 0 : _runIdentity.mergeable) === true && identity.mergeable && runIdentity.key === identity.key;
73
+ if (run.length > 0 && !canJoinRun) {
74
+ flush();
75
+ }
76
+ run.push(change);
77
+ runIdentity = identity;
78
+ if (!identity.mergeable) {
79
+ flush();
80
+ }
81
+ }
82
+ } catch (err) {
83
+ _iterator.e(err);
84
+ } finally {
85
+ _iterator.f();
86
+ }
87
+ flush();
88
+ return result;
89
+ };
@@ -1,15 +1,21 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.simplifySteps = simplifySteps;
8
+ exports.simplifyStepsWithAttribution = simplifyStepsWithAttribution;
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
7
10
  var _steps = require("@atlaskit/adf-schema/steps");
8
11
  var _document = require("@atlaskit/editor-common/utils/document");
9
12
  var _transform = require("@atlaskit/editor-prosemirror/transform");
13
+ var _attributions = require("../decorations/colorSchemes/attributions");
10
14
  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; } } }; }
11
15
  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; } }
12
16
  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; }
17
+ 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; }
18
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
19
  /**
14
20
  * Attempts to merge two consecutive ReplaceStep operations.
15
21
  * This merges steps where:
@@ -51,21 +57,67 @@ function simplifySteps(steps, originalDoc) {
51
57
  return acc;
52
58
  }, []);
53
59
  }
60
+ var mergeAttributions = function mergeAttributions(first, second) {
61
+ var _second$wasOffline;
62
+ if (!first) {
63
+ return second;
64
+ }
65
+ if (!second) {
66
+ return first;
67
+ }
68
+ return _objectSpread(_objectSpread(_objectSpread({}, first), second), {}, {
69
+ wasOffline: first.wasOffline === true || second.wasOffline === true ? true : (_second$wasOffline = second.wasOffline) !== null && _second$wasOffline !== void 0 ? _second$wasOffline : first.wasOffline
70
+ });
71
+ };
72
+
73
+ /**
74
+ * Attribution-preserving variant of `simplifySteps`.
75
+ *
76
+ * Steps may only merge when they have the same effective actor identity. Keeping the attribution
77
+ * coupled to the step also ensures filtering a no-op/analytics step cannot shift array indexes.
78
+ */
79
+ function simplifyStepsWithAttribution(steps, stepAttributions, originalDoc) {
80
+ var stepsToFilter = removeUnusedAttributedSteps(steps.map(function (step, index) {
81
+ return {
82
+ step: step,
83
+ stepAttribution: stepAttributions[index]
84
+ };
85
+ }), originalDoc);
86
+ return stepsToFilter.filter(function (_ref) {
87
+ var step = _ref.step;
88
+ return !(step instanceof _steps.AnalyticsStep);
89
+ }).reduce(function (acc, current) {
90
+ var _previous$step$merge, _previous$step$merge2, _previous$step;
91
+ var previous = acc[acc.length - 1];
92
+ var isSameIdentity = previous && (0, _attributions.getAttributionKey)(previous.stepAttribution) === (0, _attributions.getAttributionKey)(current.stepAttribution);
93
+ var merged = isSameIdentity ? (_previous$step$merge = (_previous$step$merge2 = (_previous$step = previous.step).merge) === null || _previous$step$merge2 === void 0 ? void 0 : _previous$step$merge2.call(_previous$step, current.step)) !== null && _previous$step$merge !== void 0 ? _previous$step$merge : mergeReplaceSteps(previous.step, current.step) : null;
94
+ if (merged) {
95
+ acc[acc.length - 1] = {
96
+ step: merged,
97
+ stepAttribution: mergeAttributions(previous.stepAttribution, current.stepAttribution)
98
+ };
99
+ } else {
100
+ acc.push(current);
101
+ }
102
+ return acc;
103
+ }, []);
104
+ }
54
105
 
55
106
  /**
56
107
  * Does a first pass to remove steps that don't impact the document
57
108
  */
58
- function removeUnusedSteps(steps, originalDoc) {
109
+ function removeUnusedAttributedSteps(stepsWithAttribution, originalDoc) {
59
110
  var finalSteps = [];
60
111
  var firstPassDoc = originalDoc;
61
- var _iterator = _createForOfIteratorHelper(steps),
112
+ var _iterator = _createForOfIteratorHelper(stepsWithAttribution),
62
113
  _step;
63
114
  try {
64
115
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
65
- var step = _step.value;
116
+ var stepWithAttribution = _step.value;
117
+ var step = stepWithAttribution.step;
66
118
  var result = step.apply(firstPassDoc);
67
119
  if (result.failed === null && result.doc && !(0, _document.areNodesEqualIgnoreAttrs)(firstPassDoc, result.doc, ['localId'])) {
68
- finalSteps.push(step);
120
+ finalSteps.push(stepWithAttribution);
69
121
  firstPassDoc = result.doc;
70
122
  }
71
123
  }
@@ -75,4 +127,29 @@ function removeUnusedSteps(steps, originalDoc) {
75
127
  _iterator.f();
76
128
  }
77
129
  return finalSteps;
130
+ }
131
+
132
+ /**
133
+ * Does a first pass to remove steps that don't impact the document
134
+ */
135
+ function removeUnusedSteps(steps, originalDoc) {
136
+ var finalSteps = [];
137
+ var firstPassDoc = originalDoc;
138
+ var _iterator2 = _createForOfIteratorHelper(steps),
139
+ _step2;
140
+ try {
141
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
142
+ var step = _step2.value;
143
+ var result = step.apply(firstPassDoc);
144
+ if (result.failed === null && result.doc && !(0, _document.areNodesEqualIgnoreAttrs)(firstPassDoc, result.doc, ['localId'])) {
145
+ finalSteps.push(step);
146
+ firstPassDoc = result.doc;
147
+ }
148
+ }
149
+ } catch (err) {
150
+ _iterator2.e(err);
151
+ } finally {
152
+ _iterator2.f();
153
+ }
154
+ return finalSteps;
78
155
  }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.isAttributionColoringEnabled = exports.getColorSchemeForChange = exports.getAttributionKey = exports.createAttributionColorMap = exports.areAttributionColorGatesEnabled = void 0;
8
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
11
+ var _fg = require("@atlaskit/platform-feature-flags/fg");
12
+ var ATTRIBUTION_COLOR_PALETTE = ['purple', 'blue', 'teal', 'magenta', 'orange', 'green'];
13
+
14
+ /** `userId` is primary; `agentId`, or `agentType` as its fallback, separates shared users. */
15
+ var getAttributionKey = exports.getAttributionKey = function getAttributionKey(attribution) {
16
+ var _attribution$userId, _attribution$agentId, _attribution$agentTyp;
17
+ var userId = attribution === null || attribution === void 0 || (_attribution$userId = attribution.userId) === null || _attribution$userId === void 0 ? void 0 : _attribution$userId.trim();
18
+ var agentId = attribution === null || attribution === void 0 || (_attribution$agentId = attribution.agentId) === null || _attribution$agentId === void 0 ? void 0 : _attribution$agentId.trim();
19
+ var agentType = attribution === null || attribution === void 0 || (_attribution$agentTyp = attribution.agentType) === null || _attribution$agentTyp === void 0 ? void 0 : _attribution$agentTyp.trim();
20
+ if (!userId && !agentId && !agentType) {
21
+ return undefined;
22
+ }
23
+ var agentIdentity = agentId || (agentType ? "type:".concat(agentType) : '');
24
+ return "user:".concat(userId !== null && userId !== void 0 ? userId : '', "|agent:").concat(agentIdentity);
25
+ };
26
+ var areAttributionColorGatesEnabled = exports.areAttributionColorGatesEnabled = function areAttributionColorGatesEnabled() {
27
+ return (0, _fg.fg)('confluence_ncs_step_diffing_version_history') && (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor');
28
+ };
29
+ var isAttributionColoringEnabled = exports.isAttributionColoringEnabled = function isAttributionColoringEnabled(stepAttributions) {
30
+ return areAttributionColorGatesEnabled() && (stepAttributions === null || stepAttributions === void 0 ? void 0 : stepAttributions.some(function (attribution) {
31
+ return getAttributionKey(attribution) !== undefined;
32
+ })) === true;
33
+ };
34
+ var createAttributionColorMap = exports.createAttributionColorMap = function createAttributionColorMap(stepAttributions) {
35
+ var keys = Array.from(new Set(stepAttributions.map(getAttributionKey).filter(function (key) {
36
+ return key !== undefined;
37
+ }))).sort();
38
+ return new Map(keys.map(function (key, index) {
39
+ return [key, ATTRIBUTION_COLOR_PALETTE[index % ATTRIBUTION_COLOR_PALETTE.length]];
40
+ }));
41
+ };
42
+ var getLatestAttribution = function getLatestAttribution(changes) {
43
+ var data = changes.flatMap(function (change) {
44
+ return [].concat((0, _toConsumableArray2.default)(change.deleted), (0, _toConsumableArray2.default)(change.inserted));
45
+ }).map(function (span) {
46
+ return span.data;
47
+ }).filter(function (value) {
48
+ return (0, _typeof2.default)(value) === 'object' && value !== null && 'stepIndex' in value && typeof value.stepIndex === 'number';
49
+ });
50
+ return data.reduce(function (latest, attribution) {
51
+ return !latest || attribution.stepIndex > latest.stepIndex ? attribution : latest;
52
+ }, undefined);
53
+ };
54
+ var rangesOverlap = function rangesOverlap(fromA, toA, fromB, toB) {
55
+ return fromA < toB && fromB < toA;
56
+ };
57
+ var changesOverlap = function changesOverlap(change, attributedChange) {
58
+ var insertedOverlap = change.inserted.length > 0 && attributedChange.inserted.length > 0 && rangesOverlap(change.fromB, change.toB, attributedChange.fromB, attributedChange.toB);
59
+ var deletedOverlap = change.deleted.length > 0 && attributedChange.deleted.length > 0 && rangesOverlap(change.fromA, change.toA, attributedChange.fromA, attributedChange.toA);
60
+ return insertedOverlap || deletedOverlap;
61
+ };
62
+ var getColorSchemeForChange = exports.getColorSchemeForChange = function getColorSchemeForChange(change, attributedChanges, attributionColors, fallback) {
63
+ var _attributionColors$ge;
64
+ var key = getAttributionKey(getLatestAttribution(attributedChanges.filter(function (attributedChange) {
65
+ return changesOverlap(change, attributedChange);
66
+ })));
67
+ return key ? (_attributionColors$ge = attributionColors.get(key)) !== null && _attributionColors$ge !== void 0 ? _attributionColors$ge : fallback : fallback;
68
+ };
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports.traditionalScheme = exports.standardScheme = exports.colorSchemeRegistry = void 0;
7
+ exports.traditionalScheme = exports.standardScheme = exports.getLegacyColorScheme = exports.colorSchemeRegistry = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ 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; }
10
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
11
  /** Green insertions, red deletions. */
8
12
  var traditionalScheme = exports.traditionalScheme = {
9
13
  insertColor: 'green',
@@ -58,9 +62,29 @@ var standardScheme = exports.standardScheme = {
58
62
  deletedQuoteNodeActiveTone: 'borderAccent',
59
63
  strikesDeletedEmbedCard: false
60
64
  };
65
+ var createAttributionScheme = function createAttributionScheme(color) {
66
+ return _objectSpread(_objectSpread({}, standardScheme), {}, {
67
+ insertColor: color,
68
+ insertActiveColor: color,
69
+ deleteColor: color,
70
+ deleteActiveColor: color,
71
+ deletedCellColor: color
72
+ });
73
+ };
61
74
 
62
- /** Maps the public ColorScheme string to its data object. Adding a scheme = one entry here. */
75
+ /** Maps public schemes and attribution-only accents to their data objects. */
63
76
  var colorSchemeRegistry = exports.colorSchemeRegistry = {
77
+ blue: createAttributionScheme('blue'),
78
+ green: createAttributionScheme('green'),
79
+ magenta: createAttributionScheme('magenta'),
80
+ orange: createAttributionScheme('orange'),
81
+ purple: createAttributionScheme('purple'),
82
+ teal: createAttributionScheme('teal'),
64
83
  traditional: traditionalScheme,
65
84
  standard: standardScheme
85
+ };
86
+
87
+ /** Attribution accents are impossible in the refactor-off cohort; fall back defensively. */
88
+ var getLegacyColorScheme = exports.getLegacyColorScheme = function getLegacyColorScheme(colorScheme) {
89
+ return colorScheme === 'standard' || colorScheme === 'traditional' ? colorScheme : undefined;
66
90
  };
@@ -1 +1,5 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.createBlockChangedDecoration = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
10
  var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
10
11
  var _view = require("@atlaskit/editor-prosemirror/view");
11
12
  var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
@@ -16,6 +17,8 @@ var _schemes = require("./colorSchemes/schemes");
16
17
  var _createAnchorDecorationWidgets = require("./createAnchorDecorationWidgets");
17
18
  var _decorationKeys = require("./decorationKeys");
18
19
  var _createBlockChangedDecorationStyles = require("./createBlockChangedDecoration.styles.legacy");
20
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
21
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
19
22
  var displayNoneStyle = (0, _lazyNodeView.convertToInlineCss)({
20
23
  display: 'none'
21
24
  });
@@ -105,7 +108,9 @@ var getBlockNodeStyleNext = function getBlockNodeStyleNext(_ref) {
105
108
  * same style strings for both shipped schemes; see EDITOR-8281.
106
109
  */
107
110
  var getBlockNodeStyle = function getBlockNodeStyle(props) {
108
- return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getBlockNodeStyleNext(props) : (0, _createBlockChangedDecorationStyles.getBlockNodeStyleLegacy)(props);
111
+ return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getBlockNodeStyleNext(props) : (0, _createBlockChangedDecorationStyles.getBlockNodeStyleLegacy)(_objectSpread(_objectSpread({}, props), {}, {
112
+ colorScheme: (0, _schemes.getLegacyColorScheme)(props.colorScheme)
113
+ }));
109
114
  };
110
115
 
111
116
  /**
@@ -179,7 +184,7 @@ var createBlockChangedDecoration = exports.createBlockChangedDecoration = functi
179
184
  var isEmptyCellBeingFilled = !isInserted && !!cellNode && isCellEmpty(cellNode);
180
185
  var useAddedStyle = isInserted || isEmptyCellBeingFilled;
181
186
  var cellOverlayStyle = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? useAddedStyle ? isRoundedTable ? (0, _factory.buildAddedCellOverlayRoundedStyle)(colors) : (0, _factory.buildAddedCellOverlayStyle)(colors) : isRoundedTable ? (0, _factory.buildDeletedCellOverlayRoundedStyle)(colors) : (0, _factory.buildDeletedCellOverlayStyle)(colors) : (0, _createBlockChangedDecorationStyles.resolveCellOverlayStyleLegacy)({
182
- colorScheme: colorScheme,
187
+ colorScheme: (0, _schemes.getLegacyColorScheme)(colorScheme),
183
188
  isRoundedTable: isRoundedTable,
184
189
  useAddedStyle: useAddedStyle
185
190
  });
@@ -141,7 +141,7 @@ var createChangedRowDOM = function createChangedRowDOM(rowNode, cellEdgeAttrs, n
141
141
 
142
142
  // Inserted rows keep their natural styling; the row strikethrough is deletions only.
143
143
  if (!(0, _isExtendedEnabled.isExtendedEnabled)(diffType) || !isInserted) {
144
- tr.setAttribute('style', (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? (0, _factory.buildDeletedRowStyle)(colors) : (0, _createChangedRowDecorationWidgetsStyles.resolveDeletedRowStyleLegacy)(colorScheme));
144
+ tr.setAttribute('style', (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? (0, _factory.buildDeletedRowStyle)(colors) : (0, _createChangedRowDecorationWidgetsStyles.resolveDeletedRowStyleLegacy)((0, _schemes.getLegacyColorScheme)(colorScheme)));
145
145
  }
146
146
  tr.setAttribute('data-testid', 'show-diff-deleted-row');
147
147
 
@@ -157,7 +157,7 @@ var createChangedRowDOM = function createChangedRowDOM(rowNode, cellEdgeAttrs, n
157
157
  var overlay = document.createElement('span');
158
158
  var isRoundedTable = (0, _expValEquals.expValEquals)('platform_editor_table_diff_rounded_corners', 'isEnabled', true);
159
159
  var overlayStyle = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? isInserted ? isRoundedTable ? (0, _factory.buildAddedCellOverlayRoundedStyle)(colors) : (0, _factory.buildAddedCellOverlayStyle)(colors) : isRoundedTable ? (0, _factory.buildDeletedCellOverlayRoundedStyle)(colors) : (0, _factory.buildDeletedCellOverlayStyle)(colors) : (0, _createChangedRowDecorationWidgetsStyles.resolveCellOverlayStyleLegacy)({
160
- colorScheme: colorScheme,
160
+ colorScheme: (0, _schemes.getLegacyColorScheme)(colorScheme),
161
161
  isInserted: isInserted,
162
162
  isRoundedTable: isRoundedTable
163
163
  });
@@ -77,7 +77,9 @@ var resolveInlineChangedStyleRefactored = function resolveInlineChangedStyleRefa
77
77
  * verbatim pre-refactor per-scheme constants when it is off.
78
78
  */
79
79
  var resolveInlineChangedStyle = function resolveInlineChangedStyle(args) {
80
- return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? resolveInlineChangedStyleRefactored(args) : (0, _createInlineChangedDecorationStyles.resolveInlineChangedStyleLegacy)(args);
80
+ return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? resolveInlineChangedStyleRefactored(args) : (0, _createInlineChangedDecorationStyles.resolveInlineChangedStyleLegacy)(_objectSpread(_objectSpread({}, args), {}, {
81
+ colorScheme: (0, _schemes.getLegacyColorScheme)(args.colorScheme)
82
+ }));
81
83
  };
82
84
 
83
85
  /**
@@ -91,7 +93,7 @@ var resolveAtomicInlineAttrs = function resolveAtomicInlineAttrs(inlineNodeName,
91
93
  className: getAtomicInlineNodeClassName(inlineNodeName),
92
94
  styleSuffix: (0, _factory.buildAtomicInlineChangedCSSVariables)(colors)
93
95
  } : {
94
- className: (0, _createInlineChangedDecorationStyles.getAtomicInlineNodeClassNameLegacy)(inlineNodeName, colorScheme),
96
+ className: (0, _createInlineChangedDecorationStyles.getAtomicInlineNodeClassNameLegacy)(inlineNodeName, (0, _schemes.getLegacyColorScheme)(colorScheme)),
95
97
  styleSuffix: ''
96
98
  };
97
99
  };
@@ -6,10 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.stepIsValidAttrChange = exports.getAttrChangeRanges = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
10
+ var _omit = _interopRequireDefault(require("lodash/omit"));
9
11
  var _steps = require("@atlaskit/adf-schema/steps");
10
12
  var _deprecatedPlatformFeatureExperiments = require("@atlaskit/editor-common/deprecated-platform-feature-experiments");
11
13
  var _nodeTypeUtils = require("@atlaskit/editor-common/utils/node-type-utils");
12
14
  var _transform = require("@atlaskit/editor-prosemirror/transform");
15
+ var _fg = require("@atlaskit/platform-feature-flags/fg");
13
16
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
14
17
  var _diffableAttrs = require("./diffableAttrs");
15
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; }
@@ -41,33 +44,57 @@ var isInlineAttrChangeNodeName = function isInlineAttrChangeNodeName(nodeName) {
41
44
  // Extension node type names. Their "any attr except localId" exclude rule lives
42
45
  // in the shared `diffableAttrs` map and is applied via `isDiffableAttr` below.
43
46
  var extensionNodeNames = ['extension', 'inlineExtension', 'bodiedExtension'];
47
+ var transientExtensionAttrPaths = ['localId', 'parameters.macroParams._parentId'];
48
+
49
+ /**
50
+ * Removes extension metadata that can change between document versions without changing the
51
+ * extension's user-visible configuration.
52
+ */
53
+ var getComparableExtensionAttrs = function getComparableExtensionAttrs(node) {
54
+ return (0, _omit.default)(node.attrs, transientExtensionAttrPaths);
55
+ };
56
+ var haveSameRelevantExtensionAttrs = function haveSameRelevantExtensionAttrs(beforeNode, afterNode) {
57
+ return (0, _isEqual.default)(getComparableExtensionAttrs(beforeNode), getComparableExtensionAttrs(afterNode));
58
+ };
44
59
  var getStepAttrs = function getStepAttrs(step) {
45
60
  if (step instanceof _transform.AttrStep) {
46
61
  return [step.attr];
47
62
  }
48
- if (step instanceof _steps.SetAttrsStep && step.attrs) {
63
+ if (step.attrs) {
49
64
  return Object.keys(step.attrs);
50
65
  }
51
66
  return [];
52
67
  };
53
- var getAttrChangeRanges = exports.getAttrChangeRanges = function getAttrChangeRanges(doc, steps, originalDoc) {
54
- return steps.map(function (step) {
68
+ var getAttrChangeRanges = exports.getAttrChangeRanges = function getAttrChangeRanges(doc, attrStepContexts, originalDoc) {
69
+ return attrStepContexts.map(function (attrStepContext) {
70
+ var afterNode = attrStepContext.afterNode,
71
+ beforeNode = attrStepContext.beforeNode,
72
+ finalPos = attrStepContext.finalPos,
73
+ originalPos = attrStepContext.originalPos,
74
+ step = attrStepContext.step;
55
75
  if (!(step instanceof _transform.AttrStep) && !(step instanceof _steps.SetAttrsStep)) {
56
76
  return undefined;
57
77
  }
58
78
  var stepAttrs = getStepAttrs(step);
59
- var $pos = doc.resolve(step.pos);
60
- var nodeAtPos = doc.nodeAt(step.pos);
79
+ // SetAttrsStep contains the complete replacement attrs, not only the attrs that changed.
80
+ // Keep the legacy payload-based checks until the rollout gate is enabled, and fall back
81
+ // to them if either step-time node is unavailable.
82
+ var attrsToCheck = (0, _fg.fg)('platform_editor_reduce_diff_attr_sensitivity') && beforeNode && afterNode ? stepAttrs.filter(function (attrName) {
83
+ return !(0, _isEqual.default)(beforeNode.attrs[attrName], afterNode.attrs[attrName]);
84
+ }) : stepAttrs;
85
+ var $pos = doc.resolve(finalPos);
86
+ var nodeAtPos = doc.nodeAt(finalPos);
87
+ var originalNodeAtPos = originalPos === undefined ? null : originalDoc.nodeAt(originalPos);
61
88
 
62
89
  // date node: timestamp attribute change — highlight the date node itself (inline)
63
- if (stepAttrs.some(function (v) {
90
+ if (attrsToCheck.some(function (v) {
64
91
  return dateAttrs.includes(v);
65
92
  }) && (nodeAtPos === null || nodeAtPos === void 0 ? void 0 : nodeAtPos.type.name) === 'date' && !(0, _deprecatedPlatformFeatureExperiments.isExperimentEnabled)('platform_editor_improve_inline_diffs', function () {
66
93
  return (0, _expValEquals.expValEquals)('platform_editor_improve_inline_diffs', 'isEnabled', true);
67
94
  })) {
68
95
  return {
69
- fromB: step.pos,
70
- toB: step.pos + nodeAtPos.nodeSize,
96
+ fromB: finalPos,
97
+ toB: finalPos + nodeAtPos.nodeSize,
71
98
  isInline: true,
72
99
  inlineNodeName: 'date'
73
100
  };
@@ -82,30 +109,29 @@ var getAttrChangeRanges = exports.getAttrChangeRanges = function getAttrChangeRa
82
109
  var nodeName = nodeAtPos.type.name;
83
110
  if (isInlineAttrChangeNodeName(nodeName)) {
84
111
  var watchedAttrs = inlineNodeAttrMap[nodeName];
85
- if (stepAttrs.some(function (v) {
112
+ if (attrsToCheck.some(function (v) {
86
113
  return watchedAttrs.includes(v);
87
114
  })) {
88
- var originalNodeAtPos = originalDoc === null || originalDoc === void 0 ? void 0 : originalDoc.nodeAt(step.pos);
89
115
  return _objectSpread({
90
- fromB: step.pos,
91
- toB: step.pos + nodeAtPos.nodeSize,
116
+ fromB: finalPos,
117
+ toB: finalPos + nodeAtPos.nodeSize,
92
118
  isInline: true,
93
119
  inlineNodeName: nodeName
94
- }, originalNodeAtPos && {
95
- fromA: step.pos,
96
- toA: step.pos + originalNodeAtPos.nodeSize
120
+ }, originalPos !== undefined && originalNodeAtPos && {
121
+ fromA: originalPos,
122
+ toA: originalPos + originalNodeAtPos.nodeSize
97
123
  });
98
124
  }
99
125
  }
100
126
  }
101
127
 
102
128
  // taskItem node: state attribute change — highlight the taskItem node
103
- if (stepAttrs.some(function (v) {
129
+ if (attrsToCheck.some(function (v) {
104
130
  return taskItemAttrs.includes(v);
105
131
  }) && (nodeAtPos === null || nodeAtPos === void 0 ? void 0 : nodeAtPos.type.name) === 'taskItem') {
106
132
  return {
107
- fromB: step.pos,
108
- toB: step.pos + nodeAtPos.nodeSize
133
+ fromB: finalPos,
134
+ toB: finalPos + nodeAtPos.nodeSize
109
135
  };
110
136
  }
111
137
 
@@ -113,33 +139,36 @@ var getAttrChangeRanges = exports.getAttrChangeRanges = function getAttrChangeRa
113
139
  // (e.g. note -> warning) — highlight the new panel and, when the original node
114
140
  // is resolvable, expose its range (fromA/toA) so the caller can render the old
115
141
  // panel as a "deleted" widget for a before/after comparison.
116
- if (stepAttrs.some(function (v) {
142
+ if (attrsToCheck.some(function (v) {
117
143
  return panelAttrs.includes(v);
118
144
  }) && nodeAtPos && (0, _nodeTypeUtils.getBaseNodeTypeName)(nodeAtPos.type) === 'panel') {
119
- var _originalNodeAtPos = originalDoc === null || originalDoc === void 0 ? void 0 : originalDoc.nodeAt(step.pos);
120
145
  return _objectSpread({
121
- fromB: step.pos,
122
- toB: step.pos + nodeAtPos.nodeSize
123
- }, _originalNodeAtPos && {
124
- fromA: step.pos,
125
- toA: step.pos + _originalNodeAtPos.nodeSize
146
+ fromB: finalPos,
147
+ toB: finalPos + nodeAtPos.nodeSize
148
+ }, originalPos !== undefined && originalNodeAtPos && {
149
+ fromA: originalPos,
150
+ toA: originalPos + originalNodeAtPos.nodeSize
126
151
  });
127
152
  }
128
153
 
129
- // extension nodes: highlight on any diffable attr change (exclude rule in shared map)
130
- if (nodeAtPos && extensionNodeNames.includes(nodeAtPos.type.name) && stepAttrs.some(function (v) {
154
+ // Extension nodes: highlight changes to user-visible configuration. When enabled,
155
+ // transient extension metadata is ignored by the comparison below.
156
+ if (nodeAtPos && extensionNodeNames.includes(nodeAtPos.type.name) && attrsToCheck.some(function (v) {
131
157
  return (0, _diffableAttrs.isDiffableAttr)(nodeAtPos.type.name, v);
132
158
  })) {
159
+ if ((0, _fg.fg)('platform_editor_reduce_diff_attr_sensitivity') && beforeNode && afterNode && beforeNode.type === afterNode.type && haveSameRelevantExtensionAttrs(beforeNode, afterNode)) {
160
+ return undefined;
161
+ }
133
162
  var isInline = nodeAtPos.type.name === 'inlineExtension';
134
163
  return {
135
- fromB: step.pos,
136
- toB: step.pos + nodeAtPos.nodeSize,
164
+ fromB: finalPos,
165
+ toB: finalPos + nodeAtPos.nodeSize,
137
166
  isInline: isInline
138
167
  };
139
168
  }
140
169
 
141
170
  // media node: id/collection/url attribute change — highlight the mediaSingle parent
142
- if (stepAttrs.some(function (v) {
171
+ if (attrsToCheck.some(function (v) {
143
172
  return mediaAttrs.includes(v);
144
173
  }) && $pos.parent.type === doc.type.schema.nodes.mediaSingle) {
145
174
  var startPos = $pos.pos + $pos.parentOffset;