@lateralus-ai/shipping-ui 1.4.4 → 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.4",
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>
@@ -1,24 +1,29 @@
1
- import { IconButton, ButtonGroup, Tooltip } from "@material-tailwind/react";
2
- import { Document, Page, pdfjs } from "react-pdf";
3
- import { ModalPanel } from "../ModalPanel";
4
- import ExpandIcon from "../icons/ExpandIcon";
5
- import { Icon } from "@iconify/react";
6
- import { cn } from "../../utils/cn";
7
- import "react-pdf/dist/Page/AnnotationLayer.css";
8
- import "react-pdf/dist/Page/TextLayer.css";
9
- import { useState, ChangeEvent, useMemo, MouseEvent as ReactMouseEvent } from "react";
10
- import { useZoom } from "./useZoom";
11
- import { useRotation } from "./useRotation";
12
- import { usePageManagement } from "./usePageManagement";
13
- import { usePanning } from "./usePanning";
1
+ import { IconButton, ButtonGroup, Tooltip } from "@material-tailwind/react"
2
+ import { Document, Page, pdfjs } from "react-pdf"
3
+ import { ModalPanel } from "../ModalPanel"
4
+ import ExpandIcon from "../icons/ExpandIcon"
5
+ import { Icon } from "@iconify/react"
6
+ import { cn } from "../../utils/cn"
7
+ import "react-pdf/dist/Page/AnnotationLayer.css"
8
+ import "react-pdf/dist/Page/TextLayer.css"
9
+ import {
10
+ useState,
11
+ ChangeEvent,
12
+ useMemo,
13
+ MouseEvent as ReactMouseEvent,
14
+ } from "react"
15
+ import { useZoom } from "./useZoom"
16
+ import { useRotation } from "./useRotation"
17
+ import { usePageManagement } from "./usePageManagement"
18
+ import { usePanning } from "./usePanning"
14
19
 
15
- pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;
20
+ pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`
16
21
 
17
22
  interface PdfViewerProps extends React.HTMLProps<HTMLDivElement> {
18
- onClose: () => void;
19
- src: string;
20
- title?: string;
21
- onOpen?: (event: ReactMouseEvent<HTMLButtonElement>) => void;
23
+ onClose: () => void
24
+ src: string
25
+ title?: string
26
+ onOpen?: (event: ReactMouseEvent<HTMLButtonElement>) => void
22
27
  }
23
28
 
24
29
  export const PdfViewer = ({
@@ -28,39 +33,39 @@ export const PdfViewer = ({
28
33
  className,
29
34
  onOpen,
30
35
  }: PdfViewerProps) => {
31
- const [zoom, zoomActions] = useZoom();
32
- const [rotation, rotationActions] = useRotation();
33
- const [{ currentPage, totalPages }, pageActions] = usePageManagement();
34
- const [{ pan, isDragging }, panActions] = usePanning();
36
+ const [zoom, zoomActions] = useZoom()
37
+ const [rotation, rotationActions] = useRotation()
38
+ const [{ currentPage, totalPages }, pageActions] = usePageManagement()
39
+ const [{ pan, isDragging }, panActions] = usePanning()
35
40
 
36
41
  const handleOpen = (event: ReactMouseEvent<HTMLButtonElement>) => {
37
42
  if (onOpen) {
38
43
  console.debug("[PdfViewer] onOpen callback triggered", {
39
44
  hasHandler: true,
40
- });
41
- onOpen(event);
45
+ })
46
+ onOpen(event)
42
47
  } else {
43
48
  console.debug("[PdfViewer] open button clicked", {
44
49
  hasHandler: false,
45
- });
50
+ })
46
51
  }
47
52
  if (event.defaultPrevented) {
48
- return;
53
+ return
49
54
  }
50
55
 
51
56
  if (!src) {
52
- event.preventDefault();
53
- return;
57
+ event.preventDefault()
58
+ return
54
59
  }
55
60
 
56
- window.open(src, "_blank", "noopener,noreferrer");
57
- };
61
+ window.open(src, "_blank", "noopener,noreferrer")
62
+ }
58
63
 
59
64
  const rightButtons = (
60
65
  <IconButton variant="text" color="gray" onClick={handleOpen}>
61
66
  <ExpandIcon className="size-4" />
62
67
  </IconButton>
63
- );
68
+ )
64
69
 
65
70
  return (
66
71
  <div className={cn("shadow rounded-t-lg flex flex-col h-full", className)}>
@@ -71,7 +76,7 @@ export const PdfViewer = ({
71
76
  <div className="grid grow h-full overflow-hidden">
72
77
  <div
73
78
  className={cn(
74
- "col-start-1 row-start-1 bg-gray-200 h-full overflow-hidden select-none p-8",
79
+ "col-start-1 row-start-1 bg-gray-200 h-full overflow-hidden select-none p-8 flex justify-center items-center",
75
80
  isDragging ? "cursor-grabbing" : "cursor-grab"
76
81
  )}
77
82
  onMouseDown={panActions.handleMouseDown}
@@ -79,14 +84,15 @@ export const PdfViewer = ({
79
84
  onMouseUp={panActions.handleMouseUp}
80
85
  onMouseLeave={panActions.handleMouseUp}
81
86
  style={{
82
- userSelect: 'none',
87
+ userSelect: "none",
83
88
  }}
84
89
  >
85
90
  <div
86
91
  style={{
87
92
  transform: `translate(${pan.x}px, ${pan.y}px)`,
88
- transition: isDragging ? 'none' : 'transform 0.1s',
89
- pointerEvents: 'none',
93
+ transition: isDragging ? "none" : "transform 0.1s",
94
+ pointerEvents: "none",
95
+ maxWidth: "650px",
90
96
  }}
91
97
  >
92
98
  <Document
@@ -94,7 +100,7 @@ export const PdfViewer = ({
94
100
  externalLinkTarget="_blank"
95
101
  file={src}
96
102
  onLoadSuccess={({ numPages }) => {
97
- pageActions.setTotalPages(numPages);
103
+ pageActions.setTotalPages(numPages)
98
104
  }}
99
105
  scale={zoom / 100}
100
106
  rotate={rotation}
@@ -122,8 +128,8 @@ export const PdfViewer = ({
122
128
  <button
123
129
  className="!bg-white text-center cursor-pointer w-[60px]"
124
130
  onClick={() => {
125
- zoomActions.reset();
126
- panActions.reset();
131
+ zoomActions.reset()
132
+ panActions.reset()
127
133
  }}
128
134
  >
129
135
  {zoom}%
@@ -171,9 +177,9 @@ export const PdfViewer = ({
171
177
  className="bg-white pl-4 flex items-center w-[50px] text-center focus:outline-none w-[60px]"
172
178
  value={currentPage}
173
179
  onChange={(e: ChangeEvent<HTMLInputElement>) => {
174
- const page = parseInt(e.target.value);
180
+ const page = parseInt(e.target.value)
175
181
  if (!isNaN(page)) {
176
- pageActions.goToPage(page);
182
+ pageActions.goToPage(page)
177
183
  }
178
184
  }}
179
185
  type="number"
@@ -196,5 +202,5 @@ export const PdfViewer = ({
196
202
  </div>
197
203
  </div>
198
204
  </div>
199
- );
200
- };
205
+ )
206
+ }