@atlaskit/editor-plugin-annotation 27.0.6 → 28.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # @atlaskit/editor-plugin-annotation
2
2
 
3
+ ## 28.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`0dacb94545d03`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0dacb94545d03) -
8
+ Behind cc_maui_annotations_on_extensions: fire the cc_maui_comments_on_charts_exp exposure only
9
+ where the chart Comment button can show. Adds an optional viewModeEditorToolbarItems UiConfig
10
+ hook, used by MAUI charts to show Comment in the view-mode toolbar (live pages), and a
11
+ getAddCommentPermission annotation plugin action, used to disable the chart Comment button without
12
+ comment permission. The full-page renderer checks extension comment creation on first hover or
13
+ focus instead of while rendering.
14
+ - [`98f39b65e08a9`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/98f39b65e08a9) -
15
+ Track new Remix inline comment drafts through the configured creation experience under
16
+ cc_maui_annotations_on_extensions.
17
+
18
+ ## 28.0.0
19
+
20
+ ### Minor Changes
21
+
22
+ - [`ebf585edb7bcc`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ebf585edb7bcc) -
23
+ Support starting an annotation draft on a block node, behind
24
+ `platform_editor_comments_api_manager`.
25
+ - The `startDraft` manager hook accepts an optional `localId`. It resolves the target through
26
+ `resolveAnnotatableTargetFromLocalId`, selects the node ProseMirror can select (a `media` node's
27
+ `mediaSingle` parent), starts a block draft, and reports `targetNodeType` on both the result and
28
+ the `draftAnnotationStarted` event. An unresolvable `localId` fails with `invalid-localId` and
29
+ leaves the document untouched.
30
+ - `clearDraft` now emits `draftAnnotationCleared`.
31
+ - The annotation plugin's shared state exposes `annotationManager`, so other plugins (media) can
32
+ drive the manager without the provider being threaded through them.
33
+
34
+ ### Patch Changes
35
+
36
+ - Updated dependencies
37
+
3
38
  ## 27.0.6
4
39
 
5
40
  ### Patch Changes
@@ -97,6 +97,13 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
97
97
  var _annotationProviders$, _annotationProviders$2;
98
98
  return (0, _fg.fg)('cc_maui_annotations_on_extensions') && (annotationProviders === null || annotationProviders === void 0 || (_annotationProviders$ = (_annotationProviders$2 = annotationProviders.inlineComment).isBlockNodeSupported) === null || _annotationProviders$ === void 0 ? void 0 : _annotationProviders$.call(_annotationProviders$2, node)) === true;
99
99
  },
100
+ getAddCommentPermission: function getAddCommentPermission() {
101
+ var _annotationProviders$3, _annotationProviders$4, _annotationProviders$5;
102
+ return {
103
+ canAddComments: (_annotationProviders$3 = annotationProviders === null || annotationProviders === void 0 || (_annotationProviders$4 = (_annotationProviders$5 = annotationProviders.inlineComment).getCanAddComments) === null || _annotationProviders$4 === void 0 ? void 0 : _annotationProviders$4.call(_annotationProviders$5)) !== null && _annotationProviders$3 !== void 0 ? _annotationProviders$3 : true,
104
+ contentType: annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.contentType
105
+ };
106
+ },
100
107
  hasAnyUnResolvedAnnotationInPage: _utils.hasAnyUnResolvedAnnotationInPage,
101
108
  requestCloseInlineComment: requestCloseInlineComment,
102
109
  stripNonExistingAnnotations: _utils.stripNonExistingAnnotations,
@@ -105,10 +112,10 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
105
112
  return (0, _editorCommands.createAnnotation)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api)(annotationId, _annotation.AnnotationTypes.INLINE_COMMENT, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.isBlockNodeSupported);
106
113
  },
107
114
  removeInlineCommentAnnotation: function removeInlineCommentAnnotation(annotationId) {
108
- var _api$analytics2, _annotationProviders$3;
109
- return (0, _editorCommands.removeInlineCommentFromDoc)(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(annotationId, (_annotationProviders$3 = annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes) !== null && _annotationProviders$3 !== void 0 ? _annotationProviders$3 : [], annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.isBlockNodeSupported);
115
+ var _api$analytics2, _annotationProviders$6;
116
+ return (0, _editorCommands.removeInlineCommentFromDoc)(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(annotationId, (_annotationProviders$6 = annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes) !== null && _annotationProviders$6 !== void 0 ? _annotationProviders$6 : [], annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.isBlockNodeSupported);
110
117
  },
111
- setInlineCommentDraftState: (0, _editorCommands.setInlineCommentDraftState)(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes, undefined, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.isBlockNodeSupported),
118
+ setInlineCommentDraftState: (0, _editorCommands.setInlineCommentDraftState)(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes, undefined, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.isBlockNodeSupported, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.createCommentExperience),
112
119
  showCommentForBlockNode: (0, _editorCommands.showInlineCommentForBlockNode)(annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.isBlockNodeSupported),
113
120
  setSelectedAnnotation: _editorCommands.setSelectedAnnotation,
114
121
  setPendingSelectedAnnotation: _editorCommands.setPendingSelectedAnnotation
@@ -120,7 +127,9 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
120
127
  var pluginState = (0, _utils.getPluginState)(editorState) || undefined;
121
128
  var clonedPluginState = Object.assign({}, pluginState);
122
129
  clonedPluginState === null || clonedPluginState === void 0 || delete clonedPluginState.featureFlagsPluginState;
123
- return clonedPluginState;
130
+ return _objectSpread(_objectSpread({}, clonedPluginState), {}, {
131
+ annotationManager: annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.annotationManager
132
+ });
124
133
  },
125
134
  pmPlugins: function pmPlugins() {
126
135
  return [{
@@ -173,11 +182,11 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
173
182
  var pluginState = (0, _utils.getPluginState)(state);
174
183
  if (pluginState && pluginState.isVisible && !pluginState.bookmark && !pluginState.mouseData.isSelecting) {
175
184
  var _api$analytics5;
176
- var _annotationProviders$4 = annotationProviders.inlineComment,
177
- isToolbarAbove = _annotationProviders$4.isToolbarAbove,
178
- onCommentButtonMount = _annotationProviders$4.onCommentButtonMount,
179
- getCanAddComments = _annotationProviders$4.getCanAddComments,
180
- contentType = _annotationProviders$4.contentType;
185
+ var _annotationProviders$7 = annotationProviders.inlineComment,
186
+ isToolbarAbove = _annotationProviders$7.isToolbarAbove,
187
+ onCommentButtonMount = _annotationProviders$7.onCommentButtonMount,
188
+ getCanAddComments = _annotationProviders$7.getCanAddComments,
189
+ contentType = _annotationProviders$7.contentType;
181
190
  var toolbarConfig = (0, _toolbar.buildToolbar)(api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions)({
182
191
  state: state,
183
192
  intl: intl,
@@ -9,7 +9,9 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
9
9
  var _annotation = require("@atlaskit/adf-schema/annotation");
10
10
  var _enums = require("@atlaskit/editor-common/analytics/types/enums");
11
11
  var _inlineCommentEvents = require("@atlaskit/editor-common/analytics/types/inline-comment-events");
12
+ var _manifestHelpers = require("@atlaskit/editor-common/extensions/manifest-helpers");
12
13
  var _state = require("@atlaskit/editor-prosemirror/state");
14
+ var _fg = require("@atlaskit/platform-feature-flags/fg");
13
15
  var _pluginFactory = require("../pm-plugins/plugin-factory");
14
16
  var _types = require("../pm-plugins/types");
15
17
  var _utils = require("../pm-plugins/utils");
@@ -250,16 +252,35 @@ var setInlineCommentDraftState = exports.setInlineCommentDraftState = function s
250
252
  var supportedBlockNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
251
253
  var api = arguments.length > 2 ? arguments[2] : undefined;
252
254
  var isBlockNodeSupported = arguments.length > 3 ? arguments[3] : undefined;
255
+ var createCommentExperience = arguments.length > 4 ? arguments[4] : undefined;
253
256
  return function (drafting) {
254
257
  var inputMethod = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _enums.INPUT_METHOD.TOOLBAR;
255
258
  var targetType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'inline';
256
259
  var targetNodeId = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
257
260
  var isOpeningMediaCommentFromToolbar = arguments.length > 4 ? arguments[4] : undefined;
258
261
  var commandAction = getDraftCommandAction(drafting, targetType, targetNodeId, supportedBlockNodes, isBlockNodeSupported, isOpeningMediaCommentFromToolbar);
259
- if (Boolean(api === null || api === void 0 ? void 0 : api.toolbar)) {
260
- return function (state, dispatch) {
261
- var tr = _transform.default.handleDraftState(editorAnalyticsAPI)(drafting, inputMethod)(state.tr, state);
262
+ var draftCommand = !(api !== null && api !== void 0 && api.toolbar) ? (0, _pluginFactory.createCommand)(commandAction, _transform.default.handleDraftState(editorAnalyticsAPI)(drafting, inputMethod)) : undefined;
263
+ return function (state, dispatch, view) {
264
+ // Start tracking only when a valid draft is dispatched, never during dry runs.
265
+ var dispatchDraft = dispatch && drafting && targetType === 'block' && state.selection instanceof _state.NodeSelection && state.selection.node.type.name === 'extension' && state.selection.node.attrs.extensionKey === "".concat(_manifestHelpers.NATIVE_EMBED_EXTENSION_KEY, ":maui") && (0, _fg.fg)('cc_maui_annotations_on_extensions') ? function (tr) {
266
+ createCommentExperience === null || createCommentExperience === void 0 || createCommentExperience.start({
267
+ attributes: {
268
+ pageClass: 'editor',
269
+ commentType: 'block',
270
+ blockType: 'extension',
271
+ commentTargetType: 'remixEmbed',
272
+ entryPoint: 'highlightActions'
273
+ }
274
+ });
275
+ createCommentExperience === null || createCommentExperience === void 0 || createCommentExperience.initExperience.start();
276
+ dispatch(tr);
277
+ } : dispatch;
278
+ if (Boolean(api === null || api === void 0 ? void 0 : api.toolbar)) {
262
279
  var newPluginState = commandAction(state);
280
+ if (!newPluginState) {
281
+ return false;
282
+ }
283
+ var tr = _transform.default.handleDraftState(editorAnalyticsAPI)(drafting, inputMethod)(state.tr, state);
263
284
  if (tr && newPluginState) {
264
285
  tr.setMeta(_utils.inlineCommentPluginKey, newPluginState);
265
286
  if (drafting) {
@@ -267,17 +288,16 @@ var setInlineCommentDraftState = exports.setInlineCommentDraftState = function s
267
288
  } else {
268
289
  (0, _utils2.resetUserIntent)(api, tr);
269
290
  }
270
- if (dispatch) {
271
- dispatch(tr);
291
+ if (dispatchDraft) {
292
+ dispatchDraft(tr);
272
293
  }
273
294
  } else {
274
295
  return false;
275
296
  }
276
297
  return true;
277
- };
278
- } else {
279
- return (0, _pluginFactory.createCommand)(commandAction, _transform.default.handleDraftState(editorAnalyticsAPI)(drafting, inputMethod));
280
- }
298
+ }
299
+ return draftCommand ? draftCommand(state, dispatchDraft, view) : false;
300
+ };
281
301
  };
282
302
  };
283
303
  var addInlineComment = exports.addInlineComment = function addInlineComment(editorAnalyticsAPI, editorAPI) {
@@ -5,16 +5,20 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.startDraft = exports.setIsAnnotationSelected = exports.setIsAnnotationHovered = exports.getDraft = exports.clearDraft = exports.clearAnnotation = exports.applyDraft = exports.allowAnnotation = void 0;
7
7
  var _annotation = require("@atlaskit/adf-schema/annotation");
8
+ var _analytics = require("@atlaskit/editor-common/analytics");
8
9
  var _annotation2 = require("@atlaskit/editor-common/utils/annotation");
10
+ var _state = require("@atlaskit/editor-prosemirror/state");
9
11
  var _utils = require("@atlaskit/editor-prosemirror/utils");
10
12
  var _editorCommands = require("../editor-commands");
11
13
  var _types = require("../types");
14
+ var _resolveAnnotatableTarget = require("./resolve-annotatable-target");
12
15
  var _utils2 = require("./utils");
13
16
  var ERROR_REASON_DRAFT_NOT_STARTED = 'draft-not-started';
14
17
  var ERROR_REASON_DRAFT_IN_PROGRESS = 'draft-in-progress';
15
18
  var ERROR_REASON_RANGE_MISSING = 'range-no-longer-exists';
16
19
  var ERROR_REASON_RANGE_INVALID = 'invalid-range';
17
20
  var ERROR_REASON_ID_INVALID = 'id-not-valid';
21
+ var ERROR_REASON_INVALID_LOCAL_ID = 'invalid-localId';
18
22
  var domRefFromPos = function domRefFromPos(view, position) {
19
23
  var dom;
20
24
  try {
@@ -46,8 +50,8 @@ var allowAnnotation = exports.allowAnnotation = function allowAnnotation(editorV
46
50
  };
47
51
  };
48
52
  var startDraft = exports.startDraft = function startDraft(editorView, options) {
49
- return function () {
50
- var _getRangeInlineNodeNa, _options$annotationMa2;
53
+ return function (localId) {
54
+ var _getRangeInlineNodeNa2, _options$annotationMa3;
51
55
  var _ref2 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
52
56
  isDrafting = _ref2.isDrafting,
53
57
  selectedAnnotations = _ref2.selectedAnnotations;
@@ -75,9 +79,71 @@ var startDraft = exports.startDraft = function startDraft(editorView, options) {
75
79
  });
76
80
  });
77
81
  }
82
+ if (localId !== undefined) {
83
+ var _$target$parent, _target$node$attrs$id, _getRangeInlineNodeNa, _options$annotationMa2;
84
+ var target = (0, _resolveAnnotatableTarget.resolveAnnotatableTargetFromLocalId)(editorView.state, localId, {
85
+ supportedBlockNodes: options.provider.supportedBlockNodes
86
+ });
87
+ if (!target) {
88
+ return {
89
+ success: false,
90
+ reason: ERROR_REASON_INVALID_LOCAL_ID
91
+ };
92
+ }
93
+
94
+ // The resolver returns the node accepting the annotation (the inner `media`), but
95
+ // `isSelectionValid` requires the selection to be on the selectable `mediaSingle`.
96
+ var doc = editorView.state.doc;
97
+ var selectionPos = target.pos;
98
+ var $target = doc.resolve(target.pos);
99
+ if (target.node.type.name === 'media' && ((_$target$parent = $target.parent) === null || _$target$parent === void 0 ? void 0 : _$target$parent.type.name) === 'mediaSingle') {
100
+ selectionPos = $target.before();
101
+ }
102
+
103
+ // A NodeSelection makes resolveDraftBookmark record isBlockNode: true.
104
+ editorView.dispatch(editorView.state.tr.setSelection(_state.NodeSelection.create(doc, selectionPos)));
105
+ var targetNodeId = (_target$node$attrs$id = target.node.attrs.id) !== null && _target$node$attrs$id !== void 0 ? _target$node$attrs$id : target.node.attrs.localId;
106
+ (0, _editorCommands.setInlineCommentDraftState)(options.editorAnalyticsAPI, options.provider.supportedBlockNodes, options.api, options.provider.isBlockNodeSupported)(true, _analytics.INPUT_METHOD.FLOATING_TB, 'block', targetNodeId, true)(editorView.state, editorView.dispatch);
107
+ var _ref3 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
108
+ _draftDecorationSet = _ref3.draftDecorationSet;
109
+ var _decorations = _draftDecorationSet === null || _draftDecorationSet === void 0 ? void 0 : _draftDecorationSet.find();
110
+ if (!(_decorations !== null && _decorations !== void 0 && _decorations.length)) {
111
+ return {
112
+ success: false,
113
+ reason: ERROR_REASON_RANGE_INVALID
114
+ };
115
+ }
116
+ var _from = _decorations[0].from;
117
+ var _targetElement = domRefFromPos(editorView, _from);
118
+ var _inlineNodeTypes = (_getRangeInlineNodeNa = (0, _annotation2.getRangeInlineNodeNames)({
119
+ doc: editorView.state.doc,
120
+ pos: {
121
+ from: _from,
122
+ to: _decorations[_decorations.length - 1].to
123
+ }
124
+ })) !== null && _getRangeInlineNodeNa !== void 0 ? _getRangeInlineNodeNa : [];
125
+ var targetNodeType = target.node.type.name;
126
+ (_options$annotationMa2 = options.annotationManager) === null || _options$annotationMa2 === void 0 || _options$annotationMa2.emit({
127
+ name: 'draftAnnotationStarted',
128
+ data: {
129
+ targetElement: _targetElement,
130
+ actionResult: undefined,
131
+ inlineNodeTypes: _inlineNodeTypes,
132
+ targetNodeType: targetNodeType
133
+ }
134
+ });
135
+ return {
136
+ success: true,
137
+ targetElement: _targetElement,
138
+ // In Editor the action result is undefined, because the editor will perform the transaction on the document.
139
+ actionResult: undefined,
140
+ inlineNodeTypes: _inlineNodeTypes,
141
+ targetNodeType: targetNodeType
142
+ };
143
+ }
78
144
  (0, _editorCommands.setInlineCommentDraftState)(options.editorAnalyticsAPI, options.provider.supportedBlockNodes, options.api, options.provider.isBlockNodeSupported)(true)(editorView.state, editorView.dispatch);
79
- var _ref3 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
80
- draftDecorationSet = _ref3.draftDecorationSet;
145
+ var _ref4 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
146
+ draftDecorationSet = _ref4.draftDecorationSet;
81
147
  var decorations = draftDecorationSet === null || draftDecorationSet === void 0 ? void 0 : draftDecorationSet.find();
82
148
 
83
149
  // If the matching decorations is not found containing the id, it means something went wrong with the draft.
@@ -89,14 +155,14 @@ var startDraft = exports.startDraft = function startDraft(editorView, options) {
89
155
  }
90
156
  var from = decorations[0].from;
91
157
  var targetElement = domRefFromPos(editorView, from);
92
- var inlineNodeTypes = (_getRangeInlineNodeNa = (0, _annotation2.getRangeInlineNodeNames)({
158
+ var inlineNodeTypes = (_getRangeInlineNodeNa2 = (0, _annotation2.getRangeInlineNodeNames)({
93
159
  doc: editorView.state.doc,
94
160
  pos: {
95
161
  from: from,
96
162
  to: decorations[decorations.length - 1].to
97
163
  }
98
- })) !== null && _getRangeInlineNodeNa !== void 0 ? _getRangeInlineNodeNa : [];
99
- (_options$annotationMa2 = options.annotationManager) === null || _options$annotationMa2 === void 0 || _options$annotationMa2.emit({
164
+ })) !== null && _getRangeInlineNodeNa2 !== void 0 ? _getRangeInlineNodeNa2 : [];
165
+ (_options$annotationMa3 = options.annotationManager) === null || _options$annotationMa3 === void 0 || _options$annotationMa3.emit({
100
166
  name: 'draftAnnotationStarted',
101
167
  data: {
102
168
  targetElement: targetElement,
@@ -115,9 +181,10 @@ var startDraft = exports.startDraft = function startDraft(editorView, options) {
115
181
  };
116
182
  var clearDraft = exports.clearDraft = function clearDraft(editorView, options) {
117
183
  return function () {
118
- var _ref4 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
119
- isDrafting = _ref4.isDrafting,
120
- draftDecorationSet = _ref4.draftDecorationSet;
184
+ var _options$annotationMa4;
185
+ var _ref5 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
186
+ isDrafting = _ref5.isDrafting,
187
+ draftDecorationSet = _ref5.draftDecorationSet;
121
188
  if (!isDrafting) {
122
189
  return {
123
190
  success: false,
@@ -133,6 +200,9 @@ var clearDraft = exports.clearDraft = function clearDraft(editorView, options) {
133
200
  }
134
201
  (0, _editorCommands.setInlineCommentDraftState)(options.editorAnalyticsAPI, undefined, options.api)(false)(editorView.state, editorView.dispatch);
135
202
  !editorView.hasFocus() && editorView.focus();
203
+ (_options$annotationMa4 = options.annotationManager) === null || _options$annotationMa4 === void 0 || _options$annotationMa4.emit({
204
+ name: 'draftAnnotationCleared'
205
+ });
136
206
  return {
137
207
  success: true
138
208
  };
@@ -140,11 +210,11 @@ var clearDraft = exports.clearDraft = function clearDraft(editorView, options) {
140
210
  };
141
211
  var applyDraft = exports.applyDraft = function applyDraft(editorView, options) {
142
212
  return function (id) {
143
- var _options$annotationMa3, _getAnnotationInlineN2;
144
- var _ref5 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
145
- isDrafting = _ref5.isDrafting,
146
- draftDecorationSet = _ref5.draftDecorationSet,
147
- bookmark = _ref5.bookmark;
213
+ var _options$annotationMa5, _getAnnotationInlineN2;
214
+ var _ref6 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
215
+ isDrafting = _ref6.isDrafting,
216
+ draftDecorationSet = _ref6.draftDecorationSet,
217
+ bookmark = _ref6.bookmark;
148
218
  if (!isDrafting) {
149
219
  return {
150
220
  success: false,
@@ -168,7 +238,7 @@ var applyDraft = exports.applyDraft = function applyDraft(editorView, options) {
168
238
 
169
239
  // When a draft is applied it is automatically selected, so we need to set the selected annotation.
170
240
  // emit the event for the selected annotation.
171
- (_options$annotationMa3 = options.annotationManager) === null || _options$annotationMa3 === void 0 || _options$annotationMa3.emit({
241
+ (_options$annotationMa5 = options.annotationManager) === null || _options$annotationMa5 === void 0 || _options$annotationMa5.emit({
172
242
  name: 'annotationSelectionChanged',
173
243
  data: {
174
244
  annotationId: id,
@@ -187,10 +257,10 @@ var applyDraft = exports.applyDraft = function applyDraft(editorView, options) {
187
257
  };
188
258
  var getDraft = exports.getDraft = function getDraft(editorView, _options) {
189
259
  return function () {
190
- var _getRangeInlineNodeNa2;
191
- var _ref6 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
192
- isDrafting = _ref6.isDrafting,
193
- draftDecorationSet = _ref6.draftDecorationSet;
260
+ var _getRangeInlineNodeNa3;
261
+ var _ref7 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
262
+ isDrafting = _ref7.isDrafting,
263
+ draftDecorationSet = _ref7.draftDecorationSet;
194
264
  if (!isDrafting) {
195
265
  return {
196
266
  success: false,
@@ -206,13 +276,13 @@ var getDraft = exports.getDraft = function getDraft(editorView, _options) {
206
276
  }
207
277
  var from = decorations[0].from;
208
278
  var targetElement = domRefFromPos(editorView, from);
209
- var inlineNodeTypes = (_getRangeInlineNodeNa2 = (0, _annotation2.getRangeInlineNodeNames)({
279
+ var inlineNodeTypes = (_getRangeInlineNodeNa3 = (0, _annotation2.getRangeInlineNodeNames)({
210
280
  doc: editorView.state.doc,
211
281
  pos: {
212
282
  from: from,
213
283
  to: decorations[decorations.length - 1].to
214
284
  }
215
- })) !== null && _getRangeInlineNodeNa2 !== void 0 ? _getRangeInlineNodeNa2 : [];
285
+ })) !== null && _getRangeInlineNodeNa3 !== void 0 ? _getRangeInlineNodeNa3 : [];
216
286
  return {
217
287
  success: true,
218
288
  inlineNodeTypes: inlineNodeTypes,
@@ -224,10 +294,10 @@ var getDraft = exports.getDraft = function getDraft(editorView, _options) {
224
294
  var setIsAnnotationSelected = exports.setIsAnnotationSelected = function setIsAnnotationSelected(editorView, options) {
225
295
  return function (id, isSelected) {
226
296
  var _selectedAnnotations$;
227
- var _ref7 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
228
- annotations = _ref7.annotations,
229
- isDrafting = _ref7.isDrafting,
230
- selectedAnnotations = _ref7.selectedAnnotations;
297
+ var _ref8 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
298
+ annotations = _ref8.annotations,
299
+ isDrafting = _ref8.isDrafting,
300
+ selectedAnnotations = _ref8.selectedAnnotations;
231
301
  if (isDrafting) {
232
302
  return {
233
303
  success: false,
@@ -249,10 +319,10 @@ var setIsAnnotationSelected = exports.setIsAnnotationSelected = function setIsAn
249
319
  if (isSelected !== isCurrentlySelected) {
250
320
  // the annotation is selection is changing.
251
321
  if (isCurrentlySelected && !isSelected) {
252
- var _options$annotationMa4, _getAnnotationInlineN3;
322
+ var _options$annotationMa6, _getAnnotationInlineN3;
253
323
  // the selected annotaion is being unselected, so we need to close the view.
254
324
  (0, _editorCommands.closeComponent)()(editorView.state, editorView.dispatch);
255
- (_options$annotationMa4 = options.annotationManager) === null || _options$annotationMa4 === void 0 || _options$annotationMa4.emit({
325
+ (_options$annotationMa6 = options.annotationManager) === null || _options$annotationMa6 === void 0 || _options$annotationMa6.emit({
256
326
  name: 'annotationSelectionChanged',
257
327
  data: {
258
328
  annotationId: id,
@@ -261,15 +331,15 @@ var setIsAnnotationSelected = exports.setIsAnnotationSelected = function setIsAn
261
331
  }
262
332
  });
263
333
  } else if (!isCurrentlySelected && isSelected) {
264
- var _options$annotationMa6, _getAnnotationInlineN5;
334
+ var _options$annotationMa8, _getAnnotationInlineN5;
265
335
  // the annotation is currently not selected and is being selected, so we need to open the view.
266
336
  (0, _editorCommands.setSelectedAnnotation)(id)(editorView.state, editorView.dispatch);
267
337
 
268
338
  // the current annotations are going to be unselected. So we need to notify listeners of this change also.
269
339
  selectedAnnotations === null || selectedAnnotations === void 0 || selectedAnnotations.forEach(function (annotation) {
270
340
  if (annotation.id !== id) {
271
- var _options$annotationMa5, _getAnnotationInlineN4;
272
- (_options$annotationMa5 = options.annotationManager) === null || _options$annotationMa5 === void 0 || _options$annotationMa5.emit({
341
+ var _options$annotationMa7, _getAnnotationInlineN4;
342
+ (_options$annotationMa7 = options.annotationManager) === null || _options$annotationMa7 === void 0 || _options$annotationMa7.emit({
273
343
  name: 'annotationSelectionChanged',
274
344
  data: {
275
345
  annotationId: annotation.id,
@@ -281,7 +351,7 @@ var setIsAnnotationSelected = exports.setIsAnnotationSelected = function setIsAn
281
351
  });
282
352
 
283
353
  // Lastly we need to emit the event for the selected annotation.
284
- (_options$annotationMa6 = options.annotationManager) === null || _options$annotationMa6 === void 0 || _options$annotationMa6.emit({
354
+ (_options$annotationMa8 = options.annotationManager) === null || _options$annotationMa8 === void 0 || _options$annotationMa8.emit({
285
355
  name: 'annotationSelectionChanged',
286
356
  data: {
287
357
  annotationId: id,
@@ -300,9 +370,9 @@ var setIsAnnotationSelected = exports.setIsAnnotationSelected = function setIsAn
300
370
  var setIsAnnotationHovered = exports.setIsAnnotationHovered = function setIsAnnotationHovered(editorView, _options) {
301
371
  return function (id, isHovered) {
302
372
  var _hoveredAnnotations$f;
303
- var _ref8 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
304
- annotations = _ref8.annotations,
305
- hoveredAnnotations = _ref8.hoveredAnnotations;
373
+ var _ref9 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
374
+ annotations = _ref9.annotations,
375
+ hoveredAnnotations = _ref9.hoveredAnnotations;
306
376
 
307
377
  // If there is no annotation state with this id then we can assume the annotation is invalid.
308
378
  if (!(annotations !== null && annotations !== void 0 && annotations.hasOwnProperty(id))) {
@@ -333,8 +403,8 @@ var setIsAnnotationHovered = exports.setIsAnnotationHovered = function setIsAnno
333
403
  };
334
404
  var clearAnnotation = exports.clearAnnotation = function clearAnnotation(editorView, options) {
335
405
  return function (id) {
336
- var _ref9 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
337
- annotations = _ref9.annotations;
406
+ var _ref0 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
407
+ annotations = _ref0.annotations;
338
408
 
339
409
  // If there is no annotation state with this id then we can assume the annotation is invalid.
340
410
  if (!(annotations !== null && annotations !== void 0 && annotations.hasOwnProperty(id))) {
@@ -65,6 +65,13 @@ export const annotationPlugin = ({
65
65
  var _annotationProviders$, _annotationProviders$2;
66
66
  return fg('cc_maui_annotations_on_extensions') && (annotationProviders === null || annotationProviders === void 0 ? void 0 : (_annotationProviders$ = (_annotationProviders$2 = annotationProviders.inlineComment).isBlockNodeSupported) === null || _annotationProviders$ === void 0 ? void 0 : _annotationProviders$.call(_annotationProviders$2, node)) === true;
67
67
  },
68
+ getAddCommentPermission: () => {
69
+ var _annotationProviders$3, _annotationProviders$4, _annotationProviders$5;
70
+ return {
71
+ canAddComments: (_annotationProviders$3 = annotationProviders === null || annotationProviders === void 0 ? void 0 : (_annotationProviders$4 = (_annotationProviders$5 = annotationProviders.inlineComment).getCanAddComments) === null || _annotationProviders$4 === void 0 ? void 0 : _annotationProviders$4.call(_annotationProviders$5)) !== null && _annotationProviders$3 !== void 0 ? _annotationProviders$3 : true,
72
+ contentType: annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.contentType
73
+ };
74
+ },
68
75
  hasAnyUnResolvedAnnotationInPage,
69
76
  requestCloseInlineComment,
70
77
  stripNonExistingAnnotations,
@@ -73,10 +80,10 @@ export const annotationPlugin = ({
73
80
  return createAnnotation(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api)(annotationId, AnnotationTypes.INLINE_COMMENT, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.isBlockNodeSupported);
74
81
  },
75
82
  removeInlineCommentAnnotation: annotationId => {
76
- var _api$analytics2, _annotationProviders$3;
77
- return removeInlineCommentFromDoc(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(annotationId, (_annotationProviders$3 = annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes) !== null && _annotationProviders$3 !== void 0 ? _annotationProviders$3 : [], annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.isBlockNodeSupported);
83
+ var _api$analytics2, _annotationProviders$6;
84
+ return removeInlineCommentFromDoc(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(annotationId, (_annotationProviders$6 = annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes) !== null && _annotationProviders$6 !== void 0 ? _annotationProviders$6 : [], annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.isBlockNodeSupported);
78
85
  },
79
- setInlineCommentDraftState: setInlineCommentDraftState(api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes, undefined, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.isBlockNodeSupported),
86
+ setInlineCommentDraftState: setInlineCommentDraftState(api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes, undefined, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.isBlockNodeSupported, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.createCommentExperience),
80
87
  showCommentForBlockNode: showInlineCommentForBlockNode(annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.isBlockNodeSupported),
81
88
  setSelectedAnnotation,
82
89
  setPendingSelectedAnnotation
@@ -88,7 +95,10 @@ export const annotationPlugin = ({
88
95
  const pluginState = getPluginState(editorState) || undefined;
89
96
  const clonedPluginState = Object.assign({}, pluginState);
90
97
  clonedPluginState === null || clonedPluginState === void 0 ? true : delete clonedPluginState.featureFlagsPluginState;
91
- return clonedPluginState;
98
+ return {
99
+ ...clonedPluginState,
100
+ annotationManager: annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.annotationManager
101
+ };
92
102
  },
93
103
  pmPlugins: () => [{
94
104
  name: 'annotation',
@@ -3,7 +3,9 @@ import { AnnotationTypes } from '@atlaskit/adf-schema/annotation';
3
3
 
4
4
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics/types/enums';
5
5
  import { RESOLVE_METHOD } from '@atlaskit/editor-common/analytics/types/inline-comment-events';
6
+ import { NATIVE_EMBED_EXTENSION_KEY } from '@atlaskit/editor-common/extensions/manifest-helpers';
6
7
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
8
+ import { fg } from '@atlaskit/platform-feature-flags/fg';
7
9
  import { createCommand } from '../pm-plugins/plugin-factory';
8
10
  import { ACTIONS } from '../pm-plugins/types';
9
11
  import { getPluginState, inlineCommentPluginKey, isSelectionValid, isSupportedBlockNode } from '../pm-plugins/utils';
@@ -204,12 +206,30 @@ export const showInlineCommentForBlockNode = (supportedBlockNodes = [], isBlockN
204
206
  }
205
207
  return false;
206
208
  };
207
- export const setInlineCommentDraftState = (editorAnalyticsAPI, supportedBlockNodes = [], api, isBlockNodeSupported) => (drafting, inputMethod = INPUT_METHOD.TOOLBAR, targetType = 'inline', targetNodeId = undefined, isOpeningMediaCommentFromToolbar) => {
209
+ export const setInlineCommentDraftState = (editorAnalyticsAPI, supportedBlockNodes = [], api, isBlockNodeSupported, createCommentExperience) => (drafting, inputMethod = INPUT_METHOD.TOOLBAR, targetType = 'inline', targetNodeId = undefined, isOpeningMediaCommentFromToolbar) => {
208
210
  const commandAction = getDraftCommandAction(drafting, targetType, targetNodeId, supportedBlockNodes, isBlockNodeSupported, isOpeningMediaCommentFromToolbar);
209
- if (Boolean(api === null || api === void 0 ? void 0 : api.toolbar)) {
210
- return (state, dispatch) => {
211
- const tr = transform.handleDraftState(editorAnalyticsAPI)(drafting, inputMethod)(state.tr, state);
211
+ const draftCommand = !(api !== null && api !== void 0 && api.toolbar) ? createCommand(commandAction, transform.handleDraftState(editorAnalyticsAPI)(drafting, inputMethod)) : undefined;
212
+ return (state, dispatch, view) => {
213
+ // Start tracking only when a valid draft is dispatched, never during dry runs.
214
+ const dispatchDraft = dispatch && drafting && targetType === 'block' && state.selection instanceof NodeSelection && state.selection.node.type.name === 'extension' && state.selection.node.attrs.extensionKey === `${NATIVE_EMBED_EXTENSION_KEY}:maui` && fg('cc_maui_annotations_on_extensions') ? tr => {
215
+ createCommentExperience === null || createCommentExperience === void 0 ? void 0 : createCommentExperience.start({
216
+ attributes: {
217
+ pageClass: 'editor',
218
+ commentType: 'block',
219
+ blockType: 'extension',
220
+ commentTargetType: 'remixEmbed',
221
+ entryPoint: 'highlightActions'
222
+ }
223
+ });
224
+ createCommentExperience === null || createCommentExperience === void 0 ? void 0 : createCommentExperience.initExperience.start();
225
+ dispatch(tr);
226
+ } : dispatch;
227
+ if (Boolean(api === null || api === void 0 ? void 0 : api.toolbar)) {
212
228
  const newPluginState = commandAction(state);
229
+ if (!newPluginState) {
230
+ return false;
231
+ }
232
+ const tr = transform.handleDraftState(editorAnalyticsAPI)(drafting, inputMethod)(state.tr, state);
213
233
  if (tr && newPluginState) {
214
234
  tr.setMeta(inlineCommentPluginKey, newPluginState);
215
235
  if (drafting) {
@@ -217,17 +237,16 @@ export const setInlineCommentDraftState = (editorAnalyticsAPI, supportedBlockNod
217
237
  } else {
218
238
  resetUserIntent(api, tr);
219
239
  }
220
- if (dispatch) {
221
- dispatch(tr);
240
+ if (dispatchDraft) {
241
+ dispatchDraft(tr);
222
242
  }
223
243
  } else {
224
244
  return false;
225
245
  }
226
246
  return true;
227
- };
228
- } else {
229
- return createCommand(commandAction, transform.handleDraftState(editorAnalyticsAPI)(drafting, inputMethod));
230
- }
247
+ }
248
+ return draftCommand ? draftCommand(state, dispatchDraft, view) : false;
249
+ };
231
250
  };
232
251
  export const addInlineComment = (editorAnalyticsAPI, editorAPI) => (id, supportedBlockNodes, isBlockNodeSupported) => {
233
252
  const commandAction = editorState => ({