@atlaskit/editor-plugin-show-diff 14.2.10 → 14.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/afm-products/tsconfig.json +3 -0
  4. package/dist/cjs/pm-plugins/calculateDiff/attrAwareTokenEncoder.js +2 -22
  5. package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +18 -7
  6. package/dist/cjs/pm-plugins/calculateDiff/computeDiffChanges.js +5 -6
  7. package/dist/cjs/pm-plugins/calculateDiff/encodeCharacterWithMarks.js +44 -0
  8. package/dist/cjs/pm-plugins/calculateDiff/isMarkOnlyChange.js +50 -0
  9. package/dist/cjs/pm-plugins/calculateDiff/markAwareTokenEncoder.js +38 -0
  10. package/dist/cjs/pm-plugins/calculateDiff/selectTokenEncoder.js +36 -0
  11. package/dist/cjs/pm-plugins/calculateDiff/simplifySteps.js +3 -3
  12. package/dist/cjs/pm-plugins/decorations/colorSchemes/attributions.js +68 -17
  13. package/dist/cjs/pm-plugins/decorations/colorSchemes/factory.js +68 -12
  14. package/dist/cjs/pm-plugins/decorations/colorSchemes/schemes.js +19 -7
  15. package/dist/cjs/pm-plugins/decorations/colorSchemes/types.js +16 -1
  16. package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +4 -2
  17. package/dist/cjs/pm-plugins/decorations/utils/getAttrChangeRanges.js +3 -3
  18. package/dist/es2019/pm-plugins/calculateDiff/attrAwareTokenEncoder.js +1 -21
  19. package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +19 -7
  20. package/dist/es2019/pm-plugins/calculateDiff/computeDiffChanges.js +6 -6
  21. package/dist/es2019/pm-plugins/calculateDiff/encodeCharacterWithMarks.js +36 -0
  22. package/dist/es2019/pm-plugins/calculateDiff/isMarkOnlyChange.js +47 -0
  23. package/dist/es2019/pm-plugins/calculateDiff/markAwareTokenEncoder.js +25 -0
  24. package/dist/es2019/pm-plugins/calculateDiff/selectTokenEncoder.js +30 -0
  25. package/dist/es2019/pm-plugins/calculateDiff/simplifySteps.js +1 -1
  26. package/dist/es2019/pm-plugins/decorations/colorSchemes/attributions.js +55 -11
  27. package/dist/es2019/pm-plugins/decorations/colorSchemes/factory.js +67 -12
  28. package/dist/es2019/pm-plugins/decorations/colorSchemes/schemes.js +19 -7
  29. package/dist/es2019/pm-plugins/decorations/colorSchemes/types.js +14 -1
  30. package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +7 -0
  31. package/dist/es2019/pm-plugins/decorations/utils/getAttrChangeRanges.js +1 -1
  32. package/dist/esm/pm-plugins/calculateDiff/attrAwareTokenEncoder.js +1 -21
  33. package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +18 -7
  34. package/dist/esm/pm-plugins/calculateDiff/computeDiffChanges.js +5 -6
  35. package/dist/esm/pm-plugins/calculateDiff/encodeCharacterWithMarks.js +38 -0
  36. package/dist/esm/pm-plugins/calculateDiff/isMarkOnlyChange.js +44 -0
  37. package/dist/esm/pm-plugins/calculateDiff/markAwareTokenEncoder.js +33 -0
  38. package/dist/esm/pm-plugins/calculateDiff/selectTokenEncoder.js +30 -0
  39. package/dist/esm/pm-plugins/calculateDiff/simplifySteps.js +1 -1
  40. package/dist/esm/pm-plugins/decorations/colorSchemes/attributions.js +68 -17
  41. package/dist/esm/pm-plugins/decorations/colorSchemes/factory.js +69 -12
  42. package/dist/esm/pm-plugins/decorations/colorSchemes/schemes.js +19 -7
  43. package/dist/esm/pm-plugins/decorations/colorSchemes/types.js +14 -1
  44. package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +4 -2
  45. package/dist/esm/pm-plugins/decorations/utils/getAttrChangeRanges.js +1 -1
  46. package/dist/types/pm-plugins/calculateDiff/encodeCharacterWithMarks.d.ts +9 -0
  47. package/dist/types/pm-plugins/calculateDiff/isMarkOnlyChange.d.ts +15 -0
  48. package/dist/types/pm-plugins/calculateDiff/markAwareTokenEncoder.d.ts +9 -0
  49. package/dist/types/pm-plugins/calculateDiff/selectTokenEncoder.d.ts +17 -0
  50. package/dist/types/pm-plugins/decorations/colorSchemes/attributions.d.ts +3 -3
  51. package/dist/types/pm-plugins/decorations/colorSchemes/factory.d.ts +1 -1
  52. package/dist/types/pm-plugins/decorations/colorSchemes/schemes.d.ts +1 -1
  53. package/dist/types/pm-plugins/decorations/colorSchemes/types.d.ts +19 -19
  54. package/dist/types/pm-plugins/decorations/utils/getAttrChangeRanges.d.ts +1 -1
  55. package/package.json +7 -39
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @atlaskit/editor-plugin-show-diff
2
2
 
3
+ ## 14.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`8093f00408d76`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8093f00408d76) -
8
+ Align attributed diff colours with all 18 editor participant colour slots under
9
+ confluence_ncs_step_diffing_version_history and platform_editor_show_diff_color_scheme_refactor.
10
+
11
+ ## 14.2.11
12
+
13
+ ### Patch Changes
14
+
15
+ - [`15abc159d8096`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/15abc159d8096) -
16
+ Add mark (formatting) support to the non-smart diff types behind
17
+ `platform_editor_diff_inline_mark_changes`. A mark-only agent edit arrives as a `ReplaceStep`,
18
+ which the default `prosemirror-changeset` token encoder tokenises identically on both sides, so
19
+ bold/italic/code/link changes were silently invisible in the inline diff. A mark-aware token
20
+ encoder now folds marks into the character token, and mark-only changes render as an added-side
21
+ highlight without duplicating the unchanged text. No behaviour change with the gate off.
22
+ - Updated dependencies
23
+
3
24
  ## 14.2.10
4
25
 
5
26
  ### Patch Changes
@@ -32,6 +32,9 @@
32
32
  {
33
33
  "path": "../../editor-prosemirror/afm-cc/tsconfig.json"
34
34
  },
35
+ {
36
+ "path": "../../editor-shared-styles/afm-cc/tsconfig.json"
37
+ },
35
38
  {
36
39
  "path": "../../editor-tables/afm-cc/tsconfig.json"
37
40
  },
@@ -32,6 +32,9 @@
32
32
  {
33
33
  "path": "../../editor-prosemirror/afm-products/tsconfig.json"
34
34
  },
35
+ {
36
+ "path": "../../editor-shared-styles/afm-products/tsconfig.json"
37
+ },
35
38
  {
36
39
  "path": "../../editor-tables/afm-products/tsconfig.json"
37
40
  },
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.attrAwareTokenEncoder = void 0;
7
7
  var _nodeTypeUtils = require("@atlaskit/editor-common/utils/node-type-utils");
8
8
  var _diffableAttrs = require("../decorations/utils/diffableAttrs");
9
+ var _encodeCharacterWithMarks = require("./encodeCharacterWithMarks");
9
10
  /**
10
11
  * Attribute-aware token encoder for `prosemirror-changeset`. The default encoder
11
12
  * reduces a node to `node.type.name`, so an attribute-only change (e.g. a table
@@ -25,33 +26,12 @@ var encodeNodeWithAttrs = function encodeNodeWithAttrs(node, attrNames) {
25
26
  return "".concat(node.type.name, "|").concat(parts.join('|'));
26
27
  };
27
28
 
28
- // Fold a character's marks (type + attrs) into its token so a formatting-only change
29
- // (bold/italic/link/colour, or a link whose `href` changes) registers as a real diff.
30
- // The default encoder returns just the char code, so marked and unmarked text tokenise
31
- // identically. Marks and their attrs are sorted so the token is order-independent.
32
- var encodeCharacterWithMarks = function encodeCharacterWithMarks(char, marks) {
33
- if (marks.length === 0) {
34
- // Fast path: unmarked text keeps the numeric char code (unchanged behaviour).
35
- return char;
36
- }
37
- var markKey = marks.map(function (mark) {
38
- var _mark$attrs;
39
- var attrs = (_mark$attrs = mark.attrs) !== null && _mark$attrs !== void 0 ? _mark$attrs : {};
40
- var attrParts = Object.keys(attrs).sort().map(function (key) {
41
- var _attrs$key;
42
- return "".concat(key, "=").concat(JSON.stringify((_attrs$key = attrs[key]) !== null && _attrs$key !== void 0 ? _attrs$key : null));
43
- });
44
- return attrParts.length > 0 ? "".concat(mark.type.name, "(").concat(attrParts.join(','), ")") : mark.type.name;
45
- }).sort().join('&');
46
- return "".concat(char, "\0").concat(markKey);
47
- };
48
-
49
29
  // Like the library default, but node types with a `diffableAttrs` rule fold their
50
30
  // attrs into the open token, and text characters fold in their marks. Node-end is
51
31
  // unchanged, hence `string | number`.
52
32
  var attrAwareTokenEncoder = exports.attrAwareTokenEncoder = {
53
33
  encodeCharacter: function encodeCharacter(char, marks) {
54
- return encodeCharacterWithMarks(char, marks);
34
+ return (0, _encodeCharacterWithMarks.encodeCharacterWithMarks)(char, marks);
55
35
  },
56
36
  encodeNodeStart: function encodeNodeStart(node) {
57
37
  var _node$attrs2;
@@ -27,10 +27,11 @@ var _decorationKeys = require("../decorations/decorationKeys");
27
27
  var _getAttrChangeRanges = require("../decorations/utils/getAttrChangeRanges");
28
28
  var _getMarkChangeRanges = require("../decorations/utils/getMarkChangeRanges");
29
29
  var _isExtendedEnabled = require("../isExtendedEnabled");
30
- var _attrAwareTokenEncoder = require("./attrAwareTokenEncoder");
31
30
  var _diffBySteps = require("./diffBySteps");
32
31
  var _groupChangesByBlock = require("./groupChangesByBlock");
32
+ var _isMarkOnlyChange = require("./isMarkOnlyChange");
33
33
  var _optimizeChanges = require("./optimizeChanges");
34
+ var _selectTokenEncoder2 = require("./selectTokenEncoder");
34
35
  var _simplifyChangesWithAttribution = require("./simplifyChangesWithAttribution");
35
36
  var _simplifySteps = require("./simplifySteps");
36
37
  var _classifySmartChanges = require("./smart/classifySmartChanges");
@@ -389,10 +390,10 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref7
389
390
  };
390
391
  }
391
392
  }
392
- // The attribute-aware encoder is only needed by the smart classifier and is
393
- // gated with it; other diff types keep the library default so their output is
394
- // unchanged.
395
- var tokenEncoder = diffType === 'smart' && (0, _fg.fg)('platform_editor_ai_smart_diff') ? _attrAwareTokenEncoder.attrAwareTokenEncoder : undefined;
393
+ // The attribute-aware encoder is only needed by the smart classifier and is gated with it.
394
+ var _selectTokenEncoder = (0, _selectTokenEncoder2.selectTokenEncoder)(diffType === 'smart' && (0, _fg.fg)('platform_editor_ai_smart_diff')),
395
+ tokenEncoder = _selectTokenEncoder.tokenEncoder,
396
+ shouldHideMarkOnlyDeletions = _selectTokenEncoder.shouldHideMarkOnlyDeletions;
396
397
  var changes;
397
398
  var attributedChanges = [];
398
399
  var attributionColors;
@@ -447,6 +448,16 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref7
447
448
  var changeColorScheme = attributionColors ? (0, _attributions.getColorSchemeForChange)(change, attributedChanges, attributionColors, colorScheme) : colorScheme;
448
449
  var isActive = isRangeActive(activeIndexPos, change.fromB, change.toB);
449
450
 
451
+ // The deleted side of a mark-only change is a byte-identical copy of the new text, so it is
452
+ // suppressed in the clean view. `hideDeletedDiffs` is load-bearing: when false the reviewer
453
+ // asked to compare against the original, and the deleted side is the only place the
454
+ // previous formatting is visible.
455
+ var isMarkOnly = shouldHideMarkOnlyDeletions && hideDeletedDiffs && change.deleted.length > 0 && (0, _isMarkOnlyChange.isMarkOnlyChange)({
456
+ change: change,
457
+ originalDoc: originalDoc,
458
+ newDoc: tr.doc
459
+ });
460
+
450
461
  // Hoisted because it decides BOTH where the deleted widget is anchored and — since the
451
462
  // widget pins whichever end of the range it sits at — how the indicator anchors below are
452
463
  // allowed to move.
@@ -477,7 +488,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref7
477
488
  // change. Used to decide if indicator anchor positions should be adjusted
478
489
  // inward — when the widget is present the anchor must stay at the block
479
490
  // boundary to keep the indicator bar continuous with the deleted content.
480
- var willRenderDeletedWidget = change.deleted.length > 0 && !((0, _isExtendedEnabled.isExtendedEnabled)(diffType) && !isInverted && hideDeletedDiffs && change.inserted.length > 0);
491
+ var willRenderDeletedWidget = change.deleted.length > 0 && !isMarkOnly && !((0, _isExtendedEnabled.isExtendedEnabled)(diffType) && !isInverted && hideDeletedDiffs && change.inserted.length > 0);
481
492
  if (isSmartNodeLevel) {
482
493
  // For a large inserted table, skip the O(cells) inline decorations inside the
483
494
  // table (the cell overlays added below provide the highlight without the
@@ -548,7 +559,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref7
548
559
  coarseTableCellsOnly: useCoarseTableDecoration
549
560
  }))));
550
561
  }
551
- if (change.deleted.length > 0) {
562
+ if (change.deleted.length > 0 && !isMarkOnly) {
552
563
  var _shouldHideDeleted = (0, _isExtendedEnabled.isExtendedEnabled)(diffType) ? !isInverted && hideDeletedDiffs && change.inserted.length > 0 : false;
553
564
  if (!_shouldHideDeleted) {
554
565
  decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createNodeChangedDecorationWidget.createNodeChangedDecorationWidget)(_objectSpread(_objectSpread({
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.computeDiffChanges = void 0;
7
7
  var _prosemirrorChangeset = require("prosemirror-changeset");
8
- var _attrAwareTokenEncoder = require("./attrAwareTokenEncoder");
9
8
  var _diffBySteps = require("./diffBySteps");
10
9
  var _groupChangesByBlock = require("./groupChangesByBlock");
11
10
  var _optimizeChanges = require("./optimizeChanges");
11
+ var _selectTokenEncoder2 = require("./selectTokenEncoder");
12
12
  var _simplifySteps = require("./simplifySteps");
13
13
  var _classifySmartChanges = require("./smart/classifySmartChanges");
14
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; } } }; }
@@ -82,11 +82,10 @@ var computeDiffChanges = exports.computeDiffChanges = function computeDiffChange
82
82
  };
83
83
  }
84
84
 
85
- // The attribute-aware encoder only affects the `smart` classification, so it is
86
- // applied only for that type. (This utility intentionally applies no feature
87
- // gate — see the file docstring — but a caller requesting `smart` is already
88
- // behind the smart-diff gate.)
89
- var tokenEncoder = diffType === 'smart' ? _attrAwareTokenEncoder.attrAwareTokenEncoder : undefined;
85
+ // This utility does not apply the smart-diff gate (see the file docstring); a caller
86
+ // requesting `smart` is already behind it.
87
+ var _selectTokenEncoder = (0, _selectTokenEncoder2.selectTokenEncoder)(diffType === 'smart'),
88
+ tokenEncoder = _selectTokenEncoder.tokenEncoder;
90
89
  var changeset = _prosemirrorChangeset.ChangeSet.create(originalDoc, undefined, tokenEncoder).addSteps(steppedDoc, stepMaps, steppedDoc);
91
90
  if (diffType === 'smart') {
92
91
  return {
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.encodeCharacterWithMarks = void 0;
7
+ /** U+0000 cannot occur in ProseMirror text content, so a token can never be ambiguous. */
8
+ var MARK_KEY_SEPARATOR = "\0";
9
+ var buildMarkKey = function buildMarkKey(marks) {
10
+ return marks.map(function (mark) {
11
+ var _mark$attrs;
12
+ var attrs = (_mark$attrs = mark.attrs) !== null && _mark$attrs !== void 0 ? _mark$attrs : {};
13
+ var attrParts = Object.keys(attrs).sort().map(function (key) {
14
+ var _attrs$key;
15
+ return "".concat(key, "=").concat(JSON.stringify((_attrs$key = attrs[key]) !== null && _attrs$key !== void 0 ? _attrs$key : null));
16
+ });
17
+ return attrParts.length > 0 ? "".concat(mark.type.name, "(").concat(attrParts.join(','), ")") : mark.type.name;
18
+ }).sort().join('&');
19
+ };
20
+
21
+ /**
22
+ * Keyed on array identity: `prosemirror-changeset` passes the same `child.marks` reference for
23
+ * every character in a text node, so this collapses the key building to once per node.
24
+ */
25
+ var markKeyCache = new WeakMap();
26
+
27
+ /**
28
+ * Folds a character's marks into its `prosemirror-changeset` token. The library default returns
29
+ * only the char code, so marked and unmarked text tokenise identically and a formatting-only edit
30
+ * is invisible to the changeset.
31
+ *
32
+ * Marks and attrs are sorted so the token is order-independent.
33
+ */
34
+ var encodeCharacterWithMarks = exports.encodeCharacterWithMarks = function encodeCharacterWithMarks(char, marks) {
35
+ if (marks.length === 0) {
36
+ return char;
37
+ }
38
+ var markKey = markKeyCache.get(marks);
39
+ if (markKey === undefined) {
40
+ markKey = buildMarkKey(marks);
41
+ markKeyCache.set(marks, markKey);
42
+ }
43
+ return "".concat(char).concat(MARK_KEY_SEPARATOR).concat(markKey);
44
+ };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isMarkOnlyChange = void 0;
7
+ /** U+0000 cannot occur in ProseMirror text content, so this cannot collide with document text. */
8
+ var NODE_MARKER = "\0";
9
+
10
+ /**
11
+ * Node types and text only; marks and attrs excluded.
12
+ *
13
+ * Text is unprefixed so adjacent runs concatenate — a run only splits because its marks differ, so
14
+ * `strong("hello")` and `strong("hel") + em("lo")` must match. Attrs are excluded because a
15
+ * reconstructed agent edit regenerates `localId`s; `getAttrChangeRanges` reports attrs separately.
16
+ */
17
+ var markFreeSignature = function markFreeSignature(doc, from, to) {
18
+ var parts = [];
19
+ doc.nodesBetween(from, to, function (node, pos) {
20
+ if (node.isText) {
21
+ var _node$text;
22
+ var start = Math.max(pos, from) - pos;
23
+ var end = Math.min(pos + node.nodeSize, to) - pos;
24
+ parts.push(((_node$text = node.text) !== null && _node$text !== void 0 ? _node$text : '').slice(start, end));
25
+ } else {
26
+ parts.push("".concat(NODE_MARKER).concat(node.type.name));
27
+ }
28
+ return true;
29
+ });
30
+ return parts.join('');
31
+ };
32
+
33
+ /**
34
+ * Whether a change differs only in marks, with identical structure and text on both sides. Only
35
+ * produced when a mark-aware token encoder is in use.
36
+ */
37
+ var isMarkOnlyChange = exports.isMarkOnlyChange = function isMarkOnlyChange(_ref) {
38
+ var change = _ref.change,
39
+ newDoc = _ref.newDoc,
40
+ originalDoc = _ref.originalDoc;
41
+ var fromA = change.fromA,
42
+ toA = change.toA,
43
+ fromB = change.fromB,
44
+ toB = change.toB;
45
+ var isPureInsertionOrDeletion = toA === fromA || toB === fromB;
46
+ if (isPureInsertionOrDeletion || toA - fromA !== toB - fromB) {
47
+ return false;
48
+ }
49
+ return markFreeSignature(originalDoc, fromA, toA) === markFreeSignature(newDoc, fromB, toB);
50
+ };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.markAwareTokenEncoder = void 0;
7
+ var _encodeCharacterWithMarks = require("./encodeCharacterWithMarks");
8
+ /** Mirrors the library's private (unexported) `typeID` so node-end tokens match. */
9
+ var typeID = function typeID(type) {
10
+ var cache = type.schema.cached.changeSetIDs || (type.schema.cached.changeSetIDs = Object.create(null));
11
+ var id = cache[type.name];
12
+ if (id == null) {
13
+ cache[type.name] = id = Object.keys(type.schema.nodes).indexOf(type.name) + 1;
14
+ }
15
+ return id;
16
+ };
17
+
18
+ /**
19
+ * The library default encoder plus mark folding on text characters.
20
+ *
21
+ * Deliberately narrower than `attrAwareTokenEncoder`: node-start tokens keep the library default
22
+ * and do not fold in diffable attributes, which `getAttrChangeRanges` already reports for every
23
+ * diff type.
24
+ */
25
+ var markAwareTokenEncoder = exports.markAwareTokenEncoder = {
26
+ encodeCharacter: function encodeCharacter(char, marks) {
27
+ return (0, _encodeCharacterWithMarks.encodeCharacterWithMarks)(char, marks);
28
+ },
29
+ encodeNodeStart: function encodeNodeStart(node) {
30
+ return node.type.name;
31
+ },
32
+ encodeNodeEnd: function encodeNodeEnd(node) {
33
+ return -typeID(node.type);
34
+ },
35
+ compareTokens: function compareTokens(a, b) {
36
+ return a === b;
37
+ }
38
+ };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.selectTokenEncoder = void 0;
7
+ var _fg = require("@atlaskit/platform-feature-flags/fg");
8
+ var _attrAwareTokenEncoder = require("./attrAwareTokenEncoder");
9
+ var _markAwareTokenEncoder = require("./markAwareTokenEncoder");
10
+ /**
11
+ * Single place `platform_editor_diff_inline_mark_changes` is read, shared by
12
+ * `calculateDiffDecorations` and `computeDiffChanges` so the two cannot drift.
13
+ *
14
+ * With the gate off this returns what both callers computed before it existed.
15
+ *
16
+ * @param useAttrAwareEncoder Caller is running the smart classifier, which needs node attrs folded
17
+ * into the token.
18
+ */
19
+ var selectTokenEncoder = exports.selectTokenEncoder = function selectTokenEncoder(useAttrAwareEncoder) {
20
+ if (useAttrAwareEncoder) {
21
+ return {
22
+ tokenEncoder: _attrAwareTokenEncoder.attrAwareTokenEncoder,
23
+ shouldHideMarkOnlyDeletions: false
24
+ };
25
+ }
26
+ if ((0, _fg.fg)('platform_editor_diff_inline_mark_changes')) {
27
+ return {
28
+ tokenEncoder: _markAwareTokenEncoder.markAwareTokenEncoder,
29
+ shouldHideMarkOnlyDeletions: true
30
+ };
31
+ }
32
+ return {
33
+ tokenEncoder: undefined,
34
+ shouldHideMarkOnlyDeletions: false
35
+ };
36
+ };
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.simplifySteps = simplifySteps;
8
8
  exports.simplifyStepsWithAttribution = simplifyStepsWithAttribution;
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
- var _steps = require("@atlaskit/adf-schema/steps");
10
+ var _analytics = require("@atlaskit/adf-schema/steps/analytics");
11
11
  var _document = require("@atlaskit/editor-common/utils/document");
12
12
  var _transform = require("@atlaskit/editor-prosemirror/transform");
13
13
  var _attributions = require("../decorations/colorSchemes/attributions");
@@ -42,7 +42,7 @@ function simplifySteps(steps, originalDoc) {
42
42
  return stepsToFilter
43
43
  // Remove steps that don't affect document structure or content
44
44
  .filter(function (step) {
45
- return !(step instanceof _steps.AnalyticsStep);
45
+ return !(step instanceof _analytics.AnalyticsStep);
46
46
  })
47
47
  // Merge consecutive steps where possible
48
48
  .reduce(function (acc, step) {
@@ -85,7 +85,7 @@ function simplifyStepsWithAttribution(steps, stepAttributions, originalDoc) {
85
85
  }), originalDoc);
86
86
  return stepsToFilter.filter(function (_ref) {
87
87
  var step = _ref.step;
88
- return !(step instanceof _steps.AnalyticsStep);
88
+ return !(step instanceof _analytics.AnalyticsStep);
89
89
  }).reduce(function (acc, current) {
90
90
  var _previous$step$merge, _previous$step$merge2, _previous$step;
91
91
  var previous = acc[acc.length - 1];
@@ -7,21 +7,46 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.isAttributionColoringEnabled = exports.getColorSchemeForChange = exports.getAttributionKey = exports.createAttributionColorMap = exports.areAttributionColorGatesEnabled = void 0;
8
8
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
9
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _utils = require("@atlaskit/editor-shared-styles/utils");
10
11
  var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
11
12
  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) {
13
+ var _types = require("./types");
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; } } }; }
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; } }
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
+ /**
18
+ * Normalise the attribution identity once so a valid lookup key always has a valid participant
19
+ * colour seed. `userId` is primary; `agentId`, or `agentType` as its fallback, separates shared
20
+ * users. The colour seed matches collaboration: the user ID for a human and the agent ID for an
21
+ * agent. The agent-type fallback includes the user so different users' agents do not collapse onto
22
+ * one colour when NCS omits an agent ID.
23
+ */
24
+ var getAttributionIdentity = function getAttributionIdentity(attribution) {
16
25
  var _attribution$userId, _attribution$agentId, _attribution$agentTyp;
17
26
  var userId = attribution === null || attribution === void 0 || (_attribution$userId = attribution.userId) === null || _attribution$userId === void 0 ? void 0 : _attribution$userId.trim();
18
27
  var agentId = attribution === null || attribution === void 0 || (_attribution$agentId = attribution.agentId) === null || _attribution$agentId === void 0 ? void 0 : _attribution$agentId.trim();
19
28
  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) {
29
+ var colorSeed;
30
+ if (agentId) {
31
+ colorSeed = agentId;
32
+ } else if (agentType) {
33
+ colorSeed = userId ? "user:".concat(userId, "|agent:type:").concat(agentType) : "agent:type:".concat(agentType);
34
+ } else if (userId) {
35
+ colorSeed = userId;
36
+ } else {
21
37
  return undefined;
22
38
  }
23
39
  var agentIdentity = agentId || (agentType ? "type:".concat(agentType) : '');
24
- return "user:".concat(userId !== null && userId !== void 0 ? userId : '', "|agent:").concat(agentIdentity);
40
+ return {
41
+ colorSeed: colorSeed,
42
+ key: "user:".concat(userId !== null && userId !== void 0 ? userId : '', "|agent:").concat(agentIdentity)
43
+ };
44
+ };
45
+
46
+ /** `userId` is primary; `agentId`, or `agentType` as its fallback, separates shared users. */
47
+ var getAttributionKey = exports.getAttributionKey = function getAttributionKey(attribution) {
48
+ var _getAttributionIdenti;
49
+ return (_getAttributionIdenti = getAttributionIdentity(attribution)) === null || _getAttributionIdenti === void 0 ? void 0 : _getAttributionIdenti.key;
25
50
  };
26
51
  var areAttributionColorGatesEnabled = exports.areAttributionColorGatesEnabled = function areAttributionColorGatesEnabled() {
27
52
  return (0, _fg.fg)('confluence_ncs_step_diffing_version_history') && (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor');
@@ -36,12 +61,29 @@ var isAttributionColoringEnabled = exports.isAttributionColoringEnabled = functi
36
61
  return attributionKeys.size > 1;
37
62
  };
38
63
  var createAttributionColorMap = exports.createAttributionColorMap = function createAttributionColorMap(stepAttributions) {
39
- var keys = Array.from(new Set(stepAttributions.map(getAttributionKey).filter(function (key) {
40
- return key !== undefined;
41
- }))).sort();
42
- return new Map(keys.map(function (key, index) {
43
- return [key, ATTRIBUTION_COLOR_PALETTE[index % ATTRIBUTION_COLOR_PALETTE.length]];
44
- }));
64
+ var colors = new Map();
65
+ var _iterator = _createForOfIteratorHelper(stepAttributions),
66
+ _step;
67
+ try {
68
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
69
+ var attribution = _step.value;
70
+ var identity = getAttributionIdentity(attribution);
71
+ if (!identity || colors.has(identity.key)) {
72
+ continue;
73
+ }
74
+ var _getParticipantColor = (0, _utils.getParticipantColor)(identity.colorSeed),
75
+ index = _getParticipantColor.index;
76
+ var participantColorScheme = _types.PARTICIPANT_COLOR_SCHEMES[index];
77
+ if (participantColorScheme) {
78
+ colors.set(identity.key, participantColorScheme);
79
+ }
80
+ }
81
+ } catch (err) {
82
+ _iterator.e(err);
83
+ } finally {
84
+ _iterator.f();
85
+ }
86
+ return colors;
45
87
  };
46
88
  var getLatestAttribution = function getLatestAttribution(changes) {
47
89
  var data = changes.flatMap(function (change) {
@@ -63,10 +105,19 @@ var changesOverlap = function changesOverlap(change, attributedChange) {
63
105
  var deletedOverlap = change.deleted.length > 0 && attributedChange.deleted.length > 0 && rangesOverlap(change.fromA, change.toA, attributedChange.fromA, attributedChange.toA);
64
106
  return insertedOverlap || deletedOverlap;
65
107
  };
108
+ var getParticipantColorSchemeForChanges = function getParticipantColorSchemeForChanges(changes, attributionColors) {
109
+ var key = getAttributionKey(getLatestAttribution(changes));
110
+ return key ? attributionColors.get(key) : undefined;
111
+ };
66
112
  var getColorSchemeForChange = exports.getColorSchemeForChange = function getColorSchemeForChange(change, attributedChanges, attributionColors, fallback) {
67
- var _attributionColors$ge;
68
- var key = getAttributionKey(getLatestAttribution(attributedChanges.filter(function (attributedChange) {
69
- return changesOverlap(change, attributedChange);
70
- })));
71
- return key ? (_attributionColors$ge = attributionColors.get(key)) !== null && _attributionColors$ge !== void 0 ? _attributionColors$ge : fallback : fallback;
113
+ var _ref, _getParticipantColorS;
114
+ return (// Inline and step changes retain their own attribution spans. Resolve those first so a broader
115
+ // change is not recoloured by a later contributor whose nested range happens to overlap it.
116
+ (_ref = (_getParticipantColorS = getParticipantColorSchemeForChanges([change], attributionColors)) !== null && _getParticipantColorS !== void 0 ? _getParticipantColorS :
117
+ // Grouping and smart classification can produce changes without direct attribution data. For
118
+ // those transformed changes, retain the overlap-based lookup as a fallback.
119
+ getParticipantColorSchemeForChanges(attributedChanges.filter(function (attributedChange) {
120
+ return changesOverlap(change, attributedChange);
121
+ }), attributionColors)) !== null && _ref !== void 0 ? _ref : fallback
122
+ );
72
123
  };
@@ -67,6 +67,8 @@ exports.buildInsertedBlockNodeStyle = buildInsertedBlockNodeStyle;
67
67
  exports.buildInsertedInlineStyle = buildInsertedInlineStyle;
68
68
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
69
69
  var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
70
+ var _constants = require("@atlaskit/editor-shared-styles/constants");
71
+ var _types = require("./types");
70
72
  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; }
71
73
  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; }
72
74
  // token() is a build-time transform needing static literals, so pre-compute every colour's
@@ -81,7 +83,8 @@ var bgSubtlestMap = {
81
83
  orange: "var(--ds-background-accent-orange-subtlest, #FFF5DB)",
82
84
  yellow: "var(--ds-background-accent-yellow-subtlest, #FEF7C8)",
83
85
  magenta: "var(--ds-background-accent-magenta-subtlest, #FFECF8)",
84
- gray: "var(--ds-background-accent-gray-subtlest, #F0F1F2)"
86
+ gray: "var(--ds-background-accent-gray-subtlest, #F0F1F2)",
87
+ lime: "var(--ds-background-accent-lime-subtlest, #EFFFD6)"
85
88
  };
86
89
  var bgSubtlestPressedMap = {
87
90
  green: "var(--ds-background-accent-green-subtlest-pressed, #97EDC9)",
@@ -92,7 +95,8 @@ var bgSubtlestPressedMap = {
92
95
  orange: "var(--ds-background-accent-orange-subtlest-pressed, #FBD779)",
93
96
  yellow: "var(--ds-background-accent-yellow-subtlest-pressed, #EFDD4E)",
94
97
  magenta: "var(--ds-background-accent-magenta-subtlest-pressed, #FCB6E1)",
95
- gray: "var(--ds-background-accent-gray-subtlest-pressed, #B7B9BE)"
98
+ gray: "var(--ds-background-accent-gray-subtlest-pressed, #B7B9BE)",
99
+ lime: "var(--ds-background-accent-lime-subtlest-pressed, #BDE97C)"
96
100
  };
97
101
  var bgSubtlerMap = {
98
102
  green: "var(--ds-background-accent-green-subtler, #BAF3DB)",
@@ -103,7 +107,8 @@ var bgSubtlerMap = {
103
107
  orange: "var(--ds-background-accent-orange-subtler, #FCE4A6)",
104
108
  yellow: "var(--ds-background-accent-yellow-subtler, #F5E989)",
105
109
  magenta: "var(--ds-background-accent-magenta-subtler, #FDD0EC)",
106
- gray: "var(--ds-background-accent-gray-subtler, #DDDEE1)"
110
+ gray: "var(--ds-background-accent-gray-subtler, #DDDEE1)",
111
+ lime: "var(--ds-background-accent-lime-subtler, #D3F1A7)"
107
112
  };
108
113
  var bgSubtlerPressedMap = {
109
114
  green: "var(--ds-background-accent-green-subtler-pressed, #7EE2B8)",
@@ -114,7 +119,8 @@ var bgSubtlerPressedMap = {
114
119
  orange: "var(--ds-background-accent-orange-subtler-pressed, #FBC828)",
115
120
  yellow: "var(--ds-background-accent-yellow-subtler-pressed, #EED12B)",
116
121
  magenta: "var(--ds-background-accent-magenta-subtler-pressed, #F797D2)",
117
- gray: "var(--ds-background-accent-gray-subtler-pressed, #8C8F97)"
122
+ gray: "var(--ds-background-accent-gray-subtler-pressed, #8C8F97)",
123
+ lime: "var(--ds-background-accent-lime-subtler-pressed, #B3DF72)"
118
124
  };
119
125
  var borderAccentMap = {
120
126
  green: "var(--ds-border-accent-green, #22A06B)",
@@ -125,7 +131,8 @@ var borderAccentMap = {
125
131
  orange: "var(--ds-border-accent-orange, #E06C00)",
126
132
  yellow: "var(--ds-border-accent-yellow, #B38600)",
127
133
  magenta: "var(--ds-border-accent-magenta, #CD519D)",
128
- gray: "var(--ds-border-accent-gray, #7D818A)"
134
+ gray: "var(--ds-border-accent-gray, #7D818A)",
135
+ lime: "var(--ds-border-accent-lime, #6A9A23)"
129
136
  };
130
137
  var textAccentMap = {
131
138
  green: "var(--ds-text-accent-green, #216E4E)",
@@ -136,25 +143,74 @@ var textAccentMap = {
136
143
  orange: "var(--ds-text-accent-orange, #9E4C00)",
137
144
  yellow: "var(--ds-text-accent-yellow, #7F5F01)",
138
145
  magenta: "var(--ds-text-accent-magenta, #943D73)",
139
- gray: "var(--ds-text-accent-gray, #505258)"
146
+ gray: "var(--ds-text-accent-gray, #505258)",
147
+ lime: "var(--ds-text-accent-lime, #4C6B1F)"
148
+ };
149
+
150
+ /** Pressed counterpart of each participant's diff-safe SVG background tint. */
151
+ var participantPressedBackgroundMap = {
152
+ 'red-bolder': bgSubtlerPressedMap.red,
153
+ 'blue-bolder': bgSubtlerPressedMap.blue,
154
+ 'green-bolder': bgSubtlerPressedMap.green,
155
+ 'yellow-bolder': bgSubtlerPressedMap.yellow,
156
+ 'purple-bolder': bgSubtlerPressedMap.purple,
157
+ 'magenta-bolder': bgSubtlerPressedMap.magenta,
158
+ 'teal-bolder': bgSubtlerPressedMap.teal,
159
+ 'orange-bolder': bgSubtlerPressedMap.orange,
160
+ 'lime-bolder': bgSubtlerPressedMap.lime,
161
+ 'gray-bolder': bgSubtlerPressedMap.gray,
162
+ 'blue-subtle': bgSubtlestPressedMap.blue,
163
+ 'red-subtle': bgSubtlestPressedMap.red,
164
+ 'orange-subtle': bgSubtlestPressedMap.orange,
165
+ 'yellow-subtle': bgSubtlestPressedMap.yellow,
166
+ 'green-subtle': bgSubtlestPressedMap.green,
167
+ 'teal-subtle': bgSubtlestPressedMap.teal,
168
+ 'purple-subtle': bgSubtlestPressedMap.purple,
169
+ 'magenta-subtle': bgSubtlestPressedMap.magenta
170
+ };
171
+ /**
172
+ * Telepointers can put inverse text directly on their bolder colour. Diff colours sit behind
173
+ * arbitrary document content, so use the participant SVG tint and its matching pressed token for
174
+ * diff backgrounds. Borders and rings use the exact participant colour, preserving all 18
175
+ * bolder/subtle slots while keeping every value in the shared ADS participant palette.
176
+ */
177
+ var participantColorTokenSets = Object.fromEntries(_types.PARTICIPANT_COLOR_SCHEMES.map(function (scheme, index) {
178
+ var participantColor = _constants.participantColors[index];
179
+ if (!participantColor) {
180
+ throw new Error("Missing shared participant colour for show-diff slot ".concat(index));
181
+ }
182
+ return [scheme, {
183
+ backgroundSubtlest: participantColor.svgBackgroundColor,
184
+ backgroundSubtlestPressed: participantPressedBackgroundMap[scheme],
185
+ backgroundSubtler: participantColor.svgBackgroundColor,
186
+ backgroundSubtlerPressed: participantPressedBackgroundMap[scheme],
187
+ borderAccent: participantColor.backgroundColor,
188
+ // The first ten bolder colours are safe as accents on the editor surface. The
189
+ // remaining subtle colours use their paired dark participant text colour.
190
+ textAccent: index < 10 ? participantColor.backgroundColor : participantColor.textColor
191
+ }];
192
+ }));
193
+ var participantColorSchemeSet = new Set(_types.PARTICIPANT_COLOR_SCHEMES);
194
+ var isParticipantColorScheme = function isParticipantColorScheme(color) {
195
+ return participantColorSchemeSet.has(color);
140
196
  };
141
197
  function bgSubtlest(color) {
142
- return bgSubtlestMap[color];
198
+ return isParticipantColorScheme(color) ? participantColorTokenSets[color].backgroundSubtlest : bgSubtlestMap[color];
143
199
  }
144
200
  function bgSubtlestPressed(color) {
145
- return bgSubtlestPressedMap[color];
201
+ return isParticipantColorScheme(color) ? participantColorTokenSets[color].backgroundSubtlestPressed : bgSubtlestPressedMap[color];
146
202
  }
147
203
  function bgSubtler(color) {
148
- return bgSubtlerMap[color];
204
+ return isParticipantColorScheme(color) ? participantColorTokenSets[color].backgroundSubtler : bgSubtlerMap[color];
149
205
  }
150
206
  function bgSubtlerPressed(color) {
151
- return bgSubtlerPressedMap[color];
207
+ return isParticipantColorScheme(color) ? participantColorTokenSets[color].backgroundSubtlerPressed : bgSubtlerPressedMap[color];
152
208
  }
153
209
  function borderAccent(color) {
154
- return borderAccentMap[color];
210
+ return isParticipantColorScheme(color) ? participantColorTokenSets[color].borderAccent : borderAccentMap[color];
155
211
  }
156
212
  function textAccent(color) {
157
- return textAccentMap[color];
213
+ return isParticipantColorScheme(color) ? participantColorTokenSets[color].textAccent : textAccentMap[color];
158
214
  }
159
215
 
160
216
  /** Ring colour for an active (scroll-target) deleted block outline. */