| import { Directive, TemplateRef, ViewContainerRef, EventEmitter, Component, forwardRef, ChangeDetectionStrategy, ElementRef, Renderer2, Optional, Inject, ChangeDetectorRef, ViewChild, ViewChildren, ContentChild, Input, Output, HostBinding, HostListener, NgModule } from '@angular/core'; |
| import { FormControl, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms'; |
| import { DOCUMENT, CommonModule } from '@angular/common'; |
| import { MatInput, MatInputModule } from '@angular/material/input'; |
| import { MatIconModule } from '@angular/material/icon'; |
| import { MatAutocompleteTrigger, MatAutocompleteModule } from '@angular/material/autocomplete'; |
| import { MatChip, MatChipsModule } from '@angular/material/chips'; |
| import { TemplatePortalDirective } from '@angular/cdk/portal'; |
| import { coerceBooleanProperty } from '@angular/cdk/coercion'; |
| import { ESCAPE, TAB, RIGHT_ARROW, BACKSPACE, DELETE, LEFT_ARROW, UP_ARROW, DOWN_ARROW } from '@angular/cdk/keycodes'; |
| import { MatOption } from '@angular/material/core'; |
| import { Subscription, timer, merge, fromEvent } from 'rxjs'; |
| import { debounceTime, filter } from 'rxjs/operators'; |
| import { mixinControlValueAccessor, mixinDisabled } from '@covalent/core/common'; |
| |
| /** |
| * @fileoverview added by tsickle |
| * Generated from: chips.component.ts |
| * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc |
| */ |
| class TdChipDirective extends TemplatePortalDirective { |
| /** |
| * @param {?} templateRef |
| * @param {?} viewContainerRef |
| */ |
| constructor(templateRef, viewContainerRef) { |
| super(templateRef, viewContainerRef); |
| } |
| } |
| TdChipDirective.decorators = [ |
| { type: Directive, args: [{ |
| selector: '[td-chip]ng-template', |
| },] } |
| ]; |
| /** @nocollapse */ |
| TdChipDirective.ctorParameters = () => [ |
| { type: TemplateRef }, |
| { type: ViewContainerRef } |
| ]; |
| class TdAutocompleteOptionDirective extends TemplatePortalDirective { |
| /** |
| * @param {?} templateRef |
| * @param {?} viewContainerRef |
| */ |
| constructor(templateRef, viewContainerRef) { |
| super(templateRef, viewContainerRef); |
| } |
| } |
| TdAutocompleteOptionDirective.decorators = [ |
| { type: Directive, args: [{ |
| selector: '[td-autocomplete-option]ng-template', |
| },] } |
| ]; |
| /** @nocollapse */ |
| TdAutocompleteOptionDirective.ctorParameters = () => [ |
| { type: TemplateRef }, |
| { type: ViewContainerRef } |
| ]; |
| class TdChipsBase { |
| /** |
| * @param {?} _changeDetectorRef |
| */ |
| constructor(_changeDetectorRef) { |
| this._changeDetectorRef = _changeDetectorRef; |
| } |
| } |
| if (false) { |
| /** @type {?} */ |
| TdChipsBase.prototype._changeDetectorRef; |
| } |
| /* tslint:disable-next-line */ |
| /** @type {?} */ |
| const _TdChipsMixinBase = mixinControlValueAccessor(mixinDisabled(TdChipsBase), []); |
| class TdChipsComponent extends _TdChipsMixinBase { |
| /** |
| * @param {?} _elementRef |
| * @param {?} _renderer |
| * @param {?} _document |
| * @param {?} _changeDetectorRef |
| */ |
| constructor(_elementRef, _renderer, _document, _changeDetectorRef) { |
| super(_changeDetectorRef); |
| this._elementRef = _elementRef; |
| this._renderer = _renderer; |
| this._document = _document; |
| this._outsideClickSubs = Subscription.EMPTY; |
| this._inputValueChangesSubs = Subscription.EMPTY; |
| this._isMousedown = false; |
| this._length = 0; |
| this._stacked = false; |
| this._requireMatch = false; |
| this._color = 'primary'; |
| this._inputPosition = 'after'; |
| this._chipAddition = true; |
| this._chipRemoval = true; |
| this._focused = false; |
| this._required = false; |
| this._tabIndex = 0; |
| this._touchendDebounce = 100; |
| this._internalClick = false; |
| this._internalActivateOption = false; |
| /** |
| * FormControl for the matInput element. |
| */ |
| this.inputControl = new FormControl(); |
| /** |
| * debounce?: number |
| * Debounce timeout between keypresses. Defaults to 200. |
| */ |
| this.debounce = 200; |
| /** |
| * add?: function |
| * Method to be executed when a chip is added. |
| * Sends chip value as event. |
| */ |
| this.add = new EventEmitter(); |
| /** |
| * remove?: function |
| * Method to be executed when a chip is removed. |
| * Sends chip value as event. |
| */ |
| this.remove = new EventEmitter(); |
| /** |
| * inputChange?: function |
| * Method to be executed when the value in the autocomplete input changes. |
| * Sends string value as event. |
| */ |
| this.inputChange = new EventEmitter(); |
| /** |
| * chipFocus?: function |
| * Method to be executed when a chip is focused. |
| * Sends chip value as event. |
| */ |
| this.chipFocus = new EventEmitter(); |
| /** |
| * blur?: function |
| * Method to be executed when a chip is blurred. |
| * Sends chip value as event. |
| */ |
| this.chipBlur = new EventEmitter(); |
| /** |
| * compareWith? function |
| * Function used to check whether a chip value already exists. |
| * Defaults to strict equality comparison === |
| */ |
| this.compareWith = (/** |
| * @param {?} o1 |
| * @param {?} o2 |
| * @return {?} |
| */ |
| (o1, o2) => { |
| return o1 === o2; |
| }); |
| this._renderer.addClass(this._elementRef.nativeElement, 'mat-' + this._color); |
| } |
| /** |
| * Flag that is true when autocomplete is focused. |
| * @return {?} |
| */ |
| get focused() { |
| return this._focused; |
| } |
| /** |
| * items?: any[] |
| * Renders the `mat-autocomplete` with the provided list to display as options. |
| * @param {?} items |
| * @return {?} |
| */ |
| set items(items) { |
| this._items = items; |
| this._setFirstOptionActive(); |
| this._changeDetectorRef.markForCheck(); |
| } |
| /** |
| * @return {?} |
| */ |
| get items() { |
| return this._items; |
| } |
| /** |
| * stacked?: boolean |
| * Set stacked or horizontal chips depending on value. |
| * Defaults to false. |
| * @param {?} stacked |
| * @return {?} |
| */ |
| set stacked(stacked) { |
| this._stacked = coerceBooleanProperty(stacked); |
| } |
| /** |
| * @return {?} |
| */ |
| get stacked() { |
| return this._stacked; |
| } |
| /** |
| * inputPosition?: 'before' | 'after' |
| * Set input position before or after the chips. |
| * Defaults to 'after'. |
| * @param {?} inputPosition |
| * @return {?} |
| */ |
| set inputPosition(inputPosition) { |
| this._inputPosition = inputPosition; |
| } |
| /** |
| * @return {?} |
| */ |
| get inputPosition() { |
| return this._inputPosition; |
| } |
| /** |
| * requireMatch?: boolean |
| * Blocks custom inputs and only allows selections from the autocomplete list. |
| * @param {?} requireMatch |
| * @return {?} |
| */ |
| set requireMatch(requireMatch) { |
| this._requireMatch = coerceBooleanProperty(requireMatch); |
| } |
| /** |
| * @return {?} |
| */ |
| get requireMatch() { |
| return this._requireMatch; |
| } |
| /** |
| * required?: boolean |
| * Value is set to true if at least one chip is needed |
| * Defaults to false |
| * @param {?} required |
| * @return {?} |
| */ |
| set required(required) { |
| this._required = coerceBooleanProperty(required); |
| } |
| /** |
| * @return {?} |
| */ |
| get required() { |
| return this._required; |
| } |
| /** |
| * chipAddition?: boolean |
| * Disables the ability to add chips. When setting disabled as true, this will be overriden. |
| * Defaults to true. |
| * @param {?} chipAddition |
| * @return {?} |
| */ |
| set chipAddition(chipAddition) { |
| this._chipAddition = chipAddition; |
| this._toggleInput(); |
| } |
| /** |
| * @return {?} |
| */ |
| get chipAddition() { |
| return this._chipAddition; |
| } |
| /** |
| * Checks if not in disabled state and if chipAddition is set to 'true' |
| * States if a chip can be added and if the input is available |
| * @return {?} |
| */ |
| get canAddChip() { |
| return this.chipAddition && !this.disabled; |
| } |
| /** |
| * chipRemoval?: boolean |
| * Disables the ability to remove chips. If it doesn't exist chip remmoval defaults to true. |
| * When setting disabled as true, this will be overriden to false. |
| * @param {?} chipRemoval |
| * @return {?} |
| */ |
| set chipRemoval(chipRemoval) { |
| this._chipRemoval = chipRemoval; |
| } |
| /** |
| * @return {?} |
| */ |
| get chipRemoval() { |
| return this._chipRemoval; |
| } |
| /** |
| * Checks if not in disabled state and if chipRemoval is set to 'true' |
| * States if a chip can be removed |
| * @return {?} |
| */ |
| get canRemoveChip() { |
| return this.chipRemoval && !this.disabled; |
| } |
| /** |
| * returns the display placeholder |
| * @return {?} |
| */ |
| get displayPlaceHolder() { |
| if (!this.canAddChip) { |
| return ''; |
| } |
| return this._required ? `${this.placeholder} *` : this.placeholder; |
| } |
| /** |
| * color?: 'primary' | 'accent' | 'warn' |
| * Sets the color for the input and focus/selected state of the chips. |
| * Defaults to 'primary' |
| * @param {?} color |
| * @return {?} |
| */ |
| set color(color) { |
| if (color) { |
| this._renderer.removeClass(this._elementRef.nativeElement, 'mat-' + this._color); |
| this._color = color; |
| this._renderer.addClass(this._elementRef.nativeElement, 'mat-' + this._color); |
| } |
| } |
| /** |
| * @return {?} |
| */ |
| get color() { |
| return this._color; |
| } |
| /** |
| * Hostbinding to set the a11y of the TdChipsComponent depending on its state |
| * @return {?} |
| */ |
| get tabIndex() { |
| return this.disabled ? -1 : this._tabIndex; |
| } |
| /** |
| * Listens to host focus event to act on it |
| * @param {?} event |
| * @return {?} |
| */ |
| focusListener(event) { |
| // should only focus if its not via mousedown to prevent clashing with autocomplete |
| if (!this._isMousedown) { |
| this.focus(); |
| } |
| event.preventDefault(); |
| } |
| /** |
| * Listens to host mousedown event to act on it |
| * @param {?} event |
| * @return {?} |
| */ |
| mousedownListener(event) { |
| // sets a flag to know if there was a mousedown and then it returns it back to false |
| this._isMousedown = true; |
| timer() |
| .toPromise() |
| .then((/** |
| * @return {?} |
| */ |
| () => { |
| this._isMousedown = false; |
| })); |
| } |
| /** |
| * If clicking on :host or `td-chips-wrapper`, then we stop the click propagation so the autocomplete |
| * doesnt close automatically. |
| * @param {?} event |
| * @return {?} |
| */ |
| clickListener(event) { |
| /** @type {?} */ |
| const clickTarget = (/** @type {?} */ (event.target)); |
| if (clickTarget === this._elementRef.nativeElement || clickTarget.className.indexOf('td-chips-wrapper') > -1) { |
| this.focus(); |
| event.preventDefault(); |
| event.stopPropagation(); |
| } |
| } |
| /** |
| * Listens to host keydown event to act on it depending on the keypress |
| * @param {?} event |
| * @return {?} |
| */ |
| keydownListener(event) { |
| switch (event.keyCode) { |
| case TAB: |
| // if tabing out, then unfocus the component |
| timer() |
| .toPromise() |
| .then((/** |
| * @return {?} |
| */ |
| () => { |
| this.removeFocusedState(); |
| })); |
| break; |
| case ESCAPE: |
| if (this._inputChild.focused) { |
| this._nativeInput.nativeElement.blur(); |
| this.removeFocusedState(); |
| this._closeAutocomplete(); |
| } |
| else { |
| this.focus(); |
| } |
| break; |
| default: |
| // default |
| } |
| } |
| /** |
| * @return {?} |
| */ |
| ngOnInit() { |
| this._inputValueChangesSubs = this.inputControl.valueChanges |
| .pipe(debounceTime(this.debounce)) |
| .subscribe((/** |
| * @param {?} value |
| * @return {?} |
| */ |
| (value) => { |
| this.inputChange.emit(value ? value : ''); |
| })); |
| this._changeDetectorRef.markForCheck(); |
| } |
| /** |
| * @return {?} |
| */ |
| ngAfterViewInit() { |
| this._watchOutsideClick(); |
| this._changeDetectorRef.markForCheck(); |
| } |
| /** |
| * @return {?} |
| */ |
| ngDoCheck() { |
| // Throw onChange event only if array changes size. |
| if (this.value && this.value.length !== this._length) { |
| this._length = this.value.length; |
| this.onChange(this.value); |
| } |
| } |
| /** |
| * @return {?} |
| */ |
| ngOnDestroy() { |
| this._outsideClickSubs.unsubscribe(); |
| this._inputValueChangesSubs.unsubscribe(); |
| } |
| /** |
| * @return {?} |
| */ |
| _setInternalClick() { |
| this._internalClick = true; |
| } |
| /** |
| * Method executed when the disabled value changes |
| * @param {?} v |
| * @return {?} |
| */ |
| onDisabledChange(v) { |
| this._toggleInput(); |
| } |
| /** |
| * Method that is executed when trying to create a new chip from the autocomplete. |
| * It check if [requireMatch] is enabled, and tries to add the first active option |
| * else if just adds the value thats on the input |
| * returns 'true' if successful, 'false' if it fails. |
| * @return {?} |
| */ |
| _handleAddChip() { |
| /** @type {?} */ |
| let value; |
| if (this.requireMatch) { |
| /** @type {?} */ |
| const selectedOptions = this._options.toArray().filter((/** |
| * @param {?} option |
| * @return {?} |
| */ |
| (option) => { |
| return option.active; |
| })); |
| if (selectedOptions.length > 0) { |
| value = selectedOptions[0].value; |
| selectedOptions[0].setInactiveStyles(); |
| } |
| if (!value) { |
| return false; |
| } |
| } |
| else { |
| // if there is a selection, then use that |
| // else use the input value as chip |
| if (this._autocompleteTrigger.activeOption) { |
| value = this._autocompleteTrigger.activeOption.value; |
| this._autocompleteTrigger.activeOption.setInactiveStyles(); |
| } |
| else { |
| value = this._inputChild.value; |
| if (value.trim() === '') { |
| return false; |
| } |
| } |
| } |
| return this.addChip(value); |
| } |
| /** |
| * Method thats exectuted when trying to add a value as chip |
| * returns 'true' if successful, 'false' if it fails. |
| * @param {?} value |
| * @return {?} |
| */ |
| addChip(value) { |
| /** |
| * add a debounce ms delay when reopening the autocomplete to give it time |
| * to rerender the next list and at the correct spot |
| */ |
| this._closeAutocomplete(); |
| timer(this.debounce) |
| .toPromise() |
| .then((/** |
| * @return {?} |
| */ |
| () => { |
| this.setFocusedState(); |
| this._setFirstOptionActive(); |
| this._openAutocomplete(); |
| })); |
| this.inputControl.setValue(''); |
| // check if value is already part of the model |
| if (this.value.findIndex((/** |
| * @param {?} item |
| * @return {?} |
| */ |
| (item) => this.compareWith(item, value))) > -1) { |
| return false; |
| } |
| this.value.push(value); |
| this.add.emit(value); |
| this.onChange(this.value); |
| this._changeDetectorRef.markForCheck(); |
| return true; |
| } |
| /** |
| * Method that is executed when trying to remove a chip. |
| * returns 'true' if successful, 'false' if it fails. |
| * @param {?} index |
| * @return {?} |
| */ |
| removeChip(index) { |
| /** @type {?} */ |
| const removedValues = this.value.splice(index, 1); |
| if (removedValues.length === 0) { |
| return false; |
| } |
| /** |
| * Checks if deleting last single chip, to focus input afterwards |
| * Else check if its not the last chip of the list to focus the next one. |
| */ |
| if (index === this._totalChips - 1 && index === 0) { |
| this._inputChild.focus(); |
| } |
| else if (index < this._totalChips - 1) { |
| this._focusChip(index + 1); |
| } |
| else if (index > 0) { |
| this._focusChip(index - 1); |
| } |
| this.remove.emit(removedValues[0]); |
| this.onChange(this.value); |
| this.inputControl.setValue(''); |
| this._changeDetectorRef.markForCheck(); |
| return true; |
| } |
| /** |
| * Sets blur of chip and sends out event |
| * @param {?} event |
| * @param {?} value |
| * @return {?} |
| */ |
| _handleChipBlur(event, value) { |
| this.chipBlur.emit(value); |
| } |
| /** |
| * Sets focus of chip and sends out event |
| * @param {?} event |
| * @param {?} value |
| * @return {?} |
| */ |
| _handleChipFocus(event, value) { |
| this.setFocusedState(); |
| this.chipFocus.emit(value); |
| } |
| /** |
| * @return {?} |
| */ |
| _handleFocus() { |
| this.setFocusedState(); |
| this._setFirstOptionActive(); |
| return true; |
| } |
| /** |
| * Sets focus state of the component |
| * @return {?} |
| */ |
| setFocusedState() { |
| if (!this.disabled) { |
| this._focused = true; |
| this._tabIndex = -1; |
| this._changeDetectorRef.markForCheck(); |
| } |
| } |
| /** |
| * Removes focus state of the component |
| * @return {?} |
| */ |
| removeFocusedState() { |
| this._focused = false; |
| this._tabIndex = 0; |
| this._changeDetectorRef.markForCheck(); |
| } |
| /** |
| * Programmatically focus the input or first chip. Since its the component entry point |
| * depending if a user can add or remove chips |
| * @return {?} |
| */ |
| focus() { |
| if (this.canAddChip) { |
| this._inputChild.focus(); |
| } |
| else if (!this.disabled) { |
| this._focusFirstChip(); |
| } |
| } |
| /** |
| * Passes relevant input key presses. |
| * @param {?} event |
| * @return {?} |
| */ |
| _inputKeydown(event) { |
| switch (event.keyCode) { |
| case UP_ARROW: |
| /** |
| * Since the first item is highlighted on [requireMatch], we need to inactivate it |
| * when pressing the up key |
| */ |
| if (this.requireMatch) { |
| /** @type {?} */ |
| const length = this._options.length; |
| if (length > 1 && this._options.toArray()[0].active && this._internalActivateOption) { |
| this._options.toArray()[0].setInactiveStyles(); |
| this._internalActivateOption = false; |
| // prevent default window scrolling |
| event.preventDefault(); |
| } |
| } |
| break; |
| case LEFT_ARROW: |
| case DELETE: |
| case BACKSPACE: |
| this._closeAutocomplete(); |
| /** Check to see if input is empty when pressing left arrow to move to the last chip */ |
| if (!this._inputChild.value) { |
| this._focusLastChip(); |
| // prevent default window scrolling |
| event.preventDefault(); |
| } |
| break; |
| case RIGHT_ARROW: |
| this._closeAutocomplete(); |
| /** Check to see if input is empty when pressing right arrow to move to the first chip */ |
| if (!this._inputChild.value) { |
| this._focusFirstChip(); |
| // prevent default window scrolling |
| event.preventDefault(); |
| } |
| break; |
| default: |
| // default |
| } |
| } |
| /** |
| * Passes relevant chip key presses. |
| * @param {?} event |
| * @param {?} index |
| * @return {?} |
| */ |
| _chipKeydown(event, index) { |
| switch (event.keyCode) { |
| case DELETE: |
| case BACKSPACE: |
| /** Check to see if we can delete a chip */ |
| if (this.canRemoveChip) { |
| this.removeChip(index); |
| } |
| break; |
| case UP_ARROW: |
| case LEFT_ARROW: |
| /** |
| * Check to see if left/down arrow was pressed while focusing the first chip to focus input next |
| * Also check if input should be focused |
| */ |
| if (index === 0) { |
| // only try to target input if pressing left |
| if (this.canAddChip && event.keyCode === LEFT_ARROW) { |
| this._inputChild.focus(); |
| } |
| else { |
| this._focusLastChip(); |
| } |
| } |
| else if (index > 0) { |
| this._focusChip(index - 1); |
| } |
| // prevent default window scrolling |
| event.preventDefault(); |
| break; |
| case DOWN_ARROW: |
| case RIGHT_ARROW: |
| /** |
| * Check to see if right/up arrow was pressed while focusing the last chip to focus input next |
| * Also check if input should be focused |
| */ |
| if (index === this._totalChips - 1) { |
| // only try to target input if pressing right |
| if (this.canAddChip && event.keyCode === RIGHT_ARROW) { |
| this._inputChild.focus(); |
| } |
| else { |
| this._focusFirstChip(); |
| } |
| } |
| else if (index < this._totalChips - 1) { |
| this._focusChip(index + 1); |
| } |
| // prevent default window scrolling |
| event.preventDefault(); |
| break; |
| default: |
| // default |
| } |
| } |
| /** |
| * Method to remove from display the value added from the autocomplete since it goes directly as chip. |
| * @return {?} |
| */ |
| _removeInputDisplay() { |
| return ''; |
| } |
| /** |
| * Method to open the autocomplete manually if its not already opened |
| * @return {?} |
| */ |
| _openAutocomplete() { |
| if (!this._autocompleteTrigger.panelOpen) { |
| this._autocompleteTrigger.openPanel(); |
| this._changeDetectorRef.markForCheck(); |
| } |
| } |
| /** |
| * Method to close the autocomplete manually if its not already closed |
| * @return {?} |
| */ |
| _closeAutocomplete() { |
| if (this._autocompleteTrigger.panelOpen) { |
| this._autocompleteTrigger.closePanel(); |
| this._changeDetectorRef.markForCheck(); |
| } |
| } |
| /** |
| * Get total of chips |
| * @return {?} |
| */ |
| get _totalChips() { |
| /** @type {?} */ |
| const chips = this._chipsChildren.toArray(); |
| return chips.length; |
| } |
| /** |
| * Method to focus a desired chip by index |
| * @private |
| * @param {?} index |
| * @return {?} |
| */ |
| _focusChip(index) { |
| /** check to see if index exists in the array before focusing */ |
| if (index > -1 && this._totalChips > index) { |
| this._chipsChildren.toArray()[index].focus(); |
| } |
| } |
| /** |
| * Method to focus first chip |
| * @private |
| * @return {?} |
| */ |
| _focusFirstChip() { |
| this._focusChip(0); |
| } |
| /** |
| * Method to focus last chip |
| * @private |
| * @return {?} |
| */ |
| _focusLastChip() { |
| this._focusChip(this._totalChips - 1); |
| } |
| /** |
| * Method to toggle the disable state of input |
| * Checks if not in disabled state and if chipAddition is set to 'true' |
| * @private |
| * @return {?} |
| */ |
| _toggleInput() { |
| if (this.canAddChip) { |
| this.inputControl.enable(); |
| } |
| else { |
| this.inputControl.disable(); |
| } |
| this._changeDetectorRef.markForCheck(); |
| } |
| /** |
| * Sets first option as active to let the user know which one will be added when pressing enter |
| * Only if [requireMatch] has been set |
| * @private |
| * @return {?} |
| */ |
| _setFirstOptionActive() { |
| if (this.requireMatch) { |
| // need to use a timer here to wait until the autocomplete has been opened (end of queue) |
| timer() |
| .toPromise() |
| .then((/** |
| * @return {?} |
| */ |
| () => { |
| if (this.focused && this._options && this._options.length > 0) { |
| // clean up of previously active options |
| this._options.toArray().forEach((/** |
| * @param {?} option |
| * @return {?} |
| */ |
| (option) => { |
| option.setInactiveStyles(); |
| })); |
| // set the first one as active |
| this._options.toArray()[0].setActiveStyles(); |
| this._internalActivateOption = true; |
| this._changeDetectorRef.markForCheck(); |
| } |
| })); |
| } |
| } |
| /** |
| * Watches clicks outside of the component to remove the focus |
| * The autocomplete panel is considered inside the component so we |
| * need to use a flag to find out when its clicked. |
| * @private |
| * @return {?} |
| */ |
| _watchOutsideClick() { |
| if (this._document) { |
| this._outsideClickSubs = merge(fromEvent(this._document, 'click'), fromEvent(this._document, 'touchend')) |
| .pipe(debounceTime(this._touchendDebounce), filter((/** |
| * @param {?} event |
| * @return {?} |
| */ |
| (event) => { |
| /** @type {?} */ |
| const clickTarget = (/** @type {?} */ (event.target)); |
| setTimeout((/** |
| * @return {?} |
| */ |
| () => { |
| this._internalClick = false; |
| })); |
| return (this.focused && |
| clickTarget !== this._elementRef.nativeElement && |
| !this._elementRef.nativeElement.contains(clickTarget) && |
| !this._internalClick); |
| }))) |
| .subscribe((/** |
| * @return {?} |
| */ |
| () => { |
| if (this.focused) { |
| this._autocompleteTrigger.closePanel(); |
| this.removeFocusedState(); |
| this.onTouched(); |
| this._changeDetectorRef.markForCheck(); |
| } |
| })); |
| } |
| return undefined; |
| } |
| } |
| TdChipsComponent.decorators = [ |
| { type: Component, args: [{ |
| providers: [ |
| { |
| provide: NG_VALUE_ACCESSOR, |
| useExisting: forwardRef((/** |
| * @return {?} |
| */ |
| () => TdChipsComponent)), |
| multi: true, |
| }, |
| ], |
| selector: 'td-chips', |
| inputs: ['disabled', 'value'], |
| template: "<div\n class=\"td-chips-wrapper\"\n [class.td-chips-stacked]=\"stacked\"\n [class.td-chips-input-before-position]=\"inputPosition === 'before'\"\n>\n <ng-template let-chip let-first=\"first\" let-index=\"index\" ngFor [ngForOf]=\"value\">\n <mat-basic-chip\n [class.td-chip-disabled]=\"disabled\"\n [class.td-chip-after-pad]=\"!canRemoveChip\"\n [disableRipple]=\"true\"\n [color]=\"color\"\n (keydown)=\"_chipKeydown($event, index)\"\n (blur)=\"_handleChipBlur($event, chip)\"\n (focus)=\"_handleChipFocus($event, chip)\"\n >\n <div class=\"td-chip\" [class.td-chip-stacked]=\"stacked\">\n <span class=\"td-chip-content\">\n <span *ngIf=\"!_chipTemplate?.templateRef\">{{ chip }}</span>\n <ng-template\n *ngIf=\"_chipTemplate?.templateRef\"\n [ngTemplateOutlet]=\"_chipTemplate?.templateRef\"\n [ngTemplateOutletContext]=\"{ chip: chip }\"\n ></ng-template>\n </span>\n <mat-icon *ngIf=\"canRemoveChip\" class=\"td-chip-removal\" (click)=\"_internalClick = removeChip(index)\">\n cancel\n </mat-icon>\n </div>\n </mat-basic-chip>\n </ng-template>\n <mat-form-field\n floatLabel=\"never\"\n class=\"td-chips-form-field\"\n [style.width.px]=\"canAddChip ? null : 0\"\n [style.height.px]=\"canAddChip ? null : 0\"\n [color]=\"color\"\n >\n <input\n matInput\n #input\n [tabIndex]=\"-1\"\n [matAutocomplete]=\"autocomplete\"\n [formControl]=\"inputControl\"\n [placeholder]=\"displayPlaceHolder\"\n (keydown)=\"_inputKeydown($event)\"\n (keyup.enter)=\"_handleAddChip()\"\n (focus)=\"_handleFocus()\"\n />\n </mat-form-field>\n <mat-autocomplete\n #autocomplete=\"matAutocomplete\"\n [displayWith]=\"_removeInputDisplay\"\n (optionSelected)=\"addChip($event.option.value)\"\n >\n <ng-template let-item let-first=\"first\" ngFor [ngForOf]=\"items\">\n <mat-option (click)=\"_setInternalClick()\" [value]=\"item\">\n <span *ngIf=\"!_autocompleteOptionTemplate?.templateRef\">{{ item }}</span>\n <ng-template\n *ngIf=\"_autocompleteOptionTemplate?.templateRef\"\n [ngTemplateOutlet]=\"_autocompleteOptionTemplate?.templateRef\"\n [ngTemplateOutletContext]=\"{ option: item }\"\n ></ng-template>\n </mat-option>\n </ng-template>\n </mat-autocomplete>\n</div>\n<div *ngIf=\"chipAddition\" class=\"mat-form-field-underline\" [class.mat-disabled]=\"disabled\">\n <span class=\"mat-form-field-ripple\" [class.mat-focused]=\"focused\"></span>\n</div>\n<ng-content></ng-content>\n", |
| changeDetection: ChangeDetectionStrategy.OnPush, |
| styles: [":host{display:block;min-height:48px;padding:0 5px}:host .td-chips-wrapper{-ms-flex-align:start;-ms-flex-direction:row;-ms-flex-wrap:wrap;align-items:flex-start;display:-ms-flexbox;display:flex;flex-direction:row;flex-wrap:wrap;min-height:42px}:host .td-chips-wrapper.td-chips-stacked .mat-basic-chip,:host .td-chips-wrapper.td-chips-stacked .td-chips-form-field{width:100%}:host .td-chips-wrapper.td-chips-input-before-position .td-chips-form-field{-ms-flex-order:-1;order:-1}:host .td-chip,:host .td-chip>.td-chip-content{-ms-flex-align:center;-ms-flex-direction:row;-ms-flex-line-pack:center;-ms-flex-pack:start;align-content:center;align-items:center;box-sizing:border-box;display:-ms-flexbox;display:flex;flex-direction:row;justify-content:flex-start;max-width:100%;min-width:0}:host .td-chip.td-chip-stacked,:host .td-chip>.td-chip-content.td-chip-stacked{-ms-flex-pack:justify;justify-content:space-between}:host ::ng-deep .mat-form-field-wrapper{padding-bottom:2px}:host ::ng-deep .mat-basic-chip{border-radius:16px;box-sizing:border-box;cursor:default;display:inline-block;margin:8px 8px 0 0;max-width:100%;position:relative}html[dir=rtl] :host ::ng-deep .mat-basic-chip{margin:8px 0 0 8px;unicode-bidi:embed}body[dir=rtl] :host ::ng-deep .mat-basic-chip{margin:8px 0 0 8px;unicode-bidi:embed}[dir=rtl] :host ::ng-deep .mat-basic-chip{margin:8px 0 0 8px;unicode-bidi:embed}:host ::ng-deep .mat-basic-chip bdo[dir=rtl]{direction:rtl;unicode-bidi:bidi-override}:host ::ng-deep .mat-basic-chip bdo[dir=ltr]{direction:ltr;unicode-bidi:bidi-override}:host ::ng-deep .mat-basic-chip .td-chip{font-size:13px;line-height:32px;min-height:32px;padding:0 0 0 12px}html[dir=rtl] :host ::ng-deep .mat-basic-chip .td-chip{padding:0 12px 0 0;unicode-bidi:embed}body[dir=rtl] :host ::ng-deep .mat-basic-chip .td-chip{padding:0 12px 0 0;unicode-bidi:embed}[dir=rtl] :host ::ng-deep .mat-basic-chip .td-chip{padding:0 12px 0 0;unicode-bidi:embed}:host ::ng-deep .mat-basic-chip .td-chip bdo[dir=rtl]{direction:rtl;unicode-bidi:bidi-override}:host ::ng-deep .mat-basic-chip .td-chip bdo[dir=ltr]{direction:ltr;unicode-bidi:bidi-override}:host ::ng-deep .mat-basic-chip .td-chip [td-chip-avatar]{-ms-flex:0 0 auto;-ms-flex-align:center;-ms-flex-order:-20;-ms-flex-pack:center;align-items:center;border-radius:50%;box-sizing:border-box;display:inline-block;flex:0 0 auto;height:32px;justify-content:center;margin:0 8px 0 -12px;order:-20;text-align:center;width:32px}html[dir=rtl] :host ::ng-deep .mat-basic-chip .td-chip [td-chip-avatar]{margin:0 -12px 0 8px;unicode-bidi:embed}body[dir=rtl] :host ::ng-deep .mat-basic-chip .td-chip [td-chip-avatar]{margin:0 -12px 0 8px;unicode-bidi:embed}[dir=rtl] :host ::ng-deep .mat-basic-chip .td-chip [td-chip-avatar]{margin:0 -12px 0 8px;unicode-bidi:embed}:host ::ng-deep .mat-basic-chip .td-chip [td-chip-avatar] bdo[dir=rtl]{direction:rtl;unicode-bidi:bidi-override}:host ::ng-deep .mat-basic-chip .td-chip [td-chip-avatar] bdo[dir=ltr]{direction:ltr;unicode-bidi:bidi-override}:host ::ng-deep .mat-basic-chip.td-chip-after-pad{padding:0 12px 0 0}html[dir=rtl] :host ::ng-deep .mat-basic-chip.td-chip-after-pad{padding:0 0 0 12px;unicode-bidi:embed}body[dir=rtl] :host ::ng-deep .mat-basic-chip.td-chip-after-pad{padding:0 0 0 12px;unicode-bidi:embed}[dir=rtl] :host ::ng-deep .mat-basic-chip.td-chip-after-pad{padding:0 0 0 12px;unicode-bidi:embed}:host ::ng-deep .mat-basic-chip.td-chip-after-pad bdo[dir=rtl]{direction:rtl;unicode-bidi:bidi-override}:host ::ng-deep .mat-basic-chip.td-chip-after-pad bdo[dir=ltr]{direction:ltr;unicode-bidi:bidi-override}:host ::ng-deep .mat-basic-chip mat-icon.td-chip-removal{font-size:21px;line-height:22px;margin:0 4px}:host ::ng-deep .mat-basic-chip mat-icon.td-chip-removal:hover{cursor:pointer}:host ::ng-deep .td-chips-stacked .mat-basic-chip{margin:4px 0}:host ::ng-deep .td-chips-stacked .mat-basic-chip:first-of-type{margin:8px 0 4px}:host ::ng-deep .td-chips-stacked .mat-basic-chip:last-of-type{margin:4px 0 8px}:host .mat-form-field-underline{bottom:0;height:1px;position:relative;width:100%}:host .mat-form-field-underline.mat-disabled{background-color:rgba(0,0,0,0);background-position:0;bottom:-4px}:host .mat-form-field-underline .mat-form-field-ripple{-ms-transform:scaleX(.5);-ms-transform-origin:50%;height:2px;opacity:0;position:absolute;top:0;transform:scaleX(.5);transform-origin:50%;transition:background-color .3s cubic-bezier(.55,0,.55,.2);visibility:hidden;width:100%}:host .mat-form-field-underline .mat-form-field-ripple.mat-focused,:host.ng-invalid .mat-form-field-underline .mat-form-field-ripple{-ms-transform:scaleX(1);opacity:1;transform:scaleX(1);transition:transform .15s linear,background-color .3s cubic-bezier(.55,0,.55,.2);visibility:visible}:host ::ng-deep mat-form-field .mat-form-field-underline{display:none}"] |
| }] } |
| ]; |
| /** @nocollapse */ |
| TdChipsComponent.ctorParameters = () => [ |
| { type: ElementRef }, |
| { type: Renderer2 }, |
| { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] }, |
| { type: ChangeDetectorRef } |
| ]; |
| TdChipsComponent.propDecorators = { |
| _nativeInput: [{ type: ViewChild, args: ['input', { static: true },] }], |
| _inputChild: [{ type: ViewChild, args: [MatInput, { static: true },] }], |
| _autocompleteTrigger: [{ type: ViewChild, args: [MatAutocompleteTrigger, { static: true },] }], |
| _chipsChildren: [{ type: ViewChildren, args: [MatChip,] }], |
| _chipTemplate: [{ type: ContentChild, args: [TdChipDirective,] }], |
| _autocompleteOptionTemplate: [{ type: ContentChild, args: [TdAutocompleteOptionDirective,] }], |
| _options: [{ type: ViewChildren, args: [MatOption,] }], |
| items: [{ type: Input, args: ['items',] }], |
| stacked: [{ type: Input, args: ['stacked',] }], |
| inputPosition: [{ type: Input, args: ['inputPosition',] }], |
| requireMatch: [{ type: Input, args: ['requireMatch',] }], |
| required: [{ type: Input, args: ['required',] }], |
| chipAddition: [{ type: Input, args: ['chipAddition',] }], |
| chipRemoval: [{ type: Input, args: ['chipRemoval',] }], |
| placeholder: [{ type: Input }], |
| debounce: [{ type: Input }], |
| color: [{ type: Input, args: ['color',] }], |
| add: [{ type: Output }], |
| remove: [{ type: Output }], |
| inputChange: [{ type: Output }], |
| chipFocus: [{ type: Output }], |
| chipBlur: [{ type: Output }], |
| tabIndex: [{ type: HostBinding, args: ['attr.tabindex',] }], |
| compareWith: [{ type: Input }], |
| focusListener: [{ type: HostListener, args: ['focus', ['$event'],] }], |
| mousedownListener: [{ type: HostListener, args: ['mousedown', ['$event'],] }], |
| clickListener: [{ type: HostListener, args: ['click', ['$event'],] }], |
| keydownListener: [{ type: HostListener, args: ['keydown', ['$event'],] }] |
| }; |
| if (false) { |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._outsideClickSubs; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._inputValueChangesSubs; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._isMousedown; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._items; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._length; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._stacked; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._requireMatch; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._color; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._inputPosition; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._chipAddition; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._chipRemoval; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._focused; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._required; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._tabIndex; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._touchendDebounce; |
| /** @type {?} */ |
| TdChipsComponent.prototype._internalClick; |
| /** @type {?} */ |
| TdChipsComponent.prototype._internalActivateOption; |
| /** @type {?} */ |
| TdChipsComponent.prototype._nativeInput; |
| /** @type {?} */ |
| TdChipsComponent.prototype._inputChild; |
| /** @type {?} */ |
| TdChipsComponent.prototype._autocompleteTrigger; |
| /** @type {?} */ |
| TdChipsComponent.prototype._chipsChildren; |
| /** @type {?} */ |
| TdChipsComponent.prototype._chipTemplate; |
| /** @type {?} */ |
| TdChipsComponent.prototype._autocompleteOptionTemplate; |
| /** @type {?} */ |
| TdChipsComponent.prototype._options; |
| /** |
| * FormControl for the matInput element. |
| * @type {?} |
| */ |
| TdChipsComponent.prototype.inputControl; |
| /** |
| * placeholder?: string |
| * Placeholder for the autocomplete input. |
| * @type {?} |
| */ |
| TdChipsComponent.prototype.placeholder; |
| /** |
| * debounce?: number |
| * Debounce timeout between keypresses. Defaults to 200. |
| * @type {?} |
| */ |
| TdChipsComponent.prototype.debounce; |
| /** |
| * add?: function |
| * Method to be executed when a chip is added. |
| * Sends chip value as event. |
| * @type {?} |
| */ |
| TdChipsComponent.prototype.add; |
| /** |
| * remove?: function |
| * Method to be executed when a chip is removed. |
| * Sends chip value as event. |
| * @type {?} |
| */ |
| TdChipsComponent.prototype.remove; |
| /** |
| * inputChange?: function |
| * Method to be executed when the value in the autocomplete input changes. |
| * Sends string value as event. |
| * @type {?} |
| */ |
| TdChipsComponent.prototype.inputChange; |
| /** |
| * chipFocus?: function |
| * Method to be executed when a chip is focused. |
| * Sends chip value as event. |
| * @type {?} |
| */ |
| TdChipsComponent.prototype.chipFocus; |
| /** |
| * blur?: function |
| * Method to be executed when a chip is blurred. |
| * Sends chip value as event. |
| * @type {?} |
| */ |
| TdChipsComponent.prototype.chipBlur; |
| /** |
| * compareWith? function |
| * Function used to check whether a chip value already exists. |
| * Defaults to strict equality comparison === |
| * @type {?} |
| */ |
| TdChipsComponent.prototype.compareWith; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._elementRef; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._renderer; |
| /** |
| * @type {?} |
| * @private |
| */ |
| TdChipsComponent.prototype._document; |
| } |
| |
| /** |
| * @fileoverview added by tsickle |
| * Generated from: chips.module.ts |
| * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc |
| */ |
| class CovalentChipsModule { |
| } |
| CovalentChipsModule.decorators = [ |
| { type: NgModule, args: [{ |
| imports: [ReactiveFormsModule, CommonModule, MatInputModule, MatIconModule, MatChipsModule, MatAutocompleteModule], |
| declarations: [TdChipsComponent, TdChipDirective, TdAutocompleteOptionDirective], |
| exports: [TdChipsComponent, TdChipDirective, TdAutocompleteOptionDirective], |
| },] } |
| ]; |
| |
| /** |
| * @fileoverview added by tsickle |
| * Generated from: public-api.ts |
| * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc |
| */ |
| |
| /** |
| * @fileoverview added by tsickle |
| * Generated from: index.ts |
| * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc |
| */ |
| |
| /** |
| * @fileoverview added by tsickle |
| * Generated from: covalent-core-chips.ts |
| * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc |
| */ |
| |
| export { CovalentChipsModule, TdAutocompleteOptionDirective, TdChipDirective, TdChipsBase, TdChipsComponent, _TdChipsMixinBase }; |
| //# sourceMappingURL=covalent-core-chips.js.map |