~ 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
87 lines · 2.4 KB Raw History
<script lang="ts">
	import Icon from '../atoms/Icon.svelte';
	import type { Template } from '../playground/playground.svelte';

	/**
	 * What to start from: a blank view of one's own, or a bundled view with
	 * its call, grouped by its app; the one begun from checked. On a phone,
	 * a sheet.
	 */
	let { templates, current, onchoose, onblank }: { templates: Template[]; current: string | null; onchoose: (name: string) => void; onblank: () => void } = $props();

	let open = $state(false);

	const groups = $derived.by(() => {
		const byApp: Record<string, Template[]> = {};
		for (const template of templates) (byApp[template.app] ??= []).push(template);
		return Object.entries(byApp);
	});
	const chosen = $derived(templates.find((t) => t.name === current) ?? null);

	function act(run: () => void) {
		open = false;
		run();
	}
</script>

<details class="popover sheet" bind:open>
	<summary class="btn sm" title="Start from a bundled view">
		<Icon name="view" /><span class="label">{chosen ? `${chosen.app}: ${chosen.example.title}` : 'Start from'}</span><Icon name="expand" />
	</summary>
	<div class="menu" role="menu">
		<button type="button" class="menu-item" role="menuitem" onclick={() => act(onblank)}>
			<span class="mark"><Icon name="add" /></span>
			<span class="grow">Blank</span>
			<span class="mute">A list of posts</span>
		</button>
		{#each groups as [app, group] (app)}
			<hr />
			<p class="menu-head">{app}</p>
			{#each group as template (template.name)}
				<button type="button" class="menu-item" role="menuitemradio" aria-checked={template.name === current} onclick={() => act(() => onchoose(template.name))}>
					<span class="mark">{#if template.name === current}<Icon name="check" />{/if}</span>
					<span class="grow name">{template.example.title}</span>
					{#if template.example.signIn}<span class="mute">Needs sign-in</span>{/if}
					<code class="mute">{template.name}</code>
				</button>
			{/each}
		{:else}
			<p class="empty-state">No bundled views</p>
		{/each}
	</div>
</details>

<style>
	summary .label {
		max-width: var(--tab-name);
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.mark {
		display: inline-grid;
		flex: none;
		place-items: center;
		width: var(--icon);
	}

	.grow {
		flex: 1;
		min-width: 0;
	}

	.name {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	code {
		font: var(--text-2xs) var(--font-mono);
	}

	.menu-item .mute {
		flex: none;
		font-size: var(--text-xs);
	}
</style>