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.
npm install editor-structureconfig/defaults.js
DEFAULT_THEME
DEFAULT_I18N
DEFAULT_FEATURES
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.json
`
$3
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 dependency
`
$3
`
āāā 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:
$3
1. 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)
2. DEFAULT_THEME - Complete theming system
- Colors (primary, background, borders, text)
- Fonts (family, sizes, weights)
- Spacing (padding, margins, borders)
3. DEFAULT_I18N - Internationalization (80+ keys)
- All UI labels and messages
- Error messages and tooltips
- Command descriptions
4. DEFAULT_FEATURES - Feature toggles
- Enable/disable undo, spellcheck, autocorrect
- Image resize, drag & drop
- Accessibility features
5. DEFAULT_EDITOR_OPTIONS - Editor behavior
- Placeholder text, read-only mode
- Content sanitization, autosave
$3
`javascript
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
$3
- 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
$3
- 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
- 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
$3
- 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
$3
- 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
$3
- Source Code - Toggle raw HTML editing with sanitization
- Code Block - Pre-formatted code containers
- Fullscreen - Expand editor to full browser window
$3
- 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
$3
`javascript
createButton({
label: 'Bold',
icon: '', // Font Awesome icons supported
command: 'bold',
onclick: handler
})
`
States:
- inactive - Transparent (default)
- hover - Light gray background
- focus - Blue outline (keyboard nav)
- active - Primary blue with white text
- disabled - Reduced opacity, not-allowed cursor
$3
`javascript
createSelect({
label: 'Heading',
command: 'formatBlock',
icon: '', // Icons now supported in dropdowns
options: [
{ label: 'Paragraph', value: 'p' },
{ label: 'Heading 1', value: 'h1' },
{ label: 'Heading 2', value: 'h2' }
]
})
`
$3
`javascript
createColorPicker({
label: 'Text Color',
command: 'foreColor',
value: '#000000'
})
`
$3
`javascript
createRangeSlider({
label: 'Line Height',
command: 'lineHeight',
min: '0.8',
max: '2.0'
})
`
---
ļæ½ Advanced Paste Cleanup
$3
Automatically preserves Word formatting when content is copied from Microsoft Word:
`javascript
// Content from Word automatically keeps ALL formatting
pasteCleanup: {
formatOption: 'cleanFormat' // Word content bypasses all filtering
}
`
Word Detection markers:
- mso- CSS classes and styles
- w: and o: 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
$3
For non-Word content, apply advanced filtering:
`javascript
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
}
`
$3
Use attribute-based filtering:
`javascript
deniedTags: [
'a[!href]', // Remove links without href
'a[href, target]' // Remove links with both href and target
]
`
---
ļæ½š§ Architecture & Design Patterns
$3
Everything is controlled via config objects - no hardcoded content:
`javascript
const editor = new RTE('container', {
toolbar: [
{
group: 'formatting',
items: [
{ type: 'button', label: 'Bold', command: 'bold', icon: 'B' }
]
}
]
});
`
$3
Centralized command processing with history management:
- Executes 50+ commands
- Tracks history for undo/redo
- Sanitizes all input
- Handles complex operations (links, tables, media)
$3
Real-time button state tracking:
- Monitors active formatting
- Updates ARIA attributes
- Toggles CSS classes
- Tracks disabled states
$3
Prevents global scope pollution:
`javascript
import { RTE } from './editor.js';
import { CommandHandler } from './commands/handler.js';
`
$3
Predictable, maintainable styling:
`css
.rte__btn { } / Block /
.rte__btn--active { } / Modifier /
.rte__toolbar-group { } / Element /
`
---
āæ Accessibility (WCAG AA Compliant)
ā
Semantic HTML
- for toolbar
- for content area
ā
ARIA Support
- aria-label on all controls
- aria-pressed for toggle state
- aria-multiline="true" on editor
- aria-modal on 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
$3
undo, redo, cut, copy, paste, pasteAsPlainText
$3
bold, italic, underline, strikeThrough, superscript, subscript, code, clearFormatting
$3
uppercase, lowercase, sentenceCase
$3
formatBlock, insertUnorderedList, insertOrderedList, alignLeft, alignCenter, alignRight, alignJustify, indent, outdent, insertBlockquote, insertHorizontalRule
$3
createLink, insertImage, insertAudio, insertVideo, insertTable, insertCodeBlock, insertEmoji, insertSpecialChar
$3
fontName, fontSize, lineHeight, foreColor, backColor
$3
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