working split

This commit is contained in:
Reece Browne 2025-08-23 02:03:51 +01:00
parent d5e1a3eccb
commit 86221c2082
3 changed files with 63 additions and 5 deletions

View File

@ -111,11 +111,14 @@ export default function Workbench() {
onRotate={pageEditorFunctions.handleRotate} onRotate={pageEditorFunctions.handleRotate}
onDelete={pageEditorFunctions.handleDelete} onDelete={pageEditorFunctions.handleDelete}
onSplit={pageEditorFunctions.handleSplit} onSplit={pageEditorFunctions.handleSplit}
onSplitAll={pageEditorFunctions.handleSplitAll}
onExportSelected={pageEditorFunctions.onExportSelected} onExportSelected={pageEditorFunctions.onExportSelected}
onExportAll={pageEditorFunctions.onExportAll} onExportAll={pageEditorFunctions.onExportAll}
exportLoading={pageEditorFunctions.exportLoading} exportLoading={pageEditorFunctions.exportLoading}
selectionMode={pageEditorFunctions.selectionMode} selectionMode={pageEditorFunctions.selectionMode}
selectedPages={pageEditorFunctions.selectedPages} selectedPages={pageEditorFunctions.selectedPages}
splitPositions={pageEditorFunctions.splitPositions}
totalPages={pageEditorFunctions.totalPages}
/> />
)} )}
</> </>

View File

@ -127,6 +127,7 @@ export interface PageEditorProps {
handleRotate: (direction: 'left' | 'right') => void; handleRotate: (direction: 'left' | 'right') => void;
handleDelete: () => void; handleDelete: () => void;
handleSplit: () => void; handleSplit: () => void;
handleSplitAll: () => void;
showExportPreview: (selectedOnly: boolean) => void; showExportPreview: (selectedOnly: boolean) => void;
onExportSelected: () => void; onExportSelected: () => void;
onExportAll: () => void; onExportAll: () => void;
@ -134,6 +135,8 @@ export interface PageEditorProps {
exportLoading: boolean; exportLoading: boolean;
selectionMode: boolean; selectionMode: boolean;
selectedPages: number[]; selectedPages: number[];
splitPositions: Set<number>;
totalPages: number;
closePdf: () => void; closePdf: () => void;
}) => void; }) => void;
} }
@ -523,6 +526,28 @@ const PageEditor = ({
}); });
}, [selectedPageNumbers, displayDocument]); }, [selectedPageNumbers, displayDocument]);
const handleSplitAll = useCallback(() => {
if (!displayDocument) return;
// Check if all possible split positions are already set
const allPossibleSplits = new Set<number>();
for (let i = 0; i < displayDocument.pages.length - 1; i++) {
allPossibleSplits.add(i);
}
const hasAllSplits = Array.from(allPossibleSplits).every(pos => splitPositions.has(pos));
if (hasAllSplits) {
// Remove all splits
console.log('Removing all split markers');
setSplitPositions(new Set());
} else {
// Add split marker after every page except the last one
console.log('Adding split markers after every page');
setSplitPositions(allPossibleSplits);
}
}, [displayDocument, splitPositions]);
const handleReorderPages = useCallback((sourcePageNumber: number, targetIndex: number, selectedPages?: number[]) => { const handleReorderPages = useCallback((sourcePageNumber: number, targetIndex: number, selectedPages?: number[]) => {
if (!displayDocument) return; if (!displayDocument) return;
@ -729,6 +754,7 @@ const PageEditor = ({
handleRotate, handleRotate,
handleDelete, handleDelete,
handleSplit, handleSplit,
handleSplitAll,
showExportPreview: handleExportPreview, showExportPreview: handleExportPreview,
onExportSelected, onExportSelected,
onExportAll, onExportAll,
@ -736,12 +762,15 @@ const PageEditor = ({
exportLoading, exportLoading,
selectionMode, selectionMode,
selectedPages: selectedPageNumbers, selectedPages: selectedPageNumbers,
splitPositions,
totalPages: displayDocument?.pages.length || 0,
closePdf, closePdf,
}); });
} }
}, [ }, [
onFunctionsReady, handleUndo, handleRedo, handleRotate, handleDelete, handleSplit, onFunctionsReady, handleUndo, handleRedo, handleRotate, handleDelete, handleSplit, handleSplitAll,
handleExportPreview, onExportSelected, onExportAll, applyChanges, exportLoading, selectionMode, selectedPageNumbers, closePdf handleExportPreview, onExportSelected, onExportAll, applyChanges, exportLoading, selectionMode, selectedPageNumbers,
splitPositions, displayDocument?.pages.length, closePdf
]); ]);
// Display all pages - use edited or original document // Display all pages - use edited or original document

View File

@ -27,6 +27,7 @@ interface PageEditorControlsProps {
onRotate: (direction: 'left' | 'right') => void; onRotate: (direction: 'left' | 'right') => void;
onDelete: () => void; onDelete: () => void;
onSplit: () => void; onSplit: () => void;
onSplitAll: () => void;
// Export functions // Export functions
onExportSelected: () => void; onExportSelected: () => void;
@ -36,6 +37,10 @@ interface PageEditorControlsProps {
// Selection state // Selection state
selectionMode: boolean; selectionMode: boolean;
selectedPages: number[]; selectedPages: number[];
// Split state (for tooltip logic)
splitPositions?: Set<number>;
totalPages?: number;
} }
const PageEditorControls = ({ const PageEditorControls = ({
@ -47,12 +52,33 @@ const PageEditorControls = ({
onRotate, onRotate,
onDelete, onDelete,
onSplit, onSplit,
onSplitAll,
onExportSelected, onExportSelected,
onExportAll, onExportAll,
exportLoading, exportLoading,
selectionMode, selectionMode,
selectedPages selectedPages,
splitPositions,
totalPages
}: PageEditorControlsProps) => { }: PageEditorControlsProps) => {
// Calculate split all tooltip text
const getSplitAllTooltip = () => {
if (selectionMode) {
return "Split Selected";
}
if (!splitPositions || !totalPages) {
return "Split All";
}
// Check if all possible splits are active
const allPossibleSplitsCount = totalPages - 1;
const hasAllSplits = splitPositions.size === allPossibleSplitsCount &&
Array.from({length: allPossibleSplitsCount}, (_, i) => i).every(pos => splitPositions.has(pos));
return hasAllSplits ? "Remove All Splits" : "Split All";
};
return ( return (
<div <div
style={{ style={{
@ -144,9 +170,9 @@ const PageEditorControls = ({
<DeleteIcon /> <DeleteIcon />
</ActionIcon> </ActionIcon>
</Tooltip> </Tooltip>
<Tooltip label={selectionMode ? "Split Selected" : "Split All"}> <Tooltip label={getSplitAllTooltip()}>
<ActionIcon <ActionIcon
onClick={onSplit} onClick={selectionMode ? onSplit : onSplitAll}
disabled={selectionMode && selectedPages.length === 0} disabled={selectionMode && selectedPages.length === 0}
variant={selectionMode && selectedPages.length > 0 ? "light" : "default"} variant={selectionMode && selectedPages.length > 0 ? "light" : "default"}
color={selectionMode && selectedPages.length > 0 ? "blue" : undefined} color={selectionMode && selectedPages.length > 0 ? "blue" : undefined}