| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import Svg from "../../Svg" | 
					
						
							|  |  |  | import Combine from "./Combine" | 
					
						
							| 
									
										
										
										
											2022-12-16 13:45:07 +01:00
										 |  |  | import { FixedUiElement } from "./FixedUiElement" | 
					
						
							|  |  |  | import { UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import Hash from "../../Logic/Web/Hash" | 
					
						
							|  |  |  | import BaseUIElement from "../BaseUIElement" | 
					
						
							|  |  |  | import Title from "./Title" | 
					
						
							| 
									
										
										
										
											2022-12-24 03:44:21 +01:00
										 |  |  | import Hotkeys from "./Hotkeys" | 
					
						
							| 
									
										
										
										
											2022-12-31 01:40:27 +01:00
										 |  |  | import Translations from "../i18n/Translations" | 
					
						
							| 
									
										
										
										
											2021-01-08 02:13:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |  * The scrollableFullScreen is a bit of a peculiar component: | 
					
						
							|  |  |  |  * - It shows a title and some contents, constructed from the respective functions passed into the constructor | 
					
						
							|  |  |  |  * - When the element is 'activated', one clone of title+contents is attached to the fullscreen | 
					
						
							|  |  |  |  * - The element itself will - upon rendering - also show the title and contents (allthough it'll be a different clone) | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-01-08 02:13:44 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2022-12-08 02:56:49 +01:00
										 |  |  | export default class ScrollableFullScreen { | 
					
						
							| 
									
										
										
										
											2022-12-13 03:46:53 +01:00
										 |  |  |     private static readonly empty = ScrollableFullScreen.initEmpty() | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     private static _currentlyOpen: ScrollableFullScreen | 
					
						
							|  |  |  |     public isShown: UIEventSource<boolean> | 
					
						
							|  |  |  |     private hashToShow: string | 
					
						
							|  |  |  |     private _fullscreencomponent: BaseUIElement | 
					
						
							|  |  |  |     private _resetScrollSignal: UIEventSource<void> = new UIEventSource<void>(undefined) | 
					
						
							| 
									
										
										
										
											2023-01-06 04:06:05 +01:00
										 |  |  |     private _setHash: boolean | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     constructor( | 
					
						
							|  |  |  |         title: (options: { mode: string }) => BaseUIElement, | 
					
						
							|  |  |  |         content: (options: { | 
					
						
							|  |  |  |             mode: string | 
					
						
							|  |  |  |             resetScrollSignal: UIEventSource<void> | 
					
						
							|  |  |  |         }) => BaseUIElement, | 
					
						
							|  |  |  |         hashToShow: string, | 
					
						
							| 
									
										
										
										
											2023-01-06 04:06:05 +01:00
										 |  |  |         isShown: UIEventSource<boolean> = new UIEventSource<boolean>(false), | 
					
						
							|  |  |  |         options?: { | 
					
						
							|  |  |  |             setHash?: boolean | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |     ) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         this.hashToShow = hashToShow | 
					
						
							|  |  |  |         this.isShown = isShown | 
					
						
							| 
									
										
										
										
											2023-01-06 04:06:05 +01:00
										 |  |  |         this._setHash = options?.setHash ?? true | 
					
						
							| 
									
										
										
										
											2021-02-25 02:23:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-06 04:06:05 +01:00
										 |  |  |         if ((hashToShow === undefined || hashToShow === "") && this._setHash) { | 
					
						
							| 
									
										
										
										
											2021-10-25 20:50:59 +02:00
										 |  |  |             throw "HashToShow should be defined as it is vital for the 'back' key functionality" | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-09 00:35:59 +01:00
										 |  |  |         const mobileOptions = { | 
					
						
							|  |  |  |             mode: "mobile", | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             resetScrollSignal: this._resetScrollSignal, | 
					
						
							| 
									
										
										
										
											2022-02-09 00:35:59 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-10-25 20:50:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         this._fullscreencomponent = this.BuildComponent( | 
					
						
							|  |  |  |             title(mobileOptions), | 
					
						
							|  |  |  |             content(mobileOptions).SetClass("pb-20") | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const self = this | 
					
						
							| 
									
										
										
										
											2023-01-06 04:06:05 +01:00
										 |  |  |         if (this._setHash) { | 
					
						
							|  |  |  |             Hash.hash.addCallback((h) => { | 
					
						
							|  |  |  |                 if (h === undefined) { | 
					
						
							|  |  |  |                     isShown.setData(false) | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-12-13 03:46:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-06 03:46:49 +01:00
										 |  |  |         isShown.addCallbackD((isShown) => { | 
					
						
							| 
									
										
										
										
											2021-02-25 02:23:26 +01:00
										 |  |  |             if (isShown) { | 
					
						
							| 
									
										
										
										
											2021-12-02 22:57:27 +01:00
										 |  |  |                 // We first must set the hash, then activate the panel
 | 
					
						
							|  |  |  |                 // If the order is wrong, this will cause the panel to disactivate again
 | 
					
						
							| 
									
										
										
										
											2022-12-13 03:46:53 +01:00
										 |  |  |                 ScrollableFullScreen._currentlyOpen = self | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 self.Activate() | 
					
						
							| 
									
										
										
										
											2021-02-25 02:23:26 +01:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2022-12-16 13:45:07 +01:00
										 |  |  |                 if (self.hashToShow !== undefined) { | 
					
						
							| 
									
										
										
										
											2022-12-13 03:46:53 +01:00
										 |  |  |                     Hash.hash.setData(undefined) | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2022-01-06 18:51:52 +01:00
										 |  |  |                 // Some cleanup...
 | 
					
						
							| 
									
										
										
										
											2022-12-09 13:58:41 +01:00
										 |  |  |                 ScrollableFullScreen.collapse() | 
					
						
							| 
									
										
										
										
											2021-02-25 02:23:26 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2023-01-06 03:46:49 +01:00
										 |  |  |         if (isShown.data) { | 
					
						
							|  |  |  |             ScrollableFullScreen._currentlyOpen = self | 
					
						
							|  |  |  |             this.Activate() | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-02-25 02:23:26 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-16 13:45:07 +01:00
										 |  |  |     private static initEmpty(): FixedUiElement { | 
					
						
							| 
									
										
										
										
											2022-12-24 03:44:21 +01:00
										 |  |  |         Hotkeys.RegisterHotkey( | 
					
						
							|  |  |  |             { nomod: "Escape", onUp: true }, | 
					
						
							| 
									
										
										
										
											2022-12-28 00:37:48 +01:00
										 |  |  |             Translations.t.hotkeyDocumentation.closeSidebar, | 
					
						
							| 
									
										
										
										
											2022-12-24 03:44:21 +01:00
										 |  |  |             ScrollableFullScreen.collapse | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2022-12-13 03:46:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return new FixedUiElement("") | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-12-16 13:45:07 +01:00
										 |  |  |     public static collapse() { | 
					
						
							| 
									
										
										
										
											2022-12-09 13:58:41 +01:00
										 |  |  |         const fs = document.getElementById("fullscreen") | 
					
						
							|  |  |  |         if (fs !== null) { | 
					
						
							|  |  |  |             ScrollableFullScreen.empty.AttachTo("fullscreen") | 
					
						
							|  |  |  |             fs.classList.add("hidden") | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-13 03:46:53 +01:00
										 |  |  |         const opened = ScrollableFullScreen._currentlyOpen | 
					
						
							| 
									
										
										
										
											2022-12-16 13:45:07 +01:00
										 |  |  |         if (opened !== undefined) { | 
					
						
							|  |  |  |             opened?.isShown?.setData(false) | 
					
						
							| 
									
										
										
										
											2022-12-13 03:46:53 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-12-09 13:58:41 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-06 18:51:52 +01:00
										 |  |  |     Destroy() { | 
					
						
							|  |  |  |         this._fullscreencomponent.Destroy() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-08 02:56:49 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Actually show this in the 'fullscreen'-div | 
					
						
							|  |  |  |      * @constructor | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public Activate(): void { | 
					
						
							| 
									
										
										
										
											2023-01-06 04:06:05 +01:00
										 |  |  |         if (this.hashToShow && this.hashToShow !== "" && this._setHash) { | 
					
						
							| 
									
										
										
										
											2023-01-06 03:46:49 +01:00
										 |  |  |             Hash.hash.setData(this.hashToShow) | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-01-06 04:06:05 +01:00
										 |  |  |         this.isShown.setData(true) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         this._fullscreencomponent.AttachTo("fullscreen") | 
					
						
							|  |  |  |         const fs = document.getElementById("fullscreen") | 
					
						
							|  |  |  |         ScrollableFullScreen._currentlyOpen = this | 
					
						
							| 
									
										
										
										
											2022-12-24 03:44:21 +01:00
										 |  |  |         fs?.classList?.remove("hidden") | 
					
						
							| 
									
										
										
										
											2021-02-25 02:23:26 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-01-18 18:52:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     private BuildComponent(title: BaseUIElement, content: BaseUIElement): BaseUIElement { | 
					
						
							|  |  |  |         const returnToTheMap = new Combine([ | 
					
						
							|  |  |  |             Svg.back_svg().SetClass("block md:hidden w-12 h-12 p-2 svg-foreground"), | 
					
						
							|  |  |  |             Svg.close_svg().SetClass("hidden md:block  w-12 h-12  p-3 svg-foreground"), | 
					
						
							|  |  |  |         ]).SetClass("rounded-full p-0 flex-shrink-0 self-center") | 
					
						
							| 
									
										
										
										
											2021-10-23 02:46:37 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         returnToTheMap.onClick(() => { | 
					
						
							| 
									
										
										
										
											2022-02-09 00:35:59 +01:00
										 |  |  |             this.isShown.setData(false) | 
					
						
							| 
									
										
										
										
											2022-01-06 18:51:52 +01:00
										 |  |  |             Hash.hash.setData(undefined) | 
					
						
							| 
									
										
										
										
											2021-10-23 02:46:37 +02:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2021-01-22 01:03:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-01 04:14:54 +01:00
										 |  |  |         title = new Title(title, 2) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         title.SetClass( | 
					
						
							|  |  |  |             "text-l sm:text-xl md:text-2xl w-full p-0 max-h-20vh overflow-y-auto self-center" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const contentWrapper = new Combine([content]).SetClass( | 
					
						
							| 
									
										
										
										
											2023-02-09 02:45:19 +01:00
										 |  |  |             "block p-2 md:pt-4 w-full h-full overflow-y-auto" | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this._resetScrollSignal.addCallback((_) => { | 
					
						
							|  |  |  |             contentWrapper.ScrollToTop() | 
					
						
							| 
									
										
										
										
											2022-02-09 00:35:59 +01:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return new Combine([ | 
					
						
							| 
									
										
										
										
											2021-01-24 18:33:16 +01:00
										 |  |  |             new Combine([ | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 new Combine([returnToTheMap, title]).SetClass( | 
					
						
							|  |  |  |                     "border-b-1 border-black shadow bg-white flex flex-shrink-0 pt-1 pb-1 md:pt-0 md:pb-0" | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |                 contentWrapper, | 
					
						
							| 
									
										
										
										
											2021-02-25 02:23:26 +01:00
										 |  |  |                 // We add an ornament which takes around 5em. This is in order to make sure the Web UI doesn't hide
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             ]).SetClass("flex flex-col h-full relative bg-white"), | 
					
						
							|  |  |  |         ]).SetClass( | 
					
						
							| 
									
										
										
										
											2023-02-09 02:45:19 +01:00
										 |  |  |             "fixed top-0 left-0 right-0 h-screen w-screen md:w-auto md:relative z-above-controls md:rounded-xl overflow-hidden" | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-01-25 03:12:09 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-01-06 03:46:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     static ActivateCurrent() { | 
					
						
							|  |  |  |         ScrollableFullScreen._currentlyOpen?.Activate() | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | } |