misc: add load prompt to images, close #511

This commit is contained in:
James Xylight committed 2025-03-19 19:23:22 -07:00
1 parent 0b4005743e
commit f18e5d09f2
5 files changed
+61 -20

No files matched your search

@@ -36,6 +36,9 @@
</div> </div>
{/if} {/if}
<TextProps wrap="no-wrap"> <TextProps wrap="no-wrap">
<Markdown source={message.private_message.content} /> <Markdown
rendererOptions={{ autoloadImages: false }}
source={message.private_message.content}
/>
</TextProps> </TextProps>
</div> </div>
@@ -112,6 +112,11 @@
<script lang="ts"> <script lang="ts">
import SvelteMarkdown from 'svelte-markdown' import SvelteMarkdown from 'svelte-markdown'
import { setContext } from 'svelte'
interface RendererOptions {
autoloadImages: boolean
}
interface Props { interface Props {
source?: string source?: string
@@ -119,6 +124,7 @@
noStyle?: boolean noStyle?: boolean
style?: string style?: string
class?: string class?: string
rendererOptions?: RendererOptions
} }
let { let {
@@ -127,8 +133,13 @@
noStyle = false, noStyle = false,
style = '', style = '',
class: clazz = '', class: clazz = '',
rendererOptions = {
autoloadImages: true,
},
}: Props = $props() }: Props = $props()
setContext('options', rendererOptions)
options.inline = inline options.inline = inline
let tokens = $derived.by(() => marked.lexer(source)) let tokens = $derived.by(() => marked.lexer(source))
@@ -6,6 +6,14 @@
optimizeImageURL, optimizeImageURL,
} from '$lib/components/lemmy/post/helpers' } from '$lib/components/lemmy/post/helpers'
import PostIframe from '$lib/components/lemmy/post/media/PostIframe.svelte' import PostIframe from '$lib/components/lemmy/post/media/PostIframe.svelte'
import { getContext } from 'svelte'
import { ArrowDown, ArrowDownTray, Icon } from 'svelte-hero-icons'
import { t } from '$lib/translations'
let loaded: boolean = $state(
(getContext('options') as { autoloadImages: boolean })?.autoloadImages ??
true,
)
interface Props { interface Props {
href: string href: string
@@ -22,26 +30,40 @@
class="w-auto h-auto max-h-96 rounded-2xl p-2 border border-slate-200 dark:border-zinc-800 class="w-auto h-auto max-h-96 rounded-2xl p-2 border border-slate-200 dark:border-zinc-800
inline-block" inline-block"
> >
{#if type == 'video' || type == 'embed' || type == 'iframe'} {#if loaded}
<PostIframe {#if type == 'video' || type == 'embed' || type == 'iframe'}
type={iframeType(href)} <PostIframe
url={href} type={iframeType(href)}
opened={true} url={href}
autoplay={false} opened={true}
class="w-auto h-auto max-h-80 inline-block rounded-lg" autoplay={false}
/> class="w-auto h-auto max-h-80 inline-block rounded-lg"
/>
{:else}
<button
class="inline"
onclick={() => showImage(optimizeImageURL(href, -1), text)}
>
<img
src={optimizeImageURL(href, 1024)}
{title}
alt={text}
width={300}
height={300}
class="object-contain w-auto h-auto max-h-80 inline rounded-lg"
/>
</button>
{/if}
{:else} {:else}
<button <button
class="inline" onclick={() => (loaded = true)}
onclick={() => showImage(optimizeImageURL(href, -1), text)} class="w-40 h-40 flex flex-col justify-center items-center gap-4 p-2 group"
title={$t('common.download')}
> >
<img <Icon
src={optimizeImageURL(href, 1024)} src={ArrowDownTray}
{title} size="24"
alt={text} class="text-primary-900 dark:text-primary-100"
width={300}
height={300}
class="object-contain w-auto h-auto max-h-80 inline rounded-lg"
/> />
</button> </button>
{/if} {/if}
+2 -1
View File
@@ -606,7 +606,8 @@
"cancel": "Cancel", "cancel": "Cancel",
"send": "Send", "send": "Send",
"general": "General", "general": "General",
"remove": "Remove" "remove": "Remove",
"download": "Download"
}, },
"message": { "message": {
"success": "Success", "success": "Success",
@@ -27,7 +27,11 @@
: 'bg-slate-100 dark:bg-zinc-900 hover:brightness-125'} rounded-2xl w-full p-1.5 px-3 : 'bg-slate-100 dark:bg-zinc-900 hover:brightness-125'} rounded-2xl w-full p-1.5 px-3
font-medium cursor-pointer transition-all" font-medium cursor-pointer transition-all"
> >
<Markdown source={message.private_message.content} class="w-full" /> <Markdown
rendererOptions={{ autoloadImages: false }}
source={message.private_message.content}
class="w-full"
/>
</div> </div>
<Menu> <Menu>
{#snippet target()} {#snippet target()}