@canlooks/can-ui 0.0.17 → 0.0.19
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/dist/cjs/components/image/imagePreview.d.ts +15 -3
- package/dist/cjs/components/image/imagePreview.js +21 -12
- package/dist/cjs/components/image/index.d.ts +1 -0
- package/dist/cjs/components/image/index.js +1 -0
- package/dist/cjs/extensions/documentViewer/documentViewer.js +1 -1
- package/dist/esm/components/image/imagePreview.d.ts +15 -3
- package/dist/esm/components/image/imagePreview.js +23 -14
- package/dist/esm/components/image/index.d.ts +1 -0
- package/dist/esm/components/image/index.js +1 -0
- package/dist/esm/extensions/documentViewer/documentViewer.js +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,22 @@
|
|
|
1
|
+
import { Ref, ReactNode } from 'react';
|
|
1
2
|
import { ModalProps } from '../modal';
|
|
2
|
-
import { ReactZoomPanPinchProps } from 'react-zoom-pan-pinch';
|
|
3
|
+
import { ReactZoomPanPinchContentRef, ReactZoomPanPinchProps } from 'react-zoom-pan-pinch';
|
|
3
4
|
export interface ImagePreviewProps extends ModalProps {
|
|
4
5
|
src?: string | string[];
|
|
6
|
+
defaultIndex?: number;
|
|
7
|
+
index?: number;
|
|
8
|
+
onIndexChange?(index: number): void;
|
|
5
9
|
defaultOpen?: boolean;
|
|
6
10
|
onOpenChange?(open: boolean): void;
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
/** 是否渲染旋转按钮{@default true} */
|
|
12
|
+
showRotate?: boolean;
|
|
13
|
+
/** 是否渲染放大缩小按钮{@default true} */
|
|
14
|
+
showZoom?: boolean;
|
|
15
|
+
/** 是否渲染关闭按钮{@default true }*/
|
|
16
|
+
showClose?: boolean;
|
|
17
|
+
/** 自定义右上角控制按钮 */
|
|
18
|
+
renderControl?: ReactNode;
|
|
19
|
+
transformWrapperProps?: ReactZoomPanPinchProps;
|
|
20
|
+
transformWrapperRef?: Ref<ReactZoomPanPinchContentRef>;
|
|
9
21
|
}
|
|
10
22
|
export declare const ImagePreview: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Omit<ImagePreviewProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>>;
|
|
@@ -10,23 +10,23 @@ const icons_1 = require("@ant-design/icons");
|
|
|
10
10
|
const button_1 = require("../button");
|
|
11
11
|
const react_zoom_pan_pinch_1 = require("react-zoom-pan-pinch");
|
|
12
12
|
const tooltip_1 = require("../tooltip");
|
|
13
|
-
exports.ImagePreview = (0, react_1.memo)((0, react_1.forwardRef)(({ src = [], defaultOpen = false, open, onOpenChange,
|
|
13
|
+
exports.ImagePreview = (0, react_1.memo)((0, react_1.forwardRef)(({ src = [], defaultIndex = 0, index, onIndexChange, defaultOpen = false, open, onOpenChange, showRotate = true, showZoom = true, showClose = true, renderControl, transformWrapperProps, transformWrapperRef, ...props }, ref) => {
|
|
14
14
|
const srcArr = Array.isArray(src) ? src : [src];
|
|
15
15
|
const [innerOpen, setInnerOpen] = (0, utils_1.useControlled)(defaultOpen, open, onOpenChange);
|
|
16
|
-
const [
|
|
17
|
-
const
|
|
16
|
+
const [innerIndex, setInnerIndex] = (0, utils_1.useControlled)(defaultIndex, index, onIndexChange);
|
|
17
|
+
const innerTransformWrapperRef = (0, react_1.useRef)(null);
|
|
18
18
|
const imgLoaded = () => {
|
|
19
|
-
|
|
19
|
+
innerTransformWrapperRef.current.centerView();
|
|
20
20
|
};
|
|
21
21
|
const prev = (e) => {
|
|
22
22
|
e.stopPropagation();
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
setInnerIndex(o => (o - 1 + srcArr.length) % srcArr.length);
|
|
24
|
+
innerTransformWrapperRef.current?.resetTransform();
|
|
25
25
|
};
|
|
26
26
|
const next = (e) => {
|
|
27
27
|
e.stopPropagation();
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
setInnerIndex(o => (o + 1) % srcArr.length);
|
|
29
|
+
innerTransformWrapperRef.current?.resetTransform();
|
|
30
30
|
};
|
|
31
31
|
const [rotate, setRotate] = (0, react_1.useState)(0);
|
|
32
32
|
const isPanning = (0, react_1.useRef)(false);
|
|
@@ -37,10 +37,19 @@ exports.ImagePreview = (0, react_1.memo)((0, react_1.forwardRef)(({ src = [], de
|
|
|
37
37
|
color: 'text'
|
|
38
38
|
};
|
|
39
39
|
return ((0, jsx_runtime_1.jsx)(modal_1.Modal, { ...props, ref: ref, css: imagePreview_style_1.style, className: (0, utils_1.classnames)(imagePreview_style_1.classes.root, props.className), open: innerOpen.current, maskProps: {
|
|
40
|
-
|
|
40
|
+
...props.maskProps,
|
|
41
|
+
children: ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: imagePreview_style_1.classes.control, children: [renderControl, showRotate &&
|
|
42
|
+
(0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { title: "\u65CB\u8F6C-90\u00B0", children: (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => setRotate(rotate - 90), children: (0, jsx_runtime_1.jsx)(icons_1.RotateLeftOutlined, {}) }) }), (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { title: "\u65CB\u8F6C90\u00B0", children: (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => setRotate(rotate + 90), children: (0, jsx_runtime_1.jsx)(icons_1.RotateRightOutlined, {}) }) })] }), showZoom &&
|
|
43
|
+
(0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { title: "\u7F29\u5C0F", children: (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => innerTransformWrapperRef.current.zoomOut(), children: (0, jsx_runtime_1.jsx)(icons_1.ZoomOutOutlined, {}) }) }), (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { title: "\u653E\u5927", children: (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => innerTransformWrapperRef.current.zoomIn(), children: (0, jsx_runtime_1.jsx)(icons_1.ZoomInOutlined, {}) }) }), (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { title: "\u9002\u5E94\u5C4F\u5E55", children: (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => innerTransformWrapperRef.current.resetTransform(), children: (0, jsx_runtime_1.jsx)(icons_1.FullscreenOutlined, {}) }) })] }), showClose &&
|
|
41
44
|
(0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: () => setInnerOpen(false), children: (0, jsx_runtime_1.jsx)(icons_1.CloseOutlined, {}) })] }), srcArr.length > 1 &&
|
|
42
|
-
(0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: imagePreview_style_1.classes.swap, children: [(0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: prev, children: (0, jsx_runtime_1.jsx)(icons_1.LeftOutlined, {}) }), (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: next, children: (0, jsx_runtime_1.jsx)(icons_1.RightOutlined, {}) })] }), (0, jsx_runtime_1.jsxs)("div", { className: imagePreview_style_1.classes.counter, children: [
|
|
43
|
-
}, children: (0, jsx_runtime_1.jsx)(react_zoom_pan_pinch_1.TransformWrapper, { smooth: false, ...
|
|
45
|
+
(0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: imagePreview_style_1.classes.swap, children: [(0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: prev, children: (0, jsx_runtime_1.jsx)(icons_1.LeftOutlined, {}) }), (0, jsx_runtime_1.jsx)(button_1.Button, { ...commonControlProps, onClick: next, children: (0, jsx_runtime_1.jsx)(icons_1.RightOutlined, {}) })] }), (0, jsx_runtime_1.jsxs)("div", { className: imagePreview_style_1.classes.counter, children: [innerIndex.current + 1, " / ", srcArr.length] })] })] }))
|
|
46
|
+
}, children: (0, jsx_runtime_1.jsx)(react_zoom_pan_pinch_1.TransformWrapper, { smooth: false, ...transformWrapperProps, ref: (0, utils_1.cloneRef)(transformWrapperRef, innerTransformWrapperRef), minScale: .2, onPanning: (ref, e) => {
|
|
47
|
+
transformWrapperProps?.onPanning?.(ref, e);
|
|
48
|
+
isPanning.current = true;
|
|
49
|
+
}, onPanningStop: (ref, e) => {
|
|
50
|
+
transformWrapperProps?.onPanningStop?.(ref, e);
|
|
51
|
+
isPanning.current && setTimeout(() => isPanning.current = false);
|
|
52
|
+
}, children: (0, jsx_runtime_1.jsx)(react_zoom_pan_pinch_1.TransformComponent, { wrapperClass: imagePreview_style_1.classes.imageWrapper, contentClass: imagePreview_style_1.classes.image, wrapperProps: {
|
|
44
53
|
onClick: () => !isPanning.current && setInnerOpen(false)
|
|
45
|
-
}, children: (0, jsx_runtime_1.jsx)("img", { src: srcArr[
|
|
54
|
+
}, children: (0, jsx_runtime_1.jsx)("img", { src: srcArr[innerIndex.current], style: { rotate: rotate + 'deg' }, onLoad: imgLoaded, alt: "" }) }) }) }));
|
|
46
55
|
}));
|
|
@@ -64,7 +64,7 @@ exports.DocumentViewer = (0, react_1.memo)((0, react_1.forwardRef)(({ src, filen
|
|
|
64
64
|
}
|
|
65
65
|
// image
|
|
66
66
|
if (mimeType.includes('image/')) {
|
|
67
|
-
return (0, jsx_runtime_1.jsx)(imagePreview_1.ImagePreview, { src: src, open: true,
|
|
67
|
+
return (0, jsx_runtime_1.jsx)(imagePreview_1.ImagePreview, { src: src, open: true, showClose: false });
|
|
68
68
|
}
|
|
69
69
|
return empty;
|
|
70
70
|
}));
|
|
@@ -1,10 +1,22 @@
|
|
|
1
|
+
import { Ref, ReactNode } from 'react';
|
|
1
2
|
import { ModalProps } from '../modal';
|
|
2
|
-
import { ReactZoomPanPinchProps } from 'react-zoom-pan-pinch';
|
|
3
|
+
import { ReactZoomPanPinchContentRef, ReactZoomPanPinchProps } from 'react-zoom-pan-pinch';
|
|
3
4
|
export interface ImagePreviewProps extends ModalProps {
|
|
4
5
|
src?: string | string[];
|
|
6
|
+
defaultIndex?: number;
|
|
7
|
+
index?: number;
|
|
8
|
+
onIndexChange?(index: number): void;
|
|
5
9
|
defaultOpen?: boolean;
|
|
6
10
|
onOpenChange?(open: boolean): void;
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
/** 是否渲染旋转按钮{@default true} */
|
|
12
|
+
showRotate?: boolean;
|
|
13
|
+
/** 是否渲染放大缩小按钮{@default true} */
|
|
14
|
+
showZoom?: boolean;
|
|
15
|
+
/** 是否渲染关闭按钮{@default true }*/
|
|
16
|
+
showClose?: boolean;
|
|
17
|
+
/** 自定义右上角控制按钮 */
|
|
18
|
+
renderControl?: ReactNode;
|
|
19
|
+
transformWrapperProps?: ReactZoomPanPinchProps;
|
|
20
|
+
transformWrapperRef?: Ref<ReactZoomPanPinchContentRef>;
|
|
9
21
|
}
|
|
10
22
|
export declare const ImagePreview: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Omit<ImagePreviewProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>>;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { forwardRef, memo, useRef, useState } from 'react';
|
|
3
3
|
import { Modal } from '../modal';
|
|
4
|
-
import { classnames, useControlled } from '../../utils';
|
|
4
|
+
import { classnames, cloneRef, useControlled } from '../../utils';
|
|
5
5
|
import { classes, style } from './imagePreview.style';
|
|
6
6
|
import { CloseOutlined, FullscreenOutlined, LeftOutlined, RightOutlined, RotateLeftOutlined, RotateRightOutlined, ZoomInOutlined, ZoomOutOutlined } from '@ant-design/icons';
|
|
7
7
|
import { Button } from '../button';
|
|
8
8
|
import { TransformComponent, TransformWrapper } from 'react-zoom-pan-pinch';
|
|
9
9
|
import { Tooltip } from '../tooltip';
|
|
10
|
-
export const ImagePreview = memo(forwardRef(({ src = [], defaultOpen = false, open, onOpenChange,
|
|
10
|
+
export const ImagePreview = memo(forwardRef(({ src = [], defaultIndex = 0, index, onIndexChange, defaultOpen = false, open, onOpenChange, showRotate = true, showZoom = true, showClose = true, renderControl, transformWrapperProps, transformWrapperRef, ...props }, ref) => {
|
|
11
11
|
const srcArr = Array.isArray(src) ? src : [src];
|
|
12
12
|
const [innerOpen, setInnerOpen] = useControlled(defaultOpen, open, onOpenChange);
|
|
13
|
-
const [
|
|
14
|
-
const
|
|
13
|
+
const [innerIndex, setInnerIndex] = useControlled(defaultIndex, index, onIndexChange);
|
|
14
|
+
const innerTransformWrapperRef = useRef(null);
|
|
15
15
|
const imgLoaded = () => {
|
|
16
|
-
|
|
16
|
+
innerTransformWrapperRef.current.centerView();
|
|
17
17
|
};
|
|
18
18
|
const prev = (e) => {
|
|
19
19
|
e.stopPropagation();
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
setInnerIndex(o => (o - 1 + srcArr.length) % srcArr.length);
|
|
21
|
+
innerTransformWrapperRef.current?.resetTransform();
|
|
22
22
|
};
|
|
23
23
|
const next = (e) => {
|
|
24
24
|
e.stopPropagation();
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
setInnerIndex(o => (o + 1) % srcArr.length);
|
|
26
|
+
innerTransformWrapperRef.current?.resetTransform();
|
|
27
27
|
};
|
|
28
28
|
const [rotate, setRotate] = useState(0);
|
|
29
29
|
const isPanning = useRef(false);
|
|
@@ -34,10 +34,19 @@ export const ImagePreview = memo(forwardRef(({ src = [], defaultOpen = false, op
|
|
|
34
34
|
color: 'text'
|
|
35
35
|
};
|
|
36
36
|
return (_jsx(Modal, { ...props, ref: ref, css: style, className: classnames(classes.root, props.className), open: innerOpen.current, maskProps: {
|
|
37
|
-
|
|
37
|
+
...props.maskProps,
|
|
38
|
+
children: (_jsxs(_Fragment, { children: [_jsxs("div", { className: classes.control, children: [renderControl, showRotate &&
|
|
39
|
+
_jsxs(_Fragment, { children: [_jsx(Tooltip, { title: "\u65CB\u8F6C-90\u00B0", children: _jsx(Button, { ...commonControlProps, onClick: () => setRotate(rotate - 90), children: _jsx(RotateLeftOutlined, {}) }) }), _jsx(Tooltip, { title: "\u65CB\u8F6C90\u00B0", children: _jsx(Button, { ...commonControlProps, onClick: () => setRotate(rotate + 90), children: _jsx(RotateRightOutlined, {}) }) })] }), showZoom &&
|
|
40
|
+
_jsxs(_Fragment, { children: [_jsx(Tooltip, { title: "\u7F29\u5C0F", children: _jsx(Button, { ...commonControlProps, onClick: () => innerTransformWrapperRef.current.zoomOut(), children: _jsx(ZoomOutOutlined, {}) }) }), _jsx(Tooltip, { title: "\u653E\u5927", children: _jsx(Button, { ...commonControlProps, onClick: () => innerTransformWrapperRef.current.zoomIn(), children: _jsx(ZoomInOutlined, {}) }) }), _jsx(Tooltip, { title: "\u9002\u5E94\u5C4F\u5E55", children: _jsx(Button, { ...commonControlProps, onClick: () => innerTransformWrapperRef.current.resetTransform(), children: _jsx(FullscreenOutlined, {}) }) })] }), showClose &&
|
|
38
41
|
_jsx(Button, { ...commonControlProps, onClick: () => setInnerOpen(false), children: _jsx(CloseOutlined, {}) })] }), srcArr.length > 1 &&
|
|
39
|
-
_jsxs(_Fragment, { children: [_jsxs("div", { className: classes.swap, children: [_jsx(Button, { ...commonControlProps, onClick: prev, children: _jsx(LeftOutlined, {}) }), _jsx(Button, { ...commonControlProps, onClick: next, children: _jsx(RightOutlined, {}) })] }), _jsxs("div", { className: classes.counter, children: [
|
|
40
|
-
}, children: _jsx(TransformWrapper, { smooth: false, ...
|
|
42
|
+
_jsxs(_Fragment, { children: [_jsxs("div", { className: classes.swap, children: [_jsx(Button, { ...commonControlProps, onClick: prev, children: _jsx(LeftOutlined, {}) }), _jsx(Button, { ...commonControlProps, onClick: next, children: _jsx(RightOutlined, {}) })] }), _jsxs("div", { className: classes.counter, children: [innerIndex.current + 1, " / ", srcArr.length] })] })] }))
|
|
43
|
+
}, children: _jsx(TransformWrapper, { smooth: false, ...transformWrapperProps, ref: cloneRef(transformWrapperRef, innerTransformWrapperRef), minScale: .2, onPanning: (ref, e) => {
|
|
44
|
+
transformWrapperProps?.onPanning?.(ref, e);
|
|
45
|
+
isPanning.current = true;
|
|
46
|
+
}, onPanningStop: (ref, e) => {
|
|
47
|
+
transformWrapperProps?.onPanningStop?.(ref, e);
|
|
48
|
+
isPanning.current && setTimeout(() => isPanning.current = false);
|
|
49
|
+
}, children: _jsx(TransformComponent, { wrapperClass: classes.imageWrapper, contentClass: classes.image, wrapperProps: {
|
|
41
50
|
onClick: () => !isPanning.current && setInnerOpen(false)
|
|
42
|
-
}, children: _jsx("img", { src: srcArr[
|
|
51
|
+
}, children: _jsx("img", { src: srcArr[innerIndex.current], style: { rotate: rotate + 'deg' }, onLoad: imgLoaded, alt: "" }) }) }) }));
|
|
43
52
|
}));
|
|
@@ -58,7 +58,7 @@ export const DocumentViewer = memo(forwardRef(({ src, filename, onError, type, e
|
|
|
58
58
|
}
|
|
59
59
|
// image
|
|
60
60
|
if (mimeType.includes('image/')) {
|
|
61
|
-
return _jsx(ImagePreview, { src: src, open: true,
|
|
61
|
+
return _jsx(ImagePreview, { src: src, open: true, showClose: false });
|
|
62
62
|
}
|
|
63
63
|
return empty;
|
|
64
64
|
}));
|