Files
MujicaUI/chat/artifact_card.go
T
ZacharyZhang-NYandClaude Opus 5.5 bcce34cda1 Upgrade MyGo to v0.5.5
MyGo v0.5.5 returns ui.Element as a checked value handle instead of a
pointer. Migrated with `mygo migrate-ui`, then fixed what the codemod
leaves to review:

- Element nil checks become .Valid(); absent elements are ui.Element{}.
- Input handlers and paint callbacks run outside the build pass, where
  elements expire and Context methods are inert: read IsDisabled into a
  local during the build, keep a ui.Handle for Focus, use c.Services()
  for clipboard access, create ui.Local state during the build.
- Add core.AutoFocus: v0.5.5 records an overlay's opener after its
  content builds, so same-frame autofocus lost focus restore on close.
  It focuses one frame later; cascader rows defer their focus likewise.
- core.OverlayLayer identifies build passes by the root element, not
  c.Now(), which repeats across passes and under the Tester clock.
- Context menus survive the opening press counted as PressedOutside;
  split button tooltip no longer reorders its open menu; disabled
  menubar rows pass presses to the panel; Form defers blur-started
  async checks so the growing message no longer moves Submit away
  from the release; Combobox drops its disabled copy now that MyGo
  blocks typing under a disabled wrapper (canary flipped to a guard).
- The Tester clock is virtual: tests use Advance/Now instead of
  time.Sleep/time.Now and read element state inside the view. The web
  mirror advances the clock to wall time before each frame and input.
- AGENTS.md and docs describe the value Element API and the new pin.

Snapshot goldens are darwin-only and were not re-verified here.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 01:37:54 -04:00

78 lines
2.8 KiB
Go

package chat
import (
"log/slog"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/agent"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/icons"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/internal"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/theme"
)
// ArtifactCardOptions configure an ArtifactCard. Title is required.
type ArtifactCardOptions struct {
Kind agent.ArtifactKind
Title string
// Detail is a short fact, such as "Go, 120 lines".
Detail string
// Streaming shows the artifact is still being written.
Streaming bool
Disabled bool
}
var artifactKinds = [3]struct{ icon, name string }{
{"file", "artifact_card.code"}, {"file-text", "artifact_card.document"}, {"layout-grid", "artifact_card.web"},
}
// ArtifactCard stands for an artifact; activating asks to open it.
func ArtifactCard(c *ui.Context, opts ArtifactCardOptions) core.ChoiceResult {
if opts.Title == "" {
panic("mujica: ArtifactCard needs a Title")
}
if opts.Kind < agent.ArtifactCode || opts.Kind > agent.ArtifactWeb {
panic("mujica: ArtifactCard Kind out of range")
}
k := core.Tokens(c)
d := core.Density(c)
kind := artifactKinds[opts.Kind]
var b ui.Element
ui.Row(c).Shrink(0).Disabled(opts.Disabled).Children(func() {
b = ui.ButtonBase(c).MinWidth(260).MaxWidth(420).MinHeight(56).Padding(d.Unit()*2, d.Unit()*3).Gap(d.Unit()*3).
Justify(ui.Start).Radius(theme.CardRadius).Background(k.Surface).Border(theme.BorderWidth, k.ControlBorder).
Label(core.Msg(c, kind.name) + ": " + opts.Title)
})
internal.Ring(b, k.Focus, theme.CardRadius)
if b.Hovered() {
b.Background(k.SurfaceHover)
}
b.Transition(core.ColorFade)
b.Children(func() {
ui.Box(c).Size(36, 36).Shrink(0).Center().Radius(theme.ControlRadius).Background(k.Selection).Children(func() {
ui.Icon(c, icons.Must(kind.icon)).Size(18, 18).TextColor(k.AccentText)
})
ui.Column(c).Grow(1).MinWidth(0).Gap(2).Children(func() {
ui.Text(c, opts.Title).SingleLine().Bold().TextColor(k.Text)
ui.Row(c).Gap(d.Unit()).AlignItems(ui.Center).Children(func() {
detail := core.Msg(c, kind.name)
if opts.Detail != "" {
detail += " · " + opts.Detail
}
ui.Text(c, detail).SingleLine().FontSize(core.FontSize(c, theme.CaptionSize)).TextColor(k.TextMuted)
if opts.Streaming {
core.Spinner(c, core.SpinnerOptions{Size: 12, Label: core.Msg(c, "artifact_card.writing")})
}
})
})
ui.Text(c, core.Msg(c, "artifact_card.open")).FontSize(core.FontSize(c, theme.CaptionSize)).TextColor(k.AccentText).Shrink(0)
ui.Icon(c, icons.Must("chevron-right")).Size(14, 14).TextColor(k.AccentText)
})
open := b.Clicked() && !b.IsDisabled()
if open {
slog.Debug("mujica: artifact_card open", "kind", opts.Kind)
}
return core.NewChoiceResult(b, open)
}