@atlaskit/editor-plugin-show-diff 17.1.5 → 17.1.6

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 (33) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +12 -1
  3. package/dist/cjs/pm-plugins/decorations/createAnchorDecorationWidgets.js +165 -32
  4. package/dist/cjs/pm-plugins/decorations/createBlockChangedDecoration.js +5 -1
  5. package/dist/cjs/pm-plugins/decorations/createChangedRowDecorationWidgets.js +4 -1
  6. package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +5 -1
  7. package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +14 -1
  8. package/dist/cjs/pm-plugins/decorations/decorationKeys.js +8 -3
  9. package/dist/cjs/ui/IndicatorBar/IndicatorBarContentComponent.js +5 -3
  10. package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +12 -1
  11. package/dist/es2019/pm-plugins/decorations/createAnchorDecorationWidgets.js +131 -12
  12. package/dist/es2019/pm-plugins/decorations/createBlockChangedDecoration.js +5 -1
  13. package/dist/es2019/pm-plugins/decorations/createChangedRowDecorationWidgets.js +4 -1
  14. package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +5 -1
  15. package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +14 -1
  16. package/dist/es2019/pm-plugins/decorations/decorationKeys.js +7 -0
  17. package/dist/es2019/ui/IndicatorBar/IndicatorBarContentComponent.js +5 -3
  18. package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +12 -1
  19. package/dist/esm/pm-plugins/decorations/createAnchorDecorationWidgets.js +165 -32
  20. package/dist/esm/pm-plugins/decorations/createBlockChangedDecoration.js +5 -1
  21. package/dist/esm/pm-plugins/decorations/createChangedRowDecorationWidgets.js +4 -1
  22. package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +5 -1
  23. package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +14 -1
  24. package/dist/esm/pm-plugins/decorations/decorationKeys.js +8 -3
  25. package/dist/esm/ui/IndicatorBar/IndicatorBarContentComponent.js +5 -3
  26. package/dist/types/pm-plugins/decorations/createAnchorDecorationWidgets.d.ts +14 -4
  27. package/dist/types/pm-plugins/decorations/createBlockChangedDecoration.d.ts +2 -1
  28. package/dist/types/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +2 -1
  29. package/dist/types/pm-plugins/decorations/createInlineChangedDecoration.d.ts +2 -1
  30. package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +2 -1
  31. package/dist/types/pm-plugins/decorations/decorationKeys.d.ts +3 -1
  32. package/dist/types/showDiffPluginType.d.ts +1 -0
  33. package/package.json +1 -1
@@ -1,4 +1,8 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ 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; } } }; }
4
+ 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; } }
5
+ 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; }
2
6
  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; }
3
7
  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; }
4
8
  import { findParentNodeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
@@ -30,21 +34,21 @@ var resolveDocLevelNode = function resolveDocLevelNode(doc, from) {
30
34
  beforePos: nodeStart - 1
31
35
  };
32
36
  };
33
-
34
37
  /**
35
38
  * Handles edge cases for block nodes whose inline content can exceed the doc
36
39
  * margin (tables, layouts, expands). Returns the position whose DOM should be
37
40
  * measured to size the left anchor, or `undefined` when the diff is not inside
38
41
  * such a node.
39
42
  */
40
- var edgeCases = function edgeCases(doc, from) {
43
+ var edgeCases = function edgeCases(doc, from, nodeOverride) {
41
44
  var resolved = resolveDocLevelNode(doc, from);
42
45
  if (!resolved) {
43
46
  return undefined;
44
47
  }
45
- var node = resolved.node,
48
+ var resolvedNode = resolved.node,
46
49
  nodeStart = resolved.nodeStart,
47
50
  beforePos = resolved.beforePos;
51
+ var node = fg('platform_editor_ai_show_diff_patch_2') ? nodeOverride !== null && nodeOverride !== void 0 ? nodeOverride : resolvedNode : resolvedNode;
48
52
  if (node.type.name === 'layoutSection' && fg('platform_editor_ai_show_diff_patch_1')) {
49
53
  // Columns extend past the node-view wrapper via negative margins (12px or 20px).
50
54
  // Measure their container so the indicator stays outside the diff outline, including
@@ -112,6 +116,45 @@ var edgeCases = function edgeCases(doc, from) {
112
116
  return undefined;
113
117
  }
114
118
  };
119
+ var getEdgeCasesForSlice = function getEdgeCasesForSlice(doc, from, slice, measureElement) {
120
+ var _targets$find;
121
+ var resolved = resolveDocLevelNode(doc, from);
122
+ if (!resolved) {
123
+ return [];
124
+ }
125
+ var targets = [];
126
+ // edge cases can only be top level nodes, so we only care about the top level nodes in the slice
127
+ slice.content.forEach(function (node, offset) {
128
+ var edgeCase = edgeCases(doc, from + offset, node);
129
+ if (edgeCase) {
130
+ targets.push(_objectSpread(_objectSpread({}, edgeCase), {}, {
131
+ measureElement: measureElement
132
+ }));
133
+ }
134
+ });
135
+ return targets.length > 0 ? [{
136
+ beforePos: resolved.beforePos,
137
+ leftOffset: (_targets$find = targets.find(function (target) {
138
+ return target.leftOffset !== undefined;
139
+ })) === null || _targets$find === void 0 ? void 0 : _targets$find.leftOffset,
140
+ widthMeasureTargets: targets
141
+ }] : [];
142
+ };
143
+
144
+ /**
145
+ * Finds the edge cases in the current document for either a whole range or one position.
146
+ * A missing `to` intentionally means the single-position lookup is the fallback.
147
+ */
148
+ var getEdgeCasesForDocument = function getEdgeCasesForDocument(doc, from, to) {
149
+ if (to !== undefined) {
150
+ var edgeCasesForSlice = getEdgeCasesForSlice(doc, from, doc.slice(from, to));
151
+ if (edgeCasesForSlice.length > 0) {
152
+ return edgeCasesForSlice;
153
+ }
154
+ }
155
+ var edgeCase = edgeCases(doc, from);
156
+ return edgeCase ? [edgeCase] : [];
157
+ };
115
158
 
116
159
  /**
117
160
  * Create a widget that marks the start of the doc margin.
@@ -142,10 +185,23 @@ export var createDocMarginAnchorWidget = function createDocMarginAnchorWidget()
142
185
  * anchor positioning. Shared by inline and node (widget) diff decorations.
143
186
  */
144
187
  export var createLeftAnchorWidget = function createLeftAnchorWidget(_ref) {
188
+ var _range$from;
145
189
  var doc = _ref.doc,
146
190
  from = _ref.from,
147
- diffId = _ref.diffId;
148
- var edgeCase = edgeCases(doc, from);
191
+ to = _ref.to,
192
+ diffId = _ref.diffId,
193
+ leftAnchorId = _ref.leftAnchorId,
194
+ measureElement = _ref.measureElement,
195
+ sliceOverride = _ref.sliceOverride,
196
+ underlyingRange = _ref.underlyingRange;
197
+ var overrideEdgeCases = sliceOverride ? getEdgeCasesForSlice(doc, from, sliceOverride, measureElement) : [];
198
+ var range = underlyingRange !== null && underlyingRange !== void 0 ? underlyingRange : to !== undefined ? {
199
+ from: from,
200
+ to: to
201
+ } : undefined;
202
+ var documentEdgeCases = getEdgeCasesForDocument(doc, (_range$from = range === null || range === void 0 ? void 0 : range.from) !== null && _range$from !== void 0 ? _range$from : from, range === null || range === void 0 ? void 0 : range.to);
203
+ var allEdgeCases = [].concat(_toConsumableArray(overrideEdgeCases), _toConsumableArray(documentEdgeCases));
204
+ var edgeCase = fg('platform_editor_ai_show_diff_patch_2') ? allEdgeCases[0] : edgeCases(doc, from);
149
205
  if (edgeCase === undefined) {
150
206
  return undefined;
151
207
  }
@@ -154,7 +210,7 @@ export var createLeftAnchorWidget = function createLeftAnchorWidget(_ref) {
154
210
  // resizable block container.
155
211
  var beforePos = edgeCase.beforePos;
156
212
  var leftAnchorKey = buildAnchorDecorationKey({
157
- diffId: diffId,
213
+ diffId: leftAnchorId !== null && leftAnchorId !== void 0 ? leftAnchorId : diffId,
158
214
  anchorType: AnchorTypeKey.left
159
215
  });
160
216
  var leftResizeObserver;
@@ -172,15 +228,87 @@ export var createLeftAnchorWidget = function createLeftAnchorWidget(_ref) {
172
228
  anchor.style.setProperty('left', "calc(50% - ".concat((edgeCase === null || edgeCase === void 0 ? void 0 : edgeCase.leftOffset) || 0, "px)"));
173
229
  anchor.style.setProperty('transform', 'translateX(-50%)');
174
230
  wrapper.appendChild(anchor);
175
- var measureWidth = function measureWidth() {
231
+ var _measureWidth = function measureWidth() {
176
232
  var _nodeDOM$querySelecto;
233
+ if (fg('platform_editor_ai_show_diff_patch_2')) {
234
+ var widthMeasureTargets = allEdgeCases.flatMap(function (target) {
235
+ var _target$widthMeasureT;
236
+ return (_target$widthMeasureT = target.widthMeasureTargets) !== null && _target$widthMeasureT !== void 0 ? _target$widthMeasureT : [target];
237
+ });
238
+ if (getPos() === undefined || widthMeasureTargets.length === 0) {
239
+ return;
240
+ }
241
+ var measuredElements = widthMeasureTargets.flatMap(function (_ref2) {
242
+ var targetMeasureElement = _ref2.measureElement,
243
+ measureLeft = _ref2.measureLeft,
244
+ measurePos = _ref2.measurePos,
245
+ measureSelector = _ref2.measureSelector;
246
+ if (measurePos === undefined) {
247
+ return [];
248
+ }
249
+ var nodeDOM = targetMeasureElement !== null && targetMeasureElement !== void 0 ? targetMeasureElement : view.nodeDOM(measurePos);
250
+ var elements = nodeDOM instanceof HTMLElement ? measureSelector ? Array.from(nodeDOM.querySelectorAll(measureSelector)) : [nodeDOM] : [];
251
+ return elements.map(function (element) {
252
+ return {
253
+ element: element,
254
+ measureLeft: measureLeft
255
+ };
256
+ });
257
+ });
258
+
259
+ // A single diff can include multiple edge-case nodes, so measure the widest one.
260
+ var widest;
261
+ var _iterator = _createForOfIteratorHelper(measuredElements),
262
+ _step;
263
+ try {
264
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
265
+ var target = _step.value;
266
+ if (!widest || target.element.offsetWidth > widest.element.offsetWidth) {
267
+ widest = target;
268
+ }
269
+ }
270
+ } catch (err) {
271
+ _iterator.e(err);
272
+ } finally {
273
+ _iterator.f();
274
+ }
275
+ if (widest) {
276
+ var updateAnchor = function updateAnchor() {
277
+ if (getPos() === undefined) {
278
+ return;
279
+ }
280
+ if (widest.measureLeft) {
281
+ var left = widest.element.getBoundingClientRect().left - wrapper.getBoundingClientRect().left;
282
+ anchor.style.setProperty('left', "".concat(left, "px"));
283
+ anchor.style.setProperty('transform', 'none');
284
+ }
285
+ anchor.style.setProperty('width', "".concat(widest.element.offsetWidth, "px"));
286
+ };
287
+ updateAnchor();
288
+
289
+ // Observe the measured elements for size changes (e.g. page
290
+ // resize) so the indicator stays aligned.
291
+ if (!leftResizeObserver) {
292
+ leftResizeObserver = new ResizeObserver(_measureWidth);
293
+ measuredElements.forEach(function (_ref3) {
294
+ var _leftResizeObserver;
295
+ var element = _ref3.element;
296
+ return (_leftResizeObserver = leftResizeObserver) === null || _leftResizeObserver === void 0 ? void 0 : _leftResizeObserver.observe(element);
297
+ });
298
+ if (widest.measureLeft) {
299
+ leftResizeObserver.observe(wrapper);
300
+ }
301
+ }
302
+ }
303
+ return;
304
+ }
177
305
  if (getPos() === undefined || edgeCase.measurePos === undefined) {
178
306
  return;
179
307
  }
180
308
  var nodeDOM = view.nodeDOM(edgeCase.measurePos);
181
309
  var dom = edgeCase.measureSelector && nodeDOM instanceof HTMLElement ? (_nodeDOM$querySelecto = nodeDOM.querySelector(edgeCase.measureSelector)) !== null && _nodeDOM$querySelecto !== void 0 ? _nodeDOM$querySelecto : nodeDOM : nodeDOM;
182
310
  if (dom instanceof HTMLElement) {
183
- var updateAnchor = function updateAnchor() {
311
+ var _updateAnchor = function _updateAnchor() {
184
312
  if (getPos() === undefined) {
185
313
  return;
186
314
  }
@@ -192,12 +320,12 @@ export var createLeftAnchorWidget = function createLeftAnchorWidget(_ref) {
192
320
  anchor.style.setProperty('width', "".concat(dom.offsetWidth, "px"));
193
321
  };
194
322
  // Align against the block's horizontal extent.
195
- updateAnchor();
323
+ _updateAnchor();
196
324
 
197
325
  // Observe the measured element for size changes (e.g. page
198
326
  // resize) so the indicator stays aligned. CCI-17981
199
327
  if (!leftResizeObserver) {
200
- leftResizeObserver = new ResizeObserver(updateAnchor);
328
+ leftResizeObserver = new ResizeObserver(_updateAnchor);
201
329
  leftResizeObserver.observe(dom);
202
330
  if (edgeCase.measureLeft) {
203
331
  leftResizeObserver.observe(wrapper);
@@ -208,7 +336,7 @@ export var createLeftAnchorWidget = function createLeftAnchorWidget(_ref) {
208
336
 
209
337
  // The block DOM may not be settled synchronously (e.g. after a
210
338
  // transaction), so defer the measurement like the gap cursor does.
211
- requestAnimationFrame(measureWidth);
339
+ requestAnimationFrame(_measureWidth);
212
340
  return wrapper;
213
341
  }, _objectSpread(_objectSpread({}, buildAnchorDecorationSpec({
214
342
  diffId: diffId,
@@ -216,8 +344,8 @@ export var createLeftAnchorWidget = function createLeftAnchorWidget(_ref) {
216
344
  side: -999
217
345
  })), {}, {
218
346
  destroy: function destroy() {
219
- var _leftResizeObserver;
220
- return (_leftResizeObserver = leftResizeObserver) === null || _leftResizeObserver === void 0 ? void 0 : _leftResizeObserver.disconnect();
347
+ var _leftResizeObserver2;
348
+ return (_leftResizeObserver2 = leftResizeObserver) === null || _leftResizeObserver2 === void 0 ? void 0 : _leftResizeObserver2.disconnect();
221
349
  }
222
350
  }));
223
351
  };
@@ -233,16 +361,18 @@ export var createLeftAnchorWidget = function createLeftAnchorWidget(_ref) {
233
361
  * layout, expand) so the bar aligns within the container boundary.
234
362
  *
235
363
  */
236
- export var createBlockIndicatorAnchorWidgets = function createBlockIndicatorAnchorWidgets(_ref2) {
237
- var _ref3, _parentTable$pos;
238
- var doc = _ref2.doc,
239
- from = _ref2.from,
240
- to = _ref2.to,
241
- diffId = _ref2.diffId;
364
+ export var createBlockIndicatorAnchorWidgets = function createBlockIndicatorAnchorWidgets(_ref4) {
365
+ var _ref5, _parentTable$pos;
366
+ var doc = _ref4.doc,
367
+ from = _ref4.from,
368
+ to = _ref4.to,
369
+ diffId = _ref4.diffId,
370
+ leftAnchorId = _ref4.leftAnchorId;
242
371
  var leftAnchor = createLeftAnchorWidget({
243
372
  doc: doc,
244
373
  from: from,
245
- diffId: diffId
374
+ diffId: diffId,
375
+ leftAnchorId: leftAnchorId
246
376
  });
247
377
  var maybeLeftAnchor = leftAnchor ? [leftAnchor] : [];
248
378
 
@@ -281,7 +411,7 @@ export var createBlockIndicatorAnchorWidgets = function createBlockIndicatorAnch
281
411
  // bounding box or positioning context, so measuring its top produces an offset from the
282
412
  // viewport origin and displaces the indicator into content below the editor. Keep the
283
413
  // wrapper outside the layout, just as we do for tables, but still measure the target node.
284
- var widgetPos = (_ref3 = (_parentTable$pos = parentTable === null || parentTable === void 0 ? void 0 : parentTable.pos) !== null && _parentTable$pos !== void 0 ? _parentTable$pos : parentLayout === null || parentLayout === void 0 ? void 0 : parentLayout.pos) !== null && _ref3 !== void 0 ? _ref3 : from;
414
+ var widgetPos = (_ref5 = (_parentTable$pos = parentTable === null || parentTable === void 0 ? void 0 : parentTable.pos) !== null && _parentTable$pos !== void 0 ? _parentTable$pos : parentLayout === null || parentLayout === void 0 ? void 0 : parentLayout.pos) !== null && _ref5 !== void 0 ? _ref5 : from;
285
415
  // Measure the actual cell/row DOM when inside one; otherwise measure the
286
416
  // widget's own position.
287
417
  var measurePos = parentCellOrRow ? parentCellOrRow.pos : from;
@@ -380,11 +510,11 @@ export var createAnchorNameSpan = function createAnchorNameSpan(anchorKey) {
380
510
  span.style.setProperty('anchor-name', "--".concat(anchorKey));
381
511
  return span;
382
512
  };
383
- var createAnchorSpanWidget = function createAnchorSpanWidget(_ref4) {
384
- var pos = _ref4.pos,
385
- diffId = _ref4.diffId,
386
- anchorType = _ref4.anchorType,
387
- side = _ref4.side;
513
+ var createAnchorSpanWidget = function createAnchorSpanWidget(_ref6) {
514
+ var pos = _ref6.pos,
515
+ diffId = _ref6.diffId,
516
+ anchorType = _ref6.anchorType,
517
+ side = _ref6.side;
388
518
  return Decoration.widget(pos, function () {
389
519
  return createAnchorNameSpan(buildAnchorDecorationKey({
390
520
  diffId: diffId,
@@ -401,15 +531,18 @@ var createAnchorSpanWidget = function createAnchorSpanWidget(_ref4) {
401
531
  * Invisible `from`/`to` (and optional `left`) anchor widgets for one inline diff
402
532
  * range, so the `IndicatorBar` can align itself via CSS anchor positioning.
403
533
  */
404
- export var createInlineIndicatorAnchorWidgets = function createInlineIndicatorAnchorWidgets(_ref5) {
405
- var doc = _ref5.doc,
406
- from = _ref5.from,
407
- to = _ref5.to,
408
- diffId = _ref5.diffId;
534
+ export var createInlineIndicatorAnchorWidgets = function createInlineIndicatorAnchorWidgets(_ref7) {
535
+ var doc = _ref7.doc,
536
+ from = _ref7.from,
537
+ to = _ref7.to,
538
+ diffId = _ref7.diffId,
539
+ leftAnchorId = _ref7.leftAnchorId;
409
540
  var leftAnchor = createLeftAnchorWidget({
410
541
  doc: doc,
411
542
  from: from,
412
- diffId: diffId
543
+ to: fg('platform_editor_ai_show_diff_patch_2') ? to : undefined,
544
+ diffId: diffId,
545
+ leftAnchorId: leftAnchorId
413
546
  });
414
547
  var maybeLeftAnchor = leftAnchor ? [leftAnchor] : [];
415
548
 
@@ -177,6 +177,7 @@ export var createBlockChangedDecoration = function createBlockChangedDecoration(
177
177
  isInserted = _ref3$isInserted === void 0 ? true : _ref3$isInserted,
178
178
  _ref3$isActive = _ref3.isActive,
179
179
  isActive = _ref3$isActive === void 0 ? false : _ref3$isActive,
180
+ leftAnchorId = _ref3.leftAnchorId,
180
181
  _ref3$shouldHideDelet = _ref3.shouldHideDeleted,
181
182
  shouldHideDeleted = _ref3$shouldHideDelet === void 0 ? false : _ref3$shouldHideDelet,
182
183
  _ref3$showContributor = _ref3.showContributorTags,
@@ -207,6 +208,7 @@ export var createBlockChangedDecoration = function createBlockChangedDecoration(
207
208
  colorScheme: colorScheme,
208
209
  decorationType: 'block',
209
210
  diffId: diffId,
211
+ leftAnchorId: leftAnchorId,
210
212
  isActive: isActive,
211
213
  isInserted: isInserted,
212
214
  nodeName: change.name,
@@ -263,6 +265,7 @@ export var createBlockChangedDecoration = function createBlockChangedDecoration(
263
265
  colorScheme: colorScheme,
264
266
  decorationType: 'block',
265
267
  diffId: diffId,
268
+ leftAnchorId: leftAnchorId,
266
269
  isActive: isActive,
267
270
  isInserted: isInserted,
268
271
  nodeName: change.name,
@@ -279,7 +282,8 @@ export var createBlockChangedDecoration = function createBlockChangedDecoration(
279
282
  doc: doc,
280
283
  from: change.from,
281
284
  to: change.to,
282
- diffId: diffId
285
+ diffId: diffId,
286
+ leftAnchorId: leftAnchorId
283
287
  })));
284
288
  }
285
289
 
@@ -305,6 +305,7 @@ export var createChangedRowDecorationWidgets = function createChangedRowDecorati
305
305
  isActive = _ref6.isActive,
306
306
  _ref6$isInserted = _ref6.isInserted,
307
307
  isInserted = _ref6$isInserted === void 0 ? false : _ref6$isInserted,
308
+ leftAnchorId = _ref6.leftAnchorId,
308
309
  diffType = _ref6.diffType,
309
310
  intl = _ref6.intl,
310
311
  _ref6$showIndicators = _ref6.showIndicators,
@@ -359,7 +360,8 @@ export var createChangedRowDecorationWidgets = function createChangedRowDecorati
359
360
  var leftAnchor = createLeftAnchorWidget({
360
361
  doc: newDoc,
361
362
  from: safeInsertPos,
362
- diffId: diffId
363
+ diffId: diffId,
364
+ leftAnchorId: leftAnchorId
363
365
  });
364
366
  if (leftAnchor) {
365
367
  decorations.push(leftAnchor);
@@ -401,6 +403,7 @@ export var createChangedRowDecorationWidgets = function createChangedRowDecorati
401
403
  colorScheme: colorScheme,
402
404
  decorationType: 'widget',
403
405
  diffId: diffId,
406
+ leftAnchorId: leftAnchorId,
404
407
  isActive: isActive,
405
408
  isInserted: isInserted,
406
409
  diffType: diffType
@@ -139,6 +139,7 @@ export var createInlineChangedDecoration = function createInlineChangedDecoratio
139
139
  isActive = _ref2$isActive === void 0 ? false : _ref2$isActive,
140
140
  _ref2$isInserted = _ref2.isInserted,
141
141
  isInserted = _ref2$isInserted === void 0 ? true : _ref2$isInserted,
142
+ leftAnchorId = _ref2.leftAnchorId,
142
143
  _ref2$isAtomicInlineN = _ref2.isAtomicInlineNode,
143
144
  isAtomicInlineNode = _ref2$isAtomicInlineN === void 0 ? false : _ref2$isAtomicInlineN,
144
145
  _ref2$shouldHideDelet = _ref2.shouldHideDeleted,
@@ -175,6 +176,7 @@ export var createInlineChangedDecoration = function createInlineChangedDecoratio
175
176
  colorScheme: colorScheme,
176
177
  decorationType: 'inline',
177
178
  diffId: diffId,
179
+ leftAnchorId: leftAnchorId,
178
180
  isActive: isActive,
179
181
  isInserted: isInserted
180
182
  }))];
@@ -238,6 +240,7 @@ export var createInlineChangedDecoration = function createInlineChangedDecoratio
238
240
  colorScheme: colorScheme,
239
241
  decorationType: 'inline',
240
242
  diffId: diffId,
243
+ leftAnchorId: leftAnchorId,
241
244
  isActive: isActive,
242
245
  isInserted: isInserted
243
246
  }))];
@@ -273,7 +276,8 @@ export var createInlineChangedDecoration = function createInlineChangedDecoratio
273
276
  doc: doc,
274
277
  from: anchorFrom,
275
278
  to: anchorTo,
276
- diffId: diffId
279
+ diffId: diffId,
280
+ leftAnchorId: leftAnchorId
277
281
  })));
278
282
  }
279
283
 
@@ -34,6 +34,7 @@ var createTableCellContentWidgets = function createTableCellContentWidgets(_ref)
34
34
  nodeViewSerializer = _ref.nodeViewSerializer,
35
35
  colorScheme = _ref.colorScheme,
36
36
  isInserted = _ref.isInserted,
37
+ leftAnchorId = _ref.leftAnchorId,
37
38
  diffType = _ref.diffType;
38
39
  // Collect the inner content position of each cell in the new document within
39
40
  // the change range. Whole-cell replacement preserves cell count/order, so the
@@ -90,6 +91,7 @@ var createTableCellContentWidgets = function createTableCellContentWidgets(_ref)
90
91
  colorScheme: colorScheme,
91
92
  decorationType: 'widget',
92
93
  diffId: crypto.randomUUID(),
94
+ leftAnchorId: leftAnchorId,
93
95
  isInserted: isInserted,
94
96
  diffType: diffType
95
97
  }, isExtendedEnabled(diffType) && {
@@ -115,6 +117,7 @@ export var createNodeChangedDecorationWidget = function createNodeChangedDecorat
115
117
  activeIndexPos = _ref2.activeIndexPos,
116
118
  _ref2$isInserted = _ref2.isInserted,
117
119
  isInserted = _ref2$isInserted === void 0 ? false : _ref2$isInserted,
120
+ leftAnchorId = _ref2.leftAnchorId,
118
121
  _ref2$showContributor = _ref2.showContributorTags,
119
122
  showContributorTags = _ref2$showContributor === void 0 ? false : _ref2$showContributor,
120
123
  _ref2$showIndicators = _ref2.showIndicators,
@@ -178,6 +181,7 @@ export var createNodeChangedDecorationWidget = function createNodeChangedDecorat
178
181
  nodeViewSerializer: nodeViewSerializer,
179
182
  colorScheme: colorScheme,
180
183
  isInserted: isInserted,
184
+ leftAnchorId: leftAnchorId,
181
185
  diffType: diffType
182
186
  });
183
187
  }
@@ -194,6 +198,7 @@ export var createNodeChangedDecorationWidget = function createNodeChangedDecorat
194
198
  colorScheme: colorScheme,
195
199
  isActive: isActive,
196
200
  isInserted: isInserted,
201
+ leftAnchorId: leftAnchorId,
197
202
  diffType: diffType,
198
203
  intl: intl,
199
204
  // Needed for the row's own indicator anchor; this path returns before the
@@ -492,7 +497,14 @@ export var createNodeChangedDecorationWidget = function createNodeChangedDecorat
492
497
  var leftAnchor = createLeftAnchorWidget({
493
498
  doc: newDoc,
494
499
  from: safeInsertPos,
495
- diffId: diffId
500
+ diffId: diffId,
501
+ leftAnchorId: leftAnchorId,
502
+ measureElement: fg('platform_editor_ai_show_diff_patch_2') ? dom : undefined,
503
+ sliceOverride: fg('platform_editor_ai_show_diff_patch_2') ? slice : undefined,
504
+ underlyingRange: fg('platform_editor_ai_show_diff_patch_2') ? {
505
+ from: change.fromB,
506
+ to: change.toB
507
+ } : undefined
496
508
  });
497
509
  if (leftAnchor) {
498
510
  decorations.push(leftAnchor);
@@ -503,6 +515,7 @@ export var createNodeChangedDecorationWidget = function createNodeChangedDecorat
503
515
  colorScheme: colorScheme,
504
516
  decorationType: 'widget',
505
517
  diffId: diffId,
518
+ leftAnchorId: leftAnchorId,
506
519
  isActive: isActive,
507
520
  isInserted: isInserted,
508
521
  diffType: diffType
@@ -75,10 +75,11 @@ export var buildDiffDecorationSpec = function buildDiffDecorationSpec(_ref3) {
75
75
  diffId = _ref3.diffId,
76
76
  isActive = _ref3.isActive,
77
77
  isInserted = _ref3.isInserted,
78
+ leftAnchorId = _ref3.leftAnchorId,
78
79
  nodeName = _ref3.nodeName,
79
80
  side = _ref3.side,
80
81
  diffType = _ref3.diffType;
81
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
82
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
82
83
  decorationFamily: DecorationFamily.diff,
83
84
  decorationType: decorationType,
84
85
  diffId: diffId,
@@ -94,6 +95,8 @@ export var buildDiffDecorationSpec = function buildDiffDecorationSpec(_ref3) {
94
95
  isActive: isActive
95
96
  } : {}), isInserted !== undefined ? {
96
97
  isInserted: isInserted
98
+ } : {}), leftAnchorId ? {
99
+ leftAnchorId: leftAnchorId
97
100
  } : {}), colorScheme ? {
98
101
  colorScheme: colorScheme
99
102
  } : {}), nodeName ? {
@@ -150,11 +153,13 @@ export var isDiffDecoration = function isDiffDecoration(decoration) {
150
153
  export var extractDiffDescriptors = function extractDiffDescriptors(decorations) {
151
154
  return decorations.find(undefined, undefined, isDiffDecorationSpec).filter(isDiffDecoration).map(function (_ref5) {
152
155
  var spec = _ref5.spec;
153
- return _objectSpread(_objectSpread(_objectSpread({}, spec.colorScheme ? {
156
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, spec.colorScheme ? {
154
157
  colorScheme: spec.colorScheme
155
158
  } : {}), {}, {
156
159
  id: spec.diffId
157
- }, spec.isInserted !== undefined ? {
160
+ }, spec.leftAnchorId ? {
161
+ leftAnchorId: spec.leftAnchorId
162
+ } : {}), spec.isInserted !== undefined ? {
158
163
  isInserted: spec.isInserted
159
164
  } : {}), {}, {
160
165
  type: spec.decorationType
@@ -5,6 +5,8 @@ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'
5
5
  import { buildAnchorDecorationKey, AnchorTypeKey } from '../../pm-plugins/decorations/decorationKeys';
6
6
  import { IndicatorBar } from './IndicatorBar';
7
7
  var renderIndicatorBar = function renderIndicatorBar(descriptor) {
8
+ var _descriptor$leftAncho;
9
+ var leftAnchorId = (_descriptor$leftAncho = descriptor.leftAnchorId) !== null && _descriptor$leftAncho !== void 0 ? _descriptor$leftAncho : descriptor.id;
8
10
  switch (descriptor.type) {
9
11
  case 'inline':
10
12
  {
@@ -21,7 +23,7 @@ var renderIndicatorBar = function renderIndicatorBar(descriptor) {
21
23
  anchorType: AnchorTypeKey.to
22
24
  }),
23
25
  anchorLeft: buildAnchorDecorationKey({
24
- diffId: descriptor.id,
26
+ diffId: leftAnchorId,
25
27
  anchorType: AnchorTypeKey.left
26
28
  })
27
29
  });
@@ -41,7 +43,7 @@ var renderIndicatorBar = function renderIndicatorBar(descriptor) {
41
43
  anchorTop: blockAnchor,
42
44
  anchorBottom: blockAnchor,
43
45
  anchorLeft: buildAnchorDecorationKey({
44
- diffId: descriptor.id,
46
+ diffId: leftAnchorId,
45
47
  anchorType: AnchorTypeKey.left
46
48
  })
47
49
  });
@@ -59,7 +61,7 @@ var renderIndicatorBar = function renderIndicatorBar(descriptor) {
59
61
  diffId: descriptor.id
60
62
  }),
61
63
  anchorLeft: buildAnchorDecorationKey({
62
- diffId: descriptor.id,
64
+ diffId: leftAnchorId,
63
65
  anchorType: AnchorTypeKey.left
64
66
  }),
65
67
  anchorLeftFallback: buildAnchorDecorationKey({
@@ -1,4 +1,4 @@
1
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
1
+ import type { Node as PMNode, Slice } from '@atlaskit/editor-prosemirror/model';
2
2
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
3
  /**
4
4
  * Create a widget that marks the start of the doc margin.
@@ -16,10 +16,18 @@ export declare const createDocMarginAnchorWidget: () => Decoration;
16
16
  * doc margin so the `IndicatorBar` can align its left edge against it via CSS
17
17
  * anchor positioning. Shared by inline and node (widget) diff decorations.
18
18
  */
19
- export declare const createLeftAnchorWidget: ({ doc, from, diffId, }: {
19
+ export declare const createLeftAnchorWidget: ({ doc, from, to, diffId, leftAnchorId, measureElement, sliceOverride, underlyingRange, }: {
20
20
  diffId: string;
21
21
  doc: PMNode;
22
22
  from: number;
23
+ leftAnchorId?: string;
24
+ measureElement?: HTMLElement;
25
+ sliceOverride?: Slice;
26
+ to?: number;
27
+ underlyingRange?: {
28
+ from: number;
29
+ to: number;
30
+ };
23
31
  }) => Decoration | undefined;
24
32
  /**
25
33
  * Creates invisible anchor widgets for a single block-changed diff so that the
@@ -32,10 +40,11 @@ export declare const createLeftAnchorWidget: ({ doc, from, diffId, }: {
32
40
  * layout, expand) so the bar aligns within the container boundary.
33
41
  *
34
42
  */
35
- export declare const createBlockIndicatorAnchorWidgets: ({ doc, from, to, diffId, }: {
43
+ export declare const createBlockIndicatorAnchorWidgets: ({ doc, from, to, diffId, leftAnchorId, }: {
36
44
  diffId: string;
37
45
  doc: PMNode;
38
46
  from: number;
47
+ leftAnchorId?: string;
39
48
  to: number;
40
49
  }) => Decoration[];
41
50
  /**
@@ -56,9 +65,10 @@ export declare const createAnchorNameSpan: (anchorKey: string) => HTMLSpanElemen
56
65
  * Invisible `from`/`to` (and optional `left`) anchor widgets for one inline diff
57
66
  * range, so the `IndicatorBar` can align itself via CSS anchor positioning.
58
67
  */
59
- export declare const createInlineIndicatorAnchorWidgets: ({ doc, from, to, diffId, }: {
68
+ export declare const createInlineIndicatorAnchorWidgets: ({ doc, from, to, diffId, leftAnchorId, }: {
60
69
  diffId: string;
61
70
  doc: PMNode;
62
71
  from: number;
72
+ leftAnchorId?: string;
63
73
  to: number;
64
74
  }) => Decoration[];
@@ -11,7 +11,7 @@ import { type ContributorTagMountContext } from './createContributorTagWidget';
11
11
  * @param isActive Whether this node is part of the currently active/focused change
12
12
  * @returns Prosemirror node decoration or undefined
13
13
  */
14
- export declare const createBlockChangedDecoration: ({ attributionKey, change, colorScheme, isInserted, isActive, shouldHideDeleted, showContributorTags, showIndicators, doc, diffType, tagMountContext, }: {
14
+ export declare const createBlockChangedDecoration: ({ attributionKey, change, colorScheme, isInserted, isActive, leftAnchorId, shouldHideDeleted, showContributorTags, showIndicators, doc, diffType, tagMountContext, }: {
15
15
  attributionKey?: string;
16
16
  change: {
17
17
  from: number;
@@ -23,6 +23,7 @@ export declare const createBlockChangedDecoration: ({ attributionKey, change, co
23
23
  doc?: PMNode;
24
24
  isActive?: boolean;
25
25
  isInserted?: boolean;
26
+ leftAnchorId?: string;
26
27
  shouldHideDeleted?: boolean;
27
28
  showContributorTags?: boolean;
28
29
  showIndicators?: boolean;
@@ -10,7 +10,7 @@ type SimpleChange = Pick<Change, 'fromA' | 'toA' | 'fromB' | 'deleted'>;
10
10
  /**
11
11
  * Main function to handle deleted rows - computes diff and creates decorations
12
12
  */
13
- export declare const createChangedRowDecorationWidgets: ({ attributionKey, changes, originalDoc, newDoc, nodeViewSerializer, colorScheme, isActive, isInserted, diffType, intl, showIndicators, showContributorTags, tagMountContext, }: {
13
+ export declare const createChangedRowDecorationWidgets: ({ attributionKey, changes, originalDoc, newDoc, nodeViewSerializer, colorScheme, isActive, isInserted, leftAnchorId, diffType, intl, showIndicators, showContributorTags, tagMountContext, }: {
14
14
  attributionKey?: string;
15
15
  changes: SimpleChange[];
16
16
  colorScheme?: ColorScheme;
@@ -18,6 +18,7 @@ export declare const createChangedRowDecorationWidgets: ({ attributionKey, chang
18
18
  intl?: IntlShape;
19
19
  isActive?: boolean;
20
20
  isInserted?: boolean;
21
+ leftAnchorId?: string;
21
22
  newDoc: PMNode;
22
23
  nodeViewSerializer: NodeViewSerializer;
23
24
  originalDoc: PMNode;
@@ -14,7 +14,7 @@ export declare const getAtomicInlineChangedAttrs: (inlineNodeName: InlineAttrCha
14
14
  * @param change Changeset "change" containing information about the change content + range
15
15
  * @returns Prosemirror inline decoration
16
16
  */
17
- export declare const createInlineChangedDecoration: ({ attributionKey, change, colorScheme, isActive, isInserted, isAtomicInlineNode, shouldHideDeleted, showContributorTags, showIndicators, doc, diffType, hideAddedDiffsUnderline, inlineNodeName, hasDeletedWidget, isDeletedWidgetBelow, reveal, tagMountContext, }: {
17
+ export declare const createInlineChangedDecoration: ({ attributionKey, change, colorScheme, isActive, isInserted, leftAnchorId, isAtomicInlineNode, shouldHideDeleted, showContributorTags, showIndicators, doc, diffType, hideAddedDiffsUnderline, inlineNodeName, hasDeletedWidget, isDeletedWidgetBelow, reveal, tagMountContext, }: {
18
18
  attributionKey?: string;
19
19
  change: {
20
20
  fromB: number;
@@ -30,6 +30,7 @@ export declare const createInlineChangedDecoration: ({ attributionKey, change, c
30
30
  isAtomicInlineNode?: boolean;
31
31
  isDeletedWidgetBelow?: boolean;
32
32
  isInserted?: boolean;
33
+ leftAnchorId?: string;
33
34
  reveal?: RevealOptions;
34
35
  shouldHideDeleted?: boolean;
35
36
  showContributorTags?: boolean;
@@ -10,7 +10,7 @@ import { type ContributorTagMountContext } from './createContributorTagWidget';
10
10
  * This function is used to create a decoration widget to show content
11
11
  * that is not in the current document.
12
12
  */
13
- export declare const createNodeChangedDecorationWidget: ({ attributionKey, change, doc, nodeViewSerializer, colorScheme, newDoc, intl, activeIndexPos, isInserted, showContributorTags, showIndicators, placeBelow, diffType, hideAddedDiffsUnderline, reveal, tagMountContext, deletedColumns, }: {
13
+ export declare const createNodeChangedDecorationWidget: ({ attributionKey, change, doc, nodeViewSerializer, colorScheme, newDoc, intl, activeIndexPos, isInserted, leftAnchorId, showContributorTags, showIndicators, placeBelow, diffType, hideAddedDiffsUnderline, reveal, tagMountContext, deletedColumns, }: {
14
14
  activeIndexPos?: {
15
15
  from: number;
16
16
  to: number;
@@ -24,6 +24,7 @@ export declare const createNodeChangedDecorationWidget: ({ attributionKey, chang
24
24
  hideAddedDiffsUnderline?: boolean;
25
25
  intl: IntlShape;
26
26
  isInserted?: boolean;
27
+ leftAnchorId?: string;
27
28
  newDoc: PMNode;
28
29
  nodeViewSerializer: NodeViewSerializer;
29
30
  placeBelow?: boolean;