2021-07-11 15:44:17 +02:00
import { InputElement } from "./InputElement" ;
import { UIEventSource } from "../../Logic/UIEventSource" ;
import BaseUIElement from "../BaseUIElement" ;
import { Translation } from "../i18n/Translation" ;
import { SubstitutedTranslation } from "../SubstitutedTranslation" ;
2022-01-12 02:31:51 +01:00
import FeaturePipelineState from "../../Logic/State/FeaturePipelineState" ;
2021-07-11 15:44:17 +02:00
export default class InputElementWrapper < T > extends InputElement < T > {
private readonly _inputElement : InputElement < T > ;
private readonly _renderElement : BaseUIElement
2022-01-12 02:31:51 +01:00
constructor ( inputElement : InputElement < T > , translation : Translation , key : string , tags : UIEventSource < any > , state : FeaturePipelineState ) {
2021-07-11 15:44:17 +02:00
super ( )
this . _inputElement = inputElement ;
const mapping = new Map < string , BaseUIElement > ( )
mapping . set ( key , inputElement )
2022-01-12 02:31:51 +01:00
// Bit of a hack: the SubstitutedTranslation expects a special rendering, but those are formatted '{key()}' instead of '{key}', so we substitute it first
2022-01-26 21:40:38 +01:00
const newTranslations = { }
2022-01-12 02:31:51 +01:00
for ( const lang in translation . translations ) {
2022-01-26 21:40:38 +01:00
newTranslations [ lang ] = translation . translations [ lang ] . replace ( "{" + key + "}" , "{" + key + "()}" )
2022-01-12 02:31:51 +01:00
}
this . _renderElement = new SubstitutedTranslation ( new Translation ( newTranslations ) , tags , state , mapping )
2021-07-11 15:44:17 +02:00
}
GetValue ( ) : UIEventSource < T > {
return this . _inputElement . GetValue ( ) ;
}
IsValid ( t : T ) : boolean {
return this . _inputElement . IsValid ( t ) ;
}
protected InnerConstructElement ( ) : HTMLElement {
return this . _renderElement . ConstructElement ( ) ;
}
}