@atlaskit/renderer 109.8.4 → 109.10.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/react/nodes/mediaSingle/index.js +4 -2
  3. package/dist/cjs/ui/MediaCard.js +16 -3
  4. package/dist/cjs/ui/Renderer/index.js +6 -6
  5. package/dist/cjs/ui/annotations/contexts/AnnotationRangeContext.js +136 -0
  6. package/dist/cjs/ui/annotations/element/mark.js +1 -1
  7. package/dist/cjs/ui/annotations/hooks/user-selection.js +10 -11
  8. package/dist/cjs/ui/annotations/hover/index.js +12 -0
  9. package/dist/cjs/ui/annotations/hover/mounter.js +134 -0
  10. package/dist/cjs/ui/annotations/hover/range-validator.js +43 -0
  11. package/dist/cjs/ui/annotations/index.js +7 -3
  12. package/dist/cjs/ui/annotations/selection/index.js +3 -3
  13. package/dist/cjs/ui/annotations/{selection/wrapper.js → wrapper.js} +15 -7
  14. package/dist/es2019/react/nodes/mediaSingle/index.js +4 -2
  15. package/dist/es2019/ui/MediaCard.js +17 -3
  16. package/dist/es2019/ui/Renderer/index.js +6 -6
  17. package/dist/es2019/ui/annotations/contexts/AnnotationRangeContext.js +112 -0
  18. package/dist/es2019/ui/annotations/element/mark.js +5 -1
  19. package/dist/es2019/ui/annotations/hooks/user-selection.js +13 -7
  20. package/dist/es2019/ui/annotations/hover/index.js +1 -0
  21. package/dist/es2019/ui/annotations/hover/mounter.js +121 -0
  22. package/dist/es2019/ui/annotations/hover/range-validator.js +38 -0
  23. package/dist/es2019/ui/annotations/index.js +7 -3
  24. package/dist/es2019/ui/annotations/selection/index.js +1 -1
  25. package/dist/es2019/ui/annotations/{selection/wrapper.js → wrapper.js} +14 -6
  26. package/dist/esm/react/nodes/mediaSingle/index.js +4 -2
  27. package/dist/esm/ui/MediaCard.js +16 -3
  28. package/dist/esm/ui/Renderer/index.js +6 -6
  29. package/dist/esm/ui/annotations/contexts/AnnotationRangeContext.js +126 -0
  30. package/dist/esm/ui/annotations/element/mark.js +2 -2
  31. package/dist/esm/ui/annotations/hooks/user-selection.js +11 -11
  32. package/dist/esm/ui/annotations/hover/index.js +1 -0
  33. package/dist/esm/ui/annotations/hover/mounter.js +124 -0
  34. package/dist/esm/ui/annotations/hover/range-validator.js +34 -0
  35. package/dist/esm/ui/annotations/index.js +7 -3
  36. package/dist/esm/ui/annotations/selection/index.js +1 -1
  37. package/dist/esm/ui/annotations/{selection/wrapper.js → wrapper.js} +14 -6
  38. package/dist/types/react/nodes/mediaSingle/index.d.ts +1 -0
  39. package/dist/types/ui/MediaCard.d.ts +1 -0
  40. package/dist/types/ui/annotations/contexts/AnnotationRangeContext.d.ts +22 -0
  41. package/dist/types/ui/annotations/hover/index.d.ts +1 -0
  42. package/dist/types/ui/annotations/hover/mounter.d.ts +20 -0
  43. package/dist/types/ui/annotations/hover/range-validator.d.ts +13 -0
  44. package/dist/types/ui/annotations/selection/index.d.ts +1 -1
  45. package/dist/{types-ts4.5/ui/annotations/selection → types/ui/annotations}/wrapper.d.ts +1 -1
  46. package/dist/types-ts4.5/react/nodes/mediaSingle/index.d.ts +1 -0
  47. package/dist/types-ts4.5/ui/MediaCard.d.ts +1 -0
  48. package/dist/types-ts4.5/ui/annotations/contexts/AnnotationRangeContext.d.ts +22 -0
  49. package/dist/types-ts4.5/ui/annotations/hover/index.d.ts +1 -0
  50. package/dist/types-ts4.5/ui/annotations/hover/mounter.d.ts +20 -0
  51. package/dist/types-ts4.5/ui/annotations/hover/range-validator.d.ts +13 -0
  52. package/dist/types-ts4.5/ui/annotations/selection/index.d.ts +1 -1
  53. package/dist/{types/ui/annotations/selection → types-ts4.5/ui/annotations}/wrapper.d.ts +1 -1
  54. package/package.json +5 -4
@@ -56,7 +56,8 @@ const MediaSingle = props => {
56
56
  width: widthAttr,
57
57
  widthType,
58
58
  allowCaptions = false,
59
- isInsideOfInlineExtension = false
59
+ isInsideOfInlineExtension = false,
60
+ dataAttributes
60
61
  } = props;
61
62
  const [externalImageDimensions, setExternalImageDimensions] = React.useState({
62
63
  width: 0,
@@ -165,7 +166,8 @@ const MediaSingle = props => {
165
166
  widthType
166
167
  },
167
168
  fullWidthMode: isFullWidth,
168
- isInsideOfInlineExtension: isInsideOfInlineExtension
169
+ isInsideOfInlineExtension: isInsideOfInlineExtension,
170
+ dataAttributes: dataAttributes
169
171
  }, jsx(Fragment, null, mediaComponent), allowCaptions && caption);
170
172
  };
171
173
  return jsx(WidthConsumer, null, ({
@@ -5,6 +5,7 @@ import { filter } from '@atlaskit/adf-utils/traverse';
5
5
  import { Card, CardLoading, CardError } from '@atlaskit/media-card';
6
6
  import { MediaClientContext } from '@atlaskit/media-client-react';
7
7
  import { withImageLoader } from '@atlaskit/editor-common/utils';
8
+ import { useAnnotationRangeDispatch } from './annotations/contexts/AnnotationRangeContext';
8
9
  export const mediaIdentifierMap = new Map();
9
10
  export const getListOfIdentifiersFromDoc = doc => {
10
11
  if (!doc) {
@@ -199,7 +200,8 @@ export class MediaCardView extends Component {
199
200
  featureFlags,
200
201
  shouldEnableDownloadButton,
201
202
  ssr,
202
- mediaClient
203
+ mediaClient,
204
+ setHoverTarget
203
205
  } = this.props;
204
206
  const isMobile = rendererAppearance === 'mobile';
205
207
  const shouldPlayInline = useInlinePlayer !== undefined ? useInlinePlayer : true;
@@ -228,13 +230,21 @@ export class MediaCardView extends Component {
228
230
  collectionName: collection,
229
231
  occurrenceKey
230
232
  };
231
- return /*#__PURE__*/React.createElement("div", getClipboardAttrs({
233
+ return /*#__PURE__*/React.createElement("div", _extends({}, getClipboardAttrs({
232
234
  id,
233
235
  alt,
234
236
  collection,
235
237
  contextIdentifierProvider,
236
238
  originalDimensions,
237
239
  fileState
240
+ }), {
241
+ onMouseEnter: event => {
242
+ // We will not allow a hover target to be set if any mouse button is depressed during the mouse enter state.
243
+ // This could be due to the user trying to select text across the document.
244
+ if (event.buttons === 0) {
245
+ setHoverTarget && setHoverTarget(event.target);
246
+ }
247
+ }
238
248
  }), /*#__PURE__*/React.createElement(Card, {
239
249
  identifier: identifier,
240
250
  alt: alt,
@@ -292,8 +302,12 @@ export const getClipboardAttrs = ({
292
302
  };
293
303
  export const MediaCardInternal = props => {
294
304
  const mediaClient = useContext(MediaClientContext);
305
+ const {
306
+ setHoverTarget
307
+ } = useAnnotationRangeDispatch();
295
308
  return /*#__PURE__*/React.createElement(MediaCardView, _extends({}, props, {
296
- mediaClient: mediaClient
309
+ mediaClient: mediaClient,
310
+ setHoverTarget: setHoverTarget
297
311
  }));
298
312
  };
299
313
  export const MediaCard = withImageLoader(MediaCardInternal);
@@ -36,7 +36,7 @@ import { EditorMediaClientProvider } from '../../react/utils/EditorMediaClientPr
36
36
  export const NORMAL_SEVERITY_THRESHOLD = 2000;
37
37
  export const DEGRADED_SEVERITY_THRESHOLD = 3000;
38
38
  const packageName = "@atlaskit/renderer";
39
- const packageVersion = "109.8.4";
39
+ const packageVersion = "109.10.0";
40
40
  export class Renderer extends PureComponent {
41
41
  constructor(props) {
42
42
  super(props);
@@ -330,7 +330,7 @@ export class Renderer extends PureComponent {
330
330
  }
331
331
  };
332
332
  try {
333
- var _featureFlags$feature, _this$featureFlags, _this$featureFlags$fe, _this$featureFlags$fe2;
333
+ var _featureFlags$feature, _featureFlags$feature2, _featureFlags$feature3;
334
334
  const schema = this.getSchema(this.props.schema, this.props.adfStage);
335
335
  const {
336
336
  result,
@@ -341,7 +341,7 @@ export class Renderer extends PureComponent {
341
341
  onComplete(stat);
342
342
  }
343
343
  const rendererOutput = jsx(RendererContextProvider, {
344
- value: this.featureFlags(this.props.featureFlags)
344
+ value: featureFlags
345
345
  }, jsx(ActiveHeaderIdProvider, {
346
346
  value: getActiveHeadingId(allowHeadingAnchorLinks)
347
347
  }, jsx(AnalyticsContext.Provider, {
@@ -374,7 +374,7 @@ export class Renderer extends PureComponent {
374
374
  height: maxHeight,
375
375
  fadeHeight: fadeOutHeight
376
376
  }, rendererOutput) : rendererOutput;
377
- const rendererRenderTracking = (_this$featureFlags = this.featureFlags(this.props.featureFlags)) === null || _this$featureFlags === void 0 ? void 0 : (_this$featureFlags$fe = _this$featureFlags.featureFlags) === null || _this$featureFlags$fe === void 0 ? void 0 : (_this$featureFlags$fe2 = _this$featureFlags$fe.rendererRenderTracking) === null || _this$featureFlags$fe2 === void 0 ? void 0 : _this$featureFlags$fe2[ACTION_SUBJECT.RENDERER];
377
+ const rendererRenderTracking = featureFlags === null || featureFlags === void 0 ? void 0 : (_featureFlags$feature2 = featureFlags.featureFlags) === null || _featureFlags$feature2 === void 0 ? void 0 : (_featureFlags$feature3 = _featureFlags$feature2.rendererRenderTracking) === null || _featureFlags$feature3 === void 0 ? void 0 : _featureFlags$feature3[ACTION_SUBJECT.RENDERER];
378
378
  const reRenderTracking = (rendererRenderTracking === null || rendererRenderTracking === void 0 ? void 0 : rendererRenderTracking.enabled) && jsx(RenderTracking, {
379
379
  componentProps: this.props,
380
380
  action: ACTION.RE_RENDERED,
@@ -384,7 +384,7 @@ export class Renderer extends PureComponent {
384
384
  });
385
385
  return jsx(Fragment, null, reRenderTracking, rendererResult);
386
386
  } catch (e) {
387
- var _featureFlags$feature2;
387
+ var _featureFlags$feature4;
388
388
  if (onError) {
389
389
  onError(e);
390
390
  }
@@ -395,7 +395,7 @@ export class Renderer extends PureComponent {
395
395
  allowPlaceholderText: allowPlaceholderText,
396
396
  allowColumnSorting: allowColumnSorting,
397
397
  allowNestedHeaderLinks: allowNestedHeaderLinks,
398
- useBlockRenderForCodeBlock: (_featureFlags$feature2 = featureFlags.featureFlags.useBlockRenderForCodeBlock) !== null && _featureFlags$feature2 !== void 0 ? _featureFlags$feature2 : true,
398
+ useBlockRenderForCodeBlock: (_featureFlags$feature4 = featureFlags.featureFlags.useBlockRenderForCodeBlock) !== null && _featureFlags$feature4 !== void 0 ? _featureFlags$feature4 : true,
399
399
  addTelepointer: this.props.addTelepointer,
400
400
  onClick: handleWrapperOnClick
401
401
  }, jsx(UnsupportedBlock, null));
@@ -0,0 +1,112 @@
1
+ import React, { createContext, useCallback, useContext, useMemo, useReducer } from 'react';
2
+ function reducer(state, action) {
3
+ switch (action.type) {
4
+ case 'clear':
5
+ if (!!state.range || !!state.type) {
6
+ return {
7
+ range: null,
8
+ type: null
9
+ };
10
+ }
11
+ return state;
12
+ case 'clearSelection':
13
+ if (state.type === 'selection') {
14
+ return {
15
+ range: null,
16
+ type: null
17
+ };
18
+ }
19
+ return state;
20
+ case 'clearHover':
21
+ if (state.type === 'hover') {
22
+ return {
23
+ range: null,
24
+ type: null
25
+ };
26
+ }
27
+ return state;
28
+ case 'setSelection':
29
+ if (state.range !== action.range || state.type !== 'selection') {
30
+ return {
31
+ range: action.range,
32
+ type: 'selection'
33
+ };
34
+ }
35
+ return state;
36
+ case 'setHover':
37
+ if (state.range !== action.range || state.type !== 'hover') {
38
+ return {
39
+ range: action.range,
40
+ type: 'hover'
41
+ };
42
+ }
43
+ return state;
44
+ }
45
+ return state;
46
+ }
47
+ export const AnnotationRangeStateContext = /*#__PURE__*/createContext({
48
+ range: null,
49
+ type: null
50
+ });
51
+ export const AnnotationRangeDispatchContext = /*#__PURE__*/createContext({
52
+ clearRange: () => {},
53
+ clearSelectionRange: () => {},
54
+ clearHoverRange: () => {},
55
+ setRange: () => {}
56
+ });
57
+ export const AnnotationRangeProvider = ({
58
+ children,
59
+ allowCommentsOnMedia
60
+ }) => {
61
+ const [{
62
+ range,
63
+ type
64
+ }, dispatch] = useReducer(reducer, {
65
+ range: null,
66
+ type: null
67
+ });
68
+ const clearRange = useCallback(() => dispatch({
69
+ type: 'clear'
70
+ }), []);
71
+ const clearSelectionRange = useCallback(() => dispatch({
72
+ type: 'clearSelection'
73
+ }), []);
74
+ const clearHoverRange = useCallback(() => dispatch({
75
+ type: 'clearHover'
76
+ }), []);
77
+ const setRange = useCallback(range => dispatch({
78
+ type: 'setSelection',
79
+ range
80
+ }), []);
81
+ const setHoverTarget = useCallback(target => {
82
+ const range = document.createRange();
83
+ range.setStartBefore(target);
84
+ range.setEndAfter(target);
85
+ dispatch({
86
+ type: 'setHover',
87
+ range
88
+ });
89
+ }, []);
90
+ const stateData = useMemo(() => ({
91
+ range,
92
+ type
93
+ }), [range, type]);
94
+ const dispatchData = useMemo(() => ({
95
+ clearRange,
96
+ clearSelectionRange,
97
+ clearHoverRange,
98
+ setRange,
99
+ setHoverTarget: !!allowCommentsOnMedia ? setHoverTarget : undefined
100
+ }), [allowCommentsOnMedia, clearRange, clearSelectionRange, clearHoverRange, setRange, setHoverTarget]);
101
+ return /*#__PURE__*/React.createElement(AnnotationRangeStateContext.Provider, {
102
+ value: stateData
103
+ }, /*#__PURE__*/React.createElement(AnnotationRangeDispatchContext.Provider, {
104
+ value: dispatchData
105
+ }, children));
106
+ };
107
+ export const useAnnotationRangeState = () => {
108
+ return useContext(AnnotationRangeStateContext);
109
+ };
110
+ export const useAnnotationRangeDispatch = () => {
111
+ return useContext(AnnotationRangeDispatchContext);
112
+ };
@@ -3,7 +3,7 @@ import _extends from "@babel/runtime/helpers/extends";
3
3
 
4
4
  import React, { useMemo, useCallback } from 'react';
5
5
  import { css, jsx } from '@emotion/react';
6
- import { AnnotationSharedCSSByState } from '@atlaskit/editor-common/styles';
6
+ import { AnnotationSharedCSSByState, mediaAnnotationStyles } from '@atlaskit/editor-common/styles';
7
7
  import { AnnotationMarkStates } from '@atlaskit/adf-schema';
8
8
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
9
 
@@ -20,6 +20,10 @@ const markStyles = () => css`
20
20
  &[data-has-focus='true'] {
21
21
  ${AnnotationSharedCSSByState().focus};
22
22
  }
23
+
24
+ & div.rich-media-item {
25
+ ${mediaAnnotationStyles};
26
+ }
23
27
  }
24
28
  `;
25
29
  export const MarkComponent = ({
@@ -1,4 +1,5 @@
1
- import { useContext, useCallback, useEffect, useState } from 'react';
1
+ import { useContext, useEffect } from 'react';
2
+ import { useAnnotationRangeDispatch, useAnnotationRangeState } from '../contexts/AnnotationRangeContext';
2
3
  import { AnnotationsDraftContext } from '../context';
3
4
  import { isRangeInsideOfRendererContainer } from './utils';
4
5
  export const useUserSelectionRange = props => {
@@ -7,7 +8,14 @@ export const useUserSelectionRange = props => {
7
8
  current: rendererDOM
8
9
  }
9
10
  } = props;
10
- const [range, setRange] = useState(null);
11
+ const {
12
+ clearSelectionRange,
13
+ setRange
14
+ } = useAnnotationRangeDispatch();
15
+ const {
16
+ range,
17
+ type
18
+ } = useAnnotationRangeState();
11
19
  const annotationDraftPosition = useContext(AnnotationsDraftContext);
12
20
  const hasAnnotationDraft = !!annotationDraftPosition;
13
21
  useEffect(() => {
@@ -27,10 +35,8 @@ export const useUserSelectionRange = props => {
27
35
  document.addEventListener('selectionchange', onSelectionChange);
28
36
  return () => {
29
37
  document.removeEventListener('selectionchange', onSelectionChange);
38
+ clearSelectionRange();
30
39
  };
31
- }, [rendererDOM, range, hasAnnotationDraft]);
32
- const clearRange = useCallback(() => {
33
- setRange(null);
34
- }, []);
35
- return [range, clearRange];
40
+ }, [rendererDOM, hasAnnotationDraft, setRange, clearSelectionRange]);
41
+ return [type === 'selection' ? range : null, clearSelectionRange];
36
42
  };
@@ -0,0 +1 @@
1
+ export { RangeValidator as HoverRangeValidator } from './range-validator';
@@ -0,0 +1,121 @@
1
+ import React, { useCallback, useState, useContext } from 'react';
2
+ import { AnnotationTypes } from '@atlaskit/adf-schema';
3
+ import { updateWindowSelectionAroundDraft } from '../draft';
4
+ import { FabricChannel } from '@atlaskit/analytics-listeners';
5
+ import { ACTION, ACTION_SUBJECT, EVENT_TYPE, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
6
+ import { RendererContext as ActionsContext } from '../../RendererActionsContext';
7
+ export const Mounter = /*#__PURE__*/React.memo(props => {
8
+ const {
9
+ component: Component,
10
+ range,
11
+ isAnnotationAllowed,
12
+ wrapperDOM,
13
+ onClose: onCloseProps,
14
+ clearAnnotationDraft,
15
+ applyAnnotationDraftAt,
16
+ documentPosition,
17
+ applyAnnotation,
18
+ createAnalyticsEvent,
19
+ generateIndexMatch
20
+ } = props;
21
+ const [draftDocumentPosition, setDraftDocumentPosition] = useState();
22
+ const actions = useContext(ActionsContext);
23
+ const onCreateCallback = useCallback(annotationId => {
24
+ if (!isAnnotationAllowed || !documentPosition || !applyAnnotation) {
25
+ return false;
26
+ }
27
+ const annotation = {
28
+ annotationId,
29
+ annotationType: AnnotationTypes.INLINE_COMMENT
30
+ };
31
+ if (createAnalyticsEvent) {
32
+ createAnalyticsEvent({
33
+ action: ACTION.INSERTED,
34
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
35
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
36
+ attributes: {},
37
+ eventType: EVENT_TYPE.TRACK
38
+ }).fire(FabricChannel.editor);
39
+ }
40
+ return applyAnnotation(draftDocumentPosition || documentPosition, annotation);
41
+ }, [isAnnotationAllowed, documentPosition, applyAnnotation, draftDocumentPosition, createAnalyticsEvent]);
42
+ const createIndexCallback = useCallback(() => {
43
+ if (!documentPosition || !generateIndexMatch) {
44
+ return false;
45
+ }
46
+ const result = generateIndexMatch(documentPosition);
47
+ if (!result) {
48
+ return false;
49
+ }
50
+ return result;
51
+ }, [documentPosition, generateIndexMatch]);
52
+ const applyDraftModeCallback = useCallback((keepNativeSelection = true) => {
53
+ if (!documentPosition || !isAnnotationAllowed) {
54
+ if (createAnalyticsEvent) {
55
+ createAnalyticsEvent({
56
+ action: ACTION.CREATE_NOT_ALLOWED,
57
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
58
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
59
+ attributes: {},
60
+ eventType: EVENT_TYPE.TRACK
61
+ }).fire(FabricChannel.editor);
62
+ }
63
+ return;
64
+ }
65
+ setDraftDocumentPosition(documentPosition);
66
+ applyAnnotationDraftAt(documentPosition);
67
+ if (createAnalyticsEvent) {
68
+ const uniqueAnnotationsInRange = actions.getAnnotationsByPosition(range);
69
+ createAnalyticsEvent({
70
+ action: ACTION.OPENED,
71
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
72
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
73
+ eventType: EVENT_TYPE.TRACK,
74
+ attributes: {
75
+ overlap: uniqueAnnotationsInRange.length
76
+ }
77
+ }).fire(FabricChannel.editor);
78
+ }
79
+ window.requestAnimationFrame(() => {
80
+ if (keepNativeSelection) {
81
+ updateWindowSelectionAroundDraft(documentPosition);
82
+ } else {
83
+ const sel = window.getSelection();
84
+ if (sel) {
85
+ sel.removeAllRanges();
86
+ }
87
+ }
88
+ });
89
+ }, [documentPosition, isAnnotationAllowed, applyAnnotationDraftAt, createAnalyticsEvent, actions, range]);
90
+ const removeDraftModeCallback = useCallback(() => {
91
+ clearAnnotationDraft();
92
+ setDraftDocumentPosition(null);
93
+ const sel = window.getSelection();
94
+ if (sel) {
95
+ sel.removeAllRanges();
96
+ }
97
+ }, [clearAnnotationDraft]);
98
+ const onCloseCallback = useCallback(() => {
99
+ if (createAnalyticsEvent) {
100
+ createAnalyticsEvent({
101
+ action: ACTION.CLOSED,
102
+ actionSubject: ACTION_SUBJECT.ANNOTATION,
103
+ actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
104
+ eventType: EVENT_TYPE.TRACK,
105
+ attributes: {}
106
+ }).fire(FabricChannel.editor);
107
+ }
108
+ removeDraftModeCallback();
109
+ onCloseProps();
110
+ }, [onCloseProps, removeDraftModeCallback, createAnalyticsEvent]);
111
+ return /*#__PURE__*/React.createElement(Component, {
112
+ range: range,
113
+ wrapperDOM: wrapperDOM.current,
114
+ isAnnotationAllowed: isAnnotationAllowed,
115
+ onClose: onCloseCallback,
116
+ onCreate: onCreateCallback,
117
+ getAnnotationIndexMatch: createIndexCallback,
118
+ applyDraftMode: applyDraftModeCallback,
119
+ removeDraftMode: removeDraftModeCallback
120
+ });
121
+ });
@@ -0,0 +1,38 @@
1
+ import React, { useContext } from 'react';
2
+ import { Mounter } from './mounter';
3
+ import { RendererContext as ActionsContext } from '../../RendererActionsContext';
4
+ import { useAnnotationRangeDispatch, useAnnotationRangeState } from '../contexts/AnnotationRangeContext';
5
+ export const RangeValidator = props => {
6
+ const {
7
+ component,
8
+ rendererRef,
9
+ applyAnnotationDraftAt,
10
+ clearAnnotationDraft,
11
+ createAnalyticsEvent
12
+ } = props;
13
+ const actions = useContext(ActionsContext);
14
+ const {
15
+ clearHoverRange
16
+ } = useAnnotationRangeDispatch();
17
+ const {
18
+ range,
19
+ type
20
+ } = useAnnotationRangeState();
21
+ if (!range || type !== 'hover') {
22
+ return null;
23
+ }
24
+ const documentPosition = actions.getPositionFromRange(range);
25
+ return /*#__PURE__*/React.createElement(Mounter, {
26
+ range: range,
27
+ wrapperDOM: rendererRef,
28
+ component: component,
29
+ onClose: clearHoverRange,
30
+ documentPosition: documentPosition,
31
+ isAnnotationAllowed: true,
32
+ applyAnnotation: actions.applyAnnotation.bind(actions),
33
+ applyAnnotationDraftAt: applyAnnotationDraftAt,
34
+ generateIndexMatch: actions.generateAnnotationIndexMatch.bind(actions),
35
+ clearAnnotationDraft: clearAnnotationDraft,
36
+ createAnalyticsEvent: createAnalyticsEvent
37
+ });
38
+ };
@@ -1,11 +1,12 @@
1
1
  import React from 'react';
2
2
  import { AnnotationTypes } from '@atlaskit/adf-schema';
3
3
  import { AnnotationView } from './view';
4
- import { SelectionComponentWrapper } from './selection';
4
+ import { AnnotationsContextWrapper } from './wrapper';
5
5
  import { ProvidersContext, InlineCommentsStateContext } from './context';
6
6
  import { useLoadAnnotations } from './hooks/use-load-annotations';
7
7
  import { useAnnotationStateByTypeEvent } from './hooks/use-events';
8
8
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
9
+ import { AnnotationRangeProvider } from './contexts/AnnotationRangeContext';
9
10
  const LoadAnnotations = /*#__PURE__*/React.memo(({
10
11
  adfDocument
11
12
  }) => {
@@ -15,6 +16,7 @@ const LoadAnnotations = /*#__PURE__*/React.memo(({
15
16
  return null;
16
17
  });
17
18
  export const AnnotationsWrapper = props => {
19
+ var _annotationProvider$i, _annotationProvider$i2;
18
20
  const {
19
21
  children,
20
22
  annotationProvider,
@@ -33,14 +35,16 @@ export const AnnotationsWrapper = props => {
33
35
  value: annotationProvider
34
36
  }, /*#__PURE__*/React.createElement(InlineCommentsStateContext.Provider, {
35
37
  value: inlineCommentAnnotationsState
36
- }, /*#__PURE__*/React.createElement(SelectionComponentWrapper, {
38
+ }, /*#__PURE__*/React.createElement(AnnotationRangeProvider, {
39
+ allowCommentsOnMedia: (_annotationProvider$i = annotationProvider === null || annotationProvider === void 0 ? void 0 : (_annotationProvider$i2 = annotationProvider.inlineComment) === null || _annotationProvider$i2 === void 0 ? void 0 : _annotationProvider$i2.allowCommentsOnMedia) !== null && _annotationProvider$i !== void 0 ? _annotationProvider$i : false
40
+ }, /*#__PURE__*/React.createElement(AnnotationsContextWrapper, {
37
41
  createAnalyticsEvent: createAnalyticsEvent,
38
42
  rendererRef: rendererRef
39
43
  }, /*#__PURE__*/React.createElement(LoadAnnotations, {
40
44
  adfDocument: adfDocument
41
45
  }), /*#__PURE__*/React.createElement(AnnotationView, {
42
46
  createAnalyticsEvent: createAnalyticsEvent
43
- }), children)));
47
+ }), children))));
44
48
  };
45
49
  export { TextWithAnnotationDraft } from './draft';
46
50
  export { MarkElement as AnnotationMark } from './element';
@@ -1 +1 @@
1
- export { Wrapper as SelectionComponentWrapper } from './wrapper';
1
+ export { SelectionRangeValidator } from './range-validator';
@@ -1,7 +1,8 @@
1
1
  import React, { useCallback, useContext } from 'react';
2
- import { AnnotationsDraftContextWrapper, ProvidersContext } from '../context';
3
- import { SelectionRangeValidator } from './range-validator';
4
- export const Wrapper = props => {
2
+ import { AnnotationsDraftContextWrapper, ProvidersContext } from './context';
3
+ import { HoverRangeValidator } from './hover';
4
+ import { SelectionRangeValidator } from './selection';
5
+ export const AnnotationsContextWrapper = props => {
5
6
  const providers = useContext(ProvidersContext);
6
7
  const {
7
8
  rendererRef,
@@ -10,19 +11,26 @@ export const Wrapper = props => {
10
11
  } = props;
11
12
  const inlineCommentProvider = providers && providers.inlineComment;
12
13
  const selectionComponent = inlineCommentProvider && inlineCommentProvider.selectionComponent;
14
+ const hoverComponent = inlineCommentProvider && inlineCommentProvider.hoverComponent;
13
15
  const render = useCallback(({
14
16
  applyAnnotationDraftAt,
15
17
  clearAnnotationDraft
16
18
  }) => {
17
- return /*#__PURE__*/React.createElement(React.Fragment, null, children, /*#__PURE__*/React.createElement(SelectionRangeValidator, {
19
+ return /*#__PURE__*/React.createElement(React.Fragment, null, children, !!hoverComponent && /*#__PURE__*/React.createElement(HoverRangeValidator, {
20
+ createAnalyticsEvent: createAnalyticsEvent,
21
+ rendererRef: rendererRef,
22
+ component: hoverComponent,
23
+ applyAnnotationDraftAt: applyAnnotationDraftAt,
24
+ clearAnnotationDraft: clearAnnotationDraft
25
+ }), !!selectionComponent && /*#__PURE__*/React.createElement(SelectionRangeValidator, {
18
26
  createAnalyticsEvent: createAnalyticsEvent,
19
27
  rendererRef: rendererRef,
20
28
  selectionComponent: selectionComponent,
21
29
  applyAnnotationDraftAt: applyAnnotationDraftAt,
22
30
  clearAnnotationDraft: clearAnnotationDraft
23
31
  }));
24
- }, [selectionComponent, children, rendererRef, createAnalyticsEvent]);
25
- if (!selectionComponent) {
32
+ }, [hoverComponent, selectionComponent, children, rendererRef, createAnalyticsEvent]);
33
+ if (!selectionComponent && !hoverComponent) {
26
34
  return /*#__PURE__*/React.createElement(React.Fragment, null, children);
27
35
  }
28
36
  return /*#__PURE__*/React.createElement(AnnotationsDraftContextWrapper, null, render);
@@ -59,7 +59,8 @@ var MediaSingle = function MediaSingle(props) {
59
59
  _props$allowCaptions = props.allowCaptions,
60
60
  allowCaptions = _props$allowCaptions === void 0 ? false : _props$allowCaptions,
61
61
  _props$isInsideOfInli = props.isInsideOfInlineExtension,
62
- isInsideOfInlineExtension = _props$isInsideOfInli === void 0 ? false : _props$isInsideOfInli;
62
+ isInsideOfInlineExtension = _props$isInsideOfInli === void 0 ? false : _props$isInsideOfInli,
63
+ dataAttributes = props.dataAttributes;
63
64
  var _React$useState = React.useState({
64
65
  width: 0,
65
66
  height: 0
@@ -170,7 +171,8 @@ var MediaSingle = function MediaSingle(props) {
170
171
  widthType: widthType
171
172
  },
172
173
  fullWidthMode: isFullWidth,
173
- isInsideOfInlineExtension: isInsideOfInlineExtension
174
+ isInsideOfInlineExtension: isInsideOfInlineExtension,
175
+ dataAttributes: dataAttributes
174
176
  }, jsx(Fragment, null, mediaComponent), allowCaptions && caption);
175
177
  };
176
178
  return jsx(WidthConsumer, null, function (_ref3) {
@@ -17,6 +17,7 @@ import { filter } from '@atlaskit/adf-utils/traverse';
17
17
  import { Card, CardLoading, CardError } from '@atlaskit/media-card';
18
18
  import { MediaClientContext } from '@atlaskit/media-client-react';
19
19
  import { withImageLoader } from '@atlaskit/editor-common/utils';
20
+ import { useAnnotationRangeDispatch } from './annotations/contexts/AnnotationRangeContext';
20
21
  export var mediaIdentifierMap = new Map();
21
22
  export var getListOfIdentifiersFromDoc = function getListOfIdentifiersFromDoc(doc) {
22
23
  if (!doc) {
@@ -257,7 +258,8 @@ export var MediaCardView = /*#__PURE__*/function (_Component) {
257
258
  featureFlags = _this$props5.featureFlags,
258
259
  shouldEnableDownloadButton = _this$props5.shouldEnableDownloadButton,
259
260
  ssr = _this$props5.ssr,
260
- mediaClient = _this$props5.mediaClient;
261
+ mediaClient = _this$props5.mediaClient,
262
+ setHoverTarget = _this$props5.setHoverTarget;
261
263
  var isMobile = rendererAppearance === 'mobile';
262
264
  var shouldPlayInline = useInlinePlayer !== undefined ? useInlinePlayer : true;
263
265
  var isInlinePlayer = isMobile ? false : shouldPlayInline;
@@ -285,13 +287,21 @@ export var MediaCardView = /*#__PURE__*/function (_Component) {
285
287
  collectionName: collection,
286
288
  occurrenceKey: occurrenceKey
287
289
  };
288
- return /*#__PURE__*/React.createElement("div", getClipboardAttrs({
290
+ return /*#__PURE__*/React.createElement("div", _extends({}, getClipboardAttrs({
289
291
  id: id,
290
292
  alt: alt,
291
293
  collection: collection,
292
294
  contextIdentifierProvider: contextIdentifierProvider,
293
295
  originalDimensions: originalDimensions,
294
296
  fileState: fileState
297
+ }), {
298
+ onMouseEnter: function onMouseEnter(event) {
299
+ // We will not allow a hover target to be set if any mouse button is depressed during the mouse enter state.
300
+ // This could be due to the user trying to select text across the document.
301
+ if (event.buttons === 0) {
302
+ setHoverTarget && setHoverTarget(event.target);
303
+ }
304
+ }
295
305
  }), /*#__PURE__*/React.createElement(Card, {
296
306
  identifier: identifier,
297
307
  alt: alt,
@@ -350,8 +360,11 @@ export var getClipboardAttrs = function getClipboardAttrs(_ref2) {
350
360
  };
351
361
  export var MediaCardInternal = function MediaCardInternal(props) {
352
362
  var mediaClient = useContext(MediaClientContext);
363
+ var _useAnnotationRangeDi = useAnnotationRangeDispatch(),
364
+ setHoverTarget = _useAnnotationRangeDi.setHoverTarget;
353
365
  return /*#__PURE__*/React.createElement(MediaCardView, _extends({}, props, {
354
- mediaClient: mediaClient
366
+ mediaClient: mediaClient,
367
+ setHoverTarget: setHoverTarget
355
368
  }));
356
369
  };
357
370
  export var MediaCard = withImageLoader(MediaCardInternal);