@atlaskit/editor-plugin-show-diff 9.1.1 → 10.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 +37 -0
- package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +24 -19
- package/dist/cjs/pm-plugins/decorations/createBlockChangedDecoration.js +14 -14
- package/dist/cjs/pm-plugins/decorations/createChangedRowDecorationWidgets.js +10 -1
- package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +13 -12
- package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +8 -8
- package/dist/cjs/pm-plugins/decorations/decorationKeys.js +49 -8
- package/dist/cjs/pm-plugins/main.js +41 -29
- package/dist/cjs/showDiffPlugin.js +8 -4
- package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +21 -16
- package/dist/es2019/pm-plugins/decorations/createBlockChangedDecoration.js +15 -15
- package/dist/es2019/pm-plugins/decorations/createChangedRowDecorationWidgets.js +9 -1
- package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +14 -13
- package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +9 -9
- package/dist/es2019/pm-plugins/decorations/decorationKeys.js +44 -7
- package/dist/es2019/pm-plugins/main.js +19 -5
- package/dist/es2019/showDiffPlugin.js +8 -2
- package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +24 -19
- package/dist/esm/pm-plugins/decorations/createBlockChangedDecoration.js +15 -15
- package/dist/esm/pm-plugins/decorations/createChangedRowDecorationWidgets.js +10 -1
- package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +14 -13
- package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +9 -9
- package/dist/esm/pm-plugins/decorations/decorationKeys.js +47 -7
- package/dist/esm/pm-plugins/main.js +41 -29
- package/dist/esm/showDiffPlugin.js +8 -4
- package/dist/types/pm-plugins/calculateDiff/calculateDiffDecorations.d.ts +7 -2
- package/dist/types/pm-plugins/decorations/createInlineChangedDecoration.d.ts +1 -1
- package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +1 -1
- package/dist/types/pm-plugins/decorations/decorationKeys.d.ts +27 -6
- package/dist/types/pm-plugins/main.d.ts +6 -1
- package/dist/types/showDiffPluginType.d.ts +9 -0
- package/package.json +21 -29
- package/show-diff-plugin/package.json +1 -8
- package/show-diff-plugin-type/package.json +1 -8
- package/dist/types-ts4.5/entry-points/show-diff-plugin-type.d.ts +0 -1
- package/dist/types-ts4.5/entry-points/show-diff-plugin.d.ts +0 -1
- package/dist/types-ts4.5/index.d.ts +0 -2
- package/dist/types-ts4.5/pm-plugins/NodeViewSerializer.d.ts +0 -80
- package/dist/types-ts4.5/pm-plugins/areDocsEqualByBlockStructureAndText.d.ts +0 -12
- package/dist/types-ts4.5/pm-plugins/calculateDiff/calculateDiffDecorations.d.ts +0 -21
- package/dist/types-ts4.5/pm-plugins/calculateDiff/diffBySteps.d.ts +0 -4
- package/dist/types-ts4.5/pm-plugins/calculateDiff/groupChangesByBlock.d.ts +0 -7
- package/dist/types-ts4.5/pm-plugins/calculateDiff/optimizeChanges.d.ts +0 -6
- package/dist/types-ts4.5/pm-plugins/calculateDiff/simplifySteps.d.ts +0 -3
- package/dist/types-ts4.5/pm-plugins/decorations/colorSchemes/standard.d.ts +0 -30
- package/dist/types-ts4.5/pm-plugins/decorations/colorSchemes/traditional.d.ts +0 -39
- package/dist/types-ts4.5/pm-plugins/decorations/createBlockChangedDecoration.d.ts +0 -21
- package/dist/types-ts4.5/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +0 -18
- package/dist/types-ts4.5/pm-plugins/decorations/createInlineChangedDecoration.d.ts +0 -18
- package/dist/types-ts4.5/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +0 -23
- package/dist/types-ts4.5/pm-plugins/decorations/decorationKeys.d.ts +0 -23
- package/dist/types-ts4.5/pm-plugins/decorations/utils/findSafeInsertPos.d.ts +0 -9
- package/dist/types-ts4.5/pm-plugins/decorations/utils/getAttrChangeRanges.d.ts +0 -19
- package/dist/types-ts4.5/pm-plugins/decorations/utils/getMarkChangeRanges.d.ts +0 -7
- package/dist/types-ts4.5/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +0 -17
- package/dist/types-ts4.5/pm-plugins/enforceCustomStepRegisters.d.ts +0 -1
- package/dist/types-ts4.5/pm-plugins/getScrollableDecorations.d.ts +0 -27
- package/dist/types-ts4.5/pm-plugins/main.d.ts +0 -29
- package/dist/types-ts4.5/pm-plugins/scrollToDiff.d.ts +0 -15
- package/dist/types-ts4.5/showDiffPlugin.d.ts +0 -2
- package/dist/types-ts4.5/showDiffPluginType.d.ts +0 -68
|
@@ -9,6 +9,7 @@ import { areDocsEqualByBlockStructureAndText } from '../areDocsEqualByBlockStruc
|
|
|
9
9
|
import { createBlockChangedDecoration } from '../decorations/createBlockChangedDecoration';
|
|
10
10
|
import { createInlineChangedDecoration } from '../decorations/createInlineChangedDecoration';
|
|
11
11
|
import { createNodeChangedDecorationWidget } from '../decorations/createNodeChangedDecorationWidget';
|
|
12
|
+
import { extractDiffDescriptors } from '../decorations/decorationKeys';
|
|
12
13
|
import { getAttrChangeRanges, stepIsValidAttrChange } from '../decorations/utils/getAttrChangeRanges';
|
|
13
14
|
import { getMarkChangeRanges } from '../decorations/utils/getMarkChangeRanges';
|
|
14
15
|
import { diffBySteps } from './diffBySteps';
|
|
@@ -51,7 +52,7 @@ const calculateNodesForBlockDecoration = ({
|
|
|
51
52
|
if (node.isBlock && (!expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) || pos + node.nodeSize <= to)) {
|
|
52
53
|
const nodeEnd = pos + node.nodeSize;
|
|
53
54
|
const isActive = activeIndexPos && pos === activeIndexPos.from && nodeEnd === activeIndexPos.to;
|
|
54
|
-
|
|
55
|
+
decorations.push(...createBlockChangedDecoration({
|
|
55
56
|
change: {
|
|
56
57
|
from: pos,
|
|
57
58
|
to: nodeEnd,
|
|
@@ -61,10 +62,7 @@ const calculateNodesForBlockDecoration = ({
|
|
|
61
62
|
isInserted,
|
|
62
63
|
isActive,
|
|
63
64
|
shouldHideDeleted
|
|
64
|
-
});
|
|
65
|
-
if (blockChangedDecorations.length) {
|
|
66
|
-
decorations.push(...blockChangedDecorations);
|
|
67
|
-
}
|
|
65
|
+
}));
|
|
68
66
|
}
|
|
69
67
|
});
|
|
70
68
|
return decorations;
|
|
@@ -86,7 +84,10 @@ const calculateDiffDecorationsInner = ({
|
|
|
86
84
|
steps
|
|
87
85
|
} = pluginState;
|
|
88
86
|
if (!originalDoc || !pluginState.isDisplayingChanges) {
|
|
89
|
-
return
|
|
87
|
+
return {
|
|
88
|
+
decorations: DecorationSet.empty,
|
|
89
|
+
diffDescriptors: []
|
|
90
|
+
};
|
|
90
91
|
}
|
|
91
92
|
const {
|
|
92
93
|
tr
|
|
@@ -122,7 +123,10 @@ const calculateDiffDecorationsInner = ({
|
|
|
122
123
|
}
|
|
123
124
|
});
|
|
124
125
|
if (!recoveredViaContentEquality) {
|
|
125
|
-
return
|
|
126
|
+
return {
|
|
127
|
+
decorations: DecorationSet.empty,
|
|
128
|
+
diffDescriptors: []
|
|
129
|
+
};
|
|
126
130
|
}
|
|
127
131
|
}
|
|
128
132
|
const changeset = ChangeSet.create(originalDoc).addSteps(steppedDoc, stepMaps, tr.doc);
|
|
@@ -141,7 +145,7 @@ const calculateDiffDecorationsInner = ({
|
|
|
141
145
|
const isInserted = !isInverted;
|
|
142
146
|
if (change.inserted.length > 0) {
|
|
143
147
|
const shouldHideDeleted = expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? isInverted && hideDeletedDiffs : false;
|
|
144
|
-
decorations.push(createInlineChangedDecoration({
|
|
148
|
+
decorations.push(...createInlineChangedDecoration({
|
|
145
149
|
change,
|
|
146
150
|
colorScheme,
|
|
147
151
|
isActive,
|
|
@@ -166,7 +170,7 @@ const calculateDiffDecorationsInner = ({
|
|
|
166
170
|
if (change.deleted.length > 0) {
|
|
167
171
|
const shouldHideDeleted = expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? !isInverted && hideDeletedDiffs : false;
|
|
168
172
|
if (!shouldHideDeleted) {
|
|
169
|
-
|
|
173
|
+
decorations.push(...createNodeChangedDecorationWidget({
|
|
170
174
|
change,
|
|
171
175
|
doc: originalDoc,
|
|
172
176
|
nodeViewSerializer,
|
|
@@ -178,16 +182,13 @@ const calculateDiffDecorationsInner = ({
|
|
|
178
182
|
isInserted: !isInserted,
|
|
179
183
|
diffType
|
|
180
184
|
})
|
|
181
|
-
});
|
|
182
|
-
if (decoration) {
|
|
183
|
-
decorations.push(...decoration);
|
|
184
|
-
}
|
|
185
|
+
}));
|
|
185
186
|
}
|
|
186
187
|
}
|
|
187
188
|
});
|
|
188
189
|
getMarkChangeRanges(steps).forEach(change => {
|
|
189
190
|
const isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
|
|
190
|
-
decorations.push(createInlineChangedDecoration({
|
|
191
|
+
decorations.push(...createInlineChangedDecoration({
|
|
191
192
|
change,
|
|
192
193
|
colorScheme,
|
|
193
194
|
isActive,
|
|
@@ -198,7 +199,7 @@ const calculateDiffDecorationsInner = ({
|
|
|
198
199
|
if (change.isInline) {
|
|
199
200
|
// Inline nodes (e.g. date) need an inline decoration rather than a block decoration
|
|
200
201
|
const isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
|
|
201
|
-
decorations.push(createInlineChangedDecoration({
|
|
202
|
+
decorations.push(...createInlineChangedDecoration({
|
|
202
203
|
change,
|
|
203
204
|
colorScheme,
|
|
204
205
|
isActive,
|
|
@@ -216,7 +217,11 @@ const calculateDiffDecorationsInner = ({
|
|
|
216
217
|
}));
|
|
217
218
|
}
|
|
218
219
|
});
|
|
219
|
-
|
|
220
|
+
const decorationSet = DecorationSet.empty.add(tr.doc, decorations);
|
|
221
|
+
return {
|
|
222
|
+
decorations: decorationSet,
|
|
223
|
+
diffDescriptors: extractDiffDescriptors(decorationSet)
|
|
224
|
+
};
|
|
220
225
|
};
|
|
221
226
|
export const calculateDiffDecorations = memoizeOne(calculateDiffDecorationsInner,
|
|
222
227
|
// Cache results unless relevant inputs change
|
|
@@ -3,7 +3,7 @@ import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
|
3
3
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
4
4
|
import { standardDecorationMarkerVariable, editingStyleQuoteNode, editingStyleRuleNode, editingStyleCardBlockNode, editingStyleNode, deletedContentStyleNew, deletedStyleQuoteNode, addedCellOverlayStyle, deletedCellOverlayStyle } from './colorSchemes/standard';
|
|
5
5
|
import { traditionalDecorationMarkerVariableActive, traditionalDecorationMarkerVariableNew, traditionalDeletedDecorationMarkerVariableActive, traditionalDeletedDecorationMarkerVariableNew, traditionalStyleQuoteNodeActive, traditionalStyleQuoteNodeNew, traditionalStyleRuleNodeActive, traditionalStyleRuleNodeNew, traditionalStyleCardBlockNodeActive, traditionalStyleCardBlockNodeNew, traditionalStyleNodeActive, traditionalStyleNodeNew, getDeletedTraditionalInlineStyle, deletedTraditionalStyleQuoteNode, traditionalAddedCellOverlayStyle, deletedTraditionalCellOverlayStyle } from './colorSchemes/traditional';
|
|
6
|
-
import {
|
|
6
|
+
import { buildDiffDecorationSpec } from './decorationKeys';
|
|
7
7
|
const displayNoneStyle = convertToInlineCss({
|
|
8
8
|
display: 'none'
|
|
9
9
|
});
|
|
@@ -106,15 +106,16 @@ export const createBlockChangedDecoration = ({
|
|
|
106
106
|
shouldHideDeleted = false
|
|
107
107
|
}) => {
|
|
108
108
|
const decorations = [];
|
|
109
|
+
const diffId = crypto.randomUUID();
|
|
109
110
|
if (shouldHideDeleted) {
|
|
110
111
|
return [Decoration.node(change.from, change.to, {
|
|
111
112
|
style: displayNoneStyle
|
|
112
|
-
}, {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
}, buildDiffDecorationSpec({
|
|
114
|
+
decorationType: 'block',
|
|
115
|
+
diffId,
|
|
116
|
+
isActive,
|
|
116
117
|
nodeName: change.name
|
|
117
|
-
})];
|
|
118
|
+
}))];
|
|
118
119
|
}
|
|
119
120
|
let style;
|
|
120
121
|
if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) && ['tableCell', 'tableHeader'].includes(change.name)) {
|
|
@@ -123,11 +124,10 @@ export const createBlockChangedDecoration = ({
|
|
|
123
124
|
cellOverlay.setAttribute('style', cellOverlayStyle);
|
|
124
125
|
decorations.push(
|
|
125
126
|
// change.to - 1 to position the overlay inside the end of the cell
|
|
127
|
+
// this key doesn't use the spec / key builder since this is just for
|
|
128
|
+
// decorating the cells, this is part of a bigger table diff
|
|
126
129
|
Decoration.widget(change.to - 1, cellOverlay, {
|
|
127
|
-
key:
|
|
128
|
-
type: DiffDecorationKey.widget,
|
|
129
|
-
isActive
|
|
130
|
-
})
|
|
130
|
+
key: 'cell-overlay-decoration'
|
|
131
131
|
}));
|
|
132
132
|
}
|
|
133
133
|
if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
@@ -150,12 +150,12 @@ export const createBlockChangedDecoration = ({
|
|
|
150
150
|
style: style,
|
|
151
151
|
'data-testid': 'show-diff-changed-decoration-node',
|
|
152
152
|
class: className
|
|
153
|
-
}, {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
}, buildDiffDecorationSpec({
|
|
154
|
+
decorationType: 'block',
|
|
155
|
+
diffId,
|
|
156
|
+
isActive,
|
|
157
157
|
nodeName: change.name
|
|
158
|
-
}));
|
|
158
|
+
})));
|
|
159
159
|
}
|
|
160
160
|
return decorations;
|
|
161
161
|
};
|
|
@@ -5,6 +5,7 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
|
5
5
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
6
6
|
import { addedCellOverlayStyle, deletedRowStyle, deletedCellOverlayStyle } from './colorSchemes/standard';
|
|
7
7
|
import { deletedTraditionalRowStyle, deletedTraditionalCellOverlayStyle, traditionalAddedCellOverlayStyle } from './colorSchemes/traditional';
|
|
8
|
+
import { buildDiffDecorationSpec } from './decorationKeys';
|
|
8
9
|
import { findSafeInsertPos } from './utils/findSafeInsertPos';
|
|
9
10
|
/**
|
|
10
11
|
* Extracts information about deleted table rows from a change
|
|
@@ -182,6 +183,13 @@ export const createChangedRowDecorationWidgets = ({
|
|
|
182
183
|
const safeInsertPos = findSafeInsertPos(newDoc, changedRow.fromB - 1,
|
|
183
184
|
// -1 to find the first safe position from the table
|
|
184
185
|
originalDoc.slice(changedRow.fromA, changedRow.toA));
|
|
185
|
-
|
|
186
|
+
const diffId = crypto.randomUUID();
|
|
187
|
+
return Decoration.widget(safeInsertPos, rowDOM, {
|
|
188
|
+
...buildDiffDecorationSpec({
|
|
189
|
+
decorationType: 'widget',
|
|
190
|
+
diffId,
|
|
191
|
+
isActive: false
|
|
192
|
+
})
|
|
193
|
+
});
|
|
186
194
|
});
|
|
187
195
|
};
|
|
@@ -3,7 +3,7 @@ import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
|
3
3
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
4
4
|
import { editingStyle, editingStyleExtended, editingStyleActive, editingStyleActiveExtended, deletedContentStyle, deletedContentStyleActive, deletedInlineContentStyleExtended } from './colorSchemes/standard';
|
|
5
5
|
import { traditionalInsertStyle, traditionalInsertStyleActive, getDeletedTraditionalInlineStyle } from './colorSchemes/traditional';
|
|
6
|
-
import {
|
|
6
|
+
import { buildDiffDecorationSpec } from './decorationKeys';
|
|
7
7
|
const displayNoneStyle = convertToInlineCss({
|
|
8
8
|
display: 'none'
|
|
9
9
|
});
|
|
@@ -21,14 +21,15 @@ export const createInlineChangedDecoration = ({
|
|
|
21
21
|
isInserted = true,
|
|
22
22
|
shouldHideDeleted = false
|
|
23
23
|
}) => {
|
|
24
|
+
const diffId = crypto.randomUUID();
|
|
24
25
|
if (shouldHideDeleted) {
|
|
25
|
-
return Decoration.inline(change.fromB, change.toB, {
|
|
26
|
+
return [Decoration.inline(change.fromB, change.toB, {
|
|
26
27
|
style: displayNoneStyle
|
|
27
|
-
}, {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
28
|
+
}, buildDiffDecorationSpec({
|
|
29
|
+
decorationType: 'inline',
|
|
30
|
+
diffId,
|
|
31
|
+
isActive
|
|
32
|
+
}))];
|
|
32
33
|
}
|
|
33
34
|
let style;
|
|
34
35
|
if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
@@ -58,12 +59,12 @@ export const createInlineChangedDecoration = ({
|
|
|
58
59
|
style = isActive ? editingStyleActive : editingStyle;
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
|
-
return Decoration.inline(change.fromB, change.toB, {
|
|
62
|
+
return [Decoration.inline(change.fromB, change.toB, {
|
|
62
63
|
style,
|
|
63
64
|
'data-testid': 'show-diff-changed-decoration'
|
|
64
|
-
}, {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
65
|
+
}, buildDiffDecorationSpec({
|
|
66
|
+
decorationType: 'inline',
|
|
67
|
+
diffId,
|
|
68
|
+
isActive
|
|
69
|
+
}))];
|
|
69
70
|
};
|
|
@@ -4,7 +4,7 @@ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
|
4
4
|
import { editingStyle, editingStyleExtended, editingStyleActive, editingStyleActiveExtended, deletedContentStyle, deletedContentStyleActive, deletedContentStyleNew, deletedContentStyleUnbounded, deletedInlineContentStyleExtended } from './colorSchemes/standard';
|
|
5
5
|
import { traditionalInsertStyle, traditionalInsertStyleActive, getDeletedTraditionalInlineStyle, deletedTraditionalContentStyleUnbounded, deletedTraditionalContentStyleUnboundedActive } from './colorSchemes/traditional';
|
|
6
6
|
import { createChangedRowDecorationWidgets } from './createChangedRowDecorationWidgets';
|
|
7
|
-
import {
|
|
7
|
+
import { buildDiffDecorationSpec } from './decorationKeys';
|
|
8
8
|
import { findSafeInsertPos } from './utils/findSafeInsertPos';
|
|
9
9
|
import { wrapBlockNodeView } from './utils/wrapBlockNodeView';
|
|
10
10
|
const getDeletedContentStyleUnbounded = (colorScheme, isActive = false) => {
|
|
@@ -108,12 +108,12 @@ export const createNodeChangedDecorationWidget = ({
|
|
|
108
108
|
const safeInsertPos = findSafeInsertPos(newDoc, change.fromB, slice);
|
|
109
109
|
const isActive = activeIndexPos && safeInsertPos === activeIndexPos.from && safeInsertPos === activeIndexPos.to;
|
|
110
110
|
if (slice.content.content.length === 0 || shouldSkipDeletedEmptyParagraphDecoration) {
|
|
111
|
-
return;
|
|
111
|
+
return [];
|
|
112
112
|
}
|
|
113
113
|
const isTableCellContent = slice.content.content.some(() => slice.content.content.some(siblingNode => ['tableHeader', 'tableCell'].includes(siblingNode.type.name)));
|
|
114
114
|
const isTableRowContent = slice.content.content.some(() => slice.content.content.some(siblingNode => ['tableRow'].includes(siblingNode.type.name)));
|
|
115
115
|
if (isTableCellContent) {
|
|
116
|
-
return;
|
|
116
|
+
return [];
|
|
117
117
|
}
|
|
118
118
|
if (isTableRowContent) {
|
|
119
119
|
return createChangedRowDecorationWidgets({
|
|
@@ -230,15 +230,15 @@ export const createNodeChangedDecorationWidget = ({
|
|
|
230
230
|
}
|
|
231
231
|
});
|
|
232
232
|
dom.setAttribute('data-testid', 'show-diff-deleted-decoration');
|
|
233
|
+
const diffId = crypto.randomUUID();
|
|
233
234
|
const decorations = [];
|
|
234
|
-
decorations.push(Decoration.widget(safeInsertPos, dom, {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}),
|
|
235
|
+
decorations.push(Decoration.widget(safeInsertPos, dom, buildDiffDecorationSpec({
|
|
236
|
+
decorationType: 'widget',
|
|
237
|
+
diffId,
|
|
238
|
+
isActive,
|
|
239
239
|
...(expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) && {
|
|
240
240
|
side: -1
|
|
241
241
|
})
|
|
242
|
-
}));
|
|
242
|
+
})));
|
|
243
243
|
return decorations;
|
|
244
244
|
};
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
1
2
|
/**
|
|
2
3
|
* Shared prefix for every decoration key produced by the show-diff plugin.
|
|
3
4
|
* All keys derive from this, so the full set of plugin decorations can be
|
|
4
5
|
* identified by this single prefix.
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
+
const DIFF_DECORATION_FAMILY = 'diff';
|
|
7
8
|
/**
|
|
8
9
|
* The kinds of decoration the show-diff plugin produces. Each value is the
|
|
9
10
|
* leading segment of the generated key, so a decoration's kind can be matched
|
|
10
11
|
* with `key?.startsWith(DiffDecorationKey.inline)` etc.
|
|
11
12
|
*/
|
|
12
13
|
export const DiffDecorationKey = {
|
|
13
|
-
inline: `${
|
|
14
|
-
block: `${
|
|
15
|
-
widget: `${
|
|
14
|
+
inline: `${DIFF_DECORATION_FAMILY}-inline`,
|
|
15
|
+
block: `${DIFF_DECORATION_FAMILY}-block`,
|
|
16
|
+
widget: `${DIFF_DECORATION_FAMILY}-widget`
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
/**
|
|
@@ -20,6 +21,42 @@ export const DiffDecorationKey = {
|
|
|
20
21
|
* (e.g. `diff-inline-active`).
|
|
21
22
|
*/
|
|
22
23
|
export const buildDiffDecorationKey = ({
|
|
23
|
-
|
|
24
|
-
isActive
|
|
25
|
-
|
|
24
|
+
decorationKeyPrefix,
|
|
25
|
+
isActive,
|
|
26
|
+
diffId
|
|
27
|
+
}) => {
|
|
28
|
+
if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
29
|
+
return `${decorationKeyPrefix}-${diffId}-${isActive ? 'active' : 'inactive'}`;
|
|
30
|
+
}
|
|
31
|
+
return isActive !== undefined ? `${decorationKeyPrefix}-${isActive ? 'active' : 'inactive'}` : decorationKeyPrefix;
|
|
32
|
+
};
|
|
33
|
+
export const buildDiffDecorationSpec = ({
|
|
34
|
+
decorationType,
|
|
35
|
+
diffId,
|
|
36
|
+
isActive,
|
|
37
|
+
nodeName,
|
|
38
|
+
side
|
|
39
|
+
}) => ({
|
|
40
|
+
decorationFamily: DIFF_DECORATION_FAMILY,
|
|
41
|
+
decorationType,
|
|
42
|
+
diffId,
|
|
43
|
+
key: buildDiffDecorationKey({
|
|
44
|
+
decorationKeyPrefix: DiffDecorationKey[decorationType],
|
|
45
|
+
diffId,
|
|
46
|
+
isActive
|
|
47
|
+
}),
|
|
48
|
+
...(nodeName ? {
|
|
49
|
+
nodeName
|
|
50
|
+
} : {}),
|
|
51
|
+
...(side !== undefined ? {
|
|
52
|
+
side
|
|
53
|
+
} : {})
|
|
54
|
+
});
|
|
55
|
+
export const extractDiffDescriptors = decorations => decorations.find(undefined, undefined, spec => spec.decorationFamily === 'diff').map(({
|
|
56
|
+
spec
|
|
57
|
+
}) => {
|
|
58
|
+
return {
|
|
59
|
+
id: spec.diffId,
|
|
60
|
+
type: spec.decorationType
|
|
61
|
+
};
|
|
62
|
+
});
|
|
@@ -31,7 +31,8 @@ export const createPlugin = (config, getIntl, api) => {
|
|
|
31
31
|
...(expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
|
|
32
32
|
isInverted: false,
|
|
33
33
|
diffType: 'inline',
|
|
34
|
-
hideDeletedDiffs: false
|
|
34
|
+
hideDeletedDiffs: false,
|
|
35
|
+
diffDescriptors: []
|
|
35
36
|
} : {})
|
|
36
37
|
};
|
|
37
38
|
},
|
|
@@ -49,7 +50,10 @@ export const createPlugin = (config, getIntl, api) => {
|
|
|
49
50
|
activeIndex: undefined
|
|
50
51
|
};
|
|
51
52
|
// Calculate and store decorations in state
|
|
52
|
-
const
|
|
53
|
+
const {
|
|
54
|
+
decorations,
|
|
55
|
+
diffDescriptors
|
|
56
|
+
} = calculateDiffDecorations({
|
|
53
57
|
state: newState,
|
|
54
58
|
pluginState: newPluginState,
|
|
55
59
|
nodeViewSerializer,
|
|
@@ -63,8 +67,11 @@ export const createPlugin = (config, getIntl, api) => {
|
|
|
63
67
|
hideDeletedDiffs: (_newPluginState3 = newPluginState) === null || _newPluginState3 === void 0 ? void 0 : _newPluginState3.hideDeletedDiffs
|
|
64
68
|
} : {})
|
|
65
69
|
});
|
|
66
|
-
// Update the decorations
|
|
70
|
+
// Update the decorations and their ids
|
|
67
71
|
newPluginState.decorations = decorations;
|
|
72
|
+
if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
73
|
+
newPluginState.diffDescriptors = diffDescriptors;
|
|
74
|
+
}
|
|
68
75
|
} else if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'HIDE_DIFF') {
|
|
69
76
|
newPluginState = {
|
|
70
77
|
...currentPluginState,
|
|
@@ -79,7 +86,8 @@ export const createPlugin = (config, getIntl, api) => {
|
|
|
79
86
|
...(expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
|
|
80
87
|
isInverted: false,
|
|
81
88
|
diffType: 'inline',
|
|
82
|
-
hideDeletedDiffs: false
|
|
89
|
+
hideDeletedDiffs: false,
|
|
90
|
+
diffDescriptors: []
|
|
83
91
|
} : {})
|
|
84
92
|
};
|
|
85
93
|
} 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') {
|
|
@@ -111,7 +119,10 @@ export const createPlugin = (config, getIntl, api) => {
|
|
|
111
119
|
} : undefined
|
|
112
120
|
};
|
|
113
121
|
// Recalculate decorations with the new active index
|
|
114
|
-
const
|
|
122
|
+
const {
|
|
123
|
+
decorations: updatedDecorations,
|
|
124
|
+
diffDescriptors: updatedDiffDescriptors
|
|
125
|
+
} = calculateDiffDecorations({
|
|
115
126
|
state: newState,
|
|
116
127
|
pluginState: newPluginState,
|
|
117
128
|
nodeViewSerializer,
|
|
@@ -126,6 +137,9 @@ export const createPlugin = (config, getIntl, api) => {
|
|
|
126
137
|
} : {})
|
|
127
138
|
});
|
|
128
139
|
newPluginState.decorations = updatedDecorations;
|
|
140
|
+
if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
141
|
+
newPluginState.diffDescriptors = updatedDiffDescriptors;
|
|
142
|
+
}
|
|
129
143
|
}
|
|
130
144
|
} else {
|
|
131
145
|
newPluginState = {
|
|
@@ -62,7 +62,10 @@ export const showDiffPlugin = ({
|
|
|
62
62
|
if (!editorState) {
|
|
63
63
|
return {
|
|
64
64
|
isDisplayingChanges: false,
|
|
65
|
-
activeIndex: undefined
|
|
65
|
+
activeIndex: undefined,
|
|
66
|
+
...(expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
|
|
67
|
+
diffDescriptors: []
|
|
68
|
+
} : {})
|
|
66
69
|
};
|
|
67
70
|
}
|
|
68
71
|
const pluginState = showDiffPluginKey.getState(editorState);
|
|
@@ -70,7 +73,10 @@ export const showDiffPlugin = ({
|
|
|
70
73
|
return {
|
|
71
74
|
isDisplayingChanges: decorationCount.length > 0,
|
|
72
75
|
activeIndex: pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex,
|
|
73
|
-
numberOfChanges: decorationCount.length
|
|
76
|
+
numberOfChanges: decorationCount.length,
|
|
77
|
+
...(expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
|
|
78
|
+
diffDescriptors: pluginState === null || pluginState === void 0 ? void 0 : pluginState.diffDescriptors
|
|
79
|
+
} : {})
|
|
74
80
|
};
|
|
75
81
|
}
|
|
76
82
|
});
|
|
@@ -17,6 +17,7 @@ import { areDocsEqualByBlockStructureAndText } from '../areDocsEqualByBlockStruc
|
|
|
17
17
|
import { createBlockChangedDecoration } from '../decorations/createBlockChangedDecoration';
|
|
18
18
|
import { createInlineChangedDecoration } from '../decorations/createInlineChangedDecoration';
|
|
19
19
|
import { createNodeChangedDecorationWidget } from '../decorations/createNodeChangedDecorationWidget';
|
|
20
|
+
import { extractDiffDescriptors } from '../decorations/decorationKeys';
|
|
20
21
|
import { getAttrChangeRanges, stepIsValidAttrChange } from '../decorations/utils/getAttrChangeRanges';
|
|
21
22
|
import { getMarkChangeRanges } from '../decorations/utils/getMarkChangeRanges';
|
|
22
23
|
import { diffBySteps } from './diffBySteps';
|
|
@@ -59,7 +60,7 @@ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration
|
|
|
59
60
|
if (node.isBlock && (!expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) || pos + node.nodeSize <= to)) {
|
|
60
61
|
var nodeEnd = pos + node.nodeSize;
|
|
61
62
|
var isActive = activeIndexPos && pos === activeIndexPos.from && nodeEnd === activeIndexPos.to;
|
|
62
|
-
|
|
63
|
+
decorations.push.apply(decorations, _toConsumableArray(createBlockChangedDecoration({
|
|
63
64
|
change: {
|
|
64
65
|
from: pos,
|
|
65
66
|
to: nodeEnd,
|
|
@@ -69,10 +70,7 @@ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration
|
|
|
69
70
|
isInserted: isInserted,
|
|
70
71
|
isActive: isActive,
|
|
71
72
|
shouldHideDeleted: shouldHideDeleted
|
|
72
|
-
});
|
|
73
|
-
if (blockChangedDecorations.length) {
|
|
74
|
-
decorations.push.apply(decorations, _toConsumableArray(blockChangedDecorations));
|
|
75
|
-
}
|
|
73
|
+
})));
|
|
76
74
|
}
|
|
77
75
|
});
|
|
78
76
|
return decorations;
|
|
@@ -94,7 +92,10 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
|
|
|
94
92
|
var originalDoc = pluginState.originalDoc,
|
|
95
93
|
steps = pluginState.steps;
|
|
96
94
|
if (!originalDoc || !pluginState.isDisplayingChanges) {
|
|
97
|
-
return
|
|
95
|
+
return {
|
|
96
|
+
decorations: DecorationSet.empty,
|
|
97
|
+
diffDescriptors: []
|
|
98
|
+
};
|
|
98
99
|
}
|
|
99
100
|
var tr = state.tr;
|
|
100
101
|
var steppedDoc = originalDoc;
|
|
@@ -137,7 +138,10 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
|
|
|
137
138
|
}
|
|
138
139
|
});
|
|
139
140
|
if (!recoveredViaContentEquality) {
|
|
140
|
-
return
|
|
141
|
+
return {
|
|
142
|
+
decorations: DecorationSet.empty,
|
|
143
|
+
diffDescriptors: []
|
|
144
|
+
};
|
|
141
145
|
}
|
|
142
146
|
}
|
|
143
147
|
var changeset = ChangeSet.create(originalDoc).addSteps(steppedDoc, stepMaps, tr.doc);
|
|
@@ -156,14 +160,14 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
|
|
|
156
160
|
var isInserted = !isInverted;
|
|
157
161
|
if (change.inserted.length > 0) {
|
|
158
162
|
var shouldHideDeleted = expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? isInverted && hideDeletedDiffs : false;
|
|
159
|
-
decorations.push(createInlineChangedDecoration(_objectSpread({
|
|
163
|
+
decorations.push.apply(decorations, _toConsumableArray(createInlineChangedDecoration(_objectSpread({
|
|
160
164
|
change: change,
|
|
161
165
|
colorScheme: colorScheme,
|
|
162
166
|
isActive: isActive
|
|
163
167
|
}, expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) && {
|
|
164
168
|
isInserted: isInserted,
|
|
165
169
|
shouldHideDeleted: shouldHideDeleted
|
|
166
|
-
})));
|
|
170
|
+
}))));
|
|
167
171
|
decorations.push.apply(decorations, _toConsumableArray(calculateNodesForBlockDecoration(_objectSpread(_objectSpread({
|
|
168
172
|
doc: tr.doc,
|
|
169
173
|
from: change.fromB,
|
|
@@ -180,7 +184,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
|
|
|
180
184
|
if (change.deleted.length > 0) {
|
|
181
185
|
var _shouldHideDeleted = expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? !isInverted && hideDeletedDiffs : false;
|
|
182
186
|
if (!_shouldHideDeleted) {
|
|
183
|
-
|
|
187
|
+
decorations.push.apply(decorations, _toConsumableArray(createNodeChangedDecorationWidget(_objectSpread({
|
|
184
188
|
change: change,
|
|
185
189
|
doc: originalDoc,
|
|
186
190
|
nodeViewSerializer: nodeViewSerializer,
|
|
@@ -191,32 +195,29 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
|
|
|
191
195
|
}, expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) && {
|
|
192
196
|
isInserted: !isInserted,
|
|
193
197
|
diffType: diffType
|
|
194
|
-
}));
|
|
195
|
-
if (decoration) {
|
|
196
|
-
decorations.push.apply(decorations, _toConsumableArray(decoration));
|
|
197
|
-
}
|
|
198
|
+
}))));
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
201
|
});
|
|
201
202
|
getMarkChangeRanges(steps).forEach(function (change) {
|
|
202
203
|
var isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
|
|
203
|
-
decorations.push(createInlineChangedDecoration({
|
|
204
|
+
decorations.push.apply(decorations, _toConsumableArray(createInlineChangedDecoration({
|
|
204
205
|
change: change,
|
|
205
206
|
colorScheme: colorScheme,
|
|
206
207
|
isActive: isActive,
|
|
207
208
|
isInserted: true
|
|
208
|
-
}));
|
|
209
|
+
})));
|
|
209
210
|
});
|
|
210
211
|
getAttrChangeRanges(tr.doc, attrSteps).forEach(function (change) {
|
|
211
212
|
if (change.isInline) {
|
|
212
213
|
// Inline nodes (e.g. date) need an inline decoration rather than a block decoration
|
|
213
214
|
var isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
|
|
214
|
-
decorations.push(createInlineChangedDecoration({
|
|
215
|
+
decorations.push.apply(decorations, _toConsumableArray(createInlineChangedDecoration({
|
|
215
216
|
change: change,
|
|
216
217
|
colorScheme: colorScheme,
|
|
217
218
|
isActive: isActive,
|
|
218
219
|
isInserted: true
|
|
219
|
-
}));
|
|
220
|
+
})));
|
|
220
221
|
} else {
|
|
221
222
|
decorations.push.apply(decorations, _toConsumableArray(calculateNodesForBlockDecoration({
|
|
222
223
|
doc: tr.doc,
|
|
@@ -229,7 +230,11 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
|
|
|
229
230
|
})));
|
|
230
231
|
}
|
|
231
232
|
});
|
|
232
|
-
|
|
233
|
+
var decorationSet = DecorationSet.empty.add(tr.doc, decorations);
|
|
234
|
+
return {
|
|
235
|
+
decorations: decorationSet,
|
|
236
|
+
diffDescriptors: extractDiffDescriptors(decorationSet)
|
|
237
|
+
};
|
|
233
238
|
};
|
|
234
239
|
export var calculateDiffDecorations = memoizeOne(calculateDiffDecorationsInner,
|
|
235
240
|
// Cache results unless relevant inputs change
|
|
@@ -3,7 +3,7 @@ import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
|
3
3
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
4
4
|
import { standardDecorationMarkerVariable, editingStyleQuoteNode, editingStyleRuleNode, editingStyleCardBlockNode, editingStyleNode, deletedContentStyleNew, deletedStyleQuoteNode, addedCellOverlayStyle, deletedCellOverlayStyle } from './colorSchemes/standard';
|
|
5
5
|
import { traditionalDecorationMarkerVariableActive, traditionalDecorationMarkerVariableNew, traditionalDeletedDecorationMarkerVariableActive, traditionalDeletedDecorationMarkerVariableNew, traditionalStyleQuoteNodeActive, traditionalStyleQuoteNodeNew, traditionalStyleRuleNodeActive, traditionalStyleRuleNodeNew, traditionalStyleCardBlockNodeActive, traditionalStyleCardBlockNodeNew, traditionalStyleNodeActive, traditionalStyleNodeNew, getDeletedTraditionalInlineStyle, deletedTraditionalStyleQuoteNode, traditionalAddedCellOverlayStyle, deletedTraditionalCellOverlayStyle } from './colorSchemes/traditional';
|
|
6
|
-
import {
|
|
6
|
+
import { buildDiffDecorationSpec } from './decorationKeys';
|
|
7
7
|
var displayNoneStyle = convertToInlineCss({
|
|
8
8
|
display: 'none'
|
|
9
9
|
});
|
|
@@ -109,15 +109,16 @@ export var createBlockChangedDecoration = function createBlockChangedDecoration(
|
|
|
109
109
|
_ref2$shouldHideDelet = _ref2.shouldHideDeleted,
|
|
110
110
|
shouldHideDeleted = _ref2$shouldHideDelet === void 0 ? false : _ref2$shouldHideDelet;
|
|
111
111
|
var decorations = [];
|
|
112
|
+
var diffId = crypto.randomUUID();
|
|
112
113
|
if (shouldHideDeleted) {
|
|
113
114
|
return [Decoration.node(change.from, change.to, {
|
|
114
115
|
style: displayNoneStyle
|
|
115
|
-
}, {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
}, buildDiffDecorationSpec({
|
|
117
|
+
decorationType: 'block',
|
|
118
|
+
diffId: diffId,
|
|
119
|
+
isActive: isActive,
|
|
119
120
|
nodeName: change.name
|
|
120
|
-
})];
|
|
121
|
+
}))];
|
|
121
122
|
}
|
|
122
123
|
var style;
|
|
123
124
|
if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) && ['tableCell', 'tableHeader'].includes(change.name)) {
|
|
@@ -126,11 +127,10 @@ export var createBlockChangedDecoration = function createBlockChangedDecoration(
|
|
|
126
127
|
cellOverlay.setAttribute('style', cellOverlayStyle);
|
|
127
128
|
decorations.push(
|
|
128
129
|
// change.to - 1 to position the overlay inside the end of the cell
|
|
130
|
+
// this key doesn't use the spec / key builder since this is just for
|
|
131
|
+
// decorating the cells, this is part of a bigger table diff
|
|
129
132
|
Decoration.widget(change.to - 1, cellOverlay, {
|
|
130
|
-
key:
|
|
131
|
-
type: DiffDecorationKey.widget,
|
|
132
|
-
isActive: isActive
|
|
133
|
-
})
|
|
133
|
+
key: 'cell-overlay-decoration'
|
|
134
134
|
}));
|
|
135
135
|
}
|
|
136
136
|
if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
@@ -153,12 +153,12 @@ export var createBlockChangedDecoration = function createBlockChangedDecoration(
|
|
|
153
153
|
style: style,
|
|
154
154
|
'data-testid': 'show-diff-changed-decoration-node',
|
|
155
155
|
class: className
|
|
156
|
-
}, {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
}, buildDiffDecorationSpec({
|
|
157
|
+
decorationType: 'block',
|
|
158
|
+
diffId: diffId,
|
|
159
|
+
isActive: isActive,
|
|
160
160
|
nodeName: change.name
|
|
161
|
-
}));
|
|
161
|
+
})));
|
|
162
162
|
}
|
|
163
163
|
return decorations;
|
|
164
164
|
};
|