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

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/editor-plugin-show-diff
2
2
 
3
+ ## 14.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [`62c3227f6a3ac`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/62c3227f6a3ac) -
8
+ [CCI-19031] Fix large-table diffs suppressing decorations on adjacent inserted content. When a
9
+ paragraph (or other block) is inserted next to a large table, the smart classifier coalesces them
10
+ into a single node-level change. The coarse large-table decoration path now scopes cell-only
11
+ suppression to the table subtree, so adjacent inserted content keeps its highlight and indicator
12
+ instead of being dropped.
13
+ - Updated dependencies
14
+
15
+ ## 14.0.3
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies
20
+
3
21
  ## 14.0.2
4
22
 
5
23
  ### Patch Changes
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.isDeletedContentPlacedBelow = exports.calculateDiffDecorations = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
9
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
11
  var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
12
12
  var _memoizeOne = _interopRequireDefault(require("memoize-one"));
13
13
  var _prosemirrorChangeset = require("prosemirror-changeset");
@@ -115,27 +115,51 @@ var isLargeInsertedTableRange = function isLargeInsertedTableRange(doc, from, to
115
115
  });
116
116
  return containsTable && leafCount > LARGE_TABLE_LEAF_THRESHOLD;
117
117
  };
118
- var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration(_ref2) {
119
- var doc = _ref2.doc,
120
- from = _ref2.from,
121
- to = _ref2.to,
122
- colorScheme = _ref2.colorScheme,
123
- _ref2$isInserted = _ref2.isInserted,
124
- isInserted = _ref2$isInserted === void 0 ? true : _ref2$isInserted,
125
- activeIndexPos = _ref2.activeIndexPos,
126
- _ref2$shouldHideDelet = _ref2.shouldHideDeleted,
127
- shouldHideDeleted = _ref2$shouldHideDelet === void 0 ? false : _ref2$shouldHideDelet,
128
- _ref2$showIndicators = _ref2.showIndicators,
129
- showIndicators = _ref2$showIndicators === void 0 ? false : _ref2$showIndicators,
130
- diffType = _ref2.diffType,
131
- _ref2$coarseTableCell = _ref2.coarseTableCellsOnly,
132
- coarseTableCellsOnly = _ref2$coarseTableCell === void 0 ? false : _ref2$coarseTableCell;
118
+
119
+ // Collect the [from, to) ranges of every `table` node overlapping `[from, to)`. The coarse
120
+ // large-table path must only suppress decorations inside these ranges
121
+ var tableRanges = function tableRanges(doc, from, to) {
122
+ var ranges = [];
123
+ doc.nodesBetween(from, to, function (node, pos) {
124
+ if (node.type.name === 'table') {
125
+ ranges.push([pos, pos + node.nodeSize]);
126
+ return false;
127
+ }
128
+ return true;
129
+ });
130
+ return ranges;
131
+ };
132
+ 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];
137
+ return pos >= tFrom && pos < tTo;
138
+ });
139
+ };
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;
133
155
  var decorations = [];
156
+ // Coarse path: inside the large table, only cell/header overlays are kept — the
157
+ // table/row/paragraph decorations there are redundant and cause expensive per-cell
158
+ // re-render. Blocks outside the table keep their normal decorations.
159
+ var coarseTables = coarseTableCellsOnly ? tableRanges(doc, from, to) : [];
134
160
  // Iterate over the document nodes within the range
135
161
  doc.nodesBetween(from, to, function (node, pos) {
136
- // Coarse path: only cell/header overlays are visible; table/row/paragraph
137
- // decorations are redundant and cause expensive per-cell re-render.
138
- if (coarseTableCellsOnly) {
162
+ if (coarseTableCellsOnly && isInsideTable(coarseTables, pos)) {
139
163
  var name = node.type.name;
140
164
  if (name !== 'tableCell' && name !== 'tableHeader') {
141
165
  return;
@@ -173,10 +197,10 @@ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration
173
197
  *
174
198
  * Callers are responsible for the `smart` diffType and gate checks.
175
199
  */
176
- var isDeletedContentPlacedBelow = exports.isDeletedContentPlacedBelow = function isDeletedContentPlacedBelow(_ref3) {
177
- var change = _ref3.change,
178
- deletedDiffPlacement = _ref3.deletedDiffPlacement,
179
- inlineDeletedDiffPlacement = _ref3.inlineDeletedDiffPlacement;
200
+ var isDeletedContentPlacedBelow = exports.isDeletedContentPlacedBelow = function isDeletedContentPlacedBelow(_ref5) {
201
+ var change = _ref5.change,
202
+ deletedDiffPlacement = _ref5.deletedDiffPlacement,
203
+ inlineDeletedDiffPlacement = _ref5.inlineDeletedDiffPlacement;
180
204
  var level = (0, _helpers.smartChangeLevel)(change);
181
205
  if (level === 'node' || level === 'paragraph') {
182
206
  return deletedDiffPlacement === 'bottom';
@@ -185,29 +209,29 @@ var isDeletedContentPlacedBelow = exports.isDeletedContentPlacedBelow = function
185
209
  // Inline-level (undefined) and sentence-level changes.
186
210
  return inlineDeletedDiffPlacement === 'after';
187
211
  };
188
- var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4) {
189
- var state = _ref4.state,
190
- pluginState = _ref4.pluginState,
191
- nodeViewSerializer = _ref4.nodeViewSerializer,
192
- colorScheme = _ref4.colorScheme,
193
- intl = _ref4.intl,
194
- activeIndexPos = _ref4.activeIndexPos,
195
- api = _ref4.api,
196
- _ref4$isInverted = _ref4.isInverted,
197
- isInverted = _ref4$isInverted === void 0 ? false : _ref4$isInverted,
198
- _ref4$diffType = _ref4.diffType,
199
- diffType = _ref4$diffType === void 0 ? (0, _isExtendedEnabled.getDefaultDiffType)() : _ref4$diffType,
200
- _ref4$hideDeletedDiff = _ref4.hideDeletedDiffs,
201
- hideDeletedDiffs = _ref4$hideDeletedDiff === void 0 ? false : _ref4$hideDeletedDiff,
202
- _ref4$hideAddedDiffsU = _ref4.hideAddedDiffsUnderline,
203
- hideAddedDiffsUnderlineParam = _ref4$hideAddedDiffsU === void 0 ? false : _ref4$hideAddedDiffsU,
204
- _ref4$showIndicators = _ref4.showIndicators,
205
- showIndicators = _ref4$showIndicators === void 0 ? false : _ref4$showIndicators,
206
- smartThresholds = _ref4.smartThresholds,
207
- _ref4$deletedDiffPlac = _ref4.deletedDiffPlacement,
208
- deletedDiffPlacement = _ref4$deletedDiffPlac === void 0 ? 'top' : _ref4$deletedDiffPlac,
209
- _ref4$inlineDeletedDi = _ref4.inlineDeletedDiffPlacement,
210
- inlineDeletedDiffPlacement = _ref4$inlineDeletedDi === void 0 ? 'before' : _ref4$inlineDeletedDi;
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;
211
235
  var originalDoc = pluginState.originalDoc,
212
236
  steps = pluginState.steps,
213
237
  isDisplayingChanges = pluginState.isDisplayingChanges;
@@ -328,10 +352,11 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
328
352
  // inward — when the widget is present the anchor must stay at the block
329
353
  // boundary to keep the indicator bar continuous with the deleted content.
330
354
  var willRenderDeletedWidget = change.deleted.length > 0 && !((0, _isExtendedEnabled.isExtendedEnabled)(diffType) && !isInverted && hideDeletedDiffs && change.inserted.length > 0);
331
- if (useCoarseTableDecoration) {
332
- // Skip the O(cells) inline decorations; the cell overlays (added below)
333
- // provide the highlight without the expensive content re-render.
334
- } else if (isSmartNodeLevel) {
355
+ if (isSmartNodeLevel) {
356
+ // For a large inserted table, skip the O(cells) inline decorations inside the
357
+ // table (the cell overlays added below provide the highlight without the
358
+ // expensive content re-render); leaf blocks outside the table still get theirs.
359
+ var coarseTables = useCoarseTableDecoration ? tableRanges(tr.doc, change.fromB, change.toB) : [];
335
360
  var _iterator2 = _createForOfIteratorHelper(leafTextblockRanges(tr.doc, change.fromB, change.toB)),
336
361
  _step2;
337
362
  try {
@@ -339,6 +364,9 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
339
364
  var _step2$value = (0, _slicedToArray2.default)(_step2.value, 2),
340
365
  from = _step2$value[0],
341
366
  to = _step2$value[1];
367
+ if (useCoarseTableDecoration && isInsideTable(coarseTables, from)) {
368
+ continue;
369
+ }
342
370
  decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createInlineChangedDecoration.createInlineChangedDecoration)(_objectSpread({
343
371
  change: {
344
372
  fromB: from,
@@ -518,42 +546,42 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
518
546
  };
519
547
  var calculateDiffDecorations = exports.calculateDiffDecorations = (0, _memoizeOne.default)(calculateDiffDecorationsInner,
520
548
  // Cache results unless relevant inputs change
521
- function (_ref5, _ref6) {
522
- var _ref0;
523
- var _ref7 = (0, _slicedToArray2.default)(_ref5, 1),
524
- _ref7$ = _ref7[0],
525
- pluginState = _ref7$.pluginState,
526
- state = _ref7$.state,
527
- colorScheme = _ref7$.colorScheme,
528
- intl = _ref7$.intl,
529
- activeIndexPos = _ref7$.activeIndexPos,
530
- isInverted = _ref7$.isInverted,
531
- diffType = _ref7$.diffType,
532
- hideDeletedDiffs = _ref7$.hideDeletedDiffs,
533
- hideAddedDiffsUnderline = _ref7$.hideAddedDiffsUnderline,
534
- showIndicators = _ref7$.showIndicators,
535
- smartThresholds = _ref7$.smartThresholds,
536
- deletedDiffPlacement = _ref7$.deletedDiffPlacement,
537
- inlineDeletedDiffPlacement = _ref7$.inlineDeletedDiffPlacement;
538
- var _ref8 = (0, _slicedToArray2.default)(_ref6, 1),
539
- _ref8$ = _ref8[0],
540
- lastPluginState = _ref8$.pluginState,
541
- lastState = _ref8$.state,
542
- lastColorScheme = _ref8$.colorScheme,
543
- lastIntl = _ref8$.intl,
544
- lastActiveIndexPos = _ref8$.activeIndexPos,
545
- lastIsInverted = _ref8$.isInverted,
546
- lastDiffType = _ref8$.diffType,
547
- lastHideDeletedDiffs = _ref8$.hideDeletedDiffs,
548
- lastHideAddedDiffsUnderline = _ref8$.hideAddedDiffsUnderline,
549
- lastShowIndicators = _ref8$.showIndicators,
550
- lastSmartThresholds = _ref8$.smartThresholds,
551
- lastDeletedDiffPlacement = _ref8$.deletedDiffPlacement,
552
- lastInlineDeletedDiffPlacement = _ref8$.inlineDeletedDiffPlacement;
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;
553
581
  var originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
554
582
  if ((0, _isExtendedEnabled.isExtendedEnabled)(diffType)) {
555
- var _ref9;
556
- return (_ref9 = 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 && _ref9 !== void 0 ? _ref9 : false;
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;
557
585
  }
558
- return (_ref0 = 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 && _ref0 !== void 0 ? _ref0 : false;
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;
559
587
  });
@@ -101,6 +101,21 @@ const isLargeInsertedTableRange = (doc, from, to) => {
101
101
  });
102
102
  return containsTable && leafCount > LARGE_TABLE_LEAF_THRESHOLD;
103
103
  };
104
+
105
+ // Collect the [from, to) ranges of every `table` node overlapping `[from, to)`. The coarse
106
+ // large-table path must only suppress decorations inside these ranges
107
+ const tableRanges = (doc, from, to) => {
108
+ const ranges = [];
109
+ doc.nodesBetween(from, to, (node, pos) => {
110
+ if (node.type.name === 'table') {
111
+ ranges.push([pos, pos + node.nodeSize]);
112
+ return false;
113
+ }
114
+ return true;
115
+ });
116
+ return ranges;
117
+ };
118
+ const isInsideTable = (tables, pos) => tables.some(([tFrom, tTo]) => pos >= tFrom && pos < tTo);
104
119
  const calculateNodesForBlockDecoration = ({
105
120
  doc,
106
121
  from,
@@ -114,11 +129,13 @@ const calculateNodesForBlockDecoration = ({
114
129
  coarseTableCellsOnly = false
115
130
  }) => {
116
131
  const decorations = [];
132
+ // Coarse path: inside the large table, only cell/header overlays are kept — the
133
+ // table/row/paragraph decorations there are redundant and cause expensive per-cell
134
+ // re-render. Blocks outside the table keep their normal decorations.
135
+ const coarseTables = coarseTableCellsOnly ? tableRanges(doc, from, to) : [];
117
136
  // Iterate over the document nodes within the range
118
137
  doc.nodesBetween(from, to, (node, pos) => {
119
- // Coarse path: only cell/header overlays are visible; table/row/paragraph
120
- // decorations are redundant and cause expensive per-cell re-render.
121
- if (coarseTableCellsOnly) {
138
+ if (coarseTableCellsOnly && isInsideTable(coarseTables, pos)) {
122
139
  const name = node.type.name;
123
140
  if (name !== 'tableCell' && name !== 'tableHeader') {
124
141
  return;
@@ -301,11 +318,15 @@ const calculateDiffDecorationsInner = ({
301
318
  // inward — when the widget is present the anchor must stay at the block
302
319
  // boundary to keep the indicator bar continuous with the deleted content.
303
320
  const willRenderDeletedWidget = change.deleted.length > 0 && !(isExtendedEnabled(diffType) && !isInverted && hideDeletedDiffs && change.inserted.length > 0);
304
- if (useCoarseTableDecoration) {
305
- // Skip the O(cells) inline decorations; the cell overlays (added below)
306
- // provide the highlight without the expensive content re-render.
307
- } else if (isSmartNodeLevel) {
321
+ if (isSmartNodeLevel) {
322
+ // For a large inserted table, skip the O(cells) inline decorations inside the
323
+ // table (the cell overlays added below provide the highlight without the
324
+ // expensive content re-render); leaf blocks outside the table still get theirs.
325
+ const coarseTables = useCoarseTableDecoration ? tableRanges(tr.doc, change.fromB, change.toB) : [];
308
326
  for (const [from, to] of leafTextblockRanges(tr.doc, change.fromB, change.toB)) {
327
+ if (useCoarseTableDecoration && isInsideTable(coarseTables, from)) {
328
+ continue;
329
+ }
309
330
  decorations.push(...createInlineChangedDecoration({
310
331
  change: {
311
332
  fromB: from,
@@ -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; } } }; }
@@ -108,27 +108,51 @@ var isLargeInsertedTableRange = function isLargeInsertedTableRange(doc, from, to
108
108
  });
109
109
  return containsTable && leafCount > LARGE_TABLE_LEAF_THRESHOLD;
110
110
  };
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;
111
+
112
+ // Collect the [from, to) ranges of every `table` node overlapping `[from, to)`. The coarse
113
+ // large-table path must only suppress decorations inside these ranges
114
+ var tableRanges = function tableRanges(doc, from, to) {
115
+ var ranges = [];
116
+ doc.nodesBetween(from, to, function (node, pos) {
117
+ if (node.type.name === 'table') {
118
+ ranges.push([pos, pos + node.nodeSize]);
119
+ return false;
120
+ }
121
+ return true;
122
+ });
123
+ return ranges;
124
+ };
125
+ var isInsideTable = function isInsideTable(tables, pos) {
126
+ return tables.some(function (_ref2) {
127
+ var _ref3 = _slicedToArray(_ref2, 2),
128
+ tFrom = _ref3[0],
129
+ tTo = _ref3[1];
130
+ return pos >= tFrom && pos < tTo;
131
+ });
132
+ };
133
+ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration(_ref4) {
134
+ var doc = _ref4.doc,
135
+ from = _ref4.from,
136
+ to = _ref4.to,
137
+ colorScheme = _ref4.colorScheme,
138
+ _ref4$isInserted = _ref4.isInserted,
139
+ isInserted = _ref4$isInserted === void 0 ? true : _ref4$isInserted,
140
+ activeIndexPos = _ref4.activeIndexPos,
141
+ _ref4$shouldHideDelet = _ref4.shouldHideDeleted,
142
+ shouldHideDeleted = _ref4$shouldHideDelet === void 0 ? false : _ref4$shouldHideDelet,
143
+ _ref4$showIndicators = _ref4.showIndicators,
144
+ showIndicators = _ref4$showIndicators === void 0 ? false : _ref4$showIndicators,
145
+ diffType = _ref4.diffType,
146
+ _ref4$coarseTableCell = _ref4.coarseTableCellsOnly,
147
+ coarseTableCellsOnly = _ref4$coarseTableCell === void 0 ? false : _ref4$coarseTableCell;
126
148
  var decorations = [];
149
+ // Coarse path: inside the large table, only cell/header overlays are kept — the
150
+ // table/row/paragraph decorations there are redundant and cause expensive per-cell
151
+ // re-render. Blocks outside the table keep their normal decorations.
152
+ var coarseTables = coarseTableCellsOnly ? tableRanges(doc, from, to) : [];
127
153
  // Iterate over the document nodes within the range
128
154
  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) {
155
+ if (coarseTableCellsOnly && isInsideTable(coarseTables, pos)) {
132
156
  var name = node.type.name;
133
157
  if (name !== 'tableCell' && name !== 'tableHeader') {
134
158
  return;
@@ -166,10 +190,10 @@ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration
166
190
  *
167
191
  * Callers are responsible for the `smart` diffType and gate checks.
168
192
  */
169
- export var isDeletedContentPlacedBelow = function isDeletedContentPlacedBelow(_ref3) {
170
- var change = _ref3.change,
171
- deletedDiffPlacement = _ref3.deletedDiffPlacement,
172
- inlineDeletedDiffPlacement = _ref3.inlineDeletedDiffPlacement;
193
+ export var isDeletedContentPlacedBelow = function isDeletedContentPlacedBelow(_ref5) {
194
+ var change = _ref5.change,
195
+ deletedDiffPlacement = _ref5.deletedDiffPlacement,
196
+ inlineDeletedDiffPlacement = _ref5.inlineDeletedDiffPlacement;
173
197
  var level = smartChangeLevel(change);
174
198
  if (level === 'node' || level === 'paragraph') {
175
199
  return deletedDiffPlacement === 'bottom';
@@ -178,29 +202,29 @@ export var isDeletedContentPlacedBelow = function isDeletedContentPlacedBelow(_r
178
202
  // Inline-level (undefined) and sentence-level changes.
179
203
  return inlineDeletedDiffPlacement === 'after';
180
204
  };
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;
205
+ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref6) {
206
+ var state = _ref6.state,
207
+ pluginState = _ref6.pluginState,
208
+ nodeViewSerializer = _ref6.nodeViewSerializer,
209
+ colorScheme = _ref6.colorScheme,
210
+ intl = _ref6.intl,
211
+ activeIndexPos = _ref6.activeIndexPos,
212
+ api = _ref6.api,
213
+ _ref6$isInverted = _ref6.isInverted,
214
+ isInverted = _ref6$isInverted === void 0 ? false : _ref6$isInverted,
215
+ _ref6$diffType = _ref6.diffType,
216
+ diffType = _ref6$diffType === void 0 ? getDefaultDiffType() : _ref6$diffType,
217
+ _ref6$hideDeletedDiff = _ref6.hideDeletedDiffs,
218
+ hideDeletedDiffs = _ref6$hideDeletedDiff === void 0 ? false : _ref6$hideDeletedDiff,
219
+ _ref6$hideAddedDiffsU = _ref6.hideAddedDiffsUnderline,
220
+ hideAddedDiffsUnderlineParam = _ref6$hideAddedDiffsU === void 0 ? false : _ref6$hideAddedDiffsU,
221
+ _ref6$showIndicators = _ref6.showIndicators,
222
+ showIndicators = _ref6$showIndicators === void 0 ? false : _ref6$showIndicators,
223
+ smartThresholds = _ref6.smartThresholds,
224
+ _ref6$deletedDiffPlac = _ref6.deletedDiffPlacement,
225
+ deletedDiffPlacement = _ref6$deletedDiffPlac === void 0 ? 'top' : _ref6$deletedDiffPlac,
226
+ _ref6$inlineDeletedDi = _ref6.inlineDeletedDiffPlacement,
227
+ inlineDeletedDiffPlacement = _ref6$inlineDeletedDi === void 0 ? 'before' : _ref6$inlineDeletedDi;
204
228
  var originalDoc = pluginState.originalDoc,
205
229
  steps = pluginState.steps,
206
230
  isDisplayingChanges = pluginState.isDisplayingChanges;
@@ -321,10 +345,11 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
321
345
  // inward — when the widget is present the anchor must stay at the block
322
346
  // boundary to keep the indicator bar continuous with the deleted content.
323
347
  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) {
348
+ if (isSmartNodeLevel) {
349
+ // For a large inserted table, skip the O(cells) inline decorations inside the
350
+ // table (the cell overlays added below provide the highlight without the
351
+ // expensive content re-render); leaf blocks outside the table still get theirs.
352
+ var coarseTables = useCoarseTableDecoration ? tableRanges(tr.doc, change.fromB, change.toB) : [];
328
353
  var _iterator2 = _createForOfIteratorHelper(leafTextblockRanges(tr.doc, change.fromB, change.toB)),
329
354
  _step2;
330
355
  try {
@@ -332,6 +357,9 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
332
357
  var _step2$value = _slicedToArray(_step2.value, 2),
333
358
  from = _step2$value[0],
334
359
  to = _step2$value[1];
360
+ if (useCoarseTableDecoration && isInsideTable(coarseTables, from)) {
361
+ continue;
362
+ }
335
363
  decorations.push.apply(decorations, _toConsumableArray(createInlineChangedDecoration(_objectSpread({
336
364
  change: {
337
365
  fromB: from,
@@ -511,42 +539,42 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
511
539
  };
512
540
  export var calculateDiffDecorations = memoizeOne(calculateDiffDecorationsInner,
513
541
  // 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;
542
+ function (_ref7, _ref8) {
543
+ var _ref10;
544
+ var _ref9 = _slicedToArray(_ref7, 1),
545
+ _ref9$ = _ref9[0],
546
+ pluginState = _ref9$.pluginState,
547
+ state = _ref9$.state,
548
+ colorScheme = _ref9$.colorScheme,
549
+ intl = _ref9$.intl,
550
+ activeIndexPos = _ref9$.activeIndexPos,
551
+ isInverted = _ref9$.isInverted,
552
+ diffType = _ref9$.diffType,
553
+ hideDeletedDiffs = _ref9$.hideDeletedDiffs,
554
+ hideAddedDiffsUnderline = _ref9$.hideAddedDiffsUnderline,
555
+ showIndicators = _ref9$.showIndicators,
556
+ smartThresholds = _ref9$.smartThresholds,
557
+ deletedDiffPlacement = _ref9$.deletedDiffPlacement,
558
+ inlineDeletedDiffPlacement = _ref9$.inlineDeletedDiffPlacement;
559
+ var _ref0 = _slicedToArray(_ref8, 1),
560
+ _ref0$ = _ref0[0],
561
+ lastPluginState = _ref0$.pluginState,
562
+ lastState = _ref0$.state,
563
+ lastColorScheme = _ref0$.colorScheme,
564
+ lastIntl = _ref0$.intl,
565
+ lastActiveIndexPos = _ref0$.activeIndexPos,
566
+ lastIsInverted = _ref0$.isInverted,
567
+ lastDiffType = _ref0$.diffType,
568
+ lastHideDeletedDiffs = _ref0$.hideDeletedDiffs,
569
+ lastHideAddedDiffsUnderline = _ref0$.hideAddedDiffsUnderline,
570
+ lastShowIndicators = _ref0$.showIndicators,
571
+ lastSmartThresholds = _ref0$.smartThresholds,
572
+ lastDeletedDiffPlacement = _ref0$.deletedDiffPlacement,
573
+ lastInlineDeletedDiffPlacement = _ref0$.inlineDeletedDiffPlacement;
546
574
  var originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
547
575
  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;
576
+ var _ref1;
577
+ return (_ref1 = 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 && _ref1 !== void 0 ? _ref1 : false;
550
578
  }
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;
579
+ return (_ref10 = originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isEqual(activeIndexPos, lastActiveIndexPos) && hideDeletedDiffs === lastHideDeletedDiffs) !== null && _ref10 !== void 0 ? _ref10 : false;
552
580
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-show-diff",
3
- "version": "14.0.2",
3
+ "version": "14.0.4",
4
4
  "description": "ShowDiff plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -28,7 +28,7 @@
28
28
  "@atlaskit/editor-tables": "^3.0.0",
29
29
  "@atlaskit/platform-feature-experiments": "^0.3.0",
30
30
  "@atlaskit/platform-feature-flags": "^2.1.0",
31
- "@atlaskit/tmp-editor-statsig": "^161.0.0",
31
+ "@atlaskit/tmp-editor-statsig": "^162.0.0",
32
32
  "@atlaskit/tokens": "^16.8.0",
33
33
  "@babel/runtime": "^7.0.0",
34
34
  "@compiled/react": "^1.0.2",
@@ -59,7 +59,7 @@
59
59
  "react-intl": "^7.0.0"
60
60
  },
61
61
  "peerDependencies": {
62
- "@atlaskit/editor-common": "^120.1.0",
62
+ "@atlaskit/editor-common": "^120.2.0",
63
63
  "react": "^18.2.0 || ^19.2.0"
64
64
  },
65
65
  "techstack": {