Compare commits
	
		
			16 Commits
		
	
	
		
			1.13.4
			...
			feature/cu
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 77413c7e53 | |||
| 72e5425c08 | |||
| 53f5fa3988 | |||
| 6ef6dc0078 | |||
| b89d4f248c | |||
| 444b1f5370 | |||
| 3709881176 | |||
| a00af08b3f | |||
| 9ef34359d8 | |||
| 4d79589903 | |||
| 1386b80d0c | |||
| 286bd61497 | |||
| 50b5e4e455 | |||
| 2c91f46375 | |||
| 0cb1193269 | |||
| 564a971c63 | 
							
								
								
									
										15
									
								
								CHANGELOG.md
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								CHANGELOG.md
									
									
									
									
									
								
							| @@ -2,23 +2,8 @@ | |||||||
|  |  | ||||||
| All notable changes to this project will be documented in this file. Dates are displayed in UTC. | All notable changes to this project will be documented in this file. Dates are displayed in UTC. | ||||||
|  |  | ||||||
| #### [1.13.4](https://git.odit.services/lfk/frontend/compare/1.13.3...1.13.4) |  | ||||||
|  |  | ||||||
| - feat(donationcreate): improved focus handling [`a827279`](https://git.odit.services/lfk/frontend/commit/a82727916345c7e713d4225c4771ef3f23d1392c) |  | ||||||
| - chore(deps): remove unused [`3842d8b`](https://git.odit.services/lfk/frontend/commit/3842d8b1048ce12f0f70bf3d0530590470f0d200) |  | ||||||
| - fix(donationcreate): clearing [`9298a0d`](https://git.odit.services/lfk/frontend/commit/9298a0dc922ee5ed5b7c9017c865ad4b68fca3c8) |  | ||||||
| - feat(donationcreate): autofocus runner input on page load [`b9e2e65`](https://git.odit.services/lfk/frontend/commit/b9e2e653310c686bc06b9f27c38b49e9c6a3eaef) |  | ||||||
| - fix(DonationCreate): remove duplicate spaces from getRunnerLabel [`30a26ef`](https://git.odit.services/lfk/frontend/commit/30a26ef3ed55d072cd9bf2aea1b200fadc2a05f1) |  | ||||||
| - fix(donationcreate): improved resetAll [`7d9314f`](https://git.odit.services/lfk/frontend/commit/7d9314f05c58c1b50901f3797c0b461c4c79e5d2) |  | ||||||
| - fix(DeleteDonationModal): cannot overflow [`ca066aa`](https://git.odit.services/lfk/frontend/commit/ca066aa7a7a8d7c46e0f59370b06636faf5736ca) |  | ||||||
| - feat(donationcreate): full width [`b0063cd`](https://git.odit.services/lfk/frontend/commit/b0063cdead5f71c334c36e5587a58e957825dbcd) |  | ||||||
| - feat(donationcreate): add runner id to select [`27e7bbb`](https://git.odit.services/lfk/frontend/commit/27e7bbb9d142fbea659e89fb2335cc6c567d14ce) |  | ||||||
|  |  | ||||||
| #### [1.13.3](https://git.odit.services/lfk/frontend/compare/1.13.2...1.13.3) | #### [1.13.3](https://git.odit.services/lfk/frontend/compare/1.13.2...1.13.3) | ||||||
|  |  | ||||||
| > 19 May 2025 |  | ||||||
|  |  | ||||||
| - chore(release): 1.13.3 [`2139b19`](https://git.odit.services/lfk/frontend/commit/2139b197ba672275e2a0b5ffbcf7fa43f80874e6) |  | ||||||
| - Refactor code structure for improved readability and maintainability [`e3c6d5a`](https://git.odit.services/lfk/frontend/commit/e3c6d5a5c0eaac2c91432b0be37d6fa11e57f644) | - Refactor code structure for improved readability and maintainability [`e3c6d5a`](https://git.odit.services/lfk/frontend/commit/e3c6d5a5c0eaac2c91432b0be37d6fa11e57f644) | ||||||
| - refactor(donation): Refactor donor selection and add new donor creation functionality [`8c3f009`](https://git.odit.services/lfk/frontend/commit/8c3f0092d2735b1c85976f4e6955780b1035f68a) | - refactor(donation): Refactor donor selection and add new donor creation functionality [`8c3f009`](https://git.odit.services/lfk/frontend/commit/8c3f0092d2735b1c85976f4e6955780b1035f68a) | ||||||
| - fix(donation): Ensure all selections are cleared on reset [`4e1a944`](https://git.odit.services/lfk/frontend/commit/4e1a944a2d7d0d0666fb8d2181a9941d0f11957f) | - fix(donation): Ensure all selections are cleared on reset [`4e1a944`](https://git.odit.services/lfk/frontend/commit/4e1a944a2d7d0d0666fb8d2181a9941d0f11957f) | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ | |||||||
|  |  | ||||||
|   <body> |   <body> | ||||||
|     <span style="display: none; visibility: hidden" id="buildinfo" |     <span style="display: none; visibility: hidden" id="buildinfo" | ||||||
|       >RELEASE_INFO-1.13.4-RELEASE_INFO</span |       >RELEASE_INFO-1.13.3-RELEASE_INFO</span | ||||||
|     > |     > | ||||||
|     <noscript>You need to enable JavaScript to run this app.</noscript> |     <noscript>You need to enable JavaScript to run this app.</noscript> | ||||||
|     <script src="/env.js"></script> |     <script src="/env.js"></script> | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "@odit/lfk-frontend", |   "name": "@odit/lfk-frontend", | ||||||
|   "version": "1.13.4", |   "version": "1.13.3", | ||||||
|   "type": "module", |   "type": "module", | ||||||
|   "scripts": { |   "scripts": { | ||||||
|     "i18n-order": "node order.js", |     "i18n-order": "node order.js", | ||||||
|   | |||||||
| @@ -81,7 +81,7 @@ | |||||||
|                 /></svg |                 /></svg | ||||||
|               > |               > | ||||||
|             </div> |             </div> | ||||||
|             <div class="mt-3 sm:text-left max-h-[75vh]"> |             <div class="mt-3 sm:text-left max-h-[75vh] overflow-y-auto"> | ||||||
|               <h3 class="text-lg leading-6 font-medium text-gray-900"> |               <h3 class="text-lg leading-6 font-medium text-gray-900"> | ||||||
|                 {$_("please-confirm-the-deletion-of-donation")} |                 {$_("please-confirm-the-deletion-of-donation")} | ||||||
|               </h3> |               </h3> | ||||||
|   | |||||||
| @@ -1,394 +1,422 @@ | |||||||
| <script> | <script> | ||||||
|   import { _ } from "svelte-i18n"; | 	import { _ } from "svelte-i18n"; | ||||||
|   import { | 	import { | ||||||
|     DonationService, | 		DonationService, | ||||||
|     DonorService, | 		DonorService, | ||||||
|     RunnerService, | 		RunnerService, | ||||||
|   } from "@odit/lfk-client-js"; | 	} from "@odit/lfk-client-js"; | ||||||
|   import Select from "svelte-select"; | 	import toast from "svelte-french-toast"; | ||||||
|   import toast from "svelte-french-toast"; | 	import VirtualSelect from "./VirtualSelect.svelte"; | ||||||
| 	import { onMount } from "svelte"; | 	import { onMount } from "svelte"; | ||||||
|  |  | ||||||
|   let runners = []; | 	let runners = []; | ||||||
|   let donors = []; | 	let donors = []; | ||||||
|   let runnerinfo = { id: 0, firstname: "", lastname: "" }; | 	let runnerinfo = { id: 0, firstname: "", lastname: "" }; | ||||||
|   let donorinfo = { id: 0, firstname: "", lastname: "" }; | 	let donorinfo = { id: 0, firstname: "", lastname: "" }; | ||||||
|   let address = { | 	let address = { | ||||||
|     address1: "", | 		address1: "", | ||||||
|     address2: "", | 		address2: "", | ||||||
|     city: "", | 		city: "", | ||||||
|     postalcode: "", | 		postalcode: "", | ||||||
|     country: "Germany", | 		country: "Germany", | ||||||
|   }; | 	}; | ||||||
|   let amount = null; | 	let amount = null; | ||||||
|   let address_checked = false; | 	let address_checked = false; | ||||||
|   let donor_create_new = false; | 	let donor_create_new = false; | ||||||
|   let last_created = null; | 	let last_created = null; | ||||||
|  |  | ||||||
|   RunnerService.runnerControllerGetAll() | 	RunnerService.runnerControllerGetAll() | ||||||
|     .then((val) => { | 		.then((val) => { | ||||||
|       runners = val.map((r) => { | 			runners = val.map((r) => { | ||||||
|         return { label: getRunnerLabel(r), value: r }; | 				return { label: getRunnerLabel(r), value: r }; | ||||||
|       }); | 			}); | ||||||
|     }) | 		}) | ||||||
|     .catch((err) => { | 		.catch((err) => { | ||||||
|       console.log("error fetching runners:", err); | 			console.log("error fetching runners:", err); | ||||||
|     }); | 		}); | ||||||
|  |  | ||||||
|   function loadDonors() { | 	function loadDonors() { | ||||||
|     DonorService.donorControllerGetAll() | 		DonorService.donorControllerGetAll() | ||||||
|       .then((val) => { | 			.then((val) => { | ||||||
|         donors = val.map((r) => { | 				donors = val.map((r) => { | ||||||
|           return { label: getRunnerLabel(r), value: r }; | 					return { label: getRunnerLabel(r), value: r }; | ||||||
|         }); | 				}); | ||||||
|         console.log("refreshed donors"); | 				console.log("refreshed donors"); | ||||||
|         setTimeout(() => { | 				setTimeout(() => { | ||||||
|           loadDonors; | 					loadDonors; | ||||||
|         }, 30000); | 				}, 30000); | ||||||
|       }) | 			}) | ||||||
|       .catch((err) => { | 			.catch((err) => { | ||||||
|         console.log("error fetching donors:", err); | 				console.log("error fetching donors:", err); | ||||||
|       }); | 			}); | ||||||
|   } | 	} | ||||||
|   loadDonors(); | 	loadDonors(); | ||||||
|  |  | ||||||
|   const getRunnerLabel = (option) => { | 	const getRunnerLabel = (option) => { | ||||||
|     return [option.firstname,option.middlename,option.lastname].join(" ").replace("  "," ") + " [#"+option.id+"]"; | 		return ( | ||||||
|   } | 			[option.firstname, option.middlename, option.lastname] | ||||||
|  | 				.join(" ") | ||||||
|  | 				.replace("  ", " ") + | ||||||
|  | 			" [#" + | ||||||
|  | 			option.id + | ||||||
|  | 			"]" | ||||||
|  | 		); | ||||||
|  | 	}; | ||||||
|  |  | ||||||
|   const filterRunners = (label, filterText, option) => { | 	let selectRefRunner; | ||||||
|     if (filterText.startsWith("#")) { | 	let selectRefDonor; | ||||||
|       return option.value.id == parseInt(filterText.replace("#", "")); |  | ||||||
|     } |  | ||||||
|     return ( |  | ||||||
|       label.toLowerCase().includes(filterText.toLowerCase()) || |  | ||||||
|       option.value.toString().startsWith(filterText.toLowerCase()) |  | ||||||
|     ); |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   function resetAll() { | 	function resetAll() { | ||||||
|     runnerinfo = { id: 0, firstname: "", lastname: "" }; | 		runnerinfo = { id: 0, firstname: "", lastname: "" }; | ||||||
|     donorinfo = { id: 0, firstname: "", lastname: "" }; | 		donorinfo = { id: 0, firstname: "", lastname: "" }; | ||||||
|     amount = null; | 		amount = null; | ||||||
|     address_checked = false; | 		address_checked = false; | ||||||
|     donor_create_new = false; | 		donor_create_new = false; | ||||||
|     const clears = document.querySelectorAll(".clearSelect"); | 		selectRefRunner?.reset(); | ||||||
|     clears.forEach(c => { | 		selectRefDonor?.reset(); | ||||||
|       c.click(); | 		document.querySelector("#jjqzqicxujrnnh1x3447x18x").focus(); | ||||||
|     }); | 	} | ||||||
|     setTimeout(() => { | 	onMount(() => { | ||||||
|       document.querySelector("#wrapper_runner_select input").focus(); | 		document.querySelector("#jjqzqicxujrnnh1x3447x18x").focus(); | ||||||
|     }, 50); | 	}); | ||||||
|   } |  | ||||||
|  |  | ||||||
|   onMount(() => { |  | ||||||
|     document.querySelector("#wrapper_runner_select input").focus(); |  | ||||||
|   }) |  | ||||||
| </script> | </script> | ||||||
|  |  | ||||||
| <div class="p-4"> | <div class="p-4"> | ||||||
|   <h3 class="text-3xl font-bold">{$_("fast_donation_create")}</h3> | 	<h3 class="text-3xl font-bold">{$_("fast_donation_create")}</h3> | ||||||
|   <!--  --> | 	<!--  --> | ||||||
|   <div> | 	<div> | ||||||
|     <div class="w-full space-y-4 mb-6"> | 		<div class="w-full space-y-4 mb-6"> | ||||||
|       {#if last_created} | 			{#if last_created} | ||||||
|         <div class="mt-4 p-3 bg-green-50 border border-green-200 rounded-md"> | 				<div class="mt-4 p-3 bg-green-50 border border-green-200 rounded-md"> | ||||||
|           <p class="text-black"> | 					<p class="text-black"> | ||||||
|             {$_("last-created-donation")}: #{last_created.id}: {last_created.amountPerDistance / | 						{$_("last-created-donation")}: #{last_created.id}: {last_created.amountPerDistance / | ||||||
|               100} € für {getRunnerLabel(last_created.runner)} von {getRunnerLabel( | 							100}€ für {getRunnerLabel(last_created.runner)} von {getRunnerLabel( | ||||||
|               last_created.donor | 							last_created.donor | ||||||
|             )} | 						)} | ||||||
|           </p> | 					</p> | ||||||
|         </div> | 				</div> | ||||||
|       {/if} | 			{/if} | ||||||
|  |  | ||||||
|       <!-- Runner Selection --> | 			<!--  --> | ||||||
|       <div id="wrapper_runner_select"> | 			<h4 class="text-xl font-semibold">{$_("runner")}</h4> | ||||||
|         <h4 class="text-xl font-semibold">{$_("runner")}</h4> | 			<VirtualSelect | ||||||
|         <Select | 				inputElementID="jjqzqicxujrnnh1x3447x18x" | ||||||
|           containerClasses="rounded-md mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 border bg-gray-50 text-neutral-800 rounded-md p-2" | 				bind:this={selectRefRunner} | ||||||
|           itemFilter={(label, filterText, option) => | 				on:onClear={() => { | ||||||
|             filterRunners(label, filterText, option)} | 					console.log("Cleared selection"); | ||||||
|           items={runners} | 				}} | ||||||
|           showChevron={true} | 				options={runners} | ||||||
|           placeholder={$_("search-for-runner-by-name-or-id")} | 				filterFn={(item, searchTerm) => { | ||||||
|           noOptionsMessage={$_("no-runners-found")} | 					if (searchTerm.startsWith("#")) { | ||||||
|           on:select={(selectedValue) => { | 						const id = parseInt(searchTerm.replace("#", "")); | ||||||
|             runnerinfo = selectedValue.detail.value; | 						return item.value.id === id; | ||||||
|             document.querySelector("#donation_amount_eur").focus(); | 					} | ||||||
|           }} | 					return item.label.toLowerCase().includes(searchTerm.toLowerCase()); | ||||||
|           on:clear={() => (runnerinfo = { id: 0, firstname: "", lastname: "" })} | 				}} | ||||||
|         /> | 				bind:selected={runnerinfo} | ||||||
|       </div> | 				inputAriaLabel={$_("search-for-runner-by-name-or-id")} | ||||||
|  | 				inputPlaceholder={$_("search-for-runner-by-name-or-id")} | ||||||
|  | 				noOptionsText={$_("no-runners-found")} | ||||||
|  | 				on:onSelected={(data) => { | ||||||
|  | 					if (data.detail !== null) { | ||||||
|  | 						document.querySelector("#donation_amount_eur").focus(); | ||||||
|  | 					} | ||||||
|  | 				}} | ||||||
|  | 			/> | ||||||
|  |  | ||||||
|       <!-- Amount Input --> | 			<!-- Amount Input --> | ||||||
|       <div> | 			<div> | ||||||
|         <h4 class="text-xl font-semibold">{$_("amount-per-kilometer")}</h4> | 				<h4 class="text-xl font-semibold">{$_("amount-per-kilometer")}</h4> | ||||||
|         <div class="mt-1 flex rounded-md shadow-sm"> | 				<div class="mt-1 flex rounded-md shadow-sm"> | ||||||
|           <input | 					<input | ||||||
|             autocomplete="off" | 						autocomplete="off" | ||||||
|             class:border-red-500={!amount > 0} | 						class:border-red-500={!amount > 0} | ||||||
|             class:focus:border-red-500={!amount > 0} | 						class:focus:border-red-500={!amount > 0} | ||||||
|             class:focus:ring-red-500={!amount > 0} | 						class:focus:ring-red-500={!amount > 0} | ||||||
|             bind:value={amount} | 						bind:value={amount} | ||||||
|             on:keydown={(e)=> | 						on:keydown={(e) => { | ||||||
|             { | 							if (e.key === "Enter") { | ||||||
|               if(e.key==="Enter"){ | 								e.preventDefault(); | ||||||
|                 e.preventDefault(); | 								document.querySelector("#button_existing_donor").focus(); | ||||||
|                 document.querySelector("#button_existing_donor").focus(); | 							} | ||||||
|               } | 						}} | ||||||
|             }} | 						type="number" | ||||||
|             type="number" | 						step="0.01" | ||||||
|             step="0.01" | 						id="donation_amount_eur" | ||||||
|             id="donation_amount_eur" | 						name="donation_amount_eur" | ||||||
|             name="donation_amount_eur" | 						class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | ||||||
|             class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | 						placeholder="z.B. 1,50" | ||||||
|             placeholder="z.B. 1,50" | 					/> | ||||||
|           /> | 					<span | ||||||
|           <span | 						class="inline-flex items-center px-3 rounded-r-md border border-neutral-300 bg-neutral-50 text-neutral-500 text-sm" | ||||||
|             class="inline-flex items-center px-3 rounded-r-md border border-neutral-300 bg-neutral-50 text-neutral-500 text-sm" | 						>€</span | ||||||
|             >€</span | 					> | ||||||
|           > | 				</div> | ||||||
|         </div> | 			</div> | ||||||
|       </div> |  | ||||||
|  |  | ||||||
|       <!-- Donor Selection --> | 			<!-- Donor Selection --> | ||||||
|       <div> | 			<div> | ||||||
|         <h4 class="text-xl font-semibold">{$_("donor")}</h4> | 				<h4 class="text-xl font-semibold">{$_("donor")}</h4> | ||||||
|  |  | ||||||
|         <!-- Donor Type Toggle --> | 				<!-- Donor Type Toggle --> | ||||||
|         <div class="mb-2"> | 				<div class="mb-2"> | ||||||
|           <div class="flex border rounded-md overflow-hidden shadow-sm"> | 					<div class="flex border rounded-md overflow-hidden shadow-sm"> | ||||||
|             <button | 						<button | ||||||
|             on:keydown={(e)=> | 							on:keydown={(e) => { | ||||||
|             { | 								if (e.key === "ArrowRight") { | ||||||
|               if(e.key==="ArrowRight"){ | 									e.preventDefault(); | ||||||
|                 e.preventDefault(); | 									document.querySelector("#button_new_donor").focus(); | ||||||
|                 document.querySelector("#button_new_donor").focus(); | 									document.querySelector("#button_new_donor").click(); | ||||||
|                 document.querySelector("#button_new_donor").click(); | 								} | ||||||
|               } | 								if (e.key === "Enter") { | ||||||
|             }} | 									e.preventDefault(); | ||||||
|             id="button_existing_donor" | 									document.querySelector("#zt12c3udy3bme5bqobmqcif1").focus(); | ||||||
|             class:bg-indigo-600={!donor_create_new} | 								} | ||||||
|             class:text-white={!donor_create_new} | 							}} | ||||||
|             class="py-2 px-4 w-1/2 transition-colors" | 							id="button_existing_donor" | ||||||
|             on:click={() => { | 							class:bg-indigo-600={!donor_create_new} | ||||||
|               donor_create_new = false; | 							class:text-white={!donor_create_new} | ||||||
|               donorinfo = { id: 0, firstname: "", lastname: "" }; | 							class="py-2 px-4 w-1/2 transition-colors" | ||||||
|             }} | 							on:click={() => { | ||||||
|             > | 								donor_create_new = false; | ||||||
|             {$_("existing-donor")} | 								donorinfo = { id: 0, firstname: "", lastname: "" }; | ||||||
|           </button> | 							}} | ||||||
|           <button | 						> | ||||||
|               on:keydown={(e)=> | 							{$_("existing-donor")} | ||||||
|               { | 						</button> | ||||||
|                 if(e.key==="ArrowLeft"){ | 						<button | ||||||
|                   e.preventDefault(); | 							on:keydown={(e) => { | ||||||
|                   document.querySelector("#button_existing_donor").focus(); | 								if (e.key === "ArrowLeft") { | ||||||
|                   document.querySelector("#button_existing_donor").click(); | 									e.preventDefault(); | ||||||
|                 } | 									document.querySelector("#button_existing_donor").focus(); | ||||||
|               }} | 									document.querySelector("#button_existing_donor").click(); | ||||||
|               id="button_new_donor" | 								} | ||||||
|               class={`py-2 px-4 w-1/2 transition-colors ${donor_create_new ? "bg-indigo-600 text-white" : "bg-gray-100 text-gray-700"}`} | 								if (e.key === "Enter") { | ||||||
|               on:click={() => { | 									e.preventDefault(); | ||||||
|                 donor_create_new = true; | 									document.querySelector("#button_new_donor").click(); | ||||||
|                 donorinfo = { id: 0, firstname: "", lastname: "" }; | 								} | ||||||
|               }} | 							}} | ||||||
|             > | 							id="button_new_donor" | ||||||
|               {$_("new-donor")} | 							class={`py-2 px-4 w-1/2 transition-colors ${donor_create_new ? "bg-indigo-600 text-white" : "bg-gray-100 text-gray-700"}`} | ||||||
|             </button> | 							on:click={() => { | ||||||
|           </div> | 								donor_create_new = true; | ||||||
|         </div> | 								donorinfo = { id: 0, firstname: "", lastname: "" }; | ||||||
|  | 								setTimeout(() => { | ||||||
|  | 									document.querySelector("#firstname").focus(); | ||||||
|  | 								}, 50); | ||||||
|  | 							}} | ||||||
|  | 						> | ||||||
|  | 							{$_("new-donor")} | ||||||
|  | 						</button> | ||||||
|  | 					</div> | ||||||
|  | 				</div> | ||||||
|  |  | ||||||
|         {#if !donor_create_new} | 				{#if !donor_create_new} | ||||||
|           <Select | 					<VirtualSelect | ||||||
|             containerClasses="rounded-md mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 border bg-gray-50 text-neutral-800 rounded-md p-2" | 						inputElementID="zt12c3udy3bme5bqobmqcif1" | ||||||
|             itemFilter={(label, filterText, option) => | 						bind:this={selectRefDonor} | ||||||
|               filterRunners(label, filterText, option)} | 						on:onClear={() => { | ||||||
|             items={donors} | 							console.log("Cleared selection"); | ||||||
|             showChevron={true} | 						}} | ||||||
|             placeholder={$_("search-for-donor")} | 						options={donors} | ||||||
|             noOptionsMessage={$_("no-donors-found")} | 						filterFn={(item, searchTerm) => { | ||||||
|             on:select={(selectedValue) => { | 							return item.label | ||||||
|               donorinfo = selectedValue.detail.value; | 								.toLowerCase() | ||||||
|             }} | 								.includes(searchTerm.toLowerCase()); | ||||||
|             on:clear={() => | 						}} | ||||||
|               (donorinfo = { id: 0, firstname: "", lastname: "" })} | 						bind:selected={donorinfo} | ||||||
|           /> | 						inputAriaLabel={$_("search-for-donor")} | ||||||
|         {:else} | 						inputPlaceholder={$_("search-for-donor")} | ||||||
|           <div class="space-y-3"> | 						noOptionsText={$_("no-donors-found")} | ||||||
|             <!-- First Name --> | 						on:onSelected={(data) => { | ||||||
|             <div> | 							console.log(data.detail); | ||||||
|               <label | 							if (data.detail !== null) { | ||||||
|                 for="firstname" | 								document.querySelector("#submit_button").focus(); | ||||||
|                 class="block text-sm font-medium text-gray-700" | 								setTimeout(() => { | ||||||
|               > | 									document.querySelector("#submit_button").focus(); | ||||||
|                 {$_("first-name")} | 								}, 100); | ||||||
|               </label> | 							} | ||||||
|               <input | 						}} | ||||||
|                 type="text" | 					/> | ||||||
|                 id="firstname" | 				{:else} | ||||||
|                 bind:value={donorinfo.firstname} | 					<div class="space-y-3"> | ||||||
|                 class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | 						<!-- First Name --> | ||||||
|                 placeholder={$_("first-name")} | 						<div> | ||||||
|               /> | 							<label | ||||||
|             </div> | 								for="firstname" | ||||||
|  | 								class="block text-sm font-medium text-gray-700" | ||||||
|  | 							> | ||||||
|  | 								{$_("first-name")} | ||||||
|  | 							</label> | ||||||
|  | 							<input | ||||||
|  | 								type="text" | ||||||
|  | 								id="firstname" | ||||||
|  | 								on:keydown={(e) => { | ||||||
|  | 									if (e.key === "Enter") { | ||||||
|  | 										document.querySelector("#lastname").focus(); | ||||||
|  | 									} | ||||||
|  | 								}} | ||||||
|  | 								bind:value={donorinfo.firstname} | ||||||
|  | 								class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | ||||||
|  | 								placeholder={$_("first-name")} | ||||||
|  | 							/> | ||||||
|  | 						</div> | ||||||
|  |  | ||||||
|             <!-- Last Name --> | 						<!-- Last Name --> | ||||||
|             <div> | 						<div> | ||||||
|               <label | 							<label | ||||||
|                 for="lastname" | 								for="lastname" | ||||||
|                 class="block text-sm font-medium text-gray-700" | 								class="block text-sm font-medium text-gray-700" | ||||||
|               > | 							> | ||||||
|                 {$_("last-name")} | 								{$_("last-name")} | ||||||
|               </label> | 							</label> | ||||||
|               <input | 							<input | ||||||
|                 type="text" | 								type="text" | ||||||
|                 id="lastname" | 								id="lastname" | ||||||
|                 bind:value={donorinfo.lastname} | 								bind:value={donorinfo.lastname} | ||||||
|                 class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | 								class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | ||||||
|                 placeholder={$_("last-name")} | 								placeholder={$_("last-name")} | ||||||
|               /> | 							/> | ||||||
|             </div> | 						</div> | ||||||
|  |  | ||||||
|             <!-- Address Checkbox --> | 						<!-- Address Checkbox --> | ||||||
|             <div class="flex items-start mt-4"> | 						<div class="flex items-start mt-4"> | ||||||
|               <div class="flex items-center h-5"> | 							<div class="flex items-center h-5"> | ||||||
|                 <input | 								<input | ||||||
|                   id="address_check" | 									id="address_check" | ||||||
|                   type="checkbox" | 									type="checkbox" | ||||||
|                   bind:checked={address_checked} | 									bind:checked={address_checked} | ||||||
|                   class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded" | 									class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded" | ||||||
|                 /> | 								/> | ||||||
|               </div> | 							</div> | ||||||
|               <div class="ml-3 text-sm"> | 							<div class="ml-3 text-sm"> | ||||||
|                 <label for="address_check" class="font-medium text-gray-700"> | 								<label for="address_check" class="font-medium text-gray-700"> | ||||||
|                   {$_("receipt-needed")} | 									{$_("receipt-needed")} | ||||||
|                 </label> | 								</label> | ||||||
|               </div> | 							</div> | ||||||
|             </div> | 						</div> | ||||||
|  |  | ||||||
|             {#if address_checked} | 						{#if address_checked} | ||||||
|               <!-- Address Fields --> | 							<!-- Address Fields --> | ||||||
|               <div | 							<div | ||||||
|                 class="space-y-3 mt-3 p-3 border border-gray-200 rounded-md bg-gray-50" | 								class="space-y-3 mt-3 p-3 border border-gray-200 rounded-md bg-gray-50" | ||||||
|               > | 							> | ||||||
|                 <div> | 								<div> | ||||||
|                   <label | 									<label | ||||||
|                     for="address1" | 										for="address1" | ||||||
|                     class="block text-sm font-medium text-gray-700" | 										class="block text-sm font-medium text-gray-700" | ||||||
|                   > | 									> | ||||||
|                     {$_("address")} | 										{$_("address")} | ||||||
|                   </label> | 									</label> | ||||||
|                   <input | 									<input | ||||||
|                     type="text" | 										type="text" | ||||||
|                     id="address1" | 										id="address1" | ||||||
|                     bind:value={address.address1} | 										bind:value={address.address1} | ||||||
|                     class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | 										class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | ||||||
|                   /> | 									/> | ||||||
|                 </div> | 								</div> | ||||||
|  |  | ||||||
|                 <div> | 								<div> | ||||||
|                   <label | 									<label | ||||||
|                     for="address2" | 										for="address2" | ||||||
|                     class="block text-sm font-medium text-gray-700" | 										class="block text-sm font-medium text-gray-700" | ||||||
|                   > | 									> | ||||||
|                     {$_("apartment-suite-etc")} | 										{$_("apartment-suite-etc")} | ||||||
|                   </label> | 									</label> | ||||||
|                   <input | 									<input | ||||||
|                     type="text" | 										type="text" | ||||||
|                     id="address2" | 										id="address2" | ||||||
|                     bind:value={address.address2} | 										bind:value={address.address2} | ||||||
|                     class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | 										class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | ||||||
|                   /> | 									/> | ||||||
|                 </div> | 								</div> | ||||||
|  |  | ||||||
|                 <div class="grid grid-cols-2 gap-3"> | 								<div class="grid grid-cols-2 gap-3"> | ||||||
|                   <div> | 									<div> | ||||||
|                     <label | 										<label | ||||||
|                       for="postalcode" | 											for="postalcode" | ||||||
|                       class="block text-sm font-medium text-gray-700" | 											class="block text-sm font-medium text-gray-700" | ||||||
|                     > | 										> | ||||||
|                       {$_("zip-postal-code")} | 											{$_("zip-postal-code")} | ||||||
|                     </label> | 										</label> | ||||||
|                     <input | 										<input | ||||||
|                       type="text" | 											type="text" | ||||||
|                       id="postalcode" | 											id="postalcode" | ||||||
|                       bind:value={address.postalcode} | 											bind:value={address.postalcode} | ||||||
|                       class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | 											class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | ||||||
|                     /> | 										/> | ||||||
|                   </div> | 									</div> | ||||||
|  |  | ||||||
|                   <div> | 									<div> | ||||||
|                     <label | 										<label | ||||||
|                       for="city" | 											for="city" | ||||||
|                       class="block text-sm font-medium text-gray-700" | 											class="block text-sm font-medium text-gray-700" | ||||||
|                     > | 										> | ||||||
|                       {$_("city")} | 											{$_("city")} | ||||||
|                     </label> | 										</label> | ||||||
|                     <input | 										<input | ||||||
|                       type="text" | 											type="text" | ||||||
|                       id="city" | 											id="city" | ||||||
|                       bind:value={address.city} | 											bind:value={address.city} | ||||||
|                       class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | 											class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-neutral-300 border bg-neutral-50 text-neutral-800 p-2" | ||||||
|                     /> | 										/> | ||||||
|                   </div> | 									</div> | ||||||
|                 </div> | 								</div> | ||||||
|               </div> | 							</div> | ||||||
|             {/if} | 						{/if} | ||||||
|           </div> | 					</div> | ||||||
|         {/if} | 				{/if} | ||||||
|       </div> | 			</div> | ||||||
|       <!-- Submit Button --> | 			<!-- Submit Button --> | ||||||
|       <div class="mt-6"> | 			<div class="mt-6"> | ||||||
|         <button | 				<button | ||||||
|           id="submit_button" | 					id="submit_button" | ||||||
|           type="button" | 					type="button" | ||||||
|           class="w-full inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 disabled:bg-gray-400 disabled:cursor-not-allowed" | 					class="w-full inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 disabled:bg-gray-400 disabled:cursor-not-allowed" | ||||||
|           disabled={!amount > 0 || | 					disabled={!amount > 0 || | ||||||
|             !runnerinfo.id || | 						!runnerinfo.id || | ||||||
|             (!donorinfo.id && !donor_create_new) || | 						(!donorinfo.id && !donor_create_new) || | ||||||
|             (donor_create_new && | 						(donor_create_new && | ||||||
|               (!donorinfo.firstname || !donorinfo.lastname)) || | 							(!donorinfo.firstname || !donorinfo.lastname)) || | ||||||
|             (donor_create_new && | 						(donor_create_new && | ||||||
|               address_checked && | 							address_checked && | ||||||
|               (!address.address1 || !address.city || !address.postalcode))} | 							(!address.address1 || !address.city || !address.postalcode))} | ||||||
|           on:click={async () => { | 					on:click={async () => { | ||||||
|             if (donor_create_new) { | 						if (donor_create_new) { | ||||||
|               donorinfo = await DonorService.donorControllerPost({ | 							donorinfo = await DonorService.donorControllerPost({ | ||||||
|                 firstname: donorinfo.firstname, | 								firstname: donorinfo.firstname, | ||||||
|                 lastname: donorinfo.lastname, | 								lastname: donorinfo.lastname, | ||||||
|                 receiptNeeded: address_checked, | 								receiptNeeded: address_checked, | ||||||
|                 ...(address_checked ? { address: address } : {}), | 								...(address_checked ? { address: address } : {}), | ||||||
|               }); | 							}); | ||||||
|             } | 						} | ||||||
|  |  | ||||||
|             DonationService.donationControllerPostDistance({ | 						DonationService.donationControllerPostDistance({ | ||||||
|               donor: donorinfo.id, | 							donor: donorinfo.id, | ||||||
|               runner: runnerinfo.id, | 							runner: runnerinfo.id, | ||||||
|               amountPerDistance: amount * 100, | 							amountPerDistance: amount * 100, | ||||||
|             }) | 						}) | ||||||
|               .then((data) => { | 							.then((data) => { | ||||||
|                 last_created = data; | 								last_created = data; | ||||||
|                 toast.success($_("donation-created-successfully")); | 								toast.success($_("donation-created-successfully")); | ||||||
|                 resetAll(); | 								resetAll(); | ||||||
|                 loadDonors(); | 								loadDonors(); | ||||||
|               }) | 							}) | ||||||
|               .catch((err) => { | 							.catch((err) => { | ||||||
|                 console.error("Error creating donation:", err); | 								console.error("Error creating donation:", err); | ||||||
|                 toast.error($_("error-creating-donation")); | 								toast.error($_("error-creating-donation")); | ||||||
|               }); | 							}); | ||||||
|           }} | 					}} | ||||||
|         > | 				> | ||||||
|           {$_("create")} | 					{$_("create")} | ||||||
|         </button> | 				</button> | ||||||
|       </div> | 			</div> | ||||||
|     </div> | 		</div> | ||||||
|   </div> | 	</div> | ||||||
| </div> | </div> | ||||||
|  |  | ||||||
| <style> | <style> | ||||||
|   :global(:root) { | 	:global(:root) { | ||||||
|     --sv-bg: #ffffff; | 		--sv-bg: #ffffff; | ||||||
|   } | 	} | ||||||
| </style> | </style> | ||||||
|   | |||||||
							
								
								
									
										357
									
								
								src/components/tools/VirtualSelect.svelte
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										357
									
								
								src/components/tools/VirtualSelect.svelte
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,357 @@ | |||||||
|  | <script> | ||||||
|  | 	import { createEventDispatcher, onMount, tick } from "svelte"; | ||||||
|  |  | ||||||
|  | 	// Generate a default unique ID | ||||||
|  | 	function generateDefaultID() { | ||||||
|  | 		return "virtual-select-" + Math.random().toString(36).slice(2); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Props | ||||||
|  | 	export let options = []; | ||||||
|  | 	export let selected = null; | ||||||
|  | 	export let inputPlaceholder = "Search options..."; | ||||||
|  | 	export let noOptionsText = "No options found"; | ||||||
|  | 	export let inputAriaLabel = "Search and select an option"; | ||||||
|  | 	export let toggleAriaLabel = "Toggle dropdown"; | ||||||
|  | 	export let clearAriaLabel = "Clear selection"; | ||||||
|  | 	export let filterFn = null; // Custom filter function | ||||||
|  | 	export let autofocus = false; // Autofocus input | ||||||
|  | 	export let inputElementID = generateDefaultID(); // Input element ID | ||||||
|  |  | ||||||
|  | 	// Internal state | ||||||
|  | 	let searchTerm = ""; | ||||||
|  | 	let filteredOptions = options; | ||||||
|  | 	let isOpen = false; | ||||||
|  | 	let container; | ||||||
|  | 	let visibleItems = []; | ||||||
|  | 	let startIndex = 0; | ||||||
|  | 	let itemHeight = 40; // Fixed height for each option (in pixels) | ||||||
|  | 	let visibleCount = 10; // Default number of items to render | ||||||
|  | 	let focusedIndex = -1; // Track the focused option index (-1 means no focus) | ||||||
|  | 	let inputElement; // Reference to input element | ||||||
|  |  | ||||||
|  | 	const dispatch = createEventDispatcher(); | ||||||
|  |  | ||||||
|  | 	// Filter options based on search term | ||||||
|  | 	$: { | ||||||
|  | 		filteredOptions = searchTerm | ||||||
|  | 			? filterFn | ||||||
|  | 				? options.filter((option) => filterFn(option, searchTerm)) | ||||||
|  | 				: options.filter((option) => | ||||||
|  | 						option.label.toLowerCase().includes(searchTerm.toLowerCase()) | ||||||
|  | 					) | ||||||
|  | 			: options; | ||||||
|  | 		// Reset scroll and focus when filtered options change | ||||||
|  | 		startIndex = 0; | ||||||
|  | 		focusedIndex = -1; | ||||||
|  | 		updateVisibleItems(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Update visible items based on scroll position | ||||||
|  | 	function updateVisibleItems() { | ||||||
|  | 		if (!container) return; | ||||||
|  | 		const scrollTop = container.scrollTop; | ||||||
|  | 		startIndex = Math.floor(scrollTop / itemHeight); | ||||||
|  | 		const endIndex = Math.min( | ||||||
|  | 			startIndex + visibleCount, | ||||||
|  | 			filteredOptions.length | ||||||
|  | 		); | ||||||
|  | 		visibleItems = filteredOptions.slice(startIndex, endIndex); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Handle scroll event | ||||||
|  | 	function handleScroll() { | ||||||
|  | 		updateVisibleItems(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Calculate visible item count based on container height | ||||||
|  | 	async function updateVisibleCount() { | ||||||
|  | 		if (container) { | ||||||
|  | 			await tick(); // Wait for DOM to render | ||||||
|  | 			visibleCount = Math.ceil(container.clientHeight / itemHeight) + 2; // Buffer of 2 items | ||||||
|  | 			updateVisibleItems(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Handle option selection | ||||||
|  | 	function selectOption(option) { | ||||||
|  | 		selected = option.value; | ||||||
|  | 		isOpen = false; | ||||||
|  | 		searchTerm = option.label; // Set searchTerm to the selected option's label | ||||||
|  | 		focusedIndex = -1; | ||||||
|  | 		dispatch("onSelected", option.value); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Handle clear selection | ||||||
|  | 	function clearSelection() { | ||||||
|  | 		selected = null; | ||||||
|  | 		searchTerm = ""; | ||||||
|  | 		focusedIndex = -1; | ||||||
|  | 		dispatch("onSelected", null); | ||||||
|  | 		dispatch("onClear"); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Reset component state | ||||||
|  | 	export function reset() { | ||||||
|  | 		selected = null; | ||||||
|  | 		searchTerm = ""; | ||||||
|  | 		isOpen = false; | ||||||
|  | 		focusedIndex = -1; | ||||||
|  | 		startIndex = 0; | ||||||
|  | 		updateVisibleItems(); | ||||||
|  | 		dispatch("onSelected", null); | ||||||
|  | 		dispatch("onClear"); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Toggle dropdown | ||||||
|  | 	async function toggleDropdown() { | ||||||
|  | 		isOpen = !isOpen; | ||||||
|  | 		if (isOpen) { | ||||||
|  | 			forceVisibleItems(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Handle click outside to close dropdown | ||||||
|  | 	function handleClickOutside(event) { | ||||||
|  | 		if (!event.target.closest(".select-container")) { | ||||||
|  | 			isOpen = false; | ||||||
|  | 			focusedIndex = -1; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Handle input focus to open dropdown | ||||||
|  | 	async function handleInputFocus() { | ||||||
|  | 		// forceVisibleItems(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Handle input typing to open dropdown | ||||||
|  | 	async function handleInput() { | ||||||
|  | 		forceVisibleItems(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	async function forceVisibleItems() { | ||||||
|  | 		isOpen = true; | ||||||
|  | 		await updateVisibleCount(); // Ensure items render on focus | ||||||
|  | 		// these 2 timeouts are a more or less tmp fix for rendering items when dropdown opens | ||||||
|  | 		setTimeout(async () => { | ||||||
|  | 			await updateVisibleCount(); // Ensure items render on focus | ||||||
|  | 		}, 25); | ||||||
|  | 		setTimeout(async () => { | ||||||
|  | 			await updateVisibleCount(); // Ensure items render on focus | ||||||
|  | 		}, 50); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Handle keyboard navigation | ||||||
|  | 	function handleKeydown(event, index) { | ||||||
|  | 		if (!isOpen) return; | ||||||
|  |  | ||||||
|  | 		if (event.key === "ArrowDown") { | ||||||
|  | 			event.preventDefault(); | ||||||
|  | 			if (focusedIndex < filteredOptions.length - 1) { | ||||||
|  | 				focusedIndex += 1; | ||||||
|  | 				scrollToFocusedItem(); | ||||||
|  | 			} | ||||||
|  | 		} else if (event.key === "ArrowUp") { | ||||||
|  | 			event.preventDefault(); | ||||||
|  | 			if (focusedIndex > 0) { | ||||||
|  | 				focusedIndex -= 1; | ||||||
|  | 				scrollToFocusedItem(); | ||||||
|  | 			} else if (focusedIndex === -1 && filteredOptions.length > 0) { | ||||||
|  | 				focusedIndex = 0; | ||||||
|  | 				scrollToFocusedItem(); | ||||||
|  | 			} | ||||||
|  | 		} else if (event.key === "Enter" && index >= 0) { | ||||||
|  | 			event.preventDefault(); | ||||||
|  | 			selectOption(filteredOptions[index]); | ||||||
|  | 		} else if (event.key === "Escape") { | ||||||
|  | 			event.preventDefault(); | ||||||
|  | 			isOpen = false; | ||||||
|  | 			focusedIndex = -1; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Scroll to the focused item | ||||||
|  | 	function scrollToFocusedItem() { | ||||||
|  | 		if (!container || focusedIndex < 0) return; | ||||||
|  |  | ||||||
|  | 		const itemTop = focusedIndex * itemHeight; | ||||||
|  | 		const itemBottom = itemTop + itemHeight; | ||||||
|  | 		const containerTop = container.scrollTop; | ||||||
|  | 		const containerBottom = containerTop + container.clientHeight; | ||||||
|  |  | ||||||
|  | 		if (itemTop < containerTop) { | ||||||
|  | 			container.scrollTop = itemTop; | ||||||
|  | 		} else if (itemBottom > containerBottom) { | ||||||
|  | 			container.scrollTop = itemBottom - container.clientHeight; | ||||||
|  | 		} | ||||||
|  | 		updateVisibleItems(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Initialize container size observer and autofocus fallback | ||||||
|  | 	onMount(async () => { | ||||||
|  | 		if (container) { | ||||||
|  | 			const resizeObserver = new ResizeObserver(updateVisibleCount); | ||||||
|  | 			resizeObserver.observe(container); | ||||||
|  | 			return () => resizeObserver.disconnect(); | ||||||
|  | 		} | ||||||
|  | 		// Fallback autofocus with tick to ensure inputElement is bound | ||||||
|  | 		if (autofocus && inputElement) { | ||||||
|  | 			await tick(); | ||||||
|  | 			inputElement.focus(); | ||||||
|  | 		} | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	// Get display text for the input | ||||||
|  | 	function getDisplayText() { | ||||||
|  | 		if (!selected) return inputPlaceholder; | ||||||
|  | 		const selectedOption = options.find((option) => option.value === selected); | ||||||
|  | 		return selectedOption ? selectedOption.label : inputPlaceholder; | ||||||
|  | 	} | ||||||
|  | </script> | ||||||
|  |  | ||||||
|  | <svelte:window on:click={handleClickOutside} /> | ||||||
|  |  | ||||||
|  | <div class="select-container relative w-full"> | ||||||
|  | 	<!-- Select element with inline search --> | ||||||
|  | 	<div | ||||||
|  | 		class="border rounded-md px-3 py-2 bg-white shadow-sm flex items-center gap-2" | ||||||
|  | 		role="combobox" | ||||||
|  | 		aria-expanded={isOpen} | ||||||
|  | 	> | ||||||
|  | 		<input | ||||||
|  | 			autocomplete="off" | ||||||
|  | 			type="text" | ||||||
|  | 			id={inputElementID} | ||||||
|  | 			bind:value={searchTerm} | ||||||
|  | 			bind:this={inputElement} | ||||||
|  | 			placeholder={getDisplayText()} | ||||||
|  | 			class="w-full bg-transparent focus:outline-none {selected | ||||||
|  | 				? 'text-black' | ||||||
|  | 				: 'text-gray-700'}" | ||||||
|  | 			{autofocus} | ||||||
|  | 			on:focus={handleInputFocus} | ||||||
|  | 			on:input={handleInput} | ||||||
|  | 			on:keydown={(e) => { | ||||||
|  | 				if (e.key === "Enter" && !isOpen) { | ||||||
|  | 					toggleDropdown(); | ||||||
|  | 				} else { | ||||||
|  | 					handleKeydown(e, focusedIndex); | ||||||
|  | 				} | ||||||
|  | 			}} | ||||||
|  | 			aria-label={inputAriaLabel} | ||||||
|  | 		/> | ||||||
|  | 		{#if selected} | ||||||
|  | 			<button | ||||||
|  | 				type="button" | ||||||
|  | 				class="w-5 h-5 flex items-center justify-center text-gray-500 hover:text-gray-700" | ||||||
|  | 				on:click={clearSelection} | ||||||
|  | 				on:keydown={(e) => { | ||||||
|  | 					if (e.key === "Enter" || e.key === " ") { | ||||||
|  | 						e.preventDefault(); | ||||||
|  | 						clearSelection(); | ||||||
|  | 					} else if (e.key === "Escape") { | ||||||
|  | 						e.preventDefault(); | ||||||
|  | 						isOpen = false; | ||||||
|  | 						focusedIndex = -1; | ||||||
|  | 					} | ||||||
|  | 				}} | ||||||
|  | 				role="button" | ||||||
|  | 				tabindex="0" | ||||||
|  | 				aria-label={clearAriaLabel} | ||||||
|  | 			> | ||||||
|  | 				<svg | ||||||
|  | 					class="w-4 h-4" | ||||||
|  | 					fill="none" | ||||||
|  | 					stroke="currentColor" | ||||||
|  | 					viewBox="0 0 24 24" | ||||||
|  | 				> | ||||||
|  | 					<path | ||||||
|  | 						stroke-linecap="round" | ||||||
|  | 						stroke-linejoin="round" | ||||||
|  | 						stroke-width="2" | ||||||
|  | 						d="M6 18L18 6M6 6l12 12" | ||||||
|  | 					/> | ||||||
|  | 				</svg> | ||||||
|  | 			</button> | ||||||
|  | 		{/if} | ||||||
|  | 		<svg | ||||||
|  | 			class="w-4 h-4 text-gray-500 transform {isOpen ? 'rotate-180' : ''}" | ||||||
|  | 			fill="none" | ||||||
|  | 			stroke="currentColor" | ||||||
|  | 			viewBox="0 0 24 24" | ||||||
|  | 			on:click={toggleDropdown} | ||||||
|  | 			role="button" | ||||||
|  | 			tabindex="0" | ||||||
|  | 			on:keydown={(e) => { | ||||||
|  | 				if (e.key === "Enter") toggleDropdown(); | ||||||
|  | 				else if (e.key === "Escape") { | ||||||
|  | 					e.preventDefault(); | ||||||
|  | 					isOpen = false; | ||||||
|  | 					focusedIndex = -1; | ||||||
|  | 				} | ||||||
|  | 			}} | ||||||
|  | 			aria-label={toggleAriaLabel} | ||||||
|  | 		> | ||||||
|  | 			<path | ||||||
|  | 				stroke-linecap="round" | ||||||
|  | 				stroke-linejoin="round" | ||||||
|  | 				stroke | ||||||
|  | 				Politeness="round" | ||||||
|  | 				stroke-width="2" | ||||||
|  | 				d="M19 9l-7 7-7-7" | ||||||
|  | 			/> | ||||||
|  | 		</svg> | ||||||
|  | 	</div> | ||||||
|  |  | ||||||
|  | 	<!-- Dropdown --> | ||||||
|  | 	{#if isOpen} | ||||||
|  | 		<div | ||||||
|  | 			class="absolute z-10 w-full mt-1 bg-white border rounded-md shadow-lg max-h-80 overflow-auto" | ||||||
|  | 			bind:this={container} | ||||||
|  | 			on:scroll={handleScroll} | ||||||
|  | 			role="listbox" | ||||||
|  | 		> | ||||||
|  | 			{#if filteredOptions.length > 0} | ||||||
|  | 				<!-- Virtualized list container --> | ||||||
|  | 				<div style="height: {filteredOptions.length * itemHeight}px;"> | ||||||
|  | 					<div style="transform: translateY({startIndex * itemHeight}px);"> | ||||||
|  | 						{#each visibleItems as item, i (item.label + "-" + (startIndex + i))} | ||||||
|  | 							<div | ||||||
|  | 								class="px-3 py-2 hover:bg-blue-100 cursor-pointer {selected === | ||||||
|  | 								item.value | ||||||
|  | 									? 'bg-blue-50' | ||||||
|  | 									: ''} {focusedIndex === startIndex + i | ||||||
|  | 									? 'bg-blue-200 outline outline-2 outline-blue-500' | ||||||
|  | 									: ''}" | ||||||
|  | 								on:click={() => selectOption(item)} | ||||||
|  | 								on:keydown={(e) => handleKeydown(e, startIndex + i)} | ||||||
|  | 								role="option" | ||||||
|  | 								tabindex="0" | ||||||
|  | 								aria-selected={selected === item.value} | ||||||
|  | 							> | ||||||
|  | 								{item.label} | ||||||
|  | 							</div> | ||||||
|  | 						{/each} | ||||||
|  | 					</div> | ||||||
|  | 				</div> | ||||||
|  | 			{:else} | ||||||
|  | 				<div class="px-3 py-2 text-gray-500">{noOptionsText}</div> | ||||||
|  | 			{/if} | ||||||
|  | 		</div> | ||||||
|  | 	{/if} | ||||||
|  | </div> | ||||||
|  |  | ||||||
|  | <style> | ||||||
|  | 	/* Ensure Tailwind classes handle additional styling */ | ||||||
|  | 	:global(.select-container input:focus) { | ||||||
|  | 		border-color: #3b82f6; /* Tailwind's blue-500 */ | ||||||
|  | 	} | ||||||
|  | 	:global([role="option"]:focus) { | ||||||
|  | 		outline: 2px solid #3b82f6; | ||||||
|  | 		outline-offset: -2px; | ||||||
|  | 	} | ||||||
|  | 	:global([role="button"]:focus) { | ||||||
|  | 		outline: 2px solid #3b82f6; | ||||||
|  | 		outline-offset: -2px; | ||||||
|  | 	} | ||||||
|  | </style> | ||||||
| @@ -227,7 +227,7 @@ | |||||||
|     "enabled_large": "Aktiviert", |     "enabled_large": "Aktiviert", | ||||||
|     "english": "Englisch", |     "english": "Englisch", | ||||||
|     "enter-payment": "Zahlung eingeben", |     "enter-payment": "Zahlung eingeben", | ||||||
|     "error-creating-donation": "Fehler bei der Anlage", |     "error-creating-donation": "Fehler beim Erstellen des Sponsorings", | ||||||
|     "error-during-import": "Fehler beim Importieren", |     "error-during-import": "Fehler beim Importieren", | ||||||
|     "error-whyile-copying-to-clipboard": "Fehler beim Kopieren in die Zwischenablage", |     "error-whyile-copying-to-clipboard": "Fehler beim Kopieren in die Zwischenablage", | ||||||
|     "error_on_login": "😢Fehler beim Login", |     "error_on_login": "😢Fehler beim Login", | ||||||
|   | |||||||
| @@ -227,6 +227,7 @@ | |||||||
|     "enabled_large": "Enabled", |     "enabled_large": "Enabled", | ||||||
|     "english": "English", |     "english": "English", | ||||||
|     "enter-payment": "Enter payment", |     "enter-payment": "Enter payment", | ||||||
|  |     "error-creating-donation": "error creating the sponsoring", | ||||||
|     "error-during-import": "Error during import", |     "error-during-import": "Error during import", | ||||||
|     "error-whyile-copying-to-clipboard": "Error while copying to clipboard", |     "error-whyile-copying-to-clipboard": "Error while copying to clipboard", | ||||||
|     "error_on_login": "Error on login", |     "error_on_login": "Error on login", | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user