Skip to content

Commit bf2aca9

Browse files
authored
Merge pull request #381 from embedpdf/fix/print-popup
Fix/print popup
2 parents 759152f + 95bb3a0 commit bf2aca9

11 files changed

Lines changed: 234 additions & 78 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@embedpdf/snippet': patch
3+
---
4+
5+
- Add i18n support for capture and print dialogs with translations for all supported languages
6+
- Add `document:capture` command to toolbar for screenshot functionality
7+
- Refactor hint-layer and capture components to use translation hooks
8+
- Remove unused `@types/classnames` dependency

pnpm-lock.yaml

Lines changed: 28 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

viewers/snippet/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
"@rollup/plugin-typescript": "^12.3.0",
6363
"@rollup/plugin-url": "^8.0.1",
6464
"@tailwindcss/postcss": "^4.1.17",
65-
"@types/classnames": "^2.3.1",
6665
"@types/node": "^20.5.4",
6766
"@types/react": "^18.2.0",
6867
"@types/uuid": "^9.0.2",

viewers/snippet/src/components/app.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ import { TabBar, TabBarVisibility } from '@/components/tab-bar';
136136
import { EmptyState } from '@/components/empty-state';
137137
import { DocumentPasswordPrompt } from '@/components/document-password-prompt';
138138
import { ModeSelectButton } from './mode-select-button';
139+
import { Capture } from '@/components/capture';
139140

140141
// ============================================================================
141142
// Main Configuration Interface - Uses actual plugin config types directly
@@ -412,7 +413,6 @@ function ViewerLayout({ documentId, tabBarVisibility = 'multiple' }: ViewerLayou
412413
pageIndex={pageIndex}
413414
selectionMenu={annotationMenu}
414415
/>
415-
<HintLayer />
416416
</PagePointerProvider>
417417
</Rotate>
418418
)}
@@ -599,6 +599,8 @@ export function PDFViewer({ config, onRegistryReady }: PDFViewerProps) {
599599
className="relative flex h-full w-full select-none flex-col"
600600
>
601601
<ViewerLayout documentId={activeDocumentId} tabBarVisibility={config.tabBar} />
602+
<Capture documentId={activeDocumentId} />
603+
<HintLayer documentId={activeDocumentId} />
602604
</UIProvider>
603605
) : (
604606
<EmptyState />

viewers/snippet/src/components/capture.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,27 @@ import { useCaptureCapability } from '@embedpdf/plugin-capture/preact';
33
import { useState, useRef, useEffect } from 'preact/hooks';
44
import { Dialog } from './ui/dialog';
55
import { Button } from './ui/button';
6+
import { useTranslations } from '@embedpdf/plugin-i18n/preact';
67

7-
interface CaptureData {
8+
export interface CaptureData {
89
pageIndex: number;
910
rect: any;
1011
blob: Blob;
1112
}
1213

13-
export function Capture() {
14+
export interface CaptureProps {
15+
documentId: string;
16+
}
17+
18+
export function Capture({ documentId }: CaptureProps) {
1419
const { provides: capture } = useCaptureCapability();
1520
const [open, setOpen] = useState(false);
1621
const [captureData, setCaptureData] = useState<CaptureData | null>(null);
1722
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
1823
const [downloadUrl, setDownloadUrl] = useState<string | null>(null);
1924
const urlRef = useRef<string | null>(null);
2025
const downloadLinkRef = useRef<HTMLAnchorElement>(null);
26+
const { translate } = useTranslations(documentId);
2127

2228
const handleClose = () => {
2329
// Clean up object URLs
@@ -73,7 +79,12 @@ export function Capture() {
7379

7480
return (
7581
<>
76-
<Dialog open={open} onClose={handleClose} title="Capture PDF Area">
82+
<Dialog
83+
open={open}
84+
onClose={handleClose}
85+
title={translate('capture.title')}
86+
className="md:w-[48rem]"
87+
>
7788
<div className="space-y-6">
7889
<div className="flex justify-center">
7990
{previewUrl && (
@@ -91,19 +102,19 @@ export function Capture() {
91102
/>
92103
)}
93104
</div>
94-
<div className="flex justify-end space-x-3 border-t border-gray-200 pt-4">
105+
<div className="border-border-subtle flex justify-end space-x-3 border-t pt-4">
95106
<Button
96107
onClick={handleClose}
97-
className="rounded-md border border-gray-300 bg-white px-4 py-2 text-sm text-gray-700 hover:bg-gray-50"
108+
className="border-border-default bg-bg-surface text-fg-secondary hover:bg-interactive-hover rounded-md border px-4 py-2 text-sm disabled:cursor-not-allowed disabled:opacity-50"
98109
>
99-
Cancel
110+
{translate('capture.cancel')}
100111
</Button>
101112
<Button
102113
onClick={handleDownload}
103114
disabled={!captureData}
104-
className="rounded-md border border-transparent bg-blue-600 px-4 py-2 text-sm text-white hover:!bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50"
115+
className="bg-accent text-fg-on-accent hover:!bg-accent-hover flex items-center space-x-2 rounded-md border border-transparent px-4 py-2 text-sm disabled:cursor-not-allowed disabled:opacity-50"
105116
>
106-
Download
117+
{translate('capture.download')}
107118
</Button>
108119
</div>
109120
</div>

viewers/snippet/src/components/hint-layer.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import { h } from 'preact';
2-
import { useInteractionManager } from '@embedpdf/plugin-interaction-manager/preact';
2+
import { useInteractionManagerCapability } from '@embedpdf/plugin-interaction-manager/preact';
33
import { useEffect, useState } from 'preact/hooks';
4+
import { useTranslations } from '@embedpdf/plugin-i18n/preact';
45

56
interface HintState {
67
show: boolean;
78
mode: 'marqueeZoom' | 'marqueeCapture' | null;
89
isAnimating: boolean;
910
}
1011

11-
export const HintLayer = () => {
12-
const { provides: interactionManager } = useInteractionManager();
12+
export interface HintLayerProps {
13+
documentId: string;
14+
}
15+
16+
export const HintLayer = ({ documentId }: HintLayerProps) => {
17+
const { provides: interactionManager } = useInteractionManagerCapability();
1318
const [hint, setHint] = useState<HintState>({
1419
show: false,
1520
mode: null,
1621
isAnimating: false,
1722
});
23+
const { translate } = useTranslations(documentId);
1824

1925
useEffect(() => {
2026
if (!interactionManager) return;
@@ -54,7 +60,7 @@ export const HintLayer = () => {
5460
if (!hint.show && !hint.isAnimating) return null;
5561

5662
const hintText =
57-
hint.mode === 'marqueeZoom' ? 'Drag to select area to zoom' : 'Drag to select area to capture';
63+
hint.mode === 'marqueeZoom' ? translate('zoom.dragTip') : translate('capture.dragTip');
5864

5965
const hintColor = hint.mode === 'marqueeZoom' ? 'rgba(33,150,243,0.8)' : 'rgba(76,175,80,0.8)';
6066

0 commit comments

Comments
 (0)