@atlaskit/renderer 118.5.0 → 118.6.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,26 @@
1
1
  # @atlaskit/renderer
2
2
 
3
+ ## 118.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#158451](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/158451)
8
+ [`b1235f9180ac5`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b1235f9180ac5) -
9
+ EDITOR-586 - Implement Select Annotation APIs for Renderer and integrate with CCFE
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
15
+ ## 118.5.1
16
+
17
+ ### Patch Changes
18
+
19
+ - [#161072](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/161072)
20
+ [`a0c4a3b5661b9`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a0c4a3b5661b9) -
21
+ EDITOR-775 - Could not create new comment on extension Excerpt in renderer
22
+ - Updated dependencies
23
+
3
24
  ## 118.5.0
4
25
 
5
26
  ### Minor Changes
@@ -63,7 +63,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
63
63
  var NORMAL_SEVERITY_THRESHOLD = exports.NORMAL_SEVERITY_THRESHOLD = 2000;
64
64
  var DEGRADED_SEVERITY_THRESHOLD = exports.DEGRADED_SEVERITY_THRESHOLD = 3000;
65
65
  var packageName = "@atlaskit/renderer";
66
- var packageVersion = "118.5.0";
66
+ var packageVersion = "118.6.0";
67
67
  var setAsQueryContainerStyles = (0, _react2.css)({
68
68
  containerName: 'ak-renderer-wrapper',
69
69
  containerType: 'inline-size'
@@ -11,6 +11,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
11
11
  var _react = _interopRequireWildcard(require("react"));
12
12
  var _adfSchema = require("@atlaskit/adf-schema");
13
13
  var _types = require("@atlaskit/editor-common/types");
14
+ var _RendererActionsContext = require("../../../ui/RendererActionsContext");
14
15
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
15
16
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
16
17
  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; }
@@ -209,6 +210,7 @@ var AnnotationManagerProvider = exports.AnnotationManagerProvider = function Ann
209
210
  _useReducer2 = (0, _slicedToArray2.default)(_useReducer, 2),
210
211
  state = _useReducer2[0],
211
212
  dispatch = _useReducer2[1];
213
+ var actionContext = (0, _react.useContext)(_RendererActionsContext.RendererContext);
212
214
  (0, _react.useEffect)(function () {
213
215
  var getDraft = function getDraft() {
214
216
  var _state$draftActionRes;
@@ -264,50 +266,137 @@ var AnnotationManagerProvider = exports.AnnotationManagerProvider = function Ann
264
266
  });
265
267
  }
266
268
  }, [annotationManager, state.draftId, state.isDrafting, state.draftMarkRef, state.draftActionResult]);
269
+ (0, _react.useEffect)(function () {
270
+ var setIsAnnotationSelected = function setIsAnnotationSelected(id, isSelected) {
271
+ var _state$annotations;
272
+ if (state.isDrafting) {
273
+ return {
274
+ success: false,
275
+ reason: 'draft-in-progress'
276
+ };
277
+ }
278
+ if (!((_state$annotations = state.annotations) !== null && _state$annotations !== void 0 && _state$annotations[id])) {
279
+ return {
280
+ success: false,
281
+ reason: 'id-not-valid'
282
+ };
283
+ }
267
284
 
268
- // useEffect(() => {
269
- // const setIsAnnotationSelected = (id: AnnotationId, isSelected: boolean): SelectAnnotationResult => {
270
- // if (!state.annotations?.[id]) {
271
- // return {
272
- // success: false,
273
- // reason: 'id-not-valid',
274
- // };
275
- // }
276
-
277
- // dispatch({
278
- // type: 'updateAnnotation',
279
- // data: {
280
- // id,
281
- // selected: isSelected,
282
- // },
283
- // })
284
-
285
- // return {
286
- // success: true,
287
- // isSelected,
288
- // };
289
- // };
290
-
291
- // annotationManager?.hook('setIsAnnotationSelected', setIsAnnotationSelected);
292
- // return () => {
293
- // annotationManager?.unhook('setIsAnnotationSelected', setIsAnnotationSelected);
294
- // };
295
- // }, [state.annotations]);
296
-
297
- // useEffect(() => {
298
- // console.log('annotationsSelectedChanged', state.annotationsSelectedChanged);
299
-
300
- // // if (state.isDrafting && state.currentDraftId && state.draftMarkRef) {
301
- // // annotationManager?.emit({
302
- // // name: 'annotationSelectionChanged',
303
- // // data: {
304
- // // annotationId: state.currentDraftId,
305
- // // inlineNodeTypes: [],
306
- // // isSelected: true,
307
- // // },
308
- // // });
309
- // // }
310
- // }, [annotationManager, state.annotationsSelectedChanged]);
285
+ // the annotation is currently not selected and is being selected
286
+ if (id !== state.currentSelectedAnnotationId && isSelected) {
287
+ dispatch({
288
+ type: 'updateAnnotation',
289
+ data: {
290
+ id: id,
291
+ selected: true
292
+ }
293
+ });
294
+ dispatch({
295
+ type: 'setSelectedMarkRef',
296
+ data: {
297
+ markRef: document.getElementById(id) || undefined
298
+ }
299
+ });
300
+ }
301
+ // the annotation is currently selected and is being unselected
302
+ else if (id === state.currentSelectedAnnotationId && !isSelected) {
303
+ dispatch({
304
+ type: 'resetSelectedAnnotation'
305
+ });
306
+ }
307
+ return {
308
+ success: true,
309
+ isSelected: isSelected
310
+ };
311
+ };
312
+ annotationManager === null || annotationManager === void 0 || annotationManager.hook('setIsAnnotationSelected', setIsAnnotationSelected);
313
+ return function () {
314
+ annotationManager === null || annotationManager === void 0 || annotationManager.unhook('setIsAnnotationSelected', setIsAnnotationSelected);
315
+ };
316
+ }, [annotationManager, state.isDrafting, state.annotations, state.currentSelectedAnnotationId, state.currentSelectedMarkRef]);
317
+ var prevSelectedAnnotationId = (0, _react.useRef)(undefined);
318
+ (0, _react.useEffect)(function () {
319
+ if (prevSelectedAnnotationId.current) {
320
+ annotationManager === null || annotationManager === void 0 || annotationManager.emit({
321
+ name: 'annotationSelectionChanged',
322
+ data: {
323
+ annotationId: prevSelectedAnnotationId.current,
324
+ isSelected: false,
325
+ inlineNodeTypes: []
326
+ }
327
+ });
328
+ }
329
+ prevSelectedAnnotationId.current = state.currentSelectedAnnotationId;
330
+ }, [state.currentSelectedAnnotationId, annotationManager]);
331
+ (0, _react.useEffect)(function () {
332
+ if (state.currentSelectedAnnotationId && state.currentSelectedMarkRef && state.currentSelectedMarkRef.id === state.currentSelectedAnnotationId) {
333
+ annotationManager === null || annotationManager === void 0 || annotationManager.emit({
334
+ name: 'annotationSelectionChanged',
335
+ data: {
336
+ annotationId: state.currentSelectedAnnotationId,
337
+ isSelected: true,
338
+ inlineNodeTypes: []
339
+ }
340
+ });
341
+ }
342
+ }, [annotationManager, state.currentSelectedAnnotationId, state.currentSelectedMarkRef]);
343
+ (0, _react.useEffect)(function () {
344
+ var setIsAnnotationHovered = function setIsAnnotationHovered(id, isHovered) {
345
+ var _state$annotations2;
346
+ if (!((_state$annotations2 = state.annotations) !== null && _state$annotations2 !== void 0 && _state$annotations2[id])) {
347
+ return {
348
+ success: false,
349
+ reason: 'id-not-valid'
350
+ };
351
+ }
352
+ dispatch({
353
+ type: 'updateAnnotation',
354
+ data: {
355
+ id: id,
356
+ hovered: isHovered
357
+ }
358
+ });
359
+ return {
360
+ success: true,
361
+ isHovered: isHovered
362
+ };
363
+ };
364
+ annotationManager === null || annotationManager === void 0 || annotationManager.hook('setIsAnnotationHovered', setIsAnnotationHovered);
365
+ return function () {
366
+ annotationManager === null || annotationManager === void 0 || annotationManager.unhook('setIsAnnotationHovered', setIsAnnotationHovered);
367
+ };
368
+ }, [annotationManager, state.annotations]);
369
+ (0, _react.useEffect)(function () {
370
+ var clearAnnotation = function clearAnnotation(id) {
371
+ var _state$annotations3;
372
+ if (!((_state$annotations3 = state.annotations) !== null && _state$annotations3 !== void 0 && _state$annotations3[id])) {
373
+ return {
374
+ success: false,
375
+ reason: 'id-not-valid'
376
+ };
377
+ }
378
+ var result = actionContext.deleteAnnotation(id, _adfSchema.AnnotationTypes.INLINE_COMMENT);
379
+ if (!result) {
380
+ return {
381
+ success: false,
382
+ reason: 'clear-failed'
383
+ };
384
+ }
385
+ var step = result.step,
386
+ doc = result.doc;
387
+ return {
388
+ success: true,
389
+ actionResult: {
390
+ step: step,
391
+ doc: doc
392
+ }
393
+ };
394
+ };
395
+ annotationManager === null || annotationManager === void 0 || annotationManager.hook('clearAnnotation', clearAnnotation);
396
+ return function () {
397
+ annotationManager === null || annotationManager === void 0 || annotationManager.unhook('clearAnnotation', clearAnnotation);
398
+ };
399
+ }, [annotationManager, state.annotations, actionContext]);
311
400
 
312
401
  /**
313
402
  * This is a temporary solution to ensure that the annotation manager state is in sync with the
@@ -320,7 +409,7 @@ var AnnotationManagerProvider = exports.AnnotationManagerProvider = function Ann
320
409
  return;
321
410
  }
322
411
  Object.values(payload).forEach(function (annotation) {
323
- if (annotation.id && annotation.annotationType === _adfSchema.AnnotationTypes.INLINE_COMMENT && !annotation.state) {
412
+ if (annotation.id && annotation.annotationType === _adfSchema.AnnotationTypes.INLINE_COMMENT) {
324
413
  var _annotation$state;
325
414
  dispatch({
326
415
  type: 'updateAnnotation',
@@ -46,12 +46,17 @@ var MarkElement = exports.MarkElement = function MarkElement(_ref) {
46
46
  }
47
47
  var eventTarget = props.eventTarget,
48
48
  annotationIds = props.annotationIds;
49
- if ((0, _platformFeatureFlags.fg)('platform_editor_comments_api_manager')) {
49
+ if ((0, _platformFeatureFlags.fg)('platform_editor_comments_api_manager_select')) {
50
50
  if (hasFocus) {
51
51
  return;
52
52
  }
53
53
  annotationManager === null || annotationManager === void 0 || annotationManager.checkPreemptiveGate().then(function (canSelect) {
54
54
  if (canSelect) {
55
+ // if there is a draft, clear it first
56
+ annotationManager === null || annotationManager === void 0 || annotationManager.clearDraft();
57
+
58
+ // use setIsAnnotationSelected won't work here if there is a draft in progress
59
+ // so we need to use dispatch to update the state directly
55
60
  dispatch({
56
61
  type: 'updateAnnotation',
57
62
  data: {
@@ -140,7 +140,7 @@ var useAnnotationClickEvent = exports.useAnnotationClickEvent = function useAnno
140
140
  currentSelectedAnnotationId = _useAnnotationManager4.currentSelectedAnnotationId,
141
141
  currentSelectedMarkRef = _useAnnotationManager4.currentSelectedMarkRef;
142
142
  var selectedAnnotation = (0, _react.useMemo)(function () {
143
- return currentSelectedAnnotationId && currentSelectedMarkRef ? {
143
+ return currentSelectedAnnotationId && currentSelectedMarkRef && currentSelectedMarkRef.id === currentSelectedAnnotationId ? {
144
144
  annotations: [{
145
145
  id: currentSelectedAnnotationId,
146
146
  type: _adfSchema.AnnotationTypes.INLINE_COMMENT
@@ -226,12 +226,6 @@ var SelectionInlineCommentMounter = exports.SelectionInlineCommentMounter = /*#_
226
226
  reason: 'draft-in-progress'
227
227
  };
228
228
  }
229
- if (!actions.isValidAnnotationRange(range)) {
230
- return {
231
- success: false,
232
- reason: 'invalid-range'
233
- };
234
- }
235
229
  var id = (0, _v.default)();
236
230
  var result = applyDraftModeCallback({
237
231
  annotationId: id,
@@ -48,7 +48,7 @@ import { PortalContext } from './PortalContext';
48
48
  export const NORMAL_SEVERITY_THRESHOLD = 2000;
49
49
  export const DEGRADED_SEVERITY_THRESHOLD = 3000;
50
50
  const packageName = "@atlaskit/renderer";
51
- const packageVersion = "118.5.0";
51
+ const packageVersion = "118.6.0";
52
52
  const setAsQueryContainerStyles = css({
53
53
  containerName: 'ak-renderer-wrapper',
54
54
  containerType: 'inline-size'
@@ -1,6 +1,7 @@
1
- import React, { createContext, useContext, useEffect, useMemo, useReducer } from 'react';
1
+ import React, { createContext, useContext, useEffect, useMemo, useReducer, useRef } from 'react';
2
2
  import { AnnotationMarkStates, AnnotationTypes } from '@atlaskit/adf-schema';
3
3
  import { AnnotationUpdateEvent } from '@atlaskit/editor-common/types';
4
+ import { RendererContext } from '../../../ui/RendererActionsContext';
4
5
  const initState = {
5
6
  isDrafting: false,
6
7
  draftId: undefined,
@@ -205,6 +206,7 @@ export const AnnotationManagerProvider = ({
205
206
  updateSubscriber
206
207
  }) => {
207
208
  const [state, dispatch] = useReducer(reducer, initState);
209
+ const actionContext = useContext(RendererContext);
208
210
  useEffect(() => {
209
211
  const getDraft = () => {
210
212
  var _state$draftActionRes;
@@ -260,50 +262,139 @@ export const AnnotationManagerProvider = ({
260
262
  });
261
263
  }
262
264
  }, [annotationManager, state.draftId, state.isDrafting, state.draftMarkRef, state.draftActionResult]);
265
+ useEffect(() => {
266
+ const setIsAnnotationSelected = (id, isSelected) => {
267
+ var _state$annotations;
268
+ if (state.isDrafting) {
269
+ return {
270
+ success: false,
271
+ reason: 'draft-in-progress'
272
+ };
273
+ }
274
+ if (!((_state$annotations = state.annotations) !== null && _state$annotations !== void 0 && _state$annotations[id])) {
275
+ return {
276
+ success: false,
277
+ reason: 'id-not-valid'
278
+ };
279
+ }
263
280
 
264
- // useEffect(() => {
265
- // const setIsAnnotationSelected = (id: AnnotationId, isSelected: boolean): SelectAnnotationResult => {
266
- // if (!state.annotations?.[id]) {
267
- // return {
268
- // success: false,
269
- // reason: 'id-not-valid',
270
- // };
271
- // }
272
-
273
- // dispatch({
274
- // type: 'updateAnnotation',
275
- // data: {
276
- // id,
277
- // selected: isSelected,
278
- // },
279
- // })
280
-
281
- // return {
282
- // success: true,
283
- // isSelected,
284
- // };
285
- // };
286
-
287
- // annotationManager?.hook('setIsAnnotationSelected', setIsAnnotationSelected);
288
- // return () => {
289
- // annotationManager?.unhook('setIsAnnotationSelected', setIsAnnotationSelected);
290
- // };
291
- // }, [state.annotations]);
292
-
293
- // useEffect(() => {
294
- // console.log('annotationsSelectedChanged', state.annotationsSelectedChanged);
295
-
296
- // // if (state.isDrafting && state.currentDraftId && state.draftMarkRef) {
297
- // // annotationManager?.emit({
298
- // // name: 'annotationSelectionChanged',
299
- // // data: {
300
- // // annotationId: state.currentDraftId,
301
- // // inlineNodeTypes: [],
302
- // // isSelected: true,
303
- // // },
304
- // // });
305
- // // }
306
- // }, [annotationManager, state.annotationsSelectedChanged]);
281
+ // the annotation is currently not selected and is being selected
282
+ if (id !== state.currentSelectedAnnotationId && isSelected) {
283
+ dispatch({
284
+ type: 'updateAnnotation',
285
+ data: {
286
+ id,
287
+ selected: true
288
+ }
289
+ });
290
+ dispatch({
291
+ type: 'setSelectedMarkRef',
292
+ data: {
293
+ markRef: document.getElementById(id) || undefined
294
+ }
295
+ });
296
+ }
297
+ // the annotation is currently selected and is being unselected
298
+ else if (id === state.currentSelectedAnnotationId && !isSelected) {
299
+ dispatch({
300
+ type: 'resetSelectedAnnotation'
301
+ });
302
+ }
303
+ return {
304
+ success: true,
305
+ isSelected
306
+ };
307
+ };
308
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.hook('setIsAnnotationSelected', setIsAnnotationSelected);
309
+ return () => {
310
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.unhook('setIsAnnotationSelected', setIsAnnotationSelected);
311
+ };
312
+ }, [annotationManager, state.isDrafting, state.annotations, state.currentSelectedAnnotationId, state.currentSelectedMarkRef]);
313
+ const prevSelectedAnnotationId = useRef(undefined);
314
+ useEffect(() => {
315
+ if (prevSelectedAnnotationId.current) {
316
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.emit({
317
+ name: 'annotationSelectionChanged',
318
+ data: {
319
+ annotationId: prevSelectedAnnotationId.current,
320
+ isSelected: false,
321
+ inlineNodeTypes: []
322
+ }
323
+ });
324
+ }
325
+ prevSelectedAnnotationId.current = state.currentSelectedAnnotationId;
326
+ }, [state.currentSelectedAnnotationId, annotationManager]);
327
+ useEffect(() => {
328
+ if (state.currentSelectedAnnotationId && state.currentSelectedMarkRef && state.currentSelectedMarkRef.id === state.currentSelectedAnnotationId) {
329
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.emit({
330
+ name: 'annotationSelectionChanged',
331
+ data: {
332
+ annotationId: state.currentSelectedAnnotationId,
333
+ isSelected: true,
334
+ inlineNodeTypes: []
335
+ }
336
+ });
337
+ }
338
+ }, [annotationManager, state.currentSelectedAnnotationId, state.currentSelectedMarkRef]);
339
+ useEffect(() => {
340
+ const setIsAnnotationHovered = (id, isHovered) => {
341
+ var _state$annotations2;
342
+ if (!((_state$annotations2 = state.annotations) !== null && _state$annotations2 !== void 0 && _state$annotations2[id])) {
343
+ return {
344
+ success: false,
345
+ reason: 'id-not-valid'
346
+ };
347
+ }
348
+ dispatch({
349
+ type: 'updateAnnotation',
350
+ data: {
351
+ id,
352
+ hovered: isHovered
353
+ }
354
+ });
355
+ return {
356
+ success: true,
357
+ isHovered
358
+ };
359
+ };
360
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.hook('setIsAnnotationHovered', setIsAnnotationHovered);
361
+ return () => {
362
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.unhook('setIsAnnotationHovered', setIsAnnotationHovered);
363
+ };
364
+ }, [annotationManager, state.annotations]);
365
+ useEffect(() => {
366
+ const clearAnnotation = id => {
367
+ var _state$annotations3;
368
+ if (!((_state$annotations3 = state.annotations) !== null && _state$annotations3 !== void 0 && _state$annotations3[id])) {
369
+ return {
370
+ success: false,
371
+ reason: 'id-not-valid'
372
+ };
373
+ }
374
+ const result = actionContext.deleteAnnotation(id, AnnotationTypes.INLINE_COMMENT);
375
+ if (!result) {
376
+ return {
377
+ success: false,
378
+ reason: 'clear-failed'
379
+ };
380
+ }
381
+ const {
382
+ step,
383
+ doc
384
+ } = result;
385
+ return {
386
+ success: true,
387
+ actionResult: {
388
+ step,
389
+ doc
390
+ }
391
+ };
392
+ };
393
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.hook('clearAnnotation', clearAnnotation);
394
+ return () => {
395
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.unhook('clearAnnotation', clearAnnotation);
396
+ };
397
+ }, [annotationManager, state.annotations, actionContext]);
307
398
 
308
399
  /**
309
400
  * This is a temporary solution to ensure that the annotation manager state is in sync with the
@@ -316,7 +407,7 @@ export const AnnotationManagerProvider = ({
316
407
  return;
317
408
  }
318
409
  Object.values(payload).forEach(annotation => {
319
- if (annotation.id && annotation.annotationType === AnnotationTypes.INLINE_COMMENT && !annotation.state) {
410
+ if (annotation.id && annotation.annotationType === AnnotationTypes.INLINE_COMMENT) {
320
411
  var _annotation$state;
321
412
  dispatch({
322
413
  type: 'updateAnnotation',
@@ -40,12 +40,17 @@ const MarkElement = ({
40
40
  eventTarget,
41
41
  annotationIds
42
42
  } = props;
43
- if (fg('platform_editor_comments_api_manager')) {
43
+ if (fg('platform_editor_comments_api_manager_select')) {
44
44
  if (hasFocus) {
45
45
  return;
46
46
  }
47
47
  annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.checkPreemptiveGate().then(canSelect => {
48
48
  if (canSelect) {
49
+ // if there is a draft, clear it first
50
+ annotationManager === null || annotationManager === void 0 ? void 0 : annotationManager.clearDraft();
51
+
52
+ // use setIsAnnotationSelected won't work here if there is a draft in progress
53
+ // so we need to use dispatch to update the state directly
49
54
  dispatch({
50
55
  type: 'updateAnnotation',
51
56
  data: {
@@ -134,7 +134,7 @@ export const useAnnotationClickEvent = props => {
134
134
  currentSelectedMarkRef
135
135
  } = useAnnotationManagerState();
136
136
  const selectedAnnotation = useMemo(() => {
137
- return currentSelectedAnnotationId && currentSelectedMarkRef ? {
137
+ return currentSelectedAnnotationId && currentSelectedMarkRef && currentSelectedMarkRef.id === currentSelectedAnnotationId ? {
138
138
  annotations: [{
139
139
  id: currentSelectedAnnotationId,
140
140
  type: AnnotationTypes.INLINE_COMMENT
@@ -222,12 +222,6 @@ export const SelectionInlineCommentMounter = /*#__PURE__*/React.memo(props => {
222
222
  reason: 'draft-in-progress'
223
223
  };
224
224
  }
225
- if (!actions.isValidAnnotationRange(range)) {
226
- return {
227
- success: false,
228
- reason: 'invalid-range'
229
- };
230
- }
231
225
  const id = uuid();
232
226
  const result = applyDraftModeCallback({
233
227
  annotationId: id,
@@ -53,7 +53,7 @@ import { PortalContext } from './PortalContext';
53
53
  export var NORMAL_SEVERITY_THRESHOLD = 2000;
54
54
  export var DEGRADED_SEVERITY_THRESHOLD = 3000;
55
55
  var packageName = "@atlaskit/renderer";
56
- var packageVersion = "118.5.0";
56
+ var packageVersion = "118.6.0";
57
57
  var setAsQueryContainerStyles = css({
58
58
  containerName: 'ak-renderer-wrapper',
59
59
  containerType: 'inline-size'
@@ -2,9 +2,10 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
- import React, { createContext, useContext, useEffect, useMemo, useReducer } from 'react';
5
+ import React, { createContext, useContext, useEffect, useMemo, useReducer, useRef } from 'react';
6
6
  import { AnnotationMarkStates, AnnotationTypes } from '@atlaskit/adf-schema';
7
7
  import { AnnotationUpdateEvent } from '@atlaskit/editor-common/types';
8
+ import { RendererContext } from '../../../ui/RendererActionsContext';
8
9
  var initState = {
9
10
  isDrafting: false,
10
11
  draftId: undefined,
@@ -199,6 +200,7 @@ export var AnnotationManagerProvider = function AnnotationManagerProvider(_ref)
199
200
  _useReducer2 = _slicedToArray(_useReducer, 2),
200
201
  state = _useReducer2[0],
201
202
  dispatch = _useReducer2[1];
203
+ var actionContext = useContext(RendererContext);
202
204
  useEffect(function () {
203
205
  var getDraft = function getDraft() {
204
206
  var _state$draftActionRes;
@@ -254,50 +256,137 @@ export var AnnotationManagerProvider = function AnnotationManagerProvider(_ref)
254
256
  });
255
257
  }
256
258
  }, [annotationManager, state.draftId, state.isDrafting, state.draftMarkRef, state.draftActionResult]);
259
+ useEffect(function () {
260
+ var setIsAnnotationSelected = function setIsAnnotationSelected(id, isSelected) {
261
+ var _state$annotations;
262
+ if (state.isDrafting) {
263
+ return {
264
+ success: false,
265
+ reason: 'draft-in-progress'
266
+ };
267
+ }
268
+ if (!((_state$annotations = state.annotations) !== null && _state$annotations !== void 0 && _state$annotations[id])) {
269
+ return {
270
+ success: false,
271
+ reason: 'id-not-valid'
272
+ };
273
+ }
257
274
 
258
- // useEffect(() => {
259
- // const setIsAnnotationSelected = (id: AnnotationId, isSelected: boolean): SelectAnnotationResult => {
260
- // if (!state.annotations?.[id]) {
261
- // return {
262
- // success: false,
263
- // reason: 'id-not-valid',
264
- // };
265
- // }
266
-
267
- // dispatch({
268
- // type: 'updateAnnotation',
269
- // data: {
270
- // id,
271
- // selected: isSelected,
272
- // },
273
- // })
274
-
275
- // return {
276
- // success: true,
277
- // isSelected,
278
- // };
279
- // };
280
-
281
- // annotationManager?.hook('setIsAnnotationSelected', setIsAnnotationSelected);
282
- // return () => {
283
- // annotationManager?.unhook('setIsAnnotationSelected', setIsAnnotationSelected);
284
- // };
285
- // }, [state.annotations]);
286
-
287
- // useEffect(() => {
288
- // console.log('annotationsSelectedChanged', state.annotationsSelectedChanged);
289
-
290
- // // if (state.isDrafting && state.currentDraftId && state.draftMarkRef) {
291
- // // annotationManager?.emit({
292
- // // name: 'annotationSelectionChanged',
293
- // // data: {
294
- // // annotationId: state.currentDraftId,
295
- // // inlineNodeTypes: [],
296
- // // isSelected: true,
297
- // // },
298
- // // });
299
- // // }
300
- // }, [annotationManager, state.annotationsSelectedChanged]);
275
+ // the annotation is currently not selected and is being selected
276
+ if (id !== state.currentSelectedAnnotationId && isSelected) {
277
+ dispatch({
278
+ type: 'updateAnnotation',
279
+ data: {
280
+ id: id,
281
+ selected: true
282
+ }
283
+ });
284
+ dispatch({
285
+ type: 'setSelectedMarkRef',
286
+ data: {
287
+ markRef: document.getElementById(id) || undefined
288
+ }
289
+ });
290
+ }
291
+ // the annotation is currently selected and is being unselected
292
+ else if (id === state.currentSelectedAnnotationId && !isSelected) {
293
+ dispatch({
294
+ type: 'resetSelectedAnnotation'
295
+ });
296
+ }
297
+ return {
298
+ success: true,
299
+ isSelected: isSelected
300
+ };
301
+ };
302
+ annotationManager === null || annotationManager === void 0 || annotationManager.hook('setIsAnnotationSelected', setIsAnnotationSelected);
303
+ return function () {
304
+ annotationManager === null || annotationManager === void 0 || annotationManager.unhook('setIsAnnotationSelected', setIsAnnotationSelected);
305
+ };
306
+ }, [annotationManager, state.isDrafting, state.annotations, state.currentSelectedAnnotationId, state.currentSelectedMarkRef]);
307
+ var prevSelectedAnnotationId = useRef(undefined);
308
+ useEffect(function () {
309
+ if (prevSelectedAnnotationId.current) {
310
+ annotationManager === null || annotationManager === void 0 || annotationManager.emit({
311
+ name: 'annotationSelectionChanged',
312
+ data: {
313
+ annotationId: prevSelectedAnnotationId.current,
314
+ isSelected: false,
315
+ inlineNodeTypes: []
316
+ }
317
+ });
318
+ }
319
+ prevSelectedAnnotationId.current = state.currentSelectedAnnotationId;
320
+ }, [state.currentSelectedAnnotationId, annotationManager]);
321
+ useEffect(function () {
322
+ if (state.currentSelectedAnnotationId && state.currentSelectedMarkRef && state.currentSelectedMarkRef.id === state.currentSelectedAnnotationId) {
323
+ annotationManager === null || annotationManager === void 0 || annotationManager.emit({
324
+ name: 'annotationSelectionChanged',
325
+ data: {
326
+ annotationId: state.currentSelectedAnnotationId,
327
+ isSelected: true,
328
+ inlineNodeTypes: []
329
+ }
330
+ });
331
+ }
332
+ }, [annotationManager, state.currentSelectedAnnotationId, state.currentSelectedMarkRef]);
333
+ useEffect(function () {
334
+ var setIsAnnotationHovered = function setIsAnnotationHovered(id, isHovered) {
335
+ var _state$annotations2;
336
+ if (!((_state$annotations2 = state.annotations) !== null && _state$annotations2 !== void 0 && _state$annotations2[id])) {
337
+ return {
338
+ success: false,
339
+ reason: 'id-not-valid'
340
+ };
341
+ }
342
+ dispatch({
343
+ type: 'updateAnnotation',
344
+ data: {
345
+ id: id,
346
+ hovered: isHovered
347
+ }
348
+ });
349
+ return {
350
+ success: true,
351
+ isHovered: isHovered
352
+ };
353
+ };
354
+ annotationManager === null || annotationManager === void 0 || annotationManager.hook('setIsAnnotationHovered', setIsAnnotationHovered);
355
+ return function () {
356
+ annotationManager === null || annotationManager === void 0 || annotationManager.unhook('setIsAnnotationHovered', setIsAnnotationHovered);
357
+ };
358
+ }, [annotationManager, state.annotations]);
359
+ useEffect(function () {
360
+ var clearAnnotation = function clearAnnotation(id) {
361
+ var _state$annotations3;
362
+ if (!((_state$annotations3 = state.annotations) !== null && _state$annotations3 !== void 0 && _state$annotations3[id])) {
363
+ return {
364
+ success: false,
365
+ reason: 'id-not-valid'
366
+ };
367
+ }
368
+ var result = actionContext.deleteAnnotation(id, AnnotationTypes.INLINE_COMMENT);
369
+ if (!result) {
370
+ return {
371
+ success: false,
372
+ reason: 'clear-failed'
373
+ };
374
+ }
375
+ var step = result.step,
376
+ doc = result.doc;
377
+ return {
378
+ success: true,
379
+ actionResult: {
380
+ step: step,
381
+ doc: doc
382
+ }
383
+ };
384
+ };
385
+ annotationManager === null || annotationManager === void 0 || annotationManager.hook('clearAnnotation', clearAnnotation);
386
+ return function () {
387
+ annotationManager === null || annotationManager === void 0 || annotationManager.unhook('clearAnnotation', clearAnnotation);
388
+ };
389
+ }, [annotationManager, state.annotations, actionContext]);
301
390
 
302
391
  /**
303
392
  * This is a temporary solution to ensure that the annotation manager state is in sync with the
@@ -310,7 +399,7 @@ export var AnnotationManagerProvider = function AnnotationManagerProvider(_ref)
310
399
  return;
311
400
  }
312
401
  Object.values(payload).forEach(function (annotation) {
313
- if (annotation.id && annotation.annotationType === AnnotationTypes.INLINE_COMMENT && !annotation.state) {
402
+ if (annotation.id && annotation.annotationType === AnnotationTypes.INLINE_COMMENT) {
314
403
  var _annotation$state;
315
404
  dispatch({
316
405
  type: 'updateAnnotation',
@@ -37,12 +37,17 @@ var MarkElement = function MarkElement(_ref) {
37
37
  }
38
38
  var eventTarget = props.eventTarget,
39
39
  annotationIds = props.annotationIds;
40
- if (fg('platform_editor_comments_api_manager')) {
40
+ if (fg('platform_editor_comments_api_manager_select')) {
41
41
  if (hasFocus) {
42
42
  return;
43
43
  }
44
44
  annotationManager === null || annotationManager === void 0 || annotationManager.checkPreemptiveGate().then(function (canSelect) {
45
45
  if (canSelect) {
46
+ // if there is a draft, clear it first
47
+ annotationManager === null || annotationManager === void 0 || annotationManager.clearDraft();
48
+
49
+ // use setIsAnnotationSelected won't work here if there is a draft in progress
50
+ // so we need to use dispatch to update the state directly
46
51
  dispatch({
47
52
  type: 'updateAnnotation',
48
53
  data: {
@@ -133,7 +133,7 @@ export var useAnnotationClickEvent = function useAnnotationClickEvent(props) {
133
133
  currentSelectedAnnotationId = _useAnnotationManager4.currentSelectedAnnotationId,
134
134
  currentSelectedMarkRef = _useAnnotationManager4.currentSelectedMarkRef;
135
135
  var selectedAnnotation = useMemo(function () {
136
- return currentSelectedAnnotationId && currentSelectedMarkRef ? {
136
+ return currentSelectedAnnotationId && currentSelectedMarkRef && currentSelectedMarkRef.id === currentSelectedAnnotationId ? {
137
137
  annotations: [{
138
138
  id: currentSelectedAnnotationId,
139
139
  type: AnnotationTypes.INLINE_COMMENT
@@ -216,12 +216,6 @@ export var SelectionInlineCommentMounter = /*#__PURE__*/React.memo(function (pro
216
216
  reason: 'draft-in-progress'
217
217
  };
218
218
  }
219
- if (!actions.isValidAnnotationRange(range)) {
220
- return {
221
- success: false,
222
- reason: 'invalid-range'
223
- };
224
- }
225
219
  var id = uuid();
226
220
  var result = applyDraftModeCallback({
227
221
  annotationId: id,
@@ -4,6 +4,7 @@ import type { AnnotationActionResult, AnnotationByMatches } from '@atlaskit/edit
4
4
  import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
5
5
  import type { Mark, Node, Schema } from '@atlaskit/editor-prosemirror/model';
6
6
  import type { Step } from '@atlaskit/editor-prosemirror/transform';
7
+ import { RemoveMarkStep, RemoveNodeMarkStep } from '@atlaskit/editor-prosemirror/transform';
7
8
  import type { AnalyticsEventPayload } from '../analytics/events';
8
9
  type ActionResult = {
9
10
  step: Step;
@@ -48,7 +49,7 @@ export default class RendererActions implements RendererActionsOptions, Annotati
48
49
  _privateValidatePositionsForAnnotation(from: number, to: number): boolean;
49
50
  _privateWhyCannotApplyAnnotationOnRange: (pos: Position, doc: Node, schema: Schema) => string;
50
51
  deleteAnnotation(annotationId: string, annotationType: 'inlineComment'): false | {
51
- step: Step;
52
+ step: RemoveNodeMarkStep | RemoveMarkStep;
52
53
  doc: JSONDocNode;
53
54
  };
54
55
  annotate(range: Range, annotationId: string, annotationType: 'inlineComment'): AnnotationActionResult;
@@ -14,4 +14,4 @@ export declare function BreakoutSSRInlineScript({ noOpSSRInlineScript }: {
14
14
  }): React.JSX.Element | null;
15
15
  export declare function createBreakoutInlineScript(id: number, optionalFlagArg?: boolean): string;
16
16
  export declare const breakoutInlineScriptContext: string;
17
- export declare const calcLineLength: any;
17
+ export declare const calcLineLength: () => number;
@@ -4,6 +4,7 @@ import type { AnnotationActionResult, AnnotationByMatches } from '@atlaskit/edit
4
4
  import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
5
5
  import type { Mark, Node, Schema } from '@atlaskit/editor-prosemirror/model';
6
6
  import type { Step } from '@atlaskit/editor-prosemirror/transform';
7
+ import { RemoveMarkStep, RemoveNodeMarkStep } from '@atlaskit/editor-prosemirror/transform';
7
8
  import type { AnalyticsEventPayload } from '../analytics/events';
8
9
  type ActionResult = {
9
10
  step: Step;
@@ -48,7 +49,7 @@ export default class RendererActions implements RendererActionsOptions, Annotati
48
49
  _privateValidatePositionsForAnnotation(from: number, to: number): boolean;
49
50
  _privateWhyCannotApplyAnnotationOnRange: (pos: Position, doc: Node, schema: Schema) => string;
50
51
  deleteAnnotation(annotationId: string, annotationType: 'inlineComment'): false | {
51
- step: Step;
52
+ step: RemoveNodeMarkStep | RemoveMarkStep;
52
53
  doc: JSONDocNode;
53
54
  };
54
55
  annotate(range: Range, annotationId: string, annotationType: 'inlineComment'): AnnotationActionResult;
@@ -14,4 +14,4 @@ export declare function BreakoutSSRInlineScript({ noOpSSRInlineScript }: {
14
14
  }): React.JSX.Element | null;
15
15
  export declare function createBreakoutInlineScript(id: number, optionalFlagArg?: boolean): string;
16
16
  export declare const breakoutInlineScriptContext: string;
17
- export declare const calcLineLength: any;
17
+ export declare const calcLineLength: () => number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/renderer",
3
- "version": "118.5.0",
3
+ "version": "118.6.0",
4
4
  "description": "Renderer component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -31,7 +31,7 @@
31
31
  "@atlaskit/analytics-next": "^11.0.0",
32
32
  "@atlaskit/button": "^23.2.0",
33
33
  "@atlaskit/code": "^17.2.0",
34
- "@atlaskit/editor-common": "^106.0.0",
34
+ "@atlaskit/editor-common": "^106.1.0",
35
35
  "@atlaskit/editor-json-transformer": "^8.24.0",
36
36
  "@atlaskit/editor-palette": "^2.1.0",
37
37
  "@atlaskit/editor-prosemirror": "7.0.0",
@@ -172,14 +172,6 @@
172
172
  "confluence-frontend-comments-panel": {
173
173
  "type": "boolean"
174
174
  },
175
- "platform_editor_table_row_span_fix": {
176
- "type": "boolean",
177
- "referenceOnly": true
178
- },
179
- "platform_editor_table_row_span_fix_all": {
180
- "type": "boolean",
181
- "referenceOnly": true
182
- },
183
175
  "platform_editor_fix_vc90_bug_with_files": {
184
176
  "type": "boolean"
185
177
  },