@atlaskit/renderer 115.0.4 → 115.0.6

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 (68) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/actions/index.js +14 -8
  3. package/dist/cjs/react/nodes/media/index.js +5 -1
  4. package/dist/cjs/react/nodes/tableNew.js +9 -3
  5. package/dist/cjs/ui/Renderer/RendererStyleContainer.js +6 -1
  6. package/dist/cjs/ui/Renderer/index.js +4 -5
  7. package/dist/cjs/ui/annotations/context.js +14 -1
  8. package/dist/cjs/ui/annotations/contexts/AnnotationRangeContext.js +199 -35
  9. package/dist/cjs/ui/annotations/draft/component.js +6 -1
  10. package/dist/cjs/ui/annotations/element/useInlineAnnotationProps.js +5 -1
  11. package/dist/cjs/ui/annotations/hooks/user-selection.js +14 -9
  12. package/dist/cjs/ui/annotations/hover/mounter.js +31 -10
  13. package/dist/cjs/ui/annotations/hover/range-validator.js +2 -1
  14. package/dist/cjs/ui/annotations/index.js +2 -1
  15. package/dist/cjs/ui/annotations/selection/mounter.js +41 -12
  16. package/dist/cjs/ui/annotations/selection/range-validator.js +10 -7
  17. package/dist/cjs/ui/annotations/wrapper.js +48 -2
  18. package/dist/es2019/actions/index.js +12 -8
  19. package/dist/es2019/react/nodes/media/index.js +6 -1
  20. package/dist/es2019/react/nodes/tableNew.js +9 -3
  21. package/dist/es2019/ui/Renderer/RendererStyleContainer.js +8 -1
  22. package/dist/es2019/ui/Renderer/index.js +4 -5
  23. package/dist/es2019/ui/annotations/context.js +14 -1
  24. package/dist/es2019/ui/annotations/contexts/AnnotationRangeContext.js +207 -30
  25. package/dist/es2019/ui/annotations/draft/component.js +7 -1
  26. package/dist/es2019/ui/annotations/element/useInlineAnnotationProps.js +6 -1
  27. package/dist/es2019/ui/annotations/hooks/user-selection.js +14 -9
  28. package/dist/es2019/ui/annotations/hover/mounter.js +33 -10
  29. package/dist/es2019/ui/annotations/hover/range-validator.js +2 -1
  30. package/dist/es2019/ui/annotations/index.js +2 -1
  31. package/dist/es2019/ui/annotations/selection/mounter.js +43 -12
  32. package/dist/es2019/ui/annotations/selection/range-validator.js +6 -4
  33. package/dist/es2019/ui/annotations/wrapper.js +49 -1
  34. package/dist/esm/actions/index.js +14 -8
  35. package/dist/esm/react/nodes/media/index.js +5 -1
  36. package/dist/esm/react/nodes/tableNew.js +9 -3
  37. package/dist/esm/ui/Renderer/RendererStyleContainer.js +6 -1
  38. package/dist/esm/ui/Renderer/index.js +4 -5
  39. package/dist/esm/ui/annotations/context.js +14 -1
  40. package/dist/esm/ui/annotations/contexts/AnnotationRangeContext.js +198 -34
  41. package/dist/esm/ui/annotations/draft/component.js +6 -1
  42. package/dist/esm/ui/annotations/element/useInlineAnnotationProps.js +5 -1
  43. package/dist/esm/ui/annotations/hooks/user-selection.js +14 -9
  44. package/dist/esm/ui/annotations/hover/mounter.js +31 -10
  45. package/dist/esm/ui/annotations/hover/range-validator.js +2 -1
  46. package/dist/esm/ui/annotations/index.js +2 -1
  47. package/dist/esm/ui/annotations/selection/mounter.js +41 -12
  48. package/dist/esm/ui/annotations/selection/range-validator.js +10 -7
  49. package/dist/esm/ui/annotations/wrapper.js +47 -1
  50. package/dist/types/actions/index.d.ts +5 -0
  51. package/dist/types/ui/annotations/context.d.ts +13 -1
  52. package/dist/types/ui/annotations/contexts/AnnotationRangeContext.d.ts +46 -4
  53. package/dist/types/ui/annotations/hooks/user-selection.d.ts +2 -1
  54. package/dist/types/ui/annotations/hover/mounter.d.ts +10 -2
  55. package/dist/types/ui/annotations/hover/range-validator.d.ts +14 -3
  56. package/dist/types/ui/annotations/selection/mounter.d.ts +10 -2
  57. package/dist/types/ui/annotations/selection/range-validator.d.ts +14 -3
  58. package/dist/types/ui/annotations/wrapper.d.ts +2 -0
  59. package/dist/types-ts4.5/actions/index.d.ts +5 -0
  60. package/dist/types-ts4.5/ui/annotations/context.d.ts +13 -1
  61. package/dist/types-ts4.5/ui/annotations/contexts/AnnotationRangeContext.d.ts +46 -4
  62. package/dist/types-ts4.5/ui/annotations/hooks/user-selection.d.ts +2 -0
  63. package/dist/types-ts4.5/ui/annotations/hover/mounter.d.ts +10 -2
  64. package/dist/types-ts4.5/ui/annotations/hover/range-validator.d.ts +14 -3
  65. package/dist/types-ts4.5/ui/annotations/selection/mounter.d.ts +10 -2
  66. package/dist/types-ts4.5/ui/annotations/selection/range-validator.d.ts +14 -3
  67. package/dist/types-ts4.5/ui/annotations/wrapper.d.ts +2 -0
  68. package/package.json +8 -2
@@ -2,8 +2,9 @@ import React, { useCallback, useContext } from 'react';
2
2
  import { AnnotationsDraftContextWrapper, ProvidersContext } from './context';
3
3
  import { RangeValidator as HoverRangeValidator } from './hover/range-validator';
4
4
  import { SelectionRangeValidator } from './selection/range-validator';
5
+ import { fg } from '@atlaskit/platform-feature-flags';
5
6
  import { useAnnotationRangeDispatch, useAnnotationRangeState } from './contexts/AnnotationRangeContext';
6
- export const AnnotationsContextWrapper = props => {
7
+ export const AnnotationsContextWrapperOld = props => {
7
8
  const providers = useContext(ProvidersContext);
8
9
  const {
9
10
  range,
@@ -62,4 +63,51 @@ export const AnnotationsContextWrapper = props => {
62
63
  clearDraftRange: clearRangeForDraft,
63
64
  isNestedRender: isNestedRender
64
65
  }, render);
66
+ };
67
+ export const AnnotationsContextWrapperNew = props => {
68
+ const providers = useContext(ProvidersContext);
69
+ const {
70
+ rendererRef,
71
+ createAnalyticsEvent,
72
+ children
73
+ } = props;
74
+ const inlineCommentProvider = providers && providers.inlineComment;
75
+ const selectionComponent = inlineCommentProvider && inlineCommentProvider.selectionComponent;
76
+ const hoverComponent = inlineCommentProvider && inlineCommentProvider.hoverComponent;
77
+ if (!selectionComponent && !hoverComponent) {
78
+ return /*#__PURE__*/React.createElement(React.Fragment, null, children);
79
+ }
80
+ return /*#__PURE__*/React.createElement(React.Fragment, null, children, !!hoverComponent && /*#__PURE__*/React.createElement(HoverRangeValidator, {
81
+ createAnalyticsEvent: createAnalyticsEvent,
82
+ rendererRef: rendererRef
83
+ // Ignored via go/ees005
84
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
85
+ ,
86
+ component: hoverComponent
87
+ }), !!selectionComponent && /*#__PURE__*/React.createElement(SelectionRangeValidator, {
88
+ createAnalyticsEvent: createAnalyticsEvent,
89
+ rendererRef: rendererRef
90
+ // Ignored via go/ees005
91
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
92
+ ,
93
+ selectionComponent: selectionComponent
94
+ }));
95
+ };
96
+ export const AnnotationsContextWrapper = props => {
97
+ if (fg('platform_renderer_annotation_draft_position_fix')) {
98
+ // IMPORTANT: Please make sure the AnnotationsDraftContextWrapper is not used anc cleaned up correctly.
99
+ // This code path completely removes all reliance on that wrapper. Also the applyAnnotationDraftAt & clearAnnotationDraft
100
+ // properties have been made optional and not used. This means when we cleanup we can also remove those properties.
101
+ return /*#__PURE__*/React.createElement(AnnotationsContextWrapperNew, {
102
+ rendererRef: props.rendererRef,
103
+ createAnalyticsEvent: props.createAnalyticsEvent,
104
+ isNestedRender: props.isNestedRender
105
+ }, props.children);
106
+ } else {
107
+ return /*#__PURE__*/React.createElement(AnnotationsContextWrapperOld, {
108
+ rendererRef: props.rendererRef,
109
+ createAnalyticsEvent: props.createAnalyticsEvent,
110
+ isNestedRender: props.isNestedRender
111
+ }, props.children);
112
+ }
65
113
  };
@@ -15,10 +15,6 @@ import { createAnnotationStep, getPosFromRange } from '../steps';
15
15
  import { getRendererRangeInlineNodeNames } from './get-renderer-range-inline-node-names';
16
16
  import { getIndexMatch } from './matches-utils';
17
17
  var RendererActions = /*#__PURE__*/function () {
18
- // Any kind of refence is allowed
19
- // Ignored via go/ees005
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
-
22
18
  function RendererActions() {
23
19
  var initFromContext = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
24
20
  _classCallCheck(this, RendererActions);
@@ -26,6 +22,7 @@ var RendererActions = /*#__PURE__*/function () {
26
22
  // This module can only be used when wrapped with
27
23
  // the <RendererContext> component for now.
28
24
  _defineProperty(this, "initFromContext", false);
25
+ _defineProperty(this, "debugAnalyticLoggingEnabled", false);
29
26
  // TODO: EDITOR-595 - This method is temporary and should be removed once the following issue
30
27
  // has been identified and fixed: https://atlassian.slack.com/archives/C08JK0WSCH5/p1745902609966999
31
28
  // This is a copy of the original canApplyAnnotationOnRange. If that returns false this is run to figure out exactly why
@@ -108,7 +105,7 @@ var RendererActions = /*#__PURE__*/function () {
108
105
  key: "_privateValidatePositionsForAnnotation",
109
106
  value: function _privateValidatePositionsForAnnotation(from, to) {
110
107
  if (!this.doc || !this.schema) {
111
- if (this.onAnalyticsEvent && fg('platform_renderer_annotations_create_debug_logging')) {
108
+ if (this.debugAnalyticLoggingEnabled && this.onAnalyticsEvent && fg('platform_renderer_annotations_create_debug_logging')) {
112
109
  this.onAnalyticsEvent({
113
110
  // @ts-ignore
114
111
  action: 'failed',
@@ -130,7 +127,7 @@ var RendererActions = /*#__PURE__*/function () {
130
127
  }
131
128
  var currentSelection = TextSelection.create(this.doc, from, to);
132
129
  if (isEmptyTextSelection(currentSelection, this.schema)) {
133
- if (this.onAnalyticsEvent && fg('platform_renderer_annotations_create_debug_logging')) {
130
+ if (this.debugAnalyticLoggingEnabled && this.onAnalyticsEvent && fg('platform_renderer_annotations_create_debug_logging')) {
134
131
  this.onAnalyticsEvent({
135
132
  // @ts-ignore
136
133
  action: 'failed',
@@ -154,7 +151,7 @@ var RendererActions = /*#__PURE__*/function () {
154
151
  from: from,
155
152
  to: to
156
153
  }, this.doc, this.schema);
157
- if (!result && this.onAnalyticsEvent && fg('platform_renderer_annotations_create_debug_logging')) {
154
+ if (this.debugAnalyticLoggingEnabled && !result && this.onAnalyticsEvent && fg('platform_renderer_annotations_create_debug_logging')) {
158
155
  this.onAnalyticsEvent({
159
156
  // @ts-ignore
160
157
  action: 'failed',
@@ -334,7 +331,7 @@ var RendererActions = /*#__PURE__*/function () {
334
331
  key: "isValidAnnotationPosition",
335
332
  value: function isValidAnnotationPosition(pos) {
336
333
  if (!pos || !this.doc) {
337
- if (this.onAnalyticsEvent && fg('platform_renderer_annotations_create_debug_logging')) {
334
+ if (this.debugAnalyticLoggingEnabled && this.onAnalyticsEvent && fg('platform_renderer_annotations_create_debug_logging')) {
338
335
  this.onAnalyticsEvent({
339
336
  // @ts-ignore
340
337
  action: 'failed',
@@ -541,6 +538,15 @@ var RendererActions = /*#__PURE__*/function () {
541
538
  schema: this.schema
542
539
  }, annotationId);
543
540
  }
541
+
542
+ /**
543
+ * This is a temporary method used for controlling when extra analytics shoulw be logged.
544
+ */
545
+ }, {
546
+ key: "_setDebugLogging",
547
+ value: function _setDebugLogging(enabled) {
548
+ this.debugAnalyticLoggingEnabled = enabled;
549
+ }
544
550
  }]);
545
551
  }();
546
552
  export { RendererActions as default };
@@ -40,6 +40,7 @@ import { injectIntl } from 'react-intl-next';
40
40
  import { useInlineCommentsFilter } from '../../../ui/annotations/hooks/use-inline-comments-filter';
41
41
  import { useInlineCommentSubscriberContext } from '../../../ui/annotations/hooks/use-inline-comment-subscriber';
42
42
  import { AnnotationUpdateEvent } from '@atlaskit/editor-common/types';
43
+ import { useAnnotationRangeState } from '../../../ui/annotations/contexts/AnnotationRangeContext';
43
44
  var linkStyle = css({
44
45
  position: 'absolute',
45
46
  background: 'transparent',
@@ -421,7 +422,10 @@ var Media = /*#__PURE__*/function (_PureComponent) {
421
422
  }]);
422
423
  }(PureComponent);
423
424
  var MediaWithDraftAnnotation = function MediaWithDraftAnnotation(props) {
424
- var draftPosition = React.useContext(AnnotationsDraftContext);
425
+ var draftPositionOld = React.useContext(AnnotationsDraftContext);
426
+ var _useAnnotationRangeSt = useAnnotationRangeState(),
427
+ hoverDraftDocumentPosition = _useAnnotationRangeSt.hoverDraftDocumentPosition;
428
+ var draftPosition = fg('platform_renderer_annotation_draft_position_fix') ? hoverDraftDocumentPosition : draftPositionOld;
425
429
  var dataAttributes = props.dataAttributes;
426
430
  var pos = dataAttributes && dataAttributes['data-renderer-start-pos'];
427
431
  var _useState9 = useState(),
@@ -380,11 +380,17 @@ export var TableContainer = /*#__PURE__*/function (_React$Component) {
380
380
  this.updatedLayout = layout;
381
381
  }
382
382
 
383
+ // defined in colgroup.tsx:
384
+ // appearance == comment && allowTableResizing && means it is a comment
385
+ // appearance == comment && !allowTableResizing && means it is a inline comment
386
+ // for inline comments, the table should inherit the width of the parent component rather than maintain its own size
387
+ var isInsideInlineComment = rendererAppearance === 'comment' && !allowTableResizing;
388
+
383
389
  // These styling removes extra padding for `comment` rendererAppearance.
384
390
  // This is especially relevant for Jira which only uses `comment` appearance and does not need padding.
385
391
  var resizerContainerPadding = rendererAppearance === 'comment' ? 0 : gutterPadding;
386
- var resizerItemMaxWidth = rendererAppearance === 'comment' ? "min(100cqw, var(--ak-editor-table-max-width))" : "min(calc(100cqw - var(--ak-editor-table-gutter-padding)), var(--ak-editor-table-max-width))";
387
- var resizerItemWidth = rendererAppearance === 'comment' ? "min(100cqw, ".concat(tableWidthAttribute, ")") : "min(calc(100cqw - var(--ak-editor-table-gutter-padding)), ".concat(tableWidthAttribute, ")");
392
+ var resizerItemMaxWidth = rendererAppearance === 'comment' ? isInsideInlineComment ? 'inherit' : "min(100cqw, var(--ak-editor-table-max-width))" : "min(calc(100cqw - var(--ak-editor-table-gutter-padding)), var(--ak-editor-table-max-width))";
393
+ var resizerItemWidth = rendererAppearance === 'comment' ? isInsideInlineComment ? 'inherit' : "min(100cqw, ".concat(tableWidthAttribute, ")") : "min(calc(100cqw - var(--ak-editor-table-gutter-padding)), ".concat(tableWidthAttribute, ")");
388
394
 
389
395
  // full width tables can have either left-aligned or centered layout despite looking centered in the renderer.
390
396
  // in these cases, keep the alignment unset
@@ -406,7 +412,7 @@ export var TableContainer = /*#__PURE__*/function (_React$Component) {
406
412
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
407
413
  ,
408
414
  style: {
409
- width: "min(calc(100cqw - ".concat(resizerContainerPadding, "px), ").concat(tableWidthAttribute, ")")
415
+ width: isInsideInlineComment ? '100%' : "min(calc(100cqw - ".concat(resizerContainerPadding, "px), ").concat(tableWidthAttribute, ")")
410
416
  }
411
417
  }, /*#__PURE__*/React.createElement("div", {
412
418
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
@@ -716,6 +716,11 @@ var smartCardStylesAvatarFix = css(_defineProperty({}, ".".concat(SmartCardShare
716
716
  }
717
717
  /* EDM-11991: Fix list plugin add padding to ADS AvatarGroup end */
718
718
  }));
719
+ var smartCardStylesAvatarMarginFix = css(_defineProperty({}, ".".concat(SmartCardSharedCssClassName.LOADER_WRAPPER), {
720
+ 'ul, ol': {
721
+ marginRight: 'inherit'
722
+ }
723
+ }));
719
724
  var baseOtherStyles = css(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
720
725
  '& .UnknownBlock': {
721
726
  fontFamily: "var(--ds-font-family-body, ui-sans-serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Ubuntu, \"Helvetica Neue\", sans-serif)",
@@ -1382,7 +1387,7 @@ export var RendererStyleContainer = function RendererStyleContainer(props) {
1382
1387
  '--ak-renderer-editor-font-heading-h6': "".concat(editorUGCToken('editor.font.heading.h6')),
1383
1388
  '--ak-renderer-editor-font-normal-text': "".concat(editorUGCToken('editor.font.body'))
1384
1389
  },
1385
- css: [baseStyles, fg('platform_hide_heading_anchor_wrapper_before_hover') && hideHeadingCopyLinkWrapperStyles, appearance === 'full-page' && rendererFullPageStyles, appearance === 'full-width' && rendererFullWidthStyles, appearance === 'full-width' && !isTableResizingEnabled(appearance) && rendererFullWidthStylesForTableResizing, telepointerStyles, whitespaceSharedStyles, blockquoteSharedStyles, fg('platform_editor_typography_ugc') ? headingsSharedStylesWithEditorUGC : headingsSharedStyles, headingWithAlignmentStyles, ruleSharedStyles, fg('platform_editor_typography_ugc') ? paragraphSharedStylesWithEditorUGC : paragraphSharedStyles, listsSharedStyles, browser.gecko && listsSharedStylesForGekko, indentationSharedStyles, blockMarksSharedStyles, codeMarkSharedStyles, shadowSharedStyle, dateSharedStyle, textColorStyles, backgroundColorStyles, tasksAndDecisionsStyles, smartCardStyles, fg('platform-linking-visual-refresh-v1') && smartCardStylesAvatarFix,
1390
+ css: [baseStyles, fg('platform_hide_heading_anchor_wrapper_before_hover') && hideHeadingCopyLinkWrapperStyles, appearance === 'full-page' && rendererFullPageStyles, appearance === 'full-width' && rendererFullWidthStyles, appearance === 'full-width' && !isTableResizingEnabled(appearance) && rendererFullWidthStylesForTableResizing, telepointerStyles, whitespaceSharedStyles, blockquoteSharedStyles, fg('platform_editor_typography_ugc') ? headingsSharedStylesWithEditorUGC : headingsSharedStyles, headingWithAlignmentStyles, ruleSharedStyles, fg('platform_editor_typography_ugc') ? paragraphSharedStylesWithEditorUGC : paragraphSharedStyles, listsSharedStyles, browser.gecko && listsSharedStylesForGekko, indentationSharedStyles, blockMarksSharedStyles, codeMarkSharedStyles, shadowSharedStyle, dateSharedStyle, textColorStyles, backgroundColorStyles, tasksAndDecisionsStyles, smartCardStyles, fg('platform-linking-visual-refresh-v1') && smartCardStylesAvatarFix, fg('smartcard_avatar_margin_fix') && smartCardStylesAvatarMarginFix,
1386
1391
  // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
1387
1392
  fg('editor_inline_comments_on_inline_nodes') && rendererAnnotationStyles,
1388
1393
  // eslint-disable-next-line @atlaskit/platform/no-preconditioning, @atlaskit/platform/ensure-feature-flag-prefix
@@ -50,11 +50,10 @@ import { useMemoFromPropsDerivative } from './useMemoFromPropsDerivative';
50
50
  export var NORMAL_SEVERITY_THRESHOLD = 2000;
51
51
  export var DEGRADED_SEVERITY_THRESHOLD = 3000;
52
52
  var packageName = "@atlaskit/renderer";
53
- var packageVersion = "115.0.4";
53
+ var packageVersion = "115.0.6";
54
54
  var setAsQueryContainerStyles = css({
55
55
  containerName: 'ak-renderer-wrapper',
56
- containerType: 'inline-size',
57
- contain: 'layout style inline-size'
56
+ containerType: 'inline-size'
58
57
  });
59
58
  var handleMouseTripleClickInTables = function handleMouseTripleClickInTables(event) {
60
59
  var _parentElement, _parentElement2;
@@ -593,10 +592,10 @@ var RendererWrapper = /*#__PURE__*/React.memo(function (props) {
593
592
  // Only apply container-type = inline-size when having a known width in full-page/full-width/comment mode.
594
593
  // Otherwise when appearance is unspecified the renderer size is decided by the content.
595
594
  // In this case we can't set the container-type = inline-size as it will collapse width to 0.
596
- return (appearance === 'full-page' || appearance === 'full-width' || appearance === 'comment') &&
595
+ return appearance === 'comment' &&
597
596
  // In case of having excerpt-include on page there are multiple renderers nested.
598
597
  // Make sure only the root renderer is set to be query container.
599
- isTopLevelRenderer && fg('platform-fix-table-ssr-resizing') ? jsx("div", {
598
+ isTopLevelRenderer && fg('platform-ssr-table-resize') ? jsx("div", {
600
599
  css: setAsQueryContainerStyles
601
600
  }, renderer) : renderer;
602
601
  });
@@ -8,10 +8,23 @@ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstruct
8
8
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
9
9
  import React, { createContext } from 'react';
10
10
  import { fg } from '@atlaskit/platform-feature-flags';
11
- export var AnnotationsDraftContext = /*#__PURE__*/createContext(null);
12
11
  export var ProvidersContext = /*#__PURE__*/createContext(null);
13
12
  export var InlineCommentsStateContext = /*#__PURE__*/createContext({});
14
13
 
14
+ /**
15
+ * @private
16
+ * @deprecated The FG platform_renderer_annotation_draft_position_fix will make this context redundant as the draft position
17
+ * has been moved to the AnnotationRangeProvider in order to be more consistent with the hover and selection ranges.
18
+ * Once the FG is rolled out this context will be removed. Please ensure any changes are duplicated to the AnnotationRangeProvider.
19
+ */
20
+ export var AnnotationsDraftContext = /*#__PURE__*/createContext(null);
21
+
22
+ /**
23
+ * @private
24
+ * @deprecated The FG platform_renderer_annotation_draft_position_fix will make this context redundant as the draft position
25
+ * has been moved to the AnnotationRangeProvider in order to be more consistent with the hover and selection ranges.
26
+ * Once the FG is rolled out this context will be removed. Please ensure any changes are duplicated to the AnnotationRangeProvider.
27
+ */
15
28
  // Ignored via go/ees005
16
29
  // eslint-disable-next-line @repo/internal/react/no-class-components
17
30
  export var AnnotationsDraftContextWrapper = /*#__PURE__*/function (_React$Component) {
@@ -3,17 +3,22 @@ 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
5
  import React, { createContext, useCallback, useContext, useMemo, useReducer } from 'react';
6
- function reducer(state, action) {
6
+ import { fg } from '@atlaskit/platform-feature-flags';
7
+ var initialState = {
8
+ range: null,
9
+ draftRange: null,
10
+ type: null,
11
+ selectionRange: null,
12
+ hoverRange: null,
13
+ selectionDraftRange: null,
14
+ hoverDraftRange: null,
15
+ selectionDraftDocumentPosition: null,
16
+ hoverDraftDocumentPosition: null
17
+ };
18
+ function reducerOld(state, action) {
7
19
  switch (action.type) {
8
20
  case 'clear':
9
- if (!!state.range || !!state.type) {
10
- return {
11
- range: null,
12
- draftRange: null,
13
- type: null
14
- };
15
- }
16
- return state;
21
+ return initialState;
17
22
  case 'clearSelection':
18
23
  if (state.type === 'selection') {
19
24
  return _objectSpread(_objectSpread({}, state), {}, {
@@ -38,11 +43,11 @@ function reducer(state, action) {
38
43
  return state;
39
44
  case 'clearHover':
40
45
  if (state.type === 'hover') {
41
- return {
46
+ return _objectSpread(_objectSpread({}, state), {}, {
42
47
  range: null,
43
48
  draftRange: null,
44
49
  type: null
45
- };
50
+ });
46
51
  }
47
52
  return state;
48
53
  case 'setSelection':
@@ -63,11 +68,11 @@ function reducer(state, action) {
63
68
  return state;
64
69
  case 'setDraftSelection':
65
70
  if (state.draftRange !== action.draftRange || state.type !== 'selection') {
66
- return {
71
+ return _objectSpread(_objectSpread({}, state), {}, {
67
72
  range: null,
68
73
  draftRange: action.draftRange,
69
74
  type: null
70
- };
75
+ });
71
76
  }
72
77
  return state;
73
78
  case 'setDraftHover':
@@ -78,33 +83,128 @@ function reducer(state, action) {
78
83
  }
79
84
  return state;
80
85
  }
86
+ return state;
87
+ }
88
+ function reducerNew(state, action) {
89
+ switch (action.type) {
90
+ case 'clear':
91
+ return initialState;
92
+ case 'clearSelection':
93
+ if (state.selectionRange !== null) {
94
+ return _objectSpread(_objectSpread({}, state), {}, {
95
+ selectionRange: null,
96
+ type: state.type === 'selection' ? null : state.type
97
+ });
98
+ }
99
+ return state;
100
+ case 'clearHover':
101
+ {
102
+ if (state.hoverRange !== null) {
103
+ return _objectSpread(_objectSpread({}, state), {}, {
104
+ hoverRange: null,
105
+ type: state.type === 'hover' ? null : state.type
106
+ });
107
+ }
108
+ return state;
109
+ }
110
+ case 'setSelection':
111
+ if (state.selectionRange !== action.range) {
112
+ return _objectSpread(_objectSpread({}, state), {}, {
113
+ selectionRange: action.range,
114
+ type: 'selection'
115
+ });
116
+ }
117
+ return state;
118
+ case 'setHover':
119
+ if (state.hoverRange !== action.range) {
120
+ return _objectSpread(_objectSpread({}, state), {}, {
121
+ hoverRange: action.range,
122
+ type: 'hover'
123
+ });
124
+ }
125
+ return state;
126
+ case 'promoteSelectionToDraft':
127
+ // we should only promote the range to a draft if the current range type is a selection
128
+ // we should also store the promotion type, so that a clear will not accidently clear the draft of a
129
+ // different type
130
+ if (state.selectionDraftRange !== state.selectionRange) {
131
+ return _objectSpread(_objectSpread({}, state), {}, {
132
+ selectionRange: null,
133
+ type: state.type === 'selection' ? null : state.type,
134
+ selectionDraftRange: state.selectionRange,
135
+ selectionDraftDocumentPosition: action.position
136
+ });
137
+ }
138
+ return state;
139
+ case 'promoteHoverToDraft':
140
+ if (state.hoverDraftRange !== state.hoverRange) {
141
+ return _objectSpread(_objectSpread({}, state), {}, {
142
+ hoverRange: null,
143
+ type: state.type === 'hover' ? null : state.type,
144
+ hoverDraftRange: state.hoverRange,
145
+ hoverDraftDocumentPosition: action.position
146
+ });
147
+ }
148
+ return state;
149
+ case 'clearSelectionDraft':
150
+ if (state.selectionDraftRange !== null) {
151
+ return _objectSpread(_objectSpread({}, state), {}, {
152
+ selectionDraftRange: null,
153
+ selectionDraftDocumentPosition: null
154
+ });
155
+ }
156
+ return state;
157
+ case 'clearHoverDraft':
158
+ if (state.hoverDraftRange !== null) {
159
+ return _objectSpread(_objectSpread({}, state), {}, {
160
+ hoverDraftRange: null,
161
+ hoverDraftDocumentPosition: null
162
+ });
163
+ }
164
+ return state;
165
+ }
166
+ return state;
81
167
  }
82
168
  var AnnotationRangeStateContext = /*#__PURE__*/createContext({
83
169
  range: null,
84
- draftRange: null,
85
- type: null
170
+ type: null,
171
+ selectionDraftRange: null,
172
+ hoverDraftRange: null,
173
+ selectionDraftDocumentPosition: null,
174
+ hoverDraftDocumentPosition: null
86
175
  });
87
176
  var AnnotationRangeDispatchContext = /*#__PURE__*/createContext({
88
177
  clearRange: function clearRange() {},
89
178
  clearSelectionRange: function clearSelectionRange() {},
90
- clearDraftRange: function clearDraftRange() {},
91
179
  clearHoverRange: function clearHoverRange() {},
92
- setRange: function setRange() {},
93
- setDraftRange: function setDraftRange() {}
180
+ setSelectionRange: function setSelectionRange() {},
181
+ // if platform_renderer_annotation_draft_position_fix is off; then
182
+ setDraftRange: function setDraftRange() {},
183
+ clearDraftRange: function clearDraftRange() {},
184
+ // end-if
185
+
186
+ // if platform_renderer_annotation_draft_position_fix is on; then
187
+ promoteSelectionToDraft: function promoteSelectionToDraft() {},
188
+ promoteHoverToDraft: function promoteHoverToDraft() {},
189
+ clearSelectionDraft: function clearSelectionDraft() {},
190
+ clearHoverDraft: function clearHoverDraft() {}
191
+ // end-if
94
192
  });
95
- export var AnnotationRangeProvider = function AnnotationRangeProvider(_ref) {
193
+ export var AnnotationRangeProviderInner = function AnnotationRangeProviderInner(_ref) {
96
194
  var children = _ref.children,
97
195
  allowCommentsOnMedia = _ref.allowCommentsOnMedia;
98
- var _useReducer = useReducer(reducer, {
99
- range: null,
100
- draftRange: null,
101
- type: null
102
- }),
196
+ var _useReducer = useReducer(fg('platform_renderer_annotation_draft_position_fix') ? reducerNew : reducerOld, initialState),
103
197
  _useReducer2 = _slicedToArray(_useReducer, 2),
104
198
  _useReducer2$ = _useReducer2[0],
105
199
  range = _useReducer2$.range,
106
200
  draftRange = _useReducer2$.draftRange,
201
+ selectionRange = _useReducer2$.selectionRange,
202
+ hoverRange = _useReducer2$.hoverRange,
107
203
  type = _useReducer2$.type,
204
+ selectionDraftRange = _useReducer2$.selectionDraftRange,
205
+ selectionDraftDocumentPosition = _useReducer2$.selectionDraftDocumentPosition,
206
+ hoverDraftRange = _useReducer2$.hoverDraftRange,
207
+ hoverDraftDocumentPosition = _useReducer2$.hoverDraftDocumentPosition,
108
208
  dispatch = _useReducer2[1];
109
209
  var clearRange = useCallback(function () {
110
210
  return dispatch({
@@ -132,7 +232,7 @@ export var AnnotationRangeProvider = function AnnotationRangeProvider(_ref) {
132
232
  type: 'clearHover'
133
233
  });
134
234
  }, []);
135
- var setRange = useCallback(function (range) {
235
+ var setSelectionRange = useCallback(function (range) {
136
236
  return dispatch({
137
237
  type: 'setSelection',
138
238
  range: range
@@ -165,30 +265,94 @@ export var AnnotationRangeProvider = function AnnotationRangeProvider(_ref) {
165
265
  range: range
166
266
  });
167
267
  }, []);
268
+ var promoteSelectionToDraft = useCallback(function (position) {
269
+ dispatch({
270
+ type: 'promoteSelectionToDraft',
271
+ position: position
272
+ });
273
+ }, []);
274
+ var clearSelectionDraft = useCallback(function () {
275
+ dispatch({
276
+ type: 'clearSelectionDraft'
277
+ });
278
+ }, []);
279
+ var promoteHoverToDraft = useCallback(function (position) {
280
+ dispatch({
281
+ type: 'promoteHoverToDraft',
282
+ position: position
283
+ });
284
+ }, []);
285
+ var clearHoverDraft = useCallback(function () {
286
+ dispatch({
287
+ type: 'clearHoverDraft'
288
+ });
289
+ }, []);
168
290
  var stateData = useMemo(function () {
169
- return {
170
- range: range,
171
- draftRange: draftRange,
172
- type: type
173
- };
174
- }, [range, draftRange, type]);
291
+ if (fg('platform_renderer_annotation_draft_position_fix')) {
292
+ return {
293
+ // We techinically have two ranges, however we only want to expose one of them at a time, because only one draft
294
+ // can be active at a time. The type of range is used to determine which range is active.
295
+ range: type === 'selection' ? selectionRange : hoverRange,
296
+ type: type,
297
+ selectionDraftRange: selectionDraftRange,
298
+ hoverDraftRange: hoverDraftRange,
299
+ selectionDraftDocumentPosition: selectionDraftDocumentPosition,
300
+ hoverDraftDocumentPosition: hoverDraftDocumentPosition
301
+ };
302
+ } else {
303
+ return {
304
+ range: range,
305
+ draftRange: draftRange,
306
+ type: type,
307
+ // I've updated some refs to use the new selectionDraftRange, this is being add here to be fowards compatible
308
+ // with the new changes coming in platform_renderer_annotation_draft_position_fix.
309
+ selectionDraftRange: draftRange,
310
+ hoverDraftRange: draftRange,
311
+ selectionDraftDocumentPosition: null,
312
+ hoverDraftDocumentPosition: null
313
+ };
314
+ }
315
+ }, [range, draftRange, selectionRange, hoverRange, type, selectionDraftRange, selectionDraftDocumentPosition, hoverDraftRange, hoverDraftDocumentPosition]);
175
316
  var dispatchData = useMemo(function () {
176
317
  return {
177
318
  clearRange: clearRange,
178
319
  clearSelectionRange: clearSelectionRange,
179
320
  clearDraftRange: clearDraftRange,
180
321
  clearHoverRange: clearHoverRange,
181
- setRange: setRange,
322
+ setSelectionRange: setSelectionRange,
182
323
  setDraftRange: setDraftRange,
183
- setHoverTarget: !!allowCommentsOnMedia ? setHoverTarget : undefined
324
+ setHoverTarget: !!allowCommentsOnMedia ? setHoverTarget : undefined,
325
+ promoteSelectionToDraft: promoteSelectionToDraft,
326
+ promoteHoverToDraft: promoteHoverToDraft,
327
+ clearSelectionDraft: clearSelectionDraft,
328
+ clearHoverDraft: clearHoverDraft
184
329
  };
185
- }, [allowCommentsOnMedia, clearRange, clearSelectionRange, clearDraftRange, clearHoverRange, setRange, setDraftRange, setHoverTarget]);
330
+ }, [allowCommentsOnMedia, clearRange, clearSelectionRange, clearDraftRange, clearHoverRange, setSelectionRange, setDraftRange, setHoverTarget, promoteSelectionToDraft, promoteHoverToDraft, clearSelectionDraft, clearHoverDraft]);
186
331
  return /*#__PURE__*/React.createElement(AnnotationRangeStateContext.Provider, {
187
332
  value: stateData
188
333
  }, /*#__PURE__*/React.createElement(AnnotationRangeDispatchContext.Provider, {
189
334
  value: dispatchData
190
335
  }, children));
191
336
  };
337
+ export var AnnotationRangeProvider = function AnnotationRangeProvider(_ref2) {
338
+ var children = _ref2.children,
339
+ allowCommentsOnMedia = _ref2.allowCommentsOnMedia,
340
+ isNestedRender = _ref2.isNestedRender;
341
+ if (fg('platform_renderer_annotation_draft_position_fix')) {
342
+ /*
343
+ * If this is a nested render, we do not provide the context
344
+ * because it has already been provided higher up the component tree
345
+ * and we need the original context to create annotations on extensions.
346
+ */
347
+ return isNestedRender ? /*#__PURE__*/React.createElement(React.Fragment, null, children) : /*#__PURE__*/React.createElement(AnnotationRangeProviderInner, {
348
+ allowCommentsOnMedia: allowCommentsOnMedia
349
+ }, children);
350
+ } else {
351
+ return /*#__PURE__*/React.createElement(AnnotationRangeProviderInner, {
352
+ allowCommentsOnMedia: allowCommentsOnMedia
353
+ }, children);
354
+ }
355
+ };
192
356
  export var useAnnotationRangeState = function useAnnotationRangeState() {
193
357
  return useContext(AnnotationRangeStateContext);
194
358
  };
@@ -6,6 +6,7 @@ import _extends from "@babel/runtime/helpers/extends";
6
6
  import React, { Fragment, useCallback } from 'react';
7
7
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
8
8
  import { css, jsx } from '@emotion/react';
9
+ import { fg } from '@atlaskit/platform-feature-flags';
9
10
  import { InsertDraftPosition } from '../types';
10
11
  import { AnnotationsDraftContext } from '../context';
11
12
  import { splitText, calcTextSplitOffset, findTextString } from './text';
@@ -14,6 +15,7 @@ import { dataAttributes } from './dom';
14
15
  import { segmentText } from '../../../react/utils/segment-text';
15
16
  import { renderTextSegments } from '../../../react/utils/render-text-segments';
16
17
  import { useAnnotationManagerDispatch } from '../contexts/AnnotationManagerContext';
18
+ import { useAnnotationRangeState } from '../contexts/AnnotationRangeContext';
17
19
 
18
20
  // Localized AnnotationSharedCSSByState().common and AnnotationSharedCSSByState().focus
19
21
  var markStyles = css({
@@ -109,7 +111,10 @@ export var TextWithAnnotationDraft = function TextWithAnnotationDraft(_ref3) {
109
111
  end: endPos
110
112
  };
111
113
  }, [endPos, startPos]);
112
- var nextDraftPosition = React.useContext(AnnotationsDraftContext);
114
+ var nextDraftPositionOld = React.useContext(AnnotationsDraftContext);
115
+ var _useAnnotationRangeSt = useAnnotationRangeState(),
116
+ selectionDraftDocumentPosition = _useAnnotationRangeSt.selectionDraftDocumentPosition;
117
+ var nextDraftPosition = fg('platform_renderer_annotation_draft_position_fix') ? selectionDraftDocumentPosition : nextDraftPositionOld;
113
118
  var shouldApplyAnnotationAt = React.useMemo(function () {
114
119
  if (!nextDraftPosition) {
115
120
  return false;
@@ -1,8 +1,12 @@
1
1
  import { useContext } from 'react';
2
2
  import { fg } from '@atlaskit/platform-feature-flags';
3
3
  import { AnnotationsDraftContext } from '../context';
4
+ import { useAnnotationRangeState } from '../contexts/AnnotationRangeContext';
4
5
  export function useInlineAnnotationProps(props) {
5
- var draftPosition = useContext(AnnotationsDraftContext);
6
+ var draftPositionOld = useContext(AnnotationsDraftContext);
7
+ var _useAnnotationRangeSt = useAnnotationRangeState(),
8
+ selectionDraftDocumentPosition = _useAnnotationRangeSt.selectionDraftDocumentPosition;
9
+ var draftPosition = fg('platform_renderer_annotation_draft_position_fix') ? selectionDraftDocumentPosition : draftPositionOld;
6
10
  if (!fg('editor_inline_comments_on_inline_nodes')) {
7
11
  return {};
8
12
  }