@atlaskit/renderer 115.0.2 → 115.0.4

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 (37) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/ui/Renderer/index.js +1 -1
  3. package/dist/cjs/ui/annotations/contexts/AnnotationManagerContext.js +421 -0
  4. package/dist/cjs/ui/annotations/draft/component.js +13 -1
  5. package/dist/cjs/ui/annotations/element/index.js +38 -6
  6. package/dist/cjs/ui/annotations/element/mark.js +16 -0
  7. package/dist/cjs/ui/annotations/hooks/use-events.js +77 -27
  8. package/dist/cjs/ui/annotations/hooks/use-load-annotations.js +18 -2
  9. package/dist/cjs/ui/annotations/index.js +49 -12
  10. package/dist/cjs/ui/annotations/selection/mounter.js +177 -4
  11. package/dist/es2019/ui/Renderer/index.js +1 -1
  12. package/dist/es2019/ui/annotations/contexts/AnnotationManagerContext.js +416 -0
  13. package/dist/es2019/ui/annotations/draft/component.js +15 -3
  14. package/dist/es2019/ui/annotations/element/index.js +39 -6
  15. package/dist/es2019/ui/annotations/element/mark.js +18 -0
  16. package/dist/es2019/ui/annotations/hooks/use-events.js +85 -28
  17. package/dist/es2019/ui/annotations/hooks/use-load-annotations.js +19 -2
  18. package/dist/es2019/ui/annotations/index.js +47 -10
  19. package/dist/es2019/ui/annotations/selection/mounter.js +177 -6
  20. package/dist/esm/ui/Renderer/index.js +1 -1
  21. package/dist/esm/ui/annotations/contexts/AnnotationManagerContext.js +411 -0
  22. package/dist/esm/ui/annotations/draft/component.js +14 -3
  23. package/dist/esm/ui/annotations/element/index.js +38 -6
  24. package/dist/esm/ui/annotations/element/mark.js +16 -0
  25. package/dist/esm/ui/annotations/hooks/use-events.js +78 -28
  26. package/dist/esm/ui/annotations/hooks/use-load-annotations.js +18 -2
  27. package/dist/esm/ui/annotations/index.js +45 -10
  28. package/dist/esm/ui/annotations/selection/mounter.js +179 -6
  29. package/dist/types/ui/annotations/contexts/AnnotationManagerContext.d.ts +71 -0
  30. package/dist/types/ui/annotations/draft/component.d.ts +5 -1
  31. package/dist/types/ui/annotations/element/mark.d.ts +6 -0
  32. package/dist/types/ui/annotations/index.d.ts +1 -0
  33. package/dist/types-ts4.5/ui/annotations/contexts/AnnotationManagerContext.d.ts +71 -0
  34. package/dist/types-ts4.5/ui/annotations/draft/component.d.ts +5 -1
  35. package/dist/types-ts4.5/ui/annotations/element/mark.d.ts +6 -0
  36. package/dist/types-ts4.5/ui/annotations/index.d.ts +1 -0
  37. package/package.json +13 -5
@@ -1,13 +1,21 @@
1
- import { useLayoutEffect, useState } from 'react';
1
+ import { useLayoutEffect, useMemo, useState } from 'react';
2
2
  import { AnnotationUpdateEvent } from '@atlaskit/editor-common/types';
3
3
  import { AnnotationTypes } from '@atlaskit/adf-schema';
4
4
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
5
5
  import { FabricChannel } from '@atlaskit/analytics-listeners/types';
6
+ import { fg } from '@atlaskit/platform-feature-flags';
7
+ import { useAnnotationManagerDispatch, useAnnotationManagerState } from '../contexts/AnnotationManagerContext';
6
8
  export const useAnnotationStateByTypeEvent = ({
7
9
  type,
8
10
  updateSubscriber
9
11
  }) => {
10
12
  const [states, setStates] = useState({});
13
+ const {
14
+ dispatch
15
+ } = useAnnotationManagerDispatch();
16
+ const {
17
+ annotations
18
+ } = useAnnotationManagerState();
11
19
  useLayoutEffect(() => {
12
20
  if (!updateSubscriber) {
13
21
  return;
@@ -32,12 +40,26 @@ export const useAnnotationStateByTypeEvent = ({
32
40
  ...nextStates
33
41
  });
34
42
  };
35
- updateSubscriber.on(AnnotationUpdateEvent.SET_ANNOTATION_STATE, cb);
36
- return () => {
37
- updateSubscriber.off(AnnotationUpdateEvent.SET_ANNOTATION_STATE, cb);
38
- };
39
- }, [states, type, updateSubscriber]);
40
- return states;
43
+ if (!fg('platform_editor_comments_api_manager')) {
44
+ updateSubscriber.on(AnnotationUpdateEvent.SET_ANNOTATION_STATE, cb);
45
+ return () => {
46
+ updateSubscriber.off(AnnotationUpdateEvent.SET_ANNOTATION_STATE, cb);
47
+ };
48
+ }
49
+ }, [states, type, updateSubscriber, dispatch]);
50
+ const annotationMarkStates = useMemo(() => {
51
+ return Object.values(annotations).reduce((acc, curr) => {
52
+ return {
53
+ ...acc,
54
+ [curr.id]: curr.markState
55
+ };
56
+ }, {});
57
+ }, [annotations]);
58
+ if (fg('platform_editor_comments_api_manager')) {
59
+ return annotationMarkStates;
60
+ } else {
61
+ return states;
62
+ }
41
63
  };
42
64
  export const useHasFocusEvent = ({
43
65
  id,
@@ -45,6 +67,10 @@ export const useHasFocusEvent = ({
45
67
  }) => {
46
68
  const [hasFocus, setHasFocus] = useState(false);
47
69
  const [isHovered, setIsHovered] = useState(false);
70
+ const {
71
+ currentSelectedAnnotationId,
72
+ currentHoveredAnnotationId
73
+ } = useAnnotationManagerState();
48
74
  useLayoutEffect(() => {
49
75
  if (!updateSubscriber) {
50
76
  return;
@@ -67,21 +93,30 @@ export const useHasFocusEvent = ({
67
93
  document.activeElement.blur();
68
94
  }
69
95
  };
70
- updateSubscriber.on(AnnotationUpdateEvent.SET_ANNOTATION_FOCUS, cb);
71
- updateSubscriber.on(AnnotationUpdateEvent.SET_ANNOTATION_HOVERED, callbackForHoveredAnnotation);
72
- updateSubscriber.on(AnnotationUpdateEvent.REMOVE_ANNOTATION_FOCUS, removeFocus);
73
- updateSubscriber.on(AnnotationUpdateEvent.REMOVE_ANNOTATION_HOVERED, removeHoverEffect);
74
- return () => {
75
- updateSubscriber.off(AnnotationUpdateEvent.SET_ANNOTATION_FOCUS, cb);
76
- updateSubscriber.off(AnnotationUpdateEvent.SET_ANNOTATION_HOVERED, callbackForHoveredAnnotation);
77
- updateSubscriber.off(AnnotationUpdateEvent.REMOVE_ANNOTATION_FOCUS, removeFocus);
78
- updateSubscriber.off(AnnotationUpdateEvent.SET_ANNOTATION_HOVERED, removeHoverEffect);
79
- };
96
+ if (!fg('platform_editor_comments_api_manager')) {
97
+ updateSubscriber.on(AnnotationUpdateEvent.SET_ANNOTATION_FOCUS, cb);
98
+ updateSubscriber.on(AnnotationUpdateEvent.SET_ANNOTATION_HOVERED, callbackForHoveredAnnotation);
99
+ updateSubscriber.on(AnnotationUpdateEvent.REMOVE_ANNOTATION_FOCUS, removeFocus);
100
+ updateSubscriber.on(AnnotationUpdateEvent.REMOVE_ANNOTATION_HOVERED, removeHoverEffect);
101
+ return () => {
102
+ updateSubscriber.off(AnnotationUpdateEvent.SET_ANNOTATION_FOCUS, cb);
103
+ updateSubscriber.off(AnnotationUpdateEvent.SET_ANNOTATION_HOVERED, callbackForHoveredAnnotation);
104
+ updateSubscriber.off(AnnotationUpdateEvent.REMOVE_ANNOTATION_FOCUS, removeFocus);
105
+ updateSubscriber.off(AnnotationUpdateEvent.SET_ANNOTATION_HOVERED, removeHoverEffect);
106
+ };
107
+ }
80
108
  }, [id, updateSubscriber]);
81
- return {
82
- hasFocus,
83
- isHovered
84
- };
109
+ if (fg('platform_editor_comments_api_manager')) {
110
+ return {
111
+ hasFocus: currentSelectedAnnotationId === id,
112
+ isHovered: currentHoveredAnnotationId === id
113
+ };
114
+ } else {
115
+ return {
116
+ hasFocus,
117
+ isHovered
118
+ };
119
+ }
85
120
  };
86
121
  export const useAnnotationClickEvent = props => {
87
122
  const [annotationClickEvent, setAnnotationClickEvent] = useState(null);
@@ -90,6 +125,22 @@ export const useAnnotationClickEvent = props => {
90
125
  createAnalyticsEvent,
91
126
  isNestedRender
92
127
  } = props;
128
+ const {
129
+ currentSelectedAnnotationId,
130
+ currentSelectedMarkRef
131
+ } = useAnnotationManagerState();
132
+ const selectedAnnotation = useMemo(() => {
133
+ return currentSelectedAnnotationId && currentSelectedMarkRef ? {
134
+ annotations: [{
135
+ id: currentSelectedAnnotationId,
136
+ type: AnnotationTypes.INLINE_COMMENT
137
+ }],
138
+ clickElementTarget: currentSelectedMarkRef
139
+ } : {
140
+ annotations: [],
141
+ clickElementTarget: undefined
142
+ };
143
+ }, [currentSelectedAnnotationId, currentSelectedMarkRef]);
93
144
  useLayoutEffect(() => {
94
145
  if (!updateSubscriber || isNestedRender) {
95
146
  return;
@@ -131,12 +182,18 @@ export const useAnnotationClickEvent = props => {
131
182
  document.activeElement.blur();
132
183
  }
133
184
  };
134
- updateSubscriber.on(AnnotationUpdateEvent.ON_ANNOTATION_CLICK, clickCb);
135
- updateSubscriber.on(AnnotationUpdateEvent.DESELECT_ANNOTATIONS, deselectCb);
136
- return () => {
137
- updateSubscriber.off(AnnotationUpdateEvent.ON_ANNOTATION_CLICK, clickCb);
138
- updateSubscriber.off(AnnotationUpdateEvent.DESELECT_ANNOTATIONS, deselectCb);
139
- };
185
+ if (!fg('platform_editor_comments_api_manager')) {
186
+ updateSubscriber.on(AnnotationUpdateEvent.ON_ANNOTATION_CLICK, clickCb);
187
+ updateSubscriber.on(AnnotationUpdateEvent.DESELECT_ANNOTATIONS, deselectCb);
188
+ return () => {
189
+ updateSubscriber.off(AnnotationUpdateEvent.ON_ANNOTATION_CLICK, clickCb);
190
+ updateSubscriber.off(AnnotationUpdateEvent.DESELECT_ANNOTATIONS, deselectCb);
191
+ };
192
+ }
140
193
  }, [updateSubscriber, createAnalyticsEvent, isNestedRender]);
141
- return annotationClickEvent;
194
+ if (fg('platform_editor_comments_api_manager')) {
195
+ return selectedAnnotation;
196
+ } else {
197
+ return annotationClickEvent;
198
+ }
142
199
  };
@@ -3,6 +3,7 @@ import { AnnotationUpdateEvent } from '@atlaskit/editor-common/types';
3
3
  import { fg } from '@atlaskit/platform-feature-flags';
4
4
  import { ProvidersContext } from '../context';
5
5
  import { RendererContext as ActionsContext } from '../../RendererActionsContext';
6
+ import { useAnnotationManagerDispatch } from '../contexts/AnnotationManagerContext';
6
7
  export const useLoadAnnotations = ({
7
8
  adfDocument,
8
9
  isNestedRender,
@@ -10,6 +11,9 @@ export const useLoadAnnotations = ({
10
11
  }) => {
11
12
  const actions = useContext(ActionsContext);
12
13
  const providers = useContext(ProvidersContext);
14
+ const {
15
+ dispatch
16
+ } = useAnnotationManagerDispatch();
13
17
  useEffect(() => {
14
18
  if (!providers) {
15
19
  return;
@@ -41,11 +45,24 @@ export const useLoadAnnotations = ({
41
45
  ...acc,
42
46
  [value.id]: value
43
47
  }), {});
44
- updateSubscriberInlineComment.emit(AnnotationUpdateEvent.SET_ANNOTATION_STATE, payload);
48
+ if (fg('platform_editor_comments_api_manager')) {
49
+ dispatch({
50
+ type: 'loadAnnotation',
51
+ data: Object.keys(payload).map(id => {
52
+ var _payload$id$state;
53
+ return {
54
+ id,
55
+ markState: (_payload$id$state = payload[id].state) !== null && _payload$id$state !== void 0 ? _payload$id$state : undefined
56
+ };
57
+ })
58
+ });
59
+ } else {
60
+ updateSubscriberInlineComment.emit(AnnotationUpdateEvent.SET_ANNOTATION_STATE, payload);
61
+ }
45
62
  onLoadComplete && onLoadComplete({
46
63
  numberOfUnresolvedInlineComments: data.filter(data => data.state === 'active').length
47
64
  });
48
65
  };
49
66
  inlineCommentGetState(ids, isNestedRender).then(cb);
50
- }, [actions, providers, adfDocument, isNestedRender, onLoadComplete]);
67
+ }, [actions, providers, adfDocument, isNestedRender, onLoadComplete, dispatch]);
51
68
  };
@@ -1,5 +1,6 @@
1
- import React from 'react';
1
+ import React, { useContext } from 'react';
2
2
  import { AnnotationTypes } from '@atlaskit/adf-schema';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
3
4
  import { AnnotationView } from './view';
4
5
  import { AnnotationsContextWrapper } from './wrapper';
5
6
  import { ProvidersContext, InlineCommentsStateContext } from './context';
@@ -8,6 +9,7 @@ import { useAnnotationStateByTypeEvent } from './hooks/use-events';
8
9
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
9
10
  import { AnnotationRangeProvider } from './contexts/AnnotationRangeContext';
10
11
  import { AnnotationHoverContext } from './contexts/AnnotationHoverContext';
12
+ import { AnnotationManagerProvider } from './contexts/AnnotationManagerContext';
11
13
  const LoadAnnotations = /*#__PURE__*/React.memo(({
12
14
  adfDocument,
13
15
  isNestedRender,
@@ -28,17 +30,17 @@ const LoadAnnotations = /*#__PURE__*/React.memo(({
28
30
  export const AnnotationsPositionContext = /*#__PURE__*/React.createContext({
29
31
  startPos: 1
30
32
  });
31
- export const AnnotationsWrapper = props => {
32
- var _annotationProvider$i, _annotationProvider$i2;
33
+ export const AnnotationsWrapperInner = props => {
34
+ var _providers$inlineComm, _providers$inlineComm2;
33
35
  const {
34
36
  children,
35
- annotationProvider,
36
37
  rendererRef,
37
38
  adfDocument,
38
39
  isNestedRender,
39
40
  onLoadComplete
40
41
  } = props;
41
- const updateSubscriber = annotationProvider && annotationProvider.inlineComment && annotationProvider.inlineComment.updateSubscriber;
42
+ const providers = useContext(ProvidersContext);
43
+ const updateSubscriber = providers && providers.inlineComment && providers.inlineComment.updateSubscriber;
42
44
  const inlineCommentAnnotationsState = useAnnotationStateByTypeEvent({
43
45
  type: AnnotationTypes.INLINE_COMMENT,
44
46
  updateSubscriber: updateSubscriber || null
@@ -46,12 +48,10 @@ export const AnnotationsWrapper = props => {
46
48
  const {
47
49
  createAnalyticsEvent
48
50
  } = useAnalyticsEvents();
49
- return /*#__PURE__*/React.createElement(ProvidersContext.Provider, {
50
- value: annotationProvider
51
- }, /*#__PURE__*/React.createElement(InlineCommentsStateContext.Provider, {
51
+ return /*#__PURE__*/React.createElement(InlineCommentsStateContext.Provider, {
52
52
  value: inlineCommentAnnotationsState
53
53
  }, /*#__PURE__*/React.createElement(AnnotationRangeProvider, {
54
- allowCommentsOnMedia: (_annotationProvider$i = annotationProvider === null || annotationProvider === void 0 ? void 0 : (_annotationProvider$i2 = annotationProvider.inlineComment) === null || _annotationProvider$i2 === void 0 ? void 0 : _annotationProvider$i2.allowCommentsOnMedia) !== null && _annotationProvider$i !== void 0 ? _annotationProvider$i : false
54
+ allowCommentsOnMedia: (_providers$inlineComm = providers === null || providers === void 0 ? void 0 : (_providers$inlineComm2 = providers.inlineComment) === null || _providers$inlineComm2 === void 0 ? void 0 : _providers$inlineComm2.allowCommentsOnMedia) !== null && _providers$inlineComm !== void 0 ? _providers$inlineComm : false
55
55
  }, /*#__PURE__*/React.createElement(AnnotationHoverContext, null, /*#__PURE__*/React.createElement(AnnotationsContextWrapper, {
56
56
  createAnalyticsEvent: createAnalyticsEvent,
57
57
  rendererRef: rendererRef,
@@ -63,5 +63,42 @@ export const AnnotationsWrapper = props => {
63
63
  }), /*#__PURE__*/React.createElement(AnnotationView, {
64
64
  isNestedRender: isNestedRender,
65
65
  createAnalyticsEvent: createAnalyticsEvent
66
- }), children)))));
66
+ }), children))));
67
+ };
68
+ export const AnnotationsWrapper = props => {
69
+ const {
70
+ children,
71
+ annotationProvider,
72
+ rendererRef,
73
+ adfDocument,
74
+ isNestedRender,
75
+ onLoadComplete
76
+ } = props;
77
+ if (!isNestedRender && fg('platform_editor_comments_api_manager')) {
78
+ var _annotationProvider$i, _annotationProvider$i2;
79
+ // We need to ensure there is a single instance of the annotation manager for the whole document
80
+ // and that it is the same instance for all annotations.
81
+ // This is because the annotation manager is responsible for managing the state of ALL annotations.
82
+ // This includes annotations inside extensions.
83
+ return /*#__PURE__*/React.createElement(ProvidersContext.Provider, {
84
+ value: annotationProvider
85
+ }, /*#__PURE__*/React.createElement(AnnotationManagerProvider, {
86
+ annotationManager: annotationProvider === null || annotationProvider === void 0 ? void 0 : annotationProvider.annotationManager,
87
+ updateSubscriber: (_annotationProvider$i = annotationProvider === null || annotationProvider === void 0 ? void 0 : (_annotationProvider$i2 = annotationProvider.inlineComment) === null || _annotationProvider$i2 === void 0 ? void 0 : _annotationProvider$i2.updateSubscriber) !== null && _annotationProvider$i !== void 0 ? _annotationProvider$i : undefined
88
+ }, /*#__PURE__*/React.createElement(AnnotationsWrapperInner, {
89
+ rendererRef: rendererRef,
90
+ adfDocument: adfDocument,
91
+ isNestedRender: isNestedRender,
92
+ onLoadComplete: onLoadComplete
93
+ }, children)));
94
+ } else {
95
+ return /*#__PURE__*/React.createElement(ProvidersContext.Provider, {
96
+ value: annotationProvider
97
+ }, /*#__PURE__*/React.createElement(AnnotationsWrapperInner, {
98
+ rendererRef: rendererRef,
99
+ adfDocument: adfDocument,
100
+ isNestedRender: isNestedRender,
101
+ onLoadComplete: onLoadComplete
102
+ }, children));
103
+ }
67
104
  };
@@ -1,11 +1,13 @@
1
- import React, { useCallback, useState, useContext, useMemo } from 'react';
2
- import { AnnotationTypes } from '@atlaskit/adf-schema';
1
+ import React, { useCallback, useState, useContext, useMemo, useEffect } from 'react';
2
+ import uuid from 'uuid/v4';
3
+ import { AnnotationTypes, AnnotationMarkStates } from '@atlaskit/adf-schema';
3
4
  import { fg } from '@atlaskit/platform-feature-flags';
4
5
  import { updateWindowSelectionAroundDraft } from '../draft/dom';
5
6
  import { FabricChannel } from '@atlaskit/analytics-listeners/types';
6
7
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
7
8
  import { getRendererRangeInlineNodeNames } from '../../../actions/get-renderer-range-inline-node-names';
8
9
  import { RendererContext as ActionsContext } from '../../RendererActionsContext';
10
+ import { useAnnotationManagerDispatch, useAnnotationManagerState } from '../contexts/AnnotationManagerContext';
9
11
  export const SelectionInlineCommentMounter = /*#__PURE__*/React.memo(props => {
10
12
  const {
11
13
  component: Component,
@@ -23,6 +25,14 @@ export const SelectionInlineCommentMounter = /*#__PURE__*/React.memo(props => {
23
25
  } = props;
24
26
  const [draftDocumentPosition, setDraftDocumentPosition] = useState();
25
27
  const actions = useContext(ActionsContext);
28
+ const {
29
+ isDrafting,
30
+ draftId
31
+ } = useAnnotationManagerState();
32
+ const {
33
+ annotationManager,
34
+ dispatch
35
+ } = useAnnotationManagerDispatch();
26
36
  const inlineNodeTypes = useMemo(() => {
27
37
  if (fg('annotations_defensive_node_name_calculations')) {
28
38
  if (!actions.isRangeAnnotatable(range)) {
@@ -175,6 +185,167 @@ export const SelectionInlineCommentMounter = /*#__PURE__*/React.memo(props => {
175
185
  removeDraftModeCallback();
176
186
  onCloseProps();
177
187
  }, [onCloseProps, removeDraftModeCallback, createAnalyticsEvent, inlineNodeTypes]);
188
+ useEffect(() => {
189
+ if (fg('platform_editor_comments_api_manager')) {
190
+ const allowAnnotation = () => {
191
+ if (isDrafting) {
192
+ return false;
193
+ }
194
+ return isAnnotationAllowed;
195
+ };
196
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.hook('allowAnnotation', allowAnnotation);
197
+ return () => {
198
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.unhook('allowAnnotation', allowAnnotation);
199
+ };
200
+ }
201
+ }, [annotationManager, isAnnotationAllowed, isDrafting]);
202
+ useEffect(() => {
203
+ if (fg('platform_editor_comments_api_manager')) {
204
+ const startDraft = () => {
205
+ var _result$inlineNodeTyp;
206
+ if (isDrafting) {
207
+ return {
208
+ success: false,
209
+ reason: 'draft-in-progress'
210
+ };
211
+ }
212
+ if (!actions.isValidAnnotationRange(range)) {
213
+ return {
214
+ success: false,
215
+ reason: 'invalid-range'
216
+ };
217
+ }
218
+ const id = uuid();
219
+ const result = applyDraftModeCallback({
220
+ annotationId: id,
221
+ keepNativeSelection: false
222
+ });
223
+ if (!result) {
224
+ return {
225
+ success: false,
226
+ reason: 'invalid-range'
227
+ };
228
+ }
229
+ dispatch({
230
+ type: 'setDrafting',
231
+ data: {
232
+ isDrafting: true,
233
+ draftId: id,
234
+ draftActionResult: result
235
+ }
236
+ });
237
+ dispatch({
238
+ type: 'resetSelectedAnnotation'
239
+ });
240
+ return {
241
+ success: true,
242
+ // We cannot get a ref to the target element here
243
+ // because the draft is not yet applied to the DOM
244
+ targetElement: undefined,
245
+ inlineNodeTypes: (_result$inlineNodeTyp = result.inlineNodeTypes) !== null && _result$inlineNodeTyp !== void 0 ? _result$inlineNodeTyp : [],
246
+ actionResult: {
247
+ step: result.step,
248
+ doc: result.doc,
249
+ inlineNodeTypes: result.inlineNodeTypes,
250
+ targetNodeType: result.targetNodeType,
251
+ originalSelection: result.originalSelection,
252
+ numMatches: result.numMatches,
253
+ matchIndex: result.matchIndex,
254
+ pos: result.pos
255
+ }
256
+ };
257
+ };
258
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.hook('startDraft', startDraft);
259
+ return () => {
260
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.unhook('startDraft', startDraft);
261
+ };
262
+ }
263
+ }, [annotationManager, isDrafting, applyDraftModeCallback, actions, range, dispatch]);
264
+ useEffect(() => {
265
+ if (fg('platform_editor_comments_api_manager')) {
266
+ const clearDraft = () => {
267
+ if (!isDrafting) {
268
+ return {
269
+ success: false,
270
+ reason: 'draft-not-started'
271
+ };
272
+ }
273
+ dispatch({
274
+ type: 'setDrafting',
275
+ data: {
276
+ isDrafting: false,
277
+ draftId: undefined,
278
+ draftActionResult: undefined
279
+ }
280
+ });
281
+ onCloseCallback();
282
+ return {
283
+ success: true
284
+ };
285
+ };
286
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.hook('clearDraft', clearDraft);
287
+ return () => {
288
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.unhook('clearDraft', clearDraft);
289
+ };
290
+ }
291
+ }, [annotationManager, onCloseCallback, isDrafting, dispatch]);
292
+ useEffect(() => {
293
+ if (fg('platform_editor_comments_api_manager')) {
294
+ const applyDraft = id => {
295
+ if (!isDrafting || !draftId) {
296
+ return {
297
+ success: false,
298
+ reason: 'draft-not-started'
299
+ };
300
+ }
301
+ const result = onCreateCallback(id);
302
+ if (!result) {
303
+ return {
304
+ success: false,
305
+ reason: 'range-no-longer-exists'
306
+ };
307
+ }
308
+ onCloseCallback();
309
+ dispatch({
310
+ type: 'setDrafting',
311
+ data: {
312
+ isDrafting: false,
313
+ draftId: undefined,
314
+ draftActionResult: undefined
315
+ }
316
+ });
317
+ dispatch({
318
+ type: 'updateAnnotation',
319
+ data: {
320
+ id,
321
+ selected: true,
322
+ markState: AnnotationMarkStates.ACTIVE
323
+ }
324
+ });
325
+ return {
326
+ success: true,
327
+ targetElement: undefined,
328
+ actionResult: id !== draftId ? {
329
+ step: result.step,
330
+ doc: result.doc,
331
+ inlineNodeTypes: result.inlineNodeTypes,
332
+ targetNodeType: result.targetNodeType,
333
+ originalSelection: result.originalSelection,
334
+ numMatches: result.numMatches,
335
+ matchIndex: result.matchIndex,
336
+ pos: result.pos
337
+ } : undefined
338
+ };
339
+ };
340
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.hook('applyDraft', applyDraft);
341
+ return () => {
342
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.unhook('applyDraft', applyDraft);
343
+ };
344
+ }
345
+ }, [annotationManager, onCreateCallback, onCloseCallback, isDrafting, draftId, dispatch]);
346
+
347
+ // Please remove this NOP function when the flag platform_editor_comments_api_manager is removed.
348
+ const nop = useMemo(() => () => false, []);
178
349
  return /*#__PURE__*/React.createElement(Component, {
179
350
  range: range,
180
351
  draftRange: draftRange
@@ -183,11 +354,11 @@ export const SelectionInlineCommentMounter = /*#__PURE__*/React.memo(props => {
183
354
  ,
184
355
  wrapperDOM: wrapperDOM.current,
185
356
  isAnnotationAllowed: isAnnotationAllowed,
186
- onClose: onCloseCallback,
187
- onCreate: onCreateCallback,
357
+ onClose: fg('platform_editor_comments_api_manager') ? nop : onCloseCallback,
358
+ onCreate: fg('platform_editor_comments_api_manager') ? nop : onCreateCallback,
188
359
  getAnnotationIndexMatch: createIndexCallback,
189
- applyDraftMode: applyDraftModeCallback,
190
- removeDraftMode: removeDraftModeCallback,
360
+ applyDraftMode: fg('platform_editor_comments_api_manager') ? nop : applyDraftModeCallback,
361
+ removeDraftMode: fg('platform_editor_comments_api_manager') ? nop : removeDraftModeCallback,
191
362
  inlineNodeTypes: inlineNodeTypes
192
363
  });
193
364
  });
@@ -50,7 +50,7 @@ import { useMemoFromPropsDerivative } from './useMemoFromPropsDerivative';
50
50
  export var NORMAL_SEVERITY_THRESHOLD = 2000;
51
51
  export var DEGRADED_SEVERITY_THRESHOLD = 3000;
52
52
  var packageName = "@atlaskit/renderer";
53
- var packageVersion = "115.0.2";
53
+ var packageVersion = "115.0.4";
54
54
  var setAsQueryContainerStyles = css({
55
55
  containerName: 'ak-renderer-wrapper',
56
56
  containerType: 'inline-size',