This commit is contained in:
Tomáš Dvořák
2025-10-16 13:32:05 +02:00
commit 12cba639b9
663 changed files with 168914 additions and 0 deletions
+220
View File
@@ -0,0 +1,220 @@
# Custom Rich Text Editor Enhancement Summary
## Overview
Successfully removed **TinyMCE** from the entire application and replaced it with a fully custom, enhanced rich text editor built on **ReactQuill** with advanced image manipulation features.
## What Was Done
### ✅ 1. Created Enhanced Custom Editor (`CustomRichEditor.tsx`)
A new, feature-rich editor component with:
#### **Image Manipulation Features**
- **📸 Image Cropping**: Built-in crop modal with adjustable quality and max-width settings
- **↔️ Drag to Reposition**: Click and drag images left/right for alignment
- **🔧 Resize with Handles**: Blue circular handle at bottom-right corner for intuitive resizing
- **🗑️ Delete Images**: Select image and press Delete/Backspace to remove
- **✨ Visual Feedback**: Outline, shadow, and smooth transitions when selecting images
- **🎯 Professional Crop Tool**: Rectangle crop with percentage-based selection
#### **Editor Features**
- **Rich/HTML Toggle**: Switch between visual editor and raw HTML editing
- **Custom Toolbar Configurations**: Full, Basic, and Minimal toolbars
- **Sanitized Output**: DOMPurify integration for safe HTML
- **Upload Integration**: Seamless image upload with progress feedback
- **Responsive Design**: Mobile-friendly with adaptive controls
### ✅ 2. Enhanced Visual Styling (`custom-editor.css`)
Created comprehensive CSS enhancements:
#### **Professional Appearance**
- Gradient toolbar background
- Smooth hover effects and transitions
- Rounded corners and modern shadows
- Color-coded active states
- Professional typography hierarchy
#### **Image Styling**
- Rounded corners with subtle shadows
- Smooth hover animations
- Transform effects on interaction
- Pulsing resize handle animation
- High-quality image smoothing
#### **Dark Mode Support**
- Automatic dark mode detection
- Proper color schemes for both themes
- Readable contrast in all modes
#### **Enhanced Elements**
- Beautiful blockquotes with left border
- Code blocks with syntax highlighting colors
- Styled tables with alternating rows
- Custom link indicators
- Improved list formatting
### ✅ 3. Updated `RichTextEditor.tsx`
- **Removed**: All TinyMCE imports and configuration
- **Replaced**: With CustomRichEditor wrapper
- **Maintained**: Same API/props for backward compatibility
- **Enhanced**: URL transformation with assetUrl utility
### ✅ 4. Cleaned Dependencies (`package.json`)
Removed unused packages:
- `@tinymce/tinymce-react` - TinyMCE React wrapper
- `quill-image-resize-module-v2` - Old Quill resize module (replaced with custom)
## Where the Editor is Used
**The custom editor is now active on ALL admin pages:**
1. **📝 Articles/Blog Admin** (`ArticlesAdminPage.tsx`) - Blog/news creation with full editing
2. **️ About Admin** (`AboutAdminPage.tsx`) - About page content editing
3. **📅 Activities Admin** (`AdminActivitiesPage.tsx`) - Events and activities descriptions
4. **Any other page** importing `RichTextEditor` component
**Verified:** All pages have been confirmed to use the enhanced editor!
## How to Use the Enhanced Features
### Image Insertion
1. Click the **"Vložit obrázek"** (Insert Image) button
2. Select an image file
3. Adjust the crop area by dragging corners/edges
4. Set quality (recommended: 85%) and max width (default: 1500px)
5. Click **"Oříznout a vložit"** (Crop and Insert)
### Image Resizing
1. **Click on any image** in the editor to select it
2. A **blue circular handle** appears at bottom-right corner
3. **Drag the handle** to resize the image
4. Release to set the new size
### Image Positioning
1. **Click on an image** to select it
2. **Drag left or right** to change alignment
3. Drag **right**: Image aligns to the right
4. Drag **left**: Image aligns to the left
### Delete Images
1. **Click on an image** to select it
2. Press **Delete** or **Backspace** key
3. Image is removed instantly
### Editor Modes
- **Editor Mode**: Visual WYSIWYG editing with toolbar
- **HTML Mode**: Direct HTML code editing
## Technical Improvements
### Performance
- **Optimized image uploads**: Quality and size controls reduce file sizes
- **Lazy loading**: Images load progressively
- **Debounced updates**: Smooth editing experience
### User Experience
- **Visual feedback**: Outlines, shadows, and animations
- **Intuitive controls**: Drag-based interactions
- **Keyboard shortcuts**: Delete key for image removal
- **Tooltips**: Contextual help text
### Code Quality
- **TypeScript**: Full type safety
- **DOMPurify**: XSS protection
- **React best practices**: Hooks, refs, and lifecycle management
- **Clean separation**: Editor logic separated from business logic
## Styling Details
### Colors
- **Primary**: `#3182ce` (Blue)
- **Hover**: `rgba(66, 153, 225, 0.1)` (Light blue)
- **Active**: `#2c5aa0` (Dark blue)
- **Text**: `#2d3748` (Dark gray)
- **Muted**: `#a0aec0` (Gray)
### Animations
- **Resize handle pulse**: 2s infinite
- **Hover transforms**: 0.2s ease
- **Image hover**: Scale 1.01 with opacity change
## Browser Support
- ✅ Chrome/Edge (latest)
- ✅ Firefox (latest)
- ✅ Safari (latest)
- ✅ Mobile browsers (iOS Safari, Chrome Mobile)
## Migration Notes
### Breaking Changes
- **None** - The API remains the same
### What to Test
1. ✅ Image upload and cropping
2. ✅ Image resizing with handles
3. ✅ Image repositioning via drag
4. ✅ Image deletion with keyboard
5. ✅ Text formatting (bold, italic, lists, etc.)
6. ✅ Link insertion
7. ✅ HTML/Rich mode switching
8. ✅ Dark mode appearance
9. ✅ Mobile responsiveness
## Next Steps (Optional Enhancements)
If you want to add more features:
1. **Image Alignment Buttons**: Add left/center/right buttons in toolbar
2. **Image Alt Text**: Modal to set alt text for accessibility
3. **Drag & Drop Upload**: Drop images directly into editor
4. **Copy/Paste Images**: Paste from clipboard
5. **Image Gallery**: Browse previously uploaded images
6. **Undo/Redo**: History management for changes
7. **Auto-save**: Save drafts automatically
8. **Collaborative Editing**: Real-time multi-user editing
## Installation
After these changes, run:
```bash
cd frontend
npm install
```
This will remove the old TinyMCE packages and ensure all dependencies are up to date.
## Troubleshooting
### If images don't show resize handles:
- Check that `showImageResize` prop is `true` (default)
- Verify the custom CSS is loaded
- Check browser console for errors
### If crop modal doesn't appear:
- Ensure `onImageUpload` function is provided
- Check file input accepts image types
- Verify upload endpoint is working
### If styles look wrong:
- Clear browser cache
- Check that `custom-editor.css` is imported
- Verify Chakra UI theme is loaded
## Files Modified
1.`frontend/src/components/common/CustomRichEditor.tsx` (NEW)
2.`frontend/src/components/common/RichTextEditor.tsx` (REPLACED)
3.`frontend/src/styles/custom-editor.css` (NEW)
4.`frontend/package.json` (UPDATED - removed TinyMCE)
## Summary
You now have a **professional, feature-rich custom editor** that:
- ✨ Looks as good as TinyMCE (arguably better!)
- 🎯 Has advanced image manipulation (crop, resize, drag, delete)
- 🚀 Is fully customizable and maintainable
- 💪 Has no external dependencies on proprietary editors
- 🎨 Matches your app's design language
- 📱 Works great on mobile devices
**The editor is ready to use immediately!** All existing pages will automatically benefit from these enhancements.