<commit_before>/* tslint:disable:jsx-no-multiline-js */
import React from 'react';
import ReactDOM from 'react-dom';
import classnames from 'classnames';
import CustomKeyboard from './CustomKeyboard';
import { addClass, removeClass } from '../_util/class';

const IS_REACT_16 = !!(ReactDOM as any).createPortal;

class NumberInput extends React.Component<any, any> {

  static defaultProps = {
    onChange: () => { },
    onFocus: () => { },
    onBlur: () => { },
    placeholder: '',
    disabled: false,
    editable: true,
    prefixCls: 'am-input',
    keyboardPrefixCls: 'am-number-keyboard',
  };

  private container: any;
  private inputRef: any;

  constructor(props) {
    super(props);
    this.state = {
      focus: false,
      value: props.value || '',
    };
  }

  onChange = (value) => {
    if (!('value' in this.props)) {
      this.setState({ value: value.target.value });
    }
    this.props.onChange(value);
  }

  componentWillReceiveProps(nextProps) {
    if ('value' in nextProps) {
      this.setState({
        value: nextProps.value,
      });
    }
  }

  componentDidMount() {
    if (!IS_REACT_16 && !(window as any).antmCustomKeyboard) {
      this.renderCustomKeyboard();
    }
  }
  addBlurListener = () => {
    document.addEventListener('click', this.doBlur, false);
  }
  removeBlurListen = () => {
    document.removeEventListener('click', this.doBlur, false);
  }
  componentWillUnmount() {
    this.unLinkInput();
  }

  saveRef = (el) => {
    if (IS_REACT_16) {
      (window as any).antmCustomKeyboard = el;
    }
  }

  getComponent() {
    const { keyboardPrefixCls, confirmLabel } = this.props;

    return (<CustomKeyboard
      ref={this.saveRef}
      onClick={this.onKeyboardClick}
      preixCls={keyboardPrefixCls}
      confirmLabel={confirmLabel}
    />);
  }

  getContainer() {
    let container = document.querySelector(`#${this.props.keyboardPrefixCls}-container`);
    if (!container) {
      container = document.createElement('div');
      container.setAttribute('id', `${this.props.keyboardPrefixCls}-container`);
      document.body.appendChild(container);
    }
    this.container = container;
    return container;
  }

  renderCustomKeyboard() {
    if (!this.container) {
      (window as any).antmCustomKeyboard = ReactDOM.unstable_renderSubtreeIntoContainer(
        this,
        this.getComponent(),
        this.getContainer(),
      );
    }
  }

  doBlur = (ev) => {
    const { value } = this.state;
    if (ev.target !== this.inputRef) {
      this.onInputBlur(value);
    }
  }

  unLinkInput = () => {
    const antmCustomKeyboard = (window as any).antmCustomKeyboard;
    if (antmCustomKeyboard.linkedInput === this) {
      antmCustomKeyboard.linkedInput = null;
      addClass(antmCustomKeyboard.antmKeyboard, `${this.props.keyboardPrefixCls}-wrapper-hide`);
      this.removeBlurListen();
    }
  }

  onInputBlur = (value) => {<commit_msg>fix: input-item type money unmount bug, close #2040<commit_after>/* tslint:disable:jsx-no-multiline-js */
import React from 'react';
import ReactDOM from 'react-dom';
import classnames from 'classnames';
import CustomKeyboard from './CustomKeyboard';
import { addClass, removeClass } from '../_util/class';

const IS_REACT_16 = !!(ReactDOM as any).createPortal;

class NumberInput extends React.Component<any, any> {

  static defaultProps = {
    onChange: () => { },
    onFocus: () => { },
    onBlur: () => { },
    placeholder: '',
    disabled: false,
    editable: true,
    prefixCls: 'am-input',
    keyboardPrefixCls: 'am-number-keyboard',
  };

  private container: any;
  private inputRef: any;

  constructor(props) {
    super(props);
    this.state = {
      focus: false,
      value: props.value || '',
    };
  }

  onChange = (value) => {
    if (!('value' in this.props)) {
      this.setState({ value: value.target.value });
    }
    this.props.onChange(value);
  }

  componentWillReceiveProps(nextProps) {
    if ('value' in nextProps) {
      this.setState({
        value: nextProps.value,
      });
    }
  }

  componentDidMount() {
    if (!IS_REACT_16 && !(window as any).antmCustomKeyboard) {
      this.renderCustomKeyboard();
    }
  }
  addBlurListener = () => {
    document.addEventListener('click', this.doBlur, false);
  }
  removeBlurListen = () => {
    document.removeEventListener('click', this.doBlur, false);
  }
  componentWillUnmount() {
    this.unLinkInput();
  }

  saveRef = (el) => {
    if (IS_REACT_16) {
      (window as any).antmCustomKeyboard = el;
    }
  }

  getComponent() {
    const { keyboardPrefixCls, confirmLabel } = this.props;

    return (<CustomKeyboard
      ref={this.saveRef}
      onClick={this.onKeyboardClick}
      preixCls={keyboardPrefixCls}
      confirmLabel={confirmLabel}
    />);
  }

  getContainer() {
    let container = document.querySelector(`#${this.props.keyboardPrefixCls}-container`);
    if (!container) {
      container = document.createElement('div');
      container.setAttribute('id', `${this.props.keyboardPrefixCls}-container`);
      document.body.appendChild(container);
    }
    this.container = container;
    return container;
  }

  renderCustomKeyboard() {
    if (!this.container) {
      (window as any).antmCustomKeyboard = ReactDOM.unstable_renderSubtreeIntoContainer(
        this,
        this.getComponent(),
        this.getContainer(),
      );
    }
  }

  doBlur = (ev) => {
    const { value } = this.state;
    if (ev.target !== this.inputRef) {
      this.onInputBlur(value);
    }
  }

  unLinkInput = () => {
    const antmCustomKeyboard = (window as any).antmCustomKeyboard;
    if (antmCustomKeyboard && antmCustomKeyboard.linkedInput && antmCustomKeyboard.linkedInput === this) {
      antmCustomKeyboard.linkedInput = null;
      addClass(antmCustomKeyboard.antmKeyboard, `${this.props.keyboardPrefixCls}-wrapper-hide`);
      this.removeBlurListen();
    }
  }

  onInputBlur = (value) => {
{'fraction_non_alphanumeric': 0.14581231079717458, 'fraction_numerical': 0.0026908846283215607, 'mean_word_length': 3.067715458276334, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, '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': '6596960', 'n_tokens_mistral': 1896, 'n_tokens_neox': 1911, 'n_words': 337}