@atlaskit/media-card 77.12.3 → 78.0.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 +15 -0
- package/dist/cjs/card/card.js +20 -1039
- package/dist/cjs/card/cardLoader.js +2 -2
- package/dist/cjs/card/cardView.js +255 -417
- package/dist/cjs/card/cardWithMediaClient.js +5 -9
- package/dist/cjs/card/{v2/cardviews → cardviews}/cardViewWrapper.js +8 -8
- package/dist/cjs/card/{v2/cardviews → cardviews}/errorCardView.js +6 -6
- package/dist/cjs/card/{v2/cardviews → cardviews}/iconCardView.js +5 -5
- package/dist/cjs/card/{v2/cardviews → cardviews}/imageCardView.js +5 -5
- package/dist/cjs/card/{v2/cardviews → cardviews}/index.js +2 -2
- package/dist/cjs/card/{v2/cardviews → cardviews}/loadingCardView.js +3 -3
- package/dist/cjs/card/{v2/cardviews → cardviews}/processingCardView.js +4 -4
- package/dist/cjs/card/{v2/cardviews → cardviews}/videoCardView.js +7 -7
- package/dist/cjs/card/{v2/externalImageCard.js → externalImageCard.js} +11 -11
- package/dist/cjs/card/{v2/fileCard.js → fileCard.js} +18 -18
- package/dist/cjs/card/index.js +2 -2
- package/dist/cjs/card/inlinePlayer.js +184 -267
- package/dist/cjs/card/media-card-analytics-error-boundary.js +1 -1
- package/dist/cjs/card/{v2/svgView → svgView}/svgView.js +9 -9
- package/dist/cjs/inline/loader.js +1 -1
- package/dist/cjs/utils/ufoExperiences.js +1 -1
- package/dist/es2019/card/card.js +20 -1023
- package/dist/es2019/card/cardLoader.js +2 -2
- package/dist/es2019/card/cardView.js +252 -403
- package/dist/es2019/card/cardWithMediaClient.js +6 -10
- package/dist/es2019/card/{v2/cardviews → cardviews}/cardViewWrapper.js +8 -8
- package/dist/es2019/card/{v2/cardviews → cardviews}/errorCardView.js +6 -6
- package/dist/es2019/card/{v2/cardviews → cardviews}/iconCardView.js +5 -5
- package/dist/es2019/card/{v2/cardviews → cardviews}/imageCardView.js +5 -5
- package/dist/es2019/card/{v2/cardviews → cardviews}/index.js +2 -2
- package/dist/es2019/card/{v2/cardviews → cardviews}/loadingCardView.js +3 -3
- package/dist/es2019/card/{v2/cardviews → cardviews}/processingCardView.js +4 -4
- package/dist/es2019/card/{v2/cardviews → cardviews}/videoCardView.js +7 -7
- package/dist/es2019/card/{v2/externalImageCard.js → externalImageCard.js} +11 -11
- package/dist/es2019/card/{v2/fileCard.js → fileCard.js} +18 -18
- package/dist/es2019/card/index.js +1 -1
- package/dist/es2019/card/inlinePlayer.js +127 -208
- package/dist/es2019/card/media-card-analytics-error-boundary.js +1 -1
- package/dist/es2019/card/{v2/svgView → svgView}/svgView.js +9 -9
- package/dist/es2019/inline/loader.js +1 -1
- package/dist/es2019/utils/ufoExperiences.js +1 -1
- package/dist/esm/card/card.js +21 -1040
- package/dist/esm/card/cardLoader.js +2 -2
- package/dist/esm/card/cardView.js +251 -416
- package/dist/esm/card/cardWithMediaClient.js +6 -10
- package/dist/esm/card/{v2/cardviews → cardviews}/cardViewWrapper.js +8 -8
- package/dist/esm/card/{v2/cardviews → cardviews}/errorCardView.js +6 -6
- package/dist/esm/card/{v2/cardviews → cardviews}/iconCardView.js +5 -5
- package/dist/esm/card/{v2/cardviews → cardviews}/imageCardView.js +5 -5
- package/dist/esm/card/{v2/cardviews → cardviews}/index.js +2 -2
- package/dist/esm/card/{v2/cardviews → cardviews}/loadingCardView.js +3 -3
- package/dist/esm/card/{v2/cardviews → cardviews}/processingCardView.js +4 -4
- package/dist/esm/card/{v2/cardviews → cardviews}/videoCardView.js +7 -7
- package/dist/esm/card/{v2/externalImageCard.js → externalImageCard.js} +11 -11
- package/dist/esm/card/{v2/fileCard.js → fileCard.js} +18 -18
- package/dist/esm/card/index.js +1 -1
- package/dist/esm/card/inlinePlayer.js +185 -269
- package/dist/esm/card/media-card-analytics-error-boundary.js +1 -1
- package/dist/esm/card/{v2/svgView → svgView}/svgView.js +9 -9
- package/dist/esm/inline/loader.js +1 -1
- package/dist/esm/utils/ufoExperiences.js +1 -1
- package/dist/types/card/card.d.ts +5 -66
- package/dist/types/card/cardLoader.d.ts +1 -1
- package/dist/types/card/cardView.d.ts +23 -45
- package/dist/types/card/cardWithMediaClient.d.ts +1 -1
- package/dist/types/card/{v2/cardviews → cardviews}/cardViewWrapper.d.ts +3 -3
- package/dist/types/card/{v2/cardviews → cardviews}/errorCardView.d.ts +1 -1
- package/dist/{types-ts4.5/card/v2 → types/card}/cardviews/iconCardView.d.ts +1 -1
- package/dist/{types-ts4.5/card/v2 → types/card}/cardviews/imageCardView.d.ts +1 -1
- package/dist/{types-ts4.5/card/v2 → types/card}/cardviews/index.d.ts +5 -5
- package/dist/types/card/{v2/cardviews → cardviews}/videoCardView.d.ts +1 -1
- package/dist/types/card/{v2/externalImageCard.d.ts → externalImageCard.d.ts} +1 -1
- package/dist/types/card/{v2/fileCard.d.ts → fileCard.d.ts} +2 -2
- package/dist/types/card/index.d.ts +1 -1
- package/dist/types/card/inlinePlayer.d.ts +2 -31
- package/dist/types/card/{v2/svgView → svgView}/errors.d.ts +1 -1
- package/dist/{types-ts4.5/card/v2 → types/card}/svgView/svgView.d.ts +2 -2
- package/dist/types-ts4.5/card/card.d.ts +5 -66
- package/dist/types-ts4.5/card/cardLoader.d.ts +1 -1
- package/dist/types-ts4.5/card/cardView.d.ts +23 -45
- package/dist/types-ts4.5/card/cardWithMediaClient.d.ts +1 -1
- package/dist/types-ts4.5/card/{v2/cardviews → cardviews}/cardViewWrapper.d.ts +3 -3
- package/dist/types-ts4.5/card/{v2/cardviews → cardviews}/errorCardView.d.ts +1 -1
- package/dist/{types/card/v2 → types-ts4.5/card}/cardviews/iconCardView.d.ts +1 -1
- package/dist/{types/card/v2 → types-ts4.5/card}/cardviews/imageCardView.d.ts +1 -1
- package/dist/{types/card/v2 → types-ts4.5/card}/cardviews/index.d.ts +5 -5
- package/dist/types-ts4.5/card/{v2/cardviews → cardviews}/videoCardView.d.ts +1 -1
- package/dist/types-ts4.5/card/{v2/externalImageCard.d.ts → externalImageCard.d.ts} +1 -1
- package/dist/types-ts4.5/card/{v2/fileCard.d.ts → fileCard.d.ts} +2 -2
- package/dist/types-ts4.5/card/index.d.ts +1 -1
- package/dist/types-ts4.5/card/inlinePlayer.d.ts +2 -31
- package/dist/types-ts4.5/card/{v2/svgView → svgView}/errors.d.ts +1 -1
- package/dist/{types/card/v2 → types-ts4.5/card}/svgView/svgView.d.ts +2 -2
- package/package.json +3 -6
- package/dist/cjs/card/cardSwitcher.js +0 -15
- package/dist/cjs/card/v2/cardV2.js +0 -41
- package/dist/cjs/card/v2/cardV2Loader.js +0 -36
- package/dist/cjs/card/v2/cardViewV2.js +0 -298
- package/dist/cjs/card/v2/cardWithMediaClientV2.js +0 -34
- package/dist/cjs/card/v2/inlinePlayerLazyV2.js +0 -35
- package/dist/cjs/card/v2/inlinePlayerV2.js +0 -224
- package/dist/es2019/card/cardSwitcher.js +0 -8
- package/dist/es2019/card/v2/cardV2.js +0 -33
- package/dist/es2019/card/v2/cardV2Loader.js +0 -18
- package/dist/es2019/card/v2/cardViewV2.js +0 -294
- package/dist/es2019/card/v2/cardWithMediaClientV2.js +0 -25
- package/dist/es2019/card/v2/inlinePlayerLazyV2.js +0 -10
- package/dist/es2019/card/v2/inlinePlayerV2.js +0 -166
- package/dist/esm/card/cardSwitcher.js +0 -8
- package/dist/esm/card/v2/cardV2.js +0 -34
- package/dist/esm/card/v2/cardV2Loader.js +0 -24
- package/dist/esm/card/v2/cardViewV2.js +0 -290
- package/dist/esm/card/v2/cardWithMediaClientV2.js +0 -27
- package/dist/esm/card/v2/inlinePlayerLazyV2.js +0 -23
- package/dist/esm/card/v2/inlinePlayerV2.js +0 -214
- package/dist/types/card/cardSwitcher.d.ts +0 -4
- package/dist/types/card/v2/cardV2.d.ts +0 -7
- package/dist/types/card/v2/cardV2Loader.d.ts +0 -4
- package/dist/types/card/v2/cardViewV2.d.ts +0 -59
- package/dist/types/card/v2/cardWithMediaClientV2.d.ts +0 -3
- package/dist/types/card/v2/inlinePlayerLazyV2.d.ts +0 -2
- package/dist/types/card/v2/inlinePlayerV2.d.ts +0 -24
- package/dist/types-ts4.5/card/cardSwitcher.d.ts +0 -4
- package/dist/types-ts4.5/card/v2/cardV2.d.ts +0 -7
- package/dist/types-ts4.5/card/v2/cardV2Loader.d.ts +0 -4
- package/dist/types-ts4.5/card/v2/cardViewV2.d.ts +0 -59
- package/dist/types-ts4.5/card/v2/cardWithMediaClientV2.d.ts +0 -3
- package/dist/types-ts4.5/card/v2/inlinePlayerLazyV2.d.ts +0 -2
- package/dist/types-ts4.5/card/v2/inlinePlayerV2.d.ts +0 -24
- /package/dist/cjs/card/{v2/performance.js → performance.js} +0 -0
- /package/dist/cjs/card/{v2/svgView → svgView}/errors.js +0 -0
- /package/dist/cjs/card/{v2/svgView → svgView}/helpers.js +0 -0
- /package/dist/cjs/card/{v2/svgView → svgView}/index.js +0 -0
- /package/dist/es2019/card/{v2/performance.js → performance.js} +0 -0
- /package/dist/es2019/card/{v2/svgView → svgView}/errors.js +0 -0
- /package/dist/es2019/card/{v2/svgView → svgView}/helpers.js +0 -0
- /package/dist/es2019/card/{v2/svgView → svgView}/index.js +0 -0
- /package/dist/esm/card/{v2/performance.js → performance.js} +0 -0
- /package/dist/esm/card/{v2/svgView → svgView}/errors.js +0 -0
- /package/dist/esm/card/{v2/svgView → svgView}/helpers.js +0 -0
- /package/dist/esm/card/{v2/svgView → svgView}/index.js +0 -0
- /package/dist/types/card/{v2/cardviews → cardviews}/loadingCardView.d.ts +0 -0
- /package/dist/types/card/{v2/cardviews → cardviews}/processingCardView.d.ts +0 -0
- /package/dist/types/card/{v2/performance.d.ts → performance.d.ts} +0 -0
- /package/dist/types/card/{v2/svgView → svgView}/helpers.d.ts +0 -0
- /package/dist/types/card/{v2/svgView → svgView}/index.d.ts +0 -0
- /package/dist/types-ts4.5/card/{v2/cardviews → cardviews}/loadingCardView.d.ts +0 -0
- /package/dist/types-ts4.5/card/{v2/cardviews → cardviews}/processingCardView.d.ts +0 -0
- /package/dist/types-ts4.5/card/{v2/performance.d.ts → performance.d.ts} +0 -0
- /package/dist/types-ts4.5/card/{v2/svgView → svgView}/helpers.d.ts +0 -0
- /package/dist/types-ts4.5/card/{v2/svgView → svgView}/index.d.ts +0 -0
package/dist/es2019/card/card.js
CHANGED
|
@@ -1,1036 +1,33 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
-
import React, { Component, Suspense, useContext } from 'react';
|
|
4
|
-
import ReactDOM from 'react-dom';
|
|
5
2
|
import { withAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
3
|
+
import { isFileIdentifier } from '@atlaskit/media-client';
|
|
6
4
|
import { withMediaAnalyticsContext } from '@atlaskit/media-common';
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { injectIntl, IntlProvider } from 'react-intl-next';
|
|
12
|
-
import { CardView } from './cardView';
|
|
13
|
-
import { ViewportDetector } from '../utils/viewportDetector';
|
|
14
|
-
import { videoIsPlayable } from '../utils/videoIsPlayable';
|
|
15
|
-
import { getRequestedDimensions } from '../utils/getDataURIDimension';
|
|
16
|
-
import { getCardPreview, getCardPreviewFromCache, removeCardPreviewFromCache, getFilePreviewFromFileState, shouldResolvePreview, getSSRCardPreview, isLocalPreview, isSSRPreview, isSSRClientPreview, isSSRDataPreview, fetchAndCacheRemotePreview } from './getCardPreview';
|
|
17
|
-
import { getFileDetails } from '../utils/metadata';
|
|
18
|
-
import { InlinePlayerLazy } from './inlinePlayerLazy';
|
|
19
|
-
import { getFileAttributes, extractErrorInfo } from '../utils/analytics';
|
|
20
|
-
import { isLocalPreviewError, MediaCardError, ensureMediaCardError, ImageLoadError } from '../errors';
|
|
21
|
-
import { fireOperationalEvent, fireCommencedEvent, fireCopiedEvent, fireScreenEvent, fireNonCriticalErrorEvent } from './cardAnalytics';
|
|
22
|
-
import getDocument from '../utils/document';
|
|
23
|
-
import { generateScriptProps, getSSRData } from '../utils/globalScope';
|
|
24
|
-
import { getCardStateFromFileState, createStateUpdater } from './cardState';
|
|
25
|
-
import { isBigger } from '../utils/dimensionComparer';
|
|
26
|
-
import { getMediaCardCursor } from '../utils/getMediaCardCursor';
|
|
27
|
-
import { completeUfoExperience, startUfoExperience, abortUfoExperience } from '../utils/ufoExperiences';
|
|
28
|
-
import { generateUniqueId } from '../utils/generateUniqueId';
|
|
29
|
-
import { DateOverrideContext } from '../dateOverrideContext';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { IntlProvider, injectIntl } from 'react-intl-next';
|
|
7
|
+
import { ExternalImageCard } from './externalImageCard';
|
|
8
|
+
import { FileCard } from './fileCard';
|
|
30
9
|
const packageName = "@atlaskit/media-card";
|
|
31
|
-
const packageVersion = "
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
wasStatusProcessing: false
|
|
43
|
-
});
|
|
44
|
-
_defineProperty(this, "ssrReliability", {
|
|
45
|
-
server: {
|
|
46
|
-
status: 'unknown'
|
|
47
|
-
},
|
|
48
|
-
client: {
|
|
49
|
-
status: 'unknown'
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
// We initialise timeElapsedTillCommenced
|
|
53
|
-
// to avoid extra branching on a possibly undefined value.
|
|
54
|
-
_defineProperty(this, "timeElapsedTillCommenced", performance.now());
|
|
55
|
-
// Generate unique traceId for file
|
|
56
|
-
_defineProperty(this, "traceContext", {
|
|
57
|
-
traceId: getRandomHex(8)
|
|
58
|
-
});
|
|
59
|
-
_defineProperty(this, "getImageURLParams", ({
|
|
60
|
-
collectionName: collection
|
|
61
|
-
}) => ({
|
|
62
|
-
collection,
|
|
63
|
-
mode: imageResizeModeToFileImageMode(this.props.resizeMode),
|
|
64
|
-
...this.requestedDimensions,
|
|
65
|
-
allowAnimated: true
|
|
66
|
-
}));
|
|
67
|
-
_defineProperty(this, "getMediaBlobUrlAttrs", (identifier, fileState) => {
|
|
68
|
-
const {
|
|
69
|
-
id,
|
|
70
|
-
collectionName: collection
|
|
71
|
-
} = identifier;
|
|
72
|
-
const {
|
|
73
|
-
originalDimensions,
|
|
74
|
-
contextId,
|
|
75
|
-
alt
|
|
76
|
-
} = this.props;
|
|
77
|
-
const {
|
|
78
|
-
mimeType,
|
|
79
|
-
name,
|
|
80
|
-
size
|
|
81
|
-
} = getFileDetails(identifier, fileState);
|
|
82
|
-
return contextId ? {
|
|
83
|
-
id,
|
|
84
|
-
collection,
|
|
85
|
-
contextId,
|
|
86
|
-
mimeType,
|
|
87
|
-
name,
|
|
88
|
-
size,
|
|
89
|
-
...(originalDimensions || this.requestedDimensions),
|
|
90
|
-
alt
|
|
91
|
-
} : undefined;
|
|
92
|
-
});
|
|
93
|
-
_defineProperty(this, "getCardPreviewParams", (identifier, fileState) => {
|
|
94
|
-
const {
|
|
95
|
-
isBannedLocalPreview
|
|
96
|
-
} = this.state;
|
|
97
|
-
const {
|
|
98
|
-
id
|
|
99
|
-
} = identifier;
|
|
100
|
-
const {
|
|
101
|
-
dimensions = {},
|
|
102
|
-
mediaClient
|
|
103
|
-
} = this.props;
|
|
104
|
-
return {
|
|
105
|
-
mediaClient,
|
|
106
|
-
id,
|
|
107
|
-
dimensions,
|
|
108
|
-
onLocalPreviewError: this.fireNonCriticalErrorEvent,
|
|
109
|
-
filePreview: isBannedLocalPreview ? undefined : getFilePreviewFromFileState(fileState),
|
|
110
|
-
isRemotePreviewReady: isImageRepresentationReady(fileState),
|
|
111
|
-
imageUrlParams: this.getImageURLParams(identifier),
|
|
112
|
-
mediaBlobUrlAttrs: this.getMediaBlobUrlAttrs(identifier, fileState),
|
|
113
|
-
traceContext: this.traceContext
|
|
114
|
-
};
|
|
115
|
-
});
|
|
116
|
-
_defineProperty(this, "setCacheSSRPreview", identifier => {
|
|
117
|
-
this.fetchAndCacheRemotePreview(identifier).catch(() => {
|
|
118
|
-
// No need to log this error.
|
|
119
|
-
// If preview fails, it will be refetched later
|
|
120
|
-
//TODO: test this catch
|
|
121
|
-
// https://product-fabric.atlassian.net/browse/MEX-1071
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
_defineProperty(this, "refetchSSRPreview", async identifier => {
|
|
125
|
-
try {
|
|
126
|
-
const cardPreview = await this.fetchAndCacheRemotePreview(identifier);
|
|
127
|
-
this.safeSetState({
|
|
128
|
-
cardPreview
|
|
129
|
-
});
|
|
130
|
-
} catch (e) {
|
|
131
|
-
const wrappedError = ensureMediaCardError('remote-preview-fetch-ssr', e, true);
|
|
132
|
-
this.fireNonCriticalErrorEvent(wrappedError);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
_defineProperty(this, "resolveUpfrontPreview", async identifier => {
|
|
136
|
-
const requestedDimensions = {
|
|
137
|
-
...this.props.dimensions
|
|
138
|
-
};
|
|
139
|
-
try {
|
|
140
|
-
const cardPreview = await this.fetchAndCacheRemotePreview(identifier);
|
|
141
|
-
const {
|
|
142
|
-
dimensions: currentDimensions
|
|
143
|
-
} = this.props;
|
|
144
|
-
const areValidRequestedDimensions = !isBigger(requestedDimensions, currentDimensions);
|
|
145
|
-
|
|
146
|
-
// If there are new and bigger dimensions in the props, and the upfront preview is still resolving,
|
|
147
|
-
// the fetched preview is no longer valid, and thus, we dismiss it and set the flag wasResolvedUpfrontPreview = true
|
|
148
|
-
// to trigger a normal preview fetch.
|
|
149
|
-
if (areValidRequestedDimensions) {
|
|
150
|
-
this.safeSetState({
|
|
151
|
-
cardPreview,
|
|
152
|
-
wasResolvedUpfrontPreview: true
|
|
153
|
-
});
|
|
154
|
-
} else {
|
|
155
|
-
this.safeSetState({
|
|
156
|
-
wasResolvedUpfrontPreview: true
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
} catch (e) {
|
|
160
|
-
this.safeSetState({
|
|
161
|
-
wasResolvedUpfrontPreview: true
|
|
162
|
-
});
|
|
163
|
-
// NO need to log error. If this call fails, a refetch will happen after
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
_defineProperty(this, "fetchAndCacheRemotePreview", identifier => {
|
|
167
|
-
const {
|
|
168
|
-
mediaClient,
|
|
169
|
-
dimensions = {}
|
|
170
|
-
} = this.props;
|
|
171
|
-
return fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions, this.getImageURLParams(identifier), this.getMediaBlobUrlAttrs(identifier));
|
|
172
|
-
});
|
|
173
|
-
_defineProperty(this, "resolvePreview", async (identifier, fileState) => {
|
|
174
|
-
try {
|
|
175
|
-
const params = this.getCardPreviewParams(identifier, fileState);
|
|
176
|
-
const cardPreview = await getCardPreview(params);
|
|
177
|
-
this.safeSetState({
|
|
178
|
-
cardPreview
|
|
179
|
-
});
|
|
180
|
-
} catch (e) {
|
|
181
|
-
const wrappedError = ensureMediaCardError('preview-fetch', e);
|
|
182
|
-
// If remote preview fails, we set status 'error'
|
|
183
|
-
// If local preview fails (i.e, no remote preview available),
|
|
184
|
-
// we can stay in the same status until there is a remote preview available
|
|
185
|
-
// If it's any other error we set status 'error'
|
|
186
|
-
if (isLocalPreviewError(wrappedError)) {
|
|
187
|
-
// This error should already been logged inside the getCardPreview. No need to log it here.
|
|
188
|
-
this.safeSetState({
|
|
189
|
-
isBannedLocalPreview: true
|
|
190
|
-
});
|
|
191
|
-
} else {
|
|
192
|
-
this.safeSetState({
|
|
193
|
-
status: 'error',
|
|
194
|
-
error: wrappedError
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
_defineProperty(this, "getPerformanceAttributes", () => {
|
|
200
|
-
const {
|
|
201
|
-
timeElapsedTillCommenced
|
|
202
|
-
} = this;
|
|
203
|
-
const timeElapsedTillEvent = performance.now();
|
|
204
|
-
const durationSinceCommenced = timeElapsedTillCommenced && timeElapsedTillEvent - timeElapsedTillCommenced;
|
|
205
|
-
return {
|
|
206
|
-
overall: {
|
|
207
|
-
durationSincePageStart: timeElapsedTillEvent,
|
|
208
|
-
durationSinceCommenced
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
});
|
|
212
|
-
_defineProperty(this, "logSSRImageError", cardPreview => {
|
|
213
|
-
if (cardPreview) {
|
|
214
|
-
const failedSSRObject = {
|
|
215
|
-
status: 'fail',
|
|
216
|
-
...extractErrorInfo(new ImageLoadError(cardPreview.source))
|
|
217
|
-
};
|
|
218
|
-
if (isSSRClientPreview(cardPreview)) {
|
|
219
|
-
this.ssrReliability.client = failedSSRObject;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/*
|
|
223
|
-
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.
|
|
224
|
-
*/
|
|
225
|
-
|
|
226
|
-
if (isSSRDataPreview(cardPreview)) {
|
|
227
|
-
this.ssrReliability.server = failedSSRObject;
|
|
228
|
-
this.ssrReliability.client = failedSSRObject;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
_defineProperty(this, "onImageError", cardPreview => {
|
|
233
|
-
this.logSSRImageError(cardPreview);
|
|
234
|
-
const {
|
|
235
|
-
cardPreview: currentPreview
|
|
236
|
-
} = this.state;
|
|
237
|
-
// If the dataURI has been replaced, we can dismiss this error
|
|
238
|
-
if ((cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI) !== (currentPreview === null || currentPreview === void 0 ? void 0 : currentPreview.dataURI)) {
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
const error = new ImageLoadError(cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.source);
|
|
242
|
-
const isLocal = cardPreview && isLocalPreview(cardPreview);
|
|
243
|
-
const isSSR = cardPreview && (isSSRClientPreview(cardPreview) || isSSRDataPreview(cardPreview));
|
|
244
|
-
if (isLocal || isSSR) {
|
|
245
|
-
const updateState = {
|
|
246
|
-
cardPreview: undefined
|
|
247
|
-
};
|
|
248
|
-
if (isLocal) {
|
|
249
|
-
updateState.isBannedLocalPreview = true;
|
|
250
|
-
this.fireNonCriticalErrorEvent(error);
|
|
251
|
-
}
|
|
252
|
-
const {
|
|
253
|
-
identifier,
|
|
254
|
-
resizeMode
|
|
255
|
-
} = this.props;
|
|
256
|
-
const fileImageMode = imageResizeModeToFileImageMode(resizeMode);
|
|
257
|
-
isFileIdentifier(identifier) && removeCardPreviewFromCache(identifier.id, fileImageMode);
|
|
258
|
-
this.safeSetState(updateState);
|
|
259
|
-
} else {
|
|
260
|
-
this.safeSetState({
|
|
261
|
-
status: 'error',
|
|
262
|
-
error
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
_defineProperty(this, "onImageLoad", cardPreview => {
|
|
267
|
-
if (cardPreview) {
|
|
268
|
-
if (isSSRClientPreview(cardPreview) && this.ssrReliability.client.status === 'unknown') {
|
|
269
|
-
this.ssrReliability.client = {
|
|
270
|
-
status: 'success'
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/*
|
|
275
|
-
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.
|
|
276
|
-
*/
|
|
277
|
-
|
|
278
|
-
if (isSSRDataPreview(cardPreview) && this.ssrReliability.server.status === 'unknown') {
|
|
279
|
-
this.ssrReliability.server = {
|
|
280
|
-
status: 'success'
|
|
281
|
-
};
|
|
282
|
-
this.ssrReliability.client = {
|
|
283
|
-
status: 'success'
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
const {
|
|
288
|
-
cardPreview: currentPreview
|
|
289
|
-
} = this.state;
|
|
290
|
-
// If the dataURI has been replaced, we can dismiss this callback
|
|
291
|
-
if ((cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI) !== (currentPreview === null || currentPreview === void 0 ? void 0 : currentPreview.dataURI)) {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
this.safeSetState({
|
|
295
|
-
previewDidRender: true
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
_defineProperty(this, "fireCopiedEvent", () => {
|
|
299
|
-
const {
|
|
300
|
-
createAnalyticsEvent
|
|
301
|
-
} = this.props;
|
|
302
|
-
const {
|
|
303
|
-
cardRef
|
|
304
|
-
} = this.state;
|
|
305
|
-
cardRef && createAnalyticsEvent && fireCopiedEvent(createAnalyticsEvent, this.metadata.id, cardRef);
|
|
306
|
-
});
|
|
307
|
-
_defineProperty(this, "fireScreenEvent", () => {
|
|
308
|
-
const {
|
|
309
|
-
createAnalyticsEvent
|
|
310
|
-
} = this.props;
|
|
311
|
-
createAnalyticsEvent && fireScreenEvent(createAnalyticsEvent, this.fileAttributes);
|
|
312
|
-
});
|
|
313
|
-
_defineProperty(this, "fireNonCriticalErrorEvent", error => {
|
|
314
|
-
const {
|
|
315
|
-
createAnalyticsEvent
|
|
316
|
-
} = this.props;
|
|
317
|
-
const {
|
|
318
|
-
fileState
|
|
319
|
-
} = this.state;
|
|
320
|
-
createAnalyticsEvent && fireNonCriticalErrorEvent(createAnalyticsEvent, this.state.status, this.fileAttributes, this.ssrReliability, error, this.traceContext, fileState === null || fileState === void 0 ? void 0 : fileState.metadataTraceContext);
|
|
321
|
-
});
|
|
322
|
-
_defineProperty(this, "safeSetState", newState => {
|
|
323
|
-
if (this.hasBeenMounted) {
|
|
324
|
-
/**
|
|
325
|
-
* createStateUpdater helper returns a callback to be passed to setState.
|
|
326
|
-
* It decides wether to update the 'status' depending on the current state vs the input state.
|
|
327
|
-
* From docs: "Both state and props received by the updater function are guaranteed to be up-to-date."
|
|
328
|
-
* If the input state brings an error and it won't be updating the state, the error will be logged as non-critical inside the helper.
|
|
329
|
-
* If the error persists int the state, it means it is a critical error and should be logged as a failed event for Card
|
|
330
|
-
*/
|
|
331
|
-
this.setState(createStateUpdater(newState, this.fireNonCriticalErrorEvent));
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
_defineProperty(this, "unsubscribe", () => {
|
|
335
|
-
if (this.subscription) {
|
|
336
|
-
this.subscription.unsubscribe();
|
|
337
|
-
}
|
|
338
|
-
if (this.hasBeenMounted) {
|
|
339
|
-
// TODO MEX-788: add test for "do not remove the card preview when unsubscribing".
|
|
340
|
-
this.setState({
|
|
341
|
-
isBannedLocalPreview: false
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
_defineProperty(this, "onCardViewClick", (event, analyticsEvent) => {
|
|
346
|
-
const {
|
|
347
|
-
identifier,
|
|
348
|
-
useInlinePlayer,
|
|
349
|
-
shouldOpenMediaViewer
|
|
350
|
-
} = this.props;
|
|
351
|
-
const {
|
|
352
|
-
status,
|
|
353
|
-
cardPreview
|
|
354
|
-
} = this.state;
|
|
355
|
-
const {
|
|
356
|
-
metadata
|
|
357
|
-
} = this;
|
|
358
|
-
this.onClick(event, analyticsEvent);
|
|
359
|
-
if (!metadata) {
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
const isVideo = metadata && metadata.mediaType === 'video';
|
|
363
|
-
if (useInlinePlayer && isVideo && !!cardPreview && status !== 'error') {
|
|
364
|
-
this.setState({
|
|
365
|
-
isPlayingFile: true,
|
|
366
|
-
shouldAutoplay: true
|
|
367
|
-
});
|
|
368
|
-
} else if (shouldOpenMediaViewer) {
|
|
369
|
-
let mediaViewerSelectedItem;
|
|
370
|
-
if (isFileIdentifier(identifier)) {
|
|
371
|
-
mediaViewerSelectedItem = {
|
|
372
|
-
id: identifier.id,
|
|
373
|
-
mediaItemType: 'file',
|
|
374
|
-
collectionName: identifier.collectionName,
|
|
375
|
-
occurrenceKey: identifier.occurrenceKey
|
|
376
|
-
};
|
|
377
|
-
} else {
|
|
378
|
-
mediaViewerSelectedItem = {
|
|
379
|
-
mediaItemType: 'external-image',
|
|
380
|
-
dataURI: identifier.dataURI,
|
|
381
|
-
name: identifier.name
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
this.setState({
|
|
385
|
-
mediaViewerSelectedItem
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
_defineProperty(this, "onInlinePlayerError", e => {
|
|
390
|
-
this.setState({
|
|
391
|
-
error: new MediaCardError('error-file-state', e),
|
|
392
|
-
status: 'error',
|
|
393
|
-
isPlayingFile: false
|
|
394
|
-
});
|
|
395
|
-
});
|
|
396
|
-
_defineProperty(this, "setRef", cardRef => {
|
|
397
|
-
!!cardRef && this.setState({
|
|
398
|
-
cardRef
|
|
399
|
-
});
|
|
400
|
-
});
|
|
401
|
-
_defineProperty(this, "setMediaViewerButtonRef", buttonRef => {
|
|
402
|
-
this.mediaViewerButtonRef = buttonRef;
|
|
403
|
-
});
|
|
404
|
-
_defineProperty(this, "renderInlinePlayer", () => {
|
|
405
|
-
const {
|
|
406
|
-
identifier,
|
|
407
|
-
mediaClient,
|
|
408
|
-
dimensions,
|
|
409
|
-
selected,
|
|
410
|
-
testId,
|
|
411
|
-
originalDimensions,
|
|
412
|
-
onFullscreenChange,
|
|
413
|
-
videoControlsWrapperRef
|
|
414
|
-
} = this.props;
|
|
415
|
-
const {
|
|
416
|
-
shouldAutoplay,
|
|
417
|
-
cardPreview
|
|
418
|
-
} = this.state;
|
|
419
|
-
const card = this.renderCard(false, 'loading', false);
|
|
420
|
-
return /*#__PURE__*/React.createElement(Suspense, {
|
|
421
|
-
fallback: card
|
|
422
|
-
}, /*#__PURE__*/React.createElement(InlinePlayerLazy, {
|
|
423
|
-
mediaClient: mediaClient,
|
|
424
|
-
dimensions: dimensions,
|
|
425
|
-
originalDimensions: originalDimensions,
|
|
426
|
-
identifier: identifier,
|
|
427
|
-
autoplay: !!shouldAutoplay,
|
|
428
|
-
onFullscreenChange: onFullscreenChange,
|
|
429
|
-
onError: this.onInlinePlayerError,
|
|
430
|
-
onClick: this.onClick,
|
|
431
|
-
selected: selected,
|
|
432
|
-
ref: this.setRef,
|
|
433
|
-
testId: testId,
|
|
434
|
-
cardPreview: cardPreview,
|
|
435
|
-
videoControlsWrapperRef: videoControlsWrapperRef
|
|
436
|
-
}));
|
|
437
|
-
});
|
|
438
|
-
_defineProperty(this, "onMediaViewerClose", () => {
|
|
439
|
-
this.setState({
|
|
440
|
-
mediaViewerSelectedItem: undefined
|
|
441
|
-
}, () => {
|
|
442
|
-
var _this$mediaViewerButt;
|
|
443
|
-
(_this$mediaViewerButt = this.mediaViewerButtonRef) === null || _this$mediaViewerButt === void 0 ? void 0 : _this$mediaViewerButt.focus();
|
|
444
|
-
});
|
|
445
|
-
});
|
|
446
|
-
_defineProperty(this, "onDisplayImage", () => {
|
|
447
|
-
const {
|
|
448
|
-
identifier
|
|
449
|
-
} = this.props;
|
|
450
|
-
let payloadPart;
|
|
451
|
-
if (isFileIdentifier(identifier)) {
|
|
452
|
-
payloadPart = {
|
|
453
|
-
fileId: identifier.id,
|
|
454
|
-
isUserCollection: identifier.collectionName === RECENTS_COLLECTION
|
|
455
|
-
};
|
|
456
|
-
} else {
|
|
457
|
-
payloadPart = {
|
|
458
|
-
fileId: identifier.dataURI,
|
|
459
|
-
isUserCollection: false
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
globalMediaEventEmitter.emit('media-viewed', {
|
|
463
|
-
viewingLevel: 'minimal',
|
|
464
|
-
...payloadPart
|
|
465
|
-
});
|
|
466
|
-
});
|
|
467
|
-
_defineProperty(this, "renderMediaViewer", () => {
|
|
468
|
-
const {
|
|
469
|
-
mediaViewerSelectedItem
|
|
470
|
-
} = this.state;
|
|
471
|
-
const {
|
|
472
|
-
mediaClient,
|
|
473
|
-
identifier,
|
|
474
|
-
mediaViewerItems,
|
|
475
|
-
contextId,
|
|
476
|
-
featureFlags
|
|
477
|
-
} = this.props;
|
|
478
|
-
if (!mediaViewerSelectedItem) {
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
const collectionName = isFileIdentifier(identifier) ? identifier.collectionName || '' : '';
|
|
482
|
-
return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(MediaViewer, {
|
|
483
|
-
collectionName: collectionName,
|
|
484
|
-
items: mediaViewerItems || [],
|
|
485
|
-
mediaClientConfig: mediaClient.config,
|
|
486
|
-
selectedItem: mediaViewerSelectedItem,
|
|
487
|
-
onClose: this.onMediaViewerClose,
|
|
488
|
-
contextId: contextId,
|
|
489
|
-
featureFlags: featureFlags
|
|
490
|
-
}), document.body);
|
|
491
|
-
});
|
|
492
|
-
_defineProperty(this, "renderCard", (withCallbacks = true, cardStatusOverride, izLazyOverride) => {
|
|
493
|
-
const {
|
|
494
|
-
identifier,
|
|
495
|
-
isLazy,
|
|
496
|
-
appearance,
|
|
497
|
-
resizeMode,
|
|
498
|
-
dimensions,
|
|
499
|
-
selectable,
|
|
500
|
-
selected,
|
|
501
|
-
disableOverlay,
|
|
502
|
-
alt,
|
|
503
|
-
testId,
|
|
504
|
-
featureFlags,
|
|
505
|
-
titleBoxBgColor,
|
|
506
|
-
titleBoxIcon,
|
|
507
|
-
ssr,
|
|
508
|
-
useInlinePlayer,
|
|
509
|
-
shouldOpenMediaViewer,
|
|
510
|
-
shouldHideTooltip,
|
|
511
|
-
dateOverride
|
|
512
|
-
} = this.props;
|
|
513
|
-
const {
|
|
514
|
-
mediaItemType
|
|
515
|
-
} = identifier;
|
|
516
|
-
const {
|
|
517
|
-
status,
|
|
518
|
-
progress,
|
|
519
|
-
cardPreview,
|
|
520
|
-
error,
|
|
521
|
-
cardRef,
|
|
522
|
-
isCardVisible
|
|
523
|
-
} = this.state;
|
|
524
|
-
const {
|
|
525
|
-
metadata
|
|
526
|
-
} = this;
|
|
527
|
-
const {
|
|
528
|
-
onCardViewClick,
|
|
529
|
-
onDisplayImage,
|
|
530
|
-
actions,
|
|
531
|
-
onMouseEnter
|
|
532
|
-
} = this;
|
|
533
|
-
const isLazyWithOverride = izLazyOverride === undefined ? isLazy : izLazyOverride;
|
|
534
|
-
|
|
535
|
-
// Card can be artificially turned visible before entering the viewport
|
|
536
|
-
// For example, when we have the image in cache
|
|
537
|
-
const nativeLazyLoad = isLazyWithOverride && !isCardVisible;
|
|
538
|
-
// Force Media Image to always display img for SSR
|
|
539
|
-
const forceSyncDisplay = !!ssr;
|
|
540
|
-
const mediaCardCursor = getMediaCardCursor(!!useInlinePlayer, !!shouldOpenMediaViewer, status === 'error' || status === 'failed-processing', !!this.state.cardPreview, metadata.mediaType);
|
|
541
|
-
const card = /*#__PURE__*/React.createElement(CardView, {
|
|
542
|
-
status: cardStatusOverride || status,
|
|
543
|
-
error: error,
|
|
544
|
-
mediaItemType: mediaItemType,
|
|
545
|
-
metadata: metadata,
|
|
546
|
-
cardPreview: cardPreview,
|
|
547
|
-
alt: alt,
|
|
548
|
-
appearance: appearance,
|
|
549
|
-
resizeMode: resizeMode,
|
|
550
|
-
dimensions: dimensions,
|
|
551
|
-
actions: actions,
|
|
552
|
-
selectable: selectable,
|
|
553
|
-
selected: selected,
|
|
554
|
-
shouldOpenMediaViewer: shouldOpenMediaViewer,
|
|
555
|
-
onClick: withCallbacks ? onCardViewClick : undefined,
|
|
556
|
-
onMouseEnter: withCallbacks ? onMouseEnter : undefined,
|
|
557
|
-
disableOverlay: disableOverlay,
|
|
558
|
-
progress: progress,
|
|
559
|
-
onDisplayImage: withCallbacks ? onDisplayImage : undefined,
|
|
560
|
-
innerRef: this.setRef,
|
|
561
|
-
openMediaViewerButtonRef: this.setMediaViewerButtonRef,
|
|
562
|
-
testId: testId,
|
|
563
|
-
featureFlags: featureFlags,
|
|
564
|
-
titleBoxBgColor: titleBoxBgColor,
|
|
565
|
-
titleBoxIcon: titleBoxIcon,
|
|
566
|
-
onImageError: withCallbacks ? this.onImageError : undefined,
|
|
567
|
-
onImageLoad: withCallbacks ? this.onImageLoad : undefined,
|
|
568
|
-
nativeLazyLoad: nativeLazyLoad,
|
|
569
|
-
forceSyncDisplay: forceSyncDisplay,
|
|
570
|
-
mediaCardCursor: mediaCardCursor,
|
|
571
|
-
shouldHideTooltip: shouldHideTooltip,
|
|
572
|
-
overriddenCreationDate: dateOverride
|
|
573
|
-
});
|
|
574
|
-
return isLazyWithOverride ? /*#__PURE__*/React.createElement(ViewportDetector, {
|
|
575
|
-
cardEl: cardRef,
|
|
576
|
-
onVisible: this.onCardInViewport
|
|
577
|
-
}, card) : card;
|
|
578
|
-
});
|
|
579
|
-
_defineProperty(this, "storeSSRData", () => {
|
|
580
|
-
var _this$ssrReliability$;
|
|
581
|
-
const {
|
|
582
|
-
ssr,
|
|
583
|
-
identifier
|
|
584
|
-
} = this.props;
|
|
585
|
-
const {
|
|
586
|
-
cardPreview: {
|
|
587
|
-
dataURI
|
|
588
|
-
} = {}
|
|
589
|
-
} = this.state;
|
|
590
|
-
return isFileIdentifier(identifier) &&
|
|
591
|
-
// Print the SSR result to be used during hydration
|
|
592
|
-
ssr === 'server' && /*#__PURE__*/React.createElement("script", generateScriptProps(identifier, dataURI, this.requestedDimensions, ((_this$ssrReliability$ = this.ssrReliability.server) === null || _this$ssrReliability$ === void 0 ? void 0 : _this$ssrReliability$.status) === 'fail' ? this.ssrReliability.server : undefined));
|
|
593
|
-
});
|
|
594
|
-
_defineProperty(this, "onCardInViewport", () => {
|
|
595
|
-
this.setState({
|
|
596
|
-
isCardVisible: true
|
|
597
|
-
});
|
|
598
|
-
});
|
|
599
|
-
_defineProperty(this, "onClick", (event, analyticsEvent) => {
|
|
600
|
-
const {
|
|
601
|
-
onClick
|
|
602
|
-
} = this.props;
|
|
603
|
-
const {
|
|
604
|
-
metadata
|
|
605
|
-
} = this;
|
|
606
|
-
if (onClick) {
|
|
607
|
-
const cardEvent = {
|
|
608
|
-
event,
|
|
609
|
-
mediaItemDetails: metadata
|
|
610
|
-
};
|
|
611
|
-
onClick(cardEvent, analyticsEvent);
|
|
612
|
-
}
|
|
613
|
-
});
|
|
614
|
-
_defineProperty(this, "onMouseEnter", event => {
|
|
615
|
-
const {
|
|
616
|
-
onMouseEnter
|
|
617
|
-
} = this.props;
|
|
618
|
-
const {
|
|
619
|
-
metadata
|
|
620
|
-
} = this;
|
|
621
|
-
if (onMouseEnter) {
|
|
622
|
-
const cardEvent = {
|
|
623
|
-
event,
|
|
624
|
-
mediaItemDetails: metadata
|
|
625
|
-
};
|
|
626
|
-
onMouseEnter(cardEvent);
|
|
627
|
-
}
|
|
628
|
-
});
|
|
629
|
-
let _status = 'loading';
|
|
630
|
-
let _cardPreview;
|
|
631
|
-
let _error;
|
|
632
|
-
const {
|
|
633
|
-
identifier: _identifier,
|
|
634
|
-
resizeMode: _resizeMode,
|
|
635
|
-
ssr: _ssr,
|
|
636
|
-
mediaClient: _mediaClient
|
|
637
|
-
} = this.props;
|
|
638
|
-
if (isFileIdentifier(_identifier)) {
|
|
639
|
-
const {
|
|
640
|
-
id
|
|
641
|
-
} = _identifier;
|
|
642
|
-
const fileImageMode = imageResizeModeToFileImageMode(_resizeMode);
|
|
643
|
-
_cardPreview = getCardPreviewFromCache(id, fileImageMode);
|
|
644
|
-
if (!_cardPreview && _ssr) {
|
|
645
|
-
_cardPreview = this.getSSRPreview(_ssr, _identifier, _mediaClient);
|
|
646
|
-
}
|
|
647
|
-
} else if (isExternalImageIdentifier(_identifier)) {
|
|
648
|
-
this.fireCommencedEvent();
|
|
649
|
-
_status = 'loading-preview';
|
|
650
|
-
const {
|
|
651
|
-
dataURI
|
|
652
|
-
} = _identifier;
|
|
653
|
-
_cardPreview = {
|
|
654
|
-
dataURI,
|
|
655
|
-
orientation: 1,
|
|
656
|
-
source: 'external'
|
|
657
|
-
};
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
// If cardPreview is available from local cache or external, `isCardVisible`
|
|
661
|
-
// should be true to avoid flickers during re-mount of the component
|
|
662
|
-
// should not be visible for SSR preview, otherwise we'll fire the metadata fetch from
|
|
663
|
-
// outside the viewport
|
|
664
|
-
const _isCardVisible = !this.props.isLazy || !!_cardPreview && !isSSRPreview(_cardPreview);
|
|
665
|
-
this.state = {
|
|
666
|
-
status: _status,
|
|
667
|
-
isCardVisible: _isCardVisible,
|
|
668
|
-
isPlayingFile: false,
|
|
669
|
-
shouldAutoplay: false,
|
|
670
|
-
cardPreview: _cardPreview,
|
|
671
|
-
cardRef: null,
|
|
672
|
-
isBannedLocalPreview: false,
|
|
673
|
-
previewDidRender: false,
|
|
674
|
-
error: _error,
|
|
675
|
-
wasResolvedUpfrontPreview: false
|
|
676
|
-
};
|
|
677
|
-
}
|
|
678
|
-
getSSRPreview(ssr, identifier, mediaClient) {
|
|
679
|
-
var _this$ssrData, _this$ssrData2;
|
|
680
|
-
this.ssrData = getSSRData(identifier);
|
|
681
|
-
if ((_this$ssrData = this.ssrData) !== null && _this$ssrData !== void 0 && _this$ssrData.error) {
|
|
682
|
-
this.ssrReliability.server = {
|
|
683
|
-
status: 'fail',
|
|
684
|
-
...this.ssrData.error
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
|
-
if (!((_this$ssrData2 = this.ssrData) !== null && _this$ssrData2 !== void 0 && _this$ssrData2.dataURI)) {
|
|
688
|
-
try {
|
|
689
|
-
return getSSRCardPreview(ssr, mediaClient, identifier.id, this.getImageURLParams(identifier), this.getMediaBlobUrlAttrs(identifier));
|
|
690
|
-
} catch (e) {
|
|
691
|
-
this.ssrReliability[ssr] = {
|
|
692
|
-
status: 'fail',
|
|
693
|
-
...extractErrorInfo(e)
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
} else {
|
|
697
|
-
return {
|
|
698
|
-
dataURI: this.ssrData.dataURI,
|
|
699
|
-
source: 'ssr-data'
|
|
700
|
-
};
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
componentDidMount() {
|
|
704
|
-
var _getDocument;
|
|
705
|
-
this.hasBeenMounted = true;
|
|
706
|
-
const {
|
|
707
|
-
isCardVisible,
|
|
708
|
-
cardPreview
|
|
709
|
-
} = this.state;
|
|
710
|
-
const {
|
|
711
|
-
identifier,
|
|
712
|
-
ssr,
|
|
713
|
-
dimensions
|
|
714
|
-
} = this.props;
|
|
715
|
-
if (isCardVisible && isFileIdentifier(identifier)) {
|
|
716
|
-
this.updateStateForIdentifier(identifier);
|
|
717
|
-
if (!cardPreview) {
|
|
718
|
-
this.resolveUpfrontPreview(identifier);
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
if (isCardVisible && !!ssr && !!cardPreview && isFileIdentifier(identifier)) {
|
|
722
|
-
var _this$ssrData3;
|
|
723
|
-
if (isSSRClientPreview(cardPreview)) {
|
|
724
|
-
// Since the SSR preview brings the token in the query params,
|
|
725
|
-
// We need to fetch the remote preview to be able to cache it,
|
|
726
|
-
this.setCacheSSRPreview(identifier);
|
|
727
|
-
}
|
|
728
|
-
if (isSSRDataPreview(cardPreview) && isBigger((_this$ssrData3 = this.ssrData) === null || _this$ssrData3 === void 0 ? void 0 : _this$ssrData3.dimensions, dimensions)) {
|
|
729
|
-
// If dimensions from Server have changed and are bigger,
|
|
730
|
-
// we need to refetch
|
|
731
|
-
// This is repeated in componentDidUpdate because in the case of lazy loading true
|
|
732
|
-
// the card will be invisible by default.
|
|
733
|
-
this.refetchSSRPreview(identifier);
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
// we add a listener for each of the cards on the page
|
|
737
|
-
// and then check if the triggered listener is from the card
|
|
738
|
-
// that contains a div in current window.getSelection()
|
|
739
|
-
// won't work in IE11
|
|
740
|
-
(_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.addEventListener('copy', this.fireCopiedEvent);
|
|
741
|
-
}
|
|
742
|
-
componentDidUpdate(prevProps, prevState) {
|
|
743
|
-
var _this$ssrData4;
|
|
744
|
-
const {
|
|
745
|
-
mediaClient: prevMediaClient,
|
|
746
|
-
identifier: prevIdentifier,
|
|
747
|
-
dimensions: prevDimensions
|
|
748
|
-
} = prevProps;
|
|
749
|
-
const {
|
|
750
|
-
isCardVisible: prevIsCardVisible,
|
|
751
|
-
cardPreview: prevCardPreview
|
|
752
|
-
} = prevState;
|
|
753
|
-
const {
|
|
754
|
-
mediaClient,
|
|
755
|
-
identifier,
|
|
756
|
-
dimensions,
|
|
757
|
-
useInlinePlayer,
|
|
758
|
-
disableOverlay,
|
|
759
|
-
ssr
|
|
760
|
-
} = this.props;
|
|
761
|
-
const {
|
|
762
|
-
isCardVisible,
|
|
763
|
-
cardPreview,
|
|
764
|
-
status,
|
|
765
|
-
fileState,
|
|
766
|
-
isBannedLocalPreview,
|
|
767
|
-
previewDidRender,
|
|
768
|
-
isPlayingFile,
|
|
769
|
-
wasResolvedUpfrontPreview
|
|
770
|
-
} = this.state;
|
|
771
|
-
const isDiffIdentifier = isDifferentIdentifier(prevIdentifier, identifier);
|
|
772
|
-
/**
|
|
773
|
-
* Variable turnedVisible should only be true when media card
|
|
774
|
-
* was invisible in the previous state and is visible in the current one
|
|
775
|
-
*
|
|
776
|
-
* prevIsCardVisible | isCardVisible | turnedVisible
|
|
777
|
-
* ----------------------------------------------------
|
|
778
|
-
* false | false | false
|
|
779
|
-
* false | true | true
|
|
780
|
-
* true | true | false
|
|
781
|
-
* true | false | false (unreachable case)
|
|
782
|
-
* ----------------------------------------------------
|
|
783
|
-
*/
|
|
784
|
-
const turnedVisible = !prevIsCardVisible && isCardVisible;
|
|
785
|
-
const hadSSRCardPreview = !!prevCardPreview && isSSRClientPreview(prevCardPreview) && !cardPreview;
|
|
786
|
-
const isNewMediaClient = prevMediaClient !== mediaClient;
|
|
787
|
-
this.updateFileStateFlag(fileState);
|
|
788
|
-
if (isExternalImageIdentifier(identifier) && isDiffIdentifier) {
|
|
789
|
-
this.fireCommencedEvent();
|
|
790
|
-
const {
|
|
791
|
-
dataURI
|
|
792
|
-
} = identifier;
|
|
793
|
-
this.setState({
|
|
794
|
-
status: 'loading-preview',
|
|
795
|
-
cardPreview: {
|
|
796
|
-
dataURI,
|
|
797
|
-
orientation: 1,
|
|
798
|
-
source: 'external'
|
|
799
|
-
},
|
|
800
|
-
isCardVisible: true
|
|
801
|
-
});
|
|
802
|
-
}
|
|
803
|
-
if (cardPreview && turnedVisible && isFileIdentifier(identifier) && isSSRDataPreview(cardPreview) && isBigger((_this$ssrData4 = this.ssrData) === null || _this$ssrData4 === void 0 ? void 0 : _this$ssrData4.dimensions, dimensions)) {
|
|
804
|
-
// If dimensions from Server have changed and are bigger,
|
|
805
|
-
// we need to refetch
|
|
806
|
-
this.refetchSSRPreview(identifier);
|
|
807
|
-
}
|
|
808
|
-
if (isFileIdentifier(identifier) && (turnedVisible || !!this.subscription && (isNewMediaClient || isDiffIdentifier))) {
|
|
809
|
-
this.updateStateForIdentifier(identifier);
|
|
810
|
-
}
|
|
811
|
-
if (this.state.status !== prevState.status) {
|
|
812
|
-
this.fireOperationalEvent();
|
|
813
|
-
if (this.state.status === 'complete' || this.fileAttributes.fileMediatype === 'video' && !!cardPreview && this.state.status === 'processing') {
|
|
814
|
-
this.fireScreenEvent();
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
if (isFileIdentifier(identifier) && (turnedVisible || ssr === 'client' && hadSSRCardPreview) && !cardPreview && !wasResolvedUpfrontPreview) {
|
|
818
|
-
// This is a one-off call, only meant to happen once in the component's lifecycle. Mainly when either:
|
|
819
|
-
// - turnedVisible = true
|
|
820
|
-
// - ssr = client and has no preview (the dataURI failed to load in the previous state, most likely because of an initial auth issue)
|
|
821
|
-
this.resolveUpfrontPreview(identifier);
|
|
822
|
-
} else if (isFileIdentifier(identifier) && fileState && shouldResolvePreview({
|
|
823
|
-
status,
|
|
824
|
-
fileState,
|
|
825
|
-
prevDimensions,
|
|
826
|
-
dimensions,
|
|
827
|
-
hasCardPreview: !!cardPreview,
|
|
828
|
-
isBannedLocalPreview,
|
|
829
|
-
wasResolvedUpfrontPreview
|
|
830
|
-
})) {
|
|
831
|
-
this.resolvePreview(identifier, fileState);
|
|
832
|
-
}
|
|
833
|
-
if (turnedVisible && this.props.ssr && !!cardPreview && isSSRClientPreview(cardPreview) && isFileIdentifier(identifier)) {
|
|
834
|
-
// Since the SSR preview brings the token in the query params,
|
|
835
|
-
// We need to fetch the remote preview to be able to cache it,
|
|
836
|
-
this.setCacheSSRPreview(identifier);
|
|
837
|
-
}
|
|
838
|
-
if (previewDidRender &&
|
|
839
|
-
// We should't complete if status is uploading
|
|
840
|
-
['loading-preview', 'processing'].includes(status)) {
|
|
841
|
-
this.safeSetState({
|
|
842
|
-
status: 'complete'
|
|
843
|
-
});
|
|
844
|
-
this.unsubscribe();
|
|
845
|
-
}
|
|
846
|
-
const isVideo = this.fileAttributes.fileMediatype === 'video';
|
|
847
|
-
const {
|
|
848
|
-
mimeType
|
|
849
|
-
} = getFileDetails(identifier, fileState);
|
|
850
|
-
const isVideoPlayable = videoIsPlayable(isBannedLocalPreview, fileState, mimeType);
|
|
851
|
-
if (isVideo && !isPlayingFile && disableOverlay && useInlinePlayer && isVideoPlayable && status !== 'error') {
|
|
852
|
-
this.setState({
|
|
853
|
-
isPlayingFile: true
|
|
854
|
-
});
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
componentWillUnmount() {
|
|
858
|
-
var _getDocument2;
|
|
859
|
-
this.fireAbortedEvent();
|
|
860
|
-
this.hasBeenMounted = false;
|
|
861
|
-
this.unsubscribe();
|
|
862
|
-
(_getDocument2 = getDocument()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.removeEventListener('copy', this.fireCopiedEvent);
|
|
863
|
-
}
|
|
864
|
-
updateStateForIdentifier(identifier) {
|
|
865
|
-
this.fireCommencedEvent();
|
|
866
|
-
this.subscribeInternalFile(identifier);
|
|
867
|
-
}
|
|
868
|
-
updateFileStateFlag(fileState) {
|
|
869
|
-
if (!fileState) {
|
|
870
|
-
return;
|
|
871
|
-
}
|
|
872
|
-
const {
|
|
873
|
-
status
|
|
874
|
-
} = fileState;
|
|
875
|
-
if (status === 'processing') {
|
|
876
|
-
this.fileStateFlags.wasStatusProcessing = true;
|
|
877
|
-
} else if (status === 'uploading') {
|
|
878
|
-
this.fileStateFlags.wasStatusUploading = true;
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
subscribeInternalFile(identifier) {
|
|
882
|
-
const {
|
|
883
|
-
mediaClient
|
|
884
|
-
} = this.props;
|
|
885
|
-
const {
|
|
886
|
-
isBannedLocalPreview
|
|
887
|
-
} = this.state;
|
|
888
|
-
const {
|
|
889
|
-
id,
|
|
890
|
-
collectionName,
|
|
891
|
-
occurrenceKey
|
|
892
|
-
} = identifier;
|
|
893
|
-
this.unsubscribe();
|
|
894
|
-
this.subscription = mediaClient.file.getFileState(id, {
|
|
895
|
-
collectionName,
|
|
896
|
-
occurrenceKey
|
|
897
|
-
}).subscribe({
|
|
898
|
-
next: fileState => {
|
|
899
|
-
const newState = getCardStateFromFileState(fileState, isBannedLocalPreview);
|
|
900
|
-
this.safeSetState(newState);
|
|
901
|
-
},
|
|
902
|
-
error: e => {
|
|
903
|
-
const errorReason = this.state.status === 'uploading' ? 'upload' : 'metadata-fetch';
|
|
904
|
-
const error = new MediaCardError(errorReason, e);
|
|
905
|
-
this.safeSetState({
|
|
906
|
-
error,
|
|
907
|
-
status: 'error'
|
|
908
|
-
});
|
|
909
|
-
}
|
|
910
|
-
});
|
|
911
|
-
}
|
|
912
|
-
get requestedDimensions() {
|
|
913
|
-
const {
|
|
914
|
-
dimensions
|
|
915
|
-
} = this.props;
|
|
916
|
-
const {
|
|
917
|
-
cardRef: element
|
|
918
|
-
} = this.state || {};
|
|
919
|
-
return getRequestedDimensions({
|
|
920
|
-
dimensions,
|
|
921
|
-
element
|
|
922
|
-
});
|
|
923
|
-
}
|
|
924
|
-
get metadata() {
|
|
925
|
-
var _this$state;
|
|
926
|
-
return getFileDetails(this.props.identifier, (_this$state = this.state) === null || _this$state === void 0 ? void 0 : _this$state.fileState);
|
|
927
|
-
}
|
|
928
|
-
get fileAttributes() {
|
|
929
|
-
var _this$state2, _this$state2$fileStat;
|
|
930
|
-
return getFileAttributes(this.metadata, (_this$state2 = this.state) === null || _this$state2 === void 0 ? void 0 : (_this$state2$fileStat = _this$state2.fileState) === null || _this$state2$fileStat === void 0 ? void 0 : _this$state2$fileStat.status);
|
|
931
|
-
}
|
|
932
|
-
fireOperationalEvent() {
|
|
933
|
-
const {
|
|
934
|
-
status,
|
|
935
|
-
error,
|
|
936
|
-
fileState
|
|
937
|
-
} = this.state;
|
|
938
|
-
const {
|
|
939
|
-
createAnalyticsEvent
|
|
940
|
-
} = this.props;
|
|
941
|
-
createAnalyticsEvent && fireOperationalEvent(createAnalyticsEvent, status, this.fileAttributes, this.getPerformanceAttributes(), this.ssrReliability, error, this.traceContext, fileState === null || fileState === void 0 ? void 0 : fileState.metadataTraceContext);
|
|
942
|
-
completeUfoExperience(this.internalOccurrenceKey, status, this.fileAttributes, this.fileStateFlags, this.ssrReliability, error);
|
|
943
|
-
}
|
|
944
|
-
fireAbortedEvent() {
|
|
945
|
-
const {
|
|
946
|
-
fileAttributes,
|
|
947
|
-
fileStateFlags,
|
|
948
|
-
ssrReliability
|
|
949
|
-
} = this;
|
|
950
|
-
// UFO won't abort if it's already in a final state (succeeded, failed, aborted, etc)
|
|
951
|
-
abortUfoExperience(this.internalOccurrenceKey, {
|
|
952
|
-
fileAttributes,
|
|
953
|
-
fileStateFlags,
|
|
954
|
-
ssrReliability
|
|
955
|
-
});
|
|
956
|
-
}
|
|
957
|
-
fireCommencedEvent() {
|
|
958
|
-
this.timeElapsedTillCommenced = performance.now();
|
|
959
|
-
const {
|
|
960
|
-
createAnalyticsEvent
|
|
961
|
-
} = this.props;
|
|
962
|
-
createAnalyticsEvent && fireCommencedEvent(createAnalyticsEvent, this.fileAttributes, {
|
|
963
|
-
overall: {
|
|
964
|
-
durationSincePageStart: this.timeElapsedTillCommenced
|
|
965
|
-
}
|
|
966
|
-
}, this.traceContext);
|
|
967
|
-
startUfoExperience(this.internalOccurrenceKey);
|
|
968
|
-
}
|
|
969
|
-
get actions() {
|
|
970
|
-
const {
|
|
971
|
-
actions = [],
|
|
972
|
-
identifier,
|
|
973
|
-
shouldEnableDownloadButton
|
|
974
|
-
} = this.props;
|
|
975
|
-
const {
|
|
976
|
-
status
|
|
977
|
-
} = this.state;
|
|
978
|
-
const {
|
|
979
|
-
metadata
|
|
980
|
-
} = this;
|
|
981
|
-
if (isFileIdentifier(identifier) && (status === 'failed-processing' || shouldEnableDownloadButton)) {
|
|
982
|
-
const downloadAction = {
|
|
983
|
-
label: 'Download',
|
|
984
|
-
icon: /*#__PURE__*/React.createElement(DownloadIcon, {
|
|
985
|
-
label: "Download"
|
|
986
|
-
}),
|
|
987
|
-
handler: () => this.props.mediaClient.file.downloadBinary(identifier.id, metadata.name, identifier.collectionName)
|
|
988
|
-
};
|
|
989
|
-
return [downloadAction, ...actions];
|
|
990
|
-
} else {
|
|
991
|
-
return actions;
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
render() {
|
|
995
|
-
const {
|
|
996
|
-
isPlayingFile,
|
|
997
|
-
mediaViewerSelectedItem
|
|
998
|
-
} = this.state;
|
|
999
|
-
const innerContent = /*#__PURE__*/React.createElement(React.Fragment, null, isPlayingFile ? this.renderInlinePlayer() : this.renderCard(), mediaViewerSelectedItem ? this.renderMediaViewer() : null, this.storeSSRData());
|
|
1000
|
-
return this.props.intl ? innerContent : /*#__PURE__*/React.createElement(IntlProvider, {
|
|
1001
|
-
locale: "en"
|
|
1002
|
-
}, innerContent);
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
// We require this wrapper in order
|
|
1007
|
-
// 1. To refresh media card state when the identifier is updated
|
|
1008
|
-
// 2. To allow for overriding creation date (https://product-fabric.atlassian.net/browse/CXP-2840)
|
|
1009
|
-
_defineProperty(CardBase, "defaultProps", {
|
|
1010
|
-
appearance: 'auto',
|
|
1011
|
-
resizeMode: 'crop',
|
|
1012
|
-
isLazy: true,
|
|
1013
|
-
disableOverlay: false,
|
|
1014
|
-
// Media Feature Flag defaults are defined in @atlaskit/media-common
|
|
1015
|
-
featureFlags: {}
|
|
1016
|
-
});
|
|
1017
|
-
const CardWithKeyAndDateOverrideContext = props => {
|
|
1018
|
-
const {
|
|
1019
|
-
identifier
|
|
1020
|
-
} = props;
|
|
1021
|
-
const dateOverrides = useContext(DateOverrideContext);
|
|
1022
|
-
const key = isFileIdentifier(identifier) ? identifier.id : identifier.dataURI;
|
|
1023
|
-
const dateOverride = isFileIdentifier(identifier) ? dateOverrides === null || dateOverrides === void 0 ? void 0 : dateOverrides[identifier.id] : undefined;
|
|
1024
|
-
return /*#__PURE__*/React.createElement(CardBase, _extends({}, props, {
|
|
1025
|
-
dateOverride: dateOverride,
|
|
1026
|
-
key: key
|
|
10
|
+
const packageVersion = "78.0.0";
|
|
11
|
+
export const CardBase = ({
|
|
12
|
+
identifier,
|
|
13
|
+
...otherProps
|
|
14
|
+
}) => {
|
|
15
|
+
const innerContent = isFileIdentifier(identifier) ? /*#__PURE__*/React.createElement(FileCard, _extends({}, otherProps, {
|
|
16
|
+
identifier: identifier,
|
|
17
|
+
key: identifier.id
|
|
18
|
+
})) : /*#__PURE__*/React.createElement(ExternalImageCard, _extends({}, otherProps, {
|
|
19
|
+
identifier: identifier,
|
|
20
|
+
key: identifier.dataURI
|
|
1027
21
|
}));
|
|
22
|
+
return otherProps.intl ? innerContent : /*#__PURE__*/React.createElement(IntlProvider, {
|
|
23
|
+
locale: "en"
|
|
24
|
+
}, innerContent);
|
|
1028
25
|
};
|
|
1029
26
|
export const Card = withMediaAnalyticsContext({
|
|
1030
27
|
packageVersion,
|
|
1031
28
|
packageName,
|
|
1032
29
|
componentName: 'mediaCard',
|
|
1033
30
|
component: 'mediaCard'
|
|
1034
|
-
})(withAnalyticsEvents()(injectIntl(
|
|
31
|
+
})(withAnalyticsEvents()(injectIntl(CardBase, {
|
|
1035
32
|
enforceContext: false
|
|
1036
33
|
})));
|