[ui] LetterSlot: Add the page for A Letter from the Gardener, shown once the author writes it
docs/LETTER.md holds slots as comments only, so the player sees no change
until the author writes. The app bundles the letter at build time, a small
Markdown subset renders without {@html}, only https: and tel: become links,
and lint:copy now reads the letter. Review found turbo replaying a stale
build after the letter changed; docs/LETTER.md is now in its cache key.
This commit is contained in:
@@ -1,12 +1,55 @@
|
||||
<script lang="ts">
|
||||
import { PRODUCT_NAME } from '@rosea/schema';
|
||||
import { en } from './copy/en.js';
|
||||
import Letter from './letter/Letter.svelte';
|
||||
import { parseLetter } from './letter/parse.js';
|
||||
|
||||
/** The author's Markdown from docs/LETTER.md. Empty means there is no way to the page. */
|
||||
let { letter = '' }: { letter?: string } = $props();
|
||||
|
||||
const LETTER_HASH = '#letter';
|
||||
// Any hash but the letter's is the garden. A bare '#' is not a valid link target.
|
||||
const GARDEN_HASH = '#garden';
|
||||
|
||||
const blocks = $derived(parseLetter(letter));
|
||||
let hash = $state(location.hash);
|
||||
const view = $derived(hash === LETTER_HASH && blocks.length > 0 ? 'letter' : 'home');
|
||||
|
||||
let heading = $state<HTMLHeadingElement>();
|
||||
// Focus follows the view only after the player moved, never on the first load.
|
||||
let moved = false;
|
||||
|
||||
$effect(() => {
|
||||
const onChange = (): void => {
|
||||
moved = true;
|
||||
hash = location.hash;
|
||||
};
|
||||
window.addEventListener('hashchange', onChange);
|
||||
return () => window.removeEventListener('hashchange', onChange);
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
// Read `heading` first: an effect tracks only what it reads, and `moved` is not state.
|
||||
const target = heading;
|
||||
if (moved) target?.focus();
|
||||
});
|
||||
</script>
|
||||
|
||||
<main class="shell">
|
||||
<h1>{PRODUCT_NAME}</h1>
|
||||
<p>{en.shell.preparing}</p>
|
||||
</main>
|
||||
{#if view === 'letter'}
|
||||
<main class="shell page">
|
||||
<h1 bind:this={heading} tabindex="-1">{en.letter.title}</h1>
|
||||
<Letter {blocks} />
|
||||
<a href={GARDEN_HASH}>{en.letter.back}</a>
|
||||
</main>
|
||||
{:else}
|
||||
<main class="shell">
|
||||
<h1 bind:this={heading} tabindex="-1">{PRODUCT_NAME}</h1>
|
||||
<p>{en.shell.preparing}</p>
|
||||
{#if blocks.length > 0}
|
||||
<a href={LETTER_HASH}>{en.letter.title}</a>
|
||||
{/if}
|
||||
</main>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.shell {
|
||||
@@ -18,6 +61,11 @@
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.page {
|
||||
place-content: start center;
|
||||
text-align: start;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0;
|
||||
font-family: var(--font-display);
|
||||
@@ -27,8 +75,16 @@
|
||||
color: var(--rose);
|
||||
}
|
||||
|
||||
h1:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
color: var(--ink-soft);
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--rose);
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user