Skip to content

Commit 14e8700

Browse files
fix(studio): name a repeated section by its authored id in the Design panel (#4768)
* fix(studio): name a repeated section by its authored id in the Design panel * fix(studio): the timeline's page-read fallback also names a repeated section by its authored id
1 parent ae8d178 commit 14e8700

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

‎packages/studio/src/components/editor/domEditing.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
resolveDomEditCapabilities,
1818
resolveDomEditSelection,
1919
} from "./domEditing";
20-
import { normalizeTimelineCompositionSource } from "./domEditingDom";
20+
import { buildElementLabel, normalizeTimelineCompositionSource } from "./domEditingDom";
2121

2222
function createDocument(markup: string): Document {
2323
const window = new Window();
@@ -925,6 +925,14 @@ describe("resolveDomEditSelection", () => {
925925
);
926926
});
927927

928+
it("names a repeated section by its authored id, not its runtime instance id", () => {
929+
const document = createDocument(`
930+
<div data-composition-id="benefit-fresh__hf2" data-hf-original-composition-id="benefit-fresh"></div>
931+
`);
932+
933+
expect(buildElementLabel(document.querySelector("div") as HTMLElement)).toBe("Benefit Fresh");
934+
});
935+
928936
it("finds a composition host authored with a ./ path", () => {
929937
const document = createDocument(`
930938
<div data-composition-id="scene" data-composition-file="./compositions/scene.html"></div>

‎packages/studio/src/components/editor/domEditingDom.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ function getPreferredClassSelector(el: HTMLElement): string | undefined {
312312

313313
// fallow-ignore-next-line complexity
314314
export function buildElementLabel(el: HTMLElement): string {
315-
const compositionId = el.getAttribute("data-composition-id");
315+
const compositionId =
316+
el.getAttribute("data-hf-original-composition-id") ?? el.getAttribute("data-composition-id");
316317
if (compositionId && compositionId !== "main") {
317318
return humanizeIdentifier(compositionId);
318319
}

‎packages/studio/src/player/lib/timelineDOM.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ describe("parseTimelineFromDOM — nested master time", () => {
7171
});
7272
});
7373

74+
describe("parseTimelineFromDOM — repeated sections", () => {
75+
it("names each instance by its authored id and keeps them apart", () => {
76+
const doc = makeDoc(`
77+
<div data-composition-id="main" data-start="0" data-duration="20">
78+
<div data-composition-id="card__hf1" data-hf-original-composition-id="card" data-start="0" data-duration="4"></div>
79+
<div data-composition-id="card__hf2" data-hf-original-composition-id="card" data-start="4" data-duration="4"></div>
80+
</div>
81+
`);
82+
const rows = parseTimelineFromDOM(doc, 20);
83+
expect(rows.map((e) => e.label)).toEqual(["card", "card"]);
84+
expect(new Set(rows.map((e) => e.id)).size).toBe(2);
85+
});
86+
});
87+
7488
describe("parseTimelineFromDOM — nested rows' keyframe basis", () => {
7589
const doc = () =>
7690
makeDoc(`

‎packages/studio/src/player/lib/timelineDOM.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export function parseTimelineFromDOM(
265265
const sourceFile = getTimelineElementSourceFile(el);
266266
const selectorIndex = getTimelineElementSelectorIndex(doc, el, selector);
267267
const label = getTimelineElementDisplayLabel({
268-
id: el.id || compId || null,
268+
id: el.id || el.getAttribute("data-hf-original-composition-id") || compId || null,
269269
label: el.getAttribute("data-timeline-label") ?? el.getAttribute("data-label"),
270270
tag: tagLower,
271271
});

0 commit comments

Comments
 (0)