@atlaskit/media-file-preview 0.4.2 → 0.5.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/media-file-preview
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#73279](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/73279) [`cdad00f21119`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/cdad00f21119) - Create useMediaImage hook
8
+
3
9
  ## 0.4.2
4
10
 
5
11
  ### Patch Changes
package/dist/cjs/index.js CHANGED
@@ -9,4 +9,11 @@ Object.defineProperty(exports, "useFilePreview", {
9
9
  return _useFilePreview.useFilePreview;
10
10
  }
11
11
  });
12
- var _useFilePreview = require("./useFilePreview");
12
+ Object.defineProperty(exports, "useMediaImage", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _useMediaImage.useMediaImage;
16
+ }
17
+ });
18
+ var _useFilePreview = require("./useFilePreview");
19
+ var _useMediaImage = require("./useMediaImage");
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useMediaImage = void 0;
7
+ var _react = require("react");
8
+ var _useFilePreview2 = require("./useFilePreview");
9
+ var useMediaImage = exports.useMediaImage = function useMediaImage(_ref) {
10
+ var identifier = _ref.identifier,
11
+ resizeMode = _ref.resizeMode,
12
+ dimensions = _ref.dimensions,
13
+ ssr = _ref.ssr,
14
+ mediaBlobUrlAttrs = _ref.mediaBlobUrlAttrs,
15
+ traceContext = _ref.traceContext,
16
+ skipRemote = _ref.skipRemote,
17
+ allowAnimated = _ref.allowAnimated,
18
+ upscale = _ref.upscale,
19
+ maxAge = _ref.maxAge,
20
+ onLoadCallback = _ref.onLoad,
21
+ onErrorCallback = _ref.onError;
22
+ var _useFilePreview = (0, _useFilePreview2.useFilePreview)({
23
+ identifier: identifier,
24
+ resizeMode: resizeMode,
25
+ dimensions: dimensions,
26
+ ssr: ssr,
27
+ mediaBlobUrlAttrs: mediaBlobUrlAttrs,
28
+ traceContext: traceContext,
29
+ skipRemote: skipRemote,
30
+ allowAnimated: allowAnimated,
31
+ upscale: upscale,
32
+ maxAge: maxAge
33
+ }),
34
+ preview = _useFilePreview.preview,
35
+ status = _useFilePreview.status,
36
+ error = _useFilePreview.error,
37
+ onImageError = _useFilePreview.onImageError,
38
+ onImageLoad = _useFilePreview.onImageLoad,
39
+ getSsrScriptProps = _useFilePreview.getSsrScriptProps;
40
+ var onLoad = (0, _react.useCallback)(function () {
41
+ onLoadCallback && onLoadCallback();
42
+ onImageLoad(preview);
43
+ }, [onImageLoad, onLoadCallback, preview]);
44
+ var onError = (0, _react.useCallback)(function () {
45
+ onErrorCallback && onErrorCallback();
46
+ onImageError(preview);
47
+ }, [onErrorCallback, onImageError, preview]);
48
+ var getImgProps = (0, _react.useCallback)(function () {
49
+ return {
50
+ src: preview === null || preview === void 0 ? void 0 : preview.dataURI,
51
+ onLoad: onLoad,
52
+ onError: onError,
53
+ 'data-test-file-id': identifier.id,
54
+ 'data-test-collection': identifier.collectionName,
55
+ 'data-test-preview-source': preview === null || preview === void 0 ? void 0 : preview.source
56
+ };
57
+ }, [identifier.collectionName, identifier.id, onError, onLoad, preview === null || preview === void 0 ? void 0 : preview.dataURI, preview === null || preview === void 0 ? void 0 : preview.source]);
58
+ return {
59
+ status: status,
60
+ error: error,
61
+ getImgProps: getImgProps,
62
+ getSsrScriptProps: getSsrScriptProps
63
+ };
64
+ };
@@ -1 +1,2 @@
1
- export { useFilePreview } from './useFilePreview';
1
+ export { useFilePreview } from './useFilePreview';
2
+ export { useMediaImage } from './useMediaImage';
@@ -0,0 +1,58 @@
1
+ import { useCallback } from 'react';
2
+ import { useFilePreview } from './useFilePreview';
3
+ export const useMediaImage = ({
4
+ identifier,
5
+ resizeMode,
6
+ dimensions,
7
+ ssr,
8
+ mediaBlobUrlAttrs,
9
+ traceContext,
10
+ skipRemote,
11
+ allowAnimated,
12
+ upscale,
13
+ maxAge,
14
+ onLoad: onLoadCallback,
15
+ onError: onErrorCallback
16
+ }) => {
17
+ const {
18
+ preview,
19
+ status,
20
+ error,
21
+ onImageError,
22
+ onImageLoad,
23
+ getSsrScriptProps
24
+ } = useFilePreview({
25
+ identifier,
26
+ resizeMode,
27
+ dimensions,
28
+ ssr,
29
+ mediaBlobUrlAttrs,
30
+ traceContext,
31
+ skipRemote,
32
+ allowAnimated,
33
+ upscale,
34
+ maxAge
35
+ });
36
+ const onLoad = useCallback(() => {
37
+ onLoadCallback && onLoadCallback();
38
+ onImageLoad(preview);
39
+ }, [onImageLoad, onLoadCallback, preview]);
40
+ const onError = useCallback(() => {
41
+ onErrorCallback && onErrorCallback();
42
+ onImageError(preview);
43
+ }, [onErrorCallback, onImageError, preview]);
44
+ const getImgProps = useCallback(() => ({
45
+ src: preview === null || preview === void 0 ? void 0 : preview.dataURI,
46
+ onLoad,
47
+ onError,
48
+ 'data-test-file-id': identifier.id,
49
+ 'data-test-collection': identifier.collectionName,
50
+ 'data-test-preview-source': preview === null || preview === void 0 ? void 0 : preview.source
51
+ }), [identifier.collectionName, identifier.id, onError, onLoad, preview === null || preview === void 0 ? void 0 : preview.dataURI, preview === null || preview === void 0 ? void 0 : preview.source]);
52
+ return {
53
+ status,
54
+ error,
55
+ getImgProps,
56
+ getSsrScriptProps
57
+ };
58
+ };
package/dist/esm/index.js CHANGED
@@ -1 +1,2 @@
1
- export { useFilePreview } from './useFilePreview';
1
+ export { useFilePreview } from './useFilePreview';
2
+ export { useMediaImage } from './useMediaImage';
@@ -0,0 +1,58 @@
1
+ import { useCallback } from 'react';
2
+ import { useFilePreview } from './useFilePreview';
3
+ export var useMediaImage = function useMediaImage(_ref) {
4
+ var identifier = _ref.identifier,
5
+ resizeMode = _ref.resizeMode,
6
+ dimensions = _ref.dimensions,
7
+ ssr = _ref.ssr,
8
+ mediaBlobUrlAttrs = _ref.mediaBlobUrlAttrs,
9
+ traceContext = _ref.traceContext,
10
+ skipRemote = _ref.skipRemote,
11
+ allowAnimated = _ref.allowAnimated,
12
+ upscale = _ref.upscale,
13
+ maxAge = _ref.maxAge,
14
+ onLoadCallback = _ref.onLoad,
15
+ onErrorCallback = _ref.onError;
16
+ var _useFilePreview = useFilePreview({
17
+ identifier: identifier,
18
+ resizeMode: resizeMode,
19
+ dimensions: dimensions,
20
+ ssr: ssr,
21
+ mediaBlobUrlAttrs: mediaBlobUrlAttrs,
22
+ traceContext: traceContext,
23
+ skipRemote: skipRemote,
24
+ allowAnimated: allowAnimated,
25
+ upscale: upscale,
26
+ maxAge: maxAge
27
+ }),
28
+ preview = _useFilePreview.preview,
29
+ status = _useFilePreview.status,
30
+ error = _useFilePreview.error,
31
+ onImageError = _useFilePreview.onImageError,
32
+ onImageLoad = _useFilePreview.onImageLoad,
33
+ getSsrScriptProps = _useFilePreview.getSsrScriptProps;
34
+ var onLoad = useCallback(function () {
35
+ onLoadCallback && onLoadCallback();
36
+ onImageLoad(preview);
37
+ }, [onImageLoad, onLoadCallback, preview]);
38
+ var onError = useCallback(function () {
39
+ onErrorCallback && onErrorCallback();
40
+ onImageError(preview);
41
+ }, [onErrorCallback, onImageError, preview]);
42
+ var getImgProps = useCallback(function () {
43
+ return {
44
+ src: preview === null || preview === void 0 ? void 0 : preview.dataURI,
45
+ onLoad: onLoad,
46
+ onError: onError,
47
+ 'data-test-file-id': identifier.id,
48
+ 'data-test-collection': identifier.collectionName,
49
+ 'data-test-preview-source': preview === null || preview === void 0 ? void 0 : preview.source
50
+ };
51
+ }, [identifier.collectionName, identifier.id, onError, onLoad, preview === null || preview === void 0 ? void 0 : preview.dataURI, preview === null || preview === void 0 ? void 0 : preview.source]);
52
+ return {
53
+ status: status,
54
+ error: error,
55
+ getImgProps: getImgProps,
56
+ getSsrScriptProps: getSsrScriptProps
57
+ };
58
+ };
@@ -1,2 +1,5 @@
1
1
  export { useFilePreview } from './useFilePreview';
2
+ export type { UseFilePreviewParams } from './useFilePreview';
3
+ export { useMediaImage } from './useMediaImage';
4
+ export type { UseMediaImageParams } from './useMediaImage';
2
5
  export type { MediaFilePreview } from './types';
@@ -0,0 +1,43 @@
1
+ /// <reference types="react" />
2
+ import { FileIdentifier, MediaBlobUrlAttrs, MediaStoreGetFileImageParams } from '@atlaskit/media-client';
3
+ import { MediaTraceContext, SSR } from '@atlaskit/media-common';
4
+ import { MediaFilePreviewDimensions } from './types';
5
+ export interface UseMediaImageParams {
6
+ /** Instance of file identifier. */
7
+ readonly identifier: FileIdentifier;
8
+ /** Resize the media to 'crop' | 'fit' | 'full-fit' */
9
+ readonly resizeMode?: MediaStoreGetFileImageParams['mode'];
10
+ /** Dimensions to be requested to the server. Will be scaled x2 in Retina Displays */
11
+ readonly dimensions?: MediaFilePreviewDimensions;
12
+ /** Server-Side-Rendering modes are "server" and "client" */
13
+ readonly ssr?: SSR;
14
+ /** Attributes to attach to the created Blob Url */
15
+ readonly mediaBlobUrlAttrs?: MediaBlobUrlAttrs;
16
+ /** Trace context to be passed to the backend requests */
17
+ readonly traceContext?: MediaTraceContext;
18
+ /** Do not fetch a remote preview. Helpful for lazy loading */
19
+ readonly skipRemote?: boolean;
20
+ /** Define whether an animated image is acceptable to return */
21
+ readonly allowAnimated?: boolean;
22
+ /** Define the upscale strategy for this image. */
23
+ readonly upscale?: boolean;
24
+ /** Make the client receive the response with the given max-age cache control header. Minimum: 0, maximum: 9223372036854776000.
25
+ */
26
+ readonly maxAge?: number;
27
+ /** On image load and on error callback from the parent. We are keeping the name same to streamline the customer experience when using these properties back to their image components */
28
+ readonly onLoad?: () => void;
29
+ readonly onError?: () => void;
30
+ }
31
+ export declare const useMediaImage: ({ identifier, resizeMode, dimensions, ssr, mediaBlobUrlAttrs, traceContext, skipRemote, allowAnimated, upscale, maxAge, onLoad: onLoadCallback, onError: onErrorCallback, }: UseMediaImageParams) => {
32
+ status: import("./types").MediaFilePreviewStatus;
33
+ error: import("./errors").MediaFilePreviewError | undefined;
34
+ getImgProps: () => {
35
+ src: string | undefined;
36
+ onLoad: () => void;
37
+ onError: () => void;
38
+ 'data-test-file-id': string;
39
+ 'data-test-collection': string | undefined;
40
+ 'data-test-preview-source': import("./types").MediaFilePreviewSource | undefined;
41
+ };
42
+ getSsrScriptProps: (() => import("react").ScriptHTMLAttributes<HTMLScriptElement>) | undefined;
43
+ };
@@ -1,2 +1,5 @@
1
1
  export { useFilePreview } from './useFilePreview';
2
+ export type { UseFilePreviewParams } from './useFilePreview';
3
+ export { useMediaImage } from './useMediaImage';
4
+ export type { UseMediaImageParams } from './useMediaImage';
2
5
  export type { MediaFilePreview } from './types';
@@ -0,0 +1,43 @@
1
+ /// <reference types="react" />
2
+ import { FileIdentifier, MediaBlobUrlAttrs, MediaStoreGetFileImageParams } from '@atlaskit/media-client';
3
+ import { MediaTraceContext, SSR } from '@atlaskit/media-common';
4
+ import { MediaFilePreviewDimensions } from './types';
5
+ export interface UseMediaImageParams {
6
+ /** Instance of file identifier. */
7
+ readonly identifier: FileIdentifier;
8
+ /** Resize the media to 'crop' | 'fit' | 'full-fit' */
9
+ readonly resizeMode?: MediaStoreGetFileImageParams['mode'];
10
+ /** Dimensions to be requested to the server. Will be scaled x2 in Retina Displays */
11
+ readonly dimensions?: MediaFilePreviewDimensions;
12
+ /** Server-Side-Rendering modes are "server" and "client" */
13
+ readonly ssr?: SSR;
14
+ /** Attributes to attach to the created Blob Url */
15
+ readonly mediaBlobUrlAttrs?: MediaBlobUrlAttrs;
16
+ /** Trace context to be passed to the backend requests */
17
+ readonly traceContext?: MediaTraceContext;
18
+ /** Do not fetch a remote preview. Helpful for lazy loading */
19
+ readonly skipRemote?: boolean;
20
+ /** Define whether an animated image is acceptable to return */
21
+ readonly allowAnimated?: boolean;
22
+ /** Define the upscale strategy for this image. */
23
+ readonly upscale?: boolean;
24
+ /** Make the client receive the response with the given max-age cache control header. Minimum: 0, maximum: 9223372036854776000.
25
+ */
26
+ readonly maxAge?: number;
27
+ /** On image load and on error callback from the parent. We are keeping the name same to streamline the customer experience when using these properties back to their image components */
28
+ readonly onLoad?: () => void;
29
+ readonly onError?: () => void;
30
+ }
31
+ export declare const useMediaImage: ({ identifier, resizeMode, dimensions, ssr, mediaBlobUrlAttrs, traceContext, skipRemote, allowAnimated, upscale, maxAge, onLoad: onLoadCallback, onError: onErrorCallback, }: UseMediaImageParams) => {
32
+ status: import("./types").MediaFilePreviewStatus;
33
+ error: import("./errors").MediaFilePreviewError | undefined;
34
+ getImgProps: () => {
35
+ src: string | undefined;
36
+ onLoad: () => void;
37
+ onError: () => void;
38
+ 'data-test-file-id': string;
39
+ 'data-test-collection': string | undefined;
40
+ 'data-test-preview-source': import("./types").MediaFilePreviewSource | undefined;
41
+ };
42
+ getSsrScriptProps: (() => import("react").ScriptHTMLAttributes<HTMLScriptElement>) | undefined;
43
+ };
@@ -0,0 +1,30 @@
1
+ /* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
2
+ /* eslint-disable @atlaskit/design-system/prefer-primitives */
3
+ import React, { ReactNode } from 'react';
4
+
5
+ type TerminalTextDisplayProps = {
6
+ children: ReactNode;
7
+ };
8
+
9
+ export const TerminalTextDisplay: React.FC<TerminalTextDisplayProps> = ({
10
+ children,
11
+ }): React.ReactElement | null => (
12
+ <div
13
+ style={{
14
+ backgroundColor: '#000000',
15
+ color: '#33FF00',
16
+ borderRadius: 5,
17
+ // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview
18
+ padding: 20,
19
+ fontFamily: 'Courier New, monospace',
20
+ lineHeight: '1.4',
21
+ maxWidth: 600,
22
+ width: '100%',
23
+ fontSize: '1.1em',
24
+ whiteSpace: 'pre-wrap',
25
+ overflow: 'auto',
26
+ }}
27
+ >
28
+ {children}
29
+ </div>
30
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-file-preview",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "A React Hook to fetch and render file previews. It's overloaded with fancy features like SSR, lazy loading, memory cache and local preview.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -35,7 +35,7 @@
35
35
  ".": "./src/index.ts"
36
36
  },
37
37
  "dependencies": {
38
- "@atlaskit/media-client": "^26.1.0",
38
+ "@atlaskit/media-client": "^26.2.0",
39
39
  "@atlaskit/media-client-react": "^2.0.1",
40
40
  "@atlaskit/media-common": "^11.0.0",
41
41
  "@atlaskit/media-ui": "^25.1.0",