|
|
@ -97,6 +97,9 @@ export class TagEditorComponent implements ControlValueAccessor, OnDestroy, OnIn |
|
|
@Input() |
|
|
@Input() |
|
|
public suggestions: string[] = []; |
|
|
public suggestions: string[] = []; |
|
|
|
|
|
|
|
|
|
|
|
@Input() |
|
|
|
|
|
public singleLine = false; |
|
|
|
|
|
|
|
|
@Input() |
|
|
@Input() |
|
|
public class: string; |
|
|
public class: string; |
|
|
|
|
|
|
|
|
@ -106,6 +109,9 @@ export class TagEditorComponent implements ControlValueAccessor, OnDestroy, OnIn |
|
|
@Input() |
|
|
@Input() |
|
|
public inputName = 'tag-editor'; |
|
|
public inputName = 'tag-editor'; |
|
|
|
|
|
|
|
|
|
|
|
@ViewChild('form') |
|
|
|
|
|
public formElement: ElementRef; |
|
|
|
|
|
|
|
|
@ViewChild('input') |
|
|
@ViewChild('input') |
|
|
public inputElement: ElementRef; |
|
|
public inputElement: ElementRef; |
|
|
|
|
|
|
|
|
@ -126,7 +132,7 @@ export class TagEditorComponent implements ControlValueAccessor, OnDestroy, OnIn |
|
|
this.subscription = |
|
|
this.subscription = |
|
|
this.addInput.valueChanges.pipe( |
|
|
this.addInput.valueChanges.pipe( |
|
|
tap(() => { |
|
|
tap(() => { |
|
|
this.adjustSize(); |
|
|
this.resetSize(); |
|
|
}), |
|
|
}), |
|
|
map(query => <string>query), |
|
|
map(query => <string>query), |
|
|
map(query => query ? query.trim() : query), |
|
|
map(query => query ? query.trim() : query), |
|
|
@ -151,6 +157,7 @@ export class TagEditorComponent implements ControlValueAccessor, OnDestroy, OnIn |
|
|
|
|
|
|
|
|
public writeValue(obj: any) { |
|
|
public writeValue(obj: any) { |
|
|
this.resetForm(); |
|
|
this.resetForm(); |
|
|
|
|
|
this.resetSize(); |
|
|
|
|
|
|
|
|
if (this.converter && Types.isArrayOf(obj, v => this.converter.isValidValue(v))) { |
|
|
if (this.converter && Types.isArrayOf(obj, v => this.converter.isValidValue(v))) { |
|
|
this.items = obj; |
|
|
this.items = obj; |
|
|
@ -191,7 +198,7 @@ export class TagEditorComponent implements ControlValueAccessor, OnDestroy, OnIn |
|
|
this.updateItems([...this.items.slice(0, index), ...this.items.splice(index + 1)]); |
|
|
this.updateItems([...this.items.slice(0, index), ...this.items.splice(index + 1)]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public adjustSize() { |
|
|
public resetSize() { |
|
|
const style = window.getComputedStyle(this.inputElement.nativeElement); |
|
|
const style = window.getComputedStyle(this.inputElement.nativeElement); |
|
|
|
|
|
|
|
|
if (!canvas) { |
|
|
if (!canvas) { |
|
|
@ -204,14 +211,24 @@ export class TagEditorComponent implements ControlValueAccessor, OnDestroy, OnIn |
|
|
if (ctx) { |
|
|
if (ctx) { |
|
|
ctx.font = `${style.getPropertyValue('font-size')} ${style.getPropertyValue('font-family')}`; |
|
|
ctx.font = `${style.getPropertyValue('font-size')} ${style.getPropertyValue('font-family')}`; |
|
|
|
|
|
|
|
|
|
|
|
let width = 0; |
|
|
|
|
|
|
|
|
|
|
|
if (this.singleLine) { |
|
|
|
|
|
width = ctx.measureText(this.inputElement.nativeElement.value || this.placeholder).width; |
|
|
|
|
|
} else { |
|
|
const widthText = ctx.measureText(this.inputElement.nativeElement.value).width; |
|
|
const widthText = ctx.measureText(this.inputElement.nativeElement.value).width; |
|
|
const widthPlaceholder = ctx.measureText(this.placeholder).width; |
|
|
const widthPlaceholder = ctx.measureText(this.placeholder).width; |
|
|
|
|
|
|
|
|
const width = Math.max(widthText, widthPlaceholder); |
|
|
width = Math.max(widthText, widthPlaceholder); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.inputElement.nativeElement.style.width = <any>((width + 20) + 'px'); |
|
|
this.inputElement.nativeElement.style.width = <any>((width + 20) + 'px'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
this.formElement.nativeElement.scrollLeft = this.formElement.nativeElement.scrollWidth; |
|
|
|
|
|
}, 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public onKeyDown(event: KeyboardEvent) { |
|
|
public onKeyDown(event: KeyboardEvent) { |
|
|
@ -301,6 +318,8 @@ export class TagEditorComponent implements ControlValueAccessor, OnDestroy, OnIn |
|
|
} else { |
|
|
} else { |
|
|
this.callChange(this.items); |
|
|
this.callChange(this.items); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.resetSize(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|