@atlaskit/renderer 108.20.10 → 108.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/react/index.js +4 -1
  3. package/dist/cjs/react/nodes/media/index.js +1 -3
  4. package/dist/cjs/react/nodes/mediaInline.js +21 -47
  5. package/dist/cjs/react/utils/EditorMediaClientProvider.js +48 -0
  6. package/dist/cjs/ui/MediaCard.js +73 -74
  7. package/dist/cjs/ui/Renderer/index.js +15 -7
  8. package/dist/es2019/react/index.js +3 -1
  9. package/dist/es2019/react/nodes/media/index.js +1 -4
  10. package/dist/es2019/react/nodes/mediaInline.js +13 -20
  11. package/dist/es2019/react/utils/EditorMediaClientProvider.js +33 -0
  12. package/dist/es2019/ui/MediaCard.js +30 -32
  13. package/dist/es2019/ui/Renderer/index.js +17 -10
  14. package/dist/esm/react/index.js +4 -1
  15. package/dist/esm/react/nodes/media/index.js +2 -5
  16. package/dist/esm/react/nodes/mediaInline.js +22 -48
  17. package/dist/esm/react/utils/EditorMediaClientProvider.js +38 -0
  18. package/dist/esm/ui/MediaCard.js +74 -75
  19. package/dist/esm/ui/Renderer/index.js +17 -10
  20. package/dist/types/react/nodes/media/index.d.ts +2 -3
  21. package/dist/types/react/nodes/mediaInline.d.ts +2 -2
  22. package/dist/types/react/utils/EditorMediaClientProvider.d.ts +5 -0
  23. package/dist/types/ui/MediaCard.d.ts +6 -5
  24. package/dist/types/ui/Renderer/index.d.ts +2 -1
  25. package/dist/types-ts4.5/react/nodes/media/index.d.ts +2 -3
  26. package/dist/types-ts4.5/react/nodes/mediaInline.d.ts +2 -2
  27. package/dist/types-ts4.5/react/utils/EditorMediaClientProvider.d.ts +5 -0
  28. package/dist/types-ts4.5/ui/MediaCard.d.ts +6 -5
  29. package/dist/types-ts4.5/ui/Renderer/index.d.ts +2 -1
  30. package/package.json +1 -1
@@ -3,7 +3,7 @@ import React, { useEffect, useState, useCallback } from 'react';
3
3
  import { MediaInlineCard } from '@atlaskit/media-card';
4
4
  import { MediaInlineCardErroredView, MediaInlineCardLoadingView, messages } from '@atlaskit/media-ui';
5
5
  import { WithProviders } from '@atlaskit/editor-common/provider-factory';
6
- import { getMediaClient } from '@atlaskit/media-client-react';
6
+ import { MediaClientContext } from '@atlaskit/media-client-react';
7
7
  import { getClipboardAttrs, mediaIdentifierMap } from '../../ui/MediaCard';
8
8
  import { createIntl, injectIntl } from 'react-intl-next';
9
9
  import { shouldShowInlineImage, MediaInlineImageCard } from '@atlaskit/editor-common/media-inline';
@@ -21,26 +21,27 @@ export const RenderMediaInline = ({
21
21
  type
22
22
  }) => {
23
23
  const [contextIdentifierProvider, setContextIdentifierProvider] = useState();
24
- const [viewMediaClientConfigState, setViewMediaClientConfigState] = useState();
25
24
  const [fileState, setFileState] = useState();
25
+ const mediaClient = React.useContext(MediaClientContext);
26
26
  const updateContext = async contextIdentifierProvider => {
27
27
  if (contextIdentifierProvider) {
28
28
  const resolvedContextID = await contextIdentifierProvider;
29
29
  setContextIdentifierProvider(resolvedContextID);
30
30
  }
31
31
  };
32
- const updateFileState = useCallback(async (id, mediaClientConfig) => {
33
- const mediaClient = getMediaClient(mediaClientConfig);
32
+ const updateFileState = useCallback(async id => {
34
33
  const options = {
35
34
  collectionName
36
35
  };
37
36
  try {
38
- const fileState = await mediaClient.file.getCurrentState(id, options);
39
- setFileState(fileState);
37
+ if (mediaClient) {
38
+ const fileState = await mediaClient.file.getCurrentState(id, options);
39
+ setFileState(fileState);
40
+ }
40
41
  } catch (error) {
41
42
  // do not set state on error
42
43
  }
43
- }, [collectionName]);
44
+ }, [collectionName, mediaClient]);
44
45
  useEffect(() => {
45
46
  const {
46
47
  id
@@ -58,28 +59,20 @@ export const RenderMediaInline = ({
58
59
  }, [identifier, collectionName]);
59
60
  useEffect(() => {
60
61
  const {
61
- mediaProvider,
62
62
  contextIdentifierProvider
63
63
  } = mediaInlineProviders;
64
64
  const {
65
65
  id
66
66
  } = clipboardAttrs;
67
- updateViewMediaClientConfigState(mediaProvider);
68
67
  updateContext(contextIdentifierProvider);
69
- id && viewMediaClientConfigState && updateFileState(id, viewMediaClientConfigState);
70
- }, [mediaInlineProviders, contextIdentifierProvider, clipboardAttrs, viewMediaClientConfigState, updateFileState]);
71
- const updateViewMediaClientConfigState = async mediaProvider => {
72
- if (mediaProvider) {
73
- const mediaClientConfig = await mediaProvider;
74
- setViewMediaClientConfigState(mediaClientConfig.viewMediaClientConfig);
75
- }
76
- };
68
+ id && updateFileState(id);
69
+ }, [mediaInlineProviders, contextIdentifierProvider, clipboardAttrs, updateFileState]);
77
70
 
78
71
  /*
79
72
  * Only show the loading view if the media provider is not ready
80
73
  * prevents calling the media API before the provider is ready
81
74
  */
82
- if (!viewMediaClientConfigState) {
75
+ if (!mediaClient) {
83
76
  return /*#__PURE__*/React.createElement(MediaInlineCardLoadingView, {
84
77
  message: "",
85
78
  isSelected: false
@@ -87,7 +80,7 @@ export const RenderMediaInline = ({
87
80
  }
88
81
  if (type && shouldShowInlineImage(type)) {
89
82
  return /*#__PURE__*/React.createElement(MediaInlineImageCard, {
90
- mediaClient: getMediaClient(viewMediaClientConfigState),
83
+ mediaClient: mediaClient,
91
84
  identifier: identifier,
92
85
  alt: alt,
93
86
  width: width,
@@ -122,7 +115,7 @@ export const RenderMediaInline = ({
122
115
  onClick: handleMediaInlineClick,
123
116
  shouldOpenMediaViewer: shouldOpenMediaViewer,
124
117
  shouldDisplayToolTip: shouldDisplayToolTip,
125
- mediaClientConfig: viewMediaClientConfigState,
118
+ mediaClientConfig: mediaClient.mediaClientConfig,
126
119
  mediaViewerItems: Array.from(mediaIdentifierMap.values())
127
120
  }) : /*#__PURE__*/React.createElement(MediaInlineCardErroredView, {
128
121
  message: (intl || createIntl({
@@ -0,0 +1,33 @@
1
+ import React, { useContext, useEffect, useMemo, useState } from 'react';
2
+ import { MediaClientContext, getMediaClient } from '@atlaskit/media-client-react';
3
+ import { useProvider } from '@atlaskit/editor-common/provider-factory';
4
+ export const EditorMediaClientProvider = ({
5
+ children,
6
+ ssr
7
+ }) => {
8
+ const [mediaClientConfig, setMediaClientConfig] = useState();
9
+ const mediaProvider = useProvider('mediaProvider');
10
+ const contextMediaClient = useContext(MediaClientContext);
11
+
12
+ // MediaClientProvider currently requires a mediaClientConfig
13
+ // And inserting the MediaClientProvider will cause a re-render
14
+ // We should use MediaClientProvider once it no longer requires a config
15
+ const mediaClient = useMemo(() => mediaClientConfig ? getMediaClient(mediaClientConfig) : undefined, [mediaClientConfig]);
16
+
17
+ // Consumers can override the mediaClient for renderer,
18
+ // by not providing both SSR config and mediaProvider,
19
+ // and provide a top level mediaClient context
20
+ // This is useful for testing and creating examples.
21
+ useEffect(() => {
22
+ if (ssr !== null && ssr !== void 0 && ssr.config) {
23
+ setMediaClientConfig(ssr.config);
24
+ } else if (mediaProvider) {
25
+ mediaProvider.then(provider => {
26
+ setMediaClientConfig(provider.viewMediaClientConfig);
27
+ });
28
+ }
29
+ }, [mediaProvider, ssr]);
30
+ return /*#__PURE__*/React.createElement(MediaClientContext.Provider, {
31
+ value: mediaClient || contextMediaClient
32
+ }, children);
33
+ };
@@ -1,8 +1,9 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
1
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import React, { Component } from 'react';
3
+ import React, { Component, useContext } from 'react';
3
4
  import { filter } from '@atlaskit/adf-utils/traverse';
4
5
  import { Card, CardLoading, CardError } from '@atlaskit/media-card';
5
- import { getMediaClient } from '@atlaskit/media-client-react';
6
+ import { MediaClientContext } from '@atlaskit/media-client-react';
6
7
  import { withImageLoader } from '@atlaskit/editor-common/utils';
7
8
  export const mediaIdentifierMap = new Map();
8
9
  export const getListOfIdentifiersFromDoc = doc => {
@@ -32,23 +33,25 @@ export const getListOfIdentifiersFromDoc = doc => {
32
33
  return identifierList;
33
34
  }, []);
34
35
  };
35
- export class MediaCardInternal extends Component {
36
+ export class MediaCardView extends Component {
36
37
  constructor(...args) {
37
38
  super(...args);
38
39
  _defineProperty(this, "state", {});
39
- _defineProperty(this, "saveFileState", async (id, mediaClientConfig) => {
40
+ _defineProperty(this, "saveFileState", async id => {
40
41
  const {
41
- collection: collectionName
42
+ collection: collectionName,
43
+ mediaClient
42
44
  } = this.props;
43
- const mediaClient = getMediaClient(mediaClientConfig);
44
45
  const options = {
45
46
  collectionName
46
47
  };
47
48
  try {
48
- const fileState = await mediaClient.file.getCurrentState(id, options);
49
- this.setState({
50
- fileState
51
- });
49
+ if (mediaClient) {
50
+ const fileState = await mediaClient.file.getCurrentState(id, options);
51
+ this.setState({
52
+ fileState
53
+ });
54
+ }
52
55
  } catch (error) {
53
56
  // do not set state on error
54
57
  }
@@ -86,22 +89,16 @@ export class MediaCardInternal extends Component {
86
89
  async componentDidMount() {
87
90
  const {
88
91
  rendererContext,
89
- mediaProvider,
90
92
  contextIdentifierProvider,
91
93
  id,
92
94
  url,
93
95
  collection: collectionName
94
96
  } = this.props;
95
- if (!mediaProvider) {
96
- return;
97
- }
98
97
  if (contextIdentifierProvider) {
99
98
  this.setState({
100
99
  contextIdentifierProvider: await contextIdentifierProvider
101
100
  });
102
101
  }
103
- const mediaProviderObject = await mediaProvider;
104
- const mediaClientConfig = mediaProviderObject.viewMediaClientConfig;
105
102
  const nodeIsInCache = id && mediaIdentifierMap.has(id) || url && mediaIdentifierMap.has(url);
106
103
  if (rendererContext && rendererContext.adDoc && !nodeIsInCache) {
107
104
  getListOfIdentifiersFromDoc(rendererContext.adDoc).forEach(identifier => {
@@ -115,22 +112,16 @@ export class MediaCardInternal extends Component {
115
112
  }
116
113
  });
117
114
  }
118
- this.setState({
119
- mediaClientConfig: mediaClientConfig
120
- });
121
115
  if (id) {
122
- this.saveFileState(id, mediaClientConfig);
116
+ this.saveFileState(id);
123
117
  }
124
118
  }
125
119
  UNSAFE_componentWillReceiveProps(newProps) {
126
- const {
127
- mediaClientConfig
128
- } = this.state;
129
120
  const {
130
121
  id: newId
131
122
  } = newProps;
132
- if (mediaClientConfig && newId && newId !== this.props.id) {
133
- this.saveFileState(newId, mediaClientConfig);
123
+ if (newId && newId !== this.props.id) {
124
+ this.saveFileState(newId);
134
125
  }
135
126
  }
136
127
  componentWillUnmount() {
@@ -145,9 +136,6 @@ export class MediaCardInternal extends Component {
145
136
  }
146
137
  }
147
138
  renderExternal(shouldOpenMediaViewer) {
148
- const {
149
- mediaClientConfig
150
- } = this.state;
151
139
  const {
152
140
  cardDimensions,
153
141
  resizeMode,
@@ -158,7 +146,8 @@ export class MediaCardInternal extends Component {
158
146
  alt,
159
147
  featureFlags,
160
148
  ssr,
161
- rendererAppearance
149
+ rendererAppearance,
150
+ mediaClient
162
151
  } = this.props;
163
152
  if (imageStatus === 'loading' || !url) {
164
153
  return this.renderLoadingCard();
@@ -168,6 +157,9 @@ export class MediaCardInternal extends Component {
168
157
  name: url,
169
158
  mediaItemType: 'external-image'
170
159
  };
160
+
161
+ // we need this statement for the mandatory mediaClientConfig below
162
+ const mediaClientConfig = mediaClient === null || mediaClient === void 0 ? void 0 : mediaClient.mediaClientConfig;
171
163
  return /*#__PURE__*/React.createElement(Card
172
164
  // TODO MPT-315: clean up after we move mediaClientConfig into FileIdentifier
173
165
  // context is not really used when the type is external and we want to render the component asap
@@ -189,7 +181,6 @@ export class MediaCardInternal extends Component {
189
181
  render() {
190
182
  const {
191
183
  contextIdentifierProvider,
192
- mediaClientConfig: mediaClientConfigInState,
193
184
  fileState
194
185
  } = this.state;
195
186
  const {
@@ -207,7 +198,8 @@ export class MediaCardInternal extends Component {
207
198
  shouldOpenMediaViewer: forceOpenMediaViewer,
208
199
  featureFlags,
209
200
  shouldEnableDownloadButton,
210
- ssr
201
+ ssr,
202
+ mediaClient
211
203
  } = this.props;
212
204
  const isMobile = rendererAppearance === 'mobile';
213
205
  const shouldPlayInline = useInlinePlayer !== undefined ? useInlinePlayer : true;
@@ -220,7 +212,7 @@ export class MediaCardInternal extends Component {
220
212
  if (type === 'link') {
221
213
  return null;
222
214
  }
223
- const mediaClientConfig = !!ssr ? ssr.config : mediaClientConfigInState;
215
+ const mediaClientConfig = !!ssr ? ssr.config : mediaClient === null || mediaClient === void 0 ? void 0 : mediaClient.mediaClientConfig;
224
216
  if (!mediaClientConfig || !id) {
225
217
  return this.renderLoadingCard();
226
218
  }
@@ -298,4 +290,10 @@ export const getClipboardAttrs = ({
298
290
  'data-alt': alt
299
291
  };
300
292
  };
293
+ export const MediaCardInternal = props => {
294
+ const mediaClient = useContext(MediaClientContext);
295
+ return /*#__PURE__*/React.createElement(MediaCardView, _extends({}, props, {
296
+ mediaClient: mediaClient
297
+ }));
298
+ };
301
299
  export const MediaCard = withImageLoader(MediaCardInternal);
@@ -1,12 +1,11 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  /** @jsx jsx */
4
- import React, { Fragment, useContext, useLayoutEffect, useRef } from 'react';
4
+ import React, { Fragment, useContext, useLayoutEffect, useRef, PureComponent } from 'react';
5
5
  import { jsx } from '@emotion/react';
6
- import { PureComponent } from 'react';
7
6
  import { getSchemaBasedOnStage } from '@atlaskit/adf-schema/schema-default';
8
7
  import { reduce } from '@atlaskit/adf-utils/traverse';
9
- import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
8
+ import { ProviderFactory, ProviderFactoryProvider } from '@atlaskit/editor-common/provider-factory';
10
9
  import { UnsupportedBlock, BaseTheme, WidthProvider, WithCreateAnalyticsEvent, IntlErrorBoundary } from '@atlaskit/editor-common/ui';
11
10
  import { getAnalyticsAppearance, getAnalyticsEventSeverity, getResponseEndTime, startMeasure, stopMeasure, shouldForceTracking, measureTTI, getDistortedDurationMonitor, browser } from '@atlaskit/editor-common/utils';
12
11
  import { normalizeFeatureFlags } from '@atlaskit/editor-common/normalize-feature-flags';
@@ -32,10 +31,11 @@ import { RendererContextProvider } from '../../renderer-context';
32
31
  import memoizeOne from 'memoize-one';
33
32
  import { ErrorBoundary } from './ErrorBoundary';
34
33
  import { RenderTracking } from '../../react/utils/performance/RenderTracking';
34
+ import { EditorMediaClientProvider } from '../../react/utils/EditorMediaClientProvider';
35
35
  export const NORMAL_SEVERITY_THRESHOLD = 2000;
36
36
  export const DEGRADED_SEVERITY_THRESHOLD = 3000;
37
37
  const packageName = "@atlaskit/renderer";
38
- const packageVersion = "108.20.10";
38
+ const packageVersion = "108.21.0";
39
39
  export class Renderer extends PureComponent {
40
40
  constructor(props) {
41
41
  super(props);
@@ -277,7 +277,8 @@ export class Renderer extends PureComponent {
277
277
  allowColumnSorting,
278
278
  allowCopyToClipboard,
279
279
  allowWrapCodeBlock,
280
- allowCustomPanels
280
+ allowCustomPanels,
281
+ media
281
282
  } = this.props;
282
283
  const featureFlags = this.featureFlags(this.props.featureFlags);
283
284
  const allowNestedHeaderLinks = isNestedHeaderLinksEnabled(allowHeadingAnchorLinks);
@@ -345,7 +346,9 @@ export class Renderer extends PureComponent {
345
346
  value: {
346
347
  fireAnalyticsEvent: event => this.fireAnalyticsEvent(event)
347
348
  }
348
- }, jsx(SmartCardStorageProvider, null, jsx(RendererWrapper, {
349
+ }, jsx(SmartCardStorageProvider, null, jsx(ProviderFactoryProvider, {
350
+ value: this.providerFactory
351
+ }, jsx(RendererWrapper, {
349
352
  appearance: appearance,
350
353
  allowNestedHeaderLinks: allowNestedHeaderLinks,
351
354
  allowColumnSorting: allowColumnSorting,
@@ -357,12 +360,13 @@ export class Renderer extends PureComponent {
357
360
  addTelepointer: this.props.addTelepointer,
358
361
  innerRef: this.editorRef,
359
362
  onClick: handleWrapperOnClick,
360
- onMouseDown: this.onMouseDownEditView
363
+ onMouseDown: this.onMouseDownEditView,
364
+ ssr: media === null || media === void 0 ? void 0 : media.ssr
361
365
  }, enableSsrInlineScripts ? jsx(BreakoutSSRInlineScript, null) : null, jsx(RendererActionsInternalUpdater, {
362
366
  doc: pmDoc,
363
367
  schema: schema,
364
368
  onAnalyticsEvent: this.fireAnalyticsEvent
365
- }, result))))));
369
+ }, result)))))));
366
370
  let rendererResult = truncated ? jsx(TruncatedWrapper, {
367
371
  height: maxHeight,
368
372
  fadeHeight: fadeOutHeight
@@ -440,7 +444,8 @@ const RendererWrapper = /*#__PURE__*/React.memo(props => {
440
444
  onClick,
441
445
  onMouseDown,
442
446
  useBlockRenderForCodeBlock,
443
- addTelepointer
447
+ addTelepointer,
448
+ ssr
444
449
  } = props;
445
450
  const createTelepointer = () => {
446
451
  const telepointer = document.createElement('span');
@@ -496,6 +501,8 @@ const RendererWrapper = /*#__PURE__*/React.memo(props => {
496
501
  "data-appearance": appearance
497
502
  }, jsx(BaseTheme, {
498
503
  baseFontSize: appearance && appearance !== 'comment' ? akEditorFullPageDefaultFontSize : undefined
504
+ }, jsx(EditorMediaClientProvider, {
505
+ ssr: ssr
499
506
  }, jsx("div", {
500
507
  ref: innerRef,
501
508
  onClick: onClick,
@@ -506,7 +513,7 @@ const RendererWrapper = /*#__PURE__*/React.memo(props => {
506
513
  allowColumnSorting: !!allowColumnSorting,
507
514
  useBlockRenderForCodeBlock
508
515
  })
509
- }, children)));
516
+ }, children))));
510
517
  });
511
518
  function RendererActionsInternalUpdater({
512
519
  children,
@@ -432,7 +432,10 @@ var ReactSerializer = /*#__PURE__*/function () {
432
432
  }, {
433
433
  key: "getMediaInlineProps",
434
434
  value: function getMediaInlineProps(node) {
435
- return _objectSpread({}, this.getProps(node));
435
+ var _this$media4;
436
+ return _objectSpread(_objectSpread({}, this.getProps(node)), {}, {
437
+ ssr: (_this$media4 = this.media) === null || _this$media4 === void 0 ? void 0 : _this$media4.ssr
438
+ });
436
439
  }
437
440
  }, {
438
441
  key: "getTaskItemProps",
@@ -10,8 +10,7 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
10
10
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
11
11
  /** @jsx jsx */
12
12
 
13
- import React from 'react';
14
- import { PureComponent } from 'react';
13
+ import React, { PureComponent } from 'react';
15
14
  import { jsx } from '@emotion/react';
16
15
  import { AnalyticsContext } from '@atlaskit/analytics-next';
17
16
  import { MEDIA_CONTEXT } from '@atlaskit/analytics-namespaced-context';
@@ -36,8 +35,7 @@ var Media = /*#__PURE__*/function (_PureComponent) {
36
35
  _defineProperty(_assertThisInitialized(_this), "renderCard", function () {
37
36
  var _borderMark$attrs$col, _borderMark$attrs$siz;
38
37
  var providers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
39
- var mediaProvider = providers.mediaProvider,
40
- contextIdentifierProvider = providers.contextIdentifierProvider;
38
+ var contextIdentifierProvider = providers.contextIdentifierProvider;
41
39
  var _this$props = _this.props,
42
40
  allowAltTextOnImages = _this$props.allowAltTextOnImages,
43
41
  alt = _this$props.alt,
@@ -57,7 +55,6 @@ var Media = /*#__PURE__*/function (_PureComponent) {
57
55
  border: !!borderMark
58
56
  })
59
57
  }, jsx(MediaCard, _extends({
60
- mediaProvider: mediaProvider,
61
58
  contextIdentifierProvider: contextIdentifierProvider
62
59
  }, _this.props, {
63
60
  shouldOpenMediaViewer: shouldOpenMediaViewer,
@@ -9,7 +9,7 @@ import React, { useEffect, useState, useCallback } from 'react';
9
9
  import { MediaInlineCard } from '@atlaskit/media-card';
10
10
  import { MediaInlineCardErroredView, MediaInlineCardLoadingView, messages } from '@atlaskit/media-ui';
11
11
  import { WithProviders } from '@atlaskit/editor-common/provider-factory';
12
- import { getMediaClient } from '@atlaskit/media-client-react';
12
+ import { MediaClientContext } from '@atlaskit/media-client-react';
13
13
  import { getClipboardAttrs, mediaIdentifierMap } from '../../ui/MediaCard';
14
14
  import { createIntl, injectIntl } from 'react-intl-next';
15
15
  import { shouldShowInlineImage, MediaInlineImageCard } from '@atlaskit/editor-common/media-inline';
@@ -31,12 +31,9 @@ export var RenderMediaInline = function RenderMediaInline(_ref) {
31
31
  setContextIdentifierProvider = _useState2[1];
32
32
  var _useState3 = useState(),
33
33
  _useState4 = _slicedToArray(_useState3, 2),
34
- viewMediaClientConfigState = _useState4[0],
35
- setViewMediaClientConfigState = _useState4[1];
36
- var _useState5 = useState(),
37
- _useState6 = _slicedToArray(_useState5, 2),
38
- fileState = _useState6[0],
39
- setFileState = _useState6[1];
34
+ fileState = _useState4[0],
35
+ setFileState = _useState4[1];
36
+ var mediaClient = React.useContext(MediaClientContext);
40
37
  var updateContext = /*#__PURE__*/function () {
41
38
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(contextIdentifierProvider) {
42
39
  var resolvedContextID;
@@ -63,36 +60,40 @@ export var RenderMediaInline = function RenderMediaInline(_ref) {
63
60
  };
64
61
  }();
65
62
  var updateFileState = useCallback( /*#__PURE__*/function () {
66
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id, mediaClientConfig) {
67
- var mediaClient, options, _fileState;
63
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id) {
64
+ var options, _fileState;
68
65
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
69
66
  while (1) switch (_context2.prev = _context2.next) {
70
67
  case 0:
71
- mediaClient = getMediaClient(mediaClientConfig);
72
68
  options = {
73
69
  collectionName: collectionName
74
70
  };
75
- _context2.prev = 2;
71
+ _context2.prev = 1;
72
+ if (!mediaClient) {
73
+ _context2.next = 7;
74
+ break;
75
+ }
76
76
  _context2.next = 5;
77
77
  return mediaClient.file.getCurrentState(id, options);
78
78
  case 5:
79
79
  _fileState = _context2.sent;
80
80
  setFileState(_fileState);
81
+ case 7:
81
82
  _context2.next = 11;
82
83
  break;
83
84
  case 9:
84
85
  _context2.prev = 9;
85
- _context2.t0 = _context2["catch"](2);
86
+ _context2.t0 = _context2["catch"](1);
86
87
  case 11:
87
88
  case "end":
88
89
  return _context2.stop();
89
90
  }
90
- }, _callee2, null, [[2, 9]]);
91
+ }, _callee2, null, [[1, 9]]);
91
92
  }));
92
- return function (_x2, _x3) {
93
+ return function (_x2) {
93
94
  return _ref3.apply(this, arguments);
94
95
  };
95
- }(), [collectionName]);
96
+ }(), [collectionName, mediaClient]);
96
97
  useEffect(function () {
97
98
  var id = identifier.id;
98
99
  var nodeIsInCache = id && mediaIdentifierMap.has(id);
@@ -106,44 +107,17 @@ export var RenderMediaInline = function RenderMediaInline(_ref) {
106
107
  };
107
108
  }, [identifier, collectionName]);
108
109
  useEffect(function () {
109
- var mediaProvider = mediaInlineProviders.mediaProvider,
110
- contextIdentifierProvider = mediaInlineProviders.contextIdentifierProvider;
110
+ var contextIdentifierProvider = mediaInlineProviders.contextIdentifierProvider;
111
111
  var id = clipboardAttrs.id;
112
- updateViewMediaClientConfigState(mediaProvider);
113
112
  updateContext(contextIdentifierProvider);
114
- id && viewMediaClientConfigState && updateFileState(id, viewMediaClientConfigState);
115
- }, [mediaInlineProviders, contextIdentifierProvider, clipboardAttrs, viewMediaClientConfigState, updateFileState]);
116
- var updateViewMediaClientConfigState = /*#__PURE__*/function () {
117
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(mediaProvider) {
118
- var mediaClientConfig;
119
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
120
- while (1) switch (_context3.prev = _context3.next) {
121
- case 0:
122
- if (!mediaProvider) {
123
- _context3.next = 5;
124
- break;
125
- }
126
- _context3.next = 3;
127
- return mediaProvider;
128
- case 3:
129
- mediaClientConfig = _context3.sent;
130
- setViewMediaClientConfigState(mediaClientConfig.viewMediaClientConfig);
131
- case 5:
132
- case "end":
133
- return _context3.stop();
134
- }
135
- }, _callee3);
136
- }));
137
- return function updateViewMediaClientConfigState(_x4) {
138
- return _ref4.apply(this, arguments);
139
- };
140
- }();
113
+ id && updateFileState(id);
114
+ }, [mediaInlineProviders, contextIdentifierProvider, clipboardAttrs, updateFileState]);
141
115
 
142
116
  /*
143
117
  * Only show the loading view if the media provider is not ready
144
118
  * prevents calling the media API before the provider is ready
145
119
  */
146
- if (!viewMediaClientConfigState) {
120
+ if (!mediaClient) {
147
121
  return /*#__PURE__*/React.createElement(MediaInlineCardLoadingView, {
148
122
  message: "",
149
123
  isSelected: false
@@ -151,7 +125,7 @@ export var RenderMediaInline = function RenderMediaInline(_ref) {
151
125
  }
152
126
  if (type && shouldShowInlineImage(type)) {
153
127
  return /*#__PURE__*/React.createElement(MediaInlineImageCard, {
154
- mediaClient: getMediaClient(viewMediaClientConfigState),
128
+ mediaClient: mediaClient,
155
129
  identifier: identifier,
156
130
  alt: alt,
157
131
  width: width,
@@ -182,7 +156,7 @@ export var RenderMediaInline = function RenderMediaInline(_ref) {
182
156
  onClick: handleMediaInlineClick,
183
157
  shouldOpenMediaViewer: shouldOpenMediaViewer,
184
158
  shouldDisplayToolTip: shouldDisplayToolTip,
185
- mediaClientConfig: viewMediaClientConfigState,
159
+ mediaClientConfig: mediaClient.mediaClientConfig,
186
160
  mediaViewerItems: Array.from(mediaIdentifierMap.values())
187
161
  }) : /*#__PURE__*/React.createElement(MediaInlineCardErroredView, {
188
162
  message: (intl || createIntl({
@@ -0,0 +1,38 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import React, { useContext, useEffect, useMemo, useState } from 'react';
3
+ import { MediaClientContext, getMediaClient } from '@atlaskit/media-client-react';
4
+ import { useProvider } from '@atlaskit/editor-common/provider-factory';
5
+ export var EditorMediaClientProvider = function EditorMediaClientProvider(_ref) {
6
+ var children = _ref.children,
7
+ ssr = _ref.ssr;
8
+ var _useState = useState(),
9
+ _useState2 = _slicedToArray(_useState, 2),
10
+ mediaClientConfig = _useState2[0],
11
+ setMediaClientConfig = _useState2[1];
12
+ var mediaProvider = useProvider('mediaProvider');
13
+ var contextMediaClient = useContext(MediaClientContext);
14
+
15
+ // MediaClientProvider currently requires a mediaClientConfig
16
+ // And inserting the MediaClientProvider will cause a re-render
17
+ // We should use MediaClientProvider once it no longer requires a config
18
+ var mediaClient = useMemo(function () {
19
+ return mediaClientConfig ? getMediaClient(mediaClientConfig) : undefined;
20
+ }, [mediaClientConfig]);
21
+
22
+ // Consumers can override the mediaClient for renderer,
23
+ // by not providing both SSR config and mediaProvider,
24
+ // and provide a top level mediaClient context
25
+ // This is useful for testing and creating examples.
26
+ useEffect(function () {
27
+ if (ssr !== null && ssr !== void 0 && ssr.config) {
28
+ setMediaClientConfig(ssr.config);
29
+ } else if (mediaProvider) {
30
+ mediaProvider.then(function (provider) {
31
+ setMediaClientConfig(provider.viewMediaClientConfig);
32
+ });
33
+ }
34
+ }, [mediaProvider, ssr]);
35
+ return /*#__PURE__*/React.createElement(MediaClientContext.Provider, {
36
+ value: mediaClient || contextMediaClient
37
+ }, children);
38
+ };