overtype 1.2.6 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +228 -40
- package/dist/overtype-webcomponent.esm.js +4763 -0
- package/dist/overtype-webcomponent.esm.js.map +7 -0
- package/dist/overtype-webcomponent.js +4785 -0
- package/dist/overtype-webcomponent.js.map +7 -0
- package/dist/overtype-webcomponent.min.js +991 -0
- package/dist/overtype.cjs +684 -391
- package/dist/overtype.cjs.map +4 -4
- package/dist/overtype.d.ts +57 -14
- package/dist/overtype.esm.js +681 -390
- package/dist/overtype.esm.js.map +4 -4
- package/dist/overtype.js +681 -390
- package/dist/overtype.js.map +4 -4
- package/dist/overtype.min.js +157 -125
- package/package.json +18 -4
- package/src/link-tooltip.js +48 -73
- package/src/overtype-webcomponent.js +676 -0
- package/src/overtype.d.ts +57 -14
- package/src/overtype.js +186 -59
- package/src/parser.js +122 -19
- package/src/styles.js +92 -30
- package/src/toolbar-buttons.js +163 -0
- package/src/toolbar.js +194 -249
- package/diagram.png +0 -0
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# OverType
|
|
2
2
|
|
|
3
|
-
A lightweight markdown editor library with perfect WYSIWYG alignment using an invisible textarea overlay technique. Includes optional toolbar. ~
|
|
3
|
+
A lightweight markdown editor library with perfect WYSIWYG alignment using an invisible textarea overlay technique. Includes optional toolbar. ~91KB minified with all features.
|
|
4
4
|
|
|
5
5
|
## Live Examples
|
|
6
6
|
|
|
7
7
|
🎮 **Try it out**: [Interactive demos on overtype.dev](https://overtype.dev)
|
|
8
|
-
- [Basic Editor](https://overtype.dev/#basic-editor)
|
|
9
|
-
- [With Toolbar](https://overtype.dev/#toolbar)
|
|
10
|
-
- [Multiple Instances](https://overtype.dev
|
|
11
|
-
- [View Modes](https://overtype.dev
|
|
12
|
-
- [
|
|
13
|
-
- [All
|
|
8
|
+
- [Basic Editor](https://overtype.dev/#basic-editor) - Minimal setup with live preview
|
|
9
|
+
- [With Toolbar](https://overtype.dev/#toolbar) - Full formatting toolbar
|
|
10
|
+
- [Multiple Instances](https://overtype.dev/demo.html#multiple-instances) - Several editors on one page
|
|
11
|
+
- [View Modes](https://overtype.dev/demo.html#view-modes) - Preview synchronization
|
|
12
|
+
- [Themes](https://overtype.dev/demo.html#themes) - Light/dark theme switching
|
|
13
|
+
- [All Features](https://overtype.dev/demo.html#markdown-features) - Complete markdown showcase
|
|
14
14
|
|
|
15
15
|
## Features
|
|
16
16
|
|
|
@@ -19,7 +19,7 @@ A lightweight markdown editor library with perfect WYSIWYG alignment using an in
|
|
|
19
19
|
- ⌨️ **Keyboard shortcuts** - Common markdown shortcuts (Cmd/Ctrl+B for bold, etc.)
|
|
20
20
|
- 📱 **Mobile optimized** - Responsive design with mobile-specific styles
|
|
21
21
|
- 🔄 **DOM persistence aware** - Recovers from existing DOM (perfect for HyperClay and similar platforms)
|
|
22
|
-
- 🚀 **Lightweight** - ~
|
|
22
|
+
- 🚀 **Lightweight** - ~91KB minified
|
|
23
23
|
- 🎯 **Optional toolbar** - Clean, minimal toolbar with all essential formatting
|
|
24
24
|
- ✨ **Smart shortcuts** - Keyboard shortcuts with selection preservation
|
|
25
25
|
- 📝 **Smart list continuation** - GitHub-style automatic list continuation on Enter
|
|
@@ -35,7 +35,7 @@ We overlap an invisible textarea on top of styled output, giving the illusion of
|
|
|
35
35
|
|
|
36
36
|
| Feature | OverType | HyperMD | Milkdown | TUI Editor | EasyMDE |
|
|
37
37
|
|---------|----------|---------|----------|------------|---------|
|
|
38
|
-
| **Size** | ~
|
|
38
|
+
| **Size** | ~91KB | 364.02 KB | 344.51 KB | 560.99 KB | 323.69 KB |
|
|
39
39
|
| **Dependencies** | Bundled | CodeMirror | ProseMirror + plugins | Multiple libs | CodeMirror |
|
|
40
40
|
| **Setup** | Single file | Complex config | Build step required | Complex config | Moderate |
|
|
41
41
|
| **Approach** | Invisible textarea | ContentEditable | ContentEditable | ContentEditable | CodeMirror |
|
|
@@ -85,7 +85,7 @@ const [editor] = new OverType('#editor', {
|
|
|
85
85
|
editor.getValue();
|
|
86
86
|
editor.setValue('# New Content');
|
|
87
87
|
|
|
88
|
-
// Change theme
|
|
88
|
+
// Change theme for this instance
|
|
89
89
|
editor.setTheme('cave');
|
|
90
90
|
```
|
|
91
91
|
|
|
@@ -107,33 +107,88 @@ editor.setTheme('cave');
|
|
|
107
107
|
</script>
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
-
### Toolbar
|
|
110
|
+
### Toolbar
|
|
111
111
|
|
|
112
112
|
```javascript
|
|
113
|
-
// Enable
|
|
113
|
+
// Enable default toolbar with all formatting buttons
|
|
114
114
|
const [editor] = new OverType('#editor', {
|
|
115
|
-
toolbar: true,
|
|
116
|
-
value: '# Document\n\nSelect text and use the toolbar
|
|
115
|
+
toolbar: true,
|
|
116
|
+
value: '# Document\n\nSelect text and use the toolbar!'
|
|
117
117
|
});
|
|
118
118
|
|
|
119
|
-
//
|
|
120
|
-
// - Bold, Italic formatting
|
|
121
|
-
// - Heading levels (H1, H2, H3)
|
|
122
|
-
// - Links, inline code, code blocks
|
|
123
|
-
// - Bullet and numbered lists
|
|
124
|
-
// - View mode switcher (eye icon dropdown)
|
|
125
|
-
// - All with keyboard shortcuts!
|
|
126
|
-
|
|
127
|
-
// Three view modes available via toolbar dropdown:
|
|
128
|
-
// 1. Normal Edit - Default WYSIWYG markdown editing
|
|
129
|
-
// 2. Plain Textarea - Shows raw markdown without preview overlay
|
|
130
|
-
// 3. Preview Mode - Read-only rendered preview with clickable links
|
|
131
|
-
|
|
132
|
-
// Programmatically switch modes:
|
|
133
|
-
editor.showPlainTextarea(true); // Switch to plain textarea mode
|
|
134
|
-
editor.showPreviewMode(true); // Switch to preview mode
|
|
119
|
+
// Default toolbar: Bold, Italic, Code | Link | H1, H2, H3 | Lists, Tasks | Quote | View Mode
|
|
135
120
|
```
|
|
136
121
|
|
|
122
|
+
**Custom Toolbar (v2.0):**
|
|
123
|
+
|
|
124
|
+
```javascript
|
|
125
|
+
import OverType, { toolbarButtons } from 'overtype';
|
|
126
|
+
|
|
127
|
+
const [editor] = new OverType('#editor', {
|
|
128
|
+
toolbar: true,
|
|
129
|
+
toolbarButtons: [
|
|
130
|
+
toolbarButtons.bold,
|
|
131
|
+
toolbarButtons.italic,
|
|
132
|
+
toolbarButtons.separator,
|
|
133
|
+
{
|
|
134
|
+
name: 'save',
|
|
135
|
+
icon: '<svg>...</svg>',
|
|
136
|
+
title: 'Save',
|
|
137
|
+
action: ({ editor, getValue }) => {
|
|
138
|
+
localStorage.setItem('draft', getValue());
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Available: bold, italic, code, link, h1, h2, h3, bulletList,
|
|
145
|
+
// orderedList, taskList, quote, separator, viewMode
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
See [examples/custom-toolbar.html](examples/custom-toolbar.html) for complete examples.
|
|
149
|
+
|
|
150
|
+
### View Modes
|
|
151
|
+
|
|
152
|
+
Three modes available via toolbar dropdown or programmatically:
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
editor.showNormalEditMode(); // Default WYSIWYG editing
|
|
156
|
+
editor.showPlainTextarea(); // Raw markdown, no preview
|
|
157
|
+
editor.showPreviewMode(); // Read-only preview with clickable links
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Task Lists
|
|
161
|
+
|
|
162
|
+
GitHub-style checkboxes render in preview mode:
|
|
163
|
+
|
|
164
|
+
```javascript
|
|
165
|
+
const [editor] = new OverType('#editor', {
|
|
166
|
+
value: '- [ ] Todo\n- [x] Done',
|
|
167
|
+
toolbar: true // Use view mode dropdown to see checkboxes
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Edit mode: Shows `- [ ]` and `- [x]` syntax (preserves alignment)
|
|
171
|
+
// Preview mode: Renders actual checkbox inputs
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Syntax Highlighting
|
|
175
|
+
|
|
176
|
+
```javascript
|
|
177
|
+
import { codeToHtml } from 'shiki';
|
|
178
|
+
|
|
179
|
+
// Global highlighter (all instances)
|
|
180
|
+
OverType.setCodeHighlighter((code, lang) =>
|
|
181
|
+
codeToHtml(code, { lang, theme: 'nord' })
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
// Per-instance override
|
|
185
|
+
const [editor] = new OverType('#editor', {
|
|
186
|
+
codeHighlighter: (code, lang) => myHighlighter(code, lang)
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
See [docs/SYNTAX_HIGHLIGHTING.md](docs/SYNTAX_HIGHLIGHTING.md) for complete guide.
|
|
191
|
+
|
|
137
192
|
### Keyboard Shortcuts
|
|
138
193
|
|
|
139
194
|
The toolbar and keyboard shortcuts work together seamlessly:
|
|
@@ -300,6 +355,45 @@ function MarkdownEditor({ value, onChange }) {
|
|
|
300
355
|
}
|
|
301
356
|
```
|
|
302
357
|
|
|
358
|
+
### Standalone Parser
|
|
359
|
+
|
|
360
|
+
Import and use the markdown parser without the full editor for server-side rendering, static site generation, or browser extensions:
|
|
361
|
+
|
|
362
|
+
```javascript
|
|
363
|
+
// Import just the parser
|
|
364
|
+
import { MarkdownParser } from 'overtype/parser';
|
|
365
|
+
|
|
366
|
+
// Parse markdown to HTML
|
|
367
|
+
const html = MarkdownParser.parse('# Hello World\n\nThis is **bold** text.');
|
|
368
|
+
|
|
369
|
+
// Use in Node.js for SSR
|
|
370
|
+
app.get('/preview', (req, res) => {
|
|
371
|
+
const markdown = req.body.content;
|
|
372
|
+
const html = MarkdownParser.parse(markdown);
|
|
373
|
+
res.json({ html });
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
// Use in static site generator
|
|
377
|
+
const posts = markdownFiles.map(file => ({
|
|
378
|
+
content: MarkdownParser.parse(file.content),
|
|
379
|
+
metadata: file.metadata
|
|
380
|
+
}));
|
|
381
|
+
|
|
382
|
+
// Use in browser extension
|
|
383
|
+
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
384
|
+
if (request.markdown) {
|
|
385
|
+
const html = MarkdownParser.parse(request.markdown);
|
|
386
|
+
sendResponse({ html });
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
**Benefits:**
|
|
392
|
+
- No DOM dependencies required
|
|
393
|
+
- Smaller bundle when you only need parsing
|
|
394
|
+
- Same markdown rendering as the editor
|
|
395
|
+
- Perfect for headless/server-side use cases
|
|
396
|
+
|
|
303
397
|
## API
|
|
304
398
|
|
|
305
399
|
### Constructor
|
|
@@ -360,8 +454,14 @@ new OverType(target, options)
|
|
|
360
454
|
},
|
|
361
455
|
|
|
362
456
|
// Toolbar
|
|
363
|
-
toolbar: false, // Enable/disable toolbar
|
|
364
|
-
|
|
457
|
+
toolbar: false, // Enable/disable toolbar
|
|
458
|
+
toolbarButtons: [], // Custom button array (v2.0)
|
|
459
|
+
// Defaults to all built-in buttons when toolbar: true
|
|
460
|
+
|
|
461
|
+
// Syntax highlighting
|
|
462
|
+
codeHighlighter: null, // Function: (code, lang) => html
|
|
463
|
+
// Overrides global OverType.setCodeHighlighter()
|
|
464
|
+
|
|
365
465
|
// Smart lists
|
|
366
466
|
smartLists: true, // Enable GitHub-style list continuation on Enter
|
|
367
467
|
|
|
@@ -394,15 +494,18 @@ editor.getCleanHTML() // Alias for getRenderedHTML({ clean
|
|
|
394
494
|
// Get the current preview element's HTML
|
|
395
495
|
editor.getPreviewHTML() // Actual DOM content from preview layer
|
|
396
496
|
|
|
397
|
-
// Change theme
|
|
497
|
+
// Change theme (instance-specific, overrides global theme)
|
|
398
498
|
editor.setTheme('cave') // Built-in theme name
|
|
399
499
|
editor.setTheme(customThemeObject) // Custom theme
|
|
400
500
|
|
|
501
|
+
// Set code highlighter (instance-specific)
|
|
502
|
+
editor.setCodeHighlighter((code, lang) => highlightedHTML)
|
|
503
|
+
editor.setCodeHighlighter(null) // Disable for this instance
|
|
504
|
+
|
|
401
505
|
// View modes
|
|
402
|
-
editor.
|
|
403
|
-
editor.showPlainTextarea(
|
|
404
|
-
editor.showPreviewMode(
|
|
405
|
-
editor.showPreviewMode(false) // Switch back to normal mode
|
|
506
|
+
editor.showNormalEditMode() // Switch to normal edit mode (default)
|
|
507
|
+
editor.showPlainTextarea() // Switch to plain textarea mode
|
|
508
|
+
editor.showPreviewMode() // Switch to preview mode
|
|
406
509
|
|
|
407
510
|
// Focus/blur
|
|
408
511
|
editor.focus()
|
|
@@ -425,11 +528,17 @@ editor.destroy()
|
|
|
425
528
|
### Static Methods
|
|
426
529
|
|
|
427
530
|
```javascript
|
|
428
|
-
// Set global theme (affects all instances)
|
|
531
|
+
// Set global theme (affects all instances without instance themes)
|
|
429
532
|
OverType.setTheme('cave') // Built-in theme
|
|
430
533
|
OverType.setTheme(customTheme) // Custom theme object
|
|
431
534
|
OverType.setTheme('solar', { h1: '#custom' }) // Override specific colors
|
|
432
535
|
|
|
536
|
+
// Set global code highlighter (affects all instances without instance highlighter)
|
|
537
|
+
OverType.setCodeHighlighter((code, lang) => highlightedHTML)
|
|
538
|
+
OverType.setCodeHighlighter(null) // Disable global highlighting
|
|
539
|
+
|
|
540
|
+
// Note: Instance methods override global settings
|
|
541
|
+
|
|
433
542
|
// Initialize multiple editors (same as constructor)
|
|
434
543
|
OverType.init(target, options)
|
|
435
544
|
|
|
@@ -460,13 +569,73 @@ OverType.themes.cave
|
|
|
460
569
|
- **Headers** - `# H1`, `## H2`, `### H3`
|
|
461
570
|
- **Bold** - `**text**` or `__text__`
|
|
462
571
|
- **Italic** - `*text*` or `_text_`
|
|
572
|
+
- **Strikethrough** - `~~text~~` or `~text~` (GFM)
|
|
463
573
|
- **Code** - `` `inline code` ``
|
|
574
|
+
- **Code blocks** - ` ```language `
|
|
464
575
|
- **Links** - `[text](url)`
|
|
465
576
|
- **Lists** - `- item`, `* item`, `1. item`
|
|
577
|
+
- **Task lists** - `- [ ] todo`, `- [x] done` (GFM, renders in preview mode)
|
|
466
578
|
- **Blockquotes** - `> quote`
|
|
467
579
|
- **Horizontal rule** - `---`, `***`, or `___`
|
|
468
580
|
|
|
469
|
-
Note
|
|
581
|
+
**Note:** Syntax remains visible in edit mode (e.g., `**bold**` shows markers). Use preview mode for full rendering.
|
|
582
|
+
|
|
583
|
+
## Web Component
|
|
584
|
+
|
|
585
|
+
OverType provides a fully-featured native Web Component `<overtype-editor>` with Shadow DOM encapsulation and a declarative HTML API.
|
|
586
|
+
|
|
587
|
+
**Quick example:**
|
|
588
|
+
```html
|
|
589
|
+
<overtype-editor
|
|
590
|
+
value="# Hello OverType!"
|
|
591
|
+
theme="solar"
|
|
592
|
+
height="300px"
|
|
593
|
+
toolbar>
|
|
594
|
+
</overtype-editor>
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
📖 **[Complete Web Component Documentation](docs/WEB-COMPONENT.md)**
|
|
598
|
+
|
|
599
|
+
Features include:
|
|
600
|
+
- Complete style isolation with Shadow DOM
|
|
601
|
+
- 15 reactive HTML attributes
|
|
602
|
+
- Framework-agnostic (React, Vue, Angular)
|
|
603
|
+
- Built-in themes (Solar, Cave)
|
|
604
|
+
- Custom events API
|
|
605
|
+
- Zero configuration required
|
|
606
|
+
|
|
607
|
+
## Migration from v1.x
|
|
608
|
+
|
|
609
|
+
### Breaking Change: Toolbar API (v2.0)
|
|
610
|
+
|
|
611
|
+
**Old options removed:**
|
|
612
|
+
```javascript
|
|
613
|
+
// ❌ No longer supported
|
|
614
|
+
{
|
|
615
|
+
customToolbarButtons: [...],
|
|
616
|
+
hideButtons: [...],
|
|
617
|
+
buttonOrder: [...]
|
|
618
|
+
}
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
**New approach:**
|
|
622
|
+
```javascript
|
|
623
|
+
// ✅ v2.0: Single explicit array
|
|
624
|
+
import { toolbarButtons } from 'overtype';
|
|
625
|
+
|
|
626
|
+
{
|
|
627
|
+
toolbar: true,
|
|
628
|
+
toolbarButtons: [
|
|
629
|
+
toolbarButtons.bold,
|
|
630
|
+
toolbarButtons.italic,
|
|
631
|
+
{ name: 'custom', icon: '...', action: ({ editor, getValue }) => {} }
|
|
632
|
+
]
|
|
633
|
+
}
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
**If using default toolbar** (`toolbar: true` with no customization), no changes needed.
|
|
637
|
+
|
|
638
|
+
See [examples/custom-toolbar.html](examples/custom-toolbar.html) for migration examples.
|
|
470
639
|
|
|
471
640
|
## DOM Persistence & Re-initialization
|
|
472
641
|
|
|
@@ -490,6 +659,7 @@ Check the `examples` folder for complete examples:
|
|
|
490
659
|
- `basic.html` - Simple single editor
|
|
491
660
|
- `multiple.html` - Multiple independent editors
|
|
492
661
|
- `custom-theme.html` - Theme customization
|
|
662
|
+
- `custom-toolbar.html` - Custom toolbar buttons (v2.0)
|
|
493
663
|
- `dynamic.html` - Dynamic creation/destruction
|
|
494
664
|
|
|
495
665
|
## Limitations
|
|
@@ -564,11 +734,29 @@ OverType uses a unique invisible textarea overlay approach:
|
|
|
564
734
|
## Contributors
|
|
565
735
|
|
|
566
736
|
Special thanks to:
|
|
737
|
+
|
|
738
|
+
### Core Features & Fixes
|
|
567
739
|
- [Josh Doman](https://github.com/joshdoman) - Fixed inline code formatting preservation ([#6](https://github.com/panphora/overtype/pull/6)), improved code fence detection ([#19](https://github.com/panphora/overtype/pull/19))
|
|
568
740
|
- [kbhomes](https://github.com/kbhomes) - Fixed text selection desynchronization during overscroll ([#17](https://github.com/panphora/overtype/pull/17))
|
|
741
|
+
- [Kristián Kostecký](https://github.com/kristiankostecky) - Fixed toolbar option being ignored in reinit() ([#62](https://github.com/panphora/overtype/pull/62))
|
|
742
|
+
- [Lyric Wai](https://github.com/lyricat) - Fixed double-escaping of links ([#64](https://github.com/panphora/overtype/pull/64)), reported code block alignment issues ([#65](https://github.com/panphora/overtype/issues/65))
|
|
743
|
+
|
|
744
|
+
### TypeScript & Framework Support
|
|
569
745
|
- [merlinz01](https://github.com/merlinz01) - Initial TypeScript definitions implementation ([#20](https://github.com/panphora/overtype/pull/20))
|
|
570
|
-
- [
|
|
746
|
+
- [ChasLui](https://github.com/ChasLui) - Web component implementation (under review) ([#40](https://github.com/panphora/overtype/pull/40))
|
|
747
|
+
|
|
748
|
+
### New Features & Enhancements
|
|
571
749
|
- [davidlazar](https://github.com/davidlazar) - Suggested view mode feature for toggling overlay and preview modes ([#24](https://github.com/panphora/overtype/issues/24))
|
|
750
|
+
- [Yukai Huang](https://github.com/Yukaii) - Syntax highlighting support (under review) ([#35](https://github.com/panphora/overtype/pull/35))
|
|
751
|
+
- [Rognoni](https://github.com/rognoni) - Suggested custom toolbar button API ([#61](https://github.com/panphora/overtype/issues/61))
|
|
752
|
+
- [Deyan Gigov](https://github.com/dido739) - Reported checkbox rendering issue in preview mode ([#60](https://github.com/panphora/overtype/issues/60))
|
|
753
|
+
|
|
754
|
+
### Developer Experience
|
|
755
|
+
- [Ned Twigg](https://github.com/nedtwigg) - Browser extension developer feedback, gitcasso extension ([#59](https://github.com/panphora/overtype/issues/59))
|
|
756
|
+
- [Victor](https://github.com/ViggieM) - Suggested exporting MarkdownParser for standalone use ([#58](https://github.com/panphora/overtype/issues/58))
|
|
757
|
+
- [Bernhard Weichel](https://github.com/bwl21) - Reported mode switching scroll sync bug ([#52](https://github.com/panphora/overtype/issues/52))
|
|
758
|
+
- [Colin Devroe](https://github.com/cdevroe) - Reported theme API confusion ([#54](https://github.com/panphora/overtype/issues/54))
|
|
759
|
+
- [Max Bernstein](https://github.com/tekknolagi) - Fixed typo in website ([#11](https://github.com/panphora/overtype/pull/11))
|
|
572
760
|
|
|
573
761
|
## License
|
|
574
762
|
|