@atlaskit/editor-plugin-show-diff 5.0.4 → 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 (70) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/pm-plugins/calculateDiffDecorations.js +66 -39
  3. package/dist/cjs/pm-plugins/{colorSchemes → decorations/colorSchemes}/standard.js +32 -30
  4. package/dist/cjs/pm-plugins/decorations/colorSchemes/traditional.js +75 -0
  5. package/dist/cjs/pm-plugins/decorations/createBlockChangedDecoration.js +75 -0
  6. package/dist/cjs/pm-plugins/{deletedRowsHandler.js → decorations/createChangedRowDecorationWidgets.js} +34 -61
  7. package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +33 -0
  8. package/dist/cjs/pm-plugins/{decorations.js → decorations/createNodeChangedDecorationWidget.js} +27 -71
  9. package/dist/cjs/pm-plugins/{attributeDecorations.js → decorations/utils/getAttrChangeRanges.js} +1 -1
  10. package/dist/cjs/pm-plugins/{deletedBlocksHandler.js → decorations/utils/wrapBlockNodeView.js} +90 -70
  11. package/dist/es2019/pm-plugins/calculateDiffDecorations.js +41 -13
  12. package/dist/es2019/pm-plugins/{colorSchemes → decorations/colorSchemes}/standard.js +31 -29
  13. package/dist/es2019/pm-plugins/{colorSchemes → decorations/colorSchemes}/traditional.js +28 -29
  14. package/dist/es2019/pm-plugins/decorations/createBlockChangedDecoration.js +70 -0
  15. package/dist/es2019/pm-plugins/{deletedRowsHandler.js → decorations/createChangedRowDecorationWidgets.js} +30 -57
  16. package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +28 -0
  17. package/dist/es2019/pm-plugins/{decorations.js → decorations/createNodeChangedDecorationWidget.js} +27 -71
  18. package/dist/es2019/pm-plugins/{attributeDecorations.js → decorations/utils/getAttrChangeRanges.js} +1 -1
  19. package/dist/es2019/pm-plugins/{deletedBlocksHandler.js → decorations/utils/wrapBlockNodeView.js} +89 -64
  20. package/dist/esm/pm-plugins/calculateDiffDecorations.js +62 -35
  21. package/dist/esm/pm-plugins/{colorSchemes → decorations/colorSchemes}/standard.js +31 -29
  22. package/dist/esm/pm-plugins/{colorSchemes → decorations/colorSchemes}/traditional.js +28 -29
  23. package/dist/esm/pm-plugins/decorations/createBlockChangedDecoration.js +69 -0
  24. package/dist/esm/pm-plugins/{deletedRowsHandler.js → decorations/createChangedRowDecorationWidgets.js} +32 -59
  25. package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +28 -0
  26. package/dist/esm/pm-plugins/{decorations.js → decorations/createNodeChangedDecorationWidget.js} +27 -71
  27. package/dist/esm/pm-plugins/{attributeDecorations.js → decorations/utils/getAttrChangeRanges.js} +1 -1
  28. package/dist/esm/pm-plugins/{deletedBlocksHandler.js → decorations/utils/wrapBlockNodeView.js} +84 -64
  29. package/dist/types/pm-plugins/NodeViewSerializer.d.ts +1 -1
  30. package/dist/types/pm-plugins/calculateDiffDecorations.d.ts +2 -1
  31. package/dist/types/pm-plugins/decorations/colorSchemes/standard.d.ts +17 -0
  32. package/dist/types/pm-plugins/decorations/colorSchemes/traditional.d.ts +13 -0
  33. package/dist/types/pm-plugins/decorations/createBlockChangedDecoration.d.ts +16 -0
  34. package/dist/types/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +17 -0
  35. package/dist/types/pm-plugins/decorations/createInlineChangedDecoration.d.ts +16 -0
  36. package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +15 -0
  37. package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +15 -0
  38. package/dist/types-ts4.5/pm-plugins/NodeViewSerializer.d.ts +1 -1
  39. package/dist/types-ts4.5/pm-plugins/calculateDiffDecorations.d.ts +2 -1
  40. package/dist/types-ts4.5/pm-plugins/decorations/colorSchemes/standard.d.ts +17 -0
  41. package/dist/types-ts4.5/pm-plugins/decorations/colorSchemes/traditional.d.ts +13 -0
  42. package/dist/types-ts4.5/pm-plugins/decorations/createBlockChangedDecoration.d.ts +16 -0
  43. package/dist/types-ts4.5/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +17 -0
  44. package/dist/types-ts4.5/pm-plugins/decorations/createInlineChangedDecoration.d.ts +16 -0
  45. package/dist/types-ts4.5/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +15 -0
  46. package/dist/types-ts4.5/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +15 -0
  47. package/package.json +3 -3
  48. package/dist/cjs/pm-plugins/colorSchemes/traditional.js +0 -76
  49. package/dist/types/pm-plugins/colorSchemes/standard.d.ts +0 -8
  50. package/dist/types/pm-plugins/colorSchemes/traditional.d.ts +0 -5
  51. package/dist/types/pm-plugins/decorations.d.ts +0 -39
  52. package/dist/types/pm-plugins/deletedBlocksHandler.d.ts +0 -59
  53. package/dist/types/pm-plugins/deletedRowsHandler.d.ts +0 -30
  54. package/dist/types-ts4.5/pm-plugins/colorSchemes/standard.d.ts +0 -8
  55. package/dist/types-ts4.5/pm-plugins/colorSchemes/traditional.d.ts +0 -5
  56. package/dist/types-ts4.5/pm-plugins/decorations.d.ts +0 -39
  57. package/dist/types-ts4.5/pm-plugins/deletedBlocksHandler.d.ts +0 -59
  58. package/dist/types-ts4.5/pm-plugins/deletedRowsHandler.d.ts +0 -30
  59. /package/dist/cjs/pm-plugins/{findSafeInsertPos.js → decorations/utils/findSafeInsertPos.js} +0 -0
  60. /package/dist/cjs/pm-plugins/{markDecorations.js → decorations/utils/getMarkChangeRanges.js} +0 -0
  61. /package/dist/es2019/pm-plugins/{findSafeInsertPos.js → decorations/utils/findSafeInsertPos.js} +0 -0
  62. /package/dist/es2019/pm-plugins/{markDecorations.js → decorations/utils/getMarkChangeRanges.js} +0 -0
  63. /package/dist/esm/pm-plugins/{findSafeInsertPos.js → decorations/utils/findSafeInsertPos.js} +0 -0
  64. /package/dist/esm/pm-plugins/{markDecorations.js → decorations/utils/getMarkChangeRanges.js} +0 -0
  65. /package/dist/types/pm-plugins/{findSafeInsertPos.d.ts → decorations/utils/findSafeInsertPos.d.ts} +0 -0
  66. /package/dist/types/pm-plugins/{attributeDecorations.d.ts → decorations/utils/getAttrChangeRanges.d.ts} +0 -0
  67. /package/dist/types/pm-plugins/{markDecorations.d.ts → decorations/utils/getMarkChangeRanges.d.ts} +0 -0
  68. /package/dist/types-ts4.5/pm-plugins/{findSafeInsertPos.d.ts → decorations/utils/findSafeInsertPos.d.ts} +0 -0
  69. /package/dist/types-ts4.5/pm-plugins/{attributeDecorations.d.ts → decorations/utils/getAttrChangeRanges.d.ts} +0 -0
  70. /package/dist/types-ts4.5/pm-plugins/{markDecorations.d.ts → decorations/utils/getMarkChangeRanges.d.ts} +0 -0
@@ -28,43 +28,42 @@ export const deletedTraditionalContentStyleUnbounded = convertToInlineCss({
28
28
  pointerEvents: 'none',
29
29
  zIndex: 1
30
30
  });
31
- const traditionalStyleQuoteNode = convertToInlineCss({
31
+ export const deletedTraditionalStyleQuoteNode = convertToInlineCss({
32
+ marginTop: "var(--ds-space-150, 12px)",
33
+ paddingTop: "var(--ds-space-025, 2px)",
34
+ paddingBottom: "var(--ds-space-025, 2px)",
35
+ paddingLeft: "var(--ds-space-025, 2px)",
36
+ boxShadow: `0 0 0 1px ${"var(--ds-border-accent-red, #E2483D)"}`,
37
+ borderRadius: "var(--ds-radius-small, 4px)"
38
+ });
39
+ export const deletedTraditionalBlockOutline = convertToInlineCss({
40
+ boxShadow: `0 0 0 1px ${"var(--ds-border-accent-red, #E2483D)"}`,
41
+ borderRadius: "var(--ds-radius-small, 4px)"
42
+ });
43
+ export const deletedTraditionalBlockOutlineRounded = convertToInlineCss({
44
+ boxShadow: `0 0 0 1px ${"var(--ds-border-accent-red, #E2483D)"}`,
45
+ borderRadius: `calc(${"var(--ds-radius-xsmall, 2px)"} + 1px)`
46
+ });
47
+ export const deletedTraditionalRowStyle = convertToInlineCss({
48
+ textDecorationColor: "var(--ds-border-accent-red, #E2483D)",
49
+ textDecoration: 'line-through',
50
+ opacity: 0.6,
51
+ display: 'table-row'
52
+ });
53
+ export const traditionalStyleQuoteNode = convertToInlineCss({
32
54
  borderLeft: `2px solid ${"var(--ds-border-accent-green, #22A06B)"}`
33
55
  });
34
- const traditionalStyleRuleNode = convertToInlineCss({
56
+ export const traditionalStyleRuleNode = convertToInlineCss({
35
57
  backgroundColor: "var(--ds-border-accent-green, #22A06B)"
36
58
  });
37
- const traditionalStyleNode = convertToInlineCss({
59
+ export const traditionalStyleNode = convertToInlineCss({
38
60
  boxShadow: `0 0 0 1px ${"var(--ds-border-accent-green, #22A06B)"}`,
39
61
  borderRadius: "var(--ds-radius-small, 4px)"
40
62
  });
41
- const traditionalStyleCardBlockNode = convertToInlineCss({
63
+ export const traditionalStyleCardBlockNode = convertToInlineCss({
42
64
  boxShadow: `0 0 0 1px ${"var(--ds-border-accent-green, #22A06B)"}`,
43
65
  borderRadius: "var(--ds-radius-medium, 6px)"
44
66
  });
45
- const traditionalDecorationMarkerVariable = convertToInlineCss({
67
+ export const traditionalDecorationMarkerVariable = convertToInlineCss({
46
68
  '--diff-decoration-marker-color': "var(--ds-border-accent-green, #22A06B)"
47
- });
48
- export const getTraditionalNodeStyle = nodeName => {
49
- if (['mediaSingle', 'mediaGroup', 'table',
50
- // Handle table separately to avoid border issues
51
- 'tableRow', 'tableCell', 'tableHeader', 'paragraph',
52
- // Paragraph and heading nodes do not need special styling
53
- 'heading', 'hardBreak', 'decisionList', 'taskList', 'taskItem', 'bulletList', 'orderedList', 'layoutSection'].includes(nodeName)) {
54
- // Layout nodes do not need special styling
55
- return undefined;
56
- }
57
- if (['extension', 'embedCard', 'listItem'].includes(nodeName)) {
58
- return traditionalDecorationMarkerVariable;
59
- }
60
- if (nodeName === 'blockquote') {
61
- return traditionalStyleQuoteNode;
62
- }
63
- if (nodeName === 'rule') {
64
- return traditionalStyleRuleNode;
65
- }
66
- if (nodeName === 'blockCard') {
67
- return traditionalStyleCardBlockNode;
68
- }
69
- return traditionalStyleNode;
70
- };
69
+ });
@@ -0,0 +1,70 @@
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
+ const getNodeClass = name => {
6
+ switch (name) {
7
+ case 'extension':
8
+ return 'show-diff-changed-decoration-node';
9
+ default:
10
+ return undefined;
11
+ }
12
+ };
13
+ const getBlockNodeStyle = (nodeName, colorScheme) => {
14
+ const 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 const createBlockChangedDecoration = ({
45
+ change,
46
+ colorScheme
47
+ }) => {
48
+ if (fg('platform_editor_show_diff_scroll_navigation')) {
49
+ const style = getBlockNodeStyle(change.name, colorScheme);
50
+ const className = getNodeClass(change.name);
51
+ if (style || className) {
52
+ return Decoration.node(change.from, change.to, {
53
+ style: style,
54
+ 'data-testid': 'show-diff-changed-decoration-node',
55
+ class: className
56
+ }, {
57
+ key: 'diff-block'
58
+ });
59
+ }
60
+ return undefined;
61
+ } else {
62
+ return Decoration.node(change.from, change.to, {
63
+ style: getBlockNodeStyle(change.name, colorScheme),
64
+ 'data-testid': 'show-diff-changed-decoration-node',
65
+ class: getNodeClass(change.name)
66
+ }, {
67
+ key: 'diff-block'
68
+ });
69
+ }
70
+ };
@@ -1,32 +1,21 @@
1
- import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
2
1
  import { areNodesEqualIgnoreAttrs } from '@atlaskit/editor-common/utils/document';
3
2
  import { findParentNodeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
4
3
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
5
4
  import { TableMap } from '@atlaskit/editor-tables/table-map';
6
- import { findSafeInsertPos } from './findSafeInsertPos';
7
- const deletedRowStyle = convertToInlineCss({
8
- color: "var(--ds-text-accent-gray, #505258)",
9
- textDecoration: 'line-through',
10
- opacity: 0.6,
11
- display: 'table-row'
12
- });
13
- const deletedTraditionalRowStyle = convertToInlineCss({
14
- textDecorationColor: "var(--ds-border-accent-red, #E2483D)",
15
- textDecoration: 'line-through',
16
- opacity: 0.6,
17
- display: 'table-row'
18
- });
5
+ import { deletedRowStyle } from './colorSchemes/standard';
6
+ import { deletedTraditionalRowStyle } from './colorSchemes/traditional';
7
+ import { findSafeInsertPos } from './utils/findSafeInsertPos';
19
8
  /**
20
9
  * Extracts information about deleted table rows from a change
21
10
  */
22
- const extractDeletedRows = (change, originalDoc, newDoc) => {
23
- const deletedRows = [];
11
+ const extractChangedRows = (change, originalDoc, newDoc) => {
12
+ const changedRows = [];
24
13
 
25
14
  // Find the table in the original document
26
15
  const $fromPos = originalDoc.resolve(change.fromA);
27
16
  const tableOld = findParentNodeClosestToPos($fromPos, node => node.type.name === 'table');
28
17
  if (!tableOld) {
29
- return deletedRows;
18
+ return changedRows;
30
19
  }
31
20
  const oldTableMap = TableMap.get(tableOld.node);
32
21
 
@@ -34,18 +23,18 @@ const extractDeletedRows = (change, originalDoc, newDoc) => {
34
23
  const $newPos = newDoc.resolve(change.fromB);
35
24
  const tableNew = findParentNodeClosestToPos($newPos, node => node.type.name === 'table');
36
25
  if (!tableNew) {
37
- return deletedRows;
26
+ return changedRows;
38
27
  }
39
28
  const newTableMap = TableMap.get(tableNew.node);
40
29
 
41
- // If no rows were deleted, return empty
30
+ // If no rows were changed, return empty
42
31
  if (oldTableMap.height <= newTableMap.height ||
43
32
  // For now ignore if there are column deletions as well
44
33
  oldTableMap.width !== newTableMap.width) {
45
- return deletedRows;
34
+ return changedRows;
46
35
  }
47
36
 
48
- // Find which rows were deleted by analyzing the change range
37
+ // Find which rows were changed by analyzing the change range
49
38
  const changeStartInTable = change.fromA - tableOld.pos - 1;
50
39
  const changeEndInTable = change.toA - tableOld.pos - 1;
51
40
  let currentOffset = 0;
@@ -58,7 +47,7 @@ const extractDeletedRows = (change, originalDoc, newDoc) => {
58
47
  const rowOverlapsChange = rowStart >= changeStartInTable && rowStart < changeEndInTable || rowEnd > changeStartInTable && rowEnd <= changeEndInTable || rowStart < changeStartInTable && rowEnd > changeEndInTable;
59
48
  if (rowOverlapsChange && rowNode.type.name === 'tableRow' && !isEmptyRow(rowNode)) {
60
49
  const startOfRow = newTableMap.mapByRow.slice().reverse().find(row => row[0] + tableNew.pos < change.fromB && change.fromB < row[row.length - 1] + tableNew.pos);
61
- deletedRows.push({
50
+ changedRows.push({
62
51
  rowIndex,
63
52
  rowNode,
64
53
  fromA: tableOld.pos + 1 + rowStart,
@@ -73,8 +62,8 @@ const extractDeletedRows = (change, originalDoc, newDoc) => {
73
62
  });
74
63
 
75
64
  // Filter changes that never truly got deleted
76
- return deletedRows.filter(deletedRow => {
77
- return !tableNew.node.children.some(newRow => areNodesEqualIgnoreAttrs(newRow, deletedRow.rowNode));
65
+ return changedRows.filter(changedRow => {
66
+ return !tableNew.node.children.some(newRow => areNodesEqualIgnoreAttrs(newRow, changedRow.rowNode));
78
67
  });
79
68
  };
80
69
 
@@ -107,7 +96,7 @@ const isEmptyRow = rowNode => {
107
96
  /**
108
97
  * Creates a DOM representation of a deleted table row
109
98
  */
110
- const createDeletedRowDOM = (rowNode, nodeViewSerializer, colorScheme) => {
99
+ const createChangedRowDOM = (rowNode, nodeViewSerializer, colorScheme) => {
111
100
  const tr = document.createElement('tr');
112
101
  tr.setAttribute('style', colorScheme === 'traditional' ? deletedTraditionalRowStyle : deletedRowStyle);
113
102
  tr.setAttribute('data-testid', 'show-diff-deleted-row');
@@ -131,55 +120,39 @@ const createDeletedRowDOM = (rowNode, nodeViewSerializer, colorScheme) => {
131
120
  };
132
121
 
133
122
  /**
134
- * Expands a diff to include whole deleted rows when table rows are affected
123
+ * Expands a diff to include whole changed rows when table rows are affected
135
124
  */
136
- const expandDiffForDeletedRows = (changes, originalDoc, newDoc) => {
137
- const deletedRowInfo = [];
125
+ const expandDiffForChangedRows = (changes, originalDoc, newDoc) => {
126
+ const rowInfo = [];
138
127
  for (const change of changes) {
139
128
  // Check if this change affects table content
140
- const deletedRows = extractDeletedRows(change, originalDoc, newDoc);
141
- if (deletedRows.length > 0) {
142
- deletedRowInfo.push(...deletedRows);
129
+ const changedRows = extractChangedRows(change, originalDoc, newDoc);
130
+ if (changedRows.length > 0) {
131
+ rowInfo.push(...changedRows);
143
132
  }
144
133
  }
145
- return deletedRowInfo;
134
+ return rowInfo;
146
135
  };
147
136
 
148
137
  /**
149
- * Creates decorations for deleted table rows
138
+ * Main function to handle deleted rows - computes diff and creates decorations
150
139
  */
151
- export const createDeletedRowsDecorations = ({
152
- deletedRows,
140
+ export const createChangedRowDecorationWidgets = ({
141
+ changes,
153
142
  originalDoc,
154
143
  newDoc,
155
144
  nodeViewSerializer,
156
145
  colorScheme
157
146
  }) => {
158
- return deletedRows.map(deletedRow => {
159
- const rowDOM = createDeletedRowDOM(deletedRow.rowNode, nodeViewSerializer, colorScheme);
147
+ // First, expand the changes to include complete deleted rows
148
+ const changedRows = expandDiffForChangedRows(changes.filter(change => change.deleted.length > 0), originalDoc, newDoc);
149
+ return changedRows.map(changedRow => {
150
+ const rowDOM = createChangedRowDOM(changedRow.rowNode, nodeViewSerializer, colorScheme);
160
151
 
161
152
  // Find safe insertion position for the deleted row
162
- const safeInsertPos = findSafeInsertPos(newDoc, deletedRow.fromB - 1,
153
+ const safeInsertPos = findSafeInsertPos(newDoc, changedRow.fromB - 1,
163
154
  // -1 to find the first safe position from the table
164
- originalDoc.slice(deletedRow.fromA, deletedRow.toA));
155
+ originalDoc.slice(changedRow.fromA, changedRow.toA));
165
156
  return Decoration.widget(safeInsertPos, rowDOM, {});
166
157
  });
167
- };
168
-
169
- /**
170
- * Main function to handle deleted rows - computes diff and creates decorations
171
- */
172
- export const handleDeletedRows = (changes, originalDoc, newDoc, nodeViewSerializer, colorScheme) => {
173
- // First, expand the changes to include complete deleted rows
174
- const deletedRows = expandDiffForDeletedRows(changes.filter(change => change.deleted.length > 0), originalDoc, newDoc);
175
- const allDecorations = createDeletedRowsDecorations({
176
- deletedRows,
177
- originalDoc,
178
- newDoc,
179
- nodeViewSerializer,
180
- colorScheme
181
- });
182
- return {
183
- decorations: allDecorations
184
- };
185
158
  };
@@ -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 const createInlineChangedDecoration = ({
12
+ change,
13
+ colorScheme,
14
+ isActive = false
15
+ }) => {
16
+ let 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,
24
+ 'data-testid': 'show-diff-changed-decoration'
25
+ }, {
26
+ key: 'diff-inline'
27
+ });
28
+ };
@@ -2,33 +2,13 @@ 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 { getStandardNodeStyle, deletedContentStyle, deletedContentStyleActive, deletedContentStyleNew, deletedContentStyleNewActive, editingStyle, editingStyleActive, deletedContentStyleUnbounded } from './colorSchemes/standard';
6
- import { getTraditionalNodeStyle, deletedTraditionalContentStyle, deletedTraditionalContentStyleUnbounded, traditionalInsertStyle, traditionalInsertStyleActive } from './colorSchemes/traditional';
7
- import { createDeletedStyleWrapperWithoutOpacity, 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 const createInlineChangedDecoration = (change, colorScheme, isActive = false) => {
17
- let style;
18
- if (colorScheme === 'traditional') {
19
- style = isActive ? traditionalInsertStyleActive : traditionalInsertStyle;
20
- } else {
21
- style = isActive ? editingStyleActive : editingStyle;
22
- }
23
- return Decoration.inline(change.fromB, change.toB, {
24
- style,
25
- 'data-testid': 'show-diff-changed-decoration'
26
- }, {
27
- key: 'diff-inline'
28
- });
29
- };
30
- export const getDeletedContentStyleUnbounded = colorScheme => colorScheme === 'traditional' ? deletedTraditionalContentStyleUnbounded : deletedContentStyleUnbounded;
31
- export const getDeletedContentStyle = (colorScheme, isActive = false) => {
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
+ const getDeletedContentStyleUnbounded = colorScheme => colorScheme === 'traditional' ? deletedTraditionalContentStyleUnbounded : deletedContentStyleUnbounded;
11
+ const getDeletedContentStyle = (colorScheme, isActive = false) => {
32
12
  if (colorScheme === 'traditional') {
33
13
  return deletedTraditionalContentStyle;
34
14
  }
@@ -37,47 +17,14 @@ export const getDeletedContentStyle = (colorScheme, isActive = false) => {
37
17
  }
38
18
  return expValEquals('platform_editor_enghealth_a11y_jan_fixes', 'isEnabled', true) ? deletedContentStyleNew : deletedContentStyle;
39
19
  };
40
- const getNodeClass = name => {
41
- switch (name) {
42
- case 'extension':
43
- return 'show-diff-changed-decoration-node';
44
- default:
45
- return undefined;
46
- }
47
- };
48
- const getBlockNodeStyle = (name, colorScheme) => {
49
- return colorScheme === 'traditional' ? getTraditionalNodeStyle(name) : getStandardNodeStyle(name);
50
- };
51
20
 
52
21
  /**
53
- * Inline decoration used for insertions as the content already exists in the document
54
- *
55
- * @param change Changeset "change" containing information about the change content + range
56
- * @returns Prosemirror inline decoration
22
+ * Wraps content with deleted styling without opacity (for use when content is a direct child of dom)
57
23
  */
58
- export const createBlockChangedDecoration = (change, colorScheme) => {
59
- if (fg('platform_editor_show_diff_scroll_navigation')) {
60
- const style = getBlockNodeStyle(change.name, colorScheme);
61
- const className = getNodeClass(change.name);
62
- if (style || className) {
63
- return Decoration.node(change.from, change.to, {
64
- style: style,
65
- 'data-testid': 'show-diff-changed-decoration-node',
66
- class: className
67
- }, {
68
- key: 'diff-block'
69
- });
70
- }
71
- return undefined;
72
- } else {
73
- return Decoration.node(change.from, change.to, {
74
- style: getBlockNodeStyle(change.name, colorScheme),
75
- 'data-testid': 'show-diff-changed-decoration-node',
76
- class: getNodeClass(change.name)
77
- }, {
78
- key: 'diff-block'
79
- });
80
- }
24
+ const createDeletedStyleWrapperWithoutOpacity = (colorScheme, isActive) => {
25
+ const wrapper = document.createElement('span');
26
+ wrapper.setAttribute('style', getDeletedContentStyle(colorScheme, isActive));
27
+ return wrapper;
81
28
  };
82
29
  const createContentWrapper = (colorScheme, isActive = false) => {
83
30
  const wrapper = document.createElement('span');
@@ -91,7 +38,7 @@ const createContentWrapper = (colorScheme, isActive = false) => {
91
38
  wrapper.append(strikethrough);
92
39
  return wrapper;
93
40
  };
94
- export const createDeletedContentDecoration = ({
41
+ export const createNodeChangedDecorationWidget = ({
95
42
  change,
96
43
  doc,
97
44
  nodeViewSerializer,
@@ -113,10 +60,13 @@ export const createDeletedContentDecoration = ({
113
60
  if (!fg('platform_editor_ai_aifc_patch_ga')) {
114
61
  return;
115
62
  }
116
- const {
117
- decorations
118
- } = handleDeletedRows([change], doc, newDoc, nodeViewSerializer, colorScheme);
119
- return decorations;
63
+ return createChangedRowDecorationWidgets({
64
+ changes: [change],
65
+ originalDoc: doc,
66
+ newDoc,
67
+ nodeViewSerializer,
68
+ colorScheme
69
+ });
120
70
  }
121
71
  const serializer = nodeViewSerializer;
122
72
 
@@ -190,7 +140,13 @@ export const createDeletedContentDecoration = ({
190
140
  dom.append(wrapper);
191
141
  } else {
192
142
  // Handle all block nodes with unified function
193
- handleBlockNodeView(dom, nodeView, node, colorScheme, intl);
143
+ wrapBlockNodeView({
144
+ dom,
145
+ nodeView,
146
+ targetNode: node,
147
+ colorScheme,
148
+ intl
149
+ });
194
150
  }
195
151
  } else if (nodeViewSerializer.getFilteredNodeViewBlocklist(['paragraph', 'tableRow']).has(node.type.name)) {
196
152
  // Skip the case where the node is a paragraph or table row that way it can still be rendered and delete the entire table
@@ -39,7 +39,7 @@ export const stepIsValidAttrChange = (step, beforeDoc, afterDoc) => {
39
39
  }
40
40
  }
41
41
  return false;
42
- } catch (e) {
42
+ } catch {
43
43
  return false;
44
44
  }
45
45
  };