@atlaskit/media-card 70.9.0 → 72.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 +69 -0
- package/dist/cjs/errors.js +109 -6
- package/dist/cjs/files/cardImageView/index.js +58 -89
- package/dist/cjs/files/index.js +0 -6
- package/dist/cjs/index.js +16 -6
- package/dist/cjs/root/card/cardAnalytics.js +33 -19
- package/dist/cjs/root/card/cardConstants.js +8 -0
- package/dist/cjs/root/card/cardSSRView.js +114 -0
- package/dist/cjs/root/card/cardState.js +50 -0
- package/dist/cjs/root/card/getCardPreview/cache.js +49 -0
- package/dist/cjs/root/card/getCardPreview/filePreviewStatus.js +50 -0
- package/dist/cjs/root/card/getCardPreview/helpers.js +215 -0
- package/dist/cjs/root/card/getCardPreview/index.js +225 -0
- package/dist/cjs/root/card/getCardStatus.js +16 -21
- package/dist/cjs/root/card/index.js +339 -398
- package/dist/cjs/root/cardView.js +108 -56
- package/dist/cjs/root/index.js +9 -1
- package/dist/cjs/root/inline/loader.js +22 -21
- package/dist/cjs/root/inline/{inlineMediaCard.js → mediaInlineCard.js} +66 -24
- package/dist/cjs/root/inlinePlayer.js +5 -15
- package/dist/cjs/root/ui/Breakpoint.js +13 -0
- package/dist/cjs/root/ui/common.js +5 -11
- package/dist/cjs/root/ui/iconMessage/index.js +17 -9
- package/dist/cjs/root/ui/imageRenderer/imageRenderer.js +32 -115
- package/dist/cjs/root/ui/loadingRateLimited/loadingRateLimited.js +2 -2
- package/dist/cjs/root/ui/progressBar/progressBar.js +2 -2
- package/dist/cjs/root/ui/progressBar/styled.js +3 -1
- package/dist/cjs/root/ui/styled.js +17 -80
- package/dist/cjs/root/ui/styledSSR.js +108 -0
- package/dist/cjs/root/ui/titleBox/failedTitleBox.js +7 -3
- package/dist/cjs/root/ui/titleBox/styled.js +3 -1
- package/dist/cjs/utils/analytics.js +26 -43
- package/dist/cjs/utils/dimensionComparer.js +1 -1
- package/dist/cjs/utils/document.js +12 -0
- package/dist/cjs/utils/getDataURIDimension.js +13 -2
- package/dist/cjs/utils/metadata.js +11 -3
- package/dist/cjs/utils/objectURLCache.js +6 -0
- package/dist/cjs/utils/resizeModeToMediaImageProps.js +13 -0
- package/dist/cjs/utils/shouldDisplayImageThumbnail.js +1 -1
- package/dist/cjs/utils/videoSnapshot.js +45 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/errors.js +52 -2
- package/dist/es2019/files/cardImageView/index.js +12 -46
- package/dist/es2019/files/index.js +1 -1
- package/dist/es2019/index.js +3 -3
- package/dist/es2019/root/card/cardAnalytics.js +23 -17
- package/dist/es2019/root/card/cardConstants.js +1 -0
- package/dist/es2019/root/card/cardSSRView.js +93 -0
- package/dist/es2019/root/card/cardState.js +26 -0
- package/dist/es2019/root/card/getCardPreview/cache.js +29 -0
- package/dist/es2019/root/card/getCardPreview/filePreviewStatus.js +35 -0
- package/dist/es2019/root/card/getCardPreview/helpers.js +83 -0
- package/dist/es2019/root/card/getCardPreview/index.js +129 -0
- package/dist/es2019/root/card/getCardStatus.js +11 -15
- package/dist/es2019/root/card/index.js +292 -276
- package/dist/es2019/root/cardView.js +107 -53
- package/dist/es2019/root/index.js +2 -1
- package/dist/es2019/root/inline/loader.js +16 -15
- package/dist/es2019/root/inline/mediaInlineCard.js +127 -0
- package/dist/es2019/root/inlinePlayer.js +5 -13
- package/dist/es2019/root/ui/Breakpoint.js +6 -0
- package/dist/es2019/root/ui/common.js +1 -7
- package/dist/es2019/root/ui/iconMessage/index.js +10 -6
- package/dist/es2019/root/ui/imageRenderer/imageRenderer.js +22 -74
- package/dist/es2019/root/ui/loadingRateLimited/loadingRateLimited.js +1 -1
- package/dist/es2019/root/ui/progressBar/progressBar.js +1 -1
- package/dist/es2019/root/ui/progressBar/styled.js +2 -1
- package/dist/es2019/root/ui/styled.js +4 -64
- package/dist/es2019/root/ui/styledSSR.js +93 -0
- package/dist/es2019/root/ui/titleBox/failedTitleBox.js +5 -3
- package/dist/es2019/root/ui/titleBox/styled.js +2 -1
- package/dist/es2019/utils/analytics.js +29 -40
- package/dist/es2019/utils/dimensionComparer.js +1 -1
- package/dist/es2019/utils/document.js +1 -0
- package/dist/es2019/utils/getDataURIDimension.js +8 -0
- package/dist/es2019/utils/metadata.js +12 -4
- package/dist/es2019/utils/objectURLCache.js +5 -0
- package/dist/es2019/utils/resizeModeToMediaImageProps.js +6 -0
- package/dist/es2019/utils/shouldDisplayImageThumbnail.js +1 -1
- package/dist/es2019/utils/videoSnapshot.js +7 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/errors.js +85 -2
- package/dist/esm/files/cardImageView/index.js +55 -87
- package/dist/esm/files/index.js +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/root/card/cardAnalytics.js +23 -18
- package/dist/esm/root/card/cardConstants.js +1 -0
- package/dist/esm/root/card/cardSSRView.js +92 -0
- package/dist/esm/root/card/cardState.js +32 -0
- package/dist/esm/root/card/getCardPreview/cache.js +33 -0
- package/dist/esm/root/card/getCardPreview/filePreviewStatus.js +35 -0
- package/dist/esm/root/card/getCardPreview/helpers.js +194 -0
- package/dist/esm/root/card/getCardPreview/index.js +174 -0
- package/dist/esm/root/card/getCardStatus.js +13 -17
- package/dist/esm/root/card/index.js +349 -401
- package/dist/esm/root/cardView.js +105 -52
- package/dist/esm/root/index.js +2 -1
- package/dist/esm/root/inline/loader.js +23 -22
- package/dist/esm/root/inline/{inlineMediaCard.js → mediaInlineCard.js} +62 -22
- package/dist/esm/root/inlinePlayer.js +5 -13
- package/dist/esm/root/ui/Breakpoint.js +6 -0
- package/dist/esm/root/ui/common.js +1 -7
- package/dist/esm/root/ui/iconMessage/index.js +12 -7
- package/dist/esm/root/ui/imageRenderer/imageRenderer.js +24 -106
- package/dist/esm/root/ui/loadingRateLimited/loadingRateLimited.js +1 -1
- package/dist/esm/root/ui/progressBar/progressBar.js +1 -1
- package/dist/esm/root/ui/progressBar/styled.js +2 -1
- package/dist/esm/root/ui/styled.js +13 -61
- package/dist/esm/root/ui/styledSSR.js +76 -0
- package/dist/esm/root/ui/titleBox/failedTitleBox.js +6 -3
- package/dist/esm/root/ui/titleBox/styled.js +2 -1
- package/dist/esm/utils/analytics.js +22 -35
- package/dist/esm/utils/dimensionComparer.js +1 -1
- package/dist/esm/utils/document.js +3 -0
- package/dist/esm/utils/getDataURIDimension.js +8 -0
- package/dist/esm/utils/metadata.js +12 -4
- package/dist/esm/utils/objectURLCache.js +6 -0
- package/dist/esm/utils/resizeModeToMediaImageProps.js +6 -0
- package/dist/esm/utils/shouldDisplayImageThumbnail.js +1 -1
- package/dist/esm/utils/videoSnapshot.js +31 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/__tests_external__/page-objects/MediaCard.d.ts +4 -3
- package/dist/types/errors.d.ts +24 -2
- package/dist/types/files/cardImageView/index.d.ts +5 -12
- package/dist/types/files/cardImageView/styled.d.ts +1 -1
- package/dist/types/files/index.d.ts +1 -1
- package/dist/types/index.d.ts +9 -12
- package/dist/types/root/card/cardAnalytics.d.ts +5 -7
- package/dist/types/root/card/cardConstants.d.ts +1 -0
- package/dist/types/root/card/cardSSRView.d.ts +13 -0
- package/dist/types/root/card/cardState.d.ts +5 -0
- package/dist/types/root/card/getCardPreview/cache.d.ts +18 -0
- package/dist/types/root/card/getCardPreview/filePreviewStatus.d.ts +5 -0
- package/dist/types/root/card/getCardPreview/helpers.d.ts +9 -0
- package/dist/types/root/card/getCardPreview/index.d.ts +44 -0
- package/dist/types/root/card/getCardStatus.d.ts +4 -14
- package/dist/types/root/card/index.d.ts +17 -21
- package/dist/types/root/cardView.d.ts +12 -8
- package/dist/types/root/index.d.ts +1 -0
- package/dist/types/root/inline/loader.d.ts +8 -8
- package/dist/types/root/inline/{inlineMediaCard.d.ts → mediaInlineCard.d.ts} +4 -4
- package/dist/types/root/inlinePlayer.d.ts +1 -1
- package/dist/types/root/ui/Breakpoint.d.ts +4 -0
- package/dist/types/root/ui/common.d.ts +1 -4
- package/dist/types/root/ui/iconMessage/index.d.ts +7 -2
- package/dist/types/root/ui/iconWrapper/styled.d.ts +1 -1
- package/dist/types/root/ui/imageRenderer/imageRenderer.d.ts +2 -16
- package/dist/types/root/ui/loadingRateLimited/loadingRateLimited.d.ts +1 -1
- package/dist/types/root/ui/loadingRateLimited/styled.d.ts +1 -1
- package/dist/types/root/ui/progressBar/progressBar.d.ts +1 -1
- package/dist/types/root/ui/progressBar/styled.d.ts +1 -1
- package/dist/types/root/ui/styled.d.ts +3 -10
- package/dist/types/root/ui/styledSSR.d.ts +16 -0
- package/dist/types/root/ui/titleBox/failedTitleBox.d.ts +3 -1
- package/dist/types/root/ui/titleBox/styled.d.ts +1 -1
- package/dist/types/root/ui/titleBox/titleBox.d.ts +1 -1
- package/dist/types/types.d.ts +15 -1
- package/dist/types/utils/analytics.d.ts +20 -21
- package/dist/types/utils/cardDimensions.d.ts +5 -1
- package/dist/types/utils/dimensionComparer.d.ts +1 -1
- package/dist/types/utils/document.d.ts +2 -0
- package/dist/types/utils/getDataURIDimension.d.ts +3 -1
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/lazyContent/styled.d.ts +1 -1
- package/dist/types/utils/lightCards/types.d.ts +1 -1
- package/dist/types/utils/metadata.d.ts +2 -2
- package/dist/types/utils/objectURLCache.d.ts +2 -1
- package/dist/types/utils/resizeModeToMediaImageProps.d.ts +5 -0
- package/dist/types/utils/shouldDisplayImageThumbnail.d.ts +1 -1
- package/dist/types/utils/videoSnapshot.d.ts +1 -0
- package/example-helpers/index.tsx +21 -0
- package/package.json +19 -17
- package/dist/cjs/root/card/getCardPreview.js +0 -173
- package/dist/cjs/utils/fileAttributesContext.js +0 -40
- package/dist/es2019/root/card/getCardPreview.js +0 -86
- package/dist/es2019/root/inline/inlineMediaCard.js +0 -92
- package/dist/es2019/utils/fileAttributesContext.js +0 -19
- package/dist/esm/root/card/getCardPreview.js +0 -153
- package/dist/esm/utils/fileAttributesContext.js +0 -18
- package/dist/types/root/card/getCardPreview.d.ts +0 -8
- package/dist/types/utils/fileAttributesContext.d.ts +0 -10
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import { takeSnapshot } from '../../../utils/videoSnapshot';
|
|
4
|
+
import { getMediaTypeFromMimeType } from '@atlaskit/media-common';
|
|
5
|
+
import { getOrientation } from '@atlaskit/media-ui';
|
|
6
|
+
import { LocalPreviewError, RemotePreviewError } from '../../../errors';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This method tells the support for the media
|
|
10
|
+
* types covered in getCardPreviewFromFilePreview
|
|
11
|
+
*/
|
|
12
|
+
export var isSupportedLocalPreview = function isSupportedLocalPreview(mediaType) {
|
|
13
|
+
return mediaType === 'image' || mediaType === 'video';
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
var getImageLocalPreview = /*#__PURE__*/function () {
|
|
17
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(value) {
|
|
18
|
+
var orientation, dataURI;
|
|
19
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
20
|
+
while (1) {
|
|
21
|
+
switch (_context.prev = _context.next) {
|
|
22
|
+
case 0:
|
|
23
|
+
_context.prev = 0;
|
|
24
|
+
_context.next = 3;
|
|
25
|
+
return getOrientation(value);
|
|
26
|
+
|
|
27
|
+
case 3:
|
|
28
|
+
orientation = _context.sent;
|
|
29
|
+
dataURI = URL.createObjectURL(value);
|
|
30
|
+
return _context.abrupt("return", {
|
|
31
|
+
dataURI: dataURI,
|
|
32
|
+
orientation: orientation,
|
|
33
|
+
source: 'local'
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
case 8:
|
|
37
|
+
_context.prev = 8;
|
|
38
|
+
_context.t0 = _context["catch"](0);
|
|
39
|
+
throw new LocalPreviewError('local-preview-image', _context.t0);
|
|
40
|
+
|
|
41
|
+
case 11:
|
|
42
|
+
case "end":
|
|
43
|
+
return _context.stop();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}, _callee, null, [[0, 8]]);
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
return function getImageLocalPreview(_x) {
|
|
50
|
+
return _ref.apply(this, arguments);
|
|
51
|
+
};
|
|
52
|
+
}();
|
|
53
|
+
|
|
54
|
+
var getVideoLocalPreview = /*#__PURE__*/function () {
|
|
55
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(value) {
|
|
56
|
+
var dataURI;
|
|
57
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
58
|
+
while (1) {
|
|
59
|
+
switch (_context2.prev = _context2.next) {
|
|
60
|
+
case 0:
|
|
61
|
+
_context2.prev = 0;
|
|
62
|
+
_context2.next = 3;
|
|
63
|
+
return takeSnapshot(value);
|
|
64
|
+
|
|
65
|
+
case 3:
|
|
66
|
+
dataURI = _context2.sent;
|
|
67
|
+
return _context2.abrupt("return", {
|
|
68
|
+
dataURI: dataURI,
|
|
69
|
+
orientation: 1,
|
|
70
|
+
source: 'local'
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
case 7:
|
|
74
|
+
_context2.prev = 7;
|
|
75
|
+
_context2.t0 = _context2["catch"](0);
|
|
76
|
+
throw new LocalPreviewError('local-preview-video', _context2.t0);
|
|
77
|
+
|
|
78
|
+
case 10:
|
|
79
|
+
case "end":
|
|
80
|
+
return _context2.stop();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}, _callee2, null, [[0, 7]]);
|
|
84
|
+
}));
|
|
85
|
+
|
|
86
|
+
return function getVideoLocalPreview(_x2) {
|
|
87
|
+
return _ref2.apply(this, arguments);
|
|
88
|
+
};
|
|
89
|
+
}();
|
|
90
|
+
|
|
91
|
+
export var getCardPreviewFromFilePreview = /*#__PURE__*/function () {
|
|
92
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(filePreview) {
|
|
93
|
+
var value, resolvedFilePreview, _value, type, mediaType;
|
|
94
|
+
|
|
95
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
96
|
+
while (1) {
|
|
97
|
+
switch (_context3.prev = _context3.next) {
|
|
98
|
+
case 0:
|
|
99
|
+
_context3.prev = 0;
|
|
100
|
+
_context3.next = 3;
|
|
101
|
+
return filePreview;
|
|
102
|
+
|
|
103
|
+
case 3:
|
|
104
|
+
resolvedFilePreview = _context3.sent;
|
|
105
|
+
value = resolvedFilePreview.value;
|
|
106
|
+
_context3.next = 10;
|
|
107
|
+
break;
|
|
108
|
+
|
|
109
|
+
case 7:
|
|
110
|
+
_context3.prev = 7;
|
|
111
|
+
_context3.t0 = _context3["catch"](0);
|
|
112
|
+
throw new LocalPreviewError('local-preview-rejected', _context3.t0);
|
|
113
|
+
|
|
114
|
+
case 10:
|
|
115
|
+
if (!(typeof value === 'string')) {
|
|
116
|
+
_context3.next = 14;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return _context3.abrupt("return", {
|
|
121
|
+
dataURI: value,
|
|
122
|
+
orientation: 1,
|
|
123
|
+
source: 'local'
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
case 14:
|
|
127
|
+
if (!(value instanceof Blob)) {
|
|
128
|
+
_context3.next = 22;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
_value = value, type = _value.type;
|
|
133
|
+
mediaType = getMediaTypeFromMimeType(type);
|
|
134
|
+
_context3.t1 = mediaType;
|
|
135
|
+
_context3.next = _context3.t1 === 'image' ? 20 : _context3.t1 === 'video' ? 21 : 22;
|
|
136
|
+
break;
|
|
137
|
+
|
|
138
|
+
case 20:
|
|
139
|
+
return _context3.abrupt("return", getImageLocalPreview(value));
|
|
140
|
+
|
|
141
|
+
case 21:
|
|
142
|
+
return _context3.abrupt("return", getVideoLocalPreview(value));
|
|
143
|
+
|
|
144
|
+
case 22:
|
|
145
|
+
throw new LocalPreviewError('local-preview-unsupported');
|
|
146
|
+
|
|
147
|
+
case 23:
|
|
148
|
+
case "end":
|
|
149
|
+
return _context3.stop();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}, _callee3, null, [[0, 7]]);
|
|
153
|
+
}));
|
|
154
|
+
|
|
155
|
+
return function getCardPreviewFromFilePreview(_x3) {
|
|
156
|
+
return _ref3.apply(this, arguments);
|
|
157
|
+
};
|
|
158
|
+
}();
|
|
159
|
+
export var getCardPreviewFromBackend = /*#__PURE__*/function () {
|
|
160
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(mediaClient, id, params) {
|
|
161
|
+
var blob;
|
|
162
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
163
|
+
while (1) {
|
|
164
|
+
switch (_context4.prev = _context4.next) {
|
|
165
|
+
case 0:
|
|
166
|
+
_context4.prev = 0;
|
|
167
|
+
_context4.next = 3;
|
|
168
|
+
return mediaClient.getImage(id, params);
|
|
169
|
+
|
|
170
|
+
case 3:
|
|
171
|
+
blob = _context4.sent;
|
|
172
|
+
return _context4.abrupt("return", {
|
|
173
|
+
dataURI: URL.createObjectURL(blob),
|
|
174
|
+
orientation: 1,
|
|
175
|
+
source: 'remote'
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
case 7:
|
|
179
|
+
_context4.prev = 7;
|
|
180
|
+
_context4.t0 = _context4["catch"](0);
|
|
181
|
+
throw new RemotePreviewError('remote-preview-fetch', _context4.t0);
|
|
182
|
+
|
|
183
|
+
case 10:
|
|
184
|
+
case "end":
|
|
185
|
+
return _context4.stop();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}, _callee4, null, [[0, 7]]);
|
|
189
|
+
}));
|
|
190
|
+
|
|
191
|
+
return function getCardPreviewFromBackend(_x4, _x5, _x6) {
|
|
192
|
+
return _ref4.apply(this, arguments);
|
|
193
|
+
};
|
|
194
|
+
}();
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
|
|
5
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
+
|
|
7
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
8
|
+
|
|
9
|
+
import { isPreviewableFileState, addFileAttrsToUrl } from '@atlaskit/media-client';
|
|
10
|
+
import { isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
11
|
+
import cardPreviewCache from './cache';
|
|
12
|
+
import { getCardPreviewFromFilePreview, getCardPreviewFromBackend } from './helpers';
|
|
13
|
+
import { MediaCardError, isUnsupportedLocalPreviewError } from '../../../errors';
|
|
14
|
+
import { isBigger } from '../../../utils/dimensionComparer';
|
|
15
|
+
import { extractFilePreviewStatus, isPreviewableStatus } from './filePreviewStatus';
|
|
16
|
+
export { getCardPreviewFromFilePreview, getCardPreviewFromBackend, isSupportedLocalPreview } from './helpers';
|
|
17
|
+
export { extractFilePreviewStatus } from './filePreviewStatus';
|
|
18
|
+
export var getCardPreviewFromCache = cardPreviewCache.get;
|
|
19
|
+
export var removeCardPreviewFromCache = cardPreviewCache.remove;
|
|
20
|
+
/**
|
|
21
|
+
* Will return the preview if available and supported by the browser
|
|
22
|
+
* See extractFilePreviewStatus "hasLocalPreview" logic
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export var getFilePreviewFromFileState = function getFilePreviewFromFileState(fileState) {
|
|
26
|
+
return 'mimeType' in fileState && isMimeTypeSupportedByBrowser(fileState.mimeType) && isPreviewableFileState(fileState) ? fileState.preview : undefined;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
var extendAndCachePreview = function extendAndCachePreview(id, dimensions, preview, mediaBlobUrlAttrs) {
|
|
30
|
+
var source;
|
|
31
|
+
|
|
32
|
+
switch (preview.source) {
|
|
33
|
+
case 'local':
|
|
34
|
+
source = 'cache-local';
|
|
35
|
+
break;
|
|
36
|
+
|
|
37
|
+
case 'remote':
|
|
38
|
+
source = 'cache-remote';
|
|
39
|
+
break;
|
|
40
|
+
|
|
41
|
+
default:
|
|
42
|
+
source = preview.source;
|
|
43
|
+
} // We want to embed some meta context into dataURI for Copy/Paste to work.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
var dataURI = mediaBlobUrlAttrs ? addFileAttrsToUrl(preview.dataURI, mediaBlobUrlAttrs) : preview.dataURI; // We store new cardPreview into cache
|
|
47
|
+
|
|
48
|
+
cardPreviewCache.set(id, dimensions, _objectSpread(_objectSpread({}, preview), {}, {
|
|
49
|
+
source: source,
|
|
50
|
+
dataURI: dataURI
|
|
51
|
+
}));
|
|
52
|
+
return _objectSpread(_objectSpread({}, preview), {}, {
|
|
53
|
+
dataURI: dataURI
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* This function will try to return a Card preview, either from cache, local preview or remote preview.
|
|
58
|
+
* It should only be called if there is a chance to get either a remote or a local preview, or both.
|
|
59
|
+
* This, in order to ensure there is always going to be a valid return value OR throw an error if the process fails.
|
|
60
|
+
* It is worth noting that local preview failures break the process if there is no remote preview available.
|
|
61
|
+
* In that case we throw an error immediately.
|
|
62
|
+
* Otherwise, if the local preview fails but there is a remote preview available, the failure does not break the process.
|
|
63
|
+
* In that case, we still want to report the local preview error to the caller, for feature realiability track.
|
|
64
|
+
* hence the use of the optional callback onLocalPreviewError
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
export var getCardPreview = /*#__PURE__*/function () {
|
|
69
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
|
|
70
|
+
var mediaClient, id, _ref$dimensions, dimensions, filePreview, onLocalPreviewError, isRemotePreviewReady, imageUrlParams, mediaBlobUrlAttrs, cachedPreview, localPreview, remotePreview;
|
|
71
|
+
|
|
72
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
73
|
+
while (1) {
|
|
74
|
+
switch (_context.prev = _context.next) {
|
|
75
|
+
case 0:
|
|
76
|
+
mediaClient = _ref.mediaClient, id = _ref.id, _ref$dimensions = _ref.dimensions, dimensions = _ref$dimensions === void 0 ? {} : _ref$dimensions, filePreview = _ref.filePreview, onLocalPreviewError = _ref.onLocalPreviewError, isRemotePreviewReady = _ref.isRemotePreviewReady, imageUrlParams = _ref.imageUrlParams, mediaBlobUrlAttrs = _ref.mediaBlobUrlAttrs;
|
|
77
|
+
cachedPreview = cardPreviewCache.get(id, dimensions);
|
|
78
|
+
|
|
79
|
+
if (!cachedPreview) {
|
|
80
|
+
_context.next = 4;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return _context.abrupt("return", cachedPreview);
|
|
85
|
+
|
|
86
|
+
case 4:
|
|
87
|
+
_context.prev = 4;
|
|
88
|
+
|
|
89
|
+
if (!filePreview) {
|
|
90
|
+
_context.next = 10;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
_context.next = 8;
|
|
95
|
+
return getCardPreviewFromFilePreview(filePreview);
|
|
96
|
+
|
|
97
|
+
case 8:
|
|
98
|
+
localPreview = _context.sent;
|
|
99
|
+
return _context.abrupt("return", extendAndCachePreview(id, dimensions, localPreview, mediaBlobUrlAttrs));
|
|
100
|
+
|
|
101
|
+
case 10:
|
|
102
|
+
_context.next = 17;
|
|
103
|
+
break;
|
|
104
|
+
|
|
105
|
+
case 12:
|
|
106
|
+
_context.prev = 12;
|
|
107
|
+
_context.t0 = _context["catch"](4);
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* We report the error if:
|
|
111
|
+
* - local preview is supported and fails
|
|
112
|
+
* - local preview is unsupported and remote preview is NOT READY
|
|
113
|
+
* i.e. the function was called for "no reason".
|
|
114
|
+
* We DON'T report the error if:
|
|
115
|
+
* - local preview is unsupported and remote preview IS READY
|
|
116
|
+
* i.e. local preview is available and not supported,
|
|
117
|
+
* but we are after the remote preview instead.
|
|
118
|
+
*/
|
|
119
|
+
if (!isUnsupportedLocalPreviewError(_context.t0) || isUnsupportedLocalPreviewError(_context.t0) && !isRemotePreviewReady) {
|
|
120
|
+
onLocalPreviewError && onLocalPreviewError(_context.t0);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* No matter the reason why the local preview failed, we break the process
|
|
124
|
+
* if there is no remote preview available
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
if (isRemotePreviewReady) {
|
|
129
|
+
_context.next = 17;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
throw _context.t0;
|
|
134
|
+
|
|
135
|
+
case 17:
|
|
136
|
+
if (isRemotePreviewReady) {
|
|
137
|
+
_context.next = 19;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
throw new MediaCardError('remote-preview-not-ready');
|
|
142
|
+
|
|
143
|
+
case 19:
|
|
144
|
+
_context.next = 21;
|
|
145
|
+
return getCardPreviewFromBackend(mediaClient, id, imageUrlParams);
|
|
146
|
+
|
|
147
|
+
case 21:
|
|
148
|
+
remotePreview = _context.sent;
|
|
149
|
+
return _context.abrupt("return", extendAndCachePreview(id, dimensions, remotePreview, mediaBlobUrlAttrs));
|
|
150
|
+
|
|
151
|
+
case 23:
|
|
152
|
+
case "end":
|
|
153
|
+
return _context.stop();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}, _callee, null, [[4, 12]]);
|
|
157
|
+
}));
|
|
158
|
+
|
|
159
|
+
return function getCardPreview(_x) {
|
|
160
|
+
return _ref2.apply(this, arguments);
|
|
161
|
+
};
|
|
162
|
+
}();
|
|
163
|
+
export var shouldResolvePreview = function shouldResolvePreview(_ref3) {
|
|
164
|
+
var status = _ref3.status,
|
|
165
|
+
fileState = _ref3.fileState,
|
|
166
|
+
dimensions = _ref3.dimensions,
|
|
167
|
+
prevDimensions = _ref3.prevDimensions,
|
|
168
|
+
hasCardPreview = _ref3.hasCardPreview,
|
|
169
|
+
isBannedLocalPreview = _ref3.isBannedLocalPreview,
|
|
170
|
+
featureFlags = _ref3.featureFlags;
|
|
171
|
+
var statusIsPreviewable = isPreviewableStatus(status, extractFilePreviewStatus(fileState, isBannedLocalPreview, featureFlags));
|
|
172
|
+
var dimensionsAreBigger = isBigger(prevDimensions, dimensions);
|
|
173
|
+
return statusIsPreviewable && (!hasCardPreview || dimensionsAreBigger);
|
|
174
|
+
};
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return {
|
|
4
|
-
// TODO: align these checks with helpers from Media Client
|
|
5
|
-
// https://product-fabric.atlassian.net/browse/BMPT-1300
|
|
6
|
-
isPreviewableType: 'mediaType' in fileState && !!fileState.mediaType && isPreviewableType(fileState.mediaType, featureFlags),
|
|
7
|
-
hasFilesize: 'size' in fileState && !!fileState.size,
|
|
8
|
-
isPreviewableFileState: isPreviewableFileState(fileState)
|
|
9
|
-
};
|
|
1
|
+
export var isFinalCardStatus = function isFinalCardStatus(status) {
|
|
2
|
+
return ['complete', 'error', 'failed-processing'].includes(status);
|
|
10
3
|
};
|
|
11
4
|
export var getCardStatus = function getCardStatus(fileStatus, _ref) {
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
var hasFilesize = _ref.hasFilesize,
|
|
6
|
+
isPreviewable = _ref.isPreviewable,
|
|
7
|
+
hasPreview = _ref.hasPreview;
|
|
15
8
|
|
|
16
9
|
switch (fileStatus) {
|
|
17
10
|
case 'uploading':
|
|
@@ -21,24 +14,27 @@ export var getCardStatus = function getCardStatus(fileStatus, _ref) {
|
|
|
21
14
|
|
|
22
15
|
case 'processing':
|
|
23
16
|
// Legacy empty files logic
|
|
24
|
-
//
|
|
17
|
+
// isPreviewable will most likely be false for empty files,
|
|
25
18
|
// therefore we need to do this cut before that check.
|
|
26
19
|
// TODO: https://product-fabric.atlassian.net/browse/BMPT-1247
|
|
27
20
|
if (!hasFilesize) {
|
|
28
21
|
return 'processing';
|
|
29
22
|
} // If we show no preview for this file
|
|
30
|
-
// we won't show the "creating preview" message
|
|
31
|
-
// i.e. Card is "complete".
|
|
23
|
+
// we won't show the "creating preview" message, i.e. Card is "complete".
|
|
32
24
|
|
|
33
25
|
|
|
34
|
-
if (!
|
|
26
|
+
if (!isPreviewable) {
|
|
35
27
|
return 'complete';
|
|
36
28
|
}
|
|
37
29
|
|
|
38
30
|
return 'processing';
|
|
39
31
|
|
|
40
32
|
case 'processed':
|
|
41
|
-
|
|
33
|
+
if (!isPreviewable || !hasPreview) {
|
|
34
|
+
return 'complete';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return 'loading-preview';
|
|
42
38
|
|
|
43
39
|
default:
|
|
44
40
|
return 'loading';
|