forked from MapComplete/MapComplete
		
	Refactoring: move all code files into a src directory
This commit is contained in:
		
							parent
							
								
									de99f56ca8
								
							
						
					
					
						commit
						e75d2789d2
					
				
					 389 changed files with 0 additions and 12 deletions
				
			
		
							
								
								
									
										62
									
								
								src/UI/Base/VariableUIElement.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								src/UI/Base/VariableUIElement.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,62 @@ | |||
| import { Store } from "../../Logic/UIEventSource" | ||||
| import BaseUIElement from "../BaseUIElement" | ||||
| import Combine from "./Combine" | ||||
| 
 | ||||
| export class VariableUiElement extends BaseUIElement { | ||||
|     private readonly _contents?: Store<string | BaseUIElement | BaseUIElement[]> | ||||
| 
 | ||||
|     constructor(contents?: Store<string | BaseUIElement | BaseUIElement[]>) { | ||||
|         super() | ||||
|         this._contents = contents | ||||
|     } | ||||
| 
 | ||||
|     Destroy() { | ||||
|         super.Destroy() | ||||
|         this.isDestroyed = true | ||||
|     } | ||||
| 
 | ||||
|     AsMarkdown(): string { | ||||
|         const d = this._contents?.data | ||||
|         if (typeof d === "string") { | ||||
|             return d | ||||
|         } | ||||
|         if (d instanceof BaseUIElement) { | ||||
|             return d.AsMarkdown() | ||||
|         } | ||||
|         return new Combine(<BaseUIElement[]>d).AsMarkdown() | ||||
|     } | ||||
| 
 | ||||
|     protected InnerConstructElement(): HTMLElement { | ||||
|         const el = document.createElement("span") | ||||
|         const self = this | ||||
|         this._contents?.addCallbackAndRun((contents) => { | ||||
|             if (self.isDestroyed) { | ||||
|                 return true | ||||
|             } | ||||
| 
 | ||||
|             while (el.firstChild) { | ||||
|                 el.removeChild(el.lastChild) | ||||
|             } | ||||
| 
 | ||||
|             if (contents === undefined) { | ||||
|                 return | ||||
|             } | ||||
|             if (typeof contents === "string") { | ||||
|                 el.innerHTML = contents | ||||
|             } else if (contents instanceof Array) { | ||||
|                 for (const content of contents) { | ||||
|                     const c = content?.ConstructElement() | ||||
|                     if (c !== undefined && c !== null) { | ||||
|                         el.appendChild(c) | ||||
|                     } | ||||
|                 } | ||||
|             } else { | ||||
|                 const c = contents.ConstructElement() | ||||
|                 if (c !== undefined && c !== null) { | ||||
|                     el.appendChild(c) | ||||
|                 } | ||||
|             } | ||||
|         }) | ||||
|         return el | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue