@atlaskit/editor-plugin-annotation 2.7.5 → 2.8.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,27 @@
1
1
  # @atlaskit/editor-plugin-annotation
2
2
 
3
+ ## 2.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#153391](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/153391)
8
+ [`1e42cbe3dd636`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1e42cbe3dd636) -
9
+ [ux] [ED-27484] Track network state from connectivity plugin and provide this to view/create
10
+ components
11
+
12
+ ## 2.7.6
13
+
14
+ ### Patch Changes
15
+
16
+ - [#142925](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/142925)
17
+ [`e013698350bef`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e013698350bef) -
18
+ This updates the renderer to use the new annotation manager create comment APIs and disables the
19
+ use of the old create hooks. This should be backward compatible and can be controled by a FG
20
+ - [#151999](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/151999)
21
+ [`daf7c638efb95`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/daf7c638efb95) -
22
+ Refactor to use sharedPluginStateHookMigratorFactory
23
+ - Updated dependencies
24
+
3
25
  ## 2.7.5
4
26
 
5
27
  ### Patch Changes
@@ -136,20 +136,29 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
136
136
  }
137
137
  };
138
138
  };
139
+ var useAnnotationContentComponentPluginState = (0, _hooks.sharedPluginStateHookMigratorFactory)(function (api) {
140
+ var isVisible = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'annotation.isVisible');
141
+ return {
142
+ isVisible: isVisible,
143
+ annotationState: undefined
144
+ };
145
+ }, function (api) {
146
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['annotation']),
147
+ annotationState = _useSharedPluginState.annotationState;
148
+ return {
149
+ isVisible: annotationState === null || annotationState === void 0 ? void 0 : annotationState.isVisible,
150
+ annotationState: annotationState
151
+ };
152
+ });
139
153
  function AnnotationContentComponent(_ref4) {
140
154
  var _api$analytics5;
141
155
  var api = _ref4.api,
142
156
  editorView = _ref4.editorView,
143
157
  annotationProviders = _ref4.annotationProviders,
144
158
  dispatchAnalyticsEvent = _ref4.dispatchAnalyticsEvent;
145
- var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['annotation'], {
146
- disabled: (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', true)
147
- }),
148
- annotationState = _useSharedPluginState.annotationState;
149
- var isVisibleSelector = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'annotation.isVisible', {
150
- disabled: (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', false)
151
- });
152
- var isVisible = (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', true) ? isVisibleSelector : annotationState === null || annotationState === void 0 ? void 0 : annotationState.isVisible;
159
+ var _useAnnotationContent = useAnnotationContentComponentPluginState(api),
160
+ isVisible = _useAnnotationContent.isVisible,
161
+ annotationState = _useAnnotationContent.annotationState;
153
162
  if (annotationState && !isVisible && (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', false)) {
154
163
  return null;
155
164
  }
@@ -147,7 +147,9 @@ var applyDraft = exports.applyDraft = function applyDraft(editorView, options) {
147
147
  return {
148
148
  success: true,
149
149
  // Get the dom element from the newly created annotation and return it here.
150
- targetElement: targetElement
150
+ targetElement: targetElement,
151
+ // In Editor this is undefined, because the editor will update the document.
152
+ actionResult: undefined
151
153
  };
152
154
  };
153
155
  };
@@ -9,6 +9,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
9
9
  var _react = _interopRequireDefault(require("react"));
10
10
  var _adfSchema = require("@atlaskit/adf-schema");
11
11
  var _analytics = require("@atlaskit/editor-common/analytics");
12
+ var _hooks = require("@atlaskit/editor-common/hooks");
12
13
  var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
13
14
  var _utils = require("@atlaskit/editor-common/utils");
14
15
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
@@ -34,53 +35,66 @@ var findPosForDOM = function findPosForDOM(sel) {
34
35
  }
35
36
  return from;
36
37
  };
37
- function InlineCommentView(_ref) {
38
- var providers = _ref.providers,
39
- editorView = _ref.editorView,
40
- editorAnalyticsAPI = _ref.editorAnalyticsAPI,
41
- editorAPI = _ref.editorAPI,
42
- dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent;
38
+ var useInlineCommentViewPluginState = (0, _hooks.sharedPluginStateHookMigratorFactory)(function (_ref) {
39
+ var api = _ref.api;
40
+ // eslint-disable-next-line react-hooks/rules-of-hooks
41
+ var bookmark = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'annotation.bookmark');
42
+ // eslint-disable-next-line react-hooks/rules-of-hooks
43
+ var selectedAnnotations = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'annotation.selectedAnnotations');
44
+ // eslint-disable-next-line react-hooks/rules-of-hooks
45
+ var annotations = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'annotation.annotations');
46
+ // eslint-disable-next-line react-hooks/rules-of-hooks
47
+ var isInlineCommentViewClosed = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'annotation.isInlineCommentViewClosed');
48
+ // eslint-disable-next-line react-hooks/rules-of-hooks
49
+ var isOpeningMediaCommentFromToolbar = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'annotation.isOpeningMediaCommentFromToolbar');
50
+ // eslint-disable-next-line react-hooks/rules-of-hooks
51
+ var selectAnnotationMethod = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'annotation.selectAnnotationMethod');
52
+ return {
53
+ bookmark: bookmark,
54
+ selectedAnnotations: selectedAnnotations,
55
+ annotations: annotations,
56
+ isInlineCommentViewClosed: isInlineCommentViewClosed,
57
+ isOpeningMediaCommentFromToolbar: isOpeningMediaCommentFromToolbar,
58
+ selectAnnotationMethod: selectAnnotationMethod
59
+ };
60
+ }, function (_ref2) {
61
+ var state = _ref2.state;
62
+ var inlineCommentState = (0, _utils3.getPluginState)(state);
63
+ return {
64
+ bookmark: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.bookmark,
65
+ selectedAnnotations: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.selectedAnnotations,
66
+ annotations: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.annotations,
67
+ isInlineCommentViewClosed: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.isInlineCommentViewClosed,
68
+ isOpeningMediaCommentFromToolbar: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.isOpeningMediaCommentFromToolbar,
69
+ selectAnnotationMethod: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.selectAnnotationMethod
70
+ };
71
+ });
72
+ function InlineCommentView(_ref3) {
73
+ var providers = _ref3.providers,
74
+ editorView = _ref3.editorView,
75
+ editorAnalyticsAPI = _ref3.editorAnalyticsAPI,
76
+ editorAPI = _ref3.editorAPI,
77
+ dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent;
43
78
  // As inlineComment is the only annotation present, this function is not generic
44
79
  var inlineCommentProvider = providers.inlineComment;
45
80
  var state = editorView.state,
46
81
  dispatch = editorView.dispatch;
47
82
  var CreateComponent = inlineCommentProvider.createComponent,
48
83
  ViewComponent = inlineCommentProvider.viewComponent;
49
- var inlineCommentState = (0, _utils3.getPluginState)(state);
50
-
51
- // bookmark
52
- var bookmarkSelector = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(editorAPI, 'annotation.bookmark', {
53
- disabled: (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', false)
54
- });
55
- var bookmark = (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', true) ? bookmarkSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.bookmark;
56
-
57
- // selectedAnnotations
58
- var selectedAnnotationsSelector = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(editorAPI, 'annotation.selectedAnnotations', {
59
- disabled: (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', false)
60
- });
61
- var selectedAnnotations = (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', true) ? selectedAnnotationsSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.selectedAnnotations;
62
-
63
- // annotations
64
- var annotationsSelector = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(editorAPI, 'annotation.annotations', {
65
- disabled: (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', false)
66
- });
67
- var annotations = (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', true) ? annotationsSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.annotations;
68
-
69
- // isInlineCommentViewClosed
70
- var isInlineCommentViewClosedSelector = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(editorAPI, 'annotation.isInlineCommentViewClosed', {
71
- disabled: (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', false)
72
- });
73
- var isInlineCommentViewClosed = (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', true) ? isInlineCommentViewClosedSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.isInlineCommentViewClosed;
74
-
75
- // isOpeningMediaCommentFromToolbar
76
- var isOpeningMediaCommentFromToolbarSelector = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(editorAPI, 'annotation.isOpeningMediaCommentFromToolbar', {
77
- disabled: (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', false)
78
- });
79
- var isOpeningMediaCommentFromToolbar = (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', true) ? isOpeningMediaCommentFromToolbarSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.isOpeningMediaCommentFromToolbar;
84
+ var _useInlineCommentView = useInlineCommentViewPluginState({
85
+ api: editorAPI,
86
+ state: state
87
+ }),
88
+ annotations = _useInlineCommentView.annotations,
89
+ bookmark = _useInlineCommentView.bookmark,
90
+ isInlineCommentViewClosed = _useInlineCommentView.isInlineCommentViewClosed,
91
+ isOpeningMediaCommentFromToolbar = _useInlineCommentView.isOpeningMediaCommentFromToolbar,
92
+ selectAnnotationMethod = _useInlineCommentView.selectAnnotationMethod,
93
+ selectedAnnotations = _useInlineCommentView.selectedAnnotations;
80
94
  var annotationsList = (0, _utils3.getAllAnnotations)(editorView.state.doc);
81
- var selection = (0, _utils3.getSelectionPositions)(state, (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', true) ? {
95
+ var selection = (0, _utils3.getSelectionPositions)(state, {
82
96
  bookmark: bookmark
83
- } : inlineCommentState);
97
+ });
84
98
  var position = findPosForDOM(selection);
85
99
  var dom;
86
100
  try {
@@ -107,9 +121,9 @@ function InlineCommentView(_ref) {
107
121
  }
108
122
  }
109
123
 
110
- // selectAnnotationMethod
111
- var selectAnnotationMethodSelector = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(editorAPI, 'annotation.selectAnnotationMethod', {
112
- disabled: (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', false)
124
+ // Network Status
125
+ var networkStatusSelector = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(editorAPI, 'connectivity.mode', {
126
+ disabled: (0, _experiments.editorExperiment)('platform_editor_offline_editing_web', false)
113
127
  });
114
128
  if (!dom) {
115
129
  return null;
@@ -149,7 +163,8 @@ function InlineCommentView(_ref) {
149
163
  }
150
164
  },
151
165
  inlineNodeTypes: inlineNodeTypes,
152
- isOpeningMediaCommentFromToolbar: isOpeningMediaCommentFromToolbar
166
+ isOpeningMediaCommentFromToolbar: isOpeningMediaCommentFromToolbar,
167
+ isOffline: networkStatusSelector === 'offline'
153
168
  }));
154
169
  }
155
170
 
@@ -175,7 +190,7 @@ function InlineCommentView(_ref) {
175
190
  attributes: {
176
191
  overlap: activeAnnotations.length ? activeAnnotations.length - 1 : 0,
177
192
  targetNodeType: (_editorView$state$doc = editorView.state.doc.nodeAt(position)) === null || _editorView$state$doc === void 0 ? void 0 : _editorView$state$doc.type.name,
178
- method: (0, _experiments.editorExperiment)('platform_editor_tables_table_selector', true) ? selectAnnotationMethodSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.selectAnnotationMethod
193
+ method: selectAnnotationMethod
179
194
  }
180
195
  };
181
196
  dispatchAnalyticsEvent(payload);
@@ -209,6 +224,7 @@ function InlineCommentView(_ref) {
209
224
  onClose: function onClose() {
210
225
  (0, _editorCommands.closeComponent)()(editorView.state, editorView.dispatch);
211
226
  },
212
- isOpeningMediaCommentFromToolbar: isOpeningMediaCommentFromToolbar
227
+ isOpeningMediaCommentFromToolbar: isOpeningMediaCommentFromToolbar,
228
+ isOffline: networkStatusSelector === 'offline'
213
229
  }));
214
230
  }
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
2
+ import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
3
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
4
4
  import { fg } from '@atlaskit/platform-feature-flags';
5
5
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
@@ -129,6 +129,21 @@ export const annotationPlugin = ({
129
129
  }
130
130
  };
131
131
  };
132
+ const useAnnotationContentComponentPluginState = sharedPluginStateHookMigratorFactory(api => {
133
+ const isVisible = useSharedPluginStateSelector(api, 'annotation.isVisible');
134
+ return {
135
+ isVisible,
136
+ annotationState: undefined
137
+ };
138
+ }, api => {
139
+ const {
140
+ annotationState
141
+ } = useSharedPluginState(api, ['annotation']);
142
+ return {
143
+ isVisible: annotationState === null || annotationState === void 0 ? void 0 : annotationState.isVisible,
144
+ annotationState
145
+ };
146
+ });
132
147
  function AnnotationContentComponent({
133
148
  api,
134
149
  editorView,
@@ -137,14 +152,9 @@ function AnnotationContentComponent({
137
152
  }) {
138
153
  var _api$analytics5;
139
154
  const {
155
+ isVisible,
140
156
  annotationState
141
- } = useSharedPluginState(api, ['annotation'], {
142
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true)
143
- });
144
- const isVisibleSelector = useSharedPluginStateSelector(api, 'annotation.isVisible', {
145
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
146
- });
147
- const isVisible = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? isVisibleSelector : annotationState === null || annotationState === void 0 ? void 0 : annotationState.isVisible;
157
+ } = useAnnotationContentComponentPluginState(api);
148
158
  if (annotationState && !isVisible && editorExperiment('platform_editor_usesharedpluginstateselector', false)) {
149
159
  return null;
150
160
  }
@@ -139,7 +139,9 @@ export const applyDraft = (editorView, options) => id => {
139
139
  return {
140
140
  success: true,
141
141
  // Get the dom element from the newly created annotation and return it here.
142
- targetElement
142
+ targetElement,
143
+ // In Editor this is undefined, because the editor will update the document.
144
+ actionResult: undefined
143
145
  };
144
146
  };
145
147
  export const getDraft = (editorView, options) => () => {
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { AnnotationTypes } from '@atlaskit/adf-schema';
3
3
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, CONTENT_COMPONENT, EVENT_TYPE, RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { sharedPluginStateHookMigratorFactory } from '@atlaskit/editor-common/hooks';
4
5
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
5
6
  import { getAnnotationInlineNodeTypes, getRangeInlineNodeNames } from '@atlaskit/editor-common/utils';
6
7
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
@@ -26,6 +27,42 @@ const findPosForDOM = sel => {
26
27
  }
27
28
  return from;
28
29
  };
30
+ const useInlineCommentViewPluginState = sharedPluginStateHookMigratorFactory(({
31
+ api
32
+ }) => {
33
+ // eslint-disable-next-line react-hooks/rules-of-hooks
34
+ const bookmark = useSharedPluginStateSelector(api, 'annotation.bookmark');
35
+ // eslint-disable-next-line react-hooks/rules-of-hooks
36
+ const selectedAnnotations = useSharedPluginStateSelector(api, 'annotation.selectedAnnotations');
37
+ // eslint-disable-next-line react-hooks/rules-of-hooks
38
+ const annotations = useSharedPluginStateSelector(api, 'annotation.annotations');
39
+ // eslint-disable-next-line react-hooks/rules-of-hooks
40
+ const isInlineCommentViewClosed = useSharedPluginStateSelector(api, 'annotation.isInlineCommentViewClosed');
41
+ // eslint-disable-next-line react-hooks/rules-of-hooks
42
+ const isOpeningMediaCommentFromToolbar = useSharedPluginStateSelector(api, 'annotation.isOpeningMediaCommentFromToolbar');
43
+ // eslint-disable-next-line react-hooks/rules-of-hooks
44
+ const selectAnnotationMethod = useSharedPluginStateSelector(api, 'annotation.selectAnnotationMethod');
45
+ return {
46
+ bookmark,
47
+ selectedAnnotations,
48
+ annotations,
49
+ isInlineCommentViewClosed,
50
+ isOpeningMediaCommentFromToolbar,
51
+ selectAnnotationMethod
52
+ };
53
+ }, ({
54
+ state
55
+ }) => {
56
+ const inlineCommentState = getPluginState(state);
57
+ return {
58
+ bookmark: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.bookmark,
59
+ selectedAnnotations: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.selectedAnnotations,
60
+ annotations: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.annotations,
61
+ isInlineCommentViewClosed: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.isInlineCommentViewClosed,
62
+ isOpeningMediaCommentFromToolbar: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.isOpeningMediaCommentFromToolbar,
63
+ selectAnnotationMethod: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.selectAnnotationMethod
64
+ };
65
+ });
29
66
  export function InlineCommentView({
30
67
  providers,
31
68
  editorView,
@@ -45,41 +82,21 @@ export function InlineCommentView({
45
82
  createComponent: CreateComponent,
46
83
  viewComponent: ViewComponent
47
84
  } = inlineCommentProvider;
48
- const inlineCommentState = getPluginState(state);
49
-
50
- // bookmark
51
- const bookmarkSelector = useSharedPluginStateSelector(editorAPI, 'annotation.bookmark', {
52
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
53
- });
54
- const bookmark = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? bookmarkSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.bookmark;
55
-
56
- // selectedAnnotations
57
- const selectedAnnotationsSelector = useSharedPluginStateSelector(editorAPI, 'annotation.selectedAnnotations', {
58
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
59
- });
60
- const selectedAnnotations = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? selectedAnnotationsSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.selectedAnnotations;
61
-
62
- // annotations
63
- const annotationsSelector = useSharedPluginStateSelector(editorAPI, 'annotation.annotations', {
64
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
65
- });
66
- const annotations = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? annotationsSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.annotations;
67
-
68
- // isInlineCommentViewClosed
69
- const isInlineCommentViewClosedSelector = useSharedPluginStateSelector(editorAPI, 'annotation.isInlineCommentViewClosed', {
70
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
71
- });
72
- const isInlineCommentViewClosed = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? isInlineCommentViewClosedSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.isInlineCommentViewClosed;
73
-
74
- // isOpeningMediaCommentFromToolbar
75
- const isOpeningMediaCommentFromToolbarSelector = useSharedPluginStateSelector(editorAPI, 'annotation.isOpeningMediaCommentFromToolbar', {
76
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
85
+ const {
86
+ annotations,
87
+ bookmark,
88
+ isInlineCommentViewClosed,
89
+ isOpeningMediaCommentFromToolbar,
90
+ selectAnnotationMethod,
91
+ selectedAnnotations
92
+ } = useInlineCommentViewPluginState({
93
+ api: editorAPI,
94
+ state
77
95
  });
78
- const isOpeningMediaCommentFromToolbar = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? isOpeningMediaCommentFromToolbarSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.isOpeningMediaCommentFromToolbar;
79
96
  const annotationsList = getAllAnnotations(editorView.state.doc);
80
- const selection = getSelectionPositions(state, editorExperiment('platform_editor_usesharedpluginstateselector', true) ? {
97
+ const selection = getSelectionPositions(state, {
81
98
  bookmark
82
- } : inlineCommentState);
99
+ });
83
100
  const position = findPosForDOM(selection);
84
101
  let dom;
85
102
  try {
@@ -106,9 +123,9 @@ export function InlineCommentView({
106
123
  }
107
124
  }
108
125
 
109
- // selectAnnotationMethod
110
- const selectAnnotationMethodSelector = useSharedPluginStateSelector(editorAPI, 'annotation.selectAnnotationMethod', {
111
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
126
+ // Network Status
127
+ const networkStatusSelector = useSharedPluginStateSelector(editorAPI, 'connectivity.mode', {
128
+ disabled: editorExperiment('platform_editor_offline_editing_web', false)
112
129
  });
113
130
  if (!dom) {
114
131
  return null;
@@ -148,7 +165,8 @@ export function InlineCommentView({
148
165
  }
149
166
  },
150
167
  inlineNodeTypes: inlineNodeTypes,
151
- isOpeningMediaCommentFromToolbar: isOpeningMediaCommentFromToolbar
168
+ isOpeningMediaCommentFromToolbar: isOpeningMediaCommentFromToolbar,
169
+ isOffline: networkStatusSelector === 'offline'
152
170
  }));
153
171
  }
154
172
 
@@ -172,7 +190,7 @@ export function InlineCommentView({
172
190
  attributes: {
173
191
  overlap: activeAnnotations.length ? activeAnnotations.length - 1 : 0,
174
192
  targetNodeType: (_editorView$state$doc = editorView.state.doc.nodeAt(position)) === null || _editorView$state$doc === void 0 ? void 0 : _editorView$state$doc.type.name,
175
- method: editorExperiment('platform_editor_tables_table_selector', true) ? selectAnnotationMethodSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.selectAnnotationMethod
193
+ method: selectAnnotationMethod
176
194
  }
177
195
  };
178
196
  dispatchAnalyticsEvent(payload);
@@ -202,6 +220,7 @@ export function InlineCommentView({
202
220
  onClose: () => {
203
221
  closeComponent()(editorView.state, editorView.dispatch);
204
222
  },
205
- isOpeningMediaCommentFromToolbar: isOpeningMediaCommentFromToolbar
223
+ isOpeningMediaCommentFromToolbar: isOpeningMediaCommentFromToolbar,
224
+ isOffline: networkStatusSelector === 'offline'
206
225
  }));
207
226
  }
@@ -2,7 +2,7 @@ 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 React from 'react';
5
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
5
+ import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
6
6
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
7
7
  import { fg } from '@atlaskit/platform-feature-flags';
8
8
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
@@ -129,20 +129,29 @@ export var annotationPlugin = function annotationPlugin(_ref) {
129
129
  }
130
130
  };
131
131
  };
132
+ var useAnnotationContentComponentPluginState = sharedPluginStateHookMigratorFactory(function (api) {
133
+ var isVisible = useSharedPluginStateSelector(api, 'annotation.isVisible');
134
+ return {
135
+ isVisible: isVisible,
136
+ annotationState: undefined
137
+ };
138
+ }, function (api) {
139
+ var _useSharedPluginState = useSharedPluginState(api, ['annotation']),
140
+ annotationState = _useSharedPluginState.annotationState;
141
+ return {
142
+ isVisible: annotationState === null || annotationState === void 0 ? void 0 : annotationState.isVisible,
143
+ annotationState: annotationState
144
+ };
145
+ });
132
146
  function AnnotationContentComponent(_ref4) {
133
147
  var _api$analytics5;
134
148
  var api = _ref4.api,
135
149
  editorView = _ref4.editorView,
136
150
  annotationProviders = _ref4.annotationProviders,
137
151
  dispatchAnalyticsEvent = _ref4.dispatchAnalyticsEvent;
138
- var _useSharedPluginState = useSharedPluginState(api, ['annotation'], {
139
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true)
140
- }),
141
- annotationState = _useSharedPluginState.annotationState;
142
- var isVisibleSelector = useSharedPluginStateSelector(api, 'annotation.isVisible', {
143
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
144
- });
145
- var isVisible = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? isVisibleSelector : annotationState === null || annotationState === void 0 ? void 0 : annotationState.isVisible;
152
+ var _useAnnotationContent = useAnnotationContentComponentPluginState(api),
153
+ isVisible = _useAnnotationContent.isVisible,
154
+ annotationState = _useAnnotationContent.annotationState;
146
155
  if (annotationState && !isVisible && editorExperiment('platform_editor_usesharedpluginstateselector', false)) {
147
156
  return null;
148
157
  }
@@ -141,7 +141,9 @@ export var applyDraft = function applyDraft(editorView, options) {
141
141
  return {
142
142
  success: true,
143
143
  // Get the dom element from the newly created annotation and return it here.
144
- targetElement: targetElement
144
+ targetElement: targetElement,
145
+ // In Editor this is undefined, because the editor will update the document.
146
+ actionResult: undefined
145
147
  };
146
148
  };
147
149
  };
@@ -2,6 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import React from 'react';
3
3
  import { AnnotationTypes } from '@atlaskit/adf-schema';
4
4
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, CONTENT_COMPONENT, EVENT_TYPE, RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
5
+ import { sharedPluginStateHookMigratorFactory } from '@atlaskit/editor-common/hooks';
5
6
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
6
7
  import { getAnnotationInlineNodeTypes, getRangeInlineNodeNames } from '@atlaskit/editor-common/utils';
7
8
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
@@ -27,53 +28,66 @@ var findPosForDOM = function findPosForDOM(sel) {
27
28
  }
28
29
  return from;
29
30
  };
30
- export function InlineCommentView(_ref) {
31
- var providers = _ref.providers,
32
- editorView = _ref.editorView,
33
- editorAnalyticsAPI = _ref.editorAnalyticsAPI,
34
- editorAPI = _ref.editorAPI,
35
- dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent;
31
+ var useInlineCommentViewPluginState = sharedPluginStateHookMigratorFactory(function (_ref) {
32
+ var api = _ref.api;
33
+ // eslint-disable-next-line react-hooks/rules-of-hooks
34
+ var bookmark = useSharedPluginStateSelector(api, 'annotation.bookmark');
35
+ // eslint-disable-next-line react-hooks/rules-of-hooks
36
+ var selectedAnnotations = useSharedPluginStateSelector(api, 'annotation.selectedAnnotations');
37
+ // eslint-disable-next-line react-hooks/rules-of-hooks
38
+ var annotations = useSharedPluginStateSelector(api, 'annotation.annotations');
39
+ // eslint-disable-next-line react-hooks/rules-of-hooks
40
+ var isInlineCommentViewClosed = useSharedPluginStateSelector(api, 'annotation.isInlineCommentViewClosed');
41
+ // eslint-disable-next-line react-hooks/rules-of-hooks
42
+ var isOpeningMediaCommentFromToolbar = useSharedPluginStateSelector(api, 'annotation.isOpeningMediaCommentFromToolbar');
43
+ // eslint-disable-next-line react-hooks/rules-of-hooks
44
+ var selectAnnotationMethod = useSharedPluginStateSelector(api, 'annotation.selectAnnotationMethod');
45
+ return {
46
+ bookmark: bookmark,
47
+ selectedAnnotations: selectedAnnotations,
48
+ annotations: annotations,
49
+ isInlineCommentViewClosed: isInlineCommentViewClosed,
50
+ isOpeningMediaCommentFromToolbar: isOpeningMediaCommentFromToolbar,
51
+ selectAnnotationMethod: selectAnnotationMethod
52
+ };
53
+ }, function (_ref2) {
54
+ var state = _ref2.state;
55
+ var inlineCommentState = getPluginState(state);
56
+ return {
57
+ bookmark: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.bookmark,
58
+ selectedAnnotations: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.selectedAnnotations,
59
+ annotations: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.annotations,
60
+ isInlineCommentViewClosed: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.isInlineCommentViewClosed,
61
+ isOpeningMediaCommentFromToolbar: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.isOpeningMediaCommentFromToolbar,
62
+ selectAnnotationMethod: inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.selectAnnotationMethod
63
+ };
64
+ });
65
+ export function InlineCommentView(_ref3) {
66
+ var providers = _ref3.providers,
67
+ editorView = _ref3.editorView,
68
+ editorAnalyticsAPI = _ref3.editorAnalyticsAPI,
69
+ editorAPI = _ref3.editorAPI,
70
+ dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent;
36
71
  // As inlineComment is the only annotation present, this function is not generic
37
72
  var inlineCommentProvider = providers.inlineComment;
38
73
  var state = editorView.state,
39
74
  dispatch = editorView.dispatch;
40
75
  var CreateComponent = inlineCommentProvider.createComponent,
41
76
  ViewComponent = inlineCommentProvider.viewComponent;
42
- var inlineCommentState = getPluginState(state);
43
-
44
- // bookmark
45
- var bookmarkSelector = useSharedPluginStateSelector(editorAPI, 'annotation.bookmark', {
46
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
47
- });
48
- var bookmark = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? bookmarkSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.bookmark;
49
-
50
- // selectedAnnotations
51
- var selectedAnnotationsSelector = useSharedPluginStateSelector(editorAPI, 'annotation.selectedAnnotations', {
52
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
53
- });
54
- var selectedAnnotations = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? selectedAnnotationsSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.selectedAnnotations;
55
-
56
- // annotations
57
- var annotationsSelector = useSharedPluginStateSelector(editorAPI, 'annotation.annotations', {
58
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
59
- });
60
- var annotations = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? annotationsSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.annotations;
61
-
62
- // isInlineCommentViewClosed
63
- var isInlineCommentViewClosedSelector = useSharedPluginStateSelector(editorAPI, 'annotation.isInlineCommentViewClosed', {
64
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
65
- });
66
- var isInlineCommentViewClosed = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? isInlineCommentViewClosedSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.isInlineCommentViewClosed;
67
-
68
- // isOpeningMediaCommentFromToolbar
69
- var isOpeningMediaCommentFromToolbarSelector = useSharedPluginStateSelector(editorAPI, 'annotation.isOpeningMediaCommentFromToolbar', {
70
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
71
- });
72
- var isOpeningMediaCommentFromToolbar = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? isOpeningMediaCommentFromToolbarSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.isOpeningMediaCommentFromToolbar;
77
+ var _useInlineCommentView = useInlineCommentViewPluginState({
78
+ api: editorAPI,
79
+ state: state
80
+ }),
81
+ annotations = _useInlineCommentView.annotations,
82
+ bookmark = _useInlineCommentView.bookmark,
83
+ isInlineCommentViewClosed = _useInlineCommentView.isInlineCommentViewClosed,
84
+ isOpeningMediaCommentFromToolbar = _useInlineCommentView.isOpeningMediaCommentFromToolbar,
85
+ selectAnnotationMethod = _useInlineCommentView.selectAnnotationMethod,
86
+ selectedAnnotations = _useInlineCommentView.selectedAnnotations;
73
87
  var annotationsList = getAllAnnotations(editorView.state.doc);
74
- var selection = getSelectionPositions(state, editorExperiment('platform_editor_usesharedpluginstateselector', true) ? {
88
+ var selection = getSelectionPositions(state, {
75
89
  bookmark: bookmark
76
- } : inlineCommentState);
90
+ });
77
91
  var position = findPosForDOM(selection);
78
92
  var dom;
79
93
  try {
@@ -100,9 +114,9 @@ export function InlineCommentView(_ref) {
100
114
  }
101
115
  }
102
116
 
103
- // selectAnnotationMethod
104
- var selectAnnotationMethodSelector = useSharedPluginStateSelector(editorAPI, 'annotation.selectAnnotationMethod', {
105
- disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
117
+ // Network Status
118
+ var networkStatusSelector = useSharedPluginStateSelector(editorAPI, 'connectivity.mode', {
119
+ disabled: editorExperiment('platform_editor_offline_editing_web', false)
106
120
  });
107
121
  if (!dom) {
108
122
  return null;
@@ -142,7 +156,8 @@ export function InlineCommentView(_ref) {
142
156
  }
143
157
  },
144
158
  inlineNodeTypes: inlineNodeTypes,
145
- isOpeningMediaCommentFromToolbar: isOpeningMediaCommentFromToolbar
159
+ isOpeningMediaCommentFromToolbar: isOpeningMediaCommentFromToolbar,
160
+ isOffline: networkStatusSelector === 'offline'
146
161
  }));
147
162
  }
148
163
 
@@ -168,7 +183,7 @@ export function InlineCommentView(_ref) {
168
183
  attributes: {
169
184
  overlap: activeAnnotations.length ? activeAnnotations.length - 1 : 0,
170
185
  targetNodeType: (_editorView$state$doc = editorView.state.doc.nodeAt(position)) === null || _editorView$state$doc === void 0 ? void 0 : _editorView$state$doc.type.name,
171
- method: editorExperiment('platform_editor_tables_table_selector', true) ? selectAnnotationMethodSelector : inlineCommentState === null || inlineCommentState === void 0 ? void 0 : inlineCommentState.selectAnnotationMethod
186
+ method: selectAnnotationMethod
172
187
  }
173
188
  };
174
189
  dispatchAnalyticsEvent(payload);
@@ -202,6 +217,7 @@ export function InlineCommentView(_ref) {
202
217
  onClose: function onClose() {
203
218
  closeComponent()(editorView.state, editorView.dispatch);
204
219
  },
205
- isOpeningMediaCommentFromToolbar: isOpeningMediaCommentFromToolbar
220
+ isOpeningMediaCommentFromToolbar: isOpeningMediaCommentFromToolbar,
221
+ isOffline: networkStatusSelector === 'offline'
206
222
  }));
207
223
  }
@@ -29,6 +29,10 @@ type AnnotationComponentProps = {
29
29
  * Indicates that a draft comment was discarded/cancelled
30
30
  */
31
31
  onClose?: () => void;
32
+ /**
33
+ * Indicates whether the comment UI is offline and should be disabled
34
+ */
35
+ isOffline?: boolean;
32
36
  };
33
37
  export type InlineCommentCreateComponentProps = AnnotationComponentProps & {
34
38
  /**
@@ -29,6 +29,10 @@ type AnnotationComponentProps = {
29
29
  * Indicates that a draft comment was discarded/cancelled
30
30
  */
31
31
  onClose?: () => void;
32
+ /**
33
+ * Indicates whether the comment UI is offline and should be disabled
34
+ */
35
+ isOffline?: boolean;
32
36
  };
33
37
  export type InlineCommentCreateComponentProps = AnnotationComponentProps & {
34
38
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-annotation",
3
- "version": "2.7.5",
3
+ "version": "2.8.0",
4
4
  "description": "Annotation plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",