forked from MapComplete/MapComplete
		
	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:
		
							parent
							
								
									89f6f606c8
								
							
						
					
					
						commit
						966fcda8d1
					
				
					 20 changed files with 302 additions and 111 deletions
				
			
		|  | @ -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(); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue