overtype 2.3.2 → 2.3.4

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.2",
3
+ "version": "2.3.4",
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
@@ -1321,33 +1321,39 @@ class OverType {
1321
1321
  */
1322
1322
  _updateAutoHeight() {
1323
1323
  if (!this.options.autoResize) return;
1324
-
1324
+
1325
1325
  const textarea = this.textarea;
1326
1326
  const preview = this.preview;
1327
1327
  const wrapper = this.wrapper;
1328
-
1329
- // Get computed styles
1330
- const computed = window.getComputedStyle(textarea);
1331
- const paddingTop = parseFloat(computed.paddingTop);
1332
- const paddingBottom = parseFloat(computed.paddingBottom);
1333
-
1328
+ const isPreviewMode = this.container.dataset.mode === 'preview';
1329
+
1330
+ if (isPreviewMode) {
1331
+ // In preview mode, CSS makes the preview position:static so it flows naturally.
1332
+ // Just clear any inline heights left over from edit mode.
1333
+ wrapper.style.removeProperty('height');
1334
+ preview.style.removeProperty('height');
1335
+ preview.style.removeProperty('overflow-y');
1336
+ textarea.style.removeProperty('height');
1337
+ textarea.style.removeProperty('overflow-y');
1338
+ return;
1339
+ }
1340
+
1334
1341
  // Store scroll positions
1335
1342
  const scrollTop = textarea.scrollTop;
1336
-
1343
+
1337
1344
  // Reset heights to get accurate scrollHeight
1338
1345
  // Wrapper must also reset so the absolute-positioned textarea isn't constrained
1339
1346
  wrapper.style.setProperty('height', 'auto', 'important');
1340
1347
  textarea.style.setProperty('height', 'auto', 'important');
1341
1348
 
1342
- // Calculate new height based on scrollHeight
1343
1349
  let newHeight = textarea.scrollHeight;
1344
-
1350
+
1345
1351
  // Apply min height constraint
1346
1352
  if (this.options.minHeight) {
1347
1353
  const minHeight = parseInt(this.options.minHeight);
1348
1354
  newHeight = Math.max(newHeight, minHeight);
1349
1355
  }
1350
-
1356
+
1351
1357
  // Apply max height constraint
1352
1358
  let overflow = 'hidden';
1353
1359
  if (this.options.maxHeight) {
@@ -1357,25 +1363,24 @@ class OverType {
1357
1363
  overflow = 'auto';
1358
1364
  }
1359
1365
  }
1360
-
1366
+
1361
1367
  // Apply the new height to all elements with !important to override base styles
1362
1368
  const heightPx = newHeight + 'px';
1363
1369
  textarea.style.setProperty('height', heightPx, 'important');
1364
1370
  textarea.style.setProperty('overflow-y', overflow, 'important');
1365
-
1371
+
1366
1372
  preview.style.setProperty('height', heightPx, 'important');
1367
1373
  preview.style.setProperty('overflow-y', overflow, 'important');
1368
-
1374
+
1369
1375
  wrapper.style.setProperty('height', heightPx, 'important');
1370
-
1376
+
1371
1377
  // Restore scroll position
1372
1378
  textarea.scrollTop = scrollTop;
1373
1379
  preview.scrollTop = scrollTop;
1374
-
1380
+
1375
1381
  // Track if height changed
1376
1382
  if (this.previousHeight !== newHeight) {
1377
1383
  this.previousHeight = newHeight;
1378
- // Could dispatch a custom event here if needed
1379
1384
  }
1380
1385
  }
1381
1386
 
@@ -1409,6 +1414,7 @@ class OverType {
1409
1414
  showNormalEditMode() {
1410
1415
  this.container.dataset.mode = 'normal';
1411
1416
  this.updatePreview(); // Re-render with normal mode (e.g., show syntax markers)
1417
+ this._updateAutoHeight();
1412
1418
 
1413
1419
  // Always sync scroll from preview to textarea
1414
1420
  requestAnimationFrame(() => {
@@ -1425,6 +1431,7 @@ class OverType {
1425
1431
  */
1426
1432
  showPlainTextarea() {
1427
1433
  this.container.dataset.mode = 'plain';
1434
+ this._updateAutoHeight();
1428
1435
 
1429
1436
  // Update toolbar button if exists
1430
1437
  if (this.toolbar) {
@@ -1445,6 +1452,7 @@ class OverType {
1445
1452
  showPreviewMode() {
1446
1453
  this.container.dataset.mode = 'preview';
1447
1454
  this.updatePreview(); // Re-render with preview mode (e.g., checkboxes)
1455
+ this._updateAutoHeight();
1448
1456
  return this;
1449
1457
  }
1450
1458
 
package/src/styles.js CHANGED
@@ -693,6 +693,11 @@ export function generateStyles(options = {}) {
693
693
  cursor: text !important;
694
694
  }
695
695
 
696
+ .overtype-container.overtype-auto-resize[data-mode="preview"] .overtype-preview {
697
+ position: static !important;
698
+ height: auto !important;
699
+ }
700
+
696
701
  /* Hide syntax markers in preview mode */
697
702
  .overtype-container[data-mode="preview"] .syntax-marker {
698
703
  display: none !important;