@atlaskit/editor-plugin-show-diff 4.0.15 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @atlaskit/editor-plugin-show-diff
2
2
 
3
+ ## 4.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`ec61e21a60034`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ec61e21a60034) -
8
+ Adds new commands to scroll to each diff change in the UI.
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
3
14
  ## 4.0.15
4
15
 
5
16
  ### Patch Changes
@@ -74,7 +74,8 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref)
74
74
  pluginState = _ref.pluginState,
75
75
  nodeViewSerializer = _ref.nodeViewSerializer,
76
76
  colourScheme = _ref.colourScheme,
77
- intl = _ref.intl;
77
+ intl = _ref.intl,
78
+ activeIndexPos = _ref.activeIndexPos;
78
79
  var originalDoc = pluginState.originalDoc,
79
80
  steps = pluginState.steps;
80
81
  if (!originalDoc || !pluginState.isDisplayingChanges) {
@@ -115,18 +116,21 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref)
115
116
  var optimizedChanges = optimizeChanges(changes);
116
117
  var decorations = [];
117
118
  optimizedChanges.forEach(function (change) {
119
+ var isActive = activeIndexPos && change.fromB >= activeIndexPos.from && change.toB <= activeIndexPos.to;
118
120
  if (change.inserted.length > 0) {
119
- decorations.push((0, _decorations.createInlineChangedDecoration)(change, colourScheme));
121
+ decorations.push((0, _decorations.createInlineChangedDecoration)(change, colourScheme, isActive));
120
122
  decorations.push.apply(decorations, (0, _toConsumableArray2.default)(calculateNodesForBlockDecoration(tr.doc, change.fromB, change.toB, colourScheme)));
121
123
  }
122
124
  if (change.deleted.length > 0) {
125
+ var _isActive = activeIndexPos && change.fromB >= activeIndexPos.from && change.toB <= activeIndexPos.to;
123
126
  var decoration = (0, _decorations.createDeletedContentDecoration)({
124
127
  change: change,
125
128
  doc: originalDoc,
126
129
  nodeViewSerializer: nodeViewSerializer,
127
130
  colourScheme: colourScheme,
128
131
  newDoc: tr.doc,
129
- intl: intl
132
+ intl: intl,
133
+ isActive: _isActive
130
134
  });
131
135
  if (decoration) {
132
136
  decorations.push.apply(decorations, (0, _toConsumableArray2.default)(decoration));
@@ -134,7 +138,8 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref)
134
138
  }
135
139
  });
136
140
  (0, _markDecorations.getMarkChangeRanges)(steps).forEach(function (change) {
137
- decorations.push((0, _decorations.createInlineChangedDecoration)(change, colourScheme));
141
+ var isActive = activeIndexPos && change.fromB >= activeIndexPos.from && change.toB <= activeIndexPos.to;
142
+ decorations.push((0, _decorations.createInlineChangedDecoration)(change, colourScheme, isActive));
138
143
  });
139
144
  (0, _attributeDecorations.getAttrChangeRanges)(tr.doc, attrSteps).forEach(function (change) {
140
145
  decorations.push.apply(decorations, (0, _toConsumableArray2.default)(calculateNodesForBlockDecoration(tr.doc, change.fromB, change.toB, colourScheme)));
@@ -150,13 +155,15 @@ function (_ref2, _ref3) {
150
155
  pluginState = _ref4$.pluginState,
151
156
  state = _ref4$.state,
152
157
  colourScheme = _ref4$.colourScheme,
153
- intl = _ref4$.intl;
158
+ intl = _ref4$.intl,
159
+ activeIndexPos = _ref4$.activeIndexPos;
154
160
  var _ref5 = (0, _slicedToArray2.default)(_ref3, 1),
155
161
  _ref5$ = _ref5[0],
156
162
  lastPluginState = _ref5$.pluginState,
157
163
  lastState = _ref5$.state,
158
164
  lastColourScheme = _ref5$.colourScheme,
159
- lastIntl = _ref5$.intl;
165
+ lastIntl = _ref5$.intl,
166
+ lastActiveIndexPos = _ref5$.activeIndexPos;
160
167
  var originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
161
- return (_ref6 = originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && colourScheme === lastColourScheme && intl.locale === lastIntl.locale) !== null && _ref6 !== void 0 ? _ref6 : false;
168
+ return (_ref6 = originalDocIsSame && (0, _isEqual.default)(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && colourScheme === lastColourScheme && intl.locale === lastIntl.locale && (0, _isEqual.default)(activeIndexPos, lastActiveIndexPos)) !== null && _ref6 !== void 0 ? _ref6 : false;
162
169
  });
@@ -18,6 +18,13 @@ var editingStyle = (0, _lazyNodeView.convertToInlineCss)({
18
18
  textDecorationThickness: "var(--ds-space-025, 2px)",
19
19
  textDecorationColor: "var(--ds-border-accent-purple, #AF59E1)"
20
20
  });
21
+ var editingStyleActive = (0, _lazyNodeView.convertToInlineCss)({
22
+ background: "var(--ds-background-accent-purple-subtler, #EED7FC)",
23
+ textDecoration: 'underline',
24
+ textDecorationStyle: 'dotted',
25
+ textDecorationThickness: "var(--ds-space-025, 2px)",
26
+ textDecorationColor: "var(--ds-text-accent-purple, #803FA5)"
27
+ });
21
28
  var traditionalInsertStyle = (0, _lazyNodeView.convertToInlineCss)({
22
29
  background: "var(--ds-background-accent-green-subtlest, #DCFFF1)",
23
30
  textDecoration: 'underline',
@@ -25,6 +32,13 @@ var traditionalInsertStyle = (0, _lazyNodeView.convertToInlineCss)({
25
32
  textDecorationThickness: "var(--ds-space-025, 2px)",
26
33
  textDecorationColor: "var(--ds-border-accent-green, #22A06B)"
27
34
  });
35
+ var traditionalInsertStyleActive = (0, _lazyNodeView.convertToInlineCss)({
36
+ background: "var(--ds-background-accent-green-subtler, #BAF3DB)",
37
+ textDecoration: 'underline',
38
+ textDecorationStyle: 'solid',
39
+ textDecorationThickness: "var(--ds-space-025, 2px)",
40
+ textDecorationColor: "var(--ds-text-accent-green, #216E4E)"
41
+ });
28
42
 
29
43
  /**
30
44
  * Inline decoration used for insertions as the content already exists in the document
@@ -33,8 +47,15 @@ var traditionalInsertStyle = (0, _lazyNodeView.convertToInlineCss)({
33
47
  * @returns Prosemirror inline decoration
34
48
  */
35
49
  var createInlineChangedDecoration = exports.createInlineChangedDecoration = function createInlineChangedDecoration(change, colourScheme) {
50
+ var isActive = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
51
+ var style;
52
+ if (colourScheme === 'traditional') {
53
+ style = isActive ? traditionalInsertStyleActive : traditionalInsertStyle;
54
+ } else {
55
+ style = isActive ? editingStyleActive : editingStyle;
56
+ }
36
57
  return _view.Decoration.inline(change.fromB, change.toB, {
37
- style: colourScheme === 'traditional' ? traditionalInsertStyle : editingStyle,
58
+ style: style,
38
59
  'data-testid': 'show-diff-changed-decoration'
39
60
  }, {});
40
61
  };
@@ -112,12 +133,26 @@ var deletedContentStyle = (0, _lazyNodeView.convertToInlineCss)({
112
133
  position: 'relative',
113
134
  opacity: 0.6
114
135
  });
136
+ var deletedContentStyleActive = (0, _lazyNodeView.convertToInlineCss)({
137
+ color: "var(--ds-text, #292A2E)",
138
+ textDecoration: 'line-through',
139
+ textDecorationColor: "var(--ds-text-accent-gray, #505258)",
140
+ position: 'relative',
141
+ opacity: 1
142
+ });
115
143
  var deletedContentStyleNew = (0, _lazyNodeView.convertToInlineCss)({
116
144
  color: "var(--ds-text-accent-gray, #505258)",
117
145
  textDecoration: 'line-through',
118
146
  position: 'relative',
119
147
  opacity: 0.8
120
148
  });
149
+ var deletedContentStyleNewActive = (0, _lazyNodeView.convertToInlineCss)({
150
+ color: "var(--ds-text, #292A2E)",
151
+ textDecoration: 'line-through',
152
+ textDecorationColor: "var(--ds-text-accent-gray, #505258)",
153
+ position: 'relative',
154
+ opacity: 1
155
+ });
121
156
  var deletedContentStyleUnbounded = (0, _lazyNodeView.convertToInlineCss)({
122
157
  position: 'absolute',
123
158
  top: '50%',
@@ -146,7 +181,14 @@ var getDeletedContentStyleUnbounded = exports.getDeletedContentStyleUnbounded =
146
181
  return colourScheme === 'traditional' ? deletedTraditionalContentStyleUnbounded : deletedContentStyleUnbounded;
147
182
  };
148
183
  var getDeletedContentStyle = exports.getDeletedContentStyle = function getDeletedContentStyle(colourScheme) {
149
- return colourScheme === 'traditional' ? deletedTraditionalContentStyle : (0, _expValEquals.expValEquals)('platform_editor_enghealth_a11y_jan_fixes', 'isEnabled', true) ? deletedContentStyleNew : deletedContentStyle;
184
+ var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
185
+ if (colourScheme === 'traditional') {
186
+ return deletedTraditionalContentStyle;
187
+ }
188
+ if (isActive) {
189
+ return (0, _expValEquals.expValEquals)('platform_editor_enghealth_a11y_jan_fixes', 'isEnabled', true) ? deletedContentStyleNewActive : deletedContentStyleActive;
190
+ }
191
+ return (0, _expValEquals.expValEquals)('platform_editor_enghealth_a11y_jan_fixes', 'isEnabled', true) ? deletedContentStyleNew : deletedContentStyle;
150
192
  };
151
193
  var getNodeClass = function getNodeClass(name) {
152
194
  switch (name) {
@@ -176,7 +218,9 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
176
218
  nodeViewSerializer = _ref.nodeViewSerializer,
177
219
  colourScheme = _ref.colourScheme,
178
220
  newDoc = _ref.newDoc,
179
- intl = _ref.intl;
221
+ intl = _ref.intl,
222
+ _ref$isActive = _ref.isActive,
223
+ isActive = _ref$isActive === void 0 ? false : _ref$isActive;
180
224
  var slice = doc.slice(change.fromA, change.toA);
181
225
  if (slice.content.content.length === 0) {
182
226
  return;
@@ -212,7 +256,6 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
212
256
  * and if it's the first or last content, we go in however many the sliced Open
213
257
  * or sliced End depth is and match only the entire node.
214
258
  */
215
-
216
259
  slice.content.forEach(function (node) {
217
260
  // Create a wrapper for each node with strikethrough
218
261
  var createWrapperWithStrikethrough = function createWrapperWithStrikethrough() {
@@ -221,7 +264,7 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
221
264
  position: 'relative',
222
265
  width: 'fit-content'
223
266
  });
224
- wrapper.setAttribute('style', "".concat(baseStyle).concat(getDeletedContentStyle(colourScheme)));
267
+ wrapper.setAttribute('style', "".concat(baseStyle).concat(getDeletedContentStyle(colourScheme, isActive)));
225
268
  var strikethrough = document.createElement('span');
226
269
  strikethrough.setAttribute('style', getDeletedContentStyleUnbounded(colourScheme));
227
270
  wrapper.append(strikethrough);
@@ -312,7 +355,7 @@ var createDeletedContentDecoration = exports.createDeletedContentDecoration = fu
312
355
  } else {
313
356
  var fallbackNode = fallbackSerialization();
314
357
  if (fallbackNode) {
315
- var _wrapper2 = (0, _deletedBlocksHandler.createDeletedStyleWrapperWithoutOpacity)(colourScheme);
358
+ var _wrapper2 = (0, _deletedBlocksHandler.createDeletedStyleWrapperWithoutOpacity)(colourScheme, isActive);
316
359
  _wrapper2.append(fallbackNode);
317
360
  dom.append(_wrapper2);
318
361
  }
@@ -163,9 +163,9 @@ var createBlockNodeWrapper = exports.createBlockNodeWrapper = function createBlo
163
163
  /**
164
164
  * Wraps content with deleted styling without opacity (for use when content is a direct child of dom)
165
165
  */
166
- var createDeletedStyleWrapperWithoutOpacity = exports.createDeletedStyleWrapperWithoutOpacity = function createDeletedStyleWrapperWithoutOpacity(colourScheme) {
166
+ var createDeletedStyleWrapperWithoutOpacity = exports.createDeletedStyleWrapperWithoutOpacity = function createDeletedStyleWrapperWithoutOpacity(colourScheme, isActive) {
167
167
  var wrapper = document.createElement('span');
168
- wrapper.setAttribute('style', (0, _decorations.getDeletedContentStyle)(colourScheme));
168
+ wrapper.setAttribute('style', (0, _decorations.getDeletedContentStyle)(colourScheme, isActive));
169
169
  return wrapper;
170
170
  };
171
171
 
@@ -11,6 +11,7 @@ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
11
  var _state2 = require("@atlaskit/editor-prosemirror/state");
12
12
  var _transform = require("@atlaskit/editor-prosemirror/transform");
13
13
  var _view = require("@atlaskit/editor-prosemirror/view");
14
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
14
15
  var _calculateDiffDecorations = require("./calculateDiffDecorations");
15
16
  var _NodeViewSerializer = require("./NodeViewSerializer");
16
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; }
@@ -25,6 +26,40 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl)
25
26
  };
26
27
  return new _safePlugin.SafePlugin({
27
28
  key: showDiffPluginKey,
29
+ appendTransaction: function appendTransaction(transactions, oldState, newState) {
30
+ var _pluginState$activeIn;
31
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_show_diff_scroll_navigation')) {
32
+ return;
33
+ }
34
+ // Check if any transaction contains scroll actions
35
+ var scrollTransaction = transactions.find(function (tr) {
36
+ var _tr$getMeta, _tr$getMeta2;
37
+ return ((_tr$getMeta = tr.getMeta(showDiffPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.action) === 'SCROLL_TO_NEXT' || ((_tr$getMeta2 = tr.getMeta(showDiffPluginKey)) === null || _tr$getMeta2 === void 0 ? void 0 : _tr$getMeta2.action) === 'SCROLL_TO_PREVIOUS';
38
+ });
39
+ if (!scrollTransaction) {
40
+ return;
41
+ }
42
+ var pluginState = showDiffPluginKey.getState(newState);
43
+ if (!pluginState || pluginState.decorations.find().length === 0) {
44
+ return;
45
+ }
46
+ var decorations = pluginState.decorations.find();
47
+ var decoration = decorations[(_pluginState$activeIn = pluginState.activeIndex) !== null && _pluginState$activeIn !== void 0 ? _pluginState$activeIn : 0];
48
+ if (!decoration) {
49
+ return;
50
+ }
51
+ var from = decoration.from,
52
+ to = decoration.to;
53
+ var $pos = newState.doc.resolve(from);
54
+ var isNodeSelection = $pos.nodeAfter && $pos.nodeAfter.nodeSize === to - from && !$pos.nodeAfter.isInline;
55
+ var tr = newState.tr;
56
+ if (isNodeSelection) {
57
+ tr.setSelection(_state2.NodeSelection.create(newState.doc, from));
58
+ } else {
59
+ tr.setSelection(_state2.TextSelection.create(newState.doc, from));
60
+ }
61
+ return tr.scrollIntoView();
62
+ },
28
63
  state: {
29
64
  init: function init(_, _state) {
30
65
  // We do initial setup after we setup the editor view
@@ -42,7 +77,8 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl)
42
77
  if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'SHOW_DIFF') {
43
78
  // Update the plugin state with the new metadata
44
79
  newPluginState = _objectSpread(_objectSpread(_objectSpread({}, currentPluginState), meta), {}, {
45
- isDisplayingChanges: true
80
+ isDisplayingChanges: true,
81
+ activeIndex: 0
46
82
  });
47
83
  // Calculate and store decorations in state
48
84
  var decorations = (0, _calculateDiffDecorations.calculateDiffDecorations)({
@@ -50,15 +86,47 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl)
50
86
  pluginState: newPluginState,
51
87
  nodeViewSerializer: nodeViewSerializer,
52
88
  colourScheme: config === null || config === void 0 ? void 0 : config.colourScheme,
53
- intl: getIntl()
89
+ intl: getIntl(),
90
+ activeIndexPos: (0, _platformFeatureFlags.fg)('platform_editor_show_diff_scroll_navigation') ? newPluginState.activeIndexPos : undefined
54
91
  });
55
92
  // Update the decorations
56
93
  newPluginState.decorations = decorations;
57
94
  } else if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'HIDE_DIFF') {
58
95
  newPluginState = _objectSpread(_objectSpread(_objectSpread({}, currentPluginState), meta), {}, {
59
96
  decorations: _view.DecorationSet.empty,
60
- isDisplayingChanges: false
97
+ isDisplayingChanges: false,
98
+ activeIndex: undefined
61
99
  });
100
+ } 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') && (0, _platformFeatureFlags.fg)('platform_editor_show_diff_scroll_navigation')) {
101
+ // Update the active index in plugin state and recalculate decorations
102
+ var _decorations = currentPluginState.decorations.find();
103
+ if (_decorations.length > 0) {
104
+ var _currentPluginState$a;
105
+ var nextIndex = (_currentPluginState$a = currentPluginState.activeIndex) !== null && _currentPluginState$a !== void 0 ? _currentPluginState$a : 0;
106
+ if (meta.action === 'SCROLL_TO_NEXT') {
107
+ nextIndex = (nextIndex + 1) % _decorations.length;
108
+ } else {
109
+ nextIndex = (nextIndex - 1 + _decorations.length) % _decorations.length;
110
+ }
111
+ var activeDecoration = _decorations[nextIndex];
112
+ newPluginState = _objectSpread(_objectSpread({}, currentPluginState), {}, {
113
+ activeIndex: nextIndex,
114
+ activeIndexPos: activeDecoration ? {
115
+ from: activeDecoration.from,
116
+ to: activeDecoration.to
117
+ } : undefined
118
+ });
119
+ // Recalculate decorations with the new active index
120
+ var updatedDecorations = (0, _calculateDiffDecorations.calculateDiffDecorations)({
121
+ state: newState,
122
+ pluginState: newPluginState,
123
+ nodeViewSerializer: nodeViewSerializer,
124
+ colourScheme: config === null || config === void 0 ? void 0 : config.colourScheme,
125
+ intl: getIntl(),
126
+ activeIndexPos: newPluginState.activeIndexPos
127
+ });
128
+ newPluginState.decorations = updatedDecorations;
129
+ }
62
130
  } else {
63
131
  newPluginState = _objectSpread(_objectSpread({}, currentPluginState), meta);
64
132
  }
@@ -29,13 +29,25 @@ var showDiffPlugin = exports.showDiffPlugin = function showDiffPlugin(_ref) {
29
29
  steps: [],
30
30
  action: 'HIDE_DIFF'
31
31
  });
32
+ },
33
+ scrollToNext: function scrollToNext(_ref4) {
34
+ var tr = _ref4.tr;
35
+ return tr.setMeta(_main.showDiffPluginKey, {
36
+ action: 'SCROLL_TO_NEXT'
37
+ });
38
+ },
39
+ scrollToPrevious: function scrollToPrevious(_ref5) {
40
+ var tr = _ref5.tr;
41
+ return tr.setMeta(_main.showDiffPluginKey, {
42
+ action: 'SCROLL_TO_PREVIOUS'
43
+ });
32
44
  }
33
45
  },
34
46
  pmPlugins: function pmPlugins() {
35
47
  return [{
36
48
  name: 'showDiffPlugin',
37
- plugin: function plugin(_ref4) {
38
- var getIntl = _ref4.getIntl;
49
+ plugin: function plugin(_ref6) {
50
+ var getIntl = _ref6.getIntl;
39
51
  return (0, _main.createPlugin)(config, getIntl);
40
52
  }
41
53
  }];
@@ -44,13 +56,16 @@ var showDiffPlugin = exports.showDiffPlugin = function showDiffPlugin(_ref) {
44
56
  var _pluginState$decorati;
45
57
  if (!editorState) {
46
58
  return {
47
- isDisplayingChanges: false
59
+ isDisplayingChanges: false,
60
+ activeIndex: undefined
48
61
  };
49
62
  }
50
63
  var pluginState = _main.showDiffPluginKey.getState(editorState);
51
64
  var decorationCount = (pluginState === null || pluginState === void 0 || (_pluginState$decorati = pluginState.decorations) === null || _pluginState$decorati === void 0 ? void 0 : _pluginState$decorati.find()) || [];
52
65
  return {
53
- isDisplayingChanges: decorationCount.length > 0
66
+ isDisplayingChanges: decorationCount.length > 0,
67
+ activeIndex: pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex,
68
+ numberOfChanges: decorationCount.length
54
69
  };
55
70
  }
56
71
  };
@@ -64,7 +64,8 @@ const calculateDiffDecorationsInner = ({
64
64
  pluginState,
65
65
  nodeViewSerializer,
66
66
  colourScheme,
67
- intl
67
+ intl,
68
+ activeIndexPos
68
69
  }) => {
69
70
  const {
70
71
  originalDoc,
@@ -101,18 +102,21 @@ const calculateDiffDecorationsInner = ({
101
102
  const optimizedChanges = optimizeChanges(changes);
102
103
  const decorations = [];
103
104
  optimizedChanges.forEach(change => {
105
+ const isActive = activeIndexPos && change.fromB >= activeIndexPos.from && change.toB <= activeIndexPos.to;
104
106
  if (change.inserted.length > 0) {
105
- decorations.push(createInlineChangedDecoration(change, colourScheme));
107
+ decorations.push(createInlineChangedDecoration(change, colourScheme, isActive));
106
108
  decorations.push(...calculateNodesForBlockDecoration(tr.doc, change.fromB, change.toB, colourScheme));
107
109
  }
108
110
  if (change.deleted.length > 0) {
111
+ const isActive = activeIndexPos && change.fromB >= activeIndexPos.from && change.toB <= activeIndexPos.to;
109
112
  const decoration = createDeletedContentDecoration({
110
113
  change,
111
114
  doc: originalDoc,
112
115
  nodeViewSerializer,
113
116
  colourScheme,
114
117
  newDoc: tr.doc,
115
- intl
118
+ intl,
119
+ isActive
116
120
  });
117
121
  if (decoration) {
118
122
  decorations.push(...decoration);
@@ -120,7 +124,8 @@ const calculateDiffDecorationsInner = ({
120
124
  }
121
125
  });
122
126
  getMarkChangeRanges(steps).forEach(change => {
123
- decorations.push(createInlineChangedDecoration(change, colourScheme));
127
+ const isActive = activeIndexPos && change.fromB >= activeIndexPos.from && change.toB <= activeIndexPos.to;
128
+ decorations.push(createInlineChangedDecoration(change, colourScheme, isActive));
124
129
  });
125
130
  getAttrChangeRanges(tr.doc, attrSteps).forEach(change => {
126
131
  decorations.push(...calculateNodesForBlockDecoration(tr.doc, change.fromB, change.toB, colourScheme));
@@ -133,14 +138,16 @@ export const calculateDiffDecorations = memoizeOne(calculateDiffDecorationsInner
133
138
  pluginState,
134
139
  state,
135
140
  colourScheme,
136
- intl
141
+ intl,
142
+ activeIndexPos
137
143
  }], [{
138
144
  pluginState: lastPluginState,
139
145
  state: lastState,
140
146
  colourScheme: lastColourScheme,
141
- intl: lastIntl
147
+ intl: lastIntl,
148
+ activeIndexPos: lastActiveIndexPos
142
149
  }]) => {
143
150
  var _ref;
144
151
  const originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
145
- return (_ref = originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && colourScheme === lastColourScheme && intl.locale === lastIntl.locale) !== null && _ref !== void 0 ? _ref : false;
152
+ return (_ref = originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && colourScheme === lastColourScheme && intl.locale === lastIntl.locale && isEqual(activeIndexPos, lastActiveIndexPos)) !== null && _ref !== void 0 ? _ref : false;
146
153
  });
@@ -12,6 +12,13 @@ const editingStyle = convertToInlineCss({
12
12
  textDecorationThickness: "var(--ds-space-025, 2px)",
13
13
  textDecorationColor: "var(--ds-border-accent-purple, #AF59E1)"
14
14
  });
15
+ const editingStyleActive = convertToInlineCss({
16
+ background: "var(--ds-background-accent-purple-subtler, #EED7FC)",
17
+ textDecoration: 'underline',
18
+ textDecorationStyle: 'dotted',
19
+ textDecorationThickness: "var(--ds-space-025, 2px)",
20
+ textDecorationColor: "var(--ds-text-accent-purple, #803FA5)"
21
+ });
15
22
  const traditionalInsertStyle = convertToInlineCss({
16
23
  background: "var(--ds-background-accent-green-subtlest, #DCFFF1)",
17
24
  textDecoration: 'underline',
@@ -19,6 +26,13 @@ const traditionalInsertStyle = convertToInlineCss({
19
26
  textDecorationThickness: "var(--ds-space-025, 2px)",
20
27
  textDecorationColor: "var(--ds-border-accent-green, #22A06B)"
21
28
  });
29
+ const traditionalInsertStyleActive = convertToInlineCss({
30
+ background: "var(--ds-background-accent-green-subtler, #BAF3DB)",
31
+ textDecoration: 'underline',
32
+ textDecorationStyle: 'solid',
33
+ textDecorationThickness: "var(--ds-space-025, 2px)",
34
+ textDecorationColor: "var(--ds-text-accent-green, #216E4E)"
35
+ });
22
36
 
23
37
  /**
24
38
  * Inline decoration used for insertions as the content already exists in the document
@@ -26,10 +40,18 @@ const traditionalInsertStyle = convertToInlineCss({
26
40
  * @param change Changeset "change" containing information about the change content + range
27
41
  * @returns Prosemirror inline decoration
28
42
  */
29
- export const createInlineChangedDecoration = (change, colourScheme) => Decoration.inline(change.fromB, change.toB, {
30
- style: colourScheme === 'traditional' ? traditionalInsertStyle : editingStyle,
31
- 'data-testid': 'show-diff-changed-decoration'
32
- }, {});
43
+ export const createInlineChangedDecoration = (change, colourScheme, isActive = false) => {
44
+ let style;
45
+ if (colourScheme === 'traditional') {
46
+ style = isActive ? traditionalInsertStyleActive : traditionalInsertStyle;
47
+ } else {
48
+ style = isActive ? editingStyleActive : editingStyle;
49
+ }
50
+ return Decoration.inline(change.fromB, change.toB, {
51
+ style,
52
+ 'data-testid': 'show-diff-changed-decoration'
53
+ }, {});
54
+ };
33
55
  const getEditorStyleNode = (nodeName, colourScheme) => {
34
56
  switch (nodeName) {
35
57
  case 'blockquote':
@@ -104,12 +126,26 @@ const deletedContentStyle = convertToInlineCss({
104
126
  position: 'relative',
105
127
  opacity: 0.6
106
128
  });
129
+ const deletedContentStyleActive = convertToInlineCss({
130
+ color: "var(--ds-text, #292A2E)",
131
+ textDecoration: 'line-through',
132
+ textDecorationColor: "var(--ds-text-accent-gray, #505258)",
133
+ position: 'relative',
134
+ opacity: 1
135
+ });
107
136
  const deletedContentStyleNew = convertToInlineCss({
108
137
  color: "var(--ds-text-accent-gray, #505258)",
109
138
  textDecoration: 'line-through',
110
139
  position: 'relative',
111
140
  opacity: 0.8
112
141
  });
142
+ const deletedContentStyleNewActive = convertToInlineCss({
143
+ color: "var(--ds-text, #292A2E)",
144
+ textDecoration: 'line-through',
145
+ textDecorationColor: "var(--ds-text-accent-gray, #505258)",
146
+ position: 'relative',
147
+ opacity: 1
148
+ });
113
149
  const deletedContentStyleUnbounded = convertToInlineCss({
114
150
  position: 'absolute',
115
151
  top: '50%',
@@ -135,7 +171,15 @@ const deletedTraditionalContentStyleUnbounded = convertToInlineCss({
135
171
  zIndex: 1
136
172
  });
137
173
  export const getDeletedContentStyleUnbounded = colourScheme => colourScheme === 'traditional' ? deletedTraditionalContentStyleUnbounded : deletedContentStyleUnbounded;
138
- export const getDeletedContentStyle = colourScheme => colourScheme === 'traditional' ? deletedTraditionalContentStyle : expValEquals('platform_editor_enghealth_a11y_jan_fixes', 'isEnabled', true) ? deletedContentStyleNew : deletedContentStyle;
174
+ export const getDeletedContentStyle = (colourScheme, isActive = false) => {
175
+ if (colourScheme === 'traditional') {
176
+ return deletedTraditionalContentStyle;
177
+ }
178
+ if (isActive) {
179
+ return expValEquals('platform_editor_enghealth_a11y_jan_fixes', 'isEnabled', true) ? deletedContentStyleNewActive : deletedContentStyleActive;
180
+ }
181
+ return expValEquals('platform_editor_enghealth_a11y_jan_fixes', 'isEnabled', true) ? deletedContentStyleNew : deletedContentStyle;
182
+ };
139
183
  const getNodeClass = name => {
140
184
  switch (name) {
141
185
  case 'extension':
@@ -162,7 +206,8 @@ export const createDeletedContentDecoration = ({
162
206
  nodeViewSerializer,
163
207
  colourScheme,
164
208
  newDoc,
165
- intl
209
+ intl,
210
+ isActive = false
166
211
  }) => {
167
212
  const slice = doc.slice(change.fromA, change.toA);
168
213
  if (slice.content.content.length === 0) {
@@ -192,7 +237,6 @@ export const createDeletedContentDecoration = ({
192
237
  * and if it's the first or last content, we go in however many the sliced Open
193
238
  * or sliced End depth is and match only the entire node.
194
239
  */
195
-
196
240
  slice.content.forEach(node => {
197
241
  // Create a wrapper for each node with strikethrough
198
242
  const createWrapperWithStrikethrough = () => {
@@ -201,7 +245,7 @@ export const createDeletedContentDecoration = ({
201
245
  position: 'relative',
202
246
  width: 'fit-content'
203
247
  });
204
- wrapper.setAttribute('style', `${baseStyle}${getDeletedContentStyle(colourScheme)}`);
248
+ wrapper.setAttribute('style', `${baseStyle}${getDeletedContentStyle(colourScheme, isActive)}`);
205
249
  const strikethrough = document.createElement('span');
206
250
  strikethrough.setAttribute('style', getDeletedContentStyleUnbounded(colourScheme));
207
251
  wrapper.append(strikethrough);
@@ -288,7 +332,7 @@ export const createDeletedContentDecoration = ({
288
332
  } else {
289
333
  const fallbackNode = fallbackSerialization();
290
334
  if (fallbackNode) {
291
- const wrapper = createDeletedStyleWrapperWithoutOpacity(colourScheme);
335
+ const wrapper = createDeletedStyleWrapperWithoutOpacity(colourScheme, isActive);
292
336
  wrapper.append(fallbackNode);
293
337
  dom.append(wrapper);
294
338
  }
@@ -154,9 +154,9 @@ export const createBlockNodeWrapper = () => {
154
154
  /**
155
155
  * Wraps content with deleted styling without opacity (for use when content is a direct child of dom)
156
156
  */
157
- export const createDeletedStyleWrapperWithoutOpacity = colourScheme => {
157
+ export const createDeletedStyleWrapperWithoutOpacity = (colourScheme, isActive) => {
158
158
  const wrapper = document.createElement('span');
159
- wrapper.setAttribute('style', getDeletedContentStyle(colourScheme));
159
+ wrapper.setAttribute('style', getDeletedContentStyle(colourScheme, isActive));
160
160
  return wrapper;
161
161
  };
162
162