overtype 2.3.7 → 2.3.9

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. ~117KB minified with all features.
3
+ A lightweight markdown editor library with perfect WYSIWYG alignment using an invisible textarea overlay technique. Includes optional toolbar. ~110KB 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** - ~117KB minified
22
+ - 🚀 **Lightweight** - ~110KB 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** | ~117KB | 364.02 KB | 344.51 KB | 560.99 KB | 323.69 KB |
38
+ | **Size** | ~110KB | 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 |
@@ -783,11 +783,12 @@ Special thanks to:
783
783
  - [ddarfantasy](https://github.com/ddarfantasy), [ThaUnknown](https://github.com/ThaUnknown) - Reported and debugged text misalignment caused by CSS framework font resets ([#91](https://github.com/panphora/overtype/issues/91))
784
784
  - [milen-yordanov](https://github.com/milen-yordanov) - Reported code block colors ignoring theme in preview mode ([#97](https://github.com/panphora/overtype/issues/97))
785
785
  - [asalimian](https://github.com/asalimian) - Reported spellcheck being disabled ([#98](https://github.com/panphora/overtype/issues/98))
786
- - [be5invis](https://github.com/be5invis) - Reported reinit() not propagating fontSize changes ([#108](https://github.com/panphora/overtype/issues/108))
786
+ - [be5invis](https://github.com/be5invis) - Reported reinit() not propagating fontSize changes ([#108](https://github.com/panphora/overtype/issues/108)), suggested focus/blur callbacks ([#107](https://github.com/panphora/overtype/issues/107))
787
787
  - [Danny Vink](https://github.com/dannyvink) - Fixed task list overlay alignment with spaced checkbox markers ([#109](https://github.com/panphora/overtype/pull/109))
788
788
  - [yurivish](https://github.com/yurivish) - Reported fontFamily option not being applied ([#110](https://github.com/panphora/overtype/issues/110))
789
789
  - [phinnaeus](https://github.com/phinnaeus) - Diagnosed missing fontFamily wiring ([#110](https://github.com/panphora/overtype/issues/110))
790
790
  - [Tan Nhu](https://github.com/tnhu) - Fixed onChange feedback loop with async syntax highlighters ([#111](https://github.com/panphora/overtype/pull/111))
791
+ - [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))
791
792
 
792
793
  ### TypeScript & Framework Support
793
794
  - [merlinz01](https://github.com/merlinz01) - Contributed TypeScript declaration file ([#20](https://github.com/panphora/overtype/pull/20))
@@ -1,5 +1,5 @@
1
1
  /**
2
- * OverType v2.3.7
2
+ * OverType v2.3.9
3
3
  * A lightweight markdown editor library with perfect WYSIWYG alignment
4
4
  * @license MIT
5
5
  * @author David Miranda
@@ -7,6 +7,10 @@
7
7
  */
8
8
  var __defProp = Object.defineProperty;
9
9
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
10
14
  var __publicField = (obj, key, value) => {
11
15
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
12
16
  return value;
@@ -1887,6 +1891,30 @@ function generateStyles(options = {}) {
1887
1891
  }
1888
1892
 
1889
1893
  // node_modules/markdown-actions/dist/markdown-actions.esm.js
1894
+ var markdown_actions_esm_exports = {};
1895
+ __export(markdown_actions_esm_exports, {
1896
+ applyCustomFormat: () => applyCustomFormat,
1897
+ default: () => src_default,
1898
+ expandSelection: () => expandSelection2,
1899
+ getActiveFormats: () => getActiveFormats2,
1900
+ getDebugMode: () => getDebugMode,
1901
+ hasFormat: () => hasFormat2,
1902
+ insertHeader: () => insertHeader,
1903
+ insertLink: () => insertLink,
1904
+ preserveSelection: () => preserveSelection,
1905
+ setDebugMode: () => setDebugMode,
1906
+ setUndoMethod: () => setUndoMethod,
1907
+ toggleBold: () => toggleBold,
1908
+ toggleBulletList: () => toggleBulletList,
1909
+ toggleCode: () => toggleCode,
1910
+ toggleH1: () => toggleH1,
1911
+ toggleH2: () => toggleH2,
1912
+ toggleH3: () => toggleH3,
1913
+ toggleItalic: () => toggleItalic,
1914
+ toggleNumberedList: () => toggleNumberedList,
1915
+ toggleQuote: () => toggleQuote,
1916
+ toggleTaskList: () => toggleTaskList
1917
+ });
1890
1918
  var __defProp2 = Object.defineProperty;
1891
1919
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1892
1920
  var __hasOwnProp = Object.prototype.hasOwnProperty;
@@ -1973,6 +2001,9 @@ function mergeWithDefaults(format) {
1973
2001
  return __spreadValues(__spreadValues({}, getDefaultStyle()), format);
1974
2002
  }
1975
2003
  var debugMode = false;
2004
+ function setDebugMode(enabled) {
2005
+ debugMode = enabled;
2006
+ }
1976
2007
  function getDebugMode() {
1977
2008
  return debugMode;
1978
2009
  }
@@ -2093,6 +2124,19 @@ function insertText(textarea, { text, selectionStart, selectionEnd }) {
2093
2124
  console.groupEnd();
2094
2125
  }
2095
2126
  }
2127
+ function setUndoMethod(method) {
2128
+ switch (method) {
2129
+ case "native":
2130
+ canInsertText = true;
2131
+ break;
2132
+ case "manual":
2133
+ canInsertText = false;
2134
+ break;
2135
+ case "auto":
2136
+ canInsertText = null;
2137
+ break;
2138
+ }
2139
+ }
2096
2140
  function isMultipleLines(string) {
2097
2141
  return string.trim().split("\n").length > 1;
2098
2142
  }
@@ -2162,6 +2206,15 @@ function newlinesToSurroundSelectedText(textarea) {
2162
2206
  }
2163
2207
  return { newlinesToAppend, newlinesToPrepend };
2164
2208
  }
2209
+ function preserveSelection(textarea, callback) {
2210
+ const start = textarea.selectionStart;
2211
+ const end = textarea.selectionEnd;
2212
+ const scrollTop = textarea.scrollTop;
2213
+ callback();
2214
+ textarea.selectionStart = start;
2215
+ textarea.selectionEnd = end;
2216
+ textarea.scrollTop = scrollTop;
2217
+ }
2165
2218
  function applyLineOperation(textarea, operation, options = {}) {
2166
2219
  const originalStart = textarea.selectionStart;
2167
2220
  const originalEnd = textarea.selectionEnd;
@@ -2535,6 +2588,43 @@ function getActiveFormats(textarea) {
2535
2588
  }
2536
2589
  return formats;
2537
2590
  }
2591
+ function hasFormat(textarea, format) {
2592
+ const activeFormats = getActiveFormats(textarea);
2593
+ return activeFormats.includes(format);
2594
+ }
2595
+ function expandSelection(textarea, options = {}) {
2596
+ if (!textarea)
2597
+ return;
2598
+ const { toWord, toLine, toFormat } = options;
2599
+ const { selectionStart, selectionEnd, value } = textarea;
2600
+ if (toLine) {
2601
+ const lines = value.split("\n");
2602
+ let lineStart = 0;
2603
+ let lineEnd = 0;
2604
+ let currentPos = 0;
2605
+ for (const line of lines) {
2606
+ if (selectionStart >= currentPos && selectionStart <= currentPos + line.length) {
2607
+ lineStart = currentPos;
2608
+ lineEnd = currentPos + line.length;
2609
+ break;
2610
+ }
2611
+ currentPos += line.length + 1;
2612
+ }
2613
+ textarea.selectionStart = lineStart;
2614
+ textarea.selectionEnd = lineEnd;
2615
+ } else if (toWord && selectionStart === selectionEnd) {
2616
+ let start = selectionStart;
2617
+ let end = selectionEnd;
2618
+ while (start > 0 && !/\s/.test(value[start - 1])) {
2619
+ start--;
2620
+ }
2621
+ while (end < value.length && !/\s/.test(value[end])) {
2622
+ end++;
2623
+ }
2624
+ textarea.selectionStart = start;
2625
+ textarea.selectionEnd = end;
2626
+ }
2627
+ }
2538
2628
  function toggleBold(textarea) {
2539
2629
  if (!textarea || textarea.disabled || textarea.readOnly)
2540
2630
  return;
@@ -2728,6 +2818,51 @@ function toggleH3(textarea) {
2728
2818
  function getActiveFormats2(textarea) {
2729
2819
  return getActiveFormats(textarea);
2730
2820
  }
2821
+ function hasFormat2(textarea, format) {
2822
+ return hasFormat(textarea, format);
2823
+ }
2824
+ function expandSelection2(textarea, options = {}) {
2825
+ expandSelection(textarea, options);
2826
+ }
2827
+ function applyCustomFormat(textarea, format) {
2828
+ if (!textarea || textarea.disabled || textarea.readOnly)
2829
+ return;
2830
+ const style = mergeWithDefaults(format);
2831
+ let result;
2832
+ if (style.multiline) {
2833
+ const selectedText = textarea.value.slice(textarea.selectionStart, textarea.selectionEnd);
2834
+ if (isMultipleLines(selectedText)) {
2835
+ result = multilineStyle(textarea, style);
2836
+ } else {
2837
+ result = blockStyle(textarea, style);
2838
+ }
2839
+ } else {
2840
+ result = blockStyle(textarea, style);
2841
+ }
2842
+ insertText(textarea, result);
2843
+ }
2844
+ var src_default = {
2845
+ toggleBold,
2846
+ toggleItalic,
2847
+ toggleCode,
2848
+ insertLink,
2849
+ toggleBulletList,
2850
+ toggleNumberedList,
2851
+ toggleQuote,
2852
+ toggleTaskList,
2853
+ insertHeader,
2854
+ toggleH1,
2855
+ toggleH2,
2856
+ toggleH3,
2857
+ getActiveFormats: getActiveFormats2,
2858
+ hasFormat: hasFormat2,
2859
+ expandSelection: expandSelection2,
2860
+ applyCustomFormat,
2861
+ preserveSelection,
2862
+ setUndoMethod,
2863
+ setDebugMode,
2864
+ getDebugMode
2865
+ };
2731
2866
 
2732
2867
  // src/toolbar.js
2733
2868
  var Toolbar = class {
@@ -4653,21 +4788,9 @@ var _OverType = class _OverType {
4653
4788
  * @returns {Array} Array of OverType instances
4654
4789
  */
4655
4790
  constructor(target, options = {}) {
4656
- let elements;
4657
- if (typeof target === "string") {
4658
- elements = document.querySelectorAll(target);
4659
- if (elements.length === 0) {
4660
- throw new Error(`No elements found for selector: ${target}`);
4661
- }
4662
- elements = Array.from(elements);
4663
- } else if (target instanceof Element) {
4664
- elements = [target];
4665
- } else if (target instanceof NodeList) {
4666
- elements = Array.from(target);
4667
- } else if (Array.isArray(target)) {
4668
- elements = target;
4669
- } else {
4670
- throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");
4791
+ const elements = _OverType._resolveTargets(target);
4792
+ if (typeof target === "string" && elements.length === 0) {
4793
+ throw new Error(`No elements found for selector: ${target}`);
4671
4794
  }
4672
4795
  const instances = elements.map((element) => {
4673
4796
  if (element.overTypeInstance) {
@@ -4753,6 +4876,8 @@ var _OverType = class _OverType {
4753
4876
  onChange: null,
4754
4877
  onKeydown: null,
4755
4878
  onRender: null,
4879
+ onFocus: null,
4880
+ onBlur: null,
4756
4881
  // Features
4757
4882
  showActiveLineRaw: false,
4758
4883
  showStats: false,
@@ -5203,6 +5328,24 @@ var _OverType = class _OverType {
5203
5328
  this.updatePreview();
5204
5329
  this._notifyChange();
5205
5330
  }
5331
+ /**
5332
+ * Handle focus events
5333
+ * @private
5334
+ */
5335
+ handleFocus(event) {
5336
+ if (this.options.onFocus) {
5337
+ this.options.onFocus(event, this);
5338
+ }
5339
+ }
5340
+ /**
5341
+ * Handle blur events
5342
+ * @private
5343
+ */
5344
+ handleBlur(event) {
5345
+ if (this.options.onBlur) {
5346
+ this.options.onBlur(event, this);
5347
+ }
5348
+ }
5206
5349
  /**
5207
5350
  * Handle keydown events
5208
5351
  * @private
@@ -5747,9 +5890,9 @@ var _OverType = class _OverType {
5747
5890
  * // HTML: <div class="editor" data-ot-toolbar="true" data-ot-theme="cave"></div>
5748
5891
  * OverType.initFromData('.editor', { fontSize: '14px' });
5749
5892
  */
5750
- static initFromData(selector, defaults = {}) {
5751
- const elements = document.querySelectorAll(selector);
5752
- return Array.from(elements).map((el) => {
5893
+ static initFromData(target, defaults = {}) {
5894
+ const elements = _OverType._resolveTargets(target);
5895
+ return elements.map((el) => {
5753
5896
  const options = { ...defaults };
5754
5897
  for (const attr of el.attributes) {
5755
5898
  if (attr.name.startsWith("data-ot-")) {
@@ -5761,6 +5904,33 @@ var _OverType = class _OverType {
5761
5904
  return new _OverType(el, options)[0];
5762
5905
  });
5763
5906
  }
5907
+ /**
5908
+ * Normalize various target shapes to an array of Elements
5909
+ * @private
5910
+ * @param {string|Element|NodeList|Element[]} target
5911
+ * @returns {Element[]}
5912
+ */
5913
+ static _resolveTargets(target) {
5914
+ if (target == null) {
5915
+ throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");
5916
+ }
5917
+ if (typeof target === "string") {
5918
+ return Array.from(document.querySelectorAll(target));
5919
+ }
5920
+ if (target instanceof Element) {
5921
+ return [target];
5922
+ }
5923
+ if (target instanceof NodeList) {
5924
+ return Array.from(target);
5925
+ }
5926
+ if (Array.isArray(target)) {
5927
+ return target;
5928
+ }
5929
+ if (typeof target.length === "number") {
5930
+ return Array.from(target);
5931
+ }
5932
+ throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");
5933
+ }
5764
5934
  /**
5765
5935
  * Parse a data attribute value to the appropriate type
5766
5936
  * @private
@@ -5777,11 +5947,22 @@ var _OverType = class _OverType {
5777
5947
  return value;
5778
5948
  }
5779
5949
  /**
5780
- * Get instance from element
5781
- * @param {Element} element - DOM element
5782
- * @returns {OverType|null} OverType instance or null
5950
+ * Get instance from a target. Accepts the same shapes as the constructor;
5951
+ * for multi-element targets, returns the instance for the first matching
5952
+ * element, or null if none.
5953
+ * @param {string|Element|NodeList|Element[]} target
5954
+ * @returns {OverType|null}
5783
5955
  */
5784
- static getInstance(element) {
5956
+ static getInstance(target) {
5957
+ let element;
5958
+ if (target instanceof Element) {
5959
+ element = target;
5960
+ } else {
5961
+ const elements = _OverType._resolveTargets(target);
5962
+ element = elements[0];
5963
+ }
5964
+ if (!element)
5965
+ return null;
5785
5966
  return element.overTypeInstance || _OverType.instances.get(element) || null;
5786
5967
  }
5787
5968
  /**
@@ -5959,6 +6140,22 @@ var _OverType = class _OverType {
5959
6140
  instance.handleKeydown(e);
5960
6141
  }
5961
6142
  });
6143
+ document.addEventListener("focus", (e) => {
6144
+ if (e.target && e.target.classList && e.target.classList.contains("overtype-input")) {
6145
+ const wrapper = e.target.closest(".overtype-wrapper");
6146
+ const instance = wrapper == null ? void 0 : wrapper._instance;
6147
+ if (instance)
6148
+ instance.handleFocus(e);
6149
+ }
6150
+ }, true);
6151
+ document.addEventListener("blur", (e) => {
6152
+ if (e.target && e.target.classList && e.target.classList.contains("overtype-input")) {
6153
+ const wrapper = e.target.closest(".overtype-wrapper");
6154
+ const instance = wrapper == null ? void 0 : wrapper._instance;
6155
+ if (instance)
6156
+ instance.handleBlur(e);
6157
+ }
6158
+ }, true);
5962
6159
  document.addEventListener("scroll", (e) => {
5963
6160
  if (e.target && e.target.classList && e.target.classList.contains("overtype-input")) {
5964
6161
  const wrapper = e.target.closest(".overtype-wrapper");