<commit_before>import { autoinject, bindable, bindingMode, customElement, TaskQueue } from 'aurelia-framework';
import { getLogger, Logger } from 'aurelia-logging';
import { MDCTextfield } from '@material/textfield';
import * as util from '../../util';

@customElement('mdc-textfield')
@autoinject()
export class MdcTextfield {
  private static id = 0;
  @bindable({ defaultBindingMode: bindingMode.twoWay }) public value = '';
  @bindable({ defaultBindingMode: bindingMode.twoWay }) public focused = false;
  @bindable({ defaultBindingMode: bindingMode.oneTime }) public type = '';
  @bindable({ defaultBindingMode: bindingMode.oneTime }) public multiline = false;
  @bindable({ defaultBindingMode: bindingMode.oneTime }) public box = false;
  @bindable() public multilineRows = '8';
  @bindable() public multilineCols = '40';
  @bindable() public disabled = false;
  @bindable() public placeholder = '';
  @bindable() public ariaLabel = '';
  @bindable() public dense = false;
  @bindable() public fullwidth = false;
  @bindable() public required = false;
  @bindable() public pattern = '';
  @bindable() public helptext = '';
  @bindable() public helptextShow = false;
  @bindable() public helptextPersistent = false;
  @bindable() public helptextValidation = false;
  @bindable() public prefilled = false;
  @bindable() public min: number = null;
  @bindable() public max: number = null;
  @bindable() public step: number = null;
  @bindable() public name: string = null;
  private log: Logger;
  private controlId = '';
  private helptextId = '';
  private mdcTextfield;
  private elementLabel: HTMLLabelElement;
  private elementMain: HTMLDivElement;
  private elementHelpText: HTMLParagraphElement;
  private elementInput: HTMLInputElement | HTMLTextAreaElement;
  private styleHelptext = 'display: none;';
  private stopFocusedChanged = false;

  constructor(private element: Element, private taskQueue: TaskQueue) {
    this.controlId = `mdc-textfield-${MdcTextfield.id++}`;
    this.helptextId = `mdc-helptextfield-${MdcTextfield.id}`;
    this.log = getLogger('mdc-textfield');
  }

  public focus() {
    this.elementInput.focus();
  }

  public getNativeInput(): {value: string, disabled: boolean, badInput: boolean, checkValidity: () => boolean } {
    return this.mdcTextfield.foundation_.adapter_.getNativeInput();
  }

  private bind() { /** */ }
  private unbind() { /** */ }

  private attached() {
    this.boxChanged(this.box);
    this.multilineChanged(this.multiline);
    this.denseChanged(this.dense);
    this.fullwidthChanged(this.fullwidth);

    this.patternChanged(this.pattern);
    this.placeholderChanged(this.placeholder);
    this.ariaLabelChanged(this.ariaLabel);

    this.helptextPersistentChanged(this.helptextPersistent);
    this.helptextValidationChanged(this.helptextValidation);

    this.prefilledChanged(this.prefilled);

    this.mdcTextfield = new MDCTextfield(this.elementMain);

    this.helptextShowChanged(this.helptextShow);
    this.disabledChanged(this.disabled);
    this.focusedChanged(this.focused);

    this.mdcTextfield.foundation_.adapter_.registerInputBlurHandler(this.onBlur.bind(this));
    this.mdcTextfield.foundation_.adapter_.registerInputFocusHandler(this.onFocus.bind(this));
  }

  private detached() {
    this.mdcTextfield.foundation_.adapter_.deregisterInputFocusHandler(this.onFocus.bind(this));
    this.mdcTextfield.foundation_.adapter_.deregisterInputBlurHandler(this.onBlur.bind(this));
    this.mdcTextfield.destroy();
  }

  private valueChanged(newValue: string) {
    // TODO: validation if value is updated from other controls or script
    const isAbove = this.elementLabel.classList.contains('mdc-textfield__label--float-above');

    if (newValue && newValue.length > 0) {
      if (!isAbove) {
        this.elementLabel.classList.add('mdc-textfield__label--float-above');
      }
    } else {
      if (isAbove) {
        this.elementLabel.classList.remove('mdc-textfield__label--float-above');
      }
    }
  }

  private focusedChanged(newValue) {
    // do not focus or blur if focused variable
    // is changed from focus or blur events.
    if (this.stopFocusedChanged) {
      this.stopFocusedChanged = false;
      return;
    }
    if (util.getBoolean(newValue)) {
      this.taskQueue.queueTask(() => {
        if (this.elementInput) {<commit_msg>fix(mdc-textfield): use the new registerInputInteractionHandler for registering blur & focus handlers<commit_after>import { autoinject, bindable, bindingMode, customElement, TaskQueue } from 'aurelia-framework';
import { getLogger, Logger } from 'aurelia-logging';
import { MDCTextfield } from '@material/textfield';
import * as util from '../../util';

@customElement('mdc-textfield')
@autoinject()
export class MdcTextfield {
  private static id = 0;
  @bindable({ defaultBindingMode: bindingMode.twoWay }) public value = '';
  @bindable({ defaultBindingMode: bindingMode.twoWay }) public focused = false;
  @bindable({ defaultBindingMode: bindingMode.oneTime }) public type = '';
  @bindable({ defaultBindingMode: bindingMode.oneTime }) public multiline = false;
  @bindable({ defaultBindingMode: bindingMode.oneTime }) public box = false;
  @bindable() public multilineRows = '8';
  @bindable() public multilineCols = '40';
  @bindable() public disabled = false;
  @bindable() public placeholder = '';
  @bindable() public ariaLabel = '';
  @bindable() public dense = false;
  @bindable() public fullwidth = false;
  @bindable() public required = false;
  @bindable() public pattern = '';
  @bindable() public helptext = '';
  @bindable() public helptextShow = false;
  @bindable() public helptextPersistent = false;
  @bindable() public helptextValidation = false;
  @bindable() public prefilled = false;
  @bindable() public min: number = null;
  @bindable() public max: number = null;
  @bindable() public step: number = null;
  @bindable() public name: string = null;
  private log: Logger;
  private controlId = '';
  private helptextId = '';
  private mdcTextfield;
  private elementLabel: HTMLLabelElement;
  private elementMain: HTMLDivElement;
  private elementHelpText: HTMLParagraphElement;
  private elementInput: HTMLInputElement | HTMLTextAreaElement;
  private styleHelptext = 'display: none;';
  private stopFocusedChanged = false;

  constructor(private element: Element, private taskQueue: TaskQueue) {
    this.controlId = `mdc-textfield-${MdcTextfield.id++}`;
    this.helptextId = `mdc-helptextfield-${MdcTextfield.id}`;
    this.log = getLogger('mdc-textfield');
  }

  public focus() {
    this.elementInput.focus();
  }

  public getNativeInput(): {value: string, disabled: boolean, badInput: boolean, checkValidity: () => boolean } {
    return this.mdcTextfield.foundation_.adapter_.getNativeInput();
  }

  private bind() { /** */ }
  private unbind() { /** */ }

  private attached() {
    this.boxChanged(this.box);
    this.multilineChanged(this.multiline);
    this.denseChanged(this.dense);
    this.fullwidthChanged(this.fullwidth);

    this.patternChanged(this.pattern);
    this.placeholderChanged(this.placeholder);
    this.ariaLabelChanged(this.ariaLabel);

    this.helptextPersistentChanged(this.helptextPersistent);
    this.helptextValidationChanged(this.helptextValidation);

    this.prefilledChanged(this.prefilled);

    this.mdcTextfield = new MDCTextfield(this.elementMain);

    this.helptextShowChanged(this.helptextShow);
    this.disabledChanged(this.disabled);
    this.focusedChanged(this.focused);

    this.mdcTextfield.foundation_.adapter_.registerInputInteractionHandler('blur', this.onBlur.bind(this));
    this.mdcTextfield.foundation_.adapter_.registerInputInteractionHandler('focus', this.onFocus.bind(this));
  }

  private detached() {
    this.mdcTextfield.foundation_.adapter_.deregisterInputInteractionHandler('focus', this.onFocus.bind(this));
    this.mdcTextfield.foundation_.adapter_.deregisterInputInteractionHandler('blur', this.onBlur.bind(this));
    this.mdcTextfield.destroy();
  }

  private valueChanged(newValue: string) {
    // TODO: validation if value is updated from other controls or script
    const isAbove = this.elementLabel.classList.contains('mdc-textfield__label--float-above');

    if (newValue && newValue.length > 0) {
      if (!isAbove) {
        this.elementLabel.classList.add('mdc-textfield__label--float-above');
      }
    } else {
      if (isAbove) {
        this.elementLabel.classList.remove('mdc-textfield__label--float-above');
      }
    }
  }

  private focusedChanged(newValue) {
    // do not focus or blur if focused variable
    // is changed from focus or blur events.
    if (this.stopFocusedChanged) {
      this.stopFocusedChanged = false;
      return;
    }
    if (util.getBoolean(newValue)) {
      this.taskQueue.queueTask(() => {
        if (this.elementInput) {
{'fraction_non_alphanumeric': 0.126328884867677, 'fraction_numerical': 0.001130965844831486, 'mean_word_length': 4.41187270501836, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5382791', 'n_tokens_mistral': 2676, 'n_tokens_neox': 2635, 'n_words': 555}