@atlaskit/editor-plugin-show-diff 14.0.4 → 14.1.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 (56) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +172 -97
  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/wrapBlockNodeViewStyles.js +14 -10
  13. package/dist/cjs/pm-plugins/main.js +1 -0
  14. package/dist/cjs/showDiffPlugin.js +36 -14
  15. package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +90 -19
  16. package/dist/es2019/pm-plugins/calculateDiff/diffBySteps.js +17 -9
  17. package/dist/es2019/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +64 -0
  18. package/dist/es2019/pm-plugins/calculateDiff/simplifySteps.js +64 -1
  19. package/dist/es2019/pm-plugins/decorations/colorSchemes/attributions.js +37 -0
  20. package/dist/es2019/pm-plugins/decorations/colorSchemes/schemes.js +19 -2
  21. package/dist/es2019/pm-plugins/decorations/colorSchemes/types.js +1 -0
  22. package/dist/es2019/pm-plugins/decorations/createBlockChangedDecoration.js +6 -3
  23. package/dist/es2019/pm-plugins/decorations/createChangedRowDecorationWidgets.js +3 -3
  24. package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +6 -3
  25. package/dist/es2019/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +12 -9
  26. package/dist/es2019/pm-plugins/main.js +1 -0
  27. package/dist/es2019/showDiffPlugin.js +23 -1
  28. package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +173 -98
  29. package/dist/esm/pm-plugins/calculateDiff/diffBySteps.js +20 -9
  30. package/dist/esm/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +82 -0
  31. package/dist/esm/pm-plugins/calculateDiff/simplifySteps.js +79 -5
  32. package/dist/esm/pm-plugins/decorations/colorSchemes/attributions.js +61 -0
  33. package/dist/esm/pm-plugins/decorations/colorSchemes/schemes.js +24 -1
  34. package/dist/esm/pm-plugins/decorations/colorSchemes/types.js +1 -0
  35. package/dist/esm/pm-plugins/decorations/createBlockChangedDecoration.js +8 -3
  36. package/dist/esm/pm-plugins/decorations/createChangedRowDecorationWidgets.js +3 -3
  37. package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +5 -3
  38. package/dist/esm/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +14 -9
  39. package/dist/esm/pm-plugins/main.js +1 -0
  40. package/dist/esm/showDiffPlugin.js +36 -14
  41. package/dist/types/entry-points/show-diff-plugin-type.d.ts +1 -1
  42. package/dist/types/pm-plugins/calculateDiff/diffBySteps.d.ts +2 -1
  43. package/dist/types/pm-plugins/calculateDiff/simplifyChangesWithAttribution.d.ts +7 -0
  44. package/dist/types/pm-plugins/calculateDiff/simplifySteps.d.ts +10 -0
  45. package/dist/types/pm-plugins/decorations/colorSchemes/attributions.d.ts +12 -0
  46. package/dist/types/pm-plugins/decorations/colorSchemes/schemes.d.ts +5 -3
  47. package/dist/types/pm-plugins/decorations/colorSchemes/types.d.ts +6 -1
  48. package/dist/types/pm-plugins/decorations/createBlockChangedDecoration.d.ts +2 -1
  49. package/dist/types/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +2 -1
  50. package/dist/types/pm-plugins/decorations/createInlineChangedDecoration.d.ts +2 -1
  51. package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +2 -1
  52. package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +2 -1
  53. package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.d.ts +2 -1
  54. package/dist/types/pm-plugins/main.d.ts +3 -1
  55. package/dist/types/showDiffPluginType.d.ts +29 -1
  56. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/editor-plugin-show-diff
2
2
 
3
+ ## 14.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`69574af99ed9e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/69574af99ed9e) -
8
+ [ux] Add attributed-step inputs and internally selected, gated agent colours behind
9
+ `confluence_ncs_step_diffing_version_history` and
10
+ `platform_editor_show_diff_color_scheme_refactor`.
11
+
3
12
  ## 14.0.4
4
13
 
5
14
  ### Patch Changes
@@ -21,6 +21,7 @@ var _createAnchorDecorationWidgets = require("../decorations/createAnchorDecorat
21
21
  var _createBlockChangedDecoration = require("../decorations/createBlockChangedDecoration");
22
22
  var _createInlineChangedDecoration = require("../decorations/createInlineChangedDecoration");
23
23
  var _createNodeChangedDecorationWidget = require("../decorations/createNodeChangedDecorationWidget");
24
+ var _attributions = require("../decorations/colorSchemes/attributions");
24
25
  var _decorationKeys = require("../decorations/decorationKeys");
25
26
  var _getAttrChangeRanges = require("../decorations/utils/getAttrChangeRanges");
26
27
  var _getMarkChangeRanges = require("../decorations/utils/getMarkChangeRanges");
@@ -29,6 +30,7 @@ var _attrAwareTokenEncoder = require("./attrAwareTokenEncoder");
29
30
  var _diffBySteps = require("./diffBySteps");
30
31
  var _groupChangesByBlock = require("./groupChangesByBlock");
31
32
  var _optimizeChanges = require("./optimizeChanges");
33
+ var _simplifyChangesWithAttribution = require("./simplifyChangesWithAttribution");
32
34
  var _simplifySteps = require("./simplifySteps");
33
35
  var _classifySmartChanges = require("./smart/classifySmartChanges");
34
36
  var _helpers = require("./smart/helpers");
@@ -72,6 +74,34 @@ var getChanges = function getChanges(_ref) {
72
74
  var changes = (0, _prosemirrorChangeset.simplifyChanges)(changeset.changes, tr.doc);
73
75
  return (0, _optimizeChanges.optimizeChanges)(changes);
74
76
  };
77
+ var getAttributedChanges = function getAttributedChanges(_ref2) {
78
+ var attributedChanges = _ref2.attributedChanges,
79
+ changeset = _ref2.changeset,
80
+ originalDoc = _ref2.originalDoc,
81
+ steppedDoc = _ref2.steppedDoc,
82
+ diffType = _ref2.diffType,
83
+ tr = _ref2.tr,
84
+ intl = _ref2.intl,
85
+ smartThresholds = _ref2.smartThresholds;
86
+ if ((0, _isExtendedEnabled.isExtendedEnabled)(diffType)) {
87
+ if (diffType === 'smart' && (0, _fg.fg)('platform_editor_ai_smart_diff')) {
88
+ return (0, _classifySmartChanges.classifySmartChanges)({
89
+ changes: (0, _simplifyChangesWithAttribution.simplifyChangesWithAttribution)(attributedChanges, tr.doc),
90
+ originalDoc: originalDoc,
91
+ newDoc: tr.doc,
92
+ locale: intl.locale,
93
+ thresholds: smartThresholds
94
+ });
95
+ }
96
+ if (diffType === 'step') {
97
+ return attributedChanges;
98
+ }
99
+ if (diffType === 'block') {
100
+ return (0, _groupChangesByBlock.groupChangesByBlock)(changeset.changes, originalDoc, steppedDoc);
101
+ }
102
+ }
103
+ return (0, _simplifyChangesWithAttribution.simplifyChangesWithAttribution)(attributedChanges, tr.doc);
104
+ };
75
105
 
76
106
  /**
77
107
  * Collect the inline-content ranges of every leaf text-bearing block (paragraph, heading, …)
@@ -130,28 +160,28 @@ var tableRanges = function tableRanges(doc, from, to) {
130
160
  return ranges;
131
161
  };
132
162
  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];
163
+ return tables.some(function (_ref3) {
164
+ var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
165
+ tFrom = _ref4[0],
166
+ tTo = _ref4[1];
137
167
  return pos >= tFrom && pos < tTo;
138
168
  });
139
169
  };
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;
170
+ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration(_ref5) {
171
+ var doc = _ref5.doc,
172
+ from = _ref5.from,
173
+ to = _ref5.to,
174
+ colorScheme = _ref5.colorScheme,
175
+ _ref5$isInserted = _ref5.isInserted,
176
+ isInserted = _ref5$isInserted === void 0 ? true : _ref5$isInserted,
177
+ activeIndexPos = _ref5.activeIndexPos,
178
+ _ref5$shouldHideDelet = _ref5.shouldHideDeleted,
179
+ shouldHideDeleted = _ref5$shouldHideDelet === void 0 ? false : _ref5$shouldHideDelet,
180
+ _ref5$showIndicators = _ref5.showIndicators,
181
+ showIndicators = _ref5$showIndicators === void 0 ? false : _ref5$showIndicators,
182
+ diffType = _ref5.diffType,
183
+ _ref5$coarseTableCell = _ref5.coarseTableCellsOnly,
184
+ coarseTableCellsOnly = _ref5$coarseTableCell === void 0 ? false : _ref5$coarseTableCell;
155
185
  var decorations = [];
156
186
  // Coarse path: inside the large table, only cell/header overlays are kept — the
157
187
  // table/row/paragraph decorations there are redundant and cause expensive per-cell
@@ -197,10 +227,10 @@ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration
197
227
  *
198
228
  * Callers are responsible for the `smart` diffType and gate checks.
199
229
  */
200
- var isDeletedContentPlacedBelow = exports.isDeletedContentPlacedBelow = function isDeletedContentPlacedBelow(_ref5) {
201
- var change = _ref5.change,
202
- deletedDiffPlacement = _ref5.deletedDiffPlacement,
203
- inlineDeletedDiffPlacement = _ref5.inlineDeletedDiffPlacement;
230
+ var isDeletedContentPlacedBelow = exports.isDeletedContentPlacedBelow = function isDeletedContentPlacedBelow(_ref6) {
231
+ var change = _ref6.change,
232
+ deletedDiffPlacement = _ref6.deletedDiffPlacement,
233
+ inlineDeletedDiffPlacement = _ref6.inlineDeletedDiffPlacement;
204
234
  var level = (0, _helpers.smartChangeLevel)(change);
205
235
  if (level === 'node' || level === 'paragraph') {
206
236
  return deletedDiffPlacement === 'bottom';
@@ -209,31 +239,32 @@ var isDeletedContentPlacedBelow = exports.isDeletedContentPlacedBelow = function
209
239
  // Inline-level (undefined) and sentence-level changes.
210
240
  return inlineDeletedDiffPlacement === 'after';
211
241
  };
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;
242
+ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref7) {
243
+ var state = _ref7.state,
244
+ pluginState = _ref7.pluginState,
245
+ nodeViewSerializer = _ref7.nodeViewSerializer,
246
+ colorScheme = _ref7.colorScheme,
247
+ intl = _ref7.intl,
248
+ activeIndexPos = _ref7.activeIndexPos,
249
+ api = _ref7.api,
250
+ _ref7$isInverted = _ref7.isInverted,
251
+ isInverted = _ref7$isInverted === void 0 ? false : _ref7$isInverted,
252
+ _ref7$diffType = _ref7.diffType,
253
+ diffType = _ref7$diffType === void 0 ? (0, _isExtendedEnabled.getDefaultDiffType)() : _ref7$diffType,
254
+ _ref7$hideDeletedDiff = _ref7.hideDeletedDiffs,
255
+ hideDeletedDiffs = _ref7$hideDeletedDiff === void 0 ? false : _ref7$hideDeletedDiff,
256
+ _ref7$hideAddedDiffsU = _ref7.hideAddedDiffsUnderline,
257
+ hideAddedDiffsUnderlineParam = _ref7$hideAddedDiffsU === void 0 ? false : _ref7$hideAddedDiffsU,
258
+ _ref7$showIndicators = _ref7.showIndicators,
259
+ showIndicators = _ref7$showIndicators === void 0 ? false : _ref7$showIndicators,
260
+ smartThresholds = _ref7.smartThresholds,
261
+ _ref7$deletedDiffPlac = _ref7.deletedDiffPlacement,
262
+ deletedDiffPlacement = _ref7$deletedDiffPlac === void 0 ? 'top' : _ref7$deletedDiffPlac,
263
+ _ref7$inlineDeletedDi = _ref7.inlineDeletedDiffPlacement,
264
+ inlineDeletedDiffPlacement = _ref7$inlineDeletedDi === void 0 ? 'before' : _ref7$inlineDeletedDi;
235
265
  var originalDoc = pluginState.originalDoc,
236
266
  steps = pluginState.steps,
267
+ stepAttributions = pluginState.stepAttributions,
237
268
  isDisplayingChanges = pluginState.isDisplayingChanges;
238
269
  if (!originalDoc || !isDisplayingChanges) {
239
270
  return {
@@ -247,8 +278,23 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
247
278
  var hideAddedDiffsUnderline = hideAddedDiffsUnderlineParam && (0, _fg.fg)('platform_editor_ai_smart_diff');
248
279
  var tr = state.tr;
249
280
  var steppedDoc = originalDoc;
281
+ var attributionColoringEnabled = (0, _attributions.isAttributionColoringEnabled)(stepAttributions);
282
+ var simplifiedSteps;
283
+ var simplifiedStepAttributions = [];
284
+ if (attributionColoringEnabled) {
285
+ var simplifiedStepsWithAttribution = (0, _simplifySteps.simplifyStepsWithAttribution)(steps, stepAttributions !== null && stepAttributions !== void 0 ? stepAttributions : [], originalDoc);
286
+ simplifiedSteps = simplifiedStepsWithAttribution.map(function (_ref8) {
287
+ var step = _ref8.step;
288
+ return step;
289
+ });
290
+ simplifiedStepAttributions = simplifiedStepsWithAttribution.map(function (_ref9) {
291
+ var stepAttribution = _ref9.stepAttribution;
292
+ return stepAttribution;
293
+ });
294
+ } else {
295
+ simplifiedSteps = (0, _simplifySteps.simplifySteps)(steps, originalDoc);
296
+ }
250
297
  var attrSteps = [];
251
- var simplifiedSteps = (0, _simplifySteps.simplifySteps)(steps, originalDoc);
252
298
  var stepMaps = [];
253
299
  var _iterator = _createForOfIteratorHelper(simplifiedSteps),
254
300
  _step;
@@ -296,17 +342,45 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
296
342
  // gated with it; other diff types keep the library default so their output is
297
343
  // unchanged.
298
344
  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
- });
345
+ var changes;
346
+ var attributedChanges = [];
347
+ var attributionColors;
348
+ if (attributionColoringEnabled) {
349
+ var changeset = _prosemirrorChangeset.ChangeSet.create(originalDoc, function (left, right) {
350
+ return (0, _attributions.getAttributionKey)(left) === (0, _attributions.getAttributionKey)(right) ? left.stepIndex > right.stepIndex ? left : right :
351
+ // `prosemirror-changeset` uses null as its incompatible-data sentinel even
352
+ // though its public combine callback is typed as returning Data.
353
+ null;
354
+ }, tokenEncoder).addSteps(steppedDoc, stepMaps, simplifiedStepAttributions.map(function (attribution, stepIndex) {
355
+ return _objectSpread(_objectSpread({}, attribution), {}, {
356
+ stepIndex: stepIndex
357
+ });
358
+ }));
359
+ attributedChanges = (0, _diffBySteps.diffBySteps)(originalDoc, simplifiedSteps, simplifiedStepAttributions);
360
+ changes = getAttributedChanges({
361
+ changeset: changeset,
362
+ originalDoc: originalDoc,
363
+ steppedDoc: steppedDoc,
364
+ diffType: diffType,
365
+ tr: tr,
366
+ attributedChanges: attributedChanges,
367
+ intl: intl,
368
+ smartThresholds: smartThresholds
369
+ });
370
+ attributionColors = (0, _attributions.createAttributionColorMap)(simplifiedStepAttributions);
371
+ } else {
372
+ var _changeset = _prosemirrorChangeset.ChangeSet.create(originalDoc, undefined, tokenEncoder).addSteps(steppedDoc, stepMaps, tr.doc);
373
+ changes = getChanges({
374
+ changeset: _changeset,
375
+ originalDoc: originalDoc,
376
+ steppedDoc: steppedDoc,
377
+ diffType: diffType,
378
+ tr: tr,
379
+ steps: simplifiedSteps,
380
+ intl: intl,
381
+ smartThresholds: smartThresholds
382
+ });
383
+ }
310
384
  var decorations = [];
311
385
 
312
386
  /**
@@ -319,6 +393,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
319
393
  // Our default operations are insertions, so it should match the opposite of isInverted.
320
394
  var isInserted = !isInverted;
321
395
  var createDecorationsForChange = function createDecorationsForChange(change) {
396
+ var changeColorScheme = attributionColors ? (0, _attributions.getColorSchemeForChange)(change, attributedChanges, attributionColors, colorScheme) : colorScheme;
322
397
  var isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
323
398
 
324
399
  // Hoisted because it decides BOTH where the deleted widget is anchored and — since the
@@ -373,7 +448,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
373
448
  toB: to
374
449
  },
375
450
  doc: tr.doc,
376
- colorScheme: colorScheme,
451
+ colorScheme: changeColorScheme,
377
452
  isActive: isActive,
378
453
  diffType: diffType
379
454
  }, (0, _isExtendedEnabled.isExtendedEnabled)(diffType) && {
@@ -394,7 +469,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
394
469
  decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createInlineChangedDecoration.createInlineChangedDecoration)(_objectSpread({
395
470
  change: change,
396
471
  doc: tr.doc,
397
- colorScheme: colorScheme,
472
+ colorScheme: changeColorScheme,
398
473
  isActive: isActive,
399
474
  diffType: diffType
400
475
  }, (0, _isExtendedEnabled.isExtendedEnabled)(diffType) && {
@@ -410,7 +485,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
410
485
  doc: tr.doc,
411
486
  from: change.fromB,
412
487
  to: change.toB,
413
- colorScheme: colorScheme
488
+ colorScheme: changeColorScheme
414
489
  }, (0, _isExtendedEnabled.isExtendedEnabled)(diffType) && {
415
490
  isInserted: isInserted,
416
491
  shouldHideDeleted: shouldHideDeleted,
@@ -429,7 +504,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
429
504
  change: change,
430
505
  doc: originalDoc,
431
506
  nodeViewSerializer: nodeViewSerializer,
432
- colorScheme: colorScheme,
507
+ colorScheme: changeColorScheme,
433
508
  newDoc: tr.doc,
434
509
  intl: intl,
435
510
  activeIndexPos: activeIndexPos
@@ -546,42 +621,42 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6
546
621
  };
547
622
  var calculateDiffDecorations = exports.calculateDiffDecorations = (0, _memoizeOne.default)(calculateDiffDecorationsInner,
548
623
  // 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;
624
+ function (_ref0, _ref1) {
625
+ var _ref13;
626
+ var _ref10 = (0, _slicedToArray2.default)(_ref0, 1),
627
+ _ref10$ = _ref10[0],
628
+ pluginState = _ref10$.pluginState,
629
+ state = _ref10$.state,
630
+ colorScheme = _ref10$.colorScheme,
631
+ intl = _ref10$.intl,
632
+ activeIndexPos = _ref10$.activeIndexPos,
633
+ isInverted = _ref10$.isInverted,
634
+ diffType = _ref10$.diffType,
635
+ hideDeletedDiffs = _ref10$.hideDeletedDiffs,
636
+ hideAddedDiffsUnderline = _ref10$.hideAddedDiffsUnderline,
637
+ showIndicators = _ref10$.showIndicators,
638
+ smartThresholds = _ref10$.smartThresholds,
639
+ deletedDiffPlacement = _ref10$.deletedDiffPlacement,
640
+ inlineDeletedDiffPlacement = _ref10$.inlineDeletedDiffPlacement;
641
+ var _ref11 = (0, _slicedToArray2.default)(_ref1, 1),
642
+ _ref11$ = _ref11[0],
643
+ lastPluginState = _ref11$.pluginState,
644
+ lastState = _ref11$.state,
645
+ lastColorScheme = _ref11$.colorScheme,
646
+ lastIntl = _ref11$.intl,
647
+ lastActiveIndexPos = _ref11$.activeIndexPos,
648
+ lastIsInverted = _ref11$.isInverted,
649
+ lastDiffType = _ref11$.diffType,
650
+ lastHideDeletedDiffs = _ref11$.hideDeletedDiffs,
651
+ lastHideAddedDiffsUnderline = _ref11$.hideAddedDiffsUnderline,
652
+ lastShowIndicators = _ref11$.showIndicators,
653
+ lastSmartThresholds = _ref11$.smartThresholds,
654
+ lastDeletedDiffPlacement = _ref11$.deletedDiffPlacement,
655
+ lastInlineDeletedDiffPlacement = _ref11$.inlineDeletedDiffPlacement;
581
656
  var originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
582
657
  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;
658
+ var _ref12;
659
+ return (_ref12 = 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 && _ref12 !== void 0 ? _ref12 : false;
585
660
  }
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;
661
+ return (_ref13 = 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 && _ref13 !== void 0 ? _ref13 : false;
587
662
  });
@@ -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);
@@ -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
+ };