@atlaskit/editor-plugin-show-diff 4.1.3 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/cjs/pm-plugins/calculateDiffDecorations.js +15 -12
- package/dist/cjs/pm-plugins/decorations.js +47 -26
- package/dist/cjs/pm-plugins/deletedBlocksHandler.js +22 -22
- package/dist/cjs/pm-plugins/deletedRowsHandler.js +7 -7
- package/dist/cjs/pm-plugins/main.js +11 -5
- package/dist/cjs/showDiffPlugin.js +2 -1
- package/dist/es2019/pm-plugins/calculateDiffDecorations.js +15 -12
- package/dist/es2019/pm-plugins/decorations.js +47 -24
- package/dist/es2019/pm-plugins/deletedBlocksHandler.js +22 -22
- package/dist/es2019/pm-plugins/deletedRowsHandler.js +7 -7
- package/dist/es2019/pm-plugins/main.js +8 -4
- package/dist/es2019/showDiffPlugin.js +3 -2
- package/dist/esm/pm-plugins/calculateDiffDecorations.js +15 -12
- package/dist/esm/pm-plugins/decorations.js +47 -26
- package/dist/esm/pm-plugins/deletedBlocksHandler.js +22 -22
- package/dist/esm/pm-plugins/deletedRowsHandler.js +7 -7
- package/dist/esm/pm-plugins/main.js +10 -4
- package/dist/esm/showDiffPlugin.js +3 -2
- package/dist/types/pm-plugins/calculateDiffDecorations.d.ts +2 -2
- package/dist/types/pm-plugins/decorations.d.ts +6 -6
- package/dist/types/pm-plugins/deletedBlocksHandler.d.ts +8 -8
- package/dist/types/pm-plugins/deletedRowsHandler.d.ts +3 -3
- package/dist/types/pm-plugins/main.d.ts +2 -0
- package/dist/types/showDiffPluginType.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/calculateDiffDecorations.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +6 -6
- package/dist/types-ts4.5/pm-plugins/deletedBlocksHandler.d.ts +8 -8
- package/dist/types-ts4.5/pm-plugins/deletedRowsHandler.d.ts +3 -3
- package/dist/types-ts4.5/pm-plugins/main.d.ts +2 -0
- package/dist/types-ts4.5/showDiffPluginType.d.ts +2 -1
- package/package.json +3 -3
|
@@ -13,9 +13,9 @@ import { findSafeInsertPos } from './findSafeInsertPos';
|
|
|
13
13
|
* @param change Changeset "change" containing information about the change content + range
|
|
14
14
|
* @returns Prosemirror inline decoration
|
|
15
15
|
*/
|
|
16
|
-
export const createInlineChangedDecoration = (change,
|
|
16
|
+
export const createInlineChangedDecoration = (change, colorScheme, isActive = false) => {
|
|
17
17
|
let style;
|
|
18
|
-
if (
|
|
18
|
+
if (colorScheme === 'traditional') {
|
|
19
19
|
style = isActive ? traditionalInsertStyleActive : traditionalInsertStyle;
|
|
20
20
|
} else {
|
|
21
21
|
style = isActive ? editingStyleActive : editingStyle;
|
|
@@ -23,11 +23,13 @@ export const createInlineChangedDecoration = (change, colourScheme, isActive = f
|
|
|
23
23
|
return Decoration.inline(change.fromB, change.toB, {
|
|
24
24
|
style,
|
|
25
25
|
'data-testid': 'show-diff-changed-decoration'
|
|
26
|
-
}, {
|
|
26
|
+
}, {
|
|
27
|
+
key: 'diff-inline'
|
|
28
|
+
});
|
|
27
29
|
};
|
|
28
|
-
export const getDeletedContentStyleUnbounded =
|
|
29
|
-
export const getDeletedContentStyle = (
|
|
30
|
-
if (
|
|
30
|
+
export const getDeletedContentStyleUnbounded = colorScheme => colorScheme === 'traditional' ? deletedTraditionalContentStyleUnbounded : deletedContentStyleUnbounded;
|
|
31
|
+
export const getDeletedContentStyle = (colorScheme, isActive = false) => {
|
|
32
|
+
if (colorScheme === 'traditional') {
|
|
31
33
|
return deletedTraditionalContentStyle;
|
|
32
34
|
}
|
|
33
35
|
if (isActive) {
|
|
@@ -43,8 +45,8 @@ const getNodeClass = name => {
|
|
|
43
45
|
return undefined;
|
|
44
46
|
}
|
|
45
47
|
};
|
|
46
|
-
const getBlockNodeStyle = (name,
|
|
47
|
-
return
|
|
48
|
+
const getBlockNodeStyle = (name, colorScheme) => {
|
|
49
|
+
return colorScheme === 'traditional' ? getTraditionalNodeStyle(name) : getStandardNodeStyle(name);
|
|
48
50
|
};
|
|
49
51
|
|
|
50
52
|
/**
|
|
@@ -53,20 +55,39 @@ const getBlockNodeStyle = (name, colourScheme) => {
|
|
|
53
55
|
* @param change Changeset "change" containing information about the change content + range
|
|
54
56
|
* @returns Prosemirror inline decoration
|
|
55
57
|
*/
|
|
56
|
-
export const createBlockChangedDecoration = (change,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const createContentWrapper = (colorScheme, isActive = false) => {
|
|
62
83
|
const wrapper = document.createElement('span');
|
|
63
84
|
const baseStyle = convertToInlineCss({
|
|
64
85
|
position: 'relative',
|
|
65
86
|
width: 'fit-content'
|
|
66
87
|
});
|
|
67
|
-
wrapper.setAttribute('style', `${baseStyle}${getDeletedContentStyle(
|
|
88
|
+
wrapper.setAttribute('style', `${baseStyle}${getDeletedContentStyle(colorScheme, isActive)}`);
|
|
68
89
|
const strikethrough = document.createElement('span');
|
|
69
|
-
strikethrough.setAttribute('style', getDeletedContentStyleUnbounded(
|
|
90
|
+
strikethrough.setAttribute('style', getDeletedContentStyleUnbounded(colorScheme));
|
|
70
91
|
wrapper.append(strikethrough);
|
|
71
92
|
return wrapper;
|
|
72
93
|
};
|
|
@@ -74,7 +95,7 @@ export const createDeletedContentDecoration = ({
|
|
|
74
95
|
change,
|
|
75
96
|
doc,
|
|
76
97
|
nodeViewSerializer,
|
|
77
|
-
|
|
98
|
+
colorScheme,
|
|
78
99
|
newDoc,
|
|
79
100
|
intl,
|
|
80
101
|
isActive = false
|
|
@@ -94,7 +115,7 @@ export const createDeletedContentDecoration = ({
|
|
|
94
115
|
}
|
|
95
116
|
const {
|
|
96
117
|
decorations
|
|
97
|
-
} = handleDeletedRows([change], doc, newDoc, nodeViewSerializer,
|
|
118
|
+
} = handleDeletedRows([change], doc, newDoc, nodeViewSerializer, colorScheme);
|
|
98
119
|
return decorations;
|
|
99
120
|
}
|
|
100
121
|
const serializer = nodeViewSerializer;
|
|
@@ -116,14 +137,14 @@ export const createDeletedContentDecoration = ({
|
|
|
116
137
|
if (childNodeView) {
|
|
117
138
|
const lineBreak = document.createElement('br');
|
|
118
139
|
dom.append(lineBreak);
|
|
119
|
-
const wrapper = createContentWrapper(
|
|
140
|
+
const wrapper = createContentWrapper(colorScheme, isActive);
|
|
120
141
|
wrapper.append(childNodeView);
|
|
121
142
|
dom.append(wrapper);
|
|
122
143
|
} else {
|
|
123
144
|
// Fallback to serializing the individual child node
|
|
124
145
|
const serializedChild = serializer.serializeNode(childNode);
|
|
125
146
|
if (serializedChild) {
|
|
126
|
-
const wrapper = createContentWrapper(
|
|
147
|
+
const wrapper = createContentWrapper(colorScheme, isActive);
|
|
127
148
|
wrapper.append(serializedChild);
|
|
128
149
|
dom.append(wrapper);
|
|
129
150
|
}
|
|
@@ -164,12 +185,12 @@ export const createDeletedContentDecoration = ({
|
|
|
164
185
|
const nodeView = serializer.tryCreateNodeView(node);
|
|
165
186
|
if (nodeView) {
|
|
166
187
|
if (node.isInline) {
|
|
167
|
-
const wrapper = createContentWrapper(
|
|
188
|
+
const wrapper = createContentWrapper(colorScheme, isActive);
|
|
168
189
|
wrapper.append(nodeView);
|
|
169
190
|
dom.append(wrapper);
|
|
170
191
|
} else {
|
|
171
192
|
// Handle all block nodes with unified function
|
|
172
|
-
handleBlockNodeView(dom, nodeView, node,
|
|
193
|
+
handleBlockNodeView(dom, nodeView, node, colorScheme, intl);
|
|
173
194
|
}
|
|
174
195
|
} else if (nodeViewSerializer.getFilteredNodeViewBlocklist(['paragraph', 'tableRow']).has(node.type.name)) {
|
|
175
196
|
// Skip the case where the node is a paragraph or table row that way it can still be rendered and delete the entire table
|
|
@@ -177,7 +198,7 @@ export const createDeletedContentDecoration = ({
|
|
|
177
198
|
} else {
|
|
178
199
|
const fallbackNode = fallbackSerialization();
|
|
179
200
|
if (fallbackNode) {
|
|
180
|
-
const wrapper = createDeletedStyleWrapperWithoutOpacity(
|
|
201
|
+
const wrapper = createDeletedStyleWrapperWithoutOpacity(colorScheme, isActive);
|
|
181
202
|
wrapper.append(fallbackNode);
|
|
182
203
|
dom.append(wrapper);
|
|
183
204
|
}
|
|
@@ -188,5 +209,7 @@ export const createDeletedContentDecoration = ({
|
|
|
188
209
|
// Widget decoration used for deletions as the content is not in the document
|
|
189
210
|
// and we want to display the deleted content with a style.
|
|
190
211
|
const safeInsertPos = findSafeInsertPos(newDoc, change.fromB, slice);
|
|
191
|
-
return [Decoration.widget(safeInsertPos, dom
|
|
212
|
+
return [Decoration.widget(safeInsertPos, dom, {
|
|
213
|
+
key: 'diff-widget'
|
|
214
|
+
})];
|
|
192
215
|
};
|
|
@@ -53,8 +53,8 @@ const lozengeStyle = convertToInlineCss({
|
|
|
53
53
|
whiteSpace: 'nowrap',
|
|
54
54
|
color: "var(--ds-text-warning-inverse, #292A2E)"
|
|
55
55
|
});
|
|
56
|
-
export const getDeletedStyleNode = (nodeName,
|
|
57
|
-
const isTraditional =
|
|
56
|
+
export const getDeletedStyleNode = (nodeName, colorScheme) => {
|
|
57
|
+
const isTraditional = colorScheme === 'traditional';
|
|
58
58
|
switch (nodeName) {
|
|
59
59
|
case 'blockquote':
|
|
60
60
|
return fg('platform_editor_ai_aifc_patch_ga_blockers') ? isTraditional ? deletedTraditionalStyleQuoteNode : deletedStyleQuoteNodeWithLozenge : deletedStyleQuoteNode;
|
|
@@ -154,29 +154,29 @@ export const createBlockNodeWrapper = () => {
|
|
|
154
154
|
/**
|
|
155
155
|
* Wraps content with deleted styling without opacity (for use when content is a direct child of dom)
|
|
156
156
|
*/
|
|
157
|
-
export const createDeletedStyleWrapperWithoutOpacity = (
|
|
157
|
+
export const createDeletedStyleWrapperWithoutOpacity = (colorScheme, isActive) => {
|
|
158
158
|
const wrapper = document.createElement('span');
|
|
159
|
-
wrapper.setAttribute('style', getDeletedContentStyle(
|
|
159
|
+
wrapper.setAttribute('style', getDeletedContentStyle(colorScheme, isActive));
|
|
160
160
|
return wrapper;
|
|
161
161
|
};
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
164
|
* Applies deleted styles directly to an HTML element by merging with existing styles
|
|
165
165
|
*/
|
|
166
|
-
export const applyDeletedStylesToElement = (element, targetNode,
|
|
166
|
+
export const applyDeletedStylesToElement = (element, targetNode, colorScheme) => {
|
|
167
167
|
const currentStyle = element.getAttribute('style') || '';
|
|
168
|
-
const deletedContentStyle = getDeletedContentStyle(
|
|
169
|
-
const nodeSpecificStyle = getDeletedStyleNode(targetNode.type.name,
|
|
168
|
+
const deletedContentStyle = getDeletedContentStyle(colorScheme);
|
|
169
|
+
const nodeSpecificStyle = getDeletedStyleNode(targetNode.type.name, colorScheme) || '';
|
|
170
170
|
element.setAttribute('style', `${currentStyle}${deletedContentStyle}${nodeSpecificStyle}`);
|
|
171
171
|
};
|
|
172
172
|
|
|
173
173
|
/**
|
|
174
174
|
* Creates a content wrapper with deleted styles for a block node
|
|
175
175
|
*/
|
|
176
|
-
export const createBlockNodeContentWrapper = (nodeView, targetNode,
|
|
176
|
+
export const createBlockNodeContentWrapper = (nodeView, targetNode, colorScheme) => {
|
|
177
177
|
const contentWrapper = document.createElement('div');
|
|
178
|
-
const nodeStyle = getDeletedStyleNode(targetNode.type.name,
|
|
179
|
-
contentWrapper.setAttribute('style', `${getDeletedContentStyle(
|
|
178
|
+
const nodeStyle = getDeletedStyleNode(targetNode.type.name, colorScheme);
|
|
179
|
+
contentWrapper.setAttribute('style', `${getDeletedContentStyle(colorScheme)}${nodeStyle || ''}`);
|
|
180
180
|
contentWrapper.append(nodeView);
|
|
181
181
|
return contentWrapper;
|
|
182
182
|
};
|
|
@@ -187,7 +187,7 @@ export const createBlockNodeContentWrapper = (nodeView, targetNode, colourScheme
|
|
|
187
187
|
* to wait for the rich-media-item to appear before attaching the lozenge.
|
|
188
188
|
* @returns true if embedCard was handled
|
|
189
189
|
*/
|
|
190
|
-
export const handleEmbedCardWithLozenge = (dom, nodeView, targetNode, lozenge,
|
|
190
|
+
export const handleEmbedCardWithLozenge = (dom, nodeView, targetNode, lozenge, colorScheme) => {
|
|
191
191
|
if (targetNode.type.name !== 'embedCard' || !(nodeView instanceof HTMLElement)) {
|
|
192
192
|
return false;
|
|
193
193
|
}
|
|
@@ -208,7 +208,7 @@ export const handleEmbedCardWithLozenge = (dom, nodeView, targetNode, lozenge, c
|
|
|
208
208
|
});
|
|
209
209
|
}
|
|
210
210
|
if (shouldAddShowDiffDeletedNodeClass(targetNode.type.name)) {
|
|
211
|
-
const showDiffDeletedNodeClass =
|
|
211
|
+
const showDiffDeletedNodeClass = colorScheme === 'traditional' ? 'show-diff-deleted-node-traditional' : 'show-diff-deleted-node';
|
|
212
212
|
nodeView.classList.add(showDiffDeletedNodeClass);
|
|
213
213
|
}
|
|
214
214
|
dom.append(nodeView);
|
|
@@ -219,7 +219,7 @@ export const handleEmbedCardWithLozenge = (dom, nodeView, targetNode, lozenge, c
|
|
|
219
219
|
* Handles special mediaSingle node rendering with lozenge on child media element
|
|
220
220
|
* @returns true if mediaSingle was handled, false otherwise
|
|
221
221
|
*/
|
|
222
|
-
export const handleMediaSingleWithLozenge = (dom, nodeView, targetNode, lozenge,
|
|
222
|
+
export const handleMediaSingleWithLozenge = (dom, nodeView, targetNode, lozenge, colorScheme) => {
|
|
223
223
|
if (targetNode.type.name !== 'mediaSingle' || !(nodeView instanceof HTMLElement)) {
|
|
224
224
|
return false;
|
|
225
225
|
}
|
|
@@ -238,7 +238,7 @@ export const handleMediaSingleWithLozenge = (dom, nodeView, targetNode, lozenge,
|
|
|
238
238
|
|
|
239
239
|
// Add deleted node class if needed
|
|
240
240
|
if (shouldAddShowDiffDeletedNodeClass(targetNode.type.name)) {
|
|
241
|
-
const showDiffDeletedNodeClass =
|
|
241
|
+
const showDiffDeletedNodeClass = colorScheme === 'traditional' && fg('platform_editor_ai_aifc_patch_ga_blockers') ? 'show-diff-deleted-node-traditional' : 'show-diff-deleted-node';
|
|
242
242
|
nodeView.classList.add(showDiffDeletedNodeClass);
|
|
243
243
|
}
|
|
244
244
|
dom.append(nodeView);
|
|
@@ -248,22 +248,22 @@ export const handleMediaSingleWithLozenge = (dom, nodeView, targetNode, lozenge,
|
|
|
248
248
|
/**
|
|
249
249
|
* Appends a block node with wrapper, lozenge, and appropriate styling
|
|
250
250
|
*/
|
|
251
|
-
export const appendBlockNodeWithWrapper = (dom, nodeView, targetNode,
|
|
251
|
+
export const appendBlockNodeWithWrapper = (dom, nodeView, targetNode, colorScheme, intl) => {
|
|
252
252
|
const blockWrapper = createBlockNodeWrapper();
|
|
253
253
|
if (shouldShowRemovedLozenge(targetNode.type.name)) {
|
|
254
254
|
const lozenge = createRemovedLozenge(intl);
|
|
255
|
-
if (handleEmbedCardWithLozenge(dom, nodeView, targetNode, lozenge,
|
|
255
|
+
if (handleEmbedCardWithLozenge(dom, nodeView, targetNode, lozenge, colorScheme) && fg('platform_editor_ai_aifc_patch_ga_blockers')) {
|
|
256
256
|
return;
|
|
257
257
|
}
|
|
258
|
-
if (handleMediaSingleWithLozenge(dom, nodeView, targetNode, lozenge,
|
|
258
|
+
if (handleMediaSingleWithLozenge(dom, nodeView, targetNode, lozenge, colorScheme)) {
|
|
259
259
|
return;
|
|
260
260
|
}
|
|
261
261
|
blockWrapper.append(lozenge);
|
|
262
262
|
}
|
|
263
|
-
const contentWrapper = createBlockNodeContentWrapper(nodeView, targetNode,
|
|
263
|
+
const contentWrapper = createBlockNodeContentWrapper(nodeView, targetNode, colorScheme);
|
|
264
264
|
blockWrapper.append(contentWrapper);
|
|
265
265
|
if (nodeView instanceof HTMLElement && shouldAddShowDiffDeletedNodeClass(targetNode.type.name)) {
|
|
266
|
-
const showDiffDeletedNodeClass =
|
|
266
|
+
const showDiffDeletedNodeClass = colorScheme === 'traditional' && fg('platform_editor_ai_aifc_patch_ga_blockers') ? 'show-diff-deleted-node-traditional' : 'show-diff-deleted-node';
|
|
267
267
|
nodeView.classList.add(showDiffDeletedNodeClass);
|
|
268
268
|
}
|
|
269
269
|
dom.append(blockWrapper);
|
|
@@ -274,13 +274,13 @@ export const appendBlockNodeWithWrapper = (dom, nodeView, targetNode, colourSche
|
|
|
274
274
|
* For heading nodes, applies styles directly to preserve natural margins.
|
|
275
275
|
* For other block nodes, uses wrapper approach with optional lozenge.
|
|
276
276
|
*/
|
|
277
|
-
export const handleBlockNodeView = (dom, nodeView, targetNode,
|
|
277
|
+
export const handleBlockNodeView = (dom, nodeView, targetNode, colorScheme, intl) => {
|
|
278
278
|
if (shouldApplyDeletedStylesDirectly(targetNode.type.name) && nodeView instanceof HTMLElement) {
|
|
279
279
|
// Apply deleted styles directly to preserve natural block-level margins
|
|
280
|
-
applyDeletedStylesToElement(nodeView, targetNode,
|
|
280
|
+
applyDeletedStylesToElement(nodeView, targetNode, colorScheme);
|
|
281
281
|
dom.append(nodeView);
|
|
282
282
|
} else {
|
|
283
283
|
// Use wrapper approach for other block nodes
|
|
284
|
-
appendBlockNodeWithWrapper(dom, nodeView, targetNode,
|
|
284
|
+
appendBlockNodeWithWrapper(dom, nodeView, targetNode, colorScheme, intl);
|
|
285
285
|
}
|
|
286
286
|
};
|
|
@@ -50,7 +50,7 @@ const extractDeletedRows = (change, originalDoc, newDoc) => {
|
|
|
50
50
|
const changeEndInTable = change.toA - tableOld.pos - 1;
|
|
51
51
|
let currentOffset = 0;
|
|
52
52
|
let rowIndex = 0;
|
|
53
|
-
tableOld.node.content.forEach(
|
|
53
|
+
tableOld.node.content.forEach(rowNode => {
|
|
54
54
|
const rowStart = currentOffset;
|
|
55
55
|
const rowEnd = currentOffset + rowNode.nodeSize;
|
|
56
56
|
|
|
@@ -107,9 +107,9 @@ const isEmptyRow = rowNode => {
|
|
|
107
107
|
/**
|
|
108
108
|
* Creates a DOM representation of a deleted table row
|
|
109
109
|
*/
|
|
110
|
-
const createDeletedRowDOM = (rowNode, nodeViewSerializer,
|
|
110
|
+
const createDeletedRowDOM = (rowNode, nodeViewSerializer, colorScheme) => {
|
|
111
111
|
const tr = document.createElement('tr');
|
|
112
|
-
tr.setAttribute('style',
|
|
112
|
+
tr.setAttribute('style', colorScheme === 'traditional' ? deletedTraditionalRowStyle : deletedRowStyle);
|
|
113
113
|
tr.setAttribute('data-testid', 'show-diff-deleted-row');
|
|
114
114
|
|
|
115
115
|
// Serialize each cell in the row
|
|
@@ -153,10 +153,10 @@ export const createDeletedRowsDecorations = ({
|
|
|
153
153
|
originalDoc,
|
|
154
154
|
newDoc,
|
|
155
155
|
nodeViewSerializer,
|
|
156
|
-
|
|
156
|
+
colorScheme
|
|
157
157
|
}) => {
|
|
158
158
|
return deletedRows.map(deletedRow => {
|
|
159
|
-
const rowDOM = createDeletedRowDOM(deletedRow.rowNode, nodeViewSerializer,
|
|
159
|
+
const rowDOM = createDeletedRowDOM(deletedRow.rowNode, nodeViewSerializer, colorScheme);
|
|
160
160
|
|
|
161
161
|
// Find safe insertion position for the deleted row
|
|
162
162
|
const safeInsertPos = findSafeInsertPos(newDoc, deletedRow.fromB - 1,
|
|
@@ -169,7 +169,7 @@ export const createDeletedRowsDecorations = ({
|
|
|
169
169
|
/**
|
|
170
170
|
* Main function to handle deleted rows - computes diff and creates decorations
|
|
171
171
|
*/
|
|
172
|
-
export const handleDeletedRows = (changes, originalDoc, newDoc, nodeViewSerializer,
|
|
172
|
+
export const handleDeletedRows = (changes, originalDoc, newDoc, nodeViewSerializer, colorScheme) => {
|
|
173
173
|
// First, expand the changes to include complete deleted rows
|
|
174
174
|
const deletedRows = expandDiffForDeletedRows(changes.filter(change => change.deleted.length > 0), originalDoc, newDoc);
|
|
175
175
|
const allDecorations = createDeletedRowsDecorations({
|
|
@@ -177,7 +177,7 @@ export const handleDeletedRows = (changes, originalDoc, newDoc, nodeViewSerializ
|
|
|
177
177
|
originalDoc,
|
|
178
178
|
newDoc,
|
|
179
179
|
nodeViewSerializer,
|
|
180
|
-
|
|
180
|
+
colorScheme
|
|
181
181
|
});
|
|
182
182
|
return {
|
|
183
183
|
decorations: allDecorations
|
|
@@ -7,6 +7,10 @@ import { fg } from '@atlaskit/platform-feature-flags';
|
|
|
7
7
|
import { calculateDiffDecorations } from './calculateDiffDecorations';
|
|
8
8
|
import { NodeViewSerializer } from './NodeViewSerializer';
|
|
9
9
|
export const showDiffPluginKey = new PluginKey('showDiffPlugin');
|
|
10
|
+
export const getScrollableDecorations = set => {
|
|
11
|
+
var _set$find;
|
|
12
|
+
return (_set$find = set === null || set === void 0 ? void 0 : set.find(undefined, undefined, spec => spec.key === 'diff-inline' || spec.key === 'diff-widget' || spec.key === 'diff-block')) !== null && _set$find !== void 0 ? _set$find : [];
|
|
13
|
+
};
|
|
10
14
|
export const createPlugin = (config, getIntl) => {
|
|
11
15
|
const nodeViewSerializer = new NodeViewSerializer({});
|
|
12
16
|
const setNodeViewSerializer = editorView => {
|
|
@@ -33,7 +37,7 @@ export const createPlugin = (config, getIntl) => {
|
|
|
33
37
|
if (!pluginState || pluginState.decorations.find().length === 0) {
|
|
34
38
|
return;
|
|
35
39
|
}
|
|
36
|
-
const decorations = pluginState.decorations
|
|
40
|
+
const decorations = getScrollableDecorations(pluginState.decorations);
|
|
37
41
|
const decoration = decorations[(_pluginState$activeIn = pluginState.activeIndex) !== null && _pluginState$activeIn !== void 0 ? _pluginState$activeIn : 0];
|
|
38
42
|
if (!decoration) {
|
|
39
43
|
return;
|
|
@@ -79,7 +83,7 @@ export const createPlugin = (config, getIntl) => {
|
|
|
79
83
|
state: newState,
|
|
80
84
|
pluginState: newPluginState,
|
|
81
85
|
nodeViewSerializer,
|
|
82
|
-
|
|
86
|
+
colorScheme: config === null || config === void 0 ? void 0 : config.colorScheme,
|
|
83
87
|
intl: getIntl(),
|
|
84
88
|
activeIndexPos: fg('platform_editor_show_diff_scroll_navigation') ? newPluginState.activeIndexPos : undefined
|
|
85
89
|
});
|
|
@@ -95,7 +99,7 @@ export const createPlugin = (config, getIntl) => {
|
|
|
95
99
|
};
|
|
96
100
|
} else if (((meta === null || meta === void 0 ? void 0 : meta.action) === 'SCROLL_TO_NEXT' || (meta === null || meta === void 0 ? void 0 : meta.action) === 'SCROLL_TO_PREVIOUS') && fg('platform_editor_show_diff_scroll_navigation')) {
|
|
97
101
|
// Update the active index in plugin state and recalculate decorations
|
|
98
|
-
const decorations = currentPluginState.decorations
|
|
102
|
+
const decorations = getScrollableDecorations(currentPluginState.decorations);
|
|
99
103
|
if (decorations.length > 0) {
|
|
100
104
|
var _currentPluginState$a;
|
|
101
105
|
let nextIndex = (_currentPluginState$a = currentPluginState.activeIndex) !== null && _currentPluginState$a !== void 0 ? _currentPluginState$a : 0;
|
|
@@ -118,7 +122,7 @@ export const createPlugin = (config, getIntl) => {
|
|
|
118
122
|
state: newState,
|
|
119
123
|
pluginState: newPluginState,
|
|
120
124
|
nodeViewSerializer,
|
|
121
|
-
|
|
125
|
+
colorScheme: config === null || config === void 0 ? void 0 : config.colorScheme,
|
|
122
126
|
intl: getIntl(),
|
|
123
127
|
activeIndexPos: newPluginState.activeIndexPos
|
|
124
128
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
|
+
import { createPlugin, showDiffPluginKey, getScrollableDecorations } from './pm-plugins/main';
|
|
2
3
|
export const showDiffPlugin = ({
|
|
3
4
|
api: _api,
|
|
4
5
|
config
|
|
@@ -53,7 +54,7 @@ export const showDiffPlugin = ({
|
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
const pluginState = showDiffPluginKey.getState(editorState);
|
|
56
|
-
const decorationCount = (pluginState === null || pluginState === void 0 ? void 0 : (_pluginState$decorati = pluginState.decorations) === null || _pluginState$decorati === void 0 ? void 0 : _pluginState$decorati.find()) || [];
|
|
57
|
+
const decorationCount = fg('platform_editor_show_diff_scroll_navigation') ? getScrollableDecorations(pluginState === null || pluginState === void 0 ? void 0 : pluginState.decorations) : (pluginState === null || pluginState === void 0 ? void 0 : (_pluginState$decorati = pluginState.decorations) === null || _pluginState$decorati === void 0 ? void 0 : _pluginState$decorati.find()) || [];
|
|
57
58
|
return {
|
|
58
59
|
isDisplayingChanges: decorationCount.length > 0,
|
|
59
60
|
activeIndex: pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex,
|
|
@@ -16,16 +16,19 @@ import { getAttrChangeRanges, stepIsValidAttrChange } from './attributeDecoratio
|
|
|
16
16
|
import { createInlineChangedDecoration, createDeletedContentDecoration, createBlockChangedDecoration } from './decorations';
|
|
17
17
|
import { getMarkChangeRanges } from './markDecorations';
|
|
18
18
|
import { simplifySteps } from './simplifyChanges';
|
|
19
|
-
var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration(doc, from, to,
|
|
19
|
+
var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration(doc, from, to, colorScheme) {
|
|
20
20
|
var decorations = [];
|
|
21
21
|
// Iterate over the document nodes within the range
|
|
22
22
|
doc.nodesBetween(from, to, function (node, pos) {
|
|
23
23
|
if (node.isBlock) {
|
|
24
|
-
|
|
24
|
+
var decoration = createBlockChangedDecoration({
|
|
25
25
|
from: pos,
|
|
26
26
|
to: pos + node.nodeSize,
|
|
27
27
|
name: node.type.name
|
|
28
|
-
},
|
|
28
|
+
}, colorScheme);
|
|
29
|
+
if (decoration) {
|
|
30
|
+
decorations.push(decoration);
|
|
31
|
+
}
|
|
29
32
|
}
|
|
30
33
|
});
|
|
31
34
|
return decorations;
|
|
@@ -67,7 +70,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref)
|
|
|
67
70
|
var state = _ref.state,
|
|
68
71
|
pluginState = _ref.pluginState,
|
|
69
72
|
nodeViewSerializer = _ref.nodeViewSerializer,
|
|
70
|
-
|
|
73
|
+
colorScheme = _ref.colorScheme,
|
|
71
74
|
intl = _ref.intl,
|
|
72
75
|
activeIndexPos = _ref.activeIndexPos;
|
|
73
76
|
var originalDoc = pluginState.originalDoc,
|
|
@@ -112,8 +115,8 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref)
|
|
|
112
115
|
optimizedChanges.forEach(function (change) {
|
|
113
116
|
var isActive = activeIndexPos && change.fromB >= activeIndexPos.from && change.toB <= activeIndexPos.to;
|
|
114
117
|
if (change.inserted.length > 0) {
|
|
115
|
-
decorations.push(createInlineChangedDecoration(change,
|
|
116
|
-
decorations.push.apply(decorations, _toConsumableArray(calculateNodesForBlockDecoration(tr.doc, change.fromB, change.toB,
|
|
118
|
+
decorations.push(createInlineChangedDecoration(change, colorScheme, isActive));
|
|
119
|
+
decorations.push.apply(decorations, _toConsumableArray(calculateNodesForBlockDecoration(tr.doc, change.fromB, change.toB, colorScheme)));
|
|
117
120
|
}
|
|
118
121
|
if (change.deleted.length > 0) {
|
|
119
122
|
var _isActive = activeIndexPos && change.fromB >= activeIndexPos.from && change.toB <= activeIndexPos.to;
|
|
@@ -121,7 +124,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref)
|
|
|
121
124
|
change: change,
|
|
122
125
|
doc: originalDoc,
|
|
123
126
|
nodeViewSerializer: nodeViewSerializer,
|
|
124
|
-
|
|
127
|
+
colorScheme: colorScheme,
|
|
125
128
|
newDoc: tr.doc,
|
|
126
129
|
intl: intl,
|
|
127
130
|
isActive: _isActive
|
|
@@ -133,10 +136,10 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref)
|
|
|
133
136
|
});
|
|
134
137
|
getMarkChangeRanges(steps).forEach(function (change) {
|
|
135
138
|
var isActive = activeIndexPos && change.fromB >= activeIndexPos.from && change.toB <= activeIndexPos.to;
|
|
136
|
-
decorations.push(createInlineChangedDecoration(change,
|
|
139
|
+
decorations.push(createInlineChangedDecoration(change, colorScheme, isActive));
|
|
137
140
|
});
|
|
138
141
|
getAttrChangeRanges(tr.doc, attrSteps).forEach(function (change) {
|
|
139
|
-
decorations.push.apply(decorations, _toConsumableArray(calculateNodesForBlockDecoration(tr.doc, change.fromB, change.toB,
|
|
142
|
+
decorations.push.apply(decorations, _toConsumableArray(calculateNodesForBlockDecoration(tr.doc, change.fromB, change.toB, colorScheme)));
|
|
140
143
|
});
|
|
141
144
|
return DecorationSet.empty.add(tr.doc, decorations);
|
|
142
145
|
};
|
|
@@ -148,16 +151,16 @@ function (_ref2, _ref3) {
|
|
|
148
151
|
_ref4$ = _ref4[0],
|
|
149
152
|
pluginState = _ref4$.pluginState,
|
|
150
153
|
state = _ref4$.state,
|
|
151
|
-
|
|
154
|
+
colorScheme = _ref4$.colorScheme,
|
|
152
155
|
intl = _ref4$.intl,
|
|
153
156
|
activeIndexPos = _ref4$.activeIndexPos;
|
|
154
157
|
var _ref5 = _slicedToArray(_ref3, 1),
|
|
155
158
|
_ref5$ = _ref5[0],
|
|
156
159
|
lastPluginState = _ref5$.pluginState,
|
|
157
160
|
lastState = _ref5$.state,
|
|
158
|
-
|
|
161
|
+
lastColorScheme = _ref5$.colorScheme,
|
|
159
162
|
lastIntl = _ref5$.intl,
|
|
160
163
|
lastActiveIndexPos = _ref5$.activeIndexPos;
|
|
161
164
|
var originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
|
|
162
|
-
return (_ref6 = originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) &&
|
|
165
|
+
return (_ref6 = originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isEqual(activeIndexPos, lastActiveIndexPos)) !== null && _ref6 !== void 0 ? _ref6 : false;
|
|
163
166
|
});
|
|
@@ -13,10 +13,10 @@ import { findSafeInsertPos } from './findSafeInsertPos';
|
|
|
13
13
|
* @param change Changeset "change" containing information about the change content + range
|
|
14
14
|
* @returns Prosemirror inline decoration
|
|
15
15
|
*/
|
|
16
|
-
export var createInlineChangedDecoration = function createInlineChangedDecoration(change,
|
|
16
|
+
export var createInlineChangedDecoration = function createInlineChangedDecoration(change, colorScheme) {
|
|
17
17
|
var isActive = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
18
18
|
var style;
|
|
19
|
-
if (
|
|
19
|
+
if (colorScheme === 'traditional') {
|
|
20
20
|
style = isActive ? traditionalInsertStyleActive : traditionalInsertStyle;
|
|
21
21
|
} else {
|
|
22
22
|
style = isActive ? editingStyleActive : editingStyle;
|
|
@@ -24,14 +24,16 @@ export var createInlineChangedDecoration = function createInlineChangedDecoratio
|
|
|
24
24
|
return Decoration.inline(change.fromB, change.toB, {
|
|
25
25
|
style: style,
|
|
26
26
|
'data-testid': 'show-diff-changed-decoration'
|
|
27
|
-
}, {
|
|
27
|
+
}, {
|
|
28
|
+
key: 'diff-inline'
|
|
29
|
+
});
|
|
28
30
|
};
|
|
29
|
-
export var getDeletedContentStyleUnbounded = function getDeletedContentStyleUnbounded(
|
|
30
|
-
return
|
|
31
|
+
export var getDeletedContentStyleUnbounded = function getDeletedContentStyleUnbounded(colorScheme) {
|
|
32
|
+
return colorScheme === 'traditional' ? deletedTraditionalContentStyleUnbounded : deletedContentStyleUnbounded;
|
|
31
33
|
};
|
|
32
|
-
export var getDeletedContentStyle = function getDeletedContentStyle(
|
|
34
|
+
export var getDeletedContentStyle = function getDeletedContentStyle(colorScheme) {
|
|
33
35
|
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
34
|
-
if (
|
|
36
|
+
if (colorScheme === 'traditional') {
|
|
35
37
|
return deletedTraditionalContentStyle;
|
|
36
38
|
}
|
|
37
39
|
if (isActive) {
|
|
@@ -47,8 +49,8 @@ var getNodeClass = function getNodeClass(name) {
|
|
|
47
49
|
return undefined;
|
|
48
50
|
}
|
|
49
51
|
};
|
|
50
|
-
var getBlockNodeStyle = function getBlockNodeStyle(name,
|
|
51
|
-
return
|
|
52
|
+
var getBlockNodeStyle = function getBlockNodeStyle(name, colorScheme) {
|
|
53
|
+
return colorScheme === 'traditional' ? getTraditionalNodeStyle(name) : getStandardNodeStyle(name);
|
|
52
54
|
};
|
|
53
55
|
|
|
54
56
|
/**
|
|
@@ -57,23 +59,40 @@ var getBlockNodeStyle = function getBlockNodeStyle(name, colourScheme) {
|
|
|
57
59
|
* @param change Changeset "change" containing information about the change content + range
|
|
58
60
|
* @returns Prosemirror inline decoration
|
|
59
61
|
*/
|
|
60
|
-
export var createBlockChangedDecoration = function createBlockChangedDecoration(change,
|
|
61
|
-
|
|
62
|
-
style
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
export var createBlockChangedDecoration = function createBlockChangedDecoration(change, colorScheme) {
|
|
63
|
+
if (fg('platform_editor_show_diff_scroll_navigation')) {
|
|
64
|
+
var style = getBlockNodeStyle(change.name, colorScheme);
|
|
65
|
+
var className = getNodeClass(change.name);
|
|
66
|
+
if (style || className) {
|
|
67
|
+
return Decoration.node(change.from, change.to, {
|
|
68
|
+
style: style,
|
|
69
|
+
'data-testid': 'show-diff-changed-decoration-node',
|
|
70
|
+
class: className
|
|
71
|
+
}, {
|
|
72
|
+
key: 'diff-block'
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
} else {
|
|
77
|
+
return Decoration.node(change.from, change.to, {
|
|
78
|
+
style: getBlockNodeStyle(change.name, colorScheme),
|
|
79
|
+
'data-testid': 'show-diff-changed-decoration-node',
|
|
80
|
+
class: getNodeClass(change.name)
|
|
81
|
+
}, {
|
|
82
|
+
key: 'diff-block'
|
|
83
|
+
});
|
|
84
|
+
}
|
|
66
85
|
};
|
|
67
|
-
var createContentWrapper = function createContentWrapper(
|
|
86
|
+
var createContentWrapper = function createContentWrapper(colorScheme) {
|
|
68
87
|
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
69
88
|
var wrapper = document.createElement('span');
|
|
70
89
|
var baseStyle = convertToInlineCss({
|
|
71
90
|
position: 'relative',
|
|
72
91
|
width: 'fit-content'
|
|
73
92
|
});
|
|
74
|
-
wrapper.setAttribute('style', "".concat(baseStyle).concat(getDeletedContentStyle(
|
|
93
|
+
wrapper.setAttribute('style', "".concat(baseStyle).concat(getDeletedContentStyle(colorScheme, isActive)));
|
|
75
94
|
var strikethrough = document.createElement('span');
|
|
76
|
-
strikethrough.setAttribute('style', getDeletedContentStyleUnbounded(
|
|
95
|
+
strikethrough.setAttribute('style', getDeletedContentStyleUnbounded(colorScheme));
|
|
77
96
|
wrapper.append(strikethrough);
|
|
78
97
|
return wrapper;
|
|
79
98
|
};
|
|
@@ -81,7 +100,7 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
|
|
|
81
100
|
var change = _ref.change,
|
|
82
101
|
doc = _ref.doc,
|
|
83
102
|
nodeViewSerializer = _ref.nodeViewSerializer,
|
|
84
|
-
|
|
103
|
+
colorScheme = _ref.colorScheme,
|
|
85
104
|
newDoc = _ref.newDoc,
|
|
86
105
|
intl = _ref.intl,
|
|
87
106
|
_ref$isActive = _ref.isActive,
|
|
@@ -107,7 +126,7 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
|
|
|
107
126
|
if (!fg('platform_editor_ai_aifc_patch_ga')) {
|
|
108
127
|
return;
|
|
109
128
|
}
|
|
110
|
-
var _handleDeletedRows = handleDeletedRows([change], doc, newDoc, nodeViewSerializer,
|
|
129
|
+
var _handleDeletedRows = handleDeletedRows([change], doc, newDoc, nodeViewSerializer, colorScheme),
|
|
111
130
|
decorations = _handleDeletedRows.decorations;
|
|
112
131
|
return decorations;
|
|
113
132
|
}
|
|
@@ -130,14 +149,14 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
|
|
|
130
149
|
if (childNodeView) {
|
|
131
150
|
var lineBreak = document.createElement('br');
|
|
132
151
|
dom.append(lineBreak);
|
|
133
|
-
var wrapper = createContentWrapper(
|
|
152
|
+
var wrapper = createContentWrapper(colorScheme, isActive);
|
|
134
153
|
wrapper.append(childNodeView);
|
|
135
154
|
dom.append(wrapper);
|
|
136
155
|
} else {
|
|
137
156
|
// Fallback to serializing the individual child node
|
|
138
157
|
var serializedChild = serializer.serializeNode(childNode);
|
|
139
158
|
if (serializedChild) {
|
|
140
|
-
var _wrapper = createContentWrapper(
|
|
159
|
+
var _wrapper = createContentWrapper(colorScheme, isActive);
|
|
141
160
|
_wrapper.append(serializedChild);
|
|
142
161
|
dom.append(_wrapper);
|
|
143
162
|
}
|
|
@@ -182,12 +201,12 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
|
|
|
182
201
|
var nodeView = serializer.tryCreateNodeView(node);
|
|
183
202
|
if (nodeView) {
|
|
184
203
|
if (node.isInline) {
|
|
185
|
-
var wrapper = createContentWrapper(
|
|
204
|
+
var wrapper = createContentWrapper(colorScheme, isActive);
|
|
186
205
|
wrapper.append(nodeView);
|
|
187
206
|
dom.append(wrapper);
|
|
188
207
|
} else {
|
|
189
208
|
// Handle all block nodes with unified function
|
|
190
|
-
handleBlockNodeView(dom, nodeView, node,
|
|
209
|
+
handleBlockNodeView(dom, nodeView, node, colorScheme, intl);
|
|
191
210
|
}
|
|
192
211
|
} else if (nodeViewSerializer.getFilteredNodeViewBlocklist(['paragraph', 'tableRow']).has(node.type.name)) {
|
|
193
212
|
// Skip the case where the node is a paragraph or table row that way it can still be rendered and delete the entire table
|
|
@@ -195,7 +214,7 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
|
|
|
195
214
|
} else {
|
|
196
215
|
var fallbackNode = fallbackSerialization();
|
|
197
216
|
if (fallbackNode) {
|
|
198
|
-
var _wrapper2 = createDeletedStyleWrapperWithoutOpacity(
|
|
217
|
+
var _wrapper2 = createDeletedStyleWrapperWithoutOpacity(colorScheme, isActive);
|
|
199
218
|
_wrapper2.append(fallbackNode);
|
|
200
219
|
dom.append(_wrapper2);
|
|
201
220
|
}
|
|
@@ -206,5 +225,7 @@ export var createDeletedContentDecoration = function createDeletedContentDecorat
|
|
|
206
225
|
// Widget decoration used for deletions as the content is not in the document
|
|
207
226
|
// and we want to display the deleted content with a style.
|
|
208
227
|
var safeInsertPos = findSafeInsertPos(newDoc, change.fromB, slice);
|
|
209
|
-
return [Decoration.widget(safeInsertPos, dom
|
|
228
|
+
return [Decoration.widget(safeInsertPos, dom, {
|
|
229
|
+
key: 'diff-widget'
|
|
230
|
+
})];
|
|
210
231
|
};
|