Skip to content

Commit 04f8a80

Browse files
authored
Merge branch 'main' into dependabot/npm_and_yarn/svelte-5.16.5
2 parents fa7f9ab + a3ca0c3 commit 04f8a80

File tree

6 files changed

+73
-10
lines changed

6 files changed

+73
-10
lines changed

src/lib/modules/modals/ModalContainer.svelte

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { onMount, type Component } from "svelte";
33
import { fly } from "svelte/transition";
44
import { modalService, type ModalOptions } from "./modal.service.svelte";
5+
import { asyncHandler } from "../utils";
56
67
interface ModalStackItem {
78
component: Component;
@@ -73,7 +74,7 @@
7374
</div>
7475
{/if}
7576
<div class="flex-grow">
76-
{#if currentModal?.options.title}
77+
{#if currentModal?.options?.title}
7778
<div>{currentModal.options.title}</div>
7879
{/if}
7980
</div>
@@ -88,6 +89,18 @@
8889
transition:fly={{ x: modalStackLength > 1 ? "100%" : "0" }}
8990
>
9091
<svelte:component this={modal.component} {...modal.options?.data} />
92+
{#if modal.options?.buttons}
93+
<div class="dialog-actions">
94+
{#each modal.options.buttons as button}
95+
<button
96+
class="btn btn-{button.color}"
97+
use:asyncHandler={() =>
98+
button.onClick({ closeModal: () => modalService.closeModal() })}
99+
>{button.text}</button
100+
>
101+
{/each}
102+
</div>
103+
{/if}
91104
</div>
92105
{/each}
93106
</div>

src/lib/modules/modals/modal.service.svelte.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface ModalOptions<RETURN_TYPE = any> {
3838
closeDialog?: (data?: RETURN_TYPE) => void | Promise<void>;
3939
/** if set, the given prop will automatically passed to the component as the closing function */
4040
closingPropName?: string;
41+
buttons?: ModalButton[];
4142
}
4243

4344
export interface ModalComponent {

src/lib/modules/navigation/Navbar.svelte

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
2-
import { type AppShellNavbarOptions } from "./app-shell-options.js";
32
import { t } from "$lib/stores/i18n.store.js";
3+
import { type AppShellNavbarOptions } from "./app-shell-options.js";
44
let { options }: { options?: AppShellNavbarOptions } = $props();
55
</script>
66

@@ -22,9 +22,19 @@
2222
<div class="flex flex-row gap-8 items-center">
2323
{#if options?.showNavigation !== false}
2424
{#each options?.navigation.entries as entry}
25-
<a class="border-b-2 menu-entry" href={entry.link}>
26-
{$t(entry.text)}
27-
</a>
25+
{#if entry.link}
26+
<a class="border-b-2 menu-entry" href={entry.link}>
27+
{$t(entry.text)}
28+
</a>
29+
{:else if entry.clickFn}
30+
<!-- svelte-ignore a11y_click_events_have_key_events -->
31+
<!-- svelte-ignore a11y_no_static_element_interactions -->
32+
<div class="border-b-2 menu-entry" onclick={() => entry.clickFn()}>
33+
{$t(entry.text)}
34+
</div>
35+
{:else}
36+
<div>{$t(entry.text)}</div>
37+
{/if}
2838
{/each}
2939
{/if}
3040
</div>

src/lib/modules/navigation/app-shell-options.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { describe, expect, it } from "vitest";
2-
import { filterAuthorizedNavigation } from "./app-shell-options.js";
2+
import {
3+
type AppShellNavbarOptions,
4+
filterAuthorizedNavigation,
5+
getComputedOptions,
6+
type AppShellOptions
7+
} from "./app-shell-options.js";
38

49
describe("AppShellOptions", () => {
510
it("should filter navigation entries based on permissions", () => {
@@ -29,4 +34,31 @@ describe("AppShellOptions", () => {
2934
expect(filteredNavigation.entries[1].text).toBe("Entry 3");
3035
expect(filteredNavigation.entries[2].text).toBe("Entry 4");
3136
});
37+
38+
it("should compute properties properly", () => {
39+
const options: AppShellOptions = {
40+
bgColor: "primary",
41+
textColor: "primary-content",
42+
navbar: {
43+
show: true,
44+
navigation: {
45+
entries: [
46+
{
47+
text: "Test",
48+
clickFn: () => {
49+
console.log("yeah");
50+
}
51+
}
52+
]
53+
},
54+
height: 64
55+
}
56+
};
57+
58+
expect(getComputedOptions<AppShellNavbarOptions>(options, "navbar").bgColor).toBe("primary");
59+
expect(
60+
typeof getComputedOptions<AppShellNavbarOptions>(options, "navbar").navigation.entries[0]
61+
.clickFn
62+
).toBe("function");
63+
});
3264
});

src/lib/modules/navigation/app-shell-options.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,11 @@ export function filterAuthorizedNavigation(
100100

101101
export function getComputedOptions<T>(options: AppShellOptions, navigationProp: string): T {
102102
if (!(navigationProp in options)) throw new Error("property " + navigationProp + " not found");
103-
const clonedOptions = JSON.parse(JSON.stringify(options));
104-
const base = clonedOptions[navigationProp];
103+
const base = options[navigationProp];
105104

106105
function useGlobalValue(propName: string): void {
107106
if (base[propName] === undefined && base[propName] !== null)
108-
base[propName] = clonedOptions[propName];
107+
base[propName] = options[propName];
109108
}
110109
useGlobalValue("logoUrl");
111110
useGlobalValue("title");
@@ -117,7 +116,7 @@ export function getComputedOptions<T>(options: AppShellOptions, navigationProp:
117116
if (base.navigation) {
118117
base.navigation = filterAuthorizedNavigation(
119118
base.navigation,
120-
clonedOptions.availablePermissions
119+
options.availablePermissions
121120
);
122121
}
123122

src/routes/robots.txt/+server.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { text } from "@sveltejs/kit";
2+
import type { RequestHandler } from "./$types";
3+
4+
export const GET: RequestHandler = async () => {
5+
// robots.txt allow everything, follow every path
6+
return text(`User-agent: *
7+
Disallow:`);
8+
};

0 commit comments

Comments
 (0)