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
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"vcs": { "enabled": true, "clientKind": "git", "useIgnoreFile": true },
"files": { "includes": ["**", "!src/components/ui"] },
"files": { "includes": ["**", "!src/components/ui", "!.claude"] },
"formatter": { "indentStyle": "space", "indentWidth": 2, "lineWidth": 110 },
"javascript": { "formatter": { "quoteStyle": "single" } },
"css": { "parser": { "tailwindDirectives": true } },
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"format": "biome check --write ."
},
"dependencies": {
"@fontsource-variable/geist-mono": "^5.3.0",
"@fontsource-variable/inter": "^5.3.0",
"@holistics/anfra-sdk": "0.14.2",
"@hono/node-server": "^2.1.4",
"class-variance-authority": "^0.7.1",
Expand All @@ -34,6 +36,7 @@
"react-dom": "^19.3.0",
"react-resizable-panels": "^4.14.4",
"tailwind-merge": "^3.7.0",
"tw-animate-css": "^1.4.0",
"yaml": "^2.9.1"
},
"devDependencies": {
Expand Down
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 75 additions & 39 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Ellipsis, RotateCw } from 'lucide-react';
import { CircleAlert, Ellipsis, Info, LoaderCircle, RotateCw } from 'lucide-react';
import { type CSSProperties, useCallback, useEffect, useRef, useState } from 'react';
import { AppIcon, EndorsedMark } from '@/components/app-icon';
import { AppInfo } from '@/components/app-info';
import { AppSidebar } from '@/components/app-sidebar';
import { CommandPalette } from '@/components/command-palette';
import { DataAppStage } from '@/components/data-app-stage';
import { ErrorAlert } from '@/components/error-alert';
import { Home } from '@/components/home';
import { PluginPanel } from '@/components/plugin-panel';
import { PromptPanel } from '@/components/prompt-panel';
Expand All @@ -18,18 +20,19 @@ import {
} from '@/components/ui/dropdown-menu';
import { Kbd, KbdGroup } from '@/components/ui/kbd';
import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from '@/components/ui/resizable';
import { Separator } from '@/components/ui/separator';
import { SidebarInset, SidebarProvider, SidebarTrigger } from '@/components/ui/sidebar';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
import { VersionsPanel } from '@/components/versions-panel';
import {
type Command,
type DatasetDescriptor,
designTheme,
loadCatalog,
type Mounted,
type Rendering,
setPluginTheme,
} from '@/data-app';
import { isPlainClick } from '@/lib/click';
import { chromeCommands, commandIcon, commandIcons } from '@/lib/commands';
import {
catalog,
Expand Down Expand Up @@ -104,24 +107,12 @@ export function App() {
void refreshDatasets();
}, [refreshCatalog, refreshDatasets]);

// The plugins' UI (the panel's tabs, the menu and card in the frame) follows the page's theme.
// The plugins' UI (the panel's tabs, the menu and card in the frame) follows the page's theme: the SDK
// reads each token from the anfra-design property on the page (re-run when the scheme changes).
useEffect(() => {
const style = getComputedStyle(document.documentElement);
const read = (name: string) => style.getPropertyValue(name).trim() || undefined;
setPluginTheme({
scheme: theme,
tokens: {
'color-bg': read('--background'),
'color-fg': read('--foreground'),
'color-muted': read('--muted-foreground'),
'color-border': read('--border'),
// The neutral theme has no accent colour; links and selection in the tabs take indigo.
'color-accent': theme === 'dark' ? '#a5b4fc' : '#4f46e5',
'color-danger': read('--destructive'),
radius: read('--radius'),
font: getComputedStyle(document.body).fontFamily || undefined,
},
});
setPluginTheme(
designTheme(theme === 'dark' ? 'dark' : 'light', getComputedStyle(document.documentElement)),
);
}, [theme]);

// Deep links: the address follows the open Data App, and back and forward follow the address.
Expand Down Expand Up @@ -271,13 +262,13 @@ export function App() {

let content: React.ReactNode;
if (error) {
content = <Message>{error}</Message>;
content = <ErrorMessage>{error}</ErrorMessage>;
} else if (!path) {
content = entries ? <Home entries={entries} onSelect={select} /> : <Message>Loading…</Message>;
content = entries ? <Home entries={entries} onSelect={select} /> : <Loading />;
} else if (entries && !app) {
content = moved ? <Message>Loading…</Message> : <Message>No Data App at {path}.</Message>;
content = moved ? <Loading /> : <Missing path={path} onHome={() => select('')} />;
} else if (!datasets || !app) {
content = <Message>Loading…</Message>;
content = <Loading />;
} else {
content = (
<DataAppStage
Expand All @@ -294,8 +285,8 @@ export function App() {
<TooltipProvider delayDuration={300}>
<SidebarProvider className="h-full" style={sidebarStyle} defaultOpen={sidebarOpen}>
<AppSidebar entries={entries} selected={path} onSelect={select} />
<SidebarInset className="min-w-0 overflow-hidden md:peer-data-[variant=inset]:border">
<header className="flex h-12 shrink-0 items-center gap-2 border-b px-3">
<SidebarInset className="min-w-0 overflow-hidden">
<header className="flex h-12 shrink-0 items-center gap-2 rounded-t-xl border-b border-default bg-background px-3">
<Tooltip>
<TooltipTrigger asChild>
<SidebarTrigger />
Expand All @@ -308,11 +299,17 @@ export function App() {
</KbdGroup>
</TooltipContent>
</Tooltip>
<Separator orientation="vertical" className="mr-1 data-[orientation=vertical]:h-4" />
<h1 className="truncate text-sm font-medium">{app?.label ?? 'anfra demo'}</h1>
{app && <AppIcon app={app} className="size-4 shrink-0 icon-highlight-default" />}
{/* An app's name is the page's heading; elsewhere the bar is navigation, and the page has its own. */}
{app ? (
<h1 className="truncate text-label text-default">{app.label}</h1>
) : (
<span className="truncate text-label text-default">anfra demo</span>
)}
{app?.endorsed && <EndorsedMark className="ml-0" />}
{app && <AppInfo app={app} />}
{path && (
<div className="ml-auto flex items-center gap-1">
<div className="ml-auto flex shrink-0 items-center gap-1.5">
<ToolbarButton label="Reload" disabled={!app} onClick={() => setRevision((n) => n + 1)}>
<RotateCw />
</ToolbarButton>
Expand Down Expand Up @@ -355,7 +352,6 @@ export function App() {
onClick={() => !state.disabled && run(command)}
text={textOf(command)}
shortcut={command.shortcut}
className={cn(state.disabled && 'cursor-not-allowed opacity-50')}
>
<Icon />
</ToolbarButton>
Expand Down Expand Up @@ -450,19 +446,59 @@ function ToastMessage({ toast, onDone }: { toast: Toast; onDone: () => void }) {
<div
role="status"
className={cn(
'fixed right-4 bottom-4 z-50 max-w-sm rounded-md border px-3 py-2 text-sm shadow-md',
toast.tone === 'error'
? 'border-destructive/40 bg-destructive text-white'
: 'bg-popover text-popover-foreground',
'fixed right-4 bottom-4 z-50 flex max-w-sm items-start gap-2 rounded-xl border border-default bg-popover px-3 py-2 text-body text-pretty text-default shadow-e2',
'[&_svg]:mt-0.5 [&_svg]:size-4 [&_svg]:shrink-0',
)}
>
{toast.text}
{toast.tone === 'error' ? (
<CircleAlert className="icon-danger-default" />
) : (
<Info className="icon-info-default" />
)}
<span className="min-w-0">{toast.text}</span>
</div>
);
}

/** Something on its way: the stage's spinner, as anfra Cloud's. */
function Loading() {
return (
<div className="grid h-full place-items-center bg-background">
<LoaderCircle role="status" aria-label="Loading" className="size-4 animate-spin icon-weak" />
</div>
);
}

function Message({ children }: { children: React.ReactNode }) {
return <div className="grid h-full place-items-center p-6 text-sm text-muted-foreground">{children}</div>;
/** A link to a Data App that isn't in the repo. */
function Missing({ path, onHome }: { path: string; onHome: () => void }) {
return (
<div className="flex h-full flex-col items-center justify-center gap-1 bg-background p-6 text-center">
<p className="text-heading">No Data App here</p>
<p className="text-body text-pretty text-weak">
Nothing is at <span className="font-mono">{path}</span>.{' '}
<a
href={urlOf('')}
onClick={(event) => {
if (!isPlainClick(event)) return;
event.preventDefault();
onHome();
}}
className="underline underline-offset-2 hover:text-default"
>
Go home
</a>
</p>
</div>
);
}

/** The page's own failure, as a danger alert at the top of the stage. */
function ErrorMessage({ children }: { children: React.ReactNode }) {
return (
<div className="h-full bg-background p-6">
<ErrorAlert>{children}</ErrorAlert>
</div>
);
}

/** An icon button; with `text` it carries a visible label beside the icon, and with `shortcut` its tooltip shows the keys to press. */
Expand All @@ -481,9 +517,9 @@ function ToolbarButton({
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size={text ? 'sm' : 'icon'}
className={cn(!text && 'size-8', active && 'bg-accent text-accent-foreground', className)}
variant={active ? 'secondary' : 'ghost'}
size={text ? 'sm' : 'icon-sm'}
className={cn(className)}
aria-label={label}
aria-pressed={active}
{...props}
Expand Down
56 changes: 33 additions & 23 deletions src/askai/frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,32 +268,42 @@ function pathTo(
return undefined;
}

// On the host's tokens, which the popover's root inherits.
// On the host's tokens, which the popover's root inherits, set to anfra-cloud's (web/DESIGN.md):
// 14/20 body, 12/16 captions, 500 labels; 32px controls; 6px chips and items, 10px buttons and
// fields, 14px menus; hover and pressed layers of ink; disabled as a faint fill, never opacity.
// The menu's elevation is anfra-cloud's e2: a shadow on light, a 1px ring on dark (the SDK sets `color-scheme` on the root, which `light-dark()` follows).
// The SDK always sets the radius, colors and hover and active layers; the radii here derive from it (10px, menus +4px); disabled is not a token, so it mixes from the text color.
const CARD_CSS = `
.card { box-sizing: border-box; width: min(320px, calc(100vw - 32px)); padding: 12px; display: grid; gap: 8px; font: 13px/1.4 var(--anfra-font); color: var(--anfra-color-fg); }
.header { display: flex; align-items: center; gap: 6px; min-width: 0; }
.close { margin-left: auto; flex: none; display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 0; color: var(--anfra-color-muted); font-size: 16px; line-height: 1; }
.close:hover { color: var(--anfra-color-fg); background: color-mix(in srgb, var(--anfra-color-fg) 7%, transparent); }
.card { box-sizing: border-box; width: min(320px, calc(100vw - 32px)); padding: 12px; display: grid; gap: 8px; font: 400 14px/20px var(--anfra-font); color: var(--anfra-color-fg); --hover: var(--anfra-color-hover); --active: var(--anfra-color-active); --disabled: color-mix(in srgb, var(--anfra-color-fg) 4%, transparent); --ease: cubic-bezier(0.22, 1, 0.36, 1); }
.header { display: flex; align-items: center; gap: 8px; min-width: 0; }
.close { margin-left: auto; flex: none; display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: var(--anfra-radius); color: var(--anfra-color-muted); font-size: 16px; line-height: 1; }
.close:hover { color: var(--anfra-color-fg); background: var(--hover); }
.name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: 11px; padding: 1px 6px; border-radius: 4px; flex: none; }
.pill.container { color: #7c3aed; background: color-mix(in srgb, #7c3aed 14%, transparent); }
.pill.block { color: #2563eb; background: color-mix(in srgb, #2563eb 14%, transparent); }
.pill.query { color: #059669; background: color-mix(in srgb, #059669 14%, transparent); }
.pill.control { color: #ea580c; background: color-mix(in srgb, #ea580c 14%, transparent); }
.handle { font: 12px var(--anfra-font-mono); color: var(--anfra-color-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.problems { font-size: 12px; color: var(--anfra-color-danger); }
textarea { font: inherit; color: inherit; background: transparent; border: 1px solid var(--anfra-color-border); border-radius: var(--anfra-radius); padding: 6px 8px; resize: none; field-sizing: content; min-height: 3lh; max-height: 8lh; }
textarea:focus { outline: 2px solid var(--anfra-color-accent); outline-offset: -1px; }
.actions { display: flex; justify-content: flex-end; gap: 6px; }
button { font: inherit; color: inherit; background: transparent; border: 1px solid var(--anfra-color-border); border-radius: var(--anfra-radius); padding: 4px 10px; cursor: pointer; }
button.primary { background: var(--anfra-color-fg); color: var(--anfra-color-bg); border-color: transparent; }
button[aria-disabled] { opacity: 0.5; cursor: not-allowed; }
.pill { flex: none; display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 9999px; font-size: 12px; line-height: 16px; font-weight: 500; }
.pill.container { color: #7c3aed; background: color-mix(in srgb, #7c3aed 12%, transparent); }
.pill.block { color: #2563eb; background: color-mix(in srgb, #2563eb 12%, transparent); }
.pill.query { color: #059669; background: color-mix(in srgb, #059669 12%, transparent); }
.pill.control { color: #ea580c; background: color-mix(in srgb, #ea580c 12%, transparent); }
.handle { font: 400 12px/16px var(--anfra-font-mono); color: var(--anfra-color-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.problems { font-size: 12px; line-height: 16px; color: var(--anfra-color-danger); }
textarea { box-sizing: border-box; font: inherit; color: inherit; background: transparent; border: 1px solid var(--anfra-color-border); border-radius: var(--anfra-radius); padding: 6px 10px; resize: none; field-sizing: content; min-height: calc(3lh + 14px); max-height: calc(8lh + 14px); transition: border-color 160ms var(--ease); }
textarea::placeholder { color: var(--anfra-color-muted); }
textarea:hover { border-color: color-mix(in srgb, var(--anfra-color-fg) 36%, transparent); }
textarea:focus, textarea:focus-visible { outline: none; border-color: var(--anfra-color-accent); box-shadow: inset 0 0 0 1px var(--anfra-color-accent); }
.actions { display: flex; justify-content: flex-end; gap: 8px; }
button { box-sizing: border-box; font: inherit; font-weight: 500; color: inherit; background: transparent; border: 1px solid var(--anfra-color-border); border-radius: var(--anfra-radius); height: 32px; padding: 0 10px; cursor: pointer; transition: background-color 160ms var(--ease), border-color 160ms var(--ease), color 160ms var(--ease), scale 90ms var(--ease); }
button:hover { background: var(--hover); }
button:active { background: var(--active); scale: 0.97; }
button.primary { background: var(--anfra-color-accent); color: var(--anfra-color-bg); border-color: transparent; }
button.primary:hover { background: color-mix(in srgb, var(--anfra-color-accent) 88%, var(--anfra-color-fg)); }
button[aria-disabled], button.primary[aria-disabled] { background: var(--disabled); color: var(--anfra-color-muted); cursor: not-allowed; scale: none; }
.split { position: relative; display: flex; }
.split > button:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split > button:nth-child(2) { border-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; padding: 4px 6px; }
.list { position: absolute; right: 0; bottom: calc(100% + 4px); display: grid; min-width: 220px; padding: 4px; background: var(--anfra-color-bg); border: 1px solid var(--anfra-color-border); border-radius: var(--anfra-radius); }
.split > button:nth-child(2) { border-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; padding: 0 8px; }
.list { position: absolute; right: 0; bottom: calc(100% + 4px); display: grid; min-width: 220px; padding: 4px; background: var(--anfra-color-bg); border: 1px solid var(--anfra-color-border); border-radius: calc(var(--anfra-radius) + 4px); box-shadow: light-dark(0 1px 0 rgb(24 20 31 / 0.03), 0 0 0 1px var(--anfra-color-border-strong)), light-dark(0 18px 40px -18px rgb(24 20 31 / 0.28), 0 0 #0000), light-dark(0 2px 6px -2px rgb(24 20 31 / 0.08), 0 0 #0000); }
.list[hidden] { display: none; }
.list button { border: 0; display: flex; justify-content: space-between; gap: 12px; text-align: left; }
.list button[aria-disabled] { opacity: 1; color: var(--anfra-color-muted); }
.reason { font-size: 12px; }
.list button { border: 0; border-radius: 6px; height: auto; min-height: 32px; padding: 6px 8px; font-weight: 400; display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: left; }
.list button:active { scale: none; }
.list button[aria-disabled] { background: transparent; color: var(--anfra-color-muted); }
.reason { font-size: 12px; line-height: 16px; }
`;
Loading
Loading