<commit_before>
/**
* Copyright (c) 2015 ZenPayroll
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import {getSelection, setSelection} from './SelectionUtils';

const DEFAULT_TRANSLATIONS = {
  '9': /\d/,
  'a': /[A-Za-z]/,
  '*': /[A-Za-z0-9]/
};

const BLANK_CHAR = '_';

const MaskedField = React.createClass({
  propTypes: {
    mask: React.PropTypes.string,
    translations: React.PropTypes.object,
    value: React.PropTypes.string,
    placeholder: React.PropTypes.string,
    onChange: React.PropTypes.func,
    onKeyDown: React.PropTypes.func,
    onComplete: React.PropTypes.func,
    onFocus: React.PropTypes.func,
    onBlur: React.PropTypes.func,
    valueLink: React.PropTypes.object
  },
  getInitialState() {
    if (!this.props.mask) {
      return null;
    }

    this._buffer = this._initialBuffer();
    this._cursorPos = this._firstNonMaskIdx;

    const propsValue = this._getPropsValue();
    return {
      // TODO: Any way we can do this in one pass?
      value: propsValue ? this._maskedValue(propsValue) : ''
    };
  },
  componentDidUpdate() {
    if (this._cursorPos !== undefined) {
      this._setSelection(this._cursorPos);
    }
  },
  componentDidMount() {
    this._isMounted = true;
    const propsValue = this._getPropsValue();
    if (this.props.mask && typeof propsValue === 'string' && this.state.value !== propsValue) {
      this._callOnChange(this.state.value);
    }
  },
  componentWillUnmount() {
    this._isMounted = false;
  },
  render() {
    let props = {};
    if (this.props.mask) {
      props = {
        onChange: this._handleChange,
        onKeyDown: this._handleKeyDown,<commit_msg>reinit value and buffer on mask change<commit_after>
/**
* Copyright (c) 2015 ZenPayroll
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import {getSelection, setSelection} from './SelectionUtils';

const DEFAULT_TRANSLATIONS = {
  '9': /\d/,
  'a': /[A-Za-z]/,
  '*': /[A-Za-z0-9]/
};

const BLANK_CHAR = '_';

const MaskedField = React.createClass({
  propTypes: {
    mask: React.PropTypes.string,
    translations: React.PropTypes.object,
    value: React.PropTypes.string,
    placeholder: React.PropTypes.string,
    onChange: React.PropTypes.func,
    onKeyDown: React.PropTypes.func,
    onComplete: React.PropTypes.func,
    onFocus: React.PropTypes.func,
    onBlur: React.PropTypes.func,
    valueLink: React.PropTypes.object
  },
  getInitialState() {
    if (!this.props.mask) {
      return null;
    }

    this._buffer = this._initialBuffer();
    this._cursorPos = this._firstNonMaskIdx;

    const propsValue = this._getPropsValue();
    return {
      // TODO: Any way we can do this in one pass?
      value: propsValue ? this._maskedValue(propsValue) : ''
    };
  },
  componentWillReceiveProps(nextProps) {
    if (this.props.mask !== nextProps.mask) {
      this.setState({value: ''}, function () {this._buffer = this._initialBuffer()});
      this._cursorPos = this._firstNonMaskIdx;
    };
  },
  componentDidUpdate() {
    if (this._cursorPos !== undefined) {
      this._setSelection(this._cursorPos);
    }
  },
  componentDidMount() {
    this._isMounted = true;
    const propsValue = this._getPropsValue();
    if (this.props.mask && typeof propsValue === 'string' && this.state.value !== propsValue) {
      this._callOnChange(this.state.value);
    }
  },
  componentWillUnmount() {
    this._isMounted = false;
  },
  render() {
    let props = {};
    if (this.props.mask) {
      props = {
        onChange: this._handleChange,
        onKeyDown: this._handleKeyDown,
{'fraction_non_alphanumeric': 0.13611037410453702, 'fraction_numerical': 0.0037145131334571503, 'mean_word_length': 3.08008658008658, 'pattern_counts': {'":': 0, '<': 3, '<?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': '306757', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1202, 'n_words': 269}