@lateralus-ai/shipping-ui 1.4.5 → 1.4.6

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@lateralus-ai/shipping-ui",
3
- "version": "1.4.5",
3
+ "version": "1.4.6",
4
4
  "description": "Shared UI theme and components for Lateralus shipping applications",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.esm.js",
@@ -2,7 +2,7 @@ import { IconButton, ButtonGroup, Tooltip } from "@material-tailwind/react";
2
2
  import { ModalPanel } from "../ModalPanel";
3
3
  import ExpandIcon from "../icons/ExpandIcon";
4
4
  import { Icon } from "@iconify/react";
5
- import { ChangeEvent } from "react";
5
+ import { ChangeEvent, useEffect, useState } from "react";
6
6
  import { useZoom } from "./useZoom";
7
7
  import { useRotation } from "./useRotation";
8
8
  import { usePanning } from "./usePanning";
@@ -10,9 +10,11 @@ import { usePageManagement } from "./usePageManagement";
10
10
  import { cn } from "../../utils/cn";
11
11
 
12
12
  interface ImageViewerProps {
13
+ className?: string;
14
+ documentUrl?: string;
13
15
  onClose: () => void;
14
16
  totalPages: number;
15
- getImageSrc: (page: number) => string;
17
+ getImageSrc: (page: number) => string | Promise<string>;
16
18
  title?: string;
17
19
  }
18
20
 
@@ -28,6 +30,29 @@ export const ImageViewer = ({
28
30
  const [rotation, rotationActions] = useRotation();
29
31
  const [{ pan, isDragging }, panActions] = usePanning();
30
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">
@@ -71,10 +96,12 @@ export const ImageViewer = ({
71
96
  transition: isDragging ? "none" : "transform 0.3s ease",
72
97
  }}
73
98
  >
74
- <img
75
- src={getImageSrc(currentPage)}
76
- style={{ userSelect: "none", pointerEvents: "none" }}
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>