@atlaskit/editor-plugin-show-diff 20.0.11 → 21.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/pm-plugins/NodeViewSerializer.js +71 -7
  3. package/dist/cjs/pm-plugins/createEditorProxy.js +84 -0
  4. package/dist/cjs/pm-plugins/decorations/createContributorTagWidget.js +25 -6
  5. package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +35 -11
  6. package/dist/cjs/pm-plugins/decorations/utils/wrapBlockNodeView.js +38 -2
  7. package/dist/cjs/pm-plugins/markViews.js +65 -0
  8. package/dist/es2019/pm-plugins/NodeViewSerializer.js +64 -8
  9. package/dist/es2019/pm-plugins/createEditorProxy.js +76 -0
  10. package/dist/es2019/pm-plugins/decorations/createContributorTagWidget.js +26 -8
  11. package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +35 -12
  12. package/dist/es2019/pm-plugins/decorations/utils/wrapBlockNodeView.js +36 -2
  13. package/dist/es2019/pm-plugins/markViews.js +61 -0
  14. package/dist/esm/pm-plugins/NodeViewSerializer.js +71 -7
  15. package/dist/esm/pm-plugins/createEditorProxy.js +78 -0
  16. package/dist/esm/pm-plugins/decorations/createContributorTagWidget.js +27 -8
  17. package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +37 -12
  18. package/dist/esm/pm-plugins/decorations/utils/wrapBlockNodeView.js +38 -2
  19. package/dist/esm/pm-plugins/markViews.js +60 -0
  20. package/dist/types/pm-plugins/NodeViewSerializer.d.ts +7 -2
  21. package/dist/types/pm-plugins/createEditorProxy.d.ts +18 -0
  22. package/dist/types/pm-plugins/decorations/createContributorTagWidget.d.ts +2 -1
  23. package/dist/types/pm-plugins/markViews.d.ts +14 -0
  24. package/package.json +10 -10
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/editor-plugin-show-diff
2
2
 
3
+ ## 21.0.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [`a302d2ba96967`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a302d2ba96967) -
8
+ Fix contributor tag placement so it no longer overflows onto the next line when a change wraps.
9
+ - [`6563a0ae0eb6f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6563a0ae0eb6f) -
10
+ [EDITOR-9212] Fix AI Suggested Edits diff rendering for a table nested inside an expand. Behind
11
+ `platform_editor_ai_show_diff_patch_2`, the diff preview now keeps the node's `breakout` mark, and
12
+ renders against its own document so node positions are resolved within the preview instead of the
13
+ live document — nested tables are no longer sized as top-level and pushed out of their cell, and a
14
+ preview can no longer write to the live document. The changed-node outline and the "Removed"
15
+ lozenge are both placed at the breakout width rather than the content column. Selecting a
16
+ suggestion that targets a collapsed expand now opens it in both the live document and the diff
17
+ preview, so the change is visible instead of hidden behind a title bar.
18
+ - Updated dependencies
19
+
3
20
  ## 20.0.11
4
21
 
5
22
  ### Patch Changes
@@ -8,8 +8,13 @@ exports.NodeViewSerializer = void 0;
8
8
  exports.isEditorViewWithNodeViews = isEditorViewWithNodeViews;
9
9
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
10
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
+ var _expand = require("@atlaskit/editor-common/expand");
11
12
  var _model = require("@atlaskit/editor-prosemirror/model");
13
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
12
14
  var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
15
+ var _fg = require("@atlaskit/platform-feature-flags/fg");
16
+ var _createEditorProxy = require("./createEditorProxy");
17
+ var _markViews = require("./markViews");
13
18
  /**
14
19
  * Utilities for working with ProseMirror node views and DOM serialization within the
15
20
  * Show Diff editor plugin.
@@ -37,6 +42,16 @@ function isEditorViewWithNodeViews(view) {
37
42
  return view.nodeViews !== undefined;
38
43
  }
39
44
 
45
+ /** Expand-family nodes whose expanded state lives in a node-keyed WeakMap. */
46
+ var EXPAND_TYPES = new Set(['expand', 'nestedExpand']);
47
+
48
+ /** Tables are the only node views that read and write positions, so only they need a preview. */
49
+ var containsTable = function containsTable(node) {
50
+ var table = node.type.schema.nodes.table;
51
+ // `contains` only checks descendants, so the node itself is checked separately.
52
+ return !!table && (node.type === table || (0, _utils.contains)(node, table));
53
+ };
54
+
40
55
  /**
41
56
  * Encapsulates DOM serialization and node view access/creation.
42
57
  *
@@ -82,11 +97,18 @@ var NodeViewSerializer = exports.NodeViewSerializer = /*#__PURE__*/function () {
82
97
  key: "appendChildNodes",
83
98
  value: function appendChildNodes(children, contentDOM) {
84
99
  var _this = this;
100
+ var basePos = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
101
+ var editorProxy = arguments.length > 3 ? arguments[3] : undefined;
102
+ // A node's first child sits one position inside it, and each subsequent
103
+ // child is offset by the previous child's `nodeSize`. Tracking this lets nested node
104
+ // views resolve to their real depth instead of every one of them seeing depth 0.
105
+ var childPos = basePos + 1;
85
106
  children.forEach(function (child) {
86
- var childNode = _this.tryCreateNodeView(child) || _this.serializeNode(child);
107
+ var childNode = _this.tryCreateNodeViewInner(child, childPos, editorProxy) || _this.serializeNode(child);
87
108
  if (childNode) {
88
109
  contentDOM === null || contentDOM === void 0 || contentDOM.append(childNode);
89
110
  }
111
+ childPos += child.nodeSize;
90
112
  });
91
113
  }
92
114
 
@@ -95,11 +117,29 @@ var NodeViewSerializer = exports.NodeViewSerializer = /*#__PURE__*/function () {
95
117
  *
96
118
  * Returns `null` when there is no `EditorView`, no constructor for the node type,
97
119
  * or the node type is blocklisted. Otherwise returns the constructed node view instance.
120
+ *
121
+ * `$sourcePos` is where the node sits in the doc it came from, so nested tables keep their depth.
98
122
  */
99
123
  }, {
100
124
  key: "tryCreateNodeView",
101
125
  value: function tryCreateNodeView(targetNode) {
126
+ var _preview$rootPos;
127
+ var basePos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
128
+ var $sourcePos = arguments.length > 2 ? arguments[2] : undefined;
129
+ if (!this.editorView) {
130
+ return null;
131
+ }
132
+ // The preview becomes the document every nested node view resolves its position against,
133
+ // so positions stay internally consistent.
134
+ var preview = (0, _fg.fg)('platform_editor_ai_show_diff_patch_2') && containsTable(targetNode) ? (0, _createEditorProxy.createEditorProxy)(this.editorView, targetNode, $sourcePos) : null;
135
+ return this.tryCreateNodeViewInner(targetNode, (_preview$rootPos = preview === null || preview === void 0 ? void 0 : preview.rootPos) !== null && _preview$rootPos !== void 0 ? _preview$rootPos : basePos, preview === null || preview === void 0 ? void 0 : preview.editorProxy);
136
+ }
137
+ }, {
138
+ key: "tryCreateNodeViewInner",
139
+ value: function tryCreateNodeViewInner(targetNode) {
102
140
  var _this$nodeViews;
141
+ var basePos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
142
+ var editorProxy = arguments.length > 2 ? arguments[2] : undefined;
103
143
  if (!this.editorView) {
104
144
  return null;
105
145
  }
@@ -145,23 +185,47 @@ var NodeViewSerializer = exports.NodeViewSerializer = /*#__PURE__*/function () {
145
185
  if (!(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_deleted_nodeview_content') && targetNode.type.name === 'paragraph' && targetNode.children.length === 1) {
146
186
  return this.serializeFragment(targetNode.content);
147
187
  }
148
- this.appendChildNodes(targetNode.children, _contentDOM);
188
+ this.appendChildNodes(targetNode.children, _contentDOM, basePos, editorProxy);
149
189
  }
150
- return _dom;
190
+ return this.withMarkViews(targetNode, _dom, editorProxy);
151
191
  }
152
- var _constructor = constructor(targetNode, this.editorView, function () {
153
- return 0;
192
+
193
+ // The expand node view reads `expandedState.get(node) ?? false`, never `attrs.__expanded`.
194
+ // Open the preview so its tables get real layout; an existing entry is the live expand's
195
+ // own state, so leave it alone.
196
+ if (EXPAND_TYPES.has(targetNode.type.name) && !_expand.expandedState.has(targetNode) && (0, _fg.fg)('platform_editor_ai_show_diff_patch_2')) {
197
+ _expand.expandedState.set(targetNode, true);
198
+ }
199
+
200
+ // `isTableNested` is `doc.resolve(pos).depth > 0`, so the old hardcoded `0` made nested
201
+ // tables size as top-level. Positions are resolved against the preview document, so
202
+ // they are only meaningful with an editor proxy.
203
+ var view = editorProxy !== null && editorProxy !== void 0 ? editorProxy : this.editorView;
204
+ var docSize = view.state.doc.content.size;
205
+ var resolvedPos = editorProxy ? Math.max(0, Math.min(basePos, docSize)) : 0;
206
+ var _constructor = constructor(targetNode, view, function () {
207
+ return resolvedPos;
154
208
  }, [], {}),
155
209
  dom = _constructor.dom,
156
210
  contentDOM = _constructor.contentDOM;
157
211
  // Iteratively populate children
158
- this.appendChildNodes(targetNode.children, contentDOM);
159
- return dom;
212
+ this.appendChildNodes(targetNode.children, contentDOM, basePos, editorProxy);
213
+ return this.withMarkViews(targetNode, dom, editorProxy);
160
214
  } catch (_unused) {
161
215
  return null;
162
216
  }
163
217
  }
164
218
 
219
+ /** Wraps rendered DOM in its marks, rendered against the editor proxy when there is one. */
220
+ }, {
221
+ key: "withMarkViews",
222
+ value: function withMarkViews(targetNode, nodeDom, editorProxy) {
223
+ return (0, _markViews.wrapInMarkViews)(targetNode, nodeDom, {
224
+ nodeViews: this.nodeViews,
225
+ view: editorProxy !== null && editorProxy !== void 0 ? editorProxy : this.editorView
226
+ });
227
+ }
228
+
165
229
  /**
166
230
  * Serializes a node to a DOM `Node` using the schema's `DOMSerializer`.
167
231
  */
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createEditorProxy = createEditorProxy;
7
+ var _selection = require("@atlaskit/editor-common/selection/gap-cursor/selection");
8
+ /**
9
+ * A preview is rendered by the live view's own node views, which read `getPos()` against
10
+ * `view.state.doc` for both layout (`isTableNested`) and writes (`scaleTable` builds attribute
11
+ * steps at `getPos() + 1`). Handing them live positions makes the layout correct but points the
12
+ * writes at unrelated live nodes, so give them a view whose document *is* the preview instead.
13
+ *
14
+ * With `$sourcePos` (the node's position in the doc it came from) the node is swapped into a copy
15
+ * of its real top-level ancestor, so a table inside an expand still resolves as nested.
16
+ *
17
+ * Returns `null` when the node cannot be a top-level child (e.g. a bare `tableCell`), in which
18
+ * case the caller falls back to the live view and the previous stubbed positions.
19
+ */
20
+ function createEditorProxy(liveView, rootNode, $sourcePos) {
21
+ var liveState = liveView.state;
22
+ var createDoc = function createDoc(topLevel) {
23
+ return liveState.schema.topNodeType.createChecked(null, topLevel);
24
+ };
25
+ var previewDoc;
26
+ var rootPos = 0;
27
+ try {
28
+ var _$sourcePos$nodeAfter;
29
+ if ($sourcePos && $sourcePos.depth > 0 && ((_$sourcePos$nodeAfter = $sourcePos.nodeAfter) === null || _$sourcePos$nodeAfter === void 0 ? void 0 : _$sourcePos$nodeAfter.type) === rootNode.type) {
30
+ var topLevel = rootNode;
31
+ for (var depth = $sourcePos.depth; depth > 0; depth--) {
32
+ var ancestor = $sourcePos.node(depth);
33
+ topLevel = ancestor.copy(ancestor.content.replaceChild($sourcePos.index(depth), topLevel));
34
+ }
35
+ previewDoc = createDoc(topLevel);
36
+ rootPos = $sourcePos.pos - $sourcePos.before(1);
37
+ } else {
38
+ previewDoc = createDoc(rootNode);
39
+ }
40
+ } catch (_unused) {
41
+ return null;
42
+ }
43
+
44
+ // A gap cursor just before the node selects nothing, so the table's node view doesn't render
45
+ // as selected or show its controls.
46
+ var previewSelection = new _selection.GapCursorSelection(previewDoc.resolve(rootPos), _selection.Side.LEFT);
47
+ // Proxy rather than `EditorState.create` so plugin state is shared as-is: re-initialising
48
+ // every plugin per preview would be costly and re-runs their side effects.
49
+ var stateProxy = new Proxy(liveState, {
50
+ get: function get(target, prop, receiver) {
51
+ if (prop === 'doc') {
52
+ return previewDoc;
53
+ }
54
+ if (prop === 'selection') {
55
+ return previewSelection;
56
+ }
57
+ return Reflect.get(target, prop, receiver);
58
+ }
59
+ });
60
+ var editorProxy = new Proxy(liveView, {
61
+ get: function get(target, prop, receiver) {
62
+ if (prop === 'state') {
63
+ return stateProxy;
64
+ }
65
+ if (prop === 'dispatch') {
66
+ // Keep the transaction inside the preview. It was built against `previewDoc`, so
67
+ // applying it to the live state would corrupt the real document.
68
+ return function (tr) {
69
+ try {
70
+ stateProxy = stateProxy.apply(tr);
71
+ } catch (_unused2) {
72
+ // A preview is throwaway; a failed self-update is not worth surfacing.
73
+ }
74
+ };
75
+ }
76
+ var value = Reflect.get(target, prop, receiver);
77
+ return typeof value === 'function' ? value.bind(target) : value;
78
+ }
79
+ });
80
+ return {
81
+ editorProxy: editorProxy,
82
+ rootPos: rootPos
83
+ };
84
+ }
@@ -224,13 +224,14 @@ var resolveHoistedCodeBlockAnchor = exports.resolveHoistedCodeBlockAnchor = func
224
224
  * highlights — or, with `anchorAtRangeStart`, at `from` itself. A host inside a code block is
225
225
  * hoisted in front of it instead, anchored via `resolveHoistedCodeBlockAnchor` (EDITOR-9045).
226
226
  *
227
- * Returns one decoration normally, two (marker + tag) when hoisted out of a code block.
227
+ * Returns one decoration when a caller-supplied `anchorName` is used, two (marker + tag)
228
+ * otherwise — hoisted out of a code block, or anchored to its own point marker.
228
229
  *
229
230
  * The tag is mounted in `toDOM` and taken down in `destroy`, so it lives exactly as long as the host
230
231
  * element ProseMirror drew it into — see `mountContributorTag`.
231
232
  */
232
233
  var createContributorTagWidget = exports.createContributorTagWidget = function createContributorTagWidget(_ref4) {
233
- var _hoisted$anchorName, _hoisted$codeBlockSta;
234
+ var _hoisted$codeBlockSta, _ref5, _hoisted$anchorName;
234
235
  var _ref4$anchorAtRangeSt = _ref4.anchorAtRangeStart,
235
236
  anchorAtRangeStart = _ref4$anchorAtRangeSt === void 0 ? false : _ref4$anchorAtRangeSt,
236
237
  anchorName = _ref4.anchorName,
@@ -250,15 +251,33 @@ var createContributorTagWidget = exports.createContributorTagWidget = function c
250
251
  // A change inside a code block is hoisted out of it, anchored to its own marker; anything else
251
252
  // keeps its own anchor.
252
253
  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
+ // Keep the host out of the table row's grid (EDITOR-8442).
255
+ var hostPos = (0, _createAnchorDecorationWidgets.clampAnchorPosIntoCell)(doc, (_hoisted$codeBlockSta = hoisted === null || hoisted === void 0 ? void 0 : hoisted.codeBlockStart) !== null && _hoisted$codeBlockSta !== void 0 ? _hoisted$codeBlockSta : anchorPos, 1);
256
+
257
+ // Inline diffs pass no anchorName. Give them their own point anchor instead of the
258
+ // `position: relative` fallback, which drifts left once the range wraps a line (EDITOR-9286).
259
+ var ownAnchorName = (0, _decorationKeys.buildAnchorDecorationKey)({
260
+ diffId: diffId,
261
+ anchorType: _decorationKeys.AnchorTypeKey.tag
262
+ });
263
+ var effectiveAnchorName = (_ref5 = (_hoisted$anchorName = hoisted === null || hoisted === void 0 ? void 0 : hoisted.anchorName) !== null && _hoisted$anchorName !== void 0 ? _hoisted$anchorName : anchorName) !== null && _ref5 !== void 0 ? _ref5 : ownAnchorName;
254
264
  var tagAnchorName = effectiveAnchorName && supportsAnchorPositioning() ? effectiveAnchorName : undefined;
255
265
  var decorations = [];
256
266
  if (hoisted) {
257
267
  decorations.push(hoisted.marker);
268
+ } else if (!anchorName && tagAnchorName) {
269
+ decorations.push(_view.Decoration.widget(hostPos, function () {
270
+ return (0, _createAnchorDecorationWidgets.createAnchorNameSpan)(ownAnchorName);
271
+ }, _objectSpread(_objectSpread({}, (0, _decorationKeys.buildAnchorDecorationSpec)({
272
+ diffId: diffId,
273
+ anchorType: _decorationKeys.AnchorTypeKey.tag,
274
+ side: -1
275
+ })), {}, {
276
+ marks: [],
277
+ ignoreSelection: true
278
+ })));
258
279
  }
259
- decorations.push(_view.Decoration.widget(
260
- // Keep the host out of the table row's grid (EDITOR-8442).
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 () {
280
+ decorations.push(_view.Decoration.widget(hostPos, function () {
262
281
  var host = buildContributorTagHost(diffId, tagAnchorName);
263
282
  mount = mountContributorTag({
264
283
  anchorName: tagAnchorName,
@@ -24,6 +24,21 @@ var _tableDiffMode = require("./utils/tableDiffMode");
24
24
  var _wrapBlockNodeView = require("./utils/wrapBlockNodeView");
25
25
  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; }
26
26
  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; }
27
+ /**
28
+ * Where a slice's `index`th child sits in `doc`: the children belong to the ancestor `openStart`
29
+ * levels above the change. `null` if out of range — `posAtIndex` throws past the last child.
30
+ */
31
+ var getSourcePos = function getSourcePos(doc, $changeFrom, openStart, index) {
32
+ var depth = $changeFrom ? $changeFrom.depth - openStart : -1;
33
+ if (!$changeFrom || depth < 0) {
34
+ return null;
35
+ }
36
+ var childIndex = $changeFrom.index(depth) + index;
37
+ if (childIndex >= $changeFrom.node(depth).childCount) {
38
+ return null;
39
+ }
40
+ return (0, _safeResolve.safeResolve)(doc, $changeFrom.posAtIndex(childIndex, depth));
41
+ };
27
42
  var isHeadingLevel = function isHeadingLevel(level) {
28
43
  return typeof level === 'number' && level >= 1 && level <= 6;
29
44
  };
@@ -291,7 +306,7 @@ var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidge
291
306
  * and if it's the first or last content, we go in however many the sliced Open
292
307
  * or sliced End depth is and match only the entire node.
293
308
  */
294
- slice.content.forEach(function (node) {
309
+ slice.content.forEach(function (node, _offset, index) {
295
310
  var isFirst = firstReplacedNode === node;
296
311
  var isLast = lastReplacedNode === node;
297
312
  var isOpenAtSliceBoundary = isFirst && slice.openStart > 0 || isLast && slice.openEnd > 0;
@@ -362,7 +377,8 @@ var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidge
362
377
  }
363
378
 
364
379
  // Try to create node view, fallback to serialization
365
- var nodeView = serializer.tryCreateNodeView(node);
380
+ var $sourcePos = (0, _fg.fg)('platform_editor_ai_show_diff_patch_2') ? getSourcePos(doc, $changeFromA, slice.openStart, index) : null;
381
+ var nodeView = serializer.tryCreateNodeView(node, 0, $sourcePos !== null && $sourcePos !== void 0 ? $sourcePos : undefined);
366
382
  if (nodeView) {
367
383
  if (node.isInline) {
368
384
  var wrapper = (0, _wrapBlockNodeView.createContentWrapper)(colorScheme, isActive, isInserted, reveal);
@@ -465,18 +481,27 @@ var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidge
465
481
  });
466
482
  }
467
483
 
468
- // Needed even when the indicator bar is off, because a contributor tag also anchors against the
469
- // widget.
484
+ // Needed even with the indicator bar off, since it anchors its top/bottom to the widget.
470
485
  if (showIndicators || showContributorTags) {
471
486
  dom.style.setProperty('anchor-name', "--".concat((0, _decorationKeys.buildAnchorDecorationKey)({
472
487
  diffId: diffId
473
488
  })));
474
- // The tag built below only anchors via `anchor()` if `contributorTagAnchorName` is set; without
475
- // it the tag falls back to a non-anchored position (EDITOR-9045).
476
- if ((0, _fg.fg)('confluence_ncs_step_diffing_version_history')) {
477
- contributorTagAnchorName !== null && contributorTagAnchorName !== void 0 ? contributorTagAnchorName : contributorTagAnchorName = (0, _decorationKeys.buildAnchorDecorationKey)({
478
- diffId: diffId
489
+ // `dom` is inline, so its box fragments across a line wrap and `anchor()` resolves to the
490
+ // wrong edge. The tag anchors to its own point marker instead (EDITOR-9286).
491
+ if ((0, _fg.fg)('confluence_ncs_step_diffing_version_history') && !contributorTagAnchorName) {
492
+ var tagPointAnchorName = (0, _decorationKeys.buildAnchorDecorationKey)({
493
+ diffId: diffId,
494
+ anchorType: _decorationKeys.AnchorTypeKey.tag
479
495
  });
496
+ contributorTagAnchorName = tagPointAnchorName;
497
+ decorations.push(_view.Decoration.widget(safeInsertPos, function () {
498
+ return (0, _createAnchorDecorationWidgets.createAnchorNameSpan)(tagPointAnchorName);
499
+ }, {
500
+ key: "contributor-tag-anchor-".concat(diffId),
501
+ side: -1,
502
+ marks: [],
503
+ ignoreSelection: true
504
+ }));
480
505
  }
481
506
  }
482
507
 
@@ -511,8 +536,7 @@ var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidge
511
536
  }
512
537
  })));
513
538
  } else {
514
- // Hosted at the start of the deleted run rather than on `dom` itself: `dom` is inline, so once
515
- // the deleted content wraps its box is the union of its line fragments.
539
+ // Anchored to the point marker pushed above, not to `dom` (EDITOR-9286).
516
540
  var tagHost = (0, _createContributorTagWidget.createContributorTagHost)({
517
541
  anchorName: contributorTagAnchorName,
518
542
  diffId: diffId,
@@ -321,6 +321,21 @@ var applyTextLikeBlockNodeStyles = function applyTextLikeBlockNodeStyles(_ref8)
321
321
  /**
322
322
  * Creates a content wrapper with deleted styles for a block node
323
323
  */
324
+ /**
325
+ * The element that spans breakout width, for nodes carrying a `breakout` mark. The wrapper divs
326
+ * stay at editor-column width, so anything that should align to the node's visible edges —
327
+ * outlines, absolutely positioned lozenges — has to attach here instead.
328
+ */
329
+ var findBreakoutElement = function findBreakoutElement(targetNode, nodeView) {
330
+ var _targetNode$marks;
331
+ var hasBreakoutMark = (_targetNode$marks = targetNode.marks) === null || _targetNode$marks === void 0 ? void 0 : _targetNode$marks.some(function (mark) {
332
+ return mark.type.name === 'breakout';
333
+ });
334
+ if (!hasBreakoutMark || !(nodeView instanceof HTMLElement)) {
335
+ return null;
336
+ }
337
+ return nodeView.matches('[data-node-type]') ? nodeView : nodeView.querySelector('[data-node-type]');
338
+ };
324
339
  var createBlockNodeContentWrapper = function createBlockNodeContentWrapper(_ref9) {
325
340
  var nodeView = _ref9.nodeView,
326
341
  targetNode = _ref9.targetNode,
@@ -338,7 +353,16 @@ var createBlockNodeContentWrapper = function createBlockNodeContentWrapper(_ref9
338
353
  // should not also get the inline content style (borderBottom underline) on their container.
339
354
  var shouldSkipContentStyle = isInserted && nodeStyle !== undefined;
340
355
  var contentStyle = shouldSkipContentStyle ? '' : (0, _wrapBlockNodeViewStyles.getChangedContentStyle)(colorScheme, isActive, isInserted, hideAddedDiffsUnderline);
341
- contentWrapper.setAttribute('style', "".concat(contentStyle).concat(nodeStyle || ''));
356
+
357
+ // A `breakout` node renders wider than the editor column while the wrapper divs
358
+ // stay at column width, so paint the outline on the node element that spans that width.
359
+ var breakoutTarget = nodeStyle ? findBreakoutElement(targetNode, nodeView) : null;
360
+ if ((0, _fg.fg)('platform_editor_ai_show_diff_patch_2') && breakoutTarget) {
361
+ appendStyleToElement(breakoutTarget, nodeStyle !== null && nodeStyle !== void 0 ? nodeStyle : '');
362
+ contentWrapper.setAttribute('style', contentStyle || '');
363
+ } else {
364
+ contentWrapper.setAttribute('style', "".concat(contentStyle).concat(nodeStyle || ''));
365
+ }
342
366
  contentWrapper.append(nodeView);
343
367
  return contentWrapper;
344
368
  };
@@ -468,7 +492,19 @@ var wrapBlockNode = function wrapBlockNode(_ref10) {
468
492
  })) {
469
493
  return;
470
494
  }
471
- blockWrapper.append(lozenge);
495
+
496
+ // `lozenge` is absolutely positioned, so it lands on the nearest positioned ancestor. For a
497
+ // breakout node that is the column-width wrapper, leaving the pill short of the node's
498
+ // right edge — host it on the breakout element, which must establish a containing block.
499
+ var breakoutHost = (0, _fg.fg)('platform_editor_ai_show_diff_patch_2') ? findBreakoutElement(targetNode, nodeView) : null;
500
+ if (breakoutHost) {
501
+ appendStyleToElement(breakoutHost, (0, _lazyNodeView.convertToInlineCss)({
502
+ position: 'relative'
503
+ }));
504
+ breakoutHost.append(lozenge);
505
+ } else {
506
+ blockWrapper.append(lozenge);
507
+ }
472
508
  }
473
509
  var contentWrapper = createBlockNodeContentWrapper({
474
510
  nodeView: nodeView,
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.wrapInMarkViews = void 0;
7
+ var _model = require("@atlaskit/editor-prosemirror/model");
8
+ var _fg = require("@atlaskit/platform-feature-flags/fg");
9
+ /**
10
+ * `@atlaskit/editor-prosemirror/view` doesn't re-export prosemirror-view's `MarkViewConstructor`,
11
+ * so it's typed locally, as `EditorSSRRenderer` does.
12
+ */
13
+
14
+ /** Where to look up a mark's renderer, and the view to render it against. */
15
+
16
+ /**
17
+ * Renders a mark as ProseMirror does: `view.nodeViews` also holds mark views, keyed by mark name,
18
+ * so `breakout` resolves whether it's registered under `markViews` or `nodeViews`. Falls back to
19
+ * `toDOM` — they can differ: `breakout` renders `.fabric-editor-breakout-mark-dom`, which the width
20
+ * CSS targets.
21
+ */
22
+ var renderMarkView = function renderMarkView(mark, inline, _ref) {
23
+ var nodeViews = _ref.nodeViews,
24
+ view = _ref.view;
25
+ try {
26
+ var markView = nodeViews === null || nodeViews === void 0 ? void 0 : nodeViews[mark.type.name];
27
+ if (markView && view) {
28
+ var rendered = markView(mark, view, inline);
29
+ return {
30
+ dom: rendered.dom,
31
+ contentDOM: rendered.contentDOM
32
+ };
33
+ }
34
+ var toDOM = mark.type.spec.toDOM;
35
+ if (!toDOM) {
36
+ return null;
37
+ }
38
+ return _model.DOMSerializer.renderSpec(document, toDOM(mark, inline));
39
+ } catch (_unused) {
40
+ return null;
41
+ }
42
+ };
43
+
44
+ /**
45
+ * Wraps rendered DOM in its marks, as ProseMirror does for the live document. Without this a
46
+ * block node loses `breakout`, whose wrapper supplies the width. Marks nest
47
+ * outside-in, so `marks[0]` is outermost.
48
+ */
49
+ var wrapInMarkViews = exports.wrapInMarkViews = function wrapInMarkViews(targetNode, nodeDom, sources) {
50
+ if (targetNode.marks.length === 0 || !(0, _fg.fg)('platform_editor_ai_show_diff_patch_2')) {
51
+ return nodeDom;
52
+ }
53
+ var wrapped = nodeDom;
54
+ for (var index = targetNode.marks.length - 1; index >= 0; index--) {
55
+ var _mark = targetNode.marks[index];
56
+ var rendered = renderMarkView(_mark, targetNode.isInline, sources);
57
+ // No content hole means nowhere to nest the node, so skip the mark, not the node.
58
+ if (!(rendered !== null && rendered !== void 0 && rendered.contentDOM)) {
59
+ continue;
60
+ }
61
+ rendered.contentDOM.appendChild(wrapped);
62
+ wrapped = rendered.dom;
63
+ }
64
+ return wrapped;
65
+ };
@@ -1,5 +1,10 @@
1
+ import { expandedState } from '@atlaskit/editor-common/expand';
1
2
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
3
+ import { contains } from '@atlaskit/editor-prosemirror/utils';
2
4
  import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
5
+ import { fg } from '@atlaskit/platform-feature-flags/fg';
6
+ import { createEditorProxy } from './createEditorProxy';
7
+ import { wrapInMarkViews } from './markViews';
3
8
 
4
9
  /**
5
10
  * Utilities for working with ProseMirror node views and DOM serialization within the
@@ -28,6 +33,18 @@ export function isEditorViewWithNodeViews(view) {
28
33
  return view.nodeViews !== undefined;
29
34
  }
30
35
 
36
+ /** Expand-family nodes whose expanded state lives in a node-keyed WeakMap. */
37
+ const EXPAND_TYPES = new Set(['expand', 'nestedExpand']);
38
+
39
+ /** Tables are the only node views that read and write positions, so only they need a preview. */
40
+ const containsTable = node => {
41
+ const {
42
+ table
43
+ } = node.type.schema.nodes;
44
+ // `contains` only checks descendants, so the node itself is checked separately.
45
+ return !!table && (node.type === table || contains(node, table));
46
+ };
47
+
31
48
  /**
32
49
  * Encapsulates DOM serialization and node view access/creation.
33
50
  *
@@ -66,12 +83,17 @@ export class NodeViewSerializer {
66
83
  /**
67
84
  * Appends serialized child nodes to the given contentDOM element.
68
85
  */
69
- appendChildNodes(children, contentDOM) {
86
+ appendChildNodes(children, contentDOM, basePos = 0, editorProxy) {
87
+ // A node's first child sits one position inside it, and each subsequent
88
+ // child is offset by the previous child's `nodeSize`. Tracking this lets nested node
89
+ // views resolve to their real depth instead of every one of them seeing depth 0.
90
+ let childPos = basePos + 1;
70
91
  children.forEach(child => {
71
- const childNode = this.tryCreateNodeView(child) || this.serializeNode(child);
92
+ const childNode = this.tryCreateNodeViewInner(child, childPos, editorProxy) || this.serializeNode(child);
72
93
  if (childNode) {
73
94
  contentDOM === null || contentDOM === void 0 ? void 0 : contentDOM.append(childNode);
74
95
  }
96
+ childPos += child.nodeSize;
75
97
  });
76
98
  }
77
99
 
@@ -80,8 +102,20 @@ export class NodeViewSerializer {
80
102
  *
81
103
  * Returns `null` when there is no `EditorView`, no constructor for the node type,
82
104
  * or the node type is blocklisted. Otherwise returns the constructed node view instance.
105
+ *
106
+ * `$sourcePos` is where the node sits in the doc it came from, so nested tables keep their depth.
83
107
  */
84
- tryCreateNodeView(targetNode) {
108
+ tryCreateNodeView(targetNode, basePos = 0, $sourcePos) {
109
+ var _preview$rootPos;
110
+ if (!this.editorView) {
111
+ return null;
112
+ }
113
+ // The preview becomes the document every nested node view resolves its position against,
114
+ // so positions stay internally consistent.
115
+ const preview = fg('platform_editor_ai_show_diff_patch_2') && containsTable(targetNode) ? createEditorProxy(this.editorView, targetNode, $sourcePos) : null;
116
+ return this.tryCreateNodeViewInner(targetNode, (_preview$rootPos = preview === null || preview === void 0 ? void 0 : preview.rootPos) !== null && _preview$rootPos !== void 0 ? _preview$rootPos : basePos, preview === null || preview === void 0 ? void 0 : preview.editorProxy);
117
+ }
118
+ tryCreateNodeViewInner(targetNode, basePos = 0, editorProxy) {
85
119
  var _this$nodeViews;
86
120
  if (!this.editorView) {
87
121
  return null;
@@ -129,22 +163,44 @@ export class NodeViewSerializer {
129
163
  if (!isExperimentEnabled('platform_editor_show_diff_deleted_nodeview_content') && targetNode.type.name === 'paragraph' && targetNode.children.length === 1) {
130
164
  return this.serializeFragment(targetNode.content);
131
165
  }
132
- this.appendChildNodes(targetNode.children, contentDOM);
166
+ this.appendChildNodes(targetNode.children, contentDOM, basePos, editorProxy);
133
167
  }
134
- return dom;
168
+ return this.withMarkViews(targetNode, dom, editorProxy);
135
169
  }
170
+
171
+ // The expand node view reads `expandedState.get(node) ?? false`, never `attrs.__expanded`.
172
+ // Open the preview so its tables get real layout; an existing entry is the live expand's
173
+ // own state, so leave it alone.
174
+ if (EXPAND_TYPES.has(targetNode.type.name) && !expandedState.has(targetNode) && fg('platform_editor_ai_show_diff_patch_2')) {
175
+ expandedState.set(targetNode, true);
176
+ }
177
+
178
+ // `isTableNested` is `doc.resolve(pos).depth > 0`, so the old hardcoded `0` made nested
179
+ // tables size as top-level. Positions are resolved against the preview document, so
180
+ // they are only meaningful with an editor proxy.
181
+ const view = editorProxy !== null && editorProxy !== void 0 ? editorProxy : this.editorView;
182
+ const docSize = view.state.doc.content.size;
183
+ const resolvedPos = editorProxy ? Math.max(0, Math.min(basePos, docSize)) : 0;
136
184
  const {
137
185
  dom,
138
186
  contentDOM
139
- } = constructor(targetNode, this.editorView, () => 0, [], {});
187
+ } = constructor(targetNode, view, () => resolvedPos, [], {});
140
188
  // Iteratively populate children
141
- this.appendChildNodes(targetNode.children, contentDOM);
142
- return dom;
189
+ this.appendChildNodes(targetNode.children, contentDOM, basePos, editorProxy);
190
+ return this.withMarkViews(targetNode, dom, editorProxy);
143
191
  } catch {
144
192
  return null;
145
193
  }
146
194
  }
147
195
 
196
+ /** Wraps rendered DOM in its marks, rendered against the editor proxy when there is one. */
197
+ withMarkViews(targetNode, nodeDom, editorProxy) {
198
+ return wrapInMarkViews(targetNode, nodeDom, {
199
+ nodeViews: this.nodeViews,
200
+ view: editorProxy !== null && editorProxy !== void 0 ? editorProxy : this.editorView
201
+ });
202
+ }
203
+
148
204
  /**
149
205
  * Serializes a node to a DOM `Node` using the schema's `DOMSerializer`.
150
206
  */