@atlaskit/media-card 77.5.0 → 77.5.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.
Files changed (107) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/card/card.js +1 -1
  3. package/dist/cjs/card/media-card-analytics-error-boundary.js +1 -1
  4. package/dist/cjs/card/v2/cardV2.js +1 -1
  5. package/dist/cjs/card/v2/cardViewV2.js +7 -6
  6. package/dist/cjs/card/v2/useFilePreview/errors.js +132 -0
  7. package/dist/cjs/card/v2/useFilePreview/getPreview/cache.js +39 -0
  8. package/dist/cjs/card/v2/useFilePreview/getPreview/filePreviewStatus.js +45 -0
  9. package/dist/cjs/card/v2/useFilePreview/getPreview/getPreview.js +119 -0
  10. package/dist/cjs/card/v2/useFilePreview/getPreview/helpers.js +167 -0
  11. package/dist/cjs/card/v2/useFilePreview/getPreview/index.js +62 -0
  12. package/dist/cjs/card/v2/useFilePreview/getPreview/objectURLCache.js +85 -0
  13. package/dist/cjs/card/v2/useFilePreview/getPreview/videoSnapshot.js +58 -0
  14. package/dist/cjs/card/v2/useFilePreview/globalScope/getSSRData.js +14 -0
  15. package/dist/cjs/card/v2/useFilePreview/globalScope/globalScope.js +66 -0
  16. package/dist/cjs/card/v2/useFilePreview/globalScope/index.js +37 -0
  17. package/dist/cjs/card/v2/useFilePreview/globalScope/printScript.js +32 -0
  18. package/dist/cjs/card/v2/useFilePreview/globalScope/types.js +5 -0
  19. package/dist/cjs/card/v2/useFilePreview/helpers.js +64 -0
  20. package/dist/cjs/card/v2/useFilePreview/index.js +12 -0
  21. package/dist/cjs/card/v2/useFilePreview/types.js +5 -0
  22. package/dist/cjs/card/v2/{useFilePreview.js → useFilePreview/useFilePreview.js} +58 -194
  23. package/dist/cjs/inline/loader.js +1 -1
  24. package/dist/cjs/utils/ufoExperiences.js +1 -1
  25. package/dist/es2019/card/card.js +1 -1
  26. package/dist/es2019/card/media-card-analytics-error-boundary.js +1 -1
  27. package/dist/es2019/card/v2/cardV2.js +1 -1
  28. package/dist/es2019/card/v2/cardViewV2.js +7 -6
  29. package/dist/es2019/card/v2/useFilePreview/errors.js +81 -0
  30. package/dist/es2019/card/v2/useFilePreview/getPreview/cache.js +30 -0
  31. package/dist/es2019/card/v2/useFilePreview/getPreview/filePreviewStatus.js +43 -0
  32. package/dist/es2019/card/v2/useFilePreview/getPreview/getPreview.js +75 -0
  33. package/dist/es2019/card/v2/useFilePreview/getPreview/helpers.js +76 -0
  34. package/dist/es2019/card/v2/useFilePreview/getPreview/index.js +3 -0
  35. package/dist/es2019/card/v2/useFilePreview/getPreview/objectURLCache.js +44 -0
  36. package/dist/es2019/card/v2/useFilePreview/getPreview/videoSnapshot.js +36 -0
  37. package/dist/es2019/card/v2/useFilePreview/globalScope/getSSRData.js +8 -0
  38. package/dist/es2019/card/v2/useFilePreview/globalScope/globalScope.js +48 -0
  39. package/dist/es2019/card/v2/useFilePreview/globalScope/index.js +2 -0
  40. package/dist/es2019/card/v2/useFilePreview/globalScope/printScript.js +16 -0
  41. package/dist/es2019/card/v2/useFilePreview/globalScope/types.js +1 -0
  42. package/dist/es2019/card/v2/useFilePreview/helpers.js +61 -0
  43. package/dist/es2019/card/v2/useFilePreview/index.js +1 -0
  44. package/dist/es2019/card/v2/useFilePreview/types.js +1 -0
  45. package/dist/es2019/card/v2/{useFilePreview.js → useFilePreview/useFilePreview.js} +18 -132
  46. package/dist/es2019/inline/loader.js +1 -1
  47. package/dist/es2019/utils/ufoExperiences.js +1 -1
  48. package/dist/esm/card/card.js +1 -1
  49. package/dist/esm/card/media-card-analytics-error-boundary.js +1 -1
  50. package/dist/esm/card/v2/cardV2.js +1 -1
  51. package/dist/esm/card/v2/cardViewV2.js +7 -6
  52. package/dist/esm/card/v2/useFilePreview/errors.js +124 -0
  53. package/dist/esm/card/v2/useFilePreview/getPreview/cache.js +32 -0
  54. package/dist/esm/card/v2/useFilePreview/getPreview/filePreviewStatus.js +40 -0
  55. package/dist/esm/card/v2/useFilePreview/getPreview/getPreview.js +112 -0
  56. package/dist/esm/card/v2/useFilePreview/getPreview/helpers.js +160 -0
  57. package/dist/esm/card/v2/useFilePreview/getPreview/index.js +3 -0
  58. package/dist/esm/card/v2/useFilePreview/getPreview/objectURLCache.js +78 -0
  59. package/dist/esm/card/v2/useFilePreview/getPreview/videoSnapshot.js +51 -0
  60. package/dist/esm/card/v2/useFilePreview/globalScope/getSSRData.js +8 -0
  61. package/dist/esm/card/v2/useFilePreview/globalScope/globalScope.js +56 -0
  62. package/dist/esm/card/v2/useFilePreview/globalScope/index.js +2 -0
  63. package/dist/esm/card/v2/useFilePreview/globalScope/printScript.js +25 -0
  64. package/dist/esm/card/v2/useFilePreview/globalScope/types.js +1 -0
  65. package/dist/esm/card/v2/useFilePreview/helpers.js +57 -0
  66. package/dist/esm/card/v2/useFilePreview/index.js +1 -0
  67. package/dist/esm/card/v2/useFilePreview/types.js +1 -0
  68. package/dist/esm/card/v2/{useFilePreview.js → useFilePreview/useFilePreview.js} +41 -177
  69. package/dist/esm/inline/loader.js +1 -1
  70. package/dist/esm/utils/ufoExperiences.js +1 -1
  71. package/dist/types/card/v2/cardViewV2.d.ts +5 -4
  72. package/dist/types/card/v2/useFilePreview/errors.d.ts +38 -0
  73. package/dist/types/card/v2/useFilePreview/getPreview/cache.d.ts +21 -0
  74. package/dist/types/card/v2/useFilePreview/getPreview/filePreviewStatus.d.ts +4 -0
  75. package/dist/types/card/v2/useFilePreview/getPreview/getPreview.d.ts +9 -0
  76. package/dist/types/card/v2/useFilePreview/getPreview/helpers.d.ts +10 -0
  77. package/dist/types/card/v2/useFilePreview/getPreview/index.d.ts +3 -0
  78. package/dist/types/card/v2/useFilePreview/getPreview/objectURLCache.d.ts +12 -0
  79. package/dist/types/card/v2/useFilePreview/getPreview/videoSnapshot.d.ts +1 -0
  80. package/dist/types/card/v2/useFilePreview/globalScope/getSSRData.d.ts +3 -0
  81. package/dist/types/card/v2/useFilePreview/globalScope/globalScope.d.ts +15 -0
  82. package/dist/types/card/v2/useFilePreview/globalScope/index.d.ts +4 -0
  83. package/dist/types/card/v2/useFilePreview/globalScope/printScript.d.ts +2 -0
  84. package/dist/types/card/v2/useFilePreview/globalScope/types.d.ts +8 -0
  85. package/dist/types/card/v2/useFilePreview/helpers.d.ts +11 -0
  86. package/dist/types/card/v2/useFilePreview/index.d.ts +2 -0
  87. package/dist/types/card/v2/useFilePreview/types.d.ts +18 -0
  88. package/dist/{types-ts4.5/card/v2 → types/card/v2/useFilePreview}/useFilePreview.d.ts +8 -8
  89. package/dist/types-ts4.5/card/v2/cardViewV2.d.ts +5 -4
  90. package/dist/types-ts4.5/card/v2/useFilePreview/errors.d.ts +38 -0
  91. package/dist/types-ts4.5/card/v2/useFilePreview/getPreview/cache.d.ts +21 -0
  92. package/dist/types-ts4.5/card/v2/useFilePreview/getPreview/filePreviewStatus.d.ts +4 -0
  93. package/dist/types-ts4.5/card/v2/useFilePreview/getPreview/getPreview.d.ts +9 -0
  94. package/dist/types-ts4.5/card/v2/useFilePreview/getPreview/helpers.d.ts +10 -0
  95. package/dist/types-ts4.5/card/v2/useFilePreview/getPreview/index.d.ts +3 -0
  96. package/dist/types-ts4.5/card/v2/useFilePreview/getPreview/objectURLCache.d.ts +12 -0
  97. package/dist/types-ts4.5/card/v2/useFilePreview/getPreview/videoSnapshot.d.ts +1 -0
  98. package/dist/types-ts4.5/card/v2/useFilePreview/globalScope/getSSRData.d.ts +3 -0
  99. package/dist/types-ts4.5/card/v2/useFilePreview/globalScope/globalScope.d.ts +15 -0
  100. package/dist/types-ts4.5/card/v2/useFilePreview/globalScope/index.d.ts +4 -0
  101. package/dist/types-ts4.5/card/v2/useFilePreview/globalScope/printScript.d.ts +2 -0
  102. package/dist/types-ts4.5/card/v2/useFilePreview/globalScope/types.d.ts +8 -0
  103. package/dist/types-ts4.5/card/v2/useFilePreview/helpers.d.ts +11 -0
  104. package/dist/types-ts4.5/card/v2/useFilePreview/index.d.ts +2 -0
  105. package/dist/types-ts4.5/card/v2/useFilePreview/types.d.ts +18 -0
  106. package/dist/{types/card/v2 → types-ts4.5/card/v2/useFilePreview}/useFilePreview.d.ts +8 -8
  107. package/package.json +2 -2
@@ -4,7 +4,7 @@ import { extractErrorInfo, getRenderErrorRequestMetadata } from './analytics';
4
4
  import { MediaCardError } from '../errors';
5
5
  import { getMediaEnvironment, getMediaRegion } from '@atlaskit/media-client';
6
6
  const packageName = "@atlaskit/media-card";
7
- const packageVersion = "77.5.0";
7
+ const packageVersion = "77.5.2";
8
8
  let concurrentExperience;
9
9
  const getExperience = id => {
10
10
  if (!concurrentExperience) {
@@ -40,7 +40,7 @@ import { getMediaCardCursor } from '../utils/getMediaCardCursor';
40
40
  import { completeUfoExperience, startUfoExperience, abortUfoExperience } from '../utils/ufoExperiences';
41
41
  import { generateUniqueId } from '../utils/generateUniqueId';
42
42
  var packageName = "@atlaskit/media-card";
43
- var packageVersion = "77.5.0";
43
+ var packageVersion = "77.5.2";
44
44
  export var CardBase = /*#__PURE__*/function (_Component) {
45
45
  _inherits(CardBase, _Component);
46
46
  var _super = _createSuper(CardBase);
@@ -83,7 +83,7 @@ var WrappedMediaCardAnalyticsErrorBoundary = /*#__PURE__*/function (_React$Compo
83
83
  }(React.Component);
84
84
  _defineProperty(WrappedMediaCardAnalyticsErrorBoundary, "displayName", 'MediaCardAnalyticsErrorBoundary');
85
85
  var packageName = "@atlaskit/media-card";
86
- var packageVersion = "77.5.0";
86
+ var packageVersion = "77.5.2";
87
87
  var MediaCardAnalyticsErrorBoundary = withMediaAnalyticsContext({
88
88
  packageVersion: packageVersion,
89
89
  packageName: packageName,
@@ -9,7 +9,7 @@ import { IntlProvider, injectIntl } from 'react-intl-next';
9
9
  import { ExternalImageCard } from './externalImageCard';
10
10
  import { FileCard } from './fileCard';
11
11
  var packageName = "@atlaskit/media-card";
12
- var packageVersion = "77.5.0";
12
+ var packageVersion = "77.5.2";
13
13
  export var CardV2Base = function CardV2Base(_ref) {
14
14
  var identifier = _ref.identifier,
15
15
  otherProps = _objectWithoutProperties(_ref, _excluded);
@@ -75,18 +75,19 @@ export var CardViewV2Base = function CardViewV2Base(_ref) {
75
75
  if (prevCardPreview.dataURI !== (cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI)) {
76
76
  return;
77
77
  }
78
-
79
78
  /*
80
79
  We render the icon & icon message always, even if there is cardPreview available.
81
- If the image fails to load/render, the icon will remain, i.e. the user won't see a change until the root card decides to chage status to error.
82
- If the image renders successfully, we switch this variable to hide the icon & icon message behind the thumbnail in case the image has transparency.
83
- It is less likely that root component replaces a suceeded cardPreview for a failed one than the opposite case. Therefore we prefer to hide the icon instead show when the image fails, for a smoother transition
80
+ If the image fails to load/render, the icon will remain, i.e. the user won't see a change until the root card decides to chage status to error.
81
+ If the image renders successfully, we switch this variable to hide the icon & icon message behind the thumbnail in case the image has transparency.
82
+ It is less likely that root component replaces a suceeded cardPreview for a failed one than the opposite case. Therefore we prefer to hide the icon instead show when the image fails, for a smoother transition
84
83
  */
85
-
86
84
  setDidImageRender(true);
87
85
  onImageLoad === null || onImageLoad === void 0 || onImageLoad(cardPreview);
88
86
  };
89
- var handleOnImageError = function handleOnImageError(cardPreview) {
87
+ var handleOnImageError = function handleOnImageError(prevCardPreview) {
88
+ if (prevCardPreview.dataURI !== (cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI)) {
89
+ return;
90
+ }
90
91
  setDidImageRender(false);
91
92
  onImageError === null || onImageError === void 0 || onImageError(cardPreview);
92
93
  };
@@ -0,0 +1,124 @@
1
+ import _createClass from "@babel/runtime/helpers/createClass";
2
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
+ import _inherits from "@babel/runtime/helpers/inherits";
5
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
+ import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
8
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9
+ 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; } }
10
+ /**
11
+ * Primary reason is logged through Data Portal.
12
+ * Make sure all the values are whitelisted in Measure -> Event Regitry -> "mediaCardRender failed" event
13
+ */
14
+
15
+ export var MediaFilePreviewError = /*#__PURE__*/function (_Error) {
16
+ _inherits(MediaFilePreviewError, _Error);
17
+ var _super = _createSuper(MediaFilePreviewError);
18
+ function MediaFilePreviewError(primaryReason, secondaryError) {
19
+ var _this;
20
+ _classCallCheck(this, MediaFilePreviewError);
21
+ _this = _super.call(this, primaryReason);
22
+ // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget
23
+ _this.primaryReason = primaryReason;
24
+ _this.secondaryError = secondaryError;
25
+ Object.setPrototypeOf(_assertThisInitialized(_this), (this instanceof MediaFilePreviewError ? this.constructor : void 0).prototype);
26
+
27
+ // https://v8.dev/docs/stack-trace-api
28
+ if ('captureStackTrace' in Error) {
29
+ Error.captureStackTrace(_assertThisInitialized(_this), this instanceof MediaFilePreviewError ? this.constructor : void 0);
30
+ }
31
+ return _this;
32
+ }
33
+ return _createClass(MediaFilePreviewError);
34
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
35
+ export var LocalPreviewError = /*#__PURE__*/function (_MediaFilePreviewErro) {
36
+ _inherits(LocalPreviewError, _MediaFilePreviewErro);
37
+ var _super2 = _createSuper(LocalPreviewError);
38
+ function LocalPreviewError(primaryReason, secondaryError) {
39
+ var _this2;
40
+ _classCallCheck(this, LocalPreviewError);
41
+ _this2 = _super2.call(this, primaryReason, secondaryError);
42
+ _this2.primaryReason = primaryReason;
43
+ _this2.secondaryError = secondaryError;
44
+ return _this2;
45
+ }
46
+ return _createClass(LocalPreviewError);
47
+ }(MediaFilePreviewError);
48
+ export var RemotePreviewError = /*#__PURE__*/function (_MediaFilePreviewErro2) {
49
+ _inherits(RemotePreviewError, _MediaFilePreviewErro2);
50
+ var _super3 = _createSuper(RemotePreviewError);
51
+ function RemotePreviewError(primaryReason, secondaryError) {
52
+ var _this3;
53
+ _classCallCheck(this, RemotePreviewError);
54
+ _this3 = _super3.call(this, primaryReason, secondaryError);
55
+ _this3.primaryReason = primaryReason;
56
+ _this3.secondaryError = secondaryError;
57
+ return _this3;
58
+ }
59
+ return _createClass(RemotePreviewError);
60
+ }(MediaFilePreviewError);
61
+ export var SsrPreviewError = /*#__PURE__*/function (_MediaFilePreviewErro3) {
62
+ _inherits(SsrPreviewError, _MediaFilePreviewErro3);
63
+ var _super4 = _createSuper(SsrPreviewError);
64
+ function SsrPreviewError(primaryReason, secondaryError) {
65
+ var _this4;
66
+ _classCallCheck(this, SsrPreviewError);
67
+ _this4 = _super4.call(this, primaryReason, secondaryError);
68
+ _this4.primaryReason = primaryReason;
69
+ _this4.secondaryError = secondaryError;
70
+ return _this4;
71
+ }
72
+ return _createClass(SsrPreviewError);
73
+ }(MediaFilePreviewError);
74
+ var getImageLoadPrimaryReason = function getImageLoadPrimaryReason(source) {
75
+ switch (source) {
76
+ case 'cache-remote':
77
+ return 'cache-remote-uri';
78
+ case 'cache-local':
79
+ return 'cache-local-uri';
80
+ case 'external':
81
+ return 'external-uri';
82
+ case 'local':
83
+ return 'local-uri';
84
+ case 'remote':
85
+ return 'remote-uri';
86
+ // This fail reason will come from a bug, most likely.
87
+ default:
88
+ return "unknown-uri";
89
+ }
90
+ };
91
+ export var ImageLoadError = /*#__PURE__*/function (_MediaFilePreviewErro4) {
92
+ _inherits(ImageLoadError, _MediaFilePreviewErro4);
93
+ var _super5 = _createSuper(ImageLoadError);
94
+ function ImageLoadError(source) {
95
+ _classCallCheck(this, ImageLoadError);
96
+ return _super5.call(this, getImageLoadPrimaryReason(source));
97
+ }
98
+ return _createClass(ImageLoadError);
99
+ }(MediaFilePreviewError);
100
+ export function isMediaFilePreviewError(err) {
101
+ return err instanceof MediaFilePreviewError;
102
+ }
103
+ export var isLocalPreviewError = function isLocalPreviewError(err) {
104
+ return err instanceof LocalPreviewError;
105
+ };
106
+ export var isRemotePreviewError = function isRemotePreviewError(err) {
107
+ return err instanceof RemotePreviewError;
108
+ };
109
+ export var isUnsupportedLocalPreviewError = function isUnsupportedLocalPreviewError(err) {
110
+ return isMediaFilePreviewError(err) && err.primaryReason === 'local-preview-unsupported';
111
+ };
112
+
113
+ // In a try/catch statement, the error caught is the type of unknown.
114
+ // We can use this helper to ensure that the error handled is the type of MediaFilePreviewError if unsure
115
+ // If updatePrimaryReason is true, if it's a MediaFilePreviewError already, it will update it's primary reason
116
+ export var ensureMediaFilePreviewError = function ensureMediaFilePreviewError(primaryReason, error, updatePrimaryReason) {
117
+ if (isMediaFilePreviewError(error)) {
118
+ if (updatePrimaryReason && error.primaryReason !== primaryReason) {
119
+ return new MediaFilePreviewError(primaryReason, error.secondaryError);
120
+ }
121
+ return error;
122
+ }
123
+ return new MediaFilePreviewError(primaryReason, error);
124
+ };
@@ -0,0 +1,32 @@
1
+ import _createClass from "@babel/runtime/helpers/createClass";
2
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+ import { createObjectURLCache } from './objectURLCache';
5
+
6
+ // Dimensions are used to create a key.
7
+ // Cache is invalidated when different dimensions are provided.
8
+ export var getCacheKey = function getCacheKey(id, mode) {
9
+ var resizeMode = mode || 'crop';
10
+ return [id, resizeMode].join('-');
11
+ };
12
+ export var CardPreviewCacheImpl = /*#__PURE__*/_createClass(function CardPreviewCacheImpl(previewCache) {
13
+ var _this = this;
14
+ _classCallCheck(this, CardPreviewCacheImpl);
15
+ _defineProperty(this, "get", function (id, mode) {
16
+ var cacheKey = getCacheKey(id, mode);
17
+ return _this.previewCache.get(cacheKey);
18
+ });
19
+ _defineProperty(this, "set", function (id, mode, cardPreview) {
20
+ var cacheKey = getCacheKey(id, mode);
21
+ _this.previewCache.set(cacheKey, cardPreview);
22
+ });
23
+ _defineProperty(this, "remove", function (id, mode) {
24
+ var cacheKey = getCacheKey(id, mode);
25
+ _this.previewCache.remove(cacheKey);
26
+ });
27
+ _defineProperty(this, "clear", function () {
28
+ _this.previewCache.clear();
29
+ });
30
+ this.previewCache = previewCache;
31
+ });
32
+ export var mediaFilePreviewCache = new CardPreviewCacheImpl(createObjectURLCache());
@@ -0,0 +1,40 @@
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
+ };
@@ -0,0 +1,112 @@
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 { addFileAttrsToUrl } from '@atlaskit/media-client';
7
+ import { mediaFilePreviewCache } from './cache';
8
+ import { getLocalPreview, getRemotePreview } from './helpers';
9
+ import { SsrPreviewError } from '../errors';
10
+ var extendAndCachePreview = function extendAndCachePreview(id, mode, preview, mediaBlobUrlAttrs) {
11
+ var source;
12
+ switch (preview.source) {
13
+ case 'local':
14
+ source = 'cache-local';
15
+ break;
16
+ case 'remote':
17
+ source = 'cache-remote';
18
+ break;
19
+ case 'ssr-server':
20
+ source = 'cache-ssr-server';
21
+ break;
22
+ case 'ssr-client':
23
+ source = 'cache-ssr-client';
24
+ break;
25
+ default:
26
+ source = preview.source;
27
+ }
28
+ // We want to embed some meta context into dataURI for Copy/Paste to work.
29
+ var dataURI = mediaBlobUrlAttrs ? addFileAttrsToUrl(preview.dataURI, mediaBlobUrlAttrs) : preview.dataURI;
30
+ // We store new cardPreview into cache
31
+ mediaFilePreviewCache.set(id, mode, _objectSpread(_objectSpread({}, preview), {}, {
32
+ source: source,
33
+ dataURI: dataURI
34
+ }));
35
+ return _objectSpread(_objectSpread({}, preview), {}, {
36
+ dataURI: dataURI
37
+ });
38
+ };
39
+ export var getSSRCardPreview = function getSSRCardPreview(ssr, mediaClient, id, params, mediaBlobUrlAttrs) {
40
+ var dataURI;
41
+ try {
42
+ var rawDataURI = mediaClient.getImageUrlSync(id, params);
43
+ // We want to embed some meta context into dataURI for Copy/Paste to work.
44
+ dataURI = mediaBlobUrlAttrs ? addFileAttrsToUrl(rawDataURI, mediaBlobUrlAttrs) : rawDataURI;
45
+ var source = ssr === 'client' ? 'ssr-client' : 'ssr-server';
46
+ return {
47
+ dataURI: dataURI,
48
+ source: source,
49
+ orientation: 1
50
+ };
51
+ } catch (e) {
52
+ var reason = ssr === 'server' ? 'ssr-server-uri' : 'ssr-client-uri';
53
+ throw new SsrPreviewError(reason, e instanceof Error ? e : undefined);
54
+ }
55
+ };
56
+ export var isLocalPreview = function isLocalPreview(preview) {
57
+ var localSources = ['local', 'cache-local'];
58
+ return localSources.includes(preview.source);
59
+ };
60
+ export var isSSRClientPreview = function isSSRClientPreview(preview) {
61
+ var ssrClientSources = ['ssr-client', 'cache-ssr-client'];
62
+ return ssrClientSources.includes(preview.source);
63
+ };
64
+ export var isSSRDataPreview = function isSSRDataPreview(preview) {
65
+ return preview.source === 'ssr-data';
66
+ };
67
+ export var getAndCacheRemotePreview = /*#__PURE__*/function () {
68
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(mediaClient, id, dimensions, params, mediaBlobUrlAttrs, traceContext) {
69
+ var remotePreview;
70
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
71
+ while (1) switch (_context.prev = _context.next) {
72
+ case 0:
73
+ _context.next = 2;
74
+ return getRemotePreview(mediaClient, id, params, traceContext);
75
+ case 2:
76
+ remotePreview = _context.sent;
77
+ return _context.abrupt("return", extendAndCachePreview(id, params.mode, _objectSpread(_objectSpread({}, remotePreview), {}, {
78
+ dimensions: dimensions
79
+ }), mediaBlobUrlAttrs));
80
+ case 4:
81
+ case "end":
82
+ return _context.stop();
83
+ }
84
+ }, _callee);
85
+ }));
86
+ return function getAndCacheRemotePreview(_x, _x2, _x3, _x4, _x5, _x6) {
87
+ return _ref.apply(this, arguments);
88
+ };
89
+ }();
90
+ export var getAndCacheLocalPreview = /*#__PURE__*/function () {
91
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id, filePreview, dimensions, mode, mediaBlobUrlAttrs) {
92
+ var localPreview;
93
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
94
+ while (1) switch (_context2.prev = _context2.next) {
95
+ case 0:
96
+ _context2.next = 2;
97
+ return getLocalPreview(filePreview);
98
+ case 2:
99
+ localPreview = _context2.sent;
100
+ return _context2.abrupt("return", extendAndCachePreview(id, mode, _objectSpread(_objectSpread({}, localPreview), {}, {
101
+ dimensions: dimensions
102
+ }), mediaBlobUrlAttrs));
103
+ case 4:
104
+ case "end":
105
+ return _context2.stop();
106
+ }
107
+ }, _callee2);
108
+ }));
109
+ return function getAndCacheLocalPreview(_x7, _x8, _x9, _x10, _x11) {
110
+ return _ref2.apply(this, arguments);
111
+ };
112
+ }();
@@ -0,0 +1,160 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import { takeSnapshot } from './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 getLocalPreview = /*#__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 = 23;
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
+ throw new LocalPreviewError('local-preview-unsupported');
121
+ case 24:
122
+ case "end":
123
+ return _context3.stop();
124
+ }
125
+ }, _callee3, null, [[0, 7]]);
126
+ }));
127
+ return function getLocalPreview(_x3) {
128
+ return _ref3.apply(this, arguments);
129
+ };
130
+ }();
131
+ export var getRemotePreview = /*#__PURE__*/function () {
132
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(mediaClient, id, params, traceContext) {
133
+ var blob;
134
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
135
+ while (1) switch (_context4.prev = _context4.next) {
136
+ case 0:
137
+ _context4.prev = 0;
138
+ _context4.next = 3;
139
+ return mediaClient.getImage(id, params, undefined, undefined, traceContext);
140
+ case 3:
141
+ blob = _context4.sent;
142
+ return _context4.abrupt("return", {
143
+ dataURI: URL.createObjectURL(blob),
144
+ orientation: 1,
145
+ source: 'remote'
146
+ });
147
+ case 7:
148
+ _context4.prev = 7;
149
+ _context4.t0 = _context4["catch"](0);
150
+ throw new RemotePreviewError('remote-preview-fetch', _context4.t0 instanceof Error ? _context4.t0 : undefined);
151
+ case 10:
152
+ case "end":
153
+ return _context4.stop();
154
+ }
155
+ }, _callee4, null, [[0, 7]]);
156
+ }));
157
+ return function getRemotePreview(_x4, _x5, _x6, _x7) {
158
+ return _ref4.apply(this, arguments);
159
+ };
160
+ }();
@@ -0,0 +1,3 @@
1
+ export { mediaFilePreviewCache } from './cache';
2
+ export { isPreviewableStatus, extractFilePreviewStatus } from './filePreviewStatus';
3
+ export { getSSRCardPreview, isLocalPreview, isSSRClientPreview, isSSRDataPreview, getAndCacheRemotePreview, getAndCacheLocalPreview } from './getPreview';
@@ -0,0 +1,78 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _get from "@babel/runtime/helpers/get";
4
+ import _inherits from "@babel/runtime/helpers/inherits";
5
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
+ 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; } }
9
+ import { LRUMap } from 'lru_map';
10
+ import { EventEmitter2 } from 'eventemitter2';
11
+ export var PREVIEW_CACHE_LRU_SIZE = 50;
12
+ var ExtendedLRUCache = /*#__PURE__*/function (_LRUMap) {
13
+ _inherits(ExtendedLRUCache, _LRUMap);
14
+ var _super = _createSuper(ExtendedLRUCache);
15
+ function ExtendedLRUCache(limit) {
16
+ var _this;
17
+ _classCallCheck(this, ExtendedLRUCache);
18
+ _this = _super.call(this, limit);
19
+ _this.eventEmitter = new EventEmitter2();
20
+ return _this;
21
+ }
22
+ _createClass(ExtendedLRUCache, [{
23
+ key: "shift",
24
+ value: function shift() {
25
+ var entry = _get(_getPrototypeOf(ExtendedLRUCache.prototype), "shift", this).call(this);
26
+ this.eventEmitter.emit('shift', entry);
27
+ return entry;
28
+ }
29
+ }, {
30
+ key: "on",
31
+ value: function on(event, callback) {
32
+ this.eventEmitter.on(event, callback);
33
+ }
34
+ }]);
35
+ return ExtendedLRUCache;
36
+ }(LRUMap);
37
+ export var ObjectURLCache = /*#__PURE__*/function () {
38
+ function ObjectURLCache(size) {
39
+ _classCallCheck(this, ObjectURLCache);
40
+ this.cache = new ExtendedLRUCache(size);
41
+ this.cache.on('shift', function (entry) {
42
+ if (entry && entry[1].dataURI) {
43
+ URL.revokeObjectURL(entry[1].dataURI);
44
+ }
45
+ });
46
+ }
47
+ _createClass(ObjectURLCache, [{
48
+ key: "has",
49
+ value: function has(key) {
50
+ return !!this.cache.find(key);
51
+ }
52
+ }, {
53
+ key: "get",
54
+ value: function get(key) {
55
+ return this.cache.get(key);
56
+ }
57
+ }, {
58
+ key: "set",
59
+ value: function set(key, value) {
60
+ this.cache.set(key, value);
61
+ }
62
+ }, {
63
+ key: "remove",
64
+ value: function remove(key) {
65
+ var removed = this.cache.delete(key);
66
+ removed && URL.revokeObjectURL(removed.dataURI);
67
+ }
68
+ }, {
69
+ key: "clear",
70
+ value: function clear() {
71
+ this.cache.clear();
72
+ }
73
+ }]);
74
+ return ObjectURLCache;
75
+ }();
76
+ export var createObjectURLCache = function createObjectURLCache() {
77
+ return new ObjectURLCache(PREVIEW_CACHE_LRU_SIZE);
78
+ };