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
+44 -3

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,6 +30,7 @@
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 loaded}
{#if type == 'video' || type == 'embed' || type == 'iframe'} {#if type == 'video' || type == 'embed' || type == 'iframe'}
<PostIframe <PostIframe
type={iframeType(href)} type={iframeType(href)}
@@ -45,4 +54,17 @@
/> />
</button> </button>
{/if} {/if}
{:else}
<button
onclick={() => (loaded = true)}
class="w-40 h-40 flex flex-col justify-center items-center gap-4 p-2 group"
title={$t('common.download')}
>
<Icon
src={ArrowDownTray}
size="24"
class="text-primary-900 dark:text-primary-100"
/>
</button>
{/if}
</div> </div>
+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()}