<commit_before>import * as React from "react";

interface BIProps {
  value: string | number;
  onCommit(e: React.SyntheticEvent<HTMLInputElement>): void;
  min?: number;
  max?: number;
  type?:
  | "text"
  | "number"
  | "email"
  | "password"
  | "time"
  | "date"
  | "hidden";
  name?: string;
  id?: string;
  /** Allow the user to empty out the form control. If unset, form control
   * will reset itself to previous value. */
  allowEmpty?: boolean;
  disabled?: boolean;
  className?: string;
  placeholder?: string;
  hidden?: boolean;
}

interface BIState {
  buffer: string;
  isEditing: boolean;
}

export class BlurableInput extends React.Component<BIProps, Partial<BIState>> {

  state: BIState = { buffer: "", isEditing: false };

  /** Called on blur. */
  maybeCommit = (e: React.SyntheticEvent<HTMLInputElement>) => {
    const shouldPassToParent = (this.state.buffer || (this.props.allowEmpty));
    if (shouldPassToParent) { this.props.onCommit(e); }
    this.setState({ isEditing: false, buffer: "" });
  }

  focus = () => {
    const { value } = this.props;
    this.setState({ isEditing: true, buffer: "" + (value || "") });
  }

  updateBuffer = (e: React.SyntheticEvent<HTMLInputElement>) => {
    const buffer = e.currentTarget.value;
    this.setState({ buffer });
  }

  defaultProps = () => {
    const value = this.state.isEditing ?
      this.state.buffer : this.props.value;
    return {
      value: value,
      hidden: !!this.props.hidden,
      onFocus: this.focus,
      onChange: this.updateBuffer,
      onSubmit: this.maybeCommit,
      onBlur: this.maybeCommit,
      name: this.props.name,
      id: this.props.id,
      type: this.props.type || "text",
      disabled: this.props.disabled,
      className: this.props.className,
      placeholder: this.props.placeholder,
    };
  }

  render() {
    return <input {...this.defaultProps() } />;
  }
}<commit_msg>[UNSTABLE] Test warnings gone. NEXT: Add error boundary?<commit_after>import * as React from "react";

interface BIProps {
  value: string | number;
  onCommit(e: React.SyntheticEvent<HTMLInputElement>): void;
  min?: number;
  max?: number;
  type?:
  | "text"
  | "number"
  | "email"
  | "password"
  | "time"
  | "date"
  | "hidden";
  name?: string;
  id?: string;
  /** Allow the user to empty out the form control. If unset, form control
   * will reset itself to previous value. */
  allowEmpty?: boolean;
  disabled?: boolean;
  className?: string;
  placeholder?: string;
  hidden?: boolean;
}

interface BIState {
  buffer: string;
  isEditing: boolean;
}

export class BlurableInput extends React.Component<BIProps, Partial<BIState>> {

  state: BIState = { buffer: "", isEditing: false };

  /** Called on blur. */
  maybeCommit = (e: React.SyntheticEvent<HTMLInputElement>) => {
    const shouldPassToParent = (this.state.buffer || (this.props.allowEmpty));
    if (shouldPassToParent) { this.props.onCommit(e); }
    this.setState({ isEditing: false, buffer: "" });
  }

  focus = () => {
    const { value } = this.props;
    this.setState({ isEditing: true, buffer: "" + (value || "") });
  }

  updateBuffer = (e: React.SyntheticEvent<HTMLInputElement>) => {
    const buffer = e.currentTarget.value;
    this.setState({ buffer });
  }

  usualProps = () => {
    const value = this.state.isEditing ?
      this.state.buffer : this.props.value;
    return {
      value: value,
      hidden: !!this.props.hidden,
      onFocus: this.focus,
      onChange: this.updateBuffer,
      onSubmit: this.maybeCommit,
      onBlur: this.maybeCommit,
      name: this.props.name,
      id: this.props.id,
      type: this.props.type || "text",
      disabled: this.props.disabled,
      className: this.props.className,
      placeholder: this.props.placeholder,
    };
  }

  render() {
    return <input {...this.usualProps() } />;
  }
}
{'fraction_non_alphanumeric': 0.15071335927367055, 'fraction_numerical': 0.0, 'mean_word_length': 3.097768331562168, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3077424', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1245, 'n_words': 297}