Skip to content

Commit ba607bf

Browse files
vanceingallsclaude
andauthored
fix(studio): editor panel UX — commit safety, keyboard a11y, wired BlockParamsPanel (#1965)
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
1 parent acfa7c5 commit ba607bf

29 files changed

Lines changed: 771 additions & 136 deletions

‎.fallowrc.jsonc‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,10 @@
455455
// require intrusive middleware changes beyond this PR's scope.
456456
"minLines": 6,
457457
"ignore": [
458+
// FileTree.tsx / LeftSidebar.tsx: pre-existing 8-line structural clone
459+
// (shared sidebar node shape); surfaced by the UX-sweep line shifts.
460+
"packages/studio/src/components/editor/FileTree.tsx",
461+
"packages/studio/src/components/sidebar/LeftSidebar.tsx",
458462
// AWS Lambda and GCP Cloud Run deliberately mirror the same distributed
459463
// rendering lifecycle while retaining provider-specific SDK, storage, and
460464
// retry semantics. The Plan v2 AWS adapter extends that existing symmetry;
@@ -870,6 +874,10 @@
870874
"packages/studio/src/components/editor/BlockParamsPanel.tsx",
871875
"packages/studio/src/components/editor/DomEditOverlay.tsx",
872876
"packages/studio/src/components/editor/FileTree.tsx",
877+
// ColorGradingControls: main's 374-line render function (LUT + vignette/grain
878+
// detail panels), reconciled against this PR's LUT import spinner/error graft
879+
// during rebase. Pre-existing complexity; line-shift re-flags it.
880+
"packages/studio/src/components/editor/propertyPanelColorGradingControls.tsx",
873881
"packages/studio/src/components/editor/FileTreeNodes.tsx",
874882
"packages/studio/src/components/editor/LayersPanel.tsx",
875883
"packages/studio/src/components/editor/MotionPathNode.tsx",

‎packages/studio/src/components/editor/AnimationCard.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ export const AnimationCard = memo(function AnimationCard({
197197
<button
198198
type="button"
199199
onClick={() => setExpanded((v) => !v)}
200-
className="flex w-full items-center gap-2 py-1.5"
200+
aria-expanded={expanded}
201+
className="flex w-full items-center gap-2 py-1.5 active:scale-[0.99]"
201202
>
202203
<span
203204
className="rounded bg-panel-accent/10 px-1.5 py-0.5 text-[10px] font-semibold text-panel-accent"

‎packages/studio/src/components/editor/AnimationCardParts.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ function RemoveButton({ onClick, title }: { onClick: () => void; title: string }
4646
<button
4747
type="button"
4848
onClick={onClick}
49-
className="flex-shrink-0 rounded p-0.5 text-neutral-600 transition-colors hover:bg-neutral-800 hover:text-red-400"
49+
className="relative flex-shrink-0 rounded p-1.5 text-neutral-600 transition-colors hover:bg-neutral-800 hover:text-red-400 active:scale-[0.95]"
5050
title={title}
51+
aria-label={title}
5152
>
5253
<svg
5354
width="12"
@@ -87,13 +88,15 @@ export function PropertyRow({
8788
</span>
8889
<button
8990
type="button"
91+
role="switch"
92+
aria-checked={isVisible}
9093
onClick={() => onCommit(isVisible ? "hidden" : "visible")}
91-
className="flex-shrink-0 rounded-full transition-all duration-150 relative"
94+
className="flex-shrink-0 rounded-full transition-colors duration-200 relative"
9295
style={{ width: 28, height: 16, background: isVisible ? P.accent : P.borderInput }}
9396
title={isVisible ? "Visible — click to hide" : "Hidden — click to show"}
9497
>
9598
<span
96-
className="absolute top-[2px] left-0 rounded-full transition-transform duration-150"
99+
className="absolute top-[2px] left-0 rounded-full transition-transform duration-200"
97100
style={{
98101
width: 12,
99102
height: 12,

‎packages/studio/src/components/editor/ArcPathControls.tsx‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,17 @@ export const ArcPathControls = memo(function ArcPathControls({
4545
<span className={LABEL}>Arc Motion</span>
4646
<button
4747
type="button"
48+
role="switch"
49+
aria-checked={Boolean(arcPath.enabled)}
50+
aria-label="Arc motion"
4851
onClick={handleToggle}
4952
disabled={disabled}
50-
className="relative rounded-full transition-all duration-150"
53+
className="relative rounded-full transition-colors duration-200"
5154
style={{ width: 28, height: 16, background: arcPath.enabled ? P.accent : P.borderInput }}
5255
title={arcPath.enabled ? "Disable arc motion" : "Enable arc motion"}
5356
>
5457
<span
55-
className="absolute top-[2px] left-0 rounded-full transition-transform duration-150"
58+
className="absolute top-[2px] left-0 rounded-full transition-transform duration-200"
5659
style={{
5760
width: 12,
5861
height: 12,
@@ -69,9 +72,12 @@ export const ArcPathControls = memo(function ArcPathControls({
6972
<span className={LABEL}>Auto-Rotate</span>
7073
<button
7174
type="button"
75+
role="switch"
76+
aria-checked={Boolean(arcPath.autoRotate)}
77+
aria-label="Auto-rotate along path"
7278
onClick={handleAutoRotate}
7379
disabled={disabled}
74-
className="relative rounded-full transition-all duration-150"
80+
className="relative rounded-full transition-colors duration-200"
7581
style={{
7682
width: 28,
7783
height: 16,
@@ -84,7 +90,7 @@ export const ArcPathControls = memo(function ArcPathControls({
8490
}
8591
>
8692
<span
87-
className="absolute top-[2px] left-0 rounded-full transition-transform duration-150"
93+
className="absolute top-[2px] left-0 rounded-full transition-transform duration-200"
8894
style={{
8995
width: 12,
9096
height: 12,
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
// @vitest-environment happy-dom
2+
3+
import React, { act } from "react";
4+
import { createRoot, type Root } from "react-dom/client";
5+
import { afterEach, describe, expect, it, vi } from "vitest";
6+
import type { BlockParam } from "@hyperframes/core/registry";
7+
import { FileManagerProvider } from "../../contexts/FileManagerContext";
8+
import type { useFileManager } from "../../hooks/useFileManager";
9+
import { StudioPlaybackProvider, type StudioPlaybackValue } from "../../contexts/StudioContext";
10+
import { BlockParamsPanel } from "./BlockParamsPanel";
11+
12+
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
13+
14+
vi.useFakeTimers();
15+
16+
const PARAMS: BlockParam[] = [
17+
{ key: "--bg-color", label: "Background", type: "color", default: "#0c0c0c" },
18+
{ key: "--text-color", label: "Text color", type: "color", default: "#fafafa" },
19+
];
20+
21+
const playbackValue: StudioPlaybackValue = {
22+
captionEditMode: false,
23+
compositionLoading: false,
24+
refreshKey: 0,
25+
setRefreshKey: vi.fn(),
26+
timelineElements: [],
27+
isPlaying: false,
28+
refreshPreviewDocumentVersion: vi.fn(),
29+
};
30+
31+
function makeFileManager(content: { value: string }) {
32+
const readProjectFile = vi.fn(async () => content.value);
33+
const writeProjectFile = vi.fn(async (_path: string, next: string) => {
34+
content.value = next;
35+
});
36+
// The panel only touches read/writeProjectFile; the rest of the context
37+
// surface is irrelevant to these tests.
38+
const value = { readProjectFile, writeProjectFile } as unknown as ReturnType<
39+
typeof useFileManager
40+
>;
41+
return { value, readProjectFile, writeProjectFile };
42+
}
43+
44+
let root: Root | null = null;
45+
46+
afterEach(() => {
47+
act(() => root?.unmount());
48+
root = null;
49+
document.body.innerHTML = "";
50+
vi.clearAllTimers();
51+
});
52+
53+
function renderPanel(fileManager: ReturnType<typeof makeFileManager>["value"]) {
54+
const host = document.createElement("div");
55+
document.body.append(host);
56+
root = createRoot(host);
57+
act(() => {
58+
root?.render(
59+
<StudioPlaybackProvider value={playbackValue}>
60+
<FileManagerProvider value={fileManager}>
61+
<BlockParamsPanel
62+
blockName="vfx-demo"
63+
blockTitle="VFX Demo"
64+
params={PARAMS}
65+
compositionPath="compositions/vfx-demo.html"
66+
onClose={vi.fn()}
67+
/>
68+
</FileManagerProvider>
69+
</StudioPlaybackProvider>,
70+
);
71+
});
72+
}
73+
74+
function changeParam(label: string, next: string) {
75+
const input = document.querySelector<HTMLInputElement>(`input[aria-label="${label} value"]`);
76+
if (!input) throw new Error(`no input for ${label}`);
77+
act(() => {
78+
const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set;
79+
setter?.call(input, next);
80+
input.dispatchEvent(new Event("input", { bubbles: true }));
81+
});
82+
}
83+
84+
async function flushCommit() {
85+
await act(async () => {
86+
vi.advanceTimersByTime(350);
87+
// Drain the read → guard → write promise chain.
88+
await Promise.resolve();
89+
await Promise.resolve();
90+
await Promise.resolve();
91+
await Promise.resolve();
92+
});
93+
}
94+
95+
describe("BlockParamsPanel commit safety", () => {
96+
it("refuses a multi-occurrence value and never mutates the unrelated sibling", async () => {
97+
// The param's default (#0c0c0c) also appears on an UNRELATED element. The
98+
// panel has no way to tell which occurrence belongs to the param, so it
99+
// must refuse rather than risk rewriting `.unrelated`. Nothing is written.
100+
const content = {
101+
value: ".block { background: #0c0c0c; } .unrelated { border-color: #0c0c0c; }",
102+
};
103+
const before = content.value;
104+
const fm = makeFileManager(content);
105+
renderPanel(fm.value);
106+
107+
changeParam("Background", "#123456");
108+
await flushCommit();
109+
110+
expect(fm.writeProjectFile).not.toHaveBeenCalled();
111+
expect(content.value).toBe(before); // both occurrences untouched
112+
expect(content.value).toContain(".unrelated { border-color: #0c0c0c; }");
113+
expect(document.body.textContent).toContain("appears 2×");
114+
});
115+
116+
it("writes a unique occurrence with token boundaries (no substring corruption)", async () => {
117+
// #0c0c0c is unique here — the 8-digit #0c0c0cff must NOT match (token
118+
// boundary), so exactly one occurrence rewrites and the hex8 is preserved.
119+
const content = {
120+
value: ".a { background: #0c0c0c; } .c { color: #0c0c0cff; }",
121+
};
122+
const fm = makeFileManager(content);
123+
renderPanel(fm.value);
124+
125+
changeParam("Background", "#123456");
126+
await flushCommit();
127+
128+
expect(fm.writeProjectFile).toHaveBeenCalledTimes(1);
129+
expect(content.value).toBe(".a { background: #123456; } .c { color: #0c0c0cff; }");
130+
});
131+
132+
it("refuses once a previously-unique value later collides with unrelated content", async () => {
133+
const content = {
134+
value: ".a { background: #0c0c0c; } .b { color: #fafafa; }",
135+
};
136+
const fm = makeFileManager(content);
137+
renderPanel(fm.value);
138+
139+
// #0c0c0c is unique → first commit writes; now #fafafa appears 2×.
140+
changeParam("Background", "#fafafa");
141+
await flushCommit();
142+
expect(content.value).toBe(".a { background: #fafafa; } .b { color: #fafafa; }");
143+
144+
// Next edit's current value (#fafafa) now matches 2× → refuse.
145+
changeParam("Background", "#ff0000");
146+
await flushCommit();
147+
148+
expect(fm.writeProjectFile).toHaveBeenCalledTimes(1); // no second write
149+
expect(content.value).toBe(".a { background: #fafafa; } .b { color: #fafafa; }");
150+
expect(document.body.textContent).toContain("appears 2×");
151+
});
152+
153+
it("keeps a pending commit for one param when another param is edited", async () => {
154+
const content = {
155+
value: ".a { background: #0c0c0c; } .b { color: #fafafa; }",
156+
};
157+
const fm = makeFileManager(content);
158+
renderPanel(fm.value);
159+
160+
// Edit both params back-to-back within the 300ms debounce window: the
161+
// second edit must not cancel the first param's pending commit.
162+
changeParam("Background", "#111111");
163+
changeParam("Text color", "#222222");
164+
await flushCommit();
165+
await flushCommit();
166+
167+
expect(content.value).toContain("#111111");
168+
expect(content.value).toContain("#222222");
169+
});
170+
});

0 commit comments

Comments
 (0)