Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-7733: more room around dynamic blocks, actions on hover (#8867)

Jiayuan Zhang4f2fdc0b152f
diff --git a/packages/views/editor/dynamic-block.test.tsx b/packages/views/editor/dynamic-block.test.tsx
index 38ca8f9b6c..4753bf764b 100644
--- a/packages/views/editor/dynamic-block.test.tsx
+++ b/packages/views/editor/dynamic-block.test.tsx
@@ -58,6 +58,29 @@ describe("DynamicBlock", () => {
await waitFor(() => expect(copyTextMock).toHaveBeenCalledWith("<p>chart</p>"));
});
+ it("reveals the actions on hover, but keeps them up in the source view and after a copy", async () => {
+ copyTextMock.mockResolvedValue(true);
+ const { container } = renderBlock();
+ const actions = container.querySelector<HTMLElement>("[data-dynamic-block-actions]")!;
+ const hiddenUntilHover = "[@media(hover:hover)]:opacity-0";
+
+ // The title always shows; only the actions wait for hover or focus.
+ expect(actions.textContent).not.toContain("Latency");
+ expect(actions.className).toContain(hiddenUntilHover);
+ expect(actions.className).toContain("group-hover/dynamic-block:opacity-100");
+ expect(actions.className).toContain("group-focus-within/dynamic-block:opacity-100");
+
+ // Preview is the way back from the source view, so it cannot hide.
+ fireEvent.click(screen.getByRole("tab", { name: "Source" }));
+ await waitFor(() => expect(actions.className).not.toContain(hiddenUntilHover));
+ fireEvent.click(screen.getByRole("tab", { name: "Preview" }));
+ await waitFor(() => expect(actions.className).toContain(hiddenUntilHover));
+
+ // The copy confirmation stays readable after the pointer leaves.
+ fireEvent.click(screen.getByRole("button", { name: "Copy source" }));
+ await waitFor(() => expect(actions.className).not.toContain(hiddenUntilHover));
+ });
+
it("has no fullscreen button unless the kind offers one", () => {
renderBlock();
expect(screen.queryByRole("button", { name: "Fullscreen" })).toBeNull();
diff --git a/packages/views/editor/dynamic-block.tsx b/packages/views/editor/dynamic-block.tsx
index 00df818214..cd983ee0f7 100644
--- a/packages/views/editor/dynamic-block.tsx
+++ b/packages/views/editor/dynamic-block.tsx
@@ -7,10 +7,11 @@
* A dynamic block is part of the message body. That is what separates it from
* an attachment, which is a file and shows as a card that opens the viewer. So
* the frame reads as content, not as a file: an always-visible title bar (kind
- * icon, title, kind chip, Preview | Source, fullscreen, copy) over a body that
- * takes its content's height, collapsed past DYNAMIC_BLOCK_COLLAPSE_AT_PX
- * behind a fade and "Show all". Loading and error states live inside the same
- * frame, so a block that fails never breaks the comment around it.
+ * icon, title, kind chip; the Preview | Source, fullscreen and copy actions
+ * fade in on hover or focus, MUL-7733) over a body that takes its content's
+ * height, collapsed past DYNAMIC_BLOCK_COLLAPSE_AT_PX behind a fade and
+ * "Show all". Loading and error states live inside the same frame, so a block
+ * that fails never breaks the comment around it.
*
* The kinds supply only the preview; the frame owns the chrome, the source
* view and the error panel.
@@ -111,6 +112,9 @@ export function DynamicBlock({
const Icon = KIND_ICON[kind];
const kindLabel = KIND_LABEL[kind];
const trimmedTitle = title?.trim();
+ // The actions stay up while they carry state the reader has to see: the
+ // source view (Preview is how to get back) and the copy confirmation.
+ const actionsPinned = view === "source" || copied;
const handleCopy = async () => {
if (await copyText(source)) {
@@ -124,8 +128,9 @@ export function DynamicBlock({
value={view}
onValueChange={(value) => setView(value as DynamicBlockView)}
data-dynamic-block={kind}
+ // No outer margin: the lazy shell around the block owns that spacing.
className={cn(
- "my-3 gap-0 overflow-hidden rounded-lg border bg-surface shadow-[var(--surface-shadow)]",
+ "group/dynamic-block gap-0 overflow-hidden rounded-lg border bg-surface shadow-[var(--surface-shadow)]",
error && view === "preview" && "border-destructive/35",
className,
)}
@@ -147,42 +152,56 @@ export function DynamicBlock({
</span>
)}
<span className="flex-1" />
- <TabsList
- aria-label={t(($) => $.dynamic_block.view)}
- className="mr-1 shrink-0 gap-0.5 rounded-md p-0.5 group-data-horizontal/tabs:h-[26px]"
+ {/* The title identifies the block and always shows; the actions fade
+ in while the block is hovered or holds focus (MUL-7733). Opacity,
+ not display, so they keep their place in the bar and in the tab
+ order. Touch has no hover to reveal them, so there they always
+ show. */}
+ <div
+ data-dynamic-block-actions=""
+ className={cn(
+ "flex shrink-0 items-center gap-2 transition-opacity duration-150 ease-out",
+ !actionsPinned &&
+ "group-focus-within/dynamic-block:opacity-100 group-hover/dynamic-block:opacity-100 [@media(hover:hover)]:opacity-0",
+ )}
>
- <TabsTrigger value="preview" className="rounded-sm px-2 text-caption">
- {t(($) => $.dynamic_block.preview)}
- </TabsTrigger>
- <TabsTrigger value="source" className="rounded-sm px-2 text-caption">
- {t(($) => $.dynamic_block.source)}
- </TabsTrigger>
- </TabsList>
- {onFullscreen && (
+ <TabsList
+ aria-label={t(($) => $.dynamic_block.view)}
+ className="mr-1 shrink-0 gap-0.5 rounded-md p-0.5 group-data-horizontal/tabs:h-[26px]"
+ >
+ <TabsTrigger value="preview" className="rounded-sm px-2 text-caption">
+ {t(($) => $.dynamic_block.preview)}
+ </TabsTrigger>
+ <TabsTrigger value="source" className="rounded-sm px-2 text-caption">
+ {t(($) => $.dynamic_block.source)}
+ </TabsTrigger>
+ </TabsList>
+ {onFullscreen && (
+ <Button
+ ref={fullscreenButtonRef}
+ type="button"
+ variant="ghost"
+ size="icon-xs"
+ className="text-muted-foreground"
+ onClick={onFullscreen}
+ title={t(($) => $.code_block.fullscreen)}
+ aria-label={t(($) => $.code_block.fullscreen)}
+ >
+ <Maximize2 />
+ </Button>
+ )}
<Button
- ref={fullscreenButtonRef}
type="button"
variant="ghost"
size="icon-xs"
className="text-muted-foreground"
- onClick={onFullscreen}
- title={t(($) => $.code_block.fullscreen)}
- aria-label={t(($) => $.code_block.fullscreen)}
+ onClick={handleCopy}
+ title={t(($) => $.dynamic_block.copy_source)}
+ aria-label={t(($) => $.dynamic_block.copy_source)}
>
- <Maximize2 />
+ {copied ? <Check /> : <Copy />}
</Button>
- )}
- <Button
- type="button"
- variant="ghost"
- size="icon-xs"
- className="text-muted-foreground"
- onClick={handleCopy}
- title={t(($) => $.dynamic_block.copy_source)}
- aria-label={t(($) => $.dynamic_block.copy_source)}
- >
- {copied ? <Check /> : <Copy />}
- </Button>
+ </div>
</div>
<TabsContent value="preview" keepMounted>
{error && (
diff --git a/packages/views/editor/styles/mermaid.css b/packages/views/editor/styles/mermaid.css
index 65a824657d..1b9d2f3855 100644
--- a/packages/views/editor/styles/mermaid.css
+++ b/packages/views/editor/styles/mermaid.css
@@ -16,9 +16,6 @@
.rich-text-editor .mermaid-diagram-scroll {
display: flex;
- /* Small diagrams sit centered at natural size; only oversized ones scroll.
- Upscaling a small diagram to fill the column would just coarsen it. */
- justify-content: center;
overflow-x: auto;
overflow-y: hidden;
cursor: zoom-in;
@@ -38,6 +35,13 @@
labels are unreadable. `flex: none` stops the flex parent from shrinking
it; a `max-width` here would defeat the scroll entirely. */
flex: none;
+ /* Small diagrams sit centered at natural size; only oversized ones scroll.
+ Upscaling a small diagram to fill the column would just coarsen it.
+ Centered with auto margins, not `justify-content: center` on the
+ scroller: that pushes an oversized diagram's left part past the scroll
+ origin, where it is cut off and cannot be scrolled to (MUL-7733). Auto
+ margins never go negative, so a wide diagram starts at its left edge. */
+ margin-inline: auto;
/* The iframe cannot forward clicks to this document, so it would swallow
the click-to-open gesture. Disabling pointer events hands wheel, click,
and drag to the scroll container instead. */
diff --git a/packages/views/rich-content/lazy-rich-block.tsx b/packages/views/rich-content/lazy-rich-block.tsx
index 605aa28c85..d56a6deeb6 100644
--- a/packages/views/rich-content/lazy-rich-block.tsx
+++ b/packages/views/rich-content/lazy-rich-block.tsx
@@ -147,6 +147,13 @@ export function LazyRichBlock({
ref={ref}
data-rich-block-shell=""
data-mounted={mounted ? "" : undefined}
+ // The shell, not the block inside it, owns the space around the block
+ // (MUL-7733). A child's bottom margin cannot collapse through a box with
+ // a min-height, so on the block it sat inside the reservation: the gap
+ // below grew by a paragraph margin and the page shifted on mount. Here
+ // it collapses with the paragraphs on both sides, and the prose
+ // first/last-child reset still applies.
+ className="my-5"
// The reservation persists after mount so the shell never shrinks back
// and re-triggers a measurement pass. Real diagrams and the fixed-height
// HTML preview normally exceed it, so it rarely adds visible space.
@@ -165,7 +172,7 @@ export function LazyRichBlock({
function RichBlockPlaceholder() {
return (
<div
- className="my-3 h-full w-full rounded-md border border-border/50 bg-muted/20"
+ className="h-full w-full rounded-md border border-border/50 bg-muted/20"
aria-hidden="true"
/>
);