overtype 2.3.5 → 2.3.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "overtype",
3
- "version": "2.3.5",
3
+ "version": "2.3.7",
4
4
  "description": "A lightweight markdown editor library with perfect WYSIWYG alignment using an invisible textarea overlay",
5
5
  "main": "dist/overtype.cjs",
6
6
  "module": "dist/overtype.esm.js",
package/src/overtype.js CHANGED
@@ -189,7 +189,7 @@ class OverType {
189
189
 
190
190
  // Call onChange if provided
191
191
  if (this.options.onChange) {
192
- this.options.onChange(this.getValue(), this);
192
+ this._notifyChange();
193
193
  }
194
194
  }
195
195
 
@@ -304,16 +304,7 @@ class OverType {
304
304
  // Store reference on wrapper
305
305
  this.wrapper._instance = this;
306
306
 
307
- // Apply instance-specific styles via CSS custom properties
308
- if (this.options.fontSize) {
309
- this.wrapper.style.setProperty('--instance-font-size', this.options.fontSize);
310
- }
311
- if (this.options.lineHeight) {
312
- this.wrapper.style.setProperty('--instance-line-height', String(this.options.lineHeight));
313
- }
314
- if (this.options.padding) {
315
- this.wrapper.style.setProperty('--instance-padding', this.options.padding);
316
- }
307
+ this._applyInstanceCSSVars();
317
308
 
318
309
  // Disable autofill, spellcheck, and extensions
319
310
  this._configureTextarea();
@@ -388,17 +379,8 @@ class OverType {
388
379
  this.wrapper.className = 'overtype-wrapper';
389
380
 
390
381
 
391
- // Apply instance-specific styles via CSS custom properties
392
- if (this.options.fontSize) {
393
- this.wrapper.style.setProperty('--instance-font-size', this.options.fontSize);
394
- }
395
- if (this.options.lineHeight) {
396
- this.wrapper.style.setProperty('--instance-line-height', String(this.options.lineHeight));
397
- }
398
- if (this.options.padding) {
399
- this.wrapper.style.setProperty('--instance-padding', this.options.padding);
400
- }
401
-
382
+ this._applyInstanceCSSVars();
383
+
402
384
  this.wrapper._instance = this;
403
385
 
404
386
  // Create textarea
@@ -548,11 +530,36 @@ class OverType {
548
530
  }
549
531
  }
550
532
 
533
+ /**
534
+ * Apply instance-specific styles via CSS custom properties on the wrapper.
535
+ * Called from init paths and from _applyOptions so reinit() propagates
536
+ * font/padding changes.
537
+ * @private
538
+ */
539
+ _applyInstanceCSSVars() {
540
+ if (!this.wrapper) return;
541
+ if (this.options.fontSize) {
542
+ this.wrapper.style.setProperty('--instance-font-size', this.options.fontSize);
543
+ }
544
+ if (this.options.lineHeight) {
545
+ this.wrapper.style.setProperty('--instance-line-height', String(this.options.lineHeight));
546
+ }
547
+ if (this.options.padding) {
548
+ this.wrapper.style.setProperty('--instance-padding', this.options.padding);
549
+ }
550
+ if (this.options.fontFamily) {
551
+ this.wrapper.style.setProperty('--instance-font-family', this.options.fontFamily);
552
+ }
553
+ }
554
+
551
555
  /**
552
556
  * Apply options to the editor
553
557
  * @private
554
558
  */
555
559
  _applyOptions() {
560
+ // Re-apply instance-specific CSS vars so reinit() picks up font/padding changes
561
+ this._applyInstanceCSSVars();
562
+
556
563
  // Apply autofocus
557
564
  if (this.options.autofocus) {
558
565
  this.textarea.focus();
@@ -740,17 +747,21 @@ class OverType {
740
747
  this._updateStats();
741
748
  }
742
749
 
743
- // Trigger onChange callback
744
- if (this.options.onChange && this.initialized) {
745
- this.options.onChange(text, this);
746
- }
747
-
748
750
  // Trigger onRender callback
749
751
  if (this.options.onRender) {
750
752
  this.options.onRender(this.preview, isPreviewMode ? 'preview' : 'normal', this);
751
753
  }
752
754
  }
753
755
 
756
+ /**
757
+ * Notify listeners that the editor value changed
758
+ * @private
759
+ */
760
+ _notifyChange() {
761
+ if (!this.options.onChange || !this.initialized) return;
762
+ this.options.onChange(this.textarea.value, this);
763
+ }
764
+
754
765
  /**
755
766
  * Apply background styling to code blocks
756
767
  * @private
@@ -799,6 +810,7 @@ class OverType {
799
810
  */
800
811
  handleInput(event) {
801
812
  this.updatePreview();
813
+ this._notifyChange();
802
814
  }
803
815
 
804
816
  /**
@@ -1052,6 +1064,7 @@ class OverType {
1052
1064
  * @param {string} value - Markdown content to set
1053
1065
  */
1054
1066
  setValue(value) {
1067
+ const didChange = this.textarea.value !== value;
1055
1068
  this.textarea.value = value;
1056
1069
  this.updatePreview();
1057
1070
 
@@ -1059,6 +1072,10 @@ class OverType {
1059
1072
  if (this.options.autoResize) {
1060
1073
  this._updateAutoHeight();
1061
1074
  }
1075
+
1076
+ if (didChange) {
1077
+ this._notifyChange();
1078
+ }
1062
1079
  }
1063
1080
 
1064
1081
  /**
package/src/parser.js CHANGED
@@ -134,15 +134,15 @@ export class MarkdownParser {
134
134
  * @returns {string} Parsed task list item
135
135
  */
136
136
  static parseTaskList(html, isPreviewMode = false) {
137
- return html.replace(/^((?: )*)-\s+\[([ xX])\]\s+(.+)$/, (match, indent, checked, content) => {
137
+ return html.replace(/^((?: )*)-(\s+)\[([ xX])\](\s*)(.*)$/, (match, indent, spacingBeforeBox, checked, spacingAfterBox, content) => {
138
138
  content = this.parseInlineElements(content);
139
139
  if (isPreviewMode) {
140
140
  // Preview mode: render actual checkbox
141
141
  const isChecked = checked.toLowerCase() === 'x';
142
142
  return `${indent}<li class="task-list"><input type="checkbox" ${isChecked ? 'checked' : ''}> ${content}</li>`;
143
143
  } else {
144
- // Normal mode: keep syntax visible for alignment
145
- return `${indent}<li class="task-list"><span class="syntax-marker">- [${checked}] </span>${content}</li>`;
144
+ // Normal mode: keep syntax (including user spacing) visible for alignment
145
+ return `${indent}<li class="task-list"><span class="syntax-marker">-${spacingBeforeBox}[${checked}]${spacingAfterBox}</span>${content}</li>`;
146
146
  }
147
147
  });
148
148
  }
package/src/styles.js CHANGED
@@ -121,9 +121,9 @@ export function generateStyles(options = {}) {
121
121
  left: 0 !important;
122
122
  width: 100% !important;
123
123
  height: 100% !important;
124
-
124
+
125
125
  /* Font properties - any difference breaks alignment */
126
- font-family: ${fontFamily} !important;
126
+ font-family: var(--instance-font-family, ${fontFamily}) !important;
127
127
  font-variant-ligatures: none !important; /* keep metrics stable for code */
128
128
  font-size: var(--instance-font-size, ${fontSize}) !important;
129
129
  line-height: var(--instance-line-height, ${lineHeight}) !important;
@@ -230,15 +230,12 @@ export function generateStyles(options = {}) {
230
230
  z-index: 0 !important;
231
231
  pointer-events: none !important;
232
232
  user-select: none !important;
233
- font-family: ${fontFamily} !important;
233
+ font-family: var(--instance-font-family, ${fontFamily}) !important;
234
234
  font-size: var(--instance-font-size, ${fontSize}) !important;
235
235
  line-height: var(--instance-line-height, ${lineHeight}) !important;
236
236
  padding: var(--instance-padding, ${padding}) !important;
237
237
  box-sizing: border-box !important;
238
238
  color: var(--placeholder, #999) !important;
239
- overflow: hidden !important;
240
- white-space: nowrap !important;
241
- text-overflow: ellipsis !important;
242
239
  }
243
240
 
244
241
  /* Preview layer styles */
@@ -391,7 +388,7 @@ export function generateStyles(options = {}) {
391
388
  .overtype-wrapper .overtype-preview pre code {
392
389
  background: transparent !important;
393
390
  color: var(--code, #0d3b66) !important;
394
- font-family: ${fontFamily} !important; /* Match textarea font exactly for alignment */
391
+ font-family: var(--instance-font-family, ${fontFamily}) !important; /* Match textarea font exactly for alignment */
395
392
  }
396
393
 
397
394
  /* Blockquotes */
@@ -476,26 +473,20 @@ export function generateStyles(options = {}) {
476
473
  .overtype-stats {
477
474
  height: 40px !important;
478
475
  padding: 0 20px !important;
479
- background: #f8f9fa !important;
480
- border-top: 1px solid #e0e0e0 !important;
476
+ background: var(--bg-secondary, #f8f9fa) !important;
477
+ border-top: 1px solid var(--border, #e0e0e0) !important;
481
478
  display: flex !important;
482
479
  justify-content: space-between !important;
483
480
  align-items: center !important;
484
481
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
485
482
  font-size: 0.85rem !important;
486
- color: #666 !important;
483
+ color: var(--text-secondary, #666) !important;
487
484
  flex-shrink: 0 !important; /* Don't shrink */
488
485
  z-index: 10001 !important; /* Above link tooltip */
489
486
  position: relative !important; /* Enable z-index */
490
487
  }
491
-
492
- /* Dark theme stats bar */
493
- .overtype-container[data-theme="cave"] .overtype-stats {
494
- background: var(--bg-secondary, #1D2D3E) !important;
495
- border-top: 1px solid rgba(197, 221, 232, 0.1) !important;
496
- color: var(--text, #c5dde8) !important;
497
- }
498
-
488
+
489
+
499
490
  .overtype-stats .overtype-stat {
500
491
  display: flex !important;
501
492
  align-items: center !important;