@atlaskit/media-card 78.0.6 → 78.0.8
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 +17 -0
- package/dist/cjs/card/card.js +1 -1
- package/dist/cjs/card/fileCard.js +2 -2
- package/dist/cjs/card/media-card-analytics-error-boundary.js +1 -1
- package/dist/cjs/card/svgView/helpers.js +2 -2
- package/dist/cjs/inline/loader.js +1 -1
- package/dist/cjs/types.js +16 -1
- package/dist/cjs/utils/ufoExperiences.js +1 -1
- package/dist/es2019/card/card.js +1 -1
- package/dist/es2019/card/fileCard.js +1 -1
- package/dist/es2019/card/media-card-analytics-error-boundary.js +1 -1
- package/dist/es2019/card/svgView/helpers.js +2 -2
- package/dist/es2019/inline/loader.js +1 -1
- package/dist/es2019/types.js +10 -0
- package/dist/es2019/utils/ufoExperiences.js +1 -1
- package/dist/esm/card/card.js +1 -1
- package/dist/esm/card/fileCard.js +1 -1
- package/dist/esm/card/media-card-analytics-error-boundary.js +1 -1
- package/dist/esm/card/svgView/helpers.js +2 -2
- package/dist/esm/inline/loader.js +1 -1
- package/dist/esm/types.js +14 -0
- package/dist/esm/utils/ufoExperiences.js +1 -1
- package/dist/types/types.d.ts +4 -0
- package/dist/types-ts4.5/types.d.ts +4 -0
- package/package.json +2 -2
- package/dist/cjs/card/cardState.js +0 -37
- package/dist/cjs/card/getCardPreview/cache.js +0 -39
- package/dist/cjs/card/getCardPreview/filePreviewStatus.js +0 -45
- package/dist/cjs/card/getCardPreview/helpers.js +0 -165
- package/dist/cjs/card/getCardPreview/index.js +0 -245
- package/dist/es2019/card/cardState.js +0 -30
- package/dist/es2019/card/getCardPreview/cache.js +0 -33
- package/dist/es2019/card/getCardPreview/filePreviewStatus.js +0 -43
- package/dist/es2019/card/getCardPreview/helpers.js +0 -74
- package/dist/es2019/card/getCardPreview/index.js +0 -170
- package/dist/esm/card/cardState.js +0 -32
- package/dist/esm/card/getCardPreview/cache.js +0 -35
- package/dist/esm/card/getCardPreview/filePreviewStatus.js +0 -40
- package/dist/esm/card/getCardPreview/helpers.js +0 -158
- package/dist/esm/card/getCardPreview/index.js +0 -213
- package/dist/types/card/cardState.d.ts +0 -9
- package/dist/types/card/getCardPreview/cache.d.ts +0 -21
- package/dist/types/card/getCardPreview/filePreviewStatus.d.ts +0 -4
- package/dist/types/card/getCardPreview/helpers.d.ts +0 -10
- package/dist/types/card/getCardPreview/index.d.ts +0 -53
- package/dist/types-ts4.5/card/cardState.d.ts +0 -9
- package/dist/types-ts4.5/card/getCardPreview/cache.d.ts +0 -21
- package/dist/types-ts4.5/card/getCardPreview/filePreviewStatus.d.ts +0 -4
- package/dist/types-ts4.5/card/getCardPreview/helpers.d.ts +0 -10
- package/dist/types-ts4.5/card/getCardPreview/index.d.ts +0 -53
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
2
|
-
import { isPreviewableFileState, isPreviewableType, isImageRepresentationReady } from '@atlaskit/media-client';
|
|
3
|
-
import { isSupportedLocalPreview } from './helpers';
|
|
4
|
-
|
|
5
|
-
// TODO: align these checks with helpers from Media Client
|
|
6
|
-
// https://product-fabric.atlassian.net/browse/BMPT-1300
|
|
7
|
-
export var extractFilePreviewStatus = function extractFilePreviewStatus(fileState, isBannedLocalPreview) {
|
|
8
|
-
var hasFilesize = 'size' in fileState && !!fileState.size;
|
|
9
|
-
var _ref = 'mediaType' in fileState && fileState || {},
|
|
10
|
-
mediaType = _ref.mediaType;
|
|
11
|
-
var _ref2 = 'mimeType' in fileState && fileState || {},
|
|
12
|
-
mimeType = _ref2.mimeType;
|
|
13
|
-
var isPreviewable = !!mediaType && isPreviewableType(mediaType);
|
|
14
|
-
|
|
15
|
-
// Local preview is available only if it's supported by browser and supported by Media Card (isSupportedLocalPreview)
|
|
16
|
-
// For example, SVGs are mime type NOT supported by browser but media type supported by Media Card (image)
|
|
17
|
-
// Then, local Preview NOT available
|
|
18
|
-
var hasLocalPreview = !isBannedLocalPreview && isPreviewableFileState(fileState) && isSupportedLocalPreview(mediaType) && !!mimeType && isMimeTypeSupportedByBrowser(mimeType);
|
|
19
|
-
var hasRemotePreview = isImageRepresentationReady(fileState);
|
|
20
|
-
var hasPreview = hasLocalPreview || hasRemotePreview;
|
|
21
|
-
var isSupportedByBrowser = !!mimeType && isMimeTypeSupportedByBrowser(mimeType);
|
|
22
|
-
return {
|
|
23
|
-
hasFilesize: hasFilesize,
|
|
24
|
-
isPreviewable: isPreviewable,
|
|
25
|
-
hasPreview: hasPreview,
|
|
26
|
-
isSupportedByBrowser: isSupportedByBrowser
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// CXP-2723 TODO: Review this in relation to removing status from the hook
|
|
31
|
-
export var isPreviewableStatus = function isPreviewableStatus(cardStatus, _ref3) {
|
|
32
|
-
var isPreviewable = _ref3.isPreviewable,
|
|
33
|
-
hasPreview = _ref3.hasPreview,
|
|
34
|
-
isSupportedByBrowser = _ref3.isSupportedByBrowser;
|
|
35
|
-
return hasPreview && isPreviewable && (cardStatus === 'complete' || cardStatus === 'loading-preview' || cardStatus === 'uploading' ||
|
|
36
|
-
// For Video, we can have local or remote preview while processing.
|
|
37
|
-
// Then, we only want to show the thumbnail if the file is supported by the browser,
|
|
38
|
-
// this way we prevent playing unsupported videos that are not procesed
|
|
39
|
-
cardStatus === 'processing' && isSupportedByBrowser);
|
|
40
|
-
};
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
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
|
-
* This method tells the support for the media
|
|
9
|
-
* types covered in getCardPreviewFromFilePreview
|
|
10
|
-
*/
|
|
11
|
-
export var isSupportedLocalPreview = function isSupportedLocalPreview(mediaType) {
|
|
12
|
-
return mediaType === 'image' || mediaType === 'video';
|
|
13
|
-
};
|
|
14
|
-
var getImageLocalPreview = /*#__PURE__*/function () {
|
|
15
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(value) {
|
|
16
|
-
var orientation, dataURI;
|
|
17
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
18
|
-
while (1) switch (_context.prev = _context.next) {
|
|
19
|
-
case 0:
|
|
20
|
-
_context.prev = 0;
|
|
21
|
-
_context.next = 3;
|
|
22
|
-
return getOrientation(value);
|
|
23
|
-
case 3:
|
|
24
|
-
orientation = _context.sent;
|
|
25
|
-
dataURI = URL.createObjectURL(value);
|
|
26
|
-
return _context.abrupt("return", {
|
|
27
|
-
dataURI: dataURI,
|
|
28
|
-
orientation: orientation,
|
|
29
|
-
source: 'local'
|
|
30
|
-
});
|
|
31
|
-
case 8:
|
|
32
|
-
_context.prev = 8;
|
|
33
|
-
_context.t0 = _context["catch"](0);
|
|
34
|
-
throw new LocalPreviewError('local-preview-image', _context.t0 instanceof Error ? _context.t0 : undefined);
|
|
35
|
-
case 11:
|
|
36
|
-
case "end":
|
|
37
|
-
return _context.stop();
|
|
38
|
-
}
|
|
39
|
-
}, _callee, null, [[0, 8]]);
|
|
40
|
-
}));
|
|
41
|
-
return function getImageLocalPreview(_x) {
|
|
42
|
-
return _ref.apply(this, arguments);
|
|
43
|
-
};
|
|
44
|
-
}();
|
|
45
|
-
var getVideoLocalPreview = /*#__PURE__*/function () {
|
|
46
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(value) {
|
|
47
|
-
var dataURI;
|
|
48
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
49
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
50
|
-
case 0:
|
|
51
|
-
_context2.prev = 0;
|
|
52
|
-
_context2.next = 3;
|
|
53
|
-
return takeSnapshot(value);
|
|
54
|
-
case 3:
|
|
55
|
-
dataURI = _context2.sent;
|
|
56
|
-
return _context2.abrupt("return", {
|
|
57
|
-
dataURI: dataURI,
|
|
58
|
-
orientation: 1,
|
|
59
|
-
source: 'local'
|
|
60
|
-
});
|
|
61
|
-
case 7:
|
|
62
|
-
_context2.prev = 7;
|
|
63
|
-
_context2.t0 = _context2["catch"](0);
|
|
64
|
-
throw new LocalPreviewError('local-preview-video', _context2.t0 instanceof Error ? _context2.t0 : undefined);
|
|
65
|
-
case 10:
|
|
66
|
-
case "end":
|
|
67
|
-
return _context2.stop();
|
|
68
|
-
}
|
|
69
|
-
}, _callee2, null, [[0, 7]]);
|
|
70
|
-
}));
|
|
71
|
-
return function getVideoLocalPreview(_x2) {
|
|
72
|
-
return _ref2.apply(this, arguments);
|
|
73
|
-
};
|
|
74
|
-
}();
|
|
75
|
-
export var getCardPreviewFromFilePreview = /*#__PURE__*/function () {
|
|
76
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(filePreview) {
|
|
77
|
-
var value, resolvedFilePreview, _value, type, mediaType;
|
|
78
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
79
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
80
|
-
case 0:
|
|
81
|
-
_context3.prev = 0;
|
|
82
|
-
_context3.next = 3;
|
|
83
|
-
return filePreview;
|
|
84
|
-
case 3:
|
|
85
|
-
resolvedFilePreview = _context3.sent;
|
|
86
|
-
value = resolvedFilePreview.value;
|
|
87
|
-
_context3.next = 10;
|
|
88
|
-
break;
|
|
89
|
-
case 7:
|
|
90
|
-
_context3.prev = 7;
|
|
91
|
-
_context3.t0 = _context3["catch"](0);
|
|
92
|
-
throw new LocalPreviewError('local-preview-rejected', _context3.t0 instanceof Error ? _context3.t0 : undefined);
|
|
93
|
-
case 10:
|
|
94
|
-
if (!(typeof value === 'string')) {
|
|
95
|
-
_context3.next = 14;
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
return _context3.abrupt("return", {
|
|
99
|
-
dataURI: value,
|
|
100
|
-
orientation: 1,
|
|
101
|
-
source: 'local'
|
|
102
|
-
});
|
|
103
|
-
case 14:
|
|
104
|
-
if (!(value instanceof Blob)) {
|
|
105
|
-
_context3.next = 22;
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
_value = value, type = _value.type;
|
|
109
|
-
mediaType = getMediaTypeFromMimeType(type);
|
|
110
|
-
_context3.t1 = mediaType;
|
|
111
|
-
_context3.next = _context3.t1 === 'image' ? 20 : _context3.t1 === 'video' ? 21 : 22;
|
|
112
|
-
break;
|
|
113
|
-
case 20:
|
|
114
|
-
return _context3.abrupt("return", getImageLocalPreview(value));
|
|
115
|
-
case 21:
|
|
116
|
-
return _context3.abrupt("return", getVideoLocalPreview(value));
|
|
117
|
-
case 22:
|
|
118
|
-
throw new LocalPreviewError('local-preview-unsupported');
|
|
119
|
-
case 23:
|
|
120
|
-
case "end":
|
|
121
|
-
return _context3.stop();
|
|
122
|
-
}
|
|
123
|
-
}, _callee3, null, [[0, 7]]);
|
|
124
|
-
}));
|
|
125
|
-
return function getCardPreviewFromFilePreview(_x3) {
|
|
126
|
-
return _ref3.apply(this, arguments);
|
|
127
|
-
};
|
|
128
|
-
}();
|
|
129
|
-
export var getCardPreviewFromBackend = /*#__PURE__*/function () {
|
|
130
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(mediaClient, id, params, traceContext) {
|
|
131
|
-
var blob;
|
|
132
|
-
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
133
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
134
|
-
case 0:
|
|
135
|
-
_context4.prev = 0;
|
|
136
|
-
_context4.next = 3;
|
|
137
|
-
return mediaClient.getImage(id, params, undefined, undefined, traceContext);
|
|
138
|
-
case 3:
|
|
139
|
-
blob = _context4.sent;
|
|
140
|
-
return _context4.abrupt("return", {
|
|
141
|
-
dataURI: URL.createObjectURL(blob),
|
|
142
|
-
orientation: 1,
|
|
143
|
-
source: 'remote'
|
|
144
|
-
});
|
|
145
|
-
case 7:
|
|
146
|
-
_context4.prev = 7;
|
|
147
|
-
_context4.t0 = _context4["catch"](0);
|
|
148
|
-
throw new RemotePreviewError('remote-preview-fetch', _context4.t0 instanceof Error ? _context4.t0 : undefined);
|
|
149
|
-
case 10:
|
|
150
|
-
case "end":
|
|
151
|
-
return _context4.stop();
|
|
152
|
-
}
|
|
153
|
-
}, _callee4, null, [[0, 7]]);
|
|
154
|
-
}));
|
|
155
|
-
return function getCardPreviewFromBackend(_x4, _x5, _x6, _x7) {
|
|
156
|
-
return _ref4.apply(this, arguments);
|
|
157
|
-
};
|
|
158
|
-
}();
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
-
import { isPreviewableFileState, addFileAttrsToUrl } from '@atlaskit/media-client';
|
|
7
|
-
import { isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
8
|
-
import cardPreviewCache from './cache';
|
|
9
|
-
import { getCardPreviewFromFilePreview, getCardPreviewFromBackend } from './helpers';
|
|
10
|
-
import { MediaCardError, SsrPreviewError, isUnsupportedLocalPreviewError } from '../../errors';
|
|
11
|
-
import { isBigger } from '../../utils/dimensionComparer';
|
|
12
|
-
import { extractFilePreviewStatus, isPreviewableStatus } from './filePreviewStatus';
|
|
13
|
-
export { getCardPreviewFromFilePreview, getCardPreviewFromBackend, isSupportedLocalPreview } from './helpers';
|
|
14
|
-
export { extractFilePreviewStatus } from './filePreviewStatus';
|
|
15
|
-
export var getCardPreviewFromCache = cardPreviewCache.get;
|
|
16
|
-
export var removeCardPreviewFromCache = cardPreviewCache.remove;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Will return the preview if available and supported by the browser
|
|
20
|
-
* See extractFilePreviewStatus "hasLocalPreview" logic
|
|
21
|
-
*/
|
|
22
|
-
export var getFilePreviewFromFileState = function getFilePreviewFromFileState(fileState) {
|
|
23
|
-
return 'mimeType' in fileState && isMimeTypeSupportedByBrowser(fileState.mimeType) && isPreviewableFileState(fileState) ? fileState.preview : undefined;
|
|
24
|
-
};
|
|
25
|
-
var extendAndCachePreview = function extendAndCachePreview(id, mode, preview, mediaBlobUrlAttrs) {
|
|
26
|
-
var source;
|
|
27
|
-
switch (preview.source) {
|
|
28
|
-
case 'local':
|
|
29
|
-
source = 'cache-local';
|
|
30
|
-
break;
|
|
31
|
-
case 'remote':
|
|
32
|
-
source = 'cache-remote';
|
|
33
|
-
break;
|
|
34
|
-
case 'ssr-server':
|
|
35
|
-
source = 'cache-ssr-server';
|
|
36
|
-
break;
|
|
37
|
-
case 'ssr-client':
|
|
38
|
-
source = 'cache-ssr-client';
|
|
39
|
-
break;
|
|
40
|
-
default:
|
|
41
|
-
source = preview.source;
|
|
42
|
-
}
|
|
43
|
-
// We want to embed some meta context into dataURI for Copy/Paste to work.
|
|
44
|
-
var dataURI = mediaBlobUrlAttrs ? addFileAttrsToUrl(preview.dataURI, mediaBlobUrlAttrs) : preview.dataURI;
|
|
45
|
-
// We store new cardPreview into cache
|
|
46
|
-
cardPreviewCache.set(id, mode, _objectSpread(_objectSpread({}, preview), {}, {
|
|
47
|
-
source: source,
|
|
48
|
-
dataURI: dataURI
|
|
49
|
-
}));
|
|
50
|
-
return _objectSpread(_objectSpread({}, preview), {}, {
|
|
51
|
-
dataURI: dataURI
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* This function will try to return a Card preview, either from cache, local preview or remote preview.
|
|
57
|
-
* It should only be called if there is a chance to get either a remote or a local preview, or both.
|
|
58
|
-
* This, in order to ensure there is always going to be a valid return value OR throw an error if the process fails.
|
|
59
|
-
* It is worth noting that local preview failures break the process if there is no remote preview available.
|
|
60
|
-
* In that case we throw an error immediately.
|
|
61
|
-
* Otherwise, if the local preview fails but there is a remote preview available, the failure does not break the process.
|
|
62
|
-
* In that case, we still want to report the local preview error to the caller, for feature realiability track.
|
|
63
|
-
* hence the use of the optional callback onLocalPreviewError
|
|
64
|
-
*/
|
|
65
|
-
export var getCardPreview = /*#__PURE__*/function () {
|
|
66
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
|
|
67
|
-
var mediaClient, id, _ref$dimensions, dimensions, filePreview, onLocalPreviewError, isRemotePreviewReady, imageUrlParams, mediaBlobUrlAttrs, traceContext, mode, cachedPreview, dimensionsAreBigger, localPreview, remotePreview;
|
|
68
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
69
|
-
while (1) switch (_context.prev = _context.next) {
|
|
70
|
-
case 0:
|
|
71
|
-
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, traceContext = _ref.traceContext;
|
|
72
|
-
mode = imageUrlParams.mode;
|
|
73
|
-
cachedPreview = cardPreviewCache.get(id, mode);
|
|
74
|
-
dimensionsAreBigger = isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions, dimensions);
|
|
75
|
-
if (!(cachedPreview && !dimensionsAreBigger)) {
|
|
76
|
-
_context.next = 6;
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
return _context.abrupt("return", cachedPreview);
|
|
80
|
-
case 6:
|
|
81
|
-
_context.prev = 6;
|
|
82
|
-
if (!filePreview) {
|
|
83
|
-
_context.next = 12;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
_context.next = 10;
|
|
87
|
-
return getCardPreviewFromFilePreview(filePreview);
|
|
88
|
-
case 10:
|
|
89
|
-
localPreview = _context.sent;
|
|
90
|
-
return _context.abrupt("return", extendAndCachePreview(id, mode, _objectSpread(_objectSpread({}, localPreview), {}, {
|
|
91
|
-
dimensions: dimensions
|
|
92
|
-
}), mediaBlobUrlAttrs));
|
|
93
|
-
case 12:
|
|
94
|
-
_context.next = 19;
|
|
95
|
-
break;
|
|
96
|
-
case 14:
|
|
97
|
-
_context.prev = 14;
|
|
98
|
-
_context.t0 = _context["catch"](6);
|
|
99
|
-
/**
|
|
100
|
-
* We report the error if:
|
|
101
|
-
* - local preview is supported and fails
|
|
102
|
-
* - local preview is unsupported and remote preview is NOT READY
|
|
103
|
-
* i.e. the function was called for "no reason".
|
|
104
|
-
* We DON'T report the error if:
|
|
105
|
-
* - local preview is unsupported and remote preview IS READY
|
|
106
|
-
* i.e. local preview is available and not supported,
|
|
107
|
-
* but we are after the remote preview instead.
|
|
108
|
-
*/
|
|
109
|
-
if (!isUnsupportedLocalPreviewError(_context.t0) || isUnsupportedLocalPreviewError(_context.t0) && !isRemotePreviewReady) {
|
|
110
|
-
onLocalPreviewError && onLocalPreviewError(_context.t0);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* No matter the reason why the local preview failed, we break the process
|
|
114
|
-
* if there is no remote preview available
|
|
115
|
-
*/
|
|
116
|
-
if (isRemotePreviewReady) {
|
|
117
|
-
_context.next = 19;
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
throw _context.t0;
|
|
121
|
-
case 19:
|
|
122
|
-
if (isRemotePreviewReady) {
|
|
123
|
-
_context.next = 21;
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
throw new MediaCardError('remote-preview-not-ready');
|
|
127
|
-
case 21:
|
|
128
|
-
_context.next = 23;
|
|
129
|
-
return fetchAndCacheRemotePreview(mediaClient, id, dimensions, imageUrlParams, mediaBlobUrlAttrs, traceContext);
|
|
130
|
-
case 23:
|
|
131
|
-
remotePreview = _context.sent;
|
|
132
|
-
return _context.abrupt("return", remotePreview);
|
|
133
|
-
case 25:
|
|
134
|
-
case "end":
|
|
135
|
-
return _context.stop();
|
|
136
|
-
}
|
|
137
|
-
}, _callee, null, [[6, 14]]);
|
|
138
|
-
}));
|
|
139
|
-
return function getCardPreview(_x) {
|
|
140
|
-
return _ref2.apply(this, arguments);
|
|
141
|
-
};
|
|
142
|
-
}();
|
|
143
|
-
export var shouldResolvePreview = function shouldResolvePreview(_ref3) {
|
|
144
|
-
var status = _ref3.status,
|
|
145
|
-
fileState = _ref3.fileState,
|
|
146
|
-
prevDimensions = _ref3.prevDimensions,
|
|
147
|
-
dimensions = _ref3.dimensions,
|
|
148
|
-
hasCardPreview = _ref3.hasCardPreview,
|
|
149
|
-
isBannedLocalPreview = _ref3.isBannedLocalPreview,
|
|
150
|
-
wasResolvedUpfrontPreview = _ref3.wasResolvedUpfrontPreview;
|
|
151
|
-
var statusIsPreviewable = isPreviewableStatus(status, extractFilePreviewStatus(fileState, isBannedLocalPreview));
|
|
152
|
-
var dimensionsAreBigger = isBigger(prevDimensions, dimensions);
|
|
153
|
-
// We should not fetch the preview if the upfront one hasn't been resolved yet (it could be resolving now), even if there are new dimensions.
|
|
154
|
-
return wasResolvedUpfrontPreview && statusIsPreviewable && (!hasCardPreview || dimensionsAreBigger);
|
|
155
|
-
};
|
|
156
|
-
export var getSSRCardPreview = function getSSRCardPreview(ssr, mediaClient, id, params, mediaBlobUrlAttrs) {
|
|
157
|
-
var dataURI;
|
|
158
|
-
try {
|
|
159
|
-
var rawDataURI = mediaClient.getImageUrlSync(id, params);
|
|
160
|
-
// We want to embed some meta context into dataURI for Copy/Paste to work.
|
|
161
|
-
dataURI = mediaBlobUrlAttrs ? addFileAttrsToUrl(rawDataURI, mediaBlobUrlAttrs) : rawDataURI;
|
|
162
|
-
var source = ssr === 'client' ? 'ssr-client' : 'ssr-server';
|
|
163
|
-
return {
|
|
164
|
-
dataURI: dataURI,
|
|
165
|
-
source: source,
|
|
166
|
-
orientation: 1
|
|
167
|
-
};
|
|
168
|
-
} catch (e) {
|
|
169
|
-
var reason = ssr === 'server' ? 'ssr-server-uri' : 'ssr-client-uri';
|
|
170
|
-
throw new SsrPreviewError(reason, e instanceof Error ? e : undefined);
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
export var isLocalPreview = function isLocalPreview(preview) {
|
|
174
|
-
var localSources = ['local', 'cache-local'];
|
|
175
|
-
return localSources.includes(preview.source);
|
|
176
|
-
};
|
|
177
|
-
export var isSSRPreview = function isSSRPreview(preview) {
|
|
178
|
-
return isSSRClientPreview(preview) || isSSRServerPreview(preview) || isSSRDataPreview(preview);
|
|
179
|
-
};
|
|
180
|
-
export var isSSRServerPreview = function isSSRServerPreview(preview) {
|
|
181
|
-
var ssrClientSources = ['ssr-server', 'cache-ssr-server'];
|
|
182
|
-
return ssrClientSources.includes(preview.source);
|
|
183
|
-
};
|
|
184
|
-
export var isSSRClientPreview = function isSSRClientPreview(preview) {
|
|
185
|
-
var ssrClientSources = ['ssr-client', 'cache-ssr-client'];
|
|
186
|
-
return ssrClientSources.includes(preview.source);
|
|
187
|
-
};
|
|
188
|
-
export var isSSRDataPreview = function isSSRDataPreview(preview) {
|
|
189
|
-
return preview.source === 'ssr-data';
|
|
190
|
-
};
|
|
191
|
-
export var fetchAndCacheRemotePreview = /*#__PURE__*/function () {
|
|
192
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(mediaClient, id, dimensions, params, mediaBlobUrlAttrs, traceContext) {
|
|
193
|
-
var remotePreview;
|
|
194
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
195
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
196
|
-
case 0:
|
|
197
|
-
_context2.next = 2;
|
|
198
|
-
return getCardPreviewFromBackend(mediaClient, id, params, traceContext);
|
|
199
|
-
case 2:
|
|
200
|
-
remotePreview = _context2.sent;
|
|
201
|
-
return _context2.abrupt("return", extendAndCachePreview(id, params.mode, _objectSpread(_objectSpread({}, remotePreview), {}, {
|
|
202
|
-
dimensions: dimensions
|
|
203
|
-
}), mediaBlobUrlAttrs));
|
|
204
|
-
case 4:
|
|
205
|
-
case "end":
|
|
206
|
-
return _context2.stop();
|
|
207
|
-
}
|
|
208
|
-
}, _callee2);
|
|
209
|
-
}));
|
|
210
|
-
return function fetchAndCacheRemotePreview(_x2, _x3, _x4, _x5, _x6, _x7) {
|
|
211
|
-
return _ref4.apply(this, arguments);
|
|
212
|
-
};
|
|
213
|
-
}();
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type FileState } from '@atlaskit/media-client';
|
|
2
|
-
import { type CardState } from '../types';
|
|
3
|
-
import { MediaCardError } from '../errors';
|
|
4
|
-
/**
|
|
5
|
-
* From docs: "Both state and props received by the updater function are guaranteed to be up-to-date.
|
|
6
|
-
* The output of the updater is shallowly merged with state."
|
|
7
|
-
*/
|
|
8
|
-
export declare const createStateUpdater: (newState: Partial<CardState>, fireErrorEvent: (error: MediaCardError) => void) => (prevState: CardState) => Partial<CardState>;
|
|
9
|
-
export declare const getCardStateFromFileState: (fileState: FileState, isBannedLocalPreview: boolean) => Partial<CardState>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type ImageResizeMode } from '@atlaskit/media-client';
|
|
2
|
-
import { type ObjectURLCache } from '../../utils/objectURLCache';
|
|
3
|
-
import { type CardPreview } from '../../types';
|
|
4
|
-
type Mode = ImageResizeMode | undefined;
|
|
5
|
-
export declare const getCacheKey: (id: string, mode: Mode) => string;
|
|
6
|
-
export interface CardPreviewCache {
|
|
7
|
-
get(id: string, mode: Mode): CardPreview | undefined;
|
|
8
|
-
set(id: string, mode: Mode, cardPreview: CardPreview): void;
|
|
9
|
-
remove(id: string, mode: Mode): void;
|
|
10
|
-
clear(): void;
|
|
11
|
-
}
|
|
12
|
-
export declare class CardPreviewCacheImpl implements CardPreviewCache {
|
|
13
|
-
private previewCache;
|
|
14
|
-
constructor(previewCache: ObjectURLCache);
|
|
15
|
-
get: (id: string, mode: Mode) => CardPreview | undefined;
|
|
16
|
-
set: (id: string, mode: Mode, cardPreview: CardPreview) => void;
|
|
17
|
-
remove: (id: string, mode: Mode) => void;
|
|
18
|
-
clear: () => void;
|
|
19
|
-
}
|
|
20
|
-
declare const _default: CardPreviewCacheImpl;
|
|
21
|
-
export default _default;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type CardStatus, type FilePreviewStatus } from '../../types';
|
|
2
|
-
import { type FileState } from '@atlaskit/media-client';
|
|
3
|
-
export declare const extractFilePreviewStatus: (fileState: FileState, isBannedLocalPreview: boolean) => FilePreviewStatus;
|
|
4
|
-
export declare const isPreviewableStatus: (cardStatus: CardStatus, { isPreviewable, hasPreview, isSupportedByBrowser }: FilePreviewStatus) => boolean;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type MediaClient, type FilePreview, type MediaStoreGetFileImageParams, type MediaType } from '@atlaskit/media-client';
|
|
2
|
-
import { type MediaTraceContext } from '@atlaskit/media-common';
|
|
3
|
-
import { type CardPreview } from '../../types';
|
|
4
|
-
/**
|
|
5
|
-
* This method tells the support for the media
|
|
6
|
-
* types covered in getCardPreviewFromFilePreview
|
|
7
|
-
*/
|
|
8
|
-
export declare const isSupportedLocalPreview: (mediaType?: MediaType) => boolean;
|
|
9
|
-
export declare const getCardPreviewFromFilePreview: (filePreview: FilePreview | Promise<FilePreview>) => Promise<CardPreview>;
|
|
10
|
-
export declare const getCardPreviewFromBackend: (mediaClient: MediaClient, id: string, params: MediaStoreGetFileImageParams, traceContext?: MediaTraceContext) => Promise<CardPreview>;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { type MediaClient, type FilePreview, type FileState, type MediaStoreGetFileImageParams, type MediaBlobUrlAttrs } from '@atlaskit/media-client';
|
|
2
|
-
import { type SSR, type MediaTraceContext } from '@atlaskit/media-common';
|
|
3
|
-
import { type ImageResizeMode } from '@atlaskit/media-client';
|
|
4
|
-
import { type CardDimensions } from '../../types';
|
|
5
|
-
import { MediaCardError } from '../../errors';
|
|
6
|
-
import { type CardStatus, type CardPreview } from '../../types';
|
|
7
|
-
export { getCardPreviewFromFilePreview, getCardPreviewFromBackend, isSupportedLocalPreview, } from './helpers';
|
|
8
|
-
export { extractFilePreviewStatus } from './filePreviewStatus';
|
|
9
|
-
export declare const getCardPreviewFromCache: (id: string, mode: ImageResizeMode | undefined) => CardPreview | undefined;
|
|
10
|
-
export declare const removeCardPreviewFromCache: (id: string, mode: ImageResizeMode | undefined) => void;
|
|
11
|
-
/**
|
|
12
|
-
* Will return the preview if available and supported by the browser
|
|
13
|
-
* See extractFilePreviewStatus "hasLocalPreview" logic
|
|
14
|
-
*/
|
|
15
|
-
export declare const getFilePreviewFromFileState: (fileState: FileState) => FilePreview | Promise<FilePreview> | undefined;
|
|
16
|
-
export type CardPreviewParams = {
|
|
17
|
-
mediaClient: MediaClient;
|
|
18
|
-
id: string;
|
|
19
|
-
dimensions?: CardDimensions;
|
|
20
|
-
filePreview?: FilePreview | Promise<FilePreview>;
|
|
21
|
-
onLocalPreviewError: (error: MediaCardError) => void;
|
|
22
|
-
isRemotePreviewReady: boolean;
|
|
23
|
-
imageUrlParams: MediaStoreGetFileImageParams;
|
|
24
|
-
mediaBlobUrlAttrs?: MediaBlobUrlAttrs;
|
|
25
|
-
traceContext?: MediaTraceContext;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* This function will try to return a Card preview, either from cache, local preview or remote preview.
|
|
29
|
-
* It should only be called if there is a chance to get either a remote or a local preview, or both.
|
|
30
|
-
* This, in order to ensure there is always going to be a valid return value OR throw an error if the process fails.
|
|
31
|
-
* It is worth noting that local preview failures break the process if there is no remote preview available.
|
|
32
|
-
* In that case we throw an error immediately.
|
|
33
|
-
* Otherwise, if the local preview fails but there is a remote preview available, the failure does not break the process.
|
|
34
|
-
* In that case, we still want to report the local preview error to the caller, for feature realiability track.
|
|
35
|
-
* hence the use of the optional callback onLocalPreviewError
|
|
36
|
-
*/
|
|
37
|
-
export declare const getCardPreview: ({ mediaClient, id, dimensions, filePreview, onLocalPreviewError, isRemotePreviewReady, imageUrlParams, mediaBlobUrlAttrs, traceContext, }: CardPreviewParams) => Promise<CardPreview>;
|
|
38
|
-
export declare const shouldResolvePreview: ({ status, fileState, prevDimensions, dimensions, hasCardPreview, isBannedLocalPreview, wasResolvedUpfrontPreview, }: {
|
|
39
|
-
status: CardStatus;
|
|
40
|
-
fileState: FileState;
|
|
41
|
-
prevDimensions?: CardDimensions | undefined;
|
|
42
|
-
dimensions?: CardDimensions | undefined;
|
|
43
|
-
hasCardPreview: boolean;
|
|
44
|
-
isBannedLocalPreview: boolean;
|
|
45
|
-
wasResolvedUpfrontPreview: boolean;
|
|
46
|
-
}) => boolean;
|
|
47
|
-
export declare const getSSRCardPreview: (ssr: SSR, mediaClient: MediaClient, id: string, params: MediaStoreGetFileImageParams, mediaBlobUrlAttrs?: MediaBlobUrlAttrs) => CardPreview;
|
|
48
|
-
export declare const isLocalPreview: (preview: CardPreview) => boolean;
|
|
49
|
-
export declare const isSSRPreview: (preview: CardPreview) => boolean;
|
|
50
|
-
export declare const isSSRServerPreview: (preview: CardPreview) => boolean;
|
|
51
|
-
export declare const isSSRClientPreview: (preview: CardPreview) => boolean;
|
|
52
|
-
export declare const isSSRDataPreview: (preview: CardPreview) => boolean;
|
|
53
|
-
export declare const fetchAndCacheRemotePreview: (mediaClient: MediaClient, id: string, dimensions: CardDimensions, params: MediaStoreGetFileImageParams, mediaBlobUrlAttrs?: MediaBlobUrlAttrs, traceContext?: MediaTraceContext) => Promise<CardPreview>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type FileState } from '@atlaskit/media-client';
|
|
2
|
-
import { type CardState } from '../types';
|
|
3
|
-
import { MediaCardError } from '../errors';
|
|
4
|
-
/**
|
|
5
|
-
* From docs: "Both state and props received by the updater function are guaranteed to be up-to-date.
|
|
6
|
-
* The output of the updater is shallowly merged with state."
|
|
7
|
-
*/
|
|
8
|
-
export declare const createStateUpdater: (newState: Partial<CardState>, fireErrorEvent: (error: MediaCardError) => void) => (prevState: CardState) => Partial<CardState>;
|
|
9
|
-
export declare const getCardStateFromFileState: (fileState: FileState, isBannedLocalPreview: boolean) => Partial<CardState>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type ImageResizeMode } from '@atlaskit/media-client';
|
|
2
|
-
import { type ObjectURLCache } from '../../utils/objectURLCache';
|
|
3
|
-
import { type CardPreview } from '../../types';
|
|
4
|
-
type Mode = ImageResizeMode | undefined;
|
|
5
|
-
export declare const getCacheKey: (id: string, mode: Mode) => string;
|
|
6
|
-
export interface CardPreviewCache {
|
|
7
|
-
get(id: string, mode: Mode): CardPreview | undefined;
|
|
8
|
-
set(id: string, mode: Mode, cardPreview: CardPreview): void;
|
|
9
|
-
remove(id: string, mode: Mode): void;
|
|
10
|
-
clear(): void;
|
|
11
|
-
}
|
|
12
|
-
export declare class CardPreviewCacheImpl implements CardPreviewCache {
|
|
13
|
-
private previewCache;
|
|
14
|
-
constructor(previewCache: ObjectURLCache);
|
|
15
|
-
get: (id: string, mode: Mode) => CardPreview | undefined;
|
|
16
|
-
set: (id: string, mode: Mode, cardPreview: CardPreview) => void;
|
|
17
|
-
remove: (id: string, mode: Mode) => void;
|
|
18
|
-
clear: () => void;
|
|
19
|
-
}
|
|
20
|
-
declare const _default: CardPreviewCacheImpl;
|
|
21
|
-
export default _default;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type CardStatus, type FilePreviewStatus } from '../../types';
|
|
2
|
-
import { type FileState } from '@atlaskit/media-client';
|
|
3
|
-
export declare const extractFilePreviewStatus: (fileState: FileState, isBannedLocalPreview: boolean) => FilePreviewStatus;
|
|
4
|
-
export declare const isPreviewableStatus: (cardStatus: CardStatus, { isPreviewable, hasPreview, isSupportedByBrowser }: FilePreviewStatus) => boolean;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type MediaClient, type FilePreview, type MediaStoreGetFileImageParams, type MediaType } from '@atlaskit/media-client';
|
|
2
|
-
import { type MediaTraceContext } from '@atlaskit/media-common';
|
|
3
|
-
import { type CardPreview } from '../../types';
|
|
4
|
-
/**
|
|
5
|
-
* This method tells the support for the media
|
|
6
|
-
* types covered in getCardPreviewFromFilePreview
|
|
7
|
-
*/
|
|
8
|
-
export declare const isSupportedLocalPreview: (mediaType?: MediaType) => boolean;
|
|
9
|
-
export declare const getCardPreviewFromFilePreview: (filePreview: FilePreview | Promise<FilePreview>) => Promise<CardPreview>;
|
|
10
|
-
export declare const getCardPreviewFromBackend: (mediaClient: MediaClient, id: string, params: MediaStoreGetFileImageParams, traceContext?: MediaTraceContext) => Promise<CardPreview>;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { type MediaClient, type FilePreview, type FileState, type MediaStoreGetFileImageParams, type MediaBlobUrlAttrs } from '@atlaskit/media-client';
|
|
2
|
-
import { type SSR, type MediaTraceContext } from '@atlaskit/media-common';
|
|
3
|
-
import { type ImageResizeMode } from '@atlaskit/media-client';
|
|
4
|
-
import { type CardDimensions } from '../../types';
|
|
5
|
-
import { MediaCardError } from '../../errors';
|
|
6
|
-
import { type CardStatus, type CardPreview } from '../../types';
|
|
7
|
-
export { getCardPreviewFromFilePreview, getCardPreviewFromBackend, isSupportedLocalPreview, } from './helpers';
|
|
8
|
-
export { extractFilePreviewStatus } from './filePreviewStatus';
|
|
9
|
-
export declare const getCardPreviewFromCache: (id: string, mode: ImageResizeMode | undefined) => CardPreview | undefined;
|
|
10
|
-
export declare const removeCardPreviewFromCache: (id: string, mode: ImageResizeMode | undefined) => void;
|
|
11
|
-
/**
|
|
12
|
-
* Will return the preview if available and supported by the browser
|
|
13
|
-
* See extractFilePreviewStatus "hasLocalPreview" logic
|
|
14
|
-
*/
|
|
15
|
-
export declare const getFilePreviewFromFileState: (fileState: FileState) => FilePreview | Promise<FilePreview> | undefined;
|
|
16
|
-
export type CardPreviewParams = {
|
|
17
|
-
mediaClient: MediaClient;
|
|
18
|
-
id: string;
|
|
19
|
-
dimensions?: CardDimensions;
|
|
20
|
-
filePreview?: FilePreview | Promise<FilePreview>;
|
|
21
|
-
onLocalPreviewError: (error: MediaCardError) => void;
|
|
22
|
-
isRemotePreviewReady: boolean;
|
|
23
|
-
imageUrlParams: MediaStoreGetFileImageParams;
|
|
24
|
-
mediaBlobUrlAttrs?: MediaBlobUrlAttrs;
|
|
25
|
-
traceContext?: MediaTraceContext;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* This function will try to return a Card preview, either from cache, local preview or remote preview.
|
|
29
|
-
* It should only be called if there is a chance to get either a remote or a local preview, or both.
|
|
30
|
-
* This, in order to ensure there is always going to be a valid return value OR throw an error if the process fails.
|
|
31
|
-
* It is worth noting that local preview failures break the process if there is no remote preview available.
|
|
32
|
-
* In that case we throw an error immediately.
|
|
33
|
-
* Otherwise, if the local preview fails but there is a remote preview available, the failure does not break the process.
|
|
34
|
-
* In that case, we still want to report the local preview error to the caller, for feature realiability track.
|
|
35
|
-
* hence the use of the optional callback onLocalPreviewError
|
|
36
|
-
*/
|
|
37
|
-
export declare const getCardPreview: ({ mediaClient, id, dimensions, filePreview, onLocalPreviewError, isRemotePreviewReady, imageUrlParams, mediaBlobUrlAttrs, traceContext, }: CardPreviewParams) => Promise<CardPreview>;
|
|
38
|
-
export declare const shouldResolvePreview: ({ status, fileState, prevDimensions, dimensions, hasCardPreview, isBannedLocalPreview, wasResolvedUpfrontPreview, }: {
|
|
39
|
-
status: CardStatus;
|
|
40
|
-
fileState: FileState;
|
|
41
|
-
prevDimensions?: CardDimensions | undefined;
|
|
42
|
-
dimensions?: CardDimensions | undefined;
|
|
43
|
-
hasCardPreview: boolean;
|
|
44
|
-
isBannedLocalPreview: boolean;
|
|
45
|
-
wasResolvedUpfrontPreview: boolean;
|
|
46
|
-
}) => boolean;
|
|
47
|
-
export declare const getSSRCardPreview: (ssr: SSR, mediaClient: MediaClient, id: string, params: MediaStoreGetFileImageParams, mediaBlobUrlAttrs?: MediaBlobUrlAttrs) => CardPreview;
|
|
48
|
-
export declare const isLocalPreview: (preview: CardPreview) => boolean;
|
|
49
|
-
export declare const isSSRPreview: (preview: CardPreview) => boolean;
|
|
50
|
-
export declare const isSSRServerPreview: (preview: CardPreview) => boolean;
|
|
51
|
-
export declare const isSSRClientPreview: (preview: CardPreview) => boolean;
|
|
52
|
-
export declare const isSSRDataPreview: (preview: CardPreview) => boolean;
|
|
53
|
-
export declare const fetchAndCacheRemotePreview: (mediaClient: MediaClient, id: string, dimensions: CardDimensions, params: MediaStoreGetFileImageParams, mediaBlobUrlAttrs?: MediaBlobUrlAttrs, traceContext?: MediaTraceContext) => Promise<CardPreview>;
|