@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/editor-plugin-show-diff
2
2
 
3
+ ## 14.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`b1510eccd9729`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b1510eccd9729) -
8
+ Reduce false-positive attribute diff decorations behind
9
+ `platform_editor_reduce_diff_attr_sensitivity`.
10
+ - Updated dependencies
11
+
12
+ ## 14.1.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [`69574af99ed9e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/69574af99ed9e) -
17
+ [ux] Add attributed-step inputs and internally selected, gated agent colours behind
18
+ `confluence_ncs_step_diffing_version_history` and
19
+ `platform_editor_show_diff_color_scheme_refactor`.
20
+
3
21
  ## 14.0.4
4
22
 
5
23
  ### Patch Changes
@@ -13,6 +13,7 @@ var _memoizeOne = _interopRequireDefault(require("memoize-one"));
13
13
  var _prosemirrorChangeset = require("prosemirror-changeset");
14
14
  var _deprecatedPlatformFeatureExperiments = require("@atlaskit/editor-common/deprecated-platform-feature-experiments");
15
15
  var _document = require("@atlaskit/editor-common/utils/document");
16
+ var _transform = require("@atlaskit/editor-prosemirror/transform");
16
17
  var _view = require("@atlaskit/editor-prosemirror/view");
17
18
  var _fg = require("@atlaskit/platform-feature-flags/fg");
18
19
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
@@ -21,6 +22,7 @@ var _createAnchorDecorationWidgets = require("../decorations/createAnchorDecorat
21
22
  var _createBlockChangedDecoration = require("../decorations/createBlockChangedDecoration");
22
23
  var _createInlineChangedDecoration = require("../decorations/createInlineChangedDecoration");
23
24
  var _createNodeChangedDecorationWidget = require("../decorations/createNodeChangedDecorationWidget");
25
+ var _attributions = require("../decorations/colorSchemes/attributions");
24
26
  var _decorationKeys = require("../decorations/decorationKeys");
25
27
  var _getAttrChangeRanges = require("../decorations/utils/getAttrChangeRanges");
26
28
  var _getMarkChangeRanges = require("../decorations/utils/getMarkChangeRanges");
@@ -29,6 +31,7 @@ var _attrAwareTokenEncoder = require("./attrAwareTokenEncoder");
29
31
  var _diffBySteps = require("./diffBySteps");
30
32
  var _groupChangesByBlock = require("./groupChangesByBlock");
31
33
  var _optimizeChanges = require("./optimizeChanges");
34
+ var _simplifyChangesWithAttribution = require("./simplifyChangesWithAttribution");
32
35
  var _simplifySteps = require("./simplifySteps");
33
36
  var _classifySmartChanges = require("./smart/classifySmartChanges");
34
37
  var _helpers = require("./smart/helpers");
@@ -72,6 +75,34 @@ var getChanges = function getChanges(_ref) {
72
75
  var changes = (0, _prosemirrorChangeset.simplifyChanges)(changeset.changes, tr.doc);
73
76
  return (0, _optimizeChanges.optimizeChanges)(changes);
74
77
  };
78
+ var getAttributedChanges = function getAttributedChanges(_ref2) {
79
+ var attributedChanges = _ref2.attributedChanges,
80
+ changeset = _ref2.changeset,
81
+ originalDoc = _ref2.originalDoc,
82
+ steppedDoc = _ref2.steppedDoc,
83
+ diffType = _ref2.diffType,
84
+ tr = _ref2.tr,
85
+ intl = _ref2.intl,
86
+ smartThresholds = _ref2.smartThresholds;
87
+ if ((0, _isExtendedEnabled.isExtendedEnabled)(diffType)) {
88
+ if (diffType === 'smart' && (0, _fg.fg)('platform_editor_ai_smart_diff')) {
89
+ return (0, _classifySmartChanges.classifySmartChanges)({
90
+ changes: (0, _simplifyChangesWithAttribution.simplifyChangesWithAttribution)(attributedChanges, tr.doc),
91
+ originalDoc: originalDoc,
92
+ newDoc: tr.doc,
93
+ locale: intl.locale,
94
+ thresholds: smartThresholds
95
+ });
96
+ }
97
+ if (diffType === 'step') {
98
+ return attributedChanges;
99
+ }
100
+ if (diffType === 'block') {
101
+ return (0, _groupChangesByBlock.groupChangesByBlock)(changeset.changes, originalDoc, steppedDoc);
102
+ }
103
+ }
104
+ return (0, _simplifyChangesWithAttribution.simplifyChangesWithAttribution)(attributedChanges, tr.doc);
105
+ };
75
106
 
76
107
  /**
77
108
  * Collect the inline-content ranges of every leaf text-bearing block (paragraph, heading, …)
@@ -130,28 +161,28 @@ var tableRanges = function tableRanges(doc, from, to) {
130
161
  return ranges;
131
162
  };
132
163
  var isInsideTable = function isInsideTable(tables, pos) {
133
- return tables.some(function (_ref2) {
134
- var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
135
- tFrom = _ref3[0],
136
- tTo = _ref3[1];
164
+ return tables.some(function (_ref3) {
165
+ var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
166
+ tFrom = _ref4[0],
167
+ tTo = _ref4[1];
137
168
  return pos >= tFrom && pos < tTo;
138
169
  });
139
170
  };
140
- var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration(_ref4) {
141
- var doc = _ref4.doc,
142
- from = _ref4.from,
143
- to = _ref4.to,
144
- colorScheme = _ref4.colorScheme,
145
- _ref4$isInserted = _ref4.isInserted,
146
- isInserted = _ref4$isInserted === void 0 ? true : _ref4$isInserted,
147
- activeIndexPos = _ref4.activeIndexPos,
148
- _ref4$shouldHideDelet = _ref4.shouldHideDeleted,
149
- shouldHideDeleted = _ref4$shouldHideDelet === void 0 ? false : _ref4$shouldHideDelet,
150
- _ref4$showIndicators = _ref4.showIndicators,
151
- showIndicators = _ref4$showIndicators === void 0 ? false : _ref4$showIndicators,
152
- diffType = _ref4.diffType,
153
- _ref4$coarseTableCell = _ref4.coarseTableCellsOnly,
154
- coarseTableCellsOnly = _ref4$coarseTableCell === void 0 ? false : _ref4$coarseTableCell;
171
+ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration(_ref5) {
172
+ var doc = _ref5.doc,
173
+ from = _ref5.from,
174
+ to = _ref5.to,
175
+ colorScheme = _ref5.colorScheme,
176
+ _ref5$isInserted = _ref5.isInserted,
177
+ isInserted = _ref5$isInserted === void 0 ? true : _ref5$isInserted,
178
+ activeIndexPos = _ref5.activeIndexPos,
179
+ _ref5$shouldHideDelet = _ref5.shouldHideDeleted,
180
+ shouldHideDeleted = _ref5$shouldHideDelet === void 0 ? false : _ref5$shouldHideDelet,
181
+ _ref5$showIndicators = _ref5.showIndicators,
182
+ showIndicators = _ref5$showIndicators === void 0 ? false : _ref5$showIndicators,
183
+ diffType = _ref5.diffType,
184
+ _ref5$coarseTableCell = _ref5.coarseTableCellsOnly,
185
+ coarseTableCellsOnly = _ref5$coarseTableCell === void 0 ? false : _ref5$coarseTableCell;
155
186
  var decorations = [];
156
187
  // Coarse path: inside the large table, only cell/header overlays are kept — the
157
188
  // table/row/paragraph decorations there are redundant and cause expensive per-cell
@@ -197,10 +228,10 @@ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration
197
228
  *
198
229
  * Callers are responsible for the `smart` diffType and gate checks.
199
230
  */
200
- var isDeletedContentPlacedBelow = exports.isDeletedContentPlacedBelow = function isDeletedContentPlacedBelow(_ref5) {
201
- var change = _ref5.change,
202
- deletedDiffPlacement = _ref5.deletedDiffPlacement,
203
- inlineDeletedDiffPlacement = _ref5.inlineDeletedDiffPlacement;
231
+ var isDeletedContentPlacedBelow = exports.isDeletedContentPlacedBelow = function isDeletedContentPlacedBelow(_ref6) {
232
+ var change = _ref6.change,
233
+ deletedDiffPlacement = _ref6.deletedDiffPlacement,
234
+ inlineDeletedDiffPlacement = _ref6.inlineDeletedDiffPlacement;
204
235
  var level = (0, _helpers.smartChangeLevel)(change);
205
236
  if (level === 'node' || level === 'paragraph') {
206
237
  return deletedDiffPlacement === 'bottom';
@@ -209,31 +240,32 @@ var isDeletedContentPlacedBelow = exports.isDeletedContentPlacedBelow = function
209
240
  // Inline-level (undefined) and sentence-level changes.
210
241
  return inlineDeletedDiffPlacement === 'after';
211
242
  };
212
- var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6) {
213
- var state = _ref6.state,
214
- pluginState = _ref6.pluginState,
215
- nodeViewSerializer = _ref6.nodeViewSerializer,
216
- colorScheme = _ref6.colorScheme,
217
- intl = _ref6.intl,
218
- activeIndexPos = _ref6.activeIndexPos,
219
- api = _ref6.api,
220
- _ref6$isInverted = _ref6.isInverted,
221
- isInverted = _ref6$isInverted === void 0 ? false : _ref6$isInverted,
222
- _ref6$diffType = _ref6.diffType,
223
- diffType = _ref6$diffType === void 0 ? (0, _isExtendedEnabled.getDefaultDiffType)() : _ref6$diffType,
224
- _ref6$hideDeletedDiff = _ref6.hideDeletedDiffs,
225
- hideDeletedDiffs = _ref6$hideDeletedDiff === void 0 ? false : _ref6$hideDeletedDiff,
226
- _ref6$hideAddedDiffsU = _ref6.hideAddedDiffsUnderline,
227
- hideAddedDiffsUnderlineParam = _ref6$hideAddedDiffsU === void 0 ? false : _ref6$hideAddedDiffsU,
228
- _ref6$showIndicators = _ref6.showIndicators,
229
- showIndicators = _ref6$showIndicators === void 0 ? false : _ref6$showIndicators,
230
- smartThresholds = _ref6.smartThresholds,
231
- _ref6$deletedDiffPlac = _ref6.deletedDiffPlacement,
232
- deletedDiffPlacement = _ref6$deletedDiffPlac === void 0 ? 'top' : _ref6$deletedDiffPlac,
233
- _ref6$inlineDeletedDi = _ref6.inlineDeletedDiffPlacement,
234
- inlineDeletedDiffPlacement = _ref6$inlineDeletedDi === void 0 ? 'before' : _ref6$inlineDeletedDi;
243
+ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref7) {
244
+ var state = _ref7.state,
245
+ pluginState = _ref7.pluginState,
246
+ nodeViewSerializer = _ref7.nodeViewSerializer,
247
+ colorScheme = _ref7.colorScheme,
248
+ intl = _ref7.intl,
249
+ activeIndexPos = _ref7.activeIndexPos,
250
+ api = _ref7.api,
251
+ _ref7$isInverted = _ref7.isInverted,
252
+ isInverted = _ref7$isInverted === void 0 ? false : _ref7$isInverted,
253
+ _ref7$diffType = _ref7.diffType,
254
+ diffType = _ref7$diffType === void 0 ? (0, _isExtendedEnabled.getDefaultDiffType)() : _ref7$diffType,
255
+ _ref7$hideDeletedDiff = _ref7.hideDeletedDiffs,
256
+ hideDeletedDiffs = _ref7$hideDeletedDiff === void 0 ? false : _ref7$hideDeletedDiff,
257
+ _ref7$hideAddedDiffsU = _ref7.hideAddedDiffsUnderline,
258
+ hideAddedDiffsUnderlineParam = _ref7$hideAddedDiffsU === void 0 ? false : _ref7$hideAddedDiffsU,
259
+ _ref7$showIndicators = _ref7.showIndicators,
260
+ showIndicators = _ref7$showIndicators === void 0 ? false : _ref7$showIndicators,
261
+ smartThresholds = _ref7.smartThresholds,
262
+ _ref7$deletedDiffPlac = _ref7.deletedDiffPlacement,
263
+ deletedDiffPlacement = _ref7$deletedDiffPlac === void 0 ? 'top' : _ref7$deletedDiffPlac,
264
+ _ref7$inlineDeletedDi = _ref7.inlineDeletedDiffPlacement,
265
+ inlineDeletedDiffPlacement = _ref7$inlineDeletedDi === void 0 ? 'before' : _ref7$inlineDeletedDi;
235
266
  var originalDoc = pluginState.originalDoc,
236
267
  steps = pluginState.steps,
268
+ stepAttributions = pluginState.stepAttributions,
237
269
  isDisplayingChanges = pluginState.isDisplayingChanges;
238
270
  if (!originalDoc || !isDisplayingChanges) {
239
271
  return {
@@ -247,8 +279,23 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
247
279
  var hideAddedDiffsUnderline = hideAddedDiffsUnderlineParam && (0, _fg.fg)('platform_editor_ai_smart_diff');
248
280
  var tr = state.tr;
249
281
  var steppedDoc = originalDoc;
250
- var attrSteps = [];
251
- var simplifiedSteps = (0, _simplifySteps.simplifySteps)(steps, originalDoc);
282
+ var attributionColoringEnabled = (0, _attributions.isAttributionColoringEnabled)(stepAttributions);
283
+ var simplifiedSteps;
284
+ var simplifiedStepAttributions = [];
285
+ if (attributionColoringEnabled) {
286
+ var simplifiedStepsWithAttribution = (0, _simplifySteps.simplifyStepsWithAttribution)(steps, stepAttributions !== null && stepAttributions !== void 0 ? stepAttributions : [], originalDoc);
287
+ simplifiedSteps = simplifiedStepsWithAttribution.map(function (_ref8) {
288
+ var step = _ref8.step;
289
+ return step;
290
+ });
291
+ simplifiedStepAttributions = simplifiedStepsWithAttribution.map(function (_ref9) {
292
+ var stepAttribution = _ref9.stepAttribution;
293
+ return stepAttribution;
294
+ });
295
+ } else {
296
+ simplifiedSteps = (0, _simplifySteps.simplifySteps)(steps, originalDoc);
297
+ }
298
+ var pendingAttrSteps = [];
252
299
  var stepMaps = [];
253
300
  var _iterator = _createForOfIteratorHelper(simplifiedSteps),
254
301
  _step;
@@ -258,20 +305,56 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
258
305
  var result = step.apply(steppedDoc);
259
306
  if (result.failed === null && result.doc) {
260
307
  if ((0, _getAttrChangeRanges.stepIsValidAttrChange)(step, steppedDoc, result.doc)) {
261
- attrSteps.push(step);
308
+ pendingAttrSteps.push({
309
+ afterNode: result.doc.nodeAt(step.pos),
310
+ beforeNode: steppedDoc.nodeAt(step.pos),
311
+ mapIndex: stepMaps.length,
312
+ step: step
313
+ });
262
314
  }
263
315
  stepMaps.push(step.getMap());
264
316
  steppedDoc = result.doc;
265
317
  }
266
318
  }
267
-
268
- // Rather than using .eq() we use a custom function that only checks for structural
269
- // changes and ignores differences in attributes which don't affect decoration positions
319
+ // Gate the complete attribution fix: mapped positions and step-time nodes are used together.
320
+ // The fallback deliberately preserves the legacy raw-position lookups for rollout safety.
270
321
  } catch (err) {
271
322
  _iterator.e(err);
272
323
  } finally {
273
324
  _iterator.f();
274
325
  }
326
+ var attrStepContexts = (0, _fg.fg)('platform_editor_reduce_diff_attr_sensitivity') ? pendingAttrSteps.flatMap(function (_ref0) {
327
+ var afterNode = _ref0.afterNode,
328
+ beforeNode = _ref0.beforeNode,
329
+ mapIndex = _ref0.mapIndex,
330
+ step = _ref0.step;
331
+ var finalPosition = new _transform.Mapping(stepMaps.slice(mapIndex + 1)).mapResult(step.pos);
332
+ if (finalPosition.deleted) {
333
+ return [];
334
+ }
335
+ var originalPosition = new _transform.Mapping(stepMaps.slice(0, mapIndex)).invert().mapResult(step.pos);
336
+ return [_objectSpread(_objectSpread({
337
+ afterNode: afterNode,
338
+ beforeNode: beforeNode,
339
+ finalPos: finalPosition.pos
340
+ }, originalPosition.deleted ? {} : {
341
+ originalPos: originalPosition.pos
342
+ }), {}, {
343
+ step: step
344
+ })];
345
+ }) : pendingAttrSteps.map(function (_ref1) {
346
+ var step = _ref1.step;
347
+ return {
348
+ afterNode: tr.doc.nodeAt(step.pos),
349
+ beforeNode: originalDoc.nodeAt(step.pos),
350
+ finalPos: step.pos,
351
+ originalPos: step.pos,
352
+ step: step
353
+ };
354
+ });
355
+
356
+ // Rather than using .eq() we use a custom function that only checks for structural
357
+ // changes and ignores differences in attributes which don't affect decoration positions
275
358
  if (!(0, _document.areNodesEqualIgnoreAttrs)(steppedDoc, tr.doc)) {
276
359
  var _api$analytics;
277
360
  var recoveredViaContentEquality = (0, _areDocsEqualByBlockStructureAndText.areDocsEqualByBlockStructureAndText)(steppedDoc, tr.doc);
@@ -296,17 +379,45 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
296
379
  // gated with it; other diff types keep the library default so their output is
297
380
  // unchanged.
298
381
  var tokenEncoder = diffType === 'smart' && (0, _fg.fg)('platform_editor_ai_smart_diff') ? _attrAwareTokenEncoder.attrAwareTokenEncoder : undefined;
299
- var changeset = _prosemirrorChangeset.ChangeSet.create(originalDoc, undefined, tokenEncoder).addSteps(steppedDoc, stepMaps, tr.doc);
300
- var changes = getChanges({
301
- changeset: changeset,
302
- originalDoc: originalDoc,
303
- steppedDoc: steppedDoc,
304
- diffType: diffType,
305
- tr: tr,
306
- steps: steps,
307
- intl: intl,
308
- smartThresholds: smartThresholds
309
- });
382
+ var changes;
383
+ var attributedChanges = [];
384
+ var attributionColors;
385
+ if (attributionColoringEnabled) {
386
+ var changeset = _prosemirrorChangeset.ChangeSet.create(originalDoc, function (left, right) {
387
+ return (0, _attributions.getAttributionKey)(left) === (0, _attributions.getAttributionKey)(right) ? left.stepIndex > right.stepIndex ? left : right :
388
+ // `prosemirror-changeset` uses null as its incompatible-data sentinel even
389
+ // though its public combine callback is typed as returning Data.
390
+ null;
391
+ }, tokenEncoder).addSteps(steppedDoc, stepMaps, simplifiedStepAttributions.map(function (attribution, stepIndex) {
392
+ return _objectSpread(_objectSpread({}, attribution), {}, {
393
+ stepIndex: stepIndex
394
+ });
395
+ }));
396
+ attributedChanges = (0, _diffBySteps.diffBySteps)(originalDoc, simplifiedSteps, simplifiedStepAttributions);
397
+ changes = getAttributedChanges({
398
+ changeset: changeset,
399
+ originalDoc: originalDoc,
400
+ steppedDoc: steppedDoc,
401
+ diffType: diffType,
402
+ tr: tr,
403
+ attributedChanges: attributedChanges,
404
+ intl: intl,
405
+ smartThresholds: smartThresholds
406
+ });
407
+ attributionColors = (0, _attributions.createAttributionColorMap)(simplifiedStepAttributions);
408
+ } else {
409
+ var _changeset = _prosemirrorChangeset.ChangeSet.create(originalDoc, undefined, tokenEncoder).addSteps(steppedDoc, stepMaps, tr.doc);
410
+ changes = getChanges({
411
+ changeset: _changeset,
412
+ originalDoc: originalDoc,
413
+ steppedDoc: steppedDoc,
414
+ diffType: diffType,
415
+ tr: tr,
416
+ steps: simplifiedSteps,
417
+ intl: intl,
418
+ smartThresholds: smartThresholds
419
+ });
420
+ }
310
421
  var decorations = [];
311
422
 
312
423
  /**
@@ -319,6 +430,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
319
430
  // Our default operations are insertions, so it should match the opposite of isInverted.
320
431
  var isInserted = !isInverted;
321
432
  var createDecorationsForChange = function createDecorationsForChange(change) {
433
+ var changeColorScheme = attributionColors ? (0, _attributions.getColorSchemeForChange)(change, attributedChanges, attributionColors, colorScheme) : colorScheme;
322
434
  var isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
323
435
 
324
436
  // Hoisted because it decides BOTH where the deleted widget is anchored and — since the
@@ -373,7 +485,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
373
485
  toB: to
374
486
  },
375
487
  doc: tr.doc,
376
- colorScheme: colorScheme,
488
+ colorScheme: changeColorScheme,
377
489
  isActive: isActive,
378
490
  diffType: diffType
379
491
  }, (0, _isExtendedEnabled.isExtendedEnabled)(diffType) && {
@@ -394,7 +506,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
394
506
  decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createInlineChangedDecoration.createInlineChangedDecoration)(_objectSpread({
395
507
  change: change,
396
508
  doc: tr.doc,
397
- colorScheme: colorScheme,
509
+ colorScheme: changeColorScheme,
398
510
  isActive: isActive,
399
511
  diffType: diffType
400
512
  }, (0, _isExtendedEnabled.isExtendedEnabled)(diffType) && {
@@ -410,7 +522,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
410
522
  doc: tr.doc,
411
523
  from: change.fromB,
412
524
  to: change.toB,
413
- colorScheme: colorScheme
525
+ colorScheme: changeColorScheme
414
526
  }, (0, _isExtendedEnabled.isExtendedEnabled)(diffType) && {
415
527
  isInserted: isInserted,
416
528
  shouldHideDeleted: shouldHideDeleted,
@@ -429,7 +541,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
429
541
  change: change,
430
542
  doc: originalDoc,
431
543
  nodeViewSerializer: nodeViewSerializer,
432
- colorScheme: colorScheme,
544
+ colorScheme: changeColorScheme,
433
545
  newDoc: tr.doc,
434
546
  intl: intl,
435
547
  activeIndexPos: activeIndexPos
@@ -456,7 +568,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
456
568
  isInserted: true
457
569
  })));
458
570
  });
459
- (0, _getAttrChangeRanges.getAttrChangeRanges)(tr.doc, attrSteps, originalDoc).forEach(function (change) {
571
+ (0, _getAttrChangeRanges.getAttrChangeRanges)(tr.doc, attrStepContexts, originalDoc).forEach(function (change) {
460
572
  if (change.isInline) {
461
573
  // Inline nodes (e.g. date, emoji, mention, status) need an inline decoration rather than a block decoration
462
574
  var isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
@@ -546,42 +658,42 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
546
658
  };
547
659
  var calculateDiffDecorations = exports.calculateDiffDecorations = (0, _memoizeOne.default)(calculateDiffDecorationsInner,
548
660
  // Cache results unless relevant inputs change
549
- function (_ref7, _ref8) {
550
- var _ref10;
551
- var _ref9 = (0, _slicedToArray2.default)(_ref7, 1),
552
- _ref9$ = _ref9[0],
553
- pluginState = _ref9$.pluginState,
554
- state = _ref9$.state,
555
- colorScheme = _ref9$.colorScheme,
556
- intl = _ref9$.intl,
557
- activeIndexPos = _ref9$.activeIndexPos,
558
- isInverted = _ref9$.isInverted,
559
- diffType = _ref9$.diffType,
560
- hideDeletedDiffs = _ref9$.hideDeletedDiffs,
561
- hideAddedDiffsUnderline = _ref9$.hideAddedDiffsUnderline,
562
- showIndicators = _ref9$.showIndicators,
563
- smartThresholds = _ref9$.smartThresholds,
564
- deletedDiffPlacement = _ref9$.deletedDiffPlacement,
565
- inlineDeletedDiffPlacement = _ref9$.inlineDeletedDiffPlacement;
566
- var _ref0 = (0, _slicedToArray2.default)(_ref8, 1),
567
- _ref0$ = _ref0[0],
568
- lastPluginState = _ref0$.pluginState,
569
- lastState = _ref0$.state,
570
- lastColorScheme = _ref0$.colorScheme,
571
- lastIntl = _ref0$.intl,
572
- lastActiveIndexPos = _ref0$.activeIndexPos,
573
- lastIsInverted = _ref0$.isInverted,
574
- lastDiffType = _ref0$.diffType,
575
- lastHideDeletedDiffs = _ref0$.hideDeletedDiffs,
576
- lastHideAddedDiffsUnderline = _ref0$.hideAddedDiffsUnderline,
577
- lastShowIndicators = _ref0$.showIndicators,
578
- lastSmartThresholds = _ref0$.smartThresholds,
579
- lastDeletedDiffPlacement = _ref0$.deletedDiffPlacement,
580
- lastInlineDeletedDiffPlacement = _ref0$.inlineDeletedDiffPlacement;
661
+ function (_ref10, _ref11) {
662
+ var _ref15;
663
+ var _ref12 = (0, _slicedToArray2.default)(_ref10, 1),
664
+ _ref12$ = _ref12[0],
665
+ pluginState = _ref12$.pluginState,
666
+ state = _ref12$.state,
667
+ colorScheme = _ref12$.colorScheme,
668
+ intl = _ref12$.intl,
669
+ activeIndexPos = _ref12$.activeIndexPos,
670
+ isInverted = _ref12$.isInverted,
671
+ diffType = _ref12$.diffType,
672
+ hideDeletedDiffs = _ref12$.hideDeletedDiffs,
673
+ hideAddedDiffsUnderline = _ref12$.hideAddedDiffsUnderline,
674
+ showIndicators = _ref12$.showIndicators,
675
+ smartThresholds = _ref12$.smartThresholds,
676
+ deletedDiffPlacement = _ref12$.deletedDiffPlacement,
677
+ inlineDeletedDiffPlacement = _ref12$.inlineDeletedDiffPlacement;
678
+ var _ref13 = (0, _slicedToArray2.default)(_ref11, 1),
679
+ _ref13$ = _ref13[0],
680
+ lastPluginState = _ref13$.pluginState,
681
+ lastState = _ref13$.state,
682
+ lastColorScheme = _ref13$.colorScheme,
683
+ lastIntl = _ref13$.intl,
684
+ lastActiveIndexPos = _ref13$.activeIndexPos,
685
+ lastIsInverted = _ref13$.isInverted,
686
+ lastDiffType = _ref13$.diffType,
687
+ lastHideDeletedDiffs = _ref13$.hideDeletedDiffs,
688
+ lastHideAddedDiffsUnderline = _ref13$.hideAddedDiffsUnderline,
689
+ lastShowIndicators = _ref13$.showIndicators,
690
+ lastSmartThresholds = _ref13$.smartThresholds,
691
+ lastDeletedDiffPlacement = _ref13$.deletedDiffPlacement,
692
+ lastInlineDeletedDiffPlacement = _ref13$.inlineDeletedDiffPlacement;
581
693
  var originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
582
694
  if ((0, _isExtendedEnabled.isExtendedEnabled)(diffType)) {
583
- var _ref1;
584
- return (_ref1 = colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isInverted === lastIsInverted && diffType === lastDiffType && (0, _isEqual.default)(activeIndexPos, lastActiveIndexPos) && originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && hideDeletedDiffs === lastHideDeletedDiffs && hideAddedDiffsUnderline === lastHideAddedDiffsUnderline && showIndicators === lastShowIndicators && (0, _isEqual.default)(smartThresholds, lastSmartThresholds) && deletedDiffPlacement === lastDeletedDiffPlacement && inlineDeletedDiffPlacement === lastInlineDeletedDiffPlacement) !== null && _ref1 !== void 0 ? _ref1 : false;
695
+ var _ref14;
696
+ return (_ref14 = colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isInverted === lastIsInverted && diffType === lastDiffType && (0, _isEqual.default)(activeIndexPos, lastActiveIndexPos) && originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && (0, _isEqual.default)(pluginState.stepAttributions, lastPluginState.stepAttributions) && state.doc.eq(lastState.doc) && hideDeletedDiffs === lastHideDeletedDiffs && hideAddedDiffsUnderline === lastHideAddedDiffsUnderline && showIndicators === lastShowIndicators && (0, _isEqual.default)(smartThresholds, lastSmartThresholds) && deletedDiffPlacement === lastDeletedDiffPlacement && inlineDeletedDiffPlacement === lastInlineDeletedDiffPlacement) !== null && _ref14 !== void 0 ? _ref14 : false;
585
697
  }
586
- return (_ref10 = originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && (0, _isEqual.default)(activeIndexPos, lastActiveIndexPos) && hideDeletedDiffs === lastHideDeletedDiffs) !== null && _ref10 !== void 0 ? _ref10 : false;
698
+ return (_ref15 = originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && (0, _isEqual.default)(pluginState.stepAttributions, lastPluginState.stepAttributions) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && (0, _isEqual.default)(activeIndexPos, lastActiveIndexPos) && hideDeletedDiffs === lastHideDeletedDiffs) !== null && _ref15 !== void 0 ? _ref15 : false;
587
699
  });
@@ -5,11 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.diffBySteps = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
8
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
11
  var _prosemirrorChangeset = require("prosemirror-changeset");
11
12
  var _model = require("@atlaskit/editor-prosemirror/model");
12
13
  var _transform = require("@atlaskit/editor-prosemirror/transform");
14
+ var _attributions = require("../decorations/colorSchemes/attributions");
13
15
  var _attrAwareTokenEncoder = require("./attrAwareTokenEncoder");
14
16
  var _optimizeChanges = require("./optimizeChanges");
15
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; }
@@ -205,9 +207,10 @@ var createMapping = function createMapping(maps) {
205
207
  return mapping;
206
208
  };
207
209
  var createSpans = function createSpans(length) {
210
+ var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
208
211
  return length > 0 ? [{
209
212
  length: length,
210
- data: null
213
+ data: data
211
214
  }] : [];
212
215
  };
213
216
  var mergeOverlappingByNewDocRange = function mergeOverlappingByNewDocRange(changes) {
@@ -220,8 +223,11 @@ var mergeOverlappingByNewDocRange = function mergeOverlappingByNewDocRange(chang
220
223
  var merged = [];
221
224
  var current = _objectSpread({}, sortedChanges[0]);
222
225
  for (var i = 1; i < sortedChanges.length; i++) {
226
+ var _, _2;
223
227
  var next = sortedChanges[i];
224
- var isOverlapping = next.fromB <= current.toB;
228
+ var currentIdentity = (0, _attributions.getAttributionKey)((_ = [].concat((0, _toConsumableArray2.default)(current.deleted), (0, _toConsumableArray2.default)(current.inserted))[0]) === null || _ === void 0 ? void 0 : _.data);
229
+ var nextIdentity = (0, _attributions.getAttributionKey)((_2 = [].concat((0, _toConsumableArray2.default)(next.deleted), (0, _toConsumableArray2.default)(next.inserted))[0]) === null || _2 === void 0 ? void 0 : _2.data);
230
+ var isOverlapping = next.fromB <= current.toB && currentIdentity === nextIdentity;
225
231
  if (isOverlapping) {
226
232
  current = {
227
233
  fromA: Math.min(current.fromA, next.fromA),
@@ -275,16 +281,18 @@ var shouldCheckGranularDiff = function shouldCheckGranularDiff(step, before, fro
275
281
  var isTextContentEqual = (replacedNode === null || replacedNode === void 0 ? void 0 : replacedNode.textContent) === (replacingNode === null || replacingNode === void 0 ? void 0 : replacingNode.textContent);
276
282
  return !isTextContentEqual || isTextContentEqual && hasSameChildMarks(replacedNode, replacingNode);
277
283
  };
278
- var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps) {
284
+ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps, stepAttributions) {
279
285
  var changes = [];
280
286
  var currentDoc = originalDoc;
281
287
  var successfulStepMaps = [];
282
288
  var rangedSteps = [];
283
- var _iterator2 = _createForOfIteratorHelper(steps),
289
+ var _iterator2 = _createForOfIteratorHelper(steps.entries()),
284
290
  _step2;
285
291
  try {
286
292
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
287
- var step = _step2.value;
293
+ var _step2$value = (0, _slicedToArray2.default)(_step2.value, 2),
294
+ stepIndex = _step2$value[0],
295
+ step = _step2$value[1];
288
296
  var before = currentDoc;
289
297
  var result = step.apply(currentDoc);
290
298
  if (result.failed !== null || !result.doc) {
@@ -299,6 +307,9 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
299
307
  from: rangeStep.from,
300
308
  to: rangeStep.to,
301
309
  mapIndex: successfulStepMaps.length,
310
+ stepAttribution: stepAttributions !== null && stepAttributions !== void 0 && stepAttributions[stepIndex] ? _objectSpread(_objectSpread({}, stepAttributions[stepIndex]), {}, {
311
+ stepIndex: stepIndex
312
+ }) : null,
302
313
  step: step,
303
314
  stepMap: stepMap
304
315
  });
@@ -384,8 +395,8 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
384
395
  toA: granularToA,
385
396
  fromB: granularFromB,
386
397
  toB: granularToB,
387
- deleted: createSpans(Math.max(0, granularToA - granularFromA)),
388
- inserted: createSpans(Math.max(0, granularToB - granularFromB))
398
+ deleted: createSpans(Math.max(0, granularToA - granularFromA), rangedStep.stepAttribution),
399
+ inserted: createSpans(Math.max(0, granularToB - granularFromB), rangedStep.stepAttribution)
389
400
  });
390
401
  }
391
402
  } catch (err) {
@@ -400,8 +411,8 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
400
411
  toA: toA,
401
412
  fromB: fromB,
402
413
  toB: toB,
403
- deleted: createSpans(Math.max(0, toA - fromA)),
404
- inserted: createSpans(Math.max(0, toB - fromB))
414
+ deleted: createSpans(Math.max(0, toA - fromA), rangedStep.stepAttribution),
415
+ inserted: createSpans(Math.max(0, toB - fromB), rangedStep.stepAttribution)
405
416
  });
406
417
  }
407
418
  return mergeOverlappingByNewDocRange(changes);