@atlaskit/media-card 74.0.0 → 74.1.2
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 +26 -0
- package/dist/cjs/errors.js +4 -0
- package/dist/cjs/root/card/cardAnalytics.js +6 -2
- package/dist/cjs/root/card/getCardPreview/index.js +47 -20
- package/dist/cjs/root/card/imageRefetchingAnalytics.js +45 -0
- package/dist/cjs/root/card/index.js +35 -29
- package/dist/cjs/root/inlinePlayerLazy.js +48 -0
- package/dist/cjs/utils/analytics.js +29 -2
- package/dist/cjs/utils/document.js +9 -1
- package/dist/cjs/utils/ufoExperiences.js +7 -3
- package/dist/cjs/utils/viewportDetector.js +11 -36
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/errors.js +4 -0
- package/dist/es2019/root/card/cardAnalytics.js +3 -2
- package/dist/es2019/root/card/getCardPreview/index.js +27 -2
- package/dist/es2019/root/card/imageRefetchingAnalytics.js +30 -0
- package/dist/es2019/root/card/index.js +32 -33
- package/dist/es2019/root/inlinePlayerLazy.js +11 -0
- package/dist/es2019/utils/analytics.js +18 -1
- package/dist/es2019/utils/document.js +11 -1
- package/dist/es2019/utils/ufoExperiences.js +4 -3
- package/dist/es2019/utils/viewportDetector.js +9 -36
- package/dist/es2019/version.json +1 -1
- package/dist/esm/errors.js +4 -0
- package/dist/esm/root/card/cardAnalytics.js +5 -2
- package/dist/esm/root/card/getCardPreview/index.js +47 -20
- package/dist/esm/root/card/imageRefetchingAnalytics.js +32 -0
- package/dist/esm/root/card/index.js +37 -33
- package/dist/esm/root/inlinePlayerLazy.js +29 -0
- package/dist/esm/utils/analytics.js +22 -1
- package/dist/esm/utils/document.js +9 -1
- package/dist/esm/utils/ufoExperiences.js +6 -3
- package/dist/esm/utils/viewportDetector.js +9 -36
- package/dist/esm/version.json +1 -1
- package/dist/types/errors.d.ts +5 -1
- package/dist/types/root/card/cardAnalytics.d.ts +1 -1
- package/dist/types/root/card/getCardPreview/index.d.ts +4 -1
- package/dist/types/root/card/imageRefetchingAnalytics.d.ts +10 -0
- package/dist/types/root/card/index.d.ts +2 -4
- package/dist/types/root/inlinePlayerLazy.d.ts +2 -0
- package/dist/types/utils/analytics.d.ts +17 -1
- package/dist/types/utils/document.d.ts +1 -1
- package/dist/types/utils/ufoExperiences.d.ts +1 -1
- package/dist/types/utils/viewportDetector.d.ts +0 -10
- package/package.json +11 -10
|
@@ -13,6 +13,8 @@ import { getCardPreviewFromFilePreview, getCardPreviewFromBackend } from './help
|
|
|
13
13
|
import { MediaCardError, SsrPreviewError, isUnsupportedLocalPreviewError } from '../../../errors';
|
|
14
14
|
import { isBigger } from '../../../utils/dimensionComparer';
|
|
15
15
|
import { extractFilePreviewStatus, isPreviewableStatus } from './filePreviewStatus';
|
|
16
|
+
import { fireImageFetchingOperationalEvent, calculatePercentageDifference } from '../imageRefetchingAnalytics';
|
|
17
|
+
import { getMediaFeatureFlag } from '@atlaskit/media-common';
|
|
16
18
|
export { getCardPreviewFromFilePreview, getCardPreviewFromBackend, isSupportedLocalPreview } from './helpers';
|
|
17
19
|
export { extractFilePreviewStatus } from './filePreviewStatus';
|
|
18
20
|
export var getCardPreviewFromCache = cardPreviewCache.get;
|
|
@@ -75,48 +77,57 @@ var extendAndCachePreview = function extendAndCachePreview(id, mode, preview, me
|
|
|
75
77
|
|
|
76
78
|
export var getCardPreview = /*#__PURE__*/function () {
|
|
77
79
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
|
|
78
|
-
var mediaClient, id, _ref$dimensions, dimensions, filePreview, onLocalPreviewError, isRemotePreviewReady, imageUrlParams, mediaBlobUrlAttrs, mode, cachedPreview, dimensionsAreBigger, localPreview;
|
|
80
|
+
var mediaClient, id, _ref$dimensions, dimensions, filePreview, onLocalPreviewError, isRemotePreviewReady, imageUrlParams, mediaBlobUrlAttrs, createAnalyticsEvent, featureFlags, mode, cachedPreview, dimensionsAreBigger, localPreview, remotePreview;
|
|
79
81
|
|
|
80
82
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
81
83
|
while (1) {
|
|
82
84
|
switch (_context.prev = _context.next) {
|
|
83
85
|
case 0:
|
|
84
|
-
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;
|
|
86
|
+
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, createAnalyticsEvent = _ref.createAnalyticsEvent, featureFlags = _ref.featureFlags;
|
|
85
87
|
mode = imageUrlParams.mode;
|
|
86
88
|
cachedPreview = cardPreviewCache.get(id, mode);
|
|
87
89
|
dimensionsAreBigger = isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions, dimensions);
|
|
88
90
|
|
|
89
91
|
if (!(cachedPreview && !dimensionsAreBigger)) {
|
|
90
|
-
_context.next =
|
|
92
|
+
_context.next = 7;
|
|
91
93
|
break;
|
|
92
94
|
}
|
|
93
95
|
|
|
96
|
+
if (getMediaFeatureFlag('memoryCacheLogging', featureFlags)) {
|
|
97
|
+
createAnalyticsEvent && fireImageFetchingOperationalEvent(createAnalyticsEvent, 'cache-hit', {
|
|
98
|
+
fileId: id,
|
|
99
|
+
prevDimensions: cachedPreview.dimensions,
|
|
100
|
+
currentDimensions: dimensions,
|
|
101
|
+
source: cachedPreview.source
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
94
105
|
return _context.abrupt("return", cachedPreview);
|
|
95
106
|
|
|
96
|
-
case
|
|
97
|
-
_context.prev =
|
|
107
|
+
case 7:
|
|
108
|
+
_context.prev = 7;
|
|
98
109
|
|
|
99
110
|
if (!filePreview) {
|
|
100
|
-
_context.next =
|
|
111
|
+
_context.next = 13;
|
|
101
112
|
break;
|
|
102
113
|
}
|
|
103
114
|
|
|
104
|
-
_context.next =
|
|
115
|
+
_context.next = 11;
|
|
105
116
|
return getCardPreviewFromFilePreview(filePreview);
|
|
106
117
|
|
|
107
|
-
case
|
|
118
|
+
case 11:
|
|
108
119
|
localPreview = _context.sent;
|
|
109
120
|
return _context.abrupt("return", extendAndCachePreview(id, mode, _objectSpread(_objectSpread({}, localPreview), {}, {
|
|
110
121
|
dimensions: dimensions
|
|
111
122
|
}), mediaBlobUrlAttrs));
|
|
112
123
|
|
|
113
|
-
case
|
|
114
|
-
_context.next =
|
|
124
|
+
case 13:
|
|
125
|
+
_context.next = 20;
|
|
115
126
|
break;
|
|
116
127
|
|
|
117
|
-
case
|
|
118
|
-
_context.prev =
|
|
119
|
-
_context.t0 = _context["catch"](
|
|
128
|
+
case 15:
|
|
129
|
+
_context.prev = 15;
|
|
130
|
+
_context.t0 = _context["catch"](7);
|
|
120
131
|
|
|
121
132
|
/**
|
|
122
133
|
* We report the error if:
|
|
@@ -138,29 +149,45 @@ export var getCardPreview = /*#__PURE__*/function () {
|
|
|
138
149
|
|
|
139
150
|
|
|
140
151
|
if (isRemotePreviewReady) {
|
|
141
|
-
_context.next =
|
|
152
|
+
_context.next = 20;
|
|
142
153
|
break;
|
|
143
154
|
}
|
|
144
155
|
|
|
145
156
|
throw _context.t0;
|
|
146
157
|
|
|
147
|
-
case
|
|
158
|
+
case 20:
|
|
148
159
|
if (isRemotePreviewReady) {
|
|
149
|
-
_context.next =
|
|
160
|
+
_context.next = 22;
|
|
150
161
|
break;
|
|
151
162
|
}
|
|
152
163
|
|
|
153
164
|
throw new MediaCardError('remote-preview-not-ready');
|
|
154
165
|
|
|
155
|
-
case 21:
|
|
156
|
-
return _context.abrupt("return", fetchAndCacheRemotePreview(mediaClient, id, dimensions, imageUrlParams, mediaBlobUrlAttrs));
|
|
157
|
-
|
|
158
166
|
case 22:
|
|
167
|
+
_context.next = 24;
|
|
168
|
+
return fetchAndCacheRemotePreview(mediaClient, id, dimensions, imageUrlParams, mediaBlobUrlAttrs);
|
|
169
|
+
|
|
170
|
+
case 24:
|
|
171
|
+
remotePreview = _context.sent;
|
|
172
|
+
|
|
173
|
+
if (getMediaFeatureFlag('memoryCacheLogging', featureFlags)) {
|
|
174
|
+
createAnalyticsEvent && fireImageFetchingOperationalEvent(createAnalyticsEvent, 'remote-success', {
|
|
175
|
+
fileId: id,
|
|
176
|
+
prevDimensions: cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions,
|
|
177
|
+
currentDimensions: dimensions,
|
|
178
|
+
dimensionsPercentageDiff: calculatePercentageDifference(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions, dimensions),
|
|
179
|
+
source: remotePreview.source
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return _context.abrupt("return", remotePreview);
|
|
184
|
+
|
|
185
|
+
case 27:
|
|
159
186
|
case "end":
|
|
160
187
|
return _context.stop();
|
|
161
188
|
}
|
|
162
189
|
}
|
|
163
|
-
}, _callee, null, [[
|
|
190
|
+
}, _callee, null, [[7, 15]]);
|
|
164
191
|
}));
|
|
165
192
|
|
|
166
193
|
return function getCardPreview(_x) {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { fireMediaCardEvent, getCacheHitEventPayload, getRemoteSuccessEventPayload } from '../../utils/analytics';
|
|
2
|
+
export var fireImageFetchingOperationalEvent = function fireImageFetchingOperationalEvent(createAnalyticsEvent, action, cardPreviewAttributes) {
|
|
3
|
+
var fireEvent = function fireEvent(payload) {
|
|
4
|
+
return fireMediaCardEvent(payload, createAnalyticsEvent);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
switch (action) {
|
|
8
|
+
case 'cache-hit':
|
|
9
|
+
fireEvent(getCacheHitEventPayload(cardPreviewAttributes));
|
|
10
|
+
break;
|
|
11
|
+
|
|
12
|
+
case 'remote-success':
|
|
13
|
+
fireEvent(getRemoteSuccessEventPayload(cardPreviewAttributes));
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export var calculatePercentageDifference = function calculatePercentageDifference(prevDimensions, currentDimensions) {
|
|
18
|
+
if (!prevDimensions) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var prevWidth = parseInt("".concat(prevDimensions === null || prevDimensions === void 0 ? void 0 : prevDimensions.width), 10);
|
|
23
|
+
var currWidth = parseInt("".concat(currentDimensions === null || currentDimensions === void 0 ? void 0 : currentDimensions.width), 10);
|
|
24
|
+
var prevHeight = parseInt("".concat(prevDimensions === null || prevDimensions === void 0 ? void 0 : prevDimensions.height), 10);
|
|
25
|
+
var currHeight = parseInt("".concat(currentDimensions === null || currentDimensions === void 0 ? void 0 : currentDimensions.height), 10);
|
|
26
|
+
var percentageDiffInWidth = ((currWidth - prevWidth) / prevWidth * 100).toFixed(2);
|
|
27
|
+
var percentageDiffInHeight = ((currHeight - prevHeight) / prevHeight * 100).toFixed(2);
|
|
28
|
+
return {
|
|
29
|
+
width: percentageDiffInWidth,
|
|
30
|
+
height: percentageDiffInHeight
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -17,7 +17,7 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
17
17
|
|
|
18
18
|
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; } }
|
|
19
19
|
|
|
20
|
-
import React, { Component,
|
|
20
|
+
import React, { Component, Suspense } from 'react';
|
|
21
21
|
import ReactDOM from 'react-dom';
|
|
22
22
|
import { withAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
23
23
|
import { withMediaAnalyticsContext } from '@atlaskit/media-common';
|
|
@@ -26,11 +26,11 @@ import { globalMediaEventEmitter, isDifferentIdentifier, isFileIdentifier, RECEN
|
|
|
26
26
|
import { MediaViewer } from '@atlaskit/media-viewer';
|
|
27
27
|
import { injectIntl, IntlProvider } from 'react-intl-next';
|
|
28
28
|
import { CardView } from '../cardView';
|
|
29
|
-
import {
|
|
29
|
+
import { ViewportDetector } from '../../utils/viewportDetector';
|
|
30
30
|
import { getRequestedDimensions } from '../../utils/getDataURIDimension';
|
|
31
31
|
import { getCardPreview, getCardPreviewFromCache, removeCardPreviewFromCache, getFilePreviewFromFileState, shouldResolvePreview, getSSRCardPreview, isLocalPreview, isSSRPreview, isSSRClientPreview, isSSRDataPreview, fetchAndCacheRemotePreview } from './getCardPreview';
|
|
32
32
|
import { getFileDetails } from '../../utils/metadata';
|
|
33
|
-
import {
|
|
33
|
+
import { InlinePlayerLazy } from '../inlinePlayerLazy';
|
|
34
34
|
import { getFileAttributes, extractErrorInfo, LOGGED_FEATURE_FLAGS } from '../../utils/analytics';
|
|
35
35
|
import { isLocalPreviewError, MediaCardError, ensureMediaCardError, ImageLoadError } from '../../errors';
|
|
36
36
|
import { fireOperationalEvent as _fireOperationalEvent, fireCommencedEvent as _fireCommencedEvent, fireCopiedEvent, fireScreenEvent } from './cardAnalytics';
|
|
@@ -43,7 +43,7 @@ import { getMediaCardCursor } from '../../utils/getMediaCardCursor';
|
|
|
43
43
|
import { completeUfoExperience, startUfoExperience } from '../../utils/ufoExperiences';
|
|
44
44
|
import { generateUniqueId } from '../../utils/generateUniqueId';
|
|
45
45
|
var packageName = "@atlaskit/media-card";
|
|
46
|
-
var packageVersion = "74.
|
|
46
|
+
var packageVersion = "74.1.2";
|
|
47
47
|
export var CardBase = /*#__PURE__*/function (_Component) {
|
|
48
48
|
_inherits(CardBase, _Component);
|
|
49
49
|
|
|
@@ -69,10 +69,6 @@ export var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
69
69
|
wasStatusProcessing: false
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
_defineProperty(_assertThisInitialized(_this), "viewportPreAnchorRef", /*#__PURE__*/createRef());
|
|
73
|
-
|
|
74
|
-
_defineProperty(_assertThisInitialized(_this), "viewportPostAnchorRef", /*#__PURE__*/createRef());
|
|
75
|
-
|
|
76
72
|
_defineProperty(_assertThisInitialized(_this), "ssrReliability", {
|
|
77
73
|
server: {
|
|
78
74
|
status: 'unknown'
|
|
@@ -125,7 +121,8 @@ export var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
125
121
|
var _this$props2 = _this.props,
|
|
126
122
|
_this$props2$dimensio = _this$props2.dimensions,
|
|
127
123
|
dimensions = _this$props2$dimensio === void 0 ? {} : _this$props2$dimensio,
|
|
128
|
-
mediaClient = _this$props2.mediaClient
|
|
124
|
+
mediaClient = _this$props2.mediaClient,
|
|
125
|
+
createAnalyticsEvent = _this$props2.createAnalyticsEvent;
|
|
129
126
|
return {
|
|
130
127
|
mediaClient: mediaClient,
|
|
131
128
|
id: id,
|
|
@@ -134,7 +131,9 @@ export var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
134
131
|
filePreview: isBannedLocalPreview ? undefined : getFilePreviewFromFileState(fileState),
|
|
135
132
|
isRemotePreviewReady: isImageRepresentationReady(fileState),
|
|
136
133
|
imageUrlParams: _this.getImageURLParams(identifier),
|
|
137
|
-
mediaBlobUrlAttrs: _this.getMediaBlobUrlAttrs(identifier, fileState)
|
|
134
|
+
mediaBlobUrlAttrs: _this.getMediaBlobUrlAttrs(identifier, fileState),
|
|
135
|
+
createAnalyticsEvent: createAnalyticsEvent,
|
|
136
|
+
featureFlags: _this.props.featureFlags
|
|
138
137
|
};
|
|
139
138
|
});
|
|
140
139
|
|
|
@@ -461,7 +460,12 @@ export var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
461
460
|
var _this$state = _this.state,
|
|
462
461
|
shouldAutoplay = _this$state.shouldAutoplay,
|
|
463
462
|
cardPreview = _this$state.cardPreview;
|
|
464
|
-
|
|
463
|
+
|
|
464
|
+
var card = _this.renderCard(false, 'loading', false);
|
|
465
|
+
|
|
466
|
+
return /*#__PURE__*/React.createElement(Suspense, {
|
|
467
|
+
fallback: card
|
|
468
|
+
}, /*#__PURE__*/React.createElement(InlinePlayerLazy, {
|
|
465
469
|
mediaClient: mediaClient,
|
|
466
470
|
dimensions: dimensions,
|
|
467
471
|
originalDimensions: originalDimensions,
|
|
@@ -474,7 +478,7 @@ export var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
474
478
|
ref: _this.setRef,
|
|
475
479
|
testId: testId,
|
|
476
480
|
cardPreview: cardPreview
|
|
477
|
-
});
|
|
481
|
+
}));
|
|
478
482
|
});
|
|
479
483
|
|
|
480
484
|
_defineProperty(_assertThisInitialized(_this), "onMediaViewerClose", function () {
|
|
@@ -533,6 +537,9 @@ export var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
533
537
|
});
|
|
534
538
|
|
|
535
539
|
_defineProperty(_assertThisInitialized(_this), "renderCard", function () {
|
|
540
|
+
var withCallbacks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
541
|
+
var cardStatusOverride = arguments.length > 1 ? arguments[1] : undefined;
|
|
542
|
+
var izLazyOverride = arguments.length > 2 ? arguments[2] : undefined;
|
|
536
543
|
var _this$props9 = _this.props,
|
|
537
544
|
identifier = _this$props9.identifier,
|
|
538
545
|
isLazy = _this$props9.isLazy,
|
|
@@ -566,16 +573,17 @@ export var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
566
573
|
onCardViewClick = _assertThisInitialize4.onCardViewClick,
|
|
567
574
|
onDisplayImage = _assertThisInitialize4.onDisplayImage,
|
|
568
575
|
actions = _assertThisInitialize4.actions,
|
|
569
|
-
onMouseEnter = _assertThisInitialize4.onMouseEnter;
|
|
570
|
-
// For example, when we have the image in cache
|
|
576
|
+
onMouseEnter = _assertThisInitialize4.onMouseEnter;
|
|
571
577
|
|
|
578
|
+
var isLazyWithOverride = izLazyOverride === undefined ? isLazy : izLazyOverride; // Card can be artificially turned visible before entering the viewport
|
|
579
|
+
// For example, when we have the image in cache
|
|
572
580
|
|
|
573
|
-
var nativeLazyLoad =
|
|
581
|
+
var nativeLazyLoad = isLazyWithOverride && !isCardVisible; // Force Media Image to always display img for SSR
|
|
574
582
|
|
|
575
583
|
var forceSyncDisplay = !!ssr;
|
|
576
584
|
var mediaCardCursor = getMediaCardCursor(!!useInlinePlayer, !!shouldOpenMediaViewer, status === 'error' || status === 'failed-processing', !!_this.state.cardPreview, metadata.mediaType);
|
|
577
585
|
var card = /*#__PURE__*/React.createElement(CardView, {
|
|
578
|
-
status: status,
|
|
586
|
+
status: cardStatusOverride || status,
|
|
579
587
|
error: error,
|
|
580
588
|
mediaItemType: mediaItemType,
|
|
581
589
|
metadata: metadata,
|
|
@@ -587,34 +595,26 @@ export var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
587
595
|
actions: actions,
|
|
588
596
|
selectable: selectable,
|
|
589
597
|
selected: selected,
|
|
590
|
-
onClick: onCardViewClick,
|
|
591
|
-
onMouseEnter: onMouseEnter,
|
|
598
|
+
onClick: withCallbacks ? onCardViewClick : undefined,
|
|
599
|
+
onMouseEnter: withCallbacks ? onMouseEnter : undefined,
|
|
592
600
|
disableOverlay: disableOverlay,
|
|
593
601
|
progress: progress,
|
|
594
|
-
onDisplayImage: onDisplayImage,
|
|
602
|
+
onDisplayImage: withCallbacks ? onDisplayImage : undefined,
|
|
595
603
|
innerRef: _this.setRef,
|
|
596
604
|
testId: testId,
|
|
597
605
|
featureFlags: featureFlags,
|
|
598
606
|
titleBoxBgColor: titleBoxBgColor,
|
|
599
607
|
titleBoxIcon: titleBoxIcon,
|
|
600
|
-
onImageError: _this.onImageError,
|
|
601
|
-
onImageLoad: _this.onImageLoad,
|
|
608
|
+
onImageError: withCallbacks ? _this.onImageError : undefined,
|
|
609
|
+
onImageLoad: withCallbacks ? _this.onImageLoad : undefined,
|
|
602
610
|
nativeLazyLoad: nativeLazyLoad,
|
|
603
611
|
forceSyncDisplay: forceSyncDisplay,
|
|
604
612
|
mediaCardCursor: mediaCardCursor
|
|
605
613
|
});
|
|
606
|
-
return
|
|
614
|
+
return isLazyWithOverride ? /*#__PURE__*/React.createElement(ViewportDetector, {
|
|
607
615
|
cardEl: cardRef,
|
|
608
|
-
preAnchorRef: _this.viewportPreAnchorRef,
|
|
609
|
-
postAnchorRef: _this.viewportPostAnchorRef,
|
|
610
616
|
onVisible: _this.onCardInViewport
|
|
611
|
-
},
|
|
612
|
-
ref: _this.viewportPreAnchorRef,
|
|
613
|
-
offsetTop: -ABS_VIEWPORT_ANCHOR_OFFSET_TOP
|
|
614
|
-
}), card, /*#__PURE__*/React.createElement(ViewportAnchor, {
|
|
615
|
-
ref: _this.viewportPostAnchorRef,
|
|
616
|
-
offsetTop: ABS_VIEWPORT_ANCHOR_OFFSET_TOP
|
|
617
|
-
})) : card;
|
|
617
|
+
}, card) : card;
|
|
618
618
|
});
|
|
619
619
|
|
|
620
620
|
_defineProperty(_assertThisInitialized(_this), "storeSSRData", function () {
|
|
@@ -748,6 +748,8 @@ export var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
748
748
|
_createClass(CardBase, [{
|
|
749
749
|
key: "componentDidMount",
|
|
750
750
|
value: function componentDidMount() {
|
|
751
|
+
var _getDocument;
|
|
752
|
+
|
|
751
753
|
this.hasBeenMounted = true;
|
|
752
754
|
var _this$state3 = this.state,
|
|
753
755
|
isCardVisible = _this$state3.isCardVisible,
|
|
@@ -781,7 +783,7 @@ export var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
781
783
|
// won't work in IE11
|
|
782
784
|
|
|
783
785
|
|
|
784
|
-
getDocument().addEventListener('copy', this.fireCopiedEvent);
|
|
786
|
+
(_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.addEventListener('copy', this.fireCopiedEvent);
|
|
785
787
|
}
|
|
786
788
|
}, {
|
|
787
789
|
key: "componentDidUpdate",
|
|
@@ -876,9 +878,11 @@ export var CardBase = /*#__PURE__*/function (_Component) {
|
|
|
876
878
|
}, {
|
|
877
879
|
key: "componentWillUnmount",
|
|
878
880
|
value: function componentWillUnmount() {
|
|
881
|
+
var _getDocument2;
|
|
882
|
+
|
|
879
883
|
this.hasBeenMounted = false;
|
|
880
884
|
this.unsubscribe();
|
|
881
|
-
getDocument().removeEventListener('copy', this.fireCopiedEvent);
|
|
885
|
+
(_getDocument2 = getDocument()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.removeEventListener('copy', this.fireCopiedEvent);
|
|
882
886
|
}
|
|
883
887
|
}, {
|
|
884
888
|
key: "updateStateForIdentifier",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { lazy } from 'react';
|
|
4
|
+
export var InlinePlayerLazy = /*#__PURE__*/lazy( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
5
|
+
var _yield$import, InlinePlayer;
|
|
6
|
+
|
|
7
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
8
|
+
while (1) {
|
|
9
|
+
switch (_context.prev = _context.next) {
|
|
10
|
+
case 0:
|
|
11
|
+
_context.next = 2;
|
|
12
|
+
return import(
|
|
13
|
+
/* webpackChunkName: "@atlaskit-internal_media-card-inlineplayer" */
|
|
14
|
+
'./inlinePlayer');
|
|
15
|
+
|
|
16
|
+
case 2:
|
|
17
|
+
_yield$import = _context.sent;
|
|
18
|
+
InlinePlayer = _yield$import.InlinePlayer;
|
|
19
|
+
return _context.abrupt("return", {
|
|
20
|
+
default: InlinePlayer
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
case 5:
|
|
24
|
+
case "end":
|
|
25
|
+
return _context.stop();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}, _callee);
|
|
29
|
+
})));
|
|
@@ -15,7 +15,8 @@ var relevantFlags = {
|
|
|
15
15
|
observedWidth: true,
|
|
16
16
|
mediaInline: false,
|
|
17
17
|
folderUploads: false,
|
|
18
|
-
mediaUploadApiV2: true
|
|
18
|
+
mediaUploadApiV2: true,
|
|
19
|
+
memoryCacheLogging: true
|
|
19
20
|
};
|
|
20
21
|
export var LOGGED_FEATURE_FLAGS = filterFeatureFlagNames(relevantFlags);
|
|
21
22
|
export var LOGGED_FEATURE_FLAG_KEYS = filterFeatureFlagKeysAllProducts(relevantFlags);
|
|
@@ -64,6 +65,26 @@ export var getRenderSucceededEventPayload = function getRenderSucceededEventPayl
|
|
|
64
65
|
}
|
|
65
66
|
};
|
|
66
67
|
};
|
|
68
|
+
export var getCacheHitEventPayload = function getCacheHitEventPayload(cardPreviewAttributes) {
|
|
69
|
+
return {
|
|
70
|
+
eventType: 'operational',
|
|
71
|
+
action: 'cache-hit',
|
|
72
|
+
actionSubject: 'mediaCardCache',
|
|
73
|
+
attributes: {
|
|
74
|
+
cardPreviewAttributes: cardPreviewAttributes
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
export var getRemoteSuccessEventPayload = function getRemoteSuccessEventPayload(cardPreviewAttributes) {
|
|
79
|
+
return {
|
|
80
|
+
eventType: 'operational',
|
|
81
|
+
action: 'Remote-success',
|
|
82
|
+
actionSubject: 'mediaCardCache',
|
|
83
|
+
attributes: {
|
|
84
|
+
cardPreviewAttributes: cardPreviewAttributes
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
};
|
|
67
88
|
export var getRenderFailedExternalUriPayload = function getRenderFailedExternalUriPayload(fileAttributes, performanceAttributes) {
|
|
68
89
|
return {
|
|
69
90
|
eventType: 'operational',
|
|
@@ -6,9 +6,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
6
6
|
|
|
7
7
|
import { ConcurrentExperience, ExperiencePerformanceTypes, ExperienceTypes } from '@atlaskit/ufo';
|
|
8
8
|
import { extractErrorInfo, getRenderErrorRequestMetadata, LOGGED_FEATURE_FLAG_KEYS } from './analytics';
|
|
9
|
+
import { MediaCardError } from '../errors';
|
|
9
10
|
import { getMediaEnvironment, getMediaRegion } from '@atlaskit/media-client';
|
|
10
11
|
var packageName = "@atlaskit/media-card";
|
|
11
|
-
var packageVersion = "74.
|
|
12
|
+
var packageVersion = "74.1.2";
|
|
12
13
|
var concurrentExperience;
|
|
13
14
|
|
|
14
15
|
var getExperience = function getExperience(id) {
|
|
@@ -30,7 +31,9 @@ var getExperience = function getExperience(id) {
|
|
|
30
31
|
export var startUfoExperience = function startUfoExperience(id) {
|
|
31
32
|
getExperience(id).start();
|
|
32
33
|
};
|
|
33
|
-
export var completeUfoExperience = function completeUfoExperience(id, status, fileAttributes, fileStateFlags, ssrReliability
|
|
34
|
+
export var completeUfoExperience = function completeUfoExperience(id, status, fileAttributes, fileStateFlags, ssrReliability) {
|
|
35
|
+
var error = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : new MediaCardError('missing-error-data');
|
|
36
|
+
|
|
34
37
|
switch (status) {
|
|
35
38
|
case 'complete':
|
|
36
39
|
succeedUfoExperience(id, {
|
|
@@ -50,7 +53,7 @@ export var completeUfoExperience = function completeUfoExperience(id, status, fi
|
|
|
50
53
|
break;
|
|
51
54
|
|
|
52
55
|
case 'error':
|
|
53
|
-
|
|
56
|
+
failUfoExperience(id, _objectSpread(_objectSpread({
|
|
54
57
|
fileAttributes: fileAttributes
|
|
55
58
|
}, extractErrorInfo(error)), {}, {
|
|
56
59
|
request: getRenderErrorRequestMetadata(error),
|
|
@@ -4,30 +4,9 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
4
4
|
|
|
5
5
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
6
6
|
|
|
7
|
-
import React, { useEffect
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* Using this approach, we can lazy load cards ABS_VIEWPORT_ANCHOR_OFFSET_TOP px before they enter viewport.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export var ABS_VIEWPORT_ANCHOR_OFFSET_TOP = 900; //px
|
|
14
|
-
|
|
15
|
-
export var ViewportAnchor = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
16
|
-
if (typeof IntersectionObserver === 'undefined') {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
21
|
-
ref: ref,
|
|
22
|
-
className: "media-card-viewport-anchor",
|
|
23
|
-
style: {
|
|
24
|
-
position: 'absolute',
|
|
25
|
-
top: "".concat(props.offsetTop, "px"),
|
|
26
|
-
maxHeight: 0,
|
|
27
|
-
pointerEvents: 'none'
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
});
|
|
7
|
+
import React, { useEffect } from 'react';
|
|
8
|
+
import getDocument from './document';
|
|
9
|
+
var ABS_VIEWPORT_ANCHOR_OFFSET_TOP = 900; //px
|
|
31
10
|
|
|
32
11
|
var createIntersectionObserverCallback = function createIntersectionObserverCallback(onVisible) {
|
|
33
12
|
return function (entries, observer) {
|
|
@@ -55,26 +34,22 @@ var createIntersectionObserverCallback = function createIntersectionObserverCall
|
|
|
55
34
|
var ViewportObserver = function ViewportObserver(_ref) {
|
|
56
35
|
var onVisible = _ref.onVisible,
|
|
57
36
|
cardEl = _ref.cardEl,
|
|
58
|
-
children = _ref.children
|
|
59
|
-
preAnchorRef = _ref.preAnchorRef,
|
|
60
|
-
postAnchorRef = _ref.postAnchorRef;
|
|
37
|
+
children = _ref.children;
|
|
61
38
|
useEffect(function () {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
39
|
+
var intersectionObserver = new IntersectionObserver(createIntersectionObserverCallback(onVisible), {
|
|
40
|
+
root: getDocument(),
|
|
41
|
+
rootMargin: "".concat(ABS_VIEWPORT_ANCHOR_OFFSET_TOP, "px")
|
|
42
|
+
});
|
|
66
43
|
cardEl && intersectionObserver.observe(cardEl);
|
|
67
44
|
return function () {
|
|
68
45
|
intersectionObserver.disconnect();
|
|
69
46
|
};
|
|
70
|
-
}, [cardEl,
|
|
47
|
+
}, [cardEl, onVisible]);
|
|
71
48
|
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
72
49
|
};
|
|
73
50
|
|
|
74
51
|
export var ViewportDetector = function ViewportDetector(_ref2) {
|
|
75
52
|
var cardEl = _ref2.cardEl,
|
|
76
|
-
preAnchorRef = _ref2.preAnchorRef,
|
|
77
|
-
postAnchorRef = _ref2.postAnchorRef,
|
|
78
53
|
onVisible = _ref2.onVisible,
|
|
79
54
|
children = _ref2.children;
|
|
80
55
|
|
|
@@ -84,8 +59,6 @@ export var ViewportDetector = function ViewportDetector(_ref2) {
|
|
|
84
59
|
|
|
85
60
|
return /*#__PURE__*/React.createElement(ViewportObserver, {
|
|
86
61
|
cardEl: cardEl,
|
|
87
|
-
preAnchorRef: preAnchorRef,
|
|
88
|
-
postAnchorRef: postAnchorRef,
|
|
89
62
|
onVisible: onVisible
|
|
90
63
|
}, children);
|
|
91
64
|
};
|
package/dist/esm/version.json
CHANGED
package/dist/types/errors.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { CardPreview } from '.';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Primary reason is logged through Data Portal.
|
|
4
|
+
* Make sure all the values are whitelisted in Measure -> Event Regitry -> "mediaCardRender failed" event
|
|
5
|
+
*/
|
|
6
|
+
export declare type MediaCardErrorPrimaryReason = 'upload' | 'metadata-fetch' | 'error-file-state' | RemotePreviewPrimaryReason | LocalPreviewPrimaryReason | ImageLoadPrimaryReason | SsrPreviewPrimaryReason | 'missing-error-data' | 'preview-fetch';
|
|
3
7
|
export declare type ImageLoadPrimaryReason = 'cache-remote-uri' | 'cache-local-uri' | 'local-uri' | 'remote-uri' | 'external-uri' | 'unknown-uri';
|
|
4
8
|
export declare type RemotePreviewPrimaryReason = 'remote-preview-fetch' | 'remote-preview-not-ready';
|
|
5
9
|
export declare type LocalPreviewPrimaryReason = 'local-preview-get' | 'local-preview-unsupported' | 'local-preview-rejected' | 'local-preview-image' | 'local-preview-video';
|
|
@@ -3,7 +3,7 @@ import { CreateUIAnalyticsEvent } from '@atlaskit/analytics-next';
|
|
|
3
3
|
import { SSRStatus } from '../../utils/analytics';
|
|
4
4
|
import { CardStatus } from '../..';
|
|
5
5
|
import { MediaCardError } from './../../errors';
|
|
6
|
-
export declare const fireOperationalEvent: (createAnalyticsEvent: CreateUIAnalyticsEvent, status: CardStatus, fileAttributes: FileAttributes, performanceAttributes: PerformanceAttributes, ssrReliability: SSRStatus, error?: MediaCardError
|
|
6
|
+
export declare const fireOperationalEvent: (createAnalyticsEvent: CreateUIAnalyticsEvent, status: CardStatus, fileAttributes: FileAttributes, performanceAttributes: PerformanceAttributes, ssrReliability: SSRStatus, error?: MediaCardError) => void;
|
|
7
7
|
export declare const fireCommencedEvent: (createAnalyticsEvent: CreateUIAnalyticsEvent, fileAttributes: FileAttributes, performanceAttributes: PerformanceAttributes) => void;
|
|
8
8
|
export declare const fireCopiedEvent: (createAnalyticsEvent: CreateUIAnalyticsEvent, fileId: string, cardRef: HTMLDivElement) => void;
|
|
9
9
|
export declare const fireScreenEvent: (createAnalyticsEvent: CreateUIAnalyticsEvent, fileAttributes: FileAttributes) => void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MediaClient, FilePreview, FileState, MediaStoreGetFileImageParams, MediaBlobUrlAttrs, FileIdentifier } from '@atlaskit/media-client';
|
|
2
2
|
import { MediaFeatureFlags, SSR } from '@atlaskit/media-common';
|
|
3
3
|
import { ImageResizeMode } from '@atlaskit/media-client';
|
|
4
|
+
import { CreateUIAnalyticsEvent } from '@atlaskit/analytics-next';
|
|
4
5
|
import { CardDimensions } from '../../../utils/cardDimensions';
|
|
5
6
|
import { MediaCardError } from '../../../errors';
|
|
6
7
|
import { CardStatus, CardPreview } from '../../../types';
|
|
@@ -22,6 +23,8 @@ export declare type CardPreviewParams = {
|
|
|
22
23
|
isRemotePreviewReady: boolean;
|
|
23
24
|
imageUrlParams: MediaStoreGetFileImageParams;
|
|
24
25
|
mediaBlobUrlAttrs?: MediaBlobUrlAttrs;
|
|
26
|
+
createAnalyticsEvent?: CreateUIAnalyticsEvent;
|
|
27
|
+
featureFlags?: MediaFeatureFlags;
|
|
25
28
|
};
|
|
26
29
|
/**
|
|
27
30
|
* This function will try to return a Card preview, either from cache, local preview or remote preview.
|
|
@@ -33,7 +36,7 @@ export declare type CardPreviewParams = {
|
|
|
33
36
|
* In that case, we still want to report the local preview error to the caller, for feature realiability track.
|
|
34
37
|
* hence the use of the optional callback onLocalPreviewError
|
|
35
38
|
*/
|
|
36
|
-
export declare const getCardPreview: ({ mediaClient, id, dimensions, filePreview, onLocalPreviewError, isRemotePreviewReady, imageUrlParams, mediaBlobUrlAttrs, }: CardPreviewParams) => Promise<CardPreview>;
|
|
39
|
+
export declare const getCardPreview: ({ mediaClient, id, dimensions, filePreview, onLocalPreviewError, isRemotePreviewReady, imageUrlParams, mediaBlobUrlAttrs, createAnalyticsEvent, featureFlags, }: CardPreviewParams) => Promise<CardPreview>;
|
|
37
40
|
export declare const shouldResolvePreview: ({ status, fileState, dimensions, identifier, fileImageMode, hasCardPreview, isBannedLocalPreview, featureFlags, }: {
|
|
38
41
|
status: CardStatus;
|
|
39
42
|
fileState: FileState;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CreateUIAnalyticsEvent } from '@atlaskit/analytics-next';
|
|
2
|
+
import { CardDimensions } from '../../utils';
|
|
3
|
+
import { CardPreviewAttributes } from '../../utils/analytics';
|
|
4
|
+
declare type cardAction = 'cache-hit' | 'remote-success';
|
|
5
|
+
export declare const fireImageFetchingOperationalEvent: (createAnalyticsEvent: CreateUIAnalyticsEvent, action: cardAction, cardPreviewAttributes: CardPreviewAttributes) => void;
|
|
6
|
+
export declare const calculatePercentageDifference: (prevDimensions: CardDimensions | undefined, currentDimensions: CardDimensions | undefined) => {
|
|
7
|
+
width: string;
|
|
8
|
+
height: string;
|
|
9
|
+
} | undefined;
|
|
10
|
+
export {};
|
|
@@ -2,14 +2,12 @@ import React, { Component } from 'react';
|
|
|
2
2
|
import { UIAnalyticsEvent, WithAnalyticsEventsProps } from '@atlaskit/analytics-next';
|
|
3
3
|
import { FileIdentifier, FileState, MediaSubscription } from '@atlaskit/media-client';
|
|
4
4
|
import { WrappedComponentProps } from 'react-intl-next';
|
|
5
|
-
import { CardAction, CardProps, CardState } from '../..';
|
|
5
|
+
import { CardAction, CardProps, CardState, CardStatus } from '../..';
|
|
6
6
|
export declare type CardBaseProps = CardProps & WithAnalyticsEventsProps & Partial<WrappedComponentProps>;
|
|
7
7
|
export declare class CardBase extends Component<CardBaseProps, CardState> {
|
|
8
8
|
private internalOccurrenceKey;
|
|
9
9
|
private hasBeenMounted;
|
|
10
10
|
private fileStateFlags;
|
|
11
|
-
private viewportPreAnchorRef;
|
|
12
|
-
private viewportPostAnchorRef;
|
|
13
11
|
private ssrReliability;
|
|
14
12
|
private timeElapsedTillCommenced;
|
|
15
13
|
subscription?: MediaSubscription;
|
|
@@ -50,7 +48,7 @@ export declare class CardBase extends Component<CardBaseProps, CardState> {
|
|
|
50
48
|
onMediaViewerClose: () => void;
|
|
51
49
|
private onDisplayImage;
|
|
52
50
|
renderMediaViewer: () => React.ReactPortal | undefined;
|
|
53
|
-
renderCard: () => JSX.Element;
|
|
51
|
+
renderCard: (withCallbacks?: boolean, cardStatusOverride?: CardStatus | undefined, izLazyOverride?: boolean | undefined) => JSX.Element;
|
|
54
52
|
private storeSSRData;
|
|
55
53
|
render(): JSX.Element;
|
|
56
54
|
private onCardInViewport;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const InlinePlayerLazy: import("react").LazyExoticComponent<import("react").ForwardRefExoticComponent<Pick<import("./inlinePlayer").InlinePlayerProps, "createAnalyticsEvent" | keyof import("./inlinePlayer").InlinePlayerOwnProps> & import("react").RefAttributes<HTMLDivElement>>>;
|