/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { Directive, ElementRef, Inject } from '@angular/core'; import { DOCUMENT } from '@angular/common'; import * as i0 from "@angular/core"; /** * A directive that makes a span editable and exposes functions to modify and retrieve the * element's contents. */ export class MatChipEditInput { constructor(_elementRef, _document) { this._elementRef = _elementRef; this._document = _document; } initialize(initialValue) { this.getNativeElement().focus(); this.setValue(initialValue); } getNativeElement() { return this._elementRef.nativeElement; } setValue(value) { this.getNativeElement().textContent = value; this._moveCursorToEndOfInput(); } getValue() { return this.getNativeElement().textContent || ''; } _moveCursorToEndOfInput() { const range = this._document.createRange(); range.selectNodeContents(this.getNativeElement()); range.collapse(false); const sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(range); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: MatChipEditInput, deps: [{ token: i0.ElementRef }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.1", type: MatChipEditInput, selector: "span[matChipEditInput]", host: { attributes: { "role": "textbox", "tabindex": "-1", "contenteditable": "true" }, classAttribute: "mat-chip-edit-input" }, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: MatChipEditInput, decorators: [{ type: Directive, args: [{ selector: 'span[matChipEditInput]', host: { 'class': 'mat-chip-edit-input', 'role': 'textbox', 'tabindex': '-1', 'contenteditable': 'true', }, }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT] }] }]; } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hpcC1lZGl0LWlucHV0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vL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