@atlaskit/media-card 73.1.0 → 73.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/dist/cjs/files/cardImageView/index.js +51 -41
- package/dist/cjs/root/card/cardAnalytics.js +4 -4
- package/dist/cjs/root/card/getCardPreview/index.js +7 -1
- package/dist/cjs/root/card/index.js +301 -155
- package/dist/cjs/root/cardView.js +128 -118
- package/dist/cjs/root/inlinePlayer.js +4 -2
- package/dist/cjs/root/ui/imageRenderer/imageRenderer.js +17 -23
- package/dist/cjs/root/ui/styled.js +5 -5
- package/dist/cjs/types.js +10 -1
- package/dist/cjs/utils/analytics.js +32 -13
- package/dist/cjs/utils/dimensionComparer.js +7 -13
- package/dist/cjs/utils/getMediaCardCursor.js +29 -0
- package/dist/cjs/utils/globalScope/getSSRData.js +20 -0
- package/dist/cjs/utils/globalScope/globalScope.js +94 -0
- package/dist/cjs/utils/globalScope/index.js +39 -0
- package/dist/cjs/utils/globalScope/types.js +5 -0
- package/dist/cjs/utils/printScript.js +44 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/files/cardImageView/index.js +19 -5
- package/dist/es2019/root/card/cardAnalytics.js +4 -4
- package/dist/es2019/root/card/getCardPreview/index.js +1 -0
- package/dist/es2019/root/card/index.js +167 -40
- package/dist/es2019/root/cardView.js +41 -35
- package/dist/es2019/root/inlinePlayer.js +4 -2
- package/dist/es2019/root/ui/imageRenderer/imageRenderer.js +17 -19
- package/dist/es2019/root/ui/styled.js +4 -4
- package/dist/es2019/types.js +7 -1
- package/dist/es2019/utils/analytics.js +17 -9
- package/dist/es2019/utils/dimensionComparer.js +6 -13
- package/dist/es2019/utils/getMediaCardCursor.js +19 -0
- package/dist/es2019/utils/globalScope/getSSRData.js +10 -0
- package/dist/es2019/utils/globalScope/globalScope.js +62 -0
- package/dist/es2019/utils/globalScope/index.js +2 -0
- package/dist/es2019/utils/globalScope/types.js +1 -0
- package/dist/es2019/utils/printScript.js +19 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/files/cardImageView/index.js +53 -41
- package/dist/esm/root/card/cardAnalytics.js +4 -4
- package/dist/esm/root/card/getCardPreview/index.js +3 -0
- package/dist/esm/root/card/index.js +284 -138
- package/dist/esm/root/cardView.js +127 -118
- package/dist/esm/root/inlinePlayer.js +4 -2
- package/dist/esm/root/ui/imageRenderer/imageRenderer.js +17 -21
- package/dist/esm/root/ui/styled.js +5 -5
- package/dist/esm/types.js +7 -1
- package/dist/esm/utils/analytics.js +26 -12
- package/dist/esm/utils/dimensionComparer.js +8 -13
- package/dist/esm/utils/getMediaCardCursor.js +19 -0
- package/dist/esm/utils/globalScope/getSSRData.js +10 -0
- package/dist/esm/utils/globalScope/globalScope.js +69 -0
- package/dist/esm/utils/globalScope/index.js +2 -0
- package/dist/esm/utils/globalScope/types.js +1 -0
- package/dist/esm/utils/printScript.js +30 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/__tests_external__/page-objects/MediaCard.d.ts +0 -1
- package/dist/types/errors.d.ts +1 -1
- package/dist/types/files/cardImageView/index.d.ts +6 -2
- package/dist/types/root/card/cardAnalytics.d.ts +2 -1
- package/dist/types/root/card/getCardPreview/index.d.ts +1 -0
- package/dist/types/root/card/index.d.ts +5 -1
- package/dist/types/root/cardView.d.ts +8 -6
- package/dist/types/root/inlinePlayer.d.ts +3 -1
- package/dist/types/root/ui/imageRenderer/imageRenderer.d.ts +5 -14
- package/dist/types/root/ui/styled.d.ts +2 -1
- package/dist/types/types.d.ts +6 -1
- package/dist/types/utils/analytics.d.ts +27 -5
- package/dist/types/utils/getMediaCardCursor.d.ts +2 -0
- package/dist/types/utils/globalScope/getSSRData.d.ts +3 -0
- package/dist/types/utils/globalScope/globalScope.d.ts +21 -0
- package/dist/types/utils/globalScope/index.d.ts +4 -0
- package/dist/types/utils/globalScope/types.d.ts +8 -0
- package/dist/types/utils/printScript.d.ts +2 -0
- package/package.json +12 -12
|
@@ -11,16 +11,19 @@ import { injectIntl, IntlProvider } from 'react-intl-next';
|
|
|
11
11
|
import { CardView } from '../cardView';
|
|
12
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, getSSRCardPreview, isLocalPreview, isSSRPreview, isSSRClientPreview, fetchAndCacheRemotePreview } from './getCardPreview';
|
|
14
|
+
import { getCardPreview, getCardPreviewFromCache, removeCardPreviewFromCache, getFilePreviewFromFileState, shouldResolvePreview, getSSRCardPreview, isLocalPreview, isSSRPreview, isSSRClientPreview, isSSRDataPreview, fetchAndCacheRemotePreview } from './getCardPreview';
|
|
15
15
|
import { getFileDetails } from '../../utils/metadata';
|
|
16
16
|
import { InlinePlayer } from '../inlinePlayer';
|
|
17
|
-
import { getFileAttributes } from '../../utils/analytics';
|
|
17
|
+
import { getFileAttributes, extractErrorInfo } from '../../utils/analytics';
|
|
18
18
|
import { isLocalPreviewError, MediaCardError, ensureMediaCardError, ImageLoadError } from '../../errors';
|
|
19
19
|
import { fireOperationalEvent, fireCommencedEvent, relevantFeatureFlagNames, fireCopiedEvent, fireScreenEvent } from './cardAnalytics';
|
|
20
20
|
import getDocument from '../../utils/document';
|
|
21
|
+
import { StoreSSRDataScript, getSSRData } from '../../utils/globalScope';
|
|
21
22
|
import { getCardStateFromFileState, createStateUpdater } from './cardState';
|
|
22
23
|
import { isProcessedFileState } from '@atlaskit/media-client';
|
|
23
24
|
import { getMediaFeatureFlag } from '@atlaskit/media-common';
|
|
25
|
+
import { isBigger } from '../../utils/dimensionComparer';
|
|
26
|
+
import { getMediaCardCursor } from '../../utils/getMediaCardCursor';
|
|
24
27
|
export class CardBase extends Component {
|
|
25
28
|
// We initialise timeElapsedTillCommenced
|
|
26
29
|
// to avoid extra branching on a possibly undefined value.
|
|
@@ -33,6 +36,15 @@ export class CardBase extends Component {
|
|
|
33
36
|
|
|
34
37
|
_defineProperty(this, "viewportPostAnchorRef", /*#__PURE__*/createRef());
|
|
35
38
|
|
|
39
|
+
_defineProperty(this, "ssrReliability", {
|
|
40
|
+
server: {
|
|
41
|
+
status: 'unknown'
|
|
42
|
+
},
|
|
43
|
+
client: {
|
|
44
|
+
status: 'unknown'
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
36
48
|
_defineProperty(this, "timeElapsedTillCommenced", performance.now());
|
|
37
49
|
|
|
38
50
|
_defineProperty(this, "getImageURLParams", ({
|
|
@@ -106,15 +118,19 @@ export class CardBase extends Component {
|
|
|
106
118
|
});
|
|
107
119
|
});
|
|
108
120
|
|
|
109
|
-
_defineProperty(this, "
|
|
121
|
+
_defineProperty(this, "refetchSSRPreview", async identifier => {
|
|
110
122
|
const {
|
|
111
|
-
mediaClient
|
|
123
|
+
mediaClient,
|
|
124
|
+
dimensions = {}
|
|
112
125
|
} = this.props;
|
|
113
126
|
|
|
114
127
|
try {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
128
|
+
const cardPreview = await fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions, this.getImageURLParams(identifier), this.getMediaBlobUrlAttrs(identifier));
|
|
129
|
+
this.safeSetState({
|
|
130
|
+
cardPreview
|
|
131
|
+
});
|
|
132
|
+
} catch (e) {// No need to log this error.
|
|
133
|
+
// If preview fails, it will be refetched later
|
|
118
134
|
}
|
|
119
135
|
});
|
|
120
136
|
|
|
@@ -158,13 +174,41 @@ export class CardBase extends Component {
|
|
|
158
174
|
};
|
|
159
175
|
});
|
|
160
176
|
|
|
161
|
-
_defineProperty(this, "
|
|
177
|
+
_defineProperty(this, "logSSRImageError", cardPreview => {
|
|
178
|
+
if (cardPreview) {
|
|
179
|
+
const failedSSRObject = {
|
|
180
|
+
status: 'fail',
|
|
181
|
+
...extractErrorInfo(new ImageLoadError(cardPreview.source))
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
if (isSSRClientPreview(cardPreview)) {
|
|
185
|
+
this.ssrReliability.client = failedSSRObject;
|
|
186
|
+
}
|
|
187
|
+
/*
|
|
188
|
+
If the cardPreview failed and it comes from server (global scope / ssrData), it means that we have reused it in client and the error counts for both: server & client.
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
if (isSSRDataPreview(cardPreview)) {
|
|
193
|
+
this.ssrReliability.server = failedSSRObject;
|
|
194
|
+
this.ssrReliability.client = failedSSRObject;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
_defineProperty(this, "onImageError", cardPreview => {
|
|
200
|
+
this.logSSRImageError(cardPreview);
|
|
162
201
|
const {
|
|
163
|
-
cardPreview
|
|
164
|
-
} = this.state;
|
|
202
|
+
cardPreview: currentPreview
|
|
203
|
+
} = this.state; // If the dataURI has been replaced, we can dismiss this error
|
|
204
|
+
|
|
205
|
+
if ((cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI) !== (currentPreview === null || currentPreview === void 0 ? void 0 : currentPreview.dataURI)) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
165
209
|
const error = new ImageLoadError(cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.source);
|
|
166
210
|
const isLocal = cardPreview && isLocalPreview(cardPreview);
|
|
167
|
-
const isSSR = cardPreview && isSSRClientPreview(cardPreview);
|
|
211
|
+
const isSSR = cardPreview && (isSSRClientPreview(cardPreview) || isSSRDataPreview(cardPreview));
|
|
168
212
|
|
|
169
213
|
if (isLocal || isSSR) {
|
|
170
214
|
const updateState = {
|
|
@@ -176,10 +220,6 @@ export class CardBase extends Component {
|
|
|
176
220
|
this.fireLocalPreviewErrorEvent(error);
|
|
177
221
|
}
|
|
178
222
|
|
|
179
|
-
if (isSSR) {// TODO: set SSR-client reliability 'failed'.
|
|
180
|
-
// https://product-fabric.atlassian.net/browse/MEX-770
|
|
181
|
-
}
|
|
182
|
-
|
|
183
223
|
const {
|
|
184
224
|
identifier,
|
|
185
225
|
dimensions = {}
|
|
@@ -194,7 +234,36 @@ export class CardBase extends Component {
|
|
|
194
234
|
}
|
|
195
235
|
});
|
|
196
236
|
|
|
197
|
-
_defineProperty(this, "onImageLoad",
|
|
237
|
+
_defineProperty(this, "onImageLoad", cardPreview => {
|
|
238
|
+
if (cardPreview) {
|
|
239
|
+
if (isSSRClientPreview(cardPreview) && this.ssrReliability.client.status === 'unknown') {
|
|
240
|
+
this.ssrReliability.client = {
|
|
241
|
+
status: 'success'
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/*
|
|
245
|
+
If the image loads successfully and it comes from server (global scope / ssrData), it means that we have reused it in client and the success counts for both: server & client.
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
if (isSSRDataPreview(cardPreview) && this.ssrReliability.server.status === 'unknown') {
|
|
250
|
+
this.ssrReliability.server = {
|
|
251
|
+
status: 'success'
|
|
252
|
+
};
|
|
253
|
+
this.ssrReliability.client = {
|
|
254
|
+
status: 'success'
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const {
|
|
260
|
+
cardPreview: currentPreview
|
|
261
|
+
} = this.state; // If the dataURI has been replaced, we can dismiss this callback
|
|
262
|
+
|
|
263
|
+
if ((cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI) !== (currentPreview === null || currentPreview === void 0 ? void 0 : currentPreview.dataURI)) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
|
|
198
267
|
this.safeSetState({
|
|
199
268
|
previewDidRender: true
|
|
200
269
|
});
|
|
@@ -315,7 +384,8 @@ export class CardBase extends Component {
|
|
|
315
384
|
originalDimensions
|
|
316
385
|
} = this.props;
|
|
317
386
|
const {
|
|
318
|
-
shouldAutoplay
|
|
387
|
+
shouldAutoplay,
|
|
388
|
+
cardPreview
|
|
319
389
|
} = this.state;
|
|
320
390
|
return /*#__PURE__*/React.createElement(InlinePlayer, {
|
|
321
391
|
mediaClient: mediaClient,
|
|
@@ -327,7 +397,8 @@ export class CardBase extends Component {
|
|
|
327
397
|
onClick: this.onClick,
|
|
328
398
|
selected: selected,
|
|
329
399
|
ref: this.setRef,
|
|
330
|
-
testId: testId
|
|
400
|
+
testId: testId,
|
|
401
|
+
cardPreview: cardPreview
|
|
331
402
|
});
|
|
332
403
|
});
|
|
333
404
|
|
|
@@ -407,7 +478,9 @@ export class CardBase extends Component {
|
|
|
407
478
|
featureFlags,
|
|
408
479
|
titleBoxBgColor,
|
|
409
480
|
titleBoxIcon,
|
|
410
|
-
ssr
|
|
481
|
+
ssr,
|
|
482
|
+
useInlinePlayer,
|
|
483
|
+
shouldOpenMediaViewer
|
|
411
484
|
} = this.props;
|
|
412
485
|
const {
|
|
413
486
|
mediaItemType
|
|
@@ -415,13 +488,7 @@ export class CardBase extends Component {
|
|
|
415
488
|
const {
|
|
416
489
|
status,
|
|
417
490
|
progress,
|
|
418
|
-
cardPreview
|
|
419
|
-
dataURI,
|
|
420
|
-
orientation
|
|
421
|
-
} = {
|
|
422
|
-
dataURI: undefined,
|
|
423
|
-
orientation: 1
|
|
424
|
-
},
|
|
491
|
+
cardPreview,
|
|
425
492
|
error,
|
|
426
493
|
cardRef,
|
|
427
494
|
isCardVisible
|
|
@@ -440,12 +507,13 @@ export class CardBase extends Component {
|
|
|
440
507
|
const nativeLazyLoad = isLazy && !isCardVisible; // Force Media Image to always display img for SSR
|
|
441
508
|
|
|
442
509
|
const forceSyncDisplay = !!ssr;
|
|
510
|
+
const mediaCardCursor = getMediaCardCursor(!!useInlinePlayer, !!shouldOpenMediaViewer, status === 'error' || status === 'failed-processing', !!this.state.cardPreview, metadata.mediaType);
|
|
443
511
|
const card = /*#__PURE__*/React.createElement(CardView, {
|
|
444
512
|
status: status,
|
|
445
513
|
error: error,
|
|
446
514
|
mediaItemType: mediaItemType,
|
|
447
515
|
metadata: metadata,
|
|
448
|
-
|
|
516
|
+
cardPreview: cardPreview,
|
|
449
517
|
alt: alt,
|
|
450
518
|
appearance: appearance,
|
|
451
519
|
resizeMode: resizeMode,
|
|
@@ -458,7 +526,6 @@ export class CardBase extends Component {
|
|
|
458
526
|
disableOverlay: disableOverlay,
|
|
459
527
|
progress: progress,
|
|
460
528
|
onDisplayImage: onDisplayImage,
|
|
461
|
-
previewOrientation: orientation,
|
|
462
529
|
innerRef: this.setRef,
|
|
463
530
|
testId: testId,
|
|
464
531
|
featureFlags: featureFlags,
|
|
@@ -467,7 +534,8 @@ export class CardBase extends Component {
|
|
|
467
534
|
onImageError: this.onImageError,
|
|
468
535
|
onImageLoad: this.onImageLoad,
|
|
469
536
|
nativeLazyLoad: nativeLazyLoad,
|
|
470
|
-
forceSyncDisplay: forceSyncDisplay
|
|
537
|
+
forceSyncDisplay: forceSyncDisplay,
|
|
538
|
+
mediaCardCursor: mediaCardCursor
|
|
471
539
|
});
|
|
472
540
|
return isLazy ? /*#__PURE__*/React.createElement(ViewportDetector, {
|
|
473
541
|
cardEl: cardRef,
|
|
@@ -483,6 +551,26 @@ export class CardBase extends Component {
|
|
|
483
551
|
})) : card;
|
|
484
552
|
});
|
|
485
553
|
|
|
554
|
+
_defineProperty(this, "storeSSRData", () => {
|
|
555
|
+
var _this$ssrReliability$;
|
|
556
|
+
|
|
557
|
+
const {
|
|
558
|
+
ssr,
|
|
559
|
+
identifier
|
|
560
|
+
} = this.props;
|
|
561
|
+
const {
|
|
562
|
+
cardPreview: {
|
|
563
|
+
dataURI
|
|
564
|
+
} = {}
|
|
565
|
+
} = this.state;
|
|
566
|
+
return isFileIdentifier(identifier) && ssr === 'server' && /*#__PURE__*/React.createElement(StoreSSRDataScript, {
|
|
567
|
+
identifier: identifier,
|
|
568
|
+
dataURI: dataURI,
|
|
569
|
+
dimensions: this.requestedDimensions,
|
|
570
|
+
error: ((_this$ssrReliability$ = this.ssrReliability.server) === null || _this$ssrReliability$ === void 0 ? void 0 : _this$ssrReliability$.status) === 'fail' ? this.ssrReliability.server : undefined
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
|
|
486
574
|
_defineProperty(this, "onCardInViewport", () => {
|
|
487
575
|
this.setState({
|
|
488
576
|
isCardVisible: true
|
|
@@ -527,10 +615,13 @@ export class CardBase extends Component {
|
|
|
527
615
|
|
|
528
616
|
let _cardPreview;
|
|
529
617
|
|
|
618
|
+
let _error;
|
|
619
|
+
|
|
530
620
|
const {
|
|
531
621
|
identifier: _identifier,
|
|
532
622
|
dimensions: _dimensions = {},
|
|
533
|
-
ssr: _ssr
|
|
623
|
+
ssr: _ssr,
|
|
624
|
+
mediaClient: _mediaClient
|
|
534
625
|
} = this.props;
|
|
535
626
|
|
|
536
627
|
if (isFileIdentifier(_identifier)) {
|
|
@@ -540,8 +631,32 @@ export class CardBase extends Component {
|
|
|
540
631
|
_cardPreview = getCardPreviewFromCache(id, _dimensions);
|
|
541
632
|
|
|
542
633
|
if (!_cardPreview && _ssr) {
|
|
543
|
-
|
|
544
|
-
|
|
634
|
+
var _this$ssrData, _this$ssrData2;
|
|
635
|
+
|
|
636
|
+
this.ssrData = getSSRData(_identifier);
|
|
637
|
+
|
|
638
|
+
if ((_this$ssrData = this.ssrData) !== null && _this$ssrData !== void 0 && _this$ssrData.error) {
|
|
639
|
+
this.ssrReliability.server = {
|
|
640
|
+
status: 'fail',
|
|
641
|
+
...this.ssrData.error
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
if (!((_this$ssrData2 = this.ssrData) !== null && _this$ssrData2 !== void 0 && _this$ssrData2.dataURI)) {
|
|
646
|
+
try {
|
|
647
|
+
_cardPreview = getSSRCardPreview(_ssr, _mediaClient, _identifier.id, this.getImageURLParams(_identifier), this.getMediaBlobUrlAttrs(_identifier));
|
|
648
|
+
} catch (e) {
|
|
649
|
+
this.ssrReliability[_ssr] = {
|
|
650
|
+
status: 'fail',
|
|
651
|
+
...extractErrorInfo(e)
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
} else {
|
|
655
|
+
_cardPreview = {
|
|
656
|
+
dataURI: this.ssrData.dataURI,
|
|
657
|
+
source: 'ssr-data'
|
|
658
|
+
};
|
|
659
|
+
}
|
|
545
660
|
}
|
|
546
661
|
} else if (isExternalImageIdentifier(_identifier)) {
|
|
547
662
|
this.fireCommencedEvent();
|
|
@@ -570,7 +685,8 @@ export class CardBase extends Component {
|
|
|
570
685
|
cardPreview: _cardPreview,
|
|
571
686
|
cardRef: null,
|
|
572
687
|
isBannedLocalPreview: false,
|
|
573
|
-
previewDidRender: false
|
|
688
|
+
previewDidRender: false,
|
|
689
|
+
error: _error
|
|
574
690
|
};
|
|
575
691
|
}
|
|
576
692
|
|
|
@@ -582,17 +698,28 @@ export class CardBase extends Component {
|
|
|
582
698
|
} = this.state;
|
|
583
699
|
const {
|
|
584
700
|
identifier,
|
|
585
|
-
ssr
|
|
701
|
+
ssr,
|
|
702
|
+
dimensions
|
|
586
703
|
} = this.props;
|
|
587
704
|
|
|
588
705
|
if (isCardVisible && isFileIdentifier(identifier)) {
|
|
589
706
|
this.updateStateForIdentifier(identifier);
|
|
590
707
|
}
|
|
591
708
|
|
|
592
|
-
if (isCardVisible && !!ssr && !!cardPreview &&
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
709
|
+
if (isCardVisible && !!ssr && !!cardPreview && isFileIdentifier(identifier)) {
|
|
710
|
+
var _this$ssrData3;
|
|
711
|
+
|
|
712
|
+
if (isSSRClientPreview(cardPreview)) {
|
|
713
|
+
// Since the SSR preview brings the token in the query params,
|
|
714
|
+
// We need to fetch the remote preview to be able to cache it,
|
|
715
|
+
this.setCacheSSRPreview(identifier);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
if (isSSRDataPreview(cardPreview) && isBigger((_this$ssrData3 = this.ssrData) === null || _this$ssrData3 === void 0 ? void 0 : _this$ssrData3.dimensions, dimensions)) {
|
|
719
|
+
// If dimensions from Server have changed and are bigger,
|
|
720
|
+
// we need to refetch
|
|
721
|
+
this.refetchSSRPreview(identifier);
|
|
722
|
+
}
|
|
596
723
|
} // we add a listener for each of the cards on the page
|
|
597
724
|
// and then check if the triggered listener is from the card
|
|
598
725
|
// that contains a div in current window.getSelection()
|
|
@@ -775,7 +902,7 @@ export class CardBase extends Component {
|
|
|
775
902
|
const {
|
|
776
903
|
createAnalyticsEvent
|
|
777
904
|
} = this.props;
|
|
778
|
-
createAnalyticsEvent && fireOperationalEvent(createAnalyticsEvent, status, this.fileAttributes, this.getPerformanceAttributes(), error);
|
|
905
|
+
createAnalyticsEvent && fireOperationalEvent(createAnalyticsEvent, status, this.fileAttributes, this.getPerformanceAttributes(), this.ssrReliability, error);
|
|
779
906
|
}
|
|
780
907
|
|
|
781
908
|
fireCommencedEvent() {
|
|
@@ -822,7 +949,7 @@ export class CardBase extends Component {
|
|
|
822
949
|
isPlayingFile,
|
|
823
950
|
mediaViewerSelectedItem
|
|
824
951
|
} = this.state;
|
|
825
|
-
const innerContent = /*#__PURE__*/React.createElement(React.Fragment, null, isPlayingFile ? this.renderInlinePlayer() : this.renderCard(), mediaViewerSelectedItem ? this.renderMediaViewer() : null);
|
|
952
|
+
const innerContent = /*#__PURE__*/React.createElement(React.Fragment, null, isPlayingFile ? this.renderInlinePlayer() : this.renderCard(), mediaViewerSelectedItem ? this.renderMediaViewer() : null, this.storeSSRData());
|
|
826
953
|
return this.props.intl ? innerContent : /*#__PURE__*/React.createElement(IntlProvider, {
|
|
827
954
|
locale: "en"
|
|
828
955
|
}, innerContent);
|
|
@@ -30,6 +30,7 @@ import { PreviewUnavailable, CreatingPreview, FailedToUpload, PreviewCurrentlyUn
|
|
|
30
30
|
import { isRateLimitedError, isPollingError } from '@atlaskit/media-client';
|
|
31
31
|
import { newFileExperienceClassName } from './card/cardConstants';
|
|
32
32
|
import { isUploadError } from '../errors';
|
|
33
|
+
import { MediaCardCursor } from '../types';
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* This is classic vanilla CardView class. To create an instance of class one would need to supply
|
|
@@ -45,32 +46,38 @@ export class CardViewBase extends React.Component {
|
|
|
45
46
|
|
|
46
47
|
_defineProperty(this, "divRef", /*#__PURE__*/React.createRef());
|
|
47
48
|
|
|
48
|
-
_defineProperty(this, "onImageLoad",
|
|
49
|
+
_defineProperty(this, "onImageLoad", prevCardPreview => {
|
|
49
50
|
const {
|
|
50
|
-
onImageLoad
|
|
51
|
-
|
|
51
|
+
onImageLoad,
|
|
52
|
+
cardPreview
|
|
53
|
+
} = this.props;
|
|
54
|
+
|
|
55
|
+
if (prevCardPreview.dataURI !== (cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI)) {
|
|
56
|
+
return;
|
|
57
|
+
} // We render the icon & icon message always, even if there is cardPreview available.
|
|
52
58
|
// If the image fails to load/render, the icon will remain, i.e. the user won't see a change until
|
|
53
59
|
// the root card decides to chage status to error.
|
|
54
60
|
// If the image renders successfully, we switch this variable to hide the icon & icon message
|
|
55
61
|
// behind the thumbnail in case the image has transparency.
|
|
56
|
-
// It is less likely that root component replaces a suceeded
|
|
62
|
+
// It is less likely that root component replaces a suceeded cardPreview for a failed one
|
|
57
63
|
// than the opposite case. Therefore we prefer to hide the icon instead show when the image fails,
|
|
58
64
|
// for a smoother transition
|
|
59
65
|
|
|
66
|
+
|
|
60
67
|
this.setState({
|
|
61
68
|
didImageRender: true
|
|
62
69
|
});
|
|
63
|
-
onImageLoad && onImageLoad();
|
|
70
|
+
onImageLoad && onImageLoad(cardPreview);
|
|
64
71
|
});
|
|
65
72
|
|
|
66
|
-
_defineProperty(this, "onImageError",
|
|
73
|
+
_defineProperty(this, "onImageError", cardPreview => {
|
|
67
74
|
const {
|
|
68
75
|
onImageError
|
|
69
76
|
} = this.props;
|
|
70
77
|
this.setState({
|
|
71
78
|
didImageRender: false
|
|
72
79
|
});
|
|
73
|
-
onImageError && onImageError();
|
|
80
|
+
onImageError && onImageError(cardPreview);
|
|
74
81
|
});
|
|
75
82
|
|
|
76
83
|
_defineProperty(this, "saveElementWidth", () => {
|
|
@@ -106,13 +113,13 @@ export class CardViewBase extends React.Component {
|
|
|
106
113
|
selected,
|
|
107
114
|
selectable,
|
|
108
115
|
disableOverlay,
|
|
109
|
-
|
|
116
|
+
cardPreview,
|
|
117
|
+
mediaCardCursor
|
|
110
118
|
} = this.props;
|
|
111
119
|
const {
|
|
112
120
|
name
|
|
113
121
|
} = metadata || {};
|
|
114
|
-
const
|
|
115
|
-
const shouldDisplayBackground = !dataURI || !disableOverlay || status === 'error' || status === 'failed-processing';
|
|
122
|
+
const shouldDisplayBackground = !cardPreview || !disableOverlay || status === 'error' || status === 'failed-processing';
|
|
116
123
|
const isPlayButtonClickable = !!(this.shouldRenderPlayButton() && disableOverlay);
|
|
117
124
|
const isTickBoxSelectable = !disableOverlay && !!selectable && !selected; // Disable tooltip for Media Single
|
|
118
125
|
|
|
@@ -126,7 +133,7 @@ export class CardViewBase extends React.Component {
|
|
|
126
133
|
onMouseEnter: onMouseEnter,
|
|
127
134
|
innerRef: this.divRef,
|
|
128
135
|
breakpoint: this.breakpoint,
|
|
129
|
-
|
|
136
|
+
mediaCardCursor: mediaCardCursor,
|
|
130
137
|
disableOverlay: !!disableOverlay,
|
|
131
138
|
selected: !!selected,
|
|
132
139
|
displayBackground: shouldDisplayBackground,
|
|
@@ -142,21 +149,24 @@ export class CardViewBase extends React.Component {
|
|
|
142
149
|
|
|
143
150
|
_defineProperty(this, "renderFile", () => {
|
|
144
151
|
const {
|
|
152
|
+
cardPreview,
|
|
145
153
|
status,
|
|
146
154
|
mediaItemType,
|
|
147
155
|
metadata,
|
|
148
|
-
dataURI,
|
|
149
156
|
progress,
|
|
150
157
|
resizeMode,
|
|
151
158
|
dimensions,
|
|
152
159
|
selectable,
|
|
153
160
|
selected,
|
|
154
161
|
disableOverlay,
|
|
155
|
-
previewOrientation,
|
|
156
162
|
alt,
|
|
157
163
|
onDisplayImage,
|
|
158
164
|
actions
|
|
159
165
|
} = this.props;
|
|
166
|
+
const {
|
|
167
|
+
dataURI,
|
|
168
|
+
orientation
|
|
169
|
+
} = cardPreview || {};
|
|
160
170
|
const {
|
|
161
171
|
name,
|
|
162
172
|
mediaType,
|
|
@@ -183,16 +193,17 @@ export class CardViewBase extends React.Component {
|
|
|
183
193
|
onDisplayImage: onDisplayImage,
|
|
184
194
|
actions: actionsWithDetails,
|
|
185
195
|
disableOverlay: disableOverlay,
|
|
186
|
-
previewOrientation:
|
|
196
|
+
previewOrientation: orientation,
|
|
187
197
|
alt: alt,
|
|
188
198
|
onImageLoad: this.onImageLoad,
|
|
189
|
-
onImageError: this.onImageError
|
|
199
|
+
onImageError: this.onImageError,
|
|
200
|
+
cardPreview: cardPreview
|
|
190
201
|
});
|
|
191
202
|
});
|
|
192
203
|
|
|
193
204
|
_defineProperty(this, "getRenderConfigByStatus", () => {
|
|
194
205
|
const {
|
|
195
|
-
|
|
206
|
+
cardPreview,
|
|
196
207
|
status,
|
|
197
208
|
metadata,
|
|
198
209
|
disableOverlay,
|
|
@@ -210,8 +221,8 @@ export class CardViewBase extends React.Component {
|
|
|
210
221
|
const isZeroSize = !!(metadata && metadata.size === 0);
|
|
211
222
|
const defaultConfig = {
|
|
212
223
|
renderTypeIcon: !didImageRender,
|
|
213
|
-
renderImageRenderer: !!
|
|
214
|
-
renderPlayButton: !!
|
|
224
|
+
renderImageRenderer: !!cardPreview,
|
|
225
|
+
renderPlayButton: !!cardPreview && mediaType === 'video',
|
|
215
226
|
renderBlanket: !disableOverlay,
|
|
216
227
|
renderTitleBox: !disableOverlay && !!name,
|
|
217
228
|
renderTickBox: !disableOverlay && !!selectable
|
|
@@ -330,16 +341,16 @@ export class CardViewBase extends React.Component {
|
|
|
330
341
|
}
|
|
331
342
|
|
|
332
343
|
componentDidUpdate({
|
|
333
|
-
|
|
344
|
+
cardPreview: prevCardPreview
|
|
334
345
|
}) {
|
|
335
346
|
const {
|
|
336
|
-
|
|
347
|
+
cardPreview
|
|
337
348
|
} = this.props; // We should only switch didImageRender to false
|
|
338
|
-
// when
|
|
349
|
+
// when cardPreview goes undefined, not when it is updated.
|
|
339
350
|
// as this method could be triggered after onImageLoad callback,
|
|
340
351
|
// falling on a race condition
|
|
341
352
|
|
|
342
|
-
|
|
353
|
+
!!prevCardPreview && !cardPreview && this.setState({
|
|
343
354
|
didImageRender: false
|
|
344
355
|
});
|
|
345
356
|
}
|
|
@@ -413,13 +424,13 @@ export class CardViewBase extends React.Component {
|
|
|
413
424
|
shouldRenderPlayButton() {
|
|
414
425
|
const {
|
|
415
426
|
metadata,
|
|
416
|
-
|
|
427
|
+
cardPreview
|
|
417
428
|
} = this.props;
|
|
418
429
|
const {
|
|
419
430
|
mediaType
|
|
420
431
|
} = metadata || {};
|
|
421
432
|
|
|
422
|
-
if (mediaType !== 'video' || !
|
|
433
|
+
if (mediaType !== 'video' || !cardPreview) {
|
|
423
434
|
return false;
|
|
424
435
|
}
|
|
425
436
|
|
|
@@ -480,32 +491,26 @@ export class CardViewBase extends React.Component {
|
|
|
480
491
|
|
|
481
492
|
renderImageRenderer() {
|
|
482
493
|
const {
|
|
483
|
-
|
|
494
|
+
cardPreview,
|
|
484
495
|
metadata: {
|
|
485
496
|
mediaType = 'unknown'
|
|
486
497
|
} = {},
|
|
487
|
-
previewOrientation,
|
|
488
498
|
alt,
|
|
489
499
|
resizeMode,
|
|
490
500
|
onDisplayImage,
|
|
491
501
|
nativeLazyLoad,
|
|
492
502
|
forceSyncDisplay
|
|
493
503
|
} = this.props;
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
} = this.state;
|
|
497
|
-
return !!dataURI && /*#__PURE__*/React.createElement(ImageRenderer, {
|
|
498
|
-
dataURI: dataURI,
|
|
504
|
+
return !!cardPreview && /*#__PURE__*/React.createElement(ImageRenderer, {
|
|
505
|
+
cardPreview: cardPreview,
|
|
499
506
|
mediaType: mediaType,
|
|
500
|
-
previewOrientation: previewOrientation,
|
|
501
507
|
alt: alt,
|
|
502
508
|
resizeMode: resizeMode,
|
|
503
509
|
onDisplayImage: onDisplayImage,
|
|
504
510
|
onImageLoad: this.onImageLoad,
|
|
505
511
|
onImageError: this.onImageError,
|
|
506
512
|
nativeLazyLoad: nativeLazyLoad,
|
|
507
|
-
forceSyncDisplay: forceSyncDisplay
|
|
508
|
-
isImageVisible: forceSyncDisplay || didImageRender
|
|
513
|
+
forceSyncDisplay: forceSyncDisplay
|
|
509
514
|
});
|
|
510
515
|
}
|
|
511
516
|
|
|
@@ -558,7 +563,8 @@ export class CardViewBase extends React.Component {
|
|
|
558
563
|
}
|
|
559
564
|
|
|
560
565
|
_defineProperty(CardViewBase, "defaultProps", {
|
|
561
|
-
appearance: 'auto'
|
|
566
|
+
appearance: 'auto',
|
|
567
|
+
mediaCardCursor: MediaCardCursor.NoAction
|
|
562
568
|
});
|
|
563
569
|
|
|
564
570
|
export const CardView = withAnalyticsEvents({
|
|
@@ -216,7 +216,8 @@ export class InlinePlayerBase extends Component {
|
|
|
216
216
|
testId,
|
|
217
217
|
identifier,
|
|
218
218
|
forwardRef,
|
|
219
|
-
autoplay
|
|
219
|
+
autoplay,
|
|
220
|
+
cardPreview
|
|
220
221
|
} = this.props;
|
|
221
222
|
const {
|
|
222
223
|
fileSrc,
|
|
@@ -250,7 +251,8 @@ export class InlinePlayerBase extends Component {
|
|
|
250
251
|
contentId: identifier.id
|
|
251
252
|
},
|
|
252
253
|
originalDimensions: originalDimensions,
|
|
253
|
-
showControls: checkMouseMovement
|
|
254
|
+
showControls: checkMouseMovement,
|
|
255
|
+
poster: cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI
|
|
254
256
|
})), isUploading ? /*#__PURE__*/React.createElement(ProgressBar, {
|
|
255
257
|
progress: progress,
|
|
256
258
|
breakpoint: this.breakpoint,
|
|
@@ -2,10 +2,8 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import React, { useEffect } from 'react';
|
|
3
3
|
import { MediaImage } from '@atlaskit/media-ui';
|
|
4
4
|
import { resizeModeToMediaImageProps } from '../../../utils/resizeModeToMediaImageProps';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
dataURI,
|
|
8
|
-
previewOrientation,
|
|
5
|
+
export const ImageRenderer = ({
|
|
6
|
+
cardPreview,
|
|
9
7
|
alt,
|
|
10
8
|
resizeMode,
|
|
11
9
|
onImageLoad,
|
|
@@ -13,8 +11,7 @@ export const ImageRendererBase = ({
|
|
|
13
11
|
onDisplayImage,
|
|
14
12
|
mediaType,
|
|
15
13
|
nativeLazyLoad,
|
|
16
|
-
forceSyncDisplay
|
|
17
|
-
className = 'media-card-image-renderer'
|
|
14
|
+
forceSyncDisplay
|
|
18
15
|
}) => {
|
|
19
16
|
useEffect(() => {
|
|
20
17
|
// TODO: trigger accordingly with the succeeded event. This could be a breaking change
|
|
@@ -22,21 +19,22 @@ export const ImageRendererBase = ({
|
|
|
22
19
|
onDisplayImage();
|
|
23
20
|
}
|
|
24
21
|
}, [mediaType, onDisplayImage]);
|
|
22
|
+
|
|
23
|
+
const onLoad = () => {
|
|
24
|
+
onImageLoad && onImageLoad(cardPreview);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const onError = () => {
|
|
28
|
+
onImageError && onImageError(cardPreview);
|
|
29
|
+
};
|
|
30
|
+
|
|
25
31
|
return /*#__PURE__*/React.createElement(MediaImage, _extends({
|
|
26
|
-
|
|
27
|
-
dataURI: dataURI,
|
|
32
|
+
dataURI: cardPreview.dataURI,
|
|
28
33
|
alt: alt,
|
|
29
|
-
previewOrientation:
|
|
30
|
-
onImageLoad:
|
|
31
|
-
onImageError:
|
|
34
|
+
previewOrientation: cardPreview.orientation,
|
|
35
|
+
onImageLoad: onLoad,
|
|
36
|
+
onImageError: onError,
|
|
32
37
|
loading: nativeLazyLoad ? 'lazy' : undefined,
|
|
33
38
|
forceSyncDisplay: forceSyncDisplay
|
|
34
39
|
}, resizeModeToMediaImageProps(resizeMode)));
|
|
35
|
-
};
|
|
36
|
-
export const ImageRenderer = styled(ImageRendererBase)`
|
|
37
|
-
${({
|
|
38
|
-
isImageVisible
|
|
39
|
-
}) => `
|
|
40
|
-
visibility: ${isImageVisible ? 'visible' : 'hidden'};
|
|
41
|
-
`}
|
|
42
|
-
`;
|
|
40
|
+
};
|