mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-26 14:19:24 +00:00
working split
This commit is contained in:
parent
d5e1a3eccb
commit
86221c2082
@ -111,11 +111,14 @@ export default function Workbench() {
|
||||
onRotate={pageEditorFunctions.handleRotate}
|
||||
onDelete={pageEditorFunctions.handleDelete}
|
||||
onSplit={pageEditorFunctions.handleSplit}
|
||||
onSplitAll={pageEditorFunctions.handleSplitAll}
|
||||
onExportSelected={pageEditorFunctions.onExportSelected}
|
||||
onExportAll={pageEditorFunctions.onExportAll}
|
||||
exportLoading={pageEditorFunctions.exportLoading}
|
||||
selectionMode={pageEditorFunctions.selectionMode}
|
||||
selectedPages={pageEditorFunctions.selectedPages}
|
||||
splitPositions={pageEditorFunctions.splitPositions}
|
||||
totalPages={pageEditorFunctions.totalPages}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
|
@ -127,6 +127,7 @@ export interface PageEditorProps {
|
||||
handleRotate: (direction: 'left' | 'right') => void;
|
||||
handleDelete: () => void;
|
||||
handleSplit: () => void;
|
||||
handleSplitAll: () => void;
|
||||
showExportPreview: (selectedOnly: boolean) => void;
|
||||
onExportSelected: () => void;
|
||||
onExportAll: () => void;
|
||||
@ -134,6 +135,8 @@ export interface PageEditorProps {
|
||||
exportLoading: boolean;
|
||||
selectionMode: boolean;
|
||||
selectedPages: number[];
|
||||
splitPositions: Set<number>;
|
||||
totalPages: number;
|
||||
closePdf: () => void;
|
||||
}) => void;
|
||||
}
|
||||
@ -523,6 +526,28 @@ const PageEditor = ({
|
||||
});
|
||||
}, [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[]) => {
|
||||
if (!displayDocument) return;
|
||||
|
||||
@ -729,6 +754,7 @@ const PageEditor = ({
|
||||
handleRotate,
|
||||
handleDelete,
|
||||
handleSplit,
|
||||
handleSplitAll,
|
||||
showExportPreview: handleExportPreview,
|
||||
onExportSelected,
|
||||
onExportAll,
|
||||
@ -736,12 +762,15 @@ const PageEditor = ({
|
||||
exportLoading,
|
||||
selectionMode,
|
||||
selectedPages: selectedPageNumbers,
|
||||
splitPositions,
|
||||
totalPages: displayDocument?.pages.length || 0,
|
||||
closePdf,
|
||||
});
|
||||
}
|
||||
}, [
|
||||
onFunctionsReady, handleUndo, handleRedo, handleRotate, handleDelete, handleSplit,
|
||||
handleExportPreview, onExportSelected, onExportAll, applyChanges, exportLoading, selectionMode, selectedPageNumbers, closePdf
|
||||
onFunctionsReady, handleUndo, handleRedo, handleRotate, handleDelete, handleSplit, handleSplitAll,
|
||||
handleExportPreview, onExportSelected, onExportAll, applyChanges, exportLoading, selectionMode, selectedPageNumbers,
|
||||
splitPositions, displayDocument?.pages.length, closePdf
|
||||
]);
|
||||
|
||||
// Display all pages - use edited or original document
|
||||
|
@ -27,6 +27,7 @@ interface PageEditorControlsProps {
|
||||
onRotate: (direction: 'left' | 'right') => void;
|
||||
onDelete: () => void;
|
||||
onSplit: () => void;
|
||||
onSplitAll: () => void;
|
||||
|
||||
// Export functions
|
||||
onExportSelected: () => void;
|
||||
@ -36,6 +37,10 @@ interface PageEditorControlsProps {
|
||||
// Selection state
|
||||
selectionMode: boolean;
|
||||
selectedPages: number[];
|
||||
|
||||
// Split state (for tooltip logic)
|
||||
splitPositions?: Set<number>;
|
||||
totalPages?: number;
|
||||
}
|
||||
|
||||
const PageEditorControls = ({
|
||||
@ -47,12 +52,33 @@ const PageEditorControls = ({
|
||||
onRotate,
|
||||
onDelete,
|
||||
onSplit,
|
||||
onSplitAll,
|
||||
onExportSelected,
|
||||
onExportAll,
|
||||
exportLoading,
|
||||
selectionMode,
|
||||
selectedPages
|
||||
selectedPages,
|
||||
splitPositions,
|
||||
totalPages
|
||||
}: 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 (
|
||||
<div
|
||||
style={{
|
||||
@ -144,9 +170,9 @@ const PageEditorControls = ({
|
||||
<DeleteIcon />
|
||||
</ActionIcon>
|
||||
</Tooltip>
|
||||
<Tooltip label={selectionMode ? "Split Selected" : "Split All"}>
|
||||
<Tooltip label={getSplitAllTooltip()}>
|
||||
<ActionIcon
|
||||
onClick={onSplit}
|
||||
onClick={selectionMode ? onSplit : onSplitAll}
|
||||
disabled={selectionMode && selectedPages.length === 0}
|
||||
variant={selectionMode && selectedPages.length > 0 ? "light" : "default"}
|
||||
color={selectionMode && selectedPages.length > 0 ? "blue" : undefined}
|
||||
|
Loading…
x
Reference in New Issue
Block a user