@atlaskit/editor-plugin-annotation 1.24.1 → 1.25.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,18 @@
1
1
  # @atlaskit/editor-plugin-annotation
2
2
 
3
+ ## 1.25.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#167231](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/167231)
8
+ [`335a373081eaf`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/335a373081eaf) -
9
+ [ux] Added hoveredAnnotation for the renderer and the editor to accomodate the newly implemented
10
+ comment's panel
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
3
16
  ## 1.24.1
4
17
 
5
18
  ### Patch Changes
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.updateMouseState = exports.updateInlineCommentResolvedState = exports.showInlineCommentForBlockNode = exports.setSelectedAnnotation = exports.setInlineCommentsVisibility = exports.setInlineCommentDraftState = exports.removeInlineCommentNearSelection = exports.createAnnotation = exports.closeComponent = exports.clearDirtyMark = exports.addInlineComment = void 0;
7
+ exports.updateMouseState = exports.updateInlineCommentResolvedState = exports.showInlineCommentForBlockNode = exports.setSelectedAnnotation = exports.setInlineCommentsVisibility = exports.setInlineCommentDraftState = exports.setHoveredAnnotation = exports.removeInlineCommentNearSelection = exports.createAnnotation = exports.closeComponent = exports.clearDirtyMark = exports.addInlineComment = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _adfSchema = require("@atlaskit/adf-schema");
10
10
  var _analytics = require("@atlaskit/editor-common/analytics");
@@ -223,6 +223,17 @@ var setSelectedAnnotation = exports.setSelectedAnnotation = function setSelected
223
223
  }
224
224
  });
225
225
  };
226
+ var setHoveredAnnotation = exports.setHoveredAnnotation = function setHoveredAnnotation(id) {
227
+ return (0, _pluginFactory.createCommand)({
228
+ type: _types.ACTIONS.SET_HOVERED_ANNOTATION,
229
+ data: {
230
+ hoveredAnnotations: [{
231
+ id: id,
232
+ type: _adfSchema.AnnotationTypes.INLINE_COMMENT
233
+ }]
234
+ }
235
+ });
236
+ };
226
237
  var createAnnotation = exports.createAnnotation = function createAnnotation(editorAnalyticsAPI, editorAPI) {
227
238
  return function (id) {
228
239
  var annotationType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _adfSchema.AnnotationTypes.INLINE_COMMENT;
@@ -51,11 +51,17 @@ var AnnotationNodeView = exports.AnnotationNodeView = /*#__PURE__*/function (_Re
51
51
  }]);
52
52
  return AnnotationNodeView;
53
53
  }(_reactNodeView.default);
54
- var getAnnotationViewClassname = exports.getAnnotationViewClassname = function getAnnotationViewClassname(isUnresolved, hasFocus) {
54
+ var getAnnotationViewClassname = exports.getAnnotationViewClassname = function getAnnotationViewClassname(isUnresolved, hasFocus, isHovered) {
55
55
  if (!isUnresolved) {
56
56
  return;
57
57
  }
58
- return hasFocus ? _styles.AnnotationSharedClassNames.focus : _styles.AnnotationSharedClassNames.blur;
58
+ if (hasFocus) {
59
+ return _styles.AnnotationSharedClassNames.focus;
60
+ }
61
+ if (isHovered) {
62
+ return _styles.AnnotationSharedClassNames.hover;
63
+ }
64
+ return _styles.AnnotationSharedClassNames.blur;
59
65
  };
60
66
  var getBlockAnnotationViewClassname = exports.getBlockAnnotationViewClassname = function getBlockAnnotationViewClassname(isUnresolved, hasFocus) {
61
67
  if (!isUnresolved) {
@@ -82,6 +82,7 @@ var initialState = function initialState() {
82
82
  return {
83
83
  annotations: {},
84
84
  selectedAnnotations: [],
85
+ hoveredAnnotations: [],
85
86
  mouseData: {
86
87
  isSelecting: false
87
88
  },
@@ -172,9 +173,19 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
172
173
  (0, _commands.setSelectedAnnotation)(annotationId)(editorView.state, editorView.dispatch);
173
174
  }
174
175
  };
176
+ var setHoveredAnnotationFn = function setHoveredAnnotationFn(annotationId) {
177
+ if (!annotationId) {
178
+ (0, _commands.closeComponent)()(editorView.state, editorView.dispatch);
179
+ } else {
180
+ (0, _commands.setHoveredAnnotation)(annotationId)(editorView.state, editorView.dispatch);
181
+ }
182
+ };
183
+ var removeHoveredannotationFn = function removeHoveredannotationFn() {
184
+ (0, _commands.setHoveredAnnotation)('')(editorView.state, editorView.dispatch);
185
+ };
175
186
  var updateSubscriber = provider.updateSubscriber;
176
187
  if (updateSubscriber) {
177
- updateSubscriber.on('resolve', resolve).on('delete', resolve).on('unresolve', unResolve).on('create', unResolve).on('setvisibility', setVisibility).on('setselectedannotation', setSelectedAnnotationFn);
188
+ updateSubscriber.on('resolve', resolve).on('delete', resolve).on('unresolve', unResolve).on('create', unResolve).on('setvisibility', setVisibility).on('setselectedannotation', setSelectedAnnotationFn).on('sethoveredannotation', setHoveredAnnotationFn).on('removehoveredannotation', removeHoveredannotationFn);
178
189
  }
179
190
 
180
191
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
@@ -193,7 +204,7 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
193
204
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
194
205
  editorView.root.removeEventListener('mouseup', mouseUp);
195
206
  if (updateSubscriber) {
196
- updateSubscriber.off('resolve', resolve).off('delete', resolve).off('unresolve', unResolve).off('create', unResolve).off('setvisibility', setVisibility).off('setselectedannotation', setSelectedAnnotationFn);
207
+ updateSubscriber.off('resolve', resolve).off('delete', resolve).off('unresolve', unResolve).off('create', unResolve).off('setvisibility', setVisibility).off('setselectedannotation', setSelectedAnnotationFn).off('sethoveredannotation', setHoveredAnnotationFn).off('removehoveredannotation', removeHoveredannotationFn);
197
208
  }
198
209
  }
199
210
  };
@@ -226,7 +237,8 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
226
237
  annotations = _ref5.annotations,
227
238
  selectedAnnotations = _ref5.selectedAnnotations,
228
239
  isVisible = _ref5.isVisible,
229
- isInlineCommentViewClosed = _ref5.isInlineCommentViewClosed;
240
+ isInlineCommentViewClosed = _ref5.isInlineCommentViewClosed,
241
+ hoveredAnnotations = _ref5.hoveredAnnotations;
230
242
  var decorations = draftDecorationSet !== null && draftDecorationSet !== void 0 ? draftDecorationSet : _view.DecorationSet.empty;
231
243
  var focusDecorations = [];
232
244
  state.doc.descendants(function (node, pos) {
@@ -245,6 +257,9 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
245
257
  var isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
246
258
  return selectedAnnotation.id === mark.attrs.id;
247
259
  }));
260
+ var isHovered = !isInlineCommentViewClosed && !!(hoveredAnnotations !== null && hoveredAnnotations !== void 0 && hoveredAnnotations.some(function (hoveredAnnotation) {
261
+ return hoveredAnnotation.id === mark.attrs.id;
262
+ }));
248
263
  if (isSupportedBlockNode) {
249
264
  focusDecorations.push(_view.Decoration.node(pos, pos + node.nodeSize, {
250
265
  class: "".concat((0, _nodeviews.getBlockAnnotationViewClassname)(isUnresolved, isSelected), " ").concat(isUnresolved)
@@ -255,19 +270,19 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
255
270
  if ((0, _platformFeatureFlags.fg)('editor_inline_comments_on_inline_nodes')) {
256
271
  if (node.isText) {
257
272
  focusDecorations.push(_view.Decoration.inline(pos, pos + node.nodeSize, {
258
- class: "".concat((0, _nodeviews.getAnnotationViewClassname)(isUnresolved, isSelected), " ").concat(isUnresolved),
273
+ class: "".concat((0, _nodeviews.getAnnotationViewClassname)(isUnresolved, isSelected, isHovered), " ").concat(isUnresolved),
259
274
  nodeName: 'span'
260
275
  }));
261
276
  } else {
262
277
  focusDecorations.push(_view.Decoration.node(pos, pos + node.nodeSize, {
263
- class: "".concat((0, _nodeviews.getAnnotationViewClassname)(isUnresolved, isSelected), " ").concat(isUnresolved)
278
+ class: "".concat((0, _nodeviews.getAnnotationViewClassname)(isUnresolved, isSelected, isHovered), " ").concat(isUnresolved)
264
279
  }, {
265
280
  key: _utils.decorationKey.block
266
281
  }));
267
282
  }
268
283
  } else {
269
284
  focusDecorations.push(_view.Decoration.inline(pos, pos + node.nodeSize, {
270
- class: "".concat((0, _nodeviews.getAnnotationViewClassname)(isUnresolved, isSelected), " ").concat(isUnresolved),
285
+ class: "".concat((0, _nodeviews.getAnnotationViewClassname)(isUnresolved, isSelected, isHovered), " ").concat(isUnresolved),
271
286
  nodeName: 'span'
272
287
  }));
273
288
  }
@@ -60,6 +60,12 @@ var _default = exports.default = function _default(pluginState, action) {
60
60
  isInlineCommentViewClosed: false,
61
61
  isOpeningMediaCommentFromToolbar: action.data.isOpeningMediaCommentFromToolbar
62
62
  });
63
+ case _types.ACTIONS.SET_HOVERED_ANNOTATION:
64
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
65
+ hoveredAnnotations: (0, _toConsumableArray2.default)(action.data.hoveredAnnotations),
66
+ skipSelectionHandling: true,
67
+ isInlineCommentViewClosed: false
68
+ });
63
69
  default:
64
70
  return pluginState;
65
71
  }
@@ -13,5 +13,6 @@ var ACTIONS = exports.ACTIONS = /*#__PURE__*/function (ACTIONS) {
13
13
  ACTIONS[ACTIONS["INLINE_COMMENT_SET_VISIBLE"] = 5] = "INLINE_COMMENT_SET_VISIBLE";
14
14
  ACTIONS[ACTIONS["CLOSE_COMPONENT"] = 6] = "CLOSE_COMPONENT";
15
15
  ACTIONS[ACTIONS["SET_SELECTED_ANNOTATION"] = 7] = "SET_SELECTED_ANNOTATION";
16
+ ACTIONS[ACTIONS["SET_HOVERED_ANNOTATION"] = 8] = "SET_HOVERED_ANNOTATION";
16
17
  return ACTIONS;
17
18
  }({});
@@ -185,6 +185,15 @@ export const setSelectedAnnotation = id => createCommand({
185
185
  }]
186
186
  }
187
187
  });
188
+ export const setHoveredAnnotation = id => createCommand({
189
+ type: ACTIONS.SET_HOVERED_ANNOTATION,
190
+ data: {
191
+ hoveredAnnotations: [{
192
+ id,
193
+ type: AnnotationTypes.INLINE_COMMENT
194
+ }]
195
+ }
196
+ });
188
197
  export const createAnnotation = (editorAnalyticsAPI, editorAPI) => (id, annotationType = AnnotationTypes.INLINE_COMMENT, supportedBlockNodes) => (state, dispatch) => {
189
198
  // don't try to add if there are is no temp highlight bookmarked
190
199
  const {
@@ -23,11 +23,17 @@ export class AnnotationNodeView extends ReactNodeView {
23
23
  );
24
24
  }
25
25
  }
26
- export const getAnnotationViewClassname = (isUnresolved, hasFocus) => {
26
+ export const getAnnotationViewClassname = (isUnresolved, hasFocus, isHovered) => {
27
27
  if (!isUnresolved) {
28
28
  return;
29
29
  }
30
- return hasFocus ? AnnotationSharedClassNames.focus : AnnotationSharedClassNames.blur;
30
+ if (hasFocus) {
31
+ return AnnotationSharedClassNames.focus;
32
+ }
33
+ if (isHovered) {
34
+ return AnnotationSharedClassNames.hover;
35
+ }
36
+ return AnnotationSharedClassNames.blur;
31
37
  };
32
38
  export const getBlockAnnotationViewClassname = (isUnresolved, hasFocus) => {
33
39
  if (!isUnresolved) {
@@ -3,7 +3,7 @@ import { RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
3
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
5
  import { fg } from '@atlaskit/platform-feature-flags';
6
- import { clearDirtyMark, closeComponent, setInlineCommentsVisibility, setSelectedAnnotation, updateInlineCommentResolvedState, updateMouseState } from '../commands';
6
+ import { clearDirtyMark, closeComponent, setHoveredAnnotation, setInlineCommentsVisibility, setSelectedAnnotation, updateInlineCommentResolvedState, updateMouseState } from '../commands';
7
7
  import { AnnotationNodeView, getAnnotationViewClassname, getBlockAnnotationViewClassname } from '../nodeviews';
8
8
  import { decorationKey, getAllAnnotations, getPluginState, inlineCommentPluginKey } from '../utils';
9
9
  import { createPluginState } from './plugin-factory';
@@ -33,6 +33,7 @@ const initialState = (disallowOnWhitespace = false, featureFlagsPluginState) =>
33
33
  return {
34
34
  annotations: {},
35
35
  selectedAnnotations: [],
36
+ hoveredAnnotations: [],
36
37
  mouseData: {
37
38
  isSelecting: false
38
39
  },
@@ -110,11 +111,21 @@ export const inlineCommentPlugin = options => {
110
111
  setSelectedAnnotation(annotationId)(editorView.state, editorView.dispatch);
111
112
  }
112
113
  };
114
+ const setHoveredAnnotationFn = annotationId => {
115
+ if (!annotationId) {
116
+ closeComponent()(editorView.state, editorView.dispatch);
117
+ } else {
118
+ setHoveredAnnotation(annotationId)(editorView.state, editorView.dispatch);
119
+ }
120
+ };
121
+ const removeHoveredannotationFn = () => {
122
+ setHoveredAnnotation('')(editorView.state, editorView.dispatch);
123
+ };
113
124
  const {
114
125
  updateSubscriber
115
126
  } = provider;
116
127
  if (updateSubscriber) {
117
- updateSubscriber.on('resolve', resolve).on('delete', resolve).on('unresolve', unResolve).on('create', unResolve).on('setvisibility', setVisibility).on('setselectedannotation', setSelectedAnnotationFn);
128
+ updateSubscriber.on('resolve', resolve).on('delete', resolve).on('unresolve', unResolve).on('create', unResolve).on('setvisibility', setVisibility).on('setselectedannotation', setSelectedAnnotationFn).on('sethoveredannotation', setHoveredAnnotationFn).on('removehoveredannotation', removeHoveredannotationFn);
118
129
  }
119
130
 
120
131
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
@@ -134,7 +145,7 @@ export const inlineCommentPlugin = options => {
134
145
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
135
146
  editorView.root.removeEventListener('mouseup', mouseUp);
136
147
  if (updateSubscriber) {
137
- updateSubscriber.off('resolve', resolve).off('delete', resolve).off('unresolve', unResolve).off('create', unResolve).off('setvisibility', setVisibility).off('setselectedannotation', setSelectedAnnotationFn);
148
+ updateSubscriber.off('resolve', resolve).off('delete', resolve).off('unresolve', unResolve).off('create', unResolve).off('setvisibility', setVisibility).off('setselectedannotation', setSelectedAnnotationFn).off('sethoveredannotation', setHoveredAnnotationFn).off('removehoveredannotation', removeHoveredannotationFn);
138
149
  }
139
150
  }
140
151
  };
@@ -165,7 +176,8 @@ export const inlineCommentPlugin = options => {
165
176
  annotations,
166
177
  selectedAnnotations,
167
178
  isVisible,
168
- isInlineCommentViewClosed
179
+ isInlineCommentViewClosed,
180
+ hoveredAnnotations
169
181
  } = getPluginState(state) || {};
170
182
  let decorations = draftDecorationSet !== null && draftDecorationSet !== void 0 ? draftDecorationSet : DecorationSet.empty;
171
183
  const focusDecorations = [];
@@ -181,6 +193,7 @@ export const inlineCommentPlugin = options => {
181
193
  if (isVisible) {
182
194
  const isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
183
195
  const isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(selectedAnnotation => selectedAnnotation.id === mark.attrs.id));
196
+ const isHovered = !isInlineCommentViewClosed && !!(hoveredAnnotations !== null && hoveredAnnotations !== void 0 && hoveredAnnotations.some(hoveredAnnotation => hoveredAnnotation.id === mark.attrs.id));
184
197
  if (isSupportedBlockNode) {
185
198
  focusDecorations.push(Decoration.node(pos, pos + node.nodeSize, {
186
199
  class: `${getBlockAnnotationViewClassname(isUnresolved, isSelected)} ${isUnresolved}`
@@ -191,19 +204,19 @@ export const inlineCommentPlugin = options => {
191
204
  if (fg('editor_inline_comments_on_inline_nodes')) {
192
205
  if (node.isText) {
193
206
  focusDecorations.push(Decoration.inline(pos, pos + node.nodeSize, {
194
- class: `${getAnnotationViewClassname(isUnresolved, isSelected)} ${isUnresolved}`,
207
+ class: `${getAnnotationViewClassname(isUnresolved, isSelected, isHovered)} ${isUnresolved}`,
195
208
  nodeName: 'span'
196
209
  }));
197
210
  } else {
198
211
  focusDecorations.push(Decoration.node(pos, pos + node.nodeSize, {
199
- class: `${getAnnotationViewClassname(isUnresolved, isSelected)} ${isUnresolved}`
212
+ class: `${getAnnotationViewClassname(isUnresolved, isSelected, isHovered)} ${isUnresolved}`
200
213
  }, {
201
214
  key: decorationKey.block
202
215
  }));
203
216
  }
204
217
  } else {
205
218
  focusDecorations.push(Decoration.inline(pos, pos + node.nodeSize, {
206
- class: `${getAnnotationViewClassname(isUnresolved, isSelected)} ${isUnresolved}`,
219
+ class: `${getAnnotationViewClassname(isUnresolved, isSelected, isHovered)} ${isUnresolved}`,
207
220
  nodeName: 'span'
208
221
  }));
209
222
  }
@@ -64,6 +64,13 @@ export default ((pluginState, action) => {
64
64
  isInlineCommentViewClosed: false,
65
65
  isOpeningMediaCommentFromToolbar: action.data.isOpeningMediaCommentFromToolbar
66
66
  };
67
+ case ACTIONS.SET_HOVERED_ANNOTATION:
68
+ return {
69
+ ...pluginState,
70
+ hoveredAnnotations: [...action.data.hoveredAnnotations],
71
+ skipSelectionHandling: true,
72
+ isInlineCommentViewClosed: false
73
+ };
67
74
  default:
68
75
  return pluginState;
69
76
  }
@@ -7,5 +7,6 @@ export let ACTIONS = /*#__PURE__*/function (ACTIONS) {
7
7
  ACTIONS[ACTIONS["INLINE_COMMENT_SET_VISIBLE"] = 5] = "INLINE_COMMENT_SET_VISIBLE";
8
8
  ACTIONS[ACTIONS["CLOSE_COMPONENT"] = 6] = "CLOSE_COMPONENT";
9
9
  ACTIONS[ACTIONS["SET_SELECTED_ANNOTATION"] = 7] = "SET_SELECTED_ANNOTATION";
10
+ ACTIONS[ACTIONS["SET_HOVERED_ANNOTATION"] = 8] = "SET_HOVERED_ANNOTATION";
10
11
  return ACTIONS;
11
12
  }({});
@@ -216,6 +216,17 @@ export var setSelectedAnnotation = function setSelectedAnnotation(id) {
216
216
  }
217
217
  });
218
218
  };
219
+ export var setHoveredAnnotation = function setHoveredAnnotation(id) {
220
+ return createCommand({
221
+ type: ACTIONS.SET_HOVERED_ANNOTATION,
222
+ data: {
223
+ hoveredAnnotations: [{
224
+ id: id,
225
+ type: AnnotationTypes.INLINE_COMMENT
226
+ }]
227
+ }
228
+ });
229
+ };
219
230
  export var createAnnotation = function createAnnotation(editorAnalyticsAPI, editorAPI) {
220
231
  return function (id) {
221
232
  var annotationType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : AnnotationTypes.INLINE_COMMENT;
@@ -44,11 +44,17 @@ export var AnnotationNodeView = /*#__PURE__*/function (_ReactNodeView) {
44
44
  }]);
45
45
  return AnnotationNodeView;
46
46
  }(ReactNodeView);
47
- export var getAnnotationViewClassname = function getAnnotationViewClassname(isUnresolved, hasFocus) {
47
+ export var getAnnotationViewClassname = function getAnnotationViewClassname(isUnresolved, hasFocus, isHovered) {
48
48
  if (!isUnresolved) {
49
49
  return;
50
50
  }
51
- return hasFocus ? AnnotationSharedClassNames.focus : AnnotationSharedClassNames.blur;
51
+ if (hasFocus) {
52
+ return AnnotationSharedClassNames.focus;
53
+ }
54
+ if (isHovered) {
55
+ return AnnotationSharedClassNames.hover;
56
+ }
57
+ return AnnotationSharedClassNames.blur;
52
58
  };
53
59
  export var getBlockAnnotationViewClassname = function getBlockAnnotationViewClassname(isUnresolved, hasFocus) {
54
60
  if (!isUnresolved) {
@@ -6,7 +6,7 @@ import { RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
6
6
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
7
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
8
  import { fg } from '@atlaskit/platform-feature-flags';
9
- import { clearDirtyMark, closeComponent, setInlineCommentsVisibility, setSelectedAnnotation, updateInlineCommentResolvedState, updateMouseState } from '../commands';
9
+ import { clearDirtyMark, closeComponent, setHoveredAnnotation, setInlineCommentsVisibility, setSelectedAnnotation, updateInlineCommentResolvedState, updateMouseState } from '../commands';
10
10
  import { AnnotationNodeView, getAnnotationViewClassname, getBlockAnnotationViewClassname } from '../nodeviews';
11
11
  import { decorationKey, getAllAnnotations, getPluginState, inlineCommentPluginKey } from '../utils';
12
12
  import { createPluginState } from './plugin-factory';
@@ -75,6 +75,7 @@ var initialState = function initialState() {
75
75
  return {
76
76
  annotations: {},
77
77
  selectedAnnotations: [],
78
+ hoveredAnnotations: [],
78
79
  mouseData: {
79
80
  isSelecting: false
80
81
  },
@@ -165,9 +166,19 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
165
166
  setSelectedAnnotation(annotationId)(editorView.state, editorView.dispatch);
166
167
  }
167
168
  };
169
+ var setHoveredAnnotationFn = function setHoveredAnnotationFn(annotationId) {
170
+ if (!annotationId) {
171
+ closeComponent()(editorView.state, editorView.dispatch);
172
+ } else {
173
+ setHoveredAnnotation(annotationId)(editorView.state, editorView.dispatch);
174
+ }
175
+ };
176
+ var removeHoveredannotationFn = function removeHoveredannotationFn() {
177
+ setHoveredAnnotation('')(editorView.state, editorView.dispatch);
178
+ };
168
179
  var updateSubscriber = provider.updateSubscriber;
169
180
  if (updateSubscriber) {
170
- updateSubscriber.on('resolve', resolve).on('delete', resolve).on('unresolve', unResolve).on('create', unResolve).on('setvisibility', setVisibility).on('setselectedannotation', setSelectedAnnotationFn);
181
+ updateSubscriber.on('resolve', resolve).on('delete', resolve).on('unresolve', unResolve).on('create', unResolve).on('setvisibility', setVisibility).on('setselectedannotation', setSelectedAnnotationFn).on('sethoveredannotation', setHoveredAnnotationFn).on('removehoveredannotation', removeHoveredannotationFn);
171
182
  }
172
183
 
173
184
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
@@ -186,7 +197,7 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
186
197
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
187
198
  editorView.root.removeEventListener('mouseup', mouseUp);
188
199
  if (updateSubscriber) {
189
- updateSubscriber.off('resolve', resolve).off('delete', resolve).off('unresolve', unResolve).off('create', unResolve).off('setvisibility', setVisibility).off('setselectedannotation', setSelectedAnnotationFn);
200
+ updateSubscriber.off('resolve', resolve).off('delete', resolve).off('unresolve', unResolve).off('create', unResolve).off('setvisibility', setVisibility).off('setselectedannotation', setSelectedAnnotationFn).off('sethoveredannotation', setHoveredAnnotationFn).off('removehoveredannotation', removeHoveredannotationFn);
190
201
  }
191
202
  }
192
203
  };
@@ -219,7 +230,8 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
219
230
  annotations = _ref5.annotations,
220
231
  selectedAnnotations = _ref5.selectedAnnotations,
221
232
  isVisible = _ref5.isVisible,
222
- isInlineCommentViewClosed = _ref5.isInlineCommentViewClosed;
233
+ isInlineCommentViewClosed = _ref5.isInlineCommentViewClosed,
234
+ hoveredAnnotations = _ref5.hoveredAnnotations;
223
235
  var decorations = draftDecorationSet !== null && draftDecorationSet !== void 0 ? draftDecorationSet : DecorationSet.empty;
224
236
  var focusDecorations = [];
225
237
  state.doc.descendants(function (node, pos) {
@@ -238,6 +250,9 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
238
250
  var isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
239
251
  return selectedAnnotation.id === mark.attrs.id;
240
252
  }));
253
+ var isHovered = !isInlineCommentViewClosed && !!(hoveredAnnotations !== null && hoveredAnnotations !== void 0 && hoveredAnnotations.some(function (hoveredAnnotation) {
254
+ return hoveredAnnotation.id === mark.attrs.id;
255
+ }));
241
256
  if (isSupportedBlockNode) {
242
257
  focusDecorations.push(Decoration.node(pos, pos + node.nodeSize, {
243
258
  class: "".concat(getBlockAnnotationViewClassname(isUnresolved, isSelected), " ").concat(isUnresolved)
@@ -248,19 +263,19 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
248
263
  if (fg('editor_inline_comments_on_inline_nodes')) {
249
264
  if (node.isText) {
250
265
  focusDecorations.push(Decoration.inline(pos, pos + node.nodeSize, {
251
- class: "".concat(getAnnotationViewClassname(isUnresolved, isSelected), " ").concat(isUnresolved),
266
+ class: "".concat(getAnnotationViewClassname(isUnresolved, isSelected, isHovered), " ").concat(isUnresolved),
252
267
  nodeName: 'span'
253
268
  }));
254
269
  } else {
255
270
  focusDecorations.push(Decoration.node(pos, pos + node.nodeSize, {
256
- class: "".concat(getAnnotationViewClassname(isUnresolved, isSelected), " ").concat(isUnresolved)
271
+ class: "".concat(getAnnotationViewClassname(isUnresolved, isSelected, isHovered), " ").concat(isUnresolved)
257
272
  }, {
258
273
  key: decorationKey.block
259
274
  }));
260
275
  }
261
276
  } else {
262
277
  focusDecorations.push(Decoration.inline(pos, pos + node.nodeSize, {
263
- class: "".concat(getAnnotationViewClassname(isUnresolved, isSelected), " ").concat(isUnresolved),
278
+ class: "".concat(getAnnotationViewClassname(isUnresolved, isSelected, isHovered), " ").concat(isUnresolved),
264
279
  nodeName: 'span'
265
280
  }));
266
281
  }
@@ -53,6 +53,12 @@ export default (function (pluginState, action) {
53
53
  isInlineCommentViewClosed: false,
54
54
  isOpeningMediaCommentFromToolbar: action.data.isOpeningMediaCommentFromToolbar
55
55
  });
56
+ case ACTIONS.SET_HOVERED_ANNOTATION:
57
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
58
+ hoveredAnnotations: _toConsumableArray(action.data.hoveredAnnotations),
59
+ skipSelectionHandling: true,
60
+ isInlineCommentViewClosed: false
61
+ });
56
62
  default:
57
63
  return pluginState;
58
64
  }
@@ -7,5 +7,6 @@ export var ACTIONS = /*#__PURE__*/function (ACTIONS) {
7
7
  ACTIONS[ACTIONS["INLINE_COMMENT_SET_VISIBLE"] = 5] = "INLINE_COMMENT_SET_VISIBLE";
8
8
  ACTIONS[ACTIONS["CLOSE_COMPONENT"] = 6] = "CLOSE_COMPONENT";
9
9
  ACTIONS[ACTIONS["SET_SELECTED_ANNOTATION"] = 7] = "SET_SELECTED_ANNOTATION";
10
+ ACTIONS[ACTIONS["SET_HOVERED_ANNOTATION"] = 8] = "SET_HOVERED_ANNOTATION";
10
11
  return ACTIONS;
11
12
  }({});
@@ -18,5 +18,6 @@ export declare const setInlineCommentDraftState: (editorAnalyticsAPI: EditorAnal
18
18
  export declare const addInlineComment: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorAPI?: ExtractInjectionAPI<AnnotationPlugin> | undefined) => (id: string, supportedBlockNodes?: string[]) => Command;
19
19
  export declare const updateMouseState: (mouseData: InlineCommentMouseData) => Command;
20
20
  export declare const setSelectedAnnotation: (id: string) => Command;
21
+ export declare const setHoveredAnnotation: (id: string) => Command;
21
22
  export declare const createAnnotation: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorAPI?: ExtractInjectionAPI<AnnotationPlugin> | undefined) => (id: string, annotationType?: AnnotationTypes, supportedBlockNodes?: string[]) => Command;
22
23
  export declare const setInlineCommentsVisibility: (isVisible: boolean) => Command;
@@ -8,5 +8,5 @@ export declare class AnnotationNodeView extends ReactNodeView {
8
8
  };
9
9
  render(_props: {}, forwardRef: ForwardRef): JSX.Element;
10
10
  }
11
- export declare const getAnnotationViewClassname: (isUnresolved: boolean, hasFocus: boolean) => string | undefined;
11
+ export declare const getAnnotationViewClassname: (isUnresolved: boolean, hasFocus: boolean, isHovered: boolean) => string | undefined;
12
12
  export declare const getBlockAnnotationViewClassname: (isUnresolved: boolean, hasFocus: boolean) => string | undefined;
@@ -13,7 +13,8 @@ export declare enum ACTIONS {
13
13
  ADD_INLINE_COMMENT = 4,
14
14
  INLINE_COMMENT_SET_VISIBLE = 5,
15
15
  CLOSE_COMPONENT = 6,
16
- SET_SELECTED_ANNOTATION = 7
16
+ SET_SELECTED_ANNOTATION = 7,
17
+ SET_HOVERED_ANNOTATION = 8
17
18
  }
18
19
  export interface InlineCommentPluginOptions {
19
20
  dispatch: Dispatch;
@@ -71,6 +72,12 @@ export type InlineCommentAction = {
71
72
  selectAnnotationMethod?: VIEW_METHOD;
72
73
  isOpeningMediaCommentFromToolbar?: boolean;
73
74
  };
75
+ } | {
76
+ type: ACTIONS.SET_HOVERED_ANNOTATION;
77
+ data: {
78
+ hoveredAnnotations: AnnotationInfo[];
79
+ selectAnnotationMethod?: VIEW_METHOD;
80
+ };
74
81
  };
75
82
  export type InlineCommentPluginState = {
76
83
  annotations: InlineCommentMap;
@@ -79,6 +86,7 @@ export type InlineCommentPluginState = {
79
86
  mouseData: InlineCommentMouseData;
80
87
  draftDecorationSet?: DecorationSet;
81
88
  bookmark?: SelectionBookmark;
89
+ hoveredAnnotations?: AnnotationInfo[];
82
90
  disallowOnWhitespace: boolean;
83
91
  isInlineCommentViewClosed: boolean;
84
92
  isVisible: boolean;
@@ -18,5 +18,6 @@ export declare const setInlineCommentDraftState: (editorAnalyticsAPI: EditorAnal
18
18
  export declare const addInlineComment: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorAPI?: ExtractInjectionAPI<AnnotationPlugin> | undefined) => (id: string, supportedBlockNodes?: string[]) => Command;
19
19
  export declare const updateMouseState: (mouseData: InlineCommentMouseData) => Command;
20
20
  export declare const setSelectedAnnotation: (id: string) => Command;
21
+ export declare const setHoveredAnnotation: (id: string) => Command;
21
22
  export declare const createAnnotation: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorAPI?: ExtractInjectionAPI<AnnotationPlugin> | undefined) => (id: string, annotationType?: AnnotationTypes, supportedBlockNodes?: string[]) => Command;
22
23
  export declare const setInlineCommentsVisibility: (isVisible: boolean) => Command;
@@ -8,5 +8,5 @@ export declare class AnnotationNodeView extends ReactNodeView {
8
8
  };
9
9
  render(_props: {}, forwardRef: ForwardRef): JSX.Element;
10
10
  }
11
- export declare const getAnnotationViewClassname: (isUnresolved: boolean, hasFocus: boolean) => string | undefined;
11
+ export declare const getAnnotationViewClassname: (isUnresolved: boolean, hasFocus: boolean, isHovered: boolean) => string | undefined;
12
12
  export declare const getBlockAnnotationViewClassname: (isUnresolved: boolean, hasFocus: boolean) => string | undefined;
@@ -13,7 +13,8 @@ export declare enum ACTIONS {
13
13
  ADD_INLINE_COMMENT = 4,
14
14
  INLINE_COMMENT_SET_VISIBLE = 5,
15
15
  CLOSE_COMPONENT = 6,
16
- SET_SELECTED_ANNOTATION = 7
16
+ SET_SELECTED_ANNOTATION = 7,
17
+ SET_HOVERED_ANNOTATION = 8
17
18
  }
18
19
  export interface InlineCommentPluginOptions {
19
20
  dispatch: Dispatch;
@@ -71,6 +72,12 @@ export type InlineCommentAction = {
71
72
  selectAnnotationMethod?: VIEW_METHOD;
72
73
  isOpeningMediaCommentFromToolbar?: boolean;
73
74
  };
75
+ } | {
76
+ type: ACTIONS.SET_HOVERED_ANNOTATION;
77
+ data: {
78
+ hoveredAnnotations: AnnotationInfo[];
79
+ selectAnnotationMethod?: VIEW_METHOD;
80
+ };
74
81
  };
75
82
  export type InlineCommentPluginState = {
76
83
  annotations: InlineCommentMap;
@@ -79,6 +86,7 @@ export type InlineCommentPluginState = {
79
86
  mouseData: InlineCommentMouseData;
80
87
  draftDecorationSet?: DecorationSet;
81
88
  bookmark?: SelectionBookmark;
89
+ hoveredAnnotations?: AnnotationInfo[];
82
90
  disallowOnWhitespace: boolean;
83
91
  isInlineCommentViewClosed: boolean;
84
92
  isVisible: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-annotation",
3
- "version": "1.24.1",
3
+ "version": "1.25.0",
4
4
  "description": "Annotation plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -32,13 +32,13 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@atlaskit/adf-schema": "^44.2.0",
35
- "@atlaskit/editor-common": "^95.0.0",
35
+ "@atlaskit/editor-common": "^95.4.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.10.0",
37
37
  "@atlaskit/editor-plugin-editor-viewmode-effects": "^1.1.0",
38
38
  "@atlaskit/editor-plugin-engagement-platform": "^2.1.0",
39
39
  "@atlaskit/editor-plugin-feature-flags": "^1.2.0",
40
40
  "@atlaskit/editor-prosemirror": "6.0.0",
41
- "@atlaskit/icon": "^22.24.0",
41
+ "@atlaskit/icon": "^22.25.0",
42
42
  "@atlaskit/onboarding": "^12.1.0",
43
43
  "@atlaskit/platform-feature-flags": "^0.3.0",
44
44
  "@atlaskit/tmp-editor-statsig": "^2.19.0",