@atlaskit/editor-plugin-show-diff 6.0.2 → 6.1.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 +11 -0
- package/dist/cjs/pm-plugins/calculateDiffDecorations.js +37 -16
- package/dist/cjs/pm-plugins/decorations/colorSchemes/standard.js +23 -1
- package/dist/cjs/pm-plugins/decorations/colorSchemes/traditional.js +23 -1
- package/dist/cjs/pm-plugins/decorations/createBlockChangedDecoration.js +60 -8
- package/dist/cjs/pm-plugins/decorations/createChangedRowDecorationWidgets.js +19 -4
- package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +24 -4
- package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +92 -21
- package/dist/cjs/pm-plugins/decorations/utils/getMarkChangeRanges.js +0 -15
- package/dist/cjs/pm-plugins/decorations/utils/wrapBlockNodeView.js +87 -45
- package/dist/cjs/pm-plugins/main.js +17 -7
- package/dist/es2019/pm-plugins/calculateDiffDecorations.js +35 -13
- package/dist/es2019/pm-plugins/decorations/colorSchemes/standard.js +22 -0
- package/dist/es2019/pm-plugins/decorations/colorSchemes/traditional.js +22 -0
- package/dist/es2019/pm-plugins/decorations/createBlockChangedDecoration.js +59 -8
- package/dist/es2019/pm-plugins/decorations/createChangedRowDecorationWidgets.js +20 -6
- package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +25 -6
- package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +84 -16
- package/dist/es2019/pm-plugins/decorations/utils/getMarkChangeRanges.js +0 -13
- package/dist/es2019/pm-plugins/decorations/utils/wrapBlockNodeView.js +58 -19
- package/dist/es2019/pm-plugins/main.js +22 -4
- package/dist/esm/pm-plugins/calculateDiffDecorations.js +37 -16
- package/dist/esm/pm-plugins/decorations/colorSchemes/standard.js +22 -0
- package/dist/esm/pm-plugins/decorations/colorSchemes/traditional.js +22 -0
- package/dist/esm/pm-plugins/decorations/createBlockChangedDecoration.js +62 -10
- package/dist/esm/pm-plugins/decorations/createChangedRowDecorationWidgets.js +21 -6
- package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +26 -6
- package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +93 -23
- package/dist/esm/pm-plugins/decorations/utils/getMarkChangeRanges.js +0 -15
- package/dist/esm/pm-plugins/decorations/utils/wrapBlockNodeView.js +89 -47
- package/dist/esm/pm-plugins/main.js +17 -7
- package/dist/types/pm-plugins/decorations/colorSchemes/standard.d.ts +2 -0
- package/dist/types/pm-plugins/decorations/colorSchemes/traditional.d.ts +2 -0
- package/dist/types/pm-plugins/decorations/createBlockChangedDecoration.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/createInlineChangedDecoration.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +6 -1
- package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +2 -1
- package/dist/types/pm-plugins/main.d.ts +1 -0
- package/dist/types/showDiffPluginType.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/decorations/colorSchemes/standard.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/decorations/colorSchemes/traditional.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/decorations/createBlockChangedDecoration.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/decorations/createInlineChangedDecoration.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +6 -1
- package/dist/types-ts4.5/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -0
- package/dist/types-ts4.5/showDiffPluginType.d.ts +1 -0
- package/package.json +3 -2
|
@@ -5,13 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getMarkChangeRanges = void 0;
|
|
7
7
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
8
|
-
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
9
8
|
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; } } }; }
|
|
10
9
|
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; } }
|
|
11
10
|
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; }
|
|
12
|
-
var filterUndefined = function filterUndefined(x) {
|
|
13
|
-
return !!x;
|
|
14
|
-
};
|
|
15
11
|
var extractMarkStep = function extractMarkStep(step) {
|
|
16
12
|
if (step instanceof _transform.AddMarkStep) {
|
|
17
13
|
return {
|
|
@@ -32,17 +28,6 @@ var extractMarkStep = function extractMarkStep(step) {
|
|
|
32
28
|
return undefined;
|
|
33
29
|
};
|
|
34
30
|
var getMarkChangeRanges = exports.getMarkChangeRanges = function getMarkChangeRanges(steps) {
|
|
35
|
-
if (!(0, _expValEquals.expValEquals)('platform_editor_deduplicate_mark_diff', 'isEnabled', true)) {
|
|
36
|
-
return steps.map(function (step) {
|
|
37
|
-
if (step instanceof _transform.AddMarkStep || step instanceof _transform.RemoveMarkStep) {
|
|
38
|
-
return {
|
|
39
|
-
fromB: step.from,
|
|
40
|
-
toB: step.to
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
return undefined;
|
|
44
|
-
}).filter(filterUndefined);
|
|
45
|
-
}
|
|
46
31
|
var resultRanges = [];
|
|
47
32
|
var lastOp;
|
|
48
33
|
var _iterator = _createForOfIteratorHelper(steps),
|
|
@@ -25,8 +25,15 @@ var lozengeStyle = (0, _lazyNodeView.convertToInlineCss)({
|
|
|
25
25
|
whiteSpace: 'nowrap',
|
|
26
26
|
color: "var(--ds-text-warning-inverse, #292A2E)"
|
|
27
27
|
});
|
|
28
|
-
var
|
|
28
|
+
var getChangedContentStyle = function getChangedContentStyle(colorScheme) {
|
|
29
29
|
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
30
|
+
var isInserted = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
31
|
+
if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) && isInserted) {
|
|
32
|
+
if (colorScheme === 'traditional') {
|
|
33
|
+
return isActive ? _traditional.traditionalInsertStyleActive : _traditional.traditionalInsertStyle;
|
|
34
|
+
}
|
|
35
|
+
return isActive ? _standard.editingStyleActive : _standard.editingStyle;
|
|
36
|
+
}
|
|
30
37
|
if (colorScheme === 'traditional') {
|
|
31
38
|
return _traditional.deletedTraditionalContentStyle;
|
|
32
39
|
}
|
|
@@ -35,8 +42,18 @@ var getDeletedContentStyle = function getDeletedContentStyle(colorScheme) {
|
|
|
35
42
|
}
|
|
36
43
|
return (0, _expValEquals.expValEquals)('platform_editor_enghealth_a11y_jan_fixes', 'isEnabled', true) ? _standard.deletedContentStyleNew : _standard.deletedContentStyle;
|
|
37
44
|
};
|
|
38
|
-
var
|
|
45
|
+
var getChangedNodeStyle = function getChangedNodeStyle(nodeName, colorScheme) {
|
|
46
|
+
var isInserted = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
39
47
|
var isTraditional = colorScheme === 'traditional';
|
|
48
|
+
if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) && isInserted) {
|
|
49
|
+
if (shouldApplyStylesDirectly(nodeName)) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
if (isTraditional) {
|
|
53
|
+
return _traditional.traditionalStyleNode;
|
|
54
|
+
}
|
|
55
|
+
return _standard.editingStyleNode;
|
|
56
|
+
}
|
|
40
57
|
switch (nodeName) {
|
|
41
58
|
case 'blockquote':
|
|
42
59
|
return isTraditional ? _traditional.deletedTraditionalStyleQuoteNode : _standard.deletedStyleQuoteNodeWithLozenge;
|
|
@@ -57,7 +74,6 @@ var shouldShowRemovedLozenge = function shouldShowRemovedLozenge(nodeName) {
|
|
|
57
74
|
case 'mediaSingle':
|
|
58
75
|
case 'panel':
|
|
59
76
|
case 'decisionList':
|
|
60
|
-
return true;
|
|
61
77
|
case 'embedCard':
|
|
62
78
|
case 'blockquote':
|
|
63
79
|
return true;
|
|
@@ -69,7 +85,6 @@ var shouldAddShowDiffDeletedNodeClass = function shouldAddShowDiffDeletedNodeCla
|
|
|
69
85
|
switch (nodeName) {
|
|
70
86
|
case 'mediaSingle':
|
|
71
87
|
case 'embedCard':
|
|
72
|
-
return true;
|
|
73
88
|
case 'blockquote':
|
|
74
89
|
return true;
|
|
75
90
|
default:
|
|
@@ -84,6 +99,17 @@ var shouldAddShowDiffDeletedNodeClass = function shouldAddShowDiffDeletedNodeCla
|
|
|
84
99
|
var shouldApplyStylesDirectly = function shouldApplyStylesDirectly(nodeName) {
|
|
85
100
|
return nodeName === 'heading';
|
|
86
101
|
};
|
|
102
|
+
var applyCellOverlayStyles = function applyCellOverlayStyles(_ref) {
|
|
103
|
+
var element = _ref.element,
|
|
104
|
+
colorScheme = _ref.colorScheme,
|
|
105
|
+
isInserted = _ref.isInserted;
|
|
106
|
+
element.querySelectorAll('td, th').forEach(function (cell) {
|
|
107
|
+
var overlay = document.createElement('span');
|
|
108
|
+
var overlayStyle = colorScheme === 'traditional' ? isInserted ? _traditional.traditionalAddedCellOverlayStyle : _traditional.deletedTraditionalCellOverlayStyle : isInserted ? _standard.addedCellOverlayStyle : _standard.deletedCellOverlayStyle;
|
|
109
|
+
overlay.setAttribute('style', overlayStyle);
|
|
110
|
+
cell.appendChild(overlay);
|
|
111
|
+
});
|
|
112
|
+
};
|
|
87
113
|
|
|
88
114
|
/**
|
|
89
115
|
* Creates a "Removed" lozenge to be displayed at the top right corner of deleted block nodes
|
|
@@ -126,26 +152,28 @@ var createBlockNodeWrapper = function createBlockNodeWrapper() {
|
|
|
126
152
|
/**
|
|
127
153
|
* Applies styles directly to an HTML element by merging with existing styles
|
|
128
154
|
*/
|
|
129
|
-
var applyStylesToElement = function applyStylesToElement(
|
|
130
|
-
var element =
|
|
131
|
-
targetNode =
|
|
132
|
-
colorScheme =
|
|
155
|
+
var applyStylesToElement = function applyStylesToElement(_ref2) {
|
|
156
|
+
var element = _ref2.element,
|
|
157
|
+
targetNode = _ref2.targetNode,
|
|
158
|
+
colorScheme = _ref2.colorScheme,
|
|
159
|
+
isInserted = _ref2.isInserted;
|
|
133
160
|
var currentStyle = element.getAttribute('style') || '';
|
|
134
|
-
var
|
|
135
|
-
var nodeSpecificStyle =
|
|
136
|
-
element.setAttribute('style', "".concat(currentStyle).concat(
|
|
161
|
+
var contentStyle = getChangedContentStyle(colorScheme, false, isInserted);
|
|
162
|
+
var nodeSpecificStyle = getChangedNodeStyle(targetNode.type.name, colorScheme, isInserted) || '';
|
|
163
|
+
element.setAttribute('style', "".concat(currentStyle).concat(contentStyle).concat(nodeSpecificStyle));
|
|
137
164
|
};
|
|
138
165
|
|
|
139
166
|
/**
|
|
140
167
|
* Creates a content wrapper with deleted styles for a block node
|
|
141
168
|
*/
|
|
142
|
-
var createBlockNodeContentWrapper = function createBlockNodeContentWrapper(
|
|
143
|
-
var nodeView =
|
|
144
|
-
targetNode =
|
|
145
|
-
colorScheme =
|
|
169
|
+
var createBlockNodeContentWrapper = function createBlockNodeContentWrapper(_ref3) {
|
|
170
|
+
var nodeView = _ref3.nodeView,
|
|
171
|
+
targetNode = _ref3.targetNode,
|
|
172
|
+
colorScheme = _ref3.colorScheme,
|
|
173
|
+
isInserted = _ref3.isInserted;
|
|
146
174
|
var contentWrapper = document.createElement('div');
|
|
147
|
-
var nodeStyle =
|
|
148
|
-
contentWrapper.setAttribute('style', "".concat(
|
|
175
|
+
var nodeStyle = getChangedNodeStyle(targetNode.type.name, colorScheme, isInserted);
|
|
176
|
+
contentWrapper.setAttribute('style', "".concat(getChangedContentStyle(colorScheme, false, isInserted)).concat(nodeStyle || ''));
|
|
149
177
|
contentWrapper.append(nodeView);
|
|
150
178
|
return contentWrapper;
|
|
151
179
|
};
|
|
@@ -156,12 +184,12 @@ var createBlockNodeContentWrapper = function createBlockNodeContentWrapper(_ref2
|
|
|
156
184
|
* to wait for the rich-media-item to appear before attaching the lozenge.
|
|
157
185
|
* @returns true if embedCard was handled
|
|
158
186
|
*/
|
|
159
|
-
var handleEmbedCardWithLozenge = function handleEmbedCardWithLozenge(
|
|
160
|
-
var dom =
|
|
161
|
-
nodeView =
|
|
162
|
-
targetNode =
|
|
163
|
-
lozenge =
|
|
164
|
-
colorScheme =
|
|
187
|
+
var handleEmbedCardWithLozenge = function handleEmbedCardWithLozenge(_ref4) {
|
|
188
|
+
var dom = _ref4.dom,
|
|
189
|
+
nodeView = _ref4.nodeView,
|
|
190
|
+
targetNode = _ref4.targetNode,
|
|
191
|
+
lozenge = _ref4.lozenge,
|
|
192
|
+
colorScheme = _ref4.colorScheme;
|
|
165
193
|
if (targetNode.type.name !== 'embedCard' || !(nodeView instanceof HTMLElement)) {
|
|
166
194
|
return false;
|
|
167
195
|
}
|
|
@@ -193,12 +221,12 @@ var handleEmbedCardWithLozenge = function handleEmbedCardWithLozenge(_ref3) {
|
|
|
193
221
|
* Handles special mediaSingle node rendering with lozenge on child media element
|
|
194
222
|
* @returns true if mediaSingle was handled, false otherwise
|
|
195
223
|
*/
|
|
196
|
-
var handleMediaSingleWithLozenge = function handleMediaSingleWithLozenge(
|
|
197
|
-
var dom =
|
|
198
|
-
nodeView =
|
|
199
|
-
targetNode =
|
|
200
|
-
lozenge =
|
|
201
|
-
colorScheme =
|
|
224
|
+
var handleMediaSingleWithLozenge = function handleMediaSingleWithLozenge(_ref5) {
|
|
225
|
+
var dom = _ref5.dom,
|
|
226
|
+
nodeView = _ref5.nodeView,
|
|
227
|
+
targetNode = _ref5.targetNode,
|
|
228
|
+
lozenge = _ref5.lozenge,
|
|
229
|
+
colorScheme = _ref5.colorScheme;
|
|
202
230
|
if (targetNode.type.name !== 'mediaSingle' || !(nodeView instanceof HTMLElement)) {
|
|
203
231
|
return false;
|
|
204
232
|
}
|
|
@@ -227,14 +255,16 @@ var handleMediaSingleWithLozenge = function handleMediaSingleWithLozenge(_ref4)
|
|
|
227
255
|
/**
|
|
228
256
|
* Appends a block node with wrapper, lozenge, and appropriate styling
|
|
229
257
|
*/
|
|
230
|
-
var wrapBlockNode = function wrapBlockNode(
|
|
231
|
-
var dom =
|
|
232
|
-
nodeView =
|
|
233
|
-
targetNode =
|
|
234
|
-
colorScheme =
|
|
235
|
-
intl =
|
|
258
|
+
var wrapBlockNode = function wrapBlockNode(_ref6) {
|
|
259
|
+
var dom = _ref6.dom,
|
|
260
|
+
nodeView = _ref6.nodeView,
|
|
261
|
+
targetNode = _ref6.targetNode,
|
|
262
|
+
colorScheme = _ref6.colorScheme,
|
|
263
|
+
intl = _ref6.intl,
|
|
264
|
+
_ref6$isInserted = _ref6.isInserted,
|
|
265
|
+
isInserted = _ref6$isInserted === void 0 ? false : _ref6$isInserted;
|
|
236
266
|
var blockWrapper = createBlockNodeWrapper();
|
|
237
|
-
if (shouldShowRemovedLozenge(targetNode.type.name)) {
|
|
267
|
+
if (shouldShowRemovedLozenge(targetNode.type.name) && (!(0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) || !isInserted)) {
|
|
238
268
|
var lozenge = createRemovedLozenge(intl);
|
|
239
269
|
if (handleEmbedCardWithLozenge({
|
|
240
270
|
dom: dom,
|
|
@@ -259,7 +289,8 @@ var wrapBlockNode = function wrapBlockNode(_ref5) {
|
|
|
259
289
|
var contentWrapper = createBlockNodeContentWrapper({
|
|
260
290
|
nodeView: nodeView,
|
|
261
291
|
targetNode: targetNode,
|
|
262
|
-
colorScheme: colorScheme
|
|
292
|
+
colorScheme: colorScheme,
|
|
293
|
+
isInserted: isInserted
|
|
263
294
|
});
|
|
264
295
|
blockWrapper.append(contentWrapper);
|
|
265
296
|
if (nodeView instanceof HTMLElement && shouldAddShowDiffDeletedNodeClass(targetNode.type.name)) {
|
|
@@ -274,18 +305,28 @@ var wrapBlockNode = function wrapBlockNode(_ref5) {
|
|
|
274
305
|
* For heading nodes, applies styles directly to preserve natural margins.
|
|
275
306
|
* For other block nodes, uses wrapper approach with optional lozenge.
|
|
276
307
|
*/
|
|
277
|
-
var wrapBlockNodeView = exports.wrapBlockNodeView = function wrapBlockNodeView(
|
|
278
|
-
var dom =
|
|
279
|
-
nodeView =
|
|
280
|
-
targetNode =
|
|
281
|
-
colorScheme =
|
|
282
|
-
intl =
|
|
308
|
+
var wrapBlockNodeView = exports.wrapBlockNodeView = function wrapBlockNodeView(_ref7) {
|
|
309
|
+
var dom = _ref7.dom,
|
|
310
|
+
nodeView = _ref7.nodeView,
|
|
311
|
+
targetNode = _ref7.targetNode,
|
|
312
|
+
colorScheme = _ref7.colorScheme,
|
|
313
|
+
intl = _ref7.intl,
|
|
314
|
+
_ref7$isInserted = _ref7.isInserted,
|
|
315
|
+
isInserted = _ref7$isInserted === void 0 ? false : _ref7$isInserted;
|
|
283
316
|
if (shouldApplyStylesDirectly(targetNode.type.name) && nodeView instanceof HTMLElement) {
|
|
284
317
|
// Apply deleted styles directly to preserve natural block-level margins
|
|
285
318
|
applyStylesToElement({
|
|
286
319
|
element: nodeView,
|
|
287
320
|
targetNode: targetNode,
|
|
288
|
-
colorScheme: colorScheme
|
|
321
|
+
colorScheme: colorScheme,
|
|
322
|
+
isInserted: isInserted
|
|
323
|
+
});
|
|
324
|
+
dom.append(nodeView);
|
|
325
|
+
} else if (targetNode.type.name === 'table' && nodeView instanceof HTMLElement && (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
326
|
+
applyCellOverlayStyles({
|
|
327
|
+
element: nodeView,
|
|
328
|
+
colorScheme: colorScheme,
|
|
329
|
+
isInserted: isInserted
|
|
289
330
|
});
|
|
290
331
|
dom.append(nodeView);
|
|
291
332
|
} else {
|
|
@@ -295,7 +336,8 @@ var wrapBlockNodeView = exports.wrapBlockNodeView = function wrapBlockNodeView(_
|
|
|
295
336
|
nodeView: nodeView,
|
|
296
337
|
targetNode: targetNode,
|
|
297
338
|
colorScheme: colorScheme,
|
|
298
|
-
intl: intl
|
|
339
|
+
intl: intl,
|
|
340
|
+
isInserted: isInserted
|
|
299
341
|
});
|
|
300
342
|
}
|
|
301
343
|
};
|
|
@@ -12,6 +12,7 @@ var _state2 = require("@atlaskit/editor-prosemirror/state");
|
|
|
12
12
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
13
13
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
14
14
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
15
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
15
16
|
var _calculateDiffDecorations = require("./calculateDiffDecorations");
|
|
16
17
|
var _NodeViewSerializer = require("./NodeViewSerializer");
|
|
17
18
|
var _scrollToActiveDecoration = require("./scrollToActiveDecoration");
|
|
@@ -36,25 +37,28 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
|
|
|
36
37
|
state: {
|
|
37
38
|
init: function init(_, _state) {
|
|
38
39
|
// We do initial setup after we setup the editor view
|
|
39
|
-
return {
|
|
40
|
+
return _objectSpread({
|
|
40
41
|
steps: [],
|
|
41
42
|
originalDoc: undefined,
|
|
42
43
|
decorations: _view.DecorationSet.empty,
|
|
43
44
|
isDisplayingChanges: false
|
|
44
|
-
}
|
|
45
|
+
}, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
|
|
46
|
+
isInverted: false
|
|
47
|
+
} : {});
|
|
45
48
|
},
|
|
46
49
|
apply: function apply(tr, currentPluginState, oldState, newState) {
|
|
47
50
|
var meta = tr.getMeta(showDiffPluginKey);
|
|
48
51
|
var newPluginState = currentPluginState;
|
|
49
52
|
if (meta) {
|
|
50
53
|
if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'SHOW_DIFF') {
|
|
54
|
+
var _newPluginState;
|
|
51
55
|
// Update the plugin state with the new metadata
|
|
52
56
|
newPluginState = _objectSpread(_objectSpread(_objectSpread({}, currentPluginState), meta), {}, {
|
|
53
57
|
isDisplayingChanges: true,
|
|
54
58
|
activeIndex: undefined
|
|
55
59
|
});
|
|
56
60
|
// Calculate and store decorations in state
|
|
57
|
-
var decorations = (0, _calculateDiffDecorations.calculateDiffDecorations)({
|
|
61
|
+
var decorations = (0, _calculateDiffDecorations.calculateDiffDecorations)(_objectSpread({
|
|
58
62
|
state: newState,
|
|
59
63
|
pluginState: newPluginState,
|
|
60
64
|
nodeViewSerializer: nodeViewSerializer,
|
|
@@ -62,7 +66,9 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
|
|
|
62
66
|
intl: getIntl(),
|
|
63
67
|
activeIndexPos: (0, _platformFeatureFlags.fg)('platform_editor_show_diff_scroll_navigation') ? newPluginState.activeIndexPos : undefined,
|
|
64
68
|
api: api
|
|
65
|
-
})
|
|
69
|
+
}, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
|
|
70
|
+
isInverted: (_newPluginState = newPluginState) === null || _newPluginState === void 0 ? void 0 : _newPluginState.isInverted
|
|
71
|
+
} : {}));
|
|
66
72
|
// Update the decorations
|
|
67
73
|
newPluginState.decorations = decorations;
|
|
68
74
|
} else if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'HIDE_DIFF') {
|
|
@@ -70,7 +76,9 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
|
|
|
70
76
|
decorations: _view.DecorationSet.empty,
|
|
71
77
|
isDisplayingChanges: false,
|
|
72
78
|
activeIndex: undefined
|
|
73
|
-
})
|
|
79
|
+
}, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
|
|
80
|
+
isInverted: false
|
|
81
|
+
} : {});
|
|
74
82
|
} 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') && (0, _platformFeatureFlags.fg)('platform_editor_show_diff_scroll_navigation')) {
|
|
75
83
|
// Update the active index in plugin state and recalculate decorations
|
|
76
84
|
var _decorations = getScrollableDecorations(currentPluginState.decorations);
|
|
@@ -99,7 +107,7 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
|
|
|
99
107
|
} : undefined
|
|
100
108
|
});
|
|
101
109
|
// Recalculate decorations with the new active index
|
|
102
|
-
var updatedDecorations = (0, _calculateDiffDecorations.calculateDiffDecorations)({
|
|
110
|
+
var updatedDecorations = (0, _calculateDiffDecorations.calculateDiffDecorations)(_objectSpread({
|
|
103
111
|
state: newState,
|
|
104
112
|
pluginState: newPluginState,
|
|
105
113
|
nodeViewSerializer: nodeViewSerializer,
|
|
@@ -107,7 +115,9 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
|
|
|
107
115
|
intl: getIntl(),
|
|
108
116
|
activeIndexPos: newPluginState.activeIndexPos,
|
|
109
117
|
api: api
|
|
110
|
-
})
|
|
118
|
+
}, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
|
|
119
|
+
isInverted: newPluginState.isInverted
|
|
120
|
+
} : {}));
|
|
111
121
|
newPluginState.decorations = updatedDecorations;
|
|
112
122
|
}
|
|
113
123
|
} else {
|
|
@@ -15,19 +15,21 @@ const calculateNodesForBlockDecoration = ({
|
|
|
15
15
|
doc,
|
|
16
16
|
from,
|
|
17
17
|
to,
|
|
18
|
-
colorScheme
|
|
18
|
+
colorScheme,
|
|
19
|
+
isInserted = true
|
|
19
20
|
}) => {
|
|
20
21
|
const decorations = [];
|
|
21
22
|
// Iterate over the document nodes within the range
|
|
22
23
|
doc.nodesBetween(from, to, (node, pos) => {
|
|
23
|
-
if (node.isBlock) {
|
|
24
|
+
if (node.isBlock && (!expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) || pos + node.nodeSize <= to)) {
|
|
24
25
|
const decoration = createBlockChangedDecoration({
|
|
25
26
|
change: {
|
|
26
27
|
from: pos,
|
|
27
28
|
to: pos + node.nodeSize,
|
|
28
29
|
name: node.type.name
|
|
29
30
|
},
|
|
30
|
-
colorScheme
|
|
31
|
+
colorScheme,
|
|
32
|
+
isInserted
|
|
31
33
|
});
|
|
32
34
|
if (decoration) {
|
|
33
35
|
decorations.push(decoration);
|
|
@@ -80,7 +82,8 @@ const calculateDiffDecorationsInner = ({
|
|
|
80
82
|
colorScheme,
|
|
81
83
|
intl,
|
|
82
84
|
activeIndexPos,
|
|
83
|
-
api
|
|
85
|
+
api,
|
|
86
|
+
isInverted = false
|
|
84
87
|
}) => {
|
|
85
88
|
const {
|
|
86
89
|
originalDoc,
|
|
@@ -130,17 +133,25 @@ const calculateDiffDecorationsInner = ({
|
|
|
130
133
|
const decorations = [];
|
|
131
134
|
optimizedChanges.forEach(change => {
|
|
132
135
|
const isActive = activeIndexPos && change.fromB >= activeIndexPos.from && change.toB <= activeIndexPos.to;
|
|
136
|
+
// Our default operations are insertions, so it should match the opposite of isInverted.
|
|
137
|
+
const isInserted = !isInverted;
|
|
133
138
|
if (change.inserted.length > 0) {
|
|
134
139
|
decorations.push(createInlineChangedDecoration({
|
|
135
140
|
change,
|
|
136
141
|
colorScheme,
|
|
137
|
-
isActive
|
|
142
|
+
isActive,
|
|
143
|
+
...(expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) && {
|
|
144
|
+
isInserted
|
|
145
|
+
})
|
|
138
146
|
}));
|
|
139
147
|
decorations.push(...calculateNodesForBlockDecoration({
|
|
140
148
|
doc: tr.doc,
|
|
141
149
|
from: change.fromB,
|
|
142
150
|
to: change.toB,
|
|
143
|
-
colorScheme
|
|
151
|
+
colorScheme,
|
|
152
|
+
...(expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) && {
|
|
153
|
+
isInserted
|
|
154
|
+
})
|
|
144
155
|
}));
|
|
145
156
|
}
|
|
146
157
|
if (change.deleted.length > 0) {
|
|
@@ -152,7 +163,10 @@ const calculateDiffDecorationsInner = ({
|
|
|
152
163
|
colorScheme,
|
|
153
164
|
newDoc: tr.doc,
|
|
154
165
|
intl,
|
|
155
|
-
isActive
|
|
166
|
+
isActive,
|
|
167
|
+
...(expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) && {
|
|
168
|
+
isInserted: !isInserted
|
|
169
|
+
})
|
|
156
170
|
});
|
|
157
171
|
if (decoration) {
|
|
158
172
|
decorations.push(...decoration);
|
|
@@ -164,7 +178,8 @@ const calculateDiffDecorationsInner = ({
|
|
|
164
178
|
decorations.push(createInlineChangedDecoration({
|
|
165
179
|
change,
|
|
166
180
|
colorScheme,
|
|
167
|
-
isActive
|
|
181
|
+
isActive,
|
|
182
|
+
isInserted: true
|
|
168
183
|
}));
|
|
169
184
|
});
|
|
170
185
|
getAttrChangeRanges(tr.doc, attrSteps).forEach(change => {
|
|
@@ -172,7 +187,8 @@ const calculateDiffDecorationsInner = ({
|
|
|
172
187
|
doc: tr.doc,
|
|
173
188
|
from: change.fromB,
|
|
174
189
|
to: change.toB,
|
|
175
|
-
colorScheme
|
|
190
|
+
colorScheme,
|
|
191
|
+
isInserted: true
|
|
176
192
|
}));
|
|
177
193
|
});
|
|
178
194
|
return DecorationSet.empty.add(tr.doc, decorations);
|
|
@@ -184,15 +200,21 @@ export const calculateDiffDecorations = memoizeOne(calculateDiffDecorationsInner
|
|
|
184
200
|
state,
|
|
185
201
|
colorScheme,
|
|
186
202
|
intl,
|
|
187
|
-
activeIndexPos
|
|
203
|
+
activeIndexPos,
|
|
204
|
+
isInverted
|
|
188
205
|
}], [{
|
|
189
206
|
pluginState: lastPluginState,
|
|
190
207
|
state: lastState,
|
|
191
208
|
colorScheme: lastColorScheme,
|
|
192
209
|
intl: lastIntl,
|
|
193
|
-
activeIndexPos: lastActiveIndexPos
|
|
210
|
+
activeIndexPos: lastActiveIndexPos,
|
|
211
|
+
isInverted: lastIsInverted
|
|
194
212
|
}]) => {
|
|
195
|
-
var
|
|
213
|
+
var _ref2;
|
|
196
214
|
const originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
|
|
197
|
-
|
|
215
|
+
if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
216
|
+
var _ref;
|
|
217
|
+
return (_ref = colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isInverted === lastIsInverted && isEqual(activeIndexPos, lastActiveIndexPos) && originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc)) !== null && _ref !== void 0 ? _ref : false;
|
|
218
|
+
}
|
|
219
|
+
return (_ref2 = originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isEqual(activeIndexPos, lastActiveIndexPos)) !== null && _ref2 !== void 0 ? _ref2 : false;
|
|
198
220
|
});
|
|
@@ -89,4 +89,26 @@ export const editingStyleCardBlockNode = convertToInlineCss({
|
|
|
89
89
|
});
|
|
90
90
|
export const standardDecorationMarkerVariable = convertToInlineCss({
|
|
91
91
|
'--diff-decoration-marker-color': "var(--ds-border-accent-purple, #AF59E1)"
|
|
92
|
+
});
|
|
93
|
+
export const addedCellOverlayStyle = convertToInlineCss({
|
|
94
|
+
position: 'absolute',
|
|
95
|
+
top: 0,
|
|
96
|
+
left: 0,
|
|
97
|
+
width: '100%',
|
|
98
|
+
height: '100%',
|
|
99
|
+
backgroundColor: `rgba(from ${"var(--ds-background-accent-purple-subtlest, #F8EEFE)"} r g b / 0.5)`,
|
|
100
|
+
zIndex: 1,
|
|
101
|
+
outline: `1px solid ${"var(--ds-border-accent-purple, #AF59E1)"}`,
|
|
102
|
+
pointerEvents: 'none'
|
|
103
|
+
});
|
|
104
|
+
export const deletedCellOverlayStyle = convertToInlineCss({
|
|
105
|
+
position: 'absolute',
|
|
106
|
+
top: 0,
|
|
107
|
+
left: 0,
|
|
108
|
+
width: '100%',
|
|
109
|
+
height: '100%',
|
|
110
|
+
backgroundColor: `rgba(from ${"var(--ds-background-accent-gray-subtlest, #F0F1F2)"} r g b / 0.5)`,
|
|
111
|
+
zIndex: 1,
|
|
112
|
+
outline: `1px solid ${"var(--ds-border-accent-gray, #7D818A)"}`,
|
|
113
|
+
pointerEvents: 'none'
|
|
92
114
|
});
|
|
@@ -66,4 +66,26 @@ export const traditionalStyleCardBlockNode = convertToInlineCss({
|
|
|
66
66
|
});
|
|
67
67
|
export const traditionalDecorationMarkerVariable = convertToInlineCss({
|
|
68
68
|
'--diff-decoration-marker-color': "var(--ds-border-accent-green, #22A06B)"
|
|
69
|
+
});
|
|
70
|
+
export const traditionalAddedCellOverlayStyle = convertToInlineCss({
|
|
71
|
+
position: 'absolute',
|
|
72
|
+
top: 0,
|
|
73
|
+
left: 0,
|
|
74
|
+
width: '100%',
|
|
75
|
+
height: '100%',
|
|
76
|
+
backgroundColor: `rgba(from ${"var(--ds-background-accent-green-subtlest, #DCFFF1)"} r g b / 0.5)`,
|
|
77
|
+
zIndex: 1,
|
|
78
|
+
outline: `1px solid ${"var(--ds-border-accent-green, #22A06B)"}`,
|
|
79
|
+
pointerEvents: 'none'
|
|
80
|
+
});
|
|
81
|
+
export const deletedTraditionalCellOverlayStyle = convertToInlineCss({
|
|
82
|
+
position: 'absolute',
|
|
83
|
+
top: 0,
|
|
84
|
+
left: 0,
|
|
85
|
+
width: '100%',
|
|
86
|
+
height: '100%',
|
|
87
|
+
backgroundColor: `rgba(from ${"var(--ds-background-accent-gray-subtlest, #F0F1F2)"} r g b / 0.5)`,
|
|
88
|
+
zIndex: 1,
|
|
89
|
+
outline: `1px solid ${"var(--ds-border-disabled, #0515240F)"}`,
|
|
90
|
+
pointerEvents: 'none'
|
|
69
91
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
2
2
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
4
|
+
import { standardDecorationMarkerVariable, editingStyleQuoteNode, editingStyleRuleNode, editingStyleCardBlockNode, editingStyleNode, deletedContentStyleNew, deletedStyleQuoteNode } from './colorSchemes/standard';
|
|
5
|
+
import { traditionalDecorationMarkerVariable, traditionalStyleQuoteNode, traditionalStyleRuleNode, traditionalStyleCardBlockNode, traditionalStyleNode, deletedTraditionalContentStyle, deletedTraditionalStyleQuoteNode } from './colorSchemes/traditional';
|
|
5
6
|
const getNodeClass = name => {
|
|
6
7
|
switch (name) {
|
|
7
8
|
case 'extension':
|
|
@@ -10,7 +11,11 @@ const getNodeClass = name => {
|
|
|
10
11
|
return undefined;
|
|
11
12
|
}
|
|
12
13
|
};
|
|
13
|
-
const getBlockNodeStyle = (
|
|
14
|
+
const getBlockNodeStyle = ({
|
|
15
|
+
nodeName,
|
|
16
|
+
colorScheme,
|
|
17
|
+
isInserted = true
|
|
18
|
+
}) => {
|
|
14
19
|
const isTraditional = colorScheme === 'traditional';
|
|
15
20
|
if (['mediaSingle', 'mediaGroup', 'table',
|
|
16
21
|
// Handle table separately to avoid border issues
|
|
@@ -21,17 +26,52 @@ const getBlockNodeStyle = (nodeName, colorScheme) => {
|
|
|
21
26
|
return undefined;
|
|
22
27
|
}
|
|
23
28
|
if (['extension', 'embedCard', 'listItem'].includes(nodeName)) {
|
|
29
|
+
if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
30
|
+
if (isInserted) {
|
|
31
|
+
return isTraditional ? traditionalDecorationMarkerVariable : standardDecorationMarkerVariable;
|
|
32
|
+
} else {
|
|
33
|
+
return isTraditional ? deletedTraditionalContentStyle : deletedContentStyleNew;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
24
36
|
return isTraditional ? traditionalDecorationMarkerVariable : standardDecorationMarkerVariable;
|
|
25
37
|
}
|
|
26
38
|
if (nodeName === 'blockquote') {
|
|
39
|
+
if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
40
|
+
if (isInserted) {
|
|
41
|
+
return isTraditional ? traditionalStyleQuoteNode : editingStyleQuoteNode;
|
|
42
|
+
} else {
|
|
43
|
+
return isTraditional ? deletedTraditionalStyleQuoteNode : deletedStyleQuoteNode;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
27
46
|
return isTraditional ? traditionalStyleQuoteNode : editingStyleQuoteNode;
|
|
28
47
|
}
|
|
29
48
|
if (nodeName === 'rule') {
|
|
49
|
+
if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
50
|
+
if (isInserted) {
|
|
51
|
+
return isTraditional ? traditionalStyleRuleNode : editingStyleRuleNode;
|
|
52
|
+
} else {
|
|
53
|
+
return isTraditional ? deletedTraditionalContentStyle : deletedContentStyleNew;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
30
56
|
return isTraditional ? traditionalStyleRuleNode : editingStyleRuleNode;
|
|
31
57
|
}
|
|
32
58
|
if (nodeName === 'blockCard') {
|
|
59
|
+
if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
60
|
+
if (isInserted) {
|
|
61
|
+
return isTraditional ? traditionalStyleCardBlockNode : editingStyleCardBlockNode;
|
|
62
|
+
} else {
|
|
63
|
+
return isTraditional ? deletedTraditionalContentStyle : deletedContentStyleNew;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
33
66
|
return isTraditional ? traditionalStyleCardBlockNode : editingStyleCardBlockNode;
|
|
34
67
|
}
|
|
68
|
+
if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
69
|
+
if (isInserted) {
|
|
70
|
+
return isTraditional ? traditionalStyleNode : editingStyleNode;
|
|
71
|
+
} else {
|
|
72
|
+
return isTraditional ? deletedTraditionalContentStyle : deletedContentStyleNew;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
35
75
|
return isTraditional ? traditionalStyleNode : editingStyleNode;
|
|
36
76
|
};
|
|
37
77
|
|
|
@@ -43,11 +83,22 @@ const getBlockNodeStyle = (nodeName, colorScheme) => {
|
|
|
43
83
|
*/
|
|
44
84
|
export const createBlockChangedDecoration = ({
|
|
45
85
|
change,
|
|
46
|
-
colorScheme
|
|
86
|
+
colorScheme,
|
|
87
|
+
isInserted = true
|
|
47
88
|
}) => {
|
|
89
|
+
let style = getBlockNodeStyle({
|
|
90
|
+
nodeName: change.name,
|
|
91
|
+
colorScheme
|
|
92
|
+
});
|
|
93
|
+
if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
94
|
+
style = getBlockNodeStyle({
|
|
95
|
+
nodeName: change.name,
|
|
96
|
+
colorScheme,
|
|
97
|
+
isInserted
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const className = getNodeClass(change.name);
|
|
48
101
|
if (fg('platform_editor_show_diff_scroll_navigation')) {
|
|
49
|
-
const style = getBlockNodeStyle(change.name, colorScheme);
|
|
50
|
-
const className = getNodeClass(change.name);
|
|
51
102
|
if (style || className) {
|
|
52
103
|
return Decoration.node(change.from, change.to, {
|
|
53
104
|
style: style,
|
|
@@ -60,9 +111,9 @@ export const createBlockChangedDecoration = ({
|
|
|
60
111
|
return undefined;
|
|
61
112
|
} else {
|
|
62
113
|
return Decoration.node(change.from, change.to, {
|
|
63
|
-
style
|
|
114
|
+
style,
|
|
64
115
|
'data-testid': 'show-diff-changed-decoration-node',
|
|
65
|
-
class:
|
|
116
|
+
class: className
|
|
66
117
|
}, {
|
|
67
118
|
key: 'diff-block'
|
|
68
119
|
});
|