@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
@@ -2,11 +2,13 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
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 { useLayoutEffect, useState } from 'react';
5
+ import { useLayoutEffect, useMemo, useState } from 'react';
6
6
  import { AnnotationUpdateEvent } from '@atlaskit/editor-common/types';
7
7
  import { AnnotationTypes } from '@atlaskit/adf-schema';
8
8
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
9
9
  import { FabricChannel } from '@atlaskit/analytics-listeners/types';
10
+ import { fg } from '@atlaskit/platform-feature-flags';
11
+ import { useAnnotationManagerDispatch, useAnnotationManagerState } from '../contexts/AnnotationManagerContext';
10
12
  export var useAnnotationStateByTypeEvent = function useAnnotationStateByTypeEvent(_ref) {
11
13
  var type = _ref.type,
12
14
  updateSubscriber = _ref.updateSubscriber;
@@ -14,6 +16,10 @@ export var useAnnotationStateByTypeEvent = function useAnnotationStateByTypeEven
14
16
  _useState2 = _slicedToArray(_useState, 2),
15
17
  states = _useState2[0],
16
18
  setStates = _useState2[1];
19
+ var _useAnnotationManager = useAnnotationManagerDispatch(),
20
+ dispatch = _useAnnotationManager.dispatch;
21
+ var _useAnnotationManager2 = useAnnotationManagerState(),
22
+ annotations = _useAnnotationManager2.annotations;
17
23
  useLayoutEffect(function () {
18
24
  if (!updateSubscriber) {
19
25
  return;
@@ -32,12 +38,23 @@ export var useAnnotationStateByTypeEvent = function useAnnotationStateByTypeEven
32
38
  }, {});
33
39
  setStates(_objectSpread(_objectSpread({}, states), nextStates));
34
40
  };
35
- updateSubscriber.on(AnnotationUpdateEvent.SET_ANNOTATION_STATE, cb);
36
- return function () {
37
- updateSubscriber.off(AnnotationUpdateEvent.SET_ANNOTATION_STATE, cb);
38
- };
39
- }, [states, type, updateSubscriber]);
40
- return states;
41
+ if (!fg('platform_editor_comments_api_manager')) {
42
+ updateSubscriber.on(AnnotationUpdateEvent.SET_ANNOTATION_STATE, cb);
43
+ return function () {
44
+ updateSubscriber.off(AnnotationUpdateEvent.SET_ANNOTATION_STATE, cb);
45
+ };
46
+ }
47
+ }, [states, type, updateSubscriber, dispatch]);
48
+ var annotationMarkStates = useMemo(function () {
49
+ return Object.values(annotations).reduce(function (acc, curr) {
50
+ return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, curr.id, curr.markState));
51
+ }, {});
52
+ }, [annotations]);
53
+ if (fg('platform_editor_comments_api_manager')) {
54
+ return annotationMarkStates;
55
+ } else {
56
+ return states;
57
+ }
41
58
  };
42
59
  export var useHasFocusEvent = function useHasFocusEvent(_ref2) {
43
60
  var id = _ref2.id,
@@ -50,6 +67,9 @@ export var useHasFocusEvent = function useHasFocusEvent(_ref2) {
50
67
  _useState6 = _slicedToArray(_useState5, 2),
51
68
  isHovered = _useState6[0],
52
69
  setIsHovered = _useState6[1];
70
+ var _useAnnotationManager3 = useAnnotationManagerState(),
71
+ currentSelectedAnnotationId = _useAnnotationManager3.currentSelectedAnnotationId,
72
+ currentHoveredAnnotationId = _useAnnotationManager3.currentHoveredAnnotationId;
53
73
  useLayoutEffect(function () {
54
74
  if (!updateSubscriber) {
55
75
  return;
@@ -72,21 +92,30 @@ export var useHasFocusEvent = function useHasFocusEvent(_ref2) {
72
92
  document.activeElement.blur();
73
93
  }
74
94
  };
75
- updateSubscriber.on(AnnotationUpdateEvent.SET_ANNOTATION_FOCUS, cb);
76
- updateSubscriber.on(AnnotationUpdateEvent.SET_ANNOTATION_HOVERED, callbackForHoveredAnnotation);
77
- updateSubscriber.on(AnnotationUpdateEvent.REMOVE_ANNOTATION_FOCUS, removeFocus);
78
- updateSubscriber.on(AnnotationUpdateEvent.REMOVE_ANNOTATION_HOVERED, removeHoverEffect);
79
- return function () {
80
- updateSubscriber.off(AnnotationUpdateEvent.SET_ANNOTATION_FOCUS, cb);
81
- updateSubscriber.off(AnnotationUpdateEvent.SET_ANNOTATION_HOVERED, callbackForHoveredAnnotation);
82
- updateSubscriber.off(AnnotationUpdateEvent.REMOVE_ANNOTATION_FOCUS, removeFocus);
83
- updateSubscriber.off(AnnotationUpdateEvent.SET_ANNOTATION_HOVERED, removeHoverEffect);
84
- };
95
+ if (!fg('platform_editor_comments_api_manager')) {
96
+ updateSubscriber.on(AnnotationUpdateEvent.SET_ANNOTATION_FOCUS, cb);
97
+ updateSubscriber.on(AnnotationUpdateEvent.SET_ANNOTATION_HOVERED, callbackForHoveredAnnotation);
98
+ updateSubscriber.on(AnnotationUpdateEvent.REMOVE_ANNOTATION_FOCUS, removeFocus);
99
+ updateSubscriber.on(AnnotationUpdateEvent.REMOVE_ANNOTATION_HOVERED, removeHoverEffect);
100
+ return function () {
101
+ updateSubscriber.off(AnnotationUpdateEvent.SET_ANNOTATION_FOCUS, cb);
102
+ updateSubscriber.off(AnnotationUpdateEvent.SET_ANNOTATION_HOVERED, callbackForHoveredAnnotation);
103
+ updateSubscriber.off(AnnotationUpdateEvent.REMOVE_ANNOTATION_FOCUS, removeFocus);
104
+ updateSubscriber.off(AnnotationUpdateEvent.SET_ANNOTATION_HOVERED, removeHoverEffect);
105
+ };
106
+ }
85
107
  }, [id, updateSubscriber]);
86
- return {
87
- hasFocus: hasFocus,
88
- isHovered: isHovered
89
- };
108
+ if (fg('platform_editor_comments_api_manager')) {
109
+ return {
110
+ hasFocus: currentSelectedAnnotationId === id,
111
+ isHovered: currentHoveredAnnotationId === id
112
+ };
113
+ } else {
114
+ return {
115
+ hasFocus: hasFocus,
116
+ isHovered: isHovered
117
+ };
118
+ }
90
119
  };
91
120
  export var useAnnotationClickEvent = function useAnnotationClickEvent(props) {
92
121
  var _useState7 = useState(null),
@@ -96,6 +125,21 @@ export var useAnnotationClickEvent = function useAnnotationClickEvent(props) {
96
125
  var updateSubscriber = props.updateSubscriber,
97
126
  createAnalyticsEvent = props.createAnalyticsEvent,
98
127
  isNestedRender = props.isNestedRender;
128
+ var _useAnnotationManager4 = useAnnotationManagerState(),
129
+ currentSelectedAnnotationId = _useAnnotationManager4.currentSelectedAnnotationId,
130
+ currentSelectedMarkRef = _useAnnotationManager4.currentSelectedMarkRef;
131
+ var selectedAnnotation = useMemo(function () {
132
+ return currentSelectedAnnotationId && currentSelectedMarkRef ? {
133
+ annotations: [{
134
+ id: currentSelectedAnnotationId,
135
+ type: AnnotationTypes.INLINE_COMMENT
136
+ }],
137
+ clickElementTarget: currentSelectedMarkRef
138
+ } : {
139
+ annotations: [],
140
+ clickElementTarget: undefined
141
+ };
142
+ }, [currentSelectedAnnotationId, currentSelectedMarkRef]);
99
143
  useLayoutEffect(function () {
100
144
  if (!updateSubscriber || isNestedRender) {
101
145
  return;
@@ -140,12 +184,18 @@ export var useAnnotationClickEvent = function useAnnotationClickEvent(props) {
140
184
  document.activeElement.blur();
141
185
  }
142
186
  };
143
- updateSubscriber.on(AnnotationUpdateEvent.ON_ANNOTATION_CLICK, clickCb);
144
- updateSubscriber.on(AnnotationUpdateEvent.DESELECT_ANNOTATIONS, deselectCb);
145
- return function () {
146
- updateSubscriber.off(AnnotationUpdateEvent.ON_ANNOTATION_CLICK, clickCb);
147
- updateSubscriber.off(AnnotationUpdateEvent.DESELECT_ANNOTATIONS, deselectCb);
148
- };
187
+ if (!fg('platform_editor_comments_api_manager')) {
188
+ updateSubscriber.on(AnnotationUpdateEvent.ON_ANNOTATION_CLICK, clickCb);
189
+ updateSubscriber.on(AnnotationUpdateEvent.DESELECT_ANNOTATIONS, deselectCb);
190
+ return function () {
191
+ updateSubscriber.off(AnnotationUpdateEvent.ON_ANNOTATION_CLICK, clickCb);
192
+ updateSubscriber.off(AnnotationUpdateEvent.DESELECT_ANNOTATIONS, deselectCb);
193
+ };
194
+ }
149
195
  }, [updateSubscriber, createAnalyticsEvent, isNestedRender]);
150
- return annotationClickEvent;
196
+ if (fg('platform_editor_comments_api_manager')) {
197
+ return selectedAnnotation;
198
+ } else {
199
+ return annotationClickEvent;
200
+ }
151
201
  };
@@ -6,12 +6,15 @@ import { AnnotationUpdateEvent } from '@atlaskit/editor-common/types';
6
6
  import { fg } from '@atlaskit/platform-feature-flags';
7
7
  import { ProvidersContext } from '../context';
8
8
  import { RendererContext as ActionsContext } from '../../RendererActionsContext';
9
+ import { useAnnotationManagerDispatch } from '../contexts/AnnotationManagerContext';
9
10
  export var useLoadAnnotations = function useLoadAnnotations(_ref) {
10
11
  var adfDocument = _ref.adfDocument,
11
12
  isNestedRender = _ref.isNestedRender,
12
13
  onLoadComplete = _ref.onLoadComplete;
13
14
  var actions = useContext(ActionsContext);
14
15
  var providers = useContext(ProvidersContext);
16
+ var _useAnnotationManager = useAnnotationManagerDispatch(),
17
+ dispatch = _useAnnotationManager.dispatch;
15
18
  useEffect(function () {
16
19
  if (!providers) {
17
20
  return;
@@ -41,7 +44,20 @@ export var useLoadAnnotations = function useLoadAnnotations(_ref) {
41
44
  var payload = data.reduce(function (acc, value) {
42
45
  return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, value.id, value));
43
46
  }, {});
44
- updateSubscriberInlineComment.emit(AnnotationUpdateEvent.SET_ANNOTATION_STATE, payload);
47
+ if (fg('platform_editor_comments_api_manager')) {
48
+ dispatch({
49
+ type: 'loadAnnotation',
50
+ data: Object.keys(payload).map(function (id) {
51
+ var _payload$id$state;
52
+ return {
53
+ id: id,
54
+ markState: (_payload$id$state = payload[id].state) !== null && _payload$id$state !== void 0 ? _payload$id$state : undefined
55
+ };
56
+ })
57
+ });
58
+ } else {
59
+ updateSubscriberInlineComment.emit(AnnotationUpdateEvent.SET_ANNOTATION_STATE, payload);
60
+ }
45
61
  onLoadComplete && onLoadComplete({
46
62
  numberOfUnresolvedInlineComments: data.filter(function (data) {
47
63
  return data.state === 'active';
@@ -49,5 +65,5 @@ export var useLoadAnnotations = function useLoadAnnotations(_ref) {
49
65
  });
50
66
  };
51
67
  inlineCommentGetState(ids, isNestedRender).then(cb);
52
- }, [actions, providers, adfDocument, isNestedRender, onLoadComplete]);
68
+ }, [actions, providers, adfDocument, isNestedRender, onLoadComplete, dispatch]);
53
69
  };
@@ -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
  var LoadAnnotations = /*#__PURE__*/React.memo(function (_ref) {
12
14
  var adfDocument = _ref.adfDocument,
13
15
  isNestedRender = _ref.isNestedRender,
@@ -27,27 +29,25 @@ var LoadAnnotations = /*#__PURE__*/React.memo(function (_ref) {
27
29
  export var AnnotationsPositionContext = /*#__PURE__*/React.createContext({
28
30
  startPos: 1
29
31
  });
30
- export var AnnotationsWrapper = function AnnotationsWrapper(props) {
31
- var _annotationProvider$i, _annotationProvider$i2;
32
+ export var AnnotationsWrapperInner = function AnnotationsWrapperInner(props) {
33
+ var _providers$inlineComm, _providers$inlineComm2;
32
34
  var children = props.children,
33
- annotationProvider = props.annotationProvider,
34
35
  rendererRef = props.rendererRef,
35
36
  adfDocument = props.adfDocument,
36
37
  isNestedRender = props.isNestedRender,
37
38
  onLoadComplete = props.onLoadComplete;
38
- var updateSubscriber = annotationProvider && annotationProvider.inlineComment && annotationProvider.inlineComment.updateSubscriber;
39
+ var providers = useContext(ProvidersContext);
40
+ var updateSubscriber = providers && providers.inlineComment && providers.inlineComment.updateSubscriber;
39
41
  var inlineCommentAnnotationsState = useAnnotationStateByTypeEvent({
40
42
  type: AnnotationTypes.INLINE_COMMENT,
41
43
  updateSubscriber: updateSubscriber || null
42
44
  });
43
45
  var _useAnalyticsEvents = useAnalyticsEvents(),
44
46
  createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
45
- return /*#__PURE__*/React.createElement(ProvidersContext.Provider, {
46
- value: annotationProvider
47
- }, /*#__PURE__*/React.createElement(InlineCommentsStateContext.Provider, {
47
+ return /*#__PURE__*/React.createElement(InlineCommentsStateContext.Provider, {
48
48
  value: inlineCommentAnnotationsState
49
49
  }, /*#__PURE__*/React.createElement(AnnotationRangeProvider, {
50
- allowCommentsOnMedia: (_annotationProvider$i = annotationProvider === null || annotationProvider === void 0 || (_annotationProvider$i2 = annotationProvider.inlineComment) === null || _annotationProvider$i2 === void 0 ? void 0 : _annotationProvider$i2.allowCommentsOnMedia) !== null && _annotationProvider$i !== void 0 ? _annotationProvider$i : false
50
+ allowCommentsOnMedia: (_providers$inlineComm = providers === null || providers === void 0 || (_providers$inlineComm2 = providers.inlineComment) === null || _providers$inlineComm2 === void 0 ? void 0 : _providers$inlineComm2.allowCommentsOnMedia) !== null && _providers$inlineComm !== void 0 ? _providers$inlineComm : false
51
51
  }, /*#__PURE__*/React.createElement(AnnotationHoverContext, null, /*#__PURE__*/React.createElement(AnnotationsContextWrapper, {
52
52
  createAnalyticsEvent: createAnalyticsEvent,
53
53
  rendererRef: rendererRef,
@@ -59,5 +59,40 @@ export var AnnotationsWrapper = function AnnotationsWrapper(props) {
59
59
  }), /*#__PURE__*/React.createElement(AnnotationView, {
60
60
  isNestedRender: isNestedRender,
61
61
  createAnalyticsEvent: createAnalyticsEvent
62
- }), children)))));
62
+ }), children))));
63
+ };
64
+ export var AnnotationsWrapper = function AnnotationsWrapper(props) {
65
+ var children = props.children,
66
+ annotationProvider = props.annotationProvider,
67
+ rendererRef = props.rendererRef,
68
+ adfDocument = props.adfDocument,
69
+ isNestedRender = props.isNestedRender,
70
+ onLoadComplete = props.onLoadComplete;
71
+ if (!isNestedRender && fg('platform_editor_comments_api_manager')) {
72
+ var _annotationProvider$i, _annotationProvider$i2;
73
+ // We need to ensure there is a single instance of the annotation manager for the whole document
74
+ // and that it is the same instance for all annotations.
75
+ // This is because the annotation manager is responsible for managing the state of ALL annotations.
76
+ // This includes annotations inside extensions.
77
+ return /*#__PURE__*/React.createElement(ProvidersContext.Provider, {
78
+ value: annotationProvider
79
+ }, /*#__PURE__*/React.createElement(AnnotationManagerProvider, {
80
+ annotationManager: annotationProvider === null || annotationProvider === void 0 ? void 0 : annotationProvider.annotationManager,
81
+ updateSubscriber: (_annotationProvider$i = annotationProvider === null || annotationProvider === void 0 || (_annotationProvider$i2 = annotationProvider.inlineComment) === null || _annotationProvider$i2 === void 0 ? void 0 : _annotationProvider$i2.updateSubscriber) !== null && _annotationProvider$i !== void 0 ? _annotationProvider$i : undefined
82
+ }, /*#__PURE__*/React.createElement(AnnotationsWrapperInner, {
83
+ rendererRef: rendererRef,
84
+ adfDocument: adfDocument,
85
+ isNestedRender: isNestedRender,
86
+ onLoadComplete: onLoadComplete
87
+ }, children)));
88
+ } else {
89
+ return /*#__PURE__*/React.createElement(ProvidersContext.Provider, {
90
+ value: annotationProvider
91
+ }, /*#__PURE__*/React.createElement(AnnotationsWrapperInner, {
92
+ rendererRef: rendererRef,
93
+ adfDocument: adfDocument,
94
+ isNestedRender: isNestedRender,
95
+ onLoadComplete: onLoadComplete
96
+ }, children));
97
+ }
63
98
  };
@@ -1,12 +1,14 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import React, { useCallback, useState, useContext, useMemo } from 'react';
3
- import { AnnotationTypes } from '@atlaskit/adf-schema';
2
+ import React, { useCallback, useState, useContext, useMemo, useEffect } from 'react';
3
+ import uuid from 'uuid/v4';
4
+ import { AnnotationTypes, AnnotationMarkStates } from '@atlaskit/adf-schema';
4
5
  import { fg } from '@atlaskit/platform-feature-flags';
5
6
  import { updateWindowSelectionAroundDraft } from '../draft/dom';
6
7
  import { FabricChannel } from '@atlaskit/analytics-listeners/types';
7
8
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
8
9
  import { getRendererRangeInlineNodeNames } from '../../../actions/get-renderer-range-inline-node-names';
9
10
  import { RendererContext as ActionsContext } from '../../RendererActionsContext';
11
+ import { useAnnotationManagerDispatch, useAnnotationManagerState } from '../contexts/AnnotationManagerContext';
10
12
  export var SelectionInlineCommentMounter = /*#__PURE__*/React.memo(function (props) {
11
13
  var Component = props.component,
12
14
  range = props.range,
@@ -25,6 +27,12 @@ export var SelectionInlineCommentMounter = /*#__PURE__*/React.memo(function (pro
25
27
  draftDocumentPosition = _useState2[0],
26
28
  setDraftDocumentPosition = _useState2[1];
27
29
  var actions = useContext(ActionsContext);
30
+ var _useAnnotationManager = useAnnotationManagerState(),
31
+ isDrafting = _useAnnotationManager.isDrafting,
32
+ draftId = _useAnnotationManager.draftId;
33
+ var _useAnnotationManager2 = useAnnotationManagerDispatch(),
34
+ annotationManager = _useAnnotationManager2.annotationManager,
35
+ dispatch = _useAnnotationManager2.dispatch;
28
36
  var inlineNodeTypes = useMemo(function () {
29
37
  if (fg('annotations_defensive_node_name_calculations')) {
30
38
  if (!actions.isRangeAnnotatable(range)) {
@@ -177,6 +185,171 @@ export var SelectionInlineCommentMounter = /*#__PURE__*/React.memo(function (pro
177
185
  removeDraftModeCallback();
178
186
  onCloseProps();
179
187
  }, [onCloseProps, removeDraftModeCallback, createAnalyticsEvent, inlineNodeTypes]);
188
+ useEffect(function () {
189
+ if (fg('platform_editor_comments_api_manager')) {
190
+ var allowAnnotation = function allowAnnotation() {
191
+ if (isDrafting) {
192
+ return false;
193
+ }
194
+ return isAnnotationAllowed;
195
+ };
196
+ annotationManager === null || annotationManager === void 0 || annotationManager.hook('allowAnnotation', allowAnnotation);
197
+ return function () {
198
+ annotationManager === null || annotationManager === void 0 || annotationManager.unhook('allowAnnotation', allowAnnotation);
199
+ };
200
+ }
201
+ }, [annotationManager, isAnnotationAllowed, isDrafting]);
202
+ useEffect(function () {
203
+ if (fg('platform_editor_comments_api_manager')) {
204
+ var startDraft = function 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
+ var id = uuid();
219
+ var 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 || annotationManager.hook('startDraft', startDraft);
259
+ return function () {
260
+ annotationManager === null || annotationManager === void 0 || annotationManager.unhook('startDraft', startDraft);
261
+ };
262
+ }
263
+ }, [annotationManager, isDrafting, applyDraftModeCallback, actions, range, dispatch]);
264
+ useEffect(function () {
265
+ if (fg('platform_editor_comments_api_manager')) {
266
+ var clearDraft = function 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 || annotationManager.hook('clearDraft', clearDraft);
287
+ return function () {
288
+ annotationManager === null || annotationManager === void 0 || annotationManager.unhook('clearDraft', clearDraft);
289
+ };
290
+ }
291
+ }, [annotationManager, onCloseCallback, isDrafting, dispatch]);
292
+ useEffect(function () {
293
+ if (fg('platform_editor_comments_api_manager')) {
294
+ var applyDraft = function applyDraft(id) {
295
+ if (!isDrafting || !draftId) {
296
+ return {
297
+ success: false,
298
+ reason: 'draft-not-started'
299
+ };
300
+ }
301
+ var 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: 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 || annotationManager.hook('applyDraft', applyDraft);
341
+ return function () {
342
+ annotationManager === null || annotationManager === 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
+ var nop = useMemo(function () {
349
+ return function () {
350
+ return false;
351
+ };
352
+ }, []);
180
353
  return /*#__PURE__*/React.createElement(Component, {
181
354
  range: range,
182
355
  draftRange: draftRange
@@ -185,11 +358,11 @@ export var SelectionInlineCommentMounter = /*#__PURE__*/React.memo(function (pro
185
358
  ,
186
359
  wrapperDOM: wrapperDOM.current,
187
360
  isAnnotationAllowed: isAnnotationAllowed,
188
- onClose: onCloseCallback,
189
- onCreate: onCreateCallback,
361
+ onClose: fg('platform_editor_comments_api_manager') ? nop : onCloseCallback,
362
+ onCreate: fg('platform_editor_comments_api_manager') ? nop : onCreateCallback,
190
363
  getAnnotationIndexMatch: createIndexCallback,
191
- applyDraftMode: applyDraftModeCallback,
192
- removeDraftMode: removeDraftModeCallback,
364
+ applyDraftMode: fg('platform_editor_comments_api_manager') ? nop : applyDraftModeCallback,
365
+ removeDraftMode: fg('platform_editor_comments_api_manager') ? nop : removeDraftModeCallback,
193
366
  inlineNodeTypes: inlineNodeTypes
194
367
  });
195
368
  });
@@ -0,0 +1,71 @@
1
+ import React, { type ReactNode } from 'react';
2
+ import { type AnnotationId, AnnotationMarkStates } from '@atlaskit/adf-schema';
3
+ import type { AnnotationManager, ActionResult } from '@atlaskit/editor-common/annotation';
4
+ import { AnnotationUpdateEmitter } from '@atlaskit/editor-common/types';
5
+ interface AnnotationState {
6
+ id: AnnotationId;
7
+ markState: AnnotationMarkStates;
8
+ }
9
+ type AnnotationsStateRecord = Record<AnnotationId, AnnotationState>;
10
+ interface AnnotationManagerStateContext {
11
+ isDrafting: boolean;
12
+ draftId: string | undefined;
13
+ draftMarkRef: HTMLElement | undefined;
14
+ draftActionResult: ActionResult | undefined;
15
+ annotations: AnnotationsStateRecord;
16
+ currentSelectedAnnotationId: AnnotationId | undefined;
17
+ currentSelectedMarkRef: HTMLElement | undefined;
18
+ currentHoveredAnnotationId: AnnotationId | undefined;
19
+ }
20
+ interface AnnotationManagerDispatchContext {
21
+ annotationManager: AnnotationManager | undefined;
22
+ dispatch: React.Dispatch<AnnotationManagerAction>;
23
+ }
24
+ declare const AnnotationManagerStateContext: React.Context<AnnotationManagerStateContext>;
25
+ declare const AnnotationManagerDispatchContext: React.Context<AnnotationManagerDispatchContext>;
26
+ type AnnotationManagerAction = {
27
+ type: 'reset';
28
+ } | {
29
+ type: 'loadAnnotation';
30
+ data: {
31
+ id: AnnotationId;
32
+ markState?: AnnotationMarkStates;
33
+ }[];
34
+ } | {
35
+ type: 'updateAnnotation';
36
+ data: {
37
+ id: AnnotationId;
38
+ selected?: boolean;
39
+ hovered?: boolean;
40
+ markState?: AnnotationMarkStates;
41
+ };
42
+ } | {
43
+ type: 'resetSelectedAnnotation';
44
+ } | {
45
+ type: 'resetHoveredAnnotation';
46
+ } | {
47
+ type: 'setDrafting';
48
+ data: {
49
+ isDrafting: boolean;
50
+ draftId: string | undefined;
51
+ draftActionResult: ActionResult | undefined;
52
+ };
53
+ } | {
54
+ type: 'setDraftMarkRef';
55
+ data: {
56
+ draftMarkRef: HTMLElement | undefined;
57
+ };
58
+ } | {
59
+ type: 'setSelectedMarkRef';
60
+ data: {
61
+ markRef: HTMLElement | undefined;
62
+ };
63
+ };
64
+ export declare const AnnotationManagerProvider: ({ children, annotationManager, updateSubscriber, }: {
65
+ children?: ReactNode;
66
+ annotationManager?: AnnotationManager | undefined;
67
+ updateSubscriber?: AnnotationUpdateEmitter | undefined;
68
+ }) => React.JSX.Element;
69
+ export declare const useAnnotationManagerState: () => AnnotationManagerStateContext;
70
+ export declare const useAnnotationManagerDispatch: () => AnnotationManagerDispatchContext;
71
+ export {};
@@ -1,8 +1,12 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
1
5
  import React from 'react';
2
6
  import { jsx } from '@emotion/react';
7
+ import type { Mark } from '@atlaskit/editor-prosemirror/model';
3
8
  import type { Position } from '../types';
4
9
  import { InsertDraftPosition } from '../types';
5
- import type { Mark } from '@atlaskit/editor-prosemirror/model';
6
10
  import type { TextHighlighter } from '../../../react/types';
7
11
  export declare const AnnotationDraft: ({ draftPosition, children, }: React.PropsWithChildren<{
8
12
  draftPosition: Position;
@@ -27,6 +27,7 @@ export declare const MarkComponent: ({ annotationParentIds, children, dataAttrib
27
27
  'data-id': string;
28
28
  'data-mark-annotation-state'?: AnnotationMarkStates | undefined;
29
29
  'aria-disabled': boolean;
30
+ ref: ((node: HTMLElement | null) => void) | undefined;
30
31
  id: string;
31
32
  } | {
32
33
  css?: (false | import("@emotion/react").SerializedStyles)[] | undefined;
@@ -41,6 +42,7 @@ export declare const MarkComponent: ({ annotationParentIds, children, dataAttrib
41
42
  'data-mark-annotation-type': import("@atlaskit/adf-schema").AnnotationTypes;
42
43
  'data-id': string;
43
44
  'aria-disabled': boolean;
45
+ ref: ((node: HTMLElement | null) => void) | undefined;
44
46
  id: string;
45
47
  } | {
46
48
  css?: (false | import("@emotion/react").SerializedStyles)[] | undefined;
@@ -58,6 +60,7 @@ export declare const MarkComponent: ({ annotationParentIds, children, dataAttrib
58
60
  'aria-expanded'?: undefined;
59
61
  'aria-details': string;
60
62
  'aria-disabled'?: undefined;
63
+ ref: ((node: HTMLElement | null) => void) | undefined;
61
64
  id: string;
62
65
  } | {
63
66
  css?: (false | import("@emotion/react").SerializedStyles)[] | undefined;
@@ -77,6 +80,7 @@ export declare const MarkComponent: ({ annotationParentIds, children, dataAttrib
77
80
  'aria-expanded'?: undefined;
78
81
  'aria-details': string;
79
82
  'aria-disabled'?: undefined;
83
+ ref: ((node: HTMLElement | null) => void) | undefined;
80
84
  id: string;
81
85
  } | {
82
86
  css?: (false | import("@emotion/react").SerializedStyles)[] | undefined;
@@ -94,6 +98,7 @@ export declare const MarkComponent: ({ annotationParentIds, children, dataAttrib
94
98
  'aria-expanded': boolean;
95
99
  'aria-details': string;
96
100
  'aria-disabled'?: undefined;
101
+ ref: ((node: HTMLElement | null) => void) | undefined;
97
102
  id: string;
98
103
  } | {
99
104
  css?: (false | import("@emotion/react").SerializedStyles)[] | undefined;
@@ -113,6 +118,7 @@ export declare const MarkComponent: ({ annotationParentIds, children, dataAttrib
113
118
  'aria-expanded': boolean;
114
119
  'aria-details': string;
115
120
  'aria-disabled'?: undefined;
121
+ ref: ((node: HTMLElement | null) => void) | undefined;
116
122
  id: string;
117
123
  }, string | React.JSXElementConstructor<any>>;
118
124
  export {};
@@ -3,4 +3,5 @@ import { type AnnotationsWrapperProps } from './types';
3
3
  export declare const AnnotationsPositionContext: React.Context<{
4
4
  startPos: number;
5
5
  }>;
6
+ export declare const AnnotationsWrapperInner: (props: Omit<AnnotationsWrapperProps, 'annotationProvider'>) => React.JSX.Element;
6
7
  export declare const AnnotationsWrapper: (props: AnnotationsWrapperProps) => React.JSX.Element;