initial commit
Some checks failed
deploy / build-and-deploy (push) Failing after 21s

This commit is contained in:
2025-05-18 13:16:20 +02:00
commit 60f3f8a096
148 changed files with 17900 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
<script lang="ts">
import { setContext, type Snippet } from 'svelte';
import { type Writable, writable } from 'svelte/store';
// types
interface Props {
data: Writable<{ [key: string]: any }[]>;
children: Snippet;
}
// inputs
const { data, children, ...restProps }: Props & Record<string, any> = $props();
setContext('sortableHeader', {
headerKey: writable(null),
onSort: onSort
});
// functions
function onSort(key: string, order: 'asc' | 'desc') {
data.update((old) => {
old.sort((a, b) => {
let entryA = getDataEntryByKey(key, a);
let entryB = getDataEntryByKey(key, b);
if (entryA === undefined || entryB === undefined) return 0;
if (typeof entryA === 'string') entryA = entryA.toLowerCase();
if (typeof entryB === 'string') entryB = entryB.toLowerCase();
if (order === 'asc') {
return entryA < entryB ? -1 : 1;
} else if (order === 'desc') {
return entryA > entryB ? -1 : 1;
} else {
return 0;
}
});
return old;
});
}
function getDataEntryByKey(key: string, data: { [key: string]: any }): any | undefined {
let entry = data;
for (const part of key.split('.')) {
if ((entry = entry[part]) === undefined) {
return undefined;
}
}
return entry;
}
</script>
<tr {...restProps}>
{@render children()}
</tr>