migrate: convert most components to svelte 5
This commit is contained in:
1 parent
d670f39f0a
commit
10ef4123da
225 files changed
+5441
-3341
No files matched your search
@@ -5,17 +5,9 @@
|
||||
|
||||
const sizes = [16, 24, 32, 48, 64, 96, 128, 256, 512]
|
||||
|
||||
export let url: string | undefined
|
||||
export let alt: string = ''
|
||||
export let title: string = ''
|
||||
export let circle: boolean = true
|
||||
|
||||
export let width: number
|
||||
export let res: number | undefined = undefined
|
||||
|
||||
const optimizeUrl = (
|
||||
url: string | undefined,
|
||||
res: number
|
||||
res: number,
|
||||
): string | undefined => {
|
||||
if (url === undefined) return
|
||||
|
||||
@@ -25,7 +17,7 @@
|
||||
if (res > -1) {
|
||||
urlObj.searchParams.append(
|
||||
'thumbnail',
|
||||
findClosestNumber(sizes, res).toString()
|
||||
findClosestNumber(sizes, res).toString(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -35,17 +27,38 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: optimizedURLs = [2, 3, 6, -1].map((n) =>
|
||||
optimizeUrl(url, (res || width) * n)
|
||||
interface Props {
|
||||
url: string | undefined
|
||||
alt?: string
|
||||
title?: string
|
||||
circle?: boolean
|
||||
width: number
|
||||
res?: number | undefined
|
||||
style?: string
|
||||
class?: string
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
url,
|
||||
alt = '',
|
||||
title = '',
|
||||
circle = true,
|
||||
width,
|
||||
res = undefined,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
let optimizedURLs = $derived(
|
||||
[2, 3, 6, -1].map((n) => optimizeUrl(url, (res || width) * n)),
|
||||
)
|
||||
export let style: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
</script>
|
||||
|
||||
{#if optimizedURLs[0] != undefined}
|
||||
<img
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
loading="lazy"
|
||||
srcset="{optimizedURLs[0]} 1x, {optimizedURLs[1]} 2x, {optimizedURLs[2]} 4x, {optimizedURLs[3]} 6x"
|
||||
src={optimizedURLs[0]}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
<script lang="ts">
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
action?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { class: clazz = '', children, action }: Props = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -8,8 +13,8 @@
|
||||
text-sm text-slate-600 dark:text-zinc-400 gap-2 flex-wrap {clazz}"
|
||||
>
|
||||
<span class="font-medium text-left">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</span>
|
||||
<hr class="border-slate-200 flex-1 w-full dark:border-zinc-800" />
|
||||
<slot name="action" />
|
||||
{@render action?.()}
|
||||
</div>
|
||||
@@ -1,15 +1,25 @@
|
||||
<script lang="ts">
|
||||
import Avatar from './Avatar.svelte'
|
||||
|
||||
export let name: string
|
||||
export let label: string | undefined = undefined
|
||||
export let icon: string | undefined = undefined
|
||||
interface Props {
|
||||
name: string
|
||||
label?: string | undefined
|
||||
icon?: string | undefined
|
||||
customIcon?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
name,
|
||||
label = undefined,
|
||||
icon = undefined,
|
||||
customIcon,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row gap-2 items-center">
|
||||
<slot name="icon">
|
||||
{#if customIcon}{@render customIcon()}{:else}
|
||||
<Avatar url={icon} width={32} />
|
||||
</slot>
|
||||
{/if}
|
||||
<div class="flex flex-col">
|
||||
<span class="font-semibold text-base">{name}</span>
|
||||
<span class="text-sm">{label}</span>
|
||||
|
||||
@@ -6,28 +6,46 @@
|
||||
import { optimizeImageURL } from '../lemmy/post/helpers'
|
||||
import FormattedNumber from '../util/FormattedNumber.svelte'
|
||||
|
||||
export let avatar: string | undefined = undefined
|
||||
export let name: string
|
||||
export let bio: string | undefined = undefined
|
||||
export let banner: string | undefined = undefined
|
||||
export let url: string | undefined = undefined
|
||||
export let stats: {
|
||||
interface Props {
|
||||
avatar?: string | undefined
|
||||
name: string
|
||||
value: string
|
||||
format?: boolean
|
||||
}[] = []
|
||||
bio?: string | undefined
|
||||
banner?: string | undefined
|
||||
url?: string | undefined
|
||||
stats?: {
|
||||
name: string
|
||||
value: string
|
||||
format?: boolean
|
||||
}[]
|
||||
center?: boolean
|
||||
class?: string
|
||||
nameDetail?: import('svelte').Snippet
|
||||
actions?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export let center: boolean = false
|
||||
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
avatar = undefined,
|
||||
name,
|
||||
bio = undefined,
|
||||
banner = undefined,
|
||||
url = undefined,
|
||||
stats = [],
|
||||
center = false,
|
||||
class: clazz = '',
|
||||
nameDetail,
|
||||
actions,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<Material
|
||||
color="transparent"
|
||||
padding="none"
|
||||
rounding="xl"
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
class="z-10 relative border-slate-200 dark:border-zinc-700 {clazz}"
|
||||
>
|
||||
{#if banner || avatar}
|
||||
@@ -72,12 +90,12 @@
|
||||
<span
|
||||
class="flex items-center gap-0 text-sm text-slate-600 dark:text-zinc-400 max-w-full w-max"
|
||||
>
|
||||
<slot name="nameDetail" />
|
||||
{@render nameDetail?.()}
|
||||
</span>
|
||||
|
||||
{#if $$slots.actions}
|
||||
{#if actions}
|
||||
<div class="flex flex-col mt-2">
|
||||
<slot name="actions" />
|
||||
{@render actions?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -118,7 +136,7 @@
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</Material>
|
||||
|
||||
|
||||
@@ -1,40 +1,58 @@
|
||||
<script lang="ts">
|
||||
import { Disclosure } from 'mono-svelte'
|
||||
import { Minus, Plus, Icon } from 'svelte-hero-icons'
|
||||
export let open: boolean = false
|
||||
export let icon: boolean = true
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
open?: boolean
|
||||
icon?: boolean
|
||||
class?: string
|
||||
title?: import('svelte').Snippet
|
||||
extended?: import('svelte').Snippet
|
||||
content?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
open = $bindable(false),
|
||||
icon = true,
|
||||
class: clazz = '',
|
||||
title,
|
||||
extended,
|
||||
content,
|
||||
children,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<Disclosure bind:open class="items-start justify-items-start gap-2 {clazz}">
|
||||
<div
|
||||
slot="summary"
|
||||
class="font-medium w-full text-left flex flex-row items-center justify-between hover:text-primary-900
|
||||
hover:dark:text-primary-100 transition-colors h-full z-0 group relative"
|
||||
>
|
||||
<div class="flex flex-row gap-1 items-center w-full">
|
||||
<slot name="title" />
|
||||
</div>
|
||||
{#if icon}
|
||||
<Icon
|
||||
src={open ? Minus : Plus}
|
||||
size="16"
|
||||
micro
|
||||
class="{open
|
||||
? ''
|
||||
: 'rotate-90'} transition-transform duration-300 ease-out"
|
||||
/>
|
||||
{/if}
|
||||
{#snippet summary()}
|
||||
<div
|
||||
class="inset-0 -z-10 opacity-0 absolute bg-slate-100 dark:bg-zinc-900 rounded-full
|
||||
group-hover:opacity-100 group-hover:-inset-1 group-hover:-inset-x-2 transition-all"
|
||||
/>
|
||||
</div>
|
||||
<slot name="extended" slot="extended" />
|
||||
<slot name="content">
|
||||
<div class="pt-2 text-slate-900 dark:text-zinc-100">
|
||||
<slot />
|
||||
class="font-medium w-full text-left flex flex-row items-center justify-between hover:text-primary-900
|
||||
hover:dark:text-primary-100 transition-colors h-full z-0 group relative"
|
||||
>
|
||||
<div class="flex flex-row gap-1 items-center w-full">
|
||||
{@render title?.()}
|
||||
</div>
|
||||
{#if icon}
|
||||
<Icon
|
||||
src={open ? Minus : Plus}
|
||||
size="16"
|
||||
micro
|
||||
class="{open
|
||||
? ''
|
||||
: 'rotate-90'} transition-transform duration-300 ease-out"
|
||||
/>
|
||||
{/if}
|
||||
<div
|
||||
class="inset-0 -z-10 opacity-0 absolute bg-slate-100 dark:bg-zinc-900 rounded-full
|
||||
group-hover:opacity-100 group-hover:-inset-1 group-hover:-inset-x-2 transition-all"
|
||||
></div>
|
||||
</div>
|
||||
</slot>
|
||||
{/snippet}
|
||||
{#snippet extended()}
|
||||
{@render extended?.()}
|
||||
{/snippet}
|
||||
{#if content}{@render content()}{:else}
|
||||
<div class="pt-2 text-slate-900 dark:text-zinc-100">
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</Disclosure>
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
import { pushState } from '$app/navigation'
|
||||
|
||||
export function showImage(url: string, alt: string = '') {
|
||||
@@ -24,13 +24,8 @@
|
||||
import { focusTrap } from 'svelte-focus-trap'
|
||||
import { t } from '$lib/translations'
|
||||
|
||||
/**
|
||||
* The full-resolution image URL
|
||||
*/
|
||||
export let alt: string = ''
|
||||
|
||||
let zoomed = false
|
||||
let sharing = false
|
||||
let zoomed = $state(false)
|
||||
let sharing = $state(false)
|
||||
|
||||
async function downloadImage(url: string) {
|
||||
sharing = true
|
||||
@@ -43,21 +38,29 @@
|
||||
sharing = false
|
||||
return file
|
||||
}
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
/**
|
||||
* The full-resolution image URL
|
||||
*/
|
||||
alt?: string
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { alt = '', class: clazz = '', children }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if $page.state.openImage || '' != ''}
|
||||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-positive-tabindex -->
|
||||
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_positive_tabindex -->
|
||||
<div
|
||||
class="fixed top-0 left-0 w-screen h-[100svh] overflow-auto bg-white/50 dark:bg-black/50
|
||||
flex flex-col z-[100] backdrop-blur-sm"
|
||||
transition:fade={{ duration: 150 }}
|
||||
on:click={() => history.back()}
|
||||
on:keydown={(e) => {
|
||||
onclick={() => history.back()}
|
||||
onkeydown={(e) => {
|
||||
if (e.key == 'Escape') history.back()
|
||||
}}
|
||||
use:focusTrap
|
||||
@@ -117,7 +120,9 @@
|
||||
title={$t('post.actions.more.share')}
|
||||
loading={sharing}
|
||||
>
|
||||
<Icon src={Share} size="20" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Share} size="20" micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => {
|
||||
@@ -141,13 +146,15 @@
|
||||
rounding="pill"
|
||||
title={$t('post.image.close')}
|
||||
>
|
||||
<Icon src={XMark} size="20" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={XMark} size="20" micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
</Material>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<button on:click={() => history.back()} class="contents {clazz}">
|
||||
<slot />
|
||||
<button onclick={() => history.back()} class="contents {clazz}">
|
||||
{@render children?.()}
|
||||
</button>
|
||||
@@ -1,14 +1,23 @@
|
||||
<script lang="ts">
|
||||
import FormattedNumber from '../util/FormattedNumber.svelte'
|
||||
|
||||
export let label: string
|
||||
export let content: string
|
||||
export let formatted: boolean = false
|
||||
interface Props {
|
||||
label: string
|
||||
content: string
|
||||
formatted?: boolean
|
||||
labelClass?: string
|
||||
contentClass?: string
|
||||
class?: string
|
||||
}
|
||||
|
||||
export let labelClass: string = ''
|
||||
export let contentClass: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
label,
|
||||
content,
|
||||
formatted = false,
|
||||
labelClass = '',
|
||||
contentClass = '',
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col {clazz}">
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { userSettings } from '$lib/settings'
|
||||
|
||||
export let width = 48
|
||||
interface Props {
|
||||
width?: number
|
||||
}
|
||||
|
||||
let { width = 48 }: Props = $props()
|
||||
|
||||
const monthColors: {
|
||||
[x: number]: string
|
||||
@@ -20,7 +24,7 @@
|
||||
12: '--hover-color-1: #228B22; --hover-color-2: #FFFFFF;',
|
||||
}
|
||||
|
||||
$: monthColor = monthColors[new Date().getMonth() + 1]
|
||||
let monthColor = $derived(monthColors[new Date().getMonth() + 1])
|
||||
</script>
|
||||
|
||||
<svg
|
||||
|
||||
@@ -12,9 +12,19 @@
|
||||
import { backOut } from 'svelte/easing'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
export let page: number = 0
|
||||
export let cursor: { next?: string; back?: string } | undefined = undefined
|
||||
export let hasMore: boolean = true
|
||||
interface Props {
|
||||
page?: number;
|
||||
cursor?: { next?: string; back?: string } | undefined;
|
||||
hasMore?: boolean;
|
||||
children?: import('svelte').Snippet;
|
||||
}
|
||||
|
||||
let {
|
||||
page = $bindable(0),
|
||||
cursor = undefined,
|
||||
hasMore = true,
|
||||
children
|
||||
}: Props = $props();
|
||||
|
||||
const dispatcher = createEventDispatcher<{ change: number; cursor: string }>()
|
||||
</script>
|
||||
@@ -23,9 +33,9 @@
|
||||
aria-label={$t('aria.pagination.nav')}
|
||||
class="flex flex-row w-full gap-4 items-center justify-center"
|
||||
>
|
||||
{#if $$slots.default}
|
||||
{#if children}
|
||||
<span class="text-sm text-slate-600 dark:text-zinc-400 font-medium">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</span>
|
||||
<hr class="border-slate-200 dark:border-zinc-800 flex-1" />
|
||||
{/if}
|
||||
@@ -41,7 +51,9 @@
|
||||
class="text-inherit dark:text-inherit disabled:!opacity-20 disabled:!bg-transparent"
|
||||
disabled={(!cursor?.back && cursor?.next) || page <= 1}
|
||||
>
|
||||
<Icon src={ChevronLeft} size="24" mini slot="suffix" />
|
||||
{#snippet suffix()}
|
||||
<Icon src={ChevronLeft} size="24" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
|
||||
{#if page}
|
||||
@@ -71,6 +83,8 @@
|
||||
class="text-inherit dark:text-inherit"
|
||||
disabled={!hasMore}
|
||||
>
|
||||
<Icon src={ChevronRight} size="24" mini slot="suffix" />
|
||||
{#snippet suffix()}
|
||||
<Icon src={ChevronRight} size="24" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
</nav>
|
||||
@@ -1,13 +1,25 @@
|
||||
<script lang="ts">
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
|
||||
export let icon: IconSource | undefined = undefined
|
||||
|
||||
export let title: string
|
||||
export let description: string | undefined = undefined
|
||||
export let center: boolean = false
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
icon?: IconSource | undefined;
|
||||
title: string;
|
||||
description?: string | undefined;
|
||||
center?: boolean;
|
||||
class?: string;
|
||||
children?: import('svelte').Snippet;
|
||||
}
|
||||
|
||||
let {
|
||||
icon = undefined,
|
||||
title,
|
||||
description = undefined,
|
||||
center = false,
|
||||
class: clazz = '',
|
||||
children
|
||||
}: Props = $props();
|
||||
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -32,5 +44,5 @@
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</div>
|
||||
@@ -1,15 +1,23 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy';
|
||||
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { tweened } from 'svelte/motion'
|
||||
|
||||
export let progress: number = 0
|
||||
interface Props {
|
||||
progress?: number;
|
||||
}
|
||||
|
||||
let { progress = 0 }: Props = $props();
|
||||
|
||||
let tween = tweened(progress, { easing: expoOut })
|
||||
|
||||
$: tween.set(progress)
|
||||
run(() => {
|
||||
tween.set(progress)
|
||||
});
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="bg-primary-900 dark:bg-primary-100 h-1 rounded-full"
|
||||
style="width: {$tween * 100}%;"
|
||||
/>
|
||||
></div>
|
||||
@@ -1,12 +1,18 @@
|
||||
<script lang="ts">
|
||||
export let small: boolean = false
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
small?: boolean;
|
||||
class?: string;
|
||||
children?: import('svelte').Snippet;
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let { small = false, class: clazz = '', children, ...rest }: Props = $props();
|
||||
|
||||
</script>
|
||||
|
||||
<span
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
class="{!small ? 'text-lg' : 'text-xs'} font-semibold {clazz}"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</span>
|
||||
@@ -1,6 +1,11 @@
|
||||
<script lang="ts">
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
class?: string;
|
||||
children?: import('svelte').Snippet;
|
||||
}
|
||||
|
||||
let { class: clazz = '', children }: Props = $props();
|
||||
|
||||
</script>
|
||||
|
||||
<aside
|
||||
@@ -8,5 +13,5 @@
|
||||
flex-col gap-4 px-6 pt-4 max-w-full w-full h-full
|
||||
overflow-auto text-sm border-slate-200 dark:border-zinc-800 {clazz}"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</aside>
|
||||
@@ -1,10 +1,12 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
import { derived as derivedStore } from 'svelte/store'
|
||||
|
||||
const calculateDockProperties = (
|
||||
settings: {
|
||||
top: boolean | null
|
||||
noGap: boolean | null
|
||||
},
|
||||
screenWidth: number
|
||||
screenWidth: number,
|
||||
): {
|
||||
noGap: boolean
|
||||
top: boolean
|
||||
@@ -35,7 +37,7 @@
|
||||
export const calculatePadding = (
|
||||
panel: boolean,
|
||||
top: boolean,
|
||||
content: boolean
|
||||
content: boolean,
|
||||
): {
|
||||
top: number
|
||||
bottom: number
|
||||
@@ -63,12 +65,15 @@
|
||||
|
||||
export let screenWidth = writable(1000)
|
||||
export let dockProps: Readable<ReturnType<typeof calculateDockProperties>> =
|
||||
derived([userSettings, screenWidth], ([$settings, $screenWidth], set) => {
|
||||
set(calculateDockProperties($settings.dock, $screenWidth))
|
||||
})
|
||||
derivedStore(
|
||||
[userSettings, screenWidth],
|
||||
([$settings, $screenWidth], set) => {
|
||||
set(calculateDockProperties($settings.dock, $screenWidth))
|
||||
},
|
||||
)
|
||||
export let contentPadding: Readable<ReturnType<typeof calculatePadding>> =
|
||||
derived(dockProps, ($dockProps, set) =>
|
||||
set(calculatePadding($dockProps.noGap, $dockProps.top, true))
|
||||
derivedStore(dockProps, ($dockProps, set) =>
|
||||
set(calculatePadding($dockProps.noGap, $dockProps.top, true)),
|
||||
)
|
||||
</script>
|
||||
|
||||
@@ -76,27 +81,47 @@
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { themeVars } from '$lib/ui/colors'
|
||||
import { routes } from '$lib/util.js'
|
||||
import { derived, writable, type Readable, type Writable } from 'svelte/store'
|
||||
import { writable, type Readable, type Writable } from 'svelte/store'
|
||||
|
||||
export let route: { id: string | null } | undefined = undefined
|
||||
interface Props {
|
||||
route?: { id: string | null } | undefined
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
navbar?: import('svelte').Snippet<[any]>
|
||||
sidebar?: import('svelte').Snippet<[any]>
|
||||
main?: import('svelte').Snippet<[any]>
|
||||
suffix?: import('svelte').Snippet<[any]>
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
$: title = route ? routes[(route.id as keyof typeof routes) ?? ''] : ''
|
||||
let {
|
||||
route = undefined,
|
||||
class: clazz = '',
|
||||
children,
|
||||
navbar,
|
||||
sidebar,
|
||||
main,
|
||||
suffix,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
$: sidePadding = calculatePadding($dockProps.noGap, $dockProps.top, false)
|
||||
$: topPanel = $dockProps.noGap && $dockProps.top
|
||||
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let title = $derived(
|
||||
route ? routes[(route.id as keyof typeof routes) ?? ''] : '',
|
||||
)
|
||||
let sidePadding = $derived(
|
||||
calculatePadding($dockProps.noGap, $dockProps.top, false),
|
||||
)
|
||||
let topPanel = $derived($dockProps.noGap && $dockProps.top)
|
||||
</script>
|
||||
|
||||
<svelte:window bind:innerWidth={$screenWidth} />
|
||||
|
||||
<div
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
class="shell bg-slate-50 dark:bg-zinc-950 {clazz}"
|
||||
style={$themeVars}
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
<div
|
||||
class="
|
||||
{$dockProps.noGap ? '' : 'p-4 max-w-3xl left-1/2 -translate-x-1/2'}
|
||||
@@ -108,47 +133,48 @@
|
||||
transition-duration: 250ms;
|
||||
transition-timing-function: cubic-bezier(0.075, 0.82, 0.165, 1);"
|
||||
>
|
||||
<slot
|
||||
name="navbar"
|
||||
class="
|
||||
{$dockProps.noGap
|
||||
? $dockProps.top
|
||||
? 'border-b shadow-none rounded-none'
|
||||
: 'border-t rounded-none'
|
||||
: 'border rounded-full'}
|
||||
{@render navbar?.({
|
||||
class: `
|
||||
${
|
||||
$dockProps.noGap
|
||||
? $dockProps.top
|
||||
? 'border-b shadow-none rounded-none'
|
||||
: 'border-t rounded-none'
|
||||
: 'border rounded-full'
|
||||
}
|
||||
|
||||
dark:bg-transparent transition-colors duration-500
|
||||
pointer-events-auto backdrop-blur-xl {topPanel
|
||||
? 'bg-slate-50/50 dark:bg-zinc-950/90 border-slate-100 dark:border-zinc-900'
|
||||
: `border-slate-200 dark:border-zinc-800 shadow-2xl
|
||||
bg-white/50 dark:bg-zinc-950/70`}"
|
||||
{title}
|
||||
style="transition: border-radius 250ms;"
|
||||
/>
|
||||
pointer-events-auto backdrop-blur-xl ${
|
||||
topPanel
|
||||
? 'bg-slate-50/50 dark:bg-zinc-950/90 border-slate-100 dark:border-zinc-900'
|
||||
: `border-slate-200 dark:border-zinc-800 shadow-2xl
|
||||
bg-white/50 dark:bg-zinc-950/70`
|
||||
}`,
|
||||
title,
|
||||
style: 'transition: border-radius 250ms;',
|
||||
})}
|
||||
</div>
|
||||
<div
|
||||
class="content divide-x divide-slate-100 dark:divide-zinc-900 min-h-screen {$userSettings.newWidth
|
||||
? 'limit-width'
|
||||
: ''}"
|
||||
>
|
||||
<slot
|
||||
name="sidebar"
|
||||
class="hidden md:flex sticky top-0 left-0 h-max bg-slate-50 dark:bg-zinc-950
|
||||
{@render sidebar?.({
|
||||
class: `hidden md:flex sticky top-0 left-0 h-max bg-slate-50 dark:bg-zinc-950
|
||||
z-40
|
||||
{sidePadding.class}"
|
||||
style="grid-area: sidebar; width: 100% !important;"
|
||||
/>
|
||||
<slot
|
||||
name="main"
|
||||
class="w-full bg-slate-25 dark:bg-zinc-925 justify-self-center shadow-sm z-0
|
||||
{$contentPadding.class} main"
|
||||
style="grid-area: main"
|
||||
/>
|
||||
<slot
|
||||
name="suffix"
|
||||
class="max-xl:hidden w-full sticky top-0 left-0 max-h-screen bg-slate-50 dark:bg-zinc-950 z-40 {sidePadding.class}"
|
||||
style="grid-area: suffix;"
|
||||
/>
|
||||
${sidePadding.class}`,
|
||||
style: 'grid-area: sidebar; width: 100% !important;',
|
||||
})}
|
||||
{@render main?.({
|
||||
class: `w-full bg-slate-25 dark:bg-zinc-925 justify-self-center shadow-sm z-0
|
||||
${$contentPadding.class} main`,
|
||||
style: 'grid-area: main',
|
||||
})}
|
||||
{@render suffix?.({
|
||||
class:
|
||||
'max-xl:hidden w-full sticky top-0 left-0 max-h-screen bg-slate-50 dark:bg-zinc-950 z-40 {sidePadding.class}',
|
||||
style: 'grid-area: suffix;',
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -2,11 +2,21 @@
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { contentPadding } from '../Shell.svelte'
|
||||
|
||||
export let pageHeader = false
|
||||
interface Props {
|
||||
pageHeader?: boolean
|
||||
style?: string
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
extended?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
export let style: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
pageHeader = false,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
children,
|
||||
extended,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -27,11 +37,11 @@
|
||||
class="text-3xl font-medium flex gap-2 w-full
|
||||
{$userSettings.font == 'satoshi/nunito' ? 'font-display' : ''} {clazz ?? ''}"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</h1>
|
||||
{#if $$slots.extended}
|
||||
{#if extended}
|
||||
<div class="mt-4">
|
||||
<slot name="extended" />
|
||||
{@render extended?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -3,25 +3,34 @@
|
||||
import { page } from '$app/stores'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
export let routes: {
|
||||
href: string
|
||||
name: string
|
||||
}[]
|
||||
export let currentRoute: string | undefined = undefined
|
||||
export let isSelected: (
|
||||
url: URL,
|
||||
currentRoute: string | undefined,
|
||||
route: string,
|
||||
defaultRoute?: string
|
||||
) => boolean = (url, currentRoute, route) =>
|
||||
(currentRoute ?? url.pathname) == route
|
||||
export let buildUrl: (
|
||||
currentRoute: string | undefined,
|
||||
href: string
|
||||
) => string = (route, href) => href
|
||||
export let defaultRoute: string | undefined = undefined
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
routes: {
|
||||
href: string
|
||||
name: string
|
||||
}[]
|
||||
currentRoute?: string | undefined
|
||||
isSelected?: (
|
||||
url: URL,
|
||||
currentRoute: string | undefined,
|
||||
route: string,
|
||||
defaultRoute?: string,
|
||||
) => boolean
|
||||
buildUrl?: (currentRoute: string | undefined, href: string) => string
|
||||
defaultRoute?: string | undefined
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
routes,
|
||||
currentRoute = undefined,
|
||||
isSelected = (url, currentRoute, route) =>
|
||||
(currentRoute ?? url.pathname) == route,
|
||||
buildUrl = (route, href) => href,
|
||||
defaultRoute = undefined,
|
||||
class: clazz = '',
|
||||
children,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<nav
|
||||
@@ -32,7 +41,7 @@
|
||||
>
|
||||
{#each routes as route}
|
||||
<a
|
||||
on:click={() => invalidate(route.href)}
|
||||
onclick={() => invalidate(route.href)}
|
||||
href={buildUrl(currentRoute, route.href)}
|
||||
class="font-medium rounded-full px-4 py-1 hover:bg-slate-200/40 hover:dark:bg-zinc-700/40
|
||||
transition-colors duration-100 relative z-0 flex-shrink-0"
|
||||
@@ -46,5 +55,5 @@
|
||||
{/if}
|
||||
</a>
|
||||
{/each}
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</nav>
|
||||
@@ -8,12 +8,16 @@
|
||||
function action(detail: any) {
|
||||
dispatcher('action', detail)
|
||||
}
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
class?: string
|
||||
children?: import('svelte').Snippet<[any]>
|
||||
}
|
||||
|
||||
let { class: clazz = '', children }: Props = $props()
|
||||
</script>
|
||||
|
||||
<ul
|
||||
class="divide-y divide-slate-200 dark:divide-zinc-900 flex flex-col {clazz}"
|
||||
>
|
||||
<slot {action} />
|
||||
{@render children?.({ action })}
|
||||
</ul>
|
||||
@@ -1,3 +1,13 @@
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<div class="p-2 flex flex-row">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</div>
|
||||
@@ -4,24 +4,41 @@
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
import { dockProps } from '../layout/Shell.svelte'
|
||||
|
||||
export let label: string
|
||||
export let icon: IconSource | undefined = undefined
|
||||
export let href: string | undefined = undefined
|
||||
|
||||
export let adaptive: boolean = true
|
||||
|
||||
export let isSelectedFilter: (path: string) => boolean = (path) =>
|
||||
href != undefined && path == href
|
||||
|
||||
$: isSelected = isSelectedFilter($page.url.pathname)
|
||||
$: isPanel = adaptive ? $dockProps.noGap : false
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
label: string;
|
||||
icon?: IconSource | undefined;
|
||||
href?: string | undefined;
|
||||
adaptive?: boolean;
|
||||
isSelectedFilter?: (path: string) => boolean;
|
||||
class?: string;
|
||||
customIcon?: import('svelte').Snippet<[any]>;
|
||||
children?: import('svelte').Snippet;
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
label,
|
||||
icon = undefined,
|
||||
href = undefined,
|
||||
adaptive = true,
|
||||
isSelectedFilter = (path) =>
|
||||
href != undefined && path == href,
|
||||
class: clazz = '',
|
||||
customIcon,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props();
|
||||
|
||||
let isSelected = $derived(isSelectedFilter($page.url.pathname))
|
||||
let isPanel = $derived(adaptive ? $dockProps.noGap : false)
|
||||
</script>
|
||||
|
||||
<Button
|
||||
color={isPanel ? 'secondary' : 'tertiary'}
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
on:click
|
||||
on:contextmenu
|
||||
class="rounded-full w-10 h-10 flex-shrink-0 {adaptive
|
||||
@@ -43,8 +60,8 @@
|
||||
size={isPanel ? '16' : '18'}
|
||||
/>
|
||||
{:else}
|
||||
<slot size={isPanel ? 16 : 18} {isSelected} name="icon" />
|
||||
{@render customIcon?.({ size: isPanel ? 16 : 18, isSelected, })}
|
||||
{/if}
|
||||
<span class="hidden {adaptive ? '@3xl:block' : ''}">{label}</span>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</Button>
|
||||
@@ -39,10 +39,13 @@
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { dockProps } from '../layout/Shell.svelte'
|
||||
|
||||
let promptOpen: boolean = false
|
||||
export let style: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let promptOpen: boolean = $state(false)
|
||||
interface Props {
|
||||
style?: string
|
||||
class?: string
|
||||
}
|
||||
|
||||
let { style = '', class: clazz = '' }: Props = $props()
|
||||
</script>
|
||||
|
||||
<CommandsWrapper bind:open={promptOpen} />
|
||||
@@ -64,7 +67,7 @@
|
||||
class="ml-2 logo"
|
||||
adaptive={false}
|
||||
>
|
||||
<svelte:fragment slot="icon">
|
||||
{#snippet icon()}
|
||||
{#if LINKED_INSTANCE_URL}
|
||||
{#if $site}
|
||||
<Avatar
|
||||
@@ -79,13 +82,13 @@
|
||||
{:else}
|
||||
<Logo width={32} />
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
</NavButton>
|
||||
<div
|
||||
class="flex flex-row gap-2 py-2 px-2 items-center w-full overflow-auto"
|
||||
style="border-radius: inherit;"
|
||||
>
|
||||
<div class="ml-auto" />
|
||||
<div class="ml-auto"></div>
|
||||
{#if $profile?.user && isAdmin($profile.user)}
|
||||
<NavButton
|
||||
href="/admin"
|
||||
@@ -97,7 +100,7 @@
|
||||
{#if ($notifications.applications ?? 0) > 0}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
|
||||
/>
|
||||
></div>
|
||||
{/if}
|
||||
</NavButton>
|
||||
{/if}
|
||||
@@ -110,15 +113,11 @@
|
||||
{#if ($notifications.reports ?? 0) > 0}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
|
||||
/>
|
||||
></div>
|
||||
{/if}
|
||||
<ShieldIcon
|
||||
let:size
|
||||
let:isSelected
|
||||
slot="icon"
|
||||
filled={isSelected}
|
||||
width={size}
|
||||
/>
|
||||
{#snippet customIcon({ size, isSelected })}
|
||||
<ShieldIcon filled={isSelected} width={size} />
|
||||
{/snippet}
|
||||
</NavButton>
|
||||
{/if}
|
||||
<NavButton
|
||||
@@ -128,16 +127,19 @@
|
||||
/>
|
||||
<NavButton href="/search" label={$t('nav.search')} icon={MagnifyingGlass} />
|
||||
<Menu placement="top">
|
||||
<NavButton
|
||||
class="relative"
|
||||
color="primary"
|
||||
slot="target"
|
||||
label={$t('nav.create.label')}
|
||||
icon={Plus}
|
||||
/>
|
||||
{#snippet target()}
|
||||
<NavButton
|
||||
class="relative"
|
||||
color="primary"
|
||||
label={$t('nav.create.label')}
|
||||
icon={Plus}
|
||||
/>
|
||||
{/snippet}
|
||||
<MenuDivider>{$t('nav.create.label')}</MenuDivider>
|
||||
<MenuButton link href="/create/post" disabled={!$profile?.jwt}>
|
||||
<Icon src={PencilSquare} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={PencilSquare} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('nav.create.post')}
|
||||
</MenuButton>
|
||||
<MenuButton
|
||||
@@ -148,7 +150,9 @@
|
||||
($site?.site_view.local_site.community_creation_admin_only &&
|
||||
!isAdmin($profile.user))}
|
||||
>
|
||||
<Icon src={Newspaper} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Newspaper} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('nav.create.community')}
|
||||
</MenuButton>
|
||||
{#if !$profile?.jwt}
|
||||
@@ -166,7 +170,7 @@
|
||||
<img
|
||||
src={optimizeImageURL(
|
||||
$profile?.user?.local_user_view.person.avatar ?? '',
|
||||
32
|
||||
32,
|
||||
)}
|
||||
class="blur-2xl -z-10 object-cover w-48 h-48 opacity-20 dark:opacity-50 ml-auto"
|
||||
alt=""
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { stopPropagation } from 'svelte/legacy'
|
||||
|
||||
import { notifications, profile } from '$lib/auth'
|
||||
|
||||
import {
|
||||
@@ -38,9 +40,14 @@
|
||||
import { t } from '$lib/translations'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
|
||||
let showInstance = false
|
||||
let showInstance = $state(false)
|
||||
|
||||
export let buttonClass: string = ''
|
||||
interface Props {
|
||||
buttonClass?: string
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let { buttonClass = '', ...rest }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if showInstance}
|
||||
@@ -58,35 +65,36 @@
|
||||
</Modal>
|
||||
{/if}
|
||||
|
||||
<Menu {...$$restProps}>
|
||||
<button
|
||||
class="w-10 h-10 rounded-full border-2 border-slate-200 dark:border-zinc-700
|
||||
transition-all bg-slate-50 dark:bg-zinc-900 relative
|
||||
hover:border-primary-900 hover:dark:border-primary-100 active:scale-95 {buttonClass}"
|
||||
title={$t('profile.profile')}
|
||||
slot="target"
|
||||
>
|
||||
{#if $profile?.user}
|
||||
<div
|
||||
class="w-full h-full aspect-square object-cover rounded-full grid place-items-center"
|
||||
>
|
||||
<Avatar
|
||||
url={$profile.user.local_user_view.person.avatar}
|
||||
width={36}
|
||||
alt={$profile.user.local_user_view.person.name}
|
||||
/>
|
||||
</div>
|
||||
{#if $notifications.inbox > 0}
|
||||
<Menu {...rest}>
|
||||
{#snippet target()}
|
||||
<button
|
||||
class="w-10 h-10 rounded-full border-2 border-slate-200 dark:border-zinc-700
|
||||
transition-all bg-slate-50 dark:bg-zinc-900 relative
|
||||
hover:border-primary-900 hover:dark:border-primary-100 active:scale-95 {buttonClass}"
|
||||
title={$t('profile.profile')}
|
||||
>
|
||||
{#if $profile?.user}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute top-0 left-0 z-10"
|
||||
/>
|
||||
class="w-full h-full aspect-square object-cover rounded-full grid place-items-center"
|
||||
>
|
||||
<Avatar
|
||||
url={$profile.user.local_user_view.person.avatar}
|
||||
width={36}
|
||||
alt={$profile.user.local_user_view.person.name}
|
||||
/>
|
||||
</div>
|
||||
{#if $notifications.inbox > 0}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute top-0 left-0 z-10"
|
||||
></div>
|
||||
{/if}
|
||||
{:else}
|
||||
<div class="w-full h-full grid place-items-center">
|
||||
<Icon src={Bars3} micro size="18" />
|
||||
</div>
|
||||
{/if}
|
||||
{:else}
|
||||
<div class="w-full h-full grid place-items-center">
|
||||
<Icon src={Bars3} micro size="18" />
|
||||
</div>
|
||||
{/if}
|
||||
</button>
|
||||
</button>
|
||||
{/snippet}
|
||||
{#if $profile?.user}
|
||||
<UserLink
|
||||
user={$profile?.user.local_user_view.person}
|
||||
@@ -101,11 +109,15 @@
|
||||
{/if}
|
||||
{#if $profile?.jwt}
|
||||
<MenuButton link href="/profile">
|
||||
<Icon src={UserCircle} micro width={16} slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={UserCircle} micro width={16} />
|
||||
{/snippet}
|
||||
{$t('profile.profile')}
|
||||
</MenuButton>
|
||||
<MenuButton link href="/inbox">
|
||||
<Icon src={Inbox} micro width={16} slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Inbox} micro width={16} />
|
||||
{/snippet}
|
||||
{$t('profile.inbox')}
|
||||
{#if $notifications.inbox > 0}
|
||||
<Badge color="red-subtle" class="text-xs ml-auto font-bold !py-0.5">
|
||||
@@ -114,36 +126,43 @@
|
||||
{/if}
|
||||
</MenuButton>
|
||||
<MenuButton link href="/saved">
|
||||
<Icon src={Bookmark} micro width={16} slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Bookmark} micro width={16} />
|
||||
{/snippet}
|
||||
{$t('profile.saved')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuButton link href="/accounts">
|
||||
<Icon src={UserGroup} micro width={16} slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={UserGroup} micro width={16} />
|
||||
{/snippet}
|
||||
{$t('account.accounts')}
|
||||
</MenuButton>
|
||||
<MenuDivider>{$t('nav.menu.app')}</MenuDivider>
|
||||
<MenuButton link href="/settings">
|
||||
<Icon src={Cog6Tooth} micro width={16} slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Cog6Tooth} micro width={16} />
|
||||
{/snippet}
|
||||
{$t('nav.menu.settings')}
|
||||
</MenuButton>
|
||||
<MenuButton class="!py-0">
|
||||
<Icon
|
||||
src={$colorScheme == 'system'
|
||||
? ComputerDesktop
|
||||
: $colorScheme == 'light'
|
||||
? Sun
|
||||
: $colorScheme == 'dark'
|
||||
? Moon
|
||||
: Moon}
|
||||
micro
|
||||
size="16"
|
||||
slot="prefix"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={$colorScheme == 'system'
|
||||
? ComputerDesktop
|
||||
: $colorScheme == 'light'
|
||||
? Sun
|
||||
: $colorScheme == 'dark'
|
||||
? Moon
|
||||
: Moon}
|
||||
micro
|
||||
size="16"
|
||||
/>
|
||||
{/snippet}
|
||||
<span>{$t('nav.menu.colorscheme.label')}</span>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<div class="contents" on:click|stopPropagation={() => {}}>
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div class="contents" onclick={stopPropagation(() => {})}>
|
||||
<Select bind:value={$colorScheme} class="ml-auto my-auto w-24" size="sm">
|
||||
<option value="system">
|
||||
<Icon src={ComputerDesktop} size="16" micro />
|
||||
@@ -161,23 +180,27 @@
|
||||
</div>
|
||||
</MenuButton>
|
||||
<MenuButton href="/theme">
|
||||
<Icon src={Swatch} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Swatch} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('nav.menu.theme')}
|
||||
</MenuButton>
|
||||
{#if $userSettings.debugInfo}
|
||||
<MenuButton link href="/util">
|
||||
<Icon src={BugAnt} mini width={16} slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={BugAnt} mini width={16} />
|
||||
{/snippet}
|
||||
Debug
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<hr class="dark:opacity-10 w-[90%] my-2 mx-auto" />
|
||||
<li class="flex flex-col px-2 py-1 mx-auto my-1 text-xs w-full">
|
||||
<div class="flex flex-row gap-2 w-full items-center">
|
||||
<!-- svelte-ignore missing-declaration -->
|
||||
<!-- svelte-ignore missing_declaration -->
|
||||
<div class="flex-1">
|
||||
<button
|
||||
class="hover:brightness-110 transition-all"
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
navigator?.clipboard?.writeText(__VERSION__)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
|
||||
@@ -9,9 +9,14 @@
|
||||
import Avatar from '../../Avatar.svelte'
|
||||
import type { Action } from './actions'
|
||||
|
||||
export let action: Action
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
action: Action;
|
||||
class?: string;
|
||||
children?: import('svelte').Snippet;
|
||||
}
|
||||
|
||||
let { action, class: clazz = '', children }: Props = $props();
|
||||
|
||||
</script>
|
||||
|
||||
<Button
|
||||
@@ -29,7 +34,7 @@
|
||||
{:else}
|
||||
<Icon src={action.icon ?? QuestionMarkCircle} size="20" />
|
||||
{/if}
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
<span class="mr-auto inline-flex flex-col">
|
||||
<span>{action.name}</span>
|
||||
{#if action.detail}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy';
|
||||
|
||||
import { resumables } from '$lib/lemmy/item'
|
||||
import { TextInput } from 'mono-svelte'
|
||||
import { createEventDispatcher, onMount } from 'svelte'
|
||||
@@ -12,25 +14,21 @@
|
||||
import { themeData } from '$lib/ui/colors'
|
||||
import { page } from '$app/stores'
|
||||
|
||||
export let open = false
|
||||
$: if (open) search = ''
|
||||
|
||||
export let groups: Group[] = []
|
||||
interface Props {
|
||||
open?: boolean;
|
||||
groups?: Group[];
|
||||
}
|
||||
|
||||
$: groups = getGroups(
|
||||
$resumables,
|
||||
$profile,
|
||||
$profileData.profiles,
|
||||
$themeData,
|
||||
$page.data.contextual?.actions
|
||||
)
|
||||
let { open = $bindable(false), groups = $bindable([]) }: Props = $props();
|
||||
|
||||
let search = ''
|
||||
let container: HTMLElement
|
||||
|
||||
let search = $state('')
|
||||
let container: HTMLElement = $state()
|
||||
const dispatch = createEventDispatcher()
|
||||
let selectedIndex = 0
|
||||
let filteredGroups: Group[] = []
|
||||
let breadcrumbs: Action[] = []
|
||||
let selectedIndex = $state(0)
|
||||
let filteredGroups: Group[] = $state([])
|
||||
let breadcrumbs: Action[] = $state([])
|
||||
|
||||
function fuzzySearch(text: string, pattern: string): number {
|
||||
const textLower = text.toLowerCase()
|
||||
@@ -132,8 +130,6 @@
|
||||
updateFilteredGroups()
|
||||
}
|
||||
|
||||
$: flattenedActions = filteredGroups.flatMap((group) => group.actions)
|
||||
$: debouncedSearch(search)
|
||||
|
||||
function flattenActions(
|
||||
actions: Action[],
|
||||
@@ -232,9 +228,25 @@
|
||||
afterNavigate(() => {
|
||||
// open = false
|
||||
})
|
||||
run(() => {
|
||||
if (open) search = ''
|
||||
});
|
||||
run(() => {
|
||||
groups = getGroups(
|
||||
$resumables,
|
||||
$profile,
|
||||
$profileData.profiles,
|
||||
$themeData,
|
||||
$page.data.contextual?.actions
|
||||
)
|
||||
});
|
||||
let flattenedActions = $derived(filteredGroups.flatMap((group) => group.actions))
|
||||
run(() => {
|
||||
debouncedSearch(search)
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:window on:keydown={handleKeydown} />
|
||||
<svelte:window onkeydown={handleKeydown} />
|
||||
|
||||
<TextInput bind:value={search} autofocus class="sticky font-mono" />
|
||||
<div class="h-96 overflow-auto border-slate-200 dark:border-zinc-800">
|
||||
@@ -242,7 +254,7 @@
|
||||
<div class="flex items-center gap-2 my-1">
|
||||
<button
|
||||
class="text-[13px] font-medium text-slate-600 dark:text-zinc-400"
|
||||
on:click={goBack}
|
||||
onclick={goBack}
|
||||
>
|
||||
<Icon src={Home} size="16" mini />
|
||||
</button>
|
||||
|
||||
@@ -4,7 +4,11 @@
|
||||
import Commands from './Commands.svelte'
|
||||
import { CommandLine, Icon } from 'svelte-hero-icons'
|
||||
|
||||
export let open: boolean = false
|
||||
interface Props {
|
||||
open?: boolean;
|
||||
}
|
||||
|
||||
let { open = $bindable(false) }: Props = $props();
|
||||
|
||||
function handleKeydown(event: KeyboardEvent) {
|
||||
if (
|
||||
@@ -17,24 +21,26 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window on:keydown={handleKeydown} />
|
||||
<svelte:window onkeydown={handleKeydown} />
|
||||
|
||||
{#if open}
|
||||
<Modal bind:open>
|
||||
<span slot="title" class="flex items-center gap-1">
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
fill="currentColor"
|
||||
viewBox="15 15 70 70"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M45 20.8868C48.094 19.1004 51.906 19.1004 55 20.8868L72.7128 31.1132C75.8068 32.8996 77.7128 36.2008 77.7128 39.7735V60.2265C77.7128 63.7992 75.8068 67.1004 72.7128 68.8867L55 79.1133C51.906 80.8996 48.094 80.8996 45 79.1133L27.2872 68.8867C24.1932 67.1004 22.2872 63.7992 22.2872 60.2265V39.7735C22.2872 36.2008 24.1932 32.8996 27.2872 31.1132L45 20.8868Z"
|
||||
/>
|
||||
</svg>
|
||||
{$t('nav.commands.prompt')}
|
||||
</span>
|
||||
{#snippet title()}
|
||||
<span class="flex items-center gap-1">
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
fill="currentColor"
|
||||
viewBox="15 15 70 70"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M45 20.8868C48.094 19.1004 51.906 19.1004 55 20.8868L72.7128 31.1132C75.8068 32.8996 77.7128 36.2008 77.7128 39.7735V60.2265C77.7128 63.7992 75.8068 67.1004 72.7128 68.8867L55 79.1133C51.906 80.8996 48.094 80.8996 45 79.1133L27.2872 68.8867C24.1932 67.1004 22.2872 63.7992 22.2872 60.2265V39.7735C22.2872 36.2008 24.1932 32.8996 27.2872 31.1132L45 20.8868Z"
|
||||
/>
|
||||
</svg>
|
||||
{$t('nav.commands.prompt')}
|
||||
</span>
|
||||
{/snippet}
|
||||
{#await import('./Commands.svelte')}
|
||||
<div class="h-96 flex flex-col gap-2 items-center justify-center">
|
||||
<Spinner width={32} />
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
isAdmin,
|
||||
} from '$lib/components/lemmy/moderation/moderation'
|
||||
import { resumables, type ResumableItem } from '$lib/lemmy/item'
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { userSettings } from '$lib/settings.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import { colorScheme, theme, themeData, type ThemeData } from '$lib/ui/colors'
|
||||
import { fullCommunityName } from '$lib/util'
|
||||
@@ -68,7 +68,7 @@ export function getGroups(
|
||||
profile: Profile,
|
||||
profiles: Profile[],
|
||||
td: ThemeData,
|
||||
contextual?: Action[]
|
||||
contextual?: Action[],
|
||||
) {
|
||||
return [
|
||||
{
|
||||
@@ -444,7 +444,7 @@ export function getGroups(
|
||||
name: f.community.title,
|
||||
href: `/c/${fullCommunityName(
|
||||
f.community.name,
|
||||
f.community.actor_id
|
||||
f.community.actor_id,
|
||||
)}`,
|
||||
detail: new URL(f.community.actor_id).hostname,
|
||||
})) ?? [],
|
||||
|
||||
@@ -10,8 +10,12 @@
|
||||
import { flip } from 'svelte/animate'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
|
||||
export let items: Community[]
|
||||
export let isFavorites = false
|
||||
interface Props {
|
||||
items: Community[];
|
||||
isFavorites?: boolean;
|
||||
}
|
||||
|
||||
let { items, isFavorites = false }: Props = $props();
|
||||
</script>
|
||||
|
||||
{#each items.sort( (a, b) => a.title.localeCompare(b.title), ) as follow (follow.id)}
|
||||
@@ -60,12 +64,14 @@
|
||||
alignment="left"
|
||||
href="/c/{follow.name}@{new URL(follow.actor_id).hostname}"
|
||||
>
|
||||
<div class="flex flex-col max-w-full break-words" slot="label">
|
||||
<span>{follow.title}</span>
|
||||
<span class="text-xs text-slate-600 dark:text-zinc-400">
|
||||
{new URL(follow.actor_id).hostname}
|
||||
</span>
|
||||
</div>
|
||||
{#snippet label()}
|
||||
<div class="flex flex-col max-w-full break-words" >
|
||||
<span>{follow.title}</span>
|
||||
<span class="text-xs text-slate-600 dark:text-zinc-400">
|
||||
{new URL(follow.actor_id).hostname}
|
||||
</span>
|
||||
</div>
|
||||
{/snippet}
|
||||
</SidebarButton>
|
||||
</div>
|
||||
{/each}
|
||||
@@ -8,11 +8,15 @@
|
||||
import { Button } from 'mono-svelte'
|
||||
import { Icon, QuestionMarkCircle } from 'svelte-hero-icons'
|
||||
|
||||
export let prof: Profile
|
||||
export let index: number
|
||||
|
||||
let switching: boolean = false
|
||||
export let guest: boolean = false
|
||||
let switching: boolean = $state(false)
|
||||
interface Props {
|
||||
prof: Profile;
|
||||
index: number;
|
||||
guest?: boolean;
|
||||
}
|
||||
|
||||
let { prof, index, guest = false }: Props = $props();
|
||||
</script>
|
||||
|
||||
<SidebarButton
|
||||
@@ -38,13 +42,15 @@
|
||||
? '!bg-slate-100 dark:!bg-zinc-900'
|
||||
: ''}"
|
||||
>
|
||||
<ProfileAvatar
|
||||
profile={prof}
|
||||
{index}
|
||||
{guest}
|
||||
selected={$profile?.id == prof.id}
|
||||
slot="icon"
|
||||
/>
|
||||
{#snippet icon()}
|
||||
<ProfileAvatar
|
||||
profile={prof}
|
||||
{index}
|
||||
{guest}
|
||||
selected={$profile?.id == prof.id}
|
||||
|
||||
/>
|
||||
{/snippet}
|
||||
<span
|
||||
class="inline-flex flex-col gap-0 {$profile?.id == prof.id
|
||||
? 'font-semibold'
|
||||
|
||||
@@ -23,9 +23,12 @@
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/stores'
|
||||
|
||||
export let style: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
style?: string
|
||||
class?: string
|
||||
}
|
||||
|
||||
let { style = '', class: clazz = '' }: Props = $props()
|
||||
</script>
|
||||
|
||||
<nav
|
||||
@@ -45,7 +48,7 @@
|
||||
e.preventDefault()
|
||||
$userSettings.dock.pins = $userSettings.dock.pins.toSpliced(
|
||||
$userSettings.dock.pins.findLastIndex((p) => pin.url == p.url),
|
||||
1
|
||||
1,
|
||||
)
|
||||
return false
|
||||
}}
|
||||
@@ -57,25 +60,31 @@
|
||||
{/if}
|
||||
{#if $profile?.jwt}
|
||||
<SidebarButton icon={UserCircle} href="/profile">
|
||||
<span slot="label">
|
||||
{$t('profile.profile')}
|
||||
</span>
|
||||
{#snippet label()}
|
||||
<span>
|
||||
{$t('profile.profile')}
|
||||
</span>
|
||||
{/snippet}
|
||||
</SidebarButton>
|
||||
<SidebarButton icon={Inbox} href="/inbox">
|
||||
<span slot="label" class="flex items-center gap-2">
|
||||
{$t('profile.inbox')}
|
||||
{#if $notifications.inbox}
|
||||
<Badge
|
||||
class="w-5 h-5 !p-0 grid place-items-center ml-auto"
|
||||
color="red-subtle"
|
||||
>
|
||||
{$notifications.inbox}
|
||||
</Badge>
|
||||
{/if}
|
||||
</span>
|
||||
{#snippet label()}
|
||||
<span class="flex items-center gap-2">
|
||||
{$t('profile.inbox')}
|
||||
{#if $notifications.inbox}
|
||||
<Badge
|
||||
class="w-5 h-5 !p-0 grid place-items-center ml-auto"
|
||||
color="red-subtle"
|
||||
>
|
||||
{$notifications.inbox}
|
||||
</Badge>
|
||||
{/if}
|
||||
</span>
|
||||
{/snippet}
|
||||
</SidebarButton>
|
||||
<SidebarButton icon={Bookmark} href="/saved">
|
||||
<span slot="label">{$t('profile.saved')}</span>
|
||||
{#snippet label()}
|
||||
<span>{$t('profile.saved')}</span>
|
||||
{/snippet}
|
||||
</SidebarButton>
|
||||
{:else}
|
||||
<SidebarButton
|
||||
@@ -83,21 +92,27 @@
|
||||
title={$t('account.login')}
|
||||
icon={ArrowLeftOnRectangle}
|
||||
>
|
||||
<span slot="label">{$t('account.login')}</span>
|
||||
{#snippet label()}
|
||||
<span>{$t('account.login')}</span>
|
||||
{/snippet}
|
||||
</SidebarButton>
|
||||
<SidebarButton
|
||||
href="/signup"
|
||||
title={$t('account.signup')}
|
||||
icon={Identification}
|
||||
>
|
||||
<span slot="label">{$t('account.signup')}</span>
|
||||
{#snippet label()}
|
||||
<span>{$t('account.signup')}</span>
|
||||
{/snippet}
|
||||
</SidebarButton>
|
||||
<SidebarButton
|
||||
href="/settings"
|
||||
title={$t('nav.menu.settings')}
|
||||
icon={Cog6Tooth}
|
||||
>
|
||||
<span slot="label">{$t('nav.menu.settings')}</span>
|
||||
{#snippet label()}
|
||||
<span>{$t('nav.menu.settings')}</span>
|
||||
{/snippet}
|
||||
</SidebarButton>
|
||||
{/if}
|
||||
{#if $profileData.profiles.length >= 1}
|
||||
@@ -107,14 +122,18 @@
|
||||
class="max-w-full min-w-0 w-full"
|
||||
bind:open={$userSettings.expand.accounts}
|
||||
>
|
||||
<span slot="title" class="px-2 py-1 w-full">
|
||||
<EndPlaceholder>
|
||||
{$t('account.accounts')}
|
||||
<span slot="action" class="dark:text-white text-black">
|
||||
{$profileData.profiles.length}
|
||||
</span>
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{#snippet title()}
|
||||
<span class="px-2 py-1 w-full">
|
||||
<EndPlaceholder>
|
||||
{$t('account.accounts')}
|
||||
{#snippet action()}
|
||||
<span class="dark:text-white text-black">
|
||||
{$profileData.profiles.length}
|
||||
</span>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{/snippet}
|
||||
{#each [...$profileData.profiles] as prof, index (prof.id)}
|
||||
<div animate:flip={{ duration: 300, easing: expoOut }} class="w-full">
|
||||
<ProfileButton {index} {prof} />
|
||||
@@ -131,19 +150,22 @@
|
||||
class="max-w-full min-w-0 w-full"
|
||||
bind:open={$userSettings.expand.favorites}
|
||||
>
|
||||
<span
|
||||
slot="title"
|
||||
class="px-2 py-1 w-full {$userSettings.expandSidebar
|
||||
? ''
|
||||
: '//max-lg:hidden'}"
|
||||
>
|
||||
<EndPlaceholder>
|
||||
{$t('routes.profile.favorites')}
|
||||
<span slot="action" class="dark:text-white text-black">
|
||||
{$profile.favorites.length}
|
||||
</span>
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{#snippet title()}
|
||||
<span
|
||||
class="px-2 py-1 w-full {$userSettings.expandSidebar
|
||||
? ''
|
||||
: '//max-lg:hidden'}"
|
||||
>
|
||||
<EndPlaceholder>
|
||||
{$t('routes.profile.favorites')}
|
||||
{#snippet action()}
|
||||
<span class="dark:text-white text-black">
|
||||
{$profile.favorites?.length}
|
||||
</span>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{/snippet}
|
||||
<CommunityList isFavorites items={$profile.favorites} />
|
||||
</Expandable>
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
@@ -154,19 +176,22 @@
|
||||
class="max-w-full min-w-0 w-full"
|
||||
bind:open={$userSettings.expand.moderates}
|
||||
>
|
||||
<span
|
||||
slot="title"
|
||||
class="px-2 py-1 w-full {$userSettings.expandSidebar
|
||||
? ''
|
||||
: '//max-lg:hidden'}"
|
||||
>
|
||||
<EndPlaceholder>
|
||||
{$t('routes.profile.moderates')}
|
||||
<span slot="action" class="dark:text-white text-black">
|
||||
{$profile.user.moderates.length}
|
||||
</span>
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{#snippet title()}
|
||||
<span
|
||||
class="px-2 py-1 w-full {$userSettings.expandSidebar
|
||||
? ''
|
||||
: '//max-lg:hidden'}"
|
||||
>
|
||||
<EndPlaceholder>
|
||||
{$t('routes.profile.moderates')}
|
||||
{#snippet action()}
|
||||
<span class="dark:text-white text-black">
|
||||
{$profile.user?.moderates.length}
|
||||
</span>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{/snippet}
|
||||
<CommunityList
|
||||
items={$profile.user.moderates.map((i) => i.community)}
|
||||
/>
|
||||
@@ -178,19 +203,22 @@
|
||||
class="max-w-full min-w-0 w-full"
|
||||
bind:open={$userSettings.expand.communities}
|
||||
>
|
||||
<span
|
||||
slot="title"
|
||||
class="px-2 py-1 w-full {$userSettings.expandSidebar
|
||||
? ''
|
||||
: '//max-lg:hidden'}"
|
||||
>
|
||||
<EndPlaceholder>
|
||||
{$t('profile.subscribed')}
|
||||
<span slot="action" class="dark:text-white text-black">
|
||||
{$profile.user.follows.length}
|
||||
</span>
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{#snippet title()}
|
||||
<span
|
||||
class="px-2 py-1 w-full {$userSettings.expandSidebar
|
||||
? ''
|
||||
: '//max-lg:hidden'}"
|
||||
>
|
||||
<EndPlaceholder>
|
||||
{$t('profile.subscribed')}
|
||||
{#snippet action()}
|
||||
<span class="dark:text-white text-black">
|
||||
{$profile.user?.follows.length}
|
||||
</span>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{/snippet}
|
||||
<CommunityList items={$profile.user.follows.map((i) => i.community)} />
|
||||
</Expandable>
|
||||
{/if}
|
||||
|
||||
@@ -1,25 +1,44 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import { page } from '$app/stores'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
|
||||
export let href: string | undefined = undefined
|
||||
export let icon: IconSource | undefined = undefined
|
||||
export let selected = false
|
||||
$: {
|
||||
interface Props {
|
||||
href?: string | undefined
|
||||
icon?: IconSource | undefined
|
||||
selected?: boolean
|
||||
class?: string
|
||||
customIcon?: import('svelte').Snippet<[any]>
|
||||
children?: import('svelte').Snippet
|
||||
label?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
href = undefined,
|
||||
icon = undefined,
|
||||
selected = $bindable(false),
|
||||
class: clazz = '',
|
||||
customIcon,
|
||||
children,
|
||||
label,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
run(() => {
|
||||
if (href != undefined) {
|
||||
selected = $page.url.pathname == href
|
||||
}
|
||||
}
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
})
|
||||
</script>
|
||||
|
||||
<Button
|
||||
color={selected ? 'primary' : 'tertiary'}
|
||||
alignment="left"
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
{href}
|
||||
on:click
|
||||
on:contextmenu
|
||||
@@ -27,13 +46,13 @@
|
||||
? 'text-slate-600 dark:text-zinc-400'
|
||||
: ''} {clazz}"
|
||||
>
|
||||
<slot {selected} name="icon" slot="prefix">
|
||||
{#if icon}
|
||||
{#snippet prefix()}
|
||||
{#if customIcon}{@render customIcon({ selected })}{:else if icon}
|
||||
<Icon src={icon} solid={selected} size="20" />
|
||||
{/if}
|
||||
</slot>
|
||||
<slot />
|
||||
{/snippet}
|
||||
{@render children?.()}
|
||||
<div class="contents">
|
||||
<slot name="label" />
|
||||
{@render label?.()}
|
||||
</div>
|
||||
</Button>
|
||||
@@ -7,14 +7,21 @@
|
||||
|
||||
type T = $$Generic
|
||||
|
||||
export let items: T[]
|
||||
export let id: (item: T) => string | number | symbol
|
||||
interface Props {
|
||||
items: T[]
|
||||
id: (item: T) => string | number | symbol
|
||||
identifier?: import('svelte').Snippet<[any]>
|
||||
children?: import('svelte').Snippet<[any]>
|
||||
}
|
||||
|
||||
let filters: Set<string | number | symbol> = new Set()
|
||||
let { items, id, identifier, children }: Props = $props()
|
||||
|
||||
$: filteredItems =
|
||||
filters.size > 0 ? items.filter((i) => filters.has(id(i))) : items
|
||||
$: uniqueIds = new Set(items.map(id))
|
||||
let filters: Set<string | number | symbol> = $state(new Set())
|
||||
|
||||
let filteredItems = $derived(
|
||||
filters.size > 0 ? items.filter((i) => filters.has(id(i))) : items,
|
||||
)
|
||||
let uniqueIds = $derived(new Set(items.map(id)))
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row overflow-auto space-x-2">
|
||||
@@ -42,25 +49,25 @@
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{#each uniqueIds as identifier}
|
||||
{#each uniqueIds as id}
|
||||
<Button
|
||||
on:click={() => {
|
||||
if (filters.has(identifier)) filters.delete(identifier)
|
||||
else filters.add(identifier)
|
||||
if (filters.has(id)) filters.delete(id)
|
||||
else filters.add(id)
|
||||
filters = filters
|
||||
}}
|
||||
color={filters.has(identifier) ? 'primary' : 'ghost'}
|
||||
color={filters.has(id) ? 'primary' : 'ghost'}
|
||||
class="text-xs px-2.5"
|
||||
rounding="pill"
|
||||
size="sm"
|
||||
>
|
||||
<slot name="identifier" string={identifier}>
|
||||
{#if identifier}{@render identifier({ string: id })}{:else}
|
||||
<TextProps wrap="no-wrap">
|
||||
{identifier}
|
||||
{id}
|
||||
</TextProps>
|
||||
</slot>
|
||||
{/if}
|
||||
</Button>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<slot items={filteredItems} />
|
||||
{@render children?.({ items: filteredItems })}
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
const wrapClass = {
|
||||
wrap: '',
|
||||
'no-wrap': 'overflow-hidden overflow-ellipsis whitespace-nowrap',
|
||||
@@ -6,13 +6,18 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export let wrap: keyof typeof wrapClass = 'wrap'
|
||||
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
$: classes = `${wrapClass[wrap]} ${clazz ?? ''}`
|
||||
interface Props {
|
||||
wrap?: keyof typeof wrapClass;
|
||||
class?: string;
|
||||
children?: import('svelte').Snippet;
|
||||
}
|
||||
|
||||
let { wrap = 'wrap', class: clazz = '', children }: Props = $props();
|
||||
|
||||
let classes = $derived(`${wrapClass[wrap]} ${clazz ?? ''}`)
|
||||
</script>
|
||||
|
||||
<span class={classes}>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</span>
|
||||
Reference in new issue
Block a user