Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/core/src/studio-api/routes/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ function resolveFileMutationContext(c: RouteContext, adapter: StudioApiAdapter,
return resolveProjectPath(c, adapter, (id) => `/projects/${id}/file-mutations/${operation}/`);
}

type MutationTarget = { id?: string | null; selector?: string; selectorIndex?: number };
type MutationTarget = {
id?: string | null;
hfId?: string;
selector?: string;
selectorIndex?: number;
};

/** Write `next` to `absPath` only if it differs from `original`, returning a standardized change response. */
function writeIfChanged(
Expand Down
30 changes: 30 additions & 0 deletions packages/studio/src/components/editor/domEditingLayers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @vitest-environment jsdom
import { describe, expect, it } from "vitest";
import { resolveDomEditSelection } from "./domEditingLayers";

const opts = { activeCompositionPath: "index.html", isMasterView: true, skipSourceProbe: true };

describe("resolveDomEditSelection — hfId from data-hf-id", () => {
it("populates hfId from the element data-hf-id attribute", async () => {
const el = document.createElement("div");
el.id = "hero";
el.setAttribute("data-hf-id", "hf-x7k2");
document.body.appendChild(el);

const selection = await resolveDomEditSelection(el, opts);
document.body.removeChild(el);

expect(selection?.hfId).toBe("hf-x7k2");
});

it("leaves hfId undefined when element has no data-hf-id", async () => {
const el = document.createElement("div");
el.id = "no-hfid-el";
document.body.appendChild(el);

const selection = await resolveDomEditSelection(el, opts);
document.body.removeChild(el);

expect(selection?.hfId).toBeUndefined();
});
});
1 change: 1 addition & 0 deletions packages/studio/src/components/editor/domEditingLayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ export async function resolveDomEditSelection(
return {
element: current,
id: current.id || undefined,
hfId: current.getAttribute("data-hf-id") ?? undefined,
selector,
selectorIndex,
sourceFile,
Expand Down
Loading