| 
									
										
										
										
											2023-05-18 15:44:54 +02:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   import { UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							|  |  |  |   import { onDestroy } from "svelte" | 
					
						
							| 
									
										
										
										
											2023-05-18 15:44:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Functions as 'If', but uses 'display:hidden' instead. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   export let condition: UIEventSource<boolean> | 
					
						
							|  |  |  |   let _c = condition.data | 
					
						
							|  |  |  |   let hasBeenShownPositive = false | 
					
						
							|  |  |  |   let hasBeenShownNegative = false | 
					
						
							|  |  |  |   onDestroy( | 
					
						
							|  |  |  |     condition.addCallbackAndRun((c) => { | 
					
						
							|  |  |  |       /* Do _not_ abbreviate this as `.addCallback(c => _c = c)`. This is the same as writing `.addCallback(c => {return _c = c})`,  | 
					
						
							| 
									
										
										
										
											2023-05-18 15:44:54 +02:00
										 |  |  |         which will _unregister_ the callback if `c = true`! */ | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |       hasBeenShownPositive = hasBeenShownPositive || c | 
					
						
							|  |  |  |       hasBeenShownNegative = hasBeenShownNegative || !c | 
					
						
							|  |  |  |       _c = c | 
					
						
							|  |  |  |       return false | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   ) | 
					
						
							| 
									
										
										
										
											2023-05-18 15:44:54 +02:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | {#if hasBeenShownPositive} | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   <span class={_c ? "" : "hidden"}> | 
					
						
							|  |  |  |     <slot /> | 
					
						
							|  |  |  |   </span> | 
					
						
							| 
									
										
										
										
											2023-05-18 15:44:54 +02:00
										 |  |  | {/if} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | {#if hasBeenShownNegative} | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   <span class={_c ? "hidden" : ""}> | 
					
						
							|  |  |  |     <slot name="else" /> | 
					
						
							|  |  |  |   </span> | 
					
						
							| 
									
										
										
										
											2023-05-18 15:44:54 +02:00
										 |  |  | {/if} |