@particle-academy/fancy-code 0.4.0 → 0.4.1

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/index.cjs CHANGED
@@ -110,10 +110,11 @@ function CodeEditorPanel({ className }) {
110
110
  "textarea",
111
111
  {
112
112
  ref: textareaRef,
113
- className: "relative m-0 block w-full resize-none overflow-hidden border-none bg-transparent p-2.5 text-[13px] leading-[1.5] text-transparent outline-none",
113
+ className: "relative m-0 block w-full resize-none border-none bg-transparent p-2.5 text-[13px] leading-[1.5] text-transparent outline-none",
114
114
  style: {
115
115
  caretColor: themeColors.cursorColor,
116
116
  minHeight: _minHeight ? _minHeight - 40 : 80,
117
+ overflow: "hidden",
117
118
  whiteSpace: wordWrap ? "pre-wrap" : "pre",
118
119
  overflowWrap: wordWrap ? "break-word" : "normal"
119
120
  },
@@ -1327,14 +1328,23 @@ function useEditorEngine({
1327
1328
  }
1328
1329
  return count;
1329
1330
  }, [value]);
1331
+ const autoResize = react.useCallback(() => {
1332
+ const ta = textareaRef.current;
1333
+ if (!ta) return;
1334
+ ta.style.height = "auto";
1335
+ ta.style.height = ta.scrollHeight + "px";
1336
+ }, []);
1330
1337
  react.useEffect(() => {
1331
1338
  const ta = textareaRef.current;
1332
- if (!ta || ta.value === value) return;
1333
- const { selectionStart, selectionEnd } = ta;
1334
- ta.value = value;
1335
- ta.selectionStart = selectionStart;
1336
- ta.selectionEnd = selectionEnd;
1337
- }, [value]);
1339
+ if (!ta) return;
1340
+ if (ta.value !== value) {
1341
+ const { selectionStart, selectionEnd } = ta;
1342
+ ta.value = value;
1343
+ ta.selectionStart = selectionStart;
1344
+ ta.selectionEnd = selectionEnd;
1345
+ }
1346
+ autoResize();
1347
+ }, [value, autoResize]);
1338
1348
  const updateCursorInfo = react.useCallback(() => {
1339
1349
  const ta = textareaRef.current;
1340
1350
  if (!ta) return;
@@ -1351,8 +1361,9 @@ function useEditorEngine({
1351
1361
  const ta = textareaRef.current;
1352
1362
  if (!ta) return;
1353
1363
  onChangeRef.current?.(ta.value);
1364
+ autoResize();
1354
1365
  updateCursorInfo();
1355
- }, [updateCursorInfo]);
1366
+ }, [autoResize, updateCursorInfo]);
1356
1367
  const handleSelect = react.useCallback(() => {
1357
1368
  updateCursorInfo();
1358
1369
  }, [updateCursorInfo]);
@@ -1412,6 +1423,7 @@ function useEditorEngine({
1412
1423
  ta.selectionStart = ta.selectionEnd = start + tabSize;
1413
1424
  onChangeRef.current?.(ta.value);
1414
1425
  }
1426
+ autoResize();
1415
1427
  updateCursorInfo();
1416
1428
  return;
1417
1429
  }
@@ -1430,11 +1442,12 @@ function useEditorEngine({
1430
1442
  ta.value = before + insertion + after;
1431
1443
  ta.selectionStart = ta.selectionEnd = start + insertion.length;
1432
1444
  onChangeRef.current?.(ta.value);
1445
+ autoResize();
1433
1446
  updateCursorInfo();
1434
1447
  return;
1435
1448
  }
1436
1449
  },
1437
- [readOnly, tabSize, updateCursorInfo]
1450
+ [readOnly, tabSize, autoResize, updateCursorInfo]
1438
1451
  );
1439
1452
  return {
1440
1453
  textareaRef,