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
@@ -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,
|
||||
})) ?? [],
|
||||
|
||||
Reference in new issue
Block a user