diff --git a/apps/site/scripts/reader-body-document.ts b/apps/site/scripts/reader-body-document.ts index 719dcfbc..a22056a3 100644 --- a/apps/site/scripts/reader-body-document.ts +++ b/apps/site/scripts/reader-body-document.ts @@ -152,6 +152,9 @@ export const compileReaderNodes = ( return Schema.decodeSync(Schema.Array(ReaderNodeSchema))(converted); }; +export const compileReaderSnippet = (html: string, sourcePath: string) => + compileReaderNodes(parseDocument(html).children, sourcePath); + const readBody = ( html: string, sourcePath: string, diff --git a/apps/web/effect-ui.ts b/apps/web/effect-ui.ts index 42576fa7..6a6a9545 100644 --- a/apps/web/effect-ui.ts +++ b/apps/web/effect-ui.ts @@ -4,6 +4,7 @@ import type { Plugin } from "vite"; const entries = { "directory-effect-ui": "src/client/directory-effect-ui/entry.ts", "news-effect-ui": "src/client/news-effect-ui/entry.ts", + "reader-effect-ui": "src/client/reader-effect-ui/entry.ts", }; const manifestFile = ".vite/manifest.json"; diff --git a/apps/web/scripts/reader-effect-ui-legacy.ts b/apps/web/scripts/reader-effect-ui-legacy.ts new file mode 100644 index 00000000..b3b93888 --- /dev/null +++ b/apps/web/scripts/reader-effect-ui-legacy.ts @@ -0,0 +1,218 @@ +import { Effect, Option } from "effect"; + +import { compileReaderSnippet } from "../../site/scripts/reader-body-document.js"; +import { ReaderInputError } from "../../site/scripts/reader-input-error.js"; +import { ReaderBlock, ReaderInline } from "../src/client/reader-document.js"; +import type { ReaderInlineValue } from "../src/client/reader-document.js"; +import { ReaderNode } from "../src/client/reader-node.js"; +import type { ReaderNodeValue } from "../src/client/reader-node.js"; +import type { ReaderPageFlags } from "../src/client/reader/model.js"; +import { readerParagraphAnchor } from "../src/features/reader-paragraph.js"; + +type Element = ReturnType; + +const headingTags = { 2: "h2", 3: "h3", 4: "h4" } as const; + +const text = (value: string) => ReaderNode.Text({ value }); + +const element = ( + tag: Element["tag"], + children: readonly ReaderNodeValue[], + attributes: Element["attributes"] = [] +) => ReaderNode.Element({ attributes, children, tag }); + +const attributed = ( + tag: Element["tag"], + name: Element["attributes"][number]["name"], + value: string, + children: readonly ReaderNodeValue[] +) => element(tag, children, [{ name, value }]); + +const link = (href: string, label: string) => + attributed("a", "href", href, [text(label)]); + +const renderInline = ( + inline: ReaderInlineValue, + counts: Readonly>, + pagePath: string +): ReaderNodeValue => + ReaderInline.$match(inline, { + Code: ({ value }) => element("code", [text(value)]), + Emphasis: ({ content }) => + element( + "em", + content.map((child) => renderInline(child, counts, pagePath)) + ), + Link: ({ href, value }) => { + const anchor = link(href, value); + const count = counts[href] ?? 0; + + if ( + href === pagePath || + !/^\/(?:lore|systems|skills)\//u.test(href) || + count < 2 + ) { + return anchor; + } + + return element("span", [ + anchor, + attributed("sup", "class", "inbound-count", [ + element( + "a", + [text(String(count))], + [ + { name: "href", value: `${href}#linked-from` }, + { name: "aria-label", value: `${count} pages link here` }, + ] + ), + ]), + ]); + }, + Strong: ({ content }) => + element( + "strong", + content.map((child) => renderInline(child, counts, pagePath)) + ), + Text: ({ value }) => + text(value.replaceAll(/(?<=\p{L})\u0027(?=\p{L})/gu, "’")), + }); + +const missingSnippet = (message: string) => + element( + "p", + [text(message)], + [ + { name: "class", value: "reader-missing" }, + { name: "role", value: "note" }, + ] + ); + +const legacyNodes = (flags: ReaderPageFlags) => { + const { anchors = [], inboundCounts = {} } = + Option.getOrUndefined(flags.references) ?? {}; + + const { path, sourcePath } = flags.page; + + const paragraph = ( + tag: "li" | "p", + content: readonly ReaderInlineValue[] + ) => { + const id = readerParagraphAnchor(tag, content, anchors); + + const children = content.map((inline) => + renderInline(inline, inboundCounts, path) + ); + + return id === undefined + ? element(tag, children) + : attributed(tag, "id", id, [ + ...children, + element( + "a", + [text("ΒΆ")], + [ + { name: "href", value: `#${id}` }, + { name: "class", value: "paragraph-link" }, + { name: "aria-label", value: "Link to this paragraph" }, + ] + ), + ]); + }; + + const snippet = (html: string) => + attributed( + "div", + "class", + "reader-snippet", + compileReaderSnippet(html, sourcePath) + ); + + const codeFence = (value: string) => { + const fence = flags.codeFences.find((entry) => entry.value === value); + + return fence === undefined + ? missingSnippet("This code block is not in the built page.") + : snippet(fence.html); + }; + + return flags.blocks.map((block) => + ReaderBlock.match(block, { + CodeFence: ({ value }) => codeFence(value), + CopyPrompt: ({ id }) => { + const control = ReaderNode.CopyPrompt({ id, primary: false }); + const prompt = flags.copyPrompts.find((entry) => entry.id === id); + + return prompt?.showText === true + ? attributed("div", "class", "prompt", [ + control, + attributed("details", "class", "prompt-text", [ + element("summary", [text("See the prompt")]), + element("pre", [element("code", [text(prompt.text)])]), + ]), + ]) + : control; + }, + Diagram: ({ alt, value }) => + element( + "figure", + [codeFence(value), element("figcaption", [text(alt)])], + [ + { name: "role", value: "img" }, + { name: "aria-label", value: alt }, + ] + ), + Heading: ({ id, level, title }) => + attributed(headingTags[level ?? 2], "id", id, [text(title)]), + List: ({ items }) => + element( + "ul", + items.map((item) => paragraph("li", item)) + ), + Paragraph: ({ content }) => paragraph("p", content), + PromptText: ({ value }) => + attributed("pre", "class", "prompt", [text(value)]), + Snippet: (reference) => { + const excerpt = flags.snippets.find( + (entry) => + entry.repo === reference.repo && + entry.path === reference.path && + entry.at === reference.at && + entry.lines === reference.lines + ); + + return excerpt === undefined + ? missingSnippet( + `The excerpt ${reference.path} lines ${reference.lines} is not in the built page.` + ) + : snippet(excerpt.html); + }, + }) + ); +}; + +export const compileLegacyReaderPage = Effect.fn("reader.compileLegacyPage")( + function* compileLegacyReaderPage(flags: ReaderPageFlags) { + const { path, sourcePath } = flags.page; + + const blocks = yield* Effect.try({ + catch: (cause) => + new ReaderInputError({ + cause, + message: `Could not project the reader blocks for ${path}. Fix: check the excerpt tags and attributes in \`reader-body-document.ts\`.`, + sourcePath, + }), + try: () => legacyNodes(flags), + }); + + const body = Option.getOrElse(flags.bodyNodes, () => [ + element("h1", [text(flags.heading)]), + ]); + + return { + ...flags, + blocks: [], + bodyNodes: Option.some([...body, ...blocks]), + }; + } +); diff --git a/apps/web/src/client/reader-copy-prompt.ts b/apps/web/src/client/reader-copy-prompt.ts new file mode 100644 index 00000000..26a4036d --- /dev/null +++ b/apps/web/src/client/reader-copy-prompt.ts @@ -0,0 +1,8 @@ +import { Schema } from "effect"; + +export const CopyPrompt = Schema.Struct({ + id: Schema.String, + label: Schema.String, + showText: Schema.Boolean, + text: Schema.String, +}); diff --git a/apps/web/src/client/reader-effect-ui/command.ts b/apps/web/src/client/reader-effect-ui/command.ts new file mode 100644 index 00000000..07af69d7 --- /dev/null +++ b/apps/web/src/client/reader-effect-ui/command.ts @@ -0,0 +1,44 @@ +import { Command } from "@effect/ui"; +import { Effect, Schema } from "effect"; + +import { ReaderMessage } from "./model.js"; + +export const DetectClipboard = Command.make( + "reader/DetectClipboard", + { args: {} }, + () => + Effect.sync(() => + ReaderMessage.CompletedDetectClipboard({ + available: navigator.clipboard !== undefined, + }) + ) +); + +class ClipboardFailure extends Schema.TaggedError< + ClipboardFailure, + { readonly brand: unique symbol } +>()("ClipboardFailure", { cause: Schema.Unknown }) {} + +export const CopyReaderText = Command.make( + "reader/CopyReaderText", + { args: { id: Schema.String, text: Schema.String }, mode: "concurrent" }, + ({ id, text }) => + Effect.tryPromise({ + catch: (cause) => new ClipboardFailure({ cause }), + try: () => navigator.clipboard.writeText(text), + }).pipe( + Effect.match({ + onFailure: () => ReaderMessage.FailedCopyReaderText({ id }), + onSuccess: () => ReaderMessage.SucceededCopyReaderText({ id }), + }) + ) +); + +export const WaitBeforeCopyReset = Command.make( + "reader/WaitBeforeCopyReset", + { args: { id: Schema.String }, mode: "concurrent" }, + ({ id }) => + Effect.sleep("2 seconds").pipe( + Effect.as(ReaderMessage.CompletedWaitBeforeCopyReset({ id })) + ) +); diff --git a/apps/web/src/client/reader-effect-ui/component.ts b/apps/web/src/client/reader-effect-ui/component.ts new file mode 100644 index 00000000..3543b393 --- /dev/null +++ b/apps/web/src/client/reader-effect-ui/component.ts @@ -0,0 +1,69 @@ +import { Html } from "@effect/ui/html"; +import { Record } from "effect"; + +import { view } from "../../features/reader-effect-ui/view.js"; +import { + CopyReaderText, + DetectClipboard, + WaitBeforeCopyReset, +} from "./command.js"; +import { + findCopyPrompt, + ReaderMessage, + ReaderModel, + ReaderProps, +} from "./model.js"; + +export const ReaderPage = Html.component({ + name: "ReaderPage", + props: ReaderProps, + model: ReaderModel, + message: ReaderMessage, +}).make({ + init: ($) => { + const initial = $.set({ clipboard: "unknown", copyStatuses: {} }); + + return $.props.copyPrompts.length === 0 + ? initial + : initial.run(DetectClipboard.make({})); + }, + update: ($, message) => + ReaderMessage.match(message, { + ClickedCopy: ({ id }) => { + const status = $.model.copyStatuses[id]; + const prompt = findCopyPrompt($.props, id); + + if ( + $.model.clipboard !== "available" || + status === "copying" || + status === "copied" || + prompt === undefined + ) { + return $.model; + } + + return $.evolve({ + copyStatuses: Record.set($.model.copyStatuses, id, "copying"), + }).run(CopyReaderText.make({ id, text: prompt.text })); + }, + CompletedDetectClipboard: ({ available }) => + $.evolve({ clipboard: available ? "available" : "unavailable" }), + CompletedWaitBeforeCopyReset: ({ id }) => + $.model.copyStatuses[id] === "copied" + ? $.evolve({ copyStatuses: Record.remove(id) }) + : $.model, + FailedCopyReaderText: ({ id }) => + $.model.copyStatuses[id] === "copying" + ? $.evolve({ + copyStatuses: Record.set($.model.copyStatuses, id, "failed"), + }) + : $.model, + SucceededCopyReaderText: ({ id }) => + $.model.copyStatuses[id] === "copying" + ? $.evolve({ + copyStatuses: Record.set($.model.copyStatuses, id, "copied"), + }).run(WaitBeforeCopyReset.make({ id })) + : $.model, + }), + view: (h, model) => view(h, h.props, model), +}); diff --git a/apps/web/src/client/reader-effect-ui/entry.ts b/apps/web/src/client/reader-effect-ui/entry.ts new file mode 100644 index 00000000..1f5a4f04 --- /dev/null +++ b/apps/web/src/client/reader-effect-ui/entry.ts @@ -0,0 +1,11 @@ +import { Effect } from "effect"; + +import { installReaderTools } from "../web-mcp-boot.js"; +import { hydrateReader } from "./hydration.js"; + +import "../../../../site/src/rat.css"; +import "../reader.css"; + +installReaderTools(); + +Effect.runFork(hydrateReader(document)); diff --git a/apps/web/src/client/reader-effect-ui/hydration.ts b/apps/web/src/client/reader-effect-ui/hydration.ts new file mode 100644 index 00000000..4772835a --- /dev/null +++ b/apps/web/src/client/reader-effect-ui/hydration.ts @@ -0,0 +1,50 @@ +import { HtmlHydrate } from "@effect/ui/html"; +import { Cause, Effect, Schema } from "effect"; + +import { ReaderPage } from "./component.js"; +import { ReaderHandoff, readerHandoffId, readerRootId } from "./model.js"; + +const decodeHandoff = Schema.decodeEffect(Schema.fromJsonString(ReaderHandoff)); + +const adoptReader = Effect.fn("reader.adopt")(function* adoptReader( + container: HTMLDivElement, + { props, state }: typeof ReaderHandoff.Type +) { + const root = yield* HtmlHydrate.hydrateEffect( + ReaderPage, + props, + container, + state + ); + + yield* root.adopted; + + container.dataset.hydrated = "true"; + + return yield* Effect.never; +}); + +export const hydrateReader = (page: Document) => + Effect.gen(function* hydrateReaderPage() { + const container = page.querySelector(`#${readerRootId}`); + const payload = page.querySelector(`#${readerHandoffId}`); + + if (!(container instanceof HTMLDivElement) || payload === null) { + return yield* Effect.void; + } + + const handoff = yield* decodeHandoff(payload.textContent ?? ""); + + return yield* adoptReader(container, handoff); + }).pipe( + Effect.scoped, + Effect.catchCause((cause) => + Cause.hasInterruptsOnly(cause) + ? Effect.interrupt + : Effect.logError( + "Reader hydration failed", + { path: page.location.pathname }, + cause + ) + ) + ); diff --git a/apps/web/src/client/reader-effect-ui/model.ts b/apps/web/src/client/reader-effect-ui/model.ts new file mode 100644 index 00000000..02253e72 --- /dev/null +++ b/apps/web/src/client/reader-effect-ui/model.ts @@ -0,0 +1,52 @@ +import { UiSchema } from "@effect/ui"; +import { Schema } from "effect"; + +import { bibliographySourceSchema } from "../../../../site/scripts/component-data.js"; +import { ReaderReferences } from "../../page-descriptor.js"; +import { effectUiHandoff } from "../effect-ui-handoff.js"; +import { CopyPrompt } from "../reader-copy-prompt.js"; +import { ReaderBreadcrumb, ReaderNodeSchema } from "../reader-node.js"; + +export const ReaderProps = Schema.Struct({ + bibliography: Schema.Array(bibliographySourceSchema), + breadcrumb: Schema.OptionFromOptional(ReaderBreadcrumb), + copyPrompts: Schema.Array(CopyPrompt), + heading: Schema.String, + newsTitle: Schema.OptionFromOptional(Schema.String), + nodes: Schema.Array(ReaderNodeSchema), + origin: Schema.String, + page: Schema.Struct({ + path: Schema.String, + sourcePath: Schema.String, + status: Schema.Int, + }), + references: Schema.OptionFromOptional(ReaderReferences), +}); + +export const ReaderHandoff = effectUiHandoff(ReaderProps); + +export const readerRootId = "reader-effect-ui"; + +export const readerHandoffId = "reader-effect-ui-handoff"; + +export type ReaderPageProps = typeof ReaderProps.Type; + +const CopyStatus = Schema.Literals(["copying", "copied", "failed"]); + +export const ReaderModel = Schema.Struct({ + clipboard: Schema.Literals(["unknown", "unavailable", "available"]), + copyStatuses: Schema.Record(Schema.String, CopyStatus), +}); + +export type ReaderState = typeof ReaderModel.Type; + +export const ReaderMessage = UiSchema.TaggedEnum({ + ClickedCopy: { id: Schema.String }, + CompletedDetectClipboard: { available: Schema.Boolean }, + CompletedWaitBeforeCopyReset: { id: Schema.String }, + FailedCopyReaderText: { id: Schema.String }, + SucceededCopyReaderText: { id: Schema.String }, +}); + +export const findCopyPrompt = (props: ReaderPageProps, id: string) => + props.copyPrompts.find((prompt) => prompt.id === id); diff --git a/apps/web/src/client/reader/model.ts b/apps/web/src/client/reader/model.ts index cf636361..2c40b66d 100644 --- a/apps/web/src/client/reader/model.ts +++ b/apps/web/src/client/reader/model.ts @@ -9,19 +9,13 @@ import { import { Model as CafeModel } from "../cafe/model.js"; import { Model as DocsModel } from "../docs/model.js"; import { Model as MotionDemoModel } from "../motion/model.js"; +import { CopyPrompt } from "../reader-copy-prompt.js"; import { ReaderBlock } from "../reader-document.js"; import { ReaderBreadcrumb, ReaderNodeSchema } from "../reader-node.js"; import { Model as TubeModel } from "../tube/model.js"; export { ReaderReferences } from "../../page-descriptor.js"; -export const CopyPrompt = Schema.Struct({ - id: Schema.String, - label: Schema.String, - showText: Schema.Boolean, - text: Schema.String, -}); - export const ReaderFlags = Schema.Struct({ agentMarkdown: Schema.OptionFromOptional(Schema.String), bibliography: Schema.Array(bibliographySourceSchema), diff --git a/apps/web/src/entry.server.ts b/apps/web/src/entry.server.ts index 2c959a2e..738d4da1 100644 --- a/apps/web/src/entry.server.ts +++ b/apps/web/src/entry.server.ts @@ -10,10 +10,15 @@ import { import { findPage } from "./client/reader-pages.js"; import type { ReaderPageFlags } from "./client/reader/model.js"; import { newsOrder } from "./features/cafe/news-order.js"; -import { directoryRouter } from "./features/site-route.js"; +import { + directoryRouter, + isWithinSection, + loreRouter, +} from "./features/site-route.js"; import { isWorkerFirstReaderRoute } from "./reader-routes.js"; import { readerPrerenderOrigin } from "./server/prerender-origin.js"; import { EffectUiAssets } from "./server/reader-document.js"; +import { readerSupportsEffectUi } from "./server/reader-effect-ui-props.js"; import { ReaderErrorTemplate } from "./server/reader-error-template.js"; import { renderDirectoryOrError, @@ -35,6 +40,7 @@ const effectUiAssets = Schema.decodeUnknownSync( Schema.Struct({ "directory-effect-ui": EffectUiAssets, "news-effect-ui": EffectUiAssets, + "reader-effect-ui": EffectUiAssets, }) )(effectUiAssetManifest); @@ -149,6 +155,17 @@ const renderReaderHtml = (page: ReaderPageFlags) => { ); } + if (isWithinSection(loreRouter(), path) && readerSupportsEffectUi(page)) { + return Effect.tryPromise( + () => import("./server/reader-effect-ui-page.js") + ).pipe( + Effect.flatMap(({ renderEffectUiReader }) => + renderEffectUiReader(page, effectUiAssets["reader-effect-ui"]) + ), + Effect.map((application) => ({ application, status })) + ); + } + return renderReaderApplication(page).pipe( Effect.map((application) => ({ application, status })) ); diff --git a/apps/web/src/features/reader-effect-ui/chrome.ts b/apps/web/src/features/reader-effect-ui/chrome.ts new file mode 100644 index 00000000..bb1d2465 --- /dev/null +++ b/apps/web/src/features/reader-effect-ui/chrome.ts @@ -0,0 +1,159 @@ +import type { Html } from "@effect/ui/html"; +import * as stylex from "@stylexjs/stylex"; +import { Option } from "effect"; + +import type { + ReaderMessage, + ReaderPageProps, +} from "../../client/reader-effect-ui/model.js"; +import { readerStyles } from "../reader.stylex.js"; + +type ReaderHtml = Html.H; + +const siteSections = [ + ["/skills", "skills"], + ["/lore", "lore"], + ["/systems", "systems"], + ["/news", "news"], + ["/all-stars", "all stars"], + ["/glossary", "glossary"], + ["/search", "search"], +] as const; + +const sectionIndexes: ReadonlySet = new Set([ + "/", + "/lore", + "/glossary", + "/systems", + "/skills", + "/search", + "/tokenmaxx", +]); + +const inSection = (section: string, path: string) => + path === section || path.startsWith(`${section}/`); + +const link = (h: ReaderHtml, href: string, label: string) => + h.a.attr("href", href).children(label); + +export const siteHeader = (h: ReaderHtml) => + h.header + .class( + stylex.props(readerStyles.bounded, readerStyles.header).className ?? "" + ) + .children( + h.nav + .attrs({ "aria-label": "Primary navigation", class: "site-nav" }) + .children( + h.a + .attrs({ class: "brand", href: "/" }) + .children(h.strong("πŸ€ Rat Stack")), + h.div + .class("site-links") + .children( + h.ul( + ...siteSections.map(([href, label]) => + h.li(link(h, href, label)) + ) + ), + h.ul(h.li(link(h, "/llms.txt", "agent guide"))) + ) + ) + ); + +export const agentPointer = (h: ReaderHtml, origin: string) => + h.p + .attrs({ "aria-hidden": "true", class: "agent-pointer visually-hidden" }) + .children( + "For agents: start with the ", + h.a + .attrs({ href: `${origin}/llms.txt`, tabindex: "-1" }) + .children("agent guide"), + ". Every page is Markdown by default; add Accept: text/html for HTML." + ); + +export const newsCallout = (h: ReaderHtml, title: string) => + h.aside + .attrs({ "aria-label": "New on /news", class: "news-callout" }) + .children(h.span("New on /news:"), " ", link(h, "/news", title)); + +const defaultBreadcrumb = (path: string, name: string) => { + if (inSection("/prompts", path)) { + return { href: "/prompts", label: "prompts", name }; + } + + return path.startsWith("/lore/") + ? { href: "/lore", label: "lore", name } + : { href: "/", label: "source files", name }; +}; + +export const breadcrumbView = (h: ReaderHtml, props: ReaderPageProps) => { + const { path } = props.page; + + if (sectionIndexes.has(path)) { + return []; + } + + const { href, label, name } = Option.getOrElse(props.breadcrumb, () => + defaultBreadcrumb(path, props.heading) + ); + + return [ + h.nav + .attrs({ "aria-label": "Breadcrumb", class: "breadcrumb" }) + .children(link(h, href, label), ` / ${name}`), + ]; +}; + +export const siteFooter = ( + h: ReaderHtml, + { path, status }: ReaderPageProps["page"] +) => { + const includePrompts = + status < 400 && + (path === "/" || + path === "/learn" || + inSection("/lore", path) || + inSection("/prompts", path)); + + return h.footer + .class(stylex.props(readerStyles.bounded).className ?? "") + .children( + h.hr, + h.div + .class("site-reference") + .children( + h.section + .attr("aria-label", "Explore") + .children( + h.h2("Explore"), + h.ul( + h.li(link(h, "/learn", "learn mode")), + h.li(link(h, "/glossary", "glossary")), + ...(includePrompts + ? [h.li(link(h, "/prompts", "prompts"))] + : []), + h.li(link(h, "/log", "change log")), + h.li(link(h, "/resources/peers", "peers")) + ) + ), + h.section + .attr("aria-label", "Reference") + .children( + h.h2("Reference"), + h.ul( + h.li(link(h, "/llms.txt", "agent guide")), + h.li(link(h, "/openapi.json", "API docs")), + h.li( + link(h, "https://github.com/joelhooks/rat-stack", "source") + ) + ) + ) + ), + h.p( + "Markdown by default. HTML when you ask for it. ", + link(h, "/llms.txt", "Agents start here"), + "." + ) + ); +}; diff --git a/apps/web/src/features/reader-effect-ui/copy.ts b/apps/web/src/features/reader-effect-ui/copy.ts new file mode 100644 index 00000000..fcc5ff9a --- /dev/null +++ b/apps/web/src/features/reader-effect-ui/copy.ts @@ -0,0 +1,87 @@ +import type { Html } from "@effect/ui/html"; + +import { + findCopyPrompt, + ReaderMessage, +} from "../../client/reader-effect-ui/model.js"; +import type { + ReaderPageProps, + ReaderState, +} from "../../client/reader-effect-ui/model.js"; + +type ReaderHtml = Html.H; + +const missingReference = (h: ReaderHtml, description: string) => + h.p.attrs({ class: "reader-missing", role: "note" }).children(description); + +const icon = (h: ReaderHtml, copied: boolean) => + h + .el("svg") + .attrs({ + "aria-hidden": "true", + class: copied ? "icon icon-done" : "icon", + fill: "none", + focusable: "false", + height: "16", + stroke: "currentColor", + "stroke-linecap": "round", + "stroke-linejoin": "round", + "stroke-width": copied ? "1.5" : "2", + viewBox: "0 0 24 24", + width: "16", + }) + .children( + ...(copied + ? [h.el("path").attr("d", "M5 14L8.5 17.5L19 6.5")] + : [ + h.el("path").attr("d", "M12 8V4H8"), + h + .el("rect") + .attrs({ height: "12", rx: "2", width: "16", x: "4", y: "8" }), + h.el("path").attr("d", "M2 14h2m16 0h2m-7-1v2m-6-2v2"), + ]) + ); + +const copyStatusText = { + copied: "Copied βœ“", + copying: "", + failed: "Copy failed. Select the text and copy it.", +}; + +export const copyControl = ( + h: ReaderHtml, + props: ReaderPageProps, + model: ReaderState, + id: string, + primary: boolean +) => { + const prompt = findCopyPrompt(props, id); + + if (prompt === undefined) { + return missingReference(h, `The ${id} prompt is not in this page.`); + } + + const status = model.copyStatuses[id]; + const copied = status === "copied"; + const statusText = status === undefined ? "" : copyStatusText[status]; + + return h.span.class("copy-actions").children( + h.button + .attrs({ + "aria-label": prompt.label, + class: primary ? "copy copy-primary" : "copy", + "data-copied": String(copied), + "data-text": prompt.text, + hidden: model.clipboard === "available" ? undefined : "", + type: "button", + }) + .on("click", ReaderMessage.ClickedCopy({ id })) + .children( + icon(h, copied), + h.span.class("copy-label").children(copied ? "Copied βœ“" : prompt.label) + ), + h.span + .attrs({ "aria-live": "polite", class: "copy-status", role: "status" }) + .children(statusText) + ); +}; diff --git a/apps/web/src/features/reader-effect-ui/references.ts b/apps/web/src/features/reader-effect-ui/references.ts new file mode 100644 index 00000000..2a6f7de0 --- /dev/null +++ b/apps/web/src/features/reader-effect-ui/references.ts @@ -0,0 +1,103 @@ +import type { Html } from "@effect/ui/html"; +import { Option } from "effect"; + +import type { + ReaderMessage, + ReaderPageProps, +} from "../../client/reader-effect-ui/model.js"; + +type ReaderHtml = Html.H; + +type References = Option.Option.Value; + +export const bibliographyView = ( + h: ReaderHtml, + sources: ReaderPageProps["bibliography"] +) => + sources.length === 0 + ? [] + : [ + h.section + .attrs({ "aria-labelledby": "sources", class: "bibliography" }) + .children( + h.h2.attr("id", "sources").children("Sources"), + h.ol( + ...sources.map((source, index) => + h.li + .attr("id", `source-${index + 1}`) + .children( + ...(source.kind === "linked" + ? [ + h.a.attr("href", source.url).children(source.title), + `. ${source.publisher}. ${source.note} Accessed ${source.accessed}.`, + ] + : [ + `${source.title}. Recorded ${source.recordedAt}. ${source.note}.`, + ]) + ) + ) + ) + ), + ]; + +const backlinksView = (h: ReaderHtml, backlinks: References["backlinks"]) => + backlinks.length === 0 + ? [] + : [ + h.section + .attrs({ + "aria-labelledby": "linked-from", + class: "bibliography linked-from", + }) + .children( + h.h2.attr("id", "linked-from").children("Linked from"), + h.ol( + ...backlinks.map((reference) => + h.li( + h.a.attr("href", reference.route).children(reference.title), + `. ${reference.description}`, + ...(reference.context === "" ? [] : [h.p(reference.context)]) + ) + ) + ) + ), + ]; + +const lastChangeView = ( + h: ReaderHtml, + sourcePath: string, + change: References["lastChange"] +) => + change === undefined + ? [] + : [ + h.hr, + h.p( + `Last changed ${change.date} in `, + h.a + .attr( + "href", + `https://github.com/joelhooks/rat-stack/commit/${change.hash}` + ) + .children(change.short), + ". ", + h.a + .attr( + "href", + `https://github.com/joelhooks/rat-stack/blob/main/${sourcePath}` + ) + .children("Source on GitHub"), + ". ", + h.a.attr("href", "/log").children("Change log"), + "." + ), + ]; + +export const referencesView = (h: ReaderHtml, props: ReaderPageProps) => + Option.match(props.references, { + onNone: () => [], + onSome: (references) => [ + ...lastChangeView(h, props.page.sourcePath, references.lastChange), + ...backlinksView(h, references.backlinks), + ], + }); diff --git a/apps/web/src/features/reader-effect-ui/view.ts b/apps/web/src/features/reader-effect-ui/view.ts new file mode 100644 index 00000000..a53de300 --- /dev/null +++ b/apps/web/src/features/reader-effect-ui/view.ts @@ -0,0 +1,67 @@ +import type { View } from "@effect/ui"; +import type { Html } from "@effect/ui/html"; +import * as stylex from "@stylexjs/stylex"; +import { Option } from "effect"; + +import type { + ReaderMessage, + ReaderPageProps, + ReaderState, +} from "../../client/reader-effect-ui/model.js"; +import { ReaderNode } from "../../client/reader-node.js"; +import type { ReaderNodeValue } from "../../client/reader-node.js"; +import { readerStyles } from "../reader.stylex.js"; +import { + agentPointer, + breadcrumbView, + newsCallout, + siteFooter, + siteHeader, +} from "./chrome.js"; +import { copyControl } from "./copy.js"; +import { bibliographyView, referencesView } from "./references.js"; + +type ReaderHtml = Html.H; + +type ReaderInput = View.Input; + +const renderNode = ( + h: ReaderHtml, + node: ReaderNodeValue, + props: ReaderPageProps, + model: ReaderState +): ReaderInput => + ReaderNode.$match(node, { + CopyPrompt: ({ id, primary }) => copyControl(h, props, model, id, primary), + Element: ({ attributes, children, tag }) => + h + .el(tag) + .attrs( + Object.fromEntries(attributes.map(({ name, value }) => [name, value])) + ) + .children( + ...children.map((child) => renderNode(h, child, props, model)) + ), + Text: ({ value }) => value, + }); + +export const view = ( + h: ReaderHtml, + props: ReaderPageProps, + model: ReaderState +) => + h.div.class(stylex.props(readerStyles.shell).className ?? "").children( + siteHeader(h), + h.main.attr("data-path", props.page.path).children( + agentPointer(h, props.origin), + ...Option.match(props.newsTitle, { + onNone: () => [], + onSome: (title) => [newsCallout(h, title)], + }), + ...breadcrumbView(h, props), + ...props.nodes.map((node) => renderNode(h, node, props, model)), + ...bibliographyView(h, props.bibliography), + ...referencesView(h, props) + ), + siteFooter(h, props.page) + ); diff --git a/apps/web/src/features/reader-paragraph.ts b/apps/web/src/features/reader-paragraph.ts index c86b5429..1d2bb193 100644 --- a/apps/web/src/features/reader-paragraph.ts +++ b/apps/web/src/features/reader-paragraph.ts @@ -12,13 +12,11 @@ const inlineText = (inline: ReaderInlineValue): string => Text: ({ value }) => value, }); -export const readerParagraph = ( +export const readerParagraphAnchor = ( tag: "p" | "li", content: readonly ReaderInlineValue[], - anchors: readonly { readonly id: string; readonly text: string }[], - h: HtmlBuilder, - renderInline: (inline: ReaderInlineValue) => Html | string -): Html => { + anchors: readonly { readonly id: string; readonly text: string }[] +) => { const text = content .map(inlineText) .join("") @@ -26,9 +24,19 @@ export const readerParagraph = ( .replaceAll(/\s+/gu, " ") .trim(); - const id = anchors.find( + return anchors.find( (anchor) => anchor.id.startsWith(`${tag}-`) && anchor.text === text )?.id; +}; + +export const readerParagraph = ( + tag: "p" | "li", + content: readonly ReaderInlineValue[], + anchors: readonly { readonly id: string; readonly text: string }[], + h: HtmlBuilder, + renderInline: (inline: ReaderInlineValue) => Html | string +): Html => { + const id = readerParagraphAnchor(tag, content, anchors); return h[tag](id === undefined ? [] : [h.Id(id)], [ ...content.map(renderInline), diff --git a/apps/web/src/server/reader-effect-ui-page.ts b/apps/web/src/server/reader-effect-ui-page.ts new file mode 100644 index 00000000..a6ac5b2d --- /dev/null +++ b/apps/web/src/server/reader-effect-ui-page.ts @@ -0,0 +1,39 @@ +import { HtmlServer } from "@effect/ui/html"; +import { Effect, Schema } from "effect"; + +import { ReaderPage } from "../client/reader-effect-ui/component.js"; +import { + ReaderHandoff, + readerHandoffId, + readerRootId, +} from "../client/reader-effect-ui/model.js"; +import type { ReaderPageFlags } from "../client/reader/model.js"; +import { withReaderHead } from "./reader-document.js"; +import type { EffectUiAssets } from "./reader-document.js"; +import { readerProps } from "./reader-effect-ui-props.js"; +import { effectUiDocument } from "./reader-effect-ui.js"; + +const encodeHandoff = Schema.encodeEffect(ReaderHandoff); + +export const renderEffectUiReader = Effect.fn("reader.renderEffectUi")( + function* renderEffectUiReader( + page: ReaderPageFlags, + assets: typeof EffectUiAssets.Type + ) { + const props = readerProps(page); + const rendered = yield* HtmlServer.renderToHtml(ReaderPage, props); + const handoff = yield* encodeHandoff({ props, state: rendered.state }); + const canonical = `${page.origin}${page.page.metadata.canonicalPath}`; + + return withReaderHead( + { + canonical, + html: `
${rendered.html}
`, + ogUrl: canonical, + title: page.page.metadata.title, + ...effectUiDocument(assets, readerHandoffId, handoff), + }, + page + ); + } +); diff --git a/apps/web/src/server/reader-effect-ui-props.ts b/apps/web/src/server/reader-effect-ui-props.ts new file mode 100644 index 00000000..48208bae --- /dev/null +++ b/apps/web/src/server/reader-effect-ui-props.ts @@ -0,0 +1,34 @@ +import { Option } from "effect"; + +import type { ReaderPageProps } from "../client/reader-effect-ui/model.js"; +import { ReaderNode } from "../client/reader-node.js"; +import type { ReaderPageFlags } from "../client/reader/model.js"; + +export const readerSupportsEffectUi = (flags: ReaderPageFlags) => + flags.blocks.length === 0 && + Option.isNone(flags.cafe) && + Option.isNone(flags.docs) && + Option.isNone(flags.motion) && + Option.isNone(flags.tube); + +export const readerProps = (flags: ReaderPageFlags): ReaderPageProps => { + const { path, sourcePath, status } = flags.page; + + return { + bibliography: flags.bibliography, + breadcrumb: flags.breadcrumb, + copyPrompts: flags.copyPrompts, + heading: flags.heading, + newsTitle: flags.newsTitle, + nodes: Option.getOrElse(flags.bodyNodes, () => [ + ReaderNode.Element({ + attributes: [], + children: [ReaderNode.Text({ value: flags.heading })], + tag: "h1", + }), + ]), + origin: flags.origin, + page: { path, sourcePath, status }, + references: flags.references, + }; +}; diff --git a/apps/web/test/effect-ui-assets.test.ts b/apps/web/test/effect-ui-assets.test.ts index 926414b1..a72ce18e 100644 --- a/apps/web/test/effect-ui-assets.test.ts +++ b/apps/web/test/effect-ui-assets.test.ts @@ -46,6 +46,8 @@ const directoryEntry = "src/client/directory-effect-ui/entry.ts"; const newsEntry = "src/client/news-effect-ui/entry.ts"; +const readerEntry = "src/client/reader-effect-ui/entry.ts"; + const serverEntry = "virtual:reader-asset-fixture"; type ManifestFixture = Parameters[0]; @@ -60,7 +62,11 @@ const fixture = (overrideManifest?: ManifestFixture): Plugin => ({ return `export { default } from ${JSON.stringify(assetModule)}`; } - if (id.endsWith(directoryEntry) || id.endsWith(newsEntry)) { + if ( + [directoryEntry, newsEntry, readerEntry].some((entry) => + id.endsWith(entry) + ) + ) { return `export default ${JSON.stringify(id)}`; } @@ -126,8 +132,8 @@ it.effect("loads dev source URLs without a client build", () => server.ssrLoadModule(assetModule) ); - expect(module).toHaveProperty("default.directory-effect-ui", { - entryScript: `/${directoryEntry}`, + expect(module).toHaveProperty("default.reader-effect-ui", { + entryScript: `/${readerEntry}`, modulePreloads: [], stylesheets: [], }); @@ -148,7 +154,7 @@ it.effect( } const names = client.output.map(({ fileName }) => fileName); - expect(names).toHaveLength(2); + expect(names).toHaveLength(3); expect(names).not.toContain(".vite/manifest.json"); const server = yield* buildEnvironment(builder, "ssr"); diff --git a/apps/web/test/reader-csp.test.ts b/apps/web/test/reader-csp.test.ts index 658be9da..271a2152 100644 --- a/apps/web/test/reader-csp.test.ts +++ b/apps/web/test/reader-csp.test.ts @@ -77,6 +77,8 @@ it("only Tube pages widen the reader policy, by YouTube's image host and the noc "/tubes", "/news", "/news/latest", + "/lore", + "/lore/durability-bibliography", "/search", ]) { expect(readerPagePolicy(path), path).toBe(readerContentSecurityPolicy); @@ -113,7 +115,13 @@ it.layer(NodeServices.layer)((test) => { )(files); expect(pages.map(({ route }) => route)).toEqual( - expect.arrayContaining([tubePagePath, "/news", "/news/latest"]) + expect.arrayContaining([ + tubePagePath, + "/news", + "/news/latest", + "/lore", + "/lore/durability-bibliography", + ]) ); const inlineStyles = pages.some( @@ -139,6 +147,15 @@ it.layer(NodeServices.layer)((test) => { } } + for (const link of document.querySelectorAll( + 'link[rel="modulepreload"]' + )) { + expect( + pageAllows("script-src", link.getAttribute("href") ?? ""), + route + ).toBe(true); + } + for (const link of document.querySelectorAll( 'link[rel="stylesheet"]' )) { diff --git a/apps/web/test/reader-effect-ui.test.ts b/apps/web/test/reader-effect-ui.test.ts new file mode 100644 index 00000000..728e4411 --- /dev/null +++ b/apps/web/test/reader-effect-ui.test.ts @@ -0,0 +1,264 @@ +import { NodeServices } from "@effect/platform-node"; +import { HtmlServer } from "@effect/ui/html"; +import { HtmlLocator, HtmlScene, ssr } from "@effect/ui/html/testing"; +import { Story, TestHost } from "@effect/ui/testing"; +import { expect, it } from "@effect/vitest"; +import { Effect, FileSystem, Path, Schema } from "effect"; +import { renderToString } from "foldkit/experimental/server"; + +import { compileLegacyReaderPage } from "../scripts/reader-effect-ui-legacy.js"; +import { + CopyReaderText, + DetectClipboard, + WaitBeforeCopyReset, +} from "../src/client/reader-effect-ui/command.js"; +import { ReaderPage } from "../src/client/reader-effect-ui/component.js"; +import { ReaderMessage } from "../src/client/reader-effect-ui/model.js"; +import { init } from "../src/client/reader/init.js"; +import { ReaderFlags } from "../src/client/reader/model.js"; +import { view } from "../src/features/reader.js"; +import { + renderDocument, + withReaderHead, +} from "../src/server/reader-document.js"; +import { + readerProps, + readerSupportsEffectUi, +} from "../src/server/reader-effect-ui-props.js"; +import { promptFixture, readerFlagsFixture } from "./reader-fixture.js"; + +const { id, label, text } = promptFixture; + +const detected = ReaderMessage.CompletedDetectClipboard({ available: true }); + +const reset = ReaderMessage.CompletedWaitBeforeCopyReset({ id }); + +const failed = ReaderMessage.FailedCopyReaderText({ id }); + +const copied = ReaderMessage.SucceededCopyReaderText({ id }); + +const clicked = ReaderMessage.ClickedCopy({ id }); + +it.effect( + "the copy story detects availability, ignores duplicates, retries a failure and resets a success", + () => + Effect.gen(function* clipboardStory() { + const props = readerProps(readerFlagsFixture); + const story = yield* Story.make(ReaderPage, props); + story.expectExact(DetectClipboard); + expect(story.model.clipboard).toBe("unknown"); + story.keepPending(DetectClipboard).send(clicked); + expect(story.model.copyStatuses[id]).toBeUndefined(); + story.resolve( + DetectClipboard, + ReaderMessage.CompletedDetectClipboard({ available: false }) + ); + expect(story.model.clipboard).toBe("unavailable"); + story.send(clicked); + expect(story.model.copyStatuses[id]).toBeUndefined(); + story.send(detected); + story.send(ReaderMessage.ClickedCopy({ id: "missing" })); + story.send(clicked).expectExact(CopyReaderText.make({ id, text })); + expect(story.model.copyStatuses[id]).toBe("copying"); + story.keepPending(CopyReaderText).send(clicked); + story.resolve(CopyReaderText, failed); + expect(story.model.copyStatuses[id]).toBe("failed"); + story.send(clicked).expectExact(CopyReaderText.make({ id, text })); + story + .resolve(CopyReaderText, copied) + .expectExact(WaitBeforeCopyReset.make({ id })); + expect(story.model.copyStatuses[id]).toBe("copied"); + story.keepPending(WaitBeforeCopyReset).send(clicked); + story.resolve(WaitBeforeCopyReset, reset); + expect(story.model.copyStatuses[id]).toBeUndefined(); + }) +); + +it.effect("the copy scene uses the button and announces both outcomes", () => + Effect.gen(function* clipboardScene() { + const compiled = yield* compileLegacyReaderPage(readerFlagsFixture); + const props = readerProps(compiled); + const scene = yield* HtmlScene.make(ReaderPage, props); + const button = HtmlLocator.role("button", { name: label }); + const status = HtmlLocator.role("status"); + + scene.expect(button).toBeAbsent(); + scene.expectExact(DetectClipboard).resolve(DetectClipboard, detected); + scene + .click(button) + .expectExact(CopyReaderText.make({ id, text })) + .resolve(CopyReaderText, failed); + scene + .expect(status) + .toHaveText("Copy failed. Select the text and copy it."); + scene + .click(button) + .expectExact(CopyReaderText.make({ id, text })) + .resolve(CopyReaderText, copied); + scene.expect(button).toHaveAttribute("data-copied", "true"); + scene.expect(status).toHaveText("Copied βœ“"); + scene.expectExact(WaitBeforeCopyReset).resolve(WaitBeforeCopyReset, reset); + scene.expect(button).toHaveAttribute("data-copied", "false"); + }) +); + +const parse = (html: string) => + new DOMParser().parseFromString(html, "text/html"); + +const contentHead = (page: Document) => + [ + ...page.head.querySelectorAll( + 'title, meta, link[rel="canonical"], script[type="application/ld+json"]' + ), + ].map((element) => element.outerHTML); + +const textOf = (root: ParentNode) => + [...root.querySelectorAll("header, main, footer")].map((node) => + (node.textContent ?? "").replaceAll(/\s+/gu, " ").trim() + ); + +const pageStructure = (root: ParentNode) => + [ + ...root.querySelectorAll( + "header, header *, main, main *, footer, footer *" + ), + ].map((node) => [ + node.localName, + ...[...node.attributes] + .map(({ name, value }) => [name, value]) + .toSorted(([left = ""], [right = ""]) => left.localeCompare(right)), + ]); + +const readerPages = Effect.gen(function* readerPages() { + const fs = yield* FileSystem.FileSystem; + const paths = yield* Path.Path; + + const json = yield* fs.readFileString( + paths.resolve(import.meta.dirname, "../dist/reader-pages.json") + ); + + return yield* Schema.decodeEffect( + Schema.fromJsonString(Schema.Array(ReaderFlags)) + )(json); +}); + +const flagsAt = (path: string) => + readerPages.pipe( + Effect.flatMap((pages) => + Effect.fromNullishOr(pages.find((page) => page.page.path === path)) + ) + ); + +const foldkit = (flags: typeof ReaderFlags.Type) => + renderToString( + { Flags: ReaderFlags, init, view }, + { flags, isHydratable: false } + ); + +it.live.prop( + "every committed lore page preserves Foldkit's text, metadata, elements, links and StyleX classes", + { start: Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 1000 })) }, + ({ start }) => + Effect.gen(function* loreParity() { + const fs = yield* FileSystem.FileSystem; + const paths = yield* Path.Path; + const client = paths.resolve(import.meta.dirname, "../dist/client"); + const pages = yield* readerPages; + + const lore = pages.filter( + ({ page }) => page.path === "/lore" || page.path.startsWith("/lore/") + ); + + expect(lore.length).toBeGreaterThan(1); + expect( + lore.flatMap((flags) => + readerSupportsEffectUi(flags) ? [] : [flags.page.path] + ) + ).toEqual([]); + + const offset = start % lore.length; + const visit = [...lore.slice(offset), ...lore.slice(0, offset)]; + yield* Effect.forEach( + visit, + (flags) => + Effect.gen(function* compareLorePage() { + const { path } = flags.page; + const legacy = yield* foldkit(flags); + + const expected = parse( + renderDocument(withReaderHead(legacy, flags), { + entryScript: "/assets/app.js", + modulePreloads: [], + stylesheets: [], + }) + ); + + const html = yield* fs.readFileString( + paths.join(client, path, "index.html") + ); + + const actual = parse(html); + expect( + actual.querySelector("#reader-effect-ui"), + path + ).not.toBeNull(); + expect(actual.querySelector("[data-foldkit-app]"), path).toBeNull(); + expect(actual.documentElement.lang, path).toBe( + expected.documentElement.lang + ); + expect(contentHead(actual), path).toEqual(contentHead(expected)); + expect(textOf(actual), path).toEqual(textOf(expected)); + expect(pageStructure(actual), flags.page.path).toEqual( + pageStructure(expected) + ); + }), + { discard: true } + ); + }).pipe(Effect.provide(NodeServices.layer)), + { arbitrary: { runs: 1, maxShrinks: 0 }, timeout: 30_000 } +); + +it.layer(TestHost.layer())((test) => { + test.effect( + "SSR adopts the real lore DOM with the same text, headings and links", + () => + Effect.gen(function* adoptLore() { + const page = yield* flagsAt("/lore/services-capture-dependencies"); + const props = readerProps(page); + const legacy = yield* foldkit(page); + const expected = parse(legacy.html); + const rendered = yield* ssr(ReaderPage, props); + expect(rendered.adopted).toEqual(["/ReaderPage"]); + expect(textOf(rendered.container)).toEqual(textOf(expected)); + expect(pageStructure(rendered.container)).toEqual( + pageStructure(expected) + ); + }).pipe(Effect.provide(NodeServices.layer)) + ); +}); + +it.effect( + "legacy block pages project their prompts, paragraphs and highlighted code into the same reader", + () => + Effect.gen(function* legacyDocument() { + const page = yield* flagsAt("/"); + const compiled = yield* compileLegacyReaderPage(page); + const props = readerProps(compiled); + const legacy = yield* foldkit(page); + const current = yield* HtmlServer.renderToHtml(ReaderPage, props); + const expected = parse(legacy.html); + const actual = parse(current.html); + expect(actual.querySelectorAll("pre code").length).toBeGreaterThan(0); + expect(actual.querySelectorAll("button.copy").length).toBeGreaterThan(0); + expect(textOf(actual)).toEqual(textOf(expected)); + expect( + [...actual.querySelectorAll("main a[href], main pre")].map( + (node) => node.textContent + ) + ).toEqual( + [...expected.querySelectorAll("main a[href], main pre")].map( + (node) => node.textContent + ) + ); + }).pipe(Effect.provide(NodeServices.layer)) +); diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index ce3c867c..daa967c9 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -47,6 +47,40 @@ ] } }, + { + "include": ["src/client/reader-effect-ui/command.ts"], + "options": { + "allowedExperimentalApis": ["@effect/ui/Command#make"] + } + }, + { + "include": ["src/client/reader-effect-ui/model.ts"], + "options": { + "allowedExperimentalApis": ["@effect/ui/UiSchema#TaggedEnum"] + } + }, + { + "include": ["src/features/reader-effect-ui/view.ts"], + "options": { + "allowedExperimentalApis": [ + "@effect/ui/View#Input", + "@effect/ui/html/Html#H" + ] + } + }, + { + "include": ["test/reader-effect-ui.test.ts"], + "options": { + "allowedExperimentalApis": [ + "@effect/ui/html/HtmlServer#renderToHtml", + "@effect/ui/html/testing#ssr", + "@effect/ui/html/testing/HtmlLocator#role", + "@effect/ui/html/testing/HtmlScene#make", + "@effect/ui/testing/Story#make", + "@effect/ui/testing/TestHost#layer" + ] + } + }, { "include": ["test/news-effect-ui.test.ts"], "options": { diff --git a/apps/web/vitest.config.ts b/apps/web/vitest.config.ts index aa4242ae..319f73da 100644 --- a/apps/web/vitest.config.ts +++ b/apps/web/vitest.config.ts @@ -16,6 +16,7 @@ export default defineConfig({ "test/news-effect-ui.test.ts", "test/overlay.test.ts", "test/reader-csp.test.ts", + "test/reader-effect-ui.test.ts", ], name: "browser", }, @@ -30,6 +31,7 @@ export default defineConfig({ "test/news-effect-ui.test.ts", "test/overlay.test.ts", "test/reader-csp.test.ts", + "test/reader-effect-ui.test.ts", ], include: ["test/**/*.test.ts"], name: "server", diff --git a/scripts/turbo-inputs-source.ts b/scripts/turbo-inputs-source.ts index 6603c4c6..b35d0c69 100644 --- a/scripts/turbo-inputs-source.ts +++ b/scripts/turbo-inputs-source.ts @@ -153,6 +153,9 @@ const parameterizedReadBoundaries = new Map( "apps/site/dist/content/**" ), "apps/web/test/reader-csp.test.ts": hashed("apps/web/dist/**"), + "apps/web/test/reader-effect-ui.test.ts": hashed( + "apps/web/dist/client/lore/**" + ), "apps/web/test/reader-systems-skills.test.ts": hashed( "apps/site/dist/content/**" ), diff --git a/tools/oxlint/landmines/baseline.json b/tools/oxlint/landmines/baseline.json index a5e544b0..7285ffad 100644 --- a/tools/oxlint/landmines/baseline.json +++ b/tools/oxlint/landmines/baseline.json @@ -443,6 +443,19 @@ "reason": "Waits for built reader pages and their assets to be loaded for CSP checks." } ], + "apps/web/test/reader-effect-ui.test.ts": [ + { + "budget": [ + "test", + [ + "every committed lore page preserves Foldkit's text, metadata, elements, links and StyleX classes" + ], + "timeout", + "30000" + ], + "reason": "Compares complete documents for all 138 lore routes; the default five seconds expired during the parallel gate." + } + ], "apps/web/test/reader-systems-skills.test.ts": [ { "budget": [