Something went wrong. Try again.
An all-affirming social network based on the AT Protocol. nagi.suibari.com
Something went wrong. Try again.
7.5 kB · 336 lines
Svelte
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337<script lang="ts"> import { decorateSiblingUrl } from '$lib/sso/links'; import { m } from '$lib/i18n/i18n.svelte'; import Icon from '$lib/components/shell/Icon.svelte'; import type { AppLinkView } from '$lib/atproto/appLinks';
let { link, editable = false, editing = false, onedit, }: { link: AppLinkView; editable?: boolean; editing?: boolean; onedit?: () => void; } = $props();
// 単一表示(従来レイアウト)は 1 レコードのときだけ。複数はコンパクトなリスト行で並べる。 let single = $derived(link.records.length === 1 ? link.records[0] : null); const COLLAPSED_HEIGHT = 160; let content: HTMLDivElement; let expanded = $state(false); let overflowing = $state(false); let contentId = $derived(`app-link-content-${link.collection.replace(/[^a-zA-Z0-9_-]/g, '-')}`);
$effect(() => { const target = content; if (!target) return; void link; const measure = () => { overflowing = target.scrollHeight > COLLAPSED_HEIGHT + 1; if (!overflowing) expanded = false; }; measure(); if (!('ResizeObserver' in window)) return; const observer = new ResizeObserver(measure); observer.observe(target); return () => observer.disconnect(); });</script>
{#snippet fieldList(fields: AppLinkView['records'][number]['fields'])} <ul class="fields"> {#each fields as f, i (i)} <li class="field {f.role}"> {#if f.role === 'datetime'}<Icon name="clock" size={13} />{:else if f.role === 'url'}<Icon name="link" size={13} />{/if} {#if f.role === 'url'} <a href={decorateSiblingUrl(f.value)} target="_blank" rel="noopener noreferrer">{f.value}</a> {:else} <span>{f.value}</span> {/if} </li> {/each} </ul>{/snippet}
<article class="app-link" class:editing class:has-thumb={single && single.images.length}> {#if single && single.images.length} <div class="thumb"> <img class="cover" src={single.images[0]} alt="" loading="lazy" /> {#if single.images.length > 1}<span class="more">+{single.images.length - 1}</span>{/if} </div> {/if}
<div class="body"> <header> {#if link.iconUrl} <img class="icon" src={link.iconUrl} alt="" width="18" height="18" loading="lazy" /> {:else} <span class="icon fallback"><Icon name="apps" size={14} /></span> {/if} {#if link.appUri} <a class="name" href={decorateSiblingUrl(link.appUri)} target="_blank" rel="noopener noreferrer">{link.label}</a > {:else} <span class="name">{link.label}</span> {/if} {#if editable} <button type="button" class="edit" aria-label={m.appLinksEdit()} title={m.appLinksEdit()} aria-pressed={editing} onclick={() => onedit?.()} > <Icon name="edit" size={16} /> </button> {/if} </header>
<div class="content" class:collapsed={overflowing && !expanded} id={contentId} bind:this={content} > {#if single} {#if single.fields.length} {@render fieldList(single.fields)} {/if} {:else} <ul class="rows"> {#each link.records as rec, i (i)} <li class="row" class:has-thumb={rec.images.length}> {#if rec.images.length} <img class="row-thumb" src={rec.images[0]} alt="" width="36" height="36" loading="lazy" /> {/if} <div class="row-body"> {@render fieldList(rec.fields)} </div> </li> {/each} </ul> {/if} </div> {#if overflowing} <button type="button" class="expand" aria-expanded={expanded} aria-controls={contentId} onclick={() => (expanded = !expanded)}>{expanded ? m.readLess() : m.readMore()}</button > {/if} </div></article>
<style> .app-link { display: flex; gap: 0.6rem; align-items: flex-start; inline-size: 100%; min-inline-size: 0; max-inline-size: 100%; border: 1px solid var(--line); border-radius: var(--radius-m); padding: 0.55rem 0.65rem; background: var(--bg-inset, transparent); } .app-link.editing { border-color: var(--accent); } .thumb { position: relative; flex: none; inline-size: 64px; block-size: 64px; } .thumb .cover { inline-size: 64px; block-size: 64px; object-fit: cover; border-radius: var(--radius-s); display: block; } .thumb .more { position: absolute; inset-block-end: 2px; inset-inline-end: 2px; padding: 0 0.3rem; font-size: 0.7rem; font-weight: 700; color: #fff; background: rgb(0 0 0 / 0.6); border-radius: var(--radius-pill); } .body { flex: 1; min-inline-size: 0; max-inline-size: 100%; display: flex; flex-direction: column; } .content { position: relative; min-inline-size: 0; max-inline-size: 100%; } .content.collapsed { max-block-size: 160px; overflow: hidden; } .content.collapsed::after { content: ''; position: absolute; inset: auto 0 0; height: 42px; pointer-events: none; background: linear-gradient(to bottom, transparent, var(--bg-raised)); } header { display: flex; align-items: center; gap: 0.4rem; min-inline-size: 0; } .icon { border-radius: var(--radius-s); flex: none; } .icon.fallback { display: inline-flex; align-items: center; justify-content: center; inline-size: 18px; block-size: 18px; color: var(--text-muted); } .name { flex: 1 1 auto; min-inline-size: 0; max-inline-size: 100%; font-weight: 600; font-size: 0.85rem; color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } a.name:hover { text-decoration: underline; } .edit { margin-inline-start: auto; flex: none; display: inline-flex; align-items: center; justify-content: center; background: none; border: 0; color: var(--text-muted); cursor: pointer; padding: 0.2rem; border-radius: var(--radius-s); } .edit:hover, .edit[aria-pressed='true'] { color: var(--accent); background: var(--bg-inset); } .expand { align-self: flex-start; margin-top: 0.35rem; padding: 0; border: 0; background: none; color: var(--accent-strong); font-size: 0.75rem; font-weight: 700; } .fields { list-style: none; margin: 0.3rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.2rem; min-inline-size: 0; max-inline-size: 100%; } .field { display: flex; align-items: center; gap: 0.3rem; font-size: 0.82rem; color: var(--text); min-inline-size: 0; max-inline-size: 100%; } .field :global(svg) { color: var(--text-muted); flex: none; } .field span, .field a { display: block; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; /* ネスト flex 内で長文が縮まずカードを押し広げるのを防ぐ(省略記号を効かせる)。 */ min-inline-size: 0; max-inline-size: 100%; } .field.datetime { color: var(--text-muted); } /* repeat 展開時のリスト行。1要素=小サムネ+フィールドの詰まった1行。 */ .rows { list-style: none; margin: 0.35rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; min-inline-size: 0; max-inline-size: 100%; } .row { display: flex; align-items: center; gap: 0.45rem; min-inline-size: 0; } .row-thumb { flex: none; inline-size: 36px; block-size: 36px; object-fit: cover; border-radius: var(--radius-s); display: block; } .row-body { flex: 1; min-inline-size: 0; max-inline-size: 100%; } .row-body .fields { margin: 0; gap: 0.1rem; }</style>