<commit_before>import React from "react";
import PropTypes from "prop-types";

class MentionPortal extends React.Component {
  static propTypes = {
    close: PropTypes.func.isRequired,
    closeOnClick: PropTypes.bool.isRequired,
    closeOnEsc: PropTypes.bool.isRequired
  };

  static defaultProps = {
    closeOnEsc: true,
    closeOnClick: true
  };

  onDocumentClick = e => {
    this.props.closeOnClick && this.props.close();
  };

  onDocumentEsc = e => {
    if (this.props.closeOnEsc && event.keyCode === 27) {
      this.props.close();
    }
  };

  componentDidMount() {
    if (document) {
      document.addEventListener("click", this.onDocumentClick);
      document.addEventListener("keyup", this.onDocumentEsc);
    }
  }

  componentWillUnmount() {
    if (document) {
      document.removeEventListener("click", this.onDocumentClick);
      document.removeEventListener("keyup", this.onDocumentEsc);
    }
  }

  render() {
    return this.props.children;
  }
}

export default MentionPortal;
<commit_msg>fix keydown<commit_after>import React from "react";
import ReactDom from "react-dom";
import PropTypes from "prop-types";

class SimpleMentionPortal extends React.Component {
  static propTypes = {
    close: PropTypes.func.isRequired,
    closeOnClick: PropTypes.bool.isRequired,
    closeOnEsc: PropTypes.bool.isRequired
  };

  static defaultProps = {
    closeOnEsc: true,
    closeOnClick: true
  };

  onDocumentClick = e => {
    this.props.closeOnClick && this.props.close();
  };

  onDocumentEsc = event => {
    if (this.props.closeOnEsc && event.keyCode === 27) {
      this.props.close();
    }
  };

  componentDidMount() {
    if (document) {
      document.addEventListener("click", this.onDocumentClick);
      document.addEventListener("keyup", this.onDocumentEsc);
    }
  }

  componentWillUnmount() {
    if (document) {
      document.removeEventListener("click", this.onDocumentClick);
      document.removeEventListener("keyup", this.onDocumentEsc);
    }
  }

  render() {
    return this.props.children;
  }
}

class ReactMentionPortal extends React.Component {
  componentWillMount() {
    this.portal = document.createElement("div");
    document.body.appendChild(this.portal);
  }
  componentWillUnmount() {
    document.body.removeChild(this.portal);
  }
  render() {
    return ReactDOM.createPortal(
      <SimpleMentionPortal {...this.props}>
        {this.props.children}
      </SimpleMentionPortal>,
      this.portal
    );
  }
}

export default SimpleMentionPortal;

export { ReactMentionPortal };

{'fraction_non_alphanumeric': 0.1253416634127294, 'fraction_numerical': 0.0015618898867629833, 'mean_word_length': 3.3945111492281304, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '6112922', 'n_tokens_mistral': 798, 'n_tokens_neox': 781, 'n_words': 139}