@atlaskit/editor-core 190.0.0 → 190.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.
Files changed (30) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/plugins/alignment/ui/ToolbarAlignment/index.js +0 -6
  3. package/dist/cjs/plugins/annotation/pm-plugins/inline-comment.js +7 -2
  4. package/dist/cjs/plugins/annotation/pm-plugins/plugin-factory.js +43 -2
  5. package/dist/cjs/plugins/annotation/pm-plugins/reducer.js +10 -2
  6. package/dist/cjs/plugins/annotation/ui/InlineCommentView.js +4 -2
  7. package/dist/cjs/plugins/annotation/utils.js +17 -1
  8. package/dist/cjs/ui/Alignment/index.js +1 -0
  9. package/dist/cjs/version-wrapper.js +1 -1
  10. package/dist/es2019/plugins/alignment/ui/ToolbarAlignment/index.js +0 -7
  11. package/dist/es2019/plugins/annotation/pm-plugins/inline-comment.js +5 -2
  12. package/dist/es2019/plugins/annotation/pm-plugins/plugin-factory.js +50 -3
  13. package/dist/es2019/plugins/annotation/pm-plugins/reducer.js +15 -4
  14. package/dist/es2019/plugins/annotation/ui/InlineCommentView.js +4 -2
  15. package/dist/es2019/plugins/annotation/utils.js +10 -0
  16. package/dist/es2019/ui/Alignment/index.js +1 -0
  17. package/dist/es2019/version-wrapper.js +1 -1
  18. package/dist/esm/plugins/alignment/ui/ToolbarAlignment/index.js +0 -6
  19. package/dist/esm/plugins/annotation/pm-plugins/inline-comment.js +7 -2
  20. package/dist/esm/plugins/annotation/pm-plugins/plugin-factory.js +44 -3
  21. package/dist/esm/plugins/annotation/pm-plugins/reducer.js +10 -2
  22. package/dist/esm/plugins/annotation/ui/InlineCommentView.js +4 -2
  23. package/dist/esm/plugins/annotation/utils.js +14 -0
  24. package/dist/esm/ui/Alignment/index.js +1 -0
  25. package/dist/esm/version-wrapper.js +1 -1
  26. package/dist/types/plugins/annotation/pm-plugins/types.d.ts +1 -0
  27. package/dist/types/plugins/annotation/utils.d.ts +5 -0
  28. package/dist/types-ts4.5/plugins/annotation/pm-plugins/types.d.ts +1 -0
  29. package/dist/types-ts4.5/plugins/annotation/utils.d.ts +5 -0
  30. package/package.json +4 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @atlaskit/editor-core
2
2
 
3
+ ## 190.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#59443](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/59443) [`c9c6e1634058`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c9c6e1634058) - [ux] ED-20733: Decouple selected annotation logic from logic to close the inline comment view. This fixes the bug where the inline comment view can be unexpectedly opened from doc changes (through remote editors or non-selection altering changes such as expanding / collapsing expand blocks). Changes are behind platform.editor.annotation.decouple-inline-comment-closed_flmox.
8
+
9
+ ### Patch Changes
10
+
11
+ - [#62137](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/62137) [`503cb77af9ce`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/503cb77af9ce) - [ux] Fix: Clicking on alignment button did not close the alignment popup.
12
+
3
13
  ## 190.0.0
4
14
 
5
15
  ### Major Changes
@@ -97,12 +97,6 @@ var AlignmentToolbar = exports.AlignmentToolbar = /*#__PURE__*/function (_React$
97
97
  boundariesElement: popupsBoundariesElement,
98
98
  scrollableElement: popupsScrollableElement,
99
99
  isOpen: isOpen,
100
- onOpenChange: function onOpenChange(_ref) {
101
- var isOpen = _ref.isOpen;
102
- _this2.setState({
103
- isOpen: isOpen
104
- });
105
- },
106
100
  handleClickOutside: function handleClickOutside(event) {
107
101
  if (event instanceof MouseEvent) {
108
102
  _this2.hide({
@@ -13,6 +13,7 @@ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
13
13
  var _view = require("@atlaskit/editor-prosemirror/view");
14
14
  var _adfSchema = require("@atlaskit/adf-schema");
15
15
  var _nodeviews = require("../nodeviews");
16
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
16
17
  var _commands = require("../commands");
17
18
  var _utils = require("../utils");
18
19
  var _pluginFactory = require("./plugin-factory");
@@ -84,6 +85,7 @@ var initialState = function initialState() {
84
85
  isSelecting: false
85
86
  },
86
87
  disallowOnWhitespace: disallowOnWhitespace,
88
+ isInlineCommentViewClosed: false,
87
89
  isVisible: true,
88
90
  skipSelectionHandling: false
89
91
  };
@@ -211,14 +213,17 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
211
213
  draftDecorationSet = _ref5.draftDecorationSet,
212
214
  annotations = _ref5.annotations,
213
215
  selectedAnnotations = _ref5.selectedAnnotations,
214
- isVisible = _ref5.isVisible;
216
+ isVisible = _ref5.isVisible,
217
+ isInlineCommentViewClosed = _ref5.isInlineCommentViewClosed;
215
218
  var decorations = draftDecorationSet !== null && draftDecorationSet !== void 0 ? draftDecorationSet : _view.DecorationSet.empty;
216
219
  var focusDecorations = [];
217
220
  state.doc.descendants(function (node, pos) {
218
221
  node.marks.filter(function (mark) {
219
222
  return mark.type === state.schema.marks.annotation;
220
223
  }).forEach(function (mark) {
221
- var isSelected = !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
224
+ var isSelected = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
225
+ return selectedAnnotation.id === mark.attrs.id;
226
+ })) : !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
222
227
  return selectedAnnotation.id === mark.attrs.id;
223
228
  }));
224
229
  var isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
@@ -8,12 +8,13 @@ exports.createPluginState = exports.createCommand = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _pluginStateFactory = require("../../../utils/plugin-state-factory");
10
10
  var _utils = require("../utils");
11
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
12
  var _reducer = _interopRequireDefault(require("./reducer"));
12
13
  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; }
13
14
  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) { (0, _defineProperty2.default)(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; }
14
15
  var handleDocChanged = function handleDocChanged(tr, prevPluginState) {
15
16
  if (!tr.getMeta('replaceDocument')) {
16
- return handleSelectionChanged(tr, prevPluginState);
17
+ return (0, _platformFeatureFlags.getBooleanFF)('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? getSelectionChangedHandler(false)(tr, prevPluginState) : handleSelectionChanged(tr, prevPluginState);
17
18
  }
18
19
  return _objectSpread(_objectSpread({}, prevPluginState), {}, {
19
20
  dirtyAnnotations: true
@@ -38,8 +39,48 @@ var handleSelectionChanged = function handleSelectionChanged(tr, pluginState) {
38
39
  }
39
40
  return pluginState;
40
41
  };
42
+ var getSelectionChangedHandler = function getSelectionChangedHandler(reopenCommentView) {
43
+ return function (tr, pluginState) {
44
+ /**
45
+ * If feature flag is **OFF** we want to keep the old behavior. Note that
46
+ * reopenCommentView is not relevant here when using old behaviour.
47
+ *
48
+ * Feature flag is evaluated here rather than directly in onSelectionChanged where it is assigned
49
+ * to prevent the plugin from setting up the handler before the feature flag is evaluated.
50
+ *
51
+ * This comment / logic can be cleaned up once the feature flag is removed.
52
+ */
53
+ if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.annotation.decouple-inline-comment-closed_flmox')) {
54
+ return handleSelectionChanged(tr, pluginState);
55
+ }
56
+ if (pluginState.skipSelectionHandling) {
57
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
58
+ skipSelectionHandling: false
59
+ }, reopenCommentView && {
60
+ isInlineCommentViewClosed: false
61
+ });
62
+ }
63
+ var selectedAnnotations = (0, _utils.findAnnotationsInSelection)(tr.selection, tr.doc);
64
+ if (selectedAnnotations.length === 0) {
65
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
66
+ selectedAnnotations: selectedAnnotations,
67
+ isInlineCommentViewClosed: true
68
+ });
69
+ }
70
+ if ((0, _utils.isSelectedAnnotationsChanged)(selectedAnnotations, pluginState.selectedAnnotations)) {
71
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
72
+ selectedAnnotations: selectedAnnotations
73
+ }, reopenCommentView && {
74
+ isInlineCommentViewClosed: false
75
+ });
76
+ }
77
+ return _objectSpread(_objectSpread({}, pluginState), reopenCommentView && {
78
+ isInlineCommentViewClosed: false
79
+ });
80
+ };
81
+ };
41
82
  var _pluginFactory = (0, _pluginStateFactory.pluginFactory)(_utils.inlineCommentPluginKey, _reducer.default, {
42
- onSelectionChanged: handleSelectionChanged,
83
+ onSelectionChanged: getSelectionChangedHandler(true),
43
84
  onDocChanged: handleDocChanged,
44
85
  mapping: function mapping(tr, pluginState) {
45
86
  var draftDecorationSet = pluginState.draftDecorationSet,
@@ -7,9 +7,10 @@ Object.defineProperty(exports, "__esModule", {
7
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
- var _types = require("./types");
11
10
  var _view = require("@atlaskit/editor-prosemirror/view");
11
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
12
  var _utils = require("../utils");
13
+ var _types = require("./types");
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; }
14
15
  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) { (0, _defineProperty2.default)(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; }
15
16
  var _default = exports.default = function _default(pluginState, action) {
@@ -31,7 +32,9 @@ var _default = exports.default = function _default(pluginState, action) {
31
32
  annotations: {}
32
33
  });
33
34
  case _types.ACTIONS.CLOSE_COMPONENT:
34
- return _objectSpread(_objectSpread({}, pluginState), {}, {
35
+ return (0, _platformFeatureFlags.getBooleanFF)('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? _objectSpread(_objectSpread({}, pluginState), {}, {
36
+ isInlineCommentViewClosed: true
37
+ }) : _objectSpread(_objectSpread({}, pluginState), {}, {
35
38
  selectedAnnotations: []
36
39
  });
37
40
  case _types.ACTIONS.ADD_INLINE_COMMENT:
@@ -39,6 +42,8 @@ var _default = exports.default = function _default(pluginState, action) {
39
42
  return _objectSpread(_objectSpread({}, updatedPluginState), {}, {
40
43
  selectedAnnotations: [].concat((0, _toConsumableArray2.default)(updatedPluginState.selectedAnnotations), (0, _toConsumableArray2.default)(action.data.selectedAnnotations)),
41
44
  annotations: _objectSpread(_objectSpread({}, pluginState.annotations), action.data.inlineComments)
45
+ }, (0, _platformFeatureFlags.getBooleanFF)('platform.editor.annotation.decouple-inline-comment-closed_flmox') && {
46
+ isInlineCommentViewClosed: false
42
47
  });
43
48
  case _types.ACTIONS.INLINE_COMMENT_SET_VISIBLE:
44
49
  var isVisible = action.data.isVisible;
@@ -52,6 +57,9 @@ var _default = exports.default = function _default(pluginState, action) {
52
57
  return _objectSpread(_objectSpread({}, pluginState), {}, {
53
58
  selectedAnnotations: (0, _toConsumableArray2.default)(action.data.selectedAnnotations),
54
59
  skipSelectionHandling: true
60
+ }, (0, _platformFeatureFlags.getBooleanFF)('platform.editor.annotation.decouple-inline-comment-closed_flmox') && {
61
+ // if selecting annotation explicitly, reopen the comment view
62
+ isInlineCommentViewClosed: false
55
63
  });
56
64
  default:
57
65
  return pluginState;
@@ -8,6 +8,7 @@ exports.InlineCommentView = InlineCommentView;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _react = _interopRequireDefault(require("react"));
10
10
  var _utils = require("@atlaskit/editor-prosemirror/utils");
11
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
12
  var _AnnotationViewWrapper = require("./AnnotationViewWrapper");
12
13
  var _types = require("../types");
13
14
  var _utils2 = require("../utils");
@@ -44,7 +45,8 @@ function InlineCommentView(_ref) {
44
45
  var _ref2 = inlineCommentState || {},
45
46
  bookmark = _ref2.bookmark,
46
47
  selectedAnnotations = _ref2.selectedAnnotations,
47
- annotations = _ref2.annotations;
48
+ annotations = _ref2.annotations,
49
+ isInlineCommentViewClosed = _ref2.isInlineCommentViewClosed;
48
50
  var annotationsList = (0, _utils2.getAllAnnotations)(editorView.state.doc);
49
51
  var selection = (0, _utils2.getSelectionPositions)(state, inlineCommentState);
50
52
  var position = findPosForDOM(selection);
@@ -122,7 +124,7 @@ function InlineCommentView(_ref) {
122
124
  };
123
125
  dispatchAnalyticsEvent(payload);
124
126
  };
125
- if (!selectedAnnotations) {
127
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.annotation.decouple-inline-comment-closed_flmox') && isInlineCommentViewClosed || !selectedAnnotations) {
126
128
  return null;
127
129
  }
128
130
  return /*#__PURE__*/_react.default.createElement(_AnnotationViewWrapper.AnnotationViewWrapper, {
@@ -21,7 +21,9 @@ Object.defineProperty(exports, "hasAnnotationMark", {
21
21
  });
22
22
  exports.hasInvalidNodes = void 0;
23
23
  exports.hasInvalidWhitespaceNode = hasInvalidWhitespaceNode;
24
- exports.isSelectionValid = exports.inlineCommentPluginKey = void 0;
24
+ exports.inlineCommentPluginKey = void 0;
25
+ exports.isSelectedAnnotationsChanged = isSelectedAnnotationsChanged;
26
+ exports.isSelectionValid = void 0;
25
27
  exports.stripNonExistingAnnotations = stripNonExistingAnnotations;
26
28
  exports.surroundingMarks = void 0;
27
29
  var _state = require("@atlaskit/editor-prosemirror/state");
@@ -353,4 +355,18 @@ function stripNonExistingAnnotationsFromNode(node, state) {
353
355
  });
354
356
  }
355
357
  return node;
358
+ }
359
+
360
+ /**
361
+ * Compares two sets of annotationInfos to see if the annotations have changed
362
+ * This function assumes annotations will have unique id's for simplicity
363
+ */
364
+ function isSelectedAnnotationsChanged(oldSelectedAnnotations, newSelectedAnnotations) {
365
+ return newSelectedAnnotations.length !== oldSelectedAnnotations.length ||
366
+ // assuming annotations have unique id's for simplicity
367
+ newSelectedAnnotations.some(function (annotation) {
368
+ return !oldSelectedAnnotations.find(function (pluginStateAnnotation) {
369
+ return annotation.id === pluginStateAnnotation.id && annotation.type === pluginStateAnnotation.type;
370
+ });
371
+ });
356
372
  }
@@ -47,6 +47,7 @@ var Alignment = /*#__PURE__*/function (_PureComponent) {
47
47
  className = _this$props.className,
48
48
  intl = _this$props.intl;
49
49
  return (0, _react.jsx)("div", {
50
+ "data-testid": "alignment-buttons",
50
51
  css: _styles.alignmentWrapper,
51
52
  className: className
52
53
  }, alignmentOptions.map(function (alignment) {
@@ -5,4 +5,4 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.version = exports.name = void 0;
7
7
  var name = exports.name = "@atlaskit/editor-core";
8
- var version = exports.version = "190.0.0";
8
+ var version = exports.version = "190.1.0";
@@ -75,13 +75,6 @@ export class AlignmentToolbar extends React.Component {
75
75
  boundariesElement: popupsBoundariesElement,
76
76
  scrollableElement: popupsScrollableElement,
77
77
  isOpen: isOpen,
78
- onOpenChange: ({
79
- isOpen
80
- }) => {
81
- this.setState({
82
- isOpen
83
- });
84
- },
85
78
  handleClickOutside: event => {
86
79
  if (event instanceof MouseEvent) {
87
80
  this.hide({
@@ -3,6 +3,7 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
4
  import { AnnotationTypes } from '@atlaskit/adf-schema';
5
5
  import { AnnotationNodeView, getAnnotationViewClassname } from '../nodeviews';
6
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
7
  import { updateInlineCommentResolvedState, updateMouseState, clearDirtyMark, setInlineCommentsVisibility, setSelectedAnnotation, closeComponent } from '../commands';
7
8
  import { getAllAnnotations, inlineCommentPluginKey, getPluginState } from '../utils';
8
9
  import { createPluginState } from './plugin-factory';
@@ -36,6 +37,7 @@ const initialState = (disallowOnWhitespace = false) => {
36
37
  isSelecting: false
37
38
  },
38
39
  disallowOnWhitespace,
40
+ isInlineCommentViewClosed: false,
39
41
  isVisible: true,
40
42
  skipSelectionHandling: false
41
43
  };
@@ -151,13 +153,14 @@ export const inlineCommentPlugin = options => {
151
153
  draftDecorationSet,
152
154
  annotations,
153
155
  selectedAnnotations,
154
- isVisible
156
+ isVisible,
157
+ isInlineCommentViewClosed
155
158
  } = getPluginState(state) || {};
156
159
  let decorations = draftDecorationSet !== null && draftDecorationSet !== void 0 ? draftDecorationSet : DecorationSet.empty;
157
160
  const focusDecorations = [];
158
161
  state.doc.descendants((node, pos) => {
159
162
  node.marks.filter(mark => mark.type === state.schema.marks.annotation).forEach(mark => {
160
- const isSelected = !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(selectedAnnotation => selectedAnnotation.id === mark.attrs.id));
163
+ const isSelected = getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(selectedAnnotation => selectedAnnotation.id === mark.attrs.id)) : !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(selectedAnnotation => selectedAnnotation.id === mark.attrs.id));
161
164
  const isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
162
165
  if (isVisible) {
163
166
  focusDecorations.push(Decoration.inline(pos, pos + node.nodeSize, {
@@ -1,9 +1,10 @@
1
1
  import { pluginFactory } from '../../../utils/plugin-state-factory';
2
- import { findAnnotationsInSelection, inlineCommentPluginKey } from '../utils';
2
+ import { findAnnotationsInSelection, inlineCommentPluginKey, isSelectedAnnotationsChanged } from '../utils';
3
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
3
4
  import reducer from './reducer';
4
5
  const handleDocChanged = (tr, prevPluginState) => {
5
6
  if (!tr.getMeta('replaceDocument')) {
6
- return handleSelectionChanged(tr, prevPluginState);
7
+ return getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? getSelectionChangedHandler(false)(tr, prevPluginState) : handleSelectionChanged(tr, prevPluginState);
7
8
  }
8
9
  return {
9
10
  ...prevPluginState,
@@ -29,11 +30,57 @@ const handleSelectionChanged = (tr, pluginState) => {
29
30
  }
30
31
  return pluginState;
31
32
  };
33
+ const getSelectionChangedHandler = reopenCommentView => (tr, pluginState) => {
34
+ /**
35
+ * If feature flag is **OFF** we want to keep the old behavior. Note that
36
+ * reopenCommentView is not relevant here when using old behaviour.
37
+ *
38
+ * Feature flag is evaluated here rather than directly in onSelectionChanged where it is assigned
39
+ * to prevent the plugin from setting up the handler before the feature flag is evaluated.
40
+ *
41
+ * This comment / logic can be cleaned up once the feature flag is removed.
42
+ */
43
+ if (!getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox')) {
44
+ return handleSelectionChanged(tr, pluginState);
45
+ }
46
+ if (pluginState.skipSelectionHandling) {
47
+ return {
48
+ ...pluginState,
49
+ skipSelectionHandling: false,
50
+ ...(reopenCommentView && {
51
+ isInlineCommentViewClosed: false
52
+ })
53
+ };
54
+ }
55
+ const selectedAnnotations = findAnnotationsInSelection(tr.selection, tr.doc);
56
+ if (selectedAnnotations.length === 0) {
57
+ return {
58
+ ...pluginState,
59
+ selectedAnnotations,
60
+ isInlineCommentViewClosed: true
61
+ };
62
+ }
63
+ if (isSelectedAnnotationsChanged(selectedAnnotations, pluginState.selectedAnnotations)) {
64
+ return {
65
+ ...pluginState,
66
+ selectedAnnotations,
67
+ ...(reopenCommentView && {
68
+ isInlineCommentViewClosed: false
69
+ })
70
+ };
71
+ }
72
+ return {
73
+ ...pluginState,
74
+ ...(reopenCommentView && {
75
+ isInlineCommentViewClosed: false
76
+ })
77
+ };
78
+ };
32
79
  export const {
33
80
  createPluginState,
34
81
  createCommand
35
82
  } = pluginFactory(inlineCommentPluginKey, reducer, {
36
- onSelectionChanged: handleSelectionChanged,
83
+ onSelectionChanged: getSelectionChangedHandler(true),
37
84
  onDocChanged: handleDocChanged,
38
85
  mapping: (tr, pluginState) => {
39
86
  let {
@@ -1,6 +1,7 @@
1
- import { ACTIONS } from './types';
2
1
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
3
3
  import { addDraftDecoration } from '../utils';
4
+ import { ACTIONS } from './types';
4
5
  export default ((pluginState, action) => {
5
6
  switch (action.type) {
6
7
  case ACTIONS.UPDATE_INLINE_COMMENT_STATE:
@@ -26,7 +27,10 @@ export default ((pluginState, action) => {
26
27
  annotations: {}
27
28
  };
28
29
  case ACTIONS.CLOSE_COMPONENT:
29
- return {
30
+ return getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? {
31
+ ...pluginState,
32
+ isInlineCommentViewClosed: true
33
+ } : {
30
34
  ...pluginState,
31
35
  selectedAnnotations: []
32
36
  };
@@ -38,7 +42,10 @@ export default ((pluginState, action) => {
38
42
  annotations: {
39
43
  ...pluginState.annotations,
40
44
  ...action.data.inlineComments
41
- }
45
+ },
46
+ ...(getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') && {
47
+ isInlineCommentViewClosed: false
48
+ })
42
49
  };
43
50
  case ACTIONS.INLINE_COMMENT_SET_VISIBLE:
44
51
  const {
@@ -55,7 +62,11 @@ export default ((pluginState, action) => {
55
62
  return {
56
63
  ...pluginState,
57
64
  selectedAnnotations: [...action.data.selectedAnnotations],
58
- skipSelectionHandling: true
65
+ skipSelectionHandling: true,
66
+ ...(getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') && {
67
+ // if selecting annotation explicitly, reopen the comment view
68
+ isInlineCommentViewClosed: false
69
+ })
59
70
  };
60
71
  default:
61
72
  return pluginState;
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
3
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
3
4
  import { AnnotationViewWrapper } from './AnnotationViewWrapper';
4
5
  import { AnnotationTestIds } from '../types';
5
6
  import { getAnnotationViewKey, getSelectionPositions, getPluginState, getAllAnnotations } from '../utils';
@@ -45,7 +46,8 @@ export function InlineCommentView({
45
46
  const {
46
47
  bookmark,
47
48
  selectedAnnotations,
48
- annotations
49
+ annotations,
50
+ isInlineCommentViewClosed
49
51
  } = inlineCommentState || {};
50
52
  const annotationsList = getAllAnnotations(editorView.state.doc);
51
53
  const selection = getSelectionPositions(state, inlineCommentState);
@@ -122,7 +124,7 @@ export function InlineCommentView({
122
124
  };
123
125
  dispatchAnalyticsEvent(payload);
124
126
  };
125
- if (!selectedAnnotations) {
127
+ if (getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') && isInlineCommentViewClosed || !selectedAnnotations) {
126
128
  return null;
127
129
  }
128
130
  return /*#__PURE__*/React.createElement(AnnotationViewWrapper, {
@@ -321,4 +321,14 @@ function stripNonExistingAnnotationsFromNode(node, state) {
321
321
  });
322
322
  }
323
323
  return node;
324
+ }
325
+
326
+ /**
327
+ * Compares two sets of annotationInfos to see if the annotations have changed
328
+ * This function assumes annotations will have unique id's for simplicity
329
+ */
330
+ export function isSelectedAnnotationsChanged(oldSelectedAnnotations, newSelectedAnnotations) {
331
+ return newSelectedAnnotations.length !== oldSelectedAnnotations.length ||
332
+ // assuming annotations have unique id's for simplicity
333
+ newSelectedAnnotations.some(annotation => !oldSelectedAnnotations.find(pluginStateAnnotation => annotation.id === pluginStateAnnotation.id && annotation.type === pluginStateAnnotation.type));
324
334
  }
@@ -27,6 +27,7 @@ class Alignment extends PureComponent {
27
27
  intl
28
28
  } = this.props;
29
29
  return jsx("div", {
30
+ "data-testid": "alignment-buttons",
30
31
  css: alignmentWrapper,
31
32
  className: className
32
33
  }, alignmentOptions.map(alignment => {
@@ -1,2 +1,2 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "190.0.0";
2
+ export const version = "190.1.0";
@@ -91,12 +91,6 @@ export var AlignmentToolbar = /*#__PURE__*/function (_React$Component) {
91
91
  boundariesElement: popupsBoundariesElement,
92
92
  scrollableElement: popupsScrollableElement,
93
93
  isOpen: isOpen,
94
- onOpenChange: function onOpenChange(_ref) {
95
- var isOpen = _ref.isOpen;
96
- _this2.setState({
97
- isOpen: isOpen
98
- });
99
- },
100
94
  handleClickOutside: function handleClickOutside(event) {
101
95
  if (event instanceof MouseEvent) {
102
96
  _this2.hide({
@@ -6,6 +6,7 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
6
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
7
  import { AnnotationTypes } from '@atlaskit/adf-schema';
8
8
  import { AnnotationNodeView, getAnnotationViewClassname } from '../nodeviews';
9
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
10
  import { updateInlineCommentResolvedState, updateMouseState, clearDirtyMark, setInlineCommentsVisibility, setSelectedAnnotation, closeComponent } from '../commands';
10
11
  import { getAllAnnotations, inlineCommentPluginKey, getPluginState } from '../utils';
11
12
  import { createPluginState } from './plugin-factory';
@@ -77,6 +78,7 @@ var initialState = function initialState() {
77
78
  isSelecting: false
78
79
  },
79
80
  disallowOnWhitespace: disallowOnWhitespace,
81
+ isInlineCommentViewClosed: false,
80
82
  isVisible: true,
81
83
  skipSelectionHandling: false
82
84
  };
@@ -204,14 +206,17 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
204
206
  draftDecorationSet = _ref5.draftDecorationSet,
205
207
  annotations = _ref5.annotations,
206
208
  selectedAnnotations = _ref5.selectedAnnotations,
207
- isVisible = _ref5.isVisible;
209
+ isVisible = _ref5.isVisible,
210
+ isInlineCommentViewClosed = _ref5.isInlineCommentViewClosed;
208
211
  var decorations = draftDecorationSet !== null && draftDecorationSet !== void 0 ? draftDecorationSet : DecorationSet.empty;
209
212
  var focusDecorations = [];
210
213
  state.doc.descendants(function (node, pos) {
211
214
  node.marks.filter(function (mark) {
212
215
  return mark.type === state.schema.marks.annotation;
213
216
  }).forEach(function (mark) {
214
- var isSelected = !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
217
+ var isSelected = getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
218
+ return selectedAnnotation.id === mark.attrs.id;
219
+ })) : !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
215
220
  return selectedAnnotation.id === mark.attrs.id;
216
221
  }));
217
222
  var isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
@@ -2,11 +2,12 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  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; }
3
3
  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; }
4
4
  import { pluginFactory } from '../../../utils/plugin-state-factory';
5
- import { findAnnotationsInSelection, inlineCommentPluginKey } from '../utils';
5
+ import { findAnnotationsInSelection, inlineCommentPluginKey, isSelectedAnnotationsChanged } from '../utils';
6
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
7
  import reducer from './reducer';
7
8
  var handleDocChanged = function handleDocChanged(tr, prevPluginState) {
8
9
  if (!tr.getMeta('replaceDocument')) {
9
- return handleSelectionChanged(tr, prevPluginState);
10
+ return getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? getSelectionChangedHandler(false)(tr, prevPluginState) : handleSelectionChanged(tr, prevPluginState);
10
11
  }
11
12
  return _objectSpread(_objectSpread({}, prevPluginState), {}, {
12
13
  dirtyAnnotations: true
@@ -31,8 +32,48 @@ var handleSelectionChanged = function handleSelectionChanged(tr, pluginState) {
31
32
  }
32
33
  return pluginState;
33
34
  };
35
+ var getSelectionChangedHandler = function getSelectionChangedHandler(reopenCommentView) {
36
+ return function (tr, pluginState) {
37
+ /**
38
+ * If feature flag is **OFF** we want to keep the old behavior. Note that
39
+ * reopenCommentView is not relevant here when using old behaviour.
40
+ *
41
+ * Feature flag is evaluated here rather than directly in onSelectionChanged where it is assigned
42
+ * to prevent the plugin from setting up the handler before the feature flag is evaluated.
43
+ *
44
+ * This comment / logic can be cleaned up once the feature flag is removed.
45
+ */
46
+ if (!getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox')) {
47
+ return handleSelectionChanged(tr, pluginState);
48
+ }
49
+ if (pluginState.skipSelectionHandling) {
50
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
51
+ skipSelectionHandling: false
52
+ }, reopenCommentView && {
53
+ isInlineCommentViewClosed: false
54
+ });
55
+ }
56
+ var selectedAnnotations = findAnnotationsInSelection(tr.selection, tr.doc);
57
+ if (selectedAnnotations.length === 0) {
58
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
59
+ selectedAnnotations: selectedAnnotations,
60
+ isInlineCommentViewClosed: true
61
+ });
62
+ }
63
+ if (isSelectedAnnotationsChanged(selectedAnnotations, pluginState.selectedAnnotations)) {
64
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
65
+ selectedAnnotations: selectedAnnotations
66
+ }, reopenCommentView && {
67
+ isInlineCommentViewClosed: false
68
+ });
69
+ }
70
+ return _objectSpread(_objectSpread({}, pluginState), reopenCommentView && {
71
+ isInlineCommentViewClosed: false
72
+ });
73
+ };
74
+ };
34
75
  var _pluginFactory = pluginFactory(inlineCommentPluginKey, reducer, {
35
- onSelectionChanged: handleSelectionChanged,
76
+ onSelectionChanged: getSelectionChangedHandler(true),
36
77
  onDocChanged: handleDocChanged,
37
78
  mapping: function mapping(tr, pluginState) {
38
79
  var draftDecorationSet = pluginState.draftDecorationSet,
@@ -2,9 +2,10 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  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
- import { ACTIONS } from './types';
6
5
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
7
  import { addDraftDecoration } from '../utils';
8
+ import { ACTIONS } from './types';
8
9
  export default (function (pluginState, action) {
9
10
  switch (action.type) {
10
11
  case ACTIONS.UPDATE_INLINE_COMMENT_STATE:
@@ -24,7 +25,9 @@ export default (function (pluginState, action) {
24
25
  annotations: {}
25
26
  });
26
27
  case ACTIONS.CLOSE_COMPONENT:
27
- return _objectSpread(_objectSpread({}, pluginState), {}, {
28
+ return getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? _objectSpread(_objectSpread({}, pluginState), {}, {
29
+ isInlineCommentViewClosed: true
30
+ }) : _objectSpread(_objectSpread({}, pluginState), {}, {
28
31
  selectedAnnotations: []
29
32
  });
30
33
  case ACTIONS.ADD_INLINE_COMMENT:
@@ -32,6 +35,8 @@ export default (function (pluginState, action) {
32
35
  return _objectSpread(_objectSpread({}, updatedPluginState), {}, {
33
36
  selectedAnnotations: [].concat(_toConsumableArray(updatedPluginState.selectedAnnotations), _toConsumableArray(action.data.selectedAnnotations)),
34
37
  annotations: _objectSpread(_objectSpread({}, pluginState.annotations), action.data.inlineComments)
38
+ }, getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') && {
39
+ isInlineCommentViewClosed: false
35
40
  });
36
41
  case ACTIONS.INLINE_COMMENT_SET_VISIBLE:
37
42
  var isVisible = action.data.isVisible;
@@ -45,6 +50,9 @@ export default (function (pluginState, action) {
45
50
  return _objectSpread(_objectSpread({}, pluginState), {}, {
46
51
  selectedAnnotations: _toConsumableArray(action.data.selectedAnnotations),
47
52
  skipSelectionHandling: true
53
+ }, getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') && {
54
+ // if selecting annotation explicitly, reopen the comment view
55
+ isInlineCommentViewClosed: false
48
56
  });
49
57
  default:
50
58
  return pluginState;
@@ -1,6 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import React from 'react';
3
3
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
4
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
4
5
  import { AnnotationViewWrapper } from './AnnotationViewWrapper';
5
6
  import { AnnotationTestIds } from '../types';
6
7
  import { getAnnotationViewKey, getSelectionPositions, getPluginState, getAllAnnotations } from '../utils';
@@ -39,7 +40,8 @@ export function InlineCommentView(_ref) {
39
40
  var _ref2 = inlineCommentState || {},
40
41
  bookmark = _ref2.bookmark,
41
42
  selectedAnnotations = _ref2.selectedAnnotations,
42
- annotations = _ref2.annotations;
43
+ annotations = _ref2.annotations,
44
+ isInlineCommentViewClosed = _ref2.isInlineCommentViewClosed;
43
45
  var annotationsList = getAllAnnotations(editorView.state.doc);
44
46
  var selection = getSelectionPositions(state, inlineCommentState);
45
47
  var position = findPosForDOM(selection);
@@ -117,7 +119,7 @@ export function InlineCommentView(_ref) {
117
119
  };
118
120
  dispatchAnalyticsEvent(payload);
119
121
  };
120
- if (!selectedAnnotations) {
122
+ if (getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') && isInlineCommentViewClosed || !selectedAnnotations) {
121
123
  return null;
122
124
  }
123
125
  return /*#__PURE__*/React.createElement(AnnotationViewWrapper, {
@@ -328,4 +328,18 @@ function stripNonExistingAnnotationsFromNode(node, state) {
328
328
  });
329
329
  }
330
330
  return node;
331
+ }
332
+
333
+ /**
334
+ * Compares two sets of annotationInfos to see if the annotations have changed
335
+ * This function assumes annotations will have unique id's for simplicity
336
+ */
337
+ export function isSelectedAnnotationsChanged(oldSelectedAnnotations, newSelectedAnnotations) {
338
+ return newSelectedAnnotations.length !== oldSelectedAnnotations.length ||
339
+ // assuming annotations have unique id's for simplicity
340
+ newSelectedAnnotations.some(function (annotation) {
341
+ return !oldSelectedAnnotations.find(function (pluginStateAnnotation) {
342
+ return annotation.id === pluginStateAnnotation.id && annotation.type === pluginStateAnnotation.type;
343
+ });
344
+ });
331
345
  }
@@ -41,6 +41,7 @@ var Alignment = /*#__PURE__*/function (_PureComponent) {
41
41
  className = _this$props.className,
42
42
  intl = _this$props.intl;
43
43
  return jsx("div", {
44
+ "data-testid": "alignment-buttons",
44
45
  css: alignmentWrapper,
45
46
  className: className
46
47
  }, alignmentOptions.map(function (alignment) {
@@ -1,2 +1,2 @@
1
1
  export var name = "@atlaskit/editor-core";
2
- export var version = "190.0.0";
2
+ export var version = "190.1.0";
@@ -72,6 +72,7 @@ export type InlineCommentPluginState = {
72
72
  draftDecorationSet?: DecorationSet;
73
73
  bookmark?: SelectionBookmark;
74
74
  disallowOnWhitespace: boolean;
75
+ isInlineCommentViewClosed: boolean;
75
76
  isVisible: boolean;
76
77
  skipSelectionHandling: boolean;
77
78
  };
@@ -38,3 +38,8 @@ export declare const hasInvalidNodes: (state: EditorState) => boolean;
38
38
  export declare function hasInvalidWhitespaceNode(selection: TextSelection | AllSelection, schema: Schema): boolean;
39
39
  export declare function annotationExists(annotationId: string, state: EditorState): boolean;
40
40
  export declare function stripNonExistingAnnotations(slice: Slice, state: EditorState): false | undefined;
41
+ /**
42
+ * Compares two sets of annotationInfos to see if the annotations have changed
43
+ * This function assumes annotations will have unique id's for simplicity
44
+ */
45
+ export declare function isSelectedAnnotationsChanged(oldSelectedAnnotations: AnnotationInfo[], newSelectedAnnotations: AnnotationInfo[]): boolean;
@@ -72,6 +72,7 @@ export type InlineCommentPluginState = {
72
72
  draftDecorationSet?: DecorationSet;
73
73
  bookmark?: SelectionBookmark;
74
74
  disallowOnWhitespace: boolean;
75
+ isInlineCommentViewClosed: boolean;
75
76
  isVisible: boolean;
76
77
  skipSelectionHandling: boolean;
77
78
  };
@@ -38,3 +38,8 @@ export declare const hasInvalidNodes: (state: EditorState) => boolean;
38
38
  export declare function hasInvalidWhitespaceNode(selection: TextSelection | AllSelection, schema: Schema): boolean;
39
39
  export declare function annotationExists(annotationId: string, state: EditorState): boolean;
40
40
  export declare function stripNonExistingAnnotations(slice: Slice, state: EditorState): false | undefined;
41
+ /**
42
+ * Compares two sets of annotationInfos to see if the annotations have changed
43
+ * This function assumes annotations will have unique id's for simplicity
44
+ */
45
+ export declare function isSelectedAnnotationsChanged(oldSelectedAnnotations: AnnotationInfo[], newSelectedAnnotations: AnnotationInfo[]): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "190.0.0",
3
+ "version": "190.1.0",
4
4
  "description": "A package contains Atlassian editor core functionality",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -362,6 +362,9 @@
362
362
  "platform.editor.allow-list-in-blockquote": {
363
363
  "type": "boolean",
364
364
  "referenceOnly": "true"
365
+ },
366
+ "platform.editor.annotation.decouple-inline-comment-closed_flmox": {
367
+ "type": "boolean"
365
368
  }
366
369
  }
367
370
  }