@lateralus-ai/shipping-ui 1.4.11 → 1.4.13
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/index.cjs +43 -43
- package/dist/index.esm.js +8206 -8202
- package/package.json +1 -1
- package/src/components/PdfViewer/PdfViewer.tsx +84 -58
package/package.json
CHANGED
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
ChangeEvent,
|
|
12
12
|
useMemo,
|
|
13
13
|
MouseEvent as ReactMouseEvent,
|
|
14
|
+
useRef,
|
|
15
|
+
useEffect,
|
|
14
16
|
} from "react"
|
|
15
17
|
import { useZoom } from "./useZoom"
|
|
16
18
|
import { useRotation } from "./useRotation"
|
|
@@ -37,6 +39,24 @@ export const PdfViewer = ({
|
|
|
37
39
|
const [rotation, rotationActions] = useRotation()
|
|
38
40
|
const [{ currentPage, totalPages }, pageActions] = usePageManagement()
|
|
39
41
|
const [{ pan, isDragging }, panActions] = usePanning()
|
|
42
|
+
const [scale, setScale] = useState(1)
|
|
43
|
+
const containerRef = useRef<HTMLDivElement>(null)
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const calculateScale = () => {
|
|
47
|
+
if (containerRef.current) {
|
|
48
|
+
const containerWidth = containerRef.current.offsetWidth
|
|
49
|
+
|
|
50
|
+
// Assuming standard PDF page width is ~612 points (8.5 inches)
|
|
51
|
+
const baseScale = containerWidth / 612
|
|
52
|
+
setScale(baseScale * (zoom / 100))
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
calculateScale()
|
|
57
|
+
window.addEventListener("resize", calculateScale)
|
|
58
|
+
return () => window.removeEventListener("resize", calculateScale)
|
|
59
|
+
}, [zoom])
|
|
40
60
|
|
|
41
61
|
const handleOpen = (event: ReactMouseEvent<HTMLButtonElement>) => {
|
|
42
62
|
if (onOpen) {
|
|
@@ -68,15 +88,18 @@ export const PdfViewer = ({
|
|
|
68
88
|
)
|
|
69
89
|
|
|
70
90
|
return (
|
|
71
|
-
<div
|
|
91
|
+
<div
|
|
92
|
+
className={cn("shadow rounded-t-lg flex flex-col h-full", className)}
|
|
93
|
+
ref={containerRef}
|
|
94
|
+
>
|
|
72
95
|
<ModalPanel.Header onClose={onClose} right={rightButtons}>
|
|
73
96
|
{title}
|
|
74
97
|
</ModalPanel.Header>
|
|
75
98
|
|
|
76
|
-
<div className="grid grow h-full overflow-hidden">
|
|
99
|
+
<div className="grid grow h-full overflow-hidden shadow">
|
|
77
100
|
<div
|
|
78
101
|
className={cn(
|
|
79
|
-
"col-start-1 row-start-1 bg-gray-200 h-full overflow-hidden select-none p-8 flex justify-center items-center",
|
|
102
|
+
"col-start-1 row-start-1 bg-gray-200 h-full overflow-hidden select-none p-8 flex justify-center items-center mt-8",
|
|
80
103
|
isDragging ? "cursor-grabbing" : "cursor-grab"
|
|
81
104
|
)}
|
|
82
105
|
onMouseDown={panActions.handleMouseDown}
|
|
@@ -102,7 +125,7 @@ export const PdfViewer = ({
|
|
|
102
125
|
onLoadSuccess={({ numPages }) => {
|
|
103
126
|
pageActions.setTotalPages(numPages)
|
|
104
127
|
}}
|
|
105
|
-
scale={
|
|
128
|
+
scale={scale}
|
|
106
129
|
rotate={rotation}
|
|
107
130
|
>
|
|
108
131
|
<Page
|
|
@@ -114,67 +137,19 @@ export const PdfViewer = ({
|
|
|
114
137
|
</div>
|
|
115
138
|
</div>
|
|
116
139
|
|
|
117
|
-
<div className="col-start-1 row-start-1 self-
|
|
118
|
-
<ButtonGroup className="divide-x-
|
|
119
|
-
<IconButton
|
|
120
|
-
variant="filled"
|
|
121
|
-
color="white"
|
|
122
|
-
className="py-[26px]"
|
|
123
|
-
onClick={zoomActions.zoomOut}
|
|
124
|
-
>
|
|
125
|
-
<Icon icon="lucide:minus" />
|
|
126
|
-
</IconButton>
|
|
127
|
-
<Tooltip content="Click to reset zoom and pan">
|
|
128
|
-
<button
|
|
129
|
-
className="!bg-white text-center cursor-pointer w-[60px]"
|
|
130
|
-
onClick={() => {
|
|
131
|
-
zoomActions.reset()
|
|
132
|
-
panActions.reset()
|
|
133
|
-
}}
|
|
134
|
-
>
|
|
135
|
-
{zoom}%
|
|
136
|
-
</button>
|
|
137
|
-
</Tooltip>
|
|
138
|
-
<IconButton
|
|
139
|
-
variant="filled"
|
|
140
|
-
color="white"
|
|
141
|
-
className="py-[26px]"
|
|
142
|
-
onClick={zoomActions.zoomIn}
|
|
143
|
-
>
|
|
144
|
-
<Icon icon="lucide:plus" />
|
|
145
|
-
</IconButton>
|
|
146
|
-
</ButtonGroup>
|
|
147
|
-
<ButtonGroup className="divide-x-0 h-[52px]">
|
|
148
|
-
<IconButton
|
|
149
|
-
variant="filled"
|
|
150
|
-
color="white"
|
|
151
|
-
className="py-[26px]"
|
|
152
|
-
onClick={rotationActions.rotateClockwise}
|
|
153
|
-
>
|
|
154
|
-
<Icon icon="lucide:iteration-cw" />
|
|
155
|
-
</IconButton>
|
|
156
|
-
|
|
140
|
+
<div className="col-start-1 row-start-1 self-start flex justify-between w-full z-10 flex-wrap items-center gap-3 bg-gray-50 p-2 shadow">
|
|
141
|
+
<ButtonGroup className="divide-x-1 gap-1">
|
|
157
142
|
<IconButton
|
|
158
143
|
variant="filled"
|
|
159
144
|
color="white"
|
|
160
|
-
className="
|
|
161
|
-
onClick={rotationActions.rotateCounterClockwise}
|
|
162
|
-
>
|
|
163
|
-
<Icon icon="lucide:iteration-ccw" />
|
|
164
|
-
</IconButton>
|
|
165
|
-
</ButtonGroup>
|
|
166
|
-
<ButtonGroup className="divide-x-0 ">
|
|
167
|
-
<IconButton
|
|
168
|
-
variant="filled"
|
|
169
|
-
color="white"
|
|
170
|
-
className="py-[26px]"
|
|
145
|
+
className="w-8 h-8 rounded border border-gray-300 bg-white p-2 text-gray-700 hover:bg-gray-200 disabled:opacity-50 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:hover:bg-gray-600 focus:outline-none max-w-auto"
|
|
171
146
|
onClick={pageActions.prevPage}
|
|
172
147
|
disabled={currentPage === 1}
|
|
173
148
|
>
|
|
174
149
|
<Icon icon="lucide:chevron-left" />
|
|
175
150
|
</IconButton>
|
|
176
151
|
<input
|
|
177
|
-
className="bg-white
|
|
152
|
+
className="w-14 h-8 rounded border !border-gray-300 bg-white px-1 py-1 text-center text-sm text-gray-700 dark:border-gray-600 dark:bg-gray-700 dark:text-white"
|
|
178
153
|
value={currentPage}
|
|
179
154
|
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
|
180
155
|
const page = parseInt(e.target.value)
|
|
@@ -186,19 +161,70 @@ export const PdfViewer = ({
|
|
|
186
161
|
min="1"
|
|
187
162
|
max={totalPages}
|
|
188
163
|
/>
|
|
189
|
-
<div className="flex items-center bg-
|
|
164
|
+
<div className="flex items-center bg-transparent px-2">
|
|
190
165
|
of {totalPages}
|
|
191
166
|
</div>
|
|
192
167
|
<IconButton
|
|
193
168
|
variant="filled"
|
|
194
169
|
color="white"
|
|
195
|
-
className="
|
|
170
|
+
className="w-8 h-8 rounded border !border-gray-300 bg-white p-2 text-gray-700 hover:bg-gray-200 disabled:opacity-50 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:hover:bg-gray-600 focus:outline-none max-w-auto"
|
|
196
171
|
onClick={pageActions.nextPage}
|
|
197
172
|
disabled={currentPage === totalPages}
|
|
198
173
|
>
|
|
199
174
|
<Icon icon="lucide:chevron-right" />
|
|
200
175
|
</IconButton>
|
|
201
176
|
</ButtonGroup>
|
|
177
|
+
<div className="flex gap-2 items-center">
|
|
178
|
+
<ButtonGroup className="divide-x-1 gap-1">
|
|
179
|
+
<IconButton
|
|
180
|
+
variant="filled"
|
|
181
|
+
color="white"
|
|
182
|
+
className="w-8 h-8 rounded border !border-gray-300 bg-white p-2 text-gray-700 hover:bg-gray-200 disabled:opacity-50 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:hover:bg-gray-600 focus:outline-none max-w-auto"
|
|
183
|
+
onClick={zoomActions.zoomOut}
|
|
184
|
+
>
|
|
185
|
+
<Icon icon="lucide:minus" />
|
|
186
|
+
</IconButton>
|
|
187
|
+
<Tooltip content="Click to reset zoom and pan">
|
|
188
|
+
<button
|
|
189
|
+
className="w-14 h-8 rounded border !border-gray-300 bg-white px-1 py-1 text-center text-sm text-gray-700 dark:border-gray-600 dark:bg-gray-700 dark:text-white"
|
|
190
|
+
onClick={() => {
|
|
191
|
+
zoomActions.reset()
|
|
192
|
+
panActions.reset()
|
|
193
|
+
}}
|
|
194
|
+
>
|
|
195
|
+
{zoom}%
|
|
196
|
+
</button>
|
|
197
|
+
</Tooltip>
|
|
198
|
+
<IconButton
|
|
199
|
+
variant="filled"
|
|
200
|
+
color="white"
|
|
201
|
+
className="w-8 h-8 rounded border !border-gray-300 bg-white p-2 text-gray-700 hover:bg-gray-200 disabled:opacity-50 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:hover:bg-gray-600 focus:outline-none max-w-auto"
|
|
202
|
+
onClick={zoomActions.zoomIn}
|
|
203
|
+
>
|
|
204
|
+
<Icon icon="lucide:plus" />
|
|
205
|
+
</IconButton>
|
|
206
|
+
</ButtonGroup>
|
|
207
|
+
<div className="h-6 w-px bg-gray-300 dark:bg-gray-600"></div>
|
|
208
|
+
<ButtonGroup className="divide-x-1 gap-1">
|
|
209
|
+
{/* <IconButton
|
|
210
|
+
variant="filled"
|
|
211
|
+
color="white"
|
|
212
|
+
className="w-8 h-8 rounded border !border-gray-300 bg-white p-2 text-gray-700 hover:bg-gray-200 disabled:opacity-50 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:hover:bg-gray-600 focus:outline-none max-w-auto"
|
|
213
|
+
onClick={rotationActions.rotateClockwise}
|
|
214
|
+
>
|
|
215
|
+
<Icon icon="lucide:iteration-cw" />
|
|
216
|
+
</IconButton> */}
|
|
217
|
+
|
|
218
|
+
<IconButton
|
|
219
|
+
variant="filled"
|
|
220
|
+
color="white"
|
|
221
|
+
className="w-8 h-8 rounded border !border-gray-300 bg-white p-2 text-gray-700 hover:bg-gray-200 disabled:opacity-50 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:hover:bg-gray-600 focus:outline-none max-w-auto"
|
|
222
|
+
onClick={rotationActions.rotateCounterClockwise}
|
|
223
|
+
>
|
|
224
|
+
<Icon icon="lucide:iteration-ccw" />
|
|
225
|
+
</IconButton>
|
|
226
|
+
</ButtonGroup>
|
|
227
|
+
</div>
|
|
202
228
|
</div>
|
|
203
229
|
</div>
|
|
204
230
|
</div>
|