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 AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Status legend: ⬜ Todo · ✅ Done
| 18 | Suggestion & Suggestion Group | plain & outlined rows; scroll, wrap, column | ✅ |
| 19 | Confirmation | default, approved, rejected | ⬜ |
| 20 | Error state | | ⬜ |
| 21 | Code block | | ⬜ |
| 21 | Code block | built-in synchronous highlighter; languages host-extensible | ✅ |
| 22 | Thinking indicator | turning, breathing asterisk + shimmer label; active & settled | ✅ |
| 23 | Shimmer | text only; sweeping highlight, static when settled | ✅ |

Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## 0.2.0 (unreleased)

- **Code block** — `FlowCodeBlock`, and a `FlowCodePart` message part
rendered by `FlowMessage`/`FlowThread` with copy intent surfaced on
`onCodeCopy`. Highlighting is built in and synchronous (Dart, JSON,
JavaScript/TypeScript, Python, shell, YAML, HTML, CSS and SQL;
host-extensible via `FlowCodeLanguage.register`), colored by new
`FlowSyntaxColors` theme tokens. The package now also bundles Geist Mono (three weights, SIL OFL)
behind new `code` / `codeInline` typography roles — `withFontFamily()`
no longer touches the mono roles; swap those with
`withCodeFontFamily()`.
- **Breaking**: migrated from `package:flutter/material.dart` to
`package:material_ui` (Material's home since Flutter 3.47) — no API
changes, but the two Materials are distinct types, so the host app must
Expand Down
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

Two hard constraints shape everything here:

- **No third-party dependencies.** `dependencies:` in `pubspec.yaml` contains only the Flutter SDK and Flutter's own first-party packages — `material_ui` (Material's home since Flutter 3.47) and its transitive set, all published by flutter.dev. Nothing outside that. Dev dependencies (`flutter_test`, `flutter_lints`) are fine. Bundled *assets* are not dependencies: the package ships Figtree (`fonts/`, SIL OFL) because the design system is set in it, declared under `flutter: fonts:` and referenced as `package: 'flow_ui'`.
- **No third-party dependencies.** `dependencies:` in `pubspec.yaml` contains only the Flutter SDK and Flutter's own first-party packages — `material_ui` (Material's home since Flutter 3.47) and its transitive set, all published by flutter.dev. Nothing outside that. Dev dependencies (`flutter_test`, `flutter_lints`) are fine. Bundled *assets* are not dependencies: the package ships Figtree and Geist Mono (`fonts/`, SIL OFL) because the design system is set in them, declared under `flutter: fonts:` and referenced as `package: 'flow_ui'`.
- **Nothing model-facing.** Components render state passed in and report intent out through callbacks. No prompts, schemas, provider/network calls, or any LLM awareness — that belongs to the layers built on top.

The theme, the conversation components (message, thread, streaming text, actions, loading), the composer and its menus, attachments with their preview, suggestions, and the chat surface are implemented; the roadmap below tracks the rest. Message content is modeled as typed parts (`lib/src/models/`) — sealed `FlowMessagePart` subtypes rendered by `FlowMessage`, with `FlowCustomPart` + `FlowCustomPartBuilder` as the extension seam for host-injected content.
Expand Down Expand Up @@ -87,7 +87,7 @@ Values come from the Flow UI Figma file. Role names follow Material 3's `ColorSc
| 18 | Suggestion & Suggestion Group | plain & outlined rows; scroll, wrap, column | ✅ |
| 19 | Confirmation | default, approved, rejected | ⬜ |
| 20 | Error state | | ⬜ |
| 21 | Code block | | ⬜ |
| 21 | Code block | built-in synchronous highlighter; languages host-extensible | ✅ |
| 22 | Thinking indicator | turning, breathing asterisk + shimmer label; active & settled | ✅ |
| 23 | Shimmer | text only; sweeping highlight, static when settled | ✅ |

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
| [`FlowStreamingText`](https://flowui.stac.dev/components/streaming-text) | Animated text reveal while a reply arrives |
| [`FlowThinkingIndicator`](https://flowui.stac.dev/components/thinking-indicator) | Turning, breathing asterisk with a shimmering label |
| [`FlowShimmerText`](https://flowui.stac.dev/components/shimmer-text) | Sweeping text highlight, static once settled |
| [`FlowCodeBlock`](https://flowui.stac.dev/components/code-block) | Fenced code with built-in synchronous highlighting, a header label, and a copy affordance — languages host-extensible |
| [`FlowMessageActions`](https://flowui.stac.dev/components/message-actions) | Copy / regenerate / edit / feedback row under a message |
| [`FlowComposer`](https://flowui.stac.dev/components/composer) | Multiline input with send/stop, attachments strip, and leading/trailing action slots |
| [`FlowMenu`](https://flowui.stac.dev/components/menu) | Icon-triggered menu with groups, submenus, and toggles — anchored card on desktop, bottom sheet on phones |
Expand Down
168 changes: 168 additions & 0 deletions docs/src/content/docs/components/code-block.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
---
title: Code block
description: Fenced code on its own ground — built-in synchronous highlighting, a header label, and a copy affordance that reports intent.
sidebar:
order: 13
---

import FlowDemo from '../../../components/FlowDemo.astro';

`FlowCodeBlock` renders a fenced snippet on its own washed ground, under a
header that names the content and offers copy. Highlighting is built in
and synchronous — no setup call, no assets, nothing async. `language`
picks a rule table (Dart, JSON, JavaScript/TypeScript, Python, shell,
YAML, HTML, CSS and SQL ship in the box); unknown ids render plain,
never an error. Token inks come from the theme's `FlowSyntaxColors`, so
code recolors with the rest of the palette in both themes.

In a message, code arrives as a `FlowCodePart` and `FlowMessage` renders
the block for you — copy intent surfaces on `FlowThread.onCodeCopy` with
the part in hand.

## Dart

<FlowDemo demo="codeBlock" variant="dart" height={620} title="Dart" />

```dart title="The block reports intent; the host owns the clipboard"
FlowCodeBlock(
code: source,
language: 'dart',
filename: 'point.dart',
copyTooltip: 'Copy code',
copied: copied,
onCopy: () async {
await Clipboard.setData(ClipboardData(text: source));
setState(() => copied = true);
// Hold `copied` for a beat, then clear it — the affordance shows a
// primary-tinted check for as long as the host says so.
},
)
```

## JSON

Keys read apart from string values, and long lines scroll horizontally
inside the block (`wrap: true` wraps them instead):

<FlowDemo demo="codeBlock" variant="json" height={420} title="JSON" />

```dart title="A payload with a long line"
FlowCodeBlock(
code: payload,
language: 'json',
filename: 'screen.json',
copyTooltip: 'Copy code',
onCopy: () => copy(payload),
)
```

## Plain

No `language` — or one the registry doesn't know — renders plain ink;
the header can still carry a filename:

<FlowDemo demo="codeBlock" variant="plain" height={300} title="Plain" />

```dart title="Logs, output, anything unhighlightable"
FlowCodeBlock(
code: log,
filename: 'build.log',
copyTooltip: 'Copy',
onCopy: () => copy(log),
)
```

## Streaming

While `isStreaming` is true the copy affordance hides — there is nothing
complete to copy — and each delivery renders whole, with no per-character
reveal (streamed code arrives re-highlighted as often as appended, which
a reveal would restart on). In a thread this is automatic while the
message streams:

<FlowDemo demo="codeBlock" variant="streaming" height={620} title="Streaming" />

```dart title="Code parts in a streaming thread"
FlowThread(
messages: messages,
codeCopyTooltip: 'Copy code',
copiedCodePart: copiedPart,
onCodeCopy: (part) async {
await Clipboard.setData(ClipboardData(text: part.code));
setState(() => copiedPart = part);
},
)
```

## Languages

Resolution is by id or alias, case-insensitive, and anything unknown
renders plain — a `rust` fence degrades gracefully rather than erroring:

| Language | id | Aliases |
|---|---|---|
| Dart | `dart` | — |
| JSON | `json` | `jsonc` |
| JavaScript / TypeScript | `javascript` | `js`, `jsx`, `typescript`, `ts`, `tsx` |
| Python | `python` | `py` |
| Shell | `bash` | `sh`, `shell`, `zsh` |
| YAML | `yaml` | `yml` |
| HTML | `html` | `xml` |
| CSS | `css` | `scss`, `less` |
| SQL | `sql` | `mysql`, `postgres`, `postgresql`, `sqlite` |
| Plain | `plain` | `text`, `txt` |

YAML, for one, knows that `on:` is a key before it is a boolean:

<FlowDemo demo="codeBlock" variant="yaml" height={520} title="YAML" />

The registry is host-extensible. `FlowCodeLanguage` is an ordered rule
table — earlier rules win, so comments and strings come first — and
`register` makes it resolvable from every block. A table like SQL's,
whose keywords come in either case, sets `caseSensitive: false`:

```dart title="Registering a language"
FlowCodeLanguage.register(
const FlowCodeLanguage(
id: 'lisp',
rules: [
FlowSyntaxRule(FlowSyntaxToken.comment, r';[^\n]*'),
FlowSyntaxRule(FlowSyntaxToken.string, r'"(?:\\.|[^"\\])*"'),
FlowSyntaxRule(FlowSyntaxToken.punctuation, r'[()]+'),
],
),
);
```

## Theming

Token inks are theme tokens. Install a `FlowSyntaxColors` on the theme to
recolor them; the code face is Geist Mono, bundled with the package, and
swaps via the typography:

```dart title="Custom syntax palette and mono face"
FlowTheme(
colors: FlowColors.light,
syntax: FlowSyntaxColors.light.copyWith(keyword: myBrandAccent),
typography: FlowTypography.standard.withCodeFontFamily('JetBrainsMono'),
)
```

## Key API

- `FlowCodeBlock` — `code`, `language` (id or alias, case-insensitive),
`filename` (header label; falls back to `language`), `onCopy` /
`copied` / `copyTooltip` (intent out, host-owned confirmation),
`isStreaming`, `wrap`, plus `padding` and `borderRadius` over the
design's 16/12 inset and 12px corner.
- `FlowCodePart` — `code`, `language`, `filename`; rendered by
`FlowMessage`, skipped in system messages.
- `FlowThread` / `FlowMessage` — `onCodeCopy` (handed the tapped part),
`copiedCodePart` (pass the instance back while the confirmation lasts),
`codeCopyTooltip`.
- `FlowCodeLanguage` — `find`, `register`, `caseSensitive`, and the
built-ins (`dart`, `json`, `javascript`, `python`, `bash`, `yaml`,
`html`, `css`, `sql`, `plain`); `FlowSyntaxRule` pairs a regex with a
`FlowSyntaxToken`.
- `FlowSyntaxColors` — eight token roles with light and dark presets, on
`FlowTheme.syntax`.
2 changes: 1 addition & 1 deletion docs/src/content/docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ elements and the remaining AI states are on the way.
| Suggestions | <span class="badge-done">Shipped</span> |
| Confirmation | <span class="badge-todo">Planned</span> |
| Error state | <span class="badge-todo">Planned</span> |
| Code block | <span class="badge-todo">Planned</span> |
| Code block | <span class="badge-done">Shipped</span> |
| Thinking indicator | <span class="badge-done">Shipped</span> |
| Shimmer | <span class="badge-done">Shipped</span> |

Expand Down
Binary file added fonts/GeistMono-Medium.ttf
Binary file not shown.
Binary file added fonts/GeistMono-Regular.ttf
Binary file not shown.
Binary file added fonts/GeistMono-SemiBold.ttf
Binary file not shown.
93 changes: 93 additions & 0 deletions fonts/OFL-GeistMono.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Copyright 2024 The Geist Project Authors (https://github.com/vercel/geist-font)

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://openfontlicense.org


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
2 changes: 2 additions & 0 deletions lib/flow_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ export 'src/models/flow_attachment.dart';
export 'src/models/flow_message_data.dart';
export 'src/models/flow_message_part.dart';
export 'src/theme/flow_colors.dart';
export 'src/theme/flow_syntax_colors.dart';
export 'src/theme/flow_theme.dart';
export 'src/theme/flow_typography.dart';
export 'src/widgets/flow_attachment_group.dart';
export 'src/widgets/flow_attachment_preview.dart';
export 'src/widgets/flow_chat_screen.dart';
export 'src/widgets/flow_code_block.dart';
export 'src/widgets/flow_composer.dart';
export 'src/widgets/flow_greeting.dart';
export 'src/widgets/flow_menu.dart';
Expand Down
18 changes: 17 additions & 1 deletion lib/src/models/flow_message_part.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'flow_attachment.dart';

/// One piece of content inside a `FlowMessageData`.
///
/// Sealed so renderers can switch exhaustively. More part types (code, tool)
/// Sealed so renderers can switch exhaustively. More part types (tool)
/// arrive alongside their components; [FlowCustomPart] is how hosts inject
/// arbitrary content today.
@immutable
Expand All @@ -26,6 +26,22 @@ class FlowAttachmentPart extends FlowMessagePart {
final List<FlowAttachment> attachments;
}

/// Fenced code, rendered by a `FlowCodeBlock`.
class FlowCodePart extends FlowMessagePart {
const FlowCodePart(this.code, {this.language, this.filename});

/// The source, verbatim.
final String code;

/// `FlowCodeLanguage` id or alias — usually the fence info string, e.g.
/// `'dart'`. Null or unknown renders plain.
final String? language;

/// The block's header label, e.g. a file hint beside the fence. Null
/// falls back to [language].
final String? filename;
}

/// Host-defined content, rendered through a `FlowCustomPartBuilder`.
class FlowCustomPart extends FlowMessagePart {
const FlowCustomPart({required this.type, this.data});
Expand Down
Loading