| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  | import { UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							| 
									
										
										
										
											2022-11-02 14:44:06 +01:00
										 |  |  | import LayerConfig from "../../Models/ThemeConfig/LayerConfig" | 
					
						
							| 
									
										
										
										
											2025-01-27 04:50:44 +01:00
										 |  |  | import { SpecialVisualizationState, SpecialVisualizationSvelte } from "../SpecialVisualization" | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  | import SvelteUIElement from "../Base/SvelteUIElement" | 
					
						
							|  |  |  | import ShareButton from "../Base/ShareButton.svelte" | 
					
						
							| 
									
										
										
										
											2022-10-28 04:33:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-27 04:50:44 +01:00
										 |  |  | export class ShareLinkViz implements SpecialVisualizationSvelte { | 
					
						
							| 
									
										
										
										
											2022-10-28 04:33:05 +02:00
										 |  |  |     funcName = "share_link" | 
					
						
							| 
									
										
										
										
											2025-01-27 04:50:44 +01:00
										 |  |  |     group = "default" | 
					
						
							| 
									
										
										
										
											2022-10-28 04:33:05 +02:00
										 |  |  |     docs = "Creates a link that (attempts to) open the native 'share'-screen" | 
					
						
							|  |  |  |     example = | 
					
						
							|  |  |  |         "{share_link()} to share the current page, {share_link(<some_url>)} to share the given url" | 
					
						
							|  |  |  |     args = [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             name: "url", | 
					
						
							|  |  |  |             doc: "The url to share (default: current URL)", | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2023-12-25 23:55:52 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             name: "text", | 
					
						
							|  |  |  |             doc: "The text to show on the button. If none is given, will act as a titleIcon", | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2022-10-28 04:33:05 +02:00
										 |  |  |     ] | 
					
						
							| 
									
										
										
										
											2023-09-27 22:21:35 +02:00
										 |  |  |     needsUrls = [] | 
					
						
							| 
									
										
										
										
											2023-12-31 20:57:45 +01:00
										 |  |  |     svelteBased = true | 
					
						
							| 
									
										
										
										
											2022-10-28 04:33:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |     public constr( | 
					
						
							|  |  |  |         state: SpecialVisualizationState, | 
					
						
							|  |  |  |         tagSource: UIEventSource<Record<string, string>>, | 
					
						
							|  |  |  |         args: string[] | 
					
						
							|  |  |  |     ) { | 
					
						
							| 
									
										
										
										
											2023-12-25 23:55:52 +01:00
										 |  |  |         const text = args[1] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |         const generateShareData = () => { | 
					
						
							| 
									
										
										
										
											2024-10-17 04:06:03 +02:00
										 |  |  |             const title = state?.theme?.title?.txt ?? "MapComplete" | 
					
						
							| 
									
										
										
										
											2022-10-28 04:33:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-17 04:06:03 +02:00
										 |  |  |             let matchingLayer: LayerConfig = state?.theme?.getMatchingLayer(tagSource?.data) | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |             let name = | 
					
						
							|  |  |  |                 matchingLayer?.title?.GetRenderValue(tagSource.data)?.Subs(tagSource.data)?.txt ?? | 
					
						
							|  |  |  |                 tagSource.data?.name ?? | 
					
						
							|  |  |  |                 "POI" | 
					
						
							|  |  |  |             if (name) { | 
					
						
							|  |  |  |                 name = `${name} (${title})` | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 name = title | 
					
						
							| 
									
										
										
										
											2022-10-28 04:33:05 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |             let url = args[0] ?? "" | 
					
						
							|  |  |  |             if (url === "") { | 
					
						
							|  |  |  |                 url = window.location.href | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return { | 
					
						
							|  |  |  |                 title: name, | 
					
						
							|  |  |  |                 url: url, | 
					
						
							| 
									
										
										
										
											2024-10-17 04:06:03 +02:00
										 |  |  |                 text: state?.theme?.shortDescription?.txt ?? "MapComplete", | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-10-28 04:33:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-23 13:00:26 +02:00
										 |  |  |         return new SvelteUIElement(ShareButton, { generateShareData, text }) | 
					
						
							| 
									
										
										
										
											2022-10-28 04:33:05 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } |