flotilla/src/app/components/ContentLinkInline.svelte

32 lines
1.2 KiB
Svelte
Raw Normal View History

2024-09-24 21:12:38 +00:00
<script lang="ts">
import {displayUrl} from "@welshman/lib"
import {getTagValue} from "@welshman/util"
2026-01-12 18:12:47 +00:00
import {preventDefault, stopPropagation} from "@lib/html"
2025-09-10 22:26:39 +00:00
import LinkRound from "@assets/icons/link-round.svg?dataurl"
2024-09-24 21:12:38 +00:00
import Icon from "@lib/components/Icon.svelte"
import ContentLinkDetail from "@app/components/ContentLinkDetail.svelte"
import ContentLinkUrl from "@app/components/ContentLinkUrl.svelte"
import {pushModal} from "@app/util/modal"
import {IMAGE_CONTENT_TYPES} from "@app/core/state"
2024-09-24 21:12:38 +00:00
2026-01-12 18:12:47 +00:00
const {value, event} = $props()
2024-09-24 21:12:38 +00:00
const url = value.url.toString()
2026-02-13 23:37:17 +00:00
const fileType = getTagValue("file-type", event.tags) || ""
2026-01-12 18:12:47 +00:00
const expand = () => pushModal(ContentLinkDetail, {value, event}, {fullscreen: true})
2024-09-24 21:12:38 +00:00
</script>
2026-02-13 23:37:17 +00:00
{#if url.match(/\.(jpe?g|png|gif|webp)$/) || IMAGE_CONTENT_TYPES.includes(fileType)}
2024-11-18 20:51:13 +00:00
<!-- Use a real link so people can copy the href -->
<a
href={url}
class="link-content whitespace-nowrap"
onclick={stopPropagation(preventDefault(expand))}>
2025-09-10 22:26:39 +00:00
<Icon icon={LinkRound} size={3} class="inline-block" />
{displayUrl(url)}
2024-11-18 20:51:13 +00:00
</a>
{:else}
<ContentLinkUrl {url} class="link-content whitespace-nowrap" />
{/if}