@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
|
@@ -57,22 +57,18 @@ var _getCardPreview = require("./getCardPreview");
|
|
|
57
57
|
|
|
58
58
|
var _metadata = require("../../utils/metadata");
|
|
59
59
|
|
|
60
|
-
var _dimensionComparer = require("../../utils/dimensionComparer");
|
|
61
|
-
|
|
62
|
-
var _objectURLCache = require("../../utils/objectURLCache");
|
|
63
|
-
|
|
64
|
-
var _getCardStatus = require("./getCardStatus");
|
|
65
|
-
|
|
66
60
|
var _inlinePlayer = require("../inlinePlayer");
|
|
67
61
|
|
|
68
62
|
var _analytics = require("../../utils/analytics");
|
|
69
63
|
|
|
70
|
-
var _fileAttributesContext = require("../../utils/fileAttributesContext");
|
|
71
|
-
|
|
72
64
|
var _errors = require("../../errors");
|
|
73
65
|
|
|
74
66
|
var _cardAnalytics = require("./cardAnalytics");
|
|
75
67
|
|
|
68
|
+
var _document = _interopRequireDefault(require("../../utils/document"));
|
|
69
|
+
|
|
70
|
+
var _cardState = require("./cardState");
|
|
71
|
+
|
|
76
72
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
77
73
|
|
|
78
74
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -85,154 +81,186 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
85
81
|
|
|
86
82
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
87
83
|
|
|
88
|
-
var cardPreviewCache = (0, _objectURLCache.createObjectURLCache)();
|
|
89
|
-
|
|
90
84
|
var CardBase = /*#__PURE__*/function (_Component) {
|
|
91
85
|
(0, _inherits2.default)(CardBase, _Component);
|
|
92
86
|
|
|
93
87
|
var _super = _createSuper(CardBase);
|
|
94
88
|
|
|
89
|
+
// We initialise timeElapsedTillCommenced
|
|
90
|
+
// to avoid extra branching on a possibly undefined value.
|
|
95
91
|
function CardBase(props) {
|
|
96
92
|
var _this;
|
|
97
93
|
|
|
98
94
|
(0, _classCallCheck2.default)(this, CardBase);
|
|
99
95
|
_this = _super.call(this, props);
|
|
100
96
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "hasBeenMounted", false);
|
|
101
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getPreviewCacheKey", function (id, dimensions) {
|
|
112
|
-
// Dimensions are used to create a key.
|
|
113
|
-
// Cache is invalidated when different dimensions are provided.
|
|
114
|
-
return [id, dimensions.height, dimensions.width].join('-');
|
|
97
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "timeElapsedTillCommenced", performance.now());
|
|
98
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getImageURLParams", function (_ref) {
|
|
99
|
+
var collection = _ref.collectionName;
|
|
100
|
+
return _objectSpread(_objectSpread({
|
|
101
|
+
collection: collection,
|
|
102
|
+
mode: (0, _mediaClient.imageResizeModeToFileImageMode)(_this.props.resizeMode)
|
|
103
|
+
}, _this.requestedDimensions), {}, {
|
|
104
|
+
allowAnimated: true
|
|
105
|
+
});
|
|
115
106
|
});
|
|
116
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
107
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getMediaBlobUrlAttrs", function (identifier, fileState) {
|
|
108
|
+
var id = identifier.id,
|
|
109
|
+
collection = identifier.collectionName;
|
|
110
|
+
var _this$props = _this.props,
|
|
111
|
+
originalDimensions = _this$props.originalDimensions,
|
|
112
|
+
contextId = _this$props.contextId,
|
|
113
|
+
alt = _this$props.alt;
|
|
114
|
+
|
|
115
|
+
var _getFileDetails = (0, _metadata.getFileDetails)(identifier, fileState),
|
|
116
|
+
mimeType = _getFileDetails.mimeType,
|
|
117
|
+
name = _getFileDetails.name,
|
|
118
|
+
size = _getFileDetails.size;
|
|
119
|
+
|
|
120
|
+
return contextId ? _objectSpread(_objectSpread({
|
|
121
|
+
id: id,
|
|
122
|
+
collection: collection,
|
|
123
|
+
contextId: contextId,
|
|
124
|
+
mimeType: mimeType,
|
|
125
|
+
name: name,
|
|
126
|
+
size: size
|
|
127
|
+
}, originalDimensions || _this.requestedDimensions), {}, {
|
|
128
|
+
alt: alt
|
|
129
|
+
}) : undefined;
|
|
122
130
|
});
|
|
123
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "
|
|
124
|
-
|
|
131
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getCardPreviewParams", function (identifier, fileState) {
|
|
132
|
+
var isBannedLocalPreview = _this.state.isBannedLocalPreview;
|
|
133
|
+
var id = identifier.id;
|
|
134
|
+
var _this$props2 = _this.props,
|
|
135
|
+
_this$props2$dimensio = _this$props2.dimensions,
|
|
136
|
+
dimensions = _this$props2$dimensio === void 0 ? {} : _this$props2$dimensio,
|
|
137
|
+
mediaClient = _this$props2.mediaClient;
|
|
138
|
+
return {
|
|
139
|
+
mediaClient: mediaClient,
|
|
140
|
+
id: id,
|
|
141
|
+
dimensions: dimensions,
|
|
142
|
+
onLocalPreviewError: _this.fireLocalPreviewErrorEvent,
|
|
143
|
+
filePreview: isBannedLocalPreview ? undefined : (0, _getCardPreview.getFilePreviewFromFileState)(fileState),
|
|
144
|
+
isRemotePreviewReady: (0, _mediaClient.isImageRepresentationReady)(fileState),
|
|
145
|
+
imageUrlParams: _this.getImageURLParams(identifier),
|
|
146
|
+
mediaBlobUrlAttrs: _this.getMediaBlobUrlAttrs(identifier, fileState)
|
|
147
|
+
};
|
|
125
148
|
});
|
|
126
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "
|
|
127
|
-
var
|
|
128
|
-
var
|
|
129
|
-
|
|
149
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "resolvePreview", /*#__PURE__*/function () {
|
|
150
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(identifier, fileState) {
|
|
151
|
+
var params, cardPreview, wrappedError;
|
|
130
152
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
131
153
|
while (1) {
|
|
132
154
|
switch (_context.prev = _context.next) {
|
|
133
155
|
case 0:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
_context.next = 15;
|
|
169
|
-
return (0, _getCardPreview.getCardPreviewFromFileState)(fileState);
|
|
170
|
-
|
|
171
|
-
case 15:
|
|
172
|
-
_context.t1 = _context.sent;
|
|
173
|
-
|
|
174
|
-
case 16:
|
|
175
|
-
_context.t0 = _context.t1;
|
|
176
|
-
|
|
177
|
-
if (_context.t0) {
|
|
178
|
-
_context.next = 24;
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
_context.t2 = previewableType;
|
|
183
|
-
|
|
184
|
-
if (!_context.t2) {
|
|
185
|
-
_context.next = 23;
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
_context.next = 22;
|
|
190
|
-
return (0, _getCardPreview.getCardPreviewFromBackend)(mediaClient, identifier, fileState, requestedDimensions, resizeMode);
|
|
191
|
-
|
|
192
|
-
case 22:
|
|
193
|
-
_context.t2 = _context.sent;
|
|
194
|
-
|
|
195
|
-
case 23:
|
|
196
|
-
_context.t0 = _context.t2;
|
|
197
|
-
|
|
198
|
-
case 24:
|
|
199
|
-
cardPreview = _context.t0;
|
|
200
|
-
|
|
201
|
-
if (!cardPreview) {
|
|
202
|
-
_context.next = 29;
|
|
203
|
-
break;
|
|
156
|
+
_context.prev = 0;
|
|
157
|
+
params = _this.getCardPreviewParams(identifier, fileState);
|
|
158
|
+
_context.next = 4;
|
|
159
|
+
return (0, _getCardPreview.getCardPreview)(params);
|
|
160
|
+
|
|
161
|
+
case 4:
|
|
162
|
+
cardPreview = _context.sent;
|
|
163
|
+
|
|
164
|
+
_this.safeSetState({
|
|
165
|
+
cardPreview: cardPreview
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
_context.next = 12;
|
|
169
|
+
break;
|
|
170
|
+
|
|
171
|
+
case 8:
|
|
172
|
+
_context.prev = 8;
|
|
173
|
+
_context.t0 = _context["catch"](0);
|
|
174
|
+
wrappedError = (0, _errors.ensureMediaCardError)('preview-fetch', _context.t0); // If remote preview fails, we set status 'error'
|
|
175
|
+
// If local preview fails (i.e, no remote preview available),
|
|
176
|
+
// we can stay in the same status until there is a remote preview available
|
|
177
|
+
// If it's any other error we set status 'error'
|
|
178
|
+
|
|
179
|
+
if ((0, _errors.isLocalPreviewError)(wrappedError)) {
|
|
180
|
+
_this.safeSetState({
|
|
181
|
+
isBannedLocalPreview: true
|
|
182
|
+
});
|
|
183
|
+
} else {
|
|
184
|
+
_this.safeSetState({
|
|
185
|
+
status: 'error',
|
|
186
|
+
error: wrappedError
|
|
187
|
+
});
|
|
204
188
|
}
|
|
205
189
|
|
|
206
|
-
|
|
207
|
-
// In case we've retrieved cardPreview using one of the two methods above,
|
|
208
|
-
// we want to embed some meta context into dataURI for Copy/Paste to work.
|
|
209
|
-
contextDimensions = originalDimensions || requestedDimensions;
|
|
210
|
-
cardPreview.dataURI = _this.addContextToDataURI(cardPreview.dataURI, id, metadata, contextDimensions, collectionName);
|
|
211
|
-
} // We store new cardPreview into cache
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
cardPreviewCache.set(cacheKey, cardPreview);
|
|
215
|
-
return _context.abrupt("return", cardPreview);
|
|
216
|
-
|
|
217
|
-
case 29:
|
|
190
|
+
case 12:
|
|
218
191
|
case "end":
|
|
219
192
|
return _context.stop();
|
|
220
193
|
}
|
|
221
194
|
}
|
|
222
|
-
}, _callee);
|
|
195
|
+
}, _callee, null, [[0, 8]]);
|
|
223
196
|
}));
|
|
224
197
|
|
|
225
|
-
return function (_x, _x2
|
|
226
|
-
return
|
|
198
|
+
return function (_x, _x2) {
|
|
199
|
+
return _ref2.apply(this, arguments);
|
|
227
200
|
};
|
|
228
201
|
}());
|
|
229
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "
|
|
202
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getPerformanceAttributes", function () {
|
|
203
|
+
var _assertThisInitialize = (0, _assertThisInitialized2.default)(_this),
|
|
204
|
+
timeElapsedTillCommenced = _assertThisInitialize.timeElapsedTillCommenced;
|
|
205
|
+
|
|
206
|
+
var timeElapsedTillEvent = performance.now();
|
|
207
|
+
var durationSinceCommenced = timeElapsedTillCommenced && timeElapsedTillEvent - timeElapsedTillCommenced;
|
|
208
|
+
return {
|
|
209
|
+
overall: {
|
|
210
|
+
durationSincePageStart: timeElapsedTillEvent,
|
|
211
|
+
durationSinceCommenced: durationSinceCommenced
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onImageError", function () {
|
|
216
|
+
var cardPreview = _this.state.cardPreview;
|
|
217
|
+
var error = new _errors.ImageLoadError(cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.source);
|
|
218
|
+
|
|
219
|
+
if (cardPreview !== null && cardPreview !== void 0 && cardPreview.source && ['local', 'cache-local'].includes(cardPreview.source)) {
|
|
220
|
+
var _this$props3 = _this.props,
|
|
221
|
+
identifier = _this$props3.identifier,
|
|
222
|
+
_this$props3$dimensio = _this$props3.dimensions,
|
|
223
|
+
dimensions = _this$props3$dimensio === void 0 ? {} : _this$props3$dimensio;
|
|
224
|
+
(0, _mediaClient.isFileIdentifier)(identifier) && (0, _getCardPreview.removeCardPreviewFromCache)(identifier.id, dimensions);
|
|
225
|
+
|
|
226
|
+
_this.safeSetState({
|
|
227
|
+
cardPreview: undefined,
|
|
228
|
+
isBannedLocalPreview: true
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
_this.fireLocalPreviewErrorEvent(error);
|
|
232
|
+
} else {
|
|
233
|
+
_this.safeSetState({
|
|
234
|
+
status: 'error',
|
|
235
|
+
error: error
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onImageLoad", function () {
|
|
240
|
+
_this.safeSetState({
|
|
241
|
+
previewDidRender: true
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "fireCopiedEvent", function () {
|
|
230
245
|
var createAnalyticsEvent = _this.props.createAnalyticsEvent;
|
|
231
|
-
|
|
246
|
+
var cardRef = _this.state.cardRef;
|
|
247
|
+
cardRef && createAnalyticsEvent && (0, _cardAnalytics.fireCopiedEvent)(createAnalyticsEvent, _this.metadata.id, cardRef);
|
|
248
|
+
});
|
|
249
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "fireScreenEvent", function () {
|
|
250
|
+
var createAnalyticsEvent = _this.props.createAnalyticsEvent;
|
|
251
|
+
createAnalyticsEvent && (0, _cardAnalytics.fireScreenEvent)(createAnalyticsEvent, _this.fileAttributes);
|
|
252
|
+
});
|
|
253
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "fireLocalPreviewErrorEvent", function (error) {// TODO: track local preview success rate
|
|
254
|
+
// https://product-fabric.atlassian.net/browse/MEX-774
|
|
232
255
|
});
|
|
233
256
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "safeSetState", function (state) {
|
|
234
257
|
if (_this.hasBeenMounted) {
|
|
235
|
-
|
|
258
|
+
// If it's setting the status, we need to use a state updater function,
|
|
259
|
+
// which ensures that no non-final status overrides a final status.
|
|
260
|
+
// If no status is set, we don't need a sate updater
|
|
261
|
+
var updater = !!state.status ? (0, _cardState.createStateUpdater)(state) : state;
|
|
262
|
+
|
|
263
|
+
_this.setState(updater);
|
|
236
264
|
}
|
|
237
265
|
});
|
|
238
266
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "unsubscribe", function () {
|
|
@@ -241,20 +269,21 @@ var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
241
269
|
}
|
|
242
270
|
|
|
243
271
|
if (_this.hasBeenMounted) {
|
|
272
|
+
// TODO MEX-788: add test for "do not remove the card preview when unsubscribing".
|
|
244
273
|
_this.setState({
|
|
245
|
-
|
|
274
|
+
isBannedLocalPreview: false
|
|
246
275
|
});
|
|
247
276
|
}
|
|
248
277
|
});
|
|
249
278
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCardViewClick", function (event, analyticsEvent) {
|
|
250
|
-
var _this$
|
|
251
|
-
identifier = _this$
|
|
252
|
-
useInlinePlayer = _this$
|
|
253
|
-
shouldOpenMediaViewer = _this$
|
|
279
|
+
var _this$props4 = _this.props,
|
|
280
|
+
identifier = _this$props4.identifier,
|
|
281
|
+
useInlinePlayer = _this$props4.useInlinePlayer,
|
|
282
|
+
shouldOpenMediaViewer = _this$props4.shouldOpenMediaViewer;
|
|
254
283
|
var cardPreview = _this.state.cardPreview;
|
|
255
284
|
|
|
256
|
-
var
|
|
257
|
-
metadata =
|
|
285
|
+
var _assertThisInitialize2 = (0, _assertThisInitialized2.default)(_this),
|
|
286
|
+
metadata = _assertThisInitialize2.metadata;
|
|
258
287
|
|
|
259
288
|
_this.onClick(event, analyticsEvent);
|
|
260
289
|
|
|
@@ -302,13 +331,13 @@ var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
302
331
|
});
|
|
303
332
|
});
|
|
304
333
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderInlinePlayer", function () {
|
|
305
|
-
var _this$
|
|
306
|
-
identifier = _this$
|
|
307
|
-
mediaClient = _this$
|
|
308
|
-
dimensions = _this$
|
|
309
|
-
selected = _this$
|
|
310
|
-
testId = _this$
|
|
311
|
-
originalDimensions = _this$
|
|
334
|
+
var _this$props5 = _this.props,
|
|
335
|
+
identifier = _this$props5.identifier,
|
|
336
|
+
mediaClient = _this$props5.mediaClient,
|
|
337
|
+
dimensions = _this$props5.dimensions,
|
|
338
|
+
selected = _this$props5.selected,
|
|
339
|
+
testId = _this$props5.testId,
|
|
340
|
+
originalDimensions = _this$props5.originalDimensions;
|
|
312
341
|
return /*#__PURE__*/_react.default.createElement(_inlinePlayer.InlinePlayer, {
|
|
313
342
|
mediaClient: mediaClient,
|
|
314
343
|
dimensions: dimensions,
|
|
@@ -348,12 +377,12 @@ var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
348
377
|
});
|
|
349
378
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderMediaViewer", function () {
|
|
350
379
|
var mediaViewerSelectedItem = _this.state.mediaViewerSelectedItem;
|
|
351
|
-
var _this$
|
|
352
|
-
mediaClient = _this$
|
|
353
|
-
identifier = _this$
|
|
354
|
-
mediaViewerDataSource = _this$
|
|
355
|
-
contextId = _this$
|
|
356
|
-
featureFlags = _this$
|
|
380
|
+
var _this$props6 = _this.props,
|
|
381
|
+
mediaClient = _this$props6.mediaClient,
|
|
382
|
+
identifier = _this$props6.identifier,
|
|
383
|
+
mediaViewerDataSource = _this$props6.mediaViewerDataSource,
|
|
384
|
+
contextId = _this$props6.contextId,
|
|
385
|
+
featureFlags = _this$props6.featureFlags;
|
|
357
386
|
|
|
358
387
|
if (!mediaViewerSelectedItem) {
|
|
359
388
|
return;
|
|
@@ -374,20 +403,20 @@ var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
374
403
|
}), document.body);
|
|
375
404
|
});
|
|
376
405
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderCard", function () {
|
|
377
|
-
var _this$
|
|
378
|
-
identifier = _this$
|
|
379
|
-
isLazy = _this$
|
|
380
|
-
appearance = _this$
|
|
381
|
-
resizeMode = _this$
|
|
382
|
-
dimensions = _this$
|
|
383
|
-
selectable = _this$
|
|
384
|
-
selected = _this$
|
|
385
|
-
disableOverlay = _this$
|
|
386
|
-
alt = _this$
|
|
387
|
-
testId = _this$
|
|
388
|
-
featureFlags = _this$
|
|
389
|
-
titleBoxBgColor = _this$
|
|
390
|
-
titleBoxIcon = _this$
|
|
406
|
+
var _this$props7 = _this.props,
|
|
407
|
+
identifier = _this$props7.identifier,
|
|
408
|
+
isLazy = _this$props7.isLazy,
|
|
409
|
+
appearance = _this$props7.appearance,
|
|
410
|
+
resizeMode = _this$props7.resizeMode,
|
|
411
|
+
dimensions = _this$props7.dimensions,
|
|
412
|
+
selectable = _this$props7.selectable,
|
|
413
|
+
selected = _this$props7.selected,
|
|
414
|
+
disableOverlay = _this$props7.disableOverlay,
|
|
415
|
+
alt = _this$props7.alt,
|
|
416
|
+
testId = _this$props7.testId,
|
|
417
|
+
featureFlags = _this$props7.featureFlags,
|
|
418
|
+
titleBoxBgColor = _this$props7.titleBoxBgColor,
|
|
419
|
+
titleBoxIcon = _this$props7.titleBoxIcon;
|
|
391
420
|
var mediaItemType = identifier.mediaItemType;
|
|
392
421
|
var _this$state = _this.state,
|
|
393
422
|
status = _this$state.status,
|
|
@@ -402,18 +431,18 @@ var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
402
431
|
error = _this$state.error,
|
|
403
432
|
cardRef = _this$state.cardRef;
|
|
404
433
|
|
|
405
|
-
var _assertThisInitialize2 = (0, _assertThisInitialized2.default)(_this),
|
|
406
|
-
metadata = _assertThisInitialize2.metadata;
|
|
407
|
-
|
|
408
434
|
var _assertThisInitialize3 = (0, _assertThisInitialized2.default)(_this),
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
435
|
+
metadata = _assertThisInitialize3.metadata;
|
|
436
|
+
|
|
437
|
+
var _assertThisInitialize4 = (0, _assertThisInitialized2.default)(_this),
|
|
438
|
+
onCardViewClick = _assertThisInitialize4.onCardViewClick,
|
|
439
|
+
onDisplayImage = _assertThisInitialize4.onDisplayImage,
|
|
440
|
+
actions = _assertThisInitialize4.actions,
|
|
441
|
+
onMouseEnter = _assertThisInitialize4.onMouseEnter;
|
|
413
442
|
|
|
414
443
|
var card = /*#__PURE__*/_react.default.createElement(_cardView.CardView, {
|
|
415
444
|
status: status,
|
|
416
|
-
error: error
|
|
445
|
+
error: error,
|
|
417
446
|
mediaItemType: mediaItemType,
|
|
418
447
|
metadata: metadata,
|
|
419
448
|
dataURI: dataURI,
|
|
@@ -434,7 +463,9 @@ var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
434
463
|
testId: testId,
|
|
435
464
|
featureFlags: featureFlags,
|
|
436
465
|
titleBoxBgColor: titleBoxBgColor,
|
|
437
|
-
titleBoxIcon: titleBoxIcon
|
|
466
|
+
titleBoxIcon: titleBoxIcon,
|
|
467
|
+
onImageError: _this.onImageError,
|
|
468
|
+
onImageLoad: _this.onImageLoad
|
|
438
469
|
});
|
|
439
470
|
|
|
440
471
|
return isLazy ? /*#__PURE__*/_react.default.createElement(_viewportDetector.ViewportDetector, {
|
|
@@ -450,8 +481,8 @@ var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
450
481
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onClick", function (event, analyticsEvent) {
|
|
451
482
|
var onClick = _this.props.onClick;
|
|
452
483
|
|
|
453
|
-
var
|
|
454
|
-
metadata =
|
|
484
|
+
var _assertThisInitialize5 = (0, _assertThisInitialized2.default)(_this),
|
|
485
|
+
metadata = _assertThisInitialize5.metadata;
|
|
455
486
|
|
|
456
487
|
if (onClick) {
|
|
457
488
|
var cardEvent = {
|
|
@@ -464,8 +495,8 @@ var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
464
495
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onMouseEnter", function (event) {
|
|
465
496
|
var onMouseEnter = _this.props.onMouseEnter;
|
|
466
497
|
|
|
467
|
-
var
|
|
468
|
-
metadata =
|
|
498
|
+
var _assertThisInitialize6 = (0, _assertThisInitialized2.default)(_this),
|
|
499
|
+
metadata = _assertThisInitialize6.metadata;
|
|
469
500
|
|
|
470
501
|
if (onMouseEnter) {
|
|
471
502
|
var cardEvent = {
|
|
@@ -475,48 +506,61 @@ var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
475
506
|
onMouseEnter(cardEvent);
|
|
476
507
|
}
|
|
477
508
|
});
|
|
509
|
+
var _status = 'loading';
|
|
478
510
|
|
|
479
511
|
var _cardPreview;
|
|
480
512
|
|
|
481
|
-
var _this$
|
|
482
|
-
_identifier = _this$
|
|
483
|
-
_this$
|
|
484
|
-
_dimensions = _this$
|
|
513
|
+
var _this$props8 = _this.props,
|
|
514
|
+
_identifier = _this$props8.identifier,
|
|
515
|
+
_this$props8$dimensio = _this$props8.dimensions,
|
|
516
|
+
_dimensions = _this$props8$dimensio === void 0 ? {} : _this$props8$dimensio;
|
|
485
517
|
|
|
486
518
|
if ((0, _mediaClient.isFileIdentifier)(_identifier)) {
|
|
487
519
|
var id = _identifier.id;
|
|
520
|
+
_cardPreview = (0, _getCardPreview.getCardPreviewFromCache)(id, _dimensions);
|
|
521
|
+
} else if ((0, _mediaClient.isExternalImageIdentifier)(_identifier)) {
|
|
522
|
+
_this.fireCommencedEvent();
|
|
488
523
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
_cardPreview =
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
524
|
+
_status = 'loading-preview';
|
|
525
|
+
var dataURI = _identifier.dataURI;
|
|
526
|
+
_cardPreview = {
|
|
527
|
+
dataURI: dataURI,
|
|
528
|
+
orientation: 1,
|
|
529
|
+
source: 'external'
|
|
530
|
+
};
|
|
531
|
+
} // If cardPreview is available from local cache, `isCardVisible`
|
|
532
|
+
// should be true to avoid flickers during re-mount of the component
|
|
497
533
|
|
|
498
534
|
|
|
535
|
+
var isCardVisible = _cardPreview ? true : !_this.props.isLazy;
|
|
499
536
|
_this.state = {
|
|
500
|
-
status:
|
|
501
|
-
isCardVisible:
|
|
537
|
+
status: _status,
|
|
538
|
+
isCardVisible: isCardVisible,
|
|
502
539
|
isPlayingFile: false,
|
|
503
540
|
cardPreview: _cardPreview,
|
|
504
|
-
cardRef: null
|
|
541
|
+
cardRef: null,
|
|
542
|
+
isBannedLocalPreview: false,
|
|
543
|
+
previewDidRender: false
|
|
505
544
|
};
|
|
506
545
|
return _this;
|
|
507
|
-
}
|
|
508
|
-
// and then check if the triggered listener is from the card
|
|
509
|
-
// that contains a div in current window.getSelection()
|
|
510
|
-
// won't work in IE11
|
|
511
|
-
|
|
546
|
+
}
|
|
512
547
|
|
|
513
548
|
(0, _createClass2.default)(CardBase, [{
|
|
514
549
|
key: "componentDidMount",
|
|
515
550
|
value: function componentDidMount() {
|
|
516
551
|
this.hasBeenMounted = true;
|
|
517
|
-
this.
|
|
518
|
-
this.
|
|
519
|
-
|
|
552
|
+
var isCardVisible = this.state.isCardVisible;
|
|
553
|
+
var identifier = this.props.identifier;
|
|
554
|
+
|
|
555
|
+
if (isCardVisible && (0, _mediaClient.isFileIdentifier)(identifier)) {
|
|
556
|
+
this.updateStateForIdentifier(identifier);
|
|
557
|
+
} // we add a listener for each of the cards on the page
|
|
558
|
+
// and then check if the triggered listener is from the card
|
|
559
|
+
// that contains a div in current window.getSelection()
|
|
560
|
+
// won't work in IE11
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
(0, _document.default)().addEventListener('copy', this.fireCopiedEvent);
|
|
520
564
|
}
|
|
521
565
|
}, {
|
|
522
566
|
key: "componentDidUpdate",
|
|
@@ -525,28 +569,66 @@ var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
525
569
|
prevIdentifier = prevProps.identifier,
|
|
526
570
|
prevDimensions = prevProps.dimensions;
|
|
527
571
|
var prevIsCardVisible = prevState.isCardVisible;
|
|
528
|
-
var _this$
|
|
529
|
-
mediaClient = _this$
|
|
530
|
-
identifier = _this$
|
|
531
|
-
dimensions = _this$
|
|
532
|
-
|
|
572
|
+
var _this$props9 = this.props,
|
|
573
|
+
mediaClient = _this$props9.mediaClient,
|
|
574
|
+
identifier = _this$props9.identifier,
|
|
575
|
+
dimensions = _this$props9.dimensions,
|
|
576
|
+
featureFlags = _this$props9.featureFlags;
|
|
577
|
+
var _this$state2 = this.state,
|
|
578
|
+
isCardVisible = _this$state2.isCardVisible,
|
|
579
|
+
cardPreview = _this$state2.cardPreview,
|
|
580
|
+
status = _this$state2.status,
|
|
581
|
+
fileState = _this$state2.fileState,
|
|
582
|
+
isBannedLocalPreview = _this$state2.isBannedLocalPreview,
|
|
583
|
+
previewDidRender = _this$state2.previewDidRender;
|
|
533
584
|
var isDifferent = (0, _mediaClient.isDifferentIdentifier)(prevIdentifier, identifier);
|
|
585
|
+
var turnedVisible = !prevIsCardVisible && isCardVisible;
|
|
586
|
+
var isNewMediaClient = prevMediaClient !== mediaClient;
|
|
534
587
|
|
|
535
|
-
if (
|
|
588
|
+
if ((0, _mediaClient.isExternalImageIdentifier)(identifier) && isDifferent) {
|
|
536
589
|
this.fireCommencedEvent();
|
|
537
|
-
|
|
590
|
+
var dataURI = identifier.dataURI;
|
|
591
|
+
this.setState({
|
|
592
|
+
status: 'loading-preview',
|
|
593
|
+
cardPreview: {
|
|
594
|
+
dataURI: dataURI,
|
|
595
|
+
orientation: 1,
|
|
596
|
+
source: 'external'
|
|
597
|
+
},
|
|
598
|
+
isCardVisible: true
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
if ((0, _mediaClient.isFileIdentifier)(identifier) && (turnedVisible || !!this.subscription && (isNewMediaClient || isDifferent))) {
|
|
603
|
+
this.updateStateForIdentifier(identifier);
|
|
538
604
|
}
|
|
539
605
|
|
|
540
606
|
if (this.state.status !== prevState.status) {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
607
|
+
this.fireOperationalEvent();
|
|
608
|
+
|
|
609
|
+
if (this.state.status === 'complete' || this.fileAttributes.fileMediatype === 'video' && !!cardPreview && this.state.status === 'processing') {
|
|
610
|
+
this.fireScreenEvent();
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
if ((0, _mediaClient.isFileIdentifier)(identifier) && fileState && (0, _getCardPreview.shouldResolvePreview)({
|
|
615
|
+
status: status,
|
|
616
|
+
fileState: fileState,
|
|
617
|
+
dimensions: dimensions,
|
|
618
|
+
prevDimensions: prevDimensions,
|
|
619
|
+
featureFlags: featureFlags,
|
|
620
|
+
hasCardPreview: !!cardPreview,
|
|
621
|
+
isBannedLocalPreview: isBannedLocalPreview
|
|
622
|
+
})) {
|
|
623
|
+
this.resolvePreview(identifier, fileState);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
if (previewDidRender && // We should't complete if status is uploading
|
|
627
|
+
['loading', 'loading-preview', 'processing'].includes(status)) {
|
|
628
|
+
this.safeSetState({
|
|
629
|
+
status: 'complete'
|
|
549
630
|
});
|
|
631
|
+
this.unsubscribe();
|
|
550
632
|
}
|
|
551
633
|
}
|
|
552
634
|
}, {
|
|
@@ -554,209 +636,89 @@ var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
554
636
|
value: function componentWillUnmount() {
|
|
555
637
|
this.hasBeenMounted = false;
|
|
556
638
|
this.unsubscribe();
|
|
557
|
-
|
|
639
|
+
(0, _document.default)().removeEventListener('copy', this.fireCopiedEvent);
|
|
558
640
|
}
|
|
559
641
|
}, {
|
|
560
642
|
key: "updateStateForIdentifier",
|
|
561
|
-
value: function updateStateForIdentifier() {
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
identifier = _this$props8.identifier;
|
|
565
|
-
var isCardVisible = this.state.isCardVisible;
|
|
566
|
-
|
|
567
|
-
if (!isCardVisible) {
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
if (identifier.mediaItemType === 'file') {
|
|
572
|
-
this.unsubscribe();
|
|
573
|
-
this.subscribeInternalFile(identifier, mediaClient);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
}, {
|
|
577
|
-
key: "getRequestedDimensions",
|
|
578
|
-
value: function getRequestedDimensions() {
|
|
579
|
-
var dimensions = this.props.dimensions;
|
|
580
|
-
var cardRef = this.state.cardRef;
|
|
581
|
-
var options = {
|
|
582
|
-
dimensions: dimensions,
|
|
583
|
-
element: cardRef
|
|
584
|
-
};
|
|
585
|
-
var width = (0, _getDataURIDimension.getDataURIDimension)('width', options);
|
|
586
|
-
var height = (0, _getDataURIDimension.getDataURIDimension)('height', options);
|
|
587
|
-
return {
|
|
588
|
-
width: width,
|
|
589
|
-
height: height
|
|
590
|
-
};
|
|
591
|
-
}
|
|
592
|
-
}, {
|
|
593
|
-
key: "addContextToDataURI",
|
|
594
|
-
value: function addContextToDataURI(dataURI, fileId, metadata, _ref2, collectionName) {
|
|
595
|
-
var width = _ref2.width,
|
|
596
|
-
height = _ref2.height;
|
|
597
|
-
var _this$props9 = this.props,
|
|
598
|
-
contextId = _this$props9.contextId,
|
|
599
|
-
alt = _this$props9.alt;
|
|
600
|
-
|
|
601
|
-
if (!contextId) {
|
|
602
|
-
return dataURI;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
return (0, _mediaClient.addFileAttrsToUrl)(dataURI, {
|
|
606
|
-
id: fileId,
|
|
607
|
-
collection: collectionName,
|
|
608
|
-
contextId: contextId,
|
|
609
|
-
mimeType: metadata.mimeType,
|
|
610
|
-
name: metadata.name,
|
|
611
|
-
size: metadata.size,
|
|
612
|
-
width: width,
|
|
613
|
-
height: height,
|
|
614
|
-
alt: alt
|
|
615
|
-
});
|
|
643
|
+
value: function updateStateForIdentifier(identifier) {
|
|
644
|
+
this.fireCommencedEvent();
|
|
645
|
+
this.subscribeInternalFile(identifier);
|
|
616
646
|
}
|
|
617
647
|
}, {
|
|
618
648
|
key: "subscribeInternalFile",
|
|
619
|
-
value: function subscribeInternalFile(identifier
|
|
649
|
+
value: function subscribeInternalFile(identifier) {
|
|
620
650
|
var _this2 = this;
|
|
621
651
|
|
|
652
|
+
var mediaClient = this.props.mediaClient;
|
|
653
|
+
var isBannedLocalPreview = this.state.isBannedLocalPreview;
|
|
622
654
|
var id = identifier.id,
|
|
623
655
|
collectionName = identifier.collectionName,
|
|
624
656
|
occurrenceKey = identifier.occurrenceKey;
|
|
657
|
+
this.unsubscribe();
|
|
625
658
|
this.subscription = mediaClient.file.getFileState(id, {
|
|
626
659
|
collectionName: collectionName,
|
|
627
660
|
occurrenceKey: occurrenceKey
|
|
628
661
|
}).subscribe({
|
|
629
|
-
next: function () {
|
|
630
|
-
var
|
|
631
|
-
|
|
632
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
633
|
-
while (1) {
|
|
634
|
-
switch (_context2.prev = _context2.next) {
|
|
635
|
-
case 0:
|
|
636
|
-
_this2.lastFileState = fileState;
|
|
637
|
-
thisCardStatusUpdateTimestamp = (performance || Date).now();
|
|
638
|
-
status = (0, _getCardStatus.getCardStatus)(fileState.status, (0, _getCardStatus.extractCardStatusParams)(fileState, _this2.props.featureFlags));
|
|
639
|
-
|
|
640
|
-
_this2.safeSetState({
|
|
641
|
-
fileState: fileState
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
_context2.prev = 4;
|
|
645
|
-
_context2.next = 7;
|
|
646
|
-
return _this2.getCardPreview(mediaClient, identifier, fileState, (0, _metadata.getFileDetails)(fileState));
|
|
647
|
-
|
|
648
|
-
case 7:
|
|
649
|
-
cardPreview = _context2.sent;
|
|
650
|
-
_context2.next = 14;
|
|
651
|
-
break;
|
|
652
|
-
|
|
653
|
-
case 10:
|
|
654
|
-
_context2.prev = 10;
|
|
655
|
-
_context2.t0 = _context2["catch"](4);
|
|
656
|
-
wrappedError = (0, _errors.ensureMediaCardError)('preview-fetch', _context2.t0); // If the local preview fails, we don't need to display the error.
|
|
657
|
-
// TODO: if file has local preview card will be complete status. But if the local preview fails,
|
|
658
|
-
// and we don't change the status, we will have
|
|
659
|
-
// [ !cardPreview && status == complete -> log succeeded event ]
|
|
660
|
-
// https://product-fabric.atlassian.net/browse/BMPT-1315
|
|
661
|
-
|
|
662
|
-
if (!(0, _errors.isLocalPreviewError)(wrappedError)) {
|
|
663
|
-
status = 'error';
|
|
664
|
-
error = wrappedError;
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
case 14:
|
|
668
|
-
if (_this2.isLatestCardStatusUpdate(thisCardStatusUpdateTimestamp)) {
|
|
669
|
-
// These status and progress must not override values representing more recent FileState
|
|
670
|
-
|
|
671
|
-
/* next() start some await() delay in next() status & progress update
|
|
672
|
-
* ------- ------------------ ------------------------
|
|
673
|
-
* |----[1]FileState:uploading------>| |
|
|
674
|
-
* | | |
|
|
675
|
-
* |----[2]FileState:uploading------>| |
|
|
676
|
-
* | | |
|
|
677
|
-
* | |----[2]FileState:uploading------>| Update status to `uploading`
|
|
678
|
-
* |----[3]FileState:processing----->| |
|
|
679
|
-
* | |----[3]FileState:processing----->| Update status to `complete`
|
|
680
|
-
* | | |
|
|
681
|
-
* | |----[1]FileState:uploading------>| We do not want to update status to `uploading` again!
|
|
682
|
-
*
|
|
683
|
-
*/
|
|
684
|
-
if (status === 'error' && (0, _mediaClient.isErrorFileState)(fileState) && !error) {
|
|
685
|
-
error = new _errors.MediaCardError('error-file-state', new Error(fileState.message));
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
_this2.safeSetState({
|
|
689
|
-
status: status,
|
|
690
|
-
cardPreview: cardPreview,
|
|
691
|
-
progress: status === 'uploading' && fileState.status === 'uploading' ? fileState.progress : 1,
|
|
692
|
-
error: status === 'error' && error ? error : undefined
|
|
693
|
-
});
|
|
694
|
-
|
|
695
|
-
_this2.lastCardStatusUpdateTimestamp = thisCardStatusUpdateTimestamp;
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
case 15:
|
|
699
|
-
case "end":
|
|
700
|
-
return _context2.stop();
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
}, _callee2, null, [[4, 10]]);
|
|
704
|
-
}));
|
|
705
|
-
|
|
706
|
-
function next(_x5) {
|
|
707
|
-
return _next.apply(this, arguments);
|
|
708
|
-
}
|
|
662
|
+
next: function next(fileState) {
|
|
663
|
+
var featureFlags = _this2.props.featureFlags;
|
|
664
|
+
var newState = (0, _cardState.getCardStateFromFileState)(fileState, isBannedLocalPreview, featureFlags);
|
|
709
665
|
|
|
710
|
-
|
|
711
|
-
}
|
|
666
|
+
_this2.safeSetState(newState);
|
|
667
|
+
},
|
|
712
668
|
error: function error(e) {
|
|
713
|
-
|
|
714
|
-
// and later there is an error, we won't change the card's status.
|
|
715
|
-
if (_this2.state.status === 'complete') {
|
|
716
|
-
return;
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
var errorReason = _this2.fileAttributes.fileStatus === 'uploading' ? 'upload' : 'metadata-fetch';
|
|
669
|
+
var errorReason = _this2.state.status === 'uploading' ? 'upload' : 'metadata-fetch';
|
|
720
670
|
var error = new _errors.MediaCardError(errorReason, e);
|
|
721
671
|
|
|
722
672
|
_this2.safeSetState({
|
|
723
673
|
error: error,
|
|
724
674
|
status: 'error'
|
|
725
675
|
});
|
|
726
|
-
|
|
727
|
-
_this2.lastCardStatusUpdateTimestamp = (performance || Date).now();
|
|
728
676
|
}
|
|
729
677
|
});
|
|
730
678
|
}
|
|
679
|
+
}, {
|
|
680
|
+
key: "requestedDimensions",
|
|
681
|
+
get: function get() {
|
|
682
|
+
var dimensions = this.props.dimensions;
|
|
683
|
+
var element = this.state.cardRef;
|
|
684
|
+
return (0, _getDataURIDimension.getRequestedDimensions)({
|
|
685
|
+
dimensions: dimensions,
|
|
686
|
+
element: element
|
|
687
|
+
});
|
|
688
|
+
}
|
|
731
689
|
}, {
|
|
732
690
|
key: "metadata",
|
|
733
691
|
get: function get() {
|
|
734
|
-
var
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
} : {
|
|
738
|
-
id: identifier.mediaItemType,
|
|
739
|
-
name: identifier.name || identifier.dataURI,
|
|
740
|
-
mediaType: 'image'
|
|
741
|
-
};
|
|
692
|
+
var _this$state3;
|
|
693
|
+
|
|
694
|
+
return (0, _metadata.getFileDetails)(this.props.identifier, (_this$state3 = this.state) === null || _this$state3 === void 0 ? void 0 : _this$state3.fileState);
|
|
742
695
|
}
|
|
743
696
|
}, {
|
|
744
697
|
key: "fileAttributes",
|
|
745
698
|
get: function get() {
|
|
746
|
-
var _this$
|
|
699
|
+
var _this$state4, _this$state4$fileStat;
|
|
747
700
|
|
|
748
|
-
return (0, _analytics.getFileAttributes)(this.metadata, (_this$
|
|
701
|
+
return (0, _analytics.getFileAttributes)(this.metadata, (_this$state4 = this.state) === null || _this$state4 === void 0 ? void 0 : (_this$state4$fileStat = _this$state4.fileState) === null || _this$state4$fileStat === void 0 ? void 0 : _this$state4$fileStat.status);
|
|
702
|
+
}
|
|
703
|
+
}, {
|
|
704
|
+
key: "fireOperationalEvent",
|
|
705
|
+
value: function fireOperationalEvent() {
|
|
706
|
+
var _this$state5 = this.state,
|
|
707
|
+
status = _this$state5.status,
|
|
708
|
+
error = _this$state5.error;
|
|
709
|
+
var createAnalyticsEvent = this.props.createAnalyticsEvent;
|
|
710
|
+
createAnalyticsEvent && (0, _cardAnalytics.fireOperationalEvent)(createAnalyticsEvent, status, this.fileAttributes, this.getPerformanceAttributes(), error);
|
|
749
711
|
}
|
|
750
712
|
}, {
|
|
751
713
|
key: "fireCommencedEvent",
|
|
752
714
|
value: function fireCommencedEvent() {
|
|
753
|
-
|
|
754
|
-
return;
|
|
755
|
-
}
|
|
756
|
-
|
|
715
|
+
this.timeElapsedTillCommenced = performance.now();
|
|
757
716
|
var createAnalyticsEvent = this.props.createAnalyticsEvent;
|
|
758
|
-
|
|
759
|
-
|
|
717
|
+
createAnalyticsEvent && (0, _cardAnalytics.fireCommencedEvent)(createAnalyticsEvent, this.fileAttributes, {
|
|
718
|
+
overall: {
|
|
719
|
+
durationSincePageStart: this.timeElapsedTillCommenced
|
|
720
|
+
}
|
|
721
|
+
});
|
|
760
722
|
}
|
|
761
723
|
}, {
|
|
762
724
|
key: "actions",
|
|
@@ -789,20 +751,15 @@ var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
789
751
|
}, {
|
|
790
752
|
key: "render",
|
|
791
753
|
value: function render() {
|
|
792
|
-
var _this$
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
isPlayingFile = _this$state3.isPlayingFile,
|
|
796
|
-
mediaViewerSelectedItem = _this$state3.mediaViewerSelectedItem;
|
|
754
|
+
var _this$state6 = this.state,
|
|
755
|
+
isPlayingFile = _this$state6.isPlayingFile,
|
|
756
|
+
mediaViewerSelectedItem = _this$state6.mediaViewerSelectedItem;
|
|
797
757
|
|
|
798
758
|
var innerContent = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isPlayingFile ? this.renderInlinePlayer() : this.renderCard(), mediaViewerSelectedItem ? this.renderMediaViewer() : null);
|
|
799
759
|
|
|
800
|
-
|
|
760
|
+
return this.context.intl ? innerContent : /*#__PURE__*/_react.default.createElement(_reactIntl.IntlProvider, {
|
|
801
761
|
locale: "en"
|
|
802
762
|
}, innerContent);
|
|
803
|
-
return /*#__PURE__*/_react.default.createElement(_fileAttributesContext.FileAttributesProvider, {
|
|
804
|
-
data: (0, _analytics.getFileAttributes)(this.metadata, (_this$lastFileState2 = this.lastFileState) === null || _this$lastFileState2 === void 0 ? void 0 : _this$lastFileState2.status)
|
|
805
|
-
}, content);
|
|
806
763
|
}
|
|
807
764
|
}]);
|
|
808
765
|
return CardBase;
|
|
@@ -821,22 +778,6 @@ exports.CardBase = CardBase;
|
|
|
821
778
|
// Required to detect a parent IntlProvider
|
|
822
779
|
intl: _reactIntl.intlShape
|
|
823
780
|
});
|
|
824
|
-
(0, _defineProperty2.default)(CardBase, "getDerivedStateFromProps", function (props) {
|
|
825
|
-
var identifier = props.identifier;
|
|
826
|
-
|
|
827
|
-
if (identifier.mediaItemType === 'external-image') {
|
|
828
|
-
var dataURI = identifier.dataURI;
|
|
829
|
-
return {
|
|
830
|
-
status: 'complete',
|
|
831
|
-
cardPreview: {
|
|
832
|
-
dataURI: dataURI,
|
|
833
|
-
orientation: 1
|
|
834
|
-
}
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
return null;
|
|
839
|
-
});
|
|
840
781
|
var Card = (0, _mediaCommon.withMediaAnalyticsContext)({
|
|
841
782
|
packageVersion: _version.version,
|
|
842
783
|
packageName: _version.name,
|