@lateralus-ai/shipping-ui 1.4.10 → 1.4.11
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/components/PdfViewer/usePageManagement.d.ts +1 -1
- package/dist/index.cjs +43 -43
- package/dist/index.esm.js +7943 -7929
- package/package.json +1 -1
- package/src/components/PdfViewer/ImageViewer.tsx +6 -1
- package/src/components/PdfViewer/usePageManagement.ts +17 -14
- package/src/stories/PDFViewer.stories.tsx +1 -0
package/package.json
CHANGED
|
@@ -14,6 +14,7 @@ interface ImageViewerProps {
|
|
|
14
14
|
canvasClassName?: string
|
|
15
15
|
documentUrl?: string
|
|
16
16
|
mainCanvasClassname?: string
|
|
17
|
+
initialPage?: number
|
|
17
18
|
onClose: () => void
|
|
18
19
|
totalPages: number
|
|
19
20
|
getImageSrc: (page: number) => string | Promise<string>
|
|
@@ -24,6 +25,7 @@ export const ImageViewer = ({
|
|
|
24
25
|
className,
|
|
25
26
|
canvasClassName,
|
|
26
27
|
mainCanvasClassname,
|
|
28
|
+
initialPage = 1,
|
|
27
29
|
onClose,
|
|
28
30
|
totalPages,
|
|
29
31
|
getImageSrc,
|
|
@@ -33,7 +35,10 @@ export const ImageViewer = ({
|
|
|
33
35
|
const [zoom, zoomActions] = useZoom()
|
|
34
36
|
const [rotation, rotationActions] = useRotation()
|
|
35
37
|
const [{ pan, isDragging }, panActions] = usePanning()
|
|
36
|
-
const [{ currentPage }, pageActions] = usePageManagement(
|
|
38
|
+
const [{ currentPage }, pageActions] = usePageManagement(
|
|
39
|
+
totalPages,
|
|
40
|
+
initialPage
|
|
41
|
+
)
|
|
37
42
|
const [imageSrc, setImageSrc] = useState<string>(() => {
|
|
38
43
|
const initialResult = getImageSrc(currentPage)
|
|
39
44
|
return typeof initialResult === "string" ? initialResult : ""
|
|
@@ -1,29 +1,32 @@
|
|
|
1
|
-
import { useState, useCallback } from "react"
|
|
1
|
+
import { useState, useCallback } from "react"
|
|
2
2
|
|
|
3
|
-
export const usePageManagement = (
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export const usePageManagement = (
|
|
4
|
+
initialTotalPages: number = 0,
|
|
5
|
+
initialPage: number = 1
|
|
6
|
+
) => {
|
|
7
|
+
const [currentPage, setCurrentPage] = useState<number>(initialPage)
|
|
8
|
+
const [totalPages, setTotalPages] = useState<number>(initialTotalPages)
|
|
6
9
|
|
|
7
10
|
const actions = {
|
|
8
11
|
nextPage: useCallback(() => {
|
|
9
12
|
setCurrentPage((prev) => {
|
|
10
|
-
return prev < totalPages ? prev + 1 : prev
|
|
11
|
-
})
|
|
13
|
+
return prev < totalPages ? prev + 1 : prev
|
|
14
|
+
})
|
|
12
15
|
}, [totalPages]),
|
|
13
16
|
prevPage: useCallback(() => {
|
|
14
|
-
setCurrentPage((prev) => Math.max(prev - 1, 1))
|
|
17
|
+
setCurrentPage((prev) => Math.max(prev - 1, 1))
|
|
15
18
|
}, []),
|
|
16
19
|
goToPage: useCallback(
|
|
17
20
|
(page: number) => {
|
|
18
|
-
setCurrentPage(() => Math.max(1, Math.min(page, totalPages)))
|
|
21
|
+
setCurrentPage(() => Math.max(1, Math.min(page, totalPages)))
|
|
19
22
|
},
|
|
20
|
-
[totalPages]
|
|
23
|
+
[totalPages]
|
|
21
24
|
),
|
|
22
25
|
setTotalPages: useCallback((pages: number) => {
|
|
23
|
-
setTotalPages(pages)
|
|
24
|
-
setCurrentPage((prev) => Math.min(prev, pages))
|
|
26
|
+
setTotalPages(pages)
|
|
27
|
+
setCurrentPage((prev) => Math.min(prev, pages))
|
|
25
28
|
}, []),
|
|
26
|
-
}
|
|
29
|
+
}
|
|
27
30
|
|
|
28
|
-
return [{ currentPage, totalPages }, actions] as const
|
|
29
|
-
}
|
|
31
|
+
return [{ currentPage, totalPages }, actions] as const
|
|
32
|
+
}
|