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>
|
||||
const youtubeDomain = (place: 'youtube' | 'invidious' | 'piped') => {
|
||||
switch (place) {
|
||||
case 'youtube': {
|
||||
@@ -37,12 +37,6 @@
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export let type: IframeType = 'none'
|
||||
export let thumbnail: string | undefined = undefined
|
||||
export let url: string
|
||||
export let opened = !$userSettings.embeds.clickToView
|
||||
export let autoplay: boolean = $userSettings.embeds.clickToView
|
||||
|
||||
const urlToEmbed = (inputUrl: string) => {
|
||||
if (type == 'video') {
|
||||
return inputUrl
|
||||
@@ -56,7 +50,7 @@
|
||||
if (autoplay) url.searchParams.set('autoplay', '1')
|
||||
|
||||
return `https://${youtubeDomain(
|
||||
$userSettings.embeds.youtube
|
||||
$userSettings.embeds.youtube,
|
||||
)}/embed/${videoID}?${url.searchParams.toString()}`
|
||||
}
|
||||
|
||||
@@ -64,7 +58,7 @@
|
||||
}
|
||||
|
||||
const typeData = (
|
||||
type: IframeType
|
||||
type: IframeType,
|
||||
): {
|
||||
icon: IconSource
|
||||
text: string
|
||||
@@ -91,11 +85,26 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: data = typeData(type)
|
||||
$: embedUrl = urlToEmbed(url)
|
||||
interface Props {
|
||||
type?: IframeType
|
||||
thumbnail?: string | undefined
|
||||
url: string
|
||||
opened?: any
|
||||
autoplay?: boolean
|
||||
class?: string
|
||||
}
|
||||
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
type = 'none',
|
||||
thumbnail = undefined,
|
||||
url,
|
||||
opened = $bindable(!$userSettings.embeds.clickToView),
|
||||
autoplay = $userSettings.embeds.clickToView,
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
|
||||
let data = $derived(typeData(type))
|
||||
let embedUrl = $derived(urlToEmbed(url))
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -104,7 +113,7 @@
|
||||
-->
|
||||
{#if opened}
|
||||
{#if type == 'video'}
|
||||
<!-- svelte-ignore a11y-media-has-caption -->
|
||||
<!-- svelte-ignore a11y_media_has_caption -->
|
||||
<video {autoplay} controls class="rounded-xl aspect-video {clazz}">
|
||||
<source src={url} />
|
||||
</video>
|
||||
@@ -116,11 +125,11 @@
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||
allowfullscreen
|
||||
class="aspect-video rounded-xl dark:bg-zinc-900 {clazz ?? ''}"
|
||||
/>
|
||||
></iframe>
|
||||
{/if}
|
||||
{:else}
|
||||
<button
|
||||
on:click={() => (opened = true)}
|
||||
onclick={() => (opened = true)}
|
||||
class="aspect-video w-full h-full z-0 overflow-hidden relative rounded-xl flex flex-col gap-2 items-center justify-center text-white"
|
||||
>
|
||||
{#if thumbnail}
|
||||
@@ -132,7 +141,7 @@
|
||||
{:else}
|
||||
<div
|
||||
class="absolute blur-3xl -z-10 top-0 left-0 w-full h-full bg-gradient-to-br from-green-800 via-blue-900 via-20% to-red-700"
|
||||
/>
|
||||
></div>
|
||||
{/if}
|
||||
<Icon src={data.icon} solid size="48" />
|
||||
<h1 class="font-bold text-xl">{data.text}</h1>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { stopPropagation } from 'svelte/legacy'
|
||||
|
||||
import { userSettings, type View } from '$lib/settings'
|
||||
import type { Post } from 'lemmy-js-client'
|
||||
import { bestImageURL, postLink } from '../helpers'
|
||||
@@ -6,10 +8,14 @@
|
||||
import { Button, modal } from 'mono-svelte'
|
||||
import { onMount } from 'svelte'
|
||||
|
||||
export let post: Post
|
||||
export let blur: boolean = false
|
||||
interface Props {
|
||||
post: Post
|
||||
blur?: boolean
|
||||
}
|
||||
|
||||
let imageLoaded: boolean | null = null
|
||||
let { post, blur = false }: Props = $props()
|
||||
|
||||
let imageLoaded: boolean | null = $state(null)
|
||||
|
||||
onMount(() => {
|
||||
imageLoaded = false
|
||||
@@ -23,11 +29,11 @@
|
||||
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900"
|
||||
data-sveltekit-preload-data="off"
|
||||
aria-label={post.name}
|
||||
on:click={() => showImage(bestImageURL(post, false, -1))}
|
||||
onclick={() => showImage(bestImageURL(post, false, -1))}
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<!-- svelte-ignore a11y_missing_attribute -->
|
||||
<img
|
||||
loading="lazy"
|
||||
fetchpriority="auto"
|
||||
@@ -52,7 +58,7 @@
|
||||
srcset={bestImageURL(post, false, 1512)}
|
||||
media="(max-width: 1512px)"
|
||||
/>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<!-- svelte-ignore a11y_missing_attribute -->
|
||||
<img
|
||||
src={bestImageURL(post, false, -1)}
|
||||
loading="lazy"
|
||||
@@ -63,16 +69,16 @@
|
||||
height={300}
|
||||
class:blur-[64px]={blur}
|
||||
alt={post.alt_text ?? ''}
|
||||
on:load={() => (imageLoaded = true)}
|
||||
onload={() => (imageLoaded = true)}
|
||||
/>
|
||||
</picture>
|
||||
<!-- 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 -->
|
||||
<div
|
||||
class="absolute bottom-0 left-0 right-0 flex justify-between items-center
|
||||
rounded-full ml-auto w-max m-2 p-0 gap-1
|
||||
*:bg-white *:border *:border-slate-200 *:dark:border-zinc-800 *:dark:bg-zinc-900"
|
||||
on:click|stopPropagation={() => {}}
|
||||
onclick={stopPropagation(() => {})}
|
||||
>
|
||||
{#if post.alt_text}
|
||||
<Button
|
||||
|
||||
@@ -18,11 +18,21 @@
|
||||
import { ArrowDownTray, Icon } from 'svelte-hero-icons'
|
||||
import PostImage from './PostImage.svelte'
|
||||
|
||||
export let view: 'card' | 'cozy' | 'list' | 'compact' = 'cozy'
|
||||
export let post: Post
|
||||
export let type: MediaType = 'none'
|
||||
export let opened: boolean | undefined = undefined
|
||||
export let blur: boolean = post.nsfw && $userSettings.nsfwBlur
|
||||
interface Props {
|
||||
view?: 'card' | 'cozy' | 'list' | 'compact'
|
||||
post: Post
|
||||
type?: MediaType
|
||||
opened?: boolean | undefined
|
||||
blur?: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
view = 'cozy',
|
||||
post,
|
||||
type = 'none',
|
||||
opened = undefined,
|
||||
blur = post.nsfw && $userSettings.nsfwBlur,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<!--
|
||||
|
||||
@@ -18,19 +18,28 @@
|
||||
ExclamationTriangle,
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
export let post: Post
|
||||
export let type: MediaType = 'none'
|
||||
export let view: View = 'cozy'
|
||||
export let blur: boolean = post.nsfw && $userSettings.nsfwBlur
|
||||
|
||||
const thumbnailSize = (view: View) =>
|
||||
view == 'compact' ? 'w-22 h-22 sm:w-28' : 'w-24 h-24 sm:w-32'
|
||||
|
||||
$: size = thumbnailSize(view)
|
||||
interface Props {
|
||||
post: Post
|
||||
type?: MediaType
|
||||
view?: View
|
||||
blur?: boolean
|
||||
style?: string
|
||||
class?: string
|
||||
}
|
||||
|
||||
export let style: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
post,
|
||||
type = 'none',
|
||||
view = 'cozy',
|
||||
blur = post.nsfw && $userSettings.nsfwBlur,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
|
||||
let size = $derived(thumbnailSize(view))
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -43,15 +52,16 @@
|
||||
openOnHover
|
||||
placement={$userSettings.leftAlign ? 'bottom-start' : 'bottom-end'}
|
||||
>
|
||||
<Material
|
||||
slot="target"
|
||||
padding="none"
|
||||
rounding="full"
|
||||
elevation="high"
|
||||
class="w-max absolute bottom-0 left-0 py-0.5 px-1.5 m-1 font-bold"
|
||||
>
|
||||
ALT
|
||||
</Material>
|
||||
{#snippet target()}
|
||||
<Material
|
||||
padding="none"
|
||||
rounding="full"
|
||||
elevation="high"
|
||||
class="w-max absolute bottom-0 left-0 py-0.5 px-1.5 m-1 font-bold"
|
||||
>
|
||||
ALT
|
||||
</Material>
|
||||
{/snippet}
|
||||
<div class="max-w-sm">
|
||||
{post.alt_text}
|
||||
</div>
|
||||
@@ -60,7 +70,7 @@
|
||||
<svelte:element
|
||||
this={!$userSettings.expandImages || type != 'image' ? 'a' : 'button'}
|
||||
href={postLink(post)}
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
if (type == 'image') {
|
||||
showImage(bestImageURL(post, false, -1))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user