@atlaskit/editor-plugin-show-diff 10.0.1 → 10.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 +19 -0
- package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +25 -8
- package/dist/cjs/pm-plugins/decorations/createAnchorDecorationWidgets.js +209 -0
- package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +17 -2
- package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +19 -3
- package/dist/cjs/pm-plugins/decorations/decorationKeys.js +81 -28
- package/dist/cjs/pm-plugins/getScrollableDecorations.js +32 -23
- package/dist/cjs/pm-plugins/main.js +8 -6
- package/dist/cjs/pm-plugins/scrollToDiff.js +5 -6
- package/dist/cjs/showDiffPlugin.js +12 -1
- package/dist/cjs/ui/IndicatorBar/IndicatorBar.compiled.css +9 -0
- package/dist/cjs/ui/IndicatorBar/IndicatorBar.js +33 -0
- package/dist/cjs/ui/IndicatorBar/IndicatorBarContentComponent.js +87 -0
- package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +23 -8
- package/dist/es2019/pm-plugins/decorations/createAnchorDecorationWidgets.js +205 -0
- package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +14 -2
- package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +19 -4
- package/dist/es2019/pm-plugins/decorations/decorationKeys.js +64 -14
- package/dist/es2019/pm-plugins/getScrollableDecorations.js +31 -25
- package/dist/es2019/pm-plugins/main.js +8 -6
- package/dist/es2019/pm-plugins/scrollToDiff.js +6 -7
- package/dist/es2019/showDiffPlugin.js +12 -1
- package/dist/es2019/ui/IndicatorBar/IndicatorBar.compiled.css +9 -0
- package/dist/es2019/ui/IndicatorBar/IndicatorBar.js +24 -0
- package/dist/es2019/ui/IndicatorBar/IndicatorBarContentComponent.js +82 -0
- package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +25 -8
- package/dist/esm/pm-plugins/decorations/createAnchorDecorationWidgets.js +203 -0
- package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +16 -2
- package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +20 -4
- package/dist/esm/pm-plugins/decorations/decorationKeys.js +78 -27
- package/dist/esm/pm-plugins/getScrollableDecorations.js +33 -24
- package/dist/esm/pm-plugins/main.js +8 -6
- package/dist/esm/pm-plugins/scrollToDiff.js +6 -7
- package/dist/esm/showDiffPlugin.js +12 -1
- package/dist/esm/ui/IndicatorBar/IndicatorBar.compiled.css +9 -0
- package/dist/esm/ui/IndicatorBar/IndicatorBar.js +25 -0
- package/dist/esm/ui/IndicatorBar/IndicatorBarContentComponent.js +80 -0
- package/dist/types/pm-plugins/calculateDiff/calculateDiffDecorations.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/createAnchorDecorationWidgets.d.ts +38 -0
- package/dist/types/pm-plugins/decorations/createInlineChangedDecoration.d.ts +4 -1
- package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/decorationKeys.d.ts +56 -17
- package/dist/types/pm-plugins/main.d.ts +1 -0
- package/dist/types/pm-plugins/scrollToDiff.d.ts +2 -2
- package/dist/types/showDiffPluginType.d.ts +8 -0
- package/dist/types/ui/IndicatorBar/IndicatorBar.d.ts +10 -0
- package/dist/types/ui/IndicatorBar/IndicatorBarContentComponent.d.ts +17 -0
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-show-diff
|
|
2
2
|
|
|
3
|
+
## 10.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`96a8a99060dfc`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/96a8a99060dfc) -
|
|
8
|
+
EDITOR-7523: Add diff indicators to the left doc margin
|
|
9
|
+
|
|
10
|
+
## 10.0.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
|
|
16
|
+
## 10.0.2
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
|
|
3
22
|
## 10.0.1
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -15,6 +15,7 @@ var _document = require("@atlaskit/editor-common/utils/document");
|
|
|
15
15
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
16
16
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
17
17
|
var _areDocsEqualByBlockStructureAndText = require("../areDocsEqualByBlockStructureAndText");
|
|
18
|
+
var _createAnchorDecorationWidgets = require("../decorations/createAnchorDecorationWidgets");
|
|
18
19
|
var _createBlockChangedDecoration = require("../decorations/createBlockChangedDecoration");
|
|
19
20
|
var _createInlineChangedDecoration = require("../decorations/createInlineChangedDecoration");
|
|
20
21
|
var _createNodeChangedDecorationWidget = require("../decorations/createNodeChangedDecorationWidget");
|
|
@@ -94,10 +95,13 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
|
|
|
94
95
|
_ref3$diffType = _ref3.diffType,
|
|
95
96
|
diffType = _ref3$diffType === void 0 ? 'inline' : _ref3$diffType,
|
|
96
97
|
_ref3$hideDeletedDiff = _ref3.hideDeletedDiffs,
|
|
97
|
-
hideDeletedDiffs = _ref3$hideDeletedDiff === void 0 ? false : _ref3$hideDeletedDiff
|
|
98
|
+
hideDeletedDiffs = _ref3$hideDeletedDiff === void 0 ? false : _ref3$hideDeletedDiff,
|
|
99
|
+
_ref3$showIndicators = _ref3.showIndicators,
|
|
100
|
+
showIndicators = _ref3$showIndicators === void 0 ? false : _ref3$showIndicators;
|
|
98
101
|
var originalDoc = pluginState.originalDoc,
|
|
99
|
-
steps = pluginState.steps
|
|
100
|
-
|
|
102
|
+
steps = pluginState.steps,
|
|
103
|
+
isDisplayingChanges = pluginState.isDisplayingChanges;
|
|
104
|
+
if (!originalDoc || !isDisplayingChanges) {
|
|
101
105
|
return {
|
|
102
106
|
decorations: _view.DecorationSet.empty,
|
|
103
107
|
diffDescriptors: []
|
|
@@ -160,6 +164,13 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
|
|
|
160
164
|
steps: steps
|
|
161
165
|
});
|
|
162
166
|
var decorations = [];
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* If showIndicators is on, we create an anchor widget here to mark the doc margin.
|
|
170
|
+
*/
|
|
171
|
+
if (showIndicators && (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
172
|
+
decorations.push((0, _createAnchorDecorationWidgets.createDocMarginAnchorWidget)());
|
|
173
|
+
}
|
|
163
174
|
changes.forEach(function (change) {
|
|
164
175
|
var isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
|
|
165
176
|
// Our default operations are insertions, so it should match the opposite of isInverted.
|
|
@@ -168,11 +179,13 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
|
|
|
168
179
|
var shouldHideDeleted = (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? isInverted && hideDeletedDiffs : false;
|
|
169
180
|
decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createInlineChangedDecoration.createInlineChangedDecoration)(_objectSpread({
|
|
170
181
|
change: change,
|
|
182
|
+
doc: tr.doc,
|
|
171
183
|
colorScheme: colorScheme,
|
|
172
184
|
isActive: isActive
|
|
173
185
|
}, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) && {
|
|
174
186
|
isInserted: isInserted,
|
|
175
|
-
shouldHideDeleted: shouldHideDeleted
|
|
187
|
+
shouldHideDeleted: shouldHideDeleted,
|
|
188
|
+
showIndicators: showIndicators
|
|
176
189
|
}))));
|
|
177
190
|
decorations.push.apply(decorations, (0, _toConsumableArray2.default)(calculateNodesForBlockDecoration(_objectSpread(_objectSpread({
|
|
178
191
|
doc: tr.doc,
|
|
@@ -190,7 +203,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
|
|
|
190
203
|
if (change.deleted.length > 0) {
|
|
191
204
|
var _shouldHideDeleted = (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? !isInverted && hideDeletedDiffs : false;
|
|
192
205
|
if (!_shouldHideDeleted) {
|
|
193
|
-
decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createNodeChangedDecorationWidget.createNodeChangedDecorationWidget)(_objectSpread({
|
|
206
|
+
decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createNodeChangedDecorationWidget.createNodeChangedDecorationWidget)(_objectSpread(_objectSpread({
|
|
194
207
|
change: change,
|
|
195
208
|
doc: originalDoc,
|
|
196
209
|
nodeViewSerializer: nodeViewSerializer,
|
|
@@ -201,6 +214,8 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
|
|
|
201
214
|
}, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) && {
|
|
202
215
|
isInserted: !isInserted,
|
|
203
216
|
diffType: diffType
|
|
217
|
+
}), {}, {
|
|
218
|
+
showIndicators: showIndicators
|
|
204
219
|
}))));
|
|
205
220
|
}
|
|
206
221
|
}
|
|
@@ -255,7 +270,8 @@ function (_ref4, _ref5) {
|
|
|
255
270
|
activeIndexPos = _ref6$.activeIndexPos,
|
|
256
271
|
isInverted = _ref6$.isInverted,
|
|
257
272
|
diffType = _ref6$.diffType,
|
|
258
|
-
hideDeletedDiffs = _ref6$.hideDeletedDiffs
|
|
273
|
+
hideDeletedDiffs = _ref6$.hideDeletedDiffs,
|
|
274
|
+
showIndicators = _ref6$.showIndicators;
|
|
259
275
|
var _ref7 = (0, _slicedToArray2.default)(_ref5, 1),
|
|
260
276
|
_ref7$ = _ref7[0],
|
|
261
277
|
lastPluginState = _ref7$.pluginState,
|
|
@@ -265,11 +281,12 @@ function (_ref4, _ref5) {
|
|
|
265
281
|
lastActiveIndexPos = _ref7$.activeIndexPos,
|
|
266
282
|
lastIsInverted = _ref7$.isInverted,
|
|
267
283
|
lastDiffType = _ref7$.diffType,
|
|
268
|
-
lastHideDeletedDiffs = _ref7$.hideDeletedDiffs
|
|
284
|
+
lastHideDeletedDiffs = _ref7$.hideDeletedDiffs,
|
|
285
|
+
lastShowIndicators = _ref7$.showIndicators;
|
|
269
286
|
var originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
|
|
270
287
|
if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
271
288
|
var _ref8;
|
|
272
|
-
return (_ref8 = colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isInverted === lastIsInverted && diffType === lastDiffType && (0, _isEqual.default)(activeIndexPos, lastActiveIndexPos) && originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && hideDeletedDiffs === lastHideDeletedDiffs) !== null && _ref8 !== void 0 ? _ref8 : false;
|
|
289
|
+
return (_ref8 = colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isInverted === lastIsInverted && diffType === lastDiffType && (0, _isEqual.default)(activeIndexPos, lastActiveIndexPos) && originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && hideDeletedDiffs === lastHideDeletedDiffs && showIndicators === lastShowIndicators) !== null && _ref8 !== void 0 ? _ref8 : false;
|
|
273
290
|
}
|
|
274
291
|
return (_ref9 = originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && (0, _isEqual.default)(activeIndexPos, lastActiveIndexPos) && hideDeletedDiffs === lastHideDeletedDiffs) !== null && _ref9 !== void 0 ? _ref9 : false;
|
|
275
292
|
});
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createLeftAnchorWidget = exports.createInlineIndicatorAnchorWidgets = exports.createDocMarginAnchorWidget = void 0;
|
|
7
|
+
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
8
|
+
var _decorationKeys = require("./decorationKeys");
|
|
9
|
+
var SIDE = 1;
|
|
10
|
+
var findPosAfterLastChild = function findPosAfterLastChild(node, nodeStart) {
|
|
11
|
+
if (!node) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
var lastChild = node.lastChild;
|
|
15
|
+
if (!lastChild) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
var lastChildStart = nodeStart + node.content.size - lastChild.nodeSize;
|
|
19
|
+
return lastChildStart + lastChild.nodeSize;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Handles edge cases for block nodes whose inline content can exceed the doc
|
|
24
|
+
* margin (tables, layouts, expands). Returns an adjusted position to use as
|
|
25
|
+
* the left anchor, or `undefined` when no adjustment is needed.
|
|
26
|
+
*/
|
|
27
|
+
var edgeCases = function edgeCases(doc, from) {
|
|
28
|
+
var $from = doc.resolve(from);
|
|
29
|
+
var docLevelNode = $from.node(1);
|
|
30
|
+
if (!docLevelNode) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
switch (docLevelNode.type.name) {
|
|
34
|
+
/**
|
|
35
|
+
* For resizable blocks, inline content can exceed the doc margin.
|
|
36
|
+
* The widgets need to be placed inside the block as resizing the block will
|
|
37
|
+
* exceed the block container :')
|
|
38
|
+
*/
|
|
39
|
+
case 'table':
|
|
40
|
+
{
|
|
41
|
+
var lastRow = docLevelNode.lastChild;
|
|
42
|
+
if (!lastRow) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
var lastRowStart = $from.start(1) + docLevelNode.content.size - lastRow.nodeSize;
|
|
46
|
+
var firstCellOfLastRow = lastRow.firstChild;
|
|
47
|
+
var tableAnchorPos = findPosAfterLastChild(firstCellOfLastRow, lastRowStart + 1);
|
|
48
|
+
if (tableAnchorPos === undefined) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
/**
|
|
53
|
+
* We use the last row because the first row could be a sticky header -
|
|
54
|
+
* when it becomes sticky the anchor won't be defined since it will be rendered
|
|
55
|
+
* outside of the context
|
|
56
|
+
*/
|
|
57
|
+
pos: tableAnchorPos,
|
|
58
|
+
leftMargin: "var(--ds-space-negative-025, -2px)",
|
|
59
|
+
side: -1
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
case 'expand':
|
|
63
|
+
{
|
|
64
|
+
var expandAnchorPos = findPosAfterLastChild(docLevelNode, $from.start(1));
|
|
65
|
+
if (expandAnchorPos === undefined) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
pos: expandAnchorPos,
|
|
70
|
+
leftMargin: "var(--ds-space-0, 0px)",
|
|
71
|
+
side: -1
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
case 'layoutSection':
|
|
75
|
+
{
|
|
76
|
+
var firstLayoutColumn = docLevelNode.firstChild;
|
|
77
|
+
var layoutAnchorPos = findPosAfterLastChild(firstLayoutColumn, $from.start(1) + 1);
|
|
78
|
+
if (layoutAnchorPos === undefined) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
pos: layoutAnchorPos,
|
|
83
|
+
leftMargin: "var(--ds-space-negative-025, -2px)",
|
|
84
|
+
side: 1
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
default:
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Create a widget that marks the start of the doc margin.
|
|
94
|
+
* This is used to determine the position of the inline indicators
|
|
95
|
+
* when the inline content exceeds the doc margin.
|
|
96
|
+
*/
|
|
97
|
+
var createDocMarginAnchorWidget = exports.createDocMarginAnchorWidget = function createDocMarginAnchorWidget() {
|
|
98
|
+
return _view.Decoration.widget(0, function () {
|
|
99
|
+
var span = document.createElement('span');
|
|
100
|
+
span.style.setProperty('anchor-name', "--".concat(_decorationKeys.AnchorDocMarginKey));
|
|
101
|
+
return span;
|
|
102
|
+
}, (0, _decorationKeys.buildAnchorDecorationSpec)({
|
|
103
|
+
anchorType: _decorationKeys.AnchorTypeKey.docMargin,
|
|
104
|
+
side: SIDE
|
|
105
|
+
}));
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Creates an invisible left anchor widget for a diff inside a resizable block
|
|
110
|
+
* node (table, layout, expand), whose inline content can exceed the doc margin.
|
|
111
|
+
* Resolves the edge-case position from `doc`/`from`; returns `undefined` when
|
|
112
|
+
* the diff is not inside such a node and no left anchor is needed.
|
|
113
|
+
*
|
|
114
|
+
* The span is given an `anchor-name` (keyed by `diffId`) and positioned in the
|
|
115
|
+
* doc margin so the `IndicatorBar` can align its left edge against it via CSS
|
|
116
|
+
* anchor positioning. Shared by inline and node (widget) diff decorations.
|
|
117
|
+
*/
|
|
118
|
+
var createLeftAnchorWidget = exports.createLeftAnchorWidget = function createLeftAnchorWidget(_ref) {
|
|
119
|
+
var doc = _ref.doc,
|
|
120
|
+
from = _ref.from,
|
|
121
|
+
diffId = _ref.diffId;
|
|
122
|
+
var edgeCase = edgeCases(doc, from);
|
|
123
|
+
if (edgeCase === undefined) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
var leftAnchorKey = (0, _decorationKeys.buildAnchorDecorationKey)({
|
|
127
|
+
diffId: diffId,
|
|
128
|
+
anchorType: _decorationKeys.AnchorTypeKey.left
|
|
129
|
+
});
|
|
130
|
+
return _view.Decoration.widget(edgeCase.pos, function () {
|
|
131
|
+
var span = document.createElement('span');
|
|
132
|
+
span.style.setProperty('anchor-name', "--".concat(leftAnchorKey));
|
|
133
|
+
span.style.setProperty('position', 'absolute');
|
|
134
|
+
span.style.setProperty('left', edgeCase.leftMargin);
|
|
135
|
+
return span;
|
|
136
|
+
}, (0, _decorationKeys.buildAnchorDecorationSpec)({
|
|
137
|
+
diffId: diffId,
|
|
138
|
+
anchorType: _decorationKeys.AnchorTypeKey.left,
|
|
139
|
+
side: edgeCase.side * SIDE
|
|
140
|
+
}));
|
|
141
|
+
};
|
|
142
|
+
var isFullNodeRange = function isFullNodeRange(doc, from, to) {
|
|
143
|
+
var matchesFullNodeRange = false;
|
|
144
|
+
doc.nodesBetween(from, to, function (node, pos) {
|
|
145
|
+
if (pos === from && pos + node.nodeSize === to) {
|
|
146
|
+
matchesFullNodeRange = true;
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
});
|
|
151
|
+
return matchesFullNodeRange;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Creates invisible anchor widgets for a single inline diff range so that the
|
|
155
|
+
* `IndicatorBar` can use CSS anchor positioning to align itself with the diff.
|
|
156
|
+
*
|
|
157
|
+
* - A `from` anchor is placed at the start of the range (top of the bar).
|
|
158
|
+
* - A `to` anchor is placed at the end of the range (bottom of the bar).
|
|
159
|
+
* - An optional `left` anchor is placed before the first textblock when the
|
|
160
|
+
* diff is inside a resizable block node (table, layout, expand).
|
|
161
|
+
*/
|
|
162
|
+
var createInlineIndicatorAnchorWidgets = exports.createInlineIndicatorAnchorWidgets = function createInlineIndicatorAnchorWidgets(_ref2) {
|
|
163
|
+
var doc = _ref2.doc,
|
|
164
|
+
from = _ref2.from,
|
|
165
|
+
to = _ref2.to,
|
|
166
|
+
diffId = _ref2.diffId;
|
|
167
|
+
if (isFullNodeRange(doc, from, to)) {
|
|
168
|
+
return [];
|
|
169
|
+
}
|
|
170
|
+
var leftAnchor = createLeftAnchorWidget({
|
|
171
|
+
doc: doc,
|
|
172
|
+
from: from,
|
|
173
|
+
diffId: diffId
|
|
174
|
+
});
|
|
175
|
+
var maybeLeftAnchor = leftAnchor ? [leftAnchor] : [];
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Two widgets mark the start and end of the inline range so the
|
|
179
|
+
* IndicatorBar can determine top/bottom even when the decoration
|
|
180
|
+
* spans multiple blocks.
|
|
181
|
+
*/
|
|
182
|
+
var fromAnchorKey = (0, _decorationKeys.buildAnchorDecorationKey)({
|
|
183
|
+
diffId: diffId,
|
|
184
|
+
anchorType: _decorationKeys.AnchorTypeKey.from
|
|
185
|
+
});
|
|
186
|
+
var fromWidget = _view.Decoration.widget(from, function () {
|
|
187
|
+
var span = document.createElement('span');
|
|
188
|
+
span.style.setProperty('anchor-name', "--".concat(fromAnchorKey));
|
|
189
|
+
return span;
|
|
190
|
+
}, (0, _decorationKeys.buildAnchorDecorationSpec)({
|
|
191
|
+
diffId: diffId,
|
|
192
|
+
anchorType: _decorationKeys.AnchorTypeKey.from,
|
|
193
|
+
side: 1
|
|
194
|
+
}));
|
|
195
|
+
var toAnchorKey = (0, _decorationKeys.buildAnchorDecorationKey)({
|
|
196
|
+
diffId: diffId,
|
|
197
|
+
anchorType: _decorationKeys.AnchorTypeKey.to
|
|
198
|
+
});
|
|
199
|
+
var toWidget = _view.Decoration.widget(to, function () {
|
|
200
|
+
var span = document.createElement('span');
|
|
201
|
+
span.style.setProperty('anchor-name', "--".concat(toAnchorKey));
|
|
202
|
+
return span;
|
|
203
|
+
}, (0, _decorationKeys.buildAnchorDecorationSpec)({
|
|
204
|
+
diffId: diffId,
|
|
205
|
+
anchorType: _decorationKeys.AnchorTypeKey.to,
|
|
206
|
+
side: -1
|
|
207
|
+
}));
|
|
208
|
+
return [fromWidget, toWidget].concat(maybeLeftAnchor);
|
|
209
|
+
};
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.createInlineChangedDecoration = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
7
9
|
var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
|
|
8
10
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
9
11
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
10
12
|
var _standard = require("./colorSchemes/standard");
|
|
11
13
|
var _traditional = require("./colorSchemes/traditional");
|
|
14
|
+
var _createAnchorDecorationWidgets = require("./createAnchorDecorationWidgets");
|
|
12
15
|
var _decorationKeys = require("./decorationKeys");
|
|
13
16
|
var displayNoneStyle = (0, _lazyNodeView.convertToInlineCss)({
|
|
14
17
|
display: 'none'
|
|
@@ -28,7 +31,10 @@ var createInlineChangedDecoration = exports.createInlineChangedDecoration = func
|
|
|
28
31
|
_ref$isInserted = _ref.isInserted,
|
|
29
32
|
isInserted = _ref$isInserted === void 0 ? true : _ref$isInserted,
|
|
30
33
|
_ref$shouldHideDelete = _ref.shouldHideDeleted,
|
|
31
|
-
shouldHideDeleted = _ref$shouldHideDelete === void 0 ? false : _ref$shouldHideDelete
|
|
34
|
+
shouldHideDeleted = _ref$shouldHideDelete === void 0 ? false : _ref$shouldHideDelete,
|
|
35
|
+
_ref$showIndicators = _ref.showIndicators,
|
|
36
|
+
showIndicators = _ref$showIndicators === void 0 ? false : _ref$showIndicators,
|
|
37
|
+
doc = _ref.doc;
|
|
32
38
|
var diffId = crypto.randomUUID();
|
|
33
39
|
if (shouldHideDeleted) {
|
|
34
40
|
return [_view.Decoration.inline(change.fromB, change.toB, {
|
|
@@ -67,7 +73,7 @@ var createInlineChangedDecoration = exports.createInlineChangedDecoration = func
|
|
|
67
73
|
style = isActive ? _standard.editingStyleActive : _standard.editingStyle;
|
|
68
74
|
}
|
|
69
75
|
}
|
|
70
|
-
|
|
76
|
+
var decorations = [_view.Decoration.inline(change.fromB, change.toB, {
|
|
71
77
|
style: style,
|
|
72
78
|
'data-testid': 'show-diff-changed-decoration'
|
|
73
79
|
}, (0, _decorationKeys.buildDiffDecorationSpec)({
|
|
@@ -75,4 +81,13 @@ var createInlineChangedDecoration = exports.createInlineChangedDecoration = func
|
|
|
75
81
|
diffId: diffId,
|
|
76
82
|
isActive: isActive
|
|
77
83
|
}))];
|
|
84
|
+
if (showIndicators && doc && (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
85
|
+
decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createAnchorDecorationWidgets.createInlineIndicatorAnchorWidgets)({
|
|
86
|
+
doc: doc,
|
|
87
|
+
from: change.fromB,
|
|
88
|
+
to: change.toB,
|
|
89
|
+
diffId: diffId
|
|
90
|
+
})));
|
|
91
|
+
}
|
|
92
|
+
return decorations;
|
|
78
93
|
};
|
|
@@ -12,6 +12,7 @@ var _view = require("@atlaskit/editor-prosemirror/view");
|
|
|
12
12
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
13
13
|
var _standard = require("./colorSchemes/standard");
|
|
14
14
|
var _traditional = require("./colorSchemes/traditional");
|
|
15
|
+
var _createAnchorDecorationWidgets = require("./createAnchorDecorationWidgets");
|
|
15
16
|
var _createChangedRowDecorationWidgets = require("./createChangedRowDecorationWidgets");
|
|
16
17
|
var _decorationKeys = require("./decorationKeys");
|
|
17
18
|
var _findSafeInsertPos = require("./utils/findSafeInsertPos");
|
|
@@ -114,7 +115,9 @@ var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidge
|
|
|
114
115
|
intl = _ref2.intl,
|
|
115
116
|
activeIndexPos = _ref2.activeIndexPos,
|
|
116
117
|
_ref2$isInserted = _ref2.isInserted,
|
|
117
|
-
isInserted = _ref2$isInserted === void 0 ? false : _ref2$isInserted
|
|
118
|
+
isInserted = _ref2$isInserted === void 0 ? false : _ref2$isInserted,
|
|
119
|
+
_ref2$showIndicators = _ref2.showIndicators,
|
|
120
|
+
showIndicators = _ref2$showIndicators === void 0 ? false : _ref2$showIndicators;
|
|
118
121
|
var slice = doc.slice(change.fromA, change.toA);
|
|
119
122
|
var shouldSkipDeletedEmptyParagraphDecoration = !isInserted && (slice === null || slice === void 0 || (_slice$content = slice.content) === null || _slice$content === void 0 ? void 0 : _slice$content.childCount) === 1 && (slice === null || slice === void 0 || (_slice$content2 = slice.content) === null || _slice$content2 === void 0 || (_slice$content2 = _slice$content2.firstChild) === null || _slice$content2 === void 0 ? void 0 : _slice$content2.type.name) === 'paragraph' && (slice === null || slice === void 0 || (_slice$content3 = slice.content) === null || _slice$content3 === void 0 || (_slice$content3 = _slice$content3.firstChild) === null || _slice$content3 === void 0 ? void 0 : _slice$content3.content.size) === 0;
|
|
120
123
|
// Widget decoration used for deletions as the content is not in the document
|
|
@@ -151,6 +154,8 @@ var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidge
|
|
|
151
154
|
|
|
152
155
|
// For non-table content, use the existing span wrapper approach
|
|
153
156
|
var dom = document.createElement('span');
|
|
157
|
+
var diffId = crypto.randomUUID();
|
|
158
|
+
var decorations = [];
|
|
154
159
|
|
|
155
160
|
/*
|
|
156
161
|
* The thinking is we separate out the fragment we got from doc.slice
|
|
@@ -256,8 +261,19 @@ var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidge
|
|
|
256
261
|
}
|
|
257
262
|
});
|
|
258
263
|
dom.setAttribute('data-testid', 'show-diff-deleted-decoration');
|
|
259
|
-
|
|
260
|
-
|
|
264
|
+
if (showIndicators && (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
265
|
+
var leftAnchor = (0, _createAnchorDecorationWidgets.createLeftAnchorWidget)({
|
|
266
|
+
doc: newDoc,
|
|
267
|
+
from: safeInsertPos,
|
|
268
|
+
diffId: diffId
|
|
269
|
+
});
|
|
270
|
+
dom.style.setProperty('anchor-name', "--".concat((0, _decorationKeys.buildAnchorDecorationKey)({
|
|
271
|
+
diffId: diffId
|
|
272
|
+
})));
|
|
273
|
+
if (leftAnchor) {
|
|
274
|
+
decorations.push(leftAnchor);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
261
277
|
decorations.push(_view.Decoration.widget(safeInsertPos, dom, (0, _decorationKeys.buildDiffDecorationSpec)(_objectSpread({
|
|
262
278
|
decorationType: 'widget',
|
|
263
279
|
diffId: diffId,
|
|
@@ -4,49 +4,67 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.buildAnchorDecorationKey = exports.DiffDecorationKey = exports.DecorationFamily = exports.AnchorTypeKey = exports.AnchorDocMarginKey = void 0;
|
|
8
|
+
exports.buildAnchorDecorationSpec = buildAnchorDecorationSpec;
|
|
9
|
+
exports.isDiffDecorationSpec = exports.isDiffDecoration = exports.isAnchorDecorationSpec = exports.extractDiffDescriptors = exports.buildDiffDecorationSpec = exports.buildDiffDecorationKey = void 0;
|
|
10
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
8
11
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
12
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
10
13
|
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; }
|
|
11
14
|
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) { (0, _defineProperty2.default)(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; }
|
|
12
15
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* identified by this single prefix.
|
|
16
|
+
* Decoration families produced by the show-diff plugin.
|
|
17
|
+
* Each family owns its own key space and spec shape.
|
|
16
18
|
*/
|
|
17
|
-
var
|
|
19
|
+
var DecorationFamily = exports.DecorationFamily = {
|
|
20
|
+
diff: 'diff',
|
|
21
|
+
anchor: 'anchor'
|
|
22
|
+
};
|
|
23
|
+
var AnchorTypeKey = exports.AnchorTypeKey = {
|
|
24
|
+
from: 'from',
|
|
25
|
+
to: 'to',
|
|
26
|
+
left: 'left',
|
|
27
|
+
docMargin: 'doc-margin'
|
|
28
|
+
};
|
|
18
29
|
/**
|
|
19
|
-
* The kinds
|
|
20
|
-
* leading segment of the generated key, so a decoration's kind can be
|
|
21
|
-
* with `key?.startsWith(DiffDecorationKey.inline)` etc.
|
|
30
|
+
* The diff-decoration kinds produced by the show-diff plugin. Each value is
|
|
31
|
+
* the leading segment of the generated key, so a diff decoration's kind can be
|
|
32
|
+
* matched with `key?.startsWith(DiffDecorationKey.inline)` etc.
|
|
22
33
|
*/
|
|
23
34
|
var DiffDecorationKey = exports.DiffDecorationKey = {
|
|
24
|
-
inline: "".concat(
|
|
25
|
-
block: "".concat(
|
|
26
|
-
widget: "".concat(
|
|
35
|
+
inline: "".concat(DecorationFamily.diff, "-inline"),
|
|
36
|
+
block: "".concat(DecorationFamily.diff, "-block"),
|
|
37
|
+
widget: "".concat(DecorationFamily.diff, "-widget")
|
|
38
|
+
};
|
|
39
|
+
var AnchorDocMarginKey = exports.AnchorDocMarginKey = "".concat(DecorationFamily.anchor, "-").concat(AnchorTypeKey.docMargin);
|
|
40
|
+
var buildAnchorDecorationKey = exports.buildAnchorDecorationKey = function buildAnchorDecorationKey(_ref) {
|
|
41
|
+
var diffId = _ref.diffId,
|
|
42
|
+
anchorType = _ref.anchorType;
|
|
43
|
+
return "".concat(DecorationFamily.anchor, "-").concat(diffId).concat(anchorType ? "-".concat(anchorType) : '');
|
|
27
44
|
};
|
|
28
45
|
|
|
29
46
|
/**
|
|
30
|
-
* Builds a decoration key
|
|
31
|
-
*
|
|
47
|
+
* Builds a diff decoration key. The extended experience includes the `diffId`
|
|
48
|
+
* in the key so independently rendered decorations for the same type remain
|
|
49
|
+
* distinguishable.
|
|
32
50
|
*/
|
|
33
|
-
var buildDiffDecorationKey = exports.buildDiffDecorationKey = function buildDiffDecorationKey(
|
|
34
|
-
var decorationKeyPrefix =
|
|
35
|
-
isActive =
|
|
36
|
-
diffId =
|
|
51
|
+
var buildDiffDecorationKey = exports.buildDiffDecorationKey = function buildDiffDecorationKey(_ref2) {
|
|
52
|
+
var decorationKeyPrefix = _ref2.decorationKeyPrefix,
|
|
53
|
+
isActive = _ref2.isActive,
|
|
54
|
+
diffId = _ref2.diffId;
|
|
37
55
|
if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
38
56
|
return "".concat(decorationKeyPrefix, "-").concat(diffId, "-").concat(isActive ? 'active' : 'inactive');
|
|
39
57
|
}
|
|
40
58
|
return isActive !== undefined ? "".concat(decorationKeyPrefix, "-").concat(isActive ? 'active' : 'inactive') : decorationKeyPrefix;
|
|
41
59
|
};
|
|
42
|
-
var buildDiffDecorationSpec = exports.buildDiffDecorationSpec = function buildDiffDecorationSpec(
|
|
43
|
-
var decorationType =
|
|
44
|
-
diffId =
|
|
45
|
-
isActive =
|
|
46
|
-
nodeName =
|
|
47
|
-
side =
|
|
60
|
+
var buildDiffDecorationSpec = exports.buildDiffDecorationSpec = function buildDiffDecorationSpec(_ref3) {
|
|
61
|
+
var decorationType = _ref3.decorationType,
|
|
62
|
+
diffId = _ref3.diffId,
|
|
63
|
+
isActive = _ref3.isActive,
|
|
64
|
+
nodeName = _ref3.nodeName,
|
|
65
|
+
side = _ref3.side;
|
|
48
66
|
return _objectSpread(_objectSpread({
|
|
49
|
-
decorationFamily:
|
|
67
|
+
decorationFamily: DecorationFamily.diff,
|
|
50
68
|
decorationType: decorationType,
|
|
51
69
|
diffId: diffId,
|
|
52
70
|
key: buildDiffDecorationKey({
|
|
@@ -60,11 +78,46 @@ var buildDiffDecorationSpec = exports.buildDiffDecorationSpec = function buildDi
|
|
|
60
78
|
side: side
|
|
61
79
|
} : {});
|
|
62
80
|
};
|
|
81
|
+
function buildAnchorDecorationSpec(_ref4) {
|
|
82
|
+
var anchorType = _ref4.anchorType,
|
|
83
|
+
diffId = _ref4.diffId,
|
|
84
|
+
side = _ref4.side;
|
|
85
|
+
if (anchorType === AnchorTypeKey.docMargin) {
|
|
86
|
+
return _objectSpread({
|
|
87
|
+
decorationFamily: DecorationFamily.anchor,
|
|
88
|
+
anchorType: anchorType,
|
|
89
|
+
key: AnchorDocMarginKey
|
|
90
|
+
}, side !== undefined ? {
|
|
91
|
+
side: side
|
|
92
|
+
} : {});
|
|
93
|
+
}
|
|
94
|
+
if (!diffId) {
|
|
95
|
+
throw new Error("diffId is required for anchor type \"".concat(anchorType, "\""));
|
|
96
|
+
}
|
|
97
|
+
return _objectSpread({
|
|
98
|
+
decorationFamily: DecorationFamily.anchor,
|
|
99
|
+
anchorType: anchorType,
|
|
100
|
+
diffId: diffId,
|
|
101
|
+
key: buildAnchorDecorationKey({
|
|
102
|
+
diffId: diffId,
|
|
103
|
+
anchorType: anchorType
|
|
104
|
+
})
|
|
105
|
+
}, side !== undefined ? {
|
|
106
|
+
side: side
|
|
107
|
+
} : {});
|
|
108
|
+
}
|
|
109
|
+
var isDiffDecorationSpec = exports.isDiffDecorationSpec = function isDiffDecorationSpec(spec) {
|
|
110
|
+
return Boolean(spec && (0, _typeof2.default)(spec) === 'object' && 'decorationFamily' in spec && spec.decorationFamily === DecorationFamily.diff);
|
|
111
|
+
};
|
|
112
|
+
var isAnchorDecorationSpec = exports.isAnchorDecorationSpec = function isAnchorDecorationSpec(spec) {
|
|
113
|
+
return Boolean(spec && (0, _typeof2.default)(spec) === 'object' && 'decorationFamily' in spec && spec.decorationFamily === DecorationFamily.anchor);
|
|
114
|
+
};
|
|
115
|
+
var isDiffDecoration = exports.isDiffDecoration = function isDiffDecoration(decoration) {
|
|
116
|
+
return isDiffDecorationSpec(decoration.spec);
|
|
117
|
+
};
|
|
63
118
|
var extractDiffDescriptors = exports.extractDiffDescriptors = function extractDiffDescriptors(decorations) {
|
|
64
|
-
return decorations.find(undefined, undefined, function (
|
|
65
|
-
|
|
66
|
-
}).map(function (_ref3) {
|
|
67
|
-
var spec = _ref3.spec;
|
|
119
|
+
return decorations.find(undefined, undefined, isDiffDecorationSpec).filter(isDiffDecoration).map(function (_ref5) {
|
|
120
|
+
var spec = _ref5.spec;
|
|
68
121
|
return {
|
|
69
122
|
id: spec.diffId,
|
|
70
123
|
type: spec.decorationType
|