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
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
export interface Tag {
|
||||
content: string
|
||||
color?: string
|
||||
@@ -12,7 +12,7 @@
|
||||
])
|
||||
|
||||
export const parseTags = (
|
||||
title?: string
|
||||
title?: string,
|
||||
): { tags: Tag[]; title?: string } => {
|
||||
if (!title) return { tags: [] }
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
extracted.push(
|
||||
textToTag.get(content) ?? {
|
||||
content: content,
|
||||
}
|
||||
},
|
||||
)
|
||||
})
|
||||
return ''
|
||||
@@ -43,6 +43,8 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { stopPropagation } from 'svelte/legacy'
|
||||
|
||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import { Badge, Popover } from 'mono-svelte'
|
||||
@@ -70,37 +72,53 @@
|
||||
import CommunityHeader from '../community/CommunityHeader.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date'
|
||||
|
||||
export let community: Community | undefined = undefined
|
||||
export let showCommunity: boolean = true
|
||||
export let subscribed: SubscribedType | undefined = undefined
|
||||
let popoverOpen = $state(false)
|
||||
|
||||
export let user: Person | undefined = undefined
|
||||
export let published: Date | undefined = undefined
|
||||
export let title: string | undefined = undefined
|
||||
export let id: number | undefined = undefined
|
||||
export let read: boolean = false
|
||||
export let edited: string | undefined = undefined
|
||||
|
||||
export let view: View = 'cozy'
|
||||
|
||||
// Badges
|
||||
export let badges = {
|
||||
nsfw: false,
|
||||
saved: false,
|
||||
featured: false,
|
||||
deleted: false,
|
||||
removed: false,
|
||||
locked: false,
|
||||
moderator: false,
|
||||
admin: false,
|
||||
interface Props {
|
||||
community?: Community | undefined
|
||||
showCommunity?: boolean
|
||||
subscribed?: SubscribedType | undefined
|
||||
user?: Person | undefined
|
||||
published?: Date | undefined
|
||||
title?: string | undefined
|
||||
id?: number | undefined
|
||||
read?: boolean
|
||||
edited?: string | undefined
|
||||
view?: View
|
||||
// Badges
|
||||
badges?: any
|
||||
tags?: Tag[]
|
||||
style?: string
|
||||
titleClass?: string
|
||||
extraBadges?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
export let tags: Tag[] = []
|
||||
|
||||
let popoverOpen = false
|
||||
|
||||
export let style: string = ''
|
||||
export let titleClass: string = ''
|
||||
let {
|
||||
community = $bindable(undefined),
|
||||
showCommunity = true,
|
||||
subscribed = $bindable(undefined),
|
||||
user = undefined,
|
||||
published = undefined,
|
||||
title = undefined,
|
||||
id = undefined,
|
||||
read = false,
|
||||
edited = undefined,
|
||||
view = 'cozy',
|
||||
badges = {
|
||||
nsfw: false,
|
||||
saved: false,
|
||||
featured: false,
|
||||
deleted: false,
|
||||
removed: false,
|
||||
locked: false,
|
||||
moderator: false,
|
||||
admin: false,
|
||||
},
|
||||
tags = [],
|
||||
style = '',
|
||||
titleClass = '',
|
||||
extraBadges,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -114,32 +132,36 @@
|
||||
class:compact={view == 'compact'}
|
||||
{style}
|
||||
>
|
||||
{#if showCommunity && community && subscribed && showCommunity}
|
||||
{#if showCommunity && community != undefined && subscribed}
|
||||
<Popover bind:open={popoverOpen} manual>
|
||||
<button
|
||||
on:click={() => (popoverOpen = !popoverOpen)}
|
||||
class="relative cursor-pointer row-span-2 flex-shrink-0 pr-2 group/community"
|
||||
slot="target"
|
||||
>
|
||||
<Avatar
|
||||
url={community.icon}
|
||||
width={view == 'compact' ? 24 : 32}
|
||||
alt={community.name}
|
||||
class="group-hover/community:ring-2 transition-all ring-offset-0 ring-primary-900 dark:ring-primary-100"
|
||||
/>
|
||||
</button>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<div
|
||||
slot="popover"
|
||||
class="max-w-md rounded-2xl bg-white dark:bg-zinc-950"
|
||||
on:click|stopPropagation={() => {}}
|
||||
>
|
||||
<CommunityHeader bind:community bind:subscribed />
|
||||
</div>
|
||||
{#snippet target()}
|
||||
<button
|
||||
onclick={() => (popoverOpen = !popoverOpen)}
|
||||
class="relative cursor-pointer row-span-2 flex-shrink-0 pr-2 group/community"
|
||||
>
|
||||
<Avatar
|
||||
url={community?.icon}
|
||||
width={view == 'compact' ? 24 : 32}
|
||||
alt={community?.name}
|
||||
class="group-hover/community:ring-2 transition-all ring-offset-0 ring-primary-900 dark:ring-primary-100"
|
||||
/>
|
||||
</button>
|
||||
{/snippet}
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
{#snippet popover()}
|
||||
{#if community && subscribed}
|
||||
<div
|
||||
class="max-w-md rounded-2xl bg-white dark:bg-zinc-950"
|
||||
onclick={stopPropagation(() => {})}
|
||||
>
|
||||
<CommunityHeader bind:community bind:subscribed />
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Popover>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
{/if}
|
||||
{#if showCommunity && community}
|
||||
<CommunityLink
|
||||
@@ -174,14 +196,14 @@
|
||||
avatar={!showCommunity}
|
||||
class="flex-shrink "
|
||||
>
|
||||
<svelte:fragment slot="badges">
|
||||
{#snippet extraBadges()}
|
||||
{#if badges.moderator}
|
||||
<ShieldIcon filled width={14} class="text-green-500" />
|
||||
{/if}
|
||||
{#if badges.admin}
|
||||
<ShieldIcon filled width={14} class="text-red-500" />
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
</UserLink>
|
||||
</address>
|
||||
{/if}
|
||||
@@ -213,13 +235,13 @@
|
||||
style={tag.color ? `--tag-color: ${tag.color};` : ''}
|
||||
>
|
||||
<Badge class={tag.color ? 'badge-tag-color' : ''}>
|
||||
<svelte:fragment slot="icon">
|
||||
{#snippet icon()}
|
||||
{#if tag.icon}
|
||||
<Icon src={tag.icon} micro size="14" />
|
||||
{:else}
|
||||
<Icon src={Tag} micro size="14" />
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
{tag.content}
|
||||
</Badge>
|
||||
</a>
|
||||
@@ -227,7 +249,9 @@
|
||||
{/if}
|
||||
{#if badges.nsfw}
|
||||
<Badge label={$t('post.badges.nsfw')} color="red-subtle" allowIconOnly>
|
||||
<Icon src={ExclamationTriangle} size="14" micro slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={ExclamationTriangle} size="14" micro />
|
||||
{/snippet}
|
||||
{$t('post.badges.nsfw')}
|
||||
</Badge>
|
||||
{/if}
|
||||
@@ -237,7 +261,9 @@
|
||||
color="yellow-subtle"
|
||||
allowIconOnly
|
||||
>
|
||||
<Icon src={Bookmark} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={Bookmark} micro size="14" />
|
||||
{/snippet}
|
||||
{$t('post.badges.saved')}
|
||||
</Badge>
|
||||
{/if}
|
||||
@@ -247,19 +273,25 @@
|
||||
color="yellow-subtle"
|
||||
allowIconOnly
|
||||
>
|
||||
<Icon src={LockClosed} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={LockClosed} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.locked')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if badges.removed}
|
||||
<Badge label={$t('post.badges.removed')} color="red-subtle" allowIconOnly>
|
||||
<Icon src={Trash} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={Trash} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.removed')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if badges.deleted}
|
||||
<Badge label={$t('post.badges.deleted')} color="red-subtle" allowIconOnly>
|
||||
<Icon src={Trash} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={Trash} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.deleted')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
@@ -269,11 +301,13 @@
|
||||
color="green-subtle"
|
||||
allowIconOnly
|
||||
>
|
||||
<Icon src={Megaphone} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={Megaphone} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.featured')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
<slot name="badges" />
|
||||
{@render extraBadges?.()}
|
||||
</div>
|
||||
</header>
|
||||
{#if title && id}
|
||||
|
||||
Reference in new issue
Block a user