mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 05:26:47 +03:00
fix(site): load the changelog's collapsed lists when opened (#63122)
This commit is contained in:
@@ -14,6 +14,49 @@ export default function changelog(root: HTMLElement) {
|
||||
if (list) timelineRail(list)
|
||||
$$('[data-component="changelog-entry"] > [data-slot="media"]', root).forEach(media)
|
||||
copyLinks(root)
|
||||
deferredLists(root)
|
||||
}
|
||||
|
||||
// A collapsed list the changelog leaves out of its HTML (NoteGroup's `defer`) holds a link to the
|
||||
// entry's page. Opening it moves the list in from that page, loaded once per entry, as soon as the
|
||||
// pointer reaches the heading. While it loads the group is busy; if loading fails, the link stays.
|
||||
function deferredLists(root: HTMLElement) {
|
||||
const pages = new Map<string, Promise<Document | undefined>>()
|
||||
const load = (href: string) => {
|
||||
if (!pages.has(href))
|
||||
pages.set(
|
||||
href,
|
||||
fetch(href)
|
||||
.then((response) => (response.ok ? response.text() : Promise.reject(new Error(String(response.status)))))
|
||||
.then((html) => new DOMParser().parseFromString(html, "text/html"))
|
||||
.catch(() => void pages.delete(href)),
|
||||
)
|
||||
return pages.get(href)!
|
||||
}
|
||||
const link = (group: HTMLElement) => $<HTMLAnchorElement>(':scope > [data-slot="show-more"]', group)
|
||||
const open = (group: HTMLElement) => {
|
||||
const more = link(group)
|
||||
if (!more || group.hasAttribute("aria-busy")) return
|
||||
group.setAttribute("aria-busy", "true")
|
||||
void load(more.href).then((page) => {
|
||||
group.removeAttribute("aria-busy")
|
||||
const list = page?.querySelector(`[data-slot="group"][data-kind="${group.dataset.kind}"] > ul`)
|
||||
if (list) more.replaceWith(list)
|
||||
})
|
||||
}
|
||||
const group = (event: Event) =>
|
||||
target(event).closest('details[data-slot="group"] > summary')?.parentElement as HTMLDetailsElement | null
|
||||
// A click (Enter and Space too) on the heading comes before the group opens, so the link never shows.
|
||||
root.addEventListener("click", (event) => {
|
||||
const details = group(event)
|
||||
if (details && !details.open) open(details)
|
||||
})
|
||||
root.addEventListener("pointerover", (event) => {
|
||||
const details = group(event)
|
||||
const more = details && link(details)
|
||||
if (more) void load(more.href)
|
||||
})
|
||||
$$('details[data-slot="group"][open]', root).forEach(open)
|
||||
}
|
||||
|
||||
// An entry's media (EntryCarousel): with several slides, dragged or swiped sideways (changelog-motion.ts),
|
||||
|
||||
@@ -399,10 +399,21 @@
|
||||
rotate: 0deg;
|
||||
}
|
||||
|
||||
> ul {
|
||||
> ul,
|
||||
> [data-slot="show-more"] {
|
||||
margin-top: 0.875rem;
|
||||
}
|
||||
|
||||
/* A deferred list (NoteGroup) shows its link to the entry's page only if loading it takes a while. */
|
||||
> [data-slot="show-more"] {
|
||||
display: inline-block;
|
||||
margin-inline-start: 0;
|
||||
}
|
||||
|
||||
&[aria-busy] > [data-slot="show-more"] {
|
||||
animation: changelog-loading 1s step-end;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
> summary [data-slot="chevron"] {
|
||||
transition: none;
|
||||
@@ -934,6 +945,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes changelog-loading {
|
||||
from {
|
||||
visibility: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes changelog-slide-progress {
|
||||
from {
|
||||
transform: scaleX(0);
|
||||
|
||||
@@ -226,6 +226,8 @@ export function ChangelogTimeline(props: {
|
||||
limit: number
|
||||
/** Product pages link the rest of a long list to the entry's page. */
|
||||
more?: boolean
|
||||
/** A collapsed list holds only a link to the entry's page, which the changelog's script loads it from. */
|
||||
defer?: boolean
|
||||
}) {
|
||||
const language = useLanguage()
|
||||
let list!: HTMLOListElement
|
||||
@@ -278,6 +280,7 @@ export function ChangelogTimeline(props: {
|
||||
media={entryMedia(entry)}
|
||||
limit={props.limit}
|
||||
more={props.more ? language.route(entryPath(entry)) : undefined}
|
||||
defer={props.defer ? language.route(entryPath(entry)) : undefined}
|
||||
/>
|
||||
</li>
|
||||
)
|
||||
@@ -587,7 +590,14 @@ const areaNames = {
|
||||
} as const satisfies Record<string, Key>
|
||||
|
||||
/** An entry's title and notes: the summary, the other highlights, then breaking changes, improvements and fixes. */
|
||||
function EntryBody(props: { entry: ChangelogEntry; level: 1 | 2 | 3; media?: Slide[]; limit: number; more?: string }) {
|
||||
function EntryBody(props: {
|
||||
entry: ChangelogEntry
|
||||
level: 1 | 2 | 3
|
||||
media?: Slide[]
|
||||
limit: number
|
||||
more?: string
|
||||
defer?: string
|
||||
}) {
|
||||
const i18n = useI18n()
|
||||
const language = useLanguage()
|
||||
const page = () => language.route(entryPath(props.entry))
|
||||
@@ -699,17 +709,21 @@ function EntryBody(props: { entry: ChangelogEntry; level: 1 | 2 | 3; media?: Sli
|
||||
|
||||
<NoteGroup
|
||||
title={i18n.t("changelog.improvements")}
|
||||
kind="improved"
|
||||
level={props.level + 1}
|
||||
notes={props.entry.improved}
|
||||
limit={props.limit}
|
||||
more={props.more}
|
||||
defer={props.defer}
|
||||
/>
|
||||
<NoteGroup
|
||||
title={i18n.t("changelog.fixes")}
|
||||
kind="fixed"
|
||||
level={props.level + 1}
|
||||
notes={props.entry.fixed}
|
||||
limit={props.limit}
|
||||
more={props.more}
|
||||
defer={props.defer}
|
||||
/>
|
||||
|
||||
<footer data-slot="meta">
|
||||
@@ -737,10 +751,25 @@ function EntryBody(props: { entry: ChangelogEntry; level: 1 | 2 | 3; media?: Sli
|
||||
/**
|
||||
* Improvements or fixes. A list longer than `limit` collapses behind its heading (a disclosure that
|
||||
* says how many there are), or, on product pages, shows the first few and links to the entry's
|
||||
* page for the rest.
|
||||
* page for the rest. With `defer`, a collapsed list holds only that link, and
|
||||
* src/client/islands/changelog.ts moves the list in from the entry's page when it opens.
|
||||
*/
|
||||
function NoteGroup(props: { title: string; level: number; notes: ChangelogNote[]; limit: number; more?: string }) {
|
||||
function NoteGroup(props: {
|
||||
title: string
|
||||
kind: "improved" | "fixed"
|
||||
level: number
|
||||
notes: ChangelogNote[]
|
||||
limit: number
|
||||
more?: string
|
||||
defer?: string
|
||||
}) {
|
||||
const i18n = useI18n()
|
||||
const more = (href: string, count: number) => (
|
||||
<a data-slot="show-more" href={href}>
|
||||
{i18n.t("changelog.list.more", { count })}
|
||||
<span data-slot="sr-only"> {props.title.toLowerCase()}</span>
|
||||
</a>
|
||||
)
|
||||
const items = (notes: ChangelogNote[]) => (
|
||||
<ul>
|
||||
<For each={notes}>
|
||||
@@ -757,7 +786,7 @@ function NoteGroup(props: { title: string; level: number; notes: ChangelogNote[]
|
||||
<Show when={props.notes.length > 0}>
|
||||
<Switch>
|
||||
<Match when={long() && !props.more}>
|
||||
<details data-slot="group">
|
||||
<details data-slot="group" data-kind={props.kind}>
|
||||
<summary>
|
||||
<Dynamic component={`h${props.level}`} data-slot="group-label">
|
||||
{props.title}
|
||||
@@ -765,22 +794,17 @@ function NoteGroup(props: { title: string; level: number; notes: ChangelogNote[]
|
||||
</Dynamic>
|
||||
<Chevron />
|
||||
</summary>
|
||||
{items(props.notes)}
|
||||
{props.defer ? more(props.defer, props.notes.length) : items(props.notes)}
|
||||
</details>
|
||||
</Match>
|
||||
<Match when={true}>
|
||||
<section data-slot="group">
|
||||
<section data-slot="group" data-kind={props.kind}>
|
||||
<Dynamic component={`h${props.level}`} data-slot="group-label">
|
||||
{props.title}
|
||||
</Dynamic>
|
||||
{items(long() ? props.notes.slice(0, props.limit) : props.notes)}
|
||||
<Show when={long() && props.more}>
|
||||
{(_) => (
|
||||
<a data-slot="show-more" href={props.more}>
|
||||
{i18n.t("changelog.list.more", { count: props.notes.length - props.limit })}
|
||||
<span data-slot="sr-only"> {props.title.toLowerCase()}</span>
|
||||
</a>
|
||||
)}
|
||||
{(href) => more(href(), props.notes.length - props.limit)}
|
||||
</Show>
|
||||
</section>
|
||||
</Match>
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
} from "~/component/site/changelog-entry"
|
||||
import { useMarkdown } from "~/component/site/use-markdown"
|
||||
import { PageTitle } from "~/component/site/sticky-title"
|
||||
import { staticRender } from "~/lib/static-render"
|
||||
|
||||
export default function Changelog() {
|
||||
const i18n = useI18n()
|
||||
@@ -84,7 +85,14 @@ export default function Changelog() {
|
||||
when={current().entries.length > 0}
|
||||
fallback={<p data-slot="lead">{i18n.t("changelog.filter.empty")}</p>}
|
||||
>
|
||||
<ChangelogTimeline entries={current().entries} level={2} limit={6} />
|
||||
{/* Collapsed lists load from each entry's page, which has the same notes unless a filter
|
||||
leaves some out. Hydrated (vite dev) there is no script to load them. */}
|
||||
<ChangelogTimeline
|
||||
entries={current().entries}
|
||||
level={2}
|
||||
limit={6}
|
||||
defer={staticRender() && current().filter.length === 0}
|
||||
/>
|
||||
</Show>
|
||||
<ChangelogPages view={current()} />
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user