@atlaskit/editor-plugin-show-diff 9.1.2 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +24 -19
  3. package/dist/cjs/pm-plugins/decorations/createBlockChangedDecoration.js +14 -14
  4. package/dist/cjs/pm-plugins/decorations/createChangedRowDecorationWidgets.js +10 -1
  5. package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +13 -12
  6. package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +8 -8
  7. package/dist/cjs/pm-plugins/decorations/decorationKeys.js +49 -8
  8. package/dist/cjs/pm-plugins/main.js +41 -29
  9. package/dist/cjs/showDiffPlugin.js +8 -4
  10. package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +21 -16
  11. package/dist/es2019/pm-plugins/decorations/createBlockChangedDecoration.js +15 -15
  12. package/dist/es2019/pm-plugins/decorations/createChangedRowDecorationWidgets.js +9 -1
  13. package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +14 -13
  14. package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +9 -9
  15. package/dist/es2019/pm-plugins/decorations/decorationKeys.js +44 -7
  16. package/dist/es2019/pm-plugins/main.js +19 -5
  17. package/dist/es2019/showDiffPlugin.js +8 -2
  18. package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +24 -19
  19. package/dist/esm/pm-plugins/decorations/createBlockChangedDecoration.js +15 -15
  20. package/dist/esm/pm-plugins/decorations/createChangedRowDecorationWidgets.js +10 -1
  21. package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +14 -13
  22. package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +9 -9
  23. package/dist/esm/pm-plugins/decorations/decorationKeys.js +47 -7
  24. package/dist/esm/pm-plugins/main.js +41 -29
  25. package/dist/esm/showDiffPlugin.js +8 -4
  26. package/dist/types/pm-plugins/calculateDiff/calculateDiffDecorations.d.ts +7 -2
  27. package/dist/types/pm-plugins/decorations/createInlineChangedDecoration.d.ts +1 -1
  28. package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +1 -1
  29. package/dist/types/pm-plugins/decorations/decorationKeys.d.ts +27 -6
  30. package/dist/types/pm-plugins/main.d.ts +6 -1
  31. package/dist/types/showDiffPluginType.d.ts +9 -0
  32. package/package.json +21 -29
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @atlaskit/editor-plugin-show-diff
2
2
 
3
+ ## 10.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [`f2dc9097319f0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f2dc9097319f0) - ###
8
+ Dropped support for _legacy_ Typescript 4 types. **Typescript 5 is now the new minimum**.
9
+
10
+ Removes the `typesVersions` property and `dist/types-ts4.5` directory from the dist.
11
+
12
+ Types are now exclusively via the `"types": "dist/types/index.d.ts"` property.
13
+
14
+ ```diff
15
+ - "typesVersions": {
16
+ - ">=4.5 <4.9": {
17
+ - "*": [
18
+ - "dist/types-ts4.5/*",
19
+ - "dist/types-ts4.5/index.d.ts"
20
+ - ]
21
+ - }
22
+ - },
23
+ ```
24
+
25
+ ### Minor Changes
26
+
27
+ - [`4759c2ac86196`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/4759c2ac86196) -
28
+ EDITOR-7523: Add diff descriptors with new diff ids and types.
29
+
30
+ ### Patch Changes
31
+
32
+ - Updated dependencies
33
+
3
34
  ## 9.1.2
4
35
 
5
36
  ### Patch Changes
@@ -18,6 +18,7 @@ var _areDocsEqualByBlockStructureAndText = require("../areDocsEqualByBlockStruct
18
18
  var _createBlockChangedDecoration = require("../decorations/createBlockChangedDecoration");
19
19
  var _createInlineChangedDecoration = require("../decorations/createInlineChangedDecoration");
20
20
  var _createNodeChangedDecorationWidget = require("../decorations/createNodeChangedDecorationWidget");
21
+ var _decorationKeys = require("../decorations/decorationKeys");
21
22
  var _getAttrChangeRanges = require("../decorations/utils/getAttrChangeRanges");
22
23
  var _getMarkChangeRanges = require("../decorations/utils/getMarkChangeRanges");
23
24
  var _diffBySteps = require("./diffBySteps");
@@ -65,7 +66,7 @@ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration
65
66
  if (node.isBlock && (!(0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) || pos + node.nodeSize <= to)) {
66
67
  var nodeEnd = pos + node.nodeSize;
67
68
  var isActive = activeIndexPos && pos === activeIndexPos.from && nodeEnd === activeIndexPos.to;
68
- var blockChangedDecorations = (0, _createBlockChangedDecoration.createBlockChangedDecoration)({
69
+ decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createBlockChangedDecoration.createBlockChangedDecoration)({
69
70
  change: {
70
71
  from: pos,
71
72
  to: nodeEnd,
@@ -75,10 +76,7 @@ var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration
75
76
  isInserted: isInserted,
76
77
  isActive: isActive,
77
78
  shouldHideDeleted: shouldHideDeleted
78
- });
79
- if (blockChangedDecorations.length) {
80
- decorations.push.apply(decorations, (0, _toConsumableArray2.default)(blockChangedDecorations));
81
- }
79
+ })));
82
80
  }
83
81
  });
84
82
  return decorations;
@@ -100,7 +98,10 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
100
98
  var originalDoc = pluginState.originalDoc,
101
99
  steps = pluginState.steps;
102
100
  if (!originalDoc || !pluginState.isDisplayingChanges) {
103
- return _view.DecorationSet.empty;
101
+ return {
102
+ decorations: _view.DecorationSet.empty,
103
+ diffDescriptors: []
104
+ };
104
105
  }
105
106
  var tr = state.tr;
106
107
  var steppedDoc = originalDoc;
@@ -143,7 +144,10 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
143
144
  }
144
145
  });
145
146
  if (!recoveredViaContentEquality) {
146
- return _view.DecorationSet.empty;
147
+ return {
148
+ decorations: _view.DecorationSet.empty,
149
+ diffDescriptors: []
150
+ };
147
151
  }
148
152
  }
149
153
  var changeset = _prosemirrorChangeset.ChangeSet.create(originalDoc).addSteps(steppedDoc, stepMaps, tr.doc);
@@ -162,14 +166,14 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
162
166
  var isInserted = !isInverted;
163
167
  if (change.inserted.length > 0) {
164
168
  var shouldHideDeleted = (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? isInverted && hideDeletedDiffs : false;
165
- decorations.push((0, _createInlineChangedDecoration.createInlineChangedDecoration)(_objectSpread({
169
+ decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createInlineChangedDecoration.createInlineChangedDecoration)(_objectSpread({
166
170
  change: change,
167
171
  colorScheme: colorScheme,
168
172
  isActive: isActive
169
173
  }, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) && {
170
174
  isInserted: isInserted,
171
175
  shouldHideDeleted: shouldHideDeleted
172
- })));
176
+ }))));
173
177
  decorations.push.apply(decorations, (0, _toConsumableArray2.default)(calculateNodesForBlockDecoration(_objectSpread(_objectSpread({
174
178
  doc: tr.doc,
175
179
  from: change.fromB,
@@ -186,7 +190,7 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
186
190
  if (change.deleted.length > 0) {
187
191
  var _shouldHideDeleted = (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? !isInverted && hideDeletedDiffs : false;
188
192
  if (!_shouldHideDeleted) {
189
- var decoration = (0, _createNodeChangedDecorationWidget.createNodeChangedDecorationWidget)(_objectSpread({
193
+ decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createNodeChangedDecorationWidget.createNodeChangedDecorationWidget)(_objectSpread({
190
194
  change: change,
191
195
  doc: originalDoc,
192
196
  nodeViewSerializer: nodeViewSerializer,
@@ -197,32 +201,29 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
197
201
  }, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) && {
198
202
  isInserted: !isInserted,
199
203
  diffType: diffType
200
- }));
201
- if (decoration) {
202
- decorations.push.apply(decorations, (0, _toConsumableArray2.default)(decoration));
203
- }
204
+ }))));
204
205
  }
205
206
  }
206
207
  });
207
208
  (0, _getMarkChangeRanges.getMarkChangeRanges)(steps).forEach(function (change) {
208
209
  var isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
209
- decorations.push((0, _createInlineChangedDecoration.createInlineChangedDecoration)({
210
+ decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createInlineChangedDecoration.createInlineChangedDecoration)({
210
211
  change: change,
211
212
  colorScheme: colorScheme,
212
213
  isActive: isActive,
213
214
  isInserted: true
214
- }));
215
+ })));
215
216
  });
216
217
  (0, _getAttrChangeRanges.getAttrChangeRanges)(tr.doc, attrSteps).forEach(function (change) {
217
218
  if (change.isInline) {
218
219
  // Inline nodes (e.g. date) need an inline decoration rather than a block decoration
219
220
  var isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
220
- decorations.push((0, _createInlineChangedDecoration.createInlineChangedDecoration)({
221
+ decorations.push.apply(decorations, (0, _toConsumableArray2.default)((0, _createInlineChangedDecoration.createInlineChangedDecoration)({
221
222
  change: change,
222
223
  colorScheme: colorScheme,
223
224
  isActive: isActive,
224
225
  isInserted: true
225
- }));
226
+ })));
226
227
  } else {
227
228
  decorations.push.apply(decorations, (0, _toConsumableArray2.default)(calculateNodesForBlockDecoration({
228
229
  doc: tr.doc,
@@ -235,7 +236,11 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref3
235
236
  })));
236
237
  }
237
238
  });
238
- return _view.DecorationSet.empty.add(tr.doc, decorations);
239
+ var decorationSet = _view.DecorationSet.empty.add(tr.doc, decorations);
240
+ return {
241
+ decorations: decorationSet,
242
+ diffDescriptors: (0, _decorationKeys.extractDiffDescriptors)(decorationSet)
243
+ };
239
244
  };
240
245
  var calculateDiffDecorations = exports.calculateDiffDecorations = (0, _memoizeOne.default)(calculateDiffDecorationsInner,
241
246
  // Cache results unless relevant inputs change
@@ -115,15 +115,16 @@ var createBlockChangedDecoration = exports.createBlockChangedDecoration = functi
115
115
  _ref2$shouldHideDelet = _ref2.shouldHideDeleted,
116
116
  shouldHideDeleted = _ref2$shouldHideDelet === void 0 ? false : _ref2$shouldHideDelet;
117
117
  var decorations = [];
118
+ var diffId = crypto.randomUUID();
118
119
  if (shouldHideDeleted) {
119
120
  return [_view.Decoration.node(change.from, change.to, {
120
121
  style: displayNoneStyle
121
- }, {
122
- key: (0, _decorationKeys.buildDiffDecorationKey)({
123
- type: _decorationKeys.DiffDecorationKey.block
124
- }),
122
+ }, (0, _decorationKeys.buildDiffDecorationSpec)({
123
+ decorationType: 'block',
124
+ diffId: diffId,
125
+ isActive: isActive,
125
126
  nodeName: change.name
126
- })];
127
+ }))];
127
128
  }
128
129
  var style;
129
130
  if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) && ['tableCell', 'tableHeader'].includes(change.name)) {
@@ -132,11 +133,10 @@ var createBlockChangedDecoration = exports.createBlockChangedDecoration = functi
132
133
  cellOverlay.setAttribute('style', cellOverlayStyle);
133
134
  decorations.push(
134
135
  // change.to - 1 to position the overlay inside the end of the cell
136
+ // this key doesn't use the spec / key builder since this is just for
137
+ // decorating the cells, this is part of a bigger table diff
135
138
  _view.Decoration.widget(change.to - 1, cellOverlay, {
136
- key: (0, _decorationKeys.buildDiffDecorationKey)({
137
- type: _decorationKeys.DiffDecorationKey.widget,
138
- isActive: isActive
139
- })
139
+ key: 'cell-overlay-decoration'
140
140
  }));
141
141
  }
142
142
  if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
@@ -159,12 +159,12 @@ var createBlockChangedDecoration = exports.createBlockChangedDecoration = functi
159
159
  style: style,
160
160
  'data-testid': 'show-diff-changed-decoration-node',
161
161
  class: className
162
- }, {
163
- key: (0, _decorationKeys.buildDiffDecorationKey)({
164
- type: _decorationKeys.DiffDecorationKey.block
165
- }),
162
+ }, (0, _decorationKeys.buildDiffDecorationSpec)({
163
+ decorationType: 'block',
164
+ diffId: diffId,
165
+ isActive: isActive,
166
166
  nodeName: change.name
167
- }));
167
+ })));
168
168
  }
169
169
  return decorations;
170
170
  };
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.createChangedRowDecorationWidgets = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
8
9
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
10
  var _document = require("@atlaskit/editor-common/utils/document");
10
11
  var _utils = require("@atlaskit/editor-prosemirror/utils");
@@ -13,7 +14,10 @@ var _tableMap = require("@atlaskit/editor-tables/table-map");
13
14
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
14
15
  var _standard = require("./colorSchemes/standard");
15
16
  var _traditional = require("./colorSchemes/traditional");
17
+ var _decorationKeys = require("./decorationKeys");
16
18
  var _findSafeInsertPos = require("./utils/findSafeInsertPos");
19
+ 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; }
20
+ 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
21
  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; } } }; }
18
22
  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; } }
19
23
  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; }
@@ -210,6 +214,11 @@ var createChangedRowDecorationWidgets = exports.createChangedRowDecorationWidget
210
214
  var safeInsertPos = (0, _findSafeInsertPos.findSafeInsertPos)(newDoc, changedRow.fromB - 1,
211
215
  // -1 to find the first safe position from the table
212
216
  originalDoc.slice(changedRow.fromA, changedRow.toA));
213
- return _view.Decoration.widget(safeInsertPos, rowDOM, {});
217
+ var diffId = crypto.randomUUID();
218
+ return _view.Decoration.widget(safeInsertPos, rowDOM, _objectSpread({}, (0, _decorationKeys.buildDiffDecorationSpec)({
219
+ decorationType: 'widget',
220
+ diffId: diffId,
221
+ isActive: false
222
+ })));
214
223
  });
215
224
  };
@@ -29,14 +29,15 @@ var createInlineChangedDecoration = exports.createInlineChangedDecoration = func
29
29
  isInserted = _ref$isInserted === void 0 ? true : _ref$isInserted,
30
30
  _ref$shouldHideDelete = _ref.shouldHideDeleted,
31
31
  shouldHideDeleted = _ref$shouldHideDelete === void 0 ? false : _ref$shouldHideDelete;
32
+ var diffId = crypto.randomUUID();
32
33
  if (shouldHideDeleted) {
33
- return _view.Decoration.inline(change.fromB, change.toB, {
34
+ return [_view.Decoration.inline(change.fromB, change.toB, {
34
35
  style: displayNoneStyle
35
- }, {
36
- key: (0, _decorationKeys.buildDiffDecorationKey)({
37
- type: _decorationKeys.DiffDecorationKey.inline
38
- })
39
- });
36
+ }, (0, _decorationKeys.buildDiffDecorationSpec)({
37
+ decorationType: 'inline',
38
+ diffId: diffId,
39
+ isActive: isActive
40
+ }))];
40
41
  }
41
42
  var style;
42
43
  if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
@@ -66,12 +67,12 @@ var createInlineChangedDecoration = exports.createInlineChangedDecoration = func
66
67
  style = isActive ? _standard.editingStyleActive : _standard.editingStyle;
67
68
  }
68
69
  }
69
- return _view.Decoration.inline(change.fromB, change.toB, {
70
+ return [_view.Decoration.inline(change.fromB, change.toB, {
70
71
  style: style,
71
72
  'data-testid': 'show-diff-changed-decoration'
72
- }, {
73
- key: (0, _decorationKeys.buildDiffDecorationKey)({
74
- type: _decorationKeys.DiffDecorationKey.inline
75
- })
76
- });
73
+ }, (0, _decorationKeys.buildDiffDecorationSpec)({
74
+ decorationType: 'inline',
75
+ diffId: diffId,
76
+ isActive: isActive
77
+ }))];
77
78
  };
@@ -122,7 +122,7 @@ var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidge
122
122
  var safeInsertPos = (0, _findSafeInsertPos.findSafeInsertPos)(newDoc, change.fromB, slice);
123
123
  var isActive = activeIndexPos && safeInsertPos === activeIndexPos.from && safeInsertPos === activeIndexPos.to;
124
124
  if (slice.content.content.length === 0 || shouldSkipDeletedEmptyParagraphDecoration) {
125
- return;
125
+ return [];
126
126
  }
127
127
  var isTableCellContent = slice.content.content.some(function () {
128
128
  return slice.content.content.some(function (siblingNode) {
@@ -135,7 +135,7 @@ var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidge
135
135
  });
136
136
  });
137
137
  if (isTableCellContent) {
138
- return;
138
+ return [];
139
139
  }
140
140
  if (isTableRowContent) {
141
141
  return (0, _createChangedRowDecorationWidgets.createChangedRowDecorationWidgets)({
@@ -256,14 +256,14 @@ var createNodeChangedDecorationWidget = exports.createNodeChangedDecorationWidge
256
256
  }
257
257
  });
258
258
  dom.setAttribute('data-testid', 'show-diff-deleted-decoration');
259
+ var diffId = crypto.randomUUID();
259
260
  var decorations = [];
260
- decorations.push(_view.Decoration.widget(safeInsertPos, dom, _objectSpread({
261
- key: (0, _decorationKeys.buildDiffDecorationKey)({
262
- type: _decorationKeys.DiffDecorationKey.widget,
263
- isActive: isActive
264
- })
261
+ decorations.push(_view.Decoration.widget(safeInsertPos, dom, (0, _decorationKeys.buildDiffDecorationSpec)(_objectSpread({
262
+ decorationType: 'widget',
263
+ diffId: diffId,
264
+ isActive: isActive
265
265
  }, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) && {
266
266
  side: -1
267
- })));
267
+ }))));
268
268
  return decorations;
269
269
  };
@@ -1,24 +1,29 @@
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
- exports.buildDiffDecorationKey = exports.DiffDecorationKey = exports.DIFF_KEY_PREFIX = void 0;
7
+ exports.extractDiffDescriptors = exports.buildDiffDecorationSpec = exports.buildDiffDecorationKey = exports.DiffDecorationKey = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
10
+ 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
+ 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; }
7
12
  /**
8
13
  * Shared prefix for every decoration key produced by the show-diff plugin.
9
14
  * All keys derive from this, so the full set of plugin decorations can be
10
15
  * identified by this single prefix.
11
16
  */
12
- var DIFF_KEY_PREFIX = exports.DIFF_KEY_PREFIX = 'diff';
17
+ var DIFF_DECORATION_FAMILY = 'diff';
13
18
  /**
14
19
  * The kinds of decoration the show-diff plugin produces. Each value is the
15
20
  * leading segment of the generated key, so a decoration's kind can be matched
16
21
  * with `key?.startsWith(DiffDecorationKey.inline)` etc.
17
22
  */
18
23
  var DiffDecorationKey = exports.DiffDecorationKey = {
19
- inline: "".concat(DIFF_KEY_PREFIX, "-inline"),
20
- block: "".concat(DIFF_KEY_PREFIX, "-block"),
21
- widget: "".concat(DIFF_KEY_PREFIX, "-widget")
24
+ inline: "".concat(DIFF_DECORATION_FAMILY, "-inline"),
25
+ block: "".concat(DIFF_DECORATION_FAMILY, "-block"),
26
+ widget: "".concat(DIFF_DECORATION_FAMILY, "-widget")
22
27
  };
23
28
 
24
29
  /**
@@ -26,7 +31,43 @@ var DiffDecorationKey = exports.DiffDecorationKey = {
26
31
  * (e.g. `diff-inline-active`).
27
32
  */
28
33
  var buildDiffDecorationKey = exports.buildDiffDecorationKey = function buildDiffDecorationKey(_ref) {
29
- var type = _ref.type,
30
- isActive = _ref.isActive;
31
- return isActive !== undefined ? "".concat(type, "-").concat(isActive ? 'active' : 'inactive') : type;
34
+ var decorationKeyPrefix = _ref.decorationKeyPrefix,
35
+ isActive = _ref.isActive,
36
+ diffId = _ref.diffId;
37
+ if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
38
+ return "".concat(decorationKeyPrefix, "-").concat(diffId, "-").concat(isActive ? 'active' : 'inactive');
39
+ }
40
+ return isActive !== undefined ? "".concat(decorationKeyPrefix, "-").concat(isActive ? 'active' : 'inactive') : decorationKeyPrefix;
41
+ };
42
+ var buildDiffDecorationSpec = exports.buildDiffDecorationSpec = function buildDiffDecorationSpec(_ref2) {
43
+ var decorationType = _ref2.decorationType,
44
+ diffId = _ref2.diffId,
45
+ isActive = _ref2.isActive,
46
+ nodeName = _ref2.nodeName,
47
+ side = _ref2.side;
48
+ return _objectSpread(_objectSpread({
49
+ decorationFamily: DIFF_DECORATION_FAMILY,
50
+ decorationType: decorationType,
51
+ diffId: diffId,
52
+ key: buildDiffDecorationKey({
53
+ decorationKeyPrefix: DiffDecorationKey[decorationType],
54
+ diffId: diffId,
55
+ isActive: isActive
56
+ })
57
+ }, nodeName ? {
58
+ nodeName: nodeName
59
+ } : {}), side !== undefined ? {
60
+ side: side
61
+ } : {});
62
+ };
63
+ var extractDiffDescriptors = exports.extractDiffDescriptors = function extractDiffDescriptors(decorations) {
64
+ return decorations.find(undefined, undefined, function (spec) {
65
+ return spec.decorationFamily === 'diff';
66
+ }).map(function (_ref3) {
67
+ var spec = _ref3.spec;
68
+ return {
69
+ id: spec.diffId,
70
+ type: spec.decorationType
71
+ };
72
+ });
32
73
  };
@@ -41,7 +41,8 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
41
41
  }, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
42
42
  isInverted: false,
43
43
  diffType: 'inline',
44
- hideDeletedDiffs: false
44
+ hideDeletedDiffs: false,
45
+ diffDescriptors: []
45
46
  } : {});
46
47
  },
47
48
  apply: function apply(tr, currentPluginState, oldState, newState) {
@@ -56,21 +57,26 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
56
57
  activeIndex: undefined
57
58
  });
58
59
  // Calculate and store decorations in state
59
- var decorations = (0, _calculateDiffDecorations.calculateDiffDecorations)(_objectSpread({
60
- state: newState,
61
- pluginState: newPluginState,
62
- nodeViewSerializer: nodeViewSerializer,
63
- colorScheme: config === null || config === void 0 ? void 0 : config.colorScheme,
64
- intl: getIntl(),
65
- activeIndexPos: newPluginState.activeIndexPos,
66
- api: api
67
- }, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
68
- isInverted: (_newPluginState = newPluginState) === null || _newPluginState === void 0 ? void 0 : _newPluginState.isInverted,
69
- diffType: (_newPluginState2 = newPluginState) === null || _newPluginState2 === void 0 ? void 0 : _newPluginState2.diffType,
70
- hideDeletedDiffs: (_newPluginState3 = newPluginState) === null || _newPluginState3 === void 0 ? void 0 : _newPluginState3.hideDeletedDiffs
71
- } : {}));
72
- // Update the decorations
60
+ var _calculateDiffDecorat = (0, _calculateDiffDecorations.calculateDiffDecorations)(_objectSpread({
61
+ state: newState,
62
+ pluginState: newPluginState,
63
+ nodeViewSerializer: nodeViewSerializer,
64
+ colorScheme: config === null || config === void 0 ? void 0 : config.colorScheme,
65
+ intl: getIntl(),
66
+ activeIndexPos: newPluginState.activeIndexPos,
67
+ api: api
68
+ }, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
69
+ isInverted: (_newPluginState = newPluginState) === null || _newPluginState === void 0 ? void 0 : _newPluginState.isInverted,
70
+ diffType: (_newPluginState2 = newPluginState) === null || _newPluginState2 === void 0 ? void 0 : _newPluginState2.diffType,
71
+ hideDeletedDiffs: (_newPluginState3 = newPluginState) === null || _newPluginState3 === void 0 ? void 0 : _newPluginState3.hideDeletedDiffs
72
+ } : {})),
73
+ decorations = _calculateDiffDecorat.decorations,
74
+ diffDescriptors = _calculateDiffDecorat.diffDescriptors;
75
+ // Update the decorations and their ids
73
76
  newPluginState.decorations = decorations;
77
+ if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
78
+ newPluginState.diffDescriptors = diffDescriptors;
79
+ }
74
80
  } else if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'HIDE_DIFF') {
75
81
  newPluginState = _objectSpread(_objectSpread(_objectSpread({}, currentPluginState), meta), {}, {
76
82
  decorations: _view.DecorationSet.empty,
@@ -79,7 +85,8 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
79
85
  }, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
80
86
  isInverted: false,
81
87
  diffType: 'inline',
82
- hideDeletedDiffs: false
88
+ hideDeletedDiffs: false,
89
+ diffDescriptors: []
83
90
  } : {});
84
91
  } else if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'SCROLL_TO_NEXT' || (meta === null || meta === void 0 ? void 0 : meta.action) === 'SCROLL_TO_PREVIOUS') {
85
92
  // Update the active index in plugin state and recalculate decorations
@@ -109,20 +116,25 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
109
116
  } : undefined
110
117
  });
111
118
  // Recalculate decorations with the new active index
112
- var updatedDecorations = (0, _calculateDiffDecorations.calculateDiffDecorations)(_objectSpread({
113
- state: newState,
114
- pluginState: newPluginState,
115
- nodeViewSerializer: nodeViewSerializer,
116
- colorScheme: config === null || config === void 0 ? void 0 : config.colorScheme,
117
- intl: getIntl(),
118
- activeIndexPos: newPluginState.activeIndexPos,
119
- api: api
120
- }, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
121
- isInverted: newPluginState.isInverted,
122
- diffType: newPluginState.diffType,
123
- hideDeletedDiffs: newPluginState.hideDeletedDiffs
124
- } : {}));
119
+ var _calculateDiffDecorat2 = (0, _calculateDiffDecorations.calculateDiffDecorations)(_objectSpread({
120
+ state: newState,
121
+ pluginState: newPluginState,
122
+ nodeViewSerializer: nodeViewSerializer,
123
+ colorScheme: config === null || config === void 0 ? void 0 : config.colorScheme,
124
+ intl: getIntl(),
125
+ activeIndexPos: newPluginState.activeIndexPos,
126
+ api: api
127
+ }, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
128
+ isInverted: newPluginState.isInverted,
129
+ diffType: newPluginState.diffType,
130
+ hideDeletedDiffs: newPluginState.hideDeletedDiffs
131
+ } : {})),
132
+ updatedDecorations = _calculateDiffDecorat2.decorations,
133
+ updatedDiffDescriptors = _calculateDiffDecorat2.diffDescriptors;
125
134
  newPluginState.decorations = updatedDecorations;
135
+ if ((0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
136
+ newPluginState.diffDescriptors = updatedDiffDescriptors;
137
+ }
126
138
  }
127
139
  } else {
128
140
  newPluginState = _objectSpread(_objectSpread({}, currentPluginState), meta);
@@ -68,18 +68,22 @@ var showDiffPlugin = exports.showDiffPlugin = function showDiffPlugin(_ref) {
68
68
  },
69
69
  getSharedState: function getSharedState(editorState) {
70
70
  if (!editorState) {
71
- return {
71
+ return _objectSpread({
72
72
  isDisplayingChanges: false,
73
73
  activeIndex: undefined
74
- };
74
+ }, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
75
+ diffDescriptors: []
76
+ } : {});
75
77
  }
76
78
  var pluginState = _main.showDiffPluginKey.getState(editorState);
77
79
  var decorationCount = (0, _getScrollableDecorations.getScrollableDecorations)(pluginState === null || pluginState === void 0 ? void 0 : pluginState.decorations, editorState.doc);
78
- return {
80
+ return _objectSpread({
79
81
  isDisplayingChanges: decorationCount.length > 0,
80
82
  activeIndex: pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex,
81
83
  numberOfChanges: decorationCount.length
82
- };
84
+ }, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
85
+ diffDescriptors: pluginState === null || pluginState === void 0 ? void 0 : pluginState.diffDescriptors
86
+ } : {});
83
87
  }
84
88
  };
85
89
  };
@@ -9,6 +9,7 @@ import { areDocsEqualByBlockStructureAndText } from '../areDocsEqualByBlockStruc
9
9
  import { createBlockChangedDecoration } from '../decorations/createBlockChangedDecoration';
10
10
  import { createInlineChangedDecoration } from '../decorations/createInlineChangedDecoration';
11
11
  import { createNodeChangedDecorationWidget } from '../decorations/createNodeChangedDecorationWidget';
12
+ import { extractDiffDescriptors } from '../decorations/decorationKeys';
12
13
  import { getAttrChangeRanges, stepIsValidAttrChange } from '../decorations/utils/getAttrChangeRanges';
13
14
  import { getMarkChangeRanges } from '../decorations/utils/getMarkChangeRanges';
14
15
  import { diffBySteps } from './diffBySteps';
@@ -51,7 +52,7 @@ const calculateNodesForBlockDecoration = ({
51
52
  if (node.isBlock && (!expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) || pos + node.nodeSize <= to)) {
52
53
  const nodeEnd = pos + node.nodeSize;
53
54
  const isActive = activeIndexPos && pos === activeIndexPos.from && nodeEnd === activeIndexPos.to;
54
- const blockChangedDecorations = createBlockChangedDecoration({
55
+ decorations.push(...createBlockChangedDecoration({
55
56
  change: {
56
57
  from: pos,
57
58
  to: nodeEnd,
@@ -61,10 +62,7 @@ const calculateNodesForBlockDecoration = ({
61
62
  isInserted,
62
63
  isActive,
63
64
  shouldHideDeleted
64
- });
65
- if (blockChangedDecorations.length) {
66
- decorations.push(...blockChangedDecorations);
67
- }
65
+ }));
68
66
  }
69
67
  });
70
68
  return decorations;
@@ -86,7 +84,10 @@ const calculateDiffDecorationsInner = ({
86
84
  steps
87
85
  } = pluginState;
88
86
  if (!originalDoc || !pluginState.isDisplayingChanges) {
89
- return DecorationSet.empty;
87
+ return {
88
+ decorations: DecorationSet.empty,
89
+ diffDescriptors: []
90
+ };
90
91
  }
91
92
  const {
92
93
  tr
@@ -122,7 +123,10 @@ const calculateDiffDecorationsInner = ({
122
123
  }
123
124
  });
124
125
  if (!recoveredViaContentEquality) {
125
- return DecorationSet.empty;
126
+ return {
127
+ decorations: DecorationSet.empty,
128
+ diffDescriptors: []
129
+ };
126
130
  }
127
131
  }
128
132
  const changeset = ChangeSet.create(originalDoc).addSteps(steppedDoc, stepMaps, tr.doc);
@@ -141,7 +145,7 @@ const calculateDiffDecorationsInner = ({
141
145
  const isInserted = !isInverted;
142
146
  if (change.inserted.length > 0) {
143
147
  const shouldHideDeleted = expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? isInverted && hideDeletedDiffs : false;
144
- decorations.push(createInlineChangedDecoration({
148
+ decorations.push(...createInlineChangedDecoration({
145
149
  change,
146
150
  colorScheme,
147
151
  isActive,
@@ -166,7 +170,7 @@ const calculateDiffDecorationsInner = ({
166
170
  if (change.deleted.length > 0) {
167
171
  const shouldHideDeleted = expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? !isInverted && hideDeletedDiffs : false;
168
172
  if (!shouldHideDeleted) {
169
- const decoration = createNodeChangedDecorationWidget({
173
+ decorations.push(...createNodeChangedDecorationWidget({
170
174
  change,
171
175
  doc: originalDoc,
172
176
  nodeViewSerializer,
@@ -178,16 +182,13 @@ const calculateDiffDecorationsInner = ({
178
182
  isInserted: !isInserted,
179
183
  diffType
180
184
  })
181
- });
182
- if (decoration) {
183
- decorations.push(...decoration);
184
- }
185
+ }));
185
186
  }
186
187
  }
187
188
  });
188
189
  getMarkChangeRanges(steps).forEach(change => {
189
190
  const isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
190
- decorations.push(createInlineChangedDecoration({
191
+ decorations.push(...createInlineChangedDecoration({
191
192
  change,
192
193
  colorScheme,
193
194
  isActive,
@@ -198,7 +199,7 @@ const calculateDiffDecorationsInner = ({
198
199
  if (change.isInline) {
199
200
  // Inline nodes (e.g. date) need an inline decoration rather than a block decoration
200
201
  const isActive = activeIndexPos && change.fromB === activeIndexPos.from && change.toB === activeIndexPos.to;
201
- decorations.push(createInlineChangedDecoration({
202
+ decorations.push(...createInlineChangedDecoration({
202
203
  change,
203
204
  colorScheme,
204
205
  isActive,
@@ -216,7 +217,11 @@ const calculateDiffDecorationsInner = ({
216
217
  }));
217
218
  }
218
219
  });
219
- return DecorationSet.empty.add(tr.doc, decorations);
220
+ const decorationSet = DecorationSet.empty.add(tr.doc, decorations);
221
+ return {
222
+ decorations: decorationSet,
223
+ diffDescriptors: extractDiffDescriptors(decorationSet)
224
+ };
220
225
  };
221
226
  export const calculateDiffDecorations = memoizeOne(calculateDiffDecorationsInner,
222
227
  // Cache results unless relevant inputs change