mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
feat(app): explore tighter composer layouts behind a layout prop
This commit is contained in:
parent
7a0520bbff
commit
256b59bf49
5 changed files with 275 additions and 20 deletions
|
|
@ -1,11 +1,17 @@
|
|||
import { Show, createMemo, onMount, type JSX } from "solid-js"
|
||||
import { createStore } from "solid-js/store"
|
||||
import type { ModelSelection } from "@/providers/models/selection"
|
||||
import { STORY_MODEL, emptySessionDocument, pendingAndQueuedDocument } from "@opencode/session-ui/storybook"
|
||||
import {
|
||||
STORY_MODEL,
|
||||
emptySessionDocument,
|
||||
largeCompletedDocument,
|
||||
pendingAndQueuedDocument,
|
||||
} from "@opencode/session-ui/storybook"
|
||||
import { Composer } from "./composer"
|
||||
import type { ComposerModel } from "./model"
|
||||
import { createComposerEditor } from "./editor/interaction"
|
||||
import type { ComposerPersistedState, ComposerSuggestion } from "./types"
|
||||
import { composerLayouts, type ComposerLayout } from "./editor/editor"
|
||||
import { buildPromptRequest } from "./request"
|
||||
import { promptLength } from "./prompt-parts"
|
||||
import { SessionPreview } from "@/session/story-model"
|
||||
|
|
@ -61,6 +67,9 @@ function ComposerStory(props: {
|
|||
alternate?: "queue" | "steer"
|
||||
manySuggestions?: boolean
|
||||
suggestionBoundary?: () => HTMLElement | undefined
|
||||
layout?: ComposerLayout
|
||||
// Matches the composer in Kit's capture: Anthropic / Claude Opus 5.5 at the High variant.
|
||||
opus?: boolean
|
||||
}) {
|
||||
const [draft, setDraft] = createStore<ComposerPersistedState>({
|
||||
prompt: props.prompt ?? [{ type: "text", content: "", start: 0, end: 0 }],
|
||||
|
|
@ -71,12 +80,16 @@ function ComposerStory(props: {
|
|||
|
||||
const [story, setStory] = createStore({
|
||||
activity: props.label ?? "Ready",
|
||||
variant: STORY_MODEL.variant,
|
||||
variant: props.opus ? "high" : STORY_MODEL.variant,
|
||||
})
|
||||
|
||||
const modelOption = createMemo(() => ({
|
||||
...selectedModel,
|
||||
name: props.longLabels ? "Claude Sonnet with an unusually long model name" : selectedModel.name,
|
||||
name: props.longLabels
|
||||
? "Claude Sonnet with an unusually long model name"
|
||||
: props.opus
|
||||
? "Claude Opus 5.5"
|
||||
: selectedModel.name,
|
||||
}))
|
||||
|
||||
const modelSelection = {
|
||||
|
|
@ -152,14 +165,17 @@ function ComposerStory(props: {
|
|||
readImage: async () => pixel,
|
||||
view: {
|
||||
placeholder: () => "Ask anything, / for commands, @ for context...",
|
||||
agent: {
|
||||
options: () => [
|
||||
{ id: "build", label: props.longLabels ? "Build agent with an unusually long name" : "build" },
|
||||
{ id: "review", label: "review" },
|
||||
],
|
||||
current: () => "build",
|
||||
onSelect: (agent) => setStory("activity", `Selected ${agent}`),
|
||||
},
|
||||
// Kit's composer hides the agent picker (custom agents are off by default).
|
||||
agent: props.opus
|
||||
? undefined
|
||||
: {
|
||||
options: () => [
|
||||
{ id: "build", label: props.longLabels ? "Build agent with an unusually long name" : "build" },
|
||||
{ id: "review", label: "review" },
|
||||
],
|
||||
current: () => "build",
|
||||
onSelect: (agent) => setStory("activity", `Selected ${agent}`),
|
||||
},
|
||||
variant: {
|
||||
options: () => [
|
||||
{ id: "default", label: "default" },
|
||||
|
|
@ -221,7 +237,12 @@ function ComposerStory(props: {
|
|||
|
||||
const model = {
|
||||
...editor,
|
||||
model: { selection: modelSelection, paid: true, loading: false },
|
||||
model: {
|
||||
selection: modelSelection,
|
||||
paid: true,
|
||||
loading: false,
|
||||
providerName: props.opus ? selectedModel.provider.name : undefined,
|
||||
},
|
||||
} satisfies ComposerModel
|
||||
|
||||
onMount(() => {
|
||||
|
|
@ -235,7 +256,7 @@ function ComposerStory(props: {
|
|||
<output class="text-12-regular text-text-weak" aria-live="polite">
|
||||
{story.activity}
|
||||
</output>
|
||||
<Composer model={model} borderUnderlay suggestionBoundary={props.suggestionBoundary} />
|
||||
<Composer model={model} borderUnderlay suggestionBoundary={props.suggestionBoundary} layout={props.layout} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -407,6 +428,84 @@ export const ToolbarOverflow = {
|
|||
),
|
||||
}
|
||||
|
||||
const layoutScenarios = ["empty", "text", "long", "multiline", "attachments", "longName"] as const
|
||||
|
||||
function LayoutStory(props: { layout: ComposerLayout; scenario: (typeof layoutScenarios)[number]; width: number }) {
|
||||
const prompt = () => {
|
||||
if (props.scenario === "text") return text("Explain this change")
|
||||
|
||||
if (props.scenario === "long")
|
||||
return text(
|
||||
"Walk through the composer's padding rules and tell me which ones leave empty space between the text and the controls",
|
||||
)
|
||||
|
||||
if (props.scenario === "multiline") return text("Review the implementation\nThen run the focused tests\nThen push")
|
||||
|
||||
if (props.scenario === "attachments")
|
||||
return [
|
||||
...text("Match this layout"),
|
||||
{
|
||||
type: "image" as const,
|
||||
id: "image-story",
|
||||
filename: "layout.png",
|
||||
mime: "image/png",
|
||||
blob: { id: "image-story", url: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==" },
|
||||
},
|
||||
]
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
return (
|
||||
<div data-slot="composer-layout-story" style={{ width: `${props.width + 48}px` }}>
|
||||
<Show when={`${props.layout}:${props.scenario}`} keyed>
|
||||
<ComposerStory opus longLabels={props.scenario === "longName"} prompt={prompt()} layout={props.layout} />
|
||||
</Show>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const Layouts = {
|
||||
args: { layout: "today", scenario: "empty", width: 720 },
|
||||
argTypes: {
|
||||
layout: { control: "select", options: composerLayouts },
|
||||
scenario: { control: "select", options: layoutScenarios },
|
||||
width: { control: { type: "range", min: 320, max: 960, step: 4 } },
|
||||
},
|
||||
render: (args: { layout: ComposerLayout; scenario: (typeof layoutScenarios)[number]; width: number }) => (
|
||||
<LayoutStory layout={args.layout} scenario={args.scenario} width={args.width} />
|
||||
),
|
||||
}
|
||||
|
||||
// The session surface Kit captured: a finished answer with seven subagents running above the composer.
|
||||
export const LayoutInSession = {
|
||||
args: { layout: "today" },
|
||||
argTypes: { layout: { control: "select", options: composerLayouts } },
|
||||
render: (args: { layout: ComposerLayout }) => (
|
||||
<Show when={args.layout} keyed>
|
||||
{(layout) => (
|
||||
<SessionPreview
|
||||
title="Game engine"
|
||||
description="opencode · composer layout"
|
||||
document={largeCompletedDocument}
|
||||
composerLayout={layout}
|
||||
activity={{
|
||||
subagents: Array.from({ length: 7 }, (_, index) => ({
|
||||
key: `ses_child_${index}`,
|
||||
type: "subagent" as const,
|
||||
label: `Detail pass ${index + 1}`,
|
||||
agent: "general",
|
||||
sessionID: `ses_child_${index}`,
|
||||
target: `ses_child_${index}`,
|
||||
})),
|
||||
shells: [],
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Show>
|
||||
),
|
||||
}
|
||||
|
||||
export const DemoFirstClassSkillIDs = {
|
||||
name: "Demo: First-class skill IDs",
|
||||
render: () => (
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { Keybind } from "@opencode/ui/keybind"
|
|||
import { consoleModelGroup } from "@/providers/models/provider-group"
|
||||
import { consoleProviderName } from "@/providers/catalog/console"
|
||||
import { Tooltip } from "@opencode/ui/tooltip"
|
||||
import { ComposerEditor } from "./editor/editor"
|
||||
import { ComposerEditor, composerJoinedLayouts, type ComposerLayout } from "./editor/editor"
|
||||
import { DialogSelectModel, ModelSelectorDrawer } from "@/providers/models/select-dialog"
|
||||
import { ModelDetails } from "@/providers/models/details"
|
||||
import { DialogSelectModelUnpaid } from "@/providers/models/unpaid"
|
||||
|
|
@ -21,6 +21,7 @@ export function Composer(props: {
|
|||
borderUnderlay?: boolean
|
||||
readOnly?: boolean
|
||||
suggestionBoundary?: () => HTMLElement | undefined
|
||||
layout?: ComposerLayout
|
||||
}) {
|
||||
const dialog = useDialog()
|
||||
const command = useCommand()
|
||||
|
|
@ -38,6 +39,16 @@ export function Composer(props: {
|
|||
return language.t("dialog.model.select.title")
|
||||
}
|
||||
|
||||
// Joined layouts show the variant inside the model chip; the model dialog changes it with ←/→.
|
||||
const variantName = () => {
|
||||
if (!composerJoinedLayouts.includes(props.layout ?? "today")) return
|
||||
const control = props.model.view.variant
|
||||
|
||||
if (!control || control.options().length < 2 || control.current() === "default") return
|
||||
|
||||
return control.options().find((option) => option.id === control.current())?.label ?? control.current()
|
||||
}
|
||||
|
||||
return (
|
||||
<div class="flex flex-col gap-3">
|
||||
<ComposerEditor
|
||||
|
|
@ -51,6 +62,7 @@ export function Composer(props: {
|
|||
alternateKeybind={[formatKeybind("mod", language.t), "↵"]}
|
||||
exitShellKeybind={[formatKeybind("esc", language.t)]}
|
||||
suggestionBoundary={props.suggestionBoundary}
|
||||
layout={props.layout}
|
||||
modelControl={
|
||||
<ComposerModelControl
|
||||
loading={props.model.model.loading}
|
||||
|
|
@ -60,6 +72,7 @@ export function Composer(props: {
|
|||
model={props.model.model.selection}
|
||||
providerName={props.model.model.providerName}
|
||||
modelName={modelName()}
|
||||
variantName={variantName()}
|
||||
onClose={props.model.restoreFocus}
|
||||
onUnpaidClick={() => dialog.show(() => <DialogSelectModelUnpaid model={props.model.model.selection} />)}
|
||||
/>
|
||||
|
|
@ -77,6 +90,7 @@ function ComposerModelControl(props: {
|
|||
model: ComposerModel["model"]["selection"]
|
||||
providerName?: string
|
||||
modelName: string
|
||||
variantName?: string
|
||||
onClose: () => void
|
||||
onUnpaidClick: () => void
|
||||
}) {
|
||||
|
|
@ -98,13 +112,16 @@ function ComposerModelControl(props: {
|
|||
<span class="flex min-w-0 whitespace-nowrap leading-4">
|
||||
<Show when={props.providerName}>
|
||||
{(name) => (
|
||||
<>
|
||||
<span data-slot="composer-model-provider" class="contents">
|
||||
<span class="shrink-0 text-v2-text-text-faint">{name()}</span>
|
||||
<span class="shrink-0 whitespace-pre text-v2-text-text-faint">{" / "}</span>
|
||||
</>
|
||||
</span>
|
||||
)}
|
||||
</Show>
|
||||
<span class="truncate">{props.modelName}</span>
|
||||
<Show when={props.variantName}>
|
||||
{(variant) => <span class="shrink-0 ps-1.5 capitalize text-v2-text-text-faint">{variant()}</span>}
|
||||
</Show>
|
||||
</span>
|
||||
<span class="-ml-0.5 -mr-1 flex shrink-0">
|
||||
<Icon name="chevron-down" />
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
mask-image: linear-gradient(
|
||||
to bottom,
|
||||
transparent,
|
||||
black 16px,
|
||||
black var(--composer-fade-top, 16px),
|
||||
black calc(100% - var(--composer-fade-bottom, 0px)),
|
||||
transparent
|
||||
);
|
||||
|
|
@ -64,3 +64,104 @@
|
|||
[data-color-scheme="dark"] [data-component="composer-suggestions"] [data-active] {
|
||||
background: var(--v2-alpha-light-10);
|
||||
}
|
||||
|
||||
/*
|
||||
* Composer layout exploration. "today" is the shipped geometry; every other layout drops the 60px editor and 96px
|
||||
* form minimums, whose 16px of unrequested height sits between the text and the control row.
|
||||
*/
|
||||
[data-component="composer"]:not([data-layout="today"]) {
|
||||
min-height: 0;
|
||||
|
||||
[data-component="composer-scroll"],
|
||||
[data-component="composer-editor"] {
|
||||
min-height: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* The model chip carries the variant, so it sits straight after the + button. */
|
||||
[data-component="composer"]:is([data-layout="joined"], [data-layout="slim"], [data-layout="inline"])
|
||||
[data-slot="composer-controls"] {
|
||||
margin-inline-start: 0;
|
||||
}
|
||||
|
||||
/* Slim: one 12px text inset, 24px controls 8px from the edges, and the + glyph on the text's 12px spine. */
|
||||
[data-component="composer"][data-layout="slim"] {
|
||||
--composer-fade-top: 12px;
|
||||
|
||||
[data-component="composer-editor"],
|
||||
[data-slot="composer-placeholder"] {
|
||||
padding: 12px 12px 4px;
|
||||
}
|
||||
|
||||
[data-slot="composer-row"] {
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
[data-action="composer-attach"],
|
||||
[data-action="composer-submit"] {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
}
|
||||
|
||||
[data-action="composer-submit"] {
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
[data-action="composer-model"] {
|
||||
height: 24px !important;
|
||||
padding-inline: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Inline: one 44px row at rest; it becomes the joined two-row layout once the draft wraps or holds context. */
|
||||
[data-component="composer"][data-layout="inline"] [data-slot="composer-model-provider"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
[data-component="composer"][data-layout="inline"]:not([data-expanded]) {
|
||||
--composer-fade-top: 12px;
|
||||
display: grid;
|
||||
grid-template-columns: auto minmax(160px, 1fr) minmax(0, max-content) auto;
|
||||
grid-template-areas: "add editor controls actions";
|
||||
align-items: center;
|
||||
|
||||
[data-component="composer-scroll"] {
|
||||
grid-area: editor;
|
||||
}
|
||||
|
||||
[data-slot="composer-row"] {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
[data-slot="composer-add"] {
|
||||
grid-area: add;
|
||||
padding-inline-start: 8px;
|
||||
}
|
||||
|
||||
[data-slot="composer-controls"] {
|
||||
grid-area: controls;
|
||||
height: 44px;
|
||||
margin-inline: 0 4px;
|
||||
}
|
||||
|
||||
[data-action="composer-model"] {
|
||||
max-width: 240px;
|
||||
}
|
||||
|
||||
[data-slot="composer-actions"] {
|
||||
grid-area: actions;
|
||||
padding-inline-end: 8px;
|
||||
}
|
||||
|
||||
[data-component="composer-editor"],
|
||||
[data-slot="composer-placeholder"] {
|
||||
padding-block: 12px;
|
||||
padding-inline: 4px 8px;
|
||||
}
|
||||
|
||||
[data-slot="composer-placeholder"] {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,14 @@ export type {
|
|||
|
||||
export type ComposerMode = "normal" | "shell"
|
||||
|
||||
// Exploration of tighter composer geometry. "today" is the shipped layout; the others are candidates for Kit's pick.
|
||||
export const composerLayouts = ["today", "tight", "joined", "slim", "inline"] as const
|
||||
|
||||
export type ComposerLayout = (typeof composerLayouts)[number]
|
||||
|
||||
// Layouts that fold the variant into the model chip instead of showing a second picker.
|
||||
export const composerJoinedLayouts: ComposerLayout[] = ["joined", "slim", "inline"]
|
||||
|
||||
const COMPOSER_SUGGESTION_MAX_HEIGHT = 320
|
||||
|
||||
const COMPOSER_SUGGESTION_ROW_HEIGHT = 28
|
||||
|
|
@ -89,6 +97,7 @@ export type ComposerEditorProps = {
|
|||
alternateKeybind?: string[]
|
||||
exitShellKeybind?: string[]
|
||||
suggestionBoundary?: () => HTMLElement | undefined
|
||||
layout?: ComposerLayout
|
||||
}
|
||||
|
||||
export function ComposerEditor(props: ComposerEditorProps) {
|
||||
|
|
@ -112,9 +121,32 @@ export function ComposerEditor(props: ComposerEditorProps) {
|
|||
// The bottom fade shrinks with the remaining scroll so the last line ends clear of it.
|
||||
const [fadeBottom, setFadeBottom] = createSignal(0)
|
||||
|
||||
const layout = () => props.layout ?? "today"
|
||||
const [expanded, setExpanded] = createSignal(false)
|
||||
|
||||
const hasContext = () =>
|
||||
props.controller.attachments().length +
|
||||
props.controller.uploads().length +
|
||||
props.controller.comments().length +
|
||||
props.controller.files().length >
|
||||
0
|
||||
|
||||
// The inline layout is one row while the draft fits on one line. Once it wraps it stays two rows until the draft
|
||||
// is cleared, so the wider editor of the two-row layout cannot unwrap it and flip back.
|
||||
createEffect(() => {
|
||||
if (layout() !== "inline") return
|
||||
const value = props.controller.value()
|
||||
|
||||
if (!value && !hasContext()) return setExpanded(false)
|
||||
|
||||
if (value.includes("\n") || hasContext()) setExpanded(true)
|
||||
})
|
||||
|
||||
const updateScroll = () => {
|
||||
if (!viewport) return
|
||||
setFadeBottom(Math.min(16, Math.max(0, viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop)))
|
||||
|
||||
if (layout() === "inline" && !expanded() && editor && editor.scrollHeight > 44) setExpanded(true)
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
|
|
@ -200,6 +232,8 @@ export function ComposerEditor(props: ComposerEditorProps) {
|
|||
<form
|
||||
data-component="composer"
|
||||
data-dock-border-underlay={props.borderUnderlay ? "true" : undefined}
|
||||
data-layout={layout()}
|
||||
data-expanded={layout() === "inline" && expanded() ? "" : undefined}
|
||||
class="group/composer relative min-h-[96px] w-full overflow-clip rounded-xl bg-v2-background-bg-base"
|
||||
classList={{
|
||||
"shadow-[var(--v2-elevation-raised)]": !props.borderUnderlay,
|
||||
|
|
@ -317,6 +351,7 @@ export function ComposerEditor(props: ComposerEditorProps) {
|
|||
/>
|
||||
<Show when={!props.controller.value()}>
|
||||
<div
|
||||
data-slot="composer-placeholder"
|
||||
dir={state.mode === "normal" ? "auto" : "ltr"}
|
||||
class="pointer-events-none absolute inset-x-0 top-0 px-4 pt-4 text-[13px] font-[440] leading-5 text-v2-text-text-faint"
|
||||
classList={{ "font-mono! tracking-[-0.04px]": state.mode === "shell" }}
|
||||
|
|
@ -330,8 +365,9 @@ export function ComposerEditor(props: ComposerEditorProps) {
|
|||
</Show>
|
||||
</ScrollView>
|
||||
|
||||
<div class="flex h-11 items-center px-2">
|
||||
<div data-slot="composer-row" class="flex h-11 items-center px-2">
|
||||
<div
|
||||
data-slot="composer-add"
|
||||
class="flex shrink-0 items-center"
|
||||
aria-hidden={state.mode === "shell"}
|
||||
inert={state.mode === "shell" ? true : undefined}
|
||||
|
|
@ -377,7 +413,7 @@ export function ComposerEditor(props: ComposerEditorProps) {
|
|||
</Show>
|
||||
<Show when={props.modelControlsVisible ?? true}>
|
||||
{props.modelControl}
|
||||
<Show when={view.variant} keyed>
|
||||
<Show when={!composerJoinedLayouts.includes(layout()) && view.variant} keyed>
|
||||
{(control) => (
|
||||
<Show when={control.options().length > 1}>
|
||||
<ComposerEditorConfiguredSelect
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import type { ModelSelection } from "@/providers/models/selection"
|
||||
import { Composer } from "@/composer/composer"
|
||||
import type { ComposerLayout } from "@/composer/editor/editor"
|
||||
import type { ComposerModel } from "@/composer/model"
|
||||
import { SessionHeaderActions } from "@/session/header/session-header-actions"
|
||||
import {
|
||||
|
|
@ -94,6 +95,7 @@ export type SessionPreviewProps = {
|
|||
onStop?: (item: SessionActivityItem) => void
|
||||
}
|
||||
timelineDetail?: TimelineDetail
|
||||
composerLayout?: ComposerLayout
|
||||
}
|
||||
|
||||
export function SessionPreview(props: SessionPreviewProps) {
|
||||
|
|
@ -303,7 +305,7 @@ function SessionSurfaceState(props: SessionPreviewProps & { onReset: () => void
|
|||
}
|
||||
/>
|
||||
<div class="relative z-10">
|
||||
<Composer model={prompt.controller} borderUnderlay />
|
||||
<Composer model={prompt.controller} borderUnderlay layout={props.composerLayout} />
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue