@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.
- package/CHANGELOG.md +17 -0
- package/dist/cjs/pm-plugins/calculateDiffDecorations.js +66 -39
- package/dist/cjs/pm-plugins/{colorSchemes → decorations/colorSchemes}/standard.js +32 -30
- package/dist/cjs/pm-plugins/decorations/colorSchemes/traditional.js +75 -0
- package/dist/cjs/pm-plugins/decorations/createBlockChangedDecoration.js +75 -0
- package/dist/cjs/pm-plugins/{deletedRowsHandler.js → decorations/createChangedRowDecorationWidgets.js} +34 -61
- package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +33 -0
- package/dist/cjs/pm-plugins/{decorations.js → decorations/createNodeChangedDecorationWidget.js} +27 -71
- package/dist/cjs/pm-plugins/{attributeDecorations.js → decorations/utils/getAttrChangeRanges.js} +1 -1
- package/dist/cjs/pm-plugins/{deletedBlocksHandler.js → decorations/utils/wrapBlockNodeView.js} +90 -70
- package/dist/es2019/pm-plugins/calculateDiffDecorations.js +41 -13
- package/dist/es2019/pm-plugins/{colorSchemes → decorations/colorSchemes}/standard.js +31 -29
- package/dist/es2019/pm-plugins/{colorSchemes → decorations/colorSchemes}/traditional.js +28 -29
- package/dist/es2019/pm-plugins/decorations/createBlockChangedDecoration.js +70 -0
- package/dist/es2019/pm-plugins/{deletedRowsHandler.js → decorations/createChangedRowDecorationWidgets.js} +30 -57
- package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +28 -0
- package/dist/es2019/pm-plugins/{decorations.js → decorations/createNodeChangedDecorationWidget.js} +27 -71
- package/dist/es2019/pm-plugins/{attributeDecorations.js → decorations/utils/getAttrChangeRanges.js} +1 -1
- package/dist/es2019/pm-plugins/{deletedBlocksHandler.js → decorations/utils/wrapBlockNodeView.js} +89 -64
- package/dist/esm/pm-plugins/calculateDiffDecorations.js +62 -35
- package/dist/esm/pm-plugins/{colorSchemes → decorations/colorSchemes}/standard.js +31 -29
- package/dist/esm/pm-plugins/{colorSchemes → decorations/colorSchemes}/traditional.js +28 -29
- package/dist/esm/pm-plugins/decorations/createBlockChangedDecoration.js +69 -0
- package/dist/esm/pm-plugins/{deletedRowsHandler.js → decorations/createChangedRowDecorationWidgets.js} +32 -59
- package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +28 -0
- package/dist/esm/pm-plugins/{decorations.js → decorations/createNodeChangedDecorationWidget.js} +27 -71
- package/dist/esm/pm-plugins/{attributeDecorations.js → decorations/utils/getAttrChangeRanges.js} +1 -1
- package/dist/esm/pm-plugins/{deletedBlocksHandler.js → decorations/utils/wrapBlockNodeView.js} +84 -64
- package/dist/types/pm-plugins/NodeViewSerializer.d.ts +1 -1
- package/dist/types/pm-plugins/calculateDiffDecorations.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/colorSchemes/standard.d.ts +17 -0
- package/dist/types/pm-plugins/decorations/colorSchemes/traditional.d.ts +13 -0
- package/dist/types/pm-plugins/decorations/createBlockChangedDecoration.d.ts +16 -0
- package/dist/types/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +17 -0
- package/dist/types/pm-plugins/decorations/createInlineChangedDecoration.d.ts +16 -0
- package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +15 -0
- package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +15 -0
- package/dist/types-ts4.5/pm-plugins/NodeViewSerializer.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/calculateDiffDecorations.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/decorations/colorSchemes/standard.d.ts +17 -0
- package/dist/types-ts4.5/pm-plugins/decorations/colorSchemes/traditional.d.ts +13 -0
- package/dist/types-ts4.5/pm-plugins/decorations/createBlockChangedDecoration.d.ts +16 -0
- package/dist/types-ts4.5/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +17 -0
- package/dist/types-ts4.5/pm-plugins/decorations/createInlineChangedDecoration.d.ts +16 -0
- package/dist/types-ts4.5/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +15 -0
- package/dist/types-ts4.5/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +15 -0
- package/package.json +3 -3
- package/dist/cjs/pm-plugins/colorSchemes/traditional.js +0 -76
- package/dist/types/pm-plugins/colorSchemes/standard.d.ts +0 -8
- package/dist/types/pm-plugins/colorSchemes/traditional.d.ts +0 -5
- package/dist/types/pm-plugins/decorations.d.ts +0 -39
- package/dist/types/pm-plugins/deletedBlocksHandler.d.ts +0 -59
- package/dist/types/pm-plugins/deletedRowsHandler.d.ts +0 -30
- package/dist/types-ts4.5/pm-plugins/colorSchemes/standard.d.ts +0 -8
- package/dist/types-ts4.5/pm-plugins/colorSchemes/traditional.d.ts +0 -5
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +0 -39
- package/dist/types-ts4.5/pm-plugins/deletedBlocksHandler.d.ts +0 -59
- package/dist/types-ts4.5/pm-plugins/deletedRowsHandler.d.ts +0 -30
- /package/dist/cjs/pm-plugins/{findSafeInsertPos.js → decorations/utils/findSafeInsertPos.js} +0 -0
- /package/dist/cjs/pm-plugins/{markDecorations.js → decorations/utils/getMarkChangeRanges.js} +0 -0
- /package/dist/es2019/pm-plugins/{findSafeInsertPos.js → decorations/utils/findSafeInsertPos.js} +0 -0
- /package/dist/es2019/pm-plugins/{markDecorations.js → decorations/utils/getMarkChangeRanges.js} +0 -0
- /package/dist/esm/pm-plugins/{findSafeInsertPos.js → decorations/utils/findSafeInsertPos.js} +0 -0
- /package/dist/esm/pm-plugins/{markDecorations.js → decorations/utils/getMarkChangeRanges.js} +0 -0
- /package/dist/types/pm-plugins/{findSafeInsertPos.d.ts → decorations/utils/findSafeInsertPos.d.ts} +0 -0
- /package/dist/types/pm-plugins/{attributeDecorations.d.ts → decorations/utils/getAttrChangeRanges.d.ts} +0 -0
- /package/dist/types/pm-plugins/{markDecorations.d.ts → decorations/utils/getMarkChangeRanges.d.ts} +0 -0
- /package/dist/types-ts4.5/pm-plugins/{findSafeInsertPos.d.ts → decorations/utils/findSafeInsertPos.d.ts} +0 -0
- /package/dist/types-ts4.5/pm-plugins/{attributeDecorations.d.ts → decorations/utils/getAttrChangeRanges.d.ts} +0 -0
- /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
|
|
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 {
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
23
|
-
const
|
|
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
|
|
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
|
|
26
|
+
return changedRows;
|
|
38
27
|
}
|
|
39
28
|
const newTableMap = TableMap.get(tableNew.node);
|
|
40
29
|
|
|
41
|
-
// If no rows were
|
|
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
|
|
34
|
+
return changedRows;
|
|
46
35
|
}
|
|
47
36
|
|
|
48
|
-
// Find which rows were
|
|
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
|
-
|
|
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
|
|
77
|
-
return !tableNew.node.children.some(newRow => areNodesEqualIgnoreAttrs(newRow,
|
|
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
|
|
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
|
|
123
|
+
* Expands a diff to include whole changed rows when table rows are affected
|
|
135
124
|
*/
|
|
136
|
-
const
|
|
137
|
-
const
|
|
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
|
|
141
|
-
if (
|
|
142
|
-
|
|
129
|
+
const changedRows = extractChangedRows(change, originalDoc, newDoc);
|
|
130
|
+
if (changedRows.length > 0) {
|
|
131
|
+
rowInfo.push(...changedRows);
|
|
143
132
|
}
|
|
144
133
|
}
|
|
145
|
-
return
|
|
134
|
+
return rowInfo;
|
|
146
135
|
};
|
|
147
136
|
|
|
148
137
|
/**
|
|
149
|
-
*
|
|
138
|
+
* Main function to handle deleted rows - computes diff and creates decorations
|
|
150
139
|
*/
|
|
151
|
-
export const
|
|
152
|
-
|
|
140
|
+
export const createChangedRowDecorationWidgets = ({
|
|
141
|
+
changes,
|
|
153
142
|
originalDoc,
|
|
154
143
|
newDoc,
|
|
155
144
|
nodeViewSerializer,
|
|
156
145
|
colorScheme
|
|
157
146
|
}) => {
|
|
158
|
-
|
|
159
|
-
|
|
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,
|
|
153
|
+
const safeInsertPos = findSafeInsertPos(newDoc, changedRow.fromB - 1,
|
|
163
154
|
// -1 to find the first safe position from the table
|
|
164
|
-
originalDoc.slice(
|
|
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
|
+
};
|
package/dist/es2019/pm-plugins/{decorations.js → decorations/createNodeChangedDecorationWidget.js}
RENAMED
|
@@ -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 {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
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
|