Skip to content

Commit 1eb9ab3

Browse files
committed
feat(studio): wire the flat Media group into the one-open accordion
1 parent 5d2aed9 commit 1eb9ab3

2 files changed

Lines changed: 144 additions & 13 deletions

File tree

‎packages/studio/src/components/editor/PropertyPanel.test.tsx‎

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,3 +615,119 @@ describe("PropertyPanel — flat Layout currentPct basis (currentPct follow-up f
615615
RENDER_TIMEOUT_MS,
616616
);
617617
});
618+
619+
// Media fixtures (Plan 4 Task 7): the three tag values resolveEditingSections
620+
// turns `media` on for (video/audio/img). Each carries no text fields (so the
621+
// Text group never renders) and sets `element` to a real media node so the
622+
// FlatMediaSection reads a live media element. `as never` casts around the
623+
// element-type mismatch with baseElement()'s HTMLDivElement.
624+
function videoElement() {
625+
return {
626+
...baseElement(),
627+
id: "s1-bg",
628+
selector: "#s1-bg",
629+
label: "S1 Background",
630+
tagName: "video",
631+
textFields: [],
632+
element: document.createElement("video"),
633+
};
634+
}
635+
636+
function imageElement() {
637+
return {
638+
...baseElement(),
639+
id: "s1-img",
640+
selector: "#s1-img",
641+
label: "S1 Image",
642+
tagName: "img",
643+
textFields: [],
644+
element: document.createElement("img"),
645+
};
646+
}
647+
648+
function audioElement() {
649+
return {
650+
...baseElement(),
651+
id: "s1-audio",
652+
selector: "#s1-audio",
653+
label: "S1 Audio",
654+
tagName: "audio",
655+
textFields: [],
656+
element: document.createElement("audio"),
657+
};
658+
}
659+
660+
// All FlatGroup titles currently mounted (open row + every collapsed row).
661+
function flatGroupTitles(host: HTMLElement): string[] {
662+
const open = Array.from(
663+
host.querySelectorAll('[data-flat-group-open="true"] .text-panel-text-0'),
664+
).map((el) => el.textContent ?? "");
665+
const collapsed = Array.from(
666+
host.querySelectorAll('[data-flat-group-collapsed="true"] .text-panel-text-2'),
667+
).map((el) => el.textContent ?? "");
668+
return [...open, ...collapsed];
669+
}
670+
671+
describe("PropertyPanel — Media group (Plan 4)", () => {
672+
it(
673+
"renders the flat Media group and not the legacy MediaSection, for a video element",
674+
async () => {
675+
const { host, root } = await renderPanel(true, videoElement() as never);
676+
// A Media FlatGroup exists (open or collapsed).
677+
expect(flatGroupTitles(host)).toContain("Media");
678+
// The legacy MediaSection renders its rows inside a `Section` whose
679+
// data-panel-section slug is the media title ("video"/"image"/"audio").
680+
// On the flat path it's fully replaced, so none of those may appear.
681+
expect(host.querySelector('[data-panel-section="video"]')).toBeNull();
682+
expect(host.querySelector('[data-panel-section="image"]')).toBeNull();
683+
expect(host.querySelector('[data-panel-section="audio"]')).toBeNull();
684+
act(() => root.unmount());
685+
},
686+
RENDER_TIMEOUT_MS,
687+
);
688+
689+
it(
690+
"one-open accordion: opening Media closes whichever other group was open, and vice versa (5-way exclusivity)",
691+
async () => {
692+
// videoElement() has canEditStyles: true and no text fields, so Style is
693+
// the default-open group; Layout and Media render collapsed alongside it.
694+
const { host, root } = await renderPanel(true, videoElement() as never);
695+
expect(openGroupText(host)).toContain("Style");
696+
697+
// Opening Media closes Style.
698+
openFlatGroup(host, "Media");
699+
const afterMedia = openGroupText(host);
700+
expect(afterMedia).toContain("Media");
701+
expect(afterMedia).not.toContain("Style");
702+
703+
// Reverse direction: opening Layout closes Media — same shared openGroupId.
704+
openFlatGroup(host, "Layout");
705+
const afterLayout = openGroupText(host);
706+
expect(afterLayout).toContain("Layout");
707+
expect(afterLayout).not.toContain("Media");
708+
act(() => root.unmount());
709+
},
710+
RENDER_TIMEOUT_MS,
711+
);
712+
713+
it(
714+
"gates the Media group exactly like the legacy MediaSection: present for video/img/audio, absent for a plain div/text element",
715+
async () => {
716+
for (const fixture of [videoElement, imageElement, audioElement]) {
717+
const { host, root } = await renderPanel(true, fixture() as never);
718+
expect(flatGroupTitles(host)).toContain("Media");
719+
act(() => root.unmount());
720+
}
721+
722+
// baseElement() is a plain <div> with text — sections.media is false, so
723+
// no Media group (flat or legacy) may render.
724+
const { host, root } = await renderPanel(true);
725+
expect(flatGroupTitles(host)).not.toContain("Media");
726+
expect(host.querySelector('[data-panel-section="video"]')).toBeNull();
727+
expect(host.querySelector('[data-panel-section="image"]')).toBeNull();
728+
expect(host.querySelector('[data-panel-section="audio"]')).toBeNull();
729+
act(() => root.unmount());
730+
},
731+
RENDER_TIMEOUT_MS,
732+
);
733+
});

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

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import { FlatTextSection } from "./propertyPanelFlatTextSection";
1111
import { FlatStyleSection } from "./propertyPanelFlatStyleSections";
1212
import { FlatLayoutSection } from "./propertyPanelFlatLayoutSection";
1313
import { FlatMotionSection } from "./propertyPanelFlatMotionSection";
14+
import { FlatMediaSection } from "./propertyPanelFlatMediaSection";
1415
import { deriveElementTiming } from "./propertyPanelFlatTimingDerivation";
1516
import { createGsapLivePreview } from "./gsapLivePreview";
1617
import { formatTextFieldPreview, StyleSections } from "./propertyPanelSections";
1718
import { STUDIO_GSAP_PANEL_ENABLED } from "./manualEditingAvailability";
1819
import { ColorGradingSection } from "./propertyPanelColorGradingSection";
19-
import { MediaSection } from "./propertyPanelMediaSection";
2020

2121
type EditingSections = ReturnType<typeof resolveEditingSections>;
2222

@@ -41,8 +41,8 @@ const EMPTY_GSAP_EFFECT_HANDLERS = {
4141
* (same one-directional-import precedent as FlatTextSection). Rendered only
4242
* when STUDIO_FLAT_INSPECTOR_ENABLED is on; owns the one-open/pin group state.
4343
*
44-
* The Text/Style/Layout/Motion groups share the one-open accordion. The legacy
45-
* Media and Color-Grading sections render unchanged below the flat groups.
44+
* The Text/Style/Layout/Motion/Media groups share the one-open accordion. The
45+
* legacy Color-Grading section renders unchanged below the flat groups.
4646
*/
4747
// fallow-ignore-next-line complexity
4848
export function PropertyPanelFlat({
@@ -215,7 +215,13 @@ export function PropertyPanelFlat({
215215
// switching the selection re-mounts this component and re-derives the
216216
// default instead of preserving stale state across unrelated elements.
217217
const [openGroupId, setOpenGroupId] = useState<string>(() =>
218-
isTextEditableSelection(element) ? "text" : showEditableSections ? "style" : "layout",
218+
isTextEditableSelection(element)
219+
? "text"
220+
: showEditableSections
221+
? "style"
222+
: sections.media
223+
? "media"
224+
: "layout",
219225
);
220226
const [pinnedGroupIds, setPinnedGroupIds] = useState<string[]>([]);
221227

@@ -427,15 +433,24 @@ export function PropertyPanelFlat({
427433
/>
428434
)}
429435
{sections.media && (
430-
<MediaSection
431-
projectDir={projectDir}
432-
element={element}
433-
styles={styles}
434-
onSetStyle={onSetStyle}
435-
onSetAttribute={onSetAttribute}
436-
onSetHtmlAttribute={onSetHtmlAttribute}
437-
onRemoveBackground={onRemoveBackground}
438-
/>
436+
<FlatGroup
437+
title="Media"
438+
isOpen={openGroupId === "media" || pinnedGroupIds.includes("media")}
439+
isPinned={pinnedGroupIds.includes("media")}
440+
onToggleOpen={() => toggleOpen("media")}
441+
onTogglePin={() => togglePin("media")}
442+
summary={element.tagName}
443+
>
444+
<FlatMediaSection
445+
projectDir={projectDir}
446+
element={element}
447+
styles={styles}
448+
onSetStyle={onSetStyle}
449+
onSetAttribute={onSetAttribute}
450+
onSetHtmlAttribute={onSetHtmlAttribute}
451+
onRemoveBackground={onRemoveBackground}
452+
/>
453+
</FlatGroup>
439454
)}
440455
{showEditableSections && (
441456
<StyleSections

0 commit comments

Comments
 (0)