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

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 (40) hide show
  1. package/CHANGELOG.md +24 -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 +6 -2
  5. package/dist/cjs/pm-plugins/decorations/createChangedRowDecorationWidgets.js +5 -2
  6. package/dist/cjs/pm-plugins/decorations/createContributorTagWidget.js +54 -15
  7. package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +6 -2
  8. package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +64 -13
  9. package/dist/cjs/pm-plugins/decorations/decorationKeys.js +8 -3
  10. package/dist/cjs/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +8 -3
  11. package/dist/cjs/ui/IndicatorBar/IndicatorBarContentComponent.js +5 -3
  12. package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +12 -1
  13. package/dist/es2019/pm-plugins/decorations/createAnchorDecorationWidgets.js +131 -12
  14. package/dist/es2019/pm-plugins/decorations/createBlockChangedDecoration.js +6 -2
  15. package/dist/es2019/pm-plugins/decorations/createChangedRowDecorationWidgets.js +5 -2
  16. package/dist/es2019/pm-plugins/decorations/createContributorTagWidget.js +54 -15
  17. package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +6 -2
  18. package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +66 -16
  19. package/dist/es2019/pm-plugins/decorations/decorationKeys.js +7 -0
  20. package/dist/es2019/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +8 -3
  21. package/dist/es2019/ui/IndicatorBar/IndicatorBarContentComponent.js +5 -3
  22. package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +12 -1
  23. package/dist/esm/pm-plugins/decorations/createAnchorDecorationWidgets.js +165 -32
  24. package/dist/esm/pm-plugins/decorations/createBlockChangedDecoration.js +6 -2
  25. package/dist/esm/pm-plugins/decorations/createChangedRowDecorationWidgets.js +5 -2
  26. package/dist/esm/pm-plugins/decorations/createContributorTagWidget.js +54 -15
  27. package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +6 -2
  28. package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +67 -16
  29. package/dist/esm/pm-plugins/decorations/decorationKeys.js +8 -3
  30. package/dist/esm/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +8 -3
  31. package/dist/esm/ui/IndicatorBar/IndicatorBarContentComponent.js +5 -3
  32. package/dist/types/pm-plugins/decorations/createAnchorDecorationWidgets.d.ts +14 -4
  33. package/dist/types/pm-plugins/decorations/createBlockChangedDecoration.d.ts +2 -1
  34. package/dist/types/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +2 -1
  35. package/dist/types/pm-plugins/decorations/createContributorTagWidget.d.ts +24 -6
  36. package/dist/types/pm-plugins/decorations/createInlineChangedDecoration.d.ts +2 -1
  37. package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +2 -1
  38. package/dist/types/pm-plugins/decorations/decorationKeys.d.ts +3 -1
  39. package/dist/types/showDiffPluginType.d.ts +1 -0
  40. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @atlaskit/editor-plugin-show-diff
2
2
 
3
+ ## 17.1.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [`597f7ce38c071`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/597f7ce38c071) -
8
+ Fix contributor tags rendering clipped inside code blocks, and off-position for other
9
+ deleted-content widgets, in version history diffs.
10
+
11
+ Anchor the contributor tag to the code block's own box when an edit inside the block hoists the
12
+ tag out of it, instead of an approximate host-relative offset, so the tag no longer renders
13
+ clipped by the code content wrapper.
14
+
15
+ Fix deleted headings, lists, and blockquotes missing their background highlight and underline on
16
+ the active change, behind `confluence_ncs_step_diffing_version_history`.
17
+
18
+ ## 17.1.6
19
+
20
+ ### Patch Changes
21
+
22
+ - [`188a9259b143b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/188a9259b143b) -
23
+ EDITOR-9127 [ux] Align the diff indicator outside the visible outer edges of a whole inserted
24
+ layout.
25
+ - Updated dependencies
26
+
3
27
  ## 17.1.5
4
28
 
5
29
  ### Patch Changes
@@ -192,6 +192,7 @@ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration
192
192
  colorScheme = _ref5.colorScheme,
193
193
  _ref5$isInserted = _ref5.isInserted,
194
194
  isInserted = _ref5$isInserted === void 0 ? true : _ref5$isInserted,
195
+ leftAnchorId = _ref5.leftAnchorId,
195
196
  activeIndexPos = _ref5.activeIndexPos,
196
197
  _ref5$shouldHideDelet = _ref5.shouldHideDeleted,
197
198
  shouldHideDeleted = _ref5$shouldHideDelet === void 0 ? false : _ref5$shouldHideDelet,
@@ -230,6 +231,7 @@ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration
230
231
  },
231
232
  colorScheme: colorScheme,
232
233
  isInserted: isInserted,
234
+ leftAnchorId: leftAnchorId,
233
235
  isActive: isActive,
234
236
  shouldHideDeleted: shouldHideDeleted,
235
237
  showContributorTags: showContributorTags,
@@ -271,6 +273,7 @@ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration
271
273
  },
272
274
  colorScheme: colorScheme,
273
275
  isInserted: isInserted,
276
+ leftAnchorId: leftAnchorId,
274
277
  isActive: _isActive,
275
278
  shouldHideDeleted: shouldHideDeleted,
276
279
  showContributorTags: showContributorTags,
@@ -553,6 +556,10 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
553
556
  });
554
557
  };
555
558
  var createDecorationsForChange = function createDecorationsForChange(change) {
559
+ // Patch 2 makes all decorations generated for one replacement share this anchor. Their own
560
+ // IDs still identify their top/bottom bounds, while this ID makes their bars agree on one
561
+ // left edge. When the gate is off, factories retain their existing per-decoration anchors.
562
+ var leftAnchorId = (0, _fg.fg)('platform_editor_ai_show_diff_patch_2') ? "replacement-".concat(change.fromA, "-").concat(change.toA, "-").concat(change.fromB, "-").concat(change.toB) : undefined;
556
563
  var changeColorScheme = attributionColors ? (0, _attributions.getColorSchemeForChange)(change, attributedChanges, attributionColors, colorScheme) : colorScheme;
557
564
  var attributionKey = showContributorTags ? (0, _attributions.getAttributionKeyForChange)(change, attributedChanges) : undefined;
558
565
  var isActive = isRangeActive(activeIndexPos, change.fromB, change.toB);
@@ -685,6 +692,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
685
692
  fromB: from,
686
693
  toB: to
687
694
  },
695
+ leftAnchorId: leftAnchorId,
688
696
  doc: tr.doc,
689
697
  colorScheme: changeColorScheme,
690
698
  isActive: isActive,
@@ -710,6 +718,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
710
718
  decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createInlineChangedDecoration.createInlineChangedDecoration)(_objectSpread({
711
719
  attributionKey: attributionKey,
712
720
  change: change,
721
+ leftAnchorId: leftAnchorId,
713
722
  doc: tr.doc,
714
723
  colorScheme: changeColorScheme,
715
724
  isActive: isActive,
@@ -744,7 +753,8 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
744
753
  activeIndexPos: activeIndexPos,
745
754
  intl: intl,
746
755
  diffType: diffType,
747
- coarseTableCellsOnly: useCoarseTableDecoration
756
+ coarseTableCellsOnly: useCoarseTableDecoration,
757
+ leftAnchorId: leftAnchorId
748
758
  }))));
749
759
  }
750
760
  if (change.deleted.length > 0 && !isMarkOnly && !hasNoDeletedContent) {
@@ -769,6 +779,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
769
779
  newDoc: tr.doc,
770
780
  intl: intl,
771
781
  activeIndexPos: activeIndexPos,
782
+ leftAnchorId: leftAnchorId,
772
783
  showContributorTags: showContributorTags,
773
784
  tagMountContext: tagMountContext
774
785
  }, (0, _isExtendedEnabled.isExtendedEnabled)(diffType) && {
@@ -5,11 +5,15 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.createLeftAnchorWidget = exports.createInlineIndicatorAnchorWidgets = exports.createDocMarginAnchorWidget = exports.createBlockIndicatorAnchorWidgets = exports.createAnchorNameSpan = exports.clampAnchorPosIntoCell = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
8
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
10
  var _utils = require("@atlaskit/editor-prosemirror/utils");
10
11
  var _view = require("@atlaskit/editor-prosemirror/view");
11
12
  var _fg = require("@atlaskit/platform-feature-flags/fg");
12
13
  var _decorationKeys = require("./decorationKeys");
14
+ 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; } } }; }
15
+ 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; } }
16
+ 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; }
13
17
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
18
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
19
  /**
@@ -36,21 +40,21 @@ var resolveDocLevelNode = function resolveDocLevelNode(doc, from) {
36
40
  beforePos: nodeStart - 1
37
41
  };
38
42
  };
39
-
40
43
  /**
41
44
  * Handles edge cases for block nodes whose inline content can exceed the doc
42
45
  * margin (tables, layouts, expands). Returns the position whose DOM should be
43
46
  * measured to size the left anchor, or `undefined` when the diff is not inside
44
47
  * such a node.
45
48
  */
46
- var edgeCases = function edgeCases(doc, from) {
49
+ var edgeCases = function edgeCases(doc, from, nodeOverride) {
47
50
  var resolved = resolveDocLevelNode(doc, from);
48
51
  if (!resolved) {
49
52
  return undefined;
50
53
  }
51
- var node = resolved.node,
54
+ var resolvedNode = resolved.node,
52
55
  nodeStart = resolved.nodeStart,
53
56
  beforePos = resolved.beforePos;
57
+ var node = (0, _fg.fg)('platform_editor_ai_show_diff_patch_2') ? nodeOverride !== null && nodeOverride !== void 0 ? nodeOverride : resolvedNode : resolvedNode;
54
58
  if (node.type.name === 'layoutSection' && (0, _fg.fg)('platform_editor_ai_show_diff_patch_1')) {
55
59
  // Columns extend past the node-view wrapper via negative margins (12px or 20px).
56
60
  // Measure their container so the indicator stays outside the diff outline, including
@@ -118,6 +122,45 @@ var edgeCases = function edgeCases(doc, from) {
118
122
  return undefined;
119
123
  }
120
124
  };
125
+ var getEdgeCasesForSlice = function getEdgeCasesForSlice(doc, from, slice, measureElement) {
126
+ var _targets$find;
127
+ var resolved = resolveDocLevelNode(doc, from);
128
+ if (!resolved) {
129
+ return [];
130
+ }
131
+ var targets = [];
132
+ // edge cases can only be top level nodes, so we only care about the top level nodes in the slice
133
+ slice.content.forEach(function (node, offset) {
134
+ var edgeCase = edgeCases(doc, from + offset, node);
135
+ if (edgeCase) {
136
+ targets.push(_objectSpread(_objectSpread({}, edgeCase), {}, {
137
+ measureElement: measureElement
138
+ }));
139
+ }
140
+ });
141
+ return targets.length > 0 ? [{
142
+ beforePos: resolved.beforePos,
143
+ leftOffset: (_targets$find = targets.find(function (target) {
144
+ return target.leftOffset !== undefined;
145
+ })) === null || _targets$find === void 0 ? void 0 : _targets$find.leftOffset,
146
+ widthMeasureTargets: targets
147
+ }] : [];
148
+ };
149
+
150
+ /**
151
+ * Finds the edge cases in the current document for either a whole range or one position.
152
+ * A missing `to` intentionally means the single-position lookup is the fallback.
153
+ */
154
+ var getEdgeCasesForDocument = function getEdgeCasesForDocument(doc, from, to) {
155
+ if (to !== undefined) {
156
+ var edgeCasesForSlice = getEdgeCasesForSlice(doc, from, doc.slice(from, to));
157
+ if (edgeCasesForSlice.length > 0) {
158
+ return edgeCasesForSlice;
159
+ }
160
+ }
161
+ var edgeCase = edgeCases(doc, from);
162
+ return edgeCase ? [edgeCase] : [];
163
+ };
121
164
 
122
165
  /**
123
166
  * Create a widget that marks the start of the doc margin.
@@ -148,10 +191,23 @@ var createDocMarginAnchorWidget = exports.createDocMarginAnchorWidget = function
148
191
  * anchor positioning. Shared by inline and node (widget) diff decorations.
149
192
  */
150
193
  var createLeftAnchorWidget = exports.createLeftAnchorWidget = function createLeftAnchorWidget(_ref) {
194
+ var _range$from;
151
195
  var doc = _ref.doc,
152
196
  from = _ref.from,
153
- diffId = _ref.diffId;
154
- var edgeCase = edgeCases(doc, from);
197
+ to = _ref.to,
198
+ diffId = _ref.diffId,
199
+ leftAnchorId = _ref.leftAnchorId,
200
+ measureElement = _ref.measureElement,
201
+ sliceOverride = _ref.sliceOverride,
202
+ underlyingRange = _ref.underlyingRange;
203
+ var overrideEdgeCases = sliceOverride ? getEdgeCasesForSlice(doc, from, sliceOverride, measureElement) : [];
204
+ var range = underlyingRange !== null && underlyingRange !== void 0 ? underlyingRange : to !== undefined ? {
205
+ from: from,
206
+ to: to
207
+ } : undefined;
208
+ 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);
209
+ var allEdgeCases = [].concat((0, _toConsumableArray2.default)(overrideEdgeCases), (0, _toConsumableArray2.default)(documentEdgeCases));
210
+ var edgeCase = (0, _fg.fg)('platform_editor_ai_show_diff_patch_2') ? allEdgeCases[0] : edgeCases(doc, from);
155
211
  if (edgeCase === undefined) {
156
212
  return undefined;
157
213
  }
@@ -160,7 +216,7 @@ var createLeftAnchorWidget = exports.createLeftAnchorWidget = function createLef
160
216
  // resizable block container.
161
217
  var beforePos = edgeCase.beforePos;
162
218
  var leftAnchorKey = (0, _decorationKeys.buildAnchorDecorationKey)({
163
- diffId: diffId,
219
+ diffId: leftAnchorId !== null && leftAnchorId !== void 0 ? leftAnchorId : diffId,
164
220
  anchorType: _decorationKeys.AnchorTypeKey.left
165
221
  });
166
222
  var leftResizeObserver;
@@ -178,15 +234,87 @@ var createLeftAnchorWidget = exports.createLeftAnchorWidget = function createLef
178
234
  anchor.style.setProperty('left', "calc(50% - ".concat((edgeCase === null || edgeCase === void 0 ? void 0 : edgeCase.leftOffset) || 0, "px)"));
179
235
  anchor.style.setProperty('transform', 'translateX(-50%)');
180
236
  wrapper.appendChild(anchor);
181
- var measureWidth = function measureWidth() {
237
+ var _measureWidth = function measureWidth() {
182
238
  var _nodeDOM$querySelecto;
239
+ if ((0, _fg.fg)('platform_editor_ai_show_diff_patch_2')) {
240
+ var widthMeasureTargets = allEdgeCases.flatMap(function (target) {
241
+ var _target$widthMeasureT;
242
+ return (_target$widthMeasureT = target.widthMeasureTargets) !== null && _target$widthMeasureT !== void 0 ? _target$widthMeasureT : [target];
243
+ });
244
+ if (getPos() === undefined || widthMeasureTargets.length === 0) {
245
+ return;
246
+ }
247
+ var measuredElements = widthMeasureTargets.flatMap(function (_ref2) {
248
+ var targetMeasureElement = _ref2.measureElement,
249
+ measureLeft = _ref2.measureLeft,
250
+ measurePos = _ref2.measurePos,
251
+ measureSelector = _ref2.measureSelector;
252
+ if (measurePos === undefined) {
253
+ return [];
254
+ }
255
+ var nodeDOM = targetMeasureElement !== null && targetMeasureElement !== void 0 ? targetMeasureElement : view.nodeDOM(measurePos);
256
+ var elements = nodeDOM instanceof HTMLElement ? measureSelector ? Array.from(nodeDOM.querySelectorAll(measureSelector)) : [nodeDOM] : [];
257
+ return elements.map(function (element) {
258
+ return {
259
+ element: element,
260
+ measureLeft: measureLeft
261
+ };
262
+ });
263
+ });
264
+
265
+ // A single diff can include multiple edge-case nodes, so measure the widest one.
266
+ var widest;
267
+ var _iterator = _createForOfIteratorHelper(measuredElements),
268
+ _step;
269
+ try {
270
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
271
+ var target = _step.value;
272
+ if (!widest || target.element.offsetWidth > widest.element.offsetWidth) {
273
+ widest = target;
274
+ }
275
+ }
276
+ } catch (err) {
277
+ _iterator.e(err);
278
+ } finally {
279
+ _iterator.f();
280
+ }
281
+ if (widest) {
282
+ var updateAnchor = function updateAnchor() {
283
+ if (getPos() === undefined) {
284
+ return;
285
+ }
286
+ if (widest.measureLeft) {
287
+ var left = widest.element.getBoundingClientRect().left - wrapper.getBoundingClientRect().left;
288
+ anchor.style.setProperty('left', "".concat(left, "px"));
289
+ anchor.style.setProperty('transform', 'none');
290
+ }
291
+ anchor.style.setProperty('width', "".concat(widest.element.offsetWidth, "px"));
292
+ };
293
+ updateAnchor();
294
+
295
+ // Observe the measured elements for size changes (e.g. page
296
+ // resize) so the indicator stays aligned.
297
+ if (!leftResizeObserver) {
298
+ leftResizeObserver = new ResizeObserver(_measureWidth);
299
+ measuredElements.forEach(function (_ref3) {
300
+ var _leftResizeObserver;
301
+ var element = _ref3.element;
302
+ return (_leftResizeObserver = leftResizeObserver) === null || _leftResizeObserver === void 0 ? void 0 : _leftResizeObserver.observe(element);
303
+ });
304
+ if (widest.measureLeft) {
305
+ leftResizeObserver.observe(wrapper);
306
+ }
307
+ }
308
+ }
309
+ return;
310
+ }
183
311
  if (getPos() === undefined || edgeCase.measurePos === undefined) {
184
312
  return;
185
313
  }
186
314
  var nodeDOM = view.nodeDOM(edgeCase.measurePos);
187
315
  var dom = edgeCase.measureSelector && nodeDOM instanceof HTMLElement ? (_nodeDOM$querySelecto = nodeDOM.querySelector(edgeCase.measureSelector)) !== null && _nodeDOM$querySelecto !== void 0 ? _nodeDOM$querySelecto : nodeDOM : nodeDOM;
188
316
  if (dom instanceof HTMLElement) {
189
- var updateAnchor = function updateAnchor() {
317
+ var _updateAnchor = function _updateAnchor() {
190
318
  if (getPos() === undefined) {
191
319
  return;
192
320
  }
@@ -198,12 +326,12 @@ var createLeftAnchorWidget = exports.createLeftAnchorWidget = function createLef
198
326
  anchor.style.setProperty('width', "".concat(dom.offsetWidth, "px"));
199
327
  };
200
328
  // Align against the block's horizontal extent.
201
- updateAnchor();
329
+ _updateAnchor();
202
330
 
203
331
  // Observe the measured element for size changes (e.g. page
204
332
  // resize) so the indicator stays aligned. CCI-17981
205
333
  if (!leftResizeObserver) {
206
- leftResizeObserver = new ResizeObserver(updateAnchor);
334
+ leftResizeObserver = new ResizeObserver(_updateAnchor);
207
335
  leftResizeObserver.observe(dom);
208
336
  if (edgeCase.measureLeft) {
209
337
  leftResizeObserver.observe(wrapper);
@@ -214,7 +342,7 @@ var createLeftAnchorWidget = exports.createLeftAnchorWidget = function createLef
214
342
 
215
343
  // The block DOM may not be settled synchronously (e.g. after a
216
344
  // transaction), so defer the measurement like the gap cursor does.
217
- requestAnimationFrame(measureWidth);
345
+ requestAnimationFrame(_measureWidth);
218
346
  return wrapper;
219
347
  }, _objectSpread(_objectSpread({}, (0, _decorationKeys.buildAnchorDecorationSpec)({
220
348
  diffId: diffId,
@@ -222,8 +350,8 @@ var createLeftAnchorWidget = exports.createLeftAnchorWidget = function createLef
222
350
  side: -999
223
351
  })), {}, {
224
352
  destroy: function destroy() {
225
- var _leftResizeObserver;
226
- return (_leftResizeObserver = leftResizeObserver) === null || _leftResizeObserver === void 0 ? void 0 : _leftResizeObserver.disconnect();
353
+ var _leftResizeObserver2;
354
+ return (_leftResizeObserver2 = leftResizeObserver) === null || _leftResizeObserver2 === void 0 ? void 0 : _leftResizeObserver2.disconnect();
227
355
  }
228
356
  }));
229
357
  };
@@ -239,16 +367,18 @@ var createLeftAnchorWidget = exports.createLeftAnchorWidget = function createLef
239
367
  * layout, expand) so the bar aligns within the container boundary.
240
368
  *
241
369
  */
242
- var createBlockIndicatorAnchorWidgets = exports.createBlockIndicatorAnchorWidgets = function createBlockIndicatorAnchorWidgets(_ref2) {
243
- var _ref3, _parentTable$pos;
244
- var doc = _ref2.doc,
245
- from = _ref2.from,
246
- to = _ref2.to,
247
- diffId = _ref2.diffId;
370
+ var createBlockIndicatorAnchorWidgets = exports.createBlockIndicatorAnchorWidgets = function createBlockIndicatorAnchorWidgets(_ref4) {
371
+ var _ref5, _parentTable$pos;
372
+ var doc = _ref4.doc,
373
+ from = _ref4.from,
374
+ to = _ref4.to,
375
+ diffId = _ref4.diffId,
376
+ leftAnchorId = _ref4.leftAnchorId;
248
377
  var leftAnchor = createLeftAnchorWidget({
249
378
  doc: doc,
250
379
  from: from,
251
- diffId: diffId
380
+ diffId: diffId,
381
+ leftAnchorId: leftAnchorId
252
382
  });
253
383
  var maybeLeftAnchor = leftAnchor ? [leftAnchor] : [];
254
384
 
@@ -287,7 +417,7 @@ var createBlockIndicatorAnchorWidgets = exports.createBlockIndicatorAnchorWidget
287
417
  // bounding box or positioning context, so measuring its top produces an offset from the
288
418
  // viewport origin and displaces the indicator into content below the editor. Keep the
289
419
  // wrapper outside the layout, just as we do for tables, but still measure the target node.
290
- 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;
420
+ 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;
291
421
  // Measure the actual cell/row DOM when inside one; otherwise measure the
292
422
  // widget's own position.
293
423
  var measurePos = parentCellOrRow ? parentCellOrRow.pos : from;
@@ -386,11 +516,11 @@ var createAnchorNameSpan = exports.createAnchorNameSpan = function createAnchorN
386
516
  span.style.setProperty('anchor-name', "--".concat(anchorKey));
387
517
  return span;
388
518
  };
389
- var createAnchorSpanWidget = function createAnchorSpanWidget(_ref4) {
390
- var pos = _ref4.pos,
391
- diffId = _ref4.diffId,
392
- anchorType = _ref4.anchorType,
393
- side = _ref4.side;
519
+ var createAnchorSpanWidget = function createAnchorSpanWidget(_ref6) {
520
+ var pos = _ref6.pos,
521
+ diffId = _ref6.diffId,
522
+ anchorType = _ref6.anchorType,
523
+ side = _ref6.side;
394
524
  return _view.Decoration.widget(pos, function () {
395
525
  return createAnchorNameSpan((0, _decorationKeys.buildAnchorDecorationKey)({
396
526
  diffId: diffId,
@@ -407,15 +537,18 @@ var createAnchorSpanWidget = function createAnchorSpanWidget(_ref4) {
407
537
  * Invisible `from`/`to` (and optional `left`) anchor widgets for one inline diff
408
538
  * range, so the `IndicatorBar` can align itself via CSS anchor positioning.
409
539
  */
410
- var createInlineIndicatorAnchorWidgets = exports.createInlineIndicatorAnchorWidgets = function createInlineIndicatorAnchorWidgets(_ref5) {
411
- var doc = _ref5.doc,
412
- from = _ref5.from,
413
- to = _ref5.to,
414
- diffId = _ref5.diffId;
540
+ var createInlineIndicatorAnchorWidgets = exports.createInlineIndicatorAnchorWidgets = function createInlineIndicatorAnchorWidgets(_ref7) {
541
+ var doc = _ref7.doc,
542
+ from = _ref7.from,
543
+ to = _ref7.to,
544
+ diffId = _ref7.diffId,
545
+ leftAnchorId = _ref7.leftAnchorId;
415
546
  var leftAnchor = createLeftAnchorWidget({
416
547
  doc: doc,
417
548
  from: from,
418
- diffId: diffId
549
+ to: (0, _fg.fg)('platform_editor_ai_show_diff_patch_2') ? to : undefined,
550
+ diffId: diffId,
551
+ leftAnchorId: leftAnchorId
419
552
  });
420
553
  var maybeLeftAnchor = leftAnchor ? [leftAnchor] : [];
421
554
 
@@ -184,6 +184,7 @@ var createBlockChangedDecoration = exports.createBlockChangedDecoration = functi
184
184
  isInserted = _ref3$isInserted === void 0 ? true : _ref3$isInserted,
185
185
  _ref3$isActive = _ref3.isActive,
186
186
  isActive = _ref3$isActive === void 0 ? false : _ref3$isActive,
187
+ leftAnchorId = _ref3.leftAnchorId,
187
188
  _ref3$shouldHideDelet = _ref3.shouldHideDeleted,
188
189
  shouldHideDeleted = _ref3$shouldHideDelet === void 0 ? false : _ref3$shouldHideDelet,
189
190
  _ref3$showContributor = _ref3.showContributorTags,
@@ -214,6 +215,7 @@ var createBlockChangedDecoration = exports.createBlockChangedDecoration = functi
214
215
  colorScheme: colorScheme,
215
216
  decorationType: 'block',
216
217
  diffId: diffId,
218
+ leftAnchorId: leftAnchorId,
217
219
  isActive: isActive,
218
220
  isInserted: isInserted,
219
221
  nodeName: change.name,
@@ -270,6 +272,7 @@ var createBlockChangedDecoration = exports.createBlockChangedDecoration = functi
270
272
  colorScheme: colorScheme,
271
273
  decorationType: 'block',
272
274
  diffId: diffId,
275
+ leftAnchorId: leftAnchorId,
273
276
  isActive: isActive,
274
277
  isInserted: isInserted,
275
278
  nodeName: change.name,
@@ -286,7 +289,8 @@ var createBlockChangedDecoration = exports.createBlockChangedDecoration = functi
286
289
  doc: doc,
287
290
  from: change.from,
288
291
  to: change.to,
289
- diffId: diffId
292
+ diffId: diffId,
293
+ leftAnchorId: leftAnchorId
290
294
  })));
291
295
  }
292
296
 
@@ -304,7 +308,7 @@ var createBlockChangedDecoration = exports.createBlockChangedDecoration = functi
304
308
  mountContext: tagMountContext
305
309
  });
306
310
  if (tagWidget) {
307
- decorations.push(tagWidget);
311
+ decorations.push.apply(decorations, (0, _toConsumableArray2.default)(tagWidget));
308
312
  }
309
313
  }
310
314
  return decorations;
@@ -312,6 +312,7 @@ var createChangedRowDecorationWidgets = exports.createChangedRowDecorationWidget
312
312
  isActive = _ref6.isActive,
313
313
  _ref6$isInserted = _ref6.isInserted,
314
314
  isInserted = _ref6$isInserted === void 0 ? false : _ref6$isInserted,
315
+ leftAnchorId = _ref6.leftAnchorId,
315
316
  diffType = _ref6.diffType,
316
317
  intl = _ref6.intl,
317
318
  _ref6$showIndicators = _ref6.showIndicators,
@@ -366,7 +367,8 @@ var createChangedRowDecorationWidgets = exports.createChangedRowDecorationWidget
366
367
  var leftAnchor = (0, _createAnchorDecorationWidgets.createLeftAnchorWidget)({
367
368
  doc: newDoc,
368
369
  from: safeInsertPos,
369
- diffId: diffId
370
+ diffId: diffId,
371
+ leftAnchorId: leftAnchorId
370
372
  });
371
373
  if (leftAnchor) {
372
374
  decorations.push(leftAnchor);
@@ -408,6 +410,7 @@ var createChangedRowDecorationWidgets = exports.createChangedRowDecorationWidget
408
410
  colorScheme: colorScheme,
409
411
  decorationType: 'widget',
410
412
  diffId: diffId,
413
+ leftAnchorId: leftAnchorId,
411
414
  isActive: isActive,
412
415
  isInserted: isInserted,
413
416
  diffType: diffType
@@ -423,7 +426,7 @@ var createChangedRowDecorationWidgets = exports.createChangedRowDecorationWidget
423
426
  }));
424
427
  }
425
428
  if (tagWidget) {
426
- decorations.push(tagWidget);
429
+ decorations.push.apply(decorations, (0, _toConsumableArray2.default)(tagWidget));
427
430
  }
428
431
  return decorations;
429
432
  });
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.unmountContributorTag = exports.mountContributorTag = exports.isContributorTagWidgetEnabled = exports.createContributorTagWidget = exports.createContributorTagHost = exports.CONTRIBUTOR_TAG_HOST_ATTRIBUTE = void 0;
7
+ exports.unmountContributorTag = exports.resolveHoistedCodeBlockAnchor = exports.resolveCodeBlockStart = exports.mountContributorTag = exports.isContributorTagWidgetEnabled = exports.createContributorTagWidget = exports.createContributorTagHost = exports.CONTRIBUTOR_TAG_HOST_ATTRIBUTE = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _view = require("@atlaskit/editor-prosemirror/view");
10
10
  var _fg = require("@atlaskit/platform-feature-flags/fg");
@@ -174,13 +174,12 @@ var resolveTagAnchorPos = function resolveTagAnchorPos(doc, from, to) {
174
174
  };
175
175
 
176
176
  /**
177
- * The position just before the code block enclosing `pos`, or `undefined` when nothing does.
177
+ * Position just before the code block enclosing `pos`, or `undefined` if there is none.
178
178
  *
179
- * `.code-block-content-wrapper` hides its block-axis overflow, so a host left inside the code has
180
- * its tag clipped away. Hosting it before the block puts the tag on the block's top-left corner,
181
- * where a whole-code-block change is tagged too (EDITOR-8766).
179
+ * Code blocks clip/scroll their own content, so a tag hosted inside one gets clipped away. Hoisting
180
+ * it before the block avoids that (EDITOR-9045, EDITOR-8766).
182
181
  */
183
- var resolveCodeBlockStart = function resolveCodeBlockStart(doc, pos) {
182
+ var resolveCodeBlockStart = exports.resolveCodeBlockStart = function resolveCodeBlockStart(doc, pos) {
184
183
  var $pos = doc.resolve(pos);
185
184
  for (var depth = $pos.depth; depth > 0; depth--) {
186
185
  if ($pos.node(depth).type.name === 'codeBlock') {
@@ -191,14 +190,47 @@ var resolveCodeBlockStart = function resolveCodeBlockStart(doc, pos) {
191
190
  };
192
191
 
193
192
  /**
194
- * A widget hosting the contributor tag of one diff range, placed on the first visible character the
195
- * range highlights or, with `anchorAtRangeStart`, at `from` itself. Either way a host that would
196
- * land inside a code block is hoisted out in front of it; see `resolveCodeBlockStart`.
193
+ * If `pos` is inside a code block: a marker decoration to anchor the hoisted tag against, plus the
194
+ * position just before the block to host that tag at (EDITOR-9045).
195
+ */
196
+ var resolveHoistedCodeBlockAnchor = exports.resolveHoistedCodeBlockAnchor = function resolveHoistedCodeBlockAnchor(doc, pos, diffId) {
197
+ var codeBlockStart = resolveCodeBlockStart(doc, pos);
198
+ if (codeBlockStart === undefined) {
199
+ return undefined;
200
+ }
201
+ var anchorName = (0, _decorationKeys.buildAnchorDecorationKey)({
202
+ diffId: diffId,
203
+ anchorType: _decorationKeys.AnchorTypeKey.tag
204
+ });
205
+ var marker = _view.Decoration.widget(pos, function () {
206
+ var el = document.createElement('span');
207
+ el.style.setProperty('anchor-name', "--".concat(anchorName));
208
+ return el;
209
+ }, {
210
+ key: "contributor-tag-anchor-".concat(diffId),
211
+ side: -1,
212
+ marks: [],
213
+ ignoreSelection: true
214
+ });
215
+ return {
216
+ anchorName: anchorName,
217
+ codeBlockStart: codeBlockStart,
218
+ marker: marker
219
+ };
220
+ };
221
+
222
+ /**
223
+ * The contributor tag widget for one diff range, placed on the first visible character the range
224
+ * highlights — or, with `anchorAtRangeStart`, at `from` itself. A host inside a code block is
225
+ * hoisted in front of it instead, anchored via `resolveHoistedCodeBlockAnchor` (EDITOR-9045).
226
+ *
227
+ * Returns one decoration normally, two (marker + tag) when hoisted out of a code block.
197
228
  *
198
229
  * The tag is mounted in `toDOM` and taken down in `destroy`, so it lives exactly as long as the host
199
230
  * element ProseMirror drew it into — see `mountContributorTag`.
200
231
  */
201
232
  var createContributorTagWidget = exports.createContributorTagWidget = function createContributorTagWidget(_ref4) {
233
+ var _hoisted$anchorName, _hoisted$codeBlockSta;
202
234
  var _ref4$anchorAtRangeSt = _ref4.anchorAtRangeStart,
203
235
  anchorAtRangeStart = _ref4$anchorAtRangeSt === void 0 ? false : _ref4$anchorAtRangeSt,
204
236
  anchorName = _ref4.anchorName,
@@ -210,17 +242,23 @@ var createContributorTagWidget = exports.createContributorTagWidget = function c
210
242
  if (!isContributorTagWidgetEnabled()) {
211
243
  return undefined;
212
244
  }
213
- var tagAnchorName = anchorName && supportsAnchorPositioning() ? anchorName : undefined;
214
245
 
215
246
  // Reassigned when ProseMirror redraws this decoration, which it may do more than once for the
216
247
  // same `Decoration` instance.
217
248
  var mount;
218
249
  var anchorPos = anchorAtRangeStart ? from : resolveTagAnchorPos(doc, from, to);
219
- // A change inside a code block is hoisted out of it; anything else keeps its own anchor.
220
- var codeBlockPos = resolveCodeBlockStart(doc, anchorPos);
221
- return _view.Decoration.widget(
250
+ // A change inside a code block is hoisted out of it, anchored to its own marker; anything else
251
+ // keeps its own anchor.
252
+ var hoisted = resolveHoistedCodeBlockAnchor(doc, anchorPos, diffId);
253
+ var effectiveAnchorName = (_hoisted$anchorName = hoisted === null || hoisted === void 0 ? void 0 : hoisted.anchorName) !== null && _hoisted$anchorName !== void 0 ? _hoisted$anchorName : anchorName;
254
+ var tagAnchorName = effectiveAnchorName && supportsAnchorPositioning() ? effectiveAnchorName : undefined;
255
+ var decorations = [];
256
+ if (hoisted) {
257
+ decorations.push(hoisted.marker);
258
+ }
259
+ decorations.push(_view.Decoration.widget(
222
260
  // Keep the host out of the table row's grid (EDITOR-8442).
223
- (0, _createAnchorDecorationWidgets.clampAnchorPosIntoCell)(doc, codeBlockPos !== null && codeBlockPos !== void 0 ? codeBlockPos : anchorPos, 1), function () {
261
+ (0, _createAnchorDecorationWidgets.clampAnchorPosIntoCell)(doc, (_hoisted$codeBlockSta = hoisted === null || hoisted === void 0 ? void 0 : hoisted.codeBlockStart) !== null && _hoisted$codeBlockSta !== void 0 ? _hoisted$codeBlockSta : anchorPos, 1), function () {
224
262
  var host = buildContributorTagHost(diffId, tagAnchorName);
225
263
  mount = mountContributorTag({
226
264
  anchorName: tagAnchorName,
@@ -242,5 +280,6 @@ var createContributorTagWidget = exports.createContributorTagWidget = function c
242
280
  unmountContributorTag(mount);
243
281
  mount = undefined;
244
282
  }
245
- }));
283
+ })));
284
+ return decorations;
246
285
  };
@@ -146,6 +146,7 @@ var createInlineChangedDecoration = exports.createInlineChangedDecoration = func
146
146
  isActive = _ref2$isActive === void 0 ? false : _ref2$isActive,
147
147
  _ref2$isInserted = _ref2.isInserted,
148
148
  isInserted = _ref2$isInserted === void 0 ? true : _ref2$isInserted,
149
+ leftAnchorId = _ref2.leftAnchorId,
149
150
  _ref2$isAtomicInlineN = _ref2.isAtomicInlineNode,
150
151
  isAtomicInlineNode = _ref2$isAtomicInlineN === void 0 ? false : _ref2$isAtomicInlineN,
151
152
  _ref2$shouldHideDelet = _ref2.shouldHideDeleted,
@@ -182,6 +183,7 @@ var createInlineChangedDecoration = exports.createInlineChangedDecoration = func
182
183
  colorScheme: colorScheme,
183
184
  decorationType: 'inline',
184
185
  diffId: diffId,
186
+ leftAnchorId: leftAnchorId,
185
187
  isActive: isActive,
186
188
  isInserted: isInserted
187
189
  }))];
@@ -245,6 +247,7 @@ var createInlineChangedDecoration = exports.createInlineChangedDecoration = func
245
247
  colorScheme: colorScheme,
246
248
  decorationType: 'inline',
247
249
  diffId: diffId,
250
+ leftAnchorId: leftAnchorId,
248
251
  isActive: isActive,
249
252
  isInserted: isInserted
250
253
  }))];
@@ -280,14 +283,15 @@ var createInlineChangedDecoration = exports.createInlineChangedDecoration = func
280
283
  doc: doc,
281
284
  from: anchorFrom,
282
285
  to: anchorTo,
283
- diffId: diffId
286
+ diffId: diffId,
287
+ leftAnchorId: leftAnchorId
284
288
  })));
285
289
  }
286
290
 
287
291
  // Pushed after the indicator anchors so the decoration order is unchanged — see `tagWidget` above
288
292
  // for why it is built before them.
289
293
  if (tagWidget) {
290
- decorations.push(tagWidget);
294
+ decorations.push.apply(decorations, (0, _toConsumableArray2.default)(tagWidget));
291
295
  }
292
296
  return decorations;
293
297
  };