@atlaskit/editor-plugin-show-diff 6.0.1 → 6.1.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 (50) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/pm-plugins/calculateDiffDecorations.js +37 -16
  3. package/dist/cjs/pm-plugins/decorations/colorSchemes/standard.js +23 -1
  4. package/dist/cjs/pm-plugins/decorations/colorSchemes/traditional.js +23 -1
  5. package/dist/cjs/pm-plugins/decorations/createBlockChangedDecoration.js +60 -8
  6. package/dist/cjs/pm-plugins/decorations/createChangedRowDecorationWidgets.js +19 -4
  7. package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +24 -4
  8. package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +92 -21
  9. package/dist/cjs/pm-plugins/decorations/utils/getMarkChangeRanges.js +0 -15
  10. package/dist/cjs/pm-plugins/decorations/utils/wrapBlockNodeView.js +87 -45
  11. package/dist/cjs/pm-plugins/main.js +17 -7
  12. package/dist/es2019/pm-plugins/calculateDiffDecorations.js +35 -13
  13. package/dist/es2019/pm-plugins/decorations/colorSchemes/standard.js +22 -0
  14. package/dist/es2019/pm-plugins/decorations/colorSchemes/traditional.js +22 -0
  15. package/dist/es2019/pm-plugins/decorations/createBlockChangedDecoration.js +59 -8
  16. package/dist/es2019/pm-plugins/decorations/createChangedRowDecorationWidgets.js +20 -6
  17. package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +25 -6
  18. package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +84 -16
  19. package/dist/es2019/pm-plugins/decorations/utils/getMarkChangeRanges.js +0 -13
  20. package/dist/es2019/pm-plugins/decorations/utils/wrapBlockNodeView.js +58 -19
  21. package/dist/es2019/pm-plugins/main.js +22 -4
  22. package/dist/esm/pm-plugins/calculateDiffDecorations.js +37 -16
  23. package/dist/esm/pm-plugins/decorations/colorSchemes/standard.js +22 -0
  24. package/dist/esm/pm-plugins/decorations/colorSchemes/traditional.js +22 -0
  25. package/dist/esm/pm-plugins/decorations/createBlockChangedDecoration.js +62 -10
  26. package/dist/esm/pm-plugins/decorations/createChangedRowDecorationWidgets.js +21 -6
  27. package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +26 -6
  28. package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +93 -23
  29. package/dist/esm/pm-plugins/decorations/utils/getMarkChangeRanges.js +0 -15
  30. package/dist/esm/pm-plugins/decorations/utils/wrapBlockNodeView.js +89 -47
  31. package/dist/esm/pm-plugins/main.js +17 -7
  32. package/dist/types/pm-plugins/decorations/colorSchemes/standard.d.ts +2 -0
  33. package/dist/types/pm-plugins/decorations/colorSchemes/traditional.d.ts +2 -0
  34. package/dist/types/pm-plugins/decorations/createBlockChangedDecoration.d.ts +2 -1
  35. package/dist/types/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +2 -1
  36. package/dist/types/pm-plugins/decorations/createInlineChangedDecoration.d.ts +2 -1
  37. package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +6 -1
  38. package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +2 -1
  39. package/dist/types/pm-plugins/main.d.ts +1 -0
  40. package/dist/types/showDiffPluginType.d.ts +1 -0
  41. package/dist/types-ts4.5/pm-plugins/decorations/colorSchemes/standard.d.ts +2 -0
  42. package/dist/types-ts4.5/pm-plugins/decorations/colorSchemes/traditional.d.ts +2 -0
  43. package/dist/types-ts4.5/pm-plugins/decorations/createBlockChangedDecoration.d.ts +2 -1
  44. package/dist/types-ts4.5/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +2 -1
  45. package/dist/types-ts4.5/pm-plugins/decorations/createInlineChangedDecoration.d.ts +2 -1
  46. package/dist/types-ts4.5/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +6 -1
  47. package/dist/types-ts4.5/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +2 -1
  48. package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -0
  49. package/dist/types-ts4.5/showDiffPluginType.d.ts +1 -0
  50. package/package.json +4 -3
@@ -23,18 +23,21 @@ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration
23
23
  var doc = _ref.doc,
24
24
  from = _ref.from,
25
25
  to = _ref.to,
26
- colorScheme = _ref.colorScheme;
26
+ colorScheme = _ref.colorScheme,
27
+ _ref$isInserted = _ref.isInserted,
28
+ isInserted = _ref$isInserted === void 0 ? true : _ref$isInserted;
27
29
  var decorations = [];
28
30
  // Iterate over the document nodes within the range
29
31
  doc.nodesBetween(from, to, function (node, pos) {
30
- if (node.isBlock) {
32
+ if (node.isBlock && (!expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) || pos + node.nodeSize <= to)) {
31
33
  var decoration = createBlockChangedDecoration({
32
34
  change: {
33
35
  from: pos,
34
36
  to: pos + node.nodeSize,
35
37
  name: node.type.name
36
38
  },
37
- colorScheme: colorScheme
39
+ colorScheme: colorScheme,
40
+ isInserted: isInserted
38
41
  });
39
42
  if (decoration) {
40
43
  decorations.push(decoration);
@@ -83,7 +86,9 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref2
83
86
  colorScheme = _ref2.colorScheme,
84
87
  intl = _ref2.intl,
85
88
  activeIndexPos = _ref2.activeIndexPos,
86
- api = _ref2.api;
89
+ api = _ref2.api,
90
+ _ref2$isInverted = _ref2.isInverted,
91
+ isInverted = _ref2$isInverted === void 0 ? false : _ref2$isInverted;
87
92
  var originalDoc = pluginState.originalDoc,
88
93
  steps = pluginState.steps;
89
94
  if (!originalDoc || !pluginState.isDisplayingChanges) {
@@ -137,22 +142,28 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref2
137
142
  var decorations = [];
138
143
  optimizedChanges.forEach(function (change) {
139
144
  var isActive = activeIndexPos && change.fromB >= activeIndexPos.from && change.toB <= activeIndexPos.to;
145
+ // Our default operations are insertions, so it should match the opposite of isInverted.
146
+ var isInserted = !isInverted;
140
147
  if (change.inserted.length > 0) {
141
- decorations.push(createInlineChangedDecoration({
148
+ decorations.push(createInlineChangedDecoration(_objectSpread({
142
149
  change: change,
143
150
  colorScheme: colorScheme,
144
151
  isActive: isActive
145
- }));
146
- decorations.push.apply(decorations, _toConsumableArray(calculateNodesForBlockDecoration({
152
+ }, expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) && {
153
+ isInserted: isInserted
154
+ })));
155
+ decorations.push.apply(decorations, _toConsumableArray(calculateNodesForBlockDecoration(_objectSpread({
147
156
  doc: tr.doc,
148
157
  from: change.fromB,
149
158
  to: change.toB,
150
159
  colorScheme: colorScheme
151
- })));
160
+ }, expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) && {
161
+ isInserted: isInserted
162
+ }))));
152
163
  }
153
164
  if (change.deleted.length > 0) {
154
165
  var _isActive = activeIndexPos && change.fromB >= activeIndexPos.from && change.toB <= activeIndexPos.to;
155
- var decoration = createNodeChangedDecorationWidget({
166
+ var decoration = createNodeChangedDecorationWidget(_objectSpread({
156
167
  change: change,
157
168
  doc: originalDoc,
158
169
  nodeViewSerializer: nodeViewSerializer,
@@ -160,7 +171,9 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref2
160
171
  newDoc: tr.doc,
161
172
  intl: intl,
162
173
  isActive: _isActive
163
- });
174
+ }, expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) && {
175
+ isInserted: !isInserted
176
+ }));
164
177
  if (decoration) {
165
178
  decorations.push.apply(decorations, _toConsumableArray(decoration));
166
179
  }
@@ -171,7 +184,8 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref2
171
184
  decorations.push(createInlineChangedDecoration({
172
185
  change: change,
173
186
  colorScheme: colorScheme,
174
- isActive: isActive
187
+ isActive: isActive,
188
+ isInserted: true
175
189
  }));
176
190
  });
177
191
  getAttrChangeRanges(tr.doc, attrSteps).forEach(function (change) {
@@ -179,7 +193,8 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref2
179
193
  doc: tr.doc,
180
194
  from: change.fromB,
181
195
  to: change.toB,
182
- colorScheme: colorScheme
196
+ colorScheme: colorScheme,
197
+ isInserted: true
183
198
  })));
184
199
  });
185
200
  return DecorationSet.empty.add(tr.doc, decorations);
@@ -187,21 +202,27 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref2
187
202
  export var calculateDiffDecorations = memoizeOne(calculateDiffDecorationsInner,
188
203
  // Cache results unless relevant inputs change
189
204
  function (_ref3, _ref4) {
190
- var _ref7;
205
+ var _ref8;
191
206
  var _ref5 = _slicedToArray(_ref3, 1),
192
207
  _ref5$ = _ref5[0],
193
208
  pluginState = _ref5$.pluginState,
194
209
  state = _ref5$.state,
195
210
  colorScheme = _ref5$.colorScheme,
196
211
  intl = _ref5$.intl,
197
- activeIndexPos = _ref5$.activeIndexPos;
212
+ activeIndexPos = _ref5$.activeIndexPos,
213
+ isInverted = _ref5$.isInverted;
198
214
  var _ref6 = _slicedToArray(_ref4, 1),
199
215
  _ref6$ = _ref6[0],
200
216
  lastPluginState = _ref6$.pluginState,
201
217
  lastState = _ref6$.state,
202
218
  lastColorScheme = _ref6$.colorScheme,
203
219
  lastIntl = _ref6$.intl,
204
- lastActiveIndexPos = _ref6$.activeIndexPos;
220
+ lastActiveIndexPos = _ref6$.activeIndexPos,
221
+ lastIsInverted = _ref6$.isInverted;
205
222
  var originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
206
- return (_ref7 = originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isEqual(activeIndexPos, lastActiveIndexPos)) !== null && _ref7 !== void 0 ? _ref7 : false;
223
+ if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
224
+ var _ref7;
225
+ return (_ref7 = colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isInverted === lastIsInverted && isEqual(activeIndexPos, lastActiveIndexPos) && originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc)) !== null && _ref7 !== void 0 ? _ref7 : false;
226
+ }
227
+ return (_ref8 = originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isEqual(activeIndexPos, lastActiveIndexPos)) !== null && _ref8 !== void 0 ? _ref8 : false;
207
228
  });
@@ -89,4 +89,26 @@ export var editingStyleCardBlockNode = convertToInlineCss({
89
89
  });
90
90
  export var standardDecorationMarkerVariable = convertToInlineCss({
91
91
  '--diff-decoration-marker-color': "var(--ds-border-accent-purple, #AF59E1)"
92
+ });
93
+ export var addedCellOverlayStyle = convertToInlineCss({
94
+ position: 'absolute',
95
+ top: 0,
96
+ left: 0,
97
+ width: '100%',
98
+ height: '100%',
99
+ backgroundColor: "rgba(from ".concat("var(--ds-background-accent-purple-subtlest, #F8EEFE)", " r g b / 0.5)"),
100
+ zIndex: 1,
101
+ outline: "1px solid ".concat("var(--ds-border-accent-purple, #AF59E1)"),
102
+ pointerEvents: 'none'
103
+ });
104
+ export var deletedCellOverlayStyle = convertToInlineCss({
105
+ position: 'absolute',
106
+ top: 0,
107
+ left: 0,
108
+ width: '100%',
109
+ height: '100%',
110
+ backgroundColor: "rgba(from ".concat("var(--ds-background-accent-gray-subtlest, #F0F1F2)", " r g b / 0.5)"),
111
+ zIndex: 1,
112
+ outline: "1px solid ".concat("var(--ds-border-accent-gray, #7D818A)"),
113
+ pointerEvents: 'none'
92
114
  });
@@ -66,4 +66,26 @@ export var traditionalStyleCardBlockNode = convertToInlineCss({
66
66
  });
67
67
  export var traditionalDecorationMarkerVariable = convertToInlineCss({
68
68
  '--diff-decoration-marker-color': "var(--ds-border-accent-green, #22A06B)"
69
+ });
70
+ export var traditionalAddedCellOverlayStyle = convertToInlineCss({
71
+ position: 'absolute',
72
+ top: 0,
73
+ left: 0,
74
+ width: '100%',
75
+ height: '100%',
76
+ backgroundColor: "rgba(from ".concat("var(--ds-background-accent-green-subtlest, #DCFFF1)", " r g b / 0.5)"),
77
+ zIndex: 1,
78
+ outline: "1px solid ".concat("var(--ds-border-accent-green, #22A06B)"),
79
+ pointerEvents: 'none'
80
+ });
81
+ export var deletedTraditionalCellOverlayStyle = convertToInlineCss({
82
+ position: 'absolute',
83
+ top: 0,
84
+ left: 0,
85
+ width: '100%',
86
+ height: '100%',
87
+ backgroundColor: "rgba(from ".concat("var(--ds-background-accent-gray-subtlest, #F0F1F2)", " r g b / 0.5)"),
88
+ zIndex: 1,
89
+ outline: "1px solid ".concat("var(--ds-border-disabled, #0515240F)"),
90
+ pointerEvents: 'none'
69
91
  });
@@ -1,7 +1,8 @@
1
1
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
2
2
  import { fg } from '@atlaskit/platform-feature-flags';
3
- import { standardDecorationMarkerVariable, editingStyleQuoteNode, editingStyleRuleNode, editingStyleCardBlockNode, editingStyleNode } from './colorSchemes/standard';
4
- import { traditionalDecorationMarkerVariable, traditionalStyleQuoteNode, traditionalStyleRuleNode, traditionalStyleCardBlockNode, traditionalStyleNode } from './colorSchemes/traditional';
3
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
+ import { standardDecorationMarkerVariable, editingStyleQuoteNode, editingStyleRuleNode, editingStyleCardBlockNode, editingStyleNode, deletedContentStyleNew, deletedStyleQuoteNode } from './colorSchemes/standard';
5
+ import { traditionalDecorationMarkerVariable, traditionalStyleQuoteNode, traditionalStyleRuleNode, traditionalStyleCardBlockNode, traditionalStyleNode, deletedTraditionalContentStyle, deletedTraditionalStyleQuoteNode } from './colorSchemes/traditional';
5
6
  var getNodeClass = function getNodeClass(name) {
6
7
  switch (name) {
7
8
  case 'extension':
@@ -10,7 +11,11 @@ var getNodeClass = function getNodeClass(name) {
10
11
  return undefined;
11
12
  }
12
13
  };
13
- var getBlockNodeStyle = function getBlockNodeStyle(nodeName, colorScheme) {
14
+ var getBlockNodeStyle = function getBlockNodeStyle(_ref) {
15
+ var nodeName = _ref.nodeName,
16
+ colorScheme = _ref.colorScheme,
17
+ _ref$isInserted = _ref.isInserted,
18
+ isInserted = _ref$isInserted === void 0 ? true : _ref$isInserted;
14
19
  var isTraditional = colorScheme === 'traditional';
15
20
  if (['mediaSingle', 'mediaGroup', 'table',
16
21
  // Handle table separately to avoid border issues
@@ -21,17 +26,52 @@ var getBlockNodeStyle = function getBlockNodeStyle(nodeName, colorScheme) {
21
26
  return undefined;
22
27
  }
23
28
  if (['extension', 'embedCard', 'listItem'].includes(nodeName)) {
29
+ if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
30
+ if (isInserted) {
31
+ return isTraditional ? traditionalDecorationMarkerVariable : standardDecorationMarkerVariable;
32
+ } else {
33
+ return isTraditional ? deletedTraditionalContentStyle : deletedContentStyleNew;
34
+ }
35
+ }
24
36
  return isTraditional ? traditionalDecorationMarkerVariable : standardDecorationMarkerVariable;
25
37
  }
26
38
  if (nodeName === 'blockquote') {
39
+ if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
40
+ if (isInserted) {
41
+ return isTraditional ? traditionalStyleQuoteNode : editingStyleQuoteNode;
42
+ } else {
43
+ return isTraditional ? deletedTraditionalStyleQuoteNode : deletedStyleQuoteNode;
44
+ }
45
+ }
27
46
  return isTraditional ? traditionalStyleQuoteNode : editingStyleQuoteNode;
28
47
  }
29
48
  if (nodeName === 'rule') {
49
+ if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
50
+ if (isInserted) {
51
+ return isTraditional ? traditionalStyleRuleNode : editingStyleRuleNode;
52
+ } else {
53
+ return isTraditional ? deletedTraditionalContentStyle : deletedContentStyleNew;
54
+ }
55
+ }
30
56
  return isTraditional ? traditionalStyleRuleNode : editingStyleRuleNode;
31
57
  }
32
58
  if (nodeName === 'blockCard') {
59
+ if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
60
+ if (isInserted) {
61
+ return isTraditional ? traditionalStyleCardBlockNode : editingStyleCardBlockNode;
62
+ } else {
63
+ return isTraditional ? deletedTraditionalContentStyle : deletedContentStyleNew;
64
+ }
65
+ }
33
66
  return isTraditional ? traditionalStyleCardBlockNode : editingStyleCardBlockNode;
34
67
  }
68
+ if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
69
+ if (isInserted) {
70
+ return isTraditional ? traditionalStyleNode : editingStyleNode;
71
+ } else {
72
+ return isTraditional ? deletedTraditionalContentStyle : deletedContentStyleNew;
73
+ }
74
+ }
35
75
  return isTraditional ? traditionalStyleNode : editingStyleNode;
36
76
  };
37
77
 
@@ -41,12 +81,24 @@ var getBlockNodeStyle = function getBlockNodeStyle(nodeName, colorScheme) {
41
81
  * @param change Changeset "change" containing information about the change content + range
42
82
  * @returns Prosemirror inline decoration
43
83
  */
44
- export var createBlockChangedDecoration = function createBlockChangedDecoration(_ref) {
45
- var change = _ref.change,
46
- colorScheme = _ref.colorScheme;
84
+ export var createBlockChangedDecoration = function createBlockChangedDecoration(_ref2) {
85
+ var change = _ref2.change,
86
+ colorScheme = _ref2.colorScheme,
87
+ _ref2$isInserted = _ref2.isInserted,
88
+ isInserted = _ref2$isInserted === void 0 ? true : _ref2$isInserted;
89
+ var style = getBlockNodeStyle({
90
+ nodeName: change.name,
91
+ colorScheme: colorScheme
92
+ });
93
+ if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
94
+ style = getBlockNodeStyle({
95
+ nodeName: change.name,
96
+ colorScheme: colorScheme,
97
+ isInserted: isInserted
98
+ });
99
+ }
100
+ var className = getNodeClass(change.name);
47
101
  if (fg('platform_editor_show_diff_scroll_navigation')) {
48
- var style = getBlockNodeStyle(change.name, colorScheme);
49
- var className = getNodeClass(change.name);
50
102
  if (style || className) {
51
103
  return Decoration.node(change.from, change.to, {
52
104
  style: style,
@@ -59,9 +111,9 @@ export var createBlockChangedDecoration = function createBlockChangedDecoration(
59
111
  return undefined;
60
112
  } else {
61
113
  return Decoration.node(change.from, change.to, {
62
- style: getBlockNodeStyle(change.name, colorScheme),
114
+ style: style,
63
115
  'data-testid': 'show-diff-changed-decoration-node',
64
- class: getNodeClass(change.name)
116
+ class: className
65
117
  }, {
66
118
  key: 'diff-block'
67
119
  });
@@ -6,8 +6,9 @@ import { areNodesEqualIgnoreAttrs } from '@atlaskit/editor-common/utils/document
6
6
  import { findParentNodeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
7
7
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
8
8
  import { TableMap } from '@atlaskit/editor-tables/table-map';
9
- import { deletedRowStyle } from './colorSchemes/standard';
10
- import { deletedTraditionalRowStyle } from './colorSchemes/traditional';
9
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
10
+ import { addedCellOverlayStyle, deletedRowStyle, deletedCellOverlayStyle } from './colorSchemes/standard';
11
+ import { deletedTraditionalRowStyle, deletedTraditionalCellOverlayStyle, traditionalAddedCellOverlayStyle } from './colorSchemes/traditional';
11
12
  import { findSafeInsertPos } from './utils/findSafeInsertPos';
12
13
  /**
13
14
  * Extracts information about deleted table rows from a change
@@ -108,9 +109,15 @@ var isEmptyRow = function isEmptyRow(rowNode) {
108
109
  /**
109
110
  * Creates a DOM representation of a deleted table row
110
111
  */
111
- var createChangedRowDOM = function createChangedRowDOM(rowNode, nodeViewSerializer, colorScheme) {
112
+ var createChangedRowDOM = function createChangedRowDOM(rowNode, nodeViewSerializer, colorScheme, isInserted) {
112
113
  var tr = document.createElement('tr');
113
- tr.setAttribute('style', colorScheme === 'traditional' ? deletedTraditionalRowStyle : deletedRowStyle);
114
+ if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
115
+ if (!isInserted) {
116
+ tr.setAttribute('style', colorScheme === 'traditional' ? deletedTraditionalRowStyle : deletedRowStyle);
117
+ }
118
+ } else {
119
+ tr.setAttribute('style', colorScheme === 'traditional' ? deletedTraditionalRowStyle : deletedRowStyle);
120
+ }
114
121
  tr.setAttribute('data-testid', 'show-diff-deleted-row');
115
122
 
116
123
  // Serialize each cell in the row
@@ -118,6 +125,12 @@ var createChangedRowDOM = function createChangedRowDOM(rowNode, nodeViewSerializ
118
125
  if (cellNode.type.name === 'tableCell' || cellNode.type.name === 'tableHeader') {
119
126
  var nodeView = nodeViewSerializer.tryCreateNodeView(cellNode);
120
127
  if (nodeView) {
128
+ if (isInserted && nodeView instanceof HTMLElement && expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
129
+ var overlay = document.createElement('span');
130
+ var overlayStyle = colorScheme === 'traditional' ? isInserted ? traditionalAddedCellOverlayStyle : deletedTraditionalCellOverlayStyle : isInserted ? addedCellOverlayStyle : deletedCellOverlayStyle;
131
+ overlay.setAttribute('style', overlayStyle);
132
+ nodeView.appendChild(overlay);
133
+ }
121
134
  tr.appendChild(nodeView);
122
135
  } else {
123
136
  // Fallback to fragment serialization
@@ -163,13 +176,15 @@ export var createChangedRowDecorationWidgets = function createChangedRowDecorati
163
176
  originalDoc = _ref.originalDoc,
164
177
  newDoc = _ref.newDoc,
165
178
  nodeViewSerializer = _ref.nodeViewSerializer,
166
- colorScheme = _ref.colorScheme;
179
+ colorScheme = _ref.colorScheme,
180
+ _ref$isInserted = _ref.isInserted,
181
+ isInserted = _ref$isInserted === void 0 ? false : _ref$isInserted;
167
182
  // First, expand the changes to include complete deleted rows
168
183
  var changedRows = expandDiffForChangedRows(changes.filter(function (change) {
169
184
  return change.deleted.length > 0;
170
185
  }), originalDoc, newDoc);
171
186
  return changedRows.map(function (changedRow) {
172
- var rowDOM = createChangedRowDOM(changedRow.rowNode, nodeViewSerializer, colorScheme);
187
+ var rowDOM = createChangedRowDOM(changedRow.rowNode, nodeViewSerializer, colorScheme, isInserted);
173
188
 
174
189
  // Find safe insertion position for the deleted row
175
190
  var safeInsertPos = findSafeInsertPos(newDoc, changedRow.fromB - 1,
@@ -1,6 +1,7 @@
1
1
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
2
- import { editingStyle, editingStyleActive } from './colorSchemes/standard';
3
- import { traditionalInsertStyle, traditionalInsertStyleActive } from './colorSchemes/traditional';
2
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
3
+ import { editingStyle, editingStyleActive, deletedContentStyle, deletedContentStyleActive } from './colorSchemes/standard';
4
+ import { traditionalInsertStyle, traditionalInsertStyleActive, deletedTraditionalContentStyle } from './colorSchemes/traditional';
4
5
 
5
6
  /**
6
7
  * Inline decoration used for insertions as the content already exists in the document
@@ -8,16 +9,35 @@ import { traditionalInsertStyle, traditionalInsertStyleActive } from './colorSch
8
9
  * @param change Changeset "change" containing information about the change content + range
9
10
  * @returns Prosemirror inline decoration
10
11
  */
12
+
11
13
  export var createInlineChangedDecoration = function createInlineChangedDecoration(_ref) {
12
14
  var change = _ref.change,
13
15
  colorScheme = _ref.colorScheme,
14
16
  _ref$isActive = _ref.isActive,
15
- isActive = _ref$isActive === void 0 ? false : _ref$isActive;
17
+ isActive = _ref$isActive === void 0 ? false : _ref$isActive,
18
+ _ref$isInserted = _ref.isInserted,
19
+ isInserted = _ref$isInserted === void 0 ? true : _ref$isInserted;
16
20
  var style;
17
- if (colorScheme === 'traditional') {
18
- style = isActive ? traditionalInsertStyleActive : traditionalInsertStyle;
21
+ if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
22
+ if (isInserted) {
23
+ if (colorScheme === 'traditional') {
24
+ style = isActive ? traditionalInsertStyleActive : traditionalInsertStyle;
25
+ } else {
26
+ style = isActive ? editingStyleActive : editingStyle;
27
+ }
28
+ } else {
29
+ if (colorScheme === 'traditional') {
30
+ style = deletedTraditionalContentStyle;
31
+ } else {
32
+ style = isActive ? deletedContentStyleActive : deletedContentStyle;
33
+ }
34
+ }
19
35
  } else {
20
- style = isActive ? editingStyleActive : editingStyle;
36
+ if (colorScheme === 'traditional') {
37
+ style = isActive ? traditionalInsertStyleActive : traditionalInsertStyle;
38
+ } else {
39
+ style = isActive ? editingStyleActive : editingStyle;
40
+ }
21
41
  }
22
42
  return Decoration.inline(change.fromB, change.toB, {
23
43
  style: style,
@@ -1,14 +1,28 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
2
3
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
4
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
- import { deletedContentStyle, deletedContentStyleActive, deletedContentStyleNew, deletedContentStyleNewActive, deletedContentStyleUnbounded } from './colorSchemes/standard';
5
- import { deletedTraditionalContentStyle, deletedTraditionalContentStyleUnbounded } from './colorSchemes/traditional';
5
+ import { editingStyle, editingStyleActive, deletedContentStyle, deletedContentStyleActive, deletedContentStyleNew, deletedContentStyleNewActive, deletedContentStyleUnbounded } from './colorSchemes/standard';
6
+ import { traditionalInsertStyle, traditionalInsertStyleActive, deletedTraditionalContentStyle, deletedTraditionalContentStyleUnbounded } from './colorSchemes/traditional';
6
7
  import { createChangedRowDecorationWidgets } from './createChangedRowDecorationWidgets';
7
8
  import { findSafeInsertPos } from './utils/findSafeInsertPos';
8
9
  import { wrapBlockNodeView } from './utils/wrapBlockNodeView';
9
10
  var getDeletedContentStyleUnbounded = function getDeletedContentStyleUnbounded(colorScheme) {
10
11
  return colorScheme === 'traditional' ? deletedTraditionalContentStyleUnbounded : deletedContentStyleUnbounded;
11
12
  };
13
+ var getInsertedContentStyle = function getInsertedContentStyle(colorScheme) {
14
+ var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
15
+ if (colorScheme === 'traditional') {
16
+ if (isActive) {
17
+ return traditionalInsertStyleActive;
18
+ }
19
+ return traditionalInsertStyle;
20
+ }
21
+ if (isActive) {
22
+ return editingStyleActive;
23
+ }
24
+ return editingStyle;
25
+ };
12
26
  var getDeletedContentStyle = function getDeletedContentStyle(colorScheme) {
13
27
  var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
14
28
  if (colorScheme === 'traditional') {
@@ -28,28 +42,66 @@ var createDeletedStyleWrapperWithoutOpacity = function createDeletedStyleWrapper
28
42
  wrapper.setAttribute('style', getDeletedContentStyle(colorScheme, isActive));
29
43
  return wrapper;
30
44
  };
45
+
46
+ /**
47
+ * CSS backgrounds don't work when applied to a wrapper around a paragraph, so
48
+ * the wrapper needs to be injected inside the node around the child content
49
+ */
50
+ var injectInnerWrapper = function injectInnerWrapper(_ref) {
51
+ var node = _ref.node,
52
+ colorScheme = _ref.colorScheme,
53
+ isActive = _ref.isActive,
54
+ isInserted = _ref.isInserted;
55
+ var wrapper = document.createElement('span');
56
+ wrapper.setAttribute('style', isInserted ? getInsertedContentStyle(colorScheme, isActive) : getDeletedContentStyle(colorScheme, isActive));
57
+ _toConsumableArray(node.childNodes).forEach(function (child) {
58
+ var removedChild = node.removeChild(child);
59
+ wrapper.append(removedChild);
60
+ });
61
+ node.appendChild(wrapper);
62
+ return node;
63
+ };
31
64
  var createContentWrapper = function createContentWrapper(colorScheme) {
32
65
  var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
66
+ var isInserted = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
33
67
  var wrapper = document.createElement('span');
34
68
  var baseStyle = convertToInlineCss({
35
69
  position: 'relative',
36
70
  width: 'fit-content'
37
71
  });
38
- wrapper.setAttribute('style', "".concat(baseStyle).concat(getDeletedContentStyle(colorScheme, isActive)));
39
- var strikethrough = document.createElement('span');
40
- strikethrough.setAttribute('style', getDeletedContentStyleUnbounded(colorScheme));
41
- wrapper.append(strikethrough);
72
+ if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
73
+ if (isInserted) {
74
+ wrapper.setAttribute('style', "".concat(baseStyle).concat(getInsertedContentStyle(colorScheme, isActive)));
75
+ } else {
76
+ wrapper.setAttribute('style', "".concat(baseStyle).concat(getDeletedContentStyle(colorScheme, isActive)));
77
+ var strikethrough = document.createElement('span');
78
+ strikethrough.setAttribute('style', getDeletedContentStyleUnbounded(colorScheme));
79
+ wrapper.append(strikethrough);
80
+ }
81
+ } else {
82
+ wrapper.setAttribute('style', "".concat(baseStyle).concat(getDeletedContentStyle(colorScheme, isActive)));
83
+ var _strikethrough = document.createElement('span');
84
+ _strikethrough.setAttribute('style', getDeletedContentStyleUnbounded(colorScheme));
85
+ wrapper.append(_strikethrough);
86
+ }
42
87
  return wrapper;
43
88
  };
44
- export var createNodeChangedDecorationWidget = function createNodeChangedDecorationWidget(_ref) {
45
- var change = _ref.change,
46
- doc = _ref.doc,
47
- nodeViewSerializer = _ref.nodeViewSerializer,
48
- colorScheme = _ref.colorScheme,
49
- newDoc = _ref.newDoc,
50
- intl = _ref.intl,
51
- _ref$isActive = _ref.isActive,
52
- isActive = _ref$isActive === void 0 ? false : _ref$isActive;
89
+
90
+ /**
91
+ * This function is used to create a decoration widget to show content
92
+ * that is not in the current document.
93
+ */
94
+ export var createNodeChangedDecorationWidget = function createNodeChangedDecorationWidget(_ref2) {
95
+ var change = _ref2.change,
96
+ doc = _ref2.doc,
97
+ nodeViewSerializer = _ref2.nodeViewSerializer,
98
+ colorScheme = _ref2.colorScheme,
99
+ newDoc = _ref2.newDoc,
100
+ intl = _ref2.intl,
101
+ _ref2$isActive = _ref2.isActive,
102
+ isActive = _ref2$isActive === void 0 ? false : _ref2$isActive,
103
+ _ref2$isInserted = _ref2.isInserted,
104
+ isInserted = _ref2$isInserted === void 0 ? false : _ref2$isInserted;
53
105
  var slice = doc.slice(change.fromA, change.toA);
54
106
  if (slice.content.content.length === 0) {
55
107
  return;
@@ -73,7 +125,8 @@ export var createNodeChangedDecorationWidget = function createNodeChangedDecorat
73
125
  originalDoc: doc,
74
126
  newDoc: newDoc,
75
127
  nodeViewSerializer: nodeViewSerializer,
76
- colorScheme: colorScheme
128
+ colorScheme: colorScheme,
129
+ isInserted: isInserted
77
130
  });
78
131
  }
79
132
  var serializer = nodeViewSerializer;
@@ -95,14 +148,14 @@ export var createNodeChangedDecorationWidget = function createNodeChangedDecorat
95
148
  if (childNodeView) {
96
149
  var lineBreak = document.createElement('br');
97
150
  dom.append(lineBreak);
98
- var wrapper = createContentWrapper(colorScheme, isActive);
151
+ var wrapper = createContentWrapper(colorScheme, isActive, isInserted);
99
152
  wrapper.append(childNodeView);
100
153
  dom.append(wrapper);
101
154
  } else {
102
155
  // Fallback to serializing the individual child node
103
156
  var serializedChild = serializer.serializeNode(childNode);
104
157
  if (serializedChild) {
105
- var _wrapper = createContentWrapper(colorScheme, isActive);
158
+ var _wrapper = createContentWrapper(colorScheme, isActive, isInserted);
106
159
  _wrapper.append(serializedChild);
107
160
  dom.append(_wrapper);
108
161
  }
@@ -147,7 +200,7 @@ export var createNodeChangedDecorationWidget = function createNodeChangedDecorat
147
200
  var nodeView = serializer.tryCreateNodeView(node);
148
201
  if (nodeView) {
149
202
  if (node.isInline) {
150
- var wrapper = createContentWrapper(colorScheme, isActive);
203
+ var wrapper = createContentWrapper(colorScheme, isActive, isInserted);
151
204
  wrapper.append(nodeView);
152
205
  dom.append(wrapper);
153
206
  } else {
@@ -157,7 +210,8 @@ export var createNodeChangedDecorationWidget = function createNodeChangedDecorat
157
210
  nodeView: nodeView,
158
211
  targetNode: node,
159
212
  colorScheme: colorScheme,
160
- intl: intl
213
+ intl: intl,
214
+ isInserted: isInserted
161
215
  });
162
216
  }
163
217
  } else if (nodeViewSerializer.getFilteredNodeViewBlocklist(['paragraph', 'tableRow']).has(node.type.name)) {
@@ -166,9 +220,25 @@ export var createNodeChangedDecorationWidget = function createNodeChangedDecorat
166
220
  } else {
167
221
  var fallbackNode = fallbackSerialization();
168
222
  if (fallbackNode) {
169
- var _wrapper2 = createDeletedStyleWrapperWithoutOpacity(colorScheme, isActive);
170
- _wrapper2.append(fallbackNode);
171
- dom.append(_wrapper2);
223
+ if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
224
+ if (fallbackNode instanceof HTMLElement) {
225
+ var injectedNode = injectInnerWrapper({
226
+ node: fallbackNode,
227
+ colorScheme: colorScheme,
228
+ isActive: isActive,
229
+ isInserted: isInserted
230
+ });
231
+ dom.append(injectedNode);
232
+ } else {
233
+ var _wrapper2 = createContentWrapper(colorScheme, isActive, isInserted);
234
+ _wrapper2.append(fallbackNode);
235
+ dom.append(_wrapper2);
236
+ }
237
+ } else {
238
+ var _wrapper3 = createDeletedStyleWrapperWithoutOpacity(colorScheme, isActive);
239
+ _wrapper3.append(fallbackNode);
240
+ dom.append(_wrapper3);
241
+ }
172
242
  }
173
243
  }
174
244
  });
@@ -2,10 +2,6 @@ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol
2
2
  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; } }
3
3
  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; }
4
4
  import { AddMarkStep, RemoveMarkStep } from '@atlaskit/editor-prosemirror/transform';
5
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
6
- var filterUndefined = function filterUndefined(x) {
7
- return !!x;
8
- };
9
5
  var extractMarkStep = function extractMarkStep(step) {
10
6
  if (step instanceof AddMarkStep) {
11
7
  return {
@@ -26,17 +22,6 @@ var extractMarkStep = function extractMarkStep(step) {
26
22
  return undefined;
27
23
  };
28
24
  export var getMarkChangeRanges = function getMarkChangeRanges(steps) {
29
- if (!expValEquals('platform_editor_deduplicate_mark_diff', 'isEnabled', true)) {
30
- return steps.map(function (step) {
31
- if (step instanceof AddMarkStep || step instanceof RemoveMarkStep) {
32
- return {
33
- fromB: step.from,
34
- toB: step.to
35
- };
36
- }
37
- return undefined;
38
- }).filter(filterUndefined);
39
- }
40
25
  var resultRanges = [];
41
26
  var lastOp;
42
27
  var _iterator = _createForOfIteratorHelper(steps),