editor-structure
v1.26.0
Published
A professional, **configuration-driven**, **vanilla JavaScript** WYSIWYG Rich Text Editor built with modern frontend standards. Fully reusable as an NPM package with a complete demo application.
Maintainers
Readme
RTE Project - Complete Implementation Summary
📋 Overview
A professional, 90% configurable, vanilla JavaScript WYSIWYG Rich Text Editor built with modern frontend standards. Fully reusable as an NPM package with a complete demo application.
🆕 What's New in v2.0
- 90% Configurable - Centralized configuration in
config/defaults.js - DEFAULT_TOOLBAR - Pre-built 40+ tool toolbar with Font Awesome icons
- Icon Support in Dropdowns - Visual icons in select elements (bullets, numbers, paste modes)
- Paste Dropdown - 3 paste modes (Default, From Word, Plain Text)
- Theme System - Complete theming with
DEFAULT_THEME - i18n Ready - 80+ localization keys in
DEFAULT_I18N - Feature Toggles - Enable/disable features via
DEFAULT_FEATURES - Logo Integration - Professional branding in homepage
- Updated Documentation - Comprehensive guides and migration path
📁 Project Structure
RTE Package (rte-package/)
The standalone, reusable component library:
rte-package/
├── src/
│ ├── index.js # Main entry point (exports RTE class)
│ ├── editor.js # Core RTE class with full features
│ ├── toolbar.js # Dynamic toolbar builder
│ ├── config/
│ │ └── defaults.js # 90% configurable defaults (toolbar, theme, i18n, features)
│ ├── components/
│ │ └── builder.js # UI component builders
│ ├── commands/
│ │ └── handler.js # Command execution & history
│ ├── state/
│ │ └── manager.js # Real-time state tracking
│ ├── utils/
│ │ └── sanitizer.js # HTML sanitization
│ └── styles/
│ ├── main.css # Core editor styling
│ └── components.css # Component states (BEM)
└── package.jsonDemo Application (rte-demo/)
Proves the package's reusability and configurability:
rte-demo/
├── homepage.html # Marketing homepage with logo
├── docs.html # Complete documentation page
├── playground.html # Interactive testing ground
├── main.js # Demo configuration using DEFAULT_TOOLBAR
├── assets/
│ └── logo.svg # Nalashaa RTE logo
└── package.json # Installs rte-package as dependencyDocumentation
├── CONFIGURATION_GUIDE.md # 90% configurable system guide
├── MIGRATION_GUIDE.md # Upgrade to config/defaults.js
├── CONFIGURATION_EXAMPLES.js # Pre-built toolbar configs
├── COMPONENT_DOCUMENTATION.md # Detailed component architecture
├── INTEGRATION_GUIDE.md # How to use the package
├── STATE_MANAGEMENT_GUIDE.md # Button states & ARIA
└── README.md # This file🎯 90% Configurable Architecture
The editor is now 90% configurable through centralized defaults in config/defaults.js:
Default Configurations Available
DEFAULT_TOOLBAR - 9 toolbar groups with 40+ tools
- Clipboard (undo, redo, cut, copy, paste dropdown)
- Formatting (bold, italic, underline, strikethrough, etc.)
- Paragraph (headings, lists, quotes, alignment)
- Insert (links, images, tables, media)
- Typography (fonts, sizes, colors, line height)
- Advanced (code, fullscreen, source view)
DEFAULT_THEME - Complete theming system
- Colors (primary, background, borders, text)
- Fonts (family, sizes, weights)
- Spacing (padding, margins, borders)
DEFAULT_I18N - Internationalization (80+ keys)
- All UI labels and messages
- Error messages and tooltips
- Command descriptions
DEFAULT_FEATURES - Feature toggles
- Enable/disable undo, spellcheck, autocorrect
- Image resize, drag & drop
- Accessibility features
DEFAULT_EDITOR_OPTIONS - Editor behavior
- Placeholder text, read-only mode
- Content sanitization, autosave
Usage
import RTE from 'rte-package';
import { DEFAULT_TOOLBAR, DEFAULT_THEME } from 'rte-package/src/config/defaults.js';
// Use all defaults - instant setup!
const editor = new RTE('container');
// Use DEFAULT_TOOLBAR with filtering
const minimalEditor = new RTE('container', {
toolbar: DEFAULT_TOOLBAR.filter(g => ['formatting', 'paragraph'].includes(g.group))
});
// Customize theme
const themedEditor = new RTE('container', {
toolbar: DEFAULT_TOOLBAR,
theme: {
...DEFAULT_THEME,
colors: {
...DEFAULT_THEME.colors,
primary: '#ff6b6b'
}
}
});✨ Features Implemented
1. ✅ Clipboard & History Actions
- Undo/Redo - Full history with 50-entry stack (with lock mechanism to prevent rapid clicks)
- Cut/Copy - Native browser operations
- Paste Dropdown - Select from 3 paste modes:
- Default - Standard paste with formatting
- From Word - Automatically detects and preserves MS Word formatting
- Plain Text - Removes all formatting
- Smart Word Detection - Automatically identifies Word content by
mso-classes and XML namespaces - Paste Cleanup - Configurable filtering for other content sources
2. ✅ Text Formatting & Styling
- Basic Styles - Bold, Italic, Underline, Strikethrough
- Scripts & Case - Superscript, Subscript, UPPERCASE, lowercase, Sentence Case
- Code Styling - Inline code with monospace font
- Clear Formatting - Remove all applied styles with one click
3. ✅ Paragraph & Layout Controls
- Structure Dropdown - Paragraph, H1-H6 headings
- Lists - Bulleted and numbered lists
- Alignment - Left, Center, Right, Justified
- Indentation - Increase/decrease indent
- Block Quote - Dedicated quote styling
- Horizontal Rule - Visual separator
4. ✅ Advanced Insert Options
- Media - Images, Audio, Video (all with controls)
- Links - Hyperlink insertion with custom text
- Tables - Create tables with custom rows/cols
- Extras - Emoji, Special characters, Code blocks
5. ✅ Font & Color Customization
- Typography - Font family dropdown (Arial, Georgia, etc.)
- Font Size - 4-level size selector
- Color Pickers - Text color & background highlight
- Line Height - 5 preset spacing options
6. ✅ Code & Workspace Views
- Source Code - Toggle raw HTML editing with sanitization
- Code Block - Pre-formatted code containers
- Fullscreen - Expand editor to full browser window
7. ✅ Interactive Features & UX
- Keyboard Shortcuts - Ctrl+B/I/U/Z/Y built-in
- Tooltips - Descriptive text on hover (ARIA labels)
- Visual States - Hover, Focus, Active, Disabled clearly distinguished
- WYSIWYG Feedback - Instant visual application of formatting
🎨 Component System
Button Component
createButton({
label: 'Bold',
icon: '<i class="fas fa-bold"></i>', // Font Awesome icons supported
command: 'bold',
onclick: handler
})States:
inactive- Transparent (default)hover- Light gray backgroundfocus- Blue outline (keyboard nav)active- Primary blue with white textdisabled- Reduced opacity, not-allowed cursor
Select Dropdown Component
createSelect({
label: 'Heading',
command: 'formatBlock',
icon: '<i class="fas fa-heading"></i>', // Icons now supported in dropdowns
options: [
{ label: 'Paragraph', value: 'p' },
{ label: 'Heading 1', value: 'h1' },
{ label: 'Heading 2', value: 'h2' }
]
})Color Picker Component
createColorPicker({
label: 'Text Color',
command: 'foreColor',
value: '#000000'
})Range Slider Component
createRangeSlider({
label: 'Line Height',
command: 'lineHeight',
min: '0.8',
max: '2.0'
})� Advanced Paste Cleanup
Intelligent Word Detection
Automatically preserves Word formatting when content is copied from Microsoft Word:
// Content from Word automatically keeps ALL formatting
pasteCleanup: {
formatOption: 'cleanFormat' // Word content bypasses all filtering
}Word Detection markers:
mso-CSS classes and stylesw:ando:XML namespaces- Conditional comments
[if...][endif] - Microsoft Office schemas
- Word-specific XML tags
Word content gets:
- ✅ Headings preserved as headings
- ✅ Alignment maintained (left, center, right, justify)
- ✅ Indentation and margins kept
- ✅ Font sizes and families preserved
- ✅ Line spacing and gaps maintained
- ✅ Lists and bullets preserved
- ✅ Tables and table formatting kept
- ✅ Colors and styling preserved
Configurable Content Filtering
For non-Word content, apply advanced filtering:
pasteCleanup: {
formatOption: 'cleanFormat', // 'prompt', 'plainText', 'keepFormat', 'cleanFormat'
deniedTags: ['script', 'style'], // Remove unwanted tags
deniedAttributes: ['id', 'title'], // Remove problematic attributes
allowedStyleProperties: ['color', 'margin', 'font-size'] // Keep only safe styles
}Advanced Tag Patterns
Use attribute-based filtering:
deniedTags: [
'a[!href]', // Remove links without href
'a[href, target]' // Remove links with both href and target
]�🔧 Architecture & Design Patterns
Configuration-Driven
Everything is controlled via config objects - no hardcoded content:
const editor = new RTE('container', {
toolbar: [
{
group: 'formatting',
items: [
{ type: 'button', label: 'Bold', command: 'bold', icon: 'B' }
]
}
]
});Command Handler
Centralized command processing with history management:
- Executes 50+ commands
- Tracks history for undo/redo
- Sanitizes all input
- Handles complex operations (links, tables, media)
State Manager
Real-time button state tracking:
- Monitors active formatting
- Updates ARIA attributes
- Toggles CSS classes
- Tracks disabled states
ES6 Modules
Prevents global scope pollution:
import { RTE } from './editor.js';
import { CommandHandler } from './commands/handler.js';BEM CSS Methodology
Predictable, maintainable styling:
.rte__btn { } /* Block */
.rte__btn--active { } /* Modifier */
.rte__toolbar-group { } /* Element */♿ Accessibility (WCAG AA Compliant)
✅ Semantic HTML
<header>for toolbar<main>for content area
✅ ARIA Support
aria-labelon all controlsaria-pressedfor toggle statearia-multiline="true"on editoraria-modalon dialogs
✅ Keyboard Navigation
- Tab through all controls
- Ctrl+B/I/U/Z/Y shortcuts
- Focus-visible states
- Escape to close dialogs
✅ Color Contrast
- 4.5:1 minimum ratio
- Clear state distinctions
🎯 All 50+ Commands
Clipboard (6)
undo, redo, cut, copy, paste, pasteAsPlainText
Formatting (8)
bold, italic, underline, strikeThrough, superscript, subscript, code, clearFormatting
Text Case (3)
uppercase, lowercase, sentenceCase
Paragraph (9)
formatBlock, insertUnorderedList, insertOrderedList, alignLeft, alignCenter, alignRight, alignJustify, indent, outdent, insertBlockquote, insertHorizontalRule
Insert (8)
createLink, insertImage, insertAudio, insertVideo, insertTable, insertCodeBlock, insertEmoji, insertSpecialChar
Typography (5)
fontName, fontSize, lineHeight, foreColor, backColor
View (2)
toggleSource, toggleFullscreen
🚀 Performance
✅ Load Time - Under 2 seconds ✅ Vanilla JS - No framework dependencies ✅ Bundle Size - ~30KB minified ✅ History Management - Limited to 50 entries ✅ Smart Sanitization - Real-time without heavy libraries
📊 Browser Support
| Browser | Version | Status | |---------|---------|--------| | Chrome/Edge | Latest | ✅ | | Firefox | Latest | ✅ | | Safari | Latest | ✅ | | Mobile | Latest | ✅ |
🔐 Security
- HTML sanitization removes
<script>tags on*event attributes stripped- Safe iframe/media handling
- XSS protection built-in
📚 Documentation Files
COMPONENT_DOCUMENTATION.md
- Component architecture
- State management details
- CSS BEM methodology
- Accessibility features
INTEGRATION_GUIDE.md
- Quick start guide
- API reference
- Configuration options
- Code examples
- Troubleshooting
CONFIGURATION_EXAMPLES.js
- Pre-built configs:
- Minimal (comments)
- Content Creator (blogs)
- Professional (docs)
- Full-featured (all tools)
- Technical (documentation)
- Pre-built configs:
STATE_MANAGEMENT_GUIDE.md
- Button state matrix
- ARIA attributes
- Real-time updates
- Testing examples
🚀 Getting Started
Installation
# Install from local package
npm install ../rte-package
# Install Font Awesome for icons (if using DEFAULT_TOOLBAR)
npm install @fortawesome/fontawesome-freeInclude Font Awesome
<!-- Via CDN -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">Basic Usage (Recommended)
import RTE from 'rte-package';
import { DEFAULT_TOOLBAR } from 'rte-package/src/config/defaults.js';
// Use defaults - instant full-featured editor!
const editor = new RTE('editor-container', {
toolbar: DEFAULT_TOOLBAR
});
// Or filter to specific groups
const minimalEditor = new RTE('editor-container', {
toolbar: DEFAULT_TOOLBAR.filter(g => ['formatting', 'paragraph'].includes(g.group))
});
// Get content
const html = editor.getContent();
// Set content
editor.setContent('<h1>Hello</h1>');
// Save
document.getElementById('save').onclick = () => {
saveToDatabase(editor.getContent());
};With Custom Toolbar (Advanced)
const editor = new RTE('editor', {
toolbar: [
{
group: 'formatting',
items: [
{ type: 'button', label: 'Bold', command: 'bold', icon: '<i class="fas fa-bold"></i>' }
]
}
]
});🎓 Technical Standards (v2.0)
HTML & Accessibility ✅
- Semantic structure with
<header>and<main> - Every image has
altattribute - ARIA labels on all interactive elements
CSS & Styling ✅
- BEM methodology throughout
- CSS variables for theming
- Mobile-first responsive design
- Relative units (rem, em)
JavaScript (ES6+) ✅
- Only
constandlet(novar) - ES6 modules prevent global scope pollution
- Arrow functions for callbacks
- Async/await for media loading
- DRY principle with focused functions
Built with vanilla JavaScript, no frameworks, 100% configuration-driven, fully accessible & secure.
For detailed information, refer to the individual documentation files.
