@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
|
@@ -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,21 +491,19 @@ 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
|
-
return !!
|
|
495
|
-
|
|
504
|
+
return !!cardPreview && /*#__PURE__*/React.createElement(ImageRenderer, {
|
|
505
|
+
cardPreview: cardPreview,
|
|
496
506
|
mediaType: mediaType,
|
|
497
|
-
previewOrientation: previewOrientation,
|
|
498
507
|
alt: alt,
|
|
499
508
|
resizeMode: resizeMode,
|
|
500
509
|
onDisplayImage: onDisplayImage,
|
|
@@ -554,7 +563,8 @@ export class CardViewBase extends React.Component {
|
|
|
554
563
|
}
|
|
555
564
|
|
|
556
565
|
_defineProperty(CardViewBase, "defaultProps", {
|
|
557
|
-
appearance: 'auto'
|
|
566
|
+
appearance: 'auto',
|
|
567
|
+
mediaCardCursor: MediaCardCursor.NoAction
|
|
558
568
|
});
|
|
559
569
|
|
|
560
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,
|
|
@@ -3,8 +3,7 @@ import React, { useEffect } from 'react';
|
|
|
3
3
|
import { MediaImage } from '@atlaskit/media-ui';
|
|
4
4
|
import { resizeModeToMediaImageProps } from '../../../utils/resizeModeToMediaImageProps';
|
|
5
5
|
export const ImageRenderer = ({
|
|
6
|
-
|
|
7
|
-
previewOrientation,
|
|
6
|
+
cardPreview,
|
|
8
7
|
alt,
|
|
9
8
|
resizeMode,
|
|
10
9
|
onImageLoad,
|
|
@@ -20,12 +19,21 @@ export const ImageRenderer = ({
|
|
|
20
19
|
onDisplayImage();
|
|
21
20
|
}
|
|
22
21
|
}, [mediaType, onDisplayImage]);
|
|
22
|
+
|
|
23
|
+
const onLoad = () => {
|
|
24
|
+
onImageLoad && onImageLoad(cardPreview);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const onError = () => {
|
|
28
|
+
onImageError && onImageError(cardPreview);
|
|
29
|
+
};
|
|
30
|
+
|
|
23
31
|
return /*#__PURE__*/React.createElement(MediaImage, _extends({
|
|
24
|
-
dataURI: dataURI,
|
|
32
|
+
dataURI: cardPreview.dataURI,
|
|
25
33
|
alt: alt,
|
|
26
|
-
previewOrientation:
|
|
27
|
-
onImageLoad:
|
|
28
|
-
onImageError:
|
|
34
|
+
previewOrientation: cardPreview.orientation,
|
|
35
|
+
onImageLoad: onLoad,
|
|
36
|
+
onImageError: onError,
|
|
29
37
|
loading: nativeLazyLoad ? 'lazy' : undefined,
|
|
30
38
|
forceSyncDisplay: forceSyncDisplay
|
|
31
39
|
}, resizeModeToMediaImageProps(resizeMode)));
|
|
@@ -52,7 +52,7 @@ const getWrapperShadow = (disableOverlay, selected) => {
|
|
|
52
52
|
return shadow ? `box-shadow: ${shadow};` : '';
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
const getCursorStyle =
|
|
55
|
+
const getCursorStyle = cursor => `cursor: ${cursor};`;
|
|
56
56
|
|
|
57
57
|
const getClickablePlayButtonStyles = isPlayButtonClickable => {
|
|
58
58
|
if (!isPlayButtonClickable) {
|
|
@@ -83,13 +83,13 @@ export const NewFileExperienceWrapper = styled.div`
|
|
|
83
83
|
breakpoint,
|
|
84
84
|
dimensions,
|
|
85
85
|
appearance,
|
|
86
|
-
shouldUsePointerCursor,
|
|
87
86
|
disableOverlay,
|
|
88
87
|
displayBackground,
|
|
89
88
|
selected,
|
|
90
89
|
isPlayButtonClickable,
|
|
91
90
|
isTickBoxSelectable,
|
|
92
|
-
shouldDisplayTooltip
|
|
91
|
+
shouldDisplayTooltip,
|
|
92
|
+
mediaCardCursor
|
|
93
93
|
}) => `
|
|
94
94
|
${transition()}
|
|
95
95
|
box-sizing: border-box;
|
|
@@ -101,7 +101,7 @@ export const NewFileExperienceWrapper = styled.div`
|
|
|
101
101
|
${getWrapperDimensions(dimensions, appearance)}
|
|
102
102
|
${displayBackground ? `background-color: ${N20};` : ''}
|
|
103
103
|
${borderRadius}
|
|
104
|
-
${getCursorStyle(
|
|
104
|
+
${getCursorStyle(mediaCardCursor)}
|
|
105
105
|
${getWrapperShadow(disableOverlay, selected)}
|
|
106
106
|
${generateResponsiveStyles(breakpoint)}
|
|
107
107
|
${hideNativeBrowserTextSelectionStyles}
|
package/dist/es2019/types.js
CHANGED
|
@@ -81,6 +81,13 @@ export const getRenderErrorRequestMetadata = error => {
|
|
|
81
81
|
return error.secondaryError.metadata;
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
|
+
export const extractErrorInfo = error => {
|
|
85
|
+
return {
|
|
86
|
+
failReason: getRenderErrorFailReason(error),
|
|
87
|
+
error: getRenderErrorErrorReason(error),
|
|
88
|
+
errorDetail: getRenderErrorErrorDetail(error)
|
|
89
|
+
};
|
|
90
|
+
};
|
|
84
91
|
export const getRenderErrorEventPayload = (fileAttributes, performanceAttributes, error) => ({
|
|
85
92
|
eventType: 'operational',
|
|
86
93
|
action: 'failed',
|
|
@@ -89,9 +96,7 @@ export const getRenderErrorEventPayload = (fileAttributes, performanceAttributes
|
|
|
89
96
|
fileAttributes,
|
|
90
97
|
performanceAttributes,
|
|
91
98
|
status: 'fail',
|
|
92
|
-
|
|
93
|
-
error: getRenderErrorErrorReason(error),
|
|
94
|
-
errorDetail: getRenderErrorErrorDetail(error),
|
|
99
|
+
...extractErrorInfo(error),
|
|
95
100
|
request: getRenderErrorRequestMetadata(error)
|
|
96
101
|
}
|
|
97
102
|
});
|
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
import { isValidPercentageUnit } from './isValidPercentageUnit';
|
|
2
2
|
import { containsPixelUnit } from './containsPixelUnit';
|
|
3
|
+
|
|
4
|
+
const isPixelEquivalent = dimension => typeof dimension === 'number' || containsPixelUnit(`${dimension}`);
|
|
5
|
+
|
|
3
6
|
export const canCompareDimension = (current, next) => {
|
|
4
7
|
if (!current || !next) {
|
|
5
8
|
return false;
|
|
6
9
|
}
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (containsPixelUnit(`${current}`) && containsPixelUnit(`${next}`)) {
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (typeof current === 'number' && typeof next === 'number') {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return false;
|
|
11
|
+
const bothPixelEquivalent = isPixelEquivalent(current) && isPixelEquivalent(next);
|
|
12
|
+
const bothPercentage = isValidPercentageUnit(current) && isValidPercentageUnit(next);
|
|
13
|
+
return bothPixelEquivalent || bothPercentage;
|
|
21
14
|
};
|
|
22
15
|
export const isBigger = (current, next) => {
|
|
23
16
|
if (!!current && !!next && canCompareDimension(current.width, next.width) && canCompareDimension(current.height, next.height)) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MediaCardCursor } from '../types';
|
|
2
|
+
export const getMediaCardCursor = (useInlinePlayer, useMediaViewer, isErrorStatus, hasCardPreview, mediaType) => {
|
|
3
|
+
// If error status or no action is requested = NoAction
|
|
4
|
+
if (isErrorStatus || !useInlinePlayer && !useMediaViewer) {
|
|
5
|
+
return MediaCardCursor.NoAction;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (!mediaType && (useInlinePlayer || useInlinePlayer && useMediaViewer)) {
|
|
9
|
+
return MediaCardCursor.NotReady;
|
|
10
|
+
} else if (mediaType === 'video' && hasCardPreview && useInlinePlayer) {
|
|
11
|
+
return MediaCardCursor.Action;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (useMediaViewer) {
|
|
15
|
+
return MediaCardCursor.Action;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return MediaCardCursor.NoAction;
|
|
19
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { printFunctionCall, printScript } from '../printScript';
|
|
3
|
+
// ----- WARNING -----
|
|
4
|
+
// This is a very sensitive fraction of code.
|
|
5
|
+
// Any changes to this file must be tested directly in product before merging.
|
|
6
|
+
// The scripts printed here might differ from what we observe in our internal tests
|
|
7
|
+
// due to minimification, for example.
|
|
8
|
+
export const GLOBAL_MEDIA_CARD_SSR = 'mediaCardSsr';
|
|
9
|
+
export const GLOBAL_MEDIA_NAMESPACE = '__MEDIA_INTERNAL';
|
|
10
|
+
export function getMediaGlobalScope(globalScope = window) {
|
|
11
|
+
// Must match GLOBAL_MEDIA_NAMESPACE. Can't reference the constant from here.
|
|
12
|
+
const namespace = '__MEDIA_INTERNAL';
|
|
13
|
+
|
|
14
|
+
if (!globalScope[namespace]) {
|
|
15
|
+
globalScope[namespace] = {};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return globalScope[namespace];
|
|
19
|
+
}
|
|
20
|
+
export function getMediaCardSSR(globalScope = window) {
|
|
21
|
+
const globalMedia = getMediaGlobalScope(globalScope); // Must match GLOBAL_MEDIA_CARD_SSR. Can't reference the constant from here.
|
|
22
|
+
|
|
23
|
+
const key = 'mediaCardSsr';
|
|
24
|
+
|
|
25
|
+
if (!globalMedia[key]) {
|
|
26
|
+
globalMedia[key] = {};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return globalMedia[key];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const dashed = param => param ? `-${param}` : '';
|
|
33
|
+
|
|
34
|
+
export const getKey = ({
|
|
35
|
+
id,
|
|
36
|
+
collectionName,
|
|
37
|
+
occurrenceKey
|
|
38
|
+
}) => `${id}${dashed(collectionName)}${dashed(occurrenceKey)}`;
|
|
39
|
+
export const storeDataURI = (key, dataURI, dimensions, error, globalScope = window) => {
|
|
40
|
+
const mediaCardSsr = getMediaCardSSR(globalScope);
|
|
41
|
+
mediaCardSsr[key] = {
|
|
42
|
+
dataURI,
|
|
43
|
+
dimensions,
|
|
44
|
+
error
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const generateScript = (identifier, dataURI, dimensions, error) => {
|
|
49
|
+
const functionCall = printFunctionCall(storeDataURI, getKey(identifier), dataURI, dimensions, error);
|
|
50
|
+
return printScript([getMediaCardSSR.toString(), getMediaGlobalScope.toString(), functionCall]);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const StoreSSRDataScript = ({
|
|
54
|
+
dataURI,
|
|
55
|
+
identifier,
|
|
56
|
+
dimensions,
|
|
57
|
+
error
|
|
58
|
+
}) => /*#__PURE__*/React.createElement("script", {
|
|
59
|
+
dangerouslySetInnerHTML: {
|
|
60
|
+
__html: generateScript(identifier, dataURI, dimensions, error)
|
|
61
|
+
}
|
|
62
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const printParam = param => {
|
|
2
|
+
if (typeof param === 'string') {
|
|
3
|
+
return `'${param}'`;
|
|
4
|
+
} else if (typeof param === 'object') {
|
|
5
|
+
return JSON.stringify(param);
|
|
6
|
+
} else if (param === undefined) {
|
|
7
|
+
return 'undefined';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return param;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const printParams = args => args.map(arg => printParam(arg)).join(',');
|
|
14
|
+
|
|
15
|
+
export const printFunctionCall = (fn, ...args) => `(${fn.toString()})(${printParams(args)});`;
|
|
16
|
+
export const printScript = statements => `(function(){
|
|
17
|
+
${statements.join(';')}
|
|
18
|
+
})();
|
|
19
|
+
`;
|
package/dist/es2019/version.json
CHANGED
|
@@ -156,18 +156,30 @@ export var FileCardImageView = /*#__PURE__*/function (_Component) {
|
|
|
156
156
|
})));
|
|
157
157
|
});
|
|
158
158
|
|
|
159
|
-
_defineProperty(_assertThisInitialized(_this), "
|
|
159
|
+
_defineProperty(_assertThisInitialized(_this), "onImageLoad", function () {
|
|
160
160
|
var _this$props6 = _this.props,
|
|
161
|
-
status = _this$props6.status,
|
|
162
|
-
mediaItemType = _this$props6.mediaItemType,
|
|
163
|
-
dataURI = _this$props6.dataURI,
|
|
164
|
-
mediaType = _this$props6.mediaType,
|
|
165
|
-
mimeType = _this$props6.mimeType,
|
|
166
|
-
previewOrientation = _this$props6.previewOrientation,
|
|
167
|
-
onDisplayImage = _this$props6.onDisplayImage,
|
|
168
|
-
alt = _this$props6.alt,
|
|
169
161
|
onImageLoad = _this$props6.onImageLoad,
|
|
170
|
-
|
|
162
|
+
cardPreview = _this$props6.cardPreview;
|
|
163
|
+
onImageLoad && onImageLoad(cardPreview);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
_defineProperty(_assertThisInitialized(_this), "onImageError", function () {
|
|
167
|
+
var _this$props7 = _this.props,
|
|
168
|
+
onImageError = _this$props7.onImageError,
|
|
169
|
+
cardPreview = _this$props7.cardPreview;
|
|
170
|
+
onImageError && onImageError(cardPreview);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
_defineProperty(_assertThisInitialized(_this), "renderMediaImage", function () {
|
|
174
|
+
var _this$props8 = _this.props,
|
|
175
|
+
status = _this$props8.status,
|
|
176
|
+
mediaItemType = _this$props8.mediaItemType,
|
|
177
|
+
dataURI = _this$props8.dataURI,
|
|
178
|
+
mediaType = _this$props8.mediaType,
|
|
179
|
+
mimeType = _this$props8.mimeType,
|
|
180
|
+
previewOrientation = _this$props8.previewOrientation,
|
|
181
|
+
onDisplayImage = _this$props8.onDisplayImage,
|
|
182
|
+
alt = _this$props8.alt;
|
|
171
183
|
|
|
172
184
|
if (!shouldDisplayImageThumbnail(status, mediaItemType, dataURI, mediaType, mimeType)) {
|
|
173
185
|
return null;
|
|
@@ -184,17 +196,17 @@ export var FileCardImageView = /*#__PURE__*/function (_Component) {
|
|
|
184
196
|
crop: _this.isCropped,
|
|
185
197
|
stretch: _this.isStretched,
|
|
186
198
|
previewOrientation: previewOrientation,
|
|
187
|
-
onImageLoad: onImageLoad,
|
|
188
|
-
onImageError: onImageError
|
|
199
|
+
onImageLoad: _this.onImageLoad,
|
|
200
|
+
onImageError: _this.onImageError
|
|
189
201
|
});
|
|
190
202
|
});
|
|
191
203
|
|
|
192
204
|
_defineProperty(_assertThisInitialized(_this), "renderProgressBar", function () {
|
|
193
|
-
var _this$
|
|
194
|
-
mediaName = _this$
|
|
195
|
-
progress = _this$
|
|
196
|
-
actions = _this$
|
|
197
|
-
status = _this$
|
|
205
|
+
var _this$props9 = _this.props,
|
|
206
|
+
mediaName = _this$props9.mediaName,
|
|
207
|
+
progress = _this$props9.progress,
|
|
208
|
+
actions = _this$props9.actions,
|
|
209
|
+
status = _this$props9.status;
|
|
198
210
|
|
|
199
211
|
if (status !== 'uploading') {
|
|
200
212
|
return null;
|
|
@@ -213,10 +225,10 @@ export var FileCardImageView = /*#__PURE__*/function (_Component) {
|
|
|
213
225
|
});
|
|
214
226
|
|
|
215
227
|
_defineProperty(_assertThisInitialized(_this), "renderSuccessCardContents", function () {
|
|
216
|
-
var _this$
|
|
217
|
-
disableOverlay = _this$
|
|
218
|
-
selectable = _this$
|
|
219
|
-
status = _this$
|
|
228
|
+
var _this$props10 = _this.props,
|
|
229
|
+
disableOverlay = _this$props10.disableOverlay,
|
|
230
|
+
selectable = _this$props10.selectable,
|
|
231
|
+
status = _this$props10.status;
|
|
220
232
|
var overlay = null;
|
|
221
233
|
|
|
222
234
|
if (!disableOverlay) {
|
|
@@ -237,15 +249,15 @@ export var FileCardImageView = /*#__PURE__*/function (_Component) {
|
|
|
237
249
|
});
|
|
238
250
|
|
|
239
251
|
_defineProperty(_assertThisInitialized(_this), "renderSuccessCardOverlay", function () {
|
|
240
|
-
var _this$
|
|
241
|
-
status = _this$
|
|
242
|
-
mediaName = _this$
|
|
243
|
-
mediaType = _this$
|
|
244
|
-
fileSize = _this$
|
|
245
|
-
dataURI = _this$
|
|
246
|
-
selectable = _this$
|
|
247
|
-
selected = _this$
|
|
248
|
-
actions = _this$
|
|
252
|
+
var _this$props11 = _this.props,
|
|
253
|
+
status = _this$props11.status,
|
|
254
|
+
mediaName = _this$props11.mediaName,
|
|
255
|
+
mediaType = _this$props11.mediaType,
|
|
256
|
+
fileSize = _this$props11.fileSize,
|
|
257
|
+
dataURI = _this$props11.dataURI,
|
|
258
|
+
selectable = _this$props11.selectable,
|
|
259
|
+
selected = _this$props11.selected,
|
|
260
|
+
actions = _this$props11.actions;
|
|
249
261
|
var isPersistent = mediaType === 'doc' || !dataURI;
|
|
250
262
|
return /*#__PURE__*/React.createElement(CardOverlay, {
|
|
251
263
|
cardStatus: status,
|
|
@@ -265,14 +277,14 @@ export var FileCardImageView = /*#__PURE__*/function (_Component) {
|
|
|
265
277
|
_createClass(FileCardImageView, [{
|
|
266
278
|
key: "render",
|
|
267
279
|
value: function render() {
|
|
268
|
-
var _this$
|
|
269
|
-
disableOverlay = _this$
|
|
270
|
-
selectable = _this$
|
|
271
|
-
selected = _this$
|
|
272
|
-
mediaType = _this$
|
|
273
|
-
progress = _this$
|
|
274
|
-
status = _this$
|
|
275
|
-
mediaName = _this$
|
|
280
|
+
var _this$props12 = this.props,
|
|
281
|
+
disableOverlay = _this$props12.disableOverlay,
|
|
282
|
+
selectable = _this$props12.selectable,
|
|
283
|
+
selected = _this$props12.selected,
|
|
284
|
+
mediaType = _this$props12.mediaType,
|
|
285
|
+
progress = _this$props12.progress,
|
|
286
|
+
status = _this$props12.status,
|
|
287
|
+
mediaName = _this$props12.mediaName;
|
|
276
288
|
return /*#__PURE__*/React.createElement(Wrapper, {
|
|
277
289
|
"data-testid": "media-file-card-view",
|
|
278
290
|
"data-test-media-name": mediaName,
|
|
@@ -289,9 +301,9 @@ export var FileCardImageView = /*#__PURE__*/function (_Component) {
|
|
|
289
301
|
}, {
|
|
290
302
|
key: "isFileCardImageReadyForDisplay",
|
|
291
303
|
get: function get() {
|
|
292
|
-
var _this$
|
|
293
|
-
dataURI = _this$
|
|
294
|
-
status = _this$
|
|
304
|
+
var _this$props13 = this.props,
|
|
305
|
+
dataURI = _this$props13.dataURI,
|
|
306
|
+
status = _this$props13.status;
|
|
295
307
|
return !!dataURI || !['loading', 'processing', 'loading-preview'].includes(status);
|
|
296
308
|
}
|
|
297
309
|
}, {
|
|
@@ -208,6 +208,9 @@ export var isSSRClientPreview = function isSSRClientPreview(preview) {
|
|
|
208
208
|
var ssrClientSources = ['ssr-client', 'cache-ssr-client'];
|
|
209
209
|
return ssrClientSources.includes(preview.source);
|
|
210
210
|
};
|
|
211
|
+
export var isSSRDataPreview = function isSSRDataPreview(preview) {
|
|
212
|
+
return preview.source === 'ssr-data';
|
|
213
|
+
};
|
|
211
214
|
export var fetchAndCacheRemotePreview = /*#__PURE__*/function () {
|
|
212
215
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(mediaClient, id, dimensions, params, mediaBlobUrlAttrs) {
|
|
213
216
|
var remotePreview;
|