Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Add reusable STEP import dropzone with Zod validation
Yuechen Li188db8a760c9
diff --git a/aetheris.client/package-lock.json b/aetheris.client/package-lock.jsonindex 74c053e4..d9dc22a4 100644--- a/aetheris.client/package-lock.json+++ b/aetheris.client/package-lock.json@@ -15,7 +15,8 @@"react": "^19.2.0","react-dom": "^19.2.0","tailwind-merge": "^3.5.0",- "three": "^0.183.1"+ "three": "^0.183.1",+ "zod": "^3.25.76"},"devDependencies": {"@eslint/js": "^9.39.1",@@ -5944,10 +5945,9 @@}},"node_modules/zod": {- "version": "4.3.6",- "resolved": "https://registry.npmjs.org/zod/-/zod-4.3.6.tgz",- "integrity": "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==",- "dev": true,+ "version": "3.25.76",+ "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",+ "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==","license": "MIT","funding": {"url": "https://github.com/sponsors/colinhacks"diff --git a/aetheris.client/package.json b/aetheris.client/package.jsonindex 7a109d39..c283094c 100644--- a/aetheris.client/package.json+++ b/aetheris.client/package.json@@ -18,7 +18,8 @@"react": "^19.2.0","react-dom": "^19.2.0","tailwind-merge": "^3.5.0",- "three": "^0.183.1"+ "three": "^0.183.1",+ "zod": "^3.25.76"},"devDependencies": {"@eslint/js": "^9.39.1",diff --git a/aetheris.client/src/App.css b/aetheris.client/src/App.cssindex 8cd6d5da..612b3bf3 100644--- a/aetheris.client/src/App.css+++ b/aetheris.client/src/App.css@@ -399,3 +399,41 @@ strong {.audit-panel p {margin: 2px 0;}++.step-dropzone__input {+ display: none;+}++.step-dropzone {+ border: var(--layout-border-weight) dashed hsl(var(--border));+ border-radius: var(--layout-radius);+ background: hsla(var(--muted), 0.3);+ min-height: 74px;+ display: flex;+ align-items: center;+ justify-content: center;+ text-align: center;+ cursor: pointer;+ padding: 10px 12px;+ transition: border-color 120ms ease, background-color 120ms ease;+}++.step-dropzone p {+ margin: 0;+ font-size: 0.78rem;+ letter-spacing: 0.03em;+ color: hsl(var(--muted-foreground));+}++.step-dropzone:hover,+.step-dropzone:focus-visible,+.step-dropzone--active {+ border-color: #6f8f8a;+ background: hsla(var(--muted), 0.5);+ outline: none;+}++.step-import-validation {+ color: #7f4a4a;+ font-size: 0.78rem;+}diff --git a/aetheris.client/src/App.tsx b/aetheris.client/src/App.tsxindex a8936fef..41e34d9d 100644--- a/aetheris.client/src/App.tsx+++ b/aetheris.client/src/App.tsx@@ -17,6 +17,7 @@ import {type PickHitDto,type TessellationResponseDto,} from './api/aetherisApi';+import { StepImportDropzone } from './components/StepImportDropzone';import { Button } from './components/ui/button';import { ViewerViewport } from './viewer/ViewerViewport';import { mapTessellationToRenderData } from './viewer/tessellationMapper';@@ -65,6 +66,7 @@ function App() {const [stepImportFile, setStepImportFile] = useState<File | null>(null);const [stepCanonicalHash, setStepCanonicalHash] = useState<string | null>(null);const [stepImportSelectionMessage, setStepImportSelectionMessage] = useState('No file selected.');+ const [stepImportValidationMessage, setStepImportValidationMessage] = useState<string | null>(null);const [copyHashMessage, setCopyHashMessage] = useState('');const [isImporting, setIsImporting] = useState(false);const [isRefreshing, setIsRefreshing] = useState(false);@@ -88,6 +90,7 @@ function App() {setStepImportFile(null);setStepCanonicalHash(null);setStepImportSelectionMessage('No file selected.');+ setStepImportValidationMessage(null);setCopyHashMessage('');setDiagnostics([]);setImportStatusMessage('Preparing workspace…');@@ -368,12 +371,16 @@ function App() {}}, [documentId, documentStatus, maxStepFileSizeBytes, refreshSummaryAndActiveTessellation, runAction, serverStatus, stepImportFile]);- const handleStepFileSelection = useCallback((fileList: FileList | null) => {- const selected = fileList?.[0] ?? null;+ const handleStepFileAccepted = useCallback((selected: File) => {setStepImportFile(selected);- setStepImportSelectionMessage(selected- ? `Selected file: ${selected.name} (${selected.size} bytes)`- : 'No file selected.');+ setStepImportSelectionMessage(`Selected file: ${selected.name} (${selected.size} bytes)`);+ setStepImportValidationMessage(null);+ }, []);++ const handleStepFileValidationError = useCallback((message: string) => {+ setStepImportFile(null);+ setStepImportSelectionMessage('No file selected.');+ setStepImportValidationMessage(message);}, []);const handleUseActiveBodyAsTarget = useCallback(() => {@@ -562,14 +569,11 @@ function App() {<><section className="tool-section tool-section--import"><h2 className="section-title">Step Import</h2>- <label>- STEP 242 File- <input- type="file"- accept=".step,.stp,text/plain"- onChange={(event) => handleStepFileSelection(event.target.files)}- />- </label>+ <StepImportDropzone+ onFileAccepted={handleStepFileAccepted}+ onValidationError={handleStepFileValidationError}+ />+ {stepImportValidationMessage ? <p className="step-import-validation">{stepImportValidationMessage}</p> : null}<p>{stepImportSelectionMessage}</p><Button type="button" onClick={() => void handleImportStep()} disabled={!canImportStep}>Import STEP 242</Button><div className={`import-status-box import-status-box--${importStatusTone}`}>diff --git a/aetheris.client/src/__tests__/App.test.tsx b/aetheris.client/src/__tests__/App.test.tsxindex 3dba4007..f4a7117a 100644--- a/aetheris.client/src/__tests__/App.test.tsx+++ b/aetheris.client/src/__tests__/App.test.tsx@@ -112,7 +112,7 @@ describe('App STEP file upload flow', () => {render(<App />);await screen.findByText('Document: Ready');- const fileInput = screen.getByLabelText('STEP 242 File') as HTMLInputElement;+ const fileInput = screen.getByTestId('step-import-file-input') as HTMLInputElement;const file = new File(['ISO-10303-21;DATA;'], 'part.stp', { type: 'text/plain' });fireEvent.change(fileInput, { target: { files: [file] } });@@ -125,13 +125,42 @@ describe('App STEP file upload flow', () => {render(<App />);await screen.findByText('Document: Ready');- const fileInput = screen.getByLabelText('STEP 242 File') as HTMLInputElement;+ const fileInput = screen.getByTestId('step-import-file-input') as HTMLInputElement;const file = new File(['ISO-10303-21;'], 'sample.step', { type: 'text/plain' });fireEvent.change(fileInput, { target: { files: [file] } });expect(screen.getByText('Selected file: sample.step (13 bytes)')).toBeTruthy();});++ it('shows inline validation when non-STEP file is selected', async () => {+ render(<App />);+ await screen.findByText('Document: Ready');++ const fileInput = screen.getByTestId('step-import-file-input') as HTMLInputElement;+ const file = new File(['hello'], 'notes.txt', { type: 'text/plain' });+ fireEvent.change(fileInput, { target: { files: [file] } });++ expect(screen.getByText('Unsupported file type. Please select a .step or .stp file.')).toBeTruthy();+ expect(screen.getByText('No file selected.')).toBeTruthy();+ expect((screen.getByRole('button', { name: 'Import STEP 242' }) as HTMLButtonElement).disabled).toBe(true);+ });++ it('accepts drag-and-drop STEP files', async () => {+ render(<App />);+ await screen.findByText('Document: Ready');++ const dropzone = screen.getByRole('button', { name: 'Drop STEP file here or click to browse' });+ const file = new File(['ISO-10303-21;'], 'dragged.stp', { type: 'text/plain' });+ fireEvent.drop(dropzone, {+ dataTransfer: {+ files: [file],+ },+ });++ expect(screen.getByText('Selected file: dragged.stp (13 bytes)')).toBeTruthy();+ });+it('calls importStep with file contents and refreshes canonical hash', async () => {apiMocks.importStep.mockResolvedValue({documentId: 'doc-1',@@ -151,7 +180,7 @@ describe('App STEP file upload flow', () => {render(<App />);await screen.findByText('Document: Ready');- const fileInput = screen.getByLabelText('STEP 242 File') as HTMLInputElement;+ const fileInput = screen.getByTestId('step-import-file-input') as HTMLInputElement;const file = new File(['ISO-10303-21;DATA;'], 'part.stp', { type: 'text/plain' });fireEvent.change(fileInput, { target: { files: [file] } });@@ -226,7 +255,7 @@ describe('App STEP file upload flow', () => {render(<App />);await screen.findByText('Document: Ready');- const fileInput = screen.getByLabelText('STEP 242 File') as HTMLInputElement;+ const fileInput = screen.getByTestId('step-import-file-input') as HTMLInputElement;const file = new File(['BAD'], 'bad.step', { type: 'text/plain' });fireEvent.change(fileInput, { target: { files: [file] } });@@ -265,7 +294,7 @@ describe('App STEP file upload flow', () => {render(<App />);- const fileInput = screen.getByLabelText('STEP 242 File') as HTMLInputElement;+ const fileInput = screen.getByTestId('step-import-file-input') as HTMLInputElement;const file = new File(['ISO-10303-21;DATA;'], 'part.stp', { type: 'text/plain' });fireEvent.change(fileInput, { target: { files: [file] } });@@ -284,7 +313,7 @@ describe('App STEP file upload flow', () => {render(<App />);await screen.findByText('Document: Ready');- const fileInput = screen.getByLabelText('STEP 242 File') as HTMLInputElement;+ const fileInput = screen.getByTestId('step-import-file-input') as HTMLInputElement;const file = new File(['ISO-10303-21;'], 'sample.step', { type: 'text/plain' });fireEvent.change(fileInput, { target: { files: [file] } });expect(screen.getByText(/Selected file: sample.step \(\d+ bytes\)/)).toBeTruthy();diff --git a/aetheris.client/src/components/StepImportDropzone.tsx b/aetheris.client/src/components/StepImportDropzone.tsxnew file mode 100644index 00000000..b0aa05d4--- /dev/null+++ b/aetheris.client/src/components/StepImportDropzone.tsx@@ -0,0 +1,111 @@+import { useCallback, useMemo, useRef, useState, type DragEvent } from 'react';+import { z } from 'zod';++type StepImportDropzoneProps = {+ onFileAccepted: (file: File) => void;+ onValidationError: (message: string) => void;+};++const stepFileSelectionSchema = z+ .array(z.instanceof(File))+ .length(1, 'Please select a single STEP file.')+ .superRefine((files, ctx) => {+ const [file] = files;++ if (!file) {+ return;+ }++ const lowerName = file.name.toLowerCase();+ if (!lowerName.endsWith('.step') && !lowerName.endsWith('.stp')) {+ ctx.addIssue({+ code: z.ZodIssueCode.custom,+ message: 'Unsupported file type. Please select a .step or .stp file.',+ });+ }++ if (file.size <= 0) {+ ctx.addIssue({+ code: z.ZodIssueCode.custom,+ message: 'File is empty.',+ });+ }+ });++function fileListToArray(fileList: FileList | null): File[] {+ return fileList ? Array.from(fileList) : [];+}++export function StepImportDropzone({ onFileAccepted, onValidationError }: StepImportDropzoneProps) {+ const [isDragActive, setIsDragActive] = useState(false);+ const inputRef = useRef<HTMLInputElement | null>(null);++ const handleFiles = useCallback((files: File[]) => {+ const parsed = stepFileSelectionSchema.safeParse(files);+ if (!parsed.success) {+ onValidationError(parsed.error.issues[0]?.message ?? 'Invalid STEP file selection.');+ return;+ }++ onFileAccepted(parsed.data[0]);+ }, [onFileAccepted, onValidationError]);++ const handleBrowseClick = useCallback(() => {+ inputRef.current?.click();+ }, []);++ const handleDragOver = useCallback((event: DragEvent<HTMLDivElement>) => {+ event.preventDefault();+ event.dataTransfer.dropEffect = 'copy';+ setIsDragActive(true);+ }, []);++ const handleDragLeave = useCallback((event: DragEvent<HTMLDivElement>) => {+ event.preventDefault();+ setIsDragActive(false);+ }, []);++ const handleDrop = useCallback((event: DragEvent<HTMLDivElement>) => {+ event.preventDefault();+ setIsDragActive(false);+ handleFiles(fileListToArray(event.dataTransfer.files));+ }, [handleFiles]);++ const className = useMemo(+ () => `step-dropzone${isDragActive ? ' step-dropzone--active' : ''}`,+ [isDragActive],+ );++ return (+ <>+ <input+ ref={inputRef}+ className="step-dropzone__input"+ type="file"+ accept=".step,.stp,text/plain"+ aria-label="STEP 242 File"+ data-testid="step-import-file-input"+ onChange={(event) => {+ handleFiles(fileListToArray(event.target.files));+ event.currentTarget.value = '';+ }}+ />+ <div+ className={className}+ role="button"+ tabIndex={0}+ onClick={handleBrowseClick}+ onKeyDown={(event) => {+ if (event.key === 'Enter' || event.key === ' ') {+ event.preventDefault();+ handleBrowseClick();+ }+ }}+ onDragOver={handleDragOver}+ onDragLeave={handleDragLeave}+ onDrop={handleDrop}>+ <p>Drop STEP file here or click to browse</p>+ </div>+ </>+ );+}