diff --git a/app/src/artifact-print/print.css b/app/src/artifact-print/print.css index d82054525a..ca9c8314ea 100644 --- a/app/src/artifact-print/print.css +++ b/app/src/artifact-print/print.css @@ -6,6 +6,9 @@ @import "shadcn/tailwind.css"; @import "@fontsource-variable/figtree"; @import "../theme.css"; +/* A document's words are set as on screen: typeset, tuned as the app tunes it. */ +@import "../typeset.css"; +@import "../bot-markdown.css"; /* Streamdown draws the Markdown; Tailwind only ships classes it can see used (see styles.css). */ @source "../../node_modules/streamdown/dist/*.js"; @@ -119,19 +122,7 @@ thead { display: none; } -/* A Markdown table reads like a component table (renderers/table.tsx), a row never split. */ -.print-markdown [data-streamdown="table-header"] { - @apply bg-muted/50; -} - -.print-markdown [data-streamdown="table-header-cell"] { - @apply px-3 py-2 text-xs font-medium text-muted-foreground; -} - -.print-markdown [data-streamdown="table-cell"] { - @apply px-3 py-2; -} - +/* A Markdown table on paper is drawn as on screen (lib/markdown-table.tsx), a row never split. */ .print-markdown [data-streamdown="table-row"] { break-inside: avoid; } diff --git a/app/src/artifact-print/renderers/registry.tsx b/app/src/artifact-print/renderers/registry.tsx index de6b738afb..5f4e7fa637 100644 --- a/app/src/artifact-print/renderers/registry.tsx +++ b/app/src/artifact-print/renderers/registry.tsx @@ -1,5 +1,4 @@ import type { DashboardFilter } from "@openbot/shared/artifacts/kinds"; -import { IconFilter } from "@/components/icons"; import type { ComponentType } from "react"; import { ArtifactThemeScope, @@ -11,6 +10,7 @@ import { SlideCanvas, } from "@/components/artifacts/kinds"; import { HEADING_FONT } from "@/components/artifacts/kinds/theme"; +import { IconFilter } from "@/components/icons"; import { DASHBOARD_WIDTH, type PrintableContentByKind, @@ -92,10 +92,7 @@ export function filterLine( function PrintDashboard({ title, content }: PrintRendererProps<"dashboard">) { const filters = filterLine(content.filters); return ( - +

:where( + [data-streamdown="code-block"], + [data-streamdown="table-wrapper"], + [data-streamdown="mermaid-block"], + .katex-display + ) { + margin-block-start: var(--typeset-flow); + } + + /* + * Streamdown's code block is a component with its own `pre`, and typeset's code rules (a muted + * ground, padding, a smaller size) would set what its utilities leave unset. Inside one, code is + * drawn as if typeset were not there. + */ + .typeset-reply + :is([data-streamdown="code-block"], [data-streamdown="mermaid-block"]) + :is(pre, code) { + all: revert-layer; + } +} + +/* + * A document artifact, set by the same rules as a reply (`.typeset-reply`), as a page rather than a + * message: headings on a page's scale. + */ +@layer components { + .typeset-document :where(h1) { + font-size: 1.75em; + line-height: 1.25; + letter-spacing: -0.01em; + } + + .typeset-document :where(h2) { + font-size: 1.3em; + margin-block-start: 2em; + } + + .typeset-document :where(h3) { + font-size: 1.125em; + margin-block-start: 1.75em; + } + + /* + * On paper a table may break between its rows (each row stays whole: print.css). Typeset keeps a + * table on one page, so a long one left the page before it all but empty. + */ + @media print { + .typeset-document :where(table) { + break-inside: auto; + } + } +} + +/* + * Streamdown spaces a reply's blocks with `space-y-4` and the like, utilities, which outrank typeset. + * The blocks' margins go back to what the layers below give them: typeset's, and the block rule just + * above. A first block still starts flush (Streamdown's `[&>*:first-child]:mt-0` is more specific). + */ +@layer utilities { + .typeset-reply > * { + margin-block: revert-layer; + } +} + +/* + * A code block in a Bot's words, wherever they are drawn (a reply, a document, a card): one surface, + * its body on the block's own ground and its buttons in the header, not a box in a box. Streamdown + * draws the block and its parts; these keep its look to ours. A table's look is its own component's + * (`lib/markdown-table.tsx`). + */ +[data-streamdown="code-block"] { + background: var(--card); + gap: 0; + padding: 0; +} + +[data-streamdown="code-block-header"], +[data-streamdown="code-block"] + > div:has(> [data-streamdown="code-block-actions"]) { + height: 2.5rem; + padding-inline: 0.75rem; +} + +/* Streamdown positions its sticky toolbar over a padded header. Match the header + * height here so the toolbar stays centered when the outer padding is removed. */ +[data-streamdown="code-block"] +> div:has(> [data-streamdown="code-block-actions"]) { + margin-block-start: -2.5rem; +} + +[data-streamdown="code-block-body"] { + background: transparent; + border: 0; +} + +[data-streamdown="code-block-actions"] { + background: var(--card); + border: 0; + gap: 0.25rem; + padding: 0; + backdrop-filter: none; +} + +[data-streamdown="code-block-actions"] button:has(> svg) { + display: inline-grid; + min-width: 1.75rem; + min-height: 1.75rem; + place-items: center; +} + +[data-streamdown="code-block-actions"] button { + border-radius: var(--radius-md); +} + +[data-streamdown="code-block-actions"] button:focus-visible { + outline: 2px solid var(--ring); +} + +/* + * A code block's Download and Copy show while the pointer is on the block or focus is in it, as a + * table's do (lib/markdown-table.tsx), and always where there is no hover (a touch screen). They fade + * rather than leave, so nothing moves, and they stay in the tab order. + */ +@media (hover: hover) { + [data-streamdown="code-block-actions"] { + opacity: 0; + transition: opacity 150ms; + } + + [data-streamdown="code-block"]:is(:hover, :focus-within) + [data-streamdown="code-block-actions"] { + opacity: 1; + } +} + +@media (prefers-reduced-motion: reduce) { + [data-streamdown="code-block-actions"] { + transition: none; + } +} diff --git a/app/src/components/artifacts/comments/comments-panel.tsx b/app/src/components/artifacts/comments/comments-panel.tsx index b0c40ba546..094ee31d8c 100644 --- a/app/src/components/artifacts/comments/comments-panel.tsx +++ b/app/src/components/artifacts/comments/comments-panel.tsx @@ -1,7 +1,5 @@ import { useMutation, useQuery } from "@tanstack/react-query"; import { useEffect, useState } from "react"; -import { IconMessageCircle } from "@/components/icons"; -import { PageEmpty } from "@/components/layout/page-shell"; import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { onArtifactActivity, onArtifactResync } from "@/lib/artifacts/activity"; import { createCommentThreadMutationOptions } from "@/lib/artifacts/comments/mutations"; @@ -161,16 +159,13 @@ export function CommentsPanel({ )}

) : threads.data.length === 0 ? ( - + // One quiet line, not the app's framed empty state: beside an artifact, a box with a pattern + // was one more surface competing with the artifact for the eye. +

{filter === "resolved" - ? "Threads show here once they're resolved." - : "Select something in the artifact to comment on it, or write about the whole thing above."} - + ? "Resolved threads show here." + : "No comments yet. Select something in the artifact to comment on it."} +

) : (
{threads.data.map((thread) => ( diff --git a/app/src/components/artifacts/kinds/dashboard.tsx b/app/src/components/artifacts/kinds/dashboard.tsx index 17aa3d3fa5..d32a89f4fc 100644 --- a/app/src/components/artifacts/kinds/dashboard.tsx +++ b/app/src/components/artifacts/kinds/dashboard.tsx @@ -13,9 +13,9 @@ import type { DashboardFilter, Widget, } from "@openbot/shared/artifacts/kinds"; -import { IconFilterOff, IconSearch } from "@/components/icons"; import { useState } from "react"; -import { GalleryFrame } from "@/components/gallery/frame"; +import { GalleryFrame, UnboxedFrames } from "@/components/gallery/frame"; +import { IconFilterOff, IconSearch } from "@/components/icons"; import { Button } from "@/components/ui/button"; import { InputGroup, @@ -160,7 +160,7 @@ function WidgetView({ (entry) => entry.key === widget.value, ); return ( - div]:py-4")}> + +
{widgets.map((widget) => { const span = widget.span ?? DEFAULT_SPAN[widget.type]; return ( @@ -287,66 +290,71 @@ export function DashboardView({ if (thumbnail) { return ( - - -
{grid}
-
-
+ + + +
{grid}
+
+
+
); } return ( - -
+ - {content.description || (filters.length > 0 && !onPaper) ? ( -
- {content.description ? ( -

- {content.description} -

- ) : ( - - )} - {filters.length > 0 && !onPaper ? ( -
- {filters.map((filter) => ( - - setState((current) => ({ - ...current, - [filter.id]: value, - })) - } - value={state[filter.id] ?? ALL} - /> - ))} - {filtered ? ( - - ) : null} -
- ) : null} -
- ) : null} - {grid} -
-
+
+ {content.description || (filters.length > 0 && !onPaper) ? ( +
+ {content.description ? ( +

+ {content.description} +

+ ) : ( + + )} + {filters.length > 0 && !onPaper ? ( +
+ {filters.map((filter) => ( + + setState((current) => ({ + ...current, + [filter.id]: value, + })) + } + value={state[filter.id] ?? ALL} + /> + ))} + {filtered ? ( + + ) : null} +
+ ) : null} +
+ ) : null} + {grid} +
+ + ); } diff --git a/app/src/components/artifacts/kinds/document.tsx b/app/src/components/artifacts/kinds/document.tsx index 8fd43c269f..f357d452c4 100644 --- a/app/src/components/artifacts/kinds/document.tsx +++ b/app/src/components/artifacts/kinds/document.tsx @@ -5,14 +5,16 @@ import { type DocumentDirective, splitDocument, } from "@openbot/shared/artifacts/kinds"; -import { IconAlertTriangle } from "@/components/icons"; import type { ReactNode } from "react"; import { MetricsCard, NoticeCard } from "@/components/gallery/cards"; +import { UnboxedFrames } from "@/components/gallery/frame"; import { QuoteCard } from "@/components/gallery/quote"; +import { IconAlertTriangle } from "@/components/icons"; import { cn } from "@/lib/utils"; import { ArtifactChart } from "./chart"; import { MermaidDiagram } from "./diagram"; import { ArtifactMarkdown } from "./markdown"; +import { useArtifactMedium } from "./medium"; import { changeTone, metricText } from "./metric"; import { ArtifactTable } from "./table"; import { ArtifactThemeScope, mergeThemes } from "./theme"; @@ -27,7 +29,7 @@ import type { KindViewProps } from "./types"; */ function Prose({ children }: { children: string }) { - return {children}; + return {children}; } function Unreadable({ name, line }: { name: string; line: number }) { @@ -157,12 +159,15 @@ export function DocumentView({ mode, }: KindViewProps) { const merged = mergeThemes(content.theme, theme); + const onPaper = useArtifactMedium() === "print"; if (mode === "thumbnail") { return (
- + + +
@@ -170,18 +175,27 @@ export function DocumentView({ } return (
- + + +
); diff --git a/app/src/components/artifacts/kinds/markdown.tsx b/app/src/components/artifacts/kinds/markdown.tsx index 69ebac56e2..a28c7702a2 100644 --- a/app/src/components/artifacts/kinds/markdown.tsx +++ b/app/src/components/artifacts/kinds/markdown.tsx @@ -9,6 +9,7 @@ import { BotMarkdown, markdownComponents, markdownPlugins, + replyMarkdownComponents, replyRemarkPlugins, } from "@/lib/markdown"; import { hasMaths, withMathDelimiters } from "@/lib/maths"; @@ -33,12 +34,22 @@ const STAND_IN = "https://artifact-image.openbot.invalid/"; const STORED_IMAGE = /asset:[0-9a-f]{64}|data:image\/(?:png|jpeg|gif|webp);base64,[A-Za-z0-9+/=]+/g; +/** + * A document's words, set as a page: the typeset rules a Bot's reply is set by (`typeset.css`, tuned + * for a document by `.typeset-document` in styles.css), with headings and lists drawn bare so those + * rules reach them, and tables and code as a reply draws them. + */ +export const DOCUMENT_TYPESET_CLASS = "typeset typeset-reply typeset-document"; + export function ArtifactMarkdown({ children, className, + page = false, }: { children: string | undefined; className?: string; + /** Set as a document's page (typeset), rather than as a card's or a slide's words. */ + page?: boolean; }) { const medium = useArtifactMedium(); const onPaper = medium === "print"; @@ -53,7 +64,7 @@ export function ArtifactMarkdown({ }, [text]); const components = useMemo( () => ({ - ...markdownComponents, + ...(page ? replyMarkdownComponents : markdownComponents), img: ({ src, alt }: ComponentProps<"img">) => ( ), }), - [sources, onPaper], + [sources, onPaper, page], ); useMathsOnPaper(onPaper ? text : ""); if (!children) return null; return ( Row @@ -173,7 +173,7 @@ function SheetGrid({ sheet }: { sheet: SheetTab }) { : undefined } className={cn( - "sticky top-0 border-r border-b border-border bg-muted p-0 text-xs font-medium text-muted-foreground", + "sticky top-0 border-r border-b border-border bg-background p-0 text-xs font-medium text-muted-foreground", index < frozen ? "z-30" : "z-20", )} key={column.key} @@ -182,7 +182,7 @@ function SheetGrid({ sheet }: { sheet: SheetTab }) { > {open ? ( -
+
{open ? ( -
+