@lateralus-ai/shipping-ui 1.4.6 → 1.4.8
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/components/PdfViewer/ImageViewer.d.ts +2 -1
- package/dist/index.cjs +38 -38
- package/dist/index.esm.js +4499 -4492
- package/package.json +1 -1
- package/src/components/PdfViewer/ImageViewer.tsx +44 -42
package/package.json
CHANGED
|
@@ -1,58 +1,60 @@
|
|
|
1
|
-
import { IconButton, ButtonGroup, Tooltip } from "@material-tailwind/react"
|
|
2
|
-
import { ModalPanel } from "../ModalPanel"
|
|
3
|
-
import ExpandIcon from "../icons/ExpandIcon"
|
|
4
|
-
import { Icon } from "@iconify/react"
|
|
5
|
-
import { ChangeEvent, useEffect, useState } from "react"
|
|
6
|
-
import { useZoom } from "./useZoom"
|
|
7
|
-
import { useRotation } from "./useRotation"
|
|
8
|
-
import { usePanning } from "./usePanning"
|
|
9
|
-
import { usePageManagement } from "./usePageManagement"
|
|
10
|
-
import { cn } from "../../utils/cn"
|
|
1
|
+
import { IconButton, ButtonGroup, Tooltip } from "@material-tailwind/react"
|
|
2
|
+
import { ModalPanel } from "../ModalPanel"
|
|
3
|
+
import ExpandIcon from "../icons/ExpandIcon"
|
|
4
|
+
import { Icon } from "@iconify/react"
|
|
5
|
+
import { ChangeEvent, useEffect, useState } from "react"
|
|
6
|
+
import { useZoom } from "./useZoom"
|
|
7
|
+
import { useRotation } from "./useRotation"
|
|
8
|
+
import { usePanning } from "./usePanning"
|
|
9
|
+
import { usePageManagement } from "./usePageManagement"
|
|
10
|
+
import { cn } from "../../utils/cn"
|
|
11
11
|
|
|
12
12
|
interface ImageViewerProps {
|
|
13
|
-
className?: string
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
className?: string
|
|
14
|
+
canvasClassName?: string
|
|
15
|
+
documentUrl?: string
|
|
16
|
+
onClose: () => void
|
|
17
|
+
totalPages: number
|
|
18
|
+
getImageSrc: (page: number) => string | Promise<string>
|
|
19
|
+
title?: string
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export const ImageViewer = ({
|
|
22
23
|
className,
|
|
24
|
+
canvasClassName,
|
|
23
25
|
onClose,
|
|
24
26
|
totalPages,
|
|
25
27
|
getImageSrc,
|
|
26
28
|
documentUrl,
|
|
27
29
|
title = "PDF Viewer",
|
|
28
30
|
}: ImageViewerProps) => {
|
|
29
|
-
const [zoom, zoomActions] = useZoom()
|
|
30
|
-
const [rotation, rotationActions] = useRotation()
|
|
31
|
-
const [{ pan, isDragging }, panActions] = usePanning()
|
|
32
|
-
const [{ currentPage }, pageActions] = usePageManagement(totalPages)
|
|
31
|
+
const [zoom, zoomActions] = useZoom()
|
|
32
|
+
const [rotation, rotationActions] = useRotation()
|
|
33
|
+
const [{ pan, isDragging }, panActions] = usePanning()
|
|
34
|
+
const [{ currentPage }, pageActions] = usePageManagement(totalPages)
|
|
33
35
|
const [imageSrc, setImageSrc] = useState<string>(() => {
|
|
34
|
-
const initialResult = getImageSrc(currentPage)
|
|
35
|
-
return typeof initialResult === "string" ? initialResult : ""
|
|
36
|
-
})
|
|
36
|
+
const initialResult = getImageSrc(currentPage)
|
|
37
|
+
return typeof initialResult === "string" ? initialResult : ""
|
|
38
|
+
})
|
|
37
39
|
|
|
38
40
|
useEffect(() => {
|
|
39
|
-
let isActive = true
|
|
41
|
+
let isActive = true
|
|
40
42
|
|
|
41
43
|
const loadImage = async () => {
|
|
42
|
-
const result = getImageSrc(currentPage)
|
|
43
|
-
const resolvedSrc = await Promise.resolve(result)
|
|
44
|
+
const result = getImageSrc(currentPage)
|
|
45
|
+
const resolvedSrc = await Promise.resolve(result)
|
|
44
46
|
|
|
45
47
|
if (isActive) {
|
|
46
|
-
setImageSrc(resolvedSrc)
|
|
48
|
+
setImageSrc(resolvedSrc)
|
|
47
49
|
}
|
|
48
|
-
}
|
|
50
|
+
}
|
|
49
51
|
|
|
50
|
-
void loadImage()
|
|
52
|
+
void loadImage()
|
|
51
53
|
|
|
52
54
|
return () => {
|
|
53
|
-
isActive = false
|
|
54
|
-
}
|
|
55
|
-
}, [currentPage, getImageSrc])
|
|
55
|
+
isActive = false
|
|
56
|
+
}
|
|
57
|
+
}, [currentPage, getImageSrc])
|
|
56
58
|
|
|
57
59
|
const rightButtons = (
|
|
58
60
|
<IconButton variant="text" color="gray">
|
|
@@ -60,7 +62,7 @@ export const ImageViewer = ({
|
|
|
60
62
|
<ExpandIcon className="size-4" />
|
|
61
63
|
</a>
|
|
62
64
|
</IconButton>
|
|
63
|
-
)
|
|
65
|
+
)
|
|
64
66
|
|
|
65
67
|
return (
|
|
66
68
|
<div className={cn("shadow rounded-t-lg flex flex-col h-full", className)}>
|
|
@@ -68,10 +70,10 @@ export const ImageViewer = ({
|
|
|
68
70
|
{title}
|
|
69
71
|
</ModalPanel.Header>
|
|
70
72
|
|
|
71
|
-
<div className="flex-
|
|
72
|
-
<div className="grid relative">
|
|
73
|
+
<div className="flex flex-col h-full justify-between">
|
|
74
|
+
<div className="grid relative h-full">
|
|
73
75
|
<div
|
|
74
|
-
className=
|
|
76
|
+
className={`${canvasClassName} overflow-hidden col-start-1 row-start-1 bg-gray-200 h-full relative`}
|
|
75
77
|
onMouseMove={panActions.handleMouseMove}
|
|
76
78
|
onMouseUp={panActions.handleMouseUp}
|
|
77
79
|
onMouseLeave={panActions.handleMouseUp}
|
|
@@ -120,8 +122,8 @@ export const ImageViewer = ({
|
|
|
120
122
|
<button
|
|
121
123
|
className="!bg-white text-center cursor-pointer w-[60px]"
|
|
122
124
|
onClick={() => {
|
|
123
|
-
zoomActions.reset()
|
|
124
|
-
panActions.reset()
|
|
125
|
+
zoomActions.reset()
|
|
126
|
+
panActions.reset()
|
|
125
127
|
}}
|
|
126
128
|
>
|
|
127
129
|
{zoom}%
|
|
@@ -169,9 +171,9 @@ export const ImageViewer = ({
|
|
|
169
171
|
className="bg-white pl-4 flex items-center w-[50px] text-center focus:outline-none w-[60px]"
|
|
170
172
|
value={currentPage}
|
|
171
173
|
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
|
172
|
-
const page = parseInt(e.target.value)
|
|
174
|
+
const page = parseInt(e.target.value)
|
|
173
175
|
if (!isNaN(page)) {
|
|
174
|
-
pageActions.goToPage(page)
|
|
176
|
+
pageActions.goToPage(page)
|
|
175
177
|
}
|
|
176
178
|
}}
|
|
177
179
|
type="number"
|
|
@@ -195,5 +197,5 @@ export const ImageViewer = ({
|
|
|
195
197
|
</div>
|
|
196
198
|
</div>
|
|
197
199
|
</div>
|
|
198
|
-
)
|
|
199
|
-
}
|
|
200
|
+
)
|
|
201
|
+
}
|