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
@@ -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