Update Page editor styling

This commit is contained in:
Reece 2025-06-16 15:11:00 +01:00
parent ac3da9b7c2
commit 7fc850b138
4 changed files with 458 additions and 207 deletions

View File

@ -246,7 +246,7 @@ Stirling-PDF uses different Docker images for various configurations. The build
Note: The `--no-cache` and `--pull` flags ensure that the build process uses the latest base images and doesn't use cached layers, which is useful for testing and ensuring reproducible builds. however to improve build times these can often be removed depending on your usecase Note: The `--no-cache` and `--pull` flags ensure that the build process uses the latest base images and doesn't use cached layers, which is useful for testing and ensuring reproducible builds. however to improve build times these can often be removed depending on your usecase
## 6. Testing ## 7. Testing
### Comprehensive Testing Script ### Comprehensive Testing Script
@ -311,7 +311,7 @@ Important notes:
- There are currently no automated unit tests. All testing is done manually through the UI or API calls. (You are welcome to add JUnits!) - There are currently no automated unit tests. All testing is done manually through the UI or API calls. (You are welcome to add JUnits!)
- Always verify your changes in the full Docker environment before submitting pull requests, as some integrations and features will only work in the complete setup. - Always verify your changes in the full Docker environment before submitting pull requests, as some integrations and features will only work in the complete setup.
## 7. Contributing ## 8. Contributing
1. Fork the repository on GitHub. 1. Fork the repository on GitHub.
2. Create a new branch for your feature or bug fix. 2. Create a new branch for your feature or bug fix.
@ -336,11 +336,11 @@ When you raise a PR:
Address any issues that arise from these checks before finalizing your pull request. Address any issues that arise from these checks before finalizing your pull request.
## 8. API Documentation ## 9. API Documentation
API documentation is available at `/swagger-ui/index.html` when running the application. You can also view the latest API documentation [here](https://app.swaggerhub.com/apis-docs/Stirling-Tools/Stirling-PDF/). API documentation is available at `/swagger-ui/index.html` when running the application. You can also view the latest API documentation [here](https://app.swaggerhub.com/apis-docs/Stirling-Tools/Stirling-PDF/).
## 9. Customization ## 10. Customization
Stirling-PDF can be customized through environment variables or a `settings.yml` file. Key customization options include: Stirling-PDF can be customized through environment variables or a `settings.yml` file. Key customization options include:
@ -359,7 +359,7 @@ docker run -p 8080:8080 -e APP_NAME="My PDF Tool" stirling-pdf:full
Refer to the main README for a full list of customization options. Refer to the main README for a full list of customization options.
## 10. Language Translations ## 11. Language Translations
For managing language translations that affect multiple files, Stirling-PDF provides a helper script: For managing language translations that affect multiple files, Stirling-PDF provides a helper script:

View File

@ -43,7 +43,7 @@ export class RotatePagesCommand extends PageCommand {
execute(): void { execute(): void {
const updatedPages = this.pdfDocument.pages.map(page => { const updatedPages = this.pdfDocument.pages.map(page => {
if (this.pageIds.includes(page.id)) { if (this.pageIds.includes(page.id)) {
return { ...page, rotation: (page.rotation + this.rotation) % 360 }; return { ...page, rotation: page.rotation + this.rotation };
} }
return page; return page;
}); });

View File

@ -58,6 +58,7 @@ const PageEditor: React.FC<PageEditorProps> = ({
const [showPageSelect, setShowPageSelect] = useState(false); const [showPageSelect, setShowPageSelect] = useState(false);
const [filename, setFilename] = useState<string>(""); const [filename, setFilename] = useState<string>("");
const [draggedPage, setDraggedPage] = useState<string | null>(null); const [draggedPage, setDraggedPage] = useState<string | null>(null);
const [dropTarget, setDropTarget] = useState<string | null>(null);
const [exportLoading, setExportLoading] = useState(false); const [exportLoading, setExportLoading] = useState(false);
const [showExportModal, setShowExportModal] = useState(false); const [showExportModal, setShowExportModal] = useState(false);
const [exportPreview, setExportPreview] = useState<{pageCount: number; splitCount: number; estimatedSize: string} | null>(null); const [exportPreview, setExportPreview] = useState<{pageCount: number; splitCount: number; estimatedSize: string} | null>(null);
@ -162,14 +163,55 @@ const PageEditor: React.FC<PageEditorProps> = ({
const handleDragOver = useCallback((e: React.DragEvent) => { const handleDragOver = useCallback((e: React.DragEvent) => {
e.preventDefault(); e.preventDefault();
if (!draggedPage) return;
// Get the element under the mouse cursor
const elementUnderCursor = document.elementFromPoint(e.clientX, e.clientY);
if (!elementUnderCursor) return;
// Find the closest page container
const pageContainer = elementUnderCursor.closest('[data-page-id]');
if (pageContainer) {
const pageId = pageContainer.getAttribute('data-page-id');
if (pageId && pageId !== draggedPage) {
setDropTarget(pageId);
return;
}
}
// Check if over the end zone
const endZone = elementUnderCursor.closest('[data-drop-zone="end"]');
if (endZone) {
setDropTarget('end');
return;
}
// If not over any valid drop target, clear it
setDropTarget(null);
}, [draggedPage]);
const handleDragEnter = useCallback((pageId: string) => {
if (draggedPage && pageId !== draggedPage) {
setDropTarget(pageId);
}
}, [draggedPage]);
const handleDragLeave = useCallback(() => {
// Don't clear drop target on drag leave - let dragover handle it
}, []); }, []);
const handleDrop = useCallback((e: React.DragEvent, targetPageId: string) => { const handleDrop = useCallback((e: React.DragEvent, targetPageId: string | 'end') => {
e.preventDefault(); e.preventDefault();
if (!draggedPage || !pdfDocument || draggedPage === targetPageId) return; if (!draggedPage || !pdfDocument || draggedPage === targetPageId) return;
const targetIndex = pdfDocument.pages.findIndex(p => p.id === targetPageId); let targetIndex: number;
if (targetPageId === 'end') {
targetIndex = pdfDocument.pages.length;
} else {
targetIndex = pdfDocument.pages.findIndex(p => p.id === targetPageId);
if (targetIndex === -1) return; if (targetIndex === -1) return;
}
const command = new ReorderPageCommand( const command = new ReorderPageCommand(
pdfDocument, pdfDocument,
@ -180,9 +222,16 @@ const PageEditor: React.FC<PageEditorProps> = ({
executeCommand(command); executeCommand(command);
setDraggedPage(null); setDraggedPage(null);
setDropTarget(null);
setStatus('Page reordered'); setStatus('Page reordered');
}, [draggedPage, pdfDocument, executeCommand]); }, [draggedPage, pdfDocument, executeCommand]);
const handleEndZoneDragEnter = useCallback(() => {
if (draggedPage) {
setDropTarget('end');
}
}, [draggedPage]);
const handleRotate = useCallback((direction: 'left' | 'right') => { const handleRotate = useCallback((direction: 'left' | 'right') => {
if (!pdfDocument || selectedPages.length === 0) return; if (!pdfDocument || selectedPages.length === 0) return;
@ -293,15 +342,10 @@ const PageEditor: React.FC<PageEditorProps> = ({
if (!pdfDocument) { if (!pdfDocument) {
return ( return (
<Container> <Box pos="relative" h="100vh" style={{ overflow: 'auto' }}>
<Paper shadow="xs" radius="md" p="md" pos="relative">
<LoadingOverlay visible={loading || pdfLoading} /> <LoadingOverlay visible={loading || pdfLoading} />
<Group mb="md"> <Box p="xl">
<ConstructionIcon />
<Text size="lg" fw={600}>PDF Multitool</Text>
</Group>
{error && ( {error && (
<Alert color="red" mb="md" onClose={() => setError(null)}> <Alert color="red" mb="md" onClose={() => setError(null)}>
{error} {error}
@ -312,35 +356,55 @@ const PageEditor: React.FC<PageEditorProps> = ({
onDrop={(files) => files[0] && handleFileUpload(files[0])} onDrop={(files) => files[0] && handleFileUpload(files[0])}
accept={["application/pdf"]} accept={["application/pdf"]}
multiple={false} multiple={false}
h={300} h="60vh"
style={{ minHeight: 400 }}
> >
<Center h={250}> <Center h="100%">
<Stack align="center" gap="md"> <Stack align="center" gap="md">
<UploadFileIcon style={{ fontSize: 48 }} /> <UploadFileIcon style={{ fontSize: 64 }} />
<Text size="lg" fw={500}> <Text size="xl" fw={500}>
Drop a PDF file here or click to upload Drop a PDF file here or click to upload
</Text> </Text>
<Text size="sm" c="dimmed"> <Text size="md" c="dimmed">
Supports PDF files only Supports PDF files only
</Text> </Text>
</Stack> </Stack>
</Center> </Center>
</Dropzone> </Dropzone>
</Paper> </Box>
</Container> </Box>
); );
} }
return ( return (
<Container> <Box pos="relative" h="100vh" style={{ overflow: 'auto' }}>
<Paper shadow="xs" radius="md" p="md" pos="relative"> <style>
{`
.page-container:hover .page-number {
opacity: 1 !important;
}
.page-container:hover .page-hover-controls {
opacity: 1 !important;
}
.page-container {
transition: transform 0.2s ease-in-out;
}
.page-container:hover {
transform: scale(1.02);
}
@keyframes pulse {
0%, 100% {
opacity: 1;
}
50% {
opacity: 0.5;
}
}
`}
</style>
<LoadingOverlay visible={loading || pdfLoading} /> <LoadingOverlay visible={loading || pdfLoading} />
<Group mb="md"> <Box p="md">
<ConstructionIcon />
<Text size="lg" fw={600}>PDF Multitool</Text>
</Group>
<Group mb="md"> <Group mb="md">
<TextInput <TextInput
value={filename} value={filename}
@ -412,39 +476,82 @@ const PageEditor: React.FC<PageEditorProps> = ({
</Tooltip> </Tooltip>
</Group> </Group>
<SimpleGrid cols={{ base: 2, sm: 3, md: 4, lg: 6 }} spacing="md"> <div
{pdfDocument.pages.map((page) => (
<Box
key={page.id}
style={{ style={{
borderRadius: 8, display: 'flex',
padding: 8, flexWrap: 'wrap',
gap: '1.5rem',
justifyContent: 'flex-start'
}}
>
{pdfDocument.pages.map((page, index) => (
<React.Fragment key={page.id}>
{page.splitBefore && index > 0 && (
<div
style={{
width: '4px',
height: '15rem',
border: '2px dashed #3b82f6',
backgroundColor: 'transparent',
borderRadius: '2px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
marginLeft: '-0.75rem',
marginRight: '-0.75rem',
position: 'relative', position: 'relative',
cursor: 'grab', flexShrink: 0
...(selectedPages.includes(page.id) }}
? { border: '2px solid blue' } >
: { border: '1px solid #ccc' } <ContentCutIcon
), style={{
...(page.splitBefore fontSize: 18,
? { borderLeft: '4px dashed orange' } color: '#3b82f6',
: {} backgroundColor: 'white',
) borderRadius: '50%',
padding: '3px'
}}
/>
</div>
)}
<div
data-page-id={page.id}
className={`
!rounded-lg
cursor-grab
select-none
w-[15rem]
h-[15rem]
flex items-center justify-center
flex-shrink-0
shadow-sm
hover:shadow-md
transition-all
relative
${selectedPages.includes(page.id)
? 'ring-2 ring-blue-500 bg-blue-50'
: 'bg-white hover:bg-gray-50'}
${draggedPage === page.id ? 'opacity-50 scale-95' : ''}
`}
style={{
transform: (() => {
if (!draggedPage || page.id === draggedPage) return 'translateX(0)';
if (dropTarget === page.id) {
return 'translateX(20px)'; // Move slightly right to indicate drop position
}
return 'translateX(0)';
})(),
transition: 'transform 0.2s ease-in-out'
}} }}
draggable draggable
onDragStart={() => handleDragStart(page.id)} onDragStart={() => handleDragStart(page.id)}
onDragOver={handleDragOver} onDragOver={handleDragOver}
onDragEnter={() => handleDragEnter(page.id)}
onDragLeave={handleDragLeave}
onDrop={(e) => handleDrop(e, page.id)} onDrop={(e) => handleDrop(e, page.id)}
> >
<Stack align="center" gap={4}> <div className="page-container w-[90%] h-[90%]">
{showPageSelect && (
<Checkbox
checked={selectedPages.includes(page.id)}
onChange={() => togglePage(page.id)}
size="sm"
/>
)}
<Box w={120} h={160} pos="relative">
<img <img
src={page.thumbnail} src={page.thumbnail}
alt={`Page ${page.pageNumber}`} alt={`Page ${page.pageNumber}`}
@ -453,44 +560,187 @@ const PageEditor: React.FC<PageEditorProps> = ({
height: '100%', height: '100%',
objectFit: 'contain', objectFit: 'contain',
borderRadius: 4, borderRadius: 4,
transform: `rotate(${page.rotation}deg)` transform: `rotate(${page.rotation}deg)`,
transition: 'transform 0.3s ease-in-out'
}} }}
/> />
{/* Page number overlay - shows on hover */}
<Text <Text
size="xs" className="page-number"
size="sm"
fw={500} fw={500}
c="white" c="white"
style={{ style={{
position: 'absolute', position: 'absolute',
top: 4, top: 5,
left: 4, left: 5,
background: 'rgba(0,0,0,0.7)', background: 'rgba(162, 201, 255, 0.8)',
padding: '2px 6px', padding: '6px 8px',
borderRadius: 4 borderRadius: 8,
zIndex: 2,
opacity: 0,
transition: 'opacity 0.2s ease-in-out'
}} }}
> >
{page.pageNumber} {page.pageNumber}
</Text> </Text>
{/* Hover controls */}
<div
className="page-hover-controls"
style={{
position: 'absolute',
bottom: 8,
left: '50%',
transform: 'translateX(-50%)',
background: 'rgba(0, 0, 0, 0.8)',
padding: '6px 12px',
borderRadius: 20,
opacity: 0,
transition: 'opacity 0.2s ease-in-out',
zIndex: 3,
display: 'flex',
gap: '8px',
alignItems: 'center',
whiteSpace: 'nowrap'
}}
>
<Tooltip label="Rotate Left">
<ActionIcon
size="md"
variant="subtle"
c="white"
onClick={(e) => {
e.stopPropagation();
const command = new RotatePagesCommand(
pdfDocument,
setPdfDocument,
[page.id],
-90
);
executeCommand(command);
setStatus(`Rotated page ${page.pageNumber} left`);
}}
>
<RotateLeftIcon style={{ fontSize: 20 }} />
</ActionIcon>
</Tooltip>
<Tooltip label="Rotate Right">
<ActionIcon
size="md"
variant="subtle"
c="white"
onClick={(e) => {
e.stopPropagation();
const command = new RotatePagesCommand(
pdfDocument,
setPdfDocument,
[page.id],
90
);
executeCommand(command);
setStatus(`Rotated page ${page.pageNumber} right`);
}}
>
<RotateRightIcon style={{ fontSize: 20 }} />
</ActionIcon>
</Tooltip>
<Tooltip label="Delete Page">
<ActionIcon
size="md"
variant="subtle"
c="red"
onClick={(e) => {
e.stopPropagation();
const command = new DeletePagesCommand(
pdfDocument,
setPdfDocument,
[page.id]
);
executeCommand(command);
setStatus(`Deleted page ${page.pageNumber}`);
}}
>
<DeleteIcon style={{ fontSize: 20 }} />
</ActionIcon>
</Tooltip>
<Tooltip label="Split Here">
<ActionIcon
size="md"
variant="subtle"
c="white"
onClick={(e) => {
e.stopPropagation();
const command = new ToggleSplitCommand(
pdfDocument,
setPdfDocument,
[page.id]
);
executeCommand(command);
setStatus(`Split marker toggled for page ${page.pageNumber}`);
}}
>
<ContentCutIcon style={{ fontSize: 20 }} />
</ActionIcon>
</Tooltip>
<Tooltip label="Select Page">
<Checkbox
size="md"
checked={selectedPages.includes(page.id)}
onChange={() => togglePage(page.id)}
styles={{
input: { backgroundColor: 'white' }
}}
/>
</Tooltip>
</div>
<DragIndicatorIcon <DragIndicatorIcon
style={{ style={{
position: 'absolute', position: 'absolute',
bottom: 4, bottom: 4,
right: 4, right: 4,
color: 'rgba(0,0,0,0.5)', color: 'rgba(0,0,0,0.3)',
fontSize: 16 fontSize: 16,
zIndex: 1
}} }}
/> />
</Box> </div>
</div>
<Text size="xs" c="dimmed"> </React.Fragment>
Page {page.pageNumber}
</Text>
</Stack>
</Box>
))} ))}
</SimpleGrid>
{/* Landing zone at the end */}
<div
data-drop-zone="end"
style={{
width: '15rem',
height: '15rem',
border: '2px dashed #9ca3af',
borderRadius: '8px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flexShrink: 0,
backgroundColor: dropTarget === 'end' ? '#ecfdf5' : 'transparent',
borderColor: dropTarget === 'end' ? '#10b981' : '#9ca3af',
transition: 'all 0.2s ease-in-out'
}}
onDragOver={handleDragOver}
onDragEnter={handleEndZoneDragEnter}
onDragLeave={handleDragLeave}
onDrop={(e) => handleDrop(e, 'end')}
>
<Text c="dimmed" size="sm" ta="center">
Drop here to<br />move to end
</Text>
</div>
</div>
<Group justify="space-between" mt="md"> <Group justify="space-between" mt="md">
<Button <Button
@ -524,6 +774,7 @@ const PageEditor: React.FC<PageEditorProps> = ({
</Button> </Button>
</Group> </Group>
</Group> </Group>
</Box>
<Modal <Modal
opened={showExportModal} opened={showExportModal}
@ -584,7 +835,6 @@ const PageEditor: React.FC<PageEditorProps> = ({
onChange={(file) => file && handleFileUpload(file)} onChange={(file) => file && handleFileUpload(file)}
style={{ display: 'none' }} style={{ display: 'none' }}
/> />
</Paper>
{status && ( {status && (
<Notification <Notification
@ -596,7 +846,7 @@ const PageEditor: React.FC<PageEditorProps> = ({
{status} {status}
</Notification> </Notification>
)} )}
</Container> </Box>
); );
}; };

View File

@ -1,4 +1,5 @@
import '@mantine/core/styles.css'; import '@mantine/core/styles.css';
import './index.css'; // Import Tailwind CSS
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom/client'; import ReactDOM from 'react-dom/client';
import { ColorSchemeScript, MantineProvider, mantineHtmlProps } from '@mantine/core'; import { ColorSchemeScript, MantineProvider, mantineHtmlProps } from '@mantine/core';