@atlaskit/editor-plugin-show-diff 14.0.4 → 14.1.1
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 +18 -0
- package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +215 -103
- 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/getAttrChangeRanges.js +59 -30
- 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 +130 -22
- 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/getAttrChangeRanges.js +55 -30
- 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 +216 -104
- 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/getAttrChangeRanges.js +59 -30
- 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/getAttrChangeRanges.d.ts +12 -2
- 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 +10 -7
|
@@ -1,16 +1,19 @@
|
|
|
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.resolveRemovedLozengeStyle = exports.resolveNestedInsertedNodeStyle = exports.resolveDeletedNodeCSSVariables = exports.resolveCellOverlayStyle = exports.isTextLikeBlockNode = exports.isMultiContainerBlockNode = exports.hasRestingDeletedRing = exports.getInsertedContentStyle = exports.getDeletedContentStyleUnbounded = exports.getDeletedContentStyle = exports.getChangedNodeStyle = exports.getChangedContentStyle = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
7
9
|
var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
|
|
8
10
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
9
11
|
var _isExtendedEnabled = require("../../isExtendedEnabled");
|
|
10
12
|
var _factory = require("../colorSchemes/factory");
|
|
11
13
|
var _schemes = require("../colorSchemes/schemes");
|
|
12
14
|
var _wrapBlockNodeViewStyles = require("./wrapBlockNodeViewStyles.legacy");
|
|
13
|
-
|
|
15
|
+
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; }
|
|
16
|
+
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; } /**
|
|
14
17
|
* Style resolution for the `wrapBlockNodeView` nodeview decorations.
|
|
15
18
|
*
|
|
16
19
|
* Every exported resolver is a single gate: the `colorSchemeRegistry` + `factory.ts`
|
|
@@ -22,7 +25,6 @@ var _wrapBlockNodeViewStyles = require("./wrapBlockNodeViewStyles.legacy");
|
|
|
22
25
|
* On cleanup (EDITOR-8281): drop the `isExperimentEnabled` dispatch and the `*Legacy` imports,
|
|
23
26
|
* keeping the `*Next` bodies.
|
|
24
27
|
*/
|
|
25
|
-
|
|
26
28
|
var DEFAULT_COLOR_SCHEME = 'standard';
|
|
27
29
|
var getColorScheme = function getColorScheme(colorScheme) {
|
|
28
30
|
return _schemes.colorSchemeRegistry[colorScheme !== null && colorScheme !== void 0 ? colorScheme : DEFAULT_COLOR_SCHEME];
|
|
@@ -142,7 +144,7 @@ var getChangedContentStyle = exports.getChangedContentStyle = function getChange
|
|
|
142
144
|
var isInserted = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
143
145
|
var diffType = arguments.length > 3 ? arguments[3] : undefined;
|
|
144
146
|
var hideAddedDiffsUnderline = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
145
|
-
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getChangedContentStyleNext(colorScheme, isActive, isInserted, diffType, hideAddedDiffsUnderline) : (0, _wrapBlockNodeViewStyles.getChangedContentStyleLegacy)(colorScheme, isActive, isInserted, diffType, hideAddedDiffsUnderline);
|
|
147
|
+
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getChangedContentStyleNext(colorScheme, isActive, isInserted, diffType, hideAddedDiffsUnderline) : (0, _wrapBlockNodeViewStyles.getChangedContentStyleLegacy)((0, _schemes.getLegacyColorScheme)(colorScheme), isActive, isInserted, diffType, hideAddedDiffsUnderline);
|
|
146
148
|
};
|
|
147
149
|
|
|
148
150
|
/** Node-specific style for a changed block node, or `undefined` when the node type has none. */
|
|
@@ -151,27 +153,27 @@ var getChangedNodeStyle = exports.getChangedNodeStyle = function getChangedNodeS
|
|
|
151
153
|
var isActive = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
152
154
|
var diffType = arguments.length > 4 ? arguments[4] : undefined;
|
|
153
155
|
var hideAddedDiffsUnderline = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
154
|
-
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getChangedNodeStyleNext(nodeName, colorScheme, isInserted, isActive, diffType, hideAddedDiffsUnderline) : (0, _wrapBlockNodeViewStyles.getChangedNodeStyleLegacy)(nodeName, colorScheme, isInserted, isActive, diffType, hideAddedDiffsUnderline);
|
|
156
|
+
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getChangedNodeStyleNext(nodeName, colorScheme, isInserted, isActive, diffType, hideAddedDiffsUnderline) : (0, _wrapBlockNodeViewStyles.getChangedNodeStyleLegacy)(nodeName, (0, _schemes.getLegacyColorScheme)(colorScheme), isInserted, isActive, diffType, hideAddedDiffsUnderline);
|
|
155
157
|
};
|
|
156
158
|
|
|
157
159
|
/** The positioned line drawn across deleted content spanning an unbounded range. */
|
|
158
160
|
var getDeletedContentStyleUnbounded = exports.getDeletedContentStyleUnbounded = function getDeletedContentStyleUnbounded(colorScheme) {
|
|
159
161
|
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
160
|
-
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getDeletedContentStyleUnboundedNext(colorScheme, isActive) : (0, _wrapBlockNodeViewStyles.getDeletedContentStyleUnboundedLegacy)(colorScheme, isActive);
|
|
162
|
+
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getDeletedContentStyleUnboundedNext(colorScheme, isActive) : (0, _wrapBlockNodeViewStyles.getDeletedContentStyleUnboundedLegacy)((0, _schemes.getLegacyColorScheme)(colorScheme), isActive);
|
|
161
163
|
};
|
|
162
164
|
|
|
163
165
|
/** Inline style for inserted content. */
|
|
164
166
|
var getInsertedContentStyle = exports.getInsertedContentStyle = function getInsertedContentStyle(colorScheme) {
|
|
165
167
|
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
166
168
|
var hideAddedDiffsUnderline = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
167
|
-
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getInsertedContentStyleNext(colorScheme, isActive, hideAddedDiffsUnderline) : (0, _wrapBlockNodeViewStyles.getInsertedContentStyleLegacy)(colorScheme, isActive, hideAddedDiffsUnderline);
|
|
169
|
+
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getInsertedContentStyleNext(colorScheme, isActive, hideAddedDiffsUnderline) : (0, _wrapBlockNodeViewStyles.getInsertedContentStyleLegacy)((0, _schemes.getLegacyColorScheme)(colorScheme), isActive, hideAddedDiffsUnderline);
|
|
168
170
|
};
|
|
169
171
|
|
|
170
172
|
/** Inline style for deleted content. */
|
|
171
173
|
var getDeletedContentStyle = exports.getDeletedContentStyle = function getDeletedContentStyle(colorScheme) {
|
|
172
174
|
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
173
175
|
var diffType = arguments.length > 2 ? arguments[2] : undefined;
|
|
174
|
-
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getDeletedContentStyleNext(colorScheme, isActive, diffType) : (0, _wrapBlockNodeViewStyles.getDeletedContentStyleLegacy)(colorScheme, isActive, diffType);
|
|
176
|
+
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getDeletedContentStyleNext(colorScheme, isActive, diffType) : (0, _wrapBlockNodeViewStyles.getDeletedContentStyleLegacy)((0, _schemes.getLegacyColorScheme)(colorScheme), isActive, diffType);
|
|
175
177
|
};
|
|
176
178
|
|
|
177
179
|
/**
|
|
@@ -179,12 +181,14 @@ var getDeletedContentStyle = exports.getDeletedContentStyle = function getDelete
|
|
|
179
181
|
* `querySelectorAll('td, th')` loop in `wrapBlockNodeView.ts` resolves it once.
|
|
180
182
|
*/
|
|
181
183
|
var resolveCellOverlayStyle = exports.resolveCellOverlayStyle = function resolveCellOverlayStyle(args) {
|
|
182
|
-
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? resolveCellOverlayStyleNext(args) : (0, _wrapBlockNodeViewStyles.resolveCellOverlayStyleLegacy)(args)
|
|
184
|
+
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? resolveCellOverlayStyleNext(args) : (0, _wrapBlockNodeViewStyles.resolveCellOverlayStyleLegacy)(_objectSpread(_objectSpread({}, args), {}, {
|
|
185
|
+
colorScheme: (0, _schemes.getLegacyColorScheme)(args.colorScheme)
|
|
186
|
+
}));
|
|
183
187
|
};
|
|
184
188
|
|
|
185
189
|
/** Inner style for the "Removed" lozenge on a deleted block node. */
|
|
186
190
|
var resolveRemovedLozengeStyle = exports.resolveRemovedLozengeStyle = function resolveRemovedLozengeStyle(colorScheme, isActive) {
|
|
187
|
-
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? resolveRemovedLozengeStyleNext(colorScheme, isActive) : (0, _wrapBlockNodeViewStyles.resolveRemovedLozengeStyleLegacy)(colorScheme, isActive);
|
|
191
|
+
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? resolveRemovedLozengeStyleNext(colorScheme, isActive) : (0, _wrapBlockNodeViewStyles.resolveRemovedLozengeStyleLegacy)((0, _schemes.getLegacyColorScheme)(colorScheme), isActive);
|
|
188
192
|
};
|
|
189
193
|
|
|
190
194
|
/**
|
|
@@ -201,7 +205,7 @@ var resolveNestedInsertedNodeStyle = exports.resolveNestedInsertedNodeStyle = fu
|
|
|
201
205
|
* is what the `show-diff-deleted-outline-new` class styles in editor-core's smartCardStyles.
|
|
202
206
|
*/
|
|
203
207
|
var hasRestingDeletedRing = exports.hasRestingDeletedRing = function hasRestingDeletedRing(colorScheme) {
|
|
204
|
-
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? hasRestingDeletedRingNext(colorScheme) : (0, _wrapBlockNodeViewStyles.hasRestingDeletedRingLegacy)(colorScheme);
|
|
208
|
+
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? hasRestingDeletedRingNext(colorScheme) : (0, _wrapBlockNodeViewStyles.hasRestingDeletedRingLegacy)((0, _schemes.getLegacyColorScheme)(colorScheme));
|
|
205
209
|
};
|
|
206
210
|
|
|
207
211
|
/**
|
|
@@ -37,6 +37,7 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
|
|
|
37
37
|
var defaultDiffType = (0, _isExtendedEnabled.getDefaultDiffType)();
|
|
38
38
|
return _objectSpread({
|
|
39
39
|
steps: [],
|
|
40
|
+
stepAttributions: [],
|
|
40
41
|
originalDoc: undefined,
|
|
41
42
|
decorations: _view.DecorationSet.empty,
|
|
42
43
|
isDisplayingChanges: false
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.showDiffPlugin = void 0;
|
|
8
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
8
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
10
|
var _react = _interopRequireDefault(require("react"));
|
|
10
11
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
@@ -12,11 +13,31 @@ var _getDeletedWidgets2 = require("./pm-plugins/getDeletedWidgets");
|
|
|
12
13
|
var _getScrollableDecorations = require("./pm-plugins/getScrollableDecorations");
|
|
13
14
|
var _main = require("./pm-plugins/main");
|
|
14
15
|
var _IndicatorBarContentComponent = require("./ui/IndicatorBar/IndicatorBarContentComponent");
|
|
16
|
+
var _excluded = ["stepsWithAttribution"];
|
|
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; }
|
|
16
18
|
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; }
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
var normalizeShowDiffParams = function normalizeShowDiffParams(params) {
|
|
20
|
+
if (!params || !('stepsWithAttribution' in params)) {
|
|
21
|
+
return params ? _objectSpread(_objectSpread({}, params), {}, {
|
|
22
|
+
stepAttributions: []
|
|
23
|
+
}) : params;
|
|
24
|
+
}
|
|
25
|
+
var stepsWithAttribution = params.stepsWithAttribution,
|
|
26
|
+
rest = (0, _objectWithoutProperties2.default)(params, _excluded);
|
|
27
|
+
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
28
|
+
steps: stepsWithAttribution.map(function (_ref) {
|
|
29
|
+
var step = _ref.step;
|
|
30
|
+
return step;
|
|
31
|
+
}),
|
|
32
|
+
stepAttributions: stepsWithAttribution.map(function (_ref2) {
|
|
33
|
+
var stepAttribution = _ref2.stepAttribution;
|
|
34
|
+
return stepAttribution;
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var showDiffPlugin = exports.showDiffPlugin = function showDiffPlugin(_ref3) {
|
|
39
|
+
var api = _ref3.api,
|
|
40
|
+
config = _ref3.config;
|
|
20
41
|
// Captured from the plugin's view lifecycle (see `createPlugin`) so read-only actions can access
|
|
21
42
|
// the current state without exposing the plugin key to consumers.
|
|
22
43
|
var editorView;
|
|
@@ -32,21 +53,21 @@ var showDiffPlugin = exports.showDiffPlugin = function showDiffPlugin(_ref) {
|
|
|
32
53
|
},
|
|
33
54
|
commands: {
|
|
34
55
|
showDiff: function showDiff(params) {
|
|
35
|
-
return function (
|
|
36
|
-
var tr =
|
|
56
|
+
return function (_ref4) {
|
|
57
|
+
var tr = _ref4.tr;
|
|
37
58
|
if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
38
59
|
var _api$userIntent;
|
|
39
60
|
api === null || api === void 0 || (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 || _api$userIntent.commands.setCurrentUserIntent('viewingDiff')({
|
|
40
61
|
tr: tr
|
|
41
62
|
});
|
|
42
63
|
}
|
|
43
|
-
return tr.setMeta(_main.showDiffPluginKey, _objectSpread(_objectSpread({}, params), {}, {
|
|
64
|
+
return tr.setMeta(_main.showDiffPluginKey, _objectSpread(_objectSpread({}, normalizeShowDiffParams(params)), {}, {
|
|
44
65
|
action: 'SHOW_DIFF'
|
|
45
66
|
}));
|
|
46
67
|
};
|
|
47
68
|
},
|
|
48
|
-
hideDiff: function hideDiff(
|
|
49
|
-
var tr =
|
|
69
|
+
hideDiff: function hideDiff(_ref5) {
|
|
70
|
+
var tr = _ref5.tr;
|
|
50
71
|
if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
|
|
51
72
|
var _api$userIntent2;
|
|
52
73
|
api === null || api === void 0 || (_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 || _api$userIntent2.commands.setCurrentUserIntent('default')({
|
|
@@ -55,17 +76,18 @@ var showDiffPlugin = exports.showDiffPlugin = function showDiffPlugin(_ref) {
|
|
|
55
76
|
}
|
|
56
77
|
return tr.setMeta(_main.showDiffPluginKey, {
|
|
57
78
|
steps: [],
|
|
79
|
+
stepAttributions: [],
|
|
58
80
|
action: 'HIDE_DIFF'
|
|
59
81
|
});
|
|
60
82
|
},
|
|
61
|
-
scrollToNext: function scrollToNext(
|
|
62
|
-
var tr =
|
|
83
|
+
scrollToNext: function scrollToNext(_ref6) {
|
|
84
|
+
var tr = _ref6.tr;
|
|
63
85
|
return tr.setMeta(_main.showDiffPluginKey, {
|
|
64
86
|
action: 'SCROLL_TO_NEXT'
|
|
65
87
|
});
|
|
66
88
|
},
|
|
67
|
-
scrollToPrevious: function scrollToPrevious(
|
|
68
|
-
var tr =
|
|
89
|
+
scrollToPrevious: function scrollToPrevious(_ref7) {
|
|
90
|
+
var tr = _ref7.tr;
|
|
69
91
|
return tr.setMeta(_main.showDiffPluginKey, {
|
|
70
92
|
action: 'SCROLL_TO_PREVIOUS'
|
|
71
93
|
});
|
|
@@ -74,8 +96,8 @@ var showDiffPlugin = exports.showDiffPlugin = function showDiffPlugin(_ref) {
|
|
|
74
96
|
pmPlugins: function pmPlugins() {
|
|
75
97
|
return [{
|
|
76
98
|
name: 'showDiffPlugin',
|
|
77
|
-
plugin: function plugin(
|
|
78
|
-
var getIntl =
|
|
99
|
+
plugin: function plugin(_ref8) {
|
|
100
|
+
var getIntl = _ref8.getIntl;
|
|
79
101
|
return (0, _main.createPlugin)(config, getIntl, api, setEditorView);
|
|
80
102
|
}
|
|
81
103
|
}];
|
|
@@ -3,6 +3,7 @@ import memoizeOne from 'memoize-one';
|
|
|
3
3
|
import { ChangeSet, simplifyChanges } from 'prosemirror-changeset';
|
|
4
4
|
import { isExperimentEnabled } from '@atlaskit/editor-common/deprecated-platform-feature-experiments';
|
|
5
5
|
import { areNodesEqualIgnoreAttrs } from '@atlaskit/editor-common/utils/document';
|
|
6
|
+
import { Mapping } from '@atlaskit/editor-prosemirror/transform';
|
|
6
7
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
7
8
|
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
8
9
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
@@ -11,6 +12,7 @@ import { createDocMarginAnchorWidget } from '../decorations/createAnchorDecorati
|
|
|
11
12
|
import { createBlockChangedDecoration } from '../decorations/createBlockChangedDecoration';
|
|
12
13
|
import { createInlineChangedDecoration } from '../decorations/createInlineChangedDecoration';
|
|
13
14
|
import { createNodeChangedDecorationWidget } from '../decorations/createNodeChangedDecorationWidget';
|
|
15
|
+
import { createAttributionColorMap, getAttributionKey, getColorSchemeForChange, isAttributionColoringEnabled } from '../decorations/colorSchemes/attributions';
|
|
14
16
|
import { extractDiffDescriptors } from '../decorations/decorationKeys';
|
|
15
17
|
import { getAttrChangeRanges, stepIsValidAttrChange } from '../decorations/utils/getAttrChangeRanges';
|
|
16
18
|
import { getMarkChangeRanges } from '../decorations/utils/getMarkChangeRanges';
|
|
@@ -19,7 +21,8 @@ import { attrAwareTokenEncoder } from './attrAwareTokenEncoder';
|
|
|
19
21
|
import { diffBySteps } from './diffBySteps';
|
|
20
22
|
import { groupChangesByBlock } from './groupChangesByBlock';
|
|
21
23
|
import { optimizeChanges } from './optimizeChanges';
|
|
22
|
-
import {
|
|
24
|
+
import { simplifyChangesWithAttribution } from './simplifyChangesWithAttribution';
|
|
25
|
+
import { simplifySteps, simplifyStepsWithAttribution } from './simplifySteps';
|
|
23
26
|
import { classifySmartChanges } from './smart/classifySmartChanges';
|
|
24
27
|
import { smartChangeLevel } from './smart/helpers';
|
|
25
28
|
const getChanges = ({
|
|
@@ -58,6 +61,35 @@ const getChanges = ({
|
|
|
58
61
|
const changes = simplifyChanges(changeset.changes, tr.doc);
|
|
59
62
|
return optimizeChanges(changes);
|
|
60
63
|
};
|
|
64
|
+
const getAttributedChanges = ({
|
|
65
|
+
attributedChanges,
|
|
66
|
+
changeset,
|
|
67
|
+
originalDoc,
|
|
68
|
+
steppedDoc,
|
|
69
|
+
diffType,
|
|
70
|
+
tr,
|
|
71
|
+
intl,
|
|
72
|
+
smartThresholds
|
|
73
|
+
}) => {
|
|
74
|
+
if (isExtendedEnabled(diffType)) {
|
|
75
|
+
if (diffType === 'smart' && fg('platform_editor_ai_smart_diff')) {
|
|
76
|
+
return classifySmartChanges({
|
|
77
|
+
changes: simplifyChangesWithAttribution(attributedChanges, tr.doc),
|
|
78
|
+
originalDoc,
|
|
79
|
+
newDoc: tr.doc,
|
|
80
|
+
locale: intl.locale,
|
|
81
|
+
thresholds: smartThresholds
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (diffType === 'step') {
|
|
85
|
+
return attributedChanges;
|
|
86
|
+
}
|
|
87
|
+
if (diffType === 'block') {
|
|
88
|
+
return groupChangesByBlock(changeset.changes, originalDoc, steppedDoc);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return simplifyChangesWithAttribution(attributedChanges, tr.doc);
|
|
92
|
+
};
|
|
61
93
|
|
|
62
94
|
/**
|
|
63
95
|
* Collect the inline-content ranges of every leaf text-bearing block (paragraph, heading, …)
|
|
@@ -206,6 +238,7 @@ const calculateDiffDecorationsInner = ({
|
|
|
206
238
|
const {
|
|
207
239
|
originalDoc,
|
|
208
240
|
steps,
|
|
241
|
+
stepAttributions,
|
|
209
242
|
isDisplayingChanges
|
|
210
243
|
} = pluginState;
|
|
211
244
|
if (!originalDoc || !isDisplayingChanges) {
|
|
@@ -222,19 +255,68 @@ const calculateDiffDecorationsInner = ({
|
|
|
222
255
|
tr
|
|
223
256
|
} = state;
|
|
224
257
|
let steppedDoc = originalDoc;
|
|
225
|
-
const
|
|
226
|
-
|
|
258
|
+
const attributionColoringEnabled = isAttributionColoringEnabled(stepAttributions);
|
|
259
|
+
let simplifiedSteps;
|
|
260
|
+
let simplifiedStepAttributions = [];
|
|
261
|
+
if (attributionColoringEnabled) {
|
|
262
|
+
const simplifiedStepsWithAttribution = simplifyStepsWithAttribution(steps, stepAttributions !== null && stepAttributions !== void 0 ? stepAttributions : [], originalDoc);
|
|
263
|
+
simplifiedSteps = simplifiedStepsWithAttribution.map(({
|
|
264
|
+
step
|
|
265
|
+
}) => step);
|
|
266
|
+
simplifiedStepAttributions = simplifiedStepsWithAttribution.map(({
|
|
267
|
+
stepAttribution
|
|
268
|
+
}) => stepAttribution);
|
|
269
|
+
} else {
|
|
270
|
+
simplifiedSteps = simplifySteps(steps, originalDoc);
|
|
271
|
+
}
|
|
272
|
+
const pendingAttrSteps = [];
|
|
227
273
|
const stepMaps = [];
|
|
228
274
|
for (const step of simplifiedSteps) {
|
|
229
275
|
const result = step.apply(steppedDoc);
|
|
230
276
|
if (result.failed === null && result.doc) {
|
|
231
277
|
if (stepIsValidAttrChange(step, steppedDoc, result.doc)) {
|
|
232
|
-
|
|
278
|
+
pendingAttrSteps.push({
|
|
279
|
+
afterNode: result.doc.nodeAt(step.pos),
|
|
280
|
+
beforeNode: steppedDoc.nodeAt(step.pos),
|
|
281
|
+
mapIndex: stepMaps.length,
|
|
282
|
+
step
|
|
283
|
+
});
|
|
233
284
|
}
|
|
234
285
|
stepMaps.push(step.getMap());
|
|
235
286
|
steppedDoc = result.doc;
|
|
236
287
|
}
|
|
237
288
|
}
|
|
289
|
+
// Gate the complete attribution fix: mapped positions and step-time nodes are used together.
|
|
290
|
+
// The fallback deliberately preserves the legacy raw-position lookups for rollout safety.
|
|
291
|
+
const attrStepContexts = fg('platform_editor_reduce_diff_attr_sensitivity') ? pendingAttrSteps.flatMap(({
|
|
292
|
+
afterNode,
|
|
293
|
+
beforeNode,
|
|
294
|
+
mapIndex,
|
|
295
|
+
step
|
|
296
|
+
}) => {
|
|
297
|
+
const finalPosition = new Mapping(stepMaps.slice(mapIndex + 1)).mapResult(step.pos);
|
|
298
|
+
if (finalPosition.deleted) {
|
|
299
|
+
return [];
|
|
300
|
+
}
|
|
301
|
+
const originalPosition = new Mapping(stepMaps.slice(0, mapIndex)).invert().mapResult(step.pos);
|
|
302
|
+
return [{
|
|
303
|
+
afterNode,
|
|
304
|
+
beforeNode,
|
|
305
|
+
finalPos: finalPosition.pos,
|
|
306
|
+
...(originalPosition.deleted ? {} : {
|
|
307
|
+
originalPos: originalPosition.pos
|
|
308
|
+
}),
|
|
309
|
+
step
|
|
310
|
+
}];
|
|
311
|
+
}) : pendingAttrSteps.map(({
|
|
312
|
+
step
|
|
313
|
+
}) => ({
|
|
314
|
+
afterNode: tr.doc.nodeAt(step.pos),
|
|
315
|
+
beforeNode: originalDoc.nodeAt(step.pos),
|
|
316
|
+
finalPos: step.pos,
|
|
317
|
+
originalPos: step.pos,
|
|
318
|
+
step
|
|
319
|
+
}));
|
|
238
320
|
|
|
239
321
|
// Rather than using .eq() we use a custom function that only checks for structural
|
|
240
322
|
// changes and ignores differences in attributes which don't affect decoration positions
|
|
@@ -262,17 +344,42 @@ const calculateDiffDecorationsInner = ({
|
|
|
262
344
|
// gated with it; other diff types keep the library default so their output is
|
|
263
345
|
// unchanged.
|
|
264
346
|
const tokenEncoder = diffType === 'smart' && fg('platform_editor_ai_smart_diff') ? attrAwareTokenEncoder : undefined;
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
347
|
+
let changes;
|
|
348
|
+
let attributedChanges = [];
|
|
349
|
+
let attributionColors;
|
|
350
|
+
if (attributionColoringEnabled) {
|
|
351
|
+
const changeset = ChangeSet.create(originalDoc, (left, right) => getAttributionKey(left) === getAttributionKey(right) ? left.stepIndex > right.stepIndex ? left : right :
|
|
352
|
+
// `prosemirror-changeset` uses null as its incompatible-data sentinel even
|
|
353
|
+
// though its public combine callback is typed as returning Data.
|
|
354
|
+
null, tokenEncoder).addSteps(steppedDoc, stepMaps, simplifiedStepAttributions.map((attribution, stepIndex) => ({
|
|
355
|
+
...attribution,
|
|
356
|
+
stepIndex
|
|
357
|
+
})));
|
|
358
|
+
attributedChanges = diffBySteps(originalDoc, simplifiedSteps, simplifiedStepAttributions);
|
|
359
|
+
changes = getAttributedChanges({
|
|
360
|
+
changeset,
|
|
361
|
+
originalDoc,
|
|
362
|
+
steppedDoc,
|
|
363
|
+
diffType,
|
|
364
|
+
tr,
|
|
365
|
+
attributedChanges,
|
|
366
|
+
intl,
|
|
367
|
+
smartThresholds
|
|
368
|
+
});
|
|
369
|
+
attributionColors = createAttributionColorMap(simplifiedStepAttributions);
|
|
370
|
+
} else {
|
|
371
|
+
const changeset = ChangeSet.create(originalDoc, undefined, tokenEncoder).addSteps(steppedDoc, stepMaps, tr.doc);
|
|
372
|
+
changes = getChanges({
|
|
373
|
+
changeset,
|
|
374
|
+
originalDoc,
|
|
375
|
+
steppedDoc,
|
|
376
|
+
diffType,
|
|
377
|
+
tr,
|
|
378
|
+
steps: simplifiedSteps,
|
|
379
|
+
intl,
|
|
380
|
+
smartThresholds
|
|
381
|
+
});
|
|
382
|
+
}
|
|
276
383
|
const decorations = [];
|
|
277
384
|
|
|
278
385
|
/**
|
|
@@ -285,6 +392,7 @@ const calculateDiffDecorationsInner = ({
|
|
|
285
392
|
// Our default operations are insertions, so it should match the opposite of isInverted.
|
|
286
393
|
const isInserted = !isInverted;
|
|
287
394
|
const createDecorationsForChange = change => {
|
|
395
|
+
const changeColorScheme = attributionColors ? getColorSchemeForChange(change, attributedChanges, attributionColors, colorScheme) : colorScheme;
|
|
288
396
|
const isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
|
|
289
397
|
|
|
290
398
|
// Hoisted because it decides BOTH where the deleted widget is anchored and — since the
|
|
@@ -333,7 +441,7 @@ const calculateDiffDecorationsInner = ({
|
|
|
333
441
|
toB: to
|
|
334
442
|
},
|
|
335
443
|
doc: tr.doc,
|
|
336
|
-
colorScheme,
|
|
444
|
+
colorScheme: changeColorScheme,
|
|
337
445
|
isActive,
|
|
338
446
|
diffType,
|
|
339
447
|
...(isExtendedEnabled(diffType) && {
|
|
@@ -350,7 +458,7 @@ const calculateDiffDecorationsInner = ({
|
|
|
350
458
|
decorations.push(...createInlineChangedDecoration({
|
|
351
459
|
change,
|
|
352
460
|
doc: tr.doc,
|
|
353
|
-
colorScheme,
|
|
461
|
+
colorScheme: changeColorScheme,
|
|
354
462
|
isActive,
|
|
355
463
|
diffType,
|
|
356
464
|
...(isExtendedEnabled(diffType) && {
|
|
@@ -367,7 +475,7 @@ const calculateDiffDecorationsInner = ({
|
|
|
367
475
|
doc: tr.doc,
|
|
368
476
|
from: change.fromB,
|
|
369
477
|
to: change.toB,
|
|
370
|
-
colorScheme,
|
|
478
|
+
colorScheme: changeColorScheme,
|
|
371
479
|
...(isExtendedEnabled(diffType) && {
|
|
372
480
|
isInserted,
|
|
373
481
|
shouldHideDeleted,
|
|
@@ -386,7 +494,7 @@ const calculateDiffDecorationsInner = ({
|
|
|
386
494
|
change,
|
|
387
495
|
doc: originalDoc,
|
|
388
496
|
nodeViewSerializer,
|
|
389
|
-
colorScheme,
|
|
497
|
+
colorScheme: changeColorScheme,
|
|
390
498
|
newDoc: tr.doc,
|
|
391
499
|
intl,
|
|
392
500
|
activeIndexPos,
|
|
@@ -413,7 +521,7 @@ const calculateDiffDecorationsInner = ({
|
|
|
413
521
|
isInserted: true
|
|
414
522
|
}));
|
|
415
523
|
});
|
|
416
|
-
getAttrChangeRanges(tr.doc,
|
|
524
|
+
getAttrChangeRanges(tr.doc, attrStepContexts, originalDoc).forEach(change => {
|
|
417
525
|
if (change.isInline) {
|
|
418
526
|
// Inline nodes (e.g. date, emoji, mention, status) need an inline decoration rather than a block decoration
|
|
419
527
|
const isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
|
|
@@ -532,7 +640,7 @@ export const calculateDiffDecorations = memoizeOne(calculateDiffDecorationsInner
|
|
|
532
640
|
const originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
|
|
533
641
|
if (isExtendedEnabled(diffType)) {
|
|
534
642
|
var _ref;
|
|
535
|
-
return (_ref = colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isInverted === lastIsInverted && diffType === lastDiffType && isEqual(activeIndexPos, lastActiveIndexPos) && originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && hideDeletedDiffs === lastHideDeletedDiffs && hideAddedDiffsUnderline === lastHideAddedDiffsUnderline && showIndicators === lastShowIndicators && isEqual(smartThresholds, lastSmartThresholds) && deletedDiffPlacement === lastDeletedDiffPlacement && inlineDeletedDiffPlacement === lastInlineDeletedDiffPlacement) !== null && _ref !== void 0 ? _ref : false;
|
|
643
|
+
return (_ref = colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isInverted === lastIsInverted && diffType === lastDiffType && isEqual(activeIndexPos, lastActiveIndexPos) && originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && isEqual(pluginState.stepAttributions, lastPluginState.stepAttributions) && state.doc.eq(lastState.doc) && hideDeletedDiffs === lastHideDeletedDiffs && hideAddedDiffsUnderline === lastHideAddedDiffsUnderline && showIndicators === lastShowIndicators && isEqual(smartThresholds, lastSmartThresholds) && deletedDiffPlacement === lastDeletedDiffPlacement && inlineDeletedDiffPlacement === lastInlineDeletedDiffPlacement) !== null && _ref !== void 0 ? _ref : false;
|
|
536
644
|
}
|
|
537
|
-
return (_ref2 = originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isEqual(activeIndexPos, lastActiveIndexPos) && hideDeletedDiffs === lastHideDeletedDiffs) !== null && _ref2 !== void 0 ? _ref2 : false;
|
|
645
|
+
return (_ref2 = originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && isEqual(pluginState.stepAttributions, lastPluginState.stepAttributions) && state.doc.eq(lastState.doc) && colorScheme === lastColorScheme && intl.locale === lastIntl.locale && isEqual(activeIndexPos, lastActiveIndexPos) && hideDeletedDiffs === lastHideDeletedDiffs) !== null && _ref2 !== void 0 ? _ref2 : false;
|
|
538
646
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { simplifyChanges, ChangeSet } from 'prosemirror-changeset';
|
|
2
2
|
import { Mark } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import { Mapping, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
4
|
+
import { getAttributionKey } from '../decorations/colorSchemes/attributions';
|
|
4
5
|
import { attrAwareTokenEncoder } from './attrAwareTokenEncoder';
|
|
5
6
|
import { optimizeChanges } from './optimizeChanges';
|
|
6
7
|
const WORD_CHAR_REGEX = /[\p{L}\p{N}_]/u;
|
|
@@ -177,9 +178,9 @@ const createMapping = maps => {
|
|
|
177
178
|
}
|
|
178
179
|
return mapping;
|
|
179
180
|
};
|
|
180
|
-
const createSpans = length => length > 0 ? [{
|
|
181
|
+
const createSpans = (length, data = null) => length > 0 ? [{
|
|
181
182
|
length,
|
|
182
|
-
data
|
|
183
|
+
data
|
|
183
184
|
}] : [];
|
|
184
185
|
const mergeOverlappingByNewDocRange = changes => {
|
|
185
186
|
if (changes.length <= 1) {
|
|
@@ -191,8 +192,11 @@ const mergeOverlappingByNewDocRange = changes => {
|
|
|
191
192
|
...sortedChanges[0]
|
|
192
193
|
};
|
|
193
194
|
for (let i = 1; i < sortedChanges.length; i++) {
|
|
195
|
+
var _, _2;
|
|
194
196
|
const next = sortedChanges[i];
|
|
195
|
-
const
|
|
197
|
+
const currentIdentity = getAttributionKey((_ = [...current.deleted, ...current.inserted][0]) === null || _ === void 0 ? void 0 : _.data);
|
|
198
|
+
const nextIdentity = getAttributionKey((_2 = [...next.deleted, ...next.inserted][0]) === null || _2 === void 0 ? void 0 : _2.data);
|
|
199
|
+
const isOverlapping = next.fromB <= current.toB && currentIdentity === nextIdentity;
|
|
196
200
|
if (isOverlapping) {
|
|
197
201
|
current = {
|
|
198
202
|
fromA: Math.min(current.fromA, next.fromA),
|
|
@@ -248,12 +252,12 @@ const shouldCheckGranularDiff = (step, before, from, to) => {
|
|
|
248
252
|
const isTextContentEqual = (replacedNode === null || replacedNode === void 0 ? void 0 : replacedNode.textContent) === (replacingNode === null || replacingNode === void 0 ? void 0 : replacingNode.textContent);
|
|
249
253
|
return !isTextContentEqual || isTextContentEqual && hasSameChildMarks(replacedNode, replacingNode);
|
|
250
254
|
};
|
|
251
|
-
export const diffBySteps = (originalDoc, steps) => {
|
|
255
|
+
export const diffBySteps = (originalDoc, steps, stepAttributions) => {
|
|
252
256
|
const changes = [];
|
|
253
257
|
let currentDoc = originalDoc;
|
|
254
258
|
const successfulStepMaps = [];
|
|
255
259
|
const rangedSteps = [];
|
|
256
|
-
for (const step of steps) {
|
|
260
|
+
for (const [stepIndex, step] of steps.entries()) {
|
|
257
261
|
const before = currentDoc;
|
|
258
262
|
const result = step.apply(currentDoc);
|
|
259
263
|
if (result.failed !== null || !result.doc) {
|
|
@@ -268,6 +272,10 @@ export const diffBySteps = (originalDoc, steps) => {
|
|
|
268
272
|
from: rangeStep.from,
|
|
269
273
|
to: rangeStep.to,
|
|
270
274
|
mapIndex: successfulStepMaps.length,
|
|
275
|
+
stepAttribution: stepAttributions !== null && stepAttributions !== void 0 && stepAttributions[stepIndex] ? {
|
|
276
|
+
...stepAttributions[stepIndex],
|
|
277
|
+
stepIndex
|
|
278
|
+
} : null,
|
|
271
279
|
step,
|
|
272
280
|
stepMap
|
|
273
281
|
});
|
|
@@ -343,8 +351,8 @@ export const diffBySteps = (originalDoc, steps) => {
|
|
|
343
351
|
toA: granularToA,
|
|
344
352
|
fromB: granularFromB,
|
|
345
353
|
toB: granularToB,
|
|
346
|
-
deleted: createSpans(Math.max(0, granularToA - granularFromA)),
|
|
347
|
-
inserted: createSpans(Math.max(0, granularToB - granularFromB))
|
|
354
|
+
deleted: createSpans(Math.max(0, granularToA - granularFromA), rangedStep.stepAttribution),
|
|
355
|
+
inserted: createSpans(Math.max(0, granularToB - granularFromB), rangedStep.stepAttribution)
|
|
348
356
|
});
|
|
349
357
|
}
|
|
350
358
|
continue;
|
|
@@ -354,8 +362,8 @@ export const diffBySteps = (originalDoc, steps) => {
|
|
|
354
362
|
toA,
|
|
355
363
|
fromB,
|
|
356
364
|
toB,
|
|
357
|
-
deleted: createSpans(Math.max(0, toA - fromA)),
|
|
358
|
-
inserted: createSpans(Math.max(0, toB - fromB))
|
|
365
|
+
deleted: createSpans(Math.max(0, toA - fromA), rangedStep.stepAttribution),
|
|
366
|
+
inserted: createSpans(Math.max(0, toB - fromB), rangedStep.stepAttribution)
|
|
359
367
|
});
|
|
360
368
|
}
|
|
361
369
|
return mergeOverlappingByNewDocRange(changes);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { simplifyChanges } from 'prosemirror-changeset';
|
|
2
|
+
import { getAttributionKey } from '../decorations/colorSchemes/attributions';
|
|
3
|
+
import { optimizeChanges } from './optimizeChanges';
|
|
4
|
+
const getAttributionIdentity = change => {
|
|
5
|
+
const identities = new Set();
|
|
6
|
+
for (const span of [...change.deleted, ...change.inserted]) {
|
|
7
|
+
identities.add(getAttributionKey(span.data));
|
|
8
|
+
}
|
|
9
|
+
if (identities.size > 1) {
|
|
10
|
+
return {
|
|
11
|
+
key: undefined,
|
|
12
|
+
mergeable: false
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
key: identities.values().next().value,
|
|
17
|
+
mergeable: true
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Simplifies and optimizes consecutive changes without crossing an attribution boundary.
|
|
23
|
+
* A change which already contains more than one identity is deliberately kept isolated.
|
|
24
|
+
*/
|
|
25
|
+
export const simplifyChangesWithAttribution = (changes, doc) => {
|
|
26
|
+
const result = [];
|
|
27
|
+
let run = [];
|
|
28
|
+
let runIdentity;
|
|
29
|
+
const flush = () => {
|
|
30
|
+
if (run.length > 0) {
|
|
31
|
+
// Some show-diff producers use structurally compatible Change objects rather than the
|
|
32
|
+
// library class. `simplifyChanges` reads runtime `lenA`/`lenB` getters even though they
|
|
33
|
+
// are intentionally omitted from its public declarations, so add equivalent getters
|
|
34
|
+
// without calling the library's internal constructor.
|
|
35
|
+
const normalizedRun = run.map(change => ({
|
|
36
|
+
...change,
|
|
37
|
+
get lenA() {
|
|
38
|
+
return change.toA - change.fromA;
|
|
39
|
+
},
|
|
40
|
+
get lenB() {
|
|
41
|
+
return change.toB - change.fromB;
|
|
42
|
+
}
|
|
43
|
+
}));
|
|
44
|
+
result.push(...optimizeChanges(simplifyChanges(normalizedRun, doc)));
|
|
45
|
+
}
|
|
46
|
+
run = [];
|
|
47
|
+
runIdentity = undefined;
|
|
48
|
+
};
|
|
49
|
+
for (const change of changes) {
|
|
50
|
+
var _runIdentity;
|
|
51
|
+
const identity = getAttributionIdentity(change);
|
|
52
|
+
const canJoinRun = ((_runIdentity = runIdentity) === null || _runIdentity === void 0 ? void 0 : _runIdentity.mergeable) === true && identity.mergeable && runIdentity.key === identity.key;
|
|
53
|
+
if (run.length > 0 && !canJoinRun) {
|
|
54
|
+
flush();
|
|
55
|
+
}
|
|
56
|
+
run.push(change);
|
|
57
|
+
runIdentity = identity;
|
|
58
|
+
if (!identity.mergeable) {
|
|
59
|
+
flush();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
flush();
|
|
63
|
+
return result;
|
|
64
|
+
};
|