@atlaskit/renderer 153.4.7 → 153.5.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,21 @@
1
1
  # @atlaskit/renderer
2
2
 
3
+ ## 153.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`2bf9b457b16ce`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2bf9b457b16ce) -
8
+ Track the range a draft targets explicitly in `AnnotationRangeContext`, behind
9
+ `platform_editor_comments_api_manager`. The selection and hover mounters can render at the same
10
+ time and the ambient `range` flips between them, so a draft could be built against whichever
11
+ surface updated last. The context now holds a `DraftTarget` per surface plus the surface the user
12
+ engaged (`draftIntentSource`), and the selection mounter publishes its target while it is mounted
13
+ and drops it when the selection is cleared. Nothing reads these yet, so behaviour is unchanged.
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies
18
+
3
19
  ## 153.4.7
4
20
 
5
21
  ### Patch Changes
@@ -79,7 +79,7 @@ var DEGRADED_SEVERITY_THRESHOLD = exports.DEGRADED_SEVERITY_THRESHOLD = 3000;
79
79
  var TABLE_INFO_TIMEOUT = 10000;
80
80
  var RENDER_EVENT_SAMPLE_RATE = 0.1;
81
81
  var packageName = "@atlaskit/renderer";
82
- var packageVersion = "153.4.6";
82
+ var packageVersion = "153.4.7";
83
83
  var setAsQueryContainerStyles = (0, _react2.css)({
84
84
  containerName: 'ak-renderer-wrapper',
85
85
  containerType: 'inline-size'
@@ -13,6 +13,11 @@ var _fg = require("@atlaskit/platform-feature-flags/fg");
13
13
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
14
14
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
15
15
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16
+ /**
17
+ * The range a draft should act on, published by the selection/hover mounters so the manager can
18
+ * resolve its target without reading the ambient `range`, which flips between selection and hover.
19
+ */
20
+
16
21
  // oxlint-disable-next-line eslint/no-redeclare
17
22
 
18
23
  // oxlint-disable-next-line eslint/no-redeclare
@@ -24,7 +29,10 @@ var initialState = {
24
29
  selectionDraftRange: null,
25
30
  hoverDraftRange: null,
26
31
  selectionDraftDocumentPosition: null,
27
- hoverDraftDocumentPosition: null
32
+ hoverDraftDocumentPosition: null,
33
+ draftIntentSource: null,
34
+ selectionDraftTarget: null,
35
+ hoverDraftTarget: null
28
36
  };
29
37
  function reducer(state, action) {
30
38
  switch (action.type) {
@@ -101,6 +109,27 @@ function reducer(state, action) {
101
109
  });
102
110
  }
103
111
  return state;
112
+ case 'setDraftIntentSource':
113
+ if (state.draftIntentSource !== action.source) {
114
+ return _objectSpread(_objectSpread({}, state), {}, {
115
+ draftIntentSource: action.source
116
+ });
117
+ }
118
+ return state;
119
+ case 'setSelectionDraftTarget':
120
+ if (state.selectionDraftTarget !== action.target) {
121
+ return _objectSpread(_objectSpread({}, state), {}, {
122
+ selectionDraftTarget: action.target
123
+ });
124
+ }
125
+ return state;
126
+ case 'setHoverDraftTarget':
127
+ if (state.hoverDraftTarget !== action.target) {
128
+ return _objectSpread(_objectSpread({}, state), {}, {
129
+ hoverDraftTarget: action.target
130
+ });
131
+ }
132
+ return state;
104
133
  }
105
134
  }
106
135
  var AnnotationRangeStateContext = exports.AnnotationRangeStateContext = /*#__PURE__*/(0, _react.createContext)({
@@ -109,7 +138,10 @@ var AnnotationRangeStateContext = exports.AnnotationRangeStateContext = /*#__PUR
109
138
  selectionDraftRange: null,
110
139
  hoverDraftRange: null,
111
140
  selectionDraftDocumentPosition: null,
112
- hoverDraftDocumentPosition: null
141
+ hoverDraftDocumentPosition: null,
142
+ draftIntentSource: null,
143
+ selectionDraftTarget: null,
144
+ hoverDraftTarget: null
113
145
  });
114
146
  var AnnotationRangeDispatchContext = exports.AnnotationRangeDispatchContext = /*#__PURE__*/(0, _react.createContext)({
115
147
  clearSelectionRange: function clearSelectionRange() {},
@@ -118,7 +150,10 @@ var AnnotationRangeDispatchContext = exports.AnnotationRangeDispatchContext = /*
118
150
  promoteSelectionToDraft: function promoteSelectionToDraft() {},
119
151
  promoteHoverToDraft: function promoteHoverToDraft() {},
120
152
  clearSelectionDraft: function clearSelectionDraft() {},
121
- clearHoverDraft: function clearHoverDraft() {}
153
+ clearHoverDraft: function clearHoverDraft() {},
154
+ setDraftIntentSource: function setDraftIntentSource() {},
155
+ setSelectionDraftTarget: function setSelectionDraftTarget() {},
156
+ setHoverDraftTarget: function setHoverDraftTarget() {}
122
157
  });
123
158
  var AnnotationRangeProviderInner = exports.AnnotationRangeProviderInner = function AnnotationRangeProviderInner(_ref) {
124
159
  var children = _ref.children,
@@ -135,6 +170,9 @@ var AnnotationRangeProviderInner = exports.AnnotationRangeProviderInner = functi
135
170
  selectionDraftDocumentPosition = _useReducer2$.selectionDraftDocumentPosition,
136
171
  hoverDraftRange = _useReducer2$.hoverDraftRange,
137
172
  hoverDraftDocumentPosition = _useReducer2$.hoverDraftDocumentPosition,
173
+ draftIntentSource = _useReducer2$.draftIntentSource,
174
+ selectionDraftTarget = _useReducer2$.selectionDraftTarget,
175
+ hoverDraftTarget = _useReducer2$.hoverDraftTarget,
138
176
  dispatch = _useReducer2[1];
139
177
  var clearSelectionRange = (0, _react.useCallback)(function () {
140
178
  return dispatch({
@@ -202,6 +240,24 @@ var AnnotationRangeProviderInner = exports.AnnotationRangeProviderInner = functi
202
240
  type: 'clearHoverDraft'
203
241
  });
204
242
  }, []);
243
+ var setDraftIntentSource = (0, _react.useCallback)(function (source) {
244
+ dispatch({
245
+ type: 'setDraftIntentSource',
246
+ source: source
247
+ });
248
+ }, []);
249
+ var setSelectionDraftTarget = (0, _react.useCallback)(function (target) {
250
+ dispatch({
251
+ type: 'setSelectionDraftTarget',
252
+ target: target
253
+ });
254
+ }, []);
255
+ var setHoverDraftTarget = (0, _react.useCallback)(function (target) {
256
+ dispatch({
257
+ type: 'setHoverDraftTarget',
258
+ target: target
259
+ });
260
+ }, []);
205
261
  var stateData = (0, _react.useMemo)(function () {
206
262
  return {
207
263
  // We techinically have two ranges, however we only want to expose one of them at a time, because only one draft
@@ -211,9 +267,12 @@ var AnnotationRangeProviderInner = exports.AnnotationRangeProviderInner = functi
211
267
  selectionDraftRange: selectionDraftRange,
212
268
  hoverDraftRange: hoverDraftRange,
213
269
  selectionDraftDocumentPosition: selectionDraftDocumentPosition,
214
- hoverDraftDocumentPosition: hoverDraftDocumentPosition
270
+ hoverDraftDocumentPosition: hoverDraftDocumentPosition,
271
+ draftIntentSource: draftIntentSource,
272
+ selectionDraftTarget: selectionDraftTarget,
273
+ hoverDraftTarget: hoverDraftTarget
215
274
  };
216
- }, [selectionRange, hoverRange, type, selectionDraftRange, selectionDraftDocumentPosition, hoverDraftRange, hoverDraftDocumentPosition]);
275
+ }, [selectionRange, hoverRange, type, selectionDraftRange, selectionDraftDocumentPosition, hoverDraftRange, hoverDraftDocumentPosition, draftIntentSource, selectionDraftTarget, hoverDraftTarget]);
217
276
  var dispatchData = (0, _react.useMemo)(function () {
218
277
  return {
219
278
  clearSelectionRange: clearSelectionRange,
@@ -223,9 +282,12 @@ var AnnotationRangeProviderInner = exports.AnnotationRangeProviderInner = functi
223
282
  promoteSelectionToDraft: promoteSelectionToDraft,
224
283
  promoteHoverToDraft: promoteHoverToDraft,
225
284
  clearSelectionDraft: clearSelectionDraft,
226
- clearHoverDraft: clearHoverDraft
285
+ clearHoverDraft: clearHoverDraft,
286
+ setDraftIntentSource: setDraftIntentSource,
287
+ setSelectionDraftTarget: setSelectionDraftTarget,
288
+ setHoverDraftTarget: setHoverDraftTarget
227
289
  };
228
- }, [allowCommentsOnMedia, extensionCommentsEnabled, clearSelectionRange, clearHoverRange, setSelectionRange, setHoverTarget, promoteSelectionToDraft, promoteHoverToDraft, clearSelectionDraft, clearHoverDraft]);
290
+ }, [allowCommentsOnMedia, extensionCommentsEnabled, clearSelectionRange, clearHoverRange, setSelectionRange, setHoverTarget, promoteSelectionToDraft, promoteHoverToDraft, clearSelectionDraft, clearHoverDraft, setDraftIntentSource, setSelectionDraftTarget, setHoverDraftTarget]);
229
291
  return /*#__PURE__*/_react.default.createElement(AnnotationRangeStateContext.Provider, {
230
292
  value: stateData
231
293
  }, /*#__PURE__*/_react.default.createElement(AnnotationRangeDispatchContext.Provider, {
@@ -33,7 +33,9 @@ var SelectionInlineCommentMounter = exports.SelectionInlineCommentMounter = /*#_
33
33
  generateIndexMatch = props.generateIndexMatch;
34
34
  var _useAnnotationRangeDi = (0, _AnnotationRangeContext.useAnnotationRangeDispatch)(),
35
35
  promoteSelectionToDraft = _useAnnotationRangeDi.promoteSelectionToDraft,
36
- clearSelectionDraft = _useAnnotationRangeDi.clearSelectionDraft;
36
+ clearSelectionDraft = _useAnnotationRangeDi.clearSelectionDraft,
37
+ setSelectionDraftTarget = _useAnnotationRangeDi.setSelectionDraftTarget,
38
+ setDraftIntentSource = _useAnnotationRangeDi.setDraftIntentSource;
37
39
  var _useAnnotationRangeSt = (0, _AnnotationRangeContext.useAnnotationRangeState)(),
38
40
  selectionDraftDocumentPosition = _useAnnotationRangeSt.selectionDraftDocumentPosition;
39
41
  var actions = (0, _react.useContext)(_RendererActionsContext.RendererContext);
@@ -188,6 +190,34 @@ var SelectionInlineCommentMounter = exports.SelectionInlineCommentMounter = /*#_
188
190
  removeDraftModeCallback();
189
191
  onCloseProps();
190
192
  }, [onCloseProps, removeDraftModeCallback, createAnalyticsEvent, inlineNodeTypes]);
193
+
194
+ // Publish the range this mounter owns, so a draft can be resolved against the surface the user
195
+ // engaged rather than the ambient range, which flips between selection and hover. During a draft
196
+ // the selection range has been promoted away, and skipping the publish then keeps the target a
197
+ // draft captured.
198
+ (0, _react.useEffect)(function () {
199
+ if (!annotationManager || !range) {
200
+ return;
201
+ }
202
+ setSelectionDraftTarget({
203
+ range: range,
204
+ documentPosition: documentPosition,
205
+ isAnnotationAllowed: isAnnotationAllowed,
206
+ source: 'selection'
207
+ });
208
+ setDraftIntentSource('selection');
209
+ }, [annotationManager, range, documentPosition, isAnnotationAllowed, setSelectionDraftTarget, setDraftIntentSource]);
210
+
211
+ // Unmounting means the selection was cleared, so drop the published target.
212
+ (0, _react.useEffect)(function () {
213
+ return function () {
214
+ if (annotationManager) {
215
+ setSelectionDraftTarget(null);
216
+ }
217
+ };
218
+ // Cleanup on unmount only; both dependencies are stable for this component's lifetime.
219
+ // eslint-disable-next-line react-hooks/exhaustive-deps
220
+ }, []);
191
221
  (0, _react.useEffect)(function () {
192
222
  if (annotationManager) {
193
223
  var allowAnnotation = function allowAnnotation() {
@@ -64,7 +64,7 @@ export const DEGRADED_SEVERITY_THRESHOLD = 3000;
64
64
  const TABLE_INFO_TIMEOUT = 10000;
65
65
  const RENDER_EVENT_SAMPLE_RATE = 0.1;
66
66
  const packageName = "@atlaskit/renderer";
67
- const packageVersion = "153.4.6";
67
+ const packageVersion = "153.4.7";
68
68
  const setAsQueryContainerStyles = css({
69
69
  containerName: 'ak-renderer-wrapper',
70
70
  containerType: 'inline-size'
@@ -1,6 +1,11 @@
1
1
  import React, { createContext, useCallback, useContext, useMemo, useReducer, useRef } from 'react';
2
2
  import { fg } from '@atlaskit/platform-feature-flags/fg';
3
3
 
4
+ /**
5
+ * The range a draft should act on, published by the selection/hover mounters so the manager can
6
+ * resolve its target without reading the ambient `range`, which flips between selection and hover.
7
+ */
8
+
4
9
  // oxlint-disable-next-line eslint/no-redeclare
5
10
 
6
11
  // oxlint-disable-next-line eslint/no-redeclare
@@ -12,7 +17,10 @@ const initialState = {
12
17
  selectionDraftRange: null,
13
18
  hoverDraftRange: null,
14
19
  selectionDraftDocumentPosition: null,
15
- hoverDraftDocumentPosition: null
20
+ hoverDraftDocumentPosition: null,
21
+ draftIntentSource: null,
22
+ selectionDraftTarget: null,
23
+ hoverDraftTarget: null
16
24
  };
17
25
  function reducer(state, action) {
18
26
  switch (action.type) {
@@ -97,6 +105,30 @@ function reducer(state, action) {
97
105
  };
98
106
  }
99
107
  return state;
108
+ case 'setDraftIntentSource':
109
+ if (state.draftIntentSource !== action.source) {
110
+ return {
111
+ ...state,
112
+ draftIntentSource: action.source
113
+ };
114
+ }
115
+ return state;
116
+ case 'setSelectionDraftTarget':
117
+ if (state.selectionDraftTarget !== action.target) {
118
+ return {
119
+ ...state,
120
+ selectionDraftTarget: action.target
121
+ };
122
+ }
123
+ return state;
124
+ case 'setHoverDraftTarget':
125
+ if (state.hoverDraftTarget !== action.target) {
126
+ return {
127
+ ...state,
128
+ hoverDraftTarget: action.target
129
+ };
130
+ }
131
+ return state;
100
132
  }
101
133
  }
102
134
  export const AnnotationRangeStateContext = /*#__PURE__*/createContext({
@@ -105,7 +137,10 @@ export const AnnotationRangeStateContext = /*#__PURE__*/createContext({
105
137
  selectionDraftRange: null,
106
138
  hoverDraftRange: null,
107
139
  selectionDraftDocumentPosition: null,
108
- hoverDraftDocumentPosition: null
140
+ hoverDraftDocumentPosition: null,
141
+ draftIntentSource: null,
142
+ selectionDraftTarget: null,
143
+ hoverDraftTarget: null
109
144
  });
110
145
  export const AnnotationRangeDispatchContext = /*#__PURE__*/createContext({
111
146
  clearSelectionRange: () => {},
@@ -114,7 +149,10 @@ export const AnnotationRangeDispatchContext = /*#__PURE__*/createContext({
114
149
  promoteSelectionToDraft: () => {},
115
150
  promoteHoverToDraft: () => {},
116
151
  clearSelectionDraft: () => {},
117
- clearHoverDraft: () => {}
152
+ clearHoverDraft: () => {},
153
+ setDraftIntentSource: () => {},
154
+ setSelectionDraftTarget: () => {},
155
+ setHoverDraftTarget: () => {}
118
156
  });
119
157
  export const AnnotationRangeProviderInner = ({
120
158
  children,
@@ -129,7 +167,10 @@ export const AnnotationRangeProviderInner = ({
129
167
  selectionDraftRange,
130
168
  selectionDraftDocumentPosition,
131
169
  hoverDraftRange,
132
- hoverDraftDocumentPosition
170
+ hoverDraftDocumentPosition,
171
+ draftIntentSource,
172
+ selectionDraftTarget,
173
+ hoverDraftTarget
133
174
  }, dispatch] = useReducer(reducer, initialState);
134
175
  const clearSelectionRange = useCallback(() => dispatch({
135
176
  type: 'clearSelection'
@@ -189,6 +230,24 @@ export const AnnotationRangeProviderInner = ({
189
230
  type: 'clearHoverDraft'
190
231
  });
191
232
  }, []);
233
+ const setDraftIntentSource = useCallback(source => {
234
+ dispatch({
235
+ type: 'setDraftIntentSource',
236
+ source
237
+ });
238
+ }, []);
239
+ const setSelectionDraftTarget = useCallback(target => {
240
+ dispatch({
241
+ type: 'setSelectionDraftTarget',
242
+ target
243
+ });
244
+ }, []);
245
+ const setHoverDraftTarget = useCallback(target => {
246
+ dispatch({
247
+ type: 'setHoverDraftTarget',
248
+ target
249
+ });
250
+ }, []);
192
251
  const stateData = useMemo(() => {
193
252
  return {
194
253
  // We techinically have two ranges, however we only want to expose one of them at a time, because only one draft
@@ -198,9 +257,12 @@ export const AnnotationRangeProviderInner = ({
198
257
  selectionDraftRange,
199
258
  hoverDraftRange,
200
259
  selectionDraftDocumentPosition,
201
- hoverDraftDocumentPosition
260
+ hoverDraftDocumentPosition,
261
+ draftIntentSource,
262
+ selectionDraftTarget,
263
+ hoverDraftTarget
202
264
  };
203
- }, [selectionRange, hoverRange, type, selectionDraftRange, selectionDraftDocumentPosition, hoverDraftRange, hoverDraftDocumentPosition]);
265
+ }, [selectionRange, hoverRange, type, selectionDraftRange, selectionDraftDocumentPosition, hoverDraftRange, hoverDraftDocumentPosition, draftIntentSource, selectionDraftTarget, hoverDraftTarget]);
204
266
  const dispatchData = useMemo(() => ({
205
267
  clearSelectionRange,
206
268
  clearHoverRange,
@@ -209,8 +271,11 @@ export const AnnotationRangeProviderInner = ({
209
271
  promoteSelectionToDraft,
210
272
  promoteHoverToDraft,
211
273
  clearSelectionDraft,
212
- clearHoverDraft
213
- }), [allowCommentsOnMedia, extensionCommentsEnabled, clearSelectionRange, clearHoverRange, setSelectionRange, setHoverTarget, promoteSelectionToDraft, promoteHoverToDraft, clearSelectionDraft, clearHoverDraft]);
274
+ clearHoverDraft,
275
+ setDraftIntentSource,
276
+ setSelectionDraftTarget,
277
+ setHoverDraftTarget
278
+ }), [allowCommentsOnMedia, extensionCommentsEnabled, clearSelectionRange, clearHoverRange, setSelectionRange, setHoverTarget, promoteSelectionToDraft, promoteHoverToDraft, clearSelectionDraft, clearHoverDraft, setDraftIntentSource, setSelectionDraftTarget, setHoverDraftTarget]);
214
279
  return /*#__PURE__*/React.createElement(AnnotationRangeStateContext.Provider, {
215
280
  value: stateData
216
281
  }, /*#__PURE__*/React.createElement(AnnotationRangeDispatchContext.Provider, {
@@ -27,7 +27,9 @@ export const SelectionInlineCommentMounter = /*#__PURE__*/React.memo(props => {
27
27
  } = props;
28
28
  const {
29
29
  promoteSelectionToDraft,
30
- clearSelectionDraft
30
+ clearSelectionDraft,
31
+ setSelectionDraftTarget,
32
+ setDraftIntentSource
31
33
  } = useAnnotationRangeDispatch();
32
34
  const {
33
35
  selectionDraftDocumentPosition
@@ -186,6 +188,34 @@ export const SelectionInlineCommentMounter = /*#__PURE__*/React.memo(props => {
186
188
  removeDraftModeCallback();
187
189
  onCloseProps();
188
190
  }, [onCloseProps, removeDraftModeCallback, createAnalyticsEvent, inlineNodeTypes]);
191
+
192
+ // Publish the range this mounter owns, so a draft can be resolved against the surface the user
193
+ // engaged rather than the ambient range, which flips between selection and hover. During a draft
194
+ // the selection range has been promoted away, and skipping the publish then keeps the target a
195
+ // draft captured.
196
+ useEffect(() => {
197
+ if (!annotationManager || !range) {
198
+ return;
199
+ }
200
+ setSelectionDraftTarget({
201
+ range,
202
+ documentPosition,
203
+ isAnnotationAllowed,
204
+ source: 'selection'
205
+ });
206
+ setDraftIntentSource('selection');
207
+ }, [annotationManager, range, documentPosition, isAnnotationAllowed, setSelectionDraftTarget, setDraftIntentSource]);
208
+
209
+ // Unmounting means the selection was cleared, so drop the published target.
210
+ useEffect(() => {
211
+ return () => {
212
+ if (annotationManager) {
213
+ setSelectionDraftTarget(null);
214
+ }
215
+ };
216
+ // Cleanup on unmount only; both dependencies are stable for this component's lifetime.
217
+ // eslint-disable-next-line react-hooks/exhaustive-deps
218
+ }, []);
189
219
  useEffect(() => {
190
220
  if (annotationManager) {
191
221
  const allowAnnotation = () => {
@@ -69,7 +69,7 @@ export var DEGRADED_SEVERITY_THRESHOLD = 3000;
69
69
  var TABLE_INFO_TIMEOUT = 10000;
70
70
  var RENDER_EVENT_SAMPLE_RATE = 0.1;
71
71
  var packageName = "@atlaskit/renderer";
72
- var packageVersion = "153.4.6";
72
+ var packageVersion = "153.4.7";
73
73
  var setAsQueryContainerStyles = css({
74
74
  containerName: 'ak-renderer-wrapper',
75
75
  containerType: 'inline-size'
@@ -5,6 +5,11 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
5
5
  import React, { createContext, useCallback, useContext, useMemo, useReducer, useRef } from 'react';
6
6
  import { fg } from '@atlaskit/platform-feature-flags/fg';
7
7
 
8
+ /**
9
+ * The range a draft should act on, published by the selection/hover mounters so the manager can
10
+ * resolve its target without reading the ambient `range`, which flips between selection and hover.
11
+ */
12
+
8
13
  // oxlint-disable-next-line eslint/no-redeclare
9
14
 
10
15
  // oxlint-disable-next-line eslint/no-redeclare
@@ -16,7 +21,10 @@ var initialState = {
16
21
  selectionDraftRange: null,
17
22
  hoverDraftRange: null,
18
23
  selectionDraftDocumentPosition: null,
19
- hoverDraftDocumentPosition: null
24
+ hoverDraftDocumentPosition: null,
25
+ draftIntentSource: null,
26
+ selectionDraftTarget: null,
27
+ hoverDraftTarget: null
20
28
  };
21
29
  function reducer(state, action) {
22
30
  switch (action.type) {
@@ -93,6 +101,27 @@ function reducer(state, action) {
93
101
  });
94
102
  }
95
103
  return state;
104
+ case 'setDraftIntentSource':
105
+ if (state.draftIntentSource !== action.source) {
106
+ return _objectSpread(_objectSpread({}, state), {}, {
107
+ draftIntentSource: action.source
108
+ });
109
+ }
110
+ return state;
111
+ case 'setSelectionDraftTarget':
112
+ if (state.selectionDraftTarget !== action.target) {
113
+ return _objectSpread(_objectSpread({}, state), {}, {
114
+ selectionDraftTarget: action.target
115
+ });
116
+ }
117
+ return state;
118
+ case 'setHoverDraftTarget':
119
+ if (state.hoverDraftTarget !== action.target) {
120
+ return _objectSpread(_objectSpread({}, state), {}, {
121
+ hoverDraftTarget: action.target
122
+ });
123
+ }
124
+ return state;
96
125
  }
97
126
  }
98
127
  export var AnnotationRangeStateContext = /*#__PURE__*/createContext({
@@ -101,7 +130,10 @@ export var AnnotationRangeStateContext = /*#__PURE__*/createContext({
101
130
  selectionDraftRange: null,
102
131
  hoverDraftRange: null,
103
132
  selectionDraftDocumentPosition: null,
104
- hoverDraftDocumentPosition: null
133
+ hoverDraftDocumentPosition: null,
134
+ draftIntentSource: null,
135
+ selectionDraftTarget: null,
136
+ hoverDraftTarget: null
105
137
  });
106
138
  export var AnnotationRangeDispatchContext = /*#__PURE__*/createContext({
107
139
  clearSelectionRange: function clearSelectionRange() {},
@@ -110,7 +142,10 @@ export var AnnotationRangeDispatchContext = /*#__PURE__*/createContext({
110
142
  promoteSelectionToDraft: function promoteSelectionToDraft() {},
111
143
  promoteHoverToDraft: function promoteHoverToDraft() {},
112
144
  clearSelectionDraft: function clearSelectionDraft() {},
113
- clearHoverDraft: function clearHoverDraft() {}
145
+ clearHoverDraft: function clearHoverDraft() {},
146
+ setDraftIntentSource: function setDraftIntentSource() {},
147
+ setSelectionDraftTarget: function setSelectionDraftTarget() {},
148
+ setHoverDraftTarget: function setHoverDraftTarget() {}
114
149
  });
115
150
  export var AnnotationRangeProviderInner = function AnnotationRangeProviderInner(_ref) {
116
151
  var children = _ref.children,
@@ -127,6 +162,9 @@ export var AnnotationRangeProviderInner = function AnnotationRangeProviderInner(
127
162
  selectionDraftDocumentPosition = _useReducer2$.selectionDraftDocumentPosition,
128
163
  hoverDraftRange = _useReducer2$.hoverDraftRange,
129
164
  hoverDraftDocumentPosition = _useReducer2$.hoverDraftDocumentPosition,
165
+ draftIntentSource = _useReducer2$.draftIntentSource,
166
+ selectionDraftTarget = _useReducer2$.selectionDraftTarget,
167
+ hoverDraftTarget = _useReducer2$.hoverDraftTarget,
130
168
  dispatch = _useReducer2[1];
131
169
  var clearSelectionRange = useCallback(function () {
132
170
  return dispatch({
@@ -194,6 +232,24 @@ export var AnnotationRangeProviderInner = function AnnotationRangeProviderInner(
194
232
  type: 'clearHoverDraft'
195
233
  });
196
234
  }, []);
235
+ var setDraftIntentSource = useCallback(function (source) {
236
+ dispatch({
237
+ type: 'setDraftIntentSource',
238
+ source: source
239
+ });
240
+ }, []);
241
+ var setSelectionDraftTarget = useCallback(function (target) {
242
+ dispatch({
243
+ type: 'setSelectionDraftTarget',
244
+ target: target
245
+ });
246
+ }, []);
247
+ var setHoverDraftTarget = useCallback(function (target) {
248
+ dispatch({
249
+ type: 'setHoverDraftTarget',
250
+ target: target
251
+ });
252
+ }, []);
197
253
  var stateData = useMemo(function () {
198
254
  return {
199
255
  // We techinically have two ranges, however we only want to expose one of them at a time, because only one draft
@@ -203,9 +259,12 @@ export var AnnotationRangeProviderInner = function AnnotationRangeProviderInner(
203
259
  selectionDraftRange: selectionDraftRange,
204
260
  hoverDraftRange: hoverDraftRange,
205
261
  selectionDraftDocumentPosition: selectionDraftDocumentPosition,
206
- hoverDraftDocumentPosition: hoverDraftDocumentPosition
262
+ hoverDraftDocumentPosition: hoverDraftDocumentPosition,
263
+ draftIntentSource: draftIntentSource,
264
+ selectionDraftTarget: selectionDraftTarget,
265
+ hoverDraftTarget: hoverDraftTarget
207
266
  };
208
- }, [selectionRange, hoverRange, type, selectionDraftRange, selectionDraftDocumentPosition, hoverDraftRange, hoverDraftDocumentPosition]);
267
+ }, [selectionRange, hoverRange, type, selectionDraftRange, selectionDraftDocumentPosition, hoverDraftRange, hoverDraftDocumentPosition, draftIntentSource, selectionDraftTarget, hoverDraftTarget]);
209
268
  var dispatchData = useMemo(function () {
210
269
  return {
211
270
  clearSelectionRange: clearSelectionRange,
@@ -215,9 +274,12 @@ export var AnnotationRangeProviderInner = function AnnotationRangeProviderInner(
215
274
  promoteSelectionToDraft: promoteSelectionToDraft,
216
275
  promoteHoverToDraft: promoteHoverToDraft,
217
276
  clearSelectionDraft: clearSelectionDraft,
218
- clearHoverDraft: clearHoverDraft
277
+ clearHoverDraft: clearHoverDraft,
278
+ setDraftIntentSource: setDraftIntentSource,
279
+ setSelectionDraftTarget: setSelectionDraftTarget,
280
+ setHoverDraftTarget: setHoverDraftTarget
219
281
  };
220
- }, [allowCommentsOnMedia, extensionCommentsEnabled, clearSelectionRange, clearHoverRange, setSelectionRange, setHoverTarget, promoteSelectionToDraft, promoteHoverToDraft, clearSelectionDraft, clearHoverDraft]);
282
+ }, [allowCommentsOnMedia, extensionCommentsEnabled, clearSelectionRange, clearHoverRange, setSelectionRange, setHoverTarget, promoteSelectionToDraft, promoteHoverToDraft, clearSelectionDraft, clearHoverDraft, setDraftIntentSource, setSelectionDraftTarget, setHoverDraftTarget]);
221
283
  return /*#__PURE__*/React.createElement(AnnotationRangeStateContext.Provider, {
222
284
  value: stateData
223
285
  }, /*#__PURE__*/React.createElement(AnnotationRangeDispatchContext.Provider, {
@@ -25,7 +25,9 @@ export var SelectionInlineCommentMounter = /*#__PURE__*/React.memo(function (pro
25
25
  generateIndexMatch = props.generateIndexMatch;
26
26
  var _useAnnotationRangeDi = useAnnotationRangeDispatch(),
27
27
  promoteSelectionToDraft = _useAnnotationRangeDi.promoteSelectionToDraft,
28
- clearSelectionDraft = _useAnnotationRangeDi.clearSelectionDraft;
28
+ clearSelectionDraft = _useAnnotationRangeDi.clearSelectionDraft,
29
+ setSelectionDraftTarget = _useAnnotationRangeDi.setSelectionDraftTarget,
30
+ setDraftIntentSource = _useAnnotationRangeDi.setDraftIntentSource;
29
31
  var _useAnnotationRangeSt = useAnnotationRangeState(),
30
32
  selectionDraftDocumentPosition = _useAnnotationRangeSt.selectionDraftDocumentPosition;
31
33
  var actions = useContext(ActionsContext);
@@ -180,6 +182,34 @@ export var SelectionInlineCommentMounter = /*#__PURE__*/React.memo(function (pro
180
182
  removeDraftModeCallback();
181
183
  onCloseProps();
182
184
  }, [onCloseProps, removeDraftModeCallback, createAnalyticsEvent, inlineNodeTypes]);
185
+
186
+ // Publish the range this mounter owns, so a draft can be resolved against the surface the user
187
+ // engaged rather than the ambient range, which flips between selection and hover. During a draft
188
+ // the selection range has been promoted away, and skipping the publish then keeps the target a
189
+ // draft captured.
190
+ useEffect(function () {
191
+ if (!annotationManager || !range) {
192
+ return;
193
+ }
194
+ setSelectionDraftTarget({
195
+ range: range,
196
+ documentPosition: documentPosition,
197
+ isAnnotationAllowed: isAnnotationAllowed,
198
+ source: 'selection'
199
+ });
200
+ setDraftIntentSource('selection');
201
+ }, [annotationManager, range, documentPosition, isAnnotationAllowed, setSelectionDraftTarget, setDraftIntentSource]);
202
+
203
+ // Unmounting means the selection was cleared, so drop the published target.
204
+ useEffect(function () {
205
+ return function () {
206
+ if (annotationManager) {
207
+ setSelectionDraftTarget(null);
208
+ }
209
+ };
210
+ // Cleanup on unmount only; both dependencies are stable for this component's lifetime.
211
+ // eslint-disable-next-line react-hooks/exhaustive-deps
212
+ }, []);
183
213
  useEffect(function () {
184
214
  if (annotationManager) {
185
215
  var allowAnnotation = function allowAnnotation() {
@@ -2,9 +2,26 @@ import type { ReactNode } from 'react';
2
2
  import React from 'react';
3
3
  import type { Position } from '../types';
4
4
  export type RangeType = 'selection' | 'hover' | null;
5
+ /**
6
+ * The range a draft should act on, published by the selection/hover mounters so the manager can
7
+ * resolve its target without reading the ambient `range`, which flips between selection and hover.
8
+ */
9
+ export type DraftTarget = {
10
+ documentPosition: Position | false;
11
+ isAnnotationAllowed: boolean;
12
+ /** A block node carrying a node mark, so its position is collapsed, not a text range. */
13
+ isBlockNode?: boolean;
14
+ range: Range | null;
15
+ /** The range the target came from: a draft promotes and clears the draft state of its source. */
16
+ source?: Exclude<RangeType, null>;
17
+ };
5
18
  interface AnnotationRangeStateContext {
19
+ /** Which surface the user engaged, tracked explicitly so a transient hover cannot win. */
20
+ draftIntentSource: RangeType;
6
21
  hoverDraftDocumentPosition: Position | null;
7
22
  hoverDraftRange: Range | null;
23
+ /** The live hover draft target (media). */
24
+ hoverDraftTarget: DraftTarget | null;
8
25
  /**
9
26
  * This range represents the selection that the user has made before they intend to save an annotation
10
27
  */
@@ -19,6 +36,8 @@ interface AnnotationRangeStateContext {
19
36
  * If the user does not set allowDraftMode, this will be ignored as it only is set when we call applyAnnotationDraftAt()
20
37
  */
21
38
  selectionDraftRange: Range | null;
39
+ /** The live selection draft target, read by `startDraft`. */
40
+ selectionDraftTarget: DraftTarget | null;
22
41
  /**
23
42
  * This represents the type of range that is currently set on the range property, ie, whether the range is a hover or selection.
24
43
  */
@@ -31,7 +50,10 @@ interface AnnotationRangeDispatchContext {
31
50
  clearSelectionRange: () => void;
32
51
  promoteHoverToDraft: (position: Position | null) => void;
33
52
  promoteSelectionToDraft: (position: Position | null) => void;
53
+ setDraftIntentSource: (source: RangeType) => void;
54
+ setHoverDraftTarget: (target: DraftTarget | null) => void;
34
55
  setHoverTarget?: (target: HTMLElement) => void;
56
+ setSelectionDraftTarget: (target: DraftTarget | null) => void;
35
57
  setSelectionRange: (range: Range) => void;
36
58
  }
37
59
  export declare const AnnotationRangeStateContext: React.Context<AnnotationRangeStateContext>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/renderer",
3
- "version": "153.4.7",
3
+ "version": "153.5.0",
4
4
  "description": "Renderer component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -51,7 +51,7 @@
51
51
  "@atlaskit/editor-smart-link-draggable": "^1.2.0",
52
52
  "@atlaskit/emoji": "^73.6.0",
53
53
  "@atlaskit/feature-gate-js-client": "^8.0.0",
54
- "@atlaskit/icon": "^38.0.0",
54
+ "@atlaskit/icon": "^38.1.0",
55
55
  "@atlaskit/link": "^5.1.0",
56
56
  "@atlaskit/link-datasource": "^7.13.0",
57
57
  "@atlaskit/link-extractors": "^5.0.0",
@@ -67,12 +67,12 @@
67
67
  "@atlaskit/platform-feature-flags": "^2.2.0",
68
68
  "@atlaskit/platform-feature-flags-react": "^1.2.0",
69
69
  "@atlaskit/react-compiler-gating": "^0.2.0",
70
- "@atlaskit/react-ufo": "^8.4.0",
70
+ "@atlaskit/react-ufo": "^8.5.0",
71
71
  "@atlaskit/smart-card": "^46.14.0",
72
72
  "@atlaskit/status": "^5.17.0",
73
73
  "@atlaskit/task-decision": "^21.16.0",
74
74
  "@atlaskit/tmp-editor-statsig": "^262.0.0",
75
- "@atlaskit/tokens": "^20.11.0",
75
+ "@atlaskit/tokens": "^20.12.0",
76
76
  "@atlaskit/tooltip": "^24.4.0",
77
77
  "@atlaskit/visually-hidden": "^4.4.0",
78
78
  "@babel/runtime": "^7.0.0",
@@ -86,7 +86,7 @@
86
86
  "uuid": "^11.1.1"
87
87
  },
88
88
  "peerDependencies": {
89
- "@atlaskit/editor-common": "^134.18.0",
89
+ "@atlaskit/editor-common": "^134.19.0",
90
90
  "@atlaskit/link-provider": "^6.1.0",
91
91
  "@atlaskit/media-core": "^39.0.0",
92
92
  "react": "^18.2.0 || ^19.2.0",
@@ -98,7 +98,7 @@
98
98
  "@af/visual-regression": "workspace:^",
99
99
  "@atlaskit/analytics-gas-types": "^6.2.0",
100
100
  "@atlaskit/checkbox": "^19.3.0",
101
- "@atlaskit/editor-common": "^134.18.0",
101
+ "@atlaskit/editor-common": "^134.19.0",
102
102
  "@atlaskit/editor-plugin-media": "^32.4.0",
103
103
  "@atlaskit/editor-test-helpers": "workspace:^",
104
104
  "@atlaskit/inline-edit": "^16.5.0",
@@ -114,7 +114,7 @@
114
114
  "@atlaskit/modal-dialog": "^17.2.0",
115
115
  "@atlaskit/navigation-system": "^11.7.0",
116
116
  "@atlaskit/primitives": "^22.7.0",
117
- "@atlaskit/profilecard": "^27.9.0",
117
+ "@atlaskit/profilecard": "^27.10.0",
118
118
  "@atlaskit/radio": "^10.2.0",
119
119
  "@atlaskit/range": "^12.2.0",
120
120
  "@atlaskit/section-message": "^10.3.0",
@@ -127,6 +127,7 @@
127
127
  "@atlassian/a11y-playwright-testing": "^0.13.0",
128
128
  "@atlassian/experiment-test-utils": "^0.2.0",
129
129
  "@atlassian/feature-flags-test-utils": "^1.3.0",
130
+ "@atlassian/relay-test-utils": "workspace:^",
130
131
  "@atlassian/structured-docs-types": "workspace:^",
131
132
  "@atlassian/testing-library": "^0.12.0",
132
133
  "@atlassian/workbench": "workspace:*",