Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: draw chat markdown tables inline with hover controls and a centered expand dialog (#13973)
Michael Hance83deea9ccd
diff --git a/studio/frontend/src/components/assistant-ui/markdown-table.tsx b/studio/frontend/src/components/assistant-ui/markdown-table.tsxnew file mode 100644index 00000000000..7c48ca6fbfc--- /dev/null+++ b/studio/frontend/src/components/assistant-ui/markdown-table.tsx@@ -0,0 +1,144 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import {+ Dialog,+ DialogClose,+ DialogContent,+ DialogTitle,+} from "@/components/ui/dialog";+import { useT } from "@/i18n";+import { Cancel01Icon, ExpandIcon } from "@hugeicons/core-free-icons";+import { HugeiconsIcon } from "@hugeicons/react";+import {+ type ComponentProps,+ type ReactNode,+ useContext,+ useLayoutEffect,+ useRef,+ useState,+} from "react";+import {+ type ExtraProps,+ StreamdownContext,+ TableCopyDropdown,+ TableDownloadDropdown,+ defaultTranslations,+} from "streamdown";++// Streamdown's copy and download find the table through this attribute, so the wrapper keeps it.+const TABLE_WRAPPER = "table-wrapper";++// Flags the edges hiding columns (CSS fades them) and the scrollbar height the fade stops above.+function TableScroll({+ children,+ className,+ props,+}: {+ children: ReactNode;+ className?: string;+ props: ComponentProps<"table">;+}) {+ const scroller = useRef<HTMLDivElement>(null);+ useLayoutEffect(() => {+ const el = scroller.current;+ if (!el) {+ return;+ }+ const update = () => {+ const max = el.scrollWidth - el.clientWidth;+ el.toggleAttribute("data-fade-start", el.scrollLeft > 1);+ el.toggleAttribute("data-fade-end", el.scrollLeft < max - 1);+ el.style.setProperty(+ "--md-table-scrollbar",+ `${el.offsetHeight - el.clientHeight}px`,+ );+ };+ update();+ const observer = new ResizeObserver(update);+ observer.observe(el);+ // Streaming rows widen the table without resizing the scroller.+ if (el.firstElementChild) {+ observer.observe(el.firstElementChild);+ }+ el.addEventListener("scroll", update, { passive: true });+ return () => {+ observer.disconnect();+ el.removeEventListener("scroll", update);+ };+ }, []);+ return (+ <div ref={scroller} className="aui-md-table-scroll">+ <table className={className} data-streamdown="table" {...props}>+ {children}+ </table>+ </div>+ );+}++export function MarkdownTable({+ children,+ className,+ node: _node,+ ...props+}: ComponentProps<"table"> & ExtraProps) {+ const t = useT();+ const { isAnimating } = useContext(StreamdownContext);+ const [expanded, setExpanded] = useState(false);+ const label = defaultTranslations.viewFullscreen;+ return (+ <div className="aui-md-table" data-streamdown={TABLE_WRAPPER}>+ <TableScroll className={className} props={props}>+ {children}+ </TableScroll>+ <div className="aui-md-table-actions">+ <TableCopyDropdown />+ <TableDownloadDropdown />+ <button+ type="button"+ title={label}+ aria-label={label}+ disabled={isAnimating}+ onClick={() => setExpanded(true)}+ >+ <HugeiconsIcon icon={ExpandIcon} size={14} />+ </button>+ </div>+ <Dialog open={expanded} onOpenChange={setExpanded}>+ <DialogContent+ showCloseButton={false}+ aria-describedby={undefined}+ overlayClassName="bg-black/70"+ overlayTone="dense"+ // The whole window below the desktop titlebar, so a click beside the panel closes it.+ className="top-[var(--studio-window-chrome-top,0px)] right-0 bottom-0 left-0 flex h-auto max-h-none w-auto max-w-none translate-none items-center justify-center gap-0 overflow-hidden rounded-none bg-transparent p-4 ring-0 sm:max-w-none sm:p-16 max-sm:h-auto"+ onClick={(event) => {+ if (event.target === event.currentTarget) {+ setExpanded(false);+ }+ }}+ >+ <DialogTitle className="sr-only">{label}</DialogTitle>+ <div className="aui-md-table aui-md-table-dialog max-h-full max-w-[min(72rem,100%)] overflow-y-auto rounded-3xl bg-popover px-6 py-8 ring-1 ring-border/60 sm:px-14 sm:py-12">+ <TableScroll className={className} props={props}>+ {children}+ </TableScroll>+ </div>+ <DialogClose asChild={true}>+ <button+ type="button"+ aria-label={t("common.close")}+ className="absolute top-4 right-4 flex size-10 cursor-pointer items-center justify-center rounded-full bg-popover text-foreground shadow-lg ring-1 ring-border/60 transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"+ >+ <HugeiconsIcon+ icon={Cancel01Icon}+ strokeWidth={1.75}+ className="size-5"+ />+ </button>+ </DialogClose>+ </DialogContent>+ </Dialog>+ </div>+ );+}diff --git a/studio/frontend/src/components/assistant-ui/markdown-text.tsx b/studio/frontend/src/components/assistant-ui/markdown-text.tsxindex ca9c312f9b3..16795979e0e 100644--- a/studio/frontend/src/components/assistant-ui/markdown-text.tsx+++ b/studio/frontend/src/components/assistant-ui/markdown-text.tsx@@ -119,6 +119,7 @@ import {sandboxSessionIdFor,sandboxSessionInSrc,} from "./sandbox-files";+import { MarkdownTable } from "./markdown-table";import { SearchImageElement, SearchImagesContext } from "./search-image";import { useSandboxImage } from "./use-sandbox-image";import { rehypeSandboxImages } from "./rehype-sandbox-images";@@ -346,7 +347,7 @@ const MarkdownImage = memo(function MarkdownImage(props: ComponentProps<"img">)<buttontype="button"title="Download image"- className="absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 opacity-0 backdrop-blur-sm transition-all duration-200 group-hover:opacity-100"+ className="aui-chat-icon-btn absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-full border border-border bg-background/90 opacity-0 backdrop-blur-sm transition-all duration-200 group-hover:opacity-100"onClick={async () => {// Reuse fetched bytes under the desktop CSP.try {@@ -481,6 +482,7 @@ const STREAMDOWN_COMPONENTS = {// Module-scoped: Streamdown's memo comparator ignores `components`.[SEARCH_IMAGE_TAG]: SearchImageElement,img: MarkdownImage,+ table: MarkdownTable,};// Through the sanitizer; the component drops tokens it cannot resolve.const STREAMDOWN_ALLOWED_TAGS = {@@ -491,7 +493,7 @@ const COPY_RESET_MS = 2000;const ACTION_PANEL_CLASS ="pointer-events-auto flex shrink-0 items-center gap-1";const ACTION_BUTTON_CLASS =- "flex size-8 cursor-pointer items-center justify-center rounded-[10px] text-chat-icon-fg transition-all hover:bg-chat-icon-bg-hover hover:text-chat-icon-fg-hover disabled:cursor-not-allowed disabled:opacity-50";+ "aui-chat-icon-btn flex size-8 cursor-pointer items-center justify-center rounded-full text-chat-icon-fg transition-all hover:bg-chat-icon-bg-hover hover:text-chat-icon-fg-hover disabled:cursor-not-allowed disabled:opacity-50";/*** THE MERMAID FENCE IN THIS BLOCK, found with fence context.diff --git a/studio/frontend/src/components/ui/dialog.tsx b/studio/frontend/src/components/ui/dialog.tsxindex a6121b6d68a..9dee4f311cc 100644--- a/studio/frontend/src/components/ui/dialog.tsx+++ b/studio/frontend/src/components/ui/dialog.tsx@@ -91,7 +91,7 @@ function DialogContent({overlayClassName?: string;overlayPosition?: "fixed" | "absolute";/** A darker overlay names it, so the custom titlebar dims to match. */- overlayTone?: "strong";+ overlayTone?: "strong" | "dense";}) {const resolvedContainer = container ?? null;const inheritedGlow = useContext(DropdownGlowContext);diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.cssindex 71bc9e44c2a..99ded9c4446 100644--- a/studio/frontend/src/index.css+++ b/studio/frontend/src/index.css@@ -39,6 +39,9 @@[data-slot="window-titlebar"][data-viewport-backdrop-tone="strong"]::after {background: rgb(0 0 0 / 40%);}+ [data-slot="window-titlebar"][data-viewport-backdrop-tone="dense"]::after {+ background: rgb(0 0 0 / 70%);+ }/* The surface the sidebar panel actually paints. The collapsed icon railrepaints it, so gradients fading into the panel must read this rather@@ -4419,34 +4422,150 @@ html[data-chat-font] .aui-root {}}- /* Streamdown's table controls, drawn like the code block's (ACTION_BUTTON_CLASS in- markdown-text.tsx). Without controls the table box is the only child. */- .aui-thread-root [data-streamdown="table-wrapper"] > div:first-child:not(:last-child) {- margin-right: calc(var(--spacing) * 1);+ /* Chat tables (markdown-table.tsx); these outrank Streamdown's hard-coded cell classes. */+ .aui-md-table {+ position: relative;+ margin-block: calc(1rem * var(--ui-space-scale, 1));+ }++ /* The second mask layer keeps the scrollbar opaque under the fade. */+ .aui-md-table-scroll {+ --md-table-fade-start: 0px;+ --md-table-fade-end: 0px;+ max-width: 100%;+ overflow-x: auto;+ }++ .aui-md-table-scroll[data-fade-start] {+ --md-table-fade-start: 4rem;+ }++ .aui-md-table-scroll[data-fade-end] {+ --md-table-fade-end: 4rem;+ }++ .aui-md-table-scroll:is([data-fade-start], [data-fade-end]) {+ mask-image:+ linear-gradient(+ to right,+ transparent,+ #000 var(--md-table-fade-start),+ #000 calc(100% - var(--md-table-fade-end)),+ transparent+ ),+ linear-gradient(#000, #000);+ mask-size:+ 100% calc(100% - var(--md-table-scrollbar, 0px)),+ 100% var(--md-table-scrollbar, 0px);+ mask-position: top, bottom;+ mask-repeat: no-repeat;+ }++ .aui-md-table table {+ width: 100%;+ border-collapse: collapse;+ }++ .aui-md-table thead {+ background: transparent;+ }++ .aui-md-table thead > tr {+ border-bottom: 1px solid var(--color-border);+ }++ .aui-md-table tbody > tr {+ border-color: color-mix(in oklab, var(--color-border) 60%, transparent);+ }++ .aui-md-table :is(th, td) {+ padding: calc(0.625rem * var(--ui-space-scale, 1)) calc(1rem * var(--ui-space-scale, 1));+ font-size: inherit;+ line-height: 1.5;+ vertical-align: top;+ white-space: normal;+ /* A floor, so many columns scroll instead of breaking every word. */+ min-width: 8rem;+ }++ .aui-md-table :is(th, td):first-child {+ padding-inline-start: 0;}- .aui-thread-root [data-streamdown="table-wrapper"] > div > .relative {+ .aui-md-table :is(th, td):last-child {+ padding-inline-end: 0;+ }++ .aui-md-table th {+ font-weight: 600;+ }++ .aui-md-table-actions {+ position: absolute;+ top: calc(0.25rem * var(--ui-space-scale, 1));+ right: 0;display: flex;+ align-items: center;+ gap: 0.125rem;+ padding-left: 1rem;+ background: linear-gradient(to right, transparent, var(--background) 1rem);+ opacity: 0;+ pointer-events: none;+ transition: opacity 120ms ease;}- .aui-thread-root [data-streamdown="table-wrapper"] > div > button,- .aui-thread-root [data-streamdown="table-wrapper"] > div > .relative > button {+ .aui-md-table:hover > .aui-md-table-actions,+ .aui-md-table-actions:focus-within,+ .aui-md-table-actions:has(> .relative > div) {+ opacity: 1;+ pointer-events: auto;+ }++ @media (hover: none) {+ .aui-md-table-actions {+ opacity: 1;+ pointer-events: auto;+ }+ }++ .aui-md-table-actions > .relative {+ display: flex;+ }++ .aui-md-table-actions > button,+ .aui-md-table-actions > .relative > button {display: flex;align-items: center;justify-content: center;width: calc(var(--spacing) * 8);height: calc(var(--spacing) * 8);padding: 0;- border-radius: 10px;+ border-radius: 9999px;color: var(--color-chat-icon-fg);+ cursor: pointer;}- .aui-thread-root [data-streamdown="table-wrapper"] > div > button:hover:not(:disabled),- .aui-thread-root [data-streamdown="table-wrapper"] > div > .relative > button:hover:not(:disabled) {+ .aui-md-table-actions > button:hover:not(:disabled),+ .aui-md-table-actions > .relative > button:hover:not(:disabled) {background-color: var(--color-chat-icon-bg-hover);color: var(--color-chat-icon-fg-hover);}+ /* Streamdown's diagram controls; its menu rows are w-full and stay square. */+ .aui-thread-root [data-streamdown="mermaid-block"] button:not(.w-full) {+ border-radius: 9999px;+ }++ .aui-md-table-actions > button:disabled {+ cursor: not-allowed;+ opacity: 0.5;+ }++ .aui-md-table-dialog {+ margin-block: 0;+ font-size: 1rem;+ }+/* Chat: use the app sans stack for UI + prose. */.aui-thread-root {--font-heading: var(--font-sans);@@ -5093,6 +5212,24 @@ html.force-reduced-motion .sidebar-section-drop-line {background: oklch(0.67 0 0 / 0.5);}+/* Classic, not overlay: a wide chat table shows it scrolls before it is touched. */+@supports selector(::-webkit-scrollbar) {+ .aui-md-table-scroll,+ .dark .aui-md-table-scroll {+ scrollbar-width: auto;+ scrollbar-color: auto;+ }+}++.aui-md-table-scroll::-webkit-scrollbar {+ height: 12px;+}++.aui-md-table-scroll::-webkit-scrollbar-thumb {+ border: 3px solid transparent;+ background-clip: padding-box;+}+/* Unlayered like the rules above, which a utility class could not outrank. */.aui-composer-attachment-cards[data-layout="strip"] {scrollbar-width: none;@@ -5809,6 +5946,13 @@ html.force-reduced-motion .sidebar-section-drop-line {}}+/* An odd-sized glyph in these 32px buttons sits on a half pixel, which paints it 0.5px right of+ its circle; an even size centers it. After the block above, which it must outrank. */+.aui-root.aui-thread-root :is(.aui-chat-icon-btn, .aui-md-table-actions button) svg {+ width: round(var(--icon-size), 2px);+ height: round(var(--icon-size), 2px);+}+/* Sonner injects fixed 13px toast text and 12px action labels at runtime;text follows the preference at full rate. Line heights are unitless sothey track automatically. */diff --git a/studio/frontend/tests/code-fence-body.test.ts b/studio/frontend/tests/code-fence-body.test.tsindex ef55e96b6a3..822e21f0d98 100644--- a/studio/frontend/tests/code-fence-body.test.ts+++ b/studio/frontend/tests/code-fence-body.test.ts@@ -312,11 +312,11 @@ test("a fence source is highlighted once per revision, not twice", () => {);});-const TABLE_CONTROLS = '[data-streamdown="table-wrapper"] > div';+const TABLE_CONTROLS = ".aui-md-table-actions";const POSITIONAL_ANCESTOR =/:(?:first|last|only)-child[^{,]*?>\s*(?:\.relative|button)\b/;const TABLE_BUTTON =- /height: calc\(var\(--spacing\) \* 8\);[\s\S]*border-radius: 10px;\s*color: var\(--color-chat-icon-fg\);/;+ /height: calc\(var\(--spacing\) \* 8\);[\s\S]*border-radius: 9999px;\s*color: var\(--color-chat-icon-fg\);/;// Streamdown draws the table's buttons itself, 23px with no hover fill, beside these 32px ones.test("a table's toolbar buttons are drawn like the code block's", () => {@@ -337,9 +337,5 @@ test("no positional pseudo-class sits above .relative or button in a selector",[],"a :first-child or :last-child above a subject keys the invalidation set on that subject, so inserting before #root (every modal's focus guard) restyled every .relative and button in the app",);- assert.ok(- css.includes('[data-streamdown="table-wrapper"] > div:first-child:not(:last-child) {\n\t\tmargin-right:'),- "on the subject itself the same test only invalidates the controls",- );});