<commit_before>// # Choices component

/*
Render customized (non-native) dropdown choices.
*/

'use strict';

var _keyCodeToDirection;

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var React = require('react');
var R = React.DOM;
var ReactDOM = require('react-dom');
var _ = require('../../undash');
var ScrollLock = require('react-scroll-lock');

var _require = require('../../utils');

var keyCodes = _require.keyCodes;
var scrollIntoContainerView = _require.scrollIntoContainerView;

var magicChoiceRe = /^\/\/\/[^\/]+\/\/\/$/;

var keyCodeToDirection = (_keyCodeToDirection = {}, _defineProperty(_keyCodeToDirection, keyCodes.UP, -1), _defineProperty(_keyCodeToDirection, keyCodes.DOWN, 1), _keyCodeToDirection);

var requestAnimationFrameThrottled = function requestAnimationFrameThrottled(frameCount, cb) {
  if (frameCount === undefined) frameCount = 1;

  if (frameCount < 1) {
    frameCount = 1;
  }
  var frameIndex = 0;
  var listenToFrame = function listenToFrame() {
    requestAnimationFrame(function () {
      frameIndex++;
      if (frameIndex === frameCount) {
        cb.apply(undefined, arguments);
      } else {
        listenToFrame();
      }
    });
  };
  listenToFrame();
};

module.exports = React.createClass({

  displayName: 'Choices',

  mixins: [require('../../mixins/helper'),
  //plugin.require('mixin.resize'),
  //plugin.require('mixin.scroll'),
  require('../../mixins/click-outside'), ScrollLock],

  getInitialState: function getInitialState() {
    return {
      maxHeight: null,
      open: this.props.open,
      searchString: '',
      hoverValue: null
    };
  },

  getIgnoreCloseNodes: function getIgnoreCloseNodes() {
    if (!this.props.ignoreCloseNodes) {
      return [];
    }
    var nodes = this.props.ignoreCloseNodes();
    if (!_.isArray(nodes)) {
      nodes = [nodes];
    }
    return nodes;
  },

  componentDidMount: function componentDidMount() {
    this.setOnClickOutside('container', (function (event) {

      // Make sure we don't find any nodes to ignore.
      if (!_.find(this.getIgnoreCloseNodes(), (function (node) {
        return this.isNodeInside(event.target, node);
      }).bind(this))) {
        this.onClose();
      }
    }).bind(this));

    if (this.refs.search) {
      this.refs.search.focus();
    }

    this.adjustSize();
    this.updateListeningToWindow();
  },

  componentWillUnmount: function componentWillUnmount() {
    this.stopListeningToWindow();
  },

  onSelect: function onSelect(choice, event) {
    this.setState({
      openSection: null,
      searchString: ''
    });
    this.props.onSelect(choice.value, event);
  },

  onChoiceAction: function onChoiceAction(choice) {
    this.setState({
      openSection: null,
      searchString: ''
    });
    this.props.onChoiceAction(choice);
  },

  onClose: function onClose() {
    this.setState({
      openSection: null,
      searchString: ''
    });
    this.props.onClose();
  },

  // Doing something a little crazy... measuring on every frame. Makes this smoother than using an interval.
  // Can't using scrolling events, because we might be scrolling inside a container instead of the body.
  // Shouldn't be any more costly than animations though, I think. And only one of these is open at a time.
  updateListeningToWindow: function updateListeningToWindow() {
    var _this = this;

    if (this.refs.choices) {<commit_msg>rebuild<commit_after>// # Choices component

/*
Render customized (non-native) dropdown choices.
*/

'use strict';

var _keyCodeToDirection;

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var React = require('react');
var R = React.DOM;
var ReactDOM = require('react-dom');
var _ = require('../../undash');
var ScrollLock = require('react-scroll-lock');

var _require = require('../../utils');

var keyCodes = _require.keyCodes;
var scrollIntoContainerView = _require.scrollIntoContainerView;

var magicChoiceRe = /^\/\/\/[^\/]+\/\/\/$/;

var keyCodeToDirection = (_keyCodeToDirection = {}, _defineProperty(_keyCodeToDirection, keyCodes.UP, -1), _defineProperty(_keyCodeToDirection, keyCodes.DOWN, 1), _keyCodeToDirection);

var requestAnimationFrameThrottled = function requestAnimationFrameThrottled(frameCount, cb) {
  if (frameCount === undefined) frameCount = 1;

  if (frameCount < 1) {
    frameCount = 1;
  }
  var frameIndex = 0;
  var listenToFrame = function listenToFrame() {
    requestAnimationFrame(function () {
      frameIndex++;
      if (frameIndex === frameCount) {
        cb.apply(undefined, arguments);
      } else {
        listenToFrame();
      }
    });
  };
  listenToFrame();
};

module.exports = React.createClass({

  displayName: 'Choices',

  mixins: [require('../../mixins/helper'),
  //plugin.require('mixin.resize'),
  //plugin.require('mixin.scroll'),
  require('../../mixins/click-outside'), ScrollLock],

  getInitialState: function getInitialState() {
    return {
      maxHeight: null,
      open: this.props.open,
      searchString: '',
      hoverValue: null
    };
  },

  getIgnoreCloseNodes: function getIgnoreCloseNodes() {
    if (!this.props.ignoreCloseNodes) {
      return [];
    }
    var nodes = this.props.ignoreCloseNodes();
    if (!_.isArray(nodes)) {
      nodes = [nodes];
    }
    return nodes;
  },

  componentDidMount: function componentDidMount() {
    this.setOnClickOutside('container', (function (event) {

      // Make sure we don't find any nodes to ignore.
      if (!_.find(this.getIgnoreCloseNodes(), (function (node) {
        return this.isNodeInside(event.target, node);
      }).bind(this))) {
        this.onClose();
      }
    }).bind(this));

    if (this.refs.search) {
      this.refs.search.focus();
    }

    this.adjustSize();
    this.updateListeningToWindow();
  },

  componentWillUnmount: function componentWillUnmount() {
    this.stopListeningToWindow();
  },

  onSelect: function onSelect(choice, event) {
    this.setState({
      openSection: null,
      searchString: ''
    });
    this.props.onSelect(choice.value, event);
  },

  onChoiceAction: function onChoiceAction(choice) {
    this.setState({
      openSection: null,
      searchString: choice.keepSearchString ? this.state.searchString : ''
    });
    this.props.onChoiceAction(choice);
  },

  onClose: function onClose() {
    this.setState({
      openSection: null,
      searchString: ''
    });
    this.props.onClose();
  },

  // Doing something a little crazy... measuring on every frame. Makes this smoother than using an interval.
  // Can't using scrolling events, because we might be scrolling inside a container instead of the body.
  // Shouldn't be any more costly than animations though, I think. And only one of these is open at a time.
  updateListeningToWindow: function updateListeningToWindow() {
    var _this = this;

    if (this.refs.choices) {
{'fraction_non_alphanumeric': 0.14151997764738755, 'fraction_numerical': 0.0016764459346186086, 'mean_word_length': 3.2919664268585134, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6632107', 'n_tokens_mistral': 2191, 'n_tokens_neox': 2126, 'n_words': 518}