@@ -70,7 +70,7 @@ Build outputs to `docs/` directory (configured for GitHub Pages deployment).
7070
7171```
7272src/
73- ├── stores/ # Svelte stores (projectStore, modalStore, undoStore, libraryStore)
73+ ├── stores/ # Svelte stores (projectStore, modalStore, undoStore, toastStore, libraryStore)
7474├── types/ # Zod schemas, TypeScript types, and type guards
7575│ ├── typeGuards.ts # Type guard functions (isCircle, isRectangle, isLeg)
7676│ └── panels/ # Panel-specific type definitions
@@ -392,6 +392,101 @@ Each element type (circle, rectangle, leg) has its own context menu generator:
392392- Positioned to the right of element using ` getClientRect() ` to avoid overlap
393393- Content generated by ` getSelectedElementInfo() ` in ` fineMovement.ts `
394394
395+ ## State Management
396+
397+ ### Undo System (` src/stores/undoStore.ts ` )
398+
399+ ** Architecture:**
400+
401+ - Stack-based LIFO (Last In First Out) design
402+ - Maximum 50 operations retained (oldest removed when exceeded)
403+ - Non-persistent (cleared on page refresh)
404+ - Automatically cleared on project reset to prevent cross-project contamination
405+
406+ ** Undoable Operations:**
407+
408+ - ** Element deletions** : Circles, rectangles, legs (individual or bulk)
409+ - ** Property modifications** :
410+ - Circle: radius, depth
411+ - Rectangle: width, height, depth, rotation
412+ - ** Keyboard shortcuts** :
413+ - Rectangle rotation (` R ` key): each 5° rotation creates undo entry
414+ - Rectangle dimension flip (` F ` key): swapping width/height
415+ - ** Optimization** : Only creates undo entry if values actually changed
416+
417+ ** Implementation Pattern:**
418+
419+ 1 . Capture previous state in closure before operation
420+ 2 . Perform the operation (delete, modify, rotate, flip)
421+ 3 . Add undo action to stack with descriptive name
422+ 4 . Undo action closure restores captured state when executed
423+
424+ ** Error Handling:**
425+
426+ - Failed undo operations show toast notification to user
427+ - Detailed console logging with operation name, error details, and stack trace
428+ - Failed operations re-added to stack to allow retry
429+
430+ ** Key Functions:**
431+
432+ - ` addUndo(name, action) ` : Adds undo entry with stack size enforcement
433+ - ` executeLastUndo() ` : Pops and executes last undo with error handling
434+ - ` clearUndoStack() ` : Clears entire stack (called on project reset)
435+ - ` undoStoreLastItem ` : Derived store providing operation name for UI
436+
437+ ** UI Integration:**
438+
439+ - Keyboard: ` Ctrl+Z ` / ` Cmd+Z ` (defined in ` AppNavigation.svelte ` )
440+ - Edit menu: Shows "Undo: {operation name}" when stack not empty
441+ - Disabled when modals are open (except ESC key)
442+
443+ ### Toast Notification System (` src/stores/toastStore.ts ` )
444+
445+ ** Architecture:**
446+
447+ - Array-based store of active toast messages
448+ - Auto-removal via setTimeout after configurable duration
449+ - Each toast has unique UUID for tracking and manual dismissal
450+ - Type-safe toast types: ` success ` , ` error ` , ` warning ` , ` info `
451+
452+ ** Toast Types and Colors:**
453+
454+ - ` success ` : Green with check-circle icon
455+ - ` error ` : Red with alert-circle icon (default 5s duration)
456+ - ` warning ` : Orange with alert icon
457+ - ` info ` : Blue with information icon
458+
459+ ** Key Functions:**
460+
461+ - ` toastStore.push(type, message, duration) ` : Add new toast
462+ - ` toastStore.error(message, duration) ` : Convenience method for error toasts
463+ - ` toastStore.remove(id) ` : Manually remove toast by UUID
464+
465+ ** UI Integration:**
466+
467+ - ` ToastContainer.svelte ` component subscribes to store
468+ - Fixed position: bottom-right corner with z-50
469+ - Vertical stacking with 2-unit gap spacing
470+ - Uses Flowbite Svelte ` Toast ` component with Iconify icons
471+ - Dismissable by user click on X button
472+
473+ ** Usage Example:**
474+
475+ ``` typescript
476+ import { toastStore } from ' $stores/toastStore' ;
477+
478+ // Show error toast
479+ toastStore .error (' Failed to undo: Delete circle' , 5000 );
480+
481+ // Show custom toast
482+ toastStore .push (' success' , ' Operation completed' , 3000 );
483+ ```
484+
485+ ** Current Usage:**
486+
487+ - Undo error notifications in ` undoStore.ts `
488+ - Can be extended for success confirmations, warnings, etc.
489+
395490## Testing Workflow
396491
397492Manual testing only. Key test scenarios:
0 commit comments