2020-07-20 15:54:50 +02:00
|
|
|
import {InputElement} from "./InputElement";
|
2020-08-17 17:23:15 +02:00
|
|
|
import {UIEventSource} from "../../Logic/UIEventSource";
|
2021-06-14 02:39:23 +02:00
|
|
|
import Translations from "../i18n/Translations";
|
|
|
|
import BaseUIElement from "../BaseUIElement";
|
2020-07-20 13:28:45 +02:00
|
|
|
|
2020-07-20 15:54:50 +02:00
|
|
|
export class FixedInputElement<T> extends InputElement<T> {
|
2020-08-31 02:59:47 +02:00
|
|
|
private readonly value: UIEventSource<T>;
|
2020-09-09 18:42:13 +02:00
|
|
|
private readonly _comparator: (t0: T, t1: T) => boolean;
|
2020-07-20 13:28:45 +02:00
|
|
|
|
2021-09-09 00:05:51 +02:00
|
|
|
private readonly _el: HTMLElement;
|
|
|
|
|
|
|
|
constructor(rendering: BaseUIElement | string,
|
2021-10-02 15:16:41 +02:00
|
|
|
value: T | UIEventSource<T>,
|
2021-09-09 00:05:51 +02:00
|
|
|
comparator: ((t0: T, t1: T) => boolean) = undefined) {
|
2021-06-14 02:39:23 +02:00
|
|
|
super();
|
2020-09-30 22:48:58 +02:00
|
|
|
this._comparator = comparator ?? ((t0, t1) => t0 == t1);
|
2021-11-07 16:34:51 +01:00
|
|
|
if (value instanceof UIEventSource) {
|
2021-10-02 15:16:41 +02:00
|
|
|
this.value = value
|
2021-11-07 16:34:51 +01:00
|
|
|
} else {
|
2021-10-02 15:16:41 +02:00
|
|
|
this.value = new UIEventSource<T>(value);
|
|
|
|
}
|
2021-06-14 02:39:23 +02:00
|
|
|
|
|
|
|
this._el = document.createElement("span")
|
|
|
|
const e = Translations.W(rendering)?.ConstructElement()
|
2021-09-09 00:05:51 +02:00
|
|
|
if (e) {
|
|
|
|
this._el.appendChild(e)
|
2021-06-14 02:39:23 +02:00
|
|
|
}
|
2021-09-09 00:05:51 +02:00
|
|
|
|
2020-07-20 13:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GetValue(): UIEventSource<T> {
|
|
|
|
return this.value;
|
|
|
|
}
|
|
|
|
|
2020-07-20 15:54:50 +02:00
|
|
|
IsValid(t: T): boolean {
|
2020-09-09 18:42:13 +02:00
|
|
|
return this._comparator(t, this.value.data);
|
2020-07-20 15:54:50 +02:00
|
|
|
}
|
2020-08-31 02:59:47 +02:00
|
|
|
|
2021-09-09 00:05:51 +02:00
|
|
|
protected InnerConstructElement(): HTMLElement {
|
|
|
|
return this._el;
|
|
|
|
}
|
2021-09-30 21:41:51 +02:00
|
|
|
}
|