@atlaskit/editor-plugin-show-diff 14.0.3 → 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 +21 -0
  2. package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +204 -101
  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 +118 -26
  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 +205 -102
  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
@@ -14,7 +14,7 @@ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-e
14
14
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
15
15
  import { isExtendedEnabled } from '../../isExtendedEnabled';
16
16
  import { buildAddedCellOverlayRoundedStyle, buildAddedCellOverlayStyle, buildAddedCellOverlayStyleNew, buildDeletedCellOverlayRoundedStyle, buildDeletedCellOverlayStyle, buildDeletedInlineContentStyle, buildDeletedInlineContentStyleExtended, buildDeletedLozengeActiveStyle, buildDeletedLozengeStyle, buildDeletedNodeCSSVariables, buildDeletedQuoteNodeWithLozengeStyle, buildDeletedStrikethroughLine, buildDeletedWrappedBlockOutline, buildInsertedBlockNodeStyle, buildInsertedInlineStyle, buildInsertStyleInBlockExtended, buildInsertStyleInBlockExtendedNoUnderline, buildInsertStyleNode } from '../colorSchemes/factory';
17
- import { colorSchemeRegistry, standardScheme } from '../colorSchemes/schemes';
17
+ import { colorSchemeRegistry, getLegacyColorScheme, standardScheme } from '../colorSchemes/schemes';
18
18
  import { getChangedContentStyleLegacy, getChangedNodeStyleLegacy, getDeletedContentStyleLegacy, getDeletedContentStyleUnboundedLegacy, getInsertedContentStyleLegacy, hasRestingDeletedRingLegacy, resolveCellOverlayStyleLegacy, resolveNestedInsertedNodeStyleLegacy, resolveRemovedLozengeStyleLegacy } from './wrapBlockNodeViewStyles.legacy';
19
19
  const DEFAULT_COLOR_SCHEME = 'standard';
20
20
  const getColorScheme = colorScheme => colorSchemeRegistry[colorScheme !== null && colorScheme !== void 0 ? colorScheme : DEFAULT_COLOR_SCHEME];
@@ -108,28 +108,31 @@ const resolveNestedInsertedNodeStyleNext = () => buildInsertStyleNode(nestedCont
108
108
  const hasRestingDeletedRingNext = colorScheme => getColorScheme(colorScheme).deletedNodeEmphasis === 'stateful';
109
109
 
110
110
  /** Inline content style for a changed (inserted or deleted) block node. */
111
- export const getChangedContentStyle = (colorScheme, isActive = false, isInserted = false, diffType, hideAddedDiffsUnderline = false) => isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? getChangedContentStyleNext(colorScheme, isActive, isInserted, diffType, hideAddedDiffsUnderline) : getChangedContentStyleLegacy(colorScheme, isActive, isInserted, diffType, hideAddedDiffsUnderline);
111
+ export const getChangedContentStyle = (colorScheme, isActive = false, isInserted = false, diffType, hideAddedDiffsUnderline = false) => isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? getChangedContentStyleNext(colorScheme, isActive, isInserted, diffType, hideAddedDiffsUnderline) : getChangedContentStyleLegacy(getLegacyColorScheme(colorScheme), isActive, isInserted, diffType, hideAddedDiffsUnderline);
112
112
 
113
113
  /** Node-specific style for a changed block node, or `undefined` when the node type has none. */
114
- export const getChangedNodeStyle = (nodeName, colorScheme, isInserted = false, isActive = false, diffType, hideAddedDiffsUnderline = false) => isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? getChangedNodeStyleNext(nodeName, colorScheme, isInserted, isActive, diffType, hideAddedDiffsUnderline) : getChangedNodeStyleLegacy(nodeName, colorScheme, isInserted, isActive, diffType, hideAddedDiffsUnderline);
114
+ export const getChangedNodeStyle = (nodeName, colorScheme, isInserted = false, isActive = false, diffType, hideAddedDiffsUnderline = false) => isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? getChangedNodeStyleNext(nodeName, colorScheme, isInserted, isActive, diffType, hideAddedDiffsUnderline) : getChangedNodeStyleLegacy(nodeName, getLegacyColorScheme(colorScheme), isInserted, isActive, diffType, hideAddedDiffsUnderline);
115
115
 
116
116
  /** The positioned line drawn across deleted content spanning an unbounded range. */
117
- export const getDeletedContentStyleUnbounded = (colorScheme, isActive = false) => isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? getDeletedContentStyleUnboundedNext(colorScheme, isActive) : getDeletedContentStyleUnboundedLegacy(colorScheme, isActive);
117
+ export const getDeletedContentStyleUnbounded = (colorScheme, isActive = false) => isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? getDeletedContentStyleUnboundedNext(colorScheme, isActive) : getDeletedContentStyleUnboundedLegacy(getLegacyColorScheme(colorScheme), isActive);
118
118
 
119
119
  /** Inline style for inserted content. */
120
- export const getInsertedContentStyle = (colorScheme, isActive = false, hideAddedDiffsUnderline = false) => isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? getInsertedContentStyleNext(colorScheme, isActive, hideAddedDiffsUnderline) : getInsertedContentStyleLegacy(colorScheme, isActive, hideAddedDiffsUnderline);
120
+ export const getInsertedContentStyle = (colorScheme, isActive = false, hideAddedDiffsUnderline = false) => isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? getInsertedContentStyleNext(colorScheme, isActive, hideAddedDiffsUnderline) : getInsertedContentStyleLegacy(getLegacyColorScheme(colorScheme), isActive, hideAddedDiffsUnderline);
121
121
 
122
122
  /** Inline style for deleted content. */
123
- export const getDeletedContentStyle = (colorScheme, isActive = false, diffType) => isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? getDeletedContentStyleNext(colorScheme, isActive, diffType) : getDeletedContentStyleLegacy(colorScheme, isActive, diffType);
123
+ export const getDeletedContentStyle = (colorScheme, isActive = false, diffType) => isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? getDeletedContentStyleNext(colorScheme, isActive, diffType) : getDeletedContentStyleLegacy(getLegacyColorScheme(colorScheme), isActive, diffType);
124
124
 
125
125
  /**
126
126
  * Overlay style for one added or deleted table cell. Invariant across the cells of a table, so the
127
127
  * `querySelectorAll('td, th')` loop in `wrapBlockNodeView.ts` resolves it once.
128
128
  */
129
- export const resolveCellOverlayStyle = args => isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? resolveCellOverlayStyleNext(args) : resolveCellOverlayStyleLegacy(args);
129
+ export const resolveCellOverlayStyle = args => isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? resolveCellOverlayStyleNext(args) : resolveCellOverlayStyleLegacy({
130
+ ...args,
131
+ colorScheme: getLegacyColorScheme(args.colorScheme)
132
+ });
130
133
 
131
134
  /** Inner style for the "Removed" lozenge on a deleted block node. */
132
- export const resolveRemovedLozengeStyle = (colorScheme, isActive) => isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? resolveRemovedLozengeStyleNext(colorScheme, isActive) : resolveRemovedLozengeStyleLegacy(colorScheme, isActive);
135
+ export const resolveRemovedLozengeStyle = (colorScheme, isActive) => isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? resolveRemovedLozengeStyleNext(colorScheme, isActive) : resolveRemovedLozengeStyleLegacy(getLegacyColorScheme(colorScheme), isActive);
133
136
 
134
137
  /**
135
138
  * Style for inserted content nested inside a multi-container or list node — the `decisionList` and
@@ -142,7 +145,7 @@ export const resolveNestedInsertedNodeStyle = () => isExperimentEnabled('platfor
142
145
  * Whether the colour scheme draws a resting (non-active) ring on a deleted media/embed node, which
143
146
  * is what the `show-diff-deleted-outline-new` class styles in editor-core's smartCardStyles.
144
147
  */
145
- export const hasRestingDeletedRing = colorScheme => isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? hasRestingDeletedRingNext(colorScheme) : hasRestingDeletedRingLegacy(colorScheme);
148
+ export const hasRestingDeletedRing = colorScheme => isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? hasRestingDeletedRingNext(colorScheme) : hasRestingDeletedRingLegacy(getLegacyColorScheme(colorScheme));
146
149
 
147
150
  /**
148
151
  * Custom properties consumed by the `show-diff-deleted-node-vars` selectors in editor-core.
@@ -27,6 +27,7 @@ export const createPlugin = (config, getIntl, api, onEditorView) => {
27
27
  const defaultDiffType = getDefaultDiffType();
28
28
  return {
29
29
  steps: [],
30
+ stepAttributions: [],
30
31
  originalDoc: undefined,
31
32
  decorations: DecorationSet.empty,
32
33
  isDisplayingChanges: false,
@@ -4,6 +4,27 @@ import { getDeletedWidgets } from './pm-plugins/getDeletedWidgets';
4
4
  import { getScrollableDecorations } from './pm-plugins/getScrollableDecorations';
5
5
  import { createPlugin, showDiffPluginKey } from './pm-plugins/main';
6
6
  import { IndicatorBarContentComponent } from './ui/IndicatorBar/IndicatorBarContentComponent';
7
+ const normalizeShowDiffParams = params => {
8
+ if (!params || !('stepsWithAttribution' in params)) {
9
+ return params ? {
10
+ ...params,
11
+ stepAttributions: []
12
+ } : params;
13
+ }
14
+ const {
15
+ stepsWithAttribution,
16
+ ...rest
17
+ } = params;
18
+ return {
19
+ ...rest,
20
+ steps: stepsWithAttribution.map(({
21
+ step
22
+ }) => step),
23
+ stepAttributions: stepsWithAttribution.map(({
24
+ stepAttribution
25
+ }) => stepAttribution)
26
+ };
27
+ };
7
28
  export const showDiffPlugin = ({
8
29
  api,
9
30
  config
@@ -30,7 +51,7 @@ export const showDiffPlugin = ({
30
51
  });
31
52
  }
32
53
  return tr.setMeta(showDiffPluginKey, {
33
- ...params,
54
+ ...normalizeShowDiffParams(params),
34
55
  action: 'SHOW_DIFF'
35
56
  });
36
57
  },
@@ -45,6 +66,7 @@ export const showDiffPlugin = ({
45
66
  }
46
67
  return tr.setMeta(showDiffPluginKey, {
47
68
  steps: [],
69
+ stepAttributions: [],
48
70
  action: 'HIDE_DIFF'
49
71
  });
50
72
  },
@@ -1,6 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
2
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
4
  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; }
5
5
  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) { _defineProperty(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; }
6
6
  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; } } }; }
@@ -19,6 +19,7 @@ import { createDocMarginAnchorWidget } from '../decorations/createAnchorDecorati
19
19
  import { createBlockChangedDecoration } from '../decorations/createBlockChangedDecoration';
20
20
  import { createInlineChangedDecoration } from '../decorations/createInlineChangedDecoration';
21
21
  import { createNodeChangedDecorationWidget } from '../decorations/createNodeChangedDecorationWidget';
22
+ import { createAttributionColorMap, getAttributionKey, getColorSchemeForChange, isAttributionColoringEnabled } from '../decorations/colorSchemes/attributions';
22
23
  import { extractDiffDescriptors } from '../decorations/decorationKeys';
23
24
  import { getAttrChangeRanges, stepIsValidAttrChange } from '../decorations/utils/getAttrChangeRanges';
24
25
  import { getMarkChangeRanges } from '../decorations/utils/getMarkChangeRanges';
@@ -27,7 +28,8 @@ import { attrAwareTokenEncoder } from './attrAwareTokenEncoder';
27
28
  import { diffBySteps } from './diffBySteps';
28
29
  import { groupChangesByBlock } from './groupChangesByBlock';
29
30
  import { optimizeChanges } from './optimizeChanges';
30
- import { simplifySteps } from './simplifySteps';
31
+ import { simplifyChangesWithAttribution } from './simplifyChangesWithAttribution';
32
+ import { simplifySteps, simplifyStepsWithAttribution } from './simplifySteps';
31
33
  import { classifySmartChanges } from './smart/classifySmartChanges';
32
34
  import { smartChangeLevel } from './smart/helpers';
33
35
  var getChanges = function getChanges(_ref) {
@@ -65,6 +67,34 @@ var getChanges = function getChanges(_ref) {
65
67
  var changes = simplifyChanges(changeset.changes, tr.doc);
66
68
  return optimizeChanges(changes);
67
69
  };
70
+ var getAttributedChanges = function getAttributedChanges(_ref2) {
71
+ var attributedChanges = _ref2.attributedChanges,
72
+ changeset = _ref2.changeset,
73
+ originalDoc = _ref2.originalDoc,
74
+ steppedDoc = _ref2.steppedDoc,
75
+ diffType = _ref2.diffType,
76
+ tr = _ref2.tr,
77
+ intl = _ref2.intl,
78
+ smartThresholds = _ref2.smartThresholds;
79
+ if (isExtendedEnabled(diffType)) {
80
+ if (diffType === 'smart' && fg('platform_editor_ai_smart_diff')) {
81
+ return classifySmartChanges({
82
+ changes: simplifyChangesWithAttribution(attributedChanges, tr.doc),
83
+ originalDoc: originalDoc,
84
+ newDoc: tr.doc,
85
+ locale: intl.locale,
86
+ thresholds: smartThresholds
87
+ });
88
+ }
89
+ if (diffType === 'step') {
90
+ return attributedChanges;
91
+ }
92
+ if (diffType === 'block') {
93
+ return groupChangesByBlock(changeset.changes, originalDoc, steppedDoc);
94
+ }
95
+ }
96
+ return simplifyChangesWithAttribution(attributedChanges, tr.doc);
97
+ };
68
98
 
69
99
  /**
70
100
  * Collect the inline-content ranges of every leaf text-bearing block (paragraph, heading, …)
@@ -108,27 +138,51 @@ var isLargeInsertedTableRange = function isLargeInsertedTableRange(doc, from, to
108
138
  });
109
139
  return containsTable && leafCount > LARGE_TABLE_LEAF_THRESHOLD;
110
140
  };
111
- var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration(_ref2) {
112
- var doc = _ref2.doc,
113
- from = _ref2.from,
114
- to = _ref2.to,
115
- colorScheme = _ref2.colorScheme,
116
- _ref2$isInserted = _ref2.isInserted,
117
- isInserted = _ref2$isInserted === void 0 ? true : _ref2$isInserted,
118
- activeIndexPos = _ref2.activeIndexPos,
119
- _ref2$shouldHideDelet = _ref2.shouldHideDeleted,
120
- shouldHideDeleted = _ref2$shouldHideDelet === void 0 ? false : _ref2$shouldHideDelet,
121
- _ref2$showIndicators = _ref2.showIndicators,
122
- showIndicators = _ref2$showIndicators === void 0 ? false : _ref2$showIndicators,
123
- diffType = _ref2.diffType,
124
- _ref2$coarseTableCell = _ref2.coarseTableCellsOnly,
125
- coarseTableCellsOnly = _ref2$coarseTableCell === void 0 ? false : _ref2$coarseTableCell;
141
+
142
+ // Collect the [from, to) ranges of every `table` node overlapping `[from, to)`. The coarse
143
+ // large-table path must only suppress decorations inside these ranges
144
+ var tableRanges = function tableRanges(doc, from, to) {
145
+ var ranges = [];
146
+ doc.nodesBetween(from, to, function (node, pos) {
147
+ if (node.type.name === 'table') {
148
+ ranges.push([pos, pos + node.nodeSize]);
149
+ return false;
150
+ }
151
+ return true;
152
+ });
153
+ return ranges;
154
+ };
155
+ var isInsideTable = function isInsideTable(tables, pos) {
156
+ return tables.some(function (_ref3) {
157
+ var _ref4 = _slicedToArray(_ref3, 2),
158
+ tFrom = _ref4[0],
159
+ tTo = _ref4[1];
160
+ return pos >= tFrom && pos < tTo;
161
+ });
162
+ };
163
+ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration(_ref5) {
164
+ var doc = _ref5.doc,
165
+ from = _ref5.from,
166
+ to = _ref5.to,
167
+ colorScheme = _ref5.colorScheme,
168
+ _ref5$isInserted = _ref5.isInserted,
169
+ isInserted = _ref5$isInserted === void 0 ? true : _ref5$isInserted,
170
+ activeIndexPos = _ref5.activeIndexPos,
171
+ _ref5$shouldHideDelet = _ref5.shouldHideDeleted,
172
+ shouldHideDeleted = _ref5$shouldHideDelet === void 0 ? false : _ref5$shouldHideDelet,
173
+ _ref5$showIndicators = _ref5.showIndicators,
174
+ showIndicators = _ref5$showIndicators === void 0 ? false : _ref5$showIndicators,
175
+ diffType = _ref5.diffType,
176
+ _ref5$coarseTableCell = _ref5.coarseTableCellsOnly,
177
+ coarseTableCellsOnly = _ref5$coarseTableCell === void 0 ? false : _ref5$coarseTableCell;
126
178
  var decorations = [];
179
+ // Coarse path: inside the large table, only cell/header overlays are kept — the
180
+ // table/row/paragraph decorations there are redundant and cause expensive per-cell
181
+ // re-render. Blocks outside the table keep their normal decorations.
182
+ var coarseTables = coarseTableCellsOnly ? tableRanges(doc, from, to) : [];
127
183
  // Iterate over the document nodes within the range
128
184
  doc.nodesBetween(from, to, function (node, pos) {
129
- // Coarse path: only cell/header overlays are visible; table/row/paragraph
130
- // decorations are redundant and cause expensive per-cell re-render.
131
- if (coarseTableCellsOnly) {
185
+ if (coarseTableCellsOnly && isInsideTable(coarseTables, pos)) {
132
186
  var name = node.type.name;
133
187
  if (name !== 'tableCell' && name !== 'tableHeader') {
134
188
  return;
@@ -166,10 +220,10 @@ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration
166
220
  *
167
221
  * Callers are responsible for the `smart` diffType and gate checks.
168
222
  */
169
- export var isDeletedContentPlacedBelow = function isDeletedContentPlacedBelow(_ref3) {
170
- var change = _ref3.change,
171
- deletedDiffPlacement = _ref3.deletedDiffPlacement,
172
- inlineDeletedDiffPlacement = _ref3.inlineDeletedDiffPlacement;
223
+ export var isDeletedContentPlacedBelow = function isDeletedContentPlacedBelow(_ref6) {
224
+ var change = _ref6.change,
225
+ deletedDiffPlacement = _ref6.deletedDiffPlacement,
226
+ inlineDeletedDiffPlacement = _ref6.inlineDeletedDiffPlacement;
173
227
  var level = smartChangeLevel(change);
174
228
  if (level === 'node' || level === 'paragraph') {
175
229
  return deletedDiffPlacement === 'bottom';
@@ -178,31 +232,32 @@ export var isDeletedContentPlacedBelow = function isDeletedContentPlacedBelow(_r
178
232
  // Inline-level (undefined) and sentence-level changes.
179
233
  return inlineDeletedDiffPlacement === 'after';
180
234
  };
181
- var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4) {
182
- var state = _ref4.state,
183
- pluginState = _ref4.pluginState,
184
- nodeViewSerializer = _ref4.nodeViewSerializer,
185
- colorScheme = _ref4.colorScheme,
186
- intl = _ref4.intl,
187
- activeIndexPos = _ref4.activeIndexPos,
188
- api = _ref4.api,
189
- _ref4$isInverted = _ref4.isInverted,
190
- isInverted = _ref4$isInverted === void 0 ? false : _ref4$isInverted,
191
- _ref4$diffType = _ref4.diffType,
192
- diffType = _ref4$diffType === void 0 ? getDefaultDiffType() : _ref4$diffType,
193
- _ref4$hideDeletedDiff = _ref4.hideDeletedDiffs,
194
- hideDeletedDiffs = _ref4$hideDeletedDiff === void 0 ? false : _ref4$hideDeletedDiff,
195
- _ref4$hideAddedDiffsU = _ref4.hideAddedDiffsUnderline,
196
- hideAddedDiffsUnderlineParam = _ref4$hideAddedDiffsU === void 0 ? false : _ref4$hideAddedDiffsU,
197
- _ref4$showIndicators = _ref4.showIndicators,
198
- showIndicators = _ref4$showIndicators === void 0 ? false : _ref4$showIndicators,
199
- smartThresholds = _ref4.smartThresholds,
200
- _ref4$deletedDiffPlac = _ref4.deletedDiffPlacement,
201
- deletedDiffPlacement = _ref4$deletedDiffPlac === void 0 ? 'top' : _ref4$deletedDiffPlac,
202
- _ref4$inlineDeletedDi = _ref4.inlineDeletedDiffPlacement,
203
- inlineDeletedDiffPlacement = _ref4$inlineDeletedDi === void 0 ? 'before' : _ref4$inlineDeletedDi;
235
+ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref7) {
236
+ var state = _ref7.state,
237
+ pluginState = _ref7.pluginState,
238
+ nodeViewSerializer = _ref7.nodeViewSerializer,
239
+ colorScheme = _ref7.colorScheme,
240
+ intl = _ref7.intl,
241
+ activeIndexPos = _ref7.activeIndexPos,
242
+ api = _ref7.api,
243
+ _ref7$isInverted = _ref7.isInverted,
244
+ isInverted = _ref7$isInverted === void 0 ? false : _ref7$isInverted,
245
+ _ref7$diffType = _ref7.diffType,
246
+ diffType = _ref7$diffType === void 0 ? getDefaultDiffType() : _ref7$diffType,
247
+ _ref7$hideDeletedDiff = _ref7.hideDeletedDiffs,
248
+ hideDeletedDiffs = _ref7$hideDeletedDiff === void 0 ? false : _ref7$hideDeletedDiff,
249
+ _ref7$hideAddedDiffsU = _ref7.hideAddedDiffsUnderline,
250
+ hideAddedDiffsUnderlineParam = _ref7$hideAddedDiffsU === void 0 ? false : _ref7$hideAddedDiffsU,
251
+ _ref7$showIndicators = _ref7.showIndicators,
252
+ showIndicators = _ref7$showIndicators === void 0 ? false : _ref7$showIndicators,
253
+ smartThresholds = _ref7.smartThresholds,
254
+ _ref7$deletedDiffPlac = _ref7.deletedDiffPlacement,
255
+ deletedDiffPlacement = _ref7$deletedDiffPlac === void 0 ? 'top' : _ref7$deletedDiffPlac,
256
+ _ref7$inlineDeletedDi = _ref7.inlineDeletedDiffPlacement,
257
+ inlineDeletedDiffPlacement = _ref7$inlineDeletedDi === void 0 ? 'before' : _ref7$inlineDeletedDi;
204
258
  var originalDoc = pluginState.originalDoc,
205
259
  steps = pluginState.steps,
260
+ stepAttributions = pluginState.stepAttributions,
206
261
  isDisplayingChanges = pluginState.isDisplayingChanges;
207
262
  if (!originalDoc || !isDisplayingChanges) {
208
263
  return {
@@ -216,8 +271,23 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
216
271
  var hideAddedDiffsUnderline = hideAddedDiffsUnderlineParam && fg('platform_editor_ai_smart_diff');
217
272
  var tr = state.tr;
218
273
  var steppedDoc = originalDoc;
274
+ var attributionColoringEnabled = isAttributionColoringEnabled(stepAttributions);
275
+ var simplifiedSteps;
276
+ var simplifiedStepAttributions = [];
277
+ if (attributionColoringEnabled) {
278
+ var simplifiedStepsWithAttribution = simplifyStepsWithAttribution(steps, stepAttributions !== null && stepAttributions !== void 0 ? stepAttributions : [], originalDoc);
279
+ simplifiedSteps = simplifiedStepsWithAttribution.map(function (_ref8) {
280
+ var step = _ref8.step;
281
+ return step;
282
+ });
283
+ simplifiedStepAttributions = simplifiedStepsWithAttribution.map(function (_ref9) {
284
+ var stepAttribution = _ref9.stepAttribution;
285
+ return stepAttribution;
286
+ });
287
+ } else {
288
+ simplifiedSteps = simplifySteps(steps, originalDoc);
289
+ }
219
290
  var attrSteps = [];
220
- var simplifiedSteps = simplifySteps(steps, originalDoc);
221
291
  var stepMaps = [];
222
292
  var _iterator = _createForOfIteratorHelper(simplifiedSteps),
223
293
  _step;
@@ -265,17 +335,45 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
265
335
  // gated with it; other diff types keep the library default so their output is
266
336
  // unchanged.
267
337
  var tokenEncoder = diffType === 'smart' && fg('platform_editor_ai_smart_diff') ? attrAwareTokenEncoder : undefined;
268
- var changeset = ChangeSet.create(originalDoc, undefined, tokenEncoder).addSteps(steppedDoc, stepMaps, tr.doc);
269
- var changes = getChanges({
270
- changeset: changeset,
271
- originalDoc: originalDoc,
272
- steppedDoc: steppedDoc,
273
- diffType: diffType,
274
- tr: tr,
275
- steps: steps,
276
- intl: intl,
277
- smartThresholds: smartThresholds
278
- });
338
+ var changes;
339
+ var attributedChanges = [];
340
+ var attributionColors;
341
+ if (attributionColoringEnabled) {
342
+ var changeset = ChangeSet.create(originalDoc, function (left, right) {
343
+ return getAttributionKey(left) === getAttributionKey(right) ? left.stepIndex > right.stepIndex ? left : right :
344
+ // `prosemirror-changeset` uses null as its incompatible-data sentinel even
345
+ // though its public combine callback is typed as returning Data.
346
+ null;
347
+ }, tokenEncoder).addSteps(steppedDoc, stepMaps, simplifiedStepAttributions.map(function (attribution, stepIndex) {
348
+ return _objectSpread(_objectSpread({}, attribution), {}, {
349
+ stepIndex: stepIndex
350
+ });
351
+ }));
352
+ attributedChanges = diffBySteps(originalDoc, simplifiedSteps, simplifiedStepAttributions);
353
+ changes = getAttributedChanges({
354
+ changeset: changeset,
355
+ originalDoc: originalDoc,
356
+ steppedDoc: steppedDoc,
357
+ diffType: diffType,
358
+ tr: tr,
359
+ attributedChanges: attributedChanges,
360
+ intl: intl,
361
+ smartThresholds: smartThresholds
362
+ });
363
+ attributionColors = createAttributionColorMap(simplifiedStepAttributions);
364
+ } else {
365
+ var _changeset = ChangeSet.create(originalDoc, undefined, tokenEncoder).addSteps(steppedDoc, stepMaps, tr.doc);
366
+ changes = getChanges({
367
+ changeset: _changeset,
368
+ originalDoc: originalDoc,
369
+ steppedDoc: steppedDoc,
370
+ diffType: diffType,
371
+ tr: tr,
372
+ steps: simplifiedSteps,
373
+ intl: intl,
374
+ smartThresholds: smartThresholds
375
+ });
376
+ }
279
377
  var decorations = [];
280
378
 
281
379
  /**
@@ -288,6 +386,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
288
386
  // Our default operations are insertions, so it should match the opposite of isInverted.
289
387
  var isInserted = !isInverted;
290
388
  var createDecorationsForChange = function createDecorationsForChange(change) {
389
+ var changeColorScheme = attributionColors ? getColorSchemeForChange(change, attributedChanges, attributionColors, colorScheme) : colorScheme;
291
390
  var isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
292
391
 
293
392
  // Hoisted because it decides BOTH where the deleted widget is anchored and — since the
@@ -321,10 +420,11 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
321
420
  // inward — when the widget is present the anchor must stay at the block
322
421
  // boundary to keep the indicator bar continuous with the deleted content.
323
422
  var willRenderDeletedWidget = change.deleted.length > 0 && !(isExtendedEnabled(diffType) && !isInverted && hideDeletedDiffs && change.inserted.length > 0);
324
- if (useCoarseTableDecoration) {
325
- // Skip the O(cells) inline decorations; the cell overlays (added below)
326
- // provide the highlight without the expensive content re-render.
327
- } else if (isSmartNodeLevel) {
423
+ if (isSmartNodeLevel) {
424
+ // For a large inserted table, skip the O(cells) inline decorations inside the
425
+ // table (the cell overlays added below provide the highlight without the
426
+ // expensive content re-render); leaf blocks outside the table still get theirs.
427
+ var coarseTables = useCoarseTableDecoration ? tableRanges(tr.doc, change.fromB, change.toB) : [];
328
428
  var _iterator2 = _createForOfIteratorHelper(leafTextblockRanges(tr.doc, change.fromB, change.toB)),
329
429
  _step2;
330
430
  try {
@@ -332,13 +432,16 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
332
432
  var _step2$value = _slicedToArray(_step2.value, 2),
333
433
  from = _step2$value[0],
334
434
  to = _step2$value[1];
435
+ if (useCoarseTableDecoration && isInsideTable(coarseTables, from)) {
436
+ continue;
437
+ }
335
438
  decorations.push.apply(decorations, _toConsumableArray(createInlineChangedDecoration(_objectSpread({
336
439
  change: {
337
440
  fromB: from,
338
441
  toB: to
339
442
  },
340
443
  doc: tr.doc,
341
- colorScheme: colorScheme,
444
+ colorScheme: changeColorScheme,
342
445
  isActive: isActive,
343
446
  diffType: diffType
344
447
  }, isExtendedEnabled(diffType) && {
@@ -359,7 +462,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
359
462
  decorations.push.apply(decorations, _toConsumableArray(createInlineChangedDecoration(_objectSpread({
360
463
  change: change,
361
464
  doc: tr.doc,
362
- colorScheme: colorScheme,
465
+ colorScheme: changeColorScheme,
363
466
  isActive: isActive,
364
467
  diffType: diffType
365
468
  }, isExtendedEnabled(diffType) && {
@@ -375,7 +478,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
375
478
  doc: tr.doc,
376
479
  from: change.fromB,
377
480
  to: change.toB,
378
- colorScheme: colorScheme
481
+ colorScheme: changeColorScheme
379
482
  }, isExtendedEnabled(diffType) && {
380
483
  isInserted: isInserted,
381
484
  shouldHideDeleted: shouldHideDeleted,
@@ -394,7 +497,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
394
497
  change: change,
395
498
  doc: originalDoc,
396
499
  nodeViewSerializer: nodeViewSerializer,
397
- colorScheme: colorScheme,
500
+ colorScheme: changeColorScheme,
398
501
  newDoc: tr.doc,
399
502
  intl: intl,
400
503
  activeIndexPos: activeIndexPos
@@ -511,42 +614,42 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
511
614
  };
512
615
  export var calculateDiffDecorations = memoizeOne(calculateDiffDecorationsInner,
513
616
  // Cache results unless relevant inputs change
514
- function (_ref5, _ref6) {
515
- var _ref0;
516
- var _ref7 = _slicedToArray(_ref5, 1),
517
- _ref7$ = _ref7[0],
518
- pluginState = _ref7$.pluginState,
519
- state = _ref7$.state,
520
- colorScheme = _ref7$.colorScheme,
521
- intl = _ref7$.intl,
522
- activeIndexPos = _ref7$.activeIndexPos,
523
- isInverted = _ref7$.isInverted,
524
- diffType = _ref7$.diffType,
525
- hideDeletedDiffs = _ref7$.hideDeletedDiffs,
526
- hideAddedDiffsUnderline = _ref7$.hideAddedDiffsUnderline,
527
- showIndicators = _ref7$.showIndicators,
528
- smartThresholds = _ref7$.smartThresholds,
529
- deletedDiffPlacement = _ref7$.deletedDiffPlacement,
530
- inlineDeletedDiffPlacement = _ref7$.inlineDeletedDiffPlacement;
531
- var _ref8 = _slicedToArray(_ref6, 1),
532
- _ref8$ = _ref8[0],
533
- lastPluginState = _ref8$.pluginState,
534
- lastState = _ref8$.state,
535
- lastColorScheme = _ref8$.colorScheme,
536
- lastIntl = _ref8$.intl,
537
- lastActiveIndexPos = _ref8$.activeIndexPos,
538
- lastIsInverted = _ref8$.isInverted,
539
- lastDiffType = _ref8$.diffType,
540
- lastHideDeletedDiffs = _ref8$.hideDeletedDiffs,
541
- lastHideAddedDiffsUnderline = _ref8$.hideAddedDiffsUnderline,
542
- lastShowIndicators = _ref8$.showIndicators,
543
- lastSmartThresholds = _ref8$.smartThresholds,
544
- lastDeletedDiffPlacement = _ref8$.deletedDiffPlacement,
545
- lastInlineDeletedDiffPlacement = _ref8$.inlineDeletedDiffPlacement;
617
+ function (_ref0, _ref1) {
618
+ var _ref13;
619
+ var _ref10 = _slicedToArray(_ref0, 1),
620
+ _ref10$ = _ref10[0],
621
+ pluginState = _ref10$.pluginState,
622
+ state = _ref10$.state,
623
+ colorScheme = _ref10$.colorScheme,
624
+ intl = _ref10$.intl,
625
+ activeIndexPos = _ref10$.activeIndexPos,
626
+ isInverted = _ref10$.isInverted,
627
+ diffType = _ref10$.diffType,
628
+ hideDeletedDiffs = _ref10$.hideDeletedDiffs,
629
+ hideAddedDiffsUnderline = _ref10$.hideAddedDiffsUnderline,
630
+ showIndicators = _ref10$.showIndicators,
631
+ smartThresholds = _ref10$.smartThresholds,
632
+ deletedDiffPlacement = _ref10$.deletedDiffPlacement,
633
+ inlineDeletedDiffPlacement = _ref10$.inlineDeletedDiffPlacement;
634
+ var _ref11 = _slicedToArray(_ref1, 1),
635
+ _ref11$ = _ref11[0],
636
+ lastPluginState = _ref11$.pluginState,
637
+ lastState = _ref11$.state,
638
+ lastColorScheme = _ref11$.colorScheme,
639
+ lastIntl = _ref11$.intl,
640
+ lastActiveIndexPos = _ref11$.activeIndexPos,
641
+ lastIsInverted = _ref11$.isInverted,
642
+ lastDiffType = _ref11$.diffType,
643
+ lastHideDeletedDiffs = _ref11$.hideDeletedDiffs,
644
+ lastHideAddedDiffsUnderline = _ref11$.hideAddedDiffsUnderline,
645
+ lastShowIndicators = _ref11$.showIndicators,
646
+ lastSmartThresholds = _ref11$.smartThresholds,
647
+ lastDeletedDiffPlacement = _ref11$.deletedDiffPlacement,
648
+ lastInlineDeletedDiffPlacement = _ref11$.inlineDeletedDiffPlacement;
546
649
  var originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
547
650
  if (isExtendedEnabled(diffType)) {
548
- var _ref9;
549
- return (_ref9 = colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isInverted === lastIsInverted && diffType === lastDiffType && isEqual(activeIndexPos, lastActiveIndexPos) && originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && hideDeletedDiffs === lastHideDeletedDiffs && hideAddedDiffsUnderline === lastHideAddedDiffsUnderline && showIndicators === lastShowIndicators && isEqual(smartThresholds, lastSmartThresholds) && deletedDiffPlacement === lastDeletedDiffPlacement && inlineDeletedDiffPlacement === lastInlineDeletedDiffPlacement) !== null && _ref9 !== void 0 ? _ref9 : false;
651
+ var _ref12;
652
+ return (_ref12 = colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isInverted === lastIsInverted && diffType === lastDiffType && isEqual(activeIndexPos, lastActiveIndexPos) && originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && isEqual(pluginState.stepAttributions, lastPluginState.stepAttributions) && state.doc.eq(lastState.doc) && hideDeletedDiffs === lastHideDeletedDiffs && hideAddedDiffsUnderline === lastHideAddedDiffsUnderline && showIndicators === lastShowIndicators && isEqual(smartThresholds, lastSmartThresholds) && deletedDiffPlacement === lastDeletedDiffPlacement && inlineDeletedDiffPlacement === lastInlineDeletedDiffPlacement) !== null && _ref12 !== void 0 ? _ref12 : false;
550
653
  }
551
- return (_ref0 = originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isEqual(activeIndexPos, lastActiveIndexPos) && hideDeletedDiffs === lastHideDeletedDiffs) !== null && _ref0 !== void 0 ? _ref0 : false;
654
+ return (_ref13 = originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && isEqual(pluginState.stepAttributions, lastPluginState.stepAttributions) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isEqual(activeIndexPos, lastActiveIndexPos) && hideDeletedDiffs === lastHideDeletedDiffs) !== null && _ref13 !== void 0 ? _ref13 : false;
552
655
  });