<commit_before>var React = require('react');
var util = require('./util');
var QRCodeDialog = require('./qrcode-dialog');
var storage = require('./storage');

var NOT_EMPTY_RE = /[^\s]/;
var MAX_QRCODE_LEN = 2048;
var MAX_JSON_LEN = 32768;

var ToolBox = React.createClass({
  getInitialState: function() {
    return {
      qrcodeValue: util.toString(storage.get('qrcodeValue')).substring(0, MAX_QRCODE_LEN)
    };
  },
  _saveQRCodeChange: function() {
    storage.set('qrcodeValue', this.state.qrcodeValue);
  },
  saveQRCodeChange: function() {
    clearTimeout(this.qrcodeTimer);
    this.qrcodeTimer = setTimeout(this._saveQRCodeChange, 1000);
  },
  generageQRCode: function() {
    this.refs.qrcodeDialog.show(this.state.qrcodeValue);
  },
  onQRCodeChange: function(e) {
    this.setState({
      qrcodeValue: e.target.value
    }, this.saveQRCodeChange);
  },
  shouldComponentUpdate: function(nextProps) {
    var hide = util.getBoolean(this.props.hide);
    return hide != util.getBoolean(nextProps.hide) || !hide;
  },
  render: function() {
    var state = this.state;
    var qrcodeValue = state.qrcodeValue;
    return (
      <div className={'fill orient-vertical-box w-tool-box ' + (this.props.hide ? 'hide' : '')}>
        <div className="w-detail-inspectors-title">
          QR Code
          <button className="btn btn-primary" disabled={!NOT_EMPTY_RE.test(qrcodeValue)}
          onClick={this.generageQRCode}>Generate</button>
        </div>
        <textarea onChange={this.onQRCodeChange} value={qrcodeValue} className="w-tool-box-ctn"
          maxLength={MAX_QRCODE_LEN} placeholder="Input the URL" />
        <div className="w-detail-inspectors-title">
          JSON View
          <button className="btn btn-primary">Parse</button>
        </div>
        <textarea className="w-tool-box-ctn" maxLength={MAX_JSON_LEN} placeholder="Input the JSON text" />
        <div className="w-detail-inspectors-title">
          URL Data
        </div>
        <button className="w-tool-box-ctn w-tool-box-base64">
          <span className="glyphicon glyphicon-arrow-up"></span>
          Click here to upload image (size &lt;= 256k)<commit_msg>style: refine JSON View<commit_after>var React = require('react');
var util = require('./util');
var QRCodeDialog = require('./qrcode-dialog');
var storage = require('./storage');

var NOT_EMPTY_RE = /[^\s]/;
var MAX_QRCODE_LEN = 2048;
var MAX_JSON_LEN = 32768;
var MAX_SAVE_LEN = 5120;

var ToolBox = React.createClass({
  getInitialState: function() {
    return {
      qrcodeValue: util.toString(storage.get('qrcodeValue')).substring(0, MAX_QRCODE_LEN),
      jsonValue: util.toString(storage.get('jsonValue')).substring(0, MAX_SAVE_LEN)
    };
  },
  _saveQRCodeValue: function() {
    storage.set('qrcodeValue', this.state.qrcodeValue);
  },
  saveQRCodeValue: function() {
    clearTimeout(this.qrcodeTimer);
    this.qrcodeTimer = setTimeout(this._saveQRCodeValue, 1000);
  },
  _saveJSONValue: function() {
    var value = this.state.jsonValue;
    if (value.length <= MAX_SAVE_LEN) {
      storage.set('jsonValue', value);
    }
  },
  saveJSONValue: function() {
    clearTimeout(this.jsonTimer);
    this.jsonTimer = setTimeout(this._saveJSONValue, 1000);
  },
  onJSONChange: function(e) {
    this.setState({
      jsonValue: e.target.value
    }, this._saveJSONValue);
  },
  generageQRCode: function() {
    this.refs.qrcodeDialog.show(this.state.qrcodeValue);
  },
  parseJSON: function() {
    alert(this.state.jsonValue);
  },
  onQRCodeChange: function(e) {
    this.setState({
      qrcodeValue: e.target.value
    }, this.saveQRCodeValue);
  },
  shouldComponentUpdate: function(nextProps) {
    var hide = util.getBoolean(this.props.hide);
    return hide != util.getBoolean(nextProps.hide) || !hide;
  },
  render: function() {
    var state = this.state;
    var qrcodeValue = state.qrcodeValue;
    var jsonValue = state.jsonValue;
    return (
      <div className={'fill orient-vertical-box w-tool-box ' + (this.props.hide ? 'hide' : '')}>
        <div className="w-detail-inspectors-title">
          QR Code
          <button className="btn btn-primary" disabled={!NOT_EMPTY_RE.test(qrcodeValue)}
          onClick={this.generageQRCode}>Generate</button>
        </div>
        <textarea onChange={this.onQRCodeChange} value={qrcodeValue} className="w-tool-box-ctn"
          maxLength={MAX_QRCODE_LEN} placeholder="Input the URL" />
        <div className="w-detail-inspectors-title">
          JSON View
          <button className="btn btn-primary" disabled={!NOT_EMPTY_RE.test(jsonValue)}
            onClick={this.parseJSON}>Parse</button>
        </div>
        <textarea onChange={this.onJSONChange} value={jsonValue} className="w-tool-box-ctn"
          maxLength={MAX_JSON_LEN} placeholder="Input the JSON text" />
        <div className="w-detail-inspectors-title">
          URL Data
        </div>
        <button className="w-tool-box-ctn w-tool-box-base64">
          <span className="glyphicon glyphicon-arrow-up"></span>
          Click here to upload image (size &lt;= 1m)
{'fraction_non_alphanumeric': 0.1453579858379229, 'fraction_numerical': 0.00885129819040126, 'mean_word_length': 3.3461538461538463, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 35, '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': '7040185', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1620, 'n_words': 290}