@atlaskit/media-card 73.1.1 → 73.2.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 +19 -0
- package/dist/cjs/files/cardImageView/index.js +51 -41
- package/dist/cjs/root/card/getCardPreview/index.js +7 -1
- package/dist/cjs/root/card/index.js +247 -151
- package/dist/cjs/root/cardView.js +127 -115
- package/dist/cjs/root/inlinePlayer.js +4 -2
- package/dist/cjs/root/ui/imageRenderer/imageRenderer.js +14 -6
- package/dist/cjs/root/ui/styled.js +5 -5
- package/dist/cjs/types.js +10 -1
- package/dist/cjs/utils/analytics.js +23 -7
- 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/getCardPreview/index.js +1 -0
- package/dist/es2019/root/card/index.js +107 -35
- package/dist/es2019/root/cardView.js +40 -30
- package/dist/es2019/root/inlinePlayer.js +4 -2
- package/dist/es2019/root/ui/imageRenderer/imageRenderer.js +14 -6
- package/dist/es2019/root/ui/styled.js +4 -4
- package/dist/es2019/types.js +7 -1
- package/dist/es2019/utils/analytics.js +8 -3
- 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/getCardPreview/index.js +3 -0
- package/dist/esm/root/card/index.js +228 -134
- package/dist/esm/root/cardView.js +126 -115
- package/dist/esm/root/inlinePlayer.js +4 -2
- package/dist/esm/root/ui/imageRenderer/imageRenderer.js +14 -6
- package/dist/esm/root/ui/styled.js +5 -5
- package/dist/esm/types.js +7 -1
- package/dist/esm/utils/analytics.js +17 -6
- 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/errors.d.ts +1 -1
- package/dist/types/files/cardImageView/index.d.ts +6 -2
- package/dist/types/root/card/getCardPreview/index.d.ts +1 -0
- package/dist/types/root/card/index.d.ts +3 -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 +4 -4
- 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 +6 -0
- 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 +5 -5
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSSRData = void 0;
|
|
7
|
+
|
|
8
|
+
var _globalScope = require("./globalScope");
|
|
9
|
+
|
|
10
|
+
var getSSRData = function getSSRData(identifier) {
|
|
11
|
+
var mediaCardSsr = (0, _globalScope.getMediaCardSSR)();
|
|
12
|
+
|
|
13
|
+
if (!mediaCardSsr) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return mediaCardSsr[(0, _globalScope.getKey)(identifier)];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.getSSRData = getSSRData;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.getKey = exports.StoreSSRDataScript = exports.GLOBAL_MEDIA_NAMESPACE = exports.GLOBAL_MEDIA_CARD_SSR = void 0;
|
|
9
|
+
exports.getMediaCardSSR = getMediaCardSSR;
|
|
10
|
+
exports.getMediaGlobalScope = getMediaGlobalScope;
|
|
11
|
+
exports.storeDataURI = void 0;
|
|
12
|
+
|
|
13
|
+
var _react = _interopRequireDefault(require("react"));
|
|
14
|
+
|
|
15
|
+
var _printScript = require("../printScript");
|
|
16
|
+
|
|
17
|
+
// ----- WARNING -----
|
|
18
|
+
// This is a very sensitive fraction of code.
|
|
19
|
+
// Any changes to this file must be tested directly in product before merging.
|
|
20
|
+
// The scripts printed here might differ from what we observe in our internal tests
|
|
21
|
+
// due to minimification, for example.
|
|
22
|
+
var GLOBAL_MEDIA_CARD_SSR = 'mediaCardSsr';
|
|
23
|
+
exports.GLOBAL_MEDIA_CARD_SSR = GLOBAL_MEDIA_CARD_SSR;
|
|
24
|
+
var GLOBAL_MEDIA_NAMESPACE = '__MEDIA_INTERNAL';
|
|
25
|
+
exports.GLOBAL_MEDIA_NAMESPACE = GLOBAL_MEDIA_NAMESPACE;
|
|
26
|
+
|
|
27
|
+
function getMediaGlobalScope() {
|
|
28
|
+
var globalScope = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
|
|
29
|
+
// Must match GLOBAL_MEDIA_NAMESPACE. Can't reference the constant from here.
|
|
30
|
+
var namespace = '__MEDIA_INTERNAL';
|
|
31
|
+
|
|
32
|
+
if (!globalScope[namespace]) {
|
|
33
|
+
globalScope[namespace] = {};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return globalScope[namespace];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getMediaCardSSR() {
|
|
40
|
+
var globalScope = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
|
|
41
|
+
var globalMedia = getMediaGlobalScope(globalScope); // Must match GLOBAL_MEDIA_CARD_SSR. Can't reference the constant from here.
|
|
42
|
+
|
|
43
|
+
var key = 'mediaCardSsr';
|
|
44
|
+
|
|
45
|
+
if (!globalMedia[key]) {
|
|
46
|
+
globalMedia[key] = {};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return globalMedia[key];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
var dashed = function dashed(param) {
|
|
53
|
+
return param ? "-".concat(param) : '';
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
var getKey = function getKey(_ref) {
|
|
57
|
+
var id = _ref.id,
|
|
58
|
+
collectionName = _ref.collectionName,
|
|
59
|
+
occurrenceKey = _ref.occurrenceKey;
|
|
60
|
+
return "".concat(id).concat(dashed(collectionName)).concat(dashed(occurrenceKey));
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
exports.getKey = getKey;
|
|
64
|
+
|
|
65
|
+
var storeDataURI = function storeDataURI(key, dataURI, dimensions, error) {
|
|
66
|
+
var globalScope = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : window;
|
|
67
|
+
var mediaCardSsr = getMediaCardSSR(globalScope);
|
|
68
|
+
mediaCardSsr[key] = {
|
|
69
|
+
dataURI: dataURI,
|
|
70
|
+
dimensions: dimensions,
|
|
71
|
+
error: error
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
exports.storeDataURI = storeDataURI;
|
|
76
|
+
|
|
77
|
+
var generateScript = function generateScript(identifier, dataURI, dimensions, error) {
|
|
78
|
+
var functionCall = (0, _printScript.printFunctionCall)(storeDataURI, getKey(identifier), dataURI, dimensions, error);
|
|
79
|
+
return (0, _printScript.printScript)([getMediaCardSSR.toString(), getMediaGlobalScope.toString(), functionCall]);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
var StoreSSRDataScript = function StoreSSRDataScript(_ref2) {
|
|
83
|
+
var dataURI = _ref2.dataURI,
|
|
84
|
+
identifier = _ref2.identifier,
|
|
85
|
+
dimensions = _ref2.dimensions,
|
|
86
|
+
error = _ref2.error;
|
|
87
|
+
return /*#__PURE__*/_react.default.createElement("script", {
|
|
88
|
+
dangerouslySetInnerHTML: {
|
|
89
|
+
__html: generateScript(identifier, dataURI, dimensions, error)
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
exports.StoreSSRDataScript = StoreSSRDataScript;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "GLOBAL_MEDIA_CARD_SSR", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _globalScope.GLOBAL_MEDIA_CARD_SSR;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "GLOBAL_MEDIA_NAMESPACE", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _globalScope.GLOBAL_MEDIA_NAMESPACE;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "StoreSSRDataScript", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _globalScope.StoreSSRDataScript;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "getKey", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _globalScope.getKey;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "getSSRData", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function get() {
|
|
33
|
+
return _getSSRData.getSSRData;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
var _globalScope = require("./globalScope");
|
|
38
|
+
|
|
39
|
+
var _getSSRData = require("./getSSRData");
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.printScript = exports.printFunctionCall = void 0;
|
|
9
|
+
|
|
10
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
+
|
|
12
|
+
var printParam = function printParam(param) {
|
|
13
|
+
if (typeof param === 'string') {
|
|
14
|
+
return "'".concat(param, "'");
|
|
15
|
+
} else if ((0, _typeof2.default)(param) === 'object') {
|
|
16
|
+
return JSON.stringify(param);
|
|
17
|
+
} else if (param === undefined) {
|
|
18
|
+
return 'undefined';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return param;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var printParams = function printParams(args) {
|
|
25
|
+
return args.map(function (arg) {
|
|
26
|
+
return printParam(arg);
|
|
27
|
+
}).join(',');
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var printFunctionCall = function printFunctionCall(fn) {
|
|
31
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
32
|
+
args[_key - 1] = arguments[_key];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return "(".concat(fn.toString(), ")(").concat(printParams(args), ");");
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.printFunctionCall = printFunctionCall;
|
|
39
|
+
|
|
40
|
+
var printScript = function printScript(statements) {
|
|
41
|
+
return "(function(){\n ".concat(statements.join(';'), "\n})();\n");
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.printScript = printScript;
|
package/dist/cjs/version.json
CHANGED
|
@@ -138,6 +138,22 @@ export class FileCardImageView extends Component {
|
|
|
138
138
|
})));
|
|
139
139
|
});
|
|
140
140
|
|
|
141
|
+
_defineProperty(this, "onImageLoad", () => {
|
|
142
|
+
const {
|
|
143
|
+
onImageLoad,
|
|
144
|
+
cardPreview
|
|
145
|
+
} = this.props;
|
|
146
|
+
onImageLoad && onImageLoad(cardPreview);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
_defineProperty(this, "onImageError", () => {
|
|
150
|
+
const {
|
|
151
|
+
onImageError,
|
|
152
|
+
cardPreview
|
|
153
|
+
} = this.props;
|
|
154
|
+
onImageError && onImageError(cardPreview);
|
|
155
|
+
});
|
|
156
|
+
|
|
141
157
|
_defineProperty(this, "renderMediaImage", () => {
|
|
142
158
|
const {
|
|
143
159
|
status,
|
|
@@ -147,9 +163,7 @@ export class FileCardImageView extends Component {
|
|
|
147
163
|
mimeType,
|
|
148
164
|
previewOrientation,
|
|
149
165
|
onDisplayImage,
|
|
150
|
-
alt
|
|
151
|
-
onImageLoad,
|
|
152
|
-
onImageError
|
|
166
|
+
alt
|
|
153
167
|
} = this.props;
|
|
154
168
|
|
|
155
169
|
if (!shouldDisplayImageThumbnail(status, mediaItemType, dataURI, mediaType, mimeType)) {
|
|
@@ -167,8 +181,8 @@ export class FileCardImageView extends Component {
|
|
|
167
181
|
crop: this.isCropped,
|
|
168
182
|
stretch: this.isStretched,
|
|
169
183
|
previewOrientation: previewOrientation,
|
|
170
|
-
onImageLoad: onImageLoad,
|
|
171
|
-
onImageError: onImageError
|
|
184
|
+
onImageLoad: this.onImageLoad,
|
|
185
|
+
onImageError: this.onImageError
|
|
172
186
|
});
|
|
173
187
|
});
|
|
174
188
|
|
|
@@ -165,6 +165,7 @@ export const isSSRClientPreview = preview => {
|
|
|
165
165
|
const ssrClientSources = ['ssr-client', 'cache-ssr-client'];
|
|
166
166
|
return ssrClientSources.includes(preview.source);
|
|
167
167
|
};
|
|
168
|
+
export const isSSRDataPreview = preview => preview.source === 'ssr-data';
|
|
168
169
|
export const fetchAndCacheRemotePreview = async (mediaClient, id, dimensions, params, mediaBlobUrlAttrs) => {
|
|
169
170
|
const remotePreview = await getCardPreviewFromBackend(mediaClient, id, params);
|
|
170
171
|
return extendAndCachePreview(id, dimensions, remotePreview, mediaBlobUrlAttrs);
|
|
@@ -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.
|
|
@@ -106,15 +109,19 @@ export class CardBase extends Component {
|
|
|
106
109
|
});
|
|
107
110
|
});
|
|
108
111
|
|
|
109
|
-
_defineProperty(this, "
|
|
112
|
+
_defineProperty(this, "refetchSSRPreview", async identifier => {
|
|
110
113
|
const {
|
|
111
|
-
mediaClient
|
|
114
|
+
mediaClient,
|
|
115
|
+
dimensions = {}
|
|
112
116
|
} = this.props;
|
|
113
117
|
|
|
114
118
|
try {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
119
|
+
const cardPreview = await fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions, this.getImageURLParams(identifier), this.getMediaBlobUrlAttrs(identifier));
|
|
120
|
+
this.safeSetState({
|
|
121
|
+
cardPreview
|
|
122
|
+
});
|
|
123
|
+
} catch (e) {// No need to log this error.
|
|
124
|
+
// If preview fails, it will be refetched later
|
|
118
125
|
}
|
|
119
126
|
});
|
|
120
127
|
|
|
@@ -158,13 +165,18 @@ export class CardBase extends Component {
|
|
|
158
165
|
};
|
|
159
166
|
});
|
|
160
167
|
|
|
161
|
-
_defineProperty(this, "onImageError",
|
|
168
|
+
_defineProperty(this, "onImageError", cardPreview => {
|
|
162
169
|
const {
|
|
163
|
-
cardPreview
|
|
164
|
-
} = this.state;
|
|
170
|
+
cardPreview: currentPreview
|
|
171
|
+
} = this.state; // If the dataURI has been replaced, we can dismiss this error
|
|
172
|
+
|
|
173
|
+
if ((cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI) !== (currentPreview === null || currentPreview === void 0 ? void 0 : currentPreview.dataURI)) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
165
177
|
const error = new ImageLoadError(cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.source);
|
|
166
178
|
const isLocal = cardPreview && isLocalPreview(cardPreview);
|
|
167
|
-
const isSSR = cardPreview && isSSRClientPreview(cardPreview);
|
|
179
|
+
const isSSR = cardPreview && (isSSRClientPreview(cardPreview) || isSSRDataPreview(cardPreview));
|
|
168
180
|
|
|
169
181
|
if (isLocal || isSSR) {
|
|
170
182
|
const updateState = {
|
|
@@ -194,7 +206,15 @@ export class CardBase extends Component {
|
|
|
194
206
|
}
|
|
195
207
|
});
|
|
196
208
|
|
|
197
|
-
_defineProperty(this, "onImageLoad",
|
|
209
|
+
_defineProperty(this, "onImageLoad", cardPreview => {
|
|
210
|
+
const {
|
|
211
|
+
cardPreview: currentPreview
|
|
212
|
+
} = this.state; // If the dataURI has been replaced, we can dismiss this callback
|
|
213
|
+
|
|
214
|
+
if ((cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI) !== (currentPreview === null || currentPreview === void 0 ? void 0 : currentPreview.dataURI)) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
198
218
|
this.safeSetState({
|
|
199
219
|
previewDidRender: true
|
|
200
220
|
});
|
|
@@ -315,7 +335,8 @@ export class CardBase extends Component {
|
|
|
315
335
|
originalDimensions
|
|
316
336
|
} = this.props;
|
|
317
337
|
const {
|
|
318
|
-
shouldAutoplay
|
|
338
|
+
shouldAutoplay,
|
|
339
|
+
cardPreview
|
|
319
340
|
} = this.state;
|
|
320
341
|
return /*#__PURE__*/React.createElement(InlinePlayer, {
|
|
321
342
|
mediaClient: mediaClient,
|
|
@@ -327,7 +348,8 @@ export class CardBase extends Component {
|
|
|
327
348
|
onClick: this.onClick,
|
|
328
349
|
selected: selected,
|
|
329
350
|
ref: this.setRef,
|
|
330
|
-
testId: testId
|
|
351
|
+
testId: testId,
|
|
352
|
+
cardPreview: cardPreview
|
|
331
353
|
});
|
|
332
354
|
});
|
|
333
355
|
|
|
@@ -407,7 +429,9 @@ export class CardBase extends Component {
|
|
|
407
429
|
featureFlags,
|
|
408
430
|
titleBoxBgColor,
|
|
409
431
|
titleBoxIcon,
|
|
410
|
-
ssr
|
|
432
|
+
ssr,
|
|
433
|
+
useInlinePlayer,
|
|
434
|
+
shouldOpenMediaViewer
|
|
411
435
|
} = this.props;
|
|
412
436
|
const {
|
|
413
437
|
mediaItemType
|
|
@@ -415,13 +439,7 @@ export class CardBase extends Component {
|
|
|
415
439
|
const {
|
|
416
440
|
status,
|
|
417
441
|
progress,
|
|
418
|
-
cardPreview
|
|
419
|
-
dataURI,
|
|
420
|
-
orientation
|
|
421
|
-
} = {
|
|
422
|
-
dataURI: undefined,
|
|
423
|
-
orientation: 1
|
|
424
|
-
},
|
|
442
|
+
cardPreview,
|
|
425
443
|
error,
|
|
426
444
|
cardRef,
|
|
427
445
|
isCardVisible
|
|
@@ -440,12 +458,13 @@ export class CardBase extends Component {
|
|
|
440
458
|
const nativeLazyLoad = isLazy && !isCardVisible; // Force Media Image to always display img for SSR
|
|
441
459
|
|
|
442
460
|
const forceSyncDisplay = !!ssr;
|
|
461
|
+
const mediaCardCursor = getMediaCardCursor(!!useInlinePlayer, !!shouldOpenMediaViewer, status === 'error' || status === 'failed-processing', !!this.state.cardPreview, metadata.mediaType);
|
|
443
462
|
const card = /*#__PURE__*/React.createElement(CardView, {
|
|
444
463
|
status: status,
|
|
445
464
|
error: error,
|
|
446
465
|
mediaItemType: mediaItemType,
|
|
447
466
|
metadata: metadata,
|
|
448
|
-
|
|
467
|
+
cardPreview: cardPreview,
|
|
449
468
|
alt: alt,
|
|
450
469
|
appearance: appearance,
|
|
451
470
|
resizeMode: resizeMode,
|
|
@@ -458,7 +477,6 @@ export class CardBase extends Component {
|
|
|
458
477
|
disableOverlay: disableOverlay,
|
|
459
478
|
progress: progress,
|
|
460
479
|
onDisplayImage: onDisplayImage,
|
|
461
|
-
previewOrientation: orientation,
|
|
462
480
|
innerRef: this.setRef,
|
|
463
481
|
testId: testId,
|
|
464
482
|
featureFlags: featureFlags,
|
|
@@ -467,7 +485,8 @@ export class CardBase extends Component {
|
|
|
467
485
|
onImageError: this.onImageError,
|
|
468
486
|
onImageLoad: this.onImageLoad,
|
|
469
487
|
nativeLazyLoad: nativeLazyLoad,
|
|
470
|
-
forceSyncDisplay: forceSyncDisplay
|
|
488
|
+
forceSyncDisplay: forceSyncDisplay,
|
|
489
|
+
mediaCardCursor: mediaCardCursor
|
|
471
490
|
});
|
|
472
491
|
return isLazy ? /*#__PURE__*/React.createElement(ViewportDetector, {
|
|
473
492
|
cardEl: cardRef,
|
|
@@ -483,6 +502,26 @@ export class CardBase extends Component {
|
|
|
483
502
|
})) : card;
|
|
484
503
|
});
|
|
485
504
|
|
|
505
|
+
_defineProperty(this, "storeSSRData", () => {
|
|
506
|
+
const {
|
|
507
|
+
ssr,
|
|
508
|
+
identifier
|
|
509
|
+
} = this.props;
|
|
510
|
+
const {
|
|
511
|
+
cardPreview: {
|
|
512
|
+
dataURI
|
|
513
|
+
} = {},
|
|
514
|
+
error
|
|
515
|
+
} = this.state;
|
|
516
|
+
const ssrDataError = !!error ? extractErrorInfo(error) : undefined;
|
|
517
|
+
return isFileIdentifier(identifier) && ssr === 'server' && /*#__PURE__*/React.createElement(StoreSSRDataScript, {
|
|
518
|
+
identifier: identifier,
|
|
519
|
+
dataURI: dataURI,
|
|
520
|
+
dimensions: this.requestedDimensions,
|
|
521
|
+
error: ssrDataError
|
|
522
|
+
});
|
|
523
|
+
});
|
|
524
|
+
|
|
486
525
|
_defineProperty(this, "onCardInViewport", () => {
|
|
487
526
|
this.setState({
|
|
488
527
|
isCardVisible: true
|
|
@@ -527,10 +566,13 @@ export class CardBase extends Component {
|
|
|
527
566
|
|
|
528
567
|
let _cardPreview;
|
|
529
568
|
|
|
569
|
+
let _error;
|
|
570
|
+
|
|
530
571
|
const {
|
|
531
572
|
identifier: _identifier,
|
|
532
573
|
dimensions: _dimensions = {},
|
|
533
|
-
ssr: _ssr
|
|
574
|
+
ssr: _ssr,
|
|
575
|
+
mediaClient: _mediaClient
|
|
534
576
|
} = this.props;
|
|
535
577
|
|
|
536
578
|
if (isFileIdentifier(_identifier)) {
|
|
@@ -540,8 +582,26 @@ export class CardBase extends Component {
|
|
|
540
582
|
_cardPreview = getCardPreviewFromCache(id, _dimensions);
|
|
541
583
|
|
|
542
584
|
if (!_cardPreview && _ssr) {
|
|
543
|
-
|
|
544
|
-
|
|
585
|
+
var _this$ssrData;
|
|
586
|
+
|
|
587
|
+
this.ssrData = getSSRData(_identifier);
|
|
588
|
+
|
|
589
|
+
if (_ssr === 'server' || !((_this$ssrData = this.ssrData) !== null && _this$ssrData !== void 0 && _this$ssrData.dataURI)) {
|
|
590
|
+
try {
|
|
591
|
+
_cardPreview = getSSRCardPreview(_ssr, _mediaClient, _identifier.id, this.getImageURLParams(_identifier), this.getMediaBlobUrlAttrs(_identifier));
|
|
592
|
+
} catch (e) {
|
|
593
|
+
// TODO: handle error in client MEX-770
|
|
594
|
+
// If we fail building the dataURI in server, we store the error in the state
|
|
595
|
+
// to be later stored in global scope and logged in client.
|
|
596
|
+
// We don't set the status = error to fall back to the spinner icon
|
|
597
|
+
_error = _ssr === 'server' ? e : undefined;
|
|
598
|
+
}
|
|
599
|
+
} else {
|
|
600
|
+
_cardPreview = {
|
|
601
|
+
dataURI: this.ssrData.dataURI,
|
|
602
|
+
source: 'ssr-data'
|
|
603
|
+
};
|
|
604
|
+
}
|
|
545
605
|
}
|
|
546
606
|
} else if (isExternalImageIdentifier(_identifier)) {
|
|
547
607
|
this.fireCommencedEvent();
|
|
@@ -570,7 +630,8 @@ export class CardBase extends Component {
|
|
|
570
630
|
cardPreview: _cardPreview,
|
|
571
631
|
cardRef: null,
|
|
572
632
|
isBannedLocalPreview: false,
|
|
573
|
-
previewDidRender: false
|
|
633
|
+
previewDidRender: false,
|
|
634
|
+
error: _error
|
|
574
635
|
};
|
|
575
636
|
}
|
|
576
637
|
|
|
@@ -582,17 +643,28 @@ export class CardBase extends Component {
|
|
|
582
643
|
} = this.state;
|
|
583
644
|
const {
|
|
584
645
|
identifier,
|
|
585
|
-
ssr
|
|
646
|
+
ssr,
|
|
647
|
+
dimensions
|
|
586
648
|
} = this.props;
|
|
587
649
|
|
|
588
650
|
if (isCardVisible && isFileIdentifier(identifier)) {
|
|
589
651
|
this.updateStateForIdentifier(identifier);
|
|
590
652
|
}
|
|
591
653
|
|
|
592
|
-
if (isCardVisible && !!ssr && !!cardPreview &&
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
654
|
+
if (isCardVisible && !!ssr && !!cardPreview && isFileIdentifier(identifier)) {
|
|
655
|
+
var _this$ssrData2;
|
|
656
|
+
|
|
657
|
+
if (isSSRClientPreview(cardPreview)) {
|
|
658
|
+
// Since the SSR preview brings the token in the query params,
|
|
659
|
+
// We need to fetch the remote preview to be able to cache it,
|
|
660
|
+
this.setCacheSSRPreview(identifier);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
if (isSSRDataPreview(cardPreview) && isBigger((_this$ssrData2 = this.ssrData) === null || _this$ssrData2 === void 0 ? void 0 : _this$ssrData2.dimensions, dimensions)) {
|
|
664
|
+
// If dimensions from Server have changed and are bigger,
|
|
665
|
+
// we need to refetch
|
|
666
|
+
this.refetchSSRPreview(identifier);
|
|
667
|
+
}
|
|
596
668
|
} // we add a listener for each of the cards on the page
|
|
597
669
|
// and then check if the triggered listener is from the card
|
|
598
670
|
// that contains a div in current window.getSelection()
|
|
@@ -822,7 +894,7 @@ export class CardBase extends Component {
|
|
|
822
894
|
isPlayingFile,
|
|
823
895
|
mediaViewerSelectedItem
|
|
824
896
|
} = this.state;
|
|
825
|
-
const innerContent = /*#__PURE__*/React.createElement(React.Fragment, null, isPlayingFile ? this.renderInlinePlayer() : this.renderCard(), mediaViewerSelectedItem ? this.renderMediaViewer() : null);
|
|
897
|
+
const innerContent = /*#__PURE__*/React.createElement(React.Fragment, null, isPlayingFile ? this.renderInlinePlayer() : this.renderCard(), mediaViewerSelectedItem ? this.renderMediaViewer() : null, this.storeSSRData());
|
|
826
898
|
return this.props.intl ? innerContent : /*#__PURE__*/React.createElement(IntlProvider, {
|
|
827
899
|
locale: "en"
|
|
828
900
|
}, innerContent);
|