Cleanup/v2/text editor (#5169)

# Description of Changes

<img width="2056" height="1075" alt="Screenshot 2025-12-04 at 8 16
28 PM"
src="https://github.com/user-attachments/assets/9d2deacb-e471-4711-b9ac-9ef5a64b6f23"
/>
<img width="2056" height="1070" alt="Screenshot 2025-12-04 at 8 16
51 PM"
src="https://github.com/user-attachments/assets/07f07835-c973-4f56-80fb-5efc00ff1651"
/>
<img width="728" height="517" alt="Screenshot 2025-12-04 at 8 17 04 PM"
src="https://github.com/user-attachments/assets/8c59fae0-93a8-4da5-b2e4-9a89be651b7f"
/>
<img width="388" height="218" alt="Screenshot 2025-12-04 at 8 17 29 PM"
src="https://github.com/user-attachments/assets/997e9a68-6a3b-4033-bc45-04e3945f23d5"
/>


---

## Checklist

### General

- [ ] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md)
(if applicable)
- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing)
for more details.
This commit is contained in:
EthanHealy01
2025-12-22 18:25:25 +00:00
committed by GitHub
parent ddba5a3eab
commit d9622d0fac
7 changed files with 696 additions and 397 deletions
@@ -34,6 +34,7 @@ import {
valueOr,
} from '@app/tools/pdfTextEditor/pdfTextEditorUtils';
import PdfTextEditorView from '@app/components/tools/pdfTextEditor/PdfTextEditorView';
import PdfTextEditorSidebar from '@app/components/tools/pdfTextEditor/PdfTextEditorSidebar';
import type { PDFDocumentProxy } from 'pdfjs-dist';
const WORKBENCH_VIEW_ID = 'pdfTextEditorWorkbench';
@@ -228,6 +229,7 @@ const PdfTextEditor = ({ onComplete, onError }: BaseToolProps) => {
const [groupingMode, setGroupingMode] = useState<'auto' | 'paragraph' | 'singleLine'>('auto');
const [hasVectorPreview, setHasVectorPreview] = useState(false);
const [pagePreviews, setPagePreviews] = useState<Map<number, string>>(new Map());
const [autoScaleText, setAutoScaleText] = useState(true);
// Lazy loading state
const [isLazyMode, setIsLazyMode] = useState(false);
@@ -1565,6 +1567,8 @@ const PdfTextEditor = ({ onComplete, onError }: BaseToolProps) => {
hasChanges,
forceSingleTextElement,
groupingMode,
autoScaleText,
onAutoScaleTextChange: setAutoScaleText,
requestPagePreview,
onSelectPage: handleSelectPage,
onGroupEdit: handleGroupTextChange,
@@ -1613,6 +1617,7 @@ const PdfTextEditor = ({ onComplete, onError }: BaseToolProps) => {
selectedPage,
forceSingleTextElement,
groupingMode,
autoScaleText,
requestPagePreview,
setForceSingleTextElement,
handleLoadFileFromDropzone,
@@ -1683,12 +1688,17 @@ const PdfTextEditor = ({ onComplete, onError }: BaseToolProps) => {
icon: <DescriptionIcon fontSize="small" />,
component: PdfTextEditorView,
});
setLeftPanelView('hidden');
setCustomWorkbenchViewData(WORKBENCH_VIEW_ID, latestViewDataRef.current);
return () => {
// Clear backend cache if we were using lazy loading
clearCachedJob(cachedJobIdRef.current);
clearCustomWorkbenchViewData(WORKBENCH_VIEW_ID);
unregisterCustomWorkbenchView(WORKBENCH_VIEW_ID);
};
}, [
registerCustomWorkbenchView,
setCustomWorkbenchViewData,
setLeftPanelView,
viewLabel,
]);
@@ -1723,12 +1733,12 @@ const PdfTextEditor = ({ onComplete, onError }: BaseToolProps) => {
setCustomWorkbenchViewData(WORKBENCH_VIEW_ID, viewData);
}, [setCustomWorkbenchViewData, viewData]);
// All editing happens in the custom workbench view.
return null;
// Render the sidebar with settings while editing happens in the custom workbench view.
return <PdfTextEditorSidebar data={viewData} />;
};
(PdfTextEditor as ToolComponent).tool = () => {
throw new Error('PDF JSON Editor does not support automation operations.');
throw new Error('PDF Text Editor does not support automation operations.');
};
(PdfTextEditor as ToolComponent).getDefaultParameters = () => ({
@@ -201,6 +201,8 @@ export interface PdfTextEditorViewData {
hasChanges: boolean;
forceSingleTextElement: boolean;
groupingMode: 'auto' | 'paragraph' | 'singleLine';
autoScaleText: boolean;
onAutoScaleTextChange: (value: boolean) => void;
requestPagePreview: (pageIndex: number, scale: number) => void;
onSelectPage: (pageIndex: number) => void;
onGroupEdit: (pageIndex: number, groupId: string, value: string) => void;