@atlaskit/editor-plugin-show-diff 5.0.5 → 5.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/pm-plugins/calculateDiffDecorations.js +12 -10
  3. package/dist/cjs/pm-plugins/decorations/createBlockChangedDecoration.js +75 -0
  4. package/dist/cjs/pm-plugins/{deletedRowsHandler.js → decorations/createChangedRowDecorationWidgets.js} +31 -52
  5. package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +33 -0
  6. package/dist/cjs/pm-plugins/{decorations.js → decorations/createNodeChangedDecorationWidget.js} +29 -114
  7. package/dist/cjs/pm-plugins/{attributeDecorations.js → decorations/utils/getAttrChangeRanges.js} +1 -1
  8. package/dist/cjs/pm-plugins/{deletedBlocksHandler.js → decorations/utils/wrapBlockNodeView.js} +83 -21
  9. package/dist/es2019/pm-plugins/calculateDiffDecorations.js +6 -4
  10. package/dist/es2019/pm-plugins/decorations/createBlockChangedDecoration.js +70 -0
  11. package/dist/es2019/pm-plugins/{deletedRowsHandler.js → decorations/createChangedRowDecorationWidgets.js} +28 -50
  12. package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +28 -0
  13. package/dist/es2019/pm-plugins/{decorations.js → decorations/createNodeChangedDecorationWidget.js} +16 -103
  14. package/dist/es2019/pm-plugins/{attributeDecorations.js → decorations/utils/getAttrChangeRanges.js} +1 -1
  15. package/dist/es2019/pm-plugins/{deletedBlocksHandler.js → decorations/utils/wrapBlockNodeView.js} +85 -18
  16. package/dist/esm/pm-plugins/calculateDiffDecorations.js +6 -4
  17. package/dist/esm/pm-plugins/decorations/createBlockChangedDecoration.js +69 -0
  18. package/dist/esm/pm-plugins/{deletedRowsHandler.js → decorations/createChangedRowDecorationWidgets.js} +30 -51
  19. package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +28 -0
  20. package/dist/esm/pm-plugins/{decorations.js → decorations/createNodeChangedDecorationWidget.js} +30 -115
  21. package/dist/esm/pm-plugins/{attributeDecorations.js → decorations/utils/getAttrChangeRanges.js} +1 -1
  22. package/dist/esm/pm-plugins/{deletedBlocksHandler.js → decorations/utils/wrapBlockNodeView.js} +80 -18
  23. package/dist/types/pm-plugins/NodeViewSerializer.d.ts +1 -1
  24. package/dist/types/pm-plugins/calculateDiffDecorations.d.ts +2 -1
  25. package/dist/types/pm-plugins/decorations/createBlockChangedDecoration.d.ts +16 -0
  26. package/dist/types/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +17 -0
  27. package/dist/types/pm-plugins/decorations/createInlineChangedDecoration.d.ts +16 -0
  28. package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +15 -0
  29. package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +15 -0
  30. package/dist/types-ts4.5/pm-plugins/NodeViewSerializer.d.ts +1 -1
  31. package/dist/types-ts4.5/pm-plugins/calculateDiffDecorations.d.ts +2 -1
  32. package/dist/types-ts4.5/pm-plugins/decorations/createBlockChangedDecoration.d.ts +16 -0
  33. package/dist/types-ts4.5/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +17 -0
  34. package/dist/types-ts4.5/pm-plugins/decorations/createInlineChangedDecoration.d.ts +16 -0
  35. package/dist/types-ts4.5/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +15 -0
  36. package/dist/types-ts4.5/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +15 -0
  37. package/package.json +3 -3
  38. package/dist/types/pm-plugins/decorations.d.ts +0 -46
  39. package/dist/types/pm-plugins/deletedBlocksHandler.d.ts +0 -14
  40. package/dist/types/pm-plugins/deletedRowsHandler.d.ts +0 -36
  41. package/dist/types-ts4.5/pm-plugins/decorations.d.ts +0 -46
  42. package/dist/types-ts4.5/pm-plugins/deletedBlocksHandler.d.ts +0 -14
  43. package/dist/types-ts4.5/pm-plugins/deletedRowsHandler.d.ts +0 -36
  44. /package/dist/cjs/pm-plugins/{colorSchemes → decorations/colorSchemes}/standard.js +0 -0
  45. /package/dist/cjs/pm-plugins/{colorSchemes → decorations/colorSchemes}/traditional.js +0 -0
  46. /package/dist/cjs/pm-plugins/{findSafeInsertPos.js → decorations/utils/findSafeInsertPos.js} +0 -0
  47. /package/dist/cjs/pm-plugins/{markDecorations.js → decorations/utils/getMarkChangeRanges.js} +0 -0
  48. /package/dist/es2019/pm-plugins/{colorSchemes → decorations/colorSchemes}/standard.js +0 -0
  49. /package/dist/es2019/pm-plugins/{colorSchemes → decorations/colorSchemes}/traditional.js +0 -0
  50. /package/dist/es2019/pm-plugins/{findSafeInsertPos.js → decorations/utils/findSafeInsertPos.js} +0 -0
  51. /package/dist/es2019/pm-plugins/{markDecorations.js → decorations/utils/getMarkChangeRanges.js} +0 -0
  52. /package/dist/esm/pm-plugins/{colorSchemes → decorations/colorSchemes}/standard.js +0 -0
  53. /package/dist/esm/pm-plugins/{colorSchemes → decorations/colorSchemes}/traditional.js +0 -0
  54. /package/dist/esm/pm-plugins/{findSafeInsertPos.js → decorations/utils/findSafeInsertPos.js} +0 -0
  55. /package/dist/esm/pm-plugins/{markDecorations.js → decorations/utils/getMarkChangeRanges.js} +0 -0
  56. /package/dist/types/pm-plugins/{colorSchemes → decorations/colorSchemes}/standard.d.ts +0 -0
  57. /package/dist/types/pm-plugins/{colorSchemes → decorations/colorSchemes}/traditional.d.ts +0 -0
  58. /package/dist/types/pm-plugins/{findSafeInsertPos.d.ts → decorations/utils/findSafeInsertPos.d.ts} +0 -0
  59. /package/dist/types/pm-plugins/{attributeDecorations.d.ts → decorations/utils/getAttrChangeRanges.d.ts} +0 -0
  60. /package/dist/types/pm-plugins/{markDecorations.d.ts → decorations/utils/getMarkChangeRanges.d.ts} +0 -0
  61. /package/dist/types-ts4.5/pm-plugins/{colorSchemes → decorations/colorSchemes}/standard.d.ts +0 -0
  62. /package/dist/types-ts4.5/pm-plugins/{colorSchemes → decorations/colorSchemes}/traditional.d.ts +0 -0
  63. /package/dist/types-ts4.5/pm-plugins/{findSafeInsertPos.d.ts → decorations/utils/findSafeInsertPos.d.ts} +0 -0
  64. /package/dist/types-ts4.5/pm-plugins/{attributeDecorations.d.ts → decorations/utils/getAttrChangeRanges.d.ts} +0 -0
  65. /package/dist/types-ts4.5/pm-plugins/{markDecorations.d.ts → decorations/utils/getMarkChangeRanges.d.ts} +0 -0
@@ -1,9 +1,9 @@
1
1
  import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
2
2
  import { trackChangesMessages } from '@atlaskit/editor-common/messages';
3
3
  import { fg } from '@atlaskit/platform-feature-flags';
4
- import { deletedStyleQuoteNode, deletedStyleQuoteNodeWithLozenge, deletedBlockOutline, deletedBlockOutlineRounded } from './colorSchemes/standard';
5
- import { deletedTraditionalStyleQuoteNode, deletedTraditionalBlockOutline, deletedTraditionalBlockOutlineRounded } from './colorSchemes/traditional';
6
- import { getDeletedContentStyle } from './decorations';
4
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
5
+ import { deletedStyleQuoteNode, deletedStyleQuoteNodeWithLozenge, deletedBlockOutline, deletedBlockOutlineRounded, deletedContentStyle, deletedContentStyleActive, deletedContentStyleNew, deletedContentStyleNewActive } from '../colorSchemes/standard';
6
+ import { deletedTraditionalStyleQuoteNode, deletedTraditionalBlockOutline, deletedTraditionalBlockOutlineRounded, deletedTraditionalContentStyle } from '../colorSchemes/traditional';
7
7
  const lozengeStyle = convertToInlineCss({
8
8
  display: 'inline-flex',
9
9
  boxSizing: 'border-box',
@@ -20,7 +20,16 @@ const lozengeStyle = convertToInlineCss({
20
20
  whiteSpace: 'nowrap',
21
21
  color: "var(--ds-text-warning-inverse, #292A2E)"
22
22
  });
23
- export const getDeletedStyleNode = (nodeName, colorScheme) => {
23
+ const getDeletedContentStyle = (colorScheme, isActive = false) => {
24
+ if (colorScheme === 'traditional') {
25
+ return deletedTraditionalContentStyle;
26
+ }
27
+ if (isActive) {
28
+ return expValEquals('platform_editor_enghealth_a11y_jan_fixes', 'isEnabled', true) ? deletedContentStyleNewActive : deletedContentStyleActive;
29
+ }
30
+ return expValEquals('platform_editor_enghealth_a11y_jan_fixes', 'isEnabled', true) ? deletedContentStyleNew : deletedContentStyle;
31
+ };
32
+ const getDeletedStyleNode = (nodeName, colorScheme) => {
24
33
  const isTraditional = colorScheme === 'traditional';
25
34
  switch (nodeName) {
26
35
  case 'blockquote':
@@ -66,7 +75,7 @@ const shouldAddShowDiffDeletedNodeClass = nodeName => {
66
75
  * Checks if a node should apply deleted styles directly without wrapper
67
76
  * to preserve natural block-level margins
68
77
  */
69
- const shouldApplyDeletedStylesDirectly = nodeName => {
78
+ const shouldApplyStylesDirectly = nodeName => {
70
79
  return nodeName === 'heading' || nodeName === 'blockquote' && !fg('platform_editor_ai_aifc_patch_ga_blockers');
71
80
  };
72
81
 
@@ -119,9 +128,13 @@ const createBlockNodeWrapper = () => {
119
128
  };
120
129
 
121
130
  /**
122
- * Applies deleted styles directly to an HTML element by merging with existing styles
131
+ * Applies styles directly to an HTML element by merging with existing styles
123
132
  */
124
- const applyDeletedStylesToElement = (element, targetNode, colorScheme) => {
133
+ const applyStylesToElement = ({
134
+ element,
135
+ targetNode,
136
+ colorScheme
137
+ }) => {
125
138
  const currentStyle = element.getAttribute('style') || '';
126
139
  const deletedContentStyle = getDeletedContentStyle(colorScheme);
127
140
  const nodeSpecificStyle = getDeletedStyleNode(targetNode.type.name, colorScheme) || '';
@@ -131,7 +144,11 @@ const applyDeletedStylesToElement = (element, targetNode, colorScheme) => {
131
144
  /**
132
145
  * Creates a content wrapper with deleted styles for a block node
133
146
  */
134
- const createBlockNodeContentWrapper = (nodeView, targetNode, colorScheme) => {
147
+ const createBlockNodeContentWrapper = ({
148
+ nodeView,
149
+ targetNode,
150
+ colorScheme
151
+ }) => {
135
152
  const contentWrapper = document.createElement('div');
136
153
  const nodeStyle = getDeletedStyleNode(targetNode.type.name, colorScheme);
137
154
  contentWrapper.setAttribute('style', `${getDeletedContentStyle(colorScheme)}${nodeStyle || ''}`);
@@ -145,7 +162,13 @@ const createBlockNodeContentWrapper = (nodeView, targetNode, colorScheme) => {
145
162
  * to wait for the rich-media-item to appear before attaching the lozenge.
146
163
  * @returns true if embedCard was handled
147
164
  */
148
- const handleEmbedCardWithLozenge = (dom, nodeView, targetNode, lozenge, colorScheme) => {
165
+ const handleEmbedCardWithLozenge = ({
166
+ dom,
167
+ nodeView,
168
+ targetNode,
169
+ lozenge,
170
+ colorScheme
171
+ }) => {
149
172
  if (targetNode.type.name !== 'embedCard' || !(nodeView instanceof HTMLElement)) {
150
173
  return false;
151
174
  }
@@ -177,7 +200,13 @@ const handleEmbedCardWithLozenge = (dom, nodeView, targetNode, lozenge, colorSch
177
200
  * Handles special mediaSingle node rendering with lozenge on child media element
178
201
  * @returns true if mediaSingle was handled, false otherwise
179
202
  */
180
- export const handleMediaSingleWithLozenge = (dom, nodeView, targetNode, lozenge, colorScheme) => {
203
+ const handleMediaSingleWithLozenge = ({
204
+ dom,
205
+ nodeView,
206
+ targetNode,
207
+ lozenge,
208
+ colorScheme
209
+ }) => {
181
210
  if (targetNode.type.name !== 'mediaSingle' || !(nodeView instanceof HTMLElement)) {
182
211
  return false;
183
212
  }
@@ -206,19 +235,41 @@ export const handleMediaSingleWithLozenge = (dom, nodeView, targetNode, lozenge,
206
235
  /**
207
236
  * Appends a block node with wrapper, lozenge, and appropriate styling
208
237
  */
209
- const appendBlockNodeWithWrapper = (dom, nodeView, targetNode, colorScheme, intl) => {
238
+ const wrapBlockNode = ({
239
+ dom,
240
+ nodeView,
241
+ targetNode,
242
+ colorScheme,
243
+ intl
244
+ }) => {
210
245
  const blockWrapper = createBlockNodeWrapper();
211
246
  if (shouldShowRemovedLozenge(targetNode.type.name)) {
212
247
  const lozenge = createRemovedLozenge(intl);
213
- if (handleEmbedCardWithLozenge(dom, nodeView, targetNode, lozenge, colorScheme) && fg('platform_editor_ai_aifc_patch_ga_blockers')) {
248
+ if (handleEmbedCardWithLozenge({
249
+ dom,
250
+ nodeView,
251
+ targetNode,
252
+ lozenge,
253
+ colorScheme
254
+ }) && fg('platform_editor_ai_aifc_patch_ga_blockers')) {
214
255
  return;
215
256
  }
216
- if (handleMediaSingleWithLozenge(dom, nodeView, targetNode, lozenge, colorScheme)) {
257
+ if (handleMediaSingleWithLozenge({
258
+ dom,
259
+ nodeView,
260
+ targetNode,
261
+ lozenge,
262
+ colorScheme
263
+ })) {
217
264
  return;
218
265
  }
219
266
  blockWrapper.append(lozenge);
220
267
  }
221
- const contentWrapper = createBlockNodeContentWrapper(nodeView, targetNode, colorScheme);
268
+ const contentWrapper = createBlockNodeContentWrapper({
269
+ nodeView,
270
+ targetNode,
271
+ colorScheme
272
+ });
222
273
  blockWrapper.append(contentWrapper);
223
274
  if (nodeView instanceof HTMLElement && shouldAddShowDiffDeletedNodeClass(targetNode.type.name)) {
224
275
  const showDiffDeletedNodeClass = colorScheme === 'traditional' && fg('platform_editor_ai_aifc_patch_ga_blockers') ? 'show-diff-deleted-node-traditional' : 'show-diff-deleted-node';
@@ -232,13 +283,29 @@ const appendBlockNodeWithWrapper = (dom, nodeView, targetNode, colorScheme, intl
232
283
  * For heading nodes, applies styles directly to preserve natural margins.
233
284
  * For other block nodes, uses wrapper approach with optional lozenge.
234
285
  */
235
- export const handleBlockNodeView = (dom, nodeView, targetNode, colorScheme, intl) => {
236
- if (shouldApplyDeletedStylesDirectly(targetNode.type.name) && nodeView instanceof HTMLElement) {
286
+ export const wrapBlockNodeView = ({
287
+ dom,
288
+ nodeView,
289
+ targetNode,
290
+ colorScheme,
291
+ intl
292
+ }) => {
293
+ if (shouldApplyStylesDirectly(targetNode.type.name) && nodeView instanceof HTMLElement) {
237
294
  // Apply deleted styles directly to preserve natural block-level margins
238
- applyDeletedStylesToElement(nodeView, targetNode, colorScheme);
295
+ applyStylesToElement({
296
+ element: nodeView,
297
+ targetNode,
298
+ colorScheme
299
+ });
239
300
  dom.append(nodeView);
240
301
  } else {
241
302
  // Use wrapper approach for other block nodes
242
- appendBlockNodeWithWrapper(dom, nodeView, targetNode, colorScheme, intl);
303
+ wrapBlockNode({
304
+ dom,
305
+ nodeView,
306
+ targetNode,
307
+ colorScheme,
308
+ intl
309
+ });
243
310
  }
244
311
  };
@@ -12,9 +12,11 @@ import memoizeOne from 'memoize-one';
12
12
  import { ChangeSet, simplifyChanges } from 'prosemirror-changeset';
13
13
  import { areNodesEqualIgnoreAttrs } from '@atlaskit/editor-common/utils/document';
14
14
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
15
- import { getAttrChangeRanges, stepIsValidAttrChange } from './attributeDecorations';
16
- import { createInlineChangedDecoration, createDeletedContentDecoration, createBlockChangedDecoration } from './decorations';
17
- import { getMarkChangeRanges } from './markDecorations';
15
+ import { createBlockChangedDecoration } from './decorations/createBlockChangedDecoration';
16
+ import { createInlineChangedDecoration } from './decorations/createInlineChangedDecoration';
17
+ import { createNodeChangedDecorationWidget } from './decorations/createNodeChangedDecorationWidget';
18
+ import { getAttrChangeRanges, stepIsValidAttrChange } from './decorations/utils/getAttrChangeRanges';
19
+ import { getMarkChangeRanges } from './decorations/utils/getMarkChangeRanges';
18
20
  import { simplifySteps } from './simplifyChanges';
19
21
  var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration(_ref) {
20
22
  var doc = _ref.doc,
@@ -136,7 +138,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref2
136
138
  }
137
139
  if (change.deleted.length > 0) {
138
140
  var _isActive = activeIndexPos && change.fromB >= activeIndexPos.from && change.toB <= activeIndexPos.to;
139
- var decoration = createDeletedContentDecoration({
141
+ var decoration = createNodeChangedDecorationWidget({
140
142
  change: change,
141
143
  doc: originalDoc,
142
144
  nodeViewSerializer: nodeViewSerializer,
@@ -0,0 +1,69 @@
1
+ import { Decoration } from '@atlaskit/editor-prosemirror/view';
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';
5
+ var getNodeClass = function getNodeClass(name) {
6
+ switch (name) {
7
+ case 'extension':
8
+ return 'show-diff-changed-decoration-node';
9
+ default:
10
+ return undefined;
11
+ }
12
+ };
13
+ var getBlockNodeStyle = function getBlockNodeStyle(nodeName, colorScheme) {
14
+ var isTraditional = colorScheme === 'traditional';
15
+ if (['mediaSingle', 'mediaGroup', 'table',
16
+ // Handle table separately to avoid border issues
17
+ 'tableRow', 'tableCell', 'tableHeader', 'paragraph',
18
+ // Paragraph and heading nodes do not need special styling
19
+ 'heading', 'hardBreak', 'decisionList', 'taskList', 'taskItem', 'bulletList', 'orderedList', 'layoutSection'].includes(nodeName)) {
20
+ // Layout nodes do not need special styling
21
+ return undefined;
22
+ }
23
+ if (['extension', 'embedCard', 'listItem'].includes(nodeName)) {
24
+ return isTraditional ? traditionalDecorationMarkerVariable : standardDecorationMarkerVariable;
25
+ }
26
+ if (nodeName === 'blockquote') {
27
+ return isTraditional ? traditionalStyleQuoteNode : editingStyleQuoteNode;
28
+ }
29
+ if (nodeName === 'rule') {
30
+ return isTraditional ? traditionalStyleRuleNode : editingStyleRuleNode;
31
+ }
32
+ if (nodeName === 'blockCard') {
33
+ return isTraditional ? traditionalStyleCardBlockNode : editingStyleCardBlockNode;
34
+ }
35
+ return isTraditional ? traditionalStyleNode : editingStyleNode;
36
+ };
37
+
38
+ /**
39
+ * Inline decoration used for insertions as the content already exists in the document
40
+ *
41
+ * @param change Changeset "change" containing information about the change content + range
42
+ * @returns Prosemirror inline decoration
43
+ */
44
+ export var createBlockChangedDecoration = function createBlockChangedDecoration(_ref) {
45
+ var change = _ref.change,
46
+ colorScheme = _ref.colorScheme;
47
+ if (fg('platform_editor_show_diff_scroll_navigation')) {
48
+ var style = getBlockNodeStyle(change.name, colorScheme);
49
+ var className = getNodeClass(change.name);
50
+ if (style || className) {
51
+ return Decoration.node(change.from, change.to, {
52
+ style: style,
53
+ 'data-testid': 'show-diff-changed-decoration-node',
54
+ class: className
55
+ }, {
56
+ key: 'diff-block'
57
+ });
58
+ }
59
+ return undefined;
60
+ } else {
61
+ return Decoration.node(change.from, change.to, {
62
+ style: getBlockNodeStyle(change.name, colorScheme),
63
+ 'data-testid': 'show-diff-changed-decoration-node',
64
+ class: getNodeClass(change.name)
65
+ }, {
66
+ key: 'diff-block'
67
+ });
68
+ }
69
+ };
@@ -8,12 +8,12 @@ import { Decoration } from '@atlaskit/editor-prosemirror/view';
8
8
  import { TableMap } from '@atlaskit/editor-tables/table-map';
9
9
  import { deletedRowStyle } from './colorSchemes/standard';
10
10
  import { deletedTraditionalRowStyle } from './colorSchemes/traditional';
11
- import { findSafeInsertPos } from './findSafeInsertPos';
11
+ import { findSafeInsertPos } from './utils/findSafeInsertPos';
12
12
  /**
13
13
  * Extracts information about deleted table rows from a change
14
14
  */
15
- var extractDeletedRows = function extractDeletedRows(change, originalDoc, newDoc) {
16
- var deletedRows = [];
15
+ var extractChangedRows = function extractChangedRows(change, originalDoc, newDoc) {
16
+ var changedRows = [];
17
17
 
18
18
  // Find the table in the original document
19
19
  var $fromPos = originalDoc.resolve(change.fromA);
@@ -21,7 +21,7 @@ var extractDeletedRows = function extractDeletedRows(change, originalDoc, newDoc
21
21
  return node.type.name === 'table';
22
22
  });
23
23
  if (!tableOld) {
24
- return deletedRows;
24
+ return changedRows;
25
25
  }
26
26
  var oldTableMap = TableMap.get(tableOld.node);
27
27
 
@@ -31,18 +31,18 @@ var extractDeletedRows = function extractDeletedRows(change, originalDoc, newDoc
31
31
  return node.type.name === 'table';
32
32
  });
33
33
  if (!tableNew) {
34
- return deletedRows;
34
+ return changedRows;
35
35
  }
36
36
  var newTableMap = TableMap.get(tableNew.node);
37
37
 
38
- // If no rows were deleted, return empty
38
+ // If no rows were changed, return empty
39
39
  if (oldTableMap.height <= newTableMap.height ||
40
40
  // For now ignore if there are column deletions as well
41
41
  oldTableMap.width !== newTableMap.width) {
42
- return deletedRows;
42
+ return changedRows;
43
43
  }
44
44
 
45
- // Find which rows were deleted by analyzing the change range
45
+ // Find which rows were changed by analyzing the change range
46
46
  var changeStartInTable = change.fromA - tableOld.pos - 1;
47
47
  var changeEndInTable = change.toA - tableOld.pos - 1;
48
48
  var currentOffset = 0;
@@ -57,7 +57,7 @@ var extractDeletedRows = function extractDeletedRows(change, originalDoc, newDoc
57
57
  var startOfRow = newTableMap.mapByRow.slice().reverse().find(function (row) {
58
58
  return row[0] + tableNew.pos < change.fromB && change.fromB < row[row.length - 1] + tableNew.pos;
59
59
  });
60
- deletedRows.push({
60
+ changedRows.push({
61
61
  rowIndex: rowIndex,
62
62
  rowNode: rowNode,
63
63
  fromA: tableOld.pos + 1 + rowStart,
@@ -72,9 +72,9 @@ var extractDeletedRows = function extractDeletedRows(change, originalDoc, newDoc
72
72
  });
73
73
 
74
74
  // Filter changes that never truly got deleted
75
- return deletedRows.filter(function (deletedRow) {
75
+ return changedRows.filter(function (changedRow) {
76
76
  return !tableNew.node.children.some(function (newRow) {
77
- return areNodesEqualIgnoreAttrs(newRow, deletedRow.rowNode);
77
+ return areNodesEqualIgnoreAttrs(newRow, changedRow.rowNode);
78
78
  });
79
79
  });
80
80
  };
@@ -108,7 +108,7 @@ var isEmptyRow = function isEmptyRow(rowNode) {
108
108
  /**
109
109
  * Creates a DOM representation of a deleted table row
110
110
  */
111
- var createDeletedRowDOM = function createDeletedRowDOM(rowNode, nodeViewSerializer, colorScheme) {
111
+ var createChangedRowDOM = function createChangedRowDOM(rowNode, nodeViewSerializer, colorScheme) {
112
112
  var tr = document.createElement('tr');
113
113
  tr.setAttribute('style', colorScheme === 'traditional' ? deletedTraditionalRowStyle : deletedRowStyle);
114
114
  tr.setAttribute('data-testid', 'show-diff-deleted-row');
@@ -132,19 +132,19 @@ var createDeletedRowDOM = function createDeletedRowDOM(rowNode, nodeViewSerializ
132
132
  };
133
133
 
134
134
  /**
135
- * Expands a diff to include whole deleted rows when table rows are affected
135
+ * Expands a diff to include whole changed rows when table rows are affected
136
136
  */
137
- var expandDiffForDeletedRows = function expandDiffForDeletedRows(changes, originalDoc, newDoc) {
138
- var deletedRowInfo = [];
137
+ var expandDiffForChangedRows = function expandDiffForChangedRows(changes, originalDoc, newDoc) {
138
+ var rowInfo = [];
139
139
  var _iterator = _createForOfIteratorHelper(changes),
140
140
  _step;
141
141
  try {
142
142
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
143
143
  var change = _step.value;
144
144
  // Check if this change affects table content
145
- var deletedRows = extractDeletedRows(change, originalDoc, newDoc);
146
- if (deletedRows.length > 0) {
147
- deletedRowInfo.push.apply(deletedRowInfo, _toConsumableArray(deletedRows));
145
+ var changedRows = extractChangedRows(change, originalDoc, newDoc);
146
+ if (changedRows.length > 0) {
147
+ rowInfo.push.apply(rowInfo, _toConsumableArray(changedRows));
148
148
  }
149
149
  }
150
150
  } catch (err) {
@@ -152,50 +152,29 @@ var expandDiffForDeletedRows = function expandDiffForDeletedRows(changes, origin
152
152
  } finally {
153
153
  _iterator.f();
154
154
  }
155
- return deletedRowInfo;
155
+ return rowInfo;
156
156
  };
157
157
 
158
158
  /**
159
- * Creates decorations for deleted table rows
159
+ * Main function to handle deleted rows - computes diff and creates decorations
160
160
  */
161
- export var createDeletedRowsDecorations = function createDeletedRowsDecorations(_ref) {
162
- var deletedRows = _ref.deletedRows,
161
+ export var createChangedRowDecorationWidgets = function createChangedRowDecorationWidgets(_ref) {
162
+ var changes = _ref.changes,
163
163
  originalDoc = _ref.originalDoc,
164
164
  newDoc = _ref.newDoc,
165
165
  nodeViewSerializer = _ref.nodeViewSerializer,
166
166
  colorScheme = _ref.colorScheme;
167
- return deletedRows.map(function (deletedRow) {
168
- var rowDOM = createDeletedRowDOM(deletedRow.rowNode, nodeViewSerializer, colorScheme);
167
+ // First, expand the changes to include complete deleted rows
168
+ var changedRows = expandDiffForChangedRows(changes.filter(function (change) {
169
+ return change.deleted.length > 0;
170
+ }), originalDoc, newDoc);
171
+ return changedRows.map(function (changedRow) {
172
+ var rowDOM = createChangedRowDOM(changedRow.rowNode, nodeViewSerializer, colorScheme);
169
173
 
170
174
  // Find safe insertion position for the deleted row
171
- var safeInsertPos = findSafeInsertPos(newDoc, deletedRow.fromB - 1,
175
+ var safeInsertPos = findSafeInsertPos(newDoc, changedRow.fromB - 1,
172
176
  // -1 to find the first safe position from the table
173
- originalDoc.slice(deletedRow.fromA, deletedRow.toA));
177
+ originalDoc.slice(changedRow.fromA, changedRow.toA));
174
178
  return Decoration.widget(safeInsertPos, rowDOM, {});
175
179
  });
176
- };
177
-
178
- /**
179
- * Main function to handle deleted rows - computes diff and creates decorations
180
- */
181
- export var handleDeletedRows = function handleDeletedRows(_ref2) {
182
- var changes = _ref2.changes,
183
- originalDoc = _ref2.originalDoc,
184
- newDoc = _ref2.newDoc,
185
- nodeViewSerializer = _ref2.nodeViewSerializer,
186
- colorScheme = _ref2.colorScheme;
187
- // First, expand the changes to include complete deleted rows
188
- var deletedRows = expandDiffForDeletedRows(changes.filter(function (change) {
189
- return change.deleted.length > 0;
190
- }), originalDoc, newDoc);
191
- var allDecorations = createDeletedRowsDecorations({
192
- deletedRows: deletedRows,
193
- originalDoc: originalDoc,
194
- newDoc: newDoc,
195
- nodeViewSerializer: nodeViewSerializer,
196
- colorScheme: colorScheme
197
- });
198
- return {
199
- decorations: allDecorations
200
- };
201
180
  };
@@ -0,0 +1,28 @@
1
+ import { Decoration } from '@atlaskit/editor-prosemirror/view';
2
+ import { editingStyle, editingStyleActive } from './colorSchemes/standard';
3
+ import { traditionalInsertStyle, traditionalInsertStyleActive } from './colorSchemes/traditional';
4
+
5
+ /**
6
+ * Inline decoration used for insertions as the content already exists in the document
7
+ *
8
+ * @param change Changeset "change" containing information about the change content + range
9
+ * @returns Prosemirror inline decoration
10
+ */
11
+ export var createInlineChangedDecoration = function createInlineChangedDecoration(_ref) {
12
+ var change = _ref.change,
13
+ colorScheme = _ref.colorScheme,
14
+ _ref$isActive = _ref.isActive,
15
+ isActive = _ref$isActive === void 0 ? false : _ref$isActive;
16
+ var style;
17
+ if (colorScheme === 'traditional') {
18
+ style = isActive ? traditionalInsertStyleActive : traditionalInsertStyle;
19
+ } else {
20
+ style = isActive ? editingStyleActive : editingStyle;
21
+ }
22
+ return Decoration.inline(change.fromB, change.toB, {
23
+ style: style,
24
+ 'data-testid': 'show-diff-changed-decoration'
25
+ }, {
26
+ key: 'diff-inline'
27
+ });
28
+ };
@@ -2,39 +2,15 @@ import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
2
2
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
3
  import { fg } from '@atlaskit/platform-feature-flags';
4
4
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
5
- import { deletedContentStyle, deletedContentStyleActive, deletedContentStyleNew, deletedContentStyleNewActive, editingStyle, editingStyleActive, deletedContentStyleUnbounded, standardDecorationMarkerVariable, editingStyleQuoteNode, editingStyleRuleNode, editingStyleCardBlockNode, editingStyleNode } from './colorSchemes/standard';
6
- import { deletedTraditionalContentStyle, deletedTraditionalContentStyleUnbounded, traditionalInsertStyle, traditionalInsertStyleActive, traditionalDecorationMarkerVariable, traditionalStyleQuoteNode, traditionalStyleRuleNode, traditionalStyleCardBlockNode, traditionalStyleNode } from './colorSchemes/traditional';
7
- import { handleBlockNodeView } from './deletedBlocksHandler';
8
- import { handleDeletedRows } from './deletedRowsHandler';
9
- import { findSafeInsertPos } from './findSafeInsertPos';
10
- /**
11
- * Inline decoration used for insertions as the content already exists in the document
12
- *
13
- * @param change Changeset "change" containing information about the change content + range
14
- * @returns Prosemirror inline decoration
15
- */
16
- export var createInlineChangedDecoration = function createInlineChangedDecoration(_ref) {
17
- var change = _ref.change,
18
- colorScheme = _ref.colorScheme,
19
- _ref$isActive = _ref.isActive,
20
- isActive = _ref$isActive === void 0 ? false : _ref$isActive;
21
- var style;
22
- if (colorScheme === 'traditional') {
23
- style = isActive ? traditionalInsertStyleActive : traditionalInsertStyle;
24
- } else {
25
- style = isActive ? editingStyleActive : editingStyle;
26
- }
27
- return Decoration.inline(change.fromB, change.toB, {
28
- style: style,
29
- 'data-testid': 'show-diff-changed-decoration'
30
- }, {
31
- key: 'diff-inline'
32
- });
33
- };
34
- export var getDeletedContentStyleUnbounded = function getDeletedContentStyleUnbounded(colorScheme) {
5
+ import { deletedContentStyle, deletedContentStyleActive, deletedContentStyleNew, deletedContentStyleNewActive, deletedContentStyleUnbounded } from './colorSchemes/standard';
6
+ import { deletedTraditionalContentStyle, deletedTraditionalContentStyleUnbounded } from './colorSchemes/traditional';
7
+ import { createChangedRowDecorationWidgets } from './createChangedRowDecorationWidgets';
8
+ import { findSafeInsertPos } from './utils/findSafeInsertPos';
9
+ import { wrapBlockNodeView } from './utils/wrapBlockNodeView';
10
+ var getDeletedContentStyleUnbounded = function getDeletedContentStyleUnbounded(colorScheme) {
35
11
  return colorScheme === 'traditional' ? deletedTraditionalContentStyleUnbounded : deletedContentStyleUnbounded;
36
12
  };
37
- export var getDeletedContentStyle = function getDeletedContentStyle(colorScheme) {
13
+ var getDeletedContentStyle = function getDeletedContentStyle(colorScheme) {
38
14
  var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
39
15
  if (colorScheme === 'traditional') {
40
16
  return deletedTraditionalContentStyle;
@@ -44,38 +20,6 @@ export var getDeletedContentStyle = function getDeletedContentStyle(colorScheme)
44
20
  }
45
21
  return expValEquals('platform_editor_enghealth_a11y_jan_fixes', 'isEnabled', true) ? deletedContentStyleNew : deletedContentStyle;
46
22
  };
47
- var getNodeClass = function getNodeClass(name) {
48
- switch (name) {
49
- case 'extension':
50
- return 'show-diff-changed-decoration-node';
51
- default:
52
- return undefined;
53
- }
54
- };
55
- var getBlockNodeStyle = function getBlockNodeStyle(nodeName, colorScheme) {
56
- var isTraditional = colorScheme === 'traditional';
57
- if (['mediaSingle', 'mediaGroup', 'table',
58
- // Handle table separately to avoid border issues
59
- 'tableRow', 'tableCell', 'tableHeader', 'paragraph',
60
- // Paragraph and heading nodes do not need special styling
61
- 'heading', 'hardBreak', 'decisionList', 'taskList', 'taskItem', 'bulletList', 'orderedList', 'layoutSection'].includes(nodeName)) {
62
- // Layout nodes do not need special styling
63
- return undefined;
64
- }
65
- if (['extension', 'embedCard', 'listItem'].includes(nodeName)) {
66
- return isTraditional ? traditionalDecorationMarkerVariable : standardDecorationMarkerVariable;
67
- }
68
- if (nodeName === 'blockquote') {
69
- return isTraditional ? traditionalStyleQuoteNode : editingStyleQuoteNode;
70
- }
71
- if (nodeName === 'rule') {
72
- return isTraditional ? traditionalStyleRuleNode : editingStyleRuleNode;
73
- }
74
- if (nodeName === 'blockCard') {
75
- return isTraditional ? traditionalStyleCardBlockNode : editingStyleCardBlockNode;
76
- }
77
- return isTraditional ? traditionalStyleNode : editingStyleNode;
78
- };
79
23
 
80
24
  /**
81
25
  * Wraps content with deleted styling without opacity (for use when content is a direct child of dom)
@@ -85,39 +29,6 @@ var createDeletedStyleWrapperWithoutOpacity = function createDeletedStyleWrapper
85
29
  wrapper.setAttribute('style', getDeletedContentStyle(colorScheme, isActive));
86
30
  return wrapper;
87
31
  };
88
-
89
- /**
90
- * Inline decoration used for insertions as the content already exists in the document
91
- *
92
- * @param change Changeset "change" containing information about the change content + range
93
- * @returns Prosemirror inline decoration
94
- */
95
- export var createBlockChangedDecoration = function createBlockChangedDecoration(_ref2) {
96
- var change = _ref2.change,
97
- colorScheme = _ref2.colorScheme;
98
- if (fg('platform_editor_show_diff_scroll_navigation')) {
99
- var style = getBlockNodeStyle(change.name, colorScheme);
100
- var className = getNodeClass(change.name);
101
- if (style || className) {
102
- return Decoration.node(change.from, change.to, {
103
- style: style,
104
- 'data-testid': 'show-diff-changed-decoration-node',
105
- class: className
106
- }, {
107
- key: 'diff-block'
108
- });
109
- }
110
- return undefined;
111
- } else {
112
- return Decoration.node(change.from, change.to, {
113
- style: getBlockNodeStyle(change.name, colorScheme),
114
- 'data-testid': 'show-diff-changed-decoration-node',
115
- class: getNodeClass(change.name)
116
- }, {
117
- key: 'diff-block'
118
- });
119
- }
120
- };
121
32
  var createContentWrapper = function createContentWrapper(colorScheme) {
122
33
  var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
123
34
  var wrapper = document.createElement('span');
@@ -131,15 +42,15 @@ var createContentWrapper = function createContentWrapper(colorScheme) {
131
42
  wrapper.append(strikethrough);
132
43
  return wrapper;
133
44
  };
134
- export var createDeletedContentDecoration = function createDeletedContentDecoration(_ref3) {
135
- var change = _ref3.change,
136
- doc = _ref3.doc,
137
- nodeViewSerializer = _ref3.nodeViewSerializer,
138
- colorScheme = _ref3.colorScheme,
139
- newDoc = _ref3.newDoc,
140
- intl = _ref3.intl,
141
- _ref3$isActive = _ref3.isActive,
142
- isActive = _ref3$isActive === void 0 ? false : _ref3$isActive;
45
+ export var createNodeChangedDecorationWidget = function createNodeChangedDecorationWidget(_ref) {
46
+ var change = _ref.change,
47
+ doc = _ref.doc,
48
+ nodeViewSerializer = _ref.nodeViewSerializer,
49
+ colorScheme = _ref.colorScheme,
50
+ newDoc = _ref.newDoc,
51
+ intl = _ref.intl,
52
+ _ref$isActive = _ref.isActive,
53
+ isActive = _ref$isActive === void 0 ? false : _ref$isActive;
143
54
  var slice = doc.slice(change.fromA, change.toA);
144
55
  if (slice.content.content.length === 0) {
145
56
  return;
@@ -161,15 +72,13 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
161
72
  if (!fg('platform_editor_ai_aifc_patch_ga')) {
162
73
  return;
163
74
  }
164
- var _handleDeletedRows = handleDeletedRows({
165
- changes: [change],
166
- originalDoc: doc,
167
- newDoc: newDoc,
168
- nodeViewSerializer: nodeViewSerializer,
169
- colorScheme: colorScheme
170
- }),
171
- decorations = _handleDeletedRows.decorations;
172
- return decorations;
75
+ return createChangedRowDecorationWidgets({
76
+ changes: [change],
77
+ originalDoc: doc,
78
+ newDoc: newDoc,
79
+ nodeViewSerializer: nodeViewSerializer,
80
+ colorScheme: colorScheme
81
+ });
173
82
  }
174
83
  var serializer = nodeViewSerializer;
175
84
 
@@ -247,7 +156,13 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
247
156
  dom.append(wrapper);
248
157
  } else {
249
158
  // Handle all block nodes with unified function
250
- handleBlockNodeView(dom, nodeView, node, colorScheme, intl);
159
+ wrapBlockNodeView({
160
+ dom: dom,
161
+ nodeView: nodeView,
162
+ targetNode: node,
163
+ colorScheme: colorScheme,
164
+ intl: intl
165
+ });
251
166
  }
252
167
  } else if (nodeViewSerializer.getFilteredNodeViewBlocklist(['paragraph', 'tableRow']).has(node.type.name)) {
253
168
  // Skip the case where the node is a paragraph or table row that way it can still be rendered and delete the entire table
@@ -44,7 +44,7 @@ export var stepIsValidAttrChange = function stepIsValidAttrChange(step, beforeDo
44
44
  }
45
45
  }
46
46
  return false;
47
- } catch (e) {
47
+ } catch (_unused) {
48
48
  return false;
49
49
  }
50
50
  };