|
| 1 | +# Multi-File Editor Design |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The GhostPaste multi-file editor follows GitHub Gist's UX pattern where files are displayed vertically in a single page rather than using tabs. This provides better visibility of all files and a more intuitive editing experience. |
| 6 | + |
| 7 | +## Design Principles |
| 8 | + |
| 9 | +1. **Vertical Layout**: All files visible at once, no hidden content |
| 10 | +2. **Inline Editing**: Each file is a self-contained unit with all controls |
| 11 | +3. **Progressive Disclosure**: Start with one file, add more as needed |
| 12 | +4. **Mobile-First**: Works well on all screen sizes |
| 13 | +5. **Accessibility**: Keyboard navigable, screen reader friendly |
| 14 | + |
| 15 | +## Component Architecture |
| 16 | + |
| 17 | +### 1. MultiFileEditor (Container) |
| 18 | + |
| 19 | +The main container that manages the state of all files. |
| 20 | + |
| 21 | +**State Management:** |
| 22 | + |
| 23 | +```typescript |
| 24 | +interface FileData { |
| 25 | + id: string; // Unique identifier (nanoid) |
| 26 | + name: string; // Filename with extension |
| 27 | + content: string; // File content |
| 28 | + language?: string; // Detected or selected language |
| 29 | +} |
| 30 | + |
| 31 | +const [files, setFiles] = useState<FileData[]>([ |
| 32 | + { id: nanoid(), name: "", content: "", language: "text" }, |
| 33 | +]); |
| 34 | +``` |
| 35 | + |
| 36 | +**Key Features:** |
| 37 | + |
| 38 | +- Manages array of files |
| 39 | +- Handles add/remove operations |
| 40 | +- Validates constraints (1-20 files) |
| 41 | +- Prevents duplicate filenames |
| 42 | +- Generates default filenames |
| 43 | + |
| 44 | +### 2. FileEditor (Individual File) |
| 45 | + |
| 46 | +Each file is rendered as a FileEditor component. |
| 47 | + |
| 48 | +**Layout:** |
| 49 | + |
| 50 | +``` |
| 51 | +┌─────────────────────────────────────────────────────────┐ |
| 52 | +│ [filename.js ] [JavaScript ▼] [✕] │ |
| 53 | +├─────────────────────────────────────────────────────────┤ |
| 54 | +│ │ |
| 55 | +│ // Your code here... │ |
| 56 | +│ │ |
| 57 | +│ │ |
| 58 | +└─────────────────────────────────────────────────────────┘ |
| 59 | +``` |
| 60 | + |
| 61 | +**Components:** |
| 62 | + |
| 63 | +- Filename input (with validation) |
| 64 | +- Language selector dropdown |
| 65 | +- Remove button (conditional) |
| 66 | +- CodeMirror editor |
| 67 | + |
| 68 | +### 3. AddFileButton |
| 69 | + |
| 70 | +Simple button component at the bottom of all files. |
| 71 | + |
| 72 | +``` |
| 73 | +┌─────────────────────────────────────┐ |
| 74 | +│ ➕ Add another file │ |
| 75 | +└─────────────────────────────────────┘ |
| 76 | +``` |
| 77 | + |
| 78 | +## User Interactions |
| 79 | + |
| 80 | +### Adding Files |
| 81 | + |
| 82 | +1. User clicks "Add another file" |
| 83 | +2. New FileEditor appended to bottom |
| 84 | +3. Page auto-scrolls to new file |
| 85 | +4. Focus placed on filename input |
| 86 | +5. Default filename generated (e.g., "file2.txt") |
| 87 | + |
| 88 | +### Removing Files |
| 89 | + |
| 90 | +1. User clicks ✕ button on file |
| 91 | +2. Confirmation if file has content |
| 92 | +3. File removed from list |
| 93 | +4. If last file, remove button hidden |
| 94 | + |
| 95 | +### Filename Changes |
| 96 | + |
| 97 | +1. User types in filename field |
| 98 | +2. Real-time validation: |
| 99 | + - No empty names |
| 100 | + - No duplicate names |
| 101 | + - Valid characters only |
| 102 | + - Max 255 characters |
| 103 | +3. Language auto-detected from extension |
| 104 | +4. Error shown below input if invalid |
| 105 | + |
| 106 | +### Language Selection |
| 107 | + |
| 108 | +1. Dropdown shows supported languages |
| 109 | +2. Selection updates syntax highlighting |
| 110 | +3. Manual selection overrides auto-detection |
| 111 | + |
| 112 | +## State Flow |
| 113 | + |
| 114 | +``` |
| 115 | +User Action State Update UI Update |
| 116 | +─────────── ──────────── ───────── |
| 117 | +Add File → files.push(newFile) → Render new FileEditor |
| 118 | + Auto-scroll to bottom |
| 119 | +
|
| 120 | +Remove File → files.filter(...) → Remove FileEditor |
| 121 | + Update remove buttons |
| 122 | +
|
| 123 | +Edit Filename → file.name = value → Validate & show errors |
| 124 | + file.language = auto Update syntax highlight |
| 125 | +
|
| 126 | +Edit Content → file.content = value → Update editor content |
| 127 | +
|
| 128 | +Select Lang → file.language = sel → Update syntax highlight |
| 129 | +``` |
| 130 | + |
| 131 | +## Responsive Behavior |
| 132 | + |
| 133 | +### Desktop (>768px) |
| 134 | + |
| 135 | +- Full-width editors |
| 136 | +- Side-by-side filename and language inputs |
| 137 | +- Comfortable spacing |
| 138 | + |
| 139 | +### Mobile (<768px) |
| 140 | + |
| 141 | +- Stacked filename and language inputs |
| 142 | +- Full-width editors |
| 143 | +- Touch-friendly button sizes |
| 144 | +- Reduced vertical spacing |
| 145 | + |
| 146 | +## Performance Considerations |
| 147 | + |
| 148 | +1. **Lazy Loading**: CodeMirror instances created on-demand |
| 149 | +2. **Debouncing**: Filename validation debounced |
| 150 | +3. **Virtual Scrolling**: For many files (future enhancement) |
| 151 | +4. **Memoization**: FileEditor components memoized |
| 152 | + |
| 153 | +## Accessibility |
| 154 | + |
| 155 | +1. **Keyboard Navigation**: |
| 156 | + |
| 157 | + - Tab through all inputs |
| 158 | + - Ctrl+Enter to add new file |
| 159 | + - Delete key to remove (with focus) |
| 160 | + |
| 161 | +2. **Screen Readers**: |
| 162 | + |
| 163 | + - Proper ARIA labels |
| 164 | + - Announce file operations |
| 165 | + - Describe editor state |
| 166 | + |
| 167 | +3. **Focus Management**: |
| 168 | + - Focus new file on add |
| 169 | + - Focus previous file on remove |
| 170 | + - Trap focus in dialogs |
| 171 | + |
| 172 | +## Error Handling |
| 173 | + |
| 174 | +1. **Filename Errors**: |
| 175 | + |
| 176 | + - "Filename is required" |
| 177 | + - "Filename already exists" |
| 178 | + - "Invalid characters in filename" |
| 179 | + |
| 180 | +2. **File Limit**: |
| 181 | + |
| 182 | + - Disable add button at 20 files |
| 183 | + - Show tooltip explaining limit |
| 184 | + |
| 185 | +3. **Content Size**: |
| 186 | + - Warn at 400KB per file |
| 187 | + - Error at 500KB per file |
| 188 | + - Show total size indicator |
| 189 | + |
| 190 | +## Future Enhancements |
| 191 | + |
| 192 | +1. **Drag and Drop Reordering** |
| 193 | +2. **File Templates** (e.g., "Add HTML/CSS/JS set") |
| 194 | +3. **Import from URL** |
| 195 | +4. **Syntax Validation** |
| 196 | +5. **Collaborative Editing** |
| 197 | + |
| 198 | +## Implementation Checklist |
| 199 | + |
| 200 | +- [ ] Create FileEditor component |
| 201 | +- [ ] Create MultiFileEditor container |
| 202 | +- [ ] Implement file state management |
| 203 | +- [ ] Add filename validation |
| 204 | +- [ ] Implement language auto-detection |
| 205 | +- [ ] Add remove functionality with confirmation |
| 206 | +- [ ] Create AddFileButton component |
| 207 | +- [ ] Implement auto-scroll on add |
| 208 | +- [ ] Add keyboard shortcuts |
| 209 | +- [ ] Implement responsive design |
| 210 | +- [ ] Add accessibility features |
| 211 | +- [ ] Create unit tests |
| 212 | +- [ ] Add integration tests |
| 213 | +- [ ] Performance optimization |
| 214 | +- [ ] Documentation |
0 commit comments