Skip to content
Merged

Dev #153

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
11 changes: 2 additions & 9 deletions packages/flint-mcp/ui/src/BoardView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { boardPng } from './board-export';
import { SelectionChips, chipText, impliedParts, partText } from './selection-chips';
import { ViewSwitch, useCellViews, useChartTable, type CellView } from './chart-table-view';
import { ActionButton, ThemeControl } from './controls';
import { usePageScroll } from './page-scroll';
import { LINK_LAYER, conditionUpdates, gestureParts, shownFields, type ChartLink, type LinkCondition, type LinkSpec } from 'flint-chart/interactive';

export interface BoardChart {
Expand Down Expand Up @@ -733,16 +734,8 @@ export function BoardView({ app, initial, hostContext }: { app: App; initial: Bo
document.documentElement.style.background = style.background;
document.body.style.background = style.background;
}, [style.background]);
// Inline, the card is sized to the board, so the page never scrolls. A scrollbar would appear while the
// host catches up with a new height, narrow the board, lay every chart out again, and change the height
// again. In a pane the host sets the height, so a taller board scrolls, with its gutter kept so the
// scrollbar never narrows it.
const paned = hostContext?.displayMode === 'fullscreen' || hostContext?.displayMode === 'pip';
useEffect(() => {
document.documentElement.style.overflow = paned ? 'hidden auto' : 'hidden';
document.documentElement.style.scrollbarGutter = paned ? 'stable' : '';
document.body.style.overflow = paned ? 'visible' : 'hidden';
}, [paned]);
usePageScroll(hostContext, paned);
const byId = useMemo(() => new Map(charts.map((chart) => [chart.id, chart])), [charts]);

const grid = draft ?? board.grid;
Expand Down
12 changes: 3 additions & 9 deletions packages/flint-mcp/ui/src/ChartView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { chartIconFor } from './chart-icons';
import { SelectionChips, chipText, impliedParts, partText, type SelectionChip } from './selection-chips';
import { VIEW_SWITCH_LABEL, ViewSwitchIcon, useChartTable, type CellView } from './chart-table-view';
import { tablePng } from './table-export';
import { usePageScroll } from './page-scroll';
import { conditionUpdates, selectionParts, type LinkCondition } from 'flint-chart/interactive';
import { chartContext, chartView, type ChartGesture } from '../../src/chart-context';
import {
Expand Down Expand Up @@ -611,16 +612,9 @@ export function ChartView({ app, shown, hostContext }: { app: App; shown: Board;
}, []);
useEffect(() => () => chartBoxObserver.current?.disconnect(), []);

// Inline, the card is sized to the chart, so the page never scrolls: a scrollbar shown while the host
// catches up with a new height would narrow the chart and lay it out again. In a pane the host sets
// the height and the chart is laid out for what the pane leaves it; the page scrolls only past that,
// with its gutter kept so the scrollbar never narrows the chart.
// In a pane the host sets the height and the chart is laid out for what the pane leaves it.
const paned = hostContext?.displayMode === 'fullscreen' || hostContext?.displayMode === 'pip';
useEffect(() => {
document.documentElement.style.overflow = paned ? 'hidden auto' : 'hidden';
document.documentElement.style.scrollbarGutter = paned ? 'stable' : '';
document.body.style.overflow = paned ? 'visible' : 'hidden';
}, [paned]);
usePageScroll(hostContext, paned);

// Re-seed when a new tool input arrives from the host.
useEffect(() => setCurrent(input), [input]);
Expand Down
49 changes: 49 additions & 0 deletions packages/flint-mcp/ui/src/page-scroll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { useEffect, useState } from 'react';
import type { McpUiHostContext } from '@modelcontextprotocol/ext-apps';

/** The tallest the host will draw the card inline, if it says. */
function hostMaxHeight(hostContext?: McpUiHostContext): number | undefined {
const dims = hostContext?.containerDimensions as { height?: number; maxHeight?: number } | undefined;
const cap = dims?.maxHeight ?? dims?.height;
return typeof cap === 'number' && Number.isFinite(cap) && cap > 0 ? cap : undefined;
}

/** How far a scrolling page must shrink below the cap before it stops scrolling, so the gutter cannot flip it back and forth. */
const HYSTERESIS = 16;

/**
* Whether the page scrolls. Inline, the card is sized to the page, so it never does: a scrollbar would
* appear while the host catches up with a new height, narrow the content, lay it out again, and change
* the height again. A host that stops growing the card at a height (VS Code: 75% of its window) says so
* in `containerDimensions.maxHeight`; a page taller than that scrolls, or its bottom is cut off. In a pane
* the host sets the height, so the page scrolls past it. A scrolling page keeps its gutter so the
* scrollbar never narrows it.
*/
export function usePageScroll(hostContext: McpUiHostContext | undefined, paned: boolean): void {
const cap = paned ? undefined : hostMaxHeight(hostContext);
const [over, setOver] = useState(false);
useEffect(() => {
if (cap === undefined || typeof ResizeObserver === 'undefined') {
setOver(false);
return;
}
const read = () => {
const height = document.body.scrollHeight;
setOver((prev) => (prev ? height > cap - HYSTERESIS : height > cap + 1));
};
read();
const observer = new ResizeObserver(read);
observer.observe(document.body);
return () => observer.disconnect();
}, [cap]);

const scrolls = paned || over;
useEffect(() => {
document.documentElement.style.overflow = scrolls ? 'hidden auto' : 'hidden';
document.documentElement.style.scrollbarGutter = scrolls ? 'stable' : '';
document.body.style.overflow = scrolls ? 'visible' : 'hidden';
}, [scrolls]);
}
77 changes: 77 additions & 0 deletions site/src/components/PromptBlock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { useState, type CSSProperties } from 'react';
import { useTranslation } from 'react-i18next';
import { siteTheme } from '../shared/theme';

const HAIRLINE = 'rgba(0, 0, 0, 0.10)';

/**
* A monospace block of text. With `copyable`, it is a prompt the reader pastes into their agent, with a
* copy button over its top-right corner.
*/
export function PromptBlock({ children, copyable = false }: { children: string; copyable?: boolean }) {
const { t } = useTranslation();
const [copied, setCopied] = useState(false);

async function copy() {
await navigator.clipboard.writeText(children);
setCopied(true);
window.setTimeout(() => setCopied(false), 1600);
}

return (
<div className={copyable ? 'prompt-block prompt-block-copyable' : 'prompt-block'} style={wrapStyle}>
{copyable ? (
<button type="button" style={copyButtonStyle} onClick={copy}>
<span aria-hidden="true" style={copyIconStyle}>{copied ? '✓' : '⧉'}</span>
{copied ? t('mcp.copied') : t('mcp.copyPrompt')}
</button>
) : null}
<pre style={{ ...preStyle, ...(copyable ? preCopyableStyle : null) }}>{children}</pre>
</div>
);
}

const wrapStyle: CSSProperties = {
margin: '4px 0 8px',
border: `1px solid ${HAIRLINE}`,
borderRadius: 8,
background: 'rgba(0,0,0,0.025)',
overflow: 'auto',
position: 'relative',
};

const preStyle: CSSProperties = {
margin: 0,
padding: '14px 16px',
fontFamily: siteTheme.fontMono,
fontSize: 13,
lineHeight: 1.6,
color: siteTheme.text,
};

const preCopyableStyle: CSSProperties = {
paddingRight: 128,
};

const copyButtonStyle: CSSProperties = {
position: 'absolute',
top: 8,
right: 8,
display: 'inline-flex',
alignItems: 'center',
gap: 6,
border: `1px solid rgba(0, 102, 204, 0.24)`,
borderRadius: 7,
background: 'rgba(0, 102, 204, 0.08)',
color: siteTheme.accent,
fontFamily: siteTheme.fontSans,
fontSize: 12.5,
fontWeight: 600,
padding: '5px 10px',
cursor: 'pointer',
};

const copyIconStyle: CSSProperties = {
fontSize: 13,
lineHeight: 1,
};
16 changes: 15 additions & 1 deletion site/src/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,18 @@ input[type='range'].site-range:focus-visible {
margin-left: auto;
flex-shrink: 0;
}
}
}
/* A copyable prompt: the copy button floats over the block's top-right corner, beside the short first line. */
.prompt-block-copyable pre {
padding: 14px 14px 12px !important;
font-size: 12px !important;
white-space: pre-wrap;
overflow-wrap: anywhere;
}

@media (max-width: 520px) {
/* Too narrow for the button beside the first line: it keeps a row of its own. */
.prompt-block-copyable pre {
padding-top: 42px !important;
}
}
16 changes: 12 additions & 4 deletions site/src/i18n/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@
"ctaMcp": "Get MCP Server",
"ctaGithub": "Visit GitHub",
"ctaDocs": "Read the docs",
"tryIt": {
"title": "Try it now",
"body": "Copy this prompt into your AI agent, such as GitHub Copilot, Claude Code, Cursor or Codex. It adds the Flint MCP server and draws your first chart.",
"manual": "Wondering about the experience? Check out <mcp>the MCP server</mcp>."
},
"news": {
"title": "Updates",
"video": "Video",
Expand Down Expand Up @@ -444,11 +449,12 @@
"howItWorksBody": "A Flint spec consists of the data, semantic types, the chart spec, and optional theme and interaction specs. Instead of relying on complex user-side logic to glue them together, the compiler does the heavy lifting: it resolves each part against the others and composes a complete backend-native spec (shown here in Vega-Lite), filling in the necessary low-level details, and renders a good-looking, interactive chart.",
"overviewAlt": "Flint workflow: an agent infers a dataSpec from a raw table, a short chartSpec is written, and Flint compiles it into a faceted line chart, then a grouped bar, waterfall, heatmap, and sunburst as the spec is edited.",
"leadBefore": "Flint is a visualization intermediate language that lets",
"leadHighlight1": "AI agents reliably create expressive, good-looking and interactive charts from simple, human-editable chart specs",
"leadHighlight1": "AI agents reliably create expressive, good-looking and interactive charts from simple, human-editable specs",
"leadStop": ". ",
"leadAvailability": "It is available as an <mcp>MCP server</mcp> for everyday use with your agent, and as an <npm>npm library</npm> for building interactive applications.",
"leadHighlight2": "Flint supports {{chartTypes}} chart types across {{backends}} rendering backends through one unified interface, with {{themes}} themes and {{presets}} interaction presets",
"leadAfter": "To create bespoke visualizations, you can design custom themes in the <themeLab>Theme Lab</themeLab> and build <advanced>advanced interactions</advanced> with the Flint API.",
"leadInsight": "The key design is to disentangle the visual, style and interaction logic that low-level chart libraries mix together: you or your agents describe each in a short semantic spec, and the compiler composes them.",
"leadAvailability": "Use it as an <mcp>MCP server</mcp> with your agent, or as an <npm>npm library</npm> for building interactive applications.",
"leadHighlight2": "Flint supports {{chartTypes}} chart types across {{backends}} rendering backends, {{themes}} themes and {{presets}} interaction presets",
"leadAfter": "For bespoke visualizations, design your own themes in the <themeLab>Theme Lab</themeLab> and build <advanced>advanced interactions</advanced> with the Flint API. ",
"backendRosterLabel": "Backends",
"themeRosterLabel": "Themes",
"interactionRosterLabel": "Interactions",
Expand Down Expand Up @@ -565,6 +571,8 @@
"leadBefore": "Install <code>flint-chart-mcp</code> as a",
"leadMcpLink": "Model Context Protocol",
"leadAfter": "server and your agent can create interactive charts or author reusable visual themes. By default it opens an interactive Flint chart view; it can also return static artifacts and guide agents through a formal ThemeSpec.",
"copyPrompt": "Copy prompt",
"copied": "Copied",
"quickStart": "Quick start:",
"quickStartBody": "paste this setup request into your agent and let it configure Flint for the current project. For manual setup, see",
"installConfigure": "install & configure",
Expand Down
16 changes: 12 additions & 4 deletions site/src/i18n/messages/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@
"ctaMcp": "使用 MCP 服务器",
"ctaGithub": "访问 GitHub",
"ctaDocs": "阅读文档",
"tryIt": {
"title": "立即试用",
"body": "把这段提示词复制到你的 AI 智能体(如 GitHub Copilot、Claude Code、Cursor 或 Codex)。它会添加 Flint MCP 服务器,并画出你的第一张图表。",
"manual": "想了解使用体验?请查看 <mcp>MCP 服务器</mcp>页面。"
},
"news": {
"title": "更新",
"video": "视频",
Expand Down Expand Up @@ -444,11 +449,12 @@
"howItWorksBody": "一份 Flint 规范由数据、语义类型、图表规范,以及可选的主题和交互规范组成。无需在使用方编写复杂逻辑把它们拼接起来,编译器会完成繁重的工作:它将各部分相互解析,组合出完整的后端原生规范(此处以 Vega-Lite 为例),补全必要的底层细节,并渲染出美观、可交互的图表。",
"overviewAlt": "Flint 工作流:智能体从原始表格推断 dataSpec,编写简短的 chartSpec,Flint 将其编译为按地区展示的折线图;随后在编辑规范时依次得到分组柱状图、瀑布图、热力图与旭日图。",
"leadBefore": "Flint 是一种可视化中间语言,帮助",
"leadHighlight1": "AI 智能体从简洁、可人工编辑的图表规范出发,稳定生成表现力强、观感出色且可交互的图表",
"leadHighlight1": "AI 智能体从简洁、可人工编辑的规范出发,稳定生成表现力强、观感出色且可交互的图表",
"leadStop": "。",
"leadAvailability": "你可以通过 <mcp>MCP 服务器</mcp>在日常工作中配合智能体使用它,也可以用 <npm>npm 库</npm>构建交互式应用。",
"leadHighlight2": "Flint 通过统一接口,在 {{backends}} 种渲染后端上支持 {{chartTypes}} 种图表类型,并提供 {{themes}} 套主题和 {{presets}} 种交互预设",
"leadAfter": "如需定制可视化,可以在<themeLab>主题实验室</themeLab>中设计自定义主题,并用 Flint API 构建<advanced>高级交互</advanced>。",
"leadInsight": "其核心设计是把底层图表库中混在一起的视觉逻辑、样式逻辑和交互逻辑解耦:你或你的智能体分别用简短的语义规范描述它们,由编译器将它们组合起来。",
"leadAvailability": "你可以把它作为 <mcp>MCP 服务器</mcp>配合智能体使用,也可以作为 <npm>npm 库</npm>构建交互式应用。",
"leadHighlight2": "Flint 在 {{backends}} 种渲染后端上支持 {{chartTypes}} 种图表类型,并提供 {{themes}} 套主题和 {{presets}} 种交互预设",
"leadAfter": "如需定制可视化,可以在<themeLab>主题实验室</themeLab>中设计自己的主题,并用 Flint API 构建<advanced>高级交互</advanced>。",
"backendRosterLabel": "渲染后端",
"themeRosterLabel": "主题",
"interactionRosterLabel": "交互",
Expand Down Expand Up @@ -565,6 +571,8 @@
"leadBefore": "将 <code>flint-chart-mcp</code> 配置为",
"leadMcpLink": "Model Context Protocol",
"leadAfter": "服务器后,智能体既能创建交互式图表,也能编写可复用的视觉主题。Flint 默认打开可交互的图表视图;也可以导出静态结果,并引导智能体通过正式的 ThemeSpec 定义视觉设计。",
"copyPrompt": "复制提示词",
"copied": "已复制",
"quickStart": "让 AI 智能体帮你配置:",
"quickStartBody": "把下面这段请求发给智能体即可。若想手动配置,请参阅",
"installConfigure": "安装与配置",
Expand Down
Loading
Loading