overtype 2.3.6 → 2.3.8

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/dist/overtype.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * OverType v2.3.6
2
+ * OverType v2.3.8
3
3
  * A lightweight markdown editor library with perfect WYSIWYG alignment
4
4
  * @license MIT
5
5
  * @author David Miranda
@@ -34,6 +34,7 @@ __export(overtype_exports, {
34
34
  OverType: () => OverType,
35
35
  default: () => overtype_default,
36
36
  defaultToolbarButtons: () => defaultToolbarButtons,
37
+ markdownActions: () => markdown_actions_esm_exports,
37
38
  toolbarButtons: () => toolbarButtons
38
39
  });
39
40
  module.exports = __toCommonJS(overtype_exports);
@@ -148,13 +149,13 @@ var MarkdownParser = class {
148
149
  * @returns {string} Parsed task list item
149
150
  */
150
151
  static parseTaskList(html, isPreviewMode = false) {
151
- return html.replace(/^((?: )*)-\s+\[([ xX])\]\s+(.+)$/, (match, indent, checked, content) => {
152
+ return html.replace(/^((?: )*)-(\s+)\[([ xX])\](\s*)(.*)$/, (match, indent, spacingBeforeBox, checked, spacingAfterBox, content) => {
152
153
  content = this.parseInlineElements(content);
153
154
  if (isPreviewMode) {
154
155
  const isChecked = checked.toLowerCase() === "x";
155
156
  return `${indent}<li class="task-list"><input type="checkbox" ${isChecked ? "checked" : ""}> ${content}</li>`;
156
157
  } else {
157
- return `${indent}<li class="task-list"><span class="syntax-marker">- [${checked}] </span>${content}</li>`;
158
+ return `${indent}<li class="task-list"><span class="syntax-marker">-${spacingBeforeBox}[${checked}]${spacingAfterBox}</span>${content}</li>`;
158
159
  }
159
160
  });
160
161
  }
@@ -1913,6 +1914,30 @@ function generateStyles(options = {}) {
1913
1914
  }
1914
1915
 
1915
1916
  // node_modules/markdown-actions/dist/markdown-actions.esm.js
1917
+ var markdown_actions_esm_exports = {};
1918
+ __export(markdown_actions_esm_exports, {
1919
+ applyCustomFormat: () => applyCustomFormat,
1920
+ default: () => src_default,
1921
+ expandSelection: () => expandSelection2,
1922
+ getActiveFormats: () => getActiveFormats2,
1923
+ getDebugMode: () => getDebugMode,
1924
+ hasFormat: () => hasFormat2,
1925
+ insertHeader: () => insertHeader,
1926
+ insertLink: () => insertLink,
1927
+ preserveSelection: () => preserveSelection,
1928
+ setDebugMode: () => setDebugMode,
1929
+ setUndoMethod: () => setUndoMethod,
1930
+ toggleBold: () => toggleBold,
1931
+ toggleBulletList: () => toggleBulletList,
1932
+ toggleCode: () => toggleCode,
1933
+ toggleH1: () => toggleH1,
1934
+ toggleH2: () => toggleH2,
1935
+ toggleH3: () => toggleH3,
1936
+ toggleItalic: () => toggleItalic,
1937
+ toggleNumberedList: () => toggleNumberedList,
1938
+ toggleQuote: () => toggleQuote,
1939
+ toggleTaskList: () => toggleTaskList
1940
+ });
1916
1941
  var __defProp2 = Object.defineProperty;
1917
1942
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1918
1943
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
@@ -1999,6 +2024,9 @@ function mergeWithDefaults(format) {
1999
2024
  return __spreadValues(__spreadValues({}, getDefaultStyle()), format);
2000
2025
  }
2001
2026
  var debugMode = false;
2027
+ function setDebugMode(enabled) {
2028
+ debugMode = enabled;
2029
+ }
2002
2030
  function getDebugMode() {
2003
2031
  return debugMode;
2004
2032
  }
@@ -2119,6 +2147,19 @@ function insertText(textarea, { text, selectionStart, selectionEnd }) {
2119
2147
  console.groupEnd();
2120
2148
  }
2121
2149
  }
2150
+ function setUndoMethod(method) {
2151
+ switch (method) {
2152
+ case "native":
2153
+ canInsertText = true;
2154
+ break;
2155
+ case "manual":
2156
+ canInsertText = false;
2157
+ break;
2158
+ case "auto":
2159
+ canInsertText = null;
2160
+ break;
2161
+ }
2162
+ }
2122
2163
  function isMultipleLines(string) {
2123
2164
  return string.trim().split("\n").length > 1;
2124
2165
  }
@@ -2188,6 +2229,15 @@ function newlinesToSurroundSelectedText(textarea) {
2188
2229
  }
2189
2230
  return { newlinesToAppend, newlinesToPrepend };
2190
2231
  }
2232
+ function preserveSelection(textarea, callback) {
2233
+ const start = textarea.selectionStart;
2234
+ const end = textarea.selectionEnd;
2235
+ const scrollTop = textarea.scrollTop;
2236
+ callback();
2237
+ textarea.selectionStart = start;
2238
+ textarea.selectionEnd = end;
2239
+ textarea.scrollTop = scrollTop;
2240
+ }
2191
2241
  function applyLineOperation(textarea, operation, options = {}) {
2192
2242
  const originalStart = textarea.selectionStart;
2193
2243
  const originalEnd = textarea.selectionEnd;
@@ -2561,6 +2611,43 @@ function getActiveFormats(textarea) {
2561
2611
  }
2562
2612
  return formats;
2563
2613
  }
2614
+ function hasFormat(textarea, format) {
2615
+ const activeFormats = getActiveFormats(textarea);
2616
+ return activeFormats.includes(format);
2617
+ }
2618
+ function expandSelection(textarea, options = {}) {
2619
+ if (!textarea)
2620
+ return;
2621
+ const { toWord, toLine, toFormat } = options;
2622
+ const { selectionStart, selectionEnd, value } = textarea;
2623
+ if (toLine) {
2624
+ const lines = value.split("\n");
2625
+ let lineStart = 0;
2626
+ let lineEnd = 0;
2627
+ let currentPos = 0;
2628
+ for (const line of lines) {
2629
+ if (selectionStart >= currentPos && selectionStart <= currentPos + line.length) {
2630
+ lineStart = currentPos;
2631
+ lineEnd = currentPos + line.length;
2632
+ break;
2633
+ }
2634
+ currentPos += line.length + 1;
2635
+ }
2636
+ textarea.selectionStart = lineStart;
2637
+ textarea.selectionEnd = lineEnd;
2638
+ } else if (toWord && selectionStart === selectionEnd) {
2639
+ let start = selectionStart;
2640
+ let end = selectionEnd;
2641
+ while (start > 0 && !/\s/.test(value[start - 1])) {
2642
+ start--;
2643
+ }
2644
+ while (end < value.length && !/\s/.test(value[end])) {
2645
+ end++;
2646
+ }
2647
+ textarea.selectionStart = start;
2648
+ textarea.selectionEnd = end;
2649
+ }
2650
+ }
2564
2651
  function toggleBold(textarea) {
2565
2652
  if (!textarea || textarea.disabled || textarea.readOnly)
2566
2653
  return;
@@ -2754,6 +2841,51 @@ function toggleH3(textarea) {
2754
2841
  function getActiveFormats2(textarea) {
2755
2842
  return getActiveFormats(textarea);
2756
2843
  }
2844
+ function hasFormat2(textarea, format) {
2845
+ return hasFormat(textarea, format);
2846
+ }
2847
+ function expandSelection2(textarea, options = {}) {
2848
+ expandSelection(textarea, options);
2849
+ }
2850
+ function applyCustomFormat(textarea, format) {
2851
+ if (!textarea || textarea.disabled || textarea.readOnly)
2852
+ return;
2853
+ const style = mergeWithDefaults(format);
2854
+ let result;
2855
+ if (style.multiline) {
2856
+ const selectedText = textarea.value.slice(textarea.selectionStart, textarea.selectionEnd);
2857
+ if (isMultipleLines(selectedText)) {
2858
+ result = multilineStyle(textarea, style);
2859
+ } else {
2860
+ result = blockStyle(textarea, style);
2861
+ }
2862
+ } else {
2863
+ result = blockStyle(textarea, style);
2864
+ }
2865
+ insertText(textarea, result);
2866
+ }
2867
+ var src_default = {
2868
+ toggleBold,
2869
+ toggleItalic,
2870
+ toggleCode,
2871
+ insertLink,
2872
+ toggleBulletList,
2873
+ toggleNumberedList,
2874
+ toggleQuote,
2875
+ toggleTaskList,
2876
+ insertHeader,
2877
+ toggleH1,
2878
+ toggleH2,
2879
+ toggleH3,
2880
+ getActiveFormats: getActiveFormats2,
2881
+ hasFormat: hasFormat2,
2882
+ expandSelection: expandSelection2,
2883
+ applyCustomFormat,
2884
+ preserveSelection,
2885
+ setUndoMethod,
2886
+ setDebugMode,
2887
+ getDebugMode
2888
+ };
2757
2889
 
2758
2890
  // src/toolbar.js
2759
2891
  var Toolbar = class {
@@ -4679,21 +4811,9 @@ var _OverType = class _OverType {
4679
4811
  * @returns {Array} Array of OverType instances
4680
4812
  */
4681
4813
  constructor(target, options = {}) {
4682
- let elements;
4683
- if (typeof target === "string") {
4684
- elements = document.querySelectorAll(target);
4685
- if (elements.length === 0) {
4686
- throw new Error(`No elements found for selector: ${target}`);
4687
- }
4688
- elements = Array.from(elements);
4689
- } else if (target instanceof Element) {
4690
- elements = [target];
4691
- } else if (target instanceof NodeList) {
4692
- elements = Array.from(target);
4693
- } else if (Array.isArray(target)) {
4694
- elements = target;
4695
- } else {
4696
- throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");
4814
+ const elements = _OverType._resolveTargets(target);
4815
+ if (typeof target === "string" && elements.length === 0) {
4816
+ throw new Error(`No elements found for selector: ${target}`);
4697
4817
  }
4698
4818
  const instances = elements.map((element) => {
4699
4819
  if (element.overTypeInstance) {
@@ -4741,7 +4861,7 @@ var _OverType = class _OverType {
4741
4861
  });
4742
4862
  this.initialized = true;
4743
4863
  if (this.options.onChange) {
4744
- this.options.onChange(this.getValue(), this);
4864
+ this._notifyChange();
4745
4865
  }
4746
4866
  }
4747
4867
  /**
@@ -4779,6 +4899,8 @@ var _OverType = class _OverType {
4779
4899
  onChange: null,
4780
4900
  onKeydown: null,
4781
4901
  onRender: null,
4902
+ onFocus: null,
4903
+ onBlur: null,
4782
4904
  // Features
4783
4905
  showActiveLineRaw: false,
4784
4906
  showStats: false,
@@ -5181,13 +5303,19 @@ var _OverType = class _OverType {
5181
5303
  if (this.options.showStats && this.statsBar) {
5182
5304
  this._updateStats();
5183
5305
  }
5184
- if (this.options.onChange && this.initialized) {
5185
- this.options.onChange(text, this);
5186
- }
5187
5306
  if (this.options.onRender) {
5188
5307
  this.options.onRender(this.preview, isPreviewMode ? "preview" : "normal", this);
5189
5308
  }
5190
5309
  }
5310
+ /**
5311
+ * Notify listeners that the editor value changed
5312
+ * @private
5313
+ */
5314
+ _notifyChange() {
5315
+ if (!this.options.onChange || !this.initialized)
5316
+ return;
5317
+ this.options.onChange(this.textarea.value, this);
5318
+ }
5191
5319
  /**
5192
5320
  * Apply background styling to code blocks
5193
5321
  * @private
@@ -5221,6 +5349,25 @@ var _OverType = class _OverType {
5221
5349
  */
5222
5350
  handleInput(event) {
5223
5351
  this.updatePreview();
5352
+ this._notifyChange();
5353
+ }
5354
+ /**
5355
+ * Handle focus events
5356
+ * @private
5357
+ */
5358
+ handleFocus(event) {
5359
+ if (this.options.onFocus) {
5360
+ this.options.onFocus(event, this);
5361
+ }
5362
+ }
5363
+ /**
5364
+ * Handle blur events
5365
+ * @private
5366
+ */
5367
+ handleBlur(event) {
5368
+ if (this.options.onBlur) {
5369
+ this.options.onBlur(event, this);
5370
+ }
5224
5371
  }
5225
5372
  /**
5226
5373
  * Handle keydown events
@@ -5401,11 +5548,15 @@ var _OverType = class _OverType {
5401
5548
  * @param {string} value - Markdown content to set
5402
5549
  */
5403
5550
  setValue(value) {
5551
+ const didChange = this.textarea.value !== value;
5404
5552
  this.textarea.value = value;
5405
5553
  this.updatePreview();
5406
5554
  if (this.options.autoResize) {
5407
5555
  this._updateAutoHeight();
5408
5556
  }
5557
+ if (didChange) {
5558
+ this._notifyChange();
5559
+ }
5409
5560
  }
5410
5561
  /**
5411
5562
  * Execute an action by ID
@@ -5762,9 +5913,9 @@ var _OverType = class _OverType {
5762
5913
  * // HTML: <div class="editor" data-ot-toolbar="true" data-ot-theme="cave"></div>
5763
5914
  * OverType.initFromData('.editor', { fontSize: '14px' });
5764
5915
  */
5765
- static initFromData(selector, defaults = {}) {
5766
- const elements = document.querySelectorAll(selector);
5767
- return Array.from(elements).map((el) => {
5916
+ static initFromData(target, defaults = {}) {
5917
+ const elements = _OverType._resolveTargets(target);
5918
+ return elements.map((el) => {
5768
5919
  const options = { ...defaults };
5769
5920
  for (const attr of el.attributes) {
5770
5921
  if (attr.name.startsWith("data-ot-")) {
@@ -5776,6 +5927,33 @@ var _OverType = class _OverType {
5776
5927
  return new _OverType(el, options)[0];
5777
5928
  });
5778
5929
  }
5930
+ /**
5931
+ * Normalize various target shapes to an array of Elements
5932
+ * @private
5933
+ * @param {string|Element|NodeList|Element[]} target
5934
+ * @returns {Element[]}
5935
+ */
5936
+ static _resolveTargets(target) {
5937
+ if (target == null) {
5938
+ throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");
5939
+ }
5940
+ if (typeof target === "string") {
5941
+ return Array.from(document.querySelectorAll(target));
5942
+ }
5943
+ if (target instanceof Element) {
5944
+ return [target];
5945
+ }
5946
+ if (target instanceof NodeList) {
5947
+ return Array.from(target);
5948
+ }
5949
+ if (Array.isArray(target)) {
5950
+ return target;
5951
+ }
5952
+ if (typeof target.length === "number") {
5953
+ return Array.from(target);
5954
+ }
5955
+ throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");
5956
+ }
5779
5957
  /**
5780
5958
  * Parse a data attribute value to the appropriate type
5781
5959
  * @private
@@ -5792,11 +5970,22 @@ var _OverType = class _OverType {
5792
5970
  return value;
5793
5971
  }
5794
5972
  /**
5795
- * Get instance from element
5796
- * @param {Element} element - DOM element
5797
- * @returns {OverType|null} OverType instance or null
5973
+ * Get instance from a target. Accepts the same shapes as the constructor;
5974
+ * for multi-element targets, returns the instance for the first matching
5975
+ * element, or null if none.
5976
+ * @param {string|Element|NodeList|Element[]} target
5977
+ * @returns {OverType|null}
5798
5978
  */
5799
- static getInstance(element) {
5979
+ static getInstance(target) {
5980
+ let element;
5981
+ if (target instanceof Element) {
5982
+ element = target;
5983
+ } else {
5984
+ const elements = _OverType._resolveTargets(target);
5985
+ element = elements[0];
5986
+ }
5987
+ if (!element)
5988
+ return null;
5800
5989
  return element.overTypeInstance || _OverType.instances.get(element) || null;
5801
5990
  }
5802
5991
  /**
@@ -5974,6 +6163,22 @@ var _OverType = class _OverType {
5974
6163
  instance.handleKeydown(e);
5975
6164
  }
5976
6165
  });
6166
+ document.addEventListener("focus", (e) => {
6167
+ if (e.target && e.target.classList && e.target.classList.contains("overtype-input")) {
6168
+ const wrapper = e.target.closest(".overtype-wrapper");
6169
+ const instance = wrapper == null ? void 0 : wrapper._instance;
6170
+ if (instance)
6171
+ instance.handleFocus(e);
6172
+ }
6173
+ }, true);
6174
+ document.addEventListener("blur", (e) => {
6175
+ if (e.target && e.target.classList && e.target.classList.contains("overtype-input")) {
6176
+ const wrapper = e.target.closest(".overtype-wrapper");
6177
+ const instance = wrapper == null ? void 0 : wrapper._instance;
6178
+ if (instance)
6179
+ instance.handleBlur(e);
6180
+ }
6181
+ }, true);
5977
6182
  document.addEventListener("scroll", (e) => {
5978
6183
  if (e.target && e.target.classList && e.target.classList.contains("overtype-input")) {
5979
6184
  const wrapper = e.target.closest(".overtype-wrapper");
@@ -6022,6 +6227,7 @@ var overtype_default = OverType;
6022
6227
  0 && (module.exports = {
6023
6228
  OverType,
6024
6229
  defaultToolbarButtons,
6230
+ markdownActions,
6025
6231
  toolbarButtons
6026
6232
  });
6027
6233
  /**