Commit Graph

3 Commits

Author SHA1 Message Date
Shawn Anderson de07dabb36 feat: implement undo/redo functionality with keyboard shortcuts
Implemented a clean, working undo/redo system using useRef to avoid React state management issues.

## Features Added
- **Undo**: Ctrl+Z (Cmd+Z on Mac) to undo the last action
- **Redo**: Ctrl+Shift+Z (Cmd+Shift+Z on Mac) to redo
- **Delete**: Delete key to remove selected shape
- **Escape**: Escape key to deselect
- UI buttons for undo/redo with proper enabled/disabled states

## Technical Implementation
- Uses `useRef` instead of `useState` for history to avoid stale closures
- Deep clones shapes when saving to prevent reference issues
- Maintains up to 50 history states (auto-prunes oldest)
- Properly initializes history with current canvas state on mount
- Uses `e.code === 'KeyZ'` for keyboard detection (shift-independent)
- Includes propagator cleanup when deleting arrows via Delete key

## Key Design Decisions
- **useRef over useState**: Avoids complex state synchronization and stale closure bugs
- **Deep cloning**: JSON.parse(JSON.stringify()) ensures each history entry is independent
- **Initialization guard**: Prevents saving to history before component fully initializes
- **Force re-render**: Uses dummy state update to refresh button disabled states

## Architecture
```typescript
historyRef.current = [state0, state1, state2, ...]
historyIndexRef.current = currentIndex
```

Operations:
- saveToHistory(): Truncates future, adds new state, increments index
- undo(): Decrements index, restores previous state
- redo(): Increments index, restores next state

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 11:07:29 -08:00
Shawn Anderson 97a4eee6f0 feat: implement Phase 1 - live arrows with propagators
Major features:
- Functional arrows that propagate values between shapes
- Arrow drawing with snap-to-shape centers
- Arrow selection with visual highlighting (cyan, 4px)
- Propagator system (inline FolkJS-inspired implementation)
- Shape value editor and arrow expression editor
- Test Propagation button to trigger data flow

Critical bug fixes:
- EventTarget storage in separate Map to survive React state updates
- Stale closure fix using functional setState pattern
- Negative dimension normalization for rectangles
- Arrow hit detection using point-to-line distance algorithm
- Propagator cleanup on arrow deletion

Code quality improvements:
- Extracted isPointInShape() helper (removed ~30 lines duplication)
- Added HIT_TOLERANCE constant (no magic numbers)
- Removed debug logging after troubleshooting
- Proper resource cleanup (dispose propagators)

Documentation:
- Created CANVAS_DEVELOPMENT_GUIDE.md (comprehensive technical reference)
- Created SESSION_2025-11-07.md (session journal with lessons learned)
- Updated README.md (project overview with 6-phase roadmap)
- Updated CLAUDE.md (added Development Journal section)
- All docs moved to .claude/journal/

Technical discoveries documented:
1. React state immutability & EventTarget storage pattern
2. Stale closure pattern in event handlers
3. Negative dimensions bug in canvas drawing
4. Point-to-line distance algorithm for hit detection
5. Code organization best practices

Files modified:
- app/italism/page.tsx: 769 lines (+150 net)
- README.md: Complete rewrite with practical info
- package.json: TypeScript config updates
- tsconfig.json: Next.js auto-updates

Status: Phase 1 Complete 
Next: Phase 2 (expression parser, arrow auto-update, flow animation)

🤖 Generated with Claude Code (https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-07 17:00:39 -08:00
v0 ec0cf6a4ed Initialized repository for chat Post-Appitalism Website
Co-authored-by: Jeff Emmett <46964190+Jeff-Emmett@users.noreply.github.com>
2025-11-02 04:01:46 +00:00