@atlaskit/editor-plugin-annotation 2.8.3 → 2.9.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 (31) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/editor-commands/index.js +50 -1
  3. package/dist/cjs/pm-plugins/annotation-manager-hooks.js +166 -4
  4. package/dist/cjs/pm-plugins/inline-comment.js +169 -30
  5. package/dist/cjs/pm-plugins/plugin-factory.js +51 -1
  6. package/dist/cjs/pm-plugins/reducer.js +18 -1
  7. package/dist/cjs/pm-plugins/toolbar.js +10 -7
  8. package/dist/cjs/pm-plugins/types.js +2 -0
  9. package/dist/es2019/editor-commands/index.js +42 -0
  10. package/dist/es2019/pm-plugins/annotation-manager-hooks.js +160 -5
  11. package/dist/es2019/pm-plugins/inline-comment.js +146 -9
  12. package/dist/es2019/pm-plugins/plugin-factory.js +51 -1
  13. package/dist/es2019/pm-plugins/reducer.js +22 -1
  14. package/dist/es2019/pm-plugins/toolbar.js +10 -8
  15. package/dist/es2019/pm-plugins/types.js +2 -0
  16. package/dist/esm/editor-commands/index.js +49 -0
  17. package/dist/esm/pm-plugins/annotation-manager-hooks.js +167 -5
  18. package/dist/esm/pm-plugins/inline-comment.js +159 -20
  19. package/dist/esm/pm-plugins/plugin-factory.js +51 -1
  20. package/dist/esm/pm-plugins/reducer.js +18 -1
  21. package/dist/esm/pm-plugins/toolbar.js +10 -7
  22. package/dist/esm/pm-plugins/types.js +2 -0
  23. package/dist/types/editor-commands/index.d.ts +5 -0
  24. package/dist/types/pm-plugins/annotation-manager-hooks.d.ts +4 -1
  25. package/dist/types/pm-plugins/plugin-factory.d.ts +4 -0
  26. package/dist/types/pm-plugins/types.d.ts +26 -1
  27. package/dist/types-ts4.5/editor-commands/index.d.ts +5 -0
  28. package/dist/types-ts4.5/pm-plugins/annotation-manager-hooks.d.ts +4 -1
  29. package/dist/types-ts4.5/pm-plugins/plugin-factory.d.ts +4 -0
  30. package/dist/types-ts4.5/pm-plugins/types.d.ts +26 -1
  31. package/package.json +6 -3
@@ -1,6 +1,7 @@
1
1
  import { pluginFactory } from '@atlaskit/editor-common/utils';
2
2
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
4
5
  import reducer from './reducer';
5
6
  import { decorationKey, findAnnotationsInSelection, inlineCommentPluginKey, isBlockNodeAnnotationsSelected, isSelectedAnnotationsChanged } from './utils';
6
7
  const handleDocChanged = (tr, prevPluginState) => {
@@ -17,6 +18,10 @@ const handleDocChanged = (tr, prevPluginState) => {
17
18
  * We clear bookmark on the following conditions:
18
19
  * 1. if current selection is an empty selection, or
19
20
  * 2. if the current selection and bookmark selection are different
21
+ * @param tr
22
+ * @param editorState
23
+ * @param bookmark
24
+ * @example
20
25
  */
21
26
  export const shouldClearBookMarkCheck = (tr, editorState, bookmark) => {
22
27
  if (editorState.selection.empty || !bookmark) {
@@ -44,7 +49,7 @@ export const shouldClearBookMarkCheck = (tr, editorState, bookmark) => {
44
49
  // by default we discard bookmark
45
50
  return true;
46
51
  };
47
- const getSelectionChangedHandler = reopenCommentView => (tr, pluginState) => {
52
+ const getSelectionChangeHandlerOld = reopenCommentView => (tr, pluginState) => {
48
53
  if (pluginState.skipSelectionHandling) {
49
54
  return {
50
55
  ...pluginState,
@@ -92,6 +97,51 @@ const getSelectionChangedHandler = reopenCommentView => (tr, pluginState) => {
92
97
  selectAnnotationMethod: undefined
93
98
  };
94
99
  };
100
+ const getSelectionChangeHandlerNew = reopenCommentView => (tr, pluginState) => {
101
+ if (pluginState.skipSelectionHandling) {
102
+ return {
103
+ ...pluginState,
104
+ skipSelectionHandling: false,
105
+ ...(reopenCommentView && {
106
+ isInlineCommentViewClosed: false
107
+ })
108
+ };
109
+ }
110
+ const selectedAnnotations = findAnnotationsInSelection(tr.selection, tr.doc);
111
+
112
+ // NOTE: I've left this commented code here as a reference that the previous old code would reset the selected annotations
113
+ // if the selection is empty. If this is no longer needed, we can remove this code.
114
+ // clean up with platform_editor_comments_api_manager_select
115
+ // if (selectedAnnotations.length === 0) {
116
+ // return {
117
+ // ...pluginState,
118
+ // pendingSelectedAnnotations: selectedAnnotations,
119
+ // pendingSelectedAnnotationsUpdateCount:
120
+ // pluginState.pendingSelectedAnnotationsUpdateCount + 1,
121
+ // isInlineCommentViewClosed: true,
122
+ // selectAnnotationMethod: undefined,
123
+ // };
124
+ // }
125
+
126
+ if (isSelectedAnnotationsChanged(selectedAnnotations, pluginState.pendingSelectedAnnotations)) {
127
+ return {
128
+ ...pluginState,
129
+ pendingSelectedAnnotations: selectedAnnotations,
130
+ pendingSelectedAnnotationsUpdateCount: pluginState.pendingSelectedAnnotationsUpdateCount + 1,
131
+ ...(reopenCommentView && {
132
+ isInlineCommentViewClosed: false
133
+ })
134
+ };
135
+ }
136
+ return {
137
+ ...pluginState,
138
+ ...(reopenCommentView && {
139
+ isInlineCommentViewClosed: false
140
+ }),
141
+ selectAnnotationMethod: undefined
142
+ };
143
+ };
144
+ const getSelectionChangedHandler = reopenCommentView => (tr, pluginState) => fg('platform_editor_comments_api_manager_select') ? getSelectionChangeHandlerNew(reopenCommentView)(tr, pluginState) : getSelectionChangeHandlerOld(reopenCommentView)(tr, pluginState);
95
145
  export const {
96
146
  createPluginState,
97
147
  createCommand
@@ -34,6 +34,9 @@ export default ((pluginState, action) => {
34
34
  isOpeningMediaCommentFromToolbar: false,
35
35
  ...(fg('platform_editor_annotation_selected_annotation') && {
36
36
  selectedAnnotations: []
37
+ }),
38
+ ...(fg('platform_editor_comments_api_manager_select') && {
39
+ selectedAnnotations: []
37
40
  })
38
41
  };
39
42
  case ACTIONS.ADD_INLINE_COMMENT:
@@ -46,7 +49,10 @@ export default ((pluginState, action) => {
46
49
  ...action.data.inlineComments
47
50
  },
48
51
  isInlineCommentViewClosed: false,
49
- selectAnnotationMethod: undefined
52
+ selectAnnotationMethod: undefined,
53
+ ...(fg('platform_editor_comments_api_manager_select') && {
54
+ skipSelectionHandling: true
55
+ })
50
56
  };
51
57
  case ACTIONS.INLINE_COMMENT_SET_VISIBLE:
52
58
  const {
@@ -75,6 +81,21 @@ export default ((pluginState, action) => {
75
81
  skipSelectionHandling: true,
76
82
  isInlineCommentViewClosed: false
77
83
  };
84
+ case ACTIONS.FLUSH_PENDING_SELECTIONS:
85
+ return {
86
+ ...pluginState,
87
+ selectedAnnotations: action.data.canSetAsSelectedAnnotations ? [...pluginState.pendingSelectedAnnotations] : pluginState.selectedAnnotations,
88
+ pendingSelectedAnnotations: [],
89
+ isInlineCommentViewClosed: false
90
+ };
91
+ case ACTIONS.SET_PENDING_SELECTIONS:
92
+ return {
93
+ ...pluginState,
94
+ pendingSelectedAnnotations: [...action.data.selectedAnnotations],
95
+ pendingSelectedAnnotationsUpdateCount: pluginState.pendingSelectedAnnotationsUpdateCount + 1,
96
+ skipSelectionHandling: true,
97
+ isInlineCommentViewClosed: false
98
+ };
78
99
  default:
79
100
  return pluginState;
80
101
  }
@@ -135,7 +135,7 @@ export const buildToolbar = editorAnalyticsAPI => ({
135
135
  }
136
136
  if (fg('platform_editor_comments_api_manager')) {
137
137
  if (!annotationManager) {
138
- // TODO: EDITOR-188 - If we've reached here and the manager is not initialized, we should
138
+ // TODO: EDITOR-595 - If we've reached here and the manager is not initialized, we should
139
139
  // dispatch an analytics event to indicate that the user has clicked the button but
140
140
  // the action was not completed.
141
141
  return false;
@@ -149,17 +149,19 @@ export const buildToolbar = editorAnalyticsAPI => ({
149
149
  }
150
150
  });
151
151
  createCommentExperience === null || createCommentExperience === void 0 ? void 0 : createCommentExperience.initExperience.start();
152
- const {
153
- success
154
- } = annotationManager.startDraft();
155
- if (!success) {
156
- // TODO: EDITOR-188 - Report start draft attempt failed.
152
+ const result = annotationManager.startDraft();
153
+ if (result.success) {
154
+ // TODO: EDITOR-595 - Ensure and anlytic is fired to indicate that the user has started a draft.
155
+ } else {
156
+ // TODO: EDITOR-595 - Fire an analytics event to indicate that the user has clicked the button
157
+ // but the action was not completed, the result should contain a reason.
157
158
  }
158
159
  } else {
159
- // TODO: EDITOR-188 - Dispatch analytics event
160
+ // TODO: EDITOR-595 - Track the toolbar comment button was clicked but the preemptive gate
161
+ // check returned false and the draft cannot be started.
160
162
  }
161
163
  }).catch(() => {
162
- // TODO: EDITOR-188 - Handle preemptive gate check error and dispatch analytics event
164
+ // TODO: EDITOR-595 - Handle preemptive gate check error. Something went very wrong in the gate.
163
165
  });
164
166
  return true;
165
167
  } else {
@@ -8,5 +8,7 @@ export let ACTIONS = /*#__PURE__*/function (ACTIONS) {
8
8
  ACTIONS[ACTIONS["CLOSE_COMPONENT"] = 6] = "CLOSE_COMPONENT";
9
9
  ACTIONS[ACTIONS["SET_SELECTED_ANNOTATION"] = 7] = "SET_SELECTED_ANNOTATION";
10
10
  ACTIONS[ACTIONS["SET_HOVERED_ANNOTATION"] = 8] = "SET_HOVERED_ANNOTATION";
11
+ ACTIONS[ACTIONS["FLUSH_PENDING_SELECTIONS"] = 9] = "FLUSH_PENDING_SELECTIONS";
12
+ ACTIONS[ACTIONS["SET_PENDING_SELECTIONS"] = 10] = "SET_PENDING_SELECTIONS";
11
13
  return ACTIONS;
12
14
  }({});
@@ -44,6 +44,25 @@ export var clearDirtyMark = function clearDirtyMark() {
44
44
  type: ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK
45
45
  });
46
46
  };
47
+ export var flushPendingSelections = function flushPendingSelections(canSetAsSelectedAnnotations) {
48
+ return createCommand({
49
+ type: ACTIONS.FLUSH_PENDING_SELECTIONS,
50
+ data: {
51
+ canSetAsSelectedAnnotations: canSetAsSelectedAnnotations
52
+ }
53
+ });
54
+ };
55
+ export var setPendingSelectedAnnotation = function setPendingSelectedAnnotation(id) {
56
+ return createCommand({
57
+ type: ACTIONS.SET_PENDING_SELECTIONS,
58
+ data: {
59
+ selectedAnnotations: [{
60
+ id: id,
61
+ type: AnnotationTypes.INLINE_COMMENT
62
+ }]
63
+ }
64
+ });
65
+ };
47
66
  var removeInlineCommentFromNode = function removeInlineCommentFromNode(id) {
48
67
  var supportedBlockNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
49
68
  var state = arguments.length > 2 ? arguments[2] : undefined;
@@ -105,6 +124,34 @@ export var removeInlineCommentNearSelection = function removeInlineCommentNearSe
105
124
  return true;
106
125
  };
107
126
  };
127
+ export var removeInlineCommentFromDoc = function removeInlineCommentFromDoc(id) {
128
+ var supportedNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
129
+ return function (state, dispatch) {
130
+ var tr = state.tr;
131
+ state.doc.descendants(function (node, pos) {
132
+ // Inline comment on mediaInline is not supported as part of comments on media project
133
+ // Thus, we skip the decoration for mediaInline node
134
+ if (node.type.name === 'mediaInline') {
135
+ return false;
136
+ }
137
+ var isSupportedBlockNode = node.isBlock && (supportedNodes === null || supportedNodes === void 0 ? void 0 : supportedNodes.includes(node.type.name));
138
+ node.marks.filter(function (mark) {
139
+ return mark.type === state.schema.marks.annotation && mark.attrs.id === id;
140
+ }).forEach(function (mark) {
141
+ if (isSupportedBlockNode) {
142
+ tr.removeNodeMark(pos, mark);
143
+ } else {
144
+ tr.removeMark(pos, pos + node.nodeSize, mark);
145
+ }
146
+ });
147
+ });
148
+ if (dispatch) {
149
+ dispatch(tr);
150
+ return true;
151
+ }
152
+ return false;
153
+ };
154
+ };
108
155
  var getDraftCommandAction = function getDraftCommandAction(drafting, targetType, targetNodeId, supportedBlockNodes, isOpeningMediaCommentFromToolbar) {
109
156
  return function (editorState) {
110
157
  // validate selection only when entering draft mode
@@ -128,6 +175,8 @@ var getDraftCommandAction = function getDraftCommandAction(drafting, targetType,
128
175
  /**
129
176
  * Show active inline comments for a given block node, otherwise,
130
177
  * return false if the node has no comments or no unresolved comments.
178
+ * @param supportedBlockNodes
179
+ * @example
131
180
  */
132
181
  export var showInlineCommentForBlockNode = function showInlineCommentForBlockNode() {
133
182
  var supportedBlockNodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
@@ -1,13 +1,15 @@
1
1
  import { AnnotationTypes } from '@atlaskit/adf-schema';
2
- import { getRangeInlineNodeNames } from '@atlaskit/editor-common/utils';
2
+ import { getAnnotationInlineNodeTypes, getRangeInlineNodeNames } from '@atlaskit/editor-common/utils';
3
3
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
4
- import { setInlineCommentDraftState, createAnnotation } from '../editor-commands';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
5
+ import { setInlineCommentDraftState, createAnnotation, setSelectedAnnotation, closeComponent, setHoveredAnnotation, removeInlineCommentFromDoc } from '../editor-commands';
5
6
  import { AnnotationSelectionType } from '../types';
6
7
  import { inlineCommentPluginKey, isSelectionValid } from './utils';
7
8
  var ERROR_REASON_DRAFT_NOT_STARTED = 'draft-not-started';
8
9
  var ERROR_REASON_DRAFT_IN_PROGRESS = 'draft-in-progress';
9
10
  var ERROR_REASON_RANGE_MISSING = 'range-no-longer-exists';
10
11
  var ERROR_REASON_RANGE_INVALID = 'invalid-range';
12
+ var ERROR_REASON_ID_INVALID = 'id-not-valid';
11
13
  var domRefFromPos = function domRefFromPos(view, position) {
12
14
  var dom;
13
15
  try {
@@ -40,15 +42,34 @@ export var allowAnnotation = function allowAnnotation(editorView, options) {
40
42
  };
41
43
  export var startDraft = function startDraft(editorView, options) {
42
44
  return function () {
43
- var _getRangeInlineNodeNa, _options$annotationMa;
45
+ var _getRangeInlineNodeNa, _options$annotationMa2;
44
46
  var _ref2 = inlineCommentPluginKey.getState(editorView.state) || {},
45
- isDrafting = _ref2.isDrafting;
47
+ isDrafting = _ref2.isDrafting,
48
+ selectedAnnotations = _ref2.selectedAnnotations;
46
49
  if (isDrafting) {
47
50
  return {
48
51
  success: false,
49
52
  reason: ERROR_REASON_DRAFT_IN_PROGRESS
50
53
  };
51
54
  }
55
+ if (!!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.length) && fg('platform_editor_comments_api_manager_select')) {
56
+ // if there are selected annotations when starting a draft, we need to clear the selected annotations
57
+ // before we start the draft.
58
+ closeComponent()(editorView.state, editorView.dispatch);
59
+
60
+ // not only that but we need to also deselect any other annotations that are currently selected.
61
+ selectedAnnotations === null || selectedAnnotations === void 0 || selectedAnnotations.forEach(function (annotation) {
62
+ var _options$annotationMa, _getAnnotationInlineN;
63
+ (_options$annotationMa = options.annotationManager) === null || _options$annotationMa === void 0 || _options$annotationMa.emit({
64
+ name: 'annotationSelectionChanged',
65
+ data: {
66
+ annotationId: annotation.id,
67
+ isSelected: false,
68
+ inlineNodeTypes: (_getAnnotationInlineN = getAnnotationInlineNodeTypes(editorView.state, annotation.id)) !== null && _getAnnotationInlineN !== void 0 ? _getAnnotationInlineN : []
69
+ }
70
+ });
71
+ });
72
+ }
52
73
  setInlineCommentDraftState(options.editorAnalyticsAPI)(true)(editorView.state, editorView.dispatch);
53
74
  var _ref3 = inlineCommentPluginKey.getState(editorView.state) || {},
54
75
  draftDecorationSet = _ref3.draftDecorationSet;
@@ -70,7 +91,7 @@ export var startDraft = function startDraft(editorView, options) {
70
91
  to: decorations[decorations.length - 1].to
71
92
  }
72
93
  })) !== null && _getRangeInlineNodeNa !== void 0 ? _getRangeInlineNodeNa : [];
73
- (_options$annotationMa = options.annotationManager) === null || _options$annotationMa === void 0 || _options$annotationMa.emit({
94
+ (_options$annotationMa2 = options.annotationManager) === null || _options$annotationMa2 === void 0 || _options$annotationMa2.emit({
74
95
  name: 'draftAnnotationStarted',
75
96
  data: {
76
97
  targetElement: targetElement,
@@ -114,6 +135,7 @@ export var clearDraft = function clearDraft(editorView, options) {
114
135
  };
115
136
  export var applyDraft = function applyDraft(editorView, options) {
116
137
  return function (id) {
138
+ var _options$annotationMa3, _getAnnotationInlineN2;
117
139
  var _ref5 = inlineCommentPluginKey.getState(editorView.state) || {},
118
140
  isDrafting = _ref5.isDrafting,
119
141
  draftDecorationSet = _ref5.draftDecorationSet,
@@ -138,6 +160,17 @@ export var applyDraft = function applyDraft(editorView, options) {
138
160
  // Using the original decoration from position we should be able to locate the new target element.
139
161
  // This is because the new annotation will be created at the same position as the draft decoration.
140
162
  var targetElement = domRefFromPos(editorView, from);
163
+
164
+ // When a draft is applied it is automatically selected, so we need to set the selected annotation.
165
+ // emit the event for the selected annotation.
166
+ (_options$annotationMa3 = options.annotationManager) === null || _options$annotationMa3 === void 0 || _options$annotationMa3.emit({
167
+ name: 'annotationSelectionChanged',
168
+ data: {
169
+ annotationId: id,
170
+ isSelected: true,
171
+ inlineNodeTypes: (_getAnnotationInlineN2 = getAnnotationInlineNodeTypes(editorView.state, id)) !== null && _getAnnotationInlineN2 !== void 0 ? _getAnnotationInlineN2 : []
172
+ }
173
+ });
141
174
  return {
142
175
  success: true,
143
176
  // Get the dom element from the newly created annotation and return it here.
@@ -182,4 +215,133 @@ export var getDraft = function getDraft(editorView, options) {
182
215
  actionResult: undefined
183
216
  };
184
217
  };
218
+ };
219
+ export var setIsAnnotationSelected = function setIsAnnotationSelected(editorView, options) {
220
+ return function (id, isSelected) {
221
+ var _selectedAnnotations$;
222
+ var _ref7 = inlineCommentPluginKey.getState(editorView.state) || {},
223
+ annotations = _ref7.annotations,
224
+ isDrafting = _ref7.isDrafting,
225
+ selectedAnnotations = _ref7.selectedAnnotations;
226
+ if (isDrafting) {
227
+ return {
228
+ success: false,
229
+ reason: ERROR_REASON_DRAFT_IN_PROGRESS
230
+ };
231
+ }
232
+
233
+ // If there is no annotation state with this id then we can assume the annotation is invalid.
234
+ if (!(annotations !== null && annotations !== void 0 && annotations.hasOwnProperty(id))) {
235
+ return {
236
+ success: false,
237
+ reason: ERROR_REASON_ID_INVALID
238
+ };
239
+ }
240
+ var isCurrentlySelectedIndex = (_selectedAnnotations$ = selectedAnnotations === null || selectedAnnotations === void 0 ? void 0 : selectedAnnotations.findIndex(function (annotation) {
241
+ return annotation.id === id;
242
+ })) !== null && _selectedAnnotations$ !== void 0 ? _selectedAnnotations$ : -1;
243
+ var isCurrentlySelected = isCurrentlySelectedIndex !== -1;
244
+ if (isSelected !== isCurrentlySelected) {
245
+ // the annotation is selection is changing.
246
+ if (isCurrentlySelected && !isSelected) {
247
+ var _options$annotationMa4, _getAnnotationInlineN3;
248
+ // the selected annotaion is being unselected, so we need to close the view.
249
+ closeComponent()(editorView.state, editorView.dispatch);
250
+ (_options$annotationMa4 = options.annotationManager) === null || _options$annotationMa4 === void 0 || _options$annotationMa4.emit({
251
+ name: 'annotationSelectionChanged',
252
+ data: {
253
+ annotationId: id,
254
+ isSelected: false,
255
+ inlineNodeTypes: (_getAnnotationInlineN3 = getAnnotationInlineNodeTypes(editorView.state, id)) !== null && _getAnnotationInlineN3 !== void 0 ? _getAnnotationInlineN3 : []
256
+ }
257
+ });
258
+ } else if (!isCurrentlySelected && isSelected) {
259
+ var _options$annotationMa6, _getAnnotationInlineN5;
260
+ // the annotation is currently not selected and is being selected, so we need to open the view.
261
+ setSelectedAnnotation(id)(editorView.state, editorView.dispatch);
262
+
263
+ // the current annotations are going to be unselected. So we need to notify listeners of this change also.
264
+ selectedAnnotations === null || selectedAnnotations === void 0 || selectedAnnotations.forEach(function (annotation) {
265
+ if (annotation.id !== id) {
266
+ var _options$annotationMa5, _getAnnotationInlineN4;
267
+ (_options$annotationMa5 = options.annotationManager) === null || _options$annotationMa5 === void 0 || _options$annotationMa5.emit({
268
+ name: 'annotationSelectionChanged',
269
+ data: {
270
+ annotationId: annotation.id,
271
+ isSelected: false,
272
+ inlineNodeTypes: (_getAnnotationInlineN4 = getAnnotationInlineNodeTypes(editorView.state, annotation.id)) !== null && _getAnnotationInlineN4 !== void 0 ? _getAnnotationInlineN4 : []
273
+ }
274
+ });
275
+ }
276
+ });
277
+
278
+ // Lastly we need to emit the event for the selected annotation.
279
+ (_options$annotationMa6 = options.annotationManager) === null || _options$annotationMa6 === void 0 || _options$annotationMa6.emit({
280
+ name: 'annotationSelectionChanged',
281
+ data: {
282
+ annotationId: id,
283
+ isSelected: true,
284
+ inlineNodeTypes: (_getAnnotationInlineN5 = getAnnotationInlineNodeTypes(editorView.state, id)) !== null && _getAnnotationInlineN5 !== void 0 ? _getAnnotationInlineN5 : []
285
+ }
286
+ });
287
+ }
288
+ }
289
+ return {
290
+ success: true,
291
+ isSelected: isSelected
292
+ };
293
+ };
294
+ };
295
+ export var setIsAnnotationHovered = function setIsAnnotationHovered(editorView, options) {
296
+ return function (id, isHovered) {
297
+ var _hoveredAnnotations$f;
298
+ var _ref8 = inlineCommentPluginKey.getState(editorView.state) || {},
299
+ annotations = _ref8.annotations,
300
+ hoveredAnnotations = _ref8.hoveredAnnotations;
301
+
302
+ // If there is no annotation state with this id then we can assume the annotation is invalid.
303
+ if (!(annotations !== null && annotations !== void 0 && annotations.hasOwnProperty(id))) {
304
+ return {
305
+ success: false,
306
+ reason: ERROR_REASON_ID_INVALID
307
+ };
308
+ }
309
+ var isCurrentlyHoveredIndex = (_hoveredAnnotations$f = hoveredAnnotations === null || hoveredAnnotations === void 0 ? void 0 : hoveredAnnotations.findIndex(function (annotation) {
310
+ return annotation.id === id;
311
+ })) !== null && _hoveredAnnotations$f !== void 0 ? _hoveredAnnotations$f : -1;
312
+ var isCurrentlyHovered = isCurrentlyHoveredIndex !== -1;
313
+ if (isHovered !== isCurrentlyHovered) {
314
+ // the annotation in hovered is changing.
315
+ if (isCurrentlyHovered && !isHovered) {
316
+ // the hovered annotaion is being unhovered, so we should remove the hover state.
317
+ setHoveredAnnotation('')(editorView.state, editorView.dispatch);
318
+ } else if (!isCurrentlyHovered && isHovered) {
319
+ // the annotation is currently not hovered and is being hovered.
320
+ setHoveredAnnotation(id)(editorView.state, editorView.dispatch);
321
+ }
322
+ }
323
+ return {
324
+ success: true,
325
+ isHovered: isHovered
326
+ };
327
+ };
328
+ };
329
+ export var clearAnnotation = function clearAnnotation(editorView, options) {
330
+ return function (id) {
331
+ var _ref9 = inlineCommentPluginKey.getState(editorView.state) || {},
332
+ annotations = _ref9.annotations;
333
+
334
+ // If there is no annotation state with this id then we can assume the annotation is invalid.
335
+ if (!(annotations !== null && annotations !== void 0 && annotations.hasOwnProperty(id))) {
336
+ return {
337
+ success: false,
338
+ reason: ERROR_REASON_ID_INVALID
339
+ };
340
+ }
341
+ removeInlineCommentFromDoc(id, options.provider.supportedBlockNodes)(editorView.state, editorView.dispatch);
342
+ return {
343
+ success: true,
344
+ actionResult: undefined
345
+ };
346
+ };
185
347
  };