@atlaskit/renderer 109.47.0 → 109.48.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,17 @@
1
1
  # @atlaskit/renderer
2
2
 
3
+ ## 109.48.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#130065](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/130065)
8
+ [`e71a357ea40dd`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e71a357ea40dd) -
9
+ [ux] [ED-24323] Add external image badge for externally hosted images
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 109.47.0
4
16
 
5
17
  ### Minor Changes
@@ -36,7 +36,8 @@ var _reactIntlNext = require("react-intl-next");
36
36
  var _hooks = require("../../../ui/annotations/hooks");
37
37
  var _types = require("@atlaskit/editor-common/types");
38
38
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
39
- var _excluded = ["marks", "mediaSingleElement", "isDrafting"];
39
+ var _excluded = ["marks", "mediaSingleElement", "isDrafting"],
40
+ _excluded2 = ["marks", "mediaSingleElement", "isDrafting"];
40
41
  var _templateObject, _templateObject2;
41
42
  /**
42
43
  * @jsxRuntime classic
@@ -163,7 +164,7 @@ var CommentBadgeWrapper = function CommentBadgeWrapper(_ref5) {
163
164
  var parentNode = mutation.target.parentNode;
164
165
  if (mutation.attributeName === 'data-has-focus') {
165
166
  var isMediaCaption = parentNode === null || parentNode === void 0 ? void 0 : parentNode.closest('[data-media-caption="true"]');
166
- var elementHasFocus = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.querySelector('[data-has-focus="true"]')) && (!(0, _platformFeatureFlags.getBooleanFF)('platform.comments-on-media.bug.incorrect-badge-highlight') || !isMediaCaption);
167
+ var elementHasFocus = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.querySelector('[data-has-focus="true"]')) && (!(0, _platformFeatureFlags.fg)('platform.comments-on-media.bug.incorrect-badge-highlight') || !isMediaCaption);
167
168
  elementHasFocus ? setStatus('active') : setStatus('default');
168
169
  }
169
170
  });
@@ -205,6 +206,85 @@ var CommentBadgeWrapper = function CommentBadgeWrapper(_ref5) {
205
206
  onClick: onClick
206
207
  }, rest));
207
208
  };
209
+
210
+ // This is a copy of above component with adding forwardRef.
211
+ // Clean this up when removing fg('platform_editor_insert_media_plugin_phase_one') flag.
212
+ var CommentBadgeWrapperWithRef = /*#__PURE__*/_react.default.forwardRef(function (_ref6, ref) {
213
+ var _marks$map2;
214
+ var marks = _ref6.marks,
215
+ mediaSingleElement = _ref6.mediaSingleElement,
216
+ _ref6$isDrafting = _ref6.isDrafting,
217
+ isDrafting = _ref6$isDrafting === void 0 ? false : _ref6$isDrafting,
218
+ rest = (0, _objectWithoutProperties2.default)(_ref6, _excluded2);
219
+ var intl = (0, _reactIntlNext.useIntl)();
220
+ var _useState5 = (0, _react.useState)('default'),
221
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
222
+ status = _useState6[0],
223
+ setStatus = _useState6[1];
224
+ var _useState7 = (0, _react.useState)(false),
225
+ _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
226
+ entered = _useState8[0],
227
+ setEntered = _useState8[1];
228
+ var updateSubscriber = (0, _hooks.useInlineCommentSubscriberContext)();
229
+ var activeParentIds = (0, _hooks.useInlineCommentsFilter)({
230
+ annotationIds: (_marks$map2 = marks === null || marks === void 0 ? void 0 : marks.map(function (mark) {
231
+ return mark.attrs.id;
232
+ })) !== null && _marks$map2 !== void 0 ? _marks$map2 : [''],
233
+ filter: {
234
+ state: _adfSchema.AnnotationMarkStates.ACTIVE
235
+ }
236
+ });
237
+ (0, _react.useEffect)(function () {
238
+ var observer = new MutationObserver(function (mutationList) {
239
+ mutationList.forEach(function (mutation) {
240
+ var parentNode = mutation.target.parentNode;
241
+ if (mutation.attributeName === 'data-has-focus') {
242
+ var isMediaCaption = parentNode === null || parentNode === void 0 ? void 0 : parentNode.closest('[data-media-caption="true"]');
243
+ var elementHasFocus = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.querySelector('[data-has-focus="true"]')) && (!(0, _platformFeatureFlags.fg)('platform.comments-on-media.bug.incorrect-badge-highlight') || !isMediaCaption);
244
+ elementHasFocus ? setStatus('active') : setStatus('default');
245
+ }
246
+ });
247
+ });
248
+ if (mediaSingleElement) {
249
+ observer.observe(mediaSingleElement, {
250
+ attributes: true,
251
+ subtree: true,
252
+ attributeFilter: ['data-has-focus']
253
+ });
254
+ }
255
+ return function () {
256
+ observer.disconnect();
257
+ };
258
+ }, [mediaSingleElement, setStatus]);
259
+ if (!isDrafting && !activeParentIds.length) {
260
+ return null;
261
+ }
262
+ var onClick = function onClick(e) {
263
+ e.preventDefault();
264
+ if (updateSubscriber) {
265
+ updateSubscriber.emit(_types.AnnotationUpdateEvent.ON_ANNOTATION_CLICK, {
266
+ annotationIds: activeParentIds,
267
+ eventTarget: e.target,
268
+ // use mediaSingle here to align with annotation viewed event dispatched in editor
269
+ eventTargetType: 'mediaSingle',
270
+ viewMethod: _analytics.VIEW_METHOD.BADGE
271
+ });
272
+ }
273
+ };
274
+ return (0, _react2.jsx)(_mediaSingle.CommentBadge, (0, _extends2.default)({
275
+ ref: ref,
276
+ intl: intl,
277
+ onMouseEnter: function onMouseEnter() {
278
+ return setEntered(true);
279
+ },
280
+ onMouseLeave: function onMouseLeave() {
281
+ return setEntered(false);
282
+ },
283
+ status: entered ? 'entered' : status,
284
+ onClick: onClick,
285
+ mediaSingleElement: mediaSingleElement
286
+ }, rest));
287
+ });
208
288
  var Media = /*#__PURE__*/function (_PureComponent) {
209
289
  (0, _inherits2.default)(Media, _PureComponent);
210
290
  var _super = _createSuper(Media);
@@ -212,6 +292,7 @@ var Media = /*#__PURE__*/function (_PureComponent) {
212
292
  var _this;
213
293
  (0, _classCallCheck2.default)(this, Media);
214
294
  _this = _super.call(this, props);
295
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "commentBadgeRef", /*#__PURE__*/_react.default.createRef());
215
296
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderCard", function () {
216
297
  var providers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
217
298
  var contextIdentifierProvider = providers.contextIdentifierProvider;
@@ -236,6 +317,14 @@ var Media = /*#__PURE__*/function (_PureComponent) {
236
317
  var isInPageInclude = mediaSingleElement === null || mediaSingleElement === void 0 ? void 0 : mediaSingleElement.closest('[data-node-type="include"]');
237
318
  var isIncludeExcerpt = !!(mediaSingleElement !== null && mediaSingleElement !== void 0 && mediaSingleElement.closest('.ak-excerpt-include'));
238
319
  var showCommentBadge = !!annotationMarks && (featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.commentsOnMedia) && (!(featureFlags !== null && featureFlags !== void 0 && featureFlags.commentsOnMediaIncludePage) || !isInPageInclude) && (!(featureFlags !== null && featureFlags !== void 0 && featureFlags.commentsOnMediaInsertExcerpt) || !isIncludeExcerpt);
320
+ var insertMediaPluginPhaseOneFlag = (0, _platformFeatureFlags.fg)('platform_editor_insert_media_plugin_phase_one');
321
+ var shouldShowExternalMediaBadge = _this.props.type === 'external' && insertMediaPluginPhaseOneFlag;
322
+ var commentBadgeOffset = function commentBadgeOffset() {
323
+ if (_this.commentBadgeRef.current) {
324
+ return _this.commentBadgeRef.current.offsetWidth + 2;
325
+ }
326
+ return 0;
327
+ };
239
328
  return (0, _react2.jsx)(MediaLink, {
240
329
  mark: linkMark,
241
330
  onClick: _this.handleMediaLinkClickFn
@@ -247,13 +336,25 @@ var Media = /*#__PURE__*/function (_PureComponent) {
247
336
  data: (0, _defineProperty2.default)({}, _analyticsNamespacedContext.MEDIA_CONTEXT, {
248
337
  border: !!borderMark
249
338
  })
250
- }, showCommentBadge && (0, _react2.jsx)(CommentBadgeWrapper, {
339
+ }, shouldShowExternalMediaBadge && (0, _react2.jsx)(_mediaSingle.ExternalImageBadge, {
340
+ commentBadgeRightOffset: commentBadgeOffset(),
341
+ mediaElement: mediaSingleElement,
342
+ mediaWidth: width,
343
+ mediaHeight: height
344
+ }), showCommentBadge && (insertMediaPluginPhaseOneFlag ? (0, _react2.jsx)(CommentBadgeWrapperWithRef, {
345
+ ref: _this.commentBadgeRef,
251
346
  marks: annotationMarks,
252
347
  mediaSingleElement: mediaSingleElement,
253
348
  width: width,
254
349
  height: height,
255
350
  isDrafting: isDrafting
256
- }), (0, _react2.jsx)(_MediaCard.MediaCard, (0, _extends2.default)({
351
+ }) : (0, _react2.jsx)(CommentBadgeWrapper, {
352
+ marks: annotationMarks,
353
+ mediaSingleElement: mediaSingleElement,
354
+ width: width,
355
+ height: height,
356
+ isDrafting: isDrafting
357
+ })), (0, _react2.jsx)(_MediaCard.MediaCard, (0, _extends2.default)({
257
358
  contextIdentifierProvider: contextIdentifierProvider
258
359
  }, _this.props, {
259
360
  shouldOpenMediaViewer: shouldOpenMediaViewer,
@@ -314,14 +415,14 @@ var MediaWithDraftAnnotation = function MediaWithDraftAnnotation(props) {
314
415
  var isCommentsOnMediaBugFixEnabled = !!(providers !== null && providers !== void 0 && providers.inlineComment.isCommentsOnMediaBugFixEnabled);
315
416
  var dataAttributes = props.dataAttributes;
316
417
  var pos = dataAttributes && dataAttributes['data-renderer-start-pos'];
317
- var _useState5 = (0, _react.useState)(),
318
- _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
319
- position = _useState6[0],
320
- setPosition = _useState6[1];
321
- var _useState7 = (0, _react.useState)(false),
322
- _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
323
- shouldApplyDraftAnnotation = _useState8[0],
324
- setShouldApplyDraftAnnotation = _useState8[1];
418
+ var _useState9 = (0, _react.useState)(),
419
+ _useState10 = (0, _slicedToArray2.default)(_useState9, 2),
420
+ position = _useState10[0],
421
+ setPosition = _useState10[1];
422
+ var _useState11 = (0, _react.useState)(false),
423
+ _useState12 = (0, _slicedToArray2.default)(_useState11, 2),
424
+ shouldApplyDraftAnnotation = _useState12[0],
425
+ setShouldApplyDraftAnnotation = _useState12[1];
325
426
  (0, _react.useEffect)(function () {
326
427
  var _draftPosition$from;
327
428
  if (pos === undefined) {
@@ -60,7 +60,7 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
60
60
  var NORMAL_SEVERITY_THRESHOLD = exports.NORMAL_SEVERITY_THRESHOLD = 2000;
61
61
  var DEGRADED_SEVERITY_THRESHOLD = exports.DEGRADED_SEVERITY_THRESHOLD = 3000;
62
62
  var packageName = "@atlaskit/renderer";
63
- var packageVersion = "109.47.0";
63
+ var packageVersion = "109.48.0";
64
64
  var defaultNodeComponents = exports.defaultNodeComponents = _nodes.nodeToReact;
65
65
  var Renderer = exports.Renderer = /*#__PURE__*/function (_PureComponent) {
66
66
  (0, _inherits2.default)(Renderer, _PureComponent);
@@ -20,11 +20,11 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, VIEW_METHOD } fr
20
20
  import { MODE, PLATFORM } from '../../../analytics/events';
21
21
  import AnnotationComponent from '../../marks/annotation';
22
22
  import { AnnotationsDraftContext, ProvidersContext } from '../../../ui/annotations/context';
23
- import { CommentBadge as CommentBadgeComponent } from '@atlaskit/editor-common/media-single';
24
- import { injectIntl } from 'react-intl-next';
23
+ import { CommentBadge as CommentBadgeComponent, ExternalImageBadge } from '@atlaskit/editor-common/media-single';
24
+ import { useIntl, injectIntl } from 'react-intl-next';
25
25
  import { useInlineCommentSubscriberContext, useInlineCommentsFilter } from '../../../ui/annotations/hooks';
26
26
  import { AnnotationUpdateEvent } from '@atlaskit/editor-common/types';
27
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
27
+ import { fg } from '@atlaskit/platform-feature-flags';
28
28
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles, @atlaskit/design-system/no-css-tagged-template-expression, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
29
29
  export const linkStyle = css`
30
30
  position: absolute;
@@ -148,7 +148,7 @@ const CommentBadgeWrapper = ({
148
148
  const parentNode = mutation.target.parentNode;
149
149
  if (mutation.attributeName === 'data-has-focus') {
150
150
  const isMediaCaption = parentNode === null || parentNode === void 0 ? void 0 : parentNode.closest('[data-media-caption="true"]');
151
- const elementHasFocus = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.querySelector('[data-has-focus="true"]')) && (!getBooleanFF('platform.comments-on-media.bug.incorrect-badge-highlight') || !isMediaCaption);
151
+ const elementHasFocus = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.querySelector('[data-has-focus="true"]')) && (!fg('platform.comments-on-media.bug.incorrect-badge-highlight') || !isMediaCaption);
152
152
  elementHasFocus ? setStatus('active') : setStatus('default');
153
153
  }
154
154
  });
@@ -186,9 +186,77 @@ const CommentBadgeWrapper = ({
186
186
  onClick: onClick
187
187
  }, rest));
188
188
  };
189
+
190
+ // This is a copy of above component with adding forwardRef.
191
+ // Clean this up when removing fg('platform_editor_insert_media_plugin_phase_one') flag.
192
+ const CommentBadgeWrapperWithRef = /*#__PURE__*/React.forwardRef(({
193
+ marks,
194
+ mediaSingleElement,
195
+ isDrafting = false,
196
+ ...rest
197
+ }, ref) => {
198
+ var _marks$map2;
199
+ const intl = useIntl();
200
+ const [status, setStatus] = useState('default');
201
+ const [entered, setEntered] = useState(false);
202
+ const updateSubscriber = useInlineCommentSubscriberContext();
203
+ const activeParentIds = useInlineCommentsFilter({
204
+ annotationIds: (_marks$map2 = marks === null || marks === void 0 ? void 0 : marks.map(mark => mark.attrs.id)) !== null && _marks$map2 !== void 0 ? _marks$map2 : [''],
205
+ filter: {
206
+ state: AnnotationMarkStates.ACTIVE
207
+ }
208
+ });
209
+ useEffect(() => {
210
+ const observer = new MutationObserver(mutationList => {
211
+ mutationList.forEach(mutation => {
212
+ const parentNode = mutation.target.parentNode;
213
+ if (mutation.attributeName === 'data-has-focus') {
214
+ const isMediaCaption = parentNode === null || parentNode === void 0 ? void 0 : parentNode.closest('[data-media-caption="true"]');
215
+ const elementHasFocus = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.querySelector('[data-has-focus="true"]')) && (!fg('platform.comments-on-media.bug.incorrect-badge-highlight') || !isMediaCaption);
216
+ elementHasFocus ? setStatus('active') : setStatus('default');
217
+ }
218
+ });
219
+ });
220
+ if (mediaSingleElement) {
221
+ observer.observe(mediaSingleElement, {
222
+ attributes: true,
223
+ subtree: true,
224
+ attributeFilter: ['data-has-focus']
225
+ });
226
+ }
227
+ return () => {
228
+ observer.disconnect();
229
+ };
230
+ }, [mediaSingleElement, setStatus]);
231
+ if (!isDrafting && !activeParentIds.length) {
232
+ return null;
233
+ }
234
+ const onClick = e => {
235
+ e.preventDefault();
236
+ if (updateSubscriber) {
237
+ updateSubscriber.emit(AnnotationUpdateEvent.ON_ANNOTATION_CLICK, {
238
+ annotationIds: activeParentIds,
239
+ eventTarget: e.target,
240
+ // use mediaSingle here to align with annotation viewed event dispatched in editor
241
+ eventTargetType: 'mediaSingle',
242
+ viewMethod: VIEW_METHOD.BADGE
243
+ });
244
+ }
245
+ };
246
+ return jsx(CommentBadgeComponent, _extends({
247
+ ref: ref,
248
+ intl: intl,
249
+ onMouseEnter: () => setEntered(true),
250
+ onMouseLeave: () => setEntered(false),
251
+ status: entered ? 'entered' : status,
252
+ onClick: onClick,
253
+ mediaSingleElement: mediaSingleElement
254
+ }, rest));
255
+ });
189
256
  class Media extends PureComponent {
190
257
  constructor(props) {
191
258
  super(props);
259
+ _defineProperty(this, "commentBadgeRef", /*#__PURE__*/React.createRef());
192
260
  _defineProperty(this, "renderCard", (providers = {}) => {
193
261
  const {
194
262
  contextIdentifierProvider
@@ -214,6 +282,14 @@ class Media extends PureComponent {
214
282
  const isInPageInclude = mediaSingleElement === null || mediaSingleElement === void 0 ? void 0 : mediaSingleElement.closest('[data-node-type="include"]');
215
283
  const isIncludeExcerpt = !!(mediaSingleElement !== null && mediaSingleElement !== void 0 && mediaSingleElement.closest('.ak-excerpt-include'));
216
284
  const showCommentBadge = !!annotationMarks && (featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.commentsOnMedia) && (!(featureFlags !== null && featureFlags !== void 0 && featureFlags.commentsOnMediaIncludePage) || !isInPageInclude) && (!(featureFlags !== null && featureFlags !== void 0 && featureFlags.commentsOnMediaInsertExcerpt) || !isIncludeExcerpt);
285
+ const insertMediaPluginPhaseOneFlag = fg('platform_editor_insert_media_plugin_phase_one');
286
+ const shouldShowExternalMediaBadge = this.props.type === 'external' && insertMediaPluginPhaseOneFlag;
287
+ const commentBadgeOffset = () => {
288
+ if (this.commentBadgeRef.current) {
289
+ return this.commentBadgeRef.current.offsetWidth + 2;
290
+ }
291
+ return 0;
292
+ };
217
293
  return jsx(MediaLink, {
218
294
  mark: linkMark,
219
295
  onClick: this.handleMediaLinkClickFn
@@ -227,13 +303,25 @@ class Media extends PureComponent {
227
303
  border: !!borderMark
228
304
  }
229
305
  }
230
- }, showCommentBadge && jsx(CommentBadgeWrapper, {
306
+ }, shouldShowExternalMediaBadge && jsx(ExternalImageBadge, {
307
+ commentBadgeRightOffset: commentBadgeOffset(),
308
+ mediaElement: mediaSingleElement,
309
+ mediaWidth: width,
310
+ mediaHeight: height
311
+ }), showCommentBadge && (insertMediaPluginPhaseOneFlag ? jsx(CommentBadgeWrapperWithRef, {
312
+ ref: this.commentBadgeRef,
313
+ marks: annotationMarks,
314
+ mediaSingleElement: mediaSingleElement,
315
+ width: width,
316
+ height: height,
317
+ isDrafting: isDrafting
318
+ }) : jsx(CommentBadgeWrapper, {
231
319
  marks: annotationMarks,
232
320
  mediaSingleElement: mediaSingleElement,
233
321
  width: width,
234
322
  height: height,
235
323
  isDrafting: isDrafting
236
- }), jsx(MediaCard, _extends({
324
+ })), jsx(MediaCard, _extends({
237
325
  contextIdentifierProvider: contextIdentifierProvider
238
326
  }, this.props, {
239
327
  shouldOpenMediaViewer: shouldOpenMediaViewer,
@@ -42,7 +42,7 @@ import { nodeToReact } from '../../react/nodes';
42
42
  export const NORMAL_SEVERITY_THRESHOLD = 2000;
43
43
  export const DEGRADED_SEVERITY_THRESHOLD = 3000;
44
44
  const packageName = "@atlaskit/renderer";
45
- const packageVersion = "109.47.0";
45
+ const packageVersion = "109.48.0";
46
46
  export const defaultNodeComponents = nodeToReact;
47
47
  export class Renderer extends PureComponent {
48
48
  constructor(props) {
@@ -9,7 +9,8 @@ import _extends from "@babel/runtime/helpers/extends";
9
9
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
10
10
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
11
11
  import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
12
- var _excluded = ["marks", "mediaSingleElement", "isDrafting"];
12
+ var _excluded = ["marks", "mediaSingleElement", "isDrafting"],
13
+ _excluded2 = ["marks", "mediaSingleElement", "isDrafting"];
13
14
  var _templateObject, _templateObject2;
14
15
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
15
16
  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; }
@@ -35,11 +36,11 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, VIEW_METHOD } fr
35
36
  import { MODE, PLATFORM } from '../../../analytics/events';
36
37
  import AnnotationComponent from '../../marks/annotation';
37
38
  import { AnnotationsDraftContext, ProvidersContext } from '../../../ui/annotations/context';
38
- import { CommentBadge as CommentBadgeComponent } from '@atlaskit/editor-common/media-single';
39
- import { injectIntl } from 'react-intl-next';
39
+ import { CommentBadge as CommentBadgeComponent, ExternalImageBadge } from '@atlaskit/editor-common/media-single';
40
+ import { useIntl, injectIntl } from 'react-intl-next';
40
41
  import { useInlineCommentSubscriberContext, useInlineCommentsFilter } from '../../../ui/annotations/hooks';
41
42
  import { AnnotationUpdateEvent } from '@atlaskit/editor-common/types';
42
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
43
+ import { fg } from '@atlaskit/platform-feature-flags';
43
44
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles, @atlaskit/design-system/no-css-tagged-template-expression, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
44
45
  export var linkStyle = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n\tposition: absolute;\n\tbackground: transparent;\n\ttop: 0;\n\tright: 0;\n\tbottom: 0;\n\tleft: 0;\n\tcursor: pointer;\n\twidth: 100% !important;\n\theight: 100% !important;\n"])));
45
46
 
@@ -154,7 +155,7 @@ var CommentBadgeWrapper = function CommentBadgeWrapper(_ref5) {
154
155
  var parentNode = mutation.target.parentNode;
155
156
  if (mutation.attributeName === 'data-has-focus') {
156
157
  var isMediaCaption = parentNode === null || parentNode === void 0 ? void 0 : parentNode.closest('[data-media-caption="true"]');
157
- var elementHasFocus = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.querySelector('[data-has-focus="true"]')) && (!getBooleanFF('platform.comments-on-media.bug.incorrect-badge-highlight') || !isMediaCaption);
158
+ var elementHasFocus = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.querySelector('[data-has-focus="true"]')) && (!fg('platform.comments-on-media.bug.incorrect-badge-highlight') || !isMediaCaption);
158
159
  elementHasFocus ? setStatus('active') : setStatus('default');
159
160
  }
160
161
  });
@@ -196,6 +197,85 @@ var CommentBadgeWrapper = function CommentBadgeWrapper(_ref5) {
196
197
  onClick: onClick
197
198
  }, rest));
198
199
  };
200
+
201
+ // This is a copy of above component with adding forwardRef.
202
+ // Clean this up when removing fg('platform_editor_insert_media_plugin_phase_one') flag.
203
+ var CommentBadgeWrapperWithRef = /*#__PURE__*/React.forwardRef(function (_ref6, ref) {
204
+ var _marks$map2;
205
+ var marks = _ref6.marks,
206
+ mediaSingleElement = _ref6.mediaSingleElement,
207
+ _ref6$isDrafting = _ref6.isDrafting,
208
+ isDrafting = _ref6$isDrafting === void 0 ? false : _ref6$isDrafting,
209
+ rest = _objectWithoutProperties(_ref6, _excluded2);
210
+ var intl = useIntl();
211
+ var _useState5 = useState('default'),
212
+ _useState6 = _slicedToArray(_useState5, 2),
213
+ status = _useState6[0],
214
+ setStatus = _useState6[1];
215
+ var _useState7 = useState(false),
216
+ _useState8 = _slicedToArray(_useState7, 2),
217
+ entered = _useState8[0],
218
+ setEntered = _useState8[1];
219
+ var updateSubscriber = useInlineCommentSubscriberContext();
220
+ var activeParentIds = useInlineCommentsFilter({
221
+ annotationIds: (_marks$map2 = marks === null || marks === void 0 ? void 0 : marks.map(function (mark) {
222
+ return mark.attrs.id;
223
+ })) !== null && _marks$map2 !== void 0 ? _marks$map2 : [''],
224
+ filter: {
225
+ state: AnnotationMarkStates.ACTIVE
226
+ }
227
+ });
228
+ useEffect(function () {
229
+ var observer = new MutationObserver(function (mutationList) {
230
+ mutationList.forEach(function (mutation) {
231
+ var parentNode = mutation.target.parentNode;
232
+ if (mutation.attributeName === 'data-has-focus') {
233
+ var isMediaCaption = parentNode === null || parentNode === void 0 ? void 0 : parentNode.closest('[data-media-caption="true"]');
234
+ var elementHasFocus = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.querySelector('[data-has-focus="true"]')) && (!fg('platform.comments-on-media.bug.incorrect-badge-highlight') || !isMediaCaption);
235
+ elementHasFocus ? setStatus('active') : setStatus('default');
236
+ }
237
+ });
238
+ });
239
+ if (mediaSingleElement) {
240
+ observer.observe(mediaSingleElement, {
241
+ attributes: true,
242
+ subtree: true,
243
+ attributeFilter: ['data-has-focus']
244
+ });
245
+ }
246
+ return function () {
247
+ observer.disconnect();
248
+ };
249
+ }, [mediaSingleElement, setStatus]);
250
+ if (!isDrafting && !activeParentIds.length) {
251
+ return null;
252
+ }
253
+ var onClick = function onClick(e) {
254
+ e.preventDefault();
255
+ if (updateSubscriber) {
256
+ updateSubscriber.emit(AnnotationUpdateEvent.ON_ANNOTATION_CLICK, {
257
+ annotationIds: activeParentIds,
258
+ eventTarget: e.target,
259
+ // use mediaSingle here to align with annotation viewed event dispatched in editor
260
+ eventTargetType: 'mediaSingle',
261
+ viewMethod: VIEW_METHOD.BADGE
262
+ });
263
+ }
264
+ };
265
+ return jsx(CommentBadgeComponent, _extends({
266
+ ref: ref,
267
+ intl: intl,
268
+ onMouseEnter: function onMouseEnter() {
269
+ return setEntered(true);
270
+ },
271
+ onMouseLeave: function onMouseLeave() {
272
+ return setEntered(false);
273
+ },
274
+ status: entered ? 'entered' : status,
275
+ onClick: onClick,
276
+ mediaSingleElement: mediaSingleElement
277
+ }, rest));
278
+ });
199
279
  var Media = /*#__PURE__*/function (_PureComponent) {
200
280
  _inherits(Media, _PureComponent);
201
281
  var _super = _createSuper(Media);
@@ -203,6 +283,7 @@ var Media = /*#__PURE__*/function (_PureComponent) {
203
283
  var _this;
204
284
  _classCallCheck(this, Media);
205
285
  _this = _super.call(this, props);
286
+ _defineProperty(_assertThisInitialized(_this), "commentBadgeRef", /*#__PURE__*/React.createRef());
206
287
  _defineProperty(_assertThisInitialized(_this), "renderCard", function () {
207
288
  var providers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
208
289
  var contextIdentifierProvider = providers.contextIdentifierProvider;
@@ -227,6 +308,14 @@ var Media = /*#__PURE__*/function (_PureComponent) {
227
308
  var isInPageInclude = mediaSingleElement === null || mediaSingleElement === void 0 ? void 0 : mediaSingleElement.closest('[data-node-type="include"]');
228
309
  var isIncludeExcerpt = !!(mediaSingleElement !== null && mediaSingleElement !== void 0 && mediaSingleElement.closest('.ak-excerpt-include'));
229
310
  var showCommentBadge = !!annotationMarks && (featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.commentsOnMedia) && (!(featureFlags !== null && featureFlags !== void 0 && featureFlags.commentsOnMediaIncludePage) || !isInPageInclude) && (!(featureFlags !== null && featureFlags !== void 0 && featureFlags.commentsOnMediaInsertExcerpt) || !isIncludeExcerpt);
311
+ var insertMediaPluginPhaseOneFlag = fg('platform_editor_insert_media_plugin_phase_one');
312
+ var shouldShowExternalMediaBadge = _this.props.type === 'external' && insertMediaPluginPhaseOneFlag;
313
+ var commentBadgeOffset = function commentBadgeOffset() {
314
+ if (_this.commentBadgeRef.current) {
315
+ return _this.commentBadgeRef.current.offsetWidth + 2;
316
+ }
317
+ return 0;
318
+ };
230
319
  return jsx(MediaLink, {
231
320
  mark: linkMark,
232
321
  onClick: _this.handleMediaLinkClickFn
@@ -238,13 +327,25 @@ var Media = /*#__PURE__*/function (_PureComponent) {
238
327
  data: _defineProperty({}, MEDIA_CONTEXT, {
239
328
  border: !!borderMark
240
329
  })
241
- }, showCommentBadge && jsx(CommentBadgeWrapper, {
330
+ }, shouldShowExternalMediaBadge && jsx(ExternalImageBadge, {
331
+ commentBadgeRightOffset: commentBadgeOffset(),
332
+ mediaElement: mediaSingleElement,
333
+ mediaWidth: width,
334
+ mediaHeight: height
335
+ }), showCommentBadge && (insertMediaPluginPhaseOneFlag ? jsx(CommentBadgeWrapperWithRef, {
336
+ ref: _this.commentBadgeRef,
242
337
  marks: annotationMarks,
243
338
  mediaSingleElement: mediaSingleElement,
244
339
  width: width,
245
340
  height: height,
246
341
  isDrafting: isDrafting
247
- }), jsx(MediaCard, _extends({
342
+ }) : jsx(CommentBadgeWrapper, {
343
+ marks: annotationMarks,
344
+ mediaSingleElement: mediaSingleElement,
345
+ width: width,
346
+ height: height,
347
+ isDrafting: isDrafting
348
+ })), jsx(MediaCard, _extends({
248
349
  contextIdentifierProvider: contextIdentifierProvider
249
350
  }, _this.props, {
250
351
  shouldOpenMediaViewer: shouldOpenMediaViewer,
@@ -305,14 +406,14 @@ var MediaWithDraftAnnotation = function MediaWithDraftAnnotation(props) {
305
406
  var isCommentsOnMediaBugFixEnabled = !!(providers !== null && providers !== void 0 && providers.inlineComment.isCommentsOnMediaBugFixEnabled);
306
407
  var dataAttributes = props.dataAttributes;
307
408
  var pos = dataAttributes && dataAttributes['data-renderer-start-pos'];
308
- var _useState5 = useState(),
309
- _useState6 = _slicedToArray(_useState5, 2),
310
- position = _useState6[0],
311
- setPosition = _useState6[1];
312
- var _useState7 = useState(false),
313
- _useState8 = _slicedToArray(_useState7, 2),
314
- shouldApplyDraftAnnotation = _useState8[0],
315
- setShouldApplyDraftAnnotation = _useState8[1];
409
+ var _useState9 = useState(),
410
+ _useState10 = _slicedToArray(_useState9, 2),
411
+ position = _useState10[0],
412
+ setPosition = _useState10[1];
413
+ var _useState11 = useState(false),
414
+ _useState12 = _slicedToArray(_useState11, 2),
415
+ shouldApplyDraftAnnotation = _useState12[0],
416
+ setShouldApplyDraftAnnotation = _useState12[1];
316
417
  useEffect(function () {
317
418
  var _draftPosition$from;
318
419
  if (pos === undefined) {
@@ -52,7 +52,7 @@ import { nodeToReact } from '../../react/nodes';
52
52
  export var NORMAL_SEVERITY_THRESHOLD = 2000;
53
53
  export var DEGRADED_SEVERITY_THRESHOLD = 3000;
54
54
  var packageName = "@atlaskit/renderer";
55
- var packageVersion = "109.47.0";
55
+ var packageVersion = "109.48.0";
56
56
  export var defaultNodeComponents = nodeToReact;
57
57
  export var Renderer = /*#__PURE__*/function (_PureComponent) {
58
58
  _inherits(Renderer, _PureComponent);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/renderer",
3
- "version": "109.47.0",
3
+ "version": "109.48.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": "^10.1.0",
32
32
  "@atlaskit/button": "^20.0.0",
33
33
  "@atlaskit/code": "^15.5.0",
34
- "@atlaskit/editor-common": "^87.11.0",
34
+ "@atlaskit/editor-common": "^87.12.0",
35
35
  "@atlaskit/editor-json-transformer": "^8.18.0",
36
36
  "@atlaskit/editor-palette": "1.6.0",
37
37
  "@atlaskit/editor-prosemirror": "5.0.1",
@@ -42,8 +42,8 @@
42
42
  "@atlaskit/link-datasource": "^2.11.0",
43
43
  "@atlaskit/media-card": "^78.0.0",
44
44
  "@atlaskit/media-client": "^27.3.0",
45
- "@atlaskit/media-client-react": "^2.0.0",
46
- "@atlaskit/media-common": "^11.3.0",
45
+ "@atlaskit/media-client-react": "^2.1.0",
46
+ "@atlaskit/media-common": "^11.4.0",
47
47
  "@atlaskit/media-filmstrip": "^47.2.0",
48
48
  "@atlaskit/media-ui": "^25.11.0",
49
49
  "@atlaskit/media-viewer": "^48.7.0",
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "peerDependencies": {
66
66
  "@atlaskit/link-provider": "^1.14.0",
67
- "@atlaskit/media-core": "^34.2.0",
67
+ "@atlaskit/media-core": "^34.3.0",
68
68
  "react": "^16.8.0",
69
69
  "react-dom": "^16.8.0"
70
70
  },
@@ -77,7 +77,7 @@
77
77
  "@atlaskit/link-provider": "^1.14.0",
78
78
  "@atlaskit/link-test-helpers": "^7.4.0",
79
79
  "@atlaskit/linking-common": "^5.11.0",
80
- "@atlaskit/media-core": "^34.2.0",
80
+ "@atlaskit/media-core": "^34.3.0",
81
81
  "@atlaskit/media-integration-test-helpers": "^3.1.0",
82
82
  "@atlaskit/media-test-helpers": "^34.0.0",
83
83
  "@atlaskit/mention": "^23.2.0",
@@ -152,6 +152,9 @@
152
152
  "platform.comments-on-media.bug.incorrect-badge-highlight": {
153
153
  "type": "boolean"
154
154
  },
155
+ "platform_editor_insert_media_plugin_phase_one": {
156
+ "type": "boolean"
157
+ },
155
158
  "platform-fix-table-ssr-resizing": {
156
159
  "type": "boolean"
157
160
  },