Skip to content

Commit efe6e66

Browse files
committed
feat(app): navigable motion workspace with a floating button and replay actions
1 parent b9bf0e2 commit efe6e66

8 files changed

Lines changed: 129 additions & 47 deletions

File tree

‎packages/app/src/session/screen.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ function SessionScreenContent(props: {
129129

130130
replayPanelToggle({
131131
id: "sidePanel",
132-
label: "side panel",
132+
group: "Side panel",
133133
toggle: () => session.layout.view().side.toggle(),
134134
spring: panelSprings.side,
135135
})

‎packages/app/src/shell/panel-motion.ts‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@ import { createEffect, createSignal, on, onCleanup, type Accessor } from "solid-
22
import { frameLoop, prefersReducedMotion, Spring, type DurationOptions } from "@opencode/ui/motion"
33
import { motionTuning } from "@opencode/ui/motion-tuning"
44

5-
const group = "Sidebars"
5+
const sidebar = motionTuning.spring("sidebar", { label: "Spring", group: "Left sidebar", duration: 0.2, bounce: 0 })
66

7-
const sidebar = motionTuning.spring("sidebar", { label: "Sidebar", group, duration: 0.2, bounce: 0 })
8-
9-
const side = motionTuning.spring("sidePanel", { label: "Side panel", group, duration: 0.2, bounce: 0 })
7+
const side = motionTuning.spring("sidePanel", { label: "Spring", group: "Side panel", duration: 0.2, bounce: 0 })
108

119
const linked = motionTuning.toggle("sidePanelLinked", {
12-
label: "Side panel follows sidebar",
13-
group,
10+
label: "Follow the left sidebar's spring",
11+
group: "Side panel",
1412
value: true,
1513
})
1614

1715
const keyboardInstant = motionTuning.toggle("keyboardInstant", {
1816
label: "Keyboard toggles are instant",
19-
group,
17+
group: "Global",
2018
value: true,
2119
})
2220

@@ -25,20 +23,22 @@ export const panelSprings = {
2523
side: () => (linked() ? sidebar() : side()),
2624
}
2725

28-
/** Adds buttons that replay a panel's toggle to the Motion workspace while the panel is mounted. */
26+
/** Adds buttons that play a panel's toggle to its Motion workspace section while the panel is mounted. */
2927
export function replayPanelToggle(input: {
3028
id: string
31-
label: string
29+
group: string
3230
toggle: () => void
3331
spring: () => DurationOptions
3432
}) {
35-
onCleanup(motionTuning.action({ id: `${input.id}.toggle`, label: `Toggle ${input.label}`, group, run: input.toggle }))
33+
onCleanup(
34+
motionTuning.action({ id: `${input.id}.toggle`, label: "Open / close", group: input.group, run: input.toggle }),
35+
)
3636

3737
onCleanup(
3838
motionTuning.action({
3939
id: `${input.id}.reverse`,
40-
label: `Toggle ${input.label}, reverse mid-flight`,
41-
group,
40+
label: "Toggle, reverse mid-flight",
41+
group: input.group,
4242
run: () => {
4343
input.toggle()
4444
setTimeout(input.toggle, input.spring().duration * 350)

‎packages/app/src/shell/shell.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default function Layout(props: ParentProps) {
4545

4646
replayPanelToggle({
4747
id: "sidebar",
48-
label: "sidebar",
48+
group: "Left sidebar",
4949
toggle: () => preferences.appearance.setSidebarOpen(!preferences.appearance.sidebarOpen()),
5050
spring: panelSprings.sidebar,
5151
})

‎packages/gui-extensions/src/debug/bar.tsx‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { batch, createMemo, createSignal, onCleanup, onMount, Show } from "solid-js"
22
import { createStore } from "solid-js/store"
3-
import { Portal } from "solid-js/web"
43
import { makeEventListener } from "@solid-primitives/event-listener"
54
import { Tooltip } from "@opencode/ui/tooltip"
65
import { createKeyed, useExtension } from "../sdk"
@@ -11,7 +10,6 @@ import {
1110
type ProviderMetrics,
1211
type ProviderMetricState,
1312
} from "./metrics"
14-
import MotionWorkspace from "./motion"
1513
import { motionGlobals, motionTuning } from "@opencode/ui/motion-tuning"
1614

1715
type Mem = Performance & {
@@ -194,7 +192,11 @@ function ToggleCell(props: {
194192
)
195193
}
196194

197-
export default function DebugBar(props: { diagnostics?: boolean; inline?: boolean; motion?: boolean }) {
195+
export default function DebugBar(props: {
196+
diagnostics?: boolean
197+
inline?: boolean
198+
motion?: { open: boolean; toggle: () => void }
199+
}) {
198200
const ctx = useExtension()
199201
const router = ctx.router
200202
const locale = ctx.locale
@@ -248,7 +250,6 @@ export default function DebugBar(props: { diagnostics?: boolean; inline?: boolea
248250
// Missed events during an outage are never replayed, so live metrics hold only for the target and the outage count
249251
// they were measured under: after a disconnect the refreshed projection wins until the next live request.
250252
const outages = createMemo((count: number = 0) => (target()?.server.connected ? count : count + 1))
251-
const [workspace, setWorkspace] = createSignal(false)
252253
// The Motion workspace's global speed, kept in view while tuning.
253254
const [globals, setGlobals] = createSignal({ speed: motionGlobals.speed.value, slow: motionGlobals.slow.value })
254255
onCleanup(
@@ -747,7 +748,7 @@ export default function DebugBar(props: { diagnostics?: boolean; inline?: boolea
747748
label={ctx.t("speed.label")}
748749
tip={ctx.t("speed.tip")}
749750
value={`${globals().speed.toFixed(2)}×`}
750-
onClick={() => motionTuning.set(motionGlobals.speed, 1)}
751+
onClick={() => motionTuning.set(motionGlobals.speed, nextSpeed(globals().speed))}
751752
/>
752753
<ToggleCell
753754
active={globals().slow}
@@ -758,21 +759,21 @@ export default function DebugBar(props: { diagnostics?: boolean; inline?: boolea
758759
onClick={() => motionTuning.set(motionGlobals.slow, !globals().slow)}
759760
/>
760761
<ToggleCell
761-
active={workspace()}
762+
active={!!props.motion?.open}
762763
inline={props.inline}
763764
label={ctx.t("motion.label")}
764765
tip={ctx.t("motion.tip")}
765-
value={ctx.t(workspace() ? "focus.on" : "focus.off")}
766-
onClick={() => setWorkspace((value) => !value)}
766+
value={ctx.t(props.motion?.open ? "focus.on" : "focus.off")}
767+
onClick={() => props.motion?.toggle()}
767768
/>
768769
</div>
769-
<Show when={workspace()}>
770-
<Portal>
771-
<MotionWorkspace title={ctx.t("motion.title")} />
772-
</Portal>
773-
</Show>
774770
</Show>
775771
</div>
776772
</aside>
777773
)
778774
}
775+
776+
// The bar's speed cell steps through the common slow-downs, then back to full speed.
777+
function nextSpeed(speed: number) {
778+
return [0.5, 0.25, 1].find((step) => step < speed) ?? 1
779+
}

‎packages/gui-extensions/src/debug/i18n/en.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export default {
22
"command.toggle": "Toggle debug bar",
3+
"command.motion": "Toggle motion controls",
34
"status.toggle": "Toggle debug tools",
45
ariaLabel: "Development performance diagnostics",
56
providerAriaLabel: "Provider performance diagnostics",
@@ -37,7 +38,7 @@ export default {
3738
"motion.title": "Motion",
3839
"motion.tip": "Tune animation springs live. Changes persist on this device.",
3940
"speed.label": "SPEED",
40-
"speed.tip": "Global animation speed from the Motion workspace. Click to reset to 1×.",
41+
"speed.tip": "Global animation speed. Click to step through 0.5× and 0.25× back to 1×.",
4142
"slow.label": "SLOW",
4243
"slow.tip": "Run every tuned animation at a quarter speed.",
4344
"focus.label": "FOCUS",

‎packages/gui-extensions/src/debug/motion.tsx‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1-
import { onCleanup, onMount } from "solid-js"
1+
import { onCleanup, Show } from "solid-js"
2+
import { Portal } from "solid-js/web"
23

3-
// The Motion workspace, floating above the debug bar's bottom-right corner. knobs loads only once it opens.
4-
export default function MotionWorkspace(props: { title: string }) {
4+
// The Motion workspace and its floating button at the window's bottom-right corner. knobs loads once it opens.
5+
export default function Motion(props: { open: boolean; button: boolean; title: string; toggle: () => void }) {
6+
return (
7+
<Portal>
8+
<Show when={props.button}>
9+
<button
10+
type="button"
11+
aria-pressed={props.open}
12+
class="fixed bottom-2 right-2 z-50 rounded-full border border-border-weak-base bg-surface-raised-base px-2 py-0.5 font-mono text-[10px] font-black uppercase tracking-[0.04em] text-text-weak opacity-60 hover:opacity-100 aria-pressed:text-text-strong aria-pressed:opacity-100"
13+
onClick={props.toggle}
14+
>
15+
{props.title}
16+
</button>
17+
</Show>
18+
<Show when={props.open}>
19+
<Workspace title={props.title} />
20+
</Show>
21+
</Portal>
22+
)
23+
}
24+
25+
function Workspace(props: { title: string }) {
526
let container!: HTMLDivElement
627
let unmount: (() => void) | undefined
728
let disposed = false
@@ -11,9 +32,7 @@ export default function MotionWorkspace(props: { title: string }) {
1132
unmount?.()
1233
})
1334

14-
onMount(async () => {
15-
const { mountMotionPanel } = await import("@opencode/ui/motion-tuning-panel")
16-
35+
void import("@opencode/ui/motion-tuning-panel").then(({ mountMotionPanel }) => {
1736
if (!disposed) unmount = mountMotionPanel(container, { title: props.title })
1837
})
1938

‎packages/gui-extensions/src/debug/renderer.tsx‎

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@ import type Debug from "./index"
44

55
const setup: Setup<typeof Debug> = (ctx) => {
66
const DebugBar = lazy(() => import("./bar"))
7+
const Motion = lazy(() => import("./motion"))
78
const channel = ctx.build.channel
89
// Window-local; every window starts with the bar hidden.
910
const [visible, setVisible] = createSignal(false)
1011

12+
const [motion, setMotion] = createSignal(false)
13+
1114
const toggle = () => {
1215
setVisible((value) => !value)
1316
}
1417

18+
const toggleMotion = () => {
19+
setMotion((value) => !value)
20+
}
21+
22+
const developer = channel !== "prod"
23+
1524
ctx.add(
1625
Command,
1726
(): Command => ({
@@ -22,18 +31,40 @@ const setup: Setup<typeof Debug> = (ctx) => {
2231
}),
2332
)
2433

34+
if (developer)
35+
ctx.add(
36+
Command,
37+
(): Command => ({
38+
id: "motion",
39+
title: ctx.t("command.motion"),
40+
group: ctx.t("command.category.view"),
41+
run: toggleMotion,
42+
}),
43+
)
44+
2545
ctx.add(Slot, {
2646
at: "window.bottom",
2747
render: () => (
28-
<Show when={visible()}>
29-
<Suspense>
30-
<DebugBar diagnostics={import.meta.env.DEV} motion={channel !== "prod"} inline />
31-
</Suspense>
32-
</Show>
48+
<>
49+
<Show when={visible()}>
50+
<Suspense>
51+
<DebugBar
52+
diagnostics={import.meta.env.DEV}
53+
motion={developer ? { open: motion(), toggle: toggleMotion } : undefined}
54+
inline
55+
/>
56+
</Suspense>
57+
</Show>
58+
<Show when={developer}>
59+
<Suspense>
60+
<Motion open={motion()} button={!visible()} toggle={toggleMotion} title={ctx.t("motion.title")} />
61+
</Suspense>
62+
</Show>
63+
</>
3364
),
3465
})
3566

36-
if (channel === "prod") return
67+
if (!developer) return
3768
ctx.add(
3869
TitlebarItem,
3970
(): TitlebarItem => ({

‎packages/ui/src/motion-tuning-panel.ts‎

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ import { motionTuning, type MotionKnob } from "./motion-tuning"
44
const global = "Global"
55

66
// Kit's palette, applied to every spring at once.
7-
const palette = { snappy: 0.25, calm: 0.3, smooth: 0.45 }
7+
const durations = { snappy: 0.25, calm: 0.3, smooth: 0.45 }
88

99
/**
1010
* Mounts the Motion workspace into `container`: a tab per surface, Global on every tab, an action row per replay
11-
* button, presets and copy as code. knobs loads on first mount, so importing this module costs nothing until then.
12-
* Works anywhere a surface registered its knobs, including Storybook stories. Returns its removal.
11+
* button, a "Jump to" palette over sections, actions and presets, presets and copy as code. knobs loads on first
12+
* mount, so importing this module costs nothing until then. Works anywhere a surface registered its knobs, including
13+
* Storybook stories. Returns its removal.
1314
*/
14-
export function mountMotionPanel(container: HTMLElement, options: { title?: string } = {}) {
15+
export function mountMotionPanel(container: HTMLElement, options: { title?: string; section?: string } = {}) {
1516
let unmount: (() => void) | undefined
1617
let disposed = false
18+
let section = options.section
1719

1820
void start()
1921

@@ -23,7 +25,10 @@ export function mountMotionPanel(container: HTMLElement, options: { title?: stri
2325
}
2426

2527
async function start() {
26-
const { action, defineControls, knob, spring, toggle } = await import("knobs")
28+
const [{ action, defineControls, knob, spring, toggle }, { commandPalette, commandsFrom }] = await Promise.all([
29+
import("knobs"),
30+
import("knobs/ui"),
31+
])
2732

2833
const field = (item: MotionKnob) => {
2934
const meta = { label: item.label, group: item.group, tab: item.group === global ? undefined : item.group }
@@ -60,6 +65,25 @@ export function mountMotionPanel(container: HTMLElement, options: { title?: stri
6065
const actions = motionTuning.actions()
6166
const mounted = identity()
6267
const springs = list.flatMap((item) => (item.kind === "spring" ? [item] : []))
68+
const sections = [...new Set([...list, ...actions].map((item) => item.group))].filter((group) => group !== global)
69+
70+
const palette = commandPalette({
71+
hotkey: false,
72+
recents: false,
73+
placeholder: "Jump to a section, action or preset",
74+
commands: () => [
75+
...sections.map((id) => ({
76+
id: `section.${id}`,
77+
label: id,
78+
section: "Sections",
79+
run: () => {
80+
section = id
81+
mount()
82+
},
83+
})),
84+
...commandsFrom(controls, { fields: false }).filter((command) => command.label !== "Jump to…"),
85+
],
86+
})
6387

6488
const controls = defineControls(
6589
"opencode-motion",
@@ -71,12 +95,15 @@ export function mountMotionPanel(container: HTMLElement, options: { title?: stri
7195
action(item.label, { group: item.group, tab: item.group, run: item.run }),
7296
]),
7397
),
98+
...Object.fromEntries([["jump", action("Jump to…", { group: global, run: () => palette.open() })]]),
7499
},
75100
{
101+
// knobs enables itself only on localhost; this module is only loaded in developer channels.
102+
enabled: true,
76103
ship: () => import("knobs/panel"),
77104
persist: "variants",
78105
presets: Object.fromEntries(
79-
Object.entries(palette).map(([name, duration]) => [
106+
Object.entries(durations).map(([name, duration]) => [
80107
name,
81108
Object.fromEntries(springs.map((item) => [item.id, { duration, bounce: 0 }])),
82109
]),
@@ -96,7 +123,9 @@ export function mountMotionPanel(container: HTMLElement, options: { title?: stri
96123
const stopPanel = controls.mount(container, {
97124
theme: "auto",
98125
title: options.title ?? "Motion",
99-
tabs: [...new Set([...list, ...actions].map((item) => item.group))].filter((group) => group !== global),
126+
tabs: sections,
127+
tab: section,
128+
onTab: (id) => (section = id),
100129
})
101130

102131
const stopWatch = motionTuning.subscribe(() => {
@@ -108,6 +137,7 @@ export function mountMotionPanel(container: HTMLElement, options: { title?: stri
108137
unmount = () => {
109138
stopWatch()
110139
stopPanel()
140+
palette.dispose()
111141
}
112142
}
113143

0 commit comments

Comments
 (0)