@atlaskit/editor-plugin-media 2.6.7 → 2.7.1

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 (61) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/cjs/mediaPlugin.js +21 -6
  3. package/dist/cjs/nodeviews/mediaGroup.js +21 -6
  4. package/dist/cjs/nodeviews/mediaInline.js +55 -13
  5. package/dist/cjs/nodeviews/mediaNodeUpdater.js +24 -18
  6. package/dist/cjs/nodeviews/mediaNodeView/index.js +11 -3
  7. package/dist/cjs/nodeviews/mediaSingle.js +88 -49
  8. package/dist/cjs/nodeviews/mediaSingleNext.js +5 -4
  9. package/dist/cjs/pm-plugins/utils/media-files.js +64 -6
  10. package/dist/cjs/ui/CommentBadge/index.js +44 -14
  11. package/dist/cjs/ui/MediaPicker/index.js +15 -3
  12. package/dist/cjs/ui/MediaViewer/MediaViewerContainer.js +3 -3
  13. package/dist/cjs/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +2 -1
  14. package/dist/cjs/ui/ToolbarMedia/index.js +17 -5
  15. package/dist/cjs/ui/hooks/useMediaProvider.js +11 -3
  16. package/dist/cjs/ui/toolbar/utils.js +6 -4
  17. package/dist/es2019/mediaPlugin.js +21 -6
  18. package/dist/es2019/nodeviews/mediaGroup.js +21 -6
  19. package/dist/es2019/nodeviews/mediaInline.js +54 -12
  20. package/dist/es2019/nodeviews/mediaNodeUpdater.js +5 -1
  21. package/dist/es2019/nodeviews/mediaNodeView/index.js +11 -3
  22. package/dist/es2019/nodeviews/mediaSingle.js +60 -25
  23. package/dist/es2019/nodeviews/mediaSingleNext.js +5 -4
  24. package/dist/es2019/pm-plugins/utils/media-files.js +63 -5
  25. package/dist/es2019/ui/CommentBadge/index.js +40 -10
  26. package/dist/es2019/ui/MediaPicker/index.js +15 -3
  27. package/dist/es2019/ui/MediaViewer/MediaViewerContainer.js +4 -4
  28. package/dist/es2019/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +2 -1
  29. package/dist/es2019/ui/ToolbarMedia/index.js +17 -5
  30. package/dist/es2019/ui/hooks/useMediaProvider.js +11 -3
  31. package/dist/es2019/ui/toolbar/utils.js +5 -3
  32. package/dist/esm/mediaPlugin.js +21 -6
  33. package/dist/esm/nodeviews/mediaGroup.js +21 -6
  34. package/dist/esm/nodeviews/mediaInline.js +55 -13
  35. package/dist/esm/nodeviews/mediaNodeUpdater.js +24 -18
  36. package/dist/esm/nodeviews/mediaNodeView/index.js +11 -3
  37. package/dist/esm/nodeviews/mediaSingle.js +88 -49
  38. package/dist/esm/nodeviews/mediaSingleNext.js +5 -4
  39. package/dist/esm/pm-plugins/utils/media-files.js +63 -5
  40. package/dist/esm/ui/CommentBadge/index.js +44 -14
  41. package/dist/esm/ui/MediaPicker/index.js +15 -3
  42. package/dist/esm/ui/MediaViewer/MediaViewerContainer.js +4 -4
  43. package/dist/esm/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +2 -1
  44. package/dist/esm/ui/ToolbarMedia/index.js +17 -5
  45. package/dist/esm/ui/hooks/useMediaProvider.js +11 -3
  46. package/dist/esm/ui/toolbar/utils.js +5 -3
  47. package/dist/types/nodeviews/mediaInline.d.ts +7 -2
  48. package/dist/types/nodeviews/mediaSingleNext.d.ts +3 -4
  49. package/dist/types/nodeviews/types.d.ts +3 -4
  50. package/dist/types/pm-plugins/utils/media-files.d.ts +3 -2
  51. package/dist/types/types/index.d.ts +17 -0
  52. package/dist/types/ui/MediaViewer/MediaViewerContainer.d.ts +4 -3
  53. package/dist/types/ui/toolbar/utils.d.ts +1 -0
  54. package/dist/types-ts4.5/nodeviews/mediaInline.d.ts +7 -2
  55. package/dist/types-ts4.5/nodeviews/mediaSingleNext.d.ts +3 -4
  56. package/dist/types-ts4.5/nodeviews/types.d.ts +3 -4
  57. package/dist/types-ts4.5/pm-plugins/utils/media-files.d.ts +3 -2
  58. package/dist/types-ts4.5/types/index.d.ts +17 -0
  59. package/dist/types-ts4.5/ui/MediaViewer/MediaViewerContainer.d.ts +4 -3
  60. package/dist/types-ts4.5/ui/toolbar/utils.d.ts +1 -0
  61. package/package.json +9 -3
@@ -10,10 +10,12 @@ var _reactIntlNext = require("react-intl-next");
10
10
  var _hooks = require("@atlaskit/editor-common/hooks");
11
11
  var _media = require("@atlaskit/editor-common/media");
12
12
  var _uiMenu = require("@atlaskit/editor-common/ui-menu");
13
+ var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
13
14
  var _attachmentEditorAttachment = _interopRequireDefault(require("@atlaskit/icon/core/migration/attachment--editor-attachment"));
14
- var onClickMediaButton = function onClickMediaButton(pluginState) {
15
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
16
+ var onClickMediaButton = function onClickMediaButton(showMediaPicker) {
15
17
  return function () {
16
- pluginState.showMediaPicker();
18
+ showMediaPicker();
17
19
  return true;
18
20
  };
19
21
  };
@@ -22,15 +24,25 @@ var ToolbarMedia = function ToolbarMedia(_ref) {
22
24
  isReducedSpacing = _ref.isReducedSpacing,
23
25
  intl = _ref.intl,
24
26
  api = _ref.api;
25
- var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['media']),
27
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['media'], {
28
+ disabled: (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', true)
29
+ }),
26
30
  mediaState = _useSharedPluginState.mediaState;
27
- if (!(mediaState !== null && mediaState !== void 0 && mediaState.allowsUploads)) {
31
+ var allowsUploadsSelector = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'media.allowsUploads', {
32
+ disabled: (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', false)
33
+ });
34
+ var showMediaPickerSelector = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'media.showMediaPicker', {
35
+ disabled: (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', false)
36
+ });
37
+ var allowsUploads = (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', true) ? allowsUploadsSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.allowsUploads;
38
+ var showMediaPicker = (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', true) ? showMediaPickerSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.showMediaPicker;
39
+ if (!allowsUploads || !showMediaPicker) {
28
40
  return null;
29
41
  }
30
42
  var toolbarMediaTitle = _media.toolbarMediaMessages.toolbarMediaTitle;
31
43
  return /*#__PURE__*/_react.default.createElement(_uiMenu.ToolbarButton, {
32
44
  buttonId: _uiMenu.TOOLBAR_BUTTON.MEDIA,
33
- onClick: onClickMediaButton(mediaState),
45
+ onClick: onClickMediaButton(showMediaPicker),
34
46
  disabled: isDisabled,
35
47
  title: intl.formatMessage(toolbarMediaTitle),
36
48
  spacing: isReducedSpacing ? 'none' : 'default',
@@ -6,11 +6,19 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useMediaProvider = void 0;
7
7
  var _react = require("react");
8
8
  var _hooks = require("@atlaskit/editor-common/hooks");
9
+ var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
10
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
9
11
  var useMediaProvider = exports.useMediaProvider = function useMediaProvider(pluginInjectionApi) {
10
- var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['media']),
12
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['media'], {
13
+ disabled: (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', true)
14
+ }),
11
15
  mediaState = _useSharedPluginState.mediaState;
16
+ var mediaProviderSelector = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(pluginInjectionApi, 'media.mediaProvider', {
17
+ disabled: (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', false)
18
+ });
19
+ var mediaProvider = (0, _experiments.editorExperiment)('platform_editor_usesharedpluginstateselector', true) ? mediaProviderSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaProvider;
12
20
  var provider = (0, _react.useMemo)(function () {
13
- return mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaProvider;
14
- }, [mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaProvider]);
21
+ return mediaProvider;
22
+ }, [mediaProvider]);
15
23
  return provider;
16
24
  };
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.updateToFullHeightSeparator = exports.removeMediaGroupNode = exports.isExternalMedia = exports.getSelectedNearestMediaContainerNodeAttrs = exports.getSelectedMediaSingle = exports.getSelectedLayoutIcon = exports.getPixelWidthOfElement = exports.getMaxToolbarWidth = exports.downloadMedia = exports.canShowSwitchButtons = exports.calcNewLayout = void 0;
7
+ exports.updateToFullHeightSeparator = exports.removeMediaGroupNode = exports.isExternalMedia = exports.getSelectedNearestMediaContainerNodeAttrsFunction = exports.getSelectedNearestMediaContainerNodeAttrs = exports.getSelectedMediaSingle = exports.getSelectedLayoutIcon = exports.getPixelWidthOfElement = exports.getMaxToolbarWidth = exports.downloadMedia = exports.canShowSwitchButtons = exports.calcNewLayout = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
10
  var _memoizeOne = _interopRequireDefault(require("memoize-one"));
@@ -25,9 +25,8 @@ var getSelectedMediaContainerNodeAttrs = function getSelectedMediaContainerNodeA
25
25
  }
26
26
  return null;
27
27
  };
28
- var getSelectedNearestMediaContainerNodeAttrs = exports.getSelectedNearestMediaContainerNodeAttrs = function getSelectedNearestMediaContainerNodeAttrs(mediaPluginState) {
29
- var _mediaPluginState$sel2;
30
- var selectedNode = (_mediaPluginState$sel2 = mediaPluginState.selectedMediaContainerNode) === null || _mediaPluginState$sel2 === void 0 ? void 0 : _mediaPluginState$sel2.call(mediaPluginState);
28
+ var getSelectedNearestMediaContainerNodeAttrsFunction = exports.getSelectedNearestMediaContainerNodeAttrsFunction = function getSelectedNearestMediaContainerNodeAttrsFunction(selectedMediaContainerNode) {
29
+ var selectedNode = selectedMediaContainerNode === null || selectedMediaContainerNode === void 0 ? void 0 : selectedMediaContainerNode();
31
30
  if (selectedNode) {
32
31
  switch (selectedNode.type.name) {
33
32
  case 'mediaSingle':
@@ -41,6 +40,9 @@ var getSelectedNearestMediaContainerNodeAttrs = exports.getSelectedNearestMediaC
41
40
  }
42
41
  return null;
43
42
  };
43
+ var getSelectedNearestMediaContainerNodeAttrs = exports.getSelectedNearestMediaContainerNodeAttrs = function getSelectedNearestMediaContainerNodeAttrs(mediaPluginState) {
44
+ return getSelectedNearestMediaContainerNodeAttrsFunction(mediaPluginState.selectedMediaContainerNode);
45
+ };
44
46
  var downloadMedia = exports.downloadMedia = /*#__PURE__*/function () {
45
47
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(mediaPluginState, isViewMode) {
46
48
  var selectedNodeAttrs, id, _selectedNodeAttrs$co, collection, mediaClient, fileState, fileName;
@@ -4,6 +4,7 @@ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
4
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
5
5
  import { IconImages } from '@atlaskit/editor-common/quick-insert';
6
6
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
7
8
  import { NodeSelection, PluginKey } from '@atlaskit/editor-prosemirror/state';
8
9
  import { getMediaFeatureFlag } from '@atlaskit/media-common';
9
10
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -56,21 +57,35 @@ const MediaViewerFunctionalComponent = ({
56
57
  }) => {
57
58
  const {
58
59
  mediaState
59
- } = useSharedPluginState(api, ['media']);
60
+ } = useSharedPluginState(api, ['media'], {
61
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true)
62
+ });
63
+ const isMediaViewerVisibleSelector = useSharedPluginStateSelector(api, 'media.isMediaViewerVisible', {
64
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
65
+ });
66
+ const mediaViewerSelectedMediaSelector = useSharedPluginStateSelector(api, 'media.mediaViewerSelectedMedia', {
67
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
68
+ });
69
+ const mediaClientConfigSelector = useSharedPluginStateSelector(api, 'media.mediaClientConfig', {
70
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
71
+ });
72
+ const isMediaViewerVisible = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? isMediaViewerVisibleSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.isMediaViewerVisible;
73
+ const mediaViewerSelectedMedia = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? mediaViewerSelectedMediaSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaViewerSelectedMedia;
74
+ const mediaClientConfig = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? mediaClientConfigSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaClientConfig;
60
75
 
61
76
  // Only traverse document once when media viewer is visible, media viewer items will not update
62
77
  // when document changes are made while media viewer is open
63
78
 
64
79
  const mediaItems = useMemo(() => {
65
- if (mediaState !== null && mediaState !== void 0 && mediaState.isMediaViewerVisible) {
80
+ if (isMediaViewerVisible) {
66
81
  const mediaNodes = extractMediaNodes(editorView.state.doc);
67
82
  return createMediaIdentifierArray(mediaNodes);
68
83
  }
69
84
  // eslint-disable-next-line react-hooks/exhaustive-deps -- only update mediaItems once when media viewer is visible
70
- }, [mediaState === null || mediaState === void 0 ? void 0 : mediaState.isMediaViewerVisible]);
85
+ }, [isMediaViewerVisible]);
71
86
 
72
87
  // Viewer does not have required attributes to render the media viewer
73
- if (!(mediaState !== null && mediaState !== void 0 && mediaState.isMediaViewerVisible) || !(mediaState !== null && mediaState !== void 0 && mediaState.mediaViewerSelectedMedia) || !(mediaState !== null && mediaState !== void 0 && mediaState.mediaClientConfig)) {
88
+ if (!isMediaViewerVisible || !mediaViewerSelectedMedia || !mediaClientConfig) {
74
89
  return null;
75
90
  }
76
91
  const handleOnClose = () => {
@@ -78,9 +93,9 @@ const MediaViewerFunctionalComponent = ({
78
93
  api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.media.commands.hideMediaViewer);
79
94
  };
80
95
  return /*#__PURE__*/React.createElement(RenderMediaViewer, {
81
- mediaClientConfig: mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaClientConfig,
96
+ mediaClientConfig: mediaClientConfig,
82
97
  onClose: handleOnClose,
83
- selectedNodeAttrs: mediaState.mediaViewerSelectedMedia,
98
+ selectedNodeAttrs: mediaViewerSelectedMedia,
84
99
  items: mediaItems
85
100
  });
86
101
  };
@@ -5,6 +5,7 @@ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
5
5
  import { nodeViewsMessages as messages } from '@atlaskit/editor-common/media';
6
6
  import { WithProviders } from '@atlaskit/editor-common/provider-factory';
7
7
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
8
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
8
9
  import { isNodeSelectedOrInRange, SelectedState, setNodeSelection } from '@atlaskit/editor-common/utils';
9
10
  import EditorCloseIcon from '@atlaskit/icon/core/migration/close--editor-close';
10
11
  import { getMediaFeatureFlag } from '@atlaskit/media-common';
@@ -265,11 +266,23 @@ function MediaGroupNodeViewInternal({
265
266
  const {
266
267
  editorDisabledState: editorDisabledPlugin,
267
268
  editorViewModeState: editorViewModePlugin
268
- } = useSharedPluginState(pluginInjectionApi, ['editorDisabled', 'editorViewMode']);
269
+ } = useSharedPluginState(pluginInjectionApi, ['editorDisabled', 'editorViewMode'], {
270
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true)
271
+ });
272
+ const editorDisabledSelector = useSharedPluginStateSelector(pluginInjectionApi, 'editorDisabled.editorDisabled', {
273
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
274
+ });
275
+ const editorViewModeSelector = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.mode', {
276
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
277
+ });
278
+ const editorDisabled = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? editorDisabledSelector : editorDisabledPlugin === null || editorDisabledPlugin === void 0 ? void 0 : editorDisabledPlugin.editorDisabled;
279
+ const editorViewMode = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? editorViewModeSelector : editorViewModePlugin === null || editorViewModePlugin === void 0 ? void 0 : editorViewModePlugin.mode;
269
280
  const mediaProvider = useMediaProvider(pluginInjectionApi);
270
281
  return renderFn({
271
282
  editorDisabledPlugin,
272
283
  editorViewModePlugin,
284
+ editorDisabled,
285
+ editorViewMode,
273
286
  mediaProvider
274
287
  });
275
288
  }
@@ -290,7 +303,9 @@ class MediaGroupNodeView extends ReactNodeView {
290
303
  const renderFn = ({
291
304
  editorDisabledPlugin,
292
305
  editorViewModePlugin,
293
- mediaProvider: mediaProviderFromState
306
+ mediaProvider: mediaProviderFromState,
307
+ editorDisabled,
308
+ editorViewMode
294
309
  }) => {
295
310
  const mediaProvider = mediaProviderFromState ? Promise.resolve(mediaProviderFromState) : undefined;
296
311
  if (!mediaProvider) {
@@ -302,7 +317,7 @@ class MediaGroupNodeView extends ReactNodeView {
302
317
  getPos: getPos,
303
318
  view: this.view,
304
319
  forwardRef: forwardRef,
305
- disabled: (editorDisabledPlugin || {}).editorDisabled,
320
+ disabled: editorDisabled,
306
321
  allowLazyLoading: mediaOptions.allowLazyLoading,
307
322
  mediaProvider: mediaProvider,
308
323
  contextIdentifierProvider: contextIdentifierProvider,
@@ -310,7 +325,7 @@ class MediaGroupNodeView extends ReactNodeView {
310
325
  anchorPos: this.view.state.selection.$anchor.pos,
311
326
  headPos: this.view.state.selection.$head.pos,
312
327
  mediaOptions: mediaOptions,
313
- editorViewMode: (editorViewModePlugin === null || editorViewModePlugin === void 0 ? void 0 : editorViewModePlugin.mode) === 'view'
328
+ editorViewMode: editorViewMode === 'view'
314
329
  });
315
330
  }
316
331
  return /*#__PURE__*/React.createElement(IntlMediaGroup, {
@@ -318,7 +333,7 @@ class MediaGroupNodeView extends ReactNodeView {
318
333
  getPos: getPos,
319
334
  view: this.view,
320
335
  forwardRef: forwardRef,
321
- disabled: (editorDisabledPlugin || {}).editorDisabled,
336
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true) ? editorDisabled : (editorDisabledPlugin || {}).editorDisabled,
322
337
  allowLazyLoading: mediaOptions.allowLazyLoading,
323
338
  mediaProvider: mediaProvider,
324
339
  contextIdentifierProvider: contextIdentifierProvider,
@@ -326,7 +341,7 @@ class MediaGroupNodeView extends ReactNodeView {
326
341
  anchorPos: this.view.state.selection.$anchor.pos,
327
342
  headPos: this.view.state.selection.$head.pos,
328
343
  mediaOptions: mediaOptions,
329
- editorViewMode: (editorViewModePlugin === null || editorViewModePlugin === void 0 ? void 0 : editorViewModePlugin.mode) === 'view'
344
+ editorViewMode: editorExperiment('platform_editor_usesharedpluginstateselector', true) ? editorViewMode === 'view' : (editorViewModePlugin === null || editorViewModePlugin === void 0 ? void 0 : editorViewModePlugin.mode) === 'view'
330
345
  });
331
346
  };
332
347
  return /*#__PURE__*/React.createElement(MediaGroupNodeViewInternal, {
@@ -10,10 +10,12 @@ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
10
10
  import { MediaInlineImageCard } from '@atlaskit/editor-common/media-inline';
11
11
  import { WithProviders } from '@atlaskit/editor-common/provider-factory';
12
12
  import { SelectionBasedNodeView } from '@atlaskit/editor-common/selection-based-node-view';
13
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
13
14
  import { MediaInlineCard } from '@atlaskit/media-card';
14
15
  import { getMediaClient } from '@atlaskit/media-client-react';
15
16
  import { MediaInlineCardLoadingView } from '@atlaskit/media-ui';
16
17
  import { fg } from '@atlaskit/platform-feature-flags';
18
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
17
19
  import { isImage } from '../pm-plugins/utils/is-type';
18
20
  import { MediaViewerContainer } from '../ui/MediaViewer/MediaViewerContainer';
19
21
  import { MediaNodeUpdater } from './mediaNodeUpdater';
@@ -37,7 +39,7 @@ const createMediaNodeUpdater = props => {
37
39
  const updateMediaNodeAttributes = async (props, mediaNodeUpdater) => {
38
40
  const {
39
41
  addPendingTask
40
- } = props.mediaPluginState;
42
+ } = props;
41
43
  const node = props.node;
42
44
  if (!node) {
43
45
  return;
@@ -64,10 +66,10 @@ const updateMediaNodeAttributes = async (props, mediaNodeUpdater) => {
64
66
  export const handleNewNode = props => {
65
67
  const {
66
68
  node,
67
- mediaPluginState,
69
+ handleMediaNodeMount,
68
70
  getPos
69
71
  } = props;
70
- mediaPluginState.handleMediaNodeMount(node, () => getPos());
72
+ handleMediaNodeMount(node, () => getPos());
71
73
  };
72
74
  export const MediaInline = props => {
73
75
  var _props$node, _props$node$marks;
@@ -81,9 +83,9 @@ export const MediaInline = props => {
81
83
  updateViewMediaClientConfig(props);
82
84
  return () => {
83
85
  const {
84
- mediaPluginState
86
+ handleMediaNodeUnmount
85
87
  } = props;
86
- mediaPluginState.handleMediaNodeUnmount(props.node);
88
+ handleMediaNodeUnmount(props.node);
87
89
  };
88
90
  }, [props]);
89
91
  const updateViewMediaClientConfig = async props => {
@@ -124,7 +126,7 @@ export const MediaInline = props => {
124
126
  }
125
127
  const {
126
128
  allowInlineImages
127
- } = props.mediaPluginState;
129
+ } = props;
128
130
  const borderMark = (_props$node = props.node) === null || _props$node === void 0 ? void 0 : (_props$node$marks = _props$node.marks) === null || _props$node$marks === void 0 ? void 0 : _props$node$marks.find(mark => mark.type.name === 'border');
129
131
  if (allowInlineImages && isImage(type)) {
130
132
  return jsx(MediaInlineImageCard, {
@@ -143,7 +145,8 @@ export const MediaInline = props => {
143
145
  }
144
146
  return jsx(MediaViewerContainer, {
145
147
  mediaNode: props.node,
146
- mediaPluginState: props.mediaPluginState,
148
+ selectedMediaContainerNode: props.selectedMediaContainerNode,
149
+ mediaClientConfig: props.mediaClientConfig,
147
150
  isEditorViewMode: props.editorViewMode,
148
151
  isSelected: props.isSelected,
149
152
  isInline: fg('platform_editor_render_media_viewer_as_inline')
@@ -165,21 +168,60 @@ const MediaInlineSharedState = ({
165
168
  const {
166
169
  editorViewModeState,
167
170
  mediaState
168
- } = useSharedPluginState(api, ['editorViewMode', 'media']);
169
- const newMediaProvider = useMemo(() => mediaState !== null && mediaState !== void 0 && mediaState.mediaProvider ? Promise.resolve(mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaProvider) : undefined, [mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaProvider]);
170
- if (!mediaState || !newMediaProvider) {
171
+ } = useSharedPluginState(api, ['editorViewMode', 'media'], {
172
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true)
173
+ });
174
+ const viewModeSelector = useSharedPluginStateSelector(api, 'editorViewMode.mode', {
175
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
176
+ });
177
+ const mediaProviderSelector = useSharedPluginStateSelector(api, 'media.mediaProvider', {
178
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
179
+ });
180
+ const handleMediaNodeMountSelector = useSharedPluginStateSelector(api, 'media.handleMediaNodeMount', {
181
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
182
+ });
183
+ const handleMediaNodeUnmountSelector = useSharedPluginStateSelector(api, 'media.handleMediaNodeUnmount', {
184
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
185
+ });
186
+ const allowInlineImagesSelector = useSharedPluginStateSelector(api, 'media.allowInlineImages', {
187
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
188
+ });
189
+ const addPendingTaskSelector = useSharedPluginStateSelector(api, 'media.addPendingTask', {
190
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
191
+ });
192
+ const selectedMediaContainerNodeSelector = useSharedPluginStateSelector(api, 'media.selectedMediaContainerNode', {
193
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
194
+ });
195
+ const mediaClientConfigSelector = useSharedPluginStateSelector(api, 'media.mediaClientConfig', {
196
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
197
+ });
198
+ const viewMode = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? viewModeSelector : editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode;
199
+ const mediaProvider = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? mediaProviderSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaProvider;
200
+ const handleMediaNodeMount = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? handleMediaNodeMountSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.handleMediaNodeMount;
201
+ const handleMediaNodeUnmount = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? handleMediaNodeUnmountSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.handleMediaNodeUnmount;
202
+ const allowInlineImages = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? allowInlineImagesSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.allowInlineImages;
203
+ const addPendingTask = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? addPendingTaskSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.addPendingTask;
204
+ const selectedMediaContainerNode = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? selectedMediaContainerNodeSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.selectedMediaContainerNode;
205
+ const mediaClientConfig = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? mediaClientConfigSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaClientConfig;
206
+ const newMediaProvider = useMemo(() => mediaProvider ? Promise.resolve(mediaProvider) : undefined, [mediaProvider]);
207
+ if (!handleMediaNodeMount || !handleMediaNodeUnmount || !addPendingTask || !selectedMediaContainerNode || !mediaClientConfig || !newMediaProvider) {
171
208
  return null;
172
209
  }
173
210
  return jsx(MediaInline, {
174
211
  identifier: identifier,
175
212
  mediaProvider: newMediaProvider,
176
- mediaPluginState: mediaState,
213
+ handleMediaNodeMount: handleMediaNodeMount,
214
+ handleMediaNodeUnmount: handleMediaNodeUnmount,
215
+ allowInlineImages: allowInlineImages,
216
+ addPendingTask: addPendingTask,
217
+ selectedMediaContainerNode: selectedMediaContainerNode,
218
+ mediaClientConfig: mediaClientConfig,
177
219
  node: node,
178
220
  isSelected: isSelected,
179
221
  view: view,
180
222
  getPos: getPos,
181
223
  contextIdentifierProvider: contextIdentifierProvider,
182
- editorViewMode: (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view'
224
+ editorViewMode: viewMode === 'view'
183
225
  });
184
226
  };
185
227
  export class MediaInlineNodeView extends SelectionBasedNodeView {
@@ -136,8 +136,12 @@ export class MediaNodeUpdater {
136
136
  });
137
137
  _defineProperty(this, "uploadExternalMedia", async getPos => {
138
138
  const {
139
- node
139
+ node,
140
+ mediaOptions
140
141
  } = this.props;
142
+ if (mediaOptions !== null && mediaOptions !== void 0 && mediaOptions.isExternalMediaUploadDisabled) {
143
+ return;
144
+ }
141
145
  const mediaProvider = await this.props.mediaProvider;
142
146
  if (node && mediaProvider) {
143
147
  const uploadMediaClientConfig = mediaProvider.uploadMediaClientConfig;
@@ -4,7 +4,9 @@ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
4
  import { DEFAULT_IMAGE_HEIGHT, DEFAULT_IMAGE_WIDTH } from '@atlaskit/editor-common/media-single';
5
5
  import { WithProviders } from '@atlaskit/editor-common/provider-factory';
6
6
  import { SelectionBasedNodeView } from '@atlaskit/editor-common/selection-based-node-view';
7
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
7
8
  import { getAttrsFromUrl } from '@atlaskit/media-client';
9
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
8
10
  import { updateCurrentMediaNodeAttrs } from '../../pm-plugins/commands/helpers';
9
11
  import { isMediaBlobUrlFromAttrs } from '../../pm-plugins/utils/media-common';
10
12
  // Ignored via go/ees005
@@ -17,10 +19,16 @@ const MediaNodeWithProviders = ({
17
19
  const {
18
20
  widthState,
19
21
  mediaState
20
- } = useSharedPluginState(pluginInjectionApi, ['width', 'media']);
22
+ } = useSharedPluginState(pluginInjectionApi, ['width', 'media'], {
23
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true)
24
+ });
25
+ const mediaProviderSelector = useSharedPluginStateSelector(pluginInjectionApi, 'media.mediaProvider', {
26
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
27
+ });
28
+ const mediaProvider = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? mediaProviderSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaProvider;
21
29
  return innerComponent({
22
- width: widthState,
23
- mediaProvider: mediaState !== null && mediaState !== void 0 && mediaState.mediaProvider ? Promise.resolve(mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaProvider) : undefined
30
+ width: editorExperiment('platform_editor_usesharedpluginstateselector', true) ? widthState : undefined,
31
+ mediaProvider: mediaProvider ? Promise.resolve(mediaProvider) : undefined
24
32
  });
25
33
  };
26
34
  function isMediaDecorationSpec(decoration) {
@@ -23,6 +23,7 @@ import { findParentNodeOfTypeClosestToPos } from '@atlaskit/editor-prosemirror/u
23
23
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
24
24
  import { getAttrsFromUrl } from '@atlaskit/media-client';
25
25
  import { fg } from '@atlaskit/platform-feature-flags';
26
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
26
27
  import { insertAndSelectCaptionFromMediaSinglePos } from '../pm-plugins/commands/captions';
27
28
  import { MEDIA_CONTENT_WRAP_CLASS_NAME } from '../pm-plugins/main';
28
29
  import { isMediaBlobUrlFromAttrs } from '../pm-plugins/utils/media-common';
@@ -85,7 +86,10 @@ export default class MediaSingleNode extends Component {
85
86
  this.createOrUpdateMediaNodeUpdater(props);
86
87
  const {
87
88
  addPendingTask
88
- } = this.props.mediaPluginState;
89
+ } = this.props;
90
+ if (!addPendingTask) {
91
+ return;
92
+ }
89
93
 
90
94
  // we want the first child of MediaSingle (type "media")
91
95
  const node = this.props.node.firstChild;
@@ -267,7 +271,8 @@ export default class MediaSingleNode extends Component {
267
271
  dispatchAnalyticsEvent,
268
272
  editorViewMode,
269
273
  editorDisabled,
270
- annotationPluginState,
274
+ isDrafting,
275
+ targetNodeId,
271
276
  editorAppearance
272
277
  } = this.props;
273
278
  const {
@@ -376,7 +381,7 @@ export default class MediaSingleNode extends Component {
376
381
  const badgeOffsetRight = isBadgePosOffsetRight();
377
382
  let shouldShowPlaceholder = mediaOptions.allowCaptions && node.childCount !== 2 && isSelected && state.selection instanceof NodeSelection;
378
383
  shouldShowPlaceholder = !editorDisabled && shouldShowPlaceholder;
379
- const isCurrentNodeDrafting = (annotationPluginState === null || annotationPluginState === void 0 ? void 0 : annotationPluginState.isDrafting) && (annotationPluginState === null || annotationPluginState === void 0 ? void 0 : annotationPluginState.targetNodeId) === (node === null || node === void 0 ? void 0 : (_node$firstChild = node.firstChild) === null || _node$firstChild === void 0 ? void 0 : _node$firstChild.attrs.id);
384
+ const isCurrentNodeDrafting = Boolean(isDrafting && targetNodeId === (node === null || node === void 0 ? void 0 : (_node$firstChild = node.firstChild) === null || _node$firstChild === void 0 ? void 0 : _node$firstChild.attrs.id));
380
385
  const pos = getPos();
381
386
  const isInsideTable = pos !== undefined && findParentNodeOfTypeClosestToPos(state.doc.resolve(pos), [state.schema.nodes.table]);
382
387
  const currentMediaElement = () => {
@@ -479,14 +484,48 @@ const MediaSingleNodeWrapper = ({
479
484
  annotationState,
480
485
  editorDisabledState,
481
486
  editorViewModeState
482
- } = useSharedPluginState(pluginInjectionApi, ['width', 'media', 'annotation', 'editorDisabled', 'editorViewMode']);
487
+ } = useSharedPluginState(pluginInjectionApi, ['width', 'media', 'annotation', 'editorDisabled', 'editorViewMode'], {
488
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true)
489
+ });
490
+ const mediaProviderSelector = useSharedPluginStateSelector(pluginInjectionApi, 'media.mediaProvider', {
491
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
492
+ });
493
+ const addPendingTaskSelector = useSharedPluginStateSelector(pluginInjectionApi, 'media.addPendingTask', {
494
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
495
+ });
496
+ const isDraftingSelector = useSharedPluginStateSelector(pluginInjectionApi, 'annotation.isDrafting', {
497
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
498
+ });
499
+ const targetNodeIdSelector = useSharedPluginStateSelector(pluginInjectionApi, 'annotation.targetNodeId', {
500
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
501
+ });
502
+ const widthSelector = useSharedPluginStateSelector(pluginInjectionApi, 'width.width', {
503
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
504
+ });
505
+ const lineLengthSelector = useSharedPluginStateSelector(pluginInjectionApi, 'width.lineLength', {
506
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
507
+ });
508
+ const editorDisabledSelector = useSharedPluginStateSelector(pluginInjectionApi, 'editorDisabled.editorDisabled', {
509
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
510
+ });
511
+ const viewModeSelector = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.mode', {
512
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
513
+ });
514
+ const mediaProviderState = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? mediaProviderSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaProvider;
515
+ const addPendingTask = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? addPendingTaskSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.addPendingTask;
516
+ const isDrafting = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? isDraftingSelector : annotationState === null || annotationState === void 0 ? void 0 : annotationState.isDrafting;
517
+ const targetNodeId = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? targetNodeIdSelector : annotationState === null || annotationState === void 0 ? void 0 : annotationState.targetNodeId;
518
+ const width = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? widthSelector : widthState === null || widthState === void 0 ? void 0 : widthState.width;
519
+ const lineLength = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? lineLengthSelector : widthState === null || widthState === void 0 ? void 0 : widthState.lineLength;
520
+ const editorDisabled = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? editorDisabledSelector : editorDisabledState === null || editorDisabledState === void 0 ? void 0 : editorDisabledState.editorDisabled;
521
+ const viewMode = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? viewModeSelector : editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode;
483
522
  const hasHadInteraction = useSharedPluginStateSelector(pluginInjectionApi, 'interaction.hasHadInteraction');
484
- const mediaProvider = useMemo(() => mediaState !== null && mediaState !== void 0 && mediaState.mediaProvider ? Promise.resolve(mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaProvider) : undefined, [mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaProvider]);
485
- const isSelectedAndInteracted = useCallback(() => Boolean(selected() && hasHadInteraction), [hasHadInteraction, selected]);
523
+ const mediaProvider = useMemo(() => mediaProviderState ? Promise.resolve(mediaProviderState) : undefined, [mediaProviderState]);
524
+ const isSelectedAndInteracted = useCallback(() => Boolean(selected() && hasHadInteraction !== false), [hasHadInteraction, selected]);
486
525
  if (fg('platform_editor_react18_phase2__media_single') || fg('platform_editor_react18_phase2__media_single_jira')) {
487
526
  return jsx(MediaSingleNodeNext, {
488
- width: (widthState === null || widthState === void 0 ? void 0 : widthState.width) || 0,
489
- lineLength: (widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || 0,
527
+ width: width || 0,
528
+ lineLength: lineLength || 0,
490
529
  node: node,
491
530
  getPos: getPos,
492
531
  mediaProvider: mediaProvider,
@@ -496,25 +535,20 @@ const MediaSingleNodeWrapper = ({
496
535
  fullWidthMode: fullWidthMode,
497
536
  selected: fg('platform_editor_no_selection_until_interaction') ? isSelectedAndInteracted : selected,
498
537
  eventDispatcher: eventDispatcher,
499
- mediaPluginState: mediaState !== null && mediaState !== void 0 ? mediaState : undefined,
500
- annotationPluginState: annotationState !== null && annotationState !== void 0 ? annotationState : undefined,
538
+ addPendingTask: addPendingTask,
539
+ isDrafting: isDrafting,
540
+ targetNodeId: targetNodeId,
501
541
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
502
542
  forwardRef: forwardRef,
503
543
  pluginInjectionApi: pluginInjectionApi,
504
- editorDisabled: editorDisabledState === null || editorDisabledState === void 0 ? void 0 : editorDisabledState.editorDisabled,
505
- editorViewMode: (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view',
544
+ editorDisabled: editorDisabled,
545
+ editorViewMode: viewMode === 'view',
506
546
  editorAppearance: editorAppearance
507
547
  });
508
548
  }
509
- return jsx(MediaSingleNode
510
- // Ignored via go/ees005
511
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
512
- , {
513
- width: widthState.width
514
- // Ignored via go/ees005
515
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
516
- ,
517
- lineLength: widthState.lineLength,
549
+ return jsx(MediaSingleNode, {
550
+ width: width,
551
+ lineLength: lineLength,
518
552
  node: node,
519
553
  getPos: getPos,
520
554
  mediaProvider: mediaProvider,
@@ -524,13 +558,14 @@ const MediaSingleNodeWrapper = ({
524
558
  fullWidthMode: fullWidthMode,
525
559
  selected: fg('platform_editor_no_selection_until_interaction') ? isSelectedAndInteracted : selected,
526
560
  eventDispatcher: eventDispatcher,
527
- mediaPluginState: mediaState !== null && mediaState !== void 0 ? mediaState : undefined,
528
- annotationPluginState: annotationState !== null && annotationState !== void 0 ? annotationState : undefined,
561
+ addPendingTask: addPendingTask,
562
+ isDrafting: isDrafting,
563
+ targetNodeId: targetNodeId,
529
564
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
530
565
  forwardRef: forwardRef,
531
566
  pluginInjectionApi: pluginInjectionApi,
532
- editorDisabled: editorDisabledState === null || editorDisabledState === void 0 ? void 0 : editorDisabledState.editorDisabled,
533
- editorViewMode: (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view',
567
+ editorDisabled: editorDisabled,
568
+ editorViewMode: viewMode === 'view',
534
569
  editorAppearance: editorAppearance
535
570
  });
536
571
  };
@@ -261,12 +261,13 @@ export const MediaSingleNodeNext = mediaSingleNodeNextProps => {
261
261
  dispatchAnalyticsEvent,
262
262
  editorViewMode,
263
263
  editorDisabled,
264
- annotationPluginState,
264
+ isDrafting,
265
+ targetNodeId,
265
266
  editorAppearance,
266
267
  mediaProvider: mediaProviderPromise,
267
268
  forwardRef,
268
269
  contextIdentifierProvider: contextIdentifierProviderPromise,
269
- mediaPluginState
270
+ addPendingTask
270
271
  } = mediaSingleNodeNextProps;
271
272
  const [mediaProvider, setMediaProvider] = React.useState(null);
272
273
  const [_contextIdentifierProvider, setContextIdentifierProvider] = React.useState(null);
@@ -286,7 +287,7 @@ export const MediaSingleNodeNext = mediaSingleNodeNextProps => {
286
287
  mediaNodeUpdater,
287
288
  getPos,
288
289
  mediaNode,
289
- addPendingTask: (mediaPluginState === null || mediaPluginState === void 0 ? void 0 : mediaPluginState.addPendingTask) || noop
290
+ addPendingTask: addPendingTask || noop
290
291
  });
291
292
  React.useLayoutEffect(() => {
292
293
  mountedRef.current = true;
@@ -398,7 +399,7 @@ export const MediaSingleNodeNext = mediaSingleNodeNextProps => {
398
399
  }, [mediaSingleWidthAttribute, widthType, width, layout, contentWidthForLegacyExperience, containerWidth]);
399
400
  const currentMaxWidth = isSelected ? pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$m = pluginInjectionApi.media) === null || _pluginInjectionApi$m === void 0 ? void 0 : (_pluginInjectionApi$m2 = _pluginInjectionApi$m.sharedState.currentState()) === null || _pluginInjectionApi$m2 === void 0 ? void 0 : _pluginInjectionApi$m2.currentMaxWidth : undefined;
400
401
  const contentWidth = currentMaxWidth || lineLength;
401
- const isCurrentNodeDrafting = Boolean((annotationPluginState === null || annotationPluginState === void 0 ? void 0 : annotationPluginState.isDrafting) && (annotationPluginState === null || annotationPluginState === void 0 ? void 0 : annotationPluginState.targetNodeId) === (mediaNode === null || mediaNode === void 0 ? void 0 : (_mediaNode$firstChild = mediaNode.firstChild) === null || _mediaNode$firstChild === void 0 ? void 0 : _mediaNode$firstChild.attrs.id));
402
+ const isCurrentNodeDrafting = Boolean(isDrafting && targetNodeId === (mediaNode === null || mediaNode === void 0 ? void 0 : (_mediaNode$firstChild = mediaNode.firstChild) === null || _mediaNode$firstChild === void 0 ? void 0 : _mediaNode$firstChild.attrs.id));
402
403
  const mediaSingleWrapperRef = /*#__PURE__*/React.createRef();
403
404
  const captionPlaceHolderRef = /*#__PURE__*/React.createRef();
404
405
  const onMediaSingleClicked = React.useCallback(event => {