@atlaskit/editor-plugin-show-diff 14.0.3 → 14.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 +21 -0
- package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +204 -101
- package/dist/cjs/pm-plugins/calculateDiff/diffBySteps.js +20 -9
- package/dist/cjs/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +89 -0
- package/dist/cjs/pm-plugins/calculateDiff/simplifySteps.js +81 -4
- package/dist/cjs/pm-plugins/decorations/colorSchemes/attributions.js +68 -0
- package/dist/cjs/pm-plugins/decorations/colorSchemes/schemes.js +26 -2
- package/dist/cjs/pm-plugins/decorations/colorSchemes/types.js +5 -1
- package/dist/cjs/pm-plugins/decorations/createBlockChangedDecoration.js +7 -2
- package/dist/cjs/pm-plugins/decorations/createChangedRowDecorationWidgets.js +2 -2
- package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +4 -2
- package/dist/cjs/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +14 -10
- package/dist/cjs/pm-plugins/main.js +1 -0
- package/dist/cjs/showDiffPlugin.js +36 -14
- package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +118 -26
- package/dist/es2019/pm-plugins/calculateDiff/diffBySteps.js +17 -9
- package/dist/es2019/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +64 -0
- package/dist/es2019/pm-plugins/calculateDiff/simplifySteps.js +64 -1
- package/dist/es2019/pm-plugins/decorations/colorSchemes/attributions.js +37 -0
- package/dist/es2019/pm-plugins/decorations/colorSchemes/schemes.js +19 -2
- package/dist/es2019/pm-plugins/decorations/colorSchemes/types.js +1 -0
- package/dist/es2019/pm-plugins/decorations/createBlockChangedDecoration.js +6 -3
- package/dist/es2019/pm-plugins/decorations/createChangedRowDecorationWidgets.js +3 -3
- package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +6 -3
- package/dist/es2019/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +12 -9
- package/dist/es2019/pm-plugins/main.js +1 -0
- package/dist/es2019/showDiffPlugin.js +23 -1
- package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +205 -102
- package/dist/esm/pm-plugins/calculateDiff/diffBySteps.js +20 -9
- package/dist/esm/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +82 -0
- package/dist/esm/pm-plugins/calculateDiff/simplifySteps.js +79 -5
- package/dist/esm/pm-plugins/decorations/colorSchemes/attributions.js +61 -0
- package/dist/esm/pm-plugins/decorations/colorSchemes/schemes.js +24 -1
- package/dist/esm/pm-plugins/decorations/colorSchemes/types.js +1 -0
- package/dist/esm/pm-plugins/decorations/createBlockChangedDecoration.js +8 -3
- package/dist/esm/pm-plugins/decorations/createChangedRowDecorationWidgets.js +3 -3
- package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +5 -3
- package/dist/esm/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +14 -9
- package/dist/esm/pm-plugins/main.js +1 -0
- package/dist/esm/showDiffPlugin.js +36 -14
- package/dist/types/entry-points/show-diff-plugin-type.d.ts +1 -1
- package/dist/types/pm-plugins/calculateDiff/diffBySteps.d.ts +2 -1
- package/dist/types/pm-plugins/calculateDiff/simplifyChangesWithAttribution.d.ts +7 -0
- package/dist/types/pm-plugins/calculateDiff/simplifySteps.d.ts +10 -0
- package/dist/types/pm-plugins/decorations/colorSchemes/attributions.d.ts +12 -0
- package/dist/types/pm-plugins/decorations/colorSchemes/schemes.d.ts +5 -3
- package/dist/types/pm-plugins/decorations/colorSchemes/types.d.ts +6 -1
- 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 +2 -1
- package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.d.ts +2 -1
- package/dist/types/pm-plugins/main.d.ts +3 -1
- package/dist/types/showDiffPluginType.d.ts +29 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-show-diff
|
|
2
2
|
|
|
3
|
+
## 14.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`69574af99ed9e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/69574af99ed9e) -
|
|
8
|
+
[ux] Add attributed-step inputs and internally selected, gated agent colours behind
|
|
9
|
+
`confluence_ncs_step_diffing_version_history` and
|
|
10
|
+
`platform_editor_show_diff_color_scheme_refactor`.
|
|
11
|
+
|
|
12
|
+
## 14.0.4
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [`62c3227f6a3ac`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/62c3227f6a3ac) -
|
|
17
|
+
[CCI-19031] Fix large-table diffs suppressing decorations on adjacent inserted content. When a
|
|
18
|
+
paragraph (or other block) is inserted next to a large table, the smart classifier coalesces them
|
|
19
|
+
into a single node-level change. The coarse large-table decoration path now scopes cell-only
|
|
20
|
+
suppression to the table subtree, so adjacent inserted content keeps its highlight and indicator
|
|
21
|
+
instead of being dropped.
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
|
|
3
24
|
## 14.0.3
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.isDeletedContentPlacedBelow = exports.calculateDiffDecorations = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
9
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
11
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
12
12
|
var _memoizeOne = _interopRequireDefault(require("memoize-one"));
|
|
13
13
|
var _prosemirrorChangeset = require("prosemirror-changeset");
|
|
@@ -21,6 +21,7 @@ var _createAnchorDecorationWidgets = require("../decorations/createAnchorDecorat
|
|
|
21
21
|
var _createBlockChangedDecoration = require("../decorations/createBlockChangedDecoration");
|
|
22
22
|
var _createInlineChangedDecoration = require("../decorations/createInlineChangedDecoration");
|
|
23
23
|
var _createNodeChangedDecorationWidget = require("../decorations/createNodeChangedDecorationWidget");
|
|
24
|
+
var _attributions = require("../decorations/colorSchemes/attributions");
|
|
24
25
|
var _decorationKeys = require("../decorations/decorationKeys");
|
|
25
26
|
var _getAttrChangeRanges = require("../decorations/utils/getAttrChangeRanges");
|
|
26
27
|
var _getMarkChangeRanges = require("../decorations/utils/getMarkChangeRanges");
|
|
@@ -29,6 +30,7 @@ var _attrAwareTokenEncoder = require("./attrAwareTokenEncoder");
|
|
|
29
30
|
var _diffBySteps = require("./diffBySteps");
|
|
30
31
|
var _groupChangesByBlock = require("./groupChangesByBlock");
|
|
31
32
|
var _optimizeChanges = require("./optimizeChanges");
|
|
33
|
+
var _simplifyChangesWithAttribution = require("./simplifyChangesWithAttribution");
|
|
32
34
|
var _simplifySteps = require("./simplifySteps");
|
|
33
35
|
var _classifySmartChanges = require("./smart/classifySmartChanges");
|
|
34
36
|
var _helpers = require("./smart/helpers");
|
|
@@ -72,6 +74,34 @@ var getChanges = function getChanges(_ref) {
|
|
|
72
74
|
var changes = (0, _prosemirrorChangeset.simplifyChanges)(changeset.changes, tr.doc);
|
|
73
75
|
return (0, _optimizeChanges.optimizeChanges)(changes);
|
|
74
76
|
};
|
|
77
|
+
var getAttributedChanges = function getAttributedChanges(_ref2) {
|
|
78
|
+
var attributedChanges = _ref2.attributedChanges,
|
|
79
|
+
changeset = _ref2.changeset,
|
|
80
|
+
originalDoc = _ref2.originalDoc,
|
|
81
|
+
steppedDoc = _ref2.steppedDoc,
|
|
82
|
+
diffType = _ref2.diffType,
|
|
83
|
+
tr = _ref2.tr,
|
|
84
|
+
intl = _ref2.intl,
|
|
85
|
+
smartThresholds = _ref2.smartThresholds;
|
|
86
|
+
if ((0, _isExtendedEnabled.isExtendedEnabled)(diffType)) {
|
|
87
|
+
if (diffType === 'smart' && (0, _fg.fg)('platform_editor_ai_smart_diff')) {
|
|
88
|
+
return (0, _classifySmartChanges.classifySmartChanges)({
|
|
89
|
+
changes: (0, _simplifyChangesWithAttribution.simplifyChangesWithAttribution)(attributedChanges, tr.doc),
|
|
90
|
+
originalDoc: originalDoc,
|
|
91
|
+
newDoc: tr.doc,
|
|
92
|
+
locale: intl.locale,
|
|
93
|
+
thresholds: smartThresholds
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (diffType === 'step') {
|
|
97
|
+
return attributedChanges;
|
|
98
|
+
}
|
|
99
|
+
if (diffType === 'block') {
|
|
100
|
+
return (0, _groupChangesByBlock.groupChangesByBlock)(changeset.changes, originalDoc, steppedDoc);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return (0, _simplifyChangesWithAttribution.simplifyChangesWithAttribution)(attributedChanges, tr.doc);
|
|
104
|
+
};
|
|
75
105
|
|
|
76
106
|
/**
|
|
77
107
|
* Collect the inline-content ranges of every leaf text-bearing block (paragraph, heading, …)
|
|
@@ -115,27 +145,51 @@ var isLargeInsertedTableRange = function isLargeInsertedTableRange(doc, from, to
|
|
|
115
145
|
});
|
|
116
146
|
return containsTable && leafCount > LARGE_TABLE_LEAF_THRESHOLD;
|
|
117
147
|
};
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
148
|
+
|
|
149
|
+
// Collect the [from, to) ranges of every `table` node overlapping `[from, to)`. The coarse
|
|
150
|
+
// large-table path must only suppress decorations inside these ranges
|
|
151
|
+
var tableRanges = function tableRanges(doc, from, to) {
|
|
152
|
+
var ranges = [];
|
|
153
|
+
doc.nodesBetween(from, to, function (node, pos) {
|
|
154
|
+
if (node.type.name === 'table') {
|
|
155
|
+
ranges.push([pos, pos + node.nodeSize]);
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
});
|
|
160
|
+
return ranges;
|
|
161
|
+
};
|
|
162
|
+
var isInsideTable = function isInsideTable(tables, pos) {
|
|
163
|
+
return tables.some(function (_ref3) {
|
|
164
|
+
var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
|
|
165
|
+
tFrom = _ref4[0],
|
|
166
|
+
tTo = _ref4[1];
|
|
167
|
+
return pos >= tFrom && pos < tTo;
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration(_ref5) {
|
|
171
|
+
var doc = _ref5.doc,
|
|
172
|
+
from = _ref5.from,
|
|
173
|
+
to = _ref5.to,
|
|
174
|
+
colorScheme = _ref5.colorScheme,
|
|
175
|
+
_ref5$isInserted = _ref5.isInserted,
|
|
176
|
+
isInserted = _ref5$isInserted === void 0 ? true : _ref5$isInserted,
|
|
177
|
+
activeIndexPos = _ref5.activeIndexPos,
|
|
178
|
+
_ref5$shouldHideDelet = _ref5.shouldHideDeleted,
|
|
179
|
+
shouldHideDeleted = _ref5$shouldHideDelet === void 0 ? false : _ref5$shouldHideDelet,
|
|
180
|
+
_ref5$showIndicators = _ref5.showIndicators,
|
|
181
|
+
showIndicators = _ref5$showIndicators === void 0 ? false : _ref5$showIndicators,
|
|
182
|
+
diffType = _ref5.diffType,
|
|
183
|
+
_ref5$coarseTableCell = _ref5.coarseTableCellsOnly,
|
|
184
|
+
coarseTableCellsOnly = _ref5$coarseTableCell === void 0 ? false : _ref5$coarseTableCell;
|
|
133
185
|
var decorations = [];
|
|
186
|
+
// Coarse path: inside the large table, only cell/header overlays are kept — the
|
|
187
|
+
// table/row/paragraph decorations there are redundant and cause expensive per-cell
|
|
188
|
+
// re-render. Blocks outside the table keep their normal decorations.
|
|
189
|
+
var coarseTables = coarseTableCellsOnly ? tableRanges(doc, from, to) : [];
|
|
134
190
|
// Iterate over the document nodes within the range
|
|
135
191
|
doc.nodesBetween(from, to, function (node, pos) {
|
|
136
|
-
|
|
137
|
-
// decorations are redundant and cause expensive per-cell re-render.
|
|
138
|
-
if (coarseTableCellsOnly) {
|
|
192
|
+
if (coarseTableCellsOnly && isInsideTable(coarseTables, pos)) {
|
|
139
193
|
var name = node.type.name;
|
|
140
194
|
if (name !== 'tableCell' && name !== 'tableHeader') {
|
|
141
195
|
return;
|
|
@@ -173,10 +227,10 @@ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration
|
|
|
173
227
|
*
|
|
174
228
|
* Callers are responsible for the `smart` diffType and gate checks.
|
|
175
229
|
*/
|
|
176
|
-
var isDeletedContentPlacedBelow = exports.isDeletedContentPlacedBelow = function isDeletedContentPlacedBelow(
|
|
177
|
-
var change =
|
|
178
|
-
deletedDiffPlacement =
|
|
179
|
-
inlineDeletedDiffPlacement =
|
|
230
|
+
var isDeletedContentPlacedBelow = exports.isDeletedContentPlacedBelow = function isDeletedContentPlacedBelow(_ref6) {
|
|
231
|
+
var change = _ref6.change,
|
|
232
|
+
deletedDiffPlacement = _ref6.deletedDiffPlacement,
|
|
233
|
+
inlineDeletedDiffPlacement = _ref6.inlineDeletedDiffPlacement;
|
|
180
234
|
var level = (0, _helpers.smartChangeLevel)(change);
|
|
181
235
|
if (level === 'node' || level === 'paragraph') {
|
|
182
236
|
return deletedDiffPlacement === 'bottom';
|
|
@@ -185,31 +239,32 @@ var isDeletedContentPlacedBelow = exports.isDeletedContentPlacedBelow = function
|
|
|
185
239
|
// Inline-level (undefined) and sentence-level changes.
|
|
186
240
|
return inlineDeletedDiffPlacement === 'after';
|
|
187
241
|
};
|
|
188
|
-
var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(
|
|
189
|
-
var state =
|
|
190
|
-
pluginState =
|
|
191
|
-
nodeViewSerializer =
|
|
192
|
-
colorScheme =
|
|
193
|
-
intl =
|
|
194
|
-
activeIndexPos =
|
|
195
|
-
api =
|
|
196
|
-
|
|
197
|
-
isInverted =
|
|
198
|
-
|
|
199
|
-
diffType =
|
|
200
|
-
|
|
201
|
-
hideDeletedDiffs =
|
|
202
|
-
|
|
203
|
-
hideAddedDiffsUnderlineParam =
|
|
204
|
-
|
|
205
|
-
showIndicators =
|
|
206
|
-
smartThresholds =
|
|
207
|
-
|
|
208
|
-
deletedDiffPlacement =
|
|
209
|
-
|
|
210
|
-
inlineDeletedDiffPlacement =
|
|
242
|
+
var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref7) {
|
|
243
|
+
var state = _ref7.state,
|
|
244
|
+
pluginState = _ref7.pluginState,
|
|
245
|
+
nodeViewSerializer = _ref7.nodeViewSerializer,
|
|
246
|
+
colorScheme = _ref7.colorScheme,
|
|
247
|
+
intl = _ref7.intl,
|
|
248
|
+
activeIndexPos = _ref7.activeIndexPos,
|
|
249
|
+
api = _ref7.api,
|
|
250
|
+
_ref7$isInverted = _ref7.isInverted,
|
|
251
|
+
isInverted = _ref7$isInverted === void 0 ? false : _ref7$isInverted,
|
|
252
|
+
_ref7$diffType = _ref7.diffType,
|
|
253
|
+
diffType = _ref7$diffType === void 0 ? (0, _isExtendedEnabled.getDefaultDiffType)() : _ref7$diffType,
|
|
254
|
+
_ref7$hideDeletedDiff = _ref7.hideDeletedDiffs,
|
|
255
|
+
hideDeletedDiffs = _ref7$hideDeletedDiff === void 0 ? false : _ref7$hideDeletedDiff,
|
|
256
|
+
_ref7$hideAddedDiffsU = _ref7.hideAddedDiffsUnderline,
|
|
257
|
+
hideAddedDiffsUnderlineParam = _ref7$hideAddedDiffsU === void 0 ? false : _ref7$hideAddedDiffsU,
|
|
258
|
+
_ref7$showIndicators = _ref7.showIndicators,
|
|
259
|
+
showIndicators = _ref7$showIndicators === void 0 ? false : _ref7$showIndicators,
|
|
260
|
+
smartThresholds = _ref7.smartThresholds,
|
|
261
|
+
_ref7$deletedDiffPlac = _ref7.deletedDiffPlacement,
|
|
262
|
+
deletedDiffPlacement = _ref7$deletedDiffPlac === void 0 ? 'top' : _ref7$deletedDiffPlac,
|
|
263
|
+
_ref7$inlineDeletedDi = _ref7.inlineDeletedDiffPlacement,
|
|
264
|
+
inlineDeletedDiffPlacement = _ref7$inlineDeletedDi === void 0 ? 'before' : _ref7$inlineDeletedDi;
|
|
211
265
|
var originalDoc = pluginState.originalDoc,
|
|
212
266
|
steps = pluginState.steps,
|
|
267
|
+
stepAttributions = pluginState.stepAttributions,
|
|
213
268
|
isDisplayingChanges = pluginState.isDisplayingChanges;
|
|
214
269
|
if (!originalDoc || !isDisplayingChanges) {
|
|
215
270
|
return {
|
|
@@ -223,8 +278,23 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
|
|
|
223
278
|
var hideAddedDiffsUnderline = hideAddedDiffsUnderlineParam && (0, _fg.fg)('platform_editor_ai_smart_diff');
|
|
224
279
|
var tr = state.tr;
|
|
225
280
|
var steppedDoc = originalDoc;
|
|
281
|
+
var attributionColoringEnabled = (0, _attributions.isAttributionColoringEnabled)(stepAttributions);
|
|
282
|
+
var simplifiedSteps;
|
|
283
|
+
var simplifiedStepAttributions = [];
|
|
284
|
+
if (attributionColoringEnabled) {
|
|
285
|
+
var simplifiedStepsWithAttribution = (0, _simplifySteps.simplifyStepsWithAttribution)(steps, stepAttributions !== null && stepAttributions !== void 0 ? stepAttributions : [], originalDoc);
|
|
286
|
+
simplifiedSteps = simplifiedStepsWithAttribution.map(function (_ref8) {
|
|
287
|
+
var step = _ref8.step;
|
|
288
|
+
return step;
|
|
289
|
+
});
|
|
290
|
+
simplifiedStepAttributions = simplifiedStepsWithAttribution.map(function (_ref9) {
|
|
291
|
+
var stepAttribution = _ref9.stepAttribution;
|
|
292
|
+
return stepAttribution;
|
|
293
|
+
});
|
|
294
|
+
} else {
|
|
295
|
+
simplifiedSteps = (0, _simplifySteps.simplifySteps)(steps, originalDoc);
|
|
296
|
+
}
|
|
226
297
|
var attrSteps = [];
|
|
227
|
-
var simplifiedSteps = (0, _simplifySteps.simplifySteps)(steps, originalDoc);
|
|
228
298
|
var stepMaps = [];
|
|
229
299
|
var _iterator = _createForOfIteratorHelper(simplifiedSteps),
|
|
230
300
|
_step;
|
|
@@ -272,17 +342,45 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
|
|
|
272
342
|
// gated with it; other diff types keep the library default so their output is
|
|
273
343
|
// unchanged.
|
|
274
344
|
var tokenEncoder = diffType === 'smart' && (0, _fg.fg)('platform_editor_ai_smart_diff') ? _attrAwareTokenEncoder.attrAwareTokenEncoder : undefined;
|
|
275
|
-
var
|
|
276
|
-
var
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
345
|
+
var changes;
|
|
346
|
+
var attributedChanges = [];
|
|
347
|
+
var attributionColors;
|
|
348
|
+
if (attributionColoringEnabled) {
|
|
349
|
+
var changeset = _prosemirrorChangeset.ChangeSet.create(originalDoc, function (left, right) {
|
|
350
|
+
return (0, _attributions.getAttributionKey)(left) === (0, _attributions.getAttributionKey)(right) ? left.stepIndex > right.stepIndex ? left : right :
|
|
351
|
+
// `prosemirror-changeset` uses null as its incompatible-data sentinel even
|
|
352
|
+
// though its public combine callback is typed as returning Data.
|
|
353
|
+
null;
|
|
354
|
+
}, tokenEncoder).addSteps(steppedDoc, stepMaps, simplifiedStepAttributions.map(function (attribution, stepIndex) {
|
|
355
|
+
return _objectSpread(_objectSpread({}, attribution), {}, {
|
|
356
|
+
stepIndex: stepIndex
|
|
357
|
+
});
|
|
358
|
+
}));
|
|
359
|
+
attributedChanges = (0, _diffBySteps.diffBySteps)(originalDoc, simplifiedSteps, simplifiedStepAttributions);
|
|
360
|
+
changes = getAttributedChanges({
|
|
361
|
+
changeset: changeset,
|
|
362
|
+
originalDoc: originalDoc,
|
|
363
|
+
steppedDoc: steppedDoc,
|
|
364
|
+
diffType: diffType,
|
|
365
|
+
tr: tr,
|
|
366
|
+
attributedChanges: attributedChanges,
|
|
367
|
+
intl: intl,
|
|
368
|
+
smartThresholds: smartThresholds
|
|
369
|
+
});
|
|
370
|
+
attributionColors = (0, _attributions.createAttributionColorMap)(simplifiedStepAttributions);
|
|
371
|
+
} else {
|
|
372
|
+
var _changeset = _prosemirrorChangeset.ChangeSet.create(originalDoc, undefined, tokenEncoder).addSteps(steppedDoc, stepMaps, tr.doc);
|
|
373
|
+
changes = getChanges({
|
|
374
|
+
changeset: _changeset,
|
|
375
|
+
originalDoc: originalDoc,
|
|
376
|
+
steppedDoc: steppedDoc,
|
|
377
|
+
diffType: diffType,
|
|
378
|
+
tr: tr,
|
|
379
|
+
steps: simplifiedSteps,
|
|
380
|
+
intl: intl,
|
|
381
|
+
smartThresholds: smartThresholds
|
|
382
|
+
});
|
|
383
|
+
}
|
|
286
384
|
var decorations = [];
|
|
287
385
|
|
|
288
386
|
/**
|
|
@@ -295,6 +393,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
|
|
|
295
393
|
// Our default operations are insertions, so it should match the opposite of isInverted.
|
|
296
394
|
var isInserted = !isInverted;
|
|
297
395
|
var createDecorationsForChange = function createDecorationsForChange(change) {
|
|
396
|
+
var changeColorScheme = attributionColors ? (0, _attributions.getColorSchemeForChange)(change, attributedChanges, attributionColors, colorScheme) : colorScheme;
|
|
298
397
|
var isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
|
|
299
398
|
|
|
300
399
|
// Hoisted because it decides BOTH where the deleted widget is anchored and — since the
|
|
@@ -328,10 +427,11 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
|
|
|
328
427
|
// inward — when the widget is present the anchor must stay at the block
|
|
329
428
|
// boundary to keep the indicator bar continuous with the deleted content.
|
|
330
429
|
var willRenderDeletedWidget = change.deleted.length > 0 && !((0, _isExtendedEnabled.isExtendedEnabled)(diffType) && !isInverted && hideDeletedDiffs && change.inserted.length > 0);
|
|
331
|
-
if (
|
|
332
|
-
//
|
|
333
|
-
// provide the highlight without the
|
|
334
|
-
|
|
430
|
+
if (isSmartNodeLevel) {
|
|
431
|
+
// For a large inserted table, skip the O(cells) inline decorations inside the
|
|
432
|
+
// table (the cell overlays added below provide the highlight without the
|
|
433
|
+
// expensive content re-render); leaf blocks outside the table still get theirs.
|
|
434
|
+
var coarseTables = useCoarseTableDecoration ? tableRanges(tr.doc, change.fromB, change.toB) : [];
|
|
335
435
|
var _iterator2 = _createForOfIteratorHelper(leafTextblockRanges(tr.doc, change.fromB, change.toB)),
|
|
336
436
|
_step2;
|
|
337
437
|
try {
|
|
@@ -339,13 +439,16 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
|
|
|
339
439
|
var _step2$value = (0, _slicedToArray2.default)(_step2.value, 2),
|
|
340
440
|
from = _step2$value[0],
|
|
341
441
|
to = _step2$value[1];
|
|
442
|
+
if (useCoarseTableDecoration && isInsideTable(coarseTables, from)) {
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
342
445
|
decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createInlineChangedDecoration.createInlineChangedDecoration)(_objectSpread({
|
|
343
446
|
change: {
|
|
344
447
|
fromB: from,
|
|
345
448
|
toB: to
|
|
346
449
|
},
|
|
347
450
|
doc: tr.doc,
|
|
348
|
-
colorScheme:
|
|
451
|
+
colorScheme: changeColorScheme,
|
|
349
452
|
isActive: isActive,
|
|
350
453
|
diffType: diffType
|
|
351
454
|
}, (0, _isExtendedEnabled.isExtendedEnabled)(diffType) && {
|
|
@@ -366,7 +469,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
|
|
|
366
469
|
decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createInlineChangedDecoration.createInlineChangedDecoration)(_objectSpread({
|
|
367
470
|
change: change,
|
|
368
471
|
doc: tr.doc,
|
|
369
|
-
colorScheme:
|
|
472
|
+
colorScheme: changeColorScheme,
|
|
370
473
|
isActive: isActive,
|
|
371
474
|
diffType: diffType
|
|
372
475
|
}, (0, _isExtendedEnabled.isExtendedEnabled)(diffType) && {
|
|
@@ -382,7 +485,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
|
|
|
382
485
|
doc: tr.doc,
|
|
383
486
|
from: change.fromB,
|
|
384
487
|
to: change.toB,
|
|
385
|
-
colorScheme:
|
|
488
|
+
colorScheme: changeColorScheme
|
|
386
489
|
}, (0, _isExtendedEnabled.isExtendedEnabled)(diffType) && {
|
|
387
490
|
isInserted: isInserted,
|
|
388
491
|
shouldHideDeleted: shouldHideDeleted,
|
|
@@ -401,7 +504,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
|
|
|
401
504
|
change: change,
|
|
402
505
|
doc: originalDoc,
|
|
403
506
|
nodeViewSerializer: nodeViewSerializer,
|
|
404
|
-
colorScheme:
|
|
507
|
+
colorScheme: changeColorScheme,
|
|
405
508
|
newDoc: tr.doc,
|
|
406
509
|
intl: intl,
|
|
407
510
|
activeIndexPos: activeIndexPos
|
|
@@ -518,42 +621,42 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
|
|
|
518
621
|
};
|
|
519
622
|
var calculateDiffDecorations = exports.calculateDiffDecorations = (0, _memoizeOne.default)(calculateDiffDecorationsInner,
|
|
520
623
|
// Cache results unless relevant inputs change
|
|
521
|
-
function (
|
|
522
|
-
var
|
|
523
|
-
var
|
|
524
|
-
|
|
525
|
-
pluginState =
|
|
526
|
-
state =
|
|
527
|
-
colorScheme =
|
|
528
|
-
intl =
|
|
529
|
-
activeIndexPos =
|
|
530
|
-
isInverted =
|
|
531
|
-
diffType =
|
|
532
|
-
hideDeletedDiffs =
|
|
533
|
-
hideAddedDiffsUnderline =
|
|
534
|
-
showIndicators =
|
|
535
|
-
smartThresholds =
|
|
536
|
-
deletedDiffPlacement =
|
|
537
|
-
inlineDeletedDiffPlacement =
|
|
538
|
-
var
|
|
539
|
-
|
|
540
|
-
lastPluginState =
|
|
541
|
-
lastState =
|
|
542
|
-
lastColorScheme =
|
|
543
|
-
lastIntl =
|
|
544
|
-
lastActiveIndexPos =
|
|
545
|
-
lastIsInverted =
|
|
546
|
-
lastDiffType =
|
|
547
|
-
lastHideDeletedDiffs =
|
|
548
|
-
lastHideAddedDiffsUnderline =
|
|
549
|
-
lastShowIndicators =
|
|
550
|
-
lastSmartThresholds =
|
|
551
|
-
lastDeletedDiffPlacement =
|
|
552
|
-
lastInlineDeletedDiffPlacement =
|
|
624
|
+
function (_ref0, _ref1) {
|
|
625
|
+
var _ref13;
|
|
626
|
+
var _ref10 = (0, _slicedToArray2.default)(_ref0, 1),
|
|
627
|
+
_ref10$ = _ref10[0],
|
|
628
|
+
pluginState = _ref10$.pluginState,
|
|
629
|
+
state = _ref10$.state,
|
|
630
|
+
colorScheme = _ref10$.colorScheme,
|
|
631
|
+
intl = _ref10$.intl,
|
|
632
|
+
activeIndexPos = _ref10$.activeIndexPos,
|
|
633
|
+
isInverted = _ref10$.isInverted,
|
|
634
|
+
diffType = _ref10$.diffType,
|
|
635
|
+
hideDeletedDiffs = _ref10$.hideDeletedDiffs,
|
|
636
|
+
hideAddedDiffsUnderline = _ref10$.hideAddedDiffsUnderline,
|
|
637
|
+
showIndicators = _ref10$.showIndicators,
|
|
638
|
+
smartThresholds = _ref10$.smartThresholds,
|
|
639
|
+
deletedDiffPlacement = _ref10$.deletedDiffPlacement,
|
|
640
|
+
inlineDeletedDiffPlacement = _ref10$.inlineDeletedDiffPlacement;
|
|
641
|
+
var _ref11 = (0, _slicedToArray2.default)(_ref1, 1),
|
|
642
|
+
_ref11$ = _ref11[0],
|
|
643
|
+
lastPluginState = _ref11$.pluginState,
|
|
644
|
+
lastState = _ref11$.state,
|
|
645
|
+
lastColorScheme = _ref11$.colorScheme,
|
|
646
|
+
lastIntl = _ref11$.intl,
|
|
647
|
+
lastActiveIndexPos = _ref11$.activeIndexPos,
|
|
648
|
+
lastIsInverted = _ref11$.isInverted,
|
|
649
|
+
lastDiffType = _ref11$.diffType,
|
|
650
|
+
lastHideDeletedDiffs = _ref11$.hideDeletedDiffs,
|
|
651
|
+
lastHideAddedDiffsUnderline = _ref11$.hideAddedDiffsUnderline,
|
|
652
|
+
lastShowIndicators = _ref11$.showIndicators,
|
|
653
|
+
lastSmartThresholds = _ref11$.smartThresholds,
|
|
654
|
+
lastDeletedDiffPlacement = _ref11$.deletedDiffPlacement,
|
|
655
|
+
lastInlineDeletedDiffPlacement = _ref11$.inlineDeletedDiffPlacement;
|
|
553
656
|
var originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
|
|
554
657
|
if ((0, _isExtendedEnabled.isExtendedEnabled)(diffType)) {
|
|
555
|
-
var
|
|
556
|
-
return (
|
|
658
|
+
var _ref12;
|
|
659
|
+
return (_ref12 = colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isInverted === lastIsInverted && diffType === lastDiffType && (0, _isEqual.default)(activeIndexPos, lastActiveIndexPos) && originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && (0, _isEqual.default)(pluginState.stepAttributions, lastPluginState.stepAttributions) && state.doc.eq(lastState.doc) && hideDeletedDiffs === lastHideDeletedDiffs && hideAddedDiffsUnderline === lastHideAddedDiffsUnderline && showIndicators === lastShowIndicators && (0, _isEqual.default)(smartThresholds, lastSmartThresholds) && deletedDiffPlacement === lastDeletedDiffPlacement && inlineDeletedDiffPlacement === lastInlineDeletedDiffPlacement) !== null && _ref12 !== void 0 ? _ref12 : false;
|
|
557
660
|
}
|
|
558
|
-
return (
|
|
661
|
+
return (_ref13 = originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && (0, _isEqual.default)(pluginState.stepAttributions, lastPluginState.stepAttributions) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && (0, _isEqual.default)(activeIndexPos, lastActiveIndexPos) && hideDeletedDiffs === lastHideDeletedDiffs) !== null && _ref13 !== void 0 ? _ref13 : false;
|
|
559
662
|
});
|
|
@@ -5,11 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.diffBySteps = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
8
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
11
|
var _prosemirrorChangeset = require("prosemirror-changeset");
|
|
11
12
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
12
13
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
14
|
+
var _attributions = require("../decorations/colorSchemes/attributions");
|
|
13
15
|
var _attrAwareTokenEncoder = require("./attrAwareTokenEncoder");
|
|
14
16
|
var _optimizeChanges = require("./optimizeChanges");
|
|
15
17
|
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; }
|
|
@@ -205,9 +207,10 @@ var createMapping = function createMapping(maps) {
|
|
|
205
207
|
return mapping;
|
|
206
208
|
};
|
|
207
209
|
var createSpans = function createSpans(length) {
|
|
210
|
+
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
208
211
|
return length > 0 ? [{
|
|
209
212
|
length: length,
|
|
210
|
-
data:
|
|
213
|
+
data: data
|
|
211
214
|
}] : [];
|
|
212
215
|
};
|
|
213
216
|
var mergeOverlappingByNewDocRange = function mergeOverlappingByNewDocRange(changes) {
|
|
@@ -220,8 +223,11 @@ var mergeOverlappingByNewDocRange = function mergeOverlappingByNewDocRange(chang
|
|
|
220
223
|
var merged = [];
|
|
221
224
|
var current = _objectSpread({}, sortedChanges[0]);
|
|
222
225
|
for (var i = 1; i < sortedChanges.length; i++) {
|
|
226
|
+
var _, _2;
|
|
223
227
|
var next = sortedChanges[i];
|
|
224
|
-
var
|
|
228
|
+
var currentIdentity = (0, _attributions.getAttributionKey)((_ = [].concat((0, _toConsumableArray2.default)(current.deleted), (0, _toConsumableArray2.default)(current.inserted))[0]) === null || _ === void 0 ? void 0 : _.data);
|
|
229
|
+
var nextIdentity = (0, _attributions.getAttributionKey)((_2 = [].concat((0, _toConsumableArray2.default)(next.deleted), (0, _toConsumableArray2.default)(next.inserted))[0]) === null || _2 === void 0 ? void 0 : _2.data);
|
|
230
|
+
var isOverlapping = next.fromB <= current.toB && currentIdentity === nextIdentity;
|
|
225
231
|
if (isOverlapping) {
|
|
226
232
|
current = {
|
|
227
233
|
fromA: Math.min(current.fromA, next.fromA),
|
|
@@ -275,16 +281,18 @@ var shouldCheckGranularDiff = function shouldCheckGranularDiff(step, before, fro
|
|
|
275
281
|
var isTextContentEqual = (replacedNode === null || replacedNode === void 0 ? void 0 : replacedNode.textContent) === (replacingNode === null || replacingNode === void 0 ? void 0 : replacingNode.textContent);
|
|
276
282
|
return !isTextContentEqual || isTextContentEqual && hasSameChildMarks(replacedNode, replacingNode);
|
|
277
283
|
};
|
|
278
|
-
var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps) {
|
|
284
|
+
var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps, stepAttributions) {
|
|
279
285
|
var changes = [];
|
|
280
286
|
var currentDoc = originalDoc;
|
|
281
287
|
var successfulStepMaps = [];
|
|
282
288
|
var rangedSteps = [];
|
|
283
|
-
var _iterator2 = _createForOfIteratorHelper(steps),
|
|
289
|
+
var _iterator2 = _createForOfIteratorHelper(steps.entries()),
|
|
284
290
|
_step2;
|
|
285
291
|
try {
|
|
286
292
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
287
|
-
var
|
|
293
|
+
var _step2$value = (0, _slicedToArray2.default)(_step2.value, 2),
|
|
294
|
+
stepIndex = _step2$value[0],
|
|
295
|
+
step = _step2$value[1];
|
|
288
296
|
var before = currentDoc;
|
|
289
297
|
var result = step.apply(currentDoc);
|
|
290
298
|
if (result.failed !== null || !result.doc) {
|
|
@@ -299,6 +307,9 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
|
|
|
299
307
|
from: rangeStep.from,
|
|
300
308
|
to: rangeStep.to,
|
|
301
309
|
mapIndex: successfulStepMaps.length,
|
|
310
|
+
stepAttribution: stepAttributions !== null && stepAttributions !== void 0 && stepAttributions[stepIndex] ? _objectSpread(_objectSpread({}, stepAttributions[stepIndex]), {}, {
|
|
311
|
+
stepIndex: stepIndex
|
|
312
|
+
}) : null,
|
|
302
313
|
step: step,
|
|
303
314
|
stepMap: stepMap
|
|
304
315
|
});
|
|
@@ -384,8 +395,8 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
|
|
|
384
395
|
toA: granularToA,
|
|
385
396
|
fromB: granularFromB,
|
|
386
397
|
toB: granularToB,
|
|
387
|
-
deleted: createSpans(Math.max(0, granularToA - granularFromA)),
|
|
388
|
-
inserted: createSpans(Math.max(0, granularToB - granularFromB))
|
|
398
|
+
deleted: createSpans(Math.max(0, granularToA - granularFromA), rangedStep.stepAttribution),
|
|
399
|
+
inserted: createSpans(Math.max(0, granularToB - granularFromB), rangedStep.stepAttribution)
|
|
389
400
|
});
|
|
390
401
|
}
|
|
391
402
|
} catch (err) {
|
|
@@ -400,8 +411,8 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
|
|
|
400
411
|
toA: toA,
|
|
401
412
|
fromB: fromB,
|
|
402
413
|
toB: toB,
|
|
403
|
-
deleted: createSpans(Math.max(0, toA - fromA)),
|
|
404
|
-
inserted: createSpans(Math.max(0, toB - fromB))
|
|
414
|
+
deleted: createSpans(Math.max(0, toA - fromA), rangedStep.stepAttribution),
|
|
415
|
+
inserted: createSpans(Math.max(0, toB - fromB), rangedStep.stepAttribution)
|
|
405
416
|
});
|
|
406
417
|
}
|
|
407
418
|
return mergeOverlappingByNewDocRange(changes);
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.simplifyChangesWithAttribution = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
+
var _prosemirrorChangeset = require("prosemirror-changeset");
|
|
11
|
+
var _attributions = require("../decorations/colorSchemes/attributions");
|
|
12
|
+
var _optimizeChanges = require("./optimizeChanges");
|
|
13
|
+
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; } } }; }
|
|
14
|
+
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; } }
|
|
15
|
+
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; }
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
|
+
var getAttributionIdentity = function getAttributionIdentity(change) {
|
|
19
|
+
var identities = new Set();
|
|
20
|
+
for (var _i = 0, _arr = [].concat((0, _toConsumableArray2.default)(change.deleted), (0, _toConsumableArray2.default)(change.inserted)); _i < _arr.length; _i++) {
|
|
21
|
+
var span = _arr[_i];
|
|
22
|
+
identities.add((0, _attributions.getAttributionKey)(span.data));
|
|
23
|
+
}
|
|
24
|
+
if (identities.size > 1) {
|
|
25
|
+
return {
|
|
26
|
+
key: undefined,
|
|
27
|
+
mergeable: false
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
key: identities.values().next().value,
|
|
32
|
+
mergeable: true
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Simplifies and optimizes consecutive changes without crossing an attribution boundary.
|
|
38
|
+
* A change which already contains more than one identity is deliberately kept isolated.
|
|
39
|
+
*/
|
|
40
|
+
var simplifyChangesWithAttribution = exports.simplifyChangesWithAttribution = function simplifyChangesWithAttribution(changes, doc) {
|
|
41
|
+
var result = [];
|
|
42
|
+
var run = [];
|
|
43
|
+
var runIdentity;
|
|
44
|
+
var flush = function flush() {
|
|
45
|
+
if (run.length > 0) {
|
|
46
|
+
// Some show-diff producers use structurally compatible Change objects rather than the
|
|
47
|
+
// library class. `simplifyChanges` reads runtime `lenA`/`lenB` getters even though they
|
|
48
|
+
// are intentionally omitted from its public declarations, so add equivalent getters
|
|
49
|
+
// without calling the library's internal constructor.
|
|
50
|
+
var normalizedRun = run.map(function (change) {
|
|
51
|
+
return _objectSpread(_objectSpread({}, change), {}, {
|
|
52
|
+
get lenA() {
|
|
53
|
+
return change.toA - change.fromA;
|
|
54
|
+
},
|
|
55
|
+
get lenB() {
|
|
56
|
+
return change.toB - change.fromB;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
result.push.apply(result, (0, _toConsumableArray2.default)((0, _optimizeChanges.optimizeChanges)((0, _prosemirrorChangeset.simplifyChanges)(normalizedRun, doc))));
|
|
61
|
+
}
|
|
62
|
+
run = [];
|
|
63
|
+
runIdentity = undefined;
|
|
64
|
+
};
|
|
65
|
+
var _iterator = _createForOfIteratorHelper(changes),
|
|
66
|
+
_step;
|
|
67
|
+
try {
|
|
68
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
69
|
+
var _runIdentity;
|
|
70
|
+
var change = _step.value;
|
|
71
|
+
var identity = getAttributionIdentity(change);
|
|
72
|
+
var canJoinRun = ((_runIdentity = runIdentity) === null || _runIdentity === void 0 ? void 0 : _runIdentity.mergeable) === true && identity.mergeable && runIdentity.key === identity.key;
|
|
73
|
+
if (run.length > 0 && !canJoinRun) {
|
|
74
|
+
flush();
|
|
75
|
+
}
|
|
76
|
+
run.push(change);
|
|
77
|
+
runIdentity = identity;
|
|
78
|
+
if (!identity.mergeable) {
|
|
79
|
+
flush();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} catch (err) {
|
|
83
|
+
_iterator.e(err);
|
|
84
|
+
} finally {
|
|
85
|
+
_iterator.f();
|
|
86
|
+
}
|
|
87
|
+
flush();
|
|
88
|
+
return result;
|
|
89
|
+
};
|