flotilla/src/app/components/ContentLinkInline.svelte

41 lines
1.4 KiB
Svelte
Raw Normal View History

2024-09-24 21:12:38 +00:00
<script lang="ts">
import {call, displayUrl} from "@welshman/lib"
import {isRelayUrl} 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 Link from "@lib/components/Link.svelte"
import ContentLinkDetail from "@app/components/ContentLinkDetail.svelte"
import {pushModal} from "@app/util/modal"
2025-11-26 01:06:21 +00:00
import {PLATFORM_URL} from "@app/core/state"
import {makeSpacePath} from "@app/util/routes"
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()
const [href, external] = call(() => {
if (isRelayUrl(url)) return [makeSpacePath(url), false]
if (url.startsWith(PLATFORM_URL)) return [url.replace(PLATFORM_URL, ""), false]
return [url, true]
})
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>
{#if url.match(/\.(jpe?g|png|gif|webp)$/)}
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}
2025-11-26 01:06:21 +00:00
<Link {external} {href} class="link-content whitespace-nowrap">
2025-09-10 22:26:39 +00:00
<Icon icon={LinkRound} size={3} class="inline-block" />
{displayUrl(url)}
</Link>
{/if}