Add support for units to clean up tags when they enter mapcomplete; add example of this usage in the climbing theme, add climbing theme title icons with length and needed number of carabiners

This commit is contained in:
Pieter Vander Vennet 2021-06-22 03:16:45 +02:00
parent 89f6f606c8
commit 966fcda8d1
20 changed files with 302 additions and 111 deletions

View file

@ -3,30 +3,48 @@ import {UIEventSource} from "../../Logic/UIEventSource";
import Combine from "../Base/Combine";
import BaseUIElement from "../BaseUIElement";
export default class CombinedInputElement<T> extends InputElement<T> {
protected InnerConstructElement(): HTMLElement {
return this._combined.ConstructElement();
}
private readonly _a: InputElement<T>;
private readonly _b: BaseUIElement;
private readonly _combined: BaseUIElement;
export default class CombinedInputElement<T, J, X> extends InputElement<X> {
public readonly IsSelected: UIEventSource<boolean>;
constructor(a: InputElement<T>, b: InputElement<T>) {
private readonly _a: InputElement<T>;
private readonly _b: InputElement<J>;
private readonly _combined: BaseUIElement;
private readonly _value: UIEventSource<X>
private readonly _split: (x: X) => [T, J];
constructor(a: InputElement<T>, b: InputElement<J>,
combine: (t: T, j: J) => X,
split: (x: X) => [T, J]) {
super();
this._a = a;
this._b = b;
this._split = split;
this.IsSelected = this._a.IsSelected.map((isSelected) => {
return isSelected || b.IsSelected.data
}, [b.IsSelected])
this._combined = new Combine([this._a, this._b]);
this._value = this._a.GetValue().map(
t => combine(t, this._b.GetValue().data),
[this._b.GetValue()],
)
.addCallback(x => {
const [t, j] = split(x)
this._a.GetValue().setData(t)
this._b.GetValue().setData(j)
})
}
GetValue(): UIEventSource<T> {
return this._a.GetValue();
GetValue(): UIEventSource<X> {
return this._value;
}
IsValid(t: T): boolean {
return this._a.IsValid(t);
IsValid(x: X): boolean {
const [t, j] = this._split(x)
return this._a.IsValid(t) && this._b.IsValid(j);
}
protected InnerConstructElement(): HTMLElement {
return this._combined.ConstructElement();
}
}

View file

@ -270,7 +270,10 @@ export default class ValidatedTextField {
if (tp.inputHelper) {
input = new CombinedInputElement(input, tp.inputHelper(input.GetValue(), {
location: options.location
}));
}),
(a, b) => a, // We can ignore b, as they are linked earlier
a => [a, a]
);
}
return input;
}