@atlaskit/editor-plugin-annotation 2.9.1 → 2.9.3

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 (30) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/editor-commands/index.js +40 -30
  3. package/dist/cjs/editor-commands/transform.js +33 -1
  4. package/dist/cjs/pm-plugins/annotation-manager-hooks.js +2 -3
  5. package/dist/cjs/pm-plugins/inline-comment.js +33 -35
  6. package/dist/cjs/pm-plugins/plugin-factory.js +5 -3
  7. package/dist/cjs/pm-plugins/reducer.js +2 -2
  8. package/dist/cjs/pm-plugins/toolbar.js +30 -26
  9. package/dist/cjs/ui/InlineCommentView.js +1 -2
  10. package/dist/es2019/editor-commands/index.js +13 -7
  11. package/dist/es2019/editor-commands/transform.js +27 -1
  12. package/dist/es2019/pm-plugins/annotation-manager-hooks.js +2 -3
  13. package/dist/es2019/pm-plugins/inline-comment.js +22 -25
  14. package/dist/es2019/pm-plugins/plugin-factory.js +5 -3
  15. package/dist/es2019/pm-plugins/reducer.js +2 -2
  16. package/dist/es2019/pm-plugins/toolbar.js +30 -26
  17. package/dist/esm/editor-commands/index.js +40 -30
  18. package/dist/esm/editor-commands/transform.js +33 -1
  19. package/dist/esm/pm-plugins/annotation-manager-hooks.js +2 -3
  20. package/dist/esm/pm-plugins/inline-comment.js +33 -35
  21. package/dist/esm/pm-plugins/plugin-factory.js +5 -3
  22. package/dist/esm/pm-plugins/reducer.js +2 -2
  23. package/dist/esm/pm-plugins/toolbar.js +30 -26
  24. package/dist/types/editor-commands/index.d.ts +2 -2
  25. package/dist/types/editor-commands/transform.d.ts +2 -0
  26. package/dist/types/pm-plugins/types.d.ts +4 -0
  27. package/dist/types-ts4.5/editor-commands/index.d.ts +2 -2
  28. package/dist/types-ts4.5/editor-commands/transform.d.ts +2 -0
  29. package/dist/types-ts4.5/pm-plugins/types.d.ts +4 -0
  30. package/package.json +3 -6
@@ -37,7 +37,7 @@ const fetchState = async (provider, annotationIds, editorView, editorAnalyticsAP
37
37
  updateInlineCommentResolvedState(editorAnalyticsAPI)(inlineCommentStates)(editorView.state, editorView.dispatch);
38
38
  }
39
39
  };
40
- const initialState = (disallowOnWhitespace = false, featureFlagsPluginState) => {
40
+ const initialState = (disallowOnWhitespace = false, featureFlagsPluginState, isAnnotationManagerEnabled = false) => {
41
41
  return {
42
42
  annotations: {},
43
43
  selectedAnnotations: [],
@@ -52,7 +52,8 @@ const initialState = (disallowOnWhitespace = false, featureFlagsPluginState) =>
52
52
  featureFlagsPluginState,
53
53
  isDrafting: false,
54
54
  pendingSelectedAnnotations: [],
55
- pendingSelectedAnnotationsUpdateCount: 0
55
+ pendingSelectedAnnotationsUpdateCount: 0,
56
+ isAnnotationManagerEnabled
56
57
  };
57
58
  };
58
59
  const hideToolbar = (state, dispatch) => () => {
@@ -104,7 +105,7 @@ export const inlineCommentPlugin = options => {
104
105
  } = options;
105
106
  return new SafePlugin({
106
107
  key: inlineCommentPluginKey,
107
- state: createPluginState(options.dispatch, initialState(provider.disallowOnWhitespace, featureFlagsPluginState)),
108
+ state: createPluginState(options.dispatch, initialState(provider.disallowOnWhitespace, featureFlagsPluginState, !!annotationManager)),
108
109
  view(editorView) {
109
110
  let allowAnnotationFn;
110
111
  let startDraftFn;
@@ -114,25 +115,23 @@ export const inlineCommentPlugin = options => {
114
115
  let setIsAnnotationSelectedFn;
115
116
  let setIsAnnotationHoveredFn;
116
117
  let clearAnnotationFn;
117
- if (annotationManager && fg('platform_editor_comments_api_manager')) {
118
+ if (annotationManager) {
118
119
  allowAnnotationFn = allowAnnotation(editorView, options);
119
120
  startDraftFn = startDraft(editorView, options);
120
121
  clearDraftFn = clearDraft(editorView, options);
121
122
  applyDraftFn = applyDraft(editorView, options);
122
123
  getDraftFn = getDraft(editorView, options);
124
+ setIsAnnotationSelectedFn = setIsAnnotationSelected(editorView, options);
125
+ setIsAnnotationHoveredFn = setIsAnnotationHovered(editorView, options);
126
+ clearAnnotationFn = clearAnnotation(editorView, options);
123
127
  annotationManager.hook('allowAnnotation', allowAnnotationFn);
124
128
  annotationManager.hook('startDraft', startDraftFn);
125
129
  annotationManager.hook('clearDraft', clearDraftFn);
126
130
  annotationManager.hook('applyDraft', applyDraftFn);
127
131
  annotationManager.hook('getDraft', getDraftFn);
128
- if (fg('platform_editor_comments_api_manager_select')) {
129
- setIsAnnotationSelectedFn = setIsAnnotationSelected(editorView, options);
130
- setIsAnnotationHoveredFn = setIsAnnotationHovered(editorView, options);
131
- clearAnnotationFn = clearAnnotation(editorView, options);
132
- annotationManager.hook('setIsAnnotationSelected', setIsAnnotationSelectedFn);
133
- annotationManager.hook('setIsAnnotationHovered', setIsAnnotationHoveredFn);
134
- annotationManager.hook('clearAnnotation', clearAnnotationFn);
135
- }
132
+ annotationManager.hook('setIsAnnotationSelected', setIsAnnotationSelectedFn);
133
+ annotationManager.hook('setIsAnnotationHovered', setIsAnnotationHoveredFn);
134
+ annotationManager.hook('clearAnnotation', clearAnnotationFn);
136
135
  }
137
136
  // Get initial state
138
137
  // Need to pass `editorView` to mitigate editor state going stale
@@ -213,7 +212,7 @@ export const inlineCommentPlugin = options => {
213
212
  // The selectComponentExperience is using a simplified object, which is why it's type asserted.
214
213
  (_options$selectCommen = options.selectCommentExperience) === null || _options$selectCommen === void 0 ? void 0 : _options$selectCommen.selectAnnotation.complete(selectedAnnotationId);
215
214
  }
216
- if (fg('platform_editor_comments_api_manager_select')) {
215
+ if (annotationManager) {
217
216
  // In the Editor, Annotations can be selected in three ways:
218
217
  // 1. By clicking on the annotation in the editor
219
218
  // 2. By using the annotation manager to select the annotation
@@ -233,7 +232,7 @@ export const inlineCommentPlugin = options => {
233
232
  // Need to set a lock to avoid calling gate multiple times. The lock will be released
234
233
  // when the preemptive gate is complete.
235
234
  isPreemptiveGateActive = true;
236
- annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.checkPreemptiveGate().then(canSelectAnnotation => {
235
+ annotationManager.checkPreemptiveGate().then(canSelectAnnotation => {
237
236
  const {
238
237
  isDrafting,
239
238
  pendingSelectedAnnotations: latestPendingSelectedAnnotations,
@@ -247,10 +246,10 @@ export const inlineCommentPlugin = options => {
247
246
  }
248
247
 
249
248
  // Flush the pending selections into the selected annotations list.
250
- flushPendingSelections(true)(view.state, view.dispatch);
249
+ flushPendingSelections(options.editorAnalyticsAPI)(true)(view.state, view.dispatch);
251
250
  latestSelectedAnnotations === null || latestSelectedAnnotations === void 0 ? void 0 : latestSelectedAnnotations.filter(annotation => (latestPendingSelectedAnnotations === null || latestPendingSelectedAnnotations === void 0 ? void 0 : latestPendingSelectedAnnotations.findIndex(pendingAnnotation => pendingAnnotation.id === annotation.id)) === -1).forEach(annotation => {
252
- var _options$annotationMa, _getAnnotationInlineN;
253
- (_options$annotationMa = options.annotationManager) === null || _options$annotationMa === void 0 ? void 0 : _options$annotationMa.emit({
251
+ var _getAnnotationInlineN;
252
+ annotationManager.emit({
254
253
  name: 'annotationSelectionChanged',
255
254
  data: {
256
255
  annotationId: annotation.id,
@@ -264,8 +263,8 @@ export const inlineCommentPlugin = options => {
264
263
  latestPendingSelectedAnnotations === null || latestPendingSelectedAnnotations === void 0 ? void 0 : latestPendingSelectedAnnotations.forEach(({
265
264
  id
266
265
  }) => {
267
- var _options$annotationMa2, _getAnnotationInlineN2;
268
- (_options$annotationMa2 = options.annotationManager) === null || _options$annotationMa2 === void 0 ? void 0 : _options$annotationMa2.emit({
266
+ var _getAnnotationInlineN2;
267
+ annotationManager.emit({
269
268
  name: 'annotationSelectionChanged',
270
269
  data: {
271
270
  annotationId: id,
@@ -278,13 +277,11 @@ export const inlineCommentPlugin = options => {
278
277
  // Clears the pending selections if the preemptive gate returns false.
279
278
  // We should need to worry about dispatching change events here because the pending selections
280
279
  // are being aborted and the selections will remain unchanged.
281
- flushPendingSelections(false)(view.state, view.dispatch);
280
+ flushPendingSelections(options.editorAnalyticsAPI)(false)(view.state, view.dispatch);
282
281
  }
283
282
  }).catch(error => {
284
- // TODO: EDITOR-595 - Ensure and anlytic is fired to indicate which reports on the error.
285
-
286
283
  // If an error has occured we will clear any pending selections to avoid accidentally setting the wrong thing.
287
- flushPendingSelections(false)(view.state, view.dispatch);
284
+ flushPendingSelections(options.editorAnalyticsAPI)(false, 'pending-selection-preemptive-gate-error')(view.state, view.dispatch);
288
285
  }).finally(() => {
289
286
  isPreemptiveGateActive = false;
290
287
  });
@@ -305,7 +302,7 @@ export const inlineCommentPlugin = options => {
305
302
  if (updateSubscriber) {
306
303
  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).off('closeinlinecomment', closeInlineCommentFn);
307
304
  }
308
- if (annotationManager && fg('platform_editor_comments_api_manager')) {
305
+ if (annotationManager) {
309
306
  annotationManager.unhook('allowAnnotation', allowAnnotationFn);
310
307
  annotationManager.unhook('startDraft', startDraftFn);
311
308
  annotationManager.unhook('clearDraft', clearDraftFn);
@@ -360,7 +357,7 @@ export const inlineCommentPlugin = options => {
360
357
  if (!isUnresolved) {
361
358
  return false;
362
359
  }
363
- if (fg('platform_editor_comments_api_manager_select')) {
360
+ if (annotationManager) {
364
361
  var _pluginState$pendingS;
365
362
  // The manager disable setting the selected annotation on click because in the editor this is already
366
363
  // handled by the selection update handler. When the manager is enabled, and a selection changes it's pushed into
@@ -1,7 +1,6 @@
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';
5
4
  import reducer from './reducer';
6
5
  import { decorationKey, findAnnotationsInSelection, inlineCommentPluginKey, isBlockNodeAnnotationsSelected, isSelectedAnnotationsChanged } from './utils';
7
6
  const handleDocChanged = (tr, prevPluginState) => {
@@ -111,7 +110,6 @@ const getSelectionChangeHandlerNew = reopenCommentView => (tr, pluginState) => {
111
110
 
112
111
  // NOTE: I've left this commented code here as a reference that the previous old code would reset the selected annotations
113
112
  // 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
113
  // if (selectedAnnotations.length === 0) {
116
114
  // return {
117
115
  // ...pluginState,
@@ -141,7 +139,11 @@ const getSelectionChangeHandlerNew = reopenCommentView => (tr, pluginState) => {
141
139
  selectAnnotationMethod: undefined
142
140
  };
143
141
  };
144
- const getSelectionChangedHandler = reopenCommentView => (tr, pluginState) => fg('platform_editor_comments_api_manager_select') ? getSelectionChangeHandlerNew(reopenCommentView)(tr, pluginState) : getSelectionChangeHandlerOld(reopenCommentView)(tr, pluginState);
142
+ const getSelectionChangedHandler = reopenCommentView => (tr, pluginState) => pluginState.isAnnotationManagerEnabled ?
143
+ // if platform_editor_comments_api_manager == true
144
+ getSelectionChangeHandlerNew(reopenCommentView)(tr, pluginState) :
145
+ // else if platform_editor_comments_api_manager == false
146
+ getSelectionChangeHandlerOld(reopenCommentView)(tr, pluginState);
145
147
  export const {
146
148
  createPluginState,
147
149
  createCommand
@@ -35,7 +35,7 @@ export default ((pluginState, action) => {
35
35
  ...(fg('platform_editor_annotation_selected_annotation') && {
36
36
  selectedAnnotations: []
37
37
  }),
38
- ...(fg('platform_editor_comments_api_manager_select') && {
38
+ ...(pluginState.isAnnotationManagerEnabled && {
39
39
  selectedAnnotations: []
40
40
  })
41
41
  };
@@ -50,7 +50,7 @@ export default ((pluginState, action) => {
50
50
  },
51
51
  isInlineCommentViewClosed: false,
52
52
  selectAnnotationMethod: undefined,
53
- ...(fg('platform_editor_comments_api_manager_select') && {
53
+ ...(pluginState.isAnnotationManagerEnabled && {
54
54
  skipSelectionHandling: true
55
55
  })
56
56
  };
@@ -121,25 +121,17 @@ export const buildToolbar = editorAnalyticsAPI => ({
121
121
  }
122
122
  },
123
123
  onClick: (state, dispatch) => {
124
- if (editorAnalyticsAPI) {
125
- editorAnalyticsAPI.fireAnalyticsEvent({
126
- action: ACTION.CLICKED,
127
- actionSubject: ACTION_SUBJECT.BUTTON,
128
- actionSubjectId: ACTION_SUBJECT_ID.CREATE_INLINE_COMMENT_FROM_HIGHLIGHT_ACTIONS_MENU,
129
- eventType: EVENT_TYPE.UI,
130
- attributes: {
131
- source: 'highlightActionsMenu',
132
- pageMode: 'edit'
133
- }
134
- });
135
- }
136
- if (fg('platform_editor_comments_api_manager')) {
137
- if (!annotationManager) {
138
- // TODO: EDITOR-595 - If we've reached here and the manager is not initialized, we should
139
- // dispatch an analytics event to indicate that the user has clicked the button but
140
- // the action was not completed.
141
- return false;
124
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.fireAnalyticsEvent({
125
+ action: ACTION.CLICKED,
126
+ actionSubject: ACTION_SUBJECT.BUTTON,
127
+ actionSubjectId: ACTION_SUBJECT_ID.CREATE_INLINE_COMMENT_FROM_HIGHLIGHT_ACTIONS_MENU,
128
+ eventType: EVENT_TYPE.UI,
129
+ attributes: {
130
+ source: 'highlightActionsMenu',
131
+ pageMode: 'edit'
142
132
  }
133
+ });
134
+ if (annotationManager) {
143
135
  annotationManager.checkPreemptiveGate().then(canStartDraft => {
144
136
  if (canStartDraft) {
145
137
  createCommentExperience === null || createCommentExperience === void 0 ? void 0 : createCommentExperience.start({
@@ -150,18 +142,30 @@ export const buildToolbar = editorAnalyticsAPI => ({
150
142
  });
151
143
  createCommentExperience === null || createCommentExperience === void 0 ? void 0 : createCommentExperience.initExperience.start();
152
144
  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
145
+ if (!result.success) {
146
+ // Fire an analytics event to indicate that the user has clicked the button
157
147
  // but the action was not completed, the result should contain a reason.
148
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.fireAnalyticsEvent({
149
+ action: ACTION.ERROR,
150
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
151
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
152
+ eventType: EVENT_TYPE.OPERATIONAL,
153
+ attributes: {
154
+ errorReason: `toolbar-start-draft-failed/${result.reason}`
155
+ }
156
+ });
158
157
  }
159
- } else {
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.
162
158
  }
163
159
  }).catch(() => {
164
- // TODO: EDITOR-595 - Handle preemptive gate check error. Something went very wrong in the gate.
160
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.fireAnalyticsEvent({
161
+ action: ACTION.ERROR,
162
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
163
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
164
+ eventType: EVENT_TYPE.OPERATIONAL,
165
+ attributes: {
166
+ errorReason: `toolbar-start-draft-preemptive-gate-error`
167
+ }
168
+ });
165
169
  });
166
170
  return true;
167
171
  } else {
@@ -44,13 +44,21 @@ 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
47
+ export var flushPendingSelections = function flushPendingSelections(editorAnalyticsAPI) {
48
+ return function (canSetAsSelectedAnnotations, errorReason) {
49
+ var command = {
50
+ type: ACTIONS.FLUSH_PENDING_SELECTIONS,
51
+ data: {
52
+ canSetAsSelectedAnnotations: canSetAsSelectedAnnotations
53
+ }
54
+ };
55
+ if (!!errorReason) {
56
+ return createCommand(command, function (tr, state) {
57
+ return transform.addPreemptiveGateErrorAnalytics(editorAnalyticsAPI)(errorReason)(tr, state);
58
+ });
52
59
  }
53
- });
60
+ return createCommand(command);
61
+ };
54
62
  };
55
63
  export var setPendingSelectedAnnotation = function setPendingSelectedAnnotation(id) {
56
64
  return createCommand({
@@ -124,32 +132,34 @@ export var removeInlineCommentNearSelection = function removeInlineCommentNearSe
124
132
  return true;
125
133
  };
126
134
  };
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);
135
+ export var removeInlineCommentFromDoc = function removeInlineCommentFromDoc(editorAnalyticsAPI) {
136
+ return function (id) {
137
+ var supportedNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
138
+ return function (state, dispatch) {
139
+ var tr = state.tr;
140
+ state.doc.descendants(function (node, pos) {
141
+ // Inline comment on mediaInline is not supported as part of comments on media project
142
+ // Thus, we skip the decoration for mediaInline node
143
+ if (node.type.name === 'mediaInline') {
144
+ return false;
145
145
  }
146
+ var isSupportedBlockNode = node.isBlock && (supportedNodes === null || supportedNodes === void 0 ? void 0 : supportedNodes.includes(node.type.name));
147
+ node.marks.filter(function (mark) {
148
+ return mark.type === state.schema.marks.annotation && mark.attrs.id === id;
149
+ }).forEach(function (mark) {
150
+ if (isSupportedBlockNode) {
151
+ tr.removeNodeMark(pos, mark);
152
+ } else {
153
+ tr.removeMark(pos, pos + node.nodeSize, mark);
154
+ }
155
+ });
146
156
  });
147
- });
148
- if (dispatch) {
149
- dispatch(tr);
150
- return true;
151
- }
152
- return false;
157
+ if (dispatch) {
158
+ dispatch(transform.addDeleteAnalytics(editorAnalyticsAPI)(tr, state));
159
+ return true;
160
+ }
161
+ return false;
162
+ };
153
163
  };
154
164
  };
155
165
  var getDraftCommandAction = function getDraftCommandAction(drafting, targetType, targetNodeId, supportedBlockNodes, isOpeningMediaCommentFromToolbar) {
@@ -130,11 +130,43 @@ var addResolveAnalytics = function addResolveAnalytics(editorAnalyticsAPI) {
130
130
  };
131
131
  };
132
132
  };
133
+ var addPreemptiveGateErrorAnalytics = function addPreemptiveGateErrorAnalytics(editorAnalyticsAPI) {
134
+ return function (errorReason) {
135
+ return function (transaction, state) {
136
+ var analyticsEvent = {
137
+ action: ACTION.ERROR,
138
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
139
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
140
+ eventType: EVENT_TYPE.OPERATIONAL,
141
+ attributes: {
142
+ errorReason: errorReason
143
+ }
144
+ };
145
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(analyticsEvent)(transaction);
146
+ return transaction;
147
+ };
148
+ };
149
+ };
150
+ var addDeleteAnalytics = function addDeleteAnalytics(editorAnalyticsAPI) {
151
+ return function (transaction, state) {
152
+ var analyticsEvent = {
153
+ action: ACTION.DELETED,
154
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
155
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
156
+ eventType: EVENT_TYPE.TRACK,
157
+ attributes: {}
158
+ };
159
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(analyticsEvent)(transaction);
160
+ return transaction;
161
+ };
162
+ };
133
163
  export default {
134
164
  addAnnotationMark: addAnnotationMark,
135
165
  addInlineComment: addInlineComment,
136
166
  handleDraftState: handleDraftState,
137
167
  addOpenCloseAnalytics: addOpenCloseAnalytics,
138
168
  addInsertAnalytics: addInsertAnalytics,
139
- addResolveAnalytics: addResolveAnalytics
169
+ addResolveAnalytics: addResolveAnalytics,
170
+ addPreemptiveGateErrorAnalytics: addPreemptiveGateErrorAnalytics,
171
+ addDeleteAnalytics: addDeleteAnalytics
140
172
  };
@@ -1,7 +1,6 @@
1
1
  import { AnnotationTypes } from '@atlaskit/adf-schema';
2
2
  import { getAnnotationInlineNodeTypes, getRangeInlineNodeNames } from '@atlaskit/editor-common/utils';
3
3
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
4
- import { fg } from '@atlaskit/platform-feature-flags';
5
4
  import { setInlineCommentDraftState, createAnnotation, setSelectedAnnotation, closeComponent, setHoveredAnnotation, removeInlineCommentFromDoc } from '../editor-commands';
6
5
  import { AnnotationSelectionType } from '../types';
7
6
  import { inlineCommentPluginKey, isSelectionValid } from './utils';
@@ -52,7 +51,7 @@ export var startDraft = function startDraft(editorView, options) {
52
51
  reason: ERROR_REASON_DRAFT_IN_PROGRESS
53
52
  };
54
53
  }
55
- if (!!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.length) && fg('platform_editor_comments_api_manager_select')) {
54
+ if (!!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.length)) {
56
55
  // if there are selected annotations when starting a draft, we need to clear the selected annotations
57
56
  // before we start the draft.
58
57
  closeComponent()(editorView.state, editorView.dispatch);
@@ -338,7 +337,7 @@ export var clearAnnotation = function clearAnnotation(editorView, options) {
338
337
  reason: ERROR_REASON_ID_INVALID
339
338
  };
340
339
  }
341
- removeInlineCommentFromDoc(id, options.provider.supportedBlockNodes)(editorView.state, editorView.dispatch);
340
+ removeInlineCommentFromDoc(options.editorAnalyticsAPI)(id, options.provider.supportedBlockNodes)(editorView.state, editorView.dispatch);
342
341
  return {
343
342
  success: true,
344
343
  actionResult: undefined
@@ -86,6 +86,7 @@ var fetchState = /*#__PURE__*/function () {
86
86
  var initialState = function initialState() {
87
87
  var disallowOnWhitespace = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
88
88
  var featureFlagsPluginState = arguments.length > 1 ? arguments[1] : undefined;
89
+ var isAnnotationManagerEnabled = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
89
90
  return {
90
91
  annotations: {},
91
92
  selectedAnnotations: [],
@@ -100,7 +101,8 @@ var initialState = function initialState() {
100
101
  featureFlagsPluginState: featureFlagsPluginState,
101
102
  isDrafting: false,
102
103
  pendingSelectedAnnotations: [],
103
- pendingSelectedAnnotationsUpdateCount: 0
104
+ pendingSelectedAnnotationsUpdateCount: 0,
105
+ isAnnotationManagerEnabled: isAnnotationManagerEnabled
104
106
  };
105
107
  };
106
108
  var hideToolbar = function hideToolbar(state, dispatch) {
@@ -157,7 +159,7 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
157
159
  annotationManager = options.annotationManager;
158
160
  return new SafePlugin({
159
161
  key: inlineCommentPluginKey,
160
- state: createPluginState(options.dispatch, initialState(provider.disallowOnWhitespace, featureFlagsPluginState)),
162
+ state: createPluginState(options.dispatch, initialState(provider.disallowOnWhitespace, featureFlagsPluginState, !!annotationManager)),
161
163
  view: function view(editorView) {
162
164
  var allowAnnotationFn;
163
165
  var startDraftFn;
@@ -167,25 +169,23 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
167
169
  var setIsAnnotationSelectedFn;
168
170
  var setIsAnnotationHoveredFn;
169
171
  var clearAnnotationFn;
170
- if (annotationManager && fg('platform_editor_comments_api_manager')) {
172
+ if (annotationManager) {
171
173
  allowAnnotationFn = allowAnnotation(editorView, options);
172
174
  startDraftFn = startDraft(editorView, options);
173
175
  clearDraftFn = clearDraft(editorView, options);
174
176
  applyDraftFn = applyDraft(editorView, options);
175
177
  getDraftFn = getDraft(editorView, options);
178
+ setIsAnnotationSelectedFn = setIsAnnotationSelected(editorView, options);
179
+ setIsAnnotationHoveredFn = setIsAnnotationHovered(editorView, options);
180
+ clearAnnotationFn = clearAnnotation(editorView, options);
176
181
  annotationManager.hook('allowAnnotation', allowAnnotationFn);
177
182
  annotationManager.hook('startDraft', startDraftFn);
178
183
  annotationManager.hook('clearDraft', clearDraftFn);
179
184
  annotationManager.hook('applyDraft', applyDraftFn);
180
185
  annotationManager.hook('getDraft', getDraftFn);
181
- if (fg('platform_editor_comments_api_manager_select')) {
182
- setIsAnnotationSelectedFn = setIsAnnotationSelected(editorView, options);
183
- setIsAnnotationHoveredFn = setIsAnnotationHovered(editorView, options);
184
- clearAnnotationFn = clearAnnotation(editorView, options);
185
- annotationManager.hook('setIsAnnotationSelected', setIsAnnotationSelectedFn);
186
- annotationManager.hook('setIsAnnotationHovered', setIsAnnotationHoveredFn);
187
- annotationManager.hook('clearAnnotation', clearAnnotationFn);
188
- }
186
+ annotationManager.hook('setIsAnnotationSelected', setIsAnnotationSelectedFn);
187
+ annotationManager.hook('setIsAnnotationHovered', setIsAnnotationHoveredFn);
188
+ annotationManager.hook('clearAnnotation', clearAnnotationFn);
189
189
  }
190
190
  // Get initial state
191
191
  // Need to pass `editorView` to mitigate editor state going stale
@@ -270,7 +270,7 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
270
270
  // The selectComponentExperience is using a simplified object, which is why it's type asserted.
271
271
  (_options$selectCommen = options.selectCommentExperience) === null || _options$selectCommen === void 0 || _options$selectCommen.selectAnnotation.complete(selectedAnnotationId);
272
272
  }
273
- if (fg('platform_editor_comments_api_manager_select')) {
273
+ if (annotationManager) {
274
274
  // In the Editor, Annotations can be selected in three ways:
275
275
  // 1. By clicking on the annotation in the editor
276
276
  // 2. By using the annotation manager to select the annotation
@@ -288,7 +288,7 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
288
288
  // Need to set a lock to avoid calling gate multiple times. The lock will be released
289
289
  // when the preemptive gate is complete.
290
290
  isPreemptiveGateActive = true;
291
- annotationManager === null || annotationManager === void 0 || annotationManager.checkPreemptiveGate().then(function (canSelectAnnotation) {
291
+ annotationManager.checkPreemptiveGate().then(function (canSelectAnnotation) {
292
292
  var _ref8 = getPluginState(view.state) || {},
293
293
  isDrafting = _ref8.isDrafting,
294
294
  latestPendingSelectedAnnotations = _ref8.pendingSelectedAnnotations,
@@ -301,14 +301,14 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
301
301
  }
302
302
 
303
303
  // Flush the pending selections into the selected annotations list.
304
- flushPendingSelections(true)(view.state, view.dispatch);
304
+ flushPendingSelections(options.editorAnalyticsAPI)(true)(view.state, view.dispatch);
305
305
  latestSelectedAnnotations === null || latestSelectedAnnotations === void 0 || latestSelectedAnnotations.filter(function (annotation) {
306
306
  return (latestPendingSelectedAnnotations === null || latestPendingSelectedAnnotations === void 0 ? void 0 : latestPendingSelectedAnnotations.findIndex(function (pendingAnnotation) {
307
307
  return pendingAnnotation.id === annotation.id;
308
308
  })) === -1;
309
309
  }).forEach(function (annotation) {
310
- var _options$annotationMa, _getAnnotationInlineN;
311
- (_options$annotationMa = options.annotationManager) === null || _options$annotationMa === void 0 || _options$annotationMa.emit({
310
+ var _getAnnotationInlineN;
311
+ annotationManager.emit({
312
312
  name: 'annotationSelectionChanged',
313
313
  data: {
314
314
  annotationId: annotation.id,
@@ -320,9 +320,9 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
320
320
 
321
321
  // Notify the annotation manager that the pending selection has changed.
322
322
  latestPendingSelectedAnnotations === null || latestPendingSelectedAnnotations === void 0 || latestPendingSelectedAnnotations.forEach(function (_ref9) {
323
- var _options$annotationMa2, _getAnnotationInlineN2;
323
+ var _getAnnotationInlineN2;
324
324
  var id = _ref9.id;
325
- (_options$annotationMa2 = options.annotationManager) === null || _options$annotationMa2 === void 0 || _options$annotationMa2.emit({
325
+ annotationManager.emit({
326
326
  name: 'annotationSelectionChanged',
327
327
  data: {
328
328
  annotationId: id,
@@ -335,20 +335,18 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
335
335
  // Clears the pending selections if the preemptive gate returns false.
336
336
  // We should need to worry about dispatching change events here because the pending selections
337
337
  // are being aborted and the selections will remain unchanged.
338
- flushPendingSelections(false)(view.state, view.dispatch);
338
+ flushPendingSelections(options.editorAnalyticsAPI)(false)(view.state, view.dispatch);
339
339
  }
340
340
  }).catch(function (error) {
341
- // TODO: EDITOR-595 - Ensure and anlytic is fired to indicate which reports on the error.
342
-
343
341
  // If an error has occured we will clear any pending selections to avoid accidentally setting the wrong thing.
344
- flushPendingSelections(false)(view.state, view.dispatch);
342
+ flushPendingSelections(options.editorAnalyticsAPI)(false, 'pending-selection-preemptive-gate-error')(view.state, view.dispatch);
345
343
  }).finally(function () {
346
344
  isPreemptiveGateActive = false;
347
345
  });
348
346
  }
349
347
  }
350
- var _ref10 = getPluginState(view.state) || {},
351
- dirtyAnnotations = _ref10.dirtyAnnotations;
348
+ var _ref0 = getPluginState(view.state) || {},
349
+ dirtyAnnotations = _ref0.dirtyAnnotations;
352
350
  if (!dirtyAnnotations) {
353
351
  return;
354
352
  }
@@ -361,7 +359,7 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
361
359
  if (updateSubscriber) {
362
360
  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).off('closeinlinecomment', closeInlineCommentFn);
363
361
  }
364
- if (annotationManager && fg('platform_editor_comments_api_manager')) {
362
+ if (annotationManager) {
365
363
  annotationManager.unhook('allowAnnotation', allowAnnotationFn);
366
364
  annotationManager.unhook('startDraft', startDraftFn);
367
365
  annotationManager.unhook('clearDraft', clearDraftFn);
@@ -411,13 +409,13 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
411
409
  if (isSelected && !(pluginState !== null && pluginState !== void 0 && pluginState.isInlineCommentViewClosed)) {
412
410
  return false;
413
411
  }
414
- var _ref11 = pluginState || {},
415
- annotations = _ref11.annotations;
412
+ var _ref1 = pluginState || {},
413
+ annotations = _ref1.annotations;
416
414
  var isUnresolved = annotations && annotations[annotationId] === false;
417
415
  if (!isUnresolved) {
418
416
  return false;
419
417
  }
420
- if (fg('platform_editor_comments_api_manager_select')) {
418
+ if (annotationManager) {
421
419
  var _pluginState$pendingS;
422
420
  // The manager disable setting the selected annotation on click because in the editor this is already
423
421
  // handled by the selection update handler. When the manager is enabled, and a selection changes it's pushed into
@@ -440,13 +438,13 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
440
438
  },
441
439
  decorations: function decorations(state) {
442
440
  // highlight comments, depending on state
443
- var _ref12 = getPluginState(state) || {},
444
- draftDecorationSet = _ref12.draftDecorationSet,
445
- annotations = _ref12.annotations,
446
- selectedAnnotations = _ref12.selectedAnnotations,
447
- isVisible = _ref12.isVisible,
448
- isInlineCommentViewClosed = _ref12.isInlineCommentViewClosed,
449
- hoveredAnnotations = _ref12.hoveredAnnotations;
441
+ var _ref10 = getPluginState(state) || {},
442
+ draftDecorationSet = _ref10.draftDecorationSet,
443
+ annotations = _ref10.annotations,
444
+ selectedAnnotations = _ref10.selectedAnnotations,
445
+ isVisible = _ref10.isVisible,
446
+ isInlineCommentViewClosed = _ref10.isInlineCommentViewClosed,
447
+ hoveredAnnotations = _ref10.hoveredAnnotations;
450
448
  var decorations = draftDecorationSet !== null && draftDecorationSet !== void 0 ? draftDecorationSet : DecorationSet.empty;
451
449
  var focusDecorations = [];
452
450
 
@@ -4,7 +4,6 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  import { pluginFactory } from '@atlaskit/editor-common/utils';
5
5
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
6
6
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
- import { fg } from '@atlaskit/platform-feature-flags';
8
7
  import reducer from './reducer';
9
8
  import { decorationKey, findAnnotationsInSelection, inlineCommentPluginKey, isBlockNodeAnnotationsSelected, isSelectedAnnotationsChanged } from './utils';
10
9
  var handleDocChanged = function handleDocChanged(tr, prevPluginState) {
@@ -104,7 +103,6 @@ var getSelectionChangeHandlerNew = function getSelectionChangeHandlerNew(reopenC
104
103
 
105
104
  // NOTE: I've left this commented code here as a reference that the previous old code would reset the selected annotations
106
105
  // if the selection is empty. If this is no longer needed, we can remove this code.
107
- // clean up with platform_editor_comments_api_manager_select
108
106
  // if (selectedAnnotations.length === 0) {
109
107
  // return {
110
108
  // ...pluginState,
@@ -133,7 +131,11 @@ var getSelectionChangeHandlerNew = function getSelectionChangeHandlerNew(reopenC
133
131
  };
134
132
  var getSelectionChangedHandler = function getSelectionChangedHandler(reopenCommentView) {
135
133
  return function (tr, pluginState) {
136
- return fg('platform_editor_comments_api_manager_select') ? getSelectionChangeHandlerNew(reopenCommentView)(tr, pluginState) : getSelectionChangeHandlerOld(reopenCommentView)(tr, pluginState);
134
+ return pluginState.isAnnotationManagerEnabled ?
135
+ // if platform_editor_comments_api_manager == true
136
+ getSelectionChangeHandlerNew(reopenCommentView)(tr, pluginState) :
137
+ // else if platform_editor_comments_api_manager == false
138
+ getSelectionChangeHandlerOld(reopenCommentView)(tr, pluginState);
137
139
  };
138
140
  };
139
141
  var _pluginFactory = pluginFactory(inlineCommentPluginKey, reducer, {