@atlaskit/editor-plugin-show-diff 9.1.2 → 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 +31 -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
|
@@ -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
|
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2
5
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
3
6
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
4
7
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
@@ -9,6 +12,7 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
|
9
12
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
10
13
|
import { addedCellOverlayStyle, deletedRowStyle, deletedCellOverlayStyle } from './colorSchemes/standard';
|
|
11
14
|
import { deletedTraditionalRowStyle, deletedTraditionalCellOverlayStyle, traditionalAddedCellOverlayStyle } from './colorSchemes/traditional';
|
|
15
|
+
import { buildDiffDecorationSpec } from './decorationKeys';
|
|
12
16
|
import { findSafeInsertPos } from './utils/findSafeInsertPos';
|
|
13
17
|
/**
|
|
14
18
|
* Extracts information about deleted table rows from a change
|
|
@@ -203,6 +207,11 @@ export var createChangedRowDecorationWidgets = function createChangedRowDecorati
|
|
|
203
207
|
var safeInsertPos = findSafeInsertPos(newDoc, changedRow.fromB - 1,
|
|
204
208
|
// -1 to find the first safe position from the table
|
|
205
209
|
originalDoc.slice(changedRow.fromA, changedRow.toA));
|
|
206
|
-
|
|
210
|
+
var diffId = crypto.randomUUID();
|
|
211
|
+
return Decoration.widget(safeInsertPos, rowDOM, _objectSpread({}, buildDiffDecorationSpec({
|
|
212
|
+
decorationType: 'widget',
|
|
213
|
+
diffId: diffId,
|
|
214
|
+
isActive: false
|
|
215
|
+
})));
|
|
207
216
|
});
|
|
208
217
|
};
|
|
@@ -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
|
var displayNoneStyle = convertToInlineCss({
|
|
8
8
|
display: 'none'
|
|
9
9
|
});
|
|
@@ -23,14 +23,15 @@ export var createInlineChangedDecoration = function createInlineChangedDecoratio
|
|
|
23
23
|
isInserted = _ref$isInserted === void 0 ? true : _ref$isInserted,
|
|
24
24
|
_ref$shouldHideDelete = _ref.shouldHideDeleted,
|
|
25
25
|
shouldHideDeleted = _ref$shouldHideDelete === void 0 ? false : _ref$shouldHideDelete;
|
|
26
|
+
var diffId = crypto.randomUUID();
|
|
26
27
|
if (shouldHideDeleted) {
|
|
27
|
-
return Decoration.inline(change.fromB, change.toB, {
|
|
28
|
+
return [Decoration.inline(change.fromB, change.toB, {
|
|
28
29
|
style: displayNoneStyle
|
|
29
|
-
}, {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
30
|
+
}, buildDiffDecorationSpec({
|
|
31
|
+
decorationType: 'inline',
|
|
32
|
+
diffId: diffId,
|
|
33
|
+
isActive: isActive
|
|
34
|
+
}))];
|
|
34
35
|
}
|
|
35
36
|
var style;
|
|
36
37
|
if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
@@ -60,12 +61,12 @@ export var createInlineChangedDecoration = function createInlineChangedDecoratio
|
|
|
60
61
|
style = isActive ? editingStyleActive : editingStyle;
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
|
-
return Decoration.inline(change.fromB, change.toB, {
|
|
64
|
+
return [Decoration.inline(change.fromB, change.toB, {
|
|
64
65
|
style: style,
|
|
65
66
|
'data-testid': 'show-diff-changed-decoration'
|
|
66
|
-
}, {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
});
|
|
67
|
+
}, buildDiffDecorationSpec({
|
|
68
|
+
decorationType: 'inline',
|
|
69
|
+
diffId: diffId,
|
|
70
|
+
isActive: isActive
|
|
71
|
+
}))];
|
|
71
72
|
};
|