<commit_before>import { Component, Input, Output, forwardRef, DoCheck, ViewChild, ViewChildren, QueryList, OnInit, HostListener,
  ElementRef, Optional, Inject, Directive, TemplateRef, ViewContainerRef, ContentChild, ChangeDetectionStrategy,
  ChangeDetectorRef, AfterViewInit, OnDestroy, HostBinding, Renderer2 } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
import { EventEmitter } from '@angular/core';
import { NG_VALUE_ACCESSOR, ControlValueAccessor, FormControl } from '@angular/forms';

import { TemplatePortalDirective } from '@angular/cdk/portal';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { UP_ARROW, DOWN_ARROW, ESCAPE, LEFT_ARROW, RIGHT_ARROW, DELETE, BACKSPACE, ENTER, SPACE, TAB, HOME } from '@angular/cdk/keycodes';
import { MatChip } from '@angular/material/chips';
import { MatInput } from '@angular/material/input';
import { MatOption } from '@angular/material/core';
import { MatAutocompleteTrigger } from '@angular/material/autocomplete';

import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import { timer } from 'rxjs/observable/timer';
import { merge } from 'rxjs/observable/merge';
import { toPromise } from 'rxjs/operator/toPromise';
import { fromEvent } from 'rxjs/observable/fromEvent';
import { filter } from 'rxjs/operators/filter';
import { debounceTime } from 'rxjs/operators/debounceTime';

import { ICanDisable, mixinDisabled } from '../common/common.module';

const noop: any = () => {
  // empty method
};

@Directive({
  selector: '[td-chip]ng-template',
})
export class TdChipDirective extends TemplatePortalDirective {
  constructor(templateRef: TemplateRef<any>, viewContainerRef: ViewContainerRef) {
    super(templateRef, viewContainerRef);
  }
}

@Directive({
  selector: '[td-autocomplete-option]ng-template',
})
export class TdAutocompleteOptionDirective extends TemplatePortalDirective {
  constructor(templateRef: TemplateRef<any>, viewContainerRef: ViewContainerRef) {
    super(templateRef, viewContainerRef);
  }
}

export class TdChipsBase {}

/* tslint:disable-next-line */
export const _TdChipsMixinBase = mixinDisabled(TdChipsBase);

@Component({
  providers: [{
    provide: NG_VALUE_ACCESSOR,
    useExisting: forwardRef(() => TdChipsComponent),
    multi: true,
  }],
  selector: 'td-chips',
  inputs: ['disabled'],
  styleUrls: ['./chips.component.scss' ],
  templateUrl: './chips.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TdChipsComponent extends _TdChipsMixinBase implements ControlValueAccessor, DoCheck, OnInit, AfterViewInit, OnDestroy, ICanDisable {

  private _outsideClickSubs: Subscription;

  private _isMousedown: boolean = false;

  /**
   * Implemented as part of ControlValueAccessor.
   */
  private _value: any[] = [];

  private _items: any[];
  private _length: number = 0;
  private _stacked: boolean = false;
  private _requireMatch: boolean = false;
  private _color: 'primary' | 'accent' | 'warn' = 'primary';
  private _chipAddition: boolean = true;
  private _chipRemoval: boolean = true;
  private _focused: boolean = false;
  private _tabIndex: number = 0;

  _internalClick: boolean = false;

  @ViewChild('input') _nativeInput: ElementRef;
  @ViewChild(MatInput) _inputChild: MatInput;
  @ViewChild(MatAutocompleteTrigger) _autocompleteTrigger: MatAutocompleteTrigger;
  @ViewChildren(MatChip) _chipsChildren: QueryList<MatChip>;

  @ContentChild(TdChipDirective) _chipTemplate: TdChipDirective;
  @ContentChild(TdAutocompleteOptionDirective) _autocompleteOptionTemplate: TdAutocompleteOptionDirective;

  @ViewChildren(MatOption) _options: QueryList<MatOption>;

  /**
   * Flag that is true when autocomplete is focused.
   */
  get focused(): boolean {
    return this._focused;
  }

  /**
   * FormControl for the matInput element.
   */
  inputControl: FormControl = new FormControl();

  /**
   * items?: any[]
   * Renders the `mat-autocomplete` with the provided list to display as options.
   */
  @Input('items')
  set items(items: any[]) {
    this._items = items;
    this._setFirstOptionActive();
    this._changeDetectorRef.markForCheck();
  }
  get items(): any[] {
    return this._items;
  }

  /**
   * stacked?: boolean
   * Set stacked or horizontal chips depending on value.
   * Defaults to false.
   */
  @Input('stacked')
  set stacked(stacked: boolean) {
    this._stacked = coerceBooleanProperty(stacked);
  }
  get stacked(): boolean {
    return this._stacked;
  }
  
  /**
   * requireMatch?: boolean
   * Blocks custom inputs and only allows selections from the autocomplete list.
   */
  @Input('requireMatch')
  set requireMatch(requireMatch: boolean) {
    this._requireMatch = coerceBooleanProperty(requireMatch);
  }
  get requireMatch(): boolean {
    return this._requireMatch;
  }

  /**
   * @deprecated 1.0.0@beta.6
   * readOnly?: boolean
   * Disables the chips input and chip removal icon.
   */
  @Input('readOnly')
  set readOnly(readOnly: boolean) {
    this.disabled = readOnly;
  }

  /**
   * chipAddition?: boolean
   * Disables the ability to add chips. When setting disabled as true, this will be overriden.
   * Defaults to true.
   */
  @Input('chipAddition')
  set chipAddition(chipAddition: boolean) {
    this._chipAddition = chipAddition;
    this._toggleInput();
  }
  get chipAddition(): boolean {
    return this._chipAddition;
  }

  /**
   * Checks if not in disabled state and if chipAddition is set to 'true'<commit_msg>chore(chips): remove deprecated `readOnly` input (#1027)<commit_after>import { Component, Input, Output, forwardRef, DoCheck, ViewChild, ViewChildren, QueryList, OnInit, HostListener,
  ElementRef, Optional, Inject, Directive, TemplateRef, ViewContainerRef, ContentChild, ChangeDetectionStrategy,
  ChangeDetectorRef, AfterViewInit, OnDestroy, HostBinding, Renderer2 } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
import { EventEmitter } from '@angular/core';
import { NG_VALUE_ACCESSOR, ControlValueAccessor, FormControl } from '@angular/forms';

import { TemplatePortalDirective } from '@angular/cdk/portal';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { UP_ARROW, DOWN_ARROW, ESCAPE, LEFT_ARROW, RIGHT_ARROW, DELETE, BACKSPACE, ENTER, SPACE, TAB, HOME } from '@angular/cdk/keycodes';
import { MatChip } from '@angular/material/chips';
import { MatInput } from '@angular/material/input';
import { MatOption } from '@angular/material/core';
import { MatAutocompleteTrigger } from '@angular/material/autocomplete';

import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import { timer } from 'rxjs/observable/timer';
import { merge } from 'rxjs/observable/merge';
import { toPromise } from 'rxjs/operator/toPromise';
import { fromEvent } from 'rxjs/observable/fromEvent';
import { filter } from 'rxjs/operators/filter';
import { debounceTime } from 'rxjs/operators/debounceTime';

import { ICanDisable, mixinDisabled } from '../common/common.module';

const noop: any = () => {
  // empty method
};

@Directive({
  selector: '[td-chip]ng-template',
})
export class TdChipDirective extends TemplatePortalDirective {
  constructor(templateRef: TemplateRef<any>, viewContainerRef: ViewContainerRef) {
    super(templateRef, viewContainerRef);
  }
}

@Directive({
  selector: '[td-autocomplete-option]ng-template',
})
export class TdAutocompleteOptionDirective extends TemplatePortalDirective {
  constructor(templateRef: TemplateRef<any>, viewContainerRef: ViewContainerRef) {
    super(templateRef, viewContainerRef);
  }
}

export class TdChipsBase {}

/* tslint:disable-next-line */
export const _TdChipsMixinBase = mixinDisabled(TdChipsBase);

@Component({
  providers: [{
    provide: NG_VALUE_ACCESSOR,
    useExisting: forwardRef(() => TdChipsComponent),
    multi: true,
  }],
  selector: 'td-chips',
  inputs: ['disabled'],
  styleUrls: ['./chips.component.scss' ],
  templateUrl: './chips.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TdChipsComponent extends _TdChipsMixinBase implements ControlValueAccessor, DoCheck, OnInit, AfterViewInit, OnDestroy, ICanDisable {

  private _outsideClickSubs: Subscription;

  private _isMousedown: boolean = false;

  /**
   * Implemented as part of ControlValueAccessor.
   */
  private _value: any[] = [];

  private _items: any[];
  private _length: number = 0;
  private _stacked: boolean = false;
  private _requireMatch: boolean = false;
  private _color: 'primary' | 'accent' | 'warn' = 'primary';
  private _chipAddition: boolean = true;
  private _chipRemoval: boolean = true;
  private _focused: boolean = false;
  private _tabIndex: number = 0;

  _internalClick: boolean = false;

  @ViewChild('input') _nativeInput: ElementRef;
  @ViewChild(MatInput) _inputChild: MatInput;
  @ViewChild(MatAutocompleteTrigger) _autocompleteTrigger: MatAutocompleteTrigger;
  @ViewChildren(MatChip) _chipsChildren: QueryList<MatChip>;

  @ContentChild(TdChipDirective) _chipTemplate: TdChipDirective;
  @ContentChild(TdAutocompleteOptionDirective) _autocompleteOptionTemplate: TdAutocompleteOptionDirective;

  @ViewChildren(MatOption) _options: QueryList<MatOption>;

  /**
   * Flag that is true when autocomplete is focused.
   */
  get focused(): boolean {
    return this._focused;
  }

  /**
   * FormControl for the matInput element.
   */
  inputControl: FormControl = new FormControl();

  /**
   * items?: any[]
   * Renders the `mat-autocomplete` with the provided list to display as options.
   */
  @Input('items')
  set items(items: any[]) {
    this._items = items;
    this._setFirstOptionActive();
    this._changeDetectorRef.markForCheck();
  }
  get items(): any[] {
    return this._items;
  }

  /**
   * stacked?: boolean
   * Set stacked or horizontal chips depending on value.
   * Defaults to false.
   */
  @Input('stacked')
  set stacked(stacked: boolean) {
    this._stacked = coerceBooleanProperty(stacked);
  }
  get stacked(): boolean {
    return this._stacked;
  }
  
  /**
   * requireMatch?: boolean
   * Blocks custom inputs and only allows selections from the autocomplete list.
   */
  @Input('requireMatch')
  set requireMatch(requireMatch: boolean) {
    this._requireMatch = coerceBooleanProperty(requireMatch);
  }
  get requireMatch(): boolean {
    return this._requireMatch;
  }

  /**
   * chipAddition?: boolean
   * Disables the ability to add chips. When setting disabled as true, this will be overriden.
   * Defaults to true.
   */
  @Input('chipAddition')
  set chipAddition(chipAddition: boolean) {
    this._chipAddition = chipAddition;
    this._toggleInput();
  }
  get chipAddition(): boolean {
    return this._chipAddition;
  }

  /**
   * Checks if not in disabled state and if chipAddition is set to 'true'
{'fraction_non_alphanumeric': 0.11648250460405156, 'fraction_numerical': 0.001289134438305709, 'mean_word_length': 4.680439330543933, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '4635370', 'n_tokens_mistral': 3387, 'n_tokens_neox': 3256, 'n_words': 830}