@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.js CHANGED
@@ -108,10 +108,11 @@ function CodeEditorPanel({ className }) {
108
108
  "textarea",
109
109
  {
110
110
  ref: textareaRef,
111
- 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",
111
+ 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",
112
112
  style: {
113
113
  caretColor: themeColors.cursorColor,
114
114
  minHeight: _minHeight ? _minHeight - 40 : 80,
115
+ overflow: "hidden",
115
116
  whiteSpace: wordWrap ? "pre-wrap" : "pre",
116
117
  overflowWrap: wordWrap ? "break-word" : "normal"
117
118
  },
@@ -1325,14 +1326,23 @@ function useEditorEngine({
1325
1326
  }
1326
1327
  return count;
1327
1328
  }, [value]);
1329
+ const autoResize = useCallback(() => {
1330
+ const ta = textareaRef.current;
1331
+ if (!ta) return;
1332
+ ta.style.height = "auto";
1333
+ ta.style.height = ta.scrollHeight + "px";
1334
+ }, []);
1328
1335
  useEffect(() => {
1329
1336
  const ta = textareaRef.current;
1330
- if (!ta || ta.value === value) return;
1331
- const { selectionStart, selectionEnd } = ta;
1332
- ta.value = value;
1333
- ta.selectionStart = selectionStart;
1334
- ta.selectionEnd = selectionEnd;
1335
- }, [value]);
1337
+ if (!ta) return;
1338
+ if (ta.value !== value) {
1339
+ const { selectionStart, selectionEnd } = ta;
1340
+ ta.value = value;
1341
+ ta.selectionStart = selectionStart;
1342
+ ta.selectionEnd = selectionEnd;
1343
+ }
1344
+ autoResize();
1345
+ }, [value, autoResize]);
1336
1346
  const updateCursorInfo = useCallback(() => {
1337
1347
  const ta = textareaRef.current;
1338
1348
  if (!ta) return;
@@ -1349,8 +1359,9 @@ function useEditorEngine({
1349
1359
  const ta = textareaRef.current;
1350
1360
  if (!ta) return;
1351
1361
  onChangeRef.current?.(ta.value);
1362
+ autoResize();
1352
1363
  updateCursorInfo();
1353
- }, [updateCursorInfo]);
1364
+ }, [autoResize, updateCursorInfo]);
1354
1365
  const handleSelect = useCallback(() => {
1355
1366
  updateCursorInfo();
1356
1367
  }, [updateCursorInfo]);
@@ -1410,6 +1421,7 @@ function useEditorEngine({
1410
1421
  ta.selectionStart = ta.selectionEnd = start + tabSize;
1411
1422
  onChangeRef.current?.(ta.value);
1412
1423
  }
1424
+ autoResize();
1413
1425
  updateCursorInfo();
1414
1426
  return;
1415
1427
  }
@@ -1428,11 +1440,12 @@ function useEditorEngine({
1428
1440
  ta.value = before + insertion + after;
1429
1441
  ta.selectionStart = ta.selectionEnd = start + insertion.length;
1430
1442
  onChangeRef.current?.(ta.value);
1443
+ autoResize();
1431
1444
  updateCursorInfo();
1432
1445
  return;
1433
1446
  }
1434
1447
  },
1435
- [readOnly, tabSize, updateCursorInfo]
1448
+ [readOnly, tabSize, autoResize, updateCursorInfo]
1436
1449
  );
1437
1450
  return {
1438
1451
  textareaRef,