@lateralus-ai/shipping-ui 1.4.5 → 1.4.7
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/package.json
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
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 } 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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
className?: string
|
|
14
|
+
documentUrl?: string
|
|
15
|
+
onClose: () => void
|
|
16
|
+
totalPages: number
|
|
17
|
+
getImageSrc: (page: number) => string | Promise<string>
|
|
18
|
+
title?: string
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export const ImageViewer = ({
|
|
@@ -24,10 +26,33 @@ export const ImageViewer = ({
|
|
|
24
26
|
documentUrl,
|
|
25
27
|
title = "PDF Viewer",
|
|
26
28
|
}: ImageViewerProps) => {
|
|
27
|
-
const [zoom, zoomActions] = useZoom()
|
|
28
|
-
const [rotation, rotationActions] = useRotation()
|
|
29
|
-
const [{ pan, isDragging }, panActions] = usePanning()
|
|
30
|
-
const [{ currentPage }, pageActions] = usePageManagement(totalPages)
|
|
29
|
+
const [zoom, zoomActions] = useZoom()
|
|
30
|
+
const [rotation, rotationActions] = useRotation()
|
|
31
|
+
const [{ pan, isDragging }, panActions] = usePanning()
|
|
32
|
+
const [{ currentPage }, pageActions] = usePageManagement(totalPages)
|
|
33
|
+
const [imageSrc, setImageSrc] = useState<string>(() => {
|
|
34
|
+
const initialResult = getImageSrc(currentPage)
|
|
35
|
+
return typeof initialResult === "string" ? initialResult : ""
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
let isActive = true
|
|
40
|
+
|
|
41
|
+
const loadImage = async () => {
|
|
42
|
+
const result = getImageSrc(currentPage)
|
|
43
|
+
const resolvedSrc = await Promise.resolve(result)
|
|
44
|
+
|
|
45
|
+
if (isActive) {
|
|
46
|
+
setImageSrc(resolvedSrc)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
void loadImage()
|
|
51
|
+
|
|
52
|
+
return () => {
|
|
53
|
+
isActive = false
|
|
54
|
+
}
|
|
55
|
+
}, [currentPage, getImageSrc])
|
|
31
56
|
|
|
32
57
|
const rightButtons = (
|
|
33
58
|
<IconButton variant="text" color="gray">
|
|
@@ -35,7 +60,7 @@ export const ImageViewer = ({
|
|
|
35
60
|
<ExpandIcon className="size-4" />
|
|
36
61
|
</a>
|
|
37
62
|
</IconButton>
|
|
38
|
-
)
|
|
63
|
+
)
|
|
39
64
|
|
|
40
65
|
return (
|
|
41
66
|
<div className={cn("shadow rounded-t-lg flex flex-col h-full", className)}>
|
|
@@ -43,8 +68,8 @@ export const ImageViewer = ({
|
|
|
43
68
|
{title}
|
|
44
69
|
</ModalPanel.Header>
|
|
45
70
|
|
|
46
|
-
<div className="flex-
|
|
47
|
-
<div className="grid relative">
|
|
71
|
+
<div className="flex flex-col h-full justify-between">
|
|
72
|
+
<div className="grid relative h-full">
|
|
48
73
|
<div
|
|
49
74
|
className="overflow-hidden col-start-1 row-start-1 bg-gray-200 h-full relative"
|
|
50
75
|
onMouseMove={panActions.handleMouseMove}
|
|
@@ -71,10 +96,12 @@ export const ImageViewer = ({
|
|
|
71
96
|
transition: isDragging ? "none" : "transform 0.3s ease",
|
|
72
97
|
}}
|
|
73
98
|
>
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
99
|
+
{imageSrc ? (
|
|
100
|
+
<img
|
|
101
|
+
src={imageSrc}
|
|
102
|
+
style={{ userSelect: "none", pointerEvents: "none" }}
|
|
103
|
+
/>
|
|
104
|
+
) : null}
|
|
78
105
|
</div>
|
|
79
106
|
</div>
|
|
80
107
|
</div>
|
|
@@ -93,8 +120,8 @@ export const ImageViewer = ({
|
|
|
93
120
|
<button
|
|
94
121
|
className="!bg-white text-center cursor-pointer w-[60px]"
|
|
95
122
|
onClick={() => {
|
|
96
|
-
zoomActions.reset()
|
|
97
|
-
panActions.reset()
|
|
123
|
+
zoomActions.reset()
|
|
124
|
+
panActions.reset()
|
|
98
125
|
}}
|
|
99
126
|
>
|
|
100
127
|
{zoom}%
|
|
@@ -142,9 +169,9 @@ export const ImageViewer = ({
|
|
|
142
169
|
className="bg-white pl-4 flex items-center w-[50px] text-center focus:outline-none w-[60px]"
|
|
143
170
|
value={currentPage}
|
|
144
171
|
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
|
145
|
-
const page = parseInt(e.target.value)
|
|
172
|
+
const page = parseInt(e.target.value)
|
|
146
173
|
if (!isNaN(page)) {
|
|
147
|
-
pageActions.goToPage(page)
|
|
174
|
+
pageActions.goToPage(page)
|
|
148
175
|
}
|
|
149
176
|
}}
|
|
150
177
|
type="number"
|
|
@@ -168,5 +195,5 @@ export const ImageViewer = ({
|
|
|
168
195
|
</div>
|
|
169
196
|
</div>
|
|
170
197
|
</div>
|
|
171
|
-
)
|
|
172
|
-
}
|
|
198
|
+
)
|
|
199
|
+
}
|