@atlaskit/editor-plugin-annotation 2.1.9 → 2.2.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,19 @@
1
1
  # @atlaskit/editor-plugin-annotation
2
2
 
3
+ ## 2.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#133398](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/133398)
8
+ [`fd3381fec1435`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/fd3381fec1435) -
9
+ clearing the selectedAnnotations on close of inline comment
10
+
11
+ ## 2.1.10
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+
3
17
  ## 2.1.9
4
18
 
5
19
  ### Patch Changes
@@ -177,7 +177,8 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
177
177
  return onSetVisibility(editorView)(isVisible);
178
178
  };
179
179
  var setSelectedAnnotationFn = function setSelectedAnnotationFn(annotationId) {
180
- if (!annotationId) {
180
+ var pluginState = (0, _utils.getPluginState)(editorView.state);
181
+ if (!annotationId || pluginState !== null && pluginState !== void 0 && pluginState.isInlineCommentViewClosed && (0, _platformFeatureFlags.fg)('platform_editor_listen_for_annotation_clicks')) {
181
182
  (0, _editorCommands.closeComponent)()(editorView.state, editorView.dispatch);
182
183
  } else {
183
184
  (0, _editorCommands.setSelectedAnnotation)(annotationId)(editorView.state, editorView.dispatch);
@@ -232,17 +233,49 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
232
233
  // Mouseup won't be triggered after dropping
233
234
  // Hence, update the mouse data to cancel selecting when drag starts
234
235
  return onMouseUp(view.state, view.dispatch)(event);
236
+ },
237
+ click: function click(view, event) {
238
+ var _event$target$closest, _pluginState$selected;
239
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_listen_for_annotation_clicks')) {
240
+ return false;
241
+ }
242
+ if (!(event.target instanceof HTMLElement)) {
243
+ return false;
244
+ }
245
+
246
+ // Find the nearest ancestor (or self) with the data-id attribute
247
+ var annotationId = (_event$target$closest = event.target.closest('[data-id]')) === null || _event$target$closest === void 0 ? void 0 : _event$target$closest.getAttribute('data-id');
248
+ if (!annotationId) {
249
+ return false;
250
+ }
251
+ var pluginState = (0, _utils.getPluginState)(view.state);
252
+ var isSelected = pluginState === null || pluginState === void 0 || (_pluginState$selected = pluginState.selectedAnnotations) === null || _pluginState$selected === void 0 ? void 0 : _pluginState$selected.some(function (selectedAnnotation) {
253
+ return selectedAnnotation.id === annotationId;
254
+ });
255
+ // If the annotation is selected and the inline comment view is open, do nothing
256
+ // as the user is already in the comment view.
257
+ if (isSelected && !(pluginState !== null && pluginState !== void 0 && pluginState.isInlineCommentViewClosed)) {
258
+ return false;
259
+ }
260
+ var _ref5 = pluginState || {},
261
+ annotations = _ref5.annotations;
262
+ var isUnresolved = annotations && annotations[annotationId] === false;
263
+ if (!isUnresolved) {
264
+ return false;
265
+ }
266
+ (0, _editorCommands.setSelectedAnnotation)(annotationId)(view.state, view.dispatch);
267
+ return true;
235
268
  }
236
269
  },
237
270
  decorations: function decorations(state) {
238
271
  // highlight comments, depending on state
239
- var _ref5 = (0, _utils.getPluginState)(state) || {},
240
- draftDecorationSet = _ref5.draftDecorationSet,
241
- annotations = _ref5.annotations,
242
- selectedAnnotations = _ref5.selectedAnnotations,
243
- isVisible = _ref5.isVisible,
244
- isInlineCommentViewClosed = _ref5.isInlineCommentViewClosed,
245
- hoveredAnnotations = _ref5.hoveredAnnotations;
272
+ var _ref6 = (0, _utils.getPluginState)(state) || {},
273
+ draftDecorationSet = _ref6.draftDecorationSet,
274
+ annotations = _ref6.annotations,
275
+ selectedAnnotations = _ref6.selectedAnnotations,
276
+ isVisible = _ref6.isVisible,
277
+ isInlineCommentViewClosed = _ref6.isInlineCommentViewClosed,
278
+ hoveredAnnotations = _ref6.hoveredAnnotations;
246
279
  var decorations = draftDecorationSet !== null && draftDecorationSet !== void 0 ? draftDecorationSet : _view.DecorationSet.empty;
247
280
  var focusDecorations = [];
248
281
  state.doc.descendants(function (node, pos) {
@@ -8,6 +8,7 @@ exports.default = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
10
  var _view = require("@atlaskit/editor-prosemirror/view");
11
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
12
  var _types = require("./types");
12
13
  var _utils = require("./utils");
13
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; }
@@ -35,6 +36,8 @@ var _default = exports.default = function _default(pluginState, action) {
35
36
  isInlineCommentViewClosed: true,
36
37
  isDrafting: false,
37
38
  isOpeningMediaCommentFromToolbar: false
39
+ }, (0, _platformFeatureFlags.fg)('platform_editor_annotation_selected_annotation') && {
40
+ selectedAnnotations: []
38
41
  });
39
42
  case _types.ACTIONS.ADD_INLINE_COMMENT:
40
43
  var updatedPluginState = getNewDraftState(pluginState, action.data.drafting, action.data.editorState);
@@ -329,7 +329,7 @@ var isSelectionValid = exports.isSelectionValid = function isSelectionValid(stat
329
329
  var allowedInlineNodes = ['emoji', 'status', 'date', 'mention', 'inlineCard'];
330
330
  var isSelectionEmpty = selection.empty;
331
331
  var isTextOrAllSelection = selection instanceof _state.TextSelection || selection instanceof _state.AllSelection;
332
- var isValidNodeSelection = selection instanceof _state.NodeSelection && allowedInlineNodes.includes(selection.node.type.name) && (0, _platformFeatureFlags.fg)('platform_inline_node_as_valid_annotation_selection');
332
+ var isValidNodeSelection = selection instanceof _state.NodeSelection && allowedInlineNodes.includes(selection.node.type.name);
333
333
  var isValidSelection = isTextOrAllSelection || isValidNodeSelection;
334
334
 
335
335
  // Allow media so that it can enter draft mode
@@ -13,8 +13,10 @@ exports.AnnotationTestIds = exports.AnnotationSelectionType = void 0;
13
13
  */
14
14
  var AnnotationSelectionType = exports.AnnotationSelectionType = /*#__PURE__*/function (AnnotationSelectionType) {
15
15
  AnnotationSelectionType["INVALID"] = "invalid";
16
+ // Annotation should not be created, toolbar should not be shown
16
17
  AnnotationSelectionType["DISABLED"] = "disabled";
17
- AnnotationSelectionType["VALID"] = "valid";
18
+ // Annotation should not be created, toolbar should be shown, but disabled
19
+ AnnotationSelectionType["VALID"] = "valid"; // Annotation can be created
18
20
  return AnnotationSelectionType;
19
21
  }({});
20
22
  var prefix = 'ak-editor-annotation';
@@ -109,7 +109,8 @@ export const inlineCommentPlugin = options => {
109
109
  const mouseUp = event => onMouseUp(editorView.state, editorView.dispatch)(event);
110
110
  const setVisibility = isVisible => onSetVisibility(editorView)(isVisible);
111
111
  const setSelectedAnnotationFn = annotationId => {
112
- if (!annotationId) {
112
+ const pluginState = getPluginState(editorView.state);
113
+ if (!annotationId || pluginState !== null && pluginState !== void 0 && pluginState.isInlineCommentViewClosed && fg('platform_editor_listen_for_annotation_clicks')) {
113
114
  closeComponent()(editorView.state, editorView.dispatch);
114
115
  } else {
115
116
  setSelectedAnnotation(annotationId)(editorView.state, editorView.dispatch);
@@ -167,6 +168,37 @@ export const inlineCommentPlugin = options => {
167
168
  // Mouseup won't be triggered after dropping
168
169
  // Hence, update the mouse data to cancel selecting when drag starts
169
170
  return onMouseUp(view.state, view.dispatch)(event);
171
+ },
172
+ click: (view, event) => {
173
+ var _event$target$closest, _pluginState$selected;
174
+ if (!fg('platform_editor_listen_for_annotation_clicks')) {
175
+ return false;
176
+ }
177
+ if (!(event.target instanceof HTMLElement)) {
178
+ return false;
179
+ }
180
+
181
+ // Find the nearest ancestor (or self) with the data-id attribute
182
+ const annotationId = (_event$target$closest = event.target.closest('[data-id]')) === null || _event$target$closest === void 0 ? void 0 : _event$target$closest.getAttribute('data-id');
183
+ if (!annotationId) {
184
+ return false;
185
+ }
186
+ const pluginState = getPluginState(view.state);
187
+ const isSelected = pluginState === null || pluginState === void 0 ? void 0 : (_pluginState$selected = pluginState.selectedAnnotations) === null || _pluginState$selected === void 0 ? void 0 : _pluginState$selected.some(selectedAnnotation => selectedAnnotation.id === annotationId);
188
+ // If the annotation is selected and the inline comment view is open, do nothing
189
+ // as the user is already in the comment view.
190
+ if (isSelected && !(pluginState !== null && pluginState !== void 0 && pluginState.isInlineCommentViewClosed)) {
191
+ return false;
192
+ }
193
+ const {
194
+ annotations
195
+ } = pluginState || {};
196
+ const isUnresolved = annotations && annotations[annotationId] === false;
197
+ if (!isUnresolved) {
198
+ return false;
199
+ }
200
+ setSelectedAnnotation(annotationId)(view.state, view.dispatch);
201
+ return true;
170
202
  }
171
203
  },
172
204
  decorations(state) {
@@ -1,4 +1,5 @@
1
1
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
+ import { fg } from '@atlaskit/platform-feature-flags';
2
3
  import { ACTIONS } from './types';
3
4
  import { addDraftDecoration, resolveDraftBookmark } from './utils';
4
5
  export default ((pluginState, action) => {
@@ -30,7 +31,10 @@ export default ((pluginState, action) => {
30
31
  ...pluginState,
31
32
  isInlineCommentViewClosed: true,
32
33
  isDrafting: false,
33
- isOpeningMediaCommentFromToolbar: false
34
+ isOpeningMediaCommentFromToolbar: false,
35
+ ...(fg('platform_editor_annotation_selected_annotation') && {
36
+ selectedAnnotations: []
37
+ })
34
38
  };
35
39
  case ACTIONS.ADD_INLINE_COMMENT:
36
40
  const updatedPluginState = getNewDraftState(pluginState, action.data.drafting, action.data.editorState);
@@ -298,7 +298,7 @@ export const isSelectionValid = (state, _supportedNodes = []) => {
298
298
  const allowedInlineNodes = ['emoji', 'status', 'date', 'mention', 'inlineCard'];
299
299
  const isSelectionEmpty = selection.empty;
300
300
  const isTextOrAllSelection = selection instanceof TextSelection || selection instanceof AllSelection;
301
- const isValidNodeSelection = selection instanceof NodeSelection && allowedInlineNodes.includes(selection.node.type.name) && fg('platform_inline_node_as_valid_annotation_selection');
301
+ const isValidNodeSelection = selection instanceof NodeSelection && allowedInlineNodes.includes(selection.node.type.name);
302
302
  const isValidSelection = isTextOrAllSelection || isValidNodeSelection;
303
303
 
304
304
  // Allow media so that it can enter draft mode
@@ -9,8 +9,10 @@
9
9
 
10
10
  export let AnnotationSelectionType = /*#__PURE__*/function (AnnotationSelectionType) {
11
11
  AnnotationSelectionType["INVALID"] = "invalid";
12
+ // Annotation should not be created, toolbar should not be shown
12
13
  AnnotationSelectionType["DISABLED"] = "disabled";
13
- AnnotationSelectionType["VALID"] = "valid";
14
+ // Annotation should not be created, toolbar should be shown, but disabled
15
+ AnnotationSelectionType["VALID"] = "valid"; // Annotation can be created
14
16
  return AnnotationSelectionType;
15
17
  }({});
16
18
  const prefix = 'ak-editor-annotation';
@@ -170,7 +170,8 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
170
170
  return onSetVisibility(editorView)(isVisible);
171
171
  };
172
172
  var setSelectedAnnotationFn = function setSelectedAnnotationFn(annotationId) {
173
- if (!annotationId) {
173
+ var pluginState = getPluginState(editorView.state);
174
+ if (!annotationId || pluginState !== null && pluginState !== void 0 && pluginState.isInlineCommentViewClosed && fg('platform_editor_listen_for_annotation_clicks')) {
174
175
  closeComponent()(editorView.state, editorView.dispatch);
175
176
  } else {
176
177
  setSelectedAnnotation(annotationId)(editorView.state, editorView.dispatch);
@@ -225,17 +226,49 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
225
226
  // Mouseup won't be triggered after dropping
226
227
  // Hence, update the mouse data to cancel selecting when drag starts
227
228
  return onMouseUp(view.state, view.dispatch)(event);
229
+ },
230
+ click: function click(view, event) {
231
+ var _event$target$closest, _pluginState$selected;
232
+ if (!fg('platform_editor_listen_for_annotation_clicks')) {
233
+ return false;
234
+ }
235
+ if (!(event.target instanceof HTMLElement)) {
236
+ return false;
237
+ }
238
+
239
+ // Find the nearest ancestor (or self) with the data-id attribute
240
+ var annotationId = (_event$target$closest = event.target.closest('[data-id]')) === null || _event$target$closest === void 0 ? void 0 : _event$target$closest.getAttribute('data-id');
241
+ if (!annotationId) {
242
+ return false;
243
+ }
244
+ var pluginState = getPluginState(view.state);
245
+ var isSelected = pluginState === null || pluginState === void 0 || (_pluginState$selected = pluginState.selectedAnnotations) === null || _pluginState$selected === void 0 ? void 0 : _pluginState$selected.some(function (selectedAnnotation) {
246
+ return selectedAnnotation.id === annotationId;
247
+ });
248
+ // If the annotation is selected and the inline comment view is open, do nothing
249
+ // as the user is already in the comment view.
250
+ if (isSelected && !(pluginState !== null && pluginState !== void 0 && pluginState.isInlineCommentViewClosed)) {
251
+ return false;
252
+ }
253
+ var _ref5 = pluginState || {},
254
+ annotations = _ref5.annotations;
255
+ var isUnresolved = annotations && annotations[annotationId] === false;
256
+ if (!isUnresolved) {
257
+ return false;
258
+ }
259
+ setSelectedAnnotation(annotationId)(view.state, view.dispatch);
260
+ return true;
228
261
  }
229
262
  },
230
263
  decorations: function decorations(state) {
231
264
  // highlight comments, depending on state
232
- var _ref5 = getPluginState(state) || {},
233
- draftDecorationSet = _ref5.draftDecorationSet,
234
- annotations = _ref5.annotations,
235
- selectedAnnotations = _ref5.selectedAnnotations,
236
- isVisible = _ref5.isVisible,
237
- isInlineCommentViewClosed = _ref5.isInlineCommentViewClosed,
238
- hoveredAnnotations = _ref5.hoveredAnnotations;
265
+ var _ref6 = getPluginState(state) || {},
266
+ draftDecorationSet = _ref6.draftDecorationSet,
267
+ annotations = _ref6.annotations,
268
+ selectedAnnotations = _ref6.selectedAnnotations,
269
+ isVisible = _ref6.isVisible,
270
+ isInlineCommentViewClosed = _ref6.isInlineCommentViewClosed,
271
+ hoveredAnnotations = _ref6.hoveredAnnotations;
239
272
  var decorations = draftDecorationSet !== null && draftDecorationSet !== void 0 ? draftDecorationSet : DecorationSet.empty;
240
273
  var focusDecorations = [];
241
274
  state.doc.descendants(function (node, pos) {
@@ -3,6 +3,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  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; }
4
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
5
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
+ import { fg } from '@atlaskit/platform-feature-flags';
6
7
  import { ACTIONS } from './types';
7
8
  import { addDraftDecoration, resolveDraftBookmark } from './utils';
8
9
  export default (function (pluginState, action) {
@@ -28,6 +29,8 @@ export default (function (pluginState, action) {
28
29
  isInlineCommentViewClosed: true,
29
30
  isDrafting: false,
30
31
  isOpeningMediaCommentFromToolbar: false
32
+ }, fg('platform_editor_annotation_selected_annotation') && {
33
+ selectedAnnotations: []
31
34
  });
32
35
  case ACTIONS.ADD_INLINE_COMMENT:
33
36
  var updatedPluginState = getNewDraftState(pluginState, action.data.drafting, action.data.editorState);
@@ -312,7 +312,7 @@ export var isSelectionValid = function isSelectionValid(state) {
312
312
  var allowedInlineNodes = ['emoji', 'status', 'date', 'mention', 'inlineCard'];
313
313
  var isSelectionEmpty = selection.empty;
314
314
  var isTextOrAllSelection = selection instanceof TextSelection || selection instanceof AllSelection;
315
- var isValidNodeSelection = selection instanceof NodeSelection && allowedInlineNodes.includes(selection.node.type.name) && fg('platform_inline_node_as_valid_annotation_selection');
315
+ var isValidNodeSelection = selection instanceof NodeSelection && allowedInlineNodes.includes(selection.node.type.name);
316
316
  var isValidSelection = isTextOrAllSelection || isValidNodeSelection;
317
317
 
318
318
  // Allow media so that it can enter draft mode
@@ -9,8 +9,10 @@
9
9
 
10
10
  export var AnnotationSelectionType = /*#__PURE__*/function (AnnotationSelectionType) {
11
11
  AnnotationSelectionType["INVALID"] = "invalid";
12
+ // Annotation should not be created, toolbar should not be shown
12
13
  AnnotationSelectionType["DISABLED"] = "disabled";
13
- AnnotationSelectionType["VALID"] = "valid";
14
+ // Annotation should not be created, toolbar should be shown, but disabled
15
+ AnnotationSelectionType["VALID"] = "valid"; // Annotation can be created
14
16
  return AnnotationSelectionType;
15
17
  }({});
16
18
  var prefix = 'ak-editor-annotation';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-annotation",
3
- "version": "2.1.9",
3
+ "version": "2.2.0",
4
4
  "description": "Annotation plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -32,16 +32,16 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@atlaskit/adf-schema": "^47.6.0",
35
- "@atlaskit/editor-common": "^102.13.0",
35
+ "@atlaskit/editor-common": "^102.15.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^2.2.0",
37
37
  "@atlaskit/editor-plugin-connectivity": "^2.0.0",
38
38
  "@atlaskit/editor-plugin-editor-viewmode-effects": "^2.0.0",
39
39
  "@atlaskit/editor-plugin-feature-flags": "^1.3.0",
40
40
  "@atlaskit/editor-prosemirror": "7.0.0",
41
- "@atlaskit/icon": "^25.0.0",
42
- "@atlaskit/onboarding": "^13.0.0",
41
+ "@atlaskit/icon": "^25.3.0",
42
+ "@atlaskit/onboarding": "^14.0.0",
43
43
  "@atlaskit/platform-feature-flags": "^1.1.0",
44
- "@atlaskit/tmp-editor-statsig": "^4.4.0",
44
+ "@atlaskit/tmp-editor-statsig": "^4.5.0",
45
45
  "@babel/runtime": "^7.0.0"
46
46
  },
47
47
  "peerDependencies": {
@@ -96,9 +96,6 @@
96
96
  "editor_inline_comments_on_inline_nodes": {
97
97
  "type": "boolean"
98
98
  },
99
- "platform_inline_node_as_valid_annotation_selection": {
100
- "type": "boolean"
101
- },
102
99
  "platform_editor_fix_missing_selected_annotations": {
103
100
  "type": "boolean"
104
101
  },
@@ -107,6 +104,12 @@
107
104
  },
108
105
  "confluence_comments_create_comment_experience": {
109
106
  "type": "boolean"
107
+ },
108
+ "platform_editor_listen_for_annotation_clicks": {
109
+ "type": "boolean"
110
+ },
111
+ "platform_editor_annotation_selected_annotation": {
112
+ "type": "boolean"
110
113
  }
111
114
  }
112
115
  }