Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
feat(studio): wire hfId through DOM-edit patch targets, activate hfId lookup path (R7, T5a) (#1297)
Vance Ingalls82c754f27a43
diff --git a/packages/studio/src/components/editor/domEditing.ts b/packages/studio/src/components/editor/domEditing.tsindex 6cc2b18f73..d8a16344e7 100644--- a/packages/studio/src/components/editor/domEditing.ts+++ b/packages/studio/src/components/editor/domEditing.ts@@ -26,6 +26,7 @@ export {// Layers, text fields, capabilities, selection, patch opsexport {buildDefaultDomEditTextField,+ buildDomEditPatchTarget,buildDomEditStylePatchOperation,buildDomEditTextPatchOperation,collectDomEditLayerItems,diff --git a/packages/studio/src/components/editor/domEditingLayers.test.ts b/packages/studio/src/components/editor/domEditingLayers.test.tsindex 8a39e5441c..900b2aea6c 100644--- a/packages/studio/src/components/editor/domEditingLayers.test.ts+++ b/packages/studio/src/components/editor/domEditingLayers.test.ts@@ -1,9 +1,32 @@// @vitest-environment jsdomimport { describe, expect, it } from "vitest";-import { resolveDomEditSelection } from "./domEditingLayers";+import { resolveDomEditSelection, buildDomEditPatchTarget } from "./domEditingLayers";const opts = { activeCompositionPath: "index.html", isMasterView: true, skipSourceProbe: true };+describe("buildDomEditPatchTarget", () => {+ it("includes hfId when selection has hfId", () => {+ const target = buildDomEditPatchTarget({+ id: undefined,+ hfId: "hf-abc",+ selector: ".foo",+ selectorIndex: 0,+ });+ expect(target.hfId).toBe("hf-abc");+ });++ it("includes id and selector when hfId absent", () => {+ const target = buildDomEditPatchTarget({+ id: "hero",+ hfId: undefined,+ selector: "#hero",+ selectorIndex: undefined,+ });+ expect(target.id).toBe("hero");+ expect(target.hfId).toBeUndefined();+ });+});+describe("resolveDomEditSelection — hfId from data-hf-id", () => {it("populates hfId from the element data-hf-id attribute", async () => {const el = document.createElement("div");diff --git a/packages/studio/src/components/editor/domEditingLayers.ts b/packages/studio/src/components/editor/domEditingLayers.tsindex e53e3360d6..4f3195389f 100644--- a/packages/studio/src/components/editor/domEditingLayers.ts+++ b/packages/studio/src/components/editor/domEditingLayers.ts@@ -555,3 +555,14 @@ export function isTextEditableSelection(selection: DomEditSelection): boolean {}// buildElementAgentPrompt is in domEditingAgentPrompt.ts++export function buildDomEditPatchTarget(+ selection: Pick<DomEditSelection, "id" | "hfId" | "selector" | "selectorIndex">,+): { id?: string | null; hfId?: string; selector?: string; selectorIndex?: number } {+ return {+ id: selection.id,+ hfId: selection.hfId,+ selector: selection.selector,+ selectorIndex: selection.selectorIndex,+ };+}diff --git a/packages/studio/src/hooks/useDomEditCommits.ts b/packages/studio/src/hooks/useDomEditCommits.tsindex c65e87b88b..2d53c1a03f 100644--- a/packages/studio/src/hooks/useDomEditCommits.ts+++ b/packages/studio/src/hooks/useDomEditCommits.ts@@ -5,7 +5,11 @@ import type { PatchOperation } from "../utils/sourcePatcher";import { trackStudioEvent } from "../utils/studioTelemetry";import { saveProjectFilesWithHistory } from "../utils/studioFileHistory";import { primaryFontFamilyValue } from "../utils/studioFontHelpers";-import { getDomEditTargetKey, type DomEditSelection } from "../components/editor/domEditing";+import {+ buildDomEditPatchTarget,+ getDomEditTargetKey,+ type DomEditSelection,+} from "../components/editor/domEditing";import {applyStudioPathOffset,applyStudioBoxSize,@@ -182,11 +186,7 @@ export function useDomEditCommits({if (options?.shouldSave && !options.shouldSave()) return;- const patchTarget: { id?: string | null; selector?: string; selectorIndex?: number } = {- id: selection.id,- selector: selection.selector,- selectorIndex: selection.selectorIndex,- };+ const patchTarget = buildDomEditPatchTarget(selection);// Mark the save timestamp before the file write so the SSE file-change// handler suppresses the reload even if the event arrives before the@@ -471,16 +471,8 @@ export function useDomEditCommits({if (typeof originalContent !== "string")throw new Error(`Missing file contents for ${targetPath}`);- const patchTarget: { id?: string; selector?: string; selectorIndex?: number } = selection.id- ? {- id: selection.id,- selector: selection.selector,- selectorIndex: selection.selectorIndex,- }- : selection.selector- ? { selector: selection.selector, selectorIndex: selection.selectorIndex }- : ({} as never);- if (!patchTarget.id && !patchTarget.selector) {+ const patchTarget = buildDomEditPatchTarget(selection);+ if (!patchTarget.id && !patchTarget.selector && !patchTarget.hfId) {throw new Error("Selected element has no patchable target");}@@ -561,6 +553,7 @@ export function useDomEditCommits({{element: entry.element,id: entry.id ?? null,+ hfId: entry.element.getAttribute("data-hf-id") ?? undefined,selector: entry.selector,selectorIndex: entry.selectorIndex,sourceFile: entry.sourceFile,