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.
@@ -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
@@ -145,13 +145,13 @@ var OverTypeEditor = (() => {
145
145
  * @returns {string} Parsed task list item
146
146
  */
147
147
  static parseTaskList(html, isPreviewMode = false) {
148
- return html.replace(/^((?: )*)-\s+\[([ xX])\]\s+(.+)$/, (match, indent, checked, content) => {
148
+ return html.replace(/^((?: )*)-(\s+)\[([ xX])\](\s*)(.*)$/, (match, indent, spacingBeforeBox, checked, spacingAfterBox, content) => {
149
149
  content = this.parseInlineElements(content);
150
150
  if (isPreviewMode) {
151
151
  const isChecked = checked.toLowerCase() === "x";
152
152
  return `${indent}<li class="task-list"><input type="checkbox" ${isChecked ? "checked" : ""}> ${content}</li>`;
153
153
  } else {
154
- return `${indent}<li class="task-list"><span class="syntax-marker">- [${checked}] </span>${content}</li>`;
154
+ return `${indent}<li class="task-list"><span class="syntax-marker">-${spacingBeforeBox}[${checked}]${spacingAfterBox}</span>${content}</li>`;
155
155
  }
156
156
  });
157
157
  }
@@ -1910,6 +1910,30 @@ var OverTypeEditor = (() => {
1910
1910
  }
1911
1911
 
1912
1912
  // node_modules/markdown-actions/dist/markdown-actions.esm.js
1913
+ var markdown_actions_esm_exports = {};
1914
+ __export(markdown_actions_esm_exports, {
1915
+ applyCustomFormat: () => applyCustomFormat,
1916
+ default: () => src_default,
1917
+ expandSelection: () => expandSelection2,
1918
+ getActiveFormats: () => getActiveFormats2,
1919
+ getDebugMode: () => getDebugMode,
1920
+ hasFormat: () => hasFormat2,
1921
+ insertHeader: () => insertHeader,
1922
+ insertLink: () => insertLink,
1923
+ preserveSelection: () => preserveSelection,
1924
+ setDebugMode: () => setDebugMode,
1925
+ setUndoMethod: () => setUndoMethod,
1926
+ toggleBold: () => toggleBold,
1927
+ toggleBulletList: () => toggleBulletList,
1928
+ toggleCode: () => toggleCode,
1929
+ toggleH1: () => toggleH1,
1930
+ toggleH2: () => toggleH2,
1931
+ toggleH3: () => toggleH3,
1932
+ toggleItalic: () => toggleItalic,
1933
+ toggleNumberedList: () => toggleNumberedList,
1934
+ toggleQuote: () => toggleQuote,
1935
+ toggleTaskList: () => toggleTaskList
1936
+ });
1913
1937
  var __defProp2 = Object.defineProperty;
1914
1938
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1915
1939
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
@@ -1996,6 +2020,9 @@ var OverTypeEditor = (() => {
1996
2020
  return __spreadValues(__spreadValues({}, getDefaultStyle()), format);
1997
2021
  }
1998
2022
  var debugMode = false;
2023
+ function setDebugMode(enabled) {
2024
+ debugMode = enabled;
2025
+ }
1999
2026
  function getDebugMode() {
2000
2027
  return debugMode;
2001
2028
  }
@@ -2116,6 +2143,19 @@ var OverTypeEditor = (() => {
2116
2143
  console.groupEnd();
2117
2144
  }
2118
2145
  }
2146
+ function setUndoMethod(method) {
2147
+ switch (method) {
2148
+ case "native":
2149
+ canInsertText = true;
2150
+ break;
2151
+ case "manual":
2152
+ canInsertText = false;
2153
+ break;
2154
+ case "auto":
2155
+ canInsertText = null;
2156
+ break;
2157
+ }
2158
+ }
2119
2159
  function isMultipleLines(string) {
2120
2160
  return string.trim().split("\n").length > 1;
2121
2161
  }
@@ -2185,6 +2225,15 @@ var OverTypeEditor = (() => {
2185
2225
  }
2186
2226
  return { newlinesToAppend, newlinesToPrepend };
2187
2227
  }
2228
+ function preserveSelection(textarea, callback) {
2229
+ const start = textarea.selectionStart;
2230
+ const end = textarea.selectionEnd;
2231
+ const scrollTop = textarea.scrollTop;
2232
+ callback();
2233
+ textarea.selectionStart = start;
2234
+ textarea.selectionEnd = end;
2235
+ textarea.scrollTop = scrollTop;
2236
+ }
2188
2237
  function applyLineOperation(textarea, operation, options = {}) {
2189
2238
  const originalStart = textarea.selectionStart;
2190
2239
  const originalEnd = textarea.selectionEnd;
@@ -2558,6 +2607,43 @@ ${blockSuffix}` : suffix;
2558
2607
  }
2559
2608
  return formats;
2560
2609
  }
2610
+ function hasFormat(textarea, format) {
2611
+ const activeFormats = getActiveFormats(textarea);
2612
+ return activeFormats.includes(format);
2613
+ }
2614
+ function expandSelection(textarea, options = {}) {
2615
+ if (!textarea)
2616
+ return;
2617
+ const { toWord, toLine, toFormat } = options;
2618
+ const { selectionStart, selectionEnd, value } = textarea;
2619
+ if (toLine) {
2620
+ const lines = value.split("\n");
2621
+ let lineStart = 0;
2622
+ let lineEnd = 0;
2623
+ let currentPos = 0;
2624
+ for (const line of lines) {
2625
+ if (selectionStart >= currentPos && selectionStart <= currentPos + line.length) {
2626
+ lineStart = currentPos;
2627
+ lineEnd = currentPos + line.length;
2628
+ break;
2629
+ }
2630
+ currentPos += line.length + 1;
2631
+ }
2632
+ textarea.selectionStart = lineStart;
2633
+ textarea.selectionEnd = lineEnd;
2634
+ } else if (toWord && selectionStart === selectionEnd) {
2635
+ let start = selectionStart;
2636
+ let end = selectionEnd;
2637
+ while (start > 0 && !/\s/.test(value[start - 1])) {
2638
+ start--;
2639
+ }
2640
+ while (end < value.length && !/\s/.test(value[end])) {
2641
+ end++;
2642
+ }
2643
+ textarea.selectionStart = start;
2644
+ textarea.selectionEnd = end;
2645
+ }
2646
+ }
2561
2647
  function toggleBold(textarea) {
2562
2648
  if (!textarea || textarea.disabled || textarea.readOnly)
2563
2649
  return;
@@ -2751,6 +2837,51 @@ ${blockSuffix}` : suffix;
2751
2837
  function getActiveFormats2(textarea) {
2752
2838
  return getActiveFormats(textarea);
2753
2839
  }
2840
+ function hasFormat2(textarea, format) {
2841
+ return hasFormat(textarea, format);
2842
+ }
2843
+ function expandSelection2(textarea, options = {}) {
2844
+ expandSelection(textarea, options);
2845
+ }
2846
+ function applyCustomFormat(textarea, format) {
2847
+ if (!textarea || textarea.disabled || textarea.readOnly)
2848
+ return;
2849
+ const style = mergeWithDefaults(format);
2850
+ let result;
2851
+ if (style.multiline) {
2852
+ const selectedText = textarea.value.slice(textarea.selectionStart, textarea.selectionEnd);
2853
+ if (isMultipleLines(selectedText)) {
2854
+ result = multilineStyle(textarea, style);
2855
+ } else {
2856
+ result = blockStyle(textarea, style);
2857
+ }
2858
+ } else {
2859
+ result = blockStyle(textarea, style);
2860
+ }
2861
+ insertText(textarea, result);
2862
+ }
2863
+ var src_default = {
2864
+ toggleBold,
2865
+ toggleItalic,
2866
+ toggleCode,
2867
+ insertLink,
2868
+ toggleBulletList,
2869
+ toggleNumberedList,
2870
+ toggleQuote,
2871
+ toggleTaskList,
2872
+ insertHeader,
2873
+ toggleH1,
2874
+ toggleH2,
2875
+ toggleH3,
2876
+ getActiveFormats: getActiveFormats2,
2877
+ hasFormat: hasFormat2,
2878
+ expandSelection: expandSelection2,
2879
+ applyCustomFormat,
2880
+ preserveSelection,
2881
+ setUndoMethod,
2882
+ setDebugMode,
2883
+ getDebugMode
2884
+ };
2754
2885
 
2755
2886
  // src/toolbar.js
2756
2887
  var Toolbar = class {
@@ -4676,21 +4807,9 @@ ${blockSuffix}` : suffix;
4676
4807
  * @returns {Array} Array of OverType instances
4677
4808
  */
4678
4809
  constructor(target, options = {}) {
4679
- let elements;
4680
- if (typeof target === "string") {
4681
- elements = document.querySelectorAll(target);
4682
- if (elements.length === 0) {
4683
- throw new Error(`No elements found for selector: ${target}`);
4684
- }
4685
- elements = Array.from(elements);
4686
- } else if (target instanceof Element) {
4687
- elements = [target];
4688
- } else if (target instanceof NodeList) {
4689
- elements = Array.from(target);
4690
- } else if (Array.isArray(target)) {
4691
- elements = target;
4692
- } else {
4693
- throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");
4810
+ const elements = _OverType._resolveTargets(target);
4811
+ if (typeof target === "string" && elements.length === 0) {
4812
+ throw new Error(`No elements found for selector: ${target}`);
4694
4813
  }
4695
4814
  const instances = elements.map((element) => {
4696
4815
  if (element.overTypeInstance) {
@@ -4738,7 +4857,7 @@ ${blockSuffix}` : suffix;
4738
4857
  });
4739
4858
  this.initialized = true;
4740
4859
  if (this.options.onChange) {
4741
- this.options.onChange(this.getValue(), this);
4860
+ this._notifyChange();
4742
4861
  }
4743
4862
  }
4744
4863
  /**
@@ -4776,6 +4895,8 @@ ${blockSuffix}` : suffix;
4776
4895
  onChange: null,
4777
4896
  onKeydown: null,
4778
4897
  onRender: null,
4898
+ onFocus: null,
4899
+ onBlur: null,
4779
4900
  // Features
4780
4901
  showActiveLineRaw: false,
4781
4902
  showStats: false,
@@ -5178,13 +5299,19 @@ ${blockSuffix}` : suffix;
5178
5299
  if (this.options.showStats && this.statsBar) {
5179
5300
  this._updateStats();
5180
5301
  }
5181
- if (this.options.onChange && this.initialized) {
5182
- this.options.onChange(text, this);
5183
- }
5184
5302
  if (this.options.onRender) {
5185
5303
  this.options.onRender(this.preview, isPreviewMode ? "preview" : "normal", this);
5186
5304
  }
5187
5305
  }
5306
+ /**
5307
+ * Notify listeners that the editor value changed
5308
+ * @private
5309
+ */
5310
+ _notifyChange() {
5311
+ if (!this.options.onChange || !this.initialized)
5312
+ return;
5313
+ this.options.onChange(this.textarea.value, this);
5314
+ }
5188
5315
  /**
5189
5316
  * Apply background styling to code blocks
5190
5317
  * @private
@@ -5218,6 +5345,25 @@ ${blockSuffix}` : suffix;
5218
5345
  */
5219
5346
  handleInput(event) {
5220
5347
  this.updatePreview();
5348
+ this._notifyChange();
5349
+ }
5350
+ /**
5351
+ * Handle focus events
5352
+ * @private
5353
+ */
5354
+ handleFocus(event) {
5355
+ if (this.options.onFocus) {
5356
+ this.options.onFocus(event, this);
5357
+ }
5358
+ }
5359
+ /**
5360
+ * Handle blur events
5361
+ * @private
5362
+ */
5363
+ handleBlur(event) {
5364
+ if (this.options.onBlur) {
5365
+ this.options.onBlur(event, this);
5366
+ }
5221
5367
  }
5222
5368
  /**
5223
5369
  * Handle keydown events
@@ -5398,11 +5544,15 @@ ${blockSuffix}` : suffix;
5398
5544
  * @param {string} value - Markdown content to set
5399
5545
  */
5400
5546
  setValue(value) {
5547
+ const didChange = this.textarea.value !== value;
5401
5548
  this.textarea.value = value;
5402
5549
  this.updatePreview();
5403
5550
  if (this.options.autoResize) {
5404
5551
  this._updateAutoHeight();
5405
5552
  }
5553
+ if (didChange) {
5554
+ this._notifyChange();
5555
+ }
5406
5556
  }
5407
5557
  /**
5408
5558
  * Execute an action by ID
@@ -5759,9 +5909,9 @@ ${blockSuffix}` : suffix;
5759
5909
  * // HTML: <div class="editor" data-ot-toolbar="true" data-ot-theme="cave"></div>
5760
5910
  * OverType.initFromData('.editor', { fontSize: '14px' });
5761
5911
  */
5762
- static initFromData(selector, defaults = {}) {
5763
- const elements = document.querySelectorAll(selector);
5764
- return Array.from(elements).map((el) => {
5912
+ static initFromData(target, defaults = {}) {
5913
+ const elements = _OverType._resolveTargets(target);
5914
+ return elements.map((el) => {
5765
5915
  const options = { ...defaults };
5766
5916
  for (const attr of el.attributes) {
5767
5917
  if (attr.name.startsWith("data-ot-")) {
@@ -5773,6 +5923,33 @@ ${blockSuffix}` : suffix;
5773
5923
  return new _OverType(el, options)[0];
5774
5924
  });
5775
5925
  }
5926
+ /**
5927
+ * Normalize various target shapes to an array of Elements
5928
+ * @private
5929
+ * @param {string|Element|NodeList|Element[]} target
5930
+ * @returns {Element[]}
5931
+ */
5932
+ static _resolveTargets(target) {
5933
+ if (target == null) {
5934
+ throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");
5935
+ }
5936
+ if (typeof target === "string") {
5937
+ return Array.from(document.querySelectorAll(target));
5938
+ }
5939
+ if (target instanceof Element) {
5940
+ return [target];
5941
+ }
5942
+ if (target instanceof NodeList) {
5943
+ return Array.from(target);
5944
+ }
5945
+ if (Array.isArray(target)) {
5946
+ return target;
5947
+ }
5948
+ if (typeof target.length === "number") {
5949
+ return Array.from(target);
5950
+ }
5951
+ throw new Error("Invalid target: must be selector string, Element, NodeList, or Array");
5952
+ }
5776
5953
  /**
5777
5954
  * Parse a data attribute value to the appropriate type
5778
5955
  * @private
@@ -5789,11 +5966,22 @@ ${blockSuffix}` : suffix;
5789
5966
  return value;
5790
5967
  }
5791
5968
  /**
5792
- * Get instance from element
5793
- * @param {Element} element - DOM element
5794
- * @returns {OverType|null} OverType instance or null
5969
+ * Get instance from a target. Accepts the same shapes as the constructor;
5970
+ * for multi-element targets, returns the instance for the first matching
5971
+ * element, or null if none.
5972
+ * @param {string|Element|NodeList|Element[]} target
5973
+ * @returns {OverType|null}
5795
5974
  */
5796
- static getInstance(element) {
5975
+ static getInstance(target) {
5976
+ let element;
5977
+ if (target instanceof Element) {
5978
+ element = target;
5979
+ } else {
5980
+ const elements = _OverType._resolveTargets(target);
5981
+ element = elements[0];
5982
+ }
5983
+ if (!element)
5984
+ return null;
5797
5985
  return element.overTypeInstance || _OverType.instances.get(element) || null;
5798
5986
  }
5799
5987
  /**
@@ -5971,6 +6159,22 @@ ${blockSuffix}` : suffix;
5971
6159
  instance.handleKeydown(e);
5972
6160
  }
5973
6161
  });
6162
+ document.addEventListener("focus", (e) => {
6163
+ if (e.target && e.target.classList && e.target.classList.contains("overtype-input")) {
6164
+ const wrapper = e.target.closest(".overtype-wrapper");
6165
+ const instance = wrapper == null ? void 0 : wrapper._instance;
6166
+ if (instance)
6167
+ instance.handleFocus(e);
6168
+ }
6169
+ }, true);
6170
+ document.addEventListener("blur", (e) => {
6171
+ if (e.target && e.target.classList && e.target.classList.contains("overtype-input")) {
6172
+ const wrapper = e.target.closest(".overtype-wrapper");
6173
+ const instance = wrapper == null ? void 0 : wrapper._instance;
6174
+ if (instance)
6175
+ instance.handleBlur(e);
6176
+ }
6177
+ }, true);
5974
6178
  document.addEventListener("scroll", (e) => {
5975
6179
  if (e.target && e.target.classList && e.target.classList.contains("overtype-input")) {
5976
6180
  const wrapper = e.target.closest(".overtype-wrapper");