Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/framed-diagram-blocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-ui-kit": minor
"@schlessera/brain-module-diagrams": patch
---
Rendered diagrams in chat and file views now sit in one frame like other content blocks: the title and compact Open diagram and Share diagram icon buttons share a header row, replacing the separate row with a large Open diagram button. The authored 320px layout still fits a 320px column, print shows the same paper drawing without the frame or actions, and shared output is unchanged. The kit's `IconName` gains `enlarge`.
1 change: 1 addition & 0 deletions api-report/ui-kit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,7 @@ signatures (every public export and the types it is made of)
readonly dismiss: import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
readonly down: import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
readonly edit: import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
readonly enlarge: import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
readonly expand: import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
readonly failed: import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
readonly file: import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
Expand Down
7 changes: 7 additions & 0 deletions docs/integration-contract/package-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ omitted prop or state keeps every existing file default, meaning, state
machine, focus and announcement. The kit has no finding-kind prop: callers
choose the copy from the action and outcome they hold.

## UI-kit enlarge icon (additive #3397)

The semantic `IconName` gains `enlarge`: open content in its dedicated
full-size viewer. It draws lucide's `Expand`, the glyph the chat Mermaid block
already uses for Open diagram. The framed diagram renderer's header uses it.
No existing key, glyph or component changes.

## UI-kit Button reach (additive #3252)

`ButtonProps.reach?: boolean`, when the Button has `onClick`, adds the kit's
Expand Down
10 changes: 8 additions & 2 deletions packages/module-diagrams/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ SVG, PNG or PDF through the existing share path, always using the print palette.

Inline figures retain native coordinates so displayed text never shrinks below
9px. A constrained container uses the authored 320px layout when it fits;
otherwise it shows the caption, semantic summary and a 44px Open diagram button.
otherwise it shows the caption and semantic summary.
In chat and file views the figure is one framed content block: the title and
compact Open diagram and Share diagram icon buttons share its header row (44px
targets under a touch pointer). The frame's edge is an inset outline, so a
320px column still fits the authored 320px layout, and the frame replaces the
drawing's own screen edge. Share output embeds the unframed figure.
The dedicated viewer starts at readable 100% with explicit pan/zoom controls.
Browser print uses a white, non-interactive drawing without the screen frame.
Browser print uses a white, non-interactive drawing without the screen frame,
the frame or the header actions.

## Ordered axis diagrams

Expand Down
34 changes: 25 additions & 9 deletions packages/module-diagrams/src/ui.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { groupCallouts, undrawnCalloutExplanation } from "./callouts.js";
import { AXIS_TYPES } from "./spec.js";
import { createElement, useEffect, useId, useMemo, useRef, useState } from "react";
import { Button } from "@schlessera/brain-ui-kit";
import { Button, IconButton, color } from "@schlessera/brain-ui-kit";
import type { ContentRendererPack, ContentRendererProps } from "@schlessera/brain-ui-sdk/client";
import { StaticDiagramShareMenu, ZoomViewer, useWikiLinkNavigation } from "@schlessera/brain-ui-react/content-figures";
import { diagramSvgModel, parseDiagram, type DiagramSvgModel, type SvgPrimitive } from "./svg-model.js";
Expand All @@ -28,30 +28,46 @@ function Drawing({model,theme,id,interactive=true}: {model:DiagramSvgModel;theme
{model.elements.map(render)}
</svg>;
}
/** Render at native units; never shrink text below the approved 9px floor. */
/** Frame chrome that only CSS can express: print strips the frame back to the
* unframed paper figure, and the frame replaces the drawing's own screen edge.
* The drawing stays a direct child, at native width, so a 320px column still
* fits the authored 320px layout: the edge is an inset outline, not a border. */
const FRAME_CSS=`[data-diagram-framed]>svg.bk-diagram{margin:0 auto;border-radius:0 0 11px 11px}[data-diagram-framed]>svg.bk-diagram .bk-diagram-screen-frame{display:none}@media print{[data-diagram-framed]{outline:none!important;border-radius:0!important}[data-diagram-framed]>.bk-diagram-head{padding:0!important;border-bottom:none!important}[data-diagram-framed]>[data-diagram-summary],[data-diagram-framed]>[data-diagram-notes]{padding:0!important}}`;
/** Render at native units; never shrink text below the approved 9px floor.
* Chat and file views frame the figure like other content blocks, with the
* title and the open/share actions in one header. Share output keeps the
* unframed figure it has always embedded. */
export function DiagramContent({source,theme,mode}:ContentRendererProps) {
const spec=useMemo(()=>parseDiagram(source),[source]), desktop=useMemo(()=>diagramSvgModel(spec),[spec]);
const narrow=useMemo(()=>{try{return spec.layouts?.narrow || (AXIS_TYPES as readonly string[]).includes(spec.type)?diagramSvgModel(spec,"narrow"):null;}catch{return null;}},[spec]);
const host=useRef<HTMLElement>(null), [width,setWidth]=useState(0),[viewer,setViewer]=useState(false),id=useId().replace(/[^a-z0-9-]/gi,"");
useEffect(()=>{const element=host.current;if(!element)return;const observer=new ResizeObserver(entries=>setWidth(entries[0]!.contentRect.width));observer.observe(element);setWidth(element.getBoundingClientRect().width);return()=>observer.disconnect();},[]);
const model=width>=desktop.tree.viewBox.width ? desktop : narrow&&width>=narrow.tree.viewBox.width?narrow:null;
const renderModel=mode==="share"?desktop:model;
return <figure ref={host} className="bk-diagram" data-theme={theme} data-content-renderer="diagram" data-renderer-mode={mode} style={{margin:"12px 0",maxWidth:"100%",minWidth:0,color:"var(--bk-diagram-text)",fontFamily:'"Plus Jakarta Sans",system-ui,sans-serif'}}>
const renderModel=mode==="share"?desktop:model, framed=mode!=="share", inset=framed?"0 12px":undefined;
const share=<StaticDiagramShareMenu svg={()=>toStatic(source,{theme:"print"})}/>;
return <figure ref={host} className="bk-diagram" data-theme={theme} data-content-renderer="diagram" data-renderer-mode={mode} data-diagram-framed={framed?"":undefined} aria-labelledby={framed?`${id}-caption`:undefined} style={{margin:"12px 0",maxWidth:"100%",minWidth:0,color:"var(--bk-diagram-text)",fontFamily:'"Plus Jakarta Sans",system-ui,sans-serif',...framed?{boxSizing:"border-box",borderRadius:12,outline:`1px solid ${color.edge}`,outlineOffset:-1,paddingBottom:renderModel?0:12}:{}}}>
<style data-content-renderer-tokens="">{DIAGRAM_TOKEN_CSS}</style>
<figcaption style={{fontFamily:'"DM Serif Text",Georgia,serif',fontSize:18}}>{spec.title}</figcaption>
{renderModel ? <Drawing model={renderModel} theme={theme} id={id}/> : <><p data-diagram-summary="">{spec.desc}</p>{spec.callouts?.length?<div data-diagram-notes="">{groupCallouts(spec).map(group=>{
{framed ? <figcaption className="bk-diagram-head" style={{display:"flex",alignItems:"center",gap:8,minWidth:0,padding:"4px 6px 4px 12px",borderBottom:`1px solid ${color.line}`}}>
<span id={`${id}-caption`} data-diagram-title="" style={{flex:"1 1 auto",minWidth:0,fontFamily:'"DM Serif Text",Georgia,serif',fontSize:18,overflowWrap:"anywhere"}}>{spec.title}</span>
<span className="bk-diagram-controls" style={{flex:"none",marginLeft:"auto",display:"flex",alignItems:"center",gap:4}}>
<IconButton size="sm" icon="enlarge" name="Open diagram" onClick={()=>setViewer(true)}/>
{share}
</span>
</figcaption> : <figcaption style={{fontFamily:'"DM Serif Text",Georgia,serif',fontSize:18}}>{spec.title}</figcaption>}
{renderModel ? <Drawing model={renderModel} theme={theme} id={id}/> : <><p data-diagram-summary="" style={{padding:inset}}>{spec.desc}</p>{spec.callouts?.length?<div data-diagram-notes="" style={{padding:inset}}>{groupCallouts(spec).map(group=>{
const planned=desktop.elements.flatMap(item=>item.attrs["data-diagram-notes-band"]!==undefined?item.children??[]:[]).find(item=>item.attrs["data-diagram-callout-group"]===group.target);
return <section key={group.target} data-target={group.target}><h3 style={{fontFamily:'"JetBrains Mono",monospace',fontSize:9.5,fontWeight:600,color:"var(--bk-diagram-text)"}}>{group.name} · {group.indices.length} {group.indices.length===1?"NOTE":"NOTES"}</h3>
{planned?.attrs["data-target-drawn"]==="false"?<p style={{fontSize:14}}>{undrawnCalloutExplanation(spec,group.target)}</p>:null}
<ol style={{margin:0,padding:0,listStyle:"none"}}>{group.indices.map(index=><li key={index} value={index+1} data-diagram-callout={index} style={{display:"grid",gridTemplateColumns:`${Math.max(24,typeWidthBudget(String(spec.callouts!.length),"label"))}px minmax(0,1fr)`,columnGap:8,fontSize:14,fontWeight:500}}><span data-callout-index="" style={{fontFamily:'"JetBrains Mono",monospace',fontSize:9.5,fontWeight:600,textAlign:"right",color:"var(--bk-color-ink-mute)"}}>{index+1}</span><span data-callout-text="" style={{minWidth:0,overflowWrap:"anywhere"}}>{spec.callouts![index]!.text}</span></li>)}</ol>
</section>;
})}</div>:null}</>}
<div className="bk-diagram-controls" style={{display:"flex",gap:8,flexWrap:"wrap"}}>
{framed ? null : <div className="bk-diagram-controls" style={{display:"flex",gap:8,flexWrap:"wrap"}}>
<Button label="Open diagram" block={false} onClick={()=>setViewer(true)} style={{minHeight:44,minWidth:44}}/>
<StaticDiagramShareMenu svg={()=>toStatic(source,{theme:"print"})}/>
</div>
{share}
</div>}
<div className="bk-diagram-print" style={{display:"none"}}><Drawing model={desktop} theme="print" id={`${id}-print`} interactive={false}/></div>
<style>{`@media print{[data-content-renderer="diagram"]>.bk-diagram,[data-content-renderer="diagram"]>[data-diagram-summary],[data-content-renderer="diagram"]>[data-diagram-notes],.bk-diagram-controls{display:none!important}.bk-diagram-print{display:block!important}}`}</style>
{framed ? <style>{FRAME_CSS}</style> : null}
{viewer&&<ZoomViewer label="Diagram viewer" onClose={()=>setViewer(false)} minScale={1} maxFitScale={1} actions={<StaticDiagramShareMenu svg={()=>toStatic(source,{theme:"print"})}/>}><Drawing model={narrow??desktop} theme={theme} id={`${id}-viewer`}/></ZoomViewer>}
</figure>;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/ui-kit/src/primitives/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* glyph directly, so swapping `icon` swaps the glyph, with no imperative
* escape hatch and no timer.
*
* 88 keys, 86 distinct glyphs. Two pairs are aliases — `deny`/`dismiss` both
* render an x, `settings`/`filter` both render sliders — and all 88 are kept.
* 89 keys, 87 distinct glyphs. Two pairs are aliases — `deny`/`dismiss` both
* render an x, `settings`/`filter` both render sliders — and all 89 are kept.
* They render identically today but mean different things, and collapsing them
* would leave a future icon set unable to tell them apart.
*
Expand Down Expand Up @@ -70,6 +70,7 @@ import {
Download,
Ellipsis,
EllipsisVertical,
Expand,
FileImage,
FileLock2,
FilePenLine,
Expand Down Expand Up @@ -203,6 +204,8 @@ export const ICONS = {
digest: Newspaper,
health: ChartColumn, // lucide renames `bar-chart-3`; the semantic key is the kit's vocabulary
link: ArrowUpRight,
/** Open content in its dedicated full-size viewer (a diagram's zoom). */
enlarge: Expand,
chat: MessageSquare,
wifi: Wifi,
battery: BatteryFull,
Expand Down
9 changes: 5 additions & 4 deletions packages/ui-kit/tests/icon-map.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* of failure into a red build.
*
* It also pins the key and glyph counts (the port shipped 78 over 76, then 79 over 77; D52 added
* eight session-state keys, 87 over 85; Discovery adds loading, 88 over 86) — so a key lost in a merge is caught, and the
* eight session-state keys, 87 over 85; Discovery adds loading, 88 over 86; framed diagrams add enlarge, 89 over 87) — so a key lost in a merge is caught, and the
* two deprecated aliases stay repointed at their canonical exports.
*/

Expand All @@ -23,13 +23,14 @@ describe("icon map", () => {
expect(unresolved).toEqual([]);
});

test("all 88 keys survive, over 86 distinct glyphs", () => {
test("all 89 keys survive, over 87 distinct glyphs", () => {
// Two pairs are aliases — deny/dismiss and settings/filter. They render
// identically today but mean different things, and collapsing them would
// leave a future icon set unable to tell them apart.
expect(entries.length).toBe(88);
expect(new Set(entries.map(([, glyph]) => glyph)).size).toBe(86);
expect(entries.length).toBe(89);
expect(new Set(entries.map(([, glyph]) => glyph)).size).toBe(87);
expect(ICONS.loading).toBe(lucide.LoaderCircle);
expect(ICONS.enlarge).toBe(lucide.Expand);
expect(ICONS.deny).toBe(ICONS.dismiss);
expect(ICONS.settings).toBe(ICONS.filter);
});
Expand Down
8 changes: 4 additions & 4 deletions packages/ui-kit/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { recordingProof } from "../ui-react/tests/browser/offline/recording-proof.ts";
import { conversationServer } from "../ui-react/tests/browser/conversation-server-command.ts";
import { diagramArtifact, diagramFontStyles, diagramRasterComparison } from "../ui-react/tests/browser/diagram-export-command.ts";
import { diagramArtifact, diagramFontStyles, diagramRasterComparison, diagramRepaintParity, fullRasterChromiumArgs } from "../ui-react/tests/browser/diagram-export-command.ts";
import { diagramCapture, diagramFixture } from "../ui-react/tests/browser/diagram-proof-command.ts";
import { mermaidMedia, mermaidOutput, mermaidScreenComparison } from "../ui-react/tests/browser/mermaid-proof-command.ts";
import { consumerParityViewport } from "./tests/visual/consumer-parity-viewport.ts";
Expand Down Expand Up @@ -138,8 +138,8 @@ export default mergeConfig(
include: ["../ui-react/tests/browser/diagrams-*.layout.tsx"],
browser: {
enabled: true, screenshotFailures: false,
commands: { diagramRasterComparison, diagramFontStyles, diagramArtifact, mermaidScreenComparison, diagramCapture, diagramFixture, overlayMouse, mermaidMedia, mermaidOutput, formConsumerStyles, formViewport },
provider: playwright({ contextOptions: { reducedMotion: "reduce" } }),
commands: { diagramRasterComparison, diagramRepaintParity, diagramFontStyles, diagramArtifact, mermaidScreenComparison, diagramCapture, diagramFixture, overlayMouse, mermaidMedia, mermaidOutput, formConsumerStyles, formViewport },
provider: playwright({ contextOptions: { reducedMotion: "reduce" }, launchOptions: { args: fullRasterChromiumArgs } }),
headless: true,
instances: [{ browser: "chromium" }],
},
Expand All @@ -152,7 +152,7 @@ export default mergeConfig(
include: ["../ui-react/tests/browser/diagrams-*.layout.tsx"],
browser: {
enabled: true, screenshotFailures: false,
commands: { diagramRasterComparison, diagramFontStyles, diagramArtifact, mermaidScreenComparison, diagramCapture, diagramFixture, overlayMouse, mermaidMedia, mermaidOutput, formConsumerStyles, formViewport },
commands: { diagramRasterComparison, diagramRepaintParity, diagramFontStyles, diagramArtifact, mermaidScreenComparison, diagramCapture, diagramFixture, overlayMouse, mermaidMedia, mermaidOutput, formConsumerStyles, formViewport },
provider: playwright({ contextOptions: { reducedMotion: "reduce" } }),
headless: true,
instances: [{ browser: "webkit" }],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading