@atlaskit/media-card 72.0.0 → 73.1.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.
- package/CHANGELOG.md +92 -0
- package/dist/cjs/actions.js +2 -2
- package/dist/cjs/errors.js +35 -11
- package/dist/cjs/files/cardImageView/cardOverlay/styled.js +1 -1
- package/dist/cjs/files/cardImageView/index.js +1 -1
- package/dist/cjs/files/cardImageView/styled.js +1 -1
- package/dist/cjs/index.js +8 -8
- package/dist/cjs/root/card/cardAnalytics.js +2 -2
- package/dist/cjs/root/card/cardLoader.js +66 -124
- package/dist/cjs/root/card/cardState.js +2 -2
- package/dist/cjs/root/card/getCardPreview/cache.js +5 -5
- package/dist/cjs/root/card/getCardPreview/filePreviewStatus.js +4 -1
- package/dist/cjs/root/card/getCardPreview/helpers.js +1 -1
- package/dist/cjs/root/card/getCardPreview/index.js +101 -18
- package/dist/cjs/root/card/getCardStatus.js +1 -1
- package/dist/cjs/root/card/index.js +191 -97
- package/dist/cjs/root/cardView.js +44 -57
- package/dist/cjs/root/inline/loader.js +45 -14
- package/dist/cjs/root/inline/mediaInlineCard.js +31 -11
- package/dist/cjs/root/inlinePlayer.js +77 -24
- package/dist/cjs/root/styled.js +7 -3
- package/dist/cjs/root/ui/actionsBar/styled.js +1 -1
- package/dist/cjs/root/ui/blanket/styled.js +1 -1
- package/dist/cjs/root/ui/common.js +11 -5
- package/dist/cjs/root/ui/iconMessage/index.js +5 -3
- package/dist/cjs/root/ui/iconWrapper/styled.js +1 -1
- package/dist/cjs/root/ui/imageRenderer/imageRenderer.js +6 -2
- package/dist/cjs/root/ui/loadingRateLimited/loadingRateLimited.js +6 -4
- package/dist/cjs/root/ui/loadingRateLimited/styled.js +2 -2
- package/dist/cjs/root/ui/playButton/styled.js +1 -1
- package/dist/cjs/root/ui/progressBar/progressBar.js +7 -4
- package/dist/cjs/root/ui/progressBar/styled.js +8 -9
- package/dist/cjs/root/ui/styled.js +80 -17
- package/dist/cjs/root/ui/tickBox/styled.js +1 -1
- package/dist/cjs/root/ui/titleBox/failedTitleBox.js +4 -2
- package/dist/cjs/root/ui/titleBox/styled.js +2 -4
- package/dist/cjs/root/ui/titleBox/titleBox.js +2 -2
- package/dist/cjs/styles/index.js +25 -23
- package/dist/cjs/styles/mixins.js +1 -1
- package/dist/cjs/utils/analytics.js +2 -1
- package/dist/cjs/utils/breakpoint.js +1 -1
- package/dist/cjs/utils/cardActions/cardActionsDropdownMenu.js +18 -9
- package/dist/cjs/utils/cardActions/index.js +10 -10
- package/dist/cjs/utils/cardActions/styled.js +1 -1
- package/dist/cjs/utils/cardDimensions.js +1 -1
- package/dist/cjs/utils/getErrorMessage.js +2 -2
- package/dist/cjs/utils/index.js +46 -46
- package/dist/cjs/utils/lightCards/styled.js +1 -1
- package/dist/cjs/utils/objectURLCache.js +1 -1
- package/dist/cjs/utils/viewportDetector.js +49 -22
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/errors.js +9 -1
- package/dist/es2019/root/card/cardAnalytics.js +1 -1
- package/dist/es2019/root/card/cardLoader.js +47 -53
- package/dist/es2019/root/card/getCardPreview/filePreviewStatus.js +4 -1
- package/dist/es2019/root/card/getCardPreview/index.js +45 -3
- package/dist/es2019/root/card/index.js +131 -35
- package/dist/es2019/root/cardView.js +26 -40
- package/dist/es2019/root/inline/loader.js +15 -4
- package/dist/es2019/root/inline/mediaInlineCard.js +30 -10
- package/dist/es2019/root/inlinePlayer.js +56 -4
- package/dist/es2019/root/styled.js +2 -1
- package/dist/es2019/root/ui/common.js +7 -1
- package/dist/es2019/root/ui/iconMessage/index.js +3 -2
- package/dist/es2019/root/ui/imageRenderer/imageRenderer.js +6 -2
- package/dist/es2019/root/ui/loadingRateLimited/loadingRateLimited.js +4 -3
- package/dist/es2019/root/ui/loadingRateLimited/styled.js +1 -1
- package/dist/es2019/root/ui/progressBar/progressBar.js +5 -3
- package/dist/es2019/root/ui/progressBar/styled.js +7 -6
- package/dist/es2019/root/ui/styled.js +65 -4
- package/dist/es2019/root/ui/titleBox/failedTitleBox.js +3 -2
- package/dist/es2019/root/ui/titleBox/styled.js +1 -2
- package/dist/es2019/root/ui/titleBox/titleBox.js +1 -1
- package/dist/es2019/utils/cardActions/cardActionsDropdownMenu.js +8 -4
- package/dist/es2019/utils/getErrorMessage.js +1 -1
- package/dist/es2019/utils/viewportDetector.js +48 -18
- package/dist/es2019/version.json +1 -1
- package/dist/esm/actions.js +2 -2
- package/dist/esm/errors.js +28 -9
- package/dist/esm/root/card/cardAnalytics.js +1 -1
- package/dist/esm/root/card/cardLoader.js +66 -126
- package/dist/esm/root/card/cardState.js +2 -2
- package/dist/esm/root/card/getCardPreview/cache.js +3 -2
- package/dist/esm/root/card/getCardPreview/filePreviewStatus.js +4 -1
- package/dist/esm/root/card/getCardPreview/index.js +74 -12
- package/dist/esm/root/card/index.js +198 -100
- package/dist/esm/root/cardView.js +42 -54
- package/dist/esm/root/inline/loader.js +46 -14
- package/dist/esm/root/inline/mediaInlineCard.js +30 -10
- package/dist/esm/root/inlinePlayer.js +74 -23
- package/dist/esm/root/styled.js +3 -2
- package/dist/esm/root/ui/common.js +7 -1
- package/dist/esm/root/ui/iconMessage/index.js +3 -2
- package/dist/esm/root/ui/imageRenderer/imageRenderer.js +6 -2
- package/dist/esm/root/ui/loadingRateLimited/loadingRateLimited.js +4 -3
- package/dist/esm/root/ui/loadingRateLimited/styled.js +1 -1
- package/dist/esm/root/ui/progressBar/progressBar.js +6 -3
- package/dist/esm/root/ui/progressBar/styled.js +7 -7
- package/dist/esm/root/ui/styled.js +61 -13
- package/dist/esm/root/ui/titleBox/failedTitleBox.js +3 -2
- package/dist/esm/root/ui/titleBox/styled.js +1 -2
- package/dist/esm/root/ui/titleBox/titleBox.js +1 -1
- package/dist/esm/utils/cardActions/cardActionsDropdownMenu.js +17 -9
- package/dist/esm/utils/getErrorMessage.js +1 -1
- package/dist/esm/utils/viewportDetector.js +48 -21
- package/dist/esm/version.json +1 -1
- package/dist/types/errors.d.ts +9 -3
- package/dist/types/index.d.ts +3 -1
- package/dist/types/root/card/cardLoader.d.ts +5 -19
- package/dist/types/root/card/getCardPreview/index.d.ts +7 -1
- package/dist/types/root/card/index.d.ts +9 -8
- package/dist/types/root/cardView.d.ts +5 -3
- package/dist/types/root/inline/loader.d.ts +2 -0
- package/dist/types/root/inline/mediaInlineCard.d.ts +3 -5
- package/dist/types/root/inlinePlayer.d.ts +8 -1
- package/dist/types/root/styled.d.ts +1 -0
- package/dist/types/root/ui/common.d.ts +4 -1
- package/dist/types/root/ui/iconMessage/index.d.ts +2 -2
- package/dist/types/root/ui/iconWrapper/styled.d.ts +1 -1
- package/dist/types/root/ui/imageRenderer/imageRenderer.d.ts +3 -2
- package/dist/types/root/ui/loadingRateLimited/loadingRateLimited.d.ts +2 -1
- package/dist/types/root/ui/loadingRateLimited/styled.d.ts +1 -1
- package/dist/types/root/ui/playButton/playButton.d.ts +1 -0
- package/dist/types/root/ui/progressBar/progressBar.d.ts +4 -2
- package/dist/types/root/ui/progressBar/styled.d.ts +3 -2
- package/dist/types/root/ui/styled.d.ts +10 -3
- package/dist/types/root/ui/tickBox/tickBox.d.ts +1 -0
- package/dist/types/root/ui/titleBox/failedTitleBox.d.ts +3 -3
- package/dist/types/root/ui/titleBox/styled.d.ts +1 -1
- package/dist/types/root/ui/titleBox/titleBox.d.ts +2 -10
- package/dist/types/types.d.ts +1 -1
- package/dist/types/utils/getErrorMessage.d.ts +1 -0
- package/dist/types/utils/viewportDetector.d.ts +13 -5
- package/example-helpers/developmentUseMessage.tsx +14 -0
- package/example-helpers/index.tsx +34 -4
- package/example-helpers/selectableCard.tsx +2 -1
- package/package.json +16 -15
- package/dist/cjs/root/card/cardSSRView.js +0 -114
- package/dist/cjs/root/ui/Breakpoint.js +0 -13
- package/dist/cjs/root/ui/styledSSR.js +0 -108
- package/dist/cjs/utils/lazyContent/index.js +0 -56
- package/dist/cjs/utils/lazyContent/styled.js +0 -23
- package/dist/es2019/root/card/cardSSRView.js +0 -93
- package/dist/es2019/root/ui/Breakpoint.js +0 -6
- package/dist/es2019/root/ui/styledSSR.js +0 -93
- package/dist/es2019/utils/lazyContent/index.js +0 -18
- package/dist/es2019/utils/lazyContent/styled.js +0 -12
- package/dist/esm/root/card/cardSSRView.js +0 -92
- package/dist/esm/root/ui/Breakpoint.js +0 -6
- package/dist/esm/root/ui/styledSSR.js +0 -76
- package/dist/esm/utils/lazyContent/index.js +0 -41
- package/dist/esm/utils/lazyContent/styled.js +0 -14
- package/dist/types/root/card/cardSSRView.d.ts +0 -13
- package/dist/types/root/ui/Breakpoint.d.ts +0 -4
- package/dist/types/root/ui/styledSSR.d.ts +0 -16
- package/dist/types/utils/lazyContent/index.d.ts +0 -11
- package/dist/types/utils/lazyContent/styled.d.ts +0 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import React, { Component } from 'react';
|
|
2
|
+
import React, { Component, createRef } from 'react';
|
|
3
3
|
import ReactDOM from 'react-dom';
|
|
4
4
|
import { version as packageVersion, name as packageName } from '../../version.json';
|
|
5
5
|
import { withAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
@@ -7,11 +7,11 @@ import { withMediaAnalyticsContext } from '@atlaskit/media-common';
|
|
|
7
7
|
import DownloadIcon from '@atlaskit/icon/glyph/download';
|
|
8
8
|
import { globalMediaEventEmitter, isDifferentIdentifier, isFileIdentifier, RECENTS_COLLECTION, isImageRepresentationReady, isExternalImageIdentifier, imageResizeModeToFileImageMode } from '@atlaskit/media-client';
|
|
9
9
|
import { MediaViewer } from '@atlaskit/media-viewer';
|
|
10
|
-
import {
|
|
10
|
+
import { injectIntl, IntlProvider } from 'react-intl-next';
|
|
11
11
|
import { CardView } from '../cardView';
|
|
12
|
-
import { ViewportDetector } from '../../utils/viewportDetector';
|
|
12
|
+
import { ABS_VIEWPORT_ANCHOR_OFFSET_TOP, ViewportDetector, ViewportAnchor } from '../../utils/viewportDetector';
|
|
13
13
|
import { getRequestedDimensions } from '../../utils/getDataURIDimension';
|
|
14
|
-
import { getCardPreview, getCardPreviewFromCache, removeCardPreviewFromCache, getFilePreviewFromFileState, shouldResolvePreview } from './getCardPreview';
|
|
14
|
+
import { getCardPreview, getCardPreviewFromCache, removeCardPreviewFromCache, getFilePreviewFromFileState, shouldResolvePreview, getSSRCardPreview, isLocalPreview, isSSRPreview, isSSRClientPreview, fetchAndCacheRemotePreview } from './getCardPreview';
|
|
15
15
|
import { getFileDetails } from '../../utils/metadata';
|
|
16
16
|
import { InlinePlayer } from '../inlinePlayer';
|
|
17
17
|
import { getFileAttributes } from '../../utils/analytics';
|
|
@@ -19,6 +19,8 @@ import { isLocalPreviewError, MediaCardError, ensureMediaCardError, ImageLoadErr
|
|
|
19
19
|
import { fireOperationalEvent, fireCommencedEvent, relevantFeatureFlagNames, fireCopiedEvent, fireScreenEvent } from './cardAnalytics';
|
|
20
20
|
import getDocument from '../../utils/document';
|
|
21
21
|
import { getCardStateFromFileState, createStateUpdater } from './cardState';
|
|
22
|
+
import { isProcessedFileState } from '@atlaskit/media-client';
|
|
23
|
+
import { getMediaFeatureFlag } from '@atlaskit/media-common';
|
|
22
24
|
export class CardBase extends Component {
|
|
23
25
|
// We initialise timeElapsedTillCommenced
|
|
24
26
|
// to avoid extra branching on a possibly undefined value.
|
|
@@ -27,6 +29,10 @@ export class CardBase extends Component {
|
|
|
27
29
|
|
|
28
30
|
_defineProperty(this, "hasBeenMounted", false);
|
|
29
31
|
|
|
32
|
+
_defineProperty(this, "viewportPreAnchorRef", /*#__PURE__*/createRef());
|
|
33
|
+
|
|
34
|
+
_defineProperty(this, "viewportPostAnchorRef", /*#__PURE__*/createRef());
|
|
35
|
+
|
|
30
36
|
_defineProperty(this, "timeElapsedTillCommenced", performance.now());
|
|
31
37
|
|
|
32
38
|
_defineProperty(this, "getImageURLParams", ({
|
|
@@ -88,6 +94,30 @@ export class CardBase extends Component {
|
|
|
88
94
|
};
|
|
89
95
|
});
|
|
90
96
|
|
|
97
|
+
_defineProperty(this, "setCacheSSRPreview", identifier => {
|
|
98
|
+
const {
|
|
99
|
+
mediaClient,
|
|
100
|
+
dimensions = {}
|
|
101
|
+
} = this.props;
|
|
102
|
+
fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions, this.getImageURLParams(identifier), this.getMediaBlobUrlAttrs(identifier)).catch(() => {// No need to log this error.
|
|
103
|
+
// If preview fails, it will be refetched later
|
|
104
|
+
//TODO: test this catch
|
|
105
|
+
// https://product-fabric.atlassian.net/browse/MEX-1071
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
_defineProperty(this, "resolveSSRPreview", (identifier, ssr) => {
|
|
110
|
+
const {
|
|
111
|
+
mediaClient
|
|
112
|
+
} = this.props;
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
return getSSRCardPreview(ssr, mediaClient, identifier.id, this.getImageURLParams(identifier), this.getMediaBlobUrlAttrs(identifier));
|
|
116
|
+
} catch (e) {// TODO: log SSR reliability 'failed'
|
|
117
|
+
// https://product-fabric.atlassian.net/browse/MEX-770
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
91
121
|
_defineProperty(this, "resolvePreview", async (identifier, fileState) => {
|
|
92
122
|
try {
|
|
93
123
|
const params = this.getCardPreviewParams(identifier, fileState);
|
|
@@ -133,18 +163,29 @@ export class CardBase extends Component {
|
|
|
133
163
|
cardPreview
|
|
134
164
|
} = this.state;
|
|
135
165
|
const error = new ImageLoadError(cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.source);
|
|
166
|
+
const isLocal = cardPreview && isLocalPreview(cardPreview);
|
|
167
|
+
const isSSR = cardPreview && isSSRClientPreview(cardPreview);
|
|
168
|
+
|
|
169
|
+
if (isLocal || isSSR) {
|
|
170
|
+
const updateState = {
|
|
171
|
+
cardPreview: undefined
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
if (isLocal) {
|
|
175
|
+
updateState.isBannedLocalPreview = true;
|
|
176
|
+
this.fireLocalPreviewErrorEvent(error);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (isSSR) {// TODO: set SSR-client reliability 'failed'.
|
|
180
|
+
// https://product-fabric.atlassian.net/browse/MEX-770
|
|
181
|
+
}
|
|
136
182
|
|
|
137
|
-
if (cardPreview !== null && cardPreview !== void 0 && cardPreview.source && ['local', 'cache-local'].includes(cardPreview.source)) {
|
|
138
183
|
const {
|
|
139
184
|
identifier,
|
|
140
185
|
dimensions = {}
|
|
141
186
|
} = this.props;
|
|
142
187
|
isFileIdentifier(identifier) && removeCardPreviewFromCache(identifier.id, dimensions);
|
|
143
|
-
this.safeSetState(
|
|
144
|
-
cardPreview: undefined,
|
|
145
|
-
isBannedLocalPreview: true
|
|
146
|
-
});
|
|
147
|
-
this.fireLocalPreviewErrorEvent(error);
|
|
188
|
+
this.safeSetState(updateState);
|
|
148
189
|
} else {
|
|
149
190
|
this.safeSetState({
|
|
150
191
|
status: 'error',
|
|
@@ -225,7 +266,8 @@ export class CardBase extends Component {
|
|
|
225
266
|
|
|
226
267
|
if (useInlinePlayer && isVideo && !!cardPreview) {
|
|
227
268
|
this.setState({
|
|
228
|
-
isPlayingFile: true
|
|
269
|
+
isPlayingFile: true,
|
|
270
|
+
shouldAutoplay: true
|
|
229
271
|
});
|
|
230
272
|
} else if (shouldOpenMediaViewer) {
|
|
231
273
|
let mediaViewerSelectedItem;
|
|
@@ -272,11 +314,15 @@ export class CardBase extends Component {
|
|
|
272
314
|
testId,
|
|
273
315
|
originalDimensions
|
|
274
316
|
} = this.props;
|
|
317
|
+
const {
|
|
318
|
+
shouldAutoplay
|
|
319
|
+
} = this.state;
|
|
275
320
|
return /*#__PURE__*/React.createElement(InlinePlayer, {
|
|
276
321
|
mediaClient: mediaClient,
|
|
277
322
|
dimensions: dimensions,
|
|
278
323
|
originalDimensions: originalDimensions,
|
|
279
324
|
identifier: identifier,
|
|
325
|
+
autoplay: !!shouldAutoplay,
|
|
280
326
|
onError: this.onInlinePlayerError,
|
|
281
327
|
onClick: this.onClick,
|
|
282
328
|
selected: selected,
|
|
@@ -360,7 +406,8 @@ export class CardBase extends Component {
|
|
|
360
406
|
testId,
|
|
361
407
|
featureFlags,
|
|
362
408
|
titleBoxBgColor,
|
|
363
|
-
titleBoxIcon
|
|
409
|
+
titleBoxIcon,
|
|
410
|
+
ssr
|
|
364
411
|
} = this.props;
|
|
365
412
|
const {
|
|
366
413
|
mediaItemType
|
|
@@ -376,7 +423,8 @@ export class CardBase extends Component {
|
|
|
376
423
|
orientation: 1
|
|
377
424
|
},
|
|
378
425
|
error,
|
|
379
|
-
cardRef
|
|
426
|
+
cardRef,
|
|
427
|
+
isCardVisible
|
|
380
428
|
} = this.state;
|
|
381
429
|
const {
|
|
382
430
|
metadata
|
|
@@ -386,7 +434,12 @@ export class CardBase extends Component {
|
|
|
386
434
|
onDisplayImage,
|
|
387
435
|
actions,
|
|
388
436
|
onMouseEnter
|
|
389
|
-
} = this;
|
|
437
|
+
} = this; // Card can be artificially turned visible before entering the viewport
|
|
438
|
+
// For example, when we have the image in cache
|
|
439
|
+
|
|
440
|
+
const nativeLazyLoad = isLazy && !isCardVisible; // Force Media Image to always display img for SSR
|
|
441
|
+
|
|
442
|
+
const forceSyncDisplay = !!ssr;
|
|
390
443
|
const card = /*#__PURE__*/React.createElement(CardView, {
|
|
391
444
|
status: status,
|
|
392
445
|
error: error,
|
|
@@ -412,12 +465,22 @@ export class CardBase extends Component {
|
|
|
412
465
|
titleBoxBgColor: titleBoxBgColor,
|
|
413
466
|
titleBoxIcon: titleBoxIcon,
|
|
414
467
|
onImageError: this.onImageError,
|
|
415
|
-
onImageLoad: this.onImageLoad
|
|
468
|
+
onImageLoad: this.onImageLoad,
|
|
469
|
+
nativeLazyLoad: nativeLazyLoad,
|
|
470
|
+
forceSyncDisplay: forceSyncDisplay
|
|
416
471
|
});
|
|
417
472
|
return isLazy ? /*#__PURE__*/React.createElement(ViewportDetector, {
|
|
418
|
-
|
|
473
|
+
cardEl: cardRef,
|
|
474
|
+
preAnchorRef: this.viewportPreAnchorRef,
|
|
475
|
+
postAnchorRef: this.viewportPostAnchorRef,
|
|
419
476
|
onVisible: this.onCardInViewport
|
|
420
|
-
},
|
|
477
|
+
}, /*#__PURE__*/React.createElement(ViewportAnchor, {
|
|
478
|
+
ref: this.viewportPreAnchorRef,
|
|
479
|
+
offsetTop: -ABS_VIEWPORT_ANCHOR_OFFSET_TOP
|
|
480
|
+
}), card, /*#__PURE__*/React.createElement(ViewportAnchor, {
|
|
481
|
+
ref: this.viewportPostAnchorRef,
|
|
482
|
+
offsetTop: ABS_VIEWPORT_ANCHOR_OFFSET_TOP
|
|
483
|
+
})) : card;
|
|
421
484
|
});
|
|
422
485
|
|
|
423
486
|
_defineProperty(this, "onCardInViewport", () => {
|
|
@@ -466,7 +529,8 @@ export class CardBase extends Component {
|
|
|
466
529
|
|
|
467
530
|
const {
|
|
468
531
|
identifier: _identifier,
|
|
469
|
-
dimensions: _dimensions = {}
|
|
532
|
+
dimensions: _dimensions = {},
|
|
533
|
+
ssr: _ssr
|
|
470
534
|
} = this.props;
|
|
471
535
|
|
|
472
536
|
if (isFileIdentifier(_identifier)) {
|
|
@@ -474,6 +538,11 @@ export class CardBase extends Component {
|
|
|
474
538
|
id
|
|
475
539
|
} = _identifier;
|
|
476
540
|
_cardPreview = getCardPreviewFromCache(id, _dimensions);
|
|
541
|
+
|
|
542
|
+
if (!_cardPreview && _ssr) {
|
|
543
|
+
this.fireCommencedEvent();
|
|
544
|
+
_cardPreview = this.resolveSSRPreview(_identifier, _ssr);
|
|
545
|
+
}
|
|
477
546
|
} else if (isExternalImageIdentifier(_identifier)) {
|
|
478
547
|
this.fireCommencedEvent();
|
|
479
548
|
_status = 'loading-preview';
|
|
@@ -485,15 +554,19 @@ export class CardBase extends Component {
|
|
|
485
554
|
orientation: 1,
|
|
486
555
|
source: 'external'
|
|
487
556
|
};
|
|
488
|
-
} //
|
|
489
|
-
//
|
|
557
|
+
} // If cardPreview is available from local cache or external, `isCardVisible`
|
|
558
|
+
// should be true to avoid flickers during re-mount of the component
|
|
559
|
+
// should not be visible for SSR preview, otherwise we'll fire the metadata fetch from
|
|
560
|
+
// outside the viewport
|
|
561
|
+
|
|
490
562
|
|
|
563
|
+
const _isCardVisible = !this.props.isLazy || !!_cardPreview && !isSSRPreview(_cardPreview);
|
|
491
564
|
|
|
492
|
-
const isCardVisible = _cardPreview ? true : !this.props.isLazy;
|
|
493
565
|
this.state = {
|
|
494
566
|
status: _status,
|
|
495
|
-
isCardVisible,
|
|
567
|
+
isCardVisible: _isCardVisible,
|
|
496
568
|
isPlayingFile: false,
|
|
569
|
+
shouldAutoplay: false,
|
|
497
570
|
cardPreview: _cardPreview,
|
|
498
571
|
cardRef: null,
|
|
499
572
|
isBannedLocalPreview: false,
|
|
@@ -504,14 +577,22 @@ export class CardBase extends Component {
|
|
|
504
577
|
componentDidMount() {
|
|
505
578
|
this.hasBeenMounted = true;
|
|
506
579
|
const {
|
|
507
|
-
isCardVisible
|
|
580
|
+
isCardVisible,
|
|
581
|
+
cardPreview
|
|
508
582
|
} = this.state;
|
|
509
583
|
const {
|
|
510
|
-
identifier
|
|
584
|
+
identifier,
|
|
585
|
+
ssr
|
|
511
586
|
} = this.props;
|
|
512
587
|
|
|
513
588
|
if (isCardVisible && isFileIdentifier(identifier)) {
|
|
514
589
|
this.updateStateForIdentifier(identifier);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
if (isCardVisible && !!ssr && !!cardPreview && isSSRClientPreview(cardPreview) && isFileIdentifier(identifier)) {
|
|
593
|
+
// Since the SSR preview brings the token in the query params,
|
|
594
|
+
// We need to fetch the remote preview to be able to cache it,
|
|
595
|
+
this.setCacheSSRPreview(identifier);
|
|
515
596
|
} // we add a listener for each of the cards on the page
|
|
516
597
|
// and then check if the triggered listener is from the card
|
|
517
598
|
// that contains a div in current window.getSelection()
|
|
@@ -534,7 +615,9 @@ export class CardBase extends Component {
|
|
|
534
615
|
mediaClient,
|
|
535
616
|
identifier,
|
|
536
617
|
dimensions,
|
|
537
|
-
featureFlags
|
|
618
|
+
featureFlags,
|
|
619
|
+
useInlinePlayer,
|
|
620
|
+
disableOverlay
|
|
538
621
|
} = this.props;
|
|
539
622
|
const {
|
|
540
623
|
isCardVisible,
|
|
@@ -542,7 +625,8 @@ export class CardBase extends Component {
|
|
|
542
625
|
status,
|
|
543
626
|
fileState,
|
|
544
627
|
isBannedLocalPreview,
|
|
545
|
-
previewDidRender
|
|
628
|
+
previewDidRender,
|
|
629
|
+
isPlayingFile
|
|
546
630
|
} = this.state;
|
|
547
631
|
const isDifferent = isDifferentIdentifier(prevIdentifier, identifier);
|
|
548
632
|
const turnedVisible = !prevIsCardVisible && isCardVisible;
|
|
@@ -588,13 +672,28 @@ export class CardBase extends Component {
|
|
|
588
672
|
this.resolvePreview(identifier, fileState);
|
|
589
673
|
}
|
|
590
674
|
|
|
675
|
+
if (turnedVisible && this.props.ssr && !!cardPreview && isSSRClientPreview(cardPreview) && isFileIdentifier(identifier)) {
|
|
676
|
+
// Since the SSR preview brings the token in the query params,
|
|
677
|
+
// We need to fetch the remote preview to be able to cache it,
|
|
678
|
+
this.setCacheSSRPreview(identifier);
|
|
679
|
+
}
|
|
680
|
+
|
|
591
681
|
if (previewDidRender && // We should't complete if status is uploading
|
|
592
|
-
['loading
|
|
682
|
+
['loading-preview', 'processing'].includes(status)) {
|
|
593
683
|
this.safeSetState({
|
|
594
684
|
status: 'complete'
|
|
595
685
|
});
|
|
596
686
|
this.unsubscribe();
|
|
597
687
|
}
|
|
688
|
+
|
|
689
|
+
const isVideo = this.fileAttributes.fileMediatype === 'video';
|
|
690
|
+
const videoAvailableToPlay = fileState && isProcessedFileState(fileState);
|
|
691
|
+
|
|
692
|
+
if (isVideo && !isPlayingFile && disableOverlay && useInlinePlayer && videoAvailableToPlay && getMediaFeatureFlag('timestampOnVideo', this.props.featureFlags)) {
|
|
693
|
+
this.setState({
|
|
694
|
+
isPlayingFile: true
|
|
695
|
+
});
|
|
696
|
+
}
|
|
598
697
|
}
|
|
599
698
|
|
|
600
699
|
componentWillUnmount() {
|
|
@@ -649,7 +748,7 @@ export class CardBase extends Component {
|
|
|
649
748
|
} = this.props;
|
|
650
749
|
const {
|
|
651
750
|
cardRef: element
|
|
652
|
-
} = this.state;
|
|
751
|
+
} = this.state || {};
|
|
653
752
|
return getRequestedDimensions({
|
|
654
753
|
dimensions,
|
|
655
754
|
element
|
|
@@ -724,7 +823,7 @@ export class CardBase extends Component {
|
|
|
724
823
|
mediaViewerSelectedItem
|
|
725
824
|
} = this.state;
|
|
726
825
|
const innerContent = /*#__PURE__*/React.createElement(React.Fragment, null, isPlayingFile ? this.renderInlinePlayer() : this.renderCard(), mediaViewerSelectedItem ? this.renderMediaViewer() : null);
|
|
727
|
-
return this.
|
|
826
|
+
return this.props.intl ? innerContent : /*#__PURE__*/React.createElement(IntlProvider, {
|
|
728
827
|
locale: "en"
|
|
729
828
|
}, innerContent);
|
|
730
829
|
}
|
|
@@ -740,11 +839,6 @@ _defineProperty(CardBase, "defaultProps", {
|
|
|
740
839
|
featureFlags: {}
|
|
741
840
|
});
|
|
742
841
|
|
|
743
|
-
_defineProperty(CardBase, "contextTypes", {
|
|
744
|
-
// Required to detect a parent IntlProvider
|
|
745
|
-
intl: intlShape
|
|
746
|
-
});
|
|
747
|
-
|
|
748
842
|
export const Card = withMediaAnalyticsContext({
|
|
749
843
|
packageVersion,
|
|
750
844
|
packageName,
|
|
@@ -752,4 +846,6 @@ export const Card = withMediaAnalyticsContext({
|
|
|
752
846
|
component: 'mediaCard'
|
|
753
847
|
}, {
|
|
754
848
|
filterFeatureFlags: relevantFeatureFlagNames
|
|
755
|
-
})(withAnalyticsEvents()(CardBase
|
|
849
|
+
})(withAnalyticsEvents()(injectIntl(CardBase, {
|
|
850
|
+
enforceContext: false
|
|
851
|
+
})));
|
|
@@ -13,8 +13,7 @@ import { createAndFireMediaCardEvent } from '../utils/analytics';
|
|
|
13
13
|
import { attachDetailsToActions } from '../actions';
|
|
14
14
|
import { getErrorMessage } from '../utils/getErrorMessage';
|
|
15
15
|
import { toHumanReadableMediaSize, messages } from '@atlaskit/media-ui';
|
|
16
|
-
import { NewFileExperienceWrapper } from './ui/styled';
|
|
17
|
-
import { CardImageContainer, calcBreakpointSize } from './ui/styledSSR';
|
|
16
|
+
import { NewFileExperienceWrapper, CardImageContainer, calcBreakpointSize } from './ui/styled';
|
|
18
17
|
import { ImageRenderer } from './ui/imageRenderer/imageRenderer';
|
|
19
18
|
import { TitleBox } from './ui/titleBox/titleBox';
|
|
20
19
|
import { FailedTitleBox } from './ui/titleBox/failedTitleBox';
|
|
@@ -115,11 +114,9 @@ export class CardViewBase extends React.Component {
|
|
|
115
114
|
const shouldUsePointerCursor = status !== 'error' && status !== 'failed-processing';
|
|
116
115
|
const shouldDisplayBackground = !dataURI || !disableOverlay || status === 'error' || status === 'failed-processing';
|
|
117
116
|
const isPlayButtonClickable = !!(this.shouldRenderPlayButton() && disableOverlay);
|
|
118
|
-
const isTickBoxSelectable = !disableOverlay && !!selectable && !selected; //
|
|
119
|
-
// Intention is to show full file name when it's truncate in titlebox,
|
|
120
|
-
// and to hide it when no titlebox exists.
|
|
117
|
+
const isTickBoxSelectable = !disableOverlay && !!selectable && !selected; // Disable tooltip for Media Single
|
|
121
118
|
|
|
122
|
-
const shouldDisplayTooltip =
|
|
119
|
+
const shouldDisplayTooltip = !disableOverlay;
|
|
123
120
|
return /*#__PURE__*/React.createElement(NewFileExperienceWrapper, {
|
|
124
121
|
className: newFileExperienceClassName,
|
|
125
122
|
"data-testid": testId || 'media-card-view',
|
|
@@ -248,42 +245,29 @@ export class CardViewBase extends React.Component {
|
|
|
248
245
|
renderPlayButton: false
|
|
249
246
|
};
|
|
250
247
|
let iconMessage;
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
iconMessage = /*#__PURE__*/React.createElement(PreviewUnavailable, null);
|
|
263
|
-
}
|
|
264
|
-
} else if (!!disableOverlay) {
|
|
248
|
+
let customTitleMessage;
|
|
249
|
+
const {
|
|
250
|
+
secondaryError
|
|
251
|
+
} = error || {};
|
|
252
|
+
|
|
253
|
+
if (isRateLimitedError(secondaryError) || isPollingError(secondaryError)) {
|
|
254
|
+
iconMessage = /*#__PURE__*/React.createElement(PreviewCurrentlyUnavailable, null);
|
|
255
|
+
} else if (isUploadError(error)) {
|
|
256
|
+
iconMessage = /*#__PURE__*/React.createElement(FailedToUpload, null);
|
|
257
|
+
customTitleMessage = messages.failed_to_upload;
|
|
258
|
+
} else if (!metadata) {
|
|
265
259
|
iconMessage = /*#__PURE__*/React.createElement(FailedToLoad, null);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (error && isUploadError(error)) {
|
|
269
|
-
if (!disableOverlay) {
|
|
270
|
-
return { ...baseErrorConfig,
|
|
271
|
-
renderFailedTitleBox: true,
|
|
272
|
-
customTitleMessage: messages.failed_to_upload
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
return { ...baseErrorConfig,
|
|
277
|
-
renderTitleBox: !metadata && !!name,
|
|
278
|
-
iconMessage: /*#__PURE__*/React.createElement(FailedToUpload, null)
|
|
279
|
-
};
|
|
260
|
+
} else {
|
|
261
|
+
iconMessage = /*#__PURE__*/React.createElement(PreviewUnavailable, null);
|
|
280
262
|
}
|
|
281
263
|
|
|
282
264
|
if (!disableOverlay) {
|
|
265
|
+
const renderFailedTitleBox = !name || !!customTitleMessage;
|
|
283
266
|
return { ...baseErrorConfig,
|
|
284
|
-
renderTitleBox: !!name,
|
|
285
|
-
renderFailedTitleBox
|
|
286
|
-
iconMessage
|
|
267
|
+
renderTitleBox: !!name && !customTitleMessage,
|
|
268
|
+
renderFailedTitleBox,
|
|
269
|
+
iconMessage: !renderFailedTitleBox ? iconMessage : undefined,
|
|
270
|
+
customTitleMessage
|
|
287
271
|
};
|
|
288
272
|
}
|
|
289
273
|
|
|
@@ -504,18 +488,20 @@ export class CardViewBase extends React.Component {
|
|
|
504
488
|
alt,
|
|
505
489
|
resizeMode,
|
|
506
490
|
onDisplayImage,
|
|
507
|
-
|
|
491
|
+
nativeLazyLoad,
|
|
492
|
+
forceSyncDisplay
|
|
508
493
|
} = this.props;
|
|
509
494
|
return !!dataURI && /*#__PURE__*/React.createElement(ImageRenderer, {
|
|
510
495
|
dataURI: dataURI,
|
|
511
496
|
mediaType: mediaType,
|
|
512
|
-
mediaItemType: mediaItemType,
|
|
513
497
|
previewOrientation: previewOrientation,
|
|
514
498
|
alt: alt,
|
|
515
499
|
resizeMode: resizeMode,
|
|
516
500
|
onDisplayImage: onDisplayImage,
|
|
517
501
|
onImageLoad: this.onImageLoad,
|
|
518
|
-
onImageError: this.onImageError
|
|
502
|
+
onImageError: this.onImageError,
|
|
503
|
+
nativeLazyLoad: nativeLazyLoad,
|
|
504
|
+
forceSyncDisplay: forceSyncDisplay
|
|
519
505
|
});
|
|
520
506
|
}
|
|
521
507
|
|
|
@@ -5,6 +5,8 @@ export default class MediaInlineCardLoader extends React.PureComponent {
|
|
|
5
5
|
constructor(...args) {
|
|
6
6
|
super(...args);
|
|
7
7
|
|
|
8
|
+
_defineProperty(this, "isMounted", false);
|
|
9
|
+
|
|
8
10
|
_defineProperty(this, "state", {
|
|
9
11
|
MediaInlineCard: MediaInlineCardLoader.MediaInlineCard,
|
|
10
12
|
ErrorBoundary: MediaInlineCardLoader.ErrorBoundary
|
|
@@ -12,6 +14,8 @@ export default class MediaInlineCardLoader extends React.PureComponent {
|
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
async componentDidMount() {
|
|
17
|
+
this.isMounted = true;
|
|
18
|
+
|
|
15
19
|
if (!this.state.MediaInlineCard) {
|
|
16
20
|
try {
|
|
17
21
|
const [mediaClient, cardModule, mediaCardErrorBoundaryModule] = await Promise.all([import(
|
|
@@ -23,14 +27,21 @@ export default class MediaInlineCardLoader extends React.PureComponent {
|
|
|
23
27
|
'../media-card-analytics-error-boundary')]);
|
|
24
28
|
MediaInlineCardLoader.MediaInlineCard = mediaClient.withMediaClient(cardModule.MediaInlineCard);
|
|
25
29
|
MediaInlineCardLoader.ErrorBoundary = mediaCardErrorBoundaryModule.default;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
|
|
31
|
+
if (this.isMounted) {
|
|
32
|
+
this.setState({
|
|
33
|
+
MediaInlineCard: MediaInlineCardLoader.MediaInlineCard,
|
|
34
|
+
ErrorBoundary: MediaInlineCardLoader.ErrorBoundary
|
|
35
|
+
});
|
|
36
|
+
}
|
|
30
37
|
} catch (error) {}
|
|
31
38
|
}
|
|
32
39
|
}
|
|
33
40
|
|
|
41
|
+
async componentWillUnmount() {
|
|
42
|
+
this.isMounted = false;
|
|
43
|
+
}
|
|
44
|
+
|
|
34
45
|
render() {
|
|
35
46
|
const {
|
|
36
47
|
MediaInlineCard,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useState, useEffect } from 'react';
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
|
-
import { injectIntl } from 'react-intl';
|
|
3
|
+
import { injectIntl, IntlProvider, createIntl } from 'react-intl-next';
|
|
4
4
|
import { MediaInlineCardLoadedView, MediaInlineCardLoadingView, MediaInlineCardErroredView, messages } from '@atlaskit/media-ui';
|
|
5
5
|
import { MediaTypeIcon } from '@atlaskit/media-ui/media-type-icon';
|
|
6
6
|
import { MediaViewer } from '@atlaskit/media-viewer';
|
|
@@ -49,46 +49,64 @@ export const MediaInlineCardInternal = ({
|
|
|
49
49
|
return null;
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
+
const renderContent = children => {
|
|
53
|
+
return intl ? children : /*#__PURE__*/React.createElement(IntlProvider, {
|
|
54
|
+
locale: "en"
|
|
55
|
+
}, children);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const defaultIntl = createIntl({
|
|
59
|
+
locale: 'en'
|
|
60
|
+
});
|
|
52
61
|
useEffect(() => {
|
|
53
|
-
mediaClient.file.getFileState(identifier.id, {
|
|
62
|
+
const subscription = mediaClient.file.getFileState(identifier.id, {
|
|
54
63
|
collectionName: identifier.collectionName
|
|
55
64
|
}).subscribe({
|
|
56
65
|
next: fileState => {
|
|
57
66
|
setFileState(fileState);
|
|
67
|
+
setIsErrored(false);
|
|
58
68
|
},
|
|
59
69
|
error: () => {
|
|
60
70
|
setIsErrored(true);
|
|
61
71
|
}
|
|
62
72
|
});
|
|
73
|
+
return () => {
|
|
74
|
+
subscription.unsubscribe();
|
|
75
|
+
};
|
|
63
76
|
}, [identifier.collectionName, identifier.id, mediaClient.file]);
|
|
64
77
|
|
|
65
78
|
if (!fileState) {
|
|
66
79
|
return /*#__PURE__*/React.createElement(MediaInlineCardLoadingView, {
|
|
67
|
-
message: intl.formatMessage(messages.loading_file)
|
|
80
|
+
message: (intl || defaultIntl).formatMessage(messages.loading_file),
|
|
81
|
+
isSelected: isSelected
|
|
68
82
|
});
|
|
69
83
|
}
|
|
70
84
|
|
|
71
85
|
if (isErrored) {
|
|
72
86
|
return /*#__PURE__*/React.createElement(MediaInlineCardErroredView, {
|
|
73
|
-
message: intl.formatMessage(messages.couldnt_load_file)
|
|
87
|
+
message: (intl || defaultIntl).formatMessage(messages.couldnt_load_file),
|
|
88
|
+
isSelected: isSelected
|
|
74
89
|
});
|
|
75
90
|
}
|
|
76
91
|
|
|
77
92
|
if (fileState.status === 'error') {
|
|
78
93
|
return /*#__PURE__*/React.createElement(MediaInlineCardErroredView, {
|
|
79
|
-
message: fileState.message || ''
|
|
94
|
+
message: fileState.message || '',
|
|
95
|
+
isSelected: isSelected
|
|
80
96
|
});
|
|
81
97
|
}
|
|
82
98
|
|
|
83
99
|
if (fileState.status === 'failed-processing') {
|
|
84
100
|
return /*#__PURE__*/React.createElement(MediaInlineCardErroredView, {
|
|
85
|
-
message: intl.formatMessage(messages.couldnt_load_file)
|
|
101
|
+
message: (intl || defaultIntl).formatMessage(messages.couldnt_load_file),
|
|
102
|
+
isSelected: isSelected
|
|
86
103
|
});
|
|
87
104
|
}
|
|
88
105
|
|
|
89
106
|
if (fileState.status === 'uploading') {
|
|
90
107
|
return /*#__PURE__*/React.createElement(MediaInlineCardLoadingView, {
|
|
91
|
-
message: fileState.name
|
|
108
|
+
message: fileState.name,
|
|
109
|
+
isSelected: isSelected
|
|
92
110
|
});
|
|
93
111
|
}
|
|
94
112
|
|
|
@@ -113,7 +131,7 @@ export const MediaInlineCardInternal = ({
|
|
|
113
131
|
formattedDate = formatDate(fileState.createdAt, locale);
|
|
114
132
|
}
|
|
115
133
|
|
|
116
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Tooltip, {
|
|
134
|
+
return renderContent( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Tooltip, {
|
|
117
135
|
position: "bottom",
|
|
118
136
|
content: formattedDate,
|
|
119
137
|
tag: "span"
|
|
@@ -122,6 +140,8 @@ export const MediaInlineCardInternal = ({
|
|
|
122
140
|
title: name,
|
|
123
141
|
onClick: onMediaInlineCardClick,
|
|
124
142
|
isSelected: isSelected
|
|
125
|
-
})), mediaViewer);
|
|
143
|
+
})), mediaViewer));
|
|
126
144
|
};
|
|
127
|
-
export const MediaInlineCard = injectIntl(MediaInlineCardInternal
|
|
145
|
+
export const MediaInlineCard = injectIntl(MediaInlineCardInternal, {
|
|
146
|
+
enforceContext: false
|
|
147
|
+
});
|