overtype 2.3.10 → 2.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # OverType
2
2
 
3
- A lightweight markdown editor library with perfect WYSIWYG alignment using an invisible textarea overlay technique. Includes optional toolbar. ~111KB minified with all features.
3
+ A lightweight markdown editor library with perfect WYSIWYG alignment using an invisible textarea overlay technique. Includes optional toolbar. ~117KB minified with all features.
4
4
 
5
5
  ## Live Examples
6
6
 
@@ -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** - ~111KB minified
22
+ - 🚀 **Lightweight** - ~117KB 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** | ~111KB | 364.02 KB | 344.51 KB | 560.99 KB | 323.69 KB |
38
+ | **Size** | ~117KB | 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 |
@@ -62,14 +62,42 @@ We overlap an invisible textarea on top of styled output, giving the illusion of
62
62
 
63
63
  ## Installation
64
64
 
65
- ### NPM
65
+ ### NPM (bundlers: Vite, webpack, Rollup, etc.)
66
66
  ```bash
67
67
  npm install overtype
68
68
  ```
69
69
 
70
- ### CDN
70
+ ```javascript
71
+ import OverType from 'overtype';
72
+
73
+ const [editor] = new OverType('#editor', { value: '# Hello' });
74
+ ```
75
+
76
+ OverType is ESM-first and also ships a CommonJS build, so both styles work:
77
+
78
+ ```javascript
79
+ // ESM — default or named import
80
+ import OverType from 'overtype';
81
+ import { OverType } from 'overtype';
82
+
83
+ // CommonJS
84
+ const { OverType } = require('overtype');
85
+ ```
86
+
87
+ ### CDN: native ES module (no build step)
88
+ ```html
89
+ <script type="module">
90
+ import OverType from 'https://cdn.jsdelivr.net/npm/overtype@latest/dist/overtype.esm.js';
91
+ const [editor] = new OverType('#editor', { value: '# Hello' });
92
+ </script>
93
+ ```
94
+
95
+ ### CDN: global script tag (IIFE)
71
96
  ```html
72
97
  <script src="https://cdn.jsdelivr.net/npm/overtype@latest/dist/overtype.min.js"></script>
98
+ <script>
99
+ const [editor] = new OverType('#editor', { value: '# Hello' });
100
+ </script>
73
101
  ```
74
102
 
75
103
  ## Quick Start
@@ -145,6 +173,20 @@ const [editor] = new OverType('#editor', {
145
173
  // orderedList, taskList, quote, separator, viewMode
146
174
  ```
147
175
 
176
+ Custom buttons that behave like toggle buttons can provide `isActive`. When it returns `true` or `false`, OverType updates the button’s `active` class and `aria-pressed` state:
177
+
178
+ ```javascript
179
+ {
180
+ name: 'customToggle',
181
+ icon: '<svg>...</svg>',
182
+ title: 'Custom Toggle',
183
+ isActive: ({ editor, activeFormats }) => activeFormats.includes('bold'),
184
+ action: ({ editor }) => {
185
+ // Toggle your custom formatting
186
+ }
187
+ }
188
+ ```
189
+
148
190
  **Driving formatting from your own UI:**
149
191
 
150
192
  OverType re-exports the bundled `markdown-actions` library so you can build a fully custom toolbar (or any UI) without installing or bundling `markdown-actions` separately:
@@ -216,8 +258,12 @@ The toolbar and keyboard shortcuts work together seamlessly:
216
258
  - **Cmd/Ctrl + K** - Insert link
217
259
  - **Cmd/Ctrl + Shift + 7** - Numbered list
218
260
  - **Cmd/Ctrl + Shift + 8** - Bullet list
261
+ - **Cmd/Ctrl + ]** - Indent current line or selection
262
+ - **Cmd/Ctrl + [** - Outdent current line or selection
263
+ - **Tab / Shift+Tab** - Indent or outdent selected lines
219
264
 
220
- All shortcuts preserve text selection, allowing you to apply multiple formats quickly.
265
+ Collapsed **Tab** and **Shift+Tab** follow normal browser focus navigation so keyboard users can leave the editor.
266
+ Editing shortcuts preserve text selection, allowing you to apply multiple formats quickly.
221
267
 
222
268
  ### Multiple Editors
223
269
 
@@ -518,6 +564,9 @@ new OverType(target, options)
518
564
  // Spellcheck
519
565
  spellcheck: false, // Enable browser spellcheck (disabled by default)
520
566
 
567
+ // Link tooltip
568
+ transformLinkUrl: (url) => url, // Rewrite the URL shown/opened in the link tooltip (per instance)
569
+
521
570
  // Stats bar
522
571
  showStats: false, // Enable/disable stats bar
523
572
  statsFormatter: (stats) => { // Custom stats format
@@ -637,10 +686,14 @@ OverType.themes.cave
637
686
  |----------|--------|
638
687
  | Cmd/Ctrl + B | Toggle bold |
639
688
  | Cmd/Ctrl + I | Toggle italic |
640
- | Cmd/Ctrl + K | Wrap in code |
641
- | Cmd/Ctrl + Shift + K | Insert link |
689
+ | Cmd/Ctrl + K | Insert link |
642
690
  | Cmd/Ctrl + Shift + 7 | Toggle numbered list |
643
691
  | Cmd/Ctrl + Shift + 8 | Toggle bullet list |
692
+ | Cmd/Ctrl + ] | Indent current line or selection |
693
+ | Cmd/Ctrl + [ | Outdent current line or selection |
694
+ | Tab / Shift+Tab | Indent or outdent selected lines |
695
+
696
+ When no text is selected, Tab and Shift+Tab use normal browser focus navigation.
644
697
 
645
698
  ## Supported Markdown
646
699
 
@@ -761,6 +814,26 @@ Links are clickable with Cmd/Ctrl+Click only. Direct clicking would interfere wi
761
814
 
762
815
  These limitations are what enable OverType's core benefits: perfect native textarea behavior, tiny size, and zero complexity.
763
816
 
817
+ ## Transforming Link URLs
818
+
819
+ When your cursor is inside a `[text](url)`, OverType shows a tooltip to open the link. If you edit a document at a different path or domain than where it's published, relative URLs can point to the wrong place. Pass `transformLinkUrl` to rewrite the URL shown and opened by the tooltip, per instance. Your markdown text and the rendered preview are left untouched.
820
+
821
+ ```javascript
822
+ const urlPreviewRegExp = [[/^\//, '/preview/'], [/www\./, '']];
823
+
824
+ const [editor] = new OverType('#editor', {
825
+ transformLinkUrl: (url) => urlPreviewRegExp.reduce((value, re) => value.replace(...re), url)
826
+ });
827
+ ```
828
+
829
+ The transformed URL is passed through OverType's URL sanitizer before opening, so the tooltip can never open a dangerous scheme (`javascript:`, `data:`, and similar). If your function throws or returns a non-string, the original URL is used.
830
+
831
+ ## Recipes
832
+
833
+ OverType stays small by leaving optional features to the host app and exposing the public API needed to build them (`editor.textarea`, `onChange`, `getValue`/`setValue`).
834
+
835
+ - **[Autocomplete / mention popups](docs/AUTOCOMPLETE.md)** - GitHub-style `@mention` and `#issue` popups built entirely on the public API, no core changes.
836
+
764
837
  ## Development
765
838
 
766
839
  ```bash
@@ -825,9 +898,25 @@ Use `OverType.initFromData()` to configure multiple editors via HTML data attrib
825
898
 
826
899
  Uses kebab-case attributes that convert to camelCase options (e.g., `data-ot-show-stats` → `showStats`).
827
900
 
828
- **Supported:** `toolbar`, `theme`, `value`, `placeholder`, `autofocus`, `auto-resize`, `min-height`, `max-height`, `font-size`, `line-height`, `show-stats`, `smart-lists`, `show-active-line-raw`
901
+ ### Native textarea attributes (`required`, `name`, etc.)
902
+
903
+ Set `textareaProps` from HTML in two ways:
904
+
905
+ ```html
906
+ <!-- One attribute per prop: data-ot-textarea-<attr> -->
907
+ <div class="editor" data-ot-textarea-required data-ot-textarea-name="message"></div>
908
+
909
+ <!-- Or the whole object as JSON -->
910
+ <div class="editor" data-ot-textarea-props='{"required":true,"maxLength":500,"name":"message"}'></div>
911
+ ```
912
+
913
+ Both put a real `required`/`name`/etc. attribute on the underlying `<textarea>`, so the editor participates in native form validation. To make a field optional, omit the attribute (don't set `data-ot-textarea-required="false"`, which still marks it required, the same way the HTML `required` attribute works).
914
+
915
+ Any object-valued option can also be passed as JSON (values starting with `{` or `[` are parsed; malformed JSON falls back to the raw string).
916
+
917
+ **Supported:** `toolbar`, `theme`, `value`, `placeholder`, `autofocus`, `auto-resize`, `min-height`, `max-height`, `font-size`, `line-height`, `show-stats`, `smart-lists`, `show-active-line-raw`, `textarea-props` / `textarea-*`
829
918
 
830
- **Not supported (use JS):** `toolbarButtons`, `textareaProps`, `onChange`, `onKeydown`, `onFocus`, `onBlur`, `statsFormatter`, `codeHighlighter`, `colors`, `mobile`
919
+ **Not supported (use JS):** `toolbarButtons`, `onChange`, `onKeydown`, `onFocus`, `onBlur`, `statsFormatter`, `codeHighlighter`, `colors`, `mobile`
831
920
 
832
921
  ## Contributors
833
922
 
@@ -853,6 +942,9 @@ Special thanks to:
853
942
  - [phinnaeus](https://github.com/phinnaeus) - Diagnosed missing fontFamily wiring ([#110](https://github.com/panphora/overtype/issues/110))
854
943
  - [Tan Nhu](https://github.com/tnhu) - Fixed onChange feedback loop with async syntax highlighters ([#111](https://github.com/panphora/overtype/pull/111))
855
944
  - [pscanf](https://github.com/pscanf) - Re-exported markdown-actions for custom toolbar implementations ([#105](https://github.com/panphora/overtype/issues/105), [#106](https://github.com/panphora/overtype/pull/106))
945
+ - [riasvdv](https://github.com/riasvdv) - Contributed keyboard focus-trap fix ([#115](https://github.com/panphora/overtype/pull/115)) and toolbar accessibility following the W3C APG Toolbar pattern ([#114](https://github.com/panphora/overtype/pull/114))
946
+ - [gcamacho079](https://github.com/gcamacho079) - Reported the markdown editor keyboard focus trap ([#113](https://github.com/panphora/overtype/issues/113))
947
+ - [Matt Round](https://mattround.com/) - Reported the Safari stale-glyph caret/wrap desync and supplied the original workaround ([#116](https://github.com/panphora/overtype/issues/116))
856
948
 
857
949
  ### TypeScript & Framework Support
858
950
  - [merlinz01](https://github.com/merlinz01) - Contributed TypeScript declaration file ([#20](https://github.com/panphora/overtype/pull/20))
@@ -864,7 +956,7 @@ Special thanks to:
864
956
  - [Yukai Huang](https://github.com/Yukaii) - Contributed syntax highlighting implementation ([#35](https://github.com/panphora/overtype/pull/35))
865
957
  - [Rognoni](https://github.com/rognoni) - Suggested custom toolbar button API ([#61](https://github.com/panphora/overtype/issues/61))
866
958
  - [Deyan Gigov](https://github.com/dido739) - Reported checkbox rendering bug in preview mode ([#60](https://github.com/panphora/overtype/issues/60)), contributed auto theme implementation ([#100](https://github.com/panphora/overtype/pull/100))
867
- - [GregJohnStewart](https://github.com/GregJohnStewart) - Suggested data attribute configuration ([#76](https://github.com/panphora/overtype/issues/76)), reported initFromData array nesting bug ([#93](https://github.com/panphora/overtype/issues/93)), suggested DOM element init ([#92](https://github.com/panphora/overtype/issues/92))
959
+ - [GregJohnStewart](https://github.com/GregJohnStewart) - Suggested data attribute configuration ([#76](https://github.com/panphora/overtype/issues/76)), reported initFromData array nesting bug ([#93](https://github.com/panphora/overtype/issues/93)), suggested DOM element init ([#92](https://github.com/panphora/overtype/issues/92)), suggested supporting more options via data attributes ([#112](https://github.com/panphora/overtype/issues/112))
868
960
  - [boris-glumpler](https://github.com/boris-glumpler) - Suggested custom syntax highlighting API ([#79](https://github.com/panphora/overtype/issues/79))
869
961
  - [sorokya](https://github.com/sorokya) - Contributed file upload support ([#87](https://github.com/panphora/overtype/pull/87))
870
962
  - [aaronmyatt](https://github.com/aaronmyatt) - Contributed show/hide toolbar methods ([#95](https://github.com/panphora/overtype/pull/95))