@atlaskit/editor-plugin-show-diff 9.1.1 → 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 (61) hide show
  1. package/CHANGELOG.md +37 -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
  33. package/show-diff-plugin/package.json +1 -8
  34. package/show-diff-plugin-type/package.json +1 -8
  35. package/dist/types-ts4.5/entry-points/show-diff-plugin-type.d.ts +0 -1
  36. package/dist/types-ts4.5/entry-points/show-diff-plugin.d.ts +0 -1
  37. package/dist/types-ts4.5/index.d.ts +0 -2
  38. package/dist/types-ts4.5/pm-plugins/NodeViewSerializer.d.ts +0 -80
  39. package/dist/types-ts4.5/pm-plugins/areDocsEqualByBlockStructureAndText.d.ts +0 -12
  40. package/dist/types-ts4.5/pm-plugins/calculateDiff/calculateDiffDecorations.d.ts +0 -21
  41. package/dist/types-ts4.5/pm-plugins/calculateDiff/diffBySteps.d.ts +0 -4
  42. package/dist/types-ts4.5/pm-plugins/calculateDiff/groupChangesByBlock.d.ts +0 -7
  43. package/dist/types-ts4.5/pm-plugins/calculateDiff/optimizeChanges.d.ts +0 -6
  44. package/dist/types-ts4.5/pm-plugins/calculateDiff/simplifySteps.d.ts +0 -3
  45. package/dist/types-ts4.5/pm-plugins/decorations/colorSchemes/standard.d.ts +0 -30
  46. package/dist/types-ts4.5/pm-plugins/decorations/colorSchemes/traditional.d.ts +0 -39
  47. package/dist/types-ts4.5/pm-plugins/decorations/createBlockChangedDecoration.d.ts +0 -21
  48. package/dist/types-ts4.5/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +0 -18
  49. package/dist/types-ts4.5/pm-plugins/decorations/createInlineChangedDecoration.d.ts +0 -18
  50. package/dist/types-ts4.5/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +0 -23
  51. package/dist/types-ts4.5/pm-plugins/decorations/decorationKeys.d.ts +0 -23
  52. package/dist/types-ts4.5/pm-plugins/decorations/utils/findSafeInsertPos.d.ts +0 -9
  53. package/dist/types-ts4.5/pm-plugins/decorations/utils/getAttrChangeRanges.d.ts +0 -19
  54. package/dist/types-ts4.5/pm-plugins/decorations/utils/getMarkChangeRanges.d.ts +0 -7
  55. package/dist/types-ts4.5/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +0 -17
  56. package/dist/types-ts4.5/pm-plugins/enforceCustomStepRegisters.d.ts +0 -1
  57. package/dist/types-ts4.5/pm-plugins/getScrollableDecorations.d.ts +0 -27
  58. package/dist/types-ts4.5/pm-plugins/main.d.ts +0 -29
  59. package/dist/types-ts4.5/pm-plugins/scrollToDiff.d.ts +0 -15
  60. package/dist/types-ts4.5/showDiffPlugin.d.ts +0 -2
  61. package/dist/types-ts4.5/showDiffPluginType.d.ts +0 -68
@@ -1,4 +1,7 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
1
2
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
+ 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; }
4
+ 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) { _defineProperty(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; }
2
5
  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; } } }; }
3
6
  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; } }
4
7
  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; }
@@ -9,6 +12,7 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
9
12
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
10
13
  import { addedCellOverlayStyle, deletedRowStyle, deletedCellOverlayStyle } from './colorSchemes/standard';
11
14
  import { deletedTraditionalRowStyle, deletedTraditionalCellOverlayStyle, traditionalAddedCellOverlayStyle } from './colorSchemes/traditional';
15
+ import { buildDiffDecorationSpec } from './decorationKeys';
12
16
  import { findSafeInsertPos } from './utils/findSafeInsertPos';
13
17
  /**
14
18
  * Extracts information about deleted table rows from a change
@@ -203,6 +207,11 @@ export var createChangedRowDecorationWidgets = function createChangedRowDecorati
203
207
  var safeInsertPos = findSafeInsertPos(newDoc, changedRow.fromB - 1,
204
208
  // -1 to find the first safe position from the table
205
209
  originalDoc.slice(changedRow.fromA, changedRow.toA));
206
- return Decoration.widget(safeInsertPos, rowDOM, {});
210
+ var diffId = crypto.randomUUID();
211
+ return Decoration.widget(safeInsertPos, rowDOM, _objectSpread({}, buildDiffDecorationSpec({
212
+ decorationType: 'widget',
213
+ diffId: diffId,
214
+ isActive: false
215
+ })));
207
216
  });
208
217
  };
@@ -3,7 +3,7 @@ import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
3
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
4
  import { editingStyle, editingStyleExtended, editingStyleActive, editingStyleActiveExtended, deletedContentStyle, deletedContentStyleActive, deletedInlineContentStyleExtended } from './colorSchemes/standard';
5
5
  import { traditionalInsertStyle, traditionalInsertStyleActive, getDeletedTraditionalInlineStyle } from './colorSchemes/traditional';
6
- import { buildDiffDecorationKey, DiffDecorationKey } from './decorationKeys';
6
+ import { buildDiffDecorationSpec } from './decorationKeys';
7
7
  var displayNoneStyle = convertToInlineCss({
8
8
  display: 'none'
9
9
  });
@@ -23,14 +23,15 @@ export var createInlineChangedDecoration = function createInlineChangedDecoratio
23
23
  isInserted = _ref$isInserted === void 0 ? true : _ref$isInserted,
24
24
  _ref$shouldHideDelete = _ref.shouldHideDeleted,
25
25
  shouldHideDeleted = _ref$shouldHideDelete === void 0 ? false : _ref$shouldHideDelete;
26
+ var diffId = crypto.randomUUID();
26
27
  if (shouldHideDeleted) {
27
- return Decoration.inline(change.fromB, change.toB, {
28
+ return [Decoration.inline(change.fromB, change.toB, {
28
29
  style: displayNoneStyle
29
- }, {
30
- key: buildDiffDecorationKey({
31
- type: DiffDecorationKey.inline
32
- })
33
- });
30
+ }, buildDiffDecorationSpec({
31
+ decorationType: 'inline',
32
+ diffId: diffId,
33
+ isActive: isActive
34
+ }))];
34
35
  }
35
36
  var style;
36
37
  if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
@@ -60,12 +61,12 @@ export var createInlineChangedDecoration = function createInlineChangedDecoratio
60
61
  style = isActive ? editingStyleActive : editingStyle;
61
62
  }
62
63
  }
63
- return Decoration.inline(change.fromB, change.toB, {
64
+ return [Decoration.inline(change.fromB, change.toB, {
64
65
  style: style,
65
66
  'data-testid': 'show-diff-changed-decoration'
66
- }, {
67
- key: buildDiffDecorationKey({
68
- type: DiffDecorationKey.inline
69
- })
70
- });
67
+ }, buildDiffDecorationSpec({
68
+ decorationType: 'inline',
69
+ diffId: diffId,
70
+ isActive: isActive
71
+ }))];
71
72
  };
@@ -8,7 +8,7 @@ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
8
8
  import { editingStyle, editingStyleExtended, editingStyleActive, editingStyleActiveExtended, deletedContentStyle, deletedContentStyleActive, deletedContentStyleNew, deletedContentStyleUnbounded, deletedInlineContentStyleExtended } from './colorSchemes/standard';
9
9
  import { traditionalInsertStyle, traditionalInsertStyleActive, getDeletedTraditionalInlineStyle, deletedTraditionalContentStyleUnbounded, deletedTraditionalContentStyleUnboundedActive } from './colorSchemes/traditional';
10
10
  import { createChangedRowDecorationWidgets } from './createChangedRowDecorationWidgets';
11
- import { buildDiffDecorationKey, DiffDecorationKey } from './decorationKeys';
11
+ import { buildDiffDecorationSpec } from './decorationKeys';
12
12
  import { findSafeInsertPos } from './utils/findSafeInsertPos';
13
13
  import { wrapBlockNodeView } from './utils/wrapBlockNodeView';
14
14
  var getDeletedContentStyleUnbounded = function getDeletedContentStyleUnbounded(colorScheme) {
@@ -115,7 +115,7 @@ export var createNodeChangedDecorationWidget = function createNodeChangedDecorat
115
115
  var safeInsertPos = findSafeInsertPos(newDoc, change.fromB, slice);
116
116
  var isActive = activeIndexPos && safeInsertPos === activeIndexPos.from && safeInsertPos === activeIndexPos.to;
117
117
  if (slice.content.content.length === 0 || shouldSkipDeletedEmptyParagraphDecoration) {
118
- return;
118
+ return [];
119
119
  }
120
120
  var isTableCellContent = slice.content.content.some(function () {
121
121
  return slice.content.content.some(function (siblingNode) {
@@ -128,7 +128,7 @@ export var createNodeChangedDecorationWidget = function createNodeChangedDecorat
128
128
  });
129
129
  });
130
130
  if (isTableCellContent) {
131
- return;
131
+ return [];
132
132
  }
133
133
  if (isTableRowContent) {
134
134
  return createChangedRowDecorationWidgets({
@@ -249,14 +249,14 @@ export var createNodeChangedDecorationWidget = function createNodeChangedDecorat
249
249
  }
250
250
  });
251
251
  dom.setAttribute('data-testid', 'show-diff-deleted-decoration');
252
+ var diffId = crypto.randomUUID();
252
253
  var decorations = [];
253
- decorations.push(Decoration.widget(safeInsertPos, dom, _objectSpread({
254
- key: buildDiffDecorationKey({
255
- type: DiffDecorationKey.widget,
256
- isActive: isActive
257
- })
254
+ decorations.push(Decoration.widget(safeInsertPos, dom, buildDiffDecorationSpec(_objectSpread({
255
+ decorationType: 'widget',
256
+ diffId: diffId,
257
+ isActive: isActive
258
258
  }, expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) && {
259
259
  side: -1
260
- })));
260
+ }))));
261
261
  return decorations;
262
262
  };
@@ -1,18 +1,22 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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) { _defineProperty(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; }
4
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
1
5
  /**
2
6
  * Shared prefix for every decoration key produced by the show-diff plugin.
3
7
  * All keys derive from this, so the full set of plugin decorations can be
4
8
  * identified by this single prefix.
5
9
  */
6
- export var DIFF_KEY_PREFIX = 'diff';
10
+ var DIFF_DECORATION_FAMILY = 'diff';
7
11
  /**
8
12
  * The kinds of decoration the show-diff plugin produces. Each value is the
9
13
  * leading segment of the generated key, so a decoration's kind can be matched
10
14
  * with `key?.startsWith(DiffDecorationKey.inline)` etc.
11
15
  */
12
16
  export var DiffDecorationKey = {
13
- inline: "".concat(DIFF_KEY_PREFIX, "-inline"),
14
- block: "".concat(DIFF_KEY_PREFIX, "-block"),
15
- widget: "".concat(DIFF_KEY_PREFIX, "-widget")
17
+ inline: "".concat(DIFF_DECORATION_FAMILY, "-inline"),
18
+ block: "".concat(DIFF_DECORATION_FAMILY, "-block"),
19
+ widget: "".concat(DIFF_DECORATION_FAMILY, "-widget")
16
20
  };
17
21
 
18
22
  /**
@@ -20,7 +24,43 @@ export var DiffDecorationKey = {
20
24
  * (e.g. `diff-inline-active`).
21
25
  */
22
26
  export var buildDiffDecorationKey = function buildDiffDecorationKey(_ref) {
23
- var type = _ref.type,
24
- isActive = _ref.isActive;
25
- return isActive !== undefined ? "".concat(type, "-").concat(isActive ? 'active' : 'inactive') : type;
27
+ var decorationKeyPrefix = _ref.decorationKeyPrefix,
28
+ isActive = _ref.isActive,
29
+ diffId = _ref.diffId;
30
+ if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
31
+ return "".concat(decorationKeyPrefix, "-").concat(diffId, "-").concat(isActive ? 'active' : 'inactive');
32
+ }
33
+ return isActive !== undefined ? "".concat(decorationKeyPrefix, "-").concat(isActive ? 'active' : 'inactive') : decorationKeyPrefix;
34
+ };
35
+ export var buildDiffDecorationSpec = function buildDiffDecorationSpec(_ref2) {
36
+ var decorationType = _ref2.decorationType,
37
+ diffId = _ref2.diffId,
38
+ isActive = _ref2.isActive,
39
+ nodeName = _ref2.nodeName,
40
+ side = _ref2.side;
41
+ return _objectSpread(_objectSpread({
42
+ decorationFamily: DIFF_DECORATION_FAMILY,
43
+ decorationType: decorationType,
44
+ diffId: diffId,
45
+ key: buildDiffDecorationKey({
46
+ decorationKeyPrefix: DiffDecorationKey[decorationType],
47
+ diffId: diffId,
48
+ isActive: isActive
49
+ })
50
+ }, nodeName ? {
51
+ nodeName: nodeName
52
+ } : {}), side !== undefined ? {
53
+ side: side
54
+ } : {});
55
+ };
56
+ export var extractDiffDescriptors = function extractDiffDescriptors(decorations) {
57
+ return decorations.find(undefined, undefined, function (spec) {
58
+ return spec.decorationFamily === 'diff';
59
+ }).map(function (_ref3) {
60
+ var spec = _ref3.spec;
61
+ return {
62
+ id: spec.diffId,
63
+ type: spec.decorationType
64
+ };
65
+ });
26
66
  };
@@ -34,7 +34,8 @@ export var createPlugin = function createPlugin(config, getIntl, api) {
34
34
  }, expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
35
35
  isInverted: false,
36
36
  diffType: 'inline',
37
- hideDeletedDiffs: false
37
+ hideDeletedDiffs: false,
38
+ diffDescriptors: []
38
39
  } : {});
39
40
  },
40
41
  apply: function apply(tr, currentPluginState, oldState, newState) {
@@ -49,21 +50,26 @@ export var createPlugin = function createPlugin(config, getIntl, api) {
49
50
  activeIndex: undefined
50
51
  });
51
52
  // Calculate and store decorations in state
52
- var decorations = calculateDiffDecorations(_objectSpread({
53
- state: newState,
54
- pluginState: newPluginState,
55
- nodeViewSerializer: nodeViewSerializer,
56
- colorScheme: config === null || config === void 0 ? void 0 : config.colorScheme,
57
- intl: getIntl(),
58
- activeIndexPos: newPluginState.activeIndexPos,
59
- api: api
60
- }, expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
61
- isInverted: (_newPluginState = newPluginState) === null || _newPluginState === void 0 ? void 0 : _newPluginState.isInverted,
62
- diffType: (_newPluginState2 = newPluginState) === null || _newPluginState2 === void 0 ? void 0 : _newPluginState2.diffType,
63
- hideDeletedDiffs: (_newPluginState3 = newPluginState) === null || _newPluginState3 === void 0 ? void 0 : _newPluginState3.hideDeletedDiffs
64
- } : {}));
65
- // Update the decorations
53
+ var _calculateDiffDecorat = calculateDiffDecorations(_objectSpread({
54
+ state: newState,
55
+ pluginState: newPluginState,
56
+ nodeViewSerializer: nodeViewSerializer,
57
+ colorScheme: config === null || config === void 0 ? void 0 : config.colorScheme,
58
+ intl: getIntl(),
59
+ activeIndexPos: newPluginState.activeIndexPos,
60
+ api: api
61
+ }, expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
62
+ isInverted: (_newPluginState = newPluginState) === null || _newPluginState === void 0 ? void 0 : _newPluginState.isInverted,
63
+ diffType: (_newPluginState2 = newPluginState) === null || _newPluginState2 === void 0 ? void 0 : _newPluginState2.diffType,
64
+ hideDeletedDiffs: (_newPluginState3 = newPluginState) === null || _newPluginState3 === void 0 ? void 0 : _newPluginState3.hideDeletedDiffs
65
+ } : {})),
66
+ decorations = _calculateDiffDecorat.decorations,
67
+ diffDescriptors = _calculateDiffDecorat.diffDescriptors;
68
+ // Update the decorations and their ids
66
69
  newPluginState.decorations = decorations;
70
+ if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
71
+ newPluginState.diffDescriptors = diffDescriptors;
72
+ }
67
73
  } else if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'HIDE_DIFF') {
68
74
  newPluginState = _objectSpread(_objectSpread(_objectSpread({}, currentPluginState), meta), {}, {
69
75
  decorations: DecorationSet.empty,
@@ -72,7 +78,8 @@ export var createPlugin = function createPlugin(config, getIntl, api) {
72
78
  }, expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
73
79
  isInverted: false,
74
80
  diffType: 'inline',
75
- hideDeletedDiffs: false
81
+ hideDeletedDiffs: false,
82
+ diffDescriptors: []
76
83
  } : {});
77
84
  } 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') {
78
85
  // Update the active index in plugin state and recalculate decorations
@@ -102,20 +109,25 @@ export var createPlugin = function createPlugin(config, getIntl, api) {
102
109
  } : undefined
103
110
  });
104
111
  // Recalculate decorations with the new active index
105
- var updatedDecorations = calculateDiffDecorations(_objectSpread({
106
- state: newState,
107
- pluginState: newPluginState,
108
- nodeViewSerializer: nodeViewSerializer,
109
- colorScheme: config === null || config === void 0 ? void 0 : config.colorScheme,
110
- intl: getIntl(),
111
- activeIndexPos: newPluginState.activeIndexPos,
112
- api: api
113
- }, expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
114
- isInverted: newPluginState.isInverted,
115
- diffType: newPluginState.diffType,
116
- hideDeletedDiffs: newPluginState.hideDeletedDiffs
117
- } : {}));
112
+ var _calculateDiffDecorat2 = 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
+ }, expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
121
+ isInverted: newPluginState.isInverted,
122
+ diffType: newPluginState.diffType,
123
+ hideDeletedDiffs: newPluginState.hideDeletedDiffs
124
+ } : {})),
125
+ updatedDecorations = _calculateDiffDecorat2.decorations,
126
+ updatedDiffDescriptors = _calculateDiffDecorat2.diffDescriptors;
118
127
  newPluginState.decorations = updatedDecorations;
128
+ if (expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
129
+ newPluginState.diffDescriptors = updatedDiffDescriptors;
130
+ }
119
131
  }
120
132
  } else {
121
133
  newPluginState = _objectSpread(_objectSpread({}, currentPluginState), meta);
@@ -61,18 +61,22 @@ export var showDiffPlugin = function showDiffPlugin(_ref) {
61
61
  },
62
62
  getSharedState: function getSharedState(editorState) {
63
63
  if (!editorState) {
64
- return {
64
+ return _objectSpread({
65
65
  isDisplayingChanges: false,
66
66
  activeIndex: undefined
67
- };
67
+ }, expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
68
+ diffDescriptors: []
69
+ } : {});
68
70
  }
69
71
  var pluginState = showDiffPluginKey.getState(editorState);
70
72
  var decorationCount = getScrollableDecorations(pluginState === null || pluginState === void 0 ? void 0 : pluginState.decorations, editorState.doc);
71
- return {
73
+ return _objectSpread({
72
74
  isDisplayingChanges: decorationCount.length > 0,
73
75
  activeIndex: pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex,
74
76
  numberOfChanges: decorationCount.length
75
- };
77
+ }, expValEquals('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
78
+ diffDescriptors: pluginState === null || pluginState === void 0 ? void 0 : pluginState.diffDescriptors
79
+ } : {});
76
80
  }
77
81
  };
78
82
  };
@@ -3,9 +3,13 @@ import type { IntlShape } from 'react-intl';
3
3
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
4
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
5
5
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
- import type { ColorScheme, ShowDiffPlugin } from '../../showDiffPluginType';
6
+ import type { ColorScheme, DiffDescriptor, ShowDiffPlugin } from '../../showDiffPluginType';
7
7
  import type { ShowDiffPluginState } from '../main';
8
8
  import type { NodeViewSerializer } from '../NodeViewSerializer';
9
+ type CalculatedDiffs = {
10
+ decorations: DecorationSet;
11
+ diffDescriptors: DiffDescriptor[];
12
+ };
9
13
  export declare const calculateDiffDecorations: MemoizedFn<({ state, pluginState, nodeViewSerializer, colorScheme, intl, activeIndexPos, api, hideDeletedDiffs, }: {
10
14
  activeIndexPos?: {
11
15
  from: number;
@@ -18,4 +22,5 @@ export declare const calculateDiffDecorations: MemoizedFn<({ state, pluginState,
18
22
  nodeViewSerializer: NodeViewSerializer;
19
23
  pluginState: Omit<ShowDiffPluginState, 'decorations'>;
20
24
  state: EditorState;
21
- }) => DecorationSet>;
25
+ }) => CalculatedDiffs>;
26
+ export {};
@@ -15,4 +15,4 @@ export declare const createInlineChangedDecoration: ({ change, colorScheme, isAc
15
15
  isActive?: boolean;
16
16
  isInserted?: boolean;
17
17
  shouldHideDeleted?: boolean;
18
- }) => Decoration;
18
+ }) => Decoration[];
@@ -20,4 +20,4 @@ export declare const createNodeChangedDecorationWidget: ({ change, doc, nodeView
20
20
  isInserted?: boolean;
21
21
  newDoc: PMNode;
22
22
  nodeViewSerializer: NodeViewSerializer;
23
- }) => Decoration[] | undefined;
23
+ }) => Decoration[];
@@ -1,23 +1,44 @@
1
+ import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
+ import type { DiffDescriptor } from '../../showDiffPluginType';
1
3
  /**
2
4
  * Shared prefix for every decoration key produced by the show-diff plugin.
3
5
  * All keys derive from this, so the full set of plugin decorations can be
4
6
  * identified by this single prefix.
5
7
  */
6
- export declare const DIFF_KEY_PREFIX = "diff";
7
- type DiffDecorationKind = 'inline' | 'block' | 'widget';
8
- type DiffDecorationKeyType = `${typeof DIFF_KEY_PREFIX}-${DiffDecorationKind}`;
8
+ declare const DIFF_DECORATION_FAMILY: "diff";
9
+ export type DiffDecorationSpec = {
10
+ decorationFamily: typeof DIFF_DECORATION_FAMILY;
11
+ decorationType: DiffDescriptor['type'];
12
+ diffId: string;
13
+ key: string;
14
+ nodeName?: string;
15
+ side?: number;
16
+ };
9
17
  /**
10
18
  * The kinds of decoration the show-diff plugin produces. Each value is the
11
19
  * leading segment of the generated key, so a decoration's kind can be matched
12
20
  * with `key?.startsWith(DiffDecorationKey.inline)` etc.
13
21
  */
14
- export declare const DiffDecorationKey: Readonly<Record<DiffDecorationKind, DiffDecorationKeyType>>;
22
+ export declare const DiffDecorationKey: Readonly<{
23
+ block: `${typeof DIFF_DECORATION_FAMILY}-block`;
24
+ inline: `${typeof DIFF_DECORATION_FAMILY}-inline`;
25
+ widget: `${typeof DIFF_DECORATION_FAMILY}-widget`;
26
+ }>;
15
27
  /**
16
28
  * Builds a decoration key in the form `{type}-{active|inactive}`
17
29
  * (e.g. `diff-inline-active`).
18
30
  */
19
- export declare const buildDiffDecorationKey: ({ type, isActive, }: {
31
+ export declare const buildDiffDecorationKey: ({ decorationKeyPrefix, isActive, diffId, }: {
32
+ decorationKeyPrefix: (typeof DiffDecorationKey)[DiffDescriptor["type"]];
33
+ diffId?: string;
20
34
  isActive?: boolean;
21
- type: DiffDecorationKeyType;
22
35
  }) => string;
36
+ export declare const buildDiffDecorationSpec: ({ decorationType, diffId, isActive, nodeName, side, }: {
37
+ decorationType: DiffDescriptor["type"];
38
+ diffId: string;
39
+ isActive?: boolean;
40
+ nodeName?: string;
41
+ side?: number;
42
+ }) => DiffDecorationSpec;
43
+ export declare const extractDiffDescriptors: (decorations: DecorationSet) => DiffDescriptor[];
23
44
  export {};
@@ -5,7 +5,7 @@ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
5
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
6
6
  import { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
7
7
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
- import type { DiffParams, DiffType, ShowDiffPlugin } from '../showDiffPluginType';
8
+ import type { DiffDescriptor, DiffParams, DiffType, ShowDiffPlugin } from '../showDiffPluginType';
9
9
  export declare const showDiffPluginKey: PluginKey<ShowDiffPluginState>;
10
10
  export type ShowDiffPluginState = {
11
11
  activeIndex?: number;
@@ -14,6 +14,11 @@ export type ShowDiffPluginState = {
14
14
  to: number;
15
15
  };
16
16
  decorations: DecorationSet;
17
+ /**
18
+ * The diff descriptors of the diff decorations currently being displayed.
19
+ * Only set when `platform_editor_diff_plugin_extended` is on.
20
+ */
21
+ diffDescriptors?: DiffDescriptor[];
17
22
  diffType?: DiffType;
18
23
  hideDeletedDiffs?: boolean;
19
24
  isDisplayingChanges: boolean;
@@ -8,6 +8,10 @@ import type { Node } from '@atlaskit/editor-prosemirror/model';
8
8
  import type { Step } from '@atlaskit/editor-prosemirror/transform';
9
9
  export type ColorScheme = 'standard' | 'traditional';
10
10
  export type DiffType = 'inline' | 'block' | 'step';
11
+ export type DiffDescriptor = {
12
+ id: string;
13
+ type: 'inline' | 'block' | 'widget';
14
+ };
11
15
  export type DiffParams = {
12
16
  /**
13
17
  * Color scheme to use for displaying diffs.
@@ -55,6 +59,11 @@ export type ShowDiffPlugin = NextEditorPlugin<'showDiff', {
55
59
  * The index of the current diff being viewed.
56
60
  */
57
61
  activeIndex?: number;
62
+ /**
63
+ * The diff descriptors of the diff decorations currently being displayed.
64
+ * Only set when `platform_editor_diff_plugin_extended` is on.
65
+ */
66
+ diffDescriptors?: DiffDescriptor[];
58
67
  /**
59
68
  * Whether the show diff feature is currently displaying changes.
60
69
  * Defaults to false.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-show-diff",
3
- "version": "9.1.1",
3
+ "version": "10.0.0",
4
4
  "description": "ShowDiff plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -17,42 +17,34 @@
17
17
  "module": "dist/esm/index.js",
18
18
  "module:es2019": "dist/es2019/index.js",
19
19
  "types": "dist/types/index.d.ts",
20
- "typesVersions": {
21
- ">=4.5 <4.9": {
22
- "*": [
23
- "dist/types-ts4.5/*",
24
- "dist/types-ts4.5/index.d.ts"
25
- ]
26
- }
27
- },
28
20
  "sideEffects": false,
29
21
  "atlaskit:src": "src/index.ts",
30
22
  "dependencies": {
31
- "@atlaskit/adf-schema": "^54.0.0",
32
- "@atlaskit/custom-steps": "^0.17.0",
33
- "@atlaskit/editor-plugin-analytics": "^11.0.0",
34
- "@atlaskit/editor-plugin-expand": "^12.0.0",
35
- "@atlaskit/editor-plugin-user-intent": "^9.1.0",
36
- "@atlaskit/editor-prosemirror": "^7.3.0",
37
- "@atlaskit/editor-tables": "^2.10.0",
38
- "@atlaskit/platform-feature-flags": "^1.1.0",
39
- "@atlaskit/tmp-editor-statsig": "^102.0.0",
40
- "@atlaskit/tokens": "^13.4.0",
23
+ "@atlaskit/adf-schema": "^55.0.0",
24
+ "@atlaskit/custom-steps": "^1.0.0",
25
+ "@atlaskit/editor-plugin-analytics": "^12.0.0",
26
+ "@atlaskit/editor-plugin-expand": "^13.0.0",
27
+ "@atlaskit/editor-plugin-user-intent": "^10.0.0",
28
+ "@atlaskit/editor-prosemirror": "^8.0.0",
29
+ "@atlaskit/editor-tables": "^3.0.0",
30
+ "@atlaskit/platform-feature-flags": "^2.0.0",
31
+ "@atlaskit/tmp-editor-statsig": "^104.0.0",
32
+ "@atlaskit/tokens": "^14.0.0",
41
33
  "@babel/runtime": "^7.0.0",
42
34
  "lodash": "^4.17.21",
43
35
  "memoize-one": "^6.0.0",
44
36
  "prosemirror-changeset": "^2.3.1"
45
37
  },
46
38
  "devDependencies": {
47
- "@atlaskit/adf-utils": "^19.33.0",
48
- "@atlaskit/button": "^23.11.0",
49
- "@atlaskit/css": "^0.19.0",
50
- "@atlaskit/editor-core": "^220.4.0",
51
- "@atlaskit/editor-json-transformer": "^8.33.0",
52
- "@atlaskit/form": "^15.5.0",
53
- "@atlaskit/primitives": "^19.0.0",
54
- "@atlaskit/section-message": "^8.13.0",
55
- "@atlaskit/textarea": "^8.3.0",
39
+ "@atlaskit/adf-utils": "^20.0.0",
40
+ "@atlaskit/button": "^24.0.0",
41
+ "@atlaskit/css": "^1.0.0",
42
+ "@atlaskit/editor-core": "^221.0.0",
43
+ "@atlaskit/editor-json-transformer": "^9.0.0",
44
+ "@atlaskit/form": "^16.0.0",
45
+ "@atlaskit/primitives": "^20.0.0",
46
+ "@atlaskit/section-message": "^9.0.0",
47
+ "@atlaskit/textarea": "^9.0.0",
56
48
  "@atlassian/confluence-presets": "workspace:^",
57
49
  "@atlassian/content-reconciliation": "^0.1.3506",
58
50
  "@atlassian/structured-docs-types": "workspace:^",
@@ -60,7 +52,7 @@
60
52
  "react-intl": "^6.6.2"
61
53
  },
62
54
  "peerDependencies": {
63
- "@atlaskit/editor-common": "^115.15.0",
55
+ "@atlaskit/editor-common": "^116.0.0",
64
56
  "react": "^18.2.0"
65
57
  },
66
58
  "techstack": {
@@ -4,12 +4,5 @@
4
4
  "module": "../dist/esm/entry-points/show-diff-plugin.js",
5
5
  "module:es2019": "../dist/es2019/entry-points/show-diff-plugin.js",
6
6
  "sideEffects": false,
7
- "types": "../dist/types/entry-points/show-diff-plugin.d.ts",
8
- "typesVersions": {
9
- ">=4.5 <5.9": {
10
- "*": [
11
- "../dist/types-ts4.5/entry-points/show-diff-plugin.d.ts"
12
- ]
13
- }
14
- }
7
+ "types": "../dist/types/entry-points/show-diff-plugin.d.ts"
15
8
  }
@@ -4,12 +4,5 @@
4
4
  "module": "../dist/esm/entry-points/show-diff-plugin-type.js",
5
5
  "module:es2019": "../dist/es2019/entry-points/show-diff-plugin-type.js",
6
6
  "sideEffects": false,
7
- "types": "../dist/types/entry-points/show-diff-plugin-type.d.ts",
8
- "typesVersions": {
9
- ">=4.5 <5.9": {
10
- "*": [
11
- "../dist/types-ts4.5/entry-points/show-diff-plugin-type.d.ts"
12
- ]
13
- }
14
- }
7
+ "types": "../dist/types/entry-points/show-diff-plugin-type.d.ts"
15
8
  }
@@ -1 +0,0 @@
1
- export type { DiffParams, PMDiffParams, ShowDiffPlugin } from '../showDiffPluginType';
@@ -1 +0,0 @@
1
- export { showDiffPlugin } from '../showDiffPlugin';
@@ -1,2 +0,0 @@
1
- export { showDiffPlugin } from './showDiffPlugin';
2
- export type { DiffParams, PMDiffParams, ShowDiffPlugin } from './showDiffPluginType';