@atlaskit/editor-plugin-show-diff 25.1.0 → 26.0.1

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 (22) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +39 -6
  3. package/dist/cjs/pm-plugins/calculateDiff/diffBySteps.js +14 -2
  4. package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +14 -0
  5. package/dist/cjs/pm-plugins/decorations/createReplacedCellDecorations.js +350 -0
  6. package/dist/cjs/pm-plugins/decorations/utils/cellAttrs.js +30 -0
  7. package/dist/cjs/pm-plugins/decorations/utils/createNodeShapedMarginSpacer.js +13 -4
  8. package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +40 -7
  9. package/dist/es2019/pm-plugins/calculateDiff/diffBySteps.js +12 -2
  10. package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +14 -0
  11. package/dist/es2019/pm-plugins/decorations/createReplacedCellDecorations.js +338 -0
  12. package/dist/es2019/pm-plugins/decorations/utils/cellAttrs.js +19 -0
  13. package/dist/es2019/pm-plugins/decorations/utils/createNodeShapedMarginSpacer.js +13 -4
  14. package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +39 -6
  15. package/dist/esm/pm-plugins/calculateDiff/diffBySteps.js +14 -2
  16. package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +14 -0
  17. package/dist/esm/pm-plugins/decorations/createReplacedCellDecorations.js +343 -0
  18. package/dist/esm/pm-plugins/decorations/utils/cellAttrs.js +25 -0
  19. package/dist/esm/pm-plugins/decorations/utils/createNodeShapedMarginSpacer.js +13 -4
  20. package/dist/types/pm-plugins/decorations/createReplacedCellDecorations.d.ts +67 -0
  21. package/dist/types/pm-plugins/decorations/utils/cellAttrs.d.ts +13 -0
  22. package/package.json +9 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @atlaskit/editor-plugin-show-diff
2
2
 
3
+ ## 26.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`00d7be6e38362`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/00d7be6e38362) -
8
+ Render a whole-cell table replacement inside the live cell behind
9
+ `platform_editor_ai_show_diff_patch_2`, showing the new cell background when it changed, and hide
10
+ only the cell's content rather than the cell when deleted diffs are hidden, so the table keeps its
11
+ shape. Neither the diff nor the suggestion hover highlight overrides a cell's own background any
12
+ more, so removing them leaves it in place.
13
+
14
+ ## 26.0.0
15
+
16
+ ### Patch Changes
17
+
18
+ - [`b5f8a82f07fc6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b5f8a82f07fc6) -
19
+ Preserve spacing between panel replacement diffs at the start of a table cell or other container
20
+ behind platform_editor_ai_show_diff_patch_2.
21
+ - [`0f0ca74ca517a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0f0ca74ca517a) -
22
+ Add the `@atlaskit/editor-common/ai-xstate-migration` (`isAiXstateMigrationEnabled`) and
23
+ `@atlaskit/editor-common/ai-xstate-migration-no-exposure` (`isAiXstateMigrationEnabledNoExposure`)
24
+ entrypoints, which enable the AI xstate migration when either the Confluence
25
+ (`platform_editor_ai_xstate_migration`) or Jira (`platform_editor_ai_xstate_migration_jira`, a
26
+ platform feature experiment) experiment is on. Use the helper wherever the xstate migration is
27
+ checked.
28
+ - Updated dependencies
29
+
3
30
  ## 25.1.0
4
31
 
5
32
  ### Minor Changes
@@ -11,6 +11,7 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
11
11
  var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
12
12
  var _memoizeOne = _interopRequireDefault(require("memoize-one"));
13
13
  var _prosemirrorChangeset = require("prosemirror-changeset");
14
+ var _aiXstateMigrationNoExposure = require("@atlaskit/editor-common/ai-xstate-migration-no-exposure");
14
15
  var _areDocsEqualByBlockStructureAndText = require("@atlaskit/editor-common/utils/areDocsEqualByBlockStructureAndText");
15
16
  var _document = require("@atlaskit/editor-common/utils/document");
16
17
  var _transform = require("@atlaskit/editor-prosemirror/transform");
@@ -18,12 +19,12 @@ var _view = require("@atlaskit/editor-prosemirror/view");
18
19
  var _tableMap = require("@atlaskit/editor-tables/table-map");
19
20
  var _unsafeExpValNoExposure = require("@atlaskit/platform-feature-experiments/unsafe-exp-val-no-exposure");
20
21
  var _fg = require("@atlaskit/platform-feature-flags/fg");
21
- var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
22
22
  var _attributions = require("../decorations/colorSchemes/attributions");
23
23
  var _createAnchorDecorationWidgets = require("../decorations/createAnchorDecorationWidgets");
24
24
  var _createBlockChangedDecoration = require("../decorations/createBlockChangedDecoration");
25
25
  var _createInlineChangedDecoration = require("../decorations/createInlineChangedDecoration");
26
26
  var _createNodeChangedDecorationWidget = require("../decorations/createNodeChangedDecorationWidget");
27
+ var _createReplacedCellDecorations = require("../decorations/createReplacedCellDecorations");
27
28
  var _decorationKeys = require("../decorations/decorationKeys");
28
29
  var _extractContributorTags = require("../decorations/extractContributorTags");
29
30
  var _createDeletedLineBreakWidget = require("../decorations/utils/createDeletedLineBreakWidget");
@@ -603,7 +604,11 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
603
604
  // suppressed in the clean view. `hideDeletedDiffs` is load-bearing: when false the reviewer
604
605
  // asked to compare against the original, and the deleted side is the only place the
605
606
  // previous formatting is visible.
606
- var isMarkOnly = shouldHideMarkOnlyDeletions && hideDeletedDiffs && change.deleted.length > 0 && (0, _isMarkOnlyChange.isMarkOnlyChange)({
607
+ //
608
+ // Not on an inverted diff: there the widget's side is the suggested content, which the clean
609
+ // view keeps. Suppressing it hides the suggestion along with the displayed side it replaces,
610
+ // e.g. a cell whose only change is its background, as the signature ignores attrs.
611
+ var isMarkOnly = shouldHideMarkOnlyDeletions && hideDeletedDiffs && !(isInverted && (0, _fg.fg)('platform_editor_ai_show_diff_patch_2')) && change.deleted.length > 0 && (0, _isMarkOnlyChange.isMarkOnlyChange)({
607
612
  change: change,
608
613
  originalDoc: originalDoc,
609
614
  newDoc: tr.doc
@@ -679,7 +684,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
679
684
  // For a large inserted table, skip the per-cell inline decorations that
680
685
  // freeze the browser on re-render. Only active when Review moment is
681
686
  // eligible (xstate + M1).
682
- var useCoarseTableDecoration = isSmartNodeLevel && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_ai_xstate_migration', 'isEnabled', true) && (0, _unsafeExpValNoExposure.UNSAFE_expValNoExposure)('platform_editor_ai_streaming_ux_experience_m1', 'isEnabled', false) === true && isLargeInsertedTableRange(tr.doc, change.fromB, change.toB);
687
+ var useCoarseTableDecoration = isSmartNodeLevel && (0, _aiXstateMigrationNoExposure.isAiXstateMigrationEnabledNoExposure)() && (0, _unsafeExpValNoExposure.UNSAFE_expValNoExposure)('platform_editor_ai_streaming_ux_experience_m1', 'isEnabled', false) === true && isLargeInsertedTableRange(tr.doc, change.fromB, change.toB);
683
688
  // Whether the deleted-content widget will actually be rendered for this
684
689
  // change. Used to decide if indicator anchor positions should be adjusted
685
690
  // inward — when the widget is present the anchor must stay at the block
@@ -689,7 +694,35 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
689
694
  hideDeletedDiffs: hideDeletedDiffs,
690
695
  isInverted: isInverted
691
696
  });
692
- if (isSmartNodeLevel) {
697
+
698
+ // A whole-cell replacement keeps its cells in place, so it takes its own decorations
699
+ // instead of the generic inline and block ones.
700
+ var replacedCells = (0, _fg.fg)('platform_editor_ai_show_diff_patch_2') ? (0, _createReplacedCellDecorations.getReplacedCells)({
701
+ slice: originalDoc.slice(change.fromA, change.toA),
702
+ doc: tr.doc,
703
+ fromB: change.fromB,
704
+ toB: change.toB
705
+ }) : [];
706
+ if (replacedCells.length > 0) {
707
+ decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createReplacedCellDecorations.createReplacedCellDecorations)({
708
+ replacedCells: replacedCells,
709
+ change: change,
710
+ doc: tr.doc,
711
+ attributionKey: attributionKey,
712
+ colorScheme: changeColorScheme,
713
+ hasDeletedWidget: willRenderDeletedWidget,
714
+ hideAddedDiffsUnderline: hideAddedDiffsUnderline,
715
+ isActive: isActive,
716
+ isDeletedWidgetBelow: isDeletedWidgetBelow,
717
+ isInserted: isInserted,
718
+ leftAnchorId: leftAnchorId,
719
+ reveal: reveal,
720
+ shouldHideDeleted: shouldHideDeleted,
721
+ showContributorTags: showContributorTags,
722
+ showIndicators: showIndicators,
723
+ tagMountContext: tagMountContext
724
+ })));
725
+ } else if (isSmartNodeLevel) {
693
726
  // For a large inserted table, skip the O(cells) inline decorations inside the
694
727
  // table (the cell overlays added below provide the highlight without the
695
728
  // expensive content re-render); leaf blocks outside the table still get theirs.
@@ -749,7 +782,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
749
782
  tagMountContext: tagMountContext
750
783
  })));
751
784
  }
752
- decorations.push.apply(decorations, (0, _toConsumableArray2.default)(calculateNodesForBlockDecoration({
785
+ decorations.push.apply(decorations, (0, _toConsumableArray2.default)(replacedCells.length > 0 ? [] : calculateNodesForBlockDecoration({
753
786
  // A deleted widget placed below anchors at the change's end, inside the very block
754
787
  // this would let the decoration claim.
755
788
  allowTrailingCloseTokens: !isDeletedWidgetBelow,
@@ -939,7 +972,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref8
939
972
  })));
940
973
  // If the original node position is known (e.g. a panel type change), also render
941
974
  // the old block node as a "deleted" widget so the reviewer sees the before/after.
942
- var isSmartNodeLevelAttrChange = diffType === 'smart' && (0, _fg.fg)('platform_editor_ai_smart_diff') && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_ai_xstate_migration', 'isEnabled', true) && (0, _unsafeExpValNoExposure.UNSAFE_expValNoExposure)('platform_editor_ai_streaming_ux_experience_m1', 'isEnabled', false) === true;
975
+ var isSmartNodeLevelAttrChange = diffType === 'smart' && (0, _fg.fg)('platform_editor_ai_smart_diff') && (0, _aiXstateMigrationNoExposure.isAiXstateMigrationEnabledNoExposure)() && (0, _unsafeExpValNoExposure.UNSAFE_expValNoExposure)('platform_editor_ai_streaming_ux_experience_m1', 'isEnabled', false) === true;
943
976
  if (isSmartNodeLevelAttrChange && change.fromA !== undefined && change.toA !== undefined) {
944
977
  var placeBelow = deletedDiffPlacement === 'bottom';
945
978
  decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createNodeChangedDecorationWidget.createNodeChangedDecorationWidget)({
@@ -13,6 +13,7 @@ var _model = require("@atlaskit/editor-prosemirror/model");
13
13
  var _transform = require("@atlaskit/editor-prosemirror/transform");
14
14
  var _fg = require("@atlaskit/platform-feature-flags/fg");
15
15
  var _attributions = require("../decorations/colorSchemes/attributions");
16
+ var _cellAttrs = require("../decorations/utils/cellAttrs");
16
17
  var _charsByOffset = require("../utils/charsByOffset");
17
18
  var _attrAwareTokenEncoder = require("./attrAwareTokenEncoder");
18
19
  var _optimizeChanges = require("./optimizeChanges");
@@ -34,6 +35,16 @@ var WHITESPACE_REGEX = /[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u
34
35
  var isGranularIsolatingNode = function isGranularIsolatingNode(node) {
35
36
  return !!node.type.spec.isolating && node.type.spec.tableRole !== 'table';
36
37
  };
38
+ var CELL_TYPE_NAMES = ['tableCell', 'tableHeader'];
39
+
40
+ /**
41
+ * Whether a table cell's replacement changes one of its diffable attributes, such as its background.
42
+ * Such a cell is diffed whole: it renders as a cell style plus a copy of its row, which already shows
43
+ * the cell's new content, so inline marks inside it would only repeat that.
44
+ */
45
+ var isCellAttrChange = function isCellAttrChange(replacedNode, replacingNode) {
46
+ return CELL_TYPE_NAMES.includes(replacedNode.type.name) && (0, _cellAttrs.isCellAttrChanged)(replacedNode, replacingNode);
47
+ };
37
48
  var mapPosition = function mapPosition(mapping, pos) {
38
49
  return mapping.map(pos);
39
50
  };
@@ -237,7 +248,8 @@ var mergeOverlappingByNewDocRange = function mergeOverlappingByNewDocRange(chang
237
248
  * - The replaced slice has only one child
238
249
  * - The replacing slice has only one child
239
250
  * - Both children are the same textblock type, or (behind `platform_editor_ai_show_diff_patch_2`)
240
- * the same isolating, non-table node type whose text content differs
251
+ * the same isolating, non-table node type whose text content differs (for a table cell, only when
252
+ * its diffable attributes are unchanged)
241
253
  * - The replaced slice and replacing slice have the same text content
242
254
  * - The replaced slice and replacing slice have the same child marks (if text content is equal)
243
255
  */
@@ -275,7 +287,7 @@ var shouldCheckGranularDiff = function shouldCheckGranularDiff(step, before, fro
275
287
  // `hasSameChildMarks` only compares an isolating node's direct (block) children, so it cannot
276
288
  // vouch for one with unchanged text. Keep the existing whole-node fallback for that case.
277
289
  if (isIsolatingNode) {
278
- return !isTextContentEqual;
290
+ return !isTextContentEqual && !(replacingNode && isCellAttrChange(replacedNode, replacingNode));
279
291
  }
280
292
  return !isTextContentEqual || isTextContentEqual && hasSameChildMarks(replacedNode, replacingNode);
281
293
  };
@@ -18,6 +18,7 @@ var _createAnchorDecorationWidgets = require("./createAnchorDecorationWidgets");
18
18
  var _createChangedRowDecorationWidgets = require("./createChangedRowDecorationWidgets");
19
19
  var _createContributorTagWidget = require("./createContributorTagWidget");
20
20
  var _createInlineChangedDecoration = require("./createInlineChangedDecoration");
21
+ var _createReplacedCellDecorations = require("./createReplacedCellDecorations");
21
22
  var _decorationKeys = require("./decorationKeys");
22
23
  var _absorbFirstChildMarginReset = require("./utils/absorbFirstChildMarginReset");
23
24
  var _createDeletedLineBreakWidget = require("./utils/createDeletedLineBreakWidget");
@@ -222,6 +223,19 @@ var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidge
222
223
  isInserted: isInserted
223
224
  });
224
225
  if (tableDiffMode.kind === 'cells') {
226
+ if ((0, _fg.fg)('platform_editor_ai_show_diff_patch_2')) {
227
+ return (0, _createReplacedCellDecorations.createReplacedCellWidgets)({
228
+ slice: slice,
229
+ newDoc: newDoc,
230
+ change: change,
231
+ nodeViewSerializer: nodeViewSerializer,
232
+ colorScheme: colorScheme,
233
+ intl: intl,
234
+ isActive: isActive,
235
+ isInserted: isInserted,
236
+ leftAnchorId: leftAnchorId
237
+ });
238
+ }
225
239
  return createTableCellContentWidgets({
226
240
  slice: slice,
227
241
  newDoc: newDoc,
@@ -0,0 +1,350 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getReplacedCells = exports.createReplacedCellWidgets = exports.createReplacedCellDecorations = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _getDarkModeLchColor = require("@atlaskit/adf-schema/get-dark-mode-lch-color");
11
+ var _isRgb = require("@atlaskit/adf-schema/is-rgb");
12
+ var _rgbToHex = require("@atlaskit/adf-schema/rgb-to-hex");
13
+ var _tableNodes = require("@atlaskit/adf-schema/tableNodes");
14
+ var _cssHelper = require("@atlaskit/editor-common/css-helper");
15
+ var _document = require("@atlaskit/editor-common/utils/document");
16
+ var _view = require("@atlaskit/editor-prosemirror/view");
17
+ var _createBlockChangedDecoration = require("./createBlockChangedDecoration");
18
+ var _createInlineChangedDecoration = require("./createInlineChangedDecoration");
19
+ var _decorationKeys = require("./decorationKeys");
20
+ var _cellAttrs = require("./utils/cellAttrs");
21
+ var _wrapBlockNodeView = require("./utils/wrapBlockNodeView");
22
+ 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; }
23
+ 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; }
24
+ var CELL_TYPE_NAMES = ['tableCell', 'tableHeader'];
25
+ /**
26
+ * Pairs each cell of a whole-cell replacement with the live cell it replaces, or `[]` when the slice
27
+ * is not a run of whole cells matching the live ones. Whole-cell replacement preserves cell count and
28
+ * order, so the nth live cell in the range matches the nth cell in the slice.
29
+ */
30
+ var getReplacedCells = exports.getReplacedCells = function getReplacedCells(_ref) {
31
+ var slice = _ref.slice,
32
+ doc = _ref.doc,
33
+ fromB = _ref.fromB,
34
+ toB = _ref.toB;
35
+ var otherCells = slice.content.content;
36
+ if (slice.openStart !== 0 || slice.openEnd !== 0 || otherCells.length === 0 || !otherCells.every(function (node) {
37
+ return CELL_TYPE_NAMES.includes(node.type.name);
38
+ })) {
39
+ return [];
40
+ }
41
+ var liveCells = [];
42
+ doc.nodesBetween(fromB, toB, function (node, pos) {
43
+ if (CELL_TYPE_NAMES.includes(node.type.name)) {
44
+ liveCells.push({
45
+ node: node,
46
+ pos: pos
47
+ });
48
+ return false;
49
+ }
50
+ return true;
51
+ });
52
+ if (liveCells.length !== otherCells.length) {
53
+ return [];
54
+ }
55
+ return otherCells.map(function (otherCell, index) {
56
+ return {
57
+ otherCell: otherCell,
58
+ liveCell: liveCells[index].node,
59
+ liveCellPos: liveCells[index].pos
60
+ };
61
+ });
62
+ };
63
+
64
+ /**
65
+ * Whether two cells hold the same content, ignoring the cells' own attributes and `localId`s, which
66
+ * a suggestion can regenerate. Such a replacement only changed the cell (e.g. its background), so
67
+ * there is no content to diff.
68
+ */
69
+ var isCellContentEqual = function isCellContentEqual(left, right) {
70
+ if (left.childCount !== right.childCount) {
71
+ return false;
72
+ }
73
+ for (var index = 0; index < left.childCount; index++) {
74
+ if (!(0, _document.areNodesEqualIgnoreAttrs)(left.child(index), right.child(index), ['localId'])) {
75
+ return false;
76
+ }
77
+ }
78
+ return true;
79
+ };
80
+
81
+ /**
82
+ * Whether the cell itself changed — its type, or an attribute that represents a change such as its
83
+ * background or span — as opposed to only its content.
84
+ */
85
+ var isCellChanged = function isCellChanged(left, right) {
86
+ return left.type !== right.type || (0, _cellAttrs.isCellAttrChanged)(left, right);
87
+ };
88
+
89
+ /**
90
+ * A custom (non-palette) cell colour as the schema renders it: inverted in dark mode so text stays
91
+ * readable, except for design tokens, which are already themed.
92
+ */
93
+ var getCustomCellColor = function getCustomCellColor(background) {
94
+ var color = (0, _isRgb.isRgb)(background) && (0, _rgbToHex.rgbToHex)(background) || background;
95
+ if (color.startsWith('var(') || document.documentElement.getAttribute('data-color-mode') !== 'dark') {
96
+ return background;
97
+ }
98
+ return (0, _getDarkModeLchColor.getDarkModeLCHColor)(color);
99
+ };
100
+
101
+ /**
102
+ * The colour `cell` renders with. A palette colour is the editor's own themed variable for its colour
103
+ * name (e.g. for dark mode), the one `td[colorname]` cells use; a custom colour is the schema's own
104
+ * treatment of it; no colour is the editor's default.
105
+ */
106
+ var getCellBackgroundColor = function getCellBackgroundColor(cell) {
107
+ var background = (0, _cellAttrs.normalizeCellBackground)(cell.attrs.background);
108
+ if (!background) {
109
+ return cell.type.name === 'tableHeader' ? "var(--ds-background-accent-gray-subtlest, #F0F1F2)" : "var(--ds-surface, #FFFFFF)";
110
+ }
111
+ var _getCellDomAttrs = (0, _tableNodes.getCellDomAttrs)(cell),
112
+ colorname = _getCellDomAttrs.colorname;
113
+ return colorname ? "var(--ak-editor-table-cell-background-".concat(colorname.toLowerCase().split(' ').join('-'), ")") : getCustomCellColor(background);
114
+ };
115
+
116
+ /**
117
+ * A layer painting `color` over the cell's own background and under its content, so the cell reads
118
+ * as having the new background without any of the cell's own attributes being overridden: removing
119
+ * a decoration removes the attributes it set rather than restoring the ones they replaced.
120
+ */
121
+ var createCellBackgroundLayer = function createCellBackgroundLayer(color) {
122
+ var layer = document.createElement('div');
123
+ layer.setAttribute('aria-hidden', 'true');
124
+ layer.contentEditable = 'false';
125
+ layer.dataset.testid = 'show-diff-new-cell-background';
126
+ layer.setAttribute('style', (0, _cssHelper.convertToInlineCss)({
127
+ position: 'absolute',
128
+ inset: 0,
129
+ zIndex: -1,
130
+ borderRadius: 'inherit',
131
+ pointerEvents: 'none',
132
+ backgroundColor: color
133
+ }));
134
+ return layer;
135
+ };
136
+
137
+ /** The other side's cell content, as blocks, for the top of the live cell. */
138
+ var createCellContentWidget = function createCellContentWidget(_ref2) {
139
+ var cell = _ref2.cell,
140
+ pos = _ref2.pos,
141
+ nodeViewSerializer = _ref2.nodeViewSerializer,
142
+ colorScheme = _ref2.colorScheme,
143
+ intl = _ref2.intl,
144
+ isActive = _ref2.isActive,
145
+ isInserted = _ref2.isInserted,
146
+ leftAnchorId = _ref2.leftAnchorId;
147
+ var dom = document.createElement('div');
148
+ cell.content.forEach(function (block) {
149
+ var nodeView = nodeViewSerializer.tryCreateNodeView(block, 0, undefined, isInserted, colorScheme);
150
+ if (nodeView) {
151
+ (0, _wrapBlockNodeView.wrapBlockNodeView)({
152
+ dom: dom,
153
+ nodeView: nodeView,
154
+ targetNode: block,
155
+ colorScheme: colorScheme,
156
+ intl: intl,
157
+ isActive: isActive,
158
+ isInserted: isInserted
159
+ });
160
+ return;
161
+ }
162
+ var serialized = nodeViewSerializer.serializeNode(block);
163
+ if (serialized instanceof HTMLElement) {
164
+ dom.append((0, _wrapBlockNodeView.injectInnerWrapper)({
165
+ node: serialized,
166
+ colorScheme: colorScheme,
167
+ isActive: isActive,
168
+ isInserted: isInserted
169
+ }));
170
+ }
171
+ });
172
+ if (dom.childNodes.length === 0) {
173
+ return undefined;
174
+ }
175
+ dom.setAttribute('data-testid', isInserted ? 'show-diff-changed-decoration' : 'show-diff-deleted-decoration');
176
+
177
+ // Before the cell's own blocks, as a block of its own, so it never lands inside a paragraph the
178
+ // displayed side may hide.
179
+ return _view.Decoration.widget(pos + 1, dom, _objectSpread(_objectSpread({}, (0, _decorationKeys.buildDiffDecorationSpec)({
180
+ colorScheme: colorScheme,
181
+ decorationType: 'widget',
182
+ diffId: crypto.randomUUID(),
183
+ leftAnchorId: leftAnchorId,
184
+ isActive: isActive,
185
+ isInserted: isInserted,
186
+ side: -1
187
+ })), {}, {
188
+ marks: []
189
+ }));
190
+ };
191
+
192
+ /**
193
+ * The other side of a whole-cell replacement, drawn inside the live cells so the table keeps its
194
+ * shape: each live cell takes the other cell's background when it differs, and its content when that
195
+ * differs. A cell whose content did not change has nothing to diff.
196
+ */
197
+ var createReplacedCellWidgets = exports.createReplacedCellWidgets = function createReplacedCellWidgets(_ref3) {
198
+ var slice = _ref3.slice,
199
+ newDoc = _ref3.newDoc,
200
+ change = _ref3.change,
201
+ nodeViewSerializer = _ref3.nodeViewSerializer,
202
+ colorScheme = _ref3.colorScheme,
203
+ intl = _ref3.intl,
204
+ isActive = _ref3.isActive,
205
+ isInserted = _ref3.isInserted,
206
+ leftAnchorId = _ref3.leftAnchorId;
207
+ return getReplacedCells({
208
+ slice: slice,
209
+ doc: newDoc,
210
+ fromB: change.fromB,
211
+ toB: change.toB
212
+ }).flatMap(function (_ref4) {
213
+ var otherCell = _ref4.otherCell,
214
+ liveCell = _ref4.liveCell,
215
+ liveCellPos = _ref4.liveCellPos;
216
+ var decorations = [];
217
+ if (isInserted && (0, _cellAttrs.isCellBackgroundChanged)(otherCell, liveCell)) {
218
+ var cellEnd = liveCellPos + liveCell.nodeSize;
219
+ decorations.push(
220
+ // The cell becomes the layer's stacking context, so the layer sits above the cell's own
221
+ // background rather than behind it. Through `z-index` at the cell overlay's own level, not
222
+ // `isolation`: an isolated cell would trap its overlay below later cells, which then cover
223
+ // the overlay's outline where it overlaps their border. Properties the cell never sets, so
224
+ // removing them takes nothing of its own.
225
+ _view.Decoration.node(liveCellPos, cellEnd, {
226
+ style: (0, _cssHelper.convertToInlineCss)({
227
+ position: 'relative',
228
+ // The highest z-index a cell diff overlay takes (the rounded-corner variant).
229
+ zIndex: 2
230
+ })
231
+ }, {
232
+ key: "show-diff-new-cell-background-host-".concat(liveCellPos)
233
+ }),
234
+ // At the cell's end, beside its diff overlay, so the cell's first block stays its first child.
235
+ _view.Decoration.widget(cellEnd - 1, createCellBackgroundLayer(getCellBackgroundColor(otherCell)), {
236
+ key: "show-diff-new-cell-background-".concat(liveCellPos),
237
+ side: -1,
238
+ marks: [],
239
+ ignoreSelection: true
240
+ }));
241
+ }
242
+ if (!isCellContentEqual(otherCell, liveCell)) {
243
+ var contentWidget = createCellContentWidget({
244
+ cell: otherCell,
245
+ pos: liveCellPos,
246
+ nodeViewSerializer: nodeViewSerializer,
247
+ colorScheme: colorScheme,
248
+ intl: intl,
249
+ isActive: isActive,
250
+ isInserted: isInserted,
251
+ leftAnchorId: leftAnchorId
252
+ });
253
+ if (contentWidget) {
254
+ decorations.push(contentWidget);
255
+ }
256
+ }
257
+ return decorations;
258
+ });
259
+ };
260
+
261
+ /**
262
+ * The displayed side of a whole-cell replacement. A table cell is never removed on its own, only
263
+ * replaced in place, so a live cell is never hidden — hiding it would leave the row a cell short. It
264
+ * takes the changed-cell treatment only when the cell itself changed; its content is diffed, and
265
+ * hidden in the clean view, only when that changed. A cell whose content stayed the same keeps
266
+ * showing it.
267
+ */
268
+ var createReplacedCellDecorations = exports.createReplacedCellDecorations = function createReplacedCellDecorations(_ref5) {
269
+ var replacedCells = _ref5.replacedCells,
270
+ change = _ref5.change,
271
+ doc = _ref5.doc,
272
+ attributionKey = _ref5.attributionKey,
273
+ colorScheme = _ref5.colorScheme,
274
+ hasDeletedWidget = _ref5.hasDeletedWidget,
275
+ hideAddedDiffsUnderline = _ref5.hideAddedDiffsUnderline,
276
+ isActive = _ref5.isActive,
277
+ isDeletedWidgetBelow = _ref5.isDeletedWidgetBelow,
278
+ isInserted = _ref5.isInserted,
279
+ leftAnchorId = _ref5.leftAnchorId,
280
+ reveal = _ref5.reveal,
281
+ shouldHideDeleted = _ref5.shouldHideDeleted,
282
+ showContributorTags = _ref5.showContributorTags,
283
+ showIndicators = _ref5.showIndicators,
284
+ tagMountContext = _ref5.tagMountContext;
285
+ return replacedCells.flatMap(function (_ref6) {
286
+ var otherCell = _ref6.otherCell,
287
+ liveCell = _ref6.liveCell,
288
+ liveCellPos = _ref6.liveCellPos;
289
+ var cellEnd = liveCellPos + liveCell.nodeSize;
290
+ var decorations = isCellChanged(otherCell, liveCell) ? (0, _createBlockChangedDecoration.createBlockChangedDecoration)({
291
+ attributionKey: attributionKey,
292
+ change: {
293
+ from: liveCellPos,
294
+ to: cellEnd,
295
+ name: liveCell.type.name
296
+ },
297
+ colorScheme: colorScheme,
298
+ doc: doc,
299
+ isActive: isActive,
300
+ // The cell stays either way, so it reads as changed, not removed.
301
+ isInserted: true,
302
+ leftAnchorId: leftAnchorId,
303
+ showContributorTags: showContributorTags,
304
+ showIndicators: showIndicators,
305
+ tagMountContext: tagMountContext
306
+ }) : [];
307
+ if (isCellContentEqual(otherCell, liveCell)) {
308
+ return decorations;
309
+ }
310
+ decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createInlineChangedDecoration.createInlineChangedDecoration)({
311
+ attributionKey: attributionKey,
312
+ change: _objectSpread(_objectSpread({}, change), {}, {
313
+ fromB: liveCellPos,
314
+ toB: cellEnd
315
+ }),
316
+ colorScheme: colorScheme,
317
+ doc: doc,
318
+ hasDeletedWidget: hasDeletedWidget,
319
+ hideAddedDiffsUnderline: hideAddedDiffsUnderline,
320
+ isActive: isActive,
321
+ isDeletedWidgetBelow: isDeletedWidgetBelow,
322
+ isInserted: isInserted,
323
+ leftAnchorId: leftAnchorId,
324
+ reveal: reveal,
325
+ shouldHideDeleted: shouldHideDeleted,
326
+ showContributorTags: showContributorTags,
327
+ showIndicators: showIndicators,
328
+ tagMountContext: tagMountContext
329
+ })));
330
+ if (shouldHideDeleted) {
331
+ liveCell.forEach(function (block, offset) {
332
+ var blockPos = liveCellPos + 1 + offset;
333
+ decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createBlockChangedDecoration.createBlockChangedDecoration)({
334
+ change: {
335
+ from: blockPos,
336
+ to: blockPos + block.nodeSize,
337
+ name: block.type.name
338
+ },
339
+ colorScheme: colorScheme,
340
+ doc: doc,
341
+ isActive: isActive,
342
+ isInserted: isInserted,
343
+ leftAnchorId: leftAnchorId,
344
+ shouldHideDeleted: shouldHideDeleted
345
+ })));
346
+ });
347
+ }
348
+ return decorations;
349
+ });
350
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.normalizeCellBackground = exports.isCellBackgroundChanged = exports.isCellAttrChanged = void 0;
7
+ var _diffableAttrs = require("./diffableAttrs");
8
+ /**
9
+ * A cell background as it renders: absent, empty and `"null"` — the string agent payloads send for
10
+ * no background — all mean the cell has none.
11
+ */
12
+ var normalizeCellBackground = exports.normalizeCellBackground = function normalizeCellBackground(background) {
13
+ return typeof background === 'string' && background !== '' && background !== 'null' ? background : null;
14
+ };
15
+
16
+ /** Whether two cells render different backgrounds. */
17
+ var isCellBackgroundChanged = exports.isCellBackgroundChanged = function isCellBackgroundChanged(left, right) {
18
+ return normalizeCellBackground(left.attrs.background) !== normalizeCellBackground(right.attrs.background);
19
+ };
20
+
21
+ /**
22
+ * Whether two cells differ by an attribute that represents a change, such as their background or
23
+ * span, as opposed to only their content.
24
+ */
25
+ var isCellAttrChanged = exports.isCellAttrChanged = function isCellAttrChanged(left, right) {
26
+ var _getDiffableAttrNames;
27
+ return ((_getDiffableAttrNames = (0, _diffableAttrs.getDiffableAttrNames)(left.type.name, left.attrs)) !== null && _getDiffableAttrNames !== void 0 ? _getDiffableAttrNames : []).some(function (name) {
28
+ return name === 'background' ? isCellBackgroundChanged(left, right) : left.attrs[name] !== right.attrs[name];
29
+ });
30
+ };
@@ -4,16 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createNodeShapedMarginSpacer = void 0;
7
+ var _panel = require("@atlaskit/editor-common/styles/panel");
8
+ var _nodeTypeUtils = require("@atlaskit/editor-common/utils/node-type-utils");
7
9
  /**
8
10
  * Node types that can safely be reduced to an empty shell.
9
11
  *
10
12
  * A shell only replicates a margin if it collapses to nothing itself, which needs zero height and
11
- * no vertical border or padding. Textblocks and lists qualify; nodes with intrinsic sizing (tables
12
- * are `display: table`, media has a measured height) or a painted box (a zero-height panel is a
13
- * visible stripe of background) do not, and are left alone.
13
+ * no vertical border or padding. Textblocks and lists qualify; panels need their painted box
14
+ * hidden and their flex layout removed. Nodes with intrinsic sizing (tables are `display: table`,
15
+ * media has a measured height) are left alone.
14
16
  */
15
17
  var isShapeableNode = function isShapeableNode(node) {
16
- return node.isTextblock || ['bulletList', 'orderedList'].includes(node.type.name);
18
+ return node.isTextblock || ['bulletList', 'orderedList'].includes(node.type.name) || (0, _nodeTypeUtils.getBaseNodeTypeName)(node.type) === 'panel';
17
19
  };
18
20
 
19
21
  /**
@@ -57,6 +59,13 @@ var createNodeShapedMarginSpacer = exports.createNodeShapedMarginSpacer = functi
57
59
  serialized.dataset.testid = testId;
58
60
  serialized.setAttribute('aria-hidden', 'true');
59
61
  serialized.contentEditable = 'false';
62
+ if ((0, _nodeTypeUtils.getBaseNodeTypeName)(node.type) === 'panel') {
63
+ // Schema serialization lacks the node view's class, which carries the panel's margin.
64
+ // Hide the painted shell and allow its margins to collapse through a zero-height block.
65
+ serialized.classList.add(_panel.PanelSharedCssClassName.prefix);
66
+ serialized.style.display = 'block';
67
+ serialized.style.visibility = 'hidden';
68
+ }
60
69
 
61
70
  // Zero height with no vertical border or padding keeps the spacer self-collapsing: its margins
62
71
  // stay adjoining, so they collapse with the neighbours into a single margin equal to the largest