@zhongqian97-code/ecode 0.2.0 → 0.2.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.
Files changed (2) hide show
  1. package/dist/index.js +18 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -639,8 +639,12 @@ var BLINK_INTERVAL_MS = 530;
639
639
  var Input = forwardRef(function Input2({ isActive, onSubmit, onChange, placeholder }, ref) {
640
640
  const [lines, setLines] = useState2([""]);
641
641
  const [cursorVisible, setCursorVisible] = useState2(true);
642
+ const linesRef = useRef(lines);
643
+ linesRef.current = lines;
642
644
  const onChangeRef = useRef(onChange);
643
645
  onChangeRef.current = onChange;
646
+ const onSubmitRef = useRef(onSubmit);
647
+ onSubmitRef.current = onSubmit;
644
648
  useImperativeHandle(ref, () => ({
645
649
  fill(text) {
646
650
  const newLines = text ? text.split("\n") : [""];
@@ -662,41 +666,42 @@ var Input = forwardRef(function Input2({ isActive, onSubmit, onChange, placehold
662
666
  }, [isActive]);
663
667
  useInput(
664
668
  (input, key) => {
669
+ const currentLines = linesRef.current;
665
670
  if (key.return && key.shift) {
666
- const newLines = [...lines, ""];
671
+ const newLines = [...currentLines, ""];
667
672
  setLines(newLines);
668
- onChange?.(newLines.join("\n"));
673
+ onChangeRef.current?.(newLines.join("\n"));
669
674
  return;
670
675
  }
671
676
  if (key.return) {
672
- const text = lines.join("\n");
673
- onSubmit(text);
677
+ const text = currentLines.join("\n");
678
+ onSubmitRef.current(text);
674
679
  setLines([""]);
675
- onChange?.("");
680
+ onChangeRef.current?.("");
676
681
  return;
677
682
  }
678
683
  if (key.backspace || key.delete) {
679
- const lastIdx = lines.length - 1;
680
- const lastLine = lines[lastIdx];
684
+ const lastIdx = currentLines.length - 1;
685
+ const lastLine = currentLines[lastIdx];
681
686
  let newLines;
682
687
  if (lastLine.length > 0) {
683
- newLines = [...lines.slice(0, lastIdx), lastLine.slice(0, -1)];
684
- } else if (lines.length > 1) {
685
- newLines = lines.slice(0, -1);
688
+ newLines = [...currentLines.slice(0, lastIdx), lastLine.slice(0, -1)];
689
+ } else if (currentLines.length > 1) {
690
+ newLines = currentLines.slice(0, -1);
686
691
  } else {
687
692
  return;
688
693
  }
689
694
  setLines(newLines);
690
- onChange?.(newLines.join("\n"));
695
+ onChangeRef.current?.(newLines.join("\n"));
691
696
  return;
692
697
  }
693
698
  if (key.ctrl || key.escape || key.upArrow || key.downArrow || key.leftArrow || key.rightArrow || key.tab || key.pageUp || key.pageDown) {
694
699
  return;
695
700
  }
696
701
  if (input.length > 0) {
697
- const newLines = [...lines.slice(0, -1), lines[lines.length - 1] + input];
702
+ const newLines = [...currentLines.slice(0, -1), currentLines[currentLines.length - 1] + input];
698
703
  setLines(newLines);
699
- onChange?.(newLines.join("\n"));
704
+ onChangeRef.current?.(newLines.join("\n"));
700
705
  }
701
706
  },
702
707
  { isActive }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhongqian97-code/ecode",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "A minimal Claude Code clone with REPL interface and bash tool calling",
5
5
  "type": "module",
6
6
  "author": "zhongqian97-code",