~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0
102 lines · 2.3 KB Raw History
<script lang="ts">
	import type { Snippet } from 'svelte';
	import { opens, tagOf, type Opener } from '../open';

	// One item of a `Tree` or `Chain`: its `body`, opening
	// what the item opens when clicked anywhere but on a link or button of
	// its own, and under it what `nested` draws (its replies). An item whose
	// template draws nothing (a post that is not found, or blocked) takes no
	// room: its replies, if any, still show.
	let {
		body,
		open,
		nested
	}: {
		body: Snippet;
		open: Opener | null;
		nested?: Snippet;
	} = $props();

	let content: HTMLDivElement | undefined = $state();
	/** The template drew nothing: every part was missing. */
	let blank = $state(false);

	$effect(() => {
		if (!content) return;
		const observer = new ResizeObserver(([entry]) => (blank = entry.contentRect.height === 0));
		observer.observe(content);
		return () => observer.disconnect();
	});
</script>

<li class="item" class:gone={blank && !nested}>
	<div class="node" class:blank class:openable={open !== null}>
		{#if open}
			<svelte:element this={tagOf(open)} {...opens(open)} class="open" aria-label={open.label}></svelte:element>
		{/if}
		<div class="content" bind:this={content}>
			{@render body()}
		</div>
	</div>
	{@render nested?.()}
</li>

<style>
	.item {
		display: flex;
		flex-direction: column;
		gap: var(--hud-space-2);
		min-width: 0;
	}

	.gone {
		display: none;
	}

	/* Collapsed, not hidden, so it is still measured. */
	.node.blank {
		padding: 0;
	}

	/* Its words line up with what is around it; its hover reaches past them. */
	.node {
		position: relative;
		min-width: 0;
		margin: 0 calc(-1 * var(--hud-space-2));
		padding: var(--hud-space-2);
		border-radius: var(--border-radius-md);
	}

	.content {
		display: flex;
		flex-direction: column;
		gap: var(--hud-space-2);
		min-width: 0;
	}

	/* The whole item opens: a button behind the content, which lets clicks
	   fall through to it except on the content's own links and buttons. */
	.open {
		position: absolute;
		inset: 0;
		width: 100%;
		padding: 0;
		border: 0;
		border-radius: inherit;
		background: none;
		cursor: pointer;
	}

	.openable:hover {
		background: var(--color-background-secondary);
	}

	.openable > .content {
		position: relative;
		pointer-events: none;
	}

	.openable > .content :global(:is(a, button, input, audio, video, details, summary)) {
		pointer-events: auto;
	}
</style>