mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2026-09-03 05:10:16 +03:00
🔄 Dynamic Processing Strategies - Adaptive routing: Same tool uses different backend endpoints based on file analysis - Combined vs separate processing: Intelligently chooses between merge operations and individual file processing - Cross-format workflows: Enable complex conversions like "mixed files → PDF" that other tools can't handle ⚙️ Format-Specific Intelligence Each conversion type gets tailored options: - HTML/ZIP → PDF: Zoom controls (0.1-3.0 increments) with live preview - Email → PDF: Attachment handling, size limits, recipient control - PDF → PDF/A: Digital signature detection with warnings - Images → PDF: Smart combining vs individual file options File Architecture Core Implementation: ├── Convert.tsx # Main stepped workflow UI ├── ConvertSettings.tsx # Centralized settings with smart detection ├── GroupedFormatDropdown.tsx # Enhanced format selector with grouping ├── useConvertParameters.ts # Smart detection & parameter management ├── useConvertOperation.ts # Multi-strategy processing logic └── Settings Components: ├── ConvertFromWebSettings.tsx # HTML zoom controls ├── ConvertFromEmailSettings.tsx # Email attachment options ├── ConvertToPdfaSettings.tsx # PDF/A with signature detection ├── ConvertFromImageSettings.tsx # Image PDF options └── ConvertToImageSettings.tsx # PDF to image options Utility Layer Utils & Services: ├── convertUtils.ts # Format detection & endpoint routing ├── fileResponseUtils.ts # Generic API response handling └── setupTests.ts # Enhanced test environment with crypto mocks Testing & Quality Comprehensive Test Coverage Test Suite: ├── useConvertParameters.test.ts # Parameter logic & smart detection ├── useConvertParametersAutoDetection.test.ts # File type analysis ├── ConvertIntegration.test.tsx # End-to-end conversion workflows ├── ConvertSmartDetectionIntegration.test.tsx # Mixed file scenarios ├── ConvertE2E.spec.ts # Playwright browser tests ├── convertUtils.test.ts # Utility function validation └── fileResponseUtils.test.ts # API response handling Advanced Test Features - Crypto API mocking: Proper test environment for file hashing - File.arrayBuffer() polyfills: Complete browser API simulation - Multi-file scenario testing: Complex batch processing validation - CI/CD integration: Vitest runs in GitHub Actions with proper artifacts --------- Co-authored-by: Connor Yoh <connor@stirlingpdf.com> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
154 lines
3.8 KiB
TypeScript
154 lines
3.8 KiB
TypeScript
import React, { createContext, useContext, useMemo, useRef } from 'react';
|
|
import { Paper, Text, Stack, Box, Flex } from '@mantine/core';
|
|
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
|
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
|
|
|
|
interface ToolStepContextType {
|
|
visibleStepCount: number;
|
|
getStepNumber: () => number;
|
|
}
|
|
|
|
const ToolStepContext = createContext<ToolStepContextType | null>(null);
|
|
|
|
export interface ToolStepProps {
|
|
title: string;
|
|
isVisible?: boolean;
|
|
isCollapsed?: boolean;
|
|
isCompleted?: boolean;
|
|
onCollapsedClick?: () => void;
|
|
children?: React.ReactNode;
|
|
completedMessage?: string;
|
|
helpText?: string;
|
|
showNumber?: boolean;
|
|
}
|
|
|
|
const ToolStep = ({
|
|
title,
|
|
isVisible = true,
|
|
isCollapsed = false,
|
|
isCompleted = false,
|
|
onCollapsedClick,
|
|
children,
|
|
completedMessage,
|
|
helpText,
|
|
showNumber
|
|
}: ToolStepProps) => {
|
|
if (!isVisible) return null;
|
|
|
|
const parent = useContext(ToolStepContext);
|
|
|
|
// Auto-detect if we should show numbers based on sibling count
|
|
const shouldShowNumber = useMemo(() => {
|
|
if (showNumber !== undefined) return showNumber;
|
|
return parent ? parent.visibleStepCount >= 3 : false;
|
|
}, [showNumber, parent]);
|
|
|
|
const stepNumber = parent?.getStepNumber?.() || 1;
|
|
|
|
return (
|
|
<Paper
|
|
p="md"
|
|
withBorder
|
|
style={{
|
|
opacity: isCollapsed ? 0.8 : 1,
|
|
transition: 'opacity 0.2s ease'
|
|
}}
|
|
>
|
|
{/* Chevron icon to collapse/expand the step */}
|
|
<Flex
|
|
align="center"
|
|
justify="space-between"
|
|
mb="sm"
|
|
style={{
|
|
cursor: onCollapsedClick ? 'pointer' : 'default'
|
|
}}
|
|
onClick={onCollapsedClick}
|
|
>
|
|
<Flex align="center" gap="sm">
|
|
{shouldShowNumber && (
|
|
<Text fw={500} size="lg" c="dimmed">
|
|
{stepNumber}
|
|
</Text>
|
|
)}
|
|
<Text fw={500} size="lg">
|
|
{title}
|
|
</Text>
|
|
</Flex>
|
|
|
|
{isCollapsed ? (
|
|
<ChevronRightIcon style={{
|
|
fontSize: '1.2rem',
|
|
color: 'var(--mantine-color-dimmed)',
|
|
opacity: onCollapsedClick ? 1 : 0.5
|
|
}} />
|
|
) : (
|
|
<ExpandMoreIcon style={{
|
|
fontSize: '1.2rem',
|
|
color: 'var(--mantine-color-dimmed)',
|
|
opacity: onCollapsedClick ? 1 : 0.5
|
|
}} />
|
|
)}
|
|
</Flex>
|
|
|
|
{isCollapsed ? (
|
|
<Box>
|
|
{isCompleted && completedMessage && (
|
|
<Text size="sm" c="green">
|
|
✓ {completedMessage}
|
|
{onCollapsedClick && (
|
|
<Text span c="dimmed" size="xs" ml="sm">
|
|
(click to change)
|
|
</Text>
|
|
)}
|
|
</Text>
|
|
)}
|
|
</Box>
|
|
) : (
|
|
<Stack gap="md">
|
|
{helpText && (
|
|
<Text size="sm" c="dimmed">
|
|
{helpText}
|
|
</Text>
|
|
)}
|
|
{children}
|
|
</Stack>
|
|
)}
|
|
</Paper>
|
|
);
|
|
}
|
|
|
|
export interface ToolStepContainerProps {
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
export const ToolStepContainer = ({ children }: ToolStepContainerProps) => {
|
|
const stepCounterRef = useRef(0);
|
|
|
|
// Count visible ToolStep children
|
|
const visibleStepCount = useMemo(() => {
|
|
let count = 0;
|
|
React.Children.forEach(children, (child) => {
|
|
if (React.isValidElement(child) && child.type === ToolStep) {
|
|
const isVisible = (child.props as ToolStepProps).isVisible !== false;
|
|
if (isVisible) count++;
|
|
}
|
|
});
|
|
return count;
|
|
}, [children]);
|
|
|
|
const contextValue = useMemo(() => ({
|
|
visibleStepCount,
|
|
getStepNumber: () => ++stepCounterRef.current
|
|
}), [visibleStepCount]);
|
|
|
|
stepCounterRef.current = 0;
|
|
|
|
return (
|
|
<ToolStepContext.Provider value={contextValue}>
|
|
{children}
|
|
</ToolStepContext.Provider>
|
|
);
|
|
}
|
|
|
|
export default ToolStep;
|