@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @atlaskit/editor-plugin-annotation
2
2
 
3
+ ## 2.9.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#163361](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/163361)
8
+ [`76c3619bccda1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/76c3619bccda1) -
9
+ Changed the annotation manager feature gate to instead use the existance of the manager rather
10
+ then a gate
11
+ - Updated dependencies
12
+
13
+ ## 2.9.2
14
+
15
+ ### Patch Changes
16
+
17
+ - [#162493](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/162493)
18
+ [`e2fed6abf826b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e2fed6abf826b) -
19
+ Added some error reporting anayltics for the new annotation manager
20
+ - Updated dependencies
21
+
3
22
  ## 2.9.1
4
23
 
5
24
  ### Patch Changes
@@ -51,13 +51,21 @@ var clearDirtyMark = exports.clearDirtyMark = function clearDirtyMark() {
51
51
  type: _types.ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK
52
52
  });
53
53
  };
54
- var flushPendingSelections = exports.flushPendingSelections = function flushPendingSelections(canSetAsSelectedAnnotations) {
55
- return (0, _pluginFactory.createCommand)({
56
- type: _types.ACTIONS.FLUSH_PENDING_SELECTIONS,
57
- data: {
58
- canSetAsSelectedAnnotations: canSetAsSelectedAnnotations
54
+ var flushPendingSelections = exports.flushPendingSelections = function flushPendingSelections(editorAnalyticsAPI) {
55
+ return function (canSetAsSelectedAnnotations, errorReason) {
56
+ var command = {
57
+ type: _types.ACTIONS.FLUSH_PENDING_SELECTIONS,
58
+ data: {
59
+ canSetAsSelectedAnnotations: canSetAsSelectedAnnotations
60
+ }
61
+ };
62
+ if (!!errorReason) {
63
+ return (0, _pluginFactory.createCommand)(command, function (tr, state) {
64
+ return _transform.default.addPreemptiveGateErrorAnalytics(editorAnalyticsAPI)(errorReason)(tr, state);
65
+ });
59
66
  }
60
- });
67
+ return (0, _pluginFactory.createCommand)(command);
68
+ };
61
69
  };
62
70
  var setPendingSelectedAnnotation = exports.setPendingSelectedAnnotation = function setPendingSelectedAnnotation(id) {
63
71
  return (0, _pluginFactory.createCommand)({
@@ -131,32 +139,34 @@ var removeInlineCommentNearSelection = exports.removeInlineCommentNearSelection
131
139
  return true;
132
140
  };
133
141
  };
134
- var removeInlineCommentFromDoc = exports.removeInlineCommentFromDoc = function removeInlineCommentFromDoc(id) {
135
- var supportedNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
136
- return function (state, dispatch) {
137
- var tr = state.tr;
138
- state.doc.descendants(function (node, pos) {
139
- // Inline comment on mediaInline is not supported as part of comments on media project
140
- // Thus, we skip the decoration for mediaInline node
141
- if (node.type.name === 'mediaInline') {
142
- return false;
143
- }
144
- var isSupportedBlockNode = node.isBlock && (supportedNodes === null || supportedNodes === void 0 ? void 0 : supportedNodes.includes(node.type.name));
145
- node.marks.filter(function (mark) {
146
- return mark.type === state.schema.marks.annotation && mark.attrs.id === id;
147
- }).forEach(function (mark) {
148
- if (isSupportedBlockNode) {
149
- tr.removeNodeMark(pos, mark);
150
- } else {
151
- tr.removeMark(pos, pos + node.nodeSize, mark);
142
+ var removeInlineCommentFromDoc = exports.removeInlineCommentFromDoc = function removeInlineCommentFromDoc(editorAnalyticsAPI) {
143
+ return function (id) {
144
+ var supportedNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
145
+ return function (state, dispatch) {
146
+ var tr = state.tr;
147
+ state.doc.descendants(function (node, pos) {
148
+ // Inline comment on mediaInline is not supported as part of comments on media project
149
+ // Thus, we skip the decoration for mediaInline node
150
+ if (node.type.name === 'mediaInline') {
151
+ return false;
152
152
  }
153
+ var isSupportedBlockNode = node.isBlock && (supportedNodes === null || supportedNodes === void 0 ? void 0 : supportedNodes.includes(node.type.name));
154
+ node.marks.filter(function (mark) {
155
+ return mark.type === state.schema.marks.annotation && mark.attrs.id === id;
156
+ }).forEach(function (mark) {
157
+ if (isSupportedBlockNode) {
158
+ tr.removeNodeMark(pos, mark);
159
+ } else {
160
+ tr.removeMark(pos, pos + node.nodeSize, mark);
161
+ }
162
+ });
153
163
  });
154
- });
155
- if (dispatch) {
156
- dispatch(tr);
157
- return true;
158
- }
159
- return false;
164
+ if (dispatch) {
165
+ dispatch(_transform.default.addDeleteAnalytics(editorAnalyticsAPI)(tr, state));
166
+ return true;
167
+ }
168
+ return false;
169
+ };
160
170
  };
161
171
  };
162
172
  var getDraftCommandAction = function getDraftCommandAction(drafting, targetType, targetNodeId, supportedBlockNodes, isOpeningMediaCommentFromToolbar) {
@@ -136,11 +136,43 @@ var addResolveAnalytics = function addResolveAnalytics(editorAnalyticsAPI) {
136
136
  };
137
137
  };
138
138
  };
139
+ var addPreemptiveGateErrorAnalytics = function addPreemptiveGateErrorAnalytics(editorAnalyticsAPI) {
140
+ return function (errorReason) {
141
+ return function (transaction, state) {
142
+ var analyticsEvent = {
143
+ action: _analytics.ACTION.ERROR,
144
+ actionSubject: _analytics.ACTION_SUBJECT.ANNOTATION,
145
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.INLINE_COMMENT,
146
+ eventType: _analytics.EVENT_TYPE.OPERATIONAL,
147
+ attributes: {
148
+ errorReason: errorReason
149
+ }
150
+ };
151
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(analyticsEvent)(transaction);
152
+ return transaction;
153
+ };
154
+ };
155
+ };
156
+ var addDeleteAnalytics = function addDeleteAnalytics(editorAnalyticsAPI) {
157
+ return function (transaction, state) {
158
+ var analyticsEvent = {
159
+ action: _analytics.ACTION.DELETED,
160
+ actionSubject: _analytics.ACTION_SUBJECT.ANNOTATION,
161
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.INLINE_COMMENT,
162
+ eventType: _analytics.EVENT_TYPE.TRACK,
163
+ attributes: {}
164
+ };
165
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(analyticsEvent)(transaction);
166
+ return transaction;
167
+ };
168
+ };
139
169
  var _default = exports.default = {
140
170
  addAnnotationMark: addAnnotationMark,
141
171
  addInlineComment: addInlineComment,
142
172
  handleDraftState: handleDraftState,
143
173
  addOpenCloseAnalytics: addOpenCloseAnalytics,
144
174
  addInsertAnalytics: addInsertAnalytics,
145
- addResolveAnalytics: addResolveAnalytics
175
+ addResolveAnalytics: addResolveAnalytics,
176
+ addPreemptiveGateErrorAnalytics: addPreemptiveGateErrorAnalytics,
177
+ addDeleteAnalytics: addDeleteAnalytics
146
178
  };
@@ -7,7 +7,6 @@ exports.startDraft = exports.setIsAnnotationSelected = exports.setIsAnnotationHo
7
7
  var _adfSchema = require("@atlaskit/adf-schema");
8
8
  var _utils = require("@atlaskit/editor-common/utils");
9
9
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
10
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
10
  var _editorCommands = require("../editor-commands");
12
11
  var _types = require("../types");
13
12
  var _utils3 = require("./utils");
@@ -58,7 +57,7 @@ var startDraft = exports.startDraft = function startDraft(editorView, options) {
58
57
  reason: ERROR_REASON_DRAFT_IN_PROGRESS
59
58
  };
60
59
  }
61
- if (!!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.length) && (0, _platformFeatureFlags.fg)('platform_editor_comments_api_manager_select')) {
60
+ if (!!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.length)) {
62
61
  // if there are selected annotations when starting a draft, we need to clear the selected annotations
63
62
  // before we start the draft.
64
63
  (0, _editorCommands.closeComponent)()(editorView.state, editorView.dispatch);
@@ -344,7 +343,7 @@ var clearAnnotation = exports.clearAnnotation = function clearAnnotation(editorV
344
343
  reason: ERROR_REASON_ID_INVALID
345
344
  };
346
345
  }
347
- (0, _editorCommands.removeInlineCommentFromDoc)(id, options.provider.supportedBlockNodes)(editorView.state, editorView.dispatch);
346
+ (0, _editorCommands.removeInlineCommentFromDoc)(options.editorAnalyticsAPI)(id, options.provider.supportedBlockNodes)(editorView.state, editorView.dispatch);
348
347
  return {
349
348
  success: true,
350
349
  actionResult: undefined
@@ -93,6 +93,7 @@ var fetchState = /*#__PURE__*/function () {
93
93
  var initialState = function initialState() {
94
94
  var disallowOnWhitespace = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
95
95
  var featureFlagsPluginState = arguments.length > 1 ? arguments[1] : undefined;
96
+ var isAnnotationManagerEnabled = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
96
97
  return {
97
98
  annotations: {},
98
99
  selectedAnnotations: [],
@@ -107,7 +108,8 @@ var initialState = function initialState() {
107
108
  featureFlagsPluginState: featureFlagsPluginState,
108
109
  isDrafting: false,
109
110
  pendingSelectedAnnotations: [],
110
- pendingSelectedAnnotationsUpdateCount: 0
111
+ pendingSelectedAnnotationsUpdateCount: 0,
112
+ isAnnotationManagerEnabled: isAnnotationManagerEnabled
111
113
  };
112
114
  };
113
115
  var hideToolbar = function hideToolbar(state, dispatch) {
@@ -164,7 +166,7 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
164
166
  annotationManager = options.annotationManager;
165
167
  return new _safePlugin.SafePlugin({
166
168
  key: _utils2.inlineCommentPluginKey,
167
- state: (0, _pluginFactory.createPluginState)(options.dispatch, initialState(provider.disallowOnWhitespace, featureFlagsPluginState)),
169
+ state: (0, _pluginFactory.createPluginState)(options.dispatch, initialState(provider.disallowOnWhitespace, featureFlagsPluginState, !!annotationManager)),
168
170
  view: function view(editorView) {
169
171
  var allowAnnotationFn;
170
172
  var startDraftFn;
@@ -174,25 +176,23 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
174
176
  var setIsAnnotationSelectedFn;
175
177
  var setIsAnnotationHoveredFn;
176
178
  var clearAnnotationFn;
177
- if (annotationManager && (0, _platformFeatureFlags.fg)('platform_editor_comments_api_manager')) {
179
+ if (annotationManager) {
178
180
  allowAnnotationFn = (0, _annotationManagerHooks.allowAnnotation)(editorView, options);
179
181
  startDraftFn = (0, _annotationManagerHooks.startDraft)(editorView, options);
180
182
  clearDraftFn = (0, _annotationManagerHooks.clearDraft)(editorView, options);
181
183
  applyDraftFn = (0, _annotationManagerHooks.applyDraft)(editorView, options);
182
184
  getDraftFn = (0, _annotationManagerHooks.getDraft)(editorView, options);
185
+ setIsAnnotationSelectedFn = (0, _annotationManagerHooks.setIsAnnotationSelected)(editorView, options);
186
+ setIsAnnotationHoveredFn = (0, _annotationManagerHooks.setIsAnnotationHovered)(editorView, options);
187
+ clearAnnotationFn = (0, _annotationManagerHooks.clearAnnotation)(editorView, options);
183
188
  annotationManager.hook('allowAnnotation', allowAnnotationFn);
184
189
  annotationManager.hook('startDraft', startDraftFn);
185
190
  annotationManager.hook('clearDraft', clearDraftFn);
186
191
  annotationManager.hook('applyDraft', applyDraftFn);
187
192
  annotationManager.hook('getDraft', getDraftFn);
188
- if ((0, _platformFeatureFlags.fg)('platform_editor_comments_api_manager_select')) {
189
- setIsAnnotationSelectedFn = (0, _annotationManagerHooks.setIsAnnotationSelected)(editorView, options);
190
- setIsAnnotationHoveredFn = (0, _annotationManagerHooks.setIsAnnotationHovered)(editorView, options);
191
- clearAnnotationFn = (0, _annotationManagerHooks.clearAnnotation)(editorView, options);
192
- annotationManager.hook('setIsAnnotationSelected', setIsAnnotationSelectedFn);
193
- annotationManager.hook('setIsAnnotationHovered', setIsAnnotationHoveredFn);
194
- annotationManager.hook('clearAnnotation', clearAnnotationFn);
195
- }
193
+ annotationManager.hook('setIsAnnotationSelected', setIsAnnotationSelectedFn);
194
+ annotationManager.hook('setIsAnnotationHovered', setIsAnnotationHoveredFn);
195
+ annotationManager.hook('clearAnnotation', clearAnnotationFn);
196
196
  }
197
197
  // Get initial state
198
198
  // Need to pass `editorView` to mitigate editor state going stale
@@ -277,7 +277,7 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
277
277
  // The selectComponentExperience is using a simplified object, which is why it's type asserted.
278
278
  (_options$selectCommen = options.selectCommentExperience) === null || _options$selectCommen === void 0 || _options$selectCommen.selectAnnotation.complete(selectedAnnotationId);
279
279
  }
280
- if ((0, _platformFeatureFlags.fg)('platform_editor_comments_api_manager_select')) {
280
+ if (annotationManager) {
281
281
  // In the Editor, Annotations can be selected in three ways:
282
282
  // 1. By clicking on the annotation in the editor
283
283
  // 2. By using the annotation manager to select the annotation
@@ -295,7 +295,7 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
295
295
  // Need to set a lock to avoid calling gate multiple times. The lock will be released
296
296
  // when the preemptive gate is complete.
297
297
  isPreemptiveGateActive = true;
298
- annotationManager === null || annotationManager === void 0 || annotationManager.checkPreemptiveGate().then(function (canSelectAnnotation) {
298
+ annotationManager.checkPreemptiveGate().then(function (canSelectAnnotation) {
299
299
  var _ref8 = (0, _utils2.getPluginState)(view.state) || {},
300
300
  isDrafting = _ref8.isDrafting,
301
301
  latestPendingSelectedAnnotations = _ref8.pendingSelectedAnnotations,
@@ -308,14 +308,14 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
308
308
  }
309
309
 
310
310
  // Flush the pending selections into the selected annotations list.
311
- (0, _editorCommands.flushPendingSelections)(true)(view.state, view.dispatch);
311
+ (0, _editorCommands.flushPendingSelections)(options.editorAnalyticsAPI)(true)(view.state, view.dispatch);
312
312
  latestSelectedAnnotations === null || latestSelectedAnnotations === void 0 || latestSelectedAnnotations.filter(function (annotation) {
313
313
  return (latestPendingSelectedAnnotations === null || latestPendingSelectedAnnotations === void 0 ? void 0 : latestPendingSelectedAnnotations.findIndex(function (pendingAnnotation) {
314
314
  return pendingAnnotation.id === annotation.id;
315
315
  })) === -1;
316
316
  }).forEach(function (annotation) {
317
- var _options$annotationMa, _getAnnotationInlineN;
318
- (_options$annotationMa = options.annotationManager) === null || _options$annotationMa === void 0 || _options$annotationMa.emit({
317
+ var _getAnnotationInlineN;
318
+ annotationManager.emit({
319
319
  name: 'annotationSelectionChanged',
320
320
  data: {
321
321
  annotationId: annotation.id,
@@ -327,9 +327,9 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
327
327
 
328
328
  // Notify the annotation manager that the pending selection has changed.
329
329
  latestPendingSelectedAnnotations === null || latestPendingSelectedAnnotations === void 0 || latestPendingSelectedAnnotations.forEach(function (_ref9) {
330
- var _options$annotationMa2, _getAnnotationInlineN2;
330
+ var _getAnnotationInlineN2;
331
331
  var id = _ref9.id;
332
- (_options$annotationMa2 = options.annotationManager) === null || _options$annotationMa2 === void 0 || _options$annotationMa2.emit({
332
+ annotationManager.emit({
333
333
  name: 'annotationSelectionChanged',
334
334
  data: {
335
335
  annotationId: id,
@@ -342,20 +342,18 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
342
342
  // Clears the pending selections if the preemptive gate returns false.
343
343
  // We should need to worry about dispatching change events here because the pending selections
344
344
  // are being aborted and the selections will remain unchanged.
345
- (0, _editorCommands.flushPendingSelections)(false)(view.state, view.dispatch);
345
+ (0, _editorCommands.flushPendingSelections)(options.editorAnalyticsAPI)(false)(view.state, view.dispatch);
346
346
  }
347
347
  }).catch(function (error) {
348
- // TODO: EDITOR-595 - Ensure and anlytic is fired to indicate which reports on the error.
349
-
350
348
  // If an error has occured we will clear any pending selections to avoid accidentally setting the wrong thing.
351
- (0, _editorCommands.flushPendingSelections)(false)(view.state, view.dispatch);
349
+ (0, _editorCommands.flushPendingSelections)(options.editorAnalyticsAPI)(false, 'pending-selection-preemptive-gate-error')(view.state, view.dispatch);
352
350
  }).finally(function () {
353
351
  isPreemptiveGateActive = false;
354
352
  });
355
353
  }
356
354
  }
357
- var _ref10 = (0, _utils2.getPluginState)(view.state) || {},
358
- dirtyAnnotations = _ref10.dirtyAnnotations;
355
+ var _ref0 = (0, _utils2.getPluginState)(view.state) || {},
356
+ dirtyAnnotations = _ref0.dirtyAnnotations;
359
357
  if (!dirtyAnnotations) {
360
358
  return;
361
359
  }
@@ -368,7 +366,7 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
368
366
  if (updateSubscriber) {
369
367
  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);
370
368
  }
371
- if (annotationManager && (0, _platformFeatureFlags.fg)('platform_editor_comments_api_manager')) {
369
+ if (annotationManager) {
372
370
  annotationManager.unhook('allowAnnotation', allowAnnotationFn);
373
371
  annotationManager.unhook('startDraft', startDraftFn);
374
372
  annotationManager.unhook('clearDraft', clearDraftFn);
@@ -418,13 +416,13 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
418
416
  if (isSelected && !(pluginState !== null && pluginState !== void 0 && pluginState.isInlineCommentViewClosed)) {
419
417
  return false;
420
418
  }
421
- var _ref11 = pluginState || {},
422
- annotations = _ref11.annotations;
419
+ var _ref1 = pluginState || {},
420
+ annotations = _ref1.annotations;
423
421
  var isUnresolved = annotations && annotations[annotationId] === false;
424
422
  if (!isUnresolved) {
425
423
  return false;
426
424
  }
427
- if ((0, _platformFeatureFlags.fg)('platform_editor_comments_api_manager_select')) {
425
+ if (annotationManager) {
428
426
  var _pluginState$pendingS;
429
427
  // The manager disable setting the selected annotation on click because in the editor this is already
430
428
  // handled by the selection update handler. When the manager is enabled, and a selection changes it's pushed into
@@ -447,13 +445,13 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
447
445
  },
448
446
  decorations: function decorations(state) {
449
447
  // highlight comments, depending on state
450
- var _ref12 = (0, _utils2.getPluginState)(state) || {},
451
- draftDecorationSet = _ref12.draftDecorationSet,
452
- annotations = _ref12.annotations,
453
- selectedAnnotations = _ref12.selectedAnnotations,
454
- isVisible = _ref12.isVisible,
455
- isInlineCommentViewClosed = _ref12.isInlineCommentViewClosed,
456
- hoveredAnnotations = _ref12.hoveredAnnotations;
448
+ var _ref10 = (0, _utils2.getPluginState)(state) || {},
449
+ draftDecorationSet = _ref10.draftDecorationSet,
450
+ annotations = _ref10.annotations,
451
+ selectedAnnotations = _ref10.selectedAnnotations,
452
+ isVisible = _ref10.isVisible,
453
+ isInlineCommentViewClosed = _ref10.isInlineCommentViewClosed,
454
+ hoveredAnnotations = _ref10.hoveredAnnotations;
457
455
  var decorations = draftDecorationSet !== null && draftDecorationSet !== void 0 ? draftDecorationSet : _view.DecorationSet.empty;
458
456
  var focusDecorations = [];
459
457
 
@@ -9,7 +9,6 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
9
9
  var _utils = require("@atlaskit/editor-common/utils");
10
10
  var _state = require("@atlaskit/editor-prosemirror/state");
11
11
  var _view = require("@atlaskit/editor-prosemirror/view");
12
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
13
12
  var _reducer = _interopRequireDefault(require("./reducer"));
14
13
  var _utils2 = require("./utils");
15
14
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -111,7 +110,6 @@ var getSelectionChangeHandlerNew = function getSelectionChangeHandlerNew(reopenC
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,
@@ -140,7 +138,11 @@ var getSelectionChangeHandlerNew = function getSelectionChangeHandlerNew(reopenC
140
138
  };
141
139
  var getSelectionChangedHandler = function getSelectionChangedHandler(reopenCommentView) {
142
140
  return function (tr, pluginState) {
143
- return (0, _platformFeatureFlags.fg)('platform_editor_comments_api_manager_select') ? getSelectionChangeHandlerNew(reopenCommentView)(tr, pluginState) : getSelectionChangeHandlerOld(reopenCommentView)(tr, pluginState);
141
+ return pluginState.isAnnotationManagerEnabled ?
142
+ // if platform_editor_comments_api_manager == true
143
+ getSelectionChangeHandlerNew(reopenCommentView)(tr, pluginState) :
144
+ // else if platform_editor_comments_api_manager == false
145
+ getSelectionChangeHandlerOld(reopenCommentView)(tr, pluginState);
144
146
  };
145
147
  };
146
148
  var _pluginFactory = (0, _utils.pluginFactory)(_utils2.inlineCommentPluginKey, _reducer.default, {
@@ -38,7 +38,7 @@ var _default = exports.default = function _default(pluginState, action) {
38
38
  isOpeningMediaCommentFromToolbar: false
39
39
  }, (0, _platformFeatureFlags.fg)('platform_editor_annotation_selected_annotation') && {
40
40
  selectedAnnotations: []
41
- }), (0, _platformFeatureFlags.fg)('platform_editor_comments_api_manager_select') && {
41
+ }), pluginState.isAnnotationManagerEnabled && {
42
42
  selectedAnnotations: []
43
43
  });
44
44
  case _types.ACTIONS.ADD_INLINE_COMMENT:
@@ -48,7 +48,7 @@ var _default = exports.default = function _default(pluginState, action) {
48
48
  annotations: _objectSpread(_objectSpread({}, pluginState.annotations), action.data.inlineComments),
49
49
  isInlineCommentViewClosed: false,
50
50
  selectAnnotationMethod: undefined
51
- }, (0, _platformFeatureFlags.fg)('platform_editor_comments_api_manager_select') && {
51
+ }, pluginState.isAnnotationManagerEnabled && {
52
52
  skipSelectionHandling: true
53
53
  });
54
54
  case _types.ACTIONS.INLINE_COMMENT_SET_VISIBLE:
@@ -123,25 +123,17 @@ var buildToolbar = exports.buildToolbar = function buildToolbar(editorAnalyticsA
123
123
  }
124
124
  },
125
125
  onClick: function onClick(state, dispatch) {
126
- if (editorAnalyticsAPI) {
127
- editorAnalyticsAPI.fireAnalyticsEvent({
128
- action: _analytics.ACTION.CLICKED,
129
- actionSubject: _analytics.ACTION_SUBJECT.BUTTON,
130
- actionSubjectId: _analytics.ACTION_SUBJECT_ID.CREATE_INLINE_COMMENT_FROM_HIGHLIGHT_ACTIONS_MENU,
131
- eventType: _analytics.EVENT_TYPE.UI,
132
- attributes: {
133
- source: 'highlightActionsMenu',
134
- pageMode: 'edit'
135
- }
136
- });
137
- }
138
- if ((0, _platformFeatureFlags.fg)('platform_editor_comments_api_manager')) {
139
- if (!annotationManager) {
140
- // TODO: EDITOR-595 - If we've reached here and the manager is not initialized, we should
141
- // dispatch an analytics event to indicate that the user has clicked the button but
142
- // the action was not completed.
143
- return false;
126
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
127
+ action: _analytics.ACTION.CLICKED,
128
+ actionSubject: _analytics.ACTION_SUBJECT.BUTTON,
129
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.CREATE_INLINE_COMMENT_FROM_HIGHLIGHT_ACTIONS_MENU,
130
+ eventType: _analytics.EVENT_TYPE.UI,
131
+ attributes: {
132
+ source: 'highlightActionsMenu',
133
+ pageMode: 'edit'
144
134
  }
135
+ });
136
+ if (annotationManager) {
145
137
  annotationManager.checkPreemptiveGate().then(function (canStartDraft) {
146
138
  if (canStartDraft) {
147
139
  createCommentExperience === null || createCommentExperience === void 0 || createCommentExperience.start({
@@ -152,18 +144,30 @@ var buildToolbar = exports.buildToolbar = function buildToolbar(editorAnalyticsA
152
144
  });
153
145
  createCommentExperience === null || createCommentExperience === void 0 || createCommentExperience.initExperience.start();
154
146
  var result = annotationManager.startDraft();
155
- if (result.success) {
156
- // TODO: EDITOR-595 - Ensure and anlytic is fired to indicate that the user has started a draft.
157
- } else {
158
- // TODO: EDITOR-595 - Fire an analytics event to indicate that the user has clicked the button
147
+ if (!result.success) {
148
+ // Fire an analytics event to indicate that the user has clicked the button
159
149
  // but the action was not completed, the result should contain a reason.
150
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
151
+ action: _analytics.ACTION.ERROR,
152
+ actionSubject: _analytics.ACTION_SUBJECT.ANNOTATION,
153
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.INLINE_COMMENT,
154
+ eventType: _analytics.EVENT_TYPE.OPERATIONAL,
155
+ attributes: {
156
+ errorReason: "toolbar-start-draft-failed/".concat(result.reason)
157
+ }
158
+ });
160
159
  }
161
- } else {
162
- // TODO: EDITOR-595 - Track the toolbar comment button was clicked but the preemptive gate
163
- // check returned false and the draft cannot be started.
164
160
  }
165
161
  }).catch(function () {
166
- // TODO: EDITOR-595 - Handle preemptive gate check error. Something went very wrong in the gate.
162
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
163
+ action: _analytics.ACTION.ERROR,
164
+ actionSubject: _analytics.ACTION_SUBJECT.ANNOTATION,
165
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.INLINE_COMMENT,
166
+ eventType: _analytics.EVENT_TYPE.OPERATIONAL,
167
+ attributes: {
168
+ errorReason: "toolbar-start-draft-preemptive-gate-error"
169
+ }
170
+ });
167
171
  });
168
172
  return true;
169
173
  } else {
@@ -20,8 +20,7 @@ var _editorCommands = require("../editor-commands");
20
20
  var _utils3 = require("../pm-plugins/utils");
21
21
  var _types = require("../types");
22
22
  var _AnnotationViewWrapper = require("./AnnotationViewWrapper");
23
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
24
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
23
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
25
24
  var findPosForDOM = function findPosForDOM(sel) {
26
25
  var $from = sel.$from,
27
26
  from = sel.from;
@@ -31,12 +31,18 @@ export const closeComponent = () => createCommand({
31
31
  export const clearDirtyMark = () => createCommand({
32
32
  type: ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK
33
33
  });
34
- export const flushPendingSelections = canSetAsSelectedAnnotations => createCommand({
35
- type: ACTIONS.FLUSH_PENDING_SELECTIONS,
36
- data: {
37
- canSetAsSelectedAnnotations
34
+ export const flushPendingSelections = editorAnalyticsAPI => (canSetAsSelectedAnnotations, errorReason) => {
35
+ const command = {
36
+ type: ACTIONS.FLUSH_PENDING_SELECTIONS,
37
+ data: {
38
+ canSetAsSelectedAnnotations
39
+ }
40
+ };
41
+ if (!!errorReason) {
42
+ return createCommand(command, (tr, state) => transform.addPreemptiveGateErrorAnalytics(editorAnalyticsAPI)(errorReason)(tr, state));
38
43
  }
39
- });
44
+ return createCommand(command);
45
+ };
40
46
  export const setPendingSelectedAnnotation = id => createCommand({
41
47
  type: ACTIONS.SET_PENDING_SELECTIONS,
42
48
  data: {
@@ -109,7 +115,7 @@ export const removeInlineCommentNearSelection = (id, supportedNodes = []) => (st
109
115
  }
110
116
  return true;
111
117
  };
112
- export const removeInlineCommentFromDoc = (id, supportedNodes = []) => (state, dispatch) => {
118
+ export const removeInlineCommentFromDoc = editorAnalyticsAPI => (id, supportedNodes = []) => (state, dispatch) => {
113
119
  const {
114
120
  tr
115
121
  } = state;
@@ -129,7 +135,7 @@ export const removeInlineCommentFromDoc = (id, supportedNodes = []) => (state, d
129
135
  });
130
136
  });
131
137
  if (dispatch) {
132
- dispatch(tr);
138
+ dispatch(transform.addDeleteAnalytics(editorAnalyticsAPI)(tr, state));
133
139
  return true;
134
140
  }
135
141
  return false;
@@ -109,11 +109,37 @@ const addResolveAnalytics = editorAnalyticsAPI => method => (transaction, state)
109
109
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(resolvedPayload)(transaction);
110
110
  return transaction;
111
111
  };
112
+ const addPreemptiveGateErrorAnalytics = editorAnalyticsAPI => errorReason => (transaction, state) => {
113
+ const analyticsEvent = {
114
+ action: ACTION.ERROR,
115
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
116
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
117
+ eventType: EVENT_TYPE.OPERATIONAL,
118
+ attributes: {
119
+ errorReason
120
+ }
121
+ };
122
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(analyticsEvent)(transaction);
123
+ return transaction;
124
+ };
125
+ const addDeleteAnalytics = editorAnalyticsAPI => (transaction, state) => {
126
+ const analyticsEvent = {
127
+ action: ACTION.DELETED,
128
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
129
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
130
+ eventType: EVENT_TYPE.TRACK,
131
+ attributes: {}
132
+ };
133
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(analyticsEvent)(transaction);
134
+ return transaction;
135
+ };
112
136
  export default {
113
137
  addAnnotationMark,
114
138
  addInlineComment,
115
139
  handleDraftState,
116
140
  addOpenCloseAnalytics,
117
141
  addInsertAnalytics,
118
- addResolveAnalytics
142
+ addResolveAnalytics,
143
+ addPreemptiveGateErrorAnalytics,
144
+ addDeleteAnalytics
119
145
  };
@@ -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';
@@ -51,7 +50,7 @@ export const startDraft = (editorView, options) => () => {
51
50
  reason: ERROR_REASON_DRAFT_IN_PROGRESS
52
51
  };
53
52
  }
54
- if (!!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.length) && fg('platform_editor_comments_api_manager_select')) {
53
+ if (!!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.length)) {
55
54
  // if there are selected annotations when starting a draft, we need to clear the selected annotations
56
55
  // before we start the draft.
57
56
  closeComponent()(editorView.state, editorView.dispatch);
@@ -328,7 +327,7 @@ export const clearAnnotation = (editorView, options) => id => {
328
327
  reason: ERROR_REASON_ID_INVALID
329
328
  };
330
329
  }
331
- removeInlineCommentFromDoc(id, options.provider.supportedBlockNodes)(editorView.state, editorView.dispatch);
330
+ removeInlineCommentFromDoc(options.editorAnalyticsAPI)(id, options.provider.supportedBlockNodes)(editorView.state, editorView.dispatch);
332
331
  return {
333
332
  success: true,
334
333
  actionResult: undefined